aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/base/iommu.c2
-rw-r--r--drivers/char/raw.c1
-rw-r--r--drivers/i2c/busses/i2c-mpc.c9
-rw-r--r--drivers/ide/alim15x3.c9
-rw-r--r--drivers/ide/at91_ide.c70
-rw-r--r--drivers/ide/au1xxx-ide.c39
-rw-r--r--drivers/ide/buddha.c11
-rw-r--r--drivers/ide/cmd64x.c6
-rw-r--r--drivers/ide/cs5536.c2
-rw-r--r--drivers/ide/delkin_cb.c1
-rw-r--r--drivers/ide/dtc2278.c3
-rw-r--r--drivers/ide/falconide.c45
-rw-r--r--drivers/ide/gayle.c7
-rw-r--r--drivers/ide/hpt366.c6
-rw-r--r--drivers/ide/icside.c24
-rw-r--r--drivers/ide/ide-4drives.c3
-rw-r--r--drivers/ide/ide-acpi.c10
-rw-r--r--drivers/ide/ide-atapi.c123
-rw-r--r--drivers/ide/ide-cd.c155
-rw-r--r--drivers/ide/ide-cd.h4
-rw-r--r--drivers/ide/ide-cs.c1
-rw-r--r--drivers/ide/ide-devsets.c4
-rw-r--r--drivers/ide/ide-disk.c171
-rw-r--r--drivers/ide/ide-disk_proc.c28
-rw-r--r--drivers/ide/ide-dma-sff.c37
-rw-r--r--drivers/ide/ide-dma.c39
-rw-r--r--drivers/ide/ide-eh.c30
-rw-r--r--drivers/ide/ide-floppy.c156
-rw-r--r--drivers/ide/ide-gd.c10
-rw-r--r--drivers/ide/ide-gd.h4
-rw-r--r--drivers/ide/ide-generic.c8
-rw-r--r--drivers/ide/ide-h8300.c66
-rw-r--r--drivers/ide/ide-io-std.c73
-rw-r--r--drivers/ide/ide-io.c285
-rw-r--r--drivers/ide/ide-ioctls.c44
-rw-r--r--drivers/ide/ide-iops.c66
-rw-r--r--drivers/ide/ide-lib.c20
-rw-r--r--drivers/ide/ide-park.c19
-rw-r--r--drivers/ide/ide-pm.c42
-rw-r--r--drivers/ide/ide-pnp.c6
-rw-r--r--drivers/ide/ide-probe.c95
-rw-r--r--drivers/ide/ide-proc.c16
-rw-r--r--drivers/ide/ide-tape.c123
-rw-r--r--drivers/ide/ide-taskfile.c448
-rw-r--r--drivers/ide/ide_arm.c6
-rw-r--r--drivers/ide/it821x.c2
-rw-r--r--drivers/ide/macide.c7
-rw-r--r--drivers/ide/ns87415.c36
-rw-r--r--drivers/ide/palm_bk3710.c13
-rw-r--r--drivers/ide/pdc202xx_old.c4
-rw-r--r--drivers/ide/pmac.c32
-rw-r--r--drivers/ide/q40ide.c15
-rw-r--r--drivers/ide/sc1200.c2
-rw-r--r--drivers/ide/scc_pata.c115
-rw-r--r--drivers/ide/setup-pci.c4
-rw-r--r--drivers/ide/sgiioc4.c30
-rw-r--r--drivers/ide/siimage.c2
-rw-r--r--drivers/ide/sl82c105.c2
-rw-r--r--drivers/ide/tc86c001.c2
-rw-r--r--drivers/ide/trm290.c15
-rw-r--r--drivers/ide/tx4938ide.c68
-rw-r--r--drivers/ide/tx4939ide.c109
-rw-r--r--drivers/macintosh/therm_adt746x.c4
-rw-r--r--drivers/media/Kconfig2
-rw-r--r--drivers/media/common/ir-keymaps.c146
-rw-r--r--drivers/media/common/saa7146_core.c15
-rw-r--r--drivers/media/common/saa7146_fops.c48
-rw-r--r--drivers/media/common/saa7146_i2c.c29
-rw-r--r--drivers/media/common/saa7146_video.c1268
-rw-r--r--drivers/media/common/tuners/Kconfig64
-rw-r--r--drivers/media/common/tuners/Makefile1
-rw-r--r--drivers/media/common/tuners/mc44s803.c371
-rw-r--r--drivers/media/common/tuners/mc44s803.h46
-rw-r--r--drivers/media/common/tuners/mc44s803_priv.h208
-rw-r--r--drivers/media/common/tuners/mt2060.c2
-rw-r--r--drivers/media/common/tuners/mt20xx.c2
-rw-r--r--drivers/media/common/tuners/mxl5005s.c7
-rw-r--r--drivers/media/common/tuners/mxl5007t.c428
-rw-r--r--drivers/media/common/tuners/tda18271-common.c6
-rw-r--r--drivers/media/common/tuners/tda18271-fe.c37
-rw-r--r--drivers/media/common/tuners/tda18271-priv.h6
-rw-r--r--drivers/media/common/tuners/tda18271.h10
-rw-r--r--drivers/media/common/tuners/tda827x.c237
-rw-r--r--drivers/media/common/tuners/tda8290.c9
-rw-r--r--drivers/media/common/tuners/tea5761.c2
-rw-r--r--drivers/media/common/tuners/tea5767.c2
-rw-r--r--drivers/media/common/tuners/xc5000.c14
-rw-r--r--drivers/media/dvb/b2c2/Kconfig2
-rw-r--r--drivers/media/dvb/b2c2/Makefile1
-rw-r--r--drivers/media/dvb/b2c2/flexcop-common.h64
-rw-r--r--drivers/media/dvb/b2c2/flexcop-dma.c27
-rw-r--r--drivers/media/dvb/b2c2/flexcop-eeprom.c47
-rw-r--r--drivers/media/dvb/b2c2/flexcop-fe-tuner.c6
-rw-r--r--drivers/media/dvb/b2c2/flexcop-hw-filter.c171
-rw-r--r--drivers/media/dvb/b2c2/flexcop-i2c.c61
-rw-r--r--drivers/media/dvb/b2c2/flexcop-misc.c68
-rw-r--r--drivers/media/dvb/b2c2/flexcop-pci.c165
-rw-r--r--drivers/media/dvb/b2c2/flexcop-reg.h21
-rw-r--r--drivers/media/dvb/b2c2/flexcop-sram.c112
-rw-r--r--drivers/media/dvb/b2c2/flexcop-usb.c368
-rw-r--r--drivers/media/dvb/b2c2/flexcop-usb.h62
-rw-r--r--drivers/media/dvb/b2c2/flexcop.c86
-rw-r--r--drivers/media/dvb/b2c2/flexcop.h20
-rw-r--r--drivers/media/dvb/b2c2/flexcop_ibi_value_be.h7
-rw-r--r--drivers/media/dvb/b2c2/flexcop_ibi_value_le.h7
-rw-r--r--drivers/media/dvb/bt8xx/Kconfig2
-rw-r--r--drivers/media/dvb/bt8xx/dst_ca.c14
-rw-r--r--drivers/media/dvb/bt8xx/dvb-bt8xx.c2
-rw-r--r--drivers/media/dvb/dm1105/Kconfig1
-rw-r--r--drivers/media/dvb/dm1105/dm1105.c204
-rw-r--r--drivers/media/dvb/dvb-core/dmxdev.c2
-rw-r--r--drivers/media/dvb/dvb-core/dvb_ca_en50221.c2
-rw-r--r--drivers/media/dvb/dvb-core/dvb_frontend.c2
-rw-r--r--drivers/media/dvb/dvb-core/dvb_net.c2
-rw-r--r--drivers/media/dvb/dvb-core/dvbdev.c4
-rw-r--r--drivers/media/dvb/dvb-core/dvbdev.h2
-rw-r--r--drivers/media/dvb/dvb-usb/Kconfig67
-rw-r--r--drivers/media/dvb/dvb-usb/Makefile2
-rw-r--r--drivers/media/dvb/dvb-usb/af9015.c60
-rw-r--r--drivers/media/dvb/dvb-usb/af9015.h31
-rw-r--r--drivers/media/dvb/dvb-usb/ce6230.c328
-rw-r--r--drivers/media/dvb/dvb-usb/ce6230.h69
-rw-r--r--drivers/media/dvb/dvb-usb/dib0700_core.c10
-rw-r--r--drivers/media/dvb/dvb-usb/dib0700_devices.c164
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-ids.h11
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb.h2
-rw-r--r--drivers/media/dvb/firewire/firedtv-avc.c2
-rw-r--r--drivers/media/dvb/frontends/Kconfig69
-rw-r--r--drivers/media/dvb/frontends/Makefile6
-rw-r--r--drivers/media/dvb/frontends/au8522.h16
-rw-r--r--drivers/media/dvb/frontends/au8522_decoder.c835
-rw-r--r--drivers/media/dvb/frontends/au8522_dig.c (renamed from drivers/media/dvb/frontends/au8522.c)96
-rw-r--r--drivers/media/dvb/frontends/au8522_priv.h412
-rw-r--r--drivers/media/dvb/frontends/cx24113.c2
-rw-r--r--drivers/media/dvb/frontends/cx24116.c63
-rw-r--r--drivers/media/dvb/frontends/cx24123.c4
-rw-r--r--drivers/media/dvb/frontends/dib0070.h2
-rw-r--r--drivers/media/dvb/frontends/dib3000mc.h36
-rw-r--r--drivers/media/dvb/frontends/dib7000m.h28
-rw-r--r--drivers/media/dvb/frontends/dib7000p.h35
-rw-r--r--drivers/media/dvb/frontends/dvb_dummy_fe.h19
-rw-r--r--drivers/media/dvb/frontends/itd1000_priv.h2
-rw-r--r--drivers/media/dvb/frontends/lgdt3304.c1
-rw-r--r--drivers/media/dvb/frontends/lgdt3305.c1087
-rw-r--r--drivers/media/dvb/frontends/lgdt3305.h85
-rw-r--r--drivers/media/dvb/frontends/lnbh24.h55
-rw-r--r--drivers/media/dvb/frontends/lnbp21.c41
-rw-r--r--drivers/media/dvb/frontends/lnbp21.h34
-rw-r--r--drivers/media/dvb/frontends/s921_module.c1
-rw-r--r--drivers/media/dvb/frontends/stb6100_cfg.h4
-rw-r--r--drivers/media/dvb/frontends/stv0900.h62
-rw-r--r--drivers/media/dvb/frontends/stv0900_core.c1949
-rw-r--r--drivers/media/dvb/frontends/stv0900_init.h441
-rw-r--r--drivers/media/dvb/frontends/stv0900_priv.h430
-rw-r--r--drivers/media/dvb/frontends/stv0900_reg.h3787
-rw-r--r--drivers/media/dvb/frontends/stv0900_sw.c2847
-rw-r--r--drivers/media/dvb/frontends/stv6110.c456
-rw-r--r--drivers/media/dvb/frontends/stv6110.h62
-rw-r--r--drivers/media/dvb/frontends/tda1004x.c30
-rw-r--r--drivers/media/dvb/frontends/zl10036.c519
-rw-r--r--drivers/media/dvb/frontends/zl10036.h53
-rw-r--r--drivers/media/dvb/frontends/zl10353.c8
-rw-r--r--drivers/media/dvb/frontends/zl10353.h4
-rw-r--r--drivers/media/dvb/frontends/zl10353_priv.h8
-rw-r--r--drivers/media/dvb/pluto2/pluto2.c7
-rw-r--r--drivers/media/dvb/siano/Makefile4
-rw-r--r--drivers/media/dvb/siano/sms-cards.c92
-rw-r--r--drivers/media/dvb/siano/sms-cards.h5
-rw-r--r--drivers/media/dvb/siano/smscoreapi.c45
-rw-r--r--drivers/media/dvb/siano/smscoreapi.h41
-rw-r--r--drivers/media/dvb/siano/smsdvb.c60
-rw-r--r--drivers/media/dvb/siano/smsusb.c73
-rw-r--r--drivers/media/dvb/ttpci/Kconfig2
-rw-r--r--drivers/media/dvb/ttpci/av7110.c2
-rw-r--r--drivers/media/dvb/ttpci/av7110_av.c4
-rw-r--r--drivers/media/dvb/ttpci/av7110_ca.c2
-rw-r--r--drivers/media/dvb/ttpci/av7110_v4l.c480
-rw-r--r--drivers/media/dvb/ttpci/budget-av.c88
-rw-r--r--drivers/media/dvb/ttpci/budget-ci.c6
-rw-r--r--drivers/media/radio/dsbr100.c10
-rw-r--r--drivers/media/radio/radio-aimslab.c347
-rw-r--r--drivers/media/radio/radio-aztech.c378
-rw-r--r--drivers/media/radio/radio-cadet.c595
-rw-r--r--drivers/media/radio/radio-gemtek-pci.c329
-rw-r--r--drivers/media/radio/radio-gemtek.c396
-rw-r--r--drivers/media/radio/radio-maestro.c337
-rw-r--r--drivers/media/radio/radio-maxiradio.c374
-rw-r--r--drivers/media/radio/radio-mr800.c221
-rw-r--r--drivers/media/radio/radio-rtrack2.c276
-rw-r--r--drivers/media/radio/radio-sf16fmi.c283
-rw-r--r--drivers/media/radio/radio-sf16fmr2.c371
-rw-r--r--drivers/media/radio/radio-si470x.c200
-rw-r--r--drivers/media/radio/radio-terratec.c310
-rw-r--r--drivers/media/radio/radio-trust.c343
-rw-r--r--drivers/media/radio/radio-typhoon.c349
-rw-r--r--drivers/media/radio/radio-zoltrix.c378
-rw-r--r--drivers/media/video/Kconfig94
-rw-r--r--drivers/media/video/Makefile10
-rw-r--r--drivers/media/video/adv7170.c354
-rw-r--r--drivers/media/video/adv7175.c329
-rw-r--r--drivers/media/video/au0828/Kconfig10
-rw-r--r--drivers/media/video/au0828/Makefile2
-rw-r--r--drivers/media/video/au0828/au0828-cards.c127
-rw-r--r--drivers/media/video/au0828/au0828-core.c34
-rw-r--r--drivers/media/video/au0828/au0828-dvb.c2
-rw-r--r--drivers/media/video/au0828/au0828-i2c.c72
-rw-r--r--drivers/media/video/au0828/au0828-reg.h6
-rw-r--r--drivers/media/video/au0828/au0828-video.c1712
-rw-r--r--drivers/media/video/au0828/au0828.h181
-rw-r--r--drivers/media/video/bt819.c493
-rw-r--r--drivers/media/video/bt856.c291
-rw-r--r--drivers/media/video/bt866.c282
-rw-r--r--drivers/media/video/bt8xx/Kconfig2
-rw-r--r--drivers/media/video/bt8xx/bttv-cards.c1672
-rw-r--r--drivers/media/video/bt8xx/bttv-driver.c197
-rw-r--r--drivers/media/video/bt8xx/bttv-i2c.c61
-rw-r--r--drivers/media/video/bt8xx/bttv-if.c18
-rw-r--r--drivers/media/video/bt8xx/bttv-risc.c4
-rw-r--r--drivers/media/video/bt8xx/bttv-vbi.c2
-rw-r--r--drivers/media/video/bt8xx/bttv.h96
-rw-r--r--drivers/media/video/bt8xx/bttvp.h30
-rw-r--r--drivers/media/video/cafe_ccic.c432
-rw-r--r--drivers/media/video/cpia2/cpia2_v4l.c1
-rw-r--r--drivers/media/video/cs5345.c7
-rw-r--r--drivers/media/video/cs53l32a.c12
-rw-r--r--drivers/media/video/cx18/Kconfig2
-rw-r--r--drivers/media/video/cx18/cx18-audio.c52
-rw-r--r--drivers/media/video/cx18/cx18-audio.h2
-rw-r--r--drivers/media/video/cx18/cx18-av-audio.c120
-rw-r--r--drivers/media/video/cx18/cx18-av-core.c796
-rw-r--r--drivers/media/video/cx18/cx18-av-core.h49
-rw-r--r--drivers/media/video/cx18/cx18-av-firmware.c16
-rw-r--r--drivers/media/video/cx18/cx18-av-vbi.c367
-rw-r--r--drivers/media/video/cx18/cx18-cards.c50
-rw-r--r--drivers/media/video/cx18/cx18-cards.h18
-rw-r--r--drivers/media/video/cx18/cx18-controls.c70
-rw-r--r--drivers/media/video/cx18/cx18-driver.c416
-rw-r--r--drivers/media/video/cx18/cx18-driver.h258
-rw-r--r--drivers/media/video/cx18/cx18-dvb.c2
-rw-r--r--drivers/media/video/cx18/cx18-fileops.c107
-rw-r--r--drivers/media/video/cx18/cx18-firmware.c22
-rw-r--r--drivers/media/video/cx18/cx18-gpio.c319
-rw-r--r--drivers/media/video/cx18/cx18-gpio.h10
-rw-r--r--drivers/media/video/cx18/cx18-i2c.c296
-rw-r--r--drivers/media/video/cx18/cx18-i2c.h5
-rw-r--r--drivers/media/video/cx18/cx18-ioctl.c273
-rw-r--r--drivers/media/video/cx18/cx18-mailbox.c44
-rw-r--r--drivers/media/video/cx18/cx18-queue.c4
-rw-r--r--drivers/media/video/cx18/cx18-queue.h4
-rw-r--r--drivers/media/video/cx18/cx18-streams.c210
-rw-r--r--drivers/media/video/cx18/cx18-vbi.c155
-rw-r--r--drivers/media/video/cx18/cx18-vbi.h2
-rw-r--r--drivers/media/video/cx18/cx18-version.h4
-rw-r--r--drivers/media/video/cx18/cx18-video.c3
-rw-r--r--drivers/media/video/cx18/cx23418.h16
-rw-r--r--drivers/media/video/cx2341x.c196
-rw-r--r--drivers/media/video/cx23885/Kconfig15
-rw-r--r--drivers/media/video/cx23885/Makefile4
-rw-r--r--drivers/media/video/cx23885/cimax2.c472
-rw-r--r--drivers/media/video/cx23885/cimax2.h47
-rw-r--r--drivers/media/video/cx23885/cx23885-417.c49
-rw-r--r--drivers/media/video/cx23885/cx23885-cards.c94
-rw-r--r--drivers/media/video/cx23885/cx23885-core.c43
-rw-r--r--drivers/media/video/cx23885/cx23885-dvb.c166
-rw-r--r--drivers/media/video/cx23885/cx23885-i2c.c68
-rw-r--r--drivers/media/video/cx23885/cx23885-reg.h2
-rw-r--r--drivers/media/video/cx23885/cx23885-video.c51
-rw-r--r--drivers/media/video/cx23885/cx23885.h20
-rw-r--r--drivers/media/video/cx23885/netup-eeprom.c107
-rw-r--r--drivers/media/video/cx23885/netup-eeprom.h42
-rw-r--r--drivers/media/video/cx23885/netup-init.c125
-rw-r--r--drivers/media/video/cx23885/netup-init.h25
-rw-r--r--drivers/media/video/cx25840/cx25840-audio.c121
-rw-r--r--drivers/media/video/cx25840/cx25840-core.c65
-rw-r--r--drivers/media/video/cx25840/cx25840-core.h8
-rw-r--r--drivers/media/video/cx25840/cx25840-vbi.c314
-rw-r--r--drivers/media/video/cx88/Kconfig2
-rw-r--r--drivers/media/video/cx88/cx88-blackbird.c8
-rw-r--r--drivers/media/video/cx88/cx88-cards.c99
-rw-r--r--drivers/media/video/cx88/cx88-core.c11
-rw-r--r--drivers/media/video/cx88/cx88-dvb.c18
-rw-r--r--drivers/media/video/cx88/cx88-i2c.c41
-rw-r--r--drivers/media/video/cx88/cx88-input.c29
-rw-r--r--drivers/media/video/cx88/cx88-video.c52
-rw-r--r--drivers/media/video/cx88/cx88.h24
-rw-r--r--drivers/media/video/dabusb.c83
-rw-r--r--drivers/media/video/em28xx/em28xx-audio.c77
-rw-r--r--drivers/media/video/em28xx/em28xx-cards.c195
-rw-r--r--drivers/media/video/em28xx/em28xx-core.c41
-rw-r--r--drivers/media/video/em28xx/em28xx-dvb.c3
-rw-r--r--drivers/media/video/em28xx/em28xx-i2c.c12
-rw-r--r--drivers/media/video/em28xx/em28xx-input.c22
-rw-r--r--drivers/media/video/em28xx/em28xx-video.c61
-rw-r--r--drivers/media/video/em28xx/em28xx.h24
-rw-r--r--drivers/media/video/gspca/Kconfig27
-rw-r--r--drivers/media/video/gspca/Makefile102
-rw-r--r--drivers/media/video/gspca/conex.c63
-rw-r--r--drivers/media/video/gspca/etoms.c36
-rw-r--r--drivers/media/video/gspca/finepix.c433
-rw-r--r--drivers/media/video/gspca/gspca.c166
-rw-r--r--drivers/media/video/gspca/gspca.h14
-rw-r--r--drivers/media/video/gspca/jpeg.h263
-rw-r--r--drivers/media/video/gspca/m5602/m5602_core.c7
-rw-r--r--drivers/media/video/gspca/mars.c506
-rw-r--r--drivers/media/video/gspca/mr97310a.c362
-rw-r--r--drivers/media/video/gspca/ov519.c7
-rw-r--r--drivers/media/video/gspca/ov534.c820
-rw-r--r--drivers/media/video/gspca/pac207.c8
-rw-r--r--drivers/media/video/gspca/pac7311.c7
-rw-r--r--drivers/media/video/gspca/sonixb.c7
-rw-r--r--drivers/media/video/gspca/sonixj.c951
-rw-r--r--drivers/media/video/gspca/spca500.c99
-rw-r--r--drivers/media/video/gspca/spca501.c22
-rw-r--r--drivers/media/video/gspca/spca505.c525
-rw-r--r--drivers/media/video/gspca/spca506.c57
-rw-r--r--drivers/media/video/gspca/spca508.c128
-rw-r--r--drivers/media/video/gspca/spca561.c192
-rw-r--r--drivers/media/video/gspca/sq905.c456
-rw-r--r--drivers/media/video/gspca/sq905c.c328
-rw-r--r--drivers/media/video/gspca/stk014.c72
-rw-r--r--drivers/media/video/gspca/stv06xx/stv06xx.c7
-rw-r--r--drivers/media/video/gspca/stv06xx/stv06xx_hdcs.c76
-rw-r--r--drivers/media/video/gspca/stv06xx/stv06xx_hdcs.h65
-rw-r--r--drivers/media/video/gspca/stv06xx/stv06xx_pb0100.c147
-rw-r--r--drivers/media/video/gspca/stv06xx/stv06xx_pb0100.h130
-rw-r--r--drivers/media/video/gspca/stv06xx/stv06xx_sensor.h8
-rw-r--r--drivers/media/video/gspca/stv06xx/stv06xx_vv6410.c123
-rw-r--r--drivers/media/video/gspca/stv06xx/stv06xx_vv6410.h58
-rw-r--r--drivers/media/video/gspca/sunplus.c124
-rw-r--r--drivers/media/video/gspca/t613.c564
-rw-r--r--drivers/media/video/gspca/tv8532.c483
-rw-r--r--drivers/media/video/gspca/vc032x.c1591
-rw-r--r--drivers/media/video/gspca/zc3xx.c884
-rw-r--r--drivers/media/video/hdpvr/Kconfig10
-rw-r--r--drivers/media/video/hdpvr/Makefile9
-rw-r--r--drivers/media/video/hdpvr/hdpvr-control.c201
-rw-r--r--drivers/media/video/hdpvr/hdpvr-core.c466
-rw-r--r--drivers/media/video/hdpvr/hdpvr-i2c.c145
-rw-r--r--drivers/media/video/hdpvr/hdpvr-video.c1248
-rw-r--r--drivers/media/video/hdpvr/hdpvr.h303
-rw-r--r--drivers/media/video/hexium_gemini.c292
-rw-r--r--drivers/media/video/hexium_orion.c103
-rw-r--r--drivers/media/video/indycam.c314
-rw-r--r--drivers/media/video/indycam.h19
-rw-r--r--drivers/media/video/ir-kbd-i2c.c84
-rw-r--r--drivers/media/video/ivtv/ivtv-controls.c1
-rw-r--r--drivers/media/video/ivtv/ivtv-driver.c93
-rw-r--r--drivers/media/video/ivtv/ivtv-driver.h26
-rw-r--r--drivers/media/video/ivtv/ivtv-fileops.c10
-rw-r--r--drivers/media/video/ivtv/ivtv-firmware.c2
-rw-r--r--drivers/media/video/ivtv/ivtv-gpio.c4
-rw-r--r--drivers/media/video/ivtv/ivtv-i2c.c14
-rw-r--r--drivers/media/video/ivtv/ivtv-ioctl.c20
-rw-r--r--drivers/media/video/ivtv/ivtv-irq.c4
-rw-r--r--drivers/media/video/ivtv/ivtv-queue.c8
-rw-r--r--drivers/media/video/ivtv/ivtv-queue.h8
-rw-r--r--drivers/media/video/ivtv/ivtv-streams.c68
-rw-r--r--drivers/media/video/ivtv/ivtv-udma.c10
-rw-r--r--drivers/media/video/ivtv/ivtv-udma.h4
-rw-r--r--drivers/media/video/ivtv/ivtv-vbi.c2
-rw-r--r--drivers/media/video/ivtv/ivtv-version.h2
-rw-r--r--drivers/media/video/ivtv/ivtv-yuv.c6
-rw-r--r--drivers/media/video/ivtv/ivtvfb.c6
-rw-r--r--drivers/media/video/ks0127.c677
-rw-r--r--drivers/media/video/ks0127.h2
-rw-r--r--drivers/media/video/m52790.c7
-rw-r--r--drivers/media/video/meye.c45
-rw-r--r--drivers/media/video/msp3400-driver.c142
-rw-r--r--drivers/media/video/mt9m001.c164
-rw-r--r--drivers/media/video/mt9m111.c64
-rw-r--r--drivers/media/video/mt9t031.c179
-rw-r--r--drivers/media/video/mt9v022.c205
-rw-r--r--drivers/media/video/mx3_camera.c1220
-rw-r--r--drivers/media/video/mxb.c828
-rw-r--r--drivers/media/video/omap24xxcam.c7
-rw-r--r--drivers/media/video/ov7670.c552
-rw-r--r--drivers/media/video/ov772x.c320
-rw-r--r--drivers/media/video/ovcamchip/ovcamchip_core.c197
-rw-r--r--drivers/media/video/ovcamchip/ovcamchip_priv.h7
-rw-r--r--drivers/media/video/pvrusb2/Kconfig8
-rw-r--r--drivers/media/video/pvrusb2/Makefile7
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-audio.c142
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-audio.h6
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-cs53l32a.c95
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-cs53l32a.h (renamed from drivers/media/video/pvrusb2/pvrusb2-tuner.h)21
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c245
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.h4
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-debugifc.c5
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-debugifc.h12
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-devattr.c102
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-devattr.h34
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-dvb.c2
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-encoder.c2
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h50
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-hdw.c648
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-hdw.h6
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-i2c-chips-v4l2.c113
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.c322
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.h50
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-i2c-core.c417
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-i2c-core.h57
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-main.c4
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-sysfs.c12
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-tuner.c120
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-v4l2.c18
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-video-v4l.c214
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-video-v4l.h7
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-wm8775.c134
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-wm8775.h4
-rw-r--r--drivers/media/video/pwc/Kconfig10
-rw-r--r--drivers/media/video/pwc/pwc-if.c79
-rw-r--r--drivers/media/video/pwc/pwc.h6
-rw-r--r--drivers/media/video/pxa_camera.c68
-rw-r--r--drivers/media/video/s2255drv.c41
-rw-r--r--drivers/media/video/saa5246a.c70
-rw-r--r--drivers/media/video/saa5249.c71
-rw-r--r--drivers/media/video/saa6588.c207
-rw-r--r--drivers/media/video/saa7110.c472
-rw-r--r--drivers/media/video/saa7111.c492
-rw-r--r--drivers/media/video/saa7114.c1068
-rw-r--r--drivers/media/video/saa7115.c64
-rw-r--r--drivers/media/video/saa7127.c1
-rw-r--r--drivers/media/video/saa7134/Kconfig13
-rw-r--r--drivers/media/video/saa7134/saa6752hs.c581
-rw-r--r--drivers/media/video/saa7134/saa7134-cards.c333
-rw-r--r--drivers/media/video/saa7134/saa7134-core.c108
-rw-r--r--drivers/media/video/saa7134/saa7134-dvb.c75
-rw-r--r--drivers/media/video/saa7134/saa7134-empress.c27
-rw-r--r--drivers/media/video/saa7134/saa7134-i2c.c23
-rw-r--r--drivers/media/video/saa7134/saa7134-ts.c15
-rw-r--r--drivers/media/video/saa7134/saa7134-video.c75
-rw-r--r--drivers/media/video/saa7134/saa7134.h40
-rw-r--r--drivers/media/video/saa7146.h2
-rw-r--r--drivers/media/video/saa717x.c10
-rw-r--r--drivers/media/video/saa7185.c239
-rw-r--r--drivers/media/video/saa7191.c500
-rw-r--r--drivers/media/video/saa7191.h26
-rw-r--r--drivers/media/video/sh_mobile_ceu_camera.c82
-rw-r--r--drivers/media/video/sn9c102/sn9c102_devtable.h4
-rw-r--r--drivers/media/video/soc_camera.c135
-rw-r--r--drivers/media/video/soc_camera_platform.c9
-rw-r--r--drivers/media/video/stk-webcam.c24
-rw-r--r--drivers/media/video/tcm825x.c22
-rw-r--r--drivers/media/video/tcm825x.h2
-rw-r--r--drivers/media/video/tda7432.c22
-rw-r--r--drivers/media/video/tda9840.c82
-rw-r--r--drivers/media/video/tda9840.h14
-rw-r--r--drivers/media/video/tda9875.c19
-rw-r--r--drivers/media/video/tea6415c.c53
-rw-r--r--drivers/media/video/tea6415c.h12
-rw-r--r--drivers/media/video/tea6420.c69
-rw-r--r--drivers/media/video/tea6420.h27
-rw-r--r--drivers/media/video/tlv320aic23b.c12
-rw-r--r--drivers/media/video/tuner-core.c152
-rw-r--r--drivers/media/video/tvaudio.c173
-rw-r--r--drivers/media/video/tveeprom.c7
-rw-r--r--drivers/media/video/tvp514x.c113
-rw-r--r--drivers/media/video/tvp5150.c10
-rw-r--r--drivers/media/video/tw9910.c36
-rw-r--r--drivers/media/video/upd64031a.c7
-rw-r--r--drivers/media/video/upd64083.c7
-rw-r--r--drivers/media/video/usbvideo/vicam.c2
-rw-r--r--drivers/media/video/usbvision/usbvision-core.c49
-rw-r--r--drivers/media/video/usbvision/usbvision-i2c.c153
-rw-r--r--drivers/media/video/usbvision/usbvision-video.c125
-rw-r--r--drivers/media/video/usbvision/usbvision.h10
-rw-r--r--drivers/media/video/uvc/uvc_ctrl.c2
-rw-r--r--drivers/media/video/uvc/uvc_driver.c45
-rw-r--r--drivers/media/video/uvc/uvc_status.c16
-rw-r--r--drivers/media/video/uvc/uvc_v4l2.c20
-rw-r--r--drivers/media/video/uvc/uvc_video.c133
-rw-r--r--drivers/media/video/uvc/uvcvideo.h8
-rw-r--r--drivers/media/video/v4l2-common.c265
-rw-r--r--drivers/media/video/v4l2-compat-ioctl32.c1
-rw-r--r--drivers/media/video/v4l2-dev.c54
-rw-r--r--drivers/media/video/v4l2-device.c58
-rw-r--r--drivers/media/video/v4l2-ioctl.c192
-rw-r--r--drivers/media/video/v4l2-subdev.c18
-rw-r--r--drivers/media/video/videobuf-dma-contig.c2
-rw-r--r--drivers/media/video/videobuf-vmalloc.c2
-rw-r--r--drivers/media/video/vino.c1655
-rw-r--r--drivers/media/video/vivi.c495
-rw-r--r--drivers/media/video/vp27smpx.c7
-rw-r--r--drivers/media/video/vpx3220.c491
-rw-r--r--drivers/media/video/w9966.c2
-rw-r--r--drivers/media/video/w9968cf.c133
-rw-r--r--drivers/media/video/w9968cf.h24
-rw-r--r--drivers/media/video/wm8739.c7
-rw-r--r--drivers/media/video/wm8775.c12
-rw-r--r--drivers/media/video/zc0301/zc0301_sensor.h8
-rw-r--r--drivers/media/video/zoran/Kconfig8
-rw-r--r--drivers/media/video/zoran/videocodec.h9
-rw-r--r--drivers/media/video/zoran/zoran.h97
-rw-r--r--drivers/media/video/zoran/zoran_card.c555
-rw-r--r--drivers/media/video/zoran/zoran_card.h3
-rw-r--r--drivers/media/video/zoran/zoran_device.c529
-rw-r--r--drivers/media/video/zoran/zoran_device.h14
-rw-r--r--drivers/media/video/zoran/zoran_driver.c4385
-rw-r--r--drivers/media/video/zoran/zoran_procfs.c2
-rw-r--r--drivers/media/video/zoran/zr36016.c5
-rw-r--r--drivers/media/video/zoran/zr36050.c4
-rw-r--r--drivers/media/video/zoran/zr36060.c4
-rw-r--r--drivers/media/video/zr364xx.c17
-rw-r--r--drivers/net/fec_mpc52xx.c6
-rw-r--r--drivers/net/meth.c2
-rw-r--r--drivers/net/smc91x.h32
-rw-r--r--drivers/pci/dmar.c296
-rw-r--r--drivers/pci/intel-iommu.c270
-rw-r--r--drivers/pci/intr_remapping.c110
-rw-r--r--drivers/ps3/ps3av.c16
-rw-r--r--drivers/serial/cpm_uart/cpm_uart_core.c14
-rw-r--r--drivers/serial/mpc52xx_uart.c40
-rw-r--r--drivers/sh/maple/maple.c2
-rw-r--r--drivers/spi/xilinx_spi.c9
-rw-r--r--drivers/watchdog/Kconfig2
515 files changed, 49353 insertions, 28838 deletions
diff --git a/drivers/base/iommu.c b/drivers/base/iommu.c
index 5e039d4f877c..c2d1eed90376 100644
--- a/drivers/base/iommu.c
+++ b/drivers/base/iommu.c
@@ -31,7 +31,7 @@ void register_iommu(struct iommu_ops *ops)
31 iommu_ops = ops; 31 iommu_ops = ops;
32} 32}
33 33
34bool iommu_found() 34bool iommu_found(void)
35{ 35{
36 return iommu_ops != NULL; 36 return iommu_ops != NULL;
37} 37}
diff --git a/drivers/char/raw.c b/drivers/char/raw.c
index 96adf28a17e4..20d90e6a6e50 100644
--- a/drivers/char/raw.c
+++ b/drivers/char/raw.c
@@ -90,6 +90,7 @@ out1:
90 blkdev_put(bdev, filp->f_mode); 90 blkdev_put(bdev, filp->f_mode);
91out: 91out:
92 mutex_unlock(&raw_mutex); 92 mutex_unlock(&raw_mutex);
93 unlock_kernel();
93 return err; 94 return err;
94} 95}
95 96
diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c
index 2b847d875946..26bf37010586 100644
--- a/drivers/i2c/busses/i2c-mpc.c
+++ b/drivers/i2c/busses/i2c-mpc.c
@@ -70,7 +70,7 @@ static irqreturn_t mpc_i2c_isr(int irq, void *dev_id)
70 /* Read again to allow register to stabilise */ 70 /* Read again to allow register to stabilise */
71 i2c->interrupt = readb(i2c->base + MPC_I2C_SR); 71 i2c->interrupt = readb(i2c->base + MPC_I2C_SR);
72 writeb(0, i2c->base + MPC_I2C_SR); 72 writeb(0, i2c->base + MPC_I2C_SR);
73 wake_up_interruptible(&i2c->queue); 73 wake_up(&i2c->queue);
74 } 74 }
75 return IRQ_HANDLED; 75 return IRQ_HANDLED;
76} 76}
@@ -115,13 +115,10 @@ static int i2c_wait(struct mpc_i2c *i2c, unsigned timeout, int writing)
115 writeb(0, i2c->base + MPC_I2C_SR); 115 writeb(0, i2c->base + MPC_I2C_SR);
116 } else { 116 } else {
117 /* Interrupt mode */ 117 /* Interrupt mode */
118 result = wait_event_interruptible_timeout(i2c->queue, 118 result = wait_event_timeout(i2c->queue,
119 (i2c->interrupt & CSR_MIF), timeout); 119 (i2c->interrupt & CSR_MIF), timeout);
120 120
121 if (unlikely(result < 0)) { 121 if (unlikely(!(i2c->interrupt & CSR_MIF))) {
122 pr_debug("I2C: wait interrupted\n");
123 writeccr(i2c, 0);
124 } else if (unlikely(!(i2c->interrupt & CSR_MIF))) {
125 pr_debug("I2C: wait timeout\n"); 122 pr_debug("I2C: wait timeout\n");
126 writeccr(i2c, 0); 123 writeccr(i2c, 0);
127 result = -ETIMEDOUT; 124 result = -ETIMEDOUT;
diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
index d3513b6b8530..d516168464fc 100644
--- a/drivers/ide/alim15x3.c
+++ b/drivers/ide/alim15x3.c
@@ -191,17 +191,18 @@ static void ali_set_dma_mode(ide_drive_t *drive, const u8 speed)
191/** 191/**
192 * ali15x3_dma_setup - begin a DMA phase 192 * ali15x3_dma_setup - begin a DMA phase
193 * @drive: target device 193 * @drive: target device
194 * @cmd: command
194 * 195 *
195 * Returns 1 if the DMA cannot be performed, zero on success. 196 * Returns 1 if the DMA cannot be performed, zero on success.
196 */ 197 */
197 198
198static int ali15x3_dma_setup(ide_drive_t *drive) 199static int ali15x3_dma_setup(ide_drive_t *drive, struct ide_cmd *cmd)
199{ 200{
200 if (m5229_revision < 0xC2 && drive->media != ide_disk) { 201 if (m5229_revision < 0xC2 && drive->media != ide_disk) {
201 if (rq_data_dir(drive->hwif->rq)) 202 if (cmd->tf_flags & IDE_TFLAG_WRITE)
202 return 1; /* try PIO instead of DMA */ 203 return 1; /* try PIO instead of DMA */
203 } 204 }
204 return ide_dma_setup(drive); 205 return ide_dma_setup(drive, cmd);
205} 206}
206 207
207/** 208/**
@@ -503,11 +504,11 @@ static const struct ide_port_ops ali_port_ops = {
503static const struct ide_dma_ops ali_dma_ops = { 504static const struct ide_dma_ops ali_dma_ops = {
504 .dma_host_set = ide_dma_host_set, 505 .dma_host_set = ide_dma_host_set,
505 .dma_setup = ali15x3_dma_setup, 506 .dma_setup = ali15x3_dma_setup,
506 .dma_exec_cmd = ide_dma_exec_cmd,
507 .dma_start = ide_dma_start, 507 .dma_start = ide_dma_start,
508 .dma_end = ide_dma_end, 508 .dma_end = ide_dma_end,
509 .dma_test_irq = ide_dma_test_irq, 509 .dma_test_irq = ide_dma_test_irq,
510 .dma_lost_irq = ide_dma_lost_irq, 510 .dma_lost_irq = ide_dma_lost_irq,
511 .dma_timer_expiry = ide_dma_sff_timer_expiry,
511 .dma_timeout = ide_dma_timeout, 512 .dma_timeout = ide_dma_timeout,
512 .dma_sff_read_status = ide_dma_sff_read_status, 513 .dma_sff_read_status = ide_dma_sff_read_status,
513}; 514};
diff --git a/drivers/ide/at91_ide.c b/drivers/ide/at91_ide.c
index 1bb50f46388d..27547121daff 100644
--- a/drivers/ide/at91_ide.c
+++ b/drivers/ide/at91_ide.c
@@ -143,7 +143,7 @@ static void apply_timings(const u8 chipselect, const u8 pio,
143 set_smc_timings(chipselect, cycle, setup, pulse, data_float, use_iordy); 143 set_smc_timings(chipselect, cycle, setup, pulse, data_float, use_iordy);
144} 144}
145 145
146static void at91_ide_input_data(ide_drive_t *drive, struct request *rq, 146static void at91_ide_input_data(ide_drive_t *drive, struct ide_cmd *cmd,
147 void *buf, unsigned int len) 147 void *buf, unsigned int len)
148{ 148{
149 ide_hwif_t *hwif = drive->hwif; 149 ide_hwif_t *hwif = drive->hwif;
@@ -156,11 +156,11 @@ static void at91_ide_input_data(ide_drive_t *drive, struct request *rq,
156 len++; 156 len++;
157 157
158 enter_16bit(chipselect, mode); 158 enter_16bit(chipselect, mode);
159 __ide_mm_insw((void __iomem *) io_ports->data_addr, buf, len / 2); 159 readsw((void __iomem *)io_ports->data_addr, buf, len / 2);
160 leave_16bit(chipselect, mode); 160 leave_16bit(chipselect, mode);
161} 161}
162 162
163static void at91_ide_output_data(ide_drive_t *drive, struct request *rq, 163static void at91_ide_output_data(ide_drive_t *drive, struct ide_cmd *cmd,
164 void *buf, unsigned int len) 164 void *buf, unsigned int len)
165{ 165{
166 ide_hwif_t *hwif = drive->hwif; 166 ide_hwif_t *hwif = drive->hwif;
@@ -171,7 +171,7 @@ static void at91_ide_output_data(ide_drive_t *drive, struct request *rq,
171 pdbg("cs %u buf %p len %d\n", chipselect, buf, len); 171 pdbg("cs %u buf %p len %d\n", chipselect, buf, len);
172 172
173 enter_16bit(chipselect, mode); 173 enter_16bit(chipselect, mode);
174 __ide_mm_outsw((void __iomem *) io_ports->data_addr, buf, len / 2); 174 writesw((void __iomem *)io_ports->data_addr, buf, len / 2);
175 leave_16bit(chipselect, mode); 175 leave_16bit(chipselect, mode);
176} 176}
177 177
@@ -185,55 +185,55 @@ static void ide_mm_outb(u8 value, unsigned long port)
185 writeb(value, (void __iomem *) port); 185 writeb(value, (void __iomem *) port);
186} 186}
187 187
188static void at91_ide_tf_load(ide_drive_t *drive, ide_task_t *task) 188static void at91_ide_tf_load(ide_drive_t *drive, struct ide_cmd *cmd)
189{ 189{
190 ide_hwif_t *hwif = drive->hwif; 190 ide_hwif_t *hwif = drive->hwif;
191 struct ide_io_ports *io_ports = &hwif->io_ports; 191 struct ide_io_ports *io_ports = &hwif->io_ports;
192 struct ide_taskfile *tf = &task->tf; 192 struct ide_taskfile *tf = &cmd->tf;
193 u8 HIHI = (task->tf_flags & IDE_TFLAG_LBA48) ? 0xE0 : 0xEF; 193 u8 HIHI = (cmd->tf_flags & IDE_TFLAG_LBA48) ? 0xE0 : 0xEF;
194 194
195 if (task->tf_flags & IDE_TFLAG_FLAGGED) 195 if (cmd->tf_flags & IDE_FTFLAG_FLAGGED)
196 HIHI = 0xFF; 196 HIHI = 0xFF;
197 197
198 if (task->tf_flags & IDE_TFLAG_OUT_DATA) { 198 if (cmd->tf_flags & IDE_FTFLAG_OUT_DATA) {
199 u16 data = (tf->hob_data << 8) | tf->data; 199 u16 data = (tf->hob_data << 8) | tf->data;
200 200
201 at91_ide_output_data(drive, NULL, &data, 2); 201 at91_ide_output_data(drive, NULL, &data, 2);
202 } 202 }
203 203
204 if (task->tf_flags & IDE_TFLAG_OUT_HOB_FEATURE) 204 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_FEATURE)
205 ide_mm_outb(tf->hob_feature, io_ports->feature_addr); 205 ide_mm_outb(tf->hob_feature, io_ports->feature_addr);
206 if (task->tf_flags & IDE_TFLAG_OUT_HOB_NSECT) 206 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_NSECT)
207 ide_mm_outb(tf->hob_nsect, io_ports->nsect_addr); 207 ide_mm_outb(tf->hob_nsect, io_ports->nsect_addr);
208 if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAL) 208 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_LBAL)
209 ide_mm_outb(tf->hob_lbal, io_ports->lbal_addr); 209 ide_mm_outb(tf->hob_lbal, io_ports->lbal_addr);
210 if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAM) 210 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_LBAM)
211 ide_mm_outb(tf->hob_lbam, io_ports->lbam_addr); 211 ide_mm_outb(tf->hob_lbam, io_ports->lbam_addr);
212 if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAH) 212 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_LBAH)
213 ide_mm_outb(tf->hob_lbah, io_ports->lbah_addr); 213 ide_mm_outb(tf->hob_lbah, io_ports->lbah_addr);
214 214
215 if (task->tf_flags & IDE_TFLAG_OUT_FEATURE) 215 if (cmd->tf_flags & IDE_TFLAG_OUT_FEATURE)
216 ide_mm_outb(tf->feature, io_ports->feature_addr); 216 ide_mm_outb(tf->feature, io_ports->feature_addr);
217 if (task->tf_flags & IDE_TFLAG_OUT_NSECT) 217 if (cmd->tf_flags & IDE_TFLAG_OUT_NSECT)
218 ide_mm_outb(tf->nsect, io_ports->nsect_addr); 218 ide_mm_outb(tf->nsect, io_ports->nsect_addr);
219 if (task->tf_flags & IDE_TFLAG_OUT_LBAL) 219 if (cmd->tf_flags & IDE_TFLAG_OUT_LBAL)
220 ide_mm_outb(tf->lbal, io_ports->lbal_addr); 220 ide_mm_outb(tf->lbal, io_ports->lbal_addr);
221 if (task->tf_flags & IDE_TFLAG_OUT_LBAM) 221 if (cmd->tf_flags & IDE_TFLAG_OUT_LBAM)
222 ide_mm_outb(tf->lbam, io_ports->lbam_addr); 222 ide_mm_outb(tf->lbam, io_ports->lbam_addr);
223 if (task->tf_flags & IDE_TFLAG_OUT_LBAH) 223 if (cmd->tf_flags & IDE_TFLAG_OUT_LBAH)
224 ide_mm_outb(tf->lbah, io_ports->lbah_addr); 224 ide_mm_outb(tf->lbah, io_ports->lbah_addr);
225 225
226 if (task->tf_flags & IDE_TFLAG_OUT_DEVICE) 226 if (cmd->tf_flags & IDE_TFLAG_OUT_DEVICE)
227 ide_mm_outb((tf->device & HIHI) | drive->select, io_ports->device_addr); 227 ide_mm_outb((tf->device & HIHI) | drive->select, io_ports->device_addr);
228} 228}
229 229
230static void at91_ide_tf_read(ide_drive_t *drive, ide_task_t *task) 230static void at91_ide_tf_read(ide_drive_t *drive, struct ide_cmd *cmd)
231{ 231{
232 ide_hwif_t *hwif = drive->hwif; 232 ide_hwif_t *hwif = drive->hwif;
233 struct ide_io_ports *io_ports = &hwif->io_ports; 233 struct ide_io_ports *io_ports = &hwif->io_ports;
234 struct ide_taskfile *tf = &task->tf; 234 struct ide_taskfile *tf = &cmd->tf;
235 235
236 if (task->tf_flags & IDE_TFLAG_IN_DATA) { 236 if (cmd->tf_flags & IDE_FTFLAG_IN_DATA) {
237 u16 data; 237 u16 data;
238 238
239 at91_ide_input_data(drive, NULL, &data, 2); 239 at91_ide_input_data(drive, NULL, &data, 2);
@@ -244,31 +244,31 @@ static void at91_ide_tf_read(ide_drive_t *drive, ide_task_t *task)
244 /* be sure we're looking at the low order bits */ 244 /* be sure we're looking at the low order bits */
245 ide_mm_outb(ATA_DEVCTL_OBS & ~0x80, io_ports->ctl_addr); 245 ide_mm_outb(ATA_DEVCTL_OBS & ~0x80, io_ports->ctl_addr);
246 246
247 if (task->tf_flags & IDE_TFLAG_IN_FEATURE) 247 if (cmd->tf_flags & IDE_TFLAG_IN_FEATURE)
248 tf->feature = ide_mm_inb(io_ports->feature_addr); 248 tf->feature = ide_mm_inb(io_ports->feature_addr);
249 if (task->tf_flags & IDE_TFLAG_IN_NSECT) 249 if (cmd->tf_flags & IDE_TFLAG_IN_NSECT)
250 tf->nsect = ide_mm_inb(io_ports->nsect_addr); 250 tf->nsect = ide_mm_inb(io_ports->nsect_addr);
251 if (task->tf_flags & IDE_TFLAG_IN_LBAL) 251 if (cmd->tf_flags & IDE_TFLAG_IN_LBAL)
252 tf->lbal = ide_mm_inb(io_ports->lbal_addr); 252 tf->lbal = ide_mm_inb(io_ports->lbal_addr);
253 if (task->tf_flags & IDE_TFLAG_IN_LBAM) 253 if (cmd->tf_flags & IDE_TFLAG_IN_LBAM)
254 tf->lbam = ide_mm_inb(io_ports->lbam_addr); 254 tf->lbam = ide_mm_inb(io_ports->lbam_addr);
255 if (task->tf_flags & IDE_TFLAG_IN_LBAH) 255 if (cmd->tf_flags & IDE_TFLAG_IN_LBAH)
256 tf->lbah = ide_mm_inb(io_ports->lbah_addr); 256 tf->lbah = ide_mm_inb(io_ports->lbah_addr);
257 if (task->tf_flags & IDE_TFLAG_IN_DEVICE) 257 if (cmd->tf_flags & IDE_TFLAG_IN_DEVICE)
258 tf->device = ide_mm_inb(io_ports->device_addr); 258 tf->device = ide_mm_inb(io_ports->device_addr);
259 259
260 if (task->tf_flags & IDE_TFLAG_LBA48) { 260 if (cmd->tf_flags & IDE_TFLAG_LBA48) {
261 ide_mm_outb(ATA_DEVCTL_OBS | 0x80, io_ports->ctl_addr); 261 ide_mm_outb(ATA_DEVCTL_OBS | 0x80, io_ports->ctl_addr);
262 262
263 if (task->tf_flags & IDE_TFLAG_IN_HOB_FEATURE) 263 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_FEATURE)
264 tf->hob_feature = ide_mm_inb(io_ports->feature_addr); 264 tf->hob_feature = ide_mm_inb(io_ports->feature_addr);
265 if (task->tf_flags & IDE_TFLAG_IN_HOB_NSECT) 265 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_NSECT)
266 tf->hob_nsect = ide_mm_inb(io_ports->nsect_addr); 266 tf->hob_nsect = ide_mm_inb(io_ports->nsect_addr);
267 if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAL) 267 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAL)
268 tf->hob_lbal = ide_mm_inb(io_ports->lbal_addr); 268 tf->hob_lbal = ide_mm_inb(io_ports->lbal_addr);
269 if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAM) 269 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAM)
270 tf->hob_lbam = ide_mm_inb(io_ports->lbam_addr); 270 tf->hob_lbam = ide_mm_inb(io_ports->lbam_addr);
271 if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAH) 271 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAH)
272 tf->hob_lbah = ide_mm_inb(io_ports->lbah_addr); 272 tf->hob_lbah = ide_mm_inb(io_ports->lbah_addr);
273 } 273 }
274} 274}
diff --git a/drivers/ide/au1xxx-ide.c b/drivers/ide/au1xxx-ide.c
index 154ec2cf734f..d3a9d6c15328 100644
--- a/drivers/ide/au1xxx-ide.c
+++ b/drivers/ide/au1xxx-ide.c
@@ -86,13 +86,13 @@ void auide_outsw(unsigned long port, void *addr, u32 count)
86 ctp->cur_ptr = au1xxx_ddma_get_nextptr_virt(dp); 86 ctp->cur_ptr = au1xxx_ddma_get_nextptr_virt(dp);
87} 87}
88 88
89static void au1xxx_input_data(ide_drive_t *drive, struct request *rq, 89static void au1xxx_input_data(ide_drive_t *drive, struct ide_cmd *cmd,
90 void *buf, unsigned int len) 90 void *buf, unsigned int len)
91{ 91{
92 auide_insw(drive->hwif->io_ports.data_addr, buf, (len + 1) / 2); 92 auide_insw(drive->hwif->io_ports.data_addr, buf, (len + 1) / 2);
93} 93}
94 94
95static void au1xxx_output_data(ide_drive_t *drive, struct request *rq, 95static void au1xxx_output_data(ide_drive_t *drive, struct ide_cmd *cmd,
96 void *buf, unsigned int len) 96 void *buf, unsigned int len)
97{ 97{
98 auide_outsw(drive->hwif->io_ports.data_addr, buf, (len + 1) / 2); 98 auide_outsw(drive->hwif->io_ports.data_addr, buf, (len + 1) / 2);
@@ -209,23 +209,17 @@ static void auide_set_dma_mode(ide_drive_t *drive, const u8 speed)
209 */ 209 */
210 210
211#ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA 211#ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
212static int auide_build_dmatable(ide_drive_t *drive) 212static int auide_build_dmatable(ide_drive_t *drive, struct ide_cmd *cmd)
213{ 213{
214 int i, iswrite, count = 0;
215 ide_hwif_t *hwif = drive->hwif; 214 ide_hwif_t *hwif = drive->hwif;
216 struct request *rq = hwif->rq;
217 _auide_hwif *ahwif = &auide_hwif; 215 _auide_hwif *ahwif = &auide_hwif;
218 struct scatterlist *sg; 216 struct scatterlist *sg;
217 int i = cmd->sg_nents, count = 0;
218 int iswrite = !!(cmd->tf_flags & IDE_TFLAG_WRITE);
219 219
220 iswrite = (rq_data_dir(rq) == WRITE);
221 /* Save for interrupt context */ 220 /* Save for interrupt context */
222 ahwif->drive = drive; 221 ahwif->drive = drive;
223 222
224 hwif->sg_nents = i = ide_build_sglist(drive, rq);
225
226 if (!i)
227 return 0;
228
229 /* fill the descriptors */ 223 /* fill the descriptors */
230 sg = hwif->sg_table; 224 sg = hwif->sg_table;
231 while (i && sg_dma_len(sg)) { 225 while (i && sg_dma_len(sg)) {
@@ -286,12 +280,7 @@ static int auide_build_dmatable(ide_drive_t *drive)
286 280
287static int auide_dma_end(ide_drive_t *drive) 281static int auide_dma_end(ide_drive_t *drive)
288{ 282{
289 ide_hwif_t *hwif = drive->hwif; 283 ide_destroy_dmatable(drive);
290
291 if (hwif->sg_nents) {
292 ide_destroy_dmatable(drive);
293 hwif->sg_nents = 0;
294 }
295 284
296 return 0; 285 return 0;
297} 286}
@@ -301,19 +290,10 @@ static void auide_dma_start(ide_drive_t *drive )
301} 290}
302 291
303 292
304static void auide_dma_exec_cmd(ide_drive_t *drive, u8 command) 293static int auide_dma_setup(ide_drive_t *drive, struct ide_cmd *cmd)
305{ 294{
306 /* issue cmd to drive */ 295 if (auide_build_dmatable(drive, cmd) == 0) {
307 ide_execute_command(drive, command, &ide_dma_intr, 296 ide_map_sg(drive, cmd);
308 (2*WAIT_CMD), NULL);
309}
310
311static int auide_dma_setup(ide_drive_t *drive)
312{
313 struct request *rq = drive->hwif->rq;
314
315 if (!auide_build_dmatable(drive)) {
316 ide_map_sg(drive, rq);
317 return 1; 297 return 1;
318 } 298 }
319 299
@@ -369,7 +349,6 @@ static void auide_init_dbdma_dev(dbdev_tab_t *dev, u32 dev_id, u32 tsize, u32 de
369static const struct ide_dma_ops au1xxx_dma_ops = { 349static const struct ide_dma_ops au1xxx_dma_ops = {
370 .dma_host_set = auide_dma_host_set, 350 .dma_host_set = auide_dma_host_set,
371 .dma_setup = auide_dma_setup, 351 .dma_setup = auide_dma_setup,
372 .dma_exec_cmd = auide_dma_exec_cmd,
373 .dma_start = auide_dma_start, 352 .dma_start = auide_dma_start,
374 .dma_end = auide_dma_end, 353 .dma_end = auide_dma_end,
375 .dma_test_irq = auide_dma_test_irq, 354 .dma_test_irq = auide_dma_test_irq,
diff --git a/drivers/ide/buddha.c b/drivers/ide/buddha.c
index c5a3c9ef6a5d..d028f8864bc1 100644
--- a/drivers/ide/buddha.c
+++ b/drivers/ide/buddha.c
@@ -143,6 +143,11 @@ static void __init buddha_setup_ports(hw_regs_t *hw, unsigned long base,
143 hw->chipset = ide_generic; 143 hw->chipset = ide_generic;
144} 144}
145 145
146static const struct ide_port_info buddha_port_info = {
147 .host_flags = IDE_HFLAG_MMIO | IDE_HFLAG_NO_DMA,
148 .irq_flags = IRQF_SHARED,
149};
150
146 /* 151 /*
147 * Probe for a Buddha or Catweasel IDE interface 152 * Probe for a Buddha or Catweasel IDE interface
148 */ 153 */
@@ -172,10 +177,6 @@ static int __init buddha_init(void)
172 177
173 board = z->resource.start; 178 board = z->resource.start;
174 179
175/*
176 * FIXME: we now have selectable mmio v/s iomio transports.
177 */
178
179 if(type != BOARD_XSURF) { 180 if(type != BOARD_XSURF) {
180 if (!request_mem_region(board+BUDDHA_BASE1, 0x800, "IDE")) 181 if (!request_mem_region(board+BUDDHA_BASE1, 0x800, "IDE"))
181 continue; 182 continue;
@@ -224,7 +225,7 @@ fail_base2:
224 hws[i] = &hw[i]; 225 hws[i] = &hw[i];
225 } 226 }
226 227
227 ide_host_add(NULL, hws, NULL); 228 ide_host_add(&buddha_port_info, hws, NULL);
228 } 229 }
229 230
230 return 0; 231 return 0;
diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
index aeee036b1503..bf0e3f470824 100644
--- a/drivers/ide/cmd64x.c
+++ b/drivers/ide/cmd64x.c
@@ -379,11 +379,11 @@ static const struct ide_port_ops cmd64x_port_ops = {
379static const struct ide_dma_ops cmd64x_dma_ops = { 379static const struct ide_dma_ops cmd64x_dma_ops = {
380 .dma_host_set = ide_dma_host_set, 380 .dma_host_set = ide_dma_host_set,
381 .dma_setup = ide_dma_setup, 381 .dma_setup = ide_dma_setup,
382 .dma_exec_cmd = ide_dma_exec_cmd,
383 .dma_start = ide_dma_start, 382 .dma_start = ide_dma_start,
384 .dma_end = cmd64x_dma_end, 383 .dma_end = cmd64x_dma_end,
385 .dma_test_irq = cmd64x_dma_test_irq, 384 .dma_test_irq = cmd64x_dma_test_irq,
386 .dma_lost_irq = ide_dma_lost_irq, 385 .dma_lost_irq = ide_dma_lost_irq,
386 .dma_timer_expiry = ide_dma_sff_timer_expiry,
387 .dma_timeout = ide_dma_timeout, 387 .dma_timeout = ide_dma_timeout,
388 .dma_sff_read_status = ide_dma_sff_read_status, 388 .dma_sff_read_status = ide_dma_sff_read_status,
389}; 389};
@@ -391,11 +391,11 @@ static const struct ide_dma_ops cmd64x_dma_ops = {
391static const struct ide_dma_ops cmd646_rev1_dma_ops = { 391static const struct ide_dma_ops cmd646_rev1_dma_ops = {
392 .dma_host_set = ide_dma_host_set, 392 .dma_host_set = ide_dma_host_set,
393 .dma_setup = ide_dma_setup, 393 .dma_setup = ide_dma_setup,
394 .dma_exec_cmd = ide_dma_exec_cmd,
395 .dma_start = ide_dma_start, 394 .dma_start = ide_dma_start,
396 .dma_end = cmd646_1_dma_end, 395 .dma_end = cmd646_1_dma_end,
397 .dma_test_irq = ide_dma_test_irq, 396 .dma_test_irq = ide_dma_test_irq,
398 .dma_lost_irq = ide_dma_lost_irq, 397 .dma_lost_irq = ide_dma_lost_irq,
398 .dma_timer_expiry = ide_dma_sff_timer_expiry,
399 .dma_timeout = ide_dma_timeout, 399 .dma_timeout = ide_dma_timeout,
400 .dma_sff_read_status = ide_dma_sff_read_status, 400 .dma_sff_read_status = ide_dma_sff_read_status,
401}; 401};
@@ -403,11 +403,11 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
403static const struct ide_dma_ops cmd648_dma_ops = { 403static const struct ide_dma_ops cmd648_dma_ops = {
404 .dma_host_set = ide_dma_host_set, 404 .dma_host_set = ide_dma_host_set,
405 .dma_setup = ide_dma_setup, 405 .dma_setup = ide_dma_setup,
406 .dma_exec_cmd = ide_dma_exec_cmd,
407 .dma_start = ide_dma_start, 406 .dma_start = ide_dma_start,
408 .dma_end = cmd648_dma_end, 407 .dma_end = cmd648_dma_end,
409 .dma_test_irq = cmd648_dma_test_irq, 408 .dma_test_irq = cmd648_dma_test_irq,
410 .dma_lost_irq = ide_dma_lost_irq, 409 .dma_lost_irq = ide_dma_lost_irq,
410 .dma_timer_expiry = ide_dma_sff_timer_expiry,
411 .dma_timeout = ide_dma_timeout, 411 .dma_timeout = ide_dma_timeout,
412 .dma_sff_read_status = ide_dma_sff_read_status, 412 .dma_sff_read_status = ide_dma_sff_read_status,
413}; 413};
diff --git a/drivers/ide/cs5536.c b/drivers/ide/cs5536.c
index 7a62db719a46..d5dcf4899607 100644
--- a/drivers/ide/cs5536.c
+++ b/drivers/ide/cs5536.c
@@ -231,11 +231,11 @@ static const struct ide_port_ops cs5536_port_ops = {
231static const struct ide_dma_ops cs5536_dma_ops = { 231static const struct ide_dma_ops cs5536_dma_ops = {
232 .dma_host_set = ide_dma_host_set, 232 .dma_host_set = ide_dma_host_set,
233 .dma_setup = ide_dma_setup, 233 .dma_setup = ide_dma_setup,
234 .dma_exec_cmd = ide_dma_exec_cmd,
235 .dma_start = cs5536_dma_start, 234 .dma_start = cs5536_dma_start,
236 .dma_end = cs5536_dma_end, 235 .dma_end = cs5536_dma_end,
237 .dma_test_irq = ide_dma_test_irq, 236 .dma_test_irq = ide_dma_test_irq,
238 .dma_lost_irq = ide_dma_lost_irq, 237 .dma_lost_irq = ide_dma_lost_irq,
238 .dma_timer_expiry = ide_dma_sff_timer_expiry,
239 .dma_timeout = ide_dma_timeout, 239 .dma_timeout = ide_dma_timeout,
240}; 240};
241 241
diff --git a/drivers/ide/delkin_cb.c b/drivers/ide/delkin_cb.c
index bacb1194c9c9..f153b95619bb 100644
--- a/drivers/ide/delkin_cb.c
+++ b/drivers/ide/delkin_cb.c
@@ -66,6 +66,7 @@ static const struct ide_port_info delkin_cb_port_info = {
66 .port_ops = &delkin_cb_port_ops, 66 .port_ops = &delkin_cb_port_ops,
67 .host_flags = IDE_HFLAG_IO_32BIT | IDE_HFLAG_UNMASK_IRQS | 67 .host_flags = IDE_HFLAG_IO_32BIT | IDE_HFLAG_UNMASK_IRQS |
68 IDE_HFLAG_NO_DMA, 68 IDE_HFLAG_NO_DMA,
69 .irq_flags = IRQF_SHARED,
69 .init_chipset = delkin_cb_init_chipset, 70 .init_chipset = delkin_cb_init_chipset,
70}; 71};
71 72
diff --git a/drivers/ide/dtc2278.c b/drivers/ide/dtc2278.c
index 689b2e493413..c6b138122981 100644
--- a/drivers/ide/dtc2278.c
+++ b/drivers/ide/dtc2278.c
@@ -100,7 +100,8 @@ static const struct ide_port_info dtc2278_port_info __initdata = {
100 IDE_HFLAG_IO_32BIT | 100 IDE_HFLAG_IO_32BIT |
101 /* disallow ->io_32bit changes */ 101 /* disallow ->io_32bit changes */
102 IDE_HFLAG_NO_IO_32BIT | 102 IDE_HFLAG_NO_IO_32BIT |
103 IDE_HFLAG_NO_DMA, 103 IDE_HFLAG_NO_DMA |
104 IDE_HFLAG_DTC2278,
104 .pio_mask = ATA_PIO4, 105 .pio_mask = ATA_PIO4,
105}; 106};
106 107
diff --git a/drivers/ide/falconide.c b/drivers/ide/falconide.c
index a638e952d67a..b368a5effc3a 100644
--- a/drivers/ide/falconide.c
+++ b/drivers/ide/falconide.c
@@ -40,29 +40,48 @@
40 * which is shared between several drivers. 40 * which is shared between several drivers.
41 */ 41 */
42 42
43int falconide_intr_lock; 43static int falconide_intr_lock;
44EXPORT_SYMBOL(falconide_intr_lock);
45 44
46static void falconide_input_data(ide_drive_t *drive, struct request *rq, 45static void falconide_release_lock(void)
46{
47 if (falconide_intr_lock == 0) {
48 printk(KERN_ERR "%s: bug\n", __func__);
49 return;
50 }
51 falconide_intr_lock = 0;
52 stdma_release();
53}
54
55static void falconide_get_lock(irq_handler_t handler, void *data)
56{
57 if (falconide_intr_lock == 0) {
58 if (in_interrupt() > 0)
59 panic("Falcon IDE hasn't ST-DMA lock in interrupt");
60 stdma_lock(handler, data);
61 falconide_intr_lock = 1;
62 }
63}
64
65static void falconide_input_data(ide_drive_t *drive, struct ide_cmd *cmd,
47 void *buf, unsigned int len) 66 void *buf, unsigned int len)
48{ 67{
49 unsigned long data_addr = drive->hwif->io_ports.data_addr; 68 unsigned long data_addr = drive->hwif->io_ports.data_addr;
50 69
51 if (drive->media == ide_disk && rq && rq->cmd_type == REQ_TYPE_FS) 70 if (drive->media == ide_disk && cmd && (cmd->tf_flags & IDE_TFLAG_FS))
52 return insw(data_addr, buf, (len + 1) / 2); 71 return insw(data_addr, buf, (len + 1) / 2);
53 72
54 insw_swapw(data_addr, buf, (len + 1) / 2); 73 raw_insw_swapw((u16 *)data_addr, buf, (len + 1) / 2);
55} 74}
56 75
57static void falconide_output_data(ide_drive_t *drive, struct request *rq, 76static void falconide_output_data(ide_drive_t *drive, struct ide_cmd *cmd,
58 void *buf, unsigned int len) 77 void *buf, unsigned int len)
59{ 78{
60 unsigned long data_addr = drive->hwif->io_ports.data_addr; 79 unsigned long data_addr = drive->hwif->io_ports.data_addr;
61 80
62 if (drive->media == ide_disk && rq && rq->cmd_type == REQ_TYPE_FS) 81 if (drive->media == ide_disk && cmd && (cmd->tf_flags & IDE_TFLAG_FS))
63 return outsw(data_addr, buf, (len + 1) / 2); 82 return outsw(data_addr, buf, (len + 1) / 2);
64 83
65 outsw_swapw(data_addr, buf, (len + 1) / 2); 84 raw_outsw_swapw((u16 *)data_addr, buf, (len + 1) / 2);
66} 85}
67 86
68/* Atari has a byte-swapped IDE interface */ 87/* Atari has a byte-swapped IDE interface */
@@ -81,8 +100,12 @@ static const struct ide_tp_ops falconide_tp_ops = {
81}; 100};
82 101
83static const struct ide_port_info falconide_port_info = { 102static const struct ide_port_info falconide_port_info = {
103 .get_lock = falconide_get_lock,
104 .release_lock = falconide_release_lock,
84 .tp_ops = &falconide_tp_ops, 105 .tp_ops = &falconide_tp_ops,
85 .host_flags = IDE_HFLAG_NO_DMA | IDE_HFLAG_SERIALIZE, 106 .host_flags = IDE_HFLAG_MMIO | IDE_HFLAG_SERIALIZE |
107 IDE_HFLAG_NO_DMA,
108 .irq_flags = IRQF_SHARED,
86}; 109};
87 110
88static void __init falconide_setup_ports(hw_regs_t *hw) 111static void __init falconide_setup_ports(hw_regs_t *hw)
@@ -132,9 +155,9 @@ static int __init falconide_init(void)
132 goto err; 155 goto err;
133 } 156 }
134 157
135 ide_get_lock(NULL, NULL); 158 falconide_get_lock(NULL, NULL);
136 rc = ide_host_register(host, &falconide_port_info, hws); 159 rc = ide_host_register(host, &falconide_port_info, hws);
137 ide_release_lock(); 160 falconide_release_lock();
138 161
139 if (rc) 162 if (rc)
140 goto err_free; 163 goto err_free;
diff --git a/drivers/ide/gayle.c b/drivers/ide/gayle.c
index 59bd0be9dcb3..dc778251cb05 100644
--- a/drivers/ide/gayle.c
+++ b/drivers/ide/gayle.c
@@ -118,7 +118,9 @@ static void __init gayle_setup_ports(hw_regs_t *hw, unsigned long base,
118} 118}
119 119
120static const struct ide_port_info gayle_port_info = { 120static const struct ide_port_info gayle_port_info = {
121 .host_flags = IDE_HFLAG_SERIALIZE | IDE_HFLAG_NO_DMA, 121 .host_flags = IDE_HFLAG_MMIO | IDE_HFLAG_SERIALIZE |
122 IDE_HFLAG_NO_DMA,
123 .irq_flags = IRQF_SHARED,
122}; 124};
123 125
124 /* 126 /*
@@ -163,9 +165,6 @@ found:
163 irqport = (unsigned long)ZTWO_VADDR(GAYLE_IRQ_1200); 165 irqport = (unsigned long)ZTWO_VADDR(GAYLE_IRQ_1200);
164 ack_intr = gayle_ack_intr_a1200; 166 ack_intr = gayle_ack_intr_a1200;
165 } 167 }
166/*
167 * FIXME: we now have selectable modes between mmio v/s iomio
168 */
169 168
170 res_start = ((unsigned long)phys_base) & ~(GAYLE_NEXT_PORT-1); 169 res_start = ((unsigned long)phys_base) & ~(GAYLE_NEXT_PORT-1);
171 res_n = GAYLE_IDEREG_SIZE; 170 res_n = GAYLE_IDEREG_SIZE;
diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
index d3b3e824f445..dbaf184ed9c5 100644
--- a/drivers/ide/hpt366.c
+++ b/drivers/ide/hpt366.c
@@ -1418,11 +1418,11 @@ static const struct ide_port_ops hpt3xx_port_ops = {
1418static const struct ide_dma_ops hpt37x_dma_ops = { 1418static const struct ide_dma_ops hpt37x_dma_ops = {
1419 .dma_host_set = ide_dma_host_set, 1419 .dma_host_set = ide_dma_host_set,
1420 .dma_setup = ide_dma_setup, 1420 .dma_setup = ide_dma_setup,
1421 .dma_exec_cmd = ide_dma_exec_cmd,
1422 .dma_start = ide_dma_start, 1421 .dma_start = ide_dma_start,
1423 .dma_end = hpt374_dma_end, 1422 .dma_end = hpt374_dma_end,
1424 .dma_test_irq = hpt374_dma_test_irq, 1423 .dma_test_irq = hpt374_dma_test_irq,
1425 .dma_lost_irq = ide_dma_lost_irq, 1424 .dma_lost_irq = ide_dma_lost_irq,
1425 .dma_timer_expiry = ide_dma_sff_timer_expiry,
1426 .dma_timeout = ide_dma_timeout, 1426 .dma_timeout = ide_dma_timeout,
1427 .dma_sff_read_status = ide_dma_sff_read_status, 1427 .dma_sff_read_status = ide_dma_sff_read_status,
1428}; 1428};
@@ -1430,11 +1430,11 @@ static const struct ide_dma_ops hpt37x_dma_ops = {
1430static const struct ide_dma_ops hpt370_dma_ops = { 1430static const struct ide_dma_ops hpt370_dma_ops = {
1431 .dma_host_set = ide_dma_host_set, 1431 .dma_host_set = ide_dma_host_set,
1432 .dma_setup = ide_dma_setup, 1432 .dma_setup = ide_dma_setup,
1433 .dma_exec_cmd = ide_dma_exec_cmd,
1434 .dma_start = hpt370_dma_start, 1433 .dma_start = hpt370_dma_start,
1435 .dma_end = hpt370_dma_end, 1434 .dma_end = hpt370_dma_end,
1436 .dma_test_irq = ide_dma_test_irq, 1435 .dma_test_irq = ide_dma_test_irq,
1437 .dma_lost_irq = ide_dma_lost_irq, 1436 .dma_lost_irq = ide_dma_lost_irq,
1437 .dma_timer_expiry = ide_dma_sff_timer_expiry,
1438 .dma_timeout = hpt370_dma_timeout, 1438 .dma_timeout = hpt370_dma_timeout,
1439 .dma_sff_read_status = ide_dma_sff_read_status, 1439 .dma_sff_read_status = ide_dma_sff_read_status,
1440}; 1440};
@@ -1442,11 +1442,11 @@ static const struct ide_dma_ops hpt370_dma_ops = {
1442static const struct ide_dma_ops hpt36x_dma_ops = { 1442static const struct ide_dma_ops hpt36x_dma_ops = {
1443 .dma_host_set = ide_dma_host_set, 1443 .dma_host_set = ide_dma_host_set,
1444 .dma_setup = ide_dma_setup, 1444 .dma_setup = ide_dma_setup,
1445 .dma_exec_cmd = ide_dma_exec_cmd,
1446 .dma_start = ide_dma_start, 1445 .dma_start = ide_dma_start,
1447 .dma_end = ide_dma_end, 1446 .dma_end = ide_dma_end,
1448 .dma_test_irq = ide_dma_test_irq, 1447 .dma_test_irq = ide_dma_test_irq,
1449 .dma_lost_irq = hpt366_dma_lost_irq, 1448 .dma_lost_irq = hpt366_dma_lost_irq,
1449 .dma_timer_expiry = ide_dma_sff_timer_expiry,
1450 .dma_timeout = ide_dma_timeout, 1450 .dma_timeout = ide_dma_timeout,
1451 .dma_sff_read_status = ide_dma_sff_read_status, 1451 .dma_sff_read_status = ide_dma_sff_read_status,
1452}; 1452};
diff --git a/drivers/ide/icside.c b/drivers/ide/icside.c
index 415d7e24f2b6..51ce404fe532 100644
--- a/drivers/ide/icside.c
+++ b/drivers/ide/icside.c
@@ -307,15 +307,14 @@ static void icside_dma_start(ide_drive_t *drive)
307 enable_dma(ec->dma); 307 enable_dma(ec->dma);
308} 308}
309 309
310static int icside_dma_setup(ide_drive_t *drive) 310static int icside_dma_setup(ide_drive_t *drive, struct ide_cmd *cmd)
311{ 311{
312 ide_hwif_t *hwif = drive->hwif; 312 ide_hwif_t *hwif = drive->hwif;
313 struct expansion_card *ec = ECARD_DEV(hwif->dev); 313 struct expansion_card *ec = ECARD_DEV(hwif->dev);
314 struct icside_state *state = ecard_get_drvdata(ec); 314 struct icside_state *state = ecard_get_drvdata(ec);
315 struct request *rq = hwif->rq;
316 unsigned int dma_mode; 315 unsigned int dma_mode;
317 316
318 if (rq_data_dir(rq)) 317 if (cmd->tf_flags & IDE_TFLAG_WRITE)
319 dma_mode = DMA_MODE_WRITE; 318 dma_mode = DMA_MODE_WRITE;
320 else 319 else
321 dma_mode = DMA_MODE_READ; 320 dma_mode = DMA_MODE_READ;
@@ -325,8 +324,6 @@ static int icside_dma_setup(ide_drive_t *drive)
325 */ 324 */
326 BUG_ON(dma_channel_active(ec->dma)); 325 BUG_ON(dma_channel_active(ec->dma));
327 326
328 hwif->sg_nents = ide_build_sglist(drive, rq);
329
330 /* 327 /*
331 * Ensure that we have the right interrupt routed. 328 * Ensure that we have the right interrupt routed.
332 */ 329 */
@@ -346,7 +343,7 @@ static int icside_dma_setup(ide_drive_t *drive)
346 * Tell the DMA engine about the SG table and 343 * Tell the DMA engine about the SG table and
347 * data direction. 344 * data direction.
348 */ 345 */
349 set_dma_sg(ec->dma, hwif->sg_table, hwif->sg_nents); 346 set_dma_sg(ec->dma, hwif->sg_table, cmd->sg_nents);
350 set_dma_mode(ec->dma, dma_mode); 347 set_dma_mode(ec->dma, dma_mode);
351 348
352 drive->waiting_for_dma = 1; 349 drive->waiting_for_dma = 1;
@@ -354,12 +351,6 @@ static int icside_dma_setup(ide_drive_t *drive)
354 return 0; 351 return 0;
355} 352}
356 353
357static void icside_dma_exec_cmd(ide_drive_t *drive, u8 cmd)
358{
359 /* issue cmd to drive */
360 ide_execute_command(drive, cmd, ide_dma_intr, 2 * WAIT_CMD, NULL);
361}
362
363static int icside_dma_test_irq(ide_drive_t *drive) 354static int icside_dma_test_irq(ide_drive_t *drive)
364{ 355{
365 ide_hwif_t *hwif = drive->hwif; 356 ide_hwif_t *hwif = drive->hwif;
@@ -383,7 +374,6 @@ static int icside_dma_init(ide_hwif_t *hwif, const struct ide_port_info *d)
383static const struct ide_dma_ops icside_v6_dma_ops = { 374static const struct ide_dma_ops icside_v6_dma_ops = {
384 .dma_host_set = icside_dma_host_set, 375 .dma_host_set = icside_dma_host_set,
385 .dma_setup = icside_dma_setup, 376 .dma_setup = icside_dma_setup,
386 .dma_exec_cmd = icside_dma_exec_cmd,
387 .dma_start = icside_dma_start, 377 .dma_start = icside_dma_start,
388 .dma_end = icside_dma_end, 378 .dma_end = icside_dma_end,
389 .dma_test_irq = icside_dma_test_irq, 379 .dma_test_irq = icside_dma_test_irq,
@@ -419,6 +409,10 @@ static void icside_setup_ports(hw_regs_t *hw, void __iomem *base,
419 hw->chipset = ide_acorn; 409 hw->chipset = ide_acorn;
420} 410}
421 411
412static const struct ide_port_info icside_v5_port_info = {
413 .host_flags = IDE_HFLAG_NO_DMA,
414};
415
422static int __devinit 416static int __devinit
423icside_register_v5(struct icside_state *state, struct expansion_card *ec) 417icside_register_v5(struct icside_state *state, struct expansion_card *ec)
424{ 418{
@@ -445,7 +439,7 @@ icside_register_v5(struct icside_state *state, struct expansion_card *ec)
445 439
446 icside_setup_ports(&hw, base, &icside_cardinfo_v5, ec); 440 icside_setup_ports(&hw, base, &icside_cardinfo_v5, ec);
447 441
448 host = ide_host_alloc(NULL, hws); 442 host = ide_host_alloc(&icside_v5_port_info, hws);
449 if (host == NULL) 443 if (host == NULL)
450 return -ENODEV; 444 return -ENODEV;
451 445
@@ -453,7 +447,7 @@ icside_register_v5(struct icside_state *state, struct expansion_card *ec)
453 447
454 ecard_set_drvdata(ec, state); 448 ecard_set_drvdata(ec, state);
455 449
456 ret = ide_host_register(host, NULL, hws); 450 ret = ide_host_register(host, &icside_v5_port_info, hws);
457 if (ret) 451 if (ret)
458 goto err_free; 452 goto err_free;
459 453
diff --git a/drivers/ide/ide-4drives.c b/drivers/ide/ide-4drives.c
index 9e85b1ec9607..78aca75a2c48 100644
--- a/drivers/ide/ide-4drives.c
+++ b/drivers/ide/ide-4drives.c
@@ -23,7 +23,8 @@ static const struct ide_port_ops ide_4drives_port_ops = {
23 23
24static const struct ide_port_info ide_4drives_port_info = { 24static const struct ide_port_info ide_4drives_port_info = {
25 .port_ops = &ide_4drives_port_ops, 25 .port_ops = &ide_4drives_port_ops,
26 .host_flags = IDE_HFLAG_SERIALIZE | IDE_HFLAG_NO_DMA, 26 .host_flags = IDE_HFLAG_SERIALIZE | IDE_HFLAG_NO_DMA |
27 IDE_HFLAG_4DRIVES,
27}; 28};
28 29
29static int __init ide_4drives_init(void) 30static int __init ide_4drives_init(void)
diff --git a/drivers/ide/ide-acpi.c b/drivers/ide/ide-acpi.c
index 5b704f1ea90c..12f436951bff 100644
--- a/drivers/ide/ide-acpi.c
+++ b/drivers/ide/ide-acpi.c
@@ -304,7 +304,7 @@ static int do_drive_set_taskfiles(ide_drive_t *drive,
304 /* send all taskfile registers (0x1f1-0x1f7) *in*that*order* */ 304 /* send all taskfile registers (0x1f1-0x1f7) *in*that*order* */
305 for (ix = 0; ix < gtf_count; ix++) { 305 for (ix = 0; ix < gtf_count; ix++) {
306 u8 *gtf = (u8 *)(gtf_address + ix * REGS_PER_GTF); 306 u8 *gtf = (u8 *)(gtf_address + ix * REGS_PER_GTF);
307 ide_task_t task; 307 struct ide_cmd cmd;
308 308
309 DEBPRINT("(0x1f1-1f7): " 309 DEBPRINT("(0x1f1-1f7): "
310 "hex: %02x %02x %02x %02x %02x %02x %02x\n", 310 "hex: %02x %02x %02x %02x %02x %02x %02x\n",
@@ -317,11 +317,11 @@ static int do_drive_set_taskfiles(ide_drive_t *drive,
317 } 317 }
318 318
319 /* convert GTF to taskfile */ 319 /* convert GTF to taskfile */
320 memset(&task, 0, sizeof(ide_task_t)); 320 memset(&cmd, 0, sizeof(cmd));
321 memcpy(&task.tf_array[7], gtf, REGS_PER_GTF); 321 memcpy(&cmd.tf_array[7], gtf, REGS_PER_GTF);
322 task.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; 322 cmd.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
323 323
324 err = ide_no_data_taskfile(drive, &task); 324 err = ide_no_data_taskfile(drive, &cmd);
325 if (err) { 325 if (err) {
326 printk(KERN_ERR "%s: ide_no_data_taskfile failed: %u\n", 326 printk(KERN_ERR "%s: ide_no_data_taskfile failed: %u\n",
327 __func__, err); 327 __func__, err);
diff --git a/drivers/ide/ide-atapi.c b/drivers/ide/ide-atapi.c
index 6adc5b4a4406..2fb5d28a9be5 100644
--- a/drivers/ide/ide-atapi.c
+++ b/drivers/ide/ide-atapi.c
@@ -302,16 +302,16 @@ EXPORT_SYMBOL_GPL(ide_cd_get_xferlen);
302 302
303void ide_read_bcount_and_ireason(ide_drive_t *drive, u16 *bcount, u8 *ireason) 303void ide_read_bcount_and_ireason(ide_drive_t *drive, u16 *bcount, u8 *ireason)
304{ 304{
305 ide_task_t task; 305 struct ide_cmd cmd;
306 306
307 memset(&task, 0, sizeof(task)); 307 memset(&cmd, 0, sizeof(cmd));
308 task.tf_flags = IDE_TFLAG_IN_LBAH | IDE_TFLAG_IN_LBAM | 308 cmd.tf_flags = IDE_TFLAG_IN_LBAH | IDE_TFLAG_IN_LBAM |
309 IDE_TFLAG_IN_NSECT; 309 IDE_TFLAG_IN_NSECT;
310 310
311 drive->hwif->tp_ops->tf_read(drive, &task); 311 drive->hwif->tp_ops->tf_read(drive, &cmd);
312 312
313 *bcount = (task.tf.lbah << 8) | task.tf.lbam; 313 *bcount = (cmd.tf.lbah << 8) | cmd.tf.lbam;
314 *ireason = task.tf.nsect & 3; 314 *ireason = cmd.tf.nsect & 3;
315} 315}
316EXPORT_SYMBOL_GPL(ide_read_bcount_and_ireason); 316EXPORT_SYMBOL_GPL(ide_read_bcount_and_ireason);
317 317
@@ -336,11 +336,6 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
336 timeout = (drive->media == ide_floppy) ? WAIT_FLOPPY_CMD 336 timeout = (drive->media == ide_floppy) ? WAIT_FLOPPY_CMD
337 : WAIT_TAPE_CMD; 337 : WAIT_TAPE_CMD;
338 338
339 if (pc->flags & PC_FLAG_TIMEDOUT) {
340 drive->pc_callback(drive, 0);
341 return ide_stopped;
342 }
343
344 /* Clear the interrupt */ 339 /* Clear the interrupt */
345 stat = tp_ops->read_status(hwif); 340 stat = tp_ops->read_status(hwif);
346 341
@@ -362,6 +357,8 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
362 357
363 /* No more interrupts */ 358 /* No more interrupts */
364 if ((stat & ATA_DRQ) == 0) { 359 if ((stat & ATA_DRQ) == 0) {
360 int uptodate;
361
365 debug_log("Packet command completed, %d bytes transferred\n", 362 debug_log("Packet command completed, %d bytes transferred\n",
366 pc->xferred); 363 pc->xferred);
367 364
@@ -400,7 +397,22 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
400 dsc = 1; 397 dsc = 1;
401 398
402 /* Command finished - Call the callback function */ 399 /* Command finished - Call the callback function */
403 drive->pc_callback(drive, dsc); 400 uptodate = drive->pc_callback(drive, dsc);
401
402 if (uptodate == 0)
403 drive->failed_pc = NULL;
404
405 if (blk_special_request(rq)) {
406 rq->errors = 0;
407 ide_complete_rq(drive, 0, blk_rq_bytes(rq));
408 } else {
409 if (blk_fs_request(rq) == 0 && uptodate <= 0) {
410 if (rq->errors == 0)
411 rq->errors = -EIO;
412 }
413 ide_complete_rq(drive, uptodate ? 0 : -EIO,
414 ide_rq_bytes(rq));
415 }
404 416
405 return ide_stopped; 417 return ide_stopped;
406 } 418 }
@@ -458,7 +470,8 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
458 470
459 /* FIXME: don't do partial completions */ 471 /* FIXME: don't do partial completions */
460 if (drive->media == ide_floppy) 472 if (drive->media == ide_floppy)
461 ide_end_request(drive, 1, done >> 9); 473 ide_complete_rq(drive, 0,
474 done ? done : ide_rq_bytes(rq));
462 } else 475 } else
463 xferfunc(drive, NULL, pc->cur_pos, bcount); 476 xferfunc(drive, NULL, pc->cur_pos, bcount);
464 477
@@ -470,39 +483,32 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
470 rq->cmd[0], bcount); 483 rq->cmd[0], bcount);
471next_irq: 484next_irq:
472 /* And set the interrupt handler again */ 485 /* And set the interrupt handler again */
473 ide_set_handler(drive, ide_pc_intr, timeout, NULL); 486 ide_set_handler(drive, ide_pc_intr, timeout);
474 return ide_started; 487 return ide_started;
475} 488}
476 489
477static void ide_pktcmd_tf_load(ide_drive_t *drive, u32 tf_flags, u16 bcount) 490static void ide_init_packet_cmd(struct ide_cmd *cmd, u32 tf_flags,
491 u16 bcount, u8 dma)
478{ 492{
479 ide_hwif_t *hwif = drive->hwif; 493 cmd->protocol = dma ? ATAPI_PROT_DMA : ATAPI_PROT_PIO;
480 ide_task_t task; 494 cmd->tf_flags |= IDE_TFLAG_OUT_LBAH | IDE_TFLAG_OUT_LBAM |
481 u8 dma = drive->dma; 495 IDE_TFLAG_OUT_FEATURE | tf_flags;
482 496 cmd->tf.command = ATA_CMD_PACKET;
483 memset(&task, 0, sizeof(task)); 497 cmd->tf.feature = dma; /* Use PIO/DMA */
484 task.tf_flags = IDE_TFLAG_OUT_LBAH | IDE_TFLAG_OUT_LBAM | 498 cmd->tf.lbam = bcount & 0xff;
485 IDE_TFLAG_OUT_FEATURE | tf_flags; 499 cmd->tf.lbah = (bcount >> 8) & 0xff;
486 task.tf.feature = dma; /* Use PIO/DMA */
487 task.tf.lbam = bcount & 0xff;
488 task.tf.lbah = (bcount >> 8) & 0xff;
489
490 ide_tf_dump(drive->name, &task.tf);
491 hwif->tp_ops->set_irq(hwif, 1);
492 SELECT_MASK(drive, 0);
493 hwif->tp_ops->tf_load(drive, &task);
494} 500}
495 501
496static u8 ide_read_ireason(ide_drive_t *drive) 502static u8 ide_read_ireason(ide_drive_t *drive)
497{ 503{
498 ide_task_t task; 504 struct ide_cmd cmd;
499 505
500 memset(&task, 0, sizeof(task)); 506 memset(&cmd, 0, sizeof(cmd));
501 task.tf_flags = IDE_TFLAG_IN_NSECT; 507 cmd.tf_flags = IDE_TFLAG_IN_NSECT;
502 508
503 drive->hwif->tp_ops->tf_read(drive, &task); 509 drive->hwif->tp_ops->tf_read(drive, &cmd);
504 510
505 return task.tf.nsect & 3; 511 return cmd.tf.nsect & 3;
506} 512}
507 513
508static u8 ide_wait_ireason(ide_drive_t *drive, u8 ireason) 514static u8 ide_wait_ireason(ide_drive_t *drive, u8 ireason)
@@ -597,11 +603,13 @@ static ide_startstop_t ide_transfer_pc(ide_drive_t *drive)
597 } 603 }
598 } 604 }
599 605
606 hwif->expiry = expiry;
607
600 /* Set the interrupt routine */ 608 /* Set the interrupt routine */
601 ide_set_handler(drive, 609 ide_set_handler(drive,
602 (dev_is_idecd(drive) ? drive->irq_handler 610 (dev_is_idecd(drive) ? drive->irq_handler
603 : ide_pc_intr), 611 : ide_pc_intr),
604 timeout, expiry); 612 timeout);
605 613
606 /* Begin DMA, if necessary */ 614 /* Begin DMA, if necessary */
607 if (dev_is_idecd(drive)) { 615 if (dev_is_idecd(drive)) {
@@ -621,23 +629,30 @@ static ide_startstop_t ide_transfer_pc(ide_drive_t *drive)
621 return ide_started; 629 return ide_started;
622} 630}
623 631
624ide_startstop_t ide_issue_pc(ide_drive_t *drive) 632ide_startstop_t ide_issue_pc(ide_drive_t *drive, struct ide_cmd *cmd)
625{ 633{
626 struct ide_atapi_pc *pc; 634 struct ide_atapi_pc *pc;
627 ide_hwif_t *hwif = drive->hwif; 635 ide_hwif_t *hwif = drive->hwif;
636 const struct ide_dma_ops *dma_ops = hwif->dma_ops;
628 ide_expiry_t *expiry = NULL; 637 ide_expiry_t *expiry = NULL;
638 struct request *rq = hwif->rq;
629 unsigned int timeout; 639 unsigned int timeout;
630 u32 tf_flags; 640 u32 tf_flags;
631 u16 bcount; 641 u16 bcount;
642 u8 drq_int = !!(drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT);
632 643
633 if (dev_is_idecd(drive)) { 644 if (dev_is_idecd(drive)) {
634 tf_flags = IDE_TFLAG_OUT_NSECT | IDE_TFLAG_OUT_LBAL; 645 tf_flags = IDE_TFLAG_OUT_NSECT | IDE_TFLAG_OUT_LBAL;
635 bcount = ide_cd_get_xferlen(hwif->rq); 646 bcount = ide_cd_get_xferlen(rq);
636 expiry = ide_cd_expiry; 647 expiry = ide_cd_expiry;
637 timeout = ATAPI_WAIT_PC; 648 timeout = ATAPI_WAIT_PC;
638 649
639 if (drive->dma) 650 if (drive->dma) {
640 drive->dma = !hwif->dma_ops->dma_setup(drive); 651 if (ide_build_sglist(drive, cmd))
652 drive->dma = !dma_ops->dma_setup(drive, cmd);
653 else
654 drive->dma = 0;
655 }
641 } else { 656 } else {
642 pc = drive->pc; 657 pc = drive->pc;
643 658
@@ -656,8 +671,12 @@ ide_startstop_t ide_issue_pc(ide_drive_t *drive)
656 } 671 }
657 672
658 if ((pc->flags & PC_FLAG_DMA_OK) && 673 if ((pc->flags & PC_FLAG_DMA_OK) &&
659 (drive->dev_flags & IDE_DFLAG_USING_DMA)) 674 (drive->dev_flags & IDE_DFLAG_USING_DMA)) {
660 drive->dma = !hwif->dma_ops->dma_setup(drive); 675 if (ide_build_sglist(drive, cmd))
676 drive->dma = !dma_ops->dma_setup(drive, cmd);
677 else
678 drive->dma = 0;
679 }
661 680
662 if (!drive->dma) 681 if (!drive->dma)
663 pc->flags &= ~PC_FLAG_DMA_OK; 682 pc->flags &= ~PC_FLAG_DMA_OK;
@@ -666,18 +685,18 @@ ide_startstop_t ide_issue_pc(ide_drive_t *drive)
666 : WAIT_TAPE_CMD; 685 : WAIT_TAPE_CMD;
667 } 686 }
668 687
669 ide_pktcmd_tf_load(drive, tf_flags, bcount); 688 ide_init_packet_cmd(cmd, tf_flags, bcount, drive->dma);
670 689
671 /* Issue the packet command */ 690 (void)do_rw_taskfile(drive, cmd);
672 if (drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT) { 691
692 if (drq_int) {
673 if (drive->dma) 693 if (drive->dma)
674 drive->waiting_for_dma = 0; 694 drive->waiting_for_dma = 0;
675 ide_execute_command(drive, ATA_CMD_PACKET, ide_transfer_pc, 695 hwif->expiry = expiry;
676 timeout, expiry);
677 return ide_started;
678 } else {
679 ide_execute_pkt_cmd(drive);
680 return ide_transfer_pc(drive);
681 } 696 }
697
698 ide_execute_command(drive, cmd, ide_transfer_pc, timeout);
699
700 return drq_int ? ide_started : ide_transfer_pc(drive);
682} 701}
683EXPORT_SYMBOL_GPL(ide_issue_pc); 702EXPORT_SYMBOL_GPL(ide_issue_pc);
diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
index 2177cd11664c..3f630e4080d4 100644
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -100,8 +100,7 @@ static int cdrom_log_sense(ide_drive_t *drive, struct request *rq,
100{ 100{
101 int log = 0; 101 int log = 0;
102 102
103 ide_debug_log(IDE_DBG_SENSE, "Call %s, sense_key: 0x%x\n", __func__, 103 ide_debug_log(IDE_DBG_SENSE, "sense_key: 0x%x", sense->sense_key);
104 sense->sense_key);
105 104
106 if (!sense || !rq || (rq->cmd_flags & REQ_QUIET)) 105 if (!sense || !rq || (rq->cmd_flags & REQ_QUIET))
107 return 0; 106 return 0;
@@ -151,13 +150,12 @@ static void cdrom_analyze_sense_data(ide_drive_t *drive,
151 unsigned long bio_sectors; 150 unsigned long bio_sectors;
152 struct cdrom_info *info = drive->driver_data; 151 struct cdrom_info *info = drive->driver_data;
153 152
154 ide_debug_log(IDE_DBG_SENSE, "Call %s, error_code: 0x%x, " 153 ide_debug_log(IDE_DBG_SENSE, "error_code: 0x%x, sense_key: 0x%x",
155 "sense_key: 0x%x\n", __func__, sense->error_code, 154 sense->error_code, sense->sense_key);
156 sense->sense_key);
157 155
158 if (failed_command) 156 if (failed_command)
159 ide_debug_log(IDE_DBG_SENSE, "%s: failed cmd: 0x%x\n", 157 ide_debug_log(IDE_DBG_SENSE, "failed cmd: 0x%x",
160 __func__, failed_command->cmd[0]); 158 failed_command->cmd[0]);
161 159
162 if (!cdrom_log_sense(drive, failed_command, sense)) 160 if (!cdrom_log_sense(drive, failed_command, sense))
163 return; 161 return;
@@ -215,9 +213,9 @@ static void cdrom_queue_request_sense(ide_drive_t *drive, void *sense,
215 struct request *failed_command) 213 struct request *failed_command)
216{ 214{
217 struct cdrom_info *info = drive->driver_data; 215 struct cdrom_info *info = drive->driver_data;
218 struct request *rq = &info->request_sense_request; 216 struct request *rq = &drive->request_sense_rq;
219 217
220 ide_debug_log(IDE_DBG_SENSE, "Call %s\n", __func__); 218 ide_debug_log(IDE_DBG_SENSE, "enter");
221 219
222 if (sense == NULL) 220 if (sense == NULL)
223 sense = &info->sense_data; 221 sense = &info->sense_data;
@@ -239,8 +237,8 @@ static void cdrom_queue_request_sense(ide_drive_t *drive, void *sense,
239 rq->buffer = (void *) failed_command; 237 rq->buffer = (void *) failed_command;
240 238
241 if (failed_command) 239 if (failed_command)
242 ide_debug_log(IDE_DBG_SENSE, "failed_cmd: 0x%x\n", 240 ide_debug_log(IDE_DBG_SENSE, "failed_cmd: 0x%x",
243 failed_command->cmd[0]); 241 failed_command->cmd[0]);
244 242
245 drive->hwif->rq = NULL; 243 drive->hwif->rq = NULL;
246 244
@@ -252,9 +250,8 @@ static void cdrom_end_request(ide_drive_t *drive, int uptodate)
252 struct request *rq = drive->hwif->rq; 250 struct request *rq = drive->hwif->rq;
253 int nsectors = rq->hard_cur_sectors; 251 int nsectors = rq->hard_cur_sectors;
254 252
255 ide_debug_log(IDE_DBG_FUNC, "Call %s, cmd: 0x%x, uptodate: 0x%x, " 253 ide_debug_log(IDE_DBG_FUNC, "cmd: 0x%x, uptodate: 0x%x, nsectors: %d",
256 "nsectors: %d\n", __func__, rq->cmd[0], uptodate, 254 rq->cmd[0], uptodate, nsectors);
257 nsectors);
258 255
259 if (blk_sense_request(rq) && uptodate) { 256 if (blk_sense_request(rq) && uptodate) {
260 /* 257 /*
@@ -275,8 +272,8 @@ static void cdrom_end_request(ide_drive_t *drive, int uptodate)
275 * now end the failed request 272 * now end the failed request
276 */ 273 */
277 if (blk_fs_request(failed)) { 274 if (blk_fs_request(failed)) {
278 if (ide_end_dequeued_request(drive, failed, 0, 275 if (ide_end_rq(drive, failed, -EIO,
279 failed->hard_nr_sectors)) 276 failed->hard_nr_sectors << 9))
280 BUG(); 277 BUG();
281 } else { 278 } else {
282 if (blk_end_request(failed, -EIO, 279 if (blk_end_request(failed, -EIO,
@@ -295,10 +292,13 @@ static void cdrom_end_request(ide_drive_t *drive, int uptodate)
295 if (!nsectors) 292 if (!nsectors)
296 nsectors = 1; 293 nsectors = 1;
297 294
298 ide_debug_log(IDE_DBG_FUNC, "Exit %s, uptodate: 0x%x, nsectors: %d\n", 295 ide_debug_log(IDE_DBG_FUNC, "uptodate: 0x%x, nsectors: %d",
299 __func__, uptodate, nsectors); 296 uptodate, nsectors);
300 297
301 ide_end_request(drive, uptodate, nsectors); 298 if (blk_fs_request(rq) == 0 && uptodate <= 0 && rq->errors == 0)
299 rq->errors = -EIO;
300
301 ide_complete_rq(drive, uptodate ? 0 : -EIO, nsectors << 9);
302} 302}
303 303
304static void ide_dump_status_no_sense(ide_drive_t *drive, const char *msg, u8 st) 304static void ide_dump_status_no_sense(ide_drive_t *drive, const char *msg, u8 st)
@@ -338,9 +338,10 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
338 return 1; 338 return 1;
339 } 339 }
340 340
341 ide_debug_log(IDE_DBG_RQ, "%s: stat: 0x%x, good_stat: 0x%x, " 341 ide_debug_log(IDE_DBG_RQ, "stat: 0x%x, good_stat: 0x%x, cmd[0]: 0x%x, "
342 "rq->cmd[0]: 0x%x, rq->cmd_type: 0x%x, err: 0x%x\n", 342 "rq->cmd_type: 0x%x, err: 0x%x",
343 __func__, stat, good_stat, rq->cmd[0], rq->cmd_type, err); 343 stat, good_stat, rq->cmd[0], rq->cmd_type,
344 err);
344 345
345 if (blk_sense_request(rq)) { 346 if (blk_sense_request(rq)) {
346 /* 347 /*
@@ -530,8 +531,7 @@ static int ide_cd_check_ireason(ide_drive_t *drive, struct request *rq,
530{ 531{
531 ide_hwif_t *hwif = drive->hwif; 532 ide_hwif_t *hwif = drive->hwif;
532 533
533 ide_debug_log(IDE_DBG_FUNC, "Call %s, ireason: 0x%x, rw: 0x%x\n", 534 ide_debug_log(IDE_DBG_FUNC, "ireason: 0x%x, rw: 0x%x", ireason, rw);
534 __func__, ireason, rw);
535 535
536 /* 536 /*
537 * ireason == 0: the drive wants to receive data from us 537 * ireason == 0: the drive wants to receive data from us
@@ -572,7 +572,7 @@ static int ide_cd_check_ireason(ide_drive_t *drive, struct request *rq,
572 */ 572 */
573static int ide_cd_check_transfer_size(ide_drive_t *drive, int len) 573static int ide_cd_check_transfer_size(ide_drive_t *drive, int len)
574{ 574{
575 ide_debug_log(IDE_DBG_FUNC, "Call %s, len: %d\n", __func__, len); 575 ide_debug_log(IDE_DBG_FUNC, "len: %d", len);
576 576
577 if ((len % SECTOR_SIZE) == 0) 577 if ((len % SECTOR_SIZE) == 0)
578 return 0; 578 return 0;
@@ -594,8 +594,7 @@ static int ide_cd_check_transfer_size(ide_drive_t *drive, int len)
594static ide_startstop_t ide_cd_prepare_rw_request(ide_drive_t *drive, 594static ide_startstop_t ide_cd_prepare_rw_request(ide_drive_t *drive,
595 struct request *rq) 595 struct request *rq)
596{ 596{
597 ide_debug_log(IDE_DBG_RQ, "Call %s: rq->cmd_flags: 0x%x\n", __func__, 597 ide_debug_log(IDE_DBG_RQ, "rq->cmd_flags: 0x%x", rq->cmd_flags);
598 rq->cmd_flags);
599 598
600 if (rq_data_dir(rq) == READ) { 599 if (rq_data_dir(rq) == READ) {
601 unsigned short sectors_per_frame = 600 unsigned short sectors_per_frame =
@@ -639,7 +638,7 @@ static ide_startstop_t ide_cd_prepare_rw_request(ide_drive_t *drive,
639static void ide_cd_restore_request(ide_drive_t *drive, struct request *rq) 638static void ide_cd_restore_request(ide_drive_t *drive, struct request *rq)
640{ 639{
641 640
642 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__); 641 ide_debug_log(IDE_DBG_FUNC, "enter");
643 642
644 if (rq->buffer != bio_data(rq->bio)) { 643 if (rq->buffer != bio_data(rq->bio)) {
645 sector_t n = 644 sector_t n =
@@ -658,8 +657,7 @@ static void ide_cd_restore_request(ide_drive_t *drive, struct request *rq)
658 657
659static void ide_cd_request_sense_fixup(ide_drive_t *drive, struct request *rq) 658static void ide_cd_request_sense_fixup(ide_drive_t *drive, struct request *rq)
660{ 659{
661 ide_debug_log(IDE_DBG_FUNC, "Call %s, rq->cmd[0]: 0x%x\n", 660 ide_debug_log(IDE_DBG_FUNC, "rq->cmd[0]: 0x%x", rq->cmd[0]);
662 __func__, rq->cmd[0]);
663 661
664 /* 662 /*
665 * Some of the trailing request sense fields are optional, 663 * Some of the trailing request sense fields are optional,
@@ -686,9 +684,9 @@ int ide_cd_queue_pc(ide_drive_t *drive, const unsigned char *cmd,
686 if (!sense) 684 if (!sense)
687 sense = &local_sense; 685 sense = &local_sense;
688 686
689 ide_debug_log(IDE_DBG_PC, "Call %s, cmd[0]: 0x%x, write: 0x%x, " 687 ide_debug_log(IDE_DBG_PC, "cmd[0]: 0x%x, write: 0x%x, timeout: %d, "
690 "timeout: %d, cmd_flags: 0x%x\n", __func__, cmd[0], write, 688 "cmd_flags: 0x%x",
691 timeout, cmd_flags); 689 cmd[0], write, timeout, cmd_flags);
692 690
693 /* start of retry loop */ 691 /* start of retry loop */
694 do { 692 do {
@@ -772,8 +770,8 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
772 u16 len; 770 u16 len;
773 u8 ireason; 771 u8 ireason;
774 772
775 ide_debug_log(IDE_DBG_PC, "Call %s, rq->cmd[0]: 0x%x, write: 0x%x\n", 773 ide_debug_log(IDE_DBG_PC, "cmd[0]: 0x%x, write: 0x%x",
776 __func__, rq->cmd[0], write); 774 rq->cmd[0], write);
777 775
778 /* check for errors */ 776 /* check for errors */
779 dma = drive->dma; 777 dma = drive->dma;
@@ -795,10 +793,11 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
795 if (dma_error) 793 if (dma_error)
796 return ide_error(drive, "dma error", stat); 794 return ide_error(drive, "dma error", stat);
797 if (blk_fs_request(rq)) { 795 if (blk_fs_request(rq)) {
798 ide_end_request(drive, 1, rq->nr_sectors); 796 ide_complete_rq(drive, 0, rq->nr_sectors
797 ? (rq->nr_sectors << 9) : ide_rq_bytes(rq));
799 return ide_stopped; 798 return ide_stopped;
800 } else if (rq->cmd_type == REQ_TYPE_ATA_PC && !rq->bio) { 799 } else if (rq->cmd_type == REQ_TYPE_ATA_PC && !rq->bio) {
801 ide_end_request(drive, 1, 1); 800 ide_complete_rq(drive, 0, 512);
802 return ide_stopped; 801 return ide_stopped;
803 } 802 }
804 goto end_request; 803 goto end_request;
@@ -810,8 +809,8 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
810 if (thislen > len) 809 if (thislen > len)
811 thislen = len; 810 thislen = len;
812 811
813 ide_debug_log(IDE_DBG_PC, "%s: DRQ: stat: 0x%x, thislen: %d\n", 812 ide_debug_log(IDE_DBG_PC, "DRQ: stat: 0x%x, thislen: %d",
814 __func__, stat, thislen); 813 stat, thislen);
815 814
816 /* If DRQ is clear, the command has completed. */ 815 /* If DRQ is clear, the command has completed. */
817 if ((stat & ATA_DRQ) == 0) { 816 if ((stat & ATA_DRQ) == 0) {
@@ -876,8 +875,9 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
876 xferfunc = hwif->tp_ops->input_data; 875 xferfunc = hwif->tp_ops->input_data;
877 } 876 }
878 877
879 ide_debug_log(IDE_DBG_PC, "%s: data transfer, rq->cmd_type: 0x%x, " 878 ide_debug_log(IDE_DBG_PC, "data transfer, rq->cmd_type: 0x%x, "
880 "ireason: 0x%x\n", __func__, rq->cmd_type, ireason); 879 "ireason: 0x%x",
880 rq->cmd_type, ireason);
881 881
882 /* transfer data */ 882 /* transfer data */
883 while (thislen > 0) { 883 while (thislen > 0) {
@@ -959,7 +959,8 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
959 expiry = ide_cd_expiry; 959 expiry = ide_cd_expiry;
960 } 960 }
961 961
962 ide_set_handler(drive, cdrom_newpc_intr, timeout, expiry); 962 hwif->expiry = expiry;
963 ide_set_handler(drive, cdrom_newpc_intr, timeout);
963 return ide_started; 964 return ide_started;
964 965
965end_request: 966end_request:
@@ -988,9 +989,9 @@ static ide_startstop_t cdrom_start_rw(ide_drive_t *drive, struct request *rq)
988 unsigned short sectors_per_frame = 989 unsigned short sectors_per_frame =
989 queue_hardsect_size(drive->queue) >> SECTOR_BITS; 990 queue_hardsect_size(drive->queue) >> SECTOR_BITS;
990 991
991 ide_debug_log(IDE_DBG_RQ, "Call %s, rq->cmd[0]: 0x%x, write: 0x%x, " 992 ide_debug_log(IDE_DBG_RQ, "rq->cmd[0]: 0x%x, write: 0x%x, "
992 "secs_per_frame: %u\n", 993 "secs_per_frame: %u",
993 __func__, rq->cmd[0], write, sectors_per_frame); 994 rq->cmd[0], write, sectors_per_frame);
994 995
995 if (write) { 996 if (write) {
996 /* disk has become write protected */ 997 /* disk has become write protected */
@@ -1026,9 +1027,8 @@ static ide_startstop_t cdrom_start_rw(ide_drive_t *drive, struct request *rq)
1026static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq) 1027static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
1027{ 1028{
1028 1029
1029 ide_debug_log(IDE_DBG_PC, "Call %s, rq->cmd[0]: 0x%x, " 1030 ide_debug_log(IDE_DBG_PC, "rq->cmd[0]: 0x%x, rq->cmd_type: 0x%x",
1030 "rq->cmd_type: 0x%x\n", __func__, rq->cmd[0], 1031 rq->cmd[0], rq->cmd_type);
1031 rq->cmd_type);
1032 1032
1033 if (blk_pc_request(rq)) 1033 if (blk_pc_request(rq))
1034 rq->cmd_flags |= REQ_QUIET; 1034 rq->cmd_flags |= REQ_QUIET;
@@ -1067,10 +1067,13 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
1067static ide_startstop_t ide_cd_do_request(ide_drive_t *drive, struct request *rq, 1067static ide_startstop_t ide_cd_do_request(ide_drive_t *drive, struct request *rq,
1068 sector_t block) 1068 sector_t block)
1069{ 1069{
1070 ide_debug_log(IDE_DBG_RQ, "Call %s, rq->cmd[0]: 0x%x, " 1070 struct ide_cmd cmd;
1071 "rq->cmd_type: 0x%x, block: %llu\n", 1071
1072 __func__, rq->cmd[0], rq->cmd_type, 1072 ide_debug_log(IDE_DBG_RQ, "cmd: 0x%x, block: %llu",
1073 (unsigned long long)block); 1073 rq->cmd[0], (unsigned long long)block);
1074
1075 if (drive->debug_mask & IDE_DBG_RQ)
1076 blk_dump_rq_flags(rq, "ide_cd_do_request");
1074 1077
1075 if (blk_fs_request(rq)) { 1078 if (blk_fs_request(rq)) {
1076 if (cdrom_start_rw(drive, rq) == ide_stopped) 1079 if (cdrom_start_rw(drive, rq) == ide_stopped)
@@ -1094,7 +1097,14 @@ static ide_startstop_t ide_cd_do_request(ide_drive_t *drive, struct request *rq,
1094 return ide_stopped; 1097 return ide_stopped;
1095 } 1098 }
1096 1099
1097 return ide_issue_pc(drive); 1100 memset(&cmd, 0, sizeof(cmd));
1101
1102 if (rq_data_dir(rq))
1103 cmd.tf_flags |= IDE_TFLAG_WRITE;
1104
1105 cmd.rq = rq;
1106
1107 return ide_issue_pc(drive, &cmd);
1098} 1108}
1099 1109
1100/* 1110/*
@@ -1119,7 +1129,7 @@ int cdrom_check_status(ide_drive_t *drive, struct request_sense *sense)
1119 struct cdrom_device_info *cdi = &info->devinfo; 1129 struct cdrom_device_info *cdi = &info->devinfo;
1120 unsigned char cmd[BLK_MAX_CDB]; 1130 unsigned char cmd[BLK_MAX_CDB];
1121 1131
1122 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__); 1132 ide_debug_log(IDE_DBG_FUNC, "enter");
1123 1133
1124 memset(cmd, 0, BLK_MAX_CDB); 1134 memset(cmd, 0, BLK_MAX_CDB);
1125 cmd[0] = GPCMD_TEST_UNIT_READY; 1135 cmd[0] = GPCMD_TEST_UNIT_READY;
@@ -1147,7 +1157,7 @@ static int cdrom_read_capacity(ide_drive_t *drive, unsigned long *capacity,
1147 unsigned len = sizeof(capbuf); 1157 unsigned len = sizeof(capbuf);
1148 u32 blocklen; 1158 u32 blocklen;
1149 1159
1150 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__); 1160 ide_debug_log(IDE_DBG_FUNC, "enter");
1151 1161
1152 memset(cmd, 0, BLK_MAX_CDB); 1162 memset(cmd, 0, BLK_MAX_CDB);
1153 cmd[0] = GPCMD_READ_CDVD_CAPACITY; 1163 cmd[0] = GPCMD_READ_CDVD_CAPACITY;
@@ -1179,8 +1189,8 @@ static int cdrom_read_capacity(ide_drive_t *drive, unsigned long *capacity,
1179 *capacity = 1 + be32_to_cpu(capbuf.lba); 1189 *capacity = 1 + be32_to_cpu(capbuf.lba);
1180 *sectors_per_frame = blocklen >> SECTOR_BITS; 1190 *sectors_per_frame = blocklen >> SECTOR_BITS;
1181 1191
1182 ide_debug_log(IDE_DBG_PROBE, "%s: cap: %lu, sectors_per_frame: %lu\n", 1192 ide_debug_log(IDE_DBG_PROBE, "cap: %lu, sectors_per_frame: %lu",
1183 __func__, *capacity, *sectors_per_frame); 1193 *capacity, *sectors_per_frame);
1184 1194
1185 return 0; 1195 return 0;
1186} 1196}
@@ -1191,7 +1201,7 @@ static int cdrom_read_tocentry(ide_drive_t *drive, int trackno, int msf_flag,
1191{ 1201{
1192 unsigned char cmd[BLK_MAX_CDB]; 1202 unsigned char cmd[BLK_MAX_CDB];
1193 1203
1194 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__); 1204 ide_debug_log(IDE_DBG_FUNC, "enter");
1195 1205
1196 memset(cmd, 0, BLK_MAX_CDB); 1206 memset(cmd, 0, BLK_MAX_CDB);
1197 1207
@@ -1221,7 +1231,7 @@ int ide_cd_read_toc(ide_drive_t *drive, struct request_sense *sense)
1221 long last_written; 1231 long last_written;
1222 unsigned long sectors_per_frame = SECTORS_PER_FRAME; 1232 unsigned long sectors_per_frame = SECTORS_PER_FRAME;
1223 1233
1224 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__); 1234 ide_debug_log(IDE_DBG_FUNC, "enter");
1225 1235
1226 if (toc == NULL) { 1236 if (toc == NULL) {
1227 /* try to allocate space */ 1237 /* try to allocate space */
@@ -1383,7 +1393,7 @@ int ide_cdrom_get_capabilities(ide_drive_t *drive, u8 *buf)
1383 struct packet_command cgc; 1393 struct packet_command cgc;
1384 int stat, attempts = 3, size = ATAPI_CAPABILITIES_PAGE_SIZE; 1394 int stat, attempts = 3, size = ATAPI_CAPABILITIES_PAGE_SIZE;
1385 1395
1386 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__); 1396 ide_debug_log(IDE_DBG_FUNC, "enter");
1387 1397
1388 if ((drive->atapi_flags & IDE_AFLAG_FULL_CAPS_PAGE) == 0) 1398 if ((drive->atapi_flags & IDE_AFLAG_FULL_CAPS_PAGE) == 0)
1389 size -= ATAPI_CAPABILITIES_PAGE_PAD_SIZE; 1399 size -= ATAPI_CAPABILITIES_PAGE_PAD_SIZE;
@@ -1403,7 +1413,7 @@ void ide_cdrom_update_speed(ide_drive_t *drive, u8 *buf)
1403 struct cdrom_info *cd = drive->driver_data; 1413 struct cdrom_info *cd = drive->driver_data;
1404 u16 curspeed, maxspeed; 1414 u16 curspeed, maxspeed;
1405 1415
1406 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__); 1416 ide_debug_log(IDE_DBG_FUNC, "enter");
1407 1417
1408 if (drive->atapi_flags & IDE_AFLAG_LE_SPEED_FIELDS) { 1418 if (drive->atapi_flags & IDE_AFLAG_LE_SPEED_FIELDS) {
1409 curspeed = le16_to_cpup((__le16 *)&buf[8 + 14]); 1419 curspeed = le16_to_cpup((__le16 *)&buf[8 + 14]);
@@ -1413,8 +1423,8 @@ void ide_cdrom_update_speed(ide_drive_t *drive, u8 *buf)
1413 maxspeed = be16_to_cpup((__be16 *)&buf[8 + 8]); 1423 maxspeed = be16_to_cpup((__be16 *)&buf[8 + 8]);
1414 } 1424 }
1415 1425
1416 ide_debug_log(IDE_DBG_PROBE, "%s: curspeed: %u, maxspeed: %u\n", 1426 ide_debug_log(IDE_DBG_PROBE, "curspeed: %u, maxspeed: %u",
1417 __func__, curspeed, maxspeed); 1427 curspeed, maxspeed);
1418 1428
1419 cd->current_speed = (curspeed + (176/2)) / 176; 1429 cd->current_speed = (curspeed + (176/2)) / 176;
1420 cd->max_speed = (maxspeed + (176/2)) / 176; 1430 cd->max_speed = (maxspeed + (176/2)) / 176;
@@ -1448,7 +1458,7 @@ static int ide_cdrom_register(ide_drive_t *drive, int nslots)
1448 struct cdrom_info *info = drive->driver_data; 1458 struct cdrom_info *info = drive->driver_data;
1449 struct cdrom_device_info *devinfo = &info->devinfo; 1459 struct cdrom_device_info *devinfo = &info->devinfo;
1450 1460
1451 ide_debug_log(IDE_DBG_PROBE, "Call %s, nslots: %d\n", __func__, nslots); 1461 ide_debug_log(IDE_DBG_PROBE, "nslots: %d", nslots);
1452 1462
1453 devinfo->ops = &ide_cdrom_dops; 1463 devinfo->ops = &ide_cdrom_dops;
1454 devinfo->speed = info->current_speed; 1464 devinfo->speed = info->current_speed;
@@ -1471,9 +1481,8 @@ static int ide_cdrom_probe_capabilities(ide_drive_t *drive)
1471 mechtype_t mechtype; 1481 mechtype_t mechtype;
1472 int nslots = 1; 1482 int nslots = 1;
1473 1483
1474 ide_debug_log(IDE_DBG_PROBE, "Call %s, drive->media: 0x%x, " 1484 ide_debug_log(IDE_DBG_PROBE, "media: 0x%x, atapi_flags: 0x%lx",
1475 "drive->atapi_flags: 0x%lx\n", __func__, drive->media, 1485 drive->media, drive->atapi_flags);
1476 drive->atapi_flags);
1477 1486
1478 cdi->mask = (CDC_CD_R | CDC_CD_RW | CDC_DVD | CDC_DVD_R | 1487 cdi->mask = (CDC_CD_R | CDC_CD_RW | CDC_DVD | CDC_DVD_R |
1479 CDC_DVD_RAM | CDC_SELECT_DISC | CDC_PLAY_AUDIO | 1488 CDC_DVD_RAM | CDC_SELECT_DISC | CDC_PLAY_AUDIO |
@@ -1754,7 +1763,7 @@ static int ide_cdrom_setup(ide_drive_t *drive)
1754 char *fw_rev = (char *)&id[ATA_ID_FW_REV]; 1763 char *fw_rev = (char *)&id[ATA_ID_FW_REV];
1755 int nslots; 1764 int nslots;
1756 1765
1757 ide_debug_log(IDE_DBG_PROBE, "Call %s\n", __func__); 1766 ide_debug_log(IDE_DBG_PROBE, "enter");
1758 1767
1759 blk_queue_prep_rq(drive->queue, ide_cdrom_prep_fn); 1768 blk_queue_prep_rq(drive->queue, ide_cdrom_prep_fn);
1760 blk_queue_dma_alignment(drive->queue, 31); 1769 blk_queue_dma_alignment(drive->queue, 31);
@@ -1797,7 +1806,7 @@ static void ide_cd_remove(ide_drive_t *drive)
1797{ 1806{
1798 struct cdrom_info *info = drive->driver_data; 1807 struct cdrom_info *info = drive->driver_data;
1799 1808
1800 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__); 1809 ide_debug_log(IDE_DBG_FUNC, "enter");
1801 1810
1802 ide_proc_unregister_driver(drive, info->driver); 1811 ide_proc_unregister_driver(drive, info->driver);
1803 device_del(&info->dev); 1812 device_del(&info->dev);
@@ -1815,7 +1824,7 @@ static void ide_cd_release(struct device *dev)
1815 ide_drive_t *drive = info->drive; 1824 ide_drive_t *drive = info->drive;
1816 struct gendisk *g = info->disk; 1825 struct gendisk *g = info->disk;
1817 1826
1818 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__); 1827 ide_debug_log(IDE_DBG_FUNC, "enter");
1819 1828
1820 kfree(info->toc); 1829 kfree(info->toc);
1821 if (devinfo->handle == drive) 1830 if (devinfo->handle == drive)
@@ -1839,7 +1848,6 @@ static struct ide_driver ide_cdrom_driver = {
1839 .remove = ide_cd_remove, 1848 .remove = ide_cd_remove,
1840 .version = IDECD_VERSION, 1849 .version = IDECD_VERSION,
1841 .do_request = ide_cd_do_request, 1850 .do_request = ide_cd_do_request,
1842 .end_request = ide_end_request,
1843#ifdef CONFIG_IDE_PROC_FS 1851#ifdef CONFIG_IDE_PROC_FS
1844 .proc_entries = ide_cd_proc_entries, 1852 .proc_entries = ide_cd_proc_entries,
1845 .proc_devsets = ide_cd_proc_devsets, 1853 .proc_devsets = ide_cd_proc_devsets,
@@ -1974,9 +1982,8 @@ static int ide_cd_probe(ide_drive_t *drive)
1974 struct gendisk *g; 1982 struct gendisk *g;
1975 struct request_sense sense; 1983 struct request_sense sense;
1976 1984
1977 ide_debug_log(IDE_DBG_PROBE, "Call %s, drive->driver_req: %s, " 1985 ide_debug_log(IDE_DBG_PROBE, "driver_req: %s, media: 0x%x",
1978 "drive->media: 0x%x\n", __func__, drive->driver_req, 1986 drive->driver_req, drive->media);
1979 drive->media);
1980 1987
1981 if (!strstr("ide-cdrom", drive->driver_req)) 1988 if (!strstr("ide-cdrom", drive->driver_req))
1982 goto failed; 1989 goto failed;
diff --git a/drivers/ide/ide-cd.h b/drivers/ide/ide-cd.h
index c878bfcf1116..1d97101099ce 100644
--- a/drivers/ide/ide-cd.h
+++ b/drivers/ide/ide-cd.h
@@ -11,7 +11,7 @@
11#define IDECD_DEBUG_LOG 0 11#define IDECD_DEBUG_LOG 0
12 12
13#if IDECD_DEBUG_LOG 13#if IDECD_DEBUG_LOG
14#define ide_debug_log(lvl, fmt, args...) __ide_debug_log(lvl, fmt, args) 14#define ide_debug_log(lvl, fmt, args...) __ide_debug_log(lvl, fmt, ## args)
15#else 15#else
16#define ide_debug_log(lvl, fmt, args...) do {} while (0) 16#define ide_debug_log(lvl, fmt, args...) do {} while (0)
17#endif 17#endif
@@ -91,8 +91,6 @@ struct cdrom_info {
91 on this device. */ 91 on this device. */
92 struct request_sense sense_data; 92 struct request_sense sense_data;
93 93
94 struct request request_sense_request;
95
96 u8 max_speed; /* Max speed of the drive. */ 94 u8 max_speed; /* Max speed of the drive. */
97 u8 current_speed; /* Current speed of the drive. */ 95 u8 current_speed; /* Current speed of the drive. */
98 96
diff --git a/drivers/ide/ide-cs.c b/drivers/ide/ide-cs.c
index f50210fe558f..9e47f3529d55 100644
--- a/drivers/ide/ide-cs.c
+++ b/drivers/ide/ide-cs.c
@@ -154,6 +154,7 @@ static const struct ide_port_ops idecs_port_ops = {
154static const struct ide_port_info idecs_port_info = { 154static const struct ide_port_info idecs_port_info = {
155 .port_ops = &idecs_port_ops, 155 .port_ops = &idecs_port_ops,
156 .host_flags = IDE_HFLAG_NO_DMA, 156 .host_flags = IDE_HFLAG_NO_DMA,
157 .irq_flags = IRQF_SHARED,
157}; 158};
158 159
159static struct ide_host *idecs_register(unsigned long io, unsigned long ctl, 160static struct ide_host *idecs_register(unsigned long io, unsigned long ctl,
diff --git a/drivers/ide/ide-devsets.c b/drivers/ide/ide-devsets.c
index 7c3953414d47..5bf958e5b1d5 100644
--- a/drivers/ide/ide-devsets.c
+++ b/drivers/ide/ide-devsets.c
@@ -183,8 +183,6 @@ ide_startstop_t ide_do_devset(ide_drive_t *drive, struct request *rq)
183 err = setfunc(drive, *(int *)&rq->cmd[1]); 183 err = setfunc(drive, *(int *)&rq->cmd[1]);
184 if (err) 184 if (err)
185 rq->errors = err; 185 rq->errors = err;
186 else 186 ide_complete_rq(drive, err, ide_rq_bytes(rq));
187 err = 1;
188 ide_end_request(drive, err, 0);
189 return ide_stopped; 187 return ide_stopped;
190} 188}
diff --git a/drivers/ide/ide-disk.c b/drivers/ide/ide-disk.c
index 806760d24cef..ca934c8a1289 100644
--- a/drivers/ide/ide-disk.c
+++ b/drivers/ide/ide-disk.c
@@ -28,7 +28,6 @@
28#include <linux/mutex.h> 28#include <linux/mutex.h>
29#include <linux/leds.h> 29#include <linux/leds.h>
30#include <linux/ide.h> 30#include <linux/ide.h>
31#include <linux/hdreg.h>
32 31
33#include <asm/byteorder.h> 32#include <asm/byteorder.h>
34#include <asm/irq.h> 33#include <asm/irq.h>
@@ -53,33 +52,26 @@ static const u8 ide_rw_cmds[] = {
53 ATA_CMD_WRITE_EXT, 52 ATA_CMD_WRITE_EXT,
54}; 53};
55 54
56static const u8 ide_data_phases[] = { 55static void ide_tf_set_cmd(ide_drive_t *drive, struct ide_cmd *cmd, u8 dma)
57 TASKFILE_MULTI_IN,
58 TASKFILE_MULTI_OUT,
59 TASKFILE_IN,
60 TASKFILE_OUT,
61 TASKFILE_IN_DMA,
62 TASKFILE_OUT_DMA,
63};
64
65static void ide_tf_set_cmd(ide_drive_t *drive, ide_task_t *task, u8 dma)
66{ 56{
67 u8 index, lba48, write; 57 u8 index, lba48, write;
68 58
69 lba48 = (task->tf_flags & IDE_TFLAG_LBA48) ? 2 : 0; 59 lba48 = (cmd->tf_flags & IDE_TFLAG_LBA48) ? 2 : 0;
70 write = (task->tf_flags & IDE_TFLAG_WRITE) ? 1 : 0; 60 write = (cmd->tf_flags & IDE_TFLAG_WRITE) ? 1 : 0;
71 61
72 if (dma) 62 if (dma) {
63 cmd->protocol = ATA_PROT_DMA;
73 index = 8; 64 index = 8;
74 else 65 } else {
75 index = drive->mult_count ? 0 : 4; 66 cmd->protocol = ATA_PROT_PIO;
76 67 if (drive->mult_count) {
77 task->tf.command = ide_rw_cmds[index + lba48 + write]; 68 cmd->tf_flags |= IDE_TFLAG_MULTI_PIO;
78 69 index = 0;
79 if (dma) 70 } else
80 index = 8; /* fixup index */ 71 index = 4;
72 }
81 73
82 task->data_phase = ide_data_phases[index / 2 + write]; 74 cmd->tf.command = ide_rw_cmds[index + lba48 + write];
83} 75}
84 76
85/* 77/*
@@ -93,8 +85,8 @@ static ide_startstop_t __ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
93 u16 nsectors = (u16)rq->nr_sectors; 85 u16 nsectors = (u16)rq->nr_sectors;
94 u8 lba48 = !!(drive->dev_flags & IDE_DFLAG_LBA48); 86 u8 lba48 = !!(drive->dev_flags & IDE_DFLAG_LBA48);
95 u8 dma = !!(drive->dev_flags & IDE_DFLAG_USING_DMA); 87 u8 dma = !!(drive->dev_flags & IDE_DFLAG_USING_DMA);
96 ide_task_t task; 88 struct ide_cmd cmd;
97 struct ide_taskfile *tf = &task.tf; 89 struct ide_taskfile *tf = &cmd.tf;
98 ide_startstop_t rc; 90 ide_startstop_t rc;
99 91
100 if ((hwif->host_flags & IDE_HFLAG_NO_LBA48_DMA) && lba48 && dma) { 92 if ((hwif->host_flags & IDE_HFLAG_NO_LBA48_DMA) && lba48 && dma) {
@@ -104,13 +96,8 @@ static ide_startstop_t __ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
104 lba48 = 0; 96 lba48 = 0;
105 } 97 }
106 98
107 if (!dma) { 99 memset(&cmd, 0, sizeof(cmd));
108 ide_init_sg_cmd(drive, rq); 100 cmd.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
109 ide_map_sg(drive, rq);
110 }
111
112 memset(&task, 0, sizeof(task));
113 task.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
114 101
115 if (drive->dev_flags & IDE_DFLAG_LBA) { 102 if (drive->dev_flags & IDE_DFLAG_LBA) {
116 if (lba48) { 103 if (lba48) {
@@ -129,7 +116,7 @@ static ide_startstop_t __ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
129 tf->lbam = (u8)(block >> 8); 116 tf->lbam = (u8)(block >> 8);
130 tf->lbah = (u8)(block >> 16); 117 tf->lbah = (u8)(block >> 16);
131 118
132 task.tf_flags |= (IDE_TFLAG_LBA48 | IDE_TFLAG_HOB); 119 cmd.tf_flags |= (IDE_TFLAG_LBA48 | IDE_TFLAG_HOB);
133 } else { 120 } else {
134 tf->nsect = nsectors & 0xff; 121 tf->nsect = nsectors & 0xff;
135 tf->lbal = block; 122 tf->lbal = block;
@@ -156,23 +143,27 @@ static ide_startstop_t __ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
156 tf->device = head; 143 tf->device = head;
157 } 144 }
158 145
146 cmd.tf_flags |= IDE_TFLAG_FS;
147
159 if (rq_data_dir(rq)) 148 if (rq_data_dir(rq))
160 task.tf_flags |= IDE_TFLAG_WRITE; 149 cmd.tf_flags |= IDE_TFLAG_WRITE;
150
151 ide_tf_set_cmd(drive, &cmd, dma);
152 cmd.rq = rq;
161 153
162 ide_tf_set_cmd(drive, &task, dma); 154 if (dma == 0) {
163 if (!dma) 155 ide_init_sg_cmd(&cmd, nsectors << 9);
164 hwif->data_phase = task.data_phase; 156 ide_map_sg(drive, &cmd);
165 task.rq = rq; 157 }
166 158
167 rc = do_rw_taskfile(drive, &task); 159 rc = do_rw_taskfile(drive, &cmd);
168 160
169 if (rc == ide_stopped && dma) { 161 if (rc == ide_stopped && dma) {
170 /* fallback to PIO */ 162 /* fallback to PIO */
171 task.tf_flags |= IDE_TFLAG_DMA_PIO_FALLBACK; 163 cmd.tf_flags |= IDE_TFLAG_DMA_PIO_FALLBACK;
172 ide_tf_set_cmd(drive, &task, 0); 164 ide_tf_set_cmd(drive, &cmd, 0);
173 hwif->data_phase = task.data_phase; 165 ide_init_sg_cmd(&cmd, nsectors << 9);
174 ide_init_sg_cmd(drive, rq); 166 rc = do_rw_taskfile(drive, &cmd);
175 rc = do_rw_taskfile(drive, &task);
176 } 167 }
177 168
178 return rc; 169 return rc;
@@ -193,7 +184,9 @@ static ide_startstop_t ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
193 184
194 if (!blk_fs_request(rq)) { 185 if (!blk_fs_request(rq)) {
195 blk_dump_rq_flags(rq, "ide_do_rw_disk - bad command"); 186 blk_dump_rq_flags(rq, "ide_do_rw_disk - bad command");
196 ide_end_request(drive, 0, 0); 187 if (rq->errors == 0)
188 rq->errors = -EIO;
189 ide_complete_rq(drive, -EIO, ide_rq_bytes(rq));
197 return ide_stopped; 190 return ide_stopped;
198 } 191 }
199 192
@@ -216,22 +209,22 @@ static ide_startstop_t ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
216 */ 209 */
217static u64 idedisk_read_native_max_address(ide_drive_t *drive, int lba48) 210static u64 idedisk_read_native_max_address(ide_drive_t *drive, int lba48)
218{ 211{
219 ide_task_t args; 212 struct ide_cmd cmd;
220 struct ide_taskfile *tf = &args.tf; 213 struct ide_taskfile *tf = &cmd.tf;
221 u64 addr = 0; 214 u64 addr = 0;
222 215
223 /* Create IDE/ATA command request structure */ 216 memset(&cmd, 0, sizeof(cmd));
224 memset(&args, 0, sizeof(ide_task_t));
225 if (lba48) 217 if (lba48)
226 tf->command = ATA_CMD_READ_NATIVE_MAX_EXT; 218 tf->command = ATA_CMD_READ_NATIVE_MAX_EXT;
227 else 219 else
228 tf->command = ATA_CMD_READ_NATIVE_MAX; 220 tf->command = ATA_CMD_READ_NATIVE_MAX;
229 tf->device = ATA_LBA; 221 tf->device = ATA_LBA;
230 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; 222
223 cmd.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
231 if (lba48) 224 if (lba48)
232 args.tf_flags |= (IDE_TFLAG_LBA48 | IDE_TFLAG_HOB); 225 cmd.tf_flags |= (IDE_TFLAG_LBA48 | IDE_TFLAG_HOB);
233 /* submit command request */ 226
234 ide_no_data_taskfile(drive, &args); 227 ide_no_data_taskfile(drive, &cmd);
235 228
236 /* if OK, compute maximum address value */ 229 /* if OK, compute maximum address value */
237 if ((tf->status & 0x01) == 0) 230 if ((tf->status & 0x01) == 0)
@@ -246,13 +239,13 @@ static u64 idedisk_read_native_max_address(ide_drive_t *drive, int lba48)
246 */ 239 */
247static u64 idedisk_set_max_address(ide_drive_t *drive, u64 addr_req, int lba48) 240static u64 idedisk_set_max_address(ide_drive_t *drive, u64 addr_req, int lba48)
248{ 241{
249 ide_task_t args; 242 struct ide_cmd cmd;
250 struct ide_taskfile *tf = &args.tf; 243 struct ide_taskfile *tf = &cmd.tf;
251 u64 addr_set = 0; 244 u64 addr_set = 0;
252 245
253 addr_req--; 246 addr_req--;
254 /* Create IDE/ATA command request structure */ 247
255 memset(&args, 0, sizeof(ide_task_t)); 248 memset(&cmd, 0, sizeof(cmd));
256 tf->lbal = (addr_req >> 0) & 0xff; 249 tf->lbal = (addr_req >> 0) & 0xff;
257 tf->lbam = (addr_req >>= 8) & 0xff; 250 tf->lbam = (addr_req >>= 8) & 0xff;
258 tf->lbah = (addr_req >>= 8) & 0xff; 251 tf->lbah = (addr_req >>= 8) & 0xff;
@@ -266,11 +259,13 @@ static u64 idedisk_set_max_address(ide_drive_t *drive, u64 addr_req, int lba48)
266 tf->command = ATA_CMD_SET_MAX; 259 tf->command = ATA_CMD_SET_MAX;
267 } 260 }
268 tf->device |= ATA_LBA; 261 tf->device |= ATA_LBA;
269 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; 262
263 cmd.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
270 if (lba48) 264 if (lba48)
271 args.tf_flags |= (IDE_TFLAG_LBA48 | IDE_TFLAG_HOB); 265 cmd.tf_flags |= (IDE_TFLAG_LBA48 | IDE_TFLAG_HOB);
272 /* submit command request */ 266
273 ide_no_data_taskfile(drive, &args); 267 ide_no_data_taskfile(drive, &cmd);
268
274 /* if OK, compute maximum address value */ 269 /* if OK, compute maximum address value */
275 if ((tf->status & 0x01) == 0) 270 if ((tf->status & 0x01) == 0)
276 addr_set = ide_get_lba_addr(tf, lba48) + 1; 271 addr_set = ide_get_lba_addr(tf, lba48) + 1;
@@ -389,24 +384,24 @@ static int ide_disk_get_capacity(ide_drive_t *drive)
389static void idedisk_prepare_flush(struct request_queue *q, struct request *rq) 384static void idedisk_prepare_flush(struct request_queue *q, struct request *rq)
390{ 385{
391 ide_drive_t *drive = q->queuedata; 386 ide_drive_t *drive = q->queuedata;
392 ide_task_t *task = kmalloc(sizeof(*task), GFP_ATOMIC); 387 struct ide_cmd *cmd = kmalloc(sizeof(*cmd), GFP_ATOMIC);
393 388
394 /* FIXME: map struct ide_taskfile on rq->cmd[] */ 389 /* FIXME: map struct ide_taskfile on rq->cmd[] */
395 BUG_ON(task == NULL); 390 BUG_ON(cmd == NULL);
396 391
397 memset(task, 0, sizeof(*task)); 392 memset(cmd, 0, sizeof(*cmd));
398 if (ata_id_flush_ext_enabled(drive->id) && 393 if (ata_id_flush_ext_enabled(drive->id) &&
399 (drive->capacity64 >= (1UL << 28))) 394 (drive->capacity64 >= (1UL << 28)))
400 task->tf.command = ATA_CMD_FLUSH_EXT; 395 cmd->tf.command = ATA_CMD_FLUSH_EXT;
401 else 396 else
402 task->tf.command = ATA_CMD_FLUSH; 397 cmd->tf.command = ATA_CMD_FLUSH;
403 task->tf_flags = IDE_TFLAG_OUT_TF | IDE_TFLAG_OUT_DEVICE | 398 cmd->tf_flags = IDE_TFLAG_OUT_TF | IDE_TFLAG_OUT_DEVICE |
404 IDE_TFLAG_DYN; 399 IDE_TFLAG_DYN;
405 task->data_phase = TASKFILE_NO_DATA; 400 cmd->protocol = ATA_PROT_NODATA;
406 401
407 rq->cmd_type = REQ_TYPE_ATA_TASKFILE; 402 rq->cmd_type = REQ_TYPE_ATA_TASKFILE;
408 rq->cmd_flags |= REQ_SOFTBARRIER; 403 rq->cmd_flags |= REQ_SOFTBARRIER;
409 rq->special = task; 404 rq->special = cmd;
410} 405}
411 406
412ide_devset_get(multcount, mult_count); 407ide_devset_get(multcount, mult_count);
@@ -456,15 +451,15 @@ static int set_nowerr(ide_drive_t *drive, int arg)
456 451
457static int ide_do_setfeature(ide_drive_t *drive, u8 feature, u8 nsect) 452static int ide_do_setfeature(ide_drive_t *drive, u8 feature, u8 nsect)
458{ 453{
459 ide_task_t task; 454 struct ide_cmd cmd;
460 455
461 memset(&task, 0, sizeof(task)); 456 memset(&cmd, 0, sizeof(cmd));
462 task.tf.feature = feature; 457 cmd.tf.feature = feature;
463 task.tf.nsect = nsect; 458 cmd.tf.nsect = nsect;
464 task.tf.command = ATA_CMD_SET_FEATURES; 459 cmd.tf.command = ATA_CMD_SET_FEATURES;
465 task.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; 460 cmd.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
466 461
467 return ide_no_data_taskfile(drive, &task); 462 return ide_no_data_taskfile(drive, &cmd);
468} 463}
469 464
470static void update_ordered(ide_drive_t *drive) 465static void update_ordered(ide_drive_t *drive)
@@ -531,15 +526,16 @@ static int set_wcache(ide_drive_t *drive, int arg)
531 526
532static int do_idedisk_flushcache(ide_drive_t *drive) 527static int do_idedisk_flushcache(ide_drive_t *drive)
533{ 528{
534 ide_task_t args; 529 struct ide_cmd cmd;
535 530
536 memset(&args, 0, sizeof(ide_task_t)); 531 memset(&cmd, 0, sizeof(cmd));
537 if (ata_id_flush_ext_enabled(drive->id)) 532 if (ata_id_flush_ext_enabled(drive->id))
538 args.tf.command = ATA_CMD_FLUSH_EXT; 533 cmd.tf.command = ATA_CMD_FLUSH_EXT;
539 else 534 else
540 args.tf.command = ATA_CMD_FLUSH; 535 cmd.tf.command = ATA_CMD_FLUSH;
541 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; 536 cmd.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
542 return ide_no_data_taskfile(drive, &args); 537
538 return ide_no_data_taskfile(drive, &cmd);
543} 539}
544 540
545ide_devset_get(acoustic, acoustic); 541ide_devset_get(acoustic, acoustic);
@@ -711,17 +707,17 @@ static int ide_disk_init_media(ide_drive_t *drive, struct gendisk *disk)
711static int ide_disk_set_doorlock(ide_drive_t *drive, struct gendisk *disk, 707static int ide_disk_set_doorlock(ide_drive_t *drive, struct gendisk *disk,
712 int on) 708 int on)
713{ 709{
714 ide_task_t task; 710 struct ide_cmd cmd;
715 int ret; 711 int ret;
716 712
717 if ((drive->dev_flags & IDE_DFLAG_DOORLOCKING) == 0) 713 if ((drive->dev_flags & IDE_DFLAG_DOORLOCKING) == 0)
718 return 0; 714 return 0;
719 715
720 memset(&task, 0, sizeof(task)); 716 memset(&cmd, 0, sizeof(cmd));
721 task.tf.command = on ? ATA_CMD_MEDIA_LOCK : ATA_CMD_MEDIA_UNLOCK; 717 cmd.tf.command = on ? ATA_CMD_MEDIA_LOCK : ATA_CMD_MEDIA_UNLOCK;
722 task.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; 718 cmd.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
723 719
724 ret = ide_no_data_taskfile(drive, &task); 720 ret = ide_no_data_taskfile(drive, &cmd);
725 721
726 if (ret) 722 if (ret)
727 drive->dev_flags &= ~IDE_DFLAG_DOORLOCKING; 723 drive->dev_flags &= ~IDE_DFLAG_DOORLOCKING;
@@ -737,6 +733,5 @@ const struct ide_disk_ops ide_ata_disk_ops = {
737 .init_media = ide_disk_init_media, 733 .init_media = ide_disk_init_media,
738 .set_doorlock = ide_disk_set_doorlock, 734 .set_doorlock = ide_disk_set_doorlock,
739 .do_request = ide_do_rw_disk, 735 .do_request = ide_do_rw_disk,
740 .end_request = ide_end_request,
741 .ioctl = ide_disk_ioctl, 736 .ioctl = ide_disk_ioctl,
742}; 737};
diff --git a/drivers/ide/ide-disk_proc.c b/drivers/ide/ide-disk_proc.c
index 1f86dcbd2b1c..eaea3bef2073 100644
--- a/drivers/ide/ide-disk_proc.c
+++ b/drivers/ide/ide-disk_proc.c
@@ -1,38 +1,38 @@
1#include <linux/kernel.h> 1#include <linux/kernel.h>
2#include <linux/ide.h> 2#include <linux/ide.h>
3#include <linux/hdreg.h>
4 3
5#include "ide-disk.h" 4#include "ide-disk.h"
6 5
7static int smart_enable(ide_drive_t *drive) 6static int smart_enable(ide_drive_t *drive)
8{ 7{
9 ide_task_t args; 8 struct ide_cmd cmd;
10 struct ide_taskfile *tf = &args.tf; 9 struct ide_taskfile *tf = &cmd.tf;
11 10
12 memset(&args, 0, sizeof(ide_task_t)); 11 memset(&cmd, 0, sizeof(cmd));
13 tf->feature = ATA_SMART_ENABLE; 12 tf->feature = ATA_SMART_ENABLE;
14 tf->lbam = ATA_SMART_LBAM_PASS; 13 tf->lbam = ATA_SMART_LBAM_PASS;
15 tf->lbah = ATA_SMART_LBAH_PASS; 14 tf->lbah = ATA_SMART_LBAH_PASS;
16 tf->command = ATA_CMD_SMART; 15 tf->command = ATA_CMD_SMART;
17 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; 16 cmd.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
18 return ide_no_data_taskfile(drive, &args); 17
18 return ide_no_data_taskfile(drive, &cmd);
19} 19}
20 20
21static int get_smart_data(ide_drive_t *drive, u8 *buf, u8 sub_cmd) 21static int get_smart_data(ide_drive_t *drive, u8 *buf, u8 sub_cmd)
22{ 22{
23 ide_task_t args; 23 struct ide_cmd cmd;
24 struct ide_taskfile *tf = &args.tf; 24 struct ide_taskfile *tf = &cmd.tf;
25 25
26 memset(&args, 0, sizeof(ide_task_t)); 26 memset(&cmd, 0, sizeof(cmd));
27 tf->feature = sub_cmd; 27 tf->feature = sub_cmd;
28 tf->nsect = 0x01; 28 tf->nsect = 0x01;
29 tf->lbam = ATA_SMART_LBAM_PASS; 29 tf->lbam = ATA_SMART_LBAM_PASS;
30 tf->lbah = ATA_SMART_LBAH_PASS; 30 tf->lbah = ATA_SMART_LBAH_PASS;
31 tf->command = ATA_CMD_SMART; 31 tf->command = ATA_CMD_SMART;
32 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; 32 cmd.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
33 args.data_phase = TASKFILE_IN; 33 cmd.protocol = ATA_PROT_PIO;
34 (void) smart_enable(drive); 34
35 return ide_raw_taskfile(drive, &args, buf, 1); 35 return ide_raw_taskfile(drive, &cmd, buf, 1);
36} 36}
37 37
38static int proc_idedisk_read_cache 38static int proc_idedisk_read_cache
@@ -67,6 +67,8 @@ static int proc_idedisk_read_smart(char *page, char **start, off_t off,
67 ide_drive_t *drive = (ide_drive_t *)data; 67 ide_drive_t *drive = (ide_drive_t *)data;
68 int len = 0, i = 0; 68 int len = 0, i = 0;
69 69
70 (void)smart_enable(drive);
71
70 if (get_smart_data(drive, page, sub_cmd) == 0) { 72 if (get_smart_data(drive, page, sub_cmd) == 0) {
71 unsigned short *val = (unsigned short *) page; 73 unsigned short *val = (unsigned short *) page;
72 char *out = (char *)val + SECTOR_SIZE; 74 char *out = (char *)val + SECTOR_SIZE;
diff --git a/drivers/ide/ide-dma-sff.c b/drivers/ide/ide-dma-sff.c
index 123d393658af..75a9ea2e4c82 100644
--- a/drivers/ide/ide-dma-sff.c
+++ b/drivers/ide/ide-dma-sff.c
@@ -111,7 +111,7 @@ EXPORT_SYMBOL_GPL(ide_dma_host_set);
111 * May also be invoked from trm290.c 111 * May also be invoked from trm290.c
112 */ 112 */
113 113
114int ide_build_dmatable(ide_drive_t *drive, struct request *rq) 114int ide_build_dmatable(ide_drive_t *drive, struct ide_cmd *cmd)
115{ 115{
116 ide_hwif_t *hwif = drive->hwif; 116 ide_hwif_t *hwif = drive->hwif;
117 __le32 *table = (__le32 *)hwif->dmatable_cpu; 117 __le32 *table = (__le32 *)hwif->dmatable_cpu;
@@ -120,11 +120,7 @@ int ide_build_dmatable(ide_drive_t *drive, struct request *rq)
120 struct scatterlist *sg; 120 struct scatterlist *sg;
121 u8 is_trm290 = !!(hwif->host_flags & IDE_HFLAG_TRM290); 121 u8 is_trm290 = !!(hwif->host_flags & IDE_HFLAG_TRM290);
122 122
123 hwif->sg_nents = ide_build_sglist(drive, rq); 123 for_each_sg(hwif->sg_table, sg, cmd->sg_nents, i) {
124 if (hwif->sg_nents == 0)
125 return 0;
126
127 for_each_sg(hwif->sg_table, sg, hwif->sg_nents, i) {
128 u32 cur_addr, cur_len, xcount, bcount; 124 u32 cur_addr, cur_len, xcount, bcount;
129 125
130 cur_addr = sg_dma_address(sg); 126 cur_addr = sg_dma_address(sg);
@@ -179,6 +175,7 @@ EXPORT_SYMBOL_GPL(ide_build_dmatable);
179/** 175/**
180 * ide_dma_setup - begin a DMA phase 176 * ide_dma_setup - begin a DMA phase
181 * @drive: target device 177 * @drive: target device
178 * @cmd: command
182 * 179 *
183 * Build an IDE DMA PRD (IDE speak for scatter gather table) 180 * Build an IDE DMA PRD (IDE speak for scatter gather table)
184 * and then set up the DMA transfer registers for a device 181 * and then set up the DMA transfer registers for a device
@@ -189,17 +186,16 @@ EXPORT_SYMBOL_GPL(ide_build_dmatable);
189 * is returned. 186 * is returned.
190 */ 187 */
191 188
192int ide_dma_setup(ide_drive_t *drive) 189int ide_dma_setup(ide_drive_t *drive, struct ide_cmd *cmd)
193{ 190{
194 ide_hwif_t *hwif = drive->hwif; 191 ide_hwif_t *hwif = drive->hwif;
195 struct request *rq = hwif->rq;
196 unsigned int reading = rq_data_dir(rq) ? 0 : ATA_DMA_WR;
197 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0; 192 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
193 u8 rw = (cmd->tf_flags & IDE_TFLAG_WRITE) ? 0 : ATA_DMA_WR;
198 u8 dma_stat; 194 u8 dma_stat;
199 195
200 /* fall back to pio! */ 196 /* fall back to pio! */
201 if (!ide_build_dmatable(drive, rq)) { 197 if (ide_build_dmatable(drive, cmd) == 0) {
202 ide_map_sg(drive, rq); 198 ide_map_sg(drive, cmd);
203 return 1; 199 return 1;
204 } 200 }
205 201
@@ -212,9 +208,9 @@ int ide_dma_setup(ide_drive_t *drive)
212 208
213 /* specify r/w */ 209 /* specify r/w */
214 if (mmio) 210 if (mmio)
215 writeb(reading, (void __iomem *)(hwif->dma_base + ATA_DMA_CMD)); 211 writeb(rw, (void __iomem *)(hwif->dma_base + ATA_DMA_CMD));
216 else 212 else
217 outb(reading, hwif->dma_base + ATA_DMA_CMD); 213 outb(rw, hwif->dma_base + ATA_DMA_CMD);
218 214
219 /* read DMA status for INTR & ERROR flags */ 215 /* read DMA status for INTR & ERROR flags */
220 dma_stat = hwif->dma_ops->dma_sff_read_status(hwif); 216 dma_stat = hwif->dma_ops->dma_sff_read_status(hwif);
@@ -228,7 +224,7 @@ int ide_dma_setup(ide_drive_t *drive)
228EXPORT_SYMBOL_GPL(ide_dma_setup); 224EXPORT_SYMBOL_GPL(ide_dma_setup);
229 225
230/** 226/**
231 * dma_timer_expiry - handle a DMA timeout 227 * ide_dma_sff_timer_expiry - handle a DMA timeout
232 * @drive: Drive that timed out 228 * @drive: Drive that timed out
233 * 229 *
234 * An IDE DMA transfer timed out. In the event of an error we ask 230 * An IDE DMA transfer timed out. In the event of an error we ask
@@ -241,7 +237,7 @@ EXPORT_SYMBOL_GPL(ide_dma_setup);
241 * This can occur if an interrupt is lost or due to hang or bugs. 237 * This can occur if an interrupt is lost or due to hang or bugs.
242 */ 238 */
243 239
244static int dma_timer_expiry(ide_drive_t *drive) 240int ide_dma_sff_timer_expiry(ide_drive_t *drive)
245{ 241{
246 ide_hwif_t *hwif = drive->hwif; 242 ide_hwif_t *hwif = drive->hwif;
247 u8 dma_stat = hwif->dma_ops->dma_sff_read_status(hwif); 243 u8 dma_stat = hwif->dma_ops->dma_sff_read_status(hwif);
@@ -265,14 +261,7 @@ static int dma_timer_expiry(ide_drive_t *drive)
265 261
266 return 0; /* Status is unknown -- reset the bus */ 262 return 0; /* Status is unknown -- reset the bus */
267} 263}
268 264EXPORT_SYMBOL_GPL(ide_dma_sff_timer_expiry);
269void ide_dma_exec_cmd(ide_drive_t *drive, u8 command)
270{
271 /* issue cmd to drive */
272 ide_execute_command(drive, command, &ide_dma_intr, 2 * WAIT_CMD,
273 dma_timer_expiry);
274}
275EXPORT_SYMBOL_GPL(ide_dma_exec_cmd);
276 265
277void ide_dma_start(ide_drive_t *drive) 266void ide_dma_start(ide_drive_t *drive)
278{ 267{
@@ -346,10 +335,10 @@ EXPORT_SYMBOL_GPL(ide_dma_test_irq);
346const struct ide_dma_ops sff_dma_ops = { 335const struct ide_dma_ops sff_dma_ops = {
347 .dma_host_set = ide_dma_host_set, 336 .dma_host_set = ide_dma_host_set,
348 .dma_setup = ide_dma_setup, 337 .dma_setup = ide_dma_setup,
349 .dma_exec_cmd = ide_dma_exec_cmd,
350 .dma_start = ide_dma_start, 338 .dma_start = ide_dma_start,
351 .dma_end = ide_dma_end, 339 .dma_end = ide_dma_end,
352 .dma_test_irq = ide_dma_test_irq, 340 .dma_test_irq = ide_dma_test_irq,
341 .dma_timer_expiry = ide_dma_sff_timer_expiry,
353 .dma_timeout = ide_dma_timeout, 342 .dma_timeout = ide_dma_timeout,
354 .dma_lost_irq = ide_dma_lost_irq, 343 .dma_lost_irq = ide_dma_lost_irq,
355 .dma_sff_read_status = ide_dma_sff_read_status, 344 .dma_sff_read_status = ide_dma_sff_read_status,
diff --git a/drivers/ide/ide-dma.c b/drivers/ide/ide-dma.c
index a878f4734f81..3dbf80c15491 100644
--- a/drivers/ide/ide-dma.c
+++ b/drivers/ide/ide-dma.c
@@ -96,9 +96,13 @@ ide_startstop_t ide_dma_intr(ide_drive_t *drive)
96 96
97 if (OK_STAT(stat, DRIVE_READY, drive->bad_wstat | ATA_DRQ)) { 97 if (OK_STAT(stat, DRIVE_READY, drive->bad_wstat | ATA_DRQ)) {
98 if (!dma_stat) { 98 if (!dma_stat) {
99 struct request *rq = hwif->rq; 99 struct ide_cmd *cmd = &hwif->cmd;
100 100
101 task_end_request(drive, rq, stat); 101 if ((cmd->tf_flags & IDE_TFLAG_FS) == 0)
102 ide_finish_cmd(drive, cmd, stat);
103 else
104 ide_complete_rq(drive, 0,
105 cmd->rq->nr_sectors << 9);
102 return ide_stopped; 106 return ide_stopped;
103 } 107 }
104 printk(KERN_ERR "%s: %s: bad DMA status (0x%02x)\n", 108 printk(KERN_ERR "%s: %s: bad DMA status (0x%02x)\n",
@@ -106,7 +110,6 @@ ide_startstop_t ide_dma_intr(ide_drive_t *drive)
106 } 110 }
107 return ide_error(drive, "dma_intr", stat); 111 return ide_error(drive, "dma_intr", stat);
108} 112}
109EXPORT_SYMBOL_GPL(ide_dma_intr);
110 113
111int ide_dma_good_drive(ide_drive_t *drive) 114int ide_dma_good_drive(ide_drive_t *drive)
112{ 115{
@@ -116,7 +119,7 @@ int ide_dma_good_drive(ide_drive_t *drive)
116/** 119/**
117 * ide_build_sglist - map IDE scatter gather for DMA I/O 120 * ide_build_sglist - map IDE scatter gather for DMA I/O
118 * @drive: the drive to build the DMA table for 121 * @drive: the drive to build the DMA table for
119 * @rq: the request holding the sg list 122 * @cmd: command
120 * 123 *
121 * Perform the DMA mapping magic necessary to access the source or 124 * Perform the DMA mapping magic necessary to access the source or
122 * target buffers of a request via DMA. The lower layers of the 125 * target buffers of a request via DMA. The lower layers of the
@@ -124,28 +127,29 @@ int ide_dma_good_drive(ide_drive_t *drive)
124 * operate in a portable fashion. 127 * operate in a portable fashion.
125 */ 128 */
126 129
127int ide_build_sglist(ide_drive_t *drive, struct request *rq) 130int ide_build_sglist(ide_drive_t *drive, struct ide_cmd *cmd)
128{ 131{
129 ide_hwif_t *hwif = drive->hwif; 132 ide_hwif_t *hwif = drive->hwif;
130 struct scatterlist *sg = hwif->sg_table; 133 struct scatterlist *sg = hwif->sg_table;
131 int i; 134 int i;
132 135
133 ide_map_sg(drive, rq); 136 ide_map_sg(drive, cmd);
134 137
135 if (rq_data_dir(rq) == READ) 138 if (cmd->tf_flags & IDE_TFLAG_WRITE)
136 hwif->sg_dma_direction = DMA_FROM_DEVICE; 139 cmd->sg_dma_direction = DMA_TO_DEVICE;
137 else 140 else
138 hwif->sg_dma_direction = DMA_TO_DEVICE; 141 cmd->sg_dma_direction = DMA_FROM_DEVICE;
139 142
140 i = dma_map_sg(hwif->dev, sg, hwif->sg_nents, hwif->sg_dma_direction); 143 i = dma_map_sg(hwif->dev, sg, cmd->sg_nents, cmd->sg_dma_direction);
141 if (i) { 144 if (i == 0)
142 hwif->orig_sg_nents = hwif->sg_nents; 145 ide_map_sg(drive, cmd);
143 hwif->sg_nents = i; 146 else {
147 cmd->orig_sg_nents = cmd->sg_nents;
148 cmd->sg_nents = i;
144 } 149 }
145 150
146 return i; 151 return i;
147} 152}
148EXPORT_SYMBOL_GPL(ide_build_sglist);
149 153
150/** 154/**
151 * ide_destroy_dmatable - clean up DMA mapping 155 * ide_destroy_dmatable - clean up DMA mapping
@@ -161,9 +165,10 @@ EXPORT_SYMBOL_GPL(ide_build_sglist);
161void ide_destroy_dmatable(ide_drive_t *drive) 165void ide_destroy_dmatable(ide_drive_t *drive)
162{ 166{
163 ide_hwif_t *hwif = drive->hwif; 167 ide_hwif_t *hwif = drive->hwif;
168 struct ide_cmd *cmd = &hwif->cmd;
164 169
165 dma_unmap_sg(hwif->dev, hwif->sg_table, hwif->orig_sg_nents, 170 dma_unmap_sg(hwif->dev, hwif->sg_table, cmd->orig_sg_nents,
166 hwif->sg_dma_direction); 171 cmd->sg_dma_direction);
167} 172}
168EXPORT_SYMBOL_GPL(ide_destroy_dmatable); 173EXPORT_SYMBOL_GPL(ide_destroy_dmatable);
169 174
diff --git a/drivers/ide/ide-eh.c b/drivers/ide/ide-eh.c
index 1231b5e486f2..11664976eea3 100644
--- a/drivers/ide/ide-eh.c
+++ b/drivers/ide/ide-eh.c
@@ -123,8 +123,18 @@ ide_startstop_t ide_error(ide_drive_t *drive, const char *msg, u8 stat)
123 123
124 /* retry only "normal" I/O: */ 124 /* retry only "normal" I/O: */
125 if (!blk_fs_request(rq)) { 125 if (!blk_fs_request(rq)) {
126 rq->errors = 1; 126 if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE) {
127 ide_end_drive_cmd(drive, stat, err); 127 struct ide_cmd *cmd = rq->special;
128
129 if (cmd)
130 ide_complete_cmd(drive, cmd, stat, err);
131 } else if (blk_pm_request(rq)) {
132 rq->errors = 1;
133 ide_complete_pm_rq(drive, rq);
134 return ide_stopped;
135 }
136 rq->errors = err;
137 ide_complete_rq(drive, err ? -EIO : 0, blk_rq_bytes(rq));
128 return ide_stopped; 138 return ide_stopped;
129 } 139 }
130 140
@@ -136,8 +146,11 @@ static inline void ide_complete_drive_reset(ide_drive_t *drive, int err)
136{ 146{
137 struct request *rq = drive->hwif->rq; 147 struct request *rq = drive->hwif->rq;
138 148
139 if (rq && blk_special_request(rq) && rq->cmd[0] == REQ_DRIVE_RESET) 149 if (rq && blk_special_request(rq) && rq->cmd[0] == REQ_DRIVE_RESET) {
140 ide_end_request(drive, err ? err : 1, 0); 150 if (err <= 0 && rq->errors == 0)
151 rq->errors = -EIO;
152 ide_complete_rq(drive, err ? err : 0, ide_rq_bytes(rq));
153 }
141} 154}
142 155
143/* needed below */ 156/* needed below */
@@ -162,8 +175,7 @@ static ide_startstop_t atapi_reset_pollfunc(ide_drive_t *drive)
162 printk(KERN_INFO "%s: ATAPI reset complete\n", drive->name); 175 printk(KERN_INFO "%s: ATAPI reset complete\n", drive->name);
163 else { 176 else {
164 if (time_before(jiffies, hwif->poll_timeout)) { 177 if (time_before(jiffies, hwif->poll_timeout)) {
165 ide_set_handler(drive, &atapi_reset_pollfunc, HZ/20, 178 ide_set_handler(drive, &atapi_reset_pollfunc, HZ/20);
166 NULL);
167 /* continue polling */ 179 /* continue polling */
168 return ide_started; 180 return ide_started;
169 } 181 }
@@ -225,7 +237,7 @@ static ide_startstop_t reset_pollfunc(ide_drive_t *drive)
225 237
226 if (!OK_STAT(tmp, 0, ATA_BUSY)) { 238 if (!OK_STAT(tmp, 0, ATA_BUSY)) {
227 if (time_before(jiffies, hwif->poll_timeout)) { 239 if (time_before(jiffies, hwif->poll_timeout)) {
228 ide_set_handler(drive, &reset_pollfunc, HZ/20, NULL); 240 ide_set_handler(drive, &reset_pollfunc, HZ/20);
229 /* continue polling */ 241 /* continue polling */
230 return ide_started; 242 return ide_started;
231 } 243 }
@@ -342,7 +354,7 @@ static ide_startstop_t do_reset1(ide_drive_t *drive, int do_not_try_atapi)
342 ndelay(400); 354 ndelay(400);
343 hwif->poll_timeout = jiffies + WAIT_WORSTCASE; 355 hwif->poll_timeout = jiffies + WAIT_WORSTCASE;
344 hwif->polling = 1; 356 hwif->polling = 1;
345 __ide_set_handler(drive, &atapi_reset_pollfunc, HZ/20, NULL); 357 __ide_set_handler(drive, &atapi_reset_pollfunc, HZ/20);
346 spin_unlock_irqrestore(&hwif->lock, flags); 358 spin_unlock_irqrestore(&hwif->lock, flags);
347 return ide_started; 359 return ide_started;
348 } 360 }
@@ -402,7 +414,7 @@ static ide_startstop_t do_reset1(ide_drive_t *drive, int do_not_try_atapi)
402 udelay(10); 414 udelay(10);
403 hwif->poll_timeout = jiffies + WAIT_WORSTCASE; 415 hwif->poll_timeout = jiffies + WAIT_WORSTCASE;
404 hwif->polling = 1; 416 hwif->polling = 1;
405 __ide_set_handler(drive, &reset_pollfunc, HZ/20, NULL); 417 __ide_set_handler(drive, &reset_pollfunc, HZ/20);
406 418
407 /* 419 /*
408 * Some weird controller like resetting themselves to a strange 420 * Some weird controller like resetting themselves to a strange
diff --git a/drivers/ide/ide-floppy.c b/drivers/ide/ide-floppy.c
index 317ec62c33d4..7ae662334835 100644
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -61,50 +61,6 @@
61 */ 61 */
62#define IDEFLOPPY_PC_DELAY (HZ/20) /* default delay for ZIP 100 (50ms) */ 62#define IDEFLOPPY_PC_DELAY (HZ/20) /* default delay for ZIP 100 (50ms) */
63 63
64/* Error code returned in rq->errors to the higher part of the driver. */
65#define IDEFLOPPY_ERROR_GENERAL 101
66
67/*
68 * Used to finish servicing a request. For read/write requests, we will call
69 * ide_end_request to pass to the next buffer.
70 */
71static int ide_floppy_end_request(ide_drive_t *drive, int uptodate, int nsecs)
72{
73 struct ide_disk_obj *floppy = drive->driver_data;
74 struct request *rq = drive->hwif->rq;
75 int error;
76
77 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
78
79 switch (uptodate) {
80 case 0:
81 error = IDEFLOPPY_ERROR_GENERAL;
82 break;
83
84 case 1:
85 error = 0;
86 break;
87
88 default:
89 error = uptodate;
90 }
91
92 if (error)
93 floppy->failed_pc = NULL;
94 /* Why does this happen? */
95 if (!rq)
96 return 0;
97 if (!blk_special_request(rq)) {
98 /* our real local end request function */
99 ide_end_request(drive, uptodate, nsecs);
100 return 0;
101 }
102 rq->errors = error;
103 /* fixme: need to move this local also */
104 ide_end_drive_cmd(drive, 0, 0);
105 return 0;
106}
107
108static void idefloppy_update_buffers(ide_drive_t *drive, 64static void idefloppy_update_buffers(ide_drive_t *drive,
109 struct ide_atapi_pc *pc) 65 struct ide_atapi_pc *pc)
110{ 66{
@@ -112,22 +68,23 @@ static void idefloppy_update_buffers(ide_drive_t *drive,
112 struct bio *bio = rq->bio; 68 struct bio *bio = rq->bio;
113 69
114 while ((bio = rq->bio) != NULL) 70 while ((bio = rq->bio) != NULL)
115 ide_floppy_end_request(drive, 1, 0); 71 ide_complete_rq(drive, 0, ide_rq_bytes(rq));
116} 72}
117 73
118static void ide_floppy_callback(ide_drive_t *drive, int dsc) 74static int ide_floppy_callback(ide_drive_t *drive, int dsc)
119{ 75{
120 struct ide_disk_obj *floppy = drive->driver_data; 76 struct ide_disk_obj *floppy = drive->driver_data;
121 struct ide_atapi_pc *pc = drive->pc; 77 struct ide_atapi_pc *pc = drive->pc;
78 struct request *rq = pc->rq;
122 int uptodate = pc->error ? 0 : 1; 79 int uptodate = pc->error ? 0 : 1;
123 80
124 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__); 81 ide_debug_log(IDE_DBG_FUNC, "enter");
125 82
126 if (floppy->failed_pc == pc) 83 if (drive->failed_pc == pc)
127 floppy->failed_pc = NULL; 84 drive->failed_pc = NULL;
128 85
129 if (pc->c[0] == GPCMD_READ_10 || pc->c[0] == GPCMD_WRITE_10 || 86 if (pc->c[0] == GPCMD_READ_10 || pc->c[0] == GPCMD_WRITE_10 ||
130 (pc->rq && blk_pc_request(pc->rq))) 87 (rq && blk_pc_request(rq)))
131 uptodate = 1; /* FIXME */ 88 uptodate = 1; /* FIXME */
132 else if (pc->c[0] == GPCMD_REQUEST_SENSE) { 89 else if (pc->c[0] == GPCMD_REQUEST_SENSE) {
133 u8 *buf = pc->buf; 90 u8 *buf = pc->buf;
@@ -139,19 +96,22 @@ static void ide_floppy_callback(ide_drive_t *drive, int dsc)
139 floppy->progress_indication = buf[15] & 0x80 ? 96 floppy->progress_indication = buf[15] & 0x80 ?
140 (u16)get_unaligned((u16 *)&buf[16]) : 0x10000; 97 (u16)get_unaligned((u16 *)&buf[16]) : 0x10000;
141 98
142 if (floppy->failed_pc) 99 if (drive->failed_pc)
143 ide_debug_log(IDE_DBG_PC, "pc = %x, ", 100 ide_debug_log(IDE_DBG_PC, "pc = %x",
144 floppy->failed_pc->c[0]); 101 drive->failed_pc->c[0]);
145 102
146 ide_debug_log(IDE_DBG_SENSE, "sense key = %x, asc = %x," 103 ide_debug_log(IDE_DBG_SENSE, "sense key = %x, asc = %x,"
147 "ascq = %x\n", floppy->sense_key, 104 "ascq = %x", floppy->sense_key,
148 floppy->asc, floppy->ascq); 105 floppy->asc, floppy->ascq);
149 } else 106 } else
150 printk(KERN_ERR PFX "Error in REQUEST SENSE itself - " 107 printk(KERN_ERR PFX "Error in REQUEST SENSE itself - "
151 "Aborting request!\n"); 108 "Aborting request!\n");
152 } 109 }
153 110
154 ide_floppy_end_request(drive, uptodate, 0); 111 if (blk_special_request(rq))
112 rq->errors = uptodate ? 0 : IDE_DRV_ERROR_GENERAL;
113
114 return uptodate;
155} 115}
156 116
157static void ide_floppy_report_error(struct ide_disk_obj *floppy, 117static void ide_floppy_report_error(struct ide_disk_obj *floppy,
@@ -170,14 +130,15 @@ static void ide_floppy_report_error(struct ide_disk_obj *floppy,
170 130
171} 131}
172 132
173static ide_startstop_t idefloppy_issue_pc(ide_drive_t *drive, 133static ide_startstop_t ide_floppy_issue_pc(ide_drive_t *drive,
174 struct ide_atapi_pc *pc) 134 struct ide_cmd *cmd,
135 struct ide_atapi_pc *pc)
175{ 136{
176 struct ide_disk_obj *floppy = drive->driver_data; 137 struct ide_disk_obj *floppy = drive->driver_data;
177 138
178 if (floppy->failed_pc == NULL && 139 if (drive->failed_pc == NULL &&
179 pc->c[0] != GPCMD_REQUEST_SENSE) 140 pc->c[0] != GPCMD_REQUEST_SENSE)
180 floppy->failed_pc = pc; 141 drive->failed_pc = pc;
181 142
182 /* Set the current packet command */ 143 /* Set the current packet command */
183 drive->pc = pc; 144 drive->pc = pc;
@@ -186,18 +147,18 @@ static ide_startstop_t idefloppy_issue_pc(ide_drive_t *drive,
186 if (!(pc->flags & PC_FLAG_SUPPRESS_ERROR)) 147 if (!(pc->flags & PC_FLAG_SUPPRESS_ERROR))
187 ide_floppy_report_error(floppy, pc); 148 ide_floppy_report_error(floppy, pc);
188 /* Giving up */ 149 /* Giving up */
189 pc->error = IDEFLOPPY_ERROR_GENERAL; 150 pc->error = IDE_DRV_ERROR_GENERAL;
190 151
191 floppy->failed_pc = NULL; 152 drive->failed_pc = NULL;
192 drive->pc_callback(drive, 0); 153 drive->pc_callback(drive, 0);
193 return ide_stopped; 154 return ide_stopped;
194 } 155 }
195 156
196 ide_debug_log(IDE_DBG_FUNC, "%s: Retry #%d\n", __func__, pc->retries); 157 ide_debug_log(IDE_DBG_FUNC, "retry #%d", pc->retries);
197 158
198 pc->retries++; 159 pc->retries++;
199 160
200 return ide_issue_pc(drive); 161 return ide_issue_pc(drive, cmd);
201} 162}
202 163
203void ide_floppy_create_read_capacity_cmd(struct ide_atapi_pc *pc) 164void ide_floppy_create_read_capacity_cmd(struct ide_atapi_pc *pc)
@@ -242,8 +203,7 @@ static void idefloppy_create_rw_cmd(ide_drive_t *drive,
242 int blocks = rq->nr_sectors / floppy->bs_factor; 203 int blocks = rq->nr_sectors / floppy->bs_factor;
243 int cmd = rq_data_dir(rq); 204 int cmd = rq_data_dir(rq);
244 205
245 ide_debug_log(IDE_DBG_FUNC, "%s: block: %d, blocks: %d\n", __func__, 206 ide_debug_log(IDE_DBG_FUNC, "block: %d, blocks: %d", block, blocks);
246 block, blocks);
247 207
248 ide_init_pc(pc); 208 ide_init_pc(pc);
249 pc->c[0] = cmd == READ ? GPCMD_READ_10 : GPCMD_WRITE_10; 209 pc->c[0] = cmd == READ ? GPCMD_READ_10 : GPCMD_WRITE_10;
@@ -285,34 +245,34 @@ static ide_startstop_t ide_floppy_do_request(ide_drive_t *drive,
285{ 245{
286 struct ide_disk_obj *floppy = drive->driver_data; 246 struct ide_disk_obj *floppy = drive->driver_data;
287 ide_hwif_t *hwif = drive->hwif; 247 ide_hwif_t *hwif = drive->hwif;
248 struct ide_cmd cmd;
288 struct ide_atapi_pc *pc; 249 struct ide_atapi_pc *pc;
289 250
290 ide_debug_log(IDE_DBG_FUNC, "%s: dev: %s, cmd: 0x%x, cmd_type: %x, " 251 if (drive->debug_mask & IDE_DBG_RQ)
291 "errors: %d\n", 252 blk_dump_rq_flags(rq, (rq->rq_disk
292 __func__, rq->rq_disk ? rq->rq_disk->disk_name : "?", 253 ? rq->rq_disk->disk_name
293 rq->cmd[0], rq->cmd_type, rq->errors); 254 : "dev?"));
294
295 ide_debug_log(IDE_DBG_FUNC, "%s: sector: %ld, nr_sectors: %ld, "
296 "current_nr_sectors: %d\n",
297 __func__, (long)rq->sector, rq->nr_sectors,
298 rq->current_nr_sectors);
299 255
300 if (rq->errors >= ERROR_MAX) { 256 if (rq->errors >= ERROR_MAX) {
301 if (floppy->failed_pc) 257 if (drive->failed_pc) {
302 ide_floppy_report_error(floppy, floppy->failed_pc); 258 ide_floppy_report_error(floppy, drive->failed_pc);
303 else 259 drive->failed_pc = NULL;
260 } else
304 printk(KERN_ERR PFX "%s: I/O error\n", drive->name); 261 printk(KERN_ERR PFX "%s: I/O error\n", drive->name);
305 262
306 ide_floppy_end_request(drive, 0, 0); 263 if (blk_special_request(rq)) {
307 return ide_stopped; 264 rq->errors = 0;
265 ide_complete_rq(drive, 0, blk_rq_bytes(rq));
266 return ide_stopped;
267 } else
268 goto out_end;
308 } 269 }
309 if (blk_fs_request(rq)) { 270 if (blk_fs_request(rq)) {
310 if (((long)rq->sector % floppy->bs_factor) || 271 if (((long)rq->sector % floppy->bs_factor) ||
311 (rq->nr_sectors % floppy->bs_factor)) { 272 (rq->nr_sectors % floppy->bs_factor)) {
312 printk(KERN_ERR PFX "%s: unsupported r/w rq size\n", 273 printk(KERN_ERR PFX "%s: unsupported r/w rq size\n",
313 drive->name); 274 drive->name);
314 ide_floppy_end_request(drive, 0, 0); 275 goto out_end;
315 return ide_stopped;
316 } 276 }
317 pc = &floppy->queued_pc; 277 pc = &floppy->queued_pc;
318 idefloppy_create_rw_cmd(drive, pc, rq, (unsigned long)block); 278 idefloppy_create_rw_cmd(drive, pc, rq, (unsigned long)block);
@@ -323,21 +283,33 @@ static ide_startstop_t ide_floppy_do_request(ide_drive_t *drive,
323 idefloppy_blockpc_cmd(floppy, pc, rq); 283 idefloppy_blockpc_cmd(floppy, pc, rq);
324 } else { 284 } else {
325 blk_dump_rq_flags(rq, PFX "unsupported command in queue"); 285 blk_dump_rq_flags(rq, PFX "unsupported command in queue");
326 ide_floppy_end_request(drive, 0, 0); 286 goto out_end;
327 return ide_stopped;
328 } 287 }
329 288
289 memset(&cmd, 0, sizeof(cmd));
290
291 if (rq_data_dir(rq))
292 cmd.tf_flags |= IDE_TFLAG_WRITE;
293
294 cmd.rq = rq;
295
330 if (blk_fs_request(rq) || pc->req_xfer) { 296 if (blk_fs_request(rq) || pc->req_xfer) {
331 ide_init_sg_cmd(drive, rq); 297 ide_init_sg_cmd(&cmd, rq->nr_sectors << 9);
332 ide_map_sg(drive, rq); 298 ide_map_sg(drive, &cmd);
333 } 299 }
334 300
335 pc->sg = hwif->sg_table; 301 pc->sg = hwif->sg_table;
336 pc->sg_cnt = hwif->sg_nents; 302 pc->sg_cnt = cmd.sg_nents;
337 303
338 pc->rq = rq; 304 pc->rq = rq;
339 305
340 return idefloppy_issue_pc(drive, pc); 306 return ide_floppy_issue_pc(drive, &cmd, pc);
307out_end:
308 drive->failed_pc = NULL;
309 if (blk_fs_request(rq) == 0 && rq->errors == 0)
310 rq->errors = -EIO;
311 ide_complete_rq(drive, -EIO, ide_rq_bytes(rq));
312 return ide_stopped;
341} 313}
342 314
343/* 315/*
@@ -438,8 +410,9 @@ static int ide_floppy_get_capacity(ide_drive_t *drive)
438 length = be16_to_cpup((__be16 *)&pc.buf[desc_start + 6]); 410 length = be16_to_cpup((__be16 *)&pc.buf[desc_start + 6]);
439 411
440 ide_debug_log(IDE_DBG_PROBE, "Descriptor %d: %dkB, %d blocks, " 412 ide_debug_log(IDE_DBG_PROBE, "Descriptor %d: %dkB, %d blocks, "
441 "%d sector size\n", 413 "%d sector size",
442 i, blocks * length / 1024, blocks, length); 414 i, blocks * length / 1024,
415 blocks, length);
443 416
444 if (i) 417 if (i)
445 continue; 418 continue;
@@ -495,8 +468,8 @@ static int ide_floppy_get_capacity(ide_drive_t *drive)
495 "in drive\n", drive->name); 468 "in drive\n", drive->name);
496 break; 469 break;
497 } 470 }
498 ide_debug_log(IDE_DBG_PROBE, "Descriptor 0 Code: %d\n", 471 ide_debug_log(IDE_DBG_PROBE, "Descriptor 0 Code: %d",
499 pc.buf[desc_start + 4] & 0x03); 472 pc.buf[desc_start + 4] & 0x03);
500 } 473 }
501 474
502 /* Clik! disk does not support get_flexible_disk_page */ 475 /* Clik! disk does not support get_flexible_disk_page */
@@ -575,6 +548,5 @@ const struct ide_disk_ops ide_atapi_disk_ops = {
575 .init_media = ide_floppy_init_media, 548 .init_media = ide_floppy_init_media,
576 .set_doorlock = ide_set_media_lock, 549 .set_doorlock = ide_set_media_lock,
577 .do_request = ide_floppy_do_request, 550 .do_request = ide_floppy_do_request,
578 .end_request = ide_floppy_end_request,
579 .ioctl = ide_floppy_ioctl, 551 .ioctl = ide_floppy_ioctl,
580}; 552};
diff --git a/drivers/ide/ide-gd.c b/drivers/ide/ide-gd.c
index 047109419902..1aebdf1a4f58 100644
--- a/drivers/ide/ide-gd.c
+++ b/drivers/ide/ide-gd.c
@@ -145,11 +145,6 @@ static ide_startstop_t ide_gd_do_request(ide_drive_t *drive,
145 return drive->disk_ops->do_request(drive, rq, sector); 145 return drive->disk_ops->do_request(drive, rq, sector);
146} 146}
147 147
148static int ide_gd_end_request(ide_drive_t *drive, int uptodate, int nrsecs)
149{
150 return drive->disk_ops->end_request(drive, uptodate, nrsecs);
151}
152
153static struct ide_driver ide_gd_driver = { 148static struct ide_driver ide_gd_driver = {
154 .gen_driver = { 149 .gen_driver = {
155 .owner = THIS_MODULE, 150 .owner = THIS_MODULE,
@@ -162,7 +157,6 @@ static struct ide_driver ide_gd_driver = {
162 .shutdown = ide_gd_shutdown, 157 .shutdown = ide_gd_shutdown,
163 .version = IDE_GD_VERSION, 158 .version = IDE_GD_VERSION,
164 .do_request = ide_gd_do_request, 159 .do_request = ide_gd_do_request,
165 .end_request = ide_gd_end_request,
166#ifdef CONFIG_IDE_PROC_FS 160#ifdef CONFIG_IDE_PROC_FS
167 .proc_entries = ide_disk_proc_entries, 161 .proc_entries = ide_disk_proc_entries,
168 .proc_devsets = ide_disk_proc_devsets, 162 .proc_devsets = ide_disk_proc_devsets,
@@ -182,7 +176,7 @@ static int ide_gd_open(struct block_device *bdev, fmode_t mode)
182 176
183 drive = idkp->drive; 177 drive = idkp->drive;
184 178
185 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__); 179 ide_debug_log(IDE_DBG_FUNC, "enter");
186 180
187 idkp->openers++; 181 idkp->openers++;
188 182
@@ -232,7 +226,7 @@ static int ide_gd_release(struct gendisk *disk, fmode_t mode)
232 struct ide_disk_obj *idkp = ide_drv_g(disk, ide_disk_obj); 226 struct ide_disk_obj *idkp = ide_drv_g(disk, ide_disk_obj);
233 ide_drive_t *drive = idkp->drive; 227 ide_drive_t *drive = idkp->drive;
234 228
235 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__); 229 ide_debug_log(IDE_DBG_FUNC, "enter");
236 230
237 if (idkp->openers == 1) 231 if (idkp->openers == 1)
238 drive->disk_ops->flush(drive); 232 drive->disk_ops->flush(drive);
diff --git a/drivers/ide/ide-gd.h b/drivers/ide/ide-gd.h
index b604bdd318a1..55970772bd04 100644
--- a/drivers/ide/ide-gd.h
+++ b/drivers/ide/ide-gd.h
@@ -8,7 +8,7 @@
8#define IDE_GD_DEBUG_LOG 0 8#define IDE_GD_DEBUG_LOG 0
9 9
10#if IDE_GD_DEBUG_LOG 10#if IDE_GD_DEBUG_LOG
11#define ide_debug_log(lvl, fmt, args...) __ide_debug_log(lvl, fmt, args) 11#define ide_debug_log(lvl, fmt, args...) __ide_debug_log(lvl, fmt, ## args)
12#else 12#else
13#define ide_debug_log(lvl, fmt, args...) do {} while (0) 13#define ide_debug_log(lvl, fmt, args...) do {} while (0)
14#endif 14#endif
@@ -20,8 +20,6 @@ struct ide_disk_obj {
20 struct device dev; 20 struct device dev;
21 unsigned int openers; /* protected by BKL for now */ 21 unsigned int openers; /* protected by BKL for now */
22 22
23 /* Last failed packet command */
24 struct ide_atapi_pc *failed_pc;
25 /* used for blk_{fs,pc}_request() requests */ 23 /* used for blk_{fs,pc}_request() requests */
26 struct ide_atapi_pc queued_pc; 24 struct ide_atapi_pc queued_pc;
27 25
diff --git a/drivers/ide/ide-generic.c b/drivers/ide/ide-generic.c
index 81a5282ce1eb..9d03e8211536 100644
--- a/drivers/ide/ide-generic.c
+++ b/drivers/ide/ide-generic.c
@@ -32,6 +32,10 @@ static int probe_mask;
32module_param(probe_mask, int, 0); 32module_param(probe_mask, int, 0);
33MODULE_PARM_DESC(probe_mask, "probe mask for legacy ISA IDE ports"); 33MODULE_PARM_DESC(probe_mask, "probe mask for legacy ISA IDE ports");
34 34
35static const struct ide_port_info ide_generic_port_info = {
36 .host_flags = IDE_HFLAG_NO_DMA,
37};
38
35static ssize_t store_add(struct class *cls, const char *buf, size_t n) 39static ssize_t store_add(struct class *cls, const char *buf, size_t n)
36{ 40{
37 unsigned int base, ctl; 41 unsigned int base, ctl;
@@ -46,7 +50,7 @@ static ssize_t store_add(struct class *cls, const char *buf, size_t n)
46 hw.irq = irq; 50 hw.irq = irq;
47 hw.chipset = ide_generic; 51 hw.chipset = ide_generic;
48 52
49 rc = ide_host_add(NULL, hws, NULL); 53 rc = ide_host_add(&ide_generic_port_info, hws, NULL);
50 if (rc) 54 if (rc)
51 return rc; 55 return rc;
52 56
@@ -184,7 +188,7 @@ static int __init ide_generic_init(void)
184#endif 188#endif
185 hw.chipset = ide_generic; 189 hw.chipset = ide_generic;
186 190
187 rc = ide_host_add(NULL, hws, NULL); 191 rc = ide_host_add(&ide_generic_port_info, hws, NULL);
188 if (rc) { 192 if (rc) {
189 release_region(io_addr + 0x206, 1); 193 release_region(io_addr + 0x206, 1);
190 release_region(io_addr, 8); 194 release_region(io_addr, 8);
diff --git a/drivers/ide/ide-h8300.c b/drivers/ide/ide-h8300.c
index 9270d3255ee0..ff8339ed59ab 100644
--- a/drivers/ide/ide-h8300.c
+++ b/drivers/ide/ide-h8300.c
@@ -44,53 +44,53 @@ static u16 mm_inw(unsigned long a)
44 return r; 44 return r;
45} 45}
46 46
47static void h8300_tf_load(ide_drive_t *drive, ide_task_t *task) 47static void h8300_tf_load(ide_drive_t *drive, struct ide_cmd *cmd)
48{ 48{
49 ide_hwif_t *hwif = drive->hwif; 49 ide_hwif_t *hwif = drive->hwif;
50 struct ide_io_ports *io_ports = &hwif->io_ports; 50 struct ide_io_ports *io_ports = &hwif->io_ports;
51 struct ide_taskfile *tf = &task->tf; 51 struct ide_taskfile *tf = &cmd->tf;
52 u8 HIHI = (task->tf_flags & IDE_TFLAG_LBA48) ? 0xE0 : 0xEF; 52 u8 HIHI = (cmd->tf_flags & IDE_TFLAG_LBA48) ? 0xE0 : 0xEF;
53 53
54 if (task->tf_flags & IDE_TFLAG_FLAGGED) 54 if (cmd->ftf_flags & IDE_FTFLAG_FLAGGED)
55 HIHI = 0xFF; 55 HIHI = 0xFF;
56 56
57 if (task->tf_flags & IDE_TFLAG_OUT_DATA) 57 if (cmd->ftf_flags & IDE_FTFLAG_OUT_DATA)
58 mm_outw((tf->hob_data << 8) | tf->data, io_ports->data_addr); 58 mm_outw((tf->hob_data << 8) | tf->data, io_ports->data_addr);
59 59
60 if (task->tf_flags & IDE_TFLAG_OUT_HOB_FEATURE) 60 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_FEATURE)
61 outb(tf->hob_feature, io_ports->feature_addr); 61 outb(tf->hob_feature, io_ports->feature_addr);
62 if (task->tf_flags & IDE_TFLAG_OUT_HOB_NSECT) 62 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_NSECT)
63 outb(tf->hob_nsect, io_ports->nsect_addr); 63 outb(tf->hob_nsect, io_ports->nsect_addr);
64 if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAL) 64 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_LBAL)
65 outb(tf->hob_lbal, io_ports->lbal_addr); 65 outb(tf->hob_lbal, io_ports->lbal_addr);
66 if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAM) 66 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_LBAM)
67 outb(tf->hob_lbam, io_ports->lbam_addr); 67 outb(tf->hob_lbam, io_ports->lbam_addr);
68 if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAH) 68 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_LBAH)
69 outb(tf->hob_lbah, io_ports->lbah_addr); 69 outb(tf->hob_lbah, io_ports->lbah_addr);
70 70
71 if (task->tf_flags & IDE_TFLAG_OUT_FEATURE) 71 if (cmd->tf_flags & IDE_TFLAG_OUT_FEATURE)
72 outb(tf->feature, io_ports->feature_addr); 72 outb(tf->feature, io_ports->feature_addr);
73 if (task->tf_flags & IDE_TFLAG_OUT_NSECT) 73 if (cmd->tf_flags & IDE_TFLAG_OUT_NSECT)
74 outb(tf->nsect, io_ports->nsect_addr); 74 outb(tf->nsect, io_ports->nsect_addr);
75 if (task->tf_flags & IDE_TFLAG_OUT_LBAL) 75 if (cmd->tf_flags & IDE_TFLAG_OUT_LBAL)
76 outb(tf->lbal, io_ports->lbal_addr); 76 outb(tf->lbal, io_ports->lbal_addr);
77 if (task->tf_flags & IDE_TFLAG_OUT_LBAM) 77 if (cmd->tf_flags & IDE_TFLAG_OUT_LBAM)
78 outb(tf->lbam, io_ports->lbam_addr); 78 outb(tf->lbam, io_ports->lbam_addr);
79 if (task->tf_flags & IDE_TFLAG_OUT_LBAH) 79 if (cmd->tf_flags & IDE_TFLAG_OUT_LBAH)
80 outb(tf->lbah, io_ports->lbah_addr); 80 outb(tf->lbah, io_ports->lbah_addr);
81 81
82 if (task->tf_flags & IDE_TFLAG_OUT_DEVICE) 82 if (cmd->tf_flags & IDE_TFLAG_OUT_DEVICE)
83 outb((tf->device & HIHI) | drive->select, 83 outb((tf->device & HIHI) | drive->select,
84 io_ports->device_addr); 84 io_ports->device_addr);
85} 85}
86 86
87static void h8300_tf_read(ide_drive_t *drive, ide_task_t *task) 87static void h8300_tf_read(ide_drive_t *drive, struct ide_cmd *cmd)
88{ 88{
89 ide_hwif_t *hwif = drive->hwif; 89 ide_hwif_t *hwif = drive->hwif;
90 struct ide_io_ports *io_ports = &hwif->io_ports; 90 struct ide_io_ports *io_ports = &hwif->io_ports;
91 struct ide_taskfile *tf = &task->tf; 91 struct ide_taskfile *tf = &cmd->tf;
92 92
93 if (task->tf_flags & IDE_TFLAG_IN_DATA) { 93 if (cmd->ftf_flags & IDE_FTFLAG_IN_DATA) {
94 u16 data = mm_inw(io_ports->data_addr); 94 u16 data = mm_inw(io_ports->data_addr);
95 95
96 tf->data = data & 0xff; 96 tf->data = data & 0xff;
@@ -100,31 +100,31 @@ static void h8300_tf_read(ide_drive_t *drive, ide_task_t *task)
100 /* be sure we're looking at the low order bits */ 100 /* be sure we're looking at the low order bits */
101 outb(ATA_DEVCTL_OBS & ~0x80, io_ports->ctl_addr); 101 outb(ATA_DEVCTL_OBS & ~0x80, io_ports->ctl_addr);
102 102
103 if (task->tf_flags & IDE_TFLAG_IN_FEATURE) 103 if (cmd->tf_flags & IDE_TFLAG_IN_FEATURE)
104 tf->feature = inb(io_ports->feature_addr); 104 tf->feature = inb(io_ports->feature_addr);
105 if (task->tf_flags & IDE_TFLAG_IN_NSECT) 105 if (cmd->tf_flags & IDE_TFLAG_IN_NSECT)
106 tf->nsect = inb(io_ports->nsect_addr); 106 tf->nsect = inb(io_ports->nsect_addr);
107 if (task->tf_flags & IDE_TFLAG_IN_LBAL) 107 if (cmd->tf_flags & IDE_TFLAG_IN_LBAL)
108 tf->lbal = inb(io_ports->lbal_addr); 108 tf->lbal = inb(io_ports->lbal_addr);
109 if (task->tf_flags & IDE_TFLAG_IN_LBAM) 109 if (cmd->tf_flags & IDE_TFLAG_IN_LBAM)
110 tf->lbam = inb(io_ports->lbam_addr); 110 tf->lbam = inb(io_ports->lbam_addr);
111 if (task->tf_flags & IDE_TFLAG_IN_LBAH) 111 if (cmd->tf_flags & IDE_TFLAG_IN_LBAH)
112 tf->lbah = inb(io_ports->lbah_addr); 112 tf->lbah = inb(io_ports->lbah_addr);
113 if (task->tf_flags & IDE_TFLAG_IN_DEVICE) 113 if (cmd->tf_flags & IDE_TFLAG_IN_DEVICE)
114 tf->device = inb(io_ports->device_addr); 114 tf->device = inb(io_ports->device_addr);
115 115
116 if (task->tf_flags & IDE_TFLAG_LBA48) { 116 if (cmd->tf_flags & IDE_TFLAG_LBA48) {
117 outb(ATA_DEVCTL_OBS | 0x80, io_ports->ctl_addr); 117 outb(ATA_DEVCTL_OBS | 0x80, io_ports->ctl_addr);
118 118
119 if (task->tf_flags & IDE_TFLAG_IN_HOB_FEATURE) 119 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_FEATURE)
120 tf->hob_feature = inb(io_ports->feature_addr); 120 tf->hob_feature = inb(io_ports->feature_addr);
121 if (task->tf_flags & IDE_TFLAG_IN_HOB_NSECT) 121 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_NSECT)
122 tf->hob_nsect = inb(io_ports->nsect_addr); 122 tf->hob_nsect = inb(io_ports->nsect_addr);
123 if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAL) 123 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAL)
124 tf->hob_lbal = inb(io_ports->lbal_addr); 124 tf->hob_lbal = inb(io_ports->lbal_addr);
125 if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAM) 125 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAM)
126 tf->hob_lbam = inb(io_ports->lbam_addr); 126 tf->hob_lbam = inb(io_ports->lbam_addr);
127 if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAH) 127 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAH)
128 tf->hob_lbah = inb(io_ports->lbah_addr); 128 tf->hob_lbah = inb(io_ports->lbah_addr);
129 } 129 }
130} 130}
@@ -143,13 +143,13 @@ static void mm_insw(unsigned long addr, void *buf, u32 len)
143 *bp = bswap(*(volatile u16 *)addr); 143 *bp = bswap(*(volatile u16 *)addr);
144} 144}
145 145
146static void h8300_input_data(ide_drive_t *drive, struct request *rq, 146static void h8300_input_data(ide_drive_t *drive, struct ide_cmd *cmd,
147 void *buf, unsigned int len) 147 void *buf, unsigned int len)
148{ 148{
149 mm_insw(drive->hwif->io_ports.data_addr, buf, (len + 1) / 2); 149 mm_insw(drive->hwif->io_ports.data_addr, buf, (len + 1) / 2);
150} 150}
151 151
152static void h8300_output_data(ide_drive_t *drive, struct request *rq, 152static void h8300_output_data(ide_drive_t *drive, struct ide_cmd *cmd,
153 void *buf, unsigned int len) 153 void *buf, unsigned int len)
154{ 154{
155 mm_outsw(drive->hwif->io_ports.data_addr, buf, (len + 1) / 2); 155 mm_outsw(drive->hwif->io_ports.data_addr, buf, (len + 1) / 2);
diff --git a/drivers/ide/ide-io-std.c b/drivers/ide/ide-io-std.c
index 45b43dd49cda..2d9c6dc3f956 100644
--- a/drivers/ide/ide-io-std.c
+++ b/drivers/ide/ide-io-std.c
@@ -2,6 +2,13 @@
2#include <linux/kernel.h> 2#include <linux/kernel.h>
3#include <linux/ide.h> 3#include <linux/ide.h>
4 4
5#if defined(CONFIG_ARM) || defined(CONFIG_M68K) || defined(CONFIG_MIPS) || \
6 defined(CONFIG_PARISC) || defined(CONFIG_PPC) || defined(CONFIG_SPARC)
7#include <asm/ide.h>
8#else
9#include <asm-generic/ide_iops.h>
10#endif
11
5/* 12/*
6 * Conventional PIO operations for ATA devices 13 * Conventional PIO operations for ATA devices
7 */ 14 */
@@ -75,24 +82,24 @@ void ide_set_irq(ide_hwif_t *hwif, int on)
75} 82}
76EXPORT_SYMBOL_GPL(ide_set_irq); 83EXPORT_SYMBOL_GPL(ide_set_irq);
77 84
78void ide_tf_load(ide_drive_t *drive, ide_task_t *task) 85void ide_tf_load(ide_drive_t *drive, struct ide_cmd *cmd)
79{ 86{
80 ide_hwif_t *hwif = drive->hwif; 87 ide_hwif_t *hwif = drive->hwif;
81 struct ide_io_ports *io_ports = &hwif->io_ports; 88 struct ide_io_ports *io_ports = &hwif->io_ports;
82 struct ide_taskfile *tf = &task->tf; 89 struct ide_taskfile *tf = &cmd->tf;
83 void (*tf_outb)(u8 addr, unsigned long port); 90 void (*tf_outb)(u8 addr, unsigned long port);
84 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0; 91 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
85 u8 HIHI = (task->tf_flags & IDE_TFLAG_LBA48) ? 0xE0 : 0xEF; 92 u8 HIHI = (cmd->tf_flags & IDE_TFLAG_LBA48) ? 0xE0 : 0xEF;
86 93
87 if (mmio) 94 if (mmio)
88 tf_outb = ide_mm_outb; 95 tf_outb = ide_mm_outb;
89 else 96 else
90 tf_outb = ide_outb; 97 tf_outb = ide_outb;
91 98
92 if (task->tf_flags & IDE_TFLAG_FLAGGED) 99 if (cmd->ftf_flags & IDE_FTFLAG_FLAGGED)
93 HIHI = 0xFF; 100 HIHI = 0xFF;
94 101
95 if (task->tf_flags & IDE_TFLAG_OUT_DATA) { 102 if (cmd->ftf_flags & IDE_FTFLAG_OUT_DATA) {
96 u16 data = (tf->hob_data << 8) | tf->data; 103 u16 data = (tf->hob_data << 8) | tf->data;
97 104
98 if (mmio) 105 if (mmio)
@@ -101,39 +108,39 @@ void ide_tf_load(ide_drive_t *drive, ide_task_t *task)
101 outw(data, io_ports->data_addr); 108 outw(data, io_ports->data_addr);
102 } 109 }
103 110
104 if (task->tf_flags & IDE_TFLAG_OUT_HOB_FEATURE) 111 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_FEATURE)
105 tf_outb(tf->hob_feature, io_ports->feature_addr); 112 tf_outb(tf->hob_feature, io_ports->feature_addr);
106 if (task->tf_flags & IDE_TFLAG_OUT_HOB_NSECT) 113 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_NSECT)
107 tf_outb(tf->hob_nsect, io_ports->nsect_addr); 114 tf_outb(tf->hob_nsect, io_ports->nsect_addr);
108 if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAL) 115 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_LBAL)
109 tf_outb(tf->hob_lbal, io_ports->lbal_addr); 116 tf_outb(tf->hob_lbal, io_ports->lbal_addr);
110 if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAM) 117 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_LBAM)
111 tf_outb(tf->hob_lbam, io_ports->lbam_addr); 118 tf_outb(tf->hob_lbam, io_ports->lbam_addr);
112 if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAH) 119 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_LBAH)
113 tf_outb(tf->hob_lbah, io_ports->lbah_addr); 120 tf_outb(tf->hob_lbah, io_ports->lbah_addr);
114 121
115 if (task->tf_flags & IDE_TFLAG_OUT_FEATURE) 122 if (cmd->tf_flags & IDE_TFLAG_OUT_FEATURE)
116 tf_outb(tf->feature, io_ports->feature_addr); 123 tf_outb(tf->feature, io_ports->feature_addr);
117 if (task->tf_flags & IDE_TFLAG_OUT_NSECT) 124 if (cmd->tf_flags & IDE_TFLAG_OUT_NSECT)
118 tf_outb(tf->nsect, io_ports->nsect_addr); 125 tf_outb(tf->nsect, io_ports->nsect_addr);
119 if (task->tf_flags & IDE_TFLAG_OUT_LBAL) 126 if (cmd->tf_flags & IDE_TFLAG_OUT_LBAL)
120 tf_outb(tf->lbal, io_ports->lbal_addr); 127 tf_outb(tf->lbal, io_ports->lbal_addr);
121 if (task->tf_flags & IDE_TFLAG_OUT_LBAM) 128 if (cmd->tf_flags & IDE_TFLAG_OUT_LBAM)
122 tf_outb(tf->lbam, io_ports->lbam_addr); 129 tf_outb(tf->lbam, io_ports->lbam_addr);
123 if (task->tf_flags & IDE_TFLAG_OUT_LBAH) 130 if (cmd->tf_flags & IDE_TFLAG_OUT_LBAH)
124 tf_outb(tf->lbah, io_ports->lbah_addr); 131 tf_outb(tf->lbah, io_ports->lbah_addr);
125 132
126 if (task->tf_flags & IDE_TFLAG_OUT_DEVICE) 133 if (cmd->tf_flags & IDE_TFLAG_OUT_DEVICE)
127 tf_outb((tf->device & HIHI) | drive->select, 134 tf_outb((tf->device & HIHI) | drive->select,
128 io_ports->device_addr); 135 io_ports->device_addr);
129} 136}
130EXPORT_SYMBOL_GPL(ide_tf_load); 137EXPORT_SYMBOL_GPL(ide_tf_load);
131 138
132void ide_tf_read(ide_drive_t *drive, ide_task_t *task) 139void ide_tf_read(ide_drive_t *drive, struct ide_cmd *cmd)
133{ 140{
134 ide_hwif_t *hwif = drive->hwif; 141 ide_hwif_t *hwif = drive->hwif;
135 struct ide_io_ports *io_ports = &hwif->io_ports; 142 struct ide_io_ports *io_ports = &hwif->io_ports;
136 struct ide_taskfile *tf = &task->tf; 143 struct ide_taskfile *tf = &cmd->tf;
137 void (*tf_outb)(u8 addr, unsigned long port); 144 void (*tf_outb)(u8 addr, unsigned long port);
138 u8 (*tf_inb)(unsigned long port); 145 u8 (*tf_inb)(unsigned long port);
139 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0; 146 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
@@ -146,7 +153,7 @@ void ide_tf_read(ide_drive_t *drive, ide_task_t *task)
146 tf_inb = ide_inb; 153 tf_inb = ide_inb;
147 } 154 }
148 155
149 if (task->tf_flags & IDE_TFLAG_IN_DATA) { 156 if (cmd->ftf_flags & IDE_FTFLAG_IN_DATA) {
150 u16 data; 157 u16 data;
151 158
152 if (mmio) 159 if (mmio)
@@ -161,31 +168,31 @@ void ide_tf_read(ide_drive_t *drive, ide_task_t *task)
161 /* be sure we're looking at the low order bits */ 168 /* be sure we're looking at the low order bits */
162 tf_outb(ATA_DEVCTL_OBS & ~0x80, io_ports->ctl_addr); 169 tf_outb(ATA_DEVCTL_OBS & ~0x80, io_ports->ctl_addr);
163 170
164 if (task->tf_flags & IDE_TFLAG_IN_FEATURE) 171 if (cmd->tf_flags & IDE_TFLAG_IN_FEATURE)
165 tf->feature = tf_inb(io_ports->feature_addr); 172 tf->feature = tf_inb(io_ports->feature_addr);
166 if (task->tf_flags & IDE_TFLAG_IN_NSECT) 173 if (cmd->tf_flags & IDE_TFLAG_IN_NSECT)
167 tf->nsect = tf_inb(io_ports->nsect_addr); 174 tf->nsect = tf_inb(io_ports->nsect_addr);
168 if (task->tf_flags & IDE_TFLAG_IN_LBAL) 175 if (cmd->tf_flags & IDE_TFLAG_IN_LBAL)
169 tf->lbal = tf_inb(io_ports->lbal_addr); 176 tf->lbal = tf_inb(io_ports->lbal_addr);
170 if (task->tf_flags & IDE_TFLAG_IN_LBAM) 177 if (cmd->tf_flags & IDE_TFLAG_IN_LBAM)
171 tf->lbam = tf_inb(io_ports->lbam_addr); 178 tf->lbam = tf_inb(io_ports->lbam_addr);
172 if (task->tf_flags & IDE_TFLAG_IN_LBAH) 179 if (cmd->tf_flags & IDE_TFLAG_IN_LBAH)
173 tf->lbah = tf_inb(io_ports->lbah_addr); 180 tf->lbah = tf_inb(io_ports->lbah_addr);
174 if (task->tf_flags & IDE_TFLAG_IN_DEVICE) 181 if (cmd->tf_flags & IDE_TFLAG_IN_DEVICE)
175 tf->device = tf_inb(io_ports->device_addr); 182 tf->device = tf_inb(io_ports->device_addr);
176 183
177 if (task->tf_flags & IDE_TFLAG_LBA48) { 184 if (cmd->tf_flags & IDE_TFLAG_LBA48) {
178 tf_outb(ATA_DEVCTL_OBS | 0x80, io_ports->ctl_addr); 185 tf_outb(ATA_DEVCTL_OBS | 0x80, io_ports->ctl_addr);
179 186
180 if (task->tf_flags & IDE_TFLAG_IN_HOB_FEATURE) 187 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_FEATURE)
181 tf->hob_feature = tf_inb(io_ports->feature_addr); 188 tf->hob_feature = tf_inb(io_ports->feature_addr);
182 if (task->tf_flags & IDE_TFLAG_IN_HOB_NSECT) 189 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_NSECT)
183 tf->hob_nsect = tf_inb(io_ports->nsect_addr); 190 tf->hob_nsect = tf_inb(io_ports->nsect_addr);
184 if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAL) 191 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAL)
185 tf->hob_lbal = tf_inb(io_ports->lbal_addr); 192 tf->hob_lbal = tf_inb(io_ports->lbal_addr);
186 if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAM) 193 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAM)
187 tf->hob_lbam = tf_inb(io_ports->lbam_addr); 194 tf->hob_lbam = tf_inb(io_ports->lbam_addr);
188 if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAH) 195 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAH)
189 tf->hob_lbah = tf_inb(io_ports->lbah_addr); 196 tf->hob_lbah = tf_inb(io_ports->lbah_addr);
190 } 197 }
191} 198}
@@ -212,7 +219,7 @@ static void ata_vlb_sync(unsigned long port)
212 * so if an odd len is specified, be sure that there's at least one 219 * so if an odd len is specified, be sure that there's at least one
213 * extra byte allocated for the buffer. 220 * extra byte allocated for the buffer.
214 */ 221 */
215void ide_input_data(ide_drive_t *drive, struct request *rq, void *buf, 222void ide_input_data(ide_drive_t *drive, struct ide_cmd *cmd, void *buf,
216 unsigned int len) 223 unsigned int len)
217{ 224{
218 ide_hwif_t *hwif = drive->hwif; 225 ide_hwif_t *hwif = drive->hwif;
@@ -258,7 +265,7 @@ EXPORT_SYMBOL_GPL(ide_input_data);
258/* 265/*
259 * This is used for most PIO data transfers *to* the IDE interface 266 * This is used for most PIO data transfers *to* the IDE interface
260 */ 267 */
261void ide_output_data(ide_drive_t *drive, struct request *rq, void *buf, 268void ide_output_data(ide_drive_t *drive, struct ide_cmd *cmd, void *buf,
262 unsigned int len) 269 unsigned int len)
263{ 270{
264 ide_hwif_t *hwif = drive->hwif; 271 ide_hwif_t *hwif = drive->hwif;
diff --git a/drivers/ide/ide-io.c b/drivers/ide/ide-io.c
index 2e92497b58aa..1adc5e2e7fb3 100644
--- a/drivers/ide/ide-io.c
+++ b/drivers/ide/ide-io.c
@@ -40,7 +40,6 @@
40#include <linux/pci.h> 40#include <linux/pci.h>
41#include <linux/delay.h> 41#include <linux/delay.h>
42#include <linux/ide.h> 42#include <linux/ide.h>
43#include <linux/hdreg.h>
44#include <linux/completion.h> 43#include <linux/completion.h>
45#include <linux/reboot.h> 44#include <linux/reboot.h>
46#include <linux/cdrom.h> 45#include <linux/cdrom.h>
@@ -55,25 +54,9 @@
55#include <asm/uaccess.h> 54#include <asm/uaccess.h>
56#include <asm/io.h> 55#include <asm/io.h>
57 56
58static int __ide_end_request(ide_drive_t *drive, struct request *rq, 57int ide_end_rq(ide_drive_t *drive, struct request *rq, int error,
59 int uptodate, unsigned int nr_bytes, int dequeue) 58 unsigned int nr_bytes)
60{ 59{
61 int ret = 1;
62 int error = 0;
63
64 if (uptodate <= 0)
65 error = uptodate ? uptodate : -EIO;
66
67 /*
68 * if failfast is set on a request, override number of sectors and
69 * complete the whole request right now
70 */
71 if (blk_noretry_request(rq) && error)
72 nr_bytes = rq->hard_nr_sectors << 9;
73
74 if (!blk_fs_request(rq) && error && !rq->errors)
75 rq->errors = -EIO;
76
77 /* 60 /*
78 * decide whether to reenable DMA -- 3 is a random magic for now, 61 * decide whether to reenable DMA -- 3 is a random magic for now,
79 * if we DMA timeout more than 3 times, just stay in PIO 62 * if we DMA timeout more than 3 times, just stay in PIO
@@ -84,127 +67,86 @@ static int __ide_end_request(ide_drive_t *drive, struct request *rq,
84 ide_dma_on(drive); 67 ide_dma_on(drive);
85 } 68 }
86 69
87 if (!blk_end_request(rq, error, nr_bytes)) 70 return blk_end_request(rq, error, nr_bytes);
88 ret = 0;
89
90 if (ret == 0 && dequeue)
91 drive->hwif->rq = NULL;
92
93 return ret;
94} 71}
72EXPORT_SYMBOL_GPL(ide_end_rq);
95 73
96/** 74void ide_complete_cmd(ide_drive_t *drive, struct ide_cmd *cmd, u8 stat, u8 err)
97 * ide_end_request - complete an IDE I/O
98 * @drive: IDE device for the I/O
99 * @uptodate:
100 * @nr_sectors: number of sectors completed
101 *
102 * This is our end_request wrapper function. We complete the I/O
103 * update random number input and dequeue the request, which if
104 * it was tagged may be out of order.
105 */
106
107int ide_end_request (ide_drive_t *drive, int uptodate, int nr_sectors)
108{ 75{
109 unsigned int nr_bytes = nr_sectors << 9; 76 struct ide_taskfile *tf = &cmd->tf;
110 struct request *rq = drive->hwif->rq; 77 struct request *rq = cmd->rq;
111 78 u8 tf_cmd = tf->command;
112 if (!nr_bytes) { 79
113 if (blk_pc_request(rq)) 80 tf->error = err;
114 nr_bytes = rq->data_len; 81 tf->status = stat;
115 else 82
116 nr_bytes = rq->hard_cur_sectors << 9; 83 drive->hwif->tp_ops->tf_read(drive, cmd);
84
85 if ((cmd->tf_flags & IDE_TFLAG_CUSTOM_HANDLER) &&
86 tf_cmd == ATA_CMD_IDLEIMMEDIATE) {
87 if (tf->lbal != 0xc4) {
88 printk(KERN_ERR "%s: head unload failed!\n",
89 drive->name);
90 ide_tf_dump(drive->name, tf);
91 } else
92 drive->dev_flags |= IDE_DFLAG_PARKED;
117 } 93 }
118 94
119 return __ide_end_request(drive, rq, uptodate, nr_bytes, 1); 95 if (rq && rq->cmd_type == REQ_TYPE_ATA_TASKFILE)
120} 96 memcpy(rq->special, cmd, sizeof(*cmd));
121EXPORT_SYMBOL(ide_end_request);
122 97
123/** 98 if (cmd->tf_flags & IDE_TFLAG_DYN)
124 * ide_end_dequeued_request - complete an IDE I/O 99 kfree(cmd);
125 * @drive: IDE device for the I/O 100}
126 * @uptodate:
127 * @nr_sectors: number of sectors completed
128 *
129 * Complete an I/O that is no longer on the request queue. This
130 * typically occurs when we pull the request and issue a REQUEST_SENSE.
131 * We must still finish the old request but we must not tamper with the
132 * queue in the meantime.
133 *
134 * NOTE: This path does not handle barrier, but barrier is not supported
135 * on ide-cd anyway.
136 */
137 101
138int ide_end_dequeued_request(ide_drive_t *drive, struct request *rq, 102/* obsolete, blk_rq_bytes() should be used instead */
139 int uptodate, int nr_sectors) 103unsigned int ide_rq_bytes(struct request *rq)
140{ 104{
141 BUG_ON(!blk_rq_started(rq)); 105 if (blk_pc_request(rq))
142 106 return rq->data_len;
143 return __ide_end_request(drive, rq, uptodate, nr_sectors << 9, 0); 107 else
108 return rq->hard_cur_sectors << 9;
144} 109}
145EXPORT_SYMBOL_GPL(ide_end_dequeued_request); 110EXPORT_SYMBOL_GPL(ide_rq_bytes);
146 111
147/** 112int ide_complete_rq(ide_drive_t *drive, int error, unsigned int nr_bytes)
148 * ide_end_drive_cmd - end an explicit drive command
149 * @drive: command
150 * @stat: status bits
151 * @err: error bits
152 *
153 * Clean up after success/failure of an explicit drive command.
154 * These get thrown onto the queue so they are synchronized with
155 * real I/O operations on the drive.
156 *
157 * In LBA48 mode we have to read the register set twice to get
158 * all the extra information out.
159 */
160
161void ide_end_drive_cmd (ide_drive_t *drive, u8 stat, u8 err)
162{ 113{
163 ide_hwif_t *hwif = drive->hwif; 114 ide_hwif_t *hwif = drive->hwif;
164 struct request *rq = hwif->rq; 115 struct request *rq = hwif->rq;
116 int rc;
165 117
166 if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE) { 118 /*
167 ide_task_t *task = (ide_task_t *)rq->special; 119 * if failfast is set on a request, override number of sectors
168 120 * and complete the whole request right now
169 if (task) { 121 */
170 struct ide_taskfile *tf = &task->tf; 122 if (blk_noretry_request(rq) && error <= 0)
171 123 nr_bytes = rq->hard_nr_sectors << 9;
172 tf->error = err;
173 tf->status = stat;
174
175 drive->hwif->tp_ops->tf_read(drive, task);
176
177 if (task->tf_flags & IDE_TFLAG_DYN)
178 kfree(task);
179 }
180 } else if (blk_pm_request(rq)) {
181 struct request_pm_state *pm = rq->data;
182
183 ide_complete_power_step(drive, rq);
184 if (pm->pm_step == IDE_PM_COMPLETED)
185 ide_complete_pm_request(drive, rq);
186 return;
187 }
188
189 hwif->rq = NULL;
190 124
191 rq->errors = err; 125 rc = ide_end_rq(drive, rq, error, nr_bytes);
126 if (rc == 0)
127 hwif->rq = NULL;
192 128
193 if (unlikely(blk_end_request(rq, (rq->errors ? -EIO : 0), 129 return rc;
194 blk_rq_bytes(rq))))
195 BUG();
196} 130}
197EXPORT_SYMBOL(ide_end_drive_cmd); 131EXPORT_SYMBOL(ide_complete_rq);
198 132
199void ide_kill_rq(ide_drive_t *drive, struct request *rq) 133void ide_kill_rq(ide_drive_t *drive, struct request *rq)
200{ 134{
201 if (rq->rq_disk) { 135 u8 drv_req = blk_special_request(rq) && rq->rq_disk;
202 struct ide_driver *drv; 136 u8 media = drive->media;
203 137
204 drv = *(struct ide_driver **)rq->rq_disk->private_data; 138 drive->failed_pc = NULL;
205 drv->end_request(drive, 0, 0); 139
206 } else 140 if ((media == ide_floppy || media == ide_tape) && drv_req) {
207 ide_end_request(drive, 0, 0); 141 rq->errors = 0;
142 ide_complete_rq(drive, 0, blk_rq_bytes(rq));
143 } else {
144 if (media == ide_tape)
145 rq->errors = IDE_DRV_ERROR_GENERAL;
146 else if (blk_fs_request(rq) == 0 && rq->errors == 0)
147 rq->errors = -EIO;
148 ide_complete_rq(drive, -EIO, ide_rq_bytes(rq));
149 }
208} 150}
209 151
210static void ide_tf_set_specify_cmd(ide_drive_t *drive, struct ide_taskfile *tf) 152static void ide_tf_set_specify_cmd(ide_drive_t *drive, struct ide_taskfile *tf)
@@ -232,20 +174,20 @@ static void ide_tf_set_setmult_cmd(ide_drive_t *drive, struct ide_taskfile *tf)
232static ide_startstop_t ide_disk_special(ide_drive_t *drive) 174static ide_startstop_t ide_disk_special(ide_drive_t *drive)
233{ 175{
234 special_t *s = &drive->special; 176 special_t *s = &drive->special;
235 ide_task_t args; 177 struct ide_cmd cmd;
236 178
237 memset(&args, 0, sizeof(ide_task_t)); 179 memset(&cmd, 0, sizeof(cmd));
238 args.data_phase = TASKFILE_NO_DATA; 180 cmd.protocol = ATA_PROT_NODATA;
239 181
240 if (s->b.set_geometry) { 182 if (s->b.set_geometry) {
241 s->b.set_geometry = 0; 183 s->b.set_geometry = 0;
242 ide_tf_set_specify_cmd(drive, &args.tf); 184 ide_tf_set_specify_cmd(drive, &cmd.tf);
243 } else if (s->b.recalibrate) { 185 } else if (s->b.recalibrate) {
244 s->b.recalibrate = 0; 186 s->b.recalibrate = 0;
245 ide_tf_set_restore_cmd(drive, &args.tf); 187 ide_tf_set_restore_cmd(drive, &cmd.tf);
246 } else if (s->b.set_multmode) { 188 } else if (s->b.set_multmode) {
247 s->b.set_multmode = 0; 189 s->b.set_multmode = 0;
248 ide_tf_set_setmult_cmd(drive, &args.tf); 190 ide_tf_set_setmult_cmd(drive, &cmd.tf);
249 } else if (s->all) { 191 } else if (s->all) {
250 int special = s->all; 192 int special = s->all;
251 s->all = 0; 193 s->all = 0;
@@ -253,10 +195,10 @@ static ide_startstop_t ide_disk_special(ide_drive_t *drive)
253 return ide_stopped; 195 return ide_stopped;
254 } 196 }
255 197
256 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE | 198 cmd.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE |
257 IDE_TFLAG_CUSTOM_HANDLER; 199 IDE_TFLAG_CUSTOM_HANDLER;
258 200
259 do_rw_taskfile(drive, &args); 201 do_rw_taskfile(drive, &cmd);
260 202
261 return ide_started; 203 return ide_started;
262} 204}
@@ -286,33 +228,29 @@ static ide_startstop_t do_special (ide_drive_t *drive)
286 return ide_stopped; 228 return ide_stopped;
287} 229}
288 230
289void ide_map_sg(ide_drive_t *drive, struct request *rq) 231void ide_map_sg(ide_drive_t *drive, struct ide_cmd *cmd)
290{ 232{
291 ide_hwif_t *hwif = drive->hwif; 233 ide_hwif_t *hwif = drive->hwif;
292 struct scatterlist *sg = hwif->sg_table; 234 struct scatterlist *sg = hwif->sg_table;
235 struct request *rq = cmd->rq;
293 236
294 if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE) { 237 if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE) {
295 sg_init_one(sg, rq->buffer, rq->nr_sectors * SECTOR_SIZE); 238 sg_init_one(sg, rq->buffer, rq->nr_sectors * SECTOR_SIZE);
296 hwif->sg_nents = 1; 239 cmd->sg_nents = 1;
297 } else if (!rq->bio) { 240 } else if (!rq->bio) {
298 sg_init_one(sg, rq->data, rq->data_len); 241 sg_init_one(sg, rq->data, rq->data_len);
299 hwif->sg_nents = 1; 242 cmd->sg_nents = 1;
300 } else { 243 } else
301 hwif->sg_nents = blk_rq_map_sg(drive->queue, rq, sg); 244 cmd->sg_nents = blk_rq_map_sg(drive->queue, rq, sg);
302 }
303} 245}
304
305EXPORT_SYMBOL_GPL(ide_map_sg); 246EXPORT_SYMBOL_GPL(ide_map_sg);
306 247
307void ide_init_sg_cmd(ide_drive_t *drive, struct request *rq) 248void ide_init_sg_cmd(struct ide_cmd *cmd, unsigned int nr_bytes)
308{ 249{
309 ide_hwif_t *hwif = drive->hwif; 250 cmd->nbytes = cmd->nleft = nr_bytes;
310 251 cmd->cursg_ofs = 0;
311 hwif->nsect = hwif->nleft = rq->nr_sectors; 252 cmd->cursg = NULL;
312 hwif->cursg_ofs = 0;
313 hwif->cursg = NULL;
314} 253}
315
316EXPORT_SYMBOL_GPL(ide_init_sg_cmd); 254EXPORT_SYMBOL_GPL(ide_init_sg_cmd);
317 255
318/** 256/**
@@ -330,24 +268,15 @@ EXPORT_SYMBOL_GPL(ide_init_sg_cmd);
330static ide_startstop_t execute_drive_cmd (ide_drive_t *drive, 268static ide_startstop_t execute_drive_cmd (ide_drive_t *drive,
331 struct request *rq) 269 struct request *rq)
332{ 270{
333 ide_hwif_t *hwif = drive->hwif; 271 struct ide_cmd *cmd = rq->special;
334 ide_task_t *task = rq->special; 272
335 273 if (cmd) {
336 if (task) { 274 if (cmd->protocol == ATA_PROT_PIO) {
337 hwif->data_phase = task->data_phase; 275 ide_init_sg_cmd(cmd, rq->nr_sectors << 9);
338 276 ide_map_sg(drive, cmd);
339 switch (hwif->data_phase) {
340 case TASKFILE_MULTI_OUT:
341 case TASKFILE_OUT:
342 case TASKFILE_MULTI_IN:
343 case TASKFILE_IN:
344 ide_init_sg_cmd(drive, rq);
345 ide_map_sg(drive, rq);
346 default:
347 break;
348 } 277 }
349 278
350 return do_rw_taskfile(drive, task); 279 return do_rw_taskfile(drive, cmd);
351 } 280 }
352 281
353 /* 282 /*
@@ -357,8 +286,8 @@ static ide_startstop_t execute_drive_cmd (ide_drive_t *drive,
357#ifdef DEBUG 286#ifdef DEBUG
358 printk("%s: DRIVE_CMD (null)\n", drive->name); 287 printk("%s: DRIVE_CMD (null)\n", drive->name);
359#endif 288#endif
360 ide_end_drive_cmd(drive, hwif->tp_ops->read_status(hwif), 289 rq->errors = 0;
361 ide_read_error(drive)); 290 ide_complete_rq(drive, 0, blk_rq_bytes(rq));
362 291
363 return ide_stopped; 292 return ide_stopped;
364} 293}
@@ -376,9 +305,7 @@ static ide_startstop_t ide_special_rq(ide_drive_t *drive, struct request *rq)
376 case REQ_DRIVE_RESET: 305 case REQ_DRIVE_RESET:
377 return ide_do_reset(drive); 306 return ide_do_reset(drive);
378 default: 307 default:
379 blk_dump_rq_flags(rq, "ide_special_rq - bad request"); 308 BUG();
380 ide_end_request(drive, 0, 0);
381 return ide_stopped;
382 } 309 }
383} 310}
384 311
@@ -438,7 +365,7 @@ static ide_startstop_t start_request (ide_drive_t *drive, struct request *rq)
438 startstop = ide_start_power_step(drive, rq); 365 startstop = ide_start_power_step(drive, rq);
439 if (startstop == ide_stopped && 366 if (startstop == ide_stopped &&
440 pm->pm_step == IDE_PM_COMPLETED) 367 pm->pm_step == IDE_PM_COMPLETED)
441 ide_complete_pm_request(drive, rq); 368 ide_complete_pm_rq(drive, rq);
442 return startstop; 369 return startstop;
443 } else if (!rq->rq_disk && blk_special_request(rq)) 370 } else if (!rq->rq_disk && blk_special_request(rq))
444 /* 371 /*
@@ -501,8 +428,8 @@ static inline int ide_lock_host(struct ide_host *host, ide_hwif_t *hwif)
501 if (host->host_flags & IDE_HFLAG_SERIALIZE) { 428 if (host->host_flags & IDE_HFLAG_SERIALIZE) {
502 rc = test_and_set_bit_lock(IDE_HOST_BUSY, &host->host_busy); 429 rc = test_and_set_bit_lock(IDE_HOST_BUSY, &host->host_busy);
503 if (rc == 0) { 430 if (rc == 0) {
504 /* for atari only */ 431 if (host->get_lock)
505 ide_get_lock(ide_intr, hwif); 432 host->get_lock(ide_intr, hwif);
506 } 433 }
507 } 434 }
508 return rc; 435 return rc;
@@ -511,8 +438,8 @@ static inline int ide_lock_host(struct ide_host *host, ide_hwif_t *hwif)
511static inline void ide_unlock_host(struct ide_host *host) 438static inline void ide_unlock_host(struct ide_host *host)
512{ 439{
513 if (host->host_flags & IDE_HFLAG_SERIALIZE) { 440 if (host->host_flags & IDE_HFLAG_SERIALIZE) {
514 /* for atari only */ 441 if (host->release_lock)
515 ide_release_lock(); 442 host->release_lock();
516 clear_bit_unlock(IDE_HOST_BUSY, &host->host_busy); 443 clear_bit_unlock(IDE_HOST_BUSY, &host->host_busy);
517 } 444 }
518} 445}
@@ -724,6 +651,7 @@ void ide_timer_expiry (unsigned long data)
724 } 651 }
725 } 652 }
726 hwif->handler = NULL; 653 hwif->handler = NULL;
654 hwif->expiry = NULL;
727 /* 655 /*
728 * We need to simulate a real interrupt when invoking 656 * We need to simulate a real interrupt when invoking
729 * the handler() function, which means we need to 657 * the handler() function, which means we need to
@@ -739,7 +667,8 @@ void ide_timer_expiry (unsigned long data)
739 } else if (drive_is_ready(drive)) { 667 } else if (drive_is_ready(drive)) {
740 if (drive->waiting_for_dma) 668 if (drive->waiting_for_dma)
741 hwif->dma_ops->dma_lost_irq(drive); 669 hwif->dma_ops->dma_lost_irq(drive);
742 (void)ide_ack_intr(hwif); 670 if (hwif->ack_intr)
671 hwif->ack_intr(hwif);
743 printk(KERN_WARNING "%s: lost interrupt\n", 672 printk(KERN_WARNING "%s: lost interrupt\n",
744 drive->name); 673 drive->name);
745 startstop = handler(drive); 674 startstop = handler(drive);
@@ -840,6 +769,7 @@ static void unexpected_intr(int irq, ide_hwif_t *hwif)
840irqreturn_t ide_intr (int irq, void *dev_id) 769irqreturn_t ide_intr (int irq, void *dev_id)
841{ 770{
842 ide_hwif_t *hwif = (ide_hwif_t *)dev_id; 771 ide_hwif_t *hwif = (ide_hwif_t *)dev_id;
772 struct ide_host *host = hwif->host;
843 ide_drive_t *uninitialized_var(drive); 773 ide_drive_t *uninitialized_var(drive);
844 ide_handler_t *handler; 774 ide_handler_t *handler;
845 unsigned long flags; 775 unsigned long flags;
@@ -847,14 +777,14 @@ irqreturn_t ide_intr (int irq, void *dev_id)
847 irqreturn_t irq_ret = IRQ_NONE; 777 irqreturn_t irq_ret = IRQ_NONE;
848 int plug_device = 0; 778 int plug_device = 0;
849 779
850 if (hwif->host->host_flags & IDE_HFLAG_SERIALIZE) { 780 if (host->host_flags & IDE_HFLAG_SERIALIZE) {
851 if (hwif != hwif->host->cur_port) 781 if (hwif != host->cur_port)
852 goto out_early; 782 goto out_early;
853 } 783 }
854 784
855 spin_lock_irqsave(&hwif->lock, flags); 785 spin_lock_irqsave(&hwif->lock, flags);
856 786
857 if (!ide_ack_intr(hwif)) 787 if (hwif->ack_intr && hwif->ack_intr(hwif) == 0)
858 goto out; 788 goto out;
859 789
860 handler = hwif->handler; 790 handler = hwif->handler;
@@ -871,27 +801,19 @@ irqreturn_t ide_intr (int irq, void *dev_id)
871 * 801 *
872 * For PCI, we cannot tell the difference, 802 * For PCI, we cannot tell the difference,
873 * so in that case we just ignore it and hope it goes away. 803 * so in that case we just ignore it and hope it goes away.
874 *
875 * FIXME: unexpected_intr should be hwif-> then we can
876 * remove all the ifdef PCI crap
877 */ 804 */
878#ifdef CONFIG_BLK_DEV_IDEPCI 805 if ((host->irq_flags & IRQF_SHARED) == 0) {
879 if (hwif->chipset != ide_pci)
880#endif /* CONFIG_BLK_DEV_IDEPCI */
881 {
882 /* 806 /*
883 * Probably not a shared PCI interrupt, 807 * Probably not a shared PCI interrupt,
884 * so we can safely try to do something about it: 808 * so we can safely try to do something about it:
885 */ 809 */
886 unexpected_intr(irq, hwif); 810 unexpected_intr(irq, hwif);
887#ifdef CONFIG_BLK_DEV_IDEPCI
888 } else { 811 } else {
889 /* 812 /*
890 * Whack the status register, just in case 813 * Whack the status register, just in case
891 * we have a leftover pending IRQ. 814 * we have a leftover pending IRQ.
892 */ 815 */
893 (void)hwif->tp_ops->read_status(hwif); 816 (void)hwif->tp_ops->read_status(hwif);
894#endif /* CONFIG_BLK_DEV_IDEPCI */
895 } 817 }
896 goto out; 818 goto out;
897 } 819 }
@@ -909,6 +831,7 @@ irqreturn_t ide_intr (int irq, void *dev_id)
909 goto out; 831 goto out;
910 832
911 hwif->handler = NULL; 833 hwif->handler = NULL;
834 hwif->expiry = NULL;
912 hwif->req_gen++; 835 hwif->req_gen++;
913 del_timer(&hwif->timer); 836 del_timer(&hwif->timer);
914 spin_unlock(&hwif->lock); 837 spin_unlock(&hwif->lock);
diff --git a/drivers/ide/ide-ioctls.c b/drivers/ide/ide-ioctls.c
index 1be263eb9c07..770142767437 100644
--- a/drivers/ide/ide-ioctls.c
+++ b/drivers/ide/ide-ioctls.c
@@ -111,13 +111,13 @@ static int ide_set_nice_ioctl(ide_drive_t *drive, unsigned long arg)
111 return 0; 111 return 0;
112} 112}
113 113
114static int ide_cmd_ioctl(ide_drive_t *drive, unsigned cmd, unsigned long arg) 114static int ide_cmd_ioctl(ide_drive_t *drive, unsigned long arg)
115{ 115{
116 u8 *buf = NULL; 116 u8 *buf = NULL;
117 int bufsize = 0, err = 0; 117 int bufsize = 0, err = 0;
118 u8 args[4], xfer_rate = 0; 118 u8 args[4], xfer_rate = 0;
119 ide_task_t tfargs; 119 struct ide_cmd cmd;
120 struct ide_taskfile *tf = &tfargs.tf; 120 struct ide_taskfile *tf = &cmd.tf;
121 u16 *id = drive->id; 121 u16 *id = drive->id;
122 122
123 if (NULL == (void *) arg) { 123 if (NULL == (void *) arg) {
@@ -134,24 +134,24 @@ static int ide_cmd_ioctl(ide_drive_t *drive, unsigned cmd, unsigned long arg)
134 if (copy_from_user(args, (void __user *)arg, 4)) 134 if (copy_from_user(args, (void __user *)arg, 4))
135 return -EFAULT; 135 return -EFAULT;
136 136
137 memset(&tfargs, 0, sizeof(ide_task_t)); 137 memset(&cmd, 0, sizeof(cmd));
138 tf->feature = args[2]; 138 tf->feature = args[2];
139 if (args[0] == ATA_CMD_SMART) { 139 if (args[0] == ATA_CMD_SMART) {
140 tf->nsect = args[3]; 140 tf->nsect = args[3];
141 tf->lbal = args[1]; 141 tf->lbal = args[1];
142 tf->lbam = 0x4f; 142 tf->lbam = 0x4f;
143 tf->lbah = 0xc2; 143 tf->lbah = 0xc2;
144 tfargs.tf_flags = IDE_TFLAG_OUT_TF | IDE_TFLAG_IN_NSECT; 144 cmd.tf_flags = IDE_TFLAG_OUT_TF | IDE_TFLAG_IN_NSECT;
145 } else { 145 } else {
146 tf->nsect = args[1]; 146 tf->nsect = args[1];
147 tfargs.tf_flags = IDE_TFLAG_OUT_FEATURE | 147 cmd.tf_flags = IDE_TFLAG_OUT_FEATURE | IDE_TFLAG_OUT_NSECT |
148 IDE_TFLAG_OUT_NSECT | IDE_TFLAG_IN_NSECT; 148 IDE_TFLAG_IN_NSECT;
149 } 149 }
150 tf->command = args[0]; 150 tf->command = args[0];
151 tfargs.data_phase = args[3] ? TASKFILE_IN : TASKFILE_NO_DATA; 151 cmd.protocol = args[3] ? ATA_PROT_PIO : ATA_PROT_NODATA;
152 152
153 if (args[3]) { 153 if (args[3]) {
154 tfargs.tf_flags |= IDE_TFLAG_IO_16BIT; 154 cmd.tf_flags |= IDE_TFLAG_IO_16BIT;
155 bufsize = SECTOR_SIZE * args[3]; 155 bufsize = SECTOR_SIZE * args[3];
156 buf = kzalloc(bufsize, GFP_KERNEL); 156 buf = kzalloc(bufsize, GFP_KERNEL);
157 if (buf == NULL) 157 if (buf == NULL)
@@ -172,7 +172,7 @@ static int ide_cmd_ioctl(ide_drive_t *drive, unsigned cmd, unsigned long arg)
172 } 172 }
173 } 173 }
174 174
175 err = ide_raw_taskfile(drive, &tfargs, buf, args[3]); 175 err = ide_raw_taskfile(drive, &cmd, buf, args[3]);
176 176
177 args[0] = tf->status; 177 args[0] = tf->status;
178 args[1] = tf->error; 178 args[1] = tf->error;
@@ -194,25 +194,25 @@ abort:
194 return err; 194 return err;
195} 195}
196 196
197static int ide_task_ioctl(ide_drive_t *drive, unsigned cmd, unsigned long arg) 197static int ide_task_ioctl(ide_drive_t *drive, unsigned long arg)
198{ 198{
199 void __user *p = (void __user *)arg; 199 void __user *p = (void __user *)arg;
200 int err = 0; 200 int err = 0;
201 u8 args[7]; 201 u8 args[7];
202 ide_task_t task; 202 struct ide_cmd cmd;
203 203
204 if (copy_from_user(args, p, 7)) 204 if (copy_from_user(args, p, 7))
205 return -EFAULT; 205 return -EFAULT;
206 206
207 memset(&task, 0, sizeof(task)); 207 memset(&cmd, 0, sizeof(cmd));
208 memcpy(&task.tf_array[7], &args[1], 6); 208 memcpy(&cmd.tf_array[7], &args[1], 6);
209 task.tf.command = args[0]; 209 cmd.tf.command = args[0];
210 task.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; 210 cmd.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
211 211
212 err = ide_no_data_taskfile(drive, &task); 212 err = ide_no_data_taskfile(drive, &cmd);
213 213
214 args[0] = task.tf.command; 214 args[0] = cmd.tf.command;
215 memcpy(&args[1], &task.tf_array[7], 6); 215 memcpy(&args[1], &cmd.tf_array[7], 6);
216 216
217 if (copy_to_user(p, args, 7)) 217 if (copy_to_user(p, args, 7))
218 err = -EFAULT; 218 err = -EFAULT;
@@ -262,17 +262,17 @@ int generic_ide_ioctl(ide_drive_t *drive, struct block_device *bdev,
262 if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO)) 262 if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
263 return -EACCES; 263 return -EACCES;
264 if (drive->media == ide_disk) 264 if (drive->media == ide_disk)
265 return ide_taskfile_ioctl(drive, cmd, arg); 265 return ide_taskfile_ioctl(drive, arg);
266 return -ENOMSG; 266 return -ENOMSG;
267#endif 267#endif
268 case HDIO_DRIVE_CMD: 268 case HDIO_DRIVE_CMD:
269 if (!capable(CAP_SYS_RAWIO)) 269 if (!capable(CAP_SYS_RAWIO))
270 return -EACCES; 270 return -EACCES;
271 return ide_cmd_ioctl(drive, cmd, arg); 271 return ide_cmd_ioctl(drive, arg);
272 case HDIO_DRIVE_TASK: 272 case HDIO_DRIVE_TASK:
273 if (!capable(CAP_SYS_RAWIO)) 273 if (!capable(CAP_SYS_RAWIO))
274 return -EACCES; 274 return -EACCES;
275 return ide_task_ioctl(drive, cmd, arg); 275 return ide_task_ioctl(drive, arg);
276 case HDIO_DRIVE_RESET: 276 case HDIO_DRIVE_RESET:
277 if (!capable(CAP_SYS_ADMIN)) 277 if (!capable(CAP_SYS_ADMIN))
278 return -EACCES; 278 return -EACCES;
diff --git a/drivers/ide/ide-iops.c b/drivers/ide/ide-iops.c
index 317c5dadd7c0..5403e4a44be4 100644
--- a/drivers/ide/ide-iops.c
+++ b/drivers/ide/ide-iops.c
@@ -31,15 +31,15 @@ void SELECT_DRIVE(ide_drive_t *drive)
31{ 31{
32 ide_hwif_t *hwif = drive->hwif; 32 ide_hwif_t *hwif = drive->hwif;
33 const struct ide_port_ops *port_ops = hwif->port_ops; 33 const struct ide_port_ops *port_ops = hwif->port_ops;
34 ide_task_t task; 34 struct ide_cmd cmd;
35 35
36 if (port_ops && port_ops->selectproc) 36 if (port_ops && port_ops->selectproc)
37 port_ops->selectproc(drive); 37 port_ops->selectproc(drive);
38 38
39 memset(&task, 0, sizeof(task)); 39 memset(&cmd, 0, sizeof(cmd));
40 task.tf_flags = IDE_TFLAG_OUT_DEVICE; 40 cmd.tf_flags = IDE_TFLAG_OUT_DEVICE;
41 41
42 drive->hwif->tp_ops->tf_load(drive, &task); 42 drive->hwif->tp_ops->tf_load(drive, &cmd);
43} 43}
44 44
45void SELECT_MASK(ide_drive_t *drive, int mask) 45void SELECT_MASK(ide_drive_t *drive, int mask)
@@ -52,14 +52,14 @@ void SELECT_MASK(ide_drive_t *drive, int mask)
52 52
53u8 ide_read_error(ide_drive_t *drive) 53u8 ide_read_error(ide_drive_t *drive)
54{ 54{
55 ide_task_t task; 55 struct ide_cmd cmd;
56 56
57 memset(&task, 0, sizeof(task)); 57 memset(&cmd, 0, sizeof(cmd));
58 task.tf_flags = IDE_TFLAG_IN_FEATURE; 58 cmd.tf_flags = IDE_TFLAG_IN_FEATURE;
59 59
60 drive->hwif->tp_ops->tf_read(drive, &task); 60 drive->hwif->tp_ops->tf_read(drive, &cmd);
61 61
62 return task.tf.error; 62 return cmd.tf.error;
63} 63}
64EXPORT_SYMBOL_GPL(ide_read_error); 64EXPORT_SYMBOL_GPL(ide_read_error);
65 65
@@ -329,7 +329,7 @@ int ide_config_drive_speed(ide_drive_t *drive, u8 speed)
329 u16 *id = drive->id, i; 329 u16 *id = drive->id, i;
330 int error = 0; 330 int error = 0;
331 u8 stat; 331 u8 stat;
332 ide_task_t task; 332 struct ide_cmd cmd;
333 333
334#ifdef CONFIG_BLK_DEV_IDEDMA 334#ifdef CONFIG_BLK_DEV_IDEDMA
335 if (hwif->dma_ops) /* check if host supports DMA */ 335 if (hwif->dma_ops) /* check if host supports DMA */
@@ -361,12 +361,12 @@ int ide_config_drive_speed(ide_drive_t *drive, u8 speed)
361 udelay(1); 361 udelay(1);
362 tp_ops->set_irq(hwif, 0); 362 tp_ops->set_irq(hwif, 0);
363 363
364 memset(&task, 0, sizeof(task)); 364 memset(&cmd, 0, sizeof(cmd));
365 task.tf_flags = IDE_TFLAG_OUT_FEATURE | IDE_TFLAG_OUT_NSECT; 365 cmd.tf_flags = IDE_TFLAG_OUT_FEATURE | IDE_TFLAG_OUT_NSECT;
366 task.tf.feature = SETFEATURES_XFER; 366 cmd.tf.feature = SETFEATURES_XFER;
367 task.tf.nsect = speed; 367 cmd.tf.nsect = speed;
368 368
369 tp_ops->tf_load(drive, &task); 369 tp_ops->tf_load(drive, &cmd);
370 370
371 tp_ops->exec_command(hwif, ATA_CMD_SET_FEATURES); 371 tp_ops->exec_command(hwif, ATA_CMD_SET_FEATURES);
372 372
@@ -425,26 +425,25 @@ int ide_config_drive_speed(ide_drive_t *drive, u8 speed)
425 * See also ide_execute_command 425 * See also ide_execute_command
426 */ 426 */
427void __ide_set_handler(ide_drive_t *drive, ide_handler_t *handler, 427void __ide_set_handler(ide_drive_t *drive, ide_handler_t *handler,
428 unsigned int timeout, ide_expiry_t *expiry) 428 unsigned int timeout)
429{ 429{
430 ide_hwif_t *hwif = drive->hwif; 430 ide_hwif_t *hwif = drive->hwif;
431 431
432 BUG_ON(hwif->handler); 432 BUG_ON(hwif->handler);
433 hwif->handler = handler; 433 hwif->handler = handler;
434 hwif->expiry = expiry;
435 hwif->timer.expires = jiffies + timeout; 434 hwif->timer.expires = jiffies + timeout;
436 hwif->req_gen_timer = hwif->req_gen; 435 hwif->req_gen_timer = hwif->req_gen;
437 add_timer(&hwif->timer); 436 add_timer(&hwif->timer);
438} 437}
439 438
440void ide_set_handler (ide_drive_t *drive, ide_handler_t *handler, 439void ide_set_handler(ide_drive_t *drive, ide_handler_t *handler,
441 unsigned int timeout, ide_expiry_t *expiry) 440 unsigned int timeout)
442{ 441{
443 ide_hwif_t *hwif = drive->hwif; 442 ide_hwif_t *hwif = drive->hwif;
444 unsigned long flags; 443 unsigned long flags;
445 444
446 spin_lock_irqsave(&hwif->lock, flags); 445 spin_lock_irqsave(&hwif->lock, flags);
447 __ide_set_handler(drive, handler, timeout, expiry); 446 __ide_set_handler(drive, handler, timeout);
448 spin_unlock_irqrestore(&hwif->lock, flags); 447 spin_unlock_irqrestore(&hwif->lock, flags);
449} 448}
450EXPORT_SYMBOL(ide_set_handler); 449EXPORT_SYMBOL(ide_set_handler);
@@ -452,10 +451,9 @@ EXPORT_SYMBOL(ide_set_handler);
452/** 451/**
453 * ide_execute_command - execute an IDE command 452 * ide_execute_command - execute an IDE command
454 * @drive: IDE drive to issue the command against 453 * @drive: IDE drive to issue the command against
455 * @command: command byte to write 454 * @cmd: command
456 * @handler: handler for next phase 455 * @handler: handler for next phase
457 * @timeout: timeout for command 456 * @timeout: timeout for command
458 * @expiry: handler to run on timeout
459 * 457 *
460 * Helper function to issue an IDE command. This handles the 458 * Helper function to issue an IDE command. This handles the
461 * atomicity requirements, command timing and ensures that the 459 * atomicity requirements, command timing and ensures that the
@@ -463,15 +461,18 @@ EXPORT_SYMBOL(ide_set_handler);
463 * should go via this function or do equivalent locking. 461 * should go via this function or do equivalent locking.
464 */ 462 */
465 463
466void ide_execute_command(ide_drive_t *drive, u8 cmd, ide_handler_t *handler, 464void ide_execute_command(ide_drive_t *drive, struct ide_cmd *cmd,
467 unsigned timeout, ide_expiry_t *expiry) 465 ide_handler_t *handler, unsigned timeout)
468{ 466{
469 ide_hwif_t *hwif = drive->hwif; 467 ide_hwif_t *hwif = drive->hwif;
470 unsigned long flags; 468 unsigned long flags;
471 469
472 spin_lock_irqsave(&hwif->lock, flags); 470 spin_lock_irqsave(&hwif->lock, flags);
473 __ide_set_handler(drive, handler, timeout, expiry); 471 if ((cmd->protocol != ATAPI_PROT_DMA &&
474 hwif->tp_ops->exec_command(hwif, cmd); 472 cmd->protocol != ATAPI_PROT_PIO) ||
473 (drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT))
474 __ide_set_handler(drive, handler, timeout);
475 hwif->tp_ops->exec_command(hwif, cmd->tf.command);
475 /* 476 /*
476 * Drive takes 400nS to respond, we must avoid the IRQ being 477 * Drive takes 400nS to respond, we must avoid the IRQ being
477 * serviced before that. 478 * serviced before that.
@@ -481,19 +482,6 @@ void ide_execute_command(ide_drive_t *drive, u8 cmd, ide_handler_t *handler,
481 ndelay(400); 482 ndelay(400);
482 spin_unlock_irqrestore(&hwif->lock, flags); 483 spin_unlock_irqrestore(&hwif->lock, flags);
483} 484}
484EXPORT_SYMBOL(ide_execute_command);
485
486void ide_execute_pkt_cmd(ide_drive_t *drive)
487{
488 ide_hwif_t *hwif = drive->hwif;
489 unsigned long flags;
490
491 spin_lock_irqsave(&hwif->lock, flags);
492 hwif->tp_ops->exec_command(hwif, ATA_CMD_PACKET);
493 ndelay(400);
494 spin_unlock_irqrestore(&hwif->lock, flags);
495}
496EXPORT_SYMBOL_GPL(ide_execute_pkt_cmd);
497 485
498/* 486/*
499 * ide_wait_not_busy() waits for the currently selected device on the hwif 487 * ide_wait_not_busy() waits for the currently selected device on the hwif
diff --git a/drivers/ide/ide-lib.c b/drivers/ide/ide-lib.c
index f6c683dd2987..217b7fdf2b17 100644
--- a/drivers/ide/ide-lib.c
+++ b/drivers/ide/ide-lib.c
@@ -34,19 +34,19 @@ void ide_toggle_bounce(ide_drive_t *drive, int on)
34static void ide_dump_opcode(ide_drive_t *drive) 34static void ide_dump_opcode(ide_drive_t *drive)
35{ 35{
36 struct request *rq = drive->hwif->rq; 36 struct request *rq = drive->hwif->rq;
37 ide_task_t *task = NULL; 37 struct ide_cmd *cmd = NULL;
38 38
39 if (!rq) 39 if (!rq)
40 return; 40 return;
41 41
42 if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE) 42 if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE)
43 task = rq->special; 43 cmd = rq->special;
44 44
45 printk(KERN_ERR "ide: failed opcode was: "); 45 printk(KERN_ERR "ide: failed opcode was: ");
46 if (task == NULL) 46 if (cmd == NULL)
47 printk(KERN_CONT "unknown\n"); 47 printk(KERN_CONT "unknown\n");
48 else 48 else
49 printk(KERN_CONT "0x%02x\n", task->tf.command); 49 printk(KERN_CONT "0x%02x\n", cmd->tf.command);
50} 50}
51 51
52u64 ide_get_lba_addr(struct ide_taskfile *tf, int lba48) 52u64 ide_get_lba_addr(struct ide_taskfile *tf, int lba48)
@@ -66,18 +66,18 @@ EXPORT_SYMBOL_GPL(ide_get_lba_addr);
66 66
67static void ide_dump_sector(ide_drive_t *drive) 67static void ide_dump_sector(ide_drive_t *drive)
68{ 68{
69 ide_task_t task; 69 struct ide_cmd cmd;
70 struct ide_taskfile *tf = &task.tf; 70 struct ide_taskfile *tf = &cmd.tf;
71 u8 lba48 = !!(drive->dev_flags & IDE_DFLAG_LBA48); 71 u8 lba48 = !!(drive->dev_flags & IDE_DFLAG_LBA48);
72 72
73 memset(&task, 0, sizeof(task)); 73 memset(&cmd, 0, sizeof(cmd));
74 if (lba48) 74 if (lba48)
75 task.tf_flags = IDE_TFLAG_IN_LBA | IDE_TFLAG_IN_HOB_LBA | 75 cmd.tf_flags = IDE_TFLAG_IN_LBA | IDE_TFLAG_IN_HOB_LBA |
76 IDE_TFLAG_LBA48; 76 IDE_TFLAG_LBA48;
77 else 77 else
78 task.tf_flags = IDE_TFLAG_IN_LBA | IDE_TFLAG_IN_DEVICE; 78 cmd.tf_flags = IDE_TFLAG_IN_LBA | IDE_TFLAG_IN_DEVICE;
79 79
80 drive->hwif->tp_ops->tf_read(drive, &task); 80 drive->hwif->tp_ops->tf_read(drive, &cmd);
81 81
82 if (lba48 || (tf->device & ATA_LBA)) 82 if (lba48 || (tf->device & ATA_LBA))
83 printk(KERN_CONT ", LBAsect=%llu", 83 printk(KERN_CONT ", LBAsect=%llu",
diff --git a/drivers/ide/ide-park.c b/drivers/ide/ide-park.c
index f30e52152fcb..9490b446519f 100644
--- a/drivers/ide/ide-park.c
+++ b/drivers/ide/ide-park.c
@@ -1,6 +1,5 @@
1#include <linux/kernel.h> 1#include <linux/kernel.h>
2#include <linux/ide.h> 2#include <linux/ide.h>
3#include <linux/hdreg.h>
4#include <linux/jiffies.h> 3#include <linux/jiffies.h>
5#include <linux/blkdev.h> 4#include <linux/blkdev.h>
6 5
@@ -63,10 +62,10 @@ out:
63 62
64ide_startstop_t ide_do_park_unpark(ide_drive_t *drive, struct request *rq) 63ide_startstop_t ide_do_park_unpark(ide_drive_t *drive, struct request *rq)
65{ 64{
66 ide_task_t task; 65 struct ide_cmd cmd;
67 struct ide_taskfile *tf = &task.tf; 66 struct ide_taskfile *tf = &cmd.tf;
68 67
69 memset(&task, 0, sizeof(task)); 68 memset(&cmd, 0, sizeof(cmd));
70 if (rq->cmd[0] == REQ_PARK_HEADS) { 69 if (rq->cmd[0] == REQ_PARK_HEADS) {
71 drive->sleep = *(unsigned long *)rq->special; 70 drive->sleep = *(unsigned long *)rq->special;
72 drive->dev_flags |= IDE_DFLAG_SLEEPING; 71 drive->dev_flags |= IDE_DFLAG_SLEEPING;
@@ -75,14 +74,16 @@ ide_startstop_t ide_do_park_unpark(ide_drive_t *drive, struct request *rq)
75 tf->lbal = 0x4c; 74 tf->lbal = 0x4c;
76 tf->lbam = 0x4e; 75 tf->lbam = 0x4e;
77 tf->lbah = 0x55; 76 tf->lbah = 0x55;
78 task.tf_flags |= IDE_TFLAG_CUSTOM_HANDLER; 77 cmd.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
79 } else /* cmd == REQ_UNPARK_HEADS */ 78 } else /* cmd == REQ_UNPARK_HEADS */
80 tf->command = ATA_CMD_CHK_POWER; 79 tf->command = ATA_CMD_CHK_POWER;
81 80
82 task.tf_flags |= IDE_TFLAG_TF | IDE_TFLAG_DEVICE; 81 cmd.tf_flags |= IDE_TFLAG_CUSTOM_HANDLER;
83 task.rq = rq; 82 cmd.protocol = ATA_PROT_NODATA;
84 drive->hwif->data_phase = task.data_phase = TASKFILE_NO_DATA; 83
85 return do_rw_taskfile(drive, &task); 84 cmd.rq = rq;
85
86 return do_rw_taskfile(drive, &cmd);
86} 87}
87 88
88ssize_t ide_park_show(struct device *dev, struct device_attribute *attr, 89ssize_t ide_park_show(struct device *dev, struct device_attribute *attr,
diff --git a/drivers/ide/ide-pm.c b/drivers/ide/ide-pm.c
index 60538d9c84ee..ebf2d21ebdcb 100644
--- a/drivers/ide/ide-pm.c
+++ b/drivers/ide/ide-pm.c
@@ -1,6 +1,5 @@
1#include <linux/kernel.h> 1#include <linux/kernel.h>
2#include <linux/ide.h> 2#include <linux/ide.h>
3#include <linux/hdreg.h>
4 3
5int generic_ide_suspend(struct device *dev, pm_message_t mesg) 4int generic_ide_suspend(struct device *dev, pm_message_t mesg)
6{ 5{
@@ -8,7 +7,7 @@ int generic_ide_suspend(struct device *dev, pm_message_t mesg)
8 ide_hwif_t *hwif = drive->hwif; 7 ide_hwif_t *hwif = drive->hwif;
9 struct request *rq; 8 struct request *rq;
10 struct request_pm_state rqpm; 9 struct request_pm_state rqpm;
11 ide_task_t args; 10 struct ide_cmd cmd;
12 int ret; 11 int ret;
13 12
14 /* call ACPI _GTM only once */ 13 /* call ACPI _GTM only once */
@@ -16,10 +15,10 @@ int generic_ide_suspend(struct device *dev, pm_message_t mesg)
16 ide_acpi_get_timing(hwif); 15 ide_acpi_get_timing(hwif);
17 16
18 memset(&rqpm, 0, sizeof(rqpm)); 17 memset(&rqpm, 0, sizeof(rqpm));
19 memset(&args, 0, sizeof(args)); 18 memset(&cmd, 0, sizeof(cmd));
20 rq = blk_get_request(drive->queue, READ, __GFP_WAIT); 19 rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
21 rq->cmd_type = REQ_TYPE_PM_SUSPEND; 20 rq->cmd_type = REQ_TYPE_PM_SUSPEND;
22 rq->special = &args; 21 rq->special = &cmd;
23 rq->data = &rqpm; 22 rq->data = &rqpm;
24 rqpm.pm_step = IDE_PM_START_SUSPEND; 23 rqpm.pm_step = IDE_PM_START_SUSPEND;
25 if (mesg.event == PM_EVENT_PRETHAW) 24 if (mesg.event == PM_EVENT_PRETHAW)
@@ -42,7 +41,7 @@ int generic_ide_resume(struct device *dev)
42 ide_hwif_t *hwif = drive->hwif; 41 ide_hwif_t *hwif = drive->hwif;
43 struct request *rq; 42 struct request *rq;
44 struct request_pm_state rqpm; 43 struct request_pm_state rqpm;
45 ide_task_t args; 44 struct ide_cmd cmd;
46 int err; 45 int err;
47 46
48 /* call ACPI _PS0 / _STM only once */ 47 /* call ACPI _PS0 / _STM only once */
@@ -54,11 +53,11 @@ int generic_ide_resume(struct device *dev)
54 ide_acpi_exec_tfs(drive); 53 ide_acpi_exec_tfs(drive);
55 54
56 memset(&rqpm, 0, sizeof(rqpm)); 55 memset(&rqpm, 0, sizeof(rqpm));
57 memset(&args, 0, sizeof(args)); 56 memset(&cmd, 0, sizeof(cmd));
58 rq = blk_get_request(drive->queue, READ, __GFP_WAIT); 57 rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
59 rq->cmd_type = REQ_TYPE_PM_RESUME; 58 rq->cmd_type = REQ_TYPE_PM_RESUME;
60 rq->cmd_flags |= REQ_PREEMPT; 59 rq->cmd_flags |= REQ_PREEMPT;
61 rq->special = &args; 60 rq->special = &cmd;
62 rq->data = &rqpm; 61 rq->data = &rqpm;
63 rqpm.pm_step = IDE_PM_START_RESUME; 62 rqpm.pm_step = IDE_PM_START_RESUME;
64 rqpm.pm_state = PM_EVENT_ON; 63 rqpm.pm_state = PM_EVENT_ON;
@@ -109,9 +108,9 @@ void ide_complete_power_step(ide_drive_t *drive, struct request *rq)
109ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *rq) 108ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *rq)
110{ 109{
111 struct request_pm_state *pm = rq->data; 110 struct request_pm_state *pm = rq->data;
112 ide_task_t *args = rq->special; 111 struct ide_cmd *cmd = rq->special;
113 112
114 memset(args, 0, sizeof(*args)); 113 memset(cmd, 0, sizeof(*cmd));
115 114
116 switch (pm->pm_step) { 115 switch (pm->pm_step) {
117 case IDE_PM_FLUSH_CACHE: /* Suspend step 1 (flush cache) */ 116 case IDE_PM_FLUSH_CACHE: /* Suspend step 1 (flush cache) */
@@ -124,12 +123,12 @@ ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *rq)
124 return ide_stopped; 123 return ide_stopped;
125 } 124 }
126 if (ata_id_flush_ext_enabled(drive->id)) 125 if (ata_id_flush_ext_enabled(drive->id))
127 args->tf.command = ATA_CMD_FLUSH_EXT; 126 cmd->tf.command = ATA_CMD_FLUSH_EXT;
128 else 127 else
129 args->tf.command = ATA_CMD_FLUSH; 128 cmd->tf.command = ATA_CMD_FLUSH;
130 goto out_do_tf; 129 goto out_do_tf;
131 case IDE_PM_STANDBY: /* Suspend step 2 (standby) */ 130 case IDE_PM_STANDBY: /* Suspend step 2 (standby) */
132 args->tf.command = ATA_CMD_STANDBYNOW1; 131 cmd->tf.command = ATA_CMD_STANDBYNOW1;
133 goto out_do_tf; 132 goto out_do_tf;
134 case IDE_PM_RESTORE_PIO: /* Resume step 1 (restore PIO) */ 133 case IDE_PM_RESTORE_PIO: /* Resume step 1 (restore PIO) */
135 ide_set_max_pio(drive); 134 ide_set_max_pio(drive);
@@ -142,7 +141,7 @@ ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *rq)
142 ide_complete_power_step(drive, rq); 141 ide_complete_power_step(drive, rq);
143 return ide_stopped; 142 return ide_stopped;
144 case IDE_PM_IDLE: /* Resume step 2 (idle) */ 143 case IDE_PM_IDLE: /* Resume step 2 (idle) */
145 args->tf.command = ATA_CMD_IDLEIMMEDIATE; 144 cmd->tf.command = ATA_CMD_IDLEIMMEDIATE;
146 goto out_do_tf; 145 goto out_do_tf;
147 case IDE_PM_RESTORE_DMA: /* Resume step 3 (restore DMA) */ 146 case IDE_PM_RESTORE_DMA: /* Resume step 3 (restore DMA) */
148 /* 147 /*
@@ -160,27 +159,34 @@ ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *rq)
160 } 159 }
161 160
162 pm->pm_step = IDE_PM_COMPLETED; 161 pm->pm_step = IDE_PM_COMPLETED;
162
163 return ide_stopped; 163 return ide_stopped;
164 164
165out_do_tf: 165out_do_tf:
166 args->tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; 166 cmd->tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
167 args->data_phase = TASKFILE_NO_DATA; 167 cmd->protocol = ATA_PROT_NODATA;
168 return do_rw_taskfile(drive, args); 168
169 return do_rw_taskfile(drive, cmd);
169} 170}
170 171
171/** 172/**
172 * ide_complete_pm_request - end the current Power Management request 173 * ide_complete_pm_rq - end the current Power Management request
173 * @drive: target drive 174 * @drive: target drive
174 * @rq: request 175 * @rq: request
175 * 176 *
176 * This function cleans up the current PM request and stops the queue 177 * This function cleans up the current PM request and stops the queue
177 * if necessary. 178 * if necessary.
178 */ 179 */
179void ide_complete_pm_request(ide_drive_t *drive, struct request *rq) 180void ide_complete_pm_rq(ide_drive_t *drive, struct request *rq)
180{ 181{
181 struct request_queue *q = drive->queue; 182 struct request_queue *q = drive->queue;
183 struct request_pm_state *pm = rq->data;
182 unsigned long flags; 184 unsigned long flags;
183 185
186 ide_complete_power_step(drive, rq);
187 if (pm->pm_step != IDE_PM_COMPLETED)
188 return;
189
184#ifdef DEBUG_PM 190#ifdef DEBUG_PM
185 printk("%s: completing PM request, %s\n", drive->name, 191 printk("%s: completing PM request, %s\n", drive->name,
186 blk_pm_suspend_request(rq) ? "suspend" : "resume"); 192 blk_pm_suspend_request(rq) ? "suspend" : "resume");
diff --git a/drivers/ide/ide-pnp.c b/drivers/ide/ide-pnp.c
index bac9b392b689..6e80b774e88a 100644
--- a/drivers/ide/ide-pnp.c
+++ b/drivers/ide/ide-pnp.c
@@ -27,6 +27,10 @@ static struct pnp_device_id idepnp_devices[] = {
27 {.id = ""} 27 {.id = ""}
28}; 28};
29 29
30static const struct ide_port_info ide_pnp_port_info = {
31 .host_flags = IDE_HFLAG_NO_DMA,
32};
33
30static int idepnp_probe(struct pnp_dev *dev, const struct pnp_device_id *dev_id) 34static int idepnp_probe(struct pnp_dev *dev, const struct pnp_device_id *dev_id)
31{ 35{
32 struct ide_host *host; 36 struct ide_host *host;
@@ -60,7 +64,7 @@ static int idepnp_probe(struct pnp_dev *dev, const struct pnp_device_id *dev_id)
60 hw.irq = pnp_irq(dev, 0); 64 hw.irq = pnp_irq(dev, 0);
61 hw.chipset = ide_generic; 65 hw.chipset = ide_generic;
62 66
63 rc = ide_host_add(NULL, hws, &host); 67 rc = ide_host_add(&ide_pnp_port_info, hws, &host);
64 if (rc) 68 if (rc)
65 goto out; 69 goto out;
66 70
diff --git a/drivers/ide/ide-probe.c b/drivers/ide/ide-probe.c
index 974067043fba..548864510ba9 100644
--- a/drivers/ide/ide-probe.c
+++ b/drivers/ide/ide-probe.c
@@ -228,15 +228,9 @@ static void do_identify(ide_drive_t *drive, u8 cmd, u16 *id)
228 m[ATA_ID_PROD_LEN - 1] = '\0'; 228 m[ATA_ID_PROD_LEN - 1] = '\0';
229 229
230 if (strstr(m, "E X A B Y T E N E S T")) 230 if (strstr(m, "E X A B Y T E N E S T"))
231 goto err_misc; 231 drive->dev_flags &= ~IDE_DFLAG_PRESENT;
232 232 else
233 drive->dev_flags |= IDE_DFLAG_PRESENT; 233 drive->dev_flags |= IDE_DFLAG_PRESENT;
234 drive->dev_flags &= ~IDE_DFLAG_DEAD;
235
236 return;
237err_misc:
238 kfree(id);
239 drive->dev_flags &= ~IDE_DFLAG_PRESENT;
240} 234}
241 235
242/** 236/**
@@ -289,13 +283,13 @@ int ide_dev_read_id(ide_drive_t *drive, u8 cmd, u16 *id)
289 * identify command to be sure of reply 283 * identify command to be sure of reply
290 */ 284 */
291 if (cmd == ATA_CMD_ID_ATAPI) { 285 if (cmd == ATA_CMD_ID_ATAPI) {
292 ide_task_t task; 286 struct ide_cmd cmd;
293 287
294 memset(&task, 0, sizeof(task)); 288 memset(&cmd, 0, sizeof(cmd));
295 /* disable DMA & overlap */ 289 /* disable DMA & overlap */
296 task.tf_flags = IDE_TFLAG_OUT_FEATURE; 290 cmd.tf_flags = IDE_TFLAG_OUT_FEATURE;
297 291
298 tp_ops->tf_load(drive, &task); 292 tp_ops->tf_load(drive, &cmd);
299 } 293 }
300 294
301 /* ask drive for ID */ 295 /* ask drive for ID */
@@ -343,14 +337,14 @@ int ide_busy_sleep(ide_hwif_t *hwif, unsigned long timeout, int altstatus)
343 337
344static u8 ide_read_device(ide_drive_t *drive) 338static u8 ide_read_device(ide_drive_t *drive)
345{ 339{
346 ide_task_t task; 340 struct ide_cmd cmd;
347 341
348 memset(&task, 0, sizeof(task)); 342 memset(&cmd, 0, sizeof(cmd));
349 task.tf_flags = IDE_TFLAG_IN_DEVICE; 343 cmd.tf_flags = IDE_TFLAG_IN_DEVICE;
350 344
351 drive->hwif->tp_ops->tf_read(drive, &task); 345 drive->hwif->tp_ops->tf_read(drive, &cmd);
352 346
353 return task.tf.device; 347 return cmd.tf.device;
354} 348}
355 349
356/** 350/**
@@ -505,8 +499,7 @@ static u8 probe_for_drive(ide_drive_t *drive)
505 } 499 }
506 500
507 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0) 501 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
508 /* drive not found */ 502 goto out_free;
509 return 0;
510 503
511 /* identification failed? */ 504 /* identification failed? */
512 if ((drive->dev_flags & IDE_DFLAG_ID_READ) == 0) { 505 if ((drive->dev_flags & IDE_DFLAG_ID_READ) == 0) {
@@ -530,7 +523,7 @@ static u8 probe_for_drive(ide_drive_t *drive)
530 } 523 }
531 524
532 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0) 525 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
533 return 0; 526 goto out_free;
534 527
535 /* The drive wasn't being helpful. Add generic info only */ 528 /* The drive wasn't being helpful. Add generic info only */
536 if ((drive->dev_flags & IDE_DFLAG_ID_READ) == 0) { 529 if ((drive->dev_flags & IDE_DFLAG_ID_READ) == 0) {
@@ -543,7 +536,10 @@ static u8 probe_for_drive(ide_drive_t *drive)
543 ide_disk_init_mult_count(drive); 536 ide_disk_init_mult_count(drive);
544 } 537 }
545 538
546 return !!(drive->dev_flags & IDE_DFLAG_PRESENT); 539 return 1;
540out_free:
541 kfree(drive->id);
542 return 0;
547} 543}
548 544
549static void hwif_release_dev(struct device *dev) 545static void hwif_release_dev(struct device *dev)
@@ -841,34 +837,19 @@ static int ide_port_setup_devices(ide_hwif_t *hwif)
841static int init_irq (ide_hwif_t *hwif) 837static int init_irq (ide_hwif_t *hwif)
842{ 838{
843 struct ide_io_ports *io_ports = &hwif->io_ports; 839 struct ide_io_ports *io_ports = &hwif->io_ports;
844 irq_handler_t irq_handler; 840 struct ide_host *host = hwif->host;
845 int sa = 0; 841 irq_handler_t irq_handler = host->irq_handler;
842 int sa = host->irq_flags;
846 843
847 irq_handler = hwif->host->irq_handler;
848 if (irq_handler == NULL) 844 if (irq_handler == NULL)
849 irq_handler = ide_intr; 845 irq_handler = ide_intr;
850 846
851#if defined(__mc68000__)
852 sa = IRQF_SHARED;
853#endif /* __mc68000__ */
854
855 if (hwif->chipset == ide_pci)
856 sa = IRQF_SHARED;
857
858 if (io_ports->ctl_addr) 847 if (io_ports->ctl_addr)
859 hwif->tp_ops->set_irq(hwif, 1); 848 hwif->tp_ops->set_irq(hwif, 1);
860 849
861 if (request_irq(hwif->irq, irq_handler, sa, hwif->name, hwif)) 850 if (request_irq(hwif->irq, irq_handler, sa, hwif->name, hwif))
862 goto out_up; 851 goto out_up;
863 852
864 if (!hwif->rqsize) {
865 if ((hwif->host_flags & IDE_HFLAG_NO_LBA48) ||
866 (hwif->host_flags & IDE_HFLAG_NO_LBA48_DMA))
867 hwif->rqsize = 256;
868 else
869 hwif->rqsize = 65536;
870 }
871
872#if !defined(__mc68000__) 853#if !defined(__mc68000__)
873 printk(KERN_INFO "%s at 0x%03lx-0x%03lx,0x%03lx on irq %d", hwif->name, 854 printk(KERN_INFO "%s at 0x%03lx-0x%03lx,0x%03lx on irq %d", hwif->name,
874 io_ports->data_addr, io_ports->status_addr, 855 io_ports->data_addr, io_ports->status_addr,
@@ -1080,7 +1061,7 @@ static void ide_init_port(ide_hwif_t *hwif, unsigned int port,
1080 hwif->tp_ops = d->tp_ops; 1061 hwif->tp_ops = d->tp_ops;
1081 1062
1082 /* ->set_pio_mode for DTC2278 is currently limited to port 0 */ 1063 /* ->set_pio_mode for DTC2278 is currently limited to port 0 */
1083 if (hwif->chipset != ide_dtc2278 || hwif->channel == 0) 1064 if ((hwif->host_flags & IDE_HFLAG_DTC2278) == 0 || hwif->channel == 0)
1084 hwif->port_ops = d->port_ops; 1065 hwif->port_ops = d->port_ops;
1085 1066
1086 hwif->swdma_mask = d->swdma_mask; 1067 hwif->swdma_mask = d->swdma_mask;
@@ -1114,6 +1095,13 @@ static void ide_init_port(ide_hwif_t *hwif, unsigned int port,
1114 1095
1115 if (d->max_sectors) 1096 if (d->max_sectors)
1116 hwif->rqsize = d->max_sectors; 1097 hwif->rqsize = d->max_sectors;
1098 else {
1099 if ((hwif->host_flags & IDE_HFLAG_NO_LBA48) ||
1100 (hwif->host_flags & IDE_HFLAG_NO_LBA48_DMA))
1101 hwif->rqsize = 256;
1102 else
1103 hwif->rqsize = 65536;
1104 }
1117 1105
1118 /* call chipset specific routine for each enabled port */ 1106 /* call chipset specific routine for each enabled port */
1119 if (d->init_hwif) 1107 if (d->init_hwif)
@@ -1326,6 +1314,8 @@ struct ide_host *ide_host_alloc(const struct ide_port_info *d, hw_regs_t **hws)
1326 1314
1327 if (d) { 1315 if (d) {
1328 host->init_chipset = d->init_chipset; 1316 host->init_chipset = d->init_chipset;
1317 host->get_lock = d->get_lock;
1318 host->release_lock = d->release_lock;
1329 host->host_flags = d->host_flags; 1319 host->host_flags = d->host_flags;
1330 } 1320 }
1331 1321
@@ -1372,20 +1362,15 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
1372 ide_init_port_hw(hwif, hws[i]); 1362 ide_init_port_hw(hwif, hws[i]);
1373 ide_port_apply_params(hwif); 1363 ide_port_apply_params(hwif);
1374 1364
1375 if (d == NULL) { 1365 if ((i & 1) && mate) {
1376 mate = NULL; 1366 hwif->mate = mate;
1377 } else { 1367 mate->mate = hwif;
1378 if ((i & 1) && mate) {
1379 hwif->mate = mate;
1380 mate->mate = hwif;
1381 }
1382
1383 mate = (i & 1) ? NULL : hwif;
1384
1385 ide_init_port(hwif, i & 1, d);
1386 ide_port_cable_detect(hwif);
1387 } 1368 }
1388 1369
1370 mate = (i & 1) ? NULL : hwif;
1371
1372 ide_init_port(hwif, i & 1, d);
1373 ide_port_cable_detect(hwif);
1389 ide_port_init_devices(hwif); 1374 ide_port_init_devices(hwif);
1390 } 1375 }
1391 1376
@@ -1396,8 +1381,8 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
1396 if (ide_probe_port(hwif) == 0) 1381 if (ide_probe_port(hwif) == 0)
1397 hwif->present = 1; 1382 hwif->present = 1;
1398 1383
1399 if (hwif->chipset != ide_4drives || !hwif->mate || 1384 if ((hwif->host_flags & IDE_HFLAG_4DRIVES) == 0 ||
1400 !hwif->mate->present) { 1385 hwif->mate == NULL || hwif->mate->present == 0) {
1401 if (ide_register_port(hwif)) { 1386 if (ide_register_port(hwif)) {
1402 ide_disable_port(hwif); 1387 ide_disable_port(hwif);
1403 continue; 1388 continue;
diff --git a/drivers/ide/ide-proc.c b/drivers/ide/ide-proc.c
index 417cde56eafd..10a88bf3eefa 100644
--- a/drivers/ide/ide-proc.c
+++ b/drivers/ide/ide-proc.c
@@ -194,20 +194,20 @@ ide_devset_get(xfer_rate, current_speed);
194 194
195static int set_xfer_rate (ide_drive_t *drive, int arg) 195static int set_xfer_rate (ide_drive_t *drive, int arg)
196{ 196{
197 ide_task_t task; 197 struct ide_cmd cmd;
198 int err; 198 int err;
199 199
200 if (arg < XFER_PIO_0 || arg > XFER_UDMA_6) 200 if (arg < XFER_PIO_0 || arg > XFER_UDMA_6)
201 return -EINVAL; 201 return -EINVAL;
202 202
203 memset(&task, 0, sizeof(task)); 203 memset(&cmd, 0, sizeof(cmd));
204 task.tf.command = ATA_CMD_SET_FEATURES; 204 cmd.tf.command = ATA_CMD_SET_FEATURES;
205 task.tf.feature = SETFEATURES_XFER; 205 cmd.tf.feature = SETFEATURES_XFER;
206 task.tf.nsect = (u8)arg; 206 cmd.tf.nsect = (u8)arg;
207 task.tf_flags = IDE_TFLAG_OUT_FEATURE | IDE_TFLAG_OUT_NSECT | 207 cmd.tf_flags = IDE_TFLAG_OUT_FEATURE | IDE_TFLAG_OUT_NSECT |
208 IDE_TFLAG_IN_NSECT; 208 IDE_TFLAG_IN_NSECT;
209 209
210 err = ide_no_data_taskfile(drive, &task); 210 err = ide_no_data_taskfile(drive, &cmd);
211 211
212 if (!err) { 212 if (!err) {
213 ide_set_xfer_rate(drive, (u8) arg); 213 ide_set_xfer_rate(drive, (u8) arg);
diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c
index 4e6181c7bbda..64dfa7458f8d 100644
--- a/drivers/ide/ide-tape.c
+++ b/drivers/ide/ide-tape.c
@@ -152,11 +152,6 @@ struct idetape_bh {
152#define IDETAPE_LU_RETENSION_MASK 2 152#define IDETAPE_LU_RETENSION_MASK 2
153#define IDETAPE_LU_EOT_MASK 4 153#define IDETAPE_LU_EOT_MASK 4
154 154
155/* Error codes returned in rq->errors to the higher part of the driver. */
156#define IDETAPE_ERROR_GENERAL 101
157#define IDETAPE_ERROR_FILEMARK 102
158#define IDETAPE_ERROR_EOD 103
159
160/* Structures related to the SELECT SENSE / MODE SENSE packet commands. */ 155/* Structures related to the SELECT SENSE / MODE SENSE packet commands. */
161#define IDETAPE_BLOCK_DESCRIPTOR 0 156#define IDETAPE_BLOCK_DESCRIPTOR 0
162#define IDETAPE_CAPABILITIES_PAGE 0x2a 157#define IDETAPE_CAPABILITIES_PAGE 0x2a
@@ -171,14 +166,6 @@ typedef struct ide_tape_obj {
171 struct gendisk *disk; 166 struct gendisk *disk;
172 struct device dev; 167 struct device dev;
173 168
174 /*
175 * failed_pc points to the last failed packet command, or contains
176 * NULL if we do not need to retry any packet command. This is
177 * required since an additional packet command is needed before the
178 * retry, to get detailed information on what went wrong.
179 */
180 /* Last failed packet command */
181 struct ide_atapi_pc *failed_pc;
182 /* used by REQ_IDETAPE_{READ,WRITE} requests */ 169 /* used by REQ_IDETAPE_{READ,WRITE} requests */
183 struct ide_atapi_pc queued_pc; 170 struct ide_atapi_pc queued_pc;
184 171
@@ -245,9 +232,6 @@ typedef struct ide_tape_obj {
245 /* Wasted space in each stage */ 232 /* Wasted space in each stage */
246 int excess_bh_size; 233 int excess_bh_size;
247 234
248 /* protects the ide-tape queue */
249 spinlock_t lock;
250
251 /* Measures average tape speed */ 235 /* Measures average tape speed */
252 unsigned long avg_time; 236 unsigned long avg_time;
253 int avg_size; 237 int avg_size;
@@ -400,7 +384,7 @@ static void idetape_update_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc)
400static void idetape_analyze_error(ide_drive_t *drive, u8 *sense) 384static void idetape_analyze_error(ide_drive_t *drive, u8 *sense)
401{ 385{
402 idetape_tape_t *tape = drive->driver_data; 386 idetape_tape_t *tape = drive->driver_data;
403 struct ide_atapi_pc *pc = tape->failed_pc; 387 struct ide_atapi_pc *pc = drive->failed_pc;
404 388
405 tape->sense_key = sense[2] & 0xF; 389 tape->sense_key = sense[2] & 0xF;
406 tape->asc = sense[12]; 390 tape->asc = sense[12];
@@ -433,19 +417,19 @@ static void idetape_analyze_error(ide_drive_t *drive, u8 *sense)
433 } 417 }
434 } 418 }
435 if (pc->c[0] == READ_6 && (sense[2] & 0x80)) { 419 if (pc->c[0] == READ_6 && (sense[2] & 0x80)) {
436 pc->error = IDETAPE_ERROR_FILEMARK; 420 pc->error = IDE_DRV_ERROR_FILEMARK;
437 pc->flags |= PC_FLAG_ABORT; 421 pc->flags |= PC_FLAG_ABORT;
438 } 422 }
439 if (pc->c[0] == WRITE_6) { 423 if (pc->c[0] == WRITE_6) {
440 if ((sense[2] & 0x40) || (tape->sense_key == 0xd 424 if ((sense[2] & 0x40) || (tape->sense_key == 0xd
441 && tape->asc == 0x0 && tape->ascq == 0x2)) { 425 && tape->asc == 0x0 && tape->ascq == 0x2)) {
442 pc->error = IDETAPE_ERROR_EOD; 426 pc->error = IDE_DRV_ERROR_EOD;
443 pc->flags |= PC_FLAG_ABORT; 427 pc->flags |= PC_FLAG_ABORT;
444 } 428 }
445 } 429 }
446 if (pc->c[0] == READ_6 || pc->c[0] == WRITE_6) { 430 if (pc->c[0] == READ_6 || pc->c[0] == WRITE_6) {
447 if (tape->sense_key == 8) { 431 if (tape->sense_key == 8) {
448 pc->error = IDETAPE_ERROR_EOD; 432 pc->error = IDE_DRV_ERROR_EOD;
449 pc->flags |= PC_FLAG_ABORT; 433 pc->flags |= PC_FLAG_ABORT;
450 } 434 }
451 if (!(pc->flags & PC_FLAG_ABORT) && 435 if (!(pc->flags & PC_FLAG_ABORT) &&
@@ -477,52 +461,23 @@ static void ide_tape_kfree_buffer(idetape_tape_t *tape)
477 } 461 }
478} 462}
479 463
480static int idetape_end_request(ide_drive_t *drive, int uptodate, int nr_sects)
481{
482 struct request *rq = drive->hwif->rq;
483 idetape_tape_t *tape = drive->driver_data;
484 unsigned long flags;
485 int error;
486
487 debug_log(DBG_PROCS, "Enter %s\n", __func__);
488
489 switch (uptodate) {
490 case 0: error = IDETAPE_ERROR_GENERAL; break;
491 case 1: error = 0; break;
492 default: error = uptodate;
493 }
494 rq->errors = error;
495 if (error)
496 tape->failed_pc = NULL;
497
498 if (!blk_special_request(rq)) {
499 ide_end_request(drive, uptodate, nr_sects);
500 return 0;
501 }
502
503 spin_lock_irqsave(&tape->lock, flags);
504
505 ide_end_drive_cmd(drive, 0, 0);
506
507 spin_unlock_irqrestore(&tape->lock, flags);
508 return 0;
509}
510
511static void ide_tape_handle_dsc(ide_drive_t *); 464static void ide_tape_handle_dsc(ide_drive_t *);
512 465
513static void ide_tape_callback(ide_drive_t *drive, int dsc) 466static int ide_tape_callback(ide_drive_t *drive, int dsc)
514{ 467{
515 idetape_tape_t *tape = drive->driver_data; 468 idetape_tape_t *tape = drive->driver_data;
516 struct ide_atapi_pc *pc = drive->pc; 469 struct ide_atapi_pc *pc = drive->pc;
470 struct request *rq = drive->hwif->rq;
517 int uptodate = pc->error ? 0 : 1; 471 int uptodate = pc->error ? 0 : 1;
472 int err = uptodate ? 0 : IDE_DRV_ERROR_GENERAL;
518 473
519 debug_log(DBG_PROCS, "Enter %s\n", __func__); 474 debug_log(DBG_PROCS, "Enter %s\n", __func__);
520 475
521 if (dsc) 476 if (dsc)
522 ide_tape_handle_dsc(drive); 477 ide_tape_handle_dsc(drive);
523 478
524 if (tape->failed_pc == pc) 479 if (drive->failed_pc == pc)
525 tape->failed_pc = NULL; 480 drive->failed_pc = NULL;
526 481
527 if (pc->c[0] == REQUEST_SENSE) { 482 if (pc->c[0] == REQUEST_SENSE) {
528 if (uptodate) 483 if (uptodate)
@@ -531,7 +486,6 @@ static void ide_tape_callback(ide_drive_t *drive, int dsc)
531 printk(KERN_ERR "ide-tape: Error in REQUEST SENSE " 486 printk(KERN_ERR "ide-tape: Error in REQUEST SENSE "
532 "itself - Aborting request!\n"); 487 "itself - Aborting request!\n");
533 } else if (pc->c[0] == READ_6 || pc->c[0] == WRITE_6) { 488 } else if (pc->c[0] == READ_6 || pc->c[0] == WRITE_6) {
534 struct request *rq = drive->hwif->rq;
535 int blocks = pc->xferred / tape->blk_size; 489 int blocks = pc->xferred / tape->blk_size;
536 490
537 tape->avg_size += blocks * tape->blk_size; 491 tape->avg_size += blocks * tape->blk_size;
@@ -546,8 +500,10 @@ static void ide_tape_callback(ide_drive_t *drive, int dsc)
546 tape->first_frame += blocks; 500 tape->first_frame += blocks;
547 rq->current_nr_sectors -= blocks; 501 rq->current_nr_sectors -= blocks;
548 502
549 if (pc->error) 503 if (pc->error) {
550 uptodate = pc->error; 504 uptodate = 0;
505 err = pc->error;
506 }
551 } else if (pc->c[0] == READ_POSITION && uptodate) { 507 } else if (pc->c[0] == READ_POSITION && uptodate) {
552 u8 *readpos = pc->buf; 508 u8 *readpos = pc->buf;
553 509
@@ -561,6 +517,7 @@ static void ide_tape_callback(ide_drive_t *drive, int dsc)
561 "to the tape\n"); 517 "to the tape\n");
562 clear_bit(IDE_AFLAG_ADDRESS_VALID, &drive->atapi_flags); 518 clear_bit(IDE_AFLAG_ADDRESS_VALID, &drive->atapi_flags);
563 uptodate = 0; 519 uptodate = 0;
520 err = IDE_DRV_ERROR_GENERAL;
564 } else { 521 } else {
565 debug_log(DBG_SENSE, "Block Location - %u\n", 522 debug_log(DBG_SENSE, "Block Location - %u\n",
566 be32_to_cpup((__be32 *)&readpos[4])); 523 be32_to_cpup((__be32 *)&readpos[4]));
@@ -571,7 +528,9 @@ static void ide_tape_callback(ide_drive_t *drive, int dsc)
571 } 528 }
572 } 529 }
573 530
574 idetape_end_request(drive, uptodate, 0); 531 rq->errors = err;
532
533 return uptodate;
575} 534}
576 535
577/* 536/*
@@ -621,7 +580,7 @@ static int ide_tape_io_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
621 * 580 *
622 * The handling will be done in three stages: 581 * The handling will be done in three stages:
623 * 582 *
624 * 1. idetape_issue_pc will send the packet command to the drive, and will set 583 * 1. ide_tape_issue_pc will send the packet command to the drive, and will set
625 * the interrupt handler to ide_pc_intr. 584 * the interrupt handler to ide_pc_intr.
626 * 585 *
627 * 2. On each interrupt, ide_pc_intr will be called. This step will be 586 * 2. On each interrupt, ide_pc_intr will be called. This step will be
@@ -649,8 +608,9 @@ static int ide_tape_io_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
649 * request. 608 * request.
650 */ 609 */
651 610
652static ide_startstop_t idetape_issue_pc(ide_drive_t *drive, 611static ide_startstop_t ide_tape_issue_pc(ide_drive_t *drive,
653 struct ide_atapi_pc *pc) 612 struct ide_cmd *cmd,
613 struct ide_atapi_pc *pc)
654{ 614{
655 idetape_tape_t *tape = drive->driver_data; 615 idetape_tape_t *tape = drive->driver_data;
656 616
@@ -660,8 +620,8 @@ static ide_startstop_t idetape_issue_pc(ide_drive_t *drive,
660 "Two request sense in serial were issued\n"); 620 "Two request sense in serial were issued\n");
661 } 621 }
662 622
663 if (tape->failed_pc == NULL && pc->c[0] != REQUEST_SENSE) 623 if (drive->failed_pc == NULL && pc->c[0] != REQUEST_SENSE)
664 tape->failed_pc = pc; 624 drive->failed_pc = pc;
665 625
666 /* Set the current packet command */ 626 /* Set the current packet command */
667 drive->pc = pc; 627 drive->pc = pc;
@@ -685,9 +645,9 @@ static ide_startstop_t idetape_issue_pc(ide_drive_t *drive,
685 tape->ascq); 645 tape->ascq);
686 } 646 }
687 /* Giving up */ 647 /* Giving up */
688 pc->error = IDETAPE_ERROR_GENERAL; 648 pc->error = IDE_DRV_ERROR_GENERAL;
689 } 649 }
690 tape->failed_pc = NULL; 650 drive->failed_pc = NULL;
691 drive->pc_callback(drive, 0); 651 drive->pc_callback(drive, 0);
692 return ide_stopped; 652 return ide_stopped;
693 } 653 }
@@ -695,7 +655,7 @@ static ide_startstop_t idetape_issue_pc(ide_drive_t *drive,
695 655
696 pc->retries++; 656 pc->retries++;
697 657
698 return ide_issue_pc(drive); 658 return ide_issue_pc(drive, cmd);
699} 659}
700 660
701/* A mode sense command is used to "sense" tape parameters. */ 661/* A mode sense command is used to "sense" tape parameters. */
@@ -746,8 +706,8 @@ static ide_startstop_t idetape_media_access_finished(ide_drive_t *drive)
746 } 706 }
747 pc->error = 0; 707 pc->error = 0;
748 } else { 708 } else {
749 pc->error = IDETAPE_ERROR_GENERAL; 709 pc->error = IDE_DRV_ERROR_GENERAL;
750 tape->failed_pc = NULL; 710 drive->failed_pc = NULL;
751 } 711 }
752 drive->pc_callback(drive, 0); 712 drive->pc_callback(drive, 0);
753 return ide_stopped; 713 return ide_stopped;
@@ -790,6 +750,7 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
790 idetape_tape_t *tape = drive->driver_data; 750 idetape_tape_t *tape = drive->driver_data;
791 struct ide_atapi_pc *pc = NULL; 751 struct ide_atapi_pc *pc = NULL;
792 struct request *postponed_rq = tape->postponed_rq; 752 struct request *postponed_rq = tape->postponed_rq;
753 struct ide_cmd cmd;
793 u8 stat; 754 u8 stat;
794 755
795 debug_log(DBG_SENSE, "sector: %llu, nr_sectors: %lu," 756 debug_log(DBG_SENSE, "sector: %llu, nr_sectors: %lu,"
@@ -801,13 +762,15 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
801 /* We do not support buffer cache originated requests. */ 762 /* We do not support buffer cache originated requests. */
802 printk(KERN_NOTICE "ide-tape: %s: Unsupported request in " 763 printk(KERN_NOTICE "ide-tape: %s: Unsupported request in "
803 "request queue (%d)\n", drive->name, rq->cmd_type); 764 "request queue (%d)\n", drive->name, rq->cmd_type);
804 ide_end_request(drive, 0, 0); 765 if (blk_fs_request(rq) == 0 && rq->errors == 0)
766 rq->errors = -EIO;
767 ide_complete_rq(drive, -EIO, ide_rq_bytes(rq));
805 return ide_stopped; 768 return ide_stopped;
806 } 769 }
807 770
808 /* Retry a failed packet command */ 771 /* Retry a failed packet command */
809 if (tape->failed_pc && drive->pc->c[0] == REQUEST_SENSE) { 772 if (drive->failed_pc && drive->pc->c[0] == REQUEST_SENSE) {
810 pc = tape->failed_pc; 773 pc = drive->failed_pc;
811 goto out; 774 goto out;
812 } 775 }
813 776
@@ -815,7 +778,9 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
815 if (rq != postponed_rq) { 778 if (rq != postponed_rq) {
816 printk(KERN_ERR "ide-tape: ide-tape.c bug - " 779 printk(KERN_ERR "ide-tape: ide-tape.c bug - "
817 "Two DSC requests were queued\n"); 780 "Two DSC requests were queued\n");
818 idetape_end_request(drive, 0, 0); 781 drive->failed_pc = NULL;
782 rq->errors = 0;
783 ide_complete_rq(drive, 0, blk_rq_bytes(rq));
819 return ide_stopped; 784 return ide_stopped;
820 } 785 }
821 786
@@ -881,7 +846,14 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
881 BUG(); 846 BUG();
882 847
883out: 848out:
884 return idetape_issue_pc(drive, pc); 849 memset(&cmd, 0, sizeof(cmd));
850
851 if (rq_data_dir(rq))
852 cmd.tf_flags |= IDE_TFLAG_WRITE;
853
854 cmd.rq = rq;
855
856 return ide_tape_issue_pc(drive, &cmd, pc);
885} 857}
886 858
887/* 859/*
@@ -1226,7 +1198,7 @@ static int idetape_queue_rw_tail(ide_drive_t *drive, int cmd, int blocks,
1226 1198
1227 if (tape->merge_bh) 1199 if (tape->merge_bh)
1228 idetape_init_merge_buffer(tape); 1200 idetape_init_merge_buffer(tape);
1229 if (errors == IDETAPE_ERROR_GENERAL) 1201 if (errors == IDE_DRV_ERROR_GENERAL)
1230 return -EIO; 1202 return -EIO;
1231 return ret; 1203 return ret;
1232} 1204}
@@ -2192,8 +2164,6 @@ static void idetape_setup(ide_drive_t *drive, idetape_tape_t *tape, int minor)
2192 drive->pc_update_buffers = idetape_update_buffers; 2164 drive->pc_update_buffers = idetape_update_buffers;
2193 drive->pc_io_buffers = ide_tape_io_buffers; 2165 drive->pc_io_buffers = ide_tape_io_buffers;
2194 2166
2195 spin_lock_init(&tape->lock);
2196
2197 drive->dev_flags |= IDE_DFLAG_DSC_OVERLAP; 2167 drive->dev_flags |= IDE_DFLAG_DSC_OVERLAP;
2198 2168
2199 if (drive->hwif->host_flags & IDE_HFLAG_NO_DSC) { 2169 if (drive->hwif->host_flags & IDE_HFLAG_NO_DSC) {
@@ -2325,7 +2295,6 @@ static struct ide_driver idetape_driver = {
2325 .remove = ide_tape_remove, 2295 .remove = ide_tape_remove,
2326 .version = IDETAPE_VERSION, 2296 .version = IDETAPE_VERSION,
2327 .do_request = idetape_do_request, 2297 .do_request = idetape_do_request,
2328 .end_request = idetape_end_request,
2329#ifdef CONFIG_IDE_PROC_FS 2298#ifdef CONFIG_IDE_PROC_FS
2330 .proc_entries = ide_tape_proc_entries, 2299 .proc_entries = ide_tape_proc_entries,
2331 .proc_devsets = ide_tape_proc_devsets, 2300 .proc_devsets = ide_tape_proc_devsets,
diff --git a/drivers/ide/ide-taskfile.c b/drivers/ide/ide-taskfile.c
index 16138bce84a7..84532be97c00 100644
--- a/drivers/ide/ide-taskfile.c
+++ b/drivers/ide/ide-taskfile.c
@@ -39,88 +39,86 @@ void ide_tf_dump(const char *s, struct ide_taskfile *tf)
39 39
40int taskfile_lib_get_identify (ide_drive_t *drive, u8 *buf) 40int taskfile_lib_get_identify (ide_drive_t *drive, u8 *buf)
41{ 41{
42 ide_task_t args; 42 struct ide_cmd cmd;
43 43
44 memset(&args, 0, sizeof(ide_task_t)); 44 memset(&cmd, 0, sizeof(cmd));
45 args.tf.nsect = 0x01; 45 cmd.tf.nsect = 0x01;
46 if (drive->media == ide_disk) 46 if (drive->media == ide_disk)
47 args.tf.command = ATA_CMD_ID_ATA; 47 cmd.tf.command = ATA_CMD_ID_ATA;
48 else 48 else
49 args.tf.command = ATA_CMD_ID_ATAPI; 49 cmd.tf.command = ATA_CMD_ID_ATAPI;
50 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; 50 cmd.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
51 args.data_phase = TASKFILE_IN; 51 cmd.protocol = ATA_PROT_PIO;
52 return ide_raw_taskfile(drive, &args, buf, 1); 52
53 return ide_raw_taskfile(drive, &cmd, buf, 1);
53} 54}
54 55
55static ide_startstop_t task_no_data_intr(ide_drive_t *); 56static ide_startstop_t task_no_data_intr(ide_drive_t *);
56static ide_startstop_t pre_task_out_intr(ide_drive_t *, struct request *); 57static ide_startstop_t pre_task_out_intr(ide_drive_t *, struct ide_cmd *);
57static ide_startstop_t task_in_intr(ide_drive_t *); 58static ide_startstop_t task_pio_intr(ide_drive_t *);
58 59
59ide_startstop_t do_rw_taskfile (ide_drive_t *drive, ide_task_t *task) 60ide_startstop_t do_rw_taskfile(ide_drive_t *drive, struct ide_cmd *orig_cmd)
60{ 61{
61 ide_hwif_t *hwif = drive->hwif; 62 ide_hwif_t *hwif = drive->hwif;
62 struct ide_taskfile *tf = &task->tf; 63 struct ide_cmd *cmd = &hwif->cmd;
64 struct ide_taskfile *tf = &cmd->tf;
63 ide_handler_t *handler = NULL; 65 ide_handler_t *handler = NULL;
64 const struct ide_tp_ops *tp_ops = hwif->tp_ops; 66 const struct ide_tp_ops *tp_ops = hwif->tp_ops;
65 const struct ide_dma_ops *dma_ops = hwif->dma_ops; 67 const struct ide_dma_ops *dma_ops = hwif->dma_ops;
66 68
67 if (task->data_phase == TASKFILE_MULTI_IN || 69 if (orig_cmd->protocol == ATA_PROT_PIO &&
68 task->data_phase == TASKFILE_MULTI_OUT) { 70 (orig_cmd->tf_flags & IDE_TFLAG_MULTI_PIO) &&
69 if (!drive->mult_count) { 71 drive->mult_count == 0) {
70 printk(KERN_ERR "%s: multimode not set!\n", 72 printk(KERN_ERR "%s: multimode not set!\n", drive->name);
71 drive->name); 73 return ide_stopped;
72 return ide_stopped;
73 }
74 } 74 }
75 75
76 if (task->tf_flags & IDE_TFLAG_FLAGGED) 76 if (orig_cmd->ftf_flags & IDE_FTFLAG_FLAGGED)
77 task->tf_flags |= IDE_TFLAG_FLAGGED_SET_IN_FLAGS; 77 orig_cmd->ftf_flags |= IDE_FTFLAG_SET_IN_FLAGS;
78 78
79 memcpy(&hwif->task, task, sizeof(*task)); 79 memcpy(cmd, orig_cmd, sizeof(*cmd));
80 80
81 if ((task->tf_flags & IDE_TFLAG_DMA_PIO_FALLBACK) == 0) { 81 if ((cmd->tf_flags & IDE_TFLAG_DMA_PIO_FALLBACK) == 0) {
82 ide_tf_dump(drive->name, tf); 82 ide_tf_dump(drive->name, tf);
83 tp_ops->set_irq(hwif, 1); 83 tp_ops->set_irq(hwif, 1);
84 SELECT_MASK(drive, 0); 84 SELECT_MASK(drive, 0);
85 tp_ops->tf_load(drive, task); 85 tp_ops->tf_load(drive, cmd);
86 } 86 }
87 87
88 switch (task->data_phase) { 88 switch (cmd->protocol) {
89 case TASKFILE_MULTI_OUT: 89 case ATA_PROT_PIO:
90 case TASKFILE_OUT: 90 if (cmd->tf_flags & IDE_TFLAG_WRITE) {
91 tp_ops->exec_command(hwif, tf->command); 91 tp_ops->exec_command(hwif, tf->command);
92 ndelay(400); /* FIXME */ 92 ndelay(400); /* FIXME */
93 return pre_task_out_intr(drive, task->rq); 93 return pre_task_out_intr(drive, cmd);
94 case TASKFILE_MULTI_IN: 94 }
95 case TASKFILE_IN: 95 handler = task_pio_intr;
96 handler = task_in_intr;
97 /* fall-through */ 96 /* fall-through */
98 case TASKFILE_NO_DATA: 97 case ATA_PROT_NODATA:
99 if (handler == NULL) 98 if (handler == NULL)
100 handler = task_no_data_intr; 99 handler = task_no_data_intr;
101 ide_execute_command(drive, tf->command, handler, 100 ide_execute_command(drive, cmd, handler, WAIT_WORSTCASE);
102 WAIT_WORSTCASE, NULL);
103 return ide_started; 101 return ide_started;
104 default: 102 case ATA_PROT_DMA:
105 if ((drive->dev_flags & IDE_DFLAG_USING_DMA) == 0 || 103 if ((drive->dev_flags & IDE_DFLAG_USING_DMA) == 0 ||
106 dma_ops->dma_setup(drive)) 104 ide_build_sglist(drive, cmd) == 0 ||
105 dma_ops->dma_setup(drive, cmd))
107 return ide_stopped; 106 return ide_stopped;
108 dma_ops->dma_exec_cmd(drive, tf->command); 107 hwif->expiry = dma_ops->dma_timer_expiry;
108 ide_execute_command(drive, cmd, ide_dma_intr, 2 * WAIT_CMD);
109 dma_ops->dma_start(drive); 109 dma_ops->dma_start(drive);
110 default:
110 return ide_started; 111 return ide_started;
111 } 112 }
112} 113}
113EXPORT_SYMBOL_GPL(do_rw_taskfile); 114EXPORT_SYMBOL_GPL(do_rw_taskfile);
114 115
115/*
116 * Handler for commands without a data phase
117 */
118static ide_startstop_t task_no_data_intr(ide_drive_t *drive) 116static ide_startstop_t task_no_data_intr(ide_drive_t *drive)
119{ 117{
120 ide_hwif_t *hwif = drive->hwif; 118 ide_hwif_t *hwif = drive->hwif;
121 ide_task_t *task = &hwif->task; 119 struct ide_cmd *cmd = &hwif->cmd;
122 struct ide_taskfile *tf = &task->tf; 120 struct ide_taskfile *tf = &cmd->tf;
123 int custom = (task->tf_flags & IDE_TFLAG_CUSTOM_HANDLER) ? 1 : 0; 121 int custom = (cmd->tf_flags & IDE_TFLAG_CUSTOM_HANDLER) ? 1 : 0;
124 int retries = (custom && tf->command == ATA_CMD_INIT_DEV_PARAMS) ? 5 : 1; 122 int retries = (custom && tf->command == ATA_CMD_INIT_DEV_PARAMS) ? 5 : 1;
125 u8 stat; 123 u8 stat;
126 124
@@ -142,28 +140,26 @@ static ide_startstop_t task_no_data_intr(ide_drive_t *drive)
142 } else if (custom && tf->command == ATA_CMD_INIT_DEV_PARAMS) { 140 } else if (custom && tf->command == ATA_CMD_INIT_DEV_PARAMS) {
143 if ((stat & (ATA_ERR | ATA_DRQ)) == 0) { 141 if ((stat & (ATA_ERR | ATA_DRQ)) == 0) {
144 ide_set_handler(drive, &task_no_data_intr, 142 ide_set_handler(drive, &task_no_data_intr,
145 WAIT_WORSTCASE, NULL); 143 WAIT_WORSTCASE);
146 return ide_started; 144 return ide_started;
147 } 145 }
148 } 146 }
149 return ide_error(drive, "task_no_data_intr", stat); 147 return ide_error(drive, "task_no_data_intr", stat);
150 /* calls ide_end_drive_cmd */
151 } 148 }
152 149
153 if (!custom) 150 if (custom && tf->command == ATA_CMD_SET_MULTI)
154 ide_end_drive_cmd(drive, stat, ide_read_error(drive));
155 else if (tf->command == ATA_CMD_IDLEIMMEDIATE) {
156 hwif->tp_ops->tf_read(drive, task);
157 if (tf->lbal != 0xc4) {
158 printk(KERN_ERR "%s: head unload failed!\n",
159 drive->name);
160 ide_tf_dump(drive->name, tf);
161 } else
162 drive->dev_flags |= IDE_DFLAG_PARKED;
163 ide_end_drive_cmd(drive, stat, ide_read_error(drive));
164 } else if (tf->command == ATA_CMD_SET_MULTI)
165 drive->mult_count = drive->mult_req; 151 drive->mult_count = drive->mult_req;
166 152
153 if (custom == 0 || tf->command == ATA_CMD_IDLEIMMEDIATE ||
154 tf->command == ATA_CMD_CHK_POWER) {
155 struct request *rq = hwif->rq;
156
157 if (blk_pm_request(rq))
158 ide_complete_pm_rq(drive, rq);
159 else
160 ide_finish_cmd(drive, cmd, stat);
161 }
162
167 return ide_stopped; 163 return ide_stopped;
168} 164}
169 165
@@ -192,12 +188,12 @@ static u8 wait_drive_not_busy(ide_drive_t *drive)
192 return stat; 188 return stat;
193} 189}
194 190
195static void ide_pio_sector(ide_drive_t *drive, struct request *rq, 191static void ide_pio_bytes(ide_drive_t *drive, struct ide_cmd *cmd,
196 unsigned int write) 192 unsigned int write, unsigned int nr_bytes)
197{ 193{
198 ide_hwif_t *hwif = drive->hwif; 194 ide_hwif_t *hwif = drive->hwif;
199 struct scatterlist *sg = hwif->sg_table; 195 struct scatterlist *sg = hwif->sg_table;
200 struct scatterlist *cursg = hwif->cursg; 196 struct scatterlist *cursg = cmd->cursg;
201 struct page *page; 197 struct page *page;
202#ifdef CONFIG_HIGHMEM 198#ifdef CONFIG_HIGHMEM
203 unsigned long flags; 199 unsigned long flags;
@@ -205,14 +201,14 @@ static void ide_pio_sector(ide_drive_t *drive, struct request *rq,
205 unsigned int offset; 201 unsigned int offset;
206 u8 *buf; 202 u8 *buf;
207 203
208 cursg = hwif->cursg; 204 cursg = cmd->cursg;
209 if (!cursg) { 205 if (!cursg) {
210 cursg = sg; 206 cursg = sg;
211 hwif->cursg = sg; 207 cmd->cursg = sg;
212 } 208 }
213 209
214 page = sg_page(cursg); 210 page = sg_page(cursg);
215 offset = cursg->offset + hwif->cursg_ofs * SECTOR_SIZE; 211 offset = cursg->offset + cmd->cursg_ofs;
216 212
217 /* get the current page and offset */ 213 /* get the current page and offset */
218 page = nth_page(page, (offset >> PAGE_SHIFT)); 214 page = nth_page(page, (offset >> PAGE_SHIFT));
@@ -223,19 +219,19 @@ static void ide_pio_sector(ide_drive_t *drive, struct request *rq,
223#endif 219#endif
224 buf = kmap_atomic(page, KM_BIO_SRC_IRQ) + offset; 220 buf = kmap_atomic(page, KM_BIO_SRC_IRQ) + offset;
225 221
226 hwif->nleft--; 222 cmd->nleft -= nr_bytes;
227 hwif->cursg_ofs++; 223 cmd->cursg_ofs += nr_bytes;
228 224
229 if ((hwif->cursg_ofs * SECTOR_SIZE) == cursg->length) { 225 if (cmd->cursg_ofs == cursg->length) {
230 hwif->cursg = sg_next(hwif->cursg); 226 cmd->cursg = sg_next(cmd->cursg);
231 hwif->cursg_ofs = 0; 227 cmd->cursg_ofs = 0;
232 } 228 }
233 229
234 /* do the actual data transfer */ 230 /* do the actual data transfer */
235 if (write) 231 if (write)
236 hwif->tp_ops->output_data(drive, rq, buf, SECTOR_SIZE); 232 hwif->tp_ops->output_data(drive, cmd, buf, nr_bytes);
237 else 233 else
238 hwif->tp_ops->input_data(drive, rq, buf, SECTOR_SIZE); 234 hwif->tp_ops->input_data(drive, cmd, buf, nr_bytes);
239 235
240 kunmap_atomic(buf, KM_BIO_SRC_IRQ); 236 kunmap_atomic(buf, KM_BIO_SRC_IRQ);
241#ifdef CONFIG_HIGHMEM 237#ifdef CONFIG_HIGHMEM
@@ -243,188 +239,137 @@ static void ide_pio_sector(ide_drive_t *drive, struct request *rq,
243#endif 239#endif
244} 240}
245 241
246static void ide_pio_multi(ide_drive_t *drive, struct request *rq, 242static void ide_pio_multi(ide_drive_t *drive, struct ide_cmd *cmd,
247 unsigned int write) 243 unsigned int write)
248{ 244{
249 unsigned int nsect; 245 unsigned int nsect;
250 246
251 nsect = min_t(unsigned int, drive->hwif->nleft, drive->mult_count); 247 nsect = min_t(unsigned int, cmd->nleft >> 9, drive->mult_count);
252 while (nsect--) 248 while (nsect--)
253 ide_pio_sector(drive, rq, write); 249 ide_pio_bytes(drive, cmd, write, SECTOR_SIZE);
254} 250}
255 251
256static void ide_pio_datablock(ide_drive_t *drive, struct request *rq, 252static void ide_pio_datablock(ide_drive_t *drive, struct ide_cmd *cmd,
257 unsigned int write) 253 unsigned int write)
258{ 254{
259 u8 saved_io_32bit = drive->io_32bit; 255 u8 saved_io_32bit = drive->io_32bit;
260 256
261 if (rq->bio) /* fs request */ 257 if (cmd->tf_flags & IDE_TFLAG_FS)
262 rq->errors = 0; 258 cmd->rq->errors = 0;
263 259
264 if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE) { 260 if (cmd->tf_flags & IDE_TFLAG_IO_16BIT)
265 ide_task_t *task = rq->special; 261 drive->io_32bit = 0;
266
267 if (task->tf_flags & IDE_TFLAG_IO_16BIT)
268 drive->io_32bit = 0;
269 }
270 262
271 touch_softlockup_watchdog(); 263 touch_softlockup_watchdog();
272 264
273 switch (drive->hwif->data_phase) { 265 if (cmd->tf_flags & IDE_TFLAG_MULTI_PIO)
274 case TASKFILE_MULTI_IN: 266 ide_pio_multi(drive, cmd, write);
275 case TASKFILE_MULTI_OUT: 267 else
276 ide_pio_multi(drive, rq, write); 268 ide_pio_bytes(drive, cmd, write, SECTOR_SIZE);
277 break;
278 default:
279 ide_pio_sector(drive, rq, write);
280 break;
281 }
282 269
283 drive->io_32bit = saved_io_32bit; 270 drive->io_32bit = saved_io_32bit;
284} 271}
285 272
286static ide_startstop_t task_error(ide_drive_t *drive, struct request *rq, 273static void ide_error_cmd(ide_drive_t *drive, struct ide_cmd *cmd)
287 const char *s, u8 stat)
288{ 274{
289 if (rq->bio) { 275 if (cmd->tf_flags & IDE_TFLAG_FS) {
290 ide_hwif_t *hwif = drive->hwif; 276 int nr_bytes = cmd->nbytes - cmd->nleft;
291 int sectors = hwif->nsect - hwif->nleft; 277
292 278 if (cmd->protocol == ATA_PROT_PIO &&
293 switch (hwif->data_phase) { 279 ((cmd->tf_flags & IDE_TFLAG_WRITE) || cmd->nleft == 0)) {
294 case TASKFILE_IN: 280 if (cmd->tf_flags & IDE_TFLAG_MULTI_PIO)
295 if (hwif->nleft) 281 nr_bytes -= drive->mult_count << 9;
296 break; 282 else
297 /* fall through */ 283 nr_bytes -= SECTOR_SIZE;
298 case TASKFILE_OUT:
299 sectors--;
300 break;
301 case TASKFILE_MULTI_IN:
302 if (hwif->nleft)
303 break;
304 /* fall through */
305 case TASKFILE_MULTI_OUT:
306 sectors -= drive->mult_count;
307 default:
308 break;
309 } 284 }
310 285
311 if (sectors > 0) { 286 if (nr_bytes > 0)
312 struct ide_driver *drv; 287 ide_complete_rq(drive, 0, nr_bytes);
313
314 drv = *(struct ide_driver **)rq->rq_disk->private_data;
315 drv->end_request(drive, 1, sectors);
316 }
317 } 288 }
318 return ide_error(drive, s, stat);
319}
320
321void task_end_request(ide_drive_t *drive, struct request *rq, u8 stat)
322{
323 if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE) {
324 u8 err = ide_read_error(drive);
325
326 ide_end_drive_cmd(drive, stat, err);
327 return;
328 }
329
330 if (rq->rq_disk) {
331 struct ide_driver *drv;
332
333 drv = *(struct ide_driver **)rq->rq_disk->private_data;;
334 drv->end_request(drive, 1, rq->nr_sectors);
335 } else
336 ide_end_request(drive, 1, rq->nr_sectors);
337} 289}
338 290
339/* 291void ide_finish_cmd(ide_drive_t *drive, struct ide_cmd *cmd, u8 stat)
340 * We got an interrupt on a task_in case, but no errors and no DRQ.
341 *
342 * It might be a spurious irq (shared irq), but it might be a
343 * command that had no output.
344 */
345static ide_startstop_t task_in_unexpected(ide_drive_t *drive, struct request *rq, u8 stat)
346{ 292{
347 /* Command all done? */ 293 struct request *rq = drive->hwif->rq;
348 if (OK_STAT(stat, ATA_DRDY, ATA_BUSY)) { 294 u8 err = ide_read_error(drive);
349 task_end_request(drive, rq, stat);
350 return ide_stopped;
351 }
352 295
353 /* Assume it was a spurious irq */ 296 ide_complete_cmd(drive, cmd, stat, err);
354 ide_set_handler(drive, &task_in_intr, WAIT_WORSTCASE, NULL); 297 rq->errors = err;
355 return ide_started; 298 ide_complete_rq(drive, err ? -EIO : 0, blk_rq_bytes(rq));
356} 299}
357 300
358/* 301/*
359 * Handler for command with PIO data-in phase (Read/Read Multiple). 302 * Handler for command with PIO data phase.
360 */ 303 */
361static ide_startstop_t task_in_intr(ide_drive_t *drive) 304static ide_startstop_t task_pio_intr(ide_drive_t *drive)
362{ 305{
363 ide_hwif_t *hwif = drive->hwif; 306 ide_hwif_t *hwif = drive->hwif;
364 struct request *rq = hwif->rq; 307 struct ide_cmd *cmd = &drive->hwif->cmd;
365 u8 stat = hwif->tp_ops->read_status(hwif); 308 u8 stat = hwif->tp_ops->read_status(hwif);
309 u8 write = !!(cmd->tf_flags & IDE_TFLAG_WRITE);
366 310
367 /* Error? */ 311 if (write == 0) {
368 if (stat & ATA_ERR) 312 /* Error? */
369 return task_error(drive, rq, __func__, stat); 313 if (stat & ATA_ERR)
314 goto out_err;
370 315
371 /* Didn't want any data? Odd. */ 316 /* Didn't want any data? Odd. */
372 if ((stat & ATA_DRQ) == 0) 317 if ((stat & ATA_DRQ) == 0) {
373 return task_in_unexpected(drive, rq, stat); 318 /* Command all done? */
319 if (OK_STAT(stat, ATA_DRDY, ATA_BUSY))
320 goto out_end;
374 321
375 ide_pio_datablock(drive, rq, 0); 322 /* Assume it was a spurious irq */
323 goto out_wait;
324 }
325 } else {
326 if (!OK_STAT(stat, DRIVE_READY, drive->bad_wstat))
327 goto out_err;
376 328
377 /* Are we done? Check status and finish transfer. */ 329 /* Deal with unexpected ATA data phase. */
378 if (!hwif->nleft) { 330 if (((stat & ATA_DRQ) == 0) ^ (cmd->nleft == 0))
379 stat = wait_drive_not_busy(drive); 331 goto out_err;
380 if (!OK_STAT(stat, 0, BAD_STAT))
381 return task_error(drive, rq, __func__, stat);
382 task_end_request(drive, rq, stat);
383 return ide_stopped;
384 } 332 }
385 333
386 /* Still data left to transfer. */ 334 if (write && cmd->nleft == 0)
387 ide_set_handler(drive, &task_in_intr, WAIT_WORSTCASE, NULL); 335 goto out_end;
388 336
389 return ide_started; 337 /* Still data left to transfer. */
390} 338 ide_pio_datablock(drive, cmd, write);
391
392/*
393 * Handler for command with PIO data-out phase (Write/Write Multiple).
394 */
395static ide_startstop_t task_out_intr (ide_drive_t *drive)
396{
397 ide_hwif_t *hwif = drive->hwif;
398 struct request *rq = hwif->rq;
399 u8 stat = hwif->tp_ops->read_status(hwif);
400
401 if (!OK_STAT(stat, DRIVE_READY, drive->bad_wstat))
402 return task_error(drive, rq, __func__, stat);
403 339
404 /* Deal with unexpected ATA data phase. */ 340 /* Are we done? Check status and finish transfer. */
405 if (((stat & ATA_DRQ) == 0) ^ !hwif->nleft) 341 if (write == 0 && cmd->nleft == 0) {
406 return task_error(drive, rq, __func__, stat); 342 stat = wait_drive_not_busy(drive);
343 if (!OK_STAT(stat, 0, BAD_STAT))
344 goto out_err;
407 345
408 if (!hwif->nleft) { 346 goto out_end;
409 task_end_request(drive, rq, stat);
410 return ide_stopped;
411 } 347 }
412 348out_wait:
413 /* Still data left to transfer. */ 349 /* Still data left to transfer. */
414 ide_pio_datablock(drive, rq, 1); 350 ide_set_handler(drive, &task_pio_intr, WAIT_WORSTCASE);
415 ide_set_handler(drive, &task_out_intr, WAIT_WORSTCASE, NULL);
416
417 return ide_started; 351 return ide_started;
352out_end:
353 if ((cmd->tf_flags & IDE_TFLAG_FS) == 0)
354 ide_finish_cmd(drive, cmd, stat);
355 else
356 ide_complete_rq(drive, 0, cmd->rq->nr_sectors << 9);
357 return ide_stopped;
358out_err:
359 ide_error_cmd(drive, cmd);
360 return ide_error(drive, __func__, stat);
418} 361}
419 362
420static ide_startstop_t pre_task_out_intr(ide_drive_t *drive, struct request *rq) 363static ide_startstop_t pre_task_out_intr(ide_drive_t *drive,
364 struct ide_cmd *cmd)
421{ 365{
422 ide_startstop_t startstop; 366 ide_startstop_t startstop;
423 367
424 if (ide_wait_stat(&startstop, drive, ATA_DRQ, 368 if (ide_wait_stat(&startstop, drive, ATA_DRQ,
425 drive->bad_wstat, WAIT_DRQ)) { 369 drive->bad_wstat, WAIT_DRQ)) {
426 printk(KERN_ERR "%s: no DRQ after issuing %sWRITE%s\n", 370 printk(KERN_ERR "%s: no DRQ after issuing %sWRITE%s\n",
427 drive->name, drive->hwif->data_phase ? "MULT" : "", 371 drive->name,
372 (cmd->tf_flags & IDE_TFLAG_MULTI_PIO) ? "MULT" : "",
428 (drive->dev_flags & IDE_DFLAG_LBA48) ? "_EXT" : ""); 373 (drive->dev_flags & IDE_DFLAG_LBA48) ? "_EXT" : "");
429 return startstop; 374 return startstop;
430 } 375 }
@@ -432,13 +377,15 @@ static ide_startstop_t pre_task_out_intr(ide_drive_t *drive, struct request *rq)
432 if ((drive->dev_flags & IDE_DFLAG_UNMASK) == 0) 377 if ((drive->dev_flags & IDE_DFLAG_UNMASK) == 0)
433 local_irq_disable(); 378 local_irq_disable();
434 379
435 ide_set_handler(drive, &task_out_intr, WAIT_WORSTCASE, NULL); 380 ide_set_handler(drive, &task_pio_intr, WAIT_WORSTCASE);
436 ide_pio_datablock(drive, rq, 1); 381
382 ide_pio_datablock(drive, cmd, 1);
437 383
438 return ide_started; 384 return ide_started;
439} 385}
440 386
441int ide_raw_taskfile(ide_drive_t *drive, ide_task_t *task, u8 *buf, u16 nsect) 387int ide_raw_taskfile(ide_drive_t *drive, struct ide_cmd *cmd, u8 *buf,
388 u16 nsect)
442{ 389{
443 struct request *rq; 390 struct request *rq;
444 int error; 391 int error;
@@ -456,11 +403,11 @@ int ide_raw_taskfile(ide_drive_t *drive, ide_task_t *task, u8 *buf, u16 nsect)
456 rq->hard_nr_sectors = rq->nr_sectors = nsect; 403 rq->hard_nr_sectors = rq->nr_sectors = nsect;
457 rq->hard_cur_sectors = rq->current_nr_sectors = nsect; 404 rq->hard_cur_sectors = rq->current_nr_sectors = nsect;
458 405
459 if (task->tf_flags & IDE_TFLAG_WRITE) 406 if (cmd->tf_flags & IDE_TFLAG_WRITE)
460 rq->cmd_flags |= REQ_RW; 407 rq->cmd_flags |= REQ_RW;
461 408
462 rq->special = task; 409 rq->special = cmd;
463 task->rq = rq; 410 cmd->rq = rq;
464 411
465 error = blk_execute_rq(drive->queue, NULL, rq, 0); 412 error = blk_execute_rq(drive->queue, NULL, rq, 0);
466 blk_put_request(rq); 413 blk_put_request(rq);
@@ -470,19 +417,19 @@ int ide_raw_taskfile(ide_drive_t *drive, ide_task_t *task, u8 *buf, u16 nsect)
470 417
471EXPORT_SYMBOL(ide_raw_taskfile); 418EXPORT_SYMBOL(ide_raw_taskfile);
472 419
473int ide_no_data_taskfile(ide_drive_t *drive, ide_task_t *task) 420int ide_no_data_taskfile(ide_drive_t *drive, struct ide_cmd *cmd)
474{ 421{
475 task->data_phase = TASKFILE_NO_DATA; 422 cmd->protocol = ATA_PROT_NODATA;
476 423
477 return ide_raw_taskfile(drive, task, NULL, 0); 424 return ide_raw_taskfile(drive, cmd, NULL, 0);
478} 425}
479EXPORT_SYMBOL_GPL(ide_no_data_taskfile); 426EXPORT_SYMBOL_GPL(ide_no_data_taskfile);
480 427
481#ifdef CONFIG_IDE_TASK_IOCTL 428#ifdef CONFIG_IDE_TASK_IOCTL
482int ide_taskfile_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg) 429int ide_taskfile_ioctl(ide_drive_t *drive, unsigned long arg)
483{ 430{
484 ide_task_request_t *req_task; 431 ide_task_request_t *req_task;
485 ide_task_t args; 432 struct ide_cmd cmd;
486 u8 *outbuf = NULL; 433 u8 *outbuf = NULL;
487 u8 *inbuf = NULL; 434 u8 *inbuf = NULL;
488 u8 *data_buf = NULL; 435 u8 *data_buf = NULL;
@@ -536,53 +483,63 @@ int ide_taskfile_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
536 } 483 }
537 } 484 }
538 485
539 memset(&args, 0, sizeof(ide_task_t)); 486 memset(&cmd, 0, sizeof(cmd));
540 487
541 memcpy(&args.tf_array[0], req_task->hob_ports, HDIO_DRIVE_HOB_HDR_SIZE - 2); 488 memcpy(&cmd.tf_array[0], req_task->hob_ports,
542 memcpy(&args.tf_array[6], req_task->io_ports, HDIO_DRIVE_TASK_HDR_SIZE); 489 HDIO_DRIVE_HOB_HDR_SIZE - 2);
490 memcpy(&cmd.tf_array[6], req_task->io_ports,
491 HDIO_DRIVE_TASK_HDR_SIZE);
543 492
544 args.data_phase = req_task->data_phase; 493 cmd.tf_flags = IDE_TFLAG_IO_16BIT | IDE_TFLAG_DEVICE |
494 IDE_TFLAG_IN_TF;
545 495
546 args.tf_flags = IDE_TFLAG_IO_16BIT | IDE_TFLAG_DEVICE |
547 IDE_TFLAG_IN_TF;
548 if (drive->dev_flags & IDE_DFLAG_LBA48) 496 if (drive->dev_flags & IDE_DFLAG_LBA48)
549 args.tf_flags |= (IDE_TFLAG_LBA48 | IDE_TFLAG_IN_HOB); 497 cmd.tf_flags |= (IDE_TFLAG_LBA48 | IDE_TFLAG_IN_HOB);
550 498
551 if (req_task->out_flags.all) { 499 if (req_task->out_flags.all) {
552 args.tf_flags |= IDE_TFLAG_FLAGGED; 500 cmd.ftf_flags |= IDE_FTFLAG_FLAGGED;
553 501
554 if (req_task->out_flags.b.data) 502 if (req_task->out_flags.b.data)
555 args.tf_flags |= IDE_TFLAG_OUT_DATA; 503 cmd.ftf_flags |= IDE_FTFLAG_OUT_DATA;
556 504
557 if (req_task->out_flags.b.nsector_hob) 505 if (req_task->out_flags.b.nsector_hob)
558 args.tf_flags |= IDE_TFLAG_OUT_HOB_NSECT; 506 cmd.tf_flags |= IDE_TFLAG_OUT_HOB_NSECT;
559 if (req_task->out_flags.b.sector_hob) 507 if (req_task->out_flags.b.sector_hob)
560 args.tf_flags |= IDE_TFLAG_OUT_HOB_LBAL; 508 cmd.tf_flags |= IDE_TFLAG_OUT_HOB_LBAL;
561 if (req_task->out_flags.b.lcyl_hob) 509 if (req_task->out_flags.b.lcyl_hob)
562 args.tf_flags |= IDE_TFLAG_OUT_HOB_LBAM; 510 cmd.tf_flags |= IDE_TFLAG_OUT_HOB_LBAM;
563 if (req_task->out_flags.b.hcyl_hob) 511 if (req_task->out_flags.b.hcyl_hob)
564 args.tf_flags |= IDE_TFLAG_OUT_HOB_LBAH; 512 cmd.tf_flags |= IDE_TFLAG_OUT_HOB_LBAH;
565 513
566 if (req_task->out_flags.b.error_feature) 514 if (req_task->out_flags.b.error_feature)
567 args.tf_flags |= IDE_TFLAG_OUT_FEATURE; 515 cmd.tf_flags |= IDE_TFLAG_OUT_FEATURE;
568 if (req_task->out_flags.b.nsector) 516 if (req_task->out_flags.b.nsector)
569 args.tf_flags |= IDE_TFLAG_OUT_NSECT; 517 cmd.tf_flags |= IDE_TFLAG_OUT_NSECT;
570 if (req_task->out_flags.b.sector) 518 if (req_task->out_flags.b.sector)
571 args.tf_flags |= IDE_TFLAG_OUT_LBAL; 519 cmd.tf_flags |= IDE_TFLAG_OUT_LBAL;
572 if (req_task->out_flags.b.lcyl) 520 if (req_task->out_flags.b.lcyl)
573 args.tf_flags |= IDE_TFLAG_OUT_LBAM; 521 cmd.tf_flags |= IDE_TFLAG_OUT_LBAM;
574 if (req_task->out_flags.b.hcyl) 522 if (req_task->out_flags.b.hcyl)
575 args.tf_flags |= IDE_TFLAG_OUT_LBAH; 523 cmd.tf_flags |= IDE_TFLAG_OUT_LBAH;
576 } else { 524 } else {
577 args.tf_flags |= IDE_TFLAG_OUT_TF; 525 cmd.tf_flags |= IDE_TFLAG_OUT_TF;
578 if (args.tf_flags & IDE_TFLAG_LBA48) 526 if (cmd.tf_flags & IDE_TFLAG_LBA48)
579 args.tf_flags |= IDE_TFLAG_OUT_HOB; 527 cmd.tf_flags |= IDE_TFLAG_OUT_HOB;
580 } 528 }
581 529
582 if (req_task->in_flags.b.data) 530 if (req_task->in_flags.b.data)
583 args.tf_flags |= IDE_TFLAG_IN_DATA; 531 cmd.ftf_flags |= IDE_FTFLAG_IN_DATA;
584 532
585 switch(req_task->data_phase) { 533 if (req_task->req_cmd == IDE_DRIVE_TASK_RAW_WRITE) {
534 /* fixup data phase if needed */
535 if (req_task->data_phase == TASKFILE_IN_DMAQ ||
536 req_task->data_phase == TASKFILE_IN_DMA)
537 cmd.tf_flags |= IDE_TFLAG_WRITE;
538 }
539
540 cmd.protocol = ATA_PROT_DMA;
541
542 switch (req_task->data_phase) {
586 case TASKFILE_MULTI_OUT: 543 case TASKFILE_MULTI_OUT:
587 if (!drive->mult_count) { 544 if (!drive->mult_count) {
588 /* (hs): give up if multcount is not set */ 545 /* (hs): give up if multcount is not set */
@@ -592,11 +549,14 @@ int ide_taskfile_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
592 err = -EPERM; 549 err = -EPERM;
593 goto abort; 550 goto abort;
594 } 551 }
552 cmd.tf_flags |= IDE_TFLAG_MULTI_PIO;
595 /* fall through */ 553 /* fall through */
596 case TASKFILE_OUT: 554 case TASKFILE_OUT:
555 cmd.protocol = ATA_PROT_PIO;
597 /* fall through */ 556 /* fall through */
598 case TASKFILE_OUT_DMAQ: 557 case TASKFILE_OUT_DMAQ:
599 case TASKFILE_OUT_DMA: 558 case TASKFILE_OUT_DMA:
559 cmd.tf_flags |= IDE_TFLAG_WRITE;
600 nsect = taskout / SECTOR_SIZE; 560 nsect = taskout / SECTOR_SIZE;
601 data_buf = outbuf; 561 data_buf = outbuf;
602 break; 562 break;
@@ -609,8 +569,10 @@ int ide_taskfile_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
609 err = -EPERM; 569 err = -EPERM;
610 goto abort; 570 goto abort;
611 } 571 }
572 cmd.tf_flags |= IDE_TFLAG_MULTI_PIO;
612 /* fall through */ 573 /* fall through */
613 case TASKFILE_IN: 574 case TASKFILE_IN:
575 cmd.protocol = ATA_PROT_PIO;
614 /* fall through */ 576 /* fall through */
615 case TASKFILE_IN_DMAQ: 577 case TASKFILE_IN_DMAQ:
616 case TASKFILE_IN_DMA: 578 case TASKFILE_IN_DMA:
@@ -618,6 +580,7 @@ int ide_taskfile_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
618 data_buf = inbuf; 580 data_buf = inbuf;
619 break; 581 break;
620 case TASKFILE_NO_DATA: 582 case TASKFILE_NO_DATA:
583 cmd.protocol = ATA_PROT_NODATA;
621 break; 584 break;
622 default: 585 default:
623 err = -EFAULT; 586 err = -EFAULT;
@@ -627,7 +590,7 @@ int ide_taskfile_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
627 if (req_task->req_cmd == IDE_DRIVE_TASK_NO_DATA) 590 if (req_task->req_cmd == IDE_DRIVE_TASK_NO_DATA)
628 nsect = 0; 591 nsect = 0;
629 else if (!nsect) { 592 else if (!nsect) {
630 nsect = (args.tf.hob_nsect << 8) | args.tf.nsect; 593 nsect = (cmd.tf.hob_nsect << 8) | cmd.tf.nsect;
631 594
632 if (!nsect) { 595 if (!nsect) {
633 printk(KERN_ERR "%s: in/out command without data\n", 596 printk(KERN_ERR "%s: in/out command without data\n",
@@ -637,15 +600,14 @@ int ide_taskfile_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
637 } 600 }
638 } 601 }
639 602
640 if (req_task->req_cmd == IDE_DRIVE_TASK_RAW_WRITE) 603 err = ide_raw_taskfile(drive, &cmd, data_buf, nsect);
641 args.tf_flags |= IDE_TFLAG_WRITE;
642
643 err = ide_raw_taskfile(drive, &args, data_buf, nsect);
644 604
645 memcpy(req_task->hob_ports, &args.tf_array[0], HDIO_DRIVE_HOB_HDR_SIZE - 2); 605 memcpy(req_task->hob_ports, &cmd.tf_array[0],
646 memcpy(req_task->io_ports, &args.tf_array[6], HDIO_DRIVE_TASK_HDR_SIZE); 606 HDIO_DRIVE_HOB_HDR_SIZE - 2);
607 memcpy(req_task->io_ports, &cmd.tf_array[6],
608 HDIO_DRIVE_TASK_HDR_SIZE);
647 609
648 if ((args.tf_flags & IDE_TFLAG_FLAGGED_SET_IN_FLAGS) && 610 if ((cmd.ftf_flags & IDE_FTFLAG_SET_IN_FLAGS) &&
649 req_task->in_flags.all == 0) { 611 req_task->in_flags.all == 0) {
650 req_task->in_flags.all = IDE_TASKFILE_STD_IN_FLAGS; 612 req_task->in_flags.all = IDE_TASKFILE_STD_IN_FLAGS;
651 if (drive->dev_flags & IDE_DFLAG_LBA48) 613 if (drive->dev_flags & IDE_DFLAG_LBA48)
diff --git a/drivers/ide/ide_arm.c b/drivers/ide/ide_arm.c
index bdcac94d7c1f..cf6385446ece 100644
--- a/drivers/ide/ide_arm.c
+++ b/drivers/ide/ide_arm.c
@@ -18,6 +18,10 @@
18#define IDE_ARM_IO 0x1f0 18#define IDE_ARM_IO 0x1f0
19#define IDE_ARM_IRQ IRQ_HARDDISK 19#define IDE_ARM_IRQ IRQ_HARDDISK
20 20
21static const struct ide_port_info ide_arm_port_info = {
22 .host_flags = IDE_HFLAG_NO_DMA,
23};
24
21static int __init ide_arm_init(void) 25static int __init ide_arm_init(void)
22{ 26{
23 unsigned long base = IDE_ARM_IO, ctl = IDE_ARM_IO + 0x206; 27 unsigned long base = IDE_ARM_IO, ctl = IDE_ARM_IO + 0x206;
@@ -41,7 +45,7 @@ static int __init ide_arm_init(void)
41 hw.irq = IDE_ARM_IRQ; 45 hw.irq = IDE_ARM_IRQ;
42 hw.chipset = ide_generic; 46 hw.chipset = ide_generic;
43 47
44 return ide_host_add(NULL, hws, NULL); 48 return ide_host_add(&ide_arm_port_info, hws, NULL);
45} 49}
46 50
47module_init(ide_arm_init); 51module_init(ide_arm_init);
diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
index 6b9fc950b4af..0d4ac65cf949 100644
--- a/drivers/ide/it821x.c
+++ b/drivers/ide/it821x.c
@@ -508,10 +508,10 @@ static void it821x_quirkproc(ide_drive_t *drive)
508static struct ide_dma_ops it821x_pass_through_dma_ops = { 508static struct ide_dma_ops it821x_pass_through_dma_ops = {
509 .dma_host_set = ide_dma_host_set, 509 .dma_host_set = ide_dma_host_set,
510 .dma_setup = ide_dma_setup, 510 .dma_setup = ide_dma_setup,
511 .dma_exec_cmd = ide_dma_exec_cmd,
512 .dma_start = it821x_dma_start, 511 .dma_start = it821x_dma_start,
513 .dma_end = it821x_dma_end, 512 .dma_end = it821x_dma_end,
514 .dma_test_irq = ide_dma_test_irq, 513 .dma_test_irq = ide_dma_test_irq,
514 .dma_timer_expiry = ide_dma_sff_timer_expiry,
515 .dma_timeout = ide_dma_timeout, 515 .dma_timeout = ide_dma_timeout,
516 .dma_lost_irq = ide_dma_lost_irq, 516 .dma_lost_irq = ide_dma_lost_irq,
517 .dma_sff_read_status = ide_dma_sff_read_status, 517 .dma_sff_read_status = ide_dma_sff_read_status,
diff --git a/drivers/ide/macide.c b/drivers/ide/macide.c
index 3c60064f1d4f..4b1718e83283 100644
--- a/drivers/ide/macide.c
+++ b/drivers/ide/macide.c
@@ -80,6 +80,11 @@ static void __init macide_setup_ports(hw_regs_t *hw, unsigned long base,
80 hw->chipset = ide_generic; 80 hw->chipset = ide_generic;
81} 81}
82 82
83static const struct ide_port_info macide_port_info = {
84 .host_flags = IDE_HFLAG_MMIO | IDE_HFLAG_NO_DMA,
85 .irq_flags = IRQF_SHARED,
86};
87
83static const char *mac_ide_name[] = 88static const char *mac_ide_name[] =
84 { "Quadra", "Powerbook", "Powerbook Baboon" }; 89 { "Quadra", "Powerbook", "Powerbook Baboon" };
85 90
@@ -122,7 +127,7 @@ static int __init macide_init(void)
122 127
123 macide_setup_ports(&hw, base, irq, ack_intr); 128 macide_setup_ports(&hw, base, irq, ack_intr);
124 129
125 return ide_host_add(NULL, hws, NULL); 130 return ide_host_add(&macide_port_info, hws, NULL);
126} 131}
127 132
128module_init(macide_init); 133module_init(macide_init);
diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
index ea48a3ee8063..7b65fe5bf449 100644
--- a/drivers/ide/ns87415.c
+++ b/drivers/ide/ns87415.c
@@ -61,12 +61,12 @@ static u8 superio_dma_sff_read_status(ide_hwif_t *hwif)
61 return superio_ide_inb(hwif->dma_base + ATA_DMA_STATUS); 61 return superio_ide_inb(hwif->dma_base + ATA_DMA_STATUS);
62} 62}
63 63
64static void superio_tf_read(ide_drive_t *drive, ide_task_t *task) 64static void superio_tf_read(ide_drive_t *drive, struct ide_cmd *cmd)
65{ 65{
66 struct ide_io_ports *io_ports = &drive->hwif->io_ports; 66 struct ide_io_ports *io_ports = &drive->hwif->io_ports;
67 struct ide_taskfile *tf = &task->tf; 67 struct ide_taskfile *tf = &cmd->tf;
68 68
69 if (task->tf_flags & IDE_TFLAG_IN_DATA) { 69 if (cmd->ftf_flags & IDE_FTFLAG_IN_DATA) {
70 u16 data = inw(io_ports->data_addr); 70 u16 data = inw(io_ports->data_addr);
71 71
72 tf->data = data & 0xff; 72 tf->data = data & 0xff;
@@ -76,31 +76,31 @@ static void superio_tf_read(ide_drive_t *drive, ide_task_t *task)
76 /* be sure we're looking at the low order bits */ 76 /* be sure we're looking at the low order bits */
77 outb(ATA_DEVCTL_OBS & ~0x80, io_ports->ctl_addr); 77 outb(ATA_DEVCTL_OBS & ~0x80, io_ports->ctl_addr);
78 78
79 if (task->tf_flags & IDE_TFLAG_IN_FEATURE) 79 if (cmd->tf_flags & IDE_TFLAG_IN_FEATURE)
80 tf->feature = inb(io_ports->feature_addr); 80 tf->feature = inb(io_ports->feature_addr);
81 if (task->tf_flags & IDE_TFLAG_IN_NSECT) 81 if (cmd->tf_flags & IDE_TFLAG_IN_NSECT)
82 tf->nsect = inb(io_ports->nsect_addr); 82 tf->nsect = inb(io_ports->nsect_addr);
83 if (task->tf_flags & IDE_TFLAG_IN_LBAL) 83 if (cmd->tf_flags & IDE_TFLAG_IN_LBAL)
84 tf->lbal = inb(io_ports->lbal_addr); 84 tf->lbal = inb(io_ports->lbal_addr);
85 if (task->tf_flags & IDE_TFLAG_IN_LBAM) 85 if (cmd->tf_flags & IDE_TFLAG_IN_LBAM)
86 tf->lbam = inb(io_ports->lbam_addr); 86 tf->lbam = inb(io_ports->lbam_addr);
87 if (task->tf_flags & IDE_TFLAG_IN_LBAH) 87 if (cmd->tf_flags & IDE_TFLAG_IN_LBAH)
88 tf->lbah = inb(io_ports->lbah_addr); 88 tf->lbah = inb(io_ports->lbah_addr);
89 if (task->tf_flags & IDE_TFLAG_IN_DEVICE) 89 if (cmd->tf_flags & IDE_TFLAG_IN_DEVICE)
90 tf->device = superio_ide_inb(io_ports->device_addr); 90 tf->device = superio_ide_inb(io_ports->device_addr);
91 91
92 if (task->tf_flags & IDE_TFLAG_LBA48) { 92 if (cmd->tf_flags & IDE_TFLAG_LBA48) {
93 outb(ATA_DEVCTL_OBS | 0x80, io_ports->ctl_addr); 93 outb(ATA_DEVCTL_OBS | 0x80, io_ports->ctl_addr);
94 94
95 if (task->tf_flags & IDE_TFLAG_IN_HOB_FEATURE) 95 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_FEATURE)
96 tf->hob_feature = inb(io_ports->feature_addr); 96 tf->hob_feature = inb(io_ports->feature_addr);
97 if (task->tf_flags & IDE_TFLAG_IN_HOB_NSECT) 97 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_NSECT)
98 tf->hob_nsect = inb(io_ports->nsect_addr); 98 tf->hob_nsect = inb(io_ports->nsect_addr);
99 if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAL) 99 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAL)
100 tf->hob_lbal = inb(io_ports->lbal_addr); 100 tf->hob_lbal = inb(io_ports->lbal_addr);
101 if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAM) 101 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAM)
102 tf->hob_lbam = inb(io_ports->lbam_addr); 102 tf->hob_lbam = inb(io_ports->lbam_addr);
103 if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAH) 103 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAH)
104 tf->hob_lbah = inb(io_ports->lbah_addr); 104 tf->hob_lbah = inb(io_ports->lbah_addr);
105 } 105 }
106} 106}
@@ -216,11 +216,11 @@ static int ns87415_dma_end(ide_drive_t *drive)
216 return (dma_stat & 7) != 4; 216 return (dma_stat & 7) != 4;
217} 217}
218 218
219static int ns87415_dma_setup(ide_drive_t *drive) 219static int ns87415_dma_setup(ide_drive_t *drive, struct ide_cmd *cmd)
220{ 220{
221 /* select DMA xfer */ 221 /* select DMA xfer */
222 ns87415_prepare_drive(drive, 1); 222 ns87415_prepare_drive(drive, 1);
223 if (!ide_dma_setup(drive)) 223 if (ide_dma_setup(drive, cmd) == 0)
224 return 0; 224 return 0;
225 /* DMA failed: select PIO xfer */ 225 /* DMA failed: select PIO xfer */
226 ns87415_prepare_drive(drive, 0); 226 ns87415_prepare_drive(drive, 0);
@@ -301,11 +301,11 @@ static const struct ide_port_ops ns87415_port_ops = {
301static const struct ide_dma_ops ns87415_dma_ops = { 301static const struct ide_dma_ops ns87415_dma_ops = {
302 .dma_host_set = ide_dma_host_set, 302 .dma_host_set = ide_dma_host_set,
303 .dma_setup = ns87415_dma_setup, 303 .dma_setup = ns87415_dma_setup,
304 .dma_exec_cmd = ide_dma_exec_cmd,
305 .dma_start = ide_dma_start, 304 .dma_start = ide_dma_start,
306 .dma_end = ns87415_dma_end, 305 .dma_end = ns87415_dma_end,
307 .dma_test_irq = ide_dma_test_irq, 306 .dma_test_irq = ide_dma_test_irq,
308 .dma_lost_irq = ide_dma_lost_irq, 307 .dma_lost_irq = ide_dma_lost_irq,
308 .dma_timer_expiry = ide_dma_sff_timer_expiry,
309 .dma_timeout = ide_dma_timeout, 309 .dma_timeout = ide_dma_timeout,
310 .dma_sff_read_status = superio_dma_sff_read_status, 310 .dma_sff_read_status = superio_dma_sff_read_status,
311}; 311};
diff --git a/drivers/ide/palm_bk3710.c b/drivers/ide/palm_bk3710.c
index f38aac78044c..c7acca0b8733 100644
--- a/drivers/ide/palm_bk3710.c
+++ b/drivers/ide/palm_bk3710.c
@@ -347,7 +347,7 @@ static int __init palm_bk3710_probe(struct platform_device *pdev)
347 struct clk *clk; 347 struct clk *clk;
348 struct resource *mem, *irq; 348 struct resource *mem, *irq;
349 void __iomem *base; 349 void __iomem *base;
350 unsigned long rate; 350 unsigned long rate, mem_size;
351 int i, rc; 351 int i, rc;
352 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL }; 352 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL };
353 353
@@ -374,13 +374,18 @@ static int __init palm_bk3710_probe(struct platform_device *pdev)
374 return -ENODEV; 374 return -ENODEV;
375 } 375 }
376 376
377 if (request_mem_region(mem->start, mem->end - mem->start + 1, 377 mem_size = mem->end - mem->start + 1;
378 "palm_bk3710") == NULL) { 378 if (request_mem_region(mem->start, mem_size, "palm_bk3710") == NULL) {
379 printk(KERN_ERR "failed to request memory region\n"); 379 printk(KERN_ERR "failed to request memory region\n");
380 return -EBUSY; 380 return -EBUSY;
381 } 381 }
382 382
383 base = IO_ADDRESS(mem->start); 383 base = ioremap(mem->start, mem_size);
384 if (!base) {
385 printk(KERN_ERR "failed to map IO memory\n");
386 release_mem_region(mem->start, mem_size);
387 return -ENOMEM;
388 }
384 389
385 /* Configure the Palm Chip controller */ 390 /* Configure the Palm Chip controller */
386 palm_bk3710_chipinit(base); 391 palm_bk3710_chipinit(base);
diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
index cba66ebce4e3..f7536d1943f7 100644
--- a/drivers/ide/pdc202xx_old.c
+++ b/drivers/ide/pdc202xx_old.c
@@ -331,11 +331,11 @@ static const struct ide_port_ops pdc2026x_port_ops = {
331static const struct ide_dma_ops pdc20246_dma_ops = { 331static const struct ide_dma_ops pdc20246_dma_ops = {
332 .dma_host_set = ide_dma_host_set, 332 .dma_host_set = ide_dma_host_set,
333 .dma_setup = ide_dma_setup, 333 .dma_setup = ide_dma_setup,
334 .dma_exec_cmd = ide_dma_exec_cmd,
335 .dma_start = ide_dma_start, 334 .dma_start = ide_dma_start,
336 .dma_end = ide_dma_end, 335 .dma_end = ide_dma_end,
337 .dma_test_irq = pdc202xx_dma_test_irq, 336 .dma_test_irq = pdc202xx_dma_test_irq,
338 .dma_lost_irq = pdc202xx_dma_lost_irq, 337 .dma_lost_irq = pdc202xx_dma_lost_irq,
338 .dma_timer_expiry = ide_dma_sff_timer_expiry,
339 .dma_timeout = pdc202xx_dma_timeout, 339 .dma_timeout = pdc202xx_dma_timeout,
340 .dma_sff_read_status = ide_dma_sff_read_status, 340 .dma_sff_read_status = ide_dma_sff_read_status,
341}; 341};
@@ -343,11 +343,11 @@ static const struct ide_dma_ops pdc20246_dma_ops = {
343static const struct ide_dma_ops pdc2026x_dma_ops = { 343static const struct ide_dma_ops pdc2026x_dma_ops = {
344 .dma_host_set = ide_dma_host_set, 344 .dma_host_set = ide_dma_host_set,
345 .dma_setup = ide_dma_setup, 345 .dma_setup = ide_dma_setup,
346 .dma_exec_cmd = ide_dma_exec_cmd,
347 .dma_start = pdc202xx_dma_start, 346 .dma_start = pdc202xx_dma_start,
348 .dma_end = pdc202xx_dma_end, 347 .dma_end = pdc202xx_dma_end,
349 .dma_test_irq = pdc202xx_dma_test_irq, 348 .dma_test_irq = pdc202xx_dma_test_irq,
350 .dma_lost_irq = pdc202xx_dma_lost_irq, 349 .dma_lost_irq = pdc202xx_dma_lost_irq,
350 .dma_timer_expiry = ide_dma_sff_timer_expiry,
351 .dma_timeout = pdc202xx_dma_timeout, 351 .dma_timeout = pdc202xx_dma_timeout,
352 .dma_sff_read_status = ide_dma_sff_read_status, 352 .dma_sff_read_status = ide_dma_sff_read_status,
353}; 353};
diff --git a/drivers/ide/pmac.c b/drivers/ide/pmac.c
index 74625e821a43..2bfcfedaa076 100644
--- a/drivers/ide/pmac.c
+++ b/drivers/ide/pmac.c
@@ -404,7 +404,6 @@ kauai_lookup_timing(struct kauai_timing* table, int cycle_time)
404#define IDE_WAKEUP_DELAY (1*HZ) 404#define IDE_WAKEUP_DELAY (1*HZ)
405 405
406static int pmac_ide_init_dma(ide_hwif_t *, const struct ide_port_info *); 406static int pmac_ide_init_dma(ide_hwif_t *, const struct ide_port_info *);
407static int pmac_ide_build_dmatable(ide_drive_t *drive, struct request *rq);
408static void pmac_ide_selectproc(ide_drive_t *drive); 407static void pmac_ide_selectproc(ide_drive_t *drive);
409static void pmac_ide_kauai_selectproc(ide_drive_t *drive); 408static void pmac_ide_kauai_selectproc(ide_drive_t *drive);
410 409
@@ -1422,17 +1421,16 @@ out:
1422 * pmac_ide_build_dmatable builds the DBDMA command list 1421 * pmac_ide_build_dmatable builds the DBDMA command list
1423 * for a transfer and sets the DBDMA channel to point to it. 1422 * for a transfer and sets the DBDMA channel to point to it.
1424 */ 1423 */
1425static int 1424static int pmac_ide_build_dmatable(ide_drive_t *drive, struct ide_cmd *cmd)
1426pmac_ide_build_dmatable(ide_drive_t *drive, struct request *rq)
1427{ 1425{
1428 ide_hwif_t *hwif = drive->hwif; 1426 ide_hwif_t *hwif = drive->hwif;
1429 pmac_ide_hwif_t *pmif = 1427 pmac_ide_hwif_t *pmif =
1430 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent); 1428 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
1431 struct dbdma_cmd *table; 1429 struct dbdma_cmd *table;
1432 int i, count = 0;
1433 volatile struct dbdma_regs __iomem *dma = pmif->dma_regs; 1430 volatile struct dbdma_regs __iomem *dma = pmif->dma_regs;
1434 struct scatterlist *sg; 1431 struct scatterlist *sg;
1435 int wr = (rq_data_dir(rq) == WRITE); 1432 int wr = !!(cmd->tf_flags & IDE_TFLAG_WRITE);
1433 int i = cmd->sg_nents, count = 0;
1436 1434
1437 /* DMA table is already aligned */ 1435 /* DMA table is already aligned */
1438 table = (struct dbdma_cmd *) pmif->dma_table_cpu; 1436 table = (struct dbdma_cmd *) pmif->dma_table_cpu;
@@ -1442,11 +1440,6 @@ pmac_ide_build_dmatable(ide_drive_t *drive, struct request *rq)
1442 while (readl(&dma->status) & RUN) 1440 while (readl(&dma->status) & RUN)
1443 udelay(1); 1441 udelay(1);
1444 1442
1445 hwif->sg_nents = i = ide_build_sglist(drive, rq);
1446
1447 if (!i)
1448 return 0;
1449
1450 /* Build DBDMA commands list */ 1443 /* Build DBDMA commands list */
1451 sg = hwif->sg_table; 1444 sg = hwif->sg_table;
1452 while (i && sg_dma_len(sg)) { 1445 while (i && sg_dma_len(sg)) {
@@ -1509,23 +1502,22 @@ use_pio_instead:
1509 * Prepare a DMA transfer. We build the DMA table, adjust the timings for 1502 * Prepare a DMA transfer. We build the DMA table, adjust the timings for
1510 * a read on KeyLargo ATA/66 and mark us as waiting for DMA completion 1503 * a read on KeyLargo ATA/66 and mark us as waiting for DMA completion
1511 */ 1504 */
1512static int 1505static int pmac_ide_dma_setup(ide_drive_t *drive, struct ide_cmd *cmd)
1513pmac_ide_dma_setup(ide_drive_t *drive)
1514{ 1506{
1515 ide_hwif_t *hwif = drive->hwif; 1507 ide_hwif_t *hwif = drive->hwif;
1516 pmac_ide_hwif_t *pmif = 1508 pmac_ide_hwif_t *pmif =
1517 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent); 1509 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
1518 struct request *rq = hwif->rq;
1519 u8 unit = drive->dn & 1, ata4 = (pmif->kind == controller_kl_ata4); 1510 u8 unit = drive->dn & 1, ata4 = (pmif->kind == controller_kl_ata4);
1511 u8 write = !!(cmd->tf_flags & IDE_TFLAG_WRITE);
1520 1512
1521 if (!pmac_ide_build_dmatable(drive, rq)) { 1513 if (pmac_ide_build_dmatable(drive, cmd) == 0) {
1522 ide_map_sg(drive, rq); 1514 ide_map_sg(drive, cmd);
1523 return 1; 1515 return 1;
1524 } 1516 }
1525 1517
1526 /* Apple adds 60ns to wrDataSetup on reads */ 1518 /* Apple adds 60ns to wrDataSetup on reads */
1527 if (ata4 && (pmif->timings[unit] & TR_66_UDMA_EN)) { 1519 if (ata4 && (pmif->timings[unit] & TR_66_UDMA_EN)) {
1528 writel(pmif->timings[unit] + (!rq_data_dir(rq) ? 0x00800000UL : 0), 1520 writel(pmif->timings[unit] + (write ? 0 : 0x00800000UL),
1529 PMAC_IDE_REG(IDE_TIMING_CONFIG)); 1521 PMAC_IDE_REG(IDE_TIMING_CONFIG));
1530 (void)readl(PMAC_IDE_REG(IDE_TIMING_CONFIG)); 1522 (void)readl(PMAC_IDE_REG(IDE_TIMING_CONFIG));
1531 } 1523 }
@@ -1535,13 +1527,6 @@ pmac_ide_dma_setup(ide_drive_t *drive)
1535 return 0; 1527 return 0;
1536} 1528}
1537 1529
1538static void
1539pmac_ide_dma_exec_cmd(ide_drive_t *drive, u8 command)
1540{
1541 /* issue cmd to drive */
1542 ide_execute_command(drive, command, &ide_dma_intr, 2*WAIT_CMD, NULL);
1543}
1544
1545/* 1530/*
1546 * Kick the DMA controller into life after the DMA command has been issued 1531 * Kick the DMA controller into life after the DMA command has been issued
1547 * to the drive. 1532 * to the drive.
@@ -1662,7 +1647,6 @@ pmac_ide_dma_lost_irq (ide_drive_t *drive)
1662static const struct ide_dma_ops pmac_dma_ops = { 1647static const struct ide_dma_ops pmac_dma_ops = {
1663 .dma_host_set = pmac_ide_dma_host_set, 1648 .dma_host_set = pmac_ide_dma_host_set,
1664 .dma_setup = pmac_ide_dma_setup, 1649 .dma_setup = pmac_ide_dma_setup,
1665 .dma_exec_cmd = pmac_ide_dma_exec_cmd,
1666 .dma_start = pmac_ide_dma_start, 1650 .dma_start = pmac_ide_dma_start,
1667 .dma_end = pmac_ide_dma_end, 1651 .dma_end = pmac_ide_dma_end,
1668 .dma_test_irq = pmac_ide_dma_test_irq, 1652 .dma_test_irq = pmac_ide_dma_test_irq,
diff --git a/drivers/ide/q40ide.c b/drivers/ide/q40ide.c
index 9f9c0b3cc3a3..2a43a2f49633 100644
--- a/drivers/ide/q40ide.c
+++ b/drivers/ide/q40ide.c
@@ -72,26 +72,26 @@ static void q40_ide_setup_ports(hw_regs_t *hw, unsigned long base,
72 hw->chipset = ide_generic; 72 hw->chipset = ide_generic;
73} 73}
74 74
75static void q40ide_input_data(ide_drive_t *drive, struct request *rq, 75static void q40ide_input_data(ide_drive_t *drive, struct ide_cmd *cmd,
76 void *buf, unsigned int len) 76 void *buf, unsigned int len)
77{ 77{
78 unsigned long data_addr = drive->hwif->io_ports.data_addr; 78 unsigned long data_addr = drive->hwif->io_ports.data_addr;
79 79
80 if (drive->media == ide_disk && rq && rq->cmd_type == REQ_TYPE_FS) 80 if (drive->media == ide_disk && cmd && (cmd->tf_flags & IDE_TFLAG_FS))
81 return insw(data_addr, buf, (len + 1) / 2); 81 return insw(data_addr, buf, (len + 1) / 2);
82 82
83 insw_swapw(data_addr, buf, (len + 1) / 2); 83 raw_insw_swapw((u16 *)data_addr, buf, (len + 1) / 2);
84} 84}
85 85
86static void q40ide_output_data(ide_drive_t *drive, struct request *rq, 86static void q40ide_output_data(ide_drive_t *drive, struct ide_cmd *cmd,
87 void *buf, unsigned int len) 87 void *buf, unsigned int len)
88{ 88{
89 unsigned long data_addr = drive->hwif->io_ports.data_addr; 89 unsigned long data_addr = drive->hwif->io_ports.data_addr;
90 90
91 if (drive->media == ide_disk && rq && rq->cmd_type == REQ_TYPE_FS) 91 if (drive->media == ide_disk && cmd && (cmd->tf_flags & IDE_TFLAG_FS))
92 return outsw(data_addr, buf, (len + 1) / 2); 92 return outsw(data_addr, buf, (len + 1) / 2);
93 93
94 outsw_swapw(data_addr, buf, (len + 1) / 2); 94 raw_outsw_swapw((u16 *)data_addr, buf, (len + 1) / 2);
95} 95}
96 96
97/* Q40 has a byte-swapped IDE interface */ 97/* Q40 has a byte-swapped IDE interface */
@@ -111,7 +111,8 @@ static const struct ide_tp_ops q40ide_tp_ops = {
111 111
112static const struct ide_port_info q40ide_port_info = { 112static const struct ide_port_info q40ide_port_info = {
113 .tp_ops = &q40ide_tp_ops, 113 .tp_ops = &q40ide_tp_ops,
114 .host_flags = IDE_HFLAG_NO_DMA, 114 .host_flags = IDE_HFLAG_MMIO | IDE_HFLAG_NO_DMA,
115 .irq_flags = IRQF_SHARED,
115}; 116};
116 117
117/* 118/*
diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
index dbdd2985a0d8..1c3a82914999 100644
--- a/drivers/ide/sc1200.c
+++ b/drivers/ide/sc1200.c
@@ -286,11 +286,11 @@ static const struct ide_port_ops sc1200_port_ops = {
286static const struct ide_dma_ops sc1200_dma_ops = { 286static const struct ide_dma_ops sc1200_dma_ops = {
287 .dma_host_set = ide_dma_host_set, 287 .dma_host_set = ide_dma_host_set,
288 .dma_setup = ide_dma_setup, 288 .dma_setup = ide_dma_setup,
289 .dma_exec_cmd = ide_dma_exec_cmd,
290 .dma_start = ide_dma_start, 289 .dma_start = ide_dma_start,
291 .dma_end = sc1200_dma_end, 290 .dma_end = sc1200_dma_end,
292 .dma_test_irq = ide_dma_test_irq, 291 .dma_test_irq = ide_dma_test_irq,
293 .dma_lost_irq = ide_dma_lost_irq, 292 .dma_lost_irq = ide_dma_lost_irq,
293 .dma_timer_expiry = ide_dma_sff_timer_expiry,
294 .dma_timeout = ide_dma_timeout, 294 .dma_timeout = ide_dma_timeout,
295 .dma_sff_read_status = ide_dma_sff_read_status, 295 .dma_sff_read_status = ide_dma_sff_read_status,
296}; 296};
diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
index 8d2314b6327c..0cc137cfe76d 100644
--- a/drivers/ide/scc_pata.c
+++ b/drivers/ide/scc_pata.c
@@ -303,8 +303,9 @@ static void scc_dma_host_set(ide_drive_t *drive, int on)
303} 303}
304 304
305/** 305/**
306 * scc_ide_dma_setup - begin a DMA phase 306 * scc_dma_setup - begin a DMA phase
307 * @drive: target device 307 * @drive: target device
308 * @cmd: command
308 * 309 *
309 * Build an IDE DMA PRD (IDE speak for scatter gather table) 310 * Build an IDE DMA PRD (IDE speak for scatter gather table)
310 * and then set up the DMA transfer registers. 311 * and then set up the DMA transfer registers.
@@ -313,21 +314,15 @@ static void scc_dma_host_set(ide_drive_t *drive, int on)
313 * is returned. 314 * is returned.
314 */ 315 */
315 316
316static int scc_dma_setup(ide_drive_t *drive) 317static int scc_dma_setup(ide_drive_t *drive, struct ide_cmd *cmd)
317{ 318{
318 ide_hwif_t *hwif = drive->hwif; 319 ide_hwif_t *hwif = drive->hwif;
319 struct request *rq = hwif->rq; 320 u32 rw = (cmd->tf_flags & IDE_TFLAG_WRITE) ? 0 : ATA_DMA_WR;
320 unsigned int reading;
321 u8 dma_stat; 321 u8 dma_stat;
322 322
323 if (rq_data_dir(rq))
324 reading = 0;
325 else
326 reading = 1 << 3;
327
328 /* fall back to pio! */ 323 /* fall back to pio! */
329 if (!ide_build_dmatable(drive, rq)) { 324 if (ide_build_dmatable(drive, cmd) == 0) {
330 ide_map_sg(drive, rq); 325 ide_map_sg(drive, cmd);
331 return 1; 326 return 1;
332 } 327 }
333 328
@@ -335,7 +330,7 @@ static int scc_dma_setup(ide_drive_t *drive)
335 out_be32((void __iomem *)(hwif->dma_base + 8), hwif->dmatable_dma); 330 out_be32((void __iomem *)(hwif->dma_base + 8), hwif->dmatable_dma);
336 331
337 /* specify r/w */ 332 /* specify r/w */
338 out_be32((void __iomem *)hwif->dma_base, reading); 333 out_be32((void __iomem *)hwif->dma_base, rw);
339 334
340 /* read DMA status for INTR & ERROR flags */ 335 /* read DMA status for INTR & ERROR flags */
341 dma_stat = scc_dma_sff_read_status(hwif); 336 dma_stat = scc_dma_sff_read_status(hwif);
@@ -666,52 +661,52 @@ static int __devinit init_setup_scc(struct pci_dev *dev,
666 return rc; 661 return rc;
667} 662}
668 663
669static void scc_tf_load(ide_drive_t *drive, ide_task_t *task) 664static void scc_tf_load(ide_drive_t *drive, struct ide_cmd *cmd)
670{ 665{
671 struct ide_io_ports *io_ports = &drive->hwif->io_ports; 666 struct ide_io_ports *io_ports = &drive->hwif->io_ports;
672 struct ide_taskfile *tf = &task->tf; 667 struct ide_taskfile *tf = &cmd->tf;
673 u8 HIHI = (task->tf_flags & IDE_TFLAG_LBA48) ? 0xE0 : 0xEF; 668 u8 HIHI = (cmd->tf_flags & IDE_TFLAG_LBA48) ? 0xE0 : 0xEF;
674 669
675 if (task->tf_flags & IDE_TFLAG_FLAGGED) 670 if (cmd->ftf_flags & IDE_FTFLAG_FLAGGED)
676 HIHI = 0xFF; 671 HIHI = 0xFF;
677 672
678 if (task->tf_flags & IDE_TFLAG_OUT_DATA) 673 if (cmd->ftf_flags & IDE_FTFLAG_OUT_DATA)
679 out_be32((void *)io_ports->data_addr, 674 out_be32((void *)io_ports->data_addr,
680 (tf->hob_data << 8) | tf->data); 675 (tf->hob_data << 8) | tf->data);
681 676
682 if (task->tf_flags & IDE_TFLAG_OUT_HOB_FEATURE) 677 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_FEATURE)
683 scc_ide_outb(tf->hob_feature, io_ports->feature_addr); 678 scc_ide_outb(tf->hob_feature, io_ports->feature_addr);
684 if (task->tf_flags & IDE_TFLAG_OUT_HOB_NSECT) 679 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_NSECT)
685 scc_ide_outb(tf->hob_nsect, io_ports->nsect_addr); 680 scc_ide_outb(tf->hob_nsect, io_ports->nsect_addr);
686 if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAL) 681 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_LBAL)
687 scc_ide_outb(tf->hob_lbal, io_ports->lbal_addr); 682 scc_ide_outb(tf->hob_lbal, io_ports->lbal_addr);
688 if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAM) 683 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_LBAM)
689 scc_ide_outb(tf->hob_lbam, io_ports->lbam_addr); 684 scc_ide_outb(tf->hob_lbam, io_ports->lbam_addr);
690 if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAH) 685 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_LBAH)
691 scc_ide_outb(tf->hob_lbah, io_ports->lbah_addr); 686 scc_ide_outb(tf->hob_lbah, io_ports->lbah_addr);
692 687
693 if (task->tf_flags & IDE_TFLAG_OUT_FEATURE) 688 if (cmd->tf_flags & IDE_TFLAG_OUT_FEATURE)
694 scc_ide_outb(tf->feature, io_ports->feature_addr); 689 scc_ide_outb(tf->feature, io_ports->feature_addr);
695 if (task->tf_flags & IDE_TFLAG_OUT_NSECT) 690 if (cmd->tf_flags & IDE_TFLAG_OUT_NSECT)
696 scc_ide_outb(tf->nsect, io_ports->nsect_addr); 691 scc_ide_outb(tf->nsect, io_ports->nsect_addr);
697 if (task->tf_flags & IDE_TFLAG_OUT_LBAL) 692 if (cmd->tf_flags & IDE_TFLAG_OUT_LBAL)
698 scc_ide_outb(tf->lbal, io_ports->lbal_addr); 693 scc_ide_outb(tf->lbal, io_ports->lbal_addr);
699 if (task->tf_flags & IDE_TFLAG_OUT_LBAM) 694 if (cmd->tf_flags & IDE_TFLAG_OUT_LBAM)
700 scc_ide_outb(tf->lbam, io_ports->lbam_addr); 695 scc_ide_outb(tf->lbam, io_ports->lbam_addr);
701 if (task->tf_flags & IDE_TFLAG_OUT_LBAH) 696 if (cmd->tf_flags & IDE_TFLAG_OUT_LBAH)
702 scc_ide_outb(tf->lbah, io_ports->lbah_addr); 697 scc_ide_outb(tf->lbah, io_ports->lbah_addr);
703 698
704 if (task->tf_flags & IDE_TFLAG_OUT_DEVICE) 699 if (cmd->tf_flags & IDE_TFLAG_OUT_DEVICE)
705 scc_ide_outb((tf->device & HIHI) | drive->select, 700 scc_ide_outb((tf->device & HIHI) | drive->select,
706 io_ports->device_addr); 701 io_ports->device_addr);
707} 702}
708 703
709static void scc_tf_read(ide_drive_t *drive, ide_task_t *task) 704static void scc_tf_read(ide_drive_t *drive, struct ide_cmd *cmd)
710{ 705{
711 struct ide_io_ports *io_ports = &drive->hwif->io_ports; 706 struct ide_io_ports *io_ports = &drive->hwif->io_ports;
712 struct ide_taskfile *tf = &task->tf; 707 struct ide_taskfile *tf = &cmd->tf;
713 708
714 if (task->tf_flags & IDE_TFLAG_IN_DATA) { 709 if (cmd->ftf_flags & IDE_FTFLAG_IN_DATA) {
715 u16 data = (u16)in_be32((void *)io_ports->data_addr); 710 u16 data = (u16)in_be32((void *)io_ports->data_addr);
716 711
717 tf->data = data & 0xff; 712 tf->data = data & 0xff;
@@ -721,36 +716,36 @@ static void scc_tf_read(ide_drive_t *drive, ide_task_t *task)
721 /* be sure we're looking at the low order bits */ 716 /* be sure we're looking at the low order bits */
722 scc_ide_outb(ATA_DEVCTL_OBS & ~0x80, io_ports->ctl_addr); 717 scc_ide_outb(ATA_DEVCTL_OBS & ~0x80, io_ports->ctl_addr);
723 718
724 if (task->tf_flags & IDE_TFLAG_IN_FEATURE) 719 if (cmd->tf_flags & IDE_TFLAG_IN_FEATURE)
725 tf->feature = scc_ide_inb(io_ports->feature_addr); 720 tf->feature = scc_ide_inb(io_ports->feature_addr);
726 if (task->tf_flags & IDE_TFLAG_IN_NSECT) 721 if (cmd->tf_flags & IDE_TFLAG_IN_NSECT)
727 tf->nsect = scc_ide_inb(io_ports->nsect_addr); 722 tf->nsect = scc_ide_inb(io_ports->nsect_addr);
728 if (task->tf_flags & IDE_TFLAG_IN_LBAL) 723 if (cmd->tf_flags & IDE_TFLAG_IN_LBAL)
729 tf->lbal = scc_ide_inb(io_ports->lbal_addr); 724 tf->lbal = scc_ide_inb(io_ports->lbal_addr);
730 if (task->tf_flags & IDE_TFLAG_IN_LBAM) 725 if (cmd->tf_flags & IDE_TFLAG_IN_LBAM)
731 tf->lbam = scc_ide_inb(io_ports->lbam_addr); 726 tf->lbam = scc_ide_inb(io_ports->lbam_addr);
732 if (task->tf_flags & IDE_TFLAG_IN_LBAH) 727 if (cmd->tf_flags & IDE_TFLAG_IN_LBAH)
733 tf->lbah = scc_ide_inb(io_ports->lbah_addr); 728 tf->lbah = scc_ide_inb(io_ports->lbah_addr);
734 if (task->tf_flags & IDE_TFLAG_IN_DEVICE) 729 if (cmd->tf_flags & IDE_TFLAG_IN_DEVICE)
735 tf->device = scc_ide_inb(io_ports->device_addr); 730 tf->device = scc_ide_inb(io_ports->device_addr);
736 731
737 if (task->tf_flags & IDE_TFLAG_LBA48) { 732 if (cmd->tf_flags & IDE_TFLAG_LBA48) {
738 scc_ide_outb(ATA_DEVCTL_OBS | 0x80, io_ports->ctl_addr); 733 scc_ide_outb(ATA_DEVCTL_OBS | 0x80, io_ports->ctl_addr);
739 734
740 if (task->tf_flags & IDE_TFLAG_IN_HOB_FEATURE) 735 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_FEATURE)
741 tf->hob_feature = scc_ide_inb(io_ports->feature_addr); 736 tf->hob_feature = scc_ide_inb(io_ports->feature_addr);
742 if (task->tf_flags & IDE_TFLAG_IN_HOB_NSECT) 737 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_NSECT)
743 tf->hob_nsect = scc_ide_inb(io_ports->nsect_addr); 738 tf->hob_nsect = scc_ide_inb(io_ports->nsect_addr);
744 if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAL) 739 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAL)
745 tf->hob_lbal = scc_ide_inb(io_ports->lbal_addr); 740 tf->hob_lbal = scc_ide_inb(io_ports->lbal_addr);
746 if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAM) 741 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAM)
747 tf->hob_lbam = scc_ide_inb(io_ports->lbam_addr); 742 tf->hob_lbam = scc_ide_inb(io_ports->lbam_addr);
748 if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAH) 743 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAH)
749 tf->hob_lbah = scc_ide_inb(io_ports->lbah_addr); 744 tf->hob_lbah = scc_ide_inb(io_ports->lbah_addr);
750 } 745 }
751} 746}
752 747
753static void scc_input_data(ide_drive_t *drive, struct request *rq, 748static void scc_input_data(ide_drive_t *drive, struct ide_cmd *cmd,
754 void *buf, unsigned int len) 749 void *buf, unsigned int len)
755{ 750{
756 unsigned long data_addr = drive->hwif->io_ports.data_addr; 751 unsigned long data_addr = drive->hwif->io_ports.data_addr;
@@ -766,7 +761,7 @@ static void scc_input_data(ide_drive_t *drive, struct request *rq,
766 scc_ide_insw(data_addr, buf, len / 2); 761 scc_ide_insw(data_addr, buf, len / 2);
767} 762}
768 763
769static void scc_output_data(ide_drive_t *drive, struct request *rq, 764static void scc_output_data(ide_drive_t *drive, struct ide_cmd *cmd,
770 void *buf, unsigned int len) 765 void *buf, unsigned int len)
771{ 766{
772 unsigned long data_addr = drive->hwif->io_ports.data_addr; 767 unsigned long data_addr = drive->hwif->io_ports.data_addr;
@@ -873,30 +868,26 @@ static const struct ide_port_ops scc_port_ops = {
873static const struct ide_dma_ops scc_dma_ops = { 868static const struct ide_dma_ops scc_dma_ops = {
874 .dma_host_set = scc_dma_host_set, 869 .dma_host_set = scc_dma_host_set,
875 .dma_setup = scc_dma_setup, 870 .dma_setup = scc_dma_setup,
876 .dma_exec_cmd = ide_dma_exec_cmd,
877 .dma_start = scc_dma_start, 871 .dma_start = scc_dma_start,
878 .dma_end = scc_dma_end, 872 .dma_end = scc_dma_end,
879 .dma_test_irq = scc_dma_test_irq, 873 .dma_test_irq = scc_dma_test_irq,
880 .dma_lost_irq = ide_dma_lost_irq, 874 .dma_lost_irq = ide_dma_lost_irq,
881 .dma_timeout = ide_dma_timeout, 875 .dma_timeout = ide_dma_timeout,
876 .dma_timer_expiry = ide_dma_sff_timer_expiry,
882 .dma_sff_read_status = scc_dma_sff_read_status, 877 .dma_sff_read_status = scc_dma_sff_read_status,
883}; 878};
884 879
885#define DECLARE_SCC_DEV(name_str) \ 880static const struct ide_port_info scc_chipset __devinitdata = {
886 { \ 881 .name = "sccIDE",
887 .name = name_str, \ 882 .init_iops = init_iops_scc,
888 .init_iops = init_iops_scc, \ 883 .init_dma = scc_init_dma,
889 .init_dma = scc_init_dma, \ 884 .init_hwif = init_hwif_scc,
890 .init_hwif = init_hwif_scc, \ 885 .tp_ops = &scc_tp_ops,
891 .tp_ops = &scc_tp_ops, \ 886 .port_ops = &scc_port_ops,
892 .port_ops = &scc_port_ops, \ 887 .dma_ops = &scc_dma_ops,
893 .dma_ops = &scc_dma_ops, \ 888 .host_flags = IDE_HFLAG_SINGLE,
894 .host_flags = IDE_HFLAG_SINGLE, \ 889 .irq_flags = IRQF_SHARED,
895 .pio_mask = ATA_PIO4, \ 890 .pio_mask = ATA_PIO4,
896 }
897
898static const struct ide_port_info scc_chipsets[] __devinitdata = {
899 /* 0 */ DECLARE_SCC_DEV("sccIDE"),
900}; 891};
901 892
902/** 893/**
@@ -910,7 +901,7 @@ static const struct ide_port_info scc_chipsets[] __devinitdata = {
910 901
911static int __devinit scc_init_one(struct pci_dev *dev, const struct pci_device_id *id) 902static int __devinit scc_init_one(struct pci_dev *dev, const struct pci_device_id *id)
912{ 903{
913 return init_setup_scc(dev, &scc_chipsets[id->driver_data]); 904 return init_setup_scc(dev, &scc_chipset);
914} 905}
915 906
916/** 907/**
diff --git a/drivers/ide/setup-pci.c b/drivers/ide/setup-pci.c
index 24bc884826fc..a19dbccd7617 100644
--- a/drivers/ide/setup-pci.c
+++ b/drivers/ide/setup-pci.c
@@ -558,6 +558,8 @@ int ide_pci_init_one(struct pci_dev *dev, const struct ide_port_info *d,
558 558
559 host->host_priv = priv; 559 host->host_priv = priv;
560 560
561 host->irq_flags = IRQF_SHARED;
562
561 pci_set_drvdata(dev, host); 563 pci_set_drvdata(dev, host);
562 564
563 ret = do_ide_setup_pci_device(dev, d, 1); 565 ret = do_ide_setup_pci_device(dev, d, 1);
@@ -606,6 +608,8 @@ int ide_pci_init_two(struct pci_dev *dev1, struct pci_dev *dev2,
606 608
607 host->host_priv = priv; 609 host->host_priv = priv;
608 610
611 host->irq_flags = IRQF_SHARED;
612
609 pci_set_drvdata(pdev[0], host); 613 pci_set_drvdata(pdev[0], host);
610 pci_set_drvdata(pdev[1], host); 614 pci_set_drvdata(pdev[1], host);
611 615
diff --git a/drivers/ide/sgiioc4.c b/drivers/ide/sgiioc4.c
index fdb9d7037694..b12de8346c73 100644
--- a/drivers/ide/sgiioc4.c
+++ b/drivers/ide/sgiioc4.c
@@ -424,20 +424,13 @@ sgiioc4_configure_for_dma(int dma_direction, ide_drive_t * drive)
424/* | Upper 32 bits - Zero |EOL| 15 unused | 16 Bit Length| */ 424/* | Upper 32 bits - Zero |EOL| 15 unused | 16 Bit Length| */
425/* --------------------------------------------------------------------- */ 425/* --------------------------------------------------------------------- */
426/* Creates the scatter gather list, DMA Table */ 426/* Creates the scatter gather list, DMA Table */
427static unsigned int 427static int sgiioc4_build_dmatable(ide_drive_t *drive, struct ide_cmd *cmd)
428sgiioc4_build_dma_table(ide_drive_t * drive, struct request *rq, int ddir)
429{ 428{
430 ide_hwif_t *hwif = drive->hwif; 429 ide_hwif_t *hwif = drive->hwif;
431 unsigned int *table = hwif->dmatable_cpu; 430 unsigned int *table = hwif->dmatable_cpu;
432 unsigned int count = 0, i = 1; 431 unsigned int count = 0, i = cmd->sg_nents;
433 struct scatterlist *sg; 432 struct scatterlist *sg = hwif->sg_table;
434 433
435 hwif->sg_nents = i = ide_build_sglist(drive, rq);
436
437 if (!i)
438 return 0; /* sglist of length Zero */
439
440 sg = hwif->sg_table;
441 while (i && sg_dma_len(sg)) { 434 while (i && sg_dma_len(sg)) {
442 dma_addr_t cur_addr; 435 dma_addr_t cur_addr;
443 int cur_len; 436 int cur_len;
@@ -490,24 +483,18 @@ use_pio_instead:
490 return 0; /* revert to PIO for this request */ 483 return 0; /* revert to PIO for this request */
491} 484}
492 485
493static int sgiioc4_dma_setup(ide_drive_t *drive) 486static int sgiioc4_dma_setup(ide_drive_t *drive, struct ide_cmd *cmd)
494{ 487{
495 struct request *rq = drive->hwif->rq;
496 unsigned int count = 0;
497 int ddir; 488 int ddir;
489 u8 write = !!(cmd->tf_flags & IDE_TFLAG_WRITE);
498 490
499 if (rq_data_dir(rq)) 491 if (sgiioc4_build_dmatable(drive, cmd) == 0) {
500 ddir = PCI_DMA_TODEVICE;
501 else
502 ddir = PCI_DMA_FROMDEVICE;
503
504 if (!(count = sgiioc4_build_dma_table(drive, rq, ddir))) {
505 /* try PIO instead of DMA */ 492 /* try PIO instead of DMA */
506 ide_map_sg(drive, rq); 493 ide_map_sg(drive, cmd);
507 return 1; 494 return 1;
508 } 495 }
509 496
510 if (rq_data_dir(rq)) 497 if (write)
511 /* Writes TO the IOC4 FROM Main Memory */ 498 /* Writes TO the IOC4 FROM Main Memory */
512 ddir = IOC4_DMA_READ; 499 ddir = IOC4_DMA_READ;
513 else 500 else
@@ -557,6 +544,7 @@ static const struct ide_port_info sgiioc4_port_info __devinitconst = {
557 .port_ops = &sgiioc4_port_ops, 544 .port_ops = &sgiioc4_port_ops,
558 .dma_ops = &sgiioc4_dma_ops, 545 .dma_ops = &sgiioc4_dma_ops,
559 .host_flags = IDE_HFLAG_MMIO, 546 .host_flags = IDE_HFLAG_MMIO,
547 .irq_flags = IRQF_SHARED,
560 .mwdma_mask = ATA_MWDMA2_ONLY, 548 .mwdma_mask = ATA_MWDMA2_ONLY,
561}; 549};
562 550
diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
index 1811ae9cd843..075cb1243b2a 100644
--- a/drivers/ide/siimage.c
+++ b/drivers/ide/siimage.c
@@ -711,10 +711,10 @@ static const struct ide_port_ops sil_sata_port_ops = {
711static const struct ide_dma_ops sil_dma_ops = { 711static const struct ide_dma_ops sil_dma_ops = {
712 .dma_host_set = ide_dma_host_set, 712 .dma_host_set = ide_dma_host_set,
713 .dma_setup = ide_dma_setup, 713 .dma_setup = ide_dma_setup,
714 .dma_exec_cmd = ide_dma_exec_cmd,
715 .dma_start = ide_dma_start, 714 .dma_start = ide_dma_start,
716 .dma_end = ide_dma_end, 715 .dma_end = ide_dma_end,
717 .dma_test_irq = siimage_dma_test_irq, 716 .dma_test_irq = siimage_dma_test_irq,
717 .dma_timer_expiry = ide_dma_sff_timer_expiry,
718 .dma_timeout = ide_dma_timeout, 718 .dma_timeout = ide_dma_timeout,
719 .dma_lost_irq = ide_dma_lost_irq, 719 .dma_lost_irq = ide_dma_lost_irq,
720 .dma_sff_read_status = ide_dma_sff_read_status, 720 .dma_sff_read_status = ide_dma_sff_read_status,
diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
index dba213c51baa..d25137b04e7a 100644
--- a/drivers/ide/sl82c105.c
+++ b/drivers/ide/sl82c105.c
@@ -293,11 +293,11 @@ static const struct ide_port_ops sl82c105_port_ops = {
293static const struct ide_dma_ops sl82c105_dma_ops = { 293static const struct ide_dma_ops sl82c105_dma_ops = {
294 .dma_host_set = ide_dma_host_set, 294 .dma_host_set = ide_dma_host_set,
295 .dma_setup = ide_dma_setup, 295 .dma_setup = ide_dma_setup,
296 .dma_exec_cmd = ide_dma_exec_cmd,
297 .dma_start = sl82c105_dma_start, 296 .dma_start = sl82c105_dma_start,
298 .dma_end = sl82c105_dma_end, 297 .dma_end = sl82c105_dma_end,
299 .dma_test_irq = ide_dma_test_irq, 298 .dma_test_irq = ide_dma_test_irq,
300 .dma_lost_irq = sl82c105_dma_lost_irq, 299 .dma_lost_irq = sl82c105_dma_lost_irq,
300 .dma_timer_expiry = ide_dma_sff_timer_expiry,
301 .dma_timeout = sl82c105_dma_timeout, 301 .dma_timeout = sl82c105_dma_timeout,
302 .dma_sff_read_status = ide_dma_sff_read_status, 302 .dma_sff_read_status = ide_dma_sff_read_status,
303}; 303};
diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
index 84109f5a1632..427d4b3c2c63 100644
--- a/drivers/ide/tc86c001.c
+++ b/drivers/ide/tc86c001.c
@@ -182,11 +182,11 @@ static const struct ide_port_ops tc86c001_port_ops = {
182static const struct ide_dma_ops tc86c001_dma_ops = { 182static const struct ide_dma_ops tc86c001_dma_ops = {
183 .dma_host_set = ide_dma_host_set, 183 .dma_host_set = ide_dma_host_set,
184 .dma_setup = ide_dma_setup, 184 .dma_setup = ide_dma_setup,
185 .dma_exec_cmd = ide_dma_exec_cmd,
186 .dma_start = tc86c001_dma_start, 185 .dma_start = tc86c001_dma_start,
187 .dma_end = ide_dma_end, 186 .dma_end = ide_dma_end,
188 .dma_test_irq = ide_dma_test_irq, 187 .dma_test_irq = ide_dma_test_irq,
189 .dma_lost_irq = ide_dma_lost_irq, 188 .dma_lost_irq = ide_dma_lost_irq,
189 .dma_timer_expiry = ide_dma_sff_timer_expiry,
190 .dma_timeout = ide_dma_timeout, 190 .dma_timeout = ide_dma_timeout,
191 .dma_sff_read_status = ide_dma_sff_read_status, 191 .dma_sff_read_status = ide_dma_sff_read_status,
192}; 192};
diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
index 1c09e549c423..ed1496845a93 100644
--- a/drivers/ide/trm290.c
+++ b/drivers/ide/trm290.c
@@ -176,18 +176,12 @@ static void trm290_selectproc (ide_drive_t *drive)
176 trm290_prepare_drive(drive, !!(drive->dev_flags & IDE_DFLAG_USING_DMA)); 176 trm290_prepare_drive(drive, !!(drive->dev_flags & IDE_DFLAG_USING_DMA));
177} 177}
178 178
179static void trm290_dma_exec_cmd(ide_drive_t *drive, u8 command) 179static int trm290_dma_setup(ide_drive_t *drive, struct ide_cmd *cmd)
180{
181 ide_execute_command(drive, command, &ide_dma_intr, WAIT_CMD, NULL);
182}
183
184static int trm290_dma_setup(ide_drive_t *drive)
185{ 180{
186 ide_hwif_t *hwif = drive->hwif; 181 ide_hwif_t *hwif = drive->hwif;
187 struct request *rq = hwif->rq;
188 unsigned int count, rw; 182 unsigned int count, rw;
189 183
190 if (rq_data_dir(rq)) { 184 if (cmd->tf_flags & IDE_TFLAG_WRITE) {
191#ifdef TRM290_NO_DMA_WRITES 185#ifdef TRM290_NO_DMA_WRITES
192 /* always use PIO for writes */ 186 /* always use PIO for writes */
193 trm290_prepare_drive(drive, 0); /* select PIO xfer */ 187 trm290_prepare_drive(drive, 0); /* select PIO xfer */
@@ -197,7 +191,9 @@ static int trm290_dma_setup(ide_drive_t *drive)
197 } else 191 } else
198 rw = 2; 192 rw = 2;
199 193
200 if (!(count = ide_build_dmatable(drive, rq))) { 194 count = ide_build_dmatable(drive, cmd);
195 if (count == 0) {
196 ide_map_sg(drive, cmd);
201 /* try PIO instead of DMA */ 197 /* try PIO instead of DMA */
202 trm290_prepare_drive(drive, 0); /* select PIO xfer */ 198 trm290_prepare_drive(drive, 0); /* select PIO xfer */
203 return 1; 199 return 1;
@@ -314,7 +310,6 @@ static const struct ide_port_ops trm290_port_ops = {
314static struct ide_dma_ops trm290_dma_ops = { 310static struct ide_dma_ops trm290_dma_ops = {
315 .dma_host_set = trm290_dma_host_set, 311 .dma_host_set = trm290_dma_host_set,
316 .dma_setup = trm290_dma_setup, 312 .dma_setup = trm290_dma_setup,
317 .dma_exec_cmd = trm290_dma_exec_cmd,
318 .dma_start = trm290_dma_start, 313 .dma_start = trm290_dma_start,
319 .dma_end = trm290_dma_end, 314 .dma_end = trm290_dma_end,
320 .dma_test_irq = trm290_dma_test_irq, 315 .dma_test_irq = trm290_dma_test_irq,
diff --git a/drivers/ide/tx4938ide.c b/drivers/ide/tx4938ide.c
index d9095345f7ca..657a61890b1c 100644
--- a/drivers/ide/tx4938ide.c
+++ b/drivers/ide/tx4938ide.c
@@ -15,6 +15,8 @@
15#include <linux/init.h> 15#include <linux/init.h>
16#include <linux/platform_device.h> 16#include <linux/platform_device.h>
17#include <linux/io.h> 17#include <linux/io.h>
18
19#include <asm/ide.h>
18#include <asm/txx9/tx4938.h> 20#include <asm/txx9/tx4938.h>
19 21
20static void tx4938ide_tune_ebusc(unsigned int ebus_ch, 22static void tx4938ide_tune_ebusc(unsigned int ebus_ch,
@@ -80,57 +82,57 @@ static void tx4938ide_outb(u8 value, unsigned long port)
80 __raw_writeb(value, (void __iomem *)port); 82 __raw_writeb(value, (void __iomem *)port);
81} 83}
82 84
83static void tx4938ide_tf_load(ide_drive_t *drive, ide_task_t *task) 85static void tx4938ide_tf_load(ide_drive_t *drive, struct ide_cmd *cmd)
84{ 86{
85 ide_hwif_t *hwif = drive->hwif; 87 ide_hwif_t *hwif = drive->hwif;
86 struct ide_io_ports *io_ports = &hwif->io_ports; 88 struct ide_io_ports *io_ports = &hwif->io_ports;
87 struct ide_taskfile *tf = &task->tf; 89 struct ide_taskfile *tf = &cmd->tf;
88 u8 HIHI = task->tf_flags & IDE_TFLAG_LBA48 ? 0xE0 : 0xEF; 90 u8 HIHI = cmd->tf_flags & IDE_TFLAG_LBA48 ? 0xE0 : 0xEF;
89 91
90 if (task->tf_flags & IDE_TFLAG_FLAGGED) 92 if (cmd->ftf_flags & IDE_FTFLAG_FLAGGED)
91 HIHI = 0xFF; 93 HIHI = 0xFF;
92 94
93 if (task->tf_flags & IDE_TFLAG_OUT_DATA) { 95 if (cmd->ftf_flags & IDE_FTFLAG_OUT_DATA) {
94 u16 data = (tf->hob_data << 8) | tf->data; 96 u16 data = (tf->hob_data << 8) | tf->data;
95 97
96 /* no endian swap */ 98 /* no endian swap */
97 __raw_writew(data, (void __iomem *)io_ports->data_addr); 99 __raw_writew(data, (void __iomem *)io_ports->data_addr);
98 } 100 }
99 101
100 if (task->tf_flags & IDE_TFLAG_OUT_HOB_FEATURE) 102 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_FEATURE)
101 tx4938ide_outb(tf->hob_feature, io_ports->feature_addr); 103 tx4938ide_outb(tf->hob_feature, io_ports->feature_addr);
102 if (task->tf_flags & IDE_TFLAG_OUT_HOB_NSECT) 104 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_NSECT)
103 tx4938ide_outb(tf->hob_nsect, io_ports->nsect_addr); 105 tx4938ide_outb(tf->hob_nsect, io_ports->nsect_addr);
104 if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAL) 106 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_LBAL)
105 tx4938ide_outb(tf->hob_lbal, io_ports->lbal_addr); 107 tx4938ide_outb(tf->hob_lbal, io_ports->lbal_addr);
106 if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAM) 108 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_LBAM)
107 tx4938ide_outb(tf->hob_lbam, io_ports->lbam_addr); 109 tx4938ide_outb(tf->hob_lbam, io_ports->lbam_addr);
108 if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAH) 110 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_LBAH)
109 tx4938ide_outb(tf->hob_lbah, io_ports->lbah_addr); 111 tx4938ide_outb(tf->hob_lbah, io_ports->lbah_addr);
110 112
111 if (task->tf_flags & IDE_TFLAG_OUT_FEATURE) 113 if (cmd->tf_flags & IDE_TFLAG_OUT_FEATURE)
112 tx4938ide_outb(tf->feature, io_ports->feature_addr); 114 tx4938ide_outb(tf->feature, io_ports->feature_addr);
113 if (task->tf_flags & IDE_TFLAG_OUT_NSECT) 115 if (cmd->tf_flags & IDE_TFLAG_OUT_NSECT)
114 tx4938ide_outb(tf->nsect, io_ports->nsect_addr); 116 tx4938ide_outb(tf->nsect, io_ports->nsect_addr);
115 if (task->tf_flags & IDE_TFLAG_OUT_LBAL) 117 if (cmd->tf_flags & IDE_TFLAG_OUT_LBAL)
116 tx4938ide_outb(tf->lbal, io_ports->lbal_addr); 118 tx4938ide_outb(tf->lbal, io_ports->lbal_addr);
117 if (task->tf_flags & IDE_TFLAG_OUT_LBAM) 119 if (cmd->tf_flags & IDE_TFLAG_OUT_LBAM)
118 tx4938ide_outb(tf->lbam, io_ports->lbam_addr); 120 tx4938ide_outb(tf->lbam, io_ports->lbam_addr);
119 if (task->tf_flags & IDE_TFLAG_OUT_LBAH) 121 if (cmd->tf_flags & IDE_TFLAG_OUT_LBAH)
120 tx4938ide_outb(tf->lbah, io_ports->lbah_addr); 122 tx4938ide_outb(tf->lbah, io_ports->lbah_addr);
121 123
122 if (task->tf_flags & IDE_TFLAG_OUT_DEVICE) 124 if (cmd->tf_flags & IDE_TFLAG_OUT_DEVICE)
123 tx4938ide_outb((tf->device & HIHI) | drive->select, 125 tx4938ide_outb((tf->device & HIHI) | drive->select,
124 io_ports->device_addr); 126 io_ports->device_addr);
125} 127}
126 128
127static void tx4938ide_tf_read(ide_drive_t *drive, ide_task_t *task) 129static void tx4938ide_tf_read(ide_drive_t *drive, struct ide_cmd *cmd)
128{ 130{
129 ide_hwif_t *hwif = drive->hwif; 131 ide_hwif_t *hwif = drive->hwif;
130 struct ide_io_ports *io_ports = &hwif->io_ports; 132 struct ide_io_ports *io_ports = &hwif->io_ports;
131 struct ide_taskfile *tf = &task->tf; 133 struct ide_taskfile *tf = &cmd->tf;
132 134
133 if (task->tf_flags & IDE_TFLAG_IN_DATA) { 135 if (cmd->ftf_flags & IDE_FTFLAG_IN_DATA) {
134 u16 data; 136 u16 data;
135 137
136 /* no endian swap */ 138 /* no endian swap */
@@ -142,37 +144,37 @@ static void tx4938ide_tf_read(ide_drive_t *drive, ide_task_t *task)
142 /* be sure we're looking at the low order bits */ 144 /* be sure we're looking at the low order bits */
143 tx4938ide_outb(ATA_DEVCTL_OBS & ~0x80, io_ports->ctl_addr); 145 tx4938ide_outb(ATA_DEVCTL_OBS & ~0x80, io_ports->ctl_addr);
144 146
145 if (task->tf_flags & IDE_TFLAG_IN_FEATURE) 147 if (cmd->tf_flags & IDE_TFLAG_IN_FEATURE)
146 tf->feature = tx4938ide_inb(io_ports->feature_addr); 148 tf->feature = tx4938ide_inb(io_ports->feature_addr);
147 if (task->tf_flags & IDE_TFLAG_IN_NSECT) 149 if (cmd->tf_flags & IDE_TFLAG_IN_NSECT)
148 tf->nsect = tx4938ide_inb(io_ports->nsect_addr); 150 tf->nsect = tx4938ide_inb(io_ports->nsect_addr);
149 if (task->tf_flags & IDE_TFLAG_IN_LBAL) 151 if (cmd->tf_flags & IDE_TFLAG_IN_LBAL)
150 tf->lbal = tx4938ide_inb(io_ports->lbal_addr); 152 tf->lbal = tx4938ide_inb(io_ports->lbal_addr);
151 if (task->tf_flags & IDE_TFLAG_IN_LBAM) 153 if (cmd->tf_flags & IDE_TFLAG_IN_LBAM)
152 tf->lbam = tx4938ide_inb(io_ports->lbam_addr); 154 tf->lbam = tx4938ide_inb(io_ports->lbam_addr);
153 if (task->tf_flags & IDE_TFLAG_IN_LBAH) 155 if (cmd->tf_flags & IDE_TFLAG_IN_LBAH)
154 tf->lbah = tx4938ide_inb(io_ports->lbah_addr); 156 tf->lbah = tx4938ide_inb(io_ports->lbah_addr);
155 if (task->tf_flags & IDE_TFLAG_IN_DEVICE) 157 if (cmd->tf_flags & IDE_TFLAG_IN_DEVICE)
156 tf->device = tx4938ide_inb(io_ports->device_addr); 158 tf->device = tx4938ide_inb(io_ports->device_addr);
157 159
158 if (task->tf_flags & IDE_TFLAG_LBA48) { 160 if (cmd->tf_flags & IDE_TFLAG_LBA48) {
159 tx4938ide_outb(ATA_DEVCTL_OBS | 0x80, io_ports->ctl_addr); 161 tx4938ide_outb(ATA_DEVCTL_OBS | 0x80, io_ports->ctl_addr);
160 162
161 if (task->tf_flags & IDE_TFLAG_IN_HOB_FEATURE) 163 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_FEATURE)
162 tf->hob_feature = 164 tf->hob_feature =
163 tx4938ide_inb(io_ports->feature_addr); 165 tx4938ide_inb(io_ports->feature_addr);
164 if (task->tf_flags & IDE_TFLAG_IN_HOB_NSECT) 166 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_NSECT)
165 tf->hob_nsect = tx4938ide_inb(io_ports->nsect_addr); 167 tf->hob_nsect = tx4938ide_inb(io_ports->nsect_addr);
166 if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAL) 168 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAL)
167 tf->hob_lbal = tx4938ide_inb(io_ports->lbal_addr); 169 tf->hob_lbal = tx4938ide_inb(io_ports->lbal_addr);
168 if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAM) 170 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAM)
169 tf->hob_lbam = tx4938ide_inb(io_ports->lbam_addr); 171 tf->hob_lbam = tx4938ide_inb(io_ports->lbam_addr);
170 if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAH) 172 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAH)
171 tf->hob_lbah = tx4938ide_inb(io_ports->lbah_addr); 173 tf->hob_lbah = tx4938ide_inb(io_ports->lbah_addr);
172 } 174 }
173} 175}
174 176
175static void tx4938ide_input_data_swap(ide_drive_t *drive, struct request *rq, 177static void tx4938ide_input_data_swap(ide_drive_t *drive, struct ide_cmd *cmd,
176 void *buf, unsigned int len) 178 void *buf, unsigned int len)
177{ 179{
178 unsigned long port = drive->hwif->io_ports.data_addr; 180 unsigned long port = drive->hwif->io_ports.data_addr;
@@ -184,7 +186,7 @@ static void tx4938ide_input_data_swap(ide_drive_t *drive, struct request *rq,
184 __ide_flush_dcache_range((unsigned long)buf, roundup(len, 2)); 186 __ide_flush_dcache_range((unsigned long)buf, roundup(len, 2));
185} 187}
186 188
187static void tx4938ide_output_data_swap(ide_drive_t *drive, struct request *rq, 189static void tx4938ide_output_data_swap(ide_drive_t *drive, struct ide_cmd *cmd,
188 void *buf, unsigned int len) 190 void *buf, unsigned int len)
189{ 191{
190 unsigned long port = drive->hwif->io_ports.data_addr; 192 unsigned long port = drive->hwif->io_ports.data_addr;
diff --git a/drivers/ide/tx4939ide.c b/drivers/ide/tx4939ide.c
index 40b0812a045c..e0e0a803dde3 100644
--- a/drivers/ide/tx4939ide.c
+++ b/drivers/ide/tx4939ide.c
@@ -18,6 +18,8 @@
18#include <linux/io.h> 18#include <linux/io.h>
19#include <linux/scatterlist.h> 19#include <linux/scatterlist.h>
20 20
21#include <asm/ide.h>
22
21#define MODNAME "tx4939ide" 23#define MODNAME "tx4939ide"
22 24
23/* ATA Shadow Registers (8-bit except for Data which is 16-bit) */ 25/* ATA Shadow Registers (8-bit except for Data which is 16-bit) */
@@ -230,7 +232,7 @@ static u8 tx4939ide_clear_dma_status(void __iomem *base)
230 232
231#ifdef __BIG_ENDIAN 233#ifdef __BIG_ENDIAN
232/* custom ide_build_dmatable to handle swapped layout */ 234/* custom ide_build_dmatable to handle swapped layout */
233static int tx4939ide_build_dmatable(ide_drive_t *drive, struct request *rq) 235static int tx4939ide_build_dmatable(ide_drive_t *drive, struct ide_cmd *cmd)
234{ 236{
235 ide_hwif_t *hwif = drive->hwif; 237 ide_hwif_t *hwif = drive->hwif;
236 u32 *table = (u32 *)hwif->dmatable_cpu; 238 u32 *table = (u32 *)hwif->dmatable_cpu;
@@ -238,11 +240,7 @@ static int tx4939ide_build_dmatable(ide_drive_t *drive, struct request *rq)
238 int i; 240 int i;
239 struct scatterlist *sg; 241 struct scatterlist *sg;
240 242
241 hwif->sg_nents = ide_build_sglist(drive, rq); 243 for_each_sg(hwif->sg_table, sg, cmd->sg_nents, i) {
242 if (hwif->sg_nents == 0)
243 return 0;
244
245 for_each_sg(hwif->sg_table, sg, hwif->sg_nents, i) {
246 u32 cur_addr, cur_len, bcount; 244 u32 cur_addr, cur_len, bcount;
247 245
248 cur_addr = sg_dma_address(sg); 246 cur_addr = sg_dma_address(sg);
@@ -289,23 +287,15 @@ use_pio_instead:
289#define tx4939ide_build_dmatable ide_build_dmatable 287#define tx4939ide_build_dmatable ide_build_dmatable
290#endif 288#endif
291 289
292static int tx4939ide_dma_setup(ide_drive_t *drive) 290static int tx4939ide_dma_setup(ide_drive_t *drive, struct ide_cmd *cmd)
293{ 291{
294 ide_hwif_t *hwif = drive->hwif; 292 ide_hwif_t *hwif = drive->hwif;
295 void __iomem *base = TX4939IDE_BASE(hwif); 293 void __iomem *base = TX4939IDE_BASE(hwif);
296 struct request *rq = hwif->rq; 294 u8 rw = (cmd->tf_flags & IDE_TFLAG_WRITE) ? 0 : ATA_DMA_WR;
297 u8 reading;
298 int nent;
299
300 if (rq_data_dir(rq))
301 reading = 0;
302 else
303 reading = ATA_DMA_WR;
304 295
305 /* fall back to PIO! */ 296 /* fall back to PIO! */
306 nent = tx4939ide_build_dmatable(drive, rq); 297 if (tx4939ide_build_dmatable(drive, cmd) == 0) {
307 if (!nent) { 298 ide_map_sg(drive, cmd);
308 ide_map_sg(drive, rq);
309 return 1; 299 return 1;
310 } 300 }
311 301
@@ -313,7 +303,7 @@ static int tx4939ide_dma_setup(ide_drive_t *drive)
313 tx4939ide_writel(hwif->dmatable_dma, base, TX4939IDE_PRD_Ptr); 303 tx4939ide_writel(hwif->dmatable_dma, base, TX4939IDE_PRD_Ptr);
314 304
315 /* specify r/w */ 305 /* specify r/w */
316 tx4939ide_writeb(reading, base, TX4939IDE_DMA_Cmd); 306 tx4939ide_writeb(rw, base, TX4939IDE_DMA_Cmd);
317 307
318 /* clear INTR & ERROR flags */ 308 /* clear INTR & ERROR flags */
319 tx4939ide_clear_dma_status(base); 309 tx4939ide_clear_dma_status(base);
@@ -322,7 +312,9 @@ static int tx4939ide_dma_setup(ide_drive_t *drive)
322 312
323 tx4939ide_writew(SECTOR_SIZE / 2, base, drive->dn ? 313 tx4939ide_writew(SECTOR_SIZE / 2, base, drive->dn ?
324 TX4939IDE_Xfer_Cnt_2 : TX4939IDE_Xfer_Cnt_1); 314 TX4939IDE_Xfer_Cnt_2 : TX4939IDE_Xfer_Cnt_1);
325 tx4939ide_writew(rq->nr_sectors, base, TX4939IDE_Sec_Cnt); 315
316 tx4939ide_writew(cmd->rq->nr_sectors, base, TX4939IDE_Sec_Cnt);
317
326 return 0; 318 return 0;
327} 319}
328 320
@@ -437,7 +429,7 @@ static int tx4939ide_init_dma(ide_hwif_t *hwif, const struct ide_port_info *d)
437 return ide_allocate_dma_engine(hwif); 429 return ide_allocate_dma_engine(hwif);
438} 430}
439 431
440static void tx4939ide_tf_load_fixup(ide_drive_t *drive, ide_task_t *task) 432static void tx4939ide_tf_load_fixup(ide_drive_t *drive)
441{ 433{
442 ide_hwif_t *hwif = drive->hwif; 434 ide_hwif_t *hwif = drive->hwif;
443 void __iomem *base = TX4939IDE_BASE(hwif); 435 void __iomem *base = TX4939IDE_BASE(hwif);
@@ -465,59 +457,59 @@ static void tx4939ide_outb(u8 value, unsigned long port)
465 __raw_writeb(value, (void __iomem *)port); 457 __raw_writeb(value, (void __iomem *)port);
466} 458}
467 459
468static void tx4939ide_tf_load(ide_drive_t *drive, ide_task_t *task) 460static void tx4939ide_tf_load(ide_drive_t *drive, struct ide_cmd *cmd)
469{ 461{
470 ide_hwif_t *hwif = drive->hwif; 462 ide_hwif_t *hwif = drive->hwif;
471 struct ide_io_ports *io_ports = &hwif->io_ports; 463 struct ide_io_ports *io_ports = &hwif->io_ports;
472 struct ide_taskfile *tf = &task->tf; 464 struct ide_taskfile *tf = &cmd->tf;
473 u8 HIHI = task->tf_flags & IDE_TFLAG_LBA48 ? 0xE0 : 0xEF; 465 u8 HIHI = cmd->tf_flags & IDE_TFLAG_LBA48 ? 0xE0 : 0xEF;
474 466
475 if (task->tf_flags & IDE_TFLAG_FLAGGED) 467 if (cmd->ftf_flags & IDE_FTFLAG_FLAGGED)
476 HIHI = 0xFF; 468 HIHI = 0xFF;
477 469
478 if (task->tf_flags & IDE_TFLAG_OUT_DATA) { 470 if (cmd->ftf_flags & IDE_FTFLAG_OUT_DATA) {
479 u16 data = (tf->hob_data << 8) | tf->data; 471 u16 data = (tf->hob_data << 8) | tf->data;
480 472
481 /* no endian swap */ 473 /* no endian swap */
482 __raw_writew(data, (void __iomem *)io_ports->data_addr); 474 __raw_writew(data, (void __iomem *)io_ports->data_addr);
483 } 475 }
484 476
485 if (task->tf_flags & IDE_TFLAG_OUT_HOB_FEATURE) 477 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_FEATURE)
486 tx4939ide_outb(tf->hob_feature, io_ports->feature_addr); 478 tx4939ide_outb(tf->hob_feature, io_ports->feature_addr);
487 if (task->tf_flags & IDE_TFLAG_OUT_HOB_NSECT) 479 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_NSECT)
488 tx4939ide_outb(tf->hob_nsect, io_ports->nsect_addr); 480 tx4939ide_outb(tf->hob_nsect, io_ports->nsect_addr);
489 if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAL) 481 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_LBAL)
490 tx4939ide_outb(tf->hob_lbal, io_ports->lbal_addr); 482 tx4939ide_outb(tf->hob_lbal, io_ports->lbal_addr);
491 if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAM) 483 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_LBAM)
492 tx4939ide_outb(tf->hob_lbam, io_ports->lbam_addr); 484 tx4939ide_outb(tf->hob_lbam, io_ports->lbam_addr);
493 if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAH) 485 if (cmd->tf_flags & IDE_TFLAG_OUT_HOB_LBAH)
494 tx4939ide_outb(tf->hob_lbah, io_ports->lbah_addr); 486 tx4939ide_outb(tf->hob_lbah, io_ports->lbah_addr);
495 487
496 if (task->tf_flags & IDE_TFLAG_OUT_FEATURE) 488 if (cmd->tf_flags & IDE_TFLAG_OUT_FEATURE)
497 tx4939ide_outb(tf->feature, io_ports->feature_addr); 489 tx4939ide_outb(tf->feature, io_ports->feature_addr);
498 if (task->tf_flags & IDE_TFLAG_OUT_NSECT) 490 if (cmd->tf_flags & IDE_TFLAG_OUT_NSECT)
499 tx4939ide_outb(tf->nsect, io_ports->nsect_addr); 491 tx4939ide_outb(tf->nsect, io_ports->nsect_addr);
500 if (task->tf_flags & IDE_TFLAG_OUT_LBAL) 492 if (cmd->tf_flags & IDE_TFLAG_OUT_LBAL)
501 tx4939ide_outb(tf->lbal, io_ports->lbal_addr); 493 tx4939ide_outb(tf->lbal, io_ports->lbal_addr);
502 if (task->tf_flags & IDE_TFLAG_OUT_LBAM) 494 if (cmd->tf_flags & IDE_TFLAG_OUT_LBAM)
503 tx4939ide_outb(tf->lbam, io_ports->lbam_addr); 495 tx4939ide_outb(tf->lbam, io_ports->lbam_addr);
504 if (task->tf_flags & IDE_TFLAG_OUT_LBAH) 496 if (cmd->tf_flags & IDE_TFLAG_OUT_LBAH)
505 tx4939ide_outb(tf->lbah, io_ports->lbah_addr); 497 tx4939ide_outb(tf->lbah, io_ports->lbah_addr);
506 498
507 if (task->tf_flags & IDE_TFLAG_OUT_DEVICE) { 499 if (cmd->tf_flags & IDE_TFLAG_OUT_DEVICE) {
508 tx4939ide_outb((tf->device & HIHI) | drive->select, 500 tx4939ide_outb((tf->device & HIHI) | drive->select,
509 io_ports->device_addr); 501 io_ports->device_addr);
510 tx4939ide_tf_load_fixup(drive, task); 502 tx4939ide_tf_load_fixup(drive);
511 } 503 }
512} 504}
513 505
514static void tx4939ide_tf_read(ide_drive_t *drive, ide_task_t *task) 506static void tx4939ide_tf_read(ide_drive_t *drive, struct ide_cmd *cmd)
515{ 507{
516 ide_hwif_t *hwif = drive->hwif; 508 ide_hwif_t *hwif = drive->hwif;
517 struct ide_io_ports *io_ports = &hwif->io_ports; 509 struct ide_io_ports *io_ports = &hwif->io_ports;
518 struct ide_taskfile *tf = &task->tf; 510 struct ide_taskfile *tf = &cmd->tf;
519 511
520 if (task->tf_flags & IDE_TFLAG_IN_DATA) { 512 if (cmd->ftf_flags & IDE_FTFLAG_IN_DATA) {
521 u16 data; 513 u16 data;
522 514
523 /* no endian swap */ 515 /* no endian swap */
@@ -529,32 +521,32 @@ static void tx4939ide_tf_read(ide_drive_t *drive, ide_task_t *task)
529 /* be sure we're looking at the low order bits */ 521 /* be sure we're looking at the low order bits */
530 tx4939ide_outb(ATA_DEVCTL_OBS & ~0x80, io_ports->ctl_addr); 522 tx4939ide_outb(ATA_DEVCTL_OBS & ~0x80, io_ports->ctl_addr);
531 523
532 if (task->tf_flags & IDE_TFLAG_IN_FEATURE) 524 if (cmd->tf_flags & IDE_TFLAG_IN_FEATURE)
533 tf->feature = tx4939ide_inb(io_ports->feature_addr); 525 tf->feature = tx4939ide_inb(io_ports->feature_addr);
534 if (task->tf_flags & IDE_TFLAG_IN_NSECT) 526 if (cmd->tf_flags & IDE_TFLAG_IN_NSECT)
535 tf->nsect = tx4939ide_inb(io_ports->nsect_addr); 527 tf->nsect = tx4939ide_inb(io_ports->nsect_addr);
536 if (task->tf_flags & IDE_TFLAG_IN_LBAL) 528 if (cmd->tf_flags & IDE_TFLAG_IN_LBAL)
537 tf->lbal = tx4939ide_inb(io_ports->lbal_addr); 529 tf->lbal = tx4939ide_inb(io_ports->lbal_addr);
538 if (task->tf_flags & IDE_TFLAG_IN_LBAM) 530 if (cmd->tf_flags & IDE_TFLAG_IN_LBAM)
539 tf->lbam = tx4939ide_inb(io_ports->lbam_addr); 531 tf->lbam = tx4939ide_inb(io_ports->lbam_addr);
540 if (task->tf_flags & IDE_TFLAG_IN_LBAH) 532 if (cmd->tf_flags & IDE_TFLAG_IN_LBAH)
541 tf->lbah = tx4939ide_inb(io_ports->lbah_addr); 533 tf->lbah = tx4939ide_inb(io_ports->lbah_addr);
542 if (task->tf_flags & IDE_TFLAG_IN_DEVICE) 534 if (cmd->tf_flags & IDE_TFLAG_IN_DEVICE)
543 tf->device = tx4939ide_inb(io_ports->device_addr); 535 tf->device = tx4939ide_inb(io_ports->device_addr);
544 536
545 if (task->tf_flags & IDE_TFLAG_LBA48) { 537 if (cmd->tf_flags & IDE_TFLAG_LBA48) {
546 tx4939ide_outb(ATA_DEVCTL_OBS | 0x80, io_ports->ctl_addr); 538 tx4939ide_outb(ATA_DEVCTL_OBS | 0x80, io_ports->ctl_addr);
547 539
548 if (task->tf_flags & IDE_TFLAG_IN_HOB_FEATURE) 540 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_FEATURE)
549 tf->hob_feature = 541 tf->hob_feature =
550 tx4939ide_inb(io_ports->feature_addr); 542 tx4939ide_inb(io_ports->feature_addr);
551 if (task->tf_flags & IDE_TFLAG_IN_HOB_NSECT) 543 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_NSECT)
552 tf->hob_nsect = tx4939ide_inb(io_ports->nsect_addr); 544 tf->hob_nsect = tx4939ide_inb(io_ports->nsect_addr);
553 if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAL) 545 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAL)
554 tf->hob_lbal = tx4939ide_inb(io_ports->lbal_addr); 546 tf->hob_lbal = tx4939ide_inb(io_ports->lbal_addr);
555 if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAM) 547 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAM)
556 tf->hob_lbam = tx4939ide_inb(io_ports->lbam_addr); 548 tf->hob_lbam = tx4939ide_inb(io_ports->lbam_addr);
557 if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAH) 549 if (cmd->tf_flags & IDE_TFLAG_IN_HOB_LBAH)
558 tf->hob_lbah = tx4939ide_inb(io_ports->lbah_addr); 550 tf->hob_lbah = tx4939ide_inb(io_ports->lbah_addr);
559 } 551 }
560} 552}
@@ -601,11 +593,12 @@ static const struct ide_tp_ops tx4939ide_tp_ops = {
601 593
602#else /* __LITTLE_ENDIAN */ 594#else /* __LITTLE_ENDIAN */
603 595
604static void tx4939ide_tf_load(ide_drive_t *drive, ide_task_t *task) 596static void tx4939ide_tf_load(ide_drive_t *drive, struct ide_cmd *cmd)
605{ 597{
606 ide_tf_load(drive, task); 598 ide_tf_load(drive, cmd);
607 if (task->tf_flags & IDE_TFLAG_OUT_DEVICE) 599
608 tx4939ide_tf_load_fixup(drive, task); 600 if (cmd->tf_flags & IDE_TFLAG_OUT_DEVICE)
601 tx4939ide_tf_load_fixup(drive);
609} 602}
610 603
611static const struct ide_tp_ops tx4939ide_tp_ops = { 604static const struct ide_tp_ops tx4939ide_tp_ops = {
@@ -634,11 +627,11 @@ static const struct ide_port_ops tx4939ide_port_ops = {
634static const struct ide_dma_ops tx4939ide_dma_ops = { 627static const struct ide_dma_ops tx4939ide_dma_ops = {
635 .dma_host_set = tx4939ide_dma_host_set, 628 .dma_host_set = tx4939ide_dma_host_set,
636 .dma_setup = tx4939ide_dma_setup, 629 .dma_setup = tx4939ide_dma_setup,
637 .dma_exec_cmd = ide_dma_exec_cmd,
638 .dma_start = ide_dma_start, 630 .dma_start = ide_dma_start,
639 .dma_end = tx4939ide_dma_end, 631 .dma_end = tx4939ide_dma_end,
640 .dma_test_irq = tx4939ide_dma_test_irq, 632 .dma_test_irq = tx4939ide_dma_test_irq,
641 .dma_lost_irq = ide_dma_lost_irq, 633 .dma_lost_irq = ide_dma_lost_irq,
634 .dma_timer_expiry = ide_dma_sff_timer_expiry,
642 .dma_timeout = ide_dma_timeout, 635 .dma_timeout = ide_dma_timeout,
643 .dma_sff_read_status = tx4939ide_dma_sff_read_status, 636 .dma_sff_read_status = tx4939ide_dma_sff_read_status,
644}; 637};
diff --git a/drivers/macintosh/therm_adt746x.c b/drivers/macintosh/therm_adt746x.c
index 82607add69a9..c0621d50c8a0 100644
--- a/drivers/macintosh/therm_adt746x.c
+++ b/drivers/macintosh/therm_adt746x.c
@@ -498,8 +498,8 @@ static ssize_t store_##name(struct device *dev, struct device_attribute *attr, c
498#define BUILD_STORE_FUNC_INT(name, data) \ 498#define BUILD_STORE_FUNC_INT(name, data) \
499static ssize_t store_##name(struct device *dev, struct device_attribute *attr, const char *buf, size_t n) \ 499static ssize_t store_##name(struct device *dev, struct device_attribute *attr, const char *buf, size_t n) \
500{ \ 500{ \
501 u32 val; \ 501 int val; \
502 val = simple_strtoul(buf, NULL, 10); \ 502 val = simple_strtol(buf, NULL, 10); \
503 if (val < 0 || val > 255) \ 503 if (val < 0 || val > 255) \
504 return -EINVAL; \ 504 return -EINVAL; \
505 printk(KERN_INFO "Setting specified fan speed to %d\n", val); \ 505 printk(KERN_INFO "Setting specified fan speed to %d\n", val); \
diff --git a/drivers/media/Kconfig b/drivers/media/Kconfig
index 93ea201f426c..223c36ede5ae 100644
--- a/drivers/media/Kconfig
+++ b/drivers/media/Kconfig
@@ -117,7 +117,7 @@ source "drivers/media/dvb/Kconfig"
117config DAB 117config DAB
118 boolean "DAB adapters" 118 boolean "DAB adapters"
119 ---help--- 119 ---help---
120 Allow selecting support for for Digital Audio Broadcasting (DAB) 120 Allow selecting support for Digital Audio Broadcasting (DAB)
121 Receiver adapters. 121 Receiver adapters.
122 122
123if DAB 123if DAB
diff --git a/drivers/media/common/ir-keymaps.c b/drivers/media/common/ir-keymaps.c
index d8229a0e9a9c..3fe158ac7bbf 100644
--- a/drivers/media/common/ir-keymaps.c
+++ b/drivers/media/common/ir-keymaps.c
@@ -153,6 +153,65 @@ IR_KEYTAB_TYPE ir_codes_avermedia_m135a[IR_KEYTAB_SIZE] = {
153}; 153};
154EXPORT_SYMBOL_GPL(ir_codes_avermedia_m135a); 154EXPORT_SYMBOL_GPL(ir_codes_avermedia_m135a);
155 155
156/* Oldrich Jedlicka <oldium.pro@seznam.cz> */
157IR_KEYTAB_TYPE ir_codes_avermedia_cardbus[IR_KEYTAB_SIZE] = {
158 [0x00] = KEY_POWER,
159 [0x01] = KEY_TUNER, /* TV/FM */
160 [0x03] = KEY_TEXT, /* Teletext */
161 [0x04] = KEY_EPG,
162 [0x05] = KEY_1,
163 [0x06] = KEY_2,
164 [0x07] = KEY_3,
165 [0x08] = KEY_AUDIO,
166 [0x09] = KEY_4,
167 [0x0a] = KEY_5,
168 [0x0b] = KEY_6,
169 [0x0c] = KEY_ZOOM, /* Full screen */
170 [0x0d] = KEY_7,
171 [0x0e] = KEY_8,
172 [0x0f] = KEY_9,
173 [0x10] = KEY_PAGEUP, /* 16-CH PREV */
174 [0x11] = KEY_0,
175 [0x12] = KEY_INFO,
176 [0x13] = KEY_AGAIN, /* CH RTN - channel return */
177 [0x14] = KEY_MUTE,
178 [0x15] = KEY_EDIT, /* Autoscan */
179 [0x17] = KEY_SAVE, /* Screenshot */
180 [0x18] = KEY_PLAYPAUSE,
181 [0x19] = KEY_RECORD,
182 [0x1a] = KEY_PLAY,
183 [0x1b] = KEY_STOP,
184 [0x1c] = KEY_FASTFORWARD,
185 [0x1d] = KEY_REWIND,
186 [0x1e] = KEY_VOLUMEDOWN,
187 [0x1f] = KEY_VOLUMEUP,
188 [0x22] = KEY_SLEEP, /* Sleep */
189 [0x23] = KEY_ZOOM, /* Aspect */
190 [0x26] = KEY_SCREEN, /* Pos */
191 [0x27] = KEY_ANGLE, /* Size */
192 [0x28] = KEY_SELECT, /* Select */
193 [0x29] = KEY_BLUE, /* Blue/Picture */
194 [0x2a] = KEY_BACKSPACE, /* Back */
195 [0x2b] = KEY_MEDIA, /* PIP (Picture-in-picture) */
196 [0x2c] = KEY_DOWN,
197 [0x2e] = KEY_DOT,
198 [0x2f] = KEY_TV, /* Live TV */
199 [0x32] = KEY_LEFT,
200 [0x33] = KEY_CLEAR, /* Clear */
201 [0x35] = KEY_RED, /* Red/TV */
202 [0x36] = KEY_UP,
203 [0x37] = KEY_HOME, /* Home */
204 [0x39] = KEY_GREEN, /* Green/Video */
205 [0x3d] = KEY_YELLOW, /* Yellow/Music */
206 [0x3e] = KEY_OK, /* Ok */
207 [0x3f] = KEY_RIGHT,
208 [0x40] = KEY_NEXT, /* Next */
209 [0x41] = KEY_PREVIOUS, /* Previous */
210 [0x42] = KEY_CHANNELDOWN, /* Channel down */
211 [0x43] = KEY_CHANNELUP /* Channel up */
212};
213EXPORT_SYMBOL_GPL(ir_codes_avermedia_cardbus);
214
156/* Attila Kondoros <attila.kondoros@chello.hu> */ 215/* Attila Kondoros <attila.kondoros@chello.hu> */
157IR_KEYTAB_TYPE ir_codes_apac_viewcomp[IR_KEYTAB_SIZE] = { 216IR_KEYTAB_TYPE ir_codes_apac_viewcomp[IR_KEYTAB_SIZE] = {
158 217
@@ -2452,6 +2511,55 @@ IR_KEYTAB_TYPE ir_codes_kworld_plus_tv_analog[IR_KEYTAB_SIZE] = {
2452}; 2511};
2453EXPORT_SYMBOL_GPL(ir_codes_kworld_plus_tv_analog); 2512EXPORT_SYMBOL_GPL(ir_codes_kworld_plus_tv_analog);
2454 2513
2514/* Kaiomy TVnPC U2
2515 Mauro Carvalho Chehab <mchehab@infradead.org>
2516 */
2517IR_KEYTAB_TYPE ir_codes_kaiomy[IR_KEYTAB_SIZE] = {
2518 [0x43] = KEY_POWER2,
2519 [0x01] = KEY_LIST,
2520 [0x0b] = KEY_ZOOM,
2521 [0x03] = KEY_POWER,
2522
2523 [0x04] = KEY_1,
2524 [0x08] = KEY_2,
2525 [0x02] = KEY_3,
2526
2527 [0x0f] = KEY_4,
2528 [0x05] = KEY_5,
2529 [0x06] = KEY_6,
2530
2531 [0x0c] = KEY_7,
2532 [0x0d] = KEY_8,
2533 [0x0a] = KEY_9,
2534
2535 [0x11] = KEY_0,
2536
2537 [0x09] = KEY_CHANNELUP,
2538 [0x07] = KEY_CHANNELDOWN,
2539
2540 [0x0e] = KEY_VOLUMEUP,
2541 [0x13] = KEY_VOLUMEDOWN,
2542
2543 [0x10] = KEY_HOME,
2544 [0x12] = KEY_ENTER,
2545
2546 [0x14] = KEY_RECORD,
2547 [0x15] = KEY_STOP,
2548 [0x16] = KEY_PLAY,
2549 [0x17] = KEY_MUTE,
2550
2551 [0x18] = KEY_UP,
2552 [0x19] = KEY_DOWN,
2553 [0x1a] = KEY_LEFT,
2554 [0x1b] = KEY_RIGHT,
2555
2556 [0x1c] = KEY_RED,
2557 [0x1d] = KEY_GREEN,
2558 [0x1e] = KEY_YELLOW,
2559 [0x1f] = KEY_BLUE,
2560};
2561EXPORT_SYMBOL_GPL(ir_codes_kaiomy);
2562
2455IR_KEYTAB_TYPE ir_codes_avermedia_a16d[IR_KEYTAB_SIZE] = { 2563IR_KEYTAB_TYPE ir_codes_avermedia_a16d[IR_KEYTAB_SIZE] = {
2456 [0x20] = KEY_LIST, 2564 [0x20] = KEY_LIST,
2457 [0x00] = KEY_POWER, 2565 [0x00] = KEY_POWER,
@@ -2604,3 +2712,41 @@ IR_KEYTAB_TYPE ir_codes_ati_tv_wonder_hd_600[IR_KEYTAB_SIZE] = {
2604}; 2712};
2605 2713
2606EXPORT_SYMBOL_GPL(ir_codes_ati_tv_wonder_hd_600); 2714EXPORT_SYMBOL_GPL(ir_codes_ati_tv_wonder_hd_600);
2715
2716/* DVBWorld remotes
2717 Igor M. Liplianin <liplianin@me.by>
2718 */
2719IR_KEYTAB_TYPE ir_codes_dm1105_nec[IR_KEYTAB_SIZE] = {
2720 [0x0a] = KEY_Q, /*power*/
2721 [0x0c] = KEY_M, /*mute*/
2722 [0x11] = KEY_1,
2723 [0x12] = KEY_2,
2724 [0x13] = KEY_3,
2725 [0x14] = KEY_4,
2726 [0x15] = KEY_5,
2727 [0x16] = KEY_6,
2728 [0x17] = KEY_7,
2729 [0x18] = KEY_8,
2730 [0x19] = KEY_9,
2731 [0x10] = KEY_0,
2732 [0x1c] = KEY_PAGEUP, /*ch+*/
2733 [0x0f] = KEY_PAGEDOWN, /*ch-*/
2734 [0x1a] = KEY_O, /*vol+*/
2735 [0x0e] = KEY_Z, /*vol-*/
2736 [0x04] = KEY_R, /*rec*/
2737 [0x09] = KEY_D, /*fav*/
2738 [0x08] = KEY_BACKSPACE, /*rewind*/
2739 [0x07] = KEY_A, /*fast*/
2740 [0x0b] = KEY_P, /*pause*/
2741 [0x02] = KEY_ESC, /*cancel*/
2742 [0x03] = KEY_G, /*tab*/
2743 [0x00] = KEY_UP, /*up*/
2744 [0x1f] = KEY_ENTER, /*ok*/
2745 [0x01] = KEY_DOWN, /*down*/
2746 [0x05] = KEY_C, /*cap*/
2747 [0x06] = KEY_S, /*stop*/
2748 [0x40] = KEY_F, /*full*/
2749 [0x1e] = KEY_W, /*tvmode*/
2750 [0x1b] = KEY_B, /*recall*/
2751};
2752EXPORT_SYMBOL_GPL(ir_codes_dm1105_nec);
diff --git a/drivers/media/common/saa7146_core.c b/drivers/media/common/saa7146_core.c
index d599d360da3f..982f000a57ff 100644
--- a/drivers/media/common/saa7146_core.c
+++ b/drivers/media/common/saa7146_core.c
@@ -452,8 +452,6 @@ static int saa7146_init_one(struct pci_dev *pci, const struct pci_device_id *ent
452 INFO(("found saa7146 @ mem %p (revision %d, irq %d) (0x%04x,0x%04x).\n", dev->mem, dev->revision, pci->irq, pci->subsystem_vendor, pci->subsystem_device)); 452 INFO(("found saa7146 @ mem %p (revision %d, irq %d) (0x%04x,0x%04x).\n", dev->mem, dev->revision, pci->irq, pci->subsystem_vendor, pci->subsystem_device));
453 dev->ext = ext; 453 dev->ext = ext;
454 454
455 pci_set_drvdata(pci, dev);
456
457 mutex_init(&dev->lock); 455 mutex_init(&dev->lock);
458 spin_lock_init(&dev->int_slock); 456 spin_lock_init(&dev->int_slock);
459 spin_lock_init(&dev->slock); 457 spin_lock_init(&dev->slock);
@@ -477,8 +475,12 @@ static int saa7146_init_one(struct pci_dev *pci, const struct pci_device_id *ent
477 475
478 if (ext->attach(dev, pci_ext)) { 476 if (ext->attach(dev, pci_ext)) {
479 DEB_D(("ext->attach() failed for %p. skipping device.\n",dev)); 477 DEB_D(("ext->attach() failed for %p. skipping device.\n",dev));
480 goto err_unprobe; 478 goto err_free_i2c;
481 } 479 }
480 /* V4L extensions will set the pci drvdata to the v4l2_device in the
481 attach() above. So for those cards that do not use V4L we have to
482 set it explicitly. */
483 pci_set_drvdata(pci, &dev->v4l2_dev);
482 484
483 INIT_LIST_HEAD(&dev->item); 485 INIT_LIST_HEAD(&dev->item);
484 list_add_tail(&dev->item,&saa7146_devices); 486 list_add_tail(&dev->item,&saa7146_devices);
@@ -488,8 +490,6 @@ static int saa7146_init_one(struct pci_dev *pci, const struct pci_device_id *ent
488out: 490out:
489 return err; 491 return err;
490 492
491err_unprobe:
492 pci_set_drvdata(pci, NULL);
493err_free_i2c: 493err_free_i2c:
494 pci_free_consistent(pci, SAA7146_RPS_MEM, dev->d_i2c.cpu_addr, 494 pci_free_consistent(pci, SAA7146_RPS_MEM, dev->d_i2c.cpu_addr,
495 dev->d_i2c.dma_handle); 495 dev->d_i2c.dma_handle);
@@ -514,7 +514,8 @@ err_free:
514 514
515static void saa7146_remove_one(struct pci_dev *pdev) 515static void saa7146_remove_one(struct pci_dev *pdev)
516{ 516{
517 struct saa7146_dev* dev = pci_get_drvdata(pdev); 517 struct v4l2_device *v4l2_dev = pci_get_drvdata(pdev);
518 struct saa7146_dev *dev = to_saa7146_dev(v4l2_dev);
518 struct { 519 struct {
519 void *addr; 520 void *addr;
520 dma_addr_t dma; 521 dma_addr_t dma;
@@ -528,6 +529,8 @@ static void saa7146_remove_one(struct pci_dev *pdev)
528 DEB_EE(("dev:%p\n",dev)); 529 DEB_EE(("dev:%p\n",dev));
529 530
530 dev->ext->detach(dev); 531 dev->ext->detach(dev);
532 /* Zero the PCI drvdata after use. */
533 pci_set_drvdata(pdev, NULL);
531 534
532 /* shut down all video dma transfers */ 535 /* shut down all video dma transfers */
533 saa7146_write(dev, MC1, 0x00ff0000); 536 saa7146_write(dev, MC1, 0x00ff0000);
diff --git a/drivers/media/common/saa7146_fops.c b/drivers/media/common/saa7146_fops.c
index cf06f4d10ad4..620f655fa9c5 100644
--- a/drivers/media/common/saa7146_fops.c
+++ b/drivers/media/common/saa7146_fops.c
@@ -308,14 +308,6 @@ static int fops_release(struct file *file)
308 return 0; 308 return 0;
309} 309}
310 310
311static long fops_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
312{
313/*
314 DEB_EE(("file:%p, cmd:%d, arg:%li\n", file, cmd, arg));
315*/
316 return video_usercopy(file, cmd, arg, saa7146_video_do_ioctl);
317}
318
319static int fops_mmap(struct file *file, struct vm_area_struct * vma) 311static int fops_mmap(struct file *file, struct vm_area_struct * vma)
320{ 312{
321 struct saa7146_fh *fh = file->private_data; 313 struct saa7146_fh *fh = file->private_data;
@@ -425,7 +417,7 @@ static const struct v4l2_file_operations video_fops =
425 .write = fops_write, 417 .write = fops_write,
426 .poll = fops_poll, 418 .poll = fops_poll,
427 .mmap = fops_mmap, 419 .mmap = fops_mmap,
428 .ioctl = fops_ioctl, 420 .ioctl = video_ioctl2,
429}; 421};
430 422
431static void vv_callback(struct saa7146_dev *dev, unsigned long status) 423static void vv_callback(struct saa7146_dev *dev, unsigned long status)
@@ -452,19 +444,22 @@ static void vv_callback(struct saa7146_dev *dev, unsigned long status)
452 } 444 }
453} 445}
454 446
455static struct video_device device_template =
456{
457 .fops = &video_fops,
458 .minor = -1,
459};
460
461int saa7146_vv_init(struct saa7146_dev* dev, struct saa7146_ext_vv *ext_vv) 447int saa7146_vv_init(struct saa7146_dev* dev, struct saa7146_ext_vv *ext_vv)
462{ 448{
463 struct saa7146_vv *vv = kzalloc (sizeof(struct saa7146_vv),GFP_KERNEL); 449 struct saa7146_vv *vv;
464 if( NULL == vv ) { 450 int err;
451
452 err = v4l2_device_register(&dev->pci->dev, &dev->v4l2_dev);
453 if (err)
454 return err;
455
456 vv = kzalloc(sizeof(struct saa7146_vv), GFP_KERNEL);
457 if (vv == NULL) {
465 ERR(("out of memory. aborting.\n")); 458 ERR(("out of memory. aborting.\n"));
466 return -1; 459 return -ENOMEM;
467 } 460 }
461 ext_vv->ops = saa7146_video_ioctl_ops;
462 ext_vv->core_ops = &saa7146_video_ioctl_ops;
468 463
469 DEB_EE(("dev:%p\n",dev)); 464 DEB_EE(("dev:%p\n",dev));
470 465
@@ -507,6 +502,7 @@ int saa7146_vv_release(struct saa7146_dev* dev)
507 502
508 DEB_EE(("dev:%p\n",dev)); 503 DEB_EE(("dev:%p\n",dev));
509 504
505 v4l2_device_unregister(&dev->v4l2_dev);
510 pci_free_consistent(dev->pci, SAA7146_CLIPPING_MEM, vv->d_clipping.cpu_addr, vv->d_clipping.dma_handle); 506 pci_free_consistent(dev->pci, SAA7146_CLIPPING_MEM, vv->d_clipping.cpu_addr, vv->d_clipping.dma_handle);
511 kfree(vv); 507 kfree(vv);
512 dev->vv_data = NULL; 508 dev->vv_data = NULL;
@@ -521,6 +517,8 @@ int saa7146_register_device(struct video_device **vid, struct saa7146_dev* dev,
521{ 517{
522 struct saa7146_vv *vv = dev->vv_data; 518 struct saa7146_vv *vv = dev->vv_data;
523 struct video_device *vfd; 519 struct video_device *vfd;
520 int err;
521 int i;
524 522
525 DEB_EE(("dev:%p, name:'%s', type:%d\n",dev,name,type)); 523 DEB_EE(("dev:%p, name:'%s', type:%d\n",dev,name,type));
526 524
@@ -529,16 +527,20 @@ int saa7146_register_device(struct video_device **vid, struct saa7146_dev* dev,
529 if (vfd == NULL) 527 if (vfd == NULL)
530 return -ENOMEM; 528 return -ENOMEM;
531 529
532 memcpy(vfd, &device_template, sizeof(struct video_device)); 530 vfd->fops = &video_fops;
533 strlcpy(vfd->name, name, sizeof(vfd->name)); 531 vfd->ioctl_ops = &dev->ext_vv_data->ops;
534 vfd->release = video_device_release; 532 vfd->release = video_device_release;
533 vfd->tvnorms = 0;
534 for (i = 0; i < dev->ext_vv_data->num_stds; i++)
535 vfd->tvnorms |= dev->ext_vv_data->stds[i].id;
536 strlcpy(vfd->name, name, sizeof(vfd->name));
535 video_set_drvdata(vfd, dev); 537 video_set_drvdata(vfd, dev);
536 538
537 // fixme: -1 should be an insmod parameter *for the extension* (like "video_nr"); 539 err = video_register_device(vfd, type, -1);
538 if (video_register_device(vfd, type, -1) < 0) { 540 if (err < 0) {
539 ERR(("cannot register v4l2 device. skipping.\n")); 541 ERR(("cannot register v4l2 device. skipping.\n"));
540 video_device_release(vfd); 542 video_device_release(vfd);
541 return -1; 543 return err;
542 } 544 }
543 545
544 if( VFL_TYPE_GRABBER == type ) { 546 if( VFL_TYPE_GRABBER == type ) {
diff --git a/drivers/media/common/saa7146_i2c.c b/drivers/media/common/saa7146_i2c.c
index c11da4d09cd0..7e8f56815998 100644
--- a/drivers/media/common/saa7146_i2c.c
+++ b/drivers/media/common/saa7146_i2c.c
@@ -293,7 +293,6 @@ static int saa7146_i2c_transfer(struct saa7146_dev *dev, const struct i2c_msg *m
293 int i = 0, count = 0; 293 int i = 0, count = 0;
294 __le32 *buffer = dev->d_i2c.cpu_addr; 294 __le32 *buffer = dev->d_i2c.cpu_addr;
295 int err = 0; 295 int err = 0;
296 int address_err = 0;
297 int short_delay = 0; 296 int short_delay = 0;
298 297
299 if (mutex_lock_interruptible(&dev->i2c_lock)) 298 if (mutex_lock_interruptible(&dev->i2c_lock))
@@ -333,17 +332,10 @@ static int saa7146_i2c_transfer(struct saa7146_dev *dev, const struct i2c_msg *m
333 i2c address probing, however, and address errors indicate that a 332 i2c address probing, however, and address errors indicate that a
334 device is really *not* there. retrying in that case 333 device is really *not* there. retrying in that case
335 increases the time the device needs to probe greatly, so 334 increases the time the device needs to probe greatly, so
336 it should be avoided. because of the fact, that only 335 it should be avoided. So we bail out in irq mode after an
337 analog based cards use irq based i2c transactions (for dvb 336 address error and trust the saa7146 address error detection. */
338 cards, this screwes up other interrupt sources), we bail out 337 if (-EREMOTEIO == err && 0 != (SAA7146_USE_I2C_IRQ & dev->ext->flags))
339 completely for analog cards after an address error and trust 338 goto out;
340 the saa7146 address error detection. */
341 if ( -EREMOTEIO == err ) {
342 if( 0 != (SAA7146_USE_I2C_IRQ & dev->ext->flags)) {
343 goto out;
344 }
345 address_err++;
346 }
347 DEB_I2C(("error while sending message(s). starting again.\n")); 339 DEB_I2C(("error while sending message(s). starting again.\n"));
348 break; 340 break;
349 } 341 }
@@ -358,10 +350,9 @@ static int saa7146_i2c_transfer(struct saa7146_dev *dev, const struct i2c_msg *m
358 350
359 } while (err != num && retries--); 351 } while (err != num && retries--);
360 352
361 /* if every retry had an address error, exit right away */ 353 /* quit if any error occurred */
362 if (address_err == retries) { 354 if (err != num)
363 goto out; 355 goto out;
364 }
365 356
366 /* if any things had to be read, get the results */ 357 /* if any things had to be read, get the results */
367 if ( 0 != saa7146_i2c_msg_cleanup(msgs, num, buffer)) { 358 if ( 0 != saa7146_i2c_msg_cleanup(msgs, num, buffer)) {
@@ -390,7 +381,8 @@ out:
390/* utility functions */ 381/* utility functions */
391static int saa7146_i2c_xfer(struct i2c_adapter* adapter, struct i2c_msg *msg, int num) 382static int saa7146_i2c_xfer(struct i2c_adapter* adapter, struct i2c_msg *msg, int num)
392{ 383{
393 struct saa7146_dev* dev = i2c_get_adapdata(adapter); 384 struct v4l2_device *v4l2_dev = i2c_get_adapdata(adapter);
385 struct saa7146_dev *dev = to_saa7146_dev(v4l2_dev);
394 386
395 /* use helper function to transfer data */ 387 /* use helper function to transfer data */
396 return saa7146_i2c_transfer(dev, msg, num, adapter->retries); 388 return saa7146_i2c_transfer(dev, msg, num, adapter->retries);
@@ -417,9 +409,8 @@ int saa7146_i2c_adapter_prepare(struct saa7146_dev *dev, struct i2c_adapter *i2c
417 dev->i2c_bitrate = bitrate; 409 dev->i2c_bitrate = bitrate;
418 saa7146_i2c_reset(dev); 410 saa7146_i2c_reset(dev);
419 411
420 if( NULL != i2c_adapter ) { 412 if (i2c_adapter) {
421 BUG_ON(!i2c_adapter->class); 413 i2c_set_adapdata(i2c_adapter, &dev->v4l2_dev);
422 i2c_set_adapdata(i2c_adapter,dev);
423 i2c_adapter->dev.parent = &dev->pci->dev; 414 i2c_adapter->dev.parent = &dev->pci->dev;
424 i2c_adapter->algo = &saa7146_algo; 415 i2c_adapter->algo = &saa7146_algo;
425 i2c_adapter->algo_data = NULL; 416 i2c_adapter->algo_data = NULL;
diff --git a/drivers/media/common/saa7146_video.c b/drivers/media/common/saa7146_video.c
index 47fee05eaefb..552dab442d78 100644
--- a/drivers/media/common/saa7146_video.c
+++ b/drivers/media/common/saa7146_video.c
@@ -1,4 +1,5 @@
1#include <media/saa7146_vv.h> 1#include <media/saa7146_vv.h>
2#include <media/v4l2-chip-ident.h>
2 3
3static int max_memory = 32; 4static int max_memory = 32;
4 5
@@ -97,172 +98,13 @@ struct saa7146_format* format_by_fourcc(struct saa7146_dev *dev, int fourcc)
97 return NULL; 98 return NULL;
98} 99}
99 100
100static int g_fmt(struct saa7146_fh *fh, struct v4l2_format *f) 101static int vidioc_try_fmt_vid_overlay(struct file *file, void *fh, struct v4l2_format *f);
101{
102 struct saa7146_dev *dev = fh->dev;
103 DEB_EE(("dev:%p, fh:%p\n",dev,fh));
104
105 switch (f->type) {
106 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
107 f->fmt.pix = fh->video_fmt;
108 return 0;
109 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
110 f->fmt.win = fh->ov.win;
111 return 0;
112 case V4L2_BUF_TYPE_VBI_CAPTURE:
113 {
114 f->fmt.vbi = fh->vbi_fmt;
115 return 0;
116 }
117 default:
118 DEB_D(("invalid format type '%d'.\n",f->type));
119 return -EINVAL;
120 }
121}
122
123static int try_win(struct saa7146_dev *dev, struct v4l2_window *win)
124{
125 struct saa7146_vv *vv = dev->vv_data;
126 enum v4l2_field field;
127 int maxw, maxh;
128
129 DEB_EE(("dev:%p\n",dev));
130
131 if (NULL == vv->ov_fb.base) {
132 DEB_D(("no fb base set.\n"));
133 return -EINVAL;
134 }
135 if (NULL == vv->ov_fmt) {
136 DEB_D(("no fb fmt set.\n"));
137 return -EINVAL;
138 }
139 if (win->w.width < 48 || win->w.height < 32) {
140 DEB_D(("min width/height. (%d,%d)\n",win->w.width,win->w.height));
141 return -EINVAL;
142 }
143 if (win->clipcount > 16) {
144 DEB_D(("clipcount too big.\n"));
145 return -EINVAL;
146 }
147
148 field = win->field;
149 maxw = vv->standard->h_max_out;
150 maxh = vv->standard->v_max_out;
151
152 if (V4L2_FIELD_ANY == field) {
153 field = (win->w.height > maxh/2)
154 ? V4L2_FIELD_INTERLACED
155 : V4L2_FIELD_TOP;
156 }
157 switch (field) {
158 case V4L2_FIELD_TOP:
159 case V4L2_FIELD_BOTTOM:
160 case V4L2_FIELD_ALTERNATE:
161 maxh = maxh / 2;
162 break;
163 case V4L2_FIELD_INTERLACED:
164 break;
165 default: {
166 DEB_D(("no known field mode '%d'.\n",field));
167 return -EINVAL;
168 }
169 }
170
171 win->field = field;
172 if (win->w.width > maxw)
173 win->w.width = maxw;
174 if (win->w.height > maxh)
175 win->w.height = maxh;
176
177 return 0;
178}
179
180static int try_fmt(struct saa7146_fh *fh, struct v4l2_format *f)
181{
182 struct saa7146_dev *dev = fh->dev;
183 struct saa7146_vv *vv = dev->vv_data;
184 int err;
185
186 switch (f->type) {
187 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
188 {
189 struct saa7146_format *fmt;
190 enum v4l2_field field;
191 int maxw, maxh;
192 int calc_bpl;
193
194 DEB_EE(("V4L2_BUF_TYPE_VIDEO_CAPTURE: dev:%p, fh:%p\n",dev,fh));
195
196 fmt = format_by_fourcc(dev,f->fmt.pix.pixelformat);
197 if (NULL == fmt) {
198 return -EINVAL;
199 }
200
201 field = f->fmt.pix.field;
202 maxw = vv->standard->h_max_out;
203 maxh = vv->standard->v_max_out;
204
205 if (V4L2_FIELD_ANY == field) {
206 field = (f->fmt.pix.height > maxh/2)
207 ? V4L2_FIELD_INTERLACED
208 : V4L2_FIELD_BOTTOM;
209 }
210 switch (field) {
211 case V4L2_FIELD_ALTERNATE: {
212 vv->last_field = V4L2_FIELD_TOP;
213 maxh = maxh / 2;
214 break;
215 }
216 case V4L2_FIELD_TOP:
217 case V4L2_FIELD_BOTTOM:
218 vv->last_field = V4L2_FIELD_INTERLACED;
219 maxh = maxh / 2;
220 break;
221 case V4L2_FIELD_INTERLACED:
222 vv->last_field = V4L2_FIELD_INTERLACED;
223 break;
224 default: {
225 DEB_D(("no known field mode '%d'.\n",field));
226 return -EINVAL;
227 }
228 }
229
230 f->fmt.pix.field = field;
231 if (f->fmt.pix.width > maxw)
232 f->fmt.pix.width = maxw;
233 if (f->fmt.pix.height > maxh)
234 f->fmt.pix.height = maxh;
235
236 calc_bpl = (f->fmt.pix.width * fmt->depth)/8;
237
238 if (f->fmt.pix.bytesperline < calc_bpl)
239 f->fmt.pix.bytesperline = calc_bpl;
240
241 if (f->fmt.pix.bytesperline > (2*PAGE_SIZE * fmt->depth)/8) /* arbitrary constraint */
242 f->fmt.pix.bytesperline = calc_bpl;
243
244 f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * f->fmt.pix.height;
245 DEB_D(("w:%d, h:%d, bytesperline:%d, sizeimage:%d\n",f->fmt.pix.width,f->fmt.pix.height,f->fmt.pix.bytesperline,f->fmt.pix.sizeimage));
246
247 return 0;
248 }
249 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
250 DEB_EE(("V4L2_BUF_TYPE_VIDEO_OVERLAY: dev:%p, fh:%p\n",dev,fh));
251 err = try_win(dev,&f->fmt.win);
252 if (0 != err) {
253 return err;
254 }
255 return 0;
256 default:
257 DEB_EE(("unknown format type '%d'\n",f->type));
258 return -EINVAL;
259 }
260}
261 102
262int saa7146_start_preview(struct saa7146_fh *fh) 103int saa7146_start_preview(struct saa7146_fh *fh)
263{ 104{
264 struct saa7146_dev *dev = fh->dev; 105 struct saa7146_dev *dev = fh->dev;
265 struct saa7146_vv *vv = dev->vv_data; 106 struct saa7146_vv *vv = dev->vv_data;
107 struct v4l2_format fmt;
266 int ret = 0, err = 0; 108 int ret = 0, err = 0;
267 109
268 DEB_EE(("dev:%p, fh:%p\n",dev,fh)); 110 DEB_EE(("dev:%p, fh:%p\n",dev,fh));
@@ -294,12 +136,13 @@ int saa7146_start_preview(struct saa7146_fh *fh)
294 return -EBUSY; 136 return -EBUSY;
295 } 137 }
296 138
297 err = try_win(dev,&fh->ov.win); 139 fmt.fmt.win = fh->ov.win;
140 err = vidioc_try_fmt_vid_overlay(NULL, fh, &fmt);
298 if (0 != err) { 141 if (0 != err) {
299 saa7146_res_free(vv->video_fh, RESOURCE_DMA1_HPS|RESOURCE_DMA2_CLP); 142 saa7146_res_free(vv->video_fh, RESOURCE_DMA1_HPS|RESOURCE_DMA2_CLP);
300 return -EBUSY; 143 return -EBUSY;
301 } 144 }
302 145 fh->ov.win = fmt.fmt.win;
303 vv->ov_data = &fh->ov; 146 vv->ov_data = &fh->ov;
304 147
305 DEB_D(("%dx%d+%d+%d %s field=%s\n", 148 DEB_D(("%dx%d+%d+%d %s field=%s\n",
@@ -355,58 +198,6 @@ int saa7146_stop_preview(struct saa7146_fh *fh)
355} 198}
356EXPORT_SYMBOL_GPL(saa7146_stop_preview); 199EXPORT_SYMBOL_GPL(saa7146_stop_preview);
357 200
358static int s_fmt(struct saa7146_fh *fh, struct v4l2_format *f)
359{
360 struct saa7146_dev *dev = fh->dev;
361 struct saa7146_vv *vv = dev->vv_data;
362
363 int err;
364
365 switch (f->type) {
366 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
367 DEB_EE(("V4L2_BUF_TYPE_VIDEO_CAPTURE: dev:%p, fh:%p\n",dev,fh));
368 if (IS_CAPTURE_ACTIVE(fh) != 0) {
369 DEB_EE(("streaming capture is active\n"));
370 return -EBUSY;
371 }
372 err = try_fmt(fh,f);
373 if (0 != err)
374 return err;
375 fh->video_fmt = f->fmt.pix;
376 DEB_EE(("set to pixelformat '%4.4s'\n",(char *)&fh->video_fmt.pixelformat));
377 return 0;
378 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
379 DEB_EE(("V4L2_BUF_TYPE_VIDEO_OVERLAY: dev:%p, fh:%p\n",dev,fh));
380 err = try_win(dev,&f->fmt.win);
381 if (0 != err)
382 return err;
383 mutex_lock(&dev->lock);
384 fh->ov.win = f->fmt.win;
385 fh->ov.nclips = f->fmt.win.clipcount;
386 if (fh->ov.nclips > 16)
387 fh->ov.nclips = 16;
388 if (copy_from_user(fh->ov.clips,f->fmt.win.clips,sizeof(struct v4l2_clip)*fh->ov.nclips)) {
389 mutex_unlock(&dev->lock);
390 return -EFAULT;
391 }
392
393 /* fh->ov.fh is used to indicate that we have valid overlay informations, too */
394 fh->ov.fh = fh;
395
396 mutex_unlock(&dev->lock);
397
398 /* check if our current overlay is active */
399 if (IS_OVERLAY_ACTIVE(fh) != 0) {
400 saa7146_stop_preview(fh);
401 saa7146_start_preview(fh);
402 }
403 return 0;
404 default:
405 DEB_D(("unknown format type '%d'\n",f->type));
406 return -EINVAL;
407 }
408}
409
410/********************************************************************************/ 201/********************************************************************************/
411/* device controls */ 202/* device controls */
412 203
@@ -419,6 +210,7 @@ static struct v4l2_queryctrl controls[] = {
419 .step = 1, 210 .step = 1,
420 .default_value = 128, 211 .default_value = 128,
421 .type = V4L2_CTRL_TYPE_INTEGER, 212 .type = V4L2_CTRL_TYPE_INTEGER,
213 .flags = V4L2_CTRL_FLAG_SLIDER,
422 },{ 214 },{
423 .id = V4L2_CID_CONTRAST, 215 .id = V4L2_CID_CONTRAST,
424 .name = "Contrast", 216 .name = "Contrast",
@@ -427,6 +219,7 @@ static struct v4l2_queryctrl controls[] = {
427 .step = 1, 219 .step = 1,
428 .default_value = 64, 220 .default_value = 64,
429 .type = V4L2_CTRL_TYPE_INTEGER, 221 .type = V4L2_CTRL_TYPE_INTEGER,
222 .flags = V4L2_CTRL_FLAG_SLIDER,
430 },{ 223 },{
431 .id = V4L2_CID_SATURATION, 224 .id = V4L2_CID_SATURATION,
432 .name = "Saturation", 225 .name = "Saturation",
@@ -435,15 +228,16 @@ static struct v4l2_queryctrl controls[] = {
435 .step = 1, 228 .step = 1,
436 .default_value = 64, 229 .default_value = 64,
437 .type = V4L2_CTRL_TYPE_INTEGER, 230 .type = V4L2_CTRL_TYPE_INTEGER,
231 .flags = V4L2_CTRL_FLAG_SLIDER,
438 },{ 232 },{
439 .id = V4L2_CID_VFLIP, 233 .id = V4L2_CID_VFLIP,
440 .name = "Vertical flip", 234 .name = "Vertical Flip",
441 .minimum = 0, 235 .minimum = 0,
442 .maximum = 1, 236 .maximum = 1,
443 .type = V4L2_CTRL_TYPE_BOOLEAN, 237 .type = V4L2_CTRL_TYPE_BOOLEAN,
444 },{ 238 },{
445 .id = V4L2_CID_HFLIP, 239 .id = V4L2_CID_HFLIP,
446 .name = "Horizontal flip", 240 .name = "Horizontal Flip",
447 .minimum = 0, 241 .minimum = 0,
448 .maximum = 1, 242 .maximum = 1,
449 .type = V4L2_CTRL_TYPE_BOOLEAN, 243 .type = V4L2_CTRL_TYPE_BOOLEAN,
@@ -463,132 +257,6 @@ static struct v4l2_queryctrl* ctrl_by_id(int id)
463 return NULL; 257 return NULL;
464} 258}
465 259
466static int get_control(struct saa7146_fh *fh, struct v4l2_control *c)
467{
468 struct saa7146_dev *dev = fh->dev;
469 struct saa7146_vv *vv = dev->vv_data;
470
471 const struct v4l2_queryctrl* ctrl;
472 u32 value = 0;
473
474 ctrl = ctrl_by_id(c->id);
475 if (NULL == ctrl)
476 return -EINVAL;
477 switch (c->id) {
478 case V4L2_CID_BRIGHTNESS:
479 value = saa7146_read(dev, BCS_CTRL);
480 c->value = 0xff & (value >> 24);
481 DEB_D(("V4L2_CID_BRIGHTNESS: %d\n",c->value));
482 break;
483 case V4L2_CID_CONTRAST:
484 value = saa7146_read(dev, BCS_CTRL);
485 c->value = 0x7f & (value >> 16);
486 DEB_D(("V4L2_CID_CONTRAST: %d\n",c->value));
487 break;
488 case V4L2_CID_SATURATION:
489 value = saa7146_read(dev, BCS_CTRL);
490 c->value = 0x7f & (value >> 0);
491 DEB_D(("V4L2_CID_SATURATION: %d\n",c->value));
492 break;
493 case V4L2_CID_VFLIP:
494 c->value = vv->vflip;
495 DEB_D(("V4L2_CID_VFLIP: %d\n",c->value));
496 break;
497 case V4L2_CID_HFLIP:
498 c->value = vv->hflip;
499 DEB_D(("V4L2_CID_HFLIP: %d\n",c->value));
500 break;
501 default:
502 return -EINVAL;
503 }
504
505 return 0;
506}
507
508static int set_control(struct saa7146_fh *fh, struct v4l2_control *c)
509{
510 struct saa7146_dev *dev = fh->dev;
511 struct saa7146_vv *vv = dev->vv_data;
512
513 const struct v4l2_queryctrl* ctrl;
514
515 ctrl = ctrl_by_id(c->id);
516 if (NULL == ctrl) {
517 DEB_D(("unknown control %d\n",c->id));
518 return -EINVAL;
519 }
520
521 mutex_lock(&dev->lock);
522
523 switch (ctrl->type) {
524 case V4L2_CTRL_TYPE_BOOLEAN:
525 case V4L2_CTRL_TYPE_MENU:
526 case V4L2_CTRL_TYPE_INTEGER:
527 if (c->value < ctrl->minimum)
528 c->value = ctrl->minimum;
529 if (c->value > ctrl->maximum)
530 c->value = ctrl->maximum;
531 break;
532 default:
533 /* nothing */;
534 };
535
536 switch (c->id) {
537 case V4L2_CID_BRIGHTNESS: {
538 u32 value = saa7146_read(dev, BCS_CTRL);
539 value &= 0x00ffffff;
540 value |= (c->value << 24);
541 saa7146_write(dev, BCS_CTRL, value);
542 saa7146_write(dev, MC2, MASK_22 | MASK_06 );
543 break;
544 }
545 case V4L2_CID_CONTRAST: {
546 u32 value = saa7146_read(dev, BCS_CTRL);
547 value &= 0xff00ffff;
548 value |= (c->value << 16);
549 saa7146_write(dev, BCS_CTRL, value);
550 saa7146_write(dev, MC2, MASK_22 | MASK_06 );
551 break;
552 }
553 case V4L2_CID_SATURATION: {
554 u32 value = saa7146_read(dev, BCS_CTRL);
555 value &= 0xffffff00;
556 value |= (c->value << 0);
557 saa7146_write(dev, BCS_CTRL, value);
558 saa7146_write(dev, MC2, MASK_22 | MASK_06 );
559 break;
560 }
561 case V4L2_CID_HFLIP:
562 /* fixme: we can support changing VFLIP and HFLIP here... */
563 if (IS_CAPTURE_ACTIVE(fh) != 0) {
564 DEB_D(("V4L2_CID_HFLIP while active capture.\n"));
565 mutex_unlock(&dev->lock);
566 return -EINVAL;
567 }
568 vv->hflip = c->value;
569 break;
570 case V4L2_CID_VFLIP:
571 if (IS_CAPTURE_ACTIVE(fh) != 0) {
572 DEB_D(("V4L2_CID_VFLIP while active capture.\n"));
573 mutex_unlock(&dev->lock);
574 return -EINVAL;
575 }
576 vv->vflip = c->value;
577 break;
578 default: {
579 mutex_unlock(&dev->lock);
580 return -EINVAL;
581 }
582 }
583 mutex_unlock(&dev->lock);
584
585 if (IS_OVERLAY_ACTIVE(fh) != 0) {
586 saa7146_stop_preview(fh);
587 saa7146_start_preview(fh);
588 }
589 return 0;
590}
591
592/********************************************************************************/ 260/********************************************************************************/
593/* common pagetable functions */ 261/* common pagetable functions */
594 262
@@ -829,231 +497,446 @@ static int video_end(struct saa7146_fh *fh, struct file *file)
829 return 0; 497 return 0;
830} 498}
831 499
832/* 500static int vidioc_querycap(struct file *file, void *fh, struct v4l2_capability *cap)
833 * This function is _not_ called directly, but from 501{
834 * video_generic_ioctl (and maybe others). userspace 502 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
835 * copying is done already, arg is a kernel pointer. 503
836 */ 504 strcpy((char *)cap->driver, "saa7146 v4l2");
505 strlcpy((char *)cap->card, dev->ext->name, sizeof(cap->card));
506 sprintf((char *)cap->bus_info, "PCI:%s", pci_name(dev->pci));
507 cap->version = SAA7146_VERSION_CODE;
508 cap->capabilities =
509 V4L2_CAP_VIDEO_CAPTURE |
510 V4L2_CAP_VIDEO_OVERLAY |
511 V4L2_CAP_READWRITE |
512 V4L2_CAP_STREAMING;
513 cap->capabilities |= dev->ext_vv_data->capabilities;
514 return 0;
515}
837 516
838long saa7146_video_do_ioctl(struct file *file, unsigned int cmd, void *arg) 517static int vidioc_g_fbuf(struct file *file, void *fh, struct v4l2_framebuffer *fb)
839{ 518{
840 struct saa7146_fh *fh = file->private_data; 519 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
841 struct saa7146_dev *dev = fh->dev; 520 struct saa7146_vv *vv = dev->vv_data;
521
522 *fb = vv->ov_fb;
523 fb->capability = V4L2_FBUF_CAP_LIST_CLIPPING;
524 return 0;
525}
526
527static int vidioc_s_fbuf(struct file *file, void *fh, struct v4l2_framebuffer *fb)
528{
529 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
842 struct saa7146_vv *vv = dev->vv_data; 530 struct saa7146_vv *vv = dev->vv_data;
531 struct saa7146_format *fmt;
843 532
844 long err = 0; 533 DEB_EE(("VIDIOC_S_FBUF\n"));
845 int result = 0, ee = 0;
846 534
847 struct saa7146_use_ops *ops; 535 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RAWIO))
848 struct videobuf_queue *q; 536 return -EPERM;
849 537
850 /* check if extension handles the command */ 538 /* check args */
851 for(ee = 0; dev->ext_vv_data->ioctls[ee].flags != 0; ee++) { 539 fmt = format_by_fourcc(dev, fb->fmt.pixelformat);
852 if( cmd == dev->ext_vv_data->ioctls[ee].cmd ) 540 if (NULL == fmt)
853 break; 541 return -EINVAL;
542
543 /* planar formats are not allowed for overlay video, clipping and video dma would clash */
544 if (fmt->flags & FORMAT_IS_PLANAR)
545 DEB_S(("planar pixelformat '%4.4s' not allowed for overlay\n",
546 (char *)&fmt->pixelformat));
547
548 /* check if overlay is running */
549 if (IS_OVERLAY_ACTIVE(fh) != 0) {
550 if (vv->video_fh != fh) {
551 DEB_D(("refusing to change framebuffer informations while overlay is active in another open.\n"));
552 return -EBUSY;
553 }
854 } 554 }
855 555
856 if( 0 != (dev->ext_vv_data->ioctls[ee].flags & SAA7146_EXCLUSIVE) ) { 556 mutex_lock(&dev->lock);
857 DEB_D(("extension handles ioctl exclusive.\n")); 557
858 result = dev->ext_vv_data->ioctl(fh, cmd, arg); 558 /* ok, accept it */
859 return result; 559 vv->ov_fb = *fb;
560 vv->ov_fmt = fmt;
561 if (0 == vv->ov_fb.fmt.bytesperline)
562 vv->ov_fb.fmt.bytesperline =
563 vv->ov_fb.fmt.width * fmt->depth / 8;
564
565 mutex_unlock(&dev->lock);
566 return 0;
567}
568
569static int vidioc_enum_fmt_vid_cap(struct file *file, void *fh, struct v4l2_fmtdesc *f)
570{
571 if (f->index >= NUM_FORMATS)
572 return -EINVAL;
573 strlcpy((char *)f->description, formats[f->index].name,
574 sizeof(f->description));
575 f->pixelformat = formats[f->index].pixelformat;
576 return 0;
577}
578
579static int vidioc_queryctrl(struct file *file, void *fh, struct v4l2_queryctrl *c)
580{
581 const struct v4l2_queryctrl *ctrl;
582
583 if ((c->id < V4L2_CID_BASE ||
584 c->id >= V4L2_CID_LASTP1) &&
585 (c->id < V4L2_CID_PRIVATE_BASE ||
586 c->id >= V4L2_CID_PRIVATE_LASTP1))
587 return -EINVAL;
588
589 ctrl = ctrl_by_id(c->id);
590 if (ctrl == NULL)
591 return -EINVAL;
592
593 DEB_EE(("VIDIOC_QUERYCTRL: id:%d\n", c->id));
594 *c = *ctrl;
595 return 0;
596}
597
598static int vidioc_g_ctrl(struct file *file, void *fh, struct v4l2_control *c)
599{
600 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
601 struct saa7146_vv *vv = dev->vv_data;
602 const struct v4l2_queryctrl *ctrl;
603 u32 value = 0;
604
605 ctrl = ctrl_by_id(c->id);
606 if (NULL == ctrl)
607 return -EINVAL;
608 switch (c->id) {
609 case V4L2_CID_BRIGHTNESS:
610 value = saa7146_read(dev, BCS_CTRL);
611 c->value = 0xff & (value >> 24);
612 DEB_D(("V4L2_CID_BRIGHTNESS: %d\n", c->value));
613 break;
614 case V4L2_CID_CONTRAST:
615 value = saa7146_read(dev, BCS_CTRL);
616 c->value = 0x7f & (value >> 16);
617 DEB_D(("V4L2_CID_CONTRAST: %d\n", c->value));
618 break;
619 case V4L2_CID_SATURATION:
620 value = saa7146_read(dev, BCS_CTRL);
621 c->value = 0x7f & (value >> 0);
622 DEB_D(("V4L2_CID_SATURATION: %d\n", c->value));
623 break;
624 case V4L2_CID_VFLIP:
625 c->value = vv->vflip;
626 DEB_D(("V4L2_CID_VFLIP: %d\n", c->value));
627 break;
628 case V4L2_CID_HFLIP:
629 c->value = vv->hflip;
630 DEB_D(("V4L2_CID_HFLIP: %d\n", c->value));
631 break;
632 default:
633 return -EINVAL;
860 } 634 }
861 if( 0 != (dev->ext_vv_data->ioctls[ee].flags & SAA7146_BEFORE) ) { 635 return 0;
862 DEB_D(("extension handles ioctl before.\n")); 636}
863 result = dev->ext_vv_data->ioctl(fh, cmd, arg); 637
864 if( -EAGAIN != result ) { 638static int vidioc_s_ctrl(struct file *file, void *fh, struct v4l2_control *c)
865 return result; 639{
866 } 640 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
641 struct saa7146_vv *vv = dev->vv_data;
642 const struct v4l2_queryctrl *ctrl;
643
644 ctrl = ctrl_by_id(c->id);
645 if (NULL == ctrl) {
646 DEB_D(("unknown control %d\n", c->id));
647 return -EINVAL;
867 } 648 }
868 649
869 /* fixme: add handle "after" case (is it still needed?) */ 650 mutex_lock(&dev->lock);
870 651
871 switch (fh->type) { 652 switch (ctrl->type) {
872 case V4L2_BUF_TYPE_VIDEO_CAPTURE: { 653 case V4L2_CTRL_TYPE_BOOLEAN:
873 ops = &saa7146_video_uops; 654 case V4L2_CTRL_TYPE_MENU:
874 q = &fh->video_q; 655 case V4L2_CTRL_TYPE_INTEGER:
656 if (c->value < ctrl->minimum)
657 c->value = ctrl->minimum;
658 if (c->value > ctrl->maximum)
659 c->value = ctrl->maximum;
875 break; 660 break;
661 default:
662 /* nothing */;
663 }
664
665 switch (c->id) {
666 case V4L2_CID_BRIGHTNESS: {
667 u32 value = saa7146_read(dev, BCS_CTRL);
668 value &= 0x00ffffff;
669 value |= (c->value << 24);
670 saa7146_write(dev, BCS_CTRL, value);
671 saa7146_write(dev, MC2, MASK_22 | MASK_06);
672 break;
673 }
674 case V4L2_CID_CONTRAST: {
675 u32 value = saa7146_read(dev, BCS_CTRL);
676 value &= 0xff00ffff;
677 value |= (c->value << 16);
678 saa7146_write(dev, BCS_CTRL, value);
679 saa7146_write(dev, MC2, MASK_22 | MASK_06);
680 break;
681 }
682 case V4L2_CID_SATURATION: {
683 u32 value = saa7146_read(dev, BCS_CTRL);
684 value &= 0xffffff00;
685 value |= (c->value << 0);
686 saa7146_write(dev, BCS_CTRL, value);
687 saa7146_write(dev, MC2, MASK_22 | MASK_06);
688 break;
689 }
690 case V4L2_CID_HFLIP:
691 /* fixme: we can support changing VFLIP and HFLIP here... */
692 if (IS_CAPTURE_ACTIVE(fh) != 0) {
693 DEB_D(("V4L2_CID_HFLIP while active capture.\n"));
694 mutex_unlock(&dev->lock);
695 return -EBUSY;
876 } 696 }
877 case V4L2_BUF_TYPE_VBI_CAPTURE: { 697 vv->hflip = c->value;
878 ops = &saa7146_vbi_uops;
879 q = &fh->vbi_q;
880 break; 698 break;
699 case V4L2_CID_VFLIP:
700 if (IS_CAPTURE_ACTIVE(fh) != 0) {
701 DEB_D(("V4L2_CID_VFLIP while active capture.\n"));
702 mutex_unlock(&dev->lock);
703 return -EBUSY;
881 } 704 }
705 vv->vflip = c->value;
706 break;
882 default: 707 default:
883 BUG(); 708 mutex_unlock(&dev->lock);
884 return 0; 709 return -EINVAL;
885 } 710 }
711 mutex_unlock(&dev->lock);
886 712
887 switch (cmd) { 713 if (IS_OVERLAY_ACTIVE(fh) != 0) {
888 case VIDIOC_QUERYCAP: 714 saa7146_stop_preview(fh);
889 { 715 saa7146_start_preview(fh);
890 struct v4l2_capability *cap = arg;
891 memset(cap,0,sizeof(*cap));
892
893 DEB_EE(("VIDIOC_QUERYCAP\n"));
894
895 strcpy((char *)cap->driver, "saa7146 v4l2");
896 strlcpy((char *)cap->card, dev->ext->name, sizeof(cap->card));
897 sprintf((char *)cap->bus_info,"PCI:%s", pci_name(dev->pci));
898 cap->version = SAA7146_VERSION_CODE;
899 cap->capabilities =
900 V4L2_CAP_VIDEO_CAPTURE |
901 V4L2_CAP_VIDEO_OVERLAY |
902 V4L2_CAP_READWRITE |
903 V4L2_CAP_STREAMING;
904 cap->capabilities |= dev->ext_vv_data->capabilities;
905 return 0;
906 } 716 }
907 case VIDIOC_G_FBUF: 717 return 0;
908 { 718}
909 struct v4l2_framebuffer *fb = arg;
910
911 DEB_EE(("VIDIOC_G_FBUF\n"));
912 719
913 *fb = vv->ov_fb; 720static int vidioc_g_parm(struct file *file, void *fh,
914 fb->capability = V4L2_FBUF_CAP_LIST_CLIPPING; 721 struct v4l2_streamparm *parm)
915 return 0; 722{
916 } 723 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
917 case VIDIOC_S_FBUF: 724 struct saa7146_vv *vv = dev->vv_data;
918 {
919 struct v4l2_framebuffer *fb = arg;
920 struct saa7146_format *fmt;
921 725
922 DEB_EE(("VIDIOC_S_FBUF\n")); 726 parm->parm.capture.readbuffers = 1;
727 v4l2_video_std_frame_period(vv->standard->id,
728 &parm->parm.capture.timeperframe);
729 return 0;
730}
923 731
924 if(!capable(CAP_SYS_ADMIN) && 732static int vidioc_g_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *f)
925 !capable(CAP_SYS_RAWIO)) 733{
926 return -EPERM; 734 f->fmt.pix = ((struct saa7146_fh *)fh)->video_fmt;
735 return 0;
736}
927 737
928 /* check args */ 738static int vidioc_g_fmt_vid_overlay(struct file *file, void *fh, struct v4l2_format *f)
929 fmt = format_by_fourcc(dev,fb->fmt.pixelformat); 739{
930 if (NULL == fmt) { 740 f->fmt.win = ((struct saa7146_fh *)fh)->ov.win;
931 return -EINVAL; 741 return 0;
932 } 742}
933 743
934 /* planar formats are not allowed for overlay video, clipping and video dma would clash */ 744static int vidioc_g_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *f)
935 if (0 != (fmt->flags & FORMAT_IS_PLANAR)) { 745{
936 DEB_S(("planar pixelformat '%4.4s' not allowed for overlay\n",(char *)&fmt->pixelformat)); 746 f->fmt.vbi = ((struct saa7146_fh *)fh)->vbi_fmt;
937 } 747 return 0;
748}
938 749
939 /* check if overlay is running */ 750static int vidioc_try_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *f)
940 if (IS_OVERLAY_ACTIVE(fh) != 0) { 751{
941 if (vv->video_fh != fh) { 752 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
942 DEB_D(("refusing to change framebuffer informations while overlay is active in another open.\n")); 753 struct saa7146_vv *vv = dev->vv_data;
943 return -EBUSY; 754 struct saa7146_format *fmt;
944 } 755 enum v4l2_field field;
945 } 756 int maxw, maxh;
757 int calc_bpl;
946 758
947 mutex_lock(&dev->lock); 759 DEB_EE(("V4L2_BUF_TYPE_VIDEO_CAPTURE: dev:%p, fh:%p\n", dev, fh));
948 760
949 /* ok, accept it */ 761 fmt = format_by_fourcc(dev, f->fmt.pix.pixelformat);
950 vv->ov_fb = *fb; 762 if (NULL == fmt)
951 vv->ov_fmt = fmt; 763 return -EINVAL;
952 if (0 == vv->ov_fb.fmt.bytesperline)
953 vv->ov_fb.fmt.bytesperline =
954 vv->ov_fb.fmt.width*fmt->depth/8;
955 764
956 mutex_unlock(&dev->lock); 765 field = f->fmt.pix.field;
766 maxw = vv->standard->h_max_out;
767 maxh = vv->standard->v_max_out;
957 768
958 return 0; 769 if (V4L2_FIELD_ANY == field) {
770 field = (f->fmt.pix.height > maxh / 2)
771 ? V4L2_FIELD_INTERLACED
772 : V4L2_FIELD_BOTTOM;
959 } 773 }
960 case VIDIOC_ENUM_FMT: 774 switch (field) {
961 { 775 case V4L2_FIELD_ALTERNATE:
962 struct v4l2_fmtdesc *f = arg; 776 vv->last_field = V4L2_FIELD_TOP;
963 777 maxh = maxh / 2;
964 switch (f->type) { 778 break;
965 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 779 case V4L2_FIELD_TOP:
966 case V4L2_BUF_TYPE_VIDEO_OVERLAY: 780 case V4L2_FIELD_BOTTOM:
967 if (f->index >= NUM_FORMATS) 781 vv->last_field = V4L2_FIELD_INTERLACED;
968 return -EINVAL; 782 maxh = maxh / 2;
969 strlcpy((char *)f->description, formats[f->index].name, 783 break;
970 sizeof(f->description)); 784 case V4L2_FIELD_INTERLACED:
971 f->pixelformat = formats[f->index].pixelformat; 785 vv->last_field = V4L2_FIELD_INTERLACED;
972 f->flags = 0; 786 break;
973 memset(f->reserved, 0, sizeof(f->reserved)); 787 default:
974 break; 788 DEB_D(("no known field mode '%d'.\n", field));
975 default: 789 return -EINVAL;
976 return -EINVAL;
977 }
978
979 DEB_EE(("VIDIOC_ENUM_FMT: type:%d, index:%d\n",f->type,f->index));
980 return 0;
981 } 790 }
982 case VIDIOC_QUERYCTRL:
983 {
984 const struct v4l2_queryctrl *ctrl;
985 struct v4l2_queryctrl *c = arg;
986 791
987 if ((c->id < V4L2_CID_BASE || 792 f->fmt.pix.field = field;
988 c->id >= V4L2_CID_LASTP1) && 793 if (f->fmt.pix.width > maxw)
989 (c->id < V4L2_CID_PRIVATE_BASE || 794 f->fmt.pix.width = maxw;
990 c->id >= V4L2_CID_PRIVATE_LASTP1)) 795 if (f->fmt.pix.height > maxh)
991 return -EINVAL; 796 f->fmt.pix.height = maxh;
992 797
993 ctrl = ctrl_by_id(c->id); 798 calc_bpl = (f->fmt.pix.width * fmt->depth) / 8;
994 if( NULL == ctrl ) {
995 return -EINVAL;
996/*
997 c->flags = V4L2_CTRL_FLAG_DISABLED;
998 return 0;
999*/
1000 }
1001 799
1002 DEB_EE(("VIDIOC_QUERYCTRL: id:%d\n",c->id)); 800 if (f->fmt.pix.bytesperline < calc_bpl)
1003 *c = *ctrl; 801 f->fmt.pix.bytesperline = calc_bpl;
1004 return 0; 802
803 if (f->fmt.pix.bytesperline > (2 * PAGE_SIZE * fmt->depth) / 8) /* arbitrary constraint */
804 f->fmt.pix.bytesperline = calc_bpl;
805
806 f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * f->fmt.pix.height;
807 DEB_D(("w:%d, h:%d, bytesperline:%d, sizeimage:%d\n", f->fmt.pix.width,
808 f->fmt.pix.height, f->fmt.pix.bytesperline, f->fmt.pix.sizeimage));
809
810 return 0;
811}
812
813
814static int vidioc_try_fmt_vid_overlay(struct file *file, void *fh, struct v4l2_format *f)
815{
816 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
817 struct saa7146_vv *vv = dev->vv_data;
818 struct v4l2_window *win = &f->fmt.win;
819 enum v4l2_field field;
820 int maxw, maxh;
821
822 DEB_EE(("dev:%p\n", dev));
823
824 if (NULL == vv->ov_fb.base) {
825 DEB_D(("no fb base set.\n"));
826 return -EINVAL;
1005 } 827 }
1006 case VIDIOC_G_CTRL: { 828 if (NULL == vv->ov_fmt) {
1007 DEB_EE(("VIDIOC_G_CTRL\n")); 829 DEB_D(("no fb fmt set.\n"));
1008 return get_control(fh,arg); 830 return -EINVAL;
1009 } 831 }
1010 case VIDIOC_S_CTRL: 832 if (win->w.width < 48 || win->w.height < 32) {
1011 { 833 DEB_D(("min width/height. (%d,%d)\n", win->w.width, win->w.height));
1012 DEB_EE(("VIDIOC_S_CTRL\n")); 834 return -EINVAL;
1013 err = set_control(fh,arg);
1014 return err;
1015 } 835 }
1016 case VIDIOC_G_PARM: 836 if (win->clipcount > 16) {
1017 { 837 DEB_D(("clipcount too big.\n"));
1018 struct v4l2_streamparm *parm = arg; 838 return -EINVAL;
1019 if( parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ) {
1020 return -EINVAL;
1021 }
1022 memset(&parm->parm.capture,0,sizeof(struct v4l2_captureparm));
1023 parm->parm.capture.readbuffers = 1;
1024 // fixme: only for PAL!
1025 parm->parm.capture.timeperframe.numerator = 1;
1026 parm->parm.capture.timeperframe.denominator = 25;
1027 return 0;
1028 } 839 }
1029 case VIDIOC_G_FMT: 840
1030 { 841 field = win->field;
1031 struct v4l2_format *f = arg; 842 maxw = vv->standard->h_max_out;
1032 DEB_EE(("VIDIOC_G_FMT\n")); 843 maxh = vv->standard->v_max_out;
1033 return g_fmt(fh,f); 844
845 if (V4L2_FIELD_ANY == field) {
846 field = (win->w.height > maxh / 2)
847 ? V4L2_FIELD_INTERLACED
848 : V4L2_FIELD_TOP;
849 }
850 switch (field) {
851 case V4L2_FIELD_TOP:
852 case V4L2_FIELD_BOTTOM:
853 case V4L2_FIELD_ALTERNATE:
854 maxh = maxh / 2;
855 break;
856 case V4L2_FIELD_INTERLACED:
857 break;
858 default:
859 DEB_D(("no known field mode '%d'.\n", field));
860 return -EINVAL;
1034 } 861 }
1035 case VIDIOC_S_FMT: 862
1036 { 863 win->field = field;
1037 struct v4l2_format *f = arg; 864 if (win->w.width > maxw)
1038 DEB_EE(("VIDIOC_S_FMT\n")); 865 win->w.width = maxw;
1039 return s_fmt(fh,f); 866 if (win->w.height > maxh)
867 win->w.height = maxh;
868
869 return 0;
870}
871
872static int vidioc_s_fmt_vid_cap(struct file *file, void *__fh, struct v4l2_format *f)
873{
874 struct saa7146_fh *fh = __fh;
875 struct saa7146_dev *dev = fh->dev;
876 struct saa7146_vv *vv = dev->vv_data;
877 int err;
878
879 DEB_EE(("V4L2_BUF_TYPE_VIDEO_CAPTURE: dev:%p, fh:%p\n", dev, fh));
880 if (IS_CAPTURE_ACTIVE(fh) != 0) {
881 DEB_EE(("streaming capture is active\n"));
882 return -EBUSY;
1040 } 883 }
1041 case VIDIOC_TRY_FMT: 884 err = vidioc_try_fmt_vid_cap(file, fh, f);
1042 { 885 if (0 != err)
1043 struct v4l2_format *f = arg; 886 return err;
1044 DEB_EE(("VIDIOC_TRY_FMT\n")); 887 fh->video_fmt = f->fmt.pix;
1045 return try_fmt(fh,f); 888 DEB_EE(("set to pixelformat '%4.4s'\n", (char *)&fh->video_fmt.pixelformat));
889 return 0;
890}
891
892static int vidioc_s_fmt_vid_overlay(struct file *file, void *__fh, struct v4l2_format *f)
893{
894 struct saa7146_fh *fh = __fh;
895 struct saa7146_dev *dev = fh->dev;
896 struct saa7146_vv *vv = dev->vv_data;
897 int err;
898
899 DEB_EE(("V4L2_BUF_TYPE_VIDEO_OVERLAY: dev:%p, fh:%p\n", dev, fh));
900 err = vidioc_try_fmt_vid_overlay(file, fh, f);
901 if (0 != err)
902 return err;
903 mutex_lock(&dev->lock);
904 fh->ov.win = f->fmt.win;
905 fh->ov.nclips = f->fmt.win.clipcount;
906 if (fh->ov.nclips > 16)
907 fh->ov.nclips = 16;
908 if (copy_from_user(fh->ov.clips, f->fmt.win.clips,
909 sizeof(struct v4l2_clip) * fh->ov.nclips)) {
910 mutex_unlock(&dev->lock);
911 return -EFAULT;
1046 } 912 }
1047 case VIDIOC_G_STD: 913
1048 { 914 /* fh->ov.fh is used to indicate that we have valid overlay informations, too */
1049 v4l2_std_id *id = arg; 915 fh->ov.fh = fh;
1050 DEB_EE(("VIDIOC_G_STD\n")); 916
1051 *id = vv->standard->id; 917 mutex_unlock(&dev->lock);
1052 return 0; 918
919 /* check if our current overlay is active */
920 if (IS_OVERLAY_ACTIVE(fh) != 0) {
921 saa7146_stop_preview(fh);
922 saa7146_start_preview(fh);
1053 } 923 }
924 return 0;
925}
926
927static int vidioc_g_std(struct file *file, void *fh, v4l2_std_id *norm)
928{
929 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
930 struct saa7146_vv *vv = dev->vv_data;
931
932 *norm = vv->standard->id;
933 return 0;
934}
935
1054 /* the saa7146 supfhrts (used in conjunction with the saa7111a for example) 936 /* the saa7146 supfhrts (used in conjunction with the saa7111a for example)
1055 PAL / NTSC / SECAM. if your hardware does not (or does more) 937 PAL / NTSC / SECAM. if your hardware does not (or does more)
1056 -- override this function in your extension */ 938 -- override this function in your extension */
939/*
1057 case VIDIOC_ENUMSTD: 940 case VIDIOC_ENUMSTD:
1058 { 941 {
1059 struct v4l2_standard *e = arg; 942 struct v4l2_standard *e = arg;
@@ -1066,162 +949,245 @@ long saa7146_video_do_ioctl(struct file *file, unsigned int cmd, void *arg)
1066 } 949 }
1067 return -EINVAL; 950 return -EINVAL;
1068 } 951 }
1069 case VIDIOC_S_STD: 952 */
1070 {
1071 v4l2_std_id *id = arg;
1072 int found = 0;
1073 int i;
1074
1075 DEB_EE(("VIDIOC_S_STD\n"));
1076 953
1077 if ((vv->video_status & STATUS_CAPTURE) == STATUS_CAPTURE) { 954static int vidioc_s_std(struct file *file, void *fh, v4l2_std_id *id)
1078 DEB_D(("cannot change video standard while streaming capture is active\n")); 955{
1079 return -EBUSY; 956 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
1080 } 957 struct saa7146_vv *vv = dev->vv_data;
958 int found = 0;
959 int err, i;
1081 960
1082 if ((vv->video_status & STATUS_OVERLAY) != 0) { 961 DEB_EE(("VIDIOC_S_STD\n"));
1083 vv->ov_suspend = vv->video_fh;
1084 err = saa7146_stop_preview(vv->video_fh); /* side effect: video_status is now 0, video_fh is NULL */
1085 if (0 != err) {
1086 DEB_D(("suspending video failed. aborting\n"));
1087 return err;
1088 }
1089 }
1090 962
1091 mutex_lock(&dev->lock); 963 if ((vv->video_status & STATUS_CAPTURE) == STATUS_CAPTURE) {
964 DEB_D(("cannot change video standard while streaming capture is active\n"));
965 return -EBUSY;
966 }
1092 967
1093 for(i = 0; i < dev->ext_vv_data->num_stds; i++) 968 if ((vv->video_status & STATUS_OVERLAY) != 0) {
1094 if (*id & dev->ext_vv_data->stds[i].id) 969 vv->ov_suspend = vv->video_fh;
1095 break; 970 err = saa7146_stop_preview(vv->video_fh); /* side effect: video_status is now 0, video_fh is NULL */
1096 if (i != dev->ext_vv_data->num_stds) { 971 if (0 != err) {
1097 vv->standard = &dev->ext_vv_data->stds[i]; 972 DEB_D(("suspending video failed. aborting\n"));
1098 if( NULL != dev->ext_vv_data->std_callback ) 973 return err;
1099 dev->ext_vv_data->std_callback(dev, vv->standard);
1100 found = 1;
1101 } 974 }
975 }
1102 976
1103 mutex_unlock(&dev->lock); 977 mutex_lock(&dev->lock);
1104 978
1105 if (vv->ov_suspend != NULL) { 979 for (i = 0; i < dev->ext_vv_data->num_stds; i++)
1106 saa7146_start_preview(vv->ov_suspend); 980 if (*id & dev->ext_vv_data->stds[i].id)
1107 vv->ov_suspend = NULL; 981 break;
1108 } 982 if (i != dev->ext_vv_data->num_stds) {
983 vv->standard = &dev->ext_vv_data->stds[i];
984 if (NULL != dev->ext_vv_data->std_callback)
985 dev->ext_vv_data->std_callback(dev, vv->standard);
986 found = 1;
987 }
1109 988
1110 if( 0 == found ) { 989 mutex_unlock(&dev->lock);
1111 DEB_EE(("VIDIOC_S_STD: standard not found.\n"));
1112 return -EINVAL;
1113 }
1114 990
1115 DEB_EE(("VIDIOC_S_STD: set to standard to '%s'\n",vv->standard->name)); 991 if (vv->ov_suspend != NULL) {
1116 return 0; 992 saa7146_start_preview(vv->ov_suspend);
993 vv->ov_suspend = NULL;
1117 } 994 }
1118 case VIDIOC_OVERLAY:
1119 {
1120 int on = *(int *)arg;
1121 995
1122 DEB_D(("VIDIOC_OVERLAY on:%d\n",on)); 996 if (!found) {
1123 if (on != 0) { 997 DEB_EE(("VIDIOC_S_STD: standard not found.\n"));
1124 err = saa7146_start_preview(fh); 998 return -EINVAL;
1125 } else {
1126 err = saa7146_stop_preview(fh);
1127 }
1128 return err;
1129 }
1130 case VIDIOC_REQBUFS: {
1131 struct v4l2_requestbuffers *req = arg;
1132 DEB_D(("VIDIOC_REQBUFS, type:%d\n",req->type));
1133 return videobuf_reqbufs(q,req);
1134 }
1135 case VIDIOC_QUERYBUF: {
1136 struct v4l2_buffer *buf = arg;
1137 DEB_D(("VIDIOC_QUERYBUF, type:%d, offset:%d\n",buf->type,buf->m.offset));
1138 return videobuf_querybuf(q,buf);
1139 }
1140 case VIDIOC_QBUF: {
1141 struct v4l2_buffer *buf = arg;
1142 int ret = 0;
1143 ret = videobuf_qbuf(q,buf);
1144 DEB_D(("VIDIOC_QBUF: ret:%d, index:%d\n",ret,buf->index));
1145 return ret;
1146 }
1147 case VIDIOC_DQBUF: {
1148 struct v4l2_buffer *buf = arg;
1149 int ret = 0;
1150 ret = videobuf_dqbuf(q,buf,file->f_flags & O_NONBLOCK);
1151 DEB_D(("VIDIOC_DQBUF: ret:%d, index:%d\n",ret,buf->index));
1152 return ret;
1153 } 999 }
1154 case VIDIOC_STREAMON: {
1155 int *type = arg;
1156 DEB_D(("VIDIOC_STREAMON, type:%d\n",*type));
1157 1000
1158 err = video_begin(fh); 1001 DEB_EE(("VIDIOC_S_STD: set to standard to '%s'\n", vv->standard->name));
1159 if( 0 != err) { 1002 return 0;
1160 return err; 1003}
1161 }
1162 err = videobuf_streamon(q);
1163 return err;
1164 }
1165 case VIDIOC_STREAMOFF: {
1166 int *type = arg;
1167 1004
1168 DEB_D(("VIDIOC_STREAMOFF, type:%d\n",*type)); 1005static int vidioc_overlay(struct file *file, void *fh, unsigned int on)
1006{
1007 int err;
1169 1008
1170 /* ugly: we need to copy some checks from video_end(), 1009 DEB_D(("VIDIOC_OVERLAY on:%d\n", on));
1171 because videobuf_streamoff() relies on the capture running. 1010 if (on)
1172 check and fix this */ 1011 err = saa7146_start_preview(fh);
1173 if ((vv->video_status & STATUS_CAPTURE) != STATUS_CAPTURE) { 1012 else
1174 DEB_S(("not capturing.\n")); 1013 err = saa7146_stop_preview(fh);
1175 return 0; 1014 return err;
1176 } 1015}
1177 1016
1178 if (vv->video_fh != fh) { 1017static int vidioc_reqbufs(struct file *file, void *__fh, struct v4l2_requestbuffers *b)
1179 DEB_S(("capturing, but in another open.\n")); 1018{
1180 return -EBUSY; 1019 struct saa7146_fh *fh = __fh;
1181 }
1182 1020
1183 err = videobuf_streamoff(q); 1021 if (b->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1184 if (0 != err) { 1022 return videobuf_reqbufs(&fh->video_q, b);
1185 DEB_D(("warning: videobuf_streamoff() failed.\n")); 1023 if (b->type == V4L2_BUF_TYPE_VBI_CAPTURE)
1186 video_end(fh, file); 1024 return videobuf_reqbufs(&fh->vbi_q, b);
1187 } else { 1025 return -EINVAL;
1188 err = video_end(fh, file); 1026}
1189 } 1027
1028static int vidioc_querybuf(struct file *file, void *__fh, struct v4l2_buffer *buf)
1029{
1030 struct saa7146_fh *fh = __fh;
1031
1032 if (buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1033 return videobuf_querybuf(&fh->video_q, buf);
1034 if (buf->type == V4L2_BUF_TYPE_VBI_CAPTURE)
1035 return videobuf_querybuf(&fh->vbi_q, buf);
1036 return -EINVAL;
1037}
1038
1039static int vidioc_qbuf(struct file *file, void *__fh, struct v4l2_buffer *buf)
1040{
1041 struct saa7146_fh *fh = __fh;
1042
1043 if (buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1044 return videobuf_qbuf(&fh->video_q, buf);
1045 if (buf->type == V4L2_BUF_TYPE_VBI_CAPTURE)
1046 return videobuf_qbuf(&fh->vbi_q, buf);
1047 return -EINVAL;
1048}
1049
1050static int vidioc_dqbuf(struct file *file, void *__fh, struct v4l2_buffer *buf)
1051{
1052 struct saa7146_fh *fh = __fh;
1053
1054 if (buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1055 return videobuf_dqbuf(&fh->video_q, buf, file->f_flags & O_NONBLOCK);
1056 if (buf->type == V4L2_BUF_TYPE_VBI_CAPTURE)
1057 return videobuf_dqbuf(&fh->vbi_q, buf, file->f_flags & O_NONBLOCK);
1058 return -EINVAL;
1059}
1060
1061static int vidioc_streamon(struct file *file, void *__fh, enum v4l2_buf_type type)
1062{
1063 struct saa7146_fh *fh = __fh;
1064 int err;
1065
1066 DEB_D(("VIDIOC_STREAMON, type:%d\n", type));
1067
1068 err = video_begin(fh);
1069 if (err)
1190 return err; 1070 return err;
1071 if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1072 return videobuf_streamon(&fh->video_q);
1073 if (type == V4L2_BUF_TYPE_VBI_CAPTURE)
1074 return videobuf_streamon(&fh->vbi_q);
1075 return -EINVAL;
1076}
1077
1078static int vidioc_streamoff(struct file *file, void *__fh, enum v4l2_buf_type type)
1079{
1080 struct saa7146_fh *fh = __fh;
1081 struct saa7146_dev *dev = fh->dev;
1082 struct saa7146_vv *vv = dev->vv_data;
1083 int err;
1084
1085 DEB_D(("VIDIOC_STREAMOFF, type:%d\n", type));
1086
1087 /* ugly: we need to copy some checks from video_end(),
1088 because videobuf_streamoff() relies on the capture running.
1089 check and fix this */
1090 if ((vv->video_status & STATUS_CAPTURE) != STATUS_CAPTURE) {
1091 DEB_S(("not capturing.\n"));
1092 return 0;
1191 } 1093 }
1192#ifdef CONFIG_VIDEO_V4L1_COMPAT
1193 case VIDIOCGMBUF:
1194 {
1195 struct video_mbuf *mbuf = arg;
1196 int i;
1197 1094
1198 /* fixme: number of capture buffers and sizes for v4l apps */ 1095 if (vv->video_fh != fh) {
1199 int gbuffers = 2; 1096 DEB_S(("capturing, but in another open.\n"));
1200 int gbufsize = 768*576*4; 1097 return -EBUSY;
1098 }
1201 1099
1202 DEB_D(("VIDIOCGMBUF \n")); 1100 err = -EINVAL;
1101 if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1102 err = videobuf_streamoff(&fh->video_q);
1103 else if (type == V4L2_BUF_TYPE_VBI_CAPTURE)
1104 err = videobuf_streamoff(&fh->vbi_q);
1105 if (0 != err) {
1106 DEB_D(("warning: videobuf_streamoff() failed.\n"));
1107 video_end(fh, file);
1108 } else {
1109 err = video_end(fh, file);
1110 }
1111 return err;
1112}
1203 1113
1204 q = &fh->video_q; 1114static int vidioc_g_chip_ident(struct file *file, void *__fh,
1205 err = videobuf_mmap_setup(q,gbuffers,gbufsize, 1115 struct v4l2_dbg_chip_ident *chip)
1206 V4L2_MEMORY_MMAP); 1116{
1207 if (err < 0) 1117 struct saa7146_fh *fh = __fh;
1208 return err; 1118 struct saa7146_dev *dev = fh->dev;
1209 1119
1210 gbuffers = err; 1120 chip->ident = V4L2_IDENT_NONE;
1211 memset(mbuf,0,sizeof(*mbuf)); 1121 chip->revision = 0;
1212 mbuf->frames = gbuffers; 1122 if (chip->match.type == V4L2_CHIP_MATCH_HOST && !chip->match.addr) {
1213 mbuf->size = gbuffers * gbufsize; 1123 chip->ident = V4L2_IDENT_SAA7146;
1214 for (i = 0; i < gbuffers; i++)
1215 mbuf->offsets[i] = i * gbufsize;
1216 return 0; 1124 return 0;
1217 } 1125 }
1218#endif 1126 return v4l2_device_call_until_err(&dev->v4l2_dev, 0,
1219 default: 1127 core, g_chip_ident, chip);
1220 return v4l_compat_translate_ioctl(file, cmd, arg, 1128}
1221 saa7146_video_do_ioctl); 1129
1222 } 1130#ifdef CONFIG_VIDEO_V4L1_COMPAT
1131static int vidiocgmbuf(struct file *file, void *__fh, struct video_mbuf *mbuf)
1132{
1133 struct saa7146_fh *fh = __fh;
1134 struct videobuf_queue *q = &fh->video_q;
1135 int err, i;
1136
1137 /* fixme: number of capture buffers and sizes for v4l apps */
1138 int gbuffers = 2;
1139 int gbufsize = 768 * 576 * 4;
1140
1141 DEB_D(("VIDIOCGMBUF \n"));
1142
1143 q = &fh->video_q;
1144 err = videobuf_mmap_setup(q, gbuffers, gbufsize,
1145 V4L2_MEMORY_MMAP);
1146 if (err < 0)
1147 return err;
1148
1149 gbuffers = err;
1150 memset(mbuf, 0, sizeof(*mbuf));
1151 mbuf->frames = gbuffers;
1152 mbuf->size = gbuffers * gbufsize;
1153 for (i = 0; i < gbuffers; i++)
1154 mbuf->offsets[i] = i * gbufsize;
1223 return 0; 1155 return 0;
1224} 1156}
1157#endif
1158
1159const struct v4l2_ioctl_ops saa7146_video_ioctl_ops = {
1160 .vidioc_querycap = vidioc_querycap,
1161 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
1162 .vidioc_enum_fmt_vid_overlay = vidioc_enum_fmt_vid_cap,
1163 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
1164 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
1165 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
1166 .vidioc_g_fmt_vid_overlay = vidioc_g_fmt_vid_overlay,
1167 .vidioc_try_fmt_vid_overlay = vidioc_try_fmt_vid_overlay,
1168 .vidioc_s_fmt_vid_overlay = vidioc_s_fmt_vid_overlay,
1169 .vidioc_g_fmt_vbi_cap = vidioc_g_fmt_vbi_cap,
1170 .vidioc_g_chip_ident = vidioc_g_chip_ident,
1171
1172 .vidioc_overlay = vidioc_overlay,
1173 .vidioc_g_fbuf = vidioc_g_fbuf,
1174 .vidioc_s_fbuf = vidioc_s_fbuf,
1175 .vidioc_reqbufs = vidioc_reqbufs,
1176 .vidioc_querybuf = vidioc_querybuf,
1177 .vidioc_qbuf = vidioc_qbuf,
1178 .vidioc_dqbuf = vidioc_dqbuf,
1179 .vidioc_g_std = vidioc_g_std,
1180 .vidioc_s_std = vidioc_s_std,
1181 .vidioc_queryctrl = vidioc_queryctrl,
1182 .vidioc_g_ctrl = vidioc_g_ctrl,
1183 .vidioc_s_ctrl = vidioc_s_ctrl,
1184 .vidioc_streamon = vidioc_streamon,
1185 .vidioc_streamoff = vidioc_streamoff,
1186 .vidioc_g_parm = vidioc_g_parm,
1187#ifdef CONFIG_VIDEO_V4L1_COMPAT
1188 .vidiocgmbuf = vidiocgmbuf,
1189#endif
1190};
1225 1191
1226/*********************************************************************************/ 1192/*********************************************************************************/
1227/* buffer handling functions */ 1193/* buffer handling functions */
diff --git a/drivers/media/common/tuners/Kconfig b/drivers/media/common/tuners/Kconfig
index 6f92beaa5ac8..52c3f65b12d6 100644
--- a/drivers/media/common/tuners/Kconfig
+++ b/drivers/media/common/tuners/Kconfig
@@ -21,16 +21,17 @@ config MEDIA_TUNER
21 tristate 21 tristate
22 default VIDEO_MEDIA && I2C 22 default VIDEO_MEDIA && I2C
23 depends on VIDEO_MEDIA && I2C 23 depends on VIDEO_MEDIA && I2C
24 select MEDIA_TUNER_XC2028 if !MEDIA_TUNER_CUSTOMIZE 24 select MEDIA_TUNER_XC2028 if !MEDIA_TUNER_CUSTOMISE
25 select MEDIA_TUNER_XC5000 if !MEDIA_TUNER_CUSTOMIZE 25 select MEDIA_TUNER_XC5000 if !MEDIA_TUNER_CUSTOMISE
26 select MEDIA_TUNER_MT20XX if !MEDIA_TUNER_CUSTOMIZE 26 select MEDIA_TUNER_MT20XX if !MEDIA_TUNER_CUSTOMISE
27 select MEDIA_TUNER_TDA8290 if !MEDIA_TUNER_CUSTOMIZE 27 select MEDIA_TUNER_TDA8290 if !MEDIA_TUNER_CUSTOMISE
28 select MEDIA_TUNER_TEA5761 if !MEDIA_TUNER_CUSTOMIZE 28 select MEDIA_TUNER_TEA5761 if !MEDIA_TUNER_CUSTOMISE
29 select MEDIA_TUNER_TEA5767 if !MEDIA_TUNER_CUSTOMIZE 29 select MEDIA_TUNER_TEA5767 if !MEDIA_TUNER_CUSTOMISE
30 select MEDIA_TUNER_SIMPLE if !MEDIA_TUNER_CUSTOMIZE 30 select MEDIA_TUNER_SIMPLE if !MEDIA_TUNER_CUSTOMISE
31 select MEDIA_TUNER_TDA9887 if !MEDIA_TUNER_CUSTOMIZE 31 select MEDIA_TUNER_TDA9887 if !MEDIA_TUNER_CUSTOMISE
32 32 select MEDIA_TUNER_MC44S803 if !MEDIA_TUNER_CUSTOMISE
33menuconfig MEDIA_TUNER_CUSTOMIZE 33
34menuconfig MEDIA_TUNER_CUSTOMISE
34 bool "Customize analog and hybrid tuner modules to build" 35 bool "Customize analog and hybrid tuner modules to build"
35 depends on MEDIA_TUNER 36 depends on MEDIA_TUNER
36 default n 37 default n
@@ -43,13 +44,13 @@ menuconfig MEDIA_TUNER_CUSTOMIZE
43 44
44 If unsure say N. 45 If unsure say N.
45 46
46if MEDIA_TUNER_CUSTOMIZE 47if MEDIA_TUNER_CUSTOMISE
47 48
48config MEDIA_TUNER_SIMPLE 49config MEDIA_TUNER_SIMPLE
49 tristate "Simple tuner support" 50 tristate "Simple tuner support"
50 depends on VIDEO_MEDIA && I2C 51 depends on VIDEO_MEDIA && I2C
51 select MEDIA_TUNER_TDA9887 52 select MEDIA_TUNER_TDA9887
52 default m if MEDIA_TUNER_CUSTOMIZE 53 default m if MEDIA_TUNER_CUSTOMISE
53 help 54 help
54 Say Y here to include support for various simple tuners. 55 Say Y here to include support for various simple tuners.
55 56
@@ -58,28 +59,28 @@ config MEDIA_TUNER_TDA8290
58 depends on VIDEO_MEDIA && I2C 59 depends on VIDEO_MEDIA && I2C
59 select MEDIA_TUNER_TDA827X 60 select MEDIA_TUNER_TDA827X
60 select MEDIA_TUNER_TDA18271 61 select MEDIA_TUNER_TDA18271
61 default m if MEDIA_TUNER_CUSTOMIZE 62 default m if MEDIA_TUNER_CUSTOMISE
62 help 63 help
63 Say Y here to include support for Philips TDA8290+8275(a) tuner. 64 Say Y here to include support for Philips TDA8290+8275(a) tuner.
64 65
65config MEDIA_TUNER_TDA827X 66config MEDIA_TUNER_TDA827X
66 tristate "Philips TDA827X silicon tuner" 67 tristate "Philips TDA827X silicon tuner"
67 depends on VIDEO_MEDIA && I2C 68 depends on VIDEO_MEDIA && I2C
68 default m if DVB_FE_CUSTOMISE 69 default m if MEDIA_TUNER_CUSTOMISE
69 help 70 help
70 A DVB-T silicon tuner module. Say Y when you want to support this tuner. 71 A DVB-T silicon tuner module. Say Y when you want to support this tuner.
71 72
72config MEDIA_TUNER_TDA18271 73config MEDIA_TUNER_TDA18271
73 tristate "NXP TDA18271 silicon tuner" 74 tristate "NXP TDA18271 silicon tuner"
74 depends on VIDEO_MEDIA && I2C 75 depends on VIDEO_MEDIA && I2C
75 default m if DVB_FE_CUSTOMISE 76 default m if MEDIA_TUNER_CUSTOMISE
76 help 77 help
77 A silicon tuner module. Say Y when you want to support this tuner. 78 A silicon tuner module. Say Y when you want to support this tuner.
78 79
79config MEDIA_TUNER_TDA9887 80config MEDIA_TUNER_TDA9887
80 tristate "TDA 9885/6/7 analog IF demodulator" 81 tristate "TDA 9885/6/7 analog IF demodulator"
81 depends on VIDEO_MEDIA && I2C 82 depends on VIDEO_MEDIA && I2C
82 default m if MEDIA_TUNER_CUSTOMIZE 83 default m if MEDIA_TUNER_CUSTOMISE
83 help 84 help
84 Say Y here to include support for Philips TDA9885/6/7 85 Say Y here to include support for Philips TDA9885/6/7
85 analog IF demodulator. 86 analog IF demodulator.
@@ -88,63 +89,63 @@ config MEDIA_TUNER_TEA5761
88 tristate "TEA 5761 radio tuner (EXPERIMENTAL)" 89 tristate "TEA 5761 radio tuner (EXPERIMENTAL)"
89 depends on VIDEO_MEDIA && I2C 90 depends on VIDEO_MEDIA && I2C
90 depends on EXPERIMENTAL 91 depends on EXPERIMENTAL
91 default m if MEDIA_TUNER_CUSTOMIZE 92 default m if MEDIA_TUNER_CUSTOMISE
92 help 93 help
93 Say Y here to include support for the Philips TEA5761 radio tuner. 94 Say Y here to include support for the Philips TEA5761 radio tuner.
94 95
95config MEDIA_TUNER_TEA5767 96config MEDIA_TUNER_TEA5767
96 tristate "TEA 5767 radio tuner" 97 tristate "TEA 5767 radio tuner"
97 depends on VIDEO_MEDIA && I2C 98 depends on VIDEO_MEDIA && I2C
98 default m if MEDIA_TUNER_CUSTOMIZE 99 default m if MEDIA_TUNER_CUSTOMISE
99 help 100 help
100 Say Y here to include support for the Philips TEA5767 radio tuner. 101 Say Y here to include support for the Philips TEA5767 radio tuner.
101 102
102config MEDIA_TUNER_MT20XX 103config MEDIA_TUNER_MT20XX
103 tristate "Microtune 2032 / 2050 tuners" 104 tristate "Microtune 2032 / 2050 tuners"
104 depends on VIDEO_MEDIA && I2C 105 depends on VIDEO_MEDIA && I2C
105 default m if MEDIA_TUNER_CUSTOMIZE 106 default m if MEDIA_TUNER_CUSTOMISE
106 help 107 help
107 Say Y here to include support for the MT2032 / MT2050 tuner. 108 Say Y here to include support for the MT2032 / MT2050 tuner.
108 109
109config MEDIA_TUNER_MT2060 110config MEDIA_TUNER_MT2060
110 tristate "Microtune MT2060 silicon IF tuner" 111 tristate "Microtune MT2060 silicon IF tuner"
111 depends on VIDEO_MEDIA && I2C 112 depends on VIDEO_MEDIA && I2C
112 default m if DVB_FE_CUSTOMISE 113 default m if MEDIA_TUNER_CUSTOMISE
113 help 114 help
114 A driver for the silicon IF tuner MT2060 from Microtune. 115 A driver for the silicon IF tuner MT2060 from Microtune.
115 116
116config MEDIA_TUNER_MT2266 117config MEDIA_TUNER_MT2266
117 tristate "Microtune MT2266 silicon tuner" 118 tristate "Microtune MT2266 silicon tuner"
118 depends on VIDEO_MEDIA && I2C 119 depends on VIDEO_MEDIA && I2C
119 default m if DVB_FE_CUSTOMISE 120 default m if MEDIA_TUNER_CUSTOMISE
120 help 121 help
121 A driver for the silicon baseband tuner MT2266 from Microtune. 122 A driver for the silicon baseband tuner MT2266 from Microtune.
122 123
123config MEDIA_TUNER_MT2131 124config MEDIA_TUNER_MT2131
124 tristate "Microtune MT2131 silicon tuner" 125 tristate "Microtune MT2131 silicon tuner"
125 depends on VIDEO_MEDIA && I2C 126 depends on VIDEO_MEDIA && I2C
126 default m if DVB_FE_CUSTOMISE 127 default m if MEDIA_TUNER_CUSTOMISE
127 help 128 help
128 A driver for the silicon baseband tuner MT2131 from Microtune. 129 A driver for the silicon baseband tuner MT2131 from Microtune.
129 130
130config MEDIA_TUNER_QT1010 131config MEDIA_TUNER_QT1010
131 tristate "Quantek QT1010 silicon tuner" 132 tristate "Quantek QT1010 silicon tuner"
132 depends on VIDEO_MEDIA && I2C 133 depends on VIDEO_MEDIA && I2C
133 default m if DVB_FE_CUSTOMISE 134 default m if MEDIA_TUNER_CUSTOMISE
134 help 135 help
135 A driver for the silicon tuner QT1010 from Quantek. 136 A driver for the silicon tuner QT1010 from Quantek.
136 137
137config MEDIA_TUNER_XC2028 138config MEDIA_TUNER_XC2028
138 tristate "XCeive xc2028/xc3028 tuners" 139 tristate "XCeive xc2028/xc3028 tuners"
139 depends on VIDEO_MEDIA && I2C 140 depends on VIDEO_MEDIA && I2C
140 default m if MEDIA_TUNER_CUSTOMIZE 141 default m if MEDIA_TUNER_CUSTOMISE
141 help 142 help
142 Say Y here to include support for the xc2028/xc3028 tuners. 143 Say Y here to include support for the xc2028/xc3028 tuners.
143 144
144config MEDIA_TUNER_XC5000 145config MEDIA_TUNER_XC5000
145 tristate "Xceive XC5000 silicon tuner" 146 tristate "Xceive XC5000 silicon tuner"
146 depends on VIDEO_MEDIA && I2C 147 depends on VIDEO_MEDIA && I2C
147 default m if DVB_FE_CUSTOMISE 148 default m if MEDIA_TUNER_CUSTOMISE
148 help 149 help
149 A driver for the silicon tuner XC5000 from Xceive. 150 A driver for the silicon tuner XC5000 from Xceive.
150 This device is only used inside a SiP called togther with a 151 This device is only used inside a SiP called togther with a
@@ -153,15 +154,22 @@ config MEDIA_TUNER_XC5000
153config MEDIA_TUNER_MXL5005S 154config MEDIA_TUNER_MXL5005S
154 tristate "MaxLinear MSL5005S silicon tuner" 155 tristate "MaxLinear MSL5005S silicon tuner"
155 depends on VIDEO_MEDIA && I2C 156 depends on VIDEO_MEDIA && I2C
156 default m if DVB_FE_CUSTOMISE 157 default m if MEDIA_TUNER_CUSTOMISE
157 help 158 help
158 A driver for the silicon tuner MXL5005S from MaxLinear. 159 A driver for the silicon tuner MXL5005S from MaxLinear.
159 160
160config MEDIA_TUNER_MXL5007T 161config MEDIA_TUNER_MXL5007T
161 tristate "MaxLinear MxL5007T silicon tuner" 162 tristate "MaxLinear MxL5007T silicon tuner"
162 depends on VIDEO_MEDIA && I2C 163 depends on VIDEO_MEDIA && I2C
163 default m if DVB_FE_CUSTOMISE 164 default m if MEDIA_TUNER_CUSTOMISE
164 help 165 help
165 A driver for the silicon tuner MxL5007T from MaxLinear. 166 A driver for the silicon tuner MxL5007T from MaxLinear.
166 167
167endif # MEDIA_TUNER_CUSTOMIZE 168config MEDIA_TUNER_MC44S803
169 tristate "Freescale MC44S803 Low Power CMOS Broadband tuners"
170 depends on VIDEO_MEDIA && I2C
171 default m if MEDIA_TUNER_CUSTOMISE
172 help
173 Say Y here to support the Freescale MC44S803 based tuners
174
175endif # MEDIA_TUNER_CUSTOMISE
diff --git a/drivers/media/common/tuners/Makefile b/drivers/media/common/tuners/Makefile
index 4dfbe5b8264f..4132b2be79e5 100644
--- a/drivers/media/common/tuners/Makefile
+++ b/drivers/media/common/tuners/Makefile
@@ -22,6 +22,7 @@ obj-$(CONFIG_MEDIA_TUNER_QT1010) += qt1010.o
22obj-$(CONFIG_MEDIA_TUNER_MT2131) += mt2131.o 22obj-$(CONFIG_MEDIA_TUNER_MT2131) += mt2131.o
23obj-$(CONFIG_MEDIA_TUNER_MXL5005S) += mxl5005s.o 23obj-$(CONFIG_MEDIA_TUNER_MXL5005S) += mxl5005s.o
24obj-$(CONFIG_MEDIA_TUNER_MXL5007T) += mxl5007t.o 24obj-$(CONFIG_MEDIA_TUNER_MXL5007T) += mxl5007t.o
25obj-$(CONFIG_MEDIA_TUNER_MC44S803) += mc44s803.o
25 26
26EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core 27EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
27EXTRA_CFLAGS += -Idrivers/media/dvb/frontends 28EXTRA_CFLAGS += -Idrivers/media/dvb/frontends
diff --git a/drivers/media/common/tuners/mc44s803.c b/drivers/media/common/tuners/mc44s803.c
new file mode 100644
index 000000000000..20c4485ce16a
--- /dev/null
+++ b/drivers/media/common/tuners/mc44s803.c
@@ -0,0 +1,371 @@
1/*
2 * Driver for Freescale MC44S803 Low Power CMOS Broadband Tuner
3 *
4 * Copyright (c) 2009 Jochen Friedrich <jochen@scram.de>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * 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/module.h>
23#include <linux/delay.h>
24#include <linux/dvb/frontend.h>
25#include <linux/i2c.h>
26
27#include "dvb_frontend.h"
28
29#include "mc44s803.h"
30#include "mc44s803_priv.h"
31
32#define mc_printk(level, format, arg...) \
33 printk(level "mc44s803: " format , ## arg)
34
35/* Writes a single register */
36static int mc44s803_writereg(struct mc44s803_priv *priv, u32 val)
37{
38 u8 buf[3];
39 struct i2c_msg msg = {
40 .addr = priv->cfg->i2c_address, .flags = 0, .buf = buf, .len = 3
41 };
42
43 buf[0] = (val & 0xff0000) >> 16;
44 buf[1] = (val & 0xff00) >> 8;
45 buf[2] = (val & 0xff);
46
47 if (i2c_transfer(priv->i2c, &msg, 1) != 1) {
48 mc_printk(KERN_WARNING, "I2C write failed\n");
49 return -EREMOTEIO;
50 }
51 return 0;
52}
53
54/* Reads a single register */
55static int mc44s803_readreg(struct mc44s803_priv *priv, u8 reg, u32 *val)
56{
57 u32 wval;
58 u8 buf[3];
59 int ret;
60 struct i2c_msg msg[] = {
61 { .addr = priv->cfg->i2c_address, .flags = I2C_M_RD,
62 .buf = buf, .len = 3 },
63 };
64
65 wval = MC44S803_REG_SM(MC44S803_REG_DATAREG, MC44S803_ADDR) |
66 MC44S803_REG_SM(reg, MC44S803_D);
67
68 ret = mc44s803_writereg(priv, wval);
69 if (ret)
70 return ret;
71
72 if (i2c_transfer(priv->i2c, msg, 1) != 1) {
73 mc_printk(KERN_WARNING, "I2C read failed\n");
74 return -EREMOTEIO;
75 }
76
77 *val = (buf[0] << 16) | (buf[1] << 8) | buf[2];
78
79 return 0;
80}
81
82static int mc44s803_release(struct dvb_frontend *fe)
83{
84 struct mc44s803_priv *priv = fe->tuner_priv;
85
86 fe->tuner_priv = NULL;
87 kfree(priv);
88
89 return 0;
90}
91
92static int mc44s803_init(struct dvb_frontend *fe)
93{
94 struct mc44s803_priv *priv = fe->tuner_priv;
95 u32 val;
96 int err;
97
98 if (fe->ops.i2c_gate_ctrl)
99 fe->ops.i2c_gate_ctrl(fe, 1);
100
101/* Reset chip */
102 val = MC44S803_REG_SM(MC44S803_REG_RESET, MC44S803_ADDR) |
103 MC44S803_REG_SM(1, MC44S803_RS);
104
105 err = mc44s803_writereg(priv, val);
106 if (err)
107 goto exit;
108
109 val = MC44S803_REG_SM(MC44S803_REG_RESET, MC44S803_ADDR);
110
111 err = mc44s803_writereg(priv, val);
112 if (err)
113 goto exit;
114
115/* Power Up and Start Osc */
116
117 val = MC44S803_REG_SM(MC44S803_REG_REFOSC, MC44S803_ADDR) |
118 MC44S803_REG_SM(0xC0, MC44S803_REFOSC) |
119 MC44S803_REG_SM(1, MC44S803_OSCSEL);
120
121 err = mc44s803_writereg(priv, val);
122 if (err)
123 goto exit;
124
125 val = MC44S803_REG_SM(MC44S803_REG_POWER, MC44S803_ADDR) |
126 MC44S803_REG_SM(0x200, MC44S803_POWER);
127
128 err = mc44s803_writereg(priv, val);
129 if (err)
130 goto exit;
131
132 msleep(10);
133
134 val = MC44S803_REG_SM(MC44S803_REG_REFOSC, MC44S803_ADDR) |
135 MC44S803_REG_SM(0x40, MC44S803_REFOSC) |
136 MC44S803_REG_SM(1, MC44S803_OSCSEL);
137
138 err = mc44s803_writereg(priv, val);
139 if (err)
140 goto exit;
141
142 msleep(20);
143
144/* Setup Mixer */
145
146 val = MC44S803_REG_SM(MC44S803_REG_MIXER, MC44S803_ADDR) |
147 MC44S803_REG_SM(1, MC44S803_TRI_STATE) |
148 MC44S803_REG_SM(0x7F, MC44S803_MIXER_RES);
149
150 err = mc44s803_writereg(priv, val);
151 if (err)
152 goto exit;
153
154/* Setup Cirquit Adjust */
155
156 val = MC44S803_REG_SM(MC44S803_REG_CIRCADJ, MC44S803_ADDR) |
157 MC44S803_REG_SM(1, MC44S803_G1) |
158 MC44S803_REG_SM(1, MC44S803_G3) |
159 MC44S803_REG_SM(0x3, MC44S803_CIRCADJ_RES) |
160 MC44S803_REG_SM(1, MC44S803_G6) |
161 MC44S803_REG_SM(priv->cfg->dig_out, MC44S803_S1) |
162 MC44S803_REG_SM(0x3, MC44S803_LP) |
163 MC44S803_REG_SM(1, MC44S803_CLRF) |
164 MC44S803_REG_SM(1, MC44S803_CLIF);
165
166 err = mc44s803_writereg(priv, val);
167 if (err)
168 goto exit;
169
170 val = MC44S803_REG_SM(MC44S803_REG_CIRCADJ, MC44S803_ADDR) |
171 MC44S803_REG_SM(1, MC44S803_G1) |
172 MC44S803_REG_SM(1, MC44S803_G3) |
173 MC44S803_REG_SM(0x3, MC44S803_CIRCADJ_RES) |
174 MC44S803_REG_SM(1, MC44S803_G6) |
175 MC44S803_REG_SM(priv->cfg->dig_out, MC44S803_S1) |
176 MC44S803_REG_SM(0x3, MC44S803_LP);
177
178 err = mc44s803_writereg(priv, val);
179 if (err)
180 goto exit;
181
182/* Setup Digtune */
183
184 val = MC44S803_REG_SM(MC44S803_REG_DIGTUNE, MC44S803_ADDR) |
185 MC44S803_REG_SM(3, MC44S803_XOD);
186
187 err = mc44s803_writereg(priv, val);
188 if (err)
189 goto exit;
190
191/* Setup AGC */
192
193 val = MC44S803_REG_SM(MC44S803_REG_LNAAGC, MC44S803_ADDR) |
194 MC44S803_REG_SM(1, MC44S803_AT1) |
195 MC44S803_REG_SM(1, MC44S803_AT2) |
196 MC44S803_REG_SM(1, MC44S803_AGC_AN_DIG) |
197 MC44S803_REG_SM(1, MC44S803_AGC_READ_EN) |
198 MC44S803_REG_SM(1, MC44S803_LNA0);
199
200 err = mc44s803_writereg(priv, val);
201 if (err)
202 goto exit;
203
204 if (fe->ops.i2c_gate_ctrl)
205 fe->ops.i2c_gate_ctrl(fe, 0);
206 return 0;
207
208exit:
209 if (fe->ops.i2c_gate_ctrl)
210 fe->ops.i2c_gate_ctrl(fe, 0);
211
212 mc_printk(KERN_WARNING, "I/O Error\n");
213 return err;
214}
215
216static int mc44s803_set_params(struct dvb_frontend *fe,
217 struct dvb_frontend_parameters *params)
218{
219 struct mc44s803_priv *priv = fe->tuner_priv;
220 u32 r1, r2, n1, n2, lo1, lo2, freq, val;
221 int err;
222
223 priv->frequency = params->frequency;
224
225 r1 = MC44S803_OSC / 1000000;
226 r2 = MC44S803_OSC / 100000;
227
228 n1 = (params->frequency + MC44S803_IF1 + 500000) / 1000000;
229 freq = MC44S803_OSC / r1 * n1;
230 lo1 = ((60 * n1) + (r1 / 2)) / r1;
231 freq = freq - params->frequency;
232
233 n2 = (freq - MC44S803_IF2 + 50000) / 100000;
234 lo2 = ((60 * n2) + (r2 / 2)) / r2;
235
236 if (fe->ops.i2c_gate_ctrl)
237 fe->ops.i2c_gate_ctrl(fe, 1);
238
239 val = MC44S803_REG_SM(MC44S803_REG_REFDIV, MC44S803_ADDR) |
240 MC44S803_REG_SM(r1-1, MC44S803_R1) |
241 MC44S803_REG_SM(r2-1, MC44S803_R2) |
242 MC44S803_REG_SM(1, MC44S803_REFBUF_EN);
243
244 err = mc44s803_writereg(priv, val);
245 if (err)
246 goto exit;
247
248 val = MC44S803_REG_SM(MC44S803_REG_LO1, MC44S803_ADDR) |
249 MC44S803_REG_SM(n1-2, MC44S803_LO1);
250
251 err = mc44s803_writereg(priv, val);
252 if (err)
253 goto exit;
254
255 val = MC44S803_REG_SM(MC44S803_REG_LO2, MC44S803_ADDR) |
256 MC44S803_REG_SM(n2-2, MC44S803_LO2);
257
258 err = mc44s803_writereg(priv, val);
259 if (err)
260 goto exit;
261
262 val = MC44S803_REG_SM(MC44S803_REG_DIGTUNE, MC44S803_ADDR) |
263 MC44S803_REG_SM(1, MC44S803_DA) |
264 MC44S803_REG_SM(lo1, MC44S803_LO_REF) |
265 MC44S803_REG_SM(1, MC44S803_AT);
266
267 err = mc44s803_writereg(priv, val);
268 if (err)
269 goto exit;
270
271 val = MC44S803_REG_SM(MC44S803_REG_DIGTUNE, MC44S803_ADDR) |
272 MC44S803_REG_SM(2, MC44S803_DA) |
273 MC44S803_REG_SM(lo2, MC44S803_LO_REF) |
274 MC44S803_REG_SM(1, MC44S803_AT);
275
276 err = mc44s803_writereg(priv, val);
277 if (err)
278 goto exit;
279
280 if (fe->ops.i2c_gate_ctrl)
281 fe->ops.i2c_gate_ctrl(fe, 0);
282
283 return 0;
284
285exit:
286 if (fe->ops.i2c_gate_ctrl)
287 fe->ops.i2c_gate_ctrl(fe, 0);
288
289 mc_printk(KERN_WARNING, "I/O Error\n");
290 return err;
291}
292
293static int mc44s803_get_frequency(struct dvb_frontend *fe, u32 *frequency)
294{
295 struct mc44s803_priv *priv = fe->tuner_priv;
296 *frequency = priv->frequency;
297 return 0;
298}
299
300static const struct dvb_tuner_ops mc44s803_tuner_ops = {
301 .info = {
302 .name = "Freescale MC44S803",
303 .frequency_min = 48000000,
304 .frequency_max = 1000000000,
305 .frequency_step = 100000,
306 },
307
308 .release = mc44s803_release,
309 .init = mc44s803_init,
310 .set_params = mc44s803_set_params,
311 .get_frequency = mc44s803_get_frequency
312};
313
314/* This functions tries to identify a MC44S803 tuner by reading the ID
315 register. This is hasty. */
316struct dvb_frontend *mc44s803_attach(struct dvb_frontend *fe,
317 struct i2c_adapter *i2c, struct mc44s803_config *cfg)
318{
319 struct mc44s803_priv *priv;
320 u32 reg;
321 u8 id;
322 int ret;
323
324 reg = 0;
325
326 priv = kzalloc(sizeof(struct mc44s803_priv), GFP_KERNEL);
327 if (priv == NULL)
328 return NULL;
329
330 priv->cfg = cfg;
331 priv->i2c = i2c;
332 priv->fe = fe;
333
334 if (fe->ops.i2c_gate_ctrl)
335 fe->ops.i2c_gate_ctrl(fe, 1); /* open i2c_gate */
336
337 ret = mc44s803_readreg(priv, MC44S803_REG_ID, &reg);
338 if (ret)
339 goto error;
340
341 id = MC44S803_REG_MS(reg, MC44S803_ID);
342
343 if (id != 0x14) {
344 mc_printk(KERN_ERR, "unsupported ID "
345 "(%x should be 0x14)\n", id);
346 goto error;
347 }
348
349 mc_printk(KERN_INFO, "successfully identified (ID = %x)\n", id);
350 memcpy(&fe->ops.tuner_ops, &mc44s803_tuner_ops,
351 sizeof(struct dvb_tuner_ops));
352
353 fe->tuner_priv = priv;
354
355 if (fe->ops.i2c_gate_ctrl)
356 fe->ops.i2c_gate_ctrl(fe, 0); /* close i2c_gate */
357
358 return fe;
359
360error:
361 if (fe->ops.i2c_gate_ctrl)
362 fe->ops.i2c_gate_ctrl(fe, 0); /* close i2c_gate */
363
364 kfree(priv);
365 return NULL;
366}
367EXPORT_SYMBOL(mc44s803_attach);
368
369MODULE_AUTHOR("Jochen Friedrich");
370MODULE_DESCRIPTION("Freescale MC44S803 silicon tuner driver");
371MODULE_LICENSE("GPL");
diff --git a/drivers/media/common/tuners/mc44s803.h b/drivers/media/common/tuners/mc44s803.h
new file mode 100644
index 000000000000..34f3892d3f6d
--- /dev/null
+++ b/drivers/media/common/tuners/mc44s803.h
@@ -0,0 +1,46 @@
1/*
2 * Driver for Freescale MC44S803 Low Power CMOS Broadband Tuner
3 *
4 * Copyright (c) 2009 Jochen Friedrich <jochen@scram.de>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * 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 MC44S803_H
23#define MC44S803_H
24
25struct dvb_frontend;
26struct i2c_adapter;
27
28struct mc44s803_config {
29 u8 i2c_address;
30 u8 dig_out;
31};
32
33#if defined(CONFIG_MEDIA_TUNER_MC44S803) || \
34 (defined(CONFIG_MEDIA_TUNER_MC44S803_MODULE) && defined(MODULE))
35extern struct dvb_frontend *mc44s803_attach(struct dvb_frontend *fe,
36 struct i2c_adapter *i2c, struct mc44s803_config *cfg);
37#else
38static inline struct dvb_frontend *mc44s803_attach(struct dvb_frontend *fe,
39 struct i2c_adapter *i2c, struct mc44s803_config *cfg)
40{
41 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
42 return NULL;
43}
44#endif /* CONFIG_MEDIA_TUNER_MC44S803 */
45
46#endif
diff --git a/drivers/media/common/tuners/mc44s803_priv.h b/drivers/media/common/tuners/mc44s803_priv.h
new file mode 100644
index 000000000000..14a92780906d
--- /dev/null
+++ b/drivers/media/common/tuners/mc44s803_priv.h
@@ -0,0 +1,208 @@
1/*
2 * Driver for Freescale MC44S803 Low Power CMOS Broadband Tuner
3 *
4 * Copyright (c) 2009 Jochen Friedrich <jochen@scram.de>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * 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 MC44S803_PRIV_H
23#define MC44S803_PRIV_H
24
25/* This driver is based on the information available in the datasheet
26 http://www.freescale.com/files/rf_if/doc/data_sheet/MC44S803.pdf
27
28 SPI or I2C Address : 0xc0-0xc6
29
30 Reg.No | Function
31 -------------------------------------------
32 00 | Power Down
33 01 | Reference Oszillator
34 02 | Reference Dividers
35 03 | Mixer and Reference Buffer
36 04 | Reset/Serial Out
37 05 | LO 1
38 06 | LO 2
39 07 | Circuit Adjust
40 08 | Test
41 09 | Digital Tune
42 0A | LNA AGC
43 0B | Data Register Address
44 0C | Regulator Test
45 0D | VCO Test
46 0E | LNA Gain/Input Power
47 0F | ID Bits
48
49*/
50
51#define MC44S803_OSC 26000000 /* 26 MHz */
52#define MC44S803_IF1 1086000000 /* 1086 MHz */
53#define MC44S803_IF2 36125000 /* 36.125 MHz */
54
55#define MC44S803_REG_POWER 0
56#define MC44S803_REG_REFOSC 1
57#define MC44S803_REG_REFDIV 2
58#define MC44S803_REG_MIXER 3
59#define MC44S803_REG_RESET 4
60#define MC44S803_REG_LO1 5
61#define MC44S803_REG_LO2 6
62#define MC44S803_REG_CIRCADJ 7
63#define MC44S803_REG_TEST 8
64#define MC44S803_REG_DIGTUNE 9
65#define MC44S803_REG_LNAAGC 0x0A
66#define MC44S803_REG_DATAREG 0x0B
67#define MC44S803_REG_REGTEST 0x0C
68#define MC44S803_REG_VCOTEST 0x0D
69#define MC44S803_REG_LNAGAIN 0x0E
70#define MC44S803_REG_ID 0x0F
71
72/* Register definitions */
73#define MC44S803_ADDR 0x0F
74#define MC44S803_ADDR_S 0
75/* REG_POWER */
76#define MC44S803_POWER 0xFFFFF0
77#define MC44S803_POWER_S 4
78/* REG_REFOSC */
79#define MC44S803_REFOSC 0x1FF0
80#define MC44S803_REFOSC_S 4
81#define MC44S803_OSCSEL 0x2000
82#define MC44S803_OSCSEL_S 13
83/* REG_REFDIV */
84#define MC44S803_R2 0x1FF0
85#define MC44S803_R2_S 4
86#define MC44S803_REFBUF_EN 0x2000
87#define MC44S803_REFBUF_EN_S 13
88#define MC44S803_R1 0x7C000
89#define MC44S803_R1_S 14
90/* REG_MIXER */
91#define MC44S803_R3 0x70
92#define MC44S803_R3_S 4
93#define MC44S803_MUX3 0x80
94#define MC44S803_MUX3_S 7
95#define MC44S803_MUX4 0x100
96#define MC44S803_MUX4_S 8
97#define MC44S803_OSC_SCR 0x200
98#define MC44S803_OSC_SCR_S 9
99#define MC44S803_TRI_STATE 0x400
100#define MC44S803_TRI_STATE_S 10
101#define MC44S803_BUF_GAIN 0x800
102#define MC44S803_BUF_GAIN_S 11
103#define MC44S803_BUF_IO 0x1000
104#define MC44S803_BUF_IO_S 12
105#define MC44S803_MIXER_RES 0xFE000
106#define MC44S803_MIXER_RES_S 13
107/* REG_RESET */
108#define MC44S803_RS 0x10
109#define MC44S803_RS_S 4
110#define MC44S803_SO 0x20
111#define MC44S803_SO_S 5
112/* REG_LO1 */
113#define MC44S803_LO1 0xFFF0
114#define MC44S803_LO1_S 4
115/* REG_LO2 */
116#define MC44S803_LO2 0x7FFF0
117#define MC44S803_LO2_S 4
118/* REG_CIRCADJ */
119#define MC44S803_G1 0x20
120#define MC44S803_G1_S 5
121#define MC44S803_G3 0x80
122#define MC44S803_G3_S 7
123#define MC44S803_CIRCADJ_RES 0x300
124#define MC44S803_CIRCADJ_RES_S 8
125#define MC44S803_G6 0x400
126#define MC44S803_G6_S 10
127#define MC44S803_G7 0x800
128#define MC44S803_G7_S 11
129#define MC44S803_S1 0x1000
130#define MC44S803_S1_S 12
131#define MC44S803_LP 0x7E000
132#define MC44S803_LP_S 13
133#define MC44S803_CLRF 0x80000
134#define MC44S803_CLRF_S 19
135#define MC44S803_CLIF 0x100000
136#define MC44S803_CLIF_S 20
137/* REG_TEST */
138/* REG_DIGTUNE */
139#define MC44S803_DA 0xF0
140#define MC44S803_DA_S 4
141#define MC44S803_XOD 0x300
142#define MC44S803_XOD_S 8
143#define MC44S803_RST 0x10000
144#define MC44S803_RST_S 16
145#define MC44S803_LO_REF 0x1FFF00
146#define MC44S803_LO_REF_S 8
147#define MC44S803_AT 0x200000
148#define MC44S803_AT_S 21
149#define MC44S803_MT 0x400000
150#define MC44S803_MT_S 22
151/* REG_LNAAGC */
152#define MC44S803_G 0x3F0
153#define MC44S803_G_S 4
154#define MC44S803_AT1 0x400
155#define MC44S803_AT1_S 10
156#define MC44S803_AT2 0x800
157#define MC44S803_AT2_S 11
158#define MC44S803_HL_GR_EN 0x8000
159#define MC44S803_HL_GR_EN_S 15
160#define MC44S803_AGC_AN_DIG 0x10000
161#define MC44S803_AGC_AN_DIG_S 16
162#define MC44S803_ATTEN_EN 0x20000
163#define MC44S803_ATTEN_EN_S 17
164#define MC44S803_AGC_READ_EN 0x40000
165#define MC44S803_AGC_READ_EN_S 18
166#define MC44S803_LNA0 0x80000
167#define MC44S803_LNA0_S 19
168#define MC44S803_AGC_SEL 0x100000
169#define MC44S803_AGC_SEL_S 20
170#define MC44S803_AT0 0x200000
171#define MC44S803_AT0_S 21
172#define MC44S803_B 0xC00000
173#define MC44S803_B_S 22
174/* REG_DATAREG */
175#define MC44S803_D 0xF0
176#define MC44S803_D_S 4
177/* REG_REGTEST */
178/* REG_VCOTEST */
179/* REG_LNAGAIN */
180#define MC44S803_IF_PWR 0x700
181#define MC44S803_IF_PWR_S 8
182#define MC44S803_RF_PWR 0x3800
183#define MC44S803_RF_PWR_S 11
184#define MC44S803_LNA_GAIN 0xFC000
185#define MC44S803_LNA_GAIN_S 14
186/* REG_ID */
187#define MC44S803_ID 0x3E00
188#define MC44S803_ID_S 9
189
190/* Some macros to read/write fields */
191
192/* First shift, then mask */
193#define MC44S803_REG_SM(_val, _reg) \
194 (((_val) << _reg##_S) & (_reg))
195
196/* First mask, then shift */
197#define MC44S803_REG_MS(_val, _reg) \
198 (((_val) & (_reg)) >> _reg##_S)
199
200struct mc44s803_priv {
201 struct mc44s803_config *cfg;
202 struct i2c_adapter *i2c;
203 struct dvb_frontend *fe;
204
205 u32 frequency;
206};
207
208#endif
diff --git a/drivers/media/common/tuners/mt2060.c b/drivers/media/common/tuners/mt2060.c
index 12206d75dd4e..c7abe3d8f90e 100644
--- a/drivers/media/common/tuners/mt2060.c
+++ b/drivers/media/common/tuners/mt2060.c
@@ -278,7 +278,7 @@ static void mt2060_calibrate(struct mt2060_priv *priv)
278 while (i++ < 10 && mt2060_readreg(priv, REG_MISC_STAT, &b) == 0 && (b & (1 << 6)) == 0) 278 while (i++ < 10 && mt2060_readreg(priv, REG_MISC_STAT, &b) == 0 && (b & (1 << 6)) == 0)
279 msleep(20); 279 msleep(20);
280 280
281 if (i < 10) { 281 if (i <= 10) {
282 mt2060_readreg(priv, REG_FM_FREQ, &priv->fmfreq); // now find out, what is fmreq used for :) 282 mt2060_readreg(priv, REG_FM_FREQ, &priv->fmfreq); // now find out, what is fmreq used for :)
283 dprintk("calibration was successful: %d", (int)priv->fmfreq); 283 dprintk("calibration was successful: %d", (int)priv->fmfreq);
284 } else 284 } else
diff --git a/drivers/media/common/tuners/mt20xx.c b/drivers/media/common/tuners/mt20xx.c
index 35b763a16d53..44608ad4e2d2 100644
--- a/drivers/media/common/tuners/mt20xx.c
+++ b/drivers/media/common/tuners/mt20xx.c
@@ -6,7 +6,7 @@
6 */ 6 */
7#include <linux/delay.h> 7#include <linux/delay.h>
8#include <linux/i2c.h> 8#include <linux/i2c.h>
9#include <linux/videodev.h> 9#include <linux/videodev2.h>
10#include "tuner-i2c.h" 10#include "tuner-i2c.h"
11#include "mt20xx.h" 11#include "mt20xx.h"
12 12
diff --git a/drivers/media/common/tuners/mxl5005s.c b/drivers/media/common/tuners/mxl5005s.c
index 31522d2e318e..0803dab58fff 100644
--- a/drivers/media/common/tuners/mxl5005s.c
+++ b/drivers/media/common/tuners/mxl5005s.c
@@ -4003,12 +4003,11 @@ static int mxl5005s_set_params(struct dvb_frontend *fe,
4003 /* Change tuner for new modulation type if reqd */ 4003 /* Change tuner for new modulation type if reqd */
4004 if (req_mode != state->current_mode) { 4004 if (req_mode != state->current_mode) {
4005 switch (req_mode) { 4005 switch (req_mode) {
4006 case VSB_8: 4006 case MXL_ATSC:
4007 case QAM_64: 4007 case MXL_QAM:
4008 case QAM_256:
4009 case QAM_AUTO:
4010 req_bw = MXL5005S_BANDWIDTH_6MHZ; 4008 req_bw = MXL5005S_BANDWIDTH_6MHZ;
4011 break; 4009 break;
4010 case MXL_DVBT:
4012 default: 4011 default:
4013 /* Assume DVB-T */ 4012 /* Assume DVB-T */
4014 switch (params->u.ofdm.bandwidth) { 4013 switch (params->u.ofdm.bandwidth) {
diff --git a/drivers/media/common/tuners/mxl5007t.c b/drivers/media/common/tuners/mxl5007t.c
index 3ec28945c26f..2d02698d4f4f 100644
--- a/drivers/media/common/tuners/mxl5007t.c
+++ b/drivers/media/common/tuners/mxl5007t.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * mxl5007t.c - driver for the MaxLinear MxL5007T silicon tuner 2 * mxl5007t.c - driver for the MaxLinear MxL5007T silicon tuner
3 * 3 *
4 * Copyright (C) 2008 Michael Krufky <mkrufky@linuxtv.org> 4 * Copyright (C) 2008, 2009 Michael Krufky <mkrufky@linuxtv.org>
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
@@ -66,22 +66,17 @@ MODULE_PARM_DESC(debug, "set debug level");
66#define MHz 1000000 66#define MHz 1000000
67 67
68enum mxl5007t_mode { 68enum mxl5007t_mode {
69 MxL_MODE_OTA_DVBT_ATSC = 0, 69 MxL_MODE_ISDBT = 0,
70 MxL_MODE_OTA_NTSC_PAL_GH = 1, 70 MxL_MODE_DVBT = 1,
71 MxL_MODE_OTA_PAL_IB = 2, 71 MxL_MODE_ATSC = 2,
72 MxL_MODE_OTA_PAL_D_SECAM_KL = 3, 72 MxL_MODE_CABLE = 0x10,
73 MxL_MODE_OTA_ISDBT = 4,
74 MxL_MODE_CABLE_DIGITAL = 0x10,
75 MxL_MODE_CABLE_NTSC_PAL_GH = 0x11,
76 MxL_MODE_CABLE_PAL_IB = 0x12,
77 MxL_MODE_CABLE_PAL_D_SECAM_KL = 0x13,
78 MxL_MODE_CABLE_SCTE40 = 0x14,
79}; 73};
80 74
81enum mxl5007t_chip_version { 75enum mxl5007t_chip_version {
82 MxL_UNKNOWN_ID = 0x00, 76 MxL_UNKNOWN_ID = 0x00,
83 MxL_5007_V1_F1 = 0x11, 77 MxL_5007_V1_F1 = 0x11,
84 MxL_5007_V1_F2 = 0x12, 78 MxL_5007_V1_F2 = 0x12,
79 MxL_5007_V4 = 0x14,
85 MxL_5007_V2_100_F1 = 0x21, 80 MxL_5007_V2_100_F1 = 0x21,
86 MxL_5007_V2_100_F2 = 0x22, 81 MxL_5007_V2_100_F2 = 0x22,
87 MxL_5007_V2_200_F1 = 0x23, 82 MxL_5007_V2_200_F1 = 0x23,
@@ -96,67 +91,61 @@ struct reg_pair_t {
96/* ------------------------------------------------------------------------- */ 91/* ------------------------------------------------------------------------- */
97 92
98static struct reg_pair_t init_tab[] = { 93static struct reg_pair_t init_tab[] = {
99 { 0x0b, 0x44 }, /* XTAL */ 94 { 0x02, 0x06 },
100 { 0x0c, 0x60 }, /* IF */ 95 { 0x03, 0x48 },
101 { 0x10, 0x00 }, /* MISC */ 96 { 0x05, 0x04 },
102 { 0x12, 0xca }, /* IDAC */ 97 { 0x06, 0x10 },
103 { 0x16, 0x90 }, /* MODE */ 98 { 0x2e, 0x15 }, /* OVERRIDE */
104 { 0x32, 0x38 }, /* MODE Analog/Digital */ 99 { 0x30, 0x10 }, /* OVERRIDE */
105 { 0xd8, 0x18 }, /* CLK_OUT_ENABLE */ 100 { 0x45, 0x58 }, /* OVERRIDE */
106 { 0x2c, 0x34 }, /* OVERRIDE */ 101 { 0x48, 0x19 }, /* OVERRIDE */
107 { 0x4d, 0x40 }, /* OVERRIDE */ 102 { 0x52, 0x03 }, /* OVERRIDE */
108 { 0x7f, 0x02 }, /* OVERRIDE */ 103 { 0x53, 0x44 }, /* OVERRIDE */
109 { 0x9a, 0x52 }, /* OVERRIDE */ 104 { 0x6a, 0x4b }, /* OVERRIDE */
110 { 0x48, 0x5a }, /* OVERRIDE */ 105 { 0x76, 0x00 }, /* OVERRIDE */
111 { 0x76, 0x1a }, /* OVERRIDE */ 106 { 0x78, 0x18 }, /* OVERRIDE */
112 { 0x6a, 0x48 }, /* OVERRIDE */ 107 { 0x7a, 0x17 }, /* OVERRIDE */
113 { 0x64, 0x28 }, /* OVERRIDE */ 108 { 0x85, 0x06 }, /* OVERRIDE */
114 { 0x66, 0xe6 }, /* OVERRIDE */ 109 { 0x01, 0x01 }, /* TOP_MASTER_ENABLE */
115 { 0x35, 0x0e }, /* OVERRIDE */
116 { 0x7e, 0x01 }, /* OVERRIDE */
117 { 0x83, 0x00 }, /* OVERRIDE */
118 { 0x04, 0x0b }, /* OVERRIDE */
119 { 0x05, 0x01 }, /* TOP_MASTER_ENABLE */
120 { 0, 0 } 110 { 0, 0 }
121}; 111};
122 112
123static struct reg_pair_t init_tab_cable[] = { 113static struct reg_pair_t init_tab_cable[] = {
124 { 0x0b, 0x44 }, /* XTAL */ 114 { 0x02, 0x06 },
125 { 0x0c, 0x60 }, /* IF */ 115 { 0x03, 0x48 },
126 { 0x10, 0x00 }, /* MISC */ 116 { 0x05, 0x04 },
127 { 0x12, 0xca }, /* IDAC */ 117 { 0x06, 0x10 },
128 { 0x16, 0x90 }, /* MODE */ 118 { 0x09, 0x3f },
129 { 0x32, 0x38 }, /* MODE A/D */ 119 { 0x0a, 0x3f },
130 { 0x71, 0x3f }, /* TOP1 */ 120 { 0x0b, 0x3f },
131 { 0x72, 0x3f }, /* TOP2 */ 121 { 0x2e, 0x15 }, /* OVERRIDE */
132 { 0x74, 0x3f }, /* TOP3 */ 122 { 0x30, 0x10 }, /* OVERRIDE */
133 { 0xd8, 0x18 }, /* CLK_OUT_ENABLE */ 123 { 0x45, 0x58 }, /* OVERRIDE */
134 { 0x2c, 0x34 }, /* OVERRIDE */ 124 { 0x48, 0x19 }, /* OVERRIDE */
135 { 0x4d, 0x40 }, /* OVERRIDE */ 125 { 0x52, 0x03 }, /* OVERRIDE */
136 { 0x7f, 0x02 }, /* OVERRIDE */ 126 { 0x53, 0x44 }, /* OVERRIDE */
137 { 0x9a, 0x52 }, /* OVERRIDE */ 127 { 0x6a, 0x4b }, /* OVERRIDE */
138 { 0x48, 0x5a }, /* OVERRIDE */ 128 { 0x76, 0x00 }, /* OVERRIDE */
139 { 0x76, 0x1a }, /* OVERRIDE */ 129 { 0x78, 0x18 }, /* OVERRIDE */
140 { 0x6a, 0x48 }, /* OVERRIDE */ 130 { 0x7a, 0x17 }, /* OVERRIDE */
141 { 0x64, 0x28 }, /* OVERRIDE */ 131 { 0x85, 0x06 }, /* OVERRIDE */
142 { 0x66, 0xe6 }, /* OVERRIDE */ 132 { 0x01, 0x01 }, /* TOP_MASTER_ENABLE */
143 { 0x35, 0x0e }, /* OVERRIDE */
144 { 0x7e, 0x01 }, /* OVERRIDE */
145 { 0x04, 0x0b }, /* OVERRIDE */
146 { 0x68, 0xb4 }, /* OVERRIDE */
147 { 0x36, 0x00 }, /* OVERRIDE */
148 { 0x05, 0x01 }, /* TOP_MASTER_ENABLE */
149 { 0, 0 } 133 { 0, 0 }
150}; 134};
151 135
152/* ------------------------------------------------------------------------- */ 136/* ------------------------------------------------------------------------- */
153 137
154static struct reg_pair_t reg_pair_rftune[] = { 138static struct reg_pair_t reg_pair_rftune[] = {
155 { 0x11, 0x00 }, /* abort tune */ 139 { 0x0f, 0x00 }, /* abort tune */
156 { 0x13, 0x15 }, 140 { 0x0c, 0x15 },
157 { 0x14, 0x40 }, 141 { 0x0d, 0x40 },
158 { 0x15, 0x0e }, 142 { 0x0e, 0x0e },
159 { 0x11, 0x02 }, /* start tune */ 143 { 0x1f, 0x87 }, /* OVERRIDE */
144 { 0x20, 0x1f }, /* OVERRIDE */
145 { 0x21, 0x87 }, /* OVERRIDE */
146 { 0x22, 0x1f }, /* OVERRIDE */
147 { 0x80, 0x01 }, /* freq dependent */
148 { 0x0f, 0x01 }, /* start tune */
160 { 0, 0 } 149 { 0, 0 }
161}; 150};
162 151
@@ -227,63 +216,20 @@ static void mxl5007t_set_mode_bits(struct mxl5007t_state *state,
227 s32 if_diff_out_level) 216 s32 if_diff_out_level)
228{ 217{
229 switch (mode) { 218 switch (mode) {
230 case MxL_MODE_OTA_DVBT_ATSC: 219 case MxL_MODE_ATSC:
231 set_reg_bits(state->tab_init, 0x32, 0x0f, 0x06); 220 set_reg_bits(state->tab_init, 0x06, 0x1f, 0x12);
232 set_reg_bits(state->tab_init, 0x35, 0xff, 0x0e);
233 break; 221 break;
234 case MxL_MODE_OTA_ISDBT: 222 case MxL_MODE_DVBT:
235 set_reg_bits(state->tab_init, 0x32, 0x0f, 0x06); 223 set_reg_bits(state->tab_init, 0x06, 0x1f, 0x11);
236 set_reg_bits(state->tab_init, 0x35, 0xff, 0x12);
237 break; 224 break;
238 case MxL_MODE_OTA_NTSC_PAL_GH: 225 case MxL_MODE_ISDBT:
239 set_reg_bits(state->tab_init, 0x16, 0x70, 0x00); 226 set_reg_bits(state->tab_init, 0x06, 0x1f, 0x10);
240 set_reg_bits(state->tab_init, 0x32, 0xff, 0x85);
241 break; 227 break;
242 case MxL_MODE_OTA_PAL_IB: 228 case MxL_MODE_CABLE:
243 set_reg_bits(state->tab_init, 0x16, 0x70, 0x10); 229 set_reg_bits(state->tab_init_cable, 0x09, 0xff, 0xc1);
244 set_reg_bits(state->tab_init, 0x32, 0xff, 0x85); 230 set_reg_bits(state->tab_init_cable, 0x0a, 0xff,
245 break;
246 case MxL_MODE_OTA_PAL_D_SECAM_KL:
247 set_reg_bits(state->tab_init, 0x16, 0x70, 0x20);
248 set_reg_bits(state->tab_init, 0x32, 0xff, 0x85);
249 break;
250 case MxL_MODE_CABLE_DIGITAL:
251 set_reg_bits(state->tab_init_cable, 0x71, 0xff, 0x01);
252 set_reg_bits(state->tab_init_cable, 0x72, 0xff,
253 8 - if_diff_out_level);
254 set_reg_bits(state->tab_init_cable, 0x74, 0xff, 0x17);
255 break;
256 case MxL_MODE_CABLE_NTSC_PAL_GH:
257 set_reg_bits(state->tab_init, 0x16, 0x70, 0x00);
258 set_reg_bits(state->tab_init, 0x32, 0xff, 0x85);
259 set_reg_bits(state->tab_init_cable, 0x71, 0xff, 0x01);
260 set_reg_bits(state->tab_init_cable, 0x72, 0xff,
261 8 - if_diff_out_level);
262 set_reg_bits(state->tab_init_cable, 0x74, 0xff, 0x17);
263 break;
264 case MxL_MODE_CABLE_PAL_IB:
265 set_reg_bits(state->tab_init, 0x16, 0x70, 0x10);
266 set_reg_bits(state->tab_init, 0x32, 0xff, 0x85);
267 set_reg_bits(state->tab_init_cable, 0x71, 0xff, 0x01);
268 set_reg_bits(state->tab_init_cable, 0x72, 0xff,
269 8 - if_diff_out_level); 231 8 - if_diff_out_level);
270 set_reg_bits(state->tab_init_cable, 0x74, 0xff, 0x17); 232 set_reg_bits(state->tab_init_cable, 0x0b, 0xff, 0x17);
271 break;
272 case MxL_MODE_CABLE_PAL_D_SECAM_KL:
273 set_reg_bits(state->tab_init, 0x16, 0x70, 0x20);
274 set_reg_bits(state->tab_init, 0x32, 0xff, 0x85);
275 set_reg_bits(state->tab_init_cable, 0x71, 0xff, 0x01);
276 set_reg_bits(state->tab_init_cable, 0x72, 0xff,
277 8 - if_diff_out_level);
278 set_reg_bits(state->tab_init_cable, 0x74, 0xff, 0x17);
279 break;
280 case MxL_MODE_CABLE_SCTE40:
281 set_reg_bits(state->tab_init_cable, 0x36, 0xff, 0x08);
282 set_reg_bits(state->tab_init_cable, 0x68, 0xff, 0xbc);
283 set_reg_bits(state->tab_init_cable, 0x71, 0xff, 0x01);
284 set_reg_bits(state->tab_init_cable, 0x72, 0xff,
285 8 - if_diff_out_level);
286 set_reg_bits(state->tab_init_cable, 0x74, 0xff, 0x17);
287 break; 233 break;
288 default: 234 default:
289 mxl_fail(-EINVAL); 235 mxl_fail(-EINVAL);
@@ -302,43 +248,43 @@ static void mxl5007t_set_if_freq_bits(struct mxl5007t_state *state,
302 val = 0x00; 248 val = 0x00;
303 break; 249 break;
304 case MxL_IF_4_5_MHZ: 250 case MxL_IF_4_5_MHZ:
305 val = 0x20; 251 val = 0x02;
306 break; 252 break;
307 case MxL_IF_4_57_MHZ: 253 case MxL_IF_4_57_MHZ:
308 val = 0x30; 254 val = 0x03;
309 break; 255 break;
310 case MxL_IF_5_MHZ: 256 case MxL_IF_5_MHZ:
311 val = 0x40; 257 val = 0x04;
312 break; 258 break;
313 case MxL_IF_5_38_MHZ: 259 case MxL_IF_5_38_MHZ:
314 val = 0x50; 260 val = 0x05;
315 break; 261 break;
316 case MxL_IF_6_MHZ: 262 case MxL_IF_6_MHZ:
317 val = 0x60; 263 val = 0x06;
318 break; 264 break;
319 case MxL_IF_6_28_MHZ: 265 case MxL_IF_6_28_MHZ:
320 val = 0x70; 266 val = 0x07;
321 break; 267 break;
322 case MxL_IF_9_1915_MHZ: 268 case MxL_IF_9_1915_MHZ:
323 val = 0x80; 269 val = 0x08;
324 break; 270 break;
325 case MxL_IF_35_25_MHZ: 271 case MxL_IF_35_25_MHZ:
326 val = 0x90; 272 val = 0x09;
327 break; 273 break;
328 case MxL_IF_36_15_MHZ: 274 case MxL_IF_36_15_MHZ:
329 val = 0xa0; 275 val = 0x0a;
330 break; 276 break;
331 case MxL_IF_44_MHZ: 277 case MxL_IF_44_MHZ:
332 val = 0xb0; 278 val = 0x0b;
333 break; 279 break;
334 default: 280 default:
335 mxl_fail(-EINVAL); 281 mxl_fail(-EINVAL);
336 return; 282 return;
337 } 283 }
338 set_reg_bits(state->tab_init, 0x0c, 0xf0, val); 284 set_reg_bits(state->tab_init, 0x02, 0x0f, val);
339 285
340 /* set inverted IF or normal IF */ 286 /* set inverted IF or normal IF */
341 set_reg_bits(state->tab_init, 0x0c, 0x08, invert_if ? 0x08 : 0x00); 287 set_reg_bits(state->tab_init, 0x02, 0x10, invert_if ? 0x10 : 0x00);
342 288
343 return; 289 return;
344} 290}
@@ -346,56 +292,68 @@ static void mxl5007t_set_if_freq_bits(struct mxl5007t_state *state,
346static void mxl5007t_set_xtal_freq_bits(struct mxl5007t_state *state, 292static void mxl5007t_set_xtal_freq_bits(struct mxl5007t_state *state,
347 enum mxl5007t_xtal_freq xtal_freq) 293 enum mxl5007t_xtal_freq xtal_freq)
348{ 294{
349 u8 val;
350
351 switch (xtal_freq) { 295 switch (xtal_freq) {
352 case MxL_XTAL_16_MHZ: 296 case MxL_XTAL_16_MHZ:
353 val = 0x00; /* select xtal freq & Ref Freq */ 297 /* select xtal freq & ref freq */
298 set_reg_bits(state->tab_init, 0x03, 0xf0, 0x00);
299 set_reg_bits(state->tab_init, 0x05, 0x0f, 0x00);
354 break; 300 break;
355 case MxL_XTAL_20_MHZ: 301 case MxL_XTAL_20_MHZ:
356 val = 0x11; 302 set_reg_bits(state->tab_init, 0x03, 0xf0, 0x10);
303 set_reg_bits(state->tab_init, 0x05, 0x0f, 0x01);
357 break; 304 break;
358 case MxL_XTAL_20_25_MHZ: 305 case MxL_XTAL_20_25_MHZ:
359 val = 0x22; 306 set_reg_bits(state->tab_init, 0x03, 0xf0, 0x20);
307 set_reg_bits(state->tab_init, 0x05, 0x0f, 0x02);
360 break; 308 break;
361 case MxL_XTAL_20_48_MHZ: 309 case MxL_XTAL_20_48_MHZ:
362 val = 0x33; 310 set_reg_bits(state->tab_init, 0x03, 0xf0, 0x30);
311 set_reg_bits(state->tab_init, 0x05, 0x0f, 0x03);
363 break; 312 break;
364 case MxL_XTAL_24_MHZ: 313 case MxL_XTAL_24_MHZ:
365 val = 0x44; 314 set_reg_bits(state->tab_init, 0x03, 0xf0, 0x40);
315 set_reg_bits(state->tab_init, 0x05, 0x0f, 0x04);
366 break; 316 break;
367 case MxL_XTAL_25_MHZ: 317 case MxL_XTAL_25_MHZ:
368 val = 0x55; 318 set_reg_bits(state->tab_init, 0x03, 0xf0, 0x50);
319 set_reg_bits(state->tab_init, 0x05, 0x0f, 0x05);
369 break; 320 break;
370 case MxL_XTAL_25_14_MHZ: 321 case MxL_XTAL_25_14_MHZ:
371 val = 0x66; 322 set_reg_bits(state->tab_init, 0x03, 0xf0, 0x60);
323 set_reg_bits(state->tab_init, 0x05, 0x0f, 0x06);
372 break; 324 break;
373 case MxL_XTAL_27_MHZ: 325 case MxL_XTAL_27_MHZ:
374 val = 0x77; 326 set_reg_bits(state->tab_init, 0x03, 0xf0, 0x70);
327 set_reg_bits(state->tab_init, 0x05, 0x0f, 0x07);
375 break; 328 break;
376 case MxL_XTAL_28_8_MHZ: 329 case MxL_XTAL_28_8_MHZ:
377 val = 0x88; 330 set_reg_bits(state->tab_init, 0x03, 0xf0, 0x80);
331 set_reg_bits(state->tab_init, 0x05, 0x0f, 0x08);
378 break; 332 break;
379 case MxL_XTAL_32_MHZ: 333 case MxL_XTAL_32_MHZ:
380 val = 0x99; 334 set_reg_bits(state->tab_init, 0x03, 0xf0, 0x90);
335 set_reg_bits(state->tab_init, 0x05, 0x0f, 0x09);
381 break; 336 break;
382 case MxL_XTAL_40_MHZ: 337 case MxL_XTAL_40_MHZ:
383 val = 0xaa; 338 set_reg_bits(state->tab_init, 0x03, 0xf0, 0xa0);
339 set_reg_bits(state->tab_init, 0x05, 0x0f, 0x0a);
384 break; 340 break;
385 case MxL_XTAL_44_MHZ: 341 case MxL_XTAL_44_MHZ:
386 val = 0xbb; 342 set_reg_bits(state->tab_init, 0x03, 0xf0, 0xb0);
343 set_reg_bits(state->tab_init, 0x05, 0x0f, 0x0b);
387 break; 344 break;
388 case MxL_XTAL_48_MHZ: 345 case MxL_XTAL_48_MHZ:
389 val = 0xcc; 346 set_reg_bits(state->tab_init, 0x03, 0xf0, 0xc0);
347 set_reg_bits(state->tab_init, 0x05, 0x0f, 0x0c);
390 break; 348 break;
391 case MxL_XTAL_49_3811_MHZ: 349 case MxL_XTAL_49_3811_MHZ:
392 val = 0xdd; 350 set_reg_bits(state->tab_init, 0x03, 0xf0, 0xd0);
351 set_reg_bits(state->tab_init, 0x05, 0x0f, 0x0d);
393 break; 352 break;
394 default: 353 default:
395 mxl_fail(-EINVAL); 354 mxl_fail(-EINVAL);
396 return; 355 return;
397 } 356 }
398 set_reg_bits(state->tab_init, 0x0b, 0xff, val);
399 357
400 return; 358 return;
401} 359}
@@ -412,16 +370,11 @@ static struct reg_pair_t *mxl5007t_calc_init_regs(struct mxl5007t_state *state,
412 mxl5007t_set_if_freq_bits(state, cfg->if_freq_hz, cfg->invert_if); 370 mxl5007t_set_if_freq_bits(state, cfg->if_freq_hz, cfg->invert_if);
413 mxl5007t_set_xtal_freq_bits(state, cfg->xtal_freq_hz); 371 mxl5007t_set_xtal_freq_bits(state, cfg->xtal_freq_hz);
414 372
415 set_reg_bits(state->tab_init, 0x10, 0x40, cfg->loop_thru_enable << 6); 373 set_reg_bits(state->tab_init, 0x04, 0x01, cfg->loop_thru_enable);
416 374 set_reg_bits(state->tab_init, 0x03, 0x08, cfg->clk_out_enable << 3);
417 set_reg_bits(state->tab_init, 0xd8, 0x08, cfg->clk_out_enable << 3); 375 set_reg_bits(state->tab_init, 0x03, 0x07, cfg->clk_out_amp);
418
419 set_reg_bits(state->tab_init, 0x10, 0x07, cfg->clk_out_amp);
420 376
421 /* set IDAC to automatic mode control by AGC */ 377 if (mode >= MxL_MODE_CABLE) {
422 set_reg_bits(state->tab_init, 0x12, 0x80, 0x00);
423
424 if (mode >= MxL_MODE_CABLE_DIGITAL) {
425 copy_reg_bits(state->tab_init, state->tab_init_cable); 378 copy_reg_bits(state->tab_init, state->tab_init_cable);
426 return state->tab_init_cable; 379 return state->tab_init_cable;
427 } else 380 } else
@@ -447,7 +400,7 @@ static void mxl5007t_set_bw_bits(struct mxl5007t_state *state,
447 * and DIG_MODEINDEX_CSF */ 400 * and DIG_MODEINDEX_CSF */
448 break; 401 break;
449 case MxL_BW_7MHz: 402 case MxL_BW_7MHz:
450 val = 0x21; 403 val = 0x2a;
451 break; 404 break;
452 case MxL_BW_8MHz: 405 case MxL_BW_8MHz:
453 val = 0x3f; 406 val = 0x3f;
@@ -456,7 +409,7 @@ static void mxl5007t_set_bw_bits(struct mxl5007t_state *state,
456 mxl_fail(-EINVAL); 409 mxl_fail(-EINVAL);
457 return; 410 return;
458 } 411 }
459 set_reg_bits(state->tab_rftune, 0x13, 0x3f, val); 412 set_reg_bits(state->tab_rftune, 0x0c, 0x3f, val);
460 413
461 return; 414 return;
462} 415}
@@ -493,8 +446,11 @@ reg_pair_t *mxl5007t_calc_rf_tune_regs(struct mxl5007t_state *state,
493 if (temp > 7812) 446 if (temp > 7812)
494 dig_rf_freq++; 447 dig_rf_freq++;
495 448
496 set_reg_bits(state->tab_rftune, 0x14, 0xff, (u8)dig_rf_freq); 449 set_reg_bits(state->tab_rftune, 0x0d, 0xff, (u8) dig_rf_freq);
497 set_reg_bits(state->tab_rftune, 0x15, 0xff, (u8)(dig_rf_freq >> 8)); 450 set_reg_bits(state->tab_rftune, 0x0e, 0xff, (u8) (dig_rf_freq >> 8));
451
452 if (rf_freq >= 333000000)
453 set_reg_bits(state->tab_rftune, 0x80, 0x40, 0x40);
498 454
499 return state->tab_rftune; 455 return state->tab_rftune;
500} 456}
@@ -551,9 +507,10 @@ static int mxl5007t_read_reg(struct mxl5007t_state *state, u8 reg, u8 *val)
551static int mxl5007t_soft_reset(struct mxl5007t_state *state) 507static int mxl5007t_soft_reset(struct mxl5007t_state *state)
552{ 508{
553 u8 d = 0xff; 509 u8 d = 0xff;
554 struct i2c_msg msg = { .addr = state->i2c_props.addr, .flags = 0, 510 struct i2c_msg msg = {
555 .buf = &d, .len = 1 }; 511 .addr = state->i2c_props.addr, .flags = 0,
556 512 .buf = &d, .len = 1
513 };
557 int ret = i2c_transfer(state->i2c_props.adap, &msg, 1); 514 int ret = i2c_transfer(state->i2c_props.adap, &msg, 1);
558 515
559 if (ret != 1) { 516 if (ret != 1) {
@@ -580,9 +537,6 @@ static int mxl5007t_tuner_init(struct mxl5007t_state *state,
580 if (mxl_fail(ret)) 537 if (mxl_fail(ret))
581 goto fail; 538 goto fail;
582 mdelay(1); 539 mdelay(1);
583
584 ret = mxl5007t_write_reg(state, 0x2c, 0x35);
585 mxl_fail(ret);
586fail: 540fail:
587 return ret; 541 return ret;
588} 542}
@@ -615,7 +569,7 @@ static int mxl5007t_synth_lock_status(struct mxl5007t_state *state,
615 *rf_locked = 0; 569 *rf_locked = 0;
616 *ref_locked = 0; 570 *ref_locked = 0;
617 571
618 ret = mxl5007t_read_reg(state, 0xcf, &d); 572 ret = mxl5007t_read_reg(state, 0xd8, &d);
619 if (mxl_fail(ret)) 573 if (mxl_fail(ret))
620 goto fail; 574 goto fail;
621 575
@@ -628,37 +582,14 @@ fail:
628 return ret; 582 return ret;
629} 583}
630 584
631static int mxl5007t_check_rf_input_power(struct mxl5007t_state *state,
632 s32 *rf_input_level)
633{
634 u8 d1, d2;
635 int ret;
636
637 ret = mxl5007t_read_reg(state, 0xb7, &d1);
638 if (mxl_fail(ret))
639 goto fail;
640
641 ret = mxl5007t_read_reg(state, 0xbf, &d2);
642 if (mxl_fail(ret))
643 goto fail;
644
645 d2 = d2 >> 4;
646 if (d2 > 7)
647 d2 += 0xf0;
648
649 *rf_input_level = (s32)(d1 + d2 - 113);
650fail:
651 return ret;
652}
653
654/* ------------------------------------------------------------------------- */ 585/* ------------------------------------------------------------------------- */
655 586
656static int mxl5007t_get_status(struct dvb_frontend *fe, u32 *status) 587static int mxl5007t_get_status(struct dvb_frontend *fe, u32 *status)
657{ 588{
658 struct mxl5007t_state *state = fe->tuner_priv; 589 struct mxl5007t_state *state = fe->tuner_priv;
659 int rf_locked, ref_locked; 590 int rf_locked, ref_locked, ret;
660 s32 rf_input_level = 0; 591
661 int ret; 592 *status = 0;
662 593
663 if (fe->ops.i2c_gate_ctrl) 594 if (fe->ops.i2c_gate_ctrl)
664 fe->ops.i2c_gate_ctrl(fe, 1); 595 fe->ops.i2c_gate_ctrl(fe, 1);
@@ -669,10 +600,8 @@ static int mxl5007t_get_status(struct dvb_frontend *fe, u32 *status)
669 mxl_debug("%s%s", rf_locked ? "rf locked " : "", 600 mxl_debug("%s%s", rf_locked ? "rf locked " : "",
670 ref_locked ? "ref locked" : ""); 601 ref_locked ? "ref locked" : "");
671 602
672 ret = mxl5007t_check_rf_input_power(state, &rf_input_level); 603 if ((rf_locked) || (ref_locked))
673 if (mxl_fail(ret)) 604 *status |= TUNER_STATUS_LOCKED;
674 goto fail;
675 mxl_debug("rf input power: %d", rf_input_level);
676fail: 605fail:
677 if (fe->ops.i2c_gate_ctrl) 606 if (fe->ops.i2c_gate_ctrl)
678 fe->ops.i2c_gate_ctrl(fe, 0); 607 fe->ops.i2c_gate_ctrl(fe, 0);
@@ -695,11 +624,11 @@ static int mxl5007t_set_params(struct dvb_frontend *fe,
695 switch (params->u.vsb.modulation) { 624 switch (params->u.vsb.modulation) {
696 case VSB_8: 625 case VSB_8:
697 case VSB_16: 626 case VSB_16:
698 mode = MxL_MODE_OTA_DVBT_ATSC; 627 mode = MxL_MODE_ATSC;
699 break; 628 break;
700 case QAM_64: 629 case QAM_64:
701 case QAM_256: 630 case QAM_256:
702 mode = MxL_MODE_CABLE_DIGITAL; 631 mode = MxL_MODE_CABLE;
703 break; 632 break;
704 default: 633 default:
705 mxl_err("modulation not set!"); 634 mxl_err("modulation not set!");
@@ -721,7 +650,7 @@ static int mxl5007t_set_params(struct dvb_frontend *fe,
721 mxl_err("bandwidth not set!"); 650 mxl_err("bandwidth not set!");
722 return -EINVAL; 651 return -EINVAL;
723 } 652 }
724 mode = MxL_MODE_OTA_DVBT_ATSC; 653 mode = MxL_MODE_DVBT;
725 } else { 654 } else {
726 mxl_err("modulation type not supported!"); 655 mxl_err("modulation type not supported!");
727 return -EINVAL; 656 return -EINVAL;
@@ -752,96 +681,20 @@ fail:
752 return ret; 681 return ret;
753} 682}
754 683
755static int mxl5007t_set_analog_params(struct dvb_frontend *fe,
756 struct analog_parameters *params)
757{
758 struct mxl5007t_state *state = fe->tuner_priv;
759 enum mxl5007t_bw_mhz bw = 0; /* FIXME */
760 enum mxl5007t_mode cbl_mode;
761 enum mxl5007t_mode ota_mode;
762 char *mode_name;
763 int ret;
764 u32 freq = params->frequency * 62500;
765
766#define cable 1
767 if (params->std & V4L2_STD_MN) {
768 cbl_mode = MxL_MODE_CABLE_NTSC_PAL_GH;
769 ota_mode = MxL_MODE_OTA_NTSC_PAL_GH;
770 mode_name = "MN";
771 } else if (params->std & V4L2_STD_B) {
772 cbl_mode = MxL_MODE_CABLE_PAL_IB;
773 ota_mode = MxL_MODE_OTA_PAL_IB;
774 mode_name = "B";
775 } else if (params->std & V4L2_STD_GH) {
776 cbl_mode = MxL_MODE_CABLE_NTSC_PAL_GH;
777 ota_mode = MxL_MODE_OTA_NTSC_PAL_GH;
778 mode_name = "GH";
779 } else if (params->std & V4L2_STD_PAL_I) {
780 cbl_mode = MxL_MODE_CABLE_PAL_IB;
781 ota_mode = MxL_MODE_OTA_PAL_IB;
782 mode_name = "I";
783 } else if (params->std & V4L2_STD_DK) {
784 cbl_mode = MxL_MODE_CABLE_PAL_D_SECAM_KL;
785 ota_mode = MxL_MODE_OTA_PAL_D_SECAM_KL;
786 mode_name = "DK";
787 } else if (params->std & V4L2_STD_SECAM_L) {
788 cbl_mode = MxL_MODE_CABLE_PAL_D_SECAM_KL;
789 ota_mode = MxL_MODE_OTA_PAL_D_SECAM_KL;
790 mode_name = "L";
791 } else if (params->std & V4L2_STD_SECAM_LC) {
792 cbl_mode = MxL_MODE_CABLE_PAL_D_SECAM_KL;
793 ota_mode = MxL_MODE_OTA_PAL_D_SECAM_KL;
794 mode_name = "L'";
795 } else {
796 mode_name = "xx";
797 /* FIXME */
798 cbl_mode = MxL_MODE_CABLE_NTSC_PAL_GH;
799 ota_mode = MxL_MODE_OTA_NTSC_PAL_GH;
800 }
801 mxl_debug("setting mxl5007 to system %s", mode_name);
802
803 if (fe->ops.i2c_gate_ctrl)
804 fe->ops.i2c_gate_ctrl(fe, 1);
805
806 mutex_lock(&state->lock);
807
808 ret = mxl5007t_tuner_init(state, cable ? cbl_mode : ota_mode);
809 if (mxl_fail(ret))
810 goto fail;
811
812 ret = mxl5007t_tuner_rf_tune(state, freq, bw);
813 if (mxl_fail(ret))
814 goto fail;
815
816 state->frequency = freq;
817 state->bandwidth = 0;
818fail:
819 mutex_unlock(&state->lock);
820
821 if (fe->ops.i2c_gate_ctrl)
822 fe->ops.i2c_gate_ctrl(fe, 0);
823
824 return ret;
825}
826
827/* ------------------------------------------------------------------------- */ 684/* ------------------------------------------------------------------------- */
828 685
829static int mxl5007t_init(struct dvb_frontend *fe) 686static int mxl5007t_init(struct dvb_frontend *fe)
830{ 687{
831 struct mxl5007t_state *state = fe->tuner_priv; 688 struct mxl5007t_state *state = fe->tuner_priv;
832 int ret; 689 int ret;
833 u8 d;
834 690
835 if (fe->ops.i2c_gate_ctrl) 691 if (fe->ops.i2c_gate_ctrl)
836 fe->ops.i2c_gate_ctrl(fe, 1); 692 fe->ops.i2c_gate_ctrl(fe, 1);
837 693
838 ret = mxl5007t_read_reg(state, 0x05, &d); 694 /* wake from standby */
839 if (mxl_fail(ret)) 695 ret = mxl5007t_write_reg(state, 0x01, 0x01);
840 goto fail;
841
842 ret = mxl5007t_write_reg(state, 0x05, d | 0x01);
843 mxl_fail(ret); 696 mxl_fail(ret);
844fail: 697
845 if (fe->ops.i2c_gate_ctrl) 698 if (fe->ops.i2c_gate_ctrl)
846 fe->ops.i2c_gate_ctrl(fe, 0); 699 fe->ops.i2c_gate_ctrl(fe, 0);
847 700
@@ -852,18 +705,16 @@ static int mxl5007t_sleep(struct dvb_frontend *fe)
852{ 705{
853 struct mxl5007t_state *state = fe->tuner_priv; 706 struct mxl5007t_state *state = fe->tuner_priv;
854 int ret; 707 int ret;
855 u8 d;
856 708
857 if (fe->ops.i2c_gate_ctrl) 709 if (fe->ops.i2c_gate_ctrl)
858 fe->ops.i2c_gate_ctrl(fe, 1); 710 fe->ops.i2c_gate_ctrl(fe, 1);
859 711
860 ret = mxl5007t_read_reg(state, 0x05, &d); 712 /* enter standby mode */
861 if (mxl_fail(ret)) 713 ret = mxl5007t_write_reg(state, 0x01, 0x00);
862 goto fail;
863
864 ret = mxl5007t_write_reg(state, 0x05, d & ~0x01);
865 mxl_fail(ret); 714 mxl_fail(ret);
866fail: 715 ret = mxl5007t_write_reg(state, 0x0f, 0x00);
716 mxl_fail(ret);
717
867 if (fe->ops.i2c_gate_ctrl) 718 if (fe->ops.i2c_gate_ctrl)
868 fe->ops.i2c_gate_ctrl(fe, 0); 719 fe->ops.i2c_gate_ctrl(fe, 0);
869 720
@@ -911,7 +762,6 @@ static struct dvb_tuner_ops mxl5007t_tuner_ops = {
911 .init = mxl5007t_init, 762 .init = mxl5007t_init,
912 .sleep = mxl5007t_sleep, 763 .sleep = mxl5007t_sleep,
913 .set_params = mxl5007t_set_params, 764 .set_params = mxl5007t_set_params,
914 .set_analog_params = mxl5007t_set_analog_params,
915 .get_status = mxl5007t_get_status, 765 .get_status = mxl5007t_get_status,
916 .get_frequency = mxl5007t_get_frequency, 766 .get_frequency = mxl5007t_get_frequency,
917 .get_bandwidth = mxl5007t_get_bandwidth, 767 .get_bandwidth = mxl5007t_get_bandwidth,
@@ -924,7 +774,7 @@ static int mxl5007t_get_chip_id(struct mxl5007t_state *state)
924 int ret; 774 int ret;
925 u8 id; 775 u8 id;
926 776
927 ret = mxl5007t_read_reg(state, 0xd3, &id); 777 ret = mxl5007t_read_reg(state, 0xd9, &id);
928 if (mxl_fail(ret)) 778 if (mxl_fail(ret))
929 goto fail; 779 goto fail;
930 780
@@ -947,8 +797,12 @@ static int mxl5007t_get_chip_id(struct mxl5007t_state *state)
947 case MxL_5007_V2_200_F2: 797 case MxL_5007_V2_200_F2:
948 name = "MxL5007.v2.200.f2"; 798 name = "MxL5007.v2.200.f2";
949 break; 799 break;
800 case MxL_5007_V4:
801 name = "MxL5007T.v4";
802 break;
950 default: 803 default:
951 name = "MxL5007T"; 804 name = "MxL5007T";
805 printk(KERN_WARNING "%s: unknown rev (%02x)\n", __func__, id);
952 id = MxL_UNKNOWN_ID; 806 id = MxL_UNKNOWN_ID;
953 } 807 }
954 state->chip_id = id; 808 state->chip_id = id;
@@ -975,7 +829,7 @@ struct dvb_frontend *mxl5007t_attach(struct dvb_frontend *fe,
975 mutex_lock(&mxl5007t_list_mutex); 829 mutex_lock(&mxl5007t_list_mutex);
976 instance = hybrid_tuner_request_state(struct mxl5007t_state, state, 830 instance = hybrid_tuner_request_state(struct mxl5007t_state, state,
977 hybrid_tuner_instance_list, 831 hybrid_tuner_instance_list,
978 i2c, addr, "mxl5007"); 832 i2c, addr, "mxl5007t");
979 switch (instance) { 833 switch (instance) {
980 case 0: 834 case 0:
981 goto fail; 835 goto fail;
@@ -1018,7 +872,7 @@ EXPORT_SYMBOL_GPL(mxl5007t_attach);
1018MODULE_DESCRIPTION("MaxLinear MxL5007T Silicon IC tuner driver"); 872MODULE_DESCRIPTION("MaxLinear MxL5007T Silicon IC tuner driver");
1019MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>"); 873MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>");
1020MODULE_LICENSE("GPL"); 874MODULE_LICENSE("GPL");
1021MODULE_VERSION("0.1"); 875MODULE_VERSION("0.2");
1022 876
1023/* 877/*
1024 * Overrides for Emacs so that we follow Linus's tabbing style. 878 * Overrides for Emacs so that we follow Linus's tabbing style.
diff --git a/drivers/media/common/tuners/tda18271-common.c b/drivers/media/common/tuners/tda18271-common.c
index 6fb5b4586569..fc76c30e24f1 100644
--- a/drivers/media/common/tuners/tda18271-common.c
+++ b/drivers/media/common/tuners/tda18271-common.c
@@ -490,9 +490,9 @@ int tda18271_set_standby_mode(struct dvb_frontend *fe,
490 tda_dbg("sm = %d, sm_lt = %d, sm_xt = %d\n", sm, sm_lt, sm_xt); 490 tda_dbg("sm = %d, sm_lt = %d, sm_xt = %d\n", sm, sm_lt, sm_xt);
491 491
492 regs[R_EP3] &= ~0xe0; /* clear sm, sm_lt, sm_xt */ 492 regs[R_EP3] &= ~0xe0; /* clear sm, sm_lt, sm_xt */
493 regs[R_EP3] |= sm ? (1 << 7) : 0 | 493 regs[R_EP3] |= (sm ? (1 << 7) : 0) |
494 sm_lt ? (1 << 6) : 0 | 494 (sm_lt ? (1 << 6) : 0) |
495 sm_xt ? (1 << 5) : 0; 495 (sm_xt ? (1 << 5) : 0);
496 496
497 return tda18271_write_regs(fe, R_EP3, 1); 497 return tda18271_write_regs(fe, R_EP3, 1);
498} 498}
diff --git a/drivers/media/common/tuners/tda18271-fe.c b/drivers/media/common/tuners/tda18271-fe.c
index 1b48b5d0bf1e..b10935630154 100644
--- a/drivers/media/common/tuners/tda18271-fe.c
+++ b/drivers/media/common/tuners/tda18271-fe.c
@@ -818,6 +818,38 @@ fail:
818 return ret; 818 return ret;
819} 819}
820 820
821/* ------------------------------------------------------------------ */
822
823static int tda18271_agc(struct dvb_frontend *fe)
824{
825 struct tda18271_priv *priv = fe->tuner_priv;
826 int ret = 0;
827
828 switch (priv->config) {
829 case 0:
830 /* no LNA */
831 tda_dbg("no agc configuration provided\n");
832 break;
833 case 3:
834 /* switch with GPIO of saa713x */
835 tda_dbg("invoking callback\n");
836 if (fe->callback)
837 ret = fe->callback(priv->i2c_props.adap->algo_data,
838 DVB_FRONTEND_COMPONENT_TUNER,
839 TDA18271_CALLBACK_CMD_AGC_ENABLE,
840 priv->mode);
841 break;
842 case 1:
843 case 2:
844 default:
845 /* n/a - currently not supported */
846 tda_err("unsupported configuration: %d\n", priv->config);
847 ret = -EINVAL;
848 break;
849 }
850 return ret;
851}
852
821static int tda18271_tune(struct dvb_frontend *fe, 853static int tda18271_tune(struct dvb_frontend *fe,
822 struct tda18271_std_map_item *map, u32 freq, u32 bw) 854 struct tda18271_std_map_item *map, u32 freq, u32 bw)
823{ 855{
@@ -827,6 +859,10 @@ static int tda18271_tune(struct dvb_frontend *fe,
827 tda_dbg("freq = %d, ifc = %d, bw = %d, agc_mode = %d, std = %d\n", 859 tda_dbg("freq = %d, ifc = %d, bw = %d, agc_mode = %d, std = %d\n",
828 freq, map->if_freq, bw, map->agc_mode, map->std); 860 freq, map->if_freq, bw, map->agc_mode, map->std);
829 861
862 ret = tda18271_agc(fe);
863 if (tda_fail(ret))
864 tda_warn("failed to configure agc\n");
865
830 ret = tda18271_init(fe); 866 ret = tda18271_init(fe);
831 if (tda_fail(ret)) 867 if (tda_fail(ret))
832 goto fail; 868 goto fail;
@@ -1159,6 +1195,7 @@ struct dvb_frontend *tda18271_attach(struct dvb_frontend *fe, u8 addr,
1159 /* new tuner instance */ 1195 /* new tuner instance */
1160 priv->gate = (cfg) ? cfg->gate : TDA18271_GATE_AUTO; 1196 priv->gate = (cfg) ? cfg->gate : TDA18271_GATE_AUTO;
1161 priv->role = (cfg) ? cfg->role : TDA18271_MASTER; 1197 priv->role = (cfg) ? cfg->role : TDA18271_MASTER;
1198 priv->config = (cfg) ? cfg->config : 0;
1162 priv->cal_initialized = false; 1199 priv->cal_initialized = false;
1163 mutex_init(&priv->lock); 1200 mutex_init(&priv->lock);
1164 1201
diff --git a/drivers/media/common/tuners/tda18271-priv.h b/drivers/media/common/tuners/tda18271-priv.h
index 81a739365f8c..74beb28806f8 100644
--- a/drivers/media/common/tuners/tda18271-priv.h
+++ b/drivers/media/common/tuners/tda18271-priv.h
@@ -91,11 +91,6 @@ enum tda18271_pll {
91 TDA18271_CAL_PLL, 91 TDA18271_CAL_PLL,
92}; 92};
93 93
94enum tda18271_mode {
95 TDA18271_ANALOG,
96 TDA18271_DIGITAL,
97};
98
99struct tda18271_map_layout; 94struct tda18271_map_layout;
100 95
101enum tda18271_ver { 96enum tda18271_ver {
@@ -114,6 +109,7 @@ struct tda18271_priv {
114 enum tda18271_i2c_gate gate; 109 enum tda18271_i2c_gate gate;
115 enum tda18271_ver id; 110 enum tda18271_ver id;
116 111
112 unsigned int config; /* interface to saa713x / tda829x */
117 unsigned int tm_rfcal; 113 unsigned int tm_rfcal;
118 unsigned int cal_initialized:1; 114 unsigned int cal_initialized:1;
119 unsigned int small_i2c:1; 115 unsigned int small_i2c:1;
diff --git a/drivers/media/common/tuners/tda18271.h b/drivers/media/common/tuners/tda18271.h
index 7db9831c0cb0..53a9892a18d0 100644
--- a/drivers/media/common/tuners/tda18271.h
+++ b/drivers/media/common/tuners/tda18271.h
@@ -79,6 +79,16 @@ struct tda18271_config {
79 79
80 /* some i2c providers cant write all 39 registers at once */ 80 /* some i2c providers cant write all 39 registers at once */
81 unsigned int small_i2c:1; 81 unsigned int small_i2c:1;
82
83 /* interface to saa713x / tda829x */
84 unsigned int config;
85};
86
87#define TDA18271_CALLBACK_CMD_AGC_ENABLE 0
88
89enum tda18271_mode {
90 TDA18271_ANALOG = 0,
91 TDA18271_DIGITAL,
82}; 92};
83 93
84#if defined(CONFIG_MEDIA_TUNER_TDA18271) || (defined(CONFIG_MEDIA_TUNER_TDA18271_MODULE) && defined(MODULE)) 94#if defined(CONFIG_MEDIA_TUNER_TDA18271) || (defined(CONFIG_MEDIA_TUNER_TDA18271_MODULE) && defined(MODULE))
diff --git a/drivers/media/common/tuners/tda827x.c b/drivers/media/common/tuners/tda827x.c
index f4d931f14fad..36a7bc7585ab 100644
--- a/drivers/media/common/tuners/tda827x.c
+++ b/drivers/media/common/tuners/tda827x.c
@@ -132,11 +132,31 @@ static const struct tda827x_data tda827x_table[] = {
132 { .lomax = 0, .spd = 0, .bs = 0, .bp = 0, .cp = 0, .gc3 = 0, .div1p5 = 0} 132 { .lomax = 0, .spd = 0, .bs = 0, .bp = 0, .cp = 0, .gc3 = 0, .div1p5 = 0}
133}; 133};
134 134
135static int tuner_transfer(struct dvb_frontend *fe,
136 struct i2c_msg *msg,
137 const int size)
138{
139 int rc;
140 struct tda827x_priv *priv = fe->tuner_priv;
141
142 if (fe->ops.i2c_gate_ctrl)
143 fe->ops.i2c_gate_ctrl(fe, 1);
144 rc = i2c_transfer(priv->i2c_adap, msg, size);
145 if (fe->ops.i2c_gate_ctrl)
146 fe->ops.i2c_gate_ctrl(fe, 0);
147
148 if (rc >= 0 && rc != size)
149 return -EIO;
150
151 return rc;
152}
153
135static int tda827xo_set_params(struct dvb_frontend *fe, 154static int tda827xo_set_params(struct dvb_frontend *fe,
136 struct dvb_frontend_parameters *params) 155 struct dvb_frontend_parameters *params)
137{ 156{
138 struct tda827x_priv *priv = fe->tuner_priv; 157 struct tda827x_priv *priv = fe->tuner_priv;
139 u8 buf[14]; 158 u8 buf[14];
159 int rc;
140 160
141 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0, 161 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
142 .buf = buf, .len = sizeof(buf) }; 162 .buf = buf, .len = sizeof(buf) };
@@ -183,27 +203,29 @@ static int tda827xo_set_params(struct dvb_frontend *fe,
183 buf[13] = 0x40; 203 buf[13] = 0x40;
184 204
185 msg.len = 14; 205 msg.len = 14;
186 if (fe->ops.i2c_gate_ctrl) 206 rc = tuner_transfer(fe, &msg, 1);
187 fe->ops.i2c_gate_ctrl(fe, 1); 207 if (rc < 0)
188 if (i2c_transfer(priv->i2c_adap, &msg, 1) != 1) { 208 goto err;
189 printk("%s: could not write to tuner at addr: 0x%02x\n", 209
190 __func__, priv->i2c_addr << 1);
191 return -EIO;
192 }
193 msleep(500); 210 msleep(500);
194 /* correct CP value */ 211 /* correct CP value */
195 buf[0] = 0x30; 212 buf[0] = 0x30;
196 buf[1] = 0x50 + tda827x_table[i].cp; 213 buf[1] = 0x50 + tda827x_table[i].cp;
197 msg.len = 2; 214 msg.len = 2;
198 215
199 if (fe->ops.i2c_gate_ctrl) 216 rc = tuner_transfer(fe, &msg, 1);
200 fe->ops.i2c_gate_ctrl(fe, 1); 217 if (rc < 0)
201 i2c_transfer(priv->i2c_adap, &msg, 1); 218 goto err;
202 219
203 priv->frequency = params->frequency; 220 priv->frequency = params->frequency;
204 priv->bandwidth = (fe->ops.info.type == FE_OFDM) ? params->u.ofdm.bandwidth : 0; 221 priv->bandwidth = (fe->ops.info.type == FE_OFDM) ? params->u.ofdm.bandwidth : 0;
205 222
206 return 0; 223 return 0;
224
225err:
226 printk(KERN_ERR "%s: could not write to tuner at addr: 0x%02x\n",
227 __func__, priv->i2c_addr << 1);
228 return rc;
207} 229}
208 230
209static int tda827xo_sleep(struct dvb_frontend *fe) 231static int tda827xo_sleep(struct dvb_frontend *fe)
@@ -214,9 +236,7 @@ static int tda827xo_sleep(struct dvb_frontend *fe)
214 .buf = buf, .len = sizeof(buf) }; 236 .buf = buf, .len = sizeof(buf) };
215 237
216 dprintk("%s:\n", __func__); 238 dprintk("%s:\n", __func__);
217 if (fe->ops.i2c_gate_ctrl) 239 tuner_transfer(fe, &msg, 1);
218 fe->ops.i2c_gate_ctrl(fe, 1);
219 i2c_transfer(priv->i2c_adap, &msg, 1);
220 240
221 if (priv->cfg && priv->cfg->sleep) 241 if (priv->cfg && priv->cfg->sleep)
222 priv->cfg->sleep(fe); 242 priv->cfg->sleep(fe);
@@ -266,44 +286,44 @@ static int tda827xo_set_analog_params(struct dvb_frontend *fe,
266 286
267 msg.buf = tuner_reg; 287 msg.buf = tuner_reg;
268 msg.len = 8; 288 msg.len = 8;
269 i2c_transfer(priv->i2c_adap, &msg, 1); 289 tuner_transfer(fe, &msg, 1);
270 290
271 msg.buf = reg2; 291 msg.buf = reg2;
272 msg.len = 2; 292 msg.len = 2;
273 reg2[0] = 0x80; 293 reg2[0] = 0x80;
274 reg2[1] = 0; 294 reg2[1] = 0;
275 i2c_transfer(priv->i2c_adap, &msg, 1); 295 tuner_transfer(fe, &msg, 1);
276 296
277 reg2[0] = 0x60; 297 reg2[0] = 0x60;
278 reg2[1] = 0xbf; 298 reg2[1] = 0xbf;
279 i2c_transfer(priv->i2c_adap, &msg, 1); 299 tuner_transfer(fe, &msg, 1);
280 300
281 reg2[0] = 0x30; 301 reg2[0] = 0x30;
282 reg2[1] = tuner_reg[4] + 0x80; 302 reg2[1] = tuner_reg[4] + 0x80;
283 i2c_transfer(priv->i2c_adap, &msg, 1); 303 tuner_transfer(fe, &msg, 1);
284 304
285 msleep(1); 305 msleep(1);
286 reg2[0] = 0x30; 306 reg2[0] = 0x30;
287 reg2[1] = tuner_reg[4] + 4; 307 reg2[1] = tuner_reg[4] + 4;
288 i2c_transfer(priv->i2c_adap, &msg, 1); 308 tuner_transfer(fe, &msg, 1);
289 309
290 msleep(1); 310 msleep(1);
291 reg2[0] = 0x30; 311 reg2[0] = 0x30;
292 reg2[1] = tuner_reg[4]; 312 reg2[1] = tuner_reg[4];
293 i2c_transfer(priv->i2c_adap, &msg, 1); 313 tuner_transfer(fe, &msg, 1);
294 314
295 msleep(550); 315 msleep(550);
296 reg2[0] = 0x30; 316 reg2[0] = 0x30;
297 reg2[1] = (tuner_reg[4] & 0xfc) + tda827x_table[i].cp; 317 reg2[1] = (tuner_reg[4] & 0xfc) + tda827x_table[i].cp;
298 i2c_transfer(priv->i2c_adap, &msg, 1); 318 tuner_transfer(fe, &msg, 1);
299 319
300 reg2[0] = 0x60; 320 reg2[0] = 0x60;
301 reg2[1] = 0x3f; 321 reg2[1] = 0x3f;
302 i2c_transfer(priv->i2c_adap, &msg, 1); 322 tuner_transfer(fe, &msg, 1);
303 323
304 reg2[0] = 0x80; 324 reg2[0] = 0x80;
305 reg2[1] = 0x08; /* Vsync en */ 325 reg2[1] = 0x08; /* Vsync en */
306 i2c_transfer(priv->i2c_adap, &msg, 1); 326 tuner_transfer(fe, &msg, 1);
307 327
308 priv->frequency = params->frequency; 328 priv->frequency = params->frequency;
309 329
@@ -317,7 +337,7 @@ static void tda827xo_agcf(struct dvb_frontend *fe)
317 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0, 337 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
318 .buf = data, .len = 2}; 338 .buf = data, .len = 2};
319 339
320 i2c_transfer(priv->i2c_adap, &msg, 1); 340 tuner_transfer(fe, &msg, 1);
321} 341}
322 342
323/* ------------------------------------------------------------------ */ 343/* ------------------------------------------------------------------ */
@@ -331,7 +351,7 @@ struct tda827xa_data {
331 u8 gc3; 351 u8 gc3;
332}; 352};
333 353
334static const struct tda827xa_data tda827xa_dvbt[] = { 354static struct tda827xa_data tda827xa_dvbt[] = {
335 { .lomax = 56875000, .svco = 3, .spd = 4, .scr = 0, .sbs = 0, .gc3 = 1}, 355 { .lomax = 56875000, .svco = 3, .spd = 4, .scr = 0, .sbs = 0, .gc3 = 1},
336 { .lomax = 67250000, .svco = 0, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 1}, 356 { .lomax = 67250000, .svco = 0, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 1},
337 { .lomax = 81250000, .svco = 1, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 1}, 357 { .lomax = 81250000, .svco = 1, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 1},
@@ -361,6 +381,36 @@ static const struct tda827xa_data tda827xa_dvbt[] = {
361 { .lomax = 0, .svco = 0, .spd = 0, .scr = 0, .sbs = 0, .gc3 = 0} 381 { .lomax = 0, .svco = 0, .spd = 0, .scr = 0, .sbs = 0, .gc3 = 0}
362}; 382};
363 383
384static struct tda827xa_data tda827xa_dvbc[] = {
385 { .lomax = 50125000, .svco = 2, .spd = 4, .scr = 2, .sbs = 0, .gc3 = 3},
386 { .lomax = 58500000, .svco = 3, .spd = 4, .scr = 2, .sbs = 0, .gc3 = 3},
387 { .lomax = 69250000, .svco = 0, .spd = 3, .scr = 2, .sbs = 0, .gc3 = 3},
388 { .lomax = 83625000, .svco = 1, .spd = 3, .scr = 2, .sbs = 0, .gc3 = 3},
389 { .lomax = 97500000, .svco = 2, .spd = 3, .scr = 2, .sbs = 0, .gc3 = 3},
390 { .lomax = 100250000, .svco = 2, .spd = 3, .scr = 2, .sbs = 1, .gc3 = 1},
391 { .lomax = 117000000, .svco = 3, .spd = 3, .scr = 2, .sbs = 1, .gc3 = 1},
392 { .lomax = 138500000, .svco = 0, .spd = 2, .scr = 2, .sbs = 1, .gc3 = 1},
393 { .lomax = 167250000, .svco = 1, .spd = 2, .scr = 2, .sbs = 1, .gc3 = 1},
394 { .lomax = 187000000, .svco = 2, .spd = 2, .scr = 2, .sbs = 1, .gc3 = 1},
395 { .lomax = 200500000, .svco = 2, .spd = 2, .scr = 2, .sbs = 2, .gc3 = 1},
396 { .lomax = 234000000, .svco = 3, .spd = 2, .scr = 2, .sbs = 2, .gc3 = 3},
397 { .lomax = 277000000, .svco = 0, .spd = 1, .scr = 2, .sbs = 2, .gc3 = 3},
398 { .lomax = 325000000, .svco = 1, .spd = 1, .scr = 2, .sbs = 2, .gc3 = 1},
399 { .lomax = 334500000, .svco = 1, .spd = 1, .scr = 2, .sbs = 3, .gc3 = 3},
400 { .lomax = 401000000, .svco = 2, .spd = 1, .scr = 2, .sbs = 3, .gc3 = 3},
401 { .lomax = 468000000, .svco = 3, .spd = 1, .scr = 2, .sbs = 3, .gc3 = 1},
402 { .lomax = 535000000, .svco = 0, .spd = 0, .scr = 1, .sbs = 3, .gc3 = 1},
403 { .lomax = 554000000, .svco = 0, .spd = 0, .scr = 2, .sbs = 3, .gc3 = 1},
404 { .lomax = 638000000, .svco = 1, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 1},
405 { .lomax = 669000000, .svco = 1, .spd = 0, .scr = 2, .sbs = 4, .gc3 = 1},
406 { .lomax = 720000000, .svco = 2, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 1},
407 { .lomax = 802000000, .svco = 2, .spd = 0, .scr = 2, .sbs = 4, .gc3 = 1},
408 { .lomax = 835000000, .svco = 3, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 1},
409 { .lomax = 885000000, .svco = 3, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 1},
410 { .lomax = 911000000, .svco = 3, .spd = 0, .scr = 2, .sbs = 4, .gc3 = 1},
411 { .lomax = 0, .svco = 0, .spd = 0, .scr = 0, .sbs = 0, .gc3 = 0}
412};
413
364static struct tda827xa_data tda827xa_analog[] = { 414static struct tda827xa_data tda827xa_analog[] = {
365 { .lomax = 56875000, .svco = 3, .spd = 4, .scr = 0, .sbs = 0, .gc3 = 3}, 415 { .lomax = 56875000, .svco = 3, .spd = 4, .scr = 0, .sbs = 0, .gc3 = 3},
366 { .lomax = 67250000, .svco = 0, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 3}, 416 { .lomax = 67250000, .svco = 0, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 3},
@@ -398,13 +448,8 @@ static int tda827xa_sleep(struct dvb_frontend *fe)
398 .buf = buf, .len = sizeof(buf) }; 448 .buf = buf, .len = sizeof(buf) };
399 449
400 dprintk("%s:\n", __func__); 450 dprintk("%s:\n", __func__);
401 if (fe->ops.i2c_gate_ctrl)
402 fe->ops.i2c_gate_ctrl(fe, 1);
403 451
404 i2c_transfer(priv->i2c_adap, &msg, 1); 452 tuner_transfer(fe, &msg, 1);
405
406 if (fe->ops.i2c_gate_ctrl)
407 fe->ops.i2c_gate_ctrl(fe, 0);
408 453
409 if (priv->cfg && priv->cfg->sleep) 454 if (priv->cfg && priv->cfg->sleep)
410 priv->cfg->sleep(fe); 455 priv->cfg->sleep(fe);
@@ -455,7 +500,7 @@ static void tda827xa_lna_gain(struct dvb_frontend *fe, int high,
455 buf[1] = high ? 0 : 1; 500 buf[1] = high ? 0 : 1;
456 if (priv->cfg->config == 2) 501 if (priv->cfg->config == 2)
457 buf[1] = high ? 1 : 0; 502 buf[1] = high ? 1 : 0;
458 i2c_transfer(priv->i2c_adap, &msg, 1); 503 tuner_transfer(fe, &msg, 1);
459 break; 504 break;
460 case 3: /* switch with GPIO of saa713x */ 505 case 3: /* switch with GPIO of saa713x */
461 if (fe->callback) 506 if (fe->callback)
@@ -469,12 +514,13 @@ static int tda827xa_set_params(struct dvb_frontend *fe,
469 struct dvb_frontend_parameters *params) 514 struct dvb_frontend_parameters *params)
470{ 515{
471 struct tda827x_priv *priv = fe->tuner_priv; 516 struct tda827x_priv *priv = fe->tuner_priv;
517 struct tda827xa_data *frequency_map = tda827xa_dvbt;
472 u8 buf[11]; 518 u8 buf[11];
473 519
474 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0, 520 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
475 .buf = buf, .len = sizeof(buf) }; 521 .buf = buf, .len = sizeof(buf) };
476 522
477 int i, tuner_freq, if_freq; 523 int i, tuner_freq, if_freq, rc;
478 u32 N; 524 u32 N;
479 525
480 dprintk("%s:\n", __func__); 526 dprintk("%s:\n", __func__);
@@ -495,56 +541,58 @@ static int tda827xa_set_params(struct dvb_frontend *fe,
495 } 541 }
496 tuner_freq = params->frequency + if_freq; 542 tuner_freq = params->frequency + if_freq;
497 543
544 if (fe->ops.info.type == FE_QAM) {
545 dprintk("%s select tda827xa_dvbc\n", __func__);
546 frequency_map = tda827xa_dvbc;
547 }
548
498 i = 0; 549 i = 0;
499 while (tda827xa_dvbt[i].lomax < tuner_freq) { 550 while (frequency_map[i].lomax < tuner_freq) {
500 if(tda827xa_dvbt[i + 1].lomax == 0) 551 if (frequency_map[i + 1].lomax == 0)
501 break; 552 break;
502 i++; 553 i++;
503 } 554 }
504 555
505 N = ((tuner_freq + 31250) / 62500) << tda827xa_dvbt[i].spd; 556 N = ((tuner_freq + 31250) / 62500) << frequency_map[i].spd;
506 buf[0] = 0; // subaddress 557 buf[0] = 0; // subaddress
507 buf[1] = N >> 8; 558 buf[1] = N >> 8;
508 buf[2] = N & 0xff; 559 buf[2] = N & 0xff;
509 buf[3] = 0; 560 buf[3] = 0;
510 buf[4] = 0x16; 561 buf[4] = 0x16;
511 buf[5] = (tda827xa_dvbt[i].spd << 5) + (tda827xa_dvbt[i].svco << 3) + 562 buf[5] = (frequency_map[i].spd << 5) + (frequency_map[i].svco << 3) +
512 tda827xa_dvbt[i].sbs; 563 frequency_map[i].sbs;
513 buf[6] = 0x4b + (tda827xa_dvbt[i].gc3 << 4); 564 buf[6] = 0x4b + (frequency_map[i].gc3 << 4);
514 buf[7] = 0x1c; 565 buf[7] = 0x1c;
515 buf[8] = 0x06; 566 buf[8] = 0x06;
516 buf[9] = 0x24; 567 buf[9] = 0x24;
517 buf[10] = 0x00; 568 buf[10] = 0x00;
518 msg.len = 11; 569 msg.len = 11;
519 if (fe->ops.i2c_gate_ctrl) 570 rc = tuner_transfer(fe, &msg, 1);
520 fe->ops.i2c_gate_ctrl(fe, 1); 571 if (rc < 0)
521 if (i2c_transfer(priv->i2c_adap, &msg, 1) != 1) { 572 goto err;
522 printk("%s: could not write to tuner at addr: 0x%02x\n", 573
523 __func__, priv->i2c_addr << 1);
524 return -EIO;
525 }
526 buf[0] = 0x90; 574 buf[0] = 0x90;
527 buf[1] = 0xff; 575 buf[1] = 0xff;
528 buf[2] = 0x60; 576 buf[2] = 0x60;
529 buf[3] = 0x00; 577 buf[3] = 0x00;
530 buf[4] = 0x59; // lpsel, for 6MHz + 2 578 buf[4] = 0x59; // lpsel, for 6MHz + 2
531 msg.len = 5; 579 msg.len = 5;
532 if (fe->ops.i2c_gate_ctrl) 580 rc = tuner_transfer(fe, &msg, 1);
533 fe->ops.i2c_gate_ctrl(fe, 1); 581 if (rc < 0)
534 i2c_transfer(priv->i2c_adap, &msg, 1); 582 goto err;
535 583
536 buf[0] = 0xa0; 584 buf[0] = 0xa0;
537 buf[1] = 0x40; 585 buf[1] = 0x40;
538 msg.len = 2; 586 msg.len = 2;
539 if (fe->ops.i2c_gate_ctrl) 587 rc = tuner_transfer(fe, &msg, 1);
540 fe->ops.i2c_gate_ctrl(fe, 1); 588 if (rc < 0)
541 i2c_transfer(priv->i2c_adap, &msg, 1); 589 goto err;
542 590
543 msleep(11); 591 msleep(11);
544 msg.flags = I2C_M_RD; 592 msg.flags = I2C_M_RD;
545 if (fe->ops.i2c_gate_ctrl) 593 rc = tuner_transfer(fe, &msg, 1);
546 fe->ops.i2c_gate_ctrl(fe, 1); 594 if (rc < 0)
547 i2c_transfer(priv->i2c_adap, &msg, 1); 595 goto err;
548 msg.flags = 0; 596 msg.flags = 0;
549 597
550 buf[1] >>= 4; 598 buf[1] >>= 4;
@@ -553,49 +601,55 @@ static int tda827xa_set_params(struct dvb_frontend *fe,
553 tda827xa_lna_gain(fe, 0, NULL); 601 tda827xa_lna_gain(fe, 0, NULL);
554 buf[0] = 0x60; 602 buf[0] = 0x60;
555 buf[1] = 0x0c; 603 buf[1] = 0x0c;
556 if (fe->ops.i2c_gate_ctrl) 604 rc = tuner_transfer(fe, &msg, 1);
557 fe->ops.i2c_gate_ctrl(fe, 1); 605 if (rc < 0)
558 i2c_transfer(priv->i2c_adap, &msg, 1); 606 goto err;
559 } 607 }
560 608
561 buf[0] = 0xc0; 609 buf[0] = 0xc0;
562 buf[1] = 0x99; // lpsel, for 6MHz + 2 610 buf[1] = 0x99; // lpsel, for 6MHz + 2
563 if (fe->ops.i2c_gate_ctrl) 611 rc = tuner_transfer(fe, &msg, 1);
564 fe->ops.i2c_gate_ctrl(fe, 1); 612 if (rc < 0)
565 i2c_transfer(priv->i2c_adap, &msg, 1); 613 goto err;
566 614
567 buf[0] = 0x60; 615 buf[0] = 0x60;
568 buf[1] = 0x3c; 616 buf[1] = 0x3c;
569 if (fe->ops.i2c_gate_ctrl) 617 rc = tuner_transfer(fe, &msg, 1);
570 fe->ops.i2c_gate_ctrl(fe, 1); 618 if (rc < 0)
571 i2c_transfer(priv->i2c_adap, &msg, 1); 619 goto err;
572 620
573 /* correct CP value */ 621 /* correct CP value */
574 buf[0] = 0x30; 622 buf[0] = 0x30;
575 buf[1] = 0x10 + tda827xa_dvbt[i].scr; 623 buf[1] = 0x10 + frequency_map[i].scr;
576 if (fe->ops.i2c_gate_ctrl) 624 rc = tuner_transfer(fe, &msg, 1);
577 fe->ops.i2c_gate_ctrl(fe, 1); 625 if (rc < 0)
578 i2c_transfer(priv->i2c_adap, &msg, 1); 626 goto err;
579 627
580 msleep(163); 628 msleep(163);
581 buf[0] = 0xc0; 629 buf[0] = 0xc0;
582 buf[1] = 0x39; // lpsel, for 6MHz + 2 630 buf[1] = 0x39; // lpsel, for 6MHz + 2
583 if (fe->ops.i2c_gate_ctrl) 631 rc = tuner_transfer(fe, &msg, 1);
584 fe->ops.i2c_gate_ctrl(fe, 1); 632 if (rc < 0)
585 i2c_transfer(priv->i2c_adap, &msg, 1); 633 goto err;
586 634
587 msleep(3); 635 msleep(3);
588 /* freeze AGC1 */ 636 /* freeze AGC1 */
589 buf[0] = 0x50; 637 buf[0] = 0x50;
590 buf[1] = 0x4f + (tda827xa_dvbt[i].gc3 << 4); 638 buf[1] = 0x4f + (frequency_map[i].gc3 << 4);
591 if (fe->ops.i2c_gate_ctrl) 639 rc = tuner_transfer(fe, &msg, 1);
592 fe->ops.i2c_gate_ctrl(fe, 1); 640 if (rc < 0)
593 i2c_transfer(priv->i2c_adap, &msg, 1); 641 goto err;
594 642
595 priv->frequency = params->frequency; 643 priv->frequency = params->frequency;
596 priv->bandwidth = (fe->ops.info.type == FE_OFDM) ? params->u.ofdm.bandwidth : 0; 644 priv->bandwidth = (fe->ops.info.type == FE_OFDM) ? params->u.ofdm.bandwidth : 0;
597 645
646
598 return 0; 647 return 0;
648
649err:
650 printk(KERN_ERR "%s: could not write to tuner at addr: 0x%02x\n",
651 __func__, priv->i2c_addr << 1);
652 return rc;
599} 653}
600 654
601 655
@@ -643,7 +697,7 @@ static int tda827xa_set_analog_params(struct dvb_frontend *fe,
643 tuner_reg[9] = 0x20; 697 tuner_reg[9] = 0x20;
644 tuner_reg[10] = 0x00; 698 tuner_reg[10] = 0x00;
645 msg.len = 11; 699 msg.len = 11;
646 i2c_transfer(priv->i2c_adap, &msg, 1); 700 tuner_transfer(fe, &msg, 1);
647 701
648 tuner_reg[0] = 0x90; 702 tuner_reg[0] = 0x90;
649 tuner_reg[1] = 0xff; 703 tuner_reg[1] = 0xff;
@@ -651,19 +705,19 @@ static int tda827xa_set_analog_params(struct dvb_frontend *fe,
651 tuner_reg[3] = 0; 705 tuner_reg[3] = 0;
652 tuner_reg[4] = 0x99 + (priv->lpsel << 1); 706 tuner_reg[4] = 0x99 + (priv->lpsel << 1);
653 msg.len = 5; 707 msg.len = 5;
654 i2c_transfer(priv->i2c_adap, &msg, 1); 708 tuner_transfer(fe, &msg, 1);
655 709
656 tuner_reg[0] = 0xa0; 710 tuner_reg[0] = 0xa0;
657 tuner_reg[1] = 0xc0; 711 tuner_reg[1] = 0xc0;
658 msg.len = 2; 712 msg.len = 2;
659 i2c_transfer(priv->i2c_adap, &msg, 1); 713 tuner_transfer(fe, &msg, 1);
660 714
661 tuner_reg[0] = 0x30; 715 tuner_reg[0] = 0x30;
662 tuner_reg[1] = 0x10 + tda827xa_analog[i].scr; 716 tuner_reg[1] = 0x10 + tda827xa_analog[i].scr;
663 i2c_transfer(priv->i2c_adap, &msg, 1); 717 tuner_transfer(fe, &msg, 1);
664 718
665 msg.flags = I2C_M_RD; 719 msg.flags = I2C_M_RD;
666 i2c_transfer(priv->i2c_adap, &msg, 1); 720 tuner_transfer(fe, &msg, 1);
667 msg.flags = 0; 721 msg.flags = 0;
668 tuner_reg[1] >>= 4; 722 tuner_reg[1] >>= 4;
669 dprintk("AGC2 gain is: %d\n", tuner_reg[1]); 723 dprintk("AGC2 gain is: %d\n", tuner_reg[1]);
@@ -673,24 +727,24 @@ static int tda827xa_set_analog_params(struct dvb_frontend *fe,
673 msleep(100); 727 msleep(100);
674 tuner_reg[0] = 0x60; 728 tuner_reg[0] = 0x60;
675 tuner_reg[1] = 0x3c; 729 tuner_reg[1] = 0x3c;
676 i2c_transfer(priv->i2c_adap, &msg, 1); 730 tuner_transfer(fe, &msg, 1);
677 731
678 msleep(163); 732 msleep(163);
679 tuner_reg[0] = 0x50; 733 tuner_reg[0] = 0x50;
680 tuner_reg[1] = 0x8f + (tda827xa_analog[i].gc3 << 4); 734 tuner_reg[1] = 0x8f + (tda827xa_analog[i].gc3 << 4);
681 i2c_transfer(priv->i2c_adap, &msg, 1); 735 tuner_transfer(fe, &msg, 1);
682 736
683 tuner_reg[0] = 0x80; 737 tuner_reg[0] = 0x80;
684 tuner_reg[1] = 0x28; 738 tuner_reg[1] = 0x28;
685 i2c_transfer(priv->i2c_adap, &msg, 1); 739 tuner_transfer(fe, &msg, 1);
686 740
687 tuner_reg[0] = 0xb0; 741 tuner_reg[0] = 0xb0;
688 tuner_reg[1] = 0x01; 742 tuner_reg[1] = 0x01;
689 i2c_transfer(priv->i2c_adap, &msg, 1); 743 tuner_transfer(fe, &msg, 1);
690 744
691 tuner_reg[0] = 0xc0; 745 tuner_reg[0] = 0xc0;
692 tuner_reg[1] = 0x19 + (priv->lpsel << 1); 746 tuner_reg[1] = 0x19 + (priv->lpsel << 1);
693 i2c_transfer(priv->i2c_adap, &msg, 1); 747 tuner_transfer(fe, &msg, 1);
694 748
695 priv->frequency = params->frequency; 749 priv->frequency = params->frequency;
696 750
@@ -703,7 +757,7 @@ static void tda827xa_agcf(struct dvb_frontend *fe)
703 unsigned char data[] = {0x80, 0x2c}; 757 unsigned char data[] = {0x80, 0x2c};
704 struct i2c_msg msg = {.addr = priv->i2c_addr, .flags = 0, 758 struct i2c_msg msg = {.addr = priv->i2c_addr, .flags = 0,
705 .buf = data, .len = 2}; 759 .buf = data, .len = 2};
706 i2c_transfer(priv->i2c_adap, &msg, 1); 760 tuner_transfer(fe, &msg, 1);
707} 761}
708 762
709/* ------------------------------------------------------------------ */ 763/* ------------------------------------------------------------------ */
@@ -792,16 +846,19 @@ static struct dvb_tuner_ops tda827xa_tuner_ops = {
792}; 846};
793 847
794static int tda827x_probe_version(struct dvb_frontend *fe) 848static int tda827x_probe_version(struct dvb_frontend *fe)
795{ u8 data; 849{
850 u8 data;
851 int rc;
796 struct tda827x_priv *priv = fe->tuner_priv; 852 struct tda827x_priv *priv = fe->tuner_priv;
797 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = I2C_M_RD, 853 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = I2C_M_RD,
798 .buf = &data, .len = 1 }; 854 .buf = &data, .len = 1 };
799 if (fe->ops.i2c_gate_ctrl) 855
800 fe->ops.i2c_gate_ctrl(fe, 1); 856 rc = tuner_transfer(fe, &msg, 1);
801 if (i2c_transfer(priv->i2c_adap, &msg, 1) != 1) { 857
858 if (rc < 0) {
802 printk("%s: could not read from tuner at addr: 0x%02x\n", 859 printk("%s: could not read from tuner at addr: 0x%02x\n",
803 __func__, msg.addr << 1); 860 __func__, msg.addr << 1);
804 return -EIO; 861 return rc;
805 } 862 }
806 if ((data & 0x3c) == 0) { 863 if ((data & 0x3c) == 0) {
807 dprintk("tda827x tuner found\n"); 864 dprintk("tda827x tuner found\n");
diff --git a/drivers/media/common/tuners/tda8290.c b/drivers/media/common/tuners/tda8290.c
index 4b8662edb7cb..064d14c8d7b2 100644
--- a/drivers/media/common/tuners/tda8290.c
+++ b/drivers/media/common/tuners/tda8290.c
@@ -22,7 +22,7 @@
22 22
23#include <linux/i2c.h> 23#include <linux/i2c.h>
24#include <linux/delay.h> 24#include <linux/delay.h>
25#include <linux/videodev.h> 25#include <linux/videodev2.h>
26#include "tuner-i2c.h" 26#include "tuner-i2c.h"
27#include "tda8290.h" 27#include "tda8290.h"
28#include "tda827x.h" 28#include "tda827x.h"
@@ -566,8 +566,11 @@ static int tda829x_find_tuner(struct dvb_frontend *fe)
566 u8 data; 566 u8 data;
567 struct i2c_msg msg = { .flags = I2C_M_RD, .buf = &data, .len = 1 }; 567 struct i2c_msg msg = { .flags = I2C_M_RD, .buf = &data, .len = 1 };
568 568
569 if (NULL == analog_ops->i2c_gate_ctrl) 569 if (!analog_ops->i2c_gate_ctrl) {
570 printk(KERN_ERR "tda8290: no gate control were provided!\n");
571
570 return -EINVAL; 572 return -EINVAL;
573 }
571 574
572 analog_ops->i2c_gate_ctrl(fe, 1); 575 analog_ops->i2c_gate_ctrl(fe, 1);
573 576
@@ -615,11 +618,13 @@ static int tda829x_find_tuner(struct dvb_frontend *fe)
615 618
616 if (ret != 1) { 619 if (ret != 1) {
617 tuner_warn("tuner access failed!\n"); 620 tuner_warn("tuner access failed!\n");
621 analog_ops->i2c_gate_ctrl(fe, 0);
618 return -EREMOTEIO; 622 return -EREMOTEIO;
619 } 623 }
620 624
621 if ((data == 0x83) || (data == 0x84)) { 625 if ((data == 0x83) || (data == 0x84)) {
622 priv->ver |= TDA18271; 626 priv->ver |= TDA18271;
627 tda829x_tda18271_config.config = priv->cfg.config;
623 dvb_attach(tda18271_attach, fe, priv->tda827x_addr, 628 dvb_attach(tda18271_attach, fe, priv->tda827x_addr,
624 priv->i2c_props.adap, &tda829x_tda18271_config); 629 priv->i2c_props.adap, &tda829x_tda18271_config);
625 } else { 630 } else {
diff --git a/drivers/media/common/tuners/tea5761.c b/drivers/media/common/tuners/tea5761.c
index b23dadeecd05..60ed872f3d44 100644
--- a/drivers/media/common/tuners/tea5761.c
+++ b/drivers/media/common/tuners/tea5761.c
@@ -9,7 +9,7 @@
9 9
10#include <linux/i2c.h> 10#include <linux/i2c.h>
11#include <linux/delay.h> 11#include <linux/delay.h>
12#include <linux/videodev.h> 12#include <linux/videodev2.h>
13#include <media/tuner.h> 13#include <media/tuner.h>
14#include "tuner-i2c.h" 14#include "tuner-i2c.h"
15#include "tea5761.h" 15#include "tea5761.h"
diff --git a/drivers/media/common/tuners/tea5767.c b/drivers/media/common/tuners/tea5767.c
index 1f5646334a8f..223a226d20a1 100644
--- a/drivers/media/common/tuners/tea5767.c
+++ b/drivers/media/common/tuners/tea5767.c
@@ -12,7 +12,7 @@
12 12
13#include <linux/i2c.h> 13#include <linux/i2c.h>
14#include <linux/delay.h> 14#include <linux/delay.h>
15#include <linux/videodev.h> 15#include <linux/videodev2.h>
16#include "tuner-i2c.h" 16#include "tuner-i2c.h"
17#include "tea5767.h" 17#include "tea5767.h"
18 18
diff --git a/drivers/media/common/tuners/xc5000.c b/drivers/media/common/tuners/xc5000.c
index 493ce93caf43..b54598550dc4 100644
--- a/drivers/media/common/tuners/xc5000.c
+++ b/drivers/media/common/tuners/xc5000.c
@@ -739,7 +739,10 @@ static int xc5000_set_analog_params(struct dvb_frontend *fe,
739 dprintk(1, "%s() frequency=%d (in units of 62.5khz)\n", 739 dprintk(1, "%s() frequency=%d (in units of 62.5khz)\n",
740 __func__, params->frequency); 740 __func__, params->frequency);
741 741
742 priv->rf_mode = XC_RF_MODE_CABLE; /* Fix me: it could be air. */ 742 /* Fix me: it could be air. */
743 priv->rf_mode = params->mode;
744 if (params->mode > XC_RF_MODE_CABLE)
745 priv->rf_mode = XC_RF_MODE_CABLE;
743 746
744 /* params->frequency is in units of 62.5khz */ 747 /* params->frequency is in units of 62.5khz */
745 priv->freq_hz = params->frequency * 62500; 748 priv->freq_hz = params->frequency * 62500;
@@ -970,8 +973,6 @@ struct dvb_frontend *xc5000_attach(struct dvb_frontend *fe,
970 case 1: 973 case 1:
971 /* new tuner instance */ 974 /* new tuner instance */
972 priv->bandwidth = BANDWIDTH_6_MHZ; 975 priv->bandwidth = BANDWIDTH_6_MHZ;
973 priv->if_khz = cfg->if_khz;
974
975 fe->tuner_priv = priv; 976 fe->tuner_priv = priv;
976 break; 977 break;
977 default: 978 default:
@@ -980,6 +981,13 @@ struct dvb_frontend *xc5000_attach(struct dvb_frontend *fe,
980 break; 981 break;
981 } 982 }
982 983
984 if (priv->if_khz == 0) {
985 /* If the IF hasn't been set yet, use the value provided by
986 the caller (occurs in hybrid devices where the analog
987 call to xc5000_attach occurs before the digital side) */
988 priv->if_khz = cfg->if_khz;
989 }
990
983 /* Check if firmware has been loaded. It is possible that another 991 /* Check if firmware has been loaded. It is possible that another
984 instance of the driver has loaded the firmware. 992 instance of the driver has loaded the firmware.
985 */ 993 */
diff --git a/drivers/media/dvb/b2c2/Kconfig b/drivers/media/dvb/b2c2/Kconfig
index a8c6249c4099..9e5781400744 100644
--- a/drivers/media/dvb/b2c2/Kconfig
+++ b/drivers/media/dvb/b2c2/Kconfig
@@ -13,7 +13,7 @@ config DVB_B2C2_FLEXCOP
13 select DVB_TUNER_ITD1000 if !DVB_FE_CUSTOMISE 13 select DVB_TUNER_ITD1000 if !DVB_FE_CUSTOMISE
14 select DVB_ISL6421 if !DVB_FE_CUSTOMISE 14 select DVB_ISL6421 if !DVB_FE_CUSTOMISE
15 select DVB_CX24123 if !DVB_FE_CUSTOMISE 15 select DVB_CX24123 if !DVB_FE_CUSTOMISE
16 select MEDIA_TUNER_SIMPLE if !MEDIA_TUNER_CUSTOMIZE 16 select MEDIA_TUNER_SIMPLE if !MEDIA_TUNER_CUSTOMISE
17 select DVB_TUNER_CX24113 if !DVB_FE_CUSTOMISE 17 select DVB_TUNER_CX24113 if !DVB_FE_CUSTOMISE
18 help 18 help
19 Support for the digital TV receiver chip made by B2C2 Inc. included in 19 Support for the digital TV receiver chip made by B2C2 Inc. included in
diff --git a/drivers/media/dvb/b2c2/Makefile b/drivers/media/dvb/b2c2/Makefile
index d9db066f9854..b97cf7208a18 100644
--- a/drivers/media/dvb/b2c2/Makefile
+++ b/drivers/media/dvb/b2c2/Makefile
@@ -2,7 +2,6 @@ b2c2-flexcop-objs = flexcop.o flexcop-fe-tuner.o flexcop-i2c.o \
2 flexcop-sram.o flexcop-eeprom.o flexcop-misc.o flexcop-hw-filter.o 2 flexcop-sram.o flexcop-eeprom.o flexcop-misc.o flexcop-hw-filter.o
3obj-$(CONFIG_DVB_B2C2_FLEXCOP) += b2c2-flexcop.o 3obj-$(CONFIG_DVB_B2C2_FLEXCOP) += b2c2-flexcop.o
4 4
5
6ifneq ($(CONFIG_DVB_B2C2_FLEXCOP_PCI),) 5ifneq ($(CONFIG_DVB_B2C2_FLEXCOP_PCI),)
7b2c2-flexcop-objs += flexcop-dma.o 6b2c2-flexcop-objs += flexcop-dma.o
8endif 7endif
diff --git a/drivers/media/dvb/b2c2/flexcop-common.h b/drivers/media/dvb/b2c2/flexcop-common.h
index 8ce06336e76f..3e1c472092ab 100644
--- a/drivers/media/dvb/b2c2/flexcop-common.h
+++ b/drivers/media/dvb/b2c2/flexcop-common.h
@@ -28,11 +28,14 @@
28 28
29/* Steal from usb.h */ 29/* Steal from usb.h */
30#undef err 30#undef err
31#define err(format, arg...) printk(KERN_ERR FC_LOG_PREFIX ": " format "\n" , ## arg) 31#define err(format, arg...) \
32 printk(KERN_ERR FC_LOG_PREFIX ": " format "\n" , ## arg)
32#undef info 33#undef info
33#define info(format, arg...) printk(KERN_INFO FC_LOG_PREFIX ": " format "\n" , ## arg) 34#define info(format, arg...) \
35 printk(KERN_INFO FC_LOG_PREFIX ": " format "\n" , ## arg)
34#undef warn 36#undef warn
35#define warn(format, arg...) printk(KERN_WARNING FC_LOG_PREFIX ": " format "\n" , ## arg) 37#define warn(format, arg...) \
38 printk(KERN_WARNING FC_LOG_PREFIX ": " format "\n" , ## arg)
36 39
37struct flexcop_dma { 40struct flexcop_dma {
38 struct pci_dev *pdev; 41 struct pci_dev *pdev;
@@ -91,16 +94,14 @@ struct flexcop_device {
91 int fullts_streaming_state; 94 int fullts_streaming_state;
92 95
93 /* bus specific callbacks */ 96 /* bus specific callbacks */
94 flexcop_ibi_value (*read_ibi_reg) (struct flexcop_device *, flexcop_ibi_register); 97 flexcop_ibi_value(*read_ibi_reg) (struct flexcop_device *,
95 int (*write_ibi_reg) (struct flexcop_device *, flexcop_ibi_register, flexcop_ibi_value); 98 flexcop_ibi_register);
96 99 int (*write_ibi_reg) (struct flexcop_device *,
97 100 flexcop_ibi_register, flexcop_ibi_value);
98 int (*i2c_request) (struct flexcop_i2c_adapter*, 101 int (*i2c_request) (struct flexcop_i2c_adapter *,
99 flexcop_access_op_t, u8 chipaddr, u8 addr, u8 *buf, u16 len); 102 flexcop_access_op_t, u8 chipaddr, u8 addr, u8 *buf, u16 len);
100 int (*stream_control) (struct flexcop_device*, int); 103 int (*stream_control) (struct flexcop_device *, int);
101
102 int (*get_mac_addr) (struct flexcop_device *fc, int extended); 104 int (*get_mac_addr) (struct flexcop_device *fc, int extended);
103
104 void *bus_specific; 105 void *bus_specific;
105}; 106};
106 107
@@ -111,22 +112,28 @@ void flexcop_pass_dmx_data(struct flexcop_device *fc, u8 *buf, u32 len);
111void flexcop_pass_dmx_packets(struct flexcop_device *fc, u8 *buf, u32 no); 112void flexcop_pass_dmx_packets(struct flexcop_device *fc, u8 *buf, u32 no);
112 113
113struct flexcop_device *flexcop_device_kmalloc(size_t bus_specific_len); 114struct flexcop_device *flexcop_device_kmalloc(size_t bus_specific_len);
114void flexcop_device_kfree(struct flexcop_device*); 115void flexcop_device_kfree(struct flexcop_device *);
115 116
116int flexcop_device_initialize(struct flexcop_device*); 117int flexcop_device_initialize(struct flexcop_device *);
117void flexcop_device_exit(struct flexcop_device *fc); 118void flexcop_device_exit(struct flexcop_device *fc);
118
119void flexcop_reset_block_300(struct flexcop_device *fc); 119void flexcop_reset_block_300(struct flexcop_device *fc);
120 120
121/* from flexcop-dma.c */ 121/* from flexcop-dma.c */
122int flexcop_dma_allocate(struct pci_dev *pdev, struct flexcop_dma *dma, u32 size); 122int flexcop_dma_allocate(struct pci_dev *pdev,
123 struct flexcop_dma *dma, u32 size);
123void flexcop_dma_free(struct flexcop_dma *dma); 124void flexcop_dma_free(struct flexcop_dma *dma);
124 125
125int flexcop_dma_control_timer_irq(struct flexcop_device *fc, flexcop_dma_index_t no, int onoff); 126int flexcop_dma_control_timer_irq(struct flexcop_device *fc,
126int flexcop_dma_control_size_irq(struct flexcop_device *fc, flexcop_dma_index_t no, int onoff); 127 flexcop_dma_index_t no, int onoff);
127int flexcop_dma_config(struct flexcop_device *fc, struct flexcop_dma *dma, flexcop_dma_index_t dma_idx); 128int flexcop_dma_control_size_irq(struct flexcop_device *fc,
128int flexcop_dma_xfer_control(struct flexcop_device *fc, flexcop_dma_index_t dma_idx, flexcop_dma_addr_index_t index, int onoff); 129 flexcop_dma_index_t no, int onoff);
129int flexcop_dma_config_timer(struct flexcop_device *fc, flexcop_dma_index_t dma_idx, u8 cycles); 130int flexcop_dma_config(struct flexcop_device *fc, struct flexcop_dma *dma,
131 flexcop_dma_index_t dma_idx);
132int flexcop_dma_xfer_control(struct flexcop_device *fc,
133 flexcop_dma_index_t dma_idx, flexcop_dma_addr_index_t index,
134 int onoff);
135int flexcop_dma_config_timer(struct flexcop_device *fc,
136 flexcop_dma_index_t dma_idx, u8 cycles);
130 137
131/* from flexcop-eeprom.c */ 138/* from flexcop-eeprom.c */
132/* the PCI part uses this call to get the MAC address, the USB part has its own */ 139/* the PCI part uses this call to get the MAC address, the USB part has its own */
@@ -141,13 +148,15 @@ int flexcop_i2c_request(struct flexcop_i2c_adapter*, flexcop_access_op_t,
141 u8 chipaddr, u8 addr, u8 *buf, u16 len); 148 u8 chipaddr, u8 addr, u8 *buf, u16 len);
142 149
143/* from flexcop-sram.c */ 150/* from flexcop-sram.c */
144int flexcop_sram_set_dest(struct flexcop_device *fc, flexcop_sram_dest_t dest, flexcop_sram_dest_target_t target); 151int flexcop_sram_set_dest(struct flexcop_device *fc, flexcop_sram_dest_t dest,
152 flexcop_sram_dest_target_t target);
145void flexcop_wan_set_speed(struct flexcop_device *fc, flexcop_wan_speed_t s); 153void flexcop_wan_set_speed(struct flexcop_device *fc, flexcop_wan_speed_t s);
146void flexcop_sram_ctrl(struct flexcop_device *fc, int usb_wan, int sramdma, int maximumfill); 154void flexcop_sram_ctrl(struct flexcop_device *fc,
155 int usb_wan, int sramdma, int maximumfill);
147 156
148/* global prototypes for the flexcop-chip */ 157/* global prototypes for the flexcop-chip */
149/* from flexcop-fe-tuner.c */ 158/* from flexcop-fe-tuner.c */
150int flexcop_frontend_init(struct flexcop_device *card); 159int flexcop_frontend_init(struct flexcop_device *fc);
151void flexcop_frontend_exit(struct flexcop_device *fc); 160void flexcop_frontend_exit(struct flexcop_device *fc);
152 161
153/* from flexcop-i2c.c */ 162/* from flexcop-i2c.c */
@@ -159,11 +168,14 @@ int flexcop_sram_init(struct flexcop_device *fc);
159 168
160/* from flexcop-misc.c */ 169/* from flexcop-misc.c */
161void flexcop_determine_revision(struct flexcop_device *fc); 170void flexcop_determine_revision(struct flexcop_device *fc);
162void flexcop_device_name(struct flexcop_device *fc,const char *prefix,const char *suffix); 171void flexcop_device_name(struct flexcop_device *fc,
163void flexcop_dump_reg(struct flexcop_device *fc, flexcop_ibi_register reg, int num); 172 const char *prefix, const char *suffix);
173void flexcop_dump_reg(struct flexcop_device *fc,
174 flexcop_ibi_register reg, int num);
164 175
165/* from flexcop-hw-filter.c */ 176/* from flexcop-hw-filter.c */
166int flexcop_pid_feed_control(struct flexcop_device *fc, struct dvb_demux_feed *dvbdmxfeed, int onoff); 177int flexcop_pid_feed_control(struct flexcop_device *fc,
178 struct dvb_demux_feed *dvbdmxfeed, int onoff);
167void flexcop_hw_filter_init(struct flexcop_device *fc); 179void flexcop_hw_filter_init(struct flexcop_device *fc);
168 180
169void flexcop_smc_ctrl(struct flexcop_device *fc, int onoff); 181void flexcop_smc_ctrl(struct flexcop_device *fc, int onoff);
diff --git a/drivers/media/dvb/b2c2/flexcop-dma.c b/drivers/media/dvb/b2c2/flexcop-dma.c
index 26f0011a5078..2881e0d956ad 100644
--- a/drivers/media/dvb/b2c2/flexcop-dma.c
+++ b/drivers/media/dvb/b2c2/flexcop-dma.c
@@ -1,13 +1,12 @@
1/* 1/*
2 * This file is part of linux driver the digital TV devices equipped with B2C2 FlexcopII(b)/III 2 * Linux driver for digital TV devices equipped with B2C2 FlexcopII(b)/III
3 * 3 * flexcop-dma.c - configuring and controlling the DMA of the FlexCop
4 * flexcop-dma.c - methods for configuring and controlling the DMA of the FlexCop. 4 * see flexcop.c for copyright information
5 *
6 * see flexcop.c for copyright information.
7 */ 5 */
8#include "flexcop.h" 6#include "flexcop.h"
9 7
10int flexcop_dma_allocate(struct pci_dev *pdev, struct flexcop_dma *dma, u32 size) 8int flexcop_dma_allocate(struct pci_dev *pdev,
9 struct flexcop_dma *dma, u32 size)
11{ 10{
12 u8 *tcpu; 11 u8 *tcpu;
13 dma_addr_t tdma = 0; 12 dma_addr_t tdma = 0;
@@ -32,7 +31,8 @@ EXPORT_SYMBOL(flexcop_dma_allocate);
32 31
33void flexcop_dma_free(struct flexcop_dma *dma) 32void flexcop_dma_free(struct flexcop_dma *dma)
34{ 33{
35 pci_free_consistent(dma->pdev, dma->size*2,dma->cpu_addr0, dma->dma_addr0); 34 pci_free_consistent(dma->pdev, dma->size*2,
35 dma->cpu_addr0, dma->dma_addr0);
36 memset(dma,0,sizeof(struct flexcop_dma)); 36 memset(dma,0,sizeof(struct flexcop_dma));
37} 37}
38EXPORT_SYMBOL(flexcop_dma_free); 38EXPORT_SYMBOL(flexcop_dma_free);
@@ -44,8 +44,8 @@ int flexcop_dma_config(struct flexcop_device *fc,
44 flexcop_ibi_value v0x0,v0x4,v0xc; 44 flexcop_ibi_value v0x0,v0x4,v0xc;
45 v0x0.raw = v0x4.raw = v0xc.raw = 0; 45 v0x0.raw = v0x4.raw = v0xc.raw = 0;
46 46
47 v0x0.dma_0x0.dma_address0 = dma->dma_addr0 >> 2; 47 v0x0.dma_0x0.dma_address0 = dma->dma_addr0 >> 2;
48 v0xc.dma_0xc.dma_address1 = dma->dma_addr1 >> 2; 48 v0xc.dma_0xc.dma_address1 = dma->dma_addr1 >> 2;
49 v0x4.dma_0x4_write.dma_addr_size = dma->size / 4; 49 v0x4.dma_0x4_write.dma_addr_size = dma->size / 4;
50 50
51 if ((dma_idx & FC_DMA_1) == dma_idx) { 51 if ((dma_idx & FC_DMA_1) == dma_idx) {
@@ -57,7 +57,8 @@ int flexcop_dma_config(struct flexcop_device *fc,
57 fc->write_ibi_reg(fc,dma2_014,v0x4); 57 fc->write_ibi_reg(fc,dma2_014,v0x4);
58 fc->write_ibi_reg(fc,dma2_01c,v0xc); 58 fc->write_ibi_reg(fc,dma2_01c,v0xc);
59 } else { 59 } else {
60 err("either DMA1 or DMA2 can be configured at the within one flexcop_dma_config call."); 60 err("either DMA1 or DMA2 can be configured within one "
61 "flexcop_dma_config call.");
61 return -EINVAL; 62 return -EINVAL;
62 } 63 }
63 64
@@ -81,7 +82,8 @@ int flexcop_dma_xfer_control(struct flexcop_device *fc,
81 r0x0 = dma2_010; 82 r0x0 = dma2_010;
82 r0xc = dma2_01c; 83 r0xc = dma2_01c;
83 } else { 84 } else {
84 err("either transfer DMA1 or DMA2 can be started within one flexcop_dma_xfer_control call."); 85 err("either transfer DMA1 or DMA2 can be started within one "
86 "flexcop_dma_xfer_control call.");
85 return -EINVAL; 87 return -EINVAL;
86 } 88 }
87 89
@@ -154,8 +156,7 @@ EXPORT_SYMBOL(flexcop_dma_control_timer_irq);
154 156
155/* 1 cycles = 1.97 msec */ 157/* 1 cycles = 1.97 msec */
156int flexcop_dma_config_timer(struct flexcop_device *fc, 158int flexcop_dma_config_timer(struct flexcop_device *fc,
157 flexcop_dma_index_t dma_idx, 159 flexcop_dma_index_t dma_idx, u8 cycles)
158 u8 cycles)
159{ 160{
160 flexcop_ibi_register r = (dma_idx & FC_DMA_1) ? dma1_004 : dma2_014; 161 flexcop_ibi_register r = (dma_idx & FC_DMA_1) ? dma1_004 : dma2_014;
161 flexcop_ibi_value v = fc->read_ibi_reg(fc,r); 162 flexcop_ibi_value v = fc->read_ibi_reg(fc,r);
diff --git a/drivers/media/dvb/b2c2/flexcop-eeprom.c b/drivers/media/dvb/b2c2/flexcop-eeprom.c
index 8a8ae8a3e6ba..a25373a9bd84 100644
--- a/drivers/media/dvb/b2c2/flexcop-eeprom.c
+++ b/drivers/media/dvb/b2c2/flexcop-eeprom.c
@@ -1,9 +1,7 @@
1/* 1/*
2 * This file is part of linux driver the digital TV devices equipped with B2C2 FlexcopII(b)/III 2 * Linux driver for digital TV devices equipped with B2C2 FlexcopII(b)/III
3 * 3 * flexcop-eeprom.c - eeprom access methods (currently only MAC address reading)
4 * flexcop-eeprom.c - eeprom access methods (currently only MAC address reading is used) 4 * see flexcop.c for copyright information
5 *
6 * see flexcop.c for copyright information.
7 */ 5 */
8#include "flexcop.h" 6#include "flexcop.h"
9 7
@@ -14,17 +12,17 @@ static int eeprom_write(struct adapter *adapter, u16 addr, u8 *buf, u16 len)
14 return flex_i2c_write(adapter, 0x20000000, 0x50, addr, buf, len); 12 return flex_i2c_write(adapter, 0x20000000, 0x50, addr, buf, len);
15} 13}
16 14
17static int eeprom_lrc_write(struct adapter *adapter, u32 addr, u32 len, u8 *wbuf, u8 *rbuf, int retries) 15static int eeprom_lrc_write(struct adapter *adapter, u32 addr,
16 u32 len, u8 *wbuf, u8 *rbuf, int retries)
18{ 17{
19 int i; 18int i;
20 19
21 for (i = 0; i < retries; i++) { 20for (i = 0; i < retries; i++) {
22 if (eeprom_write(adapter, addr, wbuf, len) == len) { 21 if (eeprom_write(adapter, addr, wbuf, len) == len) {
23 if (eeprom_lrc_read(adapter, addr, len, rbuf, retries) == 1) 22 if (eeprom_lrc_read(adapter, addr, len, rbuf, retries) == 1)
24 return 1; 23 return 1;
25 } 24 }
26 } 25 }
27
28 return 0; 26 return 0;
29} 27}
30 28
@@ -39,12 +37,10 @@ static int eeprom_writeKey(struct adapter *adapter, u8 *key, u32 len)
39 return 0; 37 return 0;
40 38
41 memcpy(wbuf, key, len); 39 memcpy(wbuf, key, len);
42
43 wbuf[16] = 0; 40 wbuf[16] = 0;
44 wbuf[17] = 0; 41 wbuf[17] = 0;
45 wbuf[18] = 0; 42 wbuf[18] = 0;
46 wbuf[19] = calc_lrc(wbuf, 19); 43 wbuf[19] = calc_lrc(wbuf, 19);
47
48 return eeprom_lrc_write(adapter, 0x3e4, 20, wbuf, rbuf, 4); 44 return eeprom_lrc_write(adapter, 0x3e4, 20, wbuf, rbuf, 4);
49} 45}
50 46
@@ -59,7 +55,6 @@ static int eeprom_readKey(struct adapter *adapter, u8 *key, u32 len)
59 return 0; 55 return 0;
60 56
61 memcpy(key, buf, len); 57 memcpy(key, buf, len);
62
63 return 1; 58 return 1;
64} 59}
65 60
@@ -74,9 +69,7 @@ static char eeprom_set_mac_addr(struct adapter *adapter, char type, u8 *mac)
74 tmp[3] = mac[5]; 69 tmp[3] = mac[5];
75 tmp[4] = mac[6]; 70 tmp[4] = mac[6];
76 tmp[5] = mac[7]; 71 tmp[5] = mac[7];
77
78 } else { 72 } else {
79
80 tmp[0] = mac[0]; 73 tmp[0] = mac[0];
81 tmp[1] = mac[1]; 74 tmp[1] = mac[1];
82 tmp[2] = mac[2]; 75 tmp[2] = mac[2];
@@ -90,11 +83,11 @@ static char eeprom_set_mac_addr(struct adapter *adapter, char type, u8 *mac)
90 83
91 if (eeprom_write(adapter, 0x3f8, tmp, 8) == 8) 84 if (eeprom_write(adapter, 0x3f8, tmp, 8) == 8)
92 return 1; 85 return 1;
93
94 return 0; 86 return 0;
95} 87}
96 88
97static int flexcop_eeprom_read(struct flexcop_device *fc, u16 addr, u8 *buf, u16 len) 89static int flexcop_eeprom_read(struct flexcop_device *fc,
90 u16 addr, u8 *buf, u16 len)
98{ 91{
99 return fc->i2c_request(fc,FC_READ,FC_I2C_PORT_EEPROM,0x50,addr,buf,len); 92 return fc->i2c_request(fc,FC_READ,FC_I2C_PORT_EEPROM,0x50,addr,buf,len);
100} 93}
@@ -110,7 +103,8 @@ static u8 calc_lrc(u8 *buf, int len)
110 return sum; 103 return sum;
111} 104}
112 105
113static int flexcop_eeprom_request(struct flexcop_device *fc, flexcop_access_op_t op, u16 addr, u8 *buf, u16 len, int retries) 106static int flexcop_eeprom_request(struct flexcop_device *fc,
107 flexcop_access_op_t op, u16 addr, u8 *buf, u16 len, int retries)
114{ 108{
115 int i,ret = 0; 109 int i,ret = 0;
116 u8 chipaddr = 0x50 | ((addr >> 8) & 3); 110 u8 chipaddr = 0x50 | ((addr >> 8) & 3);
@@ -123,7 +117,8 @@ static int flexcop_eeprom_request(struct flexcop_device *fc, flexcop_access_op_t
123 return ret; 117 return ret;
124} 118}
125 119
126static int flexcop_eeprom_lrc_read(struct flexcop_device *fc, u16 addr, u8 *buf, u16 len, int retries) 120static int flexcop_eeprom_lrc_read(struct flexcop_device *fc, u16 addr,
121 u8 *buf, u16 len, int retries)
127{ 122{
128 int ret = flexcop_eeprom_request(fc, FC_READ, addr, buf, len, retries); 123 int ret = flexcop_eeprom_request(fc, FC_READ, addr, buf, len, retries);
129 if (ret == 0) 124 if (ret == 0)
@@ -133,8 +128,7 @@ static int flexcop_eeprom_lrc_read(struct flexcop_device *fc, u16 addr, u8 *buf,
133} 128}
134 129
135/* JJ's comment about extended == 1: it is not presently used anywhere but was 130/* JJ's comment about extended == 1: it is not presently used anywhere but was
136 * added to the low-level functions for possible support of EUI64 131 * added to the low-level functions for possible support of EUI64 */
137 */
138int flexcop_eeprom_check_mac_addr(struct flexcop_device *fc, int extended) 132int flexcop_eeprom_check_mac_addr(struct flexcop_device *fc, int extended)
139{ 133{
140 u8 buf[8]; 134 u8 buf[8];
@@ -142,12 +136,9 @@ int flexcop_eeprom_check_mac_addr(struct flexcop_device *fc, int extended)
142 136
143 if ((ret = flexcop_eeprom_lrc_read(fc,0x3f8,buf,8,4)) == 0) { 137 if ((ret = flexcop_eeprom_lrc_read(fc,0x3f8,buf,8,4)) == 0) {
144 if (extended != 0) { 138 if (extended != 0) {
145 err("TODO: extended (EUI64) MAC addresses aren't completely supported yet"); 139 err("TODO: extended (EUI64) MAC addresses aren't "
140 "completely supported yet");
146 ret = -EINVAL; 141 ret = -EINVAL;
147/* memcpy(fc->dvb_adapter.proposed_mac,buf,3);
148 mac[3] = 0xfe;
149 mac[4] = 0xff;
150 memcpy(&fc->dvb_adapter.proposed_mac[3],&buf[5],3); */
151 } else 142 } else
152 memcpy(fc->dvb_adapter.proposed_mac,buf,6); 143 memcpy(fc->dvb_adapter.proposed_mac,buf,6);
153 } 144 }
diff --git a/drivers/media/dvb/b2c2/flexcop-fe-tuner.c b/drivers/media/dvb/b2c2/flexcop-fe-tuner.c
index 5cded3708541..f7afab5944cf 100644
--- a/drivers/media/dvb/b2c2/flexcop-fe-tuner.c
+++ b/drivers/media/dvb/b2c2/flexcop-fe-tuner.c
@@ -592,14 +592,14 @@ int flexcop_frontend_init(struct flexcop_device *fc)
592 fc->fe_sleep = ops->sleep; 592 fc->fe_sleep = ops->sleep;
593 ops->sleep = flexcop_sleep; 593 ops->sleep = flexcop_sleep;
594 594
595 fc->dev_type = FC_SKY; 595 fc->dev_type = FC_SKY_REV26;
596 goto fe_found; 596 goto fe_found;
597 } 597 }
598 598
599 /* try the air dvb-t (mt352/Samsung tdtc9251dh0(??)) */ 599 /* try the air dvb-t (mt352/Samsung tdtc9251dh0(??)) */
600 fc->fe = dvb_attach(mt352_attach, &samsung_tdtc9251dh0_config, i2c); 600 fc->fe = dvb_attach(mt352_attach, &samsung_tdtc9251dh0_config, i2c);
601 if (fc->fe != NULL) { 601 if (fc->fe != NULL) {
602 fc->dev_type = FC_AIR_DVB; 602 fc->dev_type = FC_AIR_DVBT;
603 fc->fe->ops.tuner_ops.calc_regs = samsung_tdtc9251dh0_calc_regs; 603 fc->fe->ops.tuner_ops.calc_regs = samsung_tdtc9251dh0_calc_regs;
604 goto fe_found; 604 goto fe_found;
605 } 605 }
@@ -653,7 +653,7 @@ int flexcop_frontend_init(struct flexcop_device *fc)
653 fc->fe_sleep = ops->sleep; 653 fc->fe_sleep = ops->sleep;
654 ops->sleep = flexcop_sleep; 654 ops->sleep = flexcop_sleep;
655 655
656 fc->dev_type = FC_SKY_OLD; 656 fc->dev_type = FC_SKY_REV23;
657 goto fe_found; 657 goto fe_found;
658 } 658 }
659 659
diff --git a/drivers/media/dvb/b2c2/flexcop-hw-filter.c b/drivers/media/dvb/b2c2/flexcop-hw-filter.c
index 451974ba32f3..77e45475f4c7 100644
--- a/drivers/media/dvb/b2c2/flexcop-hw-filter.c
+++ b/drivers/media/dvb/b2c2/flexcop-hw-filter.c
@@ -1,33 +1,30 @@
1/* 1/*
2 * This file is part of linux driver the digital TV devices equipped with B2C2 FlexcopII(b)/III 2 * Linux driver for digital TV devices equipped with B2C2 FlexcopII(b)/III
3 * 3 * flexcop-hw-filter.c - pid and mac address filtering and control functions
4 * flexcop-hw-filter.c - pid and mac address filtering and corresponding control functions. 4 * see flexcop.c for copyright information
5 *
6 * see flexcop.c for copyright information.
7 */ 5 */
8#include "flexcop.h" 6#include "flexcop.h"
9 7
10static void flexcop_rcv_data_ctrl(struct flexcop_device *fc, int onoff) 8static void flexcop_rcv_data_ctrl(struct flexcop_device *fc, int onoff)
11{ 9{
12 flexcop_set_ibi_value(ctrl_208,Rcv_Data_sig,onoff); 10 flexcop_set_ibi_value(ctrl_208, Rcv_Data_sig, onoff);
13 11 deb_ts("rcv_data is now: '%s'\n", onoff ? "on" : "off");
14 deb_ts("rcv_data is now: '%s'\n",onoff ? "on" : "off");
15} 12}
16 13
17void flexcop_smc_ctrl(struct flexcop_device *fc, int onoff) 14void flexcop_smc_ctrl(struct flexcop_device *fc, int onoff)
18{ 15{
19 flexcop_set_ibi_value(ctrl_208,SMC_Enable_sig,onoff); 16 flexcop_set_ibi_value(ctrl_208, SMC_Enable_sig, onoff);
20} 17}
21 18
22static void flexcop_null_filter_ctrl(struct flexcop_device *fc, int onoff) 19static void flexcop_null_filter_ctrl(struct flexcop_device *fc, int onoff)
23{ 20{
24 flexcop_set_ibi_value(ctrl_208,Null_filter_sig,onoff); 21 flexcop_set_ibi_value(ctrl_208, Null_filter_sig, onoff);
25} 22}
26 23
27void flexcop_set_mac_filter(struct flexcop_device *fc, u8 mac[6]) 24void flexcop_set_mac_filter(struct flexcop_device *fc, u8 mac[6])
28{ 25{
29 flexcop_ibi_value v418,v41c; 26 flexcop_ibi_value v418, v41c;
30 v41c = fc->read_ibi_reg(fc,mac_address_41c); 27 v41c = fc->read_ibi_reg(fc, mac_address_41c);
31 28
32 v418.mac_address_418.MAC1 = mac[0]; 29 v418.mac_address_418.MAC1 = mac[0];
33 v418.mac_address_418.MAC2 = mac[1]; 30 v418.mac_address_418.MAC2 = mac[1];
@@ -36,27 +33,28 @@ void flexcop_set_mac_filter(struct flexcop_device *fc, u8 mac[6])
36 v41c.mac_address_41c.MAC7 = mac[4]; 33 v41c.mac_address_41c.MAC7 = mac[4];
37 v41c.mac_address_41c.MAC8 = mac[5]; 34 v41c.mac_address_41c.MAC8 = mac[5];
38 35
39 fc->write_ibi_reg(fc,mac_address_418,v418); 36 fc->write_ibi_reg(fc, mac_address_418, v418);
40 fc->write_ibi_reg(fc,mac_address_41c,v41c); 37 fc->write_ibi_reg(fc, mac_address_41c, v41c);
41} 38}
42 39
43void flexcop_mac_filter_ctrl(struct flexcop_device *fc, int onoff) 40void flexcop_mac_filter_ctrl(struct flexcop_device *fc, int onoff)
44{ 41{
45 flexcop_set_ibi_value(ctrl_208,MAC_filter_Mode_sig,onoff); 42 flexcop_set_ibi_value(ctrl_208, MAC_filter_Mode_sig, onoff);
46} 43}
47 44
48static void flexcop_pid_group_filter(struct flexcop_device *fc, u16 pid, u16 mask) 45static void flexcop_pid_group_filter(struct flexcop_device *fc,
46 u16 pid, u16 mask)
49{ 47{
50 /* index_reg_310.extra_index_reg need to 0 or 7 to work */ 48 /* index_reg_310.extra_index_reg need to 0 or 7 to work */
51 flexcop_ibi_value v30c; 49 flexcop_ibi_value v30c;
52 v30c.pid_filter_30c_ext_ind_0_7.Group_PID = pid; 50 v30c.pid_filter_30c_ext_ind_0_7.Group_PID = pid;
53 v30c.pid_filter_30c_ext_ind_0_7.Group_mask = mask; 51 v30c.pid_filter_30c_ext_ind_0_7.Group_mask = mask;
54 fc->write_ibi_reg(fc,pid_filter_30c,v30c); 52 fc->write_ibi_reg(fc, pid_filter_30c, v30c);
55} 53}
56 54
57static void flexcop_pid_group_filter_ctrl(struct flexcop_device *fc, int onoff) 55static void flexcop_pid_group_filter_ctrl(struct flexcop_device *fc, int onoff)
58{ 56{
59 flexcop_set_ibi_value(ctrl_208,Mask_filter_sig,onoff); 57 flexcop_set_ibi_value(ctrl_208, Mask_filter_sig, onoff);
60} 58}
61 59
62/* this fancy define reduces the code size of the quite similar PID controlling of 60/* this fancy define reduces the code size of the quite similar PID controlling of
@@ -65,91 +63,112 @@ static void flexcop_pid_group_filter_ctrl(struct flexcop_device *fc, int onoff)
65 63
66#define pid_ctrl(vregname,field,enablefield,trans_field,transval) \ 64#define pid_ctrl(vregname,field,enablefield,trans_field,transval) \
67 flexcop_ibi_value vpid = fc->read_ibi_reg(fc, vregname), \ 65 flexcop_ibi_value vpid = fc->read_ibi_reg(fc, vregname), \
68 v208 = fc->read_ibi_reg(fc, ctrl_208); \ 66v208 = fc->read_ibi_reg(fc, ctrl_208); \
69\ 67vpid.vregname.field = onoff ? pid : 0x1fff; \
70 vpid.vregname.field = onoff ? pid : 0x1fff; \ 68vpid.vregname.trans_field = transval; \
71 vpid.vregname.trans_field = transval; \ 69v208.ctrl_208.enablefield = onoff; \
72 v208.ctrl_208.enablefield = onoff; \ 70fc->write_ibi_reg(fc, vregname, vpid); \
73\ 71fc->write_ibi_reg(fc, ctrl_208, v208);
74 fc->write_ibi_reg(fc,vregname,vpid); \
75 fc->write_ibi_reg(fc,ctrl_208,v208);
76 72
77static void flexcop_pid_Stream1_PID_ctrl(struct flexcop_device *fc, u16 pid, int onoff) 73static void flexcop_pid_Stream1_PID_ctrl(struct flexcop_device *fc,
74 u16 pid, int onoff)
78{ 75{
79 pid_ctrl(pid_filter_300,Stream1_PID,Stream1_filter_sig,Stream1_trans,0); 76 pid_ctrl(pid_filter_300, Stream1_PID, Stream1_filter_sig,
77 Stream1_trans, 0);
80} 78}
81 79
82static void flexcop_pid_Stream2_PID_ctrl(struct flexcop_device *fc, u16 pid, int onoff) 80static void flexcop_pid_Stream2_PID_ctrl(struct flexcop_device *fc,
81 u16 pid, int onoff)
83{ 82{
84 pid_ctrl(pid_filter_300,Stream2_PID,Stream2_filter_sig,Stream2_trans,0); 83 pid_ctrl(pid_filter_300, Stream2_PID, Stream2_filter_sig,
84 Stream2_trans, 0);
85} 85}
86 86
87static void flexcop_pid_PCR_PID_ctrl(struct flexcop_device *fc, u16 pid, int onoff) 87static void flexcop_pid_PCR_PID_ctrl(struct flexcop_device *fc,
88 u16 pid, int onoff)
88{ 89{
89 pid_ctrl(pid_filter_304,PCR_PID,PCR_filter_sig,PCR_trans,0); 90 pid_ctrl(pid_filter_304, PCR_PID, PCR_filter_sig, PCR_trans, 0);
90} 91}
91 92
92static void flexcop_pid_PMT_PID_ctrl(struct flexcop_device *fc, u16 pid, int onoff) 93static void flexcop_pid_PMT_PID_ctrl(struct flexcop_device *fc,
94 u16 pid, int onoff)
93{ 95{
94 pid_ctrl(pid_filter_304,PMT_PID,PMT_filter_sig,PMT_trans,0); 96 pid_ctrl(pid_filter_304, PMT_PID, PMT_filter_sig, PMT_trans, 0);
95} 97}
96 98
97static void flexcop_pid_EMM_PID_ctrl(struct flexcop_device *fc, u16 pid, int onoff) 99static void flexcop_pid_EMM_PID_ctrl(struct flexcop_device *fc,
100 u16 pid, int onoff)
98{ 101{
99 pid_ctrl(pid_filter_308,EMM_PID,EMM_filter_sig,EMM_trans,0); 102 pid_ctrl(pid_filter_308, EMM_PID, EMM_filter_sig, EMM_trans, 0);
100} 103}
101 104
102static void flexcop_pid_ECM_PID_ctrl(struct flexcop_device *fc, u16 pid, int onoff) 105static void flexcop_pid_ECM_PID_ctrl(struct flexcop_device *fc,
106 u16 pid, int onoff)
103{ 107{
104 pid_ctrl(pid_filter_308,ECM_PID,ECM_filter_sig,ECM_trans,0); 108 pid_ctrl(pid_filter_308, ECM_PID, ECM_filter_sig, ECM_trans, 0);
105} 109}
106 110
107static void flexcop_pid_control(struct flexcop_device *fc, int index, u16 pid,int onoff) 111static void flexcop_pid_control(struct flexcop_device *fc,
112 int index, u16 pid, int onoff)
108{ 113{
109 if (pid == 0x2000) 114 if (pid == 0x2000)
110 return; 115 return;
111 116
112 deb_ts("setting pid: %5d %04x at index %d '%s'\n",pid,pid,index,onoff ? "on" : "off"); 117 deb_ts("setting pid: %5d %04x at index %d '%s'\n",
118 pid, pid, index, onoff ? "on" : "off");
113 119
114 /* We could use bit magic here to reduce source code size. 120 /* We could use bit magic here to reduce source code size.
115 * I decided against it, but to use the real register names */ 121 * I decided against it, but to use the real register names */
116 switch (index) { 122 switch (index) {
117 case 0: flexcop_pid_Stream1_PID_ctrl(fc,pid,onoff); break; 123 case 0:
118 case 1: flexcop_pid_Stream2_PID_ctrl(fc,pid,onoff); break; 124 flexcop_pid_Stream1_PID_ctrl(fc, pid, onoff);
119 case 2: flexcop_pid_PCR_PID_ctrl(fc,pid,onoff); break; 125 break;
120 case 3: flexcop_pid_PMT_PID_ctrl(fc,pid,onoff); break; 126 case 1:
121 case 4: flexcop_pid_EMM_PID_ctrl(fc,pid,onoff); break; 127 flexcop_pid_Stream2_PID_ctrl(fc, pid, onoff);
122 case 5: flexcop_pid_ECM_PID_ctrl(fc,pid,onoff); break; 128 break;
123 default: 129 case 2:
124 if (fc->has_32_hw_pid_filter && index < 38) { 130 flexcop_pid_PCR_PID_ctrl(fc, pid, onoff);
125 flexcop_ibi_value vpid,vid; 131 break;
126 132 case 3:
127 /* set the index */ 133 flexcop_pid_PMT_PID_ctrl(fc, pid, onoff);
128 vid = fc->read_ibi_reg(fc,index_reg_310); 134 break;
129 vid.index_reg_310.index_reg = index - 6; 135 case 4:
130 fc->write_ibi_reg(fc,index_reg_310, vid); 136 flexcop_pid_EMM_PID_ctrl(fc, pid, onoff);
131 137 break;
132 vpid = fc->read_ibi_reg(fc,pid_n_reg_314); 138 case 5:
133 vpid.pid_n_reg_314.PID = onoff ? pid : 0x1fff; 139 flexcop_pid_ECM_PID_ctrl(fc, pid, onoff);
134 vpid.pid_n_reg_314.PID_enable_bit = onoff; 140 break;
135 fc->write_ibi_reg(fc,pid_n_reg_314, vpid); 141 default:
136 } 142 if (fc->has_32_hw_pid_filter && index < 38) {
137 break; 143 flexcop_ibi_value vpid, vid;
144
145 /* set the index */
146 vid = fc->read_ibi_reg(fc, index_reg_310);
147 vid.index_reg_310.index_reg = index - 6;
148 fc->write_ibi_reg(fc, index_reg_310, vid);
149
150 vpid = fc->read_ibi_reg(fc, pid_n_reg_314);
151 vpid.pid_n_reg_314.PID = onoff ? pid : 0x1fff;
152 vpid.pid_n_reg_314.PID_enable_bit = onoff;
153 fc->write_ibi_reg(fc, pid_n_reg_314, vpid);
154 }
155 break;
138 } 156 }
139} 157}
140 158
141static int flexcop_toggle_fullts_streaming(struct flexcop_device *fc,int onoff) 159static int flexcop_toggle_fullts_streaming(struct flexcop_device *fc, int onoff)
142{ 160{
143 if (fc->fullts_streaming_state != onoff) { 161 if (fc->fullts_streaming_state != onoff) {
144 deb_ts("%s full TS transfer\n",onoff ? "enabling" : "disabling"); 162 deb_ts("%s full TS transfer\n",onoff ? "enabling" : "disabling");
145 flexcop_pid_group_filter(fc, 0, 0x1fe0 * (!onoff)); 163 flexcop_pid_group_filter(fc, 0, 0x1fe0 * (!onoff));
146 flexcop_pid_group_filter_ctrl(fc,onoff); 164 flexcop_pid_group_filter_ctrl(fc, onoff);
147 fc->fullts_streaming_state = onoff; 165 fc->fullts_streaming_state = onoff;
148 } 166 }
149 return 0; 167 return 0;
150} 168}
151 169
152int flexcop_pid_feed_control(struct flexcop_device *fc, struct dvb_demux_feed *dvbdmxfeed, int onoff) 170int flexcop_pid_feed_control(struct flexcop_device *fc,
171 struct dvb_demux_feed *dvbdmxfeed, int onoff)
153{ 172{
154 int max_pid_filter = 6 + fc->has_32_hw_pid_filter*32; 173 int max_pid_filter = 6 + fc->has_32_hw_pid_filter*32;
155 174
@@ -164,24 +183,25 @@ int flexcop_pid_feed_control(struct flexcop_device *fc, struct dvb_demux_feed *d
164 * - or the requested pid is 0x2000 */ 183 * - or the requested pid is 0x2000 */
165 184
166 if (!fc->pid_filtering && fc->feedcount == onoff) 185 if (!fc->pid_filtering && fc->feedcount == onoff)
167 flexcop_toggle_fullts_streaming(fc,onoff); 186 flexcop_toggle_fullts_streaming(fc, onoff);
168 187
169 if (fc->pid_filtering) { 188 if (fc->pid_filtering) {
170 flexcop_pid_control(fc,dvbdmxfeed->index,dvbdmxfeed->pid,onoff); 189 flexcop_pid_control \
190 (fc, dvbdmxfeed->index, dvbdmxfeed->pid, onoff);
171 191
172 if (fc->extra_feedcount > 0) 192 if (fc->extra_feedcount > 0)
173 flexcop_toggle_fullts_streaming(fc,1); 193 flexcop_toggle_fullts_streaming(fc, 1);
174 else if (dvbdmxfeed->pid == 0x2000) 194 else if (dvbdmxfeed->pid == 0x2000)
175 flexcop_toggle_fullts_streaming(fc,onoff); 195 flexcop_toggle_fullts_streaming(fc, onoff);
176 else 196 else
177 flexcop_toggle_fullts_streaming(fc,0); 197 flexcop_toggle_fullts_streaming(fc, 0);
178 } 198 }
179 199
180 /* if it was the first or last feed request change the stream-status */ 200 /* if it was the first or last feed request change the stream-status */
181 if (fc->feedcount == onoff) { 201 if (fc->feedcount == onoff) {
182 flexcop_rcv_data_ctrl(fc,onoff); 202 flexcop_rcv_data_ctrl(fc, onoff);
183 if (fc->stream_control) /* device specific stream control */ 203 if (fc->stream_control) /* device specific stream control */
184 fc->stream_control(fc,onoff); 204 fc->stream_control(fc, onoff);
185 205
186 /* feeding stopped -> reset the flexcop filter*/ 206 /* feeding stopped -> reset the flexcop filter*/
187 if (onoff == 0) { 207 if (onoff == 0) {
@@ -189,7 +209,6 @@ int flexcop_pid_feed_control(struct flexcop_device *fc, struct dvb_demux_feed *d
189 flexcop_hw_filter_init(fc); 209 flexcop_hw_filter_init(fc);
190 } 210 }
191 } 211 }
192
193 return 0; 212 return 0;
194} 213}
195EXPORT_SYMBOL(flexcop_pid_feed_control); 214EXPORT_SYMBOL(flexcop_pid_feed_control);
@@ -199,15 +218,15 @@ void flexcop_hw_filter_init(struct flexcop_device *fc)
199 int i; 218 int i;
200 flexcop_ibi_value v; 219 flexcop_ibi_value v;
201 for (i = 0; i < 6 + 32*fc->has_32_hw_pid_filter; i++) 220 for (i = 0; i < 6 + 32*fc->has_32_hw_pid_filter; i++)
202 flexcop_pid_control(fc,i,0x1fff,0); 221 flexcop_pid_control(fc, i, 0x1fff, 0);
203 222
204 flexcop_pid_group_filter(fc, 0, 0x1fe0); 223 flexcop_pid_group_filter(fc, 0, 0x1fe0);
205 flexcop_pid_group_filter_ctrl(fc,0); 224 flexcop_pid_group_filter_ctrl(fc, 0);
206 225
207 v = fc->read_ibi_reg(fc,pid_filter_308); 226 v = fc->read_ibi_reg(fc, pid_filter_308);
208 v.pid_filter_308.EMM_filter_4 = 1; 227 v.pid_filter_308.EMM_filter_4 = 1;
209 v.pid_filter_308.EMM_filter_6 = 0; 228 v.pid_filter_308.EMM_filter_6 = 0;
210 fc->write_ibi_reg(fc,pid_filter_308,v); 229 fc->write_ibi_reg(fc, pid_filter_308, v);
211 230
212 flexcop_null_filter_ctrl(fc, 1); 231 flexcop_null_filter_ctrl(fc, 1);
213} 232}
diff --git a/drivers/media/dvb/b2c2/flexcop-i2c.c b/drivers/media/dvb/b2c2/flexcop-i2c.c
index f13783f08f0f..e2bed5076485 100644
--- a/drivers/media/dvb/b2c2/flexcop-i2c.c
+++ b/drivers/media/dvb/b2c2/flexcop-i2c.c
@@ -1,17 +1,14 @@
1/* 1/*
2 * This file is part of linux driver the digital TV devices equipped with B2C2 FlexcopII(b)/III 2 * Linux driver for digital TV devices equipped with B2C2 FlexcopII(b)/III
3 *
4 * flexcop-i2c.c - flexcop internal 2Wire bus (I2C) and dvb i2c initialization 3 * flexcop-i2c.c - flexcop internal 2Wire bus (I2C) and dvb i2c initialization
5 * 4 * see flexcop.c for copyright information
6 * see flexcop.c for copyright information.
7 */ 5 */
8#include "flexcop.h" 6#include "flexcop.h"
9 7
10#define FC_MAX_I2C_RETRIES 100000 8#define FC_MAX_I2C_RETRIES 100000
11 9
12/* #define DUMP_I2C_MESSAGES */ 10static int flexcop_i2c_operation(struct flexcop_device *fc,
13 11 flexcop_ibi_value *r100)
14static int flexcop_i2c_operation(struct flexcop_device *fc, flexcop_ibi_value *r100)
15{ 12{
16 int i; 13 int i;
17 flexcop_ibi_value r; 14 flexcop_ibi_value r;
@@ -26,7 +23,7 @@ static int flexcop_i2c_operation(struct flexcop_device *fc, flexcop_ibi_value *r
26 r = fc->read_ibi_reg(fc, tw_sm_c_100); 23 r = fc->read_ibi_reg(fc, tw_sm_c_100);
27 24
28 if (!r.tw_sm_c_100.no_base_addr_ack_error) { 25 if (!r.tw_sm_c_100.no_base_addr_ack_error) {
29 if (r.tw_sm_c_100.st_done) { /* && !r.tw_sm_c_100.working_start */ 26 if (r.tw_sm_c_100.st_done) {
30 *r100 = r; 27 *r100 = r;
31 deb_i2c("i2c success\n"); 28 deb_i2c("i2c success\n");
32 return 0; 29 return 0;
@@ -36,17 +33,31 @@ static int flexcop_i2c_operation(struct flexcop_device *fc, flexcop_ibi_value *r
36 return -EREMOTEIO; 33 return -EREMOTEIO;
37 } 34 }
38 } 35 }
39 deb_i2c("tried %d times i2c operation, never finished or too many ack errors.\n",i); 36 deb_i2c("tried %d times i2c operation, "
37 "never finished or too many ack errors.\n", i);
40 return -EREMOTEIO; 38 return -EREMOTEIO;
41} 39}
42 40
43static int flexcop_i2c_read4(struct flexcop_i2c_adapter *i2c, 41static int flexcop_i2c_read4(struct flexcop_i2c_adapter *i2c,
44 flexcop_ibi_value r100, u8 *buf) 42 flexcop_ibi_value r100, u8 *buf)
45{ 43{
46 flexcop_ibi_value r104; 44 flexcop_ibi_value r104;
47 int len = r100.tw_sm_c_100.total_bytes, /* remember total_bytes is buflen-1 */ 45 int len = r100.tw_sm_c_100.total_bytes,
46 /* remember total_bytes is buflen-1 */
48 ret; 47 ret;
49 48
49 /* work-around to have CableStar2 and SkyStar2 rev 2.7 work
50 * correctly:
51 *
52 * the ITD1000 is behind an i2c-gate which closes automatically
53 * after an i2c-transaction the STV0297 needs 2 consecutive reads
54 * one with no_base_addr = 0 and one with 1
55 *
56 * those two work-arounds are conflictin: we check for the card
57 * type, it is set when probing the ITD1000 */
58 if (i2c->fc->dev_type == FC_SKY_REV27)
59 r100.tw_sm_c_100.no_base_addr_ack_error = i2c->no_base_addr;
60
50 ret = flexcop_i2c_operation(i2c->fc, &r100); 61 ret = flexcop_i2c_operation(i2c->fc, &r100);
51 if (ret != 0) { 62 if (ret != 0) {
52 deb_i2c("Retrying operation\n"); 63 deb_i2c("Retrying operation\n");
@@ -69,11 +80,11 @@ static int flexcop_i2c_read4(struct flexcop_i2c_adapter *i2c,
69 if (len > 1) buf[2] = r104.tw_sm_c_104.data3_reg; 80 if (len > 1) buf[2] = r104.tw_sm_c_104.data3_reg;
70 if (len > 2) buf[3] = r104.tw_sm_c_104.data4_reg; 81 if (len > 2) buf[3] = r104.tw_sm_c_104.data4_reg;
71 } 82 }
72
73 return 0; 83 return 0;
74} 84}
75 85
76static int flexcop_i2c_write4(struct flexcop_device *fc, flexcop_ibi_value r100, u8 *buf) 86static int flexcop_i2c_write4(struct flexcop_device *fc,
87 flexcop_ibi_value r100, u8 *buf)
77{ 88{
78 flexcop_ibi_value r104; 89 flexcop_ibi_value r104;
79 int len = r100.tw_sm_c_100.total_bytes; /* remember total_bytes is buflen-1 */ 90 int len = r100.tw_sm_c_100.total_bytes; /* remember total_bytes is buflen-1 */
@@ -81,7 +92,6 @@ static int flexcop_i2c_write4(struct flexcop_device *fc, flexcop_ibi_value r100,
81 92
82 /* there is at least one byte, otherwise we wouldn't be here */ 93 /* there is at least one byte, otherwise we wouldn't be here */
83 r100.tw_sm_c_100.data1_reg = buf[0]; 94 r100.tw_sm_c_100.data1_reg = buf[0];
84
85 r104.tw_sm_c_104.data2_reg = len > 0 ? buf[1] : 0; 95 r104.tw_sm_c_104.data2_reg = len > 0 ? buf[1] : 0;
86 r104.tw_sm_c_104.data3_reg = len > 1 ? buf[2] : 0; 96 r104.tw_sm_c_104.data3_reg = len > 1 ? buf[2] : 0;
87 r104.tw_sm_c_104.data4_reg = len > 2 ? buf[3] : 0; 97 r104.tw_sm_c_104.data4_reg = len > 2 ? buf[3] : 0;
@@ -94,7 +104,7 @@ static int flexcop_i2c_write4(struct flexcop_device *fc, flexcop_ibi_value r100,
94} 104}
95 105
96int flexcop_i2c_request(struct flexcop_i2c_adapter *i2c, 106int flexcop_i2c_request(struct flexcop_i2c_adapter *i2c,
97 flexcop_access_op_t op, u8 chipaddr, u8 addr, u8 *buf, u16 len) 107 flexcop_access_op_t op, u8 chipaddr, u8 addr, u8 *buf, u16 len)
98{ 108{
99 int ret; 109 int ret;
100 110
@@ -117,7 +127,6 @@ int flexcop_i2c_request(struct flexcop_i2c_adapter *i2c,
117 printk("rd("); 127 printk("rd(");
118 else 128 else
119 printk("wr("); 129 printk("wr(");
120
121 printk("%02x): %02x ", chipaddr, addr); 130 printk("%02x): %02x ", chipaddr, addr);
122#endif 131#endif
123 132
@@ -163,7 +172,8 @@ int flexcop_i2c_request(struct flexcop_i2c_adapter *i2c,
163EXPORT_SYMBOL(flexcop_i2c_request); 172EXPORT_SYMBOL(flexcop_i2c_request);
164 173
165/* master xfer callback for demodulator */ 174/* master xfer callback for demodulator */
166static int flexcop_master_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg msgs[], int num) 175static int flexcop_master_xfer(struct i2c_adapter *i2c_adap,
176 struct i2c_msg msgs[], int num)
167{ 177{
168 struct flexcop_i2c_adapter *i2c = i2c_get_adapdata(i2c_adap); 178 struct flexcop_i2c_adapter *i2c = i2c_get_adapdata(i2c_adap);
169 int i, ret = 0; 179 int i, ret = 0;
@@ -182,12 +192,13 @@ static int flexcop_master_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg msgs
182 /* reading */ 192 /* reading */
183 if (i+1 < num && (msgs[i+1].flags == I2C_M_RD)) { 193 if (i+1 < num && (msgs[i+1].flags == I2C_M_RD)) {
184 ret = i2c->fc->i2c_request(i2c, FC_READ, msgs[i].addr, 194 ret = i2c->fc->i2c_request(i2c, FC_READ, msgs[i].addr,
185 msgs[i].buf[0], msgs[i+1].buf, msgs[i+1].len); 195 msgs[i].buf[0], msgs[i+1].buf,
196 msgs[i+1].len);
186 i++; /* skip the following message */ 197 i++; /* skip the following message */
187 } else /* writing */ 198 } else /* writing */
188 ret = i2c->fc->i2c_request(i2c, FC_WRITE, msgs[i].addr, 199 ret = i2c->fc->i2c_request(i2c, FC_WRITE, msgs[i].addr,
189 msgs[i].buf[0], &msgs[i].buf[1], 200 msgs[i].buf[0], &msgs[i].buf[1],
190 msgs[i].len - 1); 201 msgs[i].len - 1);
191 if (ret < 0) { 202 if (ret < 0) {
192 err("i2c master_xfer failed"); 203 err("i2c master_xfer failed");
193 break; 204 break;
@@ -214,23 +225,21 @@ static struct i2c_algorithm flexcop_algo = {
214int flexcop_i2c_init(struct flexcop_device *fc) 225int flexcop_i2c_init(struct flexcop_device *fc)
215{ 226{
216 int ret; 227 int ret;
217
218 mutex_init(&fc->i2c_mutex); 228 mutex_init(&fc->i2c_mutex);
219 229
220 fc->fc_i2c_adap[0].fc = fc; 230 fc->fc_i2c_adap[0].fc = fc;
221 fc->fc_i2c_adap[1].fc = fc; 231 fc->fc_i2c_adap[1].fc = fc;
222 fc->fc_i2c_adap[2].fc = fc; 232 fc->fc_i2c_adap[2].fc = fc;
223
224 fc->fc_i2c_adap[0].port = FC_I2C_PORT_DEMOD; 233 fc->fc_i2c_adap[0].port = FC_I2C_PORT_DEMOD;
225 fc->fc_i2c_adap[1].port = FC_I2C_PORT_EEPROM; 234 fc->fc_i2c_adap[1].port = FC_I2C_PORT_EEPROM;
226 fc->fc_i2c_adap[2].port = FC_I2C_PORT_TUNER; 235 fc->fc_i2c_adap[2].port = FC_I2C_PORT_TUNER;
227 236
228 strlcpy(fc->fc_i2c_adap[0].i2c_adap.name, "B2C2 FlexCop I2C to demod", 237 strlcpy(fc->fc_i2c_adap[0].i2c_adap.name, "B2C2 FlexCop I2C to demod",
229 sizeof(fc->fc_i2c_adap[0].i2c_adap.name)); 238 sizeof(fc->fc_i2c_adap[0].i2c_adap.name));
230 strlcpy(fc->fc_i2c_adap[1].i2c_adap.name, "B2C2 FlexCop I2C to eeprom", 239 strlcpy(fc->fc_i2c_adap[1].i2c_adap.name, "B2C2 FlexCop I2C to eeprom",
231 sizeof(fc->fc_i2c_adap[1].i2c_adap.name)); 240 sizeof(fc->fc_i2c_adap[1].i2c_adap.name));
232 strlcpy(fc->fc_i2c_adap[2].i2c_adap.name, "B2C2 FlexCop I2C to tuner", 241 strlcpy(fc->fc_i2c_adap[2].i2c_adap.name, "B2C2 FlexCop I2C to tuner",
233 sizeof(fc->fc_i2c_adap[2].i2c_adap.name)); 242 sizeof(fc->fc_i2c_adap[2].i2c_adap.name));
234 243
235 i2c_set_adapdata(&fc->fc_i2c_adap[0].i2c_adap, &fc->fc_i2c_adap[0]); 244 i2c_set_adapdata(&fc->fc_i2c_adap[0].i2c_adap, &fc->fc_i2c_adap[0]);
236 i2c_set_adapdata(&fc->fc_i2c_adap[1].i2c_adap, &fc->fc_i2c_adap[1]); 245 i2c_set_adapdata(&fc->fc_i2c_adap[1].i2c_adap, &fc->fc_i2c_adap[1]);
@@ -268,7 +277,6 @@ adap_2_failed:
268 i2c_del_adapter(&fc->fc_i2c_adap[1].i2c_adap); 277 i2c_del_adapter(&fc->fc_i2c_adap[1].i2c_adap);
269adap_1_failed: 278adap_1_failed:
270 i2c_del_adapter(&fc->fc_i2c_adap[0].i2c_adap); 279 i2c_del_adapter(&fc->fc_i2c_adap[0].i2c_adap);
271
272 return ret; 280 return ret;
273} 281}
274 282
@@ -279,6 +287,5 @@ void flexcop_i2c_exit(struct flexcop_device *fc)
279 i2c_del_adapter(&fc->fc_i2c_adap[1].i2c_adap); 287 i2c_del_adapter(&fc->fc_i2c_adap[1].i2c_adap);
280 i2c_del_adapter(&fc->fc_i2c_adap[0].i2c_adap); 288 i2c_del_adapter(&fc->fc_i2c_adap[0].i2c_adap);
281 } 289 }
282
283 fc->init_state &= ~FC_STATE_I2C_INIT; 290 fc->init_state &= ~FC_STATE_I2C_INIT;
284} 291}
diff --git a/drivers/media/dvb/b2c2/flexcop-misc.c b/drivers/media/dvb/b2c2/flexcop-misc.c
index 93d20e56f909..e56627d2f0f4 100644
--- a/drivers/media/dvb/b2c2/flexcop-misc.c
+++ b/drivers/media/dvb/b2c2/flexcop-misc.c
@@ -1,9 +1,7 @@
1/* 1/*
2 * This file is part of linux driver the digital TV devices equipped with B2C2 FlexcopII(b)/III 2 * Linux driver for digital TV devices equipped with B2C2 FlexcopII(b)/III
3 * 3 * flexcop-misc.c - miscellaneous functions
4 * flexcop-misc.c - miscellaneous functions. 4 * see flexcop.c for copyright information
5 *
6 * see flexcop.c for copyright information.
7 */ 5 */
8#include "flexcop.h" 6#include "flexcop.h"
9 7
@@ -12,39 +10,43 @@ void flexcop_determine_revision(struct flexcop_device *fc)
12 flexcop_ibi_value v = fc->read_ibi_reg(fc,misc_204); 10 flexcop_ibi_value v = fc->read_ibi_reg(fc,misc_204);
13 11
14 switch (v.misc_204.Rev_N_sig_revision_hi) { 12 switch (v.misc_204.Rev_N_sig_revision_hi) {
15 case 0x2: 13 case 0x2:
16 deb_info("found a FlexCopII.\n"); 14 deb_info("found a FlexCopII.\n");
17 fc->rev = FLEXCOP_II; 15 fc->rev = FLEXCOP_II;
18 break; 16 break;
19 case 0x3: 17 case 0x3:
20 deb_info("found a FlexCopIIb.\n"); 18 deb_info("found a FlexCopIIb.\n");
21 fc->rev = FLEXCOP_IIB; 19 fc->rev = FLEXCOP_IIB;
22 break; 20 break;
23 case 0x0: 21 case 0x0:
24 deb_info("found a FlexCopIII.\n"); 22 deb_info("found a FlexCopIII.\n");
25 fc->rev = FLEXCOP_III; 23 fc->rev = FLEXCOP_III;
26 break; 24 break;
27 default: 25 default:
28 err("unkown FlexCop Revision: %x. Please report the linux-dvb@linuxtv.org.",v.misc_204.Rev_N_sig_revision_hi); 26 err("unknown FlexCop Revision: %x. Please report this to "
29 break; 27 "linux-dvb@linuxtv.org.",
28 v.misc_204.Rev_N_sig_revision_hi);
29 break;
30 } 30 }
31 31
32 if ((fc->has_32_hw_pid_filter = v.misc_204.Rev_N_sig_caps)) 32 if ((fc->has_32_hw_pid_filter = v.misc_204.Rev_N_sig_caps))
33 deb_info("this FlexCop has the additional 32 hardware pid filter.\n"); 33 deb_info("this FlexCop has "
34 "the additional 32 hardware pid filter.\n");
34 else 35 else
35 deb_info("this FlexCop has only the 6 basic main hardware pid filter.\n"); 36 deb_info("this FlexCop has "
37 "the 6 basic main hardware pid filter.\n");
36 /* bus parts have to decide if hw pid filtering is used or not. */ 38 /* bus parts have to decide if hw pid filtering is used or not. */
37} 39}
38 40
39static const char *flexcop_revision_names[] = { 41static const char *flexcop_revision_names[] = {
40 "Unkown chip", 42 "Unknown chip",
41 "FlexCopII", 43 "FlexCopII",
42 "FlexCopIIb", 44 "FlexCopIIb",
43 "FlexCopIII", 45 "FlexCopIII",
44}; 46};
45 47
46static const char *flexcop_device_names[] = { 48static const char *flexcop_device_names[] = {
47 "Unkown device", 49 "Unknown device",
48 "Air2PC/AirStar 2 DVB-T", 50 "Air2PC/AirStar 2 DVB-T",
49 "Air2PC/AirStar 2 ATSC 1st generation", 51 "Air2PC/AirStar 2 ATSC 1st generation",
50 "Air2PC/AirStar 2 ATSC 2nd generation", 52 "Air2PC/AirStar 2 ATSC 2nd generation",
@@ -61,21 +63,23 @@ static const char *flexcop_bus_names[] = {
61 "PCI", 63 "PCI",
62}; 64};
63 65
64void flexcop_device_name(struct flexcop_device *fc,const char *prefix,const 66void flexcop_device_name(struct flexcop_device *fc,
65 char *suffix) 67 const char *prefix, const char *suffix)
66{ 68{
67 info("%s '%s' at the '%s' bus controlled by a '%s' %s",prefix, 69 info("%s '%s' at the '%s' bus controlled by a '%s' %s",
68 flexcop_device_names[fc->dev_type],flexcop_bus_names[fc->bus_type], 70 prefix, flexcop_device_names[fc->dev_type],
69 flexcop_revision_names[fc->rev],suffix); 71 flexcop_bus_names[fc->bus_type],
72 flexcop_revision_names[fc->rev], suffix);
70} 73}
71 74
72void flexcop_dump_reg(struct flexcop_device *fc, flexcop_ibi_register reg, int num) 75void flexcop_dump_reg(struct flexcop_device *fc,
76 flexcop_ibi_register reg, int num)
73{ 77{
74 flexcop_ibi_value v; 78 flexcop_ibi_value v;
75 int i; 79 int i;
76 for (i = 0; i < num; i++) { 80 for (i = 0; i < num; i++) {
77 v = fc->read_ibi_reg(fc,reg+4*i); 81 v = fc->read_ibi_reg(fc, reg+4*i);
78 deb_rdump("0x%03x: %08x, ",reg+4*i, v.raw); 82 deb_rdump("0x%03x: %08x, ", reg+4*i, v.raw);
79 } 83 }
80 deb_rdump("\n"); 84 deb_rdump("\n");
81} 85}
diff --git a/drivers/media/dvb/b2c2/flexcop-pci.c b/drivers/media/dvb/b2c2/flexcop-pci.c
index 76e37fd96bb6..227c0200b70a 100644
--- a/drivers/media/dvb/b2c2/flexcop-pci.c
+++ b/drivers/media/dvb/b2c2/flexcop-pci.c
@@ -1,9 +1,7 @@
1/* 1/*
2 * This file is part of linux driver the digital TV devices equipped with B2C2 FlexcopII(b)/III 2 * Linux driver the digital TV devices equipped with B2C2 FlexcopII(b)/III
3 * 3 * flexcop-pci.c - covers the PCI part including DMA transfers
4 * flexcop-pci.c - covers the PCI part including DMA transfers. 4 * see flexcop.c for copyright information
5 *
6 * see flexcop.c for copyright information.
7 */ 5 */
8 6
9#define FC_LOG_PREFIX "flexcop-pci" 7#define FC_LOG_PREFIX "flexcop-pci"
@@ -11,7 +9,8 @@
11 9
12static int enable_pid_filtering = 1; 10static int enable_pid_filtering = 1;
13module_param(enable_pid_filtering, int, 0444); 11module_param(enable_pid_filtering, int, 0444);
14MODULE_PARM_DESC(enable_pid_filtering, "enable hardware pid filtering: supported values: 0 (fullts), 1"); 12MODULE_PARM_DESC(enable_pid_filtering,
13 "enable hardware pid filtering: supported values: 0 (fullts), 1");
15 14
16static int irq_chk_intv = 100; 15static int irq_chk_intv = 100;
17module_param(irq_chk_intv, int, 0644); 16module_param(irq_chk_intv, int, 0644);
@@ -26,17 +25,17 @@ MODULE_PARM_DESC(irq_chk_intv, "set the interval for IRQ streaming watchdog.");
26#define DEBSTATUS " (debugging is not enabled)" 25#define DEBSTATUS " (debugging is not enabled)"
27#endif 26#endif
28 27
29#define deb_info(args...) dprintk(0x01,args) 28#define deb_info(args...) dprintk(0x01, args)
30#define deb_reg(args...) dprintk(0x02,args) 29#define deb_reg(args...) dprintk(0x02, args)
31#define deb_ts(args...) dprintk(0x04,args) 30#define deb_ts(args...) dprintk(0x04, args)
32#define deb_irq(args...) dprintk(0x08,args) 31#define deb_irq(args...) dprintk(0x08, args)
33#define deb_chk(args...) dprintk(0x10,args) 32#define deb_chk(args...) dprintk(0x10, args)
34 33
35static int debug; 34static int debug;
36module_param(debug, int, 0644); 35module_param(debug, int, 0644);
37MODULE_PARM_DESC(debug, 36MODULE_PARM_DESC(debug,
38 "set debug level (1=info,2=regs,4=TS,8=irqdma,16=check (|-able))." 37 "set debug level (1=info,2=regs,4=TS,8=irqdma,16=check (|-able))."
39 DEBSTATUS); 38 DEBSTATUS);
40 39
41#define DRIVER_VERSION "0.1" 40#define DRIVER_VERSION "0.1"
42#define DRIVER_NAME "Technisat/B2C2 FlexCop II/IIb/III Digital TV PCI Driver" 41#define DRIVER_NAME "Technisat/B2C2 FlexCop II/IIb/III Digital TV PCI Driver"
@@ -51,30 +50,30 @@ struct flexcop_pci {
51 50
52 void __iomem *io_mem; 51 void __iomem *io_mem;
53 u32 irq; 52 u32 irq;
54/* buffersize (at least for DMA1, need to be % 188 == 0, 53 /* buffersize (at least for DMA1, need to be % 188 == 0,
55 * this logic is required */ 54 * this logic is required */
56#define FC_DEFAULT_DMA1_BUFSIZE (1280 * 188) 55#define FC_DEFAULT_DMA1_BUFSIZE (1280 * 188)
57#define FC_DEFAULT_DMA2_BUFSIZE (10 * 188) 56#define FC_DEFAULT_DMA2_BUFSIZE (10 * 188)
58 struct flexcop_dma dma[2]; 57 struct flexcop_dma dma[2];
59 58
60 int active_dma1_addr; /* 0 = addr0 of dma1; 1 = addr1 of dma1 */ 59 int active_dma1_addr; /* 0 = addr0 of dma1; 1 = addr1 of dma1 */
61 u32 last_dma1_cur_pos; /* position of the pointer last time the timer/packet irq occured */ 60 u32 last_dma1_cur_pos;
61 /* position of the pointer last time the timer/packet irq occured */
62 int count; 62 int count;
63 int count_prev; 63 int count_prev;
64 int stream_problem; 64 int stream_problem;
65 65
66 spinlock_t irq_lock; 66 spinlock_t irq_lock;
67
68 unsigned long last_irq; 67 unsigned long last_irq;
69 68
70 struct delayed_work irq_check_work; 69 struct delayed_work irq_check_work;
71
72 struct flexcop_device *fc_dev; 70 struct flexcop_device *fc_dev;
73}; 71};
74 72
75static int lastwreg,lastwval,lastrreg,lastrval; 73static int lastwreg, lastwval, lastrreg, lastrval;
76 74
77static flexcop_ibi_value flexcop_pci_read_ibi_reg (struct flexcop_device *fc, flexcop_ibi_register r) 75static flexcop_ibi_value flexcop_pci_read_ibi_reg(struct flexcop_device *fc,
76 flexcop_ibi_register r)
78{ 77{
79 struct flexcop_pci *fc_pci = fc->bus_specific; 78 struct flexcop_pci *fc_pci = fc->bus_specific;
80 flexcop_ibi_value v; 79 flexcop_ibi_value v;
@@ -82,19 +81,20 @@ static flexcop_ibi_value flexcop_pci_read_ibi_reg (struct flexcop_device *fc, fl
82 81
83 if (lastrreg != r || lastrval != v.raw) { 82 if (lastrreg != r || lastrval != v.raw) {
84 lastrreg = r; lastrval = v.raw; 83 lastrreg = r; lastrval = v.raw;
85 deb_reg("new rd: %3x: %08x\n",r,v.raw); 84 deb_reg("new rd: %3x: %08x\n", r, v.raw);
86 } 85 }
87 86
88 return v; 87 return v;
89} 88}
90 89
91static int flexcop_pci_write_ibi_reg(struct flexcop_device *fc, flexcop_ibi_register r, flexcop_ibi_value v) 90static int flexcop_pci_write_ibi_reg(struct flexcop_device *fc,
91 flexcop_ibi_register r, flexcop_ibi_value v)
92{ 92{
93 struct flexcop_pci *fc_pci = fc->bus_specific; 93 struct flexcop_pci *fc_pci = fc->bus_specific;
94 94
95 if (lastwreg != r || lastwval != v.raw) { 95 if (lastwreg != r || lastwval != v.raw) {
96 lastwreg = r; lastwval = v.raw; 96 lastwreg = r; lastwval = v.raw;
97 deb_reg("new wr: %3x: %08x\n",r,v.raw); 97 deb_reg("new wr: %3x: %08x\n", r, v.raw);
98 } 98 }
99 99
100 writel(v.raw, fc_pci->io_mem + r); 100 writel(v.raw, fc_pci->io_mem + r);
@@ -113,15 +113,16 @@ static void flexcop_pci_irq_check_work(struct work_struct *work)
113 deb_chk("no IRQ since the last check\n"); 113 deb_chk("no IRQ since the last check\n");
114 if (fc_pci->stream_problem++ == 3) { 114 if (fc_pci->stream_problem++ == 3) {
115 struct dvb_demux_feed *feed; 115 struct dvb_demux_feed *feed;
116 deb_info("flexcop-pci: stream problem, resetting pid filter\n");
116 117
117 spin_lock_irq(&fc->demux.lock); 118 spin_lock_irq(&fc->demux.lock);
118 list_for_each_entry(feed, &fc->demux.feed_list, 119 list_for_each_entry(feed, &fc->demux.feed_list,
119 list_head) { 120 list_head) {
120 flexcop_pid_feed_control(fc, feed, 0); 121 flexcop_pid_feed_control(fc, feed, 0);
121 } 122 }
122 123
123 list_for_each_entry(feed, &fc->demux.feed_list, 124 list_for_each_entry(feed, &fc->demux.feed_list,
124 list_head) { 125 list_head) {
125 flexcop_pid_feed_control(fc, feed, 1); 126 flexcop_pid_feed_control(fc, feed, 1);
126 } 127 }
127 spin_unlock_irq(&fc->demux.lock); 128 spin_unlock_irq(&fc->demux.lock);
@@ -149,11 +150,10 @@ static irqreturn_t flexcop_pci_isr(int irq, void *dev_id)
149 flexcop_ibi_value v; 150 flexcop_ibi_value v;
150 irqreturn_t ret = IRQ_HANDLED; 151 irqreturn_t ret = IRQ_HANDLED;
151 152
152 spin_lock_irqsave(&fc_pci->irq_lock,flags); 153 spin_lock_irqsave(&fc_pci->irq_lock, flags);
153 154 v = fc->read_ibi_reg(fc, irq_20c);
154 v = fc->read_ibi_reg(fc,irq_20c);
155 155
156 /* errors */ 156 /* errors */
157 if (v.irq_20c.Data_receiver_error) 157 if (v.irq_20c.Data_receiver_error)
158 deb_chk("data receiver error\n"); 158 deb_chk("data receiver error\n");
159 if (v.irq_20c.Continuity_error_flag) 159 if (v.irq_20c.Continuity_error_flag)
@@ -164,24 +164,29 @@ static irqreturn_t flexcop_pci_isr(int irq, void *dev_id)
164 deb_chk("Transport error\n"); 164 deb_chk("Transport error\n");
165 165
166 if ((fc_pci->count % 1000) == 0) 166 if ((fc_pci->count % 1000) == 0)
167 deb_chk("%d valid irq took place so far\n",fc_pci->count); 167 deb_chk("%d valid irq took place so far\n", fc_pci->count);
168 168
169 if (v.irq_20c.DMA1_IRQ_Status == 1) { 169 if (v.irq_20c.DMA1_IRQ_Status == 1) {
170 if (fc_pci->active_dma1_addr == 0) 170 if (fc_pci->active_dma1_addr == 0)
171 flexcop_pass_dmx_packets(fc_pci->fc_dev,fc_pci->dma[0].cpu_addr0,fc_pci->dma[0].size / 188); 171 flexcop_pass_dmx_packets(fc_pci->fc_dev,
172 fc_pci->dma[0].cpu_addr0,
173 fc_pci->dma[0].size / 188);
172 else 174 else
173 flexcop_pass_dmx_packets(fc_pci->fc_dev,fc_pci->dma[0].cpu_addr1,fc_pci->dma[0].size / 188); 175 flexcop_pass_dmx_packets(fc_pci->fc_dev,
176 fc_pci->dma[0].cpu_addr1,
177 fc_pci->dma[0].size / 188);
174 178
175 deb_irq("page change to page: %d\n",!fc_pci->active_dma1_addr); 179 deb_irq("page change to page: %d\n",!fc_pci->active_dma1_addr);
176 fc_pci->active_dma1_addr = !fc_pci->active_dma1_addr; 180 fc_pci->active_dma1_addr = !fc_pci->active_dma1_addr;
177 } else if (v.irq_20c.DMA1_Timer_Status == 1) {
178 /* for the timer IRQ we only can use buffer dmx feeding, because we don't have 181 /* for the timer IRQ we only can use buffer dmx feeding, because we don't have
179 * complete TS packets when reading from the DMA memory */ 182 * complete TS packets when reading from the DMA memory */
183 } else if (v.irq_20c.DMA1_Timer_Status == 1) {
180 dma_addr_t cur_addr = 184 dma_addr_t cur_addr =
181 fc->read_ibi_reg(fc,dma1_008).dma_0x8.dma_cur_addr << 2; 185 fc->read_ibi_reg(fc,dma1_008).dma_0x8.dma_cur_addr << 2;
182 u32 cur_pos = cur_addr - fc_pci->dma[0].dma_addr0; 186 u32 cur_pos = cur_addr - fc_pci->dma[0].dma_addr0;
183 187
184 deb_irq("%u irq: %08x cur_addr: %llx: cur_pos: %08x, last_cur_pos: %08x ", 188 deb_irq("%u irq: %08x cur_addr: %llx: cur_pos: %08x, "
189 "last_cur_pos: %08x ",
185 jiffies_to_usecs(jiffies - fc_pci->last_irq), 190 jiffies_to_usecs(jiffies - fc_pci->last_irq),
186 v.raw, (unsigned long long)cur_addr, cur_pos, 191 v.raw, (unsigned long long)cur_addr, cur_pos,
187 fc_pci->last_dma1_cur_pos); 192 fc_pci->last_dma1_cur_pos);
@@ -191,30 +196,36 @@ static irqreturn_t flexcop_pci_isr(int irq, void *dev_id)
191 * pass the data from last_cur_pos to the buffer end to the demux 196 * pass the data from last_cur_pos to the buffer end to the demux
192 */ 197 */
193 if (cur_pos < fc_pci->last_dma1_cur_pos) { 198 if (cur_pos < fc_pci->last_dma1_cur_pos) {
194 deb_irq(" end was reached: passing %d bytes ",(fc_pci->dma[0].size*2 - 1) - fc_pci->last_dma1_cur_pos); 199 deb_irq(" end was reached: passing %d bytes ",
200 (fc_pci->dma[0].size*2 - 1) -
201 fc_pci->last_dma1_cur_pos);
195 flexcop_pass_dmx_data(fc_pci->fc_dev, 202 flexcop_pass_dmx_data(fc_pci->fc_dev,
196 fc_pci->dma[0].cpu_addr0 + fc_pci->last_dma1_cur_pos, 203 fc_pci->dma[0].cpu_addr0 +
197 (fc_pci->dma[0].size*2) - fc_pci->last_dma1_cur_pos); 204 fc_pci->last_dma1_cur_pos,
205 (fc_pci->dma[0].size*2) -
206 fc_pci->last_dma1_cur_pos);
198 fc_pci->last_dma1_cur_pos = 0; 207 fc_pci->last_dma1_cur_pos = 0;
199 } 208 }
200 209
201 if (cur_pos > fc_pci->last_dma1_cur_pos) { 210 if (cur_pos > fc_pci->last_dma1_cur_pos) {
202 deb_irq(" passing %d bytes ",cur_pos - fc_pci->last_dma1_cur_pos); 211 deb_irq(" passing %d bytes ",
212 cur_pos - fc_pci->last_dma1_cur_pos);
203 flexcop_pass_dmx_data(fc_pci->fc_dev, 213 flexcop_pass_dmx_data(fc_pci->fc_dev,
204 fc_pci->dma[0].cpu_addr0 + fc_pci->last_dma1_cur_pos, 214 fc_pci->dma[0].cpu_addr0 +
205 cur_pos - fc_pci->last_dma1_cur_pos); 215 fc_pci->last_dma1_cur_pos,
216 cur_pos - fc_pci->last_dma1_cur_pos);
206 } 217 }
207 deb_irq("\n"); 218 deb_irq("\n");
208 219
209 fc_pci->last_dma1_cur_pos = cur_pos; 220 fc_pci->last_dma1_cur_pos = cur_pos;
210 fc_pci->count++; 221 fc_pci->count++;
211 } else { 222 } else {
212 deb_irq("isr for flexcop called, apparently without reason (%08x)\n",v.raw); 223 deb_irq("isr for flexcop called, "
224 "apparently without reason (%08x)\n", v.raw);
213 ret = IRQ_NONE; 225 ret = IRQ_NONE;
214 } 226 }
215 227
216 spin_unlock_irqrestore(&fc_pci->irq_lock,flags); 228 spin_unlock_irqrestore(&fc_pci->irq_lock, flags);
217
218 return ret; 229 return ret;
219} 230}
220 231
@@ -222,52 +233,48 @@ static int flexcop_pci_stream_control(struct flexcop_device *fc, int onoff)
222{ 233{
223 struct flexcop_pci *fc_pci = fc->bus_specific; 234 struct flexcop_pci *fc_pci = fc->bus_specific;
224 if (onoff) { 235 if (onoff) {
225 flexcop_dma_config(fc,&fc_pci->dma[0],FC_DMA_1); 236 flexcop_dma_config(fc, &fc_pci->dma[0], FC_DMA_1);
226 flexcop_dma_config(fc,&fc_pci->dma[1],FC_DMA_2); 237 flexcop_dma_config(fc, &fc_pci->dma[1], FC_DMA_2);
227 238 flexcop_dma_config_timer(fc, FC_DMA_1, 0);
228 flexcop_dma_config_timer(fc,FC_DMA_1,0); 239 flexcop_dma_xfer_control(fc, FC_DMA_1,
229 240 FC_DMA_SUBADDR_0 | FC_DMA_SUBADDR_1, 1);
230 flexcop_dma_xfer_control(fc,FC_DMA_1,FC_DMA_SUBADDR_0 | FC_DMA_SUBADDR_1,1);
231 deb_irq("DMA xfer enabled\n"); 241 deb_irq("DMA xfer enabled\n");
232 242
233 fc_pci->last_dma1_cur_pos = 0; 243 fc_pci->last_dma1_cur_pos = 0;
234 flexcop_dma_control_timer_irq(fc,FC_DMA_1,1); 244 flexcop_dma_control_timer_irq(fc, FC_DMA_1, 1);
235 deb_irq("IRQ enabled\n"); 245 deb_irq("IRQ enabled\n");
236
237 fc_pci->count_prev = fc_pci->count; 246 fc_pci->count_prev = fc_pci->count;
238
239// fc_pci->active_dma1_addr = 0;
240// flexcop_dma_control_size_irq(fc,FC_DMA_1,1);
241
242 } else { 247 } else {
243 flexcop_dma_control_timer_irq(fc,FC_DMA_1,0); 248 flexcop_dma_control_timer_irq(fc, FC_DMA_1, 0);
244 deb_irq("IRQ disabled\n"); 249 deb_irq("IRQ disabled\n");
245 250
246// flexcop_dma_control_size_irq(fc,FC_DMA_1,0); 251 flexcop_dma_xfer_control(fc, FC_DMA_1,
247 252 FC_DMA_SUBADDR_0 | FC_DMA_SUBADDR_1, 0);
248 flexcop_dma_xfer_control(fc,FC_DMA_1,FC_DMA_SUBADDR_0 | FC_DMA_SUBADDR_1,0);
249 deb_irq("DMA xfer disabled\n"); 253 deb_irq("DMA xfer disabled\n");
250 } 254 }
251
252 return 0; 255 return 0;
253} 256}
254 257
255static int flexcop_pci_dma_init(struct flexcop_pci *fc_pci) 258static int flexcop_pci_dma_init(struct flexcop_pci *fc_pci)
256{ 259{
257 int ret; 260 int ret;
258 if ((ret = flexcop_dma_allocate(fc_pci->pdev,&fc_pci->dma[0],FC_DEFAULT_DMA1_BUFSIZE)) != 0) 261 ret = flexcop_dma_allocate(fc_pci->pdev, &fc_pci->dma[0],
262 FC_DEFAULT_DMA1_BUFSIZE);
263 if (ret != 0)
259 return ret; 264 return ret;
260 265
261 if ((ret = flexcop_dma_allocate(fc_pci->pdev,&fc_pci->dma[1],FC_DEFAULT_DMA2_BUFSIZE)) != 0) { 266 ret = flexcop_dma_allocate(fc_pci->pdev, &fc_pci->dma[1],
267 FC_DEFAULT_DMA2_BUFSIZE);
268 if (ret != 0) {
262 flexcop_dma_free(&fc_pci->dma[0]); 269 flexcop_dma_free(&fc_pci->dma[0]);
263 return ret; 270 return ret;
264 } 271 }
265 272
266 flexcop_sram_set_dest(fc_pci->fc_dev,FC_SRAM_DEST_MEDIA | FC_SRAM_DEST_NET, FC_SRAM_DEST_TARGET_DMA1); 273 flexcop_sram_set_dest(fc_pci->fc_dev, FC_SRAM_DEST_MEDIA |
267 flexcop_sram_set_dest(fc_pci->fc_dev,FC_SRAM_DEST_CAO | FC_SRAM_DEST_CAI, FC_SRAM_DEST_TARGET_DMA2); 274 FC_SRAM_DEST_NET, FC_SRAM_DEST_TARGET_DMA1);
268 275 flexcop_sram_set_dest(fc_pci->fc_dev, FC_SRAM_DEST_CAO |
276 FC_SRAM_DEST_CAI, FC_SRAM_DEST_TARGET_DMA2);
269 fc_pci->init_state |= FC_PCI_DMA_INIT; 277 fc_pci->init_state |= FC_PCI_DMA_INIT;
270
271 return ret; 278 return ret;
272} 279}
273 280
@@ -290,12 +297,8 @@ static int flexcop_pci_init(struct flexcop_pci *fc_pci)
290 297
291 if ((ret = pci_enable_device(fc_pci->pdev)) != 0) 298 if ((ret = pci_enable_device(fc_pci->pdev)) != 0)
292 return ret; 299 return ret;
293
294 pci_set_master(fc_pci->pdev); 300 pci_set_master(fc_pci->pdev);
295 301
296 /* enable interrupts */
297 // pci_write_config_dword(pdev, 0x6c, 0x8000);
298
299 if ((ret = pci_request_regions(fc_pci->pdev, DRIVER_NAME)) != 0) 302 if ((ret = pci_request_regions(fc_pci->pdev, DRIVER_NAME)) != 0)
300 goto err_pci_disable_device; 303 goto err_pci_disable_device;
301 304
@@ -338,8 +341,8 @@ static void flexcop_pci_exit(struct flexcop_pci *fc_pci)
338 fc_pci->init_state &= ~FC_PCI_INIT; 341 fc_pci->init_state &= ~FC_PCI_INIT;
339} 342}
340 343
341 344static int flexcop_pci_probe(struct pci_dev *pdev,
342static int flexcop_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 345 const struct pci_device_id *ent)
343{ 346{
344 struct flexcop_device *fc; 347 struct flexcop_device *fc;
345 struct flexcop_pci *fc_pci; 348 struct flexcop_pci *fc_pci;
@@ -350,7 +353,7 @@ static int flexcop_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
350 return -ENOMEM; 353 return -ENOMEM;
351 } 354 }
352 355
353/* general flexcop init */ 356 /* general flexcop init */
354 fc_pci = fc->bus_specific; 357 fc_pci = fc->bus_specific;
355 fc_pci->fc_dev = fc; 358 fc_pci->fc_dev = fc;
356 359
@@ -358,7 +361,6 @@ static int flexcop_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
358 fc->write_ibi_reg = flexcop_pci_write_ibi_reg; 361 fc->write_ibi_reg = flexcop_pci_write_ibi_reg;
359 fc->i2c_request = flexcop_i2c_request; 362 fc->i2c_request = flexcop_i2c_request;
360 fc->get_mac_addr = flexcop_eeprom_check_mac_addr; 363 fc->get_mac_addr = flexcop_eeprom_check_mac_addr;
361
362 fc->stream_control = flexcop_pci_stream_control; 364 fc->stream_control = flexcop_pci_stream_control;
363 365
364 if (enable_pid_filtering) 366 if (enable_pid_filtering)
@@ -368,29 +370,29 @@ static int flexcop_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
368 370
369 fc->pid_filtering = enable_pid_filtering; 371 fc->pid_filtering = enable_pid_filtering;
370 fc->bus_type = FC_PCI; 372 fc->bus_type = FC_PCI;
371
372 fc->dev = &pdev->dev; 373 fc->dev = &pdev->dev;
373 fc->owner = THIS_MODULE; 374 fc->owner = THIS_MODULE;
374 375
375/* bus specific part */ 376 /* bus specific part */
376 fc_pci->pdev = pdev; 377 fc_pci->pdev = pdev;
377 if ((ret = flexcop_pci_init(fc_pci)) != 0) 378 if ((ret = flexcop_pci_init(fc_pci)) != 0)
378 goto err_kfree; 379 goto err_kfree;
379 380
380/* init flexcop */ 381 /* init flexcop */
381 if ((ret = flexcop_device_initialize(fc)) != 0) 382 if ((ret = flexcop_device_initialize(fc)) != 0)
382 goto err_pci_exit; 383 goto err_pci_exit;
383 384
384/* init dma */ 385 /* init dma */
385 if ((ret = flexcop_pci_dma_init(fc_pci)) != 0) 386 if ((ret = flexcop_pci_dma_init(fc_pci)) != 0)
386 goto err_fc_exit; 387 goto err_fc_exit;
387 388
388 INIT_DELAYED_WORK(&fc_pci->irq_check_work, flexcop_pci_irq_check_work); 389 INIT_DELAYED_WORK(&fc_pci->irq_check_work, flexcop_pci_irq_check_work);
389 390
390 if (irq_chk_intv > 0) 391 if (irq_chk_intv > 0)
391 schedule_delayed_work(&fc_pci->irq_check_work, 392 schedule_delayed_work(&fc_pci->irq_check_work,
392 msecs_to_jiffies(irq_chk_intv < 100 ? 100 : irq_chk_intv)); 393 msecs_to_jiffies(irq_chk_intv < 100 ?
393 394 100 :
395 irq_chk_intv));
394 return ret; 396 return ret;
395 397
396err_fc_exit: 398err_fc_exit:
@@ -420,7 +422,6 @@ static void flexcop_pci_remove(struct pci_dev *pdev)
420 422
421static struct pci_device_id flexcop_pci_tbl[] = { 423static struct pci_device_id flexcop_pci_tbl[] = {
422 { PCI_DEVICE(0x13d0, 0x2103) }, 424 { PCI_DEVICE(0x13d0, 0x2103) },
423/* { PCI_DEVICE(0x13d0, 0x2200) }, ? */
424 { }, 425 { },
425}; 426};
426 427
diff --git a/drivers/media/dvb/b2c2/flexcop-reg.h b/drivers/media/dvb/b2c2/flexcop-reg.h
index 7599fccc1a5b..dc4528dcbb98 100644
--- a/drivers/media/dvb/b2c2/flexcop-reg.h
+++ b/drivers/media/dvb/b2c2/flexcop-reg.h
@@ -1,14 +1,11 @@
1/* 1/*
2 * This file is part of linux driver the digital TV devices equipped with B2C2 FlexcopII(b)/III 2 * Linux driver for digital TV devices equipped with B2C2 FlexcopII(b)/III
3 *
4 * flexcop-reg.h - register abstraction for FlexCopII, FlexCopIIb and FlexCopIII 3 * flexcop-reg.h - register abstraction for FlexCopII, FlexCopIIb and FlexCopIII
5 * 4 * see flexcop.c for copyright information
6 * see flexcop.c for copyright information.
7 */ 5 */
8#ifndef __FLEXCOP_REG_H__ 6#ifndef __FLEXCOP_REG_H__
9#define __FLEXCOP_REG_H__ 7#define __FLEXCOP_REG_H__
10 8
11
12typedef enum { 9typedef enum {
13 FLEXCOP_UNK = 0, 10 FLEXCOP_UNK = 0,
14 FLEXCOP_II, 11 FLEXCOP_II,
@@ -18,13 +15,13 @@ typedef enum {
18 15
19typedef enum { 16typedef enum {
20 FC_UNK = 0, 17 FC_UNK = 0,
21 FC_AIR_DVB, 18 FC_CABLE,
19 FC_AIR_DVBT,
22 FC_AIR_ATSC1, 20 FC_AIR_ATSC1,
23 FC_AIR_ATSC2, 21 FC_AIR_ATSC2,
24 FC_SKY,
25 FC_SKY_OLD,
26 FC_CABLE,
27 FC_AIR_ATSC3, 22 FC_AIR_ATSC3,
23 FC_SKY_REV23,
24 FC_SKY_REV26,
28 FC_SKY_REV27, 25 FC_SKY_REV27,
29 FC_SKY_REV28, 26 FC_SKY_REV28,
30} flexcop_device_type_t; 27} flexcop_device_type_t;
@@ -36,12 +33,12 @@ typedef enum {
36 33
37/* FlexCop IBI Registers */ 34/* FlexCop IBI Registers */
38#if defined(__LITTLE_ENDIAN) 35#if defined(__LITTLE_ENDIAN)
39 #include "flexcop_ibi_value_le.h" 36#include "flexcop_ibi_value_le.h"
40#else 37#else
41#if defined(__BIG_ENDIAN) 38#if defined(__BIG_ENDIAN)
42 #include "flexcop_ibi_value_be.h" 39#include "flexcop_ibi_value_be.h"
43#else 40#else
44 #error no endian defined 41#error no endian defined
45#endif 42#endif
46#endif 43#endif
47 44
diff --git a/drivers/media/dvb/b2c2/flexcop-sram.c b/drivers/media/dvb/b2c2/flexcop-sram.c
index cda69528548a..f2199e43e803 100644
--- a/drivers/media/dvb/b2c2/flexcop-sram.c
+++ b/drivers/media/dvb/b2c2/flexcop-sram.c
@@ -1,45 +1,43 @@
1/* 1/*
2 * This file is part of linux driver the digital TV devices equipped with B2C2 FlexcopII(b)/III 2 * Linux driver for digital TV devices equipped with B2C2 FlexcopII(b)/III
3 * 3 * flexcop-sram.c - functions for controlling the SRAM
4 * flexcop-sram.c - functions for controlling the SRAM. 4 * see flexcop.c for copyright information
5 *
6 * see flexcop.c for copyright information.
7 */ 5 */
8#include "flexcop.h" 6#include "flexcop.h"
9 7
10static void flexcop_sram_set_chip (struct flexcop_device *fc, flexcop_sram_type_t type) 8static void flexcop_sram_set_chip(struct flexcop_device *fc,
9 flexcop_sram_type_t type)
11{ 10{
12 flexcop_set_ibi_value(wan_ctrl_reg_71c,sram_chip,type); 11 flexcop_set_ibi_value(wan_ctrl_reg_71c, sram_chip, type);
13} 12}
14 13
15int flexcop_sram_init(struct flexcop_device *fc) 14int flexcop_sram_init(struct flexcop_device *fc)
16{ 15{
17 switch (fc->rev) { 16 switch (fc->rev) {
18 case FLEXCOP_II: 17 case FLEXCOP_II:
19 case FLEXCOP_IIB: 18 case FLEXCOP_IIB:
20 flexcop_sram_set_chip(fc,FC_SRAM_1_32KB); 19 flexcop_sram_set_chip(fc, FC_SRAM_1_32KB);
21 break; 20 break;
22 case FLEXCOP_III: 21 case FLEXCOP_III:
23 flexcop_sram_set_chip(fc,FC_SRAM_1_48KB); 22 flexcop_sram_set_chip(fc, FC_SRAM_1_48KB);
24 break; 23 break;
25 default: 24 default:
26 return -EINVAL; 25 return -EINVAL;
27 } 26 }
28 return 0; 27 return 0;
29} 28}
30 29
31int flexcop_sram_set_dest(struct flexcop_device *fc, flexcop_sram_dest_t dest, flexcop_sram_dest_target_t target) 30int flexcop_sram_set_dest(struct flexcop_device *fc, flexcop_sram_dest_t dest,
31 flexcop_sram_dest_target_t target)
32{ 32{
33 flexcop_ibi_value v; 33 flexcop_ibi_value v;
34 34 v = fc->read_ibi_reg(fc, sram_dest_reg_714);
35 v = fc->read_ibi_reg(fc,sram_dest_reg_714);
36 35
37 if (fc->rev != FLEXCOP_III && target == FC_SRAM_DEST_TARGET_FC3_CA) { 36 if (fc->rev != FLEXCOP_III && target == FC_SRAM_DEST_TARGET_FC3_CA) {
38 err("SRAM destination target to available on FlexCopII(b)\n"); 37 err("SRAM destination target to available on FlexCopII(b)\n");
39 return -EINVAL; 38 return -EINVAL;
40 } 39 }
41 40 deb_sram("sram dest: %x target: %x\n", dest, target);
42 deb_sram("sram dest: %x target: %x\n",dest, target);
43 41
44 if (dest & FC_SRAM_DEST_NET) 42 if (dest & FC_SRAM_DEST_NET)
45 v.sram_dest_reg_714.NET_Dest = target; 43 v.sram_dest_reg_714.NET_Dest = target;
@@ -154,14 +152,12 @@ static void sram_write_chunk(struct adapter *adapter, u32 addr, u8 *buf, u16 len
154 else 152 else
155 bank = 0x10000000; 153 bank = 0x10000000;
156 } 154 }
157
158 flex_sram_write(adapter, bank, addr & 0x7fff, buf, len); 155 flex_sram_write(adapter, bank, addr & 0x7fff, buf, len);
159} 156}
160 157
161static void sram_read_chunk(struct adapter *adapter, u32 addr, u8 *buf, u16 len) 158static void sram_read_chunk(struct adapter *adapter, u32 addr, u8 *buf, u16 len)
162{ 159{
163 u32 bank; 160 u32 bank;
164
165 bank = 0; 161 bank = 0;
166 162
167 if (adapter->dw_sram_type == 0x20000) { 163 if (adapter->dw_sram_type == 0x20000) {
@@ -174,26 +170,22 @@ static void sram_read_chunk(struct adapter *adapter, u32 addr, u8 *buf, u16 len)
174 else 170 else
175 bank = 0x10000000; 171 bank = 0x10000000;
176 } 172 }
177
178 flex_sram_read(adapter, bank, addr & 0x7fff, buf, len); 173 flex_sram_read(adapter, bank, addr & 0x7fff, buf, len);
179} 174}
180 175
181static void sram_read(struct adapter *adapter, u32 addr, u8 *buf, u32 len) 176static void sram_read(struct adapter *adapter, u32 addr, u8 *buf, u32 len)
182{ 177{
183 u32 length; 178 u32 length;
184
185 while (len != 0) { 179 while (len != 0) {
186 length = len; 180 length = len;
187 181 /* check if the address range belongs to the same
188 // check if the address range belongs to the same 182 * 32K memory chip. If not, the data is read
189 // 32K memory chip. If not, the data is read from 183 * from one chip at a time */
190 // one chip at a time.
191 if ((addr >> 0x0f) != ((addr + len - 1) >> 0x0f)) { 184 if ((addr >> 0x0f) != ((addr + len - 1) >> 0x0f)) {
192 length = (((addr >> 0x0f) + 1) << 0x0f) - addr; 185 length = (((addr >> 0x0f) + 1) << 0x0f) - addr;
193 } 186 }
194 187
195 sram_read_chunk(adapter, addr, buf, length); 188 sram_read_chunk(adapter, addr, buf, length);
196
197 addr = addr + length; 189 addr = addr + length;
198 buf = buf + length; 190 buf = buf + length;
199 len = len - length; 191 len = len - length;
@@ -203,19 +195,17 @@ static void sram_read(struct adapter *adapter, u32 addr, u8 *buf, u32 len)
203static void sram_write(struct adapter *adapter, u32 addr, u8 *buf, u32 len) 195static void sram_write(struct adapter *adapter, u32 addr, u8 *buf, u32 len)
204{ 196{
205 u32 length; 197 u32 length;
206
207 while (len != 0) { 198 while (len != 0) {
208 length = len; 199 length = len;
209 200
210 // check if the address range belongs to the same 201 /* check if the address range belongs to the same
211 // 32K memory chip. If not, the data is written to 202 * 32K memory chip. If not, the data is
212 // one chip at a time. 203 * written to one chip at a time */
213 if ((addr >> 0x0f) != ((addr + len - 1) >> 0x0f)) { 204 if ((addr >> 0x0f) != ((addr + len - 1) >> 0x0f)) {
214 length = (((addr >> 0x0f) + 1) << 0x0f) - addr; 205 length = (((addr >> 0x0f) + 1) << 0x0f) - addr;
215 } 206 }
216 207
217 sram_write_chunk(adapter, addr, buf, length); 208 sram_write_chunk(adapter, addr, buf, length);
218
219 addr = addr + length; 209 addr = addr + length;
220 buf = buf + length; 210 buf = buf + length;
221 len = len - length; 211 len = len - length;
@@ -224,39 +214,29 @@ static void sram_write(struct adapter *adapter, u32 addr, u8 *buf, u32 len)
224 214
225static void sram_set_size(struct adapter *adapter, u32 mask) 215static void sram_set_size(struct adapter *adapter, u32 mask)
226{ 216{
227 write_reg_dw(adapter, 0x71c, (mask | (~0x30000 & read_reg_dw(adapter, 0x71c)))); 217 write_reg_dw(adapter, 0x71c,
218 (mask | (~0x30000 & read_reg_dw(adapter, 0x71c))));
228} 219}
229 220
230static void sram_init(struct adapter *adapter) 221static void sram_init(struct adapter *adapter)
231{ 222{
232 u32 tmp; 223 u32 tmp;
233
234 tmp = read_reg_dw(adapter, 0x71c); 224 tmp = read_reg_dw(adapter, 0x71c);
235
236 write_reg_dw(adapter, 0x71c, 1); 225 write_reg_dw(adapter, 0x71c, 1);
237 226
238 if (read_reg_dw(adapter, 0x71c) != 0) { 227 if (read_reg_dw(adapter, 0x71c) != 0) {
239 write_reg_dw(adapter, 0x71c, tmp); 228 write_reg_dw(adapter, 0x71c, tmp);
240
241 adapter->dw_sram_type = tmp & 0x30000; 229 adapter->dw_sram_type = tmp & 0x30000;
242
243 ddprintk("%s: dw_sram_type = %x\n", __func__, adapter->dw_sram_type); 230 ddprintk("%s: dw_sram_type = %x\n", __func__, adapter->dw_sram_type);
244
245 } else { 231 } else {
246
247 adapter->dw_sram_type = 0x10000; 232 adapter->dw_sram_type = 0x10000;
248
249 ddprintk("%s: dw_sram_type = %x\n", __func__, adapter->dw_sram_type); 233 ddprintk("%s: dw_sram_type = %x\n", __func__, adapter->dw_sram_type);
250 } 234 }
251
252 /* return value is never used? */
253/* return adapter->dw_sram_type; */
254} 235}
255 236
256static int sram_test_location(struct adapter *adapter, u32 mask, u32 addr) 237static int sram_test_location(struct adapter *adapter, u32 mask, u32 addr)
257{ 238{
258 u8 tmp1, tmp2; 239 u8 tmp1, tmp2;
259
260 dprintk("%s: mask = %x, addr = %x\n", __func__, mask, addr); 240 dprintk("%s: mask = %x, addr = %x\n", __func__, mask, addr);
261 241
262 sram_set_size(adapter, mask); 242 sram_set_size(adapter, mask);
@@ -269,7 +249,6 @@ static int sram_test_location(struct adapter *adapter, u32 mask, u32 addr)
269 sram_write(adapter, addr + 4, &tmp1, 1); 249 sram_write(adapter, addr + 4, &tmp1, 1);
270 250
271 tmp2 = 0; 251 tmp2 = 0;
272
273 mdelay(20); 252 mdelay(20);
274 253
275 sram_read(adapter, addr, &tmp2, 1); 254 sram_read(adapter, addr, &tmp2, 1);
@@ -287,7 +266,6 @@ static int sram_test_location(struct adapter *adapter, u32 mask, u32 addr)
287 sram_write(adapter, addr + 4, &tmp1, 1); 266 sram_write(adapter, addr + 4, &tmp1, 1);
288 267
289 tmp2 = 0; 268 tmp2 = 0;
290
291 mdelay(20); 269 mdelay(20);
292 270
293 sram_read(adapter, addr, &tmp2, 1); 271 sram_read(adapter, addr, &tmp2, 1);
@@ -297,26 +275,24 @@ static int sram_test_location(struct adapter *adapter, u32 mask, u32 addr)
297 275
298 if (tmp2 != 0x5a) 276 if (tmp2 != 0x5a)
299 return 0; 277 return 0;
300
301 return 1; 278 return 1;
302} 279}
303 280
304static u32 sram_length(struct adapter *adapter) 281static u32 sram_length(struct adapter *adapter)
305{ 282{
306 if (adapter->dw_sram_type == 0x10000) 283 if (adapter->dw_sram_type == 0x10000)
307 return 32768; // 32K 284 return 32768; /* 32K */
308 if (adapter->dw_sram_type == 0x00000) 285 if (adapter->dw_sram_type == 0x00000)
309 return 65536; // 64K 286 return 65536; /* 64K */
310 if (adapter->dw_sram_type == 0x20000) 287 if (adapter->dw_sram_type == 0x20000)
311 return 131072; // 128K 288 return 131072; /* 128K */
312 289 return 32768; /* 32K */
313 return 32768; // 32K
314} 290}
315 291
316/* FlexcopII can work with 32K, 64K or 128K of external SRAM memory. 292/* FlexcopII can work with 32K, 64K or 128K of external SRAM memory.
317 - for 128K there are 4x32K chips at bank 0,1,2,3. 293 - for 128K there are 4x32K chips at bank 0,1,2,3.
318 - for 64K there are 2x32K chips at bank 1,2. 294 - for 64K there are 2x32K chips at bank 1,2.
319 - for 32K there is one 32K chip at bank 0. 295 - for 32K there is one 32K chip at bank 0.
320 296
321 FlexCop works only with one bank at a time. The bank is selected 297 FlexCop works only with one bank at a time. The bank is selected
322 by bits 28-29 of the 0x700 register. 298 by bits 28-29 of the 0x700 register.
@@ -324,24 +300,18 @@ static u32 sram_length(struct adapter *adapter)
324 bank 0 covers addresses 0x00000-0x07fff 300 bank 0 covers addresses 0x00000-0x07fff
325 bank 1 covers addresses 0x08000-0x0ffff 301 bank 1 covers addresses 0x08000-0x0ffff
326 bank 2 covers addresses 0x10000-0x17fff 302 bank 2 covers addresses 0x10000-0x17fff
327 bank 3 covers addresses 0x18000-0x1ffff 303 bank 3 covers addresses 0x18000-0x1ffff */
328*/
329 304
330static int flexcop_sram_detect(struct flexcop_device *fc) 305static int flexcop_sram_detect(struct flexcop_device *fc)
331{ 306{
332 flexcop_ibi_value r208,r71c_0,vr71c_1; 307 flexcop_ibi_value r208, r71c_0, vr71c_1;
333
334 r208 = fc->read_ibi_reg(fc, ctrl_208); 308 r208 = fc->read_ibi_reg(fc, ctrl_208);
335 fc->write_ibi_reg(fc, ctrl_208, ibi_zero); 309 fc->write_ibi_reg(fc, ctrl_208, ibi_zero);
336 310
337 r71c_0 = fc->read_ibi_reg(fc, wan_ctrl_reg_71c); 311 r71c_0 = fc->read_ibi_reg(fc, wan_ctrl_reg_71c);
338
339 write_reg_dw(adapter, 0x71c, 1); 312 write_reg_dw(adapter, 0x71c, 1);
340
341 tmp3 = read_reg_dw(adapter, 0x71c); 313 tmp3 = read_reg_dw(adapter, 0x71c);
342
343 dprintk("%s: tmp3 = %x\n", __func__, tmp3); 314 dprintk("%s: tmp3 = %x\n", __func__, tmp3);
344
345 write_reg_dw(adapter, 0x71c, tmp2); 315 write_reg_dw(adapter, 0x71c, tmp2);
346 316
347 // check for internal SRAM ??? 317 // check for internal SRAM ???
@@ -350,9 +320,7 @@ static int flexcop_sram_detect(struct flexcop_device *fc)
350 sram_set_size(adapter, 0x10000); 320 sram_set_size(adapter, 0x10000);
351 sram_init(adapter); 321 sram_init(adapter);
352 write_reg_dw(adapter, 0x208, tmp); 322 write_reg_dw(adapter, 0x208, tmp);
353
354 dprintk("%s: sram size = 32K\n", __func__); 323 dprintk("%s: sram size = 32K\n", __func__);
355
356 return 32; 324 return 32;
357 } 325 }
358 326
@@ -360,9 +328,7 @@ static int flexcop_sram_detect(struct flexcop_device *fc)
360 sram_set_size(adapter, 0x20000); 328 sram_set_size(adapter, 0x20000);
361 sram_init(adapter); 329 sram_init(adapter);
362 write_reg_dw(adapter, 0x208, tmp); 330 write_reg_dw(adapter, 0x208, tmp);
363
364 dprintk("%s: sram size = 128K\n", __func__); 331 dprintk("%s: sram size = 128K\n", __func__);
365
366 return 128; 332 return 128;
367 } 333 }
368 334
@@ -370,9 +336,7 @@ static int flexcop_sram_detect(struct flexcop_device *fc)
370 sram_set_size(adapter, 0x00000); 336 sram_set_size(adapter, 0x00000);
371 sram_init(adapter); 337 sram_init(adapter);
372 write_reg_dw(adapter, 0x208, tmp); 338 write_reg_dw(adapter, 0x208, tmp);
373
374 dprintk("%s: sram size = 64K\n", __func__); 339 dprintk("%s: sram size = 64K\n", __func__);
375
376 return 64; 340 return 64;
377 } 341 }
378 342
@@ -380,18 +344,14 @@ static int flexcop_sram_detect(struct flexcop_device *fc)
380 sram_set_size(adapter, 0x10000); 344 sram_set_size(adapter, 0x10000);
381 sram_init(adapter); 345 sram_init(adapter);
382 write_reg_dw(adapter, 0x208, tmp); 346 write_reg_dw(adapter, 0x208, tmp);
383
384 dprintk("%s: sram size = 32K\n", __func__); 347 dprintk("%s: sram size = 32K\n", __func__);
385
386 return 32; 348 return 32;
387 } 349 }
388 350
389 sram_set_size(adapter, 0x10000); 351 sram_set_size(adapter, 0x10000);
390 sram_init(adapter); 352 sram_init(adapter);
391 write_reg_dw(adapter, 0x208, tmp); 353 write_reg_dw(adapter, 0x208, tmp);
392
393 dprintk("%s: SRAM detection failed. Set to 32K \n", __func__); 354 dprintk("%s: SRAM detection failed. Set to 32K \n", __func__);
394
395 return 0; 355 return 0;
396} 356}
397 357
diff --git a/drivers/media/dvb/b2c2/flexcop-usb.c b/drivers/media/dvb/b2c2/flexcop-usb.c
index ae0d76a5d51d..bedcfb671624 100644
--- a/drivers/media/dvb/b2c2/flexcop-usb.c
+++ b/drivers/media/dvb/b2c2/flexcop-usb.c
@@ -1,11 +1,8 @@
1/* 1/*
2 * This file is part of linux driver the digital TV devices equipped with B2C2 FlexcopII(b)/III 2 * Linux driver for digital TV devices equipped with B2C2 FlexcopII(b)/III
3 * 3 * flexcop-usb.c - covers the USB part
4 * flexcop-usb.c - covers the USB part. 4 * see flexcop.c for copyright information
5 *
6 * see flexcop.c for copyright information.
7 */ 5 */
8
9#define FC_LOG_PREFIX "flexcop_usb" 6#define FC_LOG_PREFIX "flexcop_usb"
10#include "flexcop-usb.h" 7#include "flexcop-usb.h"
11#include "flexcop-common.h" 8#include "flexcop-common.h"
@@ -18,42 +15,47 @@
18/* debug */ 15/* debug */
19#ifdef CONFIG_DVB_B2C2_FLEXCOP_DEBUG 16#ifdef CONFIG_DVB_B2C2_FLEXCOP_DEBUG
20#define dprintk(level,args...) \ 17#define dprintk(level,args...) \
21 do { if ((debug & level)) { printk(args); } } while (0) 18 do { if ((debug & level)) printk(args); } while (0)
22#define debug_dump(b,l,method) {\ 19
20#define debug_dump(b, l, method) do {\
23 int i; \ 21 int i; \
24 for (i = 0; i < l; i++) method("%02x ", b[i]); \ 22 for (i = 0; i < l; i++) \
25 method("\n");\ 23 method("%02x ", b[i]); \
26} 24 method("\n"); \
25} while (0)
27 26
28#define DEBSTATUS "" 27#define DEBSTATUS ""
29#else 28#else
30#define dprintk(level,args...) 29#define dprintk(level, args...)
31#define debug_dump(b,l,method) 30#define debug_dump(b, l, method)
32#define DEBSTATUS " (debugging is not enabled)" 31#define DEBSTATUS " (debugging is not enabled)"
33#endif 32#endif
34 33
35static int debug; 34static int debug;
36module_param(debug, int, 0644); 35module_param(debug, int, 0644);
37MODULE_PARM_DESC(debug, "set debugging level (1=info,ts=2,ctrl=4,i2c=8,v8mem=16 (or-able))." DEBSTATUS); 36MODULE_PARM_DESC(debug, "set debugging level (1=info,ts=2,"
37 "ctrl=4,i2c=8,v8mem=16 (or-able))." DEBSTATUS);
38#undef DEBSTATUS 38#undef DEBSTATUS
39 39
40#define deb_info(args...) dprintk(0x01,args) 40#define deb_info(args...) dprintk(0x01, args)
41#define deb_ts(args...) dprintk(0x02,args) 41#define deb_ts(args...) dprintk(0x02, args)
42#define deb_ctrl(args...) dprintk(0x04,args) 42#define deb_ctrl(args...) dprintk(0x04, args)
43#define deb_i2c(args...) dprintk(0x08,args) 43#define deb_i2c(args...) dprintk(0x08, args)
44#define deb_v8(args...) dprintk(0x10,args) 44#define deb_v8(args...) dprintk(0x10, args)
45 45
46/* JLP 111700: we will include the 1 bit gap between the upper and lower 3 bits 46/* JLP 111700: we will include the 1 bit gap between the upper and lower 3 bits
47 * in the IBI address, to make the V8 code simpler. 47 * in the IBI address, to make the V8 code simpler.
48 * PCI ADDRESS FORMAT: 0x71C -> 0000 0111 0001 1100 (these are the six bits used) 48 * PCI ADDRESS FORMAT: 0x71C -> 0000 0111 0001 1100 (the six bits used)
49 * in general: 0000 0HHH 000L LL00 49 * in general: 0000 0HHH 000L LL00
50 * IBI ADDRESS FORMAT: RHHH BLLL 50 * IBI ADDRESS FORMAT: RHHH BLLL
51 * 51 *
52 * where R is the read(1)/write(0) bit, B is the busy bit 52 * where R is the read(1)/write(0) bit, B is the busy bit
53 * and HHH and LLL are the two sets of three bits from the PCI address. 53 * and HHH and LLL are the two sets of three bits from the PCI address.
54 */ 54 */
55#define B2C2_FLEX_PCIOFFSET_TO_INTERNALADDR(usPCI) (u8) (((usPCI >> 2) & 0x07) + ((usPCI >> 4) & 0x70)) 55#define B2C2_FLEX_PCIOFFSET_TO_INTERNALADDR(usPCI) (u8) \
56#define B2C2_FLEX_INTERNALADDR_TO_PCIOFFSET(ucAddr) (u16) (((ucAddr & 0x07) << 2) + ((ucAddr & 0x70) << 4)) 56 (((usPCI >> 2) & 0x07) + ((usPCI >> 4) & 0x70))
57#define B2C2_FLEX_INTERNALADDR_TO_PCIOFFSET(ucAddr) (u16) \
58 (((ucAddr & 0x07) << 2) + ((ucAddr & 0x70) << 4))
57 59
58/* 60/*
59 * DKT 020228 61 * DKT 020228
@@ -69,12 +71,13 @@ static int flexcop_usb_readwrite_dw(struct flexcop_device *fc, u16 wRegOffsPCI,
69 struct flexcop_usb *fc_usb = fc->bus_specific; 71 struct flexcop_usb *fc_usb = fc->bus_specific;
70 u8 request = read ? B2C2_USB_READ_REG : B2C2_USB_WRITE_REG; 72 u8 request = read ? B2C2_USB_READ_REG : B2C2_USB_WRITE_REG;
71 u8 request_type = (read ? USB_DIR_IN : USB_DIR_OUT) | USB_TYPE_VENDOR; 73 u8 request_type = (read ? USB_DIR_IN : USB_DIR_OUT) | USB_TYPE_VENDOR;
72 u8 wAddress = B2C2_FLEX_PCIOFFSET_TO_INTERNALADDR(wRegOffsPCI) | (read ? 0x80 : 0); 74 u8 wAddress = B2C2_FLEX_PCIOFFSET_TO_INTERNALADDR(wRegOffsPCI) |
75 (read ? 0x80 : 0);
73 76
74 int len = usb_control_msg(fc_usb->udev, 77 int len = usb_control_msg(fc_usb->udev,
75 read ? B2C2_USB_CTRL_PIPE_IN : B2C2_USB_CTRL_PIPE_OUT, 78 read ? B2C2_USB_CTRL_PIPE_IN : B2C2_USB_CTRL_PIPE_OUT,
76 request, 79 request,
77 request_type, /* 0xc0 read or 0x40 write*/ 80 request_type, /* 0xc0 read or 0x40 write */
78 wAddress, 81 wAddress,
79 0, 82 0,
80 val, 83 val,
@@ -82,55 +85,49 @@ static int flexcop_usb_readwrite_dw(struct flexcop_device *fc, u16 wRegOffsPCI,
82 B2C2_WAIT_FOR_OPERATION_RDW * HZ); 85 B2C2_WAIT_FOR_OPERATION_RDW * HZ);
83 86
84 if (len != sizeof(u32)) { 87 if (len != sizeof(u32)) {
85 err("error while %s dword from %d (%d).",read ? "reading" : "writing", 88 err("error while %s dword from %d (%d).", read ? "reading" :
86 wAddress,wRegOffsPCI); 89 "writing", wAddress, wRegOffsPCI);
87 return -EIO; 90 return -EIO;
88 } 91 }
89 return 0; 92 return 0;
90} 93}
91
92/* 94/*
93 * DKT 010817 - add support for V8 memory read/write and flash update 95 * DKT 010817 - add support for V8 memory read/write and flash update
94 */ 96 */
95static int flexcop_usb_v8_memory_req(struct flexcop_usb *fc_usb, 97static int flexcop_usb_v8_memory_req(struct flexcop_usb *fc_usb,
96 flexcop_usb_request_t req, u8 page, u16 wAddress, 98 flexcop_usb_request_t req, u8 page, u16 wAddress,
97 u8 *pbBuffer,u32 buflen) 99 u8 *pbBuffer, u32 buflen)
98{ 100{
99// u8 dwRequestType;
100 u8 request_type = USB_TYPE_VENDOR; 101 u8 request_type = USB_TYPE_VENDOR;
101 u16 wIndex; 102 u16 wIndex;
102 int nWaitTime,pipe,len; 103 int nWaitTime, pipe, len;
103
104 wIndex = page << 8; 104 wIndex = page << 8;
105 105
106 switch (req) { 106 switch (req) {
107 case B2C2_USB_READ_V8_MEM: 107 case B2C2_USB_READ_V8_MEM:
108 nWaitTime = B2C2_WAIT_FOR_OPERATION_V8READ; 108 nWaitTime = B2C2_WAIT_FOR_OPERATION_V8READ;
109 request_type |= USB_DIR_IN; 109 request_type |= USB_DIR_IN;
110// dwRequestType = (u8) RTYPE_READ_V8_MEMORY; 110 pipe = B2C2_USB_CTRL_PIPE_IN;
111 pipe = B2C2_USB_CTRL_PIPE_IN;
112 break; 111 break;
113 case B2C2_USB_WRITE_V8_MEM: 112 case B2C2_USB_WRITE_V8_MEM:
114 wIndex |= pbBuffer[0]; 113 wIndex |= pbBuffer[0];
115 request_type |= USB_DIR_OUT; 114 request_type |= USB_DIR_OUT;
116 nWaitTime = B2C2_WAIT_FOR_OPERATION_V8WRITE; 115 nWaitTime = B2C2_WAIT_FOR_OPERATION_V8WRITE;
117// dwRequestType = (u8) RTYPE_WRITE_V8_MEMORY; 116 pipe = B2C2_USB_CTRL_PIPE_OUT;
118 pipe = B2C2_USB_CTRL_PIPE_OUT;
119 break; 117 break;
120 case B2C2_USB_FLASH_BLOCK: 118 case B2C2_USB_FLASH_BLOCK:
121 request_type |= USB_DIR_OUT; 119 request_type |= USB_DIR_OUT;
122 nWaitTime = B2C2_WAIT_FOR_OPERATION_V8FLASH; 120 nWaitTime = B2C2_WAIT_FOR_OPERATION_V8FLASH;
123// dwRequestType = (u8) RTYPE_WRITE_V8_FLASH; 121 pipe = B2C2_USB_CTRL_PIPE_OUT;
124 pipe = B2C2_USB_CTRL_PIPE_OUT;
125 break; 122 break;
126 default: 123 default:
127 deb_info("unsupported request for v8_mem_req %x.\n",req); 124 deb_info("unsupported request for v8_mem_req %x.\n", req);
128 return -EINVAL; 125 return -EINVAL;
129 } 126 }
130 deb_v8("v8mem: %02x %02x %04x %04x, len: %d\n",request_type,req, 127 deb_v8("v8mem: %02x %02x %04x %04x, len: %d\n", request_type, req,
131 wAddress,wIndex,buflen); 128 wAddress, wIndex, buflen);
132 129
133 len = usb_control_msg(fc_usb->udev,pipe, 130 len = usb_control_msg(fc_usb->udev, pipe,
134 req, 131 req,
135 request_type, 132 request_type,
136 wAddress, 133 wAddress,
@@ -139,39 +136,53 @@ static int flexcop_usb_v8_memory_req(struct flexcop_usb *fc_usb,
139 buflen, 136 buflen,
140 nWaitTime * HZ); 137 nWaitTime * HZ);
141 138
142 debug_dump(pbBuffer,len,deb_v8); 139 debug_dump(pbBuffer, len, deb_v8);
143
144 return len == buflen ? 0 : -EIO; 140 return len == buflen ? 0 : -EIO;
145} 141}
146 142
147#define bytes_left_to_read_on_page(paddr,buflen) \ 143#define bytes_left_to_read_on_page(paddr,buflen) \
148 ((V8_MEMORY_PAGE_SIZE - (paddr & V8_MEMORY_PAGE_MASK)) > buflen \ 144 ((V8_MEMORY_PAGE_SIZE - (paddr & V8_MEMORY_PAGE_MASK)) > buflen \
149 ? buflen : (V8_MEMORY_PAGE_SIZE - (paddr & V8_MEMORY_PAGE_MASK))) 145 ? buflen : (V8_MEMORY_PAGE_SIZE - (paddr & V8_MEMORY_PAGE_MASK)))
150 146
151static int flexcop_usb_memory_req(struct flexcop_usb *fc_usb,flexcop_usb_request_t req, 147static int flexcop_usb_memory_req(struct flexcop_usb *fc_usb,
152 flexcop_usb_mem_page_t page_start, u32 addr, int extended, u8 *buf, u32 len) 148 flexcop_usb_request_t req, flexcop_usb_mem_page_t page_start,
149 u32 addr, int extended, u8 *buf, u32 len)
153{ 150{
154 int i,ret = 0; 151 int i,ret = 0;
155 u16 wMax; 152 u16 wMax;
156 u32 pagechunk = 0; 153 u32 pagechunk = 0;
157 154
158 switch(req) { 155 switch(req) {
159 case B2C2_USB_READ_V8_MEM: wMax = USB_MEM_READ_MAX; break; 156 case B2C2_USB_READ_V8_MEM:
160 case B2C2_USB_WRITE_V8_MEM: wMax = USB_MEM_WRITE_MAX; break; 157 wMax = USB_MEM_READ_MAX;
161 case B2C2_USB_FLASH_BLOCK: wMax = USB_FLASH_MAX; break; 158 break;
162 default: 159 case B2C2_USB_WRITE_V8_MEM:
163 return -EINVAL; 160 wMax = USB_MEM_WRITE_MAX;
161 break;
162 case B2C2_USB_FLASH_BLOCK:
163 wMax = USB_FLASH_MAX;
164 break;
165 default:
166 return -EINVAL;
164 break; 167 break;
165 } 168 }
166 for (i = 0; i < len;) { 169 for (i = 0; i < len;) {
167 pagechunk = wMax < bytes_left_to_read_on_page(addr,len) ? wMax : bytes_left_to_read_on_page(addr,len); 170 pagechunk =
168 deb_info("%x\n",(addr & V8_MEMORY_PAGE_MASK) | (V8_MEMORY_EXTENDED*extended)); 171 wMax < bytes_left_to_read_on_page(addr, len) ?
169 if ((ret = flexcop_usb_v8_memory_req(fc_usb,req, 172 wMax :
170 page_start + (addr / V8_MEMORY_PAGE_SIZE), /* actual page */ 173 bytes_left_to_read_on_page(addr, len);
171 (addr & V8_MEMORY_PAGE_MASK) | (V8_MEMORY_EXTENDED*extended), 174 deb_info("%x\n",
172 &buf[i],pagechunk)) < 0) 175 (addr & V8_MEMORY_PAGE_MASK) |
176 (V8_MEMORY_EXTENDED*extended));
177
178 ret = flexcop_usb_v8_memory_req(fc_usb, req,
179 page_start + (addr / V8_MEMORY_PAGE_SIZE),
180 (addr & V8_MEMORY_PAGE_MASK) |
181 (V8_MEMORY_EXTENDED*extended),
182 &buf[i], pagechunk);
183
184 if (ret < 0)
173 return ret; 185 return ret;
174
175 addr += pagechunk; 186 addr += pagechunk;
176 len -= pagechunk; 187 len -= pagechunk;
177 } 188 }
@@ -180,8 +191,9 @@ static int flexcop_usb_memory_req(struct flexcop_usb *fc_usb,flexcop_usb_request
180 191
181static int flexcop_usb_get_mac_addr(struct flexcop_device *fc, int extended) 192static int flexcop_usb_get_mac_addr(struct flexcop_device *fc, int extended)
182{ 193{
183 return flexcop_usb_memory_req(fc->bus_specific,B2C2_USB_READ_V8_MEM, 194 return flexcop_usb_memory_req(fc->bus_specific, B2C2_USB_READ_V8_MEM,
184 V8_MEMORY_PAGE_FLASH,0x1f010,1,fc->dvb_adapter.proposed_mac,6); 195 V8_MEMORY_PAGE_FLASH, 0x1f010, 1,
196 fc->dvb_adapter.proposed_mac, 6);
185} 197}
186 198
187#if 0 199#if 0
@@ -191,11 +203,8 @@ static int flexcop_usb_utility_req(struct flexcop_usb *fc_usb, int set,
191{ 203{
192 u16 wValue; 204 u16 wValue;
193 u8 request_type = (set ? USB_DIR_OUT : USB_DIR_IN) | USB_TYPE_VENDOR; 205 u8 request_type = (set ? USB_DIR_OUT : USB_DIR_IN) | USB_TYPE_VENDOR;
194// u8 dwRequestType = (u8) RTYPE_GENERIC,
195 int nWaitTime = 2, 206 int nWaitTime = 2,
196 pipe = set ? B2C2_USB_CTRL_PIPE_OUT : B2C2_USB_CTRL_PIPE_IN, 207 pipe = set ? B2C2_USB_CTRL_PIPE_OUT : B2C2_USB_CTRL_PIPE_IN, len;
197 len;
198
199 wValue = (func << 8) | extra; 208 wValue = (func << 8) | extra;
200 209
201 len = usb_control_msg(fc_usb->udev,pipe, 210 len = usb_control_msg(fc_usb->udev,pipe,
@@ -218,36 +227,35 @@ static int flexcop_usb_i2c_req(struct flexcop_i2c_adapter *i2c,
218 struct flexcop_usb *fc_usb = i2c->fc->bus_specific; 227 struct flexcop_usb *fc_usb = i2c->fc->bus_specific;
219 u16 wValue, wIndex; 228 u16 wValue, wIndex;
220 int nWaitTime,pipe,len; 229 int nWaitTime,pipe,len;
221// u8 dwRequestType;
222 u8 request_type = USB_TYPE_VENDOR; 230 u8 request_type = USB_TYPE_VENDOR;
223 231
224 switch (func) { 232 switch (func) {
225 case USB_FUNC_I2C_WRITE: 233 case USB_FUNC_I2C_WRITE:
226 case USB_FUNC_I2C_MULTIWRITE: 234 case USB_FUNC_I2C_MULTIWRITE:
227 case USB_FUNC_I2C_REPEATWRITE: 235 case USB_FUNC_I2C_REPEATWRITE:
228 /* DKT 020208 - add this to support special case of DiSEqC */ 236 /* DKT 020208 - add this to support special case of DiSEqC */
229 case USB_FUNC_I2C_CHECKWRITE: 237 case USB_FUNC_I2C_CHECKWRITE:
230 pipe = B2C2_USB_CTRL_PIPE_OUT; 238 pipe = B2C2_USB_CTRL_PIPE_OUT;
231 nWaitTime = 2; 239 nWaitTime = 2;
232// dwRequestType = (u8) RTYPE_GENERIC; 240 request_type |= USB_DIR_OUT;
233 request_type |= USB_DIR_OUT;
234 break; 241 break;
235 case USB_FUNC_I2C_READ: 242 case USB_FUNC_I2C_READ:
236 case USB_FUNC_I2C_REPEATREAD: 243 case USB_FUNC_I2C_REPEATREAD:
237 pipe = B2C2_USB_CTRL_PIPE_IN; 244 pipe = B2C2_USB_CTRL_PIPE_IN;
238 nWaitTime = 2; 245 nWaitTime = 2;
239// dwRequestType = (u8) RTYPE_GENERIC; 246 request_type |= USB_DIR_IN;
240 request_type |= USB_DIR_IN;
241 break; 247 break;
242 default: 248 default:
243 deb_info("unsupported function for i2c_req %x\n",func); 249 deb_info("unsupported function for i2c_req %x\n", func);
244 return -EINVAL; 250 return -EINVAL;
245 } 251 }
246 wValue = (func << 8) | (i2c->port << 4); 252 wValue = (func << 8) | (i2c->port << 4);
247 wIndex = (chipaddr << 8 ) | addr; 253 wIndex = (chipaddr << 8 ) | addr;
248 254
249 deb_i2c("i2c %2d: %02x %02x %02x %02x %02x %02x\n",func,request_type,req, 255 deb_i2c("i2c %2d: %02x %02x %02x %02x %02x %02x\n",
250 wValue & 0xff, wValue >> 8, wIndex & 0xff, wIndex >> 8); 256 func, request_type, req,
257 wValue & 0xff, wValue >> 8,
258 wIndex & 0xff, wIndex >> 8);
251 259
252 len = usb_control_msg(fc_usb->udev,pipe, 260 len = usb_control_msg(fc_usb->udev,pipe,
253 req, 261 req,
@@ -257,44 +265,49 @@ static int flexcop_usb_i2c_req(struct flexcop_i2c_adapter *i2c,
257 buf, 265 buf,
258 buflen, 266 buflen,
259 nWaitTime * HZ); 267 nWaitTime * HZ);
260
261 return len == buflen ? 0 : -EREMOTEIO; 268 return len == buflen ? 0 : -EREMOTEIO;
262} 269}
263 270
264/* actual bus specific access functions, make sure prototype are/will be equal to pci */ 271/* actual bus specific access functions,
265static flexcop_ibi_value flexcop_usb_read_ibi_reg(struct flexcop_device *fc, flexcop_ibi_register reg) 272 make sure prototype are/will be equal to pci */
273static flexcop_ibi_value flexcop_usb_read_ibi_reg(struct flexcop_device *fc,
274 flexcop_ibi_register reg)
266{ 275{
267 flexcop_ibi_value val; 276 flexcop_ibi_value val;
268 val.raw = 0; 277 val.raw = 0;
269 flexcop_usb_readwrite_dw(fc,reg, &val.raw, 1); 278 flexcop_usb_readwrite_dw(fc, reg, &val.raw, 1);
270 return val; 279 return val;
271} 280}
272 281
273static int flexcop_usb_write_ibi_reg(struct flexcop_device *fc, flexcop_ibi_register reg, flexcop_ibi_value val) 282static int flexcop_usb_write_ibi_reg(struct flexcop_device *fc,
283 flexcop_ibi_register reg, flexcop_ibi_value val)
274{ 284{
275 return flexcop_usb_readwrite_dw(fc,reg, &val.raw, 0); 285 return flexcop_usb_readwrite_dw(fc, reg, &val.raw, 0);
276} 286}
277 287
278static int flexcop_usb_i2c_request(struct flexcop_i2c_adapter *i2c, 288static int flexcop_usb_i2c_request(struct flexcop_i2c_adapter *i2c,
279 flexcop_access_op_t op, u8 chipaddr, u8 addr, u8 *buf, u16 len) 289 flexcop_access_op_t op, u8 chipaddr, u8 addr, u8 *buf, u16 len)
280{ 290{
281 if (op == FC_READ) 291 if (op == FC_READ)
282 return flexcop_usb_i2c_req(i2c, B2C2_USB_I2C_REQUEST, 292 return flexcop_usb_i2c_req(i2c, B2C2_USB_I2C_REQUEST,
283 USB_FUNC_I2C_READ, chipaddr, addr, buf, len); 293 USB_FUNC_I2C_READ, chipaddr, addr, buf, len);
284 else 294 else
285 return flexcop_usb_i2c_req(i2c, B2C2_USB_I2C_REQUEST, 295 return flexcop_usb_i2c_req(i2c, B2C2_USB_I2C_REQUEST,
286 USB_FUNC_I2C_WRITE, chipaddr, addr, buf, len); 296 USB_FUNC_I2C_WRITE, chipaddr, addr, buf, len);
287} 297}
288 298
289static void flexcop_usb_process_frame(struct flexcop_usb *fc_usb, u8 *buffer, int buffer_length) 299static void flexcop_usb_process_frame(struct flexcop_usb *fc_usb,
300 u8 *buffer, int buffer_length)
290{ 301{
291 u8 *b; 302 u8 *b;
292 int l; 303 int l;
293 304
294 deb_ts("tmp_buffer_length=%d, buffer_length=%d\n", fc_usb->tmp_buffer_length, buffer_length); 305 deb_ts("tmp_buffer_length=%d, buffer_length=%d\n",
306 fc_usb->tmp_buffer_length, buffer_length);
295 307
296 if (fc_usb->tmp_buffer_length > 0) { 308 if (fc_usb->tmp_buffer_length > 0) {
297 memcpy(fc_usb->tmp_buffer+fc_usb->tmp_buffer_length, buffer, buffer_length); 309 memcpy(fc_usb->tmp_buffer+fc_usb->tmp_buffer_length, buffer,
310 buffer_length);
298 fc_usb->tmp_buffer_length += buffer_length; 311 fc_usb->tmp_buffer_length += buffer_length;
299 b = fc_usb->tmp_buffer; 312 b = fc_usb->tmp_buffer;
300 l = fc_usb->tmp_buffer_length; 313 l = fc_usb->tmp_buffer_length;
@@ -304,23 +317,26 @@ static void flexcop_usb_process_frame(struct flexcop_usb *fc_usb, u8 *buffer, in
304 } 317 }
305 318
306 while (l >= 190) { 319 while (l >= 190) {
307 if (*b == 0xff) 320 if (*b == 0xff) {
308 switch (*(b+1) & 0x03) { 321 switch (*(b+1) & 0x03) {
309 case 0x01: /* media packet */ 322 case 0x01: /* media packet */
310 if ( *(b+2) == 0x47 ) 323 if (*(b+2) == 0x47)
311 flexcop_pass_dmx_packets(fc_usb->fc_dev, b+2, 1); 324 flexcop_pass_dmx_packets(
312 else 325 fc_usb->fc_dev, b+2, 1);
313 deb_ts("not ts packet %02x %02x %02x %02x \n", *(b+2), *(b+3), *(b+4), *(b+5) ); 326 else
314 327 deb_ts(
315 b += 190; 328 "not ts packet %02x %02x %02x %02x \n",
316 l -= 190; 329 *(b+2), *(b+3),
330 *(b+4), *(b+5));
331 b += 190;
332 l -= 190;
317 break; 333 break;
318 default: 334 default:
319 deb_ts("wrong packet type\n"); 335 deb_ts("wrong packet type\n");
320 l = 0; 336 l = 0;
321 break; 337 break;
322 } 338 }
323 else { 339 } else {
324 deb_ts("wrong header\n"); 340 deb_ts("wrong header\n");
325 l = 0; 341 l = 0;
326 } 342 }
@@ -337,23 +353,26 @@ static void flexcop_usb_urb_complete(struct urb *urb)
337 int i; 353 int i;
338 354
339 if (urb->actual_length > 0) 355 if (urb->actual_length > 0)
340 deb_ts("urb completed, bufsize: %d actlen; %d\n",urb->transfer_buffer_length, urb->actual_length); 356 deb_ts("urb completed, bufsize: %d actlen; %d\n",
357 urb->transfer_buffer_length, urb->actual_length);
341 358
342 for (i = 0; i < urb->number_of_packets; i++) { 359 for (i = 0; i < urb->number_of_packets; i++) {
343 if (urb->iso_frame_desc[i].status < 0) { 360 if (urb->iso_frame_desc[i].status < 0) {
344 err("iso frame descriptor %d has an error: %d\n",i,urb->iso_frame_desc[i].status); 361 err("iso frame descriptor %d has an error: %d\n", i,
362 urb->iso_frame_desc[i].status);
345 } else 363 } else
346 if (urb->iso_frame_desc[i].actual_length > 0) { 364 if (urb->iso_frame_desc[i].actual_length > 0) {
347 deb_ts("passed %d bytes to the demux\n",urb->iso_frame_desc[i].actual_length); 365 deb_ts("passed %d bytes to the demux\n",
366 urb->iso_frame_desc[i].actual_length);
348 367
349 flexcop_usb_process_frame(fc_usb, 368 flexcop_usb_process_frame(fc_usb,
350 urb->transfer_buffer + urb->iso_frame_desc[i].offset, 369 urb->transfer_buffer +
370 urb->iso_frame_desc[i].offset,
351 urb->iso_frame_desc[i].actual_length); 371 urb->iso_frame_desc[i].actual_length);
352 } 372 }
353 urb->iso_frame_desc[i].status = 0; 373 urb->iso_frame_desc[i].status = 0;
354 urb->iso_frame_desc[i].actual_length = 0; 374 urb->iso_frame_desc[i].actual_length = 0;
355 } 375 }
356
357 usb_submit_urb(urb,GFP_ATOMIC); 376 usb_submit_urb(urb,GFP_ATOMIC);
358} 377}
359 378
@@ -374,35 +393,47 @@ static void flexcop_usb_transfer_exit(struct flexcop_usb *fc_usb)
374 } 393 }
375 394
376 if (fc_usb->iso_buffer != NULL) 395 if (fc_usb->iso_buffer != NULL)
377 pci_free_consistent(NULL,fc_usb->buffer_size, fc_usb->iso_buffer, fc_usb->dma_addr); 396 pci_free_consistent(NULL,
397 fc_usb->buffer_size, fc_usb->iso_buffer,
398 fc_usb->dma_addr);
378} 399}
379 400
380static int flexcop_usb_transfer_init(struct flexcop_usb *fc_usb) 401static int flexcop_usb_transfer_init(struct flexcop_usb *fc_usb)
381{ 402{
382 u16 frame_size = le16_to_cpu(fc_usb->uintf->cur_altsetting->endpoint[0].desc.wMaxPacketSize); 403 u16 frame_size = le16_to_cpu(
383 int bufsize = B2C2_USB_NUM_ISO_URB * B2C2_USB_FRAMES_PER_ISO * frame_size,i,j,ret; 404 fc_usb->uintf->cur_altsetting->endpoint[0].desc.wMaxPacketSize);
405 int bufsize = B2C2_USB_NUM_ISO_URB * B2C2_USB_FRAMES_PER_ISO *
406 frame_size, i, j, ret;
384 int buffer_offset = 0; 407 int buffer_offset = 0;
385 408
386 deb_ts("creating %d iso-urbs with %d frames each of %d bytes size = %d.\n", 409 deb_ts("creating %d iso-urbs with %d frames "
387 B2C2_USB_NUM_ISO_URB, B2C2_USB_FRAMES_PER_ISO, frame_size,bufsize); 410 "each of %d bytes size = %d.\n", B2C2_USB_NUM_ISO_URB,
411 B2C2_USB_FRAMES_PER_ISO, frame_size, bufsize);
388 412
389 fc_usb->iso_buffer = pci_alloc_consistent(NULL,bufsize,&fc_usb->dma_addr); 413 fc_usb->iso_buffer = pci_alloc_consistent(NULL,
414 bufsize, &fc_usb->dma_addr);
390 if (fc_usb->iso_buffer == NULL) 415 if (fc_usb->iso_buffer == NULL)
391 return -ENOMEM; 416 return -ENOMEM;
417
392 memset(fc_usb->iso_buffer, 0, bufsize); 418 memset(fc_usb->iso_buffer, 0, bufsize);
393 fc_usb->buffer_size = bufsize; 419 fc_usb->buffer_size = bufsize;
394 420
395 /* creating iso urbs */ 421 /* creating iso urbs */
396 for (i = 0; i < B2C2_USB_NUM_ISO_URB; i++) 422 for (i = 0; i < B2C2_USB_NUM_ISO_URB; i++) {
397 if (!(fc_usb->iso_urb[i] = usb_alloc_urb(B2C2_USB_FRAMES_PER_ISO,GFP_ATOMIC))) { 423 fc_usb->iso_urb[i] = usb_alloc_urb(B2C2_USB_FRAMES_PER_ISO,
424 GFP_ATOMIC);
425 if (fc_usb->iso_urb[i] == NULL) {
398 ret = -ENOMEM; 426 ret = -ENOMEM;
399 goto urb_error; 427 goto urb_error;
400 } 428 }
429 }
430
401 /* initialising and submitting iso urbs */ 431 /* initialising and submitting iso urbs */
402 for (i = 0; i < B2C2_USB_NUM_ISO_URB; i++) { 432 for (i = 0; i < B2C2_USB_NUM_ISO_URB; i++) {
403 int frame_offset = 0; 433 int frame_offset = 0;
404 struct urb *urb = fc_usb->iso_urb[i]; 434 struct urb *urb = fc_usb->iso_urb[i];
405 deb_ts("initializing and submitting urb no. %d (buf_offset: %d).\n",i,buffer_offset); 435 deb_ts("initializing and submitting urb no. %d "
436 "(buf_offset: %d).\n", i, buffer_offset);
406 437
407 urb->dev = fc_usb->udev; 438 urb->dev = fc_usb->udev;
408 urb->context = fc_usb; 439 urb->context = fc_usb;
@@ -416,26 +447,26 @@ static int flexcop_usb_transfer_init(struct flexcop_usb *fc_usb)
416 447
417 buffer_offset += frame_size * B2C2_USB_FRAMES_PER_ISO; 448 buffer_offset += frame_size * B2C2_USB_FRAMES_PER_ISO;
418 for (j = 0; j < B2C2_USB_FRAMES_PER_ISO; j++) { 449 for (j = 0; j < B2C2_USB_FRAMES_PER_ISO; j++) {
419 deb_ts("urb no: %d, frame: %d, frame_offset: %d\n",i,j,frame_offset); 450 deb_ts("urb no: %d, frame: %d, frame_offset: %d\n",
451 i, j, frame_offset);
420 urb->iso_frame_desc[j].offset = frame_offset; 452 urb->iso_frame_desc[j].offset = frame_offset;
421 urb->iso_frame_desc[j].length = frame_size; 453 urb->iso_frame_desc[j].length = frame_size;
422 frame_offset += frame_size; 454 frame_offset += frame_size;
423 } 455 }
424 456
425 if ((ret = usb_submit_urb(fc_usb->iso_urb[i],GFP_ATOMIC))) { 457 if ((ret = usb_submit_urb(fc_usb->iso_urb[i],GFP_ATOMIC))) {
426 err("submitting urb %d failed with %d.",i,ret); 458 err("submitting urb %d failed with %d.", i, ret);
427 goto urb_error; 459 goto urb_error;
428 } 460 }
429 deb_ts("submitted urb no. %d.\n",i); 461 deb_ts("submitted urb no. %d.\n",i);
430 } 462 }
431 463
432/* SRAM */ 464 /* SRAM */
433 465 flexcop_sram_set_dest(fc_usb->fc_dev, FC_SRAM_DEST_MEDIA |
434 flexcop_sram_set_dest(fc_usb->fc_dev,FC_SRAM_DEST_MEDIA | FC_SRAM_DEST_NET | 466 FC_SRAM_DEST_NET | FC_SRAM_DEST_CAO | FC_SRAM_DEST_CAI,
435 FC_SRAM_DEST_CAO | FC_SRAM_DEST_CAI, FC_SRAM_DEST_TARGET_WAN_USB); 467 FC_SRAM_DEST_TARGET_WAN_USB);
436 flexcop_wan_set_speed(fc_usb->fc_dev,FC_WAN_SPEED_8MBITS); 468 flexcop_wan_set_speed(fc_usb->fc_dev, FC_WAN_SPEED_8MBITS);
437 flexcop_sram_ctrl(fc_usb->fc_dev,1,1,1); 469 flexcop_sram_ctrl(fc_usb->fc_dev, 1, 1, 1);
438
439 return 0; 470 return 0;
440 471
441urb_error: 472urb_error:
@@ -448,20 +479,20 @@ static int flexcop_usb_init(struct flexcop_usb *fc_usb)
448 /* use the alternate setting with the larges buffer */ 479 /* use the alternate setting with the larges buffer */
449 usb_set_interface(fc_usb->udev,0,1); 480 usb_set_interface(fc_usb->udev,0,1);
450 switch (fc_usb->udev->speed) { 481 switch (fc_usb->udev->speed) {
451 case USB_SPEED_LOW: 482 case USB_SPEED_LOW:
452 err("cannot handle USB speed because it is to sLOW."); 483 err("cannot handle USB speed because it is too slow.");
453 return -ENODEV; 484 return -ENODEV;
454 break; 485 break;
455 case USB_SPEED_FULL: 486 case USB_SPEED_FULL:
456 info("running at FULL speed."); 487 info("running at FULL speed.");
457 break; 488 break;
458 case USB_SPEED_HIGH: 489 case USB_SPEED_HIGH:
459 info("running at HIGH speed."); 490 info("running at HIGH speed.");
460 break; 491 break;
461 case USB_SPEED_UNKNOWN: /* fall through */ 492 case USB_SPEED_UNKNOWN: /* fall through */
462 default: 493 default:
463 err("cannot handle USB speed because it is unkown."); 494 err("cannot handle USB speed because it is unknown.");
464 return -ENODEV; 495 return -ENODEV;
465 } 496 }
466 usb_set_intfdata(fc_usb->uintf, fc_usb); 497 usb_set_intfdata(fc_usb->uintf, fc_usb);
467 return 0; 498 return 0;
@@ -485,7 +516,7 @@ static int flexcop_usb_probe(struct usb_interface *intf,
485 return -ENOMEM; 516 return -ENOMEM;
486 } 517 }
487 518
488/* general flexcop init */ 519 /* general flexcop init */
489 fc_usb = fc->bus_specific; 520 fc_usb = fc->bus_specific;
490 fc_usb->fc_dev = fc; 521 fc_usb->fc_dev = fc;
491 522
@@ -502,21 +533,21 @@ static int flexcop_usb_probe(struct usb_interface *intf,
502 fc->dev = &udev->dev; 533 fc->dev = &udev->dev;
503 fc->owner = THIS_MODULE; 534 fc->owner = THIS_MODULE;
504 535
505/* bus specific part */ 536 /* bus specific part */
506 fc_usb->udev = udev; 537 fc_usb->udev = udev;
507 fc_usb->uintf = intf; 538 fc_usb->uintf = intf;
508 if ((ret = flexcop_usb_init(fc_usb)) != 0) 539 if ((ret = flexcop_usb_init(fc_usb)) != 0)
509 goto err_kfree; 540 goto err_kfree;
510 541
511/* init flexcop */ 542 /* init flexcop */
512 if ((ret = flexcop_device_initialize(fc)) != 0) 543 if ((ret = flexcop_device_initialize(fc)) != 0)
513 goto err_usb_exit; 544 goto err_usb_exit;
514 545
515/* xfer init */ 546 /* xfer init */
516 if ((ret = flexcop_usb_transfer_init(fc_usb)) != 0) 547 if ((ret = flexcop_usb_transfer_init(fc_usb)) != 0)
517 goto err_fc_exit; 548 goto err_fc_exit;
518 549
519 info("%s successfully initialized and connected.",DRIVER_NAME); 550 info("%s successfully initialized and connected.", DRIVER_NAME);
520 return 0; 551 return 0;
521 552
522err_fc_exit: 553err_fc_exit:
@@ -535,12 +566,12 @@ static void flexcop_usb_disconnect(struct usb_interface *intf)
535 flexcop_device_exit(fc_usb->fc_dev); 566 flexcop_device_exit(fc_usb->fc_dev);
536 flexcop_usb_exit(fc_usb); 567 flexcop_usb_exit(fc_usb);
537 flexcop_device_kfree(fc_usb->fc_dev); 568 flexcop_device_kfree(fc_usb->fc_dev);
538 info("%s successfully deinitialized and disconnected.",DRIVER_NAME); 569 info("%s successfully deinitialized and disconnected.", DRIVER_NAME);
539} 570}
540 571
541static struct usb_device_id flexcop_usb_table [] = { 572static struct usb_device_id flexcop_usb_table [] = {
542 { USB_DEVICE(0x0af7, 0x0101) }, 573 { USB_DEVICE(0x0af7, 0x0101) },
543 { } 574 { }
544}; 575};
545MODULE_DEVICE_TABLE (usb, flexcop_usb_table); 576MODULE_DEVICE_TABLE (usb, flexcop_usb_table);
546 577
@@ -557,10 +588,9 @@ static int __init flexcop_usb_module_init(void)
557{ 588{
558 int result; 589 int result;
559 if ((result = usb_register(&flexcop_usb_driver))) { 590 if ((result = usb_register(&flexcop_usb_driver))) {
560 err("usb_register failed. (%d)",result); 591 err("usb_register failed. (%d)", result);
561 return result; 592 return result;
562 } 593 }
563
564 return 0; 594 return 0;
565} 595}
566 596
diff --git a/drivers/media/dvb/b2c2/flexcop-usb.h b/drivers/media/dvb/b2c2/flexcop-usb.h
index 630e647a2caa..92529a9c4475 100644
--- a/drivers/media/dvb/b2c2/flexcop-usb.h
+++ b/drivers/media/dvb/b2c2/flexcop-usb.h
@@ -1,15 +1,20 @@
1/*
2 * Linux driver for digital TV devices equipped with B2C2 FlexcopII(b)/III
3 * flexcop-usb.h - header file for the USB part
4 * see flexcop.c for copyright information
5 */
1#ifndef __FLEXCOP_USB_H_INCLUDED__ 6#ifndef __FLEXCOP_USB_H_INCLUDED__
2#define __FLEXCOP_USB_H_INCLUDED__ 7#define __FLEXCOP_USB_H_INCLUDED__
3 8
4#include <linux/usb.h> 9#include <linux/usb.h>
5 10
6/* transfer parameters */ 11/* transfer parameters */
7#define B2C2_USB_FRAMES_PER_ISO 4 12#define B2C2_USB_FRAMES_PER_ISO 4
8#define B2C2_USB_NUM_ISO_URB 4 13#define B2C2_USB_NUM_ISO_URB 4
9 14
10#define B2C2_USB_CTRL_PIPE_IN usb_rcvctrlpipe(fc_usb->udev,0) 15#define B2C2_USB_CTRL_PIPE_IN usb_rcvctrlpipe(fc_usb->udev, 0)
11#define B2C2_USB_CTRL_PIPE_OUT usb_sndctrlpipe(fc_usb->udev,0) 16#define B2C2_USB_CTRL_PIPE_OUT usb_sndctrlpipe(fc_usb->udev, 0)
12#define B2C2_USB_DATA_PIPE usb_rcvisocpipe(fc_usb->udev,0x81) 17#define B2C2_USB_DATA_PIPE usb_rcvisocpipe(fc_usb->udev, 0x81)
13 18
14struct flexcop_usb { 19struct flexcop_usb {
15 struct usb_device *udev; 20 struct usb_device *udev;
@@ -18,8 +23,8 @@ struct flexcop_usb {
18 u8 *iso_buffer; 23 u8 *iso_buffer;
19 int buffer_size; 24 int buffer_size;
20 dma_addr_t dma_addr; 25 dma_addr_t dma_addr;
21 struct urb *iso_urb[B2C2_USB_NUM_ISO_URB];
22 26
27 struct urb *iso_urb[B2C2_USB_NUM_ISO_URB];
23 struct flexcop_device *fc_dev; 28 struct flexcop_device *fc_dev;
24 29
25 u8 tmp_buffer[1023+190]; 30 u8 tmp_buffer[1023+190];
@@ -30,14 +35,6 @@ struct flexcop_usb {
30/* request types TODO What is its use?*/ 35/* request types TODO What is its use?*/
31typedef enum { 36typedef enum {
32 37
33/* something is wrong with this part
34 RTYPE_READ_DW = (1 << 6),
35 RTYPE_WRITE_DW_1 = (3 << 6),
36 RTYPE_READ_V8_MEMORY = (6 << 6),
37 RTYPE_WRITE_V8_MEMORY = (7 << 6),
38 RTYPE_WRITE_V8_FLASH = (8 << 6),
39 RTYPE_GENERIC = (9 << 6),
40*/
41} flexcop_usb_request_type_t; 38} flexcop_usb_request_type_t;
42#endif 39#endif
43 40
@@ -47,7 +44,6 @@ typedef enum {
47 B2C2_USB_READ_V8_MEM = 0x05, 44 B2C2_USB_READ_V8_MEM = 0x05,
48 B2C2_USB_READ_REG = 0x08, 45 B2C2_USB_READ_REG = 0x08,
49 B2C2_USB_WRITE_REG = 0x0A, 46 B2C2_USB_WRITE_REG = 0x0A,
50/* B2C2_USB_WRITEREGLO = 0x0A, */
51 B2C2_USB_WRITEREGHI = 0x0B, 47 B2C2_USB_WRITEREGHI = 0x0B,
52 B2C2_USB_FLASH_BLOCK = 0x10, 48 B2C2_USB_FLASH_BLOCK = 0x10,
53 B2C2_USB_I2C_REQUEST = 0x11, 49 B2C2_USB_I2C_REQUEST = 0x11,
@@ -62,15 +58,13 @@ typedef enum {
62 USB_FUNC_I2C_REPEATWRITE = 0x04, 58 USB_FUNC_I2C_REPEATWRITE = 0x04,
63 USB_FUNC_GET_DESCRIPTOR = 0x05, 59 USB_FUNC_GET_DESCRIPTOR = 0x05,
64 USB_FUNC_I2C_REPEATREAD = 0x06, 60 USB_FUNC_I2C_REPEATREAD = 0x06,
65/* DKT 020208 - add this to support special case of DiSEqC */ 61 /* DKT 020208 - add this to support special case of DiSEqC */
66 USB_FUNC_I2C_CHECKWRITE = 0x07, 62 USB_FUNC_I2C_CHECKWRITE = 0x07,
67 USB_FUNC_I2C_CHECKRESULT = 0x08, 63 USB_FUNC_I2C_CHECKRESULT = 0x08,
68} flexcop_usb_i2c_function_t; 64} flexcop_usb_i2c_function_t;
69 65
70/* 66/* function definition for UTILITY request 0x12
71 * function definition for UTILITY request 0x12 67 * DKT 020304 - new utility function */
72 * DKT 020304 - new utility function
73 */
74typedef enum { 68typedef enum {
75 UTILITY_SET_FILTER = 0x01, 69 UTILITY_SET_FILTER = 0x01,
76 UTILITY_DATA_ENABLE = 0x02, 70 UTILITY_DATA_ENABLE = 0x02,
@@ -84,7 +78,7 @@ typedef enum {
84 UTILITY_DATA_RESET = 0x0A, 78 UTILITY_DATA_RESET = 0x0A,
85 UTILITY_GET_DATA_STATUS = 0x10, 79 UTILITY_GET_DATA_STATUS = 0x10,
86 UTILITY_GET_V8_REG = 0x11, 80 UTILITY_GET_V8_REG = 0x11,
87/* DKT 020326 - add function for v1.14 */ 81 /* DKT 020326 - add function for v1.14 */
88 UTILITY_SRAM_WRITE = 0x12, 82 UTILITY_SRAM_WRITE = 0x12,
89 UTILITY_SRAM_READ = 0x13, 83 UTILITY_SRAM_READ = 0x13,
90 UTILITY_SRAM_TESTFILL = 0x14, 84 UTILITY_SRAM_TESTFILL = 0x14,
@@ -92,13 +86,13 @@ typedef enum {
92 UTILITY_SRAM_TESTVERIFY = 0x16, 86 UTILITY_SRAM_TESTVERIFY = 0x16,
93} flexcop_usb_utility_function_t; 87} flexcop_usb_utility_function_t;
94 88
95#define B2C2_WAIT_FOR_OPERATION_RW 1*HZ /* 1 s */ 89#define B2C2_WAIT_FOR_OPERATION_RW (1*HZ)
96#define B2C2_WAIT_FOR_OPERATION_RDW 3*HZ /* 3 s */ 90#define B2C2_WAIT_FOR_OPERATION_RDW (3*HZ)
97#define B2C2_WAIT_FOR_OPERATION_WDW 1*HZ /* 1 s */ 91#define B2C2_WAIT_FOR_OPERATION_WDW (1*HZ)
98 92
99#define B2C2_WAIT_FOR_OPERATION_V8READ 3*HZ /* 3 s */ 93#define B2C2_WAIT_FOR_OPERATION_V8READ (3*HZ)
100#define B2C2_WAIT_FOR_OPERATION_V8WRITE 3*HZ /* 3 s */ 94#define B2C2_WAIT_FOR_OPERATION_V8WRITE (3*HZ)
101#define B2C2_WAIT_FOR_OPERATION_V8FLASH 3*HZ /* 3 s */ 95#define B2C2_WAIT_FOR_OPERATION_V8FLASH (3*HZ)
102 96
103typedef enum { 97typedef enum {
104 V8_MEMORY_PAGE_DVB_CI = 0x20, 98 V8_MEMORY_PAGE_DVB_CI = 0x20,
@@ -107,13 +101,11 @@ typedef enum {
107 V8_MEMORY_PAGE_FLASH = 0x80 101 V8_MEMORY_PAGE_FLASH = 0x80
108} flexcop_usb_mem_page_t; 102} flexcop_usb_mem_page_t;
109 103
110#define V8_MEMORY_EXTENDED (1 << 15) 104#define V8_MEMORY_EXTENDED (1 << 15)
111 105#define USB_MEM_READ_MAX 32
112#define USB_MEM_READ_MAX 32 106#define USB_MEM_WRITE_MAX 1
113#define USB_MEM_WRITE_MAX 1 107#define USB_FLASH_MAX 8
114#define USB_FLASH_MAX 8 108#define V8_MEMORY_PAGE_SIZE 0x8000 /* 32K */
115 109#define V8_MEMORY_PAGE_MASK 0x7FFF
116#define V8_MEMORY_PAGE_SIZE 0x8000 // 32K
117#define V8_MEMORY_PAGE_MASK 0x7FFF
118 110
119#endif 111#endif
diff --git a/drivers/media/dvb/b2c2/flexcop.c b/drivers/media/dvb/b2c2/flexcop.c
index 91068952b502..2df1b0214dcd 100644
--- a/drivers/media/dvb/b2c2/flexcop.c
+++ b/drivers/media/dvb/b2c2/flexcop.c
@@ -1,22 +1,20 @@
1/* 1/*
2 * flexcop.c - driver for digital TV devices equipped with B2C2 FlexcopII(b)/III 2 * Linux driver for digital TV devices equipped with B2C2 FlexcopII(b)/III
3 * 3 * flexcop.c - main module part
4 * Copyright (C) 2004-5 Patrick Boettcher <patrick.boettcher@desy.de> 4 * Copyright (C) 2004-9 Patrick Boettcher <patrick.boettcher@desy.de>
5 * 5 * based on skystar2-driver Copyright (C) 2003 Vadim Catana, skystar@moldova.cc
6 * based on the skystar2-driver
7 * Copyright (C) 2003 Vadim Catana, skystar@moldova.cc
8 * 6 *
9 * Acknowledgements: 7 * Acknowledgements:
10 * John Jurrius from BBTI, Inc. for extensive support with 8 * John Jurrius from BBTI, Inc. for extensive support
11 * code examples and data books 9 * with code examples and data books
12 * 10 * Bjarne Steinsbo, bjarne at steinsbo.com (some ideas for rewriting)
13 * Bjarne Steinsbo, bjarne at steinsbo.com (some ideas for rewriting)
14 * 11 *
15 * Contributions to the skystar2-driver have been done by 12 * Contributions to the skystar2-driver have been done by
16 * Vincenzo Di Massa, hawk.it at tiscalinet.it (several DiSEqC fixes) 13 * Vincenzo Di Massa, hawk.it at tiscalinet.it (several DiSEqC fixes)
17 * Roberto Ragusa, r.ragusa at libero.it (polishing, restyling the code) 14 * Roberto Ragusa, r.ragusa at libero.it (polishing, restyling the code)
18 * Niklas Peinecke, peinecke at gdv.uni-hannover.de (hardware pid/mac filtering) 15 * Uwe Bugla, uwe.bugla at gmx.de (doing tests, restyling code, writing docu)
19 * 16 * Niklas Peinecke, peinecke at gdv.uni-hannover.de (hardware pid/mac
17 * filtering)
20 * 18 *
21 * This program is free software; you can redistribute it and/or 19 * This program is free software; you can redistribute it and/or
22 * modify it under the terms of the GNU Lesser General Public License 20 * modify it under the terms of the GNU Lesser General Public License
@@ -46,7 +44,10 @@
46 44
47int b2c2_flexcop_debug; 45int b2c2_flexcop_debug;
48module_param_named(debug, b2c2_flexcop_debug, int, 0644); 46module_param_named(debug, b2c2_flexcop_debug, int, 0644);
49MODULE_PARM_DESC(debug, "set debug level (1=info,2=tuner,4=i2c,8=ts,16=sram,32=reg (|-able))." DEBSTATUS); 47MODULE_PARM_DESC(debug,
48 "set debug level (1=info,2=tuner,4=i2c,8=ts,"
49 "16=sram,32=reg (|-able))."
50 DEBSTATUS);
50#undef DEBSTATUS 51#undef DEBSTATUS
51 52
52DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); 53DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
@@ -57,37 +58,36 @@ flexcop_ibi_value ibi_zero;
57static int flexcop_dvb_start_feed(struct dvb_demux_feed *dvbdmxfeed) 58static int flexcop_dvb_start_feed(struct dvb_demux_feed *dvbdmxfeed)
58{ 59{
59 struct flexcop_device *fc = dvbdmxfeed->demux->priv; 60 struct flexcop_device *fc = dvbdmxfeed->demux->priv;
60 return flexcop_pid_feed_control(fc,dvbdmxfeed,1); 61 return flexcop_pid_feed_control(fc, dvbdmxfeed, 1);
61} 62}
62 63
63static int flexcop_dvb_stop_feed(struct dvb_demux_feed *dvbdmxfeed) 64static int flexcop_dvb_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
64{ 65{
65 struct flexcop_device *fc = dvbdmxfeed->demux->priv; 66 struct flexcop_device *fc = dvbdmxfeed->demux->priv;
66 return flexcop_pid_feed_control(fc,dvbdmxfeed,0); 67 return flexcop_pid_feed_control(fc, dvbdmxfeed, 0);
67} 68}
68 69
69static int flexcop_dvb_init(struct flexcop_device *fc) 70static int flexcop_dvb_init(struct flexcop_device *fc)
70{ 71{
71 int ret = dvb_register_adapter(&fc->dvb_adapter, 72 int ret = dvb_register_adapter(&fc->dvb_adapter,
72 "FlexCop Digital TV device", fc->owner, 73 "FlexCop Digital TV device", fc->owner,
73 fc->dev, adapter_nr); 74 fc->dev, adapter_nr);
74 if (ret < 0) { 75 if (ret < 0) {
75 err("error registering DVB adapter"); 76 err("error registering DVB adapter");
76 return ret; 77 return ret;
77 } 78 }
78 fc->dvb_adapter.priv = fc; 79 fc->dvb_adapter.priv = fc;
79 80
80 fc->demux.dmx.capabilities = (DMX_TS_FILTERING | DMX_SECTION_FILTERING | DMX_MEMORY_BASED_FILTERING); 81 fc->demux.dmx.capabilities = (DMX_TS_FILTERING | DMX_SECTION_FILTERING
82 | DMX_MEMORY_BASED_FILTERING);
81 fc->demux.priv = fc; 83 fc->demux.priv = fc;
82
83 fc->demux.filternum = fc->demux.feednum = FC_MAX_FEED; 84 fc->demux.filternum = fc->demux.feednum = FC_MAX_FEED;
84
85 fc->demux.start_feed = flexcop_dvb_start_feed; 85 fc->demux.start_feed = flexcop_dvb_start_feed;
86 fc->demux.stop_feed = flexcop_dvb_stop_feed; 86 fc->demux.stop_feed = flexcop_dvb_stop_feed;
87 fc->demux.write_to_decoder = NULL; 87 fc->demux.write_to_decoder = NULL;
88 88
89 if ((ret = dvb_dmx_init(&fc->demux)) < 0) { 89 if ((ret = dvb_dmx_init(&fc->demux)) < 0) {
90 err("dvb_dmx failed: error %d",ret); 90 err("dvb_dmx failed: error %d", ret);
91 goto err_dmx; 91 goto err_dmx;
92 } 92 }
93 93
@@ -97,23 +97,23 @@ static int flexcop_dvb_init(struct flexcop_device *fc)
97 fc->dmxdev.demux = &fc->demux.dmx; 97 fc->dmxdev.demux = &fc->demux.dmx;
98 fc->dmxdev.capabilities = 0; 98 fc->dmxdev.capabilities = 0;
99 if ((ret = dvb_dmxdev_init(&fc->dmxdev, &fc->dvb_adapter)) < 0) { 99 if ((ret = dvb_dmxdev_init(&fc->dmxdev, &fc->dvb_adapter)) < 0) {
100 err("dvb_dmxdev_init failed: error %d",ret); 100 err("dvb_dmxdev_init failed: error %d", ret);
101 goto err_dmx_dev; 101 goto err_dmx_dev;
102 } 102 }
103 103
104 if ((ret = fc->demux.dmx.add_frontend(&fc->demux.dmx, &fc->hw_frontend)) < 0) { 104 if ((ret = fc->demux.dmx.add_frontend(&fc->demux.dmx, &fc->hw_frontend)) < 0) {
105 err("adding hw_frontend to dmx failed: error %d",ret); 105 err("adding hw_frontend to dmx failed: error %d", ret);
106 goto err_dmx_add_hw_frontend; 106 goto err_dmx_add_hw_frontend;
107 } 107 }
108 108
109 fc->mem_frontend.source = DMX_MEMORY_FE; 109 fc->mem_frontend.source = DMX_MEMORY_FE;
110 if ((ret = fc->demux.dmx.add_frontend(&fc->demux.dmx, &fc->mem_frontend)) < 0) { 110 if ((ret = fc->demux.dmx.add_frontend(&fc->demux.dmx, &fc->mem_frontend)) < 0) {
111 err("adding mem_frontend to dmx failed: error %d",ret); 111 err("adding mem_frontend to dmx failed: error %d", ret);
112 goto err_dmx_add_mem_frontend; 112 goto err_dmx_add_mem_frontend;
113 } 113 }
114 114
115 if ((ret = fc->demux.dmx.connect_frontend(&fc->demux.dmx, &fc->hw_frontend)) < 0) { 115 if ((ret = fc->demux.dmx.connect_frontend(&fc->demux.dmx, &fc->hw_frontend)) < 0) {
116 err("connect frontend failed: error %d",ret); 116 err("connect frontend failed: error %d", ret);
117 goto err_connect_frontend; 117 goto err_connect_frontend;
118 } 118 }
119 119
@@ -123,9 +123,9 @@ static int flexcop_dvb_init(struct flexcop_device *fc)
123 return 0; 123 return 0;
124 124
125err_connect_frontend: 125err_connect_frontend:
126 fc->demux.dmx.remove_frontend(&fc->demux.dmx,&fc->mem_frontend); 126 fc->demux.dmx.remove_frontend(&fc->demux.dmx, &fc->mem_frontend);
127err_dmx_add_mem_frontend: 127err_dmx_add_mem_frontend:
128 fc->demux.dmx.remove_frontend(&fc->demux.dmx,&fc->hw_frontend); 128 fc->demux.dmx.remove_frontend(&fc->demux.dmx, &fc->hw_frontend);
129err_dmx_add_hw_frontend: 129err_dmx_add_hw_frontend:
130 dvb_dmxdev_release(&fc->dmxdev); 130 dvb_dmxdev_release(&fc->dmxdev);
131err_dmx_dev: 131err_dmx_dev:
@@ -141,12 +141,13 @@ static void flexcop_dvb_exit(struct flexcop_device *fc)
141 dvb_net_release(&fc->dvbnet); 141 dvb_net_release(&fc->dvbnet);
142 142
143 fc->demux.dmx.close(&fc->demux.dmx); 143 fc->demux.dmx.close(&fc->demux.dmx);
144 fc->demux.dmx.remove_frontend(&fc->demux.dmx,&fc->mem_frontend); 144 fc->demux.dmx.remove_frontend(&fc->demux.dmx,
145 fc->demux.dmx.remove_frontend(&fc->demux.dmx,&fc->hw_frontend); 145 &fc->mem_frontend);
146 fc->demux.dmx.remove_frontend(&fc->demux.dmx,
147 &fc->hw_frontend);
146 dvb_dmxdev_release(&fc->dmxdev); 148 dvb_dmxdev_release(&fc->dmxdev);
147 dvb_dmx_release(&fc->demux); 149 dvb_dmx_release(&fc->demux);
148 dvb_unregister_adapter(&fc->dvb_adapter); 150 dvb_unregister_adapter(&fc->dvb_adapter);
149
150 deb_info("deinitialized dvb stuff\n"); 151 deb_info("deinitialized dvb stuff\n");
151 } 152 }
152 fc->init_state &= ~FC_STATE_DVB_INIT; 153 fc->init_state &= ~FC_STATE_DVB_INIT;
@@ -168,9 +169,9 @@ EXPORT_SYMBOL(flexcop_pass_dmx_packets);
168 169
169static void flexcop_reset(struct flexcop_device *fc) 170static void flexcop_reset(struct flexcop_device *fc)
170{ 171{
171 flexcop_ibi_value v210,v204; 172 flexcop_ibi_value v210, v204;
172 173
173/* reset the flexcop itself */ 174 /* reset the flexcop itself */
174 fc->write_ibi_reg(fc,ctrl_208,ibi_zero); 175 fc->write_ibi_reg(fc,ctrl_208,ibi_zero);
175 176
176 v210.raw = 0; 177 v210.raw = 0;
@@ -183,13 +184,11 @@ static void flexcop_reset(struct flexcop_device *fc)
183 v210.sw_reset_210.reset_block_600 = 1; 184 v210.sw_reset_210.reset_block_600 = 1;
184 v210.sw_reset_210.reset_block_700 = 1; 185 v210.sw_reset_210.reset_block_700 = 1;
185 v210.sw_reset_210.Block_reset_enable = 0xb2; 186 v210.sw_reset_210.Block_reset_enable = 0xb2;
186
187 v210.sw_reset_210.Special_controls = 0xc259; 187 v210.sw_reset_210.Special_controls = 0xc259;
188
189 fc->write_ibi_reg(fc,sw_reset_210,v210); 188 fc->write_ibi_reg(fc,sw_reset_210,v210);
190 msleep(1); 189 msleep(1);
191 190
192/* reset the periphical devices */ 191 /* reset the periphical devices */
193 192
194 v204 = fc->read_ibi_reg(fc,misc_204); 193 v204 = fc->read_ibi_reg(fc,misc_204);
195 v204.misc_204.Per_reset_sig = 0; 194 v204.misc_204.Per_reset_sig = 0;
@@ -201,25 +200,24 @@ static void flexcop_reset(struct flexcop_device *fc)
201 200
202void flexcop_reset_block_300(struct flexcop_device *fc) 201void flexcop_reset_block_300(struct flexcop_device *fc)
203{ 202{
204 flexcop_ibi_value v208_save = fc->read_ibi_reg(fc,ctrl_208), 203 flexcop_ibi_value v208_save = fc->read_ibi_reg(fc, ctrl_208),
205 v210 = fc->read_ibi_reg(fc,sw_reset_210); 204 v210 = fc->read_ibi_reg(fc, sw_reset_210);
206
207 deb_rdump("208: %08x, 210: %08x\n",v208_save.raw,v210.raw);
208 205
206 deb_rdump("208: %08x, 210: %08x\n", v208_save.raw, v210.raw);
209 fc->write_ibi_reg(fc,ctrl_208,ibi_zero); 207 fc->write_ibi_reg(fc,ctrl_208,ibi_zero);
210 208
211 v210.sw_reset_210.reset_block_300 = 1; 209 v210.sw_reset_210.reset_block_300 = 1;
212 v210.sw_reset_210.Block_reset_enable = 0xb2; 210 v210.sw_reset_210.Block_reset_enable = 0xb2;
213 211
214 fc->write_ibi_reg(fc,sw_reset_210,v210); 212 fc->write_ibi_reg(fc,sw_reset_210,v210);
215 udelay(1000);
216 fc->write_ibi_reg(fc,ctrl_208,v208_save); 213 fc->write_ibi_reg(fc,ctrl_208,v208_save);
217} 214}
218 215
219struct flexcop_device *flexcop_device_kmalloc(size_t bus_specific_len) 216struct flexcop_device *flexcop_device_kmalloc(size_t bus_specific_len)
220{ 217{
221 void *bus; 218 void *bus;
222 struct flexcop_device *fc = kzalloc(sizeof(struct flexcop_device), GFP_KERNEL); 219 struct flexcop_device *fc = kzalloc(sizeof(struct flexcop_device),
220 GFP_KERNEL);
223 if (!fc) { 221 if (!fc) {
224 err("no memory"); 222 err("no memory");
225 return NULL; 223 return NULL;
@@ -254,7 +252,6 @@ int flexcop_device_initialize(struct flexcop_device *fc)
254 flexcop_determine_revision(fc); 252 flexcop_determine_revision(fc);
255 flexcop_sram_init(fc); 253 flexcop_sram_init(fc);
256 flexcop_hw_filter_init(fc); 254 flexcop_hw_filter_init(fc);
257
258 flexcop_smc_ctrl(fc, 0); 255 flexcop_smc_ctrl(fc, 0);
259 256
260 if ((ret = flexcop_dvb_init(fc))) 257 if ((ret = flexcop_dvb_init(fc)))
@@ -279,7 +276,6 @@ int flexcop_device_initialize(struct flexcop_device *fc)
279 goto error; 276 goto error;
280 277
281 flexcop_device_name(fc,"initialization of","complete"); 278 flexcop_device_name(fc,"initialization of","complete");
282
283 return 0; 279 return 0;
284 280
285error: 281error:
diff --git a/drivers/media/dvb/b2c2/flexcop.h b/drivers/media/dvb/b2c2/flexcop.h
index 0cebe1d92e0b..897b10c85ad9 100644
--- a/drivers/media/dvb/b2c2/flexcop.h
+++ b/drivers/media/dvb/b2c2/flexcop.h
@@ -1,9 +1,7 @@
1/* 1/*
2 * This file is part of linux driver the digital TV devices equipped with B2C2 FlexcopII(b)/III 2 * Linux driver for digital TV devices equipped with B2C2 FlexcopII(b)/III
3 * 3 * flexcop.h - private header file for all flexcop-chip-source files
4 * flexcop.h - private header file for all flexcop-chip-source files. 4 * see flexcop.c for copyright information
5 *
6 * see flexcop.c for copyright information.
7 */ 5 */
8#ifndef __FLEXCOP_H__ 6#ifndef __FLEXCOP_H__
9#define __FLEXCOP_H___ 7#define __FLEXCOP_H___
@@ -21,11 +19,11 @@ extern int b2c2_flexcop_debug;
21#define dprintk(level,args...) 19#define dprintk(level,args...)
22#endif 20#endif
23 21
24#define deb_info(args...) dprintk(0x01,args) 22#define deb_info(args...) dprintk(0x01, args)
25#define deb_tuner(args...) dprintk(0x02,args) 23#define deb_tuner(args...) dprintk(0x02, args)
26#define deb_i2c(args...) dprintk(0x04,args) 24#define deb_i2c(args...) dprintk(0x04, args)
27#define deb_ts(args...) dprintk(0x08,args) 25#define deb_ts(args...) dprintk(0x08, args)
28#define deb_sram(args...) dprintk(0x10,args) 26#define deb_sram(args...) dprintk(0x10, args)
29#define deb_rdump(args...) dprintk(0x20,args) 27#define deb_rdump(args...) dprintk(0x20, args)
30 28
31#endif 29#endif
diff --git a/drivers/media/dvb/b2c2/flexcop_ibi_value_be.h b/drivers/media/dvb/b2c2/flexcop_ibi_value_be.h
index ed9a6756b194..8f64bdbd72bb 100644
--- a/drivers/media/dvb/b2c2/flexcop_ibi_value_be.h
+++ b/drivers/media/dvb/b2c2/flexcop_ibi_value_be.h
@@ -1,10 +1,7 @@
1/* This file is part of linux driver for digital TV devices equipped with B2C2 FlexcopII(b)/III 1/* Linux driver for digital TV devices equipped with B2C2 FlexcopII(b)/III
2 *
3 * register descriptions 2 * register descriptions
4 * 3 * see flexcop.c for copyright information
5 * see flexcop.c for copyright information.
6 */ 4 */
7
8/* This file is automatically generated, do not edit things here. */ 5/* This file is automatically generated, do not edit things here. */
9#ifndef __FLEXCOP_IBI_VALUE_INCLUDED__ 6#ifndef __FLEXCOP_IBI_VALUE_INCLUDED__
10#define __FLEXCOP_IBI_VALUE_INCLUDED__ 7#define __FLEXCOP_IBI_VALUE_INCLUDED__
diff --git a/drivers/media/dvb/b2c2/flexcop_ibi_value_le.h b/drivers/media/dvb/b2c2/flexcop_ibi_value_le.h
index 49f2315b6e58..c75830d7d942 100644
--- a/drivers/media/dvb/b2c2/flexcop_ibi_value_le.h
+++ b/drivers/media/dvb/b2c2/flexcop_ibi_value_le.h
@@ -1,10 +1,7 @@
1/* This file is part of linux driver for digital TV devices equipped with B2C2 FlexcopII(b)/III 1/* Linux driver for digital TV devices equipped with B2C2 FlexcopII(b)/III
2 *
3 * register descriptions 2 * register descriptions
4 * 3 * see flexcop.c for copyright information
5 * see flexcop.c for copyright information.
6 */ 4 */
7
8/* This file is automatically generated, do not edit things here. */ 5/* This file is automatically generated, do not edit things here. */
9#ifndef __FLEXCOP_IBI_VALUE_INCLUDED__ 6#ifndef __FLEXCOP_IBI_VALUE_INCLUDED__
10#define __FLEXCOP_IBI_VALUE_INCLUDED__ 7#define __FLEXCOP_IBI_VALUE_INCLUDED__
diff --git a/drivers/media/dvb/bt8xx/Kconfig b/drivers/media/dvb/bt8xx/Kconfig
index 27edb0ece587..8668e634c7ec 100644
--- a/drivers/media/dvb/bt8xx/Kconfig
+++ b/drivers/media/dvb/bt8xx/Kconfig
@@ -8,7 +8,7 @@ config DVB_BT8XX
8 select DVB_OR51211 if !DVB_FE_CUSTOMISE 8 select DVB_OR51211 if !DVB_FE_CUSTOMISE
9 select DVB_LGDT330X if !DVB_FE_CUSTOMISE 9 select DVB_LGDT330X if !DVB_FE_CUSTOMISE
10 select DVB_ZL10353 if !DVB_FE_CUSTOMISE 10 select DVB_ZL10353 if !DVB_FE_CUSTOMISE
11 select MEDIA_TUNER_SIMPLE if !MEDIA_TUNER_CUSTOMIZE 11 select MEDIA_TUNER_SIMPLE if !MEDIA_TUNER_CUSTOMISE
12 help 12 help
13 Support for PCI cards based on the Bt8xx PCI bridge. Examples are 13 Support for PCI cards based on the Bt8xx PCI bridge. Examples are
14 the Nebula cards, the Pinnacle PCTV cards, the Twinhan DST cards, 14 the Nebula cards, the Pinnacle PCTV cards, the Twinhan DST cards,
diff --git a/drivers/media/dvb/bt8xx/dst_ca.c b/drivers/media/dvb/bt8xx/dst_ca.c
index 0258451423ad..4601b059b2b2 100644
--- a/drivers/media/dvb/bt8xx/dst_ca.c
+++ b/drivers/media/dvb/bt8xx/dst_ca.c
@@ -552,16 +552,19 @@ free_mem_and_exit:
552 return result; 552 return result;
553} 553}
554 554
555static int dst_ca_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long ioctl_arg) 555static long dst_ca_ioctl(struct file *file, unsigned int cmd, unsigned long ioctl_arg)
556{ 556{
557 struct dvb_device* dvbdev = (struct dvb_device*) file->private_data; 557 struct dvb_device *dvbdev;
558 struct dst_state* state = (struct dst_state*) dvbdev->priv; 558 struct dst_state *state;
559 struct ca_slot_info *p_ca_slot_info; 559 struct ca_slot_info *p_ca_slot_info;
560 struct ca_caps *p_ca_caps; 560 struct ca_caps *p_ca_caps;
561 struct ca_msg *p_ca_message; 561 struct ca_msg *p_ca_message;
562 void __user *arg = (void __user *)ioctl_arg; 562 void __user *arg = (void __user *)ioctl_arg;
563 int result = 0; 563 int result = 0;
564 564
565 lock_kernel();
566 dvbdev = (struct dvb_device *)file->private_data;
567 state = (struct dst_state *)dvbdev->priv;
565 p_ca_message = kmalloc(sizeof (struct ca_msg), GFP_KERNEL); 568 p_ca_message = kmalloc(sizeof (struct ca_msg), GFP_KERNEL);
566 p_ca_slot_info = kmalloc(sizeof (struct ca_slot_info), GFP_KERNEL); 569 p_ca_slot_info = kmalloc(sizeof (struct ca_slot_info), GFP_KERNEL);
567 p_ca_caps = kmalloc(sizeof (struct ca_caps), GFP_KERNEL); 570 p_ca_caps = kmalloc(sizeof (struct ca_caps), GFP_KERNEL);
@@ -647,6 +650,7 @@ static int dst_ca_ioctl(struct inode *inode, struct file *file, unsigned int cmd
647 kfree (p_ca_slot_info); 650 kfree (p_ca_slot_info);
648 kfree (p_ca_caps); 651 kfree (p_ca_caps);
649 652
653 unlock_kernel();
650 return result; 654 return result;
651} 655}
652 656
@@ -682,9 +686,9 @@ static ssize_t dst_ca_write(struct file *file, const char __user *buffer, size_t
682 return 0; 686 return 0;
683} 687}
684 688
685static struct file_operations dst_ca_fops = { 689static const struct file_operations dst_ca_fops = {
686 .owner = THIS_MODULE, 690 .owner = THIS_MODULE,
687 .ioctl = dst_ca_ioctl, 691 .unlocked_ioctl = dst_ca_ioctl,
688 .open = dst_ca_open, 692 .open = dst_ca_open,
689 .release = dst_ca_release, 693 .release = dst_ca_release,
690 .read = dst_ca_read, 694 .read = dst_ca_read,
diff --git a/drivers/media/dvb/bt8xx/dvb-bt8xx.c b/drivers/media/dvb/bt8xx/dvb-bt8xx.c
index 48762a2b9e42..b1857c19bbd2 100644
--- a/drivers/media/dvb/bt8xx/dvb-bt8xx.c
+++ b/drivers/media/dvb/bt8xx/dvb-bt8xx.c
@@ -814,7 +814,7 @@ static int __devinit dvb_bt8xx_probe(struct bttv_sub_device *sub)
814 814
815 mutex_init(&card->lock); 815 mutex_init(&card->lock);
816 card->bttv_nr = sub->core->nr; 816 card->bttv_nr = sub->core->nr;
817 strncpy(card->card_name, sub->core->name, sizeof(sub->core->name)); 817 strlcpy(card->card_name, sub->core->v4l2_dev.name, sizeof(card->card_name));
818 card->i2c_adapter = &sub->core->i2c_adap; 818 card->i2c_adapter = &sub->core->i2c_adap;
819 819
820 switch(sub->core->type) { 820 switch(sub->core->type) {
diff --git a/drivers/media/dvb/dm1105/Kconfig b/drivers/media/dvb/dm1105/Kconfig
index 43f4d44edca6..de3eeb0a8d6e 100644
--- a/drivers/media/dvb/dm1105/Kconfig
+++ b/drivers/media/dvb/dm1105/Kconfig
@@ -8,6 +8,7 @@ config DVB_DM1105
8 select DVB_STB6000 if !DVB_FE_CUSTOMISE 8 select DVB_STB6000 if !DVB_FE_CUSTOMISE
9 select DVB_CX24116 if !DVB_FE_CUSTOMISE 9 select DVB_CX24116 if !DVB_FE_CUSTOMISE
10 select DVB_SI21XX if !DVB_FE_CUSTOMISE 10 select DVB_SI21XX if !DVB_FE_CUSTOMISE
11 select VIDEO_IR
11 help 12 help
12 Support for cards based on the SDMC DM1105 PCI chip like 13 Support for cards based on the SDMC DM1105 PCI chip like
13 DvbWorld 2002 14 DvbWorld 2002
diff --git a/drivers/media/dvb/dm1105/dm1105.c b/drivers/media/dvb/dm1105/dm1105.c
index f48f73aff195..5b20cf5a29f0 100644
--- a/drivers/media/dvb/dm1105/dm1105.c
+++ b/drivers/media/dvb/dm1105/dm1105.c
@@ -156,46 +156,12 @@ MODULE_PARM_DESC(ir_debug, "enable debugging information for IR decoding");
156 156
157DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); 157DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
158 158
159static u16 ir_codes_dm1105_nec[128] = {
160 [0x0a] = KEY_Q, /*power*/
161 [0x0c] = KEY_M, /*mute*/
162 [0x11] = KEY_1,
163 [0x12] = KEY_2,
164 [0x13] = KEY_3,
165 [0x14] = KEY_4,
166 [0x15] = KEY_5,
167 [0x16] = KEY_6,
168 [0x17] = KEY_7,
169 [0x18] = KEY_8,
170 [0x19] = KEY_9,
171 [0x10] = KEY_0,
172 [0x1c] = KEY_PAGEUP, /*ch+*/
173 [0x0f] = KEY_PAGEDOWN, /*ch-*/
174 [0x1a] = KEY_O, /*vol+*/
175 [0x0e] = KEY_Z, /*vol-*/
176 [0x04] = KEY_R, /*rec*/
177 [0x09] = KEY_D, /*fav*/
178 [0x08] = KEY_BACKSPACE, /*rewind*/
179 [0x07] = KEY_A, /*fast*/
180 [0x0b] = KEY_P, /*pause*/
181 [0x02] = KEY_ESC, /*cancel*/
182 [0x03] = KEY_G, /*tab*/
183 [0x00] = KEY_UP, /*up*/
184 [0x1f] = KEY_ENTER, /*ok*/
185 [0x01] = KEY_DOWN, /*down*/
186 [0x05] = KEY_C, /*cap*/
187 [0x06] = KEY_S, /*stop*/
188 [0x40] = KEY_F, /*full*/
189 [0x1e] = KEY_W, /*tvmode*/
190 [0x1b] = KEY_B, /*recall*/
191};
192
193/* infrared remote control */ 159/* infrared remote control */
194struct infrared { 160struct infrared {
195 u16 key_map[128];
196 struct input_dev *input_dev; 161 struct input_dev *input_dev;
162 struct ir_input_state ir;
197 char input_phys[32]; 163 char input_phys[32];
198 struct tasklet_struct ir_tasklet; 164 struct work_struct work;
199 u32 ir_command; 165 u32 ir_command;
200}; 166};
201 167
@@ -220,10 +186,14 @@ struct dm1105dvb {
220 /* i2c */ 186 /* i2c */
221 struct i2c_adapter i2c_adap; 187 struct i2c_adapter i2c_adap;
222 188
189 /* irq */
190 struct work_struct work;
191
223 /* dma */ 192 /* dma */
224 dma_addr_t dma_addr; 193 dma_addr_t dma_addr;
225 unsigned char *ts_buf; 194 unsigned char *ts_buf;
226 u32 wrp; 195 u32 wrp;
196 u32 nextwrp;
227 u32 buffer_size; 197 u32 buffer_size;
228 unsigned int PacketErrorCount; 198 unsigned int PacketErrorCount;
229 unsigned int dmarst; 199 unsigned int dmarst;
@@ -233,8 +203,6 @@ struct dm1105dvb {
233 203
234#define dm_io_mem(reg) ((unsigned long)(&dm1105dvb->io_mem[reg])) 204#define dm_io_mem(reg) ((unsigned long)(&dm1105dvb->io_mem[reg]))
235 205
236static struct dm1105dvb *dm1105dvb_local;
237
238static int dm1105_i2c_xfer(struct i2c_adapter *i2c_adap, 206static int dm1105_i2c_xfer(struct i2c_adapter *i2c_adap,
239 struct i2c_msg *msgs, int num) 207 struct i2c_msg *msgs, int num)
240{ 208{
@@ -407,38 +375,61 @@ static int dm1105dvb_stop_feed(struct dvb_demux_feed *f)
407 return 0; 375 return 0;
408} 376}
409 377
410/* ir tasklet */ 378/* ir work handler */
411static void dm1105_emit_key(unsigned long parm) 379static void dm1105_emit_key(struct work_struct *work)
412{ 380{
413 struct infrared *ir = (struct infrared *) parm; 381 struct infrared *ir = container_of(work, struct infrared, work);
414 u32 ircom = ir->ir_command; 382 u32 ircom = ir->ir_command;
415 u8 data; 383 u8 data;
416 u16 keycode; 384
385 if (ir_debug)
386 printk(KERN_INFO "%s: received byte 0x%04x\n", __func__, ircom);
417 387
418 data = (ircom >> 8) & 0x7f; 388 data = (ircom >> 8) & 0x7f;
419 389
420 input_event(ir->input_dev, EV_MSC, MSC_RAW, (0x0000f8 << 16) | data); 390 ir_input_keydown(ir->input_dev, &ir->ir, data, data);
421 input_event(ir->input_dev, EV_MSC, MSC_SCAN, data); 391 ir_input_nokey(ir->input_dev, &ir->ir);
422 keycode = ir->key_map[data]; 392}
423 393
424 if (!keycode) 394/* work handler */
425 return; 395static void dm1105_dmx_buffer(struct work_struct *work)
396{
397 struct dm1105dvb *dm1105dvb =
398 container_of(work, struct dm1105dvb, work);
399 unsigned int nbpackets;
400 u32 oldwrp = dm1105dvb->wrp;
401 u32 nextwrp = dm1105dvb->nextwrp;
402
403 if (!((dm1105dvb->ts_buf[oldwrp] == 0x47) &&
404 (dm1105dvb->ts_buf[oldwrp + 188] == 0x47) &&
405 (dm1105dvb->ts_buf[oldwrp + 188 * 2] == 0x47))) {
406 dm1105dvb->PacketErrorCount++;
407 /* bad packet found */
408 if ((dm1105dvb->PacketErrorCount >= 2) &&
409 (dm1105dvb->dmarst == 0)) {
410 outb(1, dm_io_mem(DM1105_RST));
411 dm1105dvb->wrp = 0;
412 dm1105dvb->PacketErrorCount = 0;
413 dm1105dvb->dmarst = 0;
414 return;
415 }
416 }
426 417
427 input_event(ir->input_dev, EV_KEY, keycode, 1); 418 if (nextwrp < oldwrp) {
428 input_sync(ir->input_dev); 419 memcpy(dm1105dvb->ts_buf + dm1105dvb->buffer_size,
429 input_event(ir->input_dev, EV_KEY, keycode, 0); 420 dm1105dvb->ts_buf, nextwrp);
430 input_sync(ir->input_dev); 421 nbpackets = ((dm1105dvb->buffer_size - oldwrp) + nextwrp) / 188;
422 } else
423 nbpackets = (nextwrp - oldwrp) / 188;
431 424
425 dm1105dvb->wrp = nextwrp;
426 dvb_dmx_swfilter_packets(&dm1105dvb->demux,
427 &dm1105dvb->ts_buf[oldwrp], nbpackets);
432} 428}
433 429
434static irqreturn_t dm1105dvb_irq(int irq, void *dev_id) 430static irqreturn_t dm1105dvb_irq(int irq, void *dev_id)
435{ 431{
436 struct dm1105dvb *dm1105dvb = dev_id; 432 struct dm1105dvb *dm1105dvb = dev_id;
437 unsigned int piece;
438 unsigned int nbpackets;
439 u32 command;
440 u32 nextwrp;
441 u32 oldwrp;
442 433
443 /* Read-Write INSTS Ack's Interrupt for DM1105 chip 16.03.2008 */ 434 /* Read-Write INSTS Ack's Interrupt for DM1105 chip 16.03.2008 */
444 unsigned int intsts = inb(dm_io_mem(DM1105_INTSTS)); 435 unsigned int intsts = inb(dm_io_mem(DM1105_INTSTS));
@@ -447,71 +438,25 @@ static irqreturn_t dm1105dvb_irq(int irq, void *dev_id)
447 switch (intsts) { 438 switch (intsts) {
448 case INTSTS_TSIRQ: 439 case INTSTS_TSIRQ:
449 case (INTSTS_TSIRQ | INTSTS_IR): 440 case (INTSTS_TSIRQ | INTSTS_IR):
450 nextwrp = inl(dm_io_mem(DM1105_WRP)) - 441 dm1105dvb->nextwrp = inl(dm_io_mem(DM1105_WRP)) -
451 inl(dm_io_mem(DM1105_STADR)) ; 442 inl(dm_io_mem(DM1105_STADR));
452 oldwrp = dm1105dvb->wrp; 443 schedule_work(&dm1105dvb->work);
453 spin_lock(&dm1105dvb->lock);
454 if (!((dm1105dvb->ts_buf[oldwrp] == 0x47) &&
455 (dm1105dvb->ts_buf[oldwrp + 188] == 0x47) &&
456 (dm1105dvb->ts_buf[oldwrp + 188 * 2] == 0x47))) {
457 dm1105dvb->PacketErrorCount++;
458 /* bad packet found */
459 if ((dm1105dvb->PacketErrorCount >= 2) &&
460 (dm1105dvb->dmarst == 0)) {
461 outb(1, dm_io_mem(DM1105_RST));
462 dm1105dvb->wrp = 0;
463 dm1105dvb->PacketErrorCount = 0;
464 dm1105dvb->dmarst = 0;
465 spin_unlock(&dm1105dvb->lock);
466 return IRQ_HANDLED;
467 }
468 }
469 if (nextwrp < oldwrp) {
470 piece = dm1105dvb->buffer_size - oldwrp;
471 memcpy(dm1105dvb->ts_buf + dm1105dvb->buffer_size, dm1105dvb->ts_buf, nextwrp);
472 nbpackets = (piece + nextwrp)/188;
473 } else {
474 nbpackets = (nextwrp - oldwrp)/188;
475 }
476 dvb_dmx_swfilter_packets(&dm1105dvb->demux, &dm1105dvb->ts_buf[oldwrp], nbpackets);
477 dm1105dvb->wrp = nextwrp;
478 spin_unlock(&dm1105dvb->lock);
479 break; 444 break;
480 case INTSTS_IR: 445 case INTSTS_IR:
481 command = inl(dm_io_mem(DM1105_IRCODE)); 446 dm1105dvb->ir.ir_command = inl(dm_io_mem(DM1105_IRCODE));
482 if (ir_debug) 447 schedule_work(&dm1105dvb->ir.work);
483 printk("dm1105: received byte 0x%04x\n", command);
484
485 dm1105dvb->ir.ir_command = command;
486 tasklet_schedule(&dm1105dvb->ir.ir_tasklet);
487 break; 448 break;
488 } 449 }
489 return IRQ_HANDLED;
490
491
492}
493
494/* register with input layer */
495static void input_register_keys(struct infrared *ir)
496{
497 int i;
498 450
499 memset(ir->input_dev->keybit, 0, sizeof(ir->input_dev->keybit)); 451 return IRQ_HANDLED;
500
501 for (i = 0; i < ARRAY_SIZE(ir->key_map); i++)
502 set_bit(ir->key_map[i], ir->input_dev->keybit);
503
504 ir->input_dev->keycode = ir->key_map;
505 ir->input_dev->keycodesize = sizeof(ir->key_map[0]);
506 ir->input_dev->keycodemax = ARRAY_SIZE(ir->key_map);
507} 452}
508 453
509int __devinit dm1105_ir_init(struct dm1105dvb *dm1105) 454int __devinit dm1105_ir_init(struct dm1105dvb *dm1105)
510{ 455{
511 struct input_dev *input_dev; 456 struct input_dev *input_dev;
512 int err; 457 IR_KEYTAB_TYPE *ir_codes = ir_codes_dm1105_nec;
513 458 int ir_type = IR_TYPE_OTHER;
514 dm1105dvb_local = dm1105; 459 int err = -ENOMEM;
515 460
516 input_dev = input_allocate_device(); 461 input_dev = input_allocate_device();
517 if (!input_dev) 462 if (!input_dev)
@@ -521,12 +466,11 @@ int __devinit dm1105_ir_init(struct dm1105dvb *dm1105)
521 snprintf(dm1105->ir.input_phys, sizeof(dm1105->ir.input_phys), 466 snprintf(dm1105->ir.input_phys, sizeof(dm1105->ir.input_phys),
522 "pci-%s/ir0", pci_name(dm1105->pdev)); 467 "pci-%s/ir0", pci_name(dm1105->pdev));
523 468
524 input_dev->evbit[0] = BIT(EV_KEY); 469 ir_input_init(input_dev, &dm1105->ir.ir, ir_type, ir_codes);
525 input_dev->name = "DVB on-card IR receiver"; 470 input_dev->name = "DVB on-card IR receiver";
526
527 input_dev->phys = dm1105->ir.input_phys; 471 input_dev->phys = dm1105->ir.input_phys;
528 input_dev->id.bustype = BUS_PCI; 472 input_dev->id.bustype = BUS_PCI;
529 input_dev->id.version = 2; 473 input_dev->id.version = 1;
530 if (dm1105->pdev->subsystem_vendor) { 474 if (dm1105->pdev->subsystem_vendor) {
531 input_dev->id.vendor = dm1105->pdev->subsystem_vendor; 475 input_dev->id.vendor = dm1105->pdev->subsystem_vendor;
532 input_dev->id.product = dm1105->pdev->subsystem_device; 476 input_dev->id.product = dm1105->pdev->subsystem_device;
@@ -534,25 +478,22 @@ int __devinit dm1105_ir_init(struct dm1105dvb *dm1105)
534 input_dev->id.vendor = dm1105->pdev->vendor; 478 input_dev->id.vendor = dm1105->pdev->vendor;
535 input_dev->id.product = dm1105->pdev->device; 479 input_dev->id.product = dm1105->pdev->device;
536 } 480 }
481
537 input_dev->dev.parent = &dm1105->pdev->dev; 482 input_dev->dev.parent = &dm1105->pdev->dev;
538 /* initial keymap */ 483
539 memcpy(dm1105->ir.key_map, ir_codes_dm1105_nec, sizeof dm1105->ir.key_map); 484 INIT_WORK(&dm1105->ir.work, dm1105_emit_key);
540 input_register_keys(&dm1105->ir); 485
541 err = input_register_device(input_dev); 486 err = input_register_device(input_dev);
542 if (err) { 487 if (err) {
543 input_free_device(input_dev); 488 input_free_device(input_dev);
544 return err; 489 return err;
545 } 490 }
546 491
547 tasklet_init(&dm1105->ir.ir_tasklet, dm1105_emit_key, (unsigned long) &dm1105->ir);
548
549 return 0; 492 return 0;
550} 493}
551 494
552
553void __devexit dm1105_ir_exit(struct dm1105dvb *dm1105) 495void __devexit dm1105_ir_exit(struct dm1105dvb *dm1105)
554{ 496{
555 tasklet_kill(&dm1105->ir.ir_tasklet);
556 input_unregister_device(dm1105->ir.input_dev); 497 input_unregister_device(dm1105->ir.input_dev);
557 498
558} 499}
@@ -710,7 +651,7 @@ static int __devinit dm1105_probe(struct pci_dev *pdev,
710 651
711 dm1105dvb = kzalloc(sizeof(struct dm1105dvb), GFP_KERNEL); 652 dm1105dvb = kzalloc(sizeof(struct dm1105dvb), GFP_KERNEL);
712 if (!dm1105dvb) 653 if (!dm1105dvb)
713 goto out; 654 return -ENOMEM;
714 655
715 dm1105dvb->pdev = pdev; 656 dm1105dvb->pdev = pdev;
716 dm1105dvb->buffer_size = 5 * DM1105_DMA_BYTES; 657 dm1105dvb->buffer_size = 5 * DM1105_DMA_BYTES;
@@ -740,13 +681,9 @@ static int __devinit dm1105_probe(struct pci_dev *pdev,
740 spin_lock_init(&dm1105dvb->lock); 681 spin_lock_init(&dm1105dvb->lock);
741 pci_set_drvdata(pdev, dm1105dvb); 682 pci_set_drvdata(pdev, dm1105dvb);
742 683
743 ret = request_irq(pdev->irq, dm1105dvb_irq, IRQF_SHARED, DRIVER_NAME, dm1105dvb);
744 if (ret < 0)
745 goto err_pci_iounmap;
746
747 ret = dm1105dvb_hw_init(dm1105dvb); 684 ret = dm1105dvb_hw_init(dm1105dvb);
748 if (ret < 0) 685 if (ret < 0)
749 goto err_free_irq; 686 goto err_pci_iounmap;
750 687
751 /* i2c */ 688 /* i2c */
752 i2c_set_adapdata(&dm1105dvb->i2c_adap, dm1105dvb); 689 i2c_set_adapdata(&dm1105dvb->i2c_adap, dm1105dvb);
@@ -813,8 +750,15 @@ static int __devinit dm1105_probe(struct pci_dev *pdev,
813 750
814 dvb_net_init(dvb_adapter, &dm1105dvb->dvbnet, dmx); 751 dvb_net_init(dvb_adapter, &dm1105dvb->dvbnet, dmx);
815 dm1105_ir_init(dm1105dvb); 752 dm1105_ir_init(dm1105dvb);
816out: 753
817 return ret; 754 INIT_WORK(&dm1105dvb->work, dm1105_dmx_buffer);
755
756 ret = request_irq(pdev->irq, dm1105dvb_irq, IRQF_SHARED,
757 DRIVER_NAME, dm1105dvb);
758 if (ret < 0)
759 goto err_free_irq;
760
761 return 0;
818 762
819err_disconnect_frontend: 763err_disconnect_frontend:
820 dmx->disconnect_frontend(dmx); 764 dmx->disconnect_frontend(dmx);
@@ -843,7 +787,7 @@ err_pci_disable_device:
843err_kfree: 787err_kfree:
844 pci_set_drvdata(pdev, NULL); 788 pci_set_drvdata(pdev, NULL);
845 kfree(dm1105dvb); 789 kfree(dm1105dvb);
846 goto out; 790 return ret;
847} 791}
848 792
849static void __devexit dm1105_remove(struct pci_dev *pdev) 793static void __devexit dm1105_remove(struct pci_dev *pdev)
diff --git a/drivers/media/dvb/dvb-core/dmxdev.c b/drivers/media/dvb/dvb-core/dmxdev.c
index 069d847ba887..c35fbb8d8f4a 100644
--- a/drivers/media/dvb/dvb-core/dmxdev.c
+++ b/drivers/media/dvb/dvb-core/dmxdev.c
@@ -1024,7 +1024,7 @@ static int dvb_demux_release(struct inode *inode, struct file *file)
1024 return ret; 1024 return ret;
1025} 1025}
1026 1026
1027static struct file_operations dvb_demux_fops = { 1027static const struct file_operations dvb_demux_fops = {
1028 .owner = THIS_MODULE, 1028 .owner = THIS_MODULE,
1029 .read = dvb_demux_read, 1029 .read = dvb_demux_read,
1030 .ioctl = dvb_demux_ioctl, 1030 .ioctl = dvb_demux_ioctl,
diff --git a/drivers/media/dvb/dvb-core/dvb_ca_en50221.c b/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
index 7e3aeaa7370f..cb22da53bfb0 100644
--- a/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
+++ b/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
@@ -1607,7 +1607,7 @@ static unsigned int dvb_ca_en50221_io_poll(struct file *file, poll_table * wait)
1607EXPORT_SYMBOL(dvb_ca_en50221_init); 1607EXPORT_SYMBOL(dvb_ca_en50221_init);
1608 1608
1609 1609
1610static struct file_operations dvb_ca_fops = { 1610static const struct file_operations dvb_ca_fops = {
1611 .owner = THIS_MODULE, 1611 .owner = THIS_MODULE,
1612 .read = dvb_ca_en50221_io_read, 1612 .read = dvb_ca_en50221_io_read,
1613 .write = dvb_ca_en50221_io_write, 1613 .write = dvb_ca_en50221_io_write,
diff --git a/drivers/media/dvb/dvb-core/dvb_frontend.c b/drivers/media/dvb/dvb-core/dvb_frontend.c
index 8dcb3fbf7acd..ebc78157b9b8 100644
--- a/drivers/media/dvb/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb/dvb-core/dvb_frontend.c
@@ -1875,7 +1875,7 @@ static int dvb_frontend_release(struct inode *inode, struct file *file)
1875 return ret; 1875 return ret;
1876} 1876}
1877 1877
1878static struct file_operations dvb_frontend_fops = { 1878static const struct file_operations dvb_frontend_fops = {
1879 .owner = THIS_MODULE, 1879 .owner = THIS_MODULE,
1880 .ioctl = dvb_generic_ioctl, 1880 .ioctl = dvb_generic_ioctl,
1881 .poll = dvb_frontend_poll, 1881 .poll = dvb_frontend_poll,
diff --git a/drivers/media/dvb/dvb-core/dvb_net.c b/drivers/media/dvb/dvb-core/dvb_net.c
index f6ba8468858e..8280f8d66a38 100644
--- a/drivers/media/dvb/dvb-core/dvb_net.c
+++ b/drivers/media/dvb/dvb-core/dvb_net.c
@@ -1459,7 +1459,7 @@ static int dvb_net_close(struct inode *inode, struct file *file)
1459} 1459}
1460 1460
1461 1461
1462static struct file_operations dvb_net_fops = { 1462static const struct file_operations dvb_net_fops = {
1463 .owner = THIS_MODULE, 1463 .owner = THIS_MODULE,
1464 .ioctl = dvb_net_ioctl, 1464 .ioctl = dvb_net_ioctl,
1465 .open = dvb_generic_open, 1465 .open = dvb_generic_open,
diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
index 6a32680dbb1b..a454ee8f1e43 100644
--- a/drivers/media/dvb/dvb-core/dvbdev.c
+++ b/drivers/media/dvb/dvb-core/dvbdev.c
@@ -228,8 +228,8 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
228 dvbdev->fops = dvbdevfops; 228 dvbdev->fops = dvbdevfops;
229 init_waitqueue_head (&dvbdev->wait_queue); 229 init_waitqueue_head (&dvbdev->wait_queue);
230 230
231 memcpy(dvbdev->fops, template->fops, sizeof(struct file_operations)); 231 memcpy(dvbdevfops, template->fops, sizeof(struct file_operations));
232 dvbdev->fops->owner = adap->module; 232 dvbdevfops->owner = adap->module;
233 233
234 list_add_tail (&dvbdev->list_head, &adap->device_list); 234 list_add_tail (&dvbdev->list_head, &adap->device_list);
235 235
diff --git a/drivers/media/dvb/dvb-core/dvbdev.h b/drivers/media/dvb/dvb-core/dvbdev.h
index dca49cf962e8..79927305e84d 100644
--- a/drivers/media/dvb/dvb-core/dvbdev.h
+++ b/drivers/media/dvb/dvb-core/dvbdev.h
@@ -71,7 +71,7 @@ struct dvb_adapter {
71 71
72struct dvb_device { 72struct dvb_device {
73 struct list_head list_head; 73 struct list_head list_head;
74 struct file_operations *fops; 74 const struct file_operations *fops;
75 struct dvb_adapter *adapter; 75 struct dvb_adapter *adapter;
76 int type; 76 int type;
77 int minor; 77 int minor;
diff --git a/drivers/media/dvb/dvb-usb/Kconfig b/drivers/media/dvb/dvb-usb/Kconfig
index 49f7b20c25d6..6103caad1644 100644
--- a/drivers/media/dvb/dvb-usb/Kconfig
+++ b/drivers/media/dvb/dvb-usb/Kconfig
@@ -25,7 +25,7 @@ config DVB_USB_A800
25 depends on DVB_USB 25 depends on DVB_USB
26 select DVB_DIB3000MC 26 select DVB_DIB3000MC
27 select DVB_PLL if !DVB_FE_CUSTOMISE 27 select DVB_PLL if !DVB_FE_CUSTOMISE
28 select MEDIA_TUNER_MT2060 if !MEDIA_TUNER_CUSTOMIZE 28 select MEDIA_TUNER_MT2060 if !MEDIA_TUNER_CUSTOMISE
29 help 29 help
30 Say Y here to support the AVerMedia AverTV DVB-T USB 2.0 (A800) receiver. 30 Say Y here to support the AVerMedia AverTV DVB-T USB 2.0 (A800) receiver.
31 31
@@ -34,7 +34,7 @@ config DVB_USB_DIBUSB_MB
34 depends on DVB_USB 34 depends on DVB_USB
35 select DVB_PLL if !DVB_FE_CUSTOMISE 35 select DVB_PLL if !DVB_FE_CUSTOMISE
36 select DVB_DIB3000MB 36 select DVB_DIB3000MB
37 select MEDIA_TUNER_MT2060 if !MEDIA_TUNER_CUSTOMIZE 37 select MEDIA_TUNER_MT2060 if !MEDIA_TUNER_CUSTOMISE
38 help 38 help
39 Support for USB 1.1 and 2.0 DVB-T receivers based on reference designs made by 39 Support for USB 1.1 and 2.0 DVB-T receivers based on reference designs made by
40 DiBcom (<http://www.dibcom.fr>) equipped with a DiB3000M-B demodulator. 40 DiBcom (<http://www.dibcom.fr>) equipped with a DiB3000M-B demodulator.
@@ -55,7 +55,7 @@ config DVB_USB_DIBUSB_MC
55 tristate "DiBcom USB DVB-T devices (based on the DiB3000M-C/P) (see help for device list)" 55 tristate "DiBcom USB DVB-T devices (based on the DiB3000M-C/P) (see help for device list)"
56 depends on DVB_USB 56 depends on DVB_USB
57 select DVB_DIB3000MC 57 select DVB_DIB3000MC
58 select MEDIA_TUNER_MT2060 if !MEDIA_TUNER_CUSTOMIZE 58 select MEDIA_TUNER_MT2060 if !MEDIA_TUNER_CUSTOMISE
59 help 59 help
60 Support for USB2.0 DVB-T receivers based on reference designs made by 60 Support for USB2.0 DVB-T receivers based on reference designs made by
61 DiBcom (<http://www.dibcom.fr>) equipped with a DiB3000M-C/P demodulator. 61 DiBcom (<http://www.dibcom.fr>) equipped with a DiB3000M-C/P demodulator.
@@ -69,15 +69,17 @@ config DVB_USB_DIBUSB_MC
69config DVB_USB_DIB0700 69config DVB_USB_DIB0700
70 tristate "DiBcom DiB0700 USB DVB devices (see help for supported devices)" 70 tristate "DiBcom DiB0700 USB DVB devices (see help for supported devices)"
71 depends on DVB_USB 71 depends on DVB_USB
72 select DVB_DIB7000P 72 select DVB_DIB7000P if !DVB_FE_CUSTOMISE
73 select DVB_DIB7000M 73 select DVB_DIB7000M if !DVB_FE_CUSTOMISE
74 select DVB_DIB3000MC 74 select DVB_DIB3000MC if !DVB_FE_CUSTOMISE
75 select DVB_S5H1411 if !DVB_FE_CUSTOMISE 75 select DVB_S5H1411 if !DVB_FE_CUSTOMISE
76 select DVB_TUNER_DIB0070 76 select DVB_LGDT3305 if !DVB_FE_CUSTOMISE
77 select MEDIA_TUNER_MT2060 if !MEDIA_TUNER_CUSTOMIZE 77 select DVB_TUNER_DIB0070 if !DVB_FE_CUSTOMISE
78 select MEDIA_TUNER_MT2266 if !MEDIA_TUNER_CUSTOMIZE 78 select MEDIA_TUNER_MT2060 if !MEDIA_TUNER_CUSTOMISE
79 select MEDIA_TUNER_XC2028 if !MEDIA_TUNER_CUSTOMIZE 79 select MEDIA_TUNER_MT2266 if !MEDIA_TUNER_CUSTOMISE
80 select MEDIA_TUNER_XC5000 if !MEDIA_TUNER_CUSTOMIZE 80 select MEDIA_TUNER_XC2028 if !MEDIA_TUNER_CUSTOMISE
81 select MEDIA_TUNER_XC5000 if !MEDIA_TUNER_CUSTOMISE
82 select MEDIA_TUNER_MXL5007T if !MEDIA_TUNER_CUSTOMISE
81 help 83 help
82 Support for USB2.0/1.1 DVB receivers based on the DiB0700 USB bridge. The 84 Support for USB2.0/1.1 DVB receivers based on the DiB0700 USB bridge. The
83 USB bridge is also present in devices having the DiB7700 DVB-T-USB 85 USB bridge is also present in devices having the DiB7700 DVB-T-USB
@@ -95,7 +97,8 @@ config DVB_USB_UMT_010
95 depends on DVB_USB 97 depends on DVB_USB
96 select DVB_PLL if !DVB_FE_CUSTOMISE 98 select DVB_PLL if !DVB_FE_CUSTOMISE
97 select DVB_DIB3000MC 99 select DVB_DIB3000MC
98 select MEDIA_TUNER_MT2060 if !MEDIA_TUNER_CUSTOMIZE 100 select MEDIA_TUNER_MT2060 if !MEDIA_TUNER_CUSTOMISE
101 select DVB_MT352 if !DVB_FE_CUSTOMISE
99 help 102 help
100 Say Y here to support the HanfTek UMT-010 USB2.0 stick-sized DVB-T receiver. 103 Say Y here to support the HanfTek UMT-010 USB2.0 stick-sized DVB-T receiver.
101 104
@@ -108,10 +111,11 @@ config DVB_USB_CXUSB
108 select DVB_MT352 if !DVB_FE_CUSTOMISE 111 select DVB_MT352 if !DVB_FE_CUSTOMISE
109 select DVB_ZL10353 if !DVB_FE_CUSTOMISE 112 select DVB_ZL10353 if !DVB_FE_CUSTOMISE
110 select DVB_DIB7000P if !DVB_FE_CUSTOMISE 113 select DVB_DIB7000P if !DVB_FE_CUSTOMISE
114 select DVB_LGS8GL5 if !DVB_FE_CUSTOMISE
111 select DVB_TUNER_DIB0070 if !DVB_FE_CUSTOMISE 115 select DVB_TUNER_DIB0070 if !DVB_FE_CUSTOMISE
112 select MEDIA_TUNER_SIMPLE if !MEDIA_TUNER_CUSTOMIZE 116 select MEDIA_TUNER_SIMPLE if !MEDIA_TUNER_CUSTOMISE
113 select MEDIA_TUNER_XC2028 if !MEDIA_TUNER_CUSTOMIZE 117 select MEDIA_TUNER_XC2028 if !MEDIA_TUNER_CUSTOMISE
114 select MEDIA_TUNER_MXL5005S if !MEDIA_TUNER_CUSTOMIZE 118 select MEDIA_TUNER_MXL5005S if !MEDIA_TUNER_CUSTOMISE
115 help 119 help
116 Say Y here to support the Conexant USB2.0 hybrid reference design. 120 Say Y here to support the Conexant USB2.0 hybrid reference design.
117 Currently, only DVB and ATSC modes are supported, analog mode 121 Currently, only DVB and ATSC modes are supported, analog mode
@@ -125,8 +129,8 @@ config DVB_USB_M920X
125 depends on DVB_USB 129 depends on DVB_USB
126 select DVB_MT352 if !DVB_FE_CUSTOMISE 130 select DVB_MT352 if !DVB_FE_CUSTOMISE
127 select DVB_TDA1004X if !DVB_FE_CUSTOMISE 131 select DVB_TDA1004X if !DVB_FE_CUSTOMISE
128 select MEDIA_TUNER_QT1010 if !MEDIA_TUNER_CUSTOMIZE 132 select MEDIA_TUNER_QT1010 if !MEDIA_TUNER_CUSTOMISE
129 select MEDIA_TUNER_TDA827X if !MEDIA_TUNER_CUSTOMIZE 133 select MEDIA_TUNER_TDA827X if !MEDIA_TUNER_CUSTOMISE
130 help 134 help
131 Say Y here to support the MSI Mega Sky 580 USB2.0 DVB-T receiver. 135 Say Y here to support the MSI Mega Sky 580 USB2.0 DVB-T receiver.
132 Currently, only devices with a product id of 136 Currently, only devices with a product id of
@@ -137,7 +141,7 @@ config DVB_USB_GL861
137 tristate "Genesys Logic GL861 USB2.0 support" 141 tristate "Genesys Logic GL861 USB2.0 support"
138 depends on DVB_USB 142 depends on DVB_USB
139 select DVB_ZL10353 if !DVB_FE_CUSTOMISE 143 select DVB_ZL10353 if !DVB_FE_CUSTOMISE
140 select MEDIA_TUNER_QT1010 if !MEDIA_TUNER_CUSTOMIZE 144 select MEDIA_TUNER_QT1010 if !MEDIA_TUNER_CUSTOMISE
141 help 145 help
142 Say Y here to support the MSI Megasky 580 (55801) DVB-T USB2.0 146 Say Y here to support the MSI Megasky 580 (55801) DVB-T USB2.0
143 receiver with USB ID 0db0:5581. 147 receiver with USB ID 0db0:5581.
@@ -146,7 +150,7 @@ config DVB_USB_AU6610
146 tristate "Alcor Micro AU6610 USB2.0 support" 150 tristate "Alcor Micro AU6610 USB2.0 support"
147 depends on DVB_USB 151 depends on DVB_USB
148 select DVB_ZL10353 if !DVB_FE_CUSTOMISE 152 select DVB_ZL10353 if !DVB_FE_CUSTOMISE
149 select MEDIA_TUNER_QT1010 if !MEDIA_TUNER_CUSTOMIZE 153 select MEDIA_TUNER_QT1010 if !MEDIA_TUNER_CUSTOMISE
150 help 154 help
151 Say Y here to support the Sigmatek DVB-110 DVB-T USB2.0 receiver. 155 Say Y here to support the Sigmatek DVB-110 DVB-T USB2.0 receiver.
152 156
@@ -199,7 +203,7 @@ config DVB_USB_NOVA_T_USB2
199 depends on DVB_USB 203 depends on DVB_USB
200 select DVB_DIB3000MC 204 select DVB_DIB3000MC
201 select DVB_PLL if !DVB_FE_CUSTOMISE 205 select DVB_PLL if !DVB_FE_CUSTOMISE
202 select MEDIA_TUNER_MT2060 if !MEDIA_TUNER_CUSTOMIZE 206 select MEDIA_TUNER_MT2060 if !MEDIA_TUNER_CUSTOMISE
203 help 207 help
204 Say Y here to support the Hauppauge WinTV-NOVA-T usb2 DVB-T USB2.0 receiver. 208 Say Y here to support the Hauppauge WinTV-NOVA-T usb2 DVB-T USB2.0 receiver.
205 209
@@ -235,8 +239,8 @@ config DVB_USB_OPERA1
235config DVB_USB_AF9005 239config DVB_USB_AF9005
236 tristate "Afatech AF9005 DVB-T USB1.1 support" 240 tristate "Afatech AF9005 DVB-T USB1.1 support"
237 depends on DVB_USB && EXPERIMENTAL 241 depends on DVB_USB && EXPERIMENTAL
238 select MEDIA_TUNER_MT2060 if !MEDIA_TUNER_CUSTOMIZE 242 select MEDIA_TUNER_MT2060 if !MEDIA_TUNER_CUSTOMISE
239 select MEDIA_TUNER_QT1010 if !MEDIA_TUNER_CUSTOMIZE 243 select MEDIA_TUNER_QT1010 if !MEDIA_TUNER_CUSTOMISE
240 help 244 help
241 Say Y here to support the Afatech AF9005 based DVB-T USB1.1 receiver 245 Say Y here to support the Afatech AF9005 based DVB-T USB1.1 receiver
242 and the TerraTec Cinergy T USB XE (Rev.1) 246 and the TerraTec Cinergy T USB XE (Rev.1)
@@ -284,7 +288,7 @@ config DVB_USB_DTV5100
284 tristate "AME DTV-5100 USB2.0 DVB-T support" 288 tristate "AME DTV-5100 USB2.0 DVB-T support"
285 depends on DVB_USB 289 depends on DVB_USB
286 select DVB_ZL10353 if !DVB_FE_CUSTOMISE 290 select DVB_ZL10353 if !DVB_FE_CUSTOMISE
287 select MEDIA_TUNER_QT1010 if !MEDIA_TUNER_CUSTOMIZE 291 select MEDIA_TUNER_QT1010 if !MEDIA_TUNER_CUSTOMISE
288 help 292 help
289 Say Y here to support the AME DTV-5100 USB2.0 DVB-T receiver. 293 Say Y here to support the AME DTV-5100 USB2.0 DVB-T receiver.
290 294
@@ -293,9 +297,18 @@ config DVB_USB_AF9015
293 depends on DVB_USB && EXPERIMENTAL 297 depends on DVB_USB && EXPERIMENTAL
294 select DVB_AF9013 298 select DVB_AF9013
295 select DVB_PLL if !DVB_FE_CUSTOMISE 299 select DVB_PLL if !DVB_FE_CUSTOMISE
296 select MEDIA_TUNER_MT2060 if !MEDIA_TUNER_CUSTOMIZE 300 select MEDIA_TUNER_MT2060 if !MEDIA_TUNER_CUSTOMISE
297 select MEDIA_TUNER_QT1010 if !MEDIA_TUNER_CUSTOMIZE 301 select MEDIA_TUNER_QT1010 if !MEDIA_TUNER_CUSTOMISE
298 select MEDIA_TUNER_TDA18271 if !MEDIA_TUNER_CUSTOMIZE 302 select MEDIA_TUNER_TDA18271 if !MEDIA_TUNER_CUSTOMISE
299 select MEDIA_TUNER_MXL5005S if !MEDIA_TUNER_CUSTOMIZE 303 select MEDIA_TUNER_MXL5005S if !MEDIA_TUNER_CUSTOMISE
304 select MEDIA_TUNER_MC44S803 if !MEDIA_TUNER_CUSTOMISE
300 help 305 help
301 Say Y here to support the Afatech AF9015 based DVB-T USB2.0 receiver 306 Say Y here to support the Afatech AF9015 based DVB-T USB2.0 receiver
307
308config DVB_USB_CE6230
309 tristate "Intel CE6230 DVB-T USB2.0 support"
310 depends on DVB_USB && EXPERIMENTAL
311 select DVB_ZL10353
312 select MEDIA_TUNER_MXL5005S if !MEDIA_TUNER_CUSTOMIZE
313 help
314 Say Y here to support the Intel CE6230 DVB-T USB2.0 receiver
diff --git a/drivers/media/dvb/dvb-usb/Makefile b/drivers/media/dvb/dvb-usb/Makefile
index 3122b7cc2c23..f92734ed777a 100644
--- a/drivers/media/dvb/dvb-usb/Makefile
+++ b/drivers/media/dvb/dvb-usb/Makefile
@@ -76,6 +76,8 @@ obj-$(CONFIG_DVB_USB_AF9015) += dvb-usb-af9015.o
76dvb-usb-cinergyT2-objs = cinergyT2-core.o cinergyT2-fe.o 76dvb-usb-cinergyT2-objs = cinergyT2-core.o cinergyT2-fe.o
77obj-$(CONFIG_DVB_USB_CINERGY_T2) += dvb-usb-cinergyT2.o 77obj-$(CONFIG_DVB_USB_CINERGY_T2) += dvb-usb-cinergyT2.o
78 78
79dvb-usb-ce6230-objs = ce6230.o
80obj-$(CONFIG_DVB_USB_CE6230) += dvb-usb-ce6230.o
79 81
80EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/ 82EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/
81# due to tuner-xc3028 83# due to tuner-xc3028
diff --git a/drivers/media/dvb/dvb-usb/af9015.c b/drivers/media/dvb/dvb-usb/af9015.c
index 6a97a40d3dfb..f0ba8b07b84f 100644
--- a/drivers/media/dvb/dvb-usb/af9015.c
+++ b/drivers/media/dvb/dvb-usb/af9015.c
@@ -27,9 +27,7 @@
27#include "qt1010.h" 27#include "qt1010.h"
28#include "tda18271.h" 28#include "tda18271.h"
29#include "mxl5005s.h" 29#include "mxl5005s.h"
30#if 0 30#include "mc44s803.h"
31#include "mc44s80x.h"
32#endif
33 31
34static int dvb_usb_af9015_debug; 32static int dvb_usb_af9015_debug;
35module_param_named(debug, dvb_usb_af9015_debug, int, 0644); 33module_param_named(debug, dvb_usb_af9015_debug, int, 0644);
@@ -37,9 +35,6 @@ MODULE_PARM_DESC(debug, "set debugging level" DVB_USB_DEBUG_STATUS);
37static int dvb_usb_af9015_remote; 35static int dvb_usb_af9015_remote;
38module_param_named(remote, dvb_usb_af9015_remote, int, 0644); 36module_param_named(remote, dvb_usb_af9015_remote, int, 0644);
39MODULE_PARM_DESC(remote, "select remote"); 37MODULE_PARM_DESC(remote, "select remote");
40static int dvb_usb_af9015_dual_mode;
41module_param_named(dual_mode, dvb_usb_af9015_dual_mode, int, 0644);
42MODULE_PARM_DESC(dual_mode, "enable dual mode");
43DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); 38DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
44 39
45static DEFINE_MUTEX(af9015_usb_mutex); 40static DEFINE_MUTEX(af9015_usb_mutex);
@@ -283,6 +278,21 @@ Due to that the only way to select correct tuner is use demodulator I2C-gate.
283 req.data = &msg[i+1].buf[0]; 278 req.data = &msg[i+1].buf[0];
284 ret = af9015_ctrl_msg(d, &req); 279 ret = af9015_ctrl_msg(d, &req);
285 i += 2; 280 i += 2;
281 } else if (msg[i].flags & I2C_M_RD) {
282 ret = -EINVAL;
283 if (msg[i].addr ==
284 af9015_af9013_config[0].demod_address)
285 goto error;
286 else
287 req.cmd = READ_I2C;
288 req.i2c_addr = msg[i].addr;
289 req.addr = addr;
290 req.mbox = mbox;
291 req.addr_len = addr_len;
292 req.data_len = msg[i].len;
293 req.data = &msg[i].buf[0];
294 ret = af9015_ctrl_msg(d, &req);
295 i += 1;
286 } else { 296 } else {
287 if (msg[i].addr == 297 if (msg[i].addr ==
288 af9015_af9013_config[0].demod_address) 298 af9015_af9013_config[0].demod_address)
@@ -748,6 +758,16 @@ static int af9015_read_config(struct usb_device *udev)
748 af9015_config.ir_table_size = 758 af9015_config.ir_table_size =
749 ARRAY_SIZE(af9015_ir_table_digittrade); 759 ARRAY_SIZE(af9015_ir_table_digittrade);
750 break; 760 break;
761 case AF9015_REMOTE_AVERMEDIA_KS:
762 af9015_properties[i].rc_key_map =
763 af9015_rc_keys_avermedia;
764 af9015_properties[i].rc_key_map_size =
765 ARRAY_SIZE(af9015_rc_keys_avermedia);
766 af9015_config.ir_table =
767 af9015_ir_table_avermedia_ks;
768 af9015_config.ir_table_size =
769 ARRAY_SIZE(af9015_ir_table_avermedia_ks);
770 break;
751 } 771 }
752 } else { 772 } else {
753 switch (le16_to_cpu(udev->descriptor.idVendor)) { 773 switch (le16_to_cpu(udev->descriptor.idVendor)) {
@@ -836,9 +856,6 @@ static int af9015_read_config(struct usb_device *udev)
836 goto error; 856 goto error;
837 af9015_config.dual_mode = val; 857 af9015_config.dual_mode = val;
838 deb_info("%s: TS mode:%d\n", __func__, af9015_config.dual_mode); 858 deb_info("%s: TS mode:%d\n", __func__, af9015_config.dual_mode);
839 /* disable dual mode by default because it is buggy */
840 if (!dvb_usb_af9015_dual_mode)
841 af9015_config.dual_mode = 0;
842 859
843 /* Set adapter0 buffer size according to USB port speed, adapter1 buffer 860 /* Set adapter0 buffer size according to USB port speed, adapter1 buffer
844 size can be static because it is enabled only USB2.0 */ 861 size can be static because it is enabled only USB2.0 */
@@ -935,7 +952,6 @@ static int af9015_read_config(struct usb_device *udev)
935 switch (val) { 952 switch (val) {
936 case AF9013_TUNER_ENV77H11D5: 953 case AF9013_TUNER_ENV77H11D5:
937 case AF9013_TUNER_MT2060: 954 case AF9013_TUNER_MT2060:
938 case AF9013_TUNER_MC44S803:
939 case AF9013_TUNER_QT1010: 955 case AF9013_TUNER_QT1010:
940 case AF9013_TUNER_UNKNOWN: 956 case AF9013_TUNER_UNKNOWN:
941 case AF9013_TUNER_MT2060_2: 957 case AF9013_TUNER_MT2060_2:
@@ -948,6 +964,10 @@ static int af9015_read_config(struct usb_device *udev)
948 case AF9013_TUNER_MXL5005R: 964 case AF9013_TUNER_MXL5005R:
949 af9015_af9013_config[i].rf_spec_inv = 0; 965 af9015_af9013_config[i].rf_spec_inv = 0;
950 break; 966 break;
967 case AF9013_TUNER_MC44S803:
968 af9015_af9013_config[i].gpio[1] = AF9013_GPIO_LO;
969 af9015_af9013_config[i].rf_spec_inv = 1;
970 break;
951 default: 971 default:
952 warn("tuner id:%d not supported, please report!", val); 972 warn("tuner id:%d not supported, please report!", val);
953 return -ENODEV; 973 return -ENODEV;
@@ -1135,6 +1155,11 @@ static struct mxl5005s_config af9015_mxl5005_config = {
1135 .AgcMasterByte = 0x00, 1155 .AgcMasterByte = 0x00,
1136}; 1156};
1137 1157
1158static struct mc44s803_config af9015_mc44s803_config = {
1159 .i2c_address = 0xc0,
1160 .dig_out = 1,
1161};
1162
1138static int af9015_tuner_attach(struct dvb_usb_adapter *adap) 1163static int af9015_tuner_attach(struct dvb_usb_adapter *adap)
1139{ 1164{
1140 struct af9015_state *state = adap->dev->priv; 1165 struct af9015_state *state = adap->dev->priv;
@@ -1179,15 +1204,8 @@ static int af9015_tuner_attach(struct dvb_usb_adapter *adap)
1179 DVB_PLL_TDA665X) == NULL ? -ENODEV : 0; 1204 DVB_PLL_TDA665X) == NULL ? -ENODEV : 0;
1180 break; 1205 break;
1181 case AF9013_TUNER_MC44S803: 1206 case AF9013_TUNER_MC44S803:
1182#if 0 1207 ret = dvb_attach(mc44s803_attach, adap->fe, i2c_adap,
1183 ret = dvb_attach(mc44s80x_attach, adap->fe, i2c_adap) 1208 &af9015_mc44s803_config) == NULL ? -ENODEV : 0;
1184 == NULL ? -ENODEV : 0;
1185#else
1186 ret = -ENODEV;
1187 info("Freescale MC44S803 tuner found but no driver for that" \
1188 "tuner. Look at the Linuxtv.org for tuner driver" \
1189 "status.");
1190#endif
1191 break; 1209 break;
1192 case AF9013_TUNER_UNKNOWN: 1210 case AF9013_TUNER_UNKNOWN:
1193 default: 1211 default:
@@ -1218,6 +1236,7 @@ static struct usb_device_id af9015_usb_table[] = {
1218 {USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A309)}, 1236 {USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A309)},
1219/* 15 */{USB_DEVICE(USB_VID_MSI_2, USB_PID_MSI_DIGI_VOX_MINI_III)}, 1237/* 15 */{USB_DEVICE(USB_VID_MSI_2, USB_PID_MSI_DIGI_VOX_MINI_III)},
1220 {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_395U)}, 1238 {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_395U)},
1239 {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_395U_2)},
1221 {0}, 1240 {0},
1222}; 1241};
1223MODULE_DEVICE_TABLE(usb, af9015_usb_table); 1242MODULE_DEVICE_TABLE(usb, af9015_usb_table);
@@ -1417,7 +1436,8 @@ static struct dvb_usb_device_properties af9015_properties[] = {
1417 { 1436 {
1418 .name = "KWorld USB DVB-T TV Stick II " \ 1437 .name = "KWorld USB DVB-T TV Stick II " \
1419 "(VS-DVB-T 395U)", 1438 "(VS-DVB-T 395U)",
1420 .cold_ids = {&af9015_usb_table[16], NULL}, 1439 .cold_ids = {&af9015_usb_table[16],
1440 &af9015_usb_table[17], NULL},
1421 .warm_ids = {NULL}, 1441 .warm_ids = {NULL},
1422 }, 1442 },
1423 } 1443 }
diff --git a/drivers/media/dvb/dvb-usb/af9015.h b/drivers/media/dvb/dvb-usb/af9015.h
index 21c7782f4889..00e25714662a 100644
--- a/drivers/media/dvb/dvb-usb/af9015.h
+++ b/drivers/media/dvb/dvb-usb/af9015.h
@@ -124,6 +124,7 @@ enum af9015_remote {
124 AF9015_REMOTE_MSI_DIGIVOX_MINI_II_V3, 124 AF9015_REMOTE_MSI_DIGIVOX_MINI_II_V3,
125 AF9015_REMOTE_MYGICTV_U718, 125 AF9015_REMOTE_MYGICTV_U718,
126 AF9015_REMOTE_DIGITTRADE_DVB_T, 126 AF9015_REMOTE_DIGITTRADE_DVB_T,
127 AF9015_REMOTE_AVERMEDIA_KS,
127}; 128};
128 129
129/* Leadtek WinFast DTV Dongle Gold */ 130/* Leadtek WinFast DTV Dongle Gold */
@@ -597,6 +598,36 @@ static u8 af9015_ir_table_avermedia[] = {
597 0x03, 0xfc, 0x03, 0xfc, 0x0e, 0x05, 0x00, 598 0x03, 0xfc, 0x03, 0xfc, 0x0e, 0x05, 0x00,
598}; 599};
599 600
601static u8 af9015_ir_table_avermedia_ks[] = {
602 0x05, 0xfa, 0x01, 0xfe, 0x12, 0x05, 0x00,
603 0x05, 0xfa, 0x02, 0xfd, 0x0e, 0x05, 0x00,
604 0x05, 0xfa, 0x03, 0xfc, 0x0d, 0x05, 0x00,
605 0x05, 0xfa, 0x04, 0xfb, 0x2e, 0x05, 0x00,
606 0x05, 0xfa, 0x05, 0xfa, 0x2d, 0x05, 0x00,
607 0x05, 0xfa, 0x06, 0xf9, 0x10, 0x05, 0x00,
608 0x05, 0xfa, 0x07, 0xf8, 0x0f, 0x05, 0x00,
609 0x05, 0xfa, 0x08, 0xf7, 0x3d, 0x05, 0x00,
610 0x05, 0xfa, 0x09, 0xf6, 0x1e, 0x05, 0x00,
611 0x05, 0xfa, 0x0a, 0xf5, 0x1f, 0x05, 0x00,
612 0x05, 0xfa, 0x0b, 0xf4, 0x20, 0x05, 0x00,
613 0x05, 0xfa, 0x0c, 0xf3, 0x21, 0x05, 0x00,
614 0x05, 0xfa, 0x0d, 0xf2, 0x22, 0x05, 0x00,
615 0x05, 0xfa, 0x0e, 0xf1, 0x23, 0x05, 0x00,
616 0x05, 0xfa, 0x0f, 0xf0, 0x24, 0x05, 0x00,
617 0x05, 0xfa, 0x10, 0xef, 0x25, 0x05, 0x00,
618 0x05, 0xfa, 0x11, 0xee, 0x26, 0x05, 0x00,
619 0x05, 0xfa, 0x12, 0xed, 0x27, 0x05, 0x00,
620 0x05, 0xfa, 0x13, 0xec, 0x04, 0x05, 0x00,
621 0x05, 0xfa, 0x15, 0xea, 0x0a, 0x05, 0x00,
622 0x05, 0xfa, 0x16, 0xe9, 0x11, 0x05, 0x00,
623 0x05, 0xfa, 0x17, 0xe8, 0x15, 0x05, 0x00,
624 0x05, 0xfa, 0x18, 0xe7, 0x16, 0x05, 0x00,
625 0x05, 0xfa, 0x1c, 0xe3, 0x05, 0x05, 0x00,
626 0x05, 0xfa, 0x1d, 0xe2, 0x09, 0x05, 0x00,
627 0x05, 0xfa, 0x4d, 0xb2, 0x3f, 0x05, 0x00,
628 0x05, 0xfa, 0x56, 0xa9, 0x3e, 0x05, 0x00
629};
630
600/* Digittrade DVB-T USB Stick */ 631/* Digittrade DVB-T USB Stick */
601static struct dvb_usb_rc_key af9015_rc_keys_digittrade[] = { 632static struct dvb_usb_rc_key af9015_rc_keys_digittrade[] = {
602 { 0x01, 0x0f, KEY_LAST }, /* RETURN */ 633 { 0x01, 0x0f, KEY_LAST }, /* RETURN */
diff --git a/drivers/media/dvb/dvb-usb/ce6230.c b/drivers/media/dvb/dvb-usb/ce6230.c
new file mode 100644
index 000000000000..5862820f109f
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/ce6230.c
@@ -0,0 +1,328 @@
1/*
2 * DVB USB Linux driver for Intel CE6230 DVB-T USB2.0 receiver
3 *
4 * Copyright (C) 2009 Antti Palosaari <crope@iki.fi>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
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
22#include "ce6230.h"
23#include "zl10353.h"
24#include "mxl5005s.h"
25
26/* debug */
27static int dvb_usb_ce6230_debug;
28module_param_named(debug, dvb_usb_ce6230_debug, int, 0644);
29MODULE_PARM_DESC(debug, "set debugging level" DVB_USB_DEBUG_STATUS);
30DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
31
32static struct zl10353_config ce6230_zl10353_config;
33
34static int ce6230_rw_udev(struct usb_device *udev, struct req_t *req)
35{
36 int ret;
37 unsigned int pipe;
38 u8 request;
39 u8 requesttype;
40 u16 value;
41 u16 index;
42 u8 buf[req->data_len];
43
44 request = req->cmd;
45 value = req->value;
46 index = req->index;
47
48 switch (req->cmd) {
49 case I2C_READ:
50 case DEMOD_READ:
51 case REG_READ:
52 requesttype = (USB_TYPE_VENDOR | USB_DIR_IN);
53 break;
54 case I2C_WRITE:
55 case DEMOD_WRITE:
56 case REG_WRITE:
57 requesttype = (USB_TYPE_VENDOR | USB_DIR_OUT);
58 break;
59 default:
60 err("unknown command:%02x", req->cmd);
61 ret = -EPERM;
62 goto error;
63 }
64
65 if (requesttype == (USB_TYPE_VENDOR | USB_DIR_OUT)) {
66 /* write */
67 memcpy(buf, req->data, req->data_len);
68 pipe = usb_sndctrlpipe(udev, 0);
69 } else {
70 /* read */
71 pipe = usb_rcvctrlpipe(udev, 0);
72 }
73
74 msleep(1); /* avoid I2C errors */
75
76 ret = usb_control_msg(udev, pipe, request, requesttype, value, index,
77 buf, sizeof(buf), CE6230_USB_TIMEOUT);
78
79 ce6230_debug_dump(request, requesttype, value, index, buf,
80 req->data_len, deb_xfer);
81
82 if (ret < 0)
83 deb_info("%s: usb_control_msg failed:%d\n", __func__, ret);
84 else
85 ret = 0;
86
87 /* read request, copy returned data to return buf */
88 if (!ret && requesttype == (USB_TYPE_VENDOR | USB_DIR_IN))
89 memcpy(req->data, buf, req->data_len);
90
91error:
92 return ret;
93}
94
95static int ce6230_ctrl_msg(struct dvb_usb_device *d, struct req_t *req)
96{
97 return ce6230_rw_udev(d->udev, req);
98}
99
100/* I2C */
101static int ce6230_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
102 int num)
103{
104 struct dvb_usb_device *d = i2c_get_adapdata(adap);
105 int i = 0;
106 struct req_t req;
107 int ret = 0;
108 memset(&req, 0, sizeof(&req));
109
110 if (num > 2)
111 return -EINVAL;
112
113 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
114 return -EAGAIN;
115
116 while (i < num) {
117 if (num > i + 1 && (msg[i+1].flags & I2C_M_RD)) {
118 if (msg[i].addr ==
119 ce6230_zl10353_config.demod_address) {
120 req.cmd = DEMOD_READ;
121 req.value = msg[i].addr >> 1;
122 req.index = msg[i].buf[0];
123 req.data_len = msg[i+1].len;
124 req.data = &msg[i+1].buf[0];
125 ret = ce6230_ctrl_msg(d, &req);
126 } else {
127 err("i2c read not implemented");
128 ret = -EPERM;
129 }
130 i += 2;
131 } else {
132 if (msg[i].addr ==
133 ce6230_zl10353_config.demod_address) {
134 req.cmd = DEMOD_WRITE;
135 req.value = msg[i].addr >> 1;
136 req.index = msg[i].buf[0];
137 req.data_len = msg[i].len-1;
138 req.data = &msg[i].buf[1];
139 ret = ce6230_ctrl_msg(d, &req);
140 } else {
141 req.cmd = I2C_WRITE;
142 req.value = 0x2000 + (msg[i].addr >> 1);
143 req.index = 0x0000;
144 req.data_len = msg[i].len;
145 req.data = &msg[i].buf[0];
146 ret = ce6230_ctrl_msg(d, &req);
147 }
148 i += 1;
149 }
150 if (ret)
151 break;
152 }
153
154 mutex_unlock(&d->i2c_mutex);
155 return ret ? ret : i;
156}
157
158static u32 ce6230_i2c_func(struct i2c_adapter *adapter)
159{
160 return I2C_FUNC_I2C;
161}
162
163static struct i2c_algorithm ce6230_i2c_algo = {
164 .master_xfer = ce6230_i2c_xfer,
165 .functionality = ce6230_i2c_func,
166};
167
168/* Callbacks for DVB USB */
169static struct zl10353_config ce6230_zl10353_config = {
170 .demod_address = 0x1e,
171 .adc_clock = 450000,
172 .if2 = 45700,
173 .no_tuner = 1,
174 .parallel_ts = 1,
175 .clock_ctl_1 = 0x34,
176 .pll_0 = 0x0e,
177};
178
179static int ce6230_zl10353_frontend_attach(struct dvb_usb_adapter *adap)
180{
181 deb_info("%s:\n", __func__);
182 adap->fe = dvb_attach(zl10353_attach, &ce6230_zl10353_config,
183 &adap->dev->i2c_adap);
184 if (adap->fe == NULL)
185 return -ENODEV;
186 return 0;
187}
188
189static struct mxl5005s_config ce6230_mxl5003s_config = {
190 .i2c_address = 0xc6,
191 .if_freq = IF_FREQ_4570000HZ,
192 .xtal_freq = CRYSTAL_FREQ_16000000HZ,
193 .agc_mode = MXL_SINGLE_AGC,
194 .tracking_filter = MXL_TF_DEFAULT,
195 .rssi_enable = MXL_RSSI_ENABLE,
196 .cap_select = MXL_CAP_SEL_ENABLE,
197 .div_out = MXL_DIV_OUT_4,
198 .clock_out = MXL_CLOCK_OUT_DISABLE,
199 .output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM,
200 .top = MXL5005S_TOP_25P2,
201 .mod_mode = MXL_DIGITAL_MODE,
202 .if_mode = MXL_ZERO_IF,
203 .AgcMasterByte = 0x00,
204};
205
206static int ce6230_mxl5003s_tuner_attach(struct dvb_usb_adapter *adap)
207{
208 int ret;
209 deb_info("%s:\n", __func__);
210 ret = dvb_attach(mxl5005s_attach, adap->fe, &adap->dev->i2c_adap,
211 &ce6230_mxl5003s_config) == NULL ? -ENODEV : 0;
212 return ret;
213}
214
215static int ce6230_power_ctrl(struct dvb_usb_device *d, int onoff)
216{
217 int ret;
218 deb_info("%s: onoff:%d\n", __func__, onoff);
219
220 /* InterfaceNumber 1 / AlternateSetting 0 idle
221 InterfaceNumber 1 / AlternateSetting 1 streaming */
222 ret = usb_set_interface(d->udev, 1, onoff);
223 if (ret)
224 err("usb_set_interface failed with error:%d", ret);
225
226 return ret;
227}
228
229/* DVB USB Driver stuff */
230static struct dvb_usb_device_properties ce6230_properties;
231
232static int ce6230_probe(struct usb_interface *intf,
233 const struct usb_device_id *id)
234{
235 int ret = 0;
236 struct dvb_usb_device *d = NULL;
237
238 deb_info("%s: interface:%d\n", __func__,
239 intf->cur_altsetting->desc.bInterfaceNumber);
240
241 if (intf->cur_altsetting->desc.bInterfaceNumber == 1) {
242 ret = dvb_usb_device_init(intf, &ce6230_properties, THIS_MODULE,
243 &d, adapter_nr);
244 if (ret)
245 err("init failed with error:%d\n", ret);
246 }
247
248 return ret;
249}
250
251static struct usb_device_id ce6230_table[] = {
252 { USB_DEVICE(USB_VID_INTEL, USB_PID_INTEL_CE9500) },
253 { } /* Terminating entry */
254};
255MODULE_DEVICE_TABLE(usb, ce6230_table);
256
257static struct dvb_usb_device_properties ce6230_properties = {
258 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
259
260 .usb_ctrl = DEVICE_SPECIFIC,
261 .no_reconnect = 1,
262
263 .size_of_priv = 0,
264
265 .num_adapters = 1,
266 .adapter = {
267 {
268 .frontend_attach = ce6230_zl10353_frontend_attach,
269 .tuner_attach = ce6230_mxl5003s_tuner_attach,
270 .stream = {
271 .type = USB_BULK,
272 .count = 6,
273 .endpoint = 0x82,
274 .u = {
275 .bulk = {
276 .buffersize = 512,
277 }
278 }
279 },
280 }
281 },
282
283 .power_ctrl = ce6230_power_ctrl,
284
285 .i2c_algo = &ce6230_i2c_algo,
286
287 .num_device_descs = 1,
288 .devices = {
289 {
290 .name = "Intel CE9500 reference design",
291 .cold_ids = {NULL},
292 .warm_ids = {&ce6230_table[0], NULL},
293 },
294 }
295};
296
297static struct usb_driver ce6230_driver = {
298 .name = "dvb_usb_ce6230",
299 .probe = ce6230_probe,
300 .disconnect = dvb_usb_device_exit,
301 .id_table = ce6230_table,
302};
303
304/* module stuff */
305static int __init ce6230_module_init(void)
306{
307 int ret;
308 deb_info("%s:\n", __func__);
309 ret = usb_register(&ce6230_driver);
310 if (ret)
311 err("usb_register failed with error:%d", ret);
312
313 return ret;
314}
315
316static void __exit ce6230_module_exit(void)
317{
318 deb_info("%s:\n", __func__);
319 /* deregister this driver from the USB subsystem */
320 usb_deregister(&ce6230_driver);
321}
322
323module_init(ce6230_module_init);
324module_exit(ce6230_module_exit);
325
326MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
327MODULE_DESCRIPTION("Driver for Intel CE6230 DVB-T USB2.0");
328MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/dvb-usb/ce6230.h b/drivers/media/dvb/dvb-usb/ce6230.h
new file mode 100644
index 000000000000..97c42482ccb3
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/ce6230.h
@@ -0,0 +1,69 @@
1/*
2 * DVB USB Linux driver for Intel CE6230 DVB-T USB2.0 receiver
3 *
4 * Copyright (C) 2009 Antti Palosaari <crope@iki.fi>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
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
22#ifndef _DVB_USB_CE6230_H_
23#define _DVB_USB_CE6230_H_
24
25#define DVB_USB_LOG_PREFIX "ce6230"
26#include "dvb-usb.h"
27
28#define deb_info(args...) dprintk(dvb_usb_ce6230_debug, 0x01, args)
29#define deb_rc(args...) dprintk(dvb_usb_ce6230_debug, 0x02, args)
30#define deb_xfer(args...) dprintk(dvb_usb_ce6230_debug, 0x04, args)
31#define deb_reg(args...) dprintk(dvb_usb_ce6230_debug, 0x08, args)
32#define deb_i2c(args...) dprintk(dvb_usb_ce6230_debug, 0x10, args)
33#define deb_fw(args...) dprintk(dvb_usb_ce6230_debug, 0x20, args)
34
35#define ce6230_debug_dump(r, t, v, i, b, l, func) { \
36 int loop_; \
37 func("%02x %02x %02x %02x %02x %02x %02x %02x", \
38 t, r, v & 0xff, v >> 8, i & 0xff, i >> 8, l & 0xff, l >> 8); \
39 if (t == (USB_TYPE_VENDOR | USB_DIR_OUT)) \
40 func(" >>> "); \
41 else \
42 func(" <<< "); \
43 for (loop_ = 0; loop_ < l; loop_++) \
44 func("%02x ", b[loop_]); \
45 func("\n");\
46}
47
48#define CE6230_USB_TIMEOUT 1000
49
50struct req_t {
51 u8 cmd; /* [1] */
52 u16 value; /* [2|3] */
53 u16 index; /* [4|5] */
54 u16 data_len; /* [6|7] */
55 u8 *data;
56};
57
58enum ce6230_cmd {
59 CONFIG_READ = 0xd0, /* rd 0 (unclear) */
60 UNKNOWN_WRITE = 0xc7, /* wr 7 (unclear) */
61 I2C_READ = 0xd9, /* rd 9 (unclear) */
62 I2C_WRITE = 0xca, /* wr a */
63 DEMOD_READ = 0xdb, /* rd b */
64 DEMOD_WRITE = 0xcc, /* wr c */
65 REG_READ = 0xde, /* rd e */
66 REG_WRITE = 0xcf, /* wr f */
67};
68
69#endif
diff --git a/drivers/media/dvb/dvb-usb/dib0700_core.c b/drivers/media/dvb/dvb-usb/dib0700_core.c
index 200b215f4d8b..db7f7f79a66c 100644
--- a/drivers/media/dvb/dvb-usb/dib0700_core.c
+++ b/drivers/media/dvb/dvb-usb/dib0700_core.c
@@ -158,6 +158,10 @@ static int dib0700_i2c_xfer_new(struct i2c_adapter *adap, struct i2c_msg *msg,
158 err("i2c read error (status = %d)\n", result); 158 err("i2c read error (status = %d)\n", result);
159 break; 159 break;
160 } 160 }
161
162 deb_data("<<< ");
163 debug_dump(msg[i].buf, msg[i].len, deb_data);
164
161 } else { 165 } else {
162 /* Write request */ 166 /* Write request */
163 buf[0] = REQUEST_NEW_I2C_WRITE; 167 buf[0] = REQUEST_NEW_I2C_WRITE;
@@ -169,6 +173,9 @@ static int dib0700_i2c_xfer_new(struct i2c_adapter *adap, struct i2c_msg *msg,
169 /* The Actual i2c payload */ 173 /* The Actual i2c payload */
170 memcpy(&buf[4], msg[i].buf, msg[i].len); 174 memcpy(&buf[4], msg[i].buf, msg[i].len);
171 175
176 deb_data(">>> ");
177 debug_dump(buf, msg[i].len + 4, deb_data);
178
172 result = usb_control_msg(d->udev, 179 result = usb_control_msg(d->udev,
173 usb_sndctrlpipe(d->udev, 0), 180 usb_sndctrlpipe(d->udev, 0),
174 REQUEST_NEW_I2C_WRITE, 181 REQUEST_NEW_I2C_WRITE,
@@ -211,7 +218,8 @@ static int dib0700_i2c_xfer_legacy(struct i2c_adapter *adap,
211 218
212 /* special thing in the current firmware: when length is zero the read-failed */ 219 /* special thing in the current firmware: when length is zero the read-failed */
213 if ((len = dib0700_ctrl_rd(d, buf, msg[i].len + 2, msg[i+1].buf, msg[i+1].len)) <= 0) { 220 if ((len = dib0700_ctrl_rd(d, buf, msg[i].len + 2, msg[i+1].buf, msg[i+1].len)) <= 0) {
214 deb_info("I2C read failed on address %x\n", msg[i].addr); 221 deb_info("I2C read failed on address 0x%02x\n",
222 msg[i].addr);
215 break; 223 break;
216 } 224 }
217 225
diff --git a/drivers/media/dvb/dvb-usb/dib0700_devices.c b/drivers/media/dvb/dvb-usb/dib0700_devices.c
index 635d30a55078..8ddbadf62194 100644
--- a/drivers/media/dvb/dvb-usb/dib0700_devices.c
+++ b/drivers/media/dvb/dvb-usb/dib0700_devices.c
@@ -17,6 +17,8 @@
17#include "xc5000.h" 17#include "xc5000.h"
18#include "s5h1411.h" 18#include "s5h1411.h"
19#include "dib0070.h" 19#include "dib0070.h"
20#include "lgdt3305.h"
21#include "mxl5007t.h"
20 22
21static int force_lna_activation; 23static int force_lna_activation;
22module_param(force_lna_activation, int, 0644); 24module_param(force_lna_activation, int, 0644);
@@ -262,7 +264,12 @@ static int stk7700P2_frontend_attach(struct dvb_usb_adapter *adap)
262 msleep(10); 264 msleep(10);
263 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1); 265 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
264 msleep(10); 266 msleep(10);
265 dib7000p_i2c_enumeration(&adap->dev->i2c_adap,1,18,stk7700d_dib7000p_mt2266_config); 267 if (dib7000p_i2c_enumeration(&adap->dev->i2c_adap, 1, 18,
268 stk7700d_dib7000p_mt2266_config)
269 != 0) {
270 err("%s: dib7000p_i2c_enumeration failed. Cannot continue\n", __func__);
271 return -ENODEV;
272 }
266 } 273 }
267 274
268 adap->fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap,0x80+(adap->id << 1), 275 adap->fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap,0x80+(adap->id << 1),
@@ -284,7 +291,12 @@ static int stk7700d_frontend_attach(struct dvb_usb_adapter *adap)
284 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1); 291 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
285 msleep(10); 292 msleep(10);
286 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1); 293 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
287 dib7000p_i2c_enumeration(&adap->dev->i2c_adap,2,18,stk7700d_dib7000p_mt2266_config); 294 if (dib7000p_i2c_enumeration(&adap->dev->i2c_adap, 2, 18,
295 stk7700d_dib7000p_mt2266_config)
296 != 0) {
297 err("%s: dib7000p_i2c_enumeration failed. Cannot continue\n", __func__);
298 return -ENODEV;
299 }
288 } 300 }
289 301
290 adap->fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap,0x80+(adap->id << 1), 302 adap->fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap,0x80+(adap->id << 1),
@@ -421,8 +433,12 @@ static int stk7700ph_frontend_attach(struct dvb_usb_adapter *adap)
421 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1); 433 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
422 msleep(10); 434 msleep(10);
423 435
424 dib7000p_i2c_enumeration(&adap->dev->i2c_adap, 1, 18, 436 if (dib7000p_i2c_enumeration(&adap->dev->i2c_adap, 1, 18,
425 &stk7700ph_dib7700_xc3028_config); 437 &stk7700ph_dib7700_xc3028_config) != 0) {
438 err("%s: dib7000p_i2c_enumeration failed. Cannot continue\n",
439 __func__);
440 return -ENODEV;
441 }
426 442
427 adap->fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x80, 443 adap->fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x80,
428 &stk7700ph_dib7700_xc3028_config); 444 &stk7700ph_dib7700_xc3028_config);
@@ -1187,8 +1203,12 @@ static int stk7070p_frontend_attach(struct dvb_usb_adapter *adap)
1187 msleep(10); 1203 msleep(10);
1188 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1); 1204 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
1189 1205
1190 dib7000p_i2c_enumeration(&adap->dev->i2c_adap, 1, 18, 1206 if (dib7000p_i2c_enumeration(&adap->dev->i2c_adap, 1, 18,
1191 &dib7070p_dib7000p_config); 1207 &dib7070p_dib7000p_config) != 0) {
1208 err("%s: dib7000p_i2c_enumeration failed. Cannot continue\n",
1209 __func__);
1210 return -ENODEV;
1211 }
1192 1212
1193 adap->fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x80, 1213 adap->fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x80,
1194 &dib7070p_dib7000p_config); 1214 &dib7070p_dib7000p_config);
@@ -1244,7 +1264,12 @@ static int stk7070pd_frontend_attach0(struct dvb_usb_adapter *adap)
1244 msleep(10); 1264 msleep(10);
1245 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1); 1265 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
1246 1266
1247 dib7000p_i2c_enumeration(&adap->dev->i2c_adap, 2, 18, stk7070pd_dib7000p_config); 1267 if (dib7000p_i2c_enumeration(&adap->dev->i2c_adap, 2, 18,
1268 stk7070pd_dib7000p_config) != 0) {
1269 err("%s: dib7000p_i2c_enumeration failed. Cannot continue\n",
1270 __func__);
1271 return -ENODEV;
1272 }
1248 1273
1249 adap->fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x80, &stk7070pd_dib7000p_config[0]); 1274 adap->fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x80, &stk7070pd_dib7000p_config[0]);
1250 return adap->fe == NULL ? -ENODEV : 0; 1275 return adap->fe == NULL ? -ENODEV : 0;
@@ -1347,6 +1372,72 @@ static int xc5000_tuner_attach(struct dvb_usb_adapter *adap)
1347 == NULL ? -ENODEV : 0; 1372 == NULL ? -ENODEV : 0;
1348} 1373}
1349 1374
1375static struct lgdt3305_config hcw_lgdt3305_config = {
1376 .i2c_addr = 0x0e,
1377 .mpeg_mode = LGDT3305_MPEG_PARALLEL,
1378 .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
1379 .tpvalid_polarity = LGDT3305_TP_VALID_LOW,
1380 .deny_i2c_rptr = 0,
1381 .spectral_inversion = 1,
1382 .qam_if_khz = 6000,
1383 .vsb_if_khz = 6000,
1384 .usref_8vsb = 0x0500,
1385};
1386
1387static struct mxl5007t_config hcw_mxl5007t_config = {
1388 .xtal_freq_hz = MxL_XTAL_25_MHZ,
1389 .if_freq_hz = MxL_IF_6_MHZ,
1390 .invert_if = 1,
1391};
1392
1393/* TIGER-ATSC map:
1394 GPIO0 - LNA_CTR (H: LNA power enabled, L: LNA power disabled)
1395 GPIO1 - ANT_SEL (H: VPA, L: MCX)
1396 GPIO4 - SCL2
1397 GPIO6 - EN_TUNER
1398 GPIO7 - SDA2
1399 GPIO10 - DEM_RST
1400
1401 MXL is behind LG's i2c repeater. LG is on SCL2/SDA2 gpios on the DIB
1402 */
1403static int lgdt3305_frontend_attach(struct dvb_usb_adapter *adap)
1404{
1405 struct dib0700_state *st = adap->dev->priv;
1406
1407 /* Make use of the new i2c functions from FW 1.20 */
1408 st->fw_use_new_i2c_api = 1;
1409
1410 st->disable_streaming_master_mode = 1;
1411
1412 /* fe power enable */
1413 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 0);
1414 msleep(30);
1415 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
1416 msleep(30);
1417
1418 /* demod reset */
1419 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
1420 msleep(30);
1421 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
1422 msleep(30);
1423 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
1424 msleep(30);
1425
1426 adap->fe = dvb_attach(lgdt3305_attach,
1427 &hcw_lgdt3305_config,
1428 &adap->dev->i2c_adap);
1429
1430 return adap->fe == NULL ? -ENODEV : 0;
1431}
1432
1433static int mxl5007t_tuner_attach(struct dvb_usb_adapter *adap)
1434{
1435 return dvb_attach(mxl5007t_attach, adap->fe,
1436 &adap->dev->i2c_adap, 0x60,
1437 &hcw_mxl5007t_config) == NULL ? -ENODEV : 0;
1438}
1439
1440
1350/* DVB-USB and USB stuff follows */ 1441/* DVB-USB and USB stuff follows */
1351struct usb_device_id dib0700_usb_id_table[] = { 1442struct usb_device_id dib0700_usb_id_table[] = {
1352/* 0 */ { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_STK7700P) }, 1443/* 0 */ { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_STK7700P) },
@@ -1396,6 +1487,12 @@ struct usb_device_id dib0700_usb_id_table[] = {
1396 { USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_EXPRESS) }, 1487 { USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_EXPRESS) },
1397 { USB_DEVICE(USB_VID_TERRATEC, 1488 { USB_DEVICE(USB_VID_TERRATEC,
1398 USB_PID_TERRATEC_CINERGY_DT_XS_DIVERSITY_2) }, 1489 USB_PID_TERRATEC_CINERGY_DT_XS_DIVERSITY_2) },
1490 { USB_DEVICE(USB_VID_SONY, USB_PID_SONY_PLAYTV) },
1491/* 45 */{ USB_DEVICE(USB_VID_YUAN, USB_PID_YUAN_PD378S) },
1492 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_TIGER_ATSC) },
1493 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_TIGER_ATSC_B210) },
1494 { USB_DEVICE(USB_VID_YUAN, USB_PID_YUAN_MC770) },
1495 { USB_DEVICE(USB_VID_ELGATO, USB_PID_ELGATO_EYETV_DTT) },
1399 { 0 } /* Terminating entry */ 1496 { 0 } /* Terminating entry */
1400}; 1497};
1401MODULE_DEVICE_TABLE(usb, dib0700_usb_id_table); 1498MODULE_DEVICE_TABLE(usb, dib0700_usb_id_table);
@@ -1595,7 +1692,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
1595 }, 1692 },
1596 }, 1693 },
1597 1694
1598 .num_device_descs = 9, 1695 .num_device_descs = 11,
1599 .devices = { 1696 .devices = {
1600 { "DiBcom STK7070P reference design", 1697 { "DiBcom STK7070P reference design",
1601 { &dib0700_usb_id_table[15], NULL }, 1698 { &dib0700_usb_id_table[15], NULL },
@@ -1633,6 +1730,14 @@ struct dvb_usb_device_properties dib0700_devices[] = {
1633 { &dib0700_usb_id_table[33], NULL }, 1730 { &dib0700_usb_id_table[33], NULL },
1634 { NULL }, 1731 { NULL },
1635 }, 1732 },
1733 { "Elgato EyeTV DTT",
1734 { &dib0700_usb_id_table[49], NULL },
1735 { NULL },
1736 },
1737 { "Yuan PD378S",
1738 { &dib0700_usb_id_table[45], NULL },
1739 { NULL },
1740 },
1636 }, 1741 },
1637 1742
1638 .rc_interval = DEFAULT_RC_INTERVAL, 1743 .rc_interval = DEFAULT_RC_INTERVAL,
@@ -1661,7 +1766,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
1661 } 1766 }
1662 }, 1767 },
1663 1768
1664 .num_device_descs = 5, 1769 .num_device_descs = 6,
1665 .devices = { 1770 .devices = {
1666 { "DiBcom STK7070PD reference design", 1771 { "DiBcom STK7070PD reference design",
1667 { &dib0700_usb_id_table[17], NULL }, 1772 { &dib0700_usb_id_table[17], NULL },
@@ -1682,8 +1787,16 @@ struct dvb_usb_device_properties dib0700_devices[] = {
1682 { "Terratec Cinergy DT USB XS Diversity", 1787 { "Terratec Cinergy DT USB XS Diversity",
1683 { &dib0700_usb_id_table[43], NULL }, 1788 { &dib0700_usb_id_table[43], NULL },
1684 { NULL }, 1789 { NULL },
1790 },
1791 { "Sony PlayTV",
1792 { &dib0700_usb_id_table[44], NULL },
1793 { NULL },
1685 } 1794 }
1686 } 1795 },
1796 .rc_interval = DEFAULT_RC_INTERVAL,
1797 .rc_key_map = dib0700_rc_keys,
1798 .rc_key_map_size = ARRAY_SIZE(dib0700_rc_keys),
1799 .rc_query = dib0700_rc_query
1687 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES, 1800 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
1688 1801
1689 .num_adapters = 1, 1802 .num_adapters = 1,
@@ -1699,7 +1812,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
1699 }, 1812 },
1700 }, 1813 },
1701 1814
1702 .num_device_descs = 5, 1815 .num_device_descs = 7,
1703 .devices = { 1816 .devices = {
1704 { "Terratec Cinergy HT USB XE", 1817 { "Terratec Cinergy HT USB XE",
1705 { &dib0700_usb_id_table[27], NULL }, 1818 { &dib0700_usb_id_table[27], NULL },
@@ -1725,6 +1838,10 @@ struct dvb_usb_device_properties dib0700_devices[] = {
1725 { &dib0700_usb_id_table[39], NULL }, 1838 { &dib0700_usb_id_table[39], NULL },
1726 { NULL }, 1839 { NULL },
1727 }, 1840 },
1841 { "YUAN High-Tech MC770",
1842 { &dib0700_usb_id_table[48], NULL },
1843 { NULL },
1844 },
1728 }, 1845 },
1729 .rc_interval = DEFAULT_RC_INTERVAL, 1846 .rc_interval = DEFAULT_RC_INTERVAL,
1730 .rc_key_map = dib0700_rc_keys, 1847 .rc_key_map = dib0700_rc_keys,
@@ -1759,6 +1876,31 @@ struct dvb_usb_device_properties dib0700_devices[] = {
1759 .rc_key_map = dib0700_rc_keys, 1876 .rc_key_map = dib0700_rc_keys,
1760 .rc_key_map_size = ARRAY_SIZE(dib0700_rc_keys), 1877 .rc_key_map_size = ARRAY_SIZE(dib0700_rc_keys),
1761 .rc_query = dib0700_rc_query 1878 .rc_query = dib0700_rc_query
1879 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
1880 .num_adapters = 1,
1881 .adapter = {
1882 {
1883 .frontend_attach = lgdt3305_frontend_attach,
1884 .tuner_attach = mxl5007t_tuner_attach,
1885
1886 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
1887
1888 .size_of_priv = sizeof(struct
1889 dib0700_adapter_state),
1890 },
1891 },
1892
1893 .num_device_descs = 2,
1894 .devices = {
1895 { "Hauppauge ATSC MiniCard (B200)",
1896 { &dib0700_usb_id_table[46], NULL },
1897 { NULL },
1898 },
1899 { "Hauppauge ATSC MiniCard (B210)",
1900 { &dib0700_usb_id_table[47], NULL },
1901 { NULL },
1902 },
1903 },
1762 }, 1904 },
1763}; 1905};
1764 1906
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-ids.h b/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
index 0db0c06ee6f2..dc7ea21cd139 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
@@ -27,12 +27,14 @@
27#define USB_VID_DIBCOM 0x10b8 27#define USB_VID_DIBCOM 0x10b8
28#define USB_VID_DPOSH 0x1498 28#define USB_VID_DPOSH 0x1498
29#define USB_VID_DVICO 0x0fe9 29#define USB_VID_DVICO 0x0fe9
30#define USB_VID_ELGATO 0x0fd9
30#define USB_VID_EMPIA 0xeb1a 31#define USB_VID_EMPIA 0xeb1a
31#define USB_VID_GENPIX 0x09c0 32#define USB_VID_GENPIX 0x09c0
32#define USB_VID_GRANDTEC 0x5032 33#define USB_VID_GRANDTEC 0x5032
33#define USB_VID_HANFTEK 0x15f4 34#define USB_VID_HANFTEK 0x15f4
34#define USB_VID_HAUPPAUGE 0x2040 35#define USB_VID_HAUPPAUGE 0x2040
35#define USB_VID_HYPER_PALTEK 0x1025 36#define USB_VID_HYPER_PALTEK 0x1025
37#define USB_VID_INTEL 0x8086
36#define USB_VID_KWORLD 0xeb2a 38#define USB_VID_KWORLD 0xeb2a
37#define USB_VID_KWORLD_2 0x1b80 39#define USB_VID_KWORLD_2 0x1b80
38#define USB_VID_KYE 0x0458 40#define USB_VID_KYE 0x0458
@@ -48,6 +50,7 @@
48#define USB_VID_TERRATEC 0x0ccd 50#define USB_VID_TERRATEC 0x0ccd
49#define USB_VID_TELESTAR 0x10b9 51#define USB_VID_TELESTAR 0x10b9
50#define USB_VID_VISIONPLUS 0x13d3 52#define USB_VID_VISIONPLUS 0x13d3
53#define USB_VID_SONY 0x1415
51#define USB_VID_TWINHAN 0x1822 54#define USB_VID_TWINHAN 0x1822
52#define USB_VID_ULTIMA_ELECTRONIC 0x05d8 55#define USB_VID_ULTIMA_ELECTRONIC 0x05d8
53#define USB_VID_UNIWILL 0x1584 56#define USB_VID_UNIWILL 0x1584
@@ -95,8 +98,10 @@
95#define USB_PID_UNIWILL_STK7700P 0x6003 98#define USB_PID_UNIWILL_STK7700P 0x6003
96#define USB_PID_GRANDTEC_DVBT_USB_COLD 0x0fa0 99#define USB_PID_GRANDTEC_DVBT_USB_COLD 0x0fa0
97#define USB_PID_GRANDTEC_DVBT_USB_WARM 0x0fa1 100#define USB_PID_GRANDTEC_DVBT_USB_WARM 0x0fa1
101#define USB_PID_INTEL_CE9500 0x9500
98#define USB_PID_KWORLD_399U 0xe399 102#define USB_PID_KWORLD_399U 0xe399
99#define USB_PID_KWORLD_395U 0xe396 103#define USB_PID_KWORLD_395U 0xe396
104#define USB_PID_KWORLD_395U_2 0xe39b
100#define USB_PID_KWORLD_PC160_2T 0xc160 105#define USB_PID_KWORLD_PC160_2T 0xc160
101#define USB_PID_KWORLD_VSTREAM_COLD 0x17de 106#define USB_PID_KWORLD_VSTREAM_COLD 0x17de
102#define USB_PID_KWORLD_VSTREAM_WARM 0x17df 107#define USB_PID_KWORLD_VSTREAM_WARM 0x17df
@@ -149,6 +154,8 @@
149#define USB_PID_HAUPPAUGE_MYTV_T 0x7080 154#define USB_PID_HAUPPAUGE_MYTV_T 0x7080
150#define USB_PID_HAUPPAUGE_NOVA_TD_STICK 0x9580 155#define USB_PID_HAUPPAUGE_NOVA_TD_STICK 0x9580
151#define USB_PID_HAUPPAUGE_NOVA_TD_STICK_52009 0x5200 156#define USB_PID_HAUPPAUGE_NOVA_TD_STICK_52009 0x5200
157#define USB_PID_HAUPPAUGE_TIGER_ATSC 0xb200
158#define USB_PID_HAUPPAUGE_TIGER_ATSC_B210 0xb210
152#define USB_PID_AVERMEDIA_EXPRESS 0xb568 159#define USB_PID_AVERMEDIA_EXPRESS 0xb568
153#define USB_PID_AVERMEDIA_VOLAR 0xa807 160#define USB_PID_AVERMEDIA_VOLAR 0xa807
154#define USB_PID_AVERMEDIA_VOLAR_2 0xb808 161#define USB_PID_AVERMEDIA_VOLAR_2 0xb808
@@ -232,9 +239,13 @@
232#define USB_PID_ASUS_U3100 0x173f 239#define USB_PID_ASUS_U3100 0x173f
233#define USB_PID_YUAN_EC372S 0x1edc 240#define USB_PID_YUAN_EC372S 0x1edc
234#define USB_PID_YUAN_STK7700PH 0x1f08 241#define USB_PID_YUAN_STK7700PH 0x1f08
242#define USB_PID_YUAN_PD378S 0x2edc
243#define USB_PID_YUAN_MC770 0x0871
235#define USB_PID_DW2102 0x2102 244#define USB_PID_DW2102 0x2102
236#define USB_PID_XTENSIONS_XD_380 0x0381 245#define USB_PID_XTENSIONS_XD_380 0x0381
237#define USB_PID_TELESTAR_STARSTICK_2 0x8000 246#define USB_PID_TELESTAR_STARSTICK_2 0x8000
238#define USB_PID_MSI_DIGI_VOX_MINI_III 0x8807 247#define USB_PID_MSI_DIGI_VOX_MINI_III 0x8807
248#define USB_PID_SONY_PLAYTV 0x0003
249#define USB_PID_ELGATO_EYETV_DTT 0x0021
239 250
240#endif 251#endif
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb.h b/drivers/media/dvb/dvb-usb/dvb-usb.h
index b1de0f7e26e8..2d5352e54dc0 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb.h
+++ b/drivers/media/dvb/dvb-usb/dvb-usb.h
@@ -223,7 +223,7 @@ struct dvb_usb_device_properties {
223 int generic_bulk_ctrl_endpoint; 223 int generic_bulk_ctrl_endpoint;
224 224
225 int num_device_descs; 225 int num_device_descs;
226 struct dvb_usb_device_description devices[9]; 226 struct dvb_usb_device_description devices[11];
227}; 227};
228 228
229/** 229/**
diff --git a/drivers/media/dvb/firewire/firedtv-avc.c b/drivers/media/dvb/firewire/firedtv-avc.c
index 32526f103b59..12f7730184ad 100644
--- a/drivers/media/dvb/firewire/firedtv-avc.c
+++ b/drivers/media/dvb/firewire/firedtv-avc.c
@@ -151,7 +151,7 @@ static void debug_fcp(const u8 *data, int length)
151 subunit_type = data[1] >> 3; 151 subunit_type = data[1] >> 3;
152 subunit_id = data[1] & 7; 152 subunit_id = data[1] & 7;
153 op = subunit_type == 0x1e || subunit_id == 5 ? ~0 : data[2]; 153 op = subunit_type == 0x1e || subunit_id == 5 ? ~0 : data[2];
154 printk(KERN_INFO "%ssu=%x.%x l=%d: %-8s - %s\n", 154 printk(KERN_INFO "%ssu=%x.%x l=%zu: %-8s - %s\n",
155 prefix, subunit_type, subunit_id, length, 155 prefix, subunit_type, subunit_id, length,
156 debug_fcp_ctype(data[0]), 156 debug_fcp_ctype(data[0]),
157 debug_fcp_opcode(op, data, length)); 157 debug_fcp_opcode(op, data, length));
diff --git a/drivers/media/dvb/frontends/Kconfig b/drivers/media/dvb/frontends/Kconfig
index 00269560793a..a206cee23f73 100644
--- a/drivers/media/dvb/frontends/Kconfig
+++ b/drivers/media/dvb/frontends/Kconfig
@@ -1,17 +1,21 @@
1menu "Customise DVB Frontends"
2 depends on DVB_CORE
3
4config DVB_FE_CUSTOMISE 1config DVB_FE_CUSTOMISE
5 bool "Customise the frontend modules to build" 2 bool "Customise the frontend modules to build"
3 depends on DVB_CORE
6 default N 4 default N
7 help 5 help
8 This allows the user to deselect frontend drivers unnecessary 6 This allows the user to select/deselect frontend drivers for their
9 for their hardware from the build. Use this option with care 7 hardware from the build.
10 as deselecting frontends which are in fact necessary will result 8
11 in DVB devices which cannot be tuned due to lack of driver support. 9 Use this option with care as deselecting frontends which are in fact
10 necessary will result in DVB devices which cannot be tuned due to lack
11 of driver support.
12 12
13 If unsure say N. 13 If unsure say N.
14 14
15if DVB_FE_CUSTOMISE
16
17menu "Customise DVB Frontends"
18
15comment "Multistandard (satellite) frontends" 19comment "Multistandard (satellite) frontends"
16 depends on DVB_CORE 20 depends on DVB_CORE
17 21
@@ -55,6 +59,13 @@ config DVB_MT312
55 help 59 help
56 A DVB-S tuner module. Say Y when you want to support this frontend. 60 A DVB-S tuner module. Say Y when you want to support this frontend.
57 61
62config DVB_ZL10036
63 tristate "Zarlink ZL10036 silicon tuner"
64 depends on DVB_CORE && I2C
65 default m if DVB_FE_CUSTOMISE
66 help
67 A DVB-S tuner module. Say Y when you want to support this frontend.
68
58config DVB_S5H1420 69config DVB_S5H1420
59 tristate "Samsung S5H1420 based" 70 tristate "Samsung S5H1420 based"
60 depends on DVB_CORE && I2C 71 depends on DVB_CORE && I2C
@@ -83,6 +94,20 @@ config DVB_STV0299
83 help 94 help
84 A DVB-S tuner module. Say Y when you want to support this frontend. 95 A DVB-S tuner module. Say Y when you want to support this frontend.
85 96
97config DVB_STV6110
98 tristate "ST STV6110 silicon tuner"
99 depends on DVB_CORE && I2C
100 default m if DVB_FE_CUSTOMISE
101 help
102 A DVB-S silicon tuner module. Say Y when you want to support this tuner.
103
104config DVB_STV0900
105 tristate "ST STV0900 based"
106 depends on DVB_CORE && I2C
107 default m if DVB_FE_CUSTOMISE
108 help
109 A DVB-S/S2 demodulator. Say Y when you want to support this frontend.
110
86config DVB_TDA8083 111config DVB_TDA8083
87 tristate "Philips TDA8083 based" 112 tristate "Philips TDA8083 based"
88 depends on DVB_CORE && I2C 113 depends on DVB_CORE && I2C
@@ -288,6 +313,13 @@ config DVB_TDA10048
288 help 313 help
289 A DVB-T tuner module. Say Y when you want to support this frontend. 314 A DVB-T tuner module. Say Y when you want to support this frontend.
290 315
316config DVB_AF9013
317 tristate "Afatech AF9013 demodulator"
318 depends on DVB_CORE && I2C
319 default m if DVB_FE_CUSTOMISE
320 help
321 Say Y when you want to support this frontend.
322
291comment "DVB-C (cable) frontends" 323comment "DVB-C (cable) frontends"
292 depends on DVB_CORE 324 depends on DVB_CORE
293 325
@@ -387,6 +419,14 @@ config DVB_LGDT3304
387 An ATSC 8VSB and QAM64/256 tuner module. Say Y when you want 419 An ATSC 8VSB and QAM64/256 tuner module. Say Y when you want
388 to support this frontend. 420 to support this frontend.
389 421
422config DVB_LGDT3305
423 tristate "LG Electronics LGDT3305 based"
424 depends on DVB_CORE && I2C
425 default m if DVB_FE_CUSTOMISE
426 help
427 An ATSC 8VSB and QAM64/256 tuner module. Say Y when you want
428 to support this frontend.
429
390config DVB_S5H1409 430config DVB_S5H1409
391 tristate "Samsung S5H1409 based" 431 tristate "Samsung S5H1409 based"
392 depends on DVB_CORE && I2C 432 depends on DVB_CORE && I2C
@@ -397,7 +437,7 @@ config DVB_S5H1409
397 437
398config DVB_AU8522 438config DVB_AU8522
399 tristate "Auvitek AU8522 based" 439 tristate "Auvitek AU8522 based"
400 depends on DVB_CORE && I2C 440 depends on DVB_CORE && I2C && VIDEO_V4L2
401 default m if DVB_FE_CUSTOMISE 441 default m if DVB_FE_CUSTOMISE
402 help 442 help
403 An ATSC 8VSB and QAM64/256 tuner module. Say Y when you want 443 An ATSC 8VSB and QAM64/256 tuner module. Say Y when you want
@@ -446,11 +486,11 @@ comment "SEC control devices for DVB-S"
446 depends on DVB_CORE 486 depends on DVB_CORE
447 487
448config DVB_LNBP21 488config DVB_LNBP21
449 tristate "LNBP21 SEC controller" 489 tristate "LNBP21/LNBH24 SEC controllers"
450 depends on DVB_CORE && I2C 490 depends on DVB_CORE && I2C
451 default m if DVB_FE_CUSTOMISE 491 default m if DVB_FE_CUSTOMISE
452 help 492 help
453 An SEC control chip. 493 An SEC control chips.
454 494
455config DVB_ISL6405 495config DVB_ISL6405
456 tristate "ISL6405 SEC controller" 496 tristate "ISL6405 SEC controller"
@@ -478,11 +518,6 @@ comment "Tools to develop new frontends"
478config DVB_DUMMY_FE 518config DVB_DUMMY_FE
479 tristate "Dummy frontend driver" 519 tristate "Dummy frontend driver"
480 default n 520 default n
481
482config DVB_AF9013
483 tristate "Afatech AF9013 demodulator"
484 depends on DVB_CORE && I2C
485 default m if DVB_FE_CUSTOMISE
486 help
487 Say Y when you want to support this frontend.
488endmenu 521endmenu
522
523endif
diff --git a/drivers/media/dvb/frontends/Makefile b/drivers/media/dvb/frontends/Makefile
index af7bdf0ad4c7..65a336aa1db6 100644
--- a/drivers/media/dvb/frontends/Makefile
+++ b/drivers/media/dvb/frontends/Makefile
@@ -7,6 +7,8 @@ EXTRA_CFLAGS += -Idrivers/media/common/tuners/
7 7
8s921-objs := s921_module.o s921_core.o 8s921-objs := s921_module.o s921_core.o
9stb0899-objs = stb0899_drv.o stb0899_algo.o 9stb0899-objs = stb0899_drv.o stb0899_algo.o
10stv0900-objs = stv0900_core.o stv0900_sw.o
11au8522-objs = au8522_dig.o au8522_decoder.o
10 12
11obj-$(CONFIG_DVB_PLL) += dvb-pll.o 13obj-$(CONFIG_DVB_PLL) += dvb-pll.o
12obj-$(CONFIG_DVB_STV0299) += stv0299.o 14obj-$(CONFIG_DVB_STV0299) += stv0299.o
@@ -28,6 +30,7 @@ obj-$(CONFIG_DVB_TDA1004X) += tda1004x.o
28obj-$(CONFIG_DVB_SP887X) += sp887x.o 30obj-$(CONFIG_DVB_SP887X) += sp887x.o
29obj-$(CONFIG_DVB_NXT6000) += nxt6000.o 31obj-$(CONFIG_DVB_NXT6000) += nxt6000.o
30obj-$(CONFIG_DVB_MT352) += mt352.o 32obj-$(CONFIG_DVB_MT352) += mt352.o
33obj-$(CONFIG_DVB_ZL10036) += zl10036.o
31obj-$(CONFIG_DVB_ZL10353) += zl10353.o 34obj-$(CONFIG_DVB_ZL10353) += zl10353.o
32obj-$(CONFIG_DVB_CX22702) += cx22702.o 35obj-$(CONFIG_DVB_CX22702) += cx22702.o
33obj-$(CONFIG_DVB_DRX397XD) += drx397xD.o 36obj-$(CONFIG_DVB_DRX397XD) += drx397xD.o
@@ -41,6 +44,7 @@ obj-$(CONFIG_DVB_BCM3510) += bcm3510.o
41obj-$(CONFIG_DVB_S5H1420) += s5h1420.o 44obj-$(CONFIG_DVB_S5H1420) += s5h1420.o
42obj-$(CONFIG_DVB_LGDT330X) += lgdt330x.o 45obj-$(CONFIG_DVB_LGDT330X) += lgdt330x.o
43obj-$(CONFIG_DVB_LGDT3304) += lgdt3304.o 46obj-$(CONFIG_DVB_LGDT3304) += lgdt3304.o
47obj-$(CONFIG_DVB_LGDT3305) += lgdt3305.o
44obj-$(CONFIG_DVB_CX24123) += cx24123.o 48obj-$(CONFIG_DVB_CX24123) += cx24123.o
45obj-$(CONFIG_DVB_LNBP21) += lnbp21.o 49obj-$(CONFIG_DVB_LNBP21) += lnbp21.o
46obj-$(CONFIG_DVB_ISL6405) += isl6405.o 50obj-$(CONFIG_DVB_ISL6405) += isl6405.o
@@ -64,4 +68,6 @@ obj-$(CONFIG_DVB_SI21XX) += si21xx.o
64obj-$(CONFIG_DVB_STV0288) += stv0288.o 68obj-$(CONFIG_DVB_STV0288) += stv0288.o
65obj-$(CONFIG_DVB_STB6000) += stb6000.o 69obj-$(CONFIG_DVB_STB6000) += stb6000.o
66obj-$(CONFIG_DVB_S921) += s921.o 70obj-$(CONFIG_DVB_S921) += s921.o
71obj-$(CONFIG_DVB_STV6110) += stv6110.o
72obj-$(CONFIG_DVB_STV0900) += stv0900.o
67 73
diff --git a/drivers/media/dvb/frontends/au8522.h b/drivers/media/dvb/frontends/au8522.h
index 7b94f554a093..565dcf31af57 100644
--- a/drivers/media/dvb/frontends/au8522.h
+++ b/drivers/media/dvb/frontends/au8522.h
@@ -74,6 +74,22 @@ struct dvb_frontend *au8522_attach(const struct au8522_config *config,
74} 74}
75#endif /* CONFIG_DVB_AU8522 */ 75#endif /* CONFIG_DVB_AU8522 */
76 76
77/* Other modes may need to be added later */
78enum au8522_video_input {
79 AU8522_COMPOSITE_CH1 = 1,
80 AU8522_COMPOSITE_CH2,
81 AU8522_COMPOSITE_CH3,
82 AU8522_COMPOSITE_CH4,
83 AU8522_COMPOSITE_CH4_SIF,
84 AU8522_SVIDEO_CH13,
85 AU8522_SVIDEO_CH24,
86};
87
88enum au8522_audio_input {
89 AU8522_AUDIO_NONE,
90 AU8522_AUDIO_SIF,
91};
92
77#endif /* __AU8522_H__ */ 93#endif /* __AU8522_H__ */
78 94
79/* 95/*
diff --git a/drivers/media/dvb/frontends/au8522_decoder.c b/drivers/media/dvb/frontends/au8522_decoder.c
new file mode 100644
index 000000000000..d63e1527dc88
--- /dev/null
+++ b/drivers/media/dvb/frontends/au8522_decoder.c
@@ -0,0 +1,835 @@
1/*
2 * Auvitek AU8522 QAM/8VSB demodulator driver and video decoder
3 *
4 * Copyright (C) 2009 Devin Heitmueller <dheitmueller@linuxtv.org>
5 * Copyright (C) 2005-2008 Auvitek International, Ltd.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * As published by the Free Software Foundation; either version 2
10 * of the License, or (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., 51 Franklin Street, Fifth Floor, Boston, MA
20 * 02110-1301, USA.
21 */
22
23/* Developer notes:
24 *
25 * VBI support is not yet working
26 * Saturation and hue setting are not yet working
27 * Enough is implemented here for CVBS and S-Video inputs, but the actual
28 * analog demodulator code isn't implemented (not needed for xc5000 since it
29 * has its own demodulator and outputs CVBS)
30 *
31 */
32
33#include <linux/kernel.h>
34#include <linux/slab.h>
35#include <linux/videodev2.h>
36#include <linux/i2c.h>
37#include <linux/delay.h>
38#include <media/v4l2-common.h>
39#include <media/v4l2-chip-ident.h>
40#include <media/v4l2-i2c-drv.h>
41#include <media/v4l2-device.h>
42#include "au8522.h"
43#include "au8522_priv.h"
44
45MODULE_AUTHOR("Devin Heitmueller");
46MODULE_LICENSE("GPL");
47
48static int au8522_analog_debug;
49
50
51module_param_named(analog_debug, au8522_analog_debug, int, 0644);
52
53MODULE_PARM_DESC(analog_debug,
54 "Analog debugging messages [0=Off (default) 1=On]");
55
56struct au8522_register_config {
57 u16 reg_name;
58 u8 reg_val[8];
59};
60
61
62/* Video Decoder Filter Coefficients
63 The values are as follows from left to right
64 0="ATV RF" 1="ATV RF13" 2="CVBS" 3="S-Video" 4="PAL" 5=CVBS13" 6="SVideo13"
65*/
66struct au8522_register_config filter_coef[] = {
67 {AU8522_FILTER_COEF_R410, {0x25, 0x00, 0x25, 0x25, 0x00, 0x00, 0x00} },
68 {AU8522_FILTER_COEF_R411, {0x20, 0x00, 0x20, 0x20, 0x00, 0x00, 0x00} },
69 {AU8522_FILTER_COEF_R412, {0x03, 0x00, 0x03, 0x03, 0x00, 0x00, 0x00} },
70 {AU8522_FILTER_COEF_R413, {0xe6, 0x00, 0xe6, 0xe6, 0x00, 0x00, 0x00} },
71 {AU8522_FILTER_COEF_R414, {0x40, 0x00, 0x40, 0x40, 0x00, 0x00, 0x00} },
72 {AU8522_FILTER_COEF_R415, {0x1b, 0x00, 0x1b, 0x1b, 0x00, 0x00, 0x00} },
73 {AU8522_FILTER_COEF_R416, {0xc0, 0x00, 0xc0, 0x04, 0x00, 0x00, 0x00} },
74 {AU8522_FILTER_COEF_R417, {0x04, 0x00, 0x04, 0x04, 0x00, 0x00, 0x00} },
75 {AU8522_FILTER_COEF_R418, {0x8c, 0x00, 0x8c, 0x8c, 0x00, 0x00, 0x00} },
76 {AU8522_FILTER_COEF_R419, {0xa0, 0x40, 0xa0, 0xa0, 0x40, 0x40, 0x40} },
77 {AU8522_FILTER_COEF_R41A, {0x21, 0x09, 0x21, 0x21, 0x09, 0x09, 0x09} },
78 {AU8522_FILTER_COEF_R41B, {0x6c, 0x38, 0x6c, 0x6c, 0x38, 0x38, 0x38} },
79 {AU8522_FILTER_COEF_R41C, {0x03, 0xff, 0x03, 0x03, 0xff, 0xff, 0xff} },
80 {AU8522_FILTER_COEF_R41D, {0xbf, 0xc7, 0xbf, 0xbf, 0xc7, 0xc7, 0xc7} },
81 {AU8522_FILTER_COEF_R41E, {0xa0, 0xdf, 0xa0, 0xa0, 0xdf, 0xdf, 0xdf} },
82 {AU8522_FILTER_COEF_R41F, {0x10, 0x06, 0x10, 0x10, 0x06, 0x06, 0x06} },
83 {AU8522_FILTER_COEF_R420, {0xae, 0x30, 0xae, 0xae, 0x30, 0x30, 0x30} },
84 {AU8522_FILTER_COEF_R421, {0xc4, 0x01, 0xc4, 0xc4, 0x01, 0x01, 0x01} },
85 {AU8522_FILTER_COEF_R422, {0x54, 0xdd, 0x54, 0x54, 0xdd, 0xdd, 0xdd} },
86 {AU8522_FILTER_COEF_R423, {0xd0, 0xaf, 0xd0, 0xd0, 0xaf, 0xaf, 0xaf} },
87 {AU8522_FILTER_COEF_R424, {0x1c, 0xf7, 0x1c, 0x1c, 0xf7, 0xf7, 0xf7} },
88 {AU8522_FILTER_COEF_R425, {0x76, 0xdb, 0x76, 0x76, 0xdb, 0xdb, 0xdb} },
89 {AU8522_FILTER_COEF_R426, {0x61, 0xc0, 0x61, 0x61, 0xc0, 0xc0, 0xc0} },
90 {AU8522_FILTER_COEF_R427, {0xd1, 0x2f, 0xd1, 0xd1, 0x2f, 0x2f, 0x2f} },
91 {AU8522_FILTER_COEF_R428, {0x84, 0xd8, 0x84, 0x84, 0xd8, 0xd8, 0xd8} },
92 {AU8522_FILTER_COEF_R429, {0x06, 0xfb, 0x06, 0x06, 0xfb, 0xfb, 0xfb} },
93 {AU8522_FILTER_COEF_R42A, {0x21, 0xd5, 0x21, 0x21, 0xd5, 0xd5, 0xd5} },
94 {AU8522_FILTER_COEF_R42B, {0x0a, 0x3e, 0x0a, 0x0a, 0x3e, 0x3e, 0x3e} },
95 {AU8522_FILTER_COEF_R42C, {0xe6, 0x15, 0xe6, 0xe6, 0x15, 0x15, 0x15} },
96 {AU8522_FILTER_COEF_R42D, {0x01, 0x34, 0x01, 0x01, 0x34, 0x34, 0x34} },
97
98};
99#define NUM_FILTER_COEF (sizeof(filter_coef)\
100 / sizeof(struct au8522_register_config))
101
102
103/* Registers 0x060b through 0x0652 are the LP Filter coefficients
104 The values are as follows from left to right
105 0="SIF" 1="ATVRF/ATVRF13"
106 Note: the "ATVRF/ATVRF13" mode has never been tested
107*/
108struct au8522_register_config lpfilter_coef[] = {
109 {0x060b, {0x21, 0x0b} },
110 {0x060c, {0xad, 0xad} },
111 {0x060d, {0x70, 0xf0} },
112 {0x060e, {0xea, 0xe9} },
113 {0x060f, {0xdd, 0xdd} },
114 {0x0610, {0x08, 0x64} },
115 {0x0611, {0x60, 0x60} },
116 {0x0612, {0xf8, 0xb2} },
117 {0x0613, {0x01, 0x02} },
118 {0x0614, {0xe4, 0xb4} },
119 {0x0615, {0x19, 0x02} },
120 {0x0616, {0xae, 0x2e} },
121 {0x0617, {0xee, 0xc5} },
122 {0x0618, {0x56, 0x56} },
123 {0x0619, {0x30, 0x58} },
124 {0x061a, {0xf9, 0xf8} },
125 {0x061b, {0x24, 0x64} },
126 {0x061c, {0x07, 0x07} },
127 {0x061d, {0x30, 0x30} },
128 {0x061e, {0xa9, 0xed} },
129 {0x061f, {0x09, 0x0b} },
130 {0x0620, {0x42, 0xc2} },
131 {0x0621, {0x1d, 0x2a} },
132 {0x0622, {0xd6, 0x56} },
133 {0x0623, {0x95, 0x8b} },
134 {0x0624, {0x2b, 0x2b} },
135 {0x0625, {0x30, 0x24} },
136 {0x0626, {0x3e, 0x3e} },
137 {0x0627, {0x62, 0xe2} },
138 {0x0628, {0xe9, 0xf5} },
139 {0x0629, {0x99, 0x19} },
140 {0x062a, {0xd4, 0x11} },
141 {0x062b, {0x03, 0x04} },
142 {0x062c, {0xb5, 0x85} },
143 {0x062d, {0x1e, 0x20} },
144 {0x062e, {0x2a, 0xea} },
145 {0x062f, {0xd7, 0xd2} },
146 {0x0630, {0x15, 0x15} },
147 {0x0631, {0xa3, 0xa9} },
148 {0x0632, {0x1f, 0x1f} },
149 {0x0633, {0xf9, 0xd1} },
150 {0x0634, {0xc0, 0xc3} },
151 {0x0635, {0x4d, 0x8d} },
152 {0x0636, {0x21, 0x31} },
153 {0x0637, {0x83, 0x83} },
154 {0x0638, {0x08, 0x8c} },
155 {0x0639, {0x19, 0x19} },
156 {0x063a, {0x45, 0xa5} },
157 {0x063b, {0xef, 0xec} },
158 {0x063c, {0x8a, 0x8a} },
159 {0x063d, {0xf4, 0xf6} },
160 {0x063e, {0x8f, 0x8f} },
161 {0x063f, {0x44, 0x0c} },
162 {0x0640, {0xef, 0xf0} },
163 {0x0641, {0x66, 0x66} },
164 {0x0642, {0xcc, 0xd2} },
165 {0x0643, {0x41, 0x41} },
166 {0x0644, {0x63, 0x93} },
167 {0x0645, {0x8e, 0x8e} },
168 {0x0646, {0xa2, 0x42} },
169 {0x0647, {0x7b, 0x7b} },
170 {0x0648, {0x04, 0x04} },
171 {0x0649, {0x00, 0x00} },
172 {0x064a, {0x40, 0x40} },
173 {0x064b, {0x8c, 0x98} },
174 {0x064c, {0x00, 0x00} },
175 {0x064d, {0x63, 0xc3} },
176 {0x064e, {0x04, 0x04} },
177 {0x064f, {0x20, 0x20} },
178 {0x0650, {0x00, 0x00} },
179 {0x0651, {0x40, 0x40} },
180 {0x0652, {0x01, 0x01} },
181};
182#define NUM_LPFILTER_COEF (sizeof(lpfilter_coef)\
183 / sizeof(struct au8522_register_config))
184
185static inline struct au8522_state *to_state(struct v4l2_subdev *sd)
186{
187 return container_of(sd, struct au8522_state, sd);
188}
189
190static void setup_vbi(struct au8522_state *state, int aud_input)
191{
192 int i;
193
194 /* These are set to zero regardless of what mode we're in */
195 au8522_writereg(state, AU8522_TVDEC_VBI_CTRL_H_REG017H, 0x00);
196 au8522_writereg(state, AU8522_TVDEC_VBI_CTRL_L_REG018H, 0x00);
197 au8522_writereg(state, AU8522_TVDEC_VBI_USER_TOTAL_BITS_REG019H, 0x00);
198 au8522_writereg(state, AU8522_TVDEC_VBI_USER_TUNIT_H_REG01AH, 0x00);
199 au8522_writereg(state, AU8522_TVDEC_VBI_USER_TUNIT_L_REG01BH, 0x00);
200 au8522_writereg(state, AU8522_TVDEC_VBI_USER_THRESH1_REG01CH, 0x00);
201 au8522_writereg(state, AU8522_TVDEC_VBI_USER_FRAME_PAT2_REG01EH, 0x00);
202 au8522_writereg(state, AU8522_TVDEC_VBI_USER_FRAME_PAT1_REG01FH, 0x00);
203 au8522_writereg(state, AU8522_TVDEC_VBI_USER_FRAME_PAT0_REG020H, 0x00);
204 au8522_writereg(state, AU8522_TVDEC_VBI_USER_FRAME_MASK2_REG021H,
205 0x00);
206 au8522_writereg(state, AU8522_TVDEC_VBI_USER_FRAME_MASK1_REG022H,
207 0x00);
208 au8522_writereg(state, AU8522_TVDEC_VBI_USER_FRAME_MASK0_REG023H,
209 0x00);
210
211 /* Setup the VBI registers */
212 for (i = 0x30; i < 0x60; i++)
213 au8522_writereg(state, i, 0x40);
214
215 /* For some reason, every register is 0x40 except register 0x44
216 (confirmed via the HVR-950q USB capture) */
217 au8522_writereg(state, 0x44, 0x60);
218
219 /* Enable VBI (we always do this regardless of whether the user is
220 viewing closed caption info) */
221 au8522_writereg(state, AU8522_TVDEC_VBI_CTRL_H_REG017H,
222 AU8522_TVDEC_VBI_CTRL_H_REG017H_CCON);
223
224}
225
226static void setup_decoder_defaults(struct au8522_state *state, u8 input_mode)
227{
228 int i;
229 int filter_coef_type;
230
231 /* Provide reasonable defaults for picture tuning values */
232 au8522_writereg(state, AU8522_TVDEC_SHARPNESSREG009H, 0x07);
233 au8522_writereg(state, AU8522_TVDEC_BRIGHTNESS_REG00AH, 0xed);
234 state->brightness = 0xed - 128;
235 au8522_writereg(state, AU8522_TVDEC_CONTRAST_REG00BH, 0x79);
236 state->contrast = 0x79;
237 au8522_writereg(state, AU8522_TVDEC_SATURATION_CB_REG00CH, 0x80);
238 au8522_writereg(state, AU8522_TVDEC_SATURATION_CR_REG00DH, 0x80);
239 au8522_writereg(state, AU8522_TVDEC_HUE_H_REG00EH, 0x00);
240 au8522_writereg(state, AU8522_TVDEC_HUE_L_REG00FH, 0x00);
241
242 /* Other decoder registers */
243 au8522_writereg(state, AU8522_TVDEC_INT_MASK_REG010H, 0x00);
244
245 if (input_mode == 0x23) {
246 /* S-Video input mapping */
247 au8522_writereg(state, AU8522_VIDEO_MODE_REG011H, 0x04);
248 } else {
249 /* All other modes (CVBS/ATVRF etc.) */
250 au8522_writereg(state, AU8522_VIDEO_MODE_REG011H, 0x00);
251 }
252
253 au8522_writereg(state, AU8522_TVDEC_PGA_REG012H,
254 AU8522_TVDEC_PGA_REG012H_CVBS);
255 au8522_writereg(state, AU8522_TVDEC_COMB_MODE_REG015H,
256 AU8522_TVDEC_COMB_MODE_REG015H_CVBS);
257 au8522_writereg(state, AU8522_TVDED_DBG_MODE_REG060H,
258 AU8522_TVDED_DBG_MODE_REG060H_CVBS);
259 au8522_writereg(state, AU8522_TVDEC_FORMAT_CTRL1_REG061H,
260 AU8522_TVDEC_FORMAT_CTRL1_REG061H_CVBS13);
261 au8522_writereg(state, AU8522_TVDEC_FORMAT_CTRL2_REG062H,
262 AU8522_TVDEC_FORMAT_CTRL2_REG062H_CVBS13);
263 au8522_writereg(state, AU8522_TVDEC_VCR_DET_LLIM_REG063H,
264 AU8522_TVDEC_VCR_DET_LLIM_REG063H_CVBS);
265 au8522_writereg(state, AU8522_TVDEC_VCR_DET_HLIM_REG064H,
266 AU8522_TVDEC_VCR_DET_HLIM_REG064H_CVBS);
267 au8522_writereg(state, AU8522_TVDEC_COMB_VDIF_THR1_REG065H,
268 AU8522_TVDEC_COMB_VDIF_THR1_REG065H_CVBS);
269 au8522_writereg(state, AU8522_TVDEC_COMB_VDIF_THR2_REG066H,
270 AU8522_TVDEC_COMB_VDIF_THR2_REG066H_CVBS);
271 au8522_writereg(state, AU8522_TVDEC_COMB_VDIF_THR3_REG067H,
272 AU8522_TVDEC_COMB_VDIF_THR3_REG067H_CVBS);
273 au8522_writereg(state, AU8522_TVDEC_COMB_NOTCH_THR_REG068H,
274 AU8522_TVDEC_COMB_NOTCH_THR_REG068H_CVBS);
275 au8522_writereg(state, AU8522_TVDEC_COMB_HDIF_THR1_REG069H,
276 AU8522_TVDEC_COMB_HDIF_THR1_REG069H_CVBS);
277 au8522_writereg(state, AU8522_TVDEC_COMB_HDIF_THR2_REG06AH,
278 AU8522_TVDEC_COMB_HDIF_THR2_REG06AH_CVBS);
279 au8522_writereg(state, AU8522_TVDEC_COMB_HDIF_THR3_REG06BH,
280 AU8522_TVDEC_COMB_HDIF_THR3_REG06BH_CVBS);
281 au8522_writereg(state, AU8522_TVDEC_COMB_DCDIF_THR1_REG06CH,
282 AU8522_TVDEC_COMB_DCDIF_THR1_REG06CH_CVBS);
283 au8522_writereg(state, AU8522_TVDEC_COMB_DCDIF_THR2_REG06DH,
284 AU8522_TVDEC_COMB_DCDIF_THR2_REG06DH_CVBS);
285 au8522_writereg(state, AU8522_TVDEC_COMB_DCDIF_THR3_REG06EH,
286 AU8522_TVDEC_COMB_DCDIF_THR3_REG06EH_CVBS);
287 au8522_writereg(state, AU8522_TVDEC_UV_SEP_THR_REG06FH,
288 AU8522_TVDEC_UV_SEP_THR_REG06FH_CVBS);
289 au8522_writereg(state, AU8522_TVDEC_COMB_DC_THR1_NTSC_REG070H,
290 AU8522_TVDEC_COMB_DC_THR1_NTSC_REG070H_CVBS);
291 au8522_writereg(state, AU8522_REG071H, AU8522_REG071H_CVBS);
292 au8522_writereg(state, AU8522_REG072H, AU8522_REG072H_CVBS);
293 au8522_writereg(state, AU8522_TVDEC_COMB_DC_THR2_NTSC_REG073H,
294 AU8522_TVDEC_COMB_DC_THR2_NTSC_REG073H_CVBS);
295 au8522_writereg(state, AU8522_REG074H, AU8522_REG074H_CVBS);
296 au8522_writereg(state, AU8522_REG075H, AU8522_REG075H_CVBS);
297 au8522_writereg(state, AU8522_TVDEC_DCAGC_CTRL_REG077H,
298 AU8522_TVDEC_DCAGC_CTRL_REG077H_CVBS);
299 au8522_writereg(state, AU8522_TVDEC_PIC_START_ADJ_REG078H,
300 AU8522_TVDEC_PIC_START_ADJ_REG078H_CVBS);
301 au8522_writereg(state, AU8522_TVDEC_AGC_HIGH_LIMIT_REG079H,
302 AU8522_TVDEC_AGC_HIGH_LIMIT_REG079H_CVBS);
303 au8522_writereg(state, AU8522_TVDEC_MACROVISION_SYNC_THR_REG07AH,
304 AU8522_TVDEC_MACROVISION_SYNC_THR_REG07AH_CVBS);
305 au8522_writereg(state, AU8522_TVDEC_INTRP_CTRL_REG07BH,
306 AU8522_TVDEC_INTRP_CTRL_REG07BH_CVBS);
307 au8522_writereg(state, AU8522_TVDEC_AGC_LOW_LIMIT_REG0E4H,
308 AU8522_TVDEC_AGC_LOW_LIMIT_REG0E4H_CVBS);
309 au8522_writereg(state, AU8522_TOREGAAGC_REG0E5H,
310 AU8522_TOREGAAGC_REG0E5H_CVBS);
311 au8522_writereg(state, AU8522_REG016H, AU8522_REG016H_CVBS);
312
313 setup_vbi(state, 0);
314
315 if (input_mode == AU8522_INPUT_CONTROL_REG081H_SVIDEO_CH13 ||
316 input_mode == AU8522_INPUT_CONTROL_REG081H_SVIDEO_CH24) {
317 /* Despite what the table says, for the HVR-950q we still need
318 to be in CVBS mode for the S-Video input (reason uknown). */
319 /* filter_coef_type = 3; */
320 filter_coef_type = 5;
321 } else {
322 filter_coef_type = 5;
323 }
324
325 /* Load the Video Decoder Filter Coefficients */
326 for (i = 0; i < NUM_FILTER_COEF; i++) {
327 au8522_writereg(state, filter_coef[i].reg_name,
328 filter_coef[i].reg_val[filter_coef_type]);
329 }
330
331 /* It's not clear what these registers are for, but they are always
332 set to the same value regardless of what mode we're in */
333 au8522_writereg(state, AU8522_REG42EH, 0x87);
334 au8522_writereg(state, AU8522_REG42FH, 0xa2);
335 au8522_writereg(state, AU8522_REG430H, 0xbf);
336 au8522_writereg(state, AU8522_REG431H, 0xcb);
337 au8522_writereg(state, AU8522_REG432H, 0xa1);
338 au8522_writereg(state, AU8522_REG433H, 0x41);
339 au8522_writereg(state, AU8522_REG434H, 0x88);
340 au8522_writereg(state, AU8522_REG435H, 0xc2);
341 au8522_writereg(state, AU8522_REG436H, 0x3c);
342}
343
344static void au8522_setup_cvbs_mode(struct au8522_state *state)
345{
346 /* here we're going to try the pre-programmed route */
347 au8522_writereg(state, AU8522_MODULE_CLOCK_CONTROL_REG0A3H,
348 AU8522_MODULE_CLOCK_CONTROL_REG0A3H_CVBS);
349
350 au8522_writereg(state, AU8522_PGA_CONTROL_REG082H, 0x00);
351 au8522_writereg(state, AU8522_CLAMPING_CONTROL_REG083H, 0x0e);
352 au8522_writereg(state, AU8522_PGA_CONTROL_REG082H, 0x10);
353
354 au8522_writereg(state, AU8522_INPUT_CONTROL_REG081H,
355 AU8522_INPUT_CONTROL_REG081H_CVBS_CH1);
356
357 setup_decoder_defaults(state, AU8522_INPUT_CONTROL_REG081H_CVBS_CH1);
358
359 au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H,
360 AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_CVBS);
361}
362
363static void au8522_setup_cvbs_tuner_mode(struct au8522_state *state)
364{
365 /* here we're going to try the pre-programmed route */
366 au8522_writereg(state, AU8522_MODULE_CLOCK_CONTROL_REG0A3H,
367 AU8522_MODULE_CLOCK_CONTROL_REG0A3H_CVBS);
368
369 /* It's not clear why they turn off the PGA before enabling the clamp
370 control, but the Windows trace does it so we will too... */
371 au8522_writereg(state, AU8522_PGA_CONTROL_REG082H, 0x00);
372
373 /* Enable clamping control */
374 au8522_writereg(state, AU8522_CLAMPING_CONTROL_REG083H, 0x0e);
375
376 /* Turn on the PGA */
377 au8522_writereg(state, AU8522_PGA_CONTROL_REG082H, 0x10);
378
379 /* Set input mode to CVBS on channel 4 with SIF audio input enabled */
380 au8522_writereg(state, AU8522_INPUT_CONTROL_REG081H,
381 AU8522_INPUT_CONTROL_REG081H_CVBS_CH4_SIF);
382
383 setup_decoder_defaults(state,
384 AU8522_INPUT_CONTROL_REG081H_CVBS_CH4_SIF);
385
386 au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H,
387 AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_CVBS);
388}
389
390static void au8522_setup_svideo_mode(struct au8522_state *state)
391{
392 au8522_writereg(state, AU8522_MODULE_CLOCK_CONTROL_REG0A3H,
393 AU8522_MODULE_CLOCK_CONTROL_REG0A3H_SVIDEO);
394
395 /* Set input to Y on Channe1, C on Channel 3 */
396 au8522_writereg(state, AU8522_INPUT_CONTROL_REG081H,
397 AU8522_INPUT_CONTROL_REG081H_SVIDEO_CH13);
398
399 /* Disable clamping control (required for S-video) */
400 au8522_writereg(state, AU8522_CLAMPING_CONTROL_REG083H, 0x00);
401
402 setup_decoder_defaults(state,
403 AU8522_INPUT_CONTROL_REG081H_SVIDEO_CH13);
404
405 au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H,
406 AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_CVBS);
407}
408
409/* ----------------------------------------------------------------------- */
410
411static void disable_audio_input(struct au8522_state *state)
412{
413 /* This can probably be optimized */
414 au8522_writereg(state, AU8522_AUDIO_VOLUME_L_REG0F2H, 0x00);
415 au8522_writereg(state, AU8522_AUDIO_VOLUME_R_REG0F3H, 0x00);
416 au8522_writereg(state, AU8522_AUDIO_VOLUME_REG0F4H, 0x00);
417 au8522_writereg(state, AU8522_I2C_CONTROL_REG1_REG091H, 0x80);
418 au8522_writereg(state, AU8522_I2C_CONTROL_REG0_REG090H, 0x84);
419
420 au8522_writereg(state, AU8522_ENA_USB_REG101H, 0x00);
421 au8522_writereg(state, AU8522_AUDIO_VOLUME_L_REG0F2H, 0x7F);
422 au8522_writereg(state, AU8522_AUDIO_VOLUME_R_REG0F3H, 0x7F);
423 au8522_writereg(state, AU8522_REG0F9H, AU8522_REG0F9H_AUDIO);
424 au8522_writereg(state, AU8522_AUDIO_MODE_REG0F1H, 0x40);
425
426 au8522_writereg(state, AU8522_GPIO_DATA_REG0E2H, 0x11);
427 msleep(5);
428 au8522_writereg(state, AU8522_GPIO_DATA_REG0E2H, 0x00);
429
430 au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H, 0x04);
431 au8522_writereg(state, AU8522_AUDIOFREQ_REG606H, 0x03);
432 au8522_writereg(state, AU8522_I2S_CTRL_2_REG112H, 0x02);
433
434 au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H,
435 AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_CVBS);
436}
437
438/* 0=disable, 1=SIF */
439static void set_audio_input(struct au8522_state *state, int aud_input)
440{
441 int i;
442
443 /* Note that this function needs to be used in conjunction with setting
444 the input routing via register 0x81 */
445
446 if (aud_input == AU8522_AUDIO_NONE) {
447 disable_audio_input(state);
448 return;
449 }
450
451 if (aud_input != AU8522_AUDIO_SIF) {
452 /* The caller asked for a mode we don't currently support */
453 printk(KERN_ERR "Unsupported audio mode requested! mode=%d\n",
454 aud_input);
455 return;
456 }
457
458 /* Load the Audio Decoder Filter Coefficients */
459 for (i = 0; i < NUM_LPFILTER_COEF; i++) {
460 au8522_writereg(state, lpfilter_coef[i].reg_name,
461 lpfilter_coef[i].reg_val[0]);
462 }
463
464 /* Setup audio */
465 au8522_writereg(state, AU8522_AUDIO_VOLUME_L_REG0F2H, 0x00);
466 au8522_writereg(state, AU8522_AUDIO_VOLUME_R_REG0F3H, 0x00);
467 au8522_writereg(state, AU8522_AUDIO_VOLUME_REG0F4H, 0x00);
468 au8522_writereg(state, AU8522_I2C_CONTROL_REG1_REG091H, 0x80);
469 au8522_writereg(state, AU8522_I2C_CONTROL_REG0_REG090H, 0x84);
470 msleep(150);
471 au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H, 0x00);
472 msleep(1);
473 au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H, 0x9d);
474 msleep(50);
475 au8522_writereg(state, AU8522_AUDIO_VOLUME_L_REG0F2H, 0x7F);
476 au8522_writereg(state, AU8522_AUDIO_VOLUME_R_REG0F3H, 0x7F);
477 au8522_writereg(state, AU8522_AUDIO_VOLUME_REG0F4H, 0xff);
478 msleep(80);
479 au8522_writereg(state, AU8522_AUDIO_VOLUME_L_REG0F2H, 0x7F);
480 au8522_writereg(state, AU8522_AUDIO_VOLUME_R_REG0F3H, 0x7F);
481 au8522_writereg(state, AU8522_REG0F9H, AU8522_REG0F9H_AUDIO);
482 au8522_writereg(state, AU8522_AUDIO_MODE_REG0F1H, 0x82);
483 msleep(70);
484 au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H, 0x09);
485 au8522_writereg(state, AU8522_AUDIOFREQ_REG606H, 0x03);
486 au8522_writereg(state, AU8522_I2S_CTRL_2_REG112H, 0xc2);
487}
488
489/* ----------------------------------------------------------------------- */
490
491static int au8522_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
492{
493 struct au8522_state *state = to_state(sd);
494
495 switch (ctrl->id) {
496 case V4L2_CID_BRIGHTNESS:
497 state->brightness = ctrl->value;
498 au8522_writereg(state, AU8522_TVDEC_BRIGHTNESS_REG00AH,
499 ctrl->value - 128);
500 break;
501 case V4L2_CID_CONTRAST:
502 state->contrast = ctrl->value;
503 au8522_writereg(state, AU8522_TVDEC_CONTRAST_REG00BH,
504 ctrl->value);
505 break;
506 case V4L2_CID_SATURATION:
507 case V4L2_CID_HUE:
508 case V4L2_CID_AUDIO_VOLUME:
509 case V4L2_CID_AUDIO_BASS:
510 case V4L2_CID_AUDIO_TREBLE:
511 case V4L2_CID_AUDIO_BALANCE:
512 case V4L2_CID_AUDIO_MUTE:
513 /* Not yet implemented */
514 default:
515 return -EINVAL;
516 }
517
518 return 0;
519}
520
521static int au8522_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
522{
523 struct au8522_state *state = to_state(sd);
524
525 /* Note that we are using values cached in the state structure instead
526 of reading the registers due to issues with i2c reads not working
527 properly/consistently yet on the HVR-950q */
528
529 switch (ctrl->id) {
530 case V4L2_CID_BRIGHTNESS:
531 ctrl->value = state->brightness;
532 break;
533 case V4L2_CID_CONTRAST:
534 ctrl->value = state->contrast;
535 break;
536 case V4L2_CID_SATURATION:
537 case V4L2_CID_HUE:
538 case V4L2_CID_AUDIO_VOLUME:
539 case V4L2_CID_AUDIO_BASS:
540 case V4L2_CID_AUDIO_TREBLE:
541 case V4L2_CID_AUDIO_BALANCE:
542 case V4L2_CID_AUDIO_MUTE:
543 /* Not yet supported */
544 default:
545 return -EINVAL;
546 }
547
548 return 0;
549}
550
551/* ----------------------------------------------------------------------- */
552
553static int au8522_g_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt)
554{
555 switch (fmt->type) {
556 default:
557 return -EINVAL;
558 }
559 return 0;
560}
561
562static int au8522_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt)
563{
564 switch (fmt->type) {
565 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
566 /* Not yet implemented */
567 break;
568 default:
569 return -EINVAL;
570 }
571
572 return 0;
573}
574
575/* ----------------------------------------------------------------------- */
576
577#ifdef CONFIG_VIDEO_ADV_DEBUG
578static int au8522_g_register(struct v4l2_subdev *sd,
579 struct v4l2_dbg_register *reg)
580{
581 struct i2c_client *client = v4l2_get_subdevdata(sd);
582 struct au8522_state *state = to_state(sd);
583
584 if (!v4l2_chip_match_i2c_client(client, &reg->match))
585 return -EINVAL;
586 if (!capable(CAP_SYS_ADMIN))
587 return -EPERM;
588 reg->val = au8522_readreg(state, reg->reg & 0xffff);
589 return 0;
590}
591
592static int au8522_s_register(struct v4l2_subdev *sd,
593 struct v4l2_dbg_register *reg)
594{
595 struct i2c_client *client = v4l2_get_subdevdata(sd);
596 struct au8522_state *state = to_state(sd);
597
598 if (!v4l2_chip_match_i2c_client(client, &reg->match))
599 return -EINVAL;
600 if (!capable(CAP_SYS_ADMIN))
601 return -EPERM;
602 au8522_writereg(state, reg->reg, reg->val & 0xff);
603 return 0;
604}
605#endif
606
607static int au8522_s_stream(struct v4l2_subdev *sd, int enable)
608{
609 struct au8522_state *state = to_state(sd);
610
611 if (enable) {
612 au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H,
613 0x01);
614 msleep(1);
615 au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H,
616 AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_CVBS);
617 } else {
618 /* This does not completely power down the device
619 (it only reduces it from around 140ma to 80ma) */
620 au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H,
621 1 << 5);
622 }
623 return 0;
624}
625
626static int au8522_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc)
627{
628 switch (qc->id) {
629 case V4L2_CID_CONTRAST:
630 return v4l2_ctrl_query_fill(qc, 0, 255, 1,
631 AU8522_TVDEC_CONTRAST_REG00BH_CVBS);
632 case V4L2_CID_BRIGHTNESS:
633 return v4l2_ctrl_query_fill(qc, 0, 255, 1, 128);
634 case V4L2_CID_SATURATION:
635 case V4L2_CID_HUE:
636 /* Not yet implemented */
637 default:
638 break;
639 }
640
641 qc->type = 0;
642 return -EINVAL;
643}
644
645static int au8522_reset(struct v4l2_subdev *sd, u32 val)
646{
647 struct au8522_state *state = to_state(sd);
648
649 au8522_writereg(state, 0xa4, 1 << 5);
650
651 return 0;
652}
653
654static int au8522_s_video_routing(struct v4l2_subdev *sd,
655 const struct v4l2_routing *route)
656{
657 struct au8522_state *state = to_state(sd);
658
659 au8522_reset(sd, 0);
660
661 /* Jam open the i2c gate to the tuner. We do this here to handle the
662 case where the user went into digital mode (causing the gate to be
663 closed), and then came back to analog mode */
664 au8522_writereg(state, 0x106, 1);
665
666 if (route->input == AU8522_COMPOSITE_CH1) {
667 au8522_setup_cvbs_mode(state);
668 } else if (route->input == AU8522_SVIDEO_CH13) {
669 au8522_setup_svideo_mode(state);
670 } else if (route->input == AU8522_COMPOSITE_CH4_SIF) {
671 au8522_setup_cvbs_tuner_mode(state);
672 } else {
673 printk(KERN_ERR "au8522 mode not currently supported\n");
674 return -EINVAL;
675 }
676 return 0;
677}
678
679static int au8522_s_audio_routing(struct v4l2_subdev *sd,
680 const struct v4l2_routing *route)
681{
682 struct au8522_state *state = to_state(sd);
683 set_audio_input(state, route->input);
684 return 0;
685}
686
687static int au8522_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
688{
689 int val = 0;
690 struct au8522_state *state = to_state(sd);
691 u8 lock_status;
692
693 /* Interrogate the decoder to see if we are getting a real signal */
694 lock_status = au8522_readreg(state, 0x00);
695 if (lock_status == 0xa2)
696 vt->signal = 0x01;
697 else
698 vt->signal = 0x00;
699
700 vt->capability |=
701 V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_LANG1 |
702 V4L2_TUNER_CAP_LANG2 | V4L2_TUNER_CAP_SAP;
703
704 val = V4L2_TUNER_SUB_MONO;
705 vt->rxsubchans = val;
706 vt->audmode = V4L2_TUNER_MODE_STEREO;
707 return 0;
708}
709
710static int au8522_g_chip_ident(struct v4l2_subdev *sd,
711 struct v4l2_dbg_chip_ident *chip)
712{
713 struct au8522_state *state = to_state(sd);
714 struct i2c_client *client = v4l2_get_subdevdata(sd);
715
716 return v4l2_chip_ident_i2c_client(client, chip, state->id, state->rev);
717}
718
719static int au8522_log_status(struct v4l2_subdev *sd)
720{
721 /* FIXME: Add some status info here */
722 return 0;
723}
724
725/* ----------------------------------------------------------------------- */
726
727static const struct v4l2_subdev_core_ops au8522_core_ops = {
728 .log_status = au8522_log_status,
729 .g_chip_ident = au8522_g_chip_ident,
730 .g_ctrl = au8522_g_ctrl,
731 .s_ctrl = au8522_s_ctrl,
732 .queryctrl = au8522_queryctrl,
733 .reset = au8522_reset,
734#ifdef CONFIG_VIDEO_ADV_DEBUG
735 .g_register = au8522_g_register,
736 .s_register = au8522_s_register,
737#endif
738};
739
740static const struct v4l2_subdev_tuner_ops au8522_tuner_ops = {
741 .g_tuner = au8522_g_tuner,
742};
743
744static const struct v4l2_subdev_audio_ops au8522_audio_ops = {
745 .s_routing = au8522_s_audio_routing,
746};
747
748static const struct v4l2_subdev_video_ops au8522_video_ops = {
749 .s_routing = au8522_s_video_routing,
750 .g_fmt = au8522_g_fmt,
751 .s_fmt = au8522_s_fmt,
752 .s_stream = au8522_s_stream,
753};
754
755static const struct v4l2_subdev_ops au8522_ops = {
756 .core = &au8522_core_ops,
757 .tuner = &au8522_tuner_ops,
758 .audio = &au8522_audio_ops,
759 .video = &au8522_video_ops,
760};
761
762/* ----------------------------------------------------------------------- */
763
764static int au8522_probe(struct i2c_client *client,
765 const struct i2c_device_id *did)
766{
767 struct au8522_state *state;
768 struct v4l2_subdev *sd;
769 int instance;
770 struct au8522_config *demod_config;
771
772 /* Check if the adapter supports the needed features */
773 if (!i2c_check_functionality(client->adapter,
774 I2C_FUNC_SMBUS_BYTE_DATA)) {
775 return -EIO;
776 }
777
778 /* allocate memory for the internal state */
779 instance = au8522_get_state(&state, client->adapter, client->addr);
780 switch (instance) {
781 case 0:
782 printk(KERN_ERR "au8522_decoder allocation failed\n");
783 return -EIO;
784 case 1:
785 /* new demod instance */
786 printk(KERN_INFO "au8522_decoder creating new instance...\n");
787 break;
788 default:
789 /* existing demod instance */
790 printk(KERN_INFO "au8522_decoder attach existing instance.\n");
791 break;
792 }
793
794 demod_config = kzalloc(sizeof(struct au8522_config), GFP_KERNEL);
795 demod_config->demod_address = 0x8e >> 1;
796
797 state->config = demod_config;
798 state->i2c = client->adapter;
799
800 sd = &state->sd;
801 v4l2_i2c_subdev_init(sd, client, &au8522_ops);
802
803 state->c = client;
804 state->vid_input = AU8522_COMPOSITE_CH1;
805 state->aud_input = AU8522_AUDIO_NONE;
806 state->id = 8522;
807 state->rev = 0;
808
809 /* Jam open the i2c gate to the tuner */
810 au8522_writereg(state, 0x106, 1);
811
812 return 0;
813}
814
815static int au8522_remove(struct i2c_client *client)
816{
817 struct v4l2_subdev *sd = i2c_get_clientdata(client);
818 v4l2_device_unregister_subdev(sd);
819 au8522_release_state(to_state(sd));
820 return 0;
821}
822
823static const struct i2c_device_id au8522_id[] = {
824 {"au8522", 0},
825 {}
826};
827
828MODULE_DEVICE_TABLE(i2c, au8522_id);
829
830static struct v4l2_i2c_driver_data v4l2_i2c_data = {
831 .name = "au8522",
832 .probe = au8522_probe,
833 .remove = au8522_remove,
834 .id_table = au8522_id,
835};
diff --git a/drivers/media/dvb/frontends/au8522.c b/drivers/media/dvb/frontends/au8522_dig.c
index eabf9a68e7ec..35731258bb0a 100644
--- a/drivers/media/dvb/frontends/au8522.c
+++ b/drivers/media/dvb/frontends/au8522_dig.c
@@ -27,35 +27,25 @@
27#include <linux/delay.h> 27#include <linux/delay.h>
28#include "dvb_frontend.h" 28#include "dvb_frontend.h"
29#include "au8522.h" 29#include "au8522.h"
30 30#include "au8522_priv.h"
31struct au8522_state {
32
33 struct i2c_adapter *i2c;
34
35 /* configuration settings */
36 const struct au8522_config *config;
37
38 struct dvb_frontend frontend;
39
40 u32 current_frequency;
41 fe_modulation_t current_modulation;
42
43 u32 fe_status;
44 unsigned int led_state;
45};
46 31
47static int debug; 32static int debug;
48 33
49#define dprintk(arg...) do { \ 34/* Despite the name "hybrid_tuner", the framework works just as well for
50 if (debug) \ 35 hybrid demodulators as well... */
51 printk(arg); \ 36static LIST_HEAD(hybrid_tuner_instance_list);
37static DEFINE_MUTEX(au8522_list_mutex);
38
39#define dprintk(arg...)\
40 do { if (debug)\
41 printk(arg);\
52 } while (0) 42 } while (0)
53 43
54/* 16 bit registers, 8 bit values */ 44/* 16 bit registers, 8 bit values */
55static int au8522_writereg(struct au8522_state *state, u16 reg, u8 data) 45int au8522_writereg(struct au8522_state *state, u16 reg, u8 data)
56{ 46{
57 int ret; 47 int ret;
58 u8 buf [] = { reg >> 8, reg & 0xff, data }; 48 u8 buf[] = { (reg >> 8) | 0x80, reg & 0xff, data };
59 49
60 struct i2c_msg msg = { .addr = state->config->demod_address, 50 struct i2c_msg msg = { .addr = state->config->demod_address,
61 .flags = 0, .buf = buf, .len = 3 }; 51 .flags = 0, .buf = buf, .len = 3 };
@@ -69,13 +59,13 @@ static int au8522_writereg(struct au8522_state *state, u16 reg, u8 data)
69 return (ret != 1) ? -1 : 0; 59 return (ret != 1) ? -1 : 0;
70} 60}
71 61
72static u8 au8522_readreg(struct au8522_state *state, u16 reg) 62u8 au8522_readreg(struct au8522_state *state, u16 reg)
73{ 63{
74 int ret; 64 int ret;
75 u8 b0 [] = { reg >> 8, reg & 0xff }; 65 u8 b0[] = { (reg >> 8) | 0x40, reg & 0xff };
76 u8 b1 [] = { 0 }; 66 u8 b1[] = { 0 };
77 67
78 struct i2c_msg msg [] = { 68 struct i2c_msg msg[] = {
79 { .addr = state->config->demod_address, .flags = 0, 69 { .addr = state->config->demod_address, .flags = 0,
80 .buf = b0, .len = 2 }, 70 .buf = b0, .len = 2 },
81 { .addr = state->config->demod_address, .flags = I2C_M_RD, 71 { .addr = state->config->demod_address, .flags = I2C_M_RD,
@@ -528,7 +518,7 @@ static int au8522_set_frontend(struct dvb_frontend *fe,
528 518
529/* Reset the demod hardware and reset all of the configuration registers 519/* Reset the demod hardware and reset all of the configuration registers
530 to a default state. */ 520 to a default state. */
531static int au8522_init(struct dvb_frontend *fe) 521int au8522_init(struct dvb_frontend *fe)
532{ 522{
533 struct au8522_state *state = fe->demodulator_priv; 523 struct au8522_state *state = fe->demodulator_priv;
534 dprintk("%s()\n", __func__); 524 dprintk("%s()\n", __func__);
@@ -624,7 +614,7 @@ static int au8522_led_ctrl(struct au8522_state *state, int led)
624 return 0; 614 return 0;
625} 615}
626 616
627static int au8522_sleep(struct dvb_frontend *fe) 617int au8522_sleep(struct dvb_frontend *fe)
628{ 618{
629 struct au8522_state *state = fe->demodulator_priv; 619 struct au8522_state *state = fe->demodulator_priv;
630 dprintk("%s()\n", __func__); 620 dprintk("%s()\n", __func__);
@@ -632,6 +622,9 @@ static int au8522_sleep(struct dvb_frontend *fe)
632 /* turn off led */ 622 /* turn off led */
633 au8522_led_ctrl(state, 0); 623 au8522_led_ctrl(state, 0);
634 624
625 /* Power down the chip */
626 au8522_writereg(state, 0xa4, 1 << 5);
627
635 state->current_frequency = 0; 628 state->current_frequency = 0;
636 629
637 return 0; 630 return 0;
@@ -798,23 +791,58 @@ static int au8522_get_tune_settings(struct dvb_frontend *fe,
798 return 0; 791 return 0;
799} 792}
800 793
794static struct dvb_frontend_ops au8522_ops;
795
796int au8522_get_state(struct au8522_state **state, struct i2c_adapter *i2c,
797 u8 client_address)
798{
799 int ret;
800
801 mutex_lock(&au8522_list_mutex);
802 ret = hybrid_tuner_request_state(struct au8522_state, (*state),
803 hybrid_tuner_instance_list,
804 i2c, client_address, "au8522");
805 mutex_unlock(&au8522_list_mutex);
806
807 return ret;
808}
809
810void au8522_release_state(struct au8522_state *state)
811{
812 mutex_lock(&au8522_list_mutex);
813 if (state != NULL)
814 hybrid_tuner_release_state(state);
815 mutex_unlock(&au8522_list_mutex);
816}
817
818
801static void au8522_release(struct dvb_frontend *fe) 819static void au8522_release(struct dvb_frontend *fe)
802{ 820{
803 struct au8522_state *state = fe->demodulator_priv; 821 struct au8522_state *state = fe->demodulator_priv;
804 kfree(state); 822 au8522_release_state(state);
805} 823}
806 824
807static struct dvb_frontend_ops au8522_ops;
808
809struct dvb_frontend *au8522_attach(const struct au8522_config *config, 825struct dvb_frontend *au8522_attach(const struct au8522_config *config,
810 struct i2c_adapter *i2c) 826 struct i2c_adapter *i2c)
811{ 827{
812 struct au8522_state *state = NULL; 828 struct au8522_state *state = NULL;
829 int instance;
813 830
814 /* allocate memory for the internal state */ 831 /* allocate memory for the internal state */
815 state = kmalloc(sizeof(struct au8522_state), GFP_KERNEL); 832 instance = au8522_get_state(&state, i2c, config->demod_address);
816 if (state == NULL) 833 switch (instance) {
817 goto error; 834 case 0:
835 dprintk("%s state allocation failed\n", __func__);
836 break;
837 case 1:
838 /* new demod instance */
839 dprintk("%s using new instance\n", __func__);
840 break;
841 default:
842 /* existing demod instance */
843 dprintk("%s using existing instance\n", __func__);
844 break;
845 }
818 846
819 /* setup the state */ 847 /* setup the state */
820 state->config = config; 848 state->config = config;
@@ -836,7 +864,7 @@ struct dvb_frontend *au8522_attach(const struct au8522_config *config,
836 return &state->frontend; 864 return &state->frontend;
837 865
838error: 866error:
839 kfree(state); 867 au8522_release_state(state);
840 return NULL; 868 return NULL;
841} 869}
842EXPORT_SYMBOL(au8522_attach); 870EXPORT_SYMBOL(au8522_attach);
diff --git a/drivers/media/dvb/frontends/au8522_priv.h b/drivers/media/dvb/frontends/au8522_priv.h
new file mode 100644
index 000000000000..f328f2b3ad3d
--- /dev/null
+++ b/drivers/media/dvb/frontends/au8522_priv.h
@@ -0,0 +1,412 @@
1/*
2 Auvitek AU8522 QAM/8VSB demodulator driver
3
4 Copyright (C) 2008 Steven Toth <stoth@linuxtv.org>
5 Copyright (C) 2008 Devin Heitmueller <dheitmueller@linuxtv.org>
6 Copyright (C) 2005-2008 Auvitek International, Ltd.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
22*/
23
24#include <linux/kernel.h>
25#include <linux/init.h>
26#include <linux/module.h>
27#include <linux/string.h>
28#include <linux/slab.h>
29#include <linux/delay.h>
30#include <linux/videodev2.h>
31#include <media/v4l2-device.h>
32#include <linux/i2c.h>
33#include "dvb_frontend.h"
34#include "au8522.h"
35#include "tuner-i2c.h"
36
37struct au8522_state {
38 struct i2c_client *c;
39 struct i2c_adapter *i2c;
40
41 /* Used for sharing of the state between analog and digital mode */
42 struct tuner_i2c_props i2c_props;
43 struct list_head hybrid_tuner_instance_list;
44
45 /* configuration settings */
46 const struct au8522_config *config;
47
48 struct dvb_frontend frontend;
49
50 u32 current_frequency;
51 fe_modulation_t current_modulation;
52
53 u32 fe_status;
54 unsigned int led_state;
55
56 /* Analog settings */
57 struct v4l2_subdev sd;
58 v4l2_std_id std;
59 int vid_input;
60 int aud_input;
61 u32 id;
62 u32 rev;
63 u8 brightness;
64 u8 contrast;
65};
66
67/* These are routines shared by both the VSB/QAM demodulator and the analog
68 decoder */
69int au8522_writereg(struct au8522_state *state, u16 reg, u8 data);
70u8 au8522_readreg(struct au8522_state *state, u16 reg);
71int au8522_init(struct dvb_frontend *fe);
72int au8522_sleep(struct dvb_frontend *fe);
73
74int au8522_get_state(struct au8522_state **state, struct i2c_adapter *i2c,
75 u8 client_address);
76void au8522_release_state(struct au8522_state *state);
77
78/* REGISTERS */
79#define AU8522_INPUT_CONTROL_REG081H 0x081
80#define AU8522_PGA_CONTROL_REG082H 0x082
81#define AU8522_CLAMPING_CONTROL_REG083H 0x083
82
83#define AU8522_MODULE_CLOCK_CONTROL_REG0A3H 0x0A3
84#define AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H 0x0A4
85#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H 0x0A5
86#define AU8522_AGC_CONTROL_RANGE_REG0A6H 0x0A6
87#define AU8522_SYSTEM_GAIN_CONTROL_REG0A7H 0x0A7
88#define AU8522_TUNER_AGC_RF_STOP_REG0A8H 0x0A8
89#define AU8522_TUNER_AGC_RF_START_REG0A9H 0x0A9
90#define AU8522_TUNER_RF_AGC_DEFAULT_REG0AAH 0x0AA
91#define AU8522_TUNER_AGC_IF_STOP_REG0ABH 0x0AB
92#define AU8522_TUNER_AGC_IF_START_REG0ACH 0x0AC
93#define AU8522_TUNER_AGC_IF_DEFAULT_REG0ADH 0x0AD
94#define AU8522_TUNER_AGC_STEP_REG0AEH 0x0AE
95#define AU8522_TUNER_GAIN_STEP_REG0AFH 0x0AF
96
97/* Receiver registers */
98#define AU8522_FRMREGTHRD1_REG0B0H 0x0B0
99#define AU8522_FRMREGAGC1H_REG0B1H 0x0B1
100#define AU8522_FRMREGSHIFT1_REG0B2H 0x0B2
101#define AU8522_TOREGAGC1_REG0B3H 0x0B3
102#define AU8522_TOREGASHIFT1_REG0B4H 0x0B4
103#define AU8522_FRMREGBBH_REG0B5H 0x0B5
104#define AU8522_FRMREGBBM_REG0B6H 0x0B6
105#define AU8522_FRMREGBBL_REG0B7H 0x0B7
106/* 0xB8 TO 0xD7 are the filter coefficients */
107#define AU8522_FRMREGTHRD2_REG0D8H 0x0D8
108#define AU8522_FRMREGAGC2H_REG0D9H 0x0D9
109#define AU8522_TOREGAGC2_REG0DAH 0x0DA
110#define AU8522_TOREGSHIFT2_REG0DBH 0x0DB
111#define AU8522_FRMREGPILOTH_REG0DCH 0x0DC
112#define AU8522_FRMREGPILOTM_REG0DDH 0x0DD
113#define AU8522_FRMREGPILOTL_REG0DEH 0x0DE
114#define AU8522_TOREGFREQ_REG0DFH 0x0DF
115
116#define AU8522_RX_PGA_RFOUT_REG0EBH 0x0EB
117#define AU8522_RX_PGA_IFOUT_REG0ECH 0x0EC
118#define AU8522_RX_PGA_PGAOUT_REG0EDH 0x0ED
119
120#define AU8522_CHIP_MODE_REG0FEH 0x0FE
121
122/* I2C bus control registers */
123#define AU8522_I2C_CONTROL_REG0_REG090H 0x090
124#define AU8522_I2C_CONTROL_REG1_REG091H 0x091
125#define AU8522_I2C_STATUS_REG092H 0x092
126#define AU8522_I2C_WR_DATA0_REG093H 0x093
127#define AU8522_I2C_WR_DATA1_REG094H 0x094
128#define AU8522_I2C_WR_DATA2_REG095H 0x095
129#define AU8522_I2C_WR_DATA3_REG096H 0x096
130#define AU8522_I2C_WR_DATA4_REG097H 0x097
131#define AU8522_I2C_WR_DATA5_REG098H 0x098
132#define AU8522_I2C_WR_DATA6_REG099H 0x099
133#define AU8522_I2C_WR_DATA7_REG09AH 0x09A
134#define AU8522_I2C_RD_DATA0_REG09BH 0x09B
135#define AU8522_I2C_RD_DATA1_REG09CH 0x09C
136#define AU8522_I2C_RD_DATA2_REG09DH 0x09D
137#define AU8522_I2C_RD_DATA3_REG09EH 0x09E
138#define AU8522_I2C_RD_DATA4_REG09FH 0x09F
139#define AU8522_I2C_RD_DATA5_REG0A0H 0x0A0
140#define AU8522_I2C_RD_DATA6_REG0A1H 0x0A1
141#define AU8522_I2C_RD_DATA7_REG0A2H 0x0A2
142
143#define AU8522_ENA_USB_REG101H 0x101
144
145#define AU8522_I2S_CTRL_0_REG110H 0x110
146#define AU8522_I2S_CTRL_1_REG111H 0x111
147#define AU8522_I2S_CTRL_2_REG112H 0x112
148
149#define AU8522_FRMREGFFECONTROL_REG121H 0x121
150#define AU8522_FRMREGDFECONTROL_REG122H 0x122
151
152#define AU8522_CARRFREQOFFSET0_REG201H 0x201
153#define AU8522_CARRFREQOFFSET1_REG202H 0x202
154
155#define AU8522_DECIMATION_GAIN_REG21AH 0x21A
156#define AU8522_FRMREGIFSLP_REG21BH 0x21B
157#define AU8522_FRMREGTHRDL2_REG21CH 0x21C
158#define AU8522_FRMREGSTEP3DB_REG21DH 0x21D
159#define AU8522_DAGC_GAIN_ADJUSTMENT_REG21EH 0x21E
160#define AU8522_FRMREGPLLMODE_REG21FH 0x21F
161#define AU8522_FRMREGCSTHRD_REG220H 0x220
162#define AU8522_FRMREGCRLOCKDMAX_REG221H 0x221
163#define AU8522_FRMREGCRPERIODMASK_REG222H 0x222
164#define AU8522_FRMREGCRLOCK0THH_REG223H 0x223
165#define AU8522_FRMREGCRLOCK1THH_REG224H 0x224
166#define AU8522_FRMREGCRLOCK0THL_REG225H 0x225
167#define AU8522_FRMREGCRLOCK1THL_REG226H 0x226
168#define AU_FRMREGPLLACQPHASESCL_REG227H 0x227
169#define AU8522_FRMREGFREQFBCTRL_REG228H 0x228
170
171/* Analog TV Decoder */
172#define AU8522_TVDEC_STATUS_REG000H 0x000
173#define AU8522_TVDEC_INT_STATUS_REG001H 0x001
174#define AU8522_TVDEC_MACROVISION_STATUS_REG002H 0x002
175#define AU8522_TVDEC_SHARPNESSREG009H 0x009
176#define AU8522_TVDEC_BRIGHTNESS_REG00AH 0x00A
177#define AU8522_TVDEC_CONTRAST_REG00BH 0x00B
178#define AU8522_TVDEC_SATURATION_CB_REG00CH 0x00C
179#define AU8522_TVDEC_SATURATION_CR_REG00DH 0x00D
180#define AU8522_TVDEC_HUE_H_REG00EH 0x00E
181#define AU8522_TVDEC_HUE_L_REG00FH 0x00F
182#define AU8522_TVDEC_INT_MASK_REG010H 0x010
183#define AU8522_VIDEO_MODE_REG011H 0x011
184#define AU8522_TVDEC_PGA_REG012H 0x012
185#define AU8522_TVDEC_COMB_MODE_REG015H 0x015
186#define AU8522_REG016H 0x016
187#define AU8522_TVDED_DBG_MODE_REG060H 0x060
188#define AU8522_TVDEC_FORMAT_CTRL1_REG061H 0x061
189#define AU8522_TVDEC_FORMAT_CTRL2_REG062H 0x062
190#define AU8522_TVDEC_VCR_DET_LLIM_REG063H 0x063
191#define AU8522_TVDEC_VCR_DET_HLIM_REG064H 0x064
192#define AU8522_TVDEC_COMB_VDIF_THR1_REG065H 0x065
193#define AU8522_TVDEC_COMB_VDIF_THR2_REG066H 0x066
194#define AU8522_TVDEC_COMB_VDIF_THR3_REG067H 0x067
195#define AU8522_TVDEC_COMB_NOTCH_THR_REG068H 0x068
196#define AU8522_TVDEC_COMB_HDIF_THR1_REG069H 0x069
197#define AU8522_TVDEC_COMB_HDIF_THR2_REG06AH 0x06A
198#define AU8522_TVDEC_COMB_HDIF_THR3_REG06BH 0x06B
199#define AU8522_TVDEC_COMB_DCDIF_THR1_REG06CH 0x06C
200#define AU8522_TVDEC_COMB_DCDIF_THR2_REG06DH 0x06D
201#define AU8522_TVDEC_COMB_DCDIF_THR3_REG06EH 0x06E
202#define AU8522_TVDEC_UV_SEP_THR_REG06FH 0x06F
203#define AU8522_TVDEC_COMB_DC_THR1_NTSC_REG070H 0x070
204#define AU8522_TVDEC_COMB_DC_THR2_NTSC_REG073H 0x073
205#define AU8522_TVDEC_DCAGC_CTRL_REG077H 0x077
206#define AU8522_TVDEC_PIC_START_ADJ_REG078H 0x078
207#define AU8522_TVDEC_AGC_HIGH_LIMIT_REG079H 0x079
208#define AU8522_TVDEC_MACROVISION_SYNC_THR_REG07AH 0x07A
209#define AU8522_TVDEC_INTRP_CTRL_REG07BH 0x07B
210#define AU8522_TVDEC_PLL_STATUS_REG07EH 0x07E
211#define AU8522_TVDEC_FSC_FREQ_REG07FH 0x07F
212
213#define AU8522_TVDEC_AGC_LOW_LIMIT_REG0E4H 0x0E4
214#define AU8522_TOREGAAGC_REG0E5H 0x0E5
215
216#define AU8522_TVDEC_CHROMA_AGC_REG401H 0x401
217#define AU8522_TVDEC_CHROMA_SFT_REG402H 0x402
218#define AU8522_FILTER_COEF_R410 0x410
219#define AU8522_FILTER_COEF_R411 0x411
220#define AU8522_FILTER_COEF_R412 0x412
221#define AU8522_FILTER_COEF_R413 0x413
222#define AU8522_FILTER_COEF_R414 0x414
223#define AU8522_FILTER_COEF_R415 0x415
224#define AU8522_FILTER_COEF_R416 0x416
225#define AU8522_FILTER_COEF_R417 0x417
226#define AU8522_FILTER_COEF_R418 0x418
227#define AU8522_FILTER_COEF_R419 0x419
228#define AU8522_FILTER_COEF_R41A 0x41A
229#define AU8522_FILTER_COEF_R41B 0x41B
230#define AU8522_FILTER_COEF_R41C 0x41C
231#define AU8522_FILTER_COEF_R41D 0x41D
232#define AU8522_FILTER_COEF_R41E 0x41E
233#define AU8522_FILTER_COEF_R41F 0x41F
234#define AU8522_FILTER_COEF_R420 0x420
235#define AU8522_FILTER_COEF_R421 0x421
236#define AU8522_FILTER_COEF_R422 0x422
237#define AU8522_FILTER_COEF_R423 0x423
238#define AU8522_FILTER_COEF_R424 0x424
239#define AU8522_FILTER_COEF_R425 0x425
240#define AU8522_FILTER_COEF_R426 0x426
241#define AU8522_FILTER_COEF_R427 0x427
242#define AU8522_FILTER_COEF_R428 0x428
243#define AU8522_FILTER_COEF_R429 0x429
244#define AU8522_FILTER_COEF_R42A 0x42A
245#define AU8522_FILTER_COEF_R42B 0x42B
246#define AU8522_FILTER_COEF_R42C 0x42C
247#define AU8522_FILTER_COEF_R42D 0x42D
248
249/* VBI Control Registers */
250#define AU8522_TVDEC_VBI_RX_FIFO_CONTAIN_REG004H 0x004
251#define AU8522_TVDEC_VBI_TX_FIFO_CONTAIN_REG005H 0x005
252#define AU8522_TVDEC_VBI_RX_FIFO_READ_REG006H 0x006
253#define AU8522_TVDEC_VBI_FIFO_STATUS_REG007H 0x007
254#define AU8522_TVDEC_VBI_CTRL_H_REG017H 0x017
255#define AU8522_TVDEC_VBI_CTRL_L_REG018H 0x018
256#define AU8522_TVDEC_VBI_USER_TOTAL_BITS_REG019H 0x019
257#define AU8522_TVDEC_VBI_USER_TUNIT_H_REG01AH 0x01A
258#define AU8522_TVDEC_VBI_USER_TUNIT_L_REG01BH 0x01B
259#define AU8522_TVDEC_VBI_USER_THRESH1_REG01CH 0x01C
260#define AU8522_TVDEC_VBI_USER_FRAME_PAT2_REG01EH 0x01E
261#define AU8522_TVDEC_VBI_USER_FRAME_PAT1_REG01FH 0x01F
262#define AU8522_TVDEC_VBI_USER_FRAME_PAT0_REG020H 0x020
263#define AU8522_TVDEC_VBI_USER_FRAME_MASK2_REG021H 0x021
264#define AU8522_TVDEC_VBI_USER_FRAME_MASK1_REG022H 0x022
265#define AU8522_TVDEC_VBI_USER_FRAME_MASK0_REG023H 0x023
266
267#define AU8522_REG071H 0x071
268#define AU8522_REG072H 0x072
269#define AU8522_REG074H 0x074
270#define AU8522_REG075H 0x075
271
272/* Digital Demodulator Registers */
273#define AU8522_FRAME_COUNT0_REG084H 0x084
274#define AU8522_RS_STATUS_G0_REG085H 0x085
275#define AU8522_RS_STATUS_B0_REG086H 0x086
276#define AU8522_RS_STATUS_E_REG087H 0x087
277#define AU8522_DEMODULATION_STATUS_REG088H 0x088
278#define AU8522_TOREGTRESTATUS_REG0E6H 0x0E6
279#define AU8522_TSPORT_CONTROL_REG10BH 0x10B
280#define AU8522_TSTHES_REG10CH 0x10C
281#define AU8522_FRMREGDFEKEEP_REG301H 0x301
282#define AU8522_DFE_AVERAGE_REG302H 0x302
283#define AU8522_FRMREGEQLERRWIN_REG303H 0x303
284#define AU8522_FRMREGFFEKEEP_REG304H 0x304
285#define AU8522_FRMREGDFECONTROL1_REG305H 0x305
286#define AU8522_FRMREGEQLERRLOW_REG306H 0x306
287
288#define AU8522_REG42EH 0x42E
289#define AU8522_REG42FH 0x42F
290#define AU8522_REG430H 0x430
291#define AU8522_REG431H 0x431
292#define AU8522_REG432H 0x432
293#define AU8522_REG433H 0x433
294#define AU8522_REG434H 0x434
295#define AU8522_REG435H 0x435
296#define AU8522_REG436H 0x436
297
298/* GPIO Registers */
299#define AU8522_GPIO_CONTROL_REG0E0H 0x0E0
300#define AU8522_GPIO_STATUS_REG0E1H 0x0E1
301#define AU8522_GPIO_DATA_REG0E2H 0x0E2
302
303/* Audio Control Registers */
304#define AU8522_AUDIOAGC_REG0EEH 0x0EE
305#define AU8522_AUDIO_STATUS_REG0F0H 0x0F0
306#define AU8522_AUDIO_MODE_REG0F1H 0x0F1
307#define AU8522_AUDIO_VOLUME_L_REG0F2H 0x0F2
308#define AU8522_AUDIO_VOLUME_R_REG0F3H 0x0F3
309#define AU8522_AUDIO_VOLUME_REG0F4H 0x0F4
310#define AU8522_FRMREGAUPHASE_REG0F7H 0x0F7
311#define AU8522_REG0F9H 0x0F9
312
313#define AU8522_AUDIOAGC2_REG605H 0x605
314#define AU8522_AUDIOFREQ_REG606H 0x606
315
316
317/**************************************************************/
318
319#define AU8522_INPUT_CONTROL_REG081H_ATSC 0xC4
320#define AU8522_INPUT_CONTROL_REG081H_ATVRF 0xC4
321#define AU8522_INPUT_CONTROL_REG081H_ATVRF13 0xC4
322#define AU8522_INPUT_CONTROL_REG081H_J83B64 0xC4
323#define AU8522_INPUT_CONTROL_REG081H_J83B256 0xC4
324#define AU8522_INPUT_CONTROL_REG081H_CVBS 0x20
325#define AU8522_INPUT_CONTROL_REG081H_CVBS_CH1 0xA2
326#define AU8522_INPUT_CONTROL_REG081H_CVBS_CH2 0xA0
327#define AU8522_INPUT_CONTROL_REG081H_CVBS_CH3 0x69
328#define AU8522_INPUT_CONTROL_REG081H_CVBS_CH4 0x68
329#define AU8522_INPUT_CONTROL_REG081H_CVBS_CH4_SIF 0x28
330/* CH1 AS Y,CH3 AS C */
331#define AU8522_INPUT_CONTROL_REG081H_SVIDEO_CH13 0x23
332/* CH2 AS Y,CH4 AS C */
333#define AU8522_INPUT_CONTROL_REG081H_SVIDEO_CH24 0x20
334#define AU8522_MODULE_CLOCK_CONTROL_REG0A3H_ATSC 0x0C
335#define AU8522_MODULE_CLOCK_CONTROL_REG0A3H_J83B64 0x09
336#define AU8522_MODULE_CLOCK_CONTROL_REG0A3H_J83B256 0x09
337#define AU8522_MODULE_CLOCK_CONTROL_REG0A3H_CVBS 0x12
338#define AU8522_MODULE_CLOCK_CONTROL_REG0A3H_ATVRF 0x1A
339#define AU8522_MODULE_CLOCK_CONTROL_REG0A3H_ATVRF13 0x1A
340#define AU8522_MODULE_CLOCK_CONTROL_REG0A3H_SVIDEO 0x02
341
342#define AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_CLEAR 0x00
343#define AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_SVIDEO 0x9C
344#define AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_CVBS 0x9D
345#define AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_ATSC 0xE8
346#define AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_J83B256 0xCA
347#define AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_J83B64 0xCA
348#define AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_ATVRF 0xDD
349#define AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_ATVRF13 0xDD
350#define AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_PAL 0xDD
351#define AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_FM 0xDD
352
353#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_ATSC 0x80
354#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_J83B256 0x80
355#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_J83B64 0x80
356#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_DONGLE_ATSC 0x40
357#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_DONGLE_J83B256 0x40
358#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_DONGLE_J83B64 0x40
359#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_DONGLE_CLEAR 0x00
360#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_ATVRF 0x01
361#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_ATVRF13 0x01
362#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_SVIDEO 0x04
363#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_CVBS 0x01
364#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_PWM 0x03
365#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_IIS 0x09
366#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_PAL 0x01
367#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_FM 0x01
368
369/* STILL NEED TO BE REFACTORED @@@@@@@@@@@@@@ */
370#define AU8522_TVDEC_CONTRAST_REG00BH_CVBS 0x79
371#define AU8522_TVDEC_SATURATION_CB_REG00CH_CVBS 0x80
372#define AU8522_TVDEC_SATURATION_CR_REG00DH_CVBS 0x80
373#define AU8522_TVDEC_HUE_H_REG00EH_CVBS 0x00
374#define AU8522_TVDEC_HUE_L_REG00FH_CVBS 0x00
375#define AU8522_TVDEC_PGA_REG012H_CVBS 0x0F
376#define AU8522_TVDEC_COMB_MODE_REG015H_CVBS 0x00
377#define AU8522_REG016H_CVBS 0x00
378#define AU8522_TVDED_DBG_MODE_REG060H_CVBS 0x00
379#define AU8522_TVDEC_FORMAT_CTRL1_REG061H_CVBS 0x0B
380#define AU8522_TVDEC_FORMAT_CTRL1_REG061H_CVBS13 0x03
381#define AU8522_TVDEC_FORMAT_CTRL2_REG062H_CVBS13 0x00
382#define AU8522_TVDEC_VCR_DET_LLIM_REG063H_CVBS 0x19
383#define AU8522_REG0F9H_AUDIO 0x20
384#define AU8522_TVDEC_VCR_DET_HLIM_REG064H_CVBS 0xA7
385#define AU8522_TVDEC_COMB_VDIF_THR1_REG065H_CVBS 0x0A
386#define AU8522_TVDEC_COMB_VDIF_THR2_REG066H_CVBS 0x32
387#define AU8522_TVDEC_COMB_VDIF_THR3_REG067H_CVBS 0x19
388#define AU8522_TVDEC_COMB_NOTCH_THR_REG068H_CVBS 0x23
389#define AU8522_TVDEC_COMB_HDIF_THR1_REG069H_CVBS 0x41
390#define AU8522_TVDEC_COMB_HDIF_THR2_REG06AH_CVBS 0x0A
391#define AU8522_TVDEC_COMB_HDIF_THR3_REG06BH_CVBS 0x32
392#define AU8522_TVDEC_COMB_DCDIF_THR1_REG06CH_CVBS 0x34
393#define AU8522_TVDEC_COMB_DCDIF_THR2_REG06DH_CVBS 0x05
394#define AU8522_TVDEC_COMB_DCDIF_THR3_REG06EH_CVBS 0x6E
395#define AU8522_TVDEC_UV_SEP_THR_REG06FH_CVBS 0x0F
396#define AU8522_TVDEC_COMB_DC_THR1_NTSC_REG070H_CVBS 0x80
397#define AU8522_REG071H_CVBS 0x18
398#define AU8522_REG072H_CVBS 0x30
399#define AU8522_TVDEC_COMB_DC_THR2_NTSC_REG073H_CVBS 0xF0
400#define AU8522_REG074H_CVBS 0x80
401#define AU8522_REG075H_CVBS 0xF0
402#define AU8522_TVDEC_DCAGC_CTRL_REG077H_CVBS 0xFB
403#define AU8522_TVDEC_PIC_START_ADJ_REG078H_CVBS 0x04
404#define AU8522_TVDEC_AGC_HIGH_LIMIT_REG079H_CVBS 0x00
405#define AU8522_TVDEC_MACROVISION_SYNC_THR_REG07AH_CVBS 0x00
406#define AU8522_TVDEC_INTRP_CTRL_REG07BH_CVBS 0xEE
407#define AU8522_TVDEC_AGC_LOW_LIMIT_REG0E4H_CVBS 0xFE
408#define AU8522_TOREGAAGC_REG0E5H_CVBS 0x00
409#define AU8522_TVDEC_VBI6A_REG035H_CVBS 0x40
410
411/* Enables Closed captioning */
412#define AU8522_TVDEC_VBI_CTRL_H_REG017H_CCON 0x21
diff --git a/drivers/media/dvb/frontends/cx24113.c b/drivers/media/dvb/frontends/cx24113.c
index f6e7b0380a5a..e4fd533a427c 100644
--- a/drivers/media/dvb/frontends/cx24113.c
+++ b/drivers/media/dvb/frontends/cx24113.c
@@ -559,7 +559,7 @@ struct dvb_frontend *cx24113_attach(struct dvb_frontend *fe,
559 kzalloc(sizeof(struct cx24113_state), GFP_KERNEL); 559 kzalloc(sizeof(struct cx24113_state), GFP_KERNEL);
560 int rc; 560 int rc;
561 if (state == NULL) { 561 if (state == NULL) {
562 err("Unable to kmalloc\n"); 562 err("Unable to kzalloc\n");
563 goto error; 563 goto error;
564 } 564 }
565 565
diff --git a/drivers/media/dvb/frontends/cx24116.c b/drivers/media/dvb/frontends/cx24116.c
index 28ad609e73f4..9b9f57264cef 100644
--- a/drivers/media/dvb/frontends/cx24116.c
+++ b/drivers/media/dvb/frontends/cx24116.c
@@ -15,6 +15,9 @@
15 September, 9th 2008 15 September, 9th 2008
16 Fixed locking on high symbol rates (>30000). 16 Fixed locking on high symbol rates (>30000).
17 Implement MPEG initialization parameter. 17 Implement MPEG initialization parameter.
18 January, 17th 2009
19 Fill set_voltage with actually control voltage code.
20 Correct set tone to not affect voltage.
18 21
19 This program is free software; you can redistribute it and/or modify 22 This program is free software; you can redistribute it and/or modify
20 it under the terms of the GNU General Public License as published by 23 it under the terms of the GNU General Public License as published by
@@ -146,7 +149,7 @@ enum cmds {
146 CMD_GETAGC = 0x19, 149 CMD_GETAGC = 0x19,
147 CMD_LNBCONFIG = 0x20, 150 CMD_LNBCONFIG = 0x20,
148 CMD_LNBSEND = 0x21, /* Formerly CMD_SEND_DISEQC */ 151 CMD_LNBSEND = 0x21, /* Formerly CMD_SEND_DISEQC */
149 CMD_SET_TONEPRE = 0x22, 152 CMD_LNBDCLEVEL = 0x22,
150 CMD_SET_TONE = 0x23, 153 CMD_SET_TONE = 0x23,
151 CMD_UPDFWVERS = 0x35, 154 CMD_UPDFWVERS = 0x35,
152 CMD_TUNERSLEEP = 0x36, 155 CMD_TUNERSLEEP = 0x36,
@@ -667,16 +670,6 @@ static int cx24116_load_firmware(struct dvb_frontend *fe,
667 return 0; 670 return 0;
668} 671}
669 672
670static int cx24116_set_voltage(struct dvb_frontend *fe,
671 fe_sec_voltage_t voltage)
672{
673 /* The isl6421 module will override this function in the fops. */
674 dprintk("%s() This should never appear if the isl6421 module "
675 "is loaded correctly\n", __func__);
676
677 return -EOPNOTSUPP;
678}
679
680static int cx24116_read_status(struct dvb_frontend *fe, fe_status_t *status) 673static int cx24116_read_status(struct dvb_frontend *fe, fe_status_t *status)
681{ 674{
682 struct cx24116_state *state = fe->demodulator_priv; 675 struct cx24116_state *state = fe->demodulator_priv;
@@ -837,6 +830,34 @@ static int cx24116_wait_for_lnb(struct dvb_frontend *fe)
837 return -ETIMEDOUT; /* -EBUSY ? */ 830 return -ETIMEDOUT; /* -EBUSY ? */
838} 831}
839 832
833static int cx24116_set_voltage(struct dvb_frontend *fe,
834 fe_sec_voltage_t voltage)
835{
836 struct cx24116_cmd cmd;
837 int ret;
838
839 dprintk("%s: %s\n", __func__,
840 voltage == SEC_VOLTAGE_13 ? "SEC_VOLTAGE_13" :
841 voltage == SEC_VOLTAGE_18 ? "SEC_VOLTAGE_18" : "??");
842
843 /* Wait for LNB ready */
844 ret = cx24116_wait_for_lnb(fe);
845 if (ret != 0)
846 return ret;
847
848 /* Wait for voltage/min repeat delay */
849 msleep(100);
850
851 cmd.args[0x00] = CMD_LNBDCLEVEL;
852 cmd.args[0x01] = (voltage == SEC_VOLTAGE_18 ? 0x01 : 0x00);
853 cmd.len = 0x02;
854
855 /* Min delay time before DiSEqC send */
856 msleep(15);
857
858 return cx24116_cmd_execute(fe, &cmd);
859}
860
840static int cx24116_set_tone(struct dvb_frontend *fe, 861static int cx24116_set_tone(struct dvb_frontend *fe,
841 fe_sec_tone_mode_t tone) 862 fe_sec_tone_mode_t tone)
842{ 863{
@@ -857,14 +878,6 @@ static int cx24116_set_tone(struct dvb_frontend *fe,
857 /* Min delay time after DiSEqC send */ 878 /* Min delay time after DiSEqC send */
858 msleep(15); /* XXX determine is FW does this, see send_diseqc/burst */ 879 msleep(15); /* XXX determine is FW does this, see send_diseqc/burst */
859 880
860 /* This is always done before the tone is set */
861 cmd.args[0x00] = CMD_SET_TONEPRE;
862 cmd.args[0x01] = 0x00;
863 cmd.len = 0x02;
864 ret = cx24116_cmd_execute(fe, &cmd);
865 if (ret != 0)
866 return ret;
867
868 /* Now we set the tone */ 881 /* Now we set the tone */
869 cmd.args[0x00] = CMD_SET_TONE; 882 cmd.args[0x00] = CMD_SET_TONE;
870 cmd.args[0x01] = 0x00; 883 cmd.args[0x01] = 0x00;
@@ -1099,13 +1112,10 @@ struct dvb_frontend *cx24116_attach(const struct cx24116_config *config,
1099 dprintk("%s\n", __func__); 1112 dprintk("%s\n", __func__);
1100 1113
1101 /* allocate memory for the internal state */ 1114 /* allocate memory for the internal state */
1102 state = kmalloc(sizeof(struct cx24116_state), GFP_KERNEL); 1115 state = kzalloc(sizeof(struct cx24116_state), GFP_KERNEL);
1103 if (state == NULL) 1116 if (state == NULL)
1104 goto error1; 1117 goto error1;
1105 1118
1106 /* setup the state */
1107 memset(state, 0, sizeof(struct cx24116_state));
1108
1109 state->config = config; 1119 state->config = config;
1110 state->i2c = i2c; 1120 state->i2c = i2c;
1111 1121
@@ -1154,7 +1164,12 @@ static int cx24116_initfe(struct dvb_frontend *fe)
1154 if (ret != 0) 1164 if (ret != 0)
1155 return ret; 1165 return ret;
1156 1166
1157 return cx24116_diseqc_init(fe); 1167 ret = cx24116_diseqc_init(fe);
1168 if (ret != 0)
1169 return ret;
1170
1171 /* HVR-4000 needs this */
1172 return cx24116_set_voltage(fe, SEC_VOLTAGE_13);
1158} 1173}
1159 1174
1160/* 1175/*
diff --git a/drivers/media/dvb/frontends/cx24123.c b/drivers/media/dvb/frontends/cx24123.c
index 1a8c36f76061..0592f043ea64 100644
--- a/drivers/media/dvb/frontends/cx24123.c
+++ b/drivers/media/dvb/frontends/cx24123.c
@@ -1069,13 +1069,13 @@ static struct dvb_frontend_ops cx24123_ops;
1069struct dvb_frontend *cx24123_attach(const struct cx24123_config *config, 1069struct dvb_frontend *cx24123_attach(const struct cx24123_config *config,
1070 struct i2c_adapter *i2c) 1070 struct i2c_adapter *i2c)
1071{ 1071{
1072 /* allocate memory for the internal state */
1072 struct cx24123_state *state = 1073 struct cx24123_state *state =
1073 kzalloc(sizeof(struct cx24123_state), GFP_KERNEL); 1074 kzalloc(sizeof(struct cx24123_state), GFP_KERNEL);
1074 1075
1075 dprintk("\n"); 1076 dprintk("\n");
1076 /* allocate memory for the internal state */
1077 if (state == NULL) { 1077 if (state == NULL) {
1078 err("Unable to kmalloc\n"); 1078 err("Unable to kzalloc\n");
1079 goto error; 1079 goto error;
1080 } 1080 }
1081 1081
diff --git a/drivers/media/dvb/frontends/dib0070.h b/drivers/media/dvb/frontends/dib0070.h
index 21f2c5161af4..9670f5d20cfb 100644
--- a/drivers/media/dvb/frontends/dib0070.h
+++ b/drivers/media/dvb/frontends/dib0070.h
@@ -58,6 +58,4 @@ static inline u16 dib0070_wbd_offset(struct dvb_frontend *fe)
58} 58}
59#endif 59#endif
60 60
61extern void dib0070_ctrl_agc_filter(struct dvb_frontend *, uint8_t open);
62
63#endif 61#endif
diff --git a/drivers/media/dvb/frontends/dib3000mc.h b/drivers/media/dvb/frontends/dib3000mc.h
index 4142ed7a47d0..d75ffad2d752 100644
--- a/drivers/media/dvb/frontends/dib3000mc.h
+++ b/drivers/media/dvb/frontends/dib3000mc.h
@@ -39,19 +39,43 @@ struct dib3000mc_config {
39#define DEFAULT_DIB3000MC_I2C_ADDRESS 16 39#define DEFAULT_DIB3000MC_I2C_ADDRESS 16
40#define DEFAULT_DIB3000P_I2C_ADDRESS 24 40#define DEFAULT_DIB3000P_I2C_ADDRESS 24
41 41
42#if defined(CONFIG_DVB_DIB3000MC) || (defined(CONFIG_DVB_DIB3000MC_MODULE) && defined(MODULE)) 42#if defined(CONFIG_DVB_DIB3000MC) || (defined(CONFIG_DVB_DIB3000MC_MODULE) && \
43extern struct dvb_frontend * dib3000mc_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib3000mc_config *cfg); 43 defined(MODULE))
44extern struct dvb_frontend *dib3000mc_attach(struct i2c_adapter *i2c_adap,
45 u8 i2c_addr,
46 struct dib3000mc_config *cfg);
47extern int dib3000mc_i2c_enumeration(struct i2c_adapter *i2c,
48 int no_of_demods, u8 default_addr,
49 struct dib3000mc_config cfg[]);
50extern
51struct i2c_adapter *dib3000mc_get_tuner_i2c_master(struct dvb_frontend *demod,
52 int gating);
44#else 53#else
45static inline struct dvb_frontend * dib3000mc_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib3000mc_config *cfg) 54static inline
55struct dvb_frontend *dib3000mc_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr,
56 struct dib3000mc_config *cfg)
46{ 57{
47 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 58 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
48 return NULL; 59 return NULL;
49} 60}
50#endif // CONFIG_DVB_DIB3000MC
51 61
52extern int dib3000mc_i2c_enumeration(struct i2c_adapter *i2c, int no_of_demods, u8 default_addr, struct dib3000mc_config cfg[]); 62static inline
63int dib3000mc_i2c_enumeration(struct i2c_adapter *i2c,
64 int no_of_demods, u8 default_addr,
65 struct dib3000mc_config cfg[])
66{
67 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
68 return -ENODEV;
69}
53 70
54extern struct i2c_adapter * dib3000mc_get_tuner_i2c_master(struct dvb_frontend *demod, int gating); 71static inline
72struct i2c_adapter *dib3000mc_get_tuner_i2c_master(struct dvb_frontend *demod,
73 int gating)
74{
75 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
76 return NULL;
77}
78#endif // CONFIG_DVB_DIB3000MC
55 79
56extern int dib3000mc_pid_control(struct dvb_frontend *fe, int index, int pid,int onoff); 80extern int dib3000mc_pid_control(struct dvb_frontend *fe, int index, int pid,int onoff);
57extern int dib3000mc_pid_parse(struct dvb_frontend *fe, int onoff); 81extern int dib3000mc_pid_parse(struct dvb_frontend *fe, int onoff);
diff --git a/drivers/media/dvb/frontends/dib7000m.h b/drivers/media/dvb/frontends/dib7000m.h
index 597e9cc2da62..113819ce9f0d 100644
--- a/drivers/media/dvb/frontends/dib7000m.h
+++ b/drivers/media/dvb/frontends/dib7000m.h
@@ -38,8 +38,32 @@ struct dib7000m_config {
38 38
39#define DEFAULT_DIB7000M_I2C_ADDRESS 18 39#define DEFAULT_DIB7000M_I2C_ADDRESS 18
40 40
41extern struct dvb_frontend * dib7000m_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib7000m_config *cfg); 41#if defined(CONFIG_DVB_DIB7000M) || (defined(CONFIG_DVB_DIB7000M_MODULE) && \
42extern struct i2c_adapter * dib7000m_get_i2c_master(struct dvb_frontend *, enum dibx000_i2c_interface, int); 42 defined(MODULE))
43extern struct dvb_frontend *dib7000m_attach(struct i2c_adapter *i2c_adap,
44 u8 i2c_addr,
45 struct dib7000m_config *cfg);
46extern struct i2c_adapter *dib7000m_get_i2c_master(struct dvb_frontend *,
47 enum dibx000_i2c_interface,
48 int);
49#else
50static inline
51struct dvb_frontend *dib7000m_attach(struct i2c_adapter *i2c_adap,
52 u8 i2c_addr, struct dib7000m_config *cfg)
53{
54 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
55 return NULL;
56}
57
58static inline
59struct i2c_adapter *dib7000m_get_i2c_master(struct dvb_frontend *demod,
60 enum dibx000_i2c_interface intf,
61 int gating)
62{
63 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
64 return NULL;
65}
66#endif
43 67
44/* TODO 68/* TODO
45extern INT dib7000m_set_gpio(struct dibDemod *demod, UCHAR num, UCHAR dir, UCHAR val); 69extern INT dib7000m_set_gpio(struct dibDemod *demod, UCHAR num, UCHAR dir, UCHAR val);
diff --git a/drivers/media/dvb/frontends/dib7000p.h b/drivers/media/dvb/frontends/dib7000p.h
index aab8112e2db2..02a4c82f0c70 100644
--- a/drivers/media/dvb/frontends/dib7000p.h
+++ b/drivers/media/dvb/frontends/dib7000p.h
@@ -37,7 +37,8 @@ struct dib7000p_config {
37 37
38#define DEFAULT_DIB7000P_I2C_ADDRESS 18 38#define DEFAULT_DIB7000P_I2C_ADDRESS 18
39 39
40#if defined(CONFIG_DVB_DIB7000P) || (defined(CONFIG_DVB_DIB7000P_MODULE) && defined(MODULE)) 40#if defined(CONFIG_DVB_DIB7000P) || (defined(CONFIG_DVB_DIB7000P_MODULE) && \
41 defined(MODULE))
41extern struct dvb_frontend *dib7000p_attach(struct i2c_adapter *i2c_adap, 42extern struct dvb_frontend *dib7000p_attach(struct i2c_adapter *i2c_adap,
42 u8 i2c_addr, 43 u8 i2c_addr,
43 struct dib7000p_config *cfg); 44 struct dib7000p_config *cfg);
@@ -49,10 +50,11 @@ extern int dib7000p_i2c_enumeration(struct i2c_adapter *i2c,
49 struct dib7000p_config cfg[]); 50 struct dib7000p_config cfg[]);
50extern int dib7000p_set_gpio(struct dvb_frontend *, u8 num, u8 dir, u8 val); 51extern int dib7000p_set_gpio(struct dvb_frontend *, u8 num, u8 dir, u8 val);
51extern int dib7000p_set_wbd_ref(struct dvb_frontend *, u16 value); 52extern int dib7000p_set_wbd_ref(struct dvb_frontend *, u16 value);
53extern int dib7000pc_detection(struct i2c_adapter *i2c_adap);
52#else 54#else
53static inline struct dvb_frontend *dib7000p_attach(struct i2c_adapter *i2c_adap, 55static inline
54 u8 i2c_addr, 56struct dvb_frontend *dib7000p_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr,
55 struct dib7000p_config *cfg) 57 struct dib7000p_config *cfg)
56{ 58{
57 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 59 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
58 return NULL; 60 return NULL;
@@ -60,36 +62,39 @@ static inline struct dvb_frontend *dib7000p_attach(struct i2c_adapter *i2c_adap,
60 62
61static inline 63static inline
62struct i2c_adapter *dib7000p_get_i2c_master(struct dvb_frontend *fe, 64struct i2c_adapter *dib7000p_get_i2c_master(struct dvb_frontend *fe,
63 enum dibx000_i2c_interface i, int x) 65 enum dibx000_i2c_interface i,
66 int x)
64{ 67{
65 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 68 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
66 return NULL; 69 return NULL;
67} 70}
68 71
69static inline 72static inline int dib7000p_i2c_enumeration(struct i2c_adapter *i2c,
70int dib7000p_i2c_enumeration(struct i2c_adapter *i2c, 73 int no_of_demods, u8 default_addr,
71 int no_of_demods, u8 default_addr, 74 struct dib7000p_config cfg[])
72 struct dib7000p_config cfg[])
73{ 75{
74 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 76 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
75 return -ENODEV; 77 return -ENODEV;
76} 78}
77 79
78static inline 80static inline int dib7000p_set_gpio(struct dvb_frontend *fe,
79int dib7000p_set_gpio(struct dvb_frontend *fe, u8 num, u8 dir, u8 val) 81 u8 num, u8 dir, u8 val)
80{ 82{
81 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 83 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
82 return -ENODEV; 84 return -ENODEV;
83} 85}
84 86
85static inline 87static inline int dib7000p_set_wbd_ref(struct dvb_frontend *fe, u16 value)
86int dib7000p_set_wbd_ref(struct dvb_frontend *fe, u16 value)
87{ 88{
88 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 89 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
89 return -ENODEV; 90 return -ENODEV;
90} 91}
91#endif
92 92
93extern int dib7000pc_detection(struct i2c_adapter *i2c_adap); 93static inline int dib7000pc_detection(struct i2c_adapter *i2c_adap)
94{
95 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
96 return -ENODEV;
97}
98#endif
94 99
95#endif 100#endif
diff --git a/drivers/media/dvb/frontends/dvb_dummy_fe.h b/drivers/media/dvb/frontends/dvb_dummy_fe.h
index 8210f19d56ce..1fcb987d6386 100644
--- a/drivers/media/dvb/frontends/dvb_dummy_fe.h
+++ b/drivers/media/dvb/frontends/dvb_dummy_fe.h
@@ -25,8 +25,27 @@
25#include <linux/dvb/frontend.h> 25#include <linux/dvb/frontend.h>
26#include "dvb_frontend.h" 26#include "dvb_frontend.h"
27 27
28#if defined(CONFIG_DVB_DUMMY_FE) || (defined(CONFIG_DVB_DUMMY_FE_MODULE) && \
29defined(MODULE))
28extern struct dvb_frontend* dvb_dummy_fe_ofdm_attach(void); 30extern struct dvb_frontend* dvb_dummy_fe_ofdm_attach(void);
29extern struct dvb_frontend* dvb_dummy_fe_qpsk_attach(void); 31extern struct dvb_frontend* dvb_dummy_fe_qpsk_attach(void);
30extern struct dvb_frontend* dvb_dummy_fe_qam_attach(void); 32extern struct dvb_frontend* dvb_dummy_fe_qam_attach(void);
33#else
34static inline struct dvb_frontend *dvb_dummy_fe_ofdm_attach(void)
35{
36 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
37 return NULL;
38}
39static inline struct dvb_frontend *dvb_dummy_fe_qpsk_attach(void)
40{
41 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
42 return NULL;
43}
44static inline struct dvb_frontend *dvb_dummy_fe_qam_attach(void)
45{
46 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
47 return NULL;
48}
49#endif /* CONFIG_DVB_DUMMY_FE */
31 50
32#endif // DVB_DUMMY_FE_H 51#endif // DVB_DUMMY_FE_H
diff --git a/drivers/media/dvb/frontends/itd1000_priv.h b/drivers/media/dvb/frontends/itd1000_priv.h
index 8cdc54e57903..08ca851223c9 100644
--- a/drivers/media/dvb/frontends/itd1000_priv.h
+++ b/drivers/media/dvb/frontends/itd1000_priv.h
@@ -31,7 +31,7 @@ struct itd1000_state {
31 /* ugly workaround for flexcop's incapable i2c-controller 31 /* ugly workaround for flexcop's incapable i2c-controller
32 * FIXME, if possible 32 * FIXME, if possible
33 */ 33 */
34 u8 shadow[255]; 34 u8 shadow[256];
35}; 35};
36 36
37enum itd1000_register { 37enum itd1000_register {
diff --git a/drivers/media/dvb/frontends/lgdt3304.c b/drivers/media/dvb/frontends/lgdt3304.c
index 3bb0c4394f8a..eb72a9866c93 100644
--- a/drivers/media/dvb/frontends/lgdt3304.c
+++ b/drivers/media/dvb/frontends/lgdt3304.c
@@ -363,7 +363,6 @@ struct dvb_frontend* lgdt3304_attach(const struct lgdt3304_config *config,
363 363
364 struct lgdt3304_state *state; 364 struct lgdt3304_state *state;
365 state = kzalloc(sizeof(struct lgdt3304_state), GFP_KERNEL); 365 state = kzalloc(sizeof(struct lgdt3304_state), GFP_KERNEL);
366 memset(state, 0x0, sizeof(struct lgdt3304_state));
367 state->addr = config->i2c_address; 366 state->addr = config->i2c_address;
368 state->i2c = i2c; 367 state->i2c = i2c;
369 368
diff --git a/drivers/media/dvb/frontends/lgdt3305.c b/drivers/media/dvb/frontends/lgdt3305.c
new file mode 100644
index 000000000000..d92d0557a80b
--- /dev/null
+++ b/drivers/media/dvb/frontends/lgdt3305.c
@@ -0,0 +1,1087 @@
1/*
2 * Support for LGDT3305 - VSB/QAM
3 *
4 * Copyright (C) 2008, 2009 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
22#include <linux/dvb/frontend.h>
23#include "dvb_math.h"
24#include "lgdt3305.h"
25
26static int debug;
27module_param(debug, int, 0644);
28MODULE_PARM_DESC(debug, "set debug level (info=1, reg=2 (or-able))");
29
30#define DBG_INFO 1
31#define DBG_REG 2
32
33#define lg_printk(kern, fmt, arg...) \
34 printk(kern "%s: " fmt, __func__, ##arg)
35
36#define lg_info(fmt, arg...) printk(KERN_INFO "lgdt3305: " fmt, ##arg)
37#define lg_warn(fmt, arg...) lg_printk(KERN_WARNING, fmt, ##arg)
38#define lg_err(fmt, arg...) lg_printk(KERN_ERR, fmt, ##arg)
39#define lg_dbg(fmt, arg...) if (debug & DBG_INFO) \
40 lg_printk(KERN_DEBUG, fmt, ##arg)
41#define lg_reg(fmt, arg...) if (debug & DBG_REG) \
42 lg_printk(KERN_DEBUG, fmt, ##arg)
43
44#define lg_fail(ret) \
45({ \
46 int __ret; \
47 __ret = (ret < 0); \
48 if (__ret) \
49 lg_err("error %d on line %d\n", ret, __LINE__); \
50 __ret; \
51})
52
53struct lgdt3305_state {
54 struct i2c_adapter *i2c_adap;
55 const struct lgdt3305_config *cfg;
56
57 struct dvb_frontend frontend;
58
59 fe_modulation_t current_modulation;
60 u32 current_frequency;
61 u32 snr;
62};
63
64/* ------------------------------------------------------------------------ */
65
66#define LGDT3305_GEN_CTRL_1 0x0000
67#define LGDT3305_GEN_CTRL_2 0x0001
68#define LGDT3305_GEN_CTRL_3 0x0002
69#define LGDT3305_GEN_STATUS 0x0003
70#define LGDT3305_GEN_CONTROL 0x0007
71#define LGDT3305_GEN_CTRL_4 0x000a
72#define LGDT3305_DGTL_AGC_REF_1 0x0012
73#define LGDT3305_DGTL_AGC_REF_2 0x0013
74#define LGDT3305_CR_CTR_FREQ_1 0x0106
75#define LGDT3305_CR_CTR_FREQ_2 0x0107
76#define LGDT3305_CR_CTR_FREQ_3 0x0108
77#define LGDT3305_CR_CTR_FREQ_4 0x0109
78#define LGDT3305_CR_MSE_1 0x011b
79#define LGDT3305_CR_MSE_2 0x011c
80#define LGDT3305_CR_LOCK_STATUS 0x011d
81#define LGDT3305_CR_CTRL_7 0x0126
82#define LGDT3305_AGC_POWER_REF_1 0x0300
83#define LGDT3305_AGC_POWER_REF_2 0x0301
84#define LGDT3305_AGC_DELAY_PT_1 0x0302
85#define LGDT3305_AGC_DELAY_PT_2 0x0303
86#define LGDT3305_RFAGC_LOOP_FLTR_BW_1 0x0306
87#define LGDT3305_RFAGC_LOOP_FLTR_BW_2 0x0307
88#define LGDT3305_IFBW_1 0x0308
89#define LGDT3305_IFBW_2 0x0309
90#define LGDT3305_AGC_CTRL_1 0x030c
91#define LGDT3305_AGC_CTRL_4 0x0314
92#define LGDT3305_EQ_MSE_1 0x0413
93#define LGDT3305_EQ_MSE_2 0x0414
94#define LGDT3305_EQ_MSE_3 0x0415
95#define LGDT3305_PT_MSE_1 0x0417
96#define LGDT3305_PT_MSE_2 0x0418
97#define LGDT3305_PT_MSE_3 0x0419
98#define LGDT3305_FEC_BLOCK_CTRL 0x0504
99#define LGDT3305_FEC_LOCK_STATUS 0x050a
100#define LGDT3305_FEC_PKT_ERR_1 0x050c
101#define LGDT3305_FEC_PKT_ERR_2 0x050d
102#define LGDT3305_TP_CTRL_1 0x050e
103#define LGDT3305_BERT_PERIOD 0x0801
104#define LGDT3305_BERT_ERROR_COUNT_1 0x080a
105#define LGDT3305_BERT_ERROR_COUNT_2 0x080b
106#define LGDT3305_BERT_ERROR_COUNT_3 0x080c
107#define LGDT3305_BERT_ERROR_COUNT_4 0x080d
108
109static int lgdt3305_write_reg(struct lgdt3305_state *state, u16 reg, u8 val)
110{
111 int ret;
112 u8 buf[] = { reg >> 8, reg & 0xff, val };
113 struct i2c_msg msg = {
114 .addr = state->cfg->i2c_addr, .flags = 0,
115 .buf = buf, .len = 3,
116 };
117
118 lg_reg("reg: 0x%04x, val: 0x%02x\n", reg, val);
119
120 ret = i2c_transfer(state->i2c_adap, &msg, 1);
121
122 if (ret != 1) {
123 lg_err("error (addr %02x %02x <- %02x, err = %i)\n",
124 msg.buf[0], msg.buf[1], msg.buf[2], ret);
125 if (ret < 0)
126 return ret;
127 else
128 return -EREMOTEIO;
129 }
130 return 0;
131}
132
133static int lgdt3305_read_reg(struct lgdt3305_state *state, u16 reg, u8 *val)
134{
135 int ret;
136 u8 reg_buf[] = { reg >> 8, reg & 0xff };
137 struct i2c_msg msg[] = {
138 { .addr = state->cfg->i2c_addr,
139 .flags = 0, .buf = reg_buf, .len = 2 },
140 { .addr = state->cfg->i2c_addr,
141 .flags = I2C_M_RD, .buf = val, .len = 1 },
142 };
143
144 lg_reg("reg: 0x%04x\n", reg);
145
146 ret = i2c_transfer(state->i2c_adap, msg, 2);
147
148 if (ret != 2) {
149 lg_err("error (addr %02x reg %04x error (ret == %i)\n",
150 state->cfg->i2c_addr, reg, ret);
151 if (ret < 0)
152 return ret;
153 else
154 return -EREMOTEIO;
155 }
156 return 0;
157}
158
159#define read_reg(state, reg) \
160({ \
161 u8 __val; \
162 int ret = lgdt3305_read_reg(state, reg, &__val); \
163 if (lg_fail(ret)) \
164 __val = 0; \
165 __val; \
166})
167
168static int lgdt3305_set_reg_bit(struct lgdt3305_state *state,
169 u16 reg, int bit, int onoff)
170{
171 u8 val;
172 int ret;
173
174 lg_reg("reg: 0x%04x, bit: %d, level: %d\n", reg, bit, onoff);
175
176 ret = lgdt3305_read_reg(state, reg, &val);
177 if (lg_fail(ret))
178 goto fail;
179
180 val &= ~(1 << bit);
181 val |= (onoff & 1) << bit;
182
183 ret = lgdt3305_write_reg(state, reg, val);
184fail:
185 return ret;
186}
187
188struct lgdt3305_reg {
189 u16 reg;
190 u8 val;
191};
192
193static int lgdt3305_write_regs(struct lgdt3305_state *state,
194 struct lgdt3305_reg *regs, int len)
195{
196 int i, ret;
197
198 lg_reg("writing %d registers...\n", len);
199
200 for (i = 0; i < len - 1; i++) {
201 ret = lgdt3305_write_reg(state, regs[i].reg, regs[i].val);
202 if (lg_fail(ret))
203 return ret;
204 }
205 return 0;
206}
207
208/* ------------------------------------------------------------------------ */
209
210static int lgdt3305_soft_reset(struct lgdt3305_state *state)
211{
212 int ret;
213
214 lg_dbg("\n");
215
216 ret = lgdt3305_set_reg_bit(state, LGDT3305_GEN_CTRL_3, 0, 0);
217 if (lg_fail(ret))
218 goto fail;
219
220 msleep(20);
221 ret = lgdt3305_set_reg_bit(state, LGDT3305_GEN_CTRL_3, 0, 1);
222fail:
223 return ret;
224}
225
226static inline int lgdt3305_mpeg_mode(struct lgdt3305_state *state,
227 enum lgdt3305_mpeg_mode mode)
228{
229 lg_dbg("(%d)\n", mode);
230 return lgdt3305_set_reg_bit(state, LGDT3305_TP_CTRL_1, 5, mode);
231}
232
233static int lgdt3305_mpeg_mode_polarity(struct lgdt3305_state *state,
234 enum lgdt3305_tp_clock_edge edge,
235 enum lgdt3305_tp_valid_polarity valid)
236{
237 u8 val;
238 int ret;
239
240 lg_dbg("edge = %d, valid = %d\n", edge, valid);
241
242 ret = lgdt3305_read_reg(state, LGDT3305_TP_CTRL_1, &val);
243 if (lg_fail(ret))
244 goto fail;
245
246 val &= ~0x09;
247
248 if (edge)
249 val |= 0x08;
250 if (valid)
251 val |= 0x01;
252
253 ret = lgdt3305_write_reg(state, LGDT3305_TP_CTRL_1, val);
254 if (lg_fail(ret))
255 goto fail;
256
257 ret = lgdt3305_soft_reset(state);
258fail:
259 return ret;
260}
261
262static int lgdt3305_set_modulation(struct lgdt3305_state *state,
263 struct dvb_frontend_parameters *param)
264{
265 u8 opermode;
266 int ret;
267
268 lg_dbg("\n");
269
270 ret = lgdt3305_read_reg(state, LGDT3305_GEN_CTRL_1, &opermode);
271 if (lg_fail(ret))
272 goto fail;
273
274 opermode &= ~0x03;
275
276 switch (param->u.vsb.modulation) {
277 case VSB_8:
278 opermode |= 0x03;
279 break;
280 case QAM_64:
281 opermode |= 0x00;
282 break;
283 case QAM_256:
284 opermode |= 0x01;
285 break;
286 default:
287 return -EINVAL;
288 }
289 ret = lgdt3305_write_reg(state, LGDT3305_GEN_CTRL_1, opermode);
290fail:
291 return ret;
292}
293
294static int lgdt3305_set_filter_extension(struct lgdt3305_state *state,
295 struct dvb_frontend_parameters *param)
296{
297 int val;
298
299 switch (param->u.vsb.modulation) {
300 case VSB_8:
301 val = 0;
302 break;
303 case QAM_64:
304 case QAM_256:
305 val = 1;
306 break;
307 default:
308 return -EINVAL;
309 }
310 lg_dbg("val = %d\n", val);
311
312 return lgdt3305_set_reg_bit(state, 0x043f, 2, val);
313}
314
315/* ------------------------------------------------------------------------ */
316
317static int lgdt3305_passband_digital_agc(struct lgdt3305_state *state,
318 struct dvb_frontend_parameters *param)
319{
320 u16 agc_ref;
321
322 switch (param->u.vsb.modulation) {
323 case VSB_8:
324 agc_ref = 0x32c4;
325 break;
326 case QAM_64:
327 agc_ref = 0x2a00;
328 break;
329 case QAM_256:
330 agc_ref = 0x2a80;
331 break;
332 default:
333 return -EINVAL;
334 }
335
336 lg_dbg("agc ref: 0x%04x\n", agc_ref);
337
338 lgdt3305_write_reg(state, LGDT3305_DGTL_AGC_REF_1, agc_ref >> 8);
339 lgdt3305_write_reg(state, LGDT3305_DGTL_AGC_REF_2, agc_ref & 0xff);
340
341 return 0;
342}
343
344static int lgdt3305_rfagc_loop(struct lgdt3305_state *state,
345 struct dvb_frontend_parameters *param)
346{
347 u16 ifbw, rfbw, agcdelay;
348
349 switch (param->u.vsb.modulation) {
350 case VSB_8:
351 agcdelay = 0x04c0;
352 rfbw = 0x8000;
353 ifbw = 0x8000;
354 break;
355 case QAM_64:
356 case QAM_256:
357 agcdelay = 0x046b;
358 rfbw = 0x8889;
359 ifbw = 0x8888;
360 break;
361 default:
362 return -EINVAL;
363 }
364
365 if (state->cfg->rf_agc_loop) {
366 lg_dbg("agcdelay: 0x%04x, rfbw: 0x%04x\n", agcdelay, rfbw);
367
368 /* rf agc loop filter bandwidth */
369 lgdt3305_write_reg(state, LGDT3305_AGC_DELAY_PT_1,
370 agcdelay >> 8);
371 lgdt3305_write_reg(state, LGDT3305_AGC_DELAY_PT_2,
372 agcdelay & 0xff);
373
374 lgdt3305_write_reg(state, LGDT3305_RFAGC_LOOP_FLTR_BW_1,
375 rfbw >> 8);
376 lgdt3305_write_reg(state, LGDT3305_RFAGC_LOOP_FLTR_BW_2,
377 rfbw & 0xff);
378 } else {
379 lg_dbg("ifbw: 0x%04x\n", ifbw);
380
381 /* if agc loop filter bandwidth */
382 lgdt3305_write_reg(state, LGDT3305_IFBW_1, ifbw >> 8);
383 lgdt3305_write_reg(state, LGDT3305_IFBW_2, ifbw & 0xff);
384 }
385
386 return 0;
387}
388
389static int lgdt3305_agc_setup(struct lgdt3305_state *state,
390 struct dvb_frontend_parameters *param)
391{
392 int lockdten, acqen;
393
394 switch (param->u.vsb.modulation) {
395 case VSB_8:
396 lockdten = 0;
397 acqen = 0;
398 break;
399 case QAM_64:
400 case QAM_256:
401 lockdten = 1;
402 acqen = 1;
403 break;
404 default:
405 return -EINVAL;
406 }
407
408 lg_dbg("lockdten = %d, acqen = %d\n", lockdten, acqen);
409
410 /* control agc function */
411 lgdt3305_write_reg(state, LGDT3305_AGC_CTRL_4, 0xe1 | lockdten << 1);
412 lgdt3305_set_reg_bit(state, LGDT3305_AGC_CTRL_1, 2, acqen);
413
414 return lgdt3305_rfagc_loop(state, param);
415}
416
417static int lgdt3305_set_agc_power_ref(struct lgdt3305_state *state,
418 struct dvb_frontend_parameters *param)
419{
420 u16 usref = 0;
421
422 switch (param->u.vsb.modulation) {
423 case VSB_8:
424 if (state->cfg->usref_8vsb)
425 usref = state->cfg->usref_8vsb;
426 break;
427 case QAM_64:
428 if (state->cfg->usref_qam64)
429 usref = state->cfg->usref_qam64;
430 break;
431 case QAM_256:
432 if (state->cfg->usref_qam256)
433 usref = state->cfg->usref_qam256;
434 break;
435 default:
436 return -EINVAL;
437 }
438
439 if (usref) {
440 lg_dbg("set manual mode: 0x%04x\n", usref);
441
442 lgdt3305_set_reg_bit(state, LGDT3305_AGC_CTRL_1, 3, 1);
443
444 lgdt3305_write_reg(state, LGDT3305_AGC_POWER_REF_1,
445 0xff & (usref >> 8));
446 lgdt3305_write_reg(state, LGDT3305_AGC_POWER_REF_2,
447 0xff & (usref >> 0));
448 }
449 return 0;
450}
451
452/* ------------------------------------------------------------------------ */
453
454static int lgdt3305_spectral_inversion(struct lgdt3305_state *state,
455 struct dvb_frontend_parameters *param,
456 int inversion)
457{
458 int ret;
459
460 lg_dbg("(%d)\n", inversion);
461
462 switch (param->u.vsb.modulation) {
463 case VSB_8:
464 ret = lgdt3305_write_reg(state, LGDT3305_CR_CTRL_7,
465 inversion ? 0xf9 : 0x79);
466 break;
467 case QAM_64:
468 case QAM_256:
469 ret = lgdt3305_write_reg(state, LGDT3305_FEC_BLOCK_CTRL,
470 inversion ? 0xfd : 0xff);
471 break;
472 default:
473 ret = -EINVAL;
474 }
475 return ret;
476}
477
478static int lgdt3305_set_if(struct lgdt3305_state *state,
479 struct dvb_frontend_parameters *param)
480{
481 u16 if_freq_khz;
482 u8 nco1, nco2, nco3, nco4;
483 u64 nco;
484
485 switch (param->u.vsb.modulation) {
486 case VSB_8:
487 if_freq_khz = state->cfg->vsb_if_khz;
488 break;
489 case QAM_64:
490 case QAM_256:
491 if_freq_khz = state->cfg->qam_if_khz;
492 break;
493 default:
494 return -EINVAL;
495 }
496
497 nco = if_freq_khz / 10;
498
499#define LGDT3305_64BIT_DIVISION_ENABLED 0
500 /* FIXME: 64bit division disabled to avoid linking error:
501 * WARNING: "__udivdi3" [lgdt3305.ko] undefined!
502 */
503 switch (param->u.vsb.modulation) {
504 case VSB_8:
505#if LGDT3305_64BIT_DIVISION_ENABLED
506 nco <<= 24;
507 nco /= 625;
508#else
509 nco *= ((1 << 24) / 625);
510#endif
511 break;
512 case QAM_64:
513 case QAM_256:
514#if LGDT3305_64BIT_DIVISION_ENABLED
515 nco <<= 28;
516 nco /= 625;
517#else
518 nco *= ((1 << 28) / 625);
519#endif
520 break;
521 default:
522 return -EINVAL;
523 }
524
525 nco1 = (nco >> 24) & 0x3f;
526 nco1 |= 0x40;
527 nco2 = (nco >> 16) & 0xff;
528 nco3 = (nco >> 8) & 0xff;
529 nco4 = nco & 0xff;
530
531 lgdt3305_write_reg(state, LGDT3305_CR_CTR_FREQ_1, nco1);
532 lgdt3305_write_reg(state, LGDT3305_CR_CTR_FREQ_2, nco2);
533 lgdt3305_write_reg(state, LGDT3305_CR_CTR_FREQ_3, nco3);
534 lgdt3305_write_reg(state, LGDT3305_CR_CTR_FREQ_4, nco4);
535
536 lg_dbg("%d KHz -> [%02x%02x%02x%02x]\n",
537 if_freq_khz, nco1, nco2, nco3, nco4);
538
539 return 0;
540}
541
542/* ------------------------------------------------------------------------ */
543
544static int lgdt3305_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
545{
546 struct lgdt3305_state *state = fe->demodulator_priv;
547
548 if (state->cfg->deny_i2c_rptr)
549 return 0;
550
551 lg_dbg("(%d)\n", enable);
552
553 return lgdt3305_set_reg_bit(state, LGDT3305_GEN_CTRL_2, 5,
554 enable ? 0 : 1);
555}
556
557static int lgdt3305_sleep(struct dvb_frontend *fe)
558{
559 struct lgdt3305_state *state = fe->demodulator_priv;
560 u8 gen_ctrl_3, gen_ctrl_4;
561
562 lg_dbg("\n");
563
564 gen_ctrl_3 = read_reg(state, LGDT3305_GEN_CTRL_3);
565 gen_ctrl_4 = read_reg(state, LGDT3305_GEN_CTRL_4);
566
567 /* hold in software reset while sleeping */
568 gen_ctrl_3 &= ~0x01;
569 /* tristate the IF-AGC pin */
570 gen_ctrl_3 |= 0x02;
571 /* tristate the RF-AGC pin */
572 gen_ctrl_3 |= 0x04;
573
574 /* disable vsb/qam module */
575 gen_ctrl_4 &= ~0x01;
576 /* disable adc module */
577 gen_ctrl_4 &= ~0x02;
578
579 lgdt3305_write_reg(state, LGDT3305_GEN_CTRL_3, gen_ctrl_3);
580 lgdt3305_write_reg(state, LGDT3305_GEN_CTRL_4, gen_ctrl_4);
581
582 return 0;
583}
584
585static int lgdt3305_init(struct dvb_frontend *fe)
586{
587 struct lgdt3305_state *state = fe->demodulator_priv;
588 int ret;
589
590 static struct lgdt3305_reg lgdt3305_init_data[] = {
591 { .reg = LGDT3305_GEN_CTRL_1,
592 .val = 0x03, },
593 { .reg = LGDT3305_GEN_CTRL_2,
594 .val = 0xb0, },
595 { .reg = LGDT3305_GEN_CTRL_3,
596 .val = 0x01, },
597 { .reg = LGDT3305_GEN_CONTROL,
598 .val = 0x6f, },
599 { .reg = LGDT3305_GEN_CTRL_4,
600 .val = 0x03, },
601 { .reg = LGDT3305_DGTL_AGC_REF_1,
602 .val = 0x32, },
603 { .reg = LGDT3305_DGTL_AGC_REF_2,
604 .val = 0xc4, },
605 { .reg = LGDT3305_CR_CTR_FREQ_1,
606 .val = 0x00, },
607 { .reg = LGDT3305_CR_CTR_FREQ_2,
608 .val = 0x00, },
609 { .reg = LGDT3305_CR_CTR_FREQ_3,
610 .val = 0x00, },
611 { .reg = LGDT3305_CR_CTR_FREQ_4,
612 .val = 0x00, },
613 { .reg = LGDT3305_CR_CTRL_7,
614 .val = 0x79, },
615 { .reg = LGDT3305_AGC_POWER_REF_1,
616 .val = 0x32, },
617 { .reg = LGDT3305_AGC_POWER_REF_2,
618 .val = 0xc4, },
619 { .reg = LGDT3305_AGC_DELAY_PT_1,
620 .val = 0x0d, },
621 { .reg = LGDT3305_AGC_DELAY_PT_2,
622 .val = 0x30, },
623 { .reg = LGDT3305_RFAGC_LOOP_FLTR_BW_1,
624 .val = 0x80, },
625 { .reg = LGDT3305_RFAGC_LOOP_FLTR_BW_2,
626 .val = 0x00, },
627 { .reg = LGDT3305_IFBW_1,
628 .val = 0x80, },
629 { .reg = LGDT3305_IFBW_2,
630 .val = 0x00, },
631 { .reg = LGDT3305_AGC_CTRL_1,
632 .val = 0x30, },
633 { .reg = LGDT3305_AGC_CTRL_4,
634 .val = 0x61, },
635 { .reg = LGDT3305_FEC_BLOCK_CTRL,
636 .val = 0xff, },
637 { .reg = LGDT3305_TP_CTRL_1,
638 .val = 0x1b, },
639 };
640
641 lg_dbg("\n");
642
643 ret = lgdt3305_write_regs(state, lgdt3305_init_data,
644 ARRAY_SIZE(lgdt3305_init_data));
645 if (lg_fail(ret))
646 goto fail;
647
648 ret = lgdt3305_soft_reset(state);
649fail:
650 return ret;
651}
652
653static int lgdt3305_set_parameters(struct dvb_frontend *fe,
654 struct dvb_frontend_parameters *param)
655{
656 struct lgdt3305_state *state = fe->demodulator_priv;
657 int ret;
658
659 lg_dbg("(%d, %d)\n", param->frequency, param->u.vsb.modulation);
660
661 if (fe->ops.tuner_ops.set_params) {
662 ret = fe->ops.tuner_ops.set_params(fe, param);
663 if (fe->ops.i2c_gate_ctrl)
664 fe->ops.i2c_gate_ctrl(fe, 0);
665 if (lg_fail(ret))
666 goto fail;
667 state->current_frequency = param->frequency;
668 }
669
670 ret = lgdt3305_set_modulation(state, param);
671 if (lg_fail(ret))
672 goto fail;
673
674 ret = lgdt3305_passband_digital_agc(state, param);
675 if (lg_fail(ret))
676 goto fail;
677 ret = lgdt3305_set_agc_power_ref(state, param);
678 if (lg_fail(ret))
679 goto fail;
680 ret = lgdt3305_agc_setup(state, param);
681 if (lg_fail(ret))
682 goto fail;
683
684 /* low if */
685 ret = lgdt3305_write_reg(state, LGDT3305_GEN_CONTROL, 0x2f);
686 if (lg_fail(ret))
687 goto fail;
688 ret = lgdt3305_set_reg_bit(state, LGDT3305_CR_CTR_FREQ_1, 6, 1);
689 if (lg_fail(ret))
690 goto fail;
691
692 ret = lgdt3305_set_if(state, param);
693 if (lg_fail(ret))
694 goto fail;
695 ret = lgdt3305_spectral_inversion(state, param,
696 state->cfg->spectral_inversion
697 ? 1 : 0);
698 if (lg_fail(ret))
699 goto fail;
700
701 ret = lgdt3305_set_filter_extension(state, param);
702 if (lg_fail(ret))
703 goto fail;
704
705 state->current_modulation = param->u.vsb.modulation;
706
707 ret = lgdt3305_mpeg_mode(state, state->cfg->mpeg_mode);
708 if (lg_fail(ret))
709 goto fail;
710
711 /* lgdt3305_mpeg_mode_polarity calls lgdt3305_soft_reset */
712 ret = lgdt3305_mpeg_mode_polarity(state,
713 state->cfg->tpclk_edge,
714 state->cfg->tpvalid_polarity);
715fail:
716 return ret;
717}
718
719static int lgdt3305_get_frontend(struct dvb_frontend *fe,
720 struct dvb_frontend_parameters *param)
721{
722 struct lgdt3305_state *state = fe->demodulator_priv;
723
724 lg_dbg("\n");
725
726 param->u.vsb.modulation = state->current_modulation;
727 param->frequency = state->current_frequency;
728 return 0;
729}
730
731/* ------------------------------------------------------------------------ */
732
733static int lgdt3305_read_cr_lock_status(struct lgdt3305_state *state,
734 int *locked)
735{
736 u8 val;
737 int ret;
738 char *cr_lock_state = "";
739
740 *locked = 0;
741
742 ret = lgdt3305_read_reg(state, LGDT3305_CR_LOCK_STATUS, &val);
743 if (lg_fail(ret))
744 goto fail;
745
746 switch (state->current_modulation) {
747 case QAM_256:
748 case QAM_64:
749 if (val & (1 << 1))
750 *locked = 1;
751
752 switch (val & 0x07) {
753 case 0:
754 cr_lock_state = "QAM UNLOCK";
755 break;
756 case 4:
757 cr_lock_state = "QAM 1stLock";
758 break;
759 case 6:
760 cr_lock_state = "QAM 2ndLock";
761 break;
762 case 7:
763 cr_lock_state = "QAM FinalLock";
764 break;
765 default:
766 cr_lock_state = "CLOCKQAM-INVALID!";
767 break;
768 }
769 break;
770 case VSB_8:
771 if (val & (1 << 7)) {
772 *locked = 1;
773 cr_lock_state = "CLOCKVSB";
774 }
775 break;
776 default:
777 ret = -EINVAL;
778 }
779 lg_dbg("(%d) %s\n", *locked, cr_lock_state);
780fail:
781 return ret;
782}
783
784static int lgdt3305_read_fec_lock_status(struct lgdt3305_state *state,
785 int *locked)
786{
787 u8 val;
788 int ret, mpeg_lock, fec_lock, viterbi_lock;
789
790 *locked = 0;
791
792 switch (state->current_modulation) {
793 case QAM_256:
794 case QAM_64:
795 ret = lgdt3305_read_reg(state,
796 LGDT3305_FEC_LOCK_STATUS, &val);
797 if (lg_fail(ret))
798 goto fail;
799
800 mpeg_lock = (val & (1 << 0)) ? 1 : 0;
801 fec_lock = (val & (1 << 2)) ? 1 : 0;
802 viterbi_lock = (val & (1 << 3)) ? 1 : 0;
803
804 *locked = mpeg_lock && fec_lock && viterbi_lock;
805
806 lg_dbg("(%d) %s%s%s\n", *locked,
807 mpeg_lock ? "mpeg lock " : "",
808 fec_lock ? "fec lock " : "",
809 viterbi_lock ? "viterbi lock" : "");
810 break;
811 case VSB_8:
812 default:
813 ret = -EINVAL;
814 }
815fail:
816 return ret;
817}
818
819static int lgdt3305_read_status(struct dvb_frontend *fe, fe_status_t *status)
820{
821 struct lgdt3305_state *state = fe->demodulator_priv;
822 u8 val;
823 int ret, signal, inlock, nofecerr, snrgood,
824 cr_lock, fec_lock, sync_lock;
825
826 *status = 0;
827
828 ret = lgdt3305_read_reg(state, LGDT3305_GEN_STATUS, &val);
829 if (lg_fail(ret))
830 goto fail;
831
832 signal = (val & (1 << 4)) ? 1 : 0;
833 inlock = (val & (1 << 3)) ? 0 : 1;
834 sync_lock = (val & (1 << 2)) ? 1 : 0;
835 nofecerr = (val & (1 << 1)) ? 1 : 0;
836 snrgood = (val & (1 << 0)) ? 1 : 0;
837
838 lg_dbg("%s%s%s%s%s\n",
839 signal ? "SIGNALEXIST " : "",
840 inlock ? "INLOCK " : "",
841 sync_lock ? "SYNCLOCK " : "",
842 nofecerr ? "NOFECERR " : "",
843 snrgood ? "SNRGOOD " : "");
844
845 ret = lgdt3305_read_cr_lock_status(state, &cr_lock);
846 if (lg_fail(ret))
847 goto fail;
848
849 if (signal)
850 *status |= FE_HAS_SIGNAL;
851 if (cr_lock)
852 *status |= FE_HAS_CARRIER;
853 if (nofecerr)
854 *status |= FE_HAS_VITERBI;
855 if (sync_lock)
856 *status |= FE_HAS_SYNC;
857
858 switch (state->current_modulation) {
859 case QAM_256:
860 case QAM_64:
861 ret = lgdt3305_read_fec_lock_status(state, &fec_lock);
862 if (lg_fail(ret))
863 goto fail;
864
865 if (fec_lock)
866 *status |= FE_HAS_LOCK;
867 break;
868 case VSB_8:
869 if (inlock)
870 *status |= FE_HAS_LOCK;
871 break;
872 default:
873 ret = -EINVAL;
874 }
875fail:
876 return ret;
877}
878
879/* ------------------------------------------------------------------------ */
880
881/* borrowed from lgdt330x.c */
882static u32 calculate_snr(u32 mse, u32 c)
883{
884 if (mse == 0) /* no signal */
885 return 0;
886
887 mse = intlog10(mse);
888 if (mse > c) {
889 /* Negative SNR, which is possible, but realisticly the
890 demod will lose lock before the signal gets this bad. The
891 API only allows for unsigned values, so just return 0 */
892 return 0;
893 }
894 return 10*(c - mse);
895}
896
897static int lgdt3305_read_snr(struct dvb_frontend *fe, u16 *snr)
898{
899 struct lgdt3305_state *state = fe->demodulator_priv;
900 u32 noise; /* noise value */
901 u32 c; /* per-modulation SNR calculation constant */
902
903 switch (state->current_modulation) {
904 case VSB_8:
905#ifdef USE_PTMSE
906 /* Use Phase Tracker Mean-Square Error Register */
907 /* SNR for ranges from -13.11 to +44.08 */
908 noise = ((read_reg(state, LGDT3305_PT_MSE_1) & 0x07) << 16) |
909 (read_reg(state, LGDT3305_PT_MSE_2) << 8) |
910 (read_reg(state, LGDT3305_PT_MSE_3) & 0xff);
911 c = 73957994; /* log10(25*32^2)*2^24 */
912#else
913 /* Use Equalizer Mean-Square Error Register */
914 /* SNR for ranges from -16.12 to +44.08 */
915 noise = ((read_reg(state, LGDT3305_EQ_MSE_1) & 0x0f) << 16) |
916 (read_reg(state, LGDT3305_EQ_MSE_2) << 8) |
917 (read_reg(state, LGDT3305_EQ_MSE_3) & 0xff);
918 c = 73957994; /* log10(25*32^2)*2^24 */
919#endif
920 break;
921 case QAM_64:
922 case QAM_256:
923 noise = (read_reg(state, LGDT3305_CR_MSE_1) << 8) |
924 (read_reg(state, LGDT3305_CR_MSE_2) & 0xff);
925
926 c = (state->current_modulation == QAM_64) ?
927 97939837 : 98026066;
928 /* log10(688128)*2^24 and log10(696320)*2^24 */
929 break;
930 default:
931 return -EINVAL;
932 }
933 state->snr = calculate_snr(noise, c);
934 /* report SNR in dB * 10 */
935 *snr = (state->snr / ((1 << 24) / 10));
936 lg_dbg("noise = 0x%08x, snr = %d.%02d dB\n", noise,
937 state->snr >> 24, (((state->snr >> 8) & 0xffff) * 100) >> 16);
938
939 return 0;
940}
941
942static int lgdt3305_read_signal_strength(struct dvb_frontend *fe,
943 u16 *strength)
944{
945 /* borrowed from lgdt330x.c
946 *
947 * Calculate strength from SNR up to 35dB
948 * Even though the SNR can go higher than 35dB,
949 * there is some comfort factor in having a range of
950 * strong signals that can show at 100%
951 */
952 struct lgdt3305_state *state = fe->demodulator_priv;
953 u16 snr;
954 int ret;
955
956 *strength = 0;
957
958 ret = fe->ops.read_snr(fe, &snr);
959 if (lg_fail(ret))
960 goto fail;
961 /* Rather than use the 8.8 value snr, use state->snr which is 8.24 */
962 /* scale the range 0 - 35*2^24 into 0 - 65535 */
963 if (state->snr >= 8960 * 0x10000)
964 *strength = 0xffff;
965 else
966 *strength = state->snr / 8960;
967fail:
968 return ret;
969}
970
971/* ------------------------------------------------------------------------ */
972
973static int lgdt3305_read_ber(struct dvb_frontend *fe, u32 *ber)
974{
975 *ber = 0;
976 return 0;
977}
978
979static int lgdt3305_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
980{
981 struct lgdt3305_state *state = fe->demodulator_priv;
982
983 *ucblocks =
984 (read_reg(state, LGDT3305_FEC_PKT_ERR_1) << 8) |
985 (read_reg(state, LGDT3305_FEC_PKT_ERR_2) & 0xff);
986
987 return 0;
988}
989
990static int lgdt3305_get_tune_settings(struct dvb_frontend *fe,
991 struct dvb_frontend_tune_settings
992 *fe_tune_settings)
993{
994 fe_tune_settings->min_delay_ms = 500;
995 lg_dbg("\n");
996 return 0;
997}
998
999static void lgdt3305_release(struct dvb_frontend *fe)
1000{
1001 struct lgdt3305_state *state = fe->demodulator_priv;
1002 lg_dbg("\n");
1003 kfree(state);
1004}
1005
1006static struct dvb_frontend_ops lgdt3305_ops;
1007
1008struct dvb_frontend *lgdt3305_attach(const struct lgdt3305_config *config,
1009 struct i2c_adapter *i2c_adap)
1010{
1011 struct lgdt3305_state *state = NULL;
1012 int ret;
1013 u8 val;
1014
1015 lg_dbg("(%d-%04x)\n",
1016 i2c_adap ? i2c_adapter_id(i2c_adap) : 0,
1017 config ? config->i2c_addr : 0);
1018
1019 state = kzalloc(sizeof(struct lgdt3305_state), GFP_KERNEL);
1020 if (state == NULL)
1021 goto fail;
1022
1023 state->cfg = config;
1024 state->i2c_adap = i2c_adap;
1025
1026 memcpy(&state->frontend.ops, &lgdt3305_ops,
1027 sizeof(struct dvb_frontend_ops));
1028 state->frontend.demodulator_priv = state;
1029
1030 /* verify that we're talking to a lg dt3305 */
1031 ret = lgdt3305_read_reg(state, LGDT3305_GEN_CTRL_2, &val);
1032 if ((lg_fail(ret)) | (val == 0))
1033 goto fail;
1034 ret = lgdt3305_write_reg(state, 0x0808, 0x80);
1035 if (lg_fail(ret))
1036 goto fail;
1037 ret = lgdt3305_read_reg(state, 0x0808, &val);
1038 if ((lg_fail(ret)) | (val != 0x80))
1039 goto fail;
1040 ret = lgdt3305_write_reg(state, 0x0808, 0x00);
1041 if (lg_fail(ret))
1042 goto fail;
1043
1044 state->current_frequency = -1;
1045 state->current_modulation = -1;
1046
1047 return &state->frontend;
1048fail:
1049 lg_warn("unable to detect LGDT3305 hardware\n");
1050 kfree(state);
1051 return NULL;
1052}
1053EXPORT_SYMBOL(lgdt3305_attach);
1054
1055static struct dvb_frontend_ops lgdt3305_ops = {
1056 .info = {
1057 .name = "LG Electronics LGDT3305 VSB/QAM Frontend",
1058 .type = FE_ATSC,
1059 .frequency_min = 54000000,
1060 .frequency_max = 858000000,
1061 .frequency_stepsize = 62500,
1062 .caps = FE_CAN_QAM_64 | FE_CAN_QAM_256 | FE_CAN_8VSB
1063 },
1064 .i2c_gate_ctrl = lgdt3305_i2c_gate_ctrl,
1065 .init = lgdt3305_init,
1066 .sleep = lgdt3305_sleep,
1067 .set_frontend = lgdt3305_set_parameters,
1068 .get_frontend = lgdt3305_get_frontend,
1069 .get_tune_settings = lgdt3305_get_tune_settings,
1070 .read_status = lgdt3305_read_status,
1071 .read_ber = lgdt3305_read_ber,
1072 .read_signal_strength = lgdt3305_read_signal_strength,
1073 .read_snr = lgdt3305_read_snr,
1074 .read_ucblocks = lgdt3305_read_ucblocks,
1075 .release = lgdt3305_release,
1076};
1077
1078MODULE_DESCRIPTION("LG Electronics LGDT3305 ATSC/QAM-B Demodulator Driver");
1079MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>");
1080MODULE_LICENSE("GPL");
1081MODULE_VERSION("0.1");
1082
1083/*
1084 * Local variables:
1085 * c-basic-offset: 8
1086 * End:
1087 */
diff --git a/drivers/media/dvb/frontends/lgdt3305.h b/drivers/media/dvb/frontends/lgdt3305.h
new file mode 100644
index 000000000000..4fa6e52d1fe8
--- /dev/null
+++ b/drivers/media/dvb/frontends/lgdt3305.h
@@ -0,0 +1,85 @@
1/*
2 * Support for LGDT3305 - VSB/QAM
3 *
4 * Copyright (C) 2008, 2009 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
22#ifndef _LGDT3305_H_
23#define _LGDT3305_H_
24
25#include <linux/i2c.h>
26#include "dvb_frontend.h"
27
28
29enum lgdt3305_mpeg_mode {
30 LGDT3305_MPEG_PARALLEL = 0,
31 LGDT3305_MPEG_SERIAL = 1,
32};
33
34enum lgdt3305_tp_clock_edge {
35 LGDT3305_TPCLK_RISING_EDGE = 0,
36 LGDT3305_TPCLK_FALLING_EDGE = 1,
37};
38
39enum lgdt3305_tp_valid_polarity {
40 LGDT3305_TP_VALID_LOW = 0,
41 LGDT3305_TP_VALID_HIGH = 1,
42};
43
44struct lgdt3305_config {
45 u8 i2c_addr;
46
47 /* user defined IF frequency in KHz */
48 u16 qam_if_khz;
49 u16 vsb_if_khz;
50
51 /* AGC Power reference - defaults are used if left unset */
52 u16 usref_8vsb; /* default: 0x32c4 */
53 u16 usref_qam64; /* default: 0x5400 */
54 u16 usref_qam256; /* default: 0x2a80 */
55
56 /* disable i2c repeater - 0:repeater enabled 1:repeater disabled */
57 int deny_i2c_rptr:1;
58
59 /* spectral inversion - 0:disabled 1:enabled */
60 int spectral_inversion:1;
61
62 /* use RF AGC loop - 0:disabled 1:enabled */
63 int rf_agc_loop:1;
64
65 enum lgdt3305_mpeg_mode mpeg_mode;
66 enum lgdt3305_tp_clock_edge tpclk_edge;
67 enum lgdt3305_tp_valid_polarity tpvalid_polarity;
68};
69
70#if defined(CONFIG_DVB_LGDT3305) || (defined(CONFIG_DVB_LGDT3305_MODULE) && \
71 defined(MODULE))
72extern
73struct dvb_frontend *lgdt3305_attach(const struct lgdt3305_config *config,
74 struct i2c_adapter *i2c_adap);
75#else
76static inline
77struct dvb_frontend *lgdt3305_attach(const struct lgdt3305_config *config,
78 struct i2c_adapter *i2c_adap)
79{
80 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
81 return NULL;
82}
83#endif /* CONFIG_DVB_LGDT3305 */
84
85#endif /* _LGDT3305_H_ */
diff --git a/drivers/media/dvb/frontends/lnbh24.h b/drivers/media/dvb/frontends/lnbh24.h
new file mode 100644
index 000000000000..c059b165318f
--- /dev/null
+++ b/drivers/media/dvb/frontends/lnbh24.h
@@ -0,0 +1,55 @@
1/*
2 * lnbh24.h - driver for lnb supply and control ic lnbh24
3 *
4 * Copyright (C) 2009 NetUP Inc.
5 * Copyright (C) 2009 Igor M. Liplianin <liplianin@netup.ru>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 *
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23#ifndef _LNBH24_H
24#define _LNBH24_H
25
26/* system register bits */
27#define LNBH24_OLF 0x01
28#define LNBH24_OTF 0x02
29#define LNBH24_EN 0x04
30#define LNBH24_VSEL 0x08
31#define LNBH24_LLC 0x10
32#define LNBH24_TEN 0x20
33#define LNBH24_TTX 0x40
34#define LNBH24_PCL 0x80
35
36#include <linux/dvb/frontend.h>
37
38#if defined(CONFIG_DVB_LNBP21) || (defined(CONFIG_DVB_LNBP21_MODULE) \
39 && defined(MODULE))
40/* override_set and override_clear control which
41 system register bits (above) to always set & clear */
42extern struct dvb_frontend *lnbh24_attach(struct dvb_frontend *fe,
43 struct i2c_adapter *i2c, u8 override_set,
44 u8 override_clear, u8 i2c_addr);
45#else
46static inline struct dvb_frontend *lnbh24_attach(struct dvb_frontend *fe,
47 struct i2c_adapter *i2c, u8 override_set,
48 u8 override_clear, u8 i2c_addr)
49{
50 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
51 return NULL;
52}
53#endif
54
55#endif
diff --git a/drivers/media/dvb/frontends/lnbp21.c b/drivers/media/dvb/frontends/lnbp21.c
index 76f935d9755a..1dcc56f32bff 100644
--- a/drivers/media/dvb/frontends/lnbp21.c
+++ b/drivers/media/dvb/frontends/lnbp21.c
@@ -1,7 +1,8 @@
1/* 1/*
2 * lnbp21.h - driver for lnb supply and control ic lnbp21 2 * lnbp21.c - driver for lnb supply and control ic lnbp21
3 * 3 *
4 * Copyright (C) 2006 Oliver Endriss 4 * Copyright (C) 2006 Oliver Endriss
5 * Copyright (C) 2009 Igor M. Liplianin <liplianin@netup.ru>
5 * 6 *
6 * This program is free software; you can redistribute it and/or 7 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License 8 * modify it under the terms of the GNU General Public License
@@ -33,18 +34,21 @@
33 34
34#include "dvb_frontend.h" 35#include "dvb_frontend.h"
35#include "lnbp21.h" 36#include "lnbp21.h"
37#include "lnbh24.h"
36 38
37struct lnbp21 { 39struct lnbp21 {
38 u8 config; 40 u8 config;
39 u8 override_or; 41 u8 override_or;
40 u8 override_and; 42 u8 override_and;
41 struct i2c_adapter *i2c; 43 struct i2c_adapter *i2c;
44 u8 i2c_addr;
42}; 45};
43 46
44static int lnbp21_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage) 47static int lnbp21_set_voltage(struct dvb_frontend *fe,
48 fe_sec_voltage_t voltage)
45{ 49{
46 struct lnbp21 *lnbp21 = (struct lnbp21 *) fe->sec_priv; 50 struct lnbp21 *lnbp21 = (struct lnbp21 *) fe->sec_priv;
47 struct i2c_msg msg = { .addr = 0x08, .flags = 0, 51 struct i2c_msg msg = { .addr = lnbp21->i2c_addr, .flags = 0,
48 .buf = &lnbp21->config, 52 .buf = &lnbp21->config,
49 .len = sizeof(lnbp21->config) }; 53 .len = sizeof(lnbp21->config) };
50 54
@@ -72,7 +76,7 @@ static int lnbp21_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
72static int lnbp21_enable_high_lnb_voltage(struct dvb_frontend *fe, long arg) 76static int lnbp21_enable_high_lnb_voltage(struct dvb_frontend *fe, long arg)
73{ 77{
74 struct lnbp21 *lnbp21 = (struct lnbp21 *) fe->sec_priv; 78 struct lnbp21 *lnbp21 = (struct lnbp21 *) fe->sec_priv;
75 struct i2c_msg msg = { .addr = 0x08, .flags = 0, 79 struct i2c_msg msg = { .addr = lnbp21->i2c_addr, .flags = 0,
76 .buf = &lnbp21->config, 80 .buf = &lnbp21->config,
77 .len = sizeof(lnbp21->config) }; 81 .len = sizeof(lnbp21->config) };
78 82
@@ -97,15 +101,18 @@ static void lnbp21_release(struct dvb_frontend *fe)
97 fe->sec_priv = NULL; 101 fe->sec_priv = NULL;
98} 102}
99 103
100struct dvb_frontend *lnbp21_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, u8 override_set, u8 override_clear) 104static struct dvb_frontend *lnbx2x_attach(struct dvb_frontend *fe,
105 struct i2c_adapter *i2c, u8 override_set,
106 u8 override_clear, u8 i2c_addr, u8 config)
101{ 107{
102 struct lnbp21 *lnbp21 = kmalloc(sizeof(struct lnbp21), GFP_KERNEL); 108 struct lnbp21 *lnbp21 = kmalloc(sizeof(struct lnbp21), GFP_KERNEL);
103 if (!lnbp21) 109 if (!lnbp21)
104 return NULL; 110 return NULL;
105 111
106 /* default configuration */ 112 /* default configuration */
107 lnbp21->config = LNBP21_ISEL; 113 lnbp21->config = config;
108 lnbp21->i2c = i2c; 114 lnbp21->i2c = i2c;
115 lnbp21->i2c_addr = i2c_addr;
109 fe->sec_priv = lnbp21; 116 fe->sec_priv = lnbp21;
110 117
111 /* bits which should be forced to '1' */ 118 /* bits which should be forced to '1' */
@@ -126,11 +133,29 @@ struct dvb_frontend *lnbp21_attach(struct dvb_frontend *fe, struct i2c_adapter *
126 /* override frontend ops */ 133 /* override frontend ops */
127 fe->ops.set_voltage = lnbp21_set_voltage; 134 fe->ops.set_voltage = lnbp21_set_voltage;
128 fe->ops.enable_high_lnb_voltage = lnbp21_enable_high_lnb_voltage; 135 fe->ops.enable_high_lnb_voltage = lnbp21_enable_high_lnb_voltage;
136 printk(KERN_INFO "LNBx2x attached on addr=%x", lnbp21->i2c_addr);
129 137
130 return fe; 138 return fe;
131} 139}
140
141struct dvb_frontend *lnbh24_attach(struct dvb_frontend *fe,
142 struct i2c_adapter *i2c, u8 override_set,
143 u8 override_clear, u8 i2c_addr)
144{
145 return lnbx2x_attach(fe, i2c, override_set, override_clear,
146 i2c_addr, LNBH24_TTX);
147}
148EXPORT_SYMBOL(lnbh24_attach);
149
150struct dvb_frontend *lnbp21_attach(struct dvb_frontend *fe,
151 struct i2c_adapter *i2c, u8 override_set,
152 u8 override_clear)
153{
154 return lnbx2x_attach(fe, i2c, override_set, override_clear,
155 0x08, LNBP21_ISEL);
156}
132EXPORT_SYMBOL(lnbp21_attach); 157EXPORT_SYMBOL(lnbp21_attach);
133 158
134MODULE_DESCRIPTION("Driver for lnb supply and control ic lnbp21"); 159MODULE_DESCRIPTION("Driver for lnb supply and control ic lnbp21, lnbh24");
135MODULE_AUTHOR("Oliver Endriss"); 160MODULE_AUTHOR("Oliver Endriss, Igor M. Liplianin");
136MODULE_LICENSE("GPL"); 161MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/lnbp21.h b/drivers/media/dvb/frontends/lnbp21.h
index 8fe094bd9689..fcdf1c650dde 100644
--- a/drivers/media/dvb/frontends/lnbp21.h
+++ b/drivers/media/dvb/frontends/lnbp21.h
@@ -28,26 +28,48 @@
28#define _LNBP21_H 28#define _LNBP21_H
29 29
30/* system register bits */ 30/* system register bits */
31/* [RO] 0=OK; 1=over current limit flag */
31#define LNBP21_OLF 0x01 32#define LNBP21_OLF 0x01
33/* [RO] 0=OK; 1=over temperature flag (150 C) */
32#define LNBP21_OTF 0x02 34#define LNBP21_OTF 0x02
35/* [RW] 0=disable LNB power, enable loopthrough
36 1=enable LNB power, disable loopthrough */
33#define LNBP21_EN 0x04 37#define LNBP21_EN 0x04
38/* [RW] 0=low voltage (13/14V, vert pol)
39 1=high voltage (18/19V,horiz pol) */
34#define LNBP21_VSEL 0x08 40#define LNBP21_VSEL 0x08
41/* [RW] increase LNB voltage by 1V:
42 0=13/18V; 1=14/19V */
35#define LNBP21_LLC 0x10 43#define LNBP21_LLC 0x10
44/* [RW] 0=tone controlled by DSQIN pin
45 1=tone enable, disable DSQIN */
36#define LNBP21_TEN 0x20 46#define LNBP21_TEN 0x20
47/* [RW] current limit select:
48 0:Iout=500-650mA Isc=300mA
49 1:Iout=400-550mA Isc=200mA */
37#define LNBP21_ISEL 0x40 50#define LNBP21_ISEL 0x40
51/* [RW] short-circuit protect:
52 0=pulsed (dynamic) curr limiting
53 1=static curr limiting */
38#define LNBP21_PCL 0x80 54#define LNBP21_PCL 0x80
39 55
40#include <linux/dvb/frontend.h> 56#include <linux/dvb/frontend.h>
41 57
42#if defined(CONFIG_DVB_LNBP21) || (defined(CONFIG_DVB_LNBP21_MODULE) && defined(MODULE)) 58#if defined(CONFIG_DVB_LNBP21) || (defined(CONFIG_DVB_LNBP21_MODULE) \
43/* override_set and override_clear control which system register bits (above) to always set & clear */ 59 && defined(MODULE))
44extern struct dvb_frontend *lnbp21_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, u8 override_set, u8 override_clear); 60/* override_set and override_clear control which
61 system register bits (above) to always set & clear */
62extern struct dvb_frontend *lnbp21_attach(struct dvb_frontend *fe,
63 struct i2c_adapter *i2c, u8 override_set,
64 u8 override_clear);
45#else 65#else
46static inline struct dvb_frontend *lnbp21_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, u8 override_set, u8 override_clear) 66static inline struct dvb_frontend *lnbp21_attach(struct dvb_frontend *fe,
67 struct i2c_adapter *i2c, u8 override_set,
68 u8 override_clear)
47{ 69{
48 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 70 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
49 return NULL; 71 return NULL;
50} 72}
51#endif // CONFIG_DVB_LNBP21 73#endif
52 74
53#endif // _LNBP21_H 75#endif
diff --git a/drivers/media/dvb/frontends/s921_module.c b/drivers/media/dvb/frontends/s921_module.c
index 892af8c9ed57..3f5a0e1dfdf5 100644
--- a/drivers/media/dvb/frontends/s921_module.c
+++ b/drivers/media/dvb/frontends/s921_module.c
@@ -169,7 +169,6 @@ struct dvb_frontend* s921_attach(const struct s921_config *config,
169 169
170 struct s921_state *state; 170 struct s921_state *state;
171 state = kzalloc(sizeof(struct s921_state), GFP_KERNEL); 171 state = kzalloc(sizeof(struct s921_state), GFP_KERNEL);
172 memset(state, 0x0, sizeof(struct s921_state));
173 172
174 state->addr = config->i2c_address; 173 state->addr = config->i2c_address;
175 state->i2c = i2c; 174 state->i2c = i2c;
diff --git a/drivers/media/dvb/frontends/stb6100_cfg.h b/drivers/media/dvb/frontends/stb6100_cfg.h
index d3133405dc03..6314d18c797a 100644
--- a/drivers/media/dvb/frontends/stb6100_cfg.h
+++ b/drivers/media/dvb/frontends/stb6100_cfg.h
@@ -36,7 +36,6 @@ static int stb6100_get_frequency(struct dvb_frontend *fe, u32 *frequency)
36 return err; 36 return err;
37 } 37 }
38 *frequency = t_state.frequency; 38 *frequency = t_state.frequency;
39 printk("%s: Frequency=%d\n", __func__, t_state.frequency);
40 } 39 }
41 return 0; 40 return 0;
42} 41}
@@ -59,7 +58,6 @@ static int stb6100_set_frequency(struct dvb_frontend *fe, u32 frequency)
59 return err; 58 return err;
60 } 59 }
61 } 60 }
62 printk("%s: Frequency=%d\n", __func__, t_state.frequency);
63 return 0; 61 return 0;
64} 62}
65 63
@@ -81,7 +79,6 @@ static int stb6100_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
81 } 79 }
82 *bandwidth = t_state.bandwidth; 80 *bandwidth = t_state.bandwidth;
83 } 81 }
84 printk("%s: Bandwidth=%d\n", __func__, t_state.bandwidth);
85 return 0; 82 return 0;
86} 83}
87 84
@@ -103,6 +100,5 @@ static int stb6100_set_bandwidth(struct dvb_frontend *fe, u32 bandwidth)
103 return err; 100 return err;
104 } 101 }
105 } 102 }
106 printk("%s: Bandwidth=%d\n", __func__, t_state.bandwidth);
107 return 0; 103 return 0;
108} 104}
diff --git a/drivers/media/dvb/frontends/stv0900.h b/drivers/media/dvb/frontends/stv0900.h
new file mode 100644
index 000000000000..8a1332c2031d
--- /dev/null
+++ b/drivers/media/dvb/frontends/stv0900.h
@@ -0,0 +1,62 @@
1/*
2 * stv0900.h
3 *
4 * Driver for ST STV0900 satellite demodulator IC.
5 *
6 * Copyright (C) ST Microelectronics.
7 * Copyright (C) 2009 NetUP Inc.
8 * Copyright (C) 2009 Igor M. Liplianin <liplianin@netup.ru>
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 *
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25
26#ifndef STV0900_H
27#define STV0900_H
28
29#include <linux/dvb/frontend.h>
30#include "dvb_frontend.h"
31
32struct stv0900_config {
33 u8 demod_address;
34 u32 xtal;
35 u8 clkmode;/* 0 for CLKI, 2 for XTALI */
36
37 u8 diseqc_mode;
38
39 u8 path1_mode;
40 u8 path2_mode;
41
42 u8 tun1_maddress;/* 0, 1, 2, 3 for 0xc0, 0xc2, 0xc4, 0xc6 */
43 u8 tun2_maddress;
44 u8 tun1_adc;/* 1 for stv6110, 2 for stb6100 */
45 u8 tun2_adc;
46};
47
48#if defined(CONFIG_DVB_STV0900) || (defined(CONFIG_DVB_STV0900_MODULE) \
49 && defined(MODULE))
50extern struct dvb_frontend *stv0900_attach(const struct stv0900_config *config,
51 struct i2c_adapter *i2c, int demod);
52#else
53static inline struct dvb_frontend *stv0900_attach(const struct stv0900_config *config,
54 struct i2c_adapter *i2c, int demod)
55{
56 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
57 return NULL;
58}
59#endif
60
61#endif
62
diff --git a/drivers/media/dvb/frontends/stv0900_core.c b/drivers/media/dvb/frontends/stv0900_core.c
new file mode 100644
index 000000000000..8499bcf7f251
--- /dev/null
+++ b/drivers/media/dvb/frontends/stv0900_core.c
@@ -0,0 +1,1949 @@
1/*
2 * stv0900_core.c
3 *
4 * Driver for ST STV0900 satellite demodulator IC.
5 *
6 * Copyright (C) ST Microelectronics.
7 * Copyright (C) 2009 NetUP Inc.
8 * Copyright (C) 2009 Igor M. Liplianin <liplianin@netup.ru>
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 *
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25
26#include <linux/kernel.h>
27#include <linux/module.h>
28#include <linux/string.h>
29#include <linux/slab.h>
30#include <linux/i2c.h>
31
32#include "stv0900.h"
33#include "stv0900_reg.h"
34#include "stv0900_priv.h"
35#include "stv0900_init.h"
36
37static int stvdebug = 1;
38module_param_named(debug, stvdebug, int, 0644);
39
40/* internal params node */
41struct stv0900_inode {
42 /* pointer for internal params, one for each pair of demods */
43 struct stv0900_internal *internal;
44 struct stv0900_inode *next_inode;
45};
46
47/* first internal params */
48static struct stv0900_inode *stv0900_first_inode;
49
50/* find chip by i2c adapter and i2c address */
51static struct stv0900_inode *find_inode(struct i2c_adapter *i2c_adap,
52 u8 i2c_addr)
53{
54 struct stv0900_inode *temp_chip = stv0900_first_inode;
55
56 if (temp_chip != NULL) {
57 /*
58 Search of the last stv0900 chip or
59 find it by i2c adapter and i2c address */
60 while ((temp_chip != NULL) &&
61 ((temp_chip->internal->i2c_adap != i2c_adap) ||
62 (temp_chip->internal->i2c_addr != i2c_addr)))
63
64 temp_chip = temp_chip->next_inode;
65
66 }
67
68 return temp_chip;
69}
70
71/* deallocating chip */
72static void remove_inode(struct stv0900_internal *internal)
73{
74 struct stv0900_inode *prev_node = stv0900_first_inode;
75 struct stv0900_inode *del_node = find_inode(internal->i2c_adap,
76 internal->i2c_addr);
77
78 if (del_node != NULL) {
79 if (del_node == stv0900_first_inode) {
80 stv0900_first_inode = del_node->next_inode;
81 } else {
82 while (prev_node->next_inode != del_node)
83 prev_node = prev_node->next_inode;
84
85 if (del_node->next_inode == NULL)
86 prev_node->next_inode = NULL;
87 else
88 prev_node->next_inode =
89 prev_node->next_inode->next_inode;
90 }
91
92 kfree(del_node);
93 }
94}
95
96/* allocating new chip */
97static struct stv0900_inode *append_internal(struct stv0900_internal *internal)
98{
99 struct stv0900_inode *new_node = stv0900_first_inode;
100
101 if (new_node == NULL) {
102 new_node = kmalloc(sizeof(struct stv0900_inode), GFP_KERNEL);
103 stv0900_first_inode = new_node;
104 } else {
105 while (new_node->next_inode != NULL)
106 new_node = new_node->next_inode;
107
108 new_node->next_inode = kmalloc(sizeof(struct stv0900_inode), GFP_KERNEL);
109 if (new_node->next_inode != NULL)
110 new_node = new_node->next_inode;
111 else
112 new_node = NULL;
113 }
114
115 if (new_node != NULL) {
116 new_node->internal = internal;
117 new_node->next_inode = NULL;
118 }
119
120 return new_node;
121}
122
123s32 ge2comp(s32 a, s32 width)
124{
125 if (width == 32)
126 return a;
127 else
128 return (a >= (1 << (width - 1))) ? (a - (1 << width)) : a;
129}
130
131void stv0900_write_reg(struct stv0900_internal *i_params, u16 reg_addr,
132 u8 reg_data)
133{
134 u8 data[3];
135 int ret;
136 struct i2c_msg i2cmsg = {
137 .addr = i_params->i2c_addr,
138 .flags = 0,
139 .len = 3,
140 .buf = data,
141 };
142
143 data[0] = MSB(reg_addr);
144 data[1] = LSB(reg_addr);
145 data[2] = reg_data;
146
147 ret = i2c_transfer(i_params->i2c_adap, &i2cmsg, 1);
148 if (ret != 1)
149 dprintk(KERN_ERR "%s: i2c error %d\n", __func__, ret);
150}
151
152u8 stv0900_read_reg(struct stv0900_internal *i_params, u16 reg_addr)
153{
154 u8 data[2];
155 int ret;
156 struct i2c_msg i2cmsg = {
157 .addr = i_params->i2c_addr,
158 .flags = 0,
159 .len = 2,
160 .buf = data,
161 };
162
163 data[0] = MSB(reg_addr);
164 data[1] = LSB(reg_addr);
165
166 ret = i2c_transfer(i_params->i2c_adap, &i2cmsg, 1);
167 if (ret != 1)
168 dprintk(KERN_ERR "%s: i2c error %d\n", __func__, ret);
169
170 i2cmsg.flags = I2C_M_RD;
171 i2cmsg.len = 1;
172 ret = i2c_transfer(i_params->i2c_adap, &i2cmsg, 1);
173 if (ret != 1)
174 dprintk(KERN_ERR "%s: i2c error %d\n", __func__, ret);
175
176 return data[0];
177}
178
179void extract_mask_pos(u32 label, u8 *mask, u8 *pos)
180{
181 u8 position = 0, i = 0;
182
183 (*mask) = label & 0xff;
184
185 while ((position == 0) && (i < 8)) {
186 position = ((*mask) >> i) & 0x01;
187 i++;
188 }
189
190 (*pos) = (i - 1);
191}
192
193void stv0900_write_bits(struct stv0900_internal *i_params, u32 label, u8 val)
194{
195 u8 reg, mask, pos;
196
197 reg = stv0900_read_reg(i_params, (label >> 16) & 0xffff);
198 extract_mask_pos(label, &mask, &pos);
199
200 val = mask & (val << pos);
201
202 reg = (reg & (~mask)) | val;
203 stv0900_write_reg(i_params, (label >> 16) & 0xffff, reg);
204
205}
206
207u8 stv0900_get_bits(struct stv0900_internal *i_params, u32 label)
208{
209 u8 val = 0xff;
210 u8 mask, pos;
211
212 extract_mask_pos(label, &mask, &pos);
213
214 val = stv0900_read_reg(i_params, label >> 16);
215 val = (val & mask) >> pos;
216
217 return val;
218}
219
220enum fe_stv0900_error stv0900_initialize(struct stv0900_internal *i_params)
221{
222 s32 i;
223 enum fe_stv0900_error error;
224
225 if (i_params != NULL) {
226 i_params->chip_id = stv0900_read_reg(i_params, R0900_MID);
227 if (i_params->errs == STV0900_NO_ERROR) {
228 /*Startup sequence*/
229 stv0900_write_reg(i_params, R0900_P1_DMDISTATE, 0x5c);
230 stv0900_write_reg(i_params, R0900_P2_DMDISTATE, 0x5c);
231 stv0900_write_reg(i_params, R0900_P1_TNRCFG, 0x6c);
232 stv0900_write_reg(i_params, R0900_P2_TNRCFG, 0x6f);
233 stv0900_write_reg(i_params, R0900_P1_I2CRPT, 0x24);
234 stv0900_write_reg(i_params, R0900_P2_I2CRPT, 0x24);
235 stv0900_write_reg(i_params, R0900_NCOARSE, 0x13);
236 msleep(3);
237 stv0900_write_reg(i_params, R0900_I2CCFG, 0x08);
238
239 switch (i_params->clkmode) {
240 case 0:
241 case 2:
242 stv0900_write_reg(i_params, R0900_SYNTCTRL, 0x20
243 | i_params->clkmode);
244 break;
245 default:
246 /* preserve SELOSCI bit */
247 i = 0x02 & stv0900_read_reg(i_params, R0900_SYNTCTRL);
248 stv0900_write_reg(i_params, R0900_SYNTCTRL, 0x20 | i);
249 break;
250 }
251
252 msleep(3);
253 for (i = 0; i < 182; i++)
254 stv0900_write_reg(i_params, STV0900_InitVal[i][0], STV0900_InitVal[i][1]);
255
256 if (stv0900_read_reg(i_params, R0900_MID) >= 0x20) {
257 stv0900_write_reg(i_params, R0900_TSGENERAL, 0x0c);
258 for (i = 0; i < 32; i++)
259 stv0900_write_reg(i_params, STV0900_Cut20_AddOnVal[i][0], STV0900_Cut20_AddOnVal[i][1]);
260 }
261
262 stv0900_write_reg(i_params, R0900_P1_FSPYCFG, 0x6c);
263 stv0900_write_reg(i_params, R0900_P2_FSPYCFG, 0x6c);
264 stv0900_write_reg(i_params, R0900_TSTRES0, 0x80);
265 stv0900_write_reg(i_params, R0900_TSTRES0, 0x00);
266 }
267 error = i_params->errs;
268 } else
269 error = STV0900_INVALID_HANDLE;
270
271 return error;
272
273}
274
275u32 stv0900_get_mclk_freq(struct stv0900_internal *i_params, u32 ext_clk)
276{
277 u32 mclk = 90000000, div = 0, ad_div = 0;
278
279 div = stv0900_get_bits(i_params, F0900_M_DIV);
280 ad_div = ((stv0900_get_bits(i_params, F0900_SELX1RATIO) == 1) ? 4 : 6);
281
282 mclk = (div + 1) * ext_clk / ad_div;
283
284 dprintk(KERN_INFO "%s: Calculated Mclk = %d\n", __func__, mclk);
285
286 return mclk;
287}
288
289enum fe_stv0900_error stv0900_set_mclk(struct stv0900_internal *i_params, u32 mclk)
290{
291 enum fe_stv0900_error error = STV0900_NO_ERROR;
292 u32 m_div, clk_sel;
293
294 dprintk(KERN_INFO "%s: Mclk set to %d, Quartz = %d\n", __func__, mclk,
295 i_params->quartz);
296
297 if (i_params == NULL)
298 error = STV0900_INVALID_HANDLE;
299 else {
300 if (i_params->errs)
301 error = STV0900_I2C_ERROR;
302 else {
303 clk_sel = ((stv0900_get_bits(i_params, F0900_SELX1RATIO) == 1) ? 4 : 6);
304 m_div = ((clk_sel * mclk) / i_params->quartz) - 1;
305 stv0900_write_bits(i_params, F0900_M_DIV, m_div);
306 i_params->mclk = stv0900_get_mclk_freq(i_params,
307 i_params->quartz);
308
309 /*Set the DiseqC frequency to 22KHz */
310 /*
311 Formula:
312 DiseqC_TX_Freq= MasterClock/(32*F22TX_Reg)
313 DiseqC_RX_Freq= MasterClock/(32*F22RX_Reg)
314 */
315 m_div = i_params->mclk / 704000;
316 stv0900_write_reg(i_params, R0900_P1_F22TX, m_div);
317 stv0900_write_reg(i_params, R0900_P1_F22RX, m_div);
318
319 stv0900_write_reg(i_params, R0900_P2_F22TX, m_div);
320 stv0900_write_reg(i_params, R0900_P2_F22RX, m_div);
321
322 if ((i_params->errs))
323 error = STV0900_I2C_ERROR;
324 }
325 }
326
327 return error;
328}
329
330u32 stv0900_get_err_count(struct stv0900_internal *i_params, int cntr,
331 enum fe_stv0900_demod_num demod)
332{
333 u32 lsb, msb, hsb, err_val;
334 s32 err1field_hsb, err1field_msb, err1field_lsb;
335 s32 err2field_hsb, err2field_msb, err2field_lsb;
336
337 dmd_reg(err1field_hsb, F0900_P1_ERR_CNT12, F0900_P2_ERR_CNT12);
338 dmd_reg(err1field_msb, F0900_P1_ERR_CNT11, F0900_P2_ERR_CNT11);
339 dmd_reg(err1field_lsb, F0900_P1_ERR_CNT10, F0900_P2_ERR_CNT10);
340
341 dmd_reg(err2field_hsb, F0900_P1_ERR_CNT22, F0900_P2_ERR_CNT22);
342 dmd_reg(err2field_msb, F0900_P1_ERR_CNT21, F0900_P2_ERR_CNT21);
343 dmd_reg(err2field_lsb, F0900_P1_ERR_CNT20, F0900_P2_ERR_CNT20);
344
345 switch (cntr) {
346 case 0:
347 default:
348 hsb = stv0900_get_bits(i_params, err1field_hsb);
349 msb = stv0900_get_bits(i_params, err1field_msb);
350 lsb = stv0900_get_bits(i_params, err1field_lsb);
351 break;
352 case 1:
353 hsb = stv0900_get_bits(i_params, err2field_hsb);
354 msb = stv0900_get_bits(i_params, err2field_msb);
355 lsb = stv0900_get_bits(i_params, err2field_lsb);
356 break;
357 }
358
359 err_val = (hsb << 16) + (msb << 8) + (lsb);
360
361 return err_val;
362}
363
364static int stv0900_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
365{
366 struct stv0900_state *state = fe->demodulator_priv;
367 struct stv0900_internal *i_params = state->internal;
368 enum fe_stv0900_demod_num demod = state->demod;
369
370 u32 fi2c;
371
372 dmd_reg(fi2c, F0900_P1_I2CT_ON, F0900_P2_I2CT_ON);
373 if (enable)
374 stv0900_write_bits(i_params, fi2c, 1);
375
376 return 0;
377}
378
379static void stv0900_set_ts_parallel_serial(struct stv0900_internal *i_params,
380 enum fe_stv0900_clock_type path1_ts,
381 enum fe_stv0900_clock_type path2_ts)
382{
383
384 dprintk(KERN_INFO "%s\n", __func__);
385
386 if (i_params->chip_id >= 0x20) {
387 switch (path1_ts) {
388 case STV0900_PARALLEL_PUNCT_CLOCK:
389 case STV0900_DVBCI_CLOCK:
390 switch (path2_ts) {
391 case STV0900_SERIAL_PUNCT_CLOCK:
392 case STV0900_SERIAL_CONT_CLOCK:
393 default:
394 stv0900_write_reg(i_params, R0900_TSGENERAL,
395 0x00);
396 break;
397 case STV0900_PARALLEL_PUNCT_CLOCK:
398 case STV0900_DVBCI_CLOCK:
399 stv0900_write_reg(i_params, R0900_TSGENERAL,
400 0x06);
401 stv0900_write_bits(i_params,
402 F0900_P1_TSFIFO_MANSPEED, 3);
403 stv0900_write_bits(i_params,
404 F0900_P2_TSFIFO_MANSPEED, 0);
405 stv0900_write_reg(i_params,
406 R0900_P1_TSSPEED, 0x14);
407 stv0900_write_reg(i_params,
408 R0900_P2_TSSPEED, 0x28);
409 break;
410 }
411 break;
412 case STV0900_SERIAL_PUNCT_CLOCK:
413 case STV0900_SERIAL_CONT_CLOCK:
414 default:
415 switch (path2_ts) {
416 case STV0900_SERIAL_PUNCT_CLOCK:
417 case STV0900_SERIAL_CONT_CLOCK:
418 default:
419 stv0900_write_reg(i_params,
420 R0900_TSGENERAL, 0x0C);
421 break;
422 case STV0900_PARALLEL_PUNCT_CLOCK:
423 case STV0900_DVBCI_CLOCK:
424 stv0900_write_reg(i_params,
425 R0900_TSGENERAL, 0x0A);
426 dprintk(KERN_INFO "%s: 0x0a\n", __func__);
427 break;
428 }
429 break;
430 }
431 } else {
432 switch (path1_ts) {
433 case STV0900_PARALLEL_PUNCT_CLOCK:
434 case STV0900_DVBCI_CLOCK:
435 switch (path2_ts) {
436 case STV0900_SERIAL_PUNCT_CLOCK:
437 case STV0900_SERIAL_CONT_CLOCK:
438 default:
439 stv0900_write_reg(i_params, R0900_TSGENERAL1X,
440 0x10);
441 break;
442 case STV0900_PARALLEL_PUNCT_CLOCK:
443 case STV0900_DVBCI_CLOCK:
444 stv0900_write_reg(i_params, R0900_TSGENERAL1X,
445 0x16);
446 stv0900_write_bits(i_params,
447 F0900_P1_TSFIFO_MANSPEED, 3);
448 stv0900_write_bits(i_params,
449 F0900_P2_TSFIFO_MANSPEED, 0);
450 stv0900_write_reg(i_params, R0900_P1_TSSPEED,
451 0x14);
452 stv0900_write_reg(i_params, R0900_P2_TSSPEED,
453 0x28);
454 break;
455 }
456
457 break;
458 case STV0900_SERIAL_PUNCT_CLOCK:
459 case STV0900_SERIAL_CONT_CLOCK:
460 default:
461 switch (path2_ts) {
462 case STV0900_SERIAL_PUNCT_CLOCK:
463 case STV0900_SERIAL_CONT_CLOCK:
464 default:
465 stv0900_write_reg(i_params, R0900_TSGENERAL1X,
466 0x14);
467 break;
468 case STV0900_PARALLEL_PUNCT_CLOCK:
469 case STV0900_DVBCI_CLOCK:
470 stv0900_write_reg(i_params, R0900_TSGENERAL1X,
471 0x12);
472 dprintk(KERN_INFO "%s: 0x12\n", __func__);
473 break;
474 }
475
476 break;
477 }
478 }
479
480 switch (path1_ts) {
481 case STV0900_PARALLEL_PUNCT_CLOCK:
482 stv0900_write_bits(i_params, F0900_P1_TSFIFO_SERIAL, 0x00);
483 stv0900_write_bits(i_params, F0900_P1_TSFIFO_DVBCI, 0x00);
484 break;
485 case STV0900_DVBCI_CLOCK:
486 stv0900_write_bits(i_params, F0900_P1_TSFIFO_SERIAL, 0x00);
487 stv0900_write_bits(i_params, F0900_P1_TSFIFO_DVBCI, 0x01);
488 break;
489 case STV0900_SERIAL_PUNCT_CLOCK:
490 stv0900_write_bits(i_params, F0900_P1_TSFIFO_SERIAL, 0x01);
491 stv0900_write_bits(i_params, F0900_P1_TSFIFO_DVBCI, 0x00);
492 break;
493 case STV0900_SERIAL_CONT_CLOCK:
494 stv0900_write_bits(i_params, F0900_P1_TSFIFO_SERIAL, 0x01);
495 stv0900_write_bits(i_params, F0900_P1_TSFIFO_DVBCI, 0x01);
496 break;
497 default:
498 break;
499 }
500
501 switch (path2_ts) {
502 case STV0900_PARALLEL_PUNCT_CLOCK:
503 stv0900_write_bits(i_params, F0900_P2_TSFIFO_SERIAL, 0x00);
504 stv0900_write_bits(i_params, F0900_P2_TSFIFO_DVBCI, 0x00);
505 break;
506 case STV0900_DVBCI_CLOCK:
507 stv0900_write_bits(i_params, F0900_P2_TSFIFO_SERIAL, 0x00);
508 stv0900_write_bits(i_params, F0900_P2_TSFIFO_DVBCI, 0x01);
509 break;
510 case STV0900_SERIAL_PUNCT_CLOCK:
511 stv0900_write_bits(i_params, F0900_P2_TSFIFO_SERIAL, 0x01);
512 stv0900_write_bits(i_params, F0900_P2_TSFIFO_DVBCI, 0x00);
513 break;
514 case STV0900_SERIAL_CONT_CLOCK:
515 stv0900_write_bits(i_params, F0900_P2_TSFIFO_SERIAL, 0x01);
516 stv0900_write_bits(i_params, F0900_P2_TSFIFO_DVBCI, 0x01);
517 break;
518 default:
519 break;
520 }
521
522 stv0900_write_bits(i_params, F0900_P2_RST_HWARE, 1);
523 stv0900_write_bits(i_params, F0900_P2_RST_HWARE, 0);
524 stv0900_write_bits(i_params, F0900_P1_RST_HWARE, 1);
525 stv0900_write_bits(i_params, F0900_P1_RST_HWARE, 0);
526}
527
528void stv0900_set_tuner(struct dvb_frontend *fe, u32 frequency,
529 u32 bandwidth)
530{
531 struct dvb_frontend_ops *frontend_ops = NULL;
532 struct dvb_tuner_ops *tuner_ops = NULL;
533
534 if (&fe->ops)
535 frontend_ops = &fe->ops;
536
537 if (&frontend_ops->tuner_ops)
538 tuner_ops = &frontend_ops->tuner_ops;
539
540 if (tuner_ops->set_frequency) {
541 if ((tuner_ops->set_frequency(fe, frequency)) < 0)
542 dprintk("%s: Invalid parameter\n", __func__);
543 else
544 dprintk("%s: Frequency=%d\n", __func__, frequency);
545
546 }
547
548 if (tuner_ops->set_bandwidth) {
549 if ((tuner_ops->set_bandwidth(fe, bandwidth)) < 0)
550 dprintk("%s: Invalid parameter\n", __func__);
551 else
552 dprintk("%s: Bandwidth=%d\n", __func__, bandwidth);
553
554 }
555}
556
557void stv0900_set_bandwidth(struct dvb_frontend *fe, u32 bandwidth)
558{
559 struct dvb_frontend_ops *frontend_ops = NULL;
560 struct dvb_tuner_ops *tuner_ops = NULL;
561
562 if (&fe->ops)
563 frontend_ops = &fe->ops;
564
565 if (&frontend_ops->tuner_ops)
566 tuner_ops = &frontend_ops->tuner_ops;
567
568 if (tuner_ops->set_bandwidth) {
569 if ((tuner_ops->set_bandwidth(fe, bandwidth)) < 0)
570 dprintk("%s: Invalid parameter\n", __func__);
571 else
572 dprintk("%s: Bandwidth=%d\n", __func__, bandwidth);
573
574 }
575}
576
577static s32 stv0900_get_rf_level(struct stv0900_internal *i_params,
578 const struct stv0900_table *lookup,
579 enum fe_stv0900_demod_num demod)
580{
581 s32 agc_gain = 0,
582 imin,
583 imax,
584 i,
585 rf_lvl = 0;
586
587 dprintk(KERN_INFO "%s\n", __func__);
588
589 if ((lookup != NULL) && lookup->size) {
590 switch (demod) {
591 case STV0900_DEMOD_1:
592 default:
593 agc_gain = MAKEWORD(stv0900_get_bits(i_params, F0900_P1_AGCIQ_VALUE1),
594 stv0900_get_bits(i_params, F0900_P1_AGCIQ_VALUE0));
595 break;
596 case STV0900_DEMOD_2:
597 agc_gain = MAKEWORD(stv0900_get_bits(i_params, F0900_P2_AGCIQ_VALUE1),
598 stv0900_get_bits(i_params, F0900_P2_AGCIQ_VALUE0));
599 break;
600 }
601
602 imin = 0;
603 imax = lookup->size - 1;
604 if (INRANGE(lookup->table[imin].regval, agc_gain, lookup->table[imax].regval)) {
605 while ((imax - imin) > 1) {
606 i = (imax + imin) >> 1;
607
608 if (INRANGE(lookup->table[imin].regval, agc_gain, lookup->table[i].regval))
609 imax = i;
610 else
611 imin = i;
612 }
613
614 rf_lvl = (((s32)agc_gain - lookup->table[imin].regval)
615 * (lookup->table[imax].realval - lookup->table[imin].realval)
616 / (lookup->table[imax].regval - lookup->table[imin].regval))
617 + lookup->table[imin].realval;
618 } else if (agc_gain > lookup->table[0].regval)
619 rf_lvl = 5;
620 else if (agc_gain < lookup->table[lookup->size-1].regval)
621 rf_lvl = -100;
622
623 }
624
625 dprintk(KERN_INFO "%s: RFLevel = %d\n", __func__, rf_lvl);
626
627 return rf_lvl;
628}
629
630static int stv0900_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
631{
632 struct stv0900_state *state = fe->demodulator_priv;
633 struct stv0900_internal *internal = state->internal;
634 s32 rflevel = stv0900_get_rf_level(internal, &stv0900_rf,
635 state->demod);
636
637 *strength = (rflevel + 100) * (16383 / 105);
638
639 return 0;
640}
641
642
643static s32 stv0900_carr_get_quality(struct dvb_frontend *fe,
644 const struct stv0900_table *lookup)
645{
646 struct stv0900_state *state = fe->demodulator_priv;
647 struct stv0900_internal *i_params = state->internal;
648 enum fe_stv0900_demod_num demod = state->demod;
649
650 s32 c_n = -100,
651 regval, imin, imax,
652 i,
653 lock_flag_field,
654 noise_field1,
655 noise_field0;
656
657 dprintk(KERN_INFO "%s\n", __func__);
658
659 dmd_reg(lock_flag_field, F0900_P1_LOCK_DEFINITIF,
660 F0900_P2_LOCK_DEFINITIF);
661 if (stv0900_get_standard(fe, demod) == STV0900_DVBS2_STANDARD) {
662 dmd_reg(noise_field1, F0900_P1_NOSPLHT_NORMED1,
663 F0900_P2_NOSPLHT_NORMED1);
664 dmd_reg(noise_field0, F0900_P1_NOSPLHT_NORMED0,
665 F0900_P2_NOSPLHT_NORMED0);
666 } else {
667 dmd_reg(noise_field1, F0900_P1_NOSDATAT_NORMED1,
668 F0900_P2_NOSDATAT_NORMED1);
669 dmd_reg(noise_field0, F0900_P1_NOSDATAT_NORMED0,
670 F0900_P2_NOSDATAT_NORMED0);
671 }
672
673 if (stv0900_get_bits(i_params, lock_flag_field)) {
674 if ((lookup != NULL) && lookup->size) {
675 regval = 0;
676 msleep(5);
677 for (i = 0; i < 16; i++) {
678 regval += MAKEWORD(stv0900_get_bits(i_params,
679 noise_field1),
680 stv0900_get_bits(i_params,
681 noise_field0));
682 msleep(1);
683 }
684
685 regval /= 16;
686 imin = 0;
687 imax = lookup->size - 1;
688 if (INRANGE(lookup->table[imin].regval,
689 regval,
690 lookup->table[imax].regval)) {
691 while ((imax - imin) > 1) {
692 i = (imax + imin) >> 1;
693 if (INRANGE(lookup->table[imin].regval,
694 regval,
695 lookup->table[i].regval))
696 imax = i;
697 else
698 imin = i;
699 }
700
701 c_n = ((regval - lookup->table[imin].regval)
702 * (lookup->table[imax].realval
703 - lookup->table[imin].realval)
704 / (lookup->table[imax].regval
705 - lookup->table[imin].regval))
706 + lookup->table[imin].realval;
707 } else if (regval < lookup->table[imin].regval)
708 c_n = 1000;
709 }
710 }
711
712 return c_n;
713}
714
715static int stv0900_read_snr(struct dvb_frontend *fe, u16 *snr)
716{
717 *snr = stv0900_carr_get_quality(fe,
718 (const struct stv0900_table *)&stv0900_s2_cn);
719 *snr += 30;
720 *snr *= (16383 / 1030);
721
722 return 0;
723}
724
725static u32 stv0900_get_ber(struct stv0900_internal *i_params,
726 enum fe_stv0900_demod_num demod)
727{
728 u32 ber = 10000000, i;
729 s32 dmd_state_reg;
730 s32 demod_state;
731 s32 vstatus_reg;
732 s32 prvit_field;
733 s32 pdel_status_reg;
734 s32 pdel_lock_field;
735
736 dmd_reg(dmd_state_reg, F0900_P1_HEADER_MODE, F0900_P2_HEADER_MODE);
737 dmd_reg(vstatus_reg, R0900_P1_VSTATUSVIT, R0900_P2_VSTATUSVIT);
738 dmd_reg(prvit_field, F0900_P1_PRFVIT, F0900_P2_PRFVIT);
739 dmd_reg(pdel_status_reg, R0900_P1_PDELSTATUS1, R0900_P2_PDELSTATUS1);
740 dmd_reg(pdel_lock_field, F0900_P1_PKTDELIN_LOCK,
741 F0900_P2_PKTDELIN_LOCK);
742
743 demod_state = stv0900_get_bits(i_params, dmd_state_reg);
744
745 switch (demod_state) {
746 case STV0900_SEARCH:
747 case STV0900_PLH_DETECTED:
748 default:
749 ber = 10000000;
750 break;
751 case STV0900_DVBS_FOUND:
752 ber = 0;
753 for (i = 0; i < 5; i++) {
754 msleep(5);
755 ber += stv0900_get_err_count(i_params, 0, demod);
756 }
757
758 ber /= 5;
759 if (stv0900_get_bits(i_params, prvit_field)) {
760 ber *= 9766;
761 ber = ber >> 13;
762 }
763
764 break;
765 case STV0900_DVBS2_FOUND:
766 ber = 0;
767 for (i = 0; i < 5; i++) {
768 msleep(5);
769 ber += stv0900_get_err_count(i_params, 0, demod);
770 }
771
772 ber /= 5;
773 if (stv0900_get_bits(i_params, pdel_lock_field)) {
774 ber *= 9766;
775 ber = ber >> 13;
776 }
777
778 break;
779 }
780
781 return ber;
782}
783
784static int stv0900_read_ber(struct dvb_frontend *fe, u32 *ber)
785{
786 struct stv0900_state *state = fe->demodulator_priv;
787 struct stv0900_internal *internal = state->internal;
788
789 *ber = stv0900_get_ber(internal, state->demod);
790
791 return 0;
792}
793
794int stv0900_get_demod_lock(struct stv0900_internal *i_params,
795 enum fe_stv0900_demod_num demod, s32 time_out)
796{
797 s32 timer = 0,
798 lock = 0,
799 header_field,
800 lock_field;
801
802 enum fe_stv0900_search_state dmd_state;
803
804 dmd_reg(header_field, F0900_P1_HEADER_MODE, F0900_P2_HEADER_MODE);
805 dmd_reg(lock_field, F0900_P1_LOCK_DEFINITIF, F0900_P2_LOCK_DEFINITIF);
806 while ((timer < time_out) && (lock == 0)) {
807 dmd_state = stv0900_get_bits(i_params, header_field);
808 dprintk("Demod State = %d\n", dmd_state);
809 switch (dmd_state) {
810 case STV0900_SEARCH:
811 case STV0900_PLH_DETECTED:
812 default:
813 lock = 0;
814 break;
815 case STV0900_DVBS2_FOUND:
816 case STV0900_DVBS_FOUND:
817 lock = stv0900_get_bits(i_params, lock_field);
818 break;
819 }
820
821 if (lock == 0)
822 msleep(10);
823
824 timer += 10;
825 }
826
827 if (lock)
828 dprintk("DEMOD LOCK OK\n");
829 else
830 dprintk("DEMOD LOCK FAIL\n");
831
832 return lock;
833}
834
835void stv0900_stop_all_s2_modcod(struct stv0900_internal *i_params,
836 enum fe_stv0900_demod_num demod)
837{
838 s32 regflist,
839 i;
840
841 dprintk(KERN_INFO "%s\n", __func__);
842
843 dmd_reg(regflist, R0900_P1_MODCODLST0, R0900_P2_MODCODLST0);
844
845 for (i = 0; i < 16; i++)
846 stv0900_write_reg(i_params, regflist + i, 0xff);
847}
848
849void stv0900_activate_s2_modcode(struct stv0900_internal *i_params,
850 enum fe_stv0900_demod_num demod)
851{
852 u32 matype,
853 mod_code,
854 fmod,
855 reg_index,
856 field_index;
857
858 dprintk(KERN_INFO "%s\n", __func__);
859
860 if (i_params->chip_id <= 0x11) {
861 msleep(5);
862
863 switch (demod) {
864 case STV0900_DEMOD_1:
865 default:
866 mod_code = stv0900_read_reg(i_params,
867 R0900_P1_PLHMODCOD);
868 matype = mod_code & 0x3;
869 mod_code = (mod_code & 0x7f) >> 2;
870
871 reg_index = R0900_P1_MODCODLSTF - mod_code / 2;
872 field_index = mod_code % 2;
873 break;
874 case STV0900_DEMOD_2:
875 mod_code = stv0900_read_reg(i_params,
876 R0900_P2_PLHMODCOD);
877 matype = mod_code & 0x3;
878 mod_code = (mod_code & 0x7f) >> 2;
879
880 reg_index = R0900_P2_MODCODLSTF - mod_code / 2;
881 field_index = mod_code % 2;
882 break;
883 }
884
885
886 switch (matype) {
887 case 0:
888 default:
889 fmod = 14;
890 break;
891 case 1:
892 fmod = 13;
893 break;
894 case 2:
895 fmod = 11;
896 break;
897 case 3:
898 fmod = 7;
899 break;
900 }
901
902 if ((INRANGE(STV0900_QPSK_12, mod_code, STV0900_8PSK_910))
903 && (matype <= 1)) {
904 if (field_index == 0)
905 stv0900_write_reg(i_params, reg_index,
906 0xf0 | fmod);
907 else
908 stv0900_write_reg(i_params, reg_index,
909 (fmod << 4) | 0xf);
910 }
911 } else if (i_params->chip_id >= 0x12) {
912 switch (demod) {
913 case STV0900_DEMOD_1:
914 default:
915 for (reg_index = 0; reg_index < 7; reg_index++)
916 stv0900_write_reg(i_params, R0900_P1_MODCODLST0 + reg_index, 0xff);
917
918 stv0900_write_reg(i_params, R0900_P1_MODCODLSTE, 0xff);
919 stv0900_write_reg(i_params, R0900_P1_MODCODLSTF, 0xcf);
920 for (reg_index = 0; reg_index < 8; reg_index++)
921 stv0900_write_reg(i_params, R0900_P1_MODCODLST7 + reg_index, 0xcc);
922
923 break;
924 case STV0900_DEMOD_2:
925 for (reg_index = 0; reg_index < 7; reg_index++)
926 stv0900_write_reg(i_params, R0900_P2_MODCODLST0 + reg_index, 0xff);
927
928 stv0900_write_reg(i_params, R0900_P2_MODCODLSTE, 0xff);
929 stv0900_write_reg(i_params, R0900_P2_MODCODLSTF, 0xcf);
930 for (reg_index = 0; reg_index < 8; reg_index++)
931 stv0900_write_reg(i_params, R0900_P2_MODCODLST7 + reg_index, 0xcc);
932
933 break;
934 }
935
936 }
937}
938
939void stv0900_activate_s2_modcode_single(struct stv0900_internal *i_params,
940 enum fe_stv0900_demod_num demod)
941{
942 u32 reg_index;
943
944 dprintk(KERN_INFO "%s\n", __func__);
945
946 switch (demod) {
947 case STV0900_DEMOD_1:
948 default:
949 stv0900_write_reg(i_params, R0900_P1_MODCODLST0, 0xff);
950 stv0900_write_reg(i_params, R0900_P1_MODCODLST1, 0xf0);
951 stv0900_write_reg(i_params, R0900_P1_MODCODLSTF, 0x0f);
952 for (reg_index = 0; reg_index < 13; reg_index++)
953 stv0900_write_reg(i_params,
954 R0900_P1_MODCODLST2 + reg_index, 0);
955
956 break;
957 case STV0900_DEMOD_2:
958 stv0900_write_reg(i_params, R0900_P2_MODCODLST0, 0xff);
959 stv0900_write_reg(i_params, R0900_P2_MODCODLST1, 0xf0);
960 stv0900_write_reg(i_params, R0900_P2_MODCODLSTF, 0x0f);
961 for (reg_index = 0; reg_index < 13; reg_index++)
962 stv0900_write_reg(i_params,
963 R0900_P2_MODCODLST2 + reg_index, 0);
964
965 break;
966 }
967}
968
969static enum dvbfe_algo stv0900_frontend_algo(struct dvb_frontend *fe)
970{
971 return DVBFE_ALGO_CUSTOM;
972}
973
974static int stb0900_set_property(struct dvb_frontend *fe,
975 struct dtv_property *tvp)
976{
977 dprintk(KERN_INFO "%s(..)\n", __func__);
978
979 return 0;
980}
981
982static int stb0900_get_property(struct dvb_frontend *fe,
983 struct dtv_property *tvp)
984{
985 dprintk(KERN_INFO "%s(..)\n", __func__);
986
987 return 0;
988}
989
990void stv0900_start_search(struct stv0900_internal *i_params,
991 enum fe_stv0900_demod_num demod)
992{
993
994 switch (demod) {
995 case STV0900_DEMOD_1:
996 default:
997 stv0900_write_bits(i_params, F0900_P1_I2C_DEMOD_MODE, 0x1f);
998
999 if (i_params->chip_id == 0x10)
1000 stv0900_write_reg(i_params, R0900_P1_CORRELEXP, 0xaa);
1001
1002 if (i_params->chip_id < 0x20)
1003 stv0900_write_reg(i_params, R0900_P1_CARHDR, 0x55);
1004
1005 if (i_params->dmd1_symbol_rate <= 5000000) {
1006 stv0900_write_reg(i_params, R0900_P1_CARCFG, 0x44);
1007 stv0900_write_reg(i_params, R0900_P1_CFRUP1, 0x0f);
1008 stv0900_write_reg(i_params, R0900_P1_CFRUP0, 0xff);
1009 stv0900_write_reg(i_params, R0900_P1_CFRLOW1, 0xf0);
1010 stv0900_write_reg(i_params, R0900_P1_CFRLOW0, 0x00);
1011 stv0900_write_reg(i_params, R0900_P1_RTCS2, 0x68);
1012 } else {
1013 stv0900_write_reg(i_params, R0900_P1_CARCFG, 0xc4);
1014 stv0900_write_reg(i_params, R0900_P1_RTCS2, 0x44);
1015 }
1016
1017 stv0900_write_reg(i_params, R0900_P1_CFRINIT1, 0);
1018 stv0900_write_reg(i_params, R0900_P1_CFRINIT0, 0);
1019
1020 if (i_params->chip_id >= 0x20) {
1021 stv0900_write_reg(i_params, R0900_P1_EQUALCFG, 0x41);
1022 stv0900_write_reg(i_params, R0900_P1_FFECFG, 0x41);
1023
1024 if ((i_params->dmd1_srch_standard == STV0900_SEARCH_DVBS1) || (i_params->dmd1_srch_standard == STV0900_SEARCH_DSS) || (i_params->dmd1_srch_standard == STV0900_AUTO_SEARCH)) {
1025 stv0900_write_reg(i_params, R0900_P1_VITSCALE, 0x82);
1026 stv0900_write_reg(i_params, R0900_P1_VAVSRVIT, 0x0);
1027 }
1028 }
1029
1030 stv0900_write_reg(i_params, R0900_P1_SFRSTEP, 0x00);
1031 stv0900_write_reg(i_params, R0900_P1_TMGTHRISE, 0xe0);
1032 stv0900_write_reg(i_params, R0900_P1_TMGTHFALL, 0xc0);
1033 stv0900_write_bits(i_params, F0900_P1_SCAN_ENABLE, 0);
1034 stv0900_write_bits(i_params, F0900_P1_CFR_AUTOSCAN, 0);
1035 stv0900_write_bits(i_params, F0900_P1_S1S2_SEQUENTIAL, 0);
1036 stv0900_write_reg(i_params, R0900_P1_RTC, 0x88);
1037 if (i_params->chip_id >= 0x20) {
1038 if (i_params->dmd1_symbol_rate < 2000000) {
1039 stv0900_write_reg(i_params, R0900_P1_CARFREQ, 0x39);
1040 stv0900_write_reg(i_params, R0900_P1_CARHDR, 0x40);
1041 }
1042
1043 if (i_params->dmd1_symbol_rate < 10000000) {
1044 stv0900_write_reg(i_params, R0900_P1_CARFREQ, 0x4c);
1045 stv0900_write_reg(i_params, R0900_P1_CARHDR, 0x20);
1046 } else {
1047 stv0900_write_reg(i_params, R0900_P1_CARFREQ, 0x4b);
1048 stv0900_write_reg(i_params, R0900_P1_CARHDR, 0x20);
1049 }
1050
1051 } else {
1052 if (i_params->dmd1_symbol_rate < 10000000)
1053 stv0900_write_reg(i_params, R0900_P1_CARFREQ, 0xef);
1054 else
1055 stv0900_write_reg(i_params, R0900_P1_CARFREQ, 0xed);
1056 }
1057
1058 switch (i_params->dmd1_srch_algo) {
1059 case STV0900_WARM_START:
1060 stv0900_write_reg(i_params, R0900_P1_DMDISTATE, 0x1f);
1061 stv0900_write_reg(i_params, R0900_P1_DMDISTATE, 0x18);
1062 break;
1063 case STV0900_COLD_START:
1064 stv0900_write_reg(i_params, R0900_P1_DMDISTATE, 0x1f);
1065 stv0900_write_reg(i_params, R0900_P1_DMDISTATE, 0x15);
1066 break;
1067 default:
1068 break;
1069 }
1070
1071 break;
1072 case STV0900_DEMOD_2:
1073 stv0900_write_bits(i_params, F0900_P2_I2C_DEMOD_MODE, 0x1f);
1074 if (i_params->chip_id == 0x10)
1075 stv0900_write_reg(i_params, R0900_P2_CORRELEXP, 0xaa);
1076
1077 if (i_params->chip_id < 0x20)
1078 stv0900_write_reg(i_params, R0900_P2_CARHDR, 0x55);
1079
1080 if (i_params->dmd2_symbol_rate <= 5000000) {
1081 stv0900_write_reg(i_params, R0900_P2_CARCFG, 0x44);
1082 stv0900_write_reg(i_params, R0900_P2_CFRUP1, 0x0f);
1083 stv0900_write_reg(i_params, R0900_P2_CFRUP0, 0xff);
1084 stv0900_write_reg(i_params, R0900_P2_CFRLOW1, 0xf0);
1085 stv0900_write_reg(i_params, R0900_P2_CFRLOW0, 0x00);
1086 stv0900_write_reg(i_params, R0900_P2_RTCS2, 0x68);
1087 } else {
1088 stv0900_write_reg(i_params, R0900_P2_CARCFG, 0xc4);
1089 stv0900_write_reg(i_params, R0900_P2_RTCS2, 0x44);
1090 }
1091
1092 stv0900_write_reg(i_params, R0900_P2_CFRINIT1, 0);
1093 stv0900_write_reg(i_params, R0900_P2_CFRINIT0, 0);
1094
1095 if (i_params->chip_id >= 0x20) {
1096 stv0900_write_reg(i_params, R0900_P2_EQUALCFG, 0x41);
1097 stv0900_write_reg(i_params, R0900_P2_FFECFG, 0x41);
1098 if ((i_params->dmd2_srch_stndrd == STV0900_SEARCH_DVBS1) || (i_params->dmd2_srch_stndrd == STV0900_SEARCH_DSS) || (i_params->dmd2_srch_stndrd == STV0900_AUTO_SEARCH)) {
1099 stv0900_write_reg(i_params, R0900_P2_VITSCALE, 0x82);
1100 stv0900_write_reg(i_params, R0900_P2_VAVSRVIT, 0x0);
1101 }
1102 }
1103
1104 stv0900_write_reg(i_params, R0900_P2_SFRSTEP, 0x00);
1105 stv0900_write_reg(i_params, R0900_P2_TMGTHRISE, 0xe0);
1106 stv0900_write_reg(i_params, R0900_P2_TMGTHFALL, 0xc0);
1107 stv0900_write_bits(i_params, F0900_P2_SCAN_ENABLE, 0);
1108 stv0900_write_bits(i_params, F0900_P2_CFR_AUTOSCAN, 0);
1109 stv0900_write_bits(i_params, F0900_P2_S1S2_SEQUENTIAL, 0);
1110 stv0900_write_reg(i_params, R0900_P2_RTC, 0x88);
1111 if (i_params->chip_id >= 0x20) {
1112 if (i_params->dmd2_symbol_rate < 2000000) {
1113 stv0900_write_reg(i_params, R0900_P2_CARFREQ, 0x39);
1114 stv0900_write_reg(i_params, R0900_P2_CARHDR, 0x40);
1115 }
1116
1117 if (i_params->dmd2_symbol_rate < 10000000) {
1118 stv0900_write_reg(i_params, R0900_P2_CARFREQ, 0x4c);
1119 stv0900_write_reg(i_params, R0900_P2_CARHDR, 0x20);
1120 } else {
1121 stv0900_write_reg(i_params, R0900_P2_CARFREQ, 0x4b);
1122 stv0900_write_reg(i_params, R0900_P2_CARHDR, 0x20);
1123 }
1124
1125 } else {
1126 if (i_params->dmd2_symbol_rate < 10000000)
1127 stv0900_write_reg(i_params, R0900_P2_CARFREQ, 0xef);
1128 else
1129 stv0900_write_reg(i_params, R0900_P2_CARFREQ, 0xed);
1130 }
1131
1132 switch (i_params->dmd2_srch_algo) {
1133 case STV0900_WARM_START:
1134 stv0900_write_reg(i_params, R0900_P2_DMDISTATE, 0x1f);
1135 stv0900_write_reg(i_params, R0900_P2_DMDISTATE, 0x18);
1136 break;
1137 case STV0900_COLD_START:
1138 stv0900_write_reg(i_params, R0900_P2_DMDISTATE, 0x1f);
1139 stv0900_write_reg(i_params, R0900_P2_DMDISTATE, 0x15);
1140 break;
1141 default:
1142 break;
1143 }
1144
1145 break;
1146 }
1147}
1148
1149u8 stv0900_get_optim_carr_loop(s32 srate, enum fe_stv0900_modcode modcode,
1150 s32 pilot, u8 chip_id)
1151{
1152 u8 aclc_value = 0x29;
1153 s32 i;
1154 const struct stv0900_car_loop_optim *car_loop_s2;
1155
1156 dprintk(KERN_INFO "%s\n", __func__);
1157
1158 if (chip_id <= 0x12)
1159 car_loop_s2 = FE_STV0900_S2CarLoop;
1160 else if (chip_id == 0x20)
1161 car_loop_s2 = FE_STV0900_S2CarLoopCut20;
1162 else
1163 car_loop_s2 = FE_STV0900_S2CarLoop;
1164
1165 if (modcode < STV0900_QPSK_12) {
1166 i = 0;
1167 while ((i < 3) && (modcode != FE_STV0900_S2LowQPCarLoopCut20[i].modcode))
1168 i++;
1169
1170 if (i >= 3)
1171 i = 2;
1172 } else {
1173 i = 0;
1174 while ((i < 14) && (modcode != car_loop_s2[i].modcode))
1175 i++;
1176
1177 if (i >= 14) {
1178 i = 0;
1179 while ((i < 11) && (modcode != FE_STV0900_S2APSKCarLoopCut20[i].modcode))
1180 i++;
1181
1182 if (i >= 11)
1183 i = 10;
1184 }
1185 }
1186
1187 if (modcode <= STV0900_QPSK_25) {
1188 if (pilot) {
1189 if (srate <= 3000000)
1190 aclc_value = FE_STV0900_S2LowQPCarLoopCut20[i].car_loop_pilots_on_2;
1191 else if (srate <= 7000000)
1192 aclc_value = FE_STV0900_S2LowQPCarLoopCut20[i].car_loop_pilots_on_5;
1193 else if (srate <= 15000000)
1194 aclc_value = FE_STV0900_S2LowQPCarLoopCut20[i].car_loop_pilots_on_10;
1195 else if (srate <= 25000000)
1196 aclc_value = FE_STV0900_S2LowQPCarLoopCut20[i].car_loop_pilots_on_20;
1197 else
1198 aclc_value = FE_STV0900_S2LowQPCarLoopCut20[i].car_loop_pilots_on_30;
1199 } else {
1200 if (srate <= 3000000)
1201 aclc_value = FE_STV0900_S2LowQPCarLoopCut20[i].car_loop_pilots_off_2;
1202 else if (srate <= 7000000)
1203 aclc_value = FE_STV0900_S2LowQPCarLoopCut20[i].car_loop_pilots_off_5;
1204 else if (srate <= 15000000)
1205 aclc_value = FE_STV0900_S2LowQPCarLoopCut20[i].car_loop_pilots_off_10;
1206 else if (srate <= 25000000)
1207 aclc_value = FE_STV0900_S2LowQPCarLoopCut20[i].car_loop_pilots_off_20;
1208 else
1209 aclc_value = FE_STV0900_S2LowQPCarLoopCut20[i].car_loop_pilots_off_30;
1210 }
1211
1212 } else if (modcode <= STV0900_8PSK_910) {
1213 if (pilot) {
1214 if (srate <= 3000000)
1215 aclc_value = car_loop_s2[i].car_loop_pilots_on_2;
1216 else if (srate <= 7000000)
1217 aclc_value = car_loop_s2[i].car_loop_pilots_on_5;
1218 else if (srate <= 15000000)
1219 aclc_value = car_loop_s2[i].car_loop_pilots_on_10;
1220 else if (srate <= 25000000)
1221 aclc_value = car_loop_s2[i].car_loop_pilots_on_20;
1222 else
1223 aclc_value = car_loop_s2[i].car_loop_pilots_on_30;
1224 } else {
1225 if (srate <= 3000000)
1226 aclc_value = car_loop_s2[i].car_loop_pilots_off_2;
1227 else if (srate <= 7000000)
1228 aclc_value = car_loop_s2[i].car_loop_pilots_off_5;
1229 else if (srate <= 15000000)
1230 aclc_value = car_loop_s2[i].car_loop_pilots_off_10;
1231 else if (srate <= 25000000)
1232 aclc_value = car_loop_s2[i].car_loop_pilots_off_20;
1233 else
1234 aclc_value = car_loop_s2[i].car_loop_pilots_off_30;
1235 }
1236
1237 } else {
1238 if (srate <= 3000000)
1239 aclc_value = FE_STV0900_S2APSKCarLoopCut20[i].car_loop_pilots_on_2;
1240 else if (srate <= 7000000)
1241 aclc_value = FE_STV0900_S2APSKCarLoopCut20[i].car_loop_pilots_on_5;
1242 else if (srate <= 15000000)
1243 aclc_value = FE_STV0900_S2APSKCarLoopCut20[i].car_loop_pilots_on_10;
1244 else if (srate <= 25000000)
1245 aclc_value = FE_STV0900_S2APSKCarLoopCut20[i].car_loop_pilots_on_20;
1246 else
1247 aclc_value = FE_STV0900_S2APSKCarLoopCut20[i].car_loop_pilots_on_30;
1248 }
1249
1250 return aclc_value;
1251}
1252
1253u8 stv0900_get_optim_short_carr_loop(s32 srate, enum fe_stv0900_modulation modulation, u8 chip_id)
1254{
1255 s32 mod_index = 0;
1256
1257 u8 aclc_value = 0x0b;
1258
1259 dprintk(KERN_INFO "%s\n", __func__);
1260
1261 switch (modulation) {
1262 case STV0900_QPSK:
1263 default:
1264 mod_index = 0;
1265 break;
1266 case STV0900_8PSK:
1267 mod_index = 1;
1268 break;
1269 case STV0900_16APSK:
1270 mod_index = 2;
1271 break;
1272 case STV0900_32APSK:
1273 mod_index = 3;
1274 break;
1275 }
1276
1277 switch (chip_id) {
1278 case 0x20:
1279 if (srate <= 3000000)
1280 aclc_value = FE_STV0900_S2ShortCarLoop[mod_index].car_loop_cut20_2;
1281 else if (srate <= 7000000)
1282 aclc_value = FE_STV0900_S2ShortCarLoop[mod_index].car_loop_cut20_5;
1283 else if (srate <= 15000000)
1284 aclc_value = FE_STV0900_S2ShortCarLoop[mod_index].car_loop_cut20_10;
1285 else if (srate <= 25000000)
1286 aclc_value = FE_STV0900_S2ShortCarLoop[mod_index].car_loop_cut20_20;
1287 else
1288 aclc_value = FE_STV0900_S2ShortCarLoop[mod_index].car_loop_cut20_30;
1289
1290 break;
1291 case 0x12:
1292 default:
1293 if (srate <= 3000000)
1294 aclc_value = FE_STV0900_S2ShortCarLoop[mod_index].car_loop_cut12_2;
1295 else if (srate <= 7000000)
1296 aclc_value = FE_STV0900_S2ShortCarLoop[mod_index].car_loop_cut12_5;
1297 else if (srate <= 15000000)
1298 aclc_value = FE_STV0900_S2ShortCarLoop[mod_index].car_loop_cut12_10;
1299 else if (srate <= 25000000)
1300 aclc_value = FE_STV0900_S2ShortCarLoop[mod_index].car_loop_cut12_20;
1301 else
1302 aclc_value = FE_STV0900_S2ShortCarLoop[mod_index].car_loop_cut12_30;
1303
1304 break;
1305 }
1306
1307 return aclc_value;
1308}
1309
1310static enum fe_stv0900_error stv0900_st_dvbs2_single(struct stv0900_internal *i_params,
1311 enum fe_stv0900_demod_mode LDPC_Mode,
1312 enum fe_stv0900_demod_num demod)
1313{
1314 enum fe_stv0900_error error = STV0900_NO_ERROR;
1315
1316 dprintk(KERN_INFO "%s\n", __func__);
1317
1318 switch (LDPC_Mode) {
1319 case STV0900_DUAL:
1320 default:
1321 if ((i_params->demod_mode != STV0900_DUAL)
1322 || (stv0900_get_bits(i_params, F0900_DDEMOD) != 1)) {
1323 stv0900_write_reg(i_params, R0900_GENCFG, 0x1d);
1324
1325 i_params->demod_mode = STV0900_DUAL;
1326
1327 stv0900_write_bits(i_params, F0900_FRESFEC, 1);
1328 stv0900_write_bits(i_params, F0900_FRESFEC, 0);
1329 }
1330
1331 break;
1332 case STV0900_SINGLE:
1333 if (demod == STV0900_DEMOD_2)
1334 stv0900_write_reg(i_params, R0900_GENCFG, 0x06);
1335 else
1336 stv0900_write_reg(i_params, R0900_GENCFG, 0x04);
1337
1338 i_params->demod_mode = STV0900_SINGLE;
1339
1340 stv0900_write_bits(i_params, F0900_FRESFEC, 1);
1341 stv0900_write_bits(i_params, F0900_FRESFEC, 0);
1342 stv0900_write_bits(i_params, F0900_P1_ALGOSWRST, 1);
1343 stv0900_write_bits(i_params, F0900_P1_ALGOSWRST, 0);
1344 stv0900_write_bits(i_params, F0900_P2_ALGOSWRST, 1);
1345 stv0900_write_bits(i_params, F0900_P2_ALGOSWRST, 0);
1346 break;
1347 }
1348
1349 return error;
1350}
1351
1352static enum fe_stv0900_error stv0900_init_internal(struct dvb_frontend *fe,
1353 struct stv0900_init_params *p_init)
1354{
1355 struct stv0900_state *state = fe->demodulator_priv;
1356 enum fe_stv0900_error error = STV0900_NO_ERROR;
1357 enum fe_stv0900_error demodError = STV0900_NO_ERROR;
1358 int selosci;
1359
1360 struct stv0900_inode *temp_int = find_inode(state->i2c_adap,
1361 state->config->demod_address);
1362
1363 dprintk(KERN_INFO "%s\n", __func__);
1364
1365 if (temp_int != NULL) {
1366 state->internal = temp_int->internal;
1367 (state->internal->dmds_used)++;
1368 dprintk(KERN_INFO "%s: Find Internal Structure!\n", __func__);
1369 return STV0900_NO_ERROR;
1370 } else {
1371 state->internal = kmalloc(sizeof(struct stv0900_internal), GFP_KERNEL);
1372 temp_int = append_internal(state->internal);
1373 state->internal->dmds_used = 1;
1374 state->internal->i2c_adap = state->i2c_adap;
1375 state->internal->i2c_addr = state->config->demod_address;
1376 state->internal->clkmode = state->config->clkmode;
1377 state->internal->errs = STV0900_NO_ERROR;
1378 dprintk(KERN_INFO "%s: Create New Internal Structure!\n", __func__);
1379 }
1380
1381 if (state->internal != NULL) {
1382 demodError = stv0900_initialize(state->internal);
1383 if (demodError == STV0900_NO_ERROR) {
1384 error = STV0900_NO_ERROR;
1385 } else {
1386 if (demodError == STV0900_INVALID_HANDLE)
1387 error = STV0900_INVALID_HANDLE;
1388 else
1389 error = STV0900_I2C_ERROR;
1390 }
1391
1392 if (state->internal != NULL) {
1393 if (error == STV0900_NO_ERROR) {
1394 state->internal->demod_mode = p_init->demod_mode;
1395
1396 stv0900_st_dvbs2_single(state->internal, state->internal->demod_mode, STV0900_DEMOD_1);
1397
1398 state->internal->chip_id = stv0900_read_reg(state->internal, R0900_MID);
1399 state->internal->rolloff = p_init->rolloff;
1400 state->internal->quartz = p_init->dmd_ref_clk;
1401
1402 stv0900_write_bits(state->internal, F0900_P1_ROLLOFF_CONTROL, p_init->rolloff);
1403 stv0900_write_bits(state->internal, F0900_P2_ROLLOFF_CONTROL, p_init->rolloff);
1404
1405 stv0900_set_ts_parallel_serial(state->internal, p_init->path1_ts_clock, p_init->path2_ts_clock);
1406 stv0900_write_bits(state->internal, F0900_P1_TUN_MADDRESS, p_init->tun1_maddress);
1407 switch (p_init->tuner1_adc) {
1408 case 1:
1409 stv0900_write_reg(state->internal, R0900_TSTTNR1, 0x26);
1410 break;
1411 default:
1412 break;
1413 }
1414
1415 stv0900_write_bits(state->internal, F0900_P2_TUN_MADDRESS, p_init->tun2_maddress);
1416 switch (p_init->tuner2_adc) {
1417 case 1:
1418 stv0900_write_reg(state->internal, R0900_TSTTNR3, 0x26);
1419 break;
1420 default:
1421 break;
1422 }
1423
1424 stv0900_write_bits(state->internal, F0900_P1_TUN_IQSWAP, p_init->tun1_iq_inversion);
1425 stv0900_write_bits(state->internal, F0900_P2_TUN_IQSWAP, p_init->tun2_iq_inversion);
1426 stv0900_set_mclk(state->internal, 135000000);
1427 msleep(3);
1428
1429 switch (state->internal->clkmode) {
1430 case 0:
1431 case 2:
1432 stv0900_write_reg(state->internal, R0900_SYNTCTRL, 0x20 | state->internal->clkmode);
1433 break;
1434 default:
1435 selosci = 0x02 & stv0900_read_reg(state->internal, R0900_SYNTCTRL);
1436 stv0900_write_reg(state->internal, R0900_SYNTCTRL, 0x20 | selosci);
1437 break;
1438 }
1439 msleep(3);
1440
1441 state->internal->mclk = stv0900_get_mclk_freq(state->internal, state->internal->quartz);
1442 if (state->internal->errs)
1443 error = STV0900_I2C_ERROR;
1444 }
1445 } else {
1446 error = STV0900_INVALID_HANDLE;
1447 }
1448 }
1449
1450 return error;
1451}
1452
1453static int stv0900_status(struct stv0900_internal *i_params,
1454 enum fe_stv0900_demod_num demod)
1455{
1456 enum fe_stv0900_search_state demod_state;
1457 s32 mode_field, delin_field, lock_field, fifo_field, lockedvit_field;
1458 int locked = FALSE;
1459
1460 dmd_reg(mode_field, F0900_P1_HEADER_MODE, F0900_P2_HEADER_MODE);
1461 dmd_reg(lock_field, F0900_P1_LOCK_DEFINITIF, F0900_P2_LOCK_DEFINITIF);
1462 dmd_reg(delin_field, F0900_P1_PKTDELIN_LOCK, F0900_P2_PKTDELIN_LOCK);
1463 dmd_reg(fifo_field, F0900_P1_TSFIFO_LINEOK, F0900_P2_TSFIFO_LINEOK);
1464 dmd_reg(lockedvit_field, F0900_P1_LOCKEDVIT, F0900_P2_LOCKEDVIT);
1465
1466 demod_state = stv0900_get_bits(i_params, mode_field);
1467 switch (demod_state) {
1468 case STV0900_SEARCH:
1469 case STV0900_PLH_DETECTED:
1470 default:
1471 locked = FALSE;
1472 break;
1473 case STV0900_DVBS2_FOUND:
1474 locked = stv0900_get_bits(i_params, lock_field) &&
1475 stv0900_get_bits(i_params, delin_field) &&
1476 stv0900_get_bits(i_params, fifo_field);
1477 break;
1478 case STV0900_DVBS_FOUND:
1479 locked = stv0900_get_bits(i_params, lock_field) &&
1480 stv0900_get_bits(i_params, lockedvit_field) &&
1481 stv0900_get_bits(i_params, fifo_field);
1482 break;
1483 }
1484
1485 return locked;
1486}
1487
1488static enum dvbfe_search stv0900_search(struct dvb_frontend *fe,
1489 struct dvb_frontend_parameters *params)
1490{
1491 struct stv0900_state *state = fe->demodulator_priv;
1492 struct stv0900_internal *i_params = state->internal;
1493 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1494
1495 struct stv0900_search_params p_search;
1496 struct stv0900_signal_info p_result;
1497
1498 enum fe_stv0900_error error = STV0900_NO_ERROR;
1499
1500 dprintk(KERN_INFO "%s: ", __func__);
1501
1502 p_result.locked = FALSE;
1503 p_search.path = state->demod;
1504 p_search.frequency = c->frequency;
1505 p_search.symbol_rate = c->symbol_rate;
1506 p_search.search_range = 10000000;
1507 p_search.fec = STV0900_FEC_UNKNOWN;
1508 p_search.standard = STV0900_AUTO_SEARCH;
1509 p_search.iq_inversion = STV0900_IQ_AUTO;
1510 p_search.search_algo = STV0900_BLIND_SEARCH;
1511
1512 if ((INRANGE(100000, p_search.symbol_rate, 70000000)) &&
1513 (INRANGE(100000, p_search.search_range, 50000000))) {
1514 switch (p_search.path) {
1515 case STV0900_DEMOD_1:
1516 default:
1517 i_params->dmd1_srch_standard = p_search.standard;
1518 i_params->dmd1_symbol_rate = p_search.symbol_rate;
1519 i_params->dmd1_srch_range = p_search.search_range;
1520 i_params->tuner1_freq = p_search.frequency;
1521 i_params->dmd1_srch_algo = p_search.search_algo;
1522 i_params->dmd1_srch_iq_inv = p_search.iq_inversion;
1523 i_params->dmd1_fec = p_search.fec;
1524 break;
1525
1526 case STV0900_DEMOD_2:
1527 i_params->dmd2_srch_stndrd = p_search.standard;
1528 i_params->dmd2_symbol_rate = p_search.symbol_rate;
1529 i_params->dmd2_srch_range = p_search.search_range;
1530 i_params->tuner2_freq = p_search.frequency;
1531 i_params->dmd2_srch_algo = p_search.search_algo;
1532 i_params->dmd2_srch_iq_inv = p_search.iq_inversion;
1533 i_params->dmd2_fec = p_search.fec;
1534 break;
1535 }
1536
1537 if ((stv0900_algo(fe) == STV0900_RANGEOK) &&
1538 (i_params->errs == STV0900_NO_ERROR)) {
1539 switch (p_search.path) {
1540 case STV0900_DEMOD_1:
1541 default:
1542 p_result.locked = i_params->dmd1_rslts.locked;
1543 p_result.standard = i_params->dmd1_rslts.standard;
1544 p_result.frequency = i_params->dmd1_rslts.frequency;
1545 p_result.symbol_rate = i_params->dmd1_rslts.symbol_rate;
1546 p_result.fec = i_params->dmd1_rslts.fec;
1547 p_result.modcode = i_params->dmd1_rslts.modcode;
1548 p_result.pilot = i_params->dmd1_rslts.pilot;
1549 p_result.frame_length = i_params->dmd1_rslts.frame_length;
1550 p_result.spectrum = i_params->dmd1_rslts.spectrum;
1551 p_result.rolloff = i_params->dmd1_rslts.rolloff;
1552 p_result.modulation = i_params->dmd1_rslts.modulation;
1553 break;
1554 case STV0900_DEMOD_2:
1555 p_result.locked = i_params->dmd2_rslts.locked;
1556 p_result.standard = i_params->dmd2_rslts.standard;
1557 p_result.frequency = i_params->dmd2_rslts.frequency;
1558 p_result.symbol_rate = i_params->dmd2_rslts.symbol_rate;
1559 p_result.fec = i_params->dmd2_rslts.fec;
1560 p_result.modcode = i_params->dmd2_rslts.modcode;
1561 p_result.pilot = i_params->dmd2_rslts.pilot;
1562 p_result.frame_length = i_params->dmd2_rslts.frame_length;
1563 p_result.spectrum = i_params->dmd2_rslts.spectrum;
1564 p_result.rolloff = i_params->dmd2_rslts.rolloff;
1565 p_result.modulation = i_params->dmd2_rslts.modulation;
1566 break;
1567 }
1568
1569 } else {
1570 p_result.locked = FALSE;
1571 switch (p_search.path) {
1572 case STV0900_DEMOD_1:
1573 switch (i_params->dmd1_err) {
1574 case STV0900_I2C_ERROR:
1575 error = STV0900_I2C_ERROR;
1576 break;
1577 case STV0900_NO_ERROR:
1578 default:
1579 error = STV0900_SEARCH_FAILED;
1580 break;
1581 }
1582 break;
1583 case STV0900_DEMOD_2:
1584 switch (i_params->dmd2_err) {
1585 case STV0900_I2C_ERROR:
1586 error = STV0900_I2C_ERROR;
1587 break;
1588 case STV0900_NO_ERROR:
1589 default:
1590 error = STV0900_SEARCH_FAILED;
1591 break;
1592 }
1593 break;
1594 }
1595 }
1596
1597 } else
1598 error = STV0900_BAD_PARAMETER;
1599
1600 if ((p_result.locked == TRUE) && (error == STV0900_NO_ERROR)) {
1601 dprintk(KERN_INFO "Search Success\n");
1602 return DVBFE_ALGO_SEARCH_SUCCESS;
1603 } else {
1604 dprintk(KERN_INFO "Search Fail\n");
1605 return DVBFE_ALGO_SEARCH_FAILED;
1606 }
1607
1608 return DVBFE_ALGO_SEARCH_ERROR;
1609}
1610
1611static int stv0900_read_status(struct dvb_frontend *fe, enum fe_status *status)
1612{
1613 struct stv0900_state *state = fe->demodulator_priv;
1614
1615 dprintk("%s: ", __func__);
1616
1617 if ((stv0900_status(state->internal, state->demod)) == TRUE) {
1618 dprintk("DEMOD LOCK OK\n");
1619 *status = FE_HAS_CARRIER
1620 | FE_HAS_VITERBI
1621 | FE_HAS_SYNC
1622 | FE_HAS_LOCK;
1623 } else
1624 dprintk("DEMOD LOCK FAIL\n");
1625
1626 return 0;
1627}
1628
1629static int stv0900_track(struct dvb_frontend *fe,
1630 struct dvb_frontend_parameters *p)
1631{
1632 return 0;
1633}
1634
1635static int stv0900_stop_ts(struct dvb_frontend *fe, int stop_ts)
1636{
1637
1638 struct stv0900_state *state = fe->demodulator_priv;
1639 struct stv0900_internal *i_params = state->internal;
1640 enum fe_stv0900_demod_num demod = state->demod;
1641 s32 rst_field;
1642
1643 dmd_reg(rst_field, F0900_P1_RST_HWARE, F0900_P2_RST_HWARE);
1644
1645 if (stop_ts == TRUE)
1646 stv0900_write_bits(i_params, rst_field, 1);
1647 else
1648 stv0900_write_bits(i_params, rst_field, 0);
1649
1650 return 0;
1651}
1652
1653static int stv0900_diseqc_init(struct dvb_frontend *fe)
1654{
1655 struct stv0900_state *state = fe->demodulator_priv;
1656 struct stv0900_internal *i_params = state->internal;
1657 enum fe_stv0900_demod_num demod = state->demod;
1658 s32 mode_field, reset_field;
1659
1660 dmd_reg(mode_field, F0900_P1_DISTX_MODE, F0900_P2_DISTX_MODE);
1661 dmd_reg(reset_field, F0900_P1_DISEQC_RESET, F0900_P2_DISEQC_RESET);
1662
1663 stv0900_write_bits(i_params, mode_field, state->config->diseqc_mode);
1664 stv0900_write_bits(i_params, reset_field, 1);
1665 stv0900_write_bits(i_params, reset_field, 0);
1666
1667 return 0;
1668}
1669
1670static int stv0900_init(struct dvb_frontend *fe)
1671{
1672 dprintk(KERN_INFO "%s\n", __func__);
1673
1674 stv0900_stop_ts(fe, 1);
1675 stv0900_diseqc_init(fe);
1676
1677 return 0;
1678}
1679
1680static int stv0900_diseqc_send(struct stv0900_internal *i_params , u8 *Data,
1681 u32 NbData, enum fe_stv0900_demod_num demod)
1682{
1683 s32 i = 0;
1684
1685 switch (demod) {
1686 case STV0900_DEMOD_1:
1687 default:
1688 stv0900_write_bits(i_params, F0900_P1_DIS_PRECHARGE, 1);
1689 while (i < NbData) {
1690 while (stv0900_get_bits(i_params, F0900_P1_FIFO_FULL))
1691 ;/* checkpatch complains */
1692 stv0900_write_reg(i_params, R0900_P1_DISTXDATA, Data[i]);
1693 i++;
1694 }
1695
1696 stv0900_write_bits(i_params, F0900_P1_DIS_PRECHARGE, 0);
1697 i = 0;
1698 while ((stv0900_get_bits(i_params, F0900_P1_TX_IDLE) != 1) && (i < 10)) {
1699 msleep(10);
1700 i++;
1701 }
1702
1703 break;
1704 case STV0900_DEMOD_2:
1705 stv0900_write_bits(i_params, F0900_P2_DIS_PRECHARGE, 1);
1706
1707 while (i < NbData) {
1708 while (stv0900_get_bits(i_params, F0900_P2_FIFO_FULL))
1709 ;/* checkpatch complains */
1710 stv0900_write_reg(i_params, R0900_P2_DISTXDATA, Data[i]);
1711 i++;
1712 }
1713
1714 stv0900_write_bits(i_params, F0900_P2_DIS_PRECHARGE, 0);
1715 i = 0;
1716 while ((stv0900_get_bits(i_params, F0900_P2_TX_IDLE) != 1) && (i < 10)) {
1717 msleep(10);
1718 i++;
1719 }
1720
1721 break;
1722 }
1723
1724 return 0;
1725}
1726
1727static int stv0900_send_master_cmd(struct dvb_frontend *fe,
1728 struct dvb_diseqc_master_cmd *cmd)
1729{
1730 struct stv0900_state *state = fe->demodulator_priv;
1731
1732 return stv0900_diseqc_send(state->internal,
1733 cmd->msg,
1734 cmd->msg_len,
1735 state->demod);
1736}
1737
1738static int stv0900_send_burst(struct dvb_frontend *fe, fe_sec_mini_cmd_t burst)
1739{
1740 struct stv0900_state *state = fe->demodulator_priv;
1741 struct stv0900_internal *i_params = state->internal;
1742 enum fe_stv0900_demod_num demod = state->demod;
1743 s32 mode_field;
1744 u32 diseqc_fifo;
1745
1746 dmd_reg(mode_field, F0900_P1_DISTX_MODE, F0900_P2_DISTX_MODE);
1747 dmd_reg(diseqc_fifo, R0900_P1_DISTXDATA, R0900_P2_DISTXDATA);
1748
1749 switch (burst) {
1750 case SEC_MINI_A:
1751 stv0900_write_bits(i_params, mode_field, 3);/* Unmodulated */
1752 stv0900_write_reg(i_params, diseqc_fifo, 0x00);
1753 break;
1754 case SEC_MINI_B:
1755 stv0900_write_bits(i_params, mode_field, 2);/* Modulated */
1756 stv0900_write_reg(i_params, diseqc_fifo, 0xff);
1757 break;
1758 }
1759
1760 return 0;
1761}
1762
1763static int stv0900_recv_slave_reply(struct dvb_frontend *fe,
1764 struct dvb_diseqc_slave_reply *reply)
1765{
1766 struct stv0900_state *state = fe->demodulator_priv;
1767 struct stv0900_internal *i_params = state->internal;
1768 s32 i = 0;
1769
1770 switch (state->demod) {
1771 case STV0900_DEMOD_1:
1772 default:
1773 reply->msg_len = 0;
1774
1775 while ((stv0900_get_bits(i_params, F0900_P1_RX_END) != 1) && (i < 10)) {
1776 msleep(10);
1777 i++;
1778 }
1779
1780 if (stv0900_get_bits(i_params, F0900_P1_RX_END)) {
1781 reply->msg_len = stv0900_get_bits(i_params, F0900_P1_FIFO_BYTENBR);
1782
1783 for (i = 0; i < reply->msg_len; i++)
1784 reply->msg[i] = stv0900_read_reg(i_params, R0900_P1_DISRXDATA);
1785 }
1786 break;
1787 case STV0900_DEMOD_2:
1788 reply->msg_len = 0;
1789
1790 while ((stv0900_get_bits(i_params, F0900_P2_RX_END) != 1) && (i < 10)) {
1791 msleep(10);
1792 i++;
1793 }
1794
1795 if (stv0900_get_bits(i_params, F0900_P2_RX_END)) {
1796 reply->msg_len = stv0900_get_bits(i_params, F0900_P2_FIFO_BYTENBR);
1797
1798 for (i = 0; i < reply->msg_len; i++)
1799 reply->msg[i] = stv0900_read_reg(i_params, R0900_P2_DISRXDATA);
1800 }
1801 break;
1802 }
1803
1804 return 0;
1805}
1806
1807static int stv0900_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone)
1808{
1809 struct stv0900_state *state = fe->demodulator_priv;
1810 struct stv0900_internal *i_params = state->internal;
1811 enum fe_stv0900_demod_num demod = state->demod;
1812 s32 mode_field, reset_field;
1813
1814 dprintk(KERN_INFO "%s: %s\n", __func__, ((tone == 0) ? "Off" : "On"));
1815
1816 dmd_reg(mode_field, F0900_P1_DISTX_MODE, F0900_P2_DISTX_MODE);
1817 dmd_reg(reset_field, F0900_P1_DISEQC_RESET, F0900_P2_DISEQC_RESET);
1818
1819 if (tone) {
1820 /*Set the DiseqC mode to 22Khz continues tone*/
1821 stv0900_write_bits(i_params, mode_field, 0);
1822 stv0900_write_bits(i_params, reset_field, 1);
1823 /*release DiseqC reset to enable the 22KHz tone*/
1824 stv0900_write_bits(i_params, reset_field, 0);
1825 } else {
1826 stv0900_write_bits(i_params, mode_field, 0);
1827 /*maintain the DiseqC reset to disable the 22KHz tone*/
1828 stv0900_write_bits(i_params, reset_field, 1);
1829 }
1830
1831 return 0;
1832}
1833
1834static void stv0900_release(struct dvb_frontend *fe)
1835{
1836 struct stv0900_state *state = fe->demodulator_priv;
1837
1838 dprintk(KERN_INFO "%s\n", __func__);
1839
1840 if ((--(state->internal->dmds_used)) <= 0) {
1841
1842 dprintk(KERN_INFO "%s: Actually removing\n", __func__);
1843
1844 remove_inode(state->internal);
1845 kfree(state->internal);
1846 }
1847
1848 kfree(state);
1849}
1850
1851static struct dvb_frontend_ops stv0900_ops = {
1852
1853 .info = {
1854 .name = "STV0900 frontend",
1855 .type = FE_QPSK,
1856 .frequency_min = 950000,
1857 .frequency_max = 2150000,
1858 .frequency_stepsize = 125,
1859 .frequency_tolerance = 0,
1860 .symbol_rate_min = 1000000,
1861 .symbol_rate_max = 45000000,
1862 .symbol_rate_tolerance = 500,
1863 .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 |
1864 FE_CAN_FEC_3_4 | FE_CAN_FEC_5_6 |
1865 FE_CAN_FEC_7_8 | FE_CAN_QPSK |
1866 FE_CAN_2G_MODULATION |
1867 FE_CAN_FEC_AUTO
1868 },
1869 .release = stv0900_release,
1870 .init = stv0900_init,
1871 .get_frontend_algo = stv0900_frontend_algo,
1872 .i2c_gate_ctrl = stv0900_i2c_gate_ctrl,
1873 .diseqc_send_master_cmd = stv0900_send_master_cmd,
1874 .diseqc_send_burst = stv0900_send_burst,
1875 .diseqc_recv_slave_reply = stv0900_recv_slave_reply,
1876 .set_tone = stv0900_set_tone,
1877 .set_property = stb0900_set_property,
1878 .get_property = stb0900_get_property,
1879 .search = stv0900_search,
1880 .track = stv0900_track,
1881 .read_status = stv0900_read_status,
1882 .read_ber = stv0900_read_ber,
1883 .read_signal_strength = stv0900_read_signal_strength,
1884 .read_snr = stv0900_read_snr,
1885};
1886
1887struct dvb_frontend *stv0900_attach(const struct stv0900_config *config,
1888 struct i2c_adapter *i2c,
1889 int demod)
1890{
1891 struct stv0900_state *state = NULL;
1892 struct stv0900_init_params init_params;
1893 enum fe_stv0900_error err_stv0900;
1894
1895 state = kzalloc(sizeof(struct stv0900_state), GFP_KERNEL);
1896 if (state == NULL)
1897 goto error;
1898
1899 state->demod = demod;
1900 state->config = config;
1901 state->i2c_adap = i2c;
1902
1903 memcpy(&state->frontend.ops, &stv0900_ops,
1904 sizeof(struct dvb_frontend_ops));
1905 state->frontend.demodulator_priv = state;
1906
1907 switch (demod) {
1908 case 0:
1909 case 1:
1910 init_params.dmd_ref_clk = config->xtal;
1911 init_params.demod_mode = STV0900_DUAL;
1912 init_params.rolloff = STV0900_35;
1913 init_params.path1_ts_clock = config->path1_mode;
1914 init_params.tun1_maddress = config->tun1_maddress;
1915 init_params.tun1_iq_inversion = STV0900_IQ_NORMAL;
1916 init_params.tuner1_adc = config->tun1_adc;
1917 init_params.path2_ts_clock = config->path2_mode;
1918 init_params.tun2_maddress = config->tun2_maddress;
1919 init_params.tuner2_adc = config->tun2_adc;
1920 init_params.tun2_iq_inversion = STV0900_IQ_SWAPPED;
1921
1922 err_stv0900 = stv0900_init_internal(&state->frontend,
1923 &init_params);
1924
1925 if (err_stv0900)
1926 goto error;
1927
1928 break;
1929 default:
1930 goto error;
1931 break;
1932 }
1933
1934 dprintk("%s: Attaching STV0900 demodulator(%d) \n", __func__, demod);
1935 return &state->frontend;
1936
1937error:
1938 dprintk("%s: Failed to attach STV0900 demodulator(%d) \n",
1939 __func__, demod);
1940 kfree(state);
1941 return NULL;
1942}
1943EXPORT_SYMBOL(stv0900_attach);
1944
1945MODULE_PARM_DESC(debug, "Set debug");
1946
1947MODULE_AUTHOR("Igor M. Liplianin");
1948MODULE_DESCRIPTION("ST STV0900 frontend");
1949MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/stv0900_init.h b/drivers/media/dvb/frontends/stv0900_init.h
new file mode 100644
index 000000000000..ff388b47a4e3
--- /dev/null
+++ b/drivers/media/dvb/frontends/stv0900_init.h
@@ -0,0 +1,441 @@
1/*
2 * stv0900_init.h
3 *
4 * Driver for ST STV0900 satellite demodulator IC.
5 *
6 * Copyright (C) ST Microelectronics.
7 * Copyright (C) 2009 NetUP Inc.
8 * Copyright (C) 2009 Igor M. Liplianin <liplianin@netup.ru>
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 *
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25
26#ifndef STV0900_INIT_H
27#define STV0900_INIT_H
28
29#include "stv0900_priv.h"
30
31/* DVBS2 C/N Look-Up table */
32static const struct stv0900_table stv0900_s2_cn = {
33 55,
34 {
35 { -30, 13348 }, /*C/N=-3dB*/
36 { -20, 12640 }, /*C/N=-2dB*/
37 { -10, 11883 }, /*C/N=-1dB*/
38 { 0, 11101 }, /*C/N=-0dB*/
39 { 5, 10718 }, /*C/N=0.5dB*/
40 { 10, 10339 }, /*C/N=1.0dB*/
41 { 15, 9947 }, /*C/N=1.5dB*/
42 { 20, 9552 }, /*C/N=2.0dB*/
43 { 25, 9183 }, /*C/N=2.5dB*/
44 { 30, 8799 }, /*C/N=3.0dB*/
45 { 35, 8422 }, /*C/N=3.5dB*/
46 { 40, 8062 }, /*C/N=4.0dB*/
47 { 45, 7707 }, /*C/N=4.5dB*/
48 { 50, 7353 }, /*C/N=5.0dB*/
49 { 55, 7025 }, /*C/N=5.5dB*/
50 { 60, 6684 }, /*C/N=6.0dB*/
51 { 65, 6331 }, /*C/N=6.5dB*/
52 { 70, 6036 }, /*C/N=7.0dB*/
53 { 75, 5727 }, /*C/N=7.5dB*/
54 { 80, 5437 }, /*C/N=8.0dB*/
55 { 85, 5164 }, /*C/N=8.5dB*/
56 { 90, 4902 }, /*C/N=9.0dB*/
57 { 95, 4653 }, /*C/N=9.5dB*/
58 { 100, 4408 }, /*C/N=10.0dB*/
59 { 105, 4187 }, /*C/N=10.5dB*/
60 { 110, 3961 }, /*C/N=11.0dB*/
61 { 115, 3751 }, /*C/N=11.5dB*/
62 { 120, 3558 }, /*C/N=12.0dB*/
63 { 125, 3368 }, /*C/N=12.5dB*/
64 { 130, 3191 }, /*C/N=13.0dB*/
65 { 135, 3017 }, /*C/N=13.5dB*/
66 { 140, 2862 }, /*C/N=14.0dB*/
67 { 145, 2710 }, /*C/N=14.5dB*/
68 { 150, 2565 }, /*C/N=15.0dB*/
69 { 160, 2300 }, /*C/N=16.0dB*/
70 { 170, 2058 }, /*C/N=17.0dB*/
71 { 180, 1849 }, /*C/N=18.0dB*/
72 { 190, 1663 }, /*C/N=19.0dB*/
73 { 200, 1495 }, /*C/N=20.0dB*/
74 { 210, 1349 }, /*C/N=21.0dB*/
75 { 220, 1222 }, /*C/N=22.0dB*/
76 { 230, 1110 }, /*C/N=23.0dB*/
77 { 240, 1011 }, /*C/N=24.0dB*/
78 { 250, 925 }, /*C/N=25.0dB*/
79 { 260, 853 }, /*C/N=26.0dB*/
80 { 270, 789 }, /*C/N=27.0dB*/
81 { 280, 734 }, /*C/N=28.0dB*/
82 { 290, 690 }, /*C/N=29.0dB*/
83 { 300, 650 }, /*C/N=30.0dB*/
84 { 310, 619 }, /*C/N=31.0dB*/
85 { 320, 593 }, /*C/N=32.0dB*/
86 { 330, 571 }, /*C/N=33.0dB*/
87 { 400, 498 }, /*C/N=40.0dB*/
88 { 450, 484 }, /*C/N=45.0dB*/
89 { 500, 481 } /*C/N=50.0dB*/
90 }
91};
92
93/* RF level C/N Look-Up table */
94static const struct stv0900_table stv0900_rf = {
95 14,
96 {
97 { -5, 0xCAA1 }, /*-5dBm*/
98 { -10, 0xC229 }, /*-10dBm*/
99 { -15, 0xBB08 }, /*-15dBm*/
100 { -20, 0xB4BC }, /*-20dBm*/
101 { -25, 0xAD5A }, /*-25dBm*/
102 { -30, 0xA298 }, /*-30dBm*/
103 { -35, 0x98A8 }, /*-35dBm*/
104 { -40, 0x8389 }, /*-40dBm*/
105 { -45, 0x59BE }, /*-45dBm*/
106 { -50, 0x3A14 }, /*-50dBm*/
107 { -55, 0x2D11 }, /*-55dBm*/
108 { -60, 0x210D }, /*-60dBm*/
109 { -65, 0xA14F }, /*-65dBm*/
110 { -70, 0x7AA } /*-70dBm*/
111 }
112};
113
114struct stv0900_car_loop_optim {
115 enum fe_stv0900_modcode modcode;
116 u8 car_loop_pilots_on_2;
117 u8 car_loop_pilots_off_2;
118 u8 car_loop_pilots_on_5;
119 u8 car_loop_pilots_off_5;
120 u8 car_loop_pilots_on_10;
121 u8 car_loop_pilots_off_10;
122 u8 car_loop_pilots_on_20;
123 u8 car_loop_pilots_off_20;
124 u8 car_loop_pilots_on_30;
125 u8 car_loop_pilots_off_30;
126
127};
128
129struct stv0900_short_frames_car_loop_optim {
130 enum fe_stv0900_modulation modulation;
131 u8 car_loop_cut12_2; /* Cut 1.2, SR<=3msps */
132 u8 car_loop_cut20_2; /* Cut 2.0, SR<3msps */
133 u8 car_loop_cut12_5; /* Cut 1.2, 3<SR<=7msps */
134 u8 car_loop_cut20_5; /* Cut 2.0, 3<SR<=7msps */
135 u8 car_loop_cut12_10; /* Cut 1.2, 7<SR<=15msps */
136 u8 car_loop_cut20_10; /* Cut 2.0, 7<SR<=15msps */
137 u8 car_loop_cut12_20; /* Cut 1.2, 10<SR<=25msps */
138 u8 car_loop_cut20_20; /* Cut 2.0, 10<SR<=25msps */
139 u8 car_loop_cut12_30; /* Cut 1.2, 25<SR<=45msps */
140 u8 car_loop_cut20_30; /* Cut 2.0, 10<SR<=45msps */
141
142};
143
144/* Cut 1.x Tracking carrier loop carrier QPSK 1/2 to 8PSK 9/10 long Frame */
145static const struct stv0900_car_loop_optim FE_STV0900_S2CarLoop[14] = {
146 /*Modcod 2MPon 2MPoff 5MPon 5MPoff 10MPon 10MPoff 20MPon 20MPoff 30MPon 30MPoff */
147 { STV0900_QPSK_12, 0x1C, 0x0D, 0x1B, 0x2C, 0x3A, 0x1C, 0x2A, 0x3B, 0x2A, 0x1B },
148 { STV0900_QPSK_35, 0x2C, 0x0D, 0x2B, 0x2C, 0x3A, 0x0C, 0x3A, 0x2B, 0x2A, 0x0B },
149 { STV0900_QPSK_23, 0x2C, 0x0D, 0x2B, 0x2C, 0x0B, 0x0C, 0x3A, 0x1B, 0x2A, 0x3A },
150 { STV0900_QPSK_34, 0x3C, 0x0D, 0x3B, 0x1C, 0x0B, 0x3B, 0x3A, 0x0B, 0x2A, 0x3A },
151 { STV0900_QPSK_45, 0x3C, 0x0D, 0x3B, 0x1C, 0x0B, 0x3B, 0x3A, 0x0B, 0x2A, 0x3A },
152 { STV0900_QPSK_56, 0x0D, 0x0D, 0x3B, 0x1C, 0x0B, 0x3B, 0x3A, 0x0B, 0x2A, 0x3A },
153 { STV0900_QPSK_89, 0x0D, 0x0D, 0x3B, 0x1C, 0x1B, 0x3B, 0x3A, 0x0B, 0x2A, 0x3A },
154 { STV0900_QPSK_910, 0x1D, 0x0D, 0x3B, 0x1C, 0x1B, 0x3B, 0x3A, 0x0B, 0x2A, 0x3A },
155 { STV0900_8PSK_35, 0x29, 0x3B, 0x09, 0x2B, 0x38, 0x0B, 0x18, 0x1A, 0x08, 0x0A },
156 { STV0900_8PSK_23, 0x0A, 0x3B, 0x29, 0x2B, 0x19, 0x0B, 0x38, 0x1A, 0x18, 0x0A },
157 { STV0900_8PSK_34, 0x3A, 0x3B, 0x2A, 0x2B, 0x39, 0x0B, 0x19, 0x1A, 0x38, 0x0A },
158 { STV0900_8PSK_56, 0x1B, 0x3B, 0x0B, 0x2B, 0x1A, 0x0B, 0x39, 0x1A, 0x19, 0x0A },
159 { STV0900_8PSK_89, 0x3B, 0x3B, 0x0B, 0x2B, 0x2A, 0x0B, 0x39, 0x1A, 0x29, 0x39 },
160 { STV0900_8PSK_910, 0x3B, 0x3B, 0x0B, 0x2B, 0x2A, 0x0B, 0x39, 0x1A, 0x29, 0x39 }
161};
162
163
164/* Cut 2.0 Tracking carrier loop carrier QPSK 1/2 to 8PSK 9/10 long Frame */
165static const struct stv0900_car_loop_optim FE_STV0900_S2CarLoopCut20[14] = {
166 /* Modcod 2MPon 2MPoff 5MPon 5MPoff 10MPon 10MPoff 20MPon 20MPoff 30MPon 30MPoff */
167 { STV0900_QPSK_12, 0x1F, 0x3F, 0x1E, 0x3F, 0x3D, 0x1F, 0x3D, 0x3E, 0x3D, 0x1E },
168 { STV0900_QPSK_35, 0x2F, 0x3F, 0x2E, 0x2F, 0x3D, 0x0F, 0x0E, 0x2E, 0x3D, 0x0E },
169 { STV0900_QPSK_23, 0x2F, 0x3F, 0x2E, 0x2F, 0x0E, 0x0F, 0x0E, 0x1E, 0x3D, 0x3D },
170 { STV0900_QPSK_34, 0x3F, 0x3F, 0x3E, 0x1F, 0x0E, 0x3E, 0x0E, 0x1E, 0x3D, 0x3D },
171 { STV0900_QPSK_45, 0x3F, 0x3F, 0x3E, 0x1F, 0x0E, 0x3E, 0x0E, 0x1E, 0x3D, 0x3D },
172 { STV0900_QPSK_56, 0x3F, 0x3F, 0x3E, 0x1F, 0x0E, 0x3E, 0x0E, 0x1E, 0x3D, 0x3D },
173 { STV0900_QPSK_89, 0x3F, 0x3F, 0x3E, 0x1F, 0x1E, 0x3E, 0x0E, 0x1E, 0x3D, 0x3D },
174 { STV0900_QPSK_910, 0x3F, 0x3F, 0x3E, 0x1F, 0x1E, 0x3E, 0x0E, 0x1E, 0x3D, 0x3D },
175 { STV0900_8PSK_35, 0x3c, 0x0c, 0x1c, 0x3b, 0x0c, 0x3b, 0x2b, 0x2b, 0x1b, 0x2b },
176 { STV0900_8PSK_23, 0x1d, 0x0c, 0x3c, 0x0c, 0x2c, 0x3b, 0x0c, 0x2b, 0x2b, 0x2b },
177 { STV0900_8PSK_34, 0x0e, 0x1c, 0x3d, 0x0c, 0x0d, 0x3b, 0x2c, 0x3b, 0x0c, 0x2b },
178 { STV0900_8PSK_56, 0x2e, 0x3e, 0x1e, 0x2e, 0x2d, 0x1e, 0x3c, 0x2d, 0x2c, 0x1d },
179 { STV0900_8PSK_89, 0x3e, 0x3e, 0x1e, 0x2e, 0x3d, 0x1e, 0x0d, 0x2d, 0x3c, 0x1d },
180 { STV0900_8PSK_910, 0x3e, 0x3e, 0x1e, 0x2e, 0x3d, 0x1e, 0x1d, 0x2d, 0x0d, 0x1d }
181};
182
183
184
185/* Cut 2.0 Tracking carrier loop carrier 16APSK 2/3 to 32APSK 9/10 long Frame */
186static const struct stv0900_car_loop_optim FE_STV0900_S2APSKCarLoopCut20[11] = {
187 /* Modcod 2MPon 2MPoff 5MPon 5MPoff 10MPon 10MPoff 20MPon 20MPoff 30MPon 30MPoff */
188 { STV0900_16APSK_23, 0x0C, 0x0C, 0x0C, 0x0C, 0x1D, 0x0C, 0x3C, 0x0C, 0x2C, 0x0C },
189 { STV0900_16APSK_34, 0x0C, 0x0C, 0x0C, 0x0C, 0x0E, 0x0C, 0x2D, 0x0C, 0x1D, 0x0C },
190 { STV0900_16APSK_45, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x0C, 0x3D, 0x0C, 0x2D, 0x0C },
191 { STV0900_16APSK_56, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x0C, 0x3D, 0x0C, 0x2D, 0x0C },
192 { STV0900_16APSK_89, 0x0C, 0x0C, 0x0C, 0x0C, 0x2E, 0x0C, 0x0E, 0x0C, 0x3D, 0x0C },
193 { STV0900_16APSK_910, 0x0C, 0x0C, 0x0C, 0x0C, 0x2E, 0x0C, 0x0E, 0x0C, 0x3D, 0x0C },
194 { STV0900_32APSK_34, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C },
195 { STV0900_32APSK_45, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C },
196 { STV0900_32APSK_56, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C },
197 { STV0900_32APSK_89, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C },
198 { STV0900_32APSK_910, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C }
199};
200
201
202/* Cut 2.0 Tracking carrier loop carrier QPSK 1/4 to QPSK 2/5 long Frame */
203static const struct stv0900_car_loop_optim FE_STV0900_S2LowQPCarLoopCut20[3] = {
204 /* Modcod 2MPon 2MPoff 5MPon 5MPoff 10MPon 10MPoff 20MPon 20MPoff 30MPon 30MPoff */
205 { STV0900_QPSK_14, 0x0F, 0x3F, 0x0E, 0x3F, 0x2D, 0x2F, 0x2D, 0x1F, 0x3D, 0x3E },
206 { STV0900_QPSK_13, 0x0F, 0x3F, 0x0E, 0x3F, 0x2D, 0x2F, 0x3D, 0x0F, 0x3D, 0x2E },
207 { STV0900_QPSK_25, 0x1F, 0x3F, 0x1E, 0x3F, 0x3D, 0x1F, 0x3D, 0x3E, 0x3D, 0x2E }
208};
209
210
211/* Cut 2.0 Tracking carrier loop carrier short Frame, cut 1.2 and 2.0 */
212static const struct stv0900_short_frames_car_loop_optim FE_STV0900_S2ShortCarLoop[4] = {
213 /*Mod 2M_cut1.2 2M_cut2.0 5M_cut1.2 5M_cut2.0 10M_cut1.2 10M_cut2.0 20M_cut1.2 20M_cut2.0 30M_cut1.2 30M_cut2.0 */
214 { STV0900_QPSK, 0x3C, 0x2F, 0x2B, 0x2E, 0x0B, 0x0E, 0x3A, 0x0E, 0x2A, 0x3D },
215 { STV0900_8PSK, 0x0B, 0x3E, 0x2A, 0x0E, 0x0A, 0x2D, 0x19, 0x0D, 0x09, 0x3C },
216 { STV0900_16APSK, 0x1B, 0x1E, 0x1B, 0x1E, 0x1B, 0x1E, 0x3A, 0x3D, 0x2A, 0x2D },
217 { STV0900_32APSK, 0x1B, 0x1E, 0x1B, 0x1E, 0x1B, 0x1E, 0x3A, 0x3D, 0x2A, 0x2D }
218};
219
220static const u16 STV0900_InitVal[182][2] = {
221 { R0900_OUTCFG , 0x00 },
222 { R0900_MODECFG , 0xff },
223 { R0900_AGCRF1CFG , 0x11 },
224 { R0900_AGCRF2CFG , 0x13 },
225 { R0900_TSGENERAL1X , 0x14 },
226 { R0900_TSTTNR2 , 0x21 },
227 { R0900_TSTTNR4 , 0x21 },
228 { R0900_P2_DISTXCTL , 0x22 },
229 { R0900_P2_F22TX , 0xc0 },
230 { R0900_P2_F22RX , 0xc0 },
231 { R0900_P2_DISRXCTL , 0x00 },
232 { R0900_P2_TNRSTEPS , 0x87 },
233 { R0900_P2_TNRGAIN , 0x09 },
234 { R0900_P2_DMDCFGMD , 0xF9 },
235 { R0900_P2_DEMOD , 0x08 },
236 { R0900_P2_DMDCFG3 , 0xc4 },
237 { R0900_P2_CARFREQ , 0xed },
238 { R0900_P2_TNRCFG2 , 0x02 },
239 { R0900_P2_TNRCFG3 , 0x02 },
240 { R0900_P2_LDT , 0xd0 },
241 { R0900_P2_LDT2 , 0xb8 },
242 { R0900_P2_TMGCFG , 0xd2 },
243 { R0900_P2_TMGTHRISE , 0x20 },
244 { R0900_P2_TMGTHFALL , 0x00 },
245 { R0900_P2_FECSPY , 0x88 },
246 { R0900_P2_FSPYDATA , 0x3a },
247 { R0900_P2_FBERCPT4 , 0x00 },
248 { R0900_P2_FSPYBER , 0x10 },
249 { R0900_P2_ERRCTRL1 , 0x35 },
250 { R0900_P2_ERRCTRL2 , 0xc1 },
251 { R0900_P2_CFRICFG , 0xf8 },
252 { R0900_P2_NOSCFG , 0x1c },
253 { R0900_P2_DMDT0M , 0x20 },
254 { R0900_P2_CORRELMANT , 0x70 },
255 { R0900_P2_CORRELABS , 0x88 },
256 { R0900_P2_AGC2O , 0x5b },
257 { R0900_P2_AGC2REF , 0x38 },
258 { R0900_P2_CARCFG , 0xe4 },
259 { R0900_P2_ACLC , 0x1A },
260 { R0900_P2_BCLC , 0x09 },
261 { R0900_P2_CARHDR , 0x08 },
262 { R0900_P2_KREFTMG , 0xc1 },
263 { R0900_P2_SFRUPRATIO , 0xf0 },
264 { R0900_P2_SFRLOWRATIO , 0x70 },
265 { R0900_P2_SFRSTEP , 0x58 },
266 { R0900_P2_TMGCFG2 , 0x01 },
267 { R0900_P2_CAR2CFG , 0x26 },
268 { R0900_P2_BCLC2S2Q , 0x86 },
269 { R0900_P2_BCLC2S28 , 0x86 },
270 { R0900_P2_SMAPCOEF7 , 0x77 },
271 { R0900_P2_SMAPCOEF6 , 0x85 },
272 { R0900_P2_SMAPCOEF5 , 0x77 },
273 { R0900_P2_TSCFGL , 0x20 },
274 { R0900_P2_DMDCFG2 , 0x3b },
275 { R0900_P2_MODCODLST0 , 0xff },
276 { R0900_P2_MODCODLST1 , 0xff },
277 { R0900_P2_MODCODLST2 , 0xff },
278 { R0900_P2_MODCODLST3 , 0xff },
279 { R0900_P2_MODCODLST4 , 0xff },
280 { R0900_P2_MODCODLST5 , 0xff },
281 { R0900_P2_MODCODLST6 , 0xff },
282 { R0900_P2_MODCODLST7 , 0xcc },
283 { R0900_P2_MODCODLST8 , 0xcc },
284 { R0900_P2_MODCODLST9 , 0xcc },
285 { R0900_P2_MODCODLSTA , 0xcc },
286 { R0900_P2_MODCODLSTB , 0xcc },
287 { R0900_P2_MODCODLSTC , 0xcc },
288 { R0900_P2_MODCODLSTD , 0xcc },
289 { R0900_P2_MODCODLSTE , 0xcc },
290 { R0900_P2_MODCODLSTF , 0xcf },
291 { R0900_P1_DISTXCTL , 0x22 },
292 { R0900_P1_F22TX , 0xc0 },
293 { R0900_P1_F22RX , 0xc0 },
294 { R0900_P1_DISRXCTL , 0x00 },
295 { R0900_P1_TNRSTEPS , 0x87 },
296 { R0900_P1_TNRGAIN , 0x09 },
297 { R0900_P1_DMDCFGMD , 0xf9 },
298 { R0900_P1_DEMOD , 0x08 },
299 { R0900_P1_DMDCFG3 , 0xc4 },
300 { R0900_P1_DMDT0M , 0x20 },
301 { R0900_P1_CARFREQ , 0xed },
302 { R0900_P1_TNRCFG2 , 0x82 },
303 { R0900_P1_TNRCFG3 , 0x02 },
304 { R0900_P1_LDT , 0xd0 },
305 { R0900_P1_LDT2 , 0xb8 },
306 { R0900_P1_TMGCFG , 0xd2 },
307 { R0900_P1_TMGTHRISE , 0x20 },
308 { R0900_P1_TMGTHFALL , 0x00 },
309 { R0900_P1_SFRUPRATIO , 0xf0 },
310 { R0900_P1_SFRLOWRATIO , 0x70 },
311 { R0900_P1_TSCFGL , 0x20 },
312 { R0900_P1_FECSPY , 0x88 },
313 { R0900_P1_FSPYDATA , 0x3a },
314 { R0900_P1_FBERCPT4 , 0x00 },
315 { R0900_P1_FSPYBER , 0x10 },
316 { R0900_P1_ERRCTRL1 , 0x35 },
317 { R0900_P1_ERRCTRL2 , 0xc1 },
318 { R0900_P1_CFRICFG , 0xf8 },
319 { R0900_P1_NOSCFG , 0x1c },
320 { R0900_P1_CORRELMANT , 0x70 },
321 { R0900_P1_CORRELABS , 0x88 },
322 { R0900_P1_AGC2O , 0x5b },
323 { R0900_P1_AGC2REF , 0x38 },
324 { R0900_P1_CARCFG , 0xe4 },
325 { R0900_P1_ACLC , 0x1A },
326 { R0900_P1_BCLC , 0x09 },
327 { R0900_P1_CARHDR , 0x08 },
328 { R0900_P1_KREFTMG , 0xc1 },
329 { R0900_P1_SFRSTEP , 0x58 },
330 { R0900_P1_TMGCFG2 , 0x01 },
331 { R0900_P1_CAR2CFG , 0x26 },
332 { R0900_P1_BCLC2S2Q , 0x86 },
333 { R0900_P1_BCLC2S28 , 0x86 },
334 { R0900_P1_SMAPCOEF7 , 0x77 },
335 { R0900_P1_SMAPCOEF6 , 0x85 },
336 { R0900_P1_SMAPCOEF5 , 0x77 },
337 { R0900_P1_DMDCFG2 , 0x3b },
338 { R0900_P1_MODCODLST0 , 0xff },
339 { R0900_P1_MODCODLST1 , 0xff },
340 { R0900_P1_MODCODLST2 , 0xff },
341 { R0900_P1_MODCODLST3 , 0xff },
342 { R0900_P1_MODCODLST4 , 0xff },
343 { R0900_P1_MODCODLST5 , 0xff },
344 { R0900_P1_MODCODLST6 , 0xff },
345 { R0900_P1_MODCODLST7 , 0xcc },
346 { R0900_P1_MODCODLST8 , 0xcc },
347 { R0900_P1_MODCODLST9 , 0xcc },
348 { R0900_P1_MODCODLSTA , 0xcc },
349 { R0900_P1_MODCODLSTB , 0xcc },
350 { R0900_P1_MODCODLSTC , 0xcc },
351 { R0900_P1_MODCODLSTD , 0xcc },
352 { R0900_P1_MODCODLSTE , 0xcc },
353 { R0900_P1_MODCODLSTF , 0xcf },
354 { R0900_GENCFG , 0x1d },
355 { R0900_NBITER_NF4 , 0x37 },
356 { R0900_NBITER_NF5 , 0x29 },
357 { R0900_NBITER_NF6 , 0x37 },
358 { R0900_NBITER_NF7 , 0x33 },
359 { R0900_NBITER_NF8 , 0x31 },
360 { R0900_NBITER_NF9 , 0x2f },
361 { R0900_NBITER_NF10 , 0x39 },
362 { R0900_NBITER_NF11 , 0x3a },
363 { R0900_NBITER_NF12 , 0x29 },
364 { R0900_NBITER_NF13 , 0x37 },
365 { R0900_NBITER_NF14 , 0x33 },
366 { R0900_NBITER_NF15 , 0x2f },
367 { R0900_NBITER_NF16 , 0x39 },
368 { R0900_NBITER_NF17 , 0x3a },
369 { R0900_NBITERNOERR , 0x04 },
370 { R0900_GAINLLR_NF4 , 0x0C },
371 { R0900_GAINLLR_NF5 , 0x0F },
372 { R0900_GAINLLR_NF6 , 0x11 },
373 { R0900_GAINLLR_NF7 , 0x14 },
374 { R0900_GAINLLR_NF8 , 0x17 },
375 { R0900_GAINLLR_NF9 , 0x19 },
376 { R0900_GAINLLR_NF10 , 0x20 },
377 { R0900_GAINLLR_NF11 , 0x21 },
378 { R0900_GAINLLR_NF12 , 0x0D },
379 { R0900_GAINLLR_NF13 , 0x0F },
380 { R0900_GAINLLR_NF14 , 0x13 },
381 { R0900_GAINLLR_NF15 , 0x1A },
382 { R0900_GAINLLR_NF16 , 0x1F },
383 { R0900_GAINLLR_NF17 , 0x21 },
384 { R0900_RCCFGH , 0x20 },
385 { R0900_P1_FECM , 0x01 }, /*disable DSS modes*/
386 { R0900_P2_FECM , 0x01 }, /*disable DSS modes*/
387 { R0900_P1_PRVIT , 0x2F }, /*disable puncture rate 6/7*/
388 { R0900_P2_PRVIT , 0x2F }, /*disable puncture rate 6/7*/
389 { R0900_STROUT1CFG , 0x4c },
390 { R0900_STROUT2CFG , 0x4c },
391 { R0900_CLKOUT1CFG , 0x50 },
392 { R0900_CLKOUT2CFG , 0x50 },
393 { R0900_DPN1CFG , 0x4a },
394 { R0900_DPN2CFG , 0x4a },
395 { R0900_DATA71CFG , 0x52 },
396 { R0900_DATA72CFG , 0x52 },
397 { R0900_P1_TSCFGM , 0xc0 },
398 { R0900_P2_TSCFGM , 0xc0 },
399 { R0900_P1_TSCFGH , 0xe0 }, /* DVB-CI timings */
400 { R0900_P2_TSCFGH , 0xe0 }, /* DVB-CI timings */
401 { R0900_P1_TSSPEED , 0x40 },
402 { R0900_P2_TSSPEED , 0x40 },
403};
404
405static const u16 STV0900_Cut20_AddOnVal[32][2] = {
406 { R0900_P2_DMDCFG3 , 0xe8 },
407 { R0900_P2_DMDCFG4 , 0x10 },
408 { R0900_P2_CARFREQ , 0x38 },
409 { R0900_P2_CARHDR , 0x20 },
410 { R0900_P2_KREFTMG , 0x5a },
411 { R0900_P2_SMAPCOEF7 , 0x06 },
412 { R0900_P2_SMAPCOEF6 , 0x00 },
413 { R0900_P2_SMAPCOEF5 , 0x04 },
414 { R0900_P2_NOSCFG , 0x0c },
415 { R0900_P1_DMDCFG3 , 0xe8 },
416 { R0900_P1_DMDCFG4 , 0x10 },
417 { R0900_P1_CARFREQ , 0x38 },
418 { R0900_P1_CARHDR , 0x20 },
419 { R0900_P1_KREFTMG , 0x5a },
420 { R0900_P1_SMAPCOEF7 , 0x06 },
421 { R0900_P1_SMAPCOEF6 , 0x00 },
422 { R0900_P1_SMAPCOEF5 , 0x04 },
423 { R0900_P1_NOSCFG , 0x0c },
424 { R0900_GAINLLR_NF4 , 0x21 },
425 { R0900_GAINLLR_NF5 , 0x21 },
426 { R0900_GAINLLR_NF6 , 0x20 },
427 { R0900_GAINLLR_NF7 , 0x1F },
428 { R0900_GAINLLR_NF8 , 0x1E },
429 { R0900_GAINLLR_NF9 , 0x1E },
430 { R0900_GAINLLR_NF10 , 0x1D },
431 { R0900_GAINLLR_NF11 , 0x1B },
432 { R0900_GAINLLR_NF12 , 0x20 },
433 { R0900_GAINLLR_NF13 , 0x20 },
434 { R0900_GAINLLR_NF14 , 0x20 },
435 { R0900_GAINLLR_NF15 , 0x20 },
436 { R0900_GAINLLR_NF16 , 0x20 },
437 { R0900_GAINLLR_NF17 , 0x21 }
438
439};
440
441#endif
diff --git a/drivers/media/dvb/frontends/stv0900_priv.h b/drivers/media/dvb/frontends/stv0900_priv.h
new file mode 100644
index 000000000000..762d5af62d7a
--- /dev/null
+++ b/drivers/media/dvb/frontends/stv0900_priv.h
@@ -0,0 +1,430 @@
1/*
2 * stv0900_priv.h
3 *
4 * Driver for ST STV0900 satellite demodulator IC.
5 *
6 * Copyright (C) ST Microelectronics.
7 * Copyright (C) 2009 NetUP Inc.
8 * Copyright (C) 2009 Igor M. Liplianin <liplianin@netup.ru>
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 *
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25
26#ifndef STV0900_PRIV_H
27#define STV0900_PRIV_H
28
29#include <linux/i2c.h>
30
31#define ABS(X) ((X) < 0 ? (-1 * (X)) : (X))
32#define INRANGE(X, Y, Z) ((((X) <= (Y)) && ((Y) <= (Z))) \
33 || (((Z) <= (Y)) && ((Y) <= (X))) ? 1 : 0)
34
35#ifndef MAKEWORD
36#define MAKEWORD(X, Y) (((X) << 8) + (Y))
37#endif
38
39#define LSB(X) (((X) & 0xFF))
40#define MSB(Y) (((Y) >> 8) & 0xFF)
41
42#ifndef TRUE
43#define TRUE (1 == 1)
44#endif
45#ifndef FALSE
46#define FALSE (!TRUE)
47#endif
48
49#define dmd_reg(a, b, c) \
50 do { \
51 a = 0; \
52 switch (demod) { \
53 case STV0900_DEMOD_1: \
54 default: \
55 a = b; \
56 break; \
57 case STV0900_DEMOD_2: \
58 a = c; \
59 break; \
60 } \
61 } while (0)
62
63#define dmd_choose(a, b) (demod = STV0900_DEMOD_2 ? b : a))
64
65static int stvdebug;
66
67#define dprintk(args...) \
68 do { \
69 if (stvdebug) \
70 printk(KERN_DEBUG args); \
71 } while (0)
72
73#define STV0900_MAXLOOKUPSIZE 500
74#define STV0900_BLIND_SEARCH_AGC2_TH 700
75
76/* One point of the lookup table */
77struct stv000_lookpoint {
78 s32 realval;/* real value */
79 s32 regval;/* binary value */
80};
81
82/* Lookup table definition */
83struct stv0900_table{
84 s32 size;/* Size of the lookup table */
85 struct stv000_lookpoint table[STV0900_MAXLOOKUPSIZE];/* Lookup table */
86};
87
88enum fe_stv0900_error {
89 STV0900_NO_ERROR = 0,
90 STV0900_INVALID_HANDLE,
91 STV0900_BAD_PARAMETER,
92 STV0900_I2C_ERROR,
93 STV0900_SEARCH_FAILED,
94};
95
96enum fe_stv0900_clock_type {
97 STV0900_USE_REGISTERS_DEFAULT,
98 STV0900_SERIAL_PUNCT_CLOCK,/*Serial punctured clock */
99 STV0900_SERIAL_CONT_CLOCK,/*Serial continues clock */
100 STV0900_PARALLEL_PUNCT_CLOCK,/*Parallel punctured clock */
101 STV0900_DVBCI_CLOCK/*Parallel continues clock : DVBCI */
102};
103
104enum fe_stv0900_search_state {
105 STV0900_SEARCH = 0,
106 STV0900_PLH_DETECTED,
107 STV0900_DVBS2_FOUND,
108 STV0900_DVBS_FOUND
109
110};
111
112enum fe_stv0900_ldpc_state {
113 STV0900_PATH1_OFF_PATH2_OFF = 0,
114 STV0900_PATH1_ON_PATH2_OFF = 1,
115 STV0900_PATH1_OFF_PATH2_ON = 2,
116 STV0900_PATH1_ON_PATH2_ON = 3
117};
118
119enum fe_stv0900_signal_type {
120 STV0900_NOAGC1 = 0,
121 STV0900_AGC1OK,
122 STV0900_NOTIMING,
123 STV0900_ANALOGCARRIER,
124 STV0900_TIMINGOK,
125 STV0900_NOAGC2,
126 STV0900_AGC2OK,
127 STV0900_NOCARRIER,
128 STV0900_CARRIEROK,
129 STV0900_NODATA,
130 STV0900_DATAOK,
131 STV0900_OUTOFRANGE,
132 STV0900_RANGEOK
133};
134
135enum fe_stv0900_demod_num {
136 STV0900_DEMOD_1,
137 STV0900_DEMOD_2
138};
139
140enum fe_stv0900_tracking_standard {
141 STV0900_DVBS1_STANDARD,/* Found Standard*/
142 STV0900_DVBS2_STANDARD,
143 STV0900_DSS_STANDARD,
144 STV0900_TURBOCODE_STANDARD,
145 STV0900_UNKNOWN_STANDARD
146};
147
148enum fe_stv0900_search_standard {
149 STV0900_AUTO_SEARCH,
150 STV0900_SEARCH_DVBS1,/* Search Standard*/
151 STV0900_SEARCH_DVBS2,
152 STV0900_SEARCH_DSS,
153 STV0900_SEARCH_TURBOCODE
154};
155
156enum fe_stv0900_search_algo {
157 STV0900_BLIND_SEARCH,/* offset freq and SR are Unknown */
158 STV0900_COLD_START,/* only the SR is known */
159 STV0900_WARM_START/* offset freq and SR are known */
160};
161
162enum fe_stv0900_modulation {
163 STV0900_QPSK,
164 STV0900_8PSK,
165 STV0900_16APSK,
166 STV0900_32APSK,
167 STV0900_UNKNOWN
168};
169
170enum fe_stv0900_modcode {
171 STV0900_DUMMY_PLF,
172 STV0900_QPSK_14,
173 STV0900_QPSK_13,
174 STV0900_QPSK_25,
175 STV0900_QPSK_12,
176 STV0900_QPSK_35,
177 STV0900_QPSK_23,
178 STV0900_QPSK_34,
179 STV0900_QPSK_45,
180 STV0900_QPSK_56,
181 STV0900_QPSK_89,
182 STV0900_QPSK_910,
183 STV0900_8PSK_35,
184 STV0900_8PSK_23,
185 STV0900_8PSK_34,
186 STV0900_8PSK_56,
187 STV0900_8PSK_89,
188 STV0900_8PSK_910,
189 STV0900_16APSK_23,
190 STV0900_16APSK_34,
191 STV0900_16APSK_45,
192 STV0900_16APSK_56,
193 STV0900_16APSK_89,
194 STV0900_16APSK_910,
195 STV0900_32APSK_34,
196 STV0900_32APSK_45,
197 STV0900_32APSK_56,
198 STV0900_32APSK_89,
199 STV0900_32APSK_910,
200 STV0900_MODCODE_UNKNOWN
201};
202
203enum fe_stv0900_fec {/*DVBS1, DSS and turbo code puncture rate*/
204 STV0900_FEC_1_2 = 0,
205 STV0900_FEC_2_3,
206 STV0900_FEC_3_4,
207 STV0900_FEC_4_5,/*for turbo code only*/
208 STV0900_FEC_5_6,
209 STV0900_FEC_6_7,/*for DSS only */
210 STV0900_FEC_7_8,
211 STV0900_FEC_8_9,/*for turbo code only*/
212 STV0900_FEC_UNKNOWN
213};
214
215enum fe_stv0900_frame_length {
216 STV0900_LONG_FRAME,
217 STV0900_SHORT_FRAME
218};
219
220enum fe_stv0900_pilot {
221 STV0900_PILOTS_OFF,
222 STV0900_PILOTS_ON
223};
224
225enum fe_stv0900_rolloff {
226 STV0900_35,
227 STV0900_25,
228 STV0900_20
229};
230
231enum fe_stv0900_search_iq {
232 STV0900_IQ_AUTO,
233 STV0900_IQ_AUTO_NORMAL_FIRST,
234 STV0900_IQ_FORCE_NORMAL,
235 STV0900_IQ_FORCE_SWAPPED
236};
237
238enum stv0900_iq_inversion {
239 STV0900_IQ_NORMAL,
240 STV0900_IQ_SWAPPED
241};
242
243enum fe_stv0900_diseqc_mode {
244 STV0900_22KHZ_Continues = 0,
245 STV0900_DISEQC_2_3_PWM = 2,
246 STV0900_DISEQC_3_3_PWM = 3,
247 STV0900_DISEQC_2_3_ENVELOP = 4,
248 STV0900_DISEQC_3_3_ENVELOP = 5
249};
250
251enum fe_stv0900_demod_mode {
252 STV0900_SINGLE = 0,
253 STV0900_DUAL
254};
255
256struct stv0900_init_params{
257 u32 dmd_ref_clk;/* Refrence,Input clock for the demod in Hz */
258
259 /* Demodulator Type (single demod or dual demod) */
260 enum fe_stv0900_demod_mode demod_mode;
261 enum fe_stv0900_rolloff rolloff;
262 enum fe_stv0900_clock_type path1_ts_clock;
263
264 u8 tun1_maddress;
265 int tuner1_adc;
266
267 /* IQ from the tuner1 to the demod */
268 enum stv0900_iq_inversion tun1_iq_inversion;
269 enum fe_stv0900_clock_type path2_ts_clock;
270
271 u8 tun2_maddress;
272 int tuner2_adc;
273
274 /* IQ from the tuner2 to the demod */
275 enum stv0900_iq_inversion tun2_iq_inversion;
276};
277
278struct stv0900_search_params {
279 enum fe_stv0900_demod_num path;/* Path Used demod1 or 2 */
280
281 u32 frequency;/* Transponder frequency (in KHz) */
282 u32 symbol_rate;/* Transponder symbol rate (in bds)*/
283 u32 search_range;/* Range of the search (in Hz) */
284
285 enum fe_stv0900_search_standard standard;
286 enum fe_stv0900_modulation modulation;
287 enum fe_stv0900_fec fec;
288 enum fe_stv0900_modcode modcode;
289 enum fe_stv0900_search_iq iq_inversion;
290 enum fe_stv0900_search_algo search_algo;
291
292};
293
294struct stv0900_signal_info {
295 int locked;/* Transponder locked */
296 u32 frequency;/* Transponder frequency (in KHz) */
297 u32 symbol_rate;/* Transponder symbol rate (in Mbds) */
298
299 enum fe_stv0900_tracking_standard standard;
300 enum fe_stv0900_fec fec;
301 enum fe_stv0900_modcode modcode;
302 enum fe_stv0900_modulation modulation;
303 enum fe_stv0900_pilot pilot;
304 enum fe_stv0900_frame_length frame_length;
305 enum stv0900_iq_inversion spectrum;
306 enum fe_stv0900_rolloff rolloff;
307
308 s32 Power;/* Power of the RF signal (dBm) */
309 s32 C_N;/* Carrier to noise ratio (dB x10)*/
310 u32 BER;/* Bit error rate (x10^7) */
311
312};
313
314struct stv0900_internal{
315 s32 quartz;
316 s32 mclk;
317 /* manual RollOff for DVBS1/DSS only */
318 enum fe_stv0900_rolloff rolloff;
319 /* Demodulator use for single demod or for dual demod) */
320 enum fe_stv0900_demod_mode demod_mode;
321
322 /*Demod 1*/
323 s32 tuner1_freq;
324 s32 tuner1_bw;
325 s32 dmd1_symbol_rate;
326 s32 dmd1_srch_range;
327
328 /* algorithm for search Blind, Cold or Warm*/
329 enum fe_stv0900_search_algo dmd1_srch_algo;
330 /* search standard: Auto, DVBS1/DSS only or DVBS2 only*/
331 enum fe_stv0900_search_standard dmd1_srch_standard;
332 /* inversion search : auto, auto norma first, normal or inverted */
333 enum fe_stv0900_search_iq dmd1_srch_iq_inv;
334 enum fe_stv0900_modcode dmd1_modcode;
335 enum fe_stv0900_modulation dmd1_modulation;
336 enum fe_stv0900_fec dmd1_fec;
337
338 struct stv0900_signal_info dmd1_rslts;
339 enum fe_stv0900_signal_type dmd1_state;
340
341 enum fe_stv0900_error dmd1_err;
342
343 /*Demod 2*/
344 s32 tuner2_freq;
345 s32 tuner2_bw;
346 s32 dmd2_symbol_rate;
347 s32 dmd2_srch_range;
348
349 enum fe_stv0900_search_algo dmd2_srch_algo;
350 enum fe_stv0900_search_standard dmd2_srch_stndrd;
351 /* inversion search : auto, auto normal first, normal or inverted */
352 enum fe_stv0900_search_iq dmd2_srch_iq_inv;
353 enum fe_stv0900_modcode dmd2_modcode;
354 enum fe_stv0900_modulation dmd2_modulation;
355 enum fe_stv0900_fec dmd2_fec;
356
357 /* results of the search*/
358 struct stv0900_signal_info dmd2_rslts;
359 /* current state of the search algorithm */
360 enum fe_stv0900_signal_type dmd2_state;
361
362 enum fe_stv0900_error dmd2_err;
363
364 struct i2c_adapter *i2c_adap;
365 u8 i2c_addr;
366 u8 clkmode;/* 0 for CLKI, 2 for XTALI */
367 u8 chip_id;
368 enum fe_stv0900_error errs;
369 int dmds_used;
370};
371
372/* state for each demod */
373struct stv0900_state {
374 /* pointer for internal params, one for each pair of demods */
375 struct stv0900_internal *internal;
376 struct i2c_adapter *i2c_adap;
377 const struct stv0900_config *config;
378 struct dvb_frontend frontend;
379 int demod;
380};
381
382extern s32 ge2comp(s32 a, s32 width);
383
384extern void stv0900_write_reg(struct stv0900_internal *i_params,
385 u16 reg_addr, u8 reg_data);
386
387extern u8 stv0900_read_reg(struct stv0900_internal *i_params,
388 u16 reg_addr);
389
390extern void stv0900_write_bits(struct stv0900_internal *i_params,
391 u32 label, u8 val);
392
393extern u8 stv0900_get_bits(struct stv0900_internal *i_params,
394 u32 label);
395
396extern int stv0900_get_demod_lock(struct stv0900_internal *i_params,
397 enum fe_stv0900_demod_num demod, s32 time_out);
398extern int stv0900_check_signal_presence(struct stv0900_internal *i_params,
399 enum fe_stv0900_demod_num demod);
400
401extern enum fe_stv0900_signal_type stv0900_algo(struct dvb_frontend *fe);
402
403extern void stv0900_set_tuner(struct dvb_frontend *fe, u32 frequency,
404 u32 bandwidth);
405extern void stv0900_set_bandwidth(struct dvb_frontend *fe, u32 bandwidth);
406
407extern void stv0900_start_search(struct stv0900_internal *i_params,
408 enum fe_stv0900_demod_num demod);
409
410extern u8 stv0900_get_optim_carr_loop(s32 srate,
411 enum fe_stv0900_modcode modcode,
412 s32 pilot, u8 chip_id);
413
414extern u8 stv0900_get_optim_short_carr_loop(s32 srate,
415 enum fe_stv0900_modulation modulation,
416 u8 chip_id);
417
418extern void stv0900_stop_all_s2_modcod(struct stv0900_internal *i_params,
419 enum fe_stv0900_demod_num demod);
420
421extern void stv0900_activate_s2_modcode(struct stv0900_internal *i_params,
422 enum fe_stv0900_demod_num demod);
423
424extern void stv0900_activate_s2_modcode_single(struct stv0900_internal *i_params,
425 enum fe_stv0900_demod_num demod);
426
427extern enum fe_stv0900_tracking_standard stv0900_get_standard(struct dvb_frontend *fe,
428 enum fe_stv0900_demod_num demod);
429
430#endif
diff --git a/drivers/media/dvb/frontends/stv0900_reg.h b/drivers/media/dvb/frontends/stv0900_reg.h
new file mode 100644
index 000000000000..264f9cf9a17e
--- /dev/null
+++ b/drivers/media/dvb/frontends/stv0900_reg.h
@@ -0,0 +1,3787 @@
1/*
2 * stv0900_reg.h
3 *
4 * Driver for ST STV0900 satellite demodulator IC.
5 *
6 * Copyright (C) ST Microelectronics.
7 * Copyright (C) 2009 NetUP Inc.
8 * Copyright (C) 2009 Igor M. Liplianin <liplianin@netup.ru>
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 *
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25
26#ifndef STV0900_REG_H
27#define STV0900_REG_H
28
29/*MID*/
30#define R0900_MID 0xf100
31#define F0900_MCHIP_IDENT 0xf10000f0
32#define F0900_MRELEASE 0xf100000f
33
34/*DACR1*/
35#define R0900_DACR1 0xf113
36#define F0900_DAC_MODE 0xf11300e0
37#define F0900_DAC_VALUE1 0xf113000f
38
39/*DACR2*/
40#define R0900_DACR2 0xf114
41#define F0900_DAC_VALUE0 0xf11400ff
42
43/*OUTCFG*/
44#define R0900_OUTCFG 0xf11c
45#define F0900_INV_DATA6 0xf11c0080
46#define F0900_OUTSERRS1_HZ 0xf11c0040
47#define F0900_OUTSERRS2_HZ 0xf11c0020
48#define F0900_OUTSERRS3_HZ 0xf11c0010
49#define F0900_OUTPARRS3_HZ 0xf11c0008
50#define F0900_OUTHZ3_CONTROL 0xf11c0007
51
52/*MODECFG*/
53#define R0900_MODECFG 0xf11d
54#define F0900_FECSPY_SEL_2 0xf11d0020
55#define F0900_HWARE_SEL_2 0xf11d0010
56#define F0900_PKTDEL_SEL_2 0xf11d0008
57#define F0900_DISEQC_SEL_2 0xf11d0004
58#define F0900_VIT_SEL_2 0xf11d0002
59#define F0900_DEMOD_SEL_2 0xf11d0001
60
61/*IRQSTATUS3*/
62#define R0900_IRQSTATUS3 0xf120
63#define F0900_SPLL_LOCK 0xf1200020
64#define F0900_SSTREAM_LCK_3 0xf1200010
65#define F0900_SSTREAM_LCK_2 0xf1200008
66#define F0900_SSTREAM_LCK_1 0xf1200004
67#define F0900_SDVBS1_PRF_2 0xf1200002
68#define F0900_SDVBS1_PRF_1 0xf1200001
69
70/*IRQSTATUS2*/
71#define R0900_IRQSTATUS2 0xf121
72#define F0900_SSPY_ENDSIM_3 0xf1210080
73#define F0900_SSPY_ENDSIM_2 0xf1210040
74#define F0900_SSPY_ENDSIM_1 0xf1210020
75#define F0900_SPKTDEL_ERROR_2 0xf1210010
76#define F0900_SPKTDEL_LOCKB_2 0xf1210008
77#define F0900_SPKTDEL_LOCK_2 0xf1210004
78#define F0900_SPKTDEL_ERROR_1 0xf1210002
79#define F0900_SPKTDEL_LOCKB_1 0xf1210001
80
81/*IRQSTATUS1*/
82#define R0900_IRQSTATUS1 0xf122
83#define F0900_SPKTDEL_LOCK_1 0xf1220080
84#define F0900_SEXTPINB2 0xf1220040
85#define F0900_SEXTPIN2 0xf1220020
86#define F0900_SEXTPINB1 0xf1220010
87#define F0900_SEXTPIN1 0xf1220008
88#define F0900_SDEMOD_LOCKB_2 0xf1220004
89#define F0900_SDEMOD_LOCK_2 0xf1220002
90#define F0900_SDEMOD_IRQ_2 0xf1220001
91
92/*IRQSTATUS0*/
93#define R0900_IRQSTATUS0 0xf123
94#define F0900_SDEMOD_LOCKB_1 0xf1230080
95#define F0900_SDEMOD_LOCK_1 0xf1230040
96#define F0900_SDEMOD_IRQ_1 0xf1230020
97#define F0900_SBCH_ERRFLAG 0xf1230010
98#define F0900_SDISEQC2RX_IRQ 0xf1230008
99#define F0900_SDISEQC2TX_IRQ 0xf1230004
100#define F0900_SDISEQC1RX_IRQ 0xf1230002
101#define F0900_SDISEQC1TX_IRQ 0xf1230001
102
103/*IRQMASK3*/
104#define R0900_IRQMASK3 0xf124
105#define F0900_MPLL_LOCK 0xf1240020
106#define F0900_MSTREAM_LCK_3 0xf1240010
107#define F0900_MSTREAM_LCK_2 0xf1240008
108#define F0900_MSTREAM_LCK_1 0xf1240004
109#define F0900_MDVBS1_PRF_2 0xf1240002
110#define F0900_MDVBS1_PRF_1 0xf1240001
111
112/*IRQMASK2*/
113#define R0900_IRQMASK2 0xf125
114#define F0900_MSPY_ENDSIM_3 0xf1250080
115#define F0900_MSPY_ENDSIM_2 0xf1250040
116#define F0900_MSPY_ENDSIM_1 0xf1250020
117#define F0900_MPKTDEL_ERROR_2 0xf1250010
118#define F0900_MPKTDEL_LOCKB_2 0xf1250008
119#define F0900_MPKTDEL_LOCK_2 0xf1250004
120#define F0900_MPKTDEL_ERROR_1 0xf1250002
121#define F0900_MPKTDEL_LOCKB_1 0xf1250001
122
123/*IRQMASK1*/
124#define R0900_IRQMASK1 0xf126
125#define F0900_MPKTDEL_LOCK_1 0xf1260080
126#define F0900_MEXTPINB2 0xf1260040
127#define F0900_MEXTPIN2 0xf1260020
128#define F0900_MEXTPINB1 0xf1260010
129#define F0900_MEXTPIN1 0xf1260008
130#define F0900_MDEMOD_LOCKB_2 0xf1260004
131#define F0900_MDEMOD_LOCK_2 0xf1260002
132#define F0900_MDEMOD_IRQ_2 0xf1260001
133
134/*IRQMASK0*/
135#define R0900_IRQMASK0 0xf127
136#define F0900_MDEMOD_LOCKB_1 0xf1270080
137#define F0900_MDEMOD_LOCK_1 0xf1270040
138#define F0900_MDEMOD_IRQ_1 0xf1270020
139#define F0900_MBCH_ERRFLAG 0xf1270010
140#define F0900_MDISEQC2RX_IRQ 0xf1270008
141#define F0900_MDISEQC2TX_IRQ 0xf1270004
142#define F0900_MDISEQC1RX_IRQ 0xf1270002
143#define F0900_MDISEQC1TX_IRQ 0xf1270001
144
145/*I2CCFG*/
146#define R0900_I2CCFG 0xf129
147#define F0900_I2C2_FASTMODE 0xf1290080
148#define F0900_STATUS_WR2 0xf1290040
149#define F0900_I2C2ADDR_INC 0xf1290030
150#define F0900_I2C_FASTMODE 0xf1290008
151#define F0900_STATUS_WR 0xf1290004
152#define F0900_I2CADDR_INC 0xf1290003
153
154/*P1_I2CRPT*/
155#define R0900_P1_I2CRPT 0xf12a
156#define F0900_P1_I2CT_ON 0xf12a0080
157#define F0900_P1_ENARPT_LEVEL 0xf12a0070
158#define F0900_P1_SCLT_DELAY 0xf12a0008
159#define F0900_P1_STOP_ENABLE 0xf12a0004
160#define F0900_P1_STOP_SDAT2SDA 0xf12a0002
161
162/*P2_I2CRPT*/
163#define R0900_P2_I2CRPT 0xf12b
164#define F0900_P2_I2CT_ON 0xf12b0080
165#define F0900_P2_ENARPT_LEVEL 0xf12b0070
166#define F0900_P2_SCLT_DELAY 0xf12b0008
167#define F0900_P2_STOP_ENABLE 0xf12b0004
168#define F0900_P2_STOP_SDAT2SDA 0xf12b0002
169
170/*CLKI2CFG*/
171#define R0900_CLKI2CFG 0xf140
172#define F0900_CLKI2_OPD 0xf1400080
173#define F0900_CLKI2_CONFIG 0xf140007e
174#define F0900_CLKI2_XOR 0xf1400001
175
176/*GPIO1CFG*/
177#define R0900_GPIO1CFG 0xf141
178#define F0900_GPIO1_OPD 0xf1410080
179#define F0900_GPIO1_CONFIG 0xf141007e
180#define F0900_GPIO1_XOR 0xf1410001
181
182/*GPIO2CFG*/
183#define R0900_GPIO2CFG 0xf142
184#define F0900_GPIO2_OPD 0xf1420080
185#define F0900_GPIO2_CONFIG 0xf142007e
186#define F0900_GPIO2_XOR 0xf1420001
187
188/*GPIO3CFG*/
189#define R0900_GPIO3CFG 0xf143
190#define F0900_GPIO3_OPD 0xf1430080
191#define F0900_GPIO3_CONFIG 0xf143007e
192#define F0900_GPIO3_XOR 0xf1430001
193
194/*GPIO4CFG*/
195#define R0900_GPIO4CFG 0xf144
196#define F0900_GPIO4_OPD 0xf1440080
197#define F0900_GPIO4_CONFIG 0xf144007e
198#define F0900_GPIO4_XOR 0xf1440001
199
200/*GPIO5CFG*/
201#define R0900_GPIO5CFG 0xf145
202#define F0900_GPIO5_OPD 0xf1450080
203#define F0900_GPIO5_CONFIG 0xf145007e
204#define F0900_GPIO5_XOR 0xf1450001
205
206/*GPIO6CFG*/
207#define R0900_GPIO6CFG 0xf146
208#define F0900_GPIO6_OPD 0xf1460080
209#define F0900_GPIO6_CONFIG 0xf146007e
210#define F0900_GPIO6_XOR 0xf1460001
211
212/*GPIO7CFG*/
213#define R0900_GPIO7CFG 0xf147
214#define F0900_GPIO7_OPD 0xf1470080
215#define F0900_GPIO7_CONFIG 0xf147007e
216#define F0900_GPIO7_XOR 0xf1470001
217
218/*GPIO8CFG*/
219#define R0900_GPIO8CFG 0xf148
220#define F0900_GPIO8_OPD 0xf1480080
221#define F0900_GPIO8_CONFIG 0xf148007e
222#define F0900_GPIO8_XOR 0xf1480001
223
224/*GPIO9CFG*/
225#define R0900_GPIO9CFG 0xf149
226#define F0900_GPIO9_OPD 0xf1490080
227#define F0900_GPIO9_CONFIG 0xf149007e
228#define F0900_GPIO9_XOR 0xf1490001
229
230/*GPIO10CFG*/
231#define R0900_GPIO10CFG 0xf14a
232#define F0900_GPIO10_OPD 0xf14a0080
233#define F0900_GPIO10_CONFIG 0xf14a007e
234#define F0900_GPIO10_XOR 0xf14a0001
235
236/*GPIO11CFG*/
237#define R0900_GPIO11CFG 0xf14b
238#define F0900_GPIO11_OPD 0xf14b0080
239#define F0900_GPIO11_CONFIG 0xf14b007e
240#define F0900_GPIO11_XOR 0xf14b0001
241
242/*GPIO12CFG*/
243#define R0900_GPIO12CFG 0xf14c
244#define F0900_GPIO12_OPD 0xf14c0080
245#define F0900_GPIO12_CONFIG 0xf14c007e
246#define F0900_GPIO12_XOR 0xf14c0001
247
248/*GPIO13CFG*/
249#define R0900_GPIO13CFG 0xf14d
250#define F0900_GPIO13_OPD 0xf14d0080
251#define F0900_GPIO13_CONFIG 0xf14d007e
252#define F0900_GPIO13_XOR 0xf14d0001
253
254/*CS0CFG*/
255#define R0900_CS0CFG 0xf14e
256#define F0900_CS0_OPD 0xf14e0080
257#define F0900_CS0_CONFIG 0xf14e007e
258#define F0900_CS0_XOR 0xf14e0001
259
260/*CS1CFG*/
261#define R0900_CS1CFG 0xf14f
262#define F0900_CS1_OPD 0xf14f0080
263#define F0900_CS1_CONFIG 0xf14f007e
264#define F0900_CS1_XOR 0xf14f0001
265
266/*STDBYCFG*/
267#define R0900_STDBYCFG 0xf150
268#define F0900_STDBY_OPD 0xf1500080
269#define F0900_STDBY_CONFIG 0xf150007e
270#define F0900_STBDY_XOR 0xf1500001
271
272/*DIRCLKCFG*/
273#define R0900_DIRCLKCFG 0xf151
274#define F0900_DIRCLK_OPD 0xf1510080
275#define F0900_DIRCLK_CONFIG 0xf151007e
276#define F0900_DIRCLK_XOR 0xf1510001
277
278/*AGCRF1CFG*/
279#define R0900_AGCRF1CFG 0xf152
280#define F0900_AGCRF1_OPD 0xf1520080
281#define F0900_AGCRF1_CONFIG 0xf152007e
282#define F0900_AGCRF1_XOR 0xf1520001
283
284/*SDAT1CFG*/
285#define R0900_SDAT1CFG 0xf153
286#define F0900_SDAT1_OPD 0xf1530080
287#define F0900_SDAT1_CONFIG 0xf153007e
288#define F0900_SDAT1_XOR 0xf1530001
289
290/*SCLT1CFG*/
291#define R0900_SCLT1CFG 0xf154
292#define F0900_SCLT1_OPD 0xf1540080
293#define F0900_SCLT1_CONFIG 0xf154007e
294#define F0900_SCLT1_XOR 0xf1540001
295
296/*DISEQCO1CFG*/
297#define R0900_DISEQCO1CFG 0xf155
298#define F0900_DISEQCO1_OPD 0xf1550080
299#define F0900_DISEQCO1_CONFIG 0xf155007e
300#define F0900_DISEQC1_XOR 0xf1550001
301
302/*AGCRF2CFG*/
303#define R0900_AGCRF2CFG 0xf156
304#define F0900_AGCRF2_OPD 0xf1560080
305#define F0900_AGCRF2_CONFIG 0xf156007e
306#define F0900_AGCRF2_XOR 0xf1560001
307
308/*SDAT2CFG*/
309#define R0900_SDAT2CFG 0xf157
310#define F0900_SDAT2_OPD 0xf1570080
311#define F0900_SDAT2_CONFIG 0xf157007e
312#define F0900_SDAT2_XOR 0xf1570001
313
314/*SCLT2CFG*/
315#define R0900_SCLT2CFG 0xf158
316#define F0900_SCLT2_OPD 0xf1580080
317#define F0900_SCLT2_CONFIG 0xf158007e
318#define F0900_SCLT2_XOR 0xf1580001
319
320/*DISEQCO2CFG*/
321#define R0900_DISEQCO2CFG 0xf159
322#define F0900_DISEQCO2_OPD 0xf1590080
323#define F0900_DISEQCO2_CONFIG 0xf159007e
324#define F0900_DISEQC2_XOR 0xf1590001
325
326/*CLKOUT27CFG*/
327#define R0900_CLKOUT27CFG 0xf15a
328#define F0900_CLKOUT27_OPD 0xf15a0080
329#define F0900_CLKOUT27_CONFIG 0xf15a007e
330#define F0900_CLKOUT27_XOR 0xf15a0001
331
332/*ERROR1CFG*/
333#define R0900_ERROR1CFG 0xf15b
334#define F0900_ERROR1_OPD 0xf15b0080
335#define F0900_ERROR1_CONFIG 0xf15b007e
336#define F0900_ERROR1_XOR 0xf15b0001
337
338/*DPN1CFG*/
339#define R0900_DPN1CFG 0xf15c
340#define F0900_DPN1_OPD 0xf15c0080
341#define F0900_DPN1_CONFIG 0xf15c007e
342#define F0900_DPN1_XOR 0xf15c0001
343
344/*STROUT1CFG*/
345#define R0900_STROUT1CFG 0xf15d
346#define F0900_STROUT1_OPD 0xf15d0080
347#define F0900_STROUT1_CONFIG 0xf15d007e
348#define F0900_STROUT1_XOR 0xf15d0001
349
350/*CLKOUT1CFG*/
351#define R0900_CLKOUT1CFG 0xf15e
352#define F0900_CLKOUT1_OPD 0xf15e0080
353#define F0900_CLKOUT1_CONFIG 0xf15e007e
354#define F0900_CLKOUT1_XOR 0xf15e0001
355
356/*DATA71CFG*/
357#define R0900_DATA71CFG 0xf15f
358#define F0900_DATA71_OPD 0xf15f0080
359#define F0900_DATA71_CONFIG 0xf15f007e
360#define F0900_DATA71_XOR 0xf15f0001
361
362/*ERROR2CFG*/
363#define R0900_ERROR2CFG 0xf160
364#define F0900_ERROR2_OPD 0xf1600080
365#define F0900_ERROR2_CONFIG 0xf160007e
366#define F0900_ERROR2_XOR 0xf1600001
367
368/*DPN2CFG*/
369#define R0900_DPN2CFG 0xf161
370#define F0900_DPN2_OPD 0xf1610080
371#define F0900_DPN2_CONFIG 0xf161007e
372#define F0900_DPN2_XOR 0xf1610001
373
374/*STROUT2CFG*/
375#define R0900_STROUT2CFG 0xf162
376#define F0900_STROUT2_OPD 0xf1620080
377#define F0900_STROUT2_CONFIG 0xf162007e
378#define F0900_STROUT2_XOR 0xf1620001
379
380/*CLKOUT2CFG*/
381#define R0900_CLKOUT2CFG 0xf163
382#define F0900_CLKOUT2_OPD 0xf1630080
383#define F0900_CLKOUT2_CONFIG 0xf163007e
384#define F0900_CLKOUT2_XOR 0xf1630001
385
386/*DATA72CFG*/
387#define R0900_DATA72CFG 0xf164
388#define F0900_DATA72_OPD 0xf1640080
389#define F0900_DATA72_CONFIG 0xf164007e
390#define F0900_DATA72_XOR 0xf1640001
391
392/*ERROR3CFG*/
393#define R0900_ERROR3CFG 0xf165
394#define F0900_ERROR3_OPD 0xf1650080
395#define F0900_ERROR3_CONFIG 0xf165007e
396#define F0900_ERROR3_XOR 0xf1650001
397
398/*DPN3CFG*/
399#define R0900_DPN3CFG 0xf166
400#define F0900_DPN3_OPD 0xf1660080
401#define F0900_DPN3_CONFIG 0xf166007e
402#define F0900_DPN3_XOR 0xf1660001
403
404/*STROUT3CFG*/
405#define R0900_STROUT3CFG 0xf167
406#define F0900_STROUT3_OPD 0xf1670080
407#define F0900_STROUT3_CONFIG 0xf167007e
408#define F0900_STROUT3_XOR 0xf1670001
409
410/*CLKOUT3CFG*/
411#define R0900_CLKOUT3CFG 0xf168
412#define F0900_CLKOUT3_OPD 0xf1680080
413#define F0900_CLKOUT3_CONFIG 0xf168007e
414#define F0900_CLKOUT3_XOR 0xf1680001
415
416/*DATA73CFG*/
417#define R0900_DATA73CFG 0xf169
418#define F0900_DATA73_OPD 0xf1690080
419#define F0900_DATA73_CONFIG 0xf169007e
420#define F0900_DATA73_XOR 0xf1690001
421
422/*FSKTFC2*/
423#define R0900_FSKTFC2 0xf170
424#define F0900_FSKT_KMOD 0xf17000fc
425#define F0900_FSKT_CAR2 0xf1700003
426
427/*FSKTFC1*/
428#define R0900_FSKTFC1 0xf171
429#define F0900_FSKT_CAR1 0xf17100ff
430
431/*FSKTFC0*/
432#define R0900_FSKTFC0 0xf172
433#define F0900_FSKT_CAR0 0xf17200ff
434
435/*FSKTDELTAF1*/
436#define R0900_FSKTDELTAF1 0xf173
437#define F0900_FSKT_DELTAF1 0xf173000f
438
439/*FSKTDELTAF0*/
440#define R0900_FSKTDELTAF0 0xf174
441#define F0900_FSKT_DELTAF0 0xf17400ff
442
443/*FSKTCTRL*/
444#define R0900_FSKTCTRL 0xf175
445#define F0900_FSKT_EN_SGN 0xf1750040
446#define F0900_FSKT_MOD_SGN 0xf1750020
447#define F0900_FSKT_MOD_EN 0xf175001c
448#define F0900_FSKT_DACMODE 0xf1750003
449
450/*FSKRFC2*/
451#define R0900_FSKRFC2 0xf176
452#define F0900_FSKR_DETSGN 0xf1760040
453#define F0900_FSKR_OUTSGN 0xf1760020
454#define F0900_FSKR_KAGC 0xf176001c
455#define F0900_FSKR_CAR2 0xf1760003
456
457/*FSKRFC1*/
458#define R0900_FSKRFC1 0xf177
459#define F0900_FSKR_CAR1 0xf17700ff
460
461/*FSKRFC0*/
462#define R0900_FSKRFC0 0xf178
463#define F0900_FSKR_CAR0 0xf17800ff
464
465/*FSKRK1*/
466#define R0900_FSKRK1 0xf179
467#define F0900_FSKR_K1_EXP 0xf17900e0
468#define F0900_FSKR_K1_MANT 0xf179001f
469
470/*FSKRK2*/
471#define R0900_FSKRK2 0xf17a
472#define F0900_FSKR_K2_EXP 0xf17a00e0
473#define F0900_FSKR_K2_MANT 0xf17a001f
474
475/*FSKRAGCR*/
476#define R0900_FSKRAGCR 0xf17b
477#define F0900_FSKR_OUTCTL 0xf17b00c0
478#define F0900_FSKR_AGC_REF 0xf17b003f
479
480/*FSKRAGC*/
481#define R0900_FSKRAGC 0xf17c
482#define F0900_FSKR_AGC_ACCU 0xf17c00ff
483
484/*FSKRALPHA*/
485#define R0900_FSKRALPHA 0xf17d
486#define F0900_FSKR_ALPHA_EXP 0xf17d001c
487#define F0900_FSKR_ALPHA_M 0xf17d0003
488
489/*FSKRPLTH1*/
490#define R0900_FSKRPLTH1 0xf17e
491#define F0900_FSKR_BETA 0xf17e00f0
492#define F0900_FSKR_PLL_TRESH1 0xf17e000f
493
494/*FSKRPLTH0*/
495#define R0900_FSKRPLTH0 0xf17f
496#define F0900_FSKR_PLL_TRESH0 0xf17f00ff
497
498/*FSKRDF1*/
499#define R0900_FSKRDF1 0xf180
500#define F0900_FSKR_OUT 0xf1800080
501#define F0900_FSKR_DELTAF1 0xf180001f
502
503/*FSKRDF0*/
504#define R0900_FSKRDF0 0xf181
505#define F0900_FSKR_DELTAF0 0xf18100ff
506
507/*FSKRSTEPP*/
508#define R0900_FSKRSTEPP 0xf182
509#define F0900_FSKR_STEP_PLUS 0xf18200ff
510
511/*FSKRSTEPM*/
512#define R0900_FSKRSTEPM 0xf183
513#define F0900_FSKR_STEP_MINUS 0xf18300ff
514
515/*FSKRDET1*/
516#define R0900_FSKRDET1 0xf184
517#define F0900_FSKR_DETECT 0xf1840080
518#define F0900_FSKR_CARDET_ACCU1 0xf184000f
519
520/*FSKRDET0*/
521#define R0900_FSKRDET0 0xf185
522#define F0900_FSKR_CARDET_ACCU0 0xf18500ff
523
524/*FSKRDTH1*/
525#define R0900_FSKRDTH1 0xf186
526#define F0900_FSKR_CARLOSS_THRESH1 0xf18600f0
527#define F0900_FSKR_CARDET_THRESH1 0xf186000f
528
529/*FSKRDTH0*/
530#define R0900_FSKRDTH0 0xf187
531#define F0900_FSKR_CARDET_THRESH0 0xf18700ff
532
533/*FSKRLOSS*/
534#define R0900_FSKRLOSS 0xf188
535#define F0900_FSKR_CARLOSS_THRESH0 0xf18800ff
536
537/*P2_DISTXCTL*/
538#define R0900_P2_DISTXCTL 0xf190
539#define F0900_P2_TIM_OFF 0xf1900080
540#define F0900_P2_DISEQC_RESET 0xf1900040
541#define F0900_P2_TIM_CMD 0xf1900030
542#define F0900_P2_DIS_PRECHARGE 0xf1900008
543#define F0900_P2_DISTX_MODE 0xf1900007
544
545/*P2_DISRXCTL*/
546#define R0900_P2_DISRXCTL 0xf191
547#define F0900_P2_RECEIVER_ON 0xf1910080
548#define F0900_P2_IGNO_SHORT22K 0xf1910040
549#define F0900_P2_ONECHIP_TRX 0xf1910020
550#define F0900_P2_EXT_ENVELOP 0xf1910010
551#define F0900_P2_PIN_SELECT 0xf191000c
552#define F0900_P2_IRQ_RXEND 0xf1910002
553#define F0900_P2_IRQ_4NBYTES 0xf1910001
554
555/*P2_DISRX_ST0*/
556#define R0900_P2_DISRX_ST0 0xf194
557#define F0900_P2_RX_END 0xf1940080
558#define F0900_P2_RX_ACTIVE 0xf1940040
559#define F0900_P2_SHORT_22KHZ 0xf1940020
560#define F0900_P2_CONT_TONE 0xf1940010
561#define F0900_P2_FIFO_4BREADY 0xf1940008
562#define F0900_P2_FIFO_EMPTY 0xf1940004
563#define F0900_P2_ABORT_DISRX 0xf1940001
564
565/*P2_DISRX_ST1*/
566#define R0900_P2_DISRX_ST1 0xf195
567#define F0900_P2_RX_FAIL 0xf1950080
568#define F0900_P2_FIFO_PARITYFAIL 0xf1950040
569#define F0900_P2_RX_NONBYTE 0xf1950020
570#define F0900_P2_FIFO_OVERFLOW 0xf1950010
571#define F0900_P2_FIFO_BYTENBR 0xf195000f
572
573/*P2_DISRXDATA*/
574#define R0900_P2_DISRXDATA 0xf196
575#define F0900_P2_DISRX_DATA 0xf19600ff
576
577/*P2_DISTXDATA*/
578#define R0900_P2_DISTXDATA 0xf197
579#define F0900_P2_DISEQC_FIFO 0xf19700ff
580
581/*P2_DISTXSTATUS*/
582#define R0900_P2_DISTXSTATUS 0xf198
583#define F0900_P2_TX_FAIL 0xf1980080
584#define F0900_P2_FIFO_FULL 0xf1980040
585#define F0900_P2_TX_IDLE 0xf1980020
586#define F0900_P2_GAP_BURST 0xf1980010
587#define F0900_P2_TXFIFO_BYTES 0xf198000f
588
589/*P2_F22TX*/
590#define R0900_P2_F22TX 0xf199
591#define F0900_P2_F22_REG 0xf19900ff
592
593/*P2_F22RX*/
594#define R0900_P2_F22RX 0xf19a
595#define F0900_P2_F22RX_REG 0xf19a00ff
596
597/*P2_ACRPRESC*/
598#define R0900_P2_ACRPRESC 0xf19c
599#define F0900_P2_ACR_CODFRDY 0xf19c0008
600#define F0900_P2_ACR_PRESC 0xf19c0007
601
602/*P2_ACRDIV*/
603#define R0900_P2_ACRDIV 0xf19d
604#define F0900_P2_ACR_DIV 0xf19d00ff
605
606/*P1_DISTXCTL*/
607#define R0900_P1_DISTXCTL 0xf1a0
608#define F0900_P1_TIM_OFF 0xf1a00080
609#define F0900_P1_DISEQC_RESET 0xf1a00040
610#define F0900_P1_TIM_CMD 0xf1a00030
611#define F0900_P1_DIS_PRECHARGE 0xf1a00008
612#define F0900_P1_DISTX_MODE 0xf1a00007
613
614/*P1_DISRXCTL*/
615#define R0900_P1_DISRXCTL 0xf1a1
616#define F0900_P1_RECEIVER_ON 0xf1a10080
617#define F0900_P1_IGNO_SHORT22K 0xf1a10040
618#define F0900_P1_ONECHIP_TRX 0xf1a10020
619#define F0900_P1_EXT_ENVELOP 0xf1a10010
620#define F0900_P1_PIN_SELECT 0xf1a1000c
621#define F0900_P1_IRQ_RXEND 0xf1a10002
622#define F0900_P1_IRQ_4NBYTES 0xf1a10001
623
624/*P1_DISRX_ST0*/
625#define R0900_P1_DISRX_ST0 0xf1a4
626#define F0900_P1_RX_END 0xf1a40080
627#define F0900_P1_RX_ACTIVE 0xf1a40040
628#define F0900_P1_SHORT_22KHZ 0xf1a40020
629#define F0900_P1_CONT_TONE 0xf1a40010
630#define F0900_P1_FIFO_4BREADY 0xf1a40008
631#define F0900_P1_FIFO_EMPTY 0xf1a40004
632#define F0900_P1_ABORT_DISRX 0xf1a40001
633
634/*P1_DISRX_ST1*/
635#define R0900_P1_DISRX_ST1 0xf1a5
636#define F0900_P1_RX_FAIL 0xf1a50080
637#define F0900_P1_FIFO_PARITYFAIL 0xf1a50040
638#define F0900_P1_RX_NONBYTE 0xf1a50020
639#define F0900_P1_FIFO_OVERFLOW 0xf1a50010
640#define F0900_P1_FIFO_BYTENBR 0xf1a5000f
641
642/*P1_DISRXDATA*/
643#define R0900_P1_DISRXDATA 0xf1a6
644#define F0900_P1_DISRX_DATA 0xf1a600ff
645
646/*P1_DISTXDATA*/
647#define R0900_P1_DISTXDATA 0xf1a7
648#define F0900_P1_DISEQC_FIFO 0xf1a700ff
649
650/*P1_DISTXSTATUS*/
651#define R0900_P1_DISTXSTATUS 0xf1a8
652#define F0900_P1_TX_FAIL 0xf1a80080
653#define F0900_P1_FIFO_FULL 0xf1a80040
654#define F0900_P1_TX_IDLE 0xf1a80020
655#define F0900_P1_GAP_BURST 0xf1a80010
656#define F0900_P1_TXFIFO_BYTES 0xf1a8000f
657
658/*P1_F22TX*/
659#define R0900_P1_F22TX 0xf1a9
660#define F0900_P1_F22_REG 0xf1a900ff
661
662/*P1_F22RX*/
663#define R0900_P1_F22RX 0xf1aa
664#define F0900_P1_F22RX_REG 0xf1aa00ff
665
666/*P1_ACRPRESC*/
667#define R0900_P1_ACRPRESC 0xf1ac
668#define F0900_P1_ACR_CODFRDY 0xf1ac0008
669#define F0900_P1_ACR_PRESC 0xf1ac0007
670
671/*P1_ACRDIV*/
672#define R0900_P1_ACRDIV 0xf1ad
673#define F0900_P1_ACR_DIV 0xf1ad00ff
674
675/*NCOARSE*/
676#define R0900_NCOARSE 0xf1b3
677#define F0900_M_DIV 0xf1b300ff
678
679/*SYNTCTRL*/
680#define R0900_SYNTCTRL 0xf1b6
681#define F0900_STANDBY 0xf1b60080
682#define F0900_BYPASSPLLCORE 0xf1b60040
683#define F0900_SELX1RATIO 0xf1b60020
684#define F0900_I2C_TUD 0xf1b60010
685#define F0900_STOP_PLL 0xf1b60008
686#define F0900_BYPASSPLLFSK 0xf1b60004
687#define F0900_SELOSCI 0xf1b60002
688#define F0900_BYPASSPLLADC 0xf1b60001
689
690/*FILTCTRL*/
691#define R0900_FILTCTRL 0xf1b7
692#define F0900_INV_CLK135 0xf1b70080
693#define F0900_PERM_BYPDIS 0xf1b70040
694#define F0900_SEL_FSKCKDIV 0xf1b70004
695#define F0900_INV_CLKFSK 0xf1b70002
696#define F0900_BYPASS_APPLI 0xf1b70001
697
698/*PLLSTAT*/
699#define R0900_PLLSTAT 0xf1b8
700#define F0900_ACM_SEL 0xf1b80080
701#define F0900_DTV_SEL 0xf1b80040
702#define F0900_PLLLOCK 0xf1b80001
703
704/*STOPCLK1*/
705#define R0900_STOPCLK1 0xf1c2
706#define F0900_STOP_CLKPKDT2 0xf1c20040
707#define F0900_STOP_CLKPKDT1 0xf1c20020
708#define F0900_STOP_CLKFEC 0xf1c20010
709#define F0900_STOP_CLKADCI2 0xf1c20008
710#define F0900_INV_CLKADCI2 0xf1c20004
711#define F0900_STOP_CLKADCI1 0xf1c20002
712#define F0900_INV_CLKADCI1 0xf1c20001
713
714/*STOPCLK2*/
715#define R0900_STOPCLK2 0xf1c3
716#define F0900_STOP_CLKSAMP2 0xf1c30010
717#define F0900_STOP_CLKSAMP1 0xf1c30008
718#define F0900_STOP_CLKVIT2 0xf1c30004
719#define F0900_STOP_CLKVIT1 0xf1c30002
720#define F0900_STOP_CLKTS 0xf1c30001
721
722/*TSTTNR0*/
723#define R0900_TSTTNR0 0xf1df
724#define F0900_SEL_FSK 0xf1df0080
725#define F0900_FSK_PON 0xf1df0004
726#define F0900_FSK_OPENLOOP 0xf1df0002
727
728/*TSTTNR1*/
729#define R0900_TSTTNR1 0xf1e0
730#define F0900_BYPASS_ADC1 0xf1e00080
731#define F0900_INVADC1_CKOUT 0xf1e00040
732#define F0900_SELIQSRC1 0xf1e00030
733#define F0900_ADC1_PON 0xf1e00002
734#define F0900_ADC1_INMODE 0xf1e00001
735
736/*TSTTNR2*/
737#define R0900_TSTTNR2 0xf1e1
738#define F0900_DISEQC1_PON 0xf1e10020
739#define F0900_DISEQC1_TEST 0xf1e1001f
740
741/*TSTTNR3*/
742#define R0900_TSTTNR3 0xf1e2
743#define F0900_BYPASS_ADC2 0xf1e20080
744#define F0900_INVADC2_CKOUT 0xf1e20040
745#define F0900_SELIQSRC2 0xf1e20030
746#define F0900_ADC2_PON 0xf1e20002
747#define F0900_ADC2_INMODE 0xf1e20001
748
749/*TSTTNR4*/
750#define R0900_TSTTNR4 0xf1e3
751#define F0900_DISEQC2_PON 0xf1e30020
752#define F0900_DISEQC2_TEST 0xf1e3001f
753
754/*P2_IQCONST*/
755#define R0900_P2_IQCONST 0xf200
756#define F0900_P2_CONSTEL_SELECT 0xf2000060
757#define F0900_P2_IQSYMB_SEL 0xf200001f
758
759/*P2_NOSCFG*/
760#define R0900_P2_NOSCFG 0xf201
761#define F0900_P2_DUMMYPL_NOSDATA 0xf2010020
762#define F0900_P2_NOSPLH_BETA 0xf2010018
763#define F0900_P2_NOSDATA_BETA 0xf2010007
764
765/*P2_ISYMB*/
766#define R0900_P2_ISYMB 0xf202
767#define F0900_P2_I_SYMBOL 0xf20201ff
768
769/*P2_QSYMB*/
770#define R0900_P2_QSYMB 0xf203
771#define F0900_P2_Q_SYMBOL 0xf20301ff
772
773/*P2_AGC1CFG*/
774#define R0900_P2_AGC1CFG 0xf204
775#define F0900_P2_DC_FROZEN 0xf2040080
776#define F0900_P2_DC_CORRECT 0xf2040040
777#define F0900_P2_AMM_FROZEN 0xf2040020
778#define F0900_P2_AMM_CORRECT 0xf2040010
779#define F0900_P2_QUAD_FROZEN 0xf2040008
780#define F0900_P2_QUAD_CORRECT 0xf2040004
781#define F0900_P2_DCCOMP_SLOW 0xf2040002
782#define F0900_P2_IQMISM_SLOW 0xf2040001
783
784/*P2_AGC1CN*/
785#define R0900_P2_AGC1CN 0xf206
786#define F0900_P2_AGC1_LOCKED 0xf2060080
787#define F0900_P2_AGC1_OVERFLOW 0xf2060040
788#define F0900_P2_AGC1_NOSLOWLK 0xf2060020
789#define F0900_P2_AGC1_MINPOWER 0xf2060010
790#define F0900_P2_AGCOUT_FAST 0xf2060008
791#define F0900_P2_AGCIQ_BETA 0xf2060007
792
793/*P2_AGC1REF*/
794#define R0900_P2_AGC1REF 0xf207
795#define F0900_P2_AGCIQ_REF 0xf20700ff
796
797/*P2_IDCCOMP*/
798#define R0900_P2_IDCCOMP 0xf208
799#define F0900_P2_IAVERAGE_ADJ 0xf20801ff
800
801/*P2_QDCCOMP*/
802#define R0900_P2_QDCCOMP 0xf209
803#define F0900_P2_QAVERAGE_ADJ 0xf20901ff
804
805/*P2_POWERI*/
806#define R0900_P2_POWERI 0xf20a
807#define F0900_P2_POWER_I 0xf20a00ff
808
809/*P2_POWERQ*/
810#define R0900_P2_POWERQ 0xf20b
811#define F0900_P2_POWER_Q 0xf20b00ff
812
813/*P2_AGC1AMM*/
814#define R0900_P2_AGC1AMM 0xf20c
815#define F0900_P2_AMM_VALUE 0xf20c00ff
816
817/*P2_AGC1QUAD*/
818#define R0900_P2_AGC1QUAD 0xf20d
819#define F0900_P2_QUAD_VALUE 0xf20d01ff
820
821/*P2_AGCIQIN1*/
822#define R0900_P2_AGCIQIN1 0xf20e
823#define F0900_P2_AGCIQ_VALUE1 0xf20e00ff
824
825/*P2_AGCIQIN0*/
826#define R0900_P2_AGCIQIN0 0xf20f
827#define F0900_P2_AGCIQ_VALUE0 0xf20f00ff
828
829/*P2_DEMOD*/
830#define R0900_P2_DEMOD 0xf210
831#define F0900_P2_DEMOD_STOP 0xf2100040
832#define F0900_P2_SPECINV_CONTROL 0xf2100030
833#define F0900_P2_FORCE_ENASAMP 0xf2100008
834#define F0900_P2_MANUAL_ROLLOFF 0xf2100004
835#define F0900_P2_ROLLOFF_CONTROL 0xf2100003
836
837/*P2_DMDMODCOD*/
838#define R0900_P2_DMDMODCOD 0xf211
839#define F0900_P2_MANUAL_MODCOD 0xf2110080
840#define F0900_P2_DEMOD_MODCOD 0xf211007c
841#define F0900_P2_DEMOD_TYPE 0xf2110003
842
843/*P2_DSTATUS*/
844#define R0900_P2_DSTATUS 0xf212
845#define F0900_P2_CAR_LOCK 0xf2120080
846#define F0900_P2_TMGLOCK_QUALITY 0xf2120060
847#define F0900_P2_SDVBS1_ENABLE 0xf2120010
848#define F0900_P2_LOCK_DEFINITIF 0xf2120008
849#define F0900_P2_TIMING_IS_LOCKED 0xf2120004
850#define F0900_P2_COARSE_TMGLOCK 0xf2120002
851#define F0900_P2_COARSE_CARLOCK 0xf2120001
852
853/*P2_DSTATUS2*/
854#define R0900_P2_DSTATUS2 0xf213
855#define F0900_P2_DEMOD_DELOCK 0xf2130080
856#define F0900_P2_DEMOD_TIMEOUT 0xf2130040
857#define F0900_P2_MODCODRQ_SYNCTAG 0xf2130020
858#define F0900_P2_POLYPH_SATEVENT 0xf2130010
859#define F0900_P2_AGC1_NOSIGNALACK 0xf2130008
860#define F0900_P2_AGC2_OVERFLOW 0xf2130004
861#define F0900_P2_CFR_OVERFLOW 0xf2130002
862#define F0900_P2_GAMMA_OVERUNDER 0xf2130001
863
864/*P2_DMDCFGMD*/
865#define R0900_P2_DMDCFGMD 0xf214
866#define F0900_P2_DVBS2_ENABLE 0xf2140080
867#define F0900_P2_DVBS1_ENABLE 0xf2140040
868#define F0900_P2_CFR_AUTOSCAN 0xf2140020
869#define F0900_P2_SCAN_ENABLE 0xf2140010
870#define F0900_P2_TUN_AUTOSCAN 0xf2140008
871#define F0900_P2_NOFORCE_RELOCK 0xf2140004
872#define F0900_P2_TUN_RNG 0xf2140003
873
874/*P2_DMDCFG2*/
875#define R0900_P2_DMDCFG2 0xf215
876#define F0900_P2_AGC1_WAITLOCK 0xf2150080
877#define F0900_P2_S1S2_SEQUENTIAL 0xf2150040
878#define F0900_P2_OVERFLOW_TIMEOUT 0xf2150020
879#define F0900_P2_SCANFAIL_TIMEOUT 0xf2150010
880#define F0900_P2_DMDTOUT_BACK 0xf2150008
881#define F0900_P2_CARLOCK_S1ENABLE 0xf2150004
882#define F0900_P2_COARSE_LK3MODE 0xf2150002
883#define F0900_P2_COARSE_LK2MODE 0xf2150001
884
885/*P2_DMDISTATE*/
886#define R0900_P2_DMDISTATE 0xf216
887#define F0900_P2_I2C_NORESETDMODE 0xf2160080
888#define F0900_P2_FORCE_ETAPED 0xf2160040
889#define F0900_P2_SDMDRST_DIRCLK 0xf2160020
890#define F0900_P2_I2C_DEMOD_MODE 0xf216001f
891
892/*P2_DMDT0M*/
893#define R0900_P2_DMDT0M 0xf217
894#define F0900_P2_DMDT0_MIN 0xf21700ff
895
896/*P2_DMDSTATE*/
897#define R0900_P2_DMDSTATE 0xf21b
898#define F0900_P2_DEMOD_LOCKED 0xf21b0080
899#define F0900_P2_HEADER_MODE 0xf21b0060
900#define F0900_P2_DEMOD_MODE 0xf21b001f
901
902/*P2_DMDFLYW*/
903#define R0900_P2_DMDFLYW 0xf21c
904#define F0900_P2_I2C_IRQVAL 0xf21c00f0
905#define F0900_P2_FLYWHEEL_CPT 0xf21c000f
906
907/*P2_DSTATUS3*/
908#define R0900_P2_DSTATUS3 0xf21d
909#define F0900_P2_CFR_ZIGZAG 0xf21d0080
910#define F0900_P2_DEMOD_CFGMODE 0xf21d0060
911#define F0900_P2_GAMMA_LOWBAUDRATE 0xf21d0010
912#define F0900_P2_RELOCK_MODE 0xf21d0008
913#define F0900_P2_DEMOD_FAIL 0xf21d0004
914#define F0900_P2_ETAPE1A_DVBXMEM 0xf21d0003
915
916/*P2_DMDCFG3*/
917#define R0900_P2_DMDCFG3 0xf21e
918#define F0900_P2_DVBS1_TMGWAIT 0xf21e0080
919#define F0900_P2_NO_BWCENTERING 0xf21e0040
920#define F0900_P2_INV_SEQSRCH 0xf21e0020
921#define F0900_P2_DIS_SFRUPLOW_TRK 0xf21e0010
922#define F0900_P2_NOSTOP_FIFOFULL 0xf21e0008
923#define F0900_P2_LOCKTIME_MODE 0xf21e0007
924
925/*P2_DMDCFG4*/
926#define R0900_P2_DMDCFG4 0xf21f
927#define F0900_P2_TUNER_NRELAUNCH 0xf21f0008
928#define F0900_P2_DIS_CLKENABLE 0xf21f0004
929#define F0900_P2_DIS_HDRDIVLOCK 0xf21f0002
930#define F0900_P2_NO_TNRWBINIT 0xf21f0001
931
932/*P2_CORRELMANT*/
933#define R0900_P2_CORRELMANT 0xf220
934#define F0900_P2_CORREL_MANT 0xf22000ff
935
936/*P2_CORRELABS*/
937#define R0900_P2_CORRELABS 0xf221
938#define F0900_P2_CORREL_ABS 0xf22100ff
939
940/*P2_CORRELEXP*/
941#define R0900_P2_CORRELEXP 0xf222
942#define F0900_P2_CORREL_ABSEXP 0xf22200f0
943#define F0900_P2_CORREL_EXP 0xf222000f
944
945/*P2_PLHMODCOD*/
946#define R0900_P2_PLHMODCOD 0xf224
947#define F0900_P2_SPECINV_DEMOD 0xf2240080
948#define F0900_P2_PLH_MODCOD 0xf224007c
949#define F0900_P2_PLH_TYPE 0xf2240003
950
951/*P2_AGCK32*/
952#define R0900_P2_AGCK32 0xf22b
953#define F0900_P2_R3ADJOFF_32APSK 0xf22b0080
954#define F0900_P2_R2ADJOFF_32APSK 0xf22b0040
955#define F0900_P2_R1ADJOFF_32APSK 0xf22b0020
956#define F0900_P2_RADJ_32APSK 0xf22b001f
957
958/*P2_AGC2O*/
959#define R0900_P2_AGC2O 0xf22c
960#define F0900_P2_AGC2REF_ADJUSTING 0xf22c0080
961#define F0900_P2_AGC2_COARSEFAST 0xf22c0040
962#define F0900_P2_AGC2_LKSQRT 0xf22c0020
963#define F0900_P2_AGC2_LKMODE 0xf22c0010
964#define F0900_P2_AGC2_LKEQUA 0xf22c0008
965#define F0900_P2_AGC2_COEF 0xf22c0007
966
967/*P2_AGC2REF*/
968#define R0900_P2_AGC2REF 0xf22d
969#define F0900_P2_AGC2_REF 0xf22d00ff
970
971/*P2_AGC1ADJ*/
972#define R0900_P2_AGC1ADJ 0xf22e
973#define F0900_P2_AGC1ADJ_MANUAL 0xf22e0080
974#define F0900_P2_AGC1_ADJUSTED 0xf22e017f
975
976/*P2_AGC2I1*/
977#define R0900_P2_AGC2I1 0xf236
978#define F0900_P2_AGC2_INTEGRATOR1 0xf23600ff
979
980/*P2_AGC2I0*/
981#define R0900_P2_AGC2I0 0xf237
982#define F0900_P2_AGC2_INTEGRATOR0 0xf23700ff
983
984/*P2_CARCFG*/
985#define R0900_P2_CARCFG 0xf238
986#define F0900_P2_CFRUPLOW_AUTO 0xf2380080
987#define F0900_P2_CFRUPLOW_TEST 0xf2380040
988#define F0900_P2_EN_CAR2CENTER 0xf2380020
989#define F0900_P2_CARHDR_NODIV8 0xf2380010
990#define F0900_P2_I2C_ROTA 0xf2380008
991#define F0900_P2_ROTAON 0xf2380004
992#define F0900_P2_PH_DET_ALGO 0xf2380003
993
994/*P2_ACLC*/
995#define R0900_P2_ACLC 0xf239
996#define F0900_P2_STOP_S2ALPHA 0xf23900c0
997#define F0900_P2_CAR_ALPHA_MANT 0xf2390030
998#define F0900_P2_CAR_ALPHA_EXP 0xf239000f
999
1000/*P2_BCLC*/
1001#define R0900_P2_BCLC 0xf23a
1002#define F0900_P2_STOP_S2BETA 0xf23a00c0
1003#define F0900_P2_CAR_BETA_MANT 0xf23a0030
1004#define F0900_P2_CAR_BETA_EXP 0xf23a000f
1005
1006/*P2_CARFREQ*/
1007#define R0900_P2_CARFREQ 0xf23d
1008#define F0900_P2_KC_COARSE_EXP 0xf23d00f0
1009#define F0900_P2_BETA_FREQ 0xf23d000f
1010
1011/*P2_CARHDR*/
1012#define R0900_P2_CARHDR 0xf23e
1013#define F0900_P2_K_FREQ_HDR 0xf23e00ff
1014
1015/*P2_LDT*/
1016#define R0900_P2_LDT 0xf23f
1017#define F0900_P2_CARLOCK_THRES 0xf23f01ff
1018
1019/*P2_LDT2*/
1020#define R0900_P2_LDT2 0xf240
1021#define F0900_P2_CARLOCK_THRES2 0xf24001ff
1022
1023/*P2_CFRICFG*/
1024#define R0900_P2_CFRICFG 0xf241
1025#define F0900_P2_CFRINIT_UNVALRNG 0xf2410080
1026#define F0900_P2_CFRINIT_LUNVALCPT 0xf2410040
1027#define F0900_P2_CFRINIT_ABORTDBL 0xf2410020
1028#define F0900_P2_CFRINIT_ABORTPRED 0xf2410010
1029#define F0900_P2_CFRINIT_UNVALSKIP 0xf2410008
1030#define F0900_P2_CFRINIT_CSTINC 0xf2410004
1031#define F0900_P2_NEG_CFRSTEP 0xf2410001
1032
1033/*P2_CFRUP1*/
1034#define R0900_P2_CFRUP1 0xf242
1035#define F0900_P2_CFR_UP1 0xf24201ff
1036
1037/*P2_CFRUP0*/
1038#define R0900_P2_CFRUP0 0xf243
1039#define F0900_P2_CFR_UP0 0xf24300ff
1040
1041/*P2_CFRLOW1*/
1042#define R0900_P2_CFRLOW1 0xf246
1043#define F0900_P2_CFR_LOW1 0xf24601ff
1044
1045/*P2_CFRLOW0*/
1046#define R0900_P2_CFRLOW0 0xf247
1047#define F0900_P2_CFR_LOW0 0xf24700ff
1048
1049/*P2_CFRINIT1*/
1050#define R0900_P2_CFRINIT1 0xf248
1051#define F0900_P2_CFR_INIT1 0xf24801ff
1052
1053/*P2_CFRINIT0*/
1054#define R0900_P2_CFRINIT0 0xf249
1055#define F0900_P2_CFR_INIT0 0xf24900ff
1056
1057/*P2_CFRINC1*/
1058#define R0900_P2_CFRINC1 0xf24a
1059#define F0900_P2_MANUAL_CFRINC 0xf24a0080
1060#define F0900_P2_CFR_INC1 0xf24a017f
1061
1062/*P2_CFRINC0*/
1063#define R0900_P2_CFRINC0 0xf24b
1064#define F0900_P2_CFR_INC0 0xf24b00f0
1065
1066/*P2_CFR2*/
1067#define R0900_P2_CFR2 0xf24c
1068#define F0900_P2_CAR_FREQ2 0xf24c01ff
1069
1070/*P2_CFR1*/
1071#define R0900_P2_CFR1 0xf24d
1072#define F0900_P2_CAR_FREQ1 0xf24d00ff
1073
1074/*P2_CFR0*/
1075#define R0900_P2_CFR0 0xf24e
1076#define F0900_P2_CAR_FREQ0 0xf24e00ff
1077
1078/*P2_LDI*/
1079#define R0900_P2_LDI 0xf24f
1080#define F0900_P2_LOCK_DET_INTEGR 0xf24f01ff
1081
1082/*P2_TMGCFG*/
1083#define R0900_P2_TMGCFG 0xf250
1084#define F0900_P2_TMGLOCK_BETA 0xf25000c0
1085#define F0900_P2_NOTMG_GROUPDELAY 0xf2500020
1086#define F0900_P2_DO_TIMING_CORR 0xf2500010
1087#define F0900_P2_MANUAL_SCAN 0xf250000c
1088#define F0900_P2_TMG_MINFREQ 0xf2500003
1089
1090/*P2_RTC*/
1091#define R0900_P2_RTC 0xf251
1092#define F0900_P2_TMGALPHA_EXP 0xf25100f0
1093#define F0900_P2_TMGBETA_EXP 0xf251000f
1094
1095/*P2_RTCS2*/
1096#define R0900_P2_RTCS2 0xf252
1097#define F0900_P2_TMGALPHAS2_EXP 0xf25200f0
1098#define F0900_P2_TMGBETAS2_EXP 0xf252000f
1099
1100/*P2_TMGTHRISE*/
1101#define R0900_P2_TMGTHRISE 0xf253
1102#define F0900_P2_TMGLOCK_THRISE 0xf25300ff
1103
1104/*P2_TMGTHFALL*/
1105#define R0900_P2_TMGTHFALL 0xf254
1106#define F0900_P2_TMGLOCK_THFALL 0xf25400ff
1107
1108/*P2_SFRUPRATIO*/
1109#define R0900_P2_SFRUPRATIO 0xf255
1110#define F0900_P2_SFR_UPRATIO 0xf25500ff
1111
1112/*P2_SFRLOWRATIO*/
1113#define R0900_P2_SFRLOWRATIO 0xf256
1114#define F0900_P2_SFR_LOWRATIO 0xf25600ff
1115
1116/*P2_KREFTMG*/
1117#define R0900_P2_KREFTMG 0xf258
1118#define F0900_P2_KREF_TMG 0xf25800ff
1119
1120/*P2_SFRSTEP*/
1121#define R0900_P2_SFRSTEP 0xf259
1122#define F0900_P2_SFR_SCANSTEP 0xf25900f0
1123#define F0900_P2_SFR_CENTERSTEP 0xf259000f
1124
1125/*P2_TMGCFG2*/
1126#define R0900_P2_TMGCFG2 0xf25a
1127#define F0900_P2_DIS_AUTOSAMP 0xf25a0008
1128#define F0900_P2_SCANINIT_QUART 0xf25a0004
1129#define F0900_P2_NOTMG_DVBS1DERAT 0xf25a0002
1130#define F0900_P2_SFRRATIO_FINE 0xf25a0001
1131
1132/*P2_SFRINIT1*/
1133#define R0900_P2_SFRINIT1 0xf25e
1134#define F0900_P2_SFR_INIT1 0xf25e00ff
1135
1136/*P2_SFRINIT0*/
1137#define R0900_P2_SFRINIT0 0xf25f
1138#define F0900_P2_SFR_INIT0 0xf25f00ff
1139
1140/*P2_SFRUP1*/
1141#define R0900_P2_SFRUP1 0xf260
1142#define F0900_P2_AUTO_GUP 0xf2600080
1143#define F0900_P2_SYMB_FREQ_UP1 0xf260007f
1144
1145/*P2_SFRUP0*/
1146#define R0900_P2_SFRUP0 0xf261
1147#define F0900_P2_SYMB_FREQ_UP0 0xf26100ff
1148
1149/*P2_SFRLOW1*/
1150#define R0900_P2_SFRLOW1 0xf262
1151#define F0900_P2_AUTO_GLOW 0xf2620080
1152#define F0900_P2_SYMB_FREQ_LOW1 0xf262007f
1153
1154/*P2_SFRLOW0*/
1155#define R0900_P2_SFRLOW0 0xf263
1156#define F0900_P2_SYMB_FREQ_LOW0 0xf26300ff
1157
1158/*P2_SFR3*/
1159#define R0900_P2_SFR3 0xf264
1160#define F0900_P2_SYMB_FREQ3 0xf26400ff
1161
1162/*P2_SFR2*/
1163#define R0900_P2_SFR2 0xf265
1164#define F0900_P2_SYMB_FREQ2 0xf26500ff
1165
1166/*P2_SFR1*/
1167#define R0900_P2_SFR1 0xf266
1168#define F0900_P2_SYMB_FREQ1 0xf26600ff
1169
1170/*P2_SFR0*/
1171#define R0900_P2_SFR0 0xf267
1172#define F0900_P2_SYMB_FREQ0 0xf26700ff
1173
1174/*P2_TMGREG2*/
1175#define R0900_P2_TMGREG2 0xf268
1176#define F0900_P2_TMGREG2 0xf26800ff
1177
1178/*P2_TMGREG1*/
1179#define R0900_P2_TMGREG1 0xf269
1180#define F0900_P2_TMGREG1 0xf26900ff
1181
1182/*P2_TMGREG0*/
1183#define R0900_P2_TMGREG0 0xf26a
1184#define F0900_P2_TMGREG0 0xf26a00ff
1185
1186/*P2_TMGLOCK1*/
1187#define R0900_P2_TMGLOCK1 0xf26b
1188#define F0900_P2_TMGLOCK_LEVEL1 0xf26b01ff
1189
1190/*P2_TMGLOCK0*/
1191#define R0900_P2_TMGLOCK0 0xf26c
1192#define F0900_P2_TMGLOCK_LEVEL0 0xf26c00ff
1193
1194/*P2_TMGOBS*/
1195#define R0900_P2_TMGOBS 0xf26d
1196#define F0900_P2_ROLLOFF_STATUS 0xf26d00c0
1197#define F0900_P2_SCAN_SIGN 0xf26d0030
1198#define F0900_P2_TMG_SCANNING 0xf26d0008
1199#define F0900_P2_CHCENTERING_MODE 0xf26d0004
1200#define F0900_P2_TMG_SCANFAIL 0xf26d0002
1201
1202/*P2_EQUALCFG*/
1203#define R0900_P2_EQUALCFG 0xf26f
1204#define F0900_P2_NOTMG_NEGALWAIT 0xf26f0080
1205#define F0900_P2_EQUAL_ON 0xf26f0040
1206#define F0900_P2_SEL_EQUALCOR 0xf26f0038
1207#define F0900_P2_MU_EQUALDFE 0xf26f0007
1208
1209/*P2_EQUAI1*/
1210#define R0900_P2_EQUAI1 0xf270
1211#define F0900_P2_EQUA_ACCI1 0xf27001ff
1212
1213/*P2_EQUAQ1*/
1214#define R0900_P2_EQUAQ1 0xf271
1215#define F0900_P2_EQUA_ACCQ1 0xf27101ff
1216
1217/*P2_EQUAI2*/
1218#define R0900_P2_EQUAI2 0xf272
1219#define F0900_P2_EQUA_ACCI2 0xf27201ff
1220
1221/*P2_EQUAQ2*/
1222#define R0900_P2_EQUAQ2 0xf273
1223#define F0900_P2_EQUA_ACCQ2 0xf27301ff
1224
1225/*P2_EQUAI3*/
1226#define R0900_P2_EQUAI3 0xf274
1227#define F0900_P2_EQUA_ACCI3 0xf27401ff
1228
1229/*P2_EQUAQ3*/
1230#define R0900_P2_EQUAQ3 0xf275
1231#define F0900_P2_EQUA_ACCQ3 0xf27501ff
1232
1233/*P2_EQUAI4*/
1234#define R0900_P2_EQUAI4 0xf276
1235#define F0900_P2_EQUA_ACCI4 0xf27601ff
1236
1237/*P2_EQUAQ4*/
1238#define R0900_P2_EQUAQ4 0xf277
1239#define F0900_P2_EQUA_ACCQ4 0xf27701ff
1240
1241/*P2_EQUAI5*/
1242#define R0900_P2_EQUAI5 0xf278
1243#define F0900_P2_EQUA_ACCI5 0xf27801ff
1244
1245/*P2_EQUAQ5*/
1246#define R0900_P2_EQUAQ5 0xf279
1247#define F0900_P2_EQUA_ACCQ5 0xf27901ff
1248
1249/*P2_EQUAI6*/
1250#define R0900_P2_EQUAI6 0xf27a
1251#define F0900_P2_EQUA_ACCI6 0xf27a01ff
1252
1253/*P2_EQUAQ6*/
1254#define R0900_P2_EQUAQ6 0xf27b
1255#define F0900_P2_EQUA_ACCQ6 0xf27b01ff
1256
1257/*P2_EQUAI7*/
1258#define R0900_P2_EQUAI7 0xf27c
1259#define F0900_P2_EQUA_ACCI7 0xf27c01ff
1260
1261/*P2_EQUAQ7*/
1262#define R0900_P2_EQUAQ7 0xf27d
1263#define F0900_P2_EQUA_ACCQ7 0xf27d01ff
1264
1265/*P2_EQUAI8*/
1266#define R0900_P2_EQUAI8 0xf27e
1267#define F0900_P2_EQUA_ACCI8 0xf27e01ff
1268
1269/*P2_EQUAQ8*/
1270#define R0900_P2_EQUAQ8 0xf27f
1271#define F0900_P2_EQUA_ACCQ8 0xf27f01ff
1272
1273/*P2_NNOSDATAT1*/
1274#define R0900_P2_NNOSDATAT1 0xf280
1275#define F0900_P2_NOSDATAT_NORMED1 0xf28000ff
1276
1277/*P2_NNOSDATAT0*/
1278#define R0900_P2_NNOSDATAT0 0xf281
1279#define F0900_P2_NOSDATAT_NORMED0 0xf28100ff
1280
1281/*P2_NNOSDATA1*/
1282#define R0900_P2_NNOSDATA1 0xf282
1283#define F0900_P2_NOSDATA_NORMED1 0xf28200ff
1284
1285/*P2_NNOSDATA0*/
1286#define R0900_P2_NNOSDATA0 0xf283
1287#define F0900_P2_NOSDATA_NORMED0 0xf28300ff
1288
1289/*P2_NNOSPLHT1*/
1290#define R0900_P2_NNOSPLHT1 0xf284
1291#define F0900_P2_NOSPLHT_NORMED1 0xf28400ff
1292
1293/*P2_NNOSPLHT0*/
1294#define R0900_P2_NNOSPLHT0 0xf285
1295#define F0900_P2_NOSPLHT_NORMED0 0xf28500ff
1296
1297/*P2_NNOSPLH1*/
1298#define R0900_P2_NNOSPLH1 0xf286
1299#define F0900_P2_NOSPLH_NORMED1 0xf28600ff
1300
1301/*P2_NNOSPLH0*/
1302#define R0900_P2_NNOSPLH0 0xf287
1303#define F0900_P2_NOSPLH_NORMED0 0xf28700ff
1304
1305/*P2_NOSDATAT1*/
1306#define R0900_P2_NOSDATAT1 0xf288
1307#define F0900_P2_NOSDATAT_UNNORMED1 0xf28800ff
1308
1309/*P2_NOSDATAT0*/
1310#define R0900_P2_NOSDATAT0 0xf289
1311#define F0900_P2_NOSDATAT_UNNORMED0 0xf28900ff
1312
1313/*P2_NOSDATA1*/
1314#define R0900_P2_NOSDATA1 0xf28a
1315#define F0900_P2_NOSDATA_UNNORMED1 0xf28a00ff
1316
1317/*P2_NOSDATA0*/
1318#define R0900_P2_NOSDATA0 0xf28b
1319#define F0900_P2_NOSDATA_UNNORMED0 0xf28b00ff
1320
1321/*P2_NOSPLHT1*/
1322#define R0900_P2_NOSPLHT1 0xf28c
1323#define F0900_P2_NOSPLHT_UNNORMED1 0xf28c00ff
1324
1325/*P2_NOSPLHT0*/
1326#define R0900_P2_NOSPLHT0 0xf28d
1327#define F0900_P2_NOSPLHT_UNNORMED0 0xf28d00ff
1328
1329/*P2_NOSPLH1*/
1330#define R0900_P2_NOSPLH1 0xf28e
1331#define F0900_P2_NOSPLH_UNNORMED1 0xf28e00ff
1332
1333/*P2_NOSPLH0*/
1334#define R0900_P2_NOSPLH0 0xf28f
1335#define F0900_P2_NOSPLH_UNNORMED0 0xf28f00ff
1336
1337/*P2_CAR2CFG*/
1338#define R0900_P2_CAR2CFG 0xf290
1339#define F0900_P2_DESCRAMB_OFF 0xf2900080
1340#define F0900_P2_PN4_SELECT 0xf2900040
1341#define F0900_P2_CFR2_STOPDVBS1 0xf2900020
1342#define F0900_P2_STOP_CFR2UPDATE 0xf2900010
1343#define F0900_P2_STOP_NCO2UPDATE 0xf2900008
1344#define F0900_P2_ROTA2ON 0xf2900004
1345#define F0900_P2_PH_DET_ALGO2 0xf2900003
1346
1347/*P2_ACLC2*/
1348#define R0900_P2_ACLC2 0xf291
1349#define F0900_P2_CAR2_PUNCT_ADERAT 0xf2910040
1350#define F0900_P2_CAR2_ALPHA_MANT 0xf2910030
1351#define F0900_P2_CAR2_ALPHA_EXP 0xf291000f
1352
1353/*P2_BCLC2*/
1354#define R0900_P2_BCLC2 0xf292
1355#define F0900_P2_DVBS2_NIP 0xf2920080
1356#define F0900_P2_CAR2_PUNCT_BDERAT 0xf2920040
1357#define F0900_P2_CAR2_BETA_MANT 0xf2920030
1358#define F0900_P2_CAR2_BETA_EXP 0xf292000f
1359
1360/*P2_CFR22*/
1361#define R0900_P2_CFR22 0xf293
1362#define F0900_P2_CAR2_FREQ2 0xf29301ff
1363
1364/*P2_CFR21*/
1365#define R0900_P2_CFR21 0xf294
1366#define F0900_P2_CAR2_FREQ1 0xf29400ff
1367
1368/*P2_CFR20*/
1369#define R0900_P2_CFR20 0xf295
1370#define F0900_P2_CAR2_FREQ0 0xf29500ff
1371
1372/*P2_ACLC2S2Q*/
1373#define R0900_P2_ACLC2S2Q 0xf297
1374#define F0900_P2_ENAB_SPSKSYMB 0xf2970080
1375#define F0900_P2_CAR2S2_QADERAT 0xf2970040
1376#define F0900_P2_CAR2S2_Q_ALPH_M 0xf2970030
1377#define F0900_P2_CAR2S2_Q_ALPH_E 0xf297000f
1378
1379/*P2_ACLC2S28*/
1380#define R0900_P2_ACLC2S28 0xf298
1381#define F0900_P2_OLDI3Q_MODE 0xf2980080
1382#define F0900_P2_CAR2S2_8ADERAT 0xf2980040
1383#define F0900_P2_CAR2S2_8_ALPH_M 0xf2980030
1384#define F0900_P2_CAR2S2_8_ALPH_E 0xf298000f
1385
1386/*P2_ACLC2S216A*/
1387#define R0900_P2_ACLC2S216A 0xf299
1388#define F0900_P2_CAR2S2_16ADERAT 0xf2990040
1389#define F0900_P2_CAR2S2_16A_ALPH_M 0xf2990030
1390#define F0900_P2_CAR2S2_16A_ALPH_E 0xf299000f
1391
1392/*P2_ACLC2S232A*/
1393#define R0900_P2_ACLC2S232A 0xf29a
1394#define F0900_P2_CAR2S2_32ADERAT 0xf29a0040
1395#define F0900_P2_CAR2S2_32A_ALPH_M 0xf29a0030
1396#define F0900_P2_CAR2S2_32A_ALPH_E 0xf29a000f
1397
1398/*P2_BCLC2S2Q*/
1399#define R0900_P2_BCLC2S2Q 0xf29c
1400#define F0900_P2_DVBS2S2Q_NIP 0xf29c0080
1401#define F0900_P2_CAR2S2_QBDERAT 0xf29c0040
1402#define F0900_P2_CAR2S2_Q_BETA_M 0xf29c0030
1403#define F0900_P2_CAR2S2_Q_BETA_E 0xf29c000f
1404
1405/*P2_BCLC2S28*/
1406#define R0900_P2_BCLC2S28 0xf29d
1407#define F0900_P2_DVBS2S28_NIP 0xf29d0080
1408#define F0900_P2_CAR2S2_8BDERAT 0xf29d0040
1409#define F0900_P2_CAR2S2_8_BETA_M 0xf29d0030
1410#define F0900_P2_CAR2S2_8_BETA_E 0xf29d000f
1411
1412/*P2_BCLC2S216A*/
1413#define R0900_P2_BCLC2S216A 0xf29e
1414#define F0900_P2_DVBS2S216A_NIP 0xf29e0080
1415#define F0900_P2_CAR2S2_16BDERAT 0xf29e0040
1416#define F0900_P2_CAR2S2_16A_BETA_M 0xf29e0030
1417#define F0900_P2_CAR2S2_16A_BETA_E 0xf29e000f
1418
1419/*P2_BCLC2S232A*/
1420#define R0900_P2_BCLC2S232A 0xf29f
1421#define F0900_P2_DVBS2S232A_NIP 0xf29f0080
1422#define F0900_P2_CAR2S2_32BDERAT 0xf29f0040
1423#define F0900_P2_CAR2S2_32A_BETA_M 0xf29f0030
1424#define F0900_P2_CAR2S2_32A_BETA_E 0xf29f000f
1425
1426/*P2_PLROOT2*/
1427#define R0900_P2_PLROOT2 0xf2ac
1428#define F0900_P2_SHORTFR_DISABLE 0xf2ac0080
1429#define F0900_P2_LONGFR_DISABLE 0xf2ac0040
1430#define F0900_P2_DUMMYPL_DISABLE 0xf2ac0020
1431#define F0900_P2_SHORTFR_AVOID 0xf2ac0010
1432#define F0900_P2_PLSCRAMB_MODE 0xf2ac000c
1433#define F0900_P2_PLSCRAMB_ROOT2 0xf2ac0003
1434
1435/*P2_PLROOT1*/
1436#define R0900_P2_PLROOT1 0xf2ad
1437#define F0900_P2_PLSCRAMB_ROOT1 0xf2ad00ff
1438
1439/*P2_PLROOT0*/
1440#define R0900_P2_PLROOT0 0xf2ae
1441#define F0900_P2_PLSCRAMB_ROOT0 0xf2ae00ff
1442
1443/*P2_MODCODLST0*/
1444#define R0900_P2_MODCODLST0 0xf2b0
1445#define F0900_P2_EN_TOKEN31 0xf2b00080
1446#define F0900_P2_SYNCTAG_SELECT 0xf2b00040
1447#define F0900_P2_MODCODRQ_MODE 0xf2b00030
1448
1449/*P2_MODCODLST1*/
1450#define R0900_P2_MODCODLST1 0xf2b1
1451#define F0900_P2_DIS_MODCOD29 0xf2b100f0
1452#define F0900_P2_DIS_32PSK_9_10 0xf2b1000f
1453
1454/*P2_MODCODLST2*/
1455#define R0900_P2_MODCODLST2 0xf2b2
1456#define F0900_P2_DIS_32PSK_8_9 0xf2b200f0
1457#define F0900_P2_DIS_32PSK_5_6 0xf2b2000f
1458
1459/*P2_MODCODLST3*/
1460#define R0900_P2_MODCODLST3 0xf2b3
1461#define F0900_P2_DIS_32PSK_4_5 0xf2b300f0
1462#define F0900_P2_DIS_32PSK_3_4 0xf2b3000f
1463
1464/*P2_MODCODLST4*/
1465#define R0900_P2_MODCODLST4 0xf2b4
1466#define F0900_P2_DIS_16PSK_9_10 0xf2b400f0
1467#define F0900_P2_DIS_16PSK_8_9 0xf2b4000f
1468
1469/*P2_MODCODLST5*/
1470#define R0900_P2_MODCODLST5 0xf2b5
1471#define F0900_P2_DIS_16PSK_5_6 0xf2b500f0
1472#define F0900_P2_DIS_16PSK_4_5 0xf2b5000f
1473
1474/*P2_MODCODLST6*/
1475#define R0900_P2_MODCODLST6 0xf2b6
1476#define F0900_P2_DIS_16PSK_3_4 0xf2b600f0
1477#define F0900_P2_DIS_16PSK_2_3 0xf2b6000f
1478
1479/*P2_MODCODLST7*/
1480#define R0900_P2_MODCODLST7 0xf2b7
1481#define F0900_P2_DIS_8P_9_10 0xf2b700f0
1482#define F0900_P2_DIS_8P_8_9 0xf2b7000f
1483
1484/*P2_MODCODLST8*/
1485#define R0900_P2_MODCODLST8 0xf2b8
1486#define F0900_P2_DIS_8P_5_6 0xf2b800f0
1487#define F0900_P2_DIS_8P_3_4 0xf2b8000f
1488
1489/*P2_MODCODLST9*/
1490#define R0900_P2_MODCODLST9 0xf2b9
1491#define F0900_P2_DIS_8P_2_3 0xf2b900f0
1492#define F0900_P2_DIS_8P_3_5 0xf2b9000f
1493
1494/*P2_MODCODLSTA*/
1495#define R0900_P2_MODCODLSTA 0xf2ba
1496#define F0900_P2_DIS_QP_9_10 0xf2ba00f0
1497#define F0900_P2_DIS_QP_8_9 0xf2ba000f
1498
1499/*P2_MODCODLSTB*/
1500#define R0900_P2_MODCODLSTB 0xf2bb
1501#define F0900_P2_DIS_QP_5_6 0xf2bb00f0
1502#define F0900_P2_DIS_QP_4_5 0xf2bb000f
1503
1504/*P2_MODCODLSTC*/
1505#define R0900_P2_MODCODLSTC 0xf2bc
1506#define F0900_P2_DIS_QP_3_4 0xf2bc00f0
1507#define F0900_P2_DIS_QP_2_3 0xf2bc000f
1508
1509/*P2_MODCODLSTD*/
1510#define R0900_P2_MODCODLSTD 0xf2bd
1511#define F0900_P2_DIS_QP_3_5 0xf2bd00f0
1512#define F0900_P2_DIS_QP_1_2 0xf2bd000f
1513
1514/*P2_MODCODLSTE*/
1515#define R0900_P2_MODCODLSTE 0xf2be
1516#define F0900_P2_DIS_QP_2_5 0xf2be00f0
1517#define F0900_P2_DIS_QP_1_3 0xf2be000f
1518
1519/*P2_MODCODLSTF*/
1520#define R0900_P2_MODCODLSTF 0xf2bf
1521#define F0900_P2_DIS_QP_1_4 0xf2bf00f0
1522#define F0900_P2_DDEMOD_SET 0xf2bf0002
1523#define F0900_P2_DDEMOD_MASK 0xf2bf0001
1524
1525/*P2_DMDRESCFG*/
1526#define R0900_P2_DMDRESCFG 0xf2c6
1527#define F0900_P2_DMDRES_RESET 0xf2c60080
1528#define F0900_P2_DMDRES_NOISESQR 0xf2c60010
1529#define F0900_P2_DMDRES_STRALL 0xf2c60008
1530#define F0900_P2_DMDRES_NEWONLY 0xf2c60004
1531#define F0900_P2_DMDRES_NOSTORE 0xf2c60002
1532#define F0900_P2_DMDRES_AGC2MEM 0xf2c60001
1533
1534/*P2_DMDRESADR*/
1535#define R0900_P2_DMDRESADR 0xf2c7
1536#define F0900_P2_SUSP_PREDCANAL 0xf2c70080
1537#define F0900_P2_DMDRES_VALIDCFR 0xf2c70040
1538#define F0900_P2_DMDRES_MEMFULL 0xf2c70030
1539#define F0900_P2_DMDRES_RESNBR 0xf2c7000f
1540
1541/*P2_DMDRESDATA7*/
1542#define R0900_P2_DMDRESDATA7 0xf2c8
1543#define F0900_P2_DMDRES_DATA7 0xf2c800ff
1544
1545/*P2_DMDRESDATA6*/
1546#define R0900_P2_DMDRESDATA6 0xf2c9
1547#define F0900_P2_DMDRES_DATA6 0xf2c900ff
1548
1549/*P2_DMDRESDATA5*/
1550#define R0900_P2_DMDRESDATA5 0xf2ca
1551#define F0900_P2_DMDRES_DATA5 0xf2ca00ff
1552
1553/*P2_DMDRESDATA4*/
1554#define R0900_P2_DMDRESDATA4 0xf2cb
1555#define F0900_P2_DMDRES_DATA4 0xf2cb00ff
1556
1557/*P2_DMDRESDATA3*/
1558#define R0900_P2_DMDRESDATA3 0xf2cc
1559#define F0900_P2_DMDRES_DATA3 0xf2cc00ff
1560
1561/*P2_DMDRESDATA2*/
1562#define R0900_P2_DMDRESDATA2 0xf2cd
1563#define F0900_P2_DMDRES_DATA2 0xf2cd00ff
1564
1565/*P2_DMDRESDATA1*/
1566#define R0900_P2_DMDRESDATA1 0xf2ce
1567#define F0900_P2_DMDRES_DATA1 0xf2ce00ff
1568
1569/*P2_DMDRESDATA0*/
1570#define R0900_P2_DMDRESDATA0 0xf2cf
1571#define F0900_P2_DMDRES_DATA0 0xf2cf00ff
1572
1573/*P2_FFEI1*/
1574#define R0900_P2_FFEI1 0xf2d0
1575#define F0900_P2_FFE_ACCI1 0xf2d001ff
1576
1577/*P2_FFEQ1*/
1578#define R0900_P2_FFEQ1 0xf2d1
1579#define F0900_P2_FFE_ACCQ1 0xf2d101ff
1580
1581/*P2_FFEI2*/
1582#define R0900_P2_FFEI2 0xf2d2
1583#define F0900_P2_FFE_ACCI2 0xf2d201ff
1584
1585/*P2_FFEQ2*/
1586#define R0900_P2_FFEQ2 0xf2d3
1587#define F0900_P2_FFE_ACCQ2 0xf2d301ff
1588
1589/*P2_FFEI3*/
1590#define R0900_P2_FFEI3 0xf2d4
1591#define F0900_P2_FFE_ACCI3 0xf2d401ff
1592
1593/*P2_FFEQ3*/
1594#define R0900_P2_FFEQ3 0xf2d5
1595#define F0900_P2_FFE_ACCQ3 0xf2d501ff
1596
1597/*P2_FFEI4*/
1598#define R0900_P2_FFEI4 0xf2d6
1599#define F0900_P2_FFE_ACCI4 0xf2d601ff
1600
1601/*P2_FFEQ4*/
1602#define R0900_P2_FFEQ4 0xf2d7
1603#define F0900_P2_FFE_ACCQ4 0xf2d701ff
1604
1605/*P2_FFECFG*/
1606#define R0900_P2_FFECFG 0xf2d8
1607#define F0900_P2_EQUALFFE_ON 0xf2d80040
1608#define F0900_P2_EQUAL_USEDSYMB 0xf2d80030
1609#define F0900_P2_MU_EQUALFFE 0xf2d80007
1610
1611/*P2_TNRCFG*/
1612#define R0900_P2_TNRCFG 0xf2e0
1613#define F0900_P2_TUN_ACKFAIL 0xf2e00080
1614#define F0900_P2_TUN_TYPE 0xf2e00070
1615#define F0900_P2_TUN_SECSTOP 0xf2e00008
1616#define F0900_P2_TUN_VCOSRCH 0xf2e00004
1617#define F0900_P2_TUN_MADDRESS 0xf2e00003
1618
1619/*P2_TNRCFG2*/
1620#define R0900_P2_TNRCFG2 0xf2e1
1621#define F0900_P2_TUN_IQSWAP 0xf2e10080
1622#define F0900_P2_STB6110_STEP2MHZ 0xf2e10040
1623#define F0900_P2_STB6120_DBLI2C 0xf2e10020
1624#define F0900_P2_DIS_FCCK 0xf2e10010
1625#define F0900_P2_DIS_LPEN 0xf2e10008
1626#define F0900_P2_DIS_BWCALC 0xf2e10004
1627#define F0900_P2_SHORT_WAITSTATES 0xf2e10002
1628#define F0900_P2_DIS_2BWAGC1 0xf2e10001
1629
1630/*P2_TNRXTAL*/
1631#define R0900_P2_TNRXTAL 0xf2e4
1632#define F0900_P2_TUN_MCLKDECIMAL 0xf2e400e0
1633#define F0900_P2_TUN_XTALFREQ 0xf2e4001f
1634
1635/*P2_TNRSTEPS*/
1636#define R0900_P2_TNRSTEPS 0xf2e7
1637#define F0900_P2_TUNER_BW1P6 0xf2e70080
1638#define F0900_P2_BWINC_OFFSET 0xf2e70070
1639#define F0900_P2_SOFTSTEP_RNG 0xf2e70008
1640#define F0900_P2_TUN_BWOFFSET 0xf2e70107
1641
1642/*P2_TNRGAIN*/
1643#define R0900_P2_TNRGAIN 0xf2e8
1644#define F0900_P2_TUN_KDIVEN 0xf2e800c0
1645#define F0900_P2_STB6X00_OCK 0xf2e80030
1646#define F0900_P2_TUN_GAIN 0xf2e8000f
1647
1648/*P2_TNRRF1*/
1649#define R0900_P2_TNRRF1 0xf2e9
1650#define F0900_P2_TUN_RFFREQ2 0xf2e900ff
1651
1652/*P2_TNRRF0*/
1653#define R0900_P2_TNRRF0 0xf2ea
1654#define F0900_P2_TUN_RFFREQ1 0xf2ea00ff
1655
1656/*P2_TNRBW*/
1657#define R0900_P2_TNRBW 0xf2eb
1658#define F0900_P2_TUN_RFFREQ0 0xf2eb00c0
1659#define F0900_P2_TUN_BW 0xf2eb003f
1660
1661/*P2_TNRADJ*/
1662#define R0900_P2_TNRADJ 0xf2ec
1663#define F0900_P2_STB61X0_RCLK 0xf2ec0080
1664#define F0900_P2_STB61X0_CALTIME 0xf2ec0040
1665#define F0900_P2_STB6X00_DLB 0xf2ec0038
1666#define F0900_P2_STB6000_FCL 0xf2ec0007
1667
1668/*P2_TNRCTL2*/
1669#define R0900_P2_TNRCTL2 0xf2ed
1670#define F0900_P2_STB61X0_LCP1_RCCKOFF 0xf2ed0080
1671#define F0900_P2_STB61X0_LCP0 0xf2ed0040
1672#define F0900_P2_STB61X0_XTOUT_RFOUTS 0xf2ed0020
1673#define F0900_P2_STB61X0_XTON_MCKDV 0xf2ed0010
1674#define F0900_P2_STB61X0_CALOFF_DCOFF 0xf2ed0008
1675#define F0900_P2_STB6110_LPT 0xf2ed0004
1676#define F0900_P2_STB6110_RX 0xf2ed0002
1677#define F0900_P2_STB6110_SYN 0xf2ed0001
1678
1679/*P2_TNRCFG3*/
1680#define R0900_P2_TNRCFG3 0xf2ee
1681#define F0900_P2_STB6120_DISCTRL1 0xf2ee0080
1682#define F0900_P2_STB6120_INVORDER 0xf2ee0040
1683#define F0900_P2_STB6120_ENCTRL6 0xf2ee0020
1684#define F0900_P2_TUN_PLLFREQ 0xf2ee001c
1685#define F0900_P2_TUN_I2CFREQ_MODE 0xf2ee0003
1686
1687/*P2_TNRLAUNCH*/
1688#define R0900_P2_TNRLAUNCH 0xf2f0
1689
1690/*P2_TNRLD*/
1691#define R0900_P2_TNRLD 0xf2f0
1692#define F0900_P2_TUNLD_VCOING 0xf2f00080
1693#define F0900_P2_TUN_REG1FAIL 0xf2f00040
1694#define F0900_P2_TUN_REG2FAIL 0xf2f00020
1695#define F0900_P2_TUN_REG3FAIL 0xf2f00010
1696#define F0900_P2_TUN_REG4FAIL 0xf2f00008
1697#define F0900_P2_TUN_REG5FAIL 0xf2f00004
1698#define F0900_P2_TUN_BWING 0xf2f00002
1699#define F0900_P2_TUN_LOCKED 0xf2f00001
1700
1701/*P2_TNROBSL*/
1702#define R0900_P2_TNROBSL 0xf2f6
1703#define F0900_P2_TUN_I2CABORTED 0xf2f60080
1704#define F0900_P2_TUN_LPEN 0xf2f60040
1705#define F0900_P2_TUN_FCCK 0xf2f60020
1706#define F0900_P2_TUN_I2CLOCKED 0xf2f60010
1707#define F0900_P2_TUN_PROGDONE 0xf2f6000c
1708#define F0900_P2_TUN_RFRESTE1 0xf2f60003
1709
1710/*P2_TNRRESTE*/
1711#define R0900_P2_TNRRESTE 0xf2f7
1712#define F0900_P2_TUN_RFRESTE0 0xf2f700ff
1713
1714/*P2_SMAPCOEF7*/
1715#define R0900_P2_SMAPCOEF7 0xf300
1716#define F0900_P2_DIS_QSCALE 0xf3000080
1717#define F0900_P2_SMAPCOEF_Q_LLR12 0xf300017f
1718
1719/*P2_SMAPCOEF6*/
1720#define R0900_P2_SMAPCOEF6 0xf301
1721#define F0900_P2_DIS_NEWSCALE 0xf3010008
1722#define F0900_P2_ADJ_8PSKLLR1 0xf3010004
1723#define F0900_P2_OLD_8PSKLLR1 0xf3010002
1724#define F0900_P2_DIS_AB8PSK 0xf3010001
1725
1726/*P2_SMAPCOEF5*/
1727#define R0900_P2_SMAPCOEF5 0xf302
1728#define F0900_P2_DIS_8SCALE 0xf3020080
1729#define F0900_P2_SMAPCOEF_8P_LLR23 0xf302017f
1730
1731/*P2_DMDPLHSTAT*/
1732#define R0900_P2_DMDPLHSTAT 0xf320
1733#define F0900_P2_PLH_STATISTIC 0xf32000ff
1734
1735/*P2_LOCKTIME3*/
1736#define R0900_P2_LOCKTIME3 0xf322
1737#define F0900_P2_DEMOD_LOCKTIME3 0xf32200ff
1738
1739/*P2_LOCKTIME2*/
1740#define R0900_P2_LOCKTIME2 0xf323
1741#define F0900_P2_DEMOD_LOCKTIME2 0xf32300ff
1742
1743/*P2_LOCKTIME1*/
1744#define R0900_P2_LOCKTIME1 0xf324
1745#define F0900_P2_DEMOD_LOCKTIME1 0xf32400ff
1746
1747/*P2_LOCKTIME0*/
1748#define R0900_P2_LOCKTIME0 0xf325
1749#define F0900_P2_DEMOD_LOCKTIME0 0xf32500ff
1750
1751/*P2_VITSCALE*/
1752#define R0900_P2_VITSCALE 0xf332
1753#define F0900_P2_NVTH_NOSRANGE 0xf3320080
1754#define F0900_P2_VERROR_MAXMODE 0xf3320040
1755#define F0900_P2_KDIV_MODE 0xf3320030
1756#define F0900_P2_NSLOWSN_LOCKED 0xf3320008
1757#define F0900_P2_DELOCK_PRFLOSS 0xf3320004
1758#define F0900_P2_DIS_RSFLOCK 0xf3320002
1759
1760/*P2_FECM*/
1761#define R0900_P2_FECM 0xf333
1762#define F0900_P2_DSS_DVB 0xf3330080
1763#define F0900_P2_DEMOD_BYPASS 0xf3330040
1764#define F0900_P2_CMP_SLOWMODE 0xf3330020
1765#define F0900_P2_DSS_SRCH 0xf3330010
1766#define F0900_P2_DIFF_MODEVIT 0xf3330004
1767#define F0900_P2_SYNCVIT 0xf3330002
1768#define F0900_P2_IQINV 0xf3330001
1769
1770/*P2_VTH12*/
1771#define R0900_P2_VTH12 0xf334
1772#define F0900_P2_VTH12 0xf33400ff
1773
1774/*P2_VTH23*/
1775#define R0900_P2_VTH23 0xf335
1776#define F0900_P2_VTH23 0xf33500ff
1777
1778/*P2_VTH34*/
1779#define R0900_P2_VTH34 0xf336
1780#define F0900_P2_VTH34 0xf33600ff
1781
1782/*P2_VTH56*/
1783#define R0900_P2_VTH56 0xf337
1784#define F0900_P2_VTH56 0xf33700ff
1785
1786/*P2_VTH67*/
1787#define R0900_P2_VTH67 0xf338
1788#define F0900_P2_VTH67 0xf33800ff
1789
1790/*P2_VTH78*/
1791#define R0900_P2_VTH78 0xf339
1792#define F0900_P2_VTH78 0xf33900ff
1793
1794/*P2_VITCURPUN*/
1795#define R0900_P2_VITCURPUN 0xf33a
1796#define F0900_P2_VIT_MAPPING 0xf33a00e0
1797#define F0900_P2_VIT_CURPUN 0xf33a001f
1798
1799/*P2_VERROR*/
1800#define R0900_P2_VERROR 0xf33b
1801#define F0900_P2_REGERR_VIT 0xf33b00ff
1802
1803/*P2_PRVIT*/
1804#define R0900_P2_PRVIT 0xf33c
1805#define F0900_P2_DIS_VTHLOCK 0xf33c0040
1806#define F0900_P2_E7_8VIT 0xf33c0020
1807#define F0900_P2_E6_7VIT 0xf33c0010
1808#define F0900_P2_E5_6VIT 0xf33c0008
1809#define F0900_P2_E3_4VIT 0xf33c0004
1810#define F0900_P2_E2_3VIT 0xf33c0002
1811#define F0900_P2_E1_2VIT 0xf33c0001
1812
1813/*P2_VAVSRVIT*/
1814#define R0900_P2_VAVSRVIT 0xf33d
1815#define F0900_P2_AMVIT 0xf33d0080
1816#define F0900_P2_FROZENVIT 0xf33d0040
1817#define F0900_P2_SNVIT 0xf33d0030
1818#define F0900_P2_TOVVIT 0xf33d000c
1819#define F0900_P2_HYPVIT 0xf33d0003
1820
1821/*P2_VSTATUSVIT*/
1822#define R0900_P2_VSTATUSVIT 0xf33e
1823#define F0900_P2_VITERBI_ON 0xf33e0080
1824#define F0900_P2_END_LOOPVIT 0xf33e0040
1825#define F0900_P2_VITERBI_DEPRF 0xf33e0020
1826#define F0900_P2_PRFVIT 0xf33e0010
1827#define F0900_P2_LOCKEDVIT 0xf33e0008
1828#define F0900_P2_VITERBI_DELOCK 0xf33e0004
1829#define F0900_P2_VIT_DEMODSEL 0xf33e0002
1830#define F0900_P2_VITERBI_COMPOUT 0xf33e0001
1831
1832/*P2_VTHINUSE*/
1833#define R0900_P2_VTHINUSE 0xf33f
1834#define F0900_P2_VIT_INUSE 0xf33f00ff
1835
1836/*P2_KDIV12*/
1837#define R0900_P2_KDIV12 0xf340
1838#define F0900_P2_KDIV12_MANUAL 0xf3400080
1839#define F0900_P2_K_DIVIDER_12 0xf340007f
1840
1841/*P2_KDIV23*/
1842#define R0900_P2_KDIV23 0xf341
1843#define F0900_P2_KDIV23_MANUAL 0xf3410080
1844#define F0900_P2_K_DIVIDER_23 0xf341007f
1845
1846/*P2_KDIV34*/
1847#define R0900_P2_KDIV34 0xf342
1848#define F0900_P2_KDIV34_MANUAL 0xf3420080
1849#define F0900_P2_K_DIVIDER_34 0xf342007f
1850
1851/*P2_KDIV56*/
1852#define R0900_P2_KDIV56 0xf343
1853#define F0900_P2_KDIV56_MANUAL 0xf3430080
1854#define F0900_P2_K_DIVIDER_56 0xf343007f
1855
1856/*P2_KDIV67*/
1857#define R0900_P2_KDIV67 0xf344
1858#define F0900_P2_KDIV67_MANUAL 0xf3440080
1859#define F0900_P2_K_DIVIDER_67 0xf344007f
1860
1861/*P2_KDIV78*/
1862#define R0900_P2_KDIV78 0xf345
1863#define F0900_P2_KDIV78_MANUAL 0xf3450080
1864#define F0900_P2_K_DIVIDER_78 0xf345007f
1865
1866/*P2_PDELCTRL1*/
1867#define R0900_P2_PDELCTRL1 0xf350
1868#define F0900_P2_INV_MISMASK 0xf3500080
1869#define F0900_P2_FORCE_ACCEPTED 0xf3500040
1870#define F0900_P2_FILTER_EN 0xf3500020
1871#define F0900_P2_FORCE_PKTDELINUSE 0xf3500010
1872#define F0900_P2_HYSTEN 0xf3500008
1873#define F0900_P2_HYSTSWRST 0xf3500004
1874#define F0900_P2_EN_MIS00 0xf3500002
1875#define F0900_P2_ALGOSWRST 0xf3500001
1876
1877/*P2_PDELCTRL2*/
1878#define R0900_P2_PDELCTRL2 0xf351
1879#define F0900_P2_FORCE_CONTINUOUS 0xf3510080
1880#define F0900_P2_RESET_UPKO_COUNT 0xf3510040
1881#define F0900_P2_USER_PKTDELIN_NB 0xf3510020
1882#define F0900_P2_FORCE_LOCKED 0xf3510010
1883#define F0900_P2_DATA_UNBBSCRAM 0xf3510008
1884#define F0900_P2_FORCE_LONGPKT 0xf3510004
1885#define F0900_P2_FRAME_MODE 0xf3510002
1886
1887/*P2_HYSTTHRESH*/
1888#define R0900_P2_HYSTTHRESH 0xf354
1889#define F0900_P2_UNLCK_THRESH 0xf35400f0
1890#define F0900_P2_DELIN_LCK_THRESH 0xf354000f
1891
1892/*P2_ISIENTRY*/
1893#define R0900_P2_ISIENTRY 0xf35e
1894#define F0900_P2_ISI_ENTRY 0xf35e00ff
1895
1896/*P2_ISIBITENA*/
1897#define R0900_P2_ISIBITENA 0xf35f
1898#define F0900_P2_ISI_BIT_EN 0xf35f00ff
1899
1900/*P2_MATSTR1*/
1901#define R0900_P2_MATSTR1 0xf360
1902#define F0900_P2_MATYPE_CURRENT1 0xf36000ff
1903
1904/*P2_MATSTR0*/
1905#define R0900_P2_MATSTR0 0xf361
1906#define F0900_P2_MATYPE_CURRENT0 0xf36100ff
1907
1908/*P2_UPLSTR1*/
1909#define R0900_P2_UPLSTR1 0xf362
1910#define F0900_P2_UPL_CURRENT1 0xf36200ff
1911
1912/*P2_UPLSTR0*/
1913#define R0900_P2_UPLSTR0 0xf363
1914#define F0900_P2_UPL_CURRENT0 0xf36300ff
1915
1916/*P2_DFLSTR1*/
1917#define R0900_P2_DFLSTR1 0xf364
1918#define F0900_P2_DFL_CURRENT1 0xf36400ff
1919
1920/*P2_DFLSTR0*/
1921#define R0900_P2_DFLSTR0 0xf365
1922#define F0900_P2_DFL_CURRENT0 0xf36500ff
1923
1924/*P2_SYNCSTR*/
1925#define R0900_P2_SYNCSTR 0xf366
1926#define F0900_P2_SYNC_CURRENT 0xf36600ff
1927
1928/*P2_SYNCDSTR1*/
1929#define R0900_P2_SYNCDSTR1 0xf367
1930#define F0900_P2_SYNCD_CURRENT1 0xf36700ff
1931
1932/*P2_SYNCDSTR0*/
1933#define R0900_P2_SYNCDSTR0 0xf368
1934#define F0900_P2_SYNCD_CURRENT0 0xf36800ff
1935
1936/*P2_PDELSTATUS1*/
1937#define R0900_P2_PDELSTATUS1 0xf369
1938#define F0900_P2_PKTDELIN_DELOCK 0xf3690080
1939#define F0900_P2_SYNCDUPDFL_BADDFL 0xf3690040
1940#define F0900_P2_CONTINUOUS_STREAM 0xf3690020
1941#define F0900_P2_UNACCEPTED_STREAM 0xf3690010
1942#define F0900_P2_BCH_ERROR_FLAG 0xf3690008
1943#define F0900_P2_BBHCRCKO 0xf3690004
1944#define F0900_P2_PKTDELIN_LOCK 0xf3690002
1945#define F0900_P2_FIRST_LOCK 0xf3690001
1946
1947/*P2_PDELSTATUS2*/
1948#define R0900_P2_PDELSTATUS2 0xf36a
1949#define F0900_P2_PKTDEL_DEMODSEL 0xf36a0080
1950#define F0900_P2_FRAME_MODCOD 0xf36a007c
1951#define F0900_P2_FRAME_TYPE 0xf36a0003
1952
1953/*P2_BBFCRCKO1*/
1954#define R0900_P2_BBFCRCKO1 0xf36b
1955#define F0900_P2_BBHCRC_KOCNT1 0xf36b00ff
1956
1957/*P2_BBFCRCKO0*/
1958#define R0900_P2_BBFCRCKO0 0xf36c
1959#define F0900_P2_BBHCRC_KOCNT0 0xf36c00ff
1960
1961/*P2_UPCRCKO1*/
1962#define R0900_P2_UPCRCKO1 0xf36d
1963#define F0900_P2_PKTCRC_KOCNT1 0xf36d00ff
1964
1965/*P2_UPCRCKO0*/
1966#define R0900_P2_UPCRCKO0 0xf36e
1967#define F0900_P2_PKTCRC_KOCNT0 0xf36e00ff
1968
1969/*P2_TSSTATEM*/
1970#define R0900_P2_TSSTATEM 0xf370
1971#define F0900_P2_TSDIL_ON 0xf3700080
1972#define F0900_P2_TSSKIPRS_ON 0xf3700040
1973#define F0900_P2_TSRS_ON 0xf3700020
1974#define F0900_P2_TSDESCRAMB_ON 0xf3700010
1975#define F0900_P2_TSFRAME_MODE 0xf3700008
1976#define F0900_P2_TS_DISABLE 0xf3700004
1977#define F0900_P2_TSACM_MODE 0xf3700002
1978#define F0900_P2_TSOUT_NOSYNC 0xf3700001
1979
1980/*P2_TSCFGH*/
1981#define R0900_P2_TSCFGH 0xf372
1982#define F0900_P2_TSFIFO_DVBCI 0xf3720080
1983#define F0900_P2_TSFIFO_SERIAL 0xf3720040
1984#define F0900_P2_TSFIFO_TEIUPDATE 0xf3720020
1985#define F0900_P2_TSFIFO_DUTY50 0xf3720010
1986#define F0900_P2_TSFIFO_HSGNLOUT 0xf3720008
1987#define F0900_P2_TSFIFO_ERRMODE 0xf3720006
1988#define F0900_P2_RST_HWARE 0xf3720001
1989
1990/*P2_TSCFGM*/
1991#define R0900_P2_TSCFGM 0xf373
1992#define F0900_P2_TSFIFO_MANSPEED 0xf37300c0
1993#define F0900_P2_TSFIFO_PERMDATA 0xf3730020
1994#define F0900_P2_TSFIFO_NONEWSGNL 0xf3730010
1995#define F0900_P2_TSFIFO_BITSPEED 0xf3730008
1996#define F0900_P2_NPD_SPECDVBS2 0xf3730004
1997#define F0900_P2_TSFIFO_STOPCKDIS 0xf3730002
1998#define F0900_P2_TSFIFO_INVDATA 0xf3730001
1999
2000/*P2_TSCFGL*/
2001#define R0900_P2_TSCFGL 0xf374
2002#define F0900_P2_TSFIFO_BCLKDEL1CK 0xf37400c0
2003#define F0900_P2_BCHERROR_MODE 0xf3740030
2004#define F0900_P2_TSFIFO_NSGNL2DATA 0xf3740008
2005#define F0900_P2_TSFIFO_EMBINDVB 0xf3740004
2006#define F0900_P2_TSFIFO_DPUNACT 0xf3740002
2007#define F0900_P2_TSFIFO_NPDOFF 0xf3740001
2008
2009/*P2_TSINSDELH*/
2010#define R0900_P2_TSINSDELH 0xf376
2011#define F0900_P2_TSDEL_SYNCBYTE 0xf3760080
2012#define F0900_P2_TSDEL_XXHEADER 0xf3760040
2013#define F0900_P2_TSDEL_BBHEADER 0xf3760020
2014#define F0900_P2_TSDEL_DATAFIELD 0xf3760010
2015#define F0900_P2_TSINSDEL_ISCR 0xf3760008
2016#define F0900_P2_TSINSDEL_NPD 0xf3760004
2017#define F0900_P2_TSINSDEL_RSPARITY 0xf3760002
2018#define F0900_P2_TSINSDEL_CRC8 0xf3760001
2019
2020/*P2_TSSPEED*/
2021#define R0900_P2_TSSPEED 0xf380
2022#define F0900_P2_TSFIFO_OUTSPEED 0xf38000ff
2023
2024/*P2_TSSTATUS*/
2025#define R0900_P2_TSSTATUS 0xf381
2026#define F0900_P2_TSFIFO_LINEOK 0xf3810080
2027#define F0900_P2_TSFIFO_ERROR 0xf3810040
2028#define F0900_P2_TSFIFO_DATA7 0xf3810020
2029#define F0900_P2_TSFIFO_NOSYNC 0xf3810010
2030#define F0900_P2_ISCR_INITIALIZED 0xf3810008
2031#define F0900_P2_ISCR_UPDATED 0xf3810004
2032#define F0900_P2_SOFFIFO_UNREGUL 0xf3810002
2033#define F0900_P2_DIL_READY 0xf3810001
2034
2035/*P2_TSSTATUS2*/
2036#define R0900_P2_TSSTATUS2 0xf382
2037#define F0900_P2_TSFIFO_DEMODSEL 0xf3820080
2038#define F0900_P2_TSFIFOSPEED_STORE 0xf3820040
2039#define F0900_P2_DILXX_RESET 0xf3820020
2040#define F0900_P2_TSSERIAL_IMPOS 0xf3820010
2041#define F0900_P2_TSFIFO_LINENOK 0xf3820008
2042#define F0900_P2_BITSPEED_EVENT 0xf3820004
2043#define F0900_P2_SCRAMBDETECT 0xf3820002
2044#define F0900_P2_ULDTV67_FALSELOCK 0xf3820001
2045
2046/*P2_TSBITRATE1*/
2047#define R0900_P2_TSBITRATE1 0xf383
2048#define F0900_P2_TSFIFO_BITRATE1 0xf38300ff
2049
2050/*P2_TSBITRATE0*/
2051#define R0900_P2_TSBITRATE0 0xf384
2052#define F0900_P2_TSFIFO_BITRATE0 0xf38400ff
2053
2054/*P2_ERRCTRL1*/
2055#define R0900_P2_ERRCTRL1 0xf398
2056#define F0900_P2_ERR_SOURCE1 0xf39800f0
2057#define F0900_P2_NUM_EVENT1 0xf3980007
2058
2059/*P2_ERRCNT12*/
2060#define R0900_P2_ERRCNT12 0xf399
2061#define F0900_P2_ERRCNT1_OLDVALUE 0xf3990080
2062#define F0900_P2_ERR_CNT12 0xf399007f
2063
2064/*P2_ERRCNT11*/
2065#define R0900_P2_ERRCNT11 0xf39a
2066#define F0900_P2_ERR_CNT11 0xf39a00ff
2067
2068/*P2_ERRCNT10*/
2069#define R0900_P2_ERRCNT10 0xf39b
2070#define F0900_P2_ERR_CNT10 0xf39b00ff
2071
2072/*P2_ERRCTRL2*/
2073#define R0900_P2_ERRCTRL2 0xf39c
2074#define F0900_P2_ERR_SOURCE2 0xf39c00f0
2075#define F0900_P2_NUM_EVENT2 0xf39c0007
2076
2077/*P2_ERRCNT22*/
2078#define R0900_P2_ERRCNT22 0xf39d
2079#define F0900_P2_ERRCNT2_OLDVALUE 0xf39d0080
2080#define F0900_P2_ERR_CNT22 0xf39d007f
2081
2082/*P2_ERRCNT21*/
2083#define R0900_P2_ERRCNT21 0xf39e
2084#define F0900_P2_ERR_CNT21 0xf39e00ff
2085
2086/*P2_ERRCNT20*/
2087#define R0900_P2_ERRCNT20 0xf39f
2088#define F0900_P2_ERR_CNT20 0xf39f00ff
2089
2090/*P2_FECSPY*/
2091#define R0900_P2_FECSPY 0xf3a0
2092#define F0900_P2_SPY_ENABLE 0xf3a00080
2093#define F0900_P2_NO_SYNCBYTE 0xf3a00040
2094#define F0900_P2_SERIAL_MODE 0xf3a00020
2095#define F0900_P2_UNUSUAL_PACKET 0xf3a00010
2096#define F0900_P2_BER_PACKMODE 0xf3a00008
2097#define F0900_P2_BERMETER_LMODE 0xf3a00002
2098#define F0900_P2_BERMETER_RESET 0xf3a00001
2099
2100/*P2_FSPYCFG*/
2101#define R0900_P2_FSPYCFG 0xf3a1
2102#define F0900_P2_FECSPY_INPUT 0xf3a100c0
2103#define F0900_P2_RST_ON_ERROR 0xf3a10020
2104#define F0900_P2_ONE_SHOT 0xf3a10010
2105#define F0900_P2_I2C_MODE 0xf3a1000c
2106#define F0900_P2_SPY_HYSTERESIS 0xf3a10003
2107
2108/*P2_FSPYDATA*/
2109#define R0900_P2_FSPYDATA 0xf3a2
2110#define F0900_P2_SPY_STUFFING 0xf3a20080
2111#define F0900_P2_NOERROR_PKTJITTER 0xf3a20040
2112#define F0900_P2_SPY_CNULLPKT 0xf3a20020
2113#define F0900_P2_SPY_OUTDATA_MODE 0xf3a2001f
2114
2115/*P2_FSPYOUT*/
2116#define R0900_P2_FSPYOUT 0xf3a3
2117#define F0900_P2_FSPY_DIRECT 0xf3a30080
2118#define F0900_P2_SPY_OUTDATA_BUS 0xf3a30038
2119#define F0900_P2_STUFF_MODE 0xf3a30007
2120
2121/*P2_FSTATUS*/
2122#define R0900_P2_FSTATUS 0xf3a4
2123#define F0900_P2_SPY_ENDSIM 0xf3a40080
2124#define F0900_P2_VALID_SIM 0xf3a40040
2125#define F0900_P2_FOUND_SIGNAL 0xf3a40020
2126#define F0900_P2_DSS_SYNCBYTE 0xf3a40010
2127#define F0900_P2_RESULT_STATE 0xf3a4000f
2128
2129/*P2_FBERCPT4*/
2130#define R0900_P2_FBERCPT4 0xf3a8
2131#define F0900_P2_FBERMETER_CPT4 0xf3a800ff
2132
2133/*P2_FBERCPT3*/
2134#define R0900_P2_FBERCPT3 0xf3a9
2135#define F0900_P2_FBERMETER_CPT3 0xf3a900ff
2136
2137/*P2_FBERCPT2*/
2138#define R0900_P2_FBERCPT2 0xf3aa
2139#define F0900_P2_FBERMETER_CPT2 0xf3aa00ff
2140
2141/*P2_FBERCPT1*/
2142#define R0900_P2_FBERCPT1 0xf3ab
2143#define F0900_P2_FBERMETER_CPT1 0xf3ab00ff
2144
2145/*P2_FBERCPT0*/
2146#define R0900_P2_FBERCPT0 0xf3ac
2147#define F0900_P2_FBERMETER_CPT0 0xf3ac00ff
2148
2149/*P2_FBERERR2*/
2150#define R0900_P2_FBERERR2 0xf3ad
2151#define F0900_P2_FBERMETER_ERR2 0xf3ad00ff
2152
2153/*P2_FBERERR1*/
2154#define R0900_P2_FBERERR1 0xf3ae
2155#define F0900_P2_FBERMETER_ERR1 0xf3ae00ff
2156
2157/*P2_FBERERR0*/
2158#define R0900_P2_FBERERR0 0xf3af
2159#define F0900_P2_FBERMETER_ERR0 0xf3af00ff
2160
2161/*P2_FSPYBER*/
2162#define R0900_P2_FSPYBER 0xf3b2
2163#define F0900_P2_FSPYOBS_XORREAD 0xf3b20040
2164#define F0900_P2_FSPYBER_OBSMODE 0xf3b20020
2165#define F0900_P2_FSPYBER_SYNCBYTE 0xf3b20010
2166#define F0900_P2_FSPYBER_UNSYNC 0xf3b20008
2167#define F0900_P2_FSPYBER_CTIME 0xf3b20007
2168
2169/*P1_IQCONST*/
2170#define R0900_P1_IQCONST 0xf400
2171#define F0900_P1_CONSTEL_SELECT 0xf4000060
2172#define F0900_P1_IQSYMB_SEL 0xf400001f
2173
2174/*P1_NOSCFG*/
2175#define R0900_P1_NOSCFG 0xf401
2176#define F0900_P1_DUMMYPL_NOSDATA 0xf4010020
2177#define F0900_P1_NOSPLH_BETA 0xf4010018
2178#define F0900_P1_NOSDATA_BETA 0xf4010007
2179
2180/*P1_ISYMB*/
2181#define R0900_P1_ISYMB 0xf402
2182#define F0900_P1_I_SYMBOL 0xf40201ff
2183
2184/*P1_QSYMB*/
2185#define R0900_P1_QSYMB 0xf403
2186#define F0900_P1_Q_SYMBOL 0xf40301ff
2187
2188/*P1_AGC1CFG*/
2189#define R0900_P1_AGC1CFG 0xf404
2190#define F0900_P1_DC_FROZEN 0xf4040080
2191#define F0900_P1_DC_CORRECT 0xf4040040
2192#define F0900_P1_AMM_FROZEN 0xf4040020
2193#define F0900_P1_AMM_CORRECT 0xf4040010
2194#define F0900_P1_QUAD_FROZEN 0xf4040008
2195#define F0900_P1_QUAD_CORRECT 0xf4040004
2196#define F0900_P1_DCCOMP_SLOW 0xf4040002
2197#define F0900_P1_IQMISM_SLOW 0xf4040001
2198
2199/*P1_AGC1CN*/
2200#define R0900_P1_AGC1CN 0xf406
2201#define F0900_P1_AGC1_LOCKED 0xf4060080
2202#define F0900_P1_AGC1_OVERFLOW 0xf4060040
2203#define F0900_P1_AGC1_NOSLOWLK 0xf4060020
2204#define F0900_P1_AGC1_MINPOWER 0xf4060010
2205#define F0900_P1_AGCOUT_FAST 0xf4060008
2206#define F0900_P1_AGCIQ_BETA 0xf4060007
2207
2208/*P1_AGC1REF*/
2209#define R0900_P1_AGC1REF 0xf407
2210#define F0900_P1_AGCIQ_REF 0xf40700ff
2211
2212/*P1_IDCCOMP*/
2213#define R0900_P1_IDCCOMP 0xf408
2214#define F0900_P1_IAVERAGE_ADJ 0xf40801ff
2215
2216/*P1_QDCCOMP*/
2217#define R0900_P1_QDCCOMP 0xf409
2218#define F0900_P1_QAVERAGE_ADJ 0xf40901ff
2219
2220/*P1_POWERI*/
2221#define R0900_P1_POWERI 0xf40a
2222#define F0900_P1_POWER_I 0xf40a00ff
2223
2224/*P1_POWERQ*/
2225#define R0900_P1_POWERQ 0xf40b
2226#define F0900_P1_POWER_Q 0xf40b00ff
2227
2228/*P1_AGC1AMM*/
2229#define R0900_P1_AGC1AMM 0xf40c
2230#define F0900_P1_AMM_VALUE 0xf40c00ff
2231
2232/*P1_AGC1QUAD*/
2233#define R0900_P1_AGC1QUAD 0xf40d
2234#define F0900_P1_QUAD_VALUE 0xf40d01ff
2235
2236/*P1_AGCIQIN1*/
2237#define R0900_P1_AGCIQIN1 0xf40e
2238#define F0900_P1_AGCIQ_VALUE1 0xf40e00ff
2239
2240/*P1_AGCIQIN0*/
2241#define R0900_P1_AGCIQIN0 0xf40f
2242#define F0900_P1_AGCIQ_VALUE0 0xf40f00ff
2243
2244/*P1_DEMOD*/
2245#define R0900_P1_DEMOD 0xf410
2246#define F0900_P1_DEMOD_STOP 0xf4100040
2247#define F0900_P1_SPECINV_CONTROL 0xf4100030
2248#define F0900_P1_FORCE_ENASAMP 0xf4100008
2249#define F0900_P1_MANUAL_ROLLOFF 0xf4100004
2250#define F0900_P1_ROLLOFF_CONTROL 0xf4100003
2251
2252/*P1_DMDMODCOD*/
2253#define R0900_P1_DMDMODCOD 0xf411
2254#define F0900_P1_MANUAL_MODCOD 0xf4110080
2255#define F0900_P1_DEMOD_MODCOD 0xf411007c
2256#define F0900_P1_DEMOD_TYPE 0xf4110003
2257
2258/*P1_DSTATUS*/
2259#define R0900_P1_DSTATUS 0xf412
2260#define F0900_P1_CAR_LOCK 0xf4120080
2261#define F0900_P1_TMGLOCK_QUALITY 0xf4120060
2262#define F0900_P1_SDVBS1_ENABLE 0xf4120010
2263#define F0900_P1_LOCK_DEFINITIF 0xf4120008
2264#define F0900_P1_TIMING_IS_LOCKED 0xf4120004
2265#define F0900_P1_COARSE_TMGLOCK 0xf4120002
2266#define F0900_P1_COARSE_CARLOCK 0xf4120001
2267
2268/*P1_DSTATUS2*/
2269#define R0900_P1_DSTATUS2 0xf413
2270#define F0900_P1_DEMOD_DELOCK 0xf4130080
2271#define F0900_P1_DEMOD_TIMEOUT 0xf4130040
2272#define F0900_P1_MODCODRQ_SYNCTAG 0xf4130020
2273#define F0900_P1_POLYPH_SATEVENT 0xf4130010
2274#define F0900_P1_AGC1_NOSIGNALACK 0xf4130008
2275#define F0900_P1_AGC2_OVERFLOW 0xf4130004
2276#define F0900_P1_CFR_OVERFLOW 0xf4130002
2277#define F0900_P1_GAMMA_OVERUNDER 0xf4130001
2278
2279/*P1_DMDCFGMD*/
2280#define R0900_P1_DMDCFGMD 0xf414
2281#define F0900_P1_DVBS2_ENABLE 0xf4140080
2282#define F0900_P1_DVBS1_ENABLE 0xf4140040
2283#define F0900_P1_CFR_AUTOSCAN 0xf4140020
2284#define F0900_P1_SCAN_ENABLE 0xf4140010
2285#define F0900_P1_TUN_AUTOSCAN 0xf4140008
2286#define F0900_P1_NOFORCE_RELOCK 0xf4140004
2287#define F0900_P1_TUN_RNG 0xf4140003
2288
2289/*P1_DMDCFG2*/
2290#define R0900_P1_DMDCFG2 0xf415
2291#define F0900_P1_AGC1_WAITLOCK 0xf4150080
2292#define F0900_P1_S1S2_SEQUENTIAL 0xf4150040
2293#define F0900_P1_OVERFLOW_TIMEOUT 0xf4150020
2294#define F0900_P1_SCANFAIL_TIMEOUT 0xf4150010
2295#define F0900_P1_DMDTOUT_BACK 0xf4150008
2296#define F0900_P1_CARLOCK_S1ENABLE 0xf4150004
2297#define F0900_P1_COARSE_LK3MODE 0xf4150002
2298#define F0900_P1_COARSE_LK2MODE 0xf4150001
2299
2300/*P1_DMDISTATE*/
2301#define R0900_P1_DMDISTATE 0xf416
2302#define F0900_P1_I2C_NORESETDMODE 0xf4160080
2303#define F0900_P1_FORCE_ETAPED 0xf4160040
2304#define F0900_P1_SDMDRST_DIRCLK 0xf4160020
2305#define F0900_P1_I2C_DEMOD_MODE 0xf416001f
2306
2307/*P1_DMDT0M*/
2308#define R0900_P1_DMDT0M 0xf417
2309#define F0900_P1_DMDT0_MIN 0xf41700ff
2310
2311/*P1_DMDSTATE*/
2312#define R0900_P1_DMDSTATE 0xf41b
2313#define F0900_P1_DEMOD_LOCKED 0xf41b0080
2314#define F0900_P1_HEADER_MODE 0xf41b0060
2315#define F0900_P1_DEMOD_MODE 0xf41b001f
2316
2317/*P1_DMDFLYW*/
2318#define R0900_P1_DMDFLYW 0xf41c
2319#define F0900_P1_I2C_IRQVAL 0xf41c00f0
2320#define F0900_P1_FLYWHEEL_CPT 0xf41c000f
2321
2322/*P1_DSTATUS3*/
2323#define R0900_P1_DSTATUS3 0xf41d
2324#define F0900_P1_CFR_ZIGZAG 0xf41d0080
2325#define F0900_P1_DEMOD_CFGMODE 0xf41d0060
2326#define F0900_P1_GAMMA_LOWBAUDRATE 0xf41d0010
2327#define F0900_P1_RELOCK_MODE 0xf41d0008
2328#define F0900_P1_DEMOD_FAIL 0xf41d0004
2329#define F0900_P1_ETAPE1A_DVBXMEM 0xf41d0003
2330
2331/*P1_DMDCFG3*/
2332#define R0900_P1_DMDCFG3 0xf41e
2333#define F0900_P1_DVBS1_TMGWAIT 0xf41e0080
2334#define F0900_P1_NO_BWCENTERING 0xf41e0040
2335#define F0900_P1_INV_SEQSRCH 0xf41e0020
2336#define F0900_P1_DIS_SFRUPLOW_TRK 0xf41e0010
2337#define F0900_P1_NOSTOP_FIFOFULL 0xf41e0008
2338#define F0900_P1_LOCKTIME_MODE 0xf41e0007
2339
2340/*P1_DMDCFG4*/
2341#define R0900_P1_DMDCFG4 0xf41f
2342#define F0900_P1_TUNER_NRELAUNCH 0xf41f0008
2343#define F0900_P1_DIS_CLKENABLE 0xf41f0004
2344#define F0900_P1_DIS_HDRDIVLOCK 0xf41f0002
2345#define F0900_P1_NO_TNRWBINIT 0xf41f0001
2346
2347/*P1_CORRELMANT*/
2348#define R0900_P1_CORRELMANT 0xf420
2349#define F0900_P1_CORREL_MANT 0xf42000ff
2350
2351/*P1_CORRELABS*/
2352#define R0900_P1_CORRELABS 0xf421
2353#define F0900_P1_CORREL_ABS 0xf42100ff
2354
2355/*P1_CORRELEXP*/
2356#define R0900_P1_CORRELEXP 0xf422
2357#define F0900_P1_CORREL_ABSEXP 0xf42200f0
2358#define F0900_P1_CORREL_EXP 0xf422000f
2359
2360/*P1_PLHMODCOD*/
2361#define R0900_P1_PLHMODCOD 0xf424
2362#define F0900_P1_SPECINV_DEMOD 0xf4240080
2363#define F0900_P1_PLH_MODCOD 0xf424007c
2364#define F0900_P1_PLH_TYPE 0xf4240003
2365
2366/*P1_AGCK32*/
2367#define R0900_P1_AGCK32 0xf42b
2368#define F0900_P1_R3ADJOFF_32APSK 0xf42b0080
2369#define F0900_P1_R2ADJOFF_32APSK 0xf42b0040
2370#define F0900_P1_R1ADJOFF_32APSK 0xf42b0020
2371#define F0900_P1_RADJ_32APSK 0xf42b001f
2372
2373/*P1_AGC2O*/
2374#define R0900_P1_AGC2O 0xf42c
2375#define F0900_P1_AGC2REF_ADJUSTING 0xf42c0080
2376#define F0900_P1_AGC2_COARSEFAST 0xf42c0040
2377#define F0900_P1_AGC2_LKSQRT 0xf42c0020
2378#define F0900_P1_AGC2_LKMODE 0xf42c0010
2379#define F0900_P1_AGC2_LKEQUA 0xf42c0008
2380#define F0900_P1_AGC2_COEF 0xf42c0007
2381
2382/*P1_AGC2REF*/
2383#define R0900_P1_AGC2REF 0xf42d
2384#define F0900_P1_AGC2_REF 0xf42d00ff
2385
2386/*P1_AGC1ADJ*/
2387#define R0900_P1_AGC1ADJ 0xf42e
2388#define F0900_P1_AGC1ADJ_MANUAL 0xf42e0080
2389#define F0900_P1_AGC1_ADJUSTED 0xf42e017f
2390
2391/*P1_AGC2I1*/
2392#define R0900_P1_AGC2I1 0xf436
2393#define F0900_P1_AGC2_INTEGRATOR1 0xf43600ff
2394
2395/*P1_AGC2I0*/
2396#define R0900_P1_AGC2I0 0xf437
2397#define F0900_P1_AGC2_INTEGRATOR0 0xf43700ff
2398
2399/*P1_CARCFG*/
2400#define R0900_P1_CARCFG 0xf438
2401#define F0900_P1_CFRUPLOW_AUTO 0xf4380080
2402#define F0900_P1_CFRUPLOW_TEST 0xf4380040
2403#define F0900_P1_EN_CAR2CENTER 0xf4380020
2404#define F0900_P1_CARHDR_NODIV8 0xf4380010
2405#define F0900_P1_I2C_ROTA 0xf4380008
2406#define F0900_P1_ROTAON 0xf4380004
2407#define F0900_P1_PH_DET_ALGO 0xf4380003
2408
2409/*P1_ACLC*/
2410#define R0900_P1_ACLC 0xf439
2411#define F0900_P1_STOP_S2ALPHA 0xf43900c0
2412#define F0900_P1_CAR_ALPHA_MANT 0xf4390030
2413#define F0900_P1_CAR_ALPHA_EXP 0xf439000f
2414
2415/*P1_BCLC*/
2416#define R0900_P1_BCLC 0xf43a
2417#define F0900_P1_STOP_S2BETA 0xf43a00c0
2418#define F0900_P1_CAR_BETA_MANT 0xf43a0030
2419#define F0900_P1_CAR_BETA_EXP 0xf43a000f
2420
2421/*P1_CARFREQ*/
2422#define R0900_P1_CARFREQ 0xf43d
2423#define F0900_P1_KC_COARSE_EXP 0xf43d00f0
2424#define F0900_P1_BETA_FREQ 0xf43d000f
2425
2426/*P1_CARHDR*/
2427#define R0900_P1_CARHDR 0xf43e
2428#define F0900_P1_K_FREQ_HDR 0xf43e00ff
2429
2430/*P1_LDT*/
2431#define R0900_P1_LDT 0xf43f
2432#define F0900_P1_CARLOCK_THRES 0xf43f01ff
2433
2434/*P1_LDT2*/
2435#define R0900_P1_LDT2 0xf440
2436#define F0900_P1_CARLOCK_THRES2 0xf44001ff
2437
2438/*P1_CFRICFG*/
2439#define R0900_P1_CFRICFG 0xf441
2440#define F0900_P1_CFRINIT_UNVALRNG 0xf4410080
2441#define F0900_P1_CFRINIT_LUNVALCPT 0xf4410040
2442#define F0900_P1_CFRINIT_ABORTDBL 0xf4410020
2443#define F0900_P1_CFRINIT_ABORTPRED 0xf4410010
2444#define F0900_P1_CFRINIT_UNVALSKIP 0xf4410008
2445#define F0900_P1_CFRINIT_CSTINC 0xf4410004
2446#define F0900_P1_NEG_CFRSTEP 0xf4410001
2447
2448/*P1_CFRUP1*/
2449#define R0900_P1_CFRUP1 0xf442
2450#define F0900_P1_CFR_UP1 0xf44201ff
2451
2452/*P1_CFRUP0*/
2453#define R0900_P1_CFRUP0 0xf443
2454#define F0900_P1_CFR_UP0 0xf44300ff
2455
2456/*P1_CFRLOW1*/
2457#define R0900_P1_CFRLOW1 0xf446
2458#define F0900_P1_CFR_LOW1 0xf44601ff
2459
2460/*P1_CFRLOW0*/
2461#define R0900_P1_CFRLOW0 0xf447
2462#define F0900_P1_CFR_LOW0 0xf44700ff
2463
2464/*P1_CFRINIT1*/
2465#define R0900_P1_CFRINIT1 0xf448
2466#define F0900_P1_CFR_INIT1 0xf44801ff
2467
2468/*P1_CFRINIT0*/
2469#define R0900_P1_CFRINIT0 0xf449
2470#define F0900_P1_CFR_INIT0 0xf44900ff
2471
2472/*P1_CFRINC1*/
2473#define R0900_P1_CFRINC1 0xf44a
2474#define F0900_P1_MANUAL_CFRINC 0xf44a0080
2475#define F0900_P1_CFR_INC1 0xf44a017f
2476
2477/*P1_CFRINC0*/
2478#define R0900_P1_CFRINC0 0xf44b
2479#define F0900_P1_CFR_INC0 0xf44b00f0
2480
2481/*P1_CFR2*/
2482#define R0900_P1_CFR2 0xf44c
2483#define F0900_P1_CAR_FREQ2 0xf44c01ff
2484
2485/*P1_CFR1*/
2486#define R0900_P1_CFR1 0xf44d
2487#define F0900_P1_CAR_FREQ1 0xf44d00ff
2488
2489/*P1_CFR0*/
2490#define R0900_P1_CFR0 0xf44e
2491#define F0900_P1_CAR_FREQ0 0xf44e00ff
2492
2493/*P1_LDI*/
2494#define R0900_P1_LDI 0xf44f
2495#define F0900_P1_LOCK_DET_INTEGR 0xf44f01ff
2496
2497/*P1_TMGCFG*/
2498#define R0900_P1_TMGCFG 0xf450
2499#define F0900_P1_TMGLOCK_BETA 0xf45000c0
2500#define F0900_P1_NOTMG_GROUPDELAY 0xf4500020
2501#define F0900_P1_DO_TIMING_CORR 0xf4500010
2502#define F0900_P1_MANUAL_SCAN 0xf450000c
2503#define F0900_P1_TMG_MINFREQ 0xf4500003
2504
2505/*P1_RTC*/
2506#define R0900_P1_RTC 0xf451
2507#define F0900_P1_TMGALPHA_EXP 0xf45100f0
2508#define F0900_P1_TMGBETA_EXP 0xf451000f
2509
2510/*P1_RTCS2*/
2511#define R0900_P1_RTCS2 0xf452
2512#define F0900_P1_TMGALPHAS2_EXP 0xf45200f0
2513#define F0900_P1_TMGBETAS2_EXP 0xf452000f
2514
2515/*P1_TMGTHRISE*/
2516#define R0900_P1_TMGTHRISE 0xf453
2517#define F0900_P1_TMGLOCK_THRISE 0xf45300ff
2518
2519/*P1_TMGTHFALL*/
2520#define R0900_P1_TMGTHFALL 0xf454
2521#define F0900_P1_TMGLOCK_THFALL 0xf45400ff
2522
2523/*P1_SFRUPRATIO*/
2524#define R0900_P1_SFRUPRATIO 0xf455
2525#define F0900_P1_SFR_UPRATIO 0xf45500ff
2526
2527/*P1_SFRLOWRATIO*/
2528#define R0900_P1_SFRLOWRATIO 0xf456
2529#define F0900_P1_SFR_LOWRATIO 0xf45600ff
2530
2531/*P1_KREFTMG*/
2532#define R0900_P1_KREFTMG 0xf458
2533#define F0900_P1_KREF_TMG 0xf45800ff
2534
2535/*P1_SFRSTEP*/
2536#define R0900_P1_SFRSTEP 0xf459
2537#define F0900_P1_SFR_SCANSTEP 0xf45900f0
2538#define F0900_P1_SFR_CENTERSTEP 0xf459000f
2539
2540/*P1_TMGCFG2*/
2541#define R0900_P1_TMGCFG2 0xf45a
2542#define F0900_P1_DIS_AUTOSAMP 0xf45a0008
2543#define F0900_P1_SCANINIT_QUART 0xf45a0004
2544#define F0900_P1_NOTMG_DVBS1DERAT 0xf45a0002
2545#define F0900_P1_SFRRATIO_FINE 0xf45a0001
2546
2547/*P1_SFRINIT1*/
2548#define R0900_P1_SFRINIT1 0xf45e
2549#define F0900_P1_SFR_INIT1 0xf45e00ff
2550
2551/*P1_SFRINIT0*/
2552#define R0900_P1_SFRINIT0 0xf45f
2553#define F0900_P1_SFR_INIT0 0xf45f00ff
2554
2555/*P1_SFRUP1*/
2556#define R0900_P1_SFRUP1 0xf460
2557#define F0900_P1_AUTO_GUP 0xf4600080
2558#define F0900_P1_SYMB_FREQ_UP1 0xf460007f
2559
2560/*P1_SFRUP0*/
2561#define R0900_P1_SFRUP0 0xf461
2562#define F0900_P1_SYMB_FREQ_UP0 0xf46100ff
2563
2564/*P1_SFRLOW1*/
2565#define R0900_P1_SFRLOW1 0xf462
2566#define F0900_P1_AUTO_GLOW 0xf4620080
2567#define F0900_P1_SYMB_FREQ_LOW1 0xf462007f
2568
2569/*P1_SFRLOW0*/
2570#define R0900_P1_SFRLOW0 0xf463
2571#define F0900_P1_SYMB_FREQ_LOW0 0xf46300ff
2572
2573/*P1_SFR3*/
2574#define R0900_P1_SFR3 0xf464
2575#define F0900_P1_SYMB_FREQ3 0xf46400ff
2576
2577/*P1_SFR2*/
2578#define R0900_P1_SFR2 0xf465
2579#define F0900_P1_SYMB_FREQ2 0xf46500ff
2580
2581/*P1_SFR1*/
2582#define R0900_P1_SFR1 0xf466
2583#define F0900_P1_SYMB_FREQ1 0xf46600ff
2584
2585/*P1_SFR0*/
2586#define R0900_P1_SFR0 0xf467
2587#define F0900_P1_SYMB_FREQ0 0xf46700ff
2588
2589/*P1_TMGREG2*/
2590#define R0900_P1_TMGREG2 0xf468
2591#define F0900_P1_TMGREG2 0xf46800ff
2592
2593/*P1_TMGREG1*/
2594#define R0900_P1_TMGREG1 0xf469
2595#define F0900_P1_TMGREG1 0xf46900ff
2596
2597/*P1_TMGREG0*/
2598#define R0900_P1_TMGREG0 0xf46a
2599#define F0900_P1_TMGREG0 0xf46a00ff
2600
2601/*P1_TMGLOCK1*/
2602#define R0900_P1_TMGLOCK1 0xf46b
2603#define F0900_P1_TMGLOCK_LEVEL1 0xf46b01ff
2604
2605/*P1_TMGLOCK0*/
2606#define R0900_P1_TMGLOCK0 0xf46c
2607#define F0900_P1_TMGLOCK_LEVEL0 0xf46c00ff
2608
2609/*P1_TMGOBS*/
2610#define R0900_P1_TMGOBS 0xf46d
2611#define F0900_P1_ROLLOFF_STATUS 0xf46d00c0
2612#define F0900_P1_SCAN_SIGN 0xf46d0030
2613#define F0900_P1_TMG_SCANNING 0xf46d0008
2614#define F0900_P1_CHCENTERING_MODE 0xf46d0004
2615#define F0900_P1_TMG_SCANFAIL 0xf46d0002
2616
2617/*P1_EQUALCFG*/
2618#define R0900_P1_EQUALCFG 0xf46f
2619#define F0900_P1_NOTMG_NEGALWAIT 0xf46f0080
2620#define F0900_P1_EQUAL_ON 0xf46f0040
2621#define F0900_P1_SEL_EQUALCOR 0xf46f0038
2622#define F0900_P1_MU_EQUALDFE 0xf46f0007
2623
2624/*P1_EQUAI1*/
2625#define R0900_P1_EQUAI1 0xf470
2626#define F0900_P1_EQUA_ACCI1 0xf47001ff
2627
2628/*P1_EQUAQ1*/
2629#define R0900_P1_EQUAQ1 0xf471
2630#define F0900_P1_EQUA_ACCQ1 0xf47101ff
2631
2632/*P1_EQUAI2*/
2633#define R0900_P1_EQUAI2 0xf472
2634#define F0900_P1_EQUA_ACCI2 0xf47201ff
2635
2636/*P1_EQUAQ2*/
2637#define R0900_P1_EQUAQ2 0xf473
2638#define F0900_P1_EQUA_ACCQ2 0xf47301ff
2639
2640/*P1_EQUAI3*/
2641#define R0900_P1_EQUAI3 0xf474
2642#define F0900_P1_EQUA_ACCI3 0xf47401ff
2643
2644/*P1_EQUAQ3*/
2645#define R0900_P1_EQUAQ3 0xf475
2646#define F0900_P1_EQUA_ACCQ3 0xf47501ff
2647
2648/*P1_EQUAI4*/
2649#define R0900_P1_EQUAI4 0xf476
2650#define F0900_P1_EQUA_ACCI4 0xf47601ff
2651
2652/*P1_EQUAQ4*/
2653#define R0900_P1_EQUAQ4 0xf477
2654#define F0900_P1_EQUA_ACCQ4 0xf47701ff
2655
2656/*P1_EQUAI5*/
2657#define R0900_P1_EQUAI5 0xf478
2658#define F0900_P1_EQUA_ACCI5 0xf47801ff
2659
2660/*P1_EQUAQ5*/
2661#define R0900_P1_EQUAQ5 0xf479
2662#define F0900_P1_EQUA_ACCQ5 0xf47901ff
2663
2664/*P1_EQUAI6*/
2665#define R0900_P1_EQUAI6 0xf47a
2666#define F0900_P1_EQUA_ACCI6 0xf47a01ff
2667
2668/*P1_EQUAQ6*/
2669#define R0900_P1_EQUAQ6 0xf47b
2670#define F0900_P1_EQUA_ACCQ6 0xf47b01ff
2671
2672/*P1_EQUAI7*/
2673#define R0900_P1_EQUAI7 0xf47c
2674#define F0900_P1_EQUA_ACCI7 0xf47c01ff
2675
2676/*P1_EQUAQ7*/
2677#define R0900_P1_EQUAQ7 0xf47d
2678#define F0900_P1_EQUA_ACCQ7 0xf47d01ff
2679
2680/*P1_EQUAI8*/
2681#define R0900_P1_EQUAI8 0xf47e
2682#define F0900_P1_EQUA_ACCI8 0xf47e01ff
2683
2684/*P1_EQUAQ8*/
2685#define R0900_P1_EQUAQ8 0xf47f
2686#define F0900_P1_EQUA_ACCQ8 0xf47f01ff
2687
2688/*P1_NNOSDATAT1*/
2689#define R0900_P1_NNOSDATAT1 0xf480
2690#define F0900_P1_NOSDATAT_NORMED1 0xf48000ff
2691
2692/*P1_NNOSDATAT0*/
2693#define R0900_P1_NNOSDATAT0 0xf481
2694#define F0900_P1_NOSDATAT_NORMED0 0xf48100ff
2695
2696/*P1_NNOSDATA1*/
2697#define R0900_P1_NNOSDATA1 0xf482
2698#define F0900_P1_NOSDATA_NORMED1 0xf48200ff
2699
2700/*P1_NNOSDATA0*/
2701#define R0900_P1_NNOSDATA0 0xf483
2702#define F0900_P1_NOSDATA_NORMED0 0xf48300ff
2703
2704/*P1_NNOSPLHT1*/
2705#define R0900_P1_NNOSPLHT1 0xf484
2706#define F0900_P1_NOSPLHT_NORMED1 0xf48400ff
2707
2708/*P1_NNOSPLHT0*/
2709#define R0900_P1_NNOSPLHT0 0xf485
2710#define F0900_P1_NOSPLHT_NORMED0 0xf48500ff
2711
2712/*P1_NNOSPLH1*/
2713#define R0900_P1_NNOSPLH1 0xf486
2714#define F0900_P1_NOSPLH_NORMED1 0xf48600ff
2715
2716/*P1_NNOSPLH0*/
2717#define R0900_P1_NNOSPLH0 0xf487
2718#define F0900_P1_NOSPLH_NORMED0 0xf48700ff
2719
2720/*P1_NOSDATAT1*/
2721#define R0900_P1_NOSDATAT1 0xf488
2722#define F0900_P1_NOSDATAT_UNNORMED1 0xf48800ff
2723
2724/*P1_NOSDATAT0*/
2725#define R0900_P1_NOSDATAT0 0xf489
2726#define F0900_P1_NOSDATAT_UNNORMED0 0xf48900ff
2727
2728/*P1_NOSDATA1*/
2729#define R0900_P1_NOSDATA1 0xf48a
2730#define F0900_P1_NOSDATA_UNNORMED1 0xf48a00ff
2731
2732/*P1_NOSDATA0*/
2733#define R0900_P1_NOSDATA0 0xf48b
2734#define F0900_P1_NOSDATA_UNNORMED0 0xf48b00ff
2735
2736/*P1_NOSPLHT1*/
2737#define R0900_P1_NOSPLHT1 0xf48c
2738#define F0900_P1_NOSPLHT_UNNORMED1 0xf48c00ff
2739
2740/*P1_NOSPLHT0*/
2741#define R0900_P1_NOSPLHT0 0xf48d
2742#define F0900_P1_NOSPLHT_UNNORMED0 0xf48d00ff
2743
2744/*P1_NOSPLH1*/
2745#define R0900_P1_NOSPLH1 0xf48e
2746#define F0900_P1_NOSPLH_UNNORMED1 0xf48e00ff
2747
2748/*P1_NOSPLH0*/
2749#define R0900_P1_NOSPLH0 0xf48f
2750#define F0900_P1_NOSPLH_UNNORMED0 0xf48f00ff
2751
2752/*P1_CAR2CFG*/
2753#define R0900_P1_CAR2CFG 0xf490
2754#define F0900_P1_DESCRAMB_OFF 0xf4900080
2755#define F0900_P1_PN4_SELECT 0xf4900040
2756#define F0900_P1_CFR2_STOPDVBS1 0xf4900020
2757#define F0900_P1_STOP_CFR2UPDATE 0xf4900010
2758#define F0900_P1_STOP_NCO2UPDATE 0xf4900008
2759#define F0900_P1_ROTA2ON 0xf4900004
2760#define F0900_P1_PH_DET_ALGO2 0xf4900003
2761
2762/*P1_ACLC2*/
2763#define R0900_P1_ACLC2 0xf491
2764#define F0900_P1_CAR2_PUNCT_ADERAT 0xf4910040
2765#define F0900_P1_CAR2_ALPHA_MANT 0xf4910030
2766#define F0900_P1_CAR2_ALPHA_EXP 0xf491000f
2767
2768/*P1_BCLC2*/
2769#define R0900_P1_BCLC2 0xf492
2770#define F0900_P1_DVBS2_NIP 0xf4920080
2771#define F0900_P1_CAR2_PUNCT_BDERAT 0xf4920040
2772#define F0900_P1_CAR2_BETA_MANT 0xf4920030
2773#define F0900_P1_CAR2_BETA_EXP 0xf492000f
2774
2775/*P1_CFR22*/
2776#define R0900_P1_CFR22 0xf493
2777#define F0900_P1_CAR2_FREQ2 0xf49301ff
2778
2779/*P1_CFR21*/
2780#define R0900_P1_CFR21 0xf494
2781#define F0900_P1_CAR2_FREQ1 0xf49400ff
2782
2783/*P1_CFR20*/
2784#define R0900_P1_CFR20 0xf495
2785#define F0900_P1_CAR2_FREQ0 0xf49500ff
2786
2787/*P1_ACLC2S2Q*/
2788#define R0900_P1_ACLC2S2Q 0xf497
2789#define F0900_P1_ENAB_SPSKSYMB 0xf4970080
2790#define F0900_P1_CAR2S2_QADERAT 0xf4970040
2791#define F0900_P1_CAR2S2_Q_ALPH_M 0xf4970030
2792#define F0900_P1_CAR2S2_Q_ALPH_E 0xf497000f
2793
2794/*P1_ACLC2S28*/
2795#define R0900_P1_ACLC2S28 0xf498
2796#define F0900_P1_OLDI3Q_MODE 0xf4980080
2797#define F0900_P1_CAR2S2_8ADERAT 0xf4980040
2798#define F0900_P1_CAR2S2_8_ALPH_M 0xf4980030
2799#define F0900_P1_CAR2S2_8_ALPH_E 0xf498000f
2800
2801/*P1_ACLC2S216A*/
2802#define R0900_P1_ACLC2S216A 0xf499
2803#define F0900_P1_CAR2S2_16ADERAT 0xf4990040
2804#define F0900_P1_CAR2S2_16A_ALPH_M 0xf4990030
2805#define F0900_P1_CAR2S2_16A_ALPH_E 0xf499000f
2806
2807/*P1_ACLC2S232A*/
2808#define R0900_P1_ACLC2S232A 0xf49a
2809#define F0900_P1_CAR2S2_32ADERAT 0xf49a0040
2810#define F0900_P1_CAR2S2_32A_ALPH_M 0xf49a0030
2811#define F0900_P1_CAR2S2_32A_ALPH_E 0xf49a000f
2812
2813/*P1_BCLC2S2Q*/
2814#define R0900_P1_BCLC2S2Q 0xf49c
2815#define F0900_P1_DVBS2S2Q_NIP 0xf49c0080
2816#define F0900_P1_CAR2S2_QBDERAT 0xf49c0040
2817#define F0900_P1_CAR2S2_Q_BETA_M 0xf49c0030
2818#define F0900_P1_CAR2S2_Q_BETA_E 0xf49c000f
2819
2820/*P1_BCLC2S28*/
2821#define R0900_P1_BCLC2S28 0xf49d
2822#define F0900_P1_DVBS2S28_NIP 0xf49d0080
2823#define F0900_P1_CAR2S2_8BDERAT 0xf49d0040
2824#define F0900_P1_CAR2S2_8_BETA_M 0xf49d0030
2825#define F0900_P1_CAR2S2_8_BETA_E 0xf49d000f
2826
2827/*P1_BCLC2S216A*/
2828#define R0900_P1_BCLC2S216A 0xf49e
2829#define F0900_P1_DVBS2S216A_NIP 0xf49e0080
2830#define F0900_P1_CAR2S2_16BDERAT 0xf49e0040
2831#define F0900_P1_CAR2S2_16A_BETA_M 0xf49e0030
2832#define F0900_P1_CAR2S2_16A_BETA_E 0xf49e000f
2833
2834/*P1_BCLC2S232A*/
2835#define R0900_P1_BCLC2S232A 0xf49f
2836#define F0900_P1_DVBS2S232A_NIP 0xf49f0080
2837#define F0900_P1_CAR2S2_32BDERAT 0xf49f0040
2838#define F0900_P1_CAR2S2_32A_BETA_M 0xf49f0030
2839#define F0900_P1_CAR2S2_32A_BETA_E 0xf49f000f
2840
2841/*P1_PLROOT2*/
2842#define R0900_P1_PLROOT2 0xf4ac
2843#define F0900_P1_SHORTFR_DISABLE 0xf4ac0080
2844#define F0900_P1_LONGFR_DISABLE 0xf4ac0040
2845#define F0900_P1_DUMMYPL_DISABLE 0xf4ac0020
2846#define F0900_P1_SHORTFR_AVOID 0xf4ac0010
2847#define F0900_P1_PLSCRAMB_MODE 0xf4ac000c
2848#define F0900_P1_PLSCRAMB_ROOT2 0xf4ac0003
2849
2850/*P1_PLROOT1*/
2851#define R0900_P1_PLROOT1 0xf4ad
2852#define F0900_P1_PLSCRAMB_ROOT1 0xf4ad00ff
2853
2854/*P1_PLROOT0*/
2855#define R0900_P1_PLROOT0 0xf4ae
2856#define F0900_P1_PLSCRAMB_ROOT0 0xf4ae00ff
2857
2858/*P1_MODCODLST0*/
2859#define R0900_P1_MODCODLST0 0xf4b0
2860#define F0900_P1_EN_TOKEN31 0xf4b00080
2861#define F0900_P1_SYNCTAG_SELECT 0xf4b00040
2862#define F0900_P1_MODCODRQ_MODE 0xf4b00030
2863
2864/*P1_MODCODLST1*/
2865#define R0900_P1_MODCODLST1 0xf4b1
2866#define F0900_P1_DIS_MODCOD29 0xf4b100f0
2867#define F0900_P1_DIS_32PSK_9_10 0xf4b1000f
2868
2869/*P1_MODCODLST2*/
2870#define R0900_P1_MODCODLST2 0xf4b2
2871#define F0900_P1_DIS_32PSK_8_9 0xf4b200f0
2872#define F0900_P1_DIS_32PSK_5_6 0xf4b2000f
2873
2874/*P1_MODCODLST3*/
2875#define R0900_P1_MODCODLST3 0xf4b3
2876#define F0900_P1_DIS_32PSK_4_5 0xf4b300f0
2877#define F0900_P1_DIS_32PSK_3_4 0xf4b3000f
2878
2879/*P1_MODCODLST4*/
2880#define R0900_P1_MODCODLST4 0xf4b4
2881#define F0900_P1_DIS_16PSK_9_10 0xf4b400f0
2882#define F0900_P1_DIS_16PSK_8_9 0xf4b4000f
2883
2884/*P1_MODCODLST5*/
2885#define R0900_P1_MODCODLST5 0xf4b5
2886#define F0900_P1_DIS_16PSK_5_6 0xf4b500f0
2887#define F0900_P1_DIS_16PSK_4_5 0xf4b5000f
2888
2889/*P1_MODCODLST6*/
2890#define R0900_P1_MODCODLST6 0xf4b6
2891#define F0900_P1_DIS_16PSK_3_4 0xf4b600f0
2892#define F0900_P1_DIS_16PSK_2_3 0xf4b6000f
2893
2894/*P1_MODCODLST7*/
2895#define R0900_P1_MODCODLST7 0xf4b7
2896#define F0900_P1_DIS_8P_9_10 0xf4b700f0
2897#define F0900_P1_DIS_8P_8_9 0xf4b7000f
2898
2899/*P1_MODCODLST8*/
2900#define R0900_P1_MODCODLST8 0xf4b8
2901#define F0900_P1_DIS_8P_5_6 0xf4b800f0
2902#define F0900_P1_DIS_8P_3_4 0xf4b8000f
2903
2904/*P1_MODCODLST9*/
2905#define R0900_P1_MODCODLST9 0xf4b9
2906#define F0900_P1_DIS_8P_2_3 0xf4b900f0
2907#define F0900_P1_DIS_8P_3_5 0xf4b9000f
2908
2909/*P1_MODCODLSTA*/
2910#define R0900_P1_MODCODLSTA 0xf4ba
2911#define F0900_P1_DIS_QP_9_10 0xf4ba00f0
2912#define F0900_P1_DIS_QP_8_9 0xf4ba000f
2913
2914/*P1_MODCODLSTB*/
2915#define R0900_P1_MODCODLSTB 0xf4bb
2916#define F0900_P1_DIS_QP_5_6 0xf4bb00f0
2917#define F0900_P1_DIS_QP_4_5 0xf4bb000f
2918
2919/*P1_MODCODLSTC*/
2920#define R0900_P1_MODCODLSTC 0xf4bc
2921#define F0900_P1_DIS_QP_3_4 0xf4bc00f0
2922#define F0900_P1_DIS_QP_2_3 0xf4bc000f
2923
2924/*P1_MODCODLSTD*/
2925#define R0900_P1_MODCODLSTD 0xf4bd
2926#define F0900_P1_DIS_QP_3_5 0xf4bd00f0
2927#define F0900_P1_DIS_QP_1_2 0xf4bd000f
2928
2929/*P1_MODCODLSTE*/
2930#define R0900_P1_MODCODLSTE 0xf4be
2931#define F0900_P1_DIS_QP_2_5 0xf4be00f0
2932#define F0900_P1_DIS_QP_1_3 0xf4be000f
2933
2934/*P1_MODCODLSTF*/
2935#define R0900_P1_MODCODLSTF 0xf4bf
2936#define F0900_P1_DIS_QP_1_4 0xf4bf00f0
2937#define F0900_P1_DDEMOD_SET 0xf4bf0002
2938#define F0900_P1_DDEMOD_MASK 0xf4bf0001
2939
2940/*P1_DMDRESCFG*/
2941#define R0900_P1_DMDRESCFG 0xf4c6
2942#define F0900_P1_DMDRES_RESET 0xf4c60080
2943#define F0900_P1_DMDRES_NOISESQR 0xf4c60010
2944#define F0900_P1_DMDRES_STRALL 0xf4c60008
2945#define F0900_P1_DMDRES_NEWONLY 0xf4c60004
2946#define F0900_P1_DMDRES_NOSTORE 0xf4c60002
2947#define F0900_P1_DMDRES_AGC2MEM 0xf4c60001
2948
2949/*P1_DMDRESADR*/
2950#define R0900_P1_DMDRESADR 0xf4c7
2951#define F0900_P1_SUSP_PREDCANAL 0xf4c70080
2952#define F0900_P1_DMDRES_VALIDCFR 0xf4c70040
2953#define F0900_P1_DMDRES_MEMFULL 0xf4c70030
2954#define F0900_P1_DMDRES_RESNBR 0xf4c7000f
2955
2956/*P1_DMDRESDATA7*/
2957#define R0900_P1_DMDRESDATA7 0xf4c8
2958#define F0900_P1_DMDRES_DATA7 0xf4c800ff
2959
2960/*P1_DMDRESDATA6*/
2961#define R0900_P1_DMDRESDATA6 0xf4c9
2962#define F0900_P1_DMDRES_DATA6 0xf4c900ff
2963
2964/*P1_DMDRESDATA5*/
2965#define R0900_P1_DMDRESDATA5 0xf4ca
2966#define F0900_P1_DMDRES_DATA5 0xf4ca00ff
2967
2968/*P1_DMDRESDATA4*/
2969#define R0900_P1_DMDRESDATA4 0xf4cb
2970#define F0900_P1_DMDRES_DATA4 0xf4cb00ff
2971
2972/*P1_DMDRESDATA3*/
2973#define R0900_P1_DMDRESDATA3 0xf4cc
2974#define F0900_P1_DMDRES_DATA3 0xf4cc00ff
2975
2976/*P1_DMDRESDATA2*/
2977#define R0900_P1_DMDRESDATA2 0xf4cd
2978#define F0900_P1_DMDRES_DATA2 0xf4cd00ff
2979
2980/*P1_DMDRESDATA1*/
2981#define R0900_P1_DMDRESDATA1 0xf4ce
2982#define F0900_P1_DMDRES_DATA1 0xf4ce00ff
2983
2984/*P1_DMDRESDATA0*/
2985#define R0900_P1_DMDRESDATA0 0xf4cf
2986#define F0900_P1_DMDRES_DATA0 0xf4cf00ff
2987
2988/*P1_FFEI1*/
2989#define R0900_P1_FFEI1 0xf4d0
2990#define F0900_P1_FFE_ACCI1 0xf4d001ff
2991
2992/*P1_FFEQ1*/
2993#define R0900_P1_FFEQ1 0xf4d1
2994#define F0900_P1_FFE_ACCQ1 0xf4d101ff
2995
2996/*P1_FFEI2*/
2997#define R0900_P1_FFEI2 0xf4d2
2998#define F0900_P1_FFE_ACCI2 0xf4d201ff
2999
3000/*P1_FFEQ2*/
3001#define R0900_P1_FFEQ2 0xf4d3
3002#define F0900_P1_FFE_ACCQ2 0xf4d301ff
3003
3004/*P1_FFEI3*/
3005#define R0900_P1_FFEI3 0xf4d4
3006#define F0900_P1_FFE_ACCI3 0xf4d401ff
3007
3008/*P1_FFEQ3*/
3009#define R0900_P1_FFEQ3 0xf4d5
3010#define F0900_P1_FFE_ACCQ3 0xf4d501ff
3011
3012/*P1_FFEI4*/
3013#define R0900_P1_FFEI4 0xf4d6
3014#define F0900_P1_FFE_ACCI4 0xf4d601ff
3015
3016/*P1_FFEQ4*/
3017#define R0900_P1_FFEQ4 0xf4d7
3018#define F0900_P1_FFE_ACCQ4 0xf4d701ff
3019
3020/*P1_FFECFG*/
3021#define R0900_P1_FFECFG 0xf4d8
3022#define F0900_P1_EQUALFFE_ON 0xf4d80040
3023#define F0900_P1_EQUAL_USEDSYMB 0xf4d80030
3024#define F0900_P1_MU_EQUALFFE 0xf4d80007
3025
3026/*P1_TNRCFG*/
3027#define R0900_P1_TNRCFG 0xf4e0
3028#define F0900_P1_TUN_ACKFAIL 0xf4e00080
3029#define F0900_P1_TUN_TYPE 0xf4e00070
3030#define F0900_P1_TUN_SECSTOP 0xf4e00008
3031#define F0900_P1_TUN_VCOSRCH 0xf4e00004
3032#define F0900_P1_TUN_MADDRESS 0xf4e00003
3033
3034/*P1_TNRCFG2*/
3035#define R0900_P1_TNRCFG2 0xf4e1
3036#define F0900_P1_TUN_IQSWAP 0xf4e10080
3037#define F0900_P1_STB6110_STEP2MHZ 0xf4e10040
3038#define F0900_P1_STB6120_DBLI2C 0xf4e10020
3039#define F0900_P1_DIS_FCCK 0xf4e10010
3040#define F0900_P1_DIS_LPEN 0xf4e10008
3041#define F0900_P1_DIS_BWCALC 0xf4e10004
3042#define F0900_P1_SHORT_WAITSTATES 0xf4e10002
3043#define F0900_P1_DIS_2BWAGC1 0xf4e10001
3044
3045/*P1_TNRXTAL*/
3046#define R0900_P1_TNRXTAL 0xf4e4
3047#define F0900_P1_TUN_MCLKDECIMAL 0xf4e400e0
3048#define F0900_P1_TUN_XTALFREQ 0xf4e4001f
3049
3050/*P1_TNRSTEPS*/
3051#define R0900_P1_TNRSTEPS 0xf4e7
3052#define F0900_P1_TUNER_BW1P6 0xf4e70080
3053#define F0900_P1_BWINC_OFFSET 0xf4e70070
3054#define F0900_P1_SOFTSTEP_RNG 0xf4e70008
3055#define F0900_P1_TUN_BWOFFSET 0xf4e70107
3056
3057/*P1_TNRGAIN*/
3058#define R0900_P1_TNRGAIN 0xf4e8
3059#define F0900_P1_TUN_KDIVEN 0xf4e800c0
3060#define F0900_P1_STB6X00_OCK 0xf4e80030
3061#define F0900_P1_TUN_GAIN 0xf4e8000f
3062
3063/*P1_TNRRF1*/
3064#define R0900_P1_TNRRF1 0xf4e9
3065#define F0900_P1_TUN_RFFREQ2 0xf4e900ff
3066
3067/*P1_TNRRF0*/
3068#define R0900_P1_TNRRF0 0xf4ea
3069#define F0900_P1_TUN_RFFREQ1 0xf4ea00ff
3070
3071/*P1_TNRBW*/
3072#define R0900_P1_TNRBW 0xf4eb
3073#define F0900_P1_TUN_RFFREQ0 0xf4eb00c0
3074#define F0900_P1_TUN_BW 0xf4eb003f
3075
3076/*P1_TNRADJ*/
3077#define R0900_P1_TNRADJ 0xf4ec
3078#define F0900_P1_STB61X0_RCLK 0xf4ec0080
3079#define F0900_P1_STB61X0_CALTIME 0xf4ec0040
3080#define F0900_P1_STB6X00_DLB 0xf4ec0038
3081#define F0900_P1_STB6000_FCL 0xf4ec0007
3082
3083/*P1_TNRCTL2*/
3084#define R0900_P1_TNRCTL2 0xf4ed
3085#define F0900_P1_STB61X0_LCP1_RCCKOFF 0xf4ed0080
3086#define F0900_P1_STB61X0_LCP0 0xf4ed0040
3087#define F0900_P1_STB61X0_XTOUT_RFOUTS 0xf4ed0020
3088#define F0900_P1_STB61X0_XTON_MCKDV 0xf4ed0010
3089#define F0900_P1_STB61X0_CALOFF_DCOFF 0xf4ed0008
3090#define F0900_P1_STB6110_LPT 0xf4ed0004
3091#define F0900_P1_STB6110_RX 0xf4ed0002
3092#define F0900_P1_STB6110_SYN 0xf4ed0001
3093
3094/*P1_TNRCFG3*/
3095#define R0900_P1_TNRCFG3 0xf4ee
3096#define F0900_P1_STB6120_DISCTRL1 0xf4ee0080
3097#define F0900_P1_STB6120_INVORDER 0xf4ee0040
3098#define F0900_P1_STB6120_ENCTRL6 0xf4ee0020
3099#define F0900_P1_TUN_PLLFREQ 0xf4ee001c
3100#define F0900_P1_TUN_I2CFREQ_MODE 0xf4ee0003
3101
3102/*P1_TNRLAUNCH*/
3103#define R0900_P1_TNRLAUNCH 0xf4f0
3104
3105/*P1_TNRLD*/
3106#define R0900_P1_TNRLD 0xf4f0
3107#define F0900_P1_TUNLD_VCOING 0xf4f00080
3108#define F0900_P1_TUN_REG1FAIL 0xf4f00040
3109#define F0900_P1_TUN_REG2FAIL 0xf4f00020
3110#define F0900_P1_TUN_REG3FAIL 0xf4f00010
3111#define F0900_P1_TUN_REG4FAIL 0xf4f00008
3112#define F0900_P1_TUN_REG5FAIL 0xf4f00004
3113#define F0900_P1_TUN_BWING 0xf4f00002
3114#define F0900_P1_TUN_LOCKED 0xf4f00001
3115
3116/*P1_TNROBSL*/
3117#define R0900_P1_TNROBSL 0xf4f6
3118#define F0900_P1_TUN_I2CABORTED 0xf4f60080
3119#define F0900_P1_TUN_LPEN 0xf4f60040
3120#define F0900_P1_TUN_FCCK 0xf4f60020
3121#define F0900_P1_TUN_I2CLOCKED 0xf4f60010
3122#define F0900_P1_TUN_PROGDONE 0xf4f6000c
3123#define F0900_P1_TUN_RFRESTE1 0xf4f60003
3124
3125/*P1_TNRRESTE*/
3126#define R0900_P1_TNRRESTE 0xf4f7
3127#define F0900_P1_TUN_RFRESTE0 0xf4f700ff
3128
3129/*P1_SMAPCOEF7*/
3130#define R0900_P1_SMAPCOEF7 0xf500
3131#define F0900_P1_DIS_QSCALE 0xf5000080
3132#define F0900_P1_SMAPCOEF_Q_LLR12 0xf500017f
3133
3134/*P1_SMAPCOEF6*/
3135#define R0900_P1_SMAPCOEF6 0xf501
3136#define F0900_P1_DIS_NEWSCALE 0xf5010008
3137#define F0900_P1_ADJ_8PSKLLR1 0xf5010004
3138#define F0900_P1_OLD_8PSKLLR1 0xf5010002
3139#define F0900_P1_DIS_AB8PSK 0xf5010001
3140
3141/*P1_SMAPCOEF5*/
3142#define R0900_P1_SMAPCOEF5 0xf502
3143#define F0900_P1_DIS_8SCALE 0xf5020080
3144#define F0900_P1_SMAPCOEF_8P_LLR23 0xf502017f
3145
3146/*P1_DMDPLHSTAT*/
3147#define R0900_P1_DMDPLHSTAT 0xf520
3148#define F0900_P1_PLH_STATISTIC 0xf52000ff
3149
3150/*P1_LOCKTIME3*/
3151#define R0900_P1_LOCKTIME3 0xf522
3152#define F0900_P1_DEMOD_LOCKTIME3 0xf52200ff
3153
3154/*P1_LOCKTIME2*/
3155#define R0900_P1_LOCKTIME2 0xf523
3156#define F0900_P1_DEMOD_LOCKTIME2 0xf52300ff
3157
3158/*P1_LOCKTIME1*/
3159#define R0900_P1_LOCKTIME1 0xf524
3160#define F0900_P1_DEMOD_LOCKTIME1 0xf52400ff
3161
3162/*P1_LOCKTIME0*/
3163#define R0900_P1_LOCKTIME0 0xf525
3164#define F0900_P1_DEMOD_LOCKTIME0 0xf52500ff
3165
3166/*P1_VITSCALE*/
3167#define R0900_P1_VITSCALE 0xf532
3168#define F0900_P1_NVTH_NOSRANGE 0xf5320080
3169#define F0900_P1_VERROR_MAXMODE 0xf5320040
3170#define F0900_P1_KDIV_MODE 0xf5320030
3171#define F0900_P1_NSLOWSN_LOCKED 0xf5320008
3172#define F0900_P1_DELOCK_PRFLOSS 0xf5320004
3173#define F0900_P1_DIS_RSFLOCK 0xf5320002
3174
3175/*P1_FECM*/
3176#define R0900_P1_FECM 0xf533
3177#define F0900_P1_DSS_DVB 0xf5330080
3178#define F0900_P1_DEMOD_BYPASS 0xf5330040
3179#define F0900_P1_CMP_SLOWMODE 0xf5330020
3180#define F0900_P1_DSS_SRCH 0xf5330010
3181#define F0900_P1_DIFF_MODEVIT 0xf5330004
3182#define F0900_P1_SYNCVIT 0xf5330002
3183#define F0900_P1_IQINV 0xf5330001
3184
3185/*P1_VTH12*/
3186#define R0900_P1_VTH12 0xf534
3187#define F0900_P1_VTH12 0xf53400ff
3188
3189/*P1_VTH23*/
3190#define R0900_P1_VTH23 0xf535
3191#define F0900_P1_VTH23 0xf53500ff
3192
3193/*P1_VTH34*/
3194#define R0900_P1_VTH34 0xf536
3195#define F0900_P1_VTH34 0xf53600ff
3196
3197/*P1_VTH56*/
3198#define R0900_P1_VTH56 0xf537
3199#define F0900_P1_VTH56 0xf53700ff
3200
3201/*P1_VTH67*/
3202#define R0900_P1_VTH67 0xf538
3203#define F0900_P1_VTH67 0xf53800ff
3204
3205/*P1_VTH78*/
3206#define R0900_P1_VTH78 0xf539
3207#define F0900_P1_VTH78 0xf53900ff
3208
3209/*P1_VITCURPUN*/
3210#define R0900_P1_VITCURPUN 0xf53a
3211#define F0900_P1_VIT_MAPPING 0xf53a00e0
3212#define F0900_P1_VIT_CURPUN 0xf53a001f
3213
3214/*P1_VERROR*/
3215#define R0900_P1_VERROR 0xf53b
3216#define F0900_P1_REGERR_VIT 0xf53b00ff
3217
3218/*P1_PRVIT*/
3219#define R0900_P1_PRVIT 0xf53c
3220#define F0900_P1_DIS_VTHLOCK 0xf53c0040
3221#define F0900_P1_E7_8VIT 0xf53c0020
3222#define F0900_P1_E6_7VIT 0xf53c0010
3223#define F0900_P1_E5_6VIT 0xf53c0008
3224#define F0900_P1_E3_4VIT 0xf53c0004
3225#define F0900_P1_E2_3VIT 0xf53c0002
3226#define F0900_P1_E1_2VIT 0xf53c0001
3227
3228/*P1_VAVSRVIT*/
3229#define R0900_P1_VAVSRVIT 0xf53d
3230#define F0900_P1_AMVIT 0xf53d0080
3231#define F0900_P1_FROZENVIT 0xf53d0040
3232#define F0900_P1_SNVIT 0xf53d0030
3233#define F0900_P1_TOVVIT 0xf53d000c
3234#define F0900_P1_HYPVIT 0xf53d0003
3235
3236/*P1_VSTATUSVIT*/
3237#define R0900_P1_VSTATUSVIT 0xf53e
3238#define F0900_P1_VITERBI_ON 0xf53e0080
3239#define F0900_P1_END_LOOPVIT 0xf53e0040
3240#define F0900_P1_VITERBI_DEPRF 0xf53e0020
3241#define F0900_P1_PRFVIT 0xf53e0010
3242#define F0900_P1_LOCKEDVIT 0xf53e0008
3243#define F0900_P1_VITERBI_DELOCK 0xf53e0004
3244#define F0900_P1_VIT_DEMODSEL 0xf53e0002
3245#define F0900_P1_VITERBI_COMPOUT 0xf53e0001
3246
3247/*P1_VTHINUSE*/
3248#define R0900_P1_VTHINUSE 0xf53f
3249#define F0900_P1_VIT_INUSE 0xf53f00ff
3250
3251/*P1_KDIV12*/
3252#define R0900_P1_KDIV12 0xf540
3253#define F0900_P1_KDIV12_MANUAL 0xf5400080
3254#define F0900_P1_K_DIVIDER_12 0xf540007f
3255
3256/*P1_KDIV23*/
3257#define R0900_P1_KDIV23 0xf541
3258#define F0900_P1_KDIV23_MANUAL 0xf5410080
3259#define F0900_P1_K_DIVIDER_23 0xf541007f
3260
3261/*P1_KDIV34*/
3262#define R0900_P1_KDIV34 0xf542
3263#define F0900_P1_KDIV34_MANUAL 0xf5420080
3264#define F0900_P1_K_DIVIDER_34 0xf542007f
3265
3266/*P1_KDIV56*/
3267#define R0900_P1_KDIV56 0xf543
3268#define F0900_P1_KDIV56_MANUAL 0xf5430080
3269#define F0900_P1_K_DIVIDER_56 0xf543007f
3270
3271/*P1_KDIV67*/
3272#define R0900_P1_KDIV67 0xf544
3273#define F0900_P1_KDIV67_MANUAL 0xf5440080
3274#define F0900_P1_K_DIVIDER_67 0xf544007f
3275
3276/*P1_KDIV78*/
3277#define R0900_P1_KDIV78 0xf545
3278#define F0900_P1_KDIV78_MANUAL 0xf5450080
3279#define F0900_P1_K_DIVIDER_78 0xf545007f
3280
3281/*P1_PDELCTRL1*/
3282#define R0900_P1_PDELCTRL1 0xf550
3283#define F0900_P1_INV_MISMASK 0xf5500080
3284#define F0900_P1_FORCE_ACCEPTED 0xf5500040
3285#define F0900_P1_FILTER_EN 0xf5500020
3286#define F0900_P1_FORCE_PKTDELINUSE 0xf5500010
3287#define F0900_P1_HYSTEN 0xf5500008
3288#define F0900_P1_HYSTSWRST 0xf5500004
3289#define F0900_P1_EN_MIS00 0xf5500002
3290#define F0900_P1_ALGOSWRST 0xf5500001
3291
3292/*P1_PDELCTRL2*/
3293#define R0900_P1_PDELCTRL2 0xf551
3294#define F0900_P1_FORCE_CONTINUOUS 0xf5510080
3295#define F0900_P1_RESET_UPKO_COUNT 0xf5510040
3296#define F0900_P1_USER_PKTDELIN_NB 0xf5510020
3297#define F0900_P1_FORCE_LOCKED 0xf5510010
3298#define F0900_P1_DATA_UNBBSCRAM 0xf5510008
3299#define F0900_P1_FORCE_LONGPKT 0xf5510004
3300#define F0900_P1_FRAME_MODE 0xf5510002
3301
3302/*P1_HYSTTHRESH*/
3303#define R0900_P1_HYSTTHRESH 0xf554
3304#define F0900_P1_UNLCK_THRESH 0xf55400f0
3305#define F0900_P1_DELIN_LCK_THRESH 0xf554000f
3306
3307/*P1_ISIENTRY*/
3308#define R0900_P1_ISIENTRY 0xf55e
3309#define F0900_P1_ISI_ENTRY 0xf55e00ff
3310
3311/*P1_ISIBITENA*/
3312#define R0900_P1_ISIBITENA 0xf55f
3313#define F0900_P1_ISI_BIT_EN 0xf55f00ff
3314
3315/*P1_MATSTR1*/
3316#define R0900_P1_MATSTR1 0xf560
3317#define F0900_P1_MATYPE_CURRENT1 0xf56000ff
3318
3319/*P1_MATSTR0*/
3320#define R0900_P1_MATSTR0 0xf561
3321#define F0900_P1_MATYPE_CURRENT0 0xf56100ff
3322
3323/*P1_UPLSTR1*/
3324#define R0900_P1_UPLSTR1 0xf562
3325#define F0900_P1_UPL_CURRENT1 0xf56200ff
3326
3327/*P1_UPLSTR0*/
3328#define R0900_P1_UPLSTR0 0xf563
3329#define F0900_P1_UPL_CURRENT0 0xf56300ff
3330
3331/*P1_DFLSTR1*/
3332#define R0900_P1_DFLSTR1 0xf564
3333#define F0900_P1_DFL_CURRENT1 0xf56400ff
3334
3335/*P1_DFLSTR0*/
3336#define R0900_P1_DFLSTR0 0xf565
3337#define F0900_P1_DFL_CURRENT0 0xf56500ff
3338
3339/*P1_SYNCSTR*/
3340#define R0900_P1_SYNCSTR 0xf566
3341#define F0900_P1_SYNC_CURRENT 0xf56600ff
3342
3343/*P1_SYNCDSTR1*/
3344#define R0900_P1_SYNCDSTR1 0xf567
3345#define F0900_P1_SYNCD_CURRENT1 0xf56700ff
3346
3347/*P1_SYNCDSTR0*/
3348#define R0900_P1_SYNCDSTR0 0xf568
3349#define F0900_P1_SYNCD_CURRENT0 0xf56800ff
3350
3351/*P1_PDELSTATUS1*/
3352#define R0900_P1_PDELSTATUS1 0xf569
3353#define F0900_P1_PKTDELIN_DELOCK 0xf5690080
3354#define F0900_P1_SYNCDUPDFL_BADDFL 0xf5690040
3355#define F0900_P1_CONTINUOUS_STREAM 0xf5690020
3356#define F0900_P1_UNACCEPTED_STREAM 0xf5690010
3357#define F0900_P1_BCH_ERROR_FLAG 0xf5690008
3358#define F0900_P1_BBHCRCKO 0xf5690004
3359#define F0900_P1_PKTDELIN_LOCK 0xf5690002
3360#define F0900_P1_FIRST_LOCK 0xf5690001
3361
3362/*P1_PDELSTATUS2*/
3363#define R0900_P1_PDELSTATUS2 0xf56a
3364#define F0900_P1_PKTDEL_DEMODSEL 0xf56a0080
3365#define F0900_P1_FRAME_MODCOD 0xf56a007c
3366#define F0900_P1_FRAME_TYPE 0xf56a0003
3367
3368/*P1_BBFCRCKO1*/
3369#define R0900_P1_BBFCRCKO1 0xf56b
3370#define F0900_P1_BBHCRC_KOCNT1 0xf56b00ff
3371
3372/*P1_BBFCRCKO0*/
3373#define R0900_P1_BBFCRCKO0 0xf56c
3374#define F0900_P1_BBHCRC_KOCNT0 0xf56c00ff
3375
3376/*P1_UPCRCKO1*/
3377#define R0900_P1_UPCRCKO1 0xf56d
3378#define F0900_P1_PKTCRC_KOCNT1 0xf56d00ff
3379
3380/*P1_UPCRCKO0*/
3381#define R0900_P1_UPCRCKO0 0xf56e
3382#define F0900_P1_PKTCRC_KOCNT0 0xf56e00ff
3383
3384/*P1_TSSTATEM*/
3385#define R0900_P1_TSSTATEM 0xf570
3386#define F0900_P1_TSDIL_ON 0xf5700080
3387#define F0900_P1_TSSKIPRS_ON 0xf5700040
3388#define F0900_P1_TSRS_ON 0xf5700020
3389#define F0900_P1_TSDESCRAMB_ON 0xf5700010
3390#define F0900_P1_TSFRAME_MODE 0xf5700008
3391#define F0900_P1_TS_DISABLE 0xf5700004
3392#define F0900_P1_TSACM_MODE 0xf5700002
3393#define F0900_P1_TSOUT_NOSYNC 0xf5700001
3394
3395/*P1_TSCFGH*/
3396#define R0900_P1_TSCFGH 0xf572
3397#define F0900_P1_TSFIFO_DVBCI 0xf5720080
3398#define F0900_P1_TSFIFO_SERIAL 0xf5720040
3399#define F0900_P1_TSFIFO_TEIUPDATE 0xf5720020
3400#define F0900_P1_TSFIFO_DUTY50 0xf5720010
3401#define F0900_P1_TSFIFO_HSGNLOUT 0xf5720008
3402#define F0900_P1_TSFIFO_ERRMODE 0xf5720006
3403#define F0900_P1_RST_HWARE 0xf5720001
3404
3405/*P1_TSCFGM*/
3406#define R0900_P1_TSCFGM 0xf573
3407#define F0900_P1_TSFIFO_MANSPEED 0xf57300c0
3408#define F0900_P1_TSFIFO_PERMDATA 0xf5730020
3409#define F0900_P1_TSFIFO_NONEWSGNL 0xf5730010
3410#define F0900_P1_TSFIFO_BITSPEED 0xf5730008
3411#define F0900_P1_NPD_SPECDVBS2 0xf5730004
3412#define F0900_P1_TSFIFO_STOPCKDIS 0xf5730002
3413#define F0900_P1_TSFIFO_INVDATA 0xf5730001
3414
3415/*P1_TSCFGL*/
3416#define R0900_P1_TSCFGL 0xf574
3417#define F0900_P1_TSFIFO_BCLKDEL1CK 0xf57400c0
3418#define F0900_P1_BCHERROR_MODE 0xf5740030
3419#define F0900_P1_TSFIFO_NSGNL2DATA 0xf5740008
3420#define F0900_P1_TSFIFO_EMBINDVB 0xf5740004
3421#define F0900_P1_TSFIFO_DPUNACT 0xf5740002
3422#define F0900_P1_TSFIFO_NPDOFF 0xf5740001
3423
3424/*P1_TSINSDELH*/
3425#define R0900_P1_TSINSDELH 0xf576
3426#define F0900_P1_TSDEL_SYNCBYTE 0xf5760080
3427#define F0900_P1_TSDEL_XXHEADER 0xf5760040
3428#define F0900_P1_TSDEL_BBHEADER 0xf5760020
3429#define F0900_P1_TSDEL_DATAFIELD 0xf5760010
3430#define F0900_P1_TSINSDEL_ISCR 0xf5760008
3431#define F0900_P1_TSINSDEL_NPD 0xf5760004
3432#define F0900_P1_TSINSDEL_RSPARITY 0xf5760002
3433#define F0900_P1_TSINSDEL_CRC8 0xf5760001
3434
3435/*P1_TSSPEED*/
3436#define R0900_P1_TSSPEED 0xf580
3437#define F0900_P1_TSFIFO_OUTSPEED 0xf58000ff
3438
3439/*P1_TSSTATUS*/
3440#define R0900_P1_TSSTATUS 0xf581
3441#define F0900_P1_TSFIFO_LINEOK 0xf5810080
3442#define F0900_P1_TSFIFO_ERROR 0xf5810040
3443#define F0900_P1_TSFIFO_DATA7 0xf5810020
3444#define F0900_P1_TSFIFO_NOSYNC 0xf5810010
3445#define F0900_P1_ISCR_INITIALIZED 0xf5810008
3446#define F0900_P1_ISCR_UPDATED 0xf5810004
3447#define F0900_P1_SOFFIFO_UNREGUL 0xf5810002
3448#define F0900_P1_DIL_READY 0xf5810001
3449
3450/*P1_TSSTATUS2*/
3451#define R0900_P1_TSSTATUS2 0xf582
3452#define F0900_P1_TSFIFO_DEMODSEL 0xf5820080
3453#define F0900_P1_TSFIFOSPEED_STORE 0xf5820040
3454#define F0900_P1_DILXX_RESET 0xf5820020
3455#define F0900_P1_TSSERIAL_IMPOS 0xf5820010
3456#define F0900_P1_TSFIFO_LINENOK 0xf5820008
3457#define F0900_P1_BITSPEED_EVENT 0xf5820004
3458#define F0900_P1_SCRAMBDETECT 0xf5820002
3459#define F0900_P1_ULDTV67_FALSELOCK 0xf5820001
3460
3461/*P1_TSBITRATE1*/
3462#define R0900_P1_TSBITRATE1 0xf583
3463#define F0900_P1_TSFIFO_BITRATE1 0xf58300ff
3464
3465/*P1_TSBITRATE0*/
3466#define R0900_P1_TSBITRATE0 0xf584
3467#define F0900_P1_TSFIFO_BITRATE0 0xf58400ff
3468
3469/*P1_ERRCTRL1*/
3470#define R0900_P1_ERRCTRL1 0xf598
3471#define F0900_P1_ERR_SOURCE1 0xf59800f0
3472#define F0900_P1_NUM_EVENT1 0xf5980007
3473
3474/*P1_ERRCNT12*/
3475#define R0900_P1_ERRCNT12 0xf599
3476#define F0900_P1_ERRCNT1_OLDVALUE 0xf5990080
3477#define F0900_P1_ERR_CNT12 0xf599007f
3478
3479/*P1_ERRCNT11*/
3480#define R0900_P1_ERRCNT11 0xf59a
3481#define F0900_P1_ERR_CNT11 0xf59a00ff
3482
3483/*P1_ERRCNT10*/
3484#define R0900_P1_ERRCNT10 0xf59b
3485#define F0900_P1_ERR_CNT10 0xf59b00ff
3486
3487/*P1_ERRCTRL2*/
3488#define R0900_P1_ERRCTRL2 0xf59c
3489#define F0900_P1_ERR_SOURCE2 0xf59c00f0
3490#define F0900_P1_NUM_EVENT2 0xf59c0007
3491
3492/*P1_ERRCNT22*/
3493#define R0900_P1_ERRCNT22 0xf59d
3494#define F0900_P1_ERRCNT2_OLDVALUE 0xf59d0080
3495#define F0900_P1_ERR_CNT22 0xf59d007f
3496
3497/*P1_ERRCNT21*/
3498#define R0900_P1_ERRCNT21 0xf59e
3499#define F0900_P1_ERR_CNT21 0xf59e00ff
3500
3501/*P1_ERRCNT20*/
3502#define R0900_P1_ERRCNT20 0xf59f
3503#define F0900_P1_ERR_CNT20 0xf59f00ff
3504
3505/*P1_FECSPY*/
3506#define R0900_P1_FECSPY 0xf5a0
3507#define F0900_P1_SPY_ENABLE 0xf5a00080
3508#define F0900_P1_NO_SYNCBYTE 0xf5a00040
3509#define F0900_P1_SERIAL_MODE 0xf5a00020
3510#define F0900_P1_UNUSUAL_PACKET 0xf5a00010
3511#define F0900_P1_BER_PACKMODE 0xf5a00008
3512#define F0900_P1_BERMETER_LMODE 0xf5a00002
3513#define F0900_P1_BERMETER_RESET 0xf5a00001
3514
3515/*P1_FSPYCFG*/
3516#define R0900_P1_FSPYCFG 0xf5a1
3517#define F0900_P1_FECSPY_INPUT 0xf5a100c0
3518#define F0900_P1_RST_ON_ERROR 0xf5a10020
3519#define F0900_P1_ONE_SHOT 0xf5a10010
3520#define F0900_P1_I2C_MODE 0xf5a1000c
3521#define F0900_P1_SPY_HYSTERESIS 0xf5a10003
3522
3523/*P1_FSPYDATA*/
3524#define R0900_P1_FSPYDATA 0xf5a2
3525#define F0900_P1_SPY_STUFFING 0xf5a20080
3526#define F0900_P1_NOERROR_PKTJITTER 0xf5a20040
3527#define F0900_P1_SPY_CNULLPKT 0xf5a20020
3528#define F0900_P1_SPY_OUTDATA_MODE 0xf5a2001f
3529
3530/*P1_FSPYOUT*/
3531#define R0900_P1_FSPYOUT 0xf5a3
3532#define F0900_P1_FSPY_DIRECT 0xf5a30080
3533#define F0900_P1_SPY_OUTDATA_BUS 0xf5a30038
3534#define F0900_P1_STUFF_MODE 0xf5a30007
3535
3536/*P1_FSTATUS*/
3537#define R0900_P1_FSTATUS 0xf5a4
3538#define F0900_P1_SPY_ENDSIM 0xf5a40080
3539#define F0900_P1_VALID_SIM 0xf5a40040
3540#define F0900_P1_FOUND_SIGNAL 0xf5a40020
3541#define F0900_P1_DSS_SYNCBYTE 0xf5a40010
3542#define F0900_P1_RESULT_STATE 0xf5a4000f
3543
3544/*P1_FBERCPT4*/
3545#define R0900_P1_FBERCPT4 0xf5a8
3546#define F0900_P1_FBERMETER_CPT4 0xf5a800ff
3547
3548/*P1_FBERCPT3*/
3549#define R0900_P1_FBERCPT3 0xf5a9
3550#define F0900_P1_FBERMETER_CPT3 0xf5a900ff
3551
3552/*P1_FBERCPT2*/
3553#define R0900_P1_FBERCPT2 0xf5aa
3554#define F0900_P1_FBERMETER_CPT2 0xf5aa00ff
3555
3556/*P1_FBERCPT1*/
3557#define R0900_P1_FBERCPT1 0xf5ab
3558#define F0900_P1_FBERMETER_CPT1 0xf5ab00ff
3559
3560/*P1_FBERCPT0*/
3561#define R0900_P1_FBERCPT0 0xf5ac
3562#define F0900_P1_FBERMETER_CPT0 0xf5ac00ff
3563
3564/*P1_FBERERR2*/
3565#define R0900_P1_FBERERR2 0xf5ad
3566#define F0900_P1_FBERMETER_ERR2 0xf5ad00ff
3567
3568/*P1_FBERERR1*/
3569#define R0900_P1_FBERERR1 0xf5ae
3570#define F0900_P1_FBERMETER_ERR1 0xf5ae00ff
3571
3572/*P1_FBERERR0*/
3573#define R0900_P1_FBERERR0 0xf5af
3574#define F0900_P1_FBERMETER_ERR0 0xf5af00ff
3575
3576/*P1_FSPYBER*/
3577#define R0900_P1_FSPYBER 0xf5b2
3578#define F0900_P1_FSPYOBS_XORREAD 0xf5b20040
3579#define F0900_P1_FSPYBER_OBSMODE 0xf5b20020
3580#define F0900_P1_FSPYBER_SYNCBYTE 0xf5b20010
3581#define F0900_P1_FSPYBER_UNSYNC 0xf5b20008
3582#define F0900_P1_FSPYBER_CTIME 0xf5b20007
3583
3584/*RCCFGH*/
3585#define R0900_RCCFGH 0xf600
3586#define F0900_TSRCFIFO_DVBCI 0xf6000080
3587#define F0900_TSRCFIFO_SERIAL 0xf6000040
3588#define F0900_TSRCFIFO_DISABLE 0xf6000020
3589#define F0900_TSFIFO_2TORC 0xf6000010
3590#define F0900_TSRCFIFO_HSGNLOUT 0xf6000008
3591#define F0900_TSRCFIFO_ERRMODE 0xf6000006
3592
3593/*TSGENERAL*/
3594#define R0900_TSGENERAL 0xf630
3595#define F0900_TSFIFO_BCLK1ALL 0xf6300020
3596#define F0900_MUXSTREAM_OUTMODE 0xf6300008
3597#define F0900_TSFIFO_PERMPARAL 0xf6300006
3598#define F0900_RST_REEDSOLO 0xf6300001
3599
3600/*TSGENERAL1X*/
3601#define R0900_TSGENERAL1X 0xf670
3602#define F0900_TSFIFO1X_BCLK1ALL 0xf6700020
3603#define F0900_MUXSTREAM1X_OUTMODE 0xf6700008
3604#define F0900_TSFIFO1X_PERMPARAL 0xf6700006
3605#define F0900_RST1X_REEDSOLO 0xf6700001
3606
3607/*NBITER_NF4*/
3608#define R0900_NBITER_NF4 0xfa03
3609#define F0900_NBITER_NF_QP_1_2 0xfa0300ff
3610
3611/*NBITER_NF5*/
3612#define R0900_NBITER_NF5 0xfa04
3613#define F0900_NBITER_NF_QP_3_5 0xfa0400ff
3614
3615/*NBITER_NF6*/
3616#define R0900_NBITER_NF6 0xfa05
3617#define F0900_NBITER_NF_QP_2_3 0xfa0500ff
3618
3619/*NBITER_NF7*/
3620#define R0900_NBITER_NF7 0xfa06
3621#define F0900_NBITER_NF_QP_3_4 0xfa0600ff
3622
3623/*NBITER_NF8*/
3624#define R0900_NBITER_NF8 0xfa07
3625#define F0900_NBITER_NF_QP_4_5 0xfa0700ff
3626
3627/*NBITER_NF9*/
3628#define R0900_NBITER_NF9 0xfa08
3629#define F0900_NBITER_NF_QP_5_6 0xfa0800ff
3630
3631/*NBITER_NF10*/
3632#define R0900_NBITER_NF10 0xfa09
3633#define F0900_NBITER_NF_QP_8_9 0xfa0900ff
3634
3635/*NBITER_NF11*/
3636#define R0900_NBITER_NF11 0xfa0a
3637#define F0900_NBITER_NF_QP_9_10 0xfa0a00ff
3638
3639/*NBITER_NF12*/
3640#define R0900_NBITER_NF12 0xfa0b
3641#define F0900_NBITER_NF_8P_3_5 0xfa0b00ff
3642
3643/*NBITER_NF13*/
3644#define R0900_NBITER_NF13 0xfa0c
3645#define F0900_NBITER_NF_8P_2_3 0xfa0c00ff
3646
3647/*NBITER_NF14*/
3648#define R0900_NBITER_NF14 0xfa0d
3649#define F0900_NBITER_NF_8P_3_4 0xfa0d00ff
3650
3651/*NBITER_NF15*/
3652#define R0900_NBITER_NF15 0xfa0e
3653#define F0900_NBITER_NF_8P_5_6 0xfa0e00ff
3654
3655/*NBITER_NF16*/
3656#define R0900_NBITER_NF16 0xfa0f
3657#define F0900_NBITER_NF_8P_8_9 0xfa0f00ff
3658
3659/*NBITER_NF17*/
3660#define R0900_NBITER_NF17 0xfa10
3661#define F0900_NBITER_NF_8P_9_10 0xfa1000ff
3662
3663/*NBITERNOERR*/
3664#define R0900_NBITERNOERR 0xfa3f
3665#define F0900_NBITER_STOP_CRIT 0xfa3f000f
3666
3667/*GAINLLR_NF4*/
3668#define R0900_GAINLLR_NF4 0xfa43
3669#define F0900_GAINLLR_NF_QP_1_2 0xfa43007f
3670
3671/*GAINLLR_NF5*/
3672#define R0900_GAINLLR_NF5 0xfa44
3673#define F0900_GAINLLR_NF_QP_3_5 0xfa44007f
3674
3675/*GAINLLR_NF6*/
3676#define R0900_GAINLLR_NF6 0xfa45
3677#define F0900_GAINLLR_NF_QP_2_3 0xfa45007f
3678
3679/*GAINLLR_NF7*/
3680#define R0900_GAINLLR_NF7 0xfa46
3681#define F0900_GAINLLR_NF_QP_3_4 0xfa46007f
3682
3683/*GAINLLR_NF8*/
3684#define R0900_GAINLLR_NF8 0xfa47
3685#define F0900_GAINLLR_NF_QP_4_5 0xfa47007f
3686
3687/*GAINLLR_NF9*/
3688#define R0900_GAINLLR_NF9 0xfa48
3689#define F0900_GAINLLR_NF_QP_5_6 0xfa48007f
3690
3691/*GAINLLR_NF10*/
3692#define R0900_GAINLLR_NF10 0xfa49
3693#define F0900_GAINLLR_NF_QP_8_9 0xfa49007f
3694
3695/*GAINLLR_NF11*/
3696#define R0900_GAINLLR_NF11 0xfa4a
3697#define F0900_GAINLLR_NF_QP_9_10 0xfa4a007f
3698
3699/*GAINLLR_NF12*/
3700#define R0900_GAINLLR_NF12 0xfa4b
3701#define F0900_GAINLLR_NF_8P_3_5 0xfa4b007f
3702
3703/*GAINLLR_NF13*/
3704#define R0900_GAINLLR_NF13 0xfa4c
3705#define F0900_GAINLLR_NF_8P_2_3 0xfa4c007f
3706
3707/*GAINLLR_NF14*/
3708#define R0900_GAINLLR_NF14 0xfa4d
3709#define F0900_GAINLLR_NF_8P_3_4 0xfa4d007f
3710
3711/*GAINLLR_NF15*/
3712#define R0900_GAINLLR_NF15 0xfa4e
3713#define F0900_GAINLLR_NF_8P_5_6 0xfa4e007f
3714
3715/*GAINLLR_NF16*/
3716#define R0900_GAINLLR_NF16 0xfa4f
3717#define F0900_GAINLLR_NF_8P_8_9 0xfa4f007f
3718
3719/*GAINLLR_NF17*/
3720#define R0900_GAINLLR_NF17 0xfa50
3721#define F0900_GAINLLR_NF_8P_9_10 0xfa50007f
3722
3723/*CFGEXT*/
3724#define R0900_CFGEXT 0xfa80
3725#define F0900_STAGMODE 0xfa800080
3726#define F0900_BYPBCH 0xfa800040
3727#define F0900_BYPLDPC 0xfa800020
3728#define F0900_LDPCMODE 0xfa800010
3729#define F0900_INVLLRSIGN 0xfa800008
3730#define F0900_SHORTMULT 0xfa800004
3731#define F0900_EXTERNTX 0xfa800001
3732
3733/*GENCFG*/
3734#define R0900_GENCFG 0xfa86
3735#define F0900_BROADCAST 0xfa860010
3736#define F0900_NOSHFRD2 0xfa860008
3737#define F0900_BCHERRFLAG 0xfa860004
3738#define F0900_PRIORITY 0xfa860002
3739#define F0900_DDEMOD 0xfa860001
3740
3741/*LDPCERR1*/
3742#define R0900_LDPCERR1 0xfa96
3743#define F0900_LDPC_ERRORS_COUNTER1 0xfa9600ff
3744
3745/*LDPCERR0*/
3746#define R0900_LDPCERR0 0xfa97
3747#define F0900_LDPC_ERRORS_COUNTER0 0xfa9700ff
3748
3749/*BCHERR*/
3750#define R0900_BCHERR 0xfa98
3751#define F0900_ERRORFLAG 0xfa980010
3752#define F0900_BCH_ERRORS_COUNTER 0xfa98000f
3753
3754/*TSTRES0*/
3755#define R0900_TSTRES0 0xff11
3756#define F0900_FRESFEC 0xff110080
3757#define F0900_FRESTS 0xff110040
3758#define F0900_FRESVIT1 0xff110020
3759#define F0900_FRESVIT2 0xff110010
3760#define F0900_FRESSYM1 0xff110008
3761#define F0900_FRESSYM2 0xff110004
3762#define F0900_FRESMAS 0xff110002
3763#define F0900_FRESINT 0xff110001
3764
3765/*P2_TSTDISRX*/
3766#define R0900_P2_TSTDISRX 0xff65
3767#define F0900_P2_EN_DISRX 0xff650080
3768#define F0900_P2_TST_CURRSRC 0xff650040
3769#define F0900_P2_IN_DIGSIGNAL 0xff650020
3770#define F0900_P2_HIZ_CURRENTSRC 0xff650010
3771#define F0900_TST_P2_PIN_SELECT 0xff650008
3772#define F0900_P2_TST_DISRX 0xff650007
3773
3774/*P1_TSTDISRX*/
3775#define R0900_P1_TSTDISRX 0xff67
3776#define F0900_P1_EN_DISRX 0xff670080
3777#define F0900_P1_TST_CURRSRC 0xff670040
3778#define F0900_P1_IN_DIGSIGNAL 0xff670020
3779#define F0900_P1_HIZ_CURRENTSRC 0xff670010
3780#define F0900_TST_P1_PIN_SELECT 0xff670008
3781#define F0900_P1_TST_DISRX 0xff670007
3782
3783#define STV0900_NBREGS 684
3784#define STV0900_NBFIELDS 1702
3785
3786#endif
3787
diff --git a/drivers/media/dvb/frontends/stv0900_sw.c b/drivers/media/dvb/frontends/stv0900_sw.c
new file mode 100644
index 000000000000..a5a31536cbcb
--- /dev/null
+++ b/drivers/media/dvb/frontends/stv0900_sw.c
@@ -0,0 +1,2847 @@
1/*
2 * stv0900_sw.c
3 *
4 * Driver for ST STV0900 satellite demodulator IC.
5 *
6 * Copyright (C) ST Microelectronics.
7 * Copyright (C) 2009 NetUP Inc.
8 * Copyright (C) 2009 Igor M. Liplianin <liplianin@netup.ru>
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 *
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25
26#include "stv0900.h"
27#include "stv0900_reg.h"
28#include "stv0900_priv.h"
29
30int stv0900_check_signal_presence(struct stv0900_internal *i_params,
31 enum fe_stv0900_demod_num demod)
32{
33 s32 carr_offset,
34 agc2_integr,
35 max_carrier;
36
37 int no_signal;
38
39 switch (demod) {
40 case STV0900_DEMOD_1:
41 default:
42 carr_offset = (stv0900_read_reg(i_params, R0900_P1_CFR2) << 8)
43 | stv0900_read_reg(i_params,
44 R0900_P1_CFR1);
45 carr_offset = ge2comp(carr_offset, 16);
46 agc2_integr = (stv0900_read_reg(i_params, R0900_P1_AGC2I1) << 8)
47 | stv0900_read_reg(i_params,
48 R0900_P1_AGC2I0);
49 max_carrier = i_params->dmd1_srch_range / 1000;
50 break;
51 case STV0900_DEMOD_2:
52 carr_offset = (stv0900_read_reg(i_params, R0900_P2_CFR2) << 8)
53 | stv0900_read_reg(i_params,
54 R0900_P2_CFR1);
55 carr_offset = ge2comp(carr_offset, 16);
56 agc2_integr = (stv0900_read_reg(i_params, R0900_P2_AGC2I1) << 8)
57 | stv0900_read_reg(i_params,
58 R0900_P2_AGC2I0);
59 max_carrier = i_params->dmd2_srch_range / 1000;
60 break;
61 }
62
63 max_carrier += (max_carrier / 10);
64 max_carrier = 65536 * (max_carrier / 2);
65 max_carrier /= i_params->mclk / 1000;
66 if (max_carrier > 0x4000)
67 max_carrier = 0x4000;
68
69 if ((agc2_integr > 0x2000)
70 || (carr_offset > + 2*max_carrier)
71 || (carr_offset < -2*max_carrier))
72 no_signal = TRUE;
73 else
74 no_signal = FALSE;
75
76 return no_signal;
77}
78
79static void stv0900_get_sw_loop_params(struct stv0900_internal *i_params,
80 s32 *frequency_inc, s32 *sw_timeout,
81 s32 *steps,
82 enum fe_stv0900_demod_num demod)
83{
84 s32 timeout, freq_inc, max_steps, srate, max_carrier;
85
86 enum fe_stv0900_search_standard standard;
87
88 switch (demod) {
89 case STV0900_DEMOD_1:
90 default:
91 srate = i_params->dmd1_symbol_rate;
92 max_carrier = i_params->dmd1_srch_range / 1000;
93 max_carrier += max_carrier / 10;
94 standard = i_params->dmd1_srch_standard;
95 break;
96 case STV0900_DEMOD_2:
97 srate = i_params->dmd2_symbol_rate;
98 max_carrier = i_params->dmd2_srch_range / 1000;
99 max_carrier += max_carrier / 10;
100 standard = i_params->dmd2_srch_stndrd;
101 break;
102 }
103
104 max_carrier = 65536 * (max_carrier / 2);
105 max_carrier /= i_params->mclk / 1000;
106
107 if (max_carrier > 0x4000)
108 max_carrier = 0x4000;
109
110 freq_inc = srate;
111 freq_inc /= i_params->mclk >> 10;
112 freq_inc = freq_inc << 6;
113
114 switch (standard) {
115 case STV0900_SEARCH_DVBS1:
116 case STV0900_SEARCH_DSS:
117 freq_inc *= 3;
118 timeout = 20;
119 break;
120 case STV0900_SEARCH_DVBS2:
121 freq_inc *= 4;
122 timeout = 25;
123 break;
124 case STV0900_AUTO_SEARCH:
125 default:
126 freq_inc *= 3;
127 timeout = 25;
128 break;
129 }
130
131 freq_inc /= 100;
132
133 if ((freq_inc > max_carrier) || (freq_inc < 0))
134 freq_inc = max_carrier / 2;
135
136 timeout *= 27500;
137
138 if (srate > 0)
139 timeout /= srate / 1000;
140
141 if ((timeout > 100) || (timeout < 0))
142 timeout = 100;
143
144 max_steps = (max_carrier / freq_inc) + 1;
145
146 if ((max_steps > 100) || (max_steps < 0)) {
147 max_steps = 100;
148 freq_inc = max_carrier / max_steps;
149 }
150
151 *frequency_inc = freq_inc;
152 *sw_timeout = timeout;
153 *steps = max_steps;
154
155}
156
157static int stv0900_search_carr_sw_loop(struct stv0900_internal *i_params,
158 s32 FreqIncr, s32 Timeout, int zigzag,
159 s32 MaxStep, enum fe_stv0900_demod_num demod)
160{
161 int no_signal,
162 lock = FALSE;
163 s32 stepCpt,
164 freqOffset,
165 max_carrier;
166
167 switch (demod) {
168 case STV0900_DEMOD_1:
169 default:
170 max_carrier = i_params->dmd1_srch_range / 1000;
171 max_carrier += (max_carrier / 10);
172 break;
173 case STV0900_DEMOD_2:
174 max_carrier = i_params->dmd2_srch_range / 1000;
175 max_carrier += (max_carrier / 10);
176 break;
177 }
178
179 max_carrier = 65536 * (max_carrier / 2);
180 max_carrier /= i_params->mclk / 1000;
181
182 if (max_carrier > 0x4000)
183 max_carrier = 0x4000;
184
185 if (zigzag == TRUE)
186 freqOffset = 0;
187 else
188 freqOffset = -max_carrier + FreqIncr;
189
190 stepCpt = 0;
191
192 do {
193 switch (demod) {
194 case STV0900_DEMOD_1:
195 default:
196 stv0900_write_reg(i_params, R0900_P1_DMDISTATE, 0x1C);
197 stv0900_write_reg(i_params, R0900_P1_CFRINIT1,
198 (freqOffset / 256) & 0xFF);
199 stv0900_write_reg(i_params, R0900_P1_CFRINIT0,
200 freqOffset & 0xFF);
201 stv0900_write_reg(i_params, R0900_P1_DMDISTATE, 0x18);
202 stv0900_write_bits(i_params, F0900_P1_ALGOSWRST, 1);
203
204 if (i_params->chip_id == 0x12) {
205 stv0900_write_bits(i_params,
206 F0900_P1_RST_HWARE, 1);
207 stv0900_write_bits(i_params,
208 F0900_P1_RST_HWARE, 0);
209 }
210 break;
211 case STV0900_DEMOD_2:
212 stv0900_write_reg(i_params, R0900_P2_DMDISTATE, 0x1C);
213 stv0900_write_reg(i_params, R0900_P2_CFRINIT1,
214 (freqOffset / 256) & 0xFF);
215 stv0900_write_reg(i_params, R0900_P2_CFRINIT0,
216 freqOffset & 0xFF);
217 stv0900_write_reg(i_params, R0900_P2_DMDISTATE, 0x18);
218 stv0900_write_bits(i_params, F0900_P2_ALGOSWRST, 1);
219
220 if (i_params->chip_id == 0x12) {
221 stv0900_write_bits(i_params,
222 F0900_P2_RST_HWARE, 1);
223 stv0900_write_bits(i_params,
224 F0900_P2_RST_HWARE, 0);
225 }
226 break;
227 }
228
229 if (zigzag == TRUE) {
230 if (freqOffset >= 0)
231 freqOffset = -freqOffset - 2 * FreqIncr;
232 else
233 freqOffset = -freqOffset;
234 } else
235 freqOffset += + 2 * FreqIncr;
236
237 stepCpt++;
238 lock = stv0900_get_demod_lock(i_params, demod, Timeout);
239 no_signal = stv0900_check_signal_presence(i_params, demod);
240
241 } while ((lock == FALSE)
242 && (no_signal == FALSE)
243 && ((freqOffset - FreqIncr) < max_carrier)
244 && ((freqOffset + FreqIncr) > -max_carrier)
245 && (stepCpt < MaxStep));
246
247 switch (demod) {
248 case STV0900_DEMOD_1:
249 default:
250 stv0900_write_bits(i_params, F0900_P1_ALGOSWRST, 0);
251 break;
252 case STV0900_DEMOD_2:
253 stv0900_write_bits(i_params, F0900_P2_ALGOSWRST, 0);
254 break;
255 }
256
257 return lock;
258}
259
260int stv0900_sw_algo(struct stv0900_internal *i_params,
261 enum fe_stv0900_demod_num demod)
262{
263 int lock = FALSE;
264
265 int no_signal,
266 zigzag;
267 s32 dvbs2_fly_wheel;
268
269 s32 freqIncrement, softStepTimeout, trialCounter, max_steps;
270
271 stv0900_get_sw_loop_params(i_params, &freqIncrement, &softStepTimeout,
272 &max_steps, demod);
273 switch (demod) {
274 case STV0900_DEMOD_1:
275 default:
276 switch (i_params->dmd1_srch_standard) {
277 case STV0900_SEARCH_DVBS1:
278 case STV0900_SEARCH_DSS:
279 if (i_params->chip_id >= 0x20)
280 stv0900_write_reg(i_params, R0900_P1_CARFREQ,
281 0x3B);
282 else
283 stv0900_write_reg(i_params, R0900_P1_CARFREQ,
284 0xef);
285
286 stv0900_write_reg(i_params, R0900_P1_DMDCFGMD, 0x49);
287 zigzag = FALSE;
288 break;
289 case STV0900_SEARCH_DVBS2:
290 if (i_params->chip_id >= 0x20)
291 stv0900_write_reg(i_params, R0900_P1_CORRELABS,
292 0x79);
293 else
294 stv0900_write_reg(i_params, R0900_P1_CORRELABS,
295 0x68);
296
297 stv0900_write_reg(i_params, R0900_P1_DMDCFGMD,
298 0x89);
299
300 zigzag = TRUE;
301 break;
302 case STV0900_AUTO_SEARCH:
303 default:
304 if (i_params->chip_id >= 0x20) {
305 stv0900_write_reg(i_params, R0900_P1_CARFREQ,
306 0x3B);
307 stv0900_write_reg(i_params, R0900_P1_CORRELABS,
308 0x79);
309 } else {
310 stv0900_write_reg(i_params, R0900_P1_CARFREQ,
311 0xef);
312 stv0900_write_reg(i_params, R0900_P1_CORRELABS,
313 0x68);
314 }
315
316 stv0900_write_reg(i_params, R0900_P1_DMDCFGMD,
317 0xc9);
318 zigzag = FALSE;
319 break;
320 }
321
322 trialCounter = 0;
323 do {
324 lock = stv0900_search_carr_sw_loop(i_params,
325 freqIncrement,
326 softStepTimeout,
327 zigzag,
328 max_steps,
329 demod);
330 no_signal = stv0900_check_signal_presence(i_params,
331 demod);
332 trialCounter++;
333 if ((lock == TRUE)
334 || (no_signal == TRUE)
335 || (trialCounter == 2)) {
336
337 if (i_params->chip_id >= 0x20) {
338 stv0900_write_reg(i_params,
339 R0900_P1_CARFREQ,
340 0x49);
341 stv0900_write_reg(i_params,
342 R0900_P1_CORRELABS,
343 0x9e);
344 } else {
345 stv0900_write_reg(i_params,
346 R0900_P1_CARFREQ,
347 0xed);
348 stv0900_write_reg(i_params,
349 R0900_P1_CORRELABS,
350 0x88);
351 }
352
353 if ((lock == TRUE) && (stv0900_get_bits(i_params, F0900_P1_HEADER_MODE) == STV0900_DVBS2_FOUND)) {
354 msleep(softStepTimeout);
355 dvbs2_fly_wheel = stv0900_get_bits(i_params, F0900_P1_FLYWHEEL_CPT);
356
357 if (dvbs2_fly_wheel < 0xd) {
358 msleep(softStepTimeout);
359 dvbs2_fly_wheel = stv0900_get_bits(i_params, F0900_P1_FLYWHEEL_CPT);
360 }
361
362 if (dvbs2_fly_wheel < 0xd) {
363 lock = FALSE;
364
365 if (trialCounter < 2) {
366 if (i_params->chip_id >= 0x20)
367 stv0900_write_reg(i_params, R0900_P1_CORRELABS, 0x79);
368 else
369 stv0900_write_reg(i_params, R0900_P1_CORRELABS, 0x68);
370
371 stv0900_write_reg(i_params, R0900_P1_DMDCFGMD, 0x89);
372 }
373 }
374 }
375 }
376
377 } while ((lock == FALSE)
378 && (trialCounter < 2)
379 && (no_signal == FALSE));
380
381 break;
382 case STV0900_DEMOD_2:
383 switch (i_params->dmd2_srch_stndrd) {
384 case STV0900_SEARCH_DVBS1:
385 case STV0900_SEARCH_DSS:
386 if (i_params->chip_id >= 0x20)
387 stv0900_write_reg(i_params, R0900_P2_CARFREQ,
388 0x3b);
389 else
390 stv0900_write_reg(i_params, R0900_P2_CARFREQ,
391 0xef);
392
393 stv0900_write_reg(i_params, R0900_P2_DMDCFGMD,
394 0x49);
395 zigzag = FALSE;
396 break;
397 case STV0900_SEARCH_DVBS2:
398 if (i_params->chip_id >= 0x20)
399 stv0900_write_reg(i_params, R0900_P2_CORRELABS,
400 0x79);
401 else
402 stv0900_write_reg(i_params, R0900_P2_CORRELABS,
403 0x68);
404
405 stv0900_write_reg(i_params, R0900_P2_DMDCFGMD, 0x89);
406 zigzag = TRUE;
407 break;
408 case STV0900_AUTO_SEARCH:
409 default:
410 if (i_params->chip_id >= 0x20) {
411 stv0900_write_reg(i_params, R0900_P2_CARFREQ,
412 0x3b);
413 stv0900_write_reg(i_params, R0900_P2_CORRELABS,
414 0x79);
415 } else {
416 stv0900_write_reg(i_params, R0900_P2_CARFREQ,
417 0xef);
418 stv0900_write_reg(i_params, R0900_P2_CORRELABS,
419 0x68);
420 }
421
422 stv0900_write_reg(i_params, R0900_P2_DMDCFGMD, 0xc9);
423
424 zigzag = FALSE;
425 break;
426 }
427
428 trialCounter = 0;
429
430 do {
431 lock = stv0900_search_carr_sw_loop(i_params,
432 freqIncrement,
433 softStepTimeout,
434 zigzag,
435 max_steps,
436 demod);
437 no_signal = stv0900_check_signal_presence(i_params,
438 demod);
439 trialCounter++;
440 if ((lock == TRUE)
441 || (no_signal == TRUE)
442 || (trialCounter == 2)) {
443 if (i_params->chip_id >= 0x20) {
444 stv0900_write_reg(i_params,
445 R0900_P2_CARFREQ,
446 0x49);
447 stv0900_write_reg(i_params,
448 R0900_P2_CORRELABS,
449 0x9e);
450 } else {
451 stv0900_write_reg(i_params,
452 R0900_P2_CARFREQ,
453 0xed);
454 stv0900_write_reg(i_params,
455 R0900_P2_CORRELABS,
456 0x88);
457 }
458
459 if ((lock == TRUE) && (stv0900_get_bits(i_params, F0900_P2_HEADER_MODE) == STV0900_DVBS2_FOUND)) {
460 msleep(softStepTimeout);
461 dvbs2_fly_wheel = stv0900_get_bits(i_params, F0900_P2_FLYWHEEL_CPT);
462 if (dvbs2_fly_wheel < 0xd) {
463 msleep(softStepTimeout);
464 dvbs2_fly_wheel = stv0900_get_bits(i_params, F0900_P2_FLYWHEEL_CPT);
465 }
466
467 if (dvbs2_fly_wheel < 0xd) {
468 lock = FALSE;
469 if (trialCounter < 2) {
470 if (i_params->chip_id >= 0x20)
471 stv0900_write_reg(i_params, R0900_P2_CORRELABS, 0x79);
472 else
473 stv0900_write_reg(i_params, R0900_P2_CORRELABS, 0x68);
474
475 stv0900_write_reg(i_params, R0900_P2_DMDCFGMD, 0x89);
476 }
477 }
478 }
479 }
480
481 } while ((lock == FALSE) && (trialCounter < 2) && (no_signal == FALSE));
482
483 break;
484 }
485
486 return lock;
487}
488
489static u32 stv0900_get_symbol_rate(struct stv0900_internal *i_params,
490 u32 mclk,
491 enum fe_stv0900_demod_num demod)
492{
493 s32 sfr_field3, sfr_field2, sfr_field1, sfr_field0,
494 rem1, rem2, intval1, intval2, srate;
495
496 dmd_reg(sfr_field3, F0900_P1_SYMB_FREQ3, F0900_P2_SYMB_FREQ3);
497 dmd_reg(sfr_field2, F0900_P1_SYMB_FREQ2, F0900_P2_SYMB_FREQ2);
498 dmd_reg(sfr_field1, F0900_P1_SYMB_FREQ1, F0900_P2_SYMB_FREQ1);
499 dmd_reg(sfr_field0, F0900_P1_SYMB_FREQ0, F0900_P2_SYMB_FREQ0);
500
501 srate = (stv0900_get_bits(i_params, sfr_field3) << 24) +
502 (stv0900_get_bits(i_params, sfr_field2) << 16) +
503 (stv0900_get_bits(i_params, sfr_field1) << 8) +
504 (stv0900_get_bits(i_params, sfr_field0));
505 dprintk("lock: srate=%d r0=0x%x r1=0x%x r2=0x%x r3=0x%x \n",
506 srate, stv0900_get_bits(i_params, sfr_field0),
507 stv0900_get_bits(i_params, sfr_field1),
508 stv0900_get_bits(i_params, sfr_field2),
509 stv0900_get_bits(i_params, sfr_field3));
510
511 intval1 = (mclk) >> 16;
512 intval2 = (srate) >> 16;
513
514 rem1 = (mclk) % 0x10000;
515 rem2 = (srate) % 0x10000;
516 srate = (intval1 * intval2) +
517 ((intval1 * rem2) >> 16) +
518 ((intval2 * rem1) >> 16);
519
520 return srate;
521}
522
523static void stv0900_set_symbol_rate(struct stv0900_internal *i_params,
524 u32 mclk, u32 srate,
525 enum fe_stv0900_demod_num demod)
526{
527 s32 sfr_init_reg;
528 u32 symb;
529
530 dprintk(KERN_INFO "%s: Mclk %d, SR %d, Dmd %d\n", __func__, mclk,
531 srate, demod);
532
533 dmd_reg(sfr_init_reg, R0900_P1_SFRINIT1, R0900_P2_SFRINIT1);
534
535 if (srate > 60000000) {
536 symb = srate << 4;
537 symb /= (mclk >> 12);
538 } else if (srate > 6000000) {
539 symb = srate << 6;
540 symb /= (mclk >> 10);
541 } else {
542 symb = srate << 9;
543 symb /= (mclk >> 7);
544 }
545
546 stv0900_write_reg(i_params, sfr_init_reg, (symb >> 8) & 0x7F);
547 stv0900_write_reg(i_params, sfr_init_reg + 1, (symb & 0xFF));
548}
549
550static void stv0900_set_max_symbol_rate(struct stv0900_internal *i_params,
551 u32 mclk, u32 srate,
552 enum fe_stv0900_demod_num demod)
553{
554 s32 sfr_max_reg;
555 u32 symb;
556
557 dmd_reg(sfr_max_reg, R0900_P1_SFRUP1, R0900_P2_SFRUP1);
558
559 srate = 105 * (srate / 100);
560
561 if (srate > 60000000) {
562 symb = srate << 4;
563 symb /= (mclk >> 12);
564 } else if (srate > 6000000) {
565 symb = srate << 6;
566 symb /= (mclk >> 10);
567 } else {
568 symb = srate << 9;
569 symb /= (mclk >> 7);
570 }
571
572 if (symb < 0x7fff) {
573 stv0900_write_reg(i_params, sfr_max_reg, (symb >> 8) & 0x7F);
574 stv0900_write_reg(i_params, sfr_max_reg + 1, (symb & 0xFF));
575 } else {
576 stv0900_write_reg(i_params, sfr_max_reg, 0x7F);
577 stv0900_write_reg(i_params, sfr_max_reg + 1, 0xFF);
578 }
579}
580
581static void stv0900_set_min_symbol_rate(struct stv0900_internal *i_params,
582 u32 mclk, u32 srate,
583 enum fe_stv0900_demod_num demod)
584{
585 s32 sfr_min_reg;
586 u32 symb;
587
588 dmd_reg(sfr_min_reg, R0900_P1_SFRLOW1, R0900_P2_SFRLOW1);
589
590 srate = 95 * (srate / 100);
591 if (srate > 60000000) {
592 symb = srate << 4;
593 symb /= (mclk >> 12);
594
595 } else if (srate > 6000000) {
596 symb = srate << 6;
597 symb /= (mclk >> 10);
598
599 } else {
600 symb = srate << 9;
601 symb /= (mclk >> 7);
602 }
603
604 stv0900_write_reg(i_params, sfr_min_reg, (symb >> 8) & 0xFF);
605 stv0900_write_reg(i_params, sfr_min_reg + 1, (symb & 0xFF));
606}
607
608static s32 stv0900_get_timing_offst(struct stv0900_internal *i_params,
609 u32 srate,
610 enum fe_stv0900_demod_num demod)
611{
612 s32 tmgreg,
613 timingoffset;
614
615 dmd_reg(tmgreg, R0900_P1_TMGREG2, R0900_P2_TMGREG2);
616
617 timingoffset = (stv0900_read_reg(i_params, tmgreg) << 16) +
618 (stv0900_read_reg(i_params, tmgreg + 1) << 8) +
619 (stv0900_read_reg(i_params, tmgreg + 2));
620
621 timingoffset = ge2comp(timingoffset, 24);
622
623
624 if (timingoffset == 0)
625 timingoffset = 1;
626
627 timingoffset = ((s32)srate * 10) / ((s32)0x1000000 / timingoffset);
628 timingoffset /= 320;
629
630 return timingoffset;
631}
632
633static void stv0900_set_dvbs2_rolloff(struct stv0900_internal *i_params,
634 enum fe_stv0900_demod_num demod)
635{
636 s32 rolloff, man_fld, matstr_reg, rolloff_ctl_fld;
637
638 dmd_reg(man_fld, F0900_P1_MANUAL_ROLLOFF, F0900_P2_MANUAL_ROLLOFF);
639 dmd_reg(matstr_reg, R0900_P1_MATSTR1, R0900_P2_MATSTR1);
640 dmd_reg(rolloff_ctl_fld, F0900_P1_ROLLOFF_CONTROL,
641 F0900_P2_ROLLOFF_CONTROL);
642
643 if (i_params->chip_id == 0x10) {
644 stv0900_write_bits(i_params, man_fld, 1);
645 rolloff = stv0900_read_reg(i_params, matstr_reg) & 0x03;
646 stv0900_write_bits(i_params, rolloff_ctl_fld, rolloff);
647 } else
648 stv0900_write_bits(i_params, man_fld, 0);
649}
650
651static u32 stv0900_carrier_width(u32 srate, enum fe_stv0900_rolloff ro)
652{
653 u32 rolloff;
654
655 switch (ro) {
656 case STV0900_20:
657 rolloff = 20;
658 break;
659 case STV0900_25:
660 rolloff = 25;
661 break;
662 case STV0900_35:
663 default:
664 rolloff = 35;
665 break;
666 }
667
668 return srate + (srate * rolloff) / 100;
669}
670
671static int stv0900_check_timing_lock(struct stv0900_internal *i_params,
672 enum fe_stv0900_demod_num demod)
673{
674 int timingLock = FALSE;
675 s32 i,
676 timingcpt = 0;
677 u8 carFreq,
678 tmgTHhigh,
679 tmgTHLow;
680
681 switch (demod) {
682 case STV0900_DEMOD_1:
683 default:
684 carFreq = stv0900_read_reg(i_params, R0900_P1_CARFREQ);
685 tmgTHhigh = stv0900_read_reg(i_params, R0900_P1_TMGTHRISE);
686 tmgTHLow = stv0900_read_reg(i_params, R0900_P1_TMGTHFALL);
687 stv0900_write_reg(i_params, R0900_P1_TMGTHRISE, 0x20);
688 stv0900_write_reg(i_params, R0900_P1_TMGTHFALL, 0x0);
689 stv0900_write_bits(i_params, F0900_P1_CFR_AUTOSCAN, 0);
690 stv0900_write_reg(i_params, R0900_P1_RTC, 0x80);
691 stv0900_write_reg(i_params, R0900_P1_RTCS2, 0x40);
692 stv0900_write_reg(i_params, R0900_P1_CARFREQ, 0x0);
693 stv0900_write_reg(i_params, R0900_P1_CFRINIT1, 0x0);
694 stv0900_write_reg(i_params, R0900_P1_CFRINIT0, 0x0);
695 stv0900_write_reg(i_params, R0900_P1_AGC2REF, 0x65);
696 stv0900_write_reg(i_params, R0900_P1_DMDISTATE, 0x18);
697 msleep(7);
698
699 for (i = 0; i < 10; i++) {
700 if (stv0900_get_bits(i_params, F0900_P1_TMGLOCK_QUALITY) >= 2)
701 timingcpt++;
702
703 msleep(1);
704 }
705
706 if (timingcpt >= 3)
707 timingLock = TRUE;
708
709 stv0900_write_reg(i_params, R0900_P1_AGC2REF, 0x38);
710 stv0900_write_reg(i_params, R0900_P1_RTC, 0x88);
711 stv0900_write_reg(i_params, R0900_P1_RTCS2, 0x68);
712 stv0900_write_reg(i_params, R0900_P1_CARFREQ, carFreq);
713 stv0900_write_reg(i_params, R0900_P1_TMGTHRISE, tmgTHhigh);
714 stv0900_write_reg(i_params, R0900_P1_TMGTHFALL, tmgTHLow);
715 break;
716 case STV0900_DEMOD_2:
717 carFreq = stv0900_read_reg(i_params, R0900_P2_CARFREQ);
718 tmgTHhigh = stv0900_read_reg(i_params, R0900_P2_TMGTHRISE);
719 tmgTHLow = stv0900_read_reg(i_params, R0900_P2_TMGTHFALL);
720 stv0900_write_reg(i_params, R0900_P2_TMGTHRISE, 0x20);
721 stv0900_write_reg(i_params, R0900_P2_TMGTHFALL, 0);
722 stv0900_write_bits(i_params, F0900_P2_CFR_AUTOSCAN, 0);
723 stv0900_write_reg(i_params, R0900_P2_RTC, 0x80);
724 stv0900_write_reg(i_params, R0900_P2_RTCS2, 0x40);
725 stv0900_write_reg(i_params, R0900_P2_CARFREQ, 0x0);
726 stv0900_write_reg(i_params, R0900_P2_CFRINIT1, 0x0);
727 stv0900_write_reg(i_params, R0900_P2_CFRINIT0, 0x0);
728 stv0900_write_reg(i_params, R0900_P2_AGC2REF, 0x65);
729 stv0900_write_reg(i_params, R0900_P2_DMDISTATE, 0x18);
730 msleep(5);
731 for (i = 0; i < 10; i++) {
732 if (stv0900_get_bits(i_params, F0900_P2_TMGLOCK_QUALITY) >= 2)
733 timingcpt++;
734
735 msleep(1);
736 }
737
738 if (timingcpt >= 3)
739 timingLock = TRUE;
740
741 stv0900_write_reg(i_params, R0900_P2_AGC2REF, 0x38);
742 stv0900_write_reg(i_params, R0900_P2_RTC, 0x88);
743 stv0900_write_reg(i_params, R0900_P2_RTCS2, 0x68);
744 stv0900_write_reg(i_params, R0900_P2_CARFREQ, carFreq);
745 stv0900_write_reg(i_params, R0900_P2_TMGTHRISE, tmgTHhigh);
746 stv0900_write_reg(i_params, R0900_P2_TMGTHFALL, tmgTHLow);
747 break;
748 }
749
750 return timingLock;
751}
752
753static int stv0900_get_demod_cold_lock(struct dvb_frontend *fe,
754 s32 demod_timeout)
755{
756 struct stv0900_state *state = fe->demodulator_priv;
757 struct stv0900_internal *i_params = state->internal;
758 enum fe_stv0900_demod_num demod = state->demod;
759
760 int lock = FALSE;
761 s32 srate, search_range, locktimeout,
762 currier_step, nb_steps, current_step,
763 direction, tuner_freq, timeout;
764
765 switch (demod) {
766 case STV0900_DEMOD_1:
767 default:
768 srate = i_params->dmd1_symbol_rate;
769 search_range = i_params->dmd1_srch_range;
770 break;
771
772 case STV0900_DEMOD_2:
773 srate = i_params->dmd2_symbol_rate;
774 search_range = i_params->dmd2_srch_range;
775 break;
776 }
777
778 if (srate >= 10000000)
779 locktimeout = demod_timeout / 3;
780 else
781 locktimeout = demod_timeout / 2;
782
783 lock = stv0900_get_demod_lock(i_params, demod, locktimeout);
784
785 if (lock == FALSE) {
786 if (srate >= 10000000) {
787 if (stv0900_check_timing_lock(i_params, demod) == TRUE) {
788 switch (demod) {
789 case STV0900_DEMOD_1:
790 default:
791 stv0900_write_reg(i_params, R0900_P1_DMDISTATE, 0x1f);
792 stv0900_write_reg(i_params, R0900_P1_DMDISTATE, 0x15);
793 break;
794 case STV0900_DEMOD_2:
795 stv0900_write_reg(i_params, R0900_P2_DMDISTATE, 0x1f);
796 stv0900_write_reg(i_params, R0900_P2_DMDISTATE, 0x15);
797 break;
798 }
799
800 lock = stv0900_get_demod_lock(i_params, demod, demod_timeout);
801 } else
802 lock = FALSE;
803 } else {
804 if (srate <= 4000000)
805 currier_step = 1000;
806 else if (srate <= 7000000)
807 currier_step = 2000;
808 else if (srate <= 10000000)
809 currier_step = 3000;
810 else
811 currier_step = 5000;
812
813 nb_steps = ((search_range / 1000) / currier_step);
814 nb_steps /= 2;
815 nb_steps = (2 * (nb_steps + 1));
816 if (nb_steps < 0)
817 nb_steps = 2;
818 else if (nb_steps > 12)
819 nb_steps = 12;
820
821 current_step = 1;
822 direction = 1;
823 timeout = (demod_timeout / 3);
824 if (timeout > 1000)
825 timeout = 1000;
826
827 switch (demod) {
828 case STV0900_DEMOD_1:
829 default:
830 if (lock == FALSE) {
831 tuner_freq = i_params->tuner1_freq;
832 i_params->tuner1_bw = stv0900_carrier_width(i_params->dmd1_symbol_rate, i_params->rolloff) + i_params->dmd1_symbol_rate;
833
834 while ((current_step <= nb_steps) && (lock == FALSE)) {
835
836 if (direction > 0)
837 tuner_freq += (current_step * currier_step);
838 else
839 tuner_freq -= (current_step * currier_step);
840
841 stv0900_set_tuner(fe, tuner_freq, i_params->tuner1_bw);
842 stv0900_write_reg(i_params, R0900_P1_DMDISTATE, 0x1C);
843 if (i_params->dmd1_srch_standard == STV0900_SEARCH_DVBS2) {
844 stv0900_write_bits(i_params, F0900_P1_DVBS1_ENABLE, 0);
845 stv0900_write_bits(i_params, F0900_P1_DVBS2_ENABLE, 0);
846 stv0900_write_bits(i_params, F0900_P1_DVBS1_ENABLE, 1);
847 stv0900_write_bits(i_params, F0900_P1_DVBS2_ENABLE, 1);
848 }
849
850 stv0900_write_reg(i_params, R0900_P1_CFRINIT1, 0);
851 stv0900_write_reg(i_params, R0900_P1_CFRINIT0, 0);
852 stv0900_write_reg(i_params, R0900_P1_DMDISTATE, 0x1F);
853 stv0900_write_reg(i_params, R0900_P1_DMDISTATE, 0x15);
854 lock = stv0900_get_demod_lock(i_params, demod, timeout);
855 direction *= -1;
856 current_step++;
857 }
858 }
859 break;
860 case STV0900_DEMOD_2:
861 if (lock == FALSE) {
862 tuner_freq = i_params->tuner2_freq;
863 i_params->tuner2_bw = stv0900_carrier_width(srate, i_params->rolloff) + srate;
864
865 while ((current_step <= nb_steps) && (lock == FALSE)) {
866
867 if (direction > 0)
868 tuner_freq += (current_step * currier_step);
869 else
870 tuner_freq -= (current_step * currier_step);
871
872 stv0900_set_tuner(fe, tuner_freq, i_params->tuner2_bw);
873 stv0900_write_reg(i_params, R0900_P2_DMDISTATE, 0x1C);
874 if (i_params->dmd2_srch_stndrd == STV0900_SEARCH_DVBS2) {
875 stv0900_write_bits(i_params, F0900_P2_DVBS1_ENABLE, 0);
876 stv0900_write_bits(i_params, F0900_P2_DVBS2_ENABLE, 0);
877 stv0900_write_bits(i_params, F0900_P2_DVBS1_ENABLE, 1);
878 stv0900_write_bits(i_params, F0900_P2_DVBS2_ENABLE, 1);
879 }
880
881 stv0900_write_reg(i_params, R0900_P2_CFRINIT1, 0);
882 stv0900_write_reg(i_params, R0900_P2_CFRINIT0, 0);
883 stv0900_write_reg(i_params, R0900_P2_DMDISTATE, 0x1F);
884 stv0900_write_reg(i_params, R0900_P2_DMDISTATE, 0x15);
885 lock = stv0900_get_demod_lock(i_params, demod, timeout);
886 direction *= -1;
887 current_step++;
888 }
889 }
890 break;
891 }
892 }
893 }
894
895 return lock;
896}
897
898static void stv0900_get_lock_timeout(s32 *demod_timeout, s32 *fec_timeout,
899 s32 srate,
900 enum fe_stv0900_search_algo algo)
901{
902 switch (algo) {
903 case STV0900_BLIND_SEARCH:
904 if (srate <= 1500000) {
905 (*demod_timeout) = 1500;
906 (*fec_timeout) = 400;
907 } else if (srate <= 5000000) {
908 (*demod_timeout) = 1000;
909 (*fec_timeout) = 300;
910 } else {
911 (*demod_timeout) = 700;
912 (*fec_timeout) = 100;
913 }
914
915 break;
916 case STV0900_COLD_START:
917 case STV0900_WARM_START:
918 default:
919 if (srate <= 1000000) {
920 (*demod_timeout) = 3000;
921 (*fec_timeout) = 1700;
922 } else if (srate <= 2000000) {
923 (*demod_timeout) = 2500;
924 (*fec_timeout) = 1100;
925 } else if (srate <= 5000000) {
926 (*demod_timeout) = 1000;
927 (*fec_timeout) = 550;
928 } else if (srate <= 10000000) {
929 (*demod_timeout) = 700;
930 (*fec_timeout) = 250;
931 } else if (srate <= 20000000) {
932 (*demod_timeout) = 400;
933 (*fec_timeout) = 130;
934 }
935
936 else {
937 (*demod_timeout) = 300;
938 (*fec_timeout) = 100;
939 }
940
941 break;
942
943 }
944
945 if (algo == STV0900_WARM_START)
946 (*demod_timeout) /= 2;
947}
948
949static void stv0900_set_viterbi_tracq(struct stv0900_internal *i_params,
950 enum fe_stv0900_demod_num demod)
951{
952
953 s32 vth_reg;
954
955 dprintk(KERN_INFO "%s\n", __func__);
956
957 dmd_reg(vth_reg, R0900_P1_VTH12, R0900_P2_VTH12);
958
959 stv0900_write_reg(i_params, vth_reg++, 0xd0);
960 stv0900_write_reg(i_params, vth_reg++, 0x7d);
961 stv0900_write_reg(i_params, vth_reg++, 0x53);
962 stv0900_write_reg(i_params, vth_reg++, 0x2F);
963 stv0900_write_reg(i_params, vth_reg++, 0x24);
964 stv0900_write_reg(i_params, vth_reg++, 0x1F);
965}
966
967static void stv0900_set_viterbi_standard(struct stv0900_internal *i_params,
968 enum fe_stv0900_search_standard Standard,
969 enum fe_stv0900_fec PunctureRate,
970 enum fe_stv0900_demod_num demod)
971{
972
973 s32 fecmReg,
974 prvitReg;
975
976 dprintk(KERN_INFO "%s: ViterbiStandard = ", __func__);
977
978 switch (demod) {
979 case STV0900_DEMOD_1:
980 default:
981 fecmReg = R0900_P1_FECM;
982 prvitReg = R0900_P1_PRVIT;
983 break;
984 case STV0900_DEMOD_2:
985 fecmReg = R0900_P2_FECM;
986 prvitReg = R0900_P2_PRVIT;
987 break;
988 }
989
990 switch (Standard) {
991 case STV0900_AUTO_SEARCH:
992 dprintk("Auto\n");
993 stv0900_write_reg(i_params, fecmReg, 0x10);
994 stv0900_write_reg(i_params, prvitReg, 0x3F);
995 break;
996 case STV0900_SEARCH_DVBS1:
997 dprintk("DVBS1\n");
998 stv0900_write_reg(i_params, fecmReg, 0x00);
999 switch (PunctureRate) {
1000 case STV0900_FEC_UNKNOWN:
1001 default:
1002 stv0900_write_reg(i_params, prvitReg, 0x2F);
1003 break;
1004 case STV0900_FEC_1_2:
1005 stv0900_write_reg(i_params, prvitReg, 0x01);
1006 break;
1007 case STV0900_FEC_2_3:
1008 stv0900_write_reg(i_params, prvitReg, 0x02);
1009 break;
1010 case STV0900_FEC_3_4:
1011 stv0900_write_reg(i_params, prvitReg, 0x04);
1012 break;
1013 case STV0900_FEC_5_6:
1014 stv0900_write_reg(i_params, prvitReg, 0x08);
1015 break;
1016 case STV0900_FEC_7_8:
1017 stv0900_write_reg(i_params, prvitReg, 0x20);
1018 break;
1019 }
1020
1021 break;
1022 case STV0900_SEARCH_DSS:
1023 dprintk("DSS\n");
1024 stv0900_write_reg(i_params, fecmReg, 0x80);
1025 switch (PunctureRate) {
1026 case STV0900_FEC_UNKNOWN:
1027 default:
1028 stv0900_write_reg(i_params, prvitReg, 0x13);
1029 break;
1030 case STV0900_FEC_1_2:
1031 stv0900_write_reg(i_params, prvitReg, 0x01);
1032 break;
1033 case STV0900_FEC_2_3:
1034 stv0900_write_reg(i_params, prvitReg, 0x02);
1035 break;
1036 case STV0900_FEC_6_7:
1037 stv0900_write_reg(i_params, prvitReg, 0x10);
1038 break;
1039 }
1040 break;
1041 default:
1042 break;
1043 }
1044}
1045
1046static void stv0900_track_optimization(struct dvb_frontend *fe)
1047{
1048 struct stv0900_state *state = fe->demodulator_priv;
1049 struct stv0900_internal *i_params = state->internal;
1050 enum fe_stv0900_demod_num demod = state->demod;
1051
1052 s32 srate, pilots, aclc, freq1, freq0,
1053 i = 0, timed, timef, blindTunSw = 0;
1054
1055 enum fe_stv0900_rolloff rolloff;
1056 enum fe_stv0900_modcode foundModcod;
1057
1058 dprintk(KERN_INFO "%s\n", __func__);
1059
1060 srate = stv0900_get_symbol_rate(i_params, i_params->mclk, demod);
1061 srate += stv0900_get_timing_offst(i_params, srate, demod);
1062
1063 switch (demod) {
1064 case STV0900_DEMOD_1:
1065 default:
1066 switch (i_params->dmd1_rslts.standard) {
1067 case STV0900_DVBS1_STANDARD:
1068 if (i_params->dmd1_srch_standard == STV0900_AUTO_SEARCH) {
1069 stv0900_write_bits(i_params, F0900_P1_DVBS1_ENABLE, 1);
1070 stv0900_write_bits(i_params, F0900_P1_DVBS2_ENABLE, 0);
1071 }
1072
1073 stv0900_write_bits(i_params, F0900_P1_ROLLOFF_CONTROL, i_params->rolloff);
1074 stv0900_write_bits(i_params, F0900_P1_MANUAL_ROLLOFF, 1);
1075 stv0900_write_reg(i_params, R0900_P1_ERRCTRL1, 0x75);
1076 break;
1077 case STV0900_DSS_STANDARD:
1078 if (i_params->dmd1_srch_standard == STV0900_AUTO_SEARCH) {
1079 stv0900_write_bits(i_params, F0900_P1_DVBS1_ENABLE, 1);
1080 stv0900_write_bits(i_params, F0900_P1_DVBS2_ENABLE, 0);
1081 }
1082
1083 stv0900_write_bits(i_params, F0900_P1_ROLLOFF_CONTROL, i_params->rolloff);
1084 stv0900_write_bits(i_params, F0900_P1_MANUAL_ROLLOFF, 1);
1085 stv0900_write_reg(i_params, R0900_P1_ERRCTRL1, 0x75);
1086 break;
1087 case STV0900_DVBS2_STANDARD:
1088 stv0900_write_bits(i_params, F0900_P1_DVBS1_ENABLE, 0);
1089 stv0900_write_bits(i_params, F0900_P1_DVBS2_ENABLE, 1);
1090 stv0900_write_reg(i_params, R0900_P1_ACLC, 0);
1091 stv0900_write_reg(i_params, R0900_P1_BCLC, 0);
1092 if (i_params->dmd1_rslts.frame_length == STV0900_LONG_FRAME) {
1093 foundModcod = stv0900_get_bits(i_params, F0900_P1_DEMOD_MODCOD);
1094 pilots = stv0900_get_bits(i_params, F0900_P1_DEMOD_TYPE) & 0x01;
1095 aclc = stv0900_get_optim_carr_loop(srate, foundModcod, pilots, i_params->chip_id);
1096 if (foundModcod <= STV0900_QPSK_910)
1097 stv0900_write_reg(i_params, R0900_P1_ACLC2S2Q, aclc);
1098 else if (foundModcod <= STV0900_8PSK_910) {
1099 stv0900_write_reg(i_params, R0900_P1_ACLC2S2Q, 0x2a);
1100 stv0900_write_reg(i_params, R0900_P1_ACLC2S28, aclc);
1101 }
1102
1103 if ((i_params->demod_mode == STV0900_SINGLE) && (foundModcod > STV0900_8PSK_910)) {
1104 if (foundModcod <= STV0900_16APSK_910) {
1105 stv0900_write_reg(i_params, R0900_P1_ACLC2S2Q, 0x2a);
1106 stv0900_write_reg(i_params, R0900_P1_ACLC2S216A, aclc);
1107 } else if (foundModcod <= STV0900_32APSK_910) {
1108 stv0900_write_reg(i_params, R0900_P1_ACLC2S2Q, 0x2a);
1109 stv0900_write_reg(i_params, R0900_P1_ACLC2S232A, aclc);
1110 }
1111 }
1112
1113 } else {
1114 aclc = stv0900_get_optim_short_carr_loop(srate, i_params->dmd1_rslts.modulation, i_params->chip_id);
1115 if (i_params->dmd1_rslts.modulation == STV0900_QPSK)
1116 stv0900_write_reg(i_params, R0900_P1_ACLC2S2Q, aclc);
1117
1118 else if (i_params->dmd1_rslts.modulation == STV0900_8PSK) {
1119 stv0900_write_reg(i_params, R0900_P1_ACLC2S2Q, 0x2a);
1120 stv0900_write_reg(i_params, R0900_P1_ACLC2S28, aclc);
1121 } else if (i_params->dmd1_rslts.modulation == STV0900_16APSK) {
1122 stv0900_write_reg(i_params, R0900_P1_ACLC2S2Q, 0x2a);
1123 stv0900_write_reg(i_params, R0900_P1_ACLC2S216A, aclc);
1124 } else if (i_params->dmd1_rslts.modulation == STV0900_32APSK) {
1125 stv0900_write_reg(i_params, R0900_P1_ACLC2S2Q, 0x2a);
1126 stv0900_write_reg(i_params, R0900_P1_ACLC2S232A, aclc);
1127 }
1128
1129 }
1130
1131 if (i_params->chip_id <= 0x11) {
1132 if (i_params->demod_mode != STV0900_SINGLE)
1133 stv0900_activate_s2_modcode(i_params, demod);
1134
1135 }
1136
1137 stv0900_write_reg(i_params, R0900_P1_ERRCTRL1, 0x67);
1138 break;
1139 case STV0900_UNKNOWN_STANDARD:
1140 default:
1141 stv0900_write_bits(i_params, F0900_P1_DVBS1_ENABLE, 1);
1142 stv0900_write_bits(i_params, F0900_P1_DVBS2_ENABLE, 1);
1143 break;
1144 }
1145
1146 freq1 = stv0900_read_reg(i_params, R0900_P1_CFR2);
1147 freq0 = stv0900_read_reg(i_params, R0900_P1_CFR1);
1148 rolloff = stv0900_get_bits(i_params, F0900_P1_ROLLOFF_STATUS);
1149 if (i_params->dmd1_srch_algo == STV0900_BLIND_SEARCH) {
1150 stv0900_write_reg(i_params, R0900_P1_SFRSTEP, 0x00);
1151 stv0900_write_bits(i_params, F0900_P1_SCAN_ENABLE, 0);
1152 stv0900_write_bits(i_params, F0900_P1_CFR_AUTOSCAN, 0);
1153 stv0900_write_reg(i_params, R0900_P1_TMGCFG2, 0x01);
1154 stv0900_set_symbol_rate(i_params, i_params->mclk, srate, demod);
1155 stv0900_set_max_symbol_rate(i_params, i_params->mclk, srate, demod);
1156 stv0900_set_min_symbol_rate(i_params, i_params->mclk, srate, demod);
1157 blindTunSw = 1;
1158 }
1159
1160 if (i_params->chip_id >= 0x20) {
1161 if ((i_params->dmd1_srch_standard == STV0900_SEARCH_DVBS1) || (i_params->dmd1_srch_standard == STV0900_SEARCH_DSS) || (i_params->dmd1_srch_standard == STV0900_AUTO_SEARCH)) {
1162 stv0900_write_reg(i_params, R0900_P1_VAVSRVIT, 0x0a);
1163 stv0900_write_reg(i_params, R0900_P1_VITSCALE, 0x0);
1164 }
1165 }
1166
1167 if (i_params->chip_id < 0x20)
1168 stv0900_write_reg(i_params, R0900_P1_CARHDR, 0x08);
1169
1170 if (i_params->chip_id == 0x10)
1171 stv0900_write_reg(i_params, R0900_P1_CORRELEXP, 0x0A);
1172
1173 stv0900_write_reg(i_params, R0900_P1_AGC2REF, 0x38);
1174
1175 if ((i_params->chip_id >= 0x20) || (blindTunSw == 1) || (i_params->dmd1_symbol_rate < 10000000)) {
1176 stv0900_write_reg(i_params, R0900_P1_CFRINIT1, freq1);
1177 stv0900_write_reg(i_params, R0900_P1_CFRINIT0, freq0);
1178 i_params->tuner1_bw = stv0900_carrier_width(srate, i_params->rolloff) + 10000000;
1179
1180 if ((i_params->chip_id >= 0x20) || (blindTunSw == 1)) {
1181 if (i_params->dmd1_srch_algo != STV0900_WARM_START)
1182 stv0900_set_bandwidth(fe, i_params->tuner1_bw);
1183 }
1184
1185 if ((i_params->dmd1_srch_algo == STV0900_BLIND_SEARCH) || (i_params->dmd1_symbol_rate < 10000000))
1186 msleep(50);
1187 else
1188 msleep(5);
1189
1190 stv0900_get_lock_timeout(&timed, &timef, srate, STV0900_WARM_START);
1191
1192 if (stv0900_get_demod_lock(i_params, demod, timed / 2) == FALSE) {
1193 stv0900_write_reg(i_params, R0900_P1_DMDISTATE, 0x1F);
1194 stv0900_write_reg(i_params, R0900_P1_CFRINIT1, freq1);
1195 stv0900_write_reg(i_params, R0900_P1_CFRINIT0, freq0);
1196 stv0900_write_reg(i_params, R0900_P1_DMDISTATE, 0x18);
1197 i = 0;
1198 while ((stv0900_get_demod_lock(i_params, demod, timed / 2) == FALSE) && (i <= 2)) {
1199 stv0900_write_reg(i_params, R0900_P1_DMDISTATE, 0x1F);
1200 stv0900_write_reg(i_params, R0900_P1_CFRINIT1, freq1);
1201 stv0900_write_reg(i_params, R0900_P1_CFRINIT0, freq0);
1202 stv0900_write_reg(i_params, R0900_P1_DMDISTATE, 0x18);
1203 i++;
1204 }
1205 }
1206
1207 }
1208
1209 if (i_params->chip_id >= 0x20)
1210 stv0900_write_reg(i_params, R0900_P1_CARFREQ, 0x49);
1211
1212 if ((i_params->dmd1_rslts.standard == STV0900_DVBS1_STANDARD) || (i_params->dmd1_rslts.standard == STV0900_DSS_STANDARD))
1213 stv0900_set_viterbi_tracq(i_params, demod);
1214
1215 break;
1216
1217 case STV0900_DEMOD_2:
1218 switch (i_params->dmd2_rslts.standard) {
1219 case STV0900_DVBS1_STANDARD:
1220
1221 if (i_params->dmd2_srch_stndrd == STV0900_AUTO_SEARCH) {
1222 stv0900_write_bits(i_params, F0900_P2_DVBS1_ENABLE, 1);
1223 stv0900_write_bits(i_params, F0900_P2_DVBS2_ENABLE, 0);
1224 }
1225
1226 stv0900_write_bits(i_params, F0900_P2_ROLLOFF_CONTROL, i_params->rolloff);
1227 stv0900_write_bits(i_params, F0900_P2_MANUAL_ROLLOFF, 1);
1228 stv0900_write_reg(i_params, R0900_P2_ERRCTRL1, 0x75);
1229 break;
1230 case STV0900_DSS_STANDARD:
1231 if (i_params->dmd2_srch_stndrd == STV0900_AUTO_SEARCH) {
1232 stv0900_write_bits(i_params, F0900_P2_DVBS1_ENABLE, 1);
1233 stv0900_write_bits(i_params, F0900_P2_DVBS2_ENABLE, 0);
1234 }
1235
1236 stv0900_write_bits(i_params, F0900_P2_ROLLOFF_CONTROL, i_params->rolloff);
1237 stv0900_write_bits(i_params, F0900_P2_MANUAL_ROLLOFF, 1);
1238 stv0900_write_reg(i_params, R0900_P2_ERRCTRL1, 0x75);
1239 break;
1240 case STV0900_DVBS2_STANDARD:
1241 stv0900_write_bits(i_params, F0900_P2_DVBS1_ENABLE, 0);
1242 stv0900_write_bits(i_params, F0900_P2_DVBS2_ENABLE, 1);
1243 stv0900_write_reg(i_params, R0900_P2_ACLC, 0);
1244 stv0900_write_reg(i_params, R0900_P2_BCLC, 0);
1245 if (i_params->dmd2_rslts.frame_length == STV0900_LONG_FRAME) {
1246 foundModcod = stv0900_get_bits(i_params, F0900_P2_DEMOD_MODCOD);
1247 pilots = stv0900_get_bits(i_params, F0900_P2_DEMOD_TYPE) & 0x01;
1248 aclc = stv0900_get_optim_carr_loop(srate, foundModcod, pilots, i_params->chip_id);
1249 if (foundModcod <= STV0900_QPSK_910)
1250 stv0900_write_reg(i_params, R0900_P2_ACLC2S2Q, aclc);
1251 else if (foundModcod <= STV0900_8PSK_910) {
1252 stv0900_write_reg(i_params, R0900_P2_ACLC2S2Q, 0x2a);
1253 stv0900_write_reg(i_params, R0900_P2_ACLC2S28, aclc);
1254 }
1255
1256 if ((i_params->demod_mode == STV0900_SINGLE) && (foundModcod > STV0900_8PSK_910)) {
1257 if (foundModcod <= STV0900_16APSK_910) {
1258 stv0900_write_reg(i_params, R0900_P2_ACLC2S2Q, 0x2a);
1259 stv0900_write_reg(i_params, R0900_P2_ACLC2S216A, aclc);
1260 } else if (foundModcod <= STV0900_32APSK_910) {
1261 stv0900_write_reg(i_params, R0900_P2_ACLC2S2Q, 0x2a);
1262 stv0900_write_reg(i_params, R0900_P2_ACLC2S232A, aclc);
1263 }
1264
1265 }
1266
1267 } else {
1268 aclc = stv0900_get_optim_short_carr_loop(srate,
1269 i_params->dmd2_rslts.modulation,
1270 i_params->chip_id);
1271
1272 if (i_params->dmd2_rslts.modulation == STV0900_QPSK)
1273 stv0900_write_reg(i_params, R0900_P2_ACLC2S2Q, aclc);
1274
1275 else if (i_params->dmd2_rslts.modulation == STV0900_8PSK) {
1276 stv0900_write_reg(i_params, R0900_P2_ACLC2S2Q, 0x2a);
1277 stv0900_write_reg(i_params, R0900_P2_ACLC2S28, aclc);
1278 } else if (i_params->dmd2_rslts.modulation == STV0900_16APSK) {
1279 stv0900_write_reg(i_params, R0900_P2_ACLC2S2Q, 0x2a);
1280 stv0900_write_reg(i_params, R0900_P2_ACLC2S216A, aclc);
1281 } else if (i_params->dmd2_rslts.modulation == STV0900_32APSK) {
1282 stv0900_write_reg(i_params, R0900_P2_ACLC2S2Q, 0x2a);
1283 stv0900_write_reg(i_params, R0900_P2_ACLC2S232A, aclc);
1284 }
1285 }
1286
1287 stv0900_write_reg(i_params, R0900_P2_ERRCTRL1, 0x67);
1288
1289 break;
1290 case STV0900_UNKNOWN_STANDARD:
1291 default:
1292 stv0900_write_bits(i_params, F0900_P2_DVBS1_ENABLE, 1);
1293 stv0900_write_bits(i_params, F0900_P2_DVBS2_ENABLE, 1);
1294 break;
1295 }
1296
1297 freq1 = stv0900_read_reg(i_params, R0900_P2_CFR2);
1298 freq0 = stv0900_read_reg(i_params, R0900_P2_CFR1);
1299 rolloff = stv0900_get_bits(i_params, F0900_P2_ROLLOFF_STATUS);
1300 if (i_params->dmd2_srch_algo == STV0900_BLIND_SEARCH) {
1301 stv0900_write_reg(i_params, R0900_P2_SFRSTEP, 0x00);
1302 stv0900_write_bits(i_params, F0900_P2_SCAN_ENABLE, 0);
1303 stv0900_write_bits(i_params, F0900_P2_CFR_AUTOSCAN, 0);
1304 stv0900_write_reg(i_params, R0900_P2_TMGCFG2, 0x01);
1305 stv0900_set_symbol_rate(i_params, i_params->mclk, srate, demod);
1306 stv0900_set_max_symbol_rate(i_params, i_params->mclk, srate, demod);
1307 stv0900_set_min_symbol_rate(i_params, i_params->mclk, srate, demod);
1308 blindTunSw = 1;
1309 }
1310
1311 if (i_params->chip_id >= 0x20) {
1312 if ((i_params->dmd2_srch_stndrd == STV0900_SEARCH_DVBS1) || (i_params->dmd2_srch_stndrd == STV0900_SEARCH_DSS) || (i_params->dmd2_srch_stndrd == STV0900_AUTO_SEARCH)) {
1313 stv0900_write_reg(i_params, R0900_P2_VAVSRVIT, 0x0a);
1314 stv0900_write_reg(i_params, R0900_P2_VITSCALE, 0x0);
1315 }
1316 }
1317
1318 if (i_params->chip_id < 0x20)
1319 stv0900_write_reg(i_params, R0900_P2_CARHDR, 0x08);
1320
1321 if (i_params->chip_id == 0x10)
1322 stv0900_write_reg(i_params, R0900_P2_CORRELEXP, 0x0a);
1323
1324 stv0900_write_reg(i_params, R0900_P2_AGC2REF, 0x38);
1325 if ((i_params->chip_id >= 0x20) || (blindTunSw == 1) || (i_params->dmd2_symbol_rate < 10000000)) {
1326 stv0900_write_reg(i_params, R0900_P2_CFRINIT1, freq1);
1327 stv0900_write_reg(i_params, R0900_P2_CFRINIT0, freq0);
1328 i_params->tuner2_bw = stv0900_carrier_width(srate, i_params->rolloff) + 10000000;
1329
1330 if ((i_params->chip_id >= 0x20) || (blindTunSw == 1)) {
1331 if (i_params->dmd2_srch_algo != STV0900_WARM_START)
1332 stv0900_set_bandwidth(fe, i_params->tuner2_bw);
1333 }
1334
1335 if ((i_params->dmd2_srch_algo == STV0900_BLIND_SEARCH) || (i_params->dmd2_symbol_rate < 10000000))
1336 msleep(50);
1337 else
1338 msleep(5);
1339
1340 stv0900_get_lock_timeout(&timed, &timef, srate, STV0900_WARM_START);
1341 if (stv0900_get_demod_lock(i_params, demod, timed / 2) == FALSE) {
1342 stv0900_write_reg(i_params, R0900_P2_DMDISTATE, 0x1F);
1343 stv0900_write_reg(i_params, R0900_P2_CFRINIT1, freq1);
1344 stv0900_write_reg(i_params, R0900_P2_CFRINIT0, freq0);
1345 stv0900_write_reg(i_params, R0900_P2_DMDISTATE, 0x18);
1346 i = 0;
1347 while ((stv0900_get_demod_lock(i_params, demod, timed / 2) == FALSE) && (i <= 2)) {
1348 stv0900_write_reg(i_params, R0900_P2_DMDISTATE, 0x1F);
1349 stv0900_write_reg(i_params, R0900_P2_CFRINIT1, freq1);
1350 stv0900_write_reg(i_params, R0900_P2_CFRINIT0, freq0);
1351 stv0900_write_reg(i_params, R0900_P2_DMDISTATE, 0x18);
1352 i++;
1353 }
1354 }
1355 }
1356
1357 if (i_params->chip_id >= 0x20)
1358 stv0900_write_reg(i_params, R0900_P2_CARFREQ, 0x49);
1359
1360 if ((i_params->dmd2_rslts.standard == STV0900_DVBS1_STANDARD) || (i_params->dmd2_rslts.standard == STV0900_DSS_STANDARD))
1361 stv0900_set_viterbi_tracq(i_params, demod);
1362
1363 break;
1364 }
1365}
1366
1367static int stv0900_get_fec_lock(struct stv0900_internal *i_params, enum fe_stv0900_demod_num demod, s32 time_out)
1368{
1369 s32 timer = 0, lock = 0, header_field, pktdelin_field, lock_vit_field;
1370
1371 enum fe_stv0900_search_state dmd_state;
1372
1373 dprintk(KERN_INFO "%s\n", __func__);
1374
1375 dmd_reg(header_field, F0900_P1_HEADER_MODE, F0900_P2_HEADER_MODE);
1376 dmd_reg(pktdelin_field, F0900_P1_PKTDELIN_LOCK, F0900_P2_PKTDELIN_LOCK);
1377 dmd_reg(lock_vit_field, F0900_P1_LOCKEDVIT, F0900_P2_LOCKEDVIT);
1378
1379 dmd_state = stv0900_get_bits(i_params, header_field);
1380
1381 while ((timer < time_out) && (lock == 0)) {
1382 switch (dmd_state) {
1383 case STV0900_SEARCH:
1384 case STV0900_PLH_DETECTED:
1385 default:
1386 lock = 0;
1387 break;
1388 case STV0900_DVBS2_FOUND:
1389 lock = stv0900_get_bits(i_params, pktdelin_field);
1390 break;
1391 case STV0900_DVBS_FOUND:
1392 lock = stv0900_get_bits(i_params, lock_vit_field);
1393 break;
1394 }
1395
1396 if (lock == 0) {
1397 msleep(10);
1398 timer += 10;
1399 }
1400 }
1401
1402 if (lock)
1403 dprintk("DEMOD FEC LOCK OK\n");
1404 else
1405 dprintk("DEMOD FEC LOCK FAIL\n");
1406
1407 return lock;
1408}
1409
1410static int stv0900_wait_for_lock(struct stv0900_internal *i_params,
1411 enum fe_stv0900_demod_num demod,
1412 s32 dmd_timeout, s32 fec_timeout)
1413{
1414
1415 s32 timer = 0, lock = 0, str_merg_rst_fld, str_merg_lock_fld;
1416
1417 dprintk(KERN_INFO "%s\n", __func__);
1418
1419 dmd_reg(str_merg_rst_fld, F0900_P1_RST_HWARE, F0900_P2_RST_HWARE);
1420 dmd_reg(str_merg_lock_fld, F0900_P1_TSFIFO_LINEOK, F0900_P2_TSFIFO_LINEOK);
1421
1422 lock = stv0900_get_demod_lock(i_params, demod, dmd_timeout);
1423
1424 if (lock)
1425 lock = lock && stv0900_get_fec_lock(i_params, demod, fec_timeout);
1426
1427 if (lock) {
1428 lock = 0;
1429
1430 dprintk(KERN_INFO "%s: Timer = %d, time_out = %d\n", __func__, timer, fec_timeout);
1431
1432 while ((timer < fec_timeout) && (lock == 0)) {
1433 lock = stv0900_get_bits(i_params, str_merg_lock_fld);
1434 msleep(1);
1435 timer++;
1436 }
1437 }
1438
1439 if (lock)
1440 dprintk(KERN_INFO "%s: DEMOD LOCK OK\n", __func__);
1441 else
1442 dprintk(KERN_INFO "%s: DEMOD LOCK FAIL\n", __func__);
1443
1444 if (lock)
1445 return TRUE;
1446 else
1447 return FALSE;
1448}
1449
1450enum fe_stv0900_tracking_standard stv0900_get_standard(struct dvb_frontend *fe,
1451 enum fe_stv0900_demod_num demod)
1452{
1453 struct stv0900_state *state = fe->demodulator_priv;
1454 struct stv0900_internal *i_params = state->internal;
1455 enum fe_stv0900_tracking_standard fnd_standard;
1456 s32 state_field,
1457 dss_dvb_field;
1458
1459 dprintk(KERN_INFO "%s\n", __func__);
1460
1461 dmd_reg(state_field, F0900_P1_HEADER_MODE, F0900_P2_HEADER_MODE);
1462 dmd_reg(dss_dvb_field, F0900_P1_DSS_DVB, F0900_P2_DSS_DVB);
1463
1464 if (stv0900_get_bits(i_params, state_field) == 2)
1465 fnd_standard = STV0900_DVBS2_STANDARD;
1466
1467 else if (stv0900_get_bits(i_params, state_field) == 3) {
1468 if (stv0900_get_bits(i_params, dss_dvb_field) == 1)
1469 fnd_standard = STV0900_DSS_STANDARD;
1470 else
1471 fnd_standard = STV0900_DVBS1_STANDARD;
1472 } else
1473 fnd_standard = STV0900_UNKNOWN_STANDARD;
1474
1475 return fnd_standard;
1476}
1477
1478static s32 stv0900_get_carr_freq(struct stv0900_internal *i_params, u32 mclk,
1479 enum fe_stv0900_demod_num demod)
1480{
1481 s32 cfr_field2, cfr_field1, cfr_field0,
1482 derot, rem1, rem2, intval1, intval2;
1483
1484 dmd_reg(cfr_field2, F0900_P1_CAR_FREQ2, F0900_P2_CAR_FREQ2);
1485 dmd_reg(cfr_field1, F0900_P1_CAR_FREQ1, F0900_P2_CAR_FREQ1);
1486 dmd_reg(cfr_field0, F0900_P1_CAR_FREQ0, F0900_P2_CAR_FREQ0);
1487
1488 derot = (stv0900_get_bits(i_params, cfr_field2) << 16) +
1489 (stv0900_get_bits(i_params, cfr_field1) << 8) +
1490 (stv0900_get_bits(i_params, cfr_field0));
1491
1492 derot = ge2comp(derot, 24);
1493 intval1 = mclk >> 12;
1494 intval2 = derot >> 12;
1495 rem1 = mclk % 0x1000;
1496 rem2 = derot % 0x1000;
1497 derot = (intval1 * intval2) +
1498 ((intval1 * rem2) >> 12) +
1499 ((intval2 * rem1) >> 12);
1500
1501 return derot;
1502}
1503
1504static u32 stv0900_get_tuner_freq(struct dvb_frontend *fe)
1505{
1506 struct dvb_frontend_ops *frontend_ops = NULL;
1507 struct dvb_tuner_ops *tuner_ops = NULL;
1508 u32 frequency = 0;
1509
1510 if (&fe->ops)
1511 frontend_ops = &fe->ops;
1512
1513 if (&frontend_ops->tuner_ops)
1514 tuner_ops = &frontend_ops->tuner_ops;
1515
1516 if (tuner_ops->get_frequency) {
1517 if ((tuner_ops->get_frequency(fe, &frequency)) < 0)
1518 dprintk("%s: Invalid parameter\n", __func__);
1519 else
1520 dprintk("%s: Frequency=%d\n", __func__, frequency);
1521
1522 }
1523
1524 return frequency;
1525}
1526
1527static enum fe_stv0900_fec stv0900_get_vit_fec(struct stv0900_internal *i_params,
1528 enum fe_stv0900_demod_num demod)
1529{
1530 s32 rate_fld, vit_curpun_fld;
1531 enum fe_stv0900_fec prate;
1532
1533 dmd_reg(vit_curpun_fld, F0900_P1_VIT_CURPUN, F0900_P2_VIT_CURPUN);
1534 rate_fld = stv0900_get_bits(i_params, vit_curpun_fld);
1535
1536 switch (rate_fld) {
1537 case 13:
1538 prate = STV0900_FEC_1_2;
1539 break;
1540 case 18:
1541 prate = STV0900_FEC_2_3;
1542 break;
1543 case 21:
1544 prate = STV0900_FEC_3_4;
1545 break;
1546 case 24:
1547 prate = STV0900_FEC_5_6;
1548 break;
1549 case 25:
1550 prate = STV0900_FEC_6_7;
1551 break;
1552 case 26:
1553 prate = STV0900_FEC_7_8;
1554 break;
1555 default:
1556 prate = STV0900_FEC_UNKNOWN;
1557 break;
1558 }
1559
1560 return prate;
1561}
1562
1563static enum fe_stv0900_signal_type stv0900_get_signal_params(struct dvb_frontend *fe)
1564{
1565 struct stv0900_state *state = fe->demodulator_priv;
1566 struct stv0900_internal *i_params = state->internal;
1567 enum fe_stv0900_demod_num demod = state->demod;
1568 enum fe_stv0900_signal_type range = STV0900_OUTOFRANGE;
1569 s32 offsetFreq,
1570 srate_offset,
1571 i = 0;
1572
1573 u8 timing;
1574
1575 msleep(5);
1576 switch (demod) {
1577 case STV0900_DEMOD_1:
1578 default:
1579 if (i_params->dmd1_srch_algo == STV0900_BLIND_SEARCH) {
1580 timing = stv0900_read_reg(i_params, R0900_P1_TMGREG2);
1581 i = 0;
1582 stv0900_write_reg(i_params, R0900_P1_SFRSTEP, 0x5c);
1583
1584 while ((i <= 50) && (timing != 0) && (timing != 0xFF)) {
1585 timing = stv0900_read_reg(i_params, R0900_P1_TMGREG2);
1586 msleep(5);
1587 i += 5;
1588 }
1589 }
1590
1591 i_params->dmd1_rslts.standard = stv0900_get_standard(fe, demod);
1592 i_params->dmd1_rslts.frequency = stv0900_get_tuner_freq(fe);
1593 offsetFreq = stv0900_get_carr_freq(i_params, i_params->mclk, demod) / 1000;
1594 i_params->dmd1_rslts.frequency += offsetFreq;
1595 i_params->dmd1_rslts.symbol_rate = stv0900_get_symbol_rate(i_params, i_params->mclk, demod);
1596 srate_offset = stv0900_get_timing_offst(i_params, i_params->dmd1_rslts.symbol_rate, demod);
1597 i_params->dmd1_rslts.symbol_rate += srate_offset;
1598 i_params->dmd1_rslts.fec = stv0900_get_vit_fec(i_params, demod);
1599 i_params->dmd1_rslts.modcode = stv0900_get_bits(i_params, F0900_P1_DEMOD_MODCOD);
1600 i_params->dmd1_rslts.pilot = stv0900_get_bits(i_params, F0900_P1_DEMOD_TYPE) & 0x01;
1601 i_params->dmd1_rslts.frame_length = ((u32)stv0900_get_bits(i_params, F0900_P1_DEMOD_TYPE)) >> 1;
1602 i_params->dmd1_rslts.rolloff = stv0900_get_bits(i_params, F0900_P1_ROLLOFF_STATUS);
1603 switch (i_params->dmd1_rslts.standard) {
1604 case STV0900_DVBS2_STANDARD:
1605 i_params->dmd1_rslts.spectrum = stv0900_get_bits(i_params, F0900_P1_SPECINV_DEMOD);
1606 if (i_params->dmd1_rslts.modcode <= STV0900_QPSK_910)
1607 i_params->dmd1_rslts.modulation = STV0900_QPSK;
1608 else if (i_params->dmd1_rslts.modcode <= STV0900_8PSK_910)
1609 i_params->dmd1_rslts.modulation = STV0900_8PSK;
1610 else if (i_params->dmd1_rslts.modcode <= STV0900_16APSK_910)
1611 i_params->dmd1_rslts.modulation = STV0900_16APSK;
1612 else if (i_params->dmd1_rslts.modcode <= STV0900_32APSK_910)
1613 i_params->dmd1_rslts.modulation = STV0900_32APSK;
1614 else
1615 i_params->dmd1_rslts.modulation = STV0900_UNKNOWN;
1616 break;
1617 case STV0900_DVBS1_STANDARD:
1618 case STV0900_DSS_STANDARD:
1619 i_params->dmd1_rslts.spectrum = stv0900_get_bits(i_params, F0900_P1_IQINV);
1620 i_params->dmd1_rslts.modulation = STV0900_QPSK;
1621 break;
1622 default:
1623 break;
1624 }
1625
1626 if ((i_params->dmd1_srch_algo == STV0900_BLIND_SEARCH) || (i_params->dmd1_symbol_rate < 10000000)) {
1627 offsetFreq = i_params->dmd1_rslts.frequency - i_params->tuner1_freq;
1628 i_params->tuner1_freq = stv0900_get_tuner_freq(fe);
1629 if (ABS(offsetFreq) <= ((i_params->dmd1_srch_range / 2000) + 500))
1630 range = STV0900_RANGEOK;
1631 else
1632 if (ABS(offsetFreq) <= (stv0900_carrier_width(i_params->dmd1_rslts.symbol_rate, i_params->dmd1_rslts.rolloff) / 2000))
1633 range = STV0900_RANGEOK;
1634 else
1635 range = STV0900_OUTOFRANGE;
1636
1637 } else {
1638 if (ABS(offsetFreq) <= ((i_params->dmd1_srch_range / 2000) + 500))
1639 range = STV0900_RANGEOK;
1640 else
1641 range = STV0900_OUTOFRANGE;
1642 }
1643 break;
1644 case STV0900_DEMOD_2:
1645 if (i_params->dmd2_srch_algo == STV0900_BLIND_SEARCH) {
1646 timing = stv0900_read_reg(i_params, R0900_P2_TMGREG2);
1647 i = 0;
1648 stv0900_write_reg(i_params, R0900_P2_SFRSTEP, 0x5c);
1649
1650 while ((i <= 50) && (timing != 0) && (timing != 0xff)) {
1651 timing = stv0900_read_reg(i_params, R0900_P2_TMGREG2);
1652 msleep(5);
1653 i += 5;
1654 }
1655 }
1656
1657 i_params->dmd2_rslts.standard = stv0900_get_standard(fe, demod);
1658 i_params->dmd2_rslts.frequency = stv0900_get_tuner_freq(fe);
1659 offsetFreq = stv0900_get_carr_freq(i_params, i_params->mclk, demod) / 1000;
1660 i_params->dmd2_rslts.frequency += offsetFreq;
1661 i_params->dmd2_rslts.symbol_rate = stv0900_get_symbol_rate(i_params, i_params->mclk, demod);
1662 srate_offset = stv0900_get_timing_offst(i_params, i_params->dmd2_rslts.symbol_rate, demod);
1663 i_params->dmd2_rslts.symbol_rate += srate_offset;
1664 i_params->dmd2_rslts.fec = stv0900_get_vit_fec(i_params, demod);
1665 i_params->dmd2_rslts.modcode = stv0900_get_bits(i_params, F0900_P2_DEMOD_MODCOD);
1666 i_params->dmd2_rslts.pilot = stv0900_get_bits(i_params, F0900_P2_DEMOD_TYPE) & 0x01;
1667 i_params->dmd2_rslts.frame_length = ((u32)stv0900_get_bits(i_params, F0900_P2_DEMOD_TYPE)) >> 1;
1668 i_params->dmd2_rslts.rolloff = stv0900_get_bits(i_params, F0900_P2_ROLLOFF_STATUS);
1669 switch (i_params->dmd2_rslts.standard) {
1670 case STV0900_DVBS2_STANDARD:
1671 i_params->dmd2_rslts.spectrum = stv0900_get_bits(i_params, F0900_P2_SPECINV_DEMOD);
1672 if (i_params->dmd2_rslts.modcode <= STV0900_QPSK_910)
1673 i_params->dmd2_rslts.modulation = STV0900_QPSK;
1674 else if (i_params->dmd2_rslts.modcode <= STV0900_8PSK_910)
1675 i_params->dmd2_rslts.modulation = STV0900_8PSK;
1676 else if (i_params->dmd2_rslts.modcode <= STV0900_16APSK_910)
1677 i_params->dmd2_rslts.modulation = STV0900_16APSK;
1678 else if (i_params->dmd2_rslts.modcode <= STV0900_32APSK_910)
1679 i_params->dmd2_rslts.modulation = STV0900_32APSK;
1680 else
1681 i_params->dmd2_rslts.modulation = STV0900_UNKNOWN;
1682 break;
1683 case STV0900_DVBS1_STANDARD:
1684 case STV0900_DSS_STANDARD:
1685 i_params->dmd2_rslts.spectrum = stv0900_get_bits(i_params, F0900_P2_IQINV);
1686 i_params->dmd2_rslts.modulation = STV0900_QPSK;
1687 break;
1688 default:
1689 break;
1690 }
1691
1692 if ((i_params->dmd2_srch_algo == STV0900_BLIND_SEARCH) || (i_params->dmd2_symbol_rate < 10000000)) {
1693 offsetFreq = i_params->dmd2_rslts.frequency - i_params->tuner2_freq;
1694 i_params->tuner2_freq = stv0900_get_tuner_freq(fe);
1695
1696 if (ABS(offsetFreq) <= ((i_params->dmd2_srch_range / 2000) + 500))
1697 range = STV0900_RANGEOK;
1698 else
1699 if (ABS(offsetFreq) <= (stv0900_carrier_width(i_params->dmd2_rslts.symbol_rate, i_params->dmd2_rslts.rolloff) / 2000))
1700 range = STV0900_RANGEOK;
1701 else
1702 range = STV0900_OUTOFRANGE;
1703 } else {
1704 if (ABS(offsetFreq) <= ((i_params->dmd2_srch_range / 2000) + 500))
1705 range = STV0900_RANGEOK;
1706 else
1707 range = STV0900_OUTOFRANGE;
1708 }
1709
1710 break;
1711 }
1712
1713 return range;
1714}
1715
1716static enum fe_stv0900_signal_type stv0900_dvbs1_acq_workaround(struct dvb_frontend *fe)
1717{
1718 struct stv0900_state *state = fe->demodulator_priv;
1719 struct stv0900_internal *i_params = state->internal;
1720 enum fe_stv0900_demod_num demod = state->demod;
1721
1722 s32 srate, demod_timeout,
1723 fec_timeout, freq1, freq0;
1724 enum fe_stv0900_signal_type signal_type = STV0900_NODATA;;
1725
1726 switch (demod) {
1727 case STV0900_DEMOD_1:
1728 default:
1729 i_params->dmd1_rslts.locked = FALSE;
1730 if (stv0900_get_bits(i_params, F0900_P1_HEADER_MODE) == STV0900_DVBS_FOUND) {
1731 srate = stv0900_get_symbol_rate(i_params, i_params->mclk, demod);
1732 srate += stv0900_get_timing_offst(i_params, srate, demod);
1733 if (i_params->dmd1_srch_algo == STV0900_BLIND_SEARCH)
1734 stv0900_set_symbol_rate(i_params, i_params->mclk, srate, demod);
1735
1736 stv0900_get_lock_timeout(&demod_timeout, &fec_timeout, srate, STV0900_WARM_START);
1737 freq1 = stv0900_read_reg(i_params, R0900_P1_CFR2);
1738 freq0 = stv0900_read_reg(i_params, R0900_P1_CFR1);
1739 stv0900_write_bits(i_params, F0900_P1_CFR_AUTOSCAN, 0);
1740 stv0900_write_bits(i_params, F0900_P1_SPECINV_CONTROL, STV0900_IQ_FORCE_SWAPPED);
1741 stv0900_write_reg(i_params, R0900_P1_DMDISTATE, 0x1C);
1742 stv0900_write_reg(i_params, R0900_P1_CFRINIT1, freq1);
1743 stv0900_write_reg(i_params, R0900_P1_CFRINIT0, freq0);
1744 stv0900_write_reg(i_params, R0900_P1_DMDISTATE, 0x18);
1745 if (stv0900_wait_for_lock(i_params, demod, demod_timeout, fec_timeout) == TRUE) {
1746 i_params->dmd1_rslts.locked = TRUE;
1747 signal_type = stv0900_get_signal_params(fe);
1748 stv0900_track_optimization(fe);
1749 } else {
1750 stv0900_write_bits(i_params, F0900_P1_SPECINV_CONTROL, STV0900_IQ_FORCE_NORMAL);
1751 stv0900_write_reg(i_params, R0900_P1_DMDISTATE, 0x1c);
1752 stv0900_write_reg(i_params, R0900_P1_CFRINIT1, freq1);
1753 stv0900_write_reg(i_params, R0900_P1_CFRINIT0, freq0);
1754 stv0900_write_reg(i_params, R0900_P1_DMDISTATE, 0x18);
1755 if (stv0900_wait_for_lock(i_params, demod, demod_timeout, fec_timeout) == TRUE) {
1756 i_params->dmd1_rslts.locked = TRUE;
1757 signal_type = stv0900_get_signal_params(fe);
1758 stv0900_track_optimization(fe);
1759 }
1760
1761 }
1762
1763 } else
1764 i_params->dmd1_rslts.locked = FALSE;
1765
1766 break;
1767 case STV0900_DEMOD_2:
1768 i_params->dmd2_rslts.locked = FALSE;
1769 if (stv0900_get_bits(i_params, F0900_P2_HEADER_MODE) == STV0900_DVBS_FOUND) {
1770 srate = stv0900_get_symbol_rate(i_params, i_params->mclk, demod);
1771 srate += stv0900_get_timing_offst(i_params, srate, demod);
1772
1773 if (i_params->dmd2_srch_algo == STV0900_BLIND_SEARCH)
1774 stv0900_set_symbol_rate(i_params, i_params->mclk, srate, demod);
1775
1776 stv0900_get_lock_timeout(&demod_timeout, &fec_timeout, srate, STV0900_WARM_START);
1777 freq1 = stv0900_read_reg(i_params, R0900_P2_CFR2);
1778 freq0 = stv0900_read_reg(i_params, R0900_P2_CFR1);
1779 stv0900_write_bits(i_params, F0900_P2_CFR_AUTOSCAN, 0);
1780 stv0900_write_bits(i_params, F0900_P2_SPECINV_CONTROL, STV0900_IQ_FORCE_SWAPPED);
1781 stv0900_write_reg(i_params, R0900_P2_DMDISTATE, 0x1C);
1782 stv0900_write_reg(i_params, R0900_P2_CFRINIT1, freq1);
1783 stv0900_write_reg(i_params, R0900_P2_CFRINIT0, freq0);
1784 stv0900_write_reg(i_params, R0900_P2_DMDISTATE, 0x18);
1785
1786 if (stv0900_wait_for_lock(i_params, demod, demod_timeout, fec_timeout) == TRUE) {
1787 i_params->dmd2_rslts.locked = TRUE;
1788 signal_type = stv0900_get_signal_params(fe);
1789 stv0900_track_optimization(fe);
1790 } else {
1791 stv0900_write_bits(i_params, F0900_P2_SPECINV_CONTROL, STV0900_IQ_FORCE_NORMAL);
1792 stv0900_write_reg(i_params, R0900_P2_DMDISTATE, 0x1c);
1793 stv0900_write_reg(i_params, R0900_P2_CFRINIT1, freq1);
1794 stv0900_write_reg(i_params, R0900_P2_CFRINIT0, freq0);
1795 stv0900_write_reg(i_params, R0900_P2_DMDISTATE, 0x18);
1796
1797 if (stv0900_wait_for_lock(i_params, demod, demod_timeout, fec_timeout) == TRUE) {
1798 i_params->dmd2_rslts.locked = TRUE;
1799 signal_type = stv0900_get_signal_params(fe);
1800 stv0900_track_optimization(fe);
1801 }
1802
1803 }
1804
1805 } else
1806 i_params->dmd1_rslts.locked = FALSE;
1807
1808 break;
1809 }
1810
1811 return signal_type;
1812}
1813
1814static u16 stv0900_blind_check_agc2_min_level(struct stv0900_internal *i_params,
1815 enum fe_stv0900_demod_num demod)
1816{
1817 u32 minagc2level = 0xffff,
1818 agc2level,
1819 init_freq, freq_step;
1820
1821 s32 i, j, nb_steps, direction;
1822
1823 dprintk(KERN_INFO "%s\n", __func__);
1824
1825 switch (demod) {
1826 case STV0900_DEMOD_1:
1827 default:
1828 stv0900_write_reg(i_params, R0900_P1_AGC2REF, 0x38);
1829 stv0900_write_bits(i_params, F0900_P1_SCAN_ENABLE, 1);
1830 stv0900_write_bits(i_params, F0900_P1_CFR_AUTOSCAN, 1);
1831
1832 stv0900_write_reg(i_params, R0900_P1_SFRUP1, 0x83);
1833 stv0900_write_reg(i_params, R0900_P1_SFRUP0, 0xc0);
1834
1835 stv0900_write_reg(i_params, R0900_P1_SFRLOW1, 0x82);
1836 stv0900_write_reg(i_params, R0900_P1_SFRLOW0, 0xa0);
1837 stv0900_write_reg(i_params, R0900_P1_DMDT0M, 0x0);
1838
1839 stv0900_set_symbol_rate(i_params, i_params->mclk, 1000000, demod);
1840 nb_steps = -1 + (i_params->dmd1_srch_range / 1000000);
1841 nb_steps /= 2;
1842 nb_steps = (2 * nb_steps) + 1;
1843
1844 if (nb_steps < 0)
1845 nb_steps = 1;
1846
1847 direction = 1;
1848
1849 freq_step = (1000000 << 8) / (i_params->mclk >> 8);
1850
1851 init_freq = 0;
1852
1853 for (i = 0; i < nb_steps; i++) {
1854 if (direction > 0)
1855 init_freq = init_freq + (freq_step * i);
1856 else
1857 init_freq = init_freq - (freq_step * i);
1858
1859 direction *= -1;
1860 stv0900_write_reg(i_params, R0900_P1_DMDISTATE, 0x5C);
1861 stv0900_write_reg(i_params, R0900_P1_CFRINIT1, (init_freq >> 8) & 0xff);
1862 stv0900_write_reg(i_params, R0900_P1_CFRINIT0, init_freq & 0xff);
1863 stv0900_write_reg(i_params, R0900_P1_DMDISTATE, 0x58);
1864 msleep(10);
1865 agc2level = 0;
1866
1867 for (j = 0; j < 10; j++)
1868 agc2level += (stv0900_read_reg(i_params, R0900_P1_AGC2I1) << 8)
1869 | stv0900_read_reg(i_params, R0900_P1_AGC2I0);
1870
1871 agc2level /= 10;
1872
1873 if (agc2level < minagc2level)
1874 minagc2level = agc2level;
1875 }
1876 break;
1877 case STV0900_DEMOD_2:
1878 stv0900_write_reg(i_params, R0900_P2_AGC2REF, 0x38);
1879 stv0900_write_bits(i_params, F0900_P2_SCAN_ENABLE, 1);
1880 stv0900_write_bits(i_params, F0900_P2_CFR_AUTOSCAN, 1);
1881 stv0900_write_reg(i_params, R0900_P2_SFRUP1, 0x83);
1882 stv0900_write_reg(i_params, R0900_P2_SFRUP0, 0xc0);
1883 stv0900_write_reg(i_params, R0900_P2_SFRLOW1, 0x82);
1884 stv0900_write_reg(i_params, R0900_P2_SFRLOW0, 0xa0);
1885 stv0900_write_reg(i_params, R0900_P2_DMDT0M, 0x0);
1886 stv0900_set_symbol_rate(i_params, i_params->mclk, 1000000, demod);
1887 nb_steps = -1 + (i_params->dmd2_srch_range / 1000000);
1888 nb_steps /= 2;
1889 nb_steps = (2 * nb_steps) + 1;
1890
1891 if (nb_steps < 0)
1892 nb_steps = 1;
1893
1894 direction = 1;
1895 freq_step = (1000000 << 8) / (i_params->mclk >> 8);
1896 init_freq = 0;
1897 for (i = 0; i < nb_steps; i++) {
1898 if (direction > 0)
1899 init_freq = init_freq + (freq_step * i);
1900 else
1901 init_freq = init_freq - (freq_step * i);
1902
1903 direction *= -1;
1904
1905 stv0900_write_reg(i_params, R0900_P2_DMDISTATE, 0x5C);
1906 stv0900_write_reg(i_params, R0900_P2_CFRINIT1, (init_freq >> 8) & 0xff);
1907 stv0900_write_reg(i_params, R0900_P2_CFRINIT0, init_freq & 0xff);
1908 stv0900_write_reg(i_params, R0900_P2_DMDISTATE, 0x58);
1909
1910 msleep(10);
1911 agc2level = 0;
1912 for (j = 0; j < 10; j++)
1913 agc2level += (stv0900_read_reg(i_params, R0900_P2_AGC2I1) << 8)
1914 | stv0900_read_reg(i_params, R0900_P2_AGC2I0);
1915
1916 agc2level /= 10;
1917
1918 if (agc2level < minagc2level)
1919 minagc2level = agc2level;
1920 }
1921 break;
1922 }
1923
1924 return (u16)minagc2level;
1925}
1926
1927static u32 stv0900_search_srate_coarse(struct dvb_frontend *fe)
1928{
1929 struct stv0900_state *state = fe->demodulator_priv;
1930 struct stv0900_internal *i_params = state->internal;
1931 enum fe_stv0900_demod_num demod = state->demod;
1932 int timingLock = FALSE;
1933 s32 i, timingcpt = 0,
1934 direction = 1,
1935 nb_steps,
1936 current_step = 0,
1937 tuner_freq;
1938
1939 u32 coarse_srate = 0, agc2_integr = 0, currier_step = 1200;
1940
1941 switch (demod) {
1942 case STV0900_DEMOD_1:
1943 default:
1944 stv0900_write_bits(i_params, F0900_P1_I2C_DEMOD_MODE, 0x1F);
1945 stv0900_write_reg(i_params, R0900_P1_TMGCFG, 0x12);
1946 stv0900_write_reg(i_params, R0900_P1_TMGTHRISE, 0xf0);
1947 stv0900_write_reg(i_params, R0900_P1_TMGTHFALL, 0xe0);
1948 stv0900_write_bits(i_params, F0900_P1_SCAN_ENABLE, 1);
1949 stv0900_write_bits(i_params, F0900_P1_CFR_AUTOSCAN, 1);
1950 stv0900_write_reg(i_params, R0900_P1_SFRUP1, 0x83);
1951 stv0900_write_reg(i_params, R0900_P1_SFRUP0, 0xc0);
1952 stv0900_write_reg(i_params, R0900_P1_SFRLOW1, 0x82);
1953 stv0900_write_reg(i_params, R0900_P1_SFRLOW0, 0xa0);
1954 stv0900_write_reg(i_params, R0900_P1_DMDT0M, 0x0);
1955 stv0900_write_reg(i_params, R0900_P1_AGC2REF, 0x50);
1956
1957 if (i_params->chip_id >= 0x20) {
1958 stv0900_write_reg(i_params, R0900_P1_CARFREQ, 0x6a);
1959 stv0900_write_reg(i_params, R0900_P1_SFRSTEP, 0x95);
1960 } else {
1961 stv0900_write_reg(i_params, R0900_P1_CARFREQ, 0xed);
1962 stv0900_write_reg(i_params, R0900_P1_SFRSTEP, 0x73);
1963 }
1964
1965 if (i_params->dmd1_symbol_rate <= 2000000)
1966 currier_step = 1000;
1967 else if (i_params->dmd1_symbol_rate <= 5000000)
1968 currier_step = 2000;
1969 else if (i_params->dmd1_symbol_rate <= 12000000)
1970 currier_step = 3000;
1971 else
1972 currier_step = 5000;
1973
1974 nb_steps = -1 + ((i_params->dmd1_srch_range / 1000) / currier_step);
1975 nb_steps /= 2;
1976 nb_steps = (2 * nb_steps) + 1;
1977
1978 if (nb_steps < 0)
1979 nb_steps = 1;
1980
1981 else if (nb_steps > 10) {
1982 nb_steps = 11;
1983 currier_step = (i_params->dmd1_srch_range / 1000) / 10;
1984 }
1985
1986 current_step = 0;
1987
1988 direction = 1;
1989 tuner_freq = i_params->tuner1_freq;
1990
1991 while ((timingLock == FALSE) && (current_step < nb_steps)) {
1992 stv0900_write_reg(i_params, R0900_P1_DMDISTATE, 0x5F);
1993 stv0900_write_bits(i_params, F0900_P1_I2C_DEMOD_MODE, 0x0);
1994
1995 msleep(50);
1996
1997 for (i = 0; i < 10; i++) {
1998 if (stv0900_get_bits(i_params, F0900_P1_TMGLOCK_QUALITY) >= 2)
1999 timingcpt++;
2000
2001 agc2_integr += (stv0900_read_reg(i_params, R0900_P1_AGC2I1) << 8) | stv0900_read_reg(i_params, R0900_P1_AGC2I0);
2002
2003 }
2004
2005 agc2_integr /= 10;
2006 coarse_srate = stv0900_get_symbol_rate(i_params, i_params->mclk, demod);
2007 current_step++;
2008 direction *= -1;
2009
2010 dprintk("lock: I2C_DEMOD_MODE_FIELD =0. Search started. tuner freq=%d agc2=0x%x srate_coarse=%d tmg_cpt=%d\n", tuner_freq, agc2_integr, coarse_srate, timingcpt);
2011
2012 if ((timingcpt >= 5) && (agc2_integr < 0x1F00) && (coarse_srate < 55000000) && (coarse_srate > 850000)) {
2013 timingLock = TRUE;
2014 }
2015
2016 else if (current_step < nb_steps) {
2017 if (direction > 0)
2018 tuner_freq += (current_step * currier_step);
2019 else
2020 tuner_freq -= (current_step * currier_step);
2021
2022 stv0900_set_tuner(fe, tuner_freq, i_params->tuner1_bw);
2023 }
2024 }
2025
2026 if (timingLock == FALSE)
2027 coarse_srate = 0;
2028 else
2029 coarse_srate = stv0900_get_symbol_rate(i_params, i_params->mclk, demod);
2030 break;
2031 case STV0900_DEMOD_2:
2032 stv0900_write_bits(i_params, F0900_P2_I2C_DEMOD_MODE, 0x1F);
2033 stv0900_write_reg(i_params, R0900_P2_TMGCFG, 0x12);
2034 stv0900_write_reg(i_params, R0900_P2_TMGTHRISE, 0xf0);
2035 stv0900_write_reg(i_params, R0900_P2_TMGTHFALL, 0xe0);
2036 stv0900_write_bits(i_params, F0900_P2_SCAN_ENABLE, 1);
2037 stv0900_write_bits(i_params, F0900_P2_CFR_AUTOSCAN, 1);
2038 stv0900_write_reg(i_params, R0900_P2_SFRUP1, 0x83);
2039 stv0900_write_reg(i_params, R0900_P2_SFRUP0, 0xc0);
2040 stv0900_write_reg(i_params, R0900_P2_SFRLOW1, 0x82);
2041 stv0900_write_reg(i_params, R0900_P2_SFRLOW0, 0xa0);
2042 stv0900_write_reg(i_params, R0900_P2_DMDT0M, 0x0);
2043 stv0900_write_reg(i_params, R0900_P2_AGC2REF, 0x50);
2044
2045 if (i_params->chip_id >= 0x20) {
2046 stv0900_write_reg(i_params, R0900_P2_CARFREQ, 0x6a);
2047 stv0900_write_reg(i_params, R0900_P2_SFRSTEP, 0x95);
2048 } else {
2049 stv0900_write_reg(i_params, R0900_P2_CARFREQ, 0xed);
2050 stv0900_write_reg(i_params, R0900_P2_SFRSTEP, 0x73);
2051 }
2052
2053 if (i_params->dmd2_symbol_rate <= 2000000)
2054 currier_step = 1000;
2055 else if (i_params->dmd2_symbol_rate <= 5000000)
2056 currier_step = 2000;
2057 else if (i_params->dmd2_symbol_rate <= 12000000)
2058 currier_step = 3000;
2059 else
2060 currier_step = 5000;
2061
2062
2063 nb_steps = -1 + ((i_params->dmd2_srch_range / 1000) / currier_step);
2064 nb_steps /= 2;
2065 nb_steps = (2 * nb_steps) + 1;
2066
2067 if (nb_steps < 0)
2068 nb_steps = 1;
2069 else if (nb_steps > 10) {
2070 nb_steps = 11;
2071 currier_step = (i_params->dmd2_srch_range / 1000) / 10;
2072 }
2073
2074 current_step = 0;
2075 direction = 1;
2076 tuner_freq = i_params->tuner2_freq;
2077
2078 while ((timingLock == FALSE) && (current_step < nb_steps)) {
2079 stv0900_write_reg(i_params, R0900_P2_DMDISTATE, 0x5F);
2080 stv0900_write_bits(i_params, F0900_P2_I2C_DEMOD_MODE, 0x0);
2081
2082 msleep(50);
2083 timingcpt = 0;
2084
2085 for (i = 0; i < 20; i++) {
2086 if (stv0900_get_bits(i_params, F0900_P2_TMGLOCK_QUALITY) >= 2)
2087 timingcpt++;
2088 agc2_integr += (stv0900_read_reg(i_params, R0900_P2_AGC2I1) << 8)
2089 | stv0900_read_reg(i_params, R0900_P2_AGC2I0);
2090 }
2091
2092 agc2_integr /= 20;
2093 coarse_srate = stv0900_get_symbol_rate(i_params, i_params->mclk, demod);
2094 if ((timingcpt >= 10) && (agc2_integr < 0x1F00) && (coarse_srate < 55000000) && (coarse_srate > 850000))
2095 timingLock = TRUE;
2096 else {
2097 current_step++;
2098 direction *= -1;
2099
2100 if (direction > 0)
2101 tuner_freq += (current_step * currier_step);
2102 else
2103 tuner_freq -= (current_step * currier_step);
2104
2105 stv0900_set_tuner(fe, tuner_freq, i_params->tuner2_bw);
2106 }
2107 }
2108
2109 if (timingLock == FALSE)
2110 coarse_srate = 0;
2111 else
2112 coarse_srate = stv0900_get_symbol_rate(i_params, i_params->mclk, demod);
2113 break;
2114 }
2115
2116 return coarse_srate;
2117}
2118
2119static u32 stv0900_search_srate_fine(struct dvb_frontend *fe)
2120{
2121 struct stv0900_state *state = fe->demodulator_priv;
2122 struct stv0900_internal *i_params = state->internal;
2123 enum fe_stv0900_demod_num demod = state->demod;
2124 u32 coarse_srate,
2125 coarse_freq,
2126 symb;
2127
2128 coarse_srate = stv0900_get_symbol_rate(i_params, i_params->mclk, demod);
2129
2130 switch (demod) {
2131 case STV0900_DEMOD_1:
2132 default:
2133 coarse_freq = (stv0900_read_reg(i_params, R0900_P1_CFR2) << 8)
2134 | stv0900_read_reg(i_params, R0900_P1_CFR1);
2135 symb = 13 * (coarse_srate / 10);
2136
2137 if (symb < i_params->dmd1_symbol_rate)
2138 coarse_srate = 0;
2139 else {
2140 stv0900_write_reg(i_params, R0900_P1_DMDISTATE, 0x1F);
2141 stv0900_write_reg(i_params, R0900_P1_TMGCFG2, 0x01);
2142 stv0900_write_reg(i_params, R0900_P1_TMGTHRISE, 0x20);
2143 stv0900_write_reg(i_params, R0900_P1_TMGTHFALL, 0x00);
2144 stv0900_write_reg(i_params, R0900_P1_TMGCFG, 0xd2);
2145 stv0900_write_bits(i_params, F0900_P1_CFR_AUTOSCAN, 0);
2146
2147 if (i_params->chip_id >= 0x20)
2148 stv0900_write_reg(i_params, R0900_P1_CARFREQ, 0x49);
2149 else
2150 stv0900_write_reg(i_params, R0900_P1_CARFREQ, 0xed);
2151
2152 if (coarse_srate > 3000000) {
2153 symb = 13 * (coarse_srate / 10);
2154 symb = (symb / 1000) * 65536;
2155 symb /= (i_params->mclk / 1000);
2156 stv0900_write_reg(i_params, R0900_P1_SFRUP1, (symb >> 8) & 0x7F);
2157 stv0900_write_reg(i_params, R0900_P1_SFRUP0, (symb & 0xFF));
2158
2159 symb = 10 * (coarse_srate / 13);
2160 symb = (symb / 1000) * 65536;
2161 symb /= (i_params->mclk / 1000);
2162
2163 stv0900_write_reg(i_params, R0900_P1_SFRLOW1, (symb >> 8) & 0x7F);
2164 stv0900_write_reg(i_params, R0900_P1_SFRLOW0, (symb & 0xFF));
2165
2166 symb = (coarse_srate / 1000) * 65536;
2167 symb /= (i_params->mclk / 1000);
2168 stv0900_write_reg(i_params, R0900_P1_SFRINIT1, (symb >> 8) & 0xFF);
2169 stv0900_write_reg(i_params, R0900_P1_SFRINIT0, (symb & 0xFF));
2170 } else {
2171 symb = 13 * (coarse_srate / 10);
2172 symb = (symb / 100) * 65536;
2173 symb /= (i_params->mclk / 100);
2174 stv0900_write_reg(i_params, R0900_P1_SFRUP1, (symb >> 8) & 0x7F);
2175 stv0900_write_reg(i_params, R0900_P1_SFRUP0, (symb & 0xFF));
2176
2177 symb = 10 * (coarse_srate / 14);
2178 symb = (symb / 100) * 65536;
2179 symb /= (i_params->mclk / 100);
2180 stv0900_write_reg(i_params, R0900_P1_SFRLOW1, (symb >> 8) & 0x7F);
2181 stv0900_write_reg(i_params, R0900_P1_SFRLOW0, (symb & 0xFF));
2182
2183 symb = (coarse_srate / 100) * 65536;
2184 symb /= (i_params->mclk / 100);
2185 stv0900_write_reg(i_params, R0900_P1_SFRINIT1, (symb >> 8) & 0xFF);
2186 stv0900_write_reg(i_params, R0900_P1_SFRINIT0, (symb & 0xFF));
2187 }
2188
2189 stv0900_write_reg(i_params, R0900_P1_DMDT0M, 0x20);
2190 stv0900_write_reg(i_params, R0900_P1_CFRINIT1, (coarse_freq >> 8) & 0xff);
2191 stv0900_write_reg(i_params, R0900_P1_CFRINIT0, coarse_freq & 0xff);
2192 stv0900_write_reg(i_params, R0900_P1_DMDISTATE, 0x15);
2193 }
2194 break;
2195 case STV0900_DEMOD_2:
2196 coarse_freq = (stv0900_read_reg(i_params, R0900_P2_CFR2) << 8)
2197 | stv0900_read_reg(i_params, R0900_P2_CFR1);
2198
2199 symb = 13 * (coarse_srate / 10);
2200
2201 if (symb < i_params->dmd2_symbol_rate)
2202 coarse_srate = 0;
2203 else {
2204 stv0900_write_reg(i_params, R0900_P2_DMDISTATE, 0x1F);
2205 stv0900_write_reg(i_params, R0900_P2_TMGCFG2, 0x01);
2206 stv0900_write_reg(i_params, R0900_P2_TMGTHRISE, 0x20);
2207 stv0900_write_reg(i_params, R0900_P2_TMGTHFALL, 0x00);
2208 stv0900_write_reg(i_params, R0900_P2_TMGCFG, 0xd2);
2209 stv0900_write_bits(i_params, F0900_P2_CFR_AUTOSCAN, 0);
2210
2211 if (i_params->chip_id >= 0x20)
2212 stv0900_write_reg(i_params, R0900_P2_CARFREQ, 0x49);
2213 else
2214 stv0900_write_reg(i_params, R0900_P2_CARFREQ, 0xed);
2215
2216 if (coarse_srate > 3000000) {
2217 symb = 13 * (coarse_srate / 10);
2218 symb = (symb / 1000) * 65536;
2219 symb /= (i_params->mclk / 1000);
2220 stv0900_write_reg(i_params, R0900_P2_SFRUP1, (symb >> 8) & 0x7F);
2221 stv0900_write_reg(i_params, R0900_P2_SFRUP0, (symb & 0xFF));
2222
2223 symb = 10 * (coarse_srate / 13);
2224 symb = (symb / 1000) * 65536;
2225 symb /= (i_params->mclk / 1000);
2226
2227 stv0900_write_reg(i_params, R0900_P2_SFRLOW1, (symb >> 8) & 0x7F);
2228 stv0900_write_reg(i_params, R0900_P2_SFRLOW0, (symb & 0xFF));
2229
2230 symb = (coarse_srate / 1000) * 65536;
2231 symb /= (i_params->mclk / 1000);
2232 stv0900_write_reg(i_params, R0900_P2_SFRINIT1, (symb >> 8) & 0xFF);
2233 stv0900_write_reg(i_params, R0900_P2_SFRINIT0, (symb & 0xFF));
2234 } else {
2235 symb = 13 * (coarse_srate / 10);
2236 symb = (symb / 100) * 65536;
2237 symb /= (i_params->mclk / 100);
2238 stv0900_write_reg(i_params, R0900_P2_SFRUP1, (symb >> 8) & 0x7F);
2239 stv0900_write_reg(i_params, R0900_P2_SFRUP0, (symb & 0xFF));
2240
2241 symb = 10 * (coarse_srate / 14);
2242 symb = (symb / 100) * 65536;
2243 symb /= (i_params->mclk / 100);
2244 stv0900_write_reg(i_params, R0900_P2_SFRLOW1, (symb >> 8) & 0x7F);
2245 stv0900_write_reg(i_params, R0900_P2_SFRLOW0, (symb & 0xFF));
2246
2247 symb = (coarse_srate / 100) * 65536;
2248 symb /= (i_params->mclk / 100);
2249 stv0900_write_reg(i_params, R0900_P2_SFRINIT1, (symb >> 8) & 0xFF);
2250 stv0900_write_reg(i_params, R0900_P2_SFRINIT0, (symb & 0xFF));
2251 }
2252
2253 stv0900_write_reg(i_params, R0900_P2_DMDT0M, 0x20);
2254 stv0900_write_reg(i_params, R0900_P2_CFRINIT1, (coarse_freq >> 8) & 0xff);
2255 stv0900_write_reg(i_params, R0900_P2_CFRINIT0, coarse_freq & 0xff);
2256 stv0900_write_reg(i_params, R0900_P2_DMDISTATE, 0x15);
2257 }
2258
2259 break;
2260 }
2261
2262 return coarse_srate;
2263}
2264
2265static int stv0900_blind_search_algo(struct dvb_frontend *fe)
2266{
2267 struct stv0900_state *state = fe->demodulator_priv;
2268 struct stv0900_internal *i_params = state->internal;
2269 enum fe_stv0900_demod_num demod = state->demod;
2270 u8 k_ref_tmg, k_ref_tmg_max, k_ref_tmg_min;
2271 u32 coarse_srate;
2272 int lock = FALSE, coarse_fail = FALSE;
2273 s32 demod_timeout = 500, fec_timeout = 50, kref_tmg_reg, fail_cpt, i, agc2_overflow;
2274 u16 agc2_integr;
2275 u8 dstatus2;
2276
2277 dprintk(KERN_INFO "%s\n", __func__);
2278
2279 if (i_params->chip_id < 0x20) {
2280 k_ref_tmg_max = 233;
2281 k_ref_tmg_min = 143;
2282 } else {
2283 k_ref_tmg_max = 120;
2284 k_ref_tmg_min = 30;
2285 }
2286
2287 agc2_integr = stv0900_blind_check_agc2_min_level(i_params, demod);
2288
2289 if (agc2_integr > STV0900_BLIND_SEARCH_AGC2_TH) {
2290 lock = FALSE;
2291
2292 } else {
2293 switch (demod) {
2294 case STV0900_DEMOD_1:
2295 default:
2296 if (i_params->chip_id == 0x10)
2297 stv0900_write_reg(i_params, R0900_P1_CORRELEXP, 0xAA);
2298
2299 if (i_params->chip_id < 0x20)
2300 stv0900_write_reg(i_params, R0900_P1_CARHDR, 0x55);
2301
2302 stv0900_write_reg(i_params, R0900_P1_CARCFG, 0xC4);
2303 stv0900_write_reg(i_params, R0900_P1_RTCS2, 0x44);
2304
2305 if (i_params->chip_id >= 0x20) {
2306 stv0900_write_reg(i_params, R0900_P1_EQUALCFG, 0x41);
2307 stv0900_write_reg(i_params, R0900_P1_FFECFG, 0x41);
2308 stv0900_write_reg(i_params, R0900_P1_VITSCALE, 0x82);
2309 stv0900_write_reg(i_params, R0900_P1_VAVSRVIT, 0x0);
2310 }
2311
2312 kref_tmg_reg = R0900_P1_KREFTMG;
2313 break;
2314 case STV0900_DEMOD_2:
2315 if (i_params->chip_id == 0x10)
2316 stv0900_write_reg(i_params, R0900_P2_CORRELEXP, 0xAA);
2317
2318 if (i_params->chip_id < 0x20)
2319 stv0900_write_reg(i_params, R0900_P2_CARHDR, 0x55);
2320
2321 stv0900_write_reg(i_params, R0900_P2_CARCFG, 0xC4);
2322 stv0900_write_reg(i_params, R0900_P2_RTCS2, 0x44);
2323
2324 if (i_params->chip_id >= 0x20) {
2325 stv0900_write_reg(i_params, R0900_P2_EQUALCFG, 0x41);
2326 stv0900_write_reg(i_params, R0900_P2_FFECFG, 0x41);
2327 stv0900_write_reg(i_params, R0900_P2_VITSCALE, 0x82);
2328 stv0900_write_reg(i_params, R0900_P2_VAVSRVIT, 0x0);
2329 }
2330
2331 kref_tmg_reg = R0900_P2_KREFTMG;
2332 break;
2333 }
2334
2335 k_ref_tmg = k_ref_tmg_max;
2336
2337 do {
2338 stv0900_write_reg(i_params, kref_tmg_reg, k_ref_tmg);
2339 if (stv0900_search_srate_coarse(fe) != 0) {
2340 coarse_srate = stv0900_search_srate_fine(fe);
2341
2342 if (coarse_srate != 0) {
2343 stv0900_get_lock_timeout(&demod_timeout, &fec_timeout, coarse_srate, STV0900_BLIND_SEARCH);
2344 lock = stv0900_get_demod_lock(i_params, demod, demod_timeout);
2345 } else
2346 lock = FALSE;
2347 } else {
2348 fail_cpt = 0;
2349 agc2_overflow = 0;
2350
2351 switch (demod) {
2352 case STV0900_DEMOD_1:
2353 default:
2354 for (i = 0; i < 10; i++) {
2355 agc2_integr = (stv0900_read_reg(i_params, R0900_P1_AGC2I1) << 8)
2356 | stv0900_read_reg(i_params, R0900_P1_AGC2I0);
2357
2358 if (agc2_integr >= 0xff00)
2359 agc2_overflow++;
2360
2361 dstatus2 = stv0900_read_reg(i_params, R0900_P1_DSTATUS2);
2362
2363 if (((dstatus2 & 0x1) == 0x1) && ((dstatus2 >> 7) == 1))
2364 fail_cpt++;
2365 }
2366 break;
2367 case STV0900_DEMOD_2:
2368 for (i = 0; i < 10; i++) {
2369 agc2_integr = (stv0900_read_reg(i_params, R0900_P2_AGC2I1) << 8)
2370 | stv0900_read_reg(i_params, R0900_P2_AGC2I0);
2371
2372 if (agc2_integr >= 0xff00)
2373 agc2_overflow++;
2374
2375 dstatus2 = stv0900_read_reg(i_params, R0900_P2_DSTATUS2);
2376
2377 if (((dstatus2 & 0x1) == 0x1) && ((dstatus2 >> 7) == 1))
2378 fail_cpt++;
2379 }
2380 break;
2381 }
2382
2383 if ((fail_cpt > 7) || (agc2_overflow > 7))
2384 coarse_fail = TRUE;
2385
2386 lock = FALSE;
2387 }
2388 k_ref_tmg -= 30;
2389 } while ((k_ref_tmg >= k_ref_tmg_min) && (lock == FALSE) && (coarse_fail == FALSE));
2390 }
2391
2392 return lock;
2393}
2394
2395static void stv0900_set_viterbi_acq(struct stv0900_internal *i_params,
2396 enum fe_stv0900_demod_num demod)
2397{
2398 s32 vth_reg;
2399
2400 dprintk(KERN_INFO "%s\n", __func__);
2401
2402 dmd_reg(vth_reg, R0900_P1_VTH12, R0900_P2_VTH12);
2403
2404 stv0900_write_reg(i_params, vth_reg++, 0x96);
2405 stv0900_write_reg(i_params, vth_reg++, 0x64);
2406 stv0900_write_reg(i_params, vth_reg++, 0x36);
2407 stv0900_write_reg(i_params, vth_reg++, 0x23);
2408 stv0900_write_reg(i_params, vth_reg++, 0x1E);
2409 stv0900_write_reg(i_params, vth_reg++, 0x19);
2410}
2411
2412static void stv0900_set_search_standard(struct stv0900_internal *i_params,
2413 enum fe_stv0900_demod_num demod)
2414{
2415
2416 int sstndrd;
2417
2418 dprintk(KERN_INFO "%s\n", __func__);
2419
2420 sstndrd = i_params->dmd1_srch_standard;
2421 if (demod == 1)
2422 sstndrd = i_params->dmd2_srch_stndrd;
2423
2424 switch (sstndrd) {
2425 case STV0900_SEARCH_DVBS1:
2426 dprintk("Search Standard = DVBS1\n");
2427 break;
2428 case STV0900_SEARCH_DSS:
2429 dprintk("Search Standard = DSS\n");
2430 case STV0900_SEARCH_DVBS2:
2431 break;
2432 dprintk("Search Standard = DVBS2\n");
2433 case STV0900_AUTO_SEARCH:
2434 default:
2435 dprintk("Search Standard = AUTO\n");
2436 break;
2437 }
2438
2439 switch (demod) {
2440 case STV0900_DEMOD_1:
2441 default:
2442 switch (i_params->dmd1_srch_standard) {
2443 case STV0900_SEARCH_DVBS1:
2444 case STV0900_SEARCH_DSS:
2445 stv0900_write_bits(i_params, F0900_P1_DVBS1_ENABLE, 1);
2446 stv0900_write_bits(i_params, F0900_P1_DVBS2_ENABLE, 0);
2447
2448 stv0900_write_bits(i_params, F0900_STOP_CLKVIT1, 0);
2449 stv0900_write_reg(i_params, R0900_P1_ACLC, 0x1a);
2450 stv0900_write_reg(i_params, R0900_P1_BCLC, 0x09);
2451 stv0900_write_reg(i_params, R0900_P1_CAR2CFG, 0x22);
2452
2453 stv0900_set_viterbi_acq(i_params, demod);
2454 stv0900_set_viterbi_standard(i_params,
2455 i_params->dmd1_srch_standard,
2456 i_params->dmd1_fec, demod);
2457
2458 break;
2459 case STV0900_SEARCH_DVBS2:
2460 stv0900_write_bits(i_params, F0900_P1_DVBS1_ENABLE, 0);
2461 stv0900_write_bits(i_params, F0900_P1_DVBS2_ENABLE, 0);
2462 stv0900_write_bits(i_params, F0900_P1_DVBS1_ENABLE, 1);
2463 stv0900_write_bits(i_params, F0900_P1_DVBS2_ENABLE, 1);
2464 stv0900_write_bits(i_params, F0900_STOP_CLKVIT1, 1);
2465 stv0900_write_reg(i_params, R0900_P1_ACLC, 0x1a);
2466 stv0900_write_reg(i_params, R0900_P1_BCLC, 0x09);
2467 stv0900_write_reg(i_params, R0900_P1_CAR2CFG, 0x26);
2468 if (i_params->demod_mode != STV0900_SINGLE) {
2469 if (i_params->chip_id <= 0x11)
2470 stv0900_stop_all_s2_modcod(i_params, demod);
2471 else
2472 stv0900_activate_s2_modcode(i_params, demod);
2473
2474 } else
2475 stv0900_activate_s2_modcode_single(i_params, demod);
2476
2477 stv0900_set_viterbi_tracq(i_params, demod);
2478
2479 break;
2480 case STV0900_AUTO_SEARCH:
2481 default:
2482 stv0900_write_bits(i_params, F0900_P1_DVBS1_ENABLE, 0);
2483 stv0900_write_bits(i_params, F0900_P1_DVBS2_ENABLE, 0);
2484 stv0900_write_bits(i_params, F0900_P1_DVBS1_ENABLE, 1);
2485 stv0900_write_bits(i_params, F0900_P1_DVBS2_ENABLE, 1);
2486 stv0900_write_bits(i_params, F0900_STOP_CLKVIT1, 0);
2487 stv0900_write_reg(i_params, R0900_P1_ACLC, 0x1a);
2488 stv0900_write_reg(i_params, R0900_P1_BCLC, 0x09);
2489 stv0900_write_reg(i_params, R0900_P1_CAR2CFG, 0x26);
2490 if (i_params->demod_mode != STV0900_SINGLE) {
2491 if (i_params->chip_id <= 0x11)
2492 stv0900_stop_all_s2_modcod(i_params, demod);
2493 else
2494 stv0900_activate_s2_modcode(i_params, demod);
2495
2496 } else
2497 stv0900_activate_s2_modcode_single(i_params, demod);
2498
2499 if (i_params->dmd1_symbol_rate >= 2000000)
2500 stv0900_set_viterbi_acq(i_params, demod);
2501 else
2502 stv0900_set_viterbi_tracq(i_params, demod);
2503
2504 stv0900_set_viterbi_standard(i_params, i_params->dmd1_srch_standard, i_params->dmd1_fec, demod);
2505
2506 break;
2507 }
2508 break;
2509 case STV0900_DEMOD_2:
2510 switch (i_params->dmd2_srch_stndrd) {
2511 case STV0900_SEARCH_DVBS1:
2512 case STV0900_SEARCH_DSS:
2513 stv0900_write_bits(i_params, F0900_P2_DVBS1_ENABLE, 1);
2514 stv0900_write_bits(i_params, F0900_P2_DVBS2_ENABLE, 0);
2515 stv0900_write_bits(i_params, F0900_STOP_CLKVIT2, 0);
2516 stv0900_write_reg(i_params, R0900_P2_ACLC, 0x1a);
2517 stv0900_write_reg(i_params, R0900_P2_BCLC, 0x09);
2518 stv0900_write_reg(i_params, R0900_P2_CAR2CFG, 0x22);
2519 stv0900_set_viterbi_acq(i_params, demod);
2520 stv0900_set_viterbi_standard(i_params, i_params->dmd2_srch_stndrd, i_params->dmd2_fec, demod);
2521 break;
2522 case STV0900_SEARCH_DVBS2:
2523 stv0900_write_bits(i_params, F0900_P2_DVBS1_ENABLE, 0);
2524 stv0900_write_bits(i_params, F0900_P2_DVBS2_ENABLE, 0);
2525 stv0900_write_bits(i_params, F0900_P2_DVBS1_ENABLE, 1);
2526 stv0900_write_bits(i_params, F0900_P2_DVBS2_ENABLE, 1);
2527 stv0900_write_bits(i_params, F0900_STOP_CLKVIT2, 1);
2528 stv0900_write_reg(i_params, R0900_P2_ACLC, 0x1a);
2529 stv0900_write_reg(i_params, R0900_P2_BCLC, 0x09);
2530 stv0900_write_reg(i_params, R0900_P2_CAR2CFG, 0x26);
2531 if (i_params->demod_mode != STV0900_SINGLE)
2532 stv0900_activate_s2_modcode(i_params, demod);
2533 else
2534 stv0900_activate_s2_modcode_single(i_params, demod);
2535
2536 stv0900_set_viterbi_tracq(i_params, demod);
2537 break;
2538 case STV0900_AUTO_SEARCH:
2539 default:
2540 stv0900_write_bits(i_params, F0900_P2_DVBS1_ENABLE, 0);
2541 stv0900_write_bits(i_params, F0900_P2_DVBS2_ENABLE, 0);
2542 stv0900_write_bits(i_params, F0900_P2_DVBS1_ENABLE, 1);
2543 stv0900_write_bits(i_params, F0900_P2_DVBS2_ENABLE, 1);
2544 stv0900_write_bits(i_params, F0900_STOP_CLKVIT2, 0);
2545 stv0900_write_reg(i_params, R0900_P2_ACLC, 0x1a);
2546 stv0900_write_reg(i_params, R0900_P2_BCLC, 0x09);
2547 stv0900_write_reg(i_params, R0900_P2_CAR2CFG, 0x26);
2548 if (i_params->demod_mode != STV0900_SINGLE)
2549 stv0900_activate_s2_modcode(i_params, demod);
2550 else
2551 stv0900_activate_s2_modcode_single(i_params, demod);
2552
2553 if (i_params->dmd2_symbol_rate >= 2000000)
2554 stv0900_set_viterbi_acq(i_params, demod);
2555 else
2556 stv0900_set_viterbi_tracq(i_params, demod);
2557
2558 stv0900_set_viterbi_standard(i_params, i_params->dmd2_srch_stndrd, i_params->dmd2_fec, demod);
2559
2560 break;
2561 }
2562
2563 break;
2564 }
2565}
2566
2567enum fe_stv0900_signal_type stv0900_algo(struct dvb_frontend *fe)
2568{
2569 struct stv0900_state *state = fe->demodulator_priv;
2570 struct stv0900_internal *i_params = state->internal;
2571 enum fe_stv0900_demod_num demod = state->demod;
2572
2573 s32 demod_timeout = 500, fec_timeout = 50, stream_merger_field;
2574
2575 int lock = FALSE, low_sr = FALSE;
2576
2577 enum fe_stv0900_signal_type signal_type = STV0900_NOCARRIER;
2578 enum fe_stv0900_search_algo algo;
2579 int no_signal = FALSE;
2580
2581 dprintk(KERN_INFO "%s\n", __func__);
2582
2583 switch (demod) {
2584 case STV0900_DEMOD_1:
2585 default:
2586 algo = i_params->dmd1_srch_algo;
2587
2588 stv0900_write_bits(i_params, F0900_P1_RST_HWARE, 1);
2589 stream_merger_field = F0900_P1_RST_HWARE;
2590
2591 stv0900_write_reg(i_params, R0900_P1_DMDISTATE, 0x5C);
2592
2593 if (i_params->chip_id >= 0x20)
2594 stv0900_write_reg(i_params, R0900_P1_CORRELABS, 0x9e);
2595 else
2596 stv0900_write_reg(i_params, R0900_P1_CORRELABS, 0x88);
2597
2598 stv0900_get_lock_timeout(&demod_timeout, &fec_timeout, i_params->dmd1_symbol_rate, i_params->dmd1_srch_algo);
2599
2600 if (i_params->dmd1_srch_algo == STV0900_BLIND_SEARCH) {
2601 i_params->tuner1_bw = 2 * 36000000;
2602
2603 stv0900_write_reg(i_params, R0900_P1_TMGCFG2, 0x00);
2604 stv0900_write_reg(i_params, R0900_P1_CORRELMANT, 0x70);
2605
2606 stv0900_set_symbol_rate(i_params, i_params->mclk, 1000000, demod);
2607 } else {
2608 stv0900_write_reg(i_params, R0900_P1_DMDT0M, 0x20);
2609 stv0900_write_reg(i_params, R0900_P1_TMGCFG, 0xd2);
2610
2611 if (i_params->dmd1_symbol_rate < 2000000)
2612 stv0900_write_reg(i_params, R0900_P1_CORRELMANT, 0x63);
2613 else
2614 stv0900_write_reg(i_params, R0900_P1_CORRELMANT, 0x70);
2615
2616 stv0900_write_reg(i_params, R0900_P1_AGC2REF, 0x38);
2617 if (i_params->chip_id >= 0x20) {
2618 stv0900_write_reg(i_params, R0900_P1_KREFTMG, 0x5a);
2619
2620 if (i_params->dmd1_srch_algo == STV0900_COLD_START)
2621 i_params->tuner1_bw = (15 * (stv0900_carrier_width(i_params->dmd1_symbol_rate, i_params->rolloff) + 10000000)) / 10;
2622 else if (i_params->dmd1_srch_algo == STV0900_WARM_START)
2623 i_params->tuner1_bw = stv0900_carrier_width(i_params->dmd1_symbol_rate, i_params->rolloff) + 10000000;
2624 } else {
2625 stv0900_write_reg(i_params, R0900_P1_KREFTMG, 0xc1);
2626 i_params->tuner1_bw = (15 * (stv0900_carrier_width(i_params->dmd1_symbol_rate, i_params->rolloff) + 10000000)) / 10;
2627 }
2628
2629 stv0900_write_reg(i_params, R0900_P1_TMGCFG2, 0x01);
2630
2631 stv0900_set_symbol_rate(i_params, i_params->mclk, i_params->dmd1_symbol_rate, demod);
2632 stv0900_set_max_symbol_rate(i_params, i_params->mclk, i_params->dmd1_symbol_rate, demod);
2633 stv0900_set_min_symbol_rate(i_params, i_params->mclk, i_params->dmd1_symbol_rate, demod);
2634 if (i_params->dmd1_symbol_rate >= 10000000)
2635 low_sr = FALSE;
2636 else
2637 low_sr = TRUE;
2638
2639 }
2640
2641 stv0900_set_tuner(fe, i_params->tuner1_freq, i_params->tuner1_bw);
2642
2643 stv0900_write_bits(i_params, F0900_P1_SPECINV_CONTROL, i_params->dmd1_srch_iq_inv);
2644 stv0900_write_bits(i_params, F0900_P1_MANUAL_ROLLOFF, 1);
2645
2646 stv0900_set_search_standard(i_params, demod);
2647
2648 if (i_params->dmd1_srch_algo != STV0900_BLIND_SEARCH)
2649 stv0900_start_search(i_params, demod);
2650 break;
2651 case STV0900_DEMOD_2:
2652 algo = i_params->dmd2_srch_algo;
2653
2654 stv0900_write_bits(i_params, F0900_P2_RST_HWARE, 1);
2655
2656 stream_merger_field = F0900_P2_RST_HWARE;
2657
2658 stv0900_write_reg(i_params, R0900_P2_DMDISTATE, 0x5C);
2659
2660 if (i_params->chip_id >= 0x20)
2661 stv0900_write_reg(i_params, R0900_P2_CORRELABS, 0x9e);
2662 else
2663 stv0900_write_reg(i_params, R0900_P2_CORRELABS, 0x88);
2664
2665 stv0900_get_lock_timeout(&demod_timeout, &fec_timeout, i_params->dmd2_symbol_rate, i_params->dmd2_srch_algo);
2666
2667 if (i_params->dmd2_srch_algo == STV0900_BLIND_SEARCH) {
2668 i_params->tuner2_bw = 2 * 36000000;
2669
2670 stv0900_write_reg(i_params, R0900_P2_TMGCFG2, 0x00);
2671 stv0900_write_reg(i_params, R0900_P2_CORRELMANT, 0x70);
2672
2673 stv0900_set_symbol_rate(i_params, i_params->mclk, 1000000, demod);
2674 } else {
2675 stv0900_write_reg(i_params, R0900_P2_DMDT0M, 0x20);
2676 stv0900_write_reg(i_params, R0900_P2_TMGCFG, 0xd2);
2677
2678 if (i_params->dmd2_symbol_rate < 2000000)
2679 stv0900_write_reg(i_params, R0900_P2_CORRELMANT, 0x63);
2680 else
2681 stv0900_write_reg(i_params, R0900_P2_CORRELMANT, 0x70);
2682
2683 if (i_params->dmd2_symbol_rate >= 10000000)
2684 stv0900_write_reg(i_params, R0900_P2_AGC2REF, 0x38);
2685 else
2686 stv0900_write_reg(i_params, R0900_P2_AGC2REF, 0x60);
2687
2688 if (i_params->chip_id >= 0x20) {
2689 stv0900_write_reg(i_params, R0900_P2_KREFTMG, 0x5a);
2690
2691 if (i_params->dmd2_srch_algo == STV0900_COLD_START)
2692 i_params->tuner2_bw = (15 * (stv0900_carrier_width(i_params->dmd2_symbol_rate,
2693 i_params->rolloff) + 10000000)) / 10;
2694 else if (i_params->dmd2_srch_algo == STV0900_WARM_START)
2695 i_params->tuner2_bw = stv0900_carrier_width(i_params->dmd2_symbol_rate,
2696 i_params->rolloff) + 10000000;
2697 } else {
2698 stv0900_write_reg(i_params, R0900_P2_KREFTMG, 0xc1);
2699 i_params->tuner2_bw = (15 * (stv0900_carrier_width(i_params->dmd2_symbol_rate,
2700 i_params->rolloff) + 10000000)) / 10;
2701 }
2702
2703 stv0900_write_reg(i_params, R0900_P2_TMGCFG2, 0x01);
2704
2705 stv0900_set_symbol_rate(i_params, i_params->mclk, i_params->dmd2_symbol_rate, demod);
2706 stv0900_set_max_symbol_rate(i_params, i_params->mclk, i_params->dmd2_symbol_rate, demod);
2707 stv0900_set_min_symbol_rate(i_params, i_params->mclk, i_params->dmd2_symbol_rate, demod);
2708 if (i_params->dmd2_symbol_rate >= 10000000)
2709 low_sr = FALSE;
2710 else
2711 low_sr = TRUE;
2712
2713 }
2714
2715 stv0900_set_tuner(fe, i_params->tuner2_freq, i_params->tuner2_bw);
2716
2717 stv0900_write_bits(i_params, F0900_P2_SPECINV_CONTROL, i_params->dmd2_srch_iq_inv);
2718 stv0900_write_bits(i_params, F0900_P2_MANUAL_ROLLOFF, 1);
2719
2720 stv0900_set_search_standard(i_params, demod);
2721
2722 if (i_params->dmd2_srch_algo != STV0900_BLIND_SEARCH)
2723 stv0900_start_search(i_params, demod);
2724 break;
2725 }
2726
2727 if (i_params->chip_id == 0x12) {
2728 stv0900_write_bits(i_params, stream_merger_field, 0);
2729 msleep(3);
2730 stv0900_write_bits(i_params, stream_merger_field, 1);
2731 stv0900_write_bits(i_params, stream_merger_field, 0);
2732 }
2733
2734 if (algo == STV0900_BLIND_SEARCH)
2735 lock = stv0900_blind_search_algo(fe);
2736 else if (algo == STV0900_COLD_START)
2737 lock = stv0900_get_demod_cold_lock(fe, demod_timeout);
2738 else if (algo == STV0900_WARM_START)
2739 lock = stv0900_get_demod_lock(i_params, demod, demod_timeout);
2740
2741 if ((lock == FALSE) && (algo == STV0900_COLD_START)) {
2742 if (low_sr == FALSE) {
2743 if (stv0900_check_timing_lock(i_params, demod) == TRUE)
2744 lock = stv0900_sw_algo(i_params, demod);
2745 }
2746 }
2747
2748 if (lock == TRUE)
2749 signal_type = stv0900_get_signal_params(fe);
2750
2751 if ((lock == TRUE) && (signal_type == STV0900_RANGEOK)) {
2752 stv0900_track_optimization(fe);
2753 if (i_params->chip_id <= 0x11) {
2754 if ((stv0900_get_standard(fe, STV0900_DEMOD_1) == STV0900_DVBS1_STANDARD) && (stv0900_get_standard(fe, STV0900_DEMOD_2) == STV0900_DVBS1_STANDARD)) {
2755 msleep(20);
2756 stv0900_write_bits(i_params, stream_merger_field, 0);
2757 } else {
2758 stv0900_write_bits(i_params, stream_merger_field, 0);
2759 msleep(3);
2760 stv0900_write_bits(i_params, stream_merger_field, 1);
2761 stv0900_write_bits(i_params, stream_merger_field, 0);
2762 }
2763 } else if (i_params->chip_id == 0x20) {
2764 stv0900_write_bits(i_params, stream_merger_field, 0);
2765 msleep(3);
2766 stv0900_write_bits(i_params, stream_merger_field, 1);
2767 stv0900_write_bits(i_params, stream_merger_field, 0);
2768 }
2769
2770 if (stv0900_wait_for_lock(i_params, demod, fec_timeout, fec_timeout) == TRUE) {
2771 lock = TRUE;
2772 switch (demod) {
2773 case STV0900_DEMOD_1:
2774 default:
2775 i_params->dmd1_rslts.locked = TRUE;
2776 if (i_params->dmd1_rslts.standard == STV0900_DVBS2_STANDARD) {
2777 stv0900_set_dvbs2_rolloff(i_params, demod);
2778 stv0900_write_reg(i_params, R0900_P1_PDELCTRL2, 0x40);
2779 stv0900_write_reg(i_params, R0900_P1_PDELCTRL2, 0);
2780 stv0900_write_reg(i_params, R0900_P1_ERRCTRL1, 0x67);
2781 } else {
2782 stv0900_write_reg(i_params, R0900_P1_ERRCTRL1, 0x75);
2783 }
2784
2785 stv0900_write_reg(i_params, R0900_P1_FBERCPT4, 0);
2786 stv0900_write_reg(i_params, R0900_P1_ERRCTRL2, 0xc1);
2787 break;
2788 case STV0900_DEMOD_2:
2789 i_params->dmd2_rslts.locked = TRUE;
2790
2791 if (i_params->dmd2_rslts.standard == STV0900_DVBS2_STANDARD) {
2792 stv0900_set_dvbs2_rolloff(i_params, demod);
2793 stv0900_write_reg(i_params, R0900_P2_PDELCTRL2, 0x60);
2794 stv0900_write_reg(i_params, R0900_P2_PDELCTRL2, 0x20);
2795 stv0900_write_reg(i_params, R0900_P2_ERRCTRL1, 0x67);
2796 } else {
2797 stv0900_write_reg(i_params, R0900_P2_ERRCTRL1, 0x75);
2798 }
2799
2800 stv0900_write_reg(i_params, R0900_P2_FBERCPT4, 0);
2801
2802 stv0900_write_reg(i_params, R0900_P2_ERRCTRL2, 0xc1);
2803 break;
2804 }
2805 } else {
2806 lock = FALSE;
2807 signal_type = STV0900_NODATA;
2808 no_signal = stv0900_check_signal_presence(i_params, demod);
2809
2810 switch (demod) {
2811 case STV0900_DEMOD_1:
2812 default:
2813 i_params->dmd1_rslts.locked = FALSE;
2814 break;
2815 case STV0900_DEMOD_2:
2816 i_params->dmd2_rslts.locked = FALSE;
2817 break;
2818 }
2819 }
2820 }
2821
2822 if ((signal_type == STV0900_NODATA) && (no_signal == FALSE)) {
2823 switch (demod) {
2824 case STV0900_DEMOD_1:
2825 default:
2826 if (i_params->chip_id <= 0x11) {
2827 if ((stv0900_get_bits(i_params, F0900_P1_HEADER_MODE) == STV0900_DVBS_FOUND) &&
2828 (i_params->dmd1_srch_iq_inv <= STV0900_IQ_AUTO_NORMAL_FIRST))
2829 signal_type = stv0900_dvbs1_acq_workaround(fe);
2830 } else
2831 i_params->dmd1_rslts.locked = FALSE;
2832
2833 break;
2834 case STV0900_DEMOD_2:
2835 if (i_params->chip_id <= 0x11) {
2836 if ((stv0900_get_bits(i_params, F0900_P2_HEADER_MODE) == STV0900_DVBS_FOUND) &&
2837 (i_params->dmd2_srch_iq_inv <= STV0900_IQ_AUTO_NORMAL_FIRST))
2838 signal_type = stv0900_dvbs1_acq_workaround(fe);
2839 } else
2840 i_params->dmd2_rslts.locked = FALSE;
2841 break;
2842 }
2843 }
2844
2845 return signal_type;
2846}
2847
diff --git a/drivers/media/dvb/frontends/stv6110.c b/drivers/media/dvb/frontends/stv6110.c
new file mode 100644
index 000000000000..70efac869d28
--- /dev/null
+++ b/drivers/media/dvb/frontends/stv6110.c
@@ -0,0 +1,456 @@
1/*
2 * stv6110.c
3 *
4 * Driver for ST STV6110 satellite tuner IC.
5 *
6 * Copyright (C) 2009 NetUP Inc.
7 * Copyright (C) 2009 Igor M. Liplianin <liplianin@netup.ru>
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 *
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/module.h>
26#include <linux/dvb/frontend.h>
27
28#include <linux/types.h>
29
30#include "stv6110.h"
31
32static int debug;
33
34struct stv6110_priv {
35 int i2c_address;
36 struct i2c_adapter *i2c;
37
38 u32 mclk;
39 u8 regs[8];
40};
41
42#define dprintk(args...) \
43 do { \
44 if (debug) \
45 printk(KERN_DEBUG args); \
46 } while (0)
47
48static s32 abssub(s32 a, s32 b)
49{
50 if (a > b)
51 return a - b;
52 else
53 return b - a;
54};
55
56static int stv6110_release(struct dvb_frontend *fe)
57{
58 kfree(fe->tuner_priv);
59 fe->tuner_priv = NULL;
60 return 0;
61}
62
63static int stv6110_write_regs(struct dvb_frontend *fe, u8 buf[],
64 int start, int len)
65{
66 struct stv6110_priv *priv = fe->tuner_priv;
67 int rc;
68 u8 cmdbuf[len + 1];
69 struct i2c_msg msg = {
70 .addr = priv->i2c_address,
71 .flags = 0,
72 .buf = cmdbuf,
73 .len = len + 1
74 };
75
76 dprintk("%s\n", __func__);
77
78 if (start + len > 8)
79 return -EINVAL;
80
81 memcpy(&cmdbuf[1], buf, len);
82 cmdbuf[0] = start;
83
84 if (fe->ops.i2c_gate_ctrl)
85 fe->ops.i2c_gate_ctrl(fe, 1);
86
87 rc = i2c_transfer(priv->i2c, &msg, 1);
88 if (rc != 1)
89 dprintk("%s: i2c error\n", __func__);
90
91 if (fe->ops.i2c_gate_ctrl)
92 fe->ops.i2c_gate_ctrl(fe, 0);
93
94 return 0;
95}
96
97static int stv6110_read_regs(struct dvb_frontend *fe, u8 regs[],
98 int start, int len)
99{
100 struct stv6110_priv *priv = fe->tuner_priv;
101 int rc;
102 u8 reg[] = { start };
103 struct i2c_msg msg_wr = {
104 .addr = priv->i2c_address,
105 .flags = 0,
106 .buf = reg,
107 .len = 1,
108 };
109
110 struct i2c_msg msg_rd = {
111 .addr = priv->i2c_address,
112 .flags = I2C_M_RD,
113 .buf = regs,
114 .len = len,
115 };
116 /* write subaddr */
117 if (fe->ops.i2c_gate_ctrl)
118 fe->ops.i2c_gate_ctrl(fe, 1);
119
120 rc = i2c_transfer(priv->i2c, &msg_wr, 1);
121 if (rc != 1)
122 dprintk("%s: i2c error\n", __func__);
123
124 if (fe->ops.i2c_gate_ctrl)
125 fe->ops.i2c_gate_ctrl(fe, 0);
126 /* read registers */
127 if (fe->ops.i2c_gate_ctrl)
128 fe->ops.i2c_gate_ctrl(fe, 1);
129
130 rc = i2c_transfer(priv->i2c, &msg_rd, 1);
131 if (rc != 1)
132 dprintk("%s: i2c error\n", __func__);
133
134 if (fe->ops.i2c_gate_ctrl)
135 fe->ops.i2c_gate_ctrl(fe, 0);
136
137 memcpy(&priv->regs[start], regs, len);
138
139 return 0;
140}
141
142static int stv6110_read_reg(struct dvb_frontend *fe, int start)
143{
144 u8 buf[] = { 0 };
145 stv6110_read_regs(fe, buf, start, 1);
146
147 return buf[0];
148}
149
150static int stv6110_sleep(struct dvb_frontend *fe)
151{
152 u8 reg[] = { 0 };
153 stv6110_write_regs(fe, reg, 0, 1);
154
155 return 0;
156}
157
158static u32 carrier_width(u32 symbol_rate, fe_rolloff_t rolloff)
159{
160 u32 rlf;
161
162 switch (rolloff) {
163 case ROLLOFF_20:
164 rlf = 20;
165 break;
166 case ROLLOFF_25:
167 rlf = 25;
168 break;
169 default:
170 rlf = 35;
171 break;
172 }
173
174 return symbol_rate + ((symbol_rate * rlf) / 100);
175}
176
177static int stv6110_set_bandwidth(struct dvb_frontend *fe, u32 bandwidth)
178{
179 struct stv6110_priv *priv = fe->tuner_priv;
180 u8 r8, ret = 0x04;
181 int i;
182
183 if ((bandwidth / 2) > 36000000) /*BW/2 max=31+5=36 mhz for r8=31*/
184 r8 = 31;
185 else if ((bandwidth / 2) < 5000000) /* BW/2 min=5Mhz for F=0 */
186 r8 = 0;
187 else /*if 5 < BW/2 < 36*/
188 r8 = (bandwidth / 2) / 1000000 - 5;
189
190 /* ctrl3, RCCLKOFF = 0 Activate the calibration Clock */
191 /* ctrl3, CF = r8 Set the LPF value */
192 priv->regs[RSTV6110_CTRL3] &= ~((1 << 6) | 0x1f);
193 priv->regs[RSTV6110_CTRL3] |= (r8 & 0x1f);
194 stv6110_write_regs(fe, &priv->regs[RSTV6110_CTRL3], RSTV6110_CTRL3, 1);
195 /* stat1, CALRCSTRT = 1 Start LPF auto calibration*/
196 priv->regs[RSTV6110_STAT1] |= 0x02;
197 stv6110_write_regs(fe, &priv->regs[RSTV6110_STAT1], RSTV6110_STAT1, 1);
198
199 i = 0;
200 /* Wait for CALRCSTRT == 0 */
201 while ((i < 10) && (ret != 0)) {
202 ret = ((stv6110_read_reg(fe, RSTV6110_STAT1)) & 0x02);
203 mdelay(1); /* wait for LPF auto calibration */
204 i++;
205 }
206
207 /* RCCLKOFF = 1 calibration done, desactivate the calibration Clock */
208 priv->regs[RSTV6110_CTRL3] |= (1 << 6);
209 stv6110_write_regs(fe, &priv->regs[RSTV6110_CTRL3], RSTV6110_CTRL3, 1);
210 return 0;
211}
212
213static int stv6110_init(struct dvb_frontend *fe)
214{
215 struct stv6110_priv *priv = fe->tuner_priv;
216 u8 buf0[] = { 0x07, 0x11, 0xdc, 0x85, 0x17, 0x01, 0xe6, 0x1e };
217
218 memcpy(priv->regs, buf0, 8);
219 /* K = (Reference / 1000000) - 16 */
220 priv->regs[RSTV6110_CTRL1] &= ~(0x1f << 3);
221 priv->regs[RSTV6110_CTRL1] |=
222 ((((priv->mclk / 1000000) - 16) & 0x1f) << 3);
223
224 stv6110_write_regs(fe, &priv->regs[RSTV6110_CTRL1], RSTV6110_CTRL1, 8);
225 msleep(1);
226 stv6110_set_bandwidth(fe, 72000000);
227
228 return 0;
229}
230
231static int stv6110_get_frequency(struct dvb_frontend *fe, u32 *frequency)
232{
233 struct stv6110_priv *priv = fe->tuner_priv;
234 u32 nbsteps, divider, psd2, freq;
235 u8 regs[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
236
237 stv6110_read_regs(fe, regs, 0, 8);
238 /*N*/
239 divider = (priv->regs[RSTV6110_TUNING2] & 0x0f) << 8;
240 divider += priv->regs[RSTV6110_TUNING1];
241
242 /*R*/
243 nbsteps = (priv->regs[RSTV6110_TUNING2] >> 6) & 3;
244 /*p*/
245 psd2 = (priv->regs[RSTV6110_TUNING2] >> 4) & 1;
246
247 freq = divider * (priv->mclk / 1000);
248 freq /= (1 << (nbsteps + psd2));
249 freq /= 4;
250
251 *frequency = freq;
252
253 return 0;
254}
255
256static int stv6110_set_frequency(struct dvb_frontend *fe, u32 frequency)
257{
258 struct stv6110_priv *priv = fe->tuner_priv;
259 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
260 u8 ret = 0x04;
261 u32 divider, ref, p, presc, i, result_freq, vco_freq;
262 s32 p_calc, p_calc_opt = 1000, r_div, r_div_opt = 0, p_val;
263 s32 srate; u8 gain;
264
265 dprintk("%s, freq=%d kHz, mclk=%d Hz\n", __func__,
266 frequency, priv->mclk);
267
268 /* K = (Reference / 1000000) - 16 */
269 priv->regs[RSTV6110_CTRL1] &= ~(0x1f << 3);
270 priv->regs[RSTV6110_CTRL1] |=
271 ((((priv->mclk / 1000000) - 16) & 0x1f) << 3);
272
273 /* BB_GAIN = db/2 */
274 if (fe->ops.set_property && fe->ops.get_property) {
275 srate = c->symbol_rate;
276 dprintk("%s: Get Frontend parameters: srate=%d\n",
277 __func__, srate);
278 } else
279 srate = 15000000;
280
281 if (srate >= 15000000)
282 gain = 3; /* +6 dB */
283 else if (srate >= 5000000)
284 gain = 3; /* +6 dB */
285 else
286 gain = 3; /* +6 dB */
287
288 priv->regs[RSTV6110_CTRL2] &= ~0x0f;
289 priv->regs[RSTV6110_CTRL2] |= (gain & 0x0f);
290
291 if (frequency <= 1023000) {
292 p = 1;
293 presc = 0;
294 } else if (frequency <= 1300000) {
295 p = 1;
296 presc = 1;
297 } else if (frequency <= 2046000) {
298 p = 0;
299 presc = 0;
300 } else {
301 p = 0;
302 presc = 1;
303 }
304 /* DIV4SEL = p*/
305 priv->regs[RSTV6110_TUNING2] &= ~(1 << 4);
306 priv->regs[RSTV6110_TUNING2] |= (p << 4);
307
308 /* PRESC32ON = presc */
309 priv->regs[RSTV6110_TUNING2] &= ~(1 << 5);
310 priv->regs[RSTV6110_TUNING2] |= (presc << 5);
311
312 p_val = (int)(1 << (p + 1)) * 10;/* P = 2 or P = 4 */
313 for (r_div = 0; r_div <= 3; r_div++) {
314 p_calc = (priv->mclk / 100000);
315 p_calc /= (1 << (r_div + 1));
316 if ((abssub(p_calc, p_val)) < (abssub(p_calc_opt, p_val)))
317 r_div_opt = r_div;
318
319 p_calc_opt = (priv->mclk / 100000);
320 p_calc_opt /= (1 << (r_div_opt + 1));
321 }
322
323 ref = priv->mclk / ((1 << (r_div_opt + 1)) * (1 << (p + 1)));
324 divider = (((frequency * 1000) + (ref >> 1)) / ref);
325
326 /* RDIV = r_div_opt */
327 priv->regs[RSTV6110_TUNING2] &= ~(3 << 6);
328 priv->regs[RSTV6110_TUNING2] |= (((r_div_opt) & 3) << 6);
329
330 /* NDIV_MSB = MSB(divider) */
331 priv->regs[RSTV6110_TUNING2] &= ~0x0f;
332 priv->regs[RSTV6110_TUNING2] |= (((divider) >> 8) & 0x0f);
333
334 /* NDIV_LSB, LSB(divider) */
335 priv->regs[RSTV6110_TUNING1] = (divider & 0xff);
336
337 /* CALVCOSTRT = 1 VCO Auto Calibration */
338 priv->regs[RSTV6110_STAT1] |= 0x04;
339 stv6110_write_regs(fe, &priv->regs[RSTV6110_CTRL1],
340 RSTV6110_CTRL1, 8);
341
342 i = 0;
343 /* Wait for CALVCOSTRT == 0 */
344 while ((i < 10) && (ret != 0)) {
345 ret = ((stv6110_read_reg(fe, RSTV6110_STAT1)) & 0x04);
346 msleep(1); /* wait for VCO auto calibration */
347 i++;
348 }
349
350 ret = stv6110_read_reg(fe, RSTV6110_STAT1);
351 stv6110_get_frequency(fe, &result_freq);
352
353 vco_freq = divider * ((priv->mclk / 1000) / ((1 << (r_div_opt + 1))));
354 dprintk("%s, stat1=%x, lo_freq=%d kHz, vco_frec=%d kHz\n", __func__,
355 ret, result_freq, vco_freq);
356
357 return 0;
358}
359
360static int stv6110_set_params(struct dvb_frontend *fe,
361 struct dvb_frontend_parameters *params)
362{
363 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
364 u32 bandwidth = carrier_width(c->symbol_rate, c->rolloff);
365
366 stv6110_set_frequency(fe, c->frequency);
367 stv6110_set_bandwidth(fe, bandwidth);
368
369 return 0;
370}
371
372static int stv6110_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
373{
374 struct stv6110_priv *priv = fe->tuner_priv;
375 u8 r8 = 0;
376 u8 regs[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
377 stv6110_read_regs(fe, regs, 0, 8);
378
379 /* CF */
380 r8 = priv->regs[RSTV6110_CTRL3] & 0x1f;
381 *bandwidth = (r8 + 5) * 2000000;/* x2 for ZIF tuner BW/2 = F+5 Mhz */
382
383 return 0;
384}
385
386static struct dvb_tuner_ops stv6110_tuner_ops = {
387 .info = {
388 .name = "ST STV6110",
389 .frequency_min = 950000,
390 .frequency_max = 2150000,
391 .frequency_step = 1000,
392 },
393 .init = stv6110_init,
394 .release = stv6110_release,
395 .sleep = stv6110_sleep,
396 .set_params = stv6110_set_params,
397 .get_frequency = stv6110_get_frequency,
398 .set_frequency = stv6110_set_frequency,
399 .get_bandwidth = stv6110_get_bandwidth,
400 .set_bandwidth = stv6110_set_bandwidth,
401
402};
403
404struct dvb_frontend *stv6110_attach(struct dvb_frontend *fe,
405 const struct stv6110_config *config,
406 struct i2c_adapter *i2c)
407{
408 struct stv6110_priv *priv = NULL;
409 u8 reg0[] = { 0x00, 0x07, 0x11, 0xdc, 0x85, 0x17, 0x01, 0xe6, 0x1e };
410
411 struct i2c_msg msg[] = {
412 {
413 .addr = config->i2c_address,
414 .flags = 0,
415 .buf = reg0,
416 .len = 9
417 }
418 };
419 int ret;
420
421 if (fe->ops.i2c_gate_ctrl)
422 fe->ops.i2c_gate_ctrl(fe, 1);
423
424 ret = i2c_transfer(i2c, msg, 1);
425
426 if (fe->ops.i2c_gate_ctrl)
427 fe->ops.i2c_gate_ctrl(fe, 0);
428
429 if (ret != 1)
430 return NULL;
431
432 priv = kzalloc(sizeof(struct stv6110_priv), GFP_KERNEL);
433 if (priv == NULL)
434 return NULL;
435
436 priv->i2c_address = config->i2c_address;
437 priv->i2c = i2c;
438 priv->mclk = config->mclk;
439
440 memcpy(&priv->regs, &reg0[1], 8);
441
442 memcpy(&fe->ops.tuner_ops, &stv6110_tuner_ops,
443 sizeof(struct dvb_tuner_ops));
444 fe->tuner_priv = priv;
445 printk(KERN_INFO "STV6110 attached on addr=%x!\n", priv->i2c_address);
446
447 return fe;
448}
449EXPORT_SYMBOL(stv6110_attach);
450
451module_param(debug, int, 0644);
452MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
453
454MODULE_DESCRIPTION("ST STV6110 driver");
455MODULE_AUTHOR("Igor M. Liplianin");
456MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/stv6110.h b/drivers/media/dvb/frontends/stv6110.h
new file mode 100644
index 000000000000..1c0314d6aa55
--- /dev/null
+++ b/drivers/media/dvb/frontends/stv6110.h
@@ -0,0 +1,62 @@
1/*
2 * stv6110.h
3 *
4 * Driver for ST STV6110 satellite tuner IC.
5 *
6 * Copyright (C) 2009 NetUP Inc.
7 * Copyright (C) 2009 Igor M. Liplianin <liplianin@netup.ru>
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 *
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#ifndef __DVB_STV6110_H__
26#define __DVB_STV6110_H__
27
28#include <linux/i2c.h>
29#include "dvb_frontend.h"
30
31/* registers */
32#define RSTV6110_CTRL1 0
33#define RSTV6110_CTRL2 1
34#define RSTV6110_TUNING1 2
35#define RSTV6110_TUNING2 3
36#define RSTV6110_CTRL3 4
37#define RSTV6110_STAT1 5
38#define RSTV6110_STAT2 6
39#define RSTV6110_STAT3 7
40
41struct stv6110_config {
42 u8 i2c_address;
43 u32 mclk;
44 int iq_wiring;
45};
46
47#if defined(CONFIG_DVB_STV6110) || (defined(CONFIG_DVB_STV6110_MODULE) \
48 && defined(MODULE))
49extern struct dvb_frontend *stv6110_attach(struct dvb_frontend *fe,
50 const struct stv6110_config *config,
51 struct i2c_adapter *i2c);
52#else
53static inline struct dvb_frontend *stv6110_attach(struct dvb_frontend *fe,
54 const struct stv6110_config *config,
55 struct i2c_adapter *i2c)
56{
57 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
58 return NULL;
59}
60#endif
61
62#endif
diff --git a/drivers/media/dvb/frontends/tda1004x.c b/drivers/media/dvb/frontends/tda1004x.c
index 1465ff77b0cb..4981cef8b444 100644
--- a/drivers/media/dvb/frontends/tda1004x.c
+++ b/drivers/media/dvb/frontends/tda1004x.c
@@ -162,7 +162,7 @@ static int tda1004x_read_byte(struct tda1004x_state *state, int reg)
162 if (ret != 2) { 162 if (ret != 2) {
163 dprintk("%s: error reg=0x%x, ret=%i\n", __func__, reg, 163 dprintk("%s: error reg=0x%x, ret=%i\n", __func__, reg,
164 ret); 164 ret);
165 return -1; 165 return -EINVAL;
166 } 166 }
167 167
168 dprintk("%s: success reg=0x%x, data=0x%x, ret=%i\n", __func__, 168 dprintk("%s: success reg=0x%x, data=0x%x, ret=%i\n", __func__,
@@ -481,16 +481,18 @@ static void tda10046_init_plls(struct dvb_frontend* fe)
481static int tda10046_fwupload(struct dvb_frontend* fe) 481static int tda10046_fwupload(struct dvb_frontend* fe)
482{ 482{
483 struct tda1004x_state* state = fe->demodulator_priv; 483 struct tda1004x_state* state = fe->demodulator_priv;
484 int ret; 484 int ret, confc4;
485 const struct firmware *fw; 485 const struct firmware *fw;
486 486
487 /* reset + wake up chip */ 487 /* reset + wake up chip */
488 if (state->config->xtal_freq == TDA10046_XTAL_4M) { 488 if (state->config->xtal_freq == TDA10046_XTAL_4M) {
489 tda1004x_write_byteI(state, TDA1004X_CONFC4, 0); 489 confc4 = 0;
490 } else { 490 } else {
491 dprintk("%s: 16MHz Xtal, reducing I2C speed\n", __func__); 491 dprintk("%s: 16MHz Xtal, reducing I2C speed\n", __func__);
492 tda1004x_write_byteI(state, TDA1004X_CONFC4, 0x80); 492 confc4 = 0x80;
493 } 493 }
494 tda1004x_write_byteI(state, TDA1004X_CONFC4, confc4);
495
494 tda1004x_write_mask(state, TDA10046H_CONF_TRISTATE1, 1, 0); 496 tda1004x_write_mask(state, TDA10046H_CONF_TRISTATE1, 1, 0);
495 /* set GPIO 1 and 3 */ 497 /* set GPIO 1 and 3 */
496 if (state->config->gpio_config != TDA10046_GPTRI) { 498 if (state->config->gpio_config != TDA10046_GPTRI) {
@@ -508,13 +510,29 @@ static int tda10046_fwupload(struct dvb_frontend* fe)
508 if (tda1004x_check_upload_ok(state) == 0) 510 if (tda1004x_check_upload_ok(state) == 0)
509 return 0; 511 return 0;
510 512
513 /*
514 For i2c normal work, we need to slow down the bus speed.
515 However, the slow down breaks the eeprom firmware load.
516 So, use normal speed for eeprom booting and then restore the
517 i2c speed after that. Tested with MSI TV @nyware A/D board,
518 that comes with firmware version 29 inside their eeprom.
519
520 It should also be noticed that no other I2C transfer should
521 be in course while booting from eeprom, otherwise, tda10046
522 goes into an instable state. So, proper locking are needed
523 at the i2c bus master.
524 */
511 printk(KERN_INFO "tda1004x: trying to boot from eeprom\n"); 525 printk(KERN_INFO "tda1004x: trying to boot from eeprom\n");
512 tda1004x_write_mask(state, TDA1004X_CONFC4, 4, 4); 526 tda1004x_write_byteI(state, TDA1004X_CONFC4, 4);
513 msleep(300); 527 msleep(300);
514 /* don't re-upload unless necessary */ 528 tda1004x_write_byteI(state, TDA1004X_CONFC4, confc4);
529
530 /* Checks if eeprom firmware went without troubles */
515 if (tda1004x_check_upload_ok(state) == 0) 531 if (tda1004x_check_upload_ok(state) == 0)
516 return 0; 532 return 0;
517 533
534 /* eeprom firmware didn't work. Load one manually. */
535
518 if (state->config->request_firmware != NULL) { 536 if (state->config->request_firmware != NULL) {
519 /* request the firmware, this will block until someone uploads it */ 537 /* request the firmware, this will block until someone uploads it */
520 printk(KERN_INFO "tda1004x: waiting for firmware upload...\n"); 538 printk(KERN_INFO "tda1004x: waiting for firmware upload...\n");
diff --git a/drivers/media/dvb/frontends/zl10036.c b/drivers/media/dvb/frontends/zl10036.c
new file mode 100644
index 000000000000..e22a0b381dc4
--- /dev/null
+++ b/drivers/media/dvb/frontends/zl10036.c
@@ -0,0 +1,519 @@
1/**
2 * Driver for Zarlink zl10036 DVB-S silicon tuner
3 *
4 * Copyright (C) 2006 Tino Reichardt
5 * Copyright (C) 2007-2009 Matthias Schwarzott <zzam@gentoo.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 Version 2, as
9 * published by the Free Software Foundation.
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 * The data sheet for this tuner can be found at:
22 * http://www.mcmilk.de/projects/dvb-card/datasheets/ZL10036.pdf
23 *
24 * This one is working: (at my Avermedia DVB-S Pro)
25 * - zl10036 (40pin, FTA)
26 *
27 * A driver for zl10038 should be very similar.
28 */
29
30#include <linux/module.h>
31#include <linux/dvb/frontend.h>
32#include <asm/types.h>
33
34#include "zl10036.h"
35
36static int zl10036_debug;
37#define dprintk(level, args...) \
38 do { if (zl10036_debug & level) printk(KERN_DEBUG "zl10036: " args); \
39 } while (0)
40
41#define deb_info(args...) dprintk(0x01, args)
42#define deb_i2c(args...) dprintk(0x02, args)
43
44struct zl10036_state {
45 struct i2c_adapter *i2c;
46 const struct zl10036_config *config;
47 u32 frequency;
48 u8 br, bf;
49};
50
51
52/* This driver assumes the tuner is driven by a 10.111MHz Cristal */
53#define _XTAL 10111
54
55/* Some of the possible dividers:
56 * 64, (write 0x05 to reg), freq step size 158kHz
57 * 10, (write 0x0a to reg), freq step size 1.011kHz (used here)
58 * 5, (write 0x09 to reg), freq step size 2.022kHz
59 */
60
61#define _RDIV 10
62#define _RDIV_REG 0x0a
63#define _FR (_XTAL/_RDIV)
64
65#define STATUS_POR 0x80 /* Power on Reset */
66#define STATUS_FL 0x40 /* Frequency & Phase Lock */
67
68/* read/write for zl10036 and zl10038 */
69
70static int zl10036_read_status_reg(struct zl10036_state *state)
71{
72 u8 status;
73 struct i2c_msg msg[1] = {
74 { .addr = state->config->tuner_address, .flags = I2C_M_RD,
75 .buf = &status, .len = sizeof(status) },
76 };
77
78 if (i2c_transfer(state->i2c, msg, 1) != 1) {
79 printk(KERN_ERR "%s: i2c read failed at addr=%02x\n",
80 __func__, state->config->tuner_address);
81 return -EIO;
82 }
83
84 deb_i2c("R(status): %02x [FL=%d]\n", status,
85 (status & STATUS_FL) ? 1 : 0);
86 if (status & STATUS_POR)
87 deb_info("%s: Power-On-Reset bit enabled - "
88 "need to initialize the tuner\n", __func__);
89
90 return status;
91}
92
93static int zl10036_write(struct zl10036_state *state, u8 buf[], u8 count)
94{
95 struct i2c_msg msg[1] = {
96 { .addr = state->config->tuner_address, .flags = 0,
97 .buf = buf, .len = count },
98 };
99 u8 reg = 0;
100 int ret;
101
102 if (zl10036_debug & 0x02) {
103 /* every 8bit-value satisifes this!
104 * so only check for debug log */
105 if ((buf[0] & 0x80) == 0x00)
106 reg = 2;
107 else if ((buf[0] & 0xc0) == 0x80)
108 reg = 4;
109 else if ((buf[0] & 0xf0) == 0xc0)
110 reg = 6;
111 else if ((buf[0] & 0xf0) == 0xd0)
112 reg = 8;
113 else if ((buf[0] & 0xf0) == 0xe0)
114 reg = 10;
115 else if ((buf[0] & 0xf0) == 0xf0)
116 reg = 12;
117
118 deb_i2c("W(%d):", reg);
119 {
120 int i;
121 for (i = 0; i < count; i++)
122 printk(KERN_CONT " %02x", buf[i]);
123 printk(KERN_CONT "\n");
124 }
125 }
126
127 ret = i2c_transfer(state->i2c, msg, 1);
128 if (ret != 1) {
129 printk(KERN_ERR "%s: i2c error, ret=%d\n", __func__, ret);
130 return -EIO;
131 }
132
133 return 0;
134}
135
136static int zl10036_release(struct dvb_frontend *fe)
137{
138 struct zl10036_state *state = fe->tuner_priv;
139
140 fe->tuner_priv = NULL;
141 kfree(state);
142
143 return 0;
144}
145
146static int zl10036_sleep(struct dvb_frontend *fe)
147{
148 struct zl10036_state *state = fe->tuner_priv;
149 u8 buf[] = { 0xf0, 0x80 }; /* regs 12/13 */
150 int ret;
151
152 deb_info("%s\n", __func__);
153
154 if (fe->ops.i2c_gate_ctrl)
155 fe->ops.i2c_gate_ctrl(fe, 1); /* open i2c_gate */
156
157 ret = zl10036_write(state, buf, sizeof(buf));
158
159 if (fe->ops.i2c_gate_ctrl)
160 fe->ops.i2c_gate_ctrl(fe, 0); /* close i2c_gate */
161
162 return ret;
163}
164
165/**
166 * register map of the ZL10036/ZL10038
167 *
168 * reg[default] content
169 * 2[0x00]: 0 | N14 | N13 | N12 | N11 | N10 | N9 | N8
170 * 3[0x00]: N7 | N6 | N5 | N4 | N3 | N2 | N1 | N0
171 * 4[0x80]: 1 | 0 | RFG | BA1 | BA0 | BG1 | BG0 | LEN
172 * 5[0x00]: P0 | C1 | C0 | R4 | R3 | R2 | R1 | R0
173 * 6[0xc0]: 1 | 1 | 0 | 0 | RSD | 0 | 0 | 0
174 * 7[0x20]: P1 | BF6 | BF5 | BF4 | BF3 | BF2 | BF1 | 0
175 * 8[0xdb]: 1 | 1 | 0 | 1 | 0 | CC | 1 | 1
176 * 9[0x30]: VSD | V2 | V1 | V0 | S3 | S2 | S1 | S0
177 * 10[0xe1]: 1 | 1 | 1 | 0 | 0 | LS2 | LS1 | LS0
178 * 11[0xf5]: WS | WH2 | WH1 | WH0 | WL2 | WL1 | WL0 | WRE
179 * 12[0xf0]: 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0
180 * 13[0x28]: PD | BR4 | BR3 | BR2 | BR1 | BR0 | CLR | TL
181 */
182
183static int zl10036_set_frequency(struct zl10036_state *state, u32 frequency)
184{
185 u8 buf[2];
186 u32 div, foffset;
187
188 div = (frequency + _FR/2) / _FR;
189 state->frequency = div * _FR;
190
191 foffset = frequency - state->frequency;
192
193 buf[0] = (div >> 8) & 0x7f;
194 buf[1] = (div >> 0) & 0xff;
195
196 deb_info("%s: ftodo=%u fpriv=%u ferr=%d div=%u\n", __func__,
197 frequency, state->frequency, foffset, div);
198
199 return zl10036_write(state, buf, sizeof(buf));
200}
201
202static int zl10036_set_bandwidth(struct zl10036_state *state, u32 fbw)
203{
204 /* fbw is measured in kHz */
205 u8 br, bf;
206 int ret;
207 u8 buf_bf[] = {
208 0xc0, 0x00, /* 6/7: rsd=0 bf=0 */
209 };
210 u8 buf_br[] = {
211 0xf0, 0x00, /* 12/13: br=0xa clr=0 tl=0*/
212 };
213 u8 zl10036_rsd_off[] = { 0xc8 }; /* set RSD=1 */
214
215 /* ensure correct values */
216 if (fbw > 35000)
217 fbw = 35000;
218 if (fbw < 8000)
219 fbw = 8000;
220
221#define _BR_MAXIMUM (_XTAL/575) /* _XTAL / 575kHz = 17 */
222
223 /* <= 28,82 MHz */
224 if (fbw <= 28820) {
225 br = _BR_MAXIMUM;
226 } else {
227 /**
228 * f(bw)=34,6MHz f(xtal)=10.111MHz
229 * br = (10111/34600) * 63 * 1/K = 14;
230 */
231 br = ((_XTAL * 21 * 1000) / (fbw * 419));
232 }
233
234 /* ensure correct values */
235 if (br < 4)
236 br = 4;
237 if (br > _BR_MAXIMUM)
238 br = _BR_MAXIMUM;
239
240 /*
241 * k = 1.257
242 * bf = fbw/_XTAL * br * k - 1 */
243
244 bf = (fbw * br * 1257) / (_XTAL * 1000) - 1;
245
246 /* ensure correct values */
247 if (bf > 62)
248 bf = 62;
249
250 buf_bf[1] = (bf << 1) & 0x7e;
251 buf_br[1] = (br << 2) & 0x7c;
252 deb_info("%s: BW=%d br=%u bf=%u\n", __func__, fbw, br, bf);
253
254 if (br != state->br) {
255 ret = zl10036_write(state, buf_br, sizeof(buf_br));
256 if (ret < 0)
257 return ret;
258 }
259
260 if (bf != state->bf) {
261 ret = zl10036_write(state, buf_bf, sizeof(buf_bf));
262 if (ret < 0)
263 return ret;
264
265 /* time = br/(32* fxtal) */
266 /* minimal sleep time to be calculated
267 * maximum br is 63 -> max time = 2 /10 MHz = 2e-7 */
268 msleep(1);
269
270 ret = zl10036_write(state, zl10036_rsd_off,
271 sizeof(zl10036_rsd_off));
272 if (ret < 0)
273 return ret;
274 }
275
276 state->br = br;
277 state->bf = bf;
278
279 return 0;
280}
281
282static int zl10036_set_gain_params(struct zl10036_state *state,
283 int c)
284{
285 u8 buf[2];
286 u8 rfg, ba, bg;
287
288 /* default values */
289 rfg = 0; /* enable when using an lna */
290 ba = 1;
291 bg = 1;
292
293 /* reg 4 */
294 buf[0] = 0x80 | ((rfg << 5) & 0x20)
295 | ((ba << 3) & 0x18) | ((bg << 1) & 0x06);
296
297 if (!state->config->rf_loop_enable)
298 buf[0] |= 0x01;
299
300 /* P0=0 */
301 buf[1] = _RDIV_REG | ((c << 5) & 0x60);
302
303 deb_info("%s: c=%u rfg=%u ba=%u bg=%u\n", __func__, c, rfg, ba, bg);
304 return zl10036_write(state, buf, sizeof(buf));
305}
306
307static int zl10036_set_params(struct dvb_frontend *fe,
308 struct dvb_frontend_parameters *params)
309{
310 struct zl10036_state *state = fe->tuner_priv;
311 int ret = 0;
312 u32 frequency = params->frequency;
313 u32 fbw;
314 int i;
315 u8 c;
316
317 /* ensure correct values
318 * maybe redundant as core already checks this */
319 if ((frequency < fe->ops.info.frequency_min)
320 || (frequency > fe->ops.info.frequency_max))
321 return -EINVAL;
322
323 /**
324 * alpha = 1.35 for dvb-s
325 * fBW = (alpha*symbolrate)/(2*0.8)
326 * 1.35 / (2*0.8) = 27 / 32
327 */
328 fbw = (27 * params->u.qpsk.symbol_rate) / 32;
329
330 /* scale to kHz */
331 fbw /= 1000;
332
333 /* Add safe margin of 3MHz */
334 fbw += 3000;
335
336 /* setting the charge pump - guessed values */
337 if (frequency < 950000)
338 return -EINVAL;
339 else if (frequency < 1250000)
340 c = 0;
341 else if (frequency < 1750000)
342 c = 1;
343 else if (frequency < 2175000)
344 c = 2;
345 else
346 return -EINVAL;
347
348 if (fe->ops.i2c_gate_ctrl)
349 fe->ops.i2c_gate_ctrl(fe, 1); /* open i2c_gate */
350
351 ret = zl10036_set_gain_params(state, c);
352 if (ret < 0)
353 goto error;
354
355 ret = zl10036_set_frequency(state, params->frequency);
356 if (ret < 0)
357 goto error;
358
359 ret = zl10036_set_bandwidth(state, fbw);
360 if (ret < 0)
361 goto error;
362
363 /* wait for tuner lock - no idea if this is really needed */
364 for (i = 0; i < 20; i++) {
365 ret = zl10036_read_status_reg(state);
366 if (ret < 0)
367 goto error;
368
369 /* check Frequency & Phase Lock Bit */
370 if (ret & STATUS_FL)
371 break;
372
373 msleep(10);
374 }
375
376error:
377 if (fe->ops.i2c_gate_ctrl)
378 fe->ops.i2c_gate_ctrl(fe, 0); /* close i2c_gate */
379
380 return ret;
381}
382
383static int zl10036_get_frequency(struct dvb_frontend *fe, u32 *frequency)
384{
385 struct zl10036_state *state = fe->tuner_priv;
386
387 *frequency = state->frequency;
388
389 return 0;
390}
391
392static int zl10036_init_regs(struct zl10036_state *state)
393{
394 int ret;
395 int i;
396
397 /* could also be one block from reg 2 to 13 and additional 10/11 */
398 u8 zl10036_init_tab[][2] = {
399 { 0x04, 0x00 }, /* 2/3: div=0x400 - arbitrary value */
400 { 0x8b, _RDIV_REG }, /* 4/5: rfg=0 ba=1 bg=1 len=? */
401 /* p0=0 c=0 r=_RDIV_REG */
402 { 0xc0, 0x20 }, /* 6/7: rsd=0 bf=0x10 */
403 { 0xd3, 0x40 }, /* 8/9: from datasheet */
404 { 0xe3, 0x5b }, /* 10/11: lock window level */
405 { 0xf0, 0x28 }, /* 12/13: br=0xa clr=0 tl=0*/
406 { 0xe3, 0xf9 }, /* 10/11: unlock window level */
407 };
408
409 /* invalid values to trigger writing */
410 state->br = 0xff;
411 state->bf = 0xff;
412
413 if (!state->config->rf_loop_enable)
414 zl10036_init_tab[1][2] |= 0x01;
415
416 deb_info("%s\n", __func__);
417
418 for (i = 0; i < ARRAY_SIZE(zl10036_init_tab); i++) {
419 ret = zl10036_write(state, zl10036_init_tab[i], 2);
420 if (ret < 0)
421 return ret;
422 }
423
424 return 0;
425}
426
427static int zl10036_init(struct dvb_frontend *fe)
428{
429 struct zl10036_state *state = fe->tuner_priv;
430 int ret = 0;
431
432 if (fe->ops.i2c_gate_ctrl)
433 fe->ops.i2c_gate_ctrl(fe, 1); /* open i2c_gate */
434
435 ret = zl10036_read_status_reg(state);
436 if (ret < 0)
437 return ret;
438
439 /* Only init if Power-on-Reset bit is set? */
440 ret = zl10036_init_regs(state);
441
442 if (fe->ops.i2c_gate_ctrl)
443 fe->ops.i2c_gate_ctrl(fe, 0); /* close i2c_gate */
444
445 return ret;
446}
447
448static struct dvb_tuner_ops zl10036_tuner_ops = {
449 .info = {
450 .name = "Zarlink ZL10036",
451 .frequency_min = 950000,
452 .frequency_max = 2175000
453 },
454 .init = zl10036_init,
455 .release = zl10036_release,
456 .sleep = zl10036_sleep,
457 .set_params = zl10036_set_params,
458 .get_frequency = zl10036_get_frequency,
459};
460
461struct dvb_frontend *zl10036_attach(struct dvb_frontend *fe,
462 const struct zl10036_config *config,
463 struct i2c_adapter *i2c)
464{
465 struct zl10036_state *state = NULL;
466 int ret;
467
468 if (NULL == config) {
469 printk(KERN_ERR "%s: no config specified", __func__);
470 goto error;
471 }
472
473 state = kzalloc(sizeof(struct zl10036_state), GFP_KERNEL);
474 if (NULL == state)
475 return NULL;
476
477 state->config = config;
478 state->i2c = i2c;
479
480 if (fe->ops.i2c_gate_ctrl)
481 fe->ops.i2c_gate_ctrl(fe, 1); /* open i2c_gate */
482
483 ret = zl10036_read_status_reg(state);
484 if (ret < 0) {
485 printk(KERN_ERR "%s: No zl10036 found\n", __func__);
486 goto error;
487 }
488
489 ret = zl10036_init_regs(state);
490 if (ret < 0) {
491 printk(KERN_ERR "%s: tuner initialization failed\n",
492 __func__);
493 goto error;
494 }
495
496 if (fe->ops.i2c_gate_ctrl)
497 fe->ops.i2c_gate_ctrl(fe, 0); /* close i2c_gate */
498
499 fe->tuner_priv = state;
500
501 memcpy(&fe->ops.tuner_ops, &zl10036_tuner_ops,
502 sizeof(struct dvb_tuner_ops));
503 printk(KERN_INFO "%s: tuner initialization (%s addr=0x%02x) ok\n",
504 __func__, fe->ops.tuner_ops.info.name, config->tuner_address);
505
506 return fe;
507
508error:
509 zl10036_release(fe);
510 return NULL;
511}
512EXPORT_SYMBOL(zl10036_attach);
513
514module_param_named(debug, zl10036_debug, int, 0644);
515MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
516MODULE_DESCRIPTION("DVB ZL10036 driver");
517MODULE_AUTHOR("Tino Reichardt");
518MODULE_AUTHOR("Matthias Schwarzott");
519MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/zl10036.h b/drivers/media/dvb/frontends/zl10036.h
new file mode 100644
index 000000000000..d84b8f8215e9
--- /dev/null
+++ b/drivers/media/dvb/frontends/zl10036.h
@@ -0,0 +1,53 @@
1/**
2 * Driver for Zarlink ZL10036 DVB-S silicon tuner
3 *
4 * Copyright (C) 2006 Tino Reichardt
5 * Copyright (C) 2007-2009 Matthias Schwarzott <zzam@gentoo.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 Version 2, as
9 * published by the Free Software Foundation.
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 DVB_ZL10036_H
22#define DVB_ZL10036_H
23
24#include <linux/i2c.h>
25#include "dvb_frontend.h"
26
27/**
28 * Attach a zl10036 tuner to the supplied frontend structure.
29 *
30 * @param fe Frontend to attach to.
31 * @param config zl10036_config structure
32 * @return FE pointer on success, NULL on failure.
33 */
34
35struct zl10036_config {
36 u8 tuner_address;
37 int rf_loop_enable;
38};
39
40#if defined(CONFIG_DVB_ZL10036) || \
41 (defined(CONFIG_DVB_ZL10036_MODULE) && defined(MODULE))
42extern struct dvb_frontend *zl10036_attach(struct dvb_frontend *fe,
43 const struct zl10036_config *config, struct i2c_adapter *i2c);
44#else
45static inline struct dvb_frontend *zl10036_attach(struct dvb_frontend *fe,
46 const struct zl10036_config *config, struct i2c_adapter *i2c)
47{
48 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
49 return NULL;
50}
51#endif
52
53#endif /* DVB_ZL10036_H */
diff --git a/drivers/media/dvb/frontends/zl10353.c b/drivers/media/dvb/frontends/zl10353.c
index b150ed306696..148b6f7f6cb2 100644
--- a/drivers/media/dvb/frontends/zl10353.c
+++ b/drivers/media/dvb/frontends/zl10353.c
@@ -572,6 +572,10 @@ static int zl10353_init(struct dvb_frontend *fe)
572 zl10353_dump_regs(fe); 572 zl10353_dump_regs(fe);
573 if (state->config.parallel_ts) 573 if (state->config.parallel_ts)
574 zl10353_reset_attach[2] &= ~0x20; 574 zl10353_reset_attach[2] &= ~0x20;
575 if (state->config.clock_ctl_1)
576 zl10353_reset_attach[3] = state->config.clock_ctl_1;
577 if (state->config.pll_0)
578 zl10353_reset_attach[4] = state->config.pll_0;
575 579
576 /* Do a "hard" reset if not already done */ 580 /* Do a "hard" reset if not already done */
577 if (zl10353_read_register(state, 0x50) != zl10353_reset_attach[1] || 581 if (zl10353_read_register(state, 0x50) != zl10353_reset_attach[1] ||
@@ -614,6 +618,7 @@ struct dvb_frontend *zl10353_attach(const struct zl10353_config *config,
614 struct i2c_adapter *i2c) 618 struct i2c_adapter *i2c)
615{ 619{
616 struct zl10353_state *state = NULL; 620 struct zl10353_state *state = NULL;
621 int id;
617 622
618 /* allocate memory for the internal state */ 623 /* allocate memory for the internal state */
619 state = kzalloc(sizeof(struct zl10353_state), GFP_KERNEL); 624 state = kzalloc(sizeof(struct zl10353_state), GFP_KERNEL);
@@ -625,7 +630,8 @@ struct dvb_frontend *zl10353_attach(const struct zl10353_config *config,
625 memcpy(&state->config, config, sizeof(struct zl10353_config)); 630 memcpy(&state->config, config, sizeof(struct zl10353_config));
626 631
627 /* check if the demod is there */ 632 /* check if the demod is there */
628 if (zl10353_read_register(state, CHIP_ID) != ID_ZL10353) 633 id = zl10353_read_register(state, CHIP_ID);
634 if ((id != ID_ZL10353) && (id != ID_CE6230) && (id != ID_CE6231))
629 goto error; 635 goto error;
630 636
631 /* create dvb_frontend */ 637 /* create dvb_frontend */
diff --git a/drivers/media/dvb/frontends/zl10353.h b/drivers/media/dvb/frontends/zl10353.h
index 2287bac46243..6e3ca9eed048 100644
--- a/drivers/media/dvb/frontends/zl10353.h
+++ b/drivers/media/dvb/frontends/zl10353.h
@@ -41,6 +41,10 @@ struct zl10353_config
41 41
42 /* set if i2c_gate_ctrl disable is required */ 42 /* set if i2c_gate_ctrl disable is required */
43 u8 disable_i2c_gate_ctrl:1; 43 u8 disable_i2c_gate_ctrl:1;
44
45 /* clock control registers (0x51-0x54) */
46 u8 clock_ctl_1; /* default: 0x46 */
47 u8 pll_0; /* default: 0x15 */
44}; 48};
45 49
46#if defined(CONFIG_DVB_ZL10353) || (defined(CONFIG_DVB_ZL10353_MODULE) && defined(MODULE)) 50#if defined(CONFIG_DVB_ZL10353) || (defined(CONFIG_DVB_ZL10353_MODULE) && defined(MODULE))
diff --git a/drivers/media/dvb/frontends/zl10353_priv.h b/drivers/media/dvb/frontends/zl10353_priv.h
index 055ff1f7e349..e0dd1d3e09dd 100644
--- a/drivers/media/dvb/frontends/zl10353_priv.h
+++ b/drivers/media/dvb/frontends/zl10353_priv.h
@@ -22,7 +22,9 @@
22#ifndef _ZL10353_PRIV_ 22#ifndef _ZL10353_PRIV_
23#define _ZL10353_PRIV_ 23#define _ZL10353_PRIV_
24 24
25#define ID_ZL10353 0x14 25#define ID_ZL10353 0x14 /* Zarlink ZL10353 */
26#define ID_CE6230 0x18 /* Intel CE6230 */
27#define ID_CE6231 0x19 /* Intel CE6231 */
26 28
27#define msb(x) (((x) >> 8) & 0xff) 29#define msb(x) (((x) >> 8) & 0xff)
28#define lsb(x) ((x) & 0xff) 30#define lsb(x) ((x) & 0xff)
@@ -50,6 +52,10 @@ enum zl10353_reg_addr {
50 TPS_RECEIVED_0 = 0x1E, 52 TPS_RECEIVED_0 = 0x1E,
51 TPS_CURRENT_1 = 0x1F, 53 TPS_CURRENT_1 = 0x1F,
52 TPS_CURRENT_0 = 0x20, 54 TPS_CURRENT_0 = 0x20,
55 CLOCK_CTL_0 = 0x51,
56 CLOCK_CTL_1 = 0x52,
57 PLL_0 = 0x53,
58 PLL_1 = 0x54,
53 RESET = 0x55, 59 RESET = 0x55,
54 AGC_TARGET = 0x56, 60 AGC_TARGET = 0x56,
55 MCLK_RATIO = 0x5C, 61 MCLK_RATIO = 0x5C,
diff --git a/drivers/media/dvb/pluto2/pluto2.c b/drivers/media/dvb/pluto2/pluto2.c
index d101b304e9b0..ee89623be85a 100644
--- a/drivers/media/dvb/pluto2/pluto2.c
+++ b/drivers/media/dvb/pluto2/pluto2.c
@@ -116,6 +116,7 @@ struct pluto {
116 116
117 /* irq */ 117 /* irq */
118 unsigned int overflow; 118 unsigned int overflow;
119 unsigned int dead;
119 120
120 /* dma */ 121 /* dma */
121 dma_addr_t dma_addr; 122 dma_addr_t dma_addr;
@@ -336,8 +337,10 @@ static irqreturn_t pluto_irq(int irq, void *dev_id)
336 return IRQ_NONE; 337 return IRQ_NONE;
337 338
338 if (tscr == 0xffffffff) { 339 if (tscr == 0xffffffff) {
339 // FIXME: maybe recover somehow 340 if (pluto->dead == 0)
340 dev_err(&pluto->pdev->dev, "card hung up :(\n"); 341 dev_err(&pluto->pdev->dev, "card has hung or been ejected.\n");
342 /* It's dead Jim */
343 pluto->dead = 1;
341 return IRQ_HANDLED; 344 return IRQ_HANDLED;
342 } 345 }
343 346
diff --git a/drivers/media/dvb/siano/Makefile b/drivers/media/dvb/siano/Makefile
index ee0737af98c0..bcf93f4828b2 100644
--- a/drivers/media/dvb/siano/Makefile
+++ b/drivers/media/dvb/siano/Makefile
@@ -1,6 +1,8 @@
1sms1xxx-objs := smscoreapi.o smsusb.o smsdvb.o sms-cards.o 1sms1xxx-objs := smscoreapi.o sms-cards.o
2 2
3obj-$(CONFIG_DVB_SIANO_SMS1XXX) += sms1xxx.o 3obj-$(CONFIG_DVB_SIANO_SMS1XXX) += sms1xxx.o
4obj-$(CONFIG_DVB_SIANO_SMS1XXX) += smsusb.o
5obj-$(CONFIG_DVB_SIANO_SMS1XXX) += smsdvb.o
4 6
5EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core 7EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
6 8
diff --git a/drivers/media/dvb/siano/sms-cards.c b/drivers/media/dvb/siano/sms-cards.c
index 4307e4e8aa34..63e4d0ec6583 100644
--- a/drivers/media/dvb/siano/sms-cards.c
+++ b/drivers/media/dvb/siano/sms-cards.c
@@ -19,50 +19,9 @@
19 19
20#include "sms-cards.h" 20#include "sms-cards.h"
21 21
22struct usb_device_id smsusb_id_table[] = { 22static int sms_dbg;
23#ifdef CONFIG_DVB_SIANO_SMS1XXX_SMS_IDS 23module_param_named(cards_dbg, sms_dbg, int, 0644);
24 { USB_DEVICE(0x187f, 0x0010), 24MODULE_PARM_DESC(cards_dbg, "set debug level (info=1, adv=2 (or-able))");
25 .driver_info = SMS1XXX_BOARD_SIANO_STELLAR },
26 { USB_DEVICE(0x187f, 0x0100),
27 .driver_info = SMS1XXX_BOARD_SIANO_STELLAR },
28 { USB_DEVICE(0x187f, 0x0200),
29 .driver_info = SMS1XXX_BOARD_SIANO_NOVA_A },
30 { USB_DEVICE(0x187f, 0x0201),
31 .driver_info = SMS1XXX_BOARD_SIANO_NOVA_B },
32 { USB_DEVICE(0x187f, 0x0300),
33 .driver_info = SMS1XXX_BOARD_SIANO_VEGA },
34#endif
35 { USB_DEVICE(0x2040, 0x1700),
36 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_CATAMOUNT },
37 { USB_DEVICE(0x2040, 0x1800),
38 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_OKEMO_A },
39 { USB_DEVICE(0x2040, 0x1801),
40 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_OKEMO_B },
41 { USB_DEVICE(0x2040, 0x2000),
42 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD },
43 { USB_DEVICE(0x2040, 0x2009),
44 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD_R2 },
45 { USB_DEVICE(0x2040, 0x200a),
46 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD },
47 { USB_DEVICE(0x2040, 0x2010),
48 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD },
49 { USB_DEVICE(0x2040, 0x2019),
50 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD },
51 { USB_DEVICE(0x2040, 0x5500),
52 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
53 { USB_DEVICE(0x2040, 0x5510),
54 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
55 { USB_DEVICE(0x2040, 0x5520),
56 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
57 { USB_DEVICE(0x2040, 0x5530),
58 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
59 { USB_DEVICE(0x2040, 0x5580),
60 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
61 { USB_DEVICE(0x2040, 0x5590),
62 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
63 { } /* Terminating entry */
64};
65MODULE_DEVICE_TABLE(usb, smsusb_id_table);
66 25
67static struct sms_board sms_boards[] = { 26static struct sms_board sms_boards[] = {
68 [SMS_BOARD_UNKNOWN] = { 27 [SMS_BOARD_UNKNOWN] = {
@@ -115,6 +74,7 @@ static struct sms_board sms_boards[] = {
115 .type = SMS_NOVA_B0, 74 .type = SMS_NOVA_B0,
116 .fw[DEVICE_MODE_DVBT_BDA] = "sms1xxx-hcw-55xxx-dvbt-02.fw", 75 .fw[DEVICE_MODE_DVBT_BDA] = "sms1xxx-hcw-55xxx-dvbt-02.fw",
117 .lna_ctrl = 29, 76 .lna_ctrl = 29,
77 .rf_switch = 17,
118 }, 78 },
119 [SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD_R2] = { 79 [SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD_R2] = {
120 .name = "Hauppauge WinTV MiniCard", 80 .name = "Hauppauge WinTV MiniCard",
@@ -130,6 +90,7 @@ struct sms_board *sms_get_board(int id)
130 90
131 return &sms_boards[id]; 91 return &sms_boards[id];
132} 92}
93EXPORT_SYMBOL_GPL(sms_get_board);
133 94
134static int sms_set_gpio(struct smscore_device_t *coredev, int pin, int enable) 95static int sms_set_gpio(struct smscore_device_t *coredev, int pin, int enable)
135{ 96{
@@ -182,6 +143,7 @@ int sms_board_setup(struct smscore_device_t *coredev)
182 } 143 }
183 return 0; 144 return 0;
184} 145}
146EXPORT_SYMBOL_GPL(sms_board_setup);
185 147
186int sms_board_power(struct smscore_device_t *coredev, int onoff) 148int sms_board_power(struct smscore_device_t *coredev, int onoff)
187{ 149{
@@ -197,12 +159,13 @@ int sms_board_power(struct smscore_device_t *coredev, int onoff)
197 case SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD_R2: 159 case SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD_R2:
198 case SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD: 160 case SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD:
199 /* LNA */ 161 /* LNA */
200 sms_set_gpio(coredev, 162 if (!onoff)
201 board->lna_ctrl, onoff ? 1 : 0); 163 sms_set_gpio(coredev, board->lna_ctrl, 0);
202 break; 164 break;
203 } 165 }
204 return 0; 166 return 0;
205} 167}
168EXPORT_SYMBOL_GPL(sms_board_power);
206 169
207int sms_board_led_feedback(struct smscore_device_t *coredev, int led) 170int sms_board_led_feedback(struct smscore_device_t *coredev, int led)
208{ 171{
@@ -225,3 +188,40 @@ int sms_board_led_feedback(struct smscore_device_t *coredev, int led)
225 } 188 }
226 return 0; 189 return 0;
227} 190}
191EXPORT_SYMBOL_GPL(sms_board_led_feedback);
192
193int sms_board_lna_control(struct smscore_device_t *coredev, int onoff)
194{
195 int board_id = smscore_get_board_id(coredev);
196 struct sms_board *board = sms_get_board(board_id);
197
198 sms_debug("%s: LNA %s", __func__, onoff ? "enabled" : "disabled");
199
200 switch (board_id) {
201 case SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD_R2:
202 case SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD:
203 sms_set_gpio(coredev,
204 board->rf_switch, onoff ? 1 : 0);
205 return sms_set_gpio(coredev,
206 board->lna_ctrl, onoff ? 1 : 0);
207 }
208 return -EINVAL;
209}
210EXPORT_SYMBOL_GPL(sms_board_lna_control);
211
212int sms_board_load_modules(int id)
213{
214 switch (id) {
215 case SMS1XXX_BOARD_HAUPPAUGE_CATAMOUNT:
216 case SMS1XXX_BOARD_HAUPPAUGE_OKEMO_A:
217 case SMS1XXX_BOARD_HAUPPAUGE_OKEMO_B:
218 case SMS1XXX_BOARD_HAUPPAUGE_WINDHAM:
219 request_module("smsdvb");
220 break;
221 default:
222 /* do nothing */
223 break;
224 }
225 return 0;
226}
227EXPORT_SYMBOL_GPL(sms_board_load_modules);
diff --git a/drivers/media/dvb/siano/sms-cards.h b/drivers/media/dvb/siano/sms-cards.h
index 8e0fe9fd2610..64d74c59c33f 100644
--- a/drivers/media/dvb/siano/sms-cards.h
+++ b/drivers/media/dvb/siano/sms-cards.h
@@ -40,7 +40,7 @@ struct sms_board {
40 char *name, *fw[DEVICE_MODE_MAX]; 40 char *name, *fw[DEVICE_MODE_MAX];
41 41
42 /* gpios */ 42 /* gpios */
43 int led_power, led_hi, led_lo, lna_ctrl; 43 int led_power, led_hi, led_lo, lna_ctrl, rf_switch;
44}; 44};
45 45
46struct sms_board *sms_get_board(int id); 46struct sms_board *sms_get_board(int id);
@@ -52,7 +52,8 @@ int sms_board_setup(struct smscore_device_t *coredev);
52#define SMS_LED_HI 2 52#define SMS_LED_HI 2
53int sms_board_led_feedback(struct smscore_device_t *coredev, int led); 53int sms_board_led_feedback(struct smscore_device_t *coredev, int led);
54int sms_board_power(struct smscore_device_t *coredev, int onoff); 54int sms_board_power(struct smscore_device_t *coredev, int onoff);
55int sms_board_lna_control(struct smscore_device_t *coredev, int onoff);
55 56
56extern struct usb_device_id smsusb_id_table[]; 57extern int sms_board_load_modules(int id);
57 58
58#endif /* __SMS_CARDS_H__ */ 59#endif /* __SMS_CARDS_H__ */
diff --git a/drivers/media/dvb/siano/smscoreapi.c b/drivers/media/dvb/siano/smscoreapi.c
index cf613f22fb8d..7bd4d1dee2b3 100644
--- a/drivers/media/dvb/siano/smscoreapi.c
+++ b/drivers/media/dvb/siano/smscoreapi.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * This file contains implementation for the interface to sms core component 4 * This file contains implementation for the interface to sms core component
5 * 5 *
6 * author: Anatoly Greenblat 6 * author: Uri Shkolnik
7 * 7 *
8 * Copyright (c), 2005-2008 Siano Mobile Silicon, Inc. 8 * Copyright (c), 2005-2008 Siano Mobile Silicon, Inc.
9 * 9 *
@@ -34,8 +34,8 @@
34#include "smscoreapi.h" 34#include "smscoreapi.h"
35#include "sms-cards.h" 35#include "sms-cards.h"
36 36
37int sms_debug; 37static int sms_dbg;
38module_param_named(debug, sms_debug, int, 0644); 38module_param_named(debug, sms_dbg, int, 0644);
39MODULE_PARM_DESC(debug, "set debug level (info=1, adv=2 (or-able))"); 39MODULE_PARM_DESC(debug, "set debug level (info=1, adv=2 (or-able))");
40 40
41struct smscore_device_notifyee_t { 41struct smscore_device_notifyee_t {
@@ -105,11 +105,13 @@ int smscore_led_state(struct smscore_device_t *core, int led)
105 core->led_state = led; 105 core->led_state = led;
106 return core->led_state; 106 return core->led_state;
107} 107}
108EXPORT_SYMBOL_GPL(smscore_set_board_id);
108 109
109int smscore_get_board_id(struct smscore_device_t *core) 110int smscore_get_board_id(struct smscore_device_t *core)
110{ 111{
111 return core->board_id; 112 return core->board_id;
112} 113}
114EXPORT_SYMBOL_GPL(smscore_get_board_id);
113 115
114struct smscore_registry_entry_t { 116struct smscore_registry_entry_t {
115 struct list_head entry; 117 struct list_head entry;
@@ -170,6 +172,7 @@ int smscore_registry_getmode(char *devpath)
170 172
171 return default_mode; 173 return default_mode;
172} 174}
175EXPORT_SYMBOL_GPL(smscore_registry_getmode);
173 176
174static enum sms_device_type_st smscore_registry_gettype(char *devpath) 177static enum sms_device_type_st smscore_registry_gettype(char *devpath)
175{ 178{
@@ -261,6 +264,7 @@ int smscore_register_hotplug(hotplug_t hotplug)
261 264
262 return rc; 265 return rc;
263} 266}
267EXPORT_SYMBOL_GPL(smscore_register_hotplug);
264 268
265/** 269/**
266 * unregister a client callback that called when device plugged in/unplugged 270 * unregister a client callback that called when device plugged in/unplugged
@@ -289,6 +293,7 @@ void smscore_unregister_hotplug(hotplug_t hotplug)
289 293
290 kmutex_unlock(&g_smscore_deviceslock); 294 kmutex_unlock(&g_smscore_deviceslock);
291} 295}
296EXPORT_SYMBOL_GPL(smscore_unregister_hotplug);
292 297
293static void smscore_notify_clients(struct smscore_device_t *coredev) 298static void smscore_notify_clients(struct smscore_device_t *coredev)
294{ 299{
@@ -432,6 +437,7 @@ int smscore_register_device(struct smsdevice_params_t *params,
432 437
433 return 0; 438 return 0;
434} 439}
440EXPORT_SYMBOL_GPL(smscore_register_device);
435 441
436/** 442/**
437 * sets initial device mode and notifies client hotplugs that device is ready 443 * sets initial device mode and notifies client hotplugs that device is ready
@@ -460,6 +466,7 @@ int smscore_start_device(struct smscore_device_t *coredev)
460 466
461 return rc; 467 return rc;
462} 468}
469EXPORT_SYMBOL_GPL(smscore_start_device);
463 470
464static int smscore_sendrequest_and_wait(struct smscore_device_t *coredev, 471static int smscore_sendrequest_and_wait(struct smscore_device_t *coredev,
465 void *buffer, size_t size, 472 void *buffer, size_t size,
@@ -688,6 +695,7 @@ void smscore_unregister_device(struct smscore_device_t *coredev)
688 695
689 sms_info("device %p destroyed", coredev); 696 sms_info("device %p destroyed", coredev);
690} 697}
698EXPORT_SYMBOL_GPL(smscore_unregister_device);
691 699
692static int smscore_detect_mode(struct smscore_device_t *coredev) 700static int smscore_detect_mode(struct smscore_device_t *coredev)
693{ 701{
@@ -732,7 +740,7 @@ static char *smscore_fw_lkup[][SMS_NUM_OF_DEVICE_TYPES] = {
732 /*DVBH*/ 740 /*DVBH*/
733 {"none", "dvb_nova_12mhz.inp", "dvb_nova_12mhz_b0.inp", "none"}, 741 {"none", "dvb_nova_12mhz.inp", "dvb_nova_12mhz_b0.inp", "none"},
734 /*TDMB*/ 742 /*TDMB*/
735 {"none", "tdmb_nova_12mhz.inp", "none", "none"}, 743 {"none", "tdmb_nova_12mhz.inp", "tdmb_nova_12mhz_b0.inp", "none"},
736 /*DABIP*/ 744 /*DABIP*/
737 {"none", "none", "none", "none"}, 745 {"none", "none", "none", "none"},
738 /*BDA*/ 746 /*BDA*/
@@ -879,6 +887,7 @@ int smscore_get_device_mode(struct smscore_device_t *coredev)
879{ 887{
880 return coredev->mode; 888 return coredev->mode;
881} 889}
890EXPORT_SYMBOL_GPL(smscore_get_device_mode);
882 891
883/** 892/**
884 * find client by response id & type within the clients list. 893 * find client by response id & type within the clients list.
@@ -1006,6 +1015,7 @@ void smscore_onresponse(struct smscore_device_t *coredev,
1006 smscore_putbuffer(coredev, cb); 1015 smscore_putbuffer(coredev, cb);
1007 } 1016 }
1008} 1017}
1018EXPORT_SYMBOL_GPL(smscore_onresponse);
1009 1019
1010/** 1020/**
1011 * return pointer to next free buffer descriptor from core pool 1021 * return pointer to next free buffer descriptor from core pool
@@ -1031,6 +1041,7 @@ struct smscore_buffer_t *smscore_getbuffer(struct smscore_device_t *coredev)
1031 1041
1032 return cb; 1042 return cb;
1033} 1043}
1044EXPORT_SYMBOL_GPL(smscore_getbuffer);
1034 1045
1035/** 1046/**
1036 * return buffer descriptor to a pool 1047 * return buffer descriptor to a pool
@@ -1045,6 +1056,7 @@ void smscore_putbuffer(struct smscore_device_t *coredev,
1045{ 1056{
1046 list_add_locked(&cb->entry, &coredev->buffers, &coredev->bufferslock); 1057 list_add_locked(&cb->entry, &coredev->buffers, &coredev->bufferslock);
1047} 1058}
1059EXPORT_SYMBOL_GPL(smscore_putbuffer);
1048 1060
1049static int smscore_validate_client(struct smscore_device_t *coredev, 1061static int smscore_validate_client(struct smscore_device_t *coredev,
1050 struct smscore_client_t *client, 1062 struct smscore_client_t *client,
@@ -1124,6 +1136,7 @@ int smscore_register_client(struct smscore_device_t *coredev,
1124 1136
1125 return 0; 1137 return 0;
1126} 1138}
1139EXPORT_SYMBOL_GPL(smscore_register_client);
1127 1140
1128/** 1141/**
1129 * frees smsclient object and all subclients associated with it 1142 * frees smsclient object and all subclients associated with it
@@ -1154,6 +1167,7 @@ void smscore_unregister_client(struct smscore_client_t *client)
1154 1167
1155 spin_unlock_irqrestore(&coredev->clientslock, flags); 1168 spin_unlock_irqrestore(&coredev->clientslock, flags);
1156} 1169}
1170EXPORT_SYMBOL_GPL(smscore_unregister_client);
1157 1171
1158/** 1172/**
1159 * verifies that source id is not taken by another client, 1173 * verifies that source id is not taken by another client,
@@ -1193,6 +1207,7 @@ int smsclient_sendrequest(struct smscore_client_t *client,
1193 1207
1194 return coredev->sendrequest_handler(coredev->context, buffer, size); 1208 return coredev->sendrequest_handler(coredev->context, buffer, size);
1195} 1209}
1210EXPORT_SYMBOL_GPL(smsclient_sendrequest);
1196 1211
1197 1212
1198int smscore_configure_gpio(struct smscore_device_t *coredev, u32 pin, 1213int smscore_configure_gpio(struct smscore_device_t *coredev, u32 pin,
@@ -1276,12 +1291,12 @@ static int __init smscore_module_init(void)
1276 INIT_LIST_HEAD(&g_smscore_registry); 1291 INIT_LIST_HEAD(&g_smscore_registry);
1277 kmutex_init(&g_smscore_registrylock); 1292 kmutex_init(&g_smscore_registrylock);
1278 1293
1279 /* USB Register */
1280 rc = smsusb_register();
1281 1294
1282 /* DVB Register */
1283 rc = smsdvb_register();
1284 1295
1296
1297
1298
1299 return rc;
1285 sms_debug("rc %d", rc); 1300 sms_debug("rc %d", rc);
1286 1301
1287 return rc; 1302 return rc;
@@ -1290,6 +1305,10 @@ static int __init smscore_module_init(void)
1290static void __exit smscore_module_exit(void) 1305static void __exit smscore_module_exit(void)
1291{ 1306{
1292 1307
1308
1309
1310
1311
1293 kmutex_lock(&g_smscore_deviceslock); 1312 kmutex_lock(&g_smscore_deviceslock);
1294 while (!list_empty(&g_smscore_notifyees)) { 1313 while (!list_empty(&g_smscore_notifyees)) {
1295 struct smscore_device_notifyee_t *notifyee = 1314 struct smscore_device_notifyee_t *notifyee =
@@ -1312,18 +1331,12 @@ static void __exit smscore_module_exit(void)
1312 } 1331 }
1313 kmutex_unlock(&g_smscore_registrylock); 1332 kmutex_unlock(&g_smscore_registrylock);
1314 1333
1315 /* DVB UnRegister */
1316 smsdvb_unregister();
1317
1318 /* Unregister USB */
1319 smsusb_unregister();
1320
1321 sms_debug(""); 1334 sms_debug("");
1322} 1335}
1323 1336
1324module_init(smscore_module_init); 1337module_init(smscore_module_init);
1325module_exit(smscore_module_exit); 1338module_exit(smscore_module_exit);
1326 1339
1327MODULE_DESCRIPTION("Driver for the Siano SMS1XXX USB dongle"); 1340MODULE_DESCRIPTION("Siano MDTV Core module");
1328MODULE_AUTHOR("Siano Mobile Silicon,,, (doronc@siano-ms.com)"); 1341MODULE_AUTHOR("Siano Mobile Silicon, Inc. (uris@siano-ms.com)");
1329MODULE_LICENSE("GPL"); 1342MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/siano/smscoreapi.h b/drivers/media/dvb/siano/smscoreapi.h
index 760e233fcbc5..548de9056e8b 100644
--- a/drivers/media/dvb/siano/smscoreapi.h
+++ b/drivers/media/dvb/siano/smscoreapi.h
@@ -29,13 +29,13 @@
29#include <linux/scatterlist.h> 29#include <linux/scatterlist.h>
30#include <linux/types.h> 30#include <linux/types.h>
31#include <asm/page.h> 31#include <asm/page.h>
32#include <linux/mutex.h>
32 33
33#include "dmxdev.h" 34#include "dmxdev.h"
34#include "dvbdev.h" 35#include "dvbdev.h"
35#include "dvb_demux.h" 36#include "dvb_demux.h"
36#include "dvb_frontend.h" 37#include "dvb_frontend.h"
37 38
38#include <linux/mutex.h>
39 39
40#define kmutex_init(_p_) mutex_init(_p_) 40#define kmutex_init(_p_) mutex_init(_p_)
41#define kmutex_lock(_p_) mutex_lock(_p_) 41#define kmutex_lock(_p_) mutex_lock(_p_)
@@ -369,27 +369,6 @@ struct smscore_gpio_config {
369 u8 outputdriving; 369 u8 outputdriving;
370}; 370};
371 371
372struct smsdvb_client_t {
373 struct list_head entry;
374
375 struct smscore_device_t *coredev;
376 struct smscore_client_t *smsclient;
377
378 struct dvb_adapter adapter;
379 struct dvb_demux demux;
380 struct dmxdev dmxdev;
381 struct dvb_frontend frontend;
382
383 fe_status_t fe_status;
384 int fe_ber, fe_snr, fe_unc, fe_signal_strength;
385
386 struct completion tune_done, stat_done;
387
388 /* todo: save freq/band instead whole struct */
389 struct dvb_frontend_parameters fe_params;
390
391};
392
393extern void smscore_registry_setmode(char *devpath, int mode); 372extern void smscore_registry_setmode(char *devpath, int mode);
394extern int smscore_registry_getmode(char *devpath); 373extern int smscore_registry_getmode(char *devpath);
395 374
@@ -418,6 +397,13 @@ extern int smsclient_sendrequest(struct smscore_client_t *client,
418extern void smscore_onresponse(struct smscore_device_t *coredev, 397extern void smscore_onresponse(struct smscore_device_t *coredev,
419 struct smscore_buffer_t *cb); 398 struct smscore_buffer_t *cb);
420 399
400extern int smscore_get_common_buffer_size(struct smscore_device_t *coredev);
401extern int smscore_map_common_buffer(struct smscore_device_t *coredev,
402 struct vm_area_struct *vma);
403extern int smscore_get_fw_filename(struct smscore_device_t *coredev,
404 int mode, char *filename);
405extern int smscore_send_fw_file(struct smscore_device_t *coredev,
406 u8 *ufwbuf, int size);
421 407
422extern 408extern
423struct smscore_buffer_t *smscore_getbuffer(struct smscore_device_t *coredev); 409struct smscore_buffer_t *smscore_getbuffer(struct smscore_device_t *coredev);
@@ -433,18 +419,9 @@ int smscore_get_board_id(struct smscore_device_t *core);
433 419
434int smscore_led_state(struct smscore_device_t *core, int led); 420int smscore_led_state(struct smscore_device_t *core, int led);
435 421
436/* smsdvb.c */
437int smsdvb_register(void);
438void smsdvb_unregister(void);
439
440/* smsusb.c */
441int smsusb_register(void);
442void smsusb_unregister(void);
443 422
444/* ------------------------------------------------------------------------ */ 423/* ------------------------------------------------------------------------ */
445 424
446extern int sms_debug;
447
448#define DBG_INFO 1 425#define DBG_INFO 1
449#define DBG_ADV 2 426#define DBG_ADV 2
450 427
@@ -452,7 +429,7 @@ extern int sms_debug;
452 printk(kern "%s: " fmt "\n", __func__, ##arg) 429 printk(kern "%s: " fmt "\n", __func__, ##arg)
453 430
454#define dprintk(kern, lvl, fmt, arg...) do {\ 431#define dprintk(kern, lvl, fmt, arg...) do {\
455 if (sms_debug & lvl) \ 432 if (sms_dbg & lvl) \
456 sms_printk(kern, fmt, ##arg); } while (0) 433 sms_printk(kern, fmt, ##arg); } while (0)
457 434
458#define sms_log(fmt, arg...) sms_printk(KERN_INFO, fmt, ##arg) 435#define sms_log(fmt, arg...) sms_printk(KERN_INFO, fmt, ##arg)
diff --git a/drivers/media/dvb/siano/smsdvb.c b/drivers/media/dvb/siano/smsdvb.c
index 2da953a4f4f5..ba080b95befb 100644
--- a/drivers/media/dvb/siano/smsdvb.c
+++ b/drivers/media/dvb/siano/smsdvb.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Driver for the Siano SMS1xxx USB dongle 2 * Driver for the Siano SMS1xxx USB dongle
3 * 3 *
4 * author: Anatoly Greenblat 4 * Author: Uri Shkolni
5 * 5 *
6 * Copyright (c), 2005-2008 Siano Mobile Silicon, Inc. 6 * Copyright (c), 2005-2008 Siano Mobile Silicon, Inc.
7 * 7 *
@@ -27,9 +27,33 @@
27 27
28DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); 28DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
29 29
30struct smsdvb_client_t {
31 struct list_head entry;
32
33 struct smscore_device_t *coredev;
34 struct smscore_client_t *smsclient;
35
36 struct dvb_adapter adapter;
37 struct dvb_demux demux;
38 struct dmxdev dmxdev;
39 struct dvb_frontend frontend;
40
41 fe_status_t fe_status;
42 int fe_ber, fe_snr, fe_unc, fe_signal_strength;
43
44 struct completion tune_done, stat_done;
45
46 /* todo: save freq/band instead whole struct */
47 struct dvb_frontend_parameters fe_params;
48};
49
30static struct list_head g_smsdvb_clients; 50static struct list_head g_smsdvb_clients;
31static struct mutex g_smsdvb_clientslock; 51static struct mutex g_smsdvb_clientslock;
32 52
53static int sms_dbg;
54module_param_named(debug, sms_dbg, int, 0644);
55MODULE_PARM_DESC(debug, "set debug level (info=1, adv=2 (or-able))");
56
33static int smsdvb_onresponse(void *context, struct smscore_buffer_t *cb) 57static int smsdvb_onresponse(void *context, struct smscore_buffer_t *cb)
34{ 58{
35 struct smsdvb_client_t *client = (struct smsdvb_client_t *) context; 59 struct smsdvb_client_t *client = (struct smsdvb_client_t *) context;
@@ -262,6 +286,7 @@ static int smsdvb_set_frontend(struct dvb_frontend *fe,
262 struct SmsMsgHdr_ST Msg; 286 struct SmsMsgHdr_ST Msg;
263 u32 Data[3]; 287 u32 Data[3];
264 } Msg; 288 } Msg;
289 int ret;
265 290
266 Msg.Msg.msgSrcId = DVBT_BDA_CONTROL_MSG_ID; 291 Msg.Msg.msgSrcId = DVBT_BDA_CONTROL_MSG_ID;
267 Msg.Msg.msgDstId = HIF_TASK; 292 Msg.Msg.msgDstId = HIF_TASK;
@@ -282,6 +307,24 @@ static int smsdvb_set_frontend(struct dvb_frontend *fe,
282 default: return -EINVAL; 307 default: return -EINVAL;
283 } 308 }
284 309
310 /* Disable LNA, if any. An error is returned if no LNA is present */
311 ret = sms_board_lna_control(client->coredev, 0);
312 if (ret == 0) {
313 fe_status_t status;
314
315 /* tune with LNA off at first */
316 ret = smsdvb_sendrequest_and_wait(client, &Msg, sizeof(Msg),
317 &client->tune_done);
318
319 smsdvb_read_status(fe, &status);
320
321 if (status & FE_HAS_LOCK)
322 return ret;
323
324 /* previous tune didnt lock - enable LNA and tune again */
325 sms_board_lna_control(client->coredev, 1);
326 }
327
285 return smsdvb_sendrequest_and_wait(client, &Msg, sizeof(Msg), 328 return smsdvb_sendrequest_and_wait(client, &Msg, sizeof(Msg),
286 &client->tune_done); 329 &client->tune_done);
287} 330}
@@ -329,7 +372,7 @@ static void smsdvb_release(struct dvb_frontend *fe)
329 372
330static struct dvb_frontend_ops smsdvb_fe_ops = { 373static struct dvb_frontend_ops smsdvb_fe_ops = {
331 .info = { 374 .info = {
332 .name = "Siano Mobile Digital SMS1xxx", 375 .name = "Siano Mobile Digital MDTV Receiver",
333 .type = FE_OFDM, 376 .type = FE_OFDM,
334 .frequency_min = 44250000, 377 .frequency_min = 44250000,
335 .frequency_max = 867250000, 378 .frequency_max = 867250000,
@@ -371,7 +414,7 @@ static int smsdvb_hotplug(struct smscore_device_t *coredev,
371 if (!arrival) 414 if (!arrival)
372 return 0; 415 return 0;
373 416
374 if (smscore_get_device_mode(coredev) != 4) { 417 if (smscore_get_device_mode(coredev) != DEVICE_MODE_DVBT_BDA) {
375 sms_err("SMS Device mode is not set for " 418 sms_err("SMS Device mode is not set for "
376 "DVB operation."); 419 "DVB operation.");
377 return 0; 420 return 0;
@@ -473,7 +516,7 @@ adapter_error:
473 return rc; 516 return rc;
474} 517}
475 518
476int smsdvb_register(void) 519int smsdvb_module_init(void)
477{ 520{
478 int rc; 521 int rc;
479 522
@@ -487,7 +530,7 @@ int smsdvb_register(void)
487 return rc; 530 return rc;
488} 531}
489 532
490void smsdvb_unregister(void) 533void smsdvb_module_exit(void)
491{ 534{
492 smscore_unregister_hotplug(smsdvb_hotplug); 535 smscore_unregister_hotplug(smsdvb_hotplug);
493 536
@@ -499,3 +542,10 @@ void smsdvb_unregister(void)
499 542
500 kmutex_unlock(&g_smsdvb_clientslock); 543 kmutex_unlock(&g_smsdvb_clientslock);
501} 544}
545
546module_init(smsdvb_module_init);
547module_exit(smsdvb_module_exit);
548
549MODULE_DESCRIPTION("SMS DVB subsystem adaptation module");
550MODULE_AUTHOR("Siano Mobile Silicon, INC. (uris@siano-ms.com)");
551MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/siano/smsusb.c b/drivers/media/dvb/siano/smsusb.c
index 5d7ca3417719..71c65f544c07 100644
--- a/drivers/media/dvb/siano/smsusb.c
+++ b/drivers/media/dvb/siano/smsusb.c
@@ -27,6 +27,10 @@
27#include "smscoreapi.h" 27#include "smscoreapi.h"
28#include "sms-cards.h" 28#include "sms-cards.h"
29 29
30static int sms_dbg;
31module_param_named(debug, sms_dbg, int, 0644);
32MODULE_PARM_DESC(debug, "set debug level (info=1, adv=2 (or-able))");
33
30#define USB1_BUFFER_SIZE 0x1000 34#define USB1_BUFFER_SIZE 0x1000
31#define USB2_BUFFER_SIZE 0x4000 35#define USB2_BUFFER_SIZE 0x4000
32 36
@@ -424,6 +428,7 @@ static int smsusb_probe(struct usb_interface *intf,
424 428
425 rc = smsusb_init_device(intf, id->driver_info); 429 rc = smsusb_init_device(intf, id->driver_info);
426 sms_info("rc %d", rc); 430 sms_info("rc %d", rc);
431 sms_board_load_modules(id->driver_info);
427 return rc; 432 return rc;
428} 433}
429 434
@@ -436,7 +441,7 @@ static int smsusb_suspend(struct usb_interface *intf, pm_message_t msg)
436{ 441{
437 struct smsusb_device_t *dev = 442 struct smsusb_device_t *dev =
438 (struct smsusb_device_t *)usb_get_intfdata(intf); 443 (struct smsusb_device_t *)usb_get_intfdata(intf);
439 printk(KERN_INFO "%s Entering status %d.\n", __func__, msg.event); 444 printk(KERN_INFO "%s: Entering status %d.\n", __func__, msg.event);
440 smsusb_stop_streaming(dev); 445 smsusb_stop_streaming(dev);
441 return 0; 446 return 0;
442} 447}
@@ -448,7 +453,7 @@ static int smsusb_resume(struct usb_interface *intf)
448 (struct smsusb_device_t *)usb_get_intfdata(intf); 453 (struct smsusb_device_t *)usb_get_intfdata(intf);
449 struct usb_device *udev = interface_to_usbdev(intf); 454 struct usb_device *udev = interface_to_usbdev(intf);
450 455
451 printk(KERN_INFO "%s Entering.\n", __func__); 456 printk(KERN_INFO "%s: Entering.\n", __func__);
452 usb_clear_halt(udev, usb_rcvbulkpipe(udev, 0x81)); 457 usb_clear_halt(udev, usb_rcvbulkpipe(udev, 0x81));
453 usb_clear_halt(udev, usb_rcvbulkpipe(udev, 0x02)); 458 usb_clear_halt(udev, usb_rcvbulkpipe(udev, 0x02));
454 459
@@ -463,9 +468,8 @@ static int smsusb_resume(struct usb_interface *intf)
463 intf->cur_altsetting->desc. 468 intf->cur_altsetting->desc.
464 bInterfaceNumber, 0); 469 bInterfaceNumber, 0);
465 if (rc < 0) { 470 if (rc < 0) {
466 printk(KERN_INFO 471 printk(KERN_INFO "%s usb_set_interface failed, "
467 "%s usb_set_interface failed, rc %d\n", 472 "rc %d\n", __func__, rc);
468 __func__, rc);
469 return rc; 473 return rc;
470 } 474 }
471 } 475 }
@@ -474,8 +478,55 @@ static int smsusb_resume(struct usb_interface *intf)
474 return 0; 478 return 0;
475} 479}
476 480
481struct usb_device_id smsusb_id_table[] = {
482#ifdef CONFIG_DVB_SIANO_SMS1XXX_SMS_IDS
483 { USB_DEVICE(0x187f, 0x0010),
484 .driver_info = SMS1XXX_BOARD_SIANO_STELLAR },
485 { USB_DEVICE(0x187f, 0x0100),
486 .driver_info = SMS1XXX_BOARD_SIANO_STELLAR },
487 { USB_DEVICE(0x187f, 0x0200),
488 .driver_info = SMS1XXX_BOARD_SIANO_NOVA_A },
489 { USB_DEVICE(0x187f, 0x0201),
490 .driver_info = SMS1XXX_BOARD_SIANO_NOVA_B },
491 { USB_DEVICE(0x187f, 0x0300),
492 .driver_info = SMS1XXX_BOARD_SIANO_VEGA },
493#endif
494 { USB_DEVICE(0x2040, 0x1700),
495 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_CATAMOUNT },
496 { USB_DEVICE(0x2040, 0x1800),
497 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_OKEMO_A },
498 { USB_DEVICE(0x2040, 0x1801),
499 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_OKEMO_B },
500 { USB_DEVICE(0x2040, 0x2000),
501 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD },
502 { USB_DEVICE(0x2040, 0x2009),
503 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD_R2 },
504 { USB_DEVICE(0x2040, 0x200a),
505 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD },
506 { USB_DEVICE(0x2040, 0x2010),
507 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD },
508 { USB_DEVICE(0x2040, 0x2011),
509 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD },
510 { USB_DEVICE(0x2040, 0x2019),
511 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD },
512 { USB_DEVICE(0x2040, 0x5500),
513 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
514 { USB_DEVICE(0x2040, 0x5510),
515 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
516 { USB_DEVICE(0x2040, 0x5520),
517 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
518 { USB_DEVICE(0x2040, 0x5530),
519 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
520 { USB_DEVICE(0x2040, 0x5580),
521 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
522 { USB_DEVICE(0x2040, 0x5590),
523 .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM },
524 { } /* Terminating entry */
525};
526MODULE_DEVICE_TABLE(usb, smsusb_id_table);
527
477static struct usb_driver smsusb_driver = { 528static struct usb_driver smsusb_driver = {
478 .name = "sms1xxx", 529 .name = "smsusb",
479 .probe = smsusb_probe, 530 .probe = smsusb_probe,
480 .disconnect = smsusb_disconnect, 531 .disconnect = smsusb_disconnect,
481 .id_table = smsusb_id_table, 532 .id_table = smsusb_id_table,
@@ -484,7 +535,7 @@ static struct usb_driver smsusb_driver = {
484 .resume = smsusb_resume, 535 .resume = smsusb_resume,
485}; 536};
486 537
487int smsusb_register(void) 538int smsusb_module_init(void)
488{ 539{
489 int rc = usb_register(&smsusb_driver); 540 int rc = usb_register(&smsusb_driver);
490 if (rc) 541 if (rc)
@@ -495,10 +546,16 @@ int smsusb_register(void)
495 return rc; 546 return rc;
496} 547}
497 548
498void smsusb_unregister(void) 549void smsusb_module_exit(void)
499{ 550{
500 sms_debug(""); 551 sms_debug("");
501 /* Regular USB Cleanup */ 552 /* Regular USB Cleanup */
502 usb_deregister(&smsusb_driver); 553 usb_deregister(&smsusb_driver);
503} 554}
504 555
556module_init(smsusb_module_init);
557module_exit(smsusb_module_exit);
558
559MODULE_DESCRIPTION("Driver for the Siano SMS1XXX USB dongle");
560MODULE_AUTHOR("Siano Mobile Silicon, INC. (uris@siano-ms.com)");
561MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/ttpci/Kconfig b/drivers/media/dvb/ttpci/Kconfig
index ab0bcd208c78..772990415f99 100644
--- a/drivers/media/dvb/ttpci/Kconfig
+++ b/drivers/media/dvb/ttpci/Kconfig
@@ -108,7 +108,7 @@ config DVB_BUDGET_CI
108 select DVB_STB6100 if !DVB_FE_CUSTOMISE 108 select DVB_STB6100 if !DVB_FE_CUSTOMISE
109 select DVB_LNBP21 if !DVB_FE_CUSTOMISE 109 select DVB_LNBP21 if !DVB_FE_CUSTOMISE
110 select DVB_TDA10023 if !DVB_FE_CUSTOMISE 110 select DVB_TDA10023 if !DVB_FE_CUSTOMISE
111 select MEDIA_TUNER_TDA827X if !MEDIA_TUNER_CUSTOMIZE 111 select MEDIA_TUNER_TDA827X if !MEDIA_TUNER_CUSTOMISE
112 select VIDEO_IR 112 select VIDEO_IR
113 help 113 help
114 Support for simple SAA7146 based DVB cards 114 Support for simple SAA7146 based DVB cards
diff --git a/drivers/media/dvb/ttpci/av7110.c b/drivers/media/dvb/ttpci/av7110.c
index aa1ff524256e..4624cee93e74 100644
--- a/drivers/media/dvb/ttpci/av7110.c
+++ b/drivers/media/dvb/ttpci/av7110.c
@@ -725,7 +725,7 @@ static int dvb_osd_ioctl(struct inode *inode, struct file *file,
725} 725}
726 726
727 727
728static struct file_operations dvb_osd_fops = { 728static const struct file_operations dvb_osd_fops = {
729 .owner = THIS_MODULE, 729 .owner = THIS_MODULE,
730 .ioctl = dvb_generic_ioctl, 730 .ioctl = dvb_generic_ioctl,
731 .open = dvb_generic_open, 731 .open = dvb_generic_open,
diff --git a/drivers/media/dvb/ttpci/av7110_av.c b/drivers/media/dvb/ttpci/av7110_av.c
index bdc62acf2099..e4d0900d5121 100644
--- a/drivers/media/dvb/ttpci/av7110_av.c
+++ b/drivers/media/dvb/ttpci/av7110_av.c
@@ -1456,7 +1456,7 @@ static int dvb_audio_release(struct inode *inode, struct file *file)
1456 * driver registration 1456 * driver registration
1457 ******************************************************************************/ 1457 ******************************************************************************/
1458 1458
1459static struct file_operations dvb_video_fops = { 1459static const struct file_operations dvb_video_fops = {
1460 .owner = THIS_MODULE, 1460 .owner = THIS_MODULE,
1461 .write = dvb_video_write, 1461 .write = dvb_video_write,
1462 .ioctl = dvb_generic_ioctl, 1462 .ioctl = dvb_generic_ioctl,
@@ -1474,7 +1474,7 @@ static struct dvb_device dvbdev_video = {
1474 .kernel_ioctl = dvb_video_ioctl, 1474 .kernel_ioctl = dvb_video_ioctl,
1475}; 1475};
1476 1476
1477static struct file_operations dvb_audio_fops = { 1477static const struct file_operations dvb_audio_fops = {
1478 .owner = THIS_MODULE, 1478 .owner = THIS_MODULE,
1479 .write = dvb_audio_write, 1479 .write = dvb_audio_write,
1480 .ioctl = dvb_generic_ioctl, 1480 .ioctl = dvb_generic_ioctl,
diff --git a/drivers/media/dvb/ttpci/av7110_ca.c b/drivers/media/dvb/ttpci/av7110_ca.c
index 261135ded481..c7a65b1544a3 100644
--- a/drivers/media/dvb/ttpci/av7110_ca.c
+++ b/drivers/media/dvb/ttpci/av7110_ca.c
@@ -345,7 +345,7 @@ static ssize_t dvb_ca_read(struct file *file, char __user *buf,
345 return ci_ll_read(&av7110->ci_rbuffer, file, buf, count, ppos); 345 return ci_ll_read(&av7110->ci_rbuffer, file, buf, count, ppos);
346} 346}
347 347
348static struct file_operations dvb_ca_fops = { 348static const struct file_operations dvb_ca_fops = {
349 .owner = THIS_MODULE, 349 .owner = THIS_MODULE,
350 .read = dvb_ca_read, 350 .read = dvb_ca_read,
351 .write = dvb_ca_write, 351 .write = dvb_ca_write,
diff --git a/drivers/media/dvb/ttpci/av7110_v4l.c b/drivers/media/dvb/ttpci/av7110_v4l.c
index c5b9c70563dc..2210cff738e6 100644
--- a/drivers/media/dvb/ttpci/av7110_v4l.c
+++ b/drivers/media/dvb/ttpci/av7110_v4l.c
@@ -316,253 +316,261 @@ static int av7110_dvb_c_switch(struct saa7146_fh *fh)
316 return 0; 316 return 0;
317} 317}
318 318
319static long av7110_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg) 319static int vidioc_g_tuner(struct file *file, void *fh, struct v4l2_tuner *t)
320{ 320{
321 struct saa7146_dev *dev = fh->dev; 321 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
322 struct av7110 *av7110 = (struct av7110*) dev->ext_priv; 322 struct av7110 *av7110 = (struct av7110 *)dev->ext_priv;
323 dprintk(4, "saa7146_dev: %p\n", dev); 323 u16 stereo_det;
324 s8 stereo;
324 325
325 switch (cmd) { 326 dprintk(2, "VIDIOC_G_TUNER: %d\n", t->index);
326 case VIDIOC_G_TUNER:
327 {
328 struct v4l2_tuner *t = arg;
329 u16 stereo_det;
330 s8 stereo;
331 327
332 dprintk(2, "VIDIOC_G_TUNER: %d\n", t->index); 328 if (!av7110->analog_tuner_flags || t->index != 0)
329 return -EINVAL;
333 330
334 if (!av7110->analog_tuner_flags || t->index != 0) 331 memset(t, 0, sizeof(*t));
335 return -EINVAL; 332 strcpy((char *)t->name, "Television");
333
334 t->type = V4L2_TUNER_ANALOG_TV;
335 t->capability = V4L2_TUNER_CAP_NORM | V4L2_TUNER_CAP_STEREO |
336 V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2 | V4L2_TUNER_CAP_SAP;
337 t->rangelow = 772; /* 48.25 MHZ / 62.5 kHz = 772, see fi1216mk2-specs, page 2 */
338 t->rangehigh = 13684; /* 855.25 MHz / 62.5 kHz = 13684 */
339 /* FIXME: add the real signal strength here */
340 t->signal = 0xffff;
341 t->afc = 0;
342
343 /* FIXME: standard / stereo detection is still broken */
344 msp_readreg(av7110, MSP_RD_DEM, 0x007e, &stereo_det);
345 dprintk(1, "VIDIOC_G_TUNER: msp3400 TV standard detection: 0x%04x\n", stereo_det);
346 msp_readreg(av7110, MSP_RD_DSP, 0x0018, &stereo_det);
347 dprintk(1, "VIDIOC_G_TUNER: msp3400 stereo detection: 0x%04x\n", stereo_det);
348 stereo = (s8)(stereo_det >> 8);
349 if (stereo > 0x10) {
350 /* stereo */
351 t->rxsubchans = V4L2_TUNER_SUB_STEREO | V4L2_TUNER_SUB_MONO;
352 t->audmode = V4L2_TUNER_MODE_STEREO;
353 } else if (stereo < -0x10) {
354 /* bilingual */
355 t->rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
356 t->audmode = V4L2_TUNER_MODE_LANG1;
357 } else /* mono */
358 t->rxsubchans = V4L2_TUNER_SUB_MONO;
336 359
337 memset(t, 0, sizeof(*t)); 360 return 0;
338 strcpy((char *)t->name, "Television"); 361}
339
340 t->type = V4L2_TUNER_ANALOG_TV;
341 t->capability = V4L2_TUNER_CAP_NORM | V4L2_TUNER_CAP_STEREO |
342 V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2 | V4L2_TUNER_CAP_SAP;
343 t->rangelow = 772; /* 48.25 MHZ / 62.5 kHz = 772, see fi1216mk2-specs, page 2 */
344 t->rangehigh = 13684; /* 855.25 MHz / 62.5 kHz = 13684 */
345 /* FIXME: add the real signal strength here */
346 t->signal = 0xffff;
347 t->afc = 0;
348
349 // FIXME: standard / stereo detection is still broken
350 msp_readreg(av7110, MSP_RD_DEM, 0x007e, &stereo_det);
351 dprintk(1, "VIDIOC_G_TUNER: msp3400 TV standard detection: 0x%04x\n", stereo_det);
352 msp_readreg(av7110, MSP_RD_DSP, 0x0018, &stereo_det);
353 dprintk(1, "VIDIOC_G_TUNER: msp3400 stereo detection: 0x%04x\n", stereo_det);
354 stereo = (s8)(stereo_det >> 8);
355 if (stereo > 0x10) {
356 /* stereo */
357 t->rxsubchans = V4L2_TUNER_SUB_STEREO | V4L2_TUNER_SUB_MONO;
358 t->audmode = V4L2_TUNER_MODE_STEREO;
359 }
360 else if (stereo < -0x10) {
361 /* bilingual */
362 t->rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
363 t->audmode = V4L2_TUNER_MODE_LANG1;
364 }
365 else /* mono */
366 t->rxsubchans = V4L2_TUNER_SUB_MONO;
367 362
368 return 0; 363static int vidioc_s_tuner(struct file *file, void *fh, struct v4l2_tuner *t)
369 } 364{
370 case VIDIOC_S_TUNER: 365 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
371 { 366 struct av7110 *av7110 = (struct av7110 *)dev->ext_priv;
372 struct v4l2_tuner *t = arg; 367 u16 fm_matrix, src;
373 u16 fm_matrix, src; 368 dprintk(2, "VIDIOC_S_TUNER: %d\n", t->index);
374 dprintk(2, "VIDIOC_S_TUNER: %d\n", t->index);
375 369
376 if (!av7110->analog_tuner_flags || av7110->current_input != 1) 370 if (!av7110->analog_tuner_flags || av7110->current_input != 1)
377 return -EINVAL; 371 return -EINVAL;
378 372
379 switch (t->audmode) { 373 switch (t->audmode) {
380 case V4L2_TUNER_MODE_STEREO: 374 case V4L2_TUNER_MODE_STEREO:
381 dprintk(2, "VIDIOC_S_TUNER: V4L2_TUNER_MODE_STEREO\n"); 375 dprintk(2, "VIDIOC_S_TUNER: V4L2_TUNER_MODE_STEREO\n");
382 fm_matrix = 0x3001; // stereo 376 fm_matrix = 0x3001; /* stereo */
383 src = 0x0020; 377 src = 0x0020;
384 break; 378 break;
385 case V4L2_TUNER_MODE_LANG1_LANG2: 379 case V4L2_TUNER_MODE_LANG1_LANG2:
386 dprintk(2, "VIDIOC_S_TUNER: V4L2_TUNER_MODE_LANG1_LANG2\n"); 380 dprintk(2, "VIDIOC_S_TUNER: V4L2_TUNER_MODE_LANG1_LANG2\n");
387 fm_matrix = 0x3000; // bilingual 381 fm_matrix = 0x3000; /* bilingual */
388 src = 0x0020; 382 src = 0x0020;
389 break; 383 break;
390 case V4L2_TUNER_MODE_LANG1: 384 case V4L2_TUNER_MODE_LANG1:
391 dprintk(2, "VIDIOC_S_TUNER: V4L2_TUNER_MODE_LANG1\n"); 385 dprintk(2, "VIDIOC_S_TUNER: V4L2_TUNER_MODE_LANG1\n");
392 fm_matrix = 0x3000; // mono 386 fm_matrix = 0x3000; /* mono */
393 src = 0x0000; 387 src = 0x0000;
394 break; 388 break;
395 case V4L2_TUNER_MODE_LANG2: 389 case V4L2_TUNER_MODE_LANG2:
396 dprintk(2, "VIDIOC_S_TUNER: V4L2_TUNER_MODE_LANG2\n"); 390 dprintk(2, "VIDIOC_S_TUNER: V4L2_TUNER_MODE_LANG2\n");
397 fm_matrix = 0x3000; // mono 391 fm_matrix = 0x3000; /* mono */
398 src = 0x0010; 392 src = 0x0010;
399 break; 393 break;
400 default: /* case V4L2_TUNER_MODE_MONO: */ 394 default: /* case V4L2_TUNER_MODE_MONO: */
401 dprintk(2, "VIDIOC_S_TUNER: TDA9840_SET_MONO\n"); 395 dprintk(2, "VIDIOC_S_TUNER: TDA9840_SET_MONO\n");
402 fm_matrix = 0x3000; // mono 396 fm_matrix = 0x3000; /* mono */
403 src = 0x0030; 397 src = 0x0030;
404 break; 398 break;
405 }
406 msp_writereg(av7110, MSP_WR_DSP, 0x000e, fm_matrix);
407 msp_writereg(av7110, MSP_WR_DSP, 0x0008, src);
408 msp_writereg(av7110, MSP_WR_DSP, 0x0009, src);
409 msp_writereg(av7110, MSP_WR_DSP, 0x000a, src);
410 return 0;
411 } 399 }
412 case VIDIOC_G_FREQUENCY: 400 msp_writereg(av7110, MSP_WR_DSP, 0x000e, fm_matrix);
413 { 401 msp_writereg(av7110, MSP_WR_DSP, 0x0008, src);
414 struct v4l2_frequency *f = arg; 402 msp_writereg(av7110, MSP_WR_DSP, 0x0009, src);
403 msp_writereg(av7110, MSP_WR_DSP, 0x000a, src);
404 return 0;
405}
415 406
416 dprintk(2, "VIDIOC_G_FREQ: freq:0x%08x.\n", f->frequency); 407static int vidioc_g_frequency(struct file *file, void *fh, struct v4l2_frequency *f)
408{
409 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
410 struct av7110 *av7110 = (struct av7110 *)dev->ext_priv;
417 411
418 if (!av7110->analog_tuner_flags || av7110->current_input != 1) 412 dprintk(2, "VIDIOC_G_FREQ: freq:0x%08x.\n", f->frequency);
419 return -EINVAL;
420 413
421 memset(f, 0, sizeof(*f)); 414 if (!av7110->analog_tuner_flags || av7110->current_input != 1)
422 f->type = V4L2_TUNER_ANALOG_TV; 415 return -EINVAL;
423 f->frequency = av7110->current_freq;
424 return 0;
425 }
426 case VIDIOC_S_FREQUENCY:
427 {
428 struct v4l2_frequency *f = arg;
429 416
430 dprintk(2, "VIDIOC_S_FREQUENCY: freq:0x%08x.\n", f->frequency); 417 memset(f, 0, sizeof(*f));
418 f->type = V4L2_TUNER_ANALOG_TV;
419 f->frequency = av7110->current_freq;
420 return 0;
421}
431 422
432 if (!av7110->analog_tuner_flags || av7110->current_input != 1) 423static int vidioc_s_frequency(struct file *file, void *fh, struct v4l2_frequency *f)
433 return -EINVAL; 424{
425 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
426 struct av7110 *av7110 = (struct av7110 *)dev->ext_priv;
434 427
435 if (V4L2_TUNER_ANALOG_TV != f->type) 428 dprintk(2, "VIDIOC_S_FREQUENCY: freq:0x%08x.\n", f->frequency);
436 return -EINVAL;
437 429
438 msp_writereg(av7110, MSP_WR_DSP, 0x0000, 0xffe0); // fast mute 430 if (!av7110->analog_tuner_flags || av7110->current_input != 1)
439 msp_writereg(av7110, MSP_WR_DSP, 0x0007, 0xffe0); 431 return -EINVAL;
440 432
441 /* tune in desired frequency */ 433 if (V4L2_TUNER_ANALOG_TV != f->type)
442 if (av7110->analog_tuner_flags & ANALOG_TUNER_VES1820) { 434 return -EINVAL;
443 ves1820_set_tv_freq(dev, f->frequency);
444 } else if (av7110->analog_tuner_flags & ANALOG_TUNER_STV0297) {
445 stv0297_set_tv_freq(dev, f->frequency);
446 }
447 av7110->current_freq = f->frequency;
448 435
449 msp_writereg(av7110, MSP_WR_DSP, 0x0015, 0x003f); // start stereo detection 436 msp_writereg(av7110, MSP_WR_DSP, 0x0000, 0xffe0); /* fast mute */
450 msp_writereg(av7110, MSP_WR_DSP, 0x0015, 0x0000); 437 msp_writereg(av7110, MSP_WR_DSP, 0x0007, 0xffe0);
451 msp_writereg(av7110, MSP_WR_DSP, 0x0000, 0x4f00); // loudspeaker + headphone
452 msp_writereg(av7110, MSP_WR_DSP, 0x0007, 0x4f00); // SCART 1 volume
453 return 0;
454 }
455 case VIDIOC_ENUMINPUT:
456 {
457 struct v4l2_input *i = arg;
458 438
459 dprintk(2, "VIDIOC_ENUMINPUT: %d\n", i->index); 439 /* tune in desired frequency */
440 if (av7110->analog_tuner_flags & ANALOG_TUNER_VES1820)
441 ves1820_set_tv_freq(dev, f->frequency);
442 else if (av7110->analog_tuner_flags & ANALOG_TUNER_STV0297)
443 stv0297_set_tv_freq(dev, f->frequency);
444 av7110->current_freq = f->frequency;
460 445
461 if (av7110->analog_tuner_flags) { 446 msp_writereg(av7110, MSP_WR_DSP, 0x0015, 0x003f); /* start stereo detection */
462 if (i->index < 0 || i->index >= 4) 447 msp_writereg(av7110, MSP_WR_DSP, 0x0015, 0x0000);
463 return -EINVAL; 448 msp_writereg(av7110, MSP_WR_DSP, 0x0000, 0x4f00); /* loudspeaker + headphone */
464 } else { 449 msp_writereg(av7110, MSP_WR_DSP, 0x0007, 0x4f00); /* SCART 1 volume */
465 if (i->index != 0) 450 return 0;
466 return -EINVAL; 451}
467 }
468 452
469 memcpy(i, &inputs[i->index], sizeof(struct v4l2_input)); 453static int vidioc_enum_input(struct file *file, void *fh, struct v4l2_input *i)
454{
455 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
456 struct av7110 *av7110 = (struct av7110 *)dev->ext_priv;
470 457
471 return 0; 458 dprintk(2, "VIDIOC_ENUMINPUT: %d\n", i->index);
459
460 if (av7110->analog_tuner_flags) {
461 if (i->index < 0 || i->index >= 4)
462 return -EINVAL;
463 } else {
464 if (i->index != 0)
465 return -EINVAL;
472 } 466 }
473 case VIDIOC_G_INPUT: 467
474 { 468 memcpy(i, &inputs[i->index], sizeof(struct v4l2_input));
475 int *input = (int *)arg; 469
476 *input = av7110->current_input; 470 return 0;
477 dprintk(2, "VIDIOC_G_INPUT: %d\n", *input); 471}
472
473static int vidioc_g_input(struct file *file, void *fh, unsigned int *input)
474{
475 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
476 struct av7110 *av7110 = (struct av7110 *)dev->ext_priv;
477
478 *input = av7110->current_input;
479 dprintk(2, "VIDIOC_G_INPUT: %d\n", *input);
480 return 0;
481}
482
483static int vidioc_s_input(struct file *file, void *fh, unsigned int input)
484{
485 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
486 struct av7110 *av7110 = (struct av7110 *)dev->ext_priv;
487
488 dprintk(2, "VIDIOC_S_INPUT: %d\n", input);
489
490 if (!av7110->analog_tuner_flags)
478 return 0; 491 return 0;
479 }
480 case VIDIOC_S_INPUT:
481 {
482 int input = *(int *)arg;
483 492
484 dprintk(2, "VIDIOC_S_INPUT: %d\n", input); 493 if (input < 0 || input >= 4)
494 return -EINVAL;
485 495
486 if (!av7110->analog_tuner_flags) 496 av7110->current_input = input;
487 return 0; 497 return av7110_dvb_c_switch(fh);
498}
488 499
489 if (input < 0 || input >= 4) 500static int vidioc_g_audio(struct file *file, void *fh, struct v4l2_audio *a)
490 return -EINVAL; 501{
502 dprintk(2, "VIDIOC_G_AUDIO: %d\n", a->index);
503 if (a->index != 0)
504 return -EINVAL;
505 memcpy(a, &msp3400_v4l2_audio, sizeof(struct v4l2_audio));
506 return 0;
507}
491 508
492 av7110->current_input = input; 509static int vidioc_s_audio(struct file *file, void *fh, struct v4l2_audio *a)
493 return av7110_dvb_c_switch(fh); 510{
494 } 511 dprintk(2, "VIDIOC_S_AUDIO: %d\n", a->index);
495 case VIDIOC_G_AUDIO: 512 return 0;
496 { 513}
497 struct v4l2_audio *a = arg;
498 514
499 dprintk(2, "VIDIOC_G_AUDIO: %d\n", a->index); 515static int vidioc_g_sliced_vbi_cap(struct file *file, void *fh,
500 if (a->index != 0) 516 struct v4l2_sliced_vbi_cap *cap)
501 return -EINVAL; 517{
502 memcpy(a, &msp3400_v4l2_audio, sizeof(struct v4l2_audio)); 518 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
503 break; 519 struct av7110 *av7110 = (struct av7110 *)dev->ext_priv;
504 } 520
505 case VIDIOC_S_AUDIO: 521 dprintk(2, "VIDIOC_G_SLICED_VBI_CAP\n");
506 { 522 if (cap->type != V4L2_BUF_TYPE_SLICED_VBI_OUTPUT)
507 struct v4l2_audio *a = arg; 523 return -EINVAL;
508 dprintk(2, "VIDIOC_S_AUDIO: %d\n", a->index); 524 if (FW_VERSION(av7110->arm_app) >= 0x2623) {
509 break; 525 cap->service_set = V4L2_SLICED_WSS_625;
510 } 526 cap->service_lines[0][23] = V4L2_SLICED_WSS_625;
511 case VIDIOC_G_SLICED_VBI_CAP:
512 {
513 struct v4l2_sliced_vbi_cap *cap = arg;
514 dprintk(2, "VIDIOC_G_SLICED_VBI_CAP\n");
515 memset(cap, 0, sizeof *cap);
516 if (FW_VERSION(av7110->arm_app) >= 0x2623) {
517 cap->service_set = V4L2_SLICED_WSS_625;
518 cap->service_lines[0][23] = V4L2_SLICED_WSS_625;
519 }
520 break;
521 }
522 case VIDIOC_G_FMT:
523 {
524 struct v4l2_format *f = arg;
525 dprintk(2, "VIDIOC_G_FMT:\n");
526 if (f->type != V4L2_BUF_TYPE_SLICED_VBI_OUTPUT ||
527 FW_VERSION(av7110->arm_app) < 0x2623)
528 return -EAGAIN; /* handled by core driver */
529 memset(&f->fmt.sliced, 0, sizeof f->fmt.sliced);
530 if (av7110->wssMode) {
531 f->fmt.sliced.service_set = V4L2_SLICED_WSS_625;
532 f->fmt.sliced.service_lines[0][23] = V4L2_SLICED_WSS_625;
533 f->fmt.sliced.io_size = sizeof (struct v4l2_sliced_vbi_data);
534 }
535 break;
536 } 527 }
537 case VIDIOC_S_FMT: 528 return 0;
538 { 529}
539 struct v4l2_format *f = arg; 530
540 dprintk(2, "VIDIOC_S_FMT\n"); 531static int vidioc_g_fmt_sliced_vbi_out(struct file *file, void *fh,
541 if (f->type != V4L2_BUF_TYPE_SLICED_VBI_OUTPUT || 532 struct v4l2_format *f)
542 FW_VERSION(av7110->arm_app) < 0x2623) 533{
543 return -EAGAIN; /* handled by core driver */ 534 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
544 if (f->fmt.sliced.service_set != V4L2_SLICED_WSS_625 && 535 struct av7110 *av7110 = (struct av7110 *)dev->ext_priv;
545 f->fmt.sliced.service_lines[0][23] != V4L2_SLICED_WSS_625) { 536
546 memset(&f->fmt.sliced, 0, sizeof f->fmt.sliced); 537 dprintk(2, "VIDIOC_G_FMT:\n");
547 /* WSS controlled by firmware */ 538 if (FW_VERSION(av7110->arm_app) < 0x2623)
548 av7110->wssMode = 0; 539 return -EINVAL;
549 av7110->wssData = 0; 540 memset(&f->fmt.sliced, 0, sizeof f->fmt.sliced);
550 return av7110_fw_cmd(av7110, COMTYPE_ENCODER, 541 if (av7110->wssMode) {
551 SetWSSConfig, 1, 0); 542 f->fmt.sliced.service_set = V4L2_SLICED_WSS_625;
552 } else { 543 f->fmt.sliced.service_lines[0][23] = V4L2_SLICED_WSS_625;
553 memset(&f->fmt.sliced, 0, sizeof f->fmt.sliced); 544 f->fmt.sliced.io_size = sizeof(struct v4l2_sliced_vbi_data);
554 f->fmt.sliced.service_set = V4L2_SLICED_WSS_625;
555 f->fmt.sliced.service_lines[0][23] = V4L2_SLICED_WSS_625;
556 f->fmt.sliced.io_size = sizeof (struct v4l2_sliced_vbi_data);
557 /* WSS controlled by userspace */
558 av7110->wssMode = 1;
559 av7110->wssData = 0;
560 }
561 break;
562 } 545 }
563 default: 546 return 0;
564 printk("no such ioctl\n"); 547}
565 return -ENOIOCTLCMD; 548
549static int vidioc_s_fmt_sliced_vbi_out(struct file *file, void *fh,
550 struct v4l2_format *f)
551{
552 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
553 struct av7110 *av7110 = (struct av7110 *)dev->ext_priv;
554
555 dprintk(2, "VIDIOC_S_FMT\n");
556 if (FW_VERSION(av7110->arm_app) < 0x2623)
557 return -EINVAL;
558 if (f->fmt.sliced.service_set != V4L2_SLICED_WSS_625 &&
559 f->fmt.sliced.service_lines[0][23] != V4L2_SLICED_WSS_625) {
560 memset(&f->fmt.sliced, 0, sizeof(f->fmt.sliced));
561 /* WSS controlled by firmware */
562 av7110->wssMode = 0;
563 av7110->wssData = 0;
564 return av7110_fw_cmd(av7110, COMTYPE_ENCODER,
565 SetWSSConfig, 1, 0);
566 } else {
567 memset(&f->fmt.sliced, 0, sizeof(f->fmt.sliced));
568 f->fmt.sliced.service_set = V4L2_SLICED_WSS_625;
569 f->fmt.sliced.service_lines[0][23] = V4L2_SLICED_WSS_625;
570 f->fmt.sliced.io_size = sizeof(struct v4l2_sliced_vbi_data);
571 /* WSS controlled by userspace */
572 av7110->wssMode = 1;
573 av7110->wssData = 0;
566 } 574 }
567 return 0; 575 return 0;
568} 576}
@@ -609,22 +617,6 @@ static ssize_t av7110_vbi_write(struct file *file, const char __user *data, size
609 * INITIALIZATION 617 * INITIALIZATION
610 ****************************************************************************/ 618 ****************************************************************************/
611 619
612static struct saa7146_extension_ioctls ioctls[] = {
613 { VIDIOC_ENUMINPUT, SAA7146_EXCLUSIVE },
614 { VIDIOC_G_INPUT, SAA7146_EXCLUSIVE },
615 { VIDIOC_S_INPUT, SAA7146_EXCLUSIVE },
616 { VIDIOC_G_FREQUENCY, SAA7146_EXCLUSIVE },
617 { VIDIOC_S_FREQUENCY, SAA7146_EXCLUSIVE },
618 { VIDIOC_G_TUNER, SAA7146_EXCLUSIVE },
619 { VIDIOC_S_TUNER, SAA7146_EXCLUSIVE },
620 { VIDIOC_G_AUDIO, SAA7146_EXCLUSIVE },
621 { VIDIOC_S_AUDIO, SAA7146_EXCLUSIVE },
622 { VIDIOC_G_SLICED_VBI_CAP, SAA7146_EXCLUSIVE },
623 { VIDIOC_G_FMT, SAA7146_BEFORE },
624 { VIDIOC_S_FMT, SAA7146_BEFORE },
625 { 0, 0 }
626};
627
628static u8 saa7113_init_regs[] = { 620static u8 saa7113_init_regs[] = {
629 0x02, 0xd0, 621 0x02, 0xd0,
630 0x03, 0x23, 622 0x03, 0x23,
@@ -788,20 +780,34 @@ int av7110_init_analog_module(struct av7110 *av7110)
788int av7110_init_v4l(struct av7110 *av7110) 780int av7110_init_v4l(struct av7110 *av7110)
789{ 781{
790 struct saa7146_dev* dev = av7110->dev; 782 struct saa7146_dev* dev = av7110->dev;
783 struct saa7146_ext_vv *vv_data;
791 int ret; 784 int ret;
792 785
793 /* special case DVB-C: these cards have an analog tuner 786 /* special case DVB-C: these cards have an analog tuner
794 plus need some special handling, so we have separate 787 plus need some special handling, so we have separate
795 saa7146_ext_vv data for these... */ 788 saa7146_ext_vv data for these... */
796 if (av7110->analog_tuner_flags) 789 if (av7110->analog_tuner_flags)
797 ret = saa7146_vv_init(dev, &av7110_vv_data_c); 790 vv_data = &av7110_vv_data_c;
798 else 791 else
799 ret = saa7146_vv_init(dev, &av7110_vv_data_st); 792 vv_data = &av7110_vv_data_st;
793 ret = saa7146_vv_init(dev, vv_data);
800 794
801 if (ret) { 795 if (ret) {
802 ERR(("cannot init capture device. skipping.\n")); 796 ERR(("cannot init capture device. skipping.\n"));
803 return -ENODEV; 797 return -ENODEV;
804 } 798 }
799 vv_data->ops.vidioc_enum_input = vidioc_enum_input;
800 vv_data->ops.vidioc_g_input = vidioc_g_input;
801 vv_data->ops.vidioc_s_input = vidioc_s_input;
802 vv_data->ops.vidioc_g_tuner = vidioc_g_tuner;
803 vv_data->ops.vidioc_s_tuner = vidioc_s_tuner;
804 vv_data->ops.vidioc_g_frequency = vidioc_g_frequency;
805 vv_data->ops.vidioc_s_frequency = vidioc_s_frequency;
806 vv_data->ops.vidioc_g_audio = vidioc_g_audio;
807 vv_data->ops.vidioc_s_audio = vidioc_s_audio;
808 vv_data->ops.vidioc_g_sliced_vbi_cap = vidioc_g_sliced_vbi_cap;
809 vv_data->ops.vidioc_g_fmt_sliced_vbi_out = vidioc_g_fmt_sliced_vbi_out;
810 vv_data->ops.vidioc_s_fmt_sliced_vbi_out = vidioc_s_fmt_sliced_vbi_out;
805 811
806 if (saa7146_register_device(&av7110->v4l_dev, dev, "av7110", VFL_TYPE_GRABBER)) { 812 if (saa7146_register_device(&av7110->v4l_dev, dev, "av7110", VFL_TYPE_GRABBER)) {
807 ERR(("cannot register capture device. skipping.\n")); 813 ERR(("cannot register capture device. skipping.\n"));
@@ -900,9 +906,6 @@ static struct saa7146_ext_vv av7110_vv_data_st = {
900 .num_stds = ARRAY_SIZE(standard), 906 .num_stds = ARRAY_SIZE(standard),
901 .std_callback = &std_callback, 907 .std_callback = &std_callback,
902 908
903 .ioctls = &ioctls[0],
904 .ioctl = av7110_ioctl,
905
906 .vbi_fops.open = av7110_vbi_reset, 909 .vbi_fops.open = av7110_vbi_reset,
907 .vbi_fops.release = av7110_vbi_reset, 910 .vbi_fops.release = av7110_vbi_reset,
908 .vbi_fops.write = av7110_vbi_write, 911 .vbi_fops.write = av7110_vbi_write,
@@ -918,9 +921,6 @@ static struct saa7146_ext_vv av7110_vv_data_c = {
918 .num_stds = ARRAY_SIZE(standard), 921 .num_stds = ARRAY_SIZE(standard),
919 .std_callback = &std_callback, 922 .std_callback = &std_callback,
920 923
921 .ioctls = &ioctls[0],
922 .ioctl = av7110_ioctl,
923
924 .vbi_fops.open = av7110_vbi_reset, 924 .vbi_fops.open = av7110_vbi_reset,
925 .vbi_fops.release = av7110_vbi_reset, 925 .vbi_fops.release = av7110_vbi_reset,
926 .vbi_fops.write = av7110_vbi_write, 926 .vbi_fops.write = av7110_vbi_write,
diff --git a/drivers/media/dvb/ttpci/budget-av.c b/drivers/media/dvb/ttpci/budget-av.c
index 4182121d7e5d..855fe74b640b 100644
--- a/drivers/media/dvb/ttpci/budget-av.c
+++ b/drivers/media/dvb/ttpci/budget-av.c
@@ -1404,6 +1404,41 @@ static int budget_av_detach(struct saa7146_dev *dev)
1404 return err; 1404 return err;
1405} 1405}
1406 1406
1407#define KNC1_INPUTS 2
1408static struct v4l2_input knc1_inputs[KNC1_INPUTS] = {
1409 {0, "Composite", V4L2_INPUT_TYPE_TUNER, 1, 0, V4L2_STD_PAL_BG | V4L2_STD_NTSC_M, 0},
1410 {1, "S-Video", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG | V4L2_STD_NTSC_M, 0},
1411};
1412
1413static int vidioc_enum_input(struct file *file, void *fh, struct v4l2_input *i)
1414{
1415 dprintk(1, "VIDIOC_ENUMINPUT %d.\n", i->index);
1416 if (i->index < 0 || i->index >= KNC1_INPUTS)
1417 return -EINVAL;
1418 memcpy(i, &knc1_inputs[i->index], sizeof(struct v4l2_input));
1419 return 0;
1420}
1421
1422static int vidioc_g_input(struct file *file, void *fh, unsigned int *i)
1423{
1424 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
1425 struct budget_av *budget_av = (struct budget_av *)dev->ext_priv;
1426
1427 *i = budget_av->cur_input;
1428
1429 dprintk(1, "VIDIOC_G_INPUT %d.\n", *i);
1430 return 0;
1431}
1432
1433static int vidioc_s_input(struct file *file, void *fh, unsigned int input)
1434{
1435 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
1436 struct budget_av *budget_av = (struct budget_av *)dev->ext_priv;
1437
1438 dprintk(1, "VIDIOC_S_INPUT %d.\n", input);
1439 return saa7113_setinput(budget_av, input);
1440}
1441
1407static struct saa7146_ext_vv vv_data; 1442static struct saa7146_ext_vv vv_data;
1408 1443
1409static int budget_av_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_data *info) 1444static int budget_av_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_data *info)
@@ -1442,6 +1477,9 @@ static int budget_av_attach(struct saa7146_dev *dev, struct saa7146_pci_extensio
1442 ERR(("cannot init vv subsystem.\n")); 1477 ERR(("cannot init vv subsystem.\n"));
1443 return err; 1478 return err;
1444 } 1479 }
1480 vv_data.ops.vidioc_enum_input = vidioc_enum_input;
1481 vv_data.ops.vidioc_g_input = vidioc_g_input;
1482 vv_data.ops.vidioc_s_input = vidioc_s_input;
1445 1483
1446 if ((err = saa7146_register_device(&budget_av->vd, dev, "knc1", VFL_TYPE_GRABBER))) { 1484 if ((err = saa7146_register_device(&budget_av->vd, dev, "knc1", VFL_TYPE_GRABBER))) {
1447 /* fixme: proper cleanup here */ 1485 /* fixme: proper cleanup here */
@@ -1480,54 +1518,6 @@ static int budget_av_attach(struct saa7146_dev *dev, struct saa7146_pci_extensio
1480 return 0; 1518 return 0;
1481} 1519}
1482 1520
1483#define KNC1_INPUTS 2
1484static struct v4l2_input knc1_inputs[KNC1_INPUTS] = {
1485 {0, "Composite", V4L2_INPUT_TYPE_TUNER, 1, 0, V4L2_STD_PAL_BG | V4L2_STD_NTSC_M, 0},
1486 {1, "S-Video", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG | V4L2_STD_NTSC_M, 0},
1487};
1488
1489static struct saa7146_extension_ioctls ioctls[] = {
1490 {VIDIOC_ENUMINPUT, SAA7146_EXCLUSIVE},
1491 {VIDIOC_G_INPUT, SAA7146_EXCLUSIVE},
1492 {VIDIOC_S_INPUT, SAA7146_EXCLUSIVE},
1493 {0, 0}
1494};
1495
1496static long av_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
1497{
1498 struct saa7146_dev *dev = fh->dev;
1499 struct budget_av *budget_av = (struct budget_av *) dev->ext_priv;
1500
1501 switch (cmd) {
1502 case VIDIOC_ENUMINPUT:{
1503 struct v4l2_input *i = arg;
1504
1505 dprintk(1, "VIDIOC_ENUMINPUT %d.\n", i->index);
1506 if (i->index < 0 || i->index >= KNC1_INPUTS) {
1507 return -EINVAL;
1508 }
1509 memcpy(i, &knc1_inputs[i->index], sizeof(struct v4l2_input));
1510 return 0;
1511 }
1512 case VIDIOC_G_INPUT:{
1513 int *input = (int *) arg;
1514
1515 *input = budget_av->cur_input;
1516
1517 dprintk(1, "VIDIOC_G_INPUT %d.\n", *input);
1518 return 0;
1519 }
1520 case VIDIOC_S_INPUT:{
1521 int input = *(int *) arg;
1522 dprintk(1, "VIDIOC_S_INPUT %d.\n", input);
1523 return saa7113_setinput(budget_av, input);
1524 }
1525 default:
1526 return -ENOIOCTLCMD;
1527 }
1528 return 0;
1529}
1530
1531static struct saa7146_standard standard[] = { 1521static struct saa7146_standard standard[] = {
1532 {.name = "PAL",.id = V4L2_STD_PAL, 1522 {.name = "PAL",.id = V4L2_STD_PAL,
1533 .v_offset = 0x17,.v_field = 288, 1523 .v_offset = 0x17,.v_field = 288,
@@ -1546,8 +1536,6 @@ static struct saa7146_ext_vv vv_data = {
1546 .flags = 0, 1536 .flags = 0,
1547 .stds = &standard[0], 1537 .stds = &standard[0],
1548 .num_stds = ARRAY_SIZE(standard), 1538 .num_stds = ARRAY_SIZE(standard),
1549 .ioctls = &ioctls[0],
1550 .ioctl = av_ioctl,
1551}; 1539};
1552 1540
1553static struct saa7146_extension budget_extension; 1541static struct saa7146_extension budget_extension;
diff --git a/drivers/media/dvb/ttpci/budget-ci.c b/drivers/media/dvb/ttpci/budget-ci.c
index bcbc5d41a0fe..371a71616810 100644
--- a/drivers/media/dvb/ttpci/budget-ci.c
+++ b/drivers/media/dvb/ttpci/budget-ci.c
@@ -1076,6 +1076,10 @@ static struct tda10023_config tda10023_config = {
1076 .deltaf = 0xa511, 1076 .deltaf = 0xa511,
1077}; 1077};
1078 1078
1079static struct tda827x_config tda827x_config = {
1080 .config = 0,
1081};
1082
1079/* TT S2-3200 DVB-S (STB0899) Inittab */ 1083/* TT S2-3200 DVB-S (STB0899) Inittab */
1080static const struct stb0899_s1_reg tt3200_stb0899_s1_init_1[] = { 1084static const struct stb0899_s1_reg tt3200_stb0899_s1_init_1[] = {
1081 1085
@@ -1414,7 +1418,7 @@ static void frontend_init(struct budget_ci *budget_ci)
1414 case 0x101a: /* TT Budget-C-1501 (philips tda10023/philips tda8274A) */ 1418 case 0x101a: /* TT Budget-C-1501 (philips tda10023/philips tda8274A) */
1415 budget_ci->budget.dvb_frontend = dvb_attach(tda10023_attach, &tda10023_config, &budget_ci->budget.i2c_adap, 0x48); 1419 budget_ci->budget.dvb_frontend = dvb_attach(tda10023_attach, &tda10023_config, &budget_ci->budget.i2c_adap, 0x48);
1416 if (budget_ci->budget.dvb_frontend) { 1420 if (budget_ci->budget.dvb_frontend) {
1417 if (dvb_attach(tda827x_attach, budget_ci->budget.dvb_frontend, 0x61, &budget_ci->budget.i2c_adap, NULL) == NULL) { 1421 if (dvb_attach(tda827x_attach, budget_ci->budget.dvb_frontend, 0x61, &budget_ci->budget.i2c_adap, &tda827x_config) == NULL) {
1418 printk(KERN_ERR "%s: No tda827x found!\n", __func__); 1422 printk(KERN_ERR "%s: No tda827x found!\n", __func__);
1419 dvb_frontend_detach(budget_ci->budget.dvb_frontend); 1423 dvb_frontend_detach(budget_ci->budget.dvb_frontend);
1420 budget_ci->budget.dvb_frontend = NULL; 1424 budget_ci->budget.dvb_frontend = NULL;
diff --git a/drivers/media/radio/dsbr100.c b/drivers/media/radio/dsbr100.c
index 2014ebc4e984..cc54ed4efc48 100644
--- a/drivers/media/radio/dsbr100.c
+++ b/drivers/media/radio/dsbr100.c
@@ -390,9 +390,11 @@ static void usb_dsbr100_disconnect(struct usb_interface *intf)
390static int vidioc_querycap(struct file *file, void *priv, 390static int vidioc_querycap(struct file *file, void *priv,
391 struct v4l2_capability *v) 391 struct v4l2_capability *v)
392{ 392{
393 struct dsbr100_device *radio = video_drvdata(file);
394
393 strlcpy(v->driver, "dsbr100", sizeof(v->driver)); 395 strlcpy(v->driver, "dsbr100", sizeof(v->driver));
394 strlcpy(v->card, "D-Link R-100 USB FM Radio", sizeof(v->card)); 396 strlcpy(v->card, "D-Link R-100 USB FM Radio", sizeof(v->card));
395 sprintf(v->bus_info, "USB"); 397 usb_make_path(radio->usbdev, v->bus_info, sizeof(v->bus_info));
396 v->version = RADIO_VERSION; 398 v->version = RADIO_VERSION;
397 v->capabilities = V4L2_CAP_TUNER; 399 v->capabilities = V4L2_CAP_TUNER;
398 return 0; 400 return 0;
@@ -450,7 +452,10 @@ static int vidioc_s_frequency(struct file *file, void *priv,
450 if (radio->removed) 452 if (radio->removed)
451 return -EIO; 453 return -EIO;
452 454
455 mutex_lock(&radio->lock);
453 radio->curfreq = f->frequency; 456 radio->curfreq = f->frequency;
457 mutex_unlock(&radio->lock);
458
454 retval = dsbr100_setfreq(radio, radio->curfreq); 459 retval = dsbr100_setfreq(radio, radio->curfreq);
455 if (retval < 0) 460 if (retval < 0)
456 dev_warn(&radio->usbdev->dev, "Set frequency failed\n"); 461 dev_warn(&radio->usbdev->dev, "Set frequency failed\n");
@@ -601,7 +606,10 @@ static int usb_dsbr100_close(struct file *file)
601 if (!radio) 606 if (!radio)
602 return -ENODEV; 607 return -ENODEV;
603 608
609 mutex_lock(&radio->lock);
604 radio->users = 0; 610 radio->users = 0;
611 mutex_unlock(&radio->lock);
612
605 if (!radio->removed) { 613 if (!radio->removed) {
606 retval = dsbr100_stop(radio); 614 retval = dsbr100_stop(radio);
607 if (retval < 0) { 615 if (retval < 0) {
diff --git a/drivers/media/radio/radio-aimslab.c b/drivers/media/radio/radio-aimslab.c
index bfa13b8b3043..ac82e33cb6fc 100644
--- a/drivers/media/radio/radio-aimslab.c
+++ b/drivers/media/radio/radio-aimslab.c
@@ -32,14 +32,15 @@
32#include <linux/init.h> /* Initdata */ 32#include <linux/init.h> /* Initdata */
33#include <linux/ioport.h> /* request_region */ 33#include <linux/ioport.h> /* request_region */
34#include <linux/delay.h> /* udelay */ 34#include <linux/delay.h> /* udelay */
35#include <asm/io.h> /* outb, outb_p */
36#include <asm/uaccess.h> /* copy to/from user */
37#include <linux/videodev2.h> /* kernel radio structs */ 35#include <linux/videodev2.h> /* kernel radio structs */
38#include <media/v4l2-common.h> 36#include <linux/version.h> /* for KERNEL_VERSION MACRO */
37#include <linux/io.h> /* outb, outb_p */
38#include <media/v4l2-device.h>
39#include <media/v4l2-ioctl.h> 39#include <media/v4l2-ioctl.h>
40 40
41#include <linux/version.h> /* for KERNEL_VERSION MACRO */ 41MODULE_AUTHOR("M.Kirkwood");
42#define RADIO_VERSION KERNEL_VERSION(0,0,2) 42MODULE_DESCRIPTION("A driver for the RadioTrack/RadioReveal radio card.");
43MODULE_LICENSE("GPL");
43 44
44#ifndef CONFIG_RADIO_RTRACK_PORT 45#ifndef CONFIG_RADIO_RTRACK_PORT
45#define CONFIG_RADIO_RTRACK_PORT -1 46#define CONFIG_RADIO_RTRACK_PORT -1
@@ -47,86 +48,95 @@
47 48
48static int io = CONFIG_RADIO_RTRACK_PORT; 49static int io = CONFIG_RADIO_RTRACK_PORT;
49static int radio_nr = -1; 50static int radio_nr = -1;
50static struct mutex lock;
51 51
52struct rt_device 52module_param(io, int, 0);
53MODULE_PARM_DESC(io, "I/O address of the RadioTrack card (0x20f or 0x30f)");
54module_param(radio_nr, int, 0);
55
56#define RADIO_VERSION KERNEL_VERSION(0, 0, 2)
57
58struct rtrack
53{ 59{
54 unsigned long in_use; 60 struct v4l2_device v4l2_dev;
61 struct video_device vdev;
55 int port; 62 int port;
56 int curvol; 63 int curvol;
57 unsigned long curfreq; 64 unsigned long curfreq;
58 int muted; 65 int muted;
66 int io;
67 struct mutex lock;
59}; 68};
60 69
70static struct rtrack rtrack_card;
61 71
62/* local things */ 72/* local things */
63 73
64static void sleep_delay(long n) 74static void sleep_delay(long n)
65{ 75{
66 /* Sleep nicely for 'n' uS */ 76 /* Sleep nicely for 'n' uS */
67 int d=n/msecs_to_jiffies(1000); 77 int d = n / msecs_to_jiffies(1000);
68 if(!d) 78 if (!d)
69 udelay(n); 79 udelay(n);
70 else 80 else
71 msleep(jiffies_to_msecs(d)); 81 msleep(jiffies_to_msecs(d));
72} 82}
73 83
74static void rt_decvol(void) 84static void rt_decvol(struct rtrack *rt)
75{ 85{
76 outb(0x58, io); /* volume down + sigstr + on */ 86 outb(0x58, rt->io); /* volume down + sigstr + on */
77 sleep_delay(100000); 87 sleep_delay(100000);
78 outb(0xd8, io); /* volume steady + sigstr + on */ 88 outb(0xd8, rt->io); /* volume steady + sigstr + on */
79} 89}
80 90
81static void rt_incvol(void) 91static void rt_incvol(struct rtrack *rt)
82{ 92{
83 outb(0x98, io); /* volume up + sigstr + on */ 93 outb(0x98, rt->io); /* volume up + sigstr + on */
84 sleep_delay(100000); 94 sleep_delay(100000);
85 outb(0xd8, io); /* volume steady + sigstr + on */ 95 outb(0xd8, rt->io); /* volume steady + sigstr + on */
86} 96}
87 97
88static void rt_mute(struct rt_device *dev) 98static void rt_mute(struct rtrack *rt)
89{ 99{
90 dev->muted = 1; 100 rt->muted = 1;
91 mutex_lock(&lock); 101 mutex_lock(&rt->lock);
92 outb(0xd0, io); /* volume steady, off */ 102 outb(0xd0, rt->io); /* volume steady, off */
93 mutex_unlock(&lock); 103 mutex_unlock(&rt->lock);
94} 104}
95 105
96static int rt_setvol(struct rt_device *dev, int vol) 106static int rt_setvol(struct rtrack *rt, int vol)
97{ 107{
98 int i; 108 int i;
99 109
100 mutex_lock(&lock); 110 mutex_lock(&rt->lock);
101 111
102 if(vol == dev->curvol) { /* requested volume = current */ 112 if (vol == rt->curvol) { /* requested volume = current */
103 if (dev->muted) { /* user is unmuting the card */ 113 if (rt->muted) { /* user is unmuting the card */
104 dev->muted = 0; 114 rt->muted = 0;
105 outb (0xd8, io); /* enable card */ 115 outb(0xd8, rt->io); /* enable card */
106 } 116 }
107 mutex_unlock(&lock); 117 mutex_unlock(&rt->lock);
108 return 0; 118 return 0;
109 } 119 }
110 120
111 if(vol == 0) { /* volume = 0 means mute the card */ 121 if (vol == 0) { /* volume = 0 means mute the card */
112 outb(0x48, io); /* volume down but still "on" */ 122 outb(0x48, rt->io); /* volume down but still "on" */
113 sleep_delay(2000000); /* make sure it's totally down */ 123 sleep_delay(2000000); /* make sure it's totally down */
114 outb(0xd0, io); /* volume steady, off */ 124 outb(0xd0, rt->io); /* volume steady, off */
115 dev->curvol = 0; /* track the volume state! */ 125 rt->curvol = 0; /* track the volume state! */
116 mutex_unlock(&lock); 126 mutex_unlock(&rt->lock);
117 return 0; 127 return 0;
118 } 128 }
119 129
120 dev->muted = 0; 130 rt->muted = 0;
121 if(vol > dev->curvol) 131 if (vol > rt->curvol)
122 for(i = dev->curvol; i < vol; i++) 132 for (i = rt->curvol; i < vol; i++)
123 rt_incvol(); 133 rt_incvol(rt);
124 else 134 else
125 for(i = dev->curvol; i > vol; i--) 135 for (i = rt->curvol; i > vol; i--)
126 rt_decvol(); 136 rt_decvol(rt);
127 137
128 dev->curvol = vol; 138 rt->curvol = vol;
129 mutex_unlock(&lock); 139 mutex_unlock(&rt->lock);
130 return 0; 140 return 0;
131} 141}
132 142
@@ -135,155 +145,137 @@ static int rt_setvol(struct rt_device *dev, int vol)
135 * and bit 4 (+16) is to keep the signal strength meter enabled 145 * and bit 4 (+16) is to keep the signal strength meter enabled
136 */ 146 */
137 147
138static void send_0_byte(int port, struct rt_device *dev) 148static void send_0_byte(struct rtrack *rt)
139{ 149{
140 if ((dev->curvol == 0) || (dev->muted)) { 150 if (rt->curvol == 0 || rt->muted) {
141 outb_p(128+64+16+ 1, port); /* wr-enable + data low */ 151 outb_p(128+64+16+ 1, rt->io); /* wr-enable + data low */
142 outb_p(128+64+16+2+1, port); /* clock */ 152 outb_p(128+64+16+2+1, rt->io); /* clock */
143 } 153 }
144 else { 154 else {
145 outb_p(128+64+16+8+ 1, port); /* on + wr-enable + data low */ 155 outb_p(128+64+16+8+ 1, rt->io); /* on + wr-enable + data low */
146 outb_p(128+64+16+8+2+1, port); /* clock */ 156 outb_p(128+64+16+8+2+1, rt->io); /* clock */
147 } 157 }
148 sleep_delay(1000); 158 sleep_delay(1000);
149} 159}
150 160
151static void send_1_byte(int port, struct rt_device *dev) 161static void send_1_byte(struct rtrack *rt)
152{ 162{
153 if ((dev->curvol == 0) || (dev->muted)) { 163 if (rt->curvol == 0 || rt->muted) {
154 outb_p(128+64+16+4 +1, port); /* wr-enable+data high */ 164 outb_p(128+64+16+4 +1, rt->io); /* wr-enable+data high */
155 outb_p(128+64+16+4+2+1, port); /* clock */ 165 outb_p(128+64+16+4+2+1, rt->io); /* clock */
156 } 166 }
157 else { 167 else {
158 outb_p(128+64+16+8+4 +1, port); /* on+wr-enable+data high */ 168 outb_p(128+64+16+8+4 +1, rt->io); /* on+wr-enable+data high */
159 outb_p(128+64+16+8+4+2+1, port); /* clock */ 169 outb_p(128+64+16+8+4+2+1, rt->io); /* clock */
160 } 170 }
161 171
162 sleep_delay(1000); 172 sleep_delay(1000);
163} 173}
164 174
165static int rt_setfreq(struct rt_device *dev, unsigned long freq) 175static int rt_setfreq(struct rtrack *rt, unsigned long freq)
166{ 176{
167 int i; 177 int i;
168 178
169 /* adapted from radio-aztech.c */ 179 mutex_lock(&rt->lock); /* Stop other ops interfering */
180
181 rt->curfreq = freq;
170 182
171 /* now uses VIDEO_TUNER_LOW for fine tuning */ 183 /* now uses VIDEO_TUNER_LOW for fine tuning */
172 184
173 freq += 171200; /* Add 10.7 MHz IF */ 185 freq += 171200; /* Add 10.7 MHz IF */
174 freq /= 800; /* Convert to 50 kHz units */ 186 freq /= 800; /* Convert to 50 kHz units */
175 187
176 mutex_lock(&lock); /* Stop other ops interfering */ 188 send_0_byte(rt); /* 0: LSB of frequency */
177
178 send_0_byte (io, dev); /* 0: LSB of frequency */
179 189
180 for (i = 0; i < 13; i++) /* : frequency bits (1-13) */ 190 for (i = 0; i < 13; i++) /* : frequency bits (1-13) */
181 if (freq & (1 << i)) 191 if (freq & (1 << i))
182 send_1_byte (io, dev); 192 send_1_byte(rt);
183 else 193 else
184 send_0_byte (io, dev); 194 send_0_byte(rt);
185 195
186 send_0_byte (io, dev); /* 14: test bit - always 0 */ 196 send_0_byte(rt); /* 14: test bit - always 0 */
187 send_0_byte (io, dev); /* 15: test bit - always 0 */ 197 send_0_byte(rt); /* 15: test bit - always 0 */
188 198
189 send_0_byte (io, dev); /* 16: band data 0 - always 0 */ 199 send_0_byte(rt); /* 16: band data 0 - always 0 */
190 send_0_byte (io, dev); /* 17: band data 1 - always 0 */ 200 send_0_byte(rt); /* 17: band data 1 - always 0 */
191 send_0_byte (io, dev); /* 18: band data 2 - always 0 */ 201 send_0_byte(rt); /* 18: band data 2 - always 0 */
192 send_0_byte (io, dev); /* 19: time base - always 0 */ 202 send_0_byte(rt); /* 19: time base - always 0 */
193 203
194 send_0_byte (io, dev); /* 20: spacing (0 = 25 kHz) */ 204 send_0_byte(rt); /* 20: spacing (0 = 25 kHz) */
195 send_1_byte (io, dev); /* 21: spacing (1 = 25 kHz) */ 205 send_1_byte(rt); /* 21: spacing (1 = 25 kHz) */
196 send_0_byte (io, dev); /* 22: spacing (0 = 25 kHz) */ 206 send_0_byte(rt); /* 22: spacing (0 = 25 kHz) */
197 send_1_byte (io, dev); /* 23: AM/FM (FM = 1, always) */ 207 send_1_byte(rt); /* 23: AM/FM (FM = 1, always) */
198 208
199 if ((dev->curvol == 0) || (dev->muted)) 209 if (rt->curvol == 0 || rt->muted)
200 outb (0xd0, io); /* volume steady + sigstr */ 210 outb(0xd0, rt->io); /* volume steady + sigstr */
201 else 211 else
202 outb (0xd8, io); /* volume steady + sigstr + on */ 212 outb(0xd8, rt->io); /* volume steady + sigstr + on */
203 213
204 mutex_unlock(&lock); 214 mutex_unlock(&rt->lock);
205 215
206 return 0; 216 return 0;
207} 217}
208 218
209static int rt_getsigstr(struct rt_device *dev) 219static int rt_getsigstr(struct rtrack *rt)
210{ 220{
211 if (inb(io) & 2) /* bit set = no signal present */ 221 int sig = 1;
212 return 0;
213 return 1; /* signal present */
214}
215 222
216static struct v4l2_queryctrl radio_qctrl[] = { 223 mutex_lock(&rt->lock);
217 { 224 if (inb(rt->io) & 2) /* bit set = no signal present */
218 .id = V4L2_CID_AUDIO_MUTE, 225 sig = 0;
219 .name = "Mute", 226 mutex_unlock(&rt->lock);
220 .minimum = 0, 227 return sig;
221 .maximum = 1, 228}
222 .default_value = 1,
223 .type = V4L2_CTRL_TYPE_BOOLEAN,
224 },{
225 .id = V4L2_CID_AUDIO_VOLUME,
226 .name = "Volume",
227 .minimum = 0,
228 .maximum = 0xff,
229 .step = 1,
230 .default_value = 0xff,
231 .type = V4L2_CTRL_TYPE_INTEGER,
232 }
233};
234 229
235static int vidioc_querycap(struct file *file, void *priv, 230static int vidioc_querycap(struct file *file, void *priv,
236 struct v4l2_capability *v) 231 struct v4l2_capability *v)
237{ 232{
238 strlcpy(v->driver, "radio-aimslab", sizeof(v->driver)); 233 strlcpy(v->driver, "radio-aimslab", sizeof(v->driver));
239 strlcpy(v->card, "RadioTrack", sizeof(v->card)); 234 strlcpy(v->card, "RadioTrack", sizeof(v->card));
240 sprintf(v->bus_info, "ISA"); 235 strlcpy(v->bus_info, "ISA", sizeof(v->bus_info));
241 v->version = RADIO_VERSION; 236 v->version = RADIO_VERSION;
242 v->capabilities = V4L2_CAP_TUNER; 237 v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
243 return 0; 238 return 0;
244} 239}
245 240
246static int vidioc_g_tuner(struct file *file, void *priv, 241static int vidioc_g_tuner(struct file *file, void *priv,
247 struct v4l2_tuner *v) 242 struct v4l2_tuner *v)
248{ 243{
249 struct rt_device *rt = video_drvdata(file); 244 struct rtrack *rt = video_drvdata(file);
250 245
251 if (v->index > 0) 246 if (v->index > 0)
252 return -EINVAL; 247 return -EINVAL;
253 248
254 strcpy(v->name, "FM"); 249 strlcpy(v->name, "FM", sizeof(v->name));
255 v->type = V4L2_TUNER_RADIO; 250 v->type = V4L2_TUNER_RADIO;
256 v->rangelow = (87*16000); 251 v->rangelow = 87 * 16000;
257 v->rangehigh = (108*16000); 252 v->rangehigh = 108 * 16000;
258 v->rxsubchans = V4L2_TUNER_SUB_MONO; 253 v->rxsubchans = V4L2_TUNER_SUB_MONO;
259 v->capability = V4L2_TUNER_CAP_LOW; 254 v->capability = V4L2_TUNER_CAP_LOW;
260 v->audmode = V4L2_TUNER_MODE_MONO; 255 v->audmode = V4L2_TUNER_MODE_MONO;
261 v->signal = 0xffff*rt_getsigstr(rt); 256 v->signal = 0xffff * rt_getsigstr(rt);
262 return 0; 257 return 0;
263} 258}
264 259
265static int vidioc_s_tuner(struct file *file, void *priv, 260static int vidioc_s_tuner(struct file *file, void *priv,
266 struct v4l2_tuner *v) 261 struct v4l2_tuner *v)
267{ 262{
268 if (v->index > 0) 263 return v->index ? -EINVAL : 0;
269 return -EINVAL;
270 return 0;
271} 264}
272 265
273static int vidioc_s_frequency(struct file *file, void *priv, 266static int vidioc_s_frequency(struct file *file, void *priv,
274 struct v4l2_frequency *f) 267 struct v4l2_frequency *f)
275{ 268{
276 struct rt_device *rt = video_drvdata(file); 269 struct rtrack *rt = video_drvdata(file);
277 270
278 rt->curfreq = f->frequency; 271 rt_setfreq(rt, f->frequency);
279 rt_setfreq(rt, rt->curfreq);
280 return 0; 272 return 0;
281} 273}
282 274
283static int vidioc_g_frequency(struct file *file, void *priv, 275static int vidioc_g_frequency(struct file *file, void *priv,
284 struct v4l2_frequency *f) 276 struct v4l2_frequency *f)
285{ 277{
286 struct rt_device *rt = video_drvdata(file); 278 struct rtrack *rt = video_drvdata(file);
287 279
288 f->type = V4L2_TUNER_RADIO; 280 f->type = V4L2_TUNER_RADIO;
289 f->frequency = rt->curfreq; 281 f->frequency = rt->curfreq;
@@ -293,14 +285,11 @@ static int vidioc_g_frequency(struct file *file, void *priv,
293static int vidioc_queryctrl(struct file *file, void *priv, 285static int vidioc_queryctrl(struct file *file, void *priv,
294 struct v4l2_queryctrl *qc) 286 struct v4l2_queryctrl *qc)
295{ 287{
296 int i; 288 switch (qc->id) {
297 289 case V4L2_CID_AUDIO_MUTE:
298 for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) { 290 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
299 if (qc->id && qc->id == radio_qctrl[i].id) { 291 case V4L2_CID_AUDIO_VOLUME:
300 memcpy(qc, &(radio_qctrl[i]), 292 return v4l2_ctrl_query_fill(qc, 0, 0xff, 1, 0xff);
301 sizeof(*qc));
302 return 0;
303 }
304 } 293 }
305 return -EINVAL; 294 return -EINVAL;
306} 295}
@@ -308,14 +297,14 @@ static int vidioc_queryctrl(struct file *file, void *priv,
308static int vidioc_g_ctrl(struct file *file, void *priv, 297static int vidioc_g_ctrl(struct file *file, void *priv,
309 struct v4l2_control *ctrl) 298 struct v4l2_control *ctrl)
310{ 299{
311 struct rt_device *rt = video_drvdata(file); 300 struct rtrack *rt = video_drvdata(file);
312 301
313 switch (ctrl->id) { 302 switch (ctrl->id) {
314 case V4L2_CID_AUDIO_MUTE: 303 case V4L2_CID_AUDIO_MUTE:
315 ctrl->value = rt->muted; 304 ctrl->value = rt->muted;
316 return 0; 305 return 0;
317 case V4L2_CID_AUDIO_VOLUME: 306 case V4L2_CID_AUDIO_VOLUME:
318 ctrl->value = rt->curvol * 6554; 307 ctrl->value = rt->curvol;
319 return 0; 308 return 0;
320 } 309 }
321 return -EINVAL; 310 return -EINVAL;
@@ -324,33 +313,22 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
324static int vidioc_s_ctrl(struct file *file, void *priv, 313static int vidioc_s_ctrl(struct file *file, void *priv,
325 struct v4l2_control *ctrl) 314 struct v4l2_control *ctrl)
326{ 315{
327 struct rt_device *rt = video_drvdata(file); 316 struct rtrack *rt = video_drvdata(file);
328 317
329 switch (ctrl->id) { 318 switch (ctrl->id) {
330 case V4L2_CID_AUDIO_MUTE: 319 case V4L2_CID_AUDIO_MUTE:
331 if (ctrl->value) 320 if (ctrl->value)
332 rt_mute(rt); 321 rt_mute(rt);
333 else 322 else
334 rt_setvol(rt,rt->curvol); 323 rt_setvol(rt, rt->curvol);
335 return 0; 324 return 0;
336 case V4L2_CID_AUDIO_VOLUME: 325 case V4L2_CID_AUDIO_VOLUME:
337 rt_setvol(rt,ctrl->value); 326 rt_setvol(rt, ctrl->value);
338 return 0; 327 return 0;
339 } 328 }
340 return -EINVAL; 329 return -EINVAL;
341} 330}
342 331
343static int vidioc_g_audio (struct file *file, void *priv,
344 struct v4l2_audio *a)
345{
346 if (a->index > 1)
347 return -EINVAL;
348
349 strcpy(a->name, "Radio");
350 a->capability = V4L2_AUDCAP_STEREO;
351 return 0;
352}
353
354static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i) 332static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
355{ 333{
356 *i = 0; 334 *i = 0;
@@ -359,36 +337,38 @@ static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
359 337
360static int vidioc_s_input(struct file *filp, void *priv, unsigned int i) 338static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
361{ 339{
362 if (i != 0) 340 return i ? -EINVAL : 0;
363 return -EINVAL;
364 return 0;
365} 341}
366 342
367static int vidioc_s_audio(struct file *file, void *priv, 343static int vidioc_g_audio(struct file *file, void *priv,
368 struct v4l2_audio *a) 344 struct v4l2_audio *a)
369{ 345{
370 if (a->index != 0) 346 a->index = 0;
371 return -EINVAL; 347 strlcpy(a->name, "Radio", sizeof(a->name));
348 a->capability = V4L2_AUDCAP_STEREO;
372 return 0; 349 return 0;
373} 350}
374 351
375static struct rt_device rtrack_unit; 352static int vidioc_s_audio(struct file *file, void *priv,
353 struct v4l2_audio *a)
354{
355 return a->index ? -EINVAL : 0;
356}
376 357
377static int rtrack_exclusive_open(struct file *file) 358static int rtrack_open(struct file *file)
378{ 359{
379 return test_and_set_bit(0, &rtrack_unit.in_use) ? -EBUSY : 0; 360 return 0;
380} 361}
381 362
382static int rtrack_exclusive_release(struct file *file) 363static int rtrack_release(struct file *file)
383{ 364{
384 clear_bit(0, &rtrack_unit.in_use);
385 return 0; 365 return 0;
386} 366}
387 367
388static const struct v4l2_file_operations rtrack_fops = { 368static const struct v4l2_file_operations rtrack_fops = {
389 .owner = THIS_MODULE, 369 .owner = THIS_MODULE,
390 .open = rtrack_exclusive_open, 370 .open = rtrack_open,
391 .release = rtrack_exclusive_release, 371 .release = rtrack_release,
392 .ioctl = video_ioctl2, 372 .ioctl = video_ioctl2,
393}; 373};
394 374
@@ -407,64 +387,69 @@ static const struct v4l2_ioctl_ops rtrack_ioctl_ops = {
407 .vidioc_s_ctrl = vidioc_s_ctrl, 387 .vidioc_s_ctrl = vidioc_s_ctrl,
408}; 388};
409 389
410static struct video_device rtrack_radio = {
411 .name = "RadioTrack radio",
412 .fops = &rtrack_fops,
413 .ioctl_ops = &rtrack_ioctl_ops,
414 .release = video_device_release_empty,
415};
416
417static int __init rtrack_init(void) 390static int __init rtrack_init(void)
418{ 391{
419 if(io==-1) 392 struct rtrack *rt = &rtrack_card;
420 { 393 struct v4l2_device *v4l2_dev = &rt->v4l2_dev;
421 printk(KERN_ERR "You must set an I/O address with io=0x???\n"); 394 int res;
395
396 strlcpy(v4l2_dev->name, "rtrack", sizeof(v4l2_dev->name));
397 rt->io = io;
398
399 if (rt->io == -1) {
400 v4l2_err(v4l2_dev, "you must set an I/O address with io=0x20f or 0x30f\n");
422 return -EINVAL; 401 return -EINVAL;
423 } 402 }
424 403
425 if (!request_region(io, 2, "rtrack")) 404 if (!request_region(rt->io, 2, "rtrack")) {
426 { 405 v4l2_err(v4l2_dev, "port 0x%x already in use\n", rt->io);
427 printk(KERN_ERR "rtrack: port 0x%x already in use\n", io);
428 return -EBUSY; 406 return -EBUSY;
429 } 407 }
430 408
431 video_set_drvdata(&rtrack_radio, &rtrack_unit); 409 res = v4l2_device_register(NULL, v4l2_dev);
410 if (res < 0) {
411 release_region(rt->io, 2);
412 v4l2_err(v4l2_dev, "could not register v4l2_device\n");
413 return res;
414 }
432 415
433 if (video_register_device(&rtrack_radio, VFL_TYPE_RADIO, radio_nr) < 0) { 416 strlcpy(rt->vdev.name, v4l2_dev->name, sizeof(rt->vdev.name));
434 release_region(io, 2); 417 rt->vdev.v4l2_dev = v4l2_dev;
418 rt->vdev.fops = &rtrack_fops;
419 rt->vdev.ioctl_ops = &rtrack_ioctl_ops;
420 rt->vdev.release = video_device_release_empty;
421 video_set_drvdata(&rt->vdev, rt);
422
423 if (video_register_device(&rt->vdev, VFL_TYPE_RADIO, radio_nr) < 0) {
424 v4l2_device_unregister(&rt->v4l2_dev);
425 release_region(rt->io, 2);
435 return -EINVAL; 426 return -EINVAL;
436 } 427 }
437 printk(KERN_INFO "AIMSlab RadioTrack/RadioReveal card driver.\n"); 428 v4l2_info(v4l2_dev, "AIMSlab RadioTrack/RadioReveal card driver.\n");
438 429
439 /* Set up the I/O locking */ 430 /* Set up the I/O locking */
440 431
441 mutex_init(&lock); 432 mutex_init(&rt->lock);
442 433
443 /* mute card - prevents noisy bootups */ 434 /* mute card - prevents noisy bootups */
444 435
445 /* this ensures that the volume is all the way down */ 436 /* this ensures that the volume is all the way down */
446 outb(0x48, io); /* volume down but still "on" */ 437 outb(0x48, rt->io); /* volume down but still "on" */
447 sleep_delay(2000000); /* make sure it's totally down */ 438 sleep_delay(2000000); /* make sure it's totally down */
448 outb(0xc0, io); /* steady volume, mute card */ 439 outb(0xc0, rt->io); /* steady volume, mute card */
449 rtrack_unit.curvol = 0;
450 440
451 return 0; 441 return 0;
452} 442}
453 443
454MODULE_AUTHOR("M.Kirkwood"); 444static void __exit rtrack_exit(void)
455MODULE_DESCRIPTION("A driver for the RadioTrack/RadioReveal radio card.");
456MODULE_LICENSE("GPL");
457
458module_param(io, int, 0);
459MODULE_PARM_DESC(io, "I/O address of the RadioTrack card (0x20f or 0x30f)");
460module_param(radio_nr, int, 0);
461
462static void __exit cleanup_rtrack_module(void)
463{ 445{
464 video_unregister_device(&rtrack_radio); 446 struct rtrack *rt = &rtrack_card;
465 release_region(io,2); 447
448 video_unregister_device(&rt->vdev);
449 v4l2_device_unregister(&rt->v4l2_dev);
450 release_region(rt->io, 2);
466} 451}
467 452
468module_init(rtrack_init); 453module_init(rtrack_init);
469module_exit(cleanup_rtrack_module); 454module_exit(rtrack_exit);
470 455
diff --git a/drivers/media/radio/radio-aztech.c b/drivers/media/radio/radio-aztech.c
index 5604e881e96c..49299f7fd834 100644
--- a/drivers/media/radio/radio-aztech.c
+++ b/drivers/media/radio/radio-aztech.c
@@ -29,33 +29,15 @@
29#include <linux/init.h> /* Initdata */ 29#include <linux/init.h> /* Initdata */
30#include <linux/ioport.h> /* request_region */ 30#include <linux/ioport.h> /* request_region */
31#include <linux/delay.h> /* udelay */ 31#include <linux/delay.h> /* udelay */
32#include <asm/io.h> /* outb, outb_p */
33#include <asm/uaccess.h> /* copy to/from user */
34#include <linux/videodev2.h> /* kernel radio structs */ 32#include <linux/videodev2.h> /* kernel radio structs */
35#include <media/v4l2-common.h> 33#include <linux/version.h> /* for KERNEL_VERSION MACRO */
34#include <linux/io.h> /* outb, outb_p */
35#include <media/v4l2-device.h>
36#include <media/v4l2-ioctl.h> 36#include <media/v4l2-ioctl.h>
37 37
38#include <linux/version.h> /* for KERNEL_VERSION MACRO */ 38MODULE_AUTHOR("Russell Kroll, Quay Lu, Donald Song, Jason Lewis, Scott McGrath, William McGrath");
39#define RADIO_VERSION KERNEL_VERSION(0,0,2) 39MODULE_DESCRIPTION("A driver for the Aztech radio card.");
40 40MODULE_LICENSE("GPL");
41static struct v4l2_queryctrl radio_qctrl[] = {
42 {
43 .id = V4L2_CID_AUDIO_MUTE,
44 .name = "Mute",
45 .minimum = 0,
46 .maximum = 1,
47 .default_value = 1,
48 .type = V4L2_CTRL_TYPE_BOOLEAN,
49 },{
50 .id = V4L2_CID_AUDIO_VOLUME,
51 .name = "Volume",
52 .minimum = 0,
53 .maximum = 0xff,
54 .step = 1,
55 .default_value = 0xff,
56 .type = V4L2_CTRL_TYPE_INTEGER,
57 }
58};
59 41
60/* acceptable ports: 0x350 (JP3 shorted), 0x358 (JP3 open) */ 42/* acceptable ports: 0x350 (JP3 shorted), 0x358 (JP3 open) */
61 43
@@ -66,55 +48,64 @@ static struct v4l2_queryctrl radio_qctrl[] = {
66static int io = CONFIG_RADIO_AZTECH_PORT; 48static int io = CONFIG_RADIO_AZTECH_PORT;
67static int radio_nr = -1; 49static int radio_nr = -1;
68static int radio_wait_time = 1000; 50static int radio_wait_time = 1000;
69static struct mutex lock;
70 51
71struct az_device 52module_param(io, int, 0);
53module_param(radio_nr, int, 0);
54MODULE_PARM_DESC(io, "I/O address of the Aztech card (0x350 or 0x358)");
55
56#define RADIO_VERSION KERNEL_VERSION(0, 0, 2)
57
58struct aztech
72{ 59{
73 unsigned long in_use; 60 struct v4l2_device v4l2_dev;
61 struct video_device vdev;
62 int io;
74 int curvol; 63 int curvol;
75 unsigned long curfreq; 64 unsigned long curfreq;
76 int stereo; 65 int stereo;
66 struct mutex lock;
77}; 67};
78 68
69static struct aztech aztech_card;
70
79static int volconvert(int level) 71static int volconvert(int level)
80{ 72{
81 level>>=14; /* Map 16bits down to 2 bit */ 73 level >>= 14; /* Map 16bits down to 2 bit */
82 level&=3; 74 level &= 3;
83 75
84 /* convert to card-friendly values */ 76 /* convert to card-friendly values */
85 switch (level) 77 switch (level) {
86 { 78 case 0:
87 case 0: 79 return 0;
88 return 0; 80 case 1:
89 case 1: 81 return 1;
90 return 1; 82 case 2:
91 case 2: 83 return 4;
92 return 4; 84 case 3:
93 case 3: 85 return 5;
94 return 5;
95 } 86 }
96 return 0; /* Quieten gcc */ 87 return 0; /* Quieten gcc */
97} 88}
98 89
99static void send_0_byte (struct az_device *dev) 90static void send_0_byte(struct aztech *az)
100{ 91{
101 udelay(radio_wait_time); 92 udelay(radio_wait_time);
102 outb_p(2+volconvert(dev->curvol), io); 93 outb_p(2 + volconvert(az->curvol), az->io);
103 outb_p(64+2+volconvert(dev->curvol), io); 94 outb_p(64 + 2 + volconvert(az->curvol), az->io);
104} 95}
105 96
106static void send_1_byte (struct az_device *dev) 97static void send_1_byte(struct aztech *az)
107{ 98{
108 udelay (radio_wait_time); 99 udelay (radio_wait_time);
109 outb_p(128+2+volconvert(dev->curvol), io); 100 outb_p(128 + 2 + volconvert(az->curvol), az->io);
110 outb_p(128+64+2+volconvert(dev->curvol), io); 101 outb_p(128 + 64 + 2 + volconvert(az->curvol), az->io);
111} 102}
112 103
113static int az_setvol(struct az_device *dev, int vol) 104static int az_setvol(struct aztech *az, int vol)
114{ 105{
115 mutex_lock(&lock); 106 mutex_lock(&az->lock);
116 outb (volconvert(vol), io); 107 outb(volconvert(vol), az->io);
117 mutex_unlock(&lock); 108 mutex_unlock(&az->lock);
118 return 0; 109 return 0;
119} 110}
120 111
@@ -126,116 +117,110 @@ static int az_setvol(struct az_device *dev, int vol)
126 * 117 *
127 */ 118 */
128 119
129static int az_getsigstr(struct az_device *dev) 120static int az_getsigstr(struct aztech *az)
130{ 121{
131 if (inb(io) & 2) /* bit set = no signal present */ 122 int sig = 1;
132 return 0; 123
133 return 1; /* signal present */ 124 mutex_lock(&az->lock);
125 if (inb(az->io) & 2) /* bit set = no signal present */
126 sig = 0;
127 mutex_unlock(&az->lock);
128 return sig;
134} 129}
135 130
136static int az_getstereo(struct az_device *dev) 131static int az_getstereo(struct aztech *az)
137{ 132{
138 if (inb(io) & 1) /* bit set = mono */ 133 int stereo = 1;
139 return 0; 134
140 return 1; /* stereo */ 135 mutex_lock(&az->lock);
136 if (inb(az->io) & 1) /* bit set = mono */
137 stereo = 0;
138 mutex_unlock(&az->lock);
139 return stereo;
141} 140}
142 141
143static int az_setfreq(struct az_device *dev, unsigned long frequency) 142static int az_setfreq(struct aztech *az, unsigned long frequency)
144{ 143{
145 int i; 144 int i;
146 145
146 mutex_lock(&az->lock);
147
148 az->curfreq = frequency;
147 frequency += 171200; /* Add 10.7 MHz IF */ 149 frequency += 171200; /* Add 10.7 MHz IF */
148 frequency /= 800; /* Convert to 50 kHz units */ 150 frequency /= 800; /* Convert to 50 kHz units */
149 151
150 mutex_lock(&lock); 152 send_0_byte(az); /* 0: LSB of frequency */
151
152 send_0_byte (dev); /* 0: LSB of frequency */
153 153
154 for (i = 0; i < 13; i++) /* : frequency bits (1-13) */ 154 for (i = 0; i < 13; i++) /* : frequency bits (1-13) */
155 if (frequency & (1 << i)) 155 if (frequency & (1 << i))
156 send_1_byte (dev); 156 send_1_byte(az);
157 else 157 else
158 send_0_byte (dev); 158 send_0_byte(az);
159 159
160 send_0_byte (dev); /* 14: test bit - always 0 */ 160 send_0_byte(az); /* 14: test bit - always 0 */
161 send_0_byte (dev); /* 15: test bit - always 0 */ 161 send_0_byte(az); /* 15: test bit - always 0 */
162 send_0_byte (dev); /* 16: band data 0 - always 0 */ 162 send_0_byte(az); /* 16: band data 0 - always 0 */
163 if (dev->stereo) /* 17: stereo (1 to enable) */ 163 if (az->stereo) /* 17: stereo (1 to enable) */
164 send_1_byte (dev); 164 send_1_byte(az);
165 else 165 else
166 send_0_byte (dev); 166 send_0_byte(az);
167 167
168 send_1_byte (dev); /* 18: band data 1 - unknown */ 168 send_1_byte(az); /* 18: band data 1 - unknown */
169 send_0_byte (dev); /* 19: time base - always 0 */ 169 send_0_byte(az); /* 19: time base - always 0 */
170 send_0_byte (dev); /* 20: spacing (0 = 25 kHz) */ 170 send_0_byte(az); /* 20: spacing (0 = 25 kHz) */
171 send_1_byte (dev); /* 21: spacing (1 = 25 kHz) */ 171 send_1_byte(az); /* 21: spacing (1 = 25 kHz) */
172 send_0_byte (dev); /* 22: spacing (0 = 25 kHz) */ 172 send_0_byte(az); /* 22: spacing (0 = 25 kHz) */
173 send_1_byte (dev); /* 23: AM/FM (FM = 1, always) */ 173 send_1_byte(az); /* 23: AM/FM (FM = 1, always) */
174 174
175 /* latch frequency */ 175 /* latch frequency */
176 176
177 udelay (radio_wait_time); 177 udelay(radio_wait_time);
178 outb_p(128+64+volconvert(dev->curvol), io); 178 outb_p(128 + 64 + volconvert(az->curvol), az->io);
179 179
180 mutex_unlock(&lock); 180 mutex_unlock(&az->lock);
181 181
182 return 0; 182 return 0;
183} 183}
184 184
185static int vidioc_querycap (struct file *file, void *priv, 185static int vidioc_querycap(struct file *file, void *priv,
186 struct v4l2_capability *v) 186 struct v4l2_capability *v)
187{ 187{
188 strlcpy(v->driver, "radio-aztech", sizeof (v->driver)); 188 strlcpy(v->driver, "radio-aztech", sizeof(v->driver));
189 strlcpy(v->card, "Aztech Radio", sizeof (v->card)); 189 strlcpy(v->card, "Aztech Radio", sizeof(v->card));
190 sprintf(v->bus_info,"ISA"); 190 strlcpy(v->bus_info, "ISA", sizeof(v->bus_info));
191 v->version = RADIO_VERSION; 191 v->version = RADIO_VERSION;
192 v->capabilities = V4L2_CAP_TUNER; 192 v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
193 return 0; 193 return 0;
194} 194}
195 195
196static int vidioc_g_tuner (struct file *file, void *priv, 196static int vidioc_g_tuner(struct file *file, void *priv,
197 struct v4l2_tuner *v) 197 struct v4l2_tuner *v)
198{ 198{
199 struct az_device *az = video_drvdata(file); 199 struct aztech *az = video_drvdata(file);
200 200
201 if (v->index > 0) 201 if (v->index > 0)
202 return -EINVAL; 202 return -EINVAL;
203 203
204 strcpy(v->name, "FM"); 204 strlcpy(v->name, "FM", sizeof(v->name));
205 v->type = V4L2_TUNER_RADIO; 205 v->type = V4L2_TUNER_RADIO;
206 206
207 v->rangelow=(87*16000); 207 v->rangelow = 87 * 16000;
208 v->rangehigh=(108*16000); 208 v->rangehigh = 108 * 16000;
209 v->rxsubchans =V4L2_TUNER_SUB_MONO|V4L2_TUNER_SUB_STEREO; 209 v->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO;
210 v->capability=V4L2_TUNER_CAP_LOW; 210 v->capability = V4L2_TUNER_CAP_LOW;
211 if(az_getstereo(az)) 211 if (az_getstereo(az))
212 v->audmode = V4L2_TUNER_MODE_STEREO; 212 v->audmode = V4L2_TUNER_MODE_STEREO;
213 else 213 else
214 v->audmode = V4L2_TUNER_MODE_MONO; 214 v->audmode = V4L2_TUNER_MODE_MONO;
215 v->signal=0xFFFF*az_getsigstr(az); 215 v->signal = 0xFFFF * az_getsigstr(az);
216 216
217 return 0; 217 return 0;
218} 218}
219 219
220 220static int vidioc_s_tuner(struct file *file, void *priv,
221static int vidioc_s_tuner (struct file *file, void *priv,
222 struct v4l2_tuner *v) 221 struct v4l2_tuner *v)
223{ 222{
224 if (v->index > 0) 223 return v->index ? -EINVAL : 0;
225 return -EINVAL;
226
227 return 0;
228}
229
230static int vidioc_g_audio (struct file *file, void *priv,
231 struct v4l2_audio *a)
232{
233 if (a->index > 1)
234 return -EINVAL;
235
236 strcpy(a->name, "Radio");
237 a->capability = V4L2_AUDCAP_STEREO;
238 return 0;
239} 224}
240 225
241static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i) 226static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
@@ -246,113 +231,107 @@ static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
246 231
247static int vidioc_s_input(struct file *filp, void *priv, unsigned int i) 232static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
248{ 233{
249 if (i != 0) 234 return i ? -EINVAL : 0;
250 return -EINVAL;
251 return 0;
252} 235}
253 236
254 237static int vidioc_g_audio(struct file *file, void *priv,
255static int vidioc_s_audio (struct file *file, void *priv,
256 struct v4l2_audio *a) 238 struct v4l2_audio *a)
257{ 239{
258 if (a->index != 0) 240 a->index = 0;
259 return -EINVAL; 241 strlcpy(a->name, "Radio", sizeof(a->name));
260 242 a->capability = V4L2_AUDCAP_STEREO;
261 return 0; 243 return 0;
262} 244}
263 245
264static int vidioc_s_frequency (struct file *file, void *priv, 246static int vidioc_s_audio(struct file *file, void *priv,
247 struct v4l2_audio *a)
248{
249 return a->index ? -EINVAL : 0;
250}
251
252static int vidioc_s_frequency(struct file *file, void *priv,
265 struct v4l2_frequency *f) 253 struct v4l2_frequency *f)
266{ 254{
267 struct az_device *az = video_drvdata(file); 255 struct aztech *az = video_drvdata(file);
268 256
269 az->curfreq = f->frequency; 257 az_setfreq(az, f->frequency);
270 az_setfreq(az, az->curfreq);
271 return 0; 258 return 0;
272} 259}
273 260
274static int vidioc_g_frequency (struct file *file, void *priv, 261static int vidioc_g_frequency(struct file *file, void *priv,
275 struct v4l2_frequency *f) 262 struct v4l2_frequency *f)
276{ 263{
277 struct az_device *az = video_drvdata(file); 264 struct aztech *az = video_drvdata(file);
278 265
279 f->type = V4L2_TUNER_RADIO; 266 f->type = V4L2_TUNER_RADIO;
280 f->frequency = az->curfreq; 267 f->frequency = az->curfreq;
281
282 return 0; 268 return 0;
283} 269}
284 270
285static int vidioc_queryctrl (struct file *file, void *priv, 271static int vidioc_queryctrl(struct file *file, void *priv,
286 struct v4l2_queryctrl *qc) 272 struct v4l2_queryctrl *qc)
287{ 273{
288 int i; 274 switch (qc->id) {
289 275 case V4L2_CID_AUDIO_MUTE:
290 for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) { 276 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
291 if (qc->id && qc->id == radio_qctrl[i].id) { 277 case V4L2_CID_AUDIO_VOLUME:
292 memcpy(qc, &(radio_qctrl[i]), 278 return v4l2_ctrl_query_fill(qc, 0, 0xff, 1, 0xff);
293 sizeof(*qc));
294 return (0);
295 }
296 } 279 }
297 return -EINVAL; 280 return -EINVAL;
298} 281}
299 282
300static int vidioc_g_ctrl (struct file *file, void *priv, 283static int vidioc_g_ctrl(struct file *file, void *priv,
301 struct v4l2_control *ctrl) 284 struct v4l2_control *ctrl)
302{ 285{
303 struct az_device *az = video_drvdata(file); 286 struct aztech *az = video_drvdata(file);
304 287
305 switch (ctrl->id) { 288 switch (ctrl->id) {
306 case V4L2_CID_AUDIO_MUTE: 289 case V4L2_CID_AUDIO_MUTE:
307 if (az->curvol==0) 290 if (az->curvol == 0)
308 ctrl->value=1; 291 ctrl->value = 1;
309 else 292 else
310 ctrl->value=0; 293 ctrl->value = 0;
311 return (0); 294 return 0;
312 case V4L2_CID_AUDIO_VOLUME: 295 case V4L2_CID_AUDIO_VOLUME:
313 ctrl->value=az->curvol * 6554; 296 ctrl->value = az->curvol * 6554;
314 return (0); 297 return 0;
315 } 298 }
316 return -EINVAL; 299 return -EINVAL;
317} 300}
318 301
319static int vidioc_s_ctrl (struct file *file, void *priv, 302static int vidioc_s_ctrl(struct file *file, void *priv,
320 struct v4l2_control *ctrl) 303 struct v4l2_control *ctrl)
321{ 304{
322 struct az_device *az = video_drvdata(file); 305 struct aztech *az = video_drvdata(file);
323 306
324 switch (ctrl->id) { 307 switch (ctrl->id) {
325 case V4L2_CID_AUDIO_MUTE: 308 case V4L2_CID_AUDIO_MUTE:
326 if (ctrl->value) { 309 if (ctrl->value)
327 az_setvol(az,0); 310 az_setvol(az, 0);
328 } else { 311 else
329 az_setvol(az,az->curvol); 312 az_setvol(az, az->curvol);
330 } 313 return 0;
331 return (0); 314 case V4L2_CID_AUDIO_VOLUME:
332 case V4L2_CID_AUDIO_VOLUME: 315 az_setvol(az, ctrl->value);
333 az_setvol(az,ctrl->value); 316 return 0;
334 return (0);
335 } 317 }
336 return -EINVAL; 318 return -EINVAL;
337} 319}
338 320
339static struct az_device aztech_unit; 321static int aztech_open(struct file *file)
340
341static int aztech_exclusive_open(struct file *file)
342{ 322{
343 return test_and_set_bit(0, &aztech_unit.in_use) ? -EBUSY : 0; 323 return 0;
344} 324}
345 325
346static int aztech_exclusive_release(struct file *file) 326static int aztech_release(struct file *file)
347{ 327{
348 clear_bit(0, &aztech_unit.in_use);
349 return 0; 328 return 0;
350} 329}
351 330
352static const struct v4l2_file_operations aztech_fops = { 331static const struct v4l2_file_operations aztech_fops = {
353 .owner = THIS_MODULE, 332 .owner = THIS_MODULE,
354 .open = aztech_exclusive_open, 333 .open = aztech_open,
355 .release = aztech_exclusive_release, 334 .release = aztech_release,
356 .ioctl = video_ioctl2, 335 .ioctl = video_ioctl2,
357}; 336};
358 337
@@ -371,57 +350,60 @@ static const struct v4l2_ioctl_ops aztech_ioctl_ops = {
371 .vidioc_s_ctrl = vidioc_s_ctrl, 350 .vidioc_s_ctrl = vidioc_s_ctrl,
372}; 351};
373 352
374static struct video_device aztech_radio = {
375 .name = "Aztech radio",
376 .fops = &aztech_fops,
377 .ioctl_ops = &aztech_ioctl_ops,
378 .release = video_device_release_empty,
379};
380
381module_param_named(debug,aztech_radio.debug, int, 0644);
382MODULE_PARM_DESC(debug,"activates debug info");
383
384static int __init aztech_init(void) 353static int __init aztech_init(void)
385{ 354{
386 if(io==-1) 355 struct aztech *az = &aztech_card;
387 { 356 struct v4l2_device *v4l2_dev = &az->v4l2_dev;
388 printk(KERN_ERR "You must set an I/O address with io=0x???\n"); 357 int res;
358
359 strlcpy(v4l2_dev->name, "aztech", sizeof(v4l2_dev->name));
360 az->io = io;
361
362 if (az->io == -1) {
363 v4l2_err(v4l2_dev, "you must set an I/O address with io=0x350 or 0x358\n");
389 return -EINVAL; 364 return -EINVAL;
390 } 365 }
391 366
392 if (!request_region(io, 2, "aztech")) 367 if (!request_region(az->io, 2, "aztech")) {
393 { 368 v4l2_err(v4l2_dev, "port 0x%x already in use\n", az->io);
394 printk(KERN_ERR "aztech: port 0x%x already in use\n", io);
395 return -EBUSY; 369 return -EBUSY;
396 } 370 }
397 371
398 mutex_init(&lock); 372 res = v4l2_device_register(NULL, v4l2_dev);
399 video_set_drvdata(&aztech_radio, &aztech_unit); 373 if (res < 0) {
374 release_region(az->io, 2);
375 v4l2_err(v4l2_dev, "Could not register v4l2_device\n");
376 return res;
377 }
400 378
401 if (video_register_device(&aztech_radio, VFL_TYPE_RADIO, radio_nr) < 0) { 379 mutex_init(&az->lock);
402 release_region(io,2); 380 strlcpy(az->vdev.name, v4l2_dev->name, sizeof(az->vdev.name));
381 az->vdev.v4l2_dev = v4l2_dev;
382 az->vdev.fops = &aztech_fops;
383 az->vdev.ioctl_ops = &aztech_ioctl_ops;
384 az->vdev.release = video_device_release_empty;
385 video_set_drvdata(&az->vdev, az);
386
387 if (video_register_device(&az->vdev, VFL_TYPE_RADIO, radio_nr) < 0) {
388 v4l2_device_unregister(v4l2_dev);
389 release_region(az->io, 2);
403 return -EINVAL; 390 return -EINVAL;
404 } 391 }
405 392
406 printk(KERN_INFO "Aztech radio card driver v1.00/19990224 rkroll@exploits.org\n"); 393 v4l2_info(v4l2_dev, "Aztech radio card driver v1.00/19990224 rkroll@exploits.org\n");
407 /* mute card - prevents noisy bootups */ 394 /* mute card - prevents noisy bootups */
408 outb (0, io); 395 outb(0, az->io);
409 return 0; 396 return 0;
410} 397}
411 398
412MODULE_AUTHOR("Russell Kroll, Quay Lu, Donald Song, Jason Lewis, Scott McGrath, William McGrath"); 399static void __exit aztech_exit(void)
413MODULE_DESCRIPTION("A driver for the Aztech radio card.");
414MODULE_LICENSE("GPL");
415
416module_param(io, int, 0);
417module_param(radio_nr, int, 0);
418MODULE_PARM_DESC(io, "I/O address of the Aztech card (0x350 or 0x358)");
419
420static void __exit aztech_cleanup(void)
421{ 400{
422 video_unregister_device(&aztech_radio); 401 struct aztech *az = &aztech_card;
423 release_region(io,2); 402
403 video_unregister_device(&az->vdev);
404 v4l2_device_unregister(&az->v4l2_dev);
405 release_region(az->io, 2);
424} 406}
425 407
426module_init(aztech_init); 408module_init(aztech_init);
427module_exit(aztech_cleanup); 409module_exit(aztech_exit);
diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
index cb3075ac104c..d30fc0ce82c0 100644
--- a/drivers/media/radio/radio-cadet.c
+++ b/drivers/media/radio/radio-cadet.c
@@ -35,333 +35,318 @@
35#include <linux/init.h> /* Initdata */ 35#include <linux/init.h> /* Initdata */
36#include <linux/ioport.h> /* request_region */ 36#include <linux/ioport.h> /* request_region */
37#include <linux/delay.h> /* udelay */ 37#include <linux/delay.h> /* udelay */
38#include <asm/io.h> /* outb, outb_p */
39#include <asm/uaccess.h> /* copy to/from user */
40#include <linux/videodev2.h> /* V4L2 API defs */ 38#include <linux/videodev2.h> /* V4L2 API defs */
41#include <media/v4l2-common.h>
42#include <media/v4l2-ioctl.h>
43#include <linux/param.h> 39#include <linux/param.h>
44#include <linux/pnp.h> 40#include <linux/pnp.h>
41#include <linux/io.h> /* outb, outb_p */
42#include <media/v4l2-device.h>
43#include <media/v4l2-ioctl.h>
44
45MODULE_AUTHOR("Fred Gleason, Russell Kroll, Quay Lu, Donald Song, Jason Lewis, Scott McGrath, William McGrath");
46MODULE_DESCRIPTION("A driver for the ADS Cadet AM/FM/RDS radio card.");
47MODULE_LICENSE("GPL");
48
49static int io = -1; /* default to isapnp activation */
50static int radio_nr = -1;
51
52module_param(io, int, 0);
53MODULE_PARM_DESC(io, "I/O address of Cadet card (0x330,0x332,0x334,0x336,0x338,0x33a,0x33c,0x33e)");
54module_param(radio_nr, int, 0);
55
56#define CADET_VERSION KERNEL_VERSION(0, 3, 3)
45 57
46#define RDS_BUFFER 256 58#define RDS_BUFFER 256
47#define RDS_RX_FLAG 1 59#define RDS_RX_FLAG 1
48#define MBS_RX_FLAG 2 60#define MBS_RX_FLAG 2
49 61
50#define CADET_VERSION KERNEL_VERSION(0,3,3) 62struct cadet {
51 63 struct v4l2_device v4l2_dev;
52static struct v4l2_queryctrl radio_qctrl[] = { 64 struct video_device vdev;
53 { 65 int io;
54 .id = V4L2_CID_AUDIO_MUTE, 66 int users;
55 .name = "Mute", 67 int curtuner;
56 .minimum = 0, 68 int tunestat;
57 .maximum = 1, 69 int sigstrength;
58 .default_value = 1, 70 wait_queue_head_t read_queue;
59 .type = V4L2_CTRL_TYPE_BOOLEAN, 71 struct timer_list readtimer;
60 },{ 72 __u8 rdsin, rdsout, rdsstat;
61 .id = V4L2_CID_AUDIO_VOLUME, 73 unsigned char rdsbuf[RDS_BUFFER];
62 .name = "Volume", 74 struct mutex lock;
63 .minimum = 0, 75 int reading;
64 .maximum = 0xff,
65 .step = 1,
66 .default_value = 0xff,
67 .type = V4L2_CTRL_TYPE_INTEGER,
68 }
69}; 76};
70 77
71static int io=-1; /* default to isapnp activation */ 78static struct cadet cadet_card;
72static int radio_nr = -1;
73static int users;
74static int curtuner;
75static int tunestat;
76static int sigstrength;
77static wait_queue_head_t read_queue;
78static struct timer_list readtimer;
79static __u8 rdsin, rdsout, rdsstat;
80static unsigned char rdsbuf[RDS_BUFFER];
81static spinlock_t cadet_io_lock;
82
83static int cadet_probe(void);
84 79
85/* 80/*
86 * Signal Strength Threshold Values 81 * Signal Strength Threshold Values
87 * The V4L API spec does not define any particular unit for the signal 82 * The V4L API spec does not define any particular unit for the signal
88 * strength value. These values are in microvolts of RF at the tuner's input. 83 * strength value. These values are in microvolts of RF at the tuner's input.
89 */ 84 */
90static __u16 sigtable[2][4]={{5,10,30,150},{28,40,63,1000}}; 85static __u16 sigtable[2][4] = {
86 { 5, 10, 30, 150 },
87 { 28, 40, 63, 1000 }
88};
91 89
92 90
93static int 91static int cadet_getstereo(struct cadet *dev)
94cadet_getstereo(void)
95{ 92{
96 int ret = V4L2_TUNER_SUB_MONO; 93 int ret = V4L2_TUNER_SUB_MONO;
97 if(curtuner != 0) /* Only FM has stereo capability! */ 94
95 if (dev->curtuner != 0) /* Only FM has stereo capability! */
98 return V4L2_TUNER_SUB_MONO; 96 return V4L2_TUNER_SUB_MONO;
99 97
100 spin_lock(&cadet_io_lock); 98 mutex_lock(&dev->lock);
101 outb(7,io); /* Select tuner control */ 99 outb(7, dev->io); /* Select tuner control */
102 if( (inb(io+1) & 0x40) == 0) 100 if ((inb(dev->io + 1) & 0x40) == 0)
103 ret = V4L2_TUNER_SUB_STEREO; 101 ret = V4L2_TUNER_SUB_STEREO;
104 spin_unlock(&cadet_io_lock); 102 mutex_unlock(&dev->lock);
105 return ret; 103 return ret;
106} 104}
107 105
108static unsigned 106static unsigned cadet_gettune(struct cadet *dev)
109cadet_gettune(void)
110{ 107{
111 int curvol,i; 108 int curvol, i;
112 unsigned fifo=0; 109 unsigned fifo = 0;
113 110
114 /* 111 /*
115 * Prepare for read 112 * Prepare for read
116 */ 113 */
117 114
118 spin_lock(&cadet_io_lock); 115 mutex_lock(&dev->lock);
119 116
120 outb(7,io); /* Select tuner control */ 117 outb(7, dev->io); /* Select tuner control */
121 curvol=inb(io+1); /* Save current volume/mute setting */ 118 curvol = inb(dev->io + 1); /* Save current volume/mute setting */
122 outb(0x00,io+1); /* Ensure WRITE-ENABLE is LOW */ 119 outb(0x00, dev->io + 1); /* Ensure WRITE-ENABLE is LOW */
123 tunestat=0xffff; 120 dev->tunestat = 0xffff;
124 121
125 /* 122 /*
126 * Read the shift register 123 * Read the shift register
127 */ 124 */
128 for(i=0;i<25;i++) { 125 for (i = 0; i < 25; i++) {
129 fifo=(fifo<<1)|((inb(io+1)>>7)&0x01); 126 fifo = (fifo << 1) | ((inb(dev->io + 1) >> 7) & 0x01);
130 if(i<24) { 127 if (i < 24) {
131 outb(0x01,io+1); 128 outb(0x01, dev->io + 1);
132 tunestat&=inb(io+1); 129 dev->tunestat &= inb(dev->io + 1);
133 outb(0x00,io+1); 130 outb(0x00, dev->io + 1);
134 } 131 }
135 } 132 }
136 133
137 /* 134 /*
138 * Restore volume/mute setting 135 * Restore volume/mute setting
139 */ 136 */
140 outb(curvol,io+1); 137 outb(curvol, dev->io + 1);
141 spin_unlock(&cadet_io_lock); 138 mutex_unlock(&dev->lock);
142 139
143 return fifo; 140 return fifo;
144} 141}
145 142
146static unsigned 143static unsigned cadet_getfreq(struct cadet *dev)
147cadet_getfreq(void)
148{ 144{
149 int i; 145 int i;
150 unsigned freq=0,test,fifo=0; 146 unsigned freq = 0, test, fifo = 0;
151 147
152 /* 148 /*
153 * Read current tuning 149 * Read current tuning
154 */ 150 */
155 fifo=cadet_gettune(); 151 fifo = cadet_gettune(dev);
156 152
157 /* 153 /*
158 * Convert to actual frequency 154 * Convert to actual frequency
159 */ 155 */
160 if(curtuner==0) { /* FM */ 156 if (dev->curtuner == 0) { /* FM */
161 test=12500; 157 test = 12500;
162 for(i=0;i<14;i++) { 158 for (i = 0; i < 14; i++) {
163 if((fifo&0x01)!=0) { 159 if ((fifo & 0x01) != 0)
164 freq+=test; 160 freq += test;
165 } 161 test = test << 1;
166 test=test<<1; 162 fifo = fifo >> 1;
167 fifo=fifo>>1;
168 } 163 }
169 freq-=10700000; /* IF frequency is 10.7 MHz */ 164 freq -= 10700000; /* IF frequency is 10.7 MHz */
170 freq=(freq*16)/1000000; /* Make it 1/16 MHz */ 165 freq = (freq * 16) / 1000000; /* Make it 1/16 MHz */
171 }
172 if(curtuner==1) { /* AM */
173 freq=((fifo&0x7fff)-2010)*16;
174 } 166 }
167 if (dev->curtuner == 1) /* AM */
168 freq = ((fifo & 0x7fff) - 2010) * 16;
175 169
176 return freq; 170 return freq;
177} 171}
178 172
179static void 173static void cadet_settune(struct cadet *dev, unsigned fifo)
180cadet_settune(unsigned fifo)
181{ 174{
182 int i; 175 int i;
183 unsigned test; 176 unsigned test;
184 177
185 spin_lock(&cadet_io_lock); 178 mutex_lock(&dev->lock);
186 179
187 outb(7,io); /* Select tuner control */ 180 outb(7, dev->io); /* Select tuner control */
188 /* 181 /*
189 * Write the shift register 182 * Write the shift register
190 */ 183 */
191 test=0; 184 test = 0;
192 test=(fifo>>23)&0x02; /* Align data for SDO */ 185 test = (fifo >> 23) & 0x02; /* Align data for SDO */
193 test|=0x1c; /* SDM=1, SWE=1, SEN=1, SCK=0 */ 186 test |= 0x1c; /* SDM=1, SWE=1, SEN=1, SCK=0 */
194 outb(7,io); /* Select tuner control */ 187 outb(7, dev->io); /* Select tuner control */
195 outb(test,io+1); /* Initialize for write */ 188 outb(test, dev->io + 1); /* Initialize for write */
196 for(i=0;i<25;i++) { 189 for (i = 0; i < 25; i++) {
197 test|=0x01; /* Toggle SCK High */ 190 test |= 0x01; /* Toggle SCK High */
198 outb(test,io+1); 191 outb(test, dev->io + 1);
199 test&=0xfe; /* Toggle SCK Low */ 192 test &= 0xfe; /* Toggle SCK Low */
200 outb(test,io+1); 193 outb(test, dev->io + 1);
201 fifo=fifo<<1; /* Prepare the next bit */ 194 fifo = fifo << 1; /* Prepare the next bit */
202 test=0x1c|((fifo>>23)&0x02); 195 test = 0x1c | ((fifo >> 23) & 0x02);
203 outb(test,io+1); 196 outb(test, dev->io + 1);
204 } 197 }
205 spin_unlock(&cadet_io_lock); 198 mutex_unlock(&dev->lock);
206} 199}
207 200
208static void 201static void cadet_setfreq(struct cadet *dev, unsigned freq)
209cadet_setfreq(unsigned freq)
210{ 202{
211 unsigned fifo; 203 unsigned fifo;
212 int i,j,test; 204 int i, j, test;
213 int curvol; 205 int curvol;
214 206
215 /* 207 /*
216 * Formulate a fifo command 208 * Formulate a fifo command
217 */ 209 */
218 fifo=0; 210 fifo = 0;
219 if(curtuner==0) { /* FM */ 211 if (dev->curtuner == 0) { /* FM */
220 test=102400; 212 test = 102400;
221 freq=(freq*1000)/16; /* Make it kHz */ 213 freq = (freq * 1000) / 16; /* Make it kHz */
222 freq+=10700; /* IF is 10700 kHz */ 214 freq += 10700; /* IF is 10700 kHz */
223 for(i=0;i<14;i++) { 215 for (i = 0; i < 14; i++) {
224 fifo=fifo<<1; 216 fifo = fifo << 1;
225 if(freq>=test) { 217 if (freq >= test) {
226 fifo|=0x01; 218 fifo |= 0x01;
227 freq-=test; 219 freq -= test;
228 } 220 }
229 test=test>>1; 221 test = test >> 1;
230 } 222 }
231 } 223 }
232 if(curtuner==1) { /* AM */ 224 if (dev->curtuner == 1) { /* AM */
233 fifo=(freq/16)+2010; /* Make it kHz */ 225 fifo = (freq / 16) + 2010; /* Make it kHz */
234 fifo|=0x100000; /* Select AM Band */ 226 fifo |= 0x100000; /* Select AM Band */
235 } 227 }
236 228
237 /* 229 /*
238 * Save current volume/mute setting 230 * Save current volume/mute setting
239 */ 231 */
240 232
241 spin_lock(&cadet_io_lock); 233 mutex_lock(&dev->lock);
242 outb(7,io); /* Select tuner control */ 234 outb(7, dev->io); /* Select tuner control */
243 curvol=inb(io+1); 235 curvol = inb(dev->io + 1);
244 spin_unlock(&cadet_io_lock); 236 mutex_unlock(&dev->lock);
245 237
246 /* 238 /*
247 * Tune the card 239 * Tune the card
248 */ 240 */
249 for(j=3;j>-1;j--) { 241 for (j = 3; j > -1; j--) {
250 cadet_settune(fifo|(j<<16)); 242 cadet_settune(dev, fifo | (j << 16));
251 243
252 spin_lock(&cadet_io_lock); 244 mutex_lock(&dev->lock);
253 outb(7,io); /* Select tuner control */ 245 outb(7, dev->io); /* Select tuner control */
254 outb(curvol,io+1); 246 outb(curvol, dev->io + 1);
255 spin_unlock(&cadet_io_lock); 247 mutex_unlock(&dev->lock);
256 248
257 msleep(100); 249 msleep(100);
258 250
259 cadet_gettune(); 251 cadet_gettune(dev);
260 if((tunestat & 0x40) == 0) { /* Tuned */ 252 if ((dev->tunestat & 0x40) == 0) { /* Tuned */
261 sigstrength=sigtable[curtuner][j]; 253 dev->sigstrength = sigtable[dev->curtuner][j];
262 return; 254 return;
263 } 255 }
264 } 256 }
265 sigstrength=0; 257 dev->sigstrength = 0;
266} 258}
267 259
268 260
269static int 261static int cadet_getvol(struct cadet *dev)
270cadet_getvol(void)
271{ 262{
272 int ret = 0; 263 int ret = 0;
273 264
274 spin_lock(&cadet_io_lock); 265 mutex_lock(&dev->lock);
275 266
276 outb(7,io); /* Select tuner control */ 267 outb(7, dev->io); /* Select tuner control */
277 if((inb(io + 1) & 0x20) != 0) 268 if ((inb(dev->io + 1) & 0x20) != 0)
278 ret = 0xffff; 269 ret = 0xffff;
279 270
280 spin_unlock(&cadet_io_lock); 271 mutex_unlock(&dev->lock);
281 return ret; 272 return ret;
282} 273}
283 274
284 275
285static void 276static void cadet_setvol(struct cadet *dev, int vol)
286cadet_setvol(int vol)
287{ 277{
288 spin_lock(&cadet_io_lock); 278 mutex_lock(&dev->lock);
289 outb(7,io); /* Select tuner control */ 279 outb(7, dev->io); /* Select tuner control */
290 if(vol>0) 280 if (vol > 0)
291 outb(0x20,io+1); 281 outb(0x20, dev->io + 1);
292 else 282 else
293 outb(0x00,io+1); 283 outb(0x00, dev->io + 1);
294 spin_unlock(&cadet_io_lock); 284 mutex_unlock(&dev->lock);
295} 285}
296 286
297static void 287static void cadet_handler(unsigned long data)
298cadet_handler(unsigned long data)
299{ 288{
300 /* 289 struct cadet *dev = (void *)data;
301 * Service the RDS fifo
302 */
303 290
304 if(spin_trylock(&cadet_io_lock)) 291 /* Service the RDS fifo */
305 { 292 if (mutex_trylock(&dev->lock)) {
306 outb(0x3,io); /* Select RDS Decoder Control */ 293 outb(0x3, dev->io); /* Select RDS Decoder Control */
307 if((inb(io+1)&0x20)!=0) { 294 if ((inb(dev->io + 1) & 0x20) != 0)
308 printk(KERN_CRIT "cadet: RDS fifo overflow\n"); 295 printk(KERN_CRIT "cadet: RDS fifo overflow\n");
309 } 296 outb(0x80, dev->io); /* Select RDS fifo */
310 outb(0x80,io); /* Select RDS fifo */ 297 while ((inb(dev->io) & 0x80) != 0) {
311 while((inb(io)&0x80)!=0) { 298 dev->rdsbuf[dev->rdsin] = inb(dev->io + 1);
312 rdsbuf[rdsin]=inb(io+1); 299 if (dev->rdsin == dev->rdsout)
313 if(rdsin==rdsout)
314 printk(KERN_WARNING "cadet: RDS buffer overflow\n"); 300 printk(KERN_WARNING "cadet: RDS buffer overflow\n");
315 else 301 else
316 rdsin++; 302 dev->rdsin++;
317 } 303 }
318 spin_unlock(&cadet_io_lock); 304 mutex_unlock(&dev->lock);
319 } 305 }
320 306
321 /* 307 /*
322 * Service pending read 308 * Service pending read
323 */ 309 */
324 if( rdsin!=rdsout) 310 if (dev->rdsin != dev->rdsout)
325 wake_up_interruptible(&read_queue); 311 wake_up_interruptible(&dev->read_queue);
326 312
327 /* 313 /*
328 * Clean up and exit 314 * Clean up and exit
329 */ 315 */
330 init_timer(&readtimer); 316 init_timer(&dev->readtimer);
331 readtimer.function=cadet_handler; 317 dev->readtimer.function = cadet_handler;
332 readtimer.data=(unsigned long)0; 318 dev->readtimer.data = (unsigned long)0;
333 readtimer.expires=jiffies+msecs_to_jiffies(50); 319 dev->readtimer.expires = jiffies + msecs_to_jiffies(50);
334 add_timer(&readtimer); 320 add_timer(&dev->readtimer);
335} 321}
336 322
337 323
338 324static ssize_t cadet_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
339static ssize_t
340cadet_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
341{ 325{
342 int i=0; 326 struct cadet *dev = video_drvdata(file);
343 unsigned char readbuf[RDS_BUFFER]; 327 unsigned char readbuf[RDS_BUFFER];
344 328 int i = 0;
345 if(rdsstat==0) { 329
346 spin_lock(&cadet_io_lock); 330 if (dev->rdsstat == 0) {
347 rdsstat=1; 331 mutex_lock(&dev->lock);
348 outb(0x80,io); /* Select RDS fifo */ 332 dev->rdsstat = 1;
349 spin_unlock(&cadet_io_lock); 333 outb(0x80, dev->io); /* Select RDS fifo */
350 init_timer(&readtimer); 334 mutex_unlock(&dev->lock);
351 readtimer.function=cadet_handler; 335 init_timer(&dev->readtimer);
352 readtimer.data=(unsigned long)0; 336 dev->readtimer.function = cadet_handler;
353 readtimer.expires=jiffies+msecs_to_jiffies(50); 337 dev->readtimer.data = (unsigned long)dev;
354 add_timer(&readtimer); 338 dev->readtimer.expires = jiffies + msecs_to_jiffies(50);
339 add_timer(&dev->readtimer);
355 } 340 }
356 if(rdsin==rdsout) { 341 if (dev->rdsin == dev->rdsout) {
357 if (file->f_flags & O_NONBLOCK) 342 if (file->f_flags & O_NONBLOCK)
358 return -EWOULDBLOCK; 343 return -EWOULDBLOCK;
359 interruptible_sleep_on(&read_queue); 344 interruptible_sleep_on(&dev->read_queue);
360 } 345 }
361 while( i<count && rdsin!=rdsout) 346 while (i < count && dev->rdsin != dev->rdsout)
362 readbuf[i++]=rdsbuf[rdsout++]; 347 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
363 348
364 if (copy_to_user(data,readbuf,i)) 349 if (copy_to_user(data, readbuf, i))
365 return -EFAULT; 350 return -EFAULT;
366 return i; 351 return i;
367} 352}
@@ -370,38 +355,40 @@ cadet_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
370static int vidioc_querycap(struct file *file, void *priv, 355static int vidioc_querycap(struct file *file, void *priv,
371 struct v4l2_capability *v) 356 struct v4l2_capability *v)
372{ 357{
373 v->capabilities = 358 strlcpy(v->driver, "ADS Cadet", sizeof(v->driver));
374 V4L2_CAP_TUNER | 359 strlcpy(v->card, "ADS Cadet", sizeof(v->card));
375 V4L2_CAP_READWRITE; 360 strlcpy(v->bus_info, "ISA", sizeof(v->bus_info));
376 v->version = CADET_VERSION; 361 v->version = CADET_VERSION;
377 strcpy(v->driver, "ADS Cadet"); 362 v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO | V4L2_CAP_READWRITE;
378 strcpy(v->card, "ADS Cadet");
379 return 0; 363 return 0;
380} 364}
381 365
382static int vidioc_g_tuner(struct file *file, void *priv, 366static int vidioc_g_tuner(struct file *file, void *priv,
383 struct v4l2_tuner *v) 367 struct v4l2_tuner *v)
384{ 368{
369 struct cadet *dev = video_drvdata(file);
370
385 v->type = V4L2_TUNER_RADIO; 371 v->type = V4L2_TUNER_RADIO;
386 switch (v->index) { 372 switch (v->index) {
387 case 0: 373 case 0:
388 strcpy(v->name, "FM"); 374 strlcpy(v->name, "FM", sizeof(v->name));
389 v->capability = V4L2_TUNER_CAP_STEREO; 375 v->capability = V4L2_TUNER_CAP_STEREO;
390 v->rangelow = 1400; /* 87.5 MHz */ 376 v->rangelow = 1400; /* 87.5 MHz */
391 v->rangehigh = 1728; /* 108.0 MHz */ 377 v->rangehigh = 1728; /* 108.0 MHz */
392 v->rxsubchans=cadet_getstereo(); 378 v->rxsubchans = cadet_getstereo(dev);
393 switch (v->rxsubchans){ 379 switch (v->rxsubchans) {
394 case V4L2_TUNER_SUB_MONO: 380 case V4L2_TUNER_SUB_MONO:
395 v->audmode = V4L2_TUNER_MODE_MONO; 381 v->audmode = V4L2_TUNER_MODE_MONO;
396 break; 382 break;
397 case V4L2_TUNER_SUB_STEREO: 383 case V4L2_TUNER_SUB_STEREO:
398 v->audmode = V4L2_TUNER_MODE_STEREO; 384 v->audmode = V4L2_TUNER_MODE_STEREO;
399 break; 385 break;
400 default: ; 386 default:
387 break;
401 } 388 }
402 break; 389 break;
403 case 1: 390 case 1:
404 strcpy(v->name, "AM"); 391 strlcpy(v->name, "AM", sizeof(v->name));
405 v->capability = V4L2_TUNER_CAP_LOW; 392 v->capability = V4L2_TUNER_CAP_LOW;
406 v->rangelow = 8320; /* 520 kHz */ 393 v->rangelow = 8320; /* 520 kHz */
407 v->rangehigh = 26400; /* 1650 kHz */ 394 v->rangehigh = 26400; /* 1650 kHz */
@@ -411,25 +398,29 @@ static int vidioc_g_tuner(struct file *file, void *priv,
411 default: 398 default:
412 return -EINVAL; 399 return -EINVAL;
413 } 400 }
414 v->signal = sigstrength; /* We might need to modify scaling of this */ 401 v->signal = dev->sigstrength; /* We might need to modify scaling of this */
415 return 0; 402 return 0;
416} 403}
417 404
418static int vidioc_s_tuner(struct file *file, void *priv, 405static int vidioc_s_tuner(struct file *file, void *priv,
419 struct v4l2_tuner *v) 406 struct v4l2_tuner *v)
420{ 407{
421 if((v->index != 0)&&(v->index != 1)) 408 struct cadet *dev = video_drvdata(file);
409
410 if (v->index != 0 && v->index != 1)
422 return -EINVAL; 411 return -EINVAL;
423 curtuner = v->index; 412 dev->curtuner = v->index;
424 return 0; 413 return 0;
425} 414}
426 415
427static int vidioc_g_frequency(struct file *file, void *priv, 416static int vidioc_g_frequency(struct file *file, void *priv,
428 struct v4l2_frequency *f) 417 struct v4l2_frequency *f)
429{ 418{
430 f->tuner = curtuner; 419 struct cadet *dev = video_drvdata(file);
420
421 f->tuner = dev->curtuner;
431 f->type = V4L2_TUNER_RADIO; 422 f->type = V4L2_TUNER_RADIO;
432 f->frequency = cadet_getfreq(); 423 f->frequency = cadet_getfreq(dev);
433 return 0; 424 return 0;
434} 425}
435 426
@@ -437,27 +428,26 @@ static int vidioc_g_frequency(struct file *file, void *priv,
437static int vidioc_s_frequency(struct file *file, void *priv, 428static int vidioc_s_frequency(struct file *file, void *priv,
438 struct v4l2_frequency *f) 429 struct v4l2_frequency *f)
439{ 430{
431 struct cadet *dev = video_drvdata(file);
432
440 if (f->type != V4L2_TUNER_RADIO) 433 if (f->type != V4L2_TUNER_RADIO)
441 return -EINVAL; 434 return -EINVAL;
442 if((curtuner==0)&&((f->frequency<1400)||(f->frequency>1728))) 435 if (dev->curtuner == 0 && (f->frequency < 1400 || f->frequency > 1728))
443 return -EINVAL; 436 return -EINVAL;
444 if((curtuner==1)&&((f->frequency<8320)||(f->frequency>26400))) 437 if (dev->curtuner == 1 && (f->frequency < 8320 || f->frequency > 26400))
445 return -EINVAL; 438 return -EINVAL;
446 cadet_setfreq(f->frequency); 439 cadet_setfreq(dev, f->frequency);
447 return 0; 440 return 0;
448} 441}
449 442
450static int vidioc_queryctrl(struct file *file, void *priv, 443static int vidioc_queryctrl(struct file *file, void *priv,
451 struct v4l2_queryctrl *qc) 444 struct v4l2_queryctrl *qc)
452{ 445{
453 int i; 446 switch (qc->id) {
454 447 case V4L2_CID_AUDIO_MUTE:
455 for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) { 448 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
456 if (qc->id && qc->id == radio_qctrl[i].id) { 449 case V4L2_CID_AUDIO_VOLUME:
457 memcpy(qc, &(radio_qctrl[i]), 450 return v4l2_ctrl_query_fill(qc, 0, 0xff, 1, 0xff);
458 sizeof(*qc));
459 return 0;
460 }
461 } 451 }
462 return -EINVAL; 452 return -EINVAL;
463} 453}
@@ -465,12 +455,14 @@ static int vidioc_queryctrl(struct file *file, void *priv,
465static int vidioc_g_ctrl(struct file *file, void *priv, 455static int vidioc_g_ctrl(struct file *file, void *priv,
466 struct v4l2_control *ctrl) 456 struct v4l2_control *ctrl)
467{ 457{
468 switch (ctrl->id){ 458 struct cadet *dev = video_drvdata(file);
459
460 switch (ctrl->id) {
469 case V4L2_CID_AUDIO_MUTE: /* TODO: Handle this correctly */ 461 case V4L2_CID_AUDIO_MUTE: /* TODO: Handle this correctly */
470 ctrl->value = (cadet_getvol() == 0); 462 ctrl->value = (cadet_getvol(dev) == 0);
471 break; 463 break;
472 case V4L2_CID_AUDIO_VOLUME: 464 case V4L2_CID_AUDIO_VOLUME:
473 ctrl->value = cadet_getvol(); 465 ctrl->value = cadet_getvol(dev);
474 break; 466 break;
475 default: 467 default:
476 return -EINVAL; 468 return -EINVAL;
@@ -481,15 +473,17 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
481static int vidioc_s_ctrl(struct file *file, void *priv, 473static int vidioc_s_ctrl(struct file *file, void *priv,
482 struct v4l2_control *ctrl) 474 struct v4l2_control *ctrl)
483{ 475{
476 struct cadet *dev = video_drvdata(file);
477
484 switch (ctrl->id){ 478 switch (ctrl->id){
485 case V4L2_CID_AUDIO_MUTE: /* TODO: Handle this correctly */ 479 case V4L2_CID_AUDIO_MUTE: /* TODO: Handle this correctly */
486 if (ctrl->value) 480 if (ctrl->value)
487 cadet_setvol(0); 481 cadet_setvol(dev, 0);
488 else 482 else
489 cadet_setvol(0xffff); 483 cadet_setvol(dev, 0xffff);
490 break; 484 break;
491 case V4L2_CID_AUDIO_VOLUME: 485 case V4L2_CID_AUDIO_VOLUME:
492 cadet_setvol(ctrl->value); 486 cadet_setvol(dev, ctrl->value);
493 break; 487 break;
494 default: 488 default:
495 return -EINVAL; 489 return -EINVAL;
@@ -497,16 +491,6 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
497 return 0; 491 return 0;
498} 492}
499 493
500static int vidioc_g_audio(struct file *file, void *priv,
501 struct v4l2_audio *a)
502{
503 if (a->index > 1)
504 return -EINVAL;
505 strcpy(a->name, "Radio");
506 a->capability = V4L2_AUDCAP_STEREO;
507 return 0;
508}
509
510static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i) 494static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
511{ 495{
512 *i = 0; 496 *i = 0;
@@ -515,43 +499,52 @@ static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
515 499
516static int vidioc_s_input(struct file *filp, void *priv, unsigned int i) 500static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
517{ 501{
518 if (i != 0) 502 return i ? -EINVAL : 0;
519 return -EINVAL; 503}
504
505static int vidioc_g_audio(struct file *file, void *priv,
506 struct v4l2_audio *a)
507{
508 a->index = 0;
509 strlcpy(a->name, "Radio", sizeof(a->name));
510 a->capability = V4L2_AUDCAP_STEREO;
520 return 0; 511 return 0;
521} 512}
522 513
523static int vidioc_s_audio(struct file *file, void *priv, 514static int vidioc_s_audio(struct file *file, void *priv,
524 struct v4l2_audio *a) 515 struct v4l2_audio *a)
525{ 516{
526 if (a->index != 0) 517 return a->index ? -EINVAL : 0;
527 return -EINVAL;
528 return 0;
529} 518}
530 519
531static int 520static int cadet_open(struct file *file)
532cadet_open(struct file *file)
533{ 521{
534 users++; 522 struct cadet *dev = video_drvdata(file);
535 if (1 == users) init_waitqueue_head(&read_queue); 523
524 dev->users++;
525 if (1 == dev->users)
526 init_waitqueue_head(&dev->read_queue);
536 return 0; 527 return 0;
537} 528}
538 529
539static int 530static int cadet_release(struct file *file)
540cadet_release(struct file *file)
541{ 531{
542 users--; 532 struct cadet *dev = video_drvdata(file);
543 if (0 == users){ 533
544 del_timer_sync(&readtimer); 534 dev->users--;
545 rdsstat=0; 535 if (0 == dev->users) {
536 del_timer_sync(&dev->readtimer);
537 dev->rdsstat = 0;
546 } 538 }
547 return 0; 539 return 0;
548} 540}
549 541
550static unsigned int 542static unsigned int cadet_poll(struct file *file, struct poll_table_struct *wait)
551cadet_poll(struct file *file, struct poll_table_struct *wait)
552{ 543{
553 poll_wait(file,&read_queue,wait); 544 struct cadet *dev = video_drvdata(file);
554 if(rdsin != rdsout) 545
546 poll_wait(file, &dev->read_queue, wait);
547 if (dev->rdsin != dev->rdsout)
555 return POLLIN | POLLRDNORM; 548 return POLLIN | POLLRDNORM;
556 return 0; 549 return 0;
557} 550}
@@ -581,13 +574,6 @@ static const struct v4l2_ioctl_ops cadet_ioctl_ops = {
581 .vidioc_s_input = vidioc_s_input, 574 .vidioc_s_input = vidioc_s_input,
582}; 575};
583 576
584static struct video_device cadet_radio = {
585 .name = "Cadet radio",
586 .fops = &cadet_fops,
587 .ioctl_ops = &cadet_ioctl_ops,
588 .release = video_device_release_empty,
589};
590
591#ifdef CONFIG_PNP 577#ifdef CONFIG_PNP
592 578
593static struct pnp_device_id cadet_pnp_devices[] = { 579static struct pnp_device_id cadet_pnp_devices[] = {
@@ -598,7 +584,7 @@ static struct pnp_device_id cadet_pnp_devices[] = {
598 584
599MODULE_DEVICE_TABLE(pnp, cadet_pnp_devices); 585MODULE_DEVICE_TABLE(pnp, cadet_pnp_devices);
600 586
601static int cadet_pnp_probe(struct pnp_dev * dev, const struct pnp_device_id *dev_id) 587static int cadet_pnp_probe(struct pnp_dev *dev, const struct pnp_device_id *dev_id)
602{ 588{
603 if (!dev) 589 if (!dev)
604 return -ENODEV; 590 return -ENODEV;
@@ -606,13 +592,12 @@ static int cadet_pnp_probe(struct pnp_dev * dev, const struct pnp_device_id *dev
606 if (io > 0) 592 if (io > 0)
607 return -EBUSY; 593 return -EBUSY;
608 594
609 if (!pnp_port_valid(dev, 0)) { 595 if (!pnp_port_valid(dev, 0))
610 return -ENODEV; 596 return -ENODEV;
611 }
612 597
613 io = pnp_port_start(dev, 0); 598 io = pnp_port_start(dev, 0);
614 599
615 printk ("radio-cadet: PnP reports device at %#x\n", io); 600 printk(KERN_INFO "radio-cadet: PnP reports device at %#x\n", io);
616 601
617 return io; 602 return io;
618} 603}
@@ -628,23 +613,23 @@ static struct pnp_driver cadet_pnp_driver = {
628static struct pnp_driver cadet_pnp_driver; 613static struct pnp_driver cadet_pnp_driver;
629#endif 614#endif
630 615
631static int cadet_probe(void) 616static void cadet_probe(struct cadet *dev)
632{ 617{
633 static int iovals[8]={0x330,0x332,0x334,0x336,0x338,0x33a,0x33c,0x33e}; 618 static int iovals[8] = { 0x330, 0x332, 0x334, 0x336, 0x338, 0x33a, 0x33c, 0x33e };
634 int i; 619 int i;
635 620
636 for(i=0;i<8;i++) { 621 for (i = 0; i < 8; i++) {
637 io=iovals[i]; 622 dev->io = iovals[i];
638 if (request_region(io, 2, "cadet-probe")) { 623 if (request_region(dev->io, 2, "cadet-probe")) {
639 cadet_setfreq(1410); 624 cadet_setfreq(dev, 1410);
640 if(cadet_getfreq()==1410) { 625 if (cadet_getfreq(dev) == 1410) {
641 release_region(io, 2); 626 release_region(dev->io, 2);
642 return io; 627 return;
643 } 628 }
644 release_region(io, 2); 629 release_region(dev->io, 2);
645 } 630 }
646 } 631 }
647 return -1; 632 dev->io = -1;
648} 633}
649 634
650/* 635/*
@@ -654,59 +639,69 @@ static int cadet_probe(void)
654 639
655static int __init cadet_init(void) 640static int __init cadet_init(void)
656{ 641{
657 spin_lock_init(&cadet_io_lock); 642 struct cadet *dev = &cadet_card;
643 struct v4l2_device *v4l2_dev = &dev->v4l2_dev;
644 int res;
658 645
659 /* 646 strlcpy(v4l2_dev->name, "cadet", sizeof(v4l2_dev->name));
660 * If a probe was requested then probe ISAPnP first (safest) 647 mutex_init(&dev->lock);
661 */ 648
649 /* If a probe was requested then probe ISAPnP first (safest) */
662 if (io < 0) 650 if (io < 0)
663 pnp_register_driver(&cadet_pnp_driver); 651 pnp_register_driver(&cadet_pnp_driver);
664 /* 652 dev->io = io;
665 * If that fails then probe unsafely if probe is requested
666 */
667 if(io < 0)
668 io = cadet_probe ();
669 653
670 /* 654 /* If that fails then probe unsafely if probe is requested */
671 * Else we bail out 655 if (dev->io < 0)
672 */ 656 cadet_probe(dev);
673 657
674 if(io < 0) { 658 /* Else we bail out */
659 if (dev->io < 0) {
675#ifdef MODULE 660#ifdef MODULE
676 printk(KERN_ERR "You must set an I/O address with io=0x???\n"); 661 v4l2_err(v4l2_dev, "you must set an I/O address with io=0x330, 0x332, 0x334,\n");
662 v4l2_err(v4l2_dev, "0x336, 0x338, 0x33a, 0x33c or 0x33e\n");
677#endif 663#endif
678 goto fail; 664 goto fail;
679 } 665 }
680 if (!request_region(io,2,"cadet")) 666 if (!request_region(dev->io, 2, "cadet"))
667 goto fail;
668
669 res = v4l2_device_register(NULL, v4l2_dev);
670 if (res < 0) {
671 release_region(dev->io, 2);
672 v4l2_err(v4l2_dev, "could not register v4l2_device\n");
681 goto fail; 673 goto fail;
682 if (video_register_device(&cadet_radio, VFL_TYPE_RADIO, radio_nr) < 0) { 674 }
683 release_region(io,2); 675
676 strlcpy(dev->vdev.name, v4l2_dev->name, sizeof(dev->vdev.name));
677 dev->vdev.v4l2_dev = v4l2_dev;
678 dev->vdev.fops = &cadet_fops;
679 dev->vdev.ioctl_ops = &cadet_ioctl_ops;
680 dev->vdev.release = video_device_release_empty;
681 video_set_drvdata(&dev->vdev, dev);
682
683 if (video_register_device(&dev->vdev, VFL_TYPE_RADIO, radio_nr) < 0) {
684 v4l2_device_unregister(v4l2_dev);
685 release_region(dev->io, 2);
684 goto fail; 686 goto fail;
685 } 687 }
686 printk(KERN_INFO "ADS Cadet Radio Card at 0x%x\n",io); 688 v4l2_info(v4l2_dev, "ADS Cadet Radio Card at 0x%x\n", dev->io);
687 return 0; 689 return 0;
688fail: 690fail:
689 pnp_unregister_driver(&cadet_pnp_driver); 691 pnp_unregister_driver(&cadet_pnp_driver);
690 return -1; 692 return -ENODEV;
691} 693}
692 694
693 695static void __exit cadet_exit(void)
694
695MODULE_AUTHOR("Fred Gleason, Russell Kroll, Quay Lu, Donald Song, Jason Lewis, Scott McGrath, William McGrath");
696MODULE_DESCRIPTION("A driver for the ADS Cadet AM/FM/RDS radio card.");
697MODULE_LICENSE("GPL");
698
699module_param(io, int, 0);
700MODULE_PARM_DESC(io, "I/O address of Cadet card (0x330,0x332,0x334,0x336,0x338,0x33a,0x33c,0x33e)");
701module_param(radio_nr, int, 0);
702
703static void __exit cadet_cleanup_module(void)
704{ 696{
705 video_unregister_device(&cadet_radio); 697 struct cadet *dev = &cadet_card;
706 release_region(io,2); 698
699 video_unregister_device(&dev->vdev);
700 v4l2_device_unregister(&dev->v4l2_dev);
701 release_region(dev->io, 2);
707 pnp_unregister_driver(&cadet_pnp_driver); 702 pnp_unregister_driver(&cadet_pnp_driver);
708} 703}
709 704
710module_init(cadet_init); 705module_init(cadet_init);
711module_exit(cadet_cleanup_module); 706module_exit(cadet_exit);
712 707
diff --git a/drivers/media/radio/radio-gemtek-pci.c b/drivers/media/radio/radio-gemtek-pci.c
index 0c96bf8525b0..09265d25725e 100644
--- a/drivers/media/radio/radio-gemtek-pci.c
+++ b/drivers/media/radio/radio-gemtek-pci.c
@@ -45,34 +45,25 @@
45#include <linux/init.h> 45#include <linux/init.h>
46#include <linux/pci.h> 46#include <linux/pci.h>
47#include <linux/videodev2.h> 47#include <linux/videodev2.h>
48#include <media/v4l2-common.h>
49#include <media/v4l2-ioctl.h>
50#include <linux/errno.h> 48#include <linux/errno.h>
51
52#include <linux/version.h> /* for KERNEL_VERSION MACRO */ 49#include <linux/version.h> /* for KERNEL_VERSION MACRO */
53#define RADIO_VERSION KERNEL_VERSION(0,0,2) 50#include <linux/io.h>
54 51#include <media/v4l2-device.h>
55static struct v4l2_queryctrl radio_qctrl[] = { 52#include <media/v4l2-ioctl.h>
56 {
57 .id = V4L2_CID_AUDIO_MUTE,
58 .name = "Mute",
59 .minimum = 0,
60 .maximum = 1,
61 .default_value = 1,
62 .type = V4L2_CTRL_TYPE_BOOLEAN,
63 },{
64 .id = V4L2_CID_AUDIO_VOLUME,
65 .name = "Volume",
66 .minimum = 0,
67 .maximum = 65535,
68 .step = 65535,
69 .default_value = 0xff,
70 .type = V4L2_CTRL_TYPE_INTEGER,
71 }
72};
73 53
74#include <asm/io.h> 54MODULE_AUTHOR("Vladimir Shebordaev <vshebordaev@mail.ru>");
75#include <asm/uaccess.h> 55MODULE_DESCRIPTION("The video4linux driver for the Gemtek PCI Radio Card");
56MODULE_LICENSE("GPL");
57
58static int nr_radio = -1;
59static int mx = 1;
60
61module_param(mx, bool, 0);
62MODULE_PARM_DESC(mx, "single digit: 1 - turn off the turner upon module exit (default), 0 - do not");
63module_param(nr_radio, int, 0);
64MODULE_PARM_DESC(nr_radio, "video4linux device number to use");
65
66#define RADIO_VERSION KERNEL_VERSION(0, 0, 2)
76 67
77#ifndef PCI_VENDOR_ID_GEMTEK 68#ifndef PCI_VENDOR_ID_GEMTEK
78#define PCI_VENDOR_ID_GEMTEK 0x5046 69#define PCI_VENDOR_ID_GEMTEK 0x5046
@@ -90,8 +81,11 @@ static struct v4l2_queryctrl radio_qctrl[] = {
90#define GEMTEK_PCI_RANGE_HIGH (108*16000) 81#define GEMTEK_PCI_RANGE_HIGH (108*16000)
91#endif 82#endif
92 83
93struct gemtek_pci_card { 84struct gemtek_pci {
94 struct video_device *videodev; 85 struct v4l2_device v4l2_dev;
86 struct video_device vdev;
87 struct mutex lock;
88 struct pci_dev *pdev;
95 89
96 u32 iobase; 90 u32 iobase;
97 u32 length; 91 u32 length;
@@ -100,116 +94,133 @@ struct gemtek_pci_card {
100 u8 mute; 94 u8 mute;
101}; 95};
102 96
103static int nr_radio = -1; 97static inline struct gemtek_pci *to_gemtek_pci(struct v4l2_device *v4l2_dev)
104static unsigned long in_use; 98{
99 return container_of(v4l2_dev, struct gemtek_pci, v4l2_dev);
100}
105 101
106static inline u8 gemtek_pci_out( u16 value, u32 port ) 102static inline u8 gemtek_pci_out(u16 value, u32 port)
107{ 103{
108 outw( value, port ); 104 outw(value, port);
109 105
110 return (u8)value; 106 return (u8)value;
111} 107}
112 108
113#define _b0( v ) *((u8 *)&v) 109#define _b0(v) (*((u8 *)&v))
114static void __gemtek_pci_cmd( u16 value, u32 port, u8 *last_byte, int keep ) 110
111static void __gemtek_pci_cmd(u16 value, u32 port, u8 *last_byte, int keep)
115{ 112{
116 register u8 byte = *last_byte; 113 u8 byte = *last_byte;
117 114
118 if ( !value ) { 115 if (!value) {
119 if ( !keep ) 116 if (!keep)
120 value = (u16)port; 117 value = (u16)port;
121 byte &= 0xfd; 118 byte &= 0xfd;
122 } else 119 } else
123 byte |= 2; 120 byte |= 2;
124 121
125 _b0( value ) = byte; 122 _b0(value) = byte;
126 outw( value, port ); 123 outw(value, port);
127 byte |= 1; 124 byte |= 1;
128 _b0( value ) = byte; 125 _b0(value) = byte;
129 outw( value, port ); 126 outw(value, port);
130 byte &= 0xfe; 127 byte &= 0xfe;
131 _b0( value ) = byte; 128 _b0(value) = byte;
132 outw( value, port ); 129 outw(value, port);
133 130
134 *last_byte = byte; 131 *last_byte = byte;
135} 132}
136 133
137static inline void gemtek_pci_nil( u32 port, u8 *last_byte ) 134static inline void gemtek_pci_nil(u32 port, u8 *last_byte)
138{ 135{
139 __gemtek_pci_cmd( 0x00, port, last_byte, false ); 136 __gemtek_pci_cmd(0x00, port, last_byte, false);
140} 137}
141 138
142static inline void gemtek_pci_cmd( u16 cmd, u32 port, u8 *last_byte ) 139static inline void gemtek_pci_cmd(u16 cmd, u32 port, u8 *last_byte)
143{ 140{
144 __gemtek_pci_cmd( cmd, port, last_byte, true ); 141 __gemtek_pci_cmd(cmd, port, last_byte, true);
145} 142}
146 143
147static void gemtek_pci_setfrequency( struct gemtek_pci_card *card, unsigned long frequency ) 144static void gemtek_pci_setfrequency(struct gemtek_pci *card, unsigned long frequency)
148{ 145{
149 register int i; 146 int i;
150 register u32 value = frequency / 200 + 856; 147 u32 value = frequency / 200 + 856;
151 register u16 mask = 0x8000; 148 u16 mask = 0x8000;
152 u8 last_byte; 149 u8 last_byte;
153 u32 port = card->iobase; 150 u32 port = card->iobase;
154 151
155 last_byte = gemtek_pci_out( 0x06, port ); 152 mutex_lock(&card->lock);
153 card->current_frequency = frequency;
154 last_byte = gemtek_pci_out(0x06, port);
156 155
157 i = 0; 156 i = 0;
158 do { 157 do {
159 gemtek_pci_nil( port, &last_byte ); 158 gemtek_pci_nil(port, &last_byte);
160 i++; 159 i++;
161 } while ( i < 9 ); 160 } while (i < 9);
162 161
163 i = 0; 162 i = 0;
164 do { 163 do {
165 gemtek_pci_cmd( value & mask, port, &last_byte ); 164 gemtek_pci_cmd(value & mask, port, &last_byte);
166 mask >>= 1; 165 mask >>= 1;
167 i++; 166 i++;
168 } while ( i < 16 ); 167 } while (i < 16);
169 168
170 outw( 0x10, port ); 169 outw(0x10, port);
170 mutex_unlock(&card->lock);
171} 171}
172 172
173 173
174static inline void gemtek_pci_mute( struct gemtek_pci_card *card ) 174static void gemtek_pci_mute(struct gemtek_pci *card)
175{ 175{
176 outb( 0x1f, card->iobase ); 176 mutex_lock(&card->lock);
177 outb(0x1f, card->iobase);
177 card->mute = true; 178 card->mute = true;
179 mutex_unlock(&card->lock);
178} 180}
179 181
180static inline void gemtek_pci_unmute( struct gemtek_pci_card *card ) 182static void gemtek_pci_unmute(struct gemtek_pci *card)
181{ 183{
182 if ( card->mute ) { 184 mutex_lock(&card->lock);
183 gemtek_pci_setfrequency( card, card->current_frequency ); 185 if (card->mute) {
186 gemtek_pci_setfrequency(card, card->current_frequency);
184 card->mute = false; 187 card->mute = false;
185 } 188 }
189 mutex_unlock(&card->lock);
186} 190}
187 191
188static inline unsigned int gemtek_pci_getsignal( struct gemtek_pci_card *card ) 192static int gemtek_pci_getsignal(struct gemtek_pci *card)
189{ 193{
190 return ( inb( card->iobase ) & 0x08 ) ? 0 : 1; 194 int sig;
195
196 mutex_lock(&card->lock);
197 sig = (inb(card->iobase) & 0x08) ? 0 : 1;
198 mutex_unlock(&card->lock);
199 return sig;
191} 200}
192 201
193static int vidioc_querycap(struct file *file, void *priv, 202static int vidioc_querycap(struct file *file, void *priv,
194 struct v4l2_capability *v) 203 struct v4l2_capability *v)
195{ 204{
205 struct gemtek_pci *card = video_drvdata(file);
206
196 strlcpy(v->driver, "radio-gemtek-pci", sizeof(v->driver)); 207 strlcpy(v->driver, "radio-gemtek-pci", sizeof(v->driver));
197 strlcpy(v->card, "GemTek PCI Radio", sizeof(v->card)); 208 strlcpy(v->card, "GemTek PCI Radio", sizeof(v->card));
198 sprintf(v->bus_info, "ISA"); 209 snprintf(v->bus_info, sizeof(v->bus_info), "PCI:%s", pci_name(card->pdev));
199 v->version = RADIO_VERSION; 210 v->version = RADIO_VERSION;
200 v->capabilities = V4L2_CAP_TUNER; 211 v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
201 return 0; 212 return 0;
202} 213}
203 214
204static int vidioc_g_tuner(struct file *file, void *priv, 215static int vidioc_g_tuner(struct file *file, void *priv,
205 struct v4l2_tuner *v) 216 struct v4l2_tuner *v)
206{ 217{
207 struct gemtek_pci_card *card = video_drvdata(file); 218 struct gemtek_pci *card = video_drvdata(file);
208 219
209 if (v->index > 0) 220 if (v->index > 0)
210 return -EINVAL; 221 return -EINVAL;
211 222
212 strcpy(v->name, "FM"); 223 strlcpy(v->name, "FM", sizeof(v->name));
213 v->type = V4L2_TUNER_RADIO; 224 v->type = V4L2_TUNER_RADIO;
214 v->rangelow = GEMTEK_PCI_RANGE_LOW; 225 v->rangelow = GEMTEK_PCI_RANGE_LOW;
215 v->rangehigh = GEMTEK_PCI_RANGE_HIGH; 226 v->rangehigh = GEMTEK_PCI_RANGE_HIGH;
@@ -223,21 +234,18 @@ static int vidioc_g_tuner(struct file *file, void *priv,
223static int vidioc_s_tuner(struct file *file, void *priv, 234static int vidioc_s_tuner(struct file *file, void *priv,
224 struct v4l2_tuner *v) 235 struct v4l2_tuner *v)
225{ 236{
226 if (v->index > 0) 237 return v->index ? -EINVAL : 0;
227 return -EINVAL;
228 return 0;
229} 238}
230 239
231static int vidioc_s_frequency(struct file *file, void *priv, 240static int vidioc_s_frequency(struct file *file, void *priv,
232 struct v4l2_frequency *f) 241 struct v4l2_frequency *f)
233{ 242{
234 struct gemtek_pci_card *card = video_drvdata(file); 243 struct gemtek_pci *card = video_drvdata(file);
235 244
236 if ( (f->frequency < GEMTEK_PCI_RANGE_LOW) || 245 if (f->frequency < GEMTEK_PCI_RANGE_LOW ||
237 (f->frequency > GEMTEK_PCI_RANGE_HIGH) ) 246 f->frequency > GEMTEK_PCI_RANGE_HIGH)
238 return -EINVAL; 247 return -EINVAL;
239 gemtek_pci_setfrequency(card, f->frequency); 248 gemtek_pci_setfrequency(card, f->frequency);
240 card->current_frequency = f->frequency;
241 card->mute = false; 249 card->mute = false;
242 return 0; 250 return 0;
243} 251}
@@ -245,7 +253,7 @@ static int vidioc_s_frequency(struct file *file, void *priv,
245static int vidioc_g_frequency(struct file *file, void *priv, 253static int vidioc_g_frequency(struct file *file, void *priv,
246 struct v4l2_frequency *f) 254 struct v4l2_frequency *f)
247{ 255{
248 struct gemtek_pci_card *card = video_drvdata(file); 256 struct gemtek_pci *card = video_drvdata(file);
249 257
250 f->type = V4L2_TUNER_RADIO; 258 f->type = V4L2_TUNER_RADIO;
251 f->frequency = card->current_frequency; 259 f->frequency = card->current_frequency;
@@ -255,13 +263,11 @@ static int vidioc_g_frequency(struct file *file, void *priv,
255static int vidioc_queryctrl(struct file *file, void *priv, 263static int vidioc_queryctrl(struct file *file, void *priv,
256 struct v4l2_queryctrl *qc) 264 struct v4l2_queryctrl *qc)
257{ 265{
258 int i; 266 switch (qc->id) {
259 for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) { 267 case V4L2_CID_AUDIO_MUTE:
260 if (qc->id && qc->id == radio_qctrl[i].id) { 268 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
261 memcpy(qc, &(radio_qctrl[i]), 269 case V4L2_CID_AUDIO_VOLUME:
262 sizeof(*qc)); 270 return v4l2_ctrl_query_fill(qc, 0, 65535, 65535, 65535);
263 return 0;
264 }
265 } 271 }
266 return -EINVAL; 272 return -EINVAL;
267} 273}
@@ -269,7 +275,7 @@ static int vidioc_queryctrl(struct file *file, void *priv,
269static int vidioc_g_ctrl(struct file *file, void *priv, 275static int vidioc_g_ctrl(struct file *file, void *priv,
270 struct v4l2_control *ctrl) 276 struct v4l2_control *ctrl)
271{ 277{
272 struct gemtek_pci_card *card = video_drvdata(file); 278 struct gemtek_pci *card = video_drvdata(file);
273 279
274 switch (ctrl->id) { 280 switch (ctrl->id) {
275 case V4L2_CID_AUDIO_MUTE: 281 case V4L2_CID_AUDIO_MUTE:
@@ -288,7 +294,7 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
288static int vidioc_s_ctrl(struct file *file, void *priv, 294static int vidioc_s_ctrl(struct file *file, void *priv,
289 struct v4l2_control *ctrl) 295 struct v4l2_control *ctrl)
290{ 296{
291 struct gemtek_pci_card *card = video_drvdata(file); 297 struct gemtek_pci *card = video_drvdata(file);
292 298
293 switch (ctrl->id) { 299 switch (ctrl->id) {
294 case V4L2_CID_AUDIO_MUTE: 300 case V4L2_CID_AUDIO_MUTE:
@@ -307,17 +313,6 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
307 return -EINVAL; 313 return -EINVAL;
308} 314}
309 315
310static int vidioc_g_audio(struct file *file, void *priv,
311 struct v4l2_audio *a)
312{
313 if (a->index > 1)
314 return -EINVAL;
315
316 strcpy(a->name, "Radio");
317 a->capability = V4L2_AUDCAP_STEREO;
318 return 0;
319}
320
321static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i) 316static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
322{ 317{
323 *i = 0; 318 *i = 0;
@@ -326,17 +321,22 @@ static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
326 321
327static int vidioc_s_input(struct file *filp, void *priv, unsigned int i) 322static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
328{ 323{
329 if (i != 0) 324 return i ? -EINVAL : 0;
330 return -EINVAL; 325}
326
327static int vidioc_g_audio(struct file *file, void *priv,
328 struct v4l2_audio *a)
329{
330 a->index = 0;
331 strlcpy(a->name, "Radio", sizeof(a->name));
332 a->capability = V4L2_AUDCAP_STEREO;
331 return 0; 333 return 0;
332} 334}
333 335
334static int vidioc_s_audio(struct file *file, void *priv, 336static int vidioc_s_audio(struct file *file, void *priv,
335 struct v4l2_audio *a) 337 struct v4l2_audio *a)
336{ 338{
337 if (a->index != 0) 339 return a->index ? -EINVAL : 0;
338 return -EINVAL;
339 return 0;
340} 340}
341 341
342enum { 342enum {
@@ -354,25 +354,22 @@ static struct pci_device_id gemtek_pci_id[] =
354 { 0 } 354 { 0 }
355}; 355};
356 356
357MODULE_DEVICE_TABLE( pci, gemtek_pci_id ); 357MODULE_DEVICE_TABLE(pci, gemtek_pci_id);
358
359static int mx = 1;
360 358
361static int gemtek_pci_exclusive_open(struct file *file) 359static int gemtek_pci_open(struct file *file)
362{ 360{
363 return test_and_set_bit(0, &in_use) ? -EBUSY : 0; 361 return 0;
364} 362}
365 363
366static int gemtek_pci_exclusive_release(struct file *file) 364static int gemtek_pci_release(struct file *file)
367{ 365{
368 clear_bit(0, &in_use);
369 return 0; 366 return 0;
370} 367}
371 368
372static const struct v4l2_file_operations gemtek_pci_fops = { 369static const struct v4l2_file_operations gemtek_pci_fops = {
373 .owner = THIS_MODULE, 370 .owner = THIS_MODULE,
374 .open = gemtek_pci_exclusive_open, 371 .open = gemtek_pci_open,
375 .release = gemtek_pci_exclusive_release, 372 .release = gemtek_pci_release,
376 .ioctl = video_ioctl2, 373 .ioctl = video_ioctl2,
377}; 374};
378 375
@@ -391,108 +388,100 @@ static const struct v4l2_ioctl_ops gemtek_pci_ioctl_ops = {
391 .vidioc_s_ctrl = vidioc_s_ctrl, 388 .vidioc_s_ctrl = vidioc_s_ctrl,
392}; 389};
393 390
394static struct video_device vdev_template = { 391static int __devinit gemtek_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pci_id)
395 .name = "Gemtek PCI Radio",
396 .fops = &gemtek_pci_fops,
397 .ioctl_ops = &gemtek_pci_ioctl_ops,
398 .release = video_device_release_empty,
399};
400
401static int __devinit gemtek_pci_probe( struct pci_dev *pci_dev, const struct pci_device_id *pci_id )
402{ 392{
403 struct gemtek_pci_card *card; 393 struct gemtek_pci *card;
404 struct video_device *devradio; 394 struct v4l2_device *v4l2_dev;
395 int res;
405 396
406 if ( (card = kzalloc( sizeof( struct gemtek_pci_card ), GFP_KERNEL )) == NULL ) { 397 card = kzalloc(sizeof(struct gemtek_pci), GFP_KERNEL);
407 printk( KERN_ERR "gemtek_pci: out of memory\n" ); 398 if (card == NULL) {
399 dev_err(&pdev->dev, "out of memory\n");
408 return -ENOMEM; 400 return -ENOMEM;
409 } 401 }
410 402
411 if ( pci_enable_device( pci_dev ) ) 403 v4l2_dev = &card->v4l2_dev;
412 goto err_pci; 404 mutex_init(&card->lock);
405 card->pdev = pdev;
413 406
414 card->iobase = pci_resource_start( pci_dev, 0 ); 407 strlcpy(v4l2_dev->name, "gemtek_pci", sizeof(v4l2_dev->name));
415 card->length = pci_resource_len( pci_dev, 0 );
416 408
417 if ( request_region( card->iobase, card->length, card_names[pci_id->driver_data] ) == NULL ) { 409 res = v4l2_device_register(&pdev->dev, v4l2_dev);
418 printk( KERN_ERR "gemtek_pci: i/o port already in use\n" ); 410 if (res < 0) {
419 goto err_pci; 411 v4l2_err(v4l2_dev, "Could not register v4l2_device\n");
412 kfree(card);
413 return res;
420 } 414 }
421 415
422 pci_set_drvdata( pci_dev, card ); 416 if (pci_enable_device(pdev))
417 goto err_pci;
423 418
424 if ( (devradio = kmalloc( sizeof( struct video_device ), GFP_KERNEL )) == NULL ) { 419 card->iobase = pci_resource_start(pdev, 0);
425 printk( KERN_ERR "gemtek_pci: out of memory\n" ); 420 card->length = pci_resource_len(pdev, 0);
426 goto err_video; 421
422 if (request_region(card->iobase, card->length, card_names[pci_id->driver_data]) == NULL) {
423 v4l2_err(v4l2_dev, "i/o port already in use\n");
424 goto err_pci;
427 } 425 }
428 *devradio = vdev_template;
429 426
430 if (video_register_device(devradio, VFL_TYPE_RADIO, nr_radio) < 0) { 427 strlcpy(card->vdev.name, v4l2_dev->name, sizeof(card->vdev.name));
431 kfree( devradio ); 428 card->vdev.v4l2_dev = v4l2_dev;
429 card->vdev.fops = &gemtek_pci_fops;
430 card->vdev.ioctl_ops = &gemtek_pci_ioctl_ops;
431 card->vdev.release = video_device_release_empty;
432 video_set_drvdata(&card->vdev, card);
433
434 if (video_register_device(&card->vdev, VFL_TYPE_RADIO, nr_radio) < 0)
432 goto err_video; 435 goto err_video;
433 }
434 436
435 card->videodev = devradio; 437 gemtek_pci_mute(card);
436 video_set_drvdata(devradio, card);
437 gemtek_pci_mute( card );
438 438
439 printk( KERN_INFO "Gemtek PCI Radio (rev. %d) found at 0x%04x-0x%04x.\n", 439 v4l2_info(v4l2_dev, "Gemtek PCI Radio (rev. %d) found at 0x%04x-0x%04x.\n",
440 pci_dev->revision, card->iobase, card->iobase + card->length - 1 ); 440 pdev->revision, card->iobase, card->iobase + card->length - 1);
441 441
442 return 0; 442 return 0;
443 443
444err_video: 444err_video:
445 release_region( card->iobase, card->length ); 445 release_region(card->iobase, card->length);
446 446
447err_pci: 447err_pci:
448 kfree( card ); 448 v4l2_device_unregister(v4l2_dev);
449 kfree(card);
449 return -ENODEV; 450 return -ENODEV;
450} 451}
451 452
452static void __devexit gemtek_pci_remove( struct pci_dev *pci_dev ) 453static void __devexit gemtek_pci_remove(struct pci_dev *pdev)
453{ 454{
454 struct gemtek_pci_card *card = pci_get_drvdata( pci_dev ); 455 struct v4l2_device *v4l2_dev = dev_get_drvdata(&pdev->dev);
456 struct gemtek_pci *card = to_gemtek_pci(v4l2_dev);
455 457
456 video_unregister_device( card->videodev ); 458 video_unregister_device(&card->vdev);
457 kfree( card->videodev ); 459 v4l2_device_unregister(v4l2_dev);
458 460
459 release_region( card->iobase, card->length ); 461 release_region(card->iobase, card->length);
460 462
461 if ( mx ) 463 if (mx)
462 gemtek_pci_mute( card ); 464 gemtek_pci_mute(card);
463 465
464 kfree( card ); 466 kfree(card);
465
466 pci_set_drvdata( pci_dev, NULL );
467} 467}
468 468
469static struct pci_driver gemtek_pci_driver = 469static struct pci_driver gemtek_pci_driver = {
470{
471 .name = "gemtek_pci", 470 .name = "gemtek_pci",
472 .id_table = gemtek_pci_id, 471 .id_table = gemtek_pci_id,
473 .probe = gemtek_pci_probe, 472 .probe = gemtek_pci_probe,
474 .remove = __devexit_p(gemtek_pci_remove), 473 .remove = __devexit_p(gemtek_pci_remove),
475}; 474};
476 475
477static int __init gemtek_pci_init_module( void ) 476static int __init gemtek_pci_init(void)
478{ 477{
479 return pci_register_driver( &gemtek_pci_driver ); 478 return pci_register_driver(&gemtek_pci_driver);
480} 479}
481 480
482static void __exit gemtek_pci_cleanup_module( void ) 481static void __exit gemtek_pci_exit(void)
483{ 482{
484 pci_unregister_driver(&gemtek_pci_driver); 483 pci_unregister_driver(&gemtek_pci_driver);
485} 484}
486 485
487MODULE_AUTHOR( "Vladimir Shebordaev <vshebordaev@mail.ru>" ); 486module_init(gemtek_pci_init);
488MODULE_DESCRIPTION( "The video4linux driver for the Gemtek PCI Radio Card" ); 487module_exit(gemtek_pci_exit);
489MODULE_LICENSE("GPL");
490
491module_param(mx, bool, 0);
492MODULE_PARM_DESC( mx, "single digit: 1 - turn off the turner upon module exit (default), 0 - do not" );
493module_param(nr_radio, int, 0);
494MODULE_PARM_DESC( nr_radio, "video4linux device number to use");
495
496module_init( gemtek_pci_init_module );
497module_exit( gemtek_pci_cleanup_module );
498
diff --git a/drivers/media/radio/radio-gemtek.c b/drivers/media/radio/radio-gemtek.c
index 2b68be773f13..150464426d1d 100644
--- a/drivers/media/radio/radio-gemtek.c
+++ b/drivers/media/radio/radio-gemtek.c
@@ -20,16 +20,14 @@
20#include <linux/init.h> /* Initdata */ 20#include <linux/init.h> /* Initdata */
21#include <linux/ioport.h> /* request_region */ 21#include <linux/ioport.h> /* request_region */
22#include <linux/delay.h> /* udelay */ 22#include <linux/delay.h> /* udelay */
23#include <asm/io.h> /* outb, outb_p */
24#include <asm/uaccess.h> /* copy to/from user */
25#include <linux/videodev2.h> /* kernel radio structs */ 23#include <linux/videodev2.h> /* kernel radio structs */
24#include <linux/version.h> /* for KERNEL_VERSION MACRO */
25#include <linux/mutex.h>
26#include <linux/io.h> /* outb, outb_p */
26#include <media/v4l2-ioctl.h> 27#include <media/v4l2-ioctl.h>
27#include <media/v4l2-common.h> 28#include <media/v4l2-device.h>
28#include <linux/spinlock.h>
29 29
30#include <linux/version.h> /* for KERNEL_VERSION MACRO */ 30#define RADIO_VERSION KERNEL_VERSION(0, 0, 3)
31#define RADIO_VERSION KERNEL_VERSION(0,0,3)
32#define RADIO_BANNER "GemTek Radio card driver: v0.0.3"
33 31
34/* 32/*
35 * Module info. 33 * Module info.
@@ -57,7 +55,6 @@ static int shutdown = 1;
57static int keepmuted = 1; 55static int keepmuted = 1;
58static int initmute = 1; 56static int initmute = 1;
59static int radio_nr = -1; 57static int radio_nr = -1;
60static unsigned long in_use;
61 58
62module_param(io, int, 0444); 59module_param(io, int, 0444);
63MODULE_PARM_DESC(io, "Force I/O port for the GemTek Radio card if automatic " 60MODULE_PARM_DESC(io, "Force I/O port for the GemTek Radio card if automatic "
@@ -112,12 +109,19 @@ module_param(radio_nr, int, 0444);
112#define SHORT_DELAY 5 /* usec */ 109#define SHORT_DELAY 5 /* usec */
113#define LONG_DELAY 75 /* usec */ 110#define LONG_DELAY 75 /* usec */
114 111
115struct gemtek_device { 112struct gemtek {
113 struct v4l2_device v4l2_dev;
114 struct video_device vdev;
115 struct mutex lock;
116 unsigned long lastfreq; 116 unsigned long lastfreq;
117 int muted; 117 int muted;
118 int verified;
119 int io;
118 u32 bu2614data; 120 u32 bu2614data;
119}; 121};
120 122
123static struct gemtek gemtek_card;
124
121#define BU2614_FREQ_BITS 16 /* D0..D15, Frequency data */ 125#define BU2614_FREQ_BITS 16 /* D0..D15, Frequency data */
122#define BU2614_PORT_BITS 3 /* P0..P2, Output port control data */ 126#define BU2614_PORT_BITS 3 /* P0..P2, Output port control data */
123#define BU2614_VOID_BITS 4 /* unused */ 127#define BU2614_VOID_BITS 4 /* unused */
@@ -153,10 +157,6 @@ struct gemtek_device {
153#define BU2614_FMUN_MASK MKMASK(FMUN) 157#define BU2614_FMUN_MASK MKMASK(FMUN)
154#define BU2614_TEST_MASK MKMASK(TEST) 158#define BU2614_TEST_MASK MKMASK(TEST)
155 159
156static struct gemtek_device gemtek_unit;
157
158static spinlock_t lock;
159
160/* 160/*
161 * Set data which will be sent to BU2614FS. 161 * Set data which will be sent to BU2614FS.
162 */ 162 */
@@ -166,33 +166,33 @@ static spinlock_t lock;
166/* 166/*
167 * Transmit settings to BU2614FS over GemTek IC. 167 * Transmit settings to BU2614FS over GemTek IC.
168 */ 168 */
169static void gemtek_bu2614_transmit(struct gemtek_device *dev) 169static void gemtek_bu2614_transmit(struct gemtek *gt)
170{ 170{
171 int i, bit, q, mute; 171 int i, bit, q, mute;
172 172
173 spin_lock(&lock); 173 mutex_lock(&gt->lock);
174 174
175 mute = dev->muted ? GEMTEK_MT : 0x00; 175 mute = gt->muted ? GEMTEK_MT : 0x00;
176 176
177 outb_p(mute | GEMTEK_DA | GEMTEK_CK, io); 177 outb_p(mute | GEMTEK_DA | GEMTEK_CK, gt->io);
178 udelay(SHORT_DELAY); 178 udelay(SHORT_DELAY);
179 outb_p(mute | GEMTEK_CE | GEMTEK_DA | GEMTEK_CK, io); 179 outb_p(mute | GEMTEK_CE | GEMTEK_DA | GEMTEK_CK, gt->io);
180 udelay(LONG_DELAY); 180 udelay(LONG_DELAY);
181 181
182 for (i = 0, q = dev->bu2614data; i < 32; i++, q >>= 1) { 182 for (i = 0, q = gt->bu2614data; i < 32; i++, q >>= 1) {
183 bit = (q & 1) ? GEMTEK_DA : 0; 183 bit = (q & 1) ? GEMTEK_DA : 0;
184 outb_p(mute | GEMTEK_CE | bit, io); 184 outb_p(mute | GEMTEK_CE | bit, gt->io);
185 udelay(SHORT_DELAY); 185 udelay(SHORT_DELAY);
186 outb_p(mute | GEMTEK_CE | bit | GEMTEK_CK, io); 186 outb_p(mute | GEMTEK_CE | bit | GEMTEK_CK, gt->io);
187 udelay(SHORT_DELAY); 187 udelay(SHORT_DELAY);
188 } 188 }
189 189
190 outb_p(mute | GEMTEK_DA | GEMTEK_CK, io); 190 outb_p(mute | GEMTEK_DA | GEMTEK_CK, gt->io);
191 udelay(SHORT_DELAY); 191 udelay(SHORT_DELAY);
192 outb_p(mute | GEMTEK_CE | GEMTEK_DA | GEMTEK_CK, io); 192 outb_p(mute | GEMTEK_CE | GEMTEK_DA | GEMTEK_CK, gt->io);
193 udelay(LONG_DELAY); 193 udelay(LONG_DELAY);
194 194
195 spin_unlock(&lock); 195 mutex_unlock(&gt->lock);
196} 196}
197 197
198/* 198/*
@@ -206,107 +206,109 @@ static unsigned long gemtek_convfreq(unsigned long freq)
206/* 206/*
207 * Set FM-frequency. 207 * Set FM-frequency.
208 */ 208 */
209static void gemtek_setfreq(struct gemtek_device *dev, unsigned long freq) 209static void gemtek_setfreq(struct gemtek *gt, unsigned long freq)
210{ 210{
211 211 if (keepmuted && hardmute && gt->muted)
212 if (keepmuted && hardmute && dev->muted)
213 return; 212 return;
214 213
215 if (freq < GEMTEK_LOWFREQ) 214 freq = clamp_val(freq, GEMTEK_LOWFREQ, GEMTEK_HIGHFREQ);
216 freq = GEMTEK_LOWFREQ;
217 else if (freq > GEMTEK_HIGHFREQ)
218 freq = GEMTEK_HIGHFREQ;
219 215
220 dev->lastfreq = freq; 216 gt->lastfreq = freq;
221 dev->muted = 0; 217 gt->muted = 0;
222 218
223 gemtek_bu2614_set(dev, BU2614_PORT, 0); 219 gemtek_bu2614_set(gt, BU2614_PORT, 0);
224 gemtek_bu2614_set(dev, BU2614_FMES, 0); 220 gemtek_bu2614_set(gt, BU2614_FMES, 0);
225 gemtek_bu2614_set(dev, BU2614_SWIN, 0); /* FM-mode */ 221 gemtek_bu2614_set(gt, BU2614_SWIN, 0); /* FM-mode */
226 gemtek_bu2614_set(dev, BU2614_SWAL, 0); 222 gemtek_bu2614_set(gt, BU2614_SWAL, 0);
227 gemtek_bu2614_set(dev, BU2614_FMUN, 1); /* GT bit set */ 223 gemtek_bu2614_set(gt, BU2614_FMUN, 1); /* GT bit set */
228 gemtek_bu2614_set(dev, BU2614_TEST, 0); 224 gemtek_bu2614_set(gt, BU2614_TEST, 0);
229 225
230 gemtek_bu2614_set(dev, BU2614_STDF, GEMTEK_STDF_3_125_KHZ); 226 gemtek_bu2614_set(gt, BU2614_STDF, GEMTEK_STDF_3_125_KHZ);
231 gemtek_bu2614_set(dev, BU2614_FREQ, gemtek_convfreq(freq)); 227 gemtek_bu2614_set(gt, BU2614_FREQ, gemtek_convfreq(freq));
232 228
233 gemtek_bu2614_transmit(dev); 229 gemtek_bu2614_transmit(gt);
234} 230}
235 231
236/* 232/*
237 * Set mute flag. 233 * Set mute flag.
238 */ 234 */
239static void gemtek_mute(struct gemtek_device *dev) 235static void gemtek_mute(struct gemtek *gt)
240{ 236{
241 int i; 237 int i;
242 dev->muted = 1; 238
239 gt->muted = 1;
243 240
244 if (hardmute) { 241 if (hardmute) {
245 /* Turn off PLL, disable data output */ 242 /* Turn off PLL, disable data output */
246 gemtek_bu2614_set(dev, BU2614_PORT, 0); 243 gemtek_bu2614_set(gt, BU2614_PORT, 0);
247 gemtek_bu2614_set(dev, BU2614_FMES, 0); /* CT bit off */ 244 gemtek_bu2614_set(gt, BU2614_FMES, 0); /* CT bit off */
248 gemtek_bu2614_set(dev, BU2614_SWIN, 0); /* FM-mode */ 245 gemtek_bu2614_set(gt, BU2614_SWIN, 0); /* FM-mode */
249 gemtek_bu2614_set(dev, BU2614_SWAL, 0); 246 gemtek_bu2614_set(gt, BU2614_SWAL, 0);
250 gemtek_bu2614_set(dev, BU2614_FMUN, 0); /* GT bit off */ 247 gemtek_bu2614_set(gt, BU2614_FMUN, 0); /* GT bit off */
251 gemtek_bu2614_set(dev, BU2614_TEST, 0); 248 gemtek_bu2614_set(gt, BU2614_TEST, 0);
252 gemtek_bu2614_set(dev, BU2614_STDF, GEMTEK_PLL_OFF); 249 gemtek_bu2614_set(gt, BU2614_STDF, GEMTEK_PLL_OFF);
253 gemtek_bu2614_set(dev, BU2614_FREQ, 0); 250 gemtek_bu2614_set(gt, BU2614_FREQ, 0);
254 gemtek_bu2614_transmit(dev); 251 gemtek_bu2614_transmit(gt);
255 } else { 252 return;
256 spin_lock(&lock); 253 }
257 254
258 /* Read bus contents (CE, CK and DA). */ 255 mutex_lock(&gt->lock);
259 i = inb_p(io);
260 /* Write it back with mute flag set. */
261 outb_p((i >> 5) | GEMTEK_MT, io);
262 udelay(SHORT_DELAY);
263 256
264 spin_unlock(&lock); 257 /* Read bus contents (CE, CK and DA). */
265 } 258 i = inb_p(gt->io);
259 /* Write it back with mute flag set. */
260 outb_p((i >> 5) | GEMTEK_MT, gt->io);
261 udelay(SHORT_DELAY);
262
263 mutex_unlock(&gt->lock);
266} 264}
267 265
268/* 266/*
269 * Unset mute flag. 267 * Unset mute flag.
270 */ 268 */
271static void gemtek_unmute(struct gemtek_device *dev) 269static void gemtek_unmute(struct gemtek *gt)
272{ 270{
273 int i; 271 int i;
274 dev->muted = 0;
275 272
273 gt->muted = 0;
276 if (hardmute) { 274 if (hardmute) {
277 /* Turn PLL back on. */ 275 /* Turn PLL back on. */
278 gemtek_setfreq(dev, dev->lastfreq); 276 gemtek_setfreq(gt, gt->lastfreq);
279 } else { 277 return;
280 spin_lock(&lock); 278 }
279 mutex_lock(&gt->lock);
281 280
282 i = inb_p(io); 281 i = inb_p(gt->io);
283 outb_p(i >> 5, io); 282 outb_p(i >> 5, gt->io);
284 udelay(SHORT_DELAY); 283 udelay(SHORT_DELAY);
285 284
286 spin_unlock(&lock); 285 mutex_unlock(&gt->lock);
287 }
288} 286}
289 287
290/* 288/*
291 * Get signal strength (= stereo status). 289 * Get signal strength (= stereo status).
292 */ 290 */
293static inline int gemtek_getsigstr(void) 291static inline int gemtek_getsigstr(struct gemtek *gt)
294{ 292{
295 return inb_p(io) & GEMTEK_NS ? 0 : 1; 293 int sig;
294
295 mutex_lock(&gt->lock);
296 sig = inb_p(gt->io) & GEMTEK_NS ? 0 : 1;
297 mutex_unlock(&gt->lock);
298 return sig;
296} 299}
297 300
298/* 301/*
299 * Check if requested card acts like GemTek Radio card. 302 * Check if requested card acts like GemTek Radio card.
300 */ 303 */
301static int gemtek_verify(int port) 304static int gemtek_verify(struct gemtek *gt, int port)
302{ 305{
303 static int verified = -1;
304 int i, q; 306 int i, q;
305 307
306 if (verified == port) 308 if (gt->verified == port)
307 return 1; 309 return 1;
308 310
309 spin_lock(&lock); 311 mutex_lock(&gt->lock);
310 312
311 q = inb_p(port); /* Read bus contents before probing. */ 313 q = inb_p(port); /* Read bus contents before probing. */
312 /* Try to turn on CE, CK and DA respectively and check if card responds 314 /* Try to turn on CE, CK and DA respectively and check if card responds
@@ -316,15 +318,15 @@ static int gemtek_verify(int port)
316 udelay(SHORT_DELAY); 318 udelay(SHORT_DELAY);
317 319
318 if ((inb_p(port) & (~GEMTEK_NS)) != (0x17 | (1 << (i + 5)))) { 320 if ((inb_p(port) & (~GEMTEK_NS)) != (0x17 | (1 << (i + 5)))) {
319 spin_unlock(&lock); 321 mutex_unlock(&gt->lock);
320 return 0; 322 return 0;
321 } 323 }
322 } 324 }
323 outb_p(q >> 5, port); /* Write bus contents back. */ 325 outb_p(q >> 5, port); /* Write bus contents back. */
324 udelay(SHORT_DELAY); 326 udelay(SHORT_DELAY);
325 327
326 spin_unlock(&lock); 328 mutex_unlock(&gt->lock);
327 verified = port; 329 gt->verified = port;
328 330
329 return 1; 331 return 1;
330} 332}
@@ -332,83 +334,61 @@ static int gemtek_verify(int port)
332/* 334/*
333 * Automatic probing for card. 335 * Automatic probing for card.
334 */ 336 */
335static int gemtek_probe(void) 337static int gemtek_probe(struct gemtek *gt)
336{ 338{
339 struct v4l2_device *v4l2_dev = &gt->v4l2_dev;
337 int ioports[] = { 0x20c, 0x30c, 0x24c, 0x34c, 0x248, 0x28c }; 340 int ioports[] = { 0x20c, 0x30c, 0x24c, 0x34c, 0x248, 0x28c };
338 int i; 341 int i;
339 342
340 if (!probe) { 343 if (!probe) {
341 printk(KERN_INFO "Automatic device probing disabled.\n"); 344 v4l2_info(v4l2_dev, "Automatic device probing disabled.\n");
342 return -1; 345 return -1;
343 } 346 }
344 347
345 printk(KERN_INFO "Automatic device probing enabled.\n"); 348 v4l2_info(v4l2_dev, "Automatic device probing enabled.\n");
346 349
347 for (i = 0; i < ARRAY_SIZE(ioports); ++i) { 350 for (i = 0; i < ARRAY_SIZE(ioports); ++i) {
348 printk(KERN_INFO "Trying I/O port 0x%x...\n", ioports[i]); 351 v4l2_info(v4l2_dev, "Trying I/O port 0x%x...\n", ioports[i]);
349 352
350 if (!request_region(ioports[i], 1, "gemtek-probe")) { 353 if (!request_region(ioports[i], 1, "gemtek-probe")) {
351 printk(KERN_WARNING "I/O port 0x%x busy!\n", 354 v4l2_warn(v4l2_dev, "I/O port 0x%x busy!\n",
352 ioports[i]); 355 ioports[i]);
353 continue; 356 continue;
354 } 357 }
355 358
356 if (gemtek_verify(ioports[i])) { 359 if (gemtek_verify(gt, ioports[i])) {
357 printk(KERN_INFO "Card found from I/O port " 360 v4l2_info(v4l2_dev, "Card found from I/O port "
358 "0x%x!\n", ioports[i]); 361 "0x%x!\n", ioports[i]);
359 362
360 release_region(ioports[i], 1); 363 release_region(ioports[i], 1);
361 364 gt->io = ioports[i];
362 io = ioports[i]; 365 return gt->io;
363 return io;
364 } 366 }
365 367
366 release_region(ioports[i], 1); 368 release_region(ioports[i], 1);
367 } 369 }
368 370
369 printk(KERN_ERR "Automatic probing failed!\n"); 371 v4l2_err(v4l2_dev, "Automatic probing failed!\n");
370
371 return -1; 372 return -1;
372} 373}
373 374
374/* 375/*
375 * Video 4 Linux stuff. 376 * Video 4 Linux stuff.
376 */ 377 */
377 378static int gemtek_open(struct file *file)
378static struct v4l2_queryctrl radio_qctrl[] = {
379 {
380 .id = V4L2_CID_AUDIO_MUTE,
381 .name = "Mute",
382 .minimum = 0,
383 .maximum = 1,
384 .default_value = 1,
385 .type = V4L2_CTRL_TYPE_BOOLEAN,
386 }, {
387 .id = V4L2_CID_AUDIO_VOLUME,
388 .name = "Volume",
389 .minimum = 0,
390 .maximum = 65535,
391 .step = 65535,
392 .default_value = 0xff,
393 .type = V4L2_CTRL_TYPE_INTEGER,
394 }
395};
396
397static int gemtek_exclusive_open(struct file *file)
398{ 379{
399 return test_and_set_bit(0, &in_use) ? -EBUSY : 0; 380 return 0;
400} 381}
401 382
402static int gemtek_exclusive_release(struct file *file) 383static int gemtek_release(struct file *file)
403{ 384{
404 clear_bit(0, &in_use);
405 return 0; 385 return 0;
406} 386}
407 387
408static const struct v4l2_file_operations gemtek_fops = { 388static const struct v4l2_file_operations gemtek_fops = {
409 .owner = THIS_MODULE, 389 .owner = THIS_MODULE,
410 .open = gemtek_exclusive_open, 390 .open = gemtek_open,
411 .release = gemtek_exclusive_release, 391 .release = gemtek_release,
412 .ioctl = video_ioctl2, 392 .ioctl = video_ioctl2,
413}; 393};
414 394
@@ -417,23 +397,25 @@ static int vidioc_querycap(struct file *file, void *priv,
417{ 397{
418 strlcpy(v->driver, "radio-gemtek", sizeof(v->driver)); 398 strlcpy(v->driver, "radio-gemtek", sizeof(v->driver));
419 strlcpy(v->card, "GemTek", sizeof(v->card)); 399 strlcpy(v->card, "GemTek", sizeof(v->card));
420 sprintf(v->bus_info, "ISA"); 400 strlcpy(v->bus_info, "ISA", sizeof(v->bus_info));
421 v->version = RADIO_VERSION; 401 v->version = RADIO_VERSION;
422 v->capabilities = V4L2_CAP_TUNER; 402 v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
423 return 0; 403 return 0;
424} 404}
425 405
426static int vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *v) 406static int vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *v)
427{ 407{
408 struct gemtek *gt = video_drvdata(file);
409
428 if (v->index > 0) 410 if (v->index > 0)
429 return -EINVAL; 411 return -EINVAL;
430 412
431 strcpy(v->name, "FM"); 413 strlcpy(v->name, "FM", sizeof(v->name));
432 v->type = V4L2_TUNER_RADIO; 414 v->type = V4L2_TUNER_RADIO;
433 v->rangelow = GEMTEK_LOWFREQ; 415 v->rangelow = GEMTEK_LOWFREQ;
434 v->rangehigh = GEMTEK_HIGHFREQ; 416 v->rangehigh = GEMTEK_HIGHFREQ;
435 v->capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO; 417 v->capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO;
436 v->signal = 0xffff * gemtek_getsigstr(); 418 v->signal = 0xffff * gemtek_getsigstr(gt);
437 if (v->signal) { 419 if (v->signal) {
438 v->audmode = V4L2_TUNER_MODE_STEREO; 420 v->audmode = V4L2_TUNER_MODE_STEREO;
439 v->rxsubchans = V4L2_TUNER_SUB_STEREO; 421 v->rxsubchans = V4L2_TUNER_SUB_STEREO;
@@ -441,65 +423,56 @@ static int vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *v)
441 v->audmode = V4L2_TUNER_MODE_MONO; 423 v->audmode = V4L2_TUNER_MODE_MONO;
442 v->rxsubchans = V4L2_TUNER_SUB_MONO; 424 v->rxsubchans = V4L2_TUNER_SUB_MONO;
443 } 425 }
444
445 return 0; 426 return 0;
446} 427}
447 428
448static int vidioc_s_tuner(struct file *file, void *priv, struct v4l2_tuner *v) 429static int vidioc_s_tuner(struct file *file, void *priv, struct v4l2_tuner *v)
449{ 430{
450 if (v->index > 0) 431 return (v->index != 0) ? -EINVAL : 0;
451 return -EINVAL;
452 return 0;
453} 432}
454 433
455static int vidioc_s_frequency(struct file *file, void *priv, 434static int vidioc_g_frequency(struct file *file, void *priv,
456 struct v4l2_frequency *f) 435 struct v4l2_frequency *f)
457{ 436{
458 struct gemtek_device *rt = video_drvdata(file); 437 struct gemtek *gt = video_drvdata(file);
459
460 gemtek_setfreq(rt, f->frequency);
461 438
439 if (f->tuner != 0)
440 return -EINVAL;
441 f->type = V4L2_TUNER_RADIO;
442 f->frequency = gt->lastfreq;
462 return 0; 443 return 0;
463} 444}
464 445
465static int vidioc_g_frequency(struct file *file, void *priv, 446static int vidioc_s_frequency(struct file *file, void *priv,
466 struct v4l2_frequency *f) 447 struct v4l2_frequency *f)
467{ 448{
468 struct gemtek_device *rt = video_drvdata(file); 449 struct gemtek *gt = video_drvdata(file);
469 450
470 f->type = V4L2_TUNER_RADIO; 451 if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO)
471 f->frequency = rt->lastfreq; 452 return -EINVAL;
453 gemtek_setfreq(gt, f->frequency);
472 return 0; 454 return 0;
473} 455}
474 456
475static int vidioc_queryctrl(struct file *file, void *priv, 457static int vidioc_queryctrl(struct file *file, void *priv,
476 struct v4l2_queryctrl *qc) 458 struct v4l2_queryctrl *qc)
477{ 459{
478 int i; 460 switch (qc->id) {
479 461 case V4L2_CID_AUDIO_MUTE:
480 for (i = 0; i < ARRAY_SIZE(radio_qctrl); ++i) { 462 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 0);
481 if (qc->id && qc->id == radio_qctrl[i].id) { 463 default:
482 memcpy(qc, &(radio_qctrl[i]), sizeof(*qc)); 464 return -EINVAL;
483 return 0;
484 }
485 } 465 }
486 return -EINVAL;
487} 466}
488 467
489static int vidioc_g_ctrl(struct file *file, void *priv, 468static int vidioc_g_ctrl(struct file *file, void *priv,
490 struct v4l2_control *ctrl) 469 struct v4l2_control *ctrl)
491{ 470{
492 struct gemtek_device *rt = video_drvdata(file); 471 struct gemtek *gt = video_drvdata(file);
493 472
494 switch (ctrl->id) { 473 switch (ctrl->id) {
495 case V4L2_CID_AUDIO_MUTE: 474 case V4L2_CID_AUDIO_MUTE:
496 ctrl->value = rt->muted; 475 ctrl->value = gt->muted;
497 return 0;
498 case V4L2_CID_AUDIO_VOLUME:
499 if (rt->muted)
500 ctrl->value = 0;
501 else
502 ctrl->value = 65535;
503 return 0; 476 return 0;
504 } 477 }
505 return -EINVAL; 478 return -EINVAL;
@@ -508,35 +481,19 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
508static int vidioc_s_ctrl(struct file *file, void *priv, 481static int vidioc_s_ctrl(struct file *file, void *priv,
509 struct v4l2_control *ctrl) 482 struct v4l2_control *ctrl)
510{ 483{
511 struct gemtek_device *rt = video_drvdata(file); 484 struct gemtek *gt = video_drvdata(file);
512 485
513 switch (ctrl->id) { 486 switch (ctrl->id) {
514 case V4L2_CID_AUDIO_MUTE: 487 case V4L2_CID_AUDIO_MUTE:
515 if (ctrl->value) 488 if (ctrl->value)
516 gemtek_mute(rt); 489 gemtek_mute(gt);
517 else
518 gemtek_unmute(rt);
519 return 0;
520 case V4L2_CID_AUDIO_VOLUME:
521 if (ctrl->value)
522 gemtek_unmute(rt);
523 else 490 else
524 gemtek_mute(rt); 491 gemtek_unmute(gt);
525 return 0; 492 return 0;
526 } 493 }
527 return -EINVAL; 494 return -EINVAL;
528} 495}
529 496
530static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a)
531{
532 if (a->index > 1)
533 return -EINVAL;
534
535 strcpy(a->name, "Radio");
536 a->capability = V4L2_AUDCAP_STEREO;
537 return 0;
538}
539
540static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i) 497static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
541{ 498{
542 *i = 0; 499 *i = 0;
@@ -545,16 +502,20 @@ static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
545 502
546static int vidioc_s_input(struct file *filp, void *priv, unsigned int i) 503static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
547{ 504{
548 if (i != 0) 505 return (i != 0) ? -EINVAL : 0;
549 return -EINVAL; 506}
507
508static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a)
509{
510 a->index = 0;
511 strlcpy(a->name, "Radio", sizeof(a->name));
512 a->capability = V4L2_AUDCAP_STEREO;
550 return 0; 513 return 0;
551} 514}
552 515
553static int vidioc_s_audio(struct file *file, void *priv, struct v4l2_audio *a) 516static int vidioc_s_audio(struct file *file, void *priv, struct v4l2_audio *a)
554{ 517{
555 if (a->index != 0) 518 return (a->index != 0) ? -EINVAL : 0;
556 return -EINVAL;
557 return 0;
558} 519}
559 520
560static const struct v4l2_ioctl_ops gemtek_ioctl_ops = { 521static const struct v4l2_ioctl_ops gemtek_ioctl_ops = {
@@ -572,62 +533,73 @@ static const struct v4l2_ioctl_ops gemtek_ioctl_ops = {
572 .vidioc_s_ctrl = vidioc_s_ctrl 533 .vidioc_s_ctrl = vidioc_s_ctrl
573}; 534};
574 535
575static struct video_device gemtek_radio = {
576 .name = "GemTek Radio card",
577 .fops = &gemtek_fops,
578 .ioctl_ops = &gemtek_ioctl_ops,
579 .release = video_device_release_empty,
580};
581
582/* 536/*
583 * Initialization / cleanup related stuff. 537 * Initialization / cleanup related stuff.
584 */ 538 */
585 539
586/*
587 * Initilize card.
588 */
589static int __init gemtek_init(void) 540static int __init gemtek_init(void)
590{ 541{
591 printk(KERN_INFO RADIO_BANNER "\n"); 542 struct gemtek *gt = &gemtek_card;
543 struct v4l2_device *v4l2_dev = &gt->v4l2_dev;
544 int res;
592 545
593 spin_lock_init(&lock); 546 strlcpy(v4l2_dev->name, "gemtek", sizeof(v4l2_dev->name));
594 547
595 gemtek_probe(); 548 v4l2_info(v4l2_dev, "GemTek Radio card driver: v0.0.3\n");
596 if (io) { 549
597 if (!request_region(io, 1, "gemtek")) { 550 mutex_init(&gt->lock);
598 printk(KERN_ERR "I/O port 0x%x already in use.\n", io); 551
552 gt->verified = -1;
553 gt->io = io;
554 gemtek_probe(gt);
555 if (gt->io) {
556 if (!request_region(gt->io, 1, "gemtek")) {
557 v4l2_err(v4l2_dev, "I/O port 0x%x already in use.\n", gt->io);
599 return -EBUSY; 558 return -EBUSY;
600 } 559 }
601 560
602 if (!gemtek_verify(io)) 561 if (!gemtek_verify(gt, gt->io))
603 printk(KERN_WARNING "Card at I/O port 0x%x does not " 562 v4l2_warn(v4l2_dev, "Card at I/O port 0x%x does not "
604 "respond properly, check your " 563 "respond properly, check your "
605 "configuration.\n", io); 564 "configuration.\n", gt->io);
606 else 565 else
607 printk(KERN_INFO "Using I/O port 0x%x.\n", io); 566 v4l2_info(v4l2_dev, "Using I/O port 0x%x.\n", gt->io);
608 } else if (probe) { 567 } else if (probe) {
609 printk(KERN_ERR "Automatic probing failed and no " 568 v4l2_err(v4l2_dev, "Automatic probing failed and no "
610 "fixed I/O port defined.\n"); 569 "fixed I/O port defined.\n");
611 return -ENODEV; 570 return -ENODEV;
612 } else { 571 } else {
613 printk(KERN_ERR "Automatic probing disabled but no fixed " 572 v4l2_err(v4l2_dev, "Automatic probing disabled but no fixed "
614 "I/O port defined."); 573 "I/O port defined.");
615 return -EINVAL; 574 return -EINVAL;
616 } 575 }
617 576
618 video_set_drvdata(&gemtek_radio, &gemtek_unit); 577 res = v4l2_device_register(NULL, v4l2_dev);
578 if (res < 0) {
579 v4l2_err(v4l2_dev, "Could not register v4l2_device\n");
580 release_region(gt->io, 1);
581 return res;
582 }
619 583
620 if (video_register_device(&gemtek_radio, VFL_TYPE_RADIO, radio_nr) < 0) { 584 strlcpy(gt->vdev.name, v4l2_dev->name, sizeof(gt->vdev.name));
621 release_region(io, 1); 585 gt->vdev.v4l2_dev = v4l2_dev;
586 gt->vdev.fops = &gemtek_fops;
587 gt->vdev.ioctl_ops = &gemtek_ioctl_ops;
588 gt->vdev.release = video_device_release_empty;
589 video_set_drvdata(&gt->vdev, gt);
590
591 if (video_register_device(&gt->vdev, VFL_TYPE_RADIO, radio_nr) < 0) {
592 v4l2_device_unregister(v4l2_dev);
593 release_region(gt->io, 1);
622 return -EBUSY; 594 return -EBUSY;
623 } 595 }
624 596
625 /* Set defaults */ 597 /* Set defaults */
626 gemtek_unit.lastfreq = GEMTEK_LOWFREQ; 598 gt->lastfreq = GEMTEK_LOWFREQ;
627 gemtek_unit.bu2614data = 0; 599 gt->bu2614data = 0;
628 600
629 if (initmute) 601 if (initmute)
630 gemtek_mute(&gemtek_unit); 602 gemtek_mute(gt);
631 603
632 return 0; 604 return 0;
633} 605}
@@ -637,15 +609,19 @@ static int __init gemtek_init(void)
637 */ 609 */
638static void __exit gemtek_exit(void) 610static void __exit gemtek_exit(void)
639{ 611{
612 struct gemtek *gt = &gemtek_card;
613 struct v4l2_device *v4l2_dev = &gt->v4l2_dev;
614
640 if (shutdown) { 615 if (shutdown) {
641 hardmute = 1; /* Turn off PLL */ 616 hardmute = 1; /* Turn off PLL */
642 gemtek_mute(&gemtek_unit); 617 gemtek_mute(gt);
643 } else { 618 } else {
644 printk(KERN_INFO "Module unloaded but card not muted!\n"); 619 v4l2_info(v4l2_dev, "Module unloaded but card not muted!\n");
645 } 620 }
646 621
647 video_unregister_device(&gemtek_radio); 622 video_unregister_device(&gt->vdev);
648 release_region(io, 1); 623 v4l2_device_unregister(&gt->v4l2_dev);
624 release_region(gt->io, 1);
649} 625}
650 626
651module_init(gemtek_init); 627module_init(gemtek_init);
diff --git a/drivers/media/radio/radio-maestro.c b/drivers/media/radio/radio-maestro.c
index ba3a13a90013..01a6d22950ad 100644
--- a/drivers/media/radio/radio-maestro.c
+++ b/drivers/media/radio/radio-maestro.c
@@ -22,27 +22,22 @@
22#include <linux/init.h> 22#include <linux/init.h>
23#include <linux/ioport.h> 23#include <linux/ioport.h>
24#include <linux/delay.h> 24#include <linux/delay.h>
25#include <asm/io.h> 25#include <linux/version.h> /* for KERNEL_VERSION MACRO */
26#include <asm/uaccess.h>
27#include <linux/pci.h> 26#include <linux/pci.h>
28#include <linux/videodev2.h> 27#include <linux/videodev2.h>
29#include <media/v4l2-common.h> 28#include <linux/io.h>
29#include <media/v4l2-device.h>
30#include <media/v4l2-ioctl.h> 30#include <media/v4l2-ioctl.h>
31 31
32#include <linux/version.h> /* for KERNEL_VERSION MACRO */ 32MODULE_AUTHOR("Adam Tlalka, atlka@pg.gda.pl");
33#define RADIO_VERSION KERNEL_VERSION(0,0,6) 33MODULE_DESCRIPTION("Radio driver for the Maestro PCI sound card radio.");
34#define DRIVER_VERSION "0.06" 34MODULE_LICENSE("GPL");
35 35
36static struct v4l2_queryctrl radio_qctrl[] = { 36static int radio_nr = -1;
37 { 37module_param(radio_nr, int, 0);
38 .id = V4L2_CID_AUDIO_MUTE, 38
39 .name = "Mute", 39#define RADIO_VERSION KERNEL_VERSION(0, 0, 6)
40 .minimum = 0, 40#define DRIVER_VERSION "0.06"
41 .maximum = 1,
42 .default_value = 1,
43 .type = V4L2_CTRL_TYPE_BOOLEAN,
44 }
45};
46 41
47#define GPIO_DATA 0x60 /* port offset from ESS_IO_BASE */ 42#define GPIO_DATA 0x60 /* port offset from ESS_IO_BASE */
48 43
@@ -72,62 +67,27 @@ static struct v4l2_queryctrl radio_qctrl[] = {
72 67
73#define BITS2FREQ(x) ((x) * FREQ_STEP - FREQ_IF) 68#define BITS2FREQ(x) ((x) * FREQ_STEP - FREQ_IF)
74 69
75static int radio_nr = -1; 70struct maestro {
76module_param(radio_nr, int, 0); 71 struct v4l2_device v4l2_dev;
72 struct video_device vdev;
73 struct pci_dev *pdev;
74 struct mutex lock;
77 75
78static unsigned long in_use; 76 u16 io; /* base of Maestro card radio io (GPIO_DATA)*/
79 77 u16 muted; /* VIDEO_AUDIO_MUTE */
80static int maestro_probe(struct pci_dev *pdev, const struct pci_device_id *ent); 78 u16 stereo; /* VIDEO_TUNER_STEREO_ON */
79 u16 tuned; /* signal strength (0 or 0xffff) */
80};
81 81
82static int maestro_exclusive_open(struct file *file) 82static inline struct maestro *to_maestro(struct v4l2_device *v4l2_dev)
83{ 83{
84 return test_and_set_bit(0, &in_use) ? -EBUSY : 0; 84 return container_of(v4l2_dev, struct maestro, v4l2_dev);
85} 85}
86 86
87static int maestro_exclusive_release(struct file *file) 87static u32 radio_bits_get(struct maestro *dev)
88{ 88{
89 clear_bit(0, &in_use); 89 u16 io = dev->io, l, rdata;
90 return 0; 90 u32 data = 0;
91}
92
93static void maestro_remove(struct pci_dev *pdev);
94
95static struct pci_device_id maestro_r_pci_tbl[] = {
96 { PCI_DEVICE(PCI_VENDOR_ID_ESS, PCI_DEVICE_ID_ESS_ESS1968),
97 .class = PCI_CLASS_MULTIMEDIA_AUDIO << 8,
98 .class_mask = 0xffff00 },
99 { PCI_DEVICE(PCI_VENDOR_ID_ESS, PCI_DEVICE_ID_ESS_ESS1978),
100 .class = PCI_CLASS_MULTIMEDIA_AUDIO << 8,
101 .class_mask = 0xffff00 },
102 { 0 }
103};
104MODULE_DEVICE_TABLE(pci, maestro_r_pci_tbl);
105
106static struct pci_driver maestro_r_driver = {
107 .name = "maestro_radio",
108 .id_table = maestro_r_pci_tbl,
109 .probe = maestro_probe,
110 .remove = __devexit_p(maestro_remove),
111};
112
113static const struct v4l2_file_operations maestro_fops = {
114 .owner = THIS_MODULE,
115 .open = maestro_exclusive_open,
116 .release = maestro_exclusive_release,
117 .ioctl = video_ioctl2,
118};
119
120struct radio_device {
121 u16 io, /* base of Maestro card radio io (GPIO_DATA)*/
122 muted, /* VIDEO_AUDIO_MUTE */
123 stereo, /* VIDEO_TUNER_STEREO_ON */
124 tuned; /* signal strength (0 or 0xffff) */
125};
126
127static u32 radio_bits_get(struct radio_device *dev)
128{
129 register u16 io=dev->io, l, rdata;
130 register u32 data=0;
131 u16 omask; 91 u16 omask;
132 92
133 omask = inw(io + IO_MASK); 93 omask = inw(io + IO_MASK);
@@ -135,25 +95,23 @@ static u32 radio_bits_get(struct radio_device *dev)
135 outw(0, io); 95 outw(0, io);
136 udelay(16); 96 udelay(16);
137 97
138 for (l=24;l--;) { 98 for (l = 24; l--;) {
139 outw(STR_CLK, io); /* HI state */ 99 outw(STR_CLK, io); /* HI state */
140 udelay(2); 100 udelay(2);
141 if(!l) 101 if (!l)
142 dev->tuned = inw(io) & STR_MOST ? 0 : 0xffff; 102 dev->tuned = inw(io) & STR_MOST ? 0 : 0xffff;
143 outw(0, io); /* LO state */ 103 outw(0, io); /* LO state */
144 udelay(2); 104 udelay(2);
145 data <<= 1; /* shift data */ 105 data <<= 1; /* shift data */
146 rdata = inw(io); 106 rdata = inw(io);
147 if(!l) 107 if (!l)
148 dev->stereo = rdata & STR_MOST ? 108 dev->stereo = (rdata & STR_MOST) ? 0 : 1;
149 0 : 1; 109 else if (rdata & STR_DATA)
150 else 110 data++;
151 if(rdata & STR_DATA)
152 data++;
153 udelay(2); 111 udelay(2);
154 } 112 }
155 113
156 if(dev->muted) 114 if (dev->muted)
157 outw(STR_WREN, io); 115 outw(STR_WREN, io);
158 116
159 udelay(4); 117 udelay(4);
@@ -162,18 +120,18 @@ static u32 radio_bits_get(struct radio_device *dev)
162 return data & 0x3ffe; 120 return data & 0x3ffe;
163} 121}
164 122
165static void radio_bits_set(struct radio_device *dev, u32 data) 123static void radio_bits_set(struct maestro *dev, u32 data)
166{ 124{
167 register u16 io=dev->io, l, bits; 125 u16 io = dev->io, l, bits;
168 u16 omask, odir; 126 u16 omask, odir;
169 127
170 omask = inw(io + IO_MASK); 128 omask = inw(io + IO_MASK);
171 odir = (inw(io + IO_DIR) & ~STR_DATA) | (STR_CLK | STR_WREN); 129 odir = (inw(io + IO_DIR) & ~STR_DATA) | (STR_CLK | STR_WREN);
172 outw(odir | STR_DATA, io + IO_DIR); 130 outw(odir | STR_DATA, io + IO_DIR);
173 outw(~(STR_DATA | STR_CLK | STR_WREN), io + IO_MASK); 131 outw(~(STR_DATA | STR_CLK | STR_WREN), io + IO_MASK);
174 udelay(16); 132 udelay(16);
175 for (l=25;l;l--) { 133 for (l = 25; l; l--) {
176 bits = ((data >> 18) & STR_DATA) | STR_WREN ; 134 bits = ((data >> 18) & STR_DATA) | STR_WREN;
177 data <<= 1; /* shift data */ 135 data <<= 1; /* shift data */
178 outw(bits, io); /* start strobe */ 136 outw(bits, io); /* start strobe */
179 udelay(2); 137 udelay(2);
@@ -183,7 +141,7 @@ static void radio_bits_set(struct radio_device *dev, u32 data)
183 udelay(4); 141 udelay(4);
184 } 142 }
185 143
186 if(!dev->muted) 144 if (!dev->muted)
187 outw(0, io); 145 outw(0, io);
188 146
189 udelay(4); 147 udelay(4);
@@ -195,78 +153,79 @@ static void radio_bits_set(struct radio_device *dev, u32 data)
195static int vidioc_querycap(struct file *file, void *priv, 153static int vidioc_querycap(struct file *file, void *priv,
196 struct v4l2_capability *v) 154 struct v4l2_capability *v)
197{ 155{
156 struct maestro *dev = video_drvdata(file);
157
198 strlcpy(v->driver, "radio-maestro", sizeof(v->driver)); 158 strlcpy(v->driver, "radio-maestro", sizeof(v->driver));
199 strlcpy(v->card, "Maestro Radio", sizeof(v->card)); 159 strlcpy(v->card, "Maestro Radio", sizeof(v->card));
200 sprintf(v->bus_info, "PCI"); 160 snprintf(v->bus_info, sizeof(v->bus_info), "PCI:%s", pci_name(dev->pdev));
201 v->version = RADIO_VERSION; 161 v->version = RADIO_VERSION;
202 v->capabilities = V4L2_CAP_TUNER; 162 v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
203 return 0; 163 return 0;
204} 164}
205 165
206static int vidioc_g_tuner(struct file *file, void *priv, 166static int vidioc_g_tuner(struct file *file, void *priv,
207 struct v4l2_tuner *v) 167 struct v4l2_tuner *v)
208{ 168{
209 struct radio_device *card = video_drvdata(file); 169 struct maestro *dev = video_drvdata(file);
210 170
211 if (v->index > 0) 171 if (v->index > 0)
212 return -EINVAL; 172 return -EINVAL;
213 173
214 (void)radio_bits_get(card); 174 mutex_lock(&dev->lock);
175 radio_bits_get(dev);
215 176
216 strcpy(v->name, "FM"); 177 strlcpy(v->name, "FM", sizeof(v->name));
217 v->type = V4L2_TUNER_RADIO; 178 v->type = V4L2_TUNER_RADIO;
218 v->rangelow = FREQ_LO; 179 v->rangelow = FREQ_LO;
219 v->rangehigh = FREQ_HI; 180 v->rangehigh = FREQ_HI;
220 v->rxsubchans = V4L2_TUNER_SUB_MONO|V4L2_TUNER_SUB_STEREO; 181 v->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO;
221 v->capability = V4L2_TUNER_CAP_LOW; 182 v->capability = V4L2_TUNER_CAP_LOW;
222 if(card->stereo) 183 if (dev->stereo)
223 v->audmode = V4L2_TUNER_MODE_STEREO; 184 v->audmode = V4L2_TUNER_MODE_STEREO;
224 else 185 else
225 v->audmode = V4L2_TUNER_MODE_MONO; 186 v->audmode = V4L2_TUNER_MODE_MONO;
226 v->signal = card->tuned; 187 v->signal = dev->tuned;
188 mutex_unlock(&dev->lock);
227 return 0; 189 return 0;
228} 190}
229 191
230static int vidioc_s_tuner(struct file *file, void *priv, 192static int vidioc_s_tuner(struct file *file, void *priv,
231 struct v4l2_tuner *v) 193 struct v4l2_tuner *v)
232{ 194{
233 if (v->index > 0) 195 return v->index ? -EINVAL : 0;
234 return -EINVAL;
235 return 0;
236} 196}
237 197
238static int vidioc_s_frequency(struct file *file, void *priv, 198static int vidioc_s_frequency(struct file *file, void *priv,
239 struct v4l2_frequency *f) 199 struct v4l2_frequency *f)
240{ 200{
241 struct radio_device *card = video_drvdata(file); 201 struct maestro *dev = video_drvdata(file);
242 202
243 if (f->frequency < FREQ_LO || f->frequency > FREQ_HI) 203 if (f->frequency < FREQ_LO || f->frequency > FREQ_HI)
244 return -EINVAL; 204 return -EINVAL;
245 radio_bits_set(card, FREQ2BITS(f->frequency)); 205 mutex_lock(&dev->lock);
206 radio_bits_set(dev, FREQ2BITS(f->frequency));
207 mutex_unlock(&dev->lock);
246 return 0; 208 return 0;
247} 209}
248 210
249static int vidioc_g_frequency(struct file *file, void *priv, 211static int vidioc_g_frequency(struct file *file, void *priv,
250 struct v4l2_frequency *f) 212 struct v4l2_frequency *f)
251{ 213{
252 struct radio_device *card = video_drvdata(file); 214 struct maestro *dev = video_drvdata(file);
253 215
254 f->type = V4L2_TUNER_RADIO; 216 f->type = V4L2_TUNER_RADIO;
255 f->frequency = BITS2FREQ(radio_bits_get(card)); 217 mutex_lock(&dev->lock);
218 f->frequency = BITS2FREQ(radio_bits_get(dev));
219 mutex_unlock(&dev->lock);
256 return 0; 220 return 0;
257} 221}
258 222
259static int vidioc_queryctrl(struct file *file, void *priv, 223static int vidioc_queryctrl(struct file *file, void *priv,
260 struct v4l2_queryctrl *qc) 224 struct v4l2_queryctrl *qc)
261{ 225{
262 int i; 226 switch (qc->id) {
263 227 case V4L2_CID_AUDIO_MUTE:
264 for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) { 228 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
265 if (qc->id && qc->id == radio_qctrl[i].id) {
266 memcpy(qc, &(radio_qctrl[i]),
267 sizeof(*qc));
268 return 0;
269 }
270 } 229 }
271 return -EINVAL; 230 return -EINVAL;
272} 231}
@@ -274,11 +233,11 @@ static int vidioc_queryctrl(struct file *file, void *priv,
274static int vidioc_g_ctrl(struct file *file, void *priv, 233static int vidioc_g_ctrl(struct file *file, void *priv,
275 struct v4l2_control *ctrl) 234 struct v4l2_control *ctrl)
276{ 235{
277 struct radio_device *card = video_drvdata(file); 236 struct maestro *dev = video_drvdata(file);
278 237
279 switch (ctrl->id) { 238 switch (ctrl->id) {
280 case V4L2_CID_AUDIO_MUTE: 239 case V4L2_CID_AUDIO_MUTE:
281 ctrl->value = card->muted; 240 ctrl->value = dev->muted;
282 return 0; 241 return 0;
283 } 242 }
284 return -EINVAL; 243 return -EINVAL;
@@ -287,56 +246,85 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
287static int vidioc_s_ctrl(struct file *file, void *priv, 246static int vidioc_s_ctrl(struct file *file, void *priv,
288 struct v4l2_control *ctrl) 247 struct v4l2_control *ctrl)
289{ 248{
290 struct radio_device *card = video_drvdata(file); 249 struct maestro *dev = video_drvdata(file);
291 register u16 io = card->io; 250 u16 io = dev->io;
292 register u16 omask = inw(io + IO_MASK); 251 u16 omask;
293 252
294 switch (ctrl->id) { 253 switch (ctrl->id) {
295 case V4L2_CID_AUDIO_MUTE: 254 case V4L2_CID_AUDIO_MUTE:
255 mutex_lock(&dev->lock);
256 omask = inw(io + IO_MASK);
296 outw(~STR_WREN, io + IO_MASK); 257 outw(~STR_WREN, io + IO_MASK);
297 outw((card->muted = ctrl->value ) ? 258 dev->muted = ctrl->value;
298 STR_WREN : 0, io); 259 outw(dev->muted ? STR_WREN : 0, io);
299 udelay(4); 260 udelay(4);
300 outw(omask, io + IO_MASK); 261 outw(omask, io + IO_MASK);
301 msleep(125); 262 msleep(125);
263 mutex_unlock(&dev->lock);
302 return 0; 264 return 0;
303 } 265 }
304 return -EINVAL; 266 return -EINVAL;
305} 267}
306 268
269static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
270{
271 *i = 0;
272 return 0;
273}
274
275static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
276{
277 return i ? -EINVAL : 0;
278}
279
307static int vidioc_g_audio(struct file *file, void *priv, 280static int vidioc_g_audio(struct file *file, void *priv,
308 struct v4l2_audio *a) 281 struct v4l2_audio *a)
309{ 282{
310 if (a->index > 1) 283 a->index = 0;
311 return -EINVAL; 284 strlcpy(a->name, "Radio", sizeof(a->name));
312
313 strcpy(a->name, "Radio");
314 a->capability = V4L2_AUDCAP_STEREO; 285 a->capability = V4L2_AUDCAP_STEREO;
315 return 0; 286 return 0;
316} 287}
317 288
318static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i) 289static int vidioc_s_audio(struct file *file, void *priv,
290 struct v4l2_audio *a)
319{ 291{
320 *i = 0; 292 return a->index ? -EINVAL : 0;
321 return 0;
322} 293}
323 294
324static int vidioc_s_input(struct file *filp, void *priv, unsigned int i) 295static int maestro_open(struct file *file)
325{ 296{
326 if (i != 0)
327 return -EINVAL;
328 return 0; 297 return 0;
329} 298}
330 299
331static int vidioc_s_audio(struct file *file, void *priv, 300static int maestro_release(struct file *file)
332 struct v4l2_audio *a)
333{ 301{
334 if (a->index != 0)
335 return -EINVAL;
336 return 0; 302 return 0;
337} 303}
338 304
339static u16 __devinit radio_power_on(struct radio_device *dev) 305static const struct v4l2_file_operations maestro_fops = {
306 .owner = THIS_MODULE,
307 .open = maestro_open,
308 .release = maestro_release,
309 .ioctl = video_ioctl2,
310};
311
312static const struct v4l2_ioctl_ops maestro_ioctl_ops = {
313 .vidioc_querycap = vidioc_querycap,
314 .vidioc_g_tuner = vidioc_g_tuner,
315 .vidioc_s_tuner = vidioc_s_tuner,
316 .vidioc_g_audio = vidioc_g_audio,
317 .vidioc_s_audio = vidioc_s_audio,
318 .vidioc_g_input = vidioc_g_input,
319 .vidioc_s_input = vidioc_s_input,
320 .vidioc_g_frequency = vidioc_g_frequency,
321 .vidioc_s_frequency = vidioc_s_frequency,
322 .vidioc_queryctrl = vidioc_queryctrl,
323 .vidioc_g_ctrl = vidioc_g_ctrl,
324 .vidioc_s_ctrl = vidioc_s_ctrl,
325};
326
327static u16 __devinit radio_power_on(struct maestro *dev)
340{ 328{
341 register u16 io = dev->io; 329 register u16 io = dev->io;
342 register u32 ofreq; 330 register u32 ofreq;
@@ -360,33 +348,11 @@ static u16 __devinit radio_power_on(struct radio_device *dev)
360 return (ofreq == radio_bits_get(dev)); 348 return (ofreq == radio_bits_get(dev));
361} 349}
362 350
363static const struct v4l2_ioctl_ops maestro_ioctl_ops = {
364 .vidioc_querycap = vidioc_querycap,
365 .vidioc_g_tuner = vidioc_g_tuner,
366 .vidioc_s_tuner = vidioc_s_tuner,
367 .vidioc_g_audio = vidioc_g_audio,
368 .vidioc_s_audio = vidioc_s_audio,
369 .vidioc_g_input = vidioc_g_input,
370 .vidioc_s_input = vidioc_s_input,
371 .vidioc_g_frequency = vidioc_g_frequency,
372 .vidioc_s_frequency = vidioc_s_frequency,
373 .vidioc_queryctrl = vidioc_queryctrl,
374 .vidioc_g_ctrl = vidioc_g_ctrl,
375 .vidioc_s_ctrl = vidioc_s_ctrl,
376};
377
378static struct video_device maestro_radio = {
379 .name = "Maestro radio",
380 .fops = &maestro_fops,
381 .ioctl_ops = &maestro_ioctl_ops,
382 .release = video_device_release,
383};
384
385static int __devinit maestro_probe(struct pci_dev *pdev, 351static int __devinit maestro_probe(struct pci_dev *pdev,
386 const struct pci_device_id *ent) 352 const struct pci_device_id *ent)
387{ 353{
388 struct radio_device *radio_unit; 354 struct maestro *dev;
389 struct video_device *maestro_radio_inst; 355 struct v4l2_device *v4l2_dev;
390 int retval; 356 int retval;
391 357
392 retval = pci_enable_device(pdev); 358 retval = pci_enable_device(pdev);
@@ -397,46 +363,53 @@ static int __devinit maestro_probe(struct pci_dev *pdev,
397 363
398 retval = -ENOMEM; 364 retval = -ENOMEM;
399 365
400 radio_unit = kzalloc(sizeof(*radio_unit), GFP_KERNEL); 366 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
401 if (radio_unit == NULL) { 367 if (dev == NULL) {
402 dev_err(&pdev->dev, "not enough memory\n"); 368 dev_err(&pdev->dev, "not enough memory\n");
403 goto err; 369 goto err;
404 } 370 }
405 371
406 radio_unit->io = pci_resource_start(pdev, 0) + GPIO_DATA; 372 v4l2_dev = &dev->v4l2_dev;
373 mutex_init(&dev->lock);
374 dev->pdev = pdev;
407 375
408 maestro_radio_inst = video_device_alloc(); 376 strlcpy(v4l2_dev->name, "maestro", sizeof(v4l2_dev->name));
409 if (maestro_radio_inst == NULL) { 377
410 dev_err(&pdev->dev, "not enough memory\n"); 378 retval = v4l2_device_register(&pdev->dev, v4l2_dev);
379 if (retval < 0) {
380 v4l2_err(v4l2_dev, "Could not register v4l2_device\n");
411 goto errfr; 381 goto errfr;
412 } 382 }
413 383
414 memcpy(maestro_radio_inst, &maestro_radio, sizeof(maestro_radio)); 384 dev->io = pci_resource_start(pdev, 0) + GPIO_DATA;
415 video_set_drvdata(maestro_radio_inst, radio_unit);
416 pci_set_drvdata(pdev, maestro_radio_inst);
417 385
418 retval = video_register_device(maestro_radio_inst, VFL_TYPE_RADIO, radio_nr); 386 strlcpy(dev->vdev.name, v4l2_dev->name, sizeof(dev->vdev.name));
387 dev->vdev.v4l2_dev = v4l2_dev;
388 dev->vdev.fops = &maestro_fops;
389 dev->vdev.ioctl_ops = &maestro_ioctl_ops;
390 dev->vdev.release = video_device_release_empty;
391 video_set_drvdata(&dev->vdev, dev);
392
393 retval = video_register_device(&dev->vdev, VFL_TYPE_RADIO, radio_nr);
419 if (retval) { 394 if (retval) {
420 printk(KERN_ERR "can't register video device!\n"); 395 v4l2_err(v4l2_dev, "can't register video device!\n");
421 goto errfr1; 396 goto errfr1;
422 } 397 }
423 398
424 if (!radio_power_on(radio_unit)) { 399 if (!radio_power_on(dev)) {
425 retval = -EIO; 400 retval = -EIO;
426 goto errunr; 401 goto errunr;
427 } 402 }
428 403
429 dev_info(&pdev->dev, "version " DRIVER_VERSION " time " __TIME__ " " 404 v4l2_info(v4l2_dev, "version " DRIVER_VERSION "\n");
430 __DATE__ "\n");
431 dev_info(&pdev->dev, "radio chip initialized\n");
432 405
433 return 0; 406 return 0;
434errunr: 407errunr:
435 video_unregister_device(maestro_radio_inst); 408 video_unregister_device(&dev->vdev);
436errfr1: 409errfr1:
437 video_device_release(maestro_radio_inst); 410 v4l2_device_unregister(v4l2_dev);
438errfr: 411errfr:
439 kfree(radio_unit); 412 kfree(dev);
440err: 413err:
441 return retval; 414 return retval;
442 415
@@ -444,11 +417,31 @@ err:
444 417
445static void __devexit maestro_remove(struct pci_dev *pdev) 418static void __devexit maestro_remove(struct pci_dev *pdev)
446{ 419{
447 struct video_device *vdev = pci_get_drvdata(pdev); 420 struct v4l2_device *v4l2_dev = dev_get_drvdata(&pdev->dev);
421 struct maestro *dev = to_maestro(v4l2_dev);
448 422
449 video_unregister_device(vdev); 423 video_unregister_device(&dev->vdev);
424 v4l2_device_unregister(&dev->v4l2_dev);
450} 425}
451 426
427static struct pci_device_id maestro_r_pci_tbl[] = {
428 { PCI_DEVICE(PCI_VENDOR_ID_ESS, PCI_DEVICE_ID_ESS_ESS1968),
429 .class = PCI_CLASS_MULTIMEDIA_AUDIO << 8,
430 .class_mask = 0xffff00 },
431 { PCI_DEVICE(PCI_VENDOR_ID_ESS, PCI_DEVICE_ID_ESS_ESS1978),
432 .class = PCI_CLASS_MULTIMEDIA_AUDIO << 8,
433 .class_mask = 0xffff00 },
434 { 0 }
435};
436MODULE_DEVICE_TABLE(pci, maestro_r_pci_tbl);
437
438static struct pci_driver maestro_r_driver = {
439 .name = "maestro_radio",
440 .id_table = maestro_r_pci_tbl,
441 .probe = maestro_probe,
442 .remove = __devexit_p(maestro_remove),
443};
444
452static int __init maestro_radio_init(void) 445static int __init maestro_radio_init(void)
453{ 446{
454 int retval = pci_register_driver(&maestro_r_driver); 447 int retval = pci_register_driver(&maestro_r_driver);
@@ -466,7 +459,3 @@ static void __exit maestro_radio_exit(void)
466 459
467module_init(maestro_radio_init); 460module_init(maestro_radio_init);
468module_exit(maestro_radio_exit); 461module_exit(maestro_radio_exit);
469
470MODULE_AUTHOR("Adam Tlalka, atlka@pg.gda.pl");
471MODULE_DESCRIPTION("Radio driver for the Maestro PCI sound card radio.");
472MODULE_LICENSE("GPL");
diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
index c5dc00aa9c9f..2606f0b30355 100644
--- a/drivers/media/radio/radio-maxiradio.c
+++ b/drivers/media/radio/radio-maxiradio.c
@@ -37,38 +37,32 @@
37#include <linux/init.h> 37#include <linux/init.h>
38#include <linux/ioport.h> 38#include <linux/ioport.h>
39#include <linux/delay.h> 39#include <linux/delay.h>
40#include <asm/io.h>
41#include <asm/uaccess.h>
42#include <linux/mutex.h> 40#include <linux/mutex.h>
43
44#include <linux/pci.h> 41#include <linux/pci.h>
45#include <linux/videodev2.h> 42#include <linux/videodev2.h>
46#include <media/v4l2-common.h> 43#include <linux/version.h> /* for KERNEL_VERSION MACRO */
44#include <linux/io.h>
45#include <media/v4l2-device.h>
47#include <media/v4l2-ioctl.h> 46#include <media/v4l2-ioctl.h>
48 47
48MODULE_AUTHOR("Dimitromanolakis Apostolos, apdim@grecian.net");
49MODULE_DESCRIPTION("Radio driver for the Guillemot Maxi Radio FM2000 radio.");
50MODULE_LICENSE("GPL");
51
52static int radio_nr = -1;
53module_param(radio_nr, int, 0);
54
55static int debug;
56
57module_param(debug, int, 0644);
58MODULE_PARM_DESC(debug, "activates debug info");
59
49#define DRIVER_VERSION "0.77" 60#define DRIVER_VERSION "0.77"
50 61
51#include <linux/version.h> /* for KERNEL_VERSION MACRO */ 62#define RADIO_VERSION KERNEL_VERSION(0, 7, 7)
52#define RADIO_VERSION KERNEL_VERSION(0,7,7) 63
53 64#define dprintk(dev, num, fmt, arg...) \
54static struct video_device maxiradio_radio; 65 v4l2_dbg(num, debug, &dev->v4l2_dev, fmt, ## arg)
55
56#define dprintk(num, fmt, arg...) \
57 do { \
58 if (maxiradio_radio.debug >= num) \
59 printk(KERN_DEBUG "%s: " fmt, \
60 maxiradio_radio.name, ## arg); } while (0)
61
62static struct v4l2_queryctrl radio_qctrl[] = {
63 {
64 .id = V4L2_CID_AUDIO_MUTE,
65 .name = "Mute",
66 .minimum = 0,
67 .maximum = 1,
68 .default_value = 1,
69 .type = V4L2_CTRL_TYPE_BOOLEAN,
70 }
71};
72 66
73#ifndef PCI_VENDOR_ID_GUILLEMOT 67#ifndef PCI_VENDOR_ID_GUILLEMOT
74#define PCI_VENDOR_ID_GUILLEMOT 0x5046 68#define PCI_VENDOR_ID_GUILLEMOT 0x5046
@@ -80,90 +74,70 @@ static struct v4l2_queryctrl radio_qctrl[] = {
80 74
81 75
82/* TEA5757 pin mappings */ 76/* TEA5757 pin mappings */
83static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16 ; 77static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
84
85static int radio_nr = -1;
86module_param(radio_nr, int, 0);
87 78
88static unsigned long in_use; 79#define FREQ_LO (50 * 16000)
89 80#define FREQ_HI (150 * 16000)
90#define FREQ_LO 50*16000
91#define FREQ_HI 150*16000
92 81
93#define FREQ_IF 171200 /* 10.7*16000 */ 82#define FREQ_IF 171200 /* 10.7*16000 */
94#define FREQ_STEP 200 /* 12.5*16 */ 83#define FREQ_STEP 200 /* 12.5*16 */
95 84
96/* (x==fmhz*16*1000) -> bits */ 85/* (x==fmhz*16*1000) -> bits */
97#define FREQ2BITS(x) ((( (unsigned int)(x)+FREQ_IF+(FREQ_STEP<<1)) \ 86#define FREQ2BITS(x) \
98 /(FREQ_STEP<<2))<<2) 87 ((((unsigned int)(x) + FREQ_IF + (FREQ_STEP << 1)) / (FREQ_STEP << 2)) << 2)
99 88
100#define BITS2FREQ(x) ((x) * FREQ_STEP - FREQ_IF) 89#define BITS2FREQ(x) ((x) * FREQ_STEP - FREQ_IF)
101 90
102 91
103static int maxiradio_exclusive_open(struct file *file) 92struct maxiradio
104{ 93{
105 return test_and_set_bit(0, &in_use) ? -EBUSY : 0; 94 struct v4l2_device v4l2_dev;
106} 95 struct video_device vdev;
107 96 struct pci_dev *pdev;
108static int maxiradio_exclusive_release(struct file *file)
109{
110 clear_bit(0, &in_use);
111 return 0;
112}
113
114static const struct v4l2_file_operations maxiradio_fops = {
115 .owner = THIS_MODULE,
116 .open = maxiradio_exclusive_open,
117 .release = maxiradio_exclusive_release,
118 .ioctl = video_ioctl2,
119};
120 97
121static struct radio_device 98 u16 io; /* base of radio io */
122{ 99 u16 muted; /* VIDEO_AUDIO_MUTE */
123 __u16 io, /* base of radio io */ 100 u16 stereo; /* VIDEO_TUNER_STEREO_ON */
124 muted, /* VIDEO_AUDIO_MUTE */ 101 u16 tuned; /* signal strength (0 or 0xffff) */
125 stereo, /* VIDEO_TUNER_STEREO_ON */
126 tuned; /* signal strength (0 or 0xffff) */
127 102
128 unsigned long freq; 103 unsigned long freq;
129 104
130 struct mutex lock; 105 struct mutex lock;
131} radio_unit = {
132 .muted =1,
133 .freq = FREQ_LO,
134}; 106};
135 107
136static void outbit(unsigned long bit, __u16 io) 108static inline struct maxiradio *to_maxiradio(struct v4l2_device *v4l2_dev)
137{ 109{
138 if (bit != 0) 110 return container_of(v4l2_dev, struct maxiradio, v4l2_dev);
139 {
140 outb( power|wren|data ,io); udelay(4);
141 outb( power|wren|data|clk ,io); udelay(4);
142 outb( power|wren|data ,io); udelay(4);
143 }
144 else
145 {
146 outb( power|wren ,io); udelay(4);
147 outb( power|wren|clk ,io); udelay(4);
148 outb( power|wren ,io); udelay(4);
149 }
150} 111}
151 112
152static void turn_power(__u16 io, int p) 113static void outbit(unsigned long bit, u16 io)
114{
115 int val = power | wren | (bit ? data : 0);
116
117 outb(val, io);
118 udelay(4);
119 outb(val | clk, io);
120 udelay(4);
121 outb(val, io);
122 udelay(4);
123}
124
125static void turn_power(struct maxiradio *dev, int p)
153{ 126{
154 if (p != 0) { 127 if (p != 0) {
155 dprintk(1, "Radio powered on\n"); 128 dprintk(dev, 1, "Radio powered on\n");
156 outb(power, io); 129 outb(power, dev->io);
157 } else { 130 } else {
158 dprintk(1, "Radio powered off\n"); 131 dprintk(dev, 1, "Radio powered off\n");
159 outb(0,io); 132 outb(0, dev->io);
160 } 133 }
161} 134}
162 135
163static void set_freq(__u16 io, __u32 freq) 136static void set_freq(struct maxiradio *dev, u32 freq)
164{ 137{
165 unsigned long int si; 138 unsigned long int si;
166 int bl; 139 int bl;
140 int io = dev->io;
167 int val = FREQ2BITS(freq); 141 int val = FREQ2BITS(freq);
168 142
169 /* TEA5757 shift register bits (see pdf) */ 143 /* TEA5757 shift register bits (see pdf) */
@@ -188,14 +162,14 @@ static void set_freq(__u16 io, __u32 freq)
188 si >>= 1; 162 si >>= 1;
189 } 163 }
190 164
191 dprintk(1, "Radio freq set to %d.%02d MHz\n", 165 dprintk(dev, 1, "Radio freq set to %d.%02d MHz\n",
192 freq / 16000, 166 freq / 16000,
193 freq % 16000 * 100 / 16000); 167 freq % 16000 * 100 / 16000);
194 168
195 turn_power(io, 1); 169 turn_power(dev, 1);
196} 170}
197 171
198static int get_stereo(__u16 io) 172static int get_stereo(u16 io)
199{ 173{
200 outb(power,io); 174 outb(power,io);
201 udelay(4); 175 udelay(4);
@@ -203,7 +177,7 @@ static int get_stereo(__u16 io)
203 return !(inb(io) & mo_st); 177 return !(inb(io) & mo_st);
204} 178}
205 179
206static int get_tune(__u16 io) 180static int get_tune(u16 io)
207{ 181{
208 outb(power+clk,io); 182 outb(power+clk,io);
209 udelay(4); 183 udelay(4);
@@ -212,95 +186,84 @@ static int get_tune(__u16 io)
212} 186}
213 187
214 188
215static int vidioc_querycap (struct file *file, void *priv, 189static int vidioc_querycap(struct file *file, void *priv,
216 struct v4l2_capability *v) 190 struct v4l2_capability *v)
217{ 191{
218 strlcpy(v->driver, "radio-maxiradio", sizeof (v->driver)); 192 struct maxiradio *dev = video_drvdata(file);
219 strlcpy(v->card, "Maxi Radio FM2000 radio", sizeof (v->card));
220 sprintf(v->bus_info,"ISA");
221 v->version = RADIO_VERSION;
222 v->capabilities = V4L2_CAP_TUNER;
223 193
194 strlcpy(v->driver, "radio-maxiradio", sizeof(v->driver));
195 strlcpy(v->card, "Maxi Radio FM2000 radio", sizeof(v->card));
196 snprintf(v->bus_info, sizeof(v->bus_info), "PCI:%s", pci_name(dev->pdev));
197 v->version = RADIO_VERSION;
198 v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
224 return 0; 199 return 0;
225} 200}
226 201
227static int vidioc_g_tuner (struct file *file, void *priv, 202static int vidioc_g_tuner(struct file *file, void *priv,
228 struct v4l2_tuner *v) 203 struct v4l2_tuner *v)
229{ 204{
230 struct radio_device *card = video_drvdata(file); 205 struct maxiradio *dev = video_drvdata(file);
231 206
232 if (v->index > 0) 207 if (v->index > 0)
233 return -EINVAL; 208 return -EINVAL;
234 209
235 memset(v,0,sizeof(*v)); 210 mutex_lock(&dev->lock);
236 strcpy(v->name, "FM"); 211 strlcpy(v->name, "FM", sizeof(v->name));
237 v->type = V4L2_TUNER_RADIO; 212 v->type = V4L2_TUNER_RADIO;
238 213 v->rangelow = FREQ_LO;
239 v->rangelow=FREQ_LO; 214 v->rangehigh = FREQ_HI;
240 v->rangehigh=FREQ_HI; 215 v->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO;
241 v->rxsubchans =V4L2_TUNER_SUB_MONO|V4L2_TUNER_SUB_STEREO; 216 v->capability = V4L2_TUNER_CAP_LOW;
242 v->capability=V4L2_TUNER_CAP_LOW; 217 if (get_stereo(dev->io))
243 if(get_stereo(card->io))
244 v->audmode = V4L2_TUNER_MODE_STEREO; 218 v->audmode = V4L2_TUNER_MODE_STEREO;
245 else 219 else
246 v->audmode = V4L2_TUNER_MODE_MONO; 220 v->audmode = V4L2_TUNER_MODE_MONO;
247 v->signal=0xffff*get_tune(card->io); 221 v->signal = 0xffff * get_tune(dev->io);
222 mutex_unlock(&dev->lock);
248 223
249 return 0; 224 return 0;
250} 225}
251 226
252static int vidioc_s_tuner (struct file *file, void *priv, 227static int vidioc_s_tuner(struct file *file, void *priv,
253 struct v4l2_tuner *v) 228 struct v4l2_tuner *v)
254{ 229{
255 if (v->index > 0) 230 return v->index ? -EINVAL : 0;
256 return -EINVAL;
257
258 return 0;
259}
260
261static int vidioc_g_audio (struct file *file, void *priv,
262 struct v4l2_audio *a)
263{
264 if (a->index > 1)
265 return -EINVAL;
266
267 strcpy(a->name, "FM");
268 a->capability = V4L2_AUDCAP_STEREO;
269 return 0;
270} 231}
271 232
272static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i) 233static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
273{ 234{
274 *i = 0; 235 *i = 0;
275
276 return 0; 236 return 0;
277} 237}
278 238
279static int vidioc_s_input(struct file *filp, void *priv, unsigned int i) 239static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
280{ 240{
281 if (i != 0) 241 return i ? -EINVAL : 0;
282 return -EINVAL; 242}
283 243
244static int vidioc_g_audio(struct file *file, void *priv,
245 struct v4l2_audio *a)
246{
247 a->index = 0;
248 strlcpy(a->name, "Radio", sizeof(a->name));
249 a->capability = V4L2_AUDCAP_STEREO;
284 return 0; 250 return 0;
285} 251}
286 252
287 253
288static int vidioc_s_audio (struct file *file, void *priv, 254static int vidioc_s_audio(struct file *file, void *priv,
289 struct v4l2_audio *a) 255 struct v4l2_audio *a)
290{ 256{
291 if (a->index != 0) 257 return a->index ? -EINVAL : 0;
292 return -EINVAL;
293
294 return 0;
295} 258}
296 259
297static int vidioc_s_frequency (struct file *file, void *priv, 260static int vidioc_s_frequency(struct file *file, void *priv,
298 struct v4l2_frequency *f) 261 struct v4l2_frequency *f)
299{ 262{
300 struct radio_device *card = video_drvdata(file); 263 struct maxiradio *dev = video_drvdata(file);
301 264
302 if (f->frequency < FREQ_LO || f->frequency > FREQ_HI) { 265 if (f->frequency < FREQ_LO || f->frequency > FREQ_HI) {
303 dprintk(1, "radio freq (%d.%02d MHz) out of range (%d-%d)\n", 266 dprintk(dev, 1, "radio freq (%d.%02d MHz) out of range (%d-%d)\n",
304 f->frequency / 16000, 267 f->frequency / 16000,
305 f->frequency % 16000 * 100 / 16000, 268 f->frequency % 16000 * 100 / 16000,
306 FREQ_LO / 16000, FREQ_HI / 16000); 269 FREQ_LO / 16000, FREQ_HI / 16000);
@@ -308,75 +271,91 @@ static int vidioc_s_frequency (struct file *file, void *priv,
308 return -EINVAL; 271 return -EINVAL;
309 } 272 }
310 273
311 card->freq = f->frequency; 274 mutex_lock(&dev->lock);
312 set_freq(card->io, card->freq); 275 dev->freq = f->frequency;
276 set_freq(dev, dev->freq);
313 msleep(125); 277 msleep(125);
278 mutex_unlock(&dev->lock);
314 279
315 return 0; 280 return 0;
316} 281}
317 282
318static int vidioc_g_frequency (struct file *file, void *priv, 283static int vidioc_g_frequency(struct file *file, void *priv,
319 struct v4l2_frequency *f) 284 struct v4l2_frequency *f)
320{ 285{
321 struct radio_device *card = video_drvdata(file); 286 struct maxiradio *dev = video_drvdata(file);
322 287
323 f->type = V4L2_TUNER_RADIO; 288 f->type = V4L2_TUNER_RADIO;
324 f->frequency = card->freq; 289 f->frequency = dev->freq;
325 290
326 dprintk(4, "radio freq is %d.%02d MHz", 291 dprintk(dev, 4, "radio freq is %d.%02d MHz",
327 f->frequency / 16000, 292 f->frequency / 16000,
328 f->frequency % 16000 * 100 / 16000); 293 f->frequency % 16000 * 100 / 16000);
329 294
330 return 0; 295 return 0;
331} 296}
332 297
333static int vidioc_queryctrl (struct file *file, void *priv, 298static int vidioc_queryctrl(struct file *file, void *priv,
334 struct v4l2_queryctrl *qc) 299 struct v4l2_queryctrl *qc)
335{ 300{
336 int i; 301 switch (qc->id) {
337 302 case V4L2_CID_AUDIO_MUTE:
338 for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) { 303 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
339 if (qc->id && qc->id == radio_qctrl[i].id) {
340 memcpy(qc, &(radio_qctrl[i]), sizeof(*qc));
341 return (0);
342 }
343 } 304 }
344
345 return -EINVAL; 305 return -EINVAL;
346} 306}
347 307
348static int vidioc_g_ctrl (struct file *file, void *priv, 308static int vidioc_g_ctrl(struct file *file, void *priv,
349 struct v4l2_control *ctrl) 309 struct v4l2_control *ctrl)
350{ 310{
351 struct radio_device *card = video_drvdata(file); 311 struct maxiradio *dev = video_drvdata(file);
352 312
353 switch (ctrl->id) { 313 switch (ctrl->id) {
354 case V4L2_CID_AUDIO_MUTE: 314 case V4L2_CID_AUDIO_MUTE:
355 ctrl->value=card->muted; 315 ctrl->value = dev->muted;
356 return (0); 316 return 0;
357 } 317 }
358 318
359 return -EINVAL; 319 return -EINVAL;
360} 320}
361 321
362static int vidioc_s_ctrl (struct file *file, void *priv, 322static int vidioc_s_ctrl(struct file *file, void *priv,
363 struct v4l2_control *ctrl) 323 struct v4l2_control *ctrl)
364{ 324{
365 struct radio_device *card = video_drvdata(file); 325 struct maxiradio *dev = video_drvdata(file);
366 326
367 switch (ctrl->id) { 327 switch (ctrl->id) {
368 case V4L2_CID_AUDIO_MUTE: 328 case V4L2_CID_AUDIO_MUTE:
369 card->muted = ctrl->value; 329 mutex_lock(&dev->lock);
370 if(card->muted) 330 dev->muted = ctrl->value;
371 turn_power(card->io, 0); 331 if (dev->muted)
372 else 332 turn_power(dev, 0);
373 set_freq(card->io, card->freq); 333 else
374 return 0; 334 set_freq(dev, dev->freq);
335 mutex_unlock(&dev->lock);
336 return 0;
375 } 337 }
376 338
377 return -EINVAL; 339 return -EINVAL;
378} 340}
379 341
342static int maxiradio_open(struct file *file)
343{
344 return 0;
345}
346
347static int maxiradio_release(struct file *file)
348{
349 return 0;
350}
351
352static const struct v4l2_file_operations maxiradio_fops = {
353 .owner = THIS_MODULE,
354 .open = maxiradio_open,
355 .release = maxiradio_release,
356 .ioctl = video_ioctl2,
357};
358
380static const struct v4l2_ioctl_ops maxiradio_ioctl_ops = { 359static const struct v4l2_ioctl_ops maxiradio_ioctl_ops = {
381 .vidioc_querycap = vidioc_querycap, 360 .vidioc_querycap = vidioc_querycap,
382 .vidioc_g_tuner = vidioc_g_tuner, 361 .vidioc_g_tuner = vidioc_g_tuner,
@@ -392,60 +371,84 @@ static const struct v4l2_ioctl_ops maxiradio_ioctl_ops = {
392 .vidioc_s_ctrl = vidioc_s_ctrl, 371 .vidioc_s_ctrl = vidioc_s_ctrl,
393}; 372};
394 373
395static struct video_device maxiradio_radio = {
396 .name = "Maxi Radio FM2000 radio",
397 .fops = &maxiradio_fops,
398 .ioctl_ops = &maxiradio_ioctl_ops,
399 .release = video_device_release_empty,
400};
401
402static int __devinit maxiradio_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) 374static int __devinit maxiradio_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
403{ 375{
404 if(!request_region(pci_resource_start(pdev, 0), 376 struct maxiradio *dev;
377 struct v4l2_device *v4l2_dev;
378 int retval = -ENOMEM;
379
380 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
381 if (dev == NULL) {
382 dev_err(&pdev->dev, "not enough memory\n");
383 return -ENOMEM;
384 }
385
386 v4l2_dev = &dev->v4l2_dev;
387 mutex_init(&dev->lock);
388 dev->pdev = pdev;
389 dev->muted = 1;
390 dev->freq = FREQ_LO;
391
392 strlcpy(v4l2_dev->name, "maxiradio", sizeof(v4l2_dev->name));
393
394 retval = v4l2_device_register(&pdev->dev, v4l2_dev);
395 if (retval < 0) {
396 v4l2_err(v4l2_dev, "Could not register v4l2_device\n");
397 goto errfr;
398 }
399
400 if (!request_region(pci_resource_start(pdev, 0),
405 pci_resource_len(pdev, 0), "Maxi Radio FM 2000")) { 401 pci_resource_len(pdev, 0), "Maxi Radio FM 2000")) {
406 printk(KERN_ERR "radio-maxiradio: can't reserve I/O ports\n"); 402 v4l2_err(v4l2_dev, "can't reserve I/O ports\n");
407 goto err_out; 403 goto err_out;
408 } 404 }
409 405
410 if (pci_enable_device(pdev)) 406 if (pci_enable_device(pdev))
411 goto err_out_free_region; 407 goto err_out_free_region;
412 408
413 radio_unit.io = pci_resource_start(pdev, 0); 409 dev->io = pci_resource_start(pdev, 0);
414 mutex_init(&radio_unit.lock); 410 strlcpy(dev->vdev.name, v4l2_dev->name, sizeof(dev->vdev.name));
415 video_set_drvdata(&maxiradio_radio, &radio_unit); 411 dev->vdev.v4l2_dev = v4l2_dev;
412 dev->vdev.fops = &maxiradio_fops;
413 dev->vdev.ioctl_ops = &maxiradio_ioctl_ops;
414 dev->vdev.release = video_device_release_empty;
415 video_set_drvdata(&dev->vdev, dev);
416 416
417 if (video_register_device(&maxiradio_radio, VFL_TYPE_RADIO, radio_nr) < 0) { 417 if (video_register_device(&dev->vdev, VFL_TYPE_RADIO, radio_nr) < 0) {
418 printk("radio-maxiradio: can't register device!"); 418 v4l2_err(v4l2_dev, "can't register device!");
419 goto err_out_free_region; 419 goto err_out_free_region;
420 } 420 }
421 421
422 printk(KERN_INFO "radio-maxiradio: version " 422 v4l2_info(v4l2_dev, "version " DRIVER_VERSION
423 DRIVER_VERSION 423 " time " __TIME__ " " __DATE__ "\n");
424 " time "
425 __TIME__ " "
426 __DATE__
427 "\n");
428 424
429 printk(KERN_INFO "radio-maxiradio: found Guillemot MAXI Radio device (io = 0x%x)\n", 425 v4l2_info(v4l2_dev, "found Guillemot MAXI Radio device (io = 0x%x)\n",
430 radio_unit.io); 426 dev->io);
431 return 0; 427 return 0;
432 428
433err_out_free_region: 429err_out_free_region:
434 release_region(pci_resource_start(pdev, 0), pci_resource_len(pdev, 0)); 430 release_region(pci_resource_start(pdev, 0), pci_resource_len(pdev, 0));
435err_out: 431err_out:
432 v4l2_device_unregister(v4l2_dev);
433errfr:
434 kfree(dev);
436 return -ENODEV; 435 return -ENODEV;
437} 436}
438 437
439static void __devexit maxiradio_remove_one(struct pci_dev *pdev) 438static void __devexit maxiradio_remove_one(struct pci_dev *pdev)
440{ 439{
441 video_unregister_device(&maxiradio_radio); 440 struct v4l2_device *v4l2_dev = dev_get_drvdata(&pdev->dev);
441 struct maxiradio *dev = to_maxiradio(v4l2_dev);
442
443 video_unregister_device(&dev->vdev);
444 v4l2_device_unregister(&dev->v4l2_dev);
442 release_region(pci_resource_start(pdev, 0), pci_resource_len(pdev, 0)); 445 release_region(pci_resource_start(pdev, 0), pci_resource_len(pdev, 0));
443} 446}
444 447
445static struct pci_device_id maxiradio_pci_tbl[] = { 448static struct pci_device_id maxiradio_pci_tbl[] = {
446 { PCI_VENDOR_ID_GUILLEMOT, PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO, 449 { PCI_VENDOR_ID_GUILLEMOT, PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO,
447 PCI_ANY_ID, PCI_ANY_ID, }, 450 PCI_ANY_ID, PCI_ANY_ID, },
448 { 0,} 451 { 0 }
449}; 452};
450 453
451MODULE_DEVICE_TABLE(pci, maxiradio_pci_tbl); 454MODULE_DEVICE_TABLE(pci, maxiradio_pci_tbl);
@@ -469,10 +472,3 @@ static void __exit maxiradio_radio_exit(void)
469 472
470module_init(maxiradio_radio_init); 473module_init(maxiradio_radio_init);
471module_exit(maxiradio_radio_exit); 474module_exit(maxiradio_radio_exit);
472
473MODULE_AUTHOR("Dimitromanolakis Apostolos, apdim@grecian.net");
474MODULE_DESCRIPTION("Radio driver for the Guillemot Maxi Radio FM2000 radio.");
475MODULE_LICENSE("GPL");
476
477module_param_named(debug,maxiradio_radio.debug, int, 0644);
478MODULE_PARM_DESC(debug,"activates debug info");
diff --git a/drivers/media/radio/radio-mr800.c b/drivers/media/radio/radio-mr800.c
index fdfc7bf86b9e..ded25bfb366e 100644
--- a/drivers/media/radio/radio-mr800.c
+++ b/drivers/media/radio/radio-mr800.c
@@ -22,7 +22,7 @@
22 */ 22 */
23 23
24/* 24/*
25 * Big thanks to authors of dsbr100.c and radio-si470x.c 25 * Big thanks to authors and contributors of dsbr100.c and radio-si470x.c
26 * 26 *
27 * When work was looked pretty good, i discover this: 27 * When work was looked pretty good, i discover this:
28 * http://av-usbradio.sourceforge.net/index.php 28 * http://av-usbradio.sourceforge.net/index.php
@@ -30,18 +30,23 @@
30 * Latest release of theirs project was in 2005. 30 * Latest release of theirs project was in 2005.
31 * Probably, this driver could be improved trough using their 31 * Probably, this driver could be improved trough using their
32 * achievements (specifications given). 32 * achievements (specifications given).
33 * So, we have smth to begin with. 33 * Also, Faidon Liambotis <paravoid@debian.org> wrote nice driver for this radio
34 * in 2007. He allowed to use his driver to improve current mr800 radio driver.
35 * http://kerneltrap.org/mailarchive/linux-usb-devel/2007/10/11/342492
34 * 36 *
35 * History:
36 * Version 0.01: First working version. 37 * Version 0.01: First working version.
37 * It's required to blacklist AverMedia USB Radio 38 * It's required to blacklist AverMedia USB Radio
38 * in usbhid/hid-quirks.c 39 * in usbhid/hid-quirks.c
40 * Version 0.10: A lot of cleanups and fixes: unpluging the device,
41 * few mutex locks were added, codinstyle issues, etc.
42 * Added stereo support. Thanks to
43 * Douglas Schilling Landgraf <dougsland@gmail.com> and
44 * David Ellingsworth <david@identd.dyndns.org>
45 * for discussion, help and support.
39 * 46 *
40 * Many things to do: 47 * Many things to do:
41 * - Correct power managment of device (suspend & resume) 48 * - Correct power managment of device (suspend & resume)
42 * - Make x86 independance (little-endian and big-endian stuff)
43 * - Add code for scanning and smooth tuning 49 * - Add code for scanning and smooth tuning
44 * - Checked and add stereo&mono stuff
45 * - Add code for sensitivity value 50 * - Add code for sensitivity value
46 * - Correct mistakes 51 * - Correct mistakes
47 * - In Japan another FREQ_MIN and FREQ_MAX 52 * - In Japan another FREQ_MIN and FREQ_MAX
@@ -62,8 +67,8 @@
62/* driver and module definitions */ 67/* driver and module definitions */
63#define DRIVER_AUTHOR "Alexey Klimov <klimov.linux@gmail.com>" 68#define DRIVER_AUTHOR "Alexey Klimov <klimov.linux@gmail.com>"
64#define DRIVER_DESC "AverMedia MR 800 USB FM radio driver" 69#define DRIVER_DESC "AverMedia MR 800 USB FM radio driver"
65#define DRIVER_VERSION "0.01" 70#define DRIVER_VERSION "0.10"
66#define RADIO_VERSION KERNEL_VERSION(0, 0, 1) 71#define RADIO_VERSION KERNEL_VERSION(0, 1, 0)
67 72
68MODULE_AUTHOR(DRIVER_AUTHOR); 73MODULE_AUTHOR(DRIVER_AUTHOR);
69MODULE_DESCRIPTION(DRIVER_DESC); 74MODULE_DESCRIPTION(DRIVER_DESC);
@@ -87,6 +92,22 @@ devices, that would be 76 and 91. */
87#define FREQ_MAX 108.0 92#define FREQ_MAX 108.0
88#define FREQ_MUL 16000 93#define FREQ_MUL 16000
89 94
95/*
96 * Commands that device should understand
97 * List isnt full and will be updated with implementation of new functions
98 */
99#define AMRADIO_SET_FREQ 0xa4
100#define AMRADIO_SET_MUTE 0xab
101#define AMRADIO_SET_MONO 0xae
102
103/* Comfortable defines for amradio_set_mute */
104#define AMRADIO_START 0x00
105#define AMRADIO_STOP 0x01
106
107/* Comfortable defines for amradio_set_stereo */
108#define WANT_STEREO 0x00
109#define WANT_MONO 0x01
110
90/* module parameter */ 111/* module parameter */
91static int radio_nr = -1; 112static int radio_nr = -1;
92module_param(radio_nr, int, 0); 113module_param(radio_nr, int, 0);
@@ -169,43 +190,48 @@ static struct usb_driver usb_amradio_driver = {
169 .supports_autosuspend = 0, 190 .supports_autosuspend = 0,
170}; 191};
171 192
172/* switch on radio. Send 8 bytes to device. */ 193/* switch on/off the radio. Send 8 bytes to device */
173static int amradio_start(struct amradio_device *radio) 194static int amradio_set_mute(struct amradio_device *radio, char argument)
174{ 195{
175 int retval; 196 int retval;
176 int size; 197 int size;
177 198
199 /* safety check */
200 if (radio->removed)
201 return -EIO;
202
178 mutex_lock(&radio->lock); 203 mutex_lock(&radio->lock);
179 204
180 radio->buffer[0] = 0x00; 205 radio->buffer[0] = 0x00;
181 radio->buffer[1] = 0x55; 206 radio->buffer[1] = 0x55;
182 radio->buffer[2] = 0xaa; 207 radio->buffer[2] = 0xaa;
183 radio->buffer[3] = 0x00; 208 radio->buffer[3] = 0x00;
184 radio->buffer[4] = 0xab; 209 radio->buffer[4] = AMRADIO_SET_MUTE;
185 radio->buffer[5] = 0x00; 210 radio->buffer[5] = argument;
186 radio->buffer[6] = 0x00; 211 radio->buffer[6] = 0x00;
187 radio->buffer[7] = 0x00; 212 radio->buffer[7] = 0x00;
188 213
189 retval = usb_bulk_msg(radio->usbdev, usb_sndintpipe(radio->usbdev, 2), 214 retval = usb_bulk_msg(radio->usbdev, usb_sndintpipe(radio->usbdev, 2),
190 (void *) (radio->buffer), BUFFER_LENGTH, &size, USB_TIMEOUT); 215 (void *) (radio->buffer), BUFFER_LENGTH, &size, USB_TIMEOUT);
191 216
192 if (retval) { 217 if (retval < 0 || size != BUFFER_LENGTH) {
193 mutex_unlock(&radio->lock); 218 mutex_unlock(&radio->lock);
194 return retval; 219 return retval;
195 } 220 }
196 221
197 radio->muted = 0; 222 radio->muted = argument;
198 223
199 mutex_unlock(&radio->lock); 224 mutex_unlock(&radio->lock);
200 225
201 return retval; 226 return retval;
202} 227}
203 228
204/* switch off radio */ 229/* set a frequency, freq is defined by v4l's TUNER_LOW, i.e. 1/16th kHz */
205static int amradio_stop(struct amradio_device *radio) 230static int amradio_setfreq(struct amradio_device *radio, int freq)
206{ 231{
207 int retval; 232 int retval;
208 int size; 233 int size;
234 unsigned short freq_send = 0x10 + (freq >> 3) / 25;
209 235
210 /* safety check */ 236 /* safety check */
211 if (radio->removed) 237 if (radio->removed)
@@ -216,33 +242,46 @@ static int amradio_stop(struct amradio_device *radio)
216 radio->buffer[0] = 0x00; 242 radio->buffer[0] = 0x00;
217 radio->buffer[1] = 0x55; 243 radio->buffer[1] = 0x55;
218 radio->buffer[2] = 0xaa; 244 radio->buffer[2] = 0xaa;
219 radio->buffer[3] = 0x00; 245 radio->buffer[3] = 0x03;
220 radio->buffer[4] = 0xab; 246 radio->buffer[4] = AMRADIO_SET_FREQ;
221 radio->buffer[5] = 0x01; 247 radio->buffer[5] = 0x00;
222 radio->buffer[6] = 0x00; 248 radio->buffer[6] = 0x00;
223 radio->buffer[7] = 0x00; 249 radio->buffer[7] = 0x08;
224 250
225 retval = usb_bulk_msg(radio->usbdev, usb_sndintpipe(radio->usbdev, 2), 251 retval = usb_bulk_msg(radio->usbdev, usb_sndintpipe(radio->usbdev, 2),
226 (void *) (radio->buffer), BUFFER_LENGTH, &size, USB_TIMEOUT); 252 (void *) (radio->buffer), BUFFER_LENGTH, &size, USB_TIMEOUT);
227 253
228 if (retval) { 254 if (retval < 0 || size != BUFFER_LENGTH) {
229 mutex_unlock(&radio->lock); 255 mutex_unlock(&radio->lock);
230 return retval; 256 return retval;
231 } 257 }
232 258
233 radio->muted = 1; 259 /* frequency is calculated from freq_send and placed in first 2 bytes */
260 radio->buffer[0] = (freq_send >> 8) & 0xff;
261 radio->buffer[1] = freq_send & 0xff;
262 radio->buffer[2] = 0x01;
263 radio->buffer[3] = 0x00;
264 radio->buffer[4] = 0x00;
265 /* 5 and 6 bytes of buffer already = 0x00 */
266 radio->buffer[7] = 0x00;
267
268 retval = usb_bulk_msg(radio->usbdev, usb_sndintpipe(radio->usbdev, 2),
269 (void *) (radio->buffer), BUFFER_LENGTH, &size, USB_TIMEOUT);
270
271 if (retval < 0 || size != BUFFER_LENGTH) {
272 mutex_unlock(&radio->lock);
273 return retval;
274 }
234 275
235 mutex_unlock(&radio->lock); 276 mutex_unlock(&radio->lock);
236 277
237 return retval; 278 return retval;
238} 279}
239 280
240/* set a frequency, freq is defined by v4l's TUNER_LOW, i.e. 1/16th kHz */ 281static int amradio_set_stereo(struct amradio_device *radio, char argument)
241static int amradio_setfreq(struct amradio_device *radio, int freq)
242{ 282{
243 int retval; 283 int retval;
244 int size; 284 int size;
245 unsigned short freq_send = 0x13 + (freq >> 3) / 25;
246 285
247 /* safety check */ 286 /* safety check */
248 if (radio->removed) 287 if (radio->removed)
@@ -253,50 +292,33 @@ static int amradio_setfreq(struct amradio_device *radio, int freq)
253 radio->buffer[0] = 0x00; 292 radio->buffer[0] = 0x00;
254 radio->buffer[1] = 0x55; 293 radio->buffer[1] = 0x55;
255 radio->buffer[2] = 0xaa; 294 radio->buffer[2] = 0xaa;
256 radio->buffer[3] = 0x03;
257 radio->buffer[4] = 0xa4;
258 radio->buffer[5] = 0x00;
259 radio->buffer[6] = 0x00;
260 radio->buffer[7] = 0x08;
261
262 retval = usb_bulk_msg(radio->usbdev, usb_sndintpipe(radio->usbdev, 2),
263 (void *) (radio->buffer), BUFFER_LENGTH, &size, USB_TIMEOUT);
264
265 if (retval) {
266 mutex_unlock(&radio->lock);
267 return retval;
268 }
269
270 /* frequency is calculated from freq_send and placed in first 2 bytes */
271 radio->buffer[0] = (freq_send >> 8) & 0xff;
272 radio->buffer[1] = freq_send & 0xff;
273 radio->buffer[2] = 0x01;
274 radio->buffer[3] = 0x00; 295 radio->buffer[3] = 0x00;
275 radio->buffer[4] = 0x00; 296 radio->buffer[4] = AMRADIO_SET_MONO;
276 /* 5 and 6 bytes of buffer already = 0x00 */ 297 radio->buffer[5] = argument;
298 radio->buffer[6] = 0x00;
277 radio->buffer[7] = 0x00; 299 radio->buffer[7] = 0x00;
278 300
279 retval = usb_bulk_msg(radio->usbdev, usb_sndintpipe(radio->usbdev, 2), 301 retval = usb_bulk_msg(radio->usbdev, usb_sndintpipe(radio->usbdev, 2),
280 (void *) (radio->buffer), BUFFER_LENGTH, &size, USB_TIMEOUT); 302 (void *) (radio->buffer), BUFFER_LENGTH, &size, USB_TIMEOUT);
281 303
282 if (retval) { 304 if (retval < 0 || size != BUFFER_LENGTH) {
305 radio->stereo = -1;
283 mutex_unlock(&radio->lock); 306 mutex_unlock(&radio->lock);
284 return retval; 307 return retval;
285 } 308 }
286 309
287 radio->stereo = 0; 310 radio->stereo = 1;
288 311
289 mutex_unlock(&radio->lock); 312 mutex_unlock(&radio->lock);
290 313
291 return retval; 314 return retval;
292} 315}
293 316
294/* USB subsystem interface begins here */ 317/* Handle unplugging the device.
295 318 * We call video_unregister_device in any case.
296/* handle unplugging of the device, release data structures 319 * The last function called in this procedure is
297if nothing keeps us from doing it. If something is still 320 * usb_amradio_device_release.
298keeping us busy, the release callback of v4l will take care 321 */
299of releasing it. */
300static void usb_amradio_disconnect(struct usb_interface *intf) 322static void usb_amradio_disconnect(struct usb_interface *intf)
301{ 323{
302 struct amradio_device *radio = usb_get_intfdata(intf); 324 struct amradio_device *radio = usb_get_intfdata(intf);
@@ -313,9 +335,11 @@ static void usb_amradio_disconnect(struct usb_interface *intf)
313static int vidioc_querycap(struct file *file, void *priv, 335static int vidioc_querycap(struct file *file, void *priv,
314 struct v4l2_capability *v) 336 struct v4l2_capability *v)
315{ 337{
338 struct amradio_device *radio = video_drvdata(file);
339
316 strlcpy(v->driver, "radio-mr800", sizeof(v->driver)); 340 strlcpy(v->driver, "radio-mr800", sizeof(v->driver));
317 strlcpy(v->card, "AverMedia MR 800 USB FM Radio", sizeof(v->card)); 341 strlcpy(v->card, "AverMedia MR 800 USB FM Radio", sizeof(v->card));
318 sprintf(v->bus_info, "USB"); 342 usb_make_path(radio->usbdev, v->bus_info, sizeof(v->bus_info));
319 v->version = RADIO_VERSION; 343 v->version = RADIO_VERSION;
320 v->capabilities = V4L2_CAP_TUNER; 344 v->capabilities = V4L2_CAP_TUNER;
321 return 0; 345 return 0;
@@ -326,6 +350,7 @@ static int vidioc_g_tuner(struct file *file, void *priv,
326 struct v4l2_tuner *v) 350 struct v4l2_tuner *v)
327{ 351{
328 struct amradio_device *radio = video_get_drvdata(video_devdata(file)); 352 struct amradio_device *radio = video_get_drvdata(video_devdata(file));
353 int retval;
329 354
330 /* safety check */ 355 /* safety check */
331 if (radio->removed) 356 if (radio->removed)
@@ -337,7 +362,16 @@ static int vidioc_g_tuner(struct file *file, void *priv,
337/* TODO: Add function which look is signal stereo or not 362/* TODO: Add function which look is signal stereo or not
338 * amradio_getstat(radio); 363 * amradio_getstat(radio);
339 */ 364 */
340 radio->stereo = -1; 365
366/* we call amradio_set_stereo to set radio->stereo
367 * Honestly, amradio_getstat should cover this in future and
368 * amradio_set_stereo shouldn't be here
369 */
370 retval = amradio_set_stereo(radio, WANT_STEREO);
371 if (retval < 0)
372 amradio_dev_warn(&radio->videodev->dev,
373 "set stereo failed\n");
374
341 strcpy(v->name, "FM"); 375 strcpy(v->name, "FM");
342 v->type = V4L2_TUNER_RADIO; 376 v->type = V4L2_TUNER_RADIO;
343 v->rangelow = FREQ_MIN * FREQ_MUL; 377 v->rangelow = FREQ_MIN * FREQ_MUL;
@@ -358,6 +392,7 @@ static int vidioc_s_tuner(struct file *file, void *priv,
358 struct v4l2_tuner *v) 392 struct v4l2_tuner *v)
359{ 393{
360 struct amradio_device *radio = video_get_drvdata(video_devdata(file)); 394 struct amradio_device *radio = video_get_drvdata(video_devdata(file));
395 int retval;
361 396
362 /* safety check */ 397 /* safety check */
363 if (radio->removed) 398 if (radio->removed)
@@ -365,6 +400,25 @@ static int vidioc_s_tuner(struct file *file, void *priv,
365 400
366 if (v->index > 0) 401 if (v->index > 0)
367 return -EINVAL; 402 return -EINVAL;
403
404 /* mono/stereo selector */
405 switch (v->audmode) {
406 case V4L2_TUNER_MODE_MONO:
407 retval = amradio_set_stereo(radio, WANT_MONO);
408 if (retval < 0)
409 amradio_dev_warn(&radio->videodev->dev,
410 "set mono failed\n");
411 break;
412 case V4L2_TUNER_MODE_STEREO:
413 retval = amradio_set_stereo(radio, WANT_STEREO);
414 if (retval < 0)
415 amradio_dev_warn(&radio->videodev->dev,
416 "set stereo failed\n");
417 break;
418 default:
419 return -EINVAL;
420 }
421
368 return 0; 422 return 0;
369} 423}
370 424
@@ -373,13 +427,18 @@ static int vidioc_s_frequency(struct file *file, void *priv,
373 struct v4l2_frequency *f) 427 struct v4l2_frequency *f)
374{ 428{
375 struct amradio_device *radio = video_get_drvdata(video_devdata(file)); 429 struct amradio_device *radio = video_get_drvdata(video_devdata(file));
430 int retval;
376 431
377 /* safety check */ 432 /* safety check */
378 if (radio->removed) 433 if (radio->removed)
379 return -EIO; 434 return -EIO;
380 435
436 mutex_lock(&radio->lock);
381 radio->curfreq = f->frequency; 437 radio->curfreq = f->frequency;
382 if (amradio_setfreq(radio, radio->curfreq) < 0) 438 mutex_unlock(&radio->lock);
439
440 retval = amradio_setfreq(radio, radio->curfreq);
441 if (retval < 0)
383 amradio_dev_warn(&radio->videodev->dev, 442 amradio_dev_warn(&radio->videodev->dev,
384 "set frequency failed\n"); 443 "set frequency failed\n");
385 return 0; 444 return 0;
@@ -438,6 +497,7 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
438 struct v4l2_control *ctrl) 497 struct v4l2_control *ctrl)
439{ 498{
440 struct amradio_device *radio = video_get_drvdata(video_devdata(file)); 499 struct amradio_device *radio = video_get_drvdata(video_devdata(file));
500 int retval;
441 501
442 /* safety check */ 502 /* safety check */
443 if (radio->removed) 503 if (radio->removed)
@@ -446,13 +506,15 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
446 switch (ctrl->id) { 506 switch (ctrl->id) {
447 case V4L2_CID_AUDIO_MUTE: 507 case V4L2_CID_AUDIO_MUTE:
448 if (ctrl->value) { 508 if (ctrl->value) {
449 if (amradio_stop(radio) < 0) { 509 retval = amradio_set_mute(radio, AMRADIO_STOP);
510 if (retval < 0) {
450 amradio_dev_warn(&radio->videodev->dev, 511 amradio_dev_warn(&radio->videodev->dev,
451 "amradio_stop failed\n"); 512 "amradio_stop failed\n");
452 return -1; 513 return -1;
453 } 514 }
454 } else { 515 } else {
455 if (amradio_start(radio) < 0) { 516 retval = amradio_set_mute(radio, AMRADIO_START);
517 if (retval < 0) {
456 amradio_dev_warn(&radio->videodev->dev, 518 amradio_dev_warn(&radio->videodev->dev,
457 "amradio_start failed\n"); 519 "amradio_start failed\n");
458 return -1; 520 return -1;
@@ -503,20 +565,29 @@ static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
503static int usb_amradio_open(struct file *file) 565static int usb_amradio_open(struct file *file)
504{ 566{
505 struct amradio_device *radio = video_get_drvdata(video_devdata(file)); 567 struct amradio_device *radio = video_get_drvdata(video_devdata(file));
568 int retval;
506 569
507 lock_kernel(); 570 lock_kernel();
508 571
509 radio->users = 1; 572 radio->users = 1;
510 radio->muted = 1; 573 radio->muted = 1;
511 574
512 if (amradio_start(radio) < 0) { 575 retval = amradio_set_mute(radio, AMRADIO_START);
576 if (retval < 0) {
513 amradio_dev_warn(&radio->videodev->dev, 577 amradio_dev_warn(&radio->videodev->dev,
514 "radio did not start up properly\n"); 578 "radio did not start up properly\n");
515 radio->users = 0; 579 radio->users = 0;
516 unlock_kernel(); 580 unlock_kernel();
517 return -EIO; 581 return -EIO;
518 } 582 }
519 if (amradio_setfreq(radio, radio->curfreq) < 0) 583
584 retval = amradio_set_stereo(radio, WANT_STEREO);
585 if (retval < 0)
586 amradio_dev_warn(&radio->videodev->dev,
587 "set stereo failed\n");
588
589 retval = amradio_setfreq(radio, radio->curfreq);
590 if (retval < 0)
520 amradio_dev_warn(&radio->videodev->dev, 591 amradio_dev_warn(&radio->videodev->dev,
521 "set frequency failed\n"); 592 "set frequency failed\n");
522 593
@@ -533,10 +604,12 @@ static int usb_amradio_close(struct file *file)
533 if (!radio) 604 if (!radio)
534 return -ENODEV; 605 return -ENODEV;
535 606
607 mutex_lock(&radio->lock);
536 radio->users = 0; 608 radio->users = 0;
609 mutex_unlock(&radio->lock);
537 610
538 if (!radio->removed) { 611 if (!radio->removed) {
539 retval = amradio_stop(radio); 612 retval = amradio_set_mute(radio, AMRADIO_STOP);
540 if (retval < 0) 613 if (retval < 0)
541 amradio_dev_warn(&radio->videodev->dev, 614 amradio_dev_warn(&radio->videodev->dev,
542 "amradio_stop failed\n"); 615 "amradio_stop failed\n");
@@ -549,8 +622,10 @@ static int usb_amradio_close(struct file *file)
549static int usb_amradio_suspend(struct usb_interface *intf, pm_message_t message) 622static int usb_amradio_suspend(struct usb_interface *intf, pm_message_t message)
550{ 623{
551 struct amradio_device *radio = usb_get_intfdata(intf); 624 struct amradio_device *radio = usb_get_intfdata(intf);
625 int retval;
552 626
553 if (amradio_stop(radio) < 0) 627 retval = amradio_set_mute(radio, AMRADIO_STOP);
628 if (retval < 0)
554 dev_warn(&intf->dev, "amradio_stop failed\n"); 629 dev_warn(&intf->dev, "amradio_stop failed\n");
555 630
556 dev_info(&intf->dev, "going into suspend..\n"); 631 dev_info(&intf->dev, "going into suspend..\n");
@@ -562,8 +637,10 @@ static int usb_amradio_suspend(struct usb_interface *intf, pm_message_t message)
562static int usb_amradio_resume(struct usb_interface *intf) 637static int usb_amradio_resume(struct usb_interface *intf)
563{ 638{
564 struct amradio_device *radio = usb_get_intfdata(intf); 639 struct amradio_device *radio = usb_get_intfdata(intf);
640 int retval;
565 641
566 if (amradio_start(radio) < 0) 642 retval = amradio_set_mute(radio, AMRADIO_START);
643 if (retval < 0)
567 dev_warn(&intf->dev, "amradio_start failed\n"); 644 dev_warn(&intf->dev, "amradio_start failed\n");
568 645
569 dev_info(&intf->dev, "coming out of suspend..\n"); 646 dev_info(&intf->dev, "coming out of suspend..\n");
@@ -614,28 +691,32 @@ static struct video_device amradio_videodev_template = {
614 .release = usb_amradio_device_release, 691 .release = usb_amradio_device_release,
615}; 692};
616 693
617/* check if the device is present and register with v4l and 694/* check if the device is present and register with v4l and usb if it is */
618usb if it is */
619static int usb_amradio_probe(struct usb_interface *intf, 695static int usb_amradio_probe(struct usb_interface *intf,
620 const struct usb_device_id *id) 696 const struct usb_device_id *id)
621{ 697{
622 struct amradio_device *radio; 698 struct amradio_device *radio;
699 int retval;
623 700
624 radio = kmalloc(sizeof(struct amradio_device), GFP_KERNEL); 701 radio = kmalloc(sizeof(struct amradio_device), GFP_KERNEL);
625 702
626 if (!(radio)) 703 if (!radio) {
704 dev_err(&intf->dev, "kmalloc for amradio_device failed\n");
627 return -ENOMEM; 705 return -ENOMEM;
706 }
628 707
629 radio->buffer = kmalloc(BUFFER_LENGTH, GFP_KERNEL); 708 radio->buffer = kmalloc(BUFFER_LENGTH, GFP_KERNEL);
630 709
631 if (!(radio->buffer)) { 710 if (!radio->buffer) {
711 dev_err(&intf->dev, "kmalloc for radio->buffer failed\n");
632 kfree(radio); 712 kfree(radio);
633 return -ENOMEM; 713 return -ENOMEM;
634 } 714 }
635 715
636 radio->videodev = video_device_alloc(); 716 radio->videodev = video_device_alloc();
637 717
638 if (!(radio->videodev)) { 718 if (!radio->videodev) {
719 dev_err(&intf->dev, "video_device_alloc failed\n");
639 kfree(radio->buffer); 720 kfree(radio->buffer);
640 kfree(radio); 721 kfree(radio);
641 return -ENOMEM; 722 return -ENOMEM;
@@ -648,12 +729,14 @@ static int usb_amradio_probe(struct usb_interface *intf,
648 radio->users = 0; 729 radio->users = 0;
649 radio->usbdev = interface_to_usbdev(intf); 730 radio->usbdev = interface_to_usbdev(intf);
650 radio->curfreq = 95.16 * FREQ_MUL; 731 radio->curfreq = 95.16 * FREQ_MUL;
732 radio->stereo = -1;
651 733
652 mutex_init(&radio->lock); 734 mutex_init(&radio->lock);
653 735
654 video_set_drvdata(radio->videodev, radio); 736 video_set_drvdata(radio->videodev, radio);
655 if (video_register_device(radio->videodev, VFL_TYPE_RADIO, radio_nr)) { 737 retval = video_register_device(radio->videodev, VFL_TYPE_RADIO, radio_nr);
656 dev_warn(&intf->dev, "could not register video device\n"); 738 if (retval < 0) {
739 dev_err(&intf->dev, "could not register video device\n");
657 video_device_release(radio->videodev); 740 video_device_release(radio->videodev);
658 kfree(radio->buffer); 741 kfree(radio->buffer);
659 kfree(radio); 742 kfree(radio);
diff --git a/drivers/media/radio/radio-rtrack2.c b/drivers/media/radio/radio-rtrack2.c
index 2587227214bf..d1e6b01d4eca 100644
--- a/drivers/media/radio/radio-rtrack2.c
+++ b/drivers/media/radio/radio-rtrack2.c
@@ -13,34 +13,16 @@
13#include <linux/init.h> /* Initdata */ 13#include <linux/init.h> /* Initdata */
14#include <linux/ioport.h> /* request_region */ 14#include <linux/ioport.h> /* request_region */
15#include <linux/delay.h> /* udelay */ 15#include <linux/delay.h> /* udelay */
16#include <asm/io.h> /* outb, outb_p */
17#include <asm/uaccess.h> /* copy to/from user */
18#include <linux/videodev2.h> /* kernel radio structs */ 16#include <linux/videodev2.h> /* kernel radio structs */
19#include <media/v4l2-common.h> 17#include <linux/mutex.h>
18#include <linux/version.h> /* for KERNEL_VERSION MACRO */
19#include <linux/io.h> /* outb, outb_p */
20#include <media/v4l2-device.h>
20#include <media/v4l2-ioctl.h> 21#include <media/v4l2-ioctl.h>
21#include <linux/spinlock.h>
22 22
23#include <linux/version.h> /* for KERNEL_VERSION MACRO */ 23MODULE_AUTHOR("Ben Pfaff");
24#define RADIO_VERSION KERNEL_VERSION(0,0,2) 24MODULE_DESCRIPTION("A driver for the RadioTrack II radio card.");
25 25MODULE_LICENSE("GPL");
26static struct v4l2_queryctrl radio_qctrl[] = {
27 {
28 .id = V4L2_CID_AUDIO_MUTE,
29 .name = "Mute",
30 .minimum = 0,
31 .maximum = 1,
32 .default_value = 1,
33 .type = V4L2_CTRL_TYPE_BOOLEAN,
34 },{
35 .id = V4L2_CID_AUDIO_VOLUME,
36 .name = "Volume",
37 .minimum = 0,
38 .maximum = 65535,
39 .step = 65535,
40 .default_value = 0xff,
41 .type = V4L2_CTRL_TYPE_INTEGER,
42 }
43};
44 26
45#ifndef CONFIG_RADIO_RTRACK2_PORT 27#ifndef CONFIG_RADIO_RTRACK2_PORT
46#define CONFIG_RADIO_RTRACK2_PORT -1 28#define CONFIG_RADIO_RTRACK2_PORT -1
@@ -48,79 +30,88 @@ static struct v4l2_queryctrl radio_qctrl[] = {
48 30
49static int io = CONFIG_RADIO_RTRACK2_PORT; 31static int io = CONFIG_RADIO_RTRACK2_PORT;
50static int radio_nr = -1; 32static int radio_nr = -1;
51static spinlock_t lock;
52 33
53struct rt_device 34module_param(io, int, 0);
35MODULE_PARM_DESC(io, "I/O address of the RadioTrack card (0x20c or 0x30c)");
36module_param(radio_nr, int, 0);
37
38#define RADIO_VERSION KERNEL_VERSION(0, 0, 2)
39
40struct rtrack2
54{ 41{
55 unsigned long in_use; 42 struct v4l2_device v4l2_dev;
56 int port; 43 struct video_device vdev;
44 int io;
57 unsigned long curfreq; 45 unsigned long curfreq;
58 int muted; 46 int muted;
47 struct mutex lock;
59}; 48};
60 49
50static struct rtrack2 rtrack2_card;
51
61 52
62/* local things */ 53/* local things */
63 54
64static void rt_mute(struct rt_device *dev) 55static void rt_mute(struct rtrack2 *dev)
65{ 56{
66 if(dev->muted) 57 if (dev->muted)
67 return; 58 return;
68 spin_lock(&lock); 59 mutex_lock(&dev->lock);
69 outb(1, io); 60 outb(1, dev->io);
70 spin_unlock(&lock); 61 mutex_unlock(&dev->lock);
71 dev->muted = 1; 62 dev->muted = 1;
72} 63}
73 64
74static void rt_unmute(struct rt_device *dev) 65static void rt_unmute(struct rtrack2 *dev)
75{ 66{
76 if(dev->muted == 0) 67 if(dev->muted == 0)
77 return; 68 return;
78 spin_lock(&lock); 69 mutex_lock(&dev->lock);
79 outb(0, io); 70 outb(0, dev->io);
80 spin_unlock(&lock); 71 mutex_unlock(&dev->lock);
81 dev->muted = 0; 72 dev->muted = 0;
82} 73}
83 74
84static void zero(void) 75static void zero(struct rtrack2 *dev)
85{ 76{
86 outb_p(1, io); 77 outb_p(1, dev->io);
87 outb_p(3, io); 78 outb_p(3, dev->io);
88 outb_p(1, io); 79 outb_p(1, dev->io);
89} 80}
90 81
91static void one(void) 82static void one(struct rtrack2 *dev)
92{ 83{
93 outb_p(5, io); 84 outb_p(5, dev->io);
94 outb_p(7, io); 85 outb_p(7, dev->io);
95 outb_p(5, io); 86 outb_p(5, dev->io);
96} 87}
97 88
98static int rt_setfreq(struct rt_device *dev, unsigned long freq) 89static int rt_setfreq(struct rtrack2 *dev, unsigned long freq)
99{ 90{
100 int i; 91 int i;
101 92
93 mutex_lock(&dev->lock);
94 dev->curfreq = freq;
102 freq = freq / 200 + 856; 95 freq = freq / 200 + 856;
103 96
104 spin_lock(&lock); 97 outb_p(0xc8, dev->io);
105 98 outb_p(0xc9, dev->io);
106 outb_p(0xc8, io); 99 outb_p(0xc9, dev->io);
107 outb_p(0xc9, io);
108 outb_p(0xc9, io);
109 100
110 for (i = 0; i < 10; i++) 101 for (i = 0; i < 10; i++)
111 zero (); 102 zero(dev);
112 103
113 for (i = 14; i >= 0; i--) 104 for (i = 14; i >= 0; i--)
114 if (freq & (1 << i)) 105 if (freq & (1 << i))
115 one (); 106 one(dev);
116 else 107 else
117 zero (); 108 zero(dev);
118 109
119 outb_p(0xc8, io); 110 outb_p(0xc8, dev->io);
120 if (!dev->muted) 111 if (!dev->muted)
121 outb_p(0, io); 112 outb_p(0, dev->io);
122 113
123 spin_unlock(&lock); 114 mutex_unlock(&dev->lock);
124 return 0; 115 return 0;
125} 116}
126 117
@@ -129,61 +120,61 @@ static int vidioc_querycap(struct file *file, void *priv,
129{ 120{
130 strlcpy(v->driver, "radio-rtrack2", sizeof(v->driver)); 121 strlcpy(v->driver, "radio-rtrack2", sizeof(v->driver));
131 strlcpy(v->card, "RadioTrack II", sizeof(v->card)); 122 strlcpy(v->card, "RadioTrack II", sizeof(v->card));
132 sprintf(v->bus_info, "ISA"); 123 strlcpy(v->bus_info, "ISA", sizeof(v->bus_info));
133 v->version = RADIO_VERSION; 124 v->version = RADIO_VERSION;
134 v->capabilities = V4L2_CAP_TUNER; 125 v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
135 return 0; 126 return 0;
136} 127}
137 128
138static int vidioc_s_tuner(struct file *file, void *priv, 129static int vidioc_s_tuner(struct file *file, void *priv,
139 struct v4l2_tuner *v) 130 struct v4l2_tuner *v)
140{ 131{
141 if (v->index > 0) 132 return v->index ? -EINVAL : 0;
142 return -EINVAL;
143
144 return 0;
145} 133}
146 134
147static int rt_getsigstr(struct rt_device *dev) 135static int rt_getsigstr(struct rtrack2 *dev)
148{ 136{
149 if (inb(io) & 2) /* bit set = no signal present */ 137 int sig = 1;
150 return 0; 138
151 return 1; /* signal present */ 139 mutex_lock(&dev->lock);
140 if (inb(dev->io) & 2) /* bit set = no signal present */
141 sig = 0;
142 mutex_unlock(&dev->lock);
143 return sig;
152} 144}
153 145
154static int vidioc_g_tuner(struct file *file, void *priv, 146static int vidioc_g_tuner(struct file *file, void *priv,
155 struct v4l2_tuner *v) 147 struct v4l2_tuner *v)
156{ 148{
157 struct rt_device *rt = video_drvdata(file); 149 struct rtrack2 *rt = video_drvdata(file);
158 150
159 if (v->index > 0) 151 if (v->index > 0)
160 return -EINVAL; 152 return -EINVAL;
161 153
162 strcpy(v->name, "FM"); 154 strlcpy(v->name, "FM", sizeof(v->name));
163 v->type = V4L2_TUNER_RADIO; 155 v->type = V4L2_TUNER_RADIO;
164 v->rangelow = (88*16000); 156 v->rangelow = 88 * 16000;
165 v->rangehigh = (108*16000); 157 v->rangehigh = 108 * 16000;
166 v->rxsubchans = V4L2_TUNER_SUB_MONO; 158 v->rxsubchans = V4L2_TUNER_SUB_MONO;
167 v->capability = V4L2_TUNER_CAP_LOW; 159 v->capability = V4L2_TUNER_CAP_LOW;
168 v->audmode = V4L2_TUNER_MODE_MONO; 160 v->audmode = V4L2_TUNER_MODE_MONO;
169 v->signal = 0xFFFF*rt_getsigstr(rt); 161 v->signal = 0xFFFF * rt_getsigstr(rt);
170 return 0; 162 return 0;
171} 163}
172 164
173static int vidioc_s_frequency(struct file *file, void *priv, 165static int vidioc_s_frequency(struct file *file, void *priv,
174 struct v4l2_frequency *f) 166 struct v4l2_frequency *f)
175{ 167{
176 struct rt_device *rt = video_drvdata(file); 168 struct rtrack2 *rt = video_drvdata(file);
177 169
178 rt->curfreq = f->frequency; 170 rt_setfreq(rt, f->frequency);
179 rt_setfreq(rt, rt->curfreq);
180 return 0; 171 return 0;
181} 172}
182 173
183static int vidioc_g_frequency(struct file *file, void *priv, 174static int vidioc_g_frequency(struct file *file, void *priv,
184 struct v4l2_frequency *f) 175 struct v4l2_frequency *f)
185{ 176{
186 struct rt_device *rt = video_drvdata(file); 177 struct rtrack2 *rt = video_drvdata(file);
187 178
188 f->type = V4L2_TUNER_RADIO; 179 f->type = V4L2_TUNER_RADIO;
189 f->frequency = rt->curfreq; 180 f->frequency = rt->curfreq;
@@ -193,14 +184,11 @@ static int vidioc_g_frequency(struct file *file, void *priv,
193static int vidioc_queryctrl(struct file *file, void *priv, 184static int vidioc_queryctrl(struct file *file, void *priv,
194 struct v4l2_queryctrl *qc) 185 struct v4l2_queryctrl *qc)
195{ 186{
196 int i; 187 switch (qc->id) {
197 188 case V4L2_CID_AUDIO_MUTE:
198 for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) { 189 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
199 if (qc->id && qc->id == radio_qctrl[i].id) { 190 case V4L2_CID_AUDIO_VOLUME:
200 memcpy(qc, &(radio_qctrl[i]), 191 return v4l2_ctrl_query_fill(qc, 0, 65535, 65535, 65535);
201 sizeof(*qc));
202 return 0;
203 }
204 } 192 }
205 return -EINVAL; 193 return -EINVAL;
206} 194}
@@ -208,7 +196,7 @@ static int vidioc_queryctrl(struct file *file, void *priv,
208static int vidioc_g_ctrl(struct file *file, void *priv, 196static int vidioc_g_ctrl(struct file *file, void *priv,
209 struct v4l2_control *ctrl) 197 struct v4l2_control *ctrl)
210{ 198{
211 struct rt_device *rt = video_drvdata(file); 199 struct rtrack2 *rt = video_drvdata(file);
212 200
213 switch (ctrl->id) { 201 switch (ctrl->id) {
214 case V4L2_CID_AUDIO_MUTE: 202 case V4L2_CID_AUDIO_MUTE:
@@ -227,7 +215,7 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
227static int vidioc_s_ctrl(struct file *file, void *priv, 215static int vidioc_s_ctrl(struct file *file, void *priv,
228 struct v4l2_control *ctrl) 216 struct v4l2_control *ctrl)
229{ 217{
230 struct rt_device *rt = video_drvdata(file); 218 struct rtrack2 *rt = video_drvdata(file);
231 219
232 switch (ctrl->id) { 220 switch (ctrl->id) {
233 case V4L2_CID_AUDIO_MUTE: 221 case V4L2_CID_AUDIO_MUTE:
@@ -246,17 +234,6 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
246 return -EINVAL; 234 return -EINVAL;
247} 235}
248 236
249static int vidioc_g_audio(struct file *file, void *priv,
250 struct v4l2_audio *a)
251{
252 if (a->index > 1)
253 return -EINVAL;
254
255 strcpy(a->name, "Radio");
256 a->capability = V4L2_AUDCAP_STEREO;
257 return 0;
258}
259
260static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i) 237static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
261{ 238{
262 *i = 0; 239 *i = 0;
@@ -265,36 +242,38 @@ static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
265 242
266static int vidioc_s_input(struct file *filp, void *priv, unsigned int i) 243static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
267{ 244{
268 if (i != 0) 245 return i ? -EINVAL : 0;
269 return -EINVAL;
270 return 0;
271} 246}
272 247
273static int vidioc_s_audio(struct file *file, void *priv, 248static int vidioc_g_audio(struct file *file, void *priv,
274 struct v4l2_audio *a) 249 struct v4l2_audio *a)
275{ 250{
276 if (a->index != 0) 251 a->index = 0;
277 return -EINVAL; 252 strlcpy(a->name, "Radio", sizeof(a->name));
253 a->capability = V4L2_AUDCAP_STEREO;
278 return 0; 254 return 0;
279} 255}
280 256
281static struct rt_device rtrack2_unit; 257static int vidioc_s_audio(struct file *file, void *priv,
258 struct v4l2_audio *a)
259{
260 return a->index ? -EINVAL : 0;
261}
282 262
283static int rtrack2_exclusive_open(struct file *file) 263static int rtrack2_open(struct file *file)
284{ 264{
285 return test_and_set_bit(0, &rtrack2_unit.in_use) ? -EBUSY : 0; 265 return 0;
286} 266}
287 267
288static int rtrack2_exclusive_release(struct file *file) 268static int rtrack2_release(struct file *file)
289{ 269{
290 clear_bit(0, &rtrack2_unit.in_use);
291 return 0; 270 return 0;
292} 271}
293 272
294static const struct v4l2_file_operations rtrack2_fops = { 273static const struct v4l2_file_operations rtrack2_fops = {
295 .owner = THIS_MODULE, 274 .owner = THIS_MODULE,
296 .open = rtrack2_exclusive_open, 275 .open = rtrack2_open,
297 .release = rtrack2_exclusive_release, 276 .release = rtrack2_release,
298 .ioctl = video_ioctl2, 277 .ioctl = video_ioctl2,
299}; 278};
300 279
@@ -313,62 +292,61 @@ static const struct v4l2_ioctl_ops rtrack2_ioctl_ops = {
313 .vidioc_s_input = vidioc_s_input, 292 .vidioc_s_input = vidioc_s_input,
314}; 293};
315 294
316static struct video_device rtrack2_radio = {
317 .name = "RadioTrack II radio",
318 .fops = &rtrack2_fops,
319 .ioctl_ops = &rtrack2_ioctl_ops,
320 .release = video_device_release_empty,
321};
322
323static int __init rtrack2_init(void) 295static int __init rtrack2_init(void)
324{ 296{
325 if(io==-1) 297 struct rtrack2 *dev = &rtrack2_card;
326 { 298 struct v4l2_device *v4l2_dev = &dev->v4l2_dev;
327 printk(KERN_ERR "You must set an I/O address with io=0x20c or io=0x30c\n"); 299 int res;
300
301 strlcpy(v4l2_dev->name, "rtrack2", sizeof(v4l2_dev->name));
302 dev->io = io;
303 if (dev->io == -1) {
304 v4l2_err(v4l2_dev, "You must set an I/O address with io=0x20c or io=0x30c\n");
328 return -EINVAL; 305 return -EINVAL;
329 } 306 }
330 if (!request_region(io, 4, "rtrack2")) 307 if (!request_region(dev->io, 4, "rtrack2")) {
331 { 308 v4l2_err(v4l2_dev, "port 0x%x already in use\n", dev->io);
332 printk(KERN_ERR "rtrack2: port 0x%x already in use\n", io);
333 return -EBUSY; 309 return -EBUSY;
334 } 310 }
335 311
336 video_set_drvdata(&rtrack2_radio, &rtrack2_unit); 312 res = v4l2_device_register(NULL, v4l2_dev);
313 if (res < 0) {
314 release_region(dev->io, 4);
315 v4l2_err(v4l2_dev, "Could not register v4l2_device\n");
316 return res;
317 }
337 318
338 spin_lock_init(&lock); 319 strlcpy(dev->vdev.name, v4l2_dev->name, sizeof(dev->vdev.name));
339 if (video_register_device(&rtrack2_radio, VFL_TYPE_RADIO, radio_nr) < 0) { 320 dev->vdev.v4l2_dev = v4l2_dev;
340 release_region(io, 4); 321 dev->vdev.fops = &rtrack2_fops;
322 dev->vdev.ioctl_ops = &rtrack2_ioctl_ops;
323 dev->vdev.release = video_device_release_empty;
324 video_set_drvdata(&dev->vdev, dev);
325
326 mutex_init(&dev->lock);
327 if (video_register_device(&dev->vdev, VFL_TYPE_RADIO, radio_nr) < 0) {
328 v4l2_device_unregister(v4l2_dev);
329 release_region(dev->io, 4);
341 return -EINVAL; 330 return -EINVAL;
342 } 331 }
343 332
344 printk(KERN_INFO "AIMSlab Radiotrack II card driver.\n"); 333 v4l2_info(v4l2_dev, "AIMSlab Radiotrack II card driver.\n");
345 334
346 /* mute card - prevents noisy bootups */ 335 /* mute card - prevents noisy bootups */
347 outb(1, io); 336 outb(1, dev->io);
348 rtrack2_unit.muted = 1; 337 dev->muted = 1;
349 338
350 return 0; 339 return 0;
351} 340}
352 341
353MODULE_AUTHOR("Ben Pfaff"); 342static void __exit rtrack2_exit(void)
354MODULE_DESCRIPTION("A driver for the RadioTrack II radio card.");
355MODULE_LICENSE("GPL");
356
357module_param(io, int, 0);
358MODULE_PARM_DESC(io, "I/O address of the RadioTrack card (0x20c or 0x30c)");
359module_param(radio_nr, int, 0);
360
361static void __exit rtrack2_cleanup_module(void)
362{ 343{
363 video_unregister_device(&rtrack2_radio); 344 struct rtrack2 *dev = &rtrack2_card;
364 release_region(io,4); 345
346 video_unregister_device(&dev->vdev);
347 v4l2_device_unregister(&dev->v4l2_dev);
348 release_region(dev->io, 4);
365} 349}
366 350
367module_init(rtrack2_init); 351module_init(rtrack2_init);
368module_exit(rtrack2_cleanup_module); 352module_exit(rtrack2_exit);
369
370/*
371 Local variables:
372 compile-command: "mmake"
373 End:
374*/
diff --git a/drivers/media/radio/radio-sf16fmi.c b/drivers/media/radio/radio-sf16fmi.c
index d358e48c2422..f4784f0d1a88 100644
--- a/drivers/media/radio/radio-sf16fmi.c
+++ b/drivers/media/radio/radio-sf16fmi.c
@@ -22,113 +22,109 @@
22#include <linux/init.h> /* Initdata */ 22#include <linux/init.h> /* Initdata */
23#include <linux/ioport.h> /* request_region */ 23#include <linux/ioport.h> /* request_region */
24#include <linux/delay.h> /* udelay */ 24#include <linux/delay.h> /* udelay */
25#include <linux/videodev2.h> /* kernel radio structs */
26#include <media/v4l2-common.h>
27#include <media/v4l2-ioctl.h>
28#include <linux/isapnp.h> 25#include <linux/isapnp.h>
29#include <asm/io.h> /* outb, outb_p */
30#include <asm/uaccess.h> /* copy to/from user */
31#include <linux/mutex.h> 26#include <linux/mutex.h>
27#include <linux/videodev2.h> /* kernel radio structs */
28#include <linux/io.h> /* outb, outb_p */
29#include <media/v4l2-device.h>
30#include <media/v4l2-ioctl.h>
32 31
33#define RADIO_VERSION KERNEL_VERSION(0,0,2) 32MODULE_AUTHOR("Petr Vandrovec, vandrove@vc.cvut.cz and M. Kirkwood");
33MODULE_DESCRIPTION("A driver for the SF16MI radio.");
34MODULE_LICENSE("GPL");
34 35
35static struct v4l2_queryctrl radio_qctrl[] = { 36static int io = -1;
36 { 37static int radio_nr = -1;
37 .id = V4L2_CID_AUDIO_MUTE, 38
38 .name = "Mute", 39module_param(io, int, 0);
39 .minimum = 0, 40MODULE_PARM_DESC(io, "I/O address of the SF16MI card (0x284 or 0x384)");
40 .maximum = 1, 41module_param(radio_nr, int, 0);
41 .default_value = 1, 42
42 .type = V4L2_CTRL_TYPE_BOOLEAN, 43#define RADIO_VERSION KERNEL_VERSION(0, 0, 2)
43 }
44};
45 44
46struct fmi_device 45struct fmi
47{ 46{
48 unsigned long in_use; 47 struct v4l2_device v4l2_dev;
49 int port; 48 struct video_device vdev;
49 int io;
50 int curvol; /* 1 or 0 */ 50 int curvol; /* 1 or 0 */
51 unsigned long curfreq; /* freq in kHz */ 51 unsigned long curfreq; /* freq in kHz */
52 __u32 flags; 52 __u32 flags;
53 struct mutex lock;
53}; 54};
54 55
55static int io = -1; 56static struct fmi fmi_card;
56static int radio_nr = -1; 57static struct pnp_dev *dev;
57static struct pnp_dev *dev = NULL;
58static struct mutex lock;
59 58
60/* freq is in 1/16 kHz to internal number, hw precision is 50 kHz */ 59/* freq is in 1/16 kHz to internal number, hw precision is 50 kHz */
61/* It is only useful to give freq in intervall of 800 (=0.05Mhz), 60/* It is only useful to give freq in intervall of 800 (=0.05Mhz),
62 * other bits will be truncated, e.g 92.7400016 -> 92.7, but 61 * other bits will be truncated, e.g 92.7400016 -> 92.7, but
63 * 92.7400017 -> 92.75 62 * 92.7400017 -> 92.75
64 */ 63 */
65#define RSF16_ENCODE(x) ((x)/800+214) 64#define RSF16_ENCODE(x) ((x) / 800 + 214)
66#define RSF16_MINFREQ 87*16000 65#define RSF16_MINFREQ (87 * 16000)
67#define RSF16_MAXFREQ 108*16000 66#define RSF16_MAXFREQ (108 * 16000)
68 67
69static void outbits(int bits, unsigned int data, int port) 68static void outbits(int bits, unsigned int data, int io)
70{ 69{
71 while(bits--) { 70 while (bits--) {
72 if(data & 1) { 71 if (data & 1) {
73 outb(5, port); 72 outb(5, io);
74 udelay(6); 73 udelay(6);
75 outb(7, port); 74 outb(7, io);
76 udelay(6); 75 udelay(6);
77 } else { 76 } else {
78 outb(1, port); 77 outb(1, io);
79 udelay(6); 78 udelay(6);
80 outb(3, port); 79 outb(3, io);
81 udelay(6); 80 udelay(6);
82 } 81 }
83 data>>=1; 82 data >>= 1;
84 } 83 }
85} 84}
86 85
87static inline void fmi_mute(int port) 86static inline void fmi_mute(struct fmi *fmi)
88{ 87{
89 mutex_lock(&lock); 88 mutex_lock(&fmi->lock);
90 outb(0x00, port); 89 outb(0x00, fmi->io);
91 mutex_unlock(&lock); 90 mutex_unlock(&fmi->lock);
92} 91}
93 92
94static inline void fmi_unmute(int port) 93static inline void fmi_unmute(struct fmi *fmi)
95{ 94{
96 mutex_lock(&lock); 95 mutex_lock(&fmi->lock);
97 outb(0x08, port); 96 outb(0x08, fmi->io);
98 mutex_unlock(&lock); 97 mutex_unlock(&fmi->lock);
99} 98}
100 99
101static inline int fmi_setfreq(struct fmi_device *dev) 100static inline int fmi_setfreq(struct fmi *fmi, unsigned long freq)
102{ 101{
103 int myport = dev->port; 102 mutex_lock(&fmi->lock);
104 unsigned long freq = dev->curfreq; 103 fmi->curfreq = freq;
105 104
106 mutex_lock(&lock); 105 outbits(16, RSF16_ENCODE(freq), fmi->io);
107 106 outbits(8, 0xC0, fmi->io);
108 outbits(16, RSF16_ENCODE(freq), myport);
109 outbits(8, 0xC0, myport);
110 msleep(143); /* was schedule_timeout(HZ/7) */ 107 msleep(143); /* was schedule_timeout(HZ/7) */
111 mutex_unlock(&lock); 108 mutex_unlock(&fmi->lock);
112 if (dev->curvol) fmi_unmute(myport); 109 if (fmi->curvol)
110 fmi_unmute(fmi);
113 return 0; 111 return 0;
114} 112}
115 113
116static inline int fmi_getsigstr(struct fmi_device *dev) 114static inline int fmi_getsigstr(struct fmi *fmi)
117{ 115{
118 int val; 116 int val;
119 int res; 117 int res;
120 int myport = dev->port;
121
122 118
123 mutex_lock(&lock); 119 mutex_lock(&fmi->lock);
124 val = dev->curvol ? 0x08 : 0x00; /* unmute/mute */ 120 val = fmi->curvol ? 0x08 : 0x00; /* unmute/mute */
125 outb(val, myport); 121 outb(val, fmi->io);
126 outb(val | 0x10, myport); 122 outb(val | 0x10, fmi->io);
127 msleep(143); /* was schedule_timeout(HZ/7) */ 123 msleep(143); /* was schedule_timeout(HZ/7) */
128 res = (int)inb(myport+1); 124 res = (int)inb(fmi->io + 1);
129 outb(val, myport); 125 outb(val, fmi->io);
130 126
131 mutex_unlock(&lock); 127 mutex_unlock(&fmi->lock);
132 return (res & 2) ? 0 : 0xFFFF; 128 return (res & 2) ? 0 : 0xFFFF;
133} 129}
134 130
@@ -137,9 +133,9 @@ static int vidioc_querycap(struct file *file, void *priv,
137{ 133{
138 strlcpy(v->driver, "radio-sf16fmi", sizeof(v->driver)); 134 strlcpy(v->driver, "radio-sf16fmi", sizeof(v->driver));
139 strlcpy(v->card, "SF16-FMx radio", sizeof(v->card)); 135 strlcpy(v->card, "SF16-FMx radio", sizeof(v->card));
140 sprintf(v->bus_info, "ISA"); 136 strlcpy(v->bus_info, "ISA", sizeof(v->bus_info));
141 v->version = RADIO_VERSION; 137 v->version = RADIO_VERSION;
142 v->capabilities = V4L2_CAP_TUNER; 138 v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
143 return 0; 139 return 0;
144} 140}
145 141
@@ -147,18 +143,18 @@ static int vidioc_g_tuner(struct file *file, void *priv,
147 struct v4l2_tuner *v) 143 struct v4l2_tuner *v)
148{ 144{
149 int mult; 145 int mult;
150 struct fmi_device *fmi = video_drvdata(file); 146 struct fmi *fmi = video_drvdata(file);
151 147
152 if (v->index > 0) 148 if (v->index > 0)
153 return -EINVAL; 149 return -EINVAL;
154 150
155 strcpy(v->name, "FM"); 151 strlcpy(v->name, "FM", sizeof(v->name));
156 v->type = V4L2_TUNER_RADIO; 152 v->type = V4L2_TUNER_RADIO;
157 mult = (fmi->flags & V4L2_TUNER_CAP_LOW) ? 1 : 1000; 153 mult = (fmi->flags & V4L2_TUNER_CAP_LOW) ? 1 : 1000;
158 v->rangelow = RSF16_MINFREQ/mult; 154 v->rangelow = RSF16_MINFREQ / mult;
159 v->rangehigh = RSF16_MAXFREQ/mult; 155 v->rangehigh = RSF16_MAXFREQ / mult;
160 v->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_MODE_STEREO; 156 v->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_MODE_STEREO;
161 v->capability = fmi->flags&V4L2_TUNER_CAP_LOW; 157 v->capability = fmi->flags & V4L2_TUNER_CAP_LOW;
162 v->audmode = V4L2_TUNER_MODE_STEREO; 158 v->audmode = V4L2_TUNER_MODE_STEREO;
163 v->signal = fmi_getsigstr(fmi); 159 v->signal = fmi_getsigstr(fmi);
164 return 0; 160 return 0;
@@ -167,32 +163,29 @@ static int vidioc_g_tuner(struct file *file, void *priv,
167static int vidioc_s_tuner(struct file *file, void *priv, 163static int vidioc_s_tuner(struct file *file, void *priv,
168 struct v4l2_tuner *v) 164 struct v4l2_tuner *v)
169{ 165{
170 if (v->index > 0) 166 return v->index ? -EINVAL : 0;
171 return -EINVAL;
172 return 0;
173} 167}
174 168
175static int vidioc_s_frequency(struct file *file, void *priv, 169static int vidioc_s_frequency(struct file *file, void *priv,
176 struct v4l2_frequency *f) 170 struct v4l2_frequency *f)
177{ 171{
178 struct fmi_device *fmi = video_drvdata(file); 172 struct fmi *fmi = video_drvdata(file);
179 173
180 if (!(fmi->flags & V4L2_TUNER_CAP_LOW)) 174 if (!(fmi->flags & V4L2_TUNER_CAP_LOW))
181 f->frequency *= 1000; 175 f->frequency *= 1000;
182 if (f->frequency < RSF16_MINFREQ || 176 if (f->frequency < RSF16_MINFREQ ||
183 f->frequency > RSF16_MAXFREQ ) 177 f->frequency > RSF16_MAXFREQ)
184 return -EINVAL; 178 return -EINVAL;
185 /*rounding in steps of 800 to match th freq 179 /* rounding in steps of 800 to match the freq
186 that will be used */ 180 that will be used */
187 fmi->curfreq = (f->frequency/800)*800; 181 fmi_setfreq(fmi, (f->frequency / 800) * 800);
188 fmi_setfreq(fmi);
189 return 0; 182 return 0;
190} 183}
191 184
192static int vidioc_g_frequency(struct file *file, void *priv, 185static int vidioc_g_frequency(struct file *file, void *priv,
193 struct v4l2_frequency *f) 186 struct v4l2_frequency *f)
194{ 187{
195 struct fmi_device *fmi = video_drvdata(file); 188 struct fmi *fmi = video_drvdata(file);
196 189
197 f->type = V4L2_TUNER_RADIO; 190 f->type = V4L2_TUNER_RADIO;
198 f->frequency = fmi->curfreq; 191 f->frequency = fmi->curfreq;
@@ -204,14 +197,9 @@ static int vidioc_g_frequency(struct file *file, void *priv,
204static int vidioc_queryctrl(struct file *file, void *priv, 197static int vidioc_queryctrl(struct file *file, void *priv,
205 struct v4l2_queryctrl *qc) 198 struct v4l2_queryctrl *qc)
206{ 199{
207 int i; 200 switch (qc->id) {
208 201 case V4L2_CID_AUDIO_MUTE:
209 for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) { 202 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
210 if (qc->id && qc->id == radio_qctrl[i].id) {
211 memcpy(qc, &(radio_qctrl[i]),
212 sizeof(*qc));
213 return 0;
214 }
215 } 203 }
216 return -EINVAL; 204 return -EINVAL;
217} 205}
@@ -219,7 +207,7 @@ static int vidioc_queryctrl(struct file *file, void *priv,
219static int vidioc_g_ctrl(struct file *file, void *priv, 207static int vidioc_g_ctrl(struct file *file, void *priv,
220 struct v4l2_control *ctrl) 208 struct v4l2_control *ctrl)
221{ 209{
222 struct fmi_device *fmi = video_drvdata(file); 210 struct fmi *fmi = video_drvdata(file);
223 211
224 switch (ctrl->id) { 212 switch (ctrl->id) {
225 case V4L2_CID_AUDIO_MUTE: 213 case V4L2_CID_AUDIO_MUTE:
@@ -232,31 +220,20 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
232static int vidioc_s_ctrl(struct file *file, void *priv, 220static int vidioc_s_ctrl(struct file *file, void *priv,
233 struct v4l2_control *ctrl) 221 struct v4l2_control *ctrl)
234{ 222{
235 struct fmi_device *fmi = video_drvdata(file); 223 struct fmi *fmi = video_drvdata(file);
236 224
237 switch (ctrl->id) { 225 switch (ctrl->id) {
238 case V4L2_CID_AUDIO_MUTE: 226 case V4L2_CID_AUDIO_MUTE:
239 if (ctrl->value) 227 if (ctrl->value)
240 fmi_mute(fmi->port); 228 fmi_mute(fmi);
241 else 229 else
242 fmi_unmute(fmi->port); 230 fmi_unmute(fmi);
243 fmi->curvol = ctrl->value; 231 fmi->curvol = ctrl->value;
244 return 0; 232 return 0;
245 } 233 }
246 return -EINVAL; 234 return -EINVAL;
247} 235}
248 236
249static int vidioc_g_audio(struct file *file, void *priv,
250 struct v4l2_audio *a)
251{
252 if (a->index > 1)
253 return -EINVAL;
254
255 strcpy(a->name, "Radio");
256 a->capability = V4L2_AUDCAP_STEREO;
257 return 0;
258}
259
260static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i) 237static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
261{ 238{
262 *i = 0; 239 *i = 0;
@@ -265,36 +242,38 @@ static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
265 242
266static int vidioc_s_input(struct file *filp, void *priv, unsigned int i) 243static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
267{ 244{
268 if (i != 0) 245 return i ? -EINVAL : 0;
269 return -EINVAL;
270 return 0;
271} 246}
272 247
273static int vidioc_s_audio(struct file *file, void *priv, 248static int vidioc_g_audio(struct file *file, void *priv,
274 struct v4l2_audio *a) 249 struct v4l2_audio *a)
275{ 250{
276 if (a->index != 0) 251 a->index = 0;
277 return -EINVAL; 252 strlcpy(a->name, "Radio", sizeof(a->name));
253 a->capability = V4L2_AUDCAP_STEREO;
278 return 0; 254 return 0;
279} 255}
280 256
281static struct fmi_device fmi_unit; 257static int vidioc_s_audio(struct file *file, void *priv,
258 struct v4l2_audio *a)
259{
260 return a->index ? -EINVAL : 0;
261}
282 262
283static int fmi_exclusive_open(struct file *file) 263static int fmi_open(struct file *file)
284{ 264{
285 return test_and_set_bit(0, &fmi_unit.in_use) ? -EBUSY : 0; 265 return 0;
286} 266}
287 267
288static int fmi_exclusive_release(struct file *file) 268static int fmi_release(struct file *file)
289{ 269{
290 clear_bit(0, &fmi_unit.in_use);
291 return 0; 270 return 0;
292} 271}
293 272
294static const struct v4l2_file_operations fmi_fops = { 273static const struct v4l2_file_operations fmi_fops = {
295 .owner = THIS_MODULE, 274 .owner = THIS_MODULE,
296 .open = fmi_exclusive_open, 275 .open = fmi_open,
297 .release = fmi_exclusive_release, 276 .release = fmi_release,
298 .ioctl = video_ioctl2, 277 .ioctl = video_ioctl2,
299}; 278};
300 279
@@ -313,13 +292,6 @@ static const struct v4l2_ioctl_ops fmi_ioctl_ops = {
313 .vidioc_s_ctrl = vidioc_s_ctrl, 292 .vidioc_s_ctrl = vidioc_s_ctrl,
314}; 293};
315 294
316static struct video_device fmi_radio = {
317 .name = "SF16FMx radio",
318 .fops = &fmi_fops,
319 .ioctl_ops = &fmi_ioctl_ops,
320 .release = video_device_release_empty,
321};
322
323/* ladis: this is my card. does any other types exist? */ 295/* ladis: this is my card. does any other types exist? */
324static struct isapnp_device_id id_table[] __devinitdata = { 296static struct isapnp_device_id id_table[] __devinitdata = {
325 { ISAPNP_ANY_ID, ISAPNP_ANY_ID, 297 { ISAPNP_ANY_ID, ISAPNP_ANY_ID,
@@ -344,7 +316,7 @@ static int __init isapnp_fmi_probe(void)
344 if (pnp_device_attach(dev) < 0) 316 if (pnp_device_attach(dev) < 0)
345 return -EAGAIN; 317 return -EAGAIN;
346 if (pnp_activate_dev(dev) < 0) { 318 if (pnp_activate_dev(dev) < 0) {
347 printk ("radio-sf16fmi: PnP configure failed (out of resources?)\n"); 319 printk(KERN_ERR "radio-sf16fmi: PnP configure failed (out of resources?)\n");
348 pnp_device_detach(dev); 320 pnp_device_detach(dev);
349 return -ENOMEM; 321 return -ENOMEM;
350 } 322 }
@@ -354,59 +326,72 @@ static int __init isapnp_fmi_probe(void)
354 } 326 }
355 327
356 i = pnp_port_start(dev, 0); 328 i = pnp_port_start(dev, 0);
357 printk ("radio-sf16fmi: PnP reports card at %#x\n", i); 329 printk(KERN_INFO "radio-sf16fmi: PnP reports card at %#x\n", i);
358 330
359 return i; 331 return i;
360} 332}
361 333
362static int __init fmi_init(void) 334static int __init fmi_init(void)
363{ 335{
336 struct fmi *fmi = &fmi_card;
337 struct v4l2_device *v4l2_dev = &fmi->v4l2_dev;
338 int res;
339
364 if (io < 0) 340 if (io < 0)
365 io = isapnp_fmi_probe(); 341 io = isapnp_fmi_probe();
366 if (io < 0) { 342 strlcpy(v4l2_dev->name, "sf16fmi", sizeof(v4l2_dev->name));
367 printk(KERN_ERR "radio-sf16fmi: No PnP card found.\n"); 343 fmi->io = io;
368 return io; 344 if (fmi->io < 0) {
345 v4l2_err(v4l2_dev, "No PnP card found.\n");
346 return fmi->io;
369 } 347 }
370 if (!request_region(io, 2, "radio-sf16fmi")) { 348 if (!request_region(io, 2, "radio-sf16fmi")) {
371 printk(KERN_ERR "radio-sf16fmi: port 0x%x already in use\n", io); 349 v4l2_err(v4l2_dev, "port 0x%x already in use\n", fmi->io);
372 pnp_device_detach(dev); 350 pnp_device_detach(dev);
373 return -EBUSY; 351 return -EBUSY;
374 } 352 }
375 353
376 fmi_unit.port = io; 354 res = v4l2_device_register(NULL, v4l2_dev);
377 fmi_unit.curvol = 0; 355 if (res < 0) {
378 fmi_unit.curfreq = 0; 356 release_region(fmi->io, 2);
379 fmi_unit.flags = V4L2_TUNER_CAP_LOW; 357 pnp_device_detach(dev);
380 video_set_drvdata(&fmi_radio, &fmi_unit); 358 v4l2_err(v4l2_dev, "Could not register v4l2_device\n");
359 return res;
360 }
361
362 fmi->flags = V4L2_TUNER_CAP_LOW;
363 strlcpy(fmi->vdev.name, v4l2_dev->name, sizeof(fmi->vdev.name));
364 fmi->vdev.v4l2_dev = v4l2_dev;
365 fmi->vdev.fops = &fmi_fops;
366 fmi->vdev.ioctl_ops = &fmi_ioctl_ops;
367 fmi->vdev.release = video_device_release_empty;
368 video_set_drvdata(&fmi->vdev, fmi);
381 369
382 mutex_init(&lock); 370 mutex_init(&fmi->lock);
383 371
384 if (video_register_device(&fmi_radio, VFL_TYPE_RADIO, radio_nr) < 0) { 372 if (video_register_device(&fmi->vdev, VFL_TYPE_RADIO, radio_nr) < 0) {
385 release_region(io, 2); 373 v4l2_device_unregister(v4l2_dev);
374 release_region(fmi->io, 2);
375 pnp_device_detach(dev);
386 return -EINVAL; 376 return -EINVAL;
387 } 377 }
388 378
389 printk(KERN_INFO "SF16FMx radio card driver at 0x%x\n", io); 379 v4l2_info(v4l2_dev, "card driver at 0x%x\n", fmi->io);
390 /* mute card - prevents noisy bootups */ 380 /* mute card - prevents noisy bootups */
391 fmi_mute(io); 381 fmi_mute(fmi);
392 return 0; 382 return 0;
393} 383}
394 384
395MODULE_AUTHOR("Petr Vandrovec, vandrove@vc.cvut.cz and M. Kirkwood"); 385static void __exit fmi_exit(void)
396MODULE_DESCRIPTION("A driver for the SF16MI radio.");
397MODULE_LICENSE("GPL");
398
399module_param(io, int, 0);
400MODULE_PARM_DESC(io, "I/O address of the SF16MI card (0x284 or 0x384)");
401module_param(radio_nr, int, 0);
402
403static void __exit fmi_cleanup_module(void)
404{ 386{
405 video_unregister_device(&fmi_radio); 387 struct fmi *fmi = &fmi_card;
406 release_region(io, 2); 388
389 video_unregister_device(&fmi->vdev);
390 v4l2_device_unregister(&fmi->v4l2_dev);
391 release_region(fmi->io, 2);
407 if (dev) 392 if (dev)
408 pnp_device_detach(dev); 393 pnp_device_detach(dev);
409} 394}
410 395
411module_init(fmi_init); 396module_init(fmi_init);
412module_exit(fmi_cleanup_module); 397module_exit(fmi_exit);
diff --git a/drivers/media/radio/radio-sf16fmr2.c b/drivers/media/radio/radio-sf16fmr2.c
index 92f17a347fa7..0ba9d88a80fc 100644
--- a/drivers/media/radio/radio-sf16fmr2.c
+++ b/drivers/media/radio/radio-sf16fmr2.c
@@ -18,40 +18,28 @@
18#include <linux/init.h> /* Initdata */ 18#include <linux/init.h> /* Initdata */
19#include <linux/ioport.h> /* request_region */ 19#include <linux/ioport.h> /* request_region */
20#include <linux/delay.h> /* udelay */ 20#include <linux/delay.h> /* udelay */
21#include <asm/io.h> /* outb, outb_p */
22#include <asm/uaccess.h> /* copy to/from user */
23#include <linux/videodev2.h> /* kernel radio structs */ 21#include <linux/videodev2.h> /* kernel radio structs */
24#include <media/v4l2-common.h>
25#include <media/v4l2-ioctl.h>
26#include <linux/mutex.h> 22#include <linux/mutex.h>
23#include <linux/version.h> /* for KERNEL_VERSION MACRO */
24#include <linux/io.h> /* outb, outb_p */
25#include <media/v4l2-device.h>
26#include <media/v4l2-ioctl.h>
27 27
28static struct mutex lock; 28MODULE_AUTHOR("Ziglio Frediano, freddy77@angelfire.com");
29MODULE_DESCRIPTION("A driver for the SF16FMR2 radio.");
30MODULE_LICENSE("GPL");
31
32static int io = 0x384;
33static int radio_nr = -1;
34
35module_param(io, int, 0);
36MODULE_PARM_DESC(io, "I/O address of the SF16FMR2 card (should be 0x384, if do not work try 0x284)");
37module_param(radio_nr, int, 0);
29 38
30#include <linux/version.h> /* for KERNEL_VERSION MACRO */
31#define RADIO_VERSION KERNEL_VERSION(0,0,2) 39#define RADIO_VERSION KERNEL_VERSION(0,0,2)
32 40
33#define AUD_VOL_INDEX 1 41#define AUD_VOL_INDEX 1
34 42
35static struct v4l2_queryctrl radio_qctrl[] = {
36 {
37 .id = V4L2_CID_AUDIO_MUTE,
38 .name = "Mute",
39 .minimum = 0,
40 .maximum = 1,
41 .default_value = 1,
42 .type = V4L2_CTRL_TYPE_BOOLEAN,
43 },
44 [AUD_VOL_INDEX] = {
45 .id = V4L2_CID_AUDIO_VOLUME,
46 .name = "Volume",
47 .minimum = 0,
48 .maximum = 15,
49 .step = 1,
50 .default_value = 0,
51 .type = V4L2_CTRL_TYPE_INTEGER,
52 }
53};
54
55#undef DEBUG 43#undef DEBUG
56//#define DEBUG 1 44//#define DEBUG 1
57 45
@@ -62,156 +50,160 @@ static struct v4l2_queryctrl radio_qctrl[] = {
62#endif 50#endif
63 51
64/* this should be static vars for module size */ 52/* this should be static vars for module size */
65struct fmr2_device 53struct fmr2
66{ 54{
67 unsigned long in_use; 55 struct v4l2_device v4l2_dev;
68 int port; 56 struct video_device vdev;
57 struct mutex lock;
58 int io;
69 int curvol; /* 0-15 */ 59 int curvol; /* 0-15 */
70 int mute; 60 int mute;
71 int stereo; /* card is producing stereo audio */ 61 int stereo; /* card is producing stereo audio */
72 unsigned long curfreq; /* freq in kHz */ 62 unsigned long curfreq; /* freq in kHz */
73 int card_type; 63 int card_type;
74 __u32 flags; 64 u32 flags;
75}; 65};
76 66
77static int io = 0x384; 67static struct fmr2 fmr2_card;
78static int radio_nr = -1;
79 68
80/* hw precision is 12.5 kHz 69/* hw precision is 12.5 kHz
81 * It is only useful to give freq in intervall of 200 (=0.0125Mhz), 70 * It is only useful to give freq in intervall of 200 (=0.0125Mhz),
82 * other bits will be truncated 71 * other bits will be truncated
83 */ 72 */
84#define RSF16_ENCODE(x) ((x)/200+856) 73#define RSF16_ENCODE(x) ((x) / 200 + 856)
85#define RSF16_MINFREQ 87*16000 74#define RSF16_MINFREQ (87 * 16000)
86#define RSF16_MAXFREQ 108*16000 75#define RSF16_MAXFREQ (108 * 16000)
87 76
88static inline void wait(int n,int port) 77static inline void wait(int n, int io)
89{ 78{
90 for (;n;--n) inb(port); 79 for (; n; --n)
80 inb(io);
91} 81}
92 82
93static void outbits(int bits, unsigned int data, int nWait, int port) 83static void outbits(int bits, unsigned int data, int nWait, int io)
94{ 84{
95 int bit; 85 int bit;
96 for(;--bits>=0;) { 86
97 bit = (data>>bits) & 1; 87 for (; --bits >= 0;) {
98 outb(bit,port); 88 bit = (data >> bits) & 1;
99 wait(nWait,port); 89 outb(bit, io);
100 outb(bit|2,port); 90 wait(nWait, io);
101 wait(nWait,port); 91 outb(bit | 2, io);
102 outb(bit,port); 92 wait(nWait, io);
103 wait(nWait,port); 93 outb(bit, io);
94 wait(nWait, io);
104 } 95 }
105} 96}
106 97
107static inline void fmr2_mute(int port) 98static inline void fmr2_mute(int io)
108{ 99{
109 outb(0x00, port); 100 outb(0x00, io);
110 wait(4,port); 101 wait(4, io);
111} 102}
112 103
113static inline void fmr2_unmute(int port) 104static inline void fmr2_unmute(int io)
114{ 105{
115 outb(0x04, port); 106 outb(0x04, io);
116 wait(4,port); 107 wait(4, io);
117} 108}
118 109
119static inline int fmr2_stereo_mode(int port) 110static inline int fmr2_stereo_mode(int io)
120{ 111{
121 int n = inb(port); 112 int n = inb(io);
122 outb(6,port); 113
123 inb(port); 114 outb(6, io);
124 n = ((n>>3)&1)^1; 115 inb(io);
116 n = ((n >> 3) & 1) ^ 1;
125 debug_print((KERN_DEBUG "stereo: %d\n", n)); 117 debug_print((KERN_DEBUG "stereo: %d\n", n));
126 return n; 118 return n;
127} 119}
128 120
129static int fmr2_product_info(struct fmr2_device *dev) 121static int fmr2_product_info(struct fmr2 *dev)
130{ 122{
131 int n = inb(dev->port); 123 int n = inb(dev->io);
124
132 n &= 0xC1; 125 n &= 0xC1;
133 if (n == 0) 126 if (n == 0) {
134 {
135 /* this should support volume set */ 127 /* this should support volume set */
136 dev->card_type = 12; 128 dev->card_type = 12;
137 return 0; 129 return 0;
138 } 130 }
139 /* not volume (mine is 11) */ 131 /* not volume (mine is 11) */
140 dev->card_type = (n==128)?11:0; 132 dev->card_type = (n == 128) ? 11 : 0;
141 return n; 133 return n;
142} 134}
143 135
144static inline int fmr2_getsigstr(struct fmr2_device *dev) 136static inline int fmr2_getsigstr(struct fmr2 *dev)
145{ 137{
146 /* !!! work only if scanning freq */ 138 /* !!! works only if scanning freq */
147 int port = dev->port, res = 0xffff; 139 int res = 0xffff;
148 outb(5,port); 140
149 wait(4,port); 141 outb(5, dev->io);
150 if (!(inb(port)&1)) res = 0; 142 wait(4, dev->io);
143 if (!(inb(dev->io) & 1))
144 res = 0;
151 debug_print((KERN_DEBUG "signal: %d\n", res)); 145 debug_print((KERN_DEBUG "signal: %d\n", res));
152 return res; 146 return res;
153} 147}
154 148
155/* set frequency and unmute card */ 149/* set frequency and unmute card */
156static int fmr2_setfreq(struct fmr2_device *dev) 150static int fmr2_setfreq(struct fmr2 *dev)
157{ 151{
158 int port = dev->port;
159 unsigned long freq = dev->curfreq; 152 unsigned long freq = dev->curfreq;
160 153
161 fmr2_mute(port); 154 fmr2_mute(dev->io);
162 155
163 /* 0x42 for mono output 156 /* 0x42 for mono output
164 * 0x102 forward scanning 157 * 0x102 forward scanning
165 * 0x182 scansione avanti 158 * 0x182 scansione avanti
166 */ 159 */
167 outbits(9,0x2,3,port); 160 outbits(9, 0x2, 3, dev->io);
168 outbits(16,RSF16_ENCODE(freq),2,port); 161 outbits(16, RSF16_ENCODE(freq), 2, dev->io);
169 162
170 fmr2_unmute(port); 163 fmr2_unmute(dev->io);
171 164
172 /* wait 0.11 sec */ 165 /* wait 0.11 sec */
173 msleep(110); 166 msleep(110);
174 167
175 /* NOTE if mute this stop radio 168 /* NOTE if mute this stop radio
176 you must set freq on unmute */ 169 you must set freq on unmute */
177 dev->stereo = fmr2_stereo_mode(port); 170 dev->stereo = fmr2_stereo_mode(dev->io);
178 return 0; 171 return 0;
179} 172}
180 173
181/* !!! not tested, in my card this does't work !!! */ 174/* !!! not tested, in my card this does't work !!! */
182static int fmr2_setvolume(struct fmr2_device *dev) 175static int fmr2_setvolume(struct fmr2 *dev)
183{ 176{
184 int vol[16] = { 0x021, 0x084, 0x090, 0x104, 177 int vol[16] = { 0x021, 0x084, 0x090, 0x104,
185 0x110, 0x204, 0x210, 0x402, 178 0x110, 0x204, 0x210, 0x402,
186 0x404, 0x408, 0x410, 0x801, 179 0x404, 0x408, 0x410, 0x801,
187 0x802, 0x804, 0x808, 0x810 }; 180 0x802, 0x804, 0x808, 0x810 };
188 int i, a, port = dev->port; 181 int i, a;
189 int n = vol[dev->curvol & 0x0f]; 182 int n = vol[dev->curvol & 0x0f];
190 183
191 if (dev->card_type != 11) 184 if (dev->card_type != 11)
192 return 1; 185 return 1;
193 186
194 for (i = 12; --i >= 0; ) { 187 for (i = 12; --i >= 0; ) {
195 a = ((n >> i) & 1) << 6; /* if (a=0) a= 0; else a= 0x40; */ 188 a = ((n >> i) & 1) << 6; /* if (a==0) a = 0; else a = 0x40; */
196 outb(a | 4, port); 189 outb(a | 4, dev->io);
197 wait(4, port); 190 wait(4, dev->io);
198 outb(a | 0x24, port); 191 outb(a | 0x24, dev->io);
199 wait(4, port); 192 wait(4, dev->io);
200 outb(a | 4, port); 193 outb(a | 4, dev->io);
201 wait(4, port); 194 wait(4, dev->io);
202 } 195 }
203 for (i = 6; --i >= 0; ) { 196 for (i = 6; --i >= 0; ) {
204 a = ((0x18 >> i) & 1) << 6; 197 a = ((0x18 >> i) & 1) << 6;
205 outb(a | 4, port); 198 outb(a | 4, dev->io);
206 wait(4,port); 199 wait(4, dev->io);
207 outb(a | 0x24, port); 200 outb(a | 0x24, dev->io);
208 wait(4,port); 201 wait(4, dev->io);
209 outb(a|4, port); 202 outb(a | 4, dev->io);
210 wait(4,port); 203 wait(4, dev->io);
211 } 204 }
212 wait(4, port); 205 wait(4, dev->io);
213 outb(0x14, port); 206 outb(0x14, dev->io);
214
215 return 0; 207 return 0;
216} 208}
217 209
@@ -220,9 +212,9 @@ static int vidioc_querycap(struct file *file, void *priv,
220{ 212{
221 strlcpy(v->driver, "radio-sf16fmr2", sizeof(v->driver)); 213 strlcpy(v->driver, "radio-sf16fmr2", sizeof(v->driver));
222 strlcpy(v->card, "SF16-FMR2 radio", sizeof(v->card)); 214 strlcpy(v->card, "SF16-FMR2 radio", sizeof(v->card));
223 sprintf(v->bus_info, "ISA"); 215 strlcpy(v->bus_info, "ISA", sizeof(v->bus_info));
224 v->version = RADIO_VERSION; 216 v->version = RADIO_VERSION;
225 v->capabilities = V4L2_CAP_TUNER; 217 v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
226 return 0; 218 return 0;
227} 219}
228 220
@@ -230,54 +222,52 @@ static int vidioc_g_tuner(struct file *file, void *priv,
230 struct v4l2_tuner *v) 222 struct v4l2_tuner *v)
231{ 223{
232 int mult; 224 int mult;
233 struct fmr2_device *fmr2 = video_drvdata(file); 225 struct fmr2 *fmr2 = video_drvdata(file);
234 226
235 if (v->index > 0) 227 if (v->index > 0)
236 return -EINVAL; 228 return -EINVAL;
237 229
238 strcpy(v->name, "FM"); 230 strlcpy(v->name, "FM", sizeof(v->name));
239 v->type = V4L2_TUNER_RADIO; 231 v->type = V4L2_TUNER_RADIO;
240 232
241 mult = (fmr2->flags & V4L2_TUNER_CAP_LOW) ? 1 : 1000; 233 mult = (fmr2->flags & V4L2_TUNER_CAP_LOW) ? 1 : 1000;
242 v->rangelow = RSF16_MINFREQ/mult; 234 v->rangelow = RSF16_MINFREQ / mult;
243 v->rangehigh = RSF16_MAXFREQ/mult; 235 v->rangehigh = RSF16_MAXFREQ / mult;
244 v->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_MODE_STEREO; 236 v->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_MODE_STEREO;
245 v->capability = fmr2->flags&V4L2_TUNER_CAP_LOW; 237 v->capability = fmr2->flags&V4L2_TUNER_CAP_LOW;
246 v->audmode = fmr2->stereo ? V4L2_TUNER_MODE_STEREO: 238 v->audmode = fmr2->stereo ? V4L2_TUNER_MODE_STEREO:
247 V4L2_TUNER_MODE_MONO; 239 V4L2_TUNER_MODE_MONO;
248 mutex_lock(&lock); 240 mutex_lock(&fmr2->lock);
249 v->signal = fmr2_getsigstr(fmr2); 241 v->signal = fmr2_getsigstr(fmr2);
250 mutex_unlock(&lock); 242 mutex_unlock(&fmr2->lock);
251 return 0; 243 return 0;
252} 244}
253 245
254static int vidioc_s_tuner(struct file *file, void *priv, 246static int vidioc_s_tuner(struct file *file, void *priv,
255 struct v4l2_tuner *v) 247 struct v4l2_tuner *v)
256{ 248{
257 if (v->index > 0) 249 return v->index ? -EINVAL : 0;
258 return -EINVAL;
259 return 0;
260} 250}
261 251
262static int vidioc_s_frequency(struct file *file, void *priv, 252static int vidioc_s_frequency(struct file *file, void *priv,
263 struct v4l2_frequency *f) 253 struct v4l2_frequency *f)
264{ 254{
265 struct fmr2_device *fmr2 = video_drvdata(file); 255 struct fmr2 *fmr2 = video_drvdata(file);
266 256
267 if (!(fmr2->flags & V4L2_TUNER_CAP_LOW)) 257 if (!(fmr2->flags & V4L2_TUNER_CAP_LOW))
268 f->frequency *= 1000; 258 f->frequency *= 1000;
269 if (f->frequency < RSF16_MINFREQ || 259 if (f->frequency < RSF16_MINFREQ ||
270 f->frequency > RSF16_MAXFREQ ) 260 f->frequency > RSF16_MAXFREQ)
271 return -EINVAL; 261 return -EINVAL;
272 /*rounding in steps of 200 to match th freq 262 /* rounding in steps of 200 to match the freq
273 that will be used */ 263 that will be used */
274 fmr2->curfreq = (f->frequency/200)*200; 264 fmr2->curfreq = (f->frequency / 200) * 200;
275 265
276 /* set card freq (if not muted) */ 266 /* set card freq (if not muted) */
277 if (fmr2->curvol && !fmr2->mute) { 267 if (fmr2->curvol && !fmr2->mute) {
278 mutex_lock(&lock); 268 mutex_lock(&fmr2->lock);
279 fmr2_setfreq(fmr2); 269 fmr2_setfreq(fmr2);
280 mutex_unlock(&lock); 270 mutex_unlock(&fmr2->lock);
281 } 271 }
282 return 0; 272 return 0;
283} 273}
@@ -285,7 +275,7 @@ static int vidioc_s_frequency(struct file *file, void *priv,
285static int vidioc_g_frequency(struct file *file, void *priv, 275static int vidioc_g_frequency(struct file *file, void *priv,
286 struct v4l2_frequency *f) 276 struct v4l2_frequency *f)
287{ 277{
288 struct fmr2_device *fmr2 = video_drvdata(file); 278 struct fmr2 *fmr2 = video_drvdata(file);
289 279
290 f->type = V4L2_TUNER_RADIO; 280 f->type = V4L2_TUNER_RADIO;
291 f->frequency = fmr2->curfreq; 281 f->frequency = fmr2->curfreq;
@@ -297,13 +287,16 @@ static int vidioc_g_frequency(struct file *file, void *priv,
297static int vidioc_queryctrl(struct file *file, void *priv, 287static int vidioc_queryctrl(struct file *file, void *priv,
298 struct v4l2_queryctrl *qc) 288 struct v4l2_queryctrl *qc)
299{ 289{
300 int i; 290 struct fmr2 *fmr2 = video_drvdata(file);
301 291
302 for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) { 292 switch (qc->id) {
303 if (qc->id && qc->id == radio_qctrl[i].id) { 293 case V4L2_CID_AUDIO_MUTE:
304 memcpy(qc, &radio_qctrl[i], sizeof(*qc)); 294 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
305 return 0; 295 case V4L2_CID_AUDIO_VOLUME:
306 } 296 /* Only card_type == 11 implements volume */
297 if (fmr2->card_type == 11)
298 return v4l2_ctrl_query_fill(qc, 0, 15, 1, 0);
299 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 0);
307 } 300 }
308 return -EINVAL; 301 return -EINVAL;
309} 302}
@@ -311,7 +304,7 @@ static int vidioc_queryctrl(struct file *file, void *priv,
311static int vidioc_g_ctrl(struct file *file, void *priv, 304static int vidioc_g_ctrl(struct file *file, void *priv,
312 struct v4l2_control *ctrl) 305 struct v4l2_control *ctrl)
313{ 306{
314 struct fmr2_device *fmr2 = video_drvdata(file); 307 struct fmr2 *fmr2 = video_drvdata(file);
315 308
316 switch (ctrl->id) { 309 switch (ctrl->id) {
317 case V4L2_CID_AUDIO_MUTE: 310 case V4L2_CID_AUDIO_MUTE:
@@ -327,18 +320,14 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
327static int vidioc_s_ctrl(struct file *file, void *priv, 320static int vidioc_s_ctrl(struct file *file, void *priv,
328 struct v4l2_control *ctrl) 321 struct v4l2_control *ctrl)
329{ 322{
330 struct fmr2_device *fmr2 = video_drvdata(file); 323 struct fmr2 *fmr2 = video_drvdata(file);
331 324
332 switch (ctrl->id) { 325 switch (ctrl->id) {
333 case V4L2_CID_AUDIO_MUTE: 326 case V4L2_CID_AUDIO_MUTE:
334 fmr2->mute = ctrl->value; 327 fmr2->mute = ctrl->value;
335 break; 328 break;
336 case V4L2_CID_AUDIO_VOLUME: 329 case V4L2_CID_AUDIO_VOLUME:
337 if (ctrl->value > radio_qctrl[AUD_VOL_INDEX].maximum) 330 fmr2->curvol = ctrl->value;
338 fmr2->curvol = radio_qctrl[AUD_VOL_INDEX].maximum;
339 else
340 fmr2->curvol = ctrl->value;
341
342 break; 331 break;
343 default: 332 default:
344 return -EINVAL; 333 return -EINVAL;
@@ -351,25 +340,14 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
351 printk(KERN_DEBUG "mute\n"); 340 printk(KERN_DEBUG "mute\n");
352#endif 341#endif
353 342
354 mutex_lock(&lock); 343 mutex_lock(&fmr2->lock);
355 if (fmr2->curvol && !fmr2->mute) { 344 if (fmr2->curvol && !fmr2->mute) {
356 fmr2_setvolume(fmr2); 345 fmr2_setvolume(fmr2);
357 /* Set frequency and unmute card */ 346 /* Set frequency and unmute card */
358 fmr2_setfreq(fmr2); 347 fmr2_setfreq(fmr2);
359 } else 348 } else
360 fmr2_mute(fmr2->port); 349 fmr2_mute(fmr2->io);
361 mutex_unlock(&lock); 350 mutex_unlock(&fmr2->lock);
362 return 0;
363}
364
365static int vidioc_g_audio(struct file *file, void *priv,
366 struct v4l2_audio *a)
367{
368 if (a->index > 1)
369 return -EINVAL;
370
371 strcpy(a->name, "Radio");
372 a->capability = V4L2_AUDCAP_STEREO;
373 return 0; 351 return 0;
374} 352}
375 353
@@ -381,36 +359,38 @@ static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
381 359
382static int vidioc_s_input(struct file *filp, void *priv, unsigned int i) 360static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
383{ 361{
384 if (i != 0) 362 return i ? -EINVAL : 0;
385 return -EINVAL;
386 return 0;
387} 363}
388 364
389static int vidioc_s_audio(struct file *file, void *priv, 365static int vidioc_g_audio(struct file *file, void *priv,
390 struct v4l2_audio *a) 366 struct v4l2_audio *a)
391{ 367{
392 if (a->index != 0) 368 a->index = 0;
393 return -EINVAL; 369 strlcpy(a->name, "Radio", sizeof(a->name));
370 a->capability = V4L2_AUDCAP_STEREO;
394 return 0; 371 return 0;
395} 372}
396 373
397static struct fmr2_device fmr2_unit; 374static int vidioc_s_audio(struct file *file, void *priv,
375 struct v4l2_audio *a)
376{
377 return a->index ? -EINVAL : 0;
378}
398 379
399static int fmr2_exclusive_open(struct file *file) 380static int fmr2_open(struct file *file)
400{ 381{
401 return test_and_set_bit(0, &fmr2_unit.in_use) ? -EBUSY : 0; 382 return 0;
402} 383}
403 384
404static int fmr2_exclusive_release(struct file *file) 385static int fmr2_release(struct file *file)
405{ 386{
406 clear_bit(0, &fmr2_unit.in_use);
407 return 0; 387 return 0;
408} 388}
409 389
410static const struct v4l2_file_operations fmr2_fops = { 390static const struct v4l2_file_operations fmr2_fops = {
411 .owner = THIS_MODULE, 391 .owner = THIS_MODULE,
412 .open = fmr2_exclusive_open, 392 .open = fmr2_open,
413 .release = fmr2_exclusive_release, 393 .release = fmr2_release,
414 .ioctl = video_ioctl2, 394 .ioctl = video_ioctl2,
415}; 395};
416 396
@@ -429,67 +409,64 @@ static const struct v4l2_ioctl_ops fmr2_ioctl_ops = {
429 .vidioc_s_ctrl = vidioc_s_ctrl, 409 .vidioc_s_ctrl = vidioc_s_ctrl,
430}; 410};
431 411
432static struct video_device fmr2_radio = {
433 .name = "SF16FMR2 radio",
434 .fops = &fmr2_fops,
435 .ioctl_ops = &fmr2_ioctl_ops,
436 .release = video_device_release_empty,
437};
438
439static int __init fmr2_init(void) 412static int __init fmr2_init(void)
440{ 413{
441 fmr2_unit.port = io; 414 struct fmr2 *fmr2 = &fmr2_card;
442 fmr2_unit.curvol = 0; 415 struct v4l2_device *v4l2_dev = &fmr2->v4l2_dev;
443 fmr2_unit.mute = 0; 416 int res;
444 fmr2_unit.curfreq = 0; 417
445 fmr2_unit.stereo = 1; 418 strlcpy(v4l2_dev->name, "sf16fmr2", sizeof(v4l2_dev->name));
446 fmr2_unit.flags = V4L2_TUNER_CAP_LOW; 419 fmr2->io = io;
447 fmr2_unit.card_type = 0; 420 fmr2->stereo = 1;
448 video_set_drvdata(&fmr2_radio, &fmr2_unit); 421 fmr2->flags = V4L2_TUNER_CAP_LOW;
449 422 mutex_init(&fmr2->lock);
450 mutex_init(&lock); 423
451 424 if (!request_region(fmr2->io, 2, "sf16fmr2")) {
452 if (!request_region(io, 2, "sf16fmr2")) { 425 v4l2_err(v4l2_dev, "request_region failed!\n");
453 printk(KERN_ERR "radio-sf16fmr2: request_region failed!\n");
454 return -EBUSY; 426 return -EBUSY;
455 } 427 }
456 428
457 if (video_register_device(&fmr2_radio, VFL_TYPE_RADIO, radio_nr) < 0) { 429 res = v4l2_device_register(NULL, v4l2_dev);
458 release_region(io, 2); 430 if (res < 0) {
459 return -EINVAL; 431 release_region(fmr2->io, 2);
432 v4l2_err(v4l2_dev, "Could not register v4l2_device\n");
433 return res;
460 } 434 }
461 435
462 printk(KERN_INFO "SF16FMR2 radio card driver at 0x%x.\n", io); 436 strlcpy(fmr2->vdev.name, v4l2_dev->name, sizeof(fmr2->vdev.name));
463 /* mute card - prevents noisy bootups */ 437 fmr2->vdev.v4l2_dev = v4l2_dev;
464 mutex_lock(&lock); 438 fmr2->vdev.fops = &fmr2_fops;
465 fmr2_mute(io); 439 fmr2->vdev.ioctl_ops = &fmr2_ioctl_ops;
466 fmr2_product_info(&fmr2_unit); 440 fmr2->vdev.release = video_device_release_empty;
467 mutex_unlock(&lock); 441 video_set_drvdata(&fmr2->vdev, fmr2);
468 debug_print((KERN_DEBUG "card_type %d\n", fmr2_unit.card_type));
469 442
470 /* Only card_type == 11 implements volume */ 443 if (video_register_device(&fmr2->vdev, VFL_TYPE_RADIO, radio_nr) < 0) {
471 if (fmr2_unit.card_type != 11) 444 v4l2_device_unregister(v4l2_dev);
472 radio_qctrl[AUD_VOL_INDEX].maximum = 1; 445 release_region(fmr2->io, 2);
446 return -EINVAL;
447 }
473 448
449 v4l2_info(v4l2_dev, "SF16FMR2 radio card driver at 0x%x.\n", fmr2->io);
450 /* mute card - prevents noisy bootups */
451 mutex_lock(&fmr2->lock);
452 fmr2_mute(fmr2->io);
453 fmr2_product_info(fmr2);
454 mutex_unlock(&fmr2->lock);
455 debug_print((KERN_DEBUG "card_type %d\n", fmr2->card_type));
474 return 0; 456 return 0;
475} 457}
476 458
477MODULE_AUTHOR("Ziglio Frediano, freddy77@angelfire.com"); 459static void __exit fmr2_exit(void)
478MODULE_DESCRIPTION("A driver for the SF16FMR2 radio.");
479MODULE_LICENSE("GPL");
480
481module_param(io, int, 0);
482MODULE_PARM_DESC(io, "I/O address of the SF16FMR2 card (should be 0x384, if do not work try 0x284)");
483module_param(radio_nr, int, 0);
484
485static void __exit fmr2_cleanup_module(void)
486{ 460{
487 video_unregister_device(&fmr2_radio); 461 struct fmr2 *fmr2 = &fmr2_card;
488 release_region(io,2); 462
463 video_unregister_device(&fmr2->vdev);
464 v4l2_device_unregister(&fmr2->v4l2_dev);
465 release_region(fmr2->io, 2);
489} 466}
490 467
491module_init(fmr2_init); 468module_init(fmr2_init);
492module_exit(fmr2_cleanup_module); 469module_exit(fmr2_exit);
493 470
494#ifndef MODULE 471#ifndef MODULE
495 472
diff --git a/drivers/media/radio/radio-si470x.c b/drivers/media/radio/radio-si470x.c
index 4dfed6aa2dbc..713e242ba8b2 100644
--- a/drivers/media/radio/radio-si470x.c
+++ b/drivers/media/radio/radio-si470x.c
@@ -5,8 +5,9 @@
5 * - Silicon Labs USB FM Radio Reference Design 5 * - Silicon Labs USB FM Radio Reference Design
6 * - ADS/Tech FM Radio Receiver (formerly Instant FM Music) (RDX-155-EF) 6 * - ADS/Tech FM Radio Receiver (formerly Instant FM Music) (RDX-155-EF)
7 * - KWorld USB FM Radio SnapMusic Mobile 700 (FM700) 7 * - KWorld USB FM Radio SnapMusic Mobile 700 (FM700)
8 * - Sanei Electric, Inc. FM USB Radio (sold as DealExtreme.com PCear)
8 * 9 *
9 * Copyright (c) 2008 Tobias Lorenz <tobias.lorenz@gmx.net> 10 * Copyright (c) 2009 Tobias Lorenz <tobias.lorenz@gmx.net>
10 * 11 *
11 * This program is free software; you can redistribute it and/or modify 12 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by 13 * it under the terms of the GNU General Public License as published by
@@ -29,7 +30,7 @@
29 * 2008-01-12 Tobias Lorenz <tobias.lorenz@gmx.net> 30 * 2008-01-12 Tobias Lorenz <tobias.lorenz@gmx.net>
30 * Version 1.0.0 31 * Version 1.0.0
31 * - First working version 32 * - First working version
32 * 2008-01-13 Tobias Lorenz <tobias.lorenz@gmx.net> 33 * 2008-01-13 Tobias Lorenz <tobias.lorenz@gmx.net>
33 * Version 1.0.1 34 * Version 1.0.1
34 * - Improved error handling, every function now returns errno 35 * - Improved error handling, every function now returns errno
35 * - Improved multi user access (start/mute/stop) 36 * - Improved multi user access (start/mute/stop)
@@ -104,6 +105,7 @@
104 * 2009-01-31 Rick Bronson <rick@efn.org> 105 * 2009-01-31 Rick Bronson <rick@efn.org>
105 * Tobias Lorenz <tobias.lorenz@gmx.net> 106 * Tobias Lorenz <tobias.lorenz@gmx.net>
106 * - add LED status output 107 * - add LED status output
108 * - get HW/SW version from scratchpad
107 * 109 *
108 * ToDo: 110 * ToDo:
109 * - add firmware download/update support 111 * - add firmware download/update support
@@ -114,10 +116,10 @@
114/* driver definitions */ 116/* driver definitions */
115#define DRIVER_AUTHOR "Tobias Lorenz <tobias.lorenz@gmx.net>" 117#define DRIVER_AUTHOR "Tobias Lorenz <tobias.lorenz@gmx.net>"
116#define DRIVER_NAME "radio-si470x" 118#define DRIVER_NAME "radio-si470x"
117#define DRIVER_KERNEL_VERSION KERNEL_VERSION(1, 0, 8) 119#define DRIVER_KERNEL_VERSION KERNEL_VERSION(1, 0, 9)
118#define DRIVER_CARD "Silicon Labs Si470x FM Radio Receiver" 120#define DRIVER_CARD "Silicon Labs Si470x FM Radio Receiver"
119#define DRIVER_DESC "USB radio driver for Si470x FM Radio Receivers" 121#define DRIVER_DESC "USB radio driver for Si470x FM Radio Receivers"
120#define DRIVER_VERSION "1.0.8" 122#define DRIVER_VERSION "1.0.9"
121 123
122 124
123/* kernel includes */ 125/* kernel includes */
@@ -145,7 +147,7 @@ static struct usb_device_id si470x_usb_driver_id_table[] = {
145 { USB_DEVICE_AND_INTERFACE_INFO(0x06e1, 0xa155, USB_CLASS_HID, 0, 0) }, 147 { USB_DEVICE_AND_INTERFACE_INFO(0x06e1, 0xa155, USB_CLASS_HID, 0, 0) },
146 /* KWorld USB FM Radio SnapMusic Mobile 700 (FM700) */ 148 /* KWorld USB FM Radio SnapMusic Mobile 700 (FM700) */
147 { USB_DEVICE_AND_INTERFACE_INFO(0x1b80, 0xd700, USB_CLASS_HID, 0, 0) }, 149 { USB_DEVICE_AND_INTERFACE_INFO(0x1b80, 0xd700, USB_CLASS_HID, 0, 0) },
148 /* DealExtreme USB Radio */ 150 /* Sanei Electric, Inc. FM USB Radio (sold as DealExtreme.com PCear) */
149 { USB_DEVICE_AND_INTERFACE_INFO(0x10c5, 0x819a, USB_CLASS_HID, 0, 0) }, 151 { USB_DEVICE_AND_INTERFACE_INFO(0x10c5, 0x819a, USB_CLASS_HID, 0, 0) },
150 /* Terminating entry */ 152 /* Terminating entry */
151 { } 153 { }
@@ -345,7 +347,7 @@ MODULE_PARM_DESC(rds_poll_time, "RDS poll time (ms): *40*");
345 347
346/* Report 19: stream */ 348/* Report 19: stream */
347#define STREAM_REPORT_SIZE 3 349#define STREAM_REPORT_SIZE 3
348#define STREAM_REPORT 19 350#define STREAM_REPORT 19
349 351
350/* Report 20: scratch */ 352/* Report 20: scratch */
351#define SCRATCH_PAGE_SIZE 63 353#define SCRATCH_PAGE_SIZE 63
@@ -353,9 +355,13 @@ MODULE_PARM_DESC(rds_poll_time, "RDS poll time (ms): *40*");
353#define SCRATCH_REPORT 20 355#define SCRATCH_REPORT 20
354 356
355/* Reports 19-22: flash upgrade of the C8051F321 */ 357/* Reports 19-22: flash upgrade of the C8051F321 */
358#define WRITE_REPORT_SIZE 4
356#define WRITE_REPORT 19 359#define WRITE_REPORT 19
360#define FLASH_REPORT_SIZE 64
357#define FLASH_REPORT 20 361#define FLASH_REPORT 20
362#define CRC_REPORT_SIZE 3
358#define CRC_REPORT 21 363#define CRC_REPORT 21
364#define RESPONSE_REPORT_SIZE 2
359#define RESPONSE_REPORT 22 365#define RESPONSE_REPORT 22
360 366
361/* Report 23: currently unused, but can accept 60 byte reports on the HID */ 367/* Report 23: currently unused, but can accept 60 byte reports on the HID */
@@ -414,7 +420,7 @@ MODULE_PARM_DESC(rds_poll_time, "RDS poll time (ms): *40*");
414 420
415/* bootloader commands */ 421/* bootloader commands */
416#define GET_SW_VERSION_COMMAND 0x00 422#define GET_SW_VERSION_COMMAND 0x00
417#define SET_PAGE_COMMAND 0x01 423#define SET_PAGE_COMMAND 0x01
418#define ERASE_PAGE_COMMAND 0x02 424#define ERASE_PAGE_COMMAND 0x02
419#define WRITE_PAGE_COMMAND 0x03 425#define WRITE_PAGE_COMMAND 0x03
420#define CRC_ON_PAGE_COMMAND 0x04 426#define CRC_ON_PAGE_COMMAND 0x04
@@ -428,12 +434,6 @@ MODULE_PARM_DESC(rds_poll_time, "RDS poll time (ms): *40*");
428#define COMMAND_FAILED 0x02 434#define COMMAND_FAILED 0x02
429#define COMMAND_PENDING 0x03 435#define COMMAND_PENDING 0x03
430 436
431/* buffer sizes */
432#define COMMAND_BUFFER_SIZE 4
433#define RESPONSE_BUFFER_SIZE 2
434#define FLASH_BUFFER_SIZE 64
435#define CRC_BUFFER_SIZE 3
436
437 437
438 438
439/************************************************************************** 439/**************************************************************************
@@ -465,6 +465,10 @@ struct si470x_device {
465 unsigned int buf_size; 465 unsigned int buf_size;
466 unsigned int rd_index; 466 unsigned int rd_index;
467 unsigned int wr_index; 467 unsigned int wr_index;
468
469 /* scratch page */
470 unsigned char software_version;
471 unsigned char hardware_version;
468}; 472};
469 473
470 474
@@ -480,7 +484,7 @@ struct si470x_device {
480 484
481 485
482/************************************************************************** 486/**************************************************************************
483 * General Driver Functions 487 * General Driver Functions - REGISTER_REPORTs
484 **************************************************************************/ 488 **************************************************************************/
485 489
486/* 490/*
@@ -566,60 +570,6 @@ static int si470x_set_register(struct si470x_device *radio, int regnr)
566 570
567 571
568/* 572/*
569 * si470x_get_all_registers - read entire registers
570 */
571static int si470x_get_all_registers(struct si470x_device *radio)
572{
573 unsigned char buf[ENTIRE_REPORT_SIZE];
574 int retval;
575 unsigned char regnr;
576
577 buf[0] = ENTIRE_REPORT;
578
579 retval = si470x_get_report(radio, (void *) &buf, sizeof(buf));
580
581 if (retval >= 0)
582 for (regnr = 0; regnr < RADIO_REGISTER_NUM; regnr++)
583 radio->registers[regnr] = get_unaligned_be16(
584 &buf[regnr * RADIO_REGISTER_SIZE + 1]);
585
586 return (retval < 0) ? -EINVAL : 0;
587}
588
589
590/*
591 * si470x_get_rds_registers - read rds registers
592 */
593static int si470x_get_rds_registers(struct si470x_device *radio)
594{
595 unsigned char buf[RDS_REPORT_SIZE];
596 int retval;
597 int size;
598 unsigned char regnr;
599
600 buf[0] = RDS_REPORT;
601
602 retval = usb_interrupt_msg(radio->usbdev,
603 usb_rcvintpipe(radio->usbdev, 1),
604 (void *) &buf, sizeof(buf), &size, usb_timeout);
605 if (size != sizeof(buf))
606 printk(KERN_WARNING DRIVER_NAME ": si470x_get_rds_registers: "
607 "return size differs: %d != %zu\n", size, sizeof(buf));
608 if (retval < 0)
609 printk(KERN_WARNING DRIVER_NAME ": si470x_get_rds_registers: "
610 "usb_interrupt_msg returned %d\n", retval);
611
612 if (retval >= 0)
613 for (regnr = 0; regnr < RDS_REGISTER_NUM; regnr++)
614 radio->registers[STATUSRSSI + regnr] =
615 get_unaligned_be16(
616 &buf[regnr * RADIO_REGISTER_SIZE + 1]);
617
618 return (retval < 0) ? -EINVAL : 0;
619}
620
621
622/*
623 * si470x_set_chan - set the channel 573 * si470x_set_chan - set the channel
624 */ 574 */
625static int si470x_set_chan(struct si470x_device *radio, unsigned short chan) 575static int si470x_set_chan(struct si470x_device *radio, unsigned short chan)
@@ -887,6 +837,70 @@ static int si470x_rds_on(struct si470x_device *radio)
887 837
888 838
889/************************************************************************** 839/**************************************************************************
840 * General Driver Functions - ENTIRE_REPORT
841 **************************************************************************/
842
843/*
844 * si470x_get_all_registers - read entire registers
845 */
846static int si470x_get_all_registers(struct si470x_device *radio)
847{
848 unsigned char buf[ENTIRE_REPORT_SIZE];
849 int retval;
850 unsigned char regnr;
851
852 buf[0] = ENTIRE_REPORT;
853
854 retval = si470x_get_report(radio, (void *) &buf, sizeof(buf));
855
856 if (retval >= 0)
857 for (regnr = 0; regnr < RADIO_REGISTER_NUM; regnr++)
858 radio->registers[regnr] = get_unaligned_be16(
859 &buf[regnr * RADIO_REGISTER_SIZE + 1]);
860
861 return (retval < 0) ? -EINVAL : 0;
862}
863
864
865
866/**************************************************************************
867 * General Driver Functions - RDS_REPORT
868 **************************************************************************/
869
870/*
871 * si470x_get_rds_registers - read rds registers
872 */
873static int si470x_get_rds_registers(struct si470x_device *radio)
874{
875 unsigned char buf[RDS_REPORT_SIZE];
876 int retval;
877 int size;
878 unsigned char regnr;
879
880 buf[0] = RDS_REPORT;
881
882 retval = usb_interrupt_msg(radio->usbdev,
883 usb_rcvintpipe(radio->usbdev, 1),
884 (void *) &buf, sizeof(buf), &size, usb_timeout);
885 if (size != sizeof(buf))
886 printk(KERN_WARNING DRIVER_NAME ": si470x_get_rds_registers: "
887 "return size differs: %d != %zu\n", size, sizeof(buf));
888 if (retval < 0)
889 printk(KERN_WARNING DRIVER_NAME ": si470x_get_rds_registers: "
890 "usb_interrupt_msg returned %d\n", retval);
891
892 if (retval >= 0)
893 for (regnr = 0; regnr < RDS_REGISTER_NUM; regnr++)
894 radio->registers[STATUSRSSI + regnr] =
895 get_unaligned_be16(
896 &buf[regnr * RADIO_REGISTER_SIZE + 1]);
897
898 return (retval < 0) ? -EINVAL : 0;
899}
900
901
902
903/**************************************************************************
890 * General Driver Functions - LED_REPORT 904 * General Driver Functions - LED_REPORT
891 **************************************************************************/ 905 **************************************************************************/
892 906
@@ -911,6 +925,35 @@ static int si470x_set_led_state(struct si470x_device *radio,
911 925
912 926
913/************************************************************************** 927/**************************************************************************
928 * General Driver Functions - SCRATCH_REPORT
929 **************************************************************************/
930
931/*
932 * si470x_get_scratch_versions - gets the scratch page and version infos
933 */
934static int si470x_get_scratch_page_versions(struct si470x_device *radio)
935{
936 unsigned char buf[SCRATCH_REPORT_SIZE];
937 int retval;
938
939 buf[0] = SCRATCH_REPORT;
940
941 retval = si470x_get_report(radio, (void *) &buf, sizeof(buf));
942
943 if (retval < 0)
944 printk(KERN_WARNING DRIVER_NAME ": si470x_get_scratch: "
945 "si470x_get_report returned %d\n", retval);
946 else {
947 radio->software_version = buf[1];
948 radio->hardware_version = buf[2];
949 }
950
951 return (retval < 0) ? -EINVAL : 0;
952}
953
954
955
956/**************************************************************************
914 * RDS Driver Functions 957 * RDS Driver Functions
915 **************************************************************************/ 958 **************************************************************************/
916 959
@@ -1124,6 +1167,7 @@ static int si470x_fops_open(struct file *file)
1124 } 1167 }
1125 1168
1126 if (radio->users == 1) { 1169 if (radio->users == 1) {
1170 /* start radio */
1127 retval = si470x_start(radio); 1171 retval = si470x_start(radio);
1128 if (retval < 0) 1172 if (retval < 0)
1129 usb_autopm_put_interface(radio->intf); 1173 usb_autopm_put_interface(radio->intf);
@@ -1165,6 +1209,7 @@ static int si470x_fops_release(struct file *file)
1165 /* cancel read processes */ 1209 /* cancel read processes */
1166 wake_up_interruptible(&radio->read_queue); 1210 wake_up_interruptible(&radio->read_queue);
1167 1211
1212 /* stop radio */
1168 retval = si470x_stop(radio); 1213 retval = si470x_stop(radio);
1169 usb_autopm_put_interface(radio->intf); 1214 usb_autopm_put_interface(radio->intf);
1170 } 1215 }
@@ -1226,9 +1271,11 @@ static struct v4l2_queryctrl si470x_v4l2_queryctrl[] = {
1226static int si470x_vidioc_querycap(struct file *file, void *priv, 1271static int si470x_vidioc_querycap(struct file *file, void *priv,
1227 struct v4l2_capability *capability) 1272 struct v4l2_capability *capability)
1228{ 1273{
1274 struct si470x_device *radio = video_drvdata(file);
1275
1229 strlcpy(capability->driver, DRIVER_NAME, sizeof(capability->driver)); 1276 strlcpy(capability->driver, DRIVER_NAME, sizeof(capability->driver));
1230 strlcpy(capability->card, DRIVER_CARD, sizeof(capability->card)); 1277 strlcpy(capability->card, DRIVER_CARD, sizeof(capability->card));
1231 sprintf(capability->bus_info, "USB"); 1278 usb_make_path(radio->usbdev, capability->bus_info, sizeof(capability->bus_info));
1232 capability->version = DRIVER_KERNEL_VERSION; 1279 capability->version = DRIVER_KERNEL_VERSION;
1233 capability->capabilities = V4L2_CAP_HW_FREQ_SEEK | 1280 capability->capabilities = V4L2_CAP_HW_FREQ_SEEK |
1234 V4L2_CAP_TUNER | V4L2_CAP_RADIO; 1281 V4L2_CAP_TUNER | V4L2_CAP_RADIO;
@@ -1636,7 +1683,7 @@ static int si470x_usb_driver_probe(struct usb_interface *intf,
1636 sizeof(si470x_viddev_template)); 1683 sizeof(si470x_viddev_template));
1637 video_set_drvdata(radio->videodev, radio); 1684 video_set_drvdata(radio->videodev, radio);
1638 1685
1639 /* show some infos about the specific device */ 1686 /* show some infos about the specific si470x device */
1640 if (si470x_get_all_registers(radio) < 0) { 1687 if (si470x_get_all_registers(radio) < 0) {
1641 retval = -EIO; 1688 retval = -EIO;
1642 goto err_all; 1689 goto err_all;
@@ -1644,7 +1691,16 @@ static int si470x_usb_driver_probe(struct usb_interface *intf,
1644 printk(KERN_INFO DRIVER_NAME ": DeviceID=0x%4.4hx ChipID=0x%4.4hx\n", 1691 printk(KERN_INFO DRIVER_NAME ": DeviceID=0x%4.4hx ChipID=0x%4.4hx\n",
1645 radio->registers[DEVICEID], radio->registers[CHIPID]); 1692 radio->registers[DEVICEID], radio->registers[CHIPID]);
1646 1693
1647 /* check if firmware is current */ 1694 /* get software and hardware versions */
1695 if (si470x_get_scratch_page_versions(radio) < 0) {
1696 retval = -EIO;
1697 goto err_all;
1698 }
1699 printk(KERN_INFO DRIVER_NAME
1700 ": software version %d, hardware version %d\n",
1701 radio->software_version, radio->hardware_version);
1702
1703 /* check if device and firmware is current */
1648 if ((radio->registers[CHIPID] & CHIPID_FIRMWARE) 1704 if ((radio->registers[CHIPID] & CHIPID_FIRMWARE)
1649 < RADIO_SW_VERSION_CURRENT) { 1705 < RADIO_SW_VERSION_CURRENT) {
1650 printk(KERN_WARNING DRIVER_NAME 1706 printk(KERN_WARNING DRIVER_NAME
@@ -1657,7 +1713,7 @@ static int si470x_usb_driver_probe(struct usb_interface *intf,
1657 ": If you have some trouble using this driver,\n"); 1713 ": If you have some trouble using this driver,\n");
1658 printk(KERN_WARNING DRIVER_NAME 1714 printk(KERN_WARNING DRIVER_NAME
1659 ": please report to V4L ML at " 1715 ": please report to V4L ML at "
1660 "video4linux-list@redhat.com\n"); 1716 "linux-media@vger.kernel.org\n");
1661 } 1717 }
1662 1718
1663 /* set initial frequency */ 1719 /* set initial frequency */
diff --git a/drivers/media/radio/radio-terratec.c b/drivers/media/radio/radio-terratec.c
index 0798d71abd00..5b007f5c74b2 100644
--- a/drivers/media/radio/radio-terratec.c
+++ b/drivers/media/radio/radio-terratec.c
@@ -27,16 +27,29 @@
27#include <linux/module.h> /* Modules */ 27#include <linux/module.h> /* Modules */
28#include <linux/init.h> /* Initdata */ 28#include <linux/init.h> /* Initdata */
29#include <linux/ioport.h> /* request_region */ 29#include <linux/ioport.h> /* request_region */
30#include <linux/delay.h> /* udelay */
31#include <asm/io.h> /* outb, outb_p */
32#include <asm/uaccess.h> /* copy to/from user */
33#include <linux/videodev2.h> /* kernel radio structs */ 30#include <linux/videodev2.h> /* kernel radio structs */
34#include <media/v4l2-common.h> 31#include <linux/mutex.h>
32#include <linux/version.h> /* for KERNEL_VERSION MACRO */
33#include <linux/io.h> /* outb, outb_p */
34#include <media/v4l2-device.h>
35#include <media/v4l2-ioctl.h> 35#include <media/v4l2-ioctl.h>
36#include <linux/spinlock.h>
37 36
38#include <linux/version.h> /* for KERNEL_VERSION MACRO */ 37MODULE_AUTHOR("R.OFFERMANNS & others");
39#define RADIO_VERSION KERNEL_VERSION(0,0,2) 38MODULE_DESCRIPTION("A driver for the TerraTec ActiveRadio Standalone radio card.");
39MODULE_LICENSE("GPL");
40
41#ifndef CONFIG_RADIO_TERRATEC_PORT
42#define CONFIG_RADIO_TERRATEC_PORT 0x590
43#endif
44
45static int io = CONFIG_RADIO_TERRATEC_PORT;
46static int radio_nr = -1;
47
48module_param(io, int, 0);
49MODULE_PARM_DESC(io, "I/O address of the TerraTec ActiveRadio card (0x590 or 0x591)");
50module_param(radio_nr, int, 0);
51
52#define RADIO_VERSION KERNEL_VERSION(0, 0, 2)
40 53
41static struct v4l2_queryctrl radio_qctrl[] = { 54static struct v4l2_queryctrl radio_qctrl[] = {
42 { 55 {
@@ -57,13 +70,6 @@ static struct v4l2_queryctrl radio_qctrl[] = {
57 } 70 }
58}; 71};
59 72
60#ifndef CONFIG_RADIO_TERRATEC_PORT
61#define CONFIG_RADIO_TERRATEC_PORT 0x590
62#endif
63
64/**************** this ones are for the terratec *******************/
65#define BASEPORT 0x590
66#define VOLPORT 0x591
67#define WRT_DIS 0x00 73#define WRT_DIS 0x00
68#define CLK_OFF 0x00 74#define CLK_OFF 0x00
69#define IIC_DATA 0x01 75#define IIC_DATA 0x01
@@ -71,138 +77,124 @@ static struct v4l2_queryctrl radio_qctrl[] = {
71#define DATA 0x04 77#define DATA 0x04
72#define CLK_ON 0x08 78#define CLK_ON 0x08
73#define WRT_EN 0x10 79#define WRT_EN 0x10
74/*******************************************************************/
75 80
76static int io = CONFIG_RADIO_TERRATEC_PORT; 81struct terratec
77static int radio_nr = -1;
78static spinlock_t lock;
79
80struct tt_device
81{ 82{
82 unsigned long in_use; 83 struct v4l2_device v4l2_dev;
83 int port; 84 struct video_device vdev;
85 int io;
84 int curvol; 86 int curvol;
85 unsigned long curfreq; 87 unsigned long curfreq;
86 int muted; 88 int muted;
89 struct mutex lock;
87}; 90};
88 91
92static struct terratec terratec_card;
89 93
90/* local things */ 94/* local things */
91 95
92static void cardWriteVol(int volume) 96static void tt_write_vol(struct terratec *tt, int volume)
93{ 97{
94 int i; 98 int i;
95 volume = volume+(volume * 32); // change both channels 99
96 spin_lock(&lock); 100 volume = volume + (volume * 32); /* change both channels */
97 for (i=0;i<8;i++) 101 mutex_lock(&tt->lock);
98 { 102 for (i = 0; i < 8; i++) {
99 if (volume & (0x80>>i)) 103 if (volume & (0x80 >> i))
100 outb(0x80, VOLPORT); 104 outb(0x80, tt->io + 1);
101 else outb(0x00, VOLPORT); 105 else
106 outb(0x00, tt->io + 1);
102 } 107 }
103 spin_unlock(&lock); 108 mutex_unlock(&tt->lock);
104} 109}
105 110
106 111
107 112
108static void tt_mute(struct tt_device *dev) 113static void tt_mute(struct terratec *tt)
109{ 114{
110 dev->muted = 1; 115 tt->muted = 1;
111 cardWriteVol(0); 116 tt_write_vol(tt, 0);
112} 117}
113 118
114static int tt_setvol(struct tt_device *dev, int vol) 119static int tt_setvol(struct terratec *tt, int vol)
115{ 120{
116 121 if (vol == tt->curvol) { /* requested volume = current */
117// printk(KERN_ERR "setvol called, vol = %d\n", vol); 122 if (tt->muted) { /* user is unmuting the card */
118 123 tt->muted = 0;
119 if(vol == dev->curvol) { /* requested volume = current */ 124 tt_write_vol(tt, vol); /* enable card */
120 if (dev->muted) { /* user is unmuting the card */
121 dev->muted = 0;
122 cardWriteVol(vol); /* enable card */
123 } 125 }
124
125 return 0; 126 return 0;
126 } 127 }
127 128
128 if(vol == 0) { /* volume = 0 means mute the card */ 129 if (vol == 0) { /* volume = 0 means mute the card */
129 cardWriteVol(0); /* "turn off card" by setting vol to 0 */ 130 tt_write_vol(tt, 0); /* "turn off card" by setting vol to 0 */
130 dev->curvol = vol; /* track the volume state! */ 131 tt->curvol = vol; /* track the volume state! */
131 return 0; 132 return 0;
132 } 133 }
133 134
134 dev->muted = 0; 135 tt->muted = 0;
135 136 tt_write_vol(tt, vol);
136 cardWriteVol(vol); 137 tt->curvol = vol;
137
138 dev->curvol = vol;
139
140 return 0; 138 return 0;
141
142} 139}
143 140
144 141
145/* this is the worst part in this driver */ 142/* this is the worst part in this driver */
146/* many more or less strange things are going on here, but hey, it works :) */ 143/* many more or less strange things are going on here, but hey, it works :) */
147 144
148static int tt_setfreq(struct tt_device *dev, unsigned long freq1) 145static int tt_setfreq(struct terratec *tt, unsigned long freq1)
149{ 146{
150 int freq; 147 int freq;
151 int i; 148 int i;
152 int p; 149 int p;
153 int temp; 150 int temp;
154 long rest; 151 long rest;
155
156 unsigned char buffer[25]; /* we have to bit shift 25 registers */ 152 unsigned char buffer[25]; /* we have to bit shift 25 registers */
157 freq = freq1/160; /* convert the freq. to a nice to handle value */
158 for(i=24;i>-1;i--)
159 buffer[i]=0;
160 153
161 rest = freq*10+10700; /* i once had understood what is going on here */ 154 mutex_lock(&tt->lock);
155
156 tt->curfreq = freq1;
157
158 freq = freq1 / 160; /* convert the freq. to a nice to handle value */
159 memset(buffer, 0, sizeof(buffer));
160
161 rest = freq * 10 + 10700; /* I once had understood what is going on here */
162 /* maybe some wise guy (friedhelm?) can comment this stuff */ 162 /* maybe some wise guy (friedhelm?) can comment this stuff */
163 i=13; 163 i = 13;
164 p=10; 164 p = 10;
165 temp=102400; 165 temp = 102400;
166 while (rest!=0) 166 while (rest != 0) {
167 { 167 if (rest % temp == rest)
168 if (rest%temp == rest)
169 buffer[i] = 0; 168 buffer[i] = 0;
170 else 169 else {
171 {
172 buffer[i] = 1; 170 buffer[i] = 1;
173 rest = rest-temp; 171 rest = rest - temp;
174 } 172 }
175 i--; 173 i--;
176 p--; 174 p--;
177 temp = temp/2; 175 temp = temp / 2;
178 } 176 }
179 177
180 spin_lock(&lock); 178 for (i = 24; i > -1; i--) { /* bit shift the values to the radiocard */
181 179 if (buffer[i] == 1) {
182 for (i=24;i>-1;i--) /* bit shift the values to the radiocard */ 180 outb(WRT_EN | DATA, tt->io);
183 { 181 outb(WRT_EN | DATA | CLK_ON, tt->io);
184 if (buffer[i]==1) 182 outb(WRT_EN | DATA, tt->io);
185 { 183 } else {
186 outb(WRT_EN|DATA, BASEPORT); 184 outb(WRT_EN | 0x00, tt->io);
187 outb(WRT_EN|DATA|CLK_ON , BASEPORT); 185 outb(WRT_EN | 0x00 | CLK_ON, tt->io);
188 outb(WRT_EN|DATA, BASEPORT);
189 }
190 else
191 {
192 outb(WRT_EN|0x00, BASEPORT);
193 outb(WRT_EN|0x00|CLK_ON , BASEPORT);
194 } 186 }
195 } 187 }
196 outb(0x00, BASEPORT); 188 outb(0x00, tt->io);
197 189
198 spin_unlock(&lock); 190 mutex_unlock(&tt->lock);
199 191
200 return 0; 192 return 0;
201} 193}
202 194
203static int tt_getsigstr(struct tt_device *dev) /* TODO */ 195static int tt_getsigstr(struct terratec *tt)
204{ 196{
205 if (inb(io) & 2) /* bit set = no signal present */ 197 if (inb(tt->io) & 2) /* bit set = no signal present */
206 return 0; 198 return 0;
207 return 1; /* signal present */ 199 return 1; /* signal present */
208} 200}
@@ -212,53 +204,50 @@ static int vidioc_querycap(struct file *file, void *priv,
212{ 204{
213 strlcpy(v->driver, "radio-terratec", sizeof(v->driver)); 205 strlcpy(v->driver, "radio-terratec", sizeof(v->driver));
214 strlcpy(v->card, "ActiveRadio", sizeof(v->card)); 206 strlcpy(v->card, "ActiveRadio", sizeof(v->card));
215 sprintf(v->bus_info, "ISA"); 207 strlcpy(v->bus_info, "ISA", sizeof(v->bus_info));
216 v->version = RADIO_VERSION; 208 v->version = RADIO_VERSION;
217 v->capabilities = V4L2_CAP_TUNER; 209 v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
218 return 0; 210 return 0;
219} 211}
220 212
221static int vidioc_g_tuner(struct file *file, void *priv, 213static int vidioc_g_tuner(struct file *file, void *priv,
222 struct v4l2_tuner *v) 214 struct v4l2_tuner *v)
223{ 215{
224 struct tt_device *tt = video_drvdata(file); 216 struct terratec *tt = video_drvdata(file);
225 217
226 if (v->index > 0) 218 if (v->index > 0)
227 return -EINVAL; 219 return -EINVAL;
228 220
229 strcpy(v->name, "FM"); 221 strlcpy(v->name, "FM", sizeof(v->name));
230 v->type = V4L2_TUNER_RADIO; 222 v->type = V4L2_TUNER_RADIO;
231 v->rangelow = (87*16000); 223 v->rangelow = 87 * 16000;
232 v->rangehigh = (108*16000); 224 v->rangehigh = 108 * 16000;
233 v->rxsubchans = V4L2_TUNER_SUB_MONO; 225 v->rxsubchans = V4L2_TUNER_SUB_MONO;
234 v->capability = V4L2_TUNER_CAP_LOW; 226 v->capability = V4L2_TUNER_CAP_LOW;
235 v->audmode = V4L2_TUNER_MODE_MONO; 227 v->audmode = V4L2_TUNER_MODE_MONO;
236 v->signal = 0xFFFF*tt_getsigstr(tt); 228 v->signal = 0xFFFF * tt_getsigstr(tt);
237 return 0; 229 return 0;
238} 230}
239 231
240static int vidioc_s_tuner(struct file *file, void *priv, 232static int vidioc_s_tuner(struct file *file, void *priv,
241 struct v4l2_tuner *v) 233 struct v4l2_tuner *v)
242{ 234{
243 if (v->index > 0) 235 return v->index ? -EINVAL : 0;
244 return -EINVAL;
245 return 0;
246} 236}
247 237
248static int vidioc_s_frequency(struct file *file, void *priv, 238static int vidioc_s_frequency(struct file *file, void *priv,
249 struct v4l2_frequency *f) 239 struct v4l2_frequency *f)
250{ 240{
251 struct tt_device *tt = video_drvdata(file); 241 struct terratec *tt = video_drvdata(file);
252 242
253 tt->curfreq = f->frequency; 243 tt_setfreq(tt, f->frequency);
254 tt_setfreq(tt, tt->curfreq);
255 return 0; 244 return 0;
256} 245}
257 246
258static int vidioc_g_frequency(struct file *file, void *priv, 247static int vidioc_g_frequency(struct file *file, void *priv,
259 struct v4l2_frequency *f) 248 struct v4l2_frequency *f)
260{ 249{
261 struct tt_device *tt = video_drvdata(file); 250 struct terratec *tt = video_drvdata(file);
262 251
263 f->type = V4L2_TUNER_RADIO; 252 f->type = V4L2_TUNER_RADIO;
264 f->frequency = tt->curfreq; 253 f->frequency = tt->curfreq;
@@ -272,8 +261,7 @@ static int vidioc_queryctrl(struct file *file, void *priv,
272 261
273 for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) { 262 for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) {
274 if (qc->id && qc->id == radio_qctrl[i].id) { 263 if (qc->id && qc->id == radio_qctrl[i].id) {
275 memcpy(qc, &(radio_qctrl[i]), 264 memcpy(qc, &(radio_qctrl[i]), sizeof(*qc));
276 sizeof(*qc));
277 return 0; 265 return 0;
278 } 266 }
279 } 267 }
@@ -283,7 +271,7 @@ static int vidioc_queryctrl(struct file *file, void *priv,
283static int vidioc_g_ctrl(struct file *file, void *priv, 271static int vidioc_g_ctrl(struct file *file, void *priv,
284 struct v4l2_control *ctrl) 272 struct v4l2_control *ctrl)
285{ 273{
286 struct tt_device *tt = video_drvdata(file); 274 struct terratec *tt = video_drvdata(file);
287 275
288 switch (ctrl->id) { 276 switch (ctrl->id) {
289 case V4L2_CID_AUDIO_MUTE: 277 case V4L2_CID_AUDIO_MUTE:
@@ -302,7 +290,7 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
302static int vidioc_s_ctrl(struct file *file, void *priv, 290static int vidioc_s_ctrl(struct file *file, void *priv,
303 struct v4l2_control *ctrl) 291 struct v4l2_control *ctrl)
304{ 292{
305 struct tt_device *tt = video_drvdata(file); 293 struct terratec *tt = video_drvdata(file);
306 294
307 switch (ctrl->id) { 295 switch (ctrl->id) {
308 case V4L2_CID_AUDIO_MUTE: 296 case V4L2_CID_AUDIO_MUTE:
@@ -318,17 +306,6 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
318 return -EINVAL; 306 return -EINVAL;
319} 307}
320 308
321static int vidioc_g_audio(struct file *file, void *priv,
322 struct v4l2_audio *a)
323{
324 if (a->index > 1)
325 return -EINVAL;
326
327 strcpy(a->name, "Radio");
328 a->capability = V4L2_AUDCAP_STEREO;
329 return 0;
330}
331
332static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i) 309static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
333{ 310{
334 *i = 0; 311 *i = 0;
@@ -337,36 +314,38 @@ static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
337 314
338static int vidioc_s_input(struct file *filp, void *priv, unsigned int i) 315static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
339{ 316{
340 if (i != 0) 317 return i ? -EINVAL : 0;
341 return -EINVAL;
342 return 0;
343} 318}
344 319
345static int vidioc_s_audio(struct file *file, void *priv, 320static int vidioc_g_audio(struct file *file, void *priv,
346 struct v4l2_audio *a) 321 struct v4l2_audio *a)
347{ 322{
348 if (a->index != 0) 323 a->index = 0;
349 return -EINVAL; 324 strlcpy(a->name, "Radio", sizeof(a->name));
325 a->capability = V4L2_AUDCAP_STEREO;
350 return 0; 326 return 0;
351} 327}
352 328
353static struct tt_device terratec_unit; 329static int vidioc_s_audio(struct file *file, void *priv,
330 struct v4l2_audio *a)
331{
332 return a->index ? -EINVAL : 0;
333}
354 334
355static int terratec_exclusive_open(struct file *file) 335static int terratec_open(struct file *file)
356{ 336{
357 return test_and_set_bit(0, &terratec_unit.in_use) ? -EBUSY : 0; 337 return 0;
358} 338}
359 339
360static int terratec_exclusive_release(struct file *file) 340static int terratec_release(struct file *file)
361{ 341{
362 clear_bit(0, &terratec_unit.in_use);
363 return 0; 342 return 0;
364} 343}
365 344
366static const struct v4l2_file_operations terratec_fops = { 345static const struct v4l2_file_operations terratec_fops = {
367 .owner = THIS_MODULE, 346 .owner = THIS_MODULE,
368 .open = terratec_exclusive_open, 347 .open = terratec_open,
369 .release = terratec_exclusive_release, 348 .release = terratec_release,
370 .ioctl = video_ioctl2, 349 .ioctl = video_ioctl2,
371}; 350};
372 351
@@ -385,60 +364,63 @@ static const struct v4l2_ioctl_ops terratec_ioctl_ops = {
385 .vidioc_s_input = vidioc_s_input, 364 .vidioc_s_input = vidioc_s_input,
386}; 365};
387 366
388static struct video_device terratec_radio = {
389 .name = "TerraTec ActiveRadio",
390 .fops = &terratec_fops,
391 .ioctl_ops = &terratec_ioctl_ops,
392 .release = video_device_release_empty,
393};
394
395static int __init terratec_init(void) 367static int __init terratec_init(void)
396{ 368{
397 if(io==-1) 369 struct terratec *tt = &terratec_card;
398 { 370 struct v4l2_device *v4l2_dev = &tt->v4l2_dev;
399 printk(KERN_ERR "You must set an I/O address with io=0x???\n"); 371 int res;
372
373 strlcpy(v4l2_dev->name, "terratec", sizeof(v4l2_dev->name));
374 tt->io = io;
375 if (tt->io == -1) {
376 v4l2_err(v4l2_dev, "you must set an I/O address with io=0x590 or 0x591\n");
400 return -EINVAL; 377 return -EINVAL;
401 } 378 }
402 if (!request_region(io, 2, "terratec")) 379 if (!request_region(tt->io, 2, "terratec")) {
403 { 380 v4l2_err(v4l2_dev, "port 0x%x already in use\n", io);
404 printk(KERN_ERR "TerraTec: port 0x%x already in use\n", io);
405 return -EBUSY; 381 return -EBUSY;
406 } 382 }
407 383
408 video_set_drvdata(&terratec_radio, &terratec_unit); 384 res = v4l2_device_register(NULL, v4l2_dev);
385 if (res < 0) {
386 release_region(tt->io, 2);
387 v4l2_err(v4l2_dev, "Could not register v4l2_device\n");
388 return res;
389 }
390
391 strlcpy(tt->vdev.name, v4l2_dev->name, sizeof(tt->vdev.name));
392 tt->vdev.v4l2_dev = v4l2_dev;
393 tt->vdev.fops = &terratec_fops;
394 tt->vdev.ioctl_ops = &terratec_ioctl_ops;
395 tt->vdev.release = video_device_release_empty;
396 video_set_drvdata(&tt->vdev, tt);
409 397
410 spin_lock_init(&lock); 398 mutex_init(&tt->lock);
411 399
412 if (video_register_device(&terratec_radio, VFL_TYPE_RADIO, radio_nr) < 0) { 400 if (video_register_device(&tt->vdev, VFL_TYPE_RADIO, radio_nr) < 0) {
413 release_region(io,2); 401 v4l2_device_unregister(&tt->v4l2_dev);
402 release_region(tt->io, 2);
414 return -EINVAL; 403 return -EINVAL;
415 } 404 }
416 405
417 printk(KERN_INFO "TERRATEC ActivRadio Standalone card driver.\n"); 406 v4l2_info(v4l2_dev, "TERRATEC ActivRadio Standalone card driver.\n");
418 407
419 /* mute card - prevents noisy bootups */ 408 /* mute card - prevents noisy bootups */
420 409 tt_write_vol(tt, 0);
421 /* this ensures that the volume is all the way down */
422 cardWriteVol(0);
423 terratec_unit.curvol = 0;
424
425 return 0; 410 return 0;
426} 411}
427 412
428MODULE_AUTHOR("R.OFFERMANNS & others"); 413static void __exit terratec_exit(void)
429MODULE_DESCRIPTION("A driver for the TerraTec ActiveRadio Standalone radio card.");
430MODULE_LICENSE("GPL");
431module_param(io, int, 0);
432MODULE_PARM_DESC(io, "I/O address of the TerraTec ActiveRadio card (0x590 or 0x591)");
433module_param(radio_nr, int, 0);
434
435static void __exit terratec_cleanup_module(void)
436{ 414{
437 video_unregister_device(&terratec_radio); 415 struct terratec *tt = &terratec_card;
438 release_region(io,2); 416 struct v4l2_device *v4l2_dev = &tt->v4l2_dev;
439 printk(KERN_INFO "TERRATEC ActivRadio Standalone card driver unloaded.\n"); 417
418 video_unregister_device(&tt->vdev);
419 v4l2_device_unregister(&tt->v4l2_dev);
420 release_region(tt->io, 2);
421 v4l2_info(v4l2_dev, "TERRATEC ActivRadio Standalone card driver unloaded.\n");
440} 422}
441 423
442module_init(terratec_init); 424module_init(terratec_init);
443module_exit(terratec_cleanup_module); 425module_exit(terratec_exit);
444 426
diff --git a/drivers/media/radio/radio-trust.c b/drivers/media/radio/radio-trust.c
index bdf9cb6a75f4..d1be6492a07b 100644
--- a/drivers/media/radio/radio-trust.c
+++ b/drivers/media/radio/radio-trust.c
@@ -19,49 +19,15 @@
19#include <linux/module.h> 19#include <linux/module.h>
20#include <linux/init.h> 20#include <linux/init.h>
21#include <linux/ioport.h> 21#include <linux/ioport.h>
22#include <asm/io.h> 22#include <linux/version.h> /* for KERNEL_VERSION MACRO */
23#include <asm/uaccess.h>
24#include <linux/videodev2.h> 23#include <linux/videodev2.h>
25#include <media/v4l2-common.h> 24#include <linux/io.h>
25#include <media/v4l2-device.h>
26#include <media/v4l2-ioctl.h> 26#include <media/v4l2-ioctl.h>
27 27
28#include <linux/version.h> /* for KERNEL_VERSION MACRO */ 28MODULE_AUTHOR("Eric Lammerts, Russell Kroll, Quay Lu, Donald Song, Jason Lewis, Scott McGrath, William McGrath");
29#define RADIO_VERSION KERNEL_VERSION(0,0,2) 29MODULE_DESCRIPTION("A driver for the Trust FM Radio card.");
30 30MODULE_LICENSE("GPL");
31static struct v4l2_queryctrl radio_qctrl[] = {
32 {
33 .id = V4L2_CID_AUDIO_MUTE,
34 .name = "Mute",
35 .minimum = 0,
36 .maximum = 1,
37 .default_value = 1,
38 .type = V4L2_CTRL_TYPE_BOOLEAN,
39 },{
40 .id = V4L2_CID_AUDIO_VOLUME,
41 .name = "Volume",
42 .minimum = 0,
43 .maximum = 65535,
44 .step = 2048,
45 .default_value = 65535,
46 .type = V4L2_CTRL_TYPE_INTEGER,
47 },{
48 .id = V4L2_CID_AUDIO_BASS,
49 .name = "Bass",
50 .minimum = 0,
51 .maximum = 65535,
52 .step = 4370,
53 .default_value = 32768,
54 .type = V4L2_CTRL_TYPE_INTEGER,
55 },{
56 .id = V4L2_CID_AUDIO_TREBLE,
57 .name = "Treble",
58 .minimum = 0,
59 .maximum = 65535,
60 .step = 4370,
61 .default_value = 32768,
62 .type = V4L2_CTRL_TYPE_INTEGER,
63 },
64};
65 31
66/* acceptable ports: 0x350 (JP3 shorted), 0x358 (JP3 open) */ 32/* acceptable ports: 0x350 (JP3 shorted), 0x358 (JP3 open) */
67 33
@@ -71,26 +37,41 @@ static struct v4l2_queryctrl radio_qctrl[] = {
71 37
72static int io = CONFIG_RADIO_TRUST_PORT; 38static int io = CONFIG_RADIO_TRUST_PORT;
73static int radio_nr = -1; 39static int radio_nr = -1;
74static int ioval = 0xf; 40
75static __u16 curvol; 41module_param(io, int, 0);
76static __u16 curbass; 42MODULE_PARM_DESC(io, "I/O address of the Trust FM Radio card (0x350 or 0x358)");
77static __u16 curtreble; 43module_param(radio_nr, int, 0);
78static unsigned long curfreq; 44
79static int curstereo; 45#define RADIO_VERSION KERNEL_VERSION(0, 0, 2)
80static int curmute; 46
81static unsigned long in_use; 47struct trust {
48 struct v4l2_device v4l2_dev;
49 struct video_device vdev;
50 int io;
51 int ioval;
52 __u16 curvol;
53 __u16 curbass;
54 __u16 curtreble;
55 int muted;
56 unsigned long curfreq;
57 int curstereo;
58 int curmute;
59 struct mutex lock;
60};
61
62static struct trust trust_card;
82 63
83/* i2c addresses */ 64/* i2c addresses */
84#define TDA7318_ADDR 0x88 65#define TDA7318_ADDR 0x88
85#define TSA6060T_ADDR 0xc4 66#define TSA6060T_ADDR 0xc4
86 67
87#define TR_DELAY do { inb(io); inb(io); inb(io); } while(0) 68#define TR_DELAY do { inb(tr->io); inb(tr->io); inb(tr->io); } while (0)
88#define TR_SET_SCL outb(ioval |= 2, io) 69#define TR_SET_SCL outb(tr->ioval |= 2, tr->io)
89#define TR_CLR_SCL outb(ioval &= 0xfd, io) 70#define TR_CLR_SCL outb(tr->ioval &= 0xfd, tr->io)
90#define TR_SET_SDA outb(ioval |= 1, io) 71#define TR_SET_SDA outb(tr->ioval |= 1, tr->io)
91#define TR_CLR_SDA outb(ioval &= 0xfe, io) 72#define TR_CLR_SDA outb(tr->ioval &= 0xfe, tr->io)
92 73
93static void write_i2c(int n, ...) 74static void write_i2c(struct trust *tr, int n, ...)
94{ 75{
95 unsigned char val, mask; 76 unsigned char val, mask;
96 va_list args; 77 va_list args;
@@ -136,62 +117,77 @@ static void write_i2c(int n, ...)
136 va_end(args); 117 va_end(args);
137} 118}
138 119
139static void tr_setvol(__u16 vol) 120static void tr_setvol(struct trust *tr, __u16 vol)
140{ 121{
141 curvol = vol / 2048; 122 mutex_lock(&tr->lock);
142 write_i2c(2, TDA7318_ADDR, curvol ^ 0x1f); 123 tr->curvol = vol / 2048;
124 write_i2c(tr, 2, TDA7318_ADDR, tr->curvol ^ 0x1f);
125 mutex_unlock(&tr->lock);
143} 126}
144 127
145static int basstreble2chip[15] = { 128static int basstreble2chip[15] = {
146 0, 1, 2, 3, 4, 5, 6, 7, 14, 13, 12, 11, 10, 9, 8 129 0, 1, 2, 3, 4, 5, 6, 7, 14, 13, 12, 11, 10, 9, 8
147}; 130};
148 131
149static void tr_setbass(__u16 bass) 132static void tr_setbass(struct trust *tr, __u16 bass)
150{ 133{
151 curbass = bass / 4370; 134 mutex_lock(&tr->lock);
152 write_i2c(2, TDA7318_ADDR, 0x60 | basstreble2chip[curbass]); 135 tr->curbass = bass / 4370;
136 write_i2c(tr, 2, TDA7318_ADDR, 0x60 | basstreble2chip[tr->curbass]);
137 mutex_unlock(&tr->lock);
153} 138}
154 139
155static void tr_settreble(__u16 treble) 140static void tr_settreble(struct trust *tr, __u16 treble)
156{ 141{
157 curtreble = treble / 4370; 142 mutex_lock(&tr->lock);
158 write_i2c(2, TDA7318_ADDR, 0x70 | basstreble2chip[curtreble]); 143 tr->curtreble = treble / 4370;
144 write_i2c(tr, 2, TDA7318_ADDR, 0x70 | basstreble2chip[tr->curtreble]);
145 mutex_unlock(&tr->lock);
159} 146}
160 147
161static void tr_setstereo(int stereo) 148static void tr_setstereo(struct trust *tr, int stereo)
162{ 149{
163 curstereo = !!stereo; 150 mutex_lock(&tr->lock);
164 ioval = (ioval & 0xfb) | (!curstereo << 2); 151 tr->curstereo = !!stereo;
165 outb(ioval, io); 152 tr->ioval = (tr->ioval & 0xfb) | (!tr->curstereo << 2);
153 outb(tr->ioval, tr->io);
154 mutex_unlock(&tr->lock);
166} 155}
167 156
168static void tr_setmute(int mute) 157static void tr_setmute(struct trust *tr, int mute)
169{ 158{
170 curmute = !!mute; 159 mutex_lock(&tr->lock);
171 ioval = (ioval & 0xf7) | (curmute << 3); 160 tr->curmute = !!mute;
172 outb(ioval, io); 161 tr->ioval = (tr->ioval & 0xf7) | (tr->curmute << 3);
162 outb(tr->ioval, tr->io);
163 mutex_unlock(&tr->lock);
173} 164}
174 165
175static int tr_getsigstr(void) 166static int tr_getsigstr(struct trust *tr)
176{ 167{
177 int i, v; 168 int i, v;
178 169
179 for(i = 0, v = 0; i < 100; i++) v |= inb(io); 170 mutex_lock(&tr->lock);
180 return (v & 1)? 0 : 0xffff; 171 for (i = 0, v = 0; i < 100; i++)
172 v |= inb(tr->io);
173 mutex_unlock(&tr->lock);
174 return (v & 1) ? 0 : 0xffff;
181} 175}
182 176
183static int tr_getstereo(void) 177static int tr_getstereo(struct trust *tr)
184{ 178{
185 /* don't know how to determine it, just return the setting */ 179 /* don't know how to determine it, just return the setting */
186 return curstereo; 180 return tr->curstereo;
187} 181}
188 182
189static void tr_setfreq(unsigned long f) 183static void tr_setfreq(struct trust *tr, unsigned long f)
190{ 184{
185 mutex_lock(&tr->lock);
186 tr->curfreq = f;
191 f /= 160; /* Convert to 10 kHz units */ 187 f /= 160; /* Convert to 10 kHz units */
192 f += 1070; /* Add 10.7 MHz IF */ 188 f += 1070; /* Add 10.7 MHz IF */
193 189 write_i2c(tr, 5, TSA6060T_ADDR, (f << 1) | 1, f >> 7, 0x60 | ((f >> 15) & 1), 0);
194 write_i2c(5, TSA6060T_ADDR, (f << 1) | 1, f >> 7, 0x60 | ((f >> 15) & 1), 0); 190 mutex_unlock(&tr->lock);
195} 191}
196 192
197static int vidioc_querycap(struct file *file, void *priv, 193static int vidioc_querycap(struct file *file, void *priv,
@@ -199,68 +195,75 @@ static int vidioc_querycap(struct file *file, void *priv,
199{ 195{
200 strlcpy(v->driver, "radio-trust", sizeof(v->driver)); 196 strlcpy(v->driver, "radio-trust", sizeof(v->driver));
201 strlcpy(v->card, "Trust FM Radio", sizeof(v->card)); 197 strlcpy(v->card, "Trust FM Radio", sizeof(v->card));
202 sprintf(v->bus_info, "ISA"); 198 strlcpy(v->bus_info, "ISA", sizeof(v->bus_info));
203 v->version = RADIO_VERSION; 199 v->version = RADIO_VERSION;
204 v->capabilities = V4L2_CAP_TUNER; 200 v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
205 return 0; 201 return 0;
206} 202}
207 203
208static int vidioc_g_tuner(struct file *file, void *priv, 204static int vidioc_g_tuner(struct file *file, void *priv,
209 struct v4l2_tuner *v) 205 struct v4l2_tuner *v)
210{ 206{
207 struct trust *tr = video_drvdata(file);
208
211 if (v->index > 0) 209 if (v->index > 0)
212 return -EINVAL; 210 return -EINVAL;
213 211
214 strcpy(v->name, "FM"); 212 strlcpy(v->name, "FM", sizeof(v->name));
215 v->type = V4L2_TUNER_RADIO; 213 v->type = V4L2_TUNER_RADIO;
216 v->rangelow = (87.5*16000); 214 v->rangelow = 87.5 * 16000;
217 v->rangehigh = (108*16000); 215 v->rangehigh = 108 * 16000;
218 v->rxsubchans = V4L2_TUNER_SUB_MONO|V4L2_TUNER_SUB_STEREO; 216 v->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO;
219 v->capability = V4L2_TUNER_CAP_LOW; 217 v->capability = V4L2_TUNER_CAP_LOW;
220 if (tr_getstereo()) 218 if (tr_getstereo(tr))
221 v->audmode = V4L2_TUNER_MODE_STEREO; 219 v->audmode = V4L2_TUNER_MODE_STEREO;
222 else 220 else
223 v->audmode = V4L2_TUNER_MODE_MONO; 221 v->audmode = V4L2_TUNER_MODE_MONO;
224 v->signal = tr_getsigstr(); 222 v->signal = tr_getsigstr(tr);
225 return 0; 223 return 0;
226} 224}
227 225
228static int vidioc_s_tuner(struct file *file, void *priv, 226static int vidioc_s_tuner(struct file *file, void *priv,
229 struct v4l2_tuner *v) 227 struct v4l2_tuner *v)
230{ 228{
231 if (v->index > 0) 229 struct trust *tr = video_drvdata(file);
232 return -EINVAL;
233 230
231 if (v->index)
232 return -EINVAL;
233 tr_setstereo(tr, v->audmode == V4L2_TUNER_MODE_STEREO);
234 return 0; 234 return 0;
235} 235}
236 236
237static int vidioc_s_frequency(struct file *file, void *priv, 237static int vidioc_s_frequency(struct file *file, void *priv,
238 struct v4l2_frequency *f) 238 struct v4l2_frequency *f)
239{ 239{
240 curfreq = f->frequency; 240 struct trust *tr = video_drvdata(file);
241 tr_setfreq(curfreq); 241
242 tr_setfreq(tr, f->frequency);
242 return 0; 243 return 0;
243} 244}
244 245
245static int vidioc_g_frequency(struct file *file, void *priv, 246static int vidioc_g_frequency(struct file *file, void *priv,
246 struct v4l2_frequency *f) 247 struct v4l2_frequency *f)
247{ 248{
249 struct trust *tr = video_drvdata(file);
250
248 f->type = V4L2_TUNER_RADIO; 251 f->type = V4L2_TUNER_RADIO;
249 f->frequency = curfreq; 252 f->frequency = tr->curfreq;
250 return 0; 253 return 0;
251} 254}
252 255
253static int vidioc_queryctrl(struct file *file, void *priv, 256static int vidioc_queryctrl(struct file *file, void *priv,
254 struct v4l2_queryctrl *qc) 257 struct v4l2_queryctrl *qc)
255{ 258{
256 int i; 259 switch (qc->id) {
257 260 case V4L2_CID_AUDIO_MUTE:
258 for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) { 261 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
259 if (qc->id && qc->id == radio_qctrl[i].id) { 262 case V4L2_CID_AUDIO_VOLUME:
260 memcpy(qc, &(radio_qctrl[i]), 263 return v4l2_ctrl_query_fill(qc, 0, 65535, 2048, 65535);
261 sizeof(*qc)); 264 case V4L2_CID_AUDIO_BASS:
262 return 0; 265 case V4L2_CID_AUDIO_TREBLE:
263 } 266 return v4l2_ctrl_query_fill(qc, 0, 65535, 4370, 32768);
264 } 267 }
265 return -EINVAL; 268 return -EINVAL;
266} 269}
@@ -268,18 +271,20 @@ static int vidioc_queryctrl(struct file *file, void *priv,
268static int vidioc_g_ctrl(struct file *file, void *priv, 271static int vidioc_g_ctrl(struct file *file, void *priv,
269 struct v4l2_control *ctrl) 272 struct v4l2_control *ctrl)
270{ 273{
274 struct trust *tr = video_drvdata(file);
275
271 switch (ctrl->id) { 276 switch (ctrl->id) {
272 case V4L2_CID_AUDIO_MUTE: 277 case V4L2_CID_AUDIO_MUTE:
273 ctrl->value = curmute; 278 ctrl->value = tr->curmute;
274 return 0; 279 return 0;
275 case V4L2_CID_AUDIO_VOLUME: 280 case V4L2_CID_AUDIO_VOLUME:
276 ctrl->value = curvol * 2048; 281 ctrl->value = tr->curvol * 2048;
277 return 0; 282 return 0;
278 case V4L2_CID_AUDIO_BASS: 283 case V4L2_CID_AUDIO_BASS:
279 ctrl->value = curbass * 4370; 284 ctrl->value = tr->curbass * 4370;
280 return 0; 285 return 0;
281 case V4L2_CID_AUDIO_TREBLE: 286 case V4L2_CID_AUDIO_TREBLE:
282 ctrl->value = curtreble * 4370; 287 ctrl->value = tr->curtreble * 4370;
283 return 0; 288 return 0;
284 } 289 }
285 return -EINVAL; 290 return -EINVAL;
@@ -288,34 +293,25 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
288static int vidioc_s_ctrl(struct file *file, void *priv, 293static int vidioc_s_ctrl(struct file *file, void *priv,
289 struct v4l2_control *ctrl) 294 struct v4l2_control *ctrl)
290{ 295{
296 struct trust *tr = video_drvdata(file);
297
291 switch (ctrl->id) { 298 switch (ctrl->id) {
292 case V4L2_CID_AUDIO_MUTE: 299 case V4L2_CID_AUDIO_MUTE:
293 tr_setmute(ctrl->value); 300 tr_setmute(tr, ctrl->value);
294 return 0; 301 return 0;
295 case V4L2_CID_AUDIO_VOLUME: 302 case V4L2_CID_AUDIO_VOLUME:
296 tr_setvol(ctrl->value); 303 tr_setvol(tr, ctrl->value);
297 return 0; 304 return 0;
298 case V4L2_CID_AUDIO_BASS: 305 case V4L2_CID_AUDIO_BASS:
299 tr_setbass(ctrl->value); 306 tr_setbass(tr, ctrl->value);
300 return 0; 307 return 0;
301 case V4L2_CID_AUDIO_TREBLE: 308 case V4L2_CID_AUDIO_TREBLE:
302 tr_settreble(ctrl->value); 309 tr_settreble(tr, ctrl->value);
303 return 0; 310 return 0;
304 } 311 }
305 return -EINVAL; 312 return -EINVAL;
306} 313}
307 314
308static int vidioc_g_audio(struct file *file, void *priv,
309 struct v4l2_audio *a)
310{
311 if (a->index > 1)
312 return -EINVAL;
313
314 strcpy(a->name, "Radio");
315 a->capability = V4L2_AUDCAP_STEREO;
316 return 0;
317}
318
319static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i) 315static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
320{ 316{
321 *i = 0; 317 *i = 0;
@@ -324,34 +320,38 @@ static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
324 320
325static int vidioc_s_input(struct file *filp, void *priv, unsigned int i) 321static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
326{ 322{
327 if (i != 0) 323 return i ? -EINVAL : 0;
328 return -EINVAL; 324}
325
326static int vidioc_g_audio(struct file *file, void *priv,
327 struct v4l2_audio *a)
328{
329 a->index = 0;
330 strlcpy(a->name, "Radio", sizeof(a->name));
331 a->capability = V4L2_AUDCAP_STEREO;
329 return 0; 332 return 0;
330} 333}
331 334
332static int vidioc_s_audio(struct file *file, void *priv, 335static int vidioc_s_audio(struct file *file, void *priv,
333 struct v4l2_audio *a) 336 struct v4l2_audio *a)
334{ 337{
335 if (a->index != 0) 338 return a->index ? -EINVAL : 0;
336 return -EINVAL;
337 return 0;
338} 339}
339 340
340static int trust_exclusive_open(struct file *file) 341static int trust_open(struct file *file)
341{ 342{
342 return test_and_set_bit(0, &in_use) ? -EBUSY : 0; 343 return 0;
343} 344}
344 345
345static int trust_exclusive_release(struct file *file) 346static int trust_release(struct file *file)
346{ 347{
347 clear_bit(0, &in_use);
348 return 0; 348 return 0;
349} 349}
350 350
351static const struct v4l2_file_operations trust_fops = { 351static const struct v4l2_file_operations trust_fops = {
352 .owner = THIS_MODULE, 352 .owner = THIS_MODULE,
353 .open = trust_exclusive_open, 353 .open = trust_open,
354 .release = trust_exclusive_release, 354 .release = trust_release,
355 .ioctl = video_ioctl2, 355 .ioctl = video_ioctl2,
356}; 356};
357 357
@@ -370,59 +370,72 @@ static const struct v4l2_ioctl_ops trust_ioctl_ops = {
370 .vidioc_s_input = vidioc_s_input, 370 .vidioc_s_input = vidioc_s_input,
371}; 371};
372 372
373static struct video_device trust_radio = {
374 .name = "Trust FM Radio",
375 .fops = &trust_fops,
376 .ioctl_ops = &trust_ioctl_ops,
377 .release = video_device_release_empty,
378};
379
380static int __init trust_init(void) 373static int __init trust_init(void)
381{ 374{
382 if(io == -1) { 375 struct trust *tr = &trust_card;
383 printk(KERN_ERR "You must set an I/O address with io=0x???\n"); 376 struct v4l2_device *v4l2_dev = &tr->v4l2_dev;
377 int res;
378
379 strlcpy(v4l2_dev->name, "trust", sizeof(v4l2_dev->name));
380 tr->io = io;
381 tr->ioval = 0xf;
382 mutex_init(&tr->lock);
383
384 if (tr->io == -1) {
385 v4l2_err(v4l2_dev, "You must set an I/O address with io=0x0x350 or 0x358\n");
384 return -EINVAL; 386 return -EINVAL;
385 } 387 }
386 if(!request_region(io, 2, "Trust FM Radio")) { 388 if (!request_region(tr->io, 2, "Trust FM Radio")) {
387 printk(KERN_ERR "trust: port 0x%x already in use\n", io); 389 v4l2_err(v4l2_dev, "port 0x%x already in use\n", tr->io);
388 return -EBUSY; 390 return -EBUSY;
389 } 391 }
390 if (video_register_device(&trust_radio, VFL_TYPE_RADIO, radio_nr) < 0) { 392
391 release_region(io, 2); 393 res = v4l2_device_register(NULL, v4l2_dev);
394 if (res < 0) {
395 release_region(tr->io, 2);
396 v4l2_err(v4l2_dev, "Could not register v4l2_device\n");
397 return res;
398 }
399
400 strlcpy(tr->vdev.name, v4l2_dev->name, sizeof(tr->vdev.name));
401 tr->vdev.v4l2_dev = v4l2_dev;
402 tr->vdev.fops = &trust_fops;
403 tr->vdev.ioctl_ops = &trust_ioctl_ops;
404 tr->vdev.release = video_device_release_empty;
405 video_set_drvdata(&tr->vdev, tr);
406
407 if (video_register_device(&tr->vdev, VFL_TYPE_RADIO, radio_nr) < 0) {
408 v4l2_device_unregister(v4l2_dev);
409 release_region(tr->io, 2);
392 return -EINVAL; 410 return -EINVAL;
393 } 411 }
394 412
395 printk(KERN_INFO "Trust FM Radio card driver v1.0.\n"); 413 v4l2_info(v4l2_dev, "Trust FM Radio card driver v1.0.\n");
396 414
397 write_i2c(2, TDA7318_ADDR, 0x80); /* speaker att. LF = 0 dB */ 415 write_i2c(tr, 2, TDA7318_ADDR, 0x80); /* speaker att. LF = 0 dB */
398 write_i2c(2, TDA7318_ADDR, 0xa0); /* speaker att. RF = 0 dB */ 416 write_i2c(tr, 2, TDA7318_ADDR, 0xa0); /* speaker att. RF = 0 dB */
399 write_i2c(2, TDA7318_ADDR, 0xc0); /* speaker att. LR = 0 dB */ 417 write_i2c(tr, 2, TDA7318_ADDR, 0xc0); /* speaker att. LR = 0 dB */
400 write_i2c(2, TDA7318_ADDR, 0xe0); /* speaker att. RR = 0 dB */ 418 write_i2c(tr, 2, TDA7318_ADDR, 0xe0); /* speaker att. RR = 0 dB */
401 write_i2c(2, TDA7318_ADDR, 0x40); /* stereo 1 input, gain = 18.75 dB */ 419 write_i2c(tr, 2, TDA7318_ADDR, 0x40); /* stereo 1 input, gain = 18.75 dB */
402 420
403 tr_setvol(0x8000); 421 tr_setvol(tr, 0xffff);
404 tr_setbass(0x8000); 422 tr_setbass(tr, 0x8000);
405 tr_settreble(0x8000); 423 tr_settreble(tr, 0x8000);
406 tr_setstereo(1); 424 tr_setstereo(tr, 1);
407 425
408 /* mute card - prevents noisy bootups */ 426 /* mute card - prevents noisy bootups */
409 tr_setmute(1); 427 tr_setmute(tr, 1);
410 428
411 return 0; 429 return 0;
412} 430}
413 431
414MODULE_AUTHOR("Eric Lammerts, Russell Kroll, Quay Lu, Donald Song, Jason Lewis, Scott McGrath, William McGrath");
415MODULE_DESCRIPTION("A driver for the Trust FM Radio card.");
416MODULE_LICENSE("GPL");
417
418module_param(io, int, 0);
419MODULE_PARM_DESC(io, "I/O address of the Trust FM Radio card (0x350 or 0x358)");
420module_param(radio_nr, int, 0);
421
422static void __exit cleanup_trust_module(void) 432static void __exit cleanup_trust_module(void)
423{ 433{
424 video_unregister_device(&trust_radio); 434 struct trust *tr = &trust_card;
425 release_region(io, 2); 435
436 video_unregister_device(&tr->vdev);
437 v4l2_device_unregister(&tr->v4l2_dev);
438 release_region(tr->io, 2);
426} 439}
427 440
428module_init(trust_init); 441module_init(trust_init);
diff --git a/drivers/media/radio/radio-typhoon.c b/drivers/media/radio/radio-typhoon.c
index 5c3b319dab37..92d923c7f360 100644
--- a/drivers/media/radio/radio-typhoon.c
+++ b/drivers/media/radio/radio-typhoon.c
@@ -34,37 +34,15 @@
34#include <linux/module.h> /* Modules */ 34#include <linux/module.h> /* Modules */
35#include <linux/init.h> /* Initdata */ 35#include <linux/init.h> /* Initdata */
36#include <linux/ioport.h> /* request_region */ 36#include <linux/ioport.h> /* request_region */
37#include <linux/proc_fs.h> /* radio card status report */ 37#include <linux/version.h> /* for KERNEL_VERSION MACRO */
38#include <linux/seq_file.h>
39#include <asm/io.h> /* outb, outb_p */
40#include <asm/uaccess.h> /* copy to/from user */
41#include <linux/videodev2.h> /* kernel radio structs */ 38#include <linux/videodev2.h> /* kernel radio structs */
42#include <media/v4l2-common.h> 39#include <linux/io.h> /* outb, outb_p */
40#include <media/v4l2-device.h>
43#include <media/v4l2-ioctl.h> 41#include <media/v4l2-ioctl.h>
44 42
45#include <linux/version.h> /* for KERNEL_VERSION MACRO */ 43MODULE_AUTHOR("Dr. Henrik Seidel");
46#define RADIO_VERSION KERNEL_VERSION(0,1,1) 44MODULE_DESCRIPTION("A driver for the Typhoon radio card (a.k.a. EcoRadio).");
47#define BANNER "Typhoon Radio Card driver v0.1.1\n" 45MODULE_LICENSE("GPL");
48
49static struct v4l2_queryctrl radio_qctrl[] = {
50 {
51 .id = V4L2_CID_AUDIO_MUTE,
52 .name = "Mute",
53 .minimum = 0,
54 .maximum = 1,
55 .default_value = 1,
56 .type = V4L2_CTRL_TYPE_BOOLEAN,
57 },{
58 .id = V4L2_CID_AUDIO_VOLUME,
59 .name = "Volume",
60 .minimum = 0,
61 .maximum = 65535,
62 .step = 1<<14,
63 .default_value = 0xff,
64 .type = V4L2_CTRL_TYPE_INTEGER,
65 }
66};
67
68 46
69#ifndef CONFIG_RADIO_TYPHOON_PORT 47#ifndef CONFIG_RADIO_TYPHOON_PORT
70#define CONFIG_RADIO_TYPHOON_PORT -1 48#define CONFIG_RADIO_TYPHOON_PORT -1
@@ -74,13 +52,26 @@ static struct v4l2_queryctrl radio_qctrl[] = {
74#define CONFIG_RADIO_TYPHOON_MUTEFREQ 0 52#define CONFIG_RADIO_TYPHOON_MUTEFREQ 0
75#endif 53#endif
76 54
77#ifndef CONFIG_PROC_FS 55static int io = CONFIG_RADIO_TYPHOON_PORT;
78#undef CONFIG_RADIO_TYPHOON_PROC_FS 56static int radio_nr = -1;
79#endif
80 57
81struct typhoon_device { 58module_param(io, int, 0);
82 unsigned long in_use; 59MODULE_PARM_DESC(io, "I/O address of the Typhoon card (0x316 or 0x336)");
83 int iobase; 60
61module_param(radio_nr, int, 0);
62
63static unsigned long mutefreq = CONFIG_RADIO_TYPHOON_MUTEFREQ;
64module_param(mutefreq, ulong, 0);
65MODULE_PARM_DESC(mutefreq, "Frequency used when muting the card (in kHz)");
66
67#define RADIO_VERSION KERNEL_VERSION(0, 1, 1)
68
69#define BANNER "Typhoon Radio Card driver v0.1.1\n"
70
71struct typhoon {
72 struct v4l2_device v4l2_dev;
73 struct video_device vdev;
74 int io;
84 int curvol; 75 int curvol;
85 int muted; 76 int muted;
86 unsigned long curfreq; 77 unsigned long curfreq;
@@ -88,25 +79,19 @@ struct typhoon_device {
88 struct mutex lock; 79 struct mutex lock;
89}; 80};
90 81
91static void typhoon_setvol_generic(struct typhoon_device *dev, int vol); 82static struct typhoon typhoon_card;
92static int typhoon_setfreq_generic(struct typhoon_device *dev,
93 unsigned long frequency);
94static int typhoon_setfreq(struct typhoon_device *dev, unsigned long frequency);
95static void typhoon_mute(struct typhoon_device *dev);
96static void typhoon_unmute(struct typhoon_device *dev);
97static int typhoon_setvol(struct typhoon_device *dev, int vol);
98 83
99static void typhoon_setvol_generic(struct typhoon_device *dev, int vol) 84static void typhoon_setvol_generic(struct typhoon *dev, int vol)
100{ 85{
101 mutex_lock(&dev->lock); 86 mutex_lock(&dev->lock);
102 vol >>= 14; /* Map 16 bit to 2 bit */ 87 vol >>= 14; /* Map 16 bit to 2 bit */
103 vol &= 3; 88 vol &= 3;
104 outb_p(vol / 2, dev->iobase); /* Set the volume, high bit. */ 89 outb_p(vol / 2, dev->io); /* Set the volume, high bit. */
105 outb_p(vol % 2, dev->iobase + 2); /* Set the volume, low bit. */ 90 outb_p(vol % 2, dev->io + 2); /* Set the volume, low bit. */
106 mutex_unlock(&dev->lock); 91 mutex_unlock(&dev->lock);
107} 92}
108 93
109static int typhoon_setfreq_generic(struct typhoon_device *dev, 94static int typhoon_setfreq_generic(struct typhoon *dev,
110 unsigned long frequency) 95 unsigned long frequency)
111{ 96{
112 unsigned long outval; 97 unsigned long outval;
@@ -130,22 +115,22 @@ static int typhoon_setfreq_generic(struct typhoon_device *dev,
130 outval -= (10 * x * x + 10433) / 20866; 115 outval -= (10 * x * x + 10433) / 20866;
131 outval += 4 * x - 11505; 116 outval += 4 * x - 11505;
132 117
133 outb_p((outval >> 8) & 0x01, dev->iobase + 4); 118 outb_p((outval >> 8) & 0x01, dev->io + 4);
134 outb_p(outval >> 9, dev->iobase + 6); 119 outb_p(outval >> 9, dev->io + 6);
135 outb_p(outval & 0xff, dev->iobase + 8); 120 outb_p(outval & 0xff, dev->io + 8);
136 mutex_unlock(&dev->lock); 121 mutex_unlock(&dev->lock);
137 122
138 return 0; 123 return 0;
139} 124}
140 125
141static int typhoon_setfreq(struct typhoon_device *dev, unsigned long frequency) 126static int typhoon_setfreq(struct typhoon *dev, unsigned long frequency)
142{ 127{
143 typhoon_setfreq_generic(dev, frequency); 128 typhoon_setfreq_generic(dev, frequency);
144 dev->curfreq = frequency; 129 dev->curfreq = frequency;
145 return 0; 130 return 0;
146} 131}
147 132
148static void typhoon_mute(struct typhoon_device *dev) 133static void typhoon_mute(struct typhoon *dev)
149{ 134{
150 if (dev->muted == 1) 135 if (dev->muted == 1)
151 return; 136 return;
@@ -154,7 +139,7 @@ static void typhoon_mute(struct typhoon_device *dev)
154 dev->muted = 1; 139 dev->muted = 1;
155} 140}
156 141
157static void typhoon_unmute(struct typhoon_device *dev) 142static void typhoon_unmute(struct typhoon *dev)
158{ 143{
159 if (dev->muted == 0) 144 if (dev->muted == 0)
160 return; 145 return;
@@ -163,7 +148,7 @@ static void typhoon_unmute(struct typhoon_device *dev)
163 dev->muted = 0; 148 dev->muted = 0;
164} 149}
165 150
166static int typhoon_setvol(struct typhoon_device *dev, int vol) 151static int typhoon_setvol(struct typhoon *dev, int vol)
167{ 152{
168 if (dev->muted && vol != 0) { /* user is unmuting the card */ 153 if (dev->muted && vol != 0) { /* user is unmuting the card */
169 dev->curvol = vol; 154 dev->curvol = vol;
@@ -188,9 +173,9 @@ static int vidioc_querycap(struct file *file, void *priv,
188{ 173{
189 strlcpy(v->driver, "radio-typhoon", sizeof(v->driver)); 174 strlcpy(v->driver, "radio-typhoon", sizeof(v->driver));
190 strlcpy(v->card, "Typhoon Radio", sizeof(v->card)); 175 strlcpy(v->card, "Typhoon Radio", sizeof(v->card));
191 sprintf(v->bus_info, "ISA"); 176 strlcpy(v->bus_info, "ISA", sizeof(v->bus_info));
192 v->version = RADIO_VERSION; 177 v->version = RADIO_VERSION;
193 v->capabilities = V4L2_CAP_TUNER; 178 v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
194 return 0; 179 return 0;
195} 180}
196 181
@@ -200,10 +185,10 @@ static int vidioc_g_tuner(struct file *file, void *priv,
200 if (v->index > 0) 185 if (v->index > 0)
201 return -EINVAL; 186 return -EINVAL;
202 187
203 strcpy(v->name, "FM"); 188 strlcpy(v->name, "FM", sizeof(v->name));
204 v->type = V4L2_TUNER_RADIO; 189 v->type = V4L2_TUNER_RADIO;
205 v->rangelow = (87.5*16000); 190 v->rangelow = 87.5 * 16000;
206 v->rangehigh = (108*16000); 191 v->rangehigh = 108 * 16000;
207 v->rxsubchans = V4L2_TUNER_SUB_MONO; 192 v->rxsubchans = V4L2_TUNER_SUB_MONO;
208 v->capability = V4L2_TUNER_CAP_LOW; 193 v->capability = V4L2_TUNER_CAP_LOW;
209 v->audmode = V4L2_TUNER_MODE_MONO; 194 v->audmode = V4L2_TUNER_MODE_MONO;
@@ -214,44 +199,37 @@ static int vidioc_g_tuner(struct file *file, void *priv,
214static int vidioc_s_tuner(struct file *file, void *priv, 199static int vidioc_s_tuner(struct file *file, void *priv,
215 struct v4l2_tuner *v) 200 struct v4l2_tuner *v)
216{ 201{
217 if (v->index > 0) 202 return v->index ? -EINVAL : 0;
218 return -EINVAL;
219
220 return 0;
221} 203}
222 204
223static int vidioc_s_frequency(struct file *file, void *priv, 205static int vidioc_g_frequency(struct file *file, void *priv,
224 struct v4l2_frequency *f) 206 struct v4l2_frequency *f)
225{ 207{
226 struct typhoon_device *typhoon = video_drvdata(file); 208 struct typhoon *dev = video_drvdata(file);
227 209
228 typhoon->curfreq = f->frequency; 210 f->type = V4L2_TUNER_RADIO;
229 typhoon_setfreq(typhoon, typhoon->curfreq); 211 f->frequency = dev->curfreq;
230 return 0; 212 return 0;
231} 213}
232 214
233static int vidioc_g_frequency(struct file *file, void *priv, 215static int vidioc_s_frequency(struct file *file, void *priv,
234 struct v4l2_frequency *f) 216 struct v4l2_frequency *f)
235{ 217{
236 struct typhoon_device *typhoon = video_drvdata(file); 218 struct typhoon *dev = video_drvdata(file);
237
238 f->type = V4L2_TUNER_RADIO;
239 f->frequency = typhoon->curfreq;
240 219
220 dev->curfreq = f->frequency;
221 typhoon_setfreq(dev, dev->curfreq);
241 return 0; 222 return 0;
242} 223}
243 224
244static int vidioc_queryctrl(struct file *file, void *priv, 225static int vidioc_queryctrl(struct file *file, void *priv,
245 struct v4l2_queryctrl *qc) 226 struct v4l2_queryctrl *qc)
246{ 227{
247 int i; 228 switch (qc->id) {
248 229 case V4L2_CID_AUDIO_MUTE:
249 for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) { 230 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
250 if (qc->id && qc->id == radio_qctrl[i].id) { 231 case V4L2_CID_AUDIO_VOLUME:
251 memcpy(qc, &(radio_qctrl[i]), 232 return v4l2_ctrl_query_fill(qc, 0, 65535, 16384, 65535);
252 sizeof(*qc));
253 return 0;
254 }
255 } 233 }
256 return -EINVAL; 234 return -EINVAL;
257} 235}
@@ -259,14 +237,14 @@ static int vidioc_queryctrl(struct file *file, void *priv,
259static int vidioc_g_ctrl(struct file *file, void *priv, 237static int vidioc_g_ctrl(struct file *file, void *priv,
260 struct v4l2_control *ctrl) 238 struct v4l2_control *ctrl)
261{ 239{
262 struct typhoon_device *typhoon = video_drvdata(file); 240 struct typhoon *dev = video_drvdata(file);
263 241
264 switch (ctrl->id) { 242 switch (ctrl->id) {
265 case V4L2_CID_AUDIO_MUTE: 243 case V4L2_CID_AUDIO_MUTE:
266 ctrl->value = typhoon->muted; 244 ctrl->value = dev->muted;
267 return 0; 245 return 0;
268 case V4L2_CID_AUDIO_VOLUME: 246 case V4L2_CID_AUDIO_VOLUME:
269 ctrl->value = typhoon->curvol; 247 ctrl->value = dev->curvol;
270 return 0; 248 return 0;
271 } 249 }
272 return -EINVAL; 250 return -EINVAL;
@@ -275,33 +253,22 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
275static int vidioc_s_ctrl (struct file *file, void *priv, 253static int vidioc_s_ctrl (struct file *file, void *priv,
276 struct v4l2_control *ctrl) 254 struct v4l2_control *ctrl)
277{ 255{
278 struct typhoon_device *typhoon = video_drvdata(file); 256 struct typhoon *dev = video_drvdata(file);
279 257
280 switch (ctrl->id) { 258 switch (ctrl->id) {
281 case V4L2_CID_AUDIO_MUTE: 259 case V4L2_CID_AUDIO_MUTE:
282 if (ctrl->value) 260 if (ctrl->value)
283 typhoon_mute(typhoon); 261 typhoon_mute(dev);
284 else 262 else
285 typhoon_unmute(typhoon); 263 typhoon_unmute(dev);
286 return 0; 264 return 0;
287 case V4L2_CID_AUDIO_VOLUME: 265 case V4L2_CID_AUDIO_VOLUME:
288 typhoon_setvol(typhoon, ctrl->value); 266 typhoon_setvol(dev, ctrl->value);
289 return 0; 267 return 0;
290 } 268 }
291 return -EINVAL; 269 return -EINVAL;
292} 270}
293 271
294static int vidioc_g_audio(struct file *file, void *priv,
295 struct v4l2_audio *a)
296{
297 if (a->index > 1)
298 return -EINVAL;
299
300 strcpy(a->name, "Radio");
301 a->capability = V4L2_AUDCAP_STEREO;
302 return 0;
303}
304
305static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i) 272static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
306{ 273{
307 *i = 0; 274 *i = 0;
@@ -310,45 +277,62 @@ static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
310 277
311static int vidioc_s_input(struct file *filp, void *priv, unsigned int i) 278static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
312{ 279{
313 if (i != 0) 280 return i ? -EINVAL : 0;
314 return -EINVAL; 281}
282
283static int vidioc_g_audio(struct file *file, void *priv,
284 struct v4l2_audio *a)
285{
286 a->index = 0;
287 strlcpy(a->name, "Radio", sizeof(a->name));
288 a->capability = V4L2_AUDCAP_STEREO;
315 return 0; 289 return 0;
316} 290}
317 291
318static int vidioc_s_audio(struct file *file, void *priv, 292static int vidioc_s_audio(struct file *file, void *priv,
319 struct v4l2_audio *a) 293 struct v4l2_audio *a)
320{ 294{
321 if (a->index != 0) 295 return a->index ? -EINVAL : 0;
322 return -EINVAL;
323 return 0;
324} 296}
325 297
326static struct typhoon_device typhoon_unit = 298static int vidioc_log_status(struct file *file, void *priv)
327{ 299{
328 .iobase = CONFIG_RADIO_TYPHOON_PORT, 300 struct typhoon *dev = video_drvdata(file);
329 .curfreq = CONFIG_RADIO_TYPHOON_MUTEFREQ, 301 struct v4l2_device *v4l2_dev = &dev->v4l2_dev;
330 .mutefreq = CONFIG_RADIO_TYPHOON_MUTEFREQ, 302
331}; 303 v4l2_info(v4l2_dev, BANNER);
304#ifdef MODULE
305 v4l2_info(v4l2_dev, "Load type: Driver loaded as a module\n\n");
306#else
307 v4l2_info(v4l2_dev, "Load type: Driver compiled into kernel\n\n");
308#endif
309 v4l2_info(v4l2_dev, "frequency = %lu kHz\n", dev->curfreq >> 4);
310 v4l2_info(v4l2_dev, "volume = %d\n", dev->curvol);
311 v4l2_info(v4l2_dev, "mute = %s\n", dev->muted ? "on" : "off");
312 v4l2_info(v4l2_dev, "io = 0x%x\n", dev->io);
313 v4l2_info(v4l2_dev, "mute frequency = %lu kHz\n", dev->mutefreq >> 4);
314 return 0;
315}
332 316
333static int typhoon_exclusive_open(struct file *file) 317static int typhoon_open(struct file *file)
334{ 318{
335 return test_and_set_bit(0, &typhoon_unit.in_use) ? -EBUSY : 0; 319 return 0;
336} 320}
337 321
338static int typhoon_exclusive_release(struct file *file) 322static int typhoon_release(struct file *file)
339{ 323{
340 clear_bit(0, &typhoon_unit.in_use);
341 return 0; 324 return 0;
342} 325}
343 326
344static const struct v4l2_file_operations typhoon_fops = { 327static const struct v4l2_file_operations typhoon_fops = {
345 .owner = THIS_MODULE, 328 .owner = THIS_MODULE,
346 .open = typhoon_exclusive_open, 329 .open = typhoon_open,
347 .release = typhoon_exclusive_release, 330 .release = typhoon_release,
348 .ioctl = video_ioctl2, 331 .ioctl = video_ioctl2,
349}; 332};
350 333
351static const struct v4l2_ioctl_ops typhoon_ioctl_ops = { 334static const struct v4l2_ioctl_ops typhoon_ioctl_ops = {
335 .vidioc_log_status = vidioc_log_status,
352 .vidioc_querycap = vidioc_querycap, 336 .vidioc_querycap = vidioc_querycap,
353 .vidioc_g_tuner = vidioc_g_tuner, 337 .vidioc_g_tuner = vidioc_g_tuner,
354 .vidioc_s_tuner = vidioc_s_tuner, 338 .vidioc_s_tuner = vidioc_s_tuner,
@@ -363,125 +347,72 @@ static const struct v4l2_ioctl_ops typhoon_ioctl_ops = {
363 .vidioc_s_ctrl = vidioc_s_ctrl, 347 .vidioc_s_ctrl = vidioc_s_ctrl,
364}; 348};
365 349
366static struct video_device typhoon_radio = { 350static int __init typhoon_init(void)
367 .name = "Typhoon Radio",
368 .fops = &typhoon_fops,
369 .ioctl_ops = &typhoon_ioctl_ops,
370 .release = video_device_release_empty,
371};
372
373#ifdef CONFIG_RADIO_TYPHOON_PROC_FS
374
375static int typhoon_proc_show(struct seq_file *m, void *v)
376{
377 #ifdef MODULE
378 #define MODULEPROCSTRING "Driver loaded as a module"
379 #else
380 #define MODULEPROCSTRING "Driver compiled into kernel"
381 #endif
382
383 seq_puts(m, BANNER);
384 seq_puts(m, "Load type: " MODULEPROCSTRING "\n\n");
385 seq_printf(m, "frequency = %lu kHz\n",
386 typhoon_unit.curfreq >> 4);
387 seq_printf(m, "volume = %d\n", typhoon_unit.curvol);
388 seq_printf(m, "mute = %s\n", typhoon_unit.muted ?
389 "on" : "off");
390 seq_printf(m, "iobase = 0x%x\n", typhoon_unit.iobase);
391 seq_printf(m, "mute frequency = %lu kHz\n",
392 typhoon_unit.mutefreq >> 4);
393 return 0;
394}
395
396static int typhoon_proc_open(struct inode *inode, struct file *file)
397{ 351{
398 return single_open(file, typhoon_proc_show, NULL); 352 struct typhoon *dev = &typhoon_card;
399} 353 struct v4l2_device *v4l2_dev = &dev->v4l2_dev;
400 354 int res;
401static const struct file_operations typhoon_proc_fops = {
402 .owner = THIS_MODULE,
403 .open = typhoon_proc_open,
404 .read = seq_read,
405 .llseek = seq_lseek,
406 .release = single_release,
407};
408#endif /* CONFIG_RADIO_TYPHOON_PROC_FS */
409
410MODULE_AUTHOR("Dr. Henrik Seidel");
411MODULE_DESCRIPTION("A driver for the Typhoon radio card (a.k.a. EcoRadio).");
412MODULE_LICENSE("GPL");
413
414static int io = -1;
415static int radio_nr = -1;
416
417module_param(io, int, 0);
418MODULE_PARM_DESC(io, "I/O address of the Typhoon card (0x316 or 0x336)");
419module_param(radio_nr, int, 0);
420 355
421#ifdef MODULE 356 strlcpy(v4l2_dev->name, "typhoon", sizeof(v4l2_dev->name));
422static unsigned long mutefreq; 357 dev->io = io;
423module_param(mutefreq, ulong, 0); 358 dev->curfreq = dev->mutefreq = mutefreq;
424MODULE_PARM_DESC(mutefreq, "Frequency used when muting the card (in kHz)");
425#endif
426 359
427static int __init typhoon_init(void) 360 if (dev->io == -1) {
428{ 361 v4l2_err(v4l2_dev, "You must set an I/O address with io=0x316 or io=0x336\n");
429#ifdef MODULE
430 if (io == -1) {
431 printk(KERN_ERR "radio-typhoon: You must set an I/O address with io=0x316 or io=0x336\n");
432 return -EINVAL; 362 return -EINVAL;
433 } 363 }
434 typhoon_unit.iobase = io;
435 364
436 if (mutefreq < 87000 || mutefreq > 108500) { 365 if (dev->mutefreq < 87000 || dev->mutefreq > 108500) {
437 printk(KERN_ERR "radio-typhoon: You must set a frequency (in kHz) used when muting the card,\n"); 366 v4l2_err(v4l2_dev, "You must set a frequency (in kHz) used when muting the card,\n");
438 printk(KERN_ERR "radio-typhoon: e.g. with \"mutefreq=87500\" (87000 <= mutefreq <= 108500)\n"); 367 v4l2_err(v4l2_dev, "e.g. with \"mutefreq=87500\" (87000 <= mutefreq <= 108500)\n");
439 return -EINVAL; 368 return -EINVAL;
440 } 369 }
441 typhoon_unit.mutefreq = mutefreq; 370
442#endif /* MODULE */ 371 mutex_init(&dev->lock);
443 372 if (!request_region(dev->io, 8, "typhoon")) {
444 printk(KERN_INFO BANNER); 373 v4l2_err(v4l2_dev, "port 0x%x already in use\n",
445 mutex_init(&typhoon_unit.lock); 374 dev->io);
446 io = typhoon_unit.iobase;
447 if (!request_region(io, 8, "typhoon")) {
448 printk(KERN_ERR "radio-typhoon: port 0x%x already in use\n",
449 typhoon_unit.iobase);
450 return -EBUSY; 375 return -EBUSY;
451 } 376 }
452 377
453 video_set_drvdata(&typhoon_radio, &typhoon_unit); 378 res = v4l2_device_register(NULL, v4l2_dev);
454 if (video_register_device(&typhoon_radio, VFL_TYPE_RADIO, radio_nr) < 0) { 379 if (res < 0) {
455 release_region(io, 8); 380 release_region(dev->io, 8);
381 v4l2_err(v4l2_dev, "Could not register v4l2_device\n");
382 return res;
383 }
384 v4l2_info(v4l2_dev, BANNER);
385
386 strlcpy(dev->vdev.name, v4l2_dev->name, sizeof(dev->vdev.name));
387 dev->vdev.v4l2_dev = v4l2_dev;
388 dev->vdev.fops = &typhoon_fops;
389 dev->vdev.ioctl_ops = &typhoon_ioctl_ops;
390 dev->vdev.release = video_device_release_empty;
391 video_set_drvdata(&dev->vdev, dev);
392 if (video_register_device(&dev->vdev, VFL_TYPE_RADIO, radio_nr) < 0) {
393 v4l2_device_unregister(&dev->v4l2_dev);
394 release_region(dev->io, 8);
456 return -EINVAL; 395 return -EINVAL;
457 } 396 }
458 printk(KERN_INFO "radio-typhoon: port 0x%x.\n", typhoon_unit.iobase); 397 v4l2_info(v4l2_dev, "port 0x%x.\n", dev->io);
459 printk(KERN_INFO "radio-typhoon: mute frequency is %lu kHz.\n", 398 v4l2_info(v4l2_dev, "mute frequency is %lu kHz.\n", dev->mutefreq);
460 typhoon_unit.mutefreq); 399 dev->mutefreq <<= 4;
461 typhoon_unit.mutefreq <<= 4;
462 400
463 /* mute card - prevents noisy bootups */ 401 /* mute card - prevents noisy bootups */
464 typhoon_mute(&typhoon_unit); 402 typhoon_mute(dev);
465
466#ifdef CONFIG_RADIO_TYPHOON_PROC_FS
467 if (!proc_create("driver/radio-typhoon", 0, NULL, &typhoon_proc_fops))
468 printk(KERN_ERR "radio-typhoon: registering /proc/driver/radio-typhoon failed\n");
469#endif
470 403
471 return 0; 404 return 0;
472} 405}
473 406
474static void __exit typhoon_cleanup_module(void) 407static void __exit typhoon_exit(void)
475{ 408{
409 struct typhoon *dev = &typhoon_card;
476 410
477#ifdef CONFIG_RADIO_TYPHOON_PROC_FS 411 video_unregister_device(&dev->vdev);
478 remove_proc_entry("driver/radio-typhoon", NULL); 412 v4l2_device_unregister(&dev->v4l2_dev);
479#endif 413 release_region(dev->io, 8);
480
481 video_unregister_device(&typhoon_radio);
482 release_region(io, 8);
483} 414}
484 415
485module_init(typhoon_init); 416module_init(typhoon_init);
486module_exit(typhoon_cleanup_module); 417module_exit(typhoon_exit);
487 418
diff --git a/drivers/media/radio/radio-zoltrix.c b/drivers/media/radio/radio-zoltrix.c
index d2ac17eeec5f..1f85f2024dc0 100644
--- a/drivers/media/radio/radio-zoltrix.c
+++ b/drivers/media/radio/radio-zoltrix.c
@@ -33,33 +33,16 @@
33#include <linux/init.h> /* Initdata */ 33#include <linux/init.h> /* Initdata */
34#include <linux/ioport.h> /* request_region */ 34#include <linux/ioport.h> /* request_region */
35#include <linux/delay.h> /* udelay, msleep */ 35#include <linux/delay.h> /* udelay, msleep */
36#include <asm/io.h> /* outb, outb_p */
37#include <asm/uaccess.h> /* copy to/from user */
38#include <linux/videodev2.h> /* kernel radio structs */ 36#include <linux/videodev2.h> /* kernel radio structs */
39#include <media/v4l2-common.h> 37#include <linux/mutex.h>
38#include <linux/version.h> /* for KERNEL_VERSION MACRO */
39#include <linux/io.h> /* outb, outb_p */
40#include <media/v4l2-device.h>
40#include <media/v4l2-ioctl.h> 41#include <media/v4l2-ioctl.h>
41 42
42#include <linux/version.h> /* for KERNEL_VERSION MACRO */ 43MODULE_AUTHOR("C.van Schaik");
43#define RADIO_VERSION KERNEL_VERSION(0,0,2) 44MODULE_DESCRIPTION("A driver for the Zoltrix Radio Plus.");
44 45MODULE_LICENSE("GPL");
45static struct v4l2_queryctrl radio_qctrl[] = {
46 {
47 .id = V4L2_CID_AUDIO_MUTE,
48 .name = "Mute",
49 .minimum = 0,
50 .maximum = 1,
51 .default_value = 1,
52 .type = V4L2_CTRL_TYPE_BOOLEAN,
53 },{
54 .id = V4L2_CID_AUDIO_VOLUME,
55 .name = "Volume",
56 .minimum = 0,
57 .maximum = 65535,
58 .step = 4096,
59 .default_value = 0xff,
60 .type = V4L2_CTRL_TYPE_INTEGER,
61 }
62};
63 46
64#ifndef CONFIG_RADIO_ZOLTRIX_PORT 47#ifndef CONFIG_RADIO_ZOLTRIX_PORT
65#define CONFIG_RADIO_ZOLTRIX_PORT -1 48#define CONFIG_RADIO_ZOLTRIX_PORT -1
@@ -68,9 +51,16 @@ static struct v4l2_queryctrl radio_qctrl[] = {
68static int io = CONFIG_RADIO_ZOLTRIX_PORT; 51static int io = CONFIG_RADIO_ZOLTRIX_PORT;
69static int radio_nr = -1; 52static int radio_nr = -1;
70 53
71struct zol_device { 54module_param(io, int, 0);
72 unsigned long in_use; 55MODULE_PARM_DESC(io, "I/O address of the Zoltrix Radio Plus (0x20c or 0x30c)");
73 int port; 56module_param(radio_nr, int, 0);
57
58#define RADIO_VERSION KERNEL_VERSION(0, 0, 2)
59
60struct zoltrix {
61 struct v4l2_device v4l2_dev;
62 struct video_device vdev;
63 int io;
74 int curvol; 64 int curvol;
75 unsigned long curfreq; 65 unsigned long curfreq;
76 int muted; 66 int muted;
@@ -78,161 +68,158 @@ struct zol_device {
78 struct mutex lock; 68 struct mutex lock;
79}; 69};
80 70
81static int zol_setvol(struct zol_device *dev, int vol) 71static struct zoltrix zoltrix_card;
72
73static int zol_setvol(struct zoltrix *zol, int vol)
82{ 74{
83 dev->curvol = vol; 75 zol->curvol = vol;
84 if (dev->muted) 76 if (zol->muted)
85 return 0; 77 return 0;
86 78
87 mutex_lock(&dev->lock); 79 mutex_lock(&zol->lock);
88 if (vol == 0) { 80 if (vol == 0) {
89 outb(0, io); 81 outb(0, zol->io);
90 outb(0, io); 82 outb(0, zol->io);
91 inb(io + 3); /* Zoltrix needs to be read to confirm */ 83 inb(zol->io + 3); /* Zoltrix needs to be read to confirm */
92 mutex_unlock(&dev->lock); 84 mutex_unlock(&zol->lock);
93 return 0; 85 return 0;
94 } 86 }
95 87
96 outb(dev->curvol-1, io); 88 outb(zol->curvol-1, zol->io);
97 msleep(10); 89 msleep(10);
98 inb(io + 2); 90 inb(zol->io + 2);
99 mutex_unlock(&dev->lock); 91 mutex_unlock(&zol->lock);
100 return 0; 92 return 0;
101} 93}
102 94
103static void zol_mute(struct zol_device *dev) 95static void zol_mute(struct zoltrix *zol)
104{ 96{
105 dev->muted = 1; 97 zol->muted = 1;
106 mutex_lock(&dev->lock); 98 mutex_lock(&zol->lock);
107 outb(0, io); 99 outb(0, zol->io);
108 outb(0, io); 100 outb(0, zol->io);
109 inb(io + 3); /* Zoltrix needs to be read to confirm */ 101 inb(zol->io + 3); /* Zoltrix needs to be read to confirm */
110 mutex_unlock(&dev->lock); 102 mutex_unlock(&zol->lock);
111} 103}
112 104
113static void zol_unmute(struct zol_device *dev) 105static void zol_unmute(struct zoltrix *zol)
114{ 106{
115 dev->muted = 0; 107 zol->muted = 0;
116 zol_setvol(dev, dev->curvol); 108 zol_setvol(zol, zol->curvol);
117} 109}
118 110
119static int zol_setfreq(struct zol_device *dev, unsigned long freq) 111static int zol_setfreq(struct zoltrix *zol, unsigned long freq)
120{ 112{
121 /* tunes the radio to the desired frequency */ 113 /* tunes the radio to the desired frequency */
114 struct v4l2_device *v4l2_dev = &zol->v4l2_dev;
122 unsigned long long bitmask, f, m; 115 unsigned long long bitmask, f, m;
123 unsigned int stereo = dev->stereo; 116 unsigned int stereo = zol->stereo;
124 int i; 117 int i;
125 118
126 if (freq == 0) { 119 if (freq == 0) {
127 printk(KERN_WARNING "zoltrix: received zero freq. Failed to set.\n"); 120 v4l2_warn(v4l2_dev, "cannot set a frequency of 0.\n");
128 return -EINVAL; 121 return -EINVAL;
129 } 122 }
130 123
131 m = (freq / 160 - 8800) * 2; 124 m = (freq / 160 - 8800) * 2;
132 f = (unsigned long long) m + 0x4d1c; 125 f = (unsigned long long)m + 0x4d1c;
133 126
134 bitmask = 0xc480402c10080000ull; 127 bitmask = 0xc480402c10080000ull;
135 i = 45; 128 i = 45;
136 129
137 mutex_lock(&dev->lock); 130 mutex_lock(&zol->lock);
138 131
139 outb(0, io); 132 zol->curfreq = freq;
140 outb(0, io);
141 inb(io + 3); /* Zoltrix needs to be read to confirm */
142 133
143 outb(0x40, io); 134 outb(0, zol->io);
144 outb(0xc0, io); 135 outb(0, zol->io);
136 inb(zol->io + 3); /* Zoltrix needs to be read to confirm */
145 137
146 bitmask = (bitmask ^ ((f & 0xff) << 47) ^ ((f & 0xff00) << 30) ^ ( stereo << 31)); 138 outb(0x40, zol->io);
139 outb(0xc0, zol->io);
140
141 bitmask = (bitmask ^ ((f & 0xff) << 47) ^ ((f & 0xff00) << 30) ^ (stereo << 31));
147 while (i--) { 142 while (i--) {
148 if ((bitmask & 0x8000000000000000ull) != 0) { 143 if ((bitmask & 0x8000000000000000ull) != 0) {
149 outb(0x80, io); 144 outb(0x80, zol->io);
150 udelay(50); 145 udelay(50);
151 outb(0x00, io); 146 outb(0x00, zol->io);
152 udelay(50); 147 udelay(50);
153 outb(0x80, io); 148 outb(0x80, zol->io);
154 udelay(50); 149 udelay(50);
155 } else { 150 } else {
156 outb(0xc0, io); 151 outb(0xc0, zol->io);
157 udelay(50); 152 udelay(50);
158 outb(0x40, io); 153 outb(0x40, zol->io);
159 udelay(50); 154 udelay(50);
160 outb(0xc0, io); 155 outb(0xc0, zol->io);
161 udelay(50); 156 udelay(50);
162 } 157 }
163 bitmask *= 2; 158 bitmask *= 2;
164 } 159 }
165 /* termination sequence */ 160 /* termination sequence */
166 outb(0x80, io); 161 outb(0x80, zol->io);
167 outb(0xc0, io); 162 outb(0xc0, zol->io);
168 outb(0x40, io); 163 outb(0x40, zol->io);
169 udelay(1000); 164 udelay(1000);
170 inb(io+2); 165 inb(zol->io + 2);
171 166
172 udelay(1000); 167 udelay(1000);
173 168
174 if (dev->muted) 169 if (zol->muted) {
175 { 170 outb(0, zol->io);
176 outb(0, io); 171 outb(0, zol->io);
177 outb(0, io); 172 inb(zol->io + 3);
178 inb(io + 3);
179 udelay(1000); 173 udelay(1000);
180 } 174 }
181 175
182 mutex_unlock(&dev->lock); 176 mutex_unlock(&zol->lock);
183 177
184 if(!dev->muted) 178 if (!zol->muted)
185 { 179 zol_setvol(zol, zol->curvol);
186 zol_setvol(dev, dev->curvol);
187 }
188 return 0; 180 return 0;
189} 181}
190 182
191/* Get signal strength */ 183/* Get signal strength */
192 184static int zol_getsigstr(struct zoltrix *zol)
193static int zol_getsigstr(struct zol_device *dev)
194{ 185{
195 int a, b; 186 int a, b;
196 187
197 mutex_lock(&dev->lock); 188 mutex_lock(&zol->lock);
198 outb(0x00, io); /* This stuff I found to do nothing */ 189 outb(0x00, zol->io); /* This stuff I found to do nothing */
199 outb(dev->curvol, io); 190 outb(zol->curvol, zol->io);
200 msleep(20); 191 msleep(20);
201 192
202 a = inb(io); 193 a = inb(zol->io);
203 msleep(10); 194 msleep(10);
204 b = inb(io); 195 b = inb(zol->io);
205 196
206 mutex_unlock(&dev->lock); 197 mutex_unlock(&zol->lock);
207 198
208 if (a != b) 199 if (a != b)
209 return (0); 200 return 0;
210 201
211 if ((a == 0xcf) || (a == 0xdf) /* I found this out by playing */ 202 /* I found this out by playing with a binary scanner on the card io */
212 || (a == 0xef)) /* with a binary scanner on the card io */ 203 return a == 0xcf || a == 0xdf || a == 0xef;
213 return (1);
214 return (0);
215} 204}
216 205
217static int zol_is_stereo (struct zol_device *dev) 206static int zol_is_stereo(struct zoltrix *zol)
218{ 207{
219 int x1, x2; 208 int x1, x2;
220 209
221 mutex_lock(&dev->lock); 210 mutex_lock(&zol->lock);
222 211
223 outb(0x00, io); 212 outb(0x00, zol->io);
224 outb(dev->curvol, io); 213 outb(zol->curvol, zol->io);
225 msleep(20); 214 msleep(20);
226 215
227 x1 = inb(io); 216 x1 = inb(zol->io);
228 msleep(10); 217 msleep(10);
229 x2 = inb(io); 218 x2 = inb(zol->io);
230 219
231 mutex_unlock(&dev->lock); 220 mutex_unlock(&zol->lock);
232 221
233 if ((x1 == x2) && (x1 == 0xcf)) 222 return x1 == x2 && x1 == 0xcf;
234 return 1;
235 return 0;
236} 223}
237 224
238static int vidioc_querycap(struct file *file, void *priv, 225static int vidioc_querycap(struct file *file, void *priv,
@@ -240,59 +227,54 @@ static int vidioc_querycap(struct file *file, void *priv,
240{ 227{
241 strlcpy(v->driver, "radio-zoltrix", sizeof(v->driver)); 228 strlcpy(v->driver, "radio-zoltrix", sizeof(v->driver));
242 strlcpy(v->card, "Zoltrix Radio", sizeof(v->card)); 229 strlcpy(v->card, "Zoltrix Radio", sizeof(v->card));
243 sprintf(v->bus_info, "ISA"); 230 strlcpy(v->bus_info, "ISA", sizeof(v->bus_info));
244 v->version = RADIO_VERSION; 231 v->version = RADIO_VERSION;
245 v->capabilities = V4L2_CAP_TUNER; 232 v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
246 return 0; 233 return 0;
247} 234}
248 235
249static int vidioc_g_tuner(struct file *file, void *priv, 236static int vidioc_g_tuner(struct file *file, void *priv,
250 struct v4l2_tuner *v) 237 struct v4l2_tuner *v)
251{ 238{
252 struct zol_device *zol = video_drvdata(file); 239 struct zoltrix *zol = video_drvdata(file);
253 240
254 if (v->index > 0) 241 if (v->index > 0)
255 return -EINVAL; 242 return -EINVAL;
256 243
257 strcpy(v->name, "FM"); 244 strlcpy(v->name, "FM", sizeof(v->name));
258 v->type = V4L2_TUNER_RADIO; 245 v->type = V4L2_TUNER_RADIO;
259 v->rangelow = (88*16000); 246 v->rangelow = 88 * 16000;
260 v->rangehigh = (108*16000); 247 v->rangehigh = 108 * 16000;
261 v->rxsubchans = V4L2_TUNER_SUB_MONO|V4L2_TUNER_SUB_STEREO; 248 v->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO;
262 v->capability = V4L2_TUNER_CAP_LOW; 249 v->capability = V4L2_TUNER_CAP_LOW;
263 if (zol_is_stereo(zol)) 250 if (zol_is_stereo(zol))
264 v->audmode = V4L2_TUNER_MODE_STEREO; 251 v->audmode = V4L2_TUNER_MODE_STEREO;
265 else 252 else
266 v->audmode = V4L2_TUNER_MODE_MONO; 253 v->audmode = V4L2_TUNER_MODE_MONO;
267 v->signal = 0xFFFF*zol_getsigstr(zol); 254 v->signal = 0xFFFF * zol_getsigstr(zol);
268 return 0; 255 return 0;
269} 256}
270 257
271static int vidioc_s_tuner(struct file *file, void *priv, 258static int vidioc_s_tuner(struct file *file, void *priv,
272 struct v4l2_tuner *v) 259 struct v4l2_tuner *v)
273{ 260{
274 if (v->index > 0) 261 return v->index ? -EINVAL : 0;
275 return -EINVAL;
276 return 0;
277} 262}
278 263
279static int vidioc_s_frequency(struct file *file, void *priv, 264static int vidioc_s_frequency(struct file *file, void *priv,
280 struct v4l2_frequency *f) 265 struct v4l2_frequency *f)
281{ 266{
282 struct zol_device *zol = video_drvdata(file); 267 struct zoltrix *zol = video_drvdata(file);
283 268
284 zol->curfreq = f->frequency; 269 if (zol_setfreq(zol, f->frequency) != 0)
285 if (zol_setfreq(zol, zol->curfreq) != 0) {
286 printk(KERN_WARNING "zoltrix: Set frequency failed.\n");
287 return -EINVAL; 270 return -EINVAL;
288 }
289 return 0; 271 return 0;
290} 272}
291 273
292static int vidioc_g_frequency(struct file *file, void *priv, 274static int vidioc_g_frequency(struct file *file, void *priv,
293 struct v4l2_frequency *f) 275 struct v4l2_frequency *f)
294{ 276{
295 struct zol_device *zol = video_drvdata(file); 277 struct zoltrix *zol = video_drvdata(file);
296 278
297 f->type = V4L2_TUNER_RADIO; 279 f->type = V4L2_TUNER_RADIO;
298 f->frequency = zol->curfreq; 280 f->frequency = zol->curfreq;
@@ -302,14 +284,11 @@ static int vidioc_g_frequency(struct file *file, void *priv,
302static int vidioc_queryctrl(struct file *file, void *priv, 284static int vidioc_queryctrl(struct file *file, void *priv,
303 struct v4l2_queryctrl *qc) 285 struct v4l2_queryctrl *qc)
304{ 286{
305 int i; 287 switch (qc->id) {
306 288 case V4L2_CID_AUDIO_MUTE:
307 for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) { 289 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
308 if (qc->id && qc->id == radio_qctrl[i].id) { 290 case V4L2_CID_AUDIO_VOLUME:
309 memcpy(qc, &(radio_qctrl[i]), 291 return v4l2_ctrl_query_fill(qc, 0, 65535, 4096, 65535);
310 sizeof(*qc));
311 return 0;
312 }
313 } 292 }
314 return -EINVAL; 293 return -EINVAL;
315} 294}
@@ -317,7 +296,7 @@ static int vidioc_queryctrl(struct file *file, void *priv,
317static int vidioc_g_ctrl(struct file *file, void *priv, 296static int vidioc_g_ctrl(struct file *file, void *priv,
318 struct v4l2_control *ctrl) 297 struct v4l2_control *ctrl)
319{ 298{
320 struct zol_device *zol = video_drvdata(file); 299 struct zoltrix *zol = video_drvdata(file);
321 300
322 switch (ctrl->id) { 301 switch (ctrl->id) {
323 case V4L2_CID_AUDIO_MUTE: 302 case V4L2_CID_AUDIO_MUTE:
@@ -333,7 +312,7 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
333static int vidioc_s_ctrl(struct file *file, void *priv, 312static int vidioc_s_ctrl(struct file *file, void *priv,
334 struct v4l2_control *ctrl) 313 struct v4l2_control *ctrl)
335{ 314{
336 struct zol_device *zol = video_drvdata(file); 315 struct zoltrix *zol = video_drvdata(file);
337 316
338 switch (ctrl->id) { 317 switch (ctrl->id) {
339 case V4L2_CID_AUDIO_MUTE: 318 case V4L2_CID_AUDIO_MUTE:
@@ -341,43 +320,30 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
341 zol_mute(zol); 320 zol_mute(zol);
342 else { 321 else {
343 zol_unmute(zol); 322 zol_unmute(zol);
344 zol_setvol(zol,zol->curvol); 323 zol_setvol(zol, zol->curvol);
345 } 324 }
346 return 0; 325 return 0;
347 case V4L2_CID_AUDIO_VOLUME: 326 case V4L2_CID_AUDIO_VOLUME:
348 zol_setvol(zol,ctrl->value/4096); 327 zol_setvol(zol, ctrl->value / 4096);
349 return 0; 328 return 0;
350 } 329 }
351 zol->stereo = 1; 330 zol->stereo = 1;
352 if (zol_setfreq(zol, zol->curfreq) != 0) { 331 if (zol_setfreq(zol, zol->curfreq) != 0)
353 printk(KERN_WARNING "zoltrix: Set frequency failed.\n");
354 return -EINVAL; 332 return -EINVAL;
355 }
356#if 0 333#if 0
357/* FIXME: Implement stereo/mono switch on V4L2 */ 334/* FIXME: Implement stereo/mono switch on V4L2 */
358 if (v->mode & VIDEO_SOUND_STEREO) { 335 if (v->mode & VIDEO_SOUND_STEREO) {
359 zol->stereo = 1; 336 zol->stereo = 1;
360 zol_setfreq(zol, zol->curfreq); 337 zol_setfreq(zol, zol->curfreq);
361 } 338 }
362 if (v->mode & VIDEO_SOUND_MONO) { 339 if (v->mode & VIDEO_SOUND_MONO) {
363 zol->stereo = 0; 340 zol->stereo = 0;
364 zol_setfreq(zol, zol->curfreq); 341 zol_setfreq(zol, zol->curfreq);
365 } 342 }
366#endif 343#endif
367 return -EINVAL; 344 return -EINVAL;
368} 345}
369 346
370static int vidioc_g_audio(struct file *file, void *priv,
371 struct v4l2_audio *a)
372{
373 if (a->index > 1)
374 return -EINVAL;
375
376 strcpy(a->name, "Radio");
377 a->capability = V4L2_AUDCAP_STEREO;
378 return 0;
379}
380
381static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i) 347static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
382{ 348{
383 *i = 0; 349 *i = 0;
@@ -386,37 +352,39 @@ static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
386 352
387static int vidioc_s_input(struct file *filp, void *priv, unsigned int i) 353static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
388{ 354{
389 if (i != 0) 355 return i ? -EINVAL : 0;
390 return -EINVAL;
391 return 0;
392} 356}
393 357
394static int vidioc_s_audio(struct file *file, void *priv, 358static int vidioc_g_audio(struct file *file, void *priv,
395 struct v4l2_audio *a) 359 struct v4l2_audio *a)
396{ 360{
397 if (a->index != 0) 361 a->index = 0;
398 return -EINVAL; 362 strlcpy(a->name, "Radio", sizeof(a->name));
363 a->capability = V4L2_AUDCAP_STEREO;
399 return 0; 364 return 0;
400} 365}
401 366
402static struct zol_device zoltrix_unit; 367static int vidioc_s_audio(struct file *file, void *priv,
368 struct v4l2_audio *a)
369{
370 return a->index ? -EINVAL : 0;
371}
403 372
404static int zoltrix_exclusive_open(struct file *file) 373static int zoltrix_open(struct file *file)
405{ 374{
406 return test_and_set_bit(0, &zoltrix_unit.in_use) ? -EBUSY : 0; 375 return 0;
407} 376}
408 377
409static int zoltrix_exclusive_release(struct file *file) 378static int zoltrix_release(struct file *file)
410{ 379{
411 clear_bit(0, &zoltrix_unit.in_use);
412 return 0; 380 return 0;
413} 381}
414 382
415static const struct v4l2_file_operations zoltrix_fops = 383static const struct v4l2_file_operations zoltrix_fops =
416{ 384{
417 .owner = THIS_MODULE, 385 .owner = THIS_MODULE,
418 .open = zoltrix_exclusive_open, 386 .open = zoltrix_open,
419 .release = zoltrix_exclusive_release, 387 .release = zoltrix_release,
420 .ioctl = video_ioctl2, 388 .ioctl = video_ioctl2,
421}; 389};
422 390
@@ -435,67 +403,75 @@ static const struct v4l2_ioctl_ops zoltrix_ioctl_ops = {
435 .vidioc_s_ctrl = vidioc_s_ctrl, 403 .vidioc_s_ctrl = vidioc_s_ctrl,
436}; 404};
437 405
438static struct video_device zoltrix_radio = {
439 .name = "Zoltrix Radio Plus",
440 .fops = &zoltrix_fops,
441 .ioctl_ops = &zoltrix_ioctl_ops,
442 .release = video_device_release_empty,
443};
444
445static int __init zoltrix_init(void) 406static int __init zoltrix_init(void)
446{ 407{
447 if (io == -1) { 408 struct zoltrix *zol = &zoltrix_card;
448 printk(KERN_ERR "You must set an I/O address with io=0x???\n"); 409 struct v4l2_device *v4l2_dev = &zol->v4l2_dev;
410 int res;
411
412 strlcpy(v4l2_dev->name, "zoltrix", sizeof(v4l2_dev->name));
413 zol->io = io;
414 if (zol->io == -1) {
415 v4l2_err(v4l2_dev, "You must set an I/O address with io=0x20c or 0x30c\n");
449 return -EINVAL; 416 return -EINVAL;
450 } 417 }
451 if ((io != 0x20c) && (io != 0x30c)) { 418 if (zol->io != 0x20c && zol->io != 0x30c) {
452 printk(KERN_ERR "zoltrix: invalid port, try 0x20c or 0x30c\n"); 419 v4l2_err(v4l2_dev, "invalid port, try 0x20c or 0x30c\n");
453 return -ENXIO; 420 return -ENXIO;
454 } 421 }
455 422
456 video_set_drvdata(&zoltrix_radio, &zoltrix_unit); 423 if (!request_region(zol->io, 2, "zoltrix")) {
457 if (!request_region(io, 2, "zoltrix")) { 424 v4l2_err(v4l2_dev, "port 0x%x already in use\n", zol->io);
458 printk(KERN_ERR "zoltrix: port 0x%x already in use\n", io);
459 return -EBUSY; 425 return -EBUSY;
460 } 426 }
461 427
462 if (video_register_device(&zoltrix_radio, VFL_TYPE_RADIO, radio_nr) < 0) { 428 res = v4l2_device_register(NULL, v4l2_dev);
463 release_region(io, 2); 429 if (res < 0) {
430 release_region(zol->io, 2);
431 v4l2_err(v4l2_dev, "Could not register v4l2_device\n");
432 return res;
433 }
434
435 strlcpy(zol->vdev.name, v4l2_dev->name, sizeof(zol->vdev.name));
436 zol->vdev.v4l2_dev = v4l2_dev;
437 zol->vdev.fops = &zoltrix_fops;
438 zol->vdev.ioctl_ops = &zoltrix_ioctl_ops;
439 zol->vdev.release = video_device_release_empty;
440 video_set_drvdata(&zol->vdev, zol);
441
442 if (video_register_device(&zol->vdev, VFL_TYPE_RADIO, radio_nr) < 0) {
443 v4l2_device_unregister(v4l2_dev);
444 release_region(zol->io, 2);
464 return -EINVAL; 445 return -EINVAL;
465 } 446 }
466 printk(KERN_INFO "Zoltrix Radio Plus card driver.\n"); 447 v4l2_info(v4l2_dev, "Zoltrix Radio Plus card driver.\n");
467 448
468 mutex_init(&zoltrix_unit.lock); 449 mutex_init(&zol->lock);
469 450
470 /* mute card - prevents noisy bootups */ 451 /* mute card - prevents noisy bootups */
471 452
472 /* this ensures that the volume is all the way down */ 453 /* this ensures that the volume is all the way down */
473 454
474 outb(0, io); 455 outb(0, zol->io);
475 outb(0, io); 456 outb(0, zol->io);
476 msleep(20); 457 msleep(20);
477 inb(io + 3); 458 inb(zol->io + 3);
478 459
479 zoltrix_unit.curvol = 0; 460 zol->curvol = 0;
480 zoltrix_unit.stereo = 1; 461 zol->stereo = 1;
481 462
482 return 0; 463 return 0;
483} 464}
484 465
485MODULE_AUTHOR("C.van Schaik"); 466static void __exit zoltrix_exit(void)
486MODULE_DESCRIPTION("A driver for the Zoltrix Radio Plus.");
487MODULE_LICENSE("GPL");
488
489module_param(io, int, 0);
490MODULE_PARM_DESC(io, "I/O address of the Zoltrix Radio Plus (0x20c or 0x30c)");
491module_param(radio_nr, int, 0);
492
493static void __exit zoltrix_cleanup_module(void)
494{ 467{
495 video_unregister_device(&zoltrix_radio); 468 struct zoltrix *zol = &zoltrix_card;
496 release_region(io, 2); 469
470 video_unregister_device(&zol->vdev);
471 v4l2_device_unregister(&zol->v4l2_dev);
472 release_region(zol->io, 2);
497} 473}
498 474
499module_init(zoltrix_init); 475module_init(zoltrix_init);
500module_exit(zoltrix_cleanup_module); 476module_exit(zoltrix_exit);
501 477
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index 19cf3b8f67c4..76bad5819592 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -249,11 +249,25 @@ config VIDEO_VP27SMPX
249 To compile this driver as a module, choose M here: the 249 To compile this driver as a module, choose M here: the
250 module will be called vp27smpx. 250 module will be called vp27smpx.
251 251
252comment "RDS decoders"
253
254config VIDEO_SAA6588
255 tristate "SAA6588 Radio Chip RDS decoder support"
256 depends on VIDEO_V4L2 && I2C
257
258 help
259 Support for this Radio Data System (RDS) decoder. This allows
260 seeing radio station identification transmitted using this
261 standard.
262
263 To compile this driver as a module, choose M here: the
264 module will be called saa6588.
265
252comment "Video decoders" 266comment "Video decoders"
253 267
254config VIDEO_BT819 268config VIDEO_BT819
255 tristate "BT819A VideoStream decoder" 269 tristate "BT819A VideoStream decoder"
256 depends on VIDEO_V4L1 && I2C 270 depends on VIDEO_V4L2 && I2C
257 ---help--- 271 ---help---
258 Support for BT819A video decoder. 272 Support for BT819A video decoder.
259 273
@@ -262,7 +276,7 @@ config VIDEO_BT819
262 276
263config VIDEO_BT856 277config VIDEO_BT856
264 tristate "BT856 VideoStream decoder" 278 tristate "BT856 VideoStream decoder"
265 depends on VIDEO_V4L1 && I2C 279 depends on VIDEO_V4L2 && I2C
266 ---help--- 280 ---help---
267 Support for BT856 video decoder. 281 Support for BT856 video decoder.
268 282
@@ -271,7 +285,7 @@ config VIDEO_BT856
271 285
272config VIDEO_BT866 286config VIDEO_BT866
273 tristate "BT866 VideoStream decoder" 287 tristate "BT866 VideoStream decoder"
274 depends on VIDEO_V4L1 && I2C 288 depends on VIDEO_V4L2 && I2C
275 ---help--- 289 ---help---
276 Support for BT866 video decoder. 290 Support for BT866 video decoder.
277 291
@@ -280,7 +294,7 @@ config VIDEO_BT866
280 294
281config VIDEO_KS0127 295config VIDEO_KS0127
282 tristate "KS0127 video decoder" 296 tristate "KS0127 video decoder"
283 depends on VIDEO_V4L1 && I2C 297 depends on VIDEO_V4L2 && I2C
284 ---help--- 298 ---help---
285 Support for KS0127 video decoder. 299 Support for KS0127 video decoder.
286 300
@@ -307,38 +321,18 @@ config VIDEO_TCM825X
307 321
308config VIDEO_SAA7110 322config VIDEO_SAA7110
309 tristate "Philips SAA7110 video decoder" 323 tristate "Philips SAA7110 video decoder"
310 depends on VIDEO_V4L1 && I2C 324 depends on VIDEO_V4L2 && I2C
311 ---help--- 325 ---help---
312 Support for the Philips SAA7110 video decoders. 326 Support for the Philips SAA7110 video decoders.
313 327
314 To compile this driver as a module, choose M here: the 328 To compile this driver as a module, choose M here: the
315 module will be called saa7110. 329 module will be called saa7110.
316 330
317config VIDEO_SAA7111
318 tristate "Philips SAA7111 video decoder"
319 depends on VIDEO_V4L1 && I2C
320 ---help---
321 Support for the Philips SAA711 video decoder.
322
323 To compile this driver as a module, choose M here: the
324 module will be called saa7111.
325
326config VIDEO_SAA7114
327 tristate "Philips SAA7114 video decoder"
328 depends on VIDEO_V4L1 && I2C
329 ---help---
330 Support for the Philips SAA7114 video decoder. This driver
331 is used only on Zoran driver and should be moved soon to
332 SAA711x module.
333
334 To compile this driver as a module, choose M here: the
335 module will be called saa7114.
336
337config VIDEO_SAA711X 331config VIDEO_SAA711X
338 tristate "Philips SAA7113/4/5 video decoders" 332 tristate "Philips SAA7111/3/4/5 video decoders"
339 depends on VIDEO_V4L2 && I2C 333 depends on VIDEO_V4L2 && I2C
340 ---help--- 334 ---help---
341 Support for the Philips SAA7113/4/5 video decoders. 335 Support for the Philips SAA7111/3/4/5 video decoders.
342 336
343 To compile this driver as a module, choose M here: the 337 To compile this driver as a module, choose M here: the
344 module will be called saa7115. 338 module will be called saa7115.
@@ -383,7 +377,7 @@ config VIDEO_TVP5150
383 377
384config VIDEO_VPX3220 378config VIDEO_VPX3220
385 tristate "vpx3220a, vpx3216b & vpx3214c video decoders" 379 tristate "vpx3220a, vpx3216b & vpx3214c video decoders"
386 depends on VIDEO_V4L1 && I2C 380 depends on VIDEO_V4L2 && I2C
387 ---help--- 381 ---help---
388 Support for VPX322x video decoders. 382 Support for VPX322x video decoders.
389 383
@@ -421,7 +415,7 @@ config VIDEO_SAA7127
421 415
422config VIDEO_SAA7185 416config VIDEO_SAA7185
423 tristate "Philips SAA7185 video encoder" 417 tristate "Philips SAA7185 video encoder"
424 depends on VIDEO_V4L1 && I2C 418 depends on VIDEO_V4L2 && I2C
425 ---help--- 419 ---help---
426 Support for the Philips SAA7185 video encoder. 420 Support for the Philips SAA7185 video encoder.
427 421
@@ -430,7 +424,7 @@ config VIDEO_SAA7185
430 424
431config VIDEO_ADV7170 425config VIDEO_ADV7170
432 tristate "Analog Devices ADV7170 video encoder" 426 tristate "Analog Devices ADV7170 video encoder"
433 depends on VIDEO_V4L1 && I2C 427 depends on VIDEO_V4L2 && I2C
434 ---help--- 428 ---help---
435 Support for the Analog Devices ADV7170 video encoder driver 429 Support for the Analog Devices ADV7170 video encoder driver
436 430
@@ -439,7 +433,7 @@ config VIDEO_ADV7170
439 433
440config VIDEO_ADV7175 434config VIDEO_ADV7175
441 tristate "Analog Devices ADV7175 video encoder" 435 tristate "Analog Devices ADV7175 video encoder"
442 depends on VIDEO_V4L1 && I2C 436 depends on VIDEO_V4L2 && I2C
443 ---help--- 437 ---help---
444 Support for the Analog Devices ADV7175 video encoder driver 438 Support for the Analog Devices ADV7175 video encoder driver
445 439
@@ -487,18 +481,6 @@ config VIDEO_VIVI
487 481
488source "drivers/media/video/bt8xx/Kconfig" 482source "drivers/media/video/bt8xx/Kconfig"
489 483
490config VIDEO_SAA6588
491 tristate "SAA6588 Radio Chip RDS decoder support on BT848 cards"
492 depends on I2C && VIDEO_BT848
493
494 help
495 Support for Radio Data System (RDS) decoder. This allows seeing
496 radio station identification transmitted using this standard.
497 Currently, it works only with bt8x8 chips.
498
499 To compile this driver as a module, choose M here: the
500 module will be called saa6588.
501
502config VIDEO_PMS 484config VIDEO_PMS
503 tristate "Mediavision Pro Movie Studio Video For Linux" 485 tristate "Mediavision Pro Movie Studio Video For Linux"
504 depends on ISA && VIDEO_V4L1 486 depends on ISA && VIDEO_V4L1
@@ -602,7 +584,6 @@ config VIDEO_SAA5249
602config VIDEO_VINO 584config VIDEO_VINO
603 tristate "SGI Vino Video For Linux (EXPERIMENTAL)" 585 tristate "SGI Vino Video For Linux (EXPERIMENTAL)"
604 depends on I2C && SGI_IP22 && EXPERIMENTAL && VIDEO_V4L2 586 depends on I2C && SGI_IP22 && EXPERIMENTAL && VIDEO_V4L2
605 select I2C_ALGO_SGI
606 select VIDEO_SAA7191 if VIDEO_HELPER_CHIPS_AUTO 587 select VIDEO_SAA7191 if VIDEO_HELPER_CHIPS_AUTO
607 help 588 help
608 Say Y here to build in support for the Vino video input system found 589 Say Y here to build in support for the Vino video input system found
@@ -639,7 +620,7 @@ config VIDEO_MXB
639 depends on PCI && VIDEO_V4L1 && I2C 620 depends on PCI && VIDEO_V4L1 && I2C
640 select VIDEO_SAA7146_VV 621 select VIDEO_SAA7146_VV
641 select VIDEO_TUNER 622 select VIDEO_TUNER
642 select VIDEO_SAA7115 if VIDEO_HELPER_CHIPS_AUTO 623 select VIDEO_SAA711X if VIDEO_HELPER_CHIPS_AUTO
643 select VIDEO_TDA9840 if VIDEO_HELPER_CHIPS_AUTO 624 select VIDEO_TDA9840 if VIDEO_HELPER_CHIPS_AUTO
644 select VIDEO_TEA6415C if VIDEO_HELPER_CHIPS_AUTO 625 select VIDEO_TEA6415C if VIDEO_HELPER_CHIPS_AUTO
645 select VIDEO_TEA6420 if VIDEO_HELPER_CHIPS_AUTO 626 select VIDEO_TEA6420 if VIDEO_HELPER_CHIPS_AUTO
@@ -728,13 +709,6 @@ config SOC_CAMERA_MT9M001
728 This driver supports MT9M001 cameras from Micron, monochrome 709 This driver supports MT9M001 cameras from Micron, monochrome
729 and colour models. 710 and colour models.
730 711
731config MT9M001_PCA9536_SWITCH
732 bool "pca9536 datawidth switch for mt9m001"
733 depends on SOC_CAMERA_MT9M001 && GENERIC_GPIO
734 help
735 Select this if your MT9M001 camera uses a PCA9536 I2C GPIO
736 extender to switch between 8 and 10 bit datawidth modes
737
738config SOC_CAMERA_MT9M111 712config SOC_CAMERA_MT9M111
739 tristate "mt9m111 and mt9m112 support" 713 tristate "mt9m111 and mt9m112 support"
740 depends on SOC_CAMERA && I2C 714 depends on SOC_CAMERA && I2C
@@ -754,13 +728,6 @@ config SOC_CAMERA_MT9V022
754 help 728 help
755 This driver supports MT9V022 cameras from Micron 729 This driver supports MT9V022 cameras from Micron
756 730
757config MT9V022_PCA9536_SWITCH
758 bool "pca9536 datawidth switch for mt9v022"
759 depends on SOC_CAMERA_MT9V022 && GENERIC_GPIO
760 help
761 Select this if your MT9V022 camera uses a PCA9536 I2C GPIO
762 extender to switch between 8 and 10 bit datawidth modes
763
764config SOC_CAMERA_TW9910 731config SOC_CAMERA_TW9910
765 tristate "tw9910 support" 732 tristate "tw9910 support"
766 depends on SOC_CAMERA && I2C 733 depends on SOC_CAMERA && I2C
@@ -779,6 +746,13 @@ config SOC_CAMERA_OV772X
779 help 746 help
780 This is a ov772x camera driver 747 This is a ov772x camera driver
781 748
749config VIDEO_MX3
750 tristate "i.MX3x Camera Sensor Interface driver"
751 depends on VIDEO_DEV && MX3_IPU && SOC_CAMERA
752 select VIDEOBUF_DMA_CONTIG
753 ---help---
754 This is a v4l2 driver for the i.MX3x Camera Sensor Interface
755
782config VIDEO_PXA27x 756config VIDEO_PXA27x
783 tristate "PXA27x Quick Capture Interface driver" 757 tristate "PXA27x Quick Capture Interface driver"
784 depends on VIDEO_DEV && PXA27x && SOC_CAMERA 758 depends on VIDEO_DEV && PXA27x && SOC_CAMERA
@@ -817,6 +791,8 @@ source "drivers/media/video/gspca/Kconfig"
817 791
818source "drivers/media/video/pvrusb2/Kconfig" 792source "drivers/media/video/pvrusb2/Kconfig"
819 793
794source "drivers/media/video/hdpvr/Kconfig"
795
820source "drivers/media/video/em28xx/Kconfig" 796source "drivers/media/video/em28xx/Kconfig"
821 797
822source "drivers/media/video/usbvision/Kconfig" 798source "drivers/media/video/usbvision/Kconfig"
diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile
index 72f6d03d2d8f..b9046744463b 100644
--- a/drivers/media/video/Makefile
+++ b/drivers/media/video/Makefile
@@ -30,7 +30,6 @@ obj-$(CONFIG_VIDEO_IR_I2C) += ir-kbd-i2c.o
30obj-$(CONFIG_VIDEO_TVAUDIO) += tvaudio.o 30obj-$(CONFIG_VIDEO_TVAUDIO) += tvaudio.o
31obj-$(CONFIG_VIDEO_TDA7432) += tda7432.o 31obj-$(CONFIG_VIDEO_TDA7432) += tda7432.o
32obj-$(CONFIG_VIDEO_TDA9875) += tda9875.o 32obj-$(CONFIG_VIDEO_TDA9875) += tda9875.o
33obj-$(CONFIG_SOUND_TVMIXER) += tvmixer.o
34 33
35obj-$(CONFIG_VIDEO_SAA6588) += saa6588.o 34obj-$(CONFIG_VIDEO_SAA6588) += saa6588.o
36obj-$(CONFIG_VIDEO_SAA5246A) += saa5246a.o 35obj-$(CONFIG_VIDEO_SAA5246A) += saa5246a.o
@@ -43,8 +42,6 @@ obj-$(CONFIG_VIDEO_TDA9840) += tda9840.o
43obj-$(CONFIG_VIDEO_TEA6415C) += tea6415c.o 42obj-$(CONFIG_VIDEO_TEA6415C) += tea6415c.o
44obj-$(CONFIG_VIDEO_TEA6420) += tea6420.o 43obj-$(CONFIG_VIDEO_TEA6420) += tea6420.o
45obj-$(CONFIG_VIDEO_SAA7110) += saa7110.o 44obj-$(CONFIG_VIDEO_SAA7110) += saa7110.o
46obj-$(CONFIG_VIDEO_SAA7111) += saa7111.o
47obj-$(CONFIG_VIDEO_SAA7114) += saa7114.o
48obj-$(CONFIG_VIDEO_SAA711X) += saa7115.o 45obj-$(CONFIG_VIDEO_SAA711X) += saa7115.o
49obj-$(CONFIG_VIDEO_SAA717X) += saa717x.o 46obj-$(CONFIG_VIDEO_SAA717X) += saa717x.o
50obj-$(CONFIG_VIDEO_SAA7127) += saa7127.o 47obj-$(CONFIG_VIDEO_SAA7127) += saa7127.o
@@ -122,6 +119,8 @@ obj-$(CONFIG_USB_PWC) += pwc/
122obj-$(CONFIG_USB_ZC0301) += zc0301/ 119obj-$(CONFIG_USB_ZC0301) += zc0301/
123obj-$(CONFIG_USB_GSPCA) += gspca/ 120obj-$(CONFIG_USB_GSPCA) += gspca/
124 121
122obj-$(CONFIG_VIDEO_HDPVR) += hdpvr/
123
125obj-$(CONFIG_USB_IBMCAM) += usbvideo/ 124obj-$(CONFIG_USB_IBMCAM) += usbvideo/
126obj-$(CONFIG_USB_KONICAWC) += usbvideo/ 125obj-$(CONFIG_USB_KONICAWC) += usbvideo/
127obj-$(CONFIG_USB_VICAM) += usbvideo/ 126obj-$(CONFIG_USB_VICAM) += usbvideo/
@@ -134,10 +133,11 @@ obj-$(CONFIG_VIDEO_CX18) += cx18/
134obj-$(CONFIG_VIDEO_VIVI) += vivi.o 133obj-$(CONFIG_VIDEO_VIVI) += vivi.o
135obj-$(CONFIG_VIDEO_CX23885) += cx23885/ 134obj-$(CONFIG_VIDEO_CX23885) += cx23885/
136 135
137obj-$(CONFIG_VIDEO_PXA27x) += pxa_camera.o 136obj-$(CONFIG_VIDEO_MX3) += mx3_camera.o
137obj-$(CONFIG_VIDEO_PXA27x) += pxa_camera.o
138obj-$(CONFIG_VIDEO_SH_MOBILE_CEU) += sh_mobile_ceu_camera.o 138obj-$(CONFIG_VIDEO_SH_MOBILE_CEU) += sh_mobile_ceu_camera.o
139obj-$(CONFIG_VIDEO_OMAP2) += omap2cam.o 139obj-$(CONFIG_VIDEO_OMAP2) += omap2cam.o
140obj-$(CONFIG_SOC_CAMERA) += soc_camera.o 140obj-$(CONFIG_SOC_CAMERA) += soc_camera.o
141obj-$(CONFIG_SOC_CAMERA_MT9M001) += mt9m001.o 141obj-$(CONFIG_SOC_CAMERA_MT9M001) += mt9m001.o
142obj-$(CONFIG_SOC_CAMERA_MT9M111) += mt9m111.o 142obj-$(CONFIG_SOC_CAMERA_MT9M111) += mt9m111.o
143obj-$(CONFIG_SOC_CAMERA_MT9T031) += mt9t031.o 143obj-$(CONFIG_SOC_CAMERA_MT9T031) += mt9t031.o
diff --git a/drivers/media/video/adv7170.c b/drivers/media/video/adv7170.c
index e0eb4f321442..873c30a41bd7 100644
--- a/drivers/media/video/adv7170.c
+++ b/drivers/media/video/adv7170.c
@@ -34,15 +34,16 @@
34#include <asm/uaccess.h> 34#include <asm/uaccess.h>
35#include <linux/i2c.h> 35#include <linux/i2c.h>
36#include <linux/i2c-id.h> 36#include <linux/i2c-id.h>
37#include <linux/videodev.h> 37#include <linux/videodev2.h>
38#include <linux/video_encoder.h> 38#include <media/v4l2-device.h>
39#include <media/v4l2-common.h> 39#include <media/v4l2-chip-ident.h>
40#include <media/v4l2-i2c-drv-legacy.h> 40#include <media/v4l2-i2c-drv.h>
41 41
42MODULE_DESCRIPTION("Analog Devices ADV7170 video encoder driver"); 42MODULE_DESCRIPTION("Analog Devices ADV7170 video encoder driver");
43MODULE_AUTHOR("Maxim Yevtyushkin"); 43MODULE_AUTHOR("Maxim Yevtyushkin");
44MODULE_LICENSE("GPL"); 44MODULE_LICENSE("GPL");
45 45
46
46static int debug; 47static int debug;
47module_param(debug, int, 0); 48module_param(debug, int, 0);
48MODULE_PARM_DESC(debug, "Debug level (0-1)"); 49MODULE_PARM_DESC(debug, "Debug level (0-1)");
@@ -50,38 +51,43 @@ MODULE_PARM_DESC(debug, "Debug level (0-1)");
50/* ----------------------------------------------------------------------- */ 51/* ----------------------------------------------------------------------- */
51 52
52struct adv7170 { 53struct adv7170 {
54 struct v4l2_subdev sd;
53 unsigned char reg[128]; 55 unsigned char reg[128];
54 56
55 int norm; 57 v4l2_std_id norm;
56 int input; 58 int input;
57 int enable;
58 int bright;
59 int contrast;
60 int hue;
61 int sat;
62}; 59};
63 60
61static inline struct adv7170 *to_adv7170(struct v4l2_subdev *sd)
62{
63 return container_of(sd, struct adv7170, sd);
64}
65
64static char *inputs[] = { "pass_through", "play_back" }; 66static char *inputs[] = { "pass_through", "play_back" };
65static char *norms[] = { "PAL", "NTSC" };
66 67
67/* ----------------------------------------------------------------------- */ 68/* ----------------------------------------------------------------------- */
68 69
69static inline int adv7170_write(struct i2c_client *client, u8 reg, u8 value) 70static inline int adv7170_write(struct v4l2_subdev *sd, u8 reg, u8 value)
70{ 71{
71 struct adv7170 *encoder = i2c_get_clientdata(client); 72 struct i2c_client *client = v4l2_get_subdevdata(sd);
73 struct adv7170 *encoder = to_adv7170(sd);
72 74
73 encoder->reg[reg] = value; 75 encoder->reg[reg] = value;
74 return i2c_smbus_write_byte_data(client, reg, value); 76 return i2c_smbus_write_byte_data(client, reg, value);
75} 77}
76 78
77static inline int adv7170_read(struct i2c_client *client, u8 reg) 79static inline int adv7170_read(struct v4l2_subdev *sd, u8 reg)
78{ 80{
81 struct i2c_client *client = v4l2_get_subdevdata(sd);
82
79 return i2c_smbus_read_byte_data(client, reg); 83 return i2c_smbus_read_byte_data(client, reg);
80} 84}
81 85
82static int adv7170_write_block(struct i2c_client *client, 86static int adv7170_write_block(struct v4l2_subdev *sd,
83 const u8 *data, unsigned int len) 87 const u8 *data, unsigned int len)
84{ 88{
89 struct i2c_client *client = v4l2_get_subdevdata(sd);
90 struct adv7170 *encoder = to_adv7170(sd);
85 int ret = -1; 91 int ret = -1;
86 u8 reg; 92 u8 reg;
87 93
@@ -89,7 +95,6 @@ static int adv7170_write_block(struct i2c_client *client,
89 * the adapter understands raw I2C */ 95 * the adapter understands raw I2C */
90 if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { 96 if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
91 /* do raw I2C, not smbus compatible */ 97 /* do raw I2C, not smbus compatible */
92 struct adv7170 *encoder = i2c_get_clientdata(client);
93 u8 block_data[32]; 98 u8 block_data[32];
94 int block_len; 99 int block_len;
95 100
@@ -110,7 +115,7 @@ static int adv7170_write_block(struct i2c_client *client,
110 /* do some slow I2C emulation kind of thing */ 115 /* do some slow I2C emulation kind of thing */
111 while (len >= 2) { 116 while (len >= 2) {
112 reg = *data++; 117 reg = *data++;
113 ret = adv7170_write(client, reg, *data++); 118 ret = adv7170_write(sd, reg, *data++);
114 if (ret < 0) 119 if (ret < 0)
115 break; 120 break;
116 len -= 2; 121 len -= 2;
@@ -128,203 +133,161 @@ static int adv7170_write_block(struct i2c_client *client,
128#define TR1PLAY 0x00 133#define TR1PLAY 0x00
129 134
130static const unsigned char init_NTSC[] = { 135static const unsigned char init_NTSC[] = {
131 0x00, 0x10, // MR0 136 0x00, 0x10, /* MR0 */
132 0x01, 0x20, // MR1 137 0x01, 0x20, /* MR1 */
133 0x02, 0x0e, // MR2 RTC control: bits 2 and 1 138 0x02, 0x0e, /* MR2 RTC control: bits 2 and 1 */
134 0x03, 0x80, // MR3 139 0x03, 0x80, /* MR3 */
135 0x04, 0x30, // MR4 140 0x04, 0x30, /* MR4 */
136 0x05, 0x00, // Reserved 141 0x05, 0x00, /* Reserved */
137 0x06, 0x00, // Reserved 142 0x06, 0x00, /* Reserved */
138 0x07, TR0MODE, // TM0 143 0x07, TR0MODE, /* TM0 */
139 0x08, TR1CAPT, // TM1 144 0x08, TR1CAPT, /* TM1 */
140 0x09, 0x16, // Fsc0 145 0x09, 0x16, /* Fsc0 */
141 0x0a, 0x7c, // Fsc1 146 0x0a, 0x7c, /* Fsc1 */
142 0x0b, 0xf0, // Fsc2 147 0x0b, 0xf0, /* Fsc2 */
143 0x0c, 0x21, // Fsc3 148 0x0c, 0x21, /* Fsc3 */
144 0x0d, 0x00, // Subcarrier Phase 149 0x0d, 0x00, /* Subcarrier Phase */
145 0x0e, 0x00, // Closed Capt. Ext 0 150 0x0e, 0x00, /* Closed Capt. Ext 0 */
146 0x0f, 0x00, // Closed Capt. Ext 1 151 0x0f, 0x00, /* Closed Capt. Ext 1 */
147 0x10, 0x00, // Closed Capt. 0 152 0x10, 0x00, /* Closed Capt. 0 */
148 0x11, 0x00, // Closed Capt. 1 153 0x11, 0x00, /* Closed Capt. 1 */
149 0x12, 0x00, // Pedestal Ctl 0 154 0x12, 0x00, /* Pedestal Ctl 0 */
150 0x13, 0x00, // Pedestal Ctl 1 155 0x13, 0x00, /* Pedestal Ctl 1 */
151 0x14, 0x00, // Pedestal Ctl 2 156 0x14, 0x00, /* Pedestal Ctl 2 */
152 0x15, 0x00, // Pedestal Ctl 3 157 0x15, 0x00, /* Pedestal Ctl 3 */
153 0x16, 0x00, // CGMS_WSS_0 158 0x16, 0x00, /* CGMS_WSS_0 */
154 0x17, 0x00, // CGMS_WSS_1 159 0x17, 0x00, /* CGMS_WSS_1 */
155 0x18, 0x00, // CGMS_WSS_2 160 0x18, 0x00, /* CGMS_WSS_2 */
156 0x19, 0x00, // Teletext Ctl 161 0x19, 0x00, /* Teletext Ctl */
157}; 162};
158 163
159static const unsigned char init_PAL[] = { 164static const unsigned char init_PAL[] = {
160 0x00, 0x71, // MR0 165 0x00, 0x71, /* MR0 */
161 0x01, 0x20, // MR1 166 0x01, 0x20, /* MR1 */
162 0x02, 0x0e, // MR2 RTC control: bits 2 and 1 167 0x02, 0x0e, /* MR2 RTC control: bits 2 and 1 */
163 0x03, 0x80, // MR3 168 0x03, 0x80, /* MR3 */
164 0x04, 0x30, // MR4 169 0x04, 0x30, /* MR4 */
165 0x05, 0x00, // Reserved 170 0x05, 0x00, /* Reserved */
166 0x06, 0x00, // Reserved 171 0x06, 0x00, /* Reserved */
167 0x07, TR0MODE, // TM0 172 0x07, TR0MODE, /* TM0 */
168 0x08, TR1CAPT, // TM1 173 0x08, TR1CAPT, /* TM1 */
169 0x09, 0xcb, // Fsc0 174 0x09, 0xcb, /* Fsc0 */
170 0x0a, 0x8a, // Fsc1 175 0x0a, 0x8a, /* Fsc1 */
171 0x0b, 0x09, // Fsc2 176 0x0b, 0x09, /* Fsc2 */
172 0x0c, 0x2a, // Fsc3 177 0x0c, 0x2a, /* Fsc3 */
173 0x0d, 0x00, // Subcarrier Phase 178 0x0d, 0x00, /* Subcarrier Phase */
174 0x0e, 0x00, // Closed Capt. Ext 0 179 0x0e, 0x00, /* Closed Capt. Ext 0 */
175 0x0f, 0x00, // Closed Capt. Ext 1 180 0x0f, 0x00, /* Closed Capt. Ext 1 */
176 0x10, 0x00, // Closed Capt. 0 181 0x10, 0x00, /* Closed Capt. 0 */
177 0x11, 0x00, // Closed Capt. 1 182 0x11, 0x00, /* Closed Capt. 1 */
178 0x12, 0x00, // Pedestal Ctl 0 183 0x12, 0x00, /* Pedestal Ctl 0 */
179 0x13, 0x00, // Pedestal Ctl 1 184 0x13, 0x00, /* Pedestal Ctl 1 */
180 0x14, 0x00, // Pedestal Ctl 2 185 0x14, 0x00, /* Pedestal Ctl 2 */
181 0x15, 0x00, // Pedestal Ctl 3 186 0x15, 0x00, /* Pedestal Ctl 3 */
182 0x16, 0x00, // CGMS_WSS_0 187 0x16, 0x00, /* CGMS_WSS_0 */
183 0x17, 0x00, // CGMS_WSS_1 188 0x17, 0x00, /* CGMS_WSS_1 */
184 0x18, 0x00, // CGMS_WSS_2 189 0x18, 0x00, /* CGMS_WSS_2 */
185 0x19, 0x00, // Teletext Ctl 190 0x19, 0x00, /* Teletext Ctl */
186}; 191};
187 192
188 193
189static int adv7170_command(struct i2c_client *client, unsigned cmd, void *arg) 194static int adv7170_s_std_output(struct v4l2_subdev *sd, v4l2_std_id std)
190{ 195{
191 struct adv7170 *encoder = i2c_get_clientdata(client); 196 struct adv7170 *encoder = to_adv7170(sd);
192 197
193 switch (cmd) { 198 v4l2_dbg(1, debug, sd, "set norm %llx\n", (unsigned long long)std);
194 case 0: 199
195#if 0 200 if (std & V4L2_STD_NTSC) {
196 /* This is just for testing!!! */ 201 adv7170_write_block(sd, init_NTSC, sizeof(init_NTSC));
197 adv7170_write_block(client, init_common, 202 if (encoder->input == 0)
198 sizeof(init_common)); 203 adv7170_write(sd, 0x02, 0x0e); /* Enable genlock */
199 adv7170_write(client, 0x07, TR0MODE | TR0RST); 204 adv7170_write(sd, 0x07, TR0MODE | TR0RST);
200 adv7170_write(client, 0x07, TR0MODE); 205 adv7170_write(sd, 0x07, TR0MODE);
201#endif 206 } else if (std & V4L2_STD_PAL) {
202 break; 207 adv7170_write_block(sd, init_PAL, sizeof(init_PAL));
203 208 if (encoder->input == 0)
204 case ENCODER_GET_CAPABILITIES: 209 adv7170_write(sd, 0x02, 0x0e); /* Enable genlock */
205 { 210 adv7170_write(sd, 0x07, TR0MODE | TR0RST);
206 struct video_encoder_capability *cap = arg; 211 adv7170_write(sd, 0x07, TR0MODE);
207 212 } else {
208 cap->flags = VIDEO_ENCODER_PAL | 213 v4l2_dbg(1, debug, sd, "illegal norm: %llx\n",
209 VIDEO_ENCODER_NTSC; 214 (unsigned long long)std);
210 cap->inputs = 2; 215 return -EINVAL;
211 cap->outputs = 1;
212 break;
213 } 216 }
217 v4l2_dbg(1, debug, sd, "switched to %llx\n", (unsigned long long)std);
218 encoder->norm = std;
219 return 0;
220}
214 221
215 case ENCODER_SET_NORM: 222static int adv7170_s_routing(struct v4l2_subdev *sd, const struct v4l2_routing *route)
216 { 223{
217 int iarg = *(int *) arg; 224 struct adv7170 *encoder = to_adv7170(sd);
218
219 v4l_dbg(1, debug, client, "set norm %d\n", iarg);
220
221 switch (iarg) {
222 case VIDEO_MODE_NTSC:
223 adv7170_write_block(client, init_NTSC,
224 sizeof(init_NTSC));
225 if (encoder->input == 0)
226 adv7170_write(client, 0x02, 0x0e); // Enable genlock
227 adv7170_write(client, 0x07, TR0MODE | TR0RST);
228 adv7170_write(client, 0x07, TR0MODE);
229 break;
230
231 case VIDEO_MODE_PAL:
232 adv7170_write_block(client, init_PAL,
233 sizeof(init_PAL));
234 if (encoder->input == 0)
235 adv7170_write(client, 0x02, 0x0e); // Enable genlock
236 adv7170_write(client, 0x07, TR0MODE | TR0RST);
237 adv7170_write(client, 0x07, TR0MODE);
238 break;
239
240 default:
241 v4l_dbg(1, debug, client, "illegal norm: %d\n", iarg);
242 return -EINVAL;
243 }
244 v4l_dbg(1, debug, client, "switched to %s\n", norms[iarg]);
245 encoder->norm = iarg;
246 break;
247 }
248 225
249 case ENCODER_SET_INPUT: 226 /* RJ: route->input = 0: input is from decoder
250 { 227 route->input = 1: input is from ZR36060
251 int iarg = *(int *) arg; 228 route->input = 2: color bar */
252
253 /* RJ: *iarg = 0: input is from decoder
254 *iarg = 1: input is from ZR36060
255 *iarg = 2: color bar */
256
257 v4l_dbg(1, debug, client, "set input from %s\n",
258 iarg == 0 ? "decoder" : "ZR36060");
259
260 switch (iarg) {
261 case 0:
262 adv7170_write(client, 0x01, 0x20);
263 adv7170_write(client, 0x08, TR1CAPT); /* TR1 */
264 adv7170_write(client, 0x02, 0x0e); // Enable genlock
265 adv7170_write(client, 0x07, TR0MODE | TR0RST);
266 adv7170_write(client, 0x07, TR0MODE);
267 /* udelay(10); */
268 break;
269
270 case 1:
271 adv7170_write(client, 0x01, 0x00);
272 adv7170_write(client, 0x08, TR1PLAY); /* TR1 */
273 adv7170_write(client, 0x02, 0x08);
274 adv7170_write(client, 0x07, TR0MODE | TR0RST);
275 adv7170_write(client, 0x07, TR0MODE);
276 /* udelay(10); */
277 break;
278
279 default:
280 v4l_dbg(1, debug, client, "illegal input: %d\n", iarg);
281 return -EINVAL;
282 }
283 v4l_dbg(1, debug, client, "switched to %s\n", inputs[iarg]);
284 encoder->input = iarg;
285 break;
286 }
287 229
288 case ENCODER_SET_OUTPUT: 230 v4l2_dbg(1, debug, sd, "set input from %s\n",
289 { 231 route->input == 0 ? "decoder" : "ZR36060");
290 int *iarg = arg;
291 232
292 /* not much choice of outputs */ 233 switch (route->input) {
293 if (*iarg != 0) { 234 case 0:
294 return -EINVAL; 235 adv7170_write(sd, 0x01, 0x20);
295 } 236 adv7170_write(sd, 0x08, TR1CAPT); /* TR1 */
237 adv7170_write(sd, 0x02, 0x0e); /* Enable genlock */
238 adv7170_write(sd, 0x07, TR0MODE | TR0RST);
239 adv7170_write(sd, 0x07, TR0MODE);
240 /* udelay(10); */
296 break; 241 break;
297 }
298
299 case ENCODER_ENABLE_OUTPUT:
300 {
301 int *iarg = arg;
302 242
303 encoder->enable = !!*iarg; 243 case 1:
244 adv7170_write(sd, 0x01, 0x00);
245 adv7170_write(sd, 0x08, TR1PLAY); /* TR1 */
246 adv7170_write(sd, 0x02, 0x08);
247 adv7170_write(sd, 0x07, TR0MODE | TR0RST);
248 adv7170_write(sd, 0x07, TR0MODE);
249 /* udelay(10); */
304 break; 250 break;
305 }
306 251
307 default: 252 default:
253 v4l2_dbg(1, debug, sd, "illegal input: %d\n", route->input);
308 return -EINVAL; 254 return -EINVAL;
309 } 255 }
310 256 v4l2_dbg(1, debug, sd, "switched to %s\n", inputs[route->input]);
257 encoder->input = route->input;
311 return 0; 258 return 0;
312} 259}
313 260
261static int adv7170_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
262{
263 struct i2c_client *client = v4l2_get_subdevdata(sd);
264
265 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_ADV7170, 0);
266}
267
314/* ----------------------------------------------------------------------- */ 268/* ----------------------------------------------------------------------- */
315 269
316static unsigned short normal_i2c[] = { 270static const struct v4l2_subdev_core_ops adv7170_core_ops = {
317 0xd4 >> 1, 0xd6 >> 1, /* adv7170 IDs */ 271 .g_chip_ident = adv7170_g_chip_ident,
318 0x54 >> 1, 0x56 >> 1, /* adv7171 IDs */
319 I2C_CLIENT_END
320}; 272};
321 273
322I2C_CLIENT_INSMOD; 274static const struct v4l2_subdev_video_ops adv7170_video_ops = {
275 .s_std_output = adv7170_s_std_output,
276 .s_routing = adv7170_s_routing,
277};
278
279static const struct v4l2_subdev_ops adv7170_ops = {
280 .core = &adv7170_core_ops,
281 .video = &adv7170_video_ops,
282};
283
284/* ----------------------------------------------------------------------- */
323 285
324static int adv7170_probe(struct i2c_client *client, 286static int adv7170_probe(struct i2c_client *client,
325 const struct i2c_device_id *id) 287 const struct i2c_device_id *id)
326{ 288{
327 struct adv7170 *encoder; 289 struct adv7170 *encoder;
290 struct v4l2_subdev *sd;
328 int i; 291 int i;
329 292
330 /* Check if the adapter supports the needed features */ 293 /* Check if the adapter supports the needed features */
@@ -337,26 +300,29 @@ static int adv7170_probe(struct i2c_client *client,
337 encoder = kzalloc(sizeof(struct adv7170), GFP_KERNEL); 300 encoder = kzalloc(sizeof(struct adv7170), GFP_KERNEL);
338 if (encoder == NULL) 301 if (encoder == NULL)
339 return -ENOMEM; 302 return -ENOMEM;
340 encoder->norm = VIDEO_MODE_NTSC; 303 sd = &encoder->sd;
304 v4l2_i2c_subdev_init(sd, client, &adv7170_ops);
305 encoder->norm = V4L2_STD_NTSC;
341 encoder->input = 0; 306 encoder->input = 0;
342 encoder->enable = 1;
343 i2c_set_clientdata(client, encoder);
344 307
345 i = adv7170_write_block(client, init_NTSC, sizeof(init_NTSC)); 308 i = adv7170_write_block(sd, init_NTSC, sizeof(init_NTSC));
346 if (i >= 0) { 309 if (i >= 0) {
347 i = adv7170_write(client, 0x07, TR0MODE | TR0RST); 310 i = adv7170_write(sd, 0x07, TR0MODE | TR0RST);
348 i = adv7170_write(client, 0x07, TR0MODE); 311 i = adv7170_write(sd, 0x07, TR0MODE);
349 i = adv7170_read(client, 0x12); 312 i = adv7170_read(sd, 0x12);
350 v4l_dbg(1, debug, client, "revision %d\n", i & 1); 313 v4l2_dbg(1, debug, sd, "revision %d\n", i & 1);
351 } 314 }
352 if (i < 0) 315 if (i < 0)
353 v4l_dbg(1, debug, client, "init error 0x%x\n", i); 316 v4l2_dbg(1, debug, sd, "init error 0x%x\n", i);
354 return 0; 317 return 0;
355} 318}
356 319
357static int adv7170_remove(struct i2c_client *client) 320static int adv7170_remove(struct i2c_client *client)
358{ 321{
359 kfree(i2c_get_clientdata(client)); 322 struct v4l2_subdev *sd = i2c_get_clientdata(client);
323
324 v4l2_device_unregister_subdev(sd);
325 kfree(to_adv7170(sd));
360 return 0; 326 return 0;
361} 327}
362 328
@@ -371,8 +337,6 @@ MODULE_DEVICE_TABLE(i2c, adv7170_id);
371 337
372static struct v4l2_i2c_driver_data v4l2_i2c_data = { 338static struct v4l2_i2c_driver_data v4l2_i2c_data = {
373 .name = "adv7170", 339 .name = "adv7170",
374 .driverid = I2C_DRIVERID_ADV7170,
375 .command = adv7170_command,
376 .probe = adv7170_probe, 340 .probe = adv7170_probe,
377 .remove = adv7170_remove, 341 .remove = adv7170_remove,
378 .id_table = adv7170_id, 342 .id_table = adv7170_id,
diff --git a/drivers/media/video/adv7175.c b/drivers/media/video/adv7175.c
index 6008e84653f1..ff1210303295 100644
--- a/drivers/media/video/adv7175.c
+++ b/drivers/media/video/adv7175.c
@@ -30,15 +30,19 @@
30#include <asm/uaccess.h> 30#include <asm/uaccess.h>
31#include <linux/i2c.h> 31#include <linux/i2c.h>
32#include <linux/i2c-id.h> 32#include <linux/i2c-id.h>
33#include <linux/videodev.h> 33#include <linux/videodev2.h>
34#include <linux/video_encoder.h> 34#include <media/v4l2-device.h>
35#include <media/v4l2-common.h> 35#include <media/v4l2-chip-ident.h>
36#include <media/v4l2-i2c-drv-legacy.h> 36#include <media/v4l2-i2c-drv.h>
37 37
38MODULE_DESCRIPTION("Analog Devices ADV7175 video encoder driver"); 38MODULE_DESCRIPTION("Analog Devices ADV7175 video encoder driver");
39MODULE_AUTHOR("Dave Perks"); 39MODULE_AUTHOR("Dave Perks");
40MODULE_LICENSE("GPL"); 40MODULE_LICENSE("GPL");
41 41
42#define I2C_ADV7175 0xd4
43#define I2C_ADV7176 0x54
44
45
42static int debug; 46static int debug;
43module_param(debug, int, 0); 47module_param(debug, int, 0);
44MODULE_PARM_DESC(debug, "Debug level (0-1)"); 48MODULE_PARM_DESC(debug, "Debug level (0-1)");
@@ -46,36 +50,38 @@ MODULE_PARM_DESC(debug, "Debug level (0-1)");
46/* ----------------------------------------------------------------------- */ 50/* ----------------------------------------------------------------------- */
47 51
48struct adv7175 { 52struct adv7175 {
49 int norm; 53 struct v4l2_subdev sd;
54 v4l2_std_id norm;
50 int input; 55 int input;
51 int enable;
52 int bright;
53 int contrast;
54 int hue;
55 int sat;
56}; 56};
57 57
58#define I2C_ADV7175 0xd4 58static inline struct adv7175 *to_adv7175(struct v4l2_subdev *sd)
59#define I2C_ADV7176 0x54 59{
60 return container_of(sd, struct adv7175, sd);
61}
60 62
61static char *inputs[] = { "pass_through", "play_back", "color_bar" }; 63static char *inputs[] = { "pass_through", "play_back", "color_bar" };
62static char *norms[] = { "PAL", "NTSC", "SECAM->PAL (may not work!)" };
63 64
64/* ----------------------------------------------------------------------- */ 65/* ----------------------------------------------------------------------- */
65 66
66static inline int adv7175_write(struct i2c_client *client, u8 reg, u8 value) 67static inline int adv7175_write(struct v4l2_subdev *sd, u8 reg, u8 value)
67{ 68{
69 struct i2c_client *client = v4l2_get_subdevdata(sd);
70
68 return i2c_smbus_write_byte_data(client, reg, value); 71 return i2c_smbus_write_byte_data(client, reg, value);
69} 72}
70 73
71static inline int adv7175_read(struct i2c_client *client, u8 reg) 74static inline int adv7175_read(struct v4l2_subdev *sd, u8 reg)
72{ 75{
76 struct i2c_client *client = v4l2_get_subdevdata(sd);
77
73 return i2c_smbus_read_byte_data(client, reg); 78 return i2c_smbus_read_byte_data(client, reg);
74} 79}
75 80
76static int adv7175_write_block(struct i2c_client *client, 81static int adv7175_write_block(struct v4l2_subdev *sd,
77 const u8 *data, unsigned int len) 82 const u8 *data, unsigned int len)
78{ 83{
84 struct i2c_client *client = v4l2_get_subdevdata(sd);
79 int ret = -1; 85 int ret = -1;
80 u8 reg; 86 u8 reg;
81 87
@@ -103,7 +109,7 @@ static int adv7175_write_block(struct i2c_client *client,
103 /* do some slow I2C emulation kind of thing */ 109 /* do some slow I2C emulation kind of thing */
104 while (len >= 2) { 110 while (len >= 2) {
105 reg = *data++; 111 reg = *data++;
106 ret = adv7175_write(client, reg, *data++); 112 ret = adv7175_write(sd, reg, *data++);
107 if (ret < 0) 113 if (ret < 0)
108 break; 114 break;
109 len -= 2; 115 len -= 2;
@@ -113,18 +119,18 @@ static int adv7175_write_block(struct i2c_client *client,
113 return ret; 119 return ret;
114} 120}
115 121
116static void set_subcarrier_freq(struct i2c_client *client, int pass_through) 122static void set_subcarrier_freq(struct v4l2_subdev *sd, int pass_through)
117{ 123{
118 /* for some reason pass_through NTSC needs 124 /* for some reason pass_through NTSC needs
119 * a different sub-carrier freq to remain stable. */ 125 * a different sub-carrier freq to remain stable. */
120 if (pass_through) 126 if (pass_through)
121 adv7175_write(client, 0x02, 0x00); 127 adv7175_write(sd, 0x02, 0x00);
122 else 128 else
123 adv7175_write(client, 0x02, 0x55); 129 adv7175_write(sd, 0x02, 0x55);
124 130
125 adv7175_write(client, 0x03, 0x55); 131 adv7175_write(sd, 0x03, 0x55);
126 adv7175_write(client, 0x04, 0x55); 132 adv7175_write(sd, 0x04, 0x55);
127 adv7175_write(client, 0x05, 0x25); 133 adv7175_write(sd, 0x05, 0x25);
128} 134}
129 135
130/* ----------------------------------------------------------------------- */ 136/* ----------------------------------------------------------------------- */
@@ -184,180 +190,144 @@ static const unsigned char init_ntsc[] = {
184 0x06, 0x1a, /* subc. phase */ 190 0x06, 0x1a, /* subc. phase */
185}; 191};
186 192
187static int adv7175_command(struct i2c_client *client, unsigned cmd, void *arg) 193static int adv7175_init(struct v4l2_subdev *sd, u32 val)
188{ 194{
189 struct adv7175 *encoder = i2c_get_clientdata(client); 195 /* This is just for testing!!! */
196 adv7175_write_block(sd, init_common, sizeof(init_common));
197 adv7175_write(sd, 0x07, TR0MODE | TR0RST);
198 adv7175_write(sd, 0x07, TR0MODE);
199 return 0;
200}
190 201
191 switch (cmd) { 202static int adv7175_s_std_output(struct v4l2_subdev *sd, v4l2_std_id std)
192 case 0: 203{
193 /* This is just for testing!!! */ 204 struct adv7175 *encoder = to_adv7175(sd);
194 adv7175_write_block(client, init_common, 205
195 sizeof(init_common)); 206 if (std & V4L2_STD_NTSC) {
196 adv7175_write(client, 0x07, TR0MODE | TR0RST); 207 adv7175_write_block(sd, init_ntsc, sizeof(init_ntsc));
197 adv7175_write(client, 0x07, TR0MODE); 208 if (encoder->input == 0)
198 break; 209 adv7175_write(sd, 0x0d, 0x4f); /* Enable genlock */
210 adv7175_write(sd, 0x07, TR0MODE | TR0RST);
211 adv7175_write(sd, 0x07, TR0MODE);
212 } else if (std & V4L2_STD_PAL) {
213 adv7175_write_block(sd, init_pal, sizeof(init_pal));
214 if (encoder->input == 0)
215 adv7175_write(sd, 0x0d, 0x4f); /* Enable genlock */
216 adv7175_write(sd, 0x07, TR0MODE | TR0RST);
217 adv7175_write(sd, 0x07, TR0MODE);
218 } else if (std & V4L2_STD_SECAM) {
219 /* This is an attempt to convert
220 * SECAM->PAL (typically it does not work
221 * due to genlock: when decoder is in SECAM
222 * and encoder in in PAL the subcarrier can
223 * not be syncronized with horizontal
224 * quency) */
225 adv7175_write_block(sd, init_pal, sizeof(init_pal));
226 if (encoder->input == 0)
227 adv7175_write(sd, 0x0d, 0x49); /* Disable genlock */
228 adv7175_write(sd, 0x07, TR0MODE | TR0RST);
229 adv7175_write(sd, 0x07, TR0MODE);
230 } else {
231 v4l2_dbg(1, debug, sd, "illegal norm: %llx\n",
232 (unsigned long long)std);
233 return -EINVAL;
234 }
235 v4l2_dbg(1, debug, sd, "switched to %llx\n", (unsigned long long)std);
236 encoder->norm = std;
237 return 0;
238}
199 239
200 case ENCODER_GET_CAPABILITIES: 240static int adv7175_s_routing(struct v4l2_subdev *sd, const struct v4l2_routing *route)
201 { 241{
202 struct video_encoder_capability *cap = arg; 242 struct adv7175 *encoder = to_adv7175(sd);
203 243
204 cap->flags = VIDEO_ENCODER_PAL | 244 /* RJ: route->input = 0: input is from decoder
205 VIDEO_ENCODER_NTSC | 245 route->input = 1: input is from ZR36060
206 VIDEO_ENCODER_SECAM; /* well, hacky */ 246 route->input = 2: color bar */
207 cap->inputs = 2;
208 cap->outputs = 1;
209 break;
210 }
211 247
212 case ENCODER_SET_NORM: 248 switch (route->input) {
213 { 249 case 0:
214 int iarg = *(int *) arg; 250 adv7175_write(sd, 0x01, 0x00);
215 251
216 switch (iarg) { 252 if (encoder->norm & V4L2_STD_NTSC)
217 case VIDEO_MODE_NTSC: 253 set_subcarrier_freq(sd, 1);
218 adv7175_write_block(client, init_ntsc, 254
219 sizeof(init_ntsc)); 255 adv7175_write(sd, 0x0c, TR1CAPT); /* TR1 */
220 if (encoder->input == 0) 256 if (encoder->norm & V4L2_STD_SECAM)
221 adv7175_write(client, 0x0d, 0x4f); // Enable genlock 257 adv7175_write(sd, 0x0d, 0x49); /* Disable genlock */
222 adv7175_write(client, 0x07, TR0MODE | TR0RST); 258 else
223 adv7175_write(client, 0x07, TR0MODE); 259 adv7175_write(sd, 0x0d, 0x4f); /* Enable genlock */
224 break; 260 adv7175_write(sd, 0x07, TR0MODE | TR0RST);
225 261 adv7175_write(sd, 0x07, TR0MODE);
226 case VIDEO_MODE_PAL: 262 /*udelay(10);*/
227 adv7175_write_block(client, init_pal,
228 sizeof(init_pal));
229 if (encoder->input == 0)
230 adv7175_write(client, 0x0d, 0x4f); // Enable genlock
231 adv7175_write(client, 0x07, TR0MODE | TR0RST);
232 adv7175_write(client, 0x07, TR0MODE);
233 break;
234
235 case VIDEO_MODE_SECAM: // WARNING! ADV7176 does not support SECAM.
236 /* This is an attempt to convert
237 * SECAM->PAL (typically it does not work
238 * due to genlock: when decoder is in SECAM
239 * and encoder in in PAL the subcarrier can
240 * not be syncronized with horizontal
241 * quency) */
242 adv7175_write_block(client, init_pal,
243 sizeof(init_pal));
244 if (encoder->input == 0)
245 adv7175_write(client, 0x0d, 0x49); // Disable genlock
246 adv7175_write(client, 0x07, TR0MODE | TR0RST);
247 adv7175_write(client, 0x07, TR0MODE);
248 break;
249 default:
250 v4l_dbg(1, debug, client, "illegal norm: %d\n", iarg);
251 return -EINVAL;
252 }
253 v4l_dbg(1, debug, client, "switched to %s\n", norms[iarg]);
254 encoder->norm = iarg;
255 break; 263 break;
256 }
257 264
258 case ENCODER_SET_INPUT: 265 case 1:
259 { 266 adv7175_write(sd, 0x01, 0x00);
260 int iarg = *(int *) arg;
261
262 /* RJ: *iarg = 0: input is from SAA7110
263 *iarg = 1: input is from ZR36060
264 *iarg = 2: color bar */
265
266 switch (iarg) {
267 case 0:
268 adv7175_write(client, 0x01, 0x00);
269
270 if (encoder->norm == VIDEO_MODE_NTSC)
271 set_subcarrier_freq(client, 1);
272
273 adv7175_write(client, 0x0c, TR1CAPT); /* TR1 */
274 if (encoder->norm == VIDEO_MODE_SECAM)
275 adv7175_write(client, 0x0d, 0x49); // Disable genlock
276 else
277 adv7175_write(client, 0x0d, 0x4f); // Enable genlock
278 adv7175_write(client, 0x07, TR0MODE | TR0RST);
279 adv7175_write(client, 0x07, TR0MODE);
280 //udelay(10);
281 break;
282
283 case 1:
284 adv7175_write(client, 0x01, 0x00);
285
286 if (encoder->norm == VIDEO_MODE_NTSC)
287 set_subcarrier_freq(client, 0);
288
289 adv7175_write(client, 0x0c, TR1PLAY); /* TR1 */
290 adv7175_write(client, 0x0d, 0x49);
291 adv7175_write(client, 0x07, TR0MODE | TR0RST);
292 adv7175_write(client, 0x07, TR0MODE);
293 /* udelay(10); */
294 break;
295
296 case 2:
297 adv7175_write(client, 0x01, 0x80);
298
299 if (encoder->norm == VIDEO_MODE_NTSC)
300 set_subcarrier_freq(client, 0);
301
302 adv7175_write(client, 0x0d, 0x49);
303 adv7175_write(client, 0x07, TR0MODE | TR0RST);
304 adv7175_write(client, 0x07, TR0MODE);
305 /* udelay(10); */
306 break;
307
308 default:
309 v4l_dbg(1, debug, client, "illegal input: %d\n", iarg);
310 return -EINVAL;
311 }
312 v4l_dbg(1, debug, client, "switched to %s\n", inputs[iarg]);
313 encoder->input = iarg;
314 break;
315 }
316 267
317 case ENCODER_SET_OUTPUT: 268 if (encoder->norm & V4L2_STD_NTSC)
318 { 269 set_subcarrier_freq(sd, 0);
319 int *iarg = arg;
320 270
321 /* not much choice of outputs */ 271 adv7175_write(sd, 0x0c, TR1PLAY); /* TR1 */
322 if (*iarg != 0) 272 adv7175_write(sd, 0x0d, 0x49);
323 return -EINVAL; 273 adv7175_write(sd, 0x07, TR0MODE | TR0RST);
274 adv7175_write(sd, 0x07, TR0MODE);
275 /* udelay(10); */
324 break; 276 break;
325 }
326 277
327 case ENCODER_ENABLE_OUTPUT: 278 case 2:
328 { 279 adv7175_write(sd, 0x01, 0x80);
329 int *iarg = arg; 280
281 if (encoder->norm & V4L2_STD_NTSC)
282 set_subcarrier_freq(sd, 0);
330 283
331 encoder->enable = !!*iarg; 284 adv7175_write(sd, 0x0d, 0x49);
285 adv7175_write(sd, 0x07, TR0MODE | TR0RST);
286 adv7175_write(sd, 0x07, TR0MODE);
287 /* udelay(10); */
332 break; 288 break;
333 }
334 289
335 default: 290 default:
291 v4l2_dbg(1, debug, sd, "illegal input: %d\n", route->input);
336 return -EINVAL; 292 return -EINVAL;
337 } 293 }
338 294 v4l2_dbg(1, debug, sd, "switched to %s\n", inputs[route->input]);
295 encoder->input = route->input;
339 return 0; 296 return 0;
340} 297}
341 298
299static int adv7175_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
300{
301 struct i2c_client *client = v4l2_get_subdevdata(sd);
302
303 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_ADV7175, 0);
304}
305
342/* ----------------------------------------------------------------------- */ 306/* ----------------------------------------------------------------------- */
343 307
344/* 308static const struct v4l2_subdev_core_ops adv7175_core_ops = {
345 * Generic i2c probe 309 .g_chip_ident = adv7175_g_chip_ident,
346 * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1' 310 .init = adv7175_init,
347 */
348static unsigned short normal_i2c[] = {
349 I2C_ADV7175 >> 1, (I2C_ADV7175 >> 1) + 1,
350 I2C_ADV7176 >> 1, (I2C_ADV7176 >> 1) + 1,
351 I2C_CLIENT_END
352}; 311};
353 312
354I2C_CLIENT_INSMOD; 313static const struct v4l2_subdev_video_ops adv7175_video_ops = {
314 .s_std_output = adv7175_s_std_output,
315 .s_routing = adv7175_s_routing,
316};
317
318static const struct v4l2_subdev_ops adv7175_ops = {
319 .core = &adv7175_core_ops,
320 .video = &adv7175_video_ops,
321};
322
323/* ----------------------------------------------------------------------- */
355 324
356static int adv7175_probe(struct i2c_client *client, 325static int adv7175_probe(struct i2c_client *client,
357 const struct i2c_device_id *id) 326 const struct i2c_device_id *id)
358{ 327{
359 int i; 328 int i;
360 struct adv7175 *encoder; 329 struct adv7175 *encoder;
330 struct v4l2_subdev *sd;
361 331
362 /* Check if the adapter supports the needed features */ 332 /* Check if the adapter supports the needed features */
363 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 333 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
@@ -369,26 +339,29 @@ static int adv7175_probe(struct i2c_client *client,
369 encoder = kzalloc(sizeof(struct adv7175), GFP_KERNEL); 339 encoder = kzalloc(sizeof(struct adv7175), GFP_KERNEL);
370 if (encoder == NULL) 340 if (encoder == NULL)
371 return -ENOMEM; 341 return -ENOMEM;
372 encoder->norm = VIDEO_MODE_PAL; 342 sd = &encoder->sd;
343 v4l2_i2c_subdev_init(sd, client, &adv7175_ops);
344 encoder->norm = V4L2_STD_NTSC;
373 encoder->input = 0; 345 encoder->input = 0;
374 encoder->enable = 1;
375 i2c_set_clientdata(client, encoder);
376 346
377 i = adv7175_write_block(client, init_common, sizeof(init_common)); 347 i = adv7175_write_block(sd, init_common, sizeof(init_common));
378 if (i >= 0) { 348 if (i >= 0) {
379 i = adv7175_write(client, 0x07, TR0MODE | TR0RST); 349 i = adv7175_write(sd, 0x07, TR0MODE | TR0RST);
380 i = adv7175_write(client, 0x07, TR0MODE); 350 i = adv7175_write(sd, 0x07, TR0MODE);
381 i = adv7175_read(client, 0x12); 351 i = adv7175_read(sd, 0x12);
382 v4l_dbg(1, debug, client, "revision %d\n", i & 1); 352 v4l2_dbg(1, debug, sd, "revision %d\n", i & 1);
383 } 353 }
384 if (i < 0) 354 if (i < 0)
385 v4l_dbg(1, debug, client, "init error 0x%x\n", i); 355 v4l2_dbg(1, debug, sd, "init error 0x%x\n", i);
386 return 0; 356 return 0;
387} 357}
388 358
389static int adv7175_remove(struct i2c_client *client) 359static int adv7175_remove(struct i2c_client *client)
390{ 360{
391 kfree(i2c_get_clientdata(client)); 361 struct v4l2_subdev *sd = i2c_get_clientdata(client);
362
363 v4l2_device_unregister_subdev(sd);
364 kfree(to_adv7175(sd));
392 return 0; 365 return 0;
393} 366}
394 367
@@ -403,8 +376,6 @@ MODULE_DEVICE_TABLE(i2c, adv7175_id);
403 376
404static struct v4l2_i2c_driver_data v4l2_i2c_data = { 377static struct v4l2_i2c_driver_data v4l2_i2c_data = {
405 .name = "adv7175", 378 .name = "adv7175",
406 .driverid = I2C_DRIVERID_ADV7175,
407 .command = adv7175_command,
408 .probe = adv7175_probe, 379 .probe = adv7175_probe,
409 .remove = adv7175_remove, 380 .remove = adv7175_remove,
410 .id_table = adv7175_id, 381 .id_table = adv7175_id,
diff --git a/drivers/media/video/au0828/Kconfig b/drivers/media/video/au0828/Kconfig
index 018f72b8e3e2..05cdf494dfb0 100644
--- a/drivers/media/video/au0828/Kconfig
+++ b/drivers/media/video/au0828/Kconfig
@@ -1,13 +1,13 @@
1 1
2config VIDEO_AU0828 2config VIDEO_AU0828
3 tristate "Auvitek AU0828 support" 3 tristate "Auvitek AU0828 support"
4 depends on I2C && INPUT && DVB_CORE && USB 4 depends on I2C && INPUT && DVB_CORE && USB && VIDEO_V4L2
5 select I2C_ALGOBIT 5 select I2C_ALGOBIT
6 select VIDEO_TVEEPROM 6 select VIDEO_TVEEPROM
7 select DVB_AU8522 if !DVB_FE_CUSTOMIZE 7 select DVB_AU8522 if !DVB_FE_CUSTOMISE
8 select MEDIA_TUNER_XC5000 if !DVB_FE_CUSTOMIZE 8 select MEDIA_TUNER_XC5000 if !MEDIA_TUNER_CUSTOMISE
9 select MEDIA_TUNER_MXL5007T if !DVB_FE_CUSTOMIZE 9 select MEDIA_TUNER_MXL5007T if !MEDIA_TUNER_CUSTOMISE
10 select MEDIA_TUNER_TDA18271 if !DVB_FE_CUSTOMIZE 10 select MEDIA_TUNER_TDA18271 if !MEDIA_TUNER_CUSTOMISE
11 ---help--- 11 ---help---
12 This is a video4linux driver for Auvitek's USB device. 12 This is a video4linux driver for Auvitek's USB device.
13 13
diff --git a/drivers/media/video/au0828/Makefile b/drivers/media/video/au0828/Makefile
index cd2c58281b4e..4d2623158188 100644
--- a/drivers/media/video/au0828/Makefile
+++ b/drivers/media/video/au0828/Makefile
@@ -1,4 +1,4 @@
1au0828-objs := au0828-core.o au0828-i2c.o au0828-cards.o au0828-dvb.o 1au0828-objs := au0828-core.o au0828-i2c.o au0828-cards.o au0828-dvb.o au0828-video.o
2 2
3obj-$(CONFIG_VIDEO_AU0828) += au0828.o 3obj-$(CONFIG_VIDEO_AU0828) += au0828.o
4 4
diff --git a/drivers/media/video/au0828/au0828-cards.c b/drivers/media/video/au0828/au0828-cards.c
index d60123b413f5..1aabaa7e55bb 100644
--- a/drivers/media/video/au0828/au0828-cards.c
+++ b/drivers/media/video/au0828/au0828-cards.c
@@ -21,25 +21,89 @@
21 21
22#include "au0828.h" 22#include "au0828.h"
23#include "au0828-cards.h" 23#include "au0828-cards.h"
24#include "au8522.h"
25#include "media/tuner.h"
26#include "media/v4l2-common.h"
27
28void hvr950q_cs5340_audio(void *priv, int enable)
29{
30 /* Because the HVR-950q shares an i2s bus between the cs5340 and the
31 au8522, we need to hold cs5340 in reset when using the au8522 */
32 struct au0828_dev *dev = priv;
33 if (enable == 1)
34 au0828_set(dev, REG_000, 0x10);
35 else
36 au0828_clear(dev, REG_000, 0x10);
37}
24 38
25struct au0828_board au0828_boards[] = { 39struct au0828_board au0828_boards[] = {
26 [AU0828_BOARD_UNKNOWN] = { 40 [AU0828_BOARD_UNKNOWN] = {
27 .name = "Unknown board", 41 .name = "Unknown board",
42 .tuner_type = UNSET,
43 .tuner_addr = ADDR_UNSET,
28 }, 44 },
29 [AU0828_BOARD_HAUPPAUGE_HVR850] = { 45 [AU0828_BOARD_HAUPPAUGE_HVR850] = {
30 .name = "Hauppauge HVR850", 46 .name = "Hauppauge HVR850",
47 .tuner_type = TUNER_XC5000,
48 .tuner_addr = 0x61,
49 .input = {
50 {
51 .type = AU0828_VMUX_TELEVISION,
52 .vmux = AU8522_COMPOSITE_CH4_SIF,
53 .amux = AU8522_AUDIO_SIF,
54 },
55 {
56 .type = AU0828_VMUX_COMPOSITE,
57 .vmux = AU8522_COMPOSITE_CH1,
58 .amux = AU8522_AUDIO_NONE,
59 .audio_setup = hvr950q_cs5340_audio,
60 },
61 {
62 .type = AU0828_VMUX_SVIDEO,
63 .vmux = AU8522_SVIDEO_CH13,
64 .amux = AU8522_AUDIO_NONE,
65 .audio_setup = hvr950q_cs5340_audio,
66 },
67 },
31 }, 68 },
32 [AU0828_BOARD_HAUPPAUGE_HVR950Q] = { 69 [AU0828_BOARD_HAUPPAUGE_HVR950Q] = {
33 .name = "Hauppauge HVR950Q", 70 .name = "Hauppauge HVR950Q",
71 .tuner_type = TUNER_XC5000,
72 .tuner_addr = 0x61,
73 .input = {
74 {
75 .type = AU0828_VMUX_TELEVISION,
76 .vmux = AU8522_COMPOSITE_CH4_SIF,
77 .amux = AU8522_AUDIO_SIF,
78 },
79 {
80 .type = AU0828_VMUX_COMPOSITE,
81 .vmux = AU8522_COMPOSITE_CH1,
82 .amux = AU8522_AUDIO_NONE,
83 .audio_setup = hvr950q_cs5340_audio,
84 },
85 {
86 .type = AU0828_VMUX_SVIDEO,
87 .vmux = AU8522_SVIDEO_CH13,
88 .amux = AU8522_AUDIO_NONE,
89 .audio_setup = hvr950q_cs5340_audio,
90 },
91 },
34 }, 92 },
35 [AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL] = { 93 [AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL] = {
36 .name = "Hauppauge HVR950Q rev xxF8", 94 .name = "Hauppauge HVR950Q rev xxF8",
95 .tuner_type = UNSET,
96 .tuner_addr = ADDR_UNSET,
37 }, 97 },
38 [AU0828_BOARD_DVICO_FUSIONHDTV7] = { 98 [AU0828_BOARD_DVICO_FUSIONHDTV7] = {
39 .name = "DViCO FusionHDTV USB", 99 .name = "DViCO FusionHDTV USB",
100 .tuner_type = UNSET,
101 .tuner_addr = ADDR_UNSET,
40 }, 102 },
41 [AU0828_BOARD_HAUPPAUGE_WOODBURY] = { 103 [AU0828_BOARD_HAUPPAUGE_WOODBURY] = {
42 .name = "Hauppauge Woodbury", 104 .name = "Hauppauge Woodbury",
105 .tuner_type = UNSET,
106 .tuner_addr = ADDR_UNSET,
43 }, 107 },
44}; 108};
45 109
@@ -52,7 +116,7 @@ int au0828_tuner_callback(void *priv, int component, int command, int arg)
52 116
53 dprintk(1, "%s()\n", __func__); 117 dprintk(1, "%s()\n", __func__);
54 118
55 switch (dev->board) { 119 switch (dev->boardnr) {
56 case AU0828_BOARD_HAUPPAUGE_HVR850: 120 case AU0828_BOARD_HAUPPAUGE_HVR850:
57 case AU0828_BOARD_HAUPPAUGE_HVR950Q: 121 case AU0828_BOARD_HAUPPAUGE_HVR950Q:
58 case AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL: 122 case AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL:
@@ -81,17 +145,18 @@ static void hauppauge_eeprom(struct au0828_dev *dev, u8 *eeprom_data)
81 struct tveeprom tv; 145 struct tveeprom tv;
82 146
83 tveeprom_hauppauge_analog(&dev->i2c_client, &tv, eeprom_data); 147 tveeprom_hauppauge_analog(&dev->i2c_client, &tv, eeprom_data);
148 dev->board.tuner_type = tv.tuner_type;
84 149
85 /* Make sure we support the board model */ 150 /* Make sure we support the board model */
86 switch (tv.model) { 151 switch (tv.model) {
87 case 72000: /* WinTV-HVR950q (Retail, IR, ATSC/QAM */ 152 case 72000: /* WinTV-HVR950q (Retail, IR, ATSC/QAM */
88 case 72001: /* WinTV-HVR950q (Retail, IR, ATSC/QAM and basic analog video */ 153 case 72001: /* WinTV-HVR950q (Retail, IR, ATSC/QAM and analog video */
89 case 72211: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and basic analog video */ 154 case 72211: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and analog video */
90 case 72221: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and basic analog video */ 155 case 72221: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and analog video */
91 case 72231: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and basic analog video */ 156 case 72231: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and analog video */
92 case 72241: /* WinTV-HVR950q (OEM, No IR, ATSC/QAM and basic analog video */ 157 case 72241: /* WinTV-HVR950q (OEM, No IR, ATSC/QAM and analog video */
93 case 72251: /* WinTV-HVR950q (Retail, IR, ATSC/QAM and basic analog video */ 158 case 72251: /* WinTV-HVR950q (Retail, IR, ATSC/QAM and analog video */
94 case 72301: /* WinTV-HVR850 (Retail, IR, ATSC and basic analog video */ 159 case 72301: /* WinTV-HVR850 (Retail, IR, ATSC and analog video */
95 case 72500: /* WinTV-HVR950q (OEM, No IR, ATSC/QAM */ 160 case 72500: /* WinTV-HVR950q (OEM, No IR, ATSC/QAM */
96 break; 161 break;
97 default: 162 default:
@@ -107,15 +172,21 @@ static void hauppauge_eeprom(struct au0828_dev *dev, u8 *eeprom_data)
107void au0828_card_setup(struct au0828_dev *dev) 172void au0828_card_setup(struct au0828_dev *dev)
108{ 173{
109 static u8 eeprom[256]; 174 static u8 eeprom[256];
175 struct tuner_setup tun_setup;
176 struct v4l2_subdev *sd;
177 unsigned int mode_mask = T_ANALOG_TV |
178 T_DIGITAL_TV;
110 179
111 dprintk(1, "%s()\n", __func__); 180 dprintk(1, "%s()\n", __func__);
112 181
182 memcpy(&dev->board, &au0828_boards[dev->boardnr], sizeof(dev->board));
183
113 if (dev->i2c_rc == 0) { 184 if (dev->i2c_rc == 0) {
114 dev->i2c_client.addr = 0xa0 >> 1; 185 dev->i2c_client.addr = 0xa0 >> 1;
115 tveeprom_read(&dev->i2c_client, eeprom, sizeof(eeprom)); 186 tveeprom_read(&dev->i2c_client, eeprom, sizeof(eeprom));
116 } 187 }
117 188
118 switch (dev->board) { 189 switch (dev->boardnr) {
119 case AU0828_BOARD_HAUPPAUGE_HVR850: 190 case AU0828_BOARD_HAUPPAUGE_HVR850:
120 case AU0828_BOARD_HAUPPAUGE_HVR950Q: 191 case AU0828_BOARD_HAUPPAUGE_HVR950Q:
121 case AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL: 192 case AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL:
@@ -124,6 +195,32 @@ void au0828_card_setup(struct au0828_dev *dev)
124 hauppauge_eeprom(dev, eeprom+0xa0); 195 hauppauge_eeprom(dev, eeprom+0xa0);
125 break; 196 break;
126 } 197 }
198
199 if (AUVI_INPUT(0).type != AU0828_VMUX_UNDEFINED) {
200 /* Load the analog demodulator driver (note this would need to
201 be abstracted out if we ever need to support a different
202 demod) */
203 sd = v4l2_i2c_new_subdev(&dev->i2c_adap, "au8522", "au8522",
204 0x8e >> 1);
205 if (sd == NULL)
206 printk(KERN_ERR "analog subdev registration failed\n");
207 }
208
209 /* Setup tuners */
210 if (dev->board.tuner_type != TUNER_ABSENT) {
211 /* Load the tuner module, which does the attach */
212 sd = v4l2_i2c_new_subdev(&dev->i2c_adap, "tuner", "tuner",
213 dev->board.tuner_addr);
214 if (sd == NULL)
215 printk(KERN_ERR "tuner subdev registration fail\n");
216
217 tun_setup.mode_mask = mode_mask;
218 tun_setup.type = dev->board.tuner_type;
219 tun_setup.addr = dev->board.tuner_addr;
220 tun_setup.tuner_callback = au0828_tuner_callback;
221 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_type_addr,
222 &tun_setup);
223 }
127} 224}
128 225
129/* 226/*
@@ -135,7 +232,7 @@ void au0828_gpio_setup(struct au0828_dev *dev)
135{ 232{
136 dprintk(1, "%s()\n", __func__); 233 dprintk(1, "%s()\n", __func__);
137 234
138 switch (dev->board) { 235 switch (dev->boardnr) {
139 case AU0828_BOARD_HAUPPAUGE_HVR850: 236 case AU0828_BOARD_HAUPPAUGE_HVR850:
140 case AU0828_BOARD_HAUPPAUGE_HVR950Q: 237 case AU0828_BOARD_HAUPPAUGE_HVR950Q:
141 case AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL: 238 case AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL:
@@ -144,21 +241,23 @@ void au0828_gpio_setup(struct au0828_dev *dev)
144 * 4 - CS5340 241 * 4 - CS5340
145 * 5 - AU8522 Demodulator 242 * 5 - AU8522 Demodulator
146 * 6 - eeprom W/P 243 * 6 - eeprom W/P
244 * 7 - power supply
147 * 9 - XC5000 Tuner 245 * 9 - XC5000 Tuner
148 */ 246 */
149 247
150 /* Into reset */ 248 /* Into reset */
151 au0828_write(dev, REG_003, 0x02); 249 au0828_write(dev, REG_003, 0x02);
152 au0828_write(dev, REG_002, 0x88 | 0x20); 250 au0828_write(dev, REG_002, 0x80 | 0x20 | 0x10);
153 au0828_write(dev, REG_001, 0x0); 251 au0828_write(dev, REG_001, 0x0);
154 au0828_write(dev, REG_000, 0x0); 252 au0828_write(dev, REG_000, 0x0);
155 msleep(100); 253 msleep(100);
156 254
157 /* Out of reset */ 255 /* Out of reset (leave the cs5340 in reset until needed) */
158 au0828_write(dev, REG_003, 0x02); 256 au0828_write(dev, REG_003, 0x02);
159 au0828_write(dev, REG_001, 0x02); 257 au0828_write(dev, REG_001, 0x02);
160 au0828_write(dev, REG_002, 0x88 | 0x20); 258 au0828_write(dev, REG_002, 0x80 | 0x20 | 0x10);
161 au0828_write(dev, REG_000, 0x88 | 0x20 | 0x40); 259 au0828_write(dev, REG_000, 0x80 | 0x40 | 0x20);
260
162 msleep(250); 261 msleep(250);
163 break; 262 break;
164 case AU0828_BOARD_DVICO_FUSIONHDTV7: 263 case AU0828_BOARD_DVICO_FUSIONHDTV7:
diff --git a/drivers/media/video/au0828/au0828-core.c b/drivers/media/video/au0828/au0828-core.c
index 5765e8656376..8c761d164442 100644
--- a/drivers/media/video/au0828/au0828-core.c
+++ b/drivers/media/video/au0828/au0828-core.c
@@ -36,6 +36,8 @@ int au0828_debug;
36module_param_named(debug, au0828_debug, int, 0644); 36module_param_named(debug, au0828_debug, int, 0644);
37MODULE_PARM_DESC(debug, "enable debug messages"); 37MODULE_PARM_DESC(debug, "enable debug messages");
38 38
39static atomic_t au0828_instance = ATOMIC_INIT(0);
40
39#define _AU0828_BULKPIPE 0x03 41#define _AU0828_BULKPIPE 0x03
40#define _BULKPIPESIZE 0xffff 42#define _BULKPIPESIZE 0xffff
41 43
@@ -51,13 +53,13 @@ static int recv_control_msg(struct au0828_dev *dev, u16 request, u32 value,
51u32 au0828_readreg(struct au0828_dev *dev, u16 reg) 53u32 au0828_readreg(struct au0828_dev *dev, u16 reg)
52{ 54{
53 recv_control_msg(dev, CMD_REQUEST_IN, 0, reg, dev->ctrlmsg, 1); 55 recv_control_msg(dev, CMD_REQUEST_IN, 0, reg, dev->ctrlmsg, 1);
54 dprintk(8, "%s(0x%x) = 0x%x\n", __func__, reg, dev->ctrlmsg[0]); 56 dprintk(8, "%s(0x%04x) = 0x%02x\n", __func__, reg, dev->ctrlmsg[0]);
55 return dev->ctrlmsg[0]; 57 return dev->ctrlmsg[0];
56} 58}
57 59
58u32 au0828_writereg(struct au0828_dev *dev, u16 reg, u32 val) 60u32 au0828_writereg(struct au0828_dev *dev, u16 reg, u32 val)
59{ 61{
60 dprintk(8, "%s(0x%x, 0x%x)\n", __func__, reg, val); 62 dprintk(8, "%s(0x%04x, 0x%02x)\n", __func__, reg, val);
61 return send_control_msg(dev, CMD_REQUEST_OUT, val, reg, 63 return send_control_msg(dev, CMD_REQUEST_OUT, val, reg,
62 dev->ctrlmsg, 0); 64 dev->ctrlmsg, 0);
63} 65}
@@ -146,9 +148,14 @@ static void au0828_usb_disconnect(struct usb_interface *interface)
146 /* Digital TV */ 148 /* Digital TV */
147 au0828_dvb_unregister(dev); 149 au0828_dvb_unregister(dev);
148 150
151 if (AUVI_INPUT(0).type != AU0828_VMUX_UNDEFINED)
152 au0828_analog_unregister(dev);
153
149 /* I2C */ 154 /* I2C */
150 au0828_i2c_unregister(dev); 155 au0828_i2c_unregister(dev);
151 156
157 v4l2_device_unregister(&dev->v4l2_dev);
158
152 usb_set_intfdata(interface, NULL); 159 usb_set_intfdata(interface, NULL);
153 160
154 mutex_lock(&dev->mutex); 161 mutex_lock(&dev->mutex);
@@ -162,7 +169,7 @@ static void au0828_usb_disconnect(struct usb_interface *interface)
162static int au0828_usb_probe(struct usb_interface *interface, 169static int au0828_usb_probe(struct usb_interface *interface,
163 const struct usb_device_id *id) 170 const struct usb_device_id *id)
164{ 171{
165 int ifnum; 172 int ifnum, retval, i;
166 struct au0828_dev *dev; 173 struct au0828_dev *dev;
167 struct usb_device *usbdev = interface_to_usbdev(interface); 174 struct usb_device *usbdev = interface_to_usbdev(interface);
168 175
@@ -185,10 +192,22 @@ static int au0828_usb_probe(struct usb_interface *interface,
185 mutex_init(&dev->mutex); 192 mutex_init(&dev->mutex);
186 mutex_init(&dev->dvb.lock); 193 mutex_init(&dev->dvb.lock);
187 dev->usbdev = usbdev; 194 dev->usbdev = usbdev;
188 dev->board = id->driver_info; 195 dev->boardnr = id->driver_info;
189 196
190 usb_set_intfdata(interface, dev); 197 usb_set_intfdata(interface, dev);
191 198
199 /* Create the v4l2_device */
200 i = atomic_inc_return(&au0828_instance) - 1;
201 snprintf(dev->v4l2_dev.name, sizeof(dev->v4l2_dev.name), "%s-%03d",
202 "au0828", i);
203 retval = v4l2_device_register(&dev->usbdev->dev, &dev->v4l2_dev);
204 if (retval) {
205 printk(KERN_ERR "%s() v4l2_device_register failed\n",
206 __func__);
207 kfree(dev);
208 return -EIO;
209 }
210
192 /* Power Up the bridge */ 211 /* Power Up the bridge */
193 au0828_write(dev, REG_600, 1 << 4); 212 au0828_write(dev, REG_600, 1 << 4);
194 213
@@ -201,12 +220,15 @@ static int au0828_usb_probe(struct usb_interface *interface,
201 /* Setup */ 220 /* Setup */
202 au0828_card_setup(dev); 221 au0828_card_setup(dev);
203 222
223 /* Analog TV */
224 if (AUVI_INPUT(0).type != AU0828_VMUX_UNDEFINED)
225 au0828_analog_register(dev, interface);
226
204 /* Digital TV */ 227 /* Digital TV */
205 au0828_dvb_register(dev); 228 au0828_dvb_register(dev);
206 229
207 printk(KERN_INFO "Registered device AU0828 [%s]\n", 230 printk(KERN_INFO "Registered device AU0828 [%s]\n",
208 au0828_boards[dev->board].name == NULL ? "Unset" : 231 dev->board.name == NULL ? "Unset" : dev->board.name);
209 au0828_boards[dev->board].name);
210 232
211 return 0; 233 return 0;
212} 234}
diff --git a/drivers/media/video/au0828/au0828-dvb.c b/drivers/media/video/au0828/au0828-dvb.c
index a882cf546d0a..14baffc22192 100644
--- a/drivers/media/video/au0828/au0828-dvb.c
+++ b/drivers/media/video/au0828/au0828-dvb.c
@@ -378,7 +378,7 @@ int au0828_dvb_register(struct au0828_dev *dev)
378 dprintk(1, "%s()\n", __func__); 378 dprintk(1, "%s()\n", __func__);
379 379
380 /* init frontend */ 380 /* init frontend */
381 switch (dev->board) { 381 switch (dev->boardnr) {
382 case AU0828_BOARD_HAUPPAUGE_HVR850: 382 case AU0828_BOARD_HAUPPAUGE_HVR850:
383 case AU0828_BOARD_HAUPPAUGE_HVR950Q: 383 case AU0828_BOARD_HAUPPAUGE_HVR950Q:
384 dvb->frontend = dvb_attach(au8522_attach, 384 dvb->frontend = dvb_attach(au8522_attach,
diff --git a/drivers/media/video/au0828/au0828-i2c.c b/drivers/media/video/au0828/au0828-i2c.c
index d618fbaade1b..f9a958d0aef1 100644
--- a/drivers/media/video/au0828/au0828-i2c.c
+++ b/drivers/media/video/au0828/au0828-i2c.c
@@ -140,13 +140,39 @@ static int i2c_sendbytes(struct i2c_adapter *i2c_adap,
140 dprintk(4, "%s()\n", __func__); 140 dprintk(4, "%s()\n", __func__);
141 141
142 au0828_write(dev, REG_2FF, 0x01); 142 au0828_write(dev, REG_2FF, 0x01);
143 au0828_write(dev, REG_202, 0x07); 143
144 /* FIXME: There is a problem with i2c communications with xc5000 that
145 requires us to slow down the i2c clock until we have a better
146 strategy (such as using the secondary i2c bus to do firmware
147 loading */
148 if ((msg->addr << 1) == 0xc2)
149 au0828_write(dev, REG_202, 0x40);
150 else
151 au0828_write(dev, REG_202, 0x07);
144 152
145 /* Hardware needs 8 bit addresses */ 153 /* Hardware needs 8 bit addresses */
146 au0828_write(dev, REG_203, msg->addr << 1); 154 au0828_write(dev, REG_203, msg->addr << 1);
147 155
148 dprintk(4, "SEND: %02x\n", msg->addr); 156 dprintk(4, "SEND: %02x\n", msg->addr);
149 157
158 /* Deal with i2c_scan */
159 if (msg->len == 0) {
160 /* The analog tuner detection code makes use of the SMBUS_QUICK
161 message (which involves a zero length i2c write). To avoid
162 checking the status register when we didn't strobe out any
163 actual bytes to the bus, just do a read check. This is
164 consistent with how I saw i2c device checking done in the
165 USB trace of the Windows driver */
166 au0828_write(dev, REG_200, 0x20);
167 if (!i2c_wait_done(i2c_adap))
168 return -EIO;
169
170 if (i2c_wait_read_ack(i2c_adap))
171 return -EIO;
172
173 return 0;
174 }
175
150 for (i = 0; i < msg->len;) { 176 for (i = 0; i < msg->len;) {
151 177
152 dprintk(4, " %02x\n", msg->buf[i]); 178 dprintk(4, " %02x\n", msg->buf[i]);
@@ -191,7 +217,15 @@ static int i2c_readbytes(struct i2c_adapter *i2c_adap,
191 dprintk(4, "%s()\n", __func__); 217 dprintk(4, "%s()\n", __func__);
192 218
193 au0828_write(dev, REG_2FF, 0x01); 219 au0828_write(dev, REG_2FF, 0x01);
194 au0828_write(dev, REG_202, 0x07); 220
221 /* FIXME: There is a problem with i2c communications with xc5000 that
222 requires us to slow down the i2c clock until we have a better
223 strategy (such as using the secondary i2c bus to do firmware
224 loading */
225 if ((msg->addr << 1) == 0xc2)
226 au0828_write(dev, REG_202, 0x40);
227 else
228 au0828_write(dev, REG_202, 0x07);
195 229
196 /* Hardware needs 8 bit addresses */ 230 /* Hardware needs 8 bit addresses */
197 au0828_write(dev, REG_203, msg->addr << 1); 231 au0828_write(dev, REG_203, msg->addr << 1);
@@ -265,33 +299,6 @@ err:
265 return retval; 299 return retval;
266} 300}
267 301
268static int attach_inform(struct i2c_client *client)
269{
270 dprintk(1, "%s i2c attach [addr=0x%x,client=%s]\n",
271 client->driver->driver.name, client->addr, client->name);
272
273 if (!client->driver->command)
274 return 0;
275
276 return 0;
277}
278
279static int detach_inform(struct i2c_client *client)
280{
281 dprintk(1, "i2c detach [client=%s]\n", client->name);
282
283 return 0;
284}
285
286void au0828_call_i2c_clients(struct au0828_dev *dev,
287 unsigned int cmd, void *arg)
288{
289 if (dev->i2c_rc != 0)
290 return;
291
292 i2c_clients_command(&dev->i2c_adap, cmd, arg);
293}
294
295static u32 au0828_functionality(struct i2c_adapter *adap) 302static u32 au0828_functionality(struct i2c_adapter *adap)
296{ 303{
297 return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_I2C; 304 return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_I2C;
@@ -309,9 +316,6 @@ static struct i2c_adapter au0828_i2c_adap_template = {
309 .owner = THIS_MODULE, 316 .owner = THIS_MODULE,
310 .id = I2C_HW_B_AU0828, 317 .id = I2C_HW_B_AU0828,
311 .algo = &au0828_i2c_algo_template, 318 .algo = &au0828_i2c_algo_template,
312 .class = I2C_CLASS_TV_ANALOG,
313 .client_register = attach_inform,
314 .client_unregister = detach_inform,
315}; 319};
316 320
317static struct i2c_client au0828_i2c_client_template = { 321static struct i2c_client au0828_i2c_client_template = {
@@ -356,9 +360,9 @@ int au0828_i2c_register(struct au0828_dev *dev)
356 strlcpy(dev->i2c_adap.name, DRIVER_NAME, 360 strlcpy(dev->i2c_adap.name, DRIVER_NAME,
357 sizeof(dev->i2c_adap.name)); 361 sizeof(dev->i2c_adap.name));
358 362
359 dev->i2c_algo.data = dev; 363 dev->i2c_adap.algo = &dev->i2c_algo;
360 dev->i2c_adap.algo_data = dev; 364 dev->i2c_adap.algo_data = dev;
361 i2c_set_adapdata(&dev->i2c_adap, dev); 365 i2c_set_adapdata(&dev->i2c_adap, &dev->v4l2_dev);
362 i2c_add_adapter(&dev->i2c_adap); 366 i2c_add_adapter(&dev->i2c_adap);
363 367
364 dev->i2c_client.adapter = &dev->i2c_adap; 368 dev->i2c_client.adapter = &dev->i2c_adap;
diff --git a/drivers/media/video/au0828/au0828-reg.h b/drivers/media/video/au0828/au0828-reg.h
index 1e87fa0c6842..b15e4a3b6fc0 100644
--- a/drivers/media/video/au0828/au0828-reg.h
+++ b/drivers/media/video/au0828/au0828-reg.h
@@ -27,6 +27,9 @@
27#define REG_002 0x002 27#define REG_002 0x002
28#define REG_003 0x003 28#define REG_003 0x003
29 29
30#define AU0828_SENSORCTRL_100 0x100
31#define AU0828_SENSORCTRL_VBI_103 0x103
32
30#define REG_200 0x200 33#define REG_200 0x200
31#define REG_201 0x201 34#define REG_201 0x201
32#define REG_202 0x202 35#define REG_202 0x202
@@ -35,4 +38,7 @@
35#define REG_209 0x209 38#define REG_209 0x209
36#define REG_2FF 0x2ff 39#define REG_2FF 0x2ff
37 40
41/* Audio registers */
42#define AU0828_AUDIOCTRL_50C 0x50C
43
38#define REG_600 0x600 44#define REG_600 0x600
diff --git a/drivers/media/video/au0828/au0828-video.c b/drivers/media/video/au0828/au0828-video.c
new file mode 100644
index 000000000000..f7ad4958b94e
--- /dev/null
+++ b/drivers/media/video/au0828/au0828-video.c
@@ -0,0 +1,1712 @@
1/*
2 * Auvitek AU0828 USB Bridge (Analog video support)
3 *
4 * Copyright (C) 2009 Devin Heitmueller <dheitmueller@linuxtv.org>
5 * Copyright (C) 2005-2008 Auvitek International, Ltd.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * As published by the Free Software Foundation; either version 2
10 * of the License, or (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., 51 Franklin Street, Fifth Floor, Boston, MA
20 * 02110-1301, USA.
21 */
22
23/* Developer Notes:
24 *
25 * VBI support is not yet working
26 * The hardware scaler supported is unimplemented
27 * AC97 audio support is unimplemented (only i2s audio mode)
28 *
29 */
30
31#include <linux/module.h>
32#include <linux/init.h>
33#include <linux/device.h>
34#include <linux/suspend.h>
35#include <linux/version.h>
36#include <media/v4l2-common.h>
37#include <media/v4l2-ioctl.h>
38#include <media/v4l2-chip-ident.h>
39#include <media/tuner.h>
40#include "au0828.h"
41#include "au0828-reg.h"
42
43static LIST_HEAD(au0828_devlist);
44static DEFINE_MUTEX(au0828_sysfs_lock);
45
46#define AU0828_VERSION_CODE KERNEL_VERSION(0, 0, 1)
47
48/* ------------------------------------------------------------------
49 Videobuf operations
50 ------------------------------------------------------------------*/
51
52static unsigned int isoc_debug;
53module_param(isoc_debug, int, 0644);
54MODULE_PARM_DESC(isoc_debug, "enable debug messages [isoc transfers]");
55
56#define au0828_isocdbg(fmt, arg...) \
57do {\
58 if (isoc_debug) { \
59 printk(KERN_INFO "au0828 %s :"fmt, \
60 __func__ , ##arg); \
61 } \
62 } while (0)
63
64static inline void print_err_status(struct au0828_dev *dev,
65 int packet, int status)
66{
67 char *errmsg = "Unknown";
68
69 switch (status) {
70 case -ENOENT:
71 errmsg = "unlinked synchronuously";
72 break;
73 case -ECONNRESET:
74 errmsg = "unlinked asynchronuously";
75 break;
76 case -ENOSR:
77 errmsg = "Buffer error (overrun)";
78 break;
79 case -EPIPE:
80 errmsg = "Stalled (device not responding)";
81 break;
82 case -EOVERFLOW:
83 errmsg = "Babble (bad cable?)";
84 break;
85 case -EPROTO:
86 errmsg = "Bit-stuff error (bad cable?)";
87 break;
88 case -EILSEQ:
89 errmsg = "CRC/Timeout (could be anything)";
90 break;
91 case -ETIME:
92 errmsg = "Device does not respond";
93 break;
94 }
95 if (packet < 0) {
96 au0828_isocdbg("URB status %d [%s].\n", status, errmsg);
97 } else {
98 au0828_isocdbg("URB packet %d, status %d [%s].\n",
99 packet, status, errmsg);
100 }
101}
102
103static int check_dev(struct au0828_dev *dev)
104{
105 if (dev->dev_state & DEV_DISCONNECTED) {
106 printk(KERN_INFO "v4l2 ioctl: device not present\n");
107 return -ENODEV;
108 }
109
110 if (dev->dev_state & DEV_MISCONFIGURED) {
111 printk(KERN_INFO "v4l2 ioctl: device is misconfigured; "
112 "close and open it again\n");
113 return -EIO;
114 }
115 return 0;
116}
117
118/*
119 * IRQ callback, called by URB callback
120 */
121static void au0828_irq_callback(struct urb *urb)
122{
123 struct au0828_dmaqueue *dma_q = urb->context;
124 struct au0828_dev *dev = container_of(dma_q, struct au0828_dev, vidq);
125 int rc, i;
126
127 switch (urb->status) {
128 case 0: /* success */
129 case -ETIMEDOUT: /* NAK */
130 break;
131 case -ECONNRESET: /* kill */
132 case -ENOENT:
133 case -ESHUTDOWN:
134 au0828_isocdbg("au0828_irq_callback called: status kill\n");
135 return;
136 default: /* unknown error */
137 au0828_isocdbg("urb completition error %d.\n", urb->status);
138 break;
139 }
140
141 /* Copy data from URB */
142 spin_lock(&dev->slock);
143 rc = dev->isoc_ctl.isoc_copy(dev, urb);
144 spin_unlock(&dev->slock);
145
146 /* Reset urb buffers */
147 for (i = 0; i < urb->number_of_packets; i++) {
148 urb->iso_frame_desc[i].status = 0;
149 urb->iso_frame_desc[i].actual_length = 0;
150 }
151 urb->status = 0;
152
153 urb->status = usb_submit_urb(urb, GFP_ATOMIC);
154 if (urb->status) {
155 au0828_isocdbg("urb resubmit failed (error=%i)\n",
156 urb->status);
157 }
158}
159
160/*
161 * Stop and Deallocate URBs
162 */
163void au0828_uninit_isoc(struct au0828_dev *dev)
164{
165 struct urb *urb;
166 int i;
167
168 au0828_isocdbg("au0828: called au0828_uninit_isoc\n");
169
170 dev->isoc_ctl.nfields = -1;
171 for (i = 0; i < dev->isoc_ctl.num_bufs; i++) {
172 urb = dev->isoc_ctl.urb[i];
173 if (urb) {
174 if (!irqs_disabled())
175 usb_kill_urb(urb);
176 else
177 usb_unlink_urb(urb);
178
179 if (dev->isoc_ctl.transfer_buffer[i]) {
180 usb_buffer_free(dev->usbdev,
181 urb->transfer_buffer_length,
182 dev->isoc_ctl.transfer_buffer[i],
183 urb->transfer_dma);
184 }
185 usb_free_urb(urb);
186 dev->isoc_ctl.urb[i] = NULL;
187 }
188 dev->isoc_ctl.transfer_buffer[i] = NULL;
189 }
190
191 kfree(dev->isoc_ctl.urb);
192 kfree(dev->isoc_ctl.transfer_buffer);
193
194 dev->isoc_ctl.urb = NULL;
195 dev->isoc_ctl.transfer_buffer = NULL;
196 dev->isoc_ctl.num_bufs = 0;
197}
198
199/*
200 * Allocate URBs and start IRQ
201 */
202int au0828_init_isoc(struct au0828_dev *dev, int max_packets,
203 int num_bufs, int max_pkt_size,
204 int (*isoc_copy) (struct au0828_dev *dev, struct urb *urb))
205{
206 struct au0828_dmaqueue *dma_q = &dev->vidq;
207 int i;
208 int sb_size, pipe;
209 struct urb *urb;
210 int j, k;
211 int rc;
212
213 au0828_isocdbg("au0828: called au0828_prepare_isoc\n");
214
215 /* De-allocates all pending stuff */
216 au0828_uninit_isoc(dev);
217
218 dev->isoc_ctl.isoc_copy = isoc_copy;
219 dev->isoc_ctl.num_bufs = num_bufs;
220
221 dev->isoc_ctl.urb = kzalloc(sizeof(void *)*num_bufs, GFP_KERNEL);
222 if (!dev->isoc_ctl.urb) {
223 au0828_isocdbg("cannot alloc memory for usb buffers\n");
224 return -ENOMEM;
225 }
226
227 dev->isoc_ctl.transfer_buffer = kzalloc(sizeof(void *)*num_bufs,
228 GFP_KERNEL);
229 if (!dev->isoc_ctl.transfer_buffer) {
230 au0828_isocdbg("cannot allocate memory for usb transfer\n");
231 kfree(dev->isoc_ctl.urb);
232 return -ENOMEM;
233 }
234
235 dev->isoc_ctl.max_pkt_size = max_pkt_size;
236 dev->isoc_ctl.buf = NULL;
237
238 sb_size = max_packets * dev->isoc_ctl.max_pkt_size;
239
240 /* allocate urbs and transfer buffers */
241 for (i = 0; i < dev->isoc_ctl.num_bufs; i++) {
242 urb = usb_alloc_urb(max_packets, GFP_KERNEL);
243 if (!urb) {
244 au0828_isocdbg("cannot alloc isoc_ctl.urb %i\n", i);
245 au0828_uninit_isoc(dev);
246 return -ENOMEM;
247 }
248 dev->isoc_ctl.urb[i] = urb;
249
250 dev->isoc_ctl.transfer_buffer[i] = usb_buffer_alloc(dev->usbdev,
251 sb_size, GFP_KERNEL, &urb->transfer_dma);
252 if (!dev->isoc_ctl.transfer_buffer[i]) {
253 printk("unable to allocate %i bytes for transfer"
254 " buffer %i%s\n",
255 sb_size, i,
256 in_interrupt() ? " while in int" : "");
257 au0828_uninit_isoc(dev);
258 return -ENOMEM;
259 }
260 memset(dev->isoc_ctl.transfer_buffer[i], 0, sb_size);
261
262 pipe = usb_rcvisocpipe(dev->usbdev,
263 dev->isoc_in_endpointaddr),
264
265 usb_fill_int_urb(urb, dev->usbdev, pipe,
266 dev->isoc_ctl.transfer_buffer[i], sb_size,
267 au0828_irq_callback, dma_q, 1);
268
269 urb->number_of_packets = max_packets;
270 urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
271
272 k = 0;
273 for (j = 0; j < max_packets; j++) {
274 urb->iso_frame_desc[j].offset = k;
275 urb->iso_frame_desc[j].length =
276 dev->isoc_ctl.max_pkt_size;
277 k += dev->isoc_ctl.max_pkt_size;
278 }
279 }
280
281 init_waitqueue_head(&dma_q->wq);
282
283 /* submit urbs and enables IRQ */
284 for (i = 0; i < dev->isoc_ctl.num_bufs; i++) {
285 rc = usb_submit_urb(dev->isoc_ctl.urb[i], GFP_ATOMIC);
286 if (rc) {
287 au0828_isocdbg("submit of urb %i failed (error=%i)\n",
288 i, rc);
289 au0828_uninit_isoc(dev);
290 return rc;
291 }
292 }
293
294 return 0;
295}
296
297/*
298 * Announces that a buffer were filled and request the next
299 */
300static inline void buffer_filled(struct au0828_dev *dev,
301 struct au0828_dmaqueue *dma_q,
302 struct au0828_buffer *buf)
303{
304 /* Advice that buffer was filled */
305 au0828_isocdbg("[%p/%d] wakeup\n", buf, buf->vb.i);
306
307 buf->vb.state = VIDEOBUF_DONE;
308 buf->vb.field_count++;
309 do_gettimeofday(&buf->vb.ts);
310
311 dev->isoc_ctl.buf = NULL;
312
313 list_del(&buf->vb.queue);
314 wake_up(&buf->vb.done);
315}
316
317/*
318 * Identify the buffer header type and properly handles
319 */
320static void au0828_copy_video(struct au0828_dev *dev,
321 struct au0828_dmaqueue *dma_q,
322 struct au0828_buffer *buf,
323 unsigned char *p,
324 unsigned char *outp, unsigned long len)
325{
326 void *fieldstart, *startwrite, *startread;
327 int linesdone, currlinedone, offset, lencopy, remain;
328 int bytesperline = dev->width << 1; /* Assumes 16-bit depth @@@@ */
329
330 if (dma_q->pos + len > buf->vb.size)
331 len = buf->vb.size - dma_q->pos;
332
333 startread = p;
334 remain = len;
335
336 /* Interlaces frame */
337 if (buf->top_field)
338 fieldstart = outp;
339 else
340 fieldstart = outp + bytesperline;
341
342 linesdone = dma_q->pos / bytesperline;
343 currlinedone = dma_q->pos % bytesperline;
344 offset = linesdone * bytesperline * 2 + currlinedone;
345 startwrite = fieldstart + offset;
346 lencopy = bytesperline - currlinedone;
347 lencopy = lencopy > remain ? remain : lencopy;
348
349 if ((char *)startwrite + lencopy > (char *)outp + buf->vb.size) {
350 au0828_isocdbg("Overflow of %zi bytes past buffer end (1)\n",
351 ((char *)startwrite + lencopy) -
352 ((char *)outp + buf->vb.size));
353 remain = (char *)outp + buf->vb.size - (char *)startwrite;
354 lencopy = remain;
355 }
356 if (lencopy <= 0)
357 return;
358 memcpy(startwrite, startread, lencopy);
359
360 remain -= lencopy;
361
362 while (remain > 0) {
363 startwrite += lencopy + bytesperline;
364 startread += lencopy;
365 if (bytesperline > remain)
366 lencopy = remain;
367 else
368 lencopy = bytesperline;
369
370 if ((char *)startwrite + lencopy > (char *)outp +
371 buf->vb.size) {
372 au0828_isocdbg("Overflow %zi bytes past buf end (2)\n",
373 ((char *)startwrite + lencopy) -
374 ((char *)outp + buf->vb.size));
375 lencopy = remain = (char *)outp + buf->vb.size -
376 (char *)startwrite;
377 }
378 if (lencopy <= 0)
379 break;
380
381 memcpy(startwrite, startread, lencopy);
382
383 remain -= lencopy;
384 }
385
386 if (offset > 1440) {
387 /* We have enough data to check for greenscreen */
388 if (outp[0] < 0x60 && outp[1440] < 0x60)
389 dev->greenscreen_detected = 1;
390 }
391
392 dma_q->pos += len;
393}
394
395/*
396 * video-buf generic routine to get the next available buffer
397 */
398static inline void get_next_buf(struct au0828_dmaqueue *dma_q,
399 struct au0828_buffer **buf)
400{
401 struct au0828_dev *dev = container_of(dma_q, struct au0828_dev, vidq);
402
403 if (list_empty(&dma_q->active)) {
404 au0828_isocdbg("No active queue to serve\n");
405 dev->isoc_ctl.buf = NULL;
406 *buf = NULL;
407 return;
408 }
409
410 /* Get the next buffer */
411 *buf = list_entry(dma_q->active.next, struct au0828_buffer, vb.queue);
412 dev->isoc_ctl.buf = *buf;
413
414 return;
415}
416
417/*
418 * Controls the isoc copy of each urb packet
419 */
420static inline int au0828_isoc_copy(struct au0828_dev *dev, struct urb *urb)
421{
422 struct au0828_buffer *buf;
423 struct au0828_dmaqueue *dma_q = urb->context;
424 unsigned char *outp = NULL;
425 int i, len = 0, rc = 1;
426 unsigned char *p;
427 unsigned char fbyte;
428
429 if (!dev)
430 return 0;
431
432 if ((dev->dev_state & DEV_DISCONNECTED) ||
433 (dev->dev_state & DEV_MISCONFIGURED))
434 return 0;
435
436 if (urb->status < 0) {
437 print_err_status(dev, -1, urb->status);
438 if (urb->status == -ENOENT)
439 return 0;
440 }
441
442 buf = dev->isoc_ctl.buf;
443 if (buf != NULL)
444 outp = videobuf_to_vmalloc(&buf->vb);
445
446 for (i = 0; i < urb->number_of_packets; i++) {
447 int status = urb->iso_frame_desc[i].status;
448
449 if (status < 0) {
450 print_err_status(dev, i, status);
451 if (urb->iso_frame_desc[i].status != -EPROTO)
452 continue;
453 }
454
455 if (urb->iso_frame_desc[i].actual_length <= 0)
456 continue;
457
458 if (urb->iso_frame_desc[i].actual_length >
459 dev->max_pkt_size) {
460 au0828_isocdbg("packet bigger than packet size");
461 continue;
462 }
463
464 p = urb->transfer_buffer + urb->iso_frame_desc[i].offset;
465 fbyte = p[0];
466 len = urb->iso_frame_desc[i].actual_length - 4;
467 p += 4;
468
469 if (fbyte & 0x80) {
470 len -= 4;
471 p += 4;
472 au0828_isocdbg("Video frame %s\n",
473 (fbyte & 0x40) ? "odd" : "even");
474 if (!(fbyte & 0x40)) {
475 if (buf != NULL)
476 buffer_filled(dev, dma_q, buf);
477 get_next_buf(dma_q, &buf);
478 if (buf == NULL)
479 outp = NULL;
480 else
481 outp = videobuf_to_vmalloc(&buf->vb);
482 }
483
484 if (buf != NULL) {
485 if (fbyte & 0x40)
486 buf->top_field = 1;
487 else
488 buf->top_field = 0;
489 }
490
491 dma_q->pos = 0;
492 }
493 if (buf != NULL)
494 au0828_copy_video(dev, dma_q, buf, p, outp, len);
495 }
496 return rc;
497}
498
499static int
500buffer_setup(struct videobuf_queue *vq, unsigned int *count,
501 unsigned int *size)
502{
503 struct au0828_fh *fh = vq->priv_data;
504 *size = (fh->dev->width * fh->dev->height * 16 + 7) >> 3;
505
506 if (0 == *count)
507 *count = AU0828_DEF_BUF;
508
509 if (*count < AU0828_MIN_BUF)
510 *count = AU0828_MIN_BUF;
511 return 0;
512}
513
514/* This is called *without* dev->slock held; please keep it that way */
515static void free_buffer(struct videobuf_queue *vq, struct au0828_buffer *buf)
516{
517 struct au0828_fh *fh = vq->priv_data;
518 struct au0828_dev *dev = fh->dev;
519 unsigned long flags = 0;
520 if (in_interrupt())
521 BUG();
522
523 /* We used to wait for the buffer to finish here, but this didn't work
524 because, as we were keeping the state as VIDEOBUF_QUEUED,
525 videobuf_queue_cancel marked it as finished for us.
526 (Also, it could wedge forever if the hardware was misconfigured.)
527
528 This should be safe; by the time we get here, the buffer isn't
529 queued anymore. If we ever start marking the buffers as
530 VIDEOBUF_ACTIVE, it won't be, though.
531 */
532 spin_lock_irqsave(&dev->slock, flags);
533 if (dev->isoc_ctl.buf == buf)
534 dev->isoc_ctl.buf = NULL;
535 spin_unlock_irqrestore(&dev->slock, flags);
536
537 videobuf_vmalloc_free(&buf->vb);
538 buf->vb.state = VIDEOBUF_NEEDS_INIT;
539}
540
541static int
542buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
543 enum v4l2_field field)
544{
545 struct au0828_fh *fh = vq->priv_data;
546 struct au0828_buffer *buf = container_of(vb, struct au0828_buffer, vb);
547 struct au0828_dev *dev = fh->dev;
548 int rc = 0, urb_init = 0;
549
550 buf->vb.size = (fh->dev->width * fh->dev->height * 16 + 7) >> 3;
551
552 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)
553 return -EINVAL;
554
555 buf->vb.width = dev->width;
556 buf->vb.height = dev->height;
557 buf->vb.field = field;
558
559 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
560 rc = videobuf_iolock(vq, &buf->vb, NULL);
561 if (rc < 0) {
562 printk(KERN_INFO "videobuf_iolock failed\n");
563 goto fail;
564 }
565 }
566
567 if (!dev->isoc_ctl.num_bufs)
568 urb_init = 1;
569
570 if (urb_init) {
571 rc = au0828_init_isoc(dev, AU0828_ISO_PACKETS_PER_URB,
572 AU0828_MAX_ISO_BUFS, dev->max_pkt_size,
573 au0828_isoc_copy);
574 if (rc < 0) {
575 printk(KERN_INFO "au0828_init_isoc failed\n");
576 goto fail;
577 }
578 }
579
580 buf->vb.state = VIDEOBUF_PREPARED;
581 return 0;
582
583fail:
584 free_buffer(vq, buf);
585 return rc;
586}
587
588static void
589buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
590{
591 struct au0828_buffer *buf = container_of(vb,
592 struct au0828_buffer,
593 vb);
594 struct au0828_fh *fh = vq->priv_data;
595 struct au0828_dev *dev = fh->dev;
596 struct au0828_dmaqueue *vidq = &dev->vidq;
597
598 buf->vb.state = VIDEOBUF_QUEUED;
599 list_add_tail(&buf->vb.queue, &vidq->active);
600}
601
602static void buffer_release(struct videobuf_queue *vq,
603 struct videobuf_buffer *vb)
604{
605 struct au0828_buffer *buf = container_of(vb,
606 struct au0828_buffer,
607 vb);
608
609 free_buffer(vq, buf);
610}
611
612static struct videobuf_queue_ops au0828_video_qops = {
613 .buf_setup = buffer_setup,
614 .buf_prepare = buffer_prepare,
615 .buf_queue = buffer_queue,
616 .buf_release = buffer_release,
617};
618
619/* ------------------------------------------------------------------
620 V4L2 interface
621 ------------------------------------------------------------------*/
622
623static int au0828_i2s_init(struct au0828_dev *dev)
624{
625 /* Enable i2s mode */
626 au0828_writereg(dev, AU0828_AUDIOCTRL_50C, 0x01);
627 return 0;
628}
629
630/*
631 * Auvitek au0828 analog stream enable
632 * Please set interface0 to AS5 before enable the stream
633 */
634int au0828_analog_stream_enable(struct au0828_dev *d)
635{
636 dprintk(1, "au0828_analog_stream_enable called\n");
637 au0828_writereg(d, AU0828_SENSORCTRL_VBI_103, 0x00);
638 au0828_writereg(d, 0x106, 0x00);
639 /* set x position */
640 au0828_writereg(d, 0x110, 0x00);
641 au0828_writereg(d, 0x111, 0x00);
642 au0828_writereg(d, 0x114, 0xa0);
643 au0828_writereg(d, 0x115, 0x05);
644 /* set y position */
645 au0828_writereg(d, 0x112, 0x02);
646 au0828_writereg(d, 0x113, 0x00);
647 au0828_writereg(d, 0x116, 0xf2);
648 au0828_writereg(d, 0x117, 0x00);
649 au0828_writereg(d, AU0828_SENSORCTRL_100, 0xb3);
650
651 return 0;
652}
653
654int au0828_analog_stream_disable(struct au0828_dev *d)
655{
656 dprintk(1, "au0828_analog_stream_disable called\n");
657 au0828_writereg(d, AU0828_SENSORCTRL_100, 0x0);
658 return 0;
659}
660
661void au0828_analog_stream_reset(struct au0828_dev *dev)
662{
663 dprintk(1, "au0828_analog_stream_reset called\n");
664 au0828_writereg(dev, AU0828_SENSORCTRL_100, 0x0);
665 mdelay(30);
666 au0828_writereg(dev, AU0828_SENSORCTRL_100, 0xb3);
667}
668
669/*
670 * Some operations needs to stop current streaming
671 */
672static int au0828_stream_interrupt(struct au0828_dev *dev)
673{
674 int ret = 0;
675
676 dev->stream_state = STREAM_INTERRUPT;
677 if (dev->dev_state == DEV_DISCONNECTED)
678 return -ENODEV;
679 else if (ret) {
680 dev->dev_state = DEV_MISCONFIGURED;
681 dprintk(1, "%s device is misconfigured!\n", __func__);
682 return ret;
683 }
684 return 0;
685}
686
687/*
688 * au0828_release_resources
689 * unregister v4l2 devices
690 */
691void au0828_analog_unregister(struct au0828_dev *dev)
692{
693 dprintk(1, "au0828_release_resources called\n");
694 mutex_lock(&au0828_sysfs_lock);
695
696 if (dev->vdev) {
697 list_del(&dev->au0828list);
698 video_unregister_device(dev->vdev);
699 }
700 if (dev->vbi_dev)
701 video_unregister_device(dev->vbi_dev);
702
703 mutex_unlock(&au0828_sysfs_lock);
704}
705
706
707/* Usage lock check functions */
708static int res_get(struct au0828_fh *fh)
709{
710 struct au0828_dev *dev = fh->dev;
711 int rc = 0;
712
713 /* This instance already has stream_on */
714 if (fh->stream_on)
715 return rc;
716
717 if (dev->stream_on)
718 return -EBUSY;
719
720 dev->stream_on = 1;
721 fh->stream_on = 1;
722 return rc;
723}
724
725static int res_check(struct au0828_fh *fh)
726{
727 return fh->stream_on;
728}
729
730static void res_free(struct au0828_fh *fh)
731{
732 struct au0828_dev *dev = fh->dev;
733
734 fh->stream_on = 0;
735 dev->stream_on = 0;
736}
737
738static int au0828_v4l2_open(struct file *filp)
739{
740 int minor = video_devdata(filp)->minor;
741 int ret = 0;
742 struct au0828_dev *h, *dev = NULL;
743 struct au0828_fh *fh;
744 int type = 0;
745 struct list_head *list;
746
747 list_for_each(list, &au0828_devlist) {
748 h = list_entry(list, struct au0828_dev, au0828list);
749 if (h->vdev->minor == minor) {
750 dev = h;
751 type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
752 }
753#ifdef VBI_IS_WORKING
754 if (h->vbi_dev->minor == minor) {
755 dev = h;
756 type = V4L2_BUF_TYPE_VBI_CAPTURE;
757 }
758#endif
759 }
760
761 if (NULL == dev)
762 return -ENODEV;
763
764 fh = kzalloc(sizeof(struct au0828_fh), GFP_KERNEL);
765 if (NULL == fh) {
766 dprintk(1, "Failed allocate au0828_fh struct!\n");
767 return -ENOMEM;
768 }
769
770 fh->type = type;
771 fh->dev = dev;
772 filp->private_data = fh;
773
774 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && dev->users == 0) {
775 /* set au0828 interface0 to AS5 here again */
776 ret = usb_set_interface(dev->usbdev, 0, 5);
777 if (ret < 0) {
778 printk(KERN_INFO "Au0828 can't set alternate to 5!\n");
779 return -EBUSY;
780 }
781 dev->width = NTSC_STD_W;
782 dev->height = NTSC_STD_H;
783 dev->frame_size = dev->width * dev->height * 2;
784 dev->field_size = dev->width * dev->height;
785 dev->bytesperline = dev->width * 2;
786
787 au0828_analog_stream_enable(dev);
788 au0828_analog_stream_reset(dev);
789
790 /* If we were doing ac97 instead of i2s, it would go here...*/
791 au0828_i2s_init(dev);
792
793 dev->stream_state = STREAM_OFF;
794 dev->dev_state |= DEV_INITIALIZED;
795 }
796
797 dev->users++;
798
799 videobuf_queue_vmalloc_init(&fh->vb_vidq, &au0828_video_qops,
800 NULL, &dev->slock, fh->type,
801 V4L2_FIELD_INTERLACED,
802 sizeof(struct au0828_buffer), fh);
803
804 return ret;
805}
806
807static int au0828_v4l2_close(struct file *filp)
808{
809 int ret;
810 struct au0828_fh *fh = filp->private_data;
811 struct au0828_dev *dev = fh->dev;
812
813 mutex_lock(&dev->lock);
814 if (res_check(fh))
815 res_free(fh);
816
817 if (dev->users == 1) {
818 videobuf_stop(&fh->vb_vidq);
819 videobuf_mmap_free(&fh->vb_vidq);
820
821 if (dev->dev_state & DEV_DISCONNECTED) {
822 au0828_analog_unregister(dev);
823 mutex_unlock(&dev->lock);
824 kfree(dev);
825 return 0;
826 }
827
828 au0828_analog_stream_disable(dev);
829
830 au0828_uninit_isoc(dev);
831
832 /* When close the device, set the usb intf0 into alt0 to free
833 USB bandwidth */
834 ret = usb_set_interface(dev->usbdev, 0, 0);
835 if (ret < 0)
836 printk(KERN_INFO "Au0828 can't set alternate to 0!\n");
837 }
838
839 kfree(fh);
840 dev->users--;
841 wake_up_interruptible_nr(&dev->open, 1);
842 mutex_unlock(&dev->lock);
843 return 0;
844}
845
846static ssize_t au0828_v4l2_read(struct file *filp, char __user *buf,
847 size_t count, loff_t *pos)
848{
849 struct au0828_fh *fh = filp->private_data;
850 struct au0828_dev *dev = fh->dev;
851 int rc;
852
853 rc = check_dev(dev);
854 if (rc < 0)
855 return rc;
856
857 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
858 mutex_lock(&dev->lock);
859 rc = res_get(fh);
860 mutex_unlock(&dev->lock);
861
862 if (unlikely(rc < 0))
863 return rc;
864
865 return videobuf_read_stream(&fh->vb_vidq, buf, count, pos, 0,
866 filp->f_flags & O_NONBLOCK);
867 }
868 return 0;
869}
870
871static unsigned int au0828_v4l2_poll(struct file *filp, poll_table *wait)
872{
873 struct au0828_fh *fh = filp->private_data;
874 struct au0828_dev *dev = fh->dev;
875 int rc;
876
877 rc = check_dev(dev);
878 if (rc < 0)
879 return rc;
880
881 mutex_lock(&dev->lock);
882 rc = res_get(fh);
883 mutex_unlock(&dev->lock);
884
885 if (unlikely(rc < 0))
886 return POLLERR;
887
888 if (V4L2_BUF_TYPE_VIDEO_CAPTURE != fh->type)
889 return POLLERR;
890
891 return videobuf_poll_stream(filp, &fh->vb_vidq, wait);
892}
893
894static int au0828_v4l2_mmap(struct file *filp, struct vm_area_struct *vma)
895{
896 struct au0828_fh *fh = filp->private_data;
897 struct au0828_dev *dev = fh->dev;
898 int rc;
899
900 rc = check_dev(dev);
901 if (rc < 0)
902 return rc;
903
904 mutex_lock(&dev->lock);
905 rc = res_get(fh);
906 mutex_unlock(&dev->lock);
907
908 if (unlikely(rc < 0))
909 return rc;
910
911 rc = videobuf_mmap_mapper(&fh->vb_vidq, vma);
912
913 dprintk(2, "vma start=0x%08lx, size=%ld, ret=%d\n",
914 (unsigned long)vma->vm_start,
915 (unsigned long)vma->vm_end-(unsigned long)vma->vm_start,
916 rc);
917
918 return rc;
919}
920
921static int au0828_set_format(struct au0828_dev *dev, unsigned int cmd,
922 struct v4l2_format *format)
923{
924 int ret;
925 int width = format->fmt.pix.width;
926 int height = format->fmt.pix.height;
927 unsigned int maxwidth, maxheight;
928
929 maxwidth = 720;
930 maxheight = 480;
931
932#ifdef VBI_IS_WORKING
933 if (format->type == V4L2_BUF_TYPE_SLICED_VBI_CAPTURE) {
934 dprintk(1, "VBI format set: to be supported!\n");
935 return 0;
936 }
937 if (format->type == V4L2_BUF_TYPE_VBI_CAPTURE)
938 return 0;
939#endif
940 if (format->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
941 return -EINVAL;
942
943 /* If they are demanding a format other than the one we support,
944 bail out (tvtime asks for UYVY and then retries with YUYV) */
945 if (format->fmt.pix.pixelformat != V4L2_PIX_FMT_UYVY)
946 return -EINVAL;
947
948 /* format->fmt.pix.width only support 720 and height 480 */
949 if (width != 720)
950 width = 720;
951 if (height != 480)
952 height = 480;
953
954 format->fmt.pix.width = width;
955 format->fmt.pix.height = height;
956 format->fmt.pix.pixelformat = V4L2_PIX_FMT_UYVY;
957 format->fmt.pix.bytesperline = width * 2;
958 format->fmt.pix.sizeimage = width * height * 2;
959 format->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
960 format->fmt.pix.field = V4L2_FIELD_INTERLACED;
961
962 if (cmd == VIDIOC_TRY_FMT)
963 return 0;
964
965 /* maybe set new image format, driver current only support 720*480 */
966 dev->width = width;
967 dev->height = height;
968 dev->frame_size = width * height * 2;
969 dev->field_size = width * height;
970 dev->bytesperline = width * 2;
971
972 if (dev->stream_state == STREAM_ON) {
973 dprintk(1, "VIDIOC_SET_FMT: interrupting stream!\n");
974 ret = au0828_stream_interrupt(dev);
975 if (ret != 0) {
976 dprintk(1, "error interrupting video stream!\n");
977 return ret;
978 }
979 }
980
981 /* set au0828 interface0 to AS5 here again */
982 ret = usb_set_interface(dev->usbdev, 0, 5);
983 if (ret < 0) {
984 printk(KERN_INFO "Au0828 can't set alt setting to 5!\n");
985 return -EBUSY;
986 }
987
988 au0828_analog_stream_enable(dev);
989
990 return 0;
991}
992
993
994static int vidioc_queryctrl(struct file *file, void *priv,
995 struct v4l2_queryctrl *qc)
996{
997 struct au0828_fh *fh = priv;
998 struct au0828_dev *dev = fh->dev;
999 v4l2_device_call_all(&dev->v4l2_dev, 0, core, queryctrl, qc);
1000 if (qc->type)
1001 return 0;
1002 else
1003 return -EINVAL;
1004}
1005
1006static int vidioc_querycap(struct file *file, void *priv,
1007 struct v4l2_capability *cap)
1008{
1009 struct au0828_fh *fh = priv;
1010 struct au0828_dev *dev = fh->dev;
1011
1012 strlcpy(cap->driver, "au0828", sizeof(cap->driver));
1013 strlcpy(cap->card, dev->board.name, sizeof(cap->card));
1014 strlcpy(cap->bus_info, dev->v4l2_dev.name, sizeof(cap->bus_info));
1015
1016 cap->version = AU0828_VERSION_CODE;
1017
1018 /*set the device capabilities */
1019 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE |
1020#ifdef VBI_IS_WORKING
1021 V4L2_CAP_VBI_CAPTURE |
1022#endif
1023 V4L2_CAP_AUDIO |
1024 V4L2_CAP_READWRITE |
1025 V4L2_CAP_STREAMING |
1026 V4L2_CAP_TUNER;
1027 return 0;
1028}
1029
1030static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
1031 struct v4l2_fmtdesc *f)
1032{
1033 if (f->index)
1034 return -EINVAL;
1035
1036 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1037 strcpy(f->description, "Packed YUV2");
1038
1039 f->flags = 0;
1040 f->pixelformat = V4L2_PIX_FMT_UYVY;
1041
1042 return 0;
1043}
1044
1045static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
1046 struct v4l2_format *f)
1047{
1048 struct au0828_fh *fh = priv;
1049 struct au0828_dev *dev = fh->dev;
1050
1051 f->fmt.pix.width = dev->width;
1052 f->fmt.pix.height = dev->height;
1053 f->fmt.pix.pixelformat = V4L2_PIX_FMT_UYVY;
1054 f->fmt.pix.bytesperline = dev->bytesperline;
1055 f->fmt.pix.sizeimage = dev->frame_size;
1056 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; /* NTSC/PAL */
1057 f->fmt.pix.field = V4L2_FIELD_INTERLACED;
1058 return 0;
1059}
1060
1061static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
1062 struct v4l2_format *f)
1063{
1064 struct au0828_fh *fh = priv;
1065 struct au0828_dev *dev = fh->dev;
1066
1067 return au0828_set_format(dev, VIDIOC_TRY_FMT, f);
1068}
1069
1070static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
1071 struct v4l2_format *f)
1072{
1073 struct au0828_fh *fh = priv;
1074 struct au0828_dev *dev = fh->dev;
1075 int rc;
1076
1077 if (videobuf_queue_is_busy(&fh->vb_vidq)) {
1078 printk(KERN_INFO "%s queue busy\n", __func__);
1079 rc = -EBUSY;
1080 goto out;
1081 }
1082
1083 if (dev->stream_on && !fh->stream_on) {
1084 printk(KERN_INFO "%s device in use by another fh\n", __func__);
1085 rc = -EBUSY;
1086 goto out;
1087 }
1088
1089 return au0828_set_format(dev, VIDIOC_S_FMT, f);
1090out:
1091 return rc;
1092}
1093
1094static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id * norm)
1095{
1096 struct au0828_fh *fh = priv;
1097 struct au0828_dev *dev = fh->dev;
1098
1099 /* FIXME: when we support something other than NTSC, we are going to
1100 have to make the au0828 bridge adjust the size of its capture
1101 buffer, which is currently hardcoded at 720x480 */
1102
1103 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_std, *norm);
1104 return 0;
1105}
1106
1107static int vidioc_enum_input(struct file *file, void *priv,
1108 struct v4l2_input *input)
1109{
1110 struct au0828_fh *fh = priv;
1111 struct au0828_dev *dev = fh->dev;
1112 unsigned int tmp;
1113
1114 static const char *inames[] = {
1115 [AU0828_VMUX_UNDEFINED] = "Undefined",
1116 [AU0828_VMUX_COMPOSITE] = "Composite",
1117 [AU0828_VMUX_SVIDEO] = "S-Video",
1118 [AU0828_VMUX_CABLE] = "Cable TV",
1119 [AU0828_VMUX_TELEVISION] = "Television",
1120 [AU0828_VMUX_DVB] = "DVB",
1121 [AU0828_VMUX_DEBUG] = "tv debug"
1122 };
1123
1124 tmp = input->index;
1125
1126 if (tmp > AU0828_MAX_INPUT)
1127 return -EINVAL;
1128 if (AUVI_INPUT(tmp).type == 0)
1129 return -EINVAL;
1130
1131 input->index = tmp;
1132 strcpy(input->name, inames[AUVI_INPUT(tmp).type]);
1133 if ((AUVI_INPUT(tmp).type == AU0828_VMUX_TELEVISION) ||
1134 (AUVI_INPUT(tmp).type == AU0828_VMUX_CABLE))
1135 input->type |= V4L2_INPUT_TYPE_TUNER;
1136 else
1137 input->type |= V4L2_INPUT_TYPE_CAMERA;
1138
1139 input->std = dev->vdev->tvnorms;
1140
1141 return 0;
1142}
1143
1144static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
1145{
1146 struct au0828_fh *fh = priv;
1147 struct au0828_dev *dev = fh->dev;
1148 *i = dev->ctrl_input;
1149 return 0;
1150}
1151
1152static int vidioc_s_input(struct file *file, void *priv, unsigned int index)
1153{
1154 struct au0828_fh *fh = priv;
1155 struct au0828_dev *dev = fh->dev;
1156 int i;
1157 struct v4l2_routing route;
1158
1159 dprintk(1, "VIDIOC_S_INPUT in function %s, input=%d\n", __func__,
1160 index);
1161 if (index >= AU0828_MAX_INPUT)
1162 return -EINVAL;
1163 if (AUVI_INPUT(index).type == 0)
1164 return -EINVAL;
1165 dev->ctrl_input = index;
1166
1167 switch (AUVI_INPUT(index).type) {
1168 case AU0828_VMUX_SVIDEO:
1169 dev->input_type = AU0828_VMUX_SVIDEO;
1170 break;
1171 case AU0828_VMUX_COMPOSITE:
1172 dev->input_type = AU0828_VMUX_COMPOSITE;
1173 break;
1174 case AU0828_VMUX_TELEVISION:
1175 dev->input_type = AU0828_VMUX_TELEVISION;
1176 break;
1177 default:
1178 dprintk(1, "VIDIOC_S_INPUT unknown input type set [%d]\n",
1179 AUVI_INPUT(index).type);
1180 break;
1181 }
1182
1183 route.input = AUVI_INPUT(index).vmux;
1184 route.output = 0;
1185 v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_routing, &route);
1186
1187 for (i = 0; i < AU0828_MAX_INPUT; i++) {
1188 int enable = 0;
1189 if (AUVI_INPUT(i).audio_setup == NULL)
1190 continue;
1191
1192 if (i == index)
1193 enable = 1;
1194 else
1195 enable = 0;
1196 if (enable) {
1197 (AUVI_INPUT(i).audio_setup)(dev, enable);
1198 } else {
1199 /* Make sure we leave it turned on if some
1200 other input is routed to this callback */
1201 if ((AUVI_INPUT(i).audio_setup) !=
1202 ((AUVI_INPUT(index).audio_setup))) {
1203 (AUVI_INPUT(i).audio_setup)(dev, enable);
1204 }
1205 }
1206 }
1207
1208 route.input = AUVI_INPUT(index).amux;
1209 v4l2_device_call_all(&dev->v4l2_dev, 0, audio, s_routing, &route);
1210 return 0;
1211}
1212
1213static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a)
1214{
1215 struct au0828_fh *fh = priv;
1216 struct au0828_dev *dev = fh->dev;
1217 unsigned int index = a->index;
1218
1219 if (a->index > 1)
1220 return -EINVAL;
1221
1222 index = dev->ctrl_ainput;
1223 if (index == 0)
1224 strcpy(a->name, "Television");
1225 else
1226 strcpy(a->name, "Line in");
1227
1228 a->capability = V4L2_AUDCAP_STEREO;
1229 a->index = index;
1230 return 0;
1231}
1232
1233static int vidioc_s_audio(struct file *file, void *priv, struct v4l2_audio *a)
1234{
1235 struct au0828_fh *fh = priv;
1236 struct au0828_dev *dev = fh->dev;
1237 if (a->index != dev->ctrl_ainput)
1238 return -EINVAL;
1239 return 0;
1240}
1241
1242static int vidioc_g_ctrl(struct file *file, void *priv,
1243 struct v4l2_control *ctrl)
1244{
1245 struct au0828_fh *fh = priv;
1246 struct au0828_dev *dev = fh->dev;
1247
1248 v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_ctrl, ctrl);
1249 return 0;
1250
1251}
1252
1253static int vidioc_s_ctrl(struct file *file, void *priv,
1254 struct v4l2_control *ctrl)
1255{
1256 struct au0828_fh *fh = priv;
1257 struct au0828_dev *dev = fh->dev;
1258 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_ctrl, ctrl);
1259 return 0;
1260}
1261
1262static int vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
1263{
1264 struct au0828_fh *fh = priv;
1265 struct au0828_dev *dev = fh->dev;
1266
1267 if (t->index != 0)
1268 return -EINVAL;
1269
1270 strcpy(t->name, "Auvitek tuner");
1271 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_tuner, t);
1272 return 0;
1273}
1274
1275static int vidioc_s_tuner(struct file *file, void *priv,
1276 struct v4l2_tuner *t)
1277{
1278 struct au0828_fh *fh = priv;
1279 struct au0828_dev *dev = fh->dev;
1280
1281 if (t->index != 0)
1282 return -EINVAL;
1283
1284 t->type = V4L2_TUNER_ANALOG_TV;
1285 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_tuner, t);
1286 dprintk(1, "VIDIOC_S_TUNER: signal = %x, afc = %x\n", t->signal,
1287 t->afc);
1288 return 0;
1289
1290}
1291
1292static int vidioc_g_frequency(struct file *file, void *priv,
1293 struct v4l2_frequency *freq)
1294{
1295 struct au0828_fh *fh = priv;
1296 struct au0828_dev *dev = fh->dev;
1297
1298 freq->type = V4L2_TUNER_ANALOG_TV;
1299 freq->frequency = dev->ctrl_freq;
1300 return 0;
1301}
1302
1303static int vidioc_s_frequency(struct file *file, void *priv,
1304 struct v4l2_frequency *freq)
1305{
1306 struct au0828_fh *fh = priv;
1307 struct au0828_dev *dev = fh->dev;
1308
1309 if (freq->tuner != 0)
1310 return -EINVAL;
1311 if (freq->type != V4L2_TUNER_ANALOG_TV)
1312 return -EINVAL;
1313
1314 dev->ctrl_freq = freq->frequency;
1315
1316 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, freq);
1317
1318 au0828_analog_stream_reset(dev);
1319
1320 return 0;
1321}
1322
1323static int vidioc_g_chip_ident(struct file *file, void *priv,
1324 struct v4l2_dbg_chip_ident *chip)
1325{
1326 struct au0828_fh *fh = priv;
1327 struct au0828_dev *dev = fh->dev;
1328 chip->ident = V4L2_IDENT_NONE;
1329 chip->revision = 0;
1330
1331 if (v4l2_chip_match_host(&chip->match)) {
1332 chip->ident = V4L2_IDENT_AU0828;
1333 return 0;
1334 }
1335
1336 v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_chip_ident, chip);
1337 if (chip->ident == V4L2_IDENT_NONE)
1338 return -EINVAL;
1339
1340 return 0;
1341}
1342
1343static int vidioc_cropcap(struct file *file, void *priv,
1344 struct v4l2_cropcap *cc)
1345{
1346 struct au0828_fh *fh = priv;
1347 struct au0828_dev *dev = fh->dev;
1348
1349 if (cc->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1350 return -EINVAL;
1351
1352 cc->bounds.left = 0;
1353 cc->bounds.top = 0;
1354 cc->bounds.width = dev->width;
1355 cc->bounds.height = dev->height;
1356
1357 cc->defrect = cc->bounds;
1358
1359 cc->pixelaspect.numerator = 54;
1360 cc->pixelaspect.denominator = 59;
1361
1362 return 0;
1363}
1364
1365static int vidioc_streamon(struct file *file, void *priv,
1366 enum v4l2_buf_type type)
1367{
1368 struct au0828_fh *fh = priv;
1369 struct au0828_dev *dev = fh->dev;
1370 int rc;
1371
1372 rc = check_dev(dev);
1373 if (rc < 0)
1374 return rc;
1375
1376 if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1377 au0828_analog_stream_enable(dev);
1378 v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_stream, 1);
1379 }
1380
1381 mutex_lock(&dev->lock);
1382 rc = res_get(fh);
1383
1384 if (likely(rc >= 0))
1385 rc = videobuf_streamon(&fh->vb_vidq);
1386 mutex_unlock(&dev->lock);
1387
1388 return rc;
1389}
1390
1391static int vidioc_streamoff(struct file *file, void *priv,
1392 enum v4l2_buf_type type)
1393{
1394 struct au0828_fh *fh = priv;
1395 struct au0828_dev *dev = fh->dev;
1396 int i;
1397 int ret;
1398 int rc;
1399
1400 rc = check_dev(dev);
1401 if (rc < 0)
1402 return rc;
1403
1404 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1405 return -EINVAL;
1406 if (type != fh->type)
1407 return -EINVAL;
1408
1409 if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1410 v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_stream, 0);
1411 ret = au0828_stream_interrupt(dev);
1412 if (ret != 0)
1413 return ret;
1414 }
1415
1416 for (i = 0; i < AU0828_MAX_INPUT; i++) {
1417 if (AUVI_INPUT(i).audio_setup == NULL)
1418 continue;
1419 (AUVI_INPUT(i).audio_setup)(dev, 0);
1420 }
1421
1422 mutex_lock(&dev->lock);
1423 videobuf_streamoff(&fh->vb_vidq);
1424 res_free(fh);
1425 mutex_unlock(&dev->lock);
1426
1427 return 0;
1428}
1429
1430#ifdef CONFIG_VIDEO_ADV_DEBUG
1431static int vidioc_g_register(struct file *file, void *priv,
1432 struct v4l2_dbg_register *reg)
1433{
1434 struct au0828_fh *fh = priv;
1435 struct au0828_dev *dev = fh->dev;
1436
1437 switch (reg->match.type) {
1438 case V4L2_CHIP_MATCH_I2C_DRIVER:
1439 v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_register, reg);
1440 return 0;
1441 default:
1442 return -EINVAL;
1443 }
1444}
1445
1446static int vidioc_s_register(struct file *file, void *priv,
1447 struct v4l2_dbg_register *reg)
1448{
1449 struct au0828_fh *fh = priv;
1450 struct au0828_dev *dev = fh->dev;
1451
1452 switch (reg->match.type) {
1453 case V4L2_CHIP_MATCH_I2C_DRIVER:
1454 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_register, reg);
1455 return 0;
1456 default:
1457 return -EINVAL;
1458 }
1459 return 0;
1460}
1461#endif
1462
1463static int vidioc_reqbufs(struct file *file, void *priv,
1464 struct v4l2_requestbuffers *rb)
1465{
1466 struct au0828_fh *fh = priv;
1467 struct au0828_dev *dev = fh->dev;
1468 int rc;
1469
1470 rc = check_dev(dev);
1471 if (rc < 0)
1472 return rc;
1473
1474 return videobuf_reqbufs(&fh->vb_vidq, rb);
1475}
1476
1477static int vidioc_querybuf(struct file *file, void *priv,
1478 struct v4l2_buffer *b)
1479{
1480 struct au0828_fh *fh = priv;
1481 struct au0828_dev *dev = fh->dev;
1482 int rc;
1483
1484 rc = check_dev(dev);
1485 if (rc < 0)
1486 return rc;
1487
1488 return videobuf_querybuf(&fh->vb_vidq, b);
1489}
1490
1491static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *b)
1492{
1493 struct au0828_fh *fh = priv;
1494 struct au0828_dev *dev = fh->dev;
1495 int rc;
1496
1497 rc = check_dev(dev);
1498 if (rc < 0)
1499 return rc;
1500
1501 return videobuf_qbuf(&fh->vb_vidq, b);
1502}
1503
1504static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b)
1505{
1506 struct au0828_fh *fh = priv;
1507 struct au0828_dev *dev = fh->dev;
1508 int rc;
1509
1510 rc = check_dev(dev);
1511 if (rc < 0)
1512 return rc;
1513
1514 /* Workaround for a bug in the au0828 hardware design that sometimes
1515 results in the colorspace being inverted */
1516 if (dev->greenscreen_detected == 1) {
1517 dprintk(1, "Detected green frame. Resetting stream...\n");
1518 au0828_analog_stream_reset(dev);
1519 dev->greenscreen_detected = 0;
1520 }
1521
1522 return videobuf_dqbuf(&fh->vb_vidq, b, file->f_flags & O_NONBLOCK);
1523}
1524
1525#ifdef CONFIG_VIDEO_V4L1_COMPAT
1526static int vidiocgmbuf(struct file *file, void *priv, struct video_mbuf *mbuf)
1527{
1528 struct au0828_fh *fh = priv;
1529
1530 return videobuf_cgmbuf(&fh->vb_vidq, mbuf, 8);
1531}
1532#endif
1533
1534static struct v4l2_file_operations au0828_v4l_fops = {
1535 .owner = THIS_MODULE,
1536 .open = au0828_v4l2_open,
1537 .release = au0828_v4l2_close,
1538 .read = au0828_v4l2_read,
1539 .poll = au0828_v4l2_poll,
1540 .mmap = au0828_v4l2_mmap,
1541 .ioctl = video_ioctl2,
1542};
1543
1544static const struct v4l2_ioctl_ops video_ioctl_ops = {
1545 .vidioc_querycap = vidioc_querycap,
1546 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
1547 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
1548 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
1549 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
1550#ifdef VBI_IS_WORKING
1551 .vidioc_g_fmt_vbi_cap = vidioc_g_fmt_vbi_cap,
1552 .vidioc_try_fmt_vbi_cap = vidioc_s_fmt_vbi_cap,
1553 .vidioc_s_fmt_vbi_cap = vidioc_s_fmt_vbi_cap,
1554#endif
1555 .vidioc_g_audio = vidioc_g_audio,
1556 .vidioc_s_audio = vidioc_s_audio,
1557 .vidioc_cropcap = vidioc_cropcap,
1558#ifdef VBI_IS_WORKING
1559 .vidioc_g_fmt_sliced_vbi_cap = vidioc_g_fmt_sliced_vbi_cap,
1560 .vidioc_try_fmt_sliced_vbi_cap = vidioc_try_set_sliced_vbi_cap,
1561 .vidioc_s_fmt_sliced_vbi_cap = vidioc_try_set_sliced_vbi_cap,
1562#endif
1563 .vidioc_reqbufs = vidioc_reqbufs,
1564 .vidioc_querybuf = vidioc_querybuf,
1565 .vidioc_qbuf = vidioc_qbuf,
1566 .vidioc_dqbuf = vidioc_dqbuf,
1567 .vidioc_s_std = vidioc_s_std,
1568 .vidioc_enum_input = vidioc_enum_input,
1569 .vidioc_g_input = vidioc_g_input,
1570 .vidioc_s_input = vidioc_s_input,
1571 .vidioc_queryctrl = vidioc_queryctrl,
1572 .vidioc_g_ctrl = vidioc_g_ctrl,
1573 .vidioc_s_ctrl = vidioc_s_ctrl,
1574 .vidioc_streamon = vidioc_streamon,
1575 .vidioc_streamoff = vidioc_streamoff,
1576 .vidioc_g_tuner = vidioc_g_tuner,
1577 .vidioc_s_tuner = vidioc_s_tuner,
1578 .vidioc_g_frequency = vidioc_g_frequency,
1579 .vidioc_s_frequency = vidioc_s_frequency,
1580#ifdef CONFIG_VIDEO_ADV_DEBUG
1581 .vidioc_g_register = vidioc_g_register,
1582 .vidioc_s_register = vidioc_s_register,
1583#endif
1584 .vidioc_g_chip_ident = vidioc_g_chip_ident,
1585#ifdef CONFIG_VIDEO_V4L1_COMPAT
1586 .vidiocgmbuf = vidiocgmbuf,
1587#endif
1588};
1589
1590static const struct video_device au0828_video_template = {
1591 .fops = &au0828_v4l_fops,
1592 .release = video_device_release,
1593 .ioctl_ops = &video_ioctl_ops,
1594 .minor = -1,
1595 .tvnorms = V4L2_STD_NTSC_M,
1596 .current_norm = V4L2_STD_NTSC_M,
1597};
1598
1599/**************************************************************************/
1600
1601int au0828_analog_register(struct au0828_dev *dev,
1602 struct usb_interface *interface)
1603{
1604 int retval = -ENOMEM;
1605 struct usb_host_interface *iface_desc;
1606 struct usb_endpoint_descriptor *endpoint;
1607 int i;
1608
1609 dprintk(1, "au0828_analog_register called!\n");
1610
1611 /* set au0828 usb interface0 to as5 */
1612 retval = usb_set_interface(dev->usbdev,
1613 interface->cur_altsetting->desc.bInterfaceNumber, 5);
1614 if (retval != 0) {
1615 printk(KERN_INFO "Failure setting usb interface0 to as5\n");
1616 return retval;
1617 }
1618
1619 /* Figure out which endpoint has the isoc interface */
1620 iface_desc = interface->cur_altsetting;
1621 for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) {
1622 endpoint = &iface_desc->endpoint[i].desc;
1623 if (((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK)
1624 == USB_DIR_IN) &&
1625 ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
1626 == USB_ENDPOINT_XFER_ISOC)) {
1627
1628 /* we find our isoc in endpoint */
1629 u16 tmp = le16_to_cpu(endpoint->wMaxPacketSize);
1630 dev->max_pkt_size = (tmp & 0x07ff) *
1631 (((tmp & 0x1800) >> 11) + 1);
1632 dev->isoc_in_endpointaddr = endpoint->bEndpointAddress;
1633 }
1634 }
1635 if (!(dev->isoc_in_endpointaddr)) {
1636 printk(KERN_INFO "Could not locate isoc endpoint\n");
1637 kfree(dev);
1638 return -ENODEV;
1639 }
1640
1641 init_waitqueue_head(&dev->open);
1642 spin_lock_init(&dev->slock);
1643 mutex_init(&dev->lock);
1644
1645 INIT_LIST_HEAD(&dev->vidq.active);
1646 INIT_LIST_HEAD(&dev->vidq.queued);
1647
1648 dev->width = NTSC_STD_W;
1649 dev->height = NTSC_STD_H;
1650 dev->field_size = dev->width * dev->height;
1651 dev->frame_size = dev->field_size << 1;
1652 dev->bytesperline = dev->width << 1;
1653 dev->ctrl_ainput = 0;
1654
1655 /* allocate and fill v4l2 video struct */
1656 dev->vdev = video_device_alloc();
1657 if (NULL == dev->vdev) {
1658 dprintk(1, "Can't allocate video_device.\n");
1659 return -ENOMEM;
1660 }
1661
1662#ifdef VBI_IS_WORKING
1663 dev->vbi_dev = video_device_alloc();
1664 if (NULL == dev->vbi_dev) {
1665 dprintk(1, "Can't allocate vbi_device.\n");
1666 kfree(dev->vdev);
1667 return -ENOMEM;
1668 }
1669#endif
1670
1671 /* Fill the video capture device struct */
1672 *dev->vdev = au0828_video_template;
1673 dev->vdev->parent = &dev->usbdev->dev;
1674 strcpy(dev->vdev->name, "au0828a video");
1675
1676#ifdef VBI_IS_WORKING
1677 /* Setup the VBI device */
1678 *dev->vbi_dev = au0828_video_template;
1679 dev->vbi_dev->parent = &dev->usbdev->dev;
1680 strcpy(dev->vbi_dev->name, "au0828a vbi");
1681#endif
1682
1683 list_add_tail(&dev->au0828list, &au0828_devlist);
1684
1685 /* Register the v4l2 device */
1686 retval = video_register_device(dev->vdev, VFL_TYPE_GRABBER, -1);
1687 if (retval != 0) {
1688 dprintk(1, "unable to register video device (error = %d).\n",
1689 retval);
1690 list_del(&dev->au0828list);
1691 video_device_release(dev->vdev);
1692 return -ENODEV;
1693 }
1694
1695#ifdef VBI_IS_WORKING
1696 /* Register the vbi device */
1697 retval = video_register_device(dev->vbi_dev, VFL_TYPE_VBI, -1);
1698 if (retval != 0) {
1699 dprintk(1, "unable to register vbi device (error = %d).\n",
1700 retval);
1701 list_del(&dev->au0828list);
1702 video_device_release(dev->vbi_dev);
1703 video_device_release(dev->vdev);
1704 return -ENODEV;
1705 }
1706#endif
1707
1708 dprintk(1, "%s completed!\n", __func__);
1709
1710 return 0;
1711}
1712
diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
index 9d6a1161dc98..6ed1a6129731 100644
--- a/drivers/media/video/au0828/au0828.h
+++ b/drivers/media/video/au0828/au0828.h
@@ -24,6 +24,11 @@
24#include <linux/i2c-algo-bit.h> 24#include <linux/i2c-algo-bit.h>
25#include <media/tveeprom.h> 25#include <media/tveeprom.h>
26 26
27/* Analog */
28#include <linux/videodev2.h>
29#include <media/videobuf-vmalloc.h>
30#include <media/v4l2-device.h>
31
27/* DVB */ 32/* DVB */
28#include "demux.h" 33#include "demux.h"
29#include "dmxdev.h" 34#include "dmxdev.h"
@@ -39,8 +44,45 @@
39#define URB_COUNT 16 44#define URB_COUNT 16
40#define URB_BUFSIZE (0xe522) 45#define URB_BUFSIZE (0xe522)
41 46
47/* Analog constants */
48#define NTSC_STD_W 720
49#define NTSC_STD_H 480
50
51#define AU0828_INTERLACED_DEFAULT 1
52#define V4L2_CID_PRIVATE_SHARPNESS (V4L2_CID_PRIVATE_BASE + 0)
53
54/* Defination for AU0828 USB transfer */
55#define AU0828_MAX_ISO_BUFS 12 /* maybe resize this value in the future */
56#define AU0828_ISO_PACKETS_PER_URB 10
57
58#define AU0828_MIN_BUF 4
59#define AU0828_DEF_BUF 8
60
61#define AU0828_MAX_INPUT 4
62
63enum au0828_itype {
64 AU0828_VMUX_UNDEFINED = 0,
65 AU0828_VMUX_COMPOSITE,
66 AU0828_VMUX_SVIDEO,
67 AU0828_VMUX_CABLE,
68 AU0828_VMUX_TELEVISION,
69 AU0828_VMUX_DVB,
70 AU0828_VMUX_DEBUG
71};
72
73struct au0828_input {
74 enum au0828_itype type;
75 unsigned int vmux;
76 unsigned int amux;
77 void (*audio_setup) (void *priv, int enable);
78};
79
42struct au0828_board { 80struct au0828_board {
43 char *name; 81 char *name;
82 unsigned int tuner_type;
83 unsigned char tuner_addr;
84 struct au0828_input input[AU0828_MAX_INPUT];
85
44}; 86};
45 87
46struct au0828_dvb { 88struct au0828_dvb {
@@ -55,31 +97,143 @@ struct au0828_dvb {
55 int feeding; 97 int feeding;
56}; 98};
57 99
100enum au0828_stream_state {
101 STREAM_OFF,
102 STREAM_INTERRUPT,
103 STREAM_ON
104};
105
106#define AUVI_INPUT(nr) (dev->board.input[nr])
107
108/* device state */
109enum au0828_dev_state {
110 DEV_INITIALIZED = 0x01,
111 DEV_DISCONNECTED = 0x02,
112 DEV_MISCONFIGURED = 0x04
113};
114
115struct au0828_fh {
116 struct au0828_dev *dev;
117 unsigned int stream_on:1; /* Locks streams */
118 struct videobuf_queue vb_vidq;
119 enum v4l2_buf_type type;
120};
121
122struct au0828_usb_isoc_ctl {
123 /* max packet size of isoc transaction */
124 int max_pkt_size;
125
126 /* number of allocated urbs */
127 int num_bufs;
128
129 /* urb for isoc transfers */
130 struct urb **urb;
131
132 /* transfer buffers for isoc transfer */
133 char **transfer_buffer;
134
135 /* Last buffer command and region */
136 u8 cmd;
137 int pos, size, pktsize;
138
139 /* Last field: ODD or EVEN? */
140 int field;
141
142 /* Stores incomplete commands */
143 u32 tmp_buf;
144 int tmp_buf_len;
145
146 /* Stores already requested buffers */
147 struct au0828_buffer *buf;
148
149 /* Stores the number of received fields */
150 int nfields;
151
152 /* isoc urb callback */
153 int (*isoc_copy) (struct au0828_dev *dev, struct urb *urb);
154
155};
156
157/* buffer for one video frame */
158struct au0828_buffer {
159 /* common v4l buffer stuff -- must be first */
160 struct videobuf_buffer vb;
161
162 struct list_head frame;
163 int top_field;
164 int receiving;
165};
166
167struct au0828_dmaqueue {
168 struct list_head active;
169 struct list_head queued;
170
171 wait_queue_head_t wq;
172
173 /* Counters to control buffer fill */
174 int pos;
175};
176
58struct au0828_dev { 177struct au0828_dev {
59 struct mutex mutex; 178 struct mutex mutex;
60 struct usb_device *usbdev; 179 struct usb_device *usbdev;
61 int board; 180 int boardnr;
181 struct au0828_board board;
62 u8 ctrlmsg[64]; 182 u8 ctrlmsg[64];
63 183
64 /* I2C */ 184 /* I2C */
65 struct i2c_adapter i2c_adap; 185 struct i2c_adapter i2c_adap;
66 struct i2c_algo_bit_data i2c_algo; 186 struct i2c_algorithm i2c_algo;
67 struct i2c_client i2c_client; 187 struct i2c_client i2c_client;
68 u32 i2c_rc; 188 u32 i2c_rc;
69 189
70 /* Digital */ 190 /* Digital */
71 struct au0828_dvb dvb; 191 struct au0828_dvb dvb;
72 192
193 /* Analog */
194 struct list_head au0828list;
195 struct v4l2_device v4l2_dev;
196 int users;
197 unsigned int stream_on:1; /* Locks streams */
198 struct video_device *vdev;
199 struct video_device *vbi_dev;
200 int width;
201 int height;
202 u32 field_size;
203 u32 frame_size;
204 u32 bytesperline;
205 int type;
206 u8 ctrl_ainput;
207 __u8 isoc_in_endpointaddr;
208 u8 isoc_init_ok;
209 int greenscreen_detected;
210 unsigned int frame_count;
211 int ctrl_freq;
212 int input_type;
213 unsigned int ctrl_input;
214 enum au0828_dev_state dev_state;
215 enum au0828_stream_state stream_state;
216 wait_queue_head_t open;
217
218 struct mutex lock;
219
220 /* Isoc control struct */
221 struct au0828_dmaqueue vidq;
222 struct au0828_usb_isoc_ctl isoc_ctl;
223 spinlock_t slock;
224
225 /* usb transfer */
226 int alt; /* alternate */
227 int max_pkt_size; /* max packet size of isoc transaction */
228 int num_alt; /* Number of alternative settings */
229 unsigned int *alt_max_pkt_size; /* array of wMaxPacketSize */
230 struct urb *urb[AU0828_MAX_ISO_BUFS]; /* urb for isoc transfers */
231 char *transfer_buffer[AU0828_MAX_ISO_BUFS];/* transfer buffers for isoc
232 transfer */
233
73 /* USB / URB Related */ 234 /* USB / URB Related */
74 int urb_streaming; 235 int urb_streaming;
75 struct urb *urbs[URB_COUNT]; 236 struct urb *urbs[URB_COUNT];
76
77};
78
79struct au0828_buff {
80 struct au0828_dev *dev;
81 struct urb *purb;
82 struct list_head buff_list;
83}; 237};
84 238
85/* ----------------------------------------------------------- */ 239/* ----------------------------------------------------------- */
@@ -111,8 +265,13 @@ extern void au0828_card_setup(struct au0828_dev *dev);
111/* au0828-i2c.c */ 265/* au0828-i2c.c */
112extern int au0828_i2c_register(struct au0828_dev *dev); 266extern int au0828_i2c_register(struct au0828_dev *dev);
113extern int au0828_i2c_unregister(struct au0828_dev *dev); 267extern int au0828_i2c_unregister(struct au0828_dev *dev);
114extern void au0828_call_i2c_clients(struct au0828_dev *dev, 268
115 unsigned int cmd, void *arg); 269/* ----------------------------------------------------------- */
270/* au0828-video.c */
271int au0828_analog_register(struct au0828_dev *dev,
272 struct usb_interface *interface);
273int au0828_analog_stream_disable(struct au0828_dev *d);
274void au0828_analog_unregister(struct au0828_dev *dev);
116 275
117/* ----------------------------------------------------------- */ 276/* ----------------------------------------------------------- */
118/* au0828-dvb.c */ 277/* au0828-dvb.c */
diff --git a/drivers/media/video/bt819.c b/drivers/media/video/bt819.c
index a07b7b88e5b8..df4516d8dcab 100644
--- a/drivers/media/video/bt819.c
+++ b/drivers/media/video/bt819.c
@@ -29,16 +29,16 @@
29 */ 29 */
30 30
31#include <linux/module.h> 31#include <linux/module.h>
32#include <linux/delay.h>
33#include <linux/types.h> 32#include <linux/types.h>
34#include <linux/ioctl.h> 33#include <linux/ioctl.h>
35#include <asm/uaccess.h> 34#include <linux/delay.h>
36#include <linux/i2c.h> 35#include <linux/i2c.h>
37#include <linux/i2c-id.h> 36#include <linux/i2c-id.h>
38#include <linux/videodev.h> 37#include <linux/videodev2.h>
39#include <linux/video_decoder.h> 38#include <media/v4l2-device.h>
40#include <media/v4l2-common.h> 39#include <media/v4l2-chip-ident.h>
41#include <media/v4l2-i2c-drv-legacy.h> 40#include <media/v4l2-i2c-drv.h>
41#include <media/bt819.h>
42 42
43MODULE_DESCRIPTION("Brooktree-819 video decoder driver"); 43MODULE_DESCRIPTION("Brooktree-819 video decoder driver");
44MODULE_AUTHOR("Mike Bernson & Dave Perks"); 44MODULE_AUTHOR("Mike Bernson & Dave Perks");
@@ -48,13 +48,15 @@ static int debug;
48module_param(debug, int, 0); 48module_param(debug, int, 0);
49MODULE_PARM_DESC(debug, "Debug level (0-1)"); 49MODULE_PARM_DESC(debug, "Debug level (0-1)");
50 50
51
51/* ----------------------------------------------------------------------- */ 52/* ----------------------------------------------------------------------- */
52 53
53struct bt819 { 54struct bt819 {
55 struct v4l2_subdev sd;
54 unsigned char reg[32]; 56 unsigned char reg[32];
55 57
56 int initialized; 58 v4l2_std_id norm;
57 int norm; 59 int ident;
58 int input; 60 int input;
59 int enable; 61 int enable;
60 int bright; 62 int bright;
@@ -63,6 +65,11 @@ struct bt819 {
63 int sat; 65 int sat;
64}; 66};
65 67
68static inline struct bt819 *to_bt819(struct v4l2_subdev *sd)
69{
70 return container_of(sd, struct bt819, sd);
71}
72
66struct timing { 73struct timing {
67 int hactive; 74 int hactive;
68 int hdelay; 75 int hdelay;
@@ -80,24 +87,23 @@ static struct timing timing_data[] = {
80 87
81/* ----------------------------------------------------------------------- */ 88/* ----------------------------------------------------------------------- */
82 89
83static inline int bt819_write(struct i2c_client *client, u8 reg, u8 value) 90static inline int bt819_write(struct bt819 *decoder, u8 reg, u8 value)
84{ 91{
85 struct bt819 *decoder = i2c_get_clientdata(client); 92 struct i2c_client *client = v4l2_get_subdevdata(&decoder->sd);
86 93
87 decoder->reg[reg] = value; 94 decoder->reg[reg] = value;
88 return i2c_smbus_write_byte_data(client, reg, value); 95 return i2c_smbus_write_byte_data(client, reg, value);
89} 96}
90 97
91static inline int bt819_setbit(struct i2c_client *client, u8 reg, u8 bit, u8 value) 98static inline int bt819_setbit(struct bt819 *decoder, u8 reg, u8 bit, u8 value)
92{ 99{
93 struct bt819 *decoder = i2c_get_clientdata(client); 100 return bt819_write(decoder, reg,
94
95 return bt819_write(client, reg,
96 (decoder->reg[reg] & ~(1 << bit)) | (value ? (1 << bit) : 0)); 101 (decoder->reg[reg] & ~(1 << bit)) | (value ? (1 << bit) : 0));
97} 102}
98 103
99static int bt819_write_block(struct i2c_client *client, const u8 *data, unsigned int len) 104static int bt819_write_block(struct bt819 *decoder, const u8 *data, unsigned int len)
100{ 105{
106 struct i2c_client *client = v4l2_get_subdevdata(&decoder->sd);
101 int ret = -1; 107 int ret = -1;
102 u8 reg; 108 u8 reg;
103 109
@@ -105,7 +111,6 @@ static int bt819_write_block(struct i2c_client *client, const u8 *data, unsigned
105 * the adapter understands raw I2C */ 111 * the adapter understands raw I2C */
106 if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { 112 if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
107 /* do raw I2C, not smbus compatible */ 113 /* do raw I2C, not smbus compatible */
108 struct bt819 *decoder = i2c_get_clientdata(client);
109 u8 block_data[32]; 114 u8 block_data[32];
110 int block_len; 115 int block_len;
111 116
@@ -126,7 +131,8 @@ static int bt819_write_block(struct i2c_client *client, const u8 *data, unsigned
126 /* do some slow I2C emulation kind of thing */ 131 /* do some slow I2C emulation kind of thing */
127 while (len >= 2) { 132 while (len >= 2) {
128 reg = *data++; 133 reg = *data++;
129 if ((ret = bt819_write(client, reg, *data++)) < 0) 134 ret = bt819_write(decoder, reg, *data++);
135 if (ret < 0)
130 break; 136 break;
131 len -= 2; 137 len -= 2;
132 } 138 }
@@ -135,15 +141,15 @@ static int bt819_write_block(struct i2c_client *client, const u8 *data, unsigned
135 return ret; 141 return ret;
136} 142}
137 143
138static inline int bt819_read(struct i2c_client *client, u8 reg) 144static inline int bt819_read(struct bt819 *decoder, u8 reg)
139{ 145{
146 struct i2c_client *client = v4l2_get_subdevdata(&decoder->sd);
147
140 return i2c_smbus_read_byte_data(client, reg); 148 return i2c_smbus_read_byte_data(client, reg);
141} 149}
142 150
143static int bt819_init(struct i2c_client *client) 151static int bt819_init(struct v4l2_subdev *sd)
144{ 152{
145 struct bt819 *decoder = i2c_get_clientdata(client);
146
147 static unsigned char init[] = { 153 static unsigned char init[] = {
148 /*0x1f, 0x00,*/ /* Reset */ 154 /*0x1f, 0x00,*/ /* Reset */
149 0x01, 0x59, /* 0x01 input format */ 155 0x01, 0x59, /* 0x01 input format */
@@ -178,7 +184,8 @@ static int bt819_init(struct i2c_client *client)
178 0x1a, 0x80, /* 0x1a ADC Interface */ 184 0x1a, 0x80, /* 0x1a ADC Interface */
179 }; 185 };
180 186
181 struct timing *timing = &timing_data[decoder->norm]; 187 struct bt819 *decoder = to_bt819(sd);
188 struct timing *timing = &timing_data[(decoder->norm & V4L2_STD_525_60) ? 1 : 0];
182 189
183 init[0x03 * 2 - 1] = 190 init[0x03 * 2 - 1] =
184 (((timing->vdelay >> 8) & 0x03) << 6) | 191 (((timing->vdelay >> 8) & 0x03) << 6) |
@@ -192,266 +199,306 @@ static int bt819_init(struct i2c_client *client)
192 init[0x08 * 2 - 1] = timing->hscale >> 8; 199 init[0x08 * 2 - 1] = timing->hscale >> 8;
193 init[0x09 * 2 - 1] = timing->hscale & 0xff; 200 init[0x09 * 2 - 1] = timing->hscale & 0xff;
194 /* 0x15 in array is address 0x19 */ 201 /* 0x15 in array is address 0x19 */
195 init[0x15 * 2 - 1] = (decoder->norm == 0) ? 115 : 93; /* Chroma burst delay */ 202 init[0x15 * 2 - 1] = (decoder->norm & V4L2_STD_625_50) ? 115 : 93; /* Chroma burst delay */
196 /* reset */ 203 /* reset */
197 bt819_write(client, 0x1f, 0x00); 204 bt819_write(decoder, 0x1f, 0x00);
198 mdelay(1); 205 mdelay(1);
199 206
200 /* init */ 207 /* init */
201 return bt819_write_block(client, init, sizeof(init)); 208 return bt819_write_block(decoder, init, sizeof(init));
202} 209}
203 210
204/* ----------------------------------------------------------------------- */ 211/* ----------------------------------------------------------------------- */
205 212
206static int bt819_command(struct i2c_client *client, unsigned cmd, void *arg) 213static int bt819_status(struct v4l2_subdev *sd, u32 *pstatus, v4l2_std_id *pstd)
207{ 214{
208 int temp; 215 struct bt819 *decoder = to_bt819(sd);
216 int status = bt819_read(decoder, 0x00);
217 int res = V4L2_IN_ST_NO_SIGNAL;
218 v4l2_std_id std;
209 219
210 struct bt819 *decoder = i2c_get_clientdata(client); 220 if ((status & 0x80))
221 res = 0;
211 222
212 if (!decoder->initialized) { /* First call to bt819_init could be */ 223 if ((status & 0x10))
213 bt819_init(client); /* without #FRST = 0 */ 224 std = V4L2_STD_PAL;
214 decoder->initialized = 1; 225 else
215 } 226 std = V4L2_STD_NTSC;
227 if (pstd)
228 *pstd = std;
229 if (pstatus)
230 *pstatus = status;
216 231
217 switch (cmd) { 232 v4l2_dbg(1, debug, sd, "get status %x\n", status);
218 case 0: 233 return 0;
219 /* This is just for testing!!! */ 234}
220 bt819_init(client);
221 break;
222 235
223 case DECODER_GET_CAPABILITIES: 236static int bt819_querystd(struct v4l2_subdev *sd, v4l2_std_id *std)
224 { 237{
225 struct video_decoder_capability *cap = arg; 238 return bt819_status(sd, NULL, std);
239}
226 240
227 cap->flags = VIDEO_DECODER_PAL | 241static int bt819_g_input_status(struct v4l2_subdev *sd, u32 *status)
228 VIDEO_DECODER_NTSC | 242{
229 VIDEO_DECODER_AUTO | 243 return bt819_status(sd, status, NULL);
230 VIDEO_DECODER_CCIR; 244}
231 cap->inputs = 8; 245
232 cap->outputs = 1; 246static int bt819_s_std(struct v4l2_subdev *sd, v4l2_std_id std)
233 break; 247{
248 struct bt819 *decoder = to_bt819(sd);
249 struct timing *timing = NULL;
250
251 v4l2_dbg(1, debug, sd, "set norm %llx\n", (unsigned long long)std);
252
253 if (sd->v4l2_dev == NULL || sd->v4l2_dev->notify == NULL)
254 v4l2_err(sd, "no notify found!\n");
255
256 if (std & V4L2_STD_NTSC) {
257 v4l2_subdev_notify(sd, BT819_FIFO_RESET_LOW, 0);
258 bt819_setbit(decoder, 0x01, 0, 1);
259 bt819_setbit(decoder, 0x01, 1, 0);
260 bt819_setbit(decoder, 0x01, 5, 0);
261 bt819_write(decoder, 0x18, 0x68);
262 bt819_write(decoder, 0x19, 0x5d);
263 /* bt819_setbit(decoder, 0x1a, 5, 1); */
264 timing = &timing_data[1];
265 } else if (std & V4L2_STD_PAL) {
266 v4l2_subdev_notify(sd, BT819_FIFO_RESET_LOW, 0);
267 bt819_setbit(decoder, 0x01, 0, 1);
268 bt819_setbit(decoder, 0x01, 1, 1);
269 bt819_setbit(decoder, 0x01, 5, 1);
270 bt819_write(decoder, 0x18, 0x7f);
271 bt819_write(decoder, 0x19, 0x72);
272 /* bt819_setbit(decoder, 0x1a, 5, 0); */
273 timing = &timing_data[0];
274 } else {
275 v4l2_dbg(1, debug, sd, "unsupported norm %llx\n",
276 (unsigned long long)std);
277 return -EINVAL;
234 } 278 }
279 bt819_write(decoder, 0x03,
280 (((timing->vdelay >> 8) & 0x03) << 6) |
281 (((timing->vactive >> 8) & 0x03) << 4) |
282 (((timing->hdelay >> 8) & 0x03) << 2) |
283 ((timing->hactive >> 8) & 0x03));
284 bt819_write(decoder, 0x04, timing->vdelay & 0xff);
285 bt819_write(decoder, 0x05, timing->vactive & 0xff);
286 bt819_write(decoder, 0x06, timing->hdelay & 0xff);
287 bt819_write(decoder, 0x07, timing->hactive & 0xff);
288 bt819_write(decoder, 0x08, (timing->hscale >> 8) & 0xff);
289 bt819_write(decoder, 0x09, timing->hscale & 0xff);
290 decoder->norm = std;
291 v4l2_subdev_notify(sd, BT819_FIFO_RESET_HIGH, 0);
292 return 0;
293}
235 294
236 case DECODER_GET_STATUS: 295static int bt819_s_routing(struct v4l2_subdev *sd, const struct v4l2_routing *route)
237 { 296{
238 int *iarg = arg; 297 struct bt819 *decoder = to_bt819(sd);
239 int status;
240 int res;
241 298
242 status = bt819_read(client, 0x00); 299 v4l2_dbg(1, debug, sd, "set input %x\n", route->input);
243 res = 0;
244 if ((status & 0x80))
245 res |= DECODER_STATUS_GOOD;
246 300
247 switch (decoder->norm) { 301 if (route->input < 0 || route->input > 7)
248 case VIDEO_MODE_NTSC: 302 return -EINVAL;
249 res |= DECODER_STATUS_NTSC;
250 break;
251 case VIDEO_MODE_PAL:
252 res |= DECODER_STATUS_PAL;
253 break;
254 default:
255 case VIDEO_MODE_AUTO:
256 if ((status & 0x10))
257 res |= DECODER_STATUS_PAL;
258 else
259 res |= DECODER_STATUS_NTSC;
260 break;
261 }
262 res |= DECODER_STATUS_COLOR;
263 *iarg = res;
264 303
265 v4l_dbg(1, debug, client, "get status %x\n", *iarg); 304 if (sd->v4l2_dev == NULL || sd->v4l2_dev->notify == NULL)
266 break; 305 v4l2_err(sd, "no notify found!\n");
306
307 if (decoder->input != route->input) {
308 v4l2_subdev_notify(sd, BT819_FIFO_RESET_LOW, 0);
309 decoder->input = route->input;
310 /* select mode */
311 if (decoder->input == 0) {
312 bt819_setbit(decoder, 0x0b, 6, 0);
313 bt819_setbit(decoder, 0x1a, 1, 1);
314 } else {
315 bt819_setbit(decoder, 0x0b, 6, 1);
316 bt819_setbit(decoder, 0x1a, 1, 0);
317 }
318 v4l2_subdev_notify(sd, BT819_FIFO_RESET_HIGH, 0);
267 } 319 }
320 return 0;
321}
268 322
269 case DECODER_SET_NORM: 323static int bt819_s_stream(struct v4l2_subdev *sd, int enable)
270 { 324{
271 int *iarg = arg; 325 struct bt819 *decoder = to_bt819(sd);
272 struct timing *timing = NULL;
273
274 v4l_dbg(1, debug, client, "set norm %x\n", *iarg);
275
276 switch (*iarg) {
277 case VIDEO_MODE_NTSC:
278 bt819_setbit(client, 0x01, 0, 1);
279 bt819_setbit(client, 0x01, 1, 0);
280 bt819_setbit(client, 0x01, 5, 0);
281 bt819_write(client, 0x18, 0x68);
282 bt819_write(client, 0x19, 0x5d);
283 /* bt819_setbit(client, 0x1a, 5, 1); */
284 timing = &timing_data[VIDEO_MODE_NTSC];
285 break;
286 case VIDEO_MODE_PAL:
287 bt819_setbit(client, 0x01, 0, 1);
288 bt819_setbit(client, 0x01, 1, 1);
289 bt819_setbit(client, 0x01, 5, 1);
290 bt819_write(client, 0x18, 0x7f);
291 bt819_write(client, 0x19, 0x72);
292 /* bt819_setbit(client, 0x1a, 5, 0); */
293 timing = &timing_data[VIDEO_MODE_PAL];
294 break;
295 case VIDEO_MODE_AUTO:
296 bt819_setbit(client, 0x01, 0, 0);
297 bt819_setbit(client, 0x01, 1, 0);
298 break;
299 default:
300 v4l_dbg(1, debug, client, "unsupported norm %x\n", *iarg);
301 return -EINVAL;
302 }
303 326
304 if (timing) { 327 v4l2_dbg(1, debug, sd, "enable output %x\n", enable);
305 bt819_write(client, 0x03,
306 (((timing->vdelay >> 8) & 0x03) << 6) |
307 (((timing->vactive >> 8) & 0x03) << 4) |
308 (((timing->hdelay >> 8) & 0x03) << 2) |
309 ((timing->hactive >> 8) & 0x03) );
310 bt819_write(client, 0x04, timing->vdelay & 0xff);
311 bt819_write(client, 0x05, timing->vactive & 0xff);
312 bt819_write(client, 0x06, timing->hdelay & 0xff);
313 bt819_write(client, 0x07, timing->hactive & 0xff);
314 bt819_write(client, 0x08, (timing->hscale >> 8) & 0xff);
315 bt819_write(client, 0x09, timing->hscale & 0xff);
316 }
317 328
318 decoder->norm = *iarg; 329 if (decoder->enable != enable) {
319 break; 330 decoder->enable = enable;
331 bt819_setbit(decoder, 0x16, 7, !enable);
320 } 332 }
333 return 0;
334}
321 335
322 case DECODER_SET_INPUT: 336static int bt819_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc)
323 { 337{
324 int *iarg = arg; 338 switch (qc->id) {
325 339 case V4L2_CID_BRIGHTNESS:
326 v4l_dbg(1, debug, client, "set input %x\n", *iarg); 340 v4l2_ctrl_query_fill(qc, -128, 127, 1, 0);
327
328 if (*iarg < 0 || *iarg > 7)
329 return -EINVAL;
330
331 if (decoder->input != *iarg) {
332 decoder->input = *iarg;
333 /* select mode */
334 if (decoder->input == 0) {
335 bt819_setbit(client, 0x0b, 6, 0);
336 bt819_setbit(client, 0x1a, 1, 1);
337 } else {
338 bt819_setbit(client, 0x0b, 6, 1);
339 bt819_setbit(client, 0x1a, 1, 0);
340 }
341 }
342 break; 341 break;
343 }
344 342
345 case DECODER_SET_OUTPUT: 343 case V4L2_CID_CONTRAST:
346 { 344 v4l2_ctrl_query_fill(qc, 0, 511, 1, 256);
347 int *iarg = arg; 345 break;
348 346
349 v4l_dbg(1, debug, client, "set output %x\n", *iarg); 347 case V4L2_CID_SATURATION:
348 v4l2_ctrl_query_fill(qc, 0, 511, 1, 256);
349 break;
350 350
351 /* not much choice of outputs */ 351 case V4L2_CID_HUE:
352 if (*iarg != 0) 352 v4l2_ctrl_query_fill(qc, -128, 127, 1, 0);
353 return -EINVAL;
354 break; 353 break;
355 }
356 354
357 case DECODER_ENABLE_OUTPUT: 355 default:
358 { 356 return -EINVAL;
359 int *iarg = arg; 357 }
360 int enable = (*iarg != 0); 358 return 0;
359}
361 360
362 v4l_dbg(1, debug, client, "enable output %x\n", *iarg); 361static int bt819_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
362{
363 struct bt819 *decoder = to_bt819(sd);
364 int temp;
363 365
364 if (decoder->enable != enable) { 366 switch (ctrl->id) {
365 decoder->enable = enable; 367 case V4L2_CID_BRIGHTNESS:
366 bt819_setbit(client, 0x16, 7, !enable); 368 if (decoder->bright == ctrl->value)
367 } 369 break;
370 decoder->bright = ctrl->value;
371 bt819_write(decoder, 0x0a, decoder->bright);
368 break; 372 break;
369 }
370 373
371 case DECODER_SET_PICTURE: 374 case V4L2_CID_CONTRAST:
372 { 375 if (decoder->contrast == ctrl->value)
373 struct video_picture *pic = arg; 376 break;
374 377 decoder->contrast = ctrl->value;
375 v4l_dbg(1, debug, client, 378 bt819_write(decoder, 0x0c, decoder->contrast & 0xff);
376 "set picture brightness %d contrast %d colour %d\n", 379 bt819_setbit(decoder, 0x0b, 2, ((decoder->contrast >> 8) & 0x01));
377 pic->brightness, pic->contrast, pic->colour); 380 break;
378 381
382 case V4L2_CID_SATURATION:
383 if (decoder->sat == ctrl->value)
384 break;
385 decoder->sat = ctrl->value;
386 bt819_write(decoder, 0x0d, (decoder->sat >> 7) & 0xff);
387 bt819_setbit(decoder, 0x0b, 1, ((decoder->sat >> 15) & 0x01));
388
389 /* Ratio between U gain and V gain must stay the same as
390 the ratio between the default U and V gain values. */
391 temp = (decoder->sat * 180) / 254;
392 bt819_write(decoder, 0x0e, (temp >> 7) & 0xff);
393 bt819_setbit(decoder, 0x0b, 0, (temp >> 15) & 0x01);
394 break;
379 395
380 if (decoder->bright != pic->brightness) { 396 case V4L2_CID_HUE:
381 /* We want -128 to 127 we get 0-65535 */ 397 if (decoder->hue == ctrl->value)
382 decoder->bright = pic->brightness; 398 break;
383 bt819_write(client, 0x0a, 399 decoder->hue = ctrl->value;
384 (decoder->bright >> 8) - 128); 400 bt819_write(decoder, 0x0f, decoder->hue);
385 } 401 break;
386 402
387 if (decoder->contrast != pic->contrast) { 403 default:
388 /* We want 0 to 511 we get 0-65535 */ 404 return -EINVAL;
389 decoder->contrast = pic->contrast; 405 }
390 bt819_write(client, 0x0c, 406 return 0;
391 (decoder->contrast >> 7) & 0xff); 407}
392 bt819_setbit(client, 0x0b, 2,
393 ((decoder->contrast >> 15) & 0x01));
394 }
395 408
396 if (decoder->sat != pic->colour) { 409static int bt819_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
397 /* We want 0 to 511 we get 0-65535 */ 410{
398 decoder->sat = pic->colour; 411 struct bt819 *decoder = to_bt819(sd);
399 bt819_write(client, 0x0d,
400 (decoder->sat >> 7) & 0xff);
401 bt819_setbit(client, 0x0b, 1,
402 ((decoder->sat >> 15) & 0x01));
403
404 temp = (decoder->sat * 201) / 237;
405 bt819_write(client, 0x0e, (temp >> 7) & 0xff);
406 bt819_setbit(client, 0x0b, 0, (temp >> 15) & 0x01);
407 }
408 412
409 if (decoder->hue != pic->hue) { 413 switch (ctrl->id) {
410 /* We want -128 to 127 we get 0-65535 */ 414 case V4L2_CID_BRIGHTNESS:
411 decoder->hue = pic->hue; 415 ctrl->value = decoder->bright;
412 bt819_write(client, 0x0f, 416 break;
413 128 - (decoder->hue >> 8)); 417 case V4L2_CID_CONTRAST:
414 } 418 ctrl->value = decoder->contrast;
419 break;
420 case V4L2_CID_SATURATION:
421 ctrl->value = decoder->sat;
422 break;
423 case V4L2_CID_HUE:
424 ctrl->value = decoder->hue;
415 break; 425 break;
416 }
417
418 default: 426 default:
419 return -EINVAL; 427 return -EINVAL;
420 } 428 }
421
422 return 0; 429 return 0;
423} 430}
424 431
432static int bt819_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
433{
434 struct bt819 *decoder = to_bt819(sd);
435 struct i2c_client *client = v4l2_get_subdevdata(sd);
436
437 return v4l2_chip_ident_i2c_client(client, chip, decoder->ident, 0);
438}
439
425/* ----------------------------------------------------------------------- */ 440/* ----------------------------------------------------------------------- */
426 441
427static unsigned short normal_i2c[] = { 0x8a >> 1, I2C_CLIENT_END }; 442static const struct v4l2_subdev_core_ops bt819_core_ops = {
443 .g_chip_ident = bt819_g_chip_ident,
444 .g_ctrl = bt819_g_ctrl,
445 .s_ctrl = bt819_s_ctrl,
446 .queryctrl = bt819_queryctrl,
447};
448
449static const struct v4l2_subdev_tuner_ops bt819_tuner_ops = {
450 .s_std = bt819_s_std,
451};
452
453static const struct v4l2_subdev_video_ops bt819_video_ops = {
454 .s_routing = bt819_s_routing,
455 .s_stream = bt819_s_stream,
456 .querystd = bt819_querystd,
457 .g_input_status = bt819_g_input_status,
458};
459
460static const struct v4l2_subdev_ops bt819_ops = {
461 .core = &bt819_core_ops,
462 .tuner = &bt819_tuner_ops,
463 .video = &bt819_video_ops,
464};
428 465
429I2C_CLIENT_INSMOD; 466/* ----------------------------------------------------------------------- */
430 467
431static int bt819_probe(struct i2c_client *client, 468static int bt819_probe(struct i2c_client *client,
432 const struct i2c_device_id *id) 469 const struct i2c_device_id *id)
433{ 470{
434 int i, ver; 471 int i, ver;
435 struct bt819 *decoder; 472 struct bt819 *decoder;
473 struct v4l2_subdev *sd;
436 const char *name; 474 const char *name;
437 475
438 /* Check if the adapter supports the needed features */ 476 /* Check if the adapter supports the needed features */
439 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 477 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
440 return -ENODEV; 478 return -ENODEV;
441 479
442 ver = bt819_read(client, 0x17); 480 decoder = kzalloc(sizeof(struct bt819), GFP_KERNEL);
481 if (decoder == NULL)
482 return -ENOMEM;
483 sd = &decoder->sd;
484 v4l2_i2c_subdev_init(sd, client, &bt819_ops);
485
486 ver = bt819_read(decoder, 0x17);
443 switch (ver & 0xf0) { 487 switch (ver & 0xf0) {
444 case 0x70: 488 case 0x70:
445 name = "bt819a"; 489 name = "bt819a";
490 decoder->ident = V4L2_IDENT_BT819A;
446 break; 491 break;
447 case 0x60: 492 case 0x60:
448 name = "bt817a"; 493 name = "bt817a";
494 decoder->ident = V4L2_IDENT_BT817A;
449 break; 495 break;
450 case 0x20: 496 case 0x20:
451 name = "bt815a"; 497 name = "bt815a";
498 decoder->ident = V4L2_IDENT_BT815A;
452 break; 499 break;
453 default: 500 default:
454 v4l_dbg(1, debug, client, 501 v4l2_dbg(1, debug, sd,
455 "unknown chip version 0x%02x\n", ver); 502 "unknown chip version 0x%02x\n", ver);
456 return -ENODEV; 503 return -ENODEV;
457 } 504 }
@@ -459,28 +506,26 @@ static int bt819_probe(struct i2c_client *client,
459 v4l_info(client, "%s found @ 0x%x (%s)\n", name, 506 v4l_info(client, "%s found @ 0x%x (%s)\n", name,
460 client->addr << 1, client->adapter->name); 507 client->addr << 1, client->adapter->name);
461 508
462 decoder = kzalloc(sizeof(struct bt819), GFP_KERNEL); 509 decoder->norm = V4L2_STD_NTSC;
463 if (decoder == NULL)
464 return -ENOMEM;
465 decoder->norm = VIDEO_MODE_NTSC;
466 decoder->input = 0; 510 decoder->input = 0;
467 decoder->enable = 1; 511 decoder->enable = 1;
468 decoder->bright = 32768; 512 decoder->bright = 0;
469 decoder->contrast = 32768; 513 decoder->contrast = 0xd8; /* 100% of original signal */
470 decoder->hue = 32768; 514 decoder->hue = 0;
471 decoder->sat = 32768; 515 decoder->sat = 0xfe; /* 100% of original signal */
472 decoder->initialized = 0; 516
473 i2c_set_clientdata(client, decoder); 517 i = bt819_init(sd);
474
475 i = bt819_init(client);
476 if (i < 0) 518 if (i < 0)
477 v4l_dbg(1, debug, client, "init status %d\n", i); 519 v4l2_dbg(1, debug, sd, "init status %d\n", i);
478 return 0; 520 return 0;
479} 521}
480 522
481static int bt819_remove(struct i2c_client *client) 523static int bt819_remove(struct i2c_client *client)
482{ 524{
483 kfree(i2c_get_clientdata(client)); 525 struct v4l2_subdev *sd = i2c_get_clientdata(client);
526
527 v4l2_device_unregister_subdev(sd);
528 kfree(to_bt819(sd));
484 return 0; 529 return 0;
485} 530}
486 531
@@ -496,8 +541,6 @@ MODULE_DEVICE_TABLE(i2c, bt819_id);
496 541
497static struct v4l2_i2c_driver_data v4l2_i2c_data = { 542static struct v4l2_i2c_driver_data v4l2_i2c_data = {
498 .name = "bt819", 543 .name = "bt819",
499 .driverid = I2C_DRIVERID_BT819,
500 .command = bt819_command,
501 .probe = bt819_probe, 544 .probe = bt819_probe,
502 .remove = bt819_remove, 545 .remove = bt819_remove,
503 .id_table = bt819_id, 546 .id_table = bt819_id,
diff --git a/drivers/media/video/bt856.c b/drivers/media/video/bt856.c
index 4213867507f8..78db39503947 100644
--- a/drivers/media/video/bt856.c
+++ b/drivers/media/video/bt856.c
@@ -34,10 +34,10 @@
34#include <asm/uaccess.h> 34#include <asm/uaccess.h>
35#include <linux/i2c.h> 35#include <linux/i2c.h>
36#include <linux/i2c-id.h> 36#include <linux/i2c-id.h>
37#include <linux/videodev.h> 37#include <linux/videodev2.h>
38#include <linux/video_encoder.h> 38#include <media/v4l2-device.h>
39#include <media/v4l2-common.h> 39#include <media/v4l2-chip-ident.h>
40#include <media/v4l2-i2c-drv-legacy.h> 40#include <media/v4l2-i2c-drv.h>
41 41
42MODULE_DESCRIPTION("Brooktree-856A video encoder driver"); 42MODULE_DESCRIPTION("Brooktree-856A video encoder driver");
43MODULE_AUTHOR("Mike Bernson & Dave Perks"); 43MODULE_AUTHOR("Mike Bernson & Dave Perks");
@@ -47,43 +47,46 @@ static int debug;
47module_param(debug, int, 0); 47module_param(debug, int, 0);
48MODULE_PARM_DESC(debug, "Debug level (0-1)"); 48MODULE_PARM_DESC(debug, "Debug level (0-1)");
49 49
50
50/* ----------------------------------------------------------------------- */ 51/* ----------------------------------------------------------------------- */
51 52
52#define BT856_REG_OFFSET 0xDA 53#define BT856_REG_OFFSET 0xDA
53#define BT856_NR_REG 6 54#define BT856_NR_REG 6
54 55
55struct bt856 { 56struct bt856 {
57 struct v4l2_subdev sd;
56 unsigned char reg[BT856_NR_REG]; 58 unsigned char reg[BT856_NR_REG];
57 59
58 int norm; 60 v4l2_std_id norm;
59 int enable;
60}; 61};
61 62
63static inline struct bt856 *to_bt856(struct v4l2_subdev *sd)
64{
65 return container_of(sd, struct bt856, sd);
66}
67
62/* ----------------------------------------------------------------------- */ 68/* ----------------------------------------------------------------------- */
63 69
64static inline int bt856_write(struct i2c_client *client, u8 reg, u8 value) 70static inline int bt856_write(struct bt856 *encoder, u8 reg, u8 value)
65{ 71{
66 struct bt856 *encoder = i2c_get_clientdata(client); 72 struct i2c_client *client = v4l2_get_subdevdata(&encoder->sd);
67 73
68 encoder->reg[reg - BT856_REG_OFFSET] = value; 74 encoder->reg[reg - BT856_REG_OFFSET] = value;
69 return i2c_smbus_write_byte_data(client, reg, value); 75 return i2c_smbus_write_byte_data(client, reg, value);
70} 76}
71 77
72static inline int bt856_setbit(struct i2c_client *client, u8 reg, u8 bit, u8 value) 78static inline int bt856_setbit(struct bt856 *encoder, u8 reg, u8 bit, u8 value)
73{ 79{
74 struct bt856 *encoder = i2c_get_clientdata(client); 80 return bt856_write(encoder, reg,
75
76 return bt856_write(client, reg,
77 (encoder->reg[reg - BT856_REG_OFFSET] & ~(1 << bit)) | 81 (encoder->reg[reg - BT856_REG_OFFSET] & ~(1 << bit)) |
78 (value ? (1 << bit) : 0)); 82 (value ? (1 << bit) : 0));
79} 83}
80 84
81static void bt856_dump(struct i2c_client *client) 85static void bt856_dump(struct bt856 *encoder)
82{ 86{
83 int i; 87 int i;
84 struct bt856 *encoder = i2c_get_clientdata(client);
85 88
86 v4l_info(client, "register dump:\n"); 89 v4l2_info(&encoder->sd, "register dump:\n");
87 for (i = 0; i < BT856_NR_REG; i += 2) 90 for (i = 0; i < BT856_NR_REG; i += 2)
88 printk(KERN_CONT " %02x", encoder->reg[i]); 91 printk(KERN_CONT " %02x", encoder->reg[i]);
89 printk(KERN_CONT "\n"); 92 printk(KERN_CONT "\n");
@@ -91,153 +94,120 @@ static void bt856_dump(struct i2c_client *client)
91 94
92/* ----------------------------------------------------------------------- */ 95/* ----------------------------------------------------------------------- */
93 96
94static int bt856_command(struct i2c_client *client, unsigned cmd, void *arg) 97static int bt856_init(struct v4l2_subdev *sd, u32 arg)
95{ 98{
96 struct bt856 *encoder = i2c_get_clientdata(client); 99 struct bt856 *encoder = to_bt856(sd);
97 100
98 switch (cmd) { 101 /* This is just for testing!!! */
99 case 0: 102 v4l2_dbg(1, debug, sd, "init\n");
100 /* This is just for testing!!! */ 103 bt856_write(encoder, 0xdc, 0x18);
101 v4l_dbg(1, debug, client, "init\n"); 104 bt856_write(encoder, 0xda, 0);
102 bt856_write(client, 0xdc, 0x18); 105 bt856_write(encoder, 0xde, 0);
103 bt856_write(client, 0xda, 0); 106
104 bt856_write(client, 0xde, 0); 107 bt856_setbit(encoder, 0xdc, 3, 1);
105 108 /*bt856_setbit(encoder, 0xdc, 6, 0);*/
106 bt856_setbit(client, 0xdc, 3, 1); 109 bt856_setbit(encoder, 0xdc, 4, 1);
107 //bt856_setbit(client, 0xdc, 6, 0); 110
108 bt856_setbit(client, 0xdc, 4, 1); 111 if (encoder->norm & V4L2_STD_NTSC)
109 112 bt856_setbit(encoder, 0xdc, 2, 0);
110 switch (encoder->norm) { 113 else
111 case VIDEO_MODE_NTSC: 114 bt856_setbit(encoder, 0xdc, 2, 1);
112 bt856_setbit(client, 0xdc, 2, 0); 115
113 break; 116 bt856_setbit(encoder, 0xdc, 1, 1);
114 117 bt856_setbit(encoder, 0xde, 4, 0);
115 case VIDEO_MODE_PAL: 118 bt856_setbit(encoder, 0xde, 3, 1);
116 bt856_setbit(client, 0xdc, 2, 1); 119 if (debug != 0)
117 break; 120 bt856_dump(encoder);
118 } 121 return 0;
119 122}
120 bt856_setbit(client, 0xdc, 1, 1);
121 bt856_setbit(client, 0xde, 4, 0);
122 bt856_setbit(client, 0xde, 3, 1);
123 if (debug != 0)
124 bt856_dump(client);
125 break;
126
127 case ENCODER_GET_CAPABILITIES:
128 {
129 struct video_encoder_capability *cap = arg;
130
131 v4l_dbg(1, debug, client, "get capabilities\n");
132 123
133 cap->flags = VIDEO_ENCODER_PAL | 124static int bt856_s_std_output(struct v4l2_subdev *sd, v4l2_std_id std)
134 VIDEO_ENCODER_NTSC | 125{
135 VIDEO_ENCODER_CCIR; 126 struct bt856 *encoder = to_bt856(sd);
136 cap->inputs = 2;
137 cap->outputs = 1;
138 break;
139 }
140 127
141 case ENCODER_SET_NORM: 128 v4l2_dbg(1, debug, sd, "set norm %llx\n", (unsigned long long)std);
142 {
143 int *iarg = arg;
144
145 v4l_dbg(1, debug, client, "set norm %d\n", *iarg);
146
147 switch (*iarg) {
148 case VIDEO_MODE_NTSC:
149 bt856_setbit(client, 0xdc, 2, 0);
150 break;
151
152 case VIDEO_MODE_PAL:
153 bt856_setbit(client, 0xdc, 2, 1);
154 bt856_setbit(client, 0xda, 0, 0);
155 //bt856_setbit(client, 0xda, 0, 1);
156 break;
157
158 default:
159 return -EINVAL;
160 }
161 encoder->norm = *iarg;
162 if (debug != 0)
163 bt856_dump(client);
164 break;
165 }
166 129
167 case ENCODER_SET_INPUT: 130 if (std & V4L2_STD_NTSC) {
168 { 131 bt856_setbit(encoder, 0xdc, 2, 0);
169 int *iarg = arg; 132 } else if (std & V4L2_STD_PAL) {
170 133 bt856_setbit(encoder, 0xdc, 2, 1);
171 v4l_dbg(1, debug, client, "set input %d\n", *iarg); 134 bt856_setbit(encoder, 0xda, 0, 0);
172 135 /*bt856_setbit(encoder, 0xda, 0, 1);*/
173 /* We only have video bus. 136 } else {
174 * iarg = 0: input is from bt819 137 return -EINVAL;
175 * iarg = 1: input is from ZR36060 */
176 switch (*iarg) {
177 case 0:
178 bt856_setbit(client, 0xde, 4, 0);
179 bt856_setbit(client, 0xde, 3, 1);
180 bt856_setbit(client, 0xdc, 3, 1);
181 bt856_setbit(client, 0xdc, 6, 0);
182 break;
183 case 1:
184 bt856_setbit(client, 0xde, 4, 0);
185 bt856_setbit(client, 0xde, 3, 1);
186 bt856_setbit(client, 0xdc, 3, 1);
187 bt856_setbit(client, 0xdc, 6, 1);
188 break;
189 case 2: // Color bar
190 bt856_setbit(client, 0xdc, 3, 0);
191 bt856_setbit(client, 0xde, 4, 1);
192 break;
193 default:
194 return -EINVAL;
195 }
196
197 if (debug != 0)
198 bt856_dump(client);
199 break;
200 } 138 }
139 encoder->norm = std;
140 if (debug != 0)
141 bt856_dump(encoder);
142 return 0;
143}
201 144
202 case ENCODER_SET_OUTPUT: 145static int bt856_s_routing(struct v4l2_subdev *sd, const struct v4l2_routing *route)
203 { 146{
204 int *iarg = arg; 147 struct bt856 *encoder = to_bt856(sd);
205 148
206 v4l_dbg(1, debug, client, "set output %d\n", *iarg); 149 v4l2_dbg(1, debug, sd, "set input %d\n", route->input);
207 150
208 /* not much choice of outputs */ 151 /* We only have video bus.
209 if (*iarg != 0) 152 * route->input= 0: input is from bt819
210 return -EINVAL; 153 * route->input= 1: input is from ZR36060 */
154 switch (route->input) {
155 case 0:
156 bt856_setbit(encoder, 0xde, 4, 0);
157 bt856_setbit(encoder, 0xde, 3, 1);
158 bt856_setbit(encoder, 0xdc, 3, 1);
159 bt856_setbit(encoder, 0xdc, 6, 0);
211 break; 160 break;
212 } 161 case 1:
213 162 bt856_setbit(encoder, 0xde, 4, 0);
214 case ENCODER_ENABLE_OUTPUT: 163 bt856_setbit(encoder, 0xde, 3, 1);
215 { 164 bt856_setbit(encoder, 0xdc, 3, 1);
216 int *iarg = arg; 165 bt856_setbit(encoder, 0xdc, 6, 1);
217 166 break;
218 encoder->enable = !!*iarg; 167 case 2: /* Color bar */
219 168 bt856_setbit(encoder, 0xdc, 3, 0);
220 v4l_dbg(1, debug, client, "enable output %d\n", encoder->enable); 169 bt856_setbit(encoder, 0xde, 4, 1);
221 break; 170 break;
222 }
223
224 default: 171 default:
225 return -EINVAL; 172 return -EINVAL;
226 } 173 }
227 174
175 if (debug != 0)
176 bt856_dump(encoder);
228 return 0; 177 return 0;
229} 178}
230 179
180static int bt856_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
181{
182 struct i2c_client *client = v4l2_get_subdevdata(sd);
183
184 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_BT856, 0);
185}
186
231/* ----------------------------------------------------------------------- */ 187/* ----------------------------------------------------------------------- */
232 188
233static unsigned short normal_i2c[] = { 0x88 >> 1, I2C_CLIENT_END }; 189static const struct v4l2_subdev_core_ops bt856_core_ops = {
190 .g_chip_ident = bt856_g_chip_ident,
191 .init = bt856_init,
192};
193
194static const struct v4l2_subdev_video_ops bt856_video_ops = {
195 .s_std_output = bt856_s_std_output,
196 .s_routing = bt856_s_routing,
197};
234 198
235I2C_CLIENT_INSMOD; 199static const struct v4l2_subdev_ops bt856_ops = {
200 .core = &bt856_core_ops,
201 .video = &bt856_video_ops,
202};
203
204/* ----------------------------------------------------------------------- */
236 205
237static int bt856_probe(struct i2c_client *client, 206static int bt856_probe(struct i2c_client *client,
238 const struct i2c_device_id *id) 207 const struct i2c_device_id *id)
239{ 208{
240 struct bt856 *encoder; 209 struct bt856 *encoder;
210 struct v4l2_subdev *sd;
241 211
242 /* Check if the adapter supports the needed features */ 212 /* Check if the adapter supports the needed features */
243 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 213 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
@@ -249,41 +219,38 @@ static int bt856_probe(struct i2c_client *client,
249 encoder = kzalloc(sizeof(struct bt856), GFP_KERNEL); 219 encoder = kzalloc(sizeof(struct bt856), GFP_KERNEL);
250 if (encoder == NULL) 220 if (encoder == NULL)
251 return -ENOMEM; 221 return -ENOMEM;
252 encoder->norm = VIDEO_MODE_NTSC; 222 sd = &encoder->sd;
253 encoder->enable = 1; 223 v4l2_i2c_subdev_init(sd, client, &bt856_ops);
254 i2c_set_clientdata(client, encoder); 224 encoder->norm = V4L2_STD_NTSC;
255 225
256 bt856_write(client, 0xdc, 0x18); 226 bt856_write(encoder, 0xdc, 0x18);
257 bt856_write(client, 0xda, 0); 227 bt856_write(encoder, 0xda, 0);
258 bt856_write(client, 0xde, 0); 228 bt856_write(encoder, 0xde, 0);
259 229
260 bt856_setbit(client, 0xdc, 3, 1); 230 bt856_setbit(encoder, 0xdc, 3, 1);
261 //bt856_setbit(client, 0xdc, 6, 0); 231 /*bt856_setbit(encoder, 0xdc, 6, 0);*/
262 bt856_setbit(client, 0xdc, 4, 1); 232 bt856_setbit(encoder, 0xdc, 4, 1);
263 233
264 switch (encoder->norm) { 234 if (encoder->norm & V4L2_STD_NTSC)
235 bt856_setbit(encoder, 0xdc, 2, 0);
236 else
237 bt856_setbit(encoder, 0xdc, 2, 1);
265 238
266 case VIDEO_MODE_NTSC: 239 bt856_setbit(encoder, 0xdc, 1, 1);
267 bt856_setbit(client, 0xdc, 2, 0); 240 bt856_setbit(encoder, 0xde, 4, 0);
268 break; 241 bt856_setbit(encoder, 0xde, 3, 1);
269
270 case VIDEO_MODE_PAL:
271 bt856_setbit(client, 0xdc, 2, 1);
272 break;
273 }
274
275 bt856_setbit(client, 0xdc, 1, 1);
276 bt856_setbit(client, 0xde, 4, 0);
277 bt856_setbit(client, 0xde, 3, 1);
278 242
279 if (debug != 0) 243 if (debug != 0)
280 bt856_dump(client); 244 bt856_dump(encoder);
281 return 0; 245 return 0;
282} 246}
283 247
284static int bt856_remove(struct i2c_client *client) 248static int bt856_remove(struct i2c_client *client)
285{ 249{
286 kfree(i2c_get_clientdata(client)); 250 struct v4l2_subdev *sd = i2c_get_clientdata(client);
251
252 v4l2_device_unregister_subdev(sd);
253 kfree(to_bt856(sd));
287 return 0; 254 return 0;
288} 255}
289 256
@@ -295,8 +262,6 @@ MODULE_DEVICE_TABLE(i2c, bt856_id);
295 262
296static struct v4l2_i2c_driver_data v4l2_i2c_data = { 263static struct v4l2_i2c_driver_data v4l2_i2c_data = {
297 .name = "bt856", 264 .name = "bt856",
298 .driverid = I2C_DRIVERID_BT856,
299 .command = bt856_command,
300 .probe = bt856_probe, 265 .probe = bt856_probe,
301 .remove = bt856_remove, 266 .remove = bt856_remove,
302 .id_table = bt856_id, 267 .id_table = bt856_id,
diff --git a/drivers/media/video/bt866.c b/drivers/media/video/bt866.c
index 596f9e2376be..350cae4b02c3 100644
--- a/drivers/media/video/bt866.c
+++ b/drivers/media/video/bt866.c
@@ -34,10 +34,10 @@
34#include <asm/uaccess.h> 34#include <asm/uaccess.h>
35#include <linux/i2c.h> 35#include <linux/i2c.h>
36#include <linux/i2c-id.h> 36#include <linux/i2c-id.h>
37#include <linux/videodev.h> 37#include <linux/videodev2.h>
38#include <linux/video_encoder.h> 38#include <media/v4l2-device.h>
39#include <media/v4l2-common.h> 39#include <media/v4l2-chip-ident.h>
40#include <media/v4l2-i2c-drv-legacy.h> 40#include <media/v4l2-i2c-drv.h>
41 41
42MODULE_DESCRIPTION("Brooktree-866 video encoder driver"); 42MODULE_DESCRIPTION("Brooktree-866 video encoder driver");
43MODULE_AUTHOR("Mike Bernson & Dave Perks"); 43MODULE_AUTHOR("Mike Bernson & Dave Perks");
@@ -47,22 +47,22 @@ static int debug;
47module_param(debug, int, 0); 47module_param(debug, int, 0);
48MODULE_PARM_DESC(debug, "Debug level (0-1)"); 48MODULE_PARM_DESC(debug, "Debug level (0-1)");
49 49
50
50/* ----------------------------------------------------------------------- */ 51/* ----------------------------------------------------------------------- */
51 52
52struct bt866 { 53struct bt866 {
54 struct v4l2_subdev sd;
53 u8 reg[256]; 55 u8 reg[256];
54
55 int norm;
56 int enable;
57 int bright;
58 int contrast;
59 int hue;
60 int sat;
61}; 56};
62 57
63static int bt866_write(struct i2c_client *client, u8 subaddr, u8 data) 58static inline struct bt866 *to_bt866(struct v4l2_subdev *sd)
64{ 59{
65 struct bt866 *encoder = i2c_get_clientdata(client); 60 return container_of(sd, struct bt866, sd);
61}
62
63static int bt866_write(struct bt866 *encoder, u8 subaddr, u8 data)
64{
65 struct i2c_client *client = v4l2_get_subdevdata(&encoder->sd);
66 u8 buffer[2]; 66 u8 buffer[2];
67 int err; 67 int err;
68 68
@@ -89,163 +89,120 @@ static int bt866_write(struct i2c_client *client, u8 subaddr, u8 data)
89 return 0; 89 return 0;
90} 90}
91 91
92static int bt866_command(struct i2c_client *client, unsigned cmd, void *arg) 92static int bt866_s_std_output(struct v4l2_subdev *sd, v4l2_std_id std)
93{ 93{
94 struct bt866 *encoder = i2c_get_clientdata(client); 94 v4l2_dbg(1, debug, sd, "set norm %llx\n", (unsigned long long)std);
95
96 switch (cmd) {
97 case ENCODER_GET_CAPABILITIES:
98 {
99 struct video_encoder_capability *cap = arg;
100
101 v4l_dbg(1, debug, client, "get capabilities\n");
102
103 cap->flags
104 = VIDEO_ENCODER_PAL
105 | VIDEO_ENCODER_NTSC
106 | VIDEO_ENCODER_CCIR;
107 cap->inputs = 2;
108 cap->outputs = 1;
109 break;
110 }
111
112 case ENCODER_SET_NORM:
113 {
114 int *iarg = arg;
115
116 v4l_dbg(1, debug, client, "set norm %d\n", *iarg);
117
118 switch (*iarg) {
119 case VIDEO_MODE_NTSC:
120 break;
121
122 case VIDEO_MODE_PAL:
123 break;
124
125 default:
126 return -EINVAL;
127 }
128 encoder->norm = *iarg;
129 break;
130 }
131
132 case ENCODER_SET_INPUT:
133 {
134 int *iarg = arg;
135 static const __u8 init[] = {
136 0xc8, 0xcc, /* CRSCALE */
137 0xca, 0x91, /* CBSCALE */
138 0xcc, 0x24, /* YC16 | OSDNUM */
139 0xda, 0x00, /* */
140 0xdc, 0x24, /* SETMODE | PAL */
141 0xde, 0x02, /* EACTIVE */
142
143 /* overlay colors */
144 0x70, 0xEB, 0x90, 0x80, 0xB0, 0x80, /* white */
145 0x72, 0xA2, 0x92, 0x8E, 0xB2, 0x2C, /* yellow */
146 0x74, 0x83, 0x94, 0x2C, 0xB4, 0x9C, /* cyan */
147 0x76, 0x70, 0x96, 0x3A, 0xB6, 0x48, /* green */
148 0x78, 0x54, 0x98, 0xC6, 0xB8, 0xB8, /* magenta */
149 0x7A, 0x41, 0x9A, 0xD4, 0xBA, 0x64, /* red */
150 0x7C, 0x23, 0x9C, 0x72, 0xBC, 0xD4, /* blue */
151 0x7E, 0x10, 0x9E, 0x80, 0xBE, 0x80, /* black */
152
153 0x60, 0xEB, 0x80, 0x80, 0xc0, 0x80, /* white */
154 0x62, 0xA2, 0x82, 0x8E, 0xc2, 0x2C, /* yellow */
155 0x64, 0x83, 0x84, 0x2C, 0xc4, 0x9C, /* cyan */
156 0x66, 0x70, 0x86, 0x3A, 0xc6, 0x48, /* green */
157 0x68, 0x54, 0x88, 0xC6, 0xc8, 0xB8, /* magenta */
158 0x6A, 0x41, 0x8A, 0xD4, 0xcA, 0x64, /* red */
159 0x6C, 0x23, 0x8C, 0x72, 0xcC, 0xD4, /* blue */
160 0x6E, 0x10, 0x8E, 0x80, 0xcE, 0x80, /* black */
161 };
162 int i;
163 u8 val;
164
165 for (i = 0; i < ARRAY_SIZE(init) / 2; i += 2)
166 bt866_write(client, init[i], init[i+1]);
167
168 val = encoder->reg[0xdc];
169
170 if (*iarg == 0)
171 val |= 0x40; /* CBSWAP */
172 else
173 val &= ~0x40; /* !CBSWAP */
174
175 bt866_write(client, 0xdc, val);
176
177 val = encoder->reg[0xcc];
178 if (*iarg == 2)
179 val |= 0x01; /* OSDBAR */
180 else
181 val &= ~0x01; /* !OSDBAR */
182 bt866_write(client, 0xcc, val);
183
184 v4l_dbg(1, debug, client, "set input %d\n", *iarg);
185
186 switch (*iarg) {
187 case 0:
188 break;
189 case 1:
190 break;
191 default:
192 return -EINVAL;
193 }
194 break;
195 }
196
197 case ENCODER_SET_OUTPUT:
198 {
199 int *iarg = arg;
200
201 v4l_dbg(1, debug, client, "set output %d\n", *iarg);
202
203 /* not much choice of outputs */
204 if (*iarg != 0)
205 return -EINVAL;
206 break;
207 }
208
209 case ENCODER_ENABLE_OUTPUT:
210 {
211 int *iarg = arg;
212 encoder->enable = !!*iarg;
213 95
214 v4l_dbg(1, debug, client, "enable output %d\n", encoder->enable); 96 /* Only PAL supported by this driver at the moment! */
215 break; 97 if (!(std & V4L2_STD_NTSC))
216 } 98 return -EINVAL;
217 99 return 0;
218 case 4711: 100}
219 {
220 int *iarg = arg;
221 __u8 val;
222
223 v4l_dbg(1, debug, client, "square %d\n", *iarg);
224 101
225 val = encoder->reg[0xdc]; 102static int bt866_s_routing(struct v4l2_subdev *sd, const struct v4l2_routing *route)
226 if (*iarg) 103{
227 val |= 1; /* SQUARE */ 104 static const __u8 init[] = {
228 else 105 0xc8, 0xcc, /* CRSCALE */
229 val &= ~1; /* !SQUARE */ 106 0xca, 0x91, /* CBSCALE */
230 bt866_write(client, 0xdc, val); 107 0xcc, 0x24, /* YC16 | OSDNUM */
108 0xda, 0x00, /* */
109 0xdc, 0x24, /* SETMODE | PAL */
110 0xde, 0x02, /* EACTIVE */
111
112 /* overlay colors */
113 0x70, 0xEB, 0x90, 0x80, 0xB0, 0x80, /* white */
114 0x72, 0xA2, 0x92, 0x8E, 0xB2, 0x2C, /* yellow */
115 0x74, 0x83, 0x94, 0x2C, 0xB4, 0x9C, /* cyan */
116 0x76, 0x70, 0x96, 0x3A, 0xB6, 0x48, /* green */
117 0x78, 0x54, 0x98, 0xC6, 0xB8, 0xB8, /* magenta */
118 0x7A, 0x41, 0x9A, 0xD4, 0xBA, 0x64, /* red */
119 0x7C, 0x23, 0x9C, 0x72, 0xBC, 0xD4, /* blue */
120 0x7E, 0x10, 0x9E, 0x80, 0xBE, 0x80, /* black */
121
122 0x60, 0xEB, 0x80, 0x80, 0xc0, 0x80, /* white */
123 0x62, 0xA2, 0x82, 0x8E, 0xc2, 0x2C, /* yellow */
124 0x64, 0x83, 0x84, 0x2C, 0xc4, 0x9C, /* cyan */
125 0x66, 0x70, 0x86, 0x3A, 0xc6, 0x48, /* green */
126 0x68, 0x54, 0x88, 0xC6, 0xc8, 0xB8, /* magenta */
127 0x6A, 0x41, 0x8A, 0xD4, 0xcA, 0x64, /* red */
128 0x6C, 0x23, 0x8C, 0x72, 0xcC, 0xD4, /* blue */
129 0x6E, 0x10, 0x8E, 0x80, 0xcE, 0x80, /* black */
130 };
131 struct bt866 *encoder = to_bt866(sd);
132 u8 val;
133 int i;
134
135 for (i = 0; i < ARRAY_SIZE(init) / 2; i += 2)
136 bt866_write(encoder, init[i], init[i+1]);
137
138 val = encoder->reg[0xdc];
139
140 if (route->input == 0)
141 val |= 0x40; /* CBSWAP */
142 else
143 val &= ~0x40; /* !CBSWAP */
144
145 bt866_write(encoder, 0xdc, val);
146
147 val = encoder->reg[0xcc];
148 if (route->input == 2)
149 val |= 0x01; /* OSDBAR */
150 else
151 val &= ~0x01; /* !OSDBAR */
152 bt866_write(encoder, 0xcc, val);
153
154 v4l2_dbg(1, debug, sd, "set input %d\n", route->input);
155
156 switch (route->input) {
157 case 0:
158 case 1:
159 case 2:
231 break; 160 break;
232 }
233
234 default: 161 default:
235 return -EINVAL; 162 return -EINVAL;
236 } 163 }
237
238 return 0; 164 return 0;
239} 165}
240 166
241static unsigned short normal_i2c[] = { 0x88 >> 1, I2C_CLIENT_END }; 167#if 0
168/* Code to setup square pixels, might be of some use in the future,
169 but is currently unused. */
170 val = encoder->reg[0xdc];
171 if (*iarg)
172 val |= 1; /* SQUARE */
173 else
174 val &= ~1; /* !SQUARE */
175 bt866_write(client, 0xdc, val);
176#endif
177
178static int bt866_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
179{
180 struct i2c_client *client = v4l2_get_subdevdata(sd);
181
182 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_BT866, 0);
183}
184
185/* ----------------------------------------------------------------------- */
186
187static const struct v4l2_subdev_core_ops bt866_core_ops = {
188 .g_chip_ident = bt866_g_chip_ident,
189};
190
191static const struct v4l2_subdev_video_ops bt866_video_ops = {
192 .s_std_output = bt866_s_std_output,
193 .s_routing = bt866_s_routing,
194};
242 195
243I2C_CLIENT_INSMOD; 196static const struct v4l2_subdev_ops bt866_ops = {
197 .core = &bt866_core_ops,
198 .video = &bt866_video_ops,
199};
244 200
245static int bt866_probe(struct i2c_client *client, 201static int bt866_probe(struct i2c_client *client,
246 const struct i2c_device_id *id) 202 const struct i2c_device_id *id)
247{ 203{
248 struct bt866 *encoder; 204 struct bt866 *encoder;
205 struct v4l2_subdev *sd;
249 206
250 v4l_info(client, "chip found @ 0x%x (%s)\n", 207 v4l_info(client, "chip found @ 0x%x (%s)\n",
251 client->addr << 1, client->adapter->name); 208 client->addr << 1, client->adapter->name);
@@ -253,20 +210,18 @@ static int bt866_probe(struct i2c_client *client,
253 encoder = kzalloc(sizeof(*encoder), GFP_KERNEL); 210 encoder = kzalloc(sizeof(*encoder), GFP_KERNEL);
254 if (encoder == NULL) 211 if (encoder == NULL)
255 return -ENOMEM; 212 return -ENOMEM;
256 213 sd = &encoder->sd;
257 i2c_set_clientdata(client, encoder); 214 v4l2_i2c_subdev_init(sd, client, &bt866_ops);
258 return 0; 215 return 0;
259} 216}
260 217
261static int bt866_remove(struct i2c_client *client) 218static int bt866_remove(struct i2c_client *client)
262{ 219{
263 kfree(i2c_get_clientdata(client)); 220 struct v4l2_subdev *sd = i2c_get_clientdata(client);
264 return 0;
265}
266 221
267static int bt866_legacy_probe(struct i2c_adapter *adapter) 222 v4l2_device_unregister_subdev(sd);
268{ 223 kfree(to_bt866(sd));
269 return adapter->id == I2C_HW_B_ZR36067; 224 return 0;
270} 225}
271 226
272static const struct i2c_device_id bt866_id[] = { 227static const struct i2c_device_id bt866_id[] = {
@@ -277,10 +232,7 @@ MODULE_DEVICE_TABLE(i2c, bt866_id);
277 232
278static struct v4l2_i2c_driver_data v4l2_i2c_data = { 233static struct v4l2_i2c_driver_data v4l2_i2c_data = {
279 .name = "bt866", 234 .name = "bt866",
280 .driverid = I2C_DRIVERID_BT866,
281 .command = bt866_command,
282 .probe = bt866_probe, 235 .probe = bt866_probe,
283 .remove = bt866_remove, 236 .remove = bt866_remove,
284 .legacy_probe = bt866_legacy_probe,
285 .id_table = bt866_id, 237 .id_table = bt866_id,
286}; 238};
diff --git a/drivers/media/video/bt8xx/Kconfig b/drivers/media/video/bt8xx/Kconfig
index ce71e8e7b835..3077c45015f5 100644
--- a/drivers/media/video/bt8xx/Kconfig
+++ b/drivers/media/video/bt8xx/Kconfig
@@ -10,7 +10,7 @@ config VIDEO_BT848
10 select VIDEO_MSP3400 if VIDEO_HELPER_CHIPS_AUTO 10 select VIDEO_MSP3400 if VIDEO_HELPER_CHIPS_AUTO
11 select VIDEO_TVAUDIO if VIDEO_HELPER_CHIPS_AUTO 11 select VIDEO_TVAUDIO if VIDEO_HELPER_CHIPS_AUTO
12 select VIDEO_TDA7432 if VIDEO_HELPER_CHIPS_AUTO 12 select VIDEO_TDA7432 if VIDEO_HELPER_CHIPS_AUTO
13 select VIDEO_TDA9875 if VIDEO_HELPER_CHIPS_AUTO 13 select VIDEO_SAA6588 if VIDEO_HELPER_CHIPS_AUTO
14 ---help--- 14 ---help---
15 Support for BT848 based frame grabber/overlay boards. This includes 15 Support for BT848 based frame grabber/overlay boards. This includes
16 the Miro, Hauppauge and STB boards. Please read the material in 16 the Miro, Hauppauge and STB boards. Please read the material in
diff --git a/drivers/media/video/bt8xx/bttv-cards.c b/drivers/media/video/bt8xx/bttv-cards.c
index d24dcc025e37..b9c3ba51fb86 100644
--- a/drivers/media/video/bt8xx/bttv-cards.c
+++ b/drivers/media/video/bt8xx/bttv-cards.c
@@ -73,6 +73,11 @@ static void sigmaSQ_muxsel(struct bttv *btv, unsigned int input);
73 73
74static void geovision_muxsel(struct bttv *btv, unsigned int input); 74static void geovision_muxsel(struct bttv *btv, unsigned int input);
75 75
76static void phytec_muxsel(struct bttv *btv, unsigned int input);
77
78static void gv800s_muxsel(struct bttv *btv, unsigned int input);
79static void gv800s_init(struct bttv *btv);
80
76static int terratec_active_radio_upgrade(struct bttv *btv); 81static int terratec_active_radio_upgrade(struct bttv *btv);
77static int tea5757_read(struct bttv *btv); 82static int tea5757_read(struct bttv *btv);
78static int tea5757_write(struct bttv *btv, int value); 83static int tea5757_write(struct bttv *btv, int value);
@@ -91,12 +96,10 @@ static unsigned int pll[BTTV_MAX] = { [ 0 ... (BTTV_MAX-1) ] = UNSET };
91static unsigned int tuner[BTTV_MAX] = { [ 0 ... (BTTV_MAX-1) ] = UNSET }; 96static unsigned int tuner[BTTV_MAX] = { [ 0 ... (BTTV_MAX-1) ] = UNSET };
92static unsigned int svhs[BTTV_MAX] = { [ 0 ... (BTTV_MAX-1) ] = UNSET }; 97static unsigned int svhs[BTTV_MAX] = { [ 0 ... (BTTV_MAX-1) ] = UNSET };
93static unsigned int remote[BTTV_MAX] = { [ 0 ... (BTTV_MAX-1) ] = UNSET }; 98static unsigned int remote[BTTV_MAX] = { [ 0 ... (BTTV_MAX-1) ] = UNSET };
99static unsigned int audiodev[BTTV_MAX];
100static unsigned int saa6588[BTTV_MAX];
94static struct bttv *master[BTTV_MAX] = { [ 0 ... (BTTV_MAX-1) ] = NULL }; 101static struct bttv *master[BTTV_MAX] = { [ 0 ... (BTTV_MAX-1) ] = NULL };
95#ifdef MODULE 102static unsigned int autoload = UNSET;
96static unsigned int autoload = 1;
97#else
98static unsigned int autoload;
99#endif
100static unsigned int gpiomask = UNSET; 103static unsigned int gpiomask = UNSET;
101static unsigned int audioall = UNSET; 104static unsigned int audioall = UNSET;
102static unsigned int audiomux[5] = { [ 0 ... 4 ] = UNSET }; 105static unsigned int audiomux[5] = { [ 0 ... 4 ] = UNSET };
@@ -115,6 +118,7 @@ module_param_array(pll, int, NULL, 0444);
115module_param_array(tuner, int, NULL, 0444); 118module_param_array(tuner, int, NULL, 0444);
116module_param_array(svhs, int, NULL, 0444); 119module_param_array(svhs, int, NULL, 0444);
117module_param_array(remote, int, NULL, 0444); 120module_param_array(remote, int, NULL, 0444);
121module_param_array(audiodev, int, NULL, 0444);
118module_param_array(audiomux, int, NULL, 0444); 122module_param_array(audiomux, int, NULL, 0444);
119 123
120MODULE_PARM_DESC(triton1,"set ETBF pci config bit " 124MODULE_PARM_DESC(triton1,"set ETBF pci config bit "
@@ -125,7 +129,14 @@ MODULE_PARM_DESC(latency,"pci latency timer");
125MODULE_PARM_DESC(card,"specify TV/grabber card model, see CARDLIST file for a list"); 129MODULE_PARM_DESC(card,"specify TV/grabber card model, see CARDLIST file for a list");
126MODULE_PARM_DESC(pll,"specify installed crystal (0=none, 28=28 MHz, 35=35 MHz)"); 130MODULE_PARM_DESC(pll,"specify installed crystal (0=none, 28=28 MHz, 35=35 MHz)");
127MODULE_PARM_DESC(tuner,"specify installed tuner type"); 131MODULE_PARM_DESC(tuner,"specify installed tuner type");
128MODULE_PARM_DESC(autoload,"automatically load i2c modules like tuner.o, default is 1 (yes)"); 132MODULE_PARM_DESC(autoload, "obsolete option, please do not use anymore");
133MODULE_PARM_DESC(audiodev, "specify audio device:\n"
134 "\t\t-1 = no audio\n"
135 "\t\t 0 = autodetect (default)\n"
136 "\t\t 1 = msp3400\n"
137 "\t\t 2 = tda7432\n"
138 "\t\t 3 = tvaudio");
139MODULE_PARM_DESC(saa6588, "if 1, then load the saa6588 RDS module, default (0) is to use the card definition.");
129MODULE_PARM_DESC(no_overlay,"allow override overlay default (0 disables, 1 enables)" 140MODULE_PARM_DESC(no_overlay,"allow override overlay default (0 disables, 1 enables)"
130 " [some VIA/SIS chipsets are known to have problem with overlay]"); 141 " [some VIA/SIS chipsets are known to have problem with overlay]");
131 142
@@ -246,6 +257,10 @@ static struct CARD {
246 { 0xa182ff0d, BTTV_BOARD_IVC120, "IVC-120G" }, 257 { 0xa182ff0d, BTTV_BOARD_IVC120, "IVC-120G" },
247 { 0xa182ff0e, BTTV_BOARD_IVC120, "IVC-120G" }, 258 { 0xa182ff0e, BTTV_BOARD_IVC120, "IVC-120G" },
248 { 0xa182ff0f, BTTV_BOARD_IVC120, "IVC-120G" }, 259 { 0xa182ff0f, BTTV_BOARD_IVC120, "IVC-120G" },
260 { 0xf0500000, BTTV_BOARD_IVCE8784, "IVCE-8784" },
261 { 0xf0500001, BTTV_BOARD_IVCE8784, "IVCE-8784" },
262 { 0xf0500002, BTTV_BOARD_IVCE8784, "IVCE-8784" },
263 { 0xf0500003, BTTV_BOARD_IVCE8784, "IVCE-8784" },
249 264
250 { 0x41424344, BTTV_BOARD_GRANDTEC, "GrandTec Multi Capture" }, 265 { 0x41424344, BTTV_BOARD_GRANDTEC, "GrandTec Multi Capture" },
251 { 0x01020304, BTTV_BOARD_XGUARD, "Grandtec Grand X-Guard" }, 266 { 0x01020304, BTTV_BOARD_XGUARD, "Grandtec Grand X-Guard" },
@@ -289,6 +304,8 @@ static struct CARD {
289 /* Duplicate PCI ID, reconfigure for this board during the eeprom read. 304 /* Duplicate PCI ID, reconfigure for this board during the eeprom read.
290 * { 0x13eb0070, BTTV_BOARD_HAUPPAUGE_IMPACTVCB, "Hauppauge ImpactVCB" }, */ 305 * { 0x13eb0070, BTTV_BOARD_HAUPPAUGE_IMPACTVCB, "Hauppauge ImpactVCB" }, */
291 306
307 { 0x109e036e, BTTV_BOARD_CONCEPTRONIC_CTVFMI2, "Conceptronic CTVFMi v2"},
308
292 /* DVB cards (using pci function .1 for mpeg data xfer) */ 309 /* DVB cards (using pci function .1 for mpeg data xfer) */
293 { 0x001c11bd, BTTV_BOARD_PINNACLESAT, "Pinnacle PCTV Sat" }, 310 { 0x001c11bd, BTTV_BOARD_PINNACLESAT, "Pinnacle PCTV Sat" },
294 { 0x01010071, BTTV_BOARD_NEBULA_DIGITV, "Nebula Electronics DigiTV" }, 311 { 0x01010071, BTTV_BOARD_NEBULA_DIGITV, "Nebula Electronics DigiTV" },
@@ -305,6 +322,20 @@ static struct CARD {
305 { 0xd200dbc0, BTTV_BOARD_DVICO_FUSIONHDTV_2, "DViCO FusionHDTV 2" }, 322 { 0xd200dbc0, BTTV_BOARD_DVICO_FUSIONHDTV_2, "DViCO FusionHDTV 2" },
306 { 0x763c008a, BTTV_BOARD_GEOVISION_GV600, "GeoVision GV-600" }, 323 { 0x763c008a, BTTV_BOARD_GEOVISION_GV600, "GeoVision GV-600" },
307 { 0x18011000, BTTV_BOARD_ENLTV_FM_2, "Encore ENL TV-FM-2" }, 324 { 0x18011000, BTTV_BOARD_ENLTV_FM_2, "Encore ENL TV-FM-2" },
325 { 0x763d800a, BTTV_BOARD_GEOVISION_GV800S, "GeoVision GV-800(S) (master)" },
326 { 0x763d800b, BTTV_BOARD_GEOVISION_GV800S_SL, "GeoVision GV-800(S) (slave)" },
327 { 0x763d800c, BTTV_BOARD_GEOVISION_GV800S_SL, "GeoVision GV-800(S) (slave)" },
328 { 0x763d800d, BTTV_BOARD_GEOVISION_GV800S_SL, "GeoVision GV-800(S) (slave)" },
329
330 { 0x15401830, BTTV_BOARD_PV183, "Provideo PV183-1" },
331 { 0x15401831, BTTV_BOARD_PV183, "Provideo PV183-2" },
332 { 0x15401832, BTTV_BOARD_PV183, "Provideo PV183-3" },
333 { 0x15401833, BTTV_BOARD_PV183, "Provideo PV183-4" },
334 { 0x15401834, BTTV_BOARD_PV183, "Provideo PV183-5" },
335 { 0x15401835, BTTV_BOARD_PV183, "Provideo PV183-6" },
336 { 0x15401836, BTTV_BOARD_PV183, "Provideo PV183-7" },
337 { 0x15401837, BTTV_BOARD_PV183, "Provideo PV183-8" },
338
308 { 0, -1, NULL } 339 { 0, -1, NULL }
309}; 340};
310 341
@@ -316,59 +347,50 @@ struct tvcard bttv_tvcards[] = {
316 [BTTV_BOARD_UNKNOWN] = { 347 [BTTV_BOARD_UNKNOWN] = {
317 .name = " *** UNKNOWN/GENERIC *** ", 348 .name = " *** UNKNOWN/GENERIC *** ",
318 .video_inputs = 4, 349 .video_inputs = 4,
319 .audio_inputs = 1,
320 .tuner = 0,
321 .svhs = 2, 350 .svhs = 2,
322 .muxsel = { 2, 3, 1, 0 }, 351 .muxsel = MUXSEL(2, 3, 1, 0),
323 .tuner_type = UNSET, 352 .tuner_type = UNSET,
324 .tuner_addr = ADDR_UNSET, 353 .tuner_addr = ADDR_UNSET,
325 .radio_addr = ADDR_UNSET,
326 }, 354 },
327 [BTTV_BOARD_MIRO] = { 355 [BTTV_BOARD_MIRO] = {
328 .name = "MIRO PCTV", 356 .name = "MIRO PCTV",
329 .video_inputs = 4, 357 .video_inputs = 4,
330 .audio_inputs = 1, 358 /* .audio_inputs= 1, */
331 .tuner = 0,
332 .svhs = 2, 359 .svhs = 2,
333 .gpiomask = 15, 360 .gpiomask = 15,
334 .muxsel = { 2, 3, 1, 1 }, 361 .muxsel = MUXSEL(2, 3, 1, 1),
335 .gpiomux = { 2, 0, 0, 0 }, 362 .gpiomux = { 2, 0, 0, 0 },
336 .gpiomute = 10, 363 .gpiomute = 10,
337 .needs_tvaudio = 1, 364 .needs_tvaudio = 1,
338 .tuner_type = UNSET, 365 .tuner_type = UNSET,
339 .tuner_addr = ADDR_UNSET, 366 .tuner_addr = ADDR_UNSET,
340 .radio_addr = ADDR_UNSET,
341 }, 367 },
342 [BTTV_BOARD_HAUPPAUGE] = { 368 [BTTV_BOARD_HAUPPAUGE] = {
343 .name = "Hauppauge (bt848)", 369 .name = "Hauppauge (bt848)",
344 .video_inputs = 4, 370 .video_inputs = 4,
345 .audio_inputs = 1, 371 /* .audio_inputs= 1, */
346 .tuner = 0,
347 .svhs = 2, 372 .svhs = 2,
348 .gpiomask = 7, 373 .gpiomask = 7,
349 .muxsel = { 2, 3, 1, 1 }, 374 .muxsel = MUXSEL(2, 3, 1, 1),
350 .gpiomux = { 0, 1, 2, 3 }, 375 .gpiomux = { 0, 1, 2, 3 },
351 .gpiomute = 4, 376 .gpiomute = 4,
352 .needs_tvaudio = 1, 377 .needs_tvaudio = 1,
353 .tuner_type = UNSET, 378 .tuner_type = UNSET,
354 .tuner_addr = ADDR_UNSET, 379 .tuner_addr = ADDR_UNSET,
355 .radio_addr = ADDR_UNSET,
356 }, 380 },
357 [BTTV_BOARD_STB] = { 381 [BTTV_BOARD_STB] = {
358 .name = "STB, Gateway P/N 6000699 (bt848)", 382 .name = "STB, Gateway P/N 6000699 (bt848)",
359 .video_inputs = 3, 383 .video_inputs = 3,
360 .audio_inputs = 1, 384 /* .audio_inputs= 1, */
361 .tuner = 0,
362 .svhs = 2, 385 .svhs = 2,
363 .gpiomask = 7, 386 .gpiomask = 7,
364 .muxsel = { 2, 3, 1, 1 }, 387 .muxsel = MUXSEL(2, 3, 1, 1),
365 .gpiomux = { 4, 0, 2, 3 }, 388 .gpiomux = { 4, 0, 2, 3 },
366 .gpiomute = 1, 389 .gpiomute = 1,
367 .no_msp34xx = 1, 390 .no_msp34xx = 1,
368 .needs_tvaudio = 1, 391 .needs_tvaudio = 1,
369 .tuner_type = TUNER_PHILIPS_NTSC, 392 .tuner_type = TUNER_PHILIPS_NTSC,
370 .tuner_addr = ADDR_UNSET, 393 .tuner_addr = ADDR_UNSET,
371 .radio_addr = ADDR_UNSET,
372 .pll = PLL_28, 394 .pll = PLL_28,
373 .has_radio = 1, 395 .has_radio = 1,
374 }, 396 },
@@ -377,202 +399,177 @@ struct tvcard bttv_tvcards[] = {
377 [BTTV_BOARD_INTEL] = { 399 [BTTV_BOARD_INTEL] = {
378 .name = "Intel Create and Share PCI/ Smart Video Recorder III", 400 .name = "Intel Create and Share PCI/ Smart Video Recorder III",
379 .video_inputs = 4, 401 .video_inputs = 4,
380 .audio_inputs = 0, 402 /* .audio_inputs= 0, */
381 .tuner = UNSET,
382 .svhs = 2, 403 .svhs = 2,
383 .gpiomask = 0, 404 .gpiomask = 0,
384 .muxsel = { 2, 3, 1, 1 }, 405 .muxsel = MUXSEL(2, 3, 1, 1),
385 .gpiomux = { 0 }, 406 .gpiomux = { 0 },
386 .needs_tvaudio = 0, 407 .needs_tvaudio = 0,
387 .tuner_type = TUNER_ABSENT, 408 .tuner_type = TUNER_ABSENT,
388 .tuner_addr = ADDR_UNSET, 409 .tuner_addr = ADDR_UNSET,
389 .radio_addr = ADDR_UNSET,
390 }, 410 },
391 [BTTV_BOARD_DIAMOND] = { 411 [BTTV_BOARD_DIAMOND] = {
392 .name = "Diamond DTV2000", 412 .name = "Diamond DTV2000",
393 .video_inputs = 4, 413 .video_inputs = 4,
394 .audio_inputs = 1, 414 /* .audio_inputs= 1, */
395 .tuner = 0,
396 .svhs = 2, 415 .svhs = 2,
397 .gpiomask = 3, 416 .gpiomask = 3,
398 .muxsel = { 2, 3, 1, 0 }, 417 .muxsel = MUXSEL(2, 3, 1, 0),
399 .gpiomux = { 0, 1, 0, 1 }, 418 .gpiomux = { 0, 1, 0, 1 },
400 .gpiomute = 3, 419 .gpiomute = 3,
401 .needs_tvaudio = 1, 420 .needs_tvaudio = 1,
402 .tuner_type = UNSET, 421 .tuner_type = UNSET,
403 .tuner_addr = ADDR_UNSET, 422 .tuner_addr = ADDR_UNSET,
404 .radio_addr = ADDR_UNSET,
405 }, 423 },
406 [BTTV_BOARD_AVERMEDIA] = { 424 [BTTV_BOARD_AVERMEDIA] = {
407 .name = "AVerMedia TVPhone", 425 .name = "AVerMedia TVPhone",
408 .video_inputs = 3, 426 .video_inputs = 3,
409 .audio_inputs = 1, 427 /* .audio_inputs= 1, */
410 .tuner = 0,
411 .svhs = 3, 428 .svhs = 3,
412 .muxsel = { 2, 3, 1, 1 }, 429 .muxsel = MUXSEL(2, 3, 1, 1),
413 .gpiomask = 0x0f, 430 .gpiomask = 0x0f,
414 .gpiomux = { 0x0c, 0x04, 0x08, 0x04 }, 431 .gpiomux = { 0x0c, 0x04, 0x08, 0x04 },
415 /* 0x04 for some cards ?? */ 432 /* 0x04 for some cards ?? */
416 .needs_tvaudio = 1, 433 .needs_tvaudio = 1,
417 .tuner_type = UNSET, 434 .tuner_type = UNSET,
418 .tuner_addr = ADDR_UNSET, 435 .tuner_addr = ADDR_UNSET,
419 .radio_addr = ADDR_UNSET,
420 .audio_mode_gpio= avermedia_tvphone_audio, 436 .audio_mode_gpio= avermedia_tvphone_audio,
421 .has_remote = 1, 437 .has_remote = 1,
422 }, 438 },
423 [BTTV_BOARD_MATRIX_VISION] = { 439 [BTTV_BOARD_MATRIX_VISION] = {
424 .name = "MATRIX-Vision MV-Delta", 440 .name = "MATRIX-Vision MV-Delta",
425 .video_inputs = 5, 441 .video_inputs = 5,
426 .audio_inputs = 1, 442 /* .audio_inputs= 1, */
427 .tuner = UNSET,
428 .svhs = 3, 443 .svhs = 3,
429 .gpiomask = 0, 444 .gpiomask = 0,
430 .muxsel = { 2, 3, 1, 0, 0 }, 445 .muxsel = MUXSEL(2, 3, 1, 0, 0),
431 .gpiomux = { 0 }, 446 .gpiomux = { 0 },
432 .needs_tvaudio = 1, 447 .needs_tvaudio = 1,
433 .tuner_type = UNSET, 448 .tuner_type = TUNER_ABSENT,
434 .tuner_addr = ADDR_UNSET, 449 .tuner_addr = ADDR_UNSET,
435 .radio_addr = ADDR_UNSET,
436 }, 450 },
437 451
438 /* ---- card 0x08 ---------------------------------- */ 452 /* ---- card 0x08 ---------------------------------- */
439 [BTTV_BOARD_FLYVIDEO] = { 453 [BTTV_BOARD_FLYVIDEO] = {
440 .name = "Lifeview FlyVideo II (Bt848) LR26 / MAXI TV Video PCI2 LR26", 454 .name = "Lifeview FlyVideo II (Bt848) LR26 / MAXI TV Video PCI2 LR26",
441 .video_inputs = 4, 455 .video_inputs = 4,
442 .audio_inputs = 1, 456 /* .audio_inputs= 1, */
443 .tuner = 0,
444 .svhs = 2, 457 .svhs = 2,
445 .gpiomask = 0xc00, 458 .gpiomask = 0xc00,
446 .muxsel = { 2, 3, 1, 1 }, 459 .muxsel = MUXSEL(2, 3, 1, 1),
447 .gpiomux = { 0, 0xc00, 0x800, 0x400 }, 460 .gpiomux = { 0, 0xc00, 0x800, 0x400 },
448 .gpiomute = 0xc00, 461 .gpiomute = 0xc00,
449 .needs_tvaudio = 1, 462 .needs_tvaudio = 1,
450 .pll = PLL_28, 463 .pll = PLL_28,
451 .tuner_type = UNSET, 464 .tuner_type = UNSET,
452 .tuner_addr = ADDR_UNSET, 465 .tuner_addr = ADDR_UNSET,
453 .radio_addr = ADDR_UNSET,
454 }, 466 },
455 [BTTV_BOARD_TURBOTV] = { 467 [BTTV_BOARD_TURBOTV] = {
456 .name = "IMS/IXmicro TurboTV", 468 .name = "IMS/IXmicro TurboTV",
457 .video_inputs = 3, 469 .video_inputs = 3,
458 .audio_inputs = 1, 470 /* .audio_inputs= 1, */
459 .tuner = 0,
460 .svhs = 2, 471 .svhs = 2,
461 .gpiomask = 3, 472 .gpiomask = 3,
462 .muxsel = { 2, 3, 1, 1 }, 473 .muxsel = MUXSEL(2, 3, 1, 1),
463 .gpiomux = { 1, 1, 2, 3 }, 474 .gpiomux = { 1, 1, 2, 3 },
464 .needs_tvaudio = 0, 475 .needs_tvaudio = 0,
465 .pll = PLL_28, 476 .pll = PLL_28,
466 .tuner_type = TUNER_TEMIC_PAL, 477 .tuner_type = TUNER_TEMIC_PAL,
467 .tuner_addr = ADDR_UNSET, 478 .tuner_addr = ADDR_UNSET,
468 .radio_addr = ADDR_UNSET,
469 }, 479 },
470 [BTTV_BOARD_HAUPPAUGE878] = { 480 [BTTV_BOARD_HAUPPAUGE878] = {
471 .name = "Hauppauge (bt878)", 481 .name = "Hauppauge (bt878)",
472 .video_inputs = 4, 482 .video_inputs = 4,
473 .audio_inputs = 1, 483 /* .audio_inputs= 1, */
474 .tuner = 0,
475 .svhs = 2, 484 .svhs = 2,
476 .gpiomask = 0x0f, /* old: 7 */ 485 .gpiomask = 0x0f, /* old: 7 */
477 .muxsel = { 2, 0, 1, 1 }, 486 .muxsel = MUXSEL(2, 0, 1, 1),
478 .gpiomux = { 0, 1, 2, 3 }, 487 .gpiomux = { 0, 1, 2, 3 },
479 .gpiomute = 4, 488 .gpiomute = 4,
480 .needs_tvaudio = 1, 489 .needs_tvaudio = 1,
481 .pll = PLL_28, 490 .pll = PLL_28,
482 .tuner_type = UNSET, 491 .tuner_type = UNSET,
483 .tuner_addr = ADDR_UNSET, 492 .tuner_addr = ADDR_UNSET,
484 .radio_addr = ADDR_UNSET,
485 }, 493 },
486 [BTTV_BOARD_MIROPRO] = { 494 [BTTV_BOARD_MIROPRO] = {
487 .name = "MIRO PCTV pro", 495 .name = "MIRO PCTV pro",
488 .video_inputs = 3, 496 .video_inputs = 3,
489 .audio_inputs = 1, 497 /* .audio_inputs= 1, */
490 .tuner = 0,
491 .svhs = 2, 498 .svhs = 2,
492 .gpiomask = 0x3014f, 499 .gpiomask = 0x3014f,
493 .muxsel = { 2, 3, 1, 1 }, 500 .muxsel = MUXSEL(2, 3, 1, 1),
494 .gpiomux = { 0x20001,0x10001, 0, 0 }, 501 .gpiomux = { 0x20001,0x10001, 0, 0 },
495 .gpiomute = 10, 502 .gpiomute = 10,
496 .needs_tvaudio = 1, 503 .needs_tvaudio = 1,
497 .tuner_type = UNSET, 504 .tuner_type = UNSET,
498 .tuner_addr = ADDR_UNSET, 505 .tuner_addr = ADDR_UNSET,
499 .radio_addr = ADDR_UNSET,
500 }, 506 },
501 507
502 /* ---- card 0x0c ---------------------------------- */ 508 /* ---- card 0x0c ---------------------------------- */
503 [BTTV_BOARD_ADSTECH_TV] = { 509 [BTTV_BOARD_ADSTECH_TV] = {
504 .name = "ADS Technologies Channel Surfer TV (bt848)", 510 .name = "ADS Technologies Channel Surfer TV (bt848)",
505 .video_inputs = 3, 511 .video_inputs = 3,
506 .audio_inputs = 1, 512 /* .audio_inputs= 1, */
507 .tuner = 0,
508 .svhs = 2, 513 .svhs = 2,
509 .gpiomask = 15, 514 .gpiomask = 15,
510 .muxsel = { 2, 3, 1, 1 }, 515 .muxsel = MUXSEL(2, 3, 1, 1),
511 .gpiomux = { 13, 14, 11, 7 }, 516 .gpiomux = { 13, 14, 11, 7 },
512 .needs_tvaudio = 1, 517 .needs_tvaudio = 1,
513 .tuner_type = UNSET, 518 .tuner_type = UNSET,
514 .tuner_addr = ADDR_UNSET, 519 .tuner_addr = ADDR_UNSET,
515 .radio_addr = ADDR_UNSET,
516 }, 520 },
517 [BTTV_BOARD_AVERMEDIA98] = { 521 [BTTV_BOARD_AVERMEDIA98] = {
518 .name = "AVerMedia TVCapture 98", 522 .name = "AVerMedia TVCapture 98",
519 .video_inputs = 3, 523 .video_inputs = 3,
520 .audio_inputs = 4, 524 /* .audio_inputs= 4, */
521 .tuner = 0,
522 .svhs = 2, 525 .svhs = 2,
523 .gpiomask = 15, 526 .gpiomask = 15,
524 .muxsel = { 2, 3, 1, 1 }, 527 .muxsel = MUXSEL(2, 3, 1, 1),
525 .gpiomux = { 13, 14, 11, 7 }, 528 .gpiomux = { 13, 14, 11, 7 },
526 .needs_tvaudio = 1, 529 .needs_tvaudio = 1,
527 .msp34xx_alt = 1, 530 .msp34xx_alt = 1,
528 .pll = PLL_28, 531 .pll = PLL_28,
529 .tuner_type = TUNER_PHILIPS_PAL, 532 .tuner_type = TUNER_PHILIPS_PAL,
530 .tuner_addr = ADDR_UNSET, 533 .tuner_addr = ADDR_UNSET,
531 .radio_addr = ADDR_UNSET,
532 .audio_mode_gpio= avermedia_tv_stereo_audio, 534 .audio_mode_gpio= avermedia_tv_stereo_audio,
533 .no_gpioirq = 1, 535 .no_gpioirq = 1,
534 }, 536 },
535 [BTTV_BOARD_VHX] = { 537 [BTTV_BOARD_VHX] = {
536 .name = "Aimslab Video Highway Xtreme (VHX)", 538 .name = "Aimslab Video Highway Xtreme (VHX)",
537 .video_inputs = 3, 539 .video_inputs = 3,
538 .audio_inputs = 1, 540 /* .audio_inputs= 1, */
539 .tuner = 0,
540 .svhs = 2, 541 .svhs = 2,
541 .gpiomask = 7, 542 .gpiomask = 7,
542 .muxsel = { 2, 3, 1, 1 }, 543 .muxsel = MUXSEL(2, 3, 1, 1),
543 .gpiomux = { 0, 2, 1, 3 }, /* old: {0, 1, 2, 3, 4} */ 544 .gpiomux = { 0, 2, 1, 3 }, /* old: {0, 1, 2, 3, 4} */
544 .gpiomute = 4, 545 .gpiomute = 4,
545 .needs_tvaudio = 1, 546 .needs_tvaudio = 1,
546 .pll = PLL_28, 547 .pll = PLL_28,
547 .tuner_type = UNSET, 548 .tuner_type = UNSET,
548 .tuner_addr = ADDR_UNSET, 549 .tuner_addr = ADDR_UNSET,
549 .radio_addr = ADDR_UNSET,
550 }, 550 },
551 [BTTV_BOARD_ZOLTRIX] = { 551 [BTTV_BOARD_ZOLTRIX] = {
552 .name = "Zoltrix TV-Max", 552 .name = "Zoltrix TV-Max",
553 .video_inputs = 3, 553 .video_inputs = 3,
554 .audio_inputs = 1, 554 /* .audio_inputs= 1, */
555 .tuner = 0,
556 .svhs = 2, 555 .svhs = 2,
557 .gpiomask = 15, 556 .gpiomask = 15,
558 .muxsel = { 2, 3, 1, 1 }, 557 .muxsel = MUXSEL(2, 3, 1, 1),
559 .gpiomux = { 0, 0, 1, 0 }, 558 .gpiomux = { 0, 0, 1, 0 },
560 .gpiomute = 10, 559 .gpiomute = 10,
561 .needs_tvaudio = 1, 560 .needs_tvaudio = 1,
562 .tuner_type = UNSET, 561 .tuner_type = UNSET,
563 .tuner_addr = ADDR_UNSET, 562 .tuner_addr = ADDR_UNSET,
564 .radio_addr = ADDR_UNSET,
565 }, 563 },
566 564
567 /* ---- card 0x10 ---------------------------------- */ 565 /* ---- card 0x10 ---------------------------------- */
568 [BTTV_BOARD_PIXVIEWPLAYTV] = { 566 [BTTV_BOARD_PIXVIEWPLAYTV] = {
569 .name = "Prolink Pixelview PlayTV (bt878)", 567 .name = "Prolink Pixelview PlayTV (bt878)",
570 .video_inputs = 3, 568 .video_inputs = 3,
571 .audio_inputs = 1, 569 /* .audio_inputs= 1, */
572 .tuner = 0,
573 .svhs = 2, 570 .svhs = 2,
574 .gpiomask = 0x01fe00, 571 .gpiomask = 0x01fe00,
575 .muxsel = { 2, 3, 1, 1 }, 572 .muxsel = MUXSEL(2, 3, 1, 1),
576 /* 2003-10-20 by "Anton A. Arapov" <arapov@mail.ru> */ 573 /* 2003-10-20 by "Anton A. Arapov" <arapov@mail.ru> */
577 .gpiomux = { 0x001e00, 0, 0x018000, 0x014000 }, 574 .gpiomux = { 0x001e00, 0, 0x018000, 0x014000 },
578 .gpiomute = 0x002000, 575 .gpiomute = 0x002000,
@@ -580,194 +577,170 @@ struct tvcard bttv_tvcards[] = {
580 .pll = PLL_28, 577 .pll = PLL_28,
581 .tuner_type = UNSET, 578 .tuner_type = UNSET,
582 .tuner_addr = ADDR_UNSET, 579 .tuner_addr = ADDR_UNSET,
583 .radio_addr = ADDR_UNSET,
584 }, 580 },
585 [BTTV_BOARD_WINVIEW_601] = { 581 [BTTV_BOARD_WINVIEW_601] = {
586 .name = "Leadtek WinView 601", 582 .name = "Leadtek WinView 601",
587 .video_inputs = 3, 583 .video_inputs = 3,
588 .audio_inputs = 1, 584 /* .audio_inputs= 1, */
589 .tuner = 0,
590 .svhs = 2, 585 .svhs = 2,
591 .gpiomask = 0x8300f8, 586 .gpiomask = 0x8300f8,
592 .muxsel = { 2, 3, 1, 1,0 }, 587 .muxsel = MUXSEL(2, 3, 1, 1, 0),
593 .gpiomux = { 0x4fa007,0xcfa007,0xcfa007,0xcfa007 }, 588 .gpiomux = { 0x4fa007,0xcfa007,0xcfa007,0xcfa007 },
594 .gpiomute = 0xcfa007, 589 .gpiomute = 0xcfa007,
595 .needs_tvaudio = 1, 590 .needs_tvaudio = 1,
596 .tuner_type = UNSET, 591 .tuner_type = UNSET,
597 .tuner_addr = ADDR_UNSET, 592 .tuner_addr = ADDR_UNSET,
598 .radio_addr = ADDR_UNSET,
599 .volume_gpio = winview_volume, 593 .volume_gpio = winview_volume,
600 .has_radio = 1, 594 .has_radio = 1,
601 }, 595 },
602 [BTTV_BOARD_AVEC_INTERCAP] = { 596 [BTTV_BOARD_AVEC_INTERCAP] = {
603 .name = "AVEC Intercapture", 597 .name = "AVEC Intercapture",
604 .video_inputs = 3, 598 .video_inputs = 3,
605 .audio_inputs = 2, 599 /* .audio_inputs= 2, */
606 .tuner = 0,
607 .svhs = 2, 600 .svhs = 2,
608 .gpiomask = 0, 601 .gpiomask = 0,
609 .muxsel = { 2, 3, 1, 1 }, 602 .muxsel = MUXSEL(2, 3, 1, 1),
610 .gpiomux = { 1, 0, 0, 0 }, 603 .gpiomux = { 1, 0, 0, 0 },
611 .needs_tvaudio = 1, 604 .needs_tvaudio = 1,
612 .tuner_type = UNSET, 605 .tuner_type = UNSET,
613 .tuner_addr = ADDR_UNSET, 606 .tuner_addr = ADDR_UNSET,
614 .radio_addr = ADDR_UNSET,
615 }, 607 },
616 [BTTV_BOARD_LIFE_FLYKIT] = { 608 [BTTV_BOARD_LIFE_FLYKIT] = {
617 .name = "Lifeview FlyVideo II EZ /FlyKit LR38 Bt848 (capture only)", 609 .name = "Lifeview FlyVideo II EZ /FlyKit LR38 Bt848 (capture only)",
618 .video_inputs = 4, 610 .video_inputs = 4,
619 .audio_inputs = 1, 611 /* .audio_inputs= 1, */
620 .tuner = UNSET, 612 .svhs = NO_SVHS,
621 .svhs = UNSET,
622 .gpiomask = 0x8dff00, 613 .gpiomask = 0x8dff00,
623 .muxsel = { 2, 3, 1, 1 }, 614 .muxsel = MUXSEL(2, 3, 1, 1),
624 .gpiomux = { 0 }, 615 .gpiomux = { 0 },
625 .no_msp34xx = 1, 616 .no_msp34xx = 1,
626 .tuner_type = UNSET, 617 .tuner_type = TUNER_ABSENT,
627 .tuner_addr = ADDR_UNSET, 618 .tuner_addr = ADDR_UNSET,
628 .radio_addr = ADDR_UNSET,
629 }, 619 },
630 620
631 /* ---- card 0x14 ---------------------------------- */ 621 /* ---- card 0x14 ---------------------------------- */
632 [BTTV_BOARD_CEI_RAFFLES] = { 622 [BTTV_BOARD_CEI_RAFFLES] = {
633 .name = "CEI Raffles Card", 623 .name = "CEI Raffles Card",
634 .video_inputs = 3, 624 .video_inputs = 3,
635 .audio_inputs = 3, 625 /* .audio_inputs= 3, */
636 .tuner = 0,
637 .svhs = 2, 626 .svhs = 2,
638 .muxsel = { 2, 3, 1, 1 }, 627 .muxsel = MUXSEL(2, 3, 1, 1),
639 .tuner_type = UNSET, 628 .tuner_type = UNSET,
640 .tuner_addr = ADDR_UNSET, 629 .tuner_addr = ADDR_UNSET,
641 .radio_addr = ADDR_UNSET,
642 }, 630 },
643 [BTTV_BOARD_CONFERENCETV] = { 631 [BTTV_BOARD_CONFERENCETV] = {
644 .name = "Lifeview FlyVideo 98/ Lucky Star Image World ConferenceTV LR50", 632 .name = "Lifeview FlyVideo 98/ Lucky Star Image World ConferenceTV LR50",
645 .video_inputs = 4, 633 .video_inputs = 4,
646 .audio_inputs = 2, /* tuner, line in */ 634 /* .audio_inputs= 2, tuner, line in */
647 .tuner = 0,
648 .svhs = 2, 635 .svhs = 2,
649 .gpiomask = 0x1800, 636 .gpiomask = 0x1800,
650 .muxsel = { 2, 3, 1, 1 }, 637 .muxsel = MUXSEL(2, 3, 1, 1),
651 .gpiomux = { 0, 0x800, 0x1000, 0x1000 }, 638 .gpiomux = { 0, 0x800, 0x1000, 0x1000 },
652 .gpiomute = 0x1800, 639 .gpiomute = 0x1800,
653 .pll = PLL_28, 640 .pll = PLL_28,
654 .tuner_type = TUNER_PHILIPS_PAL_I, 641 .tuner_type = TUNER_PHILIPS_PAL_I,
655 .tuner_addr = ADDR_UNSET, 642 .tuner_addr = ADDR_UNSET,
656 .radio_addr = ADDR_UNSET,
657 }, 643 },
658 [BTTV_BOARD_PHOEBE_TVMAS] = { 644 [BTTV_BOARD_PHOEBE_TVMAS] = {
659 .name = "Askey CPH050/ Phoebe Tv Master + FM", 645 .name = "Askey CPH050/ Phoebe Tv Master + FM",
660 .video_inputs = 3, 646 .video_inputs = 3,
661 .audio_inputs = 1, 647 /* .audio_inputs= 1, */
662 .tuner = 0,
663 .svhs = 2, 648 .svhs = 2,
664 .gpiomask = 0xc00, 649 .gpiomask = 0xc00,
665 .muxsel = { 2, 3, 1, 1 }, 650 .muxsel = MUXSEL(2, 3, 1, 1),
666 .gpiomux = { 0, 1, 0x800, 0x400 }, 651 .gpiomux = { 0, 1, 0x800, 0x400 },
667 .gpiomute = 0xc00, 652 .gpiomute = 0xc00,
668 .needs_tvaudio = 1, 653 .needs_tvaudio = 1,
669 .pll = PLL_28, 654 .pll = PLL_28,
670 .tuner_type = UNSET, 655 .tuner_type = UNSET,
671 .tuner_addr = ADDR_UNSET, 656 .tuner_addr = ADDR_UNSET,
672 .radio_addr = ADDR_UNSET,
673 }, 657 },
674 [BTTV_BOARD_MODTEC_205] = { 658 [BTTV_BOARD_MODTEC_205] = {
675 .name = "Modular Technology MM201/MM202/MM205/MM210/MM215 PCTV, bt878", 659 .name = "Modular Technology MM201/MM202/MM205/MM210/MM215 PCTV, bt878",
676 .video_inputs = 3, 660 .video_inputs = 3,
677 .audio_inputs = 1, 661 /* .audio_inputs= 1, */
678 .tuner = 0, 662 .svhs = NO_SVHS,
679 .svhs = UNSET, 663 .has_dig_in = 1,
680 .gpiomask = 7, 664 .gpiomask = 7,
681 .muxsel = { 2, 3, -1 }, 665 .muxsel = MUXSEL(2, 3, 0), /* input 2 is digital */
682 .digital_mode = DIGITAL_MODE_CAMERA, 666 /* .digital_mode= DIGITAL_MODE_CAMERA, */
683 .gpiomux = { 0, 0, 0, 0 }, 667 .gpiomux = { 0, 0, 0, 0 },
684 .no_msp34xx = 1, 668 .no_msp34xx = 1,
685 .pll = PLL_28, 669 .pll = PLL_28,
686 .tuner_type = TUNER_ALPS_TSBB5_PAL_I, 670 .tuner_type = TUNER_ALPS_TSBB5_PAL_I,
687 .tuner_addr = ADDR_UNSET, 671 .tuner_addr = ADDR_UNSET,
688 .radio_addr = ADDR_UNSET,
689 }, 672 },
690 673
691 /* ---- card 0x18 ---------------------------------- */ 674 /* ---- card 0x18 ---------------------------------- */
692 [BTTV_BOARD_MAGICTVIEW061] = { 675 [BTTV_BOARD_MAGICTVIEW061] = {
693 .name = "Askey CPH05X/06X (bt878) [many vendors]", 676 .name = "Askey CPH05X/06X (bt878) [many vendors]",
694 .video_inputs = 3, 677 .video_inputs = 3,
695 .audio_inputs = 1, 678 /* .audio_inputs= 1, */
696 .tuner = 0,
697 .svhs = 2, 679 .svhs = 2,
698 .gpiomask = 0xe00, 680 .gpiomask = 0xe00,
699 .muxsel = { 2, 3, 1, 1 }, 681 .muxsel = MUXSEL(2, 3, 1, 1),
700 .gpiomux = {0x400, 0x400, 0x400, 0x400 }, 682 .gpiomux = {0x400, 0x400, 0x400, 0x400 },
701 .gpiomute = 0xc00, 683 .gpiomute = 0xc00,
702 .needs_tvaudio = 1, 684 .needs_tvaudio = 1,
703 .pll = PLL_28, 685 .pll = PLL_28,
704 .tuner_type = UNSET, 686 .tuner_type = UNSET,
705 .tuner_addr = ADDR_UNSET, 687 .tuner_addr = ADDR_UNSET,
706 .radio_addr = ADDR_UNSET,
707 .has_remote = 1, 688 .has_remote = 1,
708 }, 689 },
709 [BTTV_BOARD_VOBIS_BOOSTAR] = { 690 [BTTV_BOARD_VOBIS_BOOSTAR] = {
710 .name = "Terratec TerraTV+ Version 1.0 (Bt848)/ Terra TValue Version 1.0/ Vobis TV-Boostar", 691 .name = "Terratec TerraTV+ Version 1.0 (Bt848)/ Terra TValue Version 1.0/ Vobis TV-Boostar",
711 .video_inputs = 3, 692 .video_inputs = 3,
712 .audio_inputs = 1, 693 /* .audio_inputs= 1, */
713 .tuner = 0,
714 .svhs = 2, 694 .svhs = 2,
715 .gpiomask = 0x1f0fff, 695 .gpiomask = 0x1f0fff,
716 .muxsel = { 2, 3, 1, 1 }, 696 .muxsel = MUXSEL(2, 3, 1, 1),
717 .gpiomux = { 0x20000, 0x30000, 0x10000, 0 }, 697 .gpiomux = { 0x20000, 0x30000, 0x10000, 0 },
718 .gpiomute = 0x40000, 698 .gpiomute = 0x40000,
719 .needs_tvaudio = 0, 699 .needs_tvaudio = 0,
720 .tuner_type = TUNER_PHILIPS_PAL, 700 .tuner_type = TUNER_PHILIPS_PAL,
721 .tuner_addr = ADDR_UNSET, 701 .tuner_addr = ADDR_UNSET,
722 .radio_addr = ADDR_UNSET,
723 .audio_mode_gpio= terratv_audio, 702 .audio_mode_gpio= terratv_audio,
724 }, 703 },
725 [BTTV_BOARD_HAUPPAUG_WCAM] = { 704 [BTTV_BOARD_HAUPPAUG_WCAM] = {
726 .name = "Hauppauge WinCam newer (bt878)", 705 .name = "Hauppauge WinCam newer (bt878)",
727 .video_inputs = 4, 706 .video_inputs = 4,
728 .audio_inputs = 1, 707 /* .audio_inputs= 1, */
729 .tuner = 0,
730 .svhs = 3, 708 .svhs = 3,
731 .gpiomask = 7, 709 .gpiomask = 7,
732 .muxsel = { 2, 0, 1, 1 }, 710 .muxsel = MUXSEL(2, 0, 1, 1),
733 .gpiomux = { 0, 1, 2, 3 }, 711 .gpiomux = { 0, 1, 2, 3 },
734 .gpiomute = 4, 712 .gpiomute = 4,
735 .needs_tvaudio = 1, 713 .needs_tvaudio = 1,
736 .tuner_type = UNSET, 714 .tuner_type = UNSET,
737 .tuner_addr = ADDR_UNSET, 715 .tuner_addr = ADDR_UNSET,
738 .radio_addr = ADDR_UNSET,
739 }, 716 },
740 [BTTV_BOARD_MAXI] = { 717 [BTTV_BOARD_MAXI] = {
741 .name = "Lifeview FlyVideo 98/ MAXI TV Video PCI2 LR50", 718 .name = "Lifeview FlyVideo 98/ MAXI TV Video PCI2 LR50",
742 .video_inputs = 4, 719 .video_inputs = 4,
743 .audio_inputs = 2, 720 /* .audio_inputs= 2, */
744 .tuner = 0,
745 .svhs = 2, 721 .svhs = 2,
746 .gpiomask = 0x1800, 722 .gpiomask = 0x1800,
747 .muxsel = { 2, 3, 1, 1 }, 723 .muxsel = MUXSEL(2, 3, 1, 1),
748 .gpiomux = { 0, 0x800, 0x1000, 0x1000 }, 724 .gpiomux = { 0, 0x800, 0x1000, 0x1000 },
749 .gpiomute = 0x1800, 725 .gpiomute = 0x1800,
750 .pll = PLL_28, 726 .pll = PLL_28,
751 .tuner_type = TUNER_PHILIPS_SECAM, 727 .tuner_type = TUNER_PHILIPS_SECAM,
752 .tuner_addr = ADDR_UNSET, 728 .tuner_addr = ADDR_UNSET,
753 .radio_addr = ADDR_UNSET,
754 }, 729 },
755 730
756 /* ---- card 0x1c ---------------------------------- */ 731 /* ---- card 0x1c ---------------------------------- */
757 [BTTV_BOARD_TERRATV] = { 732 [BTTV_BOARD_TERRATV] = {
758 .name = "Terratec TerraTV+ Version 1.1 (bt878)", 733 .name = "Terratec TerraTV+ Version 1.1 (bt878)",
759 .video_inputs = 3, 734 .video_inputs = 3,
760 .audio_inputs = 1, 735 /* .audio_inputs= 1, */
761 .tuner = 0,
762 .svhs = 2, 736 .svhs = 2,
763 .gpiomask = 0x1f0fff, 737 .gpiomask = 0x1f0fff,
764 .muxsel = { 2, 3, 1, 1 }, 738 .muxsel = MUXSEL(2, 3, 1, 1),
765 .gpiomux = { 0x20000, 0x30000, 0x10000, 0x00000 }, 739 .gpiomux = { 0x20000, 0x30000, 0x10000, 0x00000 },
766 .gpiomute = 0x40000, 740 .gpiomute = 0x40000,
767 .needs_tvaudio = 0, 741 .needs_tvaudio = 0,
768 .tuner_type = TUNER_PHILIPS_PAL, 742 .tuner_type = TUNER_PHILIPS_PAL,
769 .tuner_addr = ADDR_UNSET, 743 .tuner_addr = ADDR_UNSET,
770 .radio_addr = ADDR_UNSET,
771 .audio_mode_gpio= terratv_audio, 744 .audio_mode_gpio= terratv_audio,
772 /* GPIO wiring: 745 /* GPIO wiring:
773 External 20 pin connector (for Active Radio Upgrade board) 746 External 20 pin connector (for Active Radio Upgrade board)
@@ -805,87 +778,77 @@ struct tvcard bttv_tvcards[] = {
805 /* Jannik Fritsch <jannik@techfak.uni-bielefeld.de> */ 778 /* Jannik Fritsch <jannik@techfak.uni-bielefeld.de> */
806 .name = "Imagenation PXC200", 779 .name = "Imagenation PXC200",
807 .video_inputs = 5, 780 .video_inputs = 5,
808 .audio_inputs = 1, 781 /* .audio_inputs= 1, */
809 .tuner = UNSET,
810 .svhs = 1, /* was: 4 */ 782 .svhs = 1, /* was: 4 */
811 .gpiomask = 0, 783 .gpiomask = 0,
812 .muxsel = { 2, 3, 1, 0, 0}, 784 .muxsel = MUXSEL(2, 3, 1, 0, 0),
813 .gpiomux = { 0 }, 785 .gpiomux = { 0 },
814 .needs_tvaudio = 1, 786 .needs_tvaudio = 1,
815 .tuner_type = UNSET, 787 .tuner_type = TUNER_ABSENT,
816 .tuner_addr = ADDR_UNSET, 788 .tuner_addr = ADDR_UNSET,
817 .radio_addr = ADDR_UNSET,
818 .muxsel_hook = PXC200_muxsel, 789 .muxsel_hook = PXC200_muxsel,
819 790
820 }, 791 },
821 [BTTV_BOARD_FLYVIDEO_98] = { 792 [BTTV_BOARD_FLYVIDEO_98] = {
822 .name = "Lifeview FlyVideo 98 LR50", 793 .name = "Lifeview FlyVideo 98 LR50",
823 .video_inputs = 4, 794 .video_inputs = 4,
824 .audio_inputs = 1, 795 /* .audio_inputs= 1, */
825 .tuner = 0,
826 .svhs = 2, 796 .svhs = 2,
827 .gpiomask = 0x1800, /* 0x8dfe00 */ 797 .gpiomask = 0x1800, /* 0x8dfe00 */
828 .muxsel = { 2, 3, 1, 1 }, 798 .muxsel = MUXSEL(2, 3, 1, 1),
829 .gpiomux = { 0, 0x0800, 0x1000, 0x1000 }, 799 .gpiomux = { 0, 0x0800, 0x1000, 0x1000 },
830 .gpiomute = 0x1800, 800 .gpiomute = 0x1800,
831 .pll = PLL_28, 801 .pll = PLL_28,
832 .tuner_type = UNSET, 802 .tuner_type = UNSET,
833 .tuner_addr = ADDR_UNSET, 803 .tuner_addr = ADDR_UNSET,
834 .radio_addr = ADDR_UNSET,
835 }, 804 },
836 [BTTV_BOARD_IPROTV] = { 805 [BTTV_BOARD_IPROTV] = {
837 .name = "Formac iProTV, Formac ProTV I (bt848)", 806 .name = "Formac iProTV, Formac ProTV I (bt848)",
838 .video_inputs = 4, 807 .video_inputs = 4,
839 .audio_inputs = 1, 808 /* .audio_inputs= 1, */
840 .tuner = 0,
841 .svhs = 3, 809 .svhs = 3,
842 .gpiomask = 1, 810 .gpiomask = 1,
843 .muxsel = { 2, 3, 1, 1 }, 811 .muxsel = MUXSEL(2, 3, 1, 1),
844 .gpiomux = { 1, 0, 0, 0 }, 812 .gpiomux = { 1, 0, 0, 0 },
845 .pll = PLL_28, 813 .pll = PLL_28,
846 .tuner_type = TUNER_PHILIPS_PAL, 814 .tuner_type = TUNER_PHILIPS_PAL,
847 .tuner_addr = ADDR_UNSET, 815 .tuner_addr = ADDR_UNSET,
848 .radio_addr = ADDR_UNSET,
849 }, 816 },
850 817
851 /* ---- card 0x20 ---------------------------------- */ 818 /* ---- card 0x20 ---------------------------------- */
852 [BTTV_BOARD_INTEL_C_S_PCI] = { 819 [BTTV_BOARD_INTEL_C_S_PCI] = {
853 .name = "Intel Create and Share PCI/ Smart Video Recorder III", 820 .name = "Intel Create and Share PCI/ Smart Video Recorder III",
854 .video_inputs = 4, 821 .video_inputs = 4,
855 .audio_inputs = 0, 822 /* .audio_inputs= 0, */
856 .tuner = UNSET,
857 .svhs = 2, 823 .svhs = 2,
858 .gpiomask = 0, 824 .gpiomask = 0,
859 .muxsel = { 2, 3, 1, 1 }, 825 .muxsel = MUXSEL(2, 3, 1, 1),
860 .gpiomux = { 0 }, 826 .gpiomux = { 0 },
861 .needs_tvaudio = 0, 827 .needs_tvaudio = 0,
862 .tuner_type = TUNER_ABSENT, 828 .tuner_type = TUNER_ABSENT,
863 .tuner_addr = ADDR_UNSET, 829 .tuner_addr = ADDR_UNSET,
864 .radio_addr = ADDR_UNSET,
865 }, 830 },
866 [BTTV_BOARD_TERRATVALUE] = { 831 [BTTV_BOARD_TERRATVALUE] = {
867 .name = "Terratec TerraTValue Version Bt878", 832 .name = "Terratec TerraTValue Version Bt878",
868 .video_inputs = 3, 833 .video_inputs = 3,
869 .audio_inputs = 1, 834 /* .audio_inputs= 1, */
870 .tuner = 0,
871 .svhs = 2, 835 .svhs = 2,
872 .gpiomask = 0xffff00, 836 .gpiomask = 0xffff00,
873 .muxsel = { 2, 3, 1, 1 }, 837 .muxsel = MUXSEL(2, 3, 1, 1),
874 .gpiomux = { 0x500, 0, 0x300, 0x900 }, 838 .gpiomux = { 0x500, 0, 0x300, 0x900 },
875 .gpiomute = 0x900, 839 .gpiomute = 0x900,
876 .needs_tvaudio = 1, 840 .needs_tvaudio = 1,
877 .pll = PLL_28, 841 .pll = PLL_28,
878 .tuner_type = TUNER_PHILIPS_PAL, 842 .tuner_type = TUNER_PHILIPS_PAL,
879 .tuner_addr = ADDR_UNSET, 843 .tuner_addr = ADDR_UNSET,
880 .radio_addr = ADDR_UNSET,
881 }, 844 },
882 [BTTV_BOARD_WINFAST2000] = { 845 [BTTV_BOARD_WINFAST2000] = {
883 .name = "Leadtek WinFast 2000/ WinFast 2000 XP", 846 .name = "Leadtek WinFast 2000/ WinFast 2000 XP",
884 .video_inputs = 4, 847 .video_inputs = 4,
885 .audio_inputs = 1, 848 /* .audio_inputs= 1, */
886 .tuner = 0,
887 .svhs = 2, 849 .svhs = 2,
888 .muxsel = { 2, 3, 1, 1, 0 }, /* TV, CVid, SVid, CVid over SVid connector */ 850 /* TV, CVid, SVid, CVid over SVid connector */
851 .muxsel = MUXSEL(2, 3, 1, 1, 0),
889 /* Alexander Varakin <avarakin@hotmail.com> [stereo version] */ 852 /* Alexander Varakin <avarakin@hotmail.com> [stereo version] */
890 .gpiomask = 0xb33000, 853 .gpiomask = 0xb33000,
891 .gpiomux = { 0x122000,0x1000,0x0000,0x620000 }, 854 .gpiomux = { 0x122000,0x1000,0x0000,0x620000 },
@@ -906,217 +869,191 @@ struct tvcard bttv_tvcards[] = {
906 .has_radio = 1, 869 .has_radio = 1,
907 .tuner_type = TUNER_PHILIPS_PAL, /* default for now, gpio reads BFFF06 for Pal bg+dk */ 870 .tuner_type = TUNER_PHILIPS_PAL, /* default for now, gpio reads BFFF06 for Pal bg+dk */
908 .tuner_addr = ADDR_UNSET, 871 .tuner_addr = ADDR_UNSET,
909 .radio_addr = ADDR_UNSET,
910 .audio_mode_gpio= winfast2000_audio, 872 .audio_mode_gpio= winfast2000_audio,
911 .has_remote = 1, 873 .has_remote = 1,
912 }, 874 },
913 [BTTV_BOARD_CHRONOS_VS2] = { 875 [BTTV_BOARD_CHRONOS_VS2] = {
914 .name = "Lifeview FlyVideo 98 LR50 / Chronos Video Shuttle II", 876 .name = "Lifeview FlyVideo 98 LR50 / Chronos Video Shuttle II",
915 .video_inputs = 4, 877 .video_inputs = 4,
916 .audio_inputs = 3, 878 /* .audio_inputs= 3, */
917 .tuner = 0,
918 .svhs = 2, 879 .svhs = 2,
919 .gpiomask = 0x1800, 880 .gpiomask = 0x1800,
920 .muxsel = { 2, 3, 1, 1 }, 881 .muxsel = MUXSEL(2, 3, 1, 1),
921 .gpiomux = { 0, 0x800, 0x1000, 0x1000 }, 882 .gpiomux = { 0, 0x800, 0x1000, 0x1000 },
922 .gpiomute = 0x1800, 883 .gpiomute = 0x1800,
923 .pll = PLL_28, 884 .pll = PLL_28,
924 .tuner_type = UNSET, 885 .tuner_type = UNSET,
925 .tuner_addr = ADDR_UNSET, 886 .tuner_addr = ADDR_UNSET,
926 .radio_addr = ADDR_UNSET,
927 }, 887 },
928 888
929 /* ---- card 0x24 ---------------------------------- */ 889 /* ---- card 0x24 ---------------------------------- */
930 [BTTV_BOARD_TYPHOON_TVIEW] = { 890 [BTTV_BOARD_TYPHOON_TVIEW] = {
931 .name = "Lifeview FlyVideo 98FM LR50 / Typhoon TView TV/FM Tuner", 891 .name = "Lifeview FlyVideo 98FM LR50 / Typhoon TView TV/FM Tuner",
932 .video_inputs = 4, 892 .video_inputs = 4,
933 .audio_inputs = 3, 893 /* .audio_inputs= 3, */
934 .tuner = 0,
935 .svhs = 2, 894 .svhs = 2,
936 .gpiomask = 0x1800, 895 .gpiomask = 0x1800,
937 .muxsel = { 2, 3, 1, 1 }, 896 .muxsel = MUXSEL(2, 3, 1, 1),
938 .gpiomux = { 0, 0x800, 0x1000, 0x1000 }, 897 .gpiomux = { 0, 0x800, 0x1000, 0x1000 },
939 .gpiomute = 0x1800, 898 .gpiomute = 0x1800,
940 .pll = PLL_28, 899 .pll = PLL_28,
941 .tuner_type = UNSET, 900 .tuner_type = UNSET,
942 .tuner_addr = ADDR_UNSET, 901 .tuner_addr = ADDR_UNSET,
943 .radio_addr = ADDR_UNSET,
944 .has_radio = 1, 902 .has_radio = 1,
945 }, 903 },
946 [BTTV_BOARD_PXELVWPLTVPRO] = { 904 [BTTV_BOARD_PXELVWPLTVPRO] = {
947 .name = "Prolink PixelView PlayTV pro", 905 .name = "Prolink PixelView PlayTV pro",
948 .video_inputs = 3, 906 .video_inputs = 3,
949 .audio_inputs = 1, 907 /* .audio_inputs= 1, */
950 .tuner = 0,
951 .svhs = 2, 908 .svhs = 2,
952 .gpiomask = 0xff, 909 .gpiomask = 0xff,
953 .muxsel = { 2, 3, 1, 1 }, 910 .muxsel = MUXSEL(2, 3, 1, 1),
954 .gpiomux = { 0x21, 0x20, 0x24, 0x2c }, 911 .gpiomux = { 0x21, 0x20, 0x24, 0x2c },
955 .gpiomute = 0x29, 912 .gpiomute = 0x29,
956 .no_msp34xx = 1, 913 .no_msp34xx = 1,
957 .pll = PLL_28, 914 .pll = PLL_28,
958 .tuner_type = UNSET, 915 .tuner_type = UNSET,
959 .tuner_addr = ADDR_UNSET, 916 .tuner_addr = ADDR_UNSET,
960 .radio_addr = ADDR_UNSET,
961 }, 917 },
962 [BTTV_BOARD_MAGICTVIEW063] = { 918 [BTTV_BOARD_MAGICTVIEW063] = {
963 .name = "Askey CPH06X TView99", 919 .name = "Askey CPH06X TView99",
964 .video_inputs = 4, 920 .video_inputs = 4,
965 .audio_inputs = 1, 921 /* .audio_inputs= 1, */
966 .tuner = 0,
967 .svhs = 2, 922 .svhs = 2,
968 .gpiomask = 0x551e00, 923 .gpiomask = 0x551e00,
969 .muxsel = { 2, 3, 1, 0 }, 924 .muxsel = MUXSEL(2, 3, 1, 0),
970 .gpiomux = { 0x551400, 0x551200, 0, 0 }, 925 .gpiomux = { 0x551400, 0x551200, 0, 0 },
971 .gpiomute = 0x551c00, 926 .gpiomute = 0x551c00,
972 .needs_tvaudio = 1, 927 .needs_tvaudio = 1,
973 .pll = PLL_28, 928 .pll = PLL_28,
974 .tuner_type = TUNER_PHILIPS_PAL_I, 929 .tuner_type = TUNER_PHILIPS_PAL_I,
975 .tuner_addr = ADDR_UNSET, 930 .tuner_addr = ADDR_UNSET,
976 .radio_addr = ADDR_UNSET,
977 .has_remote = 1, 931 .has_remote = 1,
978 }, 932 },
979 [BTTV_BOARD_PINNACLE] = { 933 [BTTV_BOARD_PINNACLE] = {
980 .name = "Pinnacle PCTV Studio/Rave", 934 .name = "Pinnacle PCTV Studio/Rave",
981 .video_inputs = 3, 935 .video_inputs = 3,
982 .audio_inputs = 1, 936 /* .audio_inputs= 1, */
983 .tuner = 0,
984 .svhs = 2, 937 .svhs = 2,
985 .gpiomask = 0x03000F, 938 .gpiomask = 0x03000F,
986 .muxsel = { 2, 3, 1, 1 }, 939 .muxsel = MUXSEL(2, 3, 1, 1),
987 .gpiomux = { 2, 0xd0001, 0, 0 }, 940 .gpiomux = { 2, 0xd0001, 0, 0 },
988 .gpiomute = 1, 941 .gpiomute = 1,
989 .needs_tvaudio = 0, 942 .needs_tvaudio = 0,
990 .pll = PLL_28, 943 .pll = PLL_28,
991 .tuner_type = UNSET, 944 .tuner_type = UNSET,
992 .tuner_addr = ADDR_UNSET, 945 .tuner_addr = ADDR_UNSET,
993 .radio_addr = ADDR_UNSET,
994 }, 946 },
995 947
996 /* ---- card 0x28 ---------------------------------- */ 948 /* ---- card 0x28 ---------------------------------- */
997 [BTTV_BOARD_STB2] = { 949 [BTTV_BOARD_STB2] = {
998 .name = "STB TV PCI FM, Gateway P/N 6000704 (bt878), 3Dfx VoodooTV 100", 950 .name = "STB TV PCI FM, Gateway P/N 6000704 (bt878), 3Dfx VoodooTV 100",
999 .video_inputs = 3, 951 .video_inputs = 3,
1000 .audio_inputs = 1, 952 /* .audio_inputs= 1, */
1001 .tuner = 0,
1002 .svhs = 2, 953 .svhs = 2,
1003 .gpiomask = 7, 954 .gpiomask = 7,
1004 .muxsel = { 2, 3, 1, 1 }, 955 .muxsel = MUXSEL(2, 3, 1, 1),
1005 .gpiomux = { 4, 0, 2, 3 }, 956 .gpiomux = { 4, 0, 2, 3 },
1006 .gpiomute = 1, 957 .gpiomute = 1,
1007 .no_msp34xx = 1, 958 .no_msp34xx = 1,
1008 .needs_tvaudio = 1, 959 .needs_tvaudio = 1,
1009 .tuner_type = TUNER_PHILIPS_NTSC, 960 .tuner_type = TUNER_PHILIPS_NTSC,
1010 .tuner_addr = ADDR_UNSET, 961 .tuner_addr = ADDR_UNSET,
1011 .radio_addr = ADDR_UNSET,
1012 .pll = PLL_28, 962 .pll = PLL_28,
1013 .has_radio = 1, 963 .has_radio = 1,
1014 }, 964 },
1015 [BTTV_BOARD_AVPHONE98] = { 965 [BTTV_BOARD_AVPHONE98] = {
1016 .name = "AVerMedia TVPhone 98", 966 .name = "AVerMedia TVPhone 98",
1017 .video_inputs = 3, 967 .video_inputs = 3,
1018 .audio_inputs = 4, 968 /* .audio_inputs= 4, */
1019 .tuner = 0,
1020 .svhs = 2, 969 .svhs = 2,
1021 .gpiomask = 15, 970 .gpiomask = 15,
1022 .muxsel = { 2, 3, 1, 1 }, 971 .muxsel = MUXSEL(2, 3, 1, 1),
1023 .gpiomux = { 13, 4, 11, 7 }, 972 .gpiomux = { 13, 4, 11, 7 },
1024 .needs_tvaudio = 1, 973 .needs_tvaudio = 1,
1025 .pll = PLL_28, 974 .pll = PLL_28,
1026 .tuner_type = UNSET, 975 .tuner_type = UNSET,
1027 .tuner_addr = ADDR_UNSET, 976 .tuner_addr = ADDR_UNSET,
1028 .radio_addr = ADDR_UNSET,
1029 .has_radio = 1, 977 .has_radio = 1,
1030 .audio_mode_gpio= avermedia_tvphone_audio, 978 .audio_mode_gpio= avermedia_tvphone_audio,
1031 }, 979 },
1032 [BTTV_BOARD_PV951] = { 980 [BTTV_BOARD_PV951] = {
1033 .name = "ProVideo PV951", /* pic16c54 */ 981 .name = "ProVideo PV951", /* pic16c54 */
1034 .video_inputs = 3, 982 .video_inputs = 3,
1035 .audio_inputs = 1, 983 /* .audio_inputs= 1, */
1036 .tuner = 0,
1037 .svhs = 2, 984 .svhs = 2,
1038 .gpiomask = 0, 985 .gpiomask = 0,
1039 .muxsel = { 2, 3, 1, 1}, 986 .muxsel = MUXSEL(2, 3, 1, 1),
1040 .gpiomux = { 0, 0, 0, 0}, 987 .gpiomux = { 0, 0, 0, 0},
1041 .needs_tvaudio = 1, 988 .needs_tvaudio = 1,
1042 .no_msp34xx = 1, 989 .no_msp34xx = 1,
1043 .pll = PLL_28, 990 .pll = PLL_28,
1044 .tuner_type = TUNER_PHILIPS_PAL_I, 991 .tuner_type = TUNER_PHILIPS_PAL_I,
1045 .tuner_addr = ADDR_UNSET, 992 .tuner_addr = ADDR_UNSET,
1046 .radio_addr = ADDR_UNSET,
1047 }, 993 },
1048 [BTTV_BOARD_ONAIR_TV] = { 994 [BTTV_BOARD_ONAIR_TV] = {
1049 .name = "Little OnAir TV", 995 .name = "Little OnAir TV",
1050 .video_inputs = 3, 996 .video_inputs = 3,
1051 .audio_inputs = 1, 997 /* .audio_inputs= 1, */
1052 .tuner = 0,
1053 .svhs = 2, 998 .svhs = 2,
1054 .gpiomask = 0xe00b, 999 .gpiomask = 0xe00b,
1055 .muxsel = { 2, 3, 1, 1 }, 1000 .muxsel = MUXSEL(2, 3, 1, 1),
1056 .gpiomux = { 0xff9ff6, 0xff9ff6, 0xff1ff7, 0 }, 1001 .gpiomux = { 0xff9ff6, 0xff9ff6, 0xff1ff7, 0 },
1057 .gpiomute = 0xff3ffc, 1002 .gpiomute = 0xff3ffc,
1058 .no_msp34xx = 1, 1003 .no_msp34xx = 1,
1059 .tuner_type = UNSET, 1004 .tuner_type = UNSET,
1060 .tuner_addr = ADDR_UNSET, 1005 .tuner_addr = ADDR_UNSET,
1061 .radio_addr = ADDR_UNSET,
1062 }, 1006 },
1063 1007
1064 /* ---- card 0x2c ---------------------------------- */ 1008 /* ---- card 0x2c ---------------------------------- */
1065 [BTTV_BOARD_SIGMA_TVII_FM] = { 1009 [BTTV_BOARD_SIGMA_TVII_FM] = {
1066 .name = "Sigma TVII-FM", 1010 .name = "Sigma TVII-FM",
1067 .video_inputs = 2, 1011 .video_inputs = 2,
1068 .audio_inputs = 1, 1012 /* .audio_inputs= 1, */
1069 .tuner = 0, 1013 .svhs = NO_SVHS,
1070 .svhs = UNSET,
1071 .gpiomask = 3, 1014 .gpiomask = 3,
1072 .muxsel = { 2, 3, 1, 1 }, 1015 .muxsel = MUXSEL(2, 3, 1, 1),
1073 .gpiomux = { 1, 1, 0, 2 }, 1016 .gpiomux = { 1, 1, 0, 2 },
1074 .gpiomute = 3, 1017 .gpiomute = 3,
1075 .no_msp34xx = 1, 1018 .no_msp34xx = 1,
1076 .pll = PLL_NONE, 1019 .pll = PLL_NONE,
1077 .tuner_type = UNSET, 1020 .tuner_type = UNSET,
1078 .tuner_addr = ADDR_UNSET, 1021 .tuner_addr = ADDR_UNSET,
1079 .radio_addr = ADDR_UNSET,
1080 }, 1022 },
1081 [BTTV_BOARD_MATRIX_VISION2] = { 1023 [BTTV_BOARD_MATRIX_VISION2] = {
1082 .name = "MATRIX-Vision MV-Delta 2", 1024 .name = "MATRIX-Vision MV-Delta 2",
1083 .video_inputs = 5, 1025 .video_inputs = 5,
1084 .audio_inputs = 1, 1026 /* .audio_inputs= 1, */
1085 .tuner = UNSET,
1086 .svhs = 3, 1027 .svhs = 3,
1087 .gpiomask = 0, 1028 .gpiomask = 0,
1088 .muxsel = { 2, 3, 1, 0, 0 }, 1029 .muxsel = MUXSEL(2, 3, 1, 0, 0),
1089 .gpiomux = { 0 }, 1030 .gpiomux = { 0 },
1090 .no_msp34xx = 1, 1031 .no_msp34xx = 1,
1091 .pll = PLL_28, 1032 .pll = PLL_28,
1092 .tuner_type = UNSET, 1033 .tuner_type = TUNER_ABSENT,
1093 .tuner_addr = ADDR_UNSET, 1034 .tuner_addr = ADDR_UNSET,
1094 .radio_addr = ADDR_UNSET,
1095 }, 1035 },
1096 [BTTV_BOARD_ZOLTRIX_GENIE] = { 1036 [BTTV_BOARD_ZOLTRIX_GENIE] = {
1097 .name = "Zoltrix Genie TV/FM", 1037 .name = "Zoltrix Genie TV/FM",
1098 .video_inputs = 3, 1038 .video_inputs = 3,
1099 .audio_inputs = 1, 1039 /* .audio_inputs= 1, */
1100 .tuner = 0,
1101 .svhs = 2, 1040 .svhs = 2,
1102 .gpiomask = 0xbcf03f, 1041 .gpiomask = 0xbcf03f,
1103 .muxsel = { 2, 3, 1, 1 }, 1042 .muxsel = MUXSEL(2, 3, 1, 1),
1104 .gpiomux = { 0xbc803f, 0xbc903f, 0xbcb03f, 0 }, 1043 .gpiomux = { 0xbc803f, 0xbc903f, 0xbcb03f, 0 },
1105 .gpiomute = 0xbcb03f, 1044 .gpiomute = 0xbcb03f,
1106 .no_msp34xx = 1, 1045 .no_msp34xx = 1,
1107 .pll = PLL_28, 1046 .pll = PLL_28,
1108 .tuner_type = TUNER_TEMIC_4039FR5_NTSC, 1047 .tuner_type = TUNER_TEMIC_4039FR5_NTSC,
1109 .tuner_addr = ADDR_UNSET, 1048 .tuner_addr = ADDR_UNSET,
1110 .radio_addr = ADDR_UNSET,
1111 }, 1049 },
1112 [BTTV_BOARD_TERRATVRADIO] = { 1050 [BTTV_BOARD_TERRATVRADIO] = {
1113 .name = "Terratec TV/Radio+", 1051 .name = "Terratec TV/Radio+",
1114 .video_inputs = 3, 1052 .video_inputs = 3,
1115 .audio_inputs = 1, 1053 /* .audio_inputs= 1, */
1116 .tuner = 0,
1117 .svhs = 2, 1054 .svhs = 2,
1118 .gpiomask = 0x70000, 1055 .gpiomask = 0x70000,
1119 .muxsel = { 2, 3, 1, 1 }, 1056 .muxsel = MUXSEL(2, 3, 1, 1),
1120 .gpiomux = { 0x20000, 0x30000, 0x10000, 0 }, 1057 .gpiomux = { 0x20000, 0x30000, 0x10000, 0 },
1121 .gpiomute = 0x40000, 1058 .gpiomute = 0x40000,
1122 .needs_tvaudio = 1, 1059 .needs_tvaudio = 1,
@@ -1124,7 +1061,6 @@ struct tvcard bttv_tvcards[] = {
1124 .pll = PLL_35, 1061 .pll = PLL_35,
1125 .tuner_type = TUNER_PHILIPS_PAL_I, 1062 .tuner_type = TUNER_PHILIPS_PAL_I,
1126 .tuner_addr = ADDR_UNSET, 1063 .tuner_addr = ADDR_UNSET,
1127 .radio_addr = ADDR_UNSET,
1128 .has_radio = 1, 1064 .has_radio = 1,
1129 }, 1065 },
1130 1066
@@ -1132,51 +1068,46 @@ struct tvcard bttv_tvcards[] = {
1132 [BTTV_BOARD_DYNALINK] = { 1068 [BTTV_BOARD_DYNALINK] = {
1133 .name = "Askey CPH03x/ Dynalink Magic TView", 1069 .name = "Askey CPH03x/ Dynalink Magic TView",
1134 .video_inputs = 3, 1070 .video_inputs = 3,
1135 .audio_inputs = 1, 1071 /* .audio_inputs= 1, */
1136 .tuner = 0,
1137 .svhs = 2, 1072 .svhs = 2,
1138 .gpiomask = 15, 1073 .gpiomask = 15,
1139 .muxsel = { 2, 3, 1, 1 }, 1074 .muxsel = MUXSEL(2, 3, 1, 1),
1140 .gpiomux = {2,0,0,0 }, 1075 .gpiomux = {2,0,0,0 },
1141 .gpiomute = 1, 1076 .gpiomute = 1,
1142 .needs_tvaudio = 1, 1077 .needs_tvaudio = 1,
1143 .pll = PLL_28, 1078 .pll = PLL_28,
1144 .tuner_type = UNSET, 1079 .tuner_type = UNSET,
1145 .tuner_addr = ADDR_UNSET, 1080 .tuner_addr = ADDR_UNSET,
1146 .radio_addr = ADDR_UNSET,
1147 }, 1081 },
1148 [BTTV_BOARD_GVBCTV3PCI] = { 1082 [BTTV_BOARD_GVBCTV3PCI] = {
1149 .name = "IODATA GV-BCTV3/PCI", 1083 .name = "IODATA GV-BCTV3/PCI",
1150 .video_inputs = 3, 1084 .video_inputs = 3,
1151 .audio_inputs = 1, 1085 /* .audio_inputs= 1, */
1152 .tuner = 0,
1153 .svhs = 2, 1086 .svhs = 2,
1154 .gpiomask = 0x010f00, 1087 .gpiomask = 0x010f00,
1155 .muxsel = {2, 3, 0, 0 }, 1088 .muxsel = MUXSEL(2, 3, 0, 0),
1156 .gpiomux = {0x10000, 0, 0x10000, 0 }, 1089 .gpiomux = {0x10000, 0, 0x10000, 0 },
1157 .no_msp34xx = 1, 1090 .no_msp34xx = 1,
1158 .pll = PLL_28, 1091 .pll = PLL_28,
1159 .tuner_type = TUNER_ALPS_TSHC6_NTSC, 1092 .tuner_type = TUNER_ALPS_TSHC6_NTSC,
1160 .tuner_addr = ADDR_UNSET, 1093 .tuner_addr = ADDR_UNSET,
1161 .radio_addr = ADDR_UNSET,
1162 .audio_mode_gpio= gvbctv3pci_audio, 1094 .audio_mode_gpio= gvbctv3pci_audio,
1163 }, 1095 },
1164 [BTTV_BOARD_PXELVWPLTVPAK] = { 1096 [BTTV_BOARD_PXELVWPLTVPAK] = {
1165 .name = "Prolink PV-BT878P+4E / PixelView PlayTV PAK / Lenco MXTV-9578 CP", 1097 .name = "Prolink PV-BT878P+4E / PixelView PlayTV PAK / Lenco MXTV-9578 CP",
1166 .video_inputs = 5, 1098 .video_inputs = 5,
1167 .audio_inputs = 1, 1099 /* .audio_inputs= 1, */
1168 .tuner = 0,
1169 .svhs = 3, 1100 .svhs = 3,
1101 .has_dig_in = 1,
1170 .gpiomask = 0xAA0000, 1102 .gpiomask = 0xAA0000,
1171 .muxsel = { 2,3,1,1,-1 }, 1103 .muxsel = MUXSEL(2, 3, 1, 1, 0), /* in 4 is digital */
1172 .digital_mode = DIGITAL_MODE_CAMERA, 1104 /* .digital_mode= DIGITAL_MODE_CAMERA, */
1173 .gpiomux = { 0x20000, 0, 0x80000, 0x80000 }, 1105 .gpiomux = { 0x20000, 0, 0x80000, 0x80000 },
1174 .gpiomute = 0xa8000, 1106 .gpiomute = 0xa8000,
1175 .no_msp34xx = 1, 1107 .no_msp34xx = 1,
1176 .pll = PLL_28, 1108 .pll = PLL_28,
1177 .tuner_type = TUNER_PHILIPS_PAL_I, 1109 .tuner_type = TUNER_PHILIPS_PAL_I,
1178 .tuner_addr = ADDR_UNSET, 1110 .tuner_addr = ADDR_UNSET,
1179 .radio_addr = ADDR_UNSET,
1180 .has_remote = 1, 1111 .has_remote = 1,
1181 /* GPIO wiring: (different from Rev.4C !) 1112 /* GPIO wiring: (different from Rev.4C !)
1182 GPIO17: U4.A0 (first hef4052bt) 1113 GPIO17: U4.A0 (first hef4052bt)
@@ -1191,17 +1122,15 @@ struct tvcard bttv_tvcards[] = {
1191 [BTTV_BOARD_EAGLE] = { 1122 [BTTV_BOARD_EAGLE] = {
1192 .name = "Eagle Wireless Capricorn2 (bt878A)", 1123 .name = "Eagle Wireless Capricorn2 (bt878A)",
1193 .video_inputs = 4, 1124 .video_inputs = 4,
1194 .audio_inputs = 1, 1125 /* .audio_inputs= 1, */
1195 .tuner = 0,
1196 .svhs = 2, 1126 .svhs = 2,
1197 .gpiomask = 7, 1127 .gpiomask = 7,
1198 .muxsel = { 2, 0, 1, 1 }, 1128 .muxsel = MUXSEL(2, 0, 1, 1),
1199 .gpiomux = { 0, 1, 2, 3 }, 1129 .gpiomux = { 0, 1, 2, 3 },
1200 .gpiomute = 4, 1130 .gpiomute = 4,
1201 .pll = PLL_28, 1131 .pll = PLL_28,
1202 .tuner_type = UNSET /* TUNER_ALPS_TMDH2_NTSC */, 1132 .tuner_type = UNSET /* TUNER_ALPS_TMDH2_NTSC */,
1203 .tuner_addr = ADDR_UNSET, 1133 .tuner_addr = ADDR_UNSET,
1204 .radio_addr = ADDR_UNSET,
1205 }, 1134 },
1206 1135
1207 /* ---- card 0x34 ---------------------------------- */ 1136 /* ---- card 0x34 ---------------------------------- */
@@ -1209,11 +1138,10 @@ struct tvcard bttv_tvcards[] = {
1209 /* David Härdeman <david@2gen.com> */ 1138 /* David Härdeman <david@2gen.com> */
1210 .name = "Pinnacle PCTV Studio Pro", 1139 .name = "Pinnacle PCTV Studio Pro",
1211 .video_inputs = 4, 1140 .video_inputs = 4,
1212 .audio_inputs = 1, 1141 /* .audio_inputs= 1, */
1213 .tuner = 0,
1214 .svhs = 3, 1142 .svhs = 3,
1215 .gpiomask = 0x03000F, 1143 .gpiomask = 0x03000F,
1216 .muxsel = { 2, 3, 1, 1 }, 1144 .muxsel = MUXSEL(2, 3, 1, 1),
1217 .gpiomux = { 1, 0xd0001, 0, 0 }, 1145 .gpiomux = { 1, 0xd0001, 0, 0 },
1218 .gpiomute = 10, 1146 .gpiomute = 10,
1219 /* sound path (5 sources): 1147 /* sound path (5 sources):
@@ -1229,25 +1157,22 @@ struct tvcard bttv_tvcards[] = {
1229 .pll = PLL_28, 1157 .pll = PLL_28,
1230 .tuner_type = UNSET, 1158 .tuner_type = UNSET,
1231 .tuner_addr = ADDR_UNSET, 1159 .tuner_addr = ADDR_UNSET,
1232 .radio_addr = ADDR_UNSET,
1233 }, 1160 },
1234 [BTTV_BOARD_TVIEW_RDS_FM] = { 1161 [BTTV_BOARD_TVIEW_RDS_FM] = {
1235 /* Claas Langbehn <claas@bigfoot.com>, 1162 /* Claas Langbehn <claas@bigfoot.com>,
1236 Sven Grothklags <sven@upb.de> */ 1163 Sven Grothklags <sven@upb.de> */
1237 .name = "Typhoon TView RDS + FM Stereo / KNC1 TV Station RDS", 1164 .name = "Typhoon TView RDS + FM Stereo / KNC1 TV Station RDS",
1238 .video_inputs = 4, 1165 .video_inputs = 4,
1239 .audio_inputs = 3, 1166 /* .audio_inputs= 3, */
1240 .tuner = 0,
1241 .svhs = 2, 1167 .svhs = 2,
1242 .gpiomask = 0x1c, 1168 .gpiomask = 0x1c,
1243 .muxsel = { 2, 3, 1, 1 }, 1169 .muxsel = MUXSEL(2, 3, 1, 1),
1244 .gpiomux = { 0, 0, 0x10, 8 }, 1170 .gpiomux = { 0, 0, 0x10, 8 },
1245 .gpiomute = 4, 1171 .gpiomute = 4,
1246 .needs_tvaudio = 1, 1172 .needs_tvaudio = 1,
1247 .pll = PLL_28, 1173 .pll = PLL_28,
1248 .tuner_type = TUNER_PHILIPS_PAL, 1174 .tuner_type = TUNER_PHILIPS_PAL,
1249 .tuner_addr = ADDR_UNSET, 1175 .tuner_addr = ADDR_UNSET,
1250 .radio_addr = ADDR_UNSET,
1251 .has_radio = 1, 1176 .has_radio = 1,
1252 }, 1177 },
1253 [BTTV_BOARD_LIFETEC_9415] = { 1178 [BTTV_BOARD_LIFETEC_9415] = {
@@ -1258,11 +1183,10 @@ struct tvcard bttv_tvcards[] = {
1258 options tuner type=5 */ 1183 options tuner type=5 */
1259 .name = "Lifeview FlyVideo 2000 /FlyVideo A2/ Lifetec LT 9415 TV [LR90]", 1184 .name = "Lifeview FlyVideo 2000 /FlyVideo A2/ Lifetec LT 9415 TV [LR90]",
1260 .video_inputs = 4, 1185 .video_inputs = 4,
1261 .audio_inputs = 1, 1186 /* .audio_inputs= 1, */
1262 .tuner = 0,
1263 .svhs = 2, 1187 .svhs = 2,
1264 .gpiomask = 0x18e0, 1188 .gpiomask = 0x18e0,
1265 .muxsel = { 2, 3, 1, 1 }, 1189 .muxsel = MUXSEL(2, 3, 1, 1),
1266 .gpiomux = { 0x0000,0x0800,0x1000,0x1000 }, 1190 .gpiomux = { 0x0000,0x0800,0x1000,0x1000 },
1267 .gpiomute = 0x18e0, 1191 .gpiomute = 0x18e0,
1268 /* For cards with tda9820/tda9821: 1192 /* For cards with tda9820/tda9821:
@@ -1272,25 +1196,22 @@ struct tvcard bttv_tvcards[] = {
1272 .pll = PLL_28, 1196 .pll = PLL_28,
1273 .tuner_type = UNSET, 1197 .tuner_type = UNSET,
1274 .tuner_addr = ADDR_UNSET, 1198 .tuner_addr = ADDR_UNSET,
1275 .radio_addr = ADDR_UNSET,
1276 }, 1199 },
1277 [BTTV_BOARD_BESTBUY_EASYTV] = { 1200 [BTTV_BOARD_BESTBUY_EASYTV] = {
1278 /* Miguel Angel Alvarez <maacruz@navegalia.com> 1201 /* Miguel Angel Alvarez <maacruz@navegalia.com>
1279 old Easy TV BT848 version (model CPH031) */ 1202 old Easy TV BT848 version (model CPH031) */
1280 .name = "Askey CPH031/ BESTBUY Easy TV", 1203 .name = "Askey CPH031/ BESTBUY Easy TV",
1281 .video_inputs = 4, 1204 .video_inputs = 4,
1282 .audio_inputs = 1, 1205 /* .audio_inputs= 1, */
1283 .tuner = 0,
1284 .svhs = 2, 1206 .svhs = 2,
1285 .gpiomask = 0xF, 1207 .gpiomask = 0xF,
1286 .muxsel = { 2, 3, 1, 0 }, 1208 .muxsel = MUXSEL(2, 3, 1, 0),
1287 .gpiomux = { 2, 0, 0, 0 }, 1209 .gpiomux = { 2, 0, 0, 0 },
1288 .gpiomute = 10, 1210 .gpiomute = 10,
1289 .needs_tvaudio = 0, 1211 .needs_tvaudio = 0,
1290 .pll = PLL_28, 1212 .pll = PLL_28,
1291 .tuner_type = TUNER_TEMIC_PAL, 1213 .tuner_type = TUNER_TEMIC_PAL,
1292 .tuner_addr = ADDR_UNSET, 1214 .tuner_addr = ADDR_UNSET,
1293 .radio_addr = ADDR_UNSET,
1294 }, 1215 },
1295 1216
1296 /* ---- card 0x38 ---------------------------------- */ 1217 /* ---- card 0x38 ---------------------------------- */
@@ -1298,17 +1219,15 @@ struct tvcard bttv_tvcards[] = {
1298 /* Gordon Heydon <gjheydon@bigfoot.com ('98) */ 1219 /* Gordon Heydon <gjheydon@bigfoot.com ('98) */
1299 .name = "Lifeview FlyVideo 98FM LR50", 1220 .name = "Lifeview FlyVideo 98FM LR50",
1300 .video_inputs = 4, 1221 .video_inputs = 4,
1301 .audio_inputs = 3, 1222 /* .audio_inputs= 3, */
1302 .tuner = 0,
1303 .svhs = 2, 1223 .svhs = 2,
1304 .gpiomask = 0x1800, 1224 .gpiomask = 0x1800,
1305 .muxsel = { 2, 3, 1, 1 }, 1225 .muxsel = MUXSEL(2, 3, 1, 1),
1306 .gpiomux = { 0, 0x800, 0x1000, 0x1000 }, 1226 .gpiomux = { 0, 0x800, 0x1000, 0x1000 },
1307 .gpiomute = 0x1800, 1227 .gpiomute = 0x1800,
1308 .pll = PLL_28, 1228 .pll = PLL_28,
1309 .tuner_type = TUNER_PHILIPS_PAL, 1229 .tuner_type = TUNER_PHILIPS_PAL,
1310 .tuner_addr = ADDR_UNSET, 1230 .tuner_addr = ADDR_UNSET,
1311 .radio_addr = ADDR_UNSET,
1312 }, 1231 },
1313 /* This is the ultimate cheapo capture card 1232 /* This is the ultimate cheapo capture card
1314 * just a BT848A on a small PCB! 1233 * just a BT848A on a small PCB!
@@ -1316,51 +1235,45 @@ struct tvcard bttv_tvcards[] = {
1316 [BTTV_BOARD_GRANDTEC] = { 1235 [BTTV_BOARD_GRANDTEC] = {
1317 .name = "GrandTec 'Grand Video Capture' (Bt848)", 1236 .name = "GrandTec 'Grand Video Capture' (Bt848)",
1318 .video_inputs = 2, 1237 .video_inputs = 2,
1319 .audio_inputs = 0, 1238 /* .audio_inputs= 0, */
1320 .tuner = UNSET,
1321 .svhs = 1, 1239 .svhs = 1,
1322 .gpiomask = 0, 1240 .gpiomask = 0,
1323 .muxsel = { 3, 1 }, 1241 .muxsel = MUXSEL(3, 1),
1324 .gpiomux = { 0 }, 1242 .gpiomux = { 0 },
1325 .needs_tvaudio = 0, 1243 .needs_tvaudio = 0,
1326 .no_msp34xx = 1, 1244 .no_msp34xx = 1,
1327 .pll = PLL_35, 1245 .pll = PLL_35,
1328 .tuner_type = UNSET, 1246 .tuner_type = TUNER_ABSENT,
1329 .tuner_addr = ADDR_UNSET, 1247 .tuner_addr = ADDR_UNSET,
1330 .radio_addr = ADDR_UNSET,
1331 }, 1248 },
1332 [BTTV_BOARD_ASKEY_CPH060] = { 1249 [BTTV_BOARD_ASKEY_CPH060] = {
1333 /* Daniel Herrington <daniel.herrington@home.com> */ 1250 /* Daniel Herrington <daniel.herrington@home.com> */
1334 .name = "Askey CPH060/ Phoebe TV Master Only (No FM)", 1251 .name = "Askey CPH060/ Phoebe TV Master Only (No FM)",
1335 .video_inputs = 3, 1252 .video_inputs = 3,
1336 .audio_inputs = 1, 1253 /* .audio_inputs= 1, */
1337 .tuner = 0,
1338 .svhs = 2, 1254 .svhs = 2,
1339 .gpiomask = 0xe00, 1255 .gpiomask = 0xe00,
1340 .muxsel = { 2, 3, 1, 1}, 1256 .muxsel = MUXSEL(2, 3, 1, 1),
1341 .gpiomux = { 0x400, 0x400, 0x400, 0x400 }, 1257 .gpiomux = { 0x400, 0x400, 0x400, 0x400 },
1342 .gpiomute = 0x800, 1258 .gpiomute = 0x800,
1343 .needs_tvaudio = 1, 1259 .needs_tvaudio = 1,
1344 .pll = PLL_28, 1260 .pll = PLL_28,
1345 .tuner_type = TUNER_TEMIC_4036FY5_NTSC, 1261 .tuner_type = TUNER_TEMIC_4036FY5_NTSC,
1346 .tuner_addr = ADDR_UNSET, 1262 .tuner_addr = ADDR_UNSET,
1347 .radio_addr = ADDR_UNSET,
1348 }, 1263 },
1349 [BTTV_BOARD_ASKEY_CPH03X] = { 1264 [BTTV_BOARD_ASKEY_CPH03X] = {
1350 /* Matti Mottus <mottus@physic.ut.ee> */ 1265 /* Matti Mottus <mottus@physic.ut.ee> */
1351 .name = "Askey CPH03x TV Capturer", 1266 .name = "Askey CPH03x TV Capturer",
1352 .video_inputs = 4, 1267 .video_inputs = 4,
1353 .audio_inputs = 1, 1268 /* .audio_inputs= 1, */
1354 .tuner = 0,
1355 .svhs = 2, 1269 .svhs = 2,
1356 .gpiomask = 0x03000F, 1270 .gpiomask = 0x03000F,
1357 .muxsel = { 2, 3, 1, 0 }, 1271 .muxsel = MUXSEL(2, 3, 1, 0),
1358 .gpiomux = { 2, 0, 0, 0 }, 1272 .gpiomux = { 2, 0, 0, 0 },
1359 .gpiomute = 1, 1273 .gpiomute = 1,
1360 .pll = PLL_28, 1274 .pll = PLL_28,
1361 .tuner_type = TUNER_TEMIC_PAL, 1275 .tuner_type = TUNER_TEMIC_PAL,
1362 .tuner_addr = ADDR_UNSET, 1276 .tuner_addr = ADDR_UNSET,
1363 .radio_addr = ADDR_UNSET,
1364 }, 1277 },
1365 1278
1366 /* ---- card 0x3c ---------------------------------- */ 1279 /* ---- card 0x3c ---------------------------------- */
@@ -1368,34 +1281,30 @@ struct tvcard bttv_tvcards[] = {
1368 /* Philip Blundell <philb@gnu.org> */ 1281 /* Philip Blundell <philb@gnu.org> */
1369 .name = "Modular Technology MM100PCTV", 1282 .name = "Modular Technology MM100PCTV",
1370 .video_inputs = 2, 1283 .video_inputs = 2,
1371 .audio_inputs = 2, 1284 /* .audio_inputs= 2, */
1372 .tuner = 0, 1285 .svhs = NO_SVHS,
1373 .svhs = UNSET,
1374 .gpiomask = 11, 1286 .gpiomask = 11,
1375 .muxsel = { 2, 3, 1, 1 }, 1287 .muxsel = MUXSEL(2, 3, 1, 1),
1376 .gpiomux = { 2, 0, 0, 1 }, 1288 .gpiomux = { 2, 0, 0, 1 },
1377 .gpiomute = 8, 1289 .gpiomute = 8,
1378 .pll = PLL_35, 1290 .pll = PLL_35,
1379 .tuner_type = TUNER_TEMIC_PAL, 1291 .tuner_type = TUNER_TEMIC_PAL,
1380 .tuner_addr = ADDR_UNSET, 1292 .tuner_addr = ADDR_UNSET,
1381 .radio_addr = ADDR_UNSET,
1382 }, 1293 },
1383 [BTTV_BOARD_GMV1] = { 1294 [BTTV_BOARD_GMV1] = {
1384 /* Adrian Cox <adrian@humboldt.co.uk */ 1295 /* Adrian Cox <adrian@humboldt.co.uk */
1385 .name = "AG Electronics GMV1", 1296 .name = "AG Electronics GMV1",
1386 .video_inputs = 2, 1297 .video_inputs = 2,
1387 .audio_inputs = 0, 1298 /* .audio_inputs= 0, */
1388 .tuner = UNSET,
1389 .svhs = 1, 1299 .svhs = 1,
1390 .gpiomask = 0xF, 1300 .gpiomask = 0xF,
1391 .muxsel = { 2, 2 }, 1301 .muxsel = MUXSEL(2, 2),
1392 .gpiomux = { }, 1302 .gpiomux = { },
1393 .no_msp34xx = 1, 1303 .no_msp34xx = 1,
1394 .needs_tvaudio = 0, 1304 .needs_tvaudio = 0,
1395 .pll = PLL_28, 1305 .pll = PLL_28,
1396 .tuner_type = UNSET, 1306 .tuner_type = TUNER_ABSENT,
1397 .tuner_addr = ADDR_UNSET, 1307 .tuner_addr = ADDR_UNSET,
1398 .radio_addr = ADDR_UNSET,
1399 }, 1308 },
1400 [BTTV_BOARD_BESTBUY_EASYTV2] = { 1309 [BTTV_BOARD_BESTBUY_EASYTV2] = {
1401 /* Miguel Angel Alvarez <maacruz@navegalia.com> 1310 /* Miguel Angel Alvarez <maacruz@navegalia.com>
@@ -1403,34 +1312,30 @@ struct tvcard bttv_tvcards[] = {
1403 special thanks to Informatica Mieres for providing the card */ 1312 special thanks to Informatica Mieres for providing the card */
1404 .name = "Askey CPH061/ BESTBUY Easy TV (bt878)", 1313 .name = "Askey CPH061/ BESTBUY Easy TV (bt878)",
1405 .video_inputs = 3, 1314 .video_inputs = 3,
1406 .audio_inputs = 2, 1315 /* .audio_inputs= 2, */
1407 .tuner = 0,
1408 .svhs = 2, 1316 .svhs = 2,
1409 .gpiomask = 0xFF, 1317 .gpiomask = 0xFF,
1410 .muxsel = { 2, 3, 1, 0 }, 1318 .muxsel = MUXSEL(2, 3, 1, 0),
1411 .gpiomux = { 1, 0, 4, 4 }, 1319 .gpiomux = { 1, 0, 4, 4 },
1412 .gpiomute = 9, 1320 .gpiomute = 9,
1413 .needs_tvaudio = 0, 1321 .needs_tvaudio = 0,
1414 .pll = PLL_28, 1322 .pll = PLL_28,
1415 .tuner_type = TUNER_PHILIPS_PAL, 1323 .tuner_type = TUNER_PHILIPS_PAL,
1416 .tuner_addr = ADDR_UNSET, 1324 .tuner_addr = ADDR_UNSET,
1417 .radio_addr = ADDR_UNSET,
1418 }, 1325 },
1419 [BTTV_BOARD_ATI_TVWONDER] = { 1326 [BTTV_BOARD_ATI_TVWONDER] = {
1420 /* Lukas Gebauer <geby@volny.cz> */ 1327 /* Lukas Gebauer <geby@volny.cz> */
1421 .name = "ATI TV-Wonder", 1328 .name = "ATI TV-Wonder",
1422 .video_inputs = 3, 1329 .video_inputs = 3,
1423 .audio_inputs = 1, 1330 /* .audio_inputs= 1, */
1424 .tuner = 0,
1425 .svhs = 2, 1331 .svhs = 2,
1426 .gpiomask = 0xf03f, 1332 .gpiomask = 0xf03f,
1427 .muxsel = { 2, 3, 1, 0 }, 1333 .muxsel = MUXSEL(2, 3, 1, 0),
1428 .gpiomux = { 0xbffe, 0, 0xbfff, 0 }, 1334 .gpiomux = { 0xbffe, 0, 0xbfff, 0 },
1429 .gpiomute = 0xbffe, 1335 .gpiomute = 0xbffe,
1430 .pll = PLL_28, 1336 .pll = PLL_28,
1431 .tuner_type = TUNER_TEMIC_4006FN5_MULTI_PAL, 1337 .tuner_type = TUNER_TEMIC_4006FN5_MULTI_PAL,
1432 .tuner_addr = ADDR_UNSET, 1338 .tuner_addr = ADDR_UNSET,
1433 .radio_addr = ADDR_UNSET,
1434 }, 1339 },
1435 1340
1436 /* ---- card 0x40 ---------------------------------- */ 1341 /* ---- card 0x40 ---------------------------------- */
@@ -1438,27 +1343,24 @@ struct tvcard bttv_tvcards[] = {
1438 /* Lukas Gebauer <geby@volny.cz> */ 1343 /* Lukas Gebauer <geby@volny.cz> */
1439 .name = "ATI TV-Wonder VE", 1344 .name = "ATI TV-Wonder VE",
1440 .video_inputs = 2, 1345 .video_inputs = 2,
1441 .audio_inputs = 1, 1346 /* .audio_inputs= 1, */
1442 .tuner = 0, 1347 .svhs = NO_SVHS,
1443 .svhs = UNSET,
1444 .gpiomask = 1, 1348 .gpiomask = 1,
1445 .muxsel = { 2, 3, 0, 1 }, 1349 .muxsel = MUXSEL(2, 3, 0, 1),
1446 .gpiomux = { 0, 0, 1, 0 }, 1350 .gpiomux = { 0, 0, 1, 0 },
1447 .no_msp34xx = 1, 1351 .no_msp34xx = 1,
1448 .pll = PLL_28, 1352 .pll = PLL_28,
1449 .tuner_type = TUNER_TEMIC_4006FN5_MULTI_PAL, 1353 .tuner_type = TUNER_TEMIC_4006FN5_MULTI_PAL,
1450 .tuner_addr = ADDR_UNSET, 1354 .tuner_addr = ADDR_UNSET,
1451 .radio_addr = ADDR_UNSET,
1452 }, 1355 },
1453 [BTTV_BOARD_FLYVIDEO2000] = { 1356 [BTTV_BOARD_FLYVIDEO2000] = {
1454 /* DeeJay <deejay@westel900.net (2000S) */ 1357 /* DeeJay <deejay@westel900.net (2000S) */
1455 .name = "Lifeview FlyVideo 2000S LR90", 1358 .name = "Lifeview FlyVideo 2000S LR90",
1456 .video_inputs = 3, 1359 .video_inputs = 3,
1457 .audio_inputs = 3, 1360 /* .audio_inputs= 3, */
1458 .tuner = 0,
1459 .svhs = 2, 1361 .svhs = 2,
1460 .gpiomask = 0x18e0, 1362 .gpiomask = 0x18e0,
1461 .muxsel = { 2, 3, 0, 1 }, 1363 .muxsel = MUXSEL(2, 3, 0, 1),
1462 /* Radio changed from 1e80 to 0x800 to make 1364 /* Radio changed from 1e80 to 0x800 to make
1463 FlyVideo2000S in .hu happy (gm)*/ 1365 FlyVideo2000S in .hu happy (gm)*/
1464 /* -dk-???: set mute=0x1800 for tda9874h daughterboard */ 1366 /* -dk-???: set mute=0x1800 for tda9874h daughterboard */
@@ -1471,40 +1373,35 @@ struct tvcard bttv_tvcards[] = {
1471 .pll = PLL_28, 1373 .pll = PLL_28,
1472 .tuner_type = TUNER_PHILIPS_PAL, 1374 .tuner_type = TUNER_PHILIPS_PAL,
1473 .tuner_addr = ADDR_UNSET, 1375 .tuner_addr = ADDR_UNSET,
1474 .radio_addr = ADDR_UNSET,
1475 }, 1376 },
1476 [BTTV_BOARD_TERRATVALUER] = { 1377 [BTTV_BOARD_TERRATVALUER] = {
1477 .name = "Terratec TValueRadio", 1378 .name = "Terratec TValueRadio",
1478 .video_inputs = 3, 1379 .video_inputs = 3,
1479 .audio_inputs = 1, 1380 /* .audio_inputs= 1, */
1480 .tuner = 0,
1481 .svhs = 2, 1381 .svhs = 2,
1482 .gpiomask = 0xffff00, 1382 .gpiomask = 0xffff00,
1483 .muxsel = { 2, 3, 1, 1 }, 1383 .muxsel = MUXSEL(2, 3, 1, 1),
1484 .gpiomux = { 0x500, 0x500, 0x300, 0x900 }, 1384 .gpiomux = { 0x500, 0x500, 0x300, 0x900 },
1485 .gpiomute = 0x900, 1385 .gpiomute = 0x900,
1486 .needs_tvaudio = 1, 1386 .needs_tvaudio = 1,
1487 .pll = PLL_28, 1387 .pll = PLL_28,
1488 .tuner_type = TUNER_PHILIPS_PAL, 1388 .tuner_type = TUNER_PHILIPS_PAL,
1489 .tuner_addr = ADDR_UNSET, 1389 .tuner_addr = ADDR_UNSET,
1490 .radio_addr = ADDR_UNSET,
1491 .has_radio = 1, 1390 .has_radio = 1,
1492 }, 1391 },
1493 [BTTV_BOARD_GVBCTV4PCI] = { 1392 [BTTV_BOARD_GVBCTV4PCI] = {
1494 /* TANAKA Kei <peg00625@nifty.com> */ 1393 /* TANAKA Kei <peg00625@nifty.com> */
1495 .name = "IODATA GV-BCTV4/PCI", 1394 .name = "IODATA GV-BCTV4/PCI",
1496 .video_inputs = 3, 1395 .video_inputs = 3,
1497 .audio_inputs = 1, 1396 /* .audio_inputs= 1, */
1498 .tuner = 0,
1499 .svhs = 2, 1397 .svhs = 2,
1500 .gpiomask = 0x010f00, 1398 .gpiomask = 0x010f00,
1501 .muxsel = {2, 3, 0, 0 }, 1399 .muxsel = MUXSEL(2, 3, 0, 0),
1502 .gpiomux = {0x10000, 0, 0x10000, 0 }, 1400 .gpiomux = {0x10000, 0, 0x10000, 0 },
1503 .no_msp34xx = 1, 1401 .no_msp34xx = 1,
1504 .pll = PLL_28, 1402 .pll = PLL_28,
1505 .tuner_type = TUNER_SHARP_2U5JF5540_NTSC, 1403 .tuner_type = TUNER_SHARP_2U5JF5540_NTSC,
1506 .tuner_addr = ADDR_UNSET, 1404 .tuner_addr = ADDR_UNSET,
1507 .radio_addr = ADDR_UNSET,
1508 .audio_mode_gpio= gvbctv3pci_audio, 1405 .audio_mode_gpio= gvbctv3pci_audio,
1509 }, 1406 },
1510 1407
@@ -1514,9 +1411,8 @@ struct tvcard bttv_tvcards[] = {
1514 /* try "insmod msp3400 simple=0" if you have 1411 /* try "insmod msp3400 simple=0" if you have
1515 * sound problems with this card. */ 1412 * sound problems with this card. */
1516 .video_inputs = 4, 1413 .video_inputs = 4,
1517 .audio_inputs = 1, 1414 /* .audio_inputs= 1, */
1518 .tuner = 0, 1415 .svhs = NO_SVHS,
1519 .svhs = UNSET,
1520 .gpiomask = 0x4f8a00, 1416 .gpiomask = 0x4f8a00,
1521 /* 0x100000: 1=MSP enabled (0=disable again) 1417 /* 0x100000: 1=MSP enabled (0=disable again)
1522 * 0x010000: Connected to "S0" on tda9880 (0=Pal/BG, 1=NTSC) */ 1418 * 0x010000: Connected to "S0" on tda9880 (0=Pal/BG, 1=NTSC) */
@@ -1524,10 +1420,9 @@ struct tvcard bttv_tvcards[] = {
1524 .gpiomute = 0x947fff, 1420 .gpiomute = 0x947fff,
1525 /* tvtuner, radio, external,internal, mute, stereo 1421 /* tvtuner, radio, external,internal, mute, stereo
1526 * tuner, Composit, SVid, Composit-on-Svid-adapter */ 1422 * tuner, Composit, SVid, Composit-on-Svid-adapter */
1527 .muxsel = { 2, 3 ,0 ,1 }, 1423 .muxsel = MUXSEL(2, 3, 0, 1),
1528 .tuner_type = TUNER_MT2032, 1424 .tuner_type = TUNER_MT2032,
1529 .tuner_addr = ADDR_UNSET, 1425 .tuner_addr = ADDR_UNSET,
1530 .radio_addr = ADDR_UNSET,
1531 .pll = PLL_28, 1426 .pll = PLL_28,
1532 .has_radio = 1, 1427 .has_radio = 1,
1533 }, 1428 },
@@ -1536,9 +1431,8 @@ struct tvcard bttv_tvcards[] = {
1536 /* try "insmod msp3400 simple=0" if you have 1431 /* try "insmod msp3400 simple=0" if you have
1537 * sound problems with this card. */ 1432 * sound problems with this card. */
1538 .video_inputs = 4, 1433 .video_inputs = 4,
1539 .audio_inputs = 1, 1434 /* .audio_inputs= 1, */
1540 .tuner = 0, 1435 .svhs = NO_SVHS,
1541 .svhs = UNSET,
1542 .gpiomask = 0x4f8a00, 1436 .gpiomask = 0x4f8a00,
1543 /* 0x100000: 1=MSP enabled (0=disable again) 1437 /* 0x100000: 1=MSP enabled (0=disable again)
1544 * 0x010000: Connected to "S0" on tda9880 (0=Pal/BG, 1=NTSC) */ 1438 * 0x010000: Connected to "S0" on tda9880 (0=Pal/BG, 1=NTSC) */
@@ -1546,10 +1440,9 @@ struct tvcard bttv_tvcards[] = {
1546 .gpiomute = 0x947fff, 1440 .gpiomute = 0x947fff,
1547 /* tvtuner, radio, external,internal, mute, stereo 1441 /* tvtuner, radio, external,internal, mute, stereo
1548 * tuner, Composit, SVid, Composit-on-Svid-adapter */ 1442 * tuner, Composit, SVid, Composit-on-Svid-adapter */
1549 .muxsel = { 2, 3 ,0 ,1 }, 1443 .muxsel = MUXSEL(2, 3, 0, 1),
1550 .tuner_type = TUNER_MT2032, 1444 .tuner_type = TUNER_MT2032,
1551 .tuner_addr = ADDR_UNSET, 1445 .tuner_addr = ADDR_UNSET,
1552 .radio_addr = ADDR_UNSET,
1553 .pll = PLL_28, 1446 .pll = PLL_28,
1554 .has_radio = 1, 1447 .has_radio = 1,
1555 }, 1448 },
@@ -1557,31 +1450,27 @@ struct tvcard bttv_tvcards[] = {
1557 /* Philip Blundell <pb@nexus.co.uk> */ 1450 /* Philip Blundell <pb@nexus.co.uk> */
1558 .name = "Active Imaging AIMMS", 1451 .name = "Active Imaging AIMMS",
1559 .video_inputs = 1, 1452 .video_inputs = 1,
1560 .audio_inputs = 0, 1453 /* .audio_inputs= 0, */
1561 .tuner = UNSET, 1454 .tuner_type = TUNER_ABSENT,
1562 .tuner_type = UNSET,
1563 .tuner_addr = ADDR_UNSET, 1455 .tuner_addr = ADDR_UNSET,
1564 .radio_addr = ADDR_UNSET,
1565 .pll = PLL_28, 1456 .pll = PLL_28,
1566 .muxsel = { 2 }, 1457 .muxsel = MUXSEL(2),
1567 .gpiomask = 0 1458 .gpiomask = 0
1568 }, 1459 },
1569 [BTTV_BOARD_PV_BT878P_PLUS] = { 1460 [BTTV_BOARD_PV_BT878P_PLUS] = {
1570 /* Tomasz Pyra <hellfire@sedez.iq.pl> */ 1461 /* Tomasz Pyra <hellfire@sedez.iq.pl> */
1571 .name = "Prolink Pixelview PV-BT878P+ (Rev.4C,8E)", 1462 .name = "Prolink Pixelview PV-BT878P+ (Rev.4C,8E)",
1572 .video_inputs = 3, 1463 .video_inputs = 3,
1573 .audio_inputs = 4, 1464 /* .audio_inputs= 4, */
1574 .tuner = 0,
1575 .svhs = 2, 1465 .svhs = 2,
1576 .gpiomask = 15, 1466 .gpiomask = 15,
1577 .muxsel = { 2, 3, 1, 1 }, 1467 .muxsel = MUXSEL(2, 3, 1, 1),
1578 .gpiomux = { 0, 0, 11, 7 }, /* TV and Radio with same GPIO ! */ 1468 .gpiomux = { 0, 0, 11, 7 }, /* TV and Radio with same GPIO ! */
1579 .gpiomute = 13, 1469 .gpiomute = 13,
1580 .needs_tvaudio = 1, 1470 .needs_tvaudio = 1,
1581 .pll = PLL_28, 1471 .pll = PLL_28,
1582 .tuner_type = TUNER_LG_PAL_I_FM, 1472 .tuner_type = TUNER_LG_PAL_I_FM,
1583 .tuner_addr = ADDR_UNSET, 1473 .tuner_addr = ADDR_UNSET,
1584 .radio_addr = ADDR_UNSET,
1585 .has_remote = 1, 1474 .has_remote = 1,
1586 /* GPIO wiring: 1475 /* GPIO wiring:
1587 GPIO0: U4.A0 (hef4052bt) 1476 GPIO0: U4.A0 (hef4052bt)
@@ -1594,15 +1483,14 @@ struct tvcard bttv_tvcards[] = {
1594 [BTTV_BOARD_FLYVIDEO98EZ] = { 1483 [BTTV_BOARD_FLYVIDEO98EZ] = {
1595 .name = "Lifeview FlyVideo 98EZ (capture only) LR51", 1484 .name = "Lifeview FlyVideo 98EZ (capture only) LR51",
1596 .video_inputs = 4, 1485 .video_inputs = 4,
1597 .audio_inputs = 0, 1486 /* .audio_inputs= 0, */
1598 .tuner = UNSET,
1599 .svhs = 2, 1487 .svhs = 2,
1600 .muxsel = { 2, 3, 1, 1 }, /* AV1, AV2, SVHS, CVid adapter on SVHS */ 1488 /* AV1, AV2, SVHS, CVid adapter on SVHS */
1489 .muxsel = MUXSEL(2, 3, 1, 1),
1601 .pll = PLL_28, 1490 .pll = PLL_28,
1602 .no_msp34xx = 1, 1491 .no_msp34xx = 1,
1603 .tuner_type = UNSET, 1492 .tuner_type = TUNER_ABSENT,
1604 .tuner_addr = ADDR_UNSET, 1493 .tuner_addr = ADDR_UNSET,
1605 .radio_addr = ADDR_UNSET,
1606 }, 1494 },
1607 1495
1608 /* ---- card 0x48 ---------------------------------- */ 1496 /* ---- card 0x48 ---------------------------------- */
@@ -1610,11 +1498,10 @@ struct tvcard bttv_tvcards[] = {
1610 /* Dariusz Kowalewski <darekk@automex.pl> */ 1498 /* Dariusz Kowalewski <darekk@automex.pl> */
1611 .name = "Prolink Pixelview PV-BT878P+9B (PlayTV Pro rev.9B FM+NICAM)", 1499 .name = "Prolink Pixelview PV-BT878P+9B (PlayTV Pro rev.9B FM+NICAM)",
1612 .video_inputs = 4, 1500 .video_inputs = 4,
1613 .audio_inputs = 1, 1501 /* .audio_inputs= 1, */
1614 .tuner = 0,
1615 .svhs = 2, 1502 .svhs = 2,
1616 .gpiomask = 0x3f, 1503 .gpiomask = 0x3f,
1617 .muxsel = { 2, 3, 1, 1 }, 1504 .muxsel = MUXSEL(2, 3, 1, 1),
1618 .gpiomux = { 0x01, 0x00, 0x03, 0x03 }, 1505 .gpiomux = { 0x01, 0x00, 0x03, 0x03 },
1619 .gpiomute = 0x09, 1506 .gpiomute = 0x09,
1620 .needs_tvaudio = 1, 1507 .needs_tvaudio = 1,
@@ -1623,7 +1510,6 @@ struct tvcard bttv_tvcards[] = {
1623 .pll = PLL_28, 1510 .pll = PLL_28,
1624 .tuner_type = TUNER_PHILIPS_PAL, 1511 .tuner_type = TUNER_PHILIPS_PAL,
1625 .tuner_addr = ADDR_UNSET, 1512 .tuner_addr = ADDR_UNSET,
1626 .radio_addr = ADDR_UNSET,
1627 .audio_mode_gpio= pvbt878p9b_audio, /* Note: not all cards have stereo */ 1513 .audio_mode_gpio= pvbt878p9b_audio, /* Note: not all cards have stereo */
1628 .has_radio = 1, /* Note: not all cards have radio */ 1514 .has_radio = 1, /* Note: not all cards have radio */
1629 .has_remote = 1, 1515 .has_remote = 1,
@@ -1640,49 +1526,42 @@ struct tvcard bttv_tvcards[] = {
1640 /* you must jumper JP5 for the card to work */ 1526 /* you must jumper JP5 for the card to work */
1641 .name = "Sensoray 311", 1527 .name = "Sensoray 311",
1642 .video_inputs = 5, 1528 .video_inputs = 5,
1643 .audio_inputs = 0, 1529 /* .audio_inputs= 0, */
1644 .tuner = UNSET,
1645 .svhs = 4, 1530 .svhs = 4,
1646 .gpiomask = 0, 1531 .gpiomask = 0,
1647 .muxsel = { 2, 3, 1, 0, 0 }, 1532 .muxsel = MUXSEL(2, 3, 1, 0, 0),
1648 .gpiomux = { 0 }, 1533 .gpiomux = { 0 },
1649 .needs_tvaudio = 0, 1534 .needs_tvaudio = 0,
1650 .tuner_type = UNSET, 1535 .tuner_type = TUNER_ABSENT,
1651 .tuner_addr = ADDR_UNSET, 1536 .tuner_addr = ADDR_UNSET,
1652 .radio_addr = ADDR_UNSET,
1653 }, 1537 },
1654 [BTTV_BOARD_RV605] = { 1538 [BTTV_BOARD_RV605] = {
1655 /* Miguel Freitas <miguel@cetuc.puc-rio.br> */ 1539 /* Miguel Freitas <miguel@cetuc.puc-rio.br> */
1656 .name = "RemoteVision MX (RV605)", 1540 .name = "RemoteVision MX (RV605)",
1657 .video_inputs = 16, 1541 .video_inputs = 16,
1658 .audio_inputs = 0, 1542 /* .audio_inputs= 0, */
1659 .tuner = UNSET, 1543 .svhs = NO_SVHS,
1660 .svhs = UNSET,
1661 .gpiomask = 0x00, 1544 .gpiomask = 0x00,
1662 .gpiomask2 = 0x07ff, 1545 .gpiomask2 = 0x07ff,
1663 .muxsel = { 0x33, 0x13, 0x23, 0x43, 0xf3, 0x73, 0xe3, 0x03, 1546 .muxsel = MUXSEL(3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3),
1664 0xd3, 0xb3, 0xc3, 0x63, 0x93, 0x53, 0x83, 0xa3 },
1665 .no_msp34xx = 1, 1547 .no_msp34xx = 1,
1666 .no_tda9875 = 1, 1548 .no_tda9875 = 1,
1667 .tuner_type = UNSET, 1549 .tuner_type = TUNER_ABSENT,
1668 .tuner_addr = ADDR_UNSET, 1550 .tuner_addr = ADDR_UNSET,
1669 .radio_addr = ADDR_UNSET,
1670 .muxsel_hook = rv605_muxsel, 1551 .muxsel_hook = rv605_muxsel,
1671 }, 1552 },
1672 [BTTV_BOARD_POWERCLR_MTV878] = { 1553 [BTTV_BOARD_POWERCLR_MTV878] = {
1673 .name = "Powercolor MTV878/ MTV878R/ MTV878F", 1554 .name = "Powercolor MTV878/ MTV878R/ MTV878F",
1674 .video_inputs = 3, 1555 .video_inputs = 3,
1675 .audio_inputs = 2, 1556 /* .audio_inputs= 2, */
1676 .tuner = 0,
1677 .svhs = 2, 1557 .svhs = 2,
1678 .gpiomask = 0x1C800F, /* Bit0-2: Audio select, 8-12:remote control 14:remote valid 15:remote reset */ 1558 .gpiomask = 0x1C800F, /* Bit0-2: Audio select, 8-12:remote control 14:remote valid 15:remote reset */
1679 .muxsel = { 2, 1, 1, }, 1559 .muxsel = MUXSEL(2, 1, 1),
1680 .gpiomux = { 0, 1, 2, 2 }, 1560 .gpiomux = { 0, 1, 2, 2 },
1681 .gpiomute = 4, 1561 .gpiomute = 4,
1682 .needs_tvaudio = 0, 1562 .needs_tvaudio = 0,
1683 .tuner_type = TUNER_PHILIPS_PAL, 1563 .tuner_type = TUNER_PHILIPS_PAL,
1684 .tuner_addr = ADDR_UNSET, 1564 .tuner_addr = ADDR_UNSET,
1685 .radio_addr = ADDR_UNSET,
1686 .pll = PLL_28, 1565 .pll = PLL_28,
1687 .has_radio = 1, 1566 .has_radio = 1,
1688 }, 1567 },
@@ -1692,42 +1571,38 @@ struct tvcard bttv_tvcards[] = {
1692 /* Masaki Suzuki <masaki@btree.org> */ 1571 /* Masaki Suzuki <masaki@btree.org> */
1693 .name = "Canopus WinDVR PCI (COMPAQ Presario 3524JP, 5112JP)", 1572 .name = "Canopus WinDVR PCI (COMPAQ Presario 3524JP, 5112JP)",
1694 .video_inputs = 3, 1573 .video_inputs = 3,
1695 .audio_inputs = 1, 1574 /* .audio_inputs= 1, */
1696 .tuner = 0,
1697 .svhs = 2, 1575 .svhs = 2,
1698 .gpiomask = 0x140007, 1576 .gpiomask = 0x140007,
1699 .muxsel = { 2, 3, 1, 1 }, 1577 .muxsel = MUXSEL(2, 3, 1, 1),
1700 .gpiomux = { 0, 1, 2, 3 }, 1578 .gpiomux = { 0, 1, 2, 3 },
1701 .gpiomute = 4, 1579 .gpiomute = 4,
1702 .tuner_type = TUNER_PHILIPS_NTSC, 1580 .tuner_type = TUNER_PHILIPS_NTSC,
1703 .tuner_addr = ADDR_UNSET, 1581 .tuner_addr = ADDR_UNSET,
1704 .radio_addr = ADDR_UNSET,
1705 .audio_mode_gpio= windvr_audio, 1582 .audio_mode_gpio= windvr_audio,
1706 }, 1583 },
1707 [BTTV_BOARD_GRANDTEC_MULTI] = { 1584 [BTTV_BOARD_GRANDTEC_MULTI] = {
1708 .name = "GrandTec Multi Capture Card (Bt878)", 1585 .name = "GrandTec Multi Capture Card (Bt878)",
1709 .video_inputs = 4, 1586 .video_inputs = 4,
1710 .audio_inputs = 0, 1587 /* .audio_inputs= 0, */
1711 .tuner = UNSET, 1588 .svhs = NO_SVHS,
1712 .svhs = UNSET,
1713 .gpiomask = 0, 1589 .gpiomask = 0,
1714 .muxsel = { 2, 3, 1, 0 }, 1590 .muxsel = MUXSEL(2, 3, 1, 0),
1715 .gpiomux = { 0 }, 1591 .gpiomux = { 0 },
1716 .needs_tvaudio = 0, 1592 .needs_tvaudio = 0,
1717 .no_msp34xx = 1, 1593 .no_msp34xx = 1,
1718 .pll = PLL_28, 1594 .pll = PLL_28,
1719 .tuner_type = UNSET, 1595 .tuner_type = TUNER_ABSENT,
1720 .tuner_addr = ADDR_UNSET, 1596 .tuner_addr = ADDR_UNSET,
1721 .radio_addr = ADDR_UNSET,
1722 }, 1597 },
1723 [BTTV_BOARD_KWORLD] = { 1598 [BTTV_BOARD_KWORLD] = {
1724 .name = "Jetway TV/Capture JW-TV878-FBK, Kworld KW-TV878RF", 1599 .name = "Jetway TV/Capture JW-TV878-FBK, Kworld KW-TV878RF",
1725 .video_inputs = 4, 1600 .video_inputs = 4,
1726 .audio_inputs = 3, 1601 /* .audio_inputs= 3, */
1727 .tuner = 0,
1728 .svhs = 2, 1602 .svhs = 2,
1729 .gpiomask = 7, 1603 .gpiomask = 7,
1730 .muxsel = { 2, 3, 1, 1 }, /* Tuner, SVid, SVHS, SVid to SVHS connector */ 1604 /* Tuner, SVid, SVHS, SVid to SVHS connector */
1605 .muxsel = MUXSEL(2, 3, 1, 1),
1731 .gpiomux = { 0, 0, 4, 4 },/* Yes, this tuner uses the same audio output for TV and FM radio! 1606 .gpiomux = { 0, 0, 4, 4 },/* Yes, this tuner uses the same audio output for TV and FM radio!
1732 * This card lacks external Audio In, so we mute it on Ext. & Int. 1607 * This card lacks external Audio In, so we mute it on Ext. & Int.
1733 * The PCB can take a sbx1637/sbx1673, wiring unknown. 1608 * The PCB can take a sbx1637/sbx1673, wiring unknown.
@@ -1741,7 +1616,6 @@ struct tvcard bttv_tvcards[] = {
1741 .pll = PLL_28, 1616 .pll = PLL_28,
1742 .tuner_type = TUNER_PHILIPS_PAL, 1617 .tuner_type = TUNER_PHILIPS_PAL,
1743 .tuner_addr = ADDR_UNSET, 1618 .tuner_addr = ADDR_UNSET,
1744 .radio_addr = ADDR_UNSET,
1745 /* Samsung TCPA9095PC27A (BG+DK), philips compatible, w/FM, stereo and 1619 /* Samsung TCPA9095PC27A (BG+DK), philips compatible, w/FM, stereo and
1746 radio signal strength indicators work fine. */ 1620 radio signal strength indicators work fine. */
1747 .has_radio = 1, 1621 .has_radio = 1,
@@ -1759,27 +1633,24 @@ struct tvcard bttv_tvcards[] = {
1759 /* Arthur Tetzlaff-Deas, DSP Design Ltd <software@dspdesign.com> */ 1633 /* Arthur Tetzlaff-Deas, DSP Design Ltd <software@dspdesign.com> */
1760 .name = "DSP Design TCVIDEO", 1634 .name = "DSP Design TCVIDEO",
1761 .video_inputs = 4, 1635 .video_inputs = 4,
1762 .svhs = UNSET, 1636 .svhs = NO_SVHS,
1763 .muxsel = { 2, 3, 1, 0 }, 1637 .muxsel = MUXSEL(2, 3, 1, 0),
1764 .pll = PLL_28, 1638 .pll = PLL_28,
1765 .tuner_type = UNSET, 1639 .tuner_type = UNSET,
1766 .tuner_addr = ADDR_UNSET, 1640 .tuner_addr = ADDR_UNSET,
1767 .radio_addr = ADDR_UNSET,
1768 }, 1641 },
1769 1642
1770 /* ---- card 0x50 ---------------------------------- */ 1643 /* ---- card 0x50 ---------------------------------- */
1771 [BTTV_BOARD_HAUPPAUGEPVR] = { 1644 [BTTV_BOARD_HAUPPAUGEPVR] = {
1772 .name = "Hauppauge WinTV PVR", 1645 .name = "Hauppauge WinTV PVR",
1773 .video_inputs = 4, 1646 .video_inputs = 4,
1774 .audio_inputs = 1, 1647 /* .audio_inputs= 1, */
1775 .tuner = 0,
1776 .svhs = 2, 1648 .svhs = 2,
1777 .muxsel = { 2, 0, 1, 1 }, 1649 .muxsel = MUXSEL(2, 0, 1, 1),
1778 .needs_tvaudio = 1, 1650 .needs_tvaudio = 1,
1779 .pll = PLL_28, 1651 .pll = PLL_28,
1780 .tuner_type = UNSET, 1652 .tuner_type = UNSET,
1781 .tuner_addr = ADDR_UNSET, 1653 .tuner_addr = ADDR_UNSET,
1782 .radio_addr = ADDR_UNSET,
1783 1654
1784 .gpiomask = 7, 1655 .gpiomask = 7,
1785 .gpiomux = {7}, 1656 .gpiomux = {7},
@@ -1787,32 +1658,28 @@ struct tvcard bttv_tvcards[] = {
1787 [BTTV_BOARD_GVBCTV5PCI] = { 1658 [BTTV_BOARD_GVBCTV5PCI] = {
1788 .name = "IODATA GV-BCTV5/PCI", 1659 .name = "IODATA GV-BCTV5/PCI",
1789 .video_inputs = 3, 1660 .video_inputs = 3,
1790 .audio_inputs = 1, 1661 /* .audio_inputs= 1, */
1791 .tuner = 0,
1792 .svhs = 2, 1662 .svhs = 2,
1793 .gpiomask = 0x0f0f80, 1663 .gpiomask = 0x0f0f80,
1794 .muxsel = {2, 3, 1, 0 }, 1664 .muxsel = MUXSEL(2, 3, 1, 0),
1795 .gpiomux = {0x030000, 0x010000, 0, 0 }, 1665 .gpiomux = {0x030000, 0x010000, 0, 0 },
1796 .gpiomute = 0x020000, 1666 .gpiomute = 0x020000,
1797 .no_msp34xx = 1, 1667 .no_msp34xx = 1,
1798 .pll = PLL_28, 1668 .pll = PLL_28,
1799 .tuner_type = TUNER_PHILIPS_NTSC_M, 1669 .tuner_type = TUNER_PHILIPS_NTSC_M,
1800 .tuner_addr = ADDR_UNSET, 1670 .tuner_addr = ADDR_UNSET,
1801 .radio_addr = ADDR_UNSET,
1802 .audio_mode_gpio= gvbctv5pci_audio, 1671 .audio_mode_gpio= gvbctv5pci_audio,
1803 .has_radio = 1, 1672 .has_radio = 1,
1804 }, 1673 },
1805 [BTTV_BOARD_OSPREY1x0] = { 1674 [BTTV_BOARD_OSPREY1x0] = {
1806 .name = "Osprey 100/150 (878)", /* 0x1(2|3)-45C6-C1 */ 1675 .name = "Osprey 100/150 (878)", /* 0x1(2|3)-45C6-C1 */
1807 .video_inputs = 4, /* id-inputs-clock */ 1676 .video_inputs = 4, /* id-inputs-clock */
1808 .audio_inputs = 0, 1677 /* .audio_inputs= 0, */
1809 .tuner = UNSET,
1810 .svhs = 3, 1678 .svhs = 3,
1811 .muxsel = { 3, 2, 0, 1 }, 1679 .muxsel = MUXSEL(3, 2, 0, 1),
1812 .pll = PLL_28, 1680 .pll = PLL_28,
1813 .tuner_type = UNSET, 1681 .tuner_type = TUNER_ABSENT,
1814 .tuner_addr = ADDR_UNSET, 1682 .tuner_addr = ADDR_UNSET,
1815 .radio_addr = ADDR_UNSET,
1816 .no_msp34xx = 1, 1683 .no_msp34xx = 1,
1817 .no_tda9875 = 1, 1684 .no_tda9875 = 1,
1818 .no_tda7432 = 1, 1685 .no_tda7432 = 1,
@@ -1820,14 +1687,12 @@ struct tvcard bttv_tvcards[] = {
1820 [BTTV_BOARD_OSPREY1x0_848] = { 1687 [BTTV_BOARD_OSPREY1x0_848] = {
1821 .name = "Osprey 100/150 (848)", /* 0x04-54C0-C1 & older boards */ 1688 .name = "Osprey 100/150 (848)", /* 0x04-54C0-C1 & older boards */
1822 .video_inputs = 3, 1689 .video_inputs = 3,
1823 .audio_inputs = 0, 1690 /* .audio_inputs= 0, */
1824 .tuner = UNSET,
1825 .svhs = 2, 1691 .svhs = 2,
1826 .muxsel = { 2, 3, 1 }, 1692 .muxsel = MUXSEL(2, 3, 1),
1827 .pll = PLL_28, 1693 .pll = PLL_28,
1828 .tuner_type = UNSET, 1694 .tuner_type = TUNER_ABSENT,
1829 .tuner_addr = ADDR_UNSET, 1695 .tuner_addr = ADDR_UNSET,
1830 .radio_addr = ADDR_UNSET,
1831 .no_msp34xx = 1, 1696 .no_msp34xx = 1,
1832 .no_tda9875 = 1, 1697 .no_tda9875 = 1,
1833 .no_tda7432 = 1, 1698 .no_tda7432 = 1,
@@ -1837,14 +1702,12 @@ struct tvcard bttv_tvcards[] = {
1837 [BTTV_BOARD_OSPREY101_848] = { 1702 [BTTV_BOARD_OSPREY101_848] = {
1838 .name = "Osprey 101 (848)", /* 0x05-40C0-C1 */ 1703 .name = "Osprey 101 (848)", /* 0x05-40C0-C1 */
1839 .video_inputs = 2, 1704 .video_inputs = 2,
1840 .audio_inputs = 0, 1705 /* .audio_inputs= 0, */
1841 .tuner = UNSET,
1842 .svhs = 1, 1706 .svhs = 1,
1843 .muxsel = { 3, 1 }, 1707 .muxsel = MUXSEL(3, 1),
1844 .pll = PLL_28, 1708 .pll = PLL_28,
1845 .tuner_type = UNSET, 1709 .tuner_type = TUNER_ABSENT,
1846 .tuner_addr = ADDR_UNSET, 1710 .tuner_addr = ADDR_UNSET,
1847 .radio_addr = ADDR_UNSET,
1848 .no_msp34xx = 1, 1711 .no_msp34xx = 1,
1849 .no_tda9875 = 1, 1712 .no_tda9875 = 1,
1850 .no_tda7432 = 1, 1713 .no_tda7432 = 1,
@@ -1852,14 +1715,12 @@ struct tvcard bttv_tvcards[] = {
1852 [BTTV_BOARD_OSPREY1x1] = { 1715 [BTTV_BOARD_OSPREY1x1] = {
1853 .name = "Osprey 101/151", /* 0x1(4|5)-0004-C4 */ 1716 .name = "Osprey 101/151", /* 0x1(4|5)-0004-C4 */
1854 .video_inputs = 1, 1717 .video_inputs = 1,
1855 .audio_inputs = 0, 1718 /* .audio_inputs= 0, */
1856 .tuner = UNSET, 1719 .svhs = NO_SVHS,
1857 .svhs = UNSET, 1720 .muxsel = MUXSEL(0),
1858 .muxsel = { 0 },
1859 .pll = PLL_28, 1721 .pll = PLL_28,
1860 .tuner_type = UNSET, 1722 .tuner_type = TUNER_ABSENT,
1861 .tuner_addr = ADDR_UNSET, 1723 .tuner_addr = ADDR_UNSET,
1862 .radio_addr = ADDR_UNSET,
1863 .no_msp34xx = 1, 1724 .no_msp34xx = 1,
1864 .no_tda9875 = 1, 1725 .no_tda9875 = 1,
1865 .no_tda7432 = 1, 1726 .no_tda7432 = 1,
@@ -1867,14 +1728,12 @@ struct tvcard bttv_tvcards[] = {
1867 [BTTV_BOARD_OSPREY1x1_SVID] = { 1728 [BTTV_BOARD_OSPREY1x1_SVID] = {
1868 .name = "Osprey 101/151 w/ svid", /* 0x(16|17|20)-00C4-C1 */ 1729 .name = "Osprey 101/151 w/ svid", /* 0x(16|17|20)-00C4-C1 */
1869 .video_inputs = 2, 1730 .video_inputs = 2,
1870 .audio_inputs = 0, 1731 /* .audio_inputs= 0, */
1871 .tuner = UNSET,
1872 .svhs = 1, 1732 .svhs = 1,
1873 .muxsel = { 0, 1 }, 1733 .muxsel = MUXSEL(0, 1),
1874 .pll = PLL_28, 1734 .pll = PLL_28,
1875 .tuner_type = UNSET, 1735 .tuner_type = TUNER_ABSENT,
1876 .tuner_addr = ADDR_UNSET, 1736 .tuner_addr = ADDR_UNSET,
1877 .radio_addr = ADDR_UNSET,
1878 .no_msp34xx = 1, 1737 .no_msp34xx = 1,
1879 .no_tda9875 = 1, 1738 .no_tda9875 = 1,
1880 .no_tda7432 = 1, 1739 .no_tda7432 = 1,
@@ -1882,14 +1741,12 @@ struct tvcard bttv_tvcards[] = {
1882 [BTTV_BOARD_OSPREY2xx] = { 1741 [BTTV_BOARD_OSPREY2xx] = {
1883 .name = "Osprey 200/201/250/251", /* 0x1(8|9|E|F)-0004-C4 */ 1742 .name = "Osprey 200/201/250/251", /* 0x1(8|9|E|F)-0004-C4 */
1884 .video_inputs = 1, 1743 .video_inputs = 1,
1885 .audio_inputs = 1, 1744 /* .audio_inputs= 1, */
1886 .tuner = UNSET, 1745 .svhs = NO_SVHS,
1887 .svhs = UNSET, 1746 .muxsel = MUXSEL(0),
1888 .muxsel = { 0 },
1889 .pll = PLL_28, 1747 .pll = PLL_28,
1890 .tuner_type = UNSET, 1748 .tuner_type = TUNER_ABSENT,
1891 .tuner_addr = ADDR_UNSET, 1749 .tuner_addr = ADDR_UNSET,
1892 .radio_addr = ADDR_UNSET,
1893 .no_msp34xx = 1, 1750 .no_msp34xx = 1,
1894 .no_tda9875 = 1, 1751 .no_tda9875 = 1,
1895 .no_tda7432 = 1, 1752 .no_tda7432 = 1,
@@ -1899,14 +1756,12 @@ struct tvcard bttv_tvcards[] = {
1899 [BTTV_BOARD_OSPREY2x0_SVID] = { 1756 [BTTV_BOARD_OSPREY2x0_SVID] = {
1900 .name = "Osprey 200/250", /* 0x1(A|B)-00C4-C1 */ 1757 .name = "Osprey 200/250", /* 0x1(A|B)-00C4-C1 */
1901 .video_inputs = 2, 1758 .video_inputs = 2,
1902 .audio_inputs = 1, 1759 /* .audio_inputs= 1, */
1903 .tuner = UNSET,
1904 .svhs = 1, 1760 .svhs = 1,
1905 .muxsel = { 0, 1 }, 1761 .muxsel = MUXSEL(0, 1),
1906 .pll = PLL_28, 1762 .pll = PLL_28,
1907 .tuner_type = UNSET, 1763 .tuner_type = TUNER_ABSENT,
1908 .tuner_addr = ADDR_UNSET, 1764 .tuner_addr = ADDR_UNSET,
1909 .radio_addr = ADDR_UNSET,
1910 .no_msp34xx = 1, 1765 .no_msp34xx = 1,
1911 .no_tda9875 = 1, 1766 .no_tda9875 = 1,
1912 .no_tda7432 = 1, 1767 .no_tda7432 = 1,
@@ -1914,14 +1769,12 @@ struct tvcard bttv_tvcards[] = {
1914 [BTTV_BOARD_OSPREY2x0] = { 1769 [BTTV_BOARD_OSPREY2x0] = {
1915 .name = "Osprey 210/220/230", /* 0x1(A|B)-04C0-C1 */ 1770 .name = "Osprey 210/220/230", /* 0x1(A|B)-04C0-C1 */
1916 .video_inputs = 2, 1771 .video_inputs = 2,
1917 .audio_inputs = 1, 1772 /* .audio_inputs= 1, */
1918 .tuner = UNSET,
1919 .svhs = 1, 1773 .svhs = 1,
1920 .muxsel = { 2, 3 }, 1774 .muxsel = MUXSEL(2, 3),
1921 .pll = PLL_28, 1775 .pll = PLL_28,
1922 .tuner_type = UNSET, 1776 .tuner_type = TUNER_ABSENT,
1923 .tuner_addr = ADDR_UNSET, 1777 .tuner_addr = ADDR_UNSET,
1924 .radio_addr = ADDR_UNSET,
1925 .no_msp34xx = 1, 1778 .no_msp34xx = 1,
1926 .no_tda9875 = 1, 1779 .no_tda9875 = 1,
1927 .no_tda7432 = 1, 1780 .no_tda7432 = 1,
@@ -1929,14 +1782,12 @@ struct tvcard bttv_tvcards[] = {
1929 [BTTV_BOARD_OSPREY500] = { 1782 [BTTV_BOARD_OSPREY500] = {
1930 .name = "Osprey 500", /* 500 */ 1783 .name = "Osprey 500", /* 500 */
1931 .video_inputs = 2, 1784 .video_inputs = 2,
1932 .audio_inputs = 1, 1785 /* .audio_inputs= 1, */
1933 .tuner = UNSET,
1934 .svhs = 1, 1786 .svhs = 1,
1935 .muxsel = { 2, 3 }, 1787 .muxsel = MUXSEL(2, 3),
1936 .pll = PLL_28, 1788 .pll = PLL_28,
1937 .tuner_type = UNSET, 1789 .tuner_type = TUNER_ABSENT,
1938 .tuner_addr = ADDR_UNSET, 1790 .tuner_addr = ADDR_UNSET,
1939 .radio_addr = ADDR_UNSET,
1940 .no_msp34xx = 1, 1791 .no_msp34xx = 1,
1941 .no_tda9875 = 1, 1792 .no_tda9875 = 1,
1942 .no_tda7432 = 1, 1793 .no_tda7432 = 1,
@@ -1944,12 +1795,10 @@ struct tvcard bttv_tvcards[] = {
1944 [BTTV_BOARD_OSPREY540] = { 1795 [BTTV_BOARD_OSPREY540] = {
1945 .name = "Osprey 540", /* 540 */ 1796 .name = "Osprey 540", /* 540 */
1946 .video_inputs = 4, 1797 .video_inputs = 4,
1947 .audio_inputs = 1, 1798 /* .audio_inputs= 1, */
1948 .tuner = UNSET,
1949 .pll = PLL_28, 1799 .pll = PLL_28,
1950 .tuner_type = UNSET, 1800 .tuner_type = TUNER_ABSENT,
1951 .tuner_addr = ADDR_UNSET, 1801 .tuner_addr = ADDR_UNSET,
1952 .radio_addr = ADDR_UNSET,
1953 .no_msp34xx = 1, 1802 .no_msp34xx = 1,
1954 .no_tda9875 = 1, 1803 .no_tda9875 = 1,
1955 .no_tda7432 = 1, 1804 .no_tda7432 = 1,
@@ -1959,14 +1808,12 @@ struct tvcard bttv_tvcards[] = {
1959 [BTTV_BOARD_OSPREY2000] = { 1808 [BTTV_BOARD_OSPREY2000] = {
1960 .name = "Osprey 2000", /* 2000 */ 1809 .name = "Osprey 2000", /* 2000 */
1961 .video_inputs = 2, 1810 .video_inputs = 2,
1962 .audio_inputs = 1, 1811 /* .audio_inputs= 1, */
1963 .tuner = UNSET,
1964 .svhs = 1, 1812 .svhs = 1,
1965 .muxsel = { 2, 3 }, 1813 .muxsel = MUXSEL(2, 3),
1966 .pll = PLL_28, 1814 .pll = PLL_28,
1967 .tuner_type = UNSET, 1815 .tuner_type = TUNER_ABSENT,
1968 .tuner_addr = ADDR_UNSET, 1816 .tuner_addr = ADDR_UNSET,
1969 .radio_addr = ADDR_UNSET,
1970 .no_msp34xx = 1, 1817 .no_msp34xx = 1,
1971 .no_tda9875 = 1, 1818 .no_tda9875 = 1,
1972 .no_tda7432 = 1, /* must avoid, conflicts with the bt860 */ 1819 .no_tda7432 = 1, /* must avoid, conflicts with the bt860 */
@@ -1975,14 +1822,12 @@ struct tvcard bttv_tvcards[] = {
1975 /* M G Berberich <berberic@forwiss.uni-passau.de> */ 1822 /* M G Berberich <berberic@forwiss.uni-passau.de> */
1976 .name = "IDS Eagle", 1823 .name = "IDS Eagle",
1977 .video_inputs = 4, 1824 .video_inputs = 4,
1978 .audio_inputs = 0, 1825 /* .audio_inputs= 0, */
1979 .tuner = UNSET, 1826 .tuner_type = TUNER_ABSENT,
1980 .tuner_type = UNSET,
1981 .tuner_addr = ADDR_UNSET, 1827 .tuner_addr = ADDR_UNSET,
1982 .radio_addr = ADDR_UNSET, 1828 .svhs = NO_SVHS,
1983 .svhs = UNSET,
1984 .gpiomask = 0, 1829 .gpiomask = 0,
1985 .muxsel = { 0, 1, 2, 3 }, 1830 .muxsel = MUXSEL(2, 2, 2, 2),
1986 .muxsel_hook = eagle_muxsel, 1831 .muxsel_hook = eagle_muxsel,
1987 .no_msp34xx = 1, 1832 .no_msp34xx = 1,
1988 .no_tda9875 = 1, 1833 .no_tda9875 = 1,
@@ -1991,16 +1836,14 @@ struct tvcard bttv_tvcards[] = {
1991 [BTTV_BOARD_PINNACLESAT] = { 1836 [BTTV_BOARD_PINNACLESAT] = {
1992 .name = "Pinnacle PCTV Sat", 1837 .name = "Pinnacle PCTV Sat",
1993 .video_inputs = 2, 1838 .video_inputs = 2,
1994 .audio_inputs = 0, 1839 /* .audio_inputs= 0, */
1995 .svhs = 1, 1840 .svhs = 1,
1996 .tuner = UNSET, 1841 .tuner_type = TUNER_ABSENT,
1997 .tuner_type = UNSET,
1998 .tuner_addr = ADDR_UNSET, 1842 .tuner_addr = ADDR_UNSET,
1999 .radio_addr = ADDR_UNSET,
2000 .no_msp34xx = 1, 1843 .no_msp34xx = 1,
2001 .no_tda9875 = 1, 1844 .no_tda9875 = 1,
2002 .no_tda7432 = 1, 1845 .no_tda7432 = 1,
2003 .muxsel = { 3, 1 }, 1846 .muxsel = MUXSEL(3, 1),
2004 .pll = PLL_28, 1847 .pll = PLL_28,
2005 .no_gpioirq = 1, 1848 .no_gpioirq = 1,
2006 .has_dvb = 1, 1849 .has_dvb = 1,
@@ -2008,18 +1851,16 @@ struct tvcard bttv_tvcards[] = {
2008 [BTTV_BOARD_FORMAC_PROTV] = { 1851 [BTTV_BOARD_FORMAC_PROTV] = {
2009 .name = "Formac ProTV II (bt878)", 1852 .name = "Formac ProTV II (bt878)",
2010 .video_inputs = 4, 1853 .video_inputs = 4,
2011 .audio_inputs = 1, 1854 /* .audio_inputs= 1, */
2012 .tuner = 0,
2013 .svhs = 3, 1855 .svhs = 3,
2014 .gpiomask = 2, 1856 .gpiomask = 2,
2015 /* TV, Comp1, Composite over SVID con, SVID */ 1857 /* TV, Comp1, Composite over SVID con, SVID */
2016 .muxsel = { 2, 3, 1, 1 }, 1858 .muxsel = MUXSEL(2, 3, 1, 1),
2017 .gpiomux = { 2, 2, 0, 0 }, 1859 .gpiomux = { 2, 2, 0, 0 },
2018 .pll = PLL_28, 1860 .pll = PLL_28,
2019 .has_radio = 1, 1861 .has_radio = 1,
2020 .tuner_type = TUNER_PHILIPS_PAL, 1862 .tuner_type = TUNER_PHILIPS_PAL,
2021 .tuner_addr = ADDR_UNSET, 1863 .tuner_addr = ADDR_UNSET,
2022 .radio_addr = ADDR_UNSET,
2023 /* sound routing: 1864 /* sound routing:
2024 GPIO=0x00,0x01,0x03: mute (?) 1865 GPIO=0x00,0x01,0x03: mute (?)
2025 0x02: both TV and radio (tuner: FM1216/I) 1866 0x02: both TV and radio (tuner: FM1216/I)
@@ -2033,62 +1874,55 @@ struct tvcard bttv_tvcards[] = {
2033 [BTTV_BOARD_MACHTV] = { 1874 [BTTV_BOARD_MACHTV] = {
2034 .name = "MachTV", 1875 .name = "MachTV",
2035 .video_inputs = 3, 1876 .video_inputs = 3,
2036 .audio_inputs = 1, 1877 /* .audio_inputs= 1, */
2037 .tuner = 0, 1878 .svhs = NO_SVHS,
2038 .svhs = UNSET,
2039 .gpiomask = 7, 1879 .gpiomask = 7,
2040 .muxsel = { 2, 3, 1, 1}, 1880 .muxsel = MUXSEL(2, 3, 1, 1),
2041 .gpiomux = { 0, 1, 2, 3}, 1881 .gpiomux = { 0, 1, 2, 3},
2042 .gpiomute = 4, 1882 .gpiomute = 4,
2043 .needs_tvaudio = 1, 1883 .needs_tvaudio = 1,
2044 .tuner_type = TUNER_PHILIPS_PAL, 1884 .tuner_type = TUNER_PHILIPS_PAL,
2045 .tuner_addr = ADDR_UNSET, 1885 .tuner_addr = ADDR_UNSET,
2046 .radio_addr = ADDR_UNSET,
2047 .pll = PLL_28, 1886 .pll = PLL_28,
2048 }, 1887 },
2049 [BTTV_BOARD_EURESYS_PICOLO] = { 1888 [BTTV_BOARD_EURESYS_PICOLO] = {
2050 .name = "Euresys Picolo", 1889 .name = "Euresys Picolo",
2051 .video_inputs = 3, 1890 .video_inputs = 3,
2052 .audio_inputs = 0, 1891 /* .audio_inputs= 0, */
2053 .tuner = UNSET,
2054 .svhs = 2, 1892 .svhs = 2,
2055 .gpiomask = 0, 1893 .gpiomask = 0,
2056 .no_msp34xx = 1, 1894 .no_msp34xx = 1,
2057 .no_tda9875 = 1, 1895 .no_tda9875 = 1,
2058 .no_tda7432 = 1, 1896 .no_tda7432 = 1,
2059 .muxsel = { 2, 0, 1}, 1897 .muxsel = MUXSEL(2, 0, 1),
2060 .pll = PLL_28, 1898 .pll = PLL_28,
2061 .tuner_type = UNSET, 1899 .tuner_type = TUNER_ABSENT,
2062 .tuner_addr = ADDR_UNSET, 1900 .tuner_addr = ADDR_UNSET,
2063 .radio_addr = ADDR_UNSET,
2064 }, 1901 },
2065 [BTTV_BOARD_PV150] = { 1902 [BTTV_BOARD_PV150] = {
2066 /* Luc Van Hoeylandt <luc@e-magic.be> */ 1903 /* Luc Van Hoeylandt <luc@e-magic.be> */
2067 .name = "ProVideo PV150", /* 0x4f */ 1904 .name = "ProVideo PV150", /* 0x4f */
2068 .video_inputs = 2, 1905 .video_inputs = 2,
2069 .audio_inputs = 0, 1906 /* .audio_inputs= 0, */
2070 .tuner = UNSET, 1907 .svhs = NO_SVHS,
2071 .svhs = UNSET,
2072 .gpiomask = 0, 1908 .gpiomask = 0,
2073 .muxsel = { 2, 3 }, 1909 .muxsel = MUXSEL(2, 3),
2074 .gpiomux = { 0 }, 1910 .gpiomux = { 0 },
2075 .needs_tvaudio = 0, 1911 .needs_tvaudio = 0,
2076 .no_msp34xx = 1, 1912 .no_msp34xx = 1,
2077 .pll = PLL_28, 1913 .pll = PLL_28,
2078 .tuner_type = UNSET, 1914 .tuner_type = TUNER_ABSENT,
2079 .tuner_addr = ADDR_UNSET, 1915 .tuner_addr = ADDR_UNSET,
2080 .radio_addr = ADDR_UNSET,
2081 }, 1916 },
2082 [BTTV_BOARD_AD_TVK503] = { 1917 [BTTV_BOARD_AD_TVK503] = {
2083 /* Hiroshi Takekawa <sian@big.or.jp> */ 1918 /* Hiroshi Takekawa <sian@big.or.jp> */
2084 /* This card lacks subsystem ID */ 1919 /* This card lacks subsystem ID */
2085 .name = "AD-TVK503", /* 0x63 */ 1920 .name = "AD-TVK503", /* 0x63 */
2086 .video_inputs = 4, 1921 .video_inputs = 4,
2087 .audio_inputs = 1, 1922 /* .audio_inputs= 1, */
2088 .tuner = 0,
2089 .svhs = 2, 1923 .svhs = 2,
2090 .gpiomask = 0x001e8007, 1924 .gpiomask = 0x001e8007,
2091 .muxsel = { 2, 3, 1, 0 }, 1925 .muxsel = MUXSEL(2, 3, 1, 0),
2092 /* Tuner, Radio, external, internal, off, on */ 1926 /* Tuner, Radio, external, internal, off, on */
2093 .gpiomux = { 0x08, 0x0f, 0x0a, 0x08 }, 1927 .gpiomux = { 0x08, 0x0f, 0x0a, 0x08 },
2094 .gpiomute = 0x0f, 1928 .gpiomute = 0x0f,
@@ -2097,7 +1931,6 @@ struct tvcard bttv_tvcards[] = {
2097 .pll = PLL_28, 1931 .pll = PLL_28,
2098 .tuner_type = TUNER_PHILIPS_NTSC, 1932 .tuner_type = TUNER_PHILIPS_NTSC,
2099 .tuner_addr = ADDR_UNSET, 1933 .tuner_addr = ADDR_UNSET,
2100 .radio_addr = ADDR_UNSET,
2101 .audio_mode_gpio= adtvk503_audio, 1934 .audio_mode_gpio= adtvk503_audio,
2102 }, 1935 },
2103 1936
@@ -2105,17 +1938,15 @@ struct tvcard bttv_tvcards[] = {
2105 [BTTV_BOARD_HERCULES_SM_TV] = { 1938 [BTTV_BOARD_HERCULES_SM_TV] = {
2106 .name = "Hercules Smart TV Stereo", 1939 .name = "Hercules Smart TV Stereo",
2107 .video_inputs = 4, 1940 .video_inputs = 4,
2108 .audio_inputs = 1, 1941 /* .audio_inputs= 1, */
2109 .tuner = 0,
2110 .svhs = 2, 1942 .svhs = 2,
2111 .gpiomask = 0x00, 1943 .gpiomask = 0x00,
2112 .muxsel = { 2, 3, 1, 1 }, 1944 .muxsel = MUXSEL(2, 3, 1, 1),
2113 .needs_tvaudio = 1, 1945 .needs_tvaudio = 1,
2114 .no_msp34xx = 1, 1946 .no_msp34xx = 1,
2115 .pll = PLL_28, 1947 .pll = PLL_28,
2116 .tuner_type = TUNER_PHILIPS_PAL, 1948 .tuner_type = TUNER_PHILIPS_PAL,
2117 .tuner_addr = ADDR_UNSET, 1949 .tuner_addr = ADDR_UNSET,
2118 .radio_addr = ADDR_UNSET,
2119 /* Notes: 1950 /* Notes:
2120 - card lacks subsystem ID 1951 - card lacks subsystem ID
2121 - stereo variant w/ daughter board with tda9874a @0xb0 1952 - stereo variant w/ daughter board with tda9874a @0xb0
@@ -2129,16 +1960,15 @@ struct tvcard bttv_tvcards[] = {
2129 [BTTV_BOARD_PACETV] = { 1960 [BTTV_BOARD_PACETV] = {
2130 .name = "Pace TV & Radio Card", 1961 .name = "Pace TV & Radio Card",
2131 .video_inputs = 4, 1962 .video_inputs = 4,
2132 .audio_inputs = 1, 1963 /* .audio_inputs= 1, */
2133 .tuner = 0,
2134 .svhs = 2, 1964 .svhs = 2,
2135 .muxsel = { 2, 3, 1, 1 }, /* Tuner, CVid, SVid, CVid over SVid connector */ 1965 /* Tuner, CVid, SVid, CVid over SVid connector */
1966 .muxsel = MUXSEL(2, 3, 1, 1),
2136 .gpiomask = 0, 1967 .gpiomask = 0,
2137 .no_tda9875 = 1, 1968 .no_tda9875 = 1,
2138 .no_tda7432 = 1, 1969 .no_tda7432 = 1,
2139 .tuner_type = TUNER_PHILIPS_PAL_I, 1970 .tuner_type = TUNER_PHILIPS_PAL_I,
2140 .tuner_addr = ADDR_UNSET, 1971 .tuner_addr = ADDR_UNSET,
2141 .radio_addr = ADDR_UNSET,
2142 .has_radio = 1, 1972 .has_radio = 1,
2143 .pll = PLL_28, 1973 .pll = PLL_28,
2144 /* Bt878, Bt832, FI1246 tuner; no pci subsystem id 1974 /* Bt878, Bt832, FI1246 tuner; no pci subsystem id
@@ -2152,27 +1982,34 @@ struct tvcard bttv_tvcards[] = {
2152 /* Chris Willing <chris@vislab.usyd.edu.au> */ 1982 /* Chris Willing <chris@vislab.usyd.edu.au> */
2153 .name = "IVC-200", 1983 .name = "IVC-200",
2154 .video_inputs = 1, 1984 .video_inputs = 1,
2155 .audio_inputs = 0, 1985 /* .audio_inputs= 0, */
2156 .tuner = UNSET, 1986 .tuner_type = TUNER_ABSENT,
2157 .tuner_type = UNSET,
2158 .tuner_addr = ADDR_UNSET, 1987 .tuner_addr = ADDR_UNSET,
2159 .radio_addr = ADDR_UNSET, 1988 .svhs = NO_SVHS,
2160 .svhs = UNSET, 1989 .gpiomask = 0xdf,
1990 .muxsel = MUXSEL(2),
1991 .pll = PLL_28,
1992 },
1993 [BTTV_BOARD_IVCE8784] = {
1994 .name = "IVCE-8784",
1995 .video_inputs = 1,
1996 /* .audio_inputs= 0, */
1997 .tuner_type = TUNER_ABSENT,
1998 .tuner_addr = ADDR_UNSET,
1999 .svhs = NO_SVHS,
2161 .gpiomask = 0xdf, 2000 .gpiomask = 0xdf,
2162 .muxsel = { 2 }, 2001 .muxsel = MUXSEL(2),
2163 .pll = PLL_28, 2002 .pll = PLL_28,
2164 }, 2003 },
2165 [BTTV_BOARD_XGUARD] = { 2004 [BTTV_BOARD_XGUARD] = {
2166 .name = "Grand X-Guard / Trust 814PCI", 2005 .name = "Grand X-Guard / Trust 814PCI",
2167 .video_inputs = 16, 2006 .video_inputs = 16,
2168 .audio_inputs = 0, 2007 /* .audio_inputs= 0, */
2169 .tuner = UNSET, 2008 .svhs = NO_SVHS,
2170 .svhs = UNSET,
2171 .tuner_type = TUNER_ABSENT, 2009 .tuner_type = TUNER_ABSENT,
2172 .tuner_addr = ADDR_UNSET, 2010 .tuner_addr = ADDR_UNSET,
2173 .radio_addr = ADDR_UNSET,
2174 .gpiomask2 = 0xff, 2011 .gpiomask2 = 0xff,
2175 .muxsel = { 2,2,2,2, 3,3,3,3, 1,1,1,1, 0,0,0,0 }, 2012 .muxsel = MUXSEL(2,2,2,2, 3,3,3,3, 1,1,1,1, 0,0,0,0),
2176 .muxsel_hook = xguard_muxsel, 2013 .muxsel_hook = xguard_muxsel,
2177 .no_msp34xx = 1, 2014 .no_msp34xx = 1,
2178 .no_tda9875 = 1, 2015 .no_tda9875 = 1,
@@ -2184,16 +2021,14 @@ struct tvcard bttv_tvcards[] = {
2184 [BTTV_BOARD_NEBULA_DIGITV] = { 2021 [BTTV_BOARD_NEBULA_DIGITV] = {
2185 .name = "Nebula Electronics DigiTV", 2022 .name = "Nebula Electronics DigiTV",
2186 .video_inputs = 1, 2023 .video_inputs = 1,
2187 .tuner = UNSET, 2024 .svhs = NO_SVHS,
2188 .svhs = UNSET, 2025 .muxsel = MUXSEL(2, 3, 1, 0),
2189 .muxsel = { 2, 3, 1, 0 },
2190 .no_msp34xx = 1, 2026 .no_msp34xx = 1,
2191 .no_tda9875 = 1, 2027 .no_tda9875 = 1,
2192 .no_tda7432 = 1, 2028 .no_tda7432 = 1,
2193 .pll = PLL_28, 2029 .pll = PLL_28,
2194 .tuner_type = UNSET, 2030 .tuner_type = TUNER_ABSENT,
2195 .tuner_addr = ADDR_UNSET, 2031 .tuner_addr = ADDR_UNSET,
2196 .radio_addr = ADDR_UNSET,
2197 .has_dvb = 1, 2032 .has_dvb = 1,
2198 .has_remote = 1, 2033 .has_remote = 1,
2199 .gpiomask = 0x1b, 2034 .gpiomask = 0x1b,
@@ -2203,118 +2038,101 @@ struct tvcard bttv_tvcards[] = {
2203 /* Jorge Boncompte - DTI2 <jorge@dti2.net> */ 2038 /* Jorge Boncompte - DTI2 <jorge@dti2.net> */
2204 .name = "ProVideo PV143", 2039 .name = "ProVideo PV143",
2205 .video_inputs = 4, 2040 .video_inputs = 4,
2206 .audio_inputs = 0, 2041 /* .audio_inputs= 0, */
2207 .tuner = UNSET, 2042 .svhs = NO_SVHS,
2208 .svhs = UNSET,
2209 .gpiomask = 0, 2043 .gpiomask = 0,
2210 .muxsel = { 2, 3, 1, 0 }, 2044 .muxsel = MUXSEL(2, 3, 1, 0),
2211 .gpiomux = { 0 }, 2045 .gpiomux = { 0 },
2212 .needs_tvaudio = 0, 2046 .needs_tvaudio = 0,
2213 .no_msp34xx = 1, 2047 .no_msp34xx = 1,
2214 .pll = PLL_28, 2048 .pll = PLL_28,
2215 .tuner_type = UNSET, 2049 .tuner_type = TUNER_ABSENT,
2216 .tuner_addr = ADDR_UNSET, 2050 .tuner_addr = ADDR_UNSET,
2217 .radio_addr = ADDR_UNSET,
2218 }, 2051 },
2219 [BTTV_BOARD_VD009X1_VD011_MINIDIN] = { 2052 [BTTV_BOARD_VD009X1_VD011_MINIDIN] = {
2220 /* M.Klahr@phytec.de */ 2053 /* M.Klahr@phytec.de */
2221 .name = "PHYTEC VD-009-X1 VD-011 MiniDIN (bt878)", 2054 .name = "PHYTEC VD-009-X1 VD-011 MiniDIN (bt878)",
2222 .video_inputs = 4, 2055 .video_inputs = 4,
2223 .audio_inputs = 0, 2056 /* .audio_inputs= 0, */
2224 .tuner = UNSET, /* card has no tuner */
2225 .svhs = 3, 2057 .svhs = 3,
2226 .gpiomask = 0x00, 2058 .gpiomask = 0x00,
2227 .muxsel = { 2, 3, 1, 0 }, 2059 .muxsel = MUXSEL(2, 3, 1, 0),
2228 .gpiomux = { 0, 0, 0, 0 }, /* card has no audio */ 2060 .gpiomux = { 0, 0, 0, 0 }, /* card has no audio */
2229 .needs_tvaudio = 0, 2061 .needs_tvaudio = 0,
2230 .pll = PLL_28, 2062 .pll = PLL_28,
2231 .tuner_type = UNSET, 2063 .tuner_type = TUNER_ABSENT,
2232 .tuner_addr = ADDR_UNSET, 2064 .tuner_addr = ADDR_UNSET,
2233 .radio_addr = ADDR_UNSET,
2234 }, 2065 },
2235 [BTTV_BOARD_VD009X1_VD011_COMBI] = { 2066 [BTTV_BOARD_VD009X1_VD011_COMBI] = {
2236 .name = "PHYTEC VD-009-X1 VD-011 Combi (bt878)", 2067 .name = "PHYTEC VD-009-X1 VD-011 Combi (bt878)",
2237 .video_inputs = 4, 2068 .video_inputs = 4,
2238 .audio_inputs = 0, 2069 /* .audio_inputs= 0, */
2239 .tuner = UNSET, /* card has no tuner */
2240 .svhs = 3, 2070 .svhs = 3,
2241 .gpiomask = 0x00, 2071 .gpiomask = 0x00,
2242 .muxsel = { 2, 3, 1, 1 }, 2072 .muxsel = MUXSEL(2, 3, 1, 1),
2243 .gpiomux = { 0, 0, 0, 0 }, /* card has no audio */ 2073 .gpiomux = { 0, 0, 0, 0 }, /* card has no audio */
2244 .needs_tvaudio = 0, 2074 .needs_tvaudio = 0,
2245 .pll = PLL_28, 2075 .pll = PLL_28,
2246 .tuner_type = UNSET, 2076 .tuner_type = TUNER_ABSENT,
2247 .tuner_addr = ADDR_UNSET, 2077 .tuner_addr = ADDR_UNSET,
2248 .radio_addr = ADDR_UNSET,
2249 }, 2078 },
2250 2079
2251 /* ---- card 0x6c ---------------------------------- */ 2080 /* ---- card 0x6c ---------------------------------- */
2252 [BTTV_BOARD_VD009_MINIDIN] = { 2081 [BTTV_BOARD_VD009_MINIDIN] = {
2253 .name = "PHYTEC VD-009 MiniDIN (bt878)", 2082 .name = "PHYTEC VD-009 MiniDIN (bt878)",
2254 .video_inputs = 10, 2083 .video_inputs = 10,
2255 .audio_inputs = 0, 2084 /* .audio_inputs= 0, */
2256 .tuner = UNSET, /* card has no tuner */
2257 .svhs = 9, 2085 .svhs = 9,
2258 .gpiomask = 0x00, 2086 .gpiomask = 0x00,
2259 .gpiomask2 = 0x03, /* gpiomask2 defines the bits used to switch audio 2087 .gpiomask2 = 0x03, /* used for external vodeo mux */
2260 via the upper nibble of muxsel. here: used for 2088 .muxsel = MUXSEL(2, 2, 2, 2, 3, 3, 3, 3, 1, 0),
2261 xternal video-mux */ 2089 .muxsel_hook = phytec_muxsel,
2262 .muxsel = { 0x02, 0x12, 0x22, 0x32, 0x03, 0x13, 0x23, 0x33, 0x01, 0x00 },
2263 .gpiomux = { 0, 0, 0, 0 }, /* card has no audio */ 2090 .gpiomux = { 0, 0, 0, 0 }, /* card has no audio */
2264 .needs_tvaudio = 1, 2091 .needs_tvaudio = 1,
2265 .pll = PLL_28, 2092 .pll = PLL_28,
2266 .tuner_type = UNSET, 2093 .tuner_type = TUNER_ABSENT,
2267 .tuner_addr = ADDR_UNSET, 2094 .tuner_addr = ADDR_UNSET,
2268 .radio_addr = ADDR_UNSET,
2269 }, 2095 },
2270 [BTTV_BOARD_VD009_COMBI] = { 2096 [BTTV_BOARD_VD009_COMBI] = {
2271 .name = "PHYTEC VD-009 Combi (bt878)", 2097 .name = "PHYTEC VD-009 Combi (bt878)",
2272 .video_inputs = 10, 2098 .video_inputs = 10,
2273 .audio_inputs = 0, 2099 /* .audio_inputs= 0, */
2274 .tuner = UNSET, /* card has no tuner */
2275 .svhs = 9, 2100 .svhs = 9,
2276 .gpiomask = 0x00, 2101 .gpiomask = 0x00,
2277 .gpiomask2 = 0x03, /* gpiomask2 defines the bits used to switch audio 2102 .gpiomask2 = 0x03, /* used for external vodeo mux */
2278 via the upper nibble of muxsel. here: used for 2103 .muxsel = MUXSEL(2, 2, 2, 2, 3, 3, 3, 3, 1, 1),
2279 xternal video-mux */ 2104 .muxsel_hook = phytec_muxsel,
2280 .muxsel = { 0x02, 0x12, 0x22, 0x32, 0x03, 0x13, 0x23, 0x33, 0x01, 0x01 },
2281 .gpiomux = { 0, 0, 0, 0 }, /* card has no audio */ 2105 .gpiomux = { 0, 0, 0, 0 }, /* card has no audio */
2282 .needs_tvaudio = 1, 2106 .needs_tvaudio = 1,
2283 .pll = PLL_28, 2107 .pll = PLL_28,
2284 .tuner_type = UNSET, 2108 .tuner_type = TUNER_ABSENT,
2285 .tuner_addr = ADDR_UNSET, 2109 .tuner_addr = ADDR_UNSET,
2286 .radio_addr = ADDR_UNSET,
2287 }, 2110 },
2288 [BTTV_BOARD_IVC100] = { 2111 [BTTV_BOARD_IVC100] = {
2289 .name = "IVC-100", 2112 .name = "IVC-100",
2290 .video_inputs = 4, 2113 .video_inputs = 4,
2291 .audio_inputs = 0, 2114 /* .audio_inputs= 0, */
2292 .tuner = UNSET, 2115 .tuner_type = TUNER_ABSENT,
2293 .tuner_type = UNSET,
2294 .tuner_addr = ADDR_UNSET, 2116 .tuner_addr = ADDR_UNSET,
2295 .radio_addr = ADDR_UNSET, 2117 .svhs = NO_SVHS,
2296 .svhs = UNSET,
2297 .gpiomask = 0xdf, 2118 .gpiomask = 0xdf,
2298 .muxsel = { 2, 3, 1, 0 }, 2119 .muxsel = MUXSEL(2, 3, 1, 0),
2299 .pll = PLL_28, 2120 .pll = PLL_28,
2300 }, 2121 },
2301 [BTTV_BOARD_IVC120] = { 2122 [BTTV_BOARD_IVC120] = {
2302 /* IVC-120G - Alan Garfield <alan@fromorbit.com> */ 2123 /* IVC-120G - Alan Garfield <alan@fromorbit.com> */
2303 .name = "IVC-120G", 2124 .name = "IVC-120G",
2304 .video_inputs = 16, 2125 .video_inputs = 16,
2305 .audio_inputs = 0, /* card has no audio */ 2126 /* .audio_inputs= 0, */
2306 .tuner = UNSET, /* card has no tuner */ 2127 .tuner_type = TUNER_ABSENT,
2307 .tuner_type = UNSET,
2308 .tuner_addr = ADDR_UNSET, 2128 .tuner_addr = ADDR_UNSET,
2309 .radio_addr = ADDR_UNSET, 2129 .svhs = NO_SVHS, /* card has no svhs */
2310 .svhs = UNSET, /* card has no svhs */
2311 .needs_tvaudio = 0, 2130 .needs_tvaudio = 0,
2312 .no_msp34xx = 1, 2131 .no_msp34xx = 1,
2313 .no_tda9875 = 1, 2132 .no_tda9875 = 1,
2314 .no_tda7432 = 1, 2133 .no_tda7432 = 1,
2315 .gpiomask = 0x00, 2134 .gpiomask = 0x00,
2316 .muxsel = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 2135 .muxsel = MUXSEL(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
2317 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10 },
2318 .muxsel_hook = ivc120_muxsel, 2136 .muxsel_hook = ivc120_muxsel,
2319 .pll = PLL_28, 2137 .pll = PLL_28,
2320 }, 2138 },
@@ -2323,13 +2141,11 @@ struct tvcard bttv_tvcards[] = {
2323 [BTTV_BOARD_PC_HDTV] = { 2141 [BTTV_BOARD_PC_HDTV] = {
2324 .name = "pcHDTV HD-2000 TV", 2142 .name = "pcHDTV HD-2000 TV",
2325 .video_inputs = 4, 2143 .video_inputs = 4,
2326 .audio_inputs = 1, 2144 /* .audio_inputs= 1, */
2327 .tuner = 0,
2328 .svhs = 2, 2145 .svhs = 2,
2329 .muxsel = { 2, 3, 1, 0 }, 2146 .muxsel = MUXSEL(2, 3, 1, 0),
2330 .tuner_type = TUNER_PHILIPS_FCV1236D, 2147 .tuner_type = TUNER_PHILIPS_FCV1236D,
2331 .tuner_addr = ADDR_UNSET, 2148 .tuner_addr = ADDR_UNSET,
2332 .radio_addr = ADDR_UNSET,
2333 .has_dvb = 1, 2149 .has_dvb = 1,
2334 }, 2150 },
2335 [BTTV_BOARD_TWINHAN_DST] = { 2151 [BTTV_BOARD_TWINHAN_DST] = {
@@ -2339,38 +2155,34 @@ struct tvcard bttv_tvcards[] = {
2339 .no_tda7432 = 1, 2155 .no_tda7432 = 1,
2340 .tuner_type = TUNER_ABSENT, 2156 .tuner_type = TUNER_ABSENT,
2341 .tuner_addr = ADDR_UNSET, 2157 .tuner_addr = ADDR_UNSET,
2342 .radio_addr = ADDR_UNSET,
2343 .no_video = 1, 2158 .no_video = 1,
2344 .has_dvb = 1, 2159 .has_dvb = 1,
2345 }, 2160 },
2346 [BTTV_BOARD_WINFASTVC100] = { 2161 [BTTV_BOARD_WINFASTVC100] = {
2347 .name = "Winfast VC100", 2162 .name = "Winfast VC100",
2348 .video_inputs = 3, 2163 .video_inputs = 3,
2349 .audio_inputs = 0, 2164 /* .audio_inputs= 0, */
2350 .svhs = 1, 2165 .svhs = 1,
2351 .tuner = UNSET, 2166 /* Vid In, SVid In, Vid over SVid in connector */
2352 .muxsel = { 3, 1, 1, 3 }, /* Vid In, SVid In, Vid over SVid in connector */ 2167 .muxsel = MUXSEL(3, 1, 1, 3),
2353 .no_msp34xx = 1, 2168 .no_msp34xx = 1,
2354 .no_tda9875 = 1, 2169 .no_tda9875 = 1,
2355 .no_tda7432 = 1, 2170 .no_tda7432 = 1,
2356 .tuner_type = TUNER_ABSENT, 2171 .tuner_type = TUNER_ABSENT,
2357 .tuner_addr = ADDR_UNSET, 2172 .tuner_addr = ADDR_UNSET,
2358 .radio_addr = ADDR_UNSET,
2359 .pll = PLL_28, 2173 .pll = PLL_28,
2360 }, 2174 },
2361 [BTTV_BOARD_TEV560] = { 2175 [BTTV_BOARD_TEV560] = {
2362 .name = "Teppro TEV-560/InterVision IV-560", 2176 .name = "Teppro TEV-560/InterVision IV-560",
2363 .video_inputs = 3, 2177 .video_inputs = 3,
2364 .audio_inputs = 1, 2178 /* .audio_inputs= 1, */
2365 .tuner = 0,
2366 .svhs = 2, 2179 .svhs = 2,
2367 .gpiomask = 3, 2180 .gpiomask = 3,
2368 .muxsel = { 2, 3, 1, 1 }, 2181 .muxsel = MUXSEL(2, 3, 1, 1),
2369 .gpiomux = { 1, 1, 1, 1 }, 2182 .gpiomux = { 1, 1, 1, 1 },
2370 .needs_tvaudio = 1, 2183 .needs_tvaudio = 1,
2371 .tuner_type = TUNER_PHILIPS_PAL, 2184 .tuner_type = TUNER_PHILIPS_PAL,
2372 .tuner_addr = ADDR_UNSET, 2185 .tuner_addr = ADDR_UNSET,
2373 .radio_addr = ADDR_UNSET,
2374 .pll = PLL_35, 2186 .pll = PLL_35,
2375 }, 2187 },
2376 2188
@@ -2378,14 +2190,12 @@ struct tvcard bttv_tvcards[] = {
2378 [BTTV_BOARD_SIMUS_GVC1100] = { 2190 [BTTV_BOARD_SIMUS_GVC1100] = {
2379 .name = "SIMUS GVC1100", 2191 .name = "SIMUS GVC1100",
2380 .video_inputs = 4, 2192 .video_inputs = 4,
2381 .audio_inputs = 0, 2193 /* .audio_inputs= 0, */
2382 .tuner = UNSET, 2194 .svhs = NO_SVHS,
2383 .svhs = UNSET, 2195 .tuner_type = TUNER_ABSENT,
2384 .tuner_type = UNSET,
2385 .tuner_addr = ADDR_UNSET, 2196 .tuner_addr = ADDR_UNSET,
2386 .radio_addr = ADDR_UNSET,
2387 .pll = PLL_28, 2197 .pll = PLL_28,
2388 .muxsel = { 2, 2, 2, 2 }, 2198 .muxsel = MUXSEL(2, 2, 2, 2),
2389 .gpiomask = 0x3F, 2199 .gpiomask = 0x3F,
2390 .muxsel_hook = gvc1100_muxsel, 2200 .muxsel_hook = gvc1100_muxsel,
2391 }, 2201 },
@@ -2393,47 +2203,41 @@ struct tvcard bttv_tvcards[] = {
2393 /* Carlos Silva r3pek@r3pek.homelinux.org || card 0x75 */ 2203 /* Carlos Silva r3pek@r3pek.homelinux.org || card 0x75 */
2394 .name = "NGS NGSTV+", 2204 .name = "NGS NGSTV+",
2395 .video_inputs = 3, 2205 .video_inputs = 3,
2396 .tuner = 0,
2397 .svhs = 2, 2206 .svhs = 2,
2398 .gpiomask = 0x008007, 2207 .gpiomask = 0x008007,
2399 .muxsel = { 2, 3, 0, 0 }, 2208 .muxsel = MUXSEL(2, 3, 0, 0),
2400 .gpiomux = { 0, 0, 0, 0 }, 2209 .gpiomux = { 0, 0, 0, 0 },
2401 .gpiomute = 0x000003, 2210 .gpiomute = 0x000003,
2402 .pll = PLL_28, 2211 .pll = PLL_28,
2403 .tuner_type = TUNER_PHILIPS_PAL, 2212 .tuner_type = TUNER_PHILIPS_PAL,
2404 .tuner_addr = ADDR_UNSET, 2213 .tuner_addr = ADDR_UNSET,
2405 .radio_addr = ADDR_UNSET,
2406 .has_remote = 1, 2214 .has_remote = 1,
2407 }, 2215 },
2408 [BTTV_BOARD_LMLBT4] = { 2216 [BTTV_BOARD_LMLBT4] = {
2409 /* http://linuxmedialabs.com */ 2217 /* http://linuxmedialabs.com */
2410 .name = "LMLBT4", 2218 .name = "LMLBT4",
2411 .video_inputs = 4, /* IN1,IN2,IN3,IN4 */ 2219 .video_inputs = 4, /* IN1,IN2,IN3,IN4 */
2412 .audio_inputs = 0, 2220 /* .audio_inputs= 0, */
2413 .tuner = UNSET, 2221 .svhs = NO_SVHS,
2414 .svhs = UNSET, 2222 .muxsel = MUXSEL(2, 3, 1, 0),
2415 .muxsel = { 2, 3, 1, 0 },
2416 .no_msp34xx = 1, 2223 .no_msp34xx = 1,
2417 .no_tda9875 = 1, 2224 .no_tda9875 = 1,
2418 .no_tda7432 = 1, 2225 .no_tda7432 = 1,
2419 .needs_tvaudio = 0, 2226 .needs_tvaudio = 0,
2420 .tuner_type = UNSET, 2227 .tuner_type = TUNER_ABSENT,
2421 .tuner_addr = ADDR_UNSET, 2228 .tuner_addr = ADDR_UNSET,
2422 .radio_addr = ADDR_UNSET,
2423 }, 2229 },
2424 [BTTV_BOARD_TEKRAM_M205] = { 2230 [BTTV_BOARD_TEKRAM_M205] = {
2425 /* Helmroos Harri <harri.helmroos@pp.inet.fi> */ 2231 /* Helmroos Harri <harri.helmroos@pp.inet.fi> */
2426 .name = "Tekram M205 PRO", 2232 .name = "Tekram M205 PRO",
2427 .video_inputs = 3, 2233 .video_inputs = 3,
2428 .audio_inputs = 1, 2234 /* .audio_inputs= 1, */
2429 .tuner = 0,
2430 .tuner_type = TUNER_PHILIPS_PAL, 2235 .tuner_type = TUNER_PHILIPS_PAL,
2431 .tuner_addr = ADDR_UNSET, 2236 .tuner_addr = ADDR_UNSET,
2432 .radio_addr = ADDR_UNSET,
2433 .svhs = 2, 2237 .svhs = 2,
2434 .needs_tvaudio = 0, 2238 .needs_tvaudio = 0,
2435 .gpiomask = 0x68, 2239 .gpiomask = 0x68,
2436 .muxsel = { 2, 3, 1 }, 2240 .muxsel = MUXSEL(2, 3, 1),
2437 .gpiomux = { 0x68, 0x68, 0x61, 0x61 }, 2241 .gpiomux = { 0x68, 0x68, 0x61, 0x61 },
2438 .pll = PLL_28, 2242 .pll = PLL_28,
2439 }, 2243 },
@@ -2444,18 +2248,16 @@ struct tvcard bttv_tvcards[] = {
2444 /* bt878 TV + FM without subsystem ID */ 2248 /* bt878 TV + FM without subsystem ID */
2445 .name = "Conceptronic CONTVFMi", 2249 .name = "Conceptronic CONTVFMi",
2446 .video_inputs = 3, 2250 .video_inputs = 3,
2447 .audio_inputs = 1, 2251 /* .audio_inputs= 1, */
2448 .tuner = 0,
2449 .svhs = 2, 2252 .svhs = 2,
2450 .gpiomask = 0x008007, 2253 .gpiomask = 0x008007,
2451 .muxsel = { 2, 3, 1, 1 }, 2254 .muxsel = MUXSEL(2, 3, 1, 1),
2452 .gpiomux = { 0, 1, 2, 2 }, 2255 .gpiomux = { 0, 1, 2, 2 },
2453 .gpiomute = 3, 2256 .gpiomute = 3,
2454 .needs_tvaudio = 0, 2257 .needs_tvaudio = 0,
2455 .pll = PLL_28, 2258 .pll = PLL_28,
2456 .tuner_type = TUNER_PHILIPS_PAL, 2259 .tuner_type = TUNER_PHILIPS_PAL,
2457 .tuner_addr = ADDR_UNSET, 2260 .tuner_addr = ADDR_UNSET,
2458 .radio_addr = ADDR_UNSET,
2459 .has_remote = 1, 2261 .has_remote = 1,
2460 .has_radio = 1, 2262 .has_radio = 1,
2461 }, 2263 },
@@ -2466,37 +2268,34 @@ struct tvcard bttv_tvcards[] = {
2466 /*0x79 in bttv.h*/ 2268 /*0x79 in bttv.h*/
2467 .name = "Euresys Picolo Tetra", 2269 .name = "Euresys Picolo Tetra",
2468 .video_inputs = 4, 2270 .video_inputs = 4,
2469 .audio_inputs = 0, 2271 /* .audio_inputs= 0, */
2470 .tuner = UNSET, 2272 .svhs = NO_SVHS,
2471 .svhs = UNSET,
2472 .gpiomask = 0, 2273 .gpiomask = 0,
2473 .gpiomask2 = 0x3C<<16,/*Set the GPIO[18]->GPIO[21] as output pin.==> drive the video inputs through analog multiplexers*/ 2274 .gpiomask2 = 0x3C<<16,/*Set the GPIO[18]->GPIO[21] as output pin.==> drive the video inputs through analog multiplexers*/
2474 .no_msp34xx = 1, 2275 .no_msp34xx = 1,
2475 .no_tda9875 = 1, 2276 .no_tda9875 = 1,
2476 .no_tda7432 = 1, 2277 .no_tda7432 = 1,
2477 .muxsel = {2,2,2,2},/*878A input is always MUX0, see above.*/ 2278 /*878A input is always MUX0, see above.*/
2279 .muxsel = MUXSEL(2, 2, 2, 2),
2478 .gpiomux = { 0, 0, 0, 0 }, /* card has no audio */ 2280 .gpiomux = { 0, 0, 0, 0 }, /* card has no audio */
2479 .pll = PLL_28, 2281 .pll = PLL_28,
2480 .needs_tvaudio = 0, 2282 .needs_tvaudio = 0,
2481 .muxsel_hook = picolo_tetra_muxsel,/*Required as it doesn't follow the classic input selection policy*/ 2283 .muxsel_hook = picolo_tetra_muxsel,/*Required as it doesn't follow the classic input selection policy*/
2482 .tuner_type = UNSET, 2284 .tuner_type = TUNER_ABSENT,
2483 .tuner_addr = ADDR_UNSET, 2285 .tuner_addr = ADDR_UNSET,
2484 .radio_addr = ADDR_UNSET,
2485 }, 2286 },
2486 [BTTV_BOARD_SPIRIT_TV] = { 2287 [BTTV_BOARD_SPIRIT_TV] = {
2487 /* Spirit TV Tuner from http://spiritmodems.com.au */ 2288 /* Spirit TV Tuner from http://spiritmodems.com.au */
2488 /* Stafford Goodsell <surge@goliath.homeunix.org> */ 2289 /* Stafford Goodsell <surge@goliath.homeunix.org> */
2489 .name = "Spirit TV Tuner", 2290 .name = "Spirit TV Tuner",
2490 .video_inputs = 3, 2291 .video_inputs = 3,
2491 .audio_inputs = 1, 2292 /* .audio_inputs= 1, */
2492 .tuner = 0,
2493 .svhs = 2, 2293 .svhs = 2,
2494 .gpiomask = 0x0000000f, 2294 .gpiomask = 0x0000000f,
2495 .muxsel = { 2, 1, 1 }, 2295 .muxsel = MUXSEL(2, 1, 1),
2496 .gpiomux = { 0x02, 0x00, 0x00, 0x00 }, 2296 .gpiomux = { 0x02, 0x00, 0x00, 0x00 },
2497 .tuner_type = TUNER_TEMIC_PAL, 2297 .tuner_type = TUNER_TEMIC_PAL,
2498 .tuner_addr = ADDR_UNSET, 2298 .tuner_addr = ADDR_UNSET,
2499 .radio_addr = ADDR_UNSET,
2500 .no_msp34xx = 1, 2299 .no_msp34xx = 1,
2501 .no_tda9875 = 1, 2300 .no_tda9875 = 1,
2502 }, 2301 },
@@ -2505,11 +2304,9 @@ struct tvcard bttv_tvcards[] = {
2505 .name = "AVerMedia AVerTV DVB-T 771", 2304 .name = "AVerMedia AVerTV DVB-T 771",
2506 .video_inputs = 2, 2305 .video_inputs = 2,
2507 .svhs = 1, 2306 .svhs = 1,
2508 .tuner = UNSET,
2509 .tuner_type = TUNER_ABSENT, 2307 .tuner_type = TUNER_ABSENT,
2510 .tuner_addr = ADDR_UNSET, 2308 .tuner_addr = ADDR_UNSET,
2511 .radio_addr = ADDR_UNSET, 2309 .muxsel = MUXSEL(3, 3),
2512 .muxsel = { 3 , 3 },
2513 .no_msp34xx = 1, 2310 .no_msp34xx = 1,
2514 .no_tda9875 = 1, 2311 .no_tda9875 = 1,
2515 .no_tda7432 = 1, 2312 .no_tda7432 = 1,
@@ -2524,54 +2321,47 @@ struct tvcard bttv_tvcards[] = {
2524 /* Based on the Nebula card data - added remote and new card number - BTTV_BOARD_AVDVBT_761, see also ir-kbd-gpio.c */ 2321 /* Based on the Nebula card data - added remote and new card number - BTTV_BOARD_AVDVBT_761, see also ir-kbd-gpio.c */
2525 .name = "AverMedia AverTV DVB-T 761", 2322 .name = "AverMedia AverTV DVB-T 761",
2526 .video_inputs = 2, 2323 .video_inputs = 2,
2527 .tuner = UNSET,
2528 .svhs = 1, 2324 .svhs = 1,
2529 .muxsel = { 3, 1, 2, 0 }, /* Comp0, S-Video, ?, ? */ 2325 .muxsel = MUXSEL(3, 1, 2, 0), /* Comp0, S-Video, ?, ? */
2530 .no_msp34xx = 1, 2326 .no_msp34xx = 1,
2531 .no_tda9875 = 1, 2327 .no_tda9875 = 1,
2532 .no_tda7432 = 1, 2328 .no_tda7432 = 1,
2533 .pll = PLL_28, 2329 .pll = PLL_28,
2534 .tuner_type = UNSET, 2330 .tuner_type = TUNER_ABSENT,
2535 .tuner_addr = ADDR_UNSET, 2331 .tuner_addr = ADDR_UNSET,
2536 .radio_addr = ADDR_UNSET,
2537 .has_dvb = 1, 2332 .has_dvb = 1,
2538 .no_gpioirq = 1, 2333 .no_gpioirq = 1,
2539 .has_remote = 1, 2334 .has_remote = 1,
2540 }, 2335 },
2541 [BTTV_BOARD_MATRIX_VISIONSQ] = { 2336 [BTTV_BOARD_MATRIX_VISIONSQ] = {
2542 /* andre.schwarz@matrix-vision.de */ 2337 /* andre.schwarz@matrix-vision.de */
2543 .name = "MATRIX Vision Sigma-SQ", 2338 .name = "MATRIX Vision Sigma-SQ",
2544 .video_inputs = 16, 2339 .video_inputs = 16,
2545 .audio_inputs = 0, 2340 /* .audio_inputs= 0, */
2546 .tuner = UNSET, 2341 .svhs = NO_SVHS,
2547 .svhs = UNSET, 2342 .gpiomask = 0x0,
2548 .gpiomask = 0x0, 2343 .muxsel = MUXSEL(2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3),
2549 .muxsel = { 2, 2, 2, 2, 2, 2, 2, 2, 2344 .muxsel_hook = sigmaSQ_muxsel,
2550 3, 3, 3, 3, 3, 3, 3, 3 }, 2345 .gpiomux = { 0 },
2551 .muxsel_hook = sigmaSQ_muxsel, 2346 .no_msp34xx = 1,
2552 .gpiomux = { 0 }, 2347 .pll = PLL_28,
2553 .no_msp34xx = 1, 2348 .tuner_type = TUNER_ABSENT,
2554 .pll = PLL_28, 2349 .tuner_addr = ADDR_UNSET,
2555 .tuner_type = UNSET,
2556 .tuner_addr = ADDR_UNSET,
2557 .radio_addr = ADDR_UNSET,
2558 }, 2350 },
2559 [BTTV_BOARD_MATRIX_VISIONSLC] = { 2351 [BTTV_BOARD_MATRIX_VISIONSLC] = {
2560 /* andre.schwarz@matrix-vision.de */ 2352 /* andre.schwarz@matrix-vision.de */
2561 .name = "MATRIX Vision Sigma-SLC", 2353 .name = "MATRIX Vision Sigma-SLC",
2562 .video_inputs = 4, 2354 .video_inputs = 4,
2563 .audio_inputs = 0, 2355 /* .audio_inputs= 0, */
2564 .tuner = UNSET, 2356 .svhs = NO_SVHS,
2565 .svhs = UNSET, 2357 .gpiomask = 0x0,
2566 .gpiomask = 0x0, 2358 .muxsel = MUXSEL(2, 2, 2, 2),
2567 .muxsel = { 2, 2, 2, 2 }, 2359 .muxsel_hook = sigmaSLC_muxsel,
2568 .muxsel_hook = sigmaSLC_muxsel, 2360 .gpiomux = { 0 },
2569 .gpiomux = { 0 }, 2361 .no_msp34xx = 1,
2570 .no_msp34xx = 1, 2362 .pll = PLL_28,
2571 .pll = PLL_28, 2363 .tuner_type = TUNER_ABSENT,
2572 .tuner_type = UNSET, 2364 .tuner_addr = ADDR_UNSET,
2573 .tuner_addr = ADDR_UNSET,
2574 .radio_addr = ADDR_UNSET,
2575 }, 2365 },
2576 /* BTTV_BOARD_APAC_VIEWCOMP */ 2366 /* BTTV_BOARD_APAC_VIEWCOMP */
2577 [BTTV_BOARD_APAC_VIEWCOMP] = { 2367 [BTTV_BOARD_APAC_VIEWCOMP] = {
@@ -2579,18 +2369,16 @@ struct tvcard bttv_tvcards[] = {
2579 /* bt878 TV + FM 0x00000000 subsystem ID */ 2369 /* bt878 TV + FM 0x00000000 subsystem ID */
2580 .name = "APAC Viewcomp 878(AMAX)", 2370 .name = "APAC Viewcomp 878(AMAX)",
2581 .video_inputs = 2, 2371 .video_inputs = 2,
2582 .audio_inputs = 1, 2372 /* .audio_inputs= 1, */
2583 .tuner = 0, 2373 .svhs = NO_SVHS,
2584 .svhs = UNSET,
2585 .gpiomask = 0xFF, 2374 .gpiomask = 0xFF,
2586 .muxsel = { 2, 3, 1, 1 }, 2375 .muxsel = MUXSEL(2, 3, 1, 1),
2587 .gpiomux = { 2, 0, 0, 0 }, 2376 .gpiomux = { 2, 0, 0, 0 },
2588 .gpiomute = 10, 2377 .gpiomute = 10,
2589 .needs_tvaudio = 0, 2378 .needs_tvaudio = 0,
2590 .pll = PLL_28, 2379 .pll = PLL_28,
2591 .tuner_type = TUNER_PHILIPS_PAL, 2380 .tuner_type = TUNER_PHILIPS_PAL,
2592 .tuner_addr = ADDR_UNSET, 2381 .tuner_addr = ADDR_UNSET,
2593 .radio_addr = ADDR_UNSET,
2594 .has_remote = 1, /* miniremote works, see ir-kbd-gpio.c */ 2382 .has_remote = 1, /* miniremote works, see ir-kbd-gpio.c */
2595 .has_radio = 1, /* not every card has radio */ 2383 .has_radio = 1, /* not every card has radio */
2596 }, 2384 },
@@ -2599,46 +2387,40 @@ struct tvcard bttv_tvcards[] = {
2599 [BTTV_BOARD_DVICO_DVBT_LITE] = { 2387 [BTTV_BOARD_DVICO_DVBT_LITE] = {
2600 /* Chris Pascoe <c.pascoe@itee.uq.edu.au> */ 2388 /* Chris Pascoe <c.pascoe@itee.uq.edu.au> */
2601 .name = "DViCO FusionHDTV DVB-T Lite", 2389 .name = "DViCO FusionHDTV DVB-T Lite",
2602 .tuner = UNSET,
2603 .no_msp34xx = 1, 2390 .no_msp34xx = 1,
2604 .no_tda9875 = 1, 2391 .no_tda9875 = 1,
2605 .no_tda7432 = 1, 2392 .no_tda7432 = 1,
2606 .pll = PLL_28, 2393 .pll = PLL_28,
2607 .no_video = 1, 2394 .no_video = 1,
2608 .has_dvb = 1, 2395 .has_dvb = 1,
2609 .tuner_type = UNSET, 2396 .tuner_type = TUNER_ABSENT,
2610 .tuner_addr = ADDR_UNSET, 2397 .tuner_addr = ADDR_UNSET,
2611 .radio_addr = ADDR_UNSET,
2612 }, 2398 },
2613 [BTTV_BOARD_VGEAR_MYVCD] = { 2399 [BTTV_BOARD_VGEAR_MYVCD] = {
2614 /* Steven <photon38@pchome.com.tw> */ 2400 /* Steven <photon38@pchome.com.tw> */
2615 .name = "V-Gear MyVCD", 2401 .name = "V-Gear MyVCD",
2616 .video_inputs = 3, 2402 .video_inputs = 3,
2617 .audio_inputs = 1, 2403 /* .audio_inputs= 1, */
2618 .tuner = 0,
2619 .svhs = 2, 2404 .svhs = 2,
2620 .gpiomask = 0x3f, 2405 .gpiomask = 0x3f,
2621 .muxsel = {2, 3, 1, 0 }, 2406 .muxsel = MUXSEL(2, 3, 1, 0),
2622 .gpiomux = {0x31, 0x31, 0x31, 0x31 }, 2407 .gpiomux = {0x31, 0x31, 0x31, 0x31 },
2623 .gpiomute = 0x31, 2408 .gpiomute = 0x31,
2624 .no_msp34xx = 1, 2409 .no_msp34xx = 1,
2625 .pll = PLL_28, 2410 .pll = PLL_28,
2626 .tuner_type = TUNER_PHILIPS_NTSC_M, 2411 .tuner_type = TUNER_PHILIPS_NTSC_M,
2627 .tuner_addr = ADDR_UNSET, 2412 .tuner_addr = ADDR_UNSET,
2628 .radio_addr = ADDR_UNSET,
2629 .has_radio = 0, 2413 .has_radio = 0,
2630 }, 2414 },
2631 [BTTV_BOARD_SUPER_TV] = { 2415 [BTTV_BOARD_SUPER_TV] = {
2632 /* Rick C <cryptdragoon@gmail.com> */ 2416 /* Rick C <cryptdragoon@gmail.com> */
2633 .name = "Super TV Tuner", 2417 .name = "Super TV Tuner",
2634 .video_inputs = 4, 2418 .video_inputs = 4,
2635 .audio_inputs = 1, 2419 /* .audio_inputs= 1, */
2636 .tuner = 0,
2637 .svhs = 2, 2420 .svhs = 2,
2638 .muxsel = { 2, 3, 1, 0 }, 2421 .muxsel = MUXSEL(2, 3, 1, 0),
2639 .tuner_type = TUNER_PHILIPS_NTSC, 2422 .tuner_type = TUNER_PHILIPS_NTSC,
2640 .tuner_addr = ADDR_UNSET, 2423 .tuner_addr = ADDR_UNSET,
2641 .radio_addr = ADDR_UNSET,
2642 .gpiomask = 0x008007, 2424 .gpiomask = 0x008007,
2643 .gpiomux = { 0, 0x000001,0,0 }, 2425 .gpiomux = { 0, 0x000001,0,0 },
2644 .needs_tvaudio = 1, 2426 .needs_tvaudio = 1,
@@ -2648,17 +2430,15 @@ struct tvcard bttv_tvcards[] = {
2648 /* Chris Fanning <video4linux@haydon.net> */ 2430 /* Chris Fanning <video4linux@haydon.net> */
2649 .name = "Tibet Systems 'Progress DVR' CS16", 2431 .name = "Tibet Systems 'Progress DVR' CS16",
2650 .video_inputs = 16, 2432 .video_inputs = 16,
2651 .audio_inputs = 0, 2433 /* .audio_inputs= 0, */
2652 .tuner = UNSET, 2434 .svhs = NO_SVHS,
2653 .svhs = UNSET, 2435 .muxsel = MUXSEL(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2),
2654 .muxsel = { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 },
2655 .pll = PLL_28, 2436 .pll = PLL_28,
2656 .no_msp34xx = 1, 2437 .no_msp34xx = 1,
2657 .no_tda9875 = 1, 2438 .no_tda9875 = 1,
2658 .no_tda7432 = 1, 2439 .no_tda7432 = 1,
2659 .tuner_type = UNSET, 2440 .tuner_type = TUNER_ABSENT,
2660 .tuner_addr = ADDR_UNSET, 2441 .tuner_addr = ADDR_UNSET,
2661 .radio_addr = ADDR_UNSET,
2662 .muxsel_hook = tibetCS16_muxsel, 2442 .muxsel_hook = tibetCS16_muxsel,
2663 }, 2443 },
2664 [BTTV_BOARD_KODICOM_4400R] = { 2444 [BTTV_BOARD_KODICOM_4400R] = {
@@ -2675,12 +2455,10 @@ struct tvcard bttv_tvcards[] = {
2675 */ 2455 */
2676 .name = "Kodicom 4400R (master)", 2456 .name = "Kodicom 4400R (master)",
2677 .video_inputs = 16, 2457 .video_inputs = 16,
2678 .audio_inputs = 0, 2458 /* .audio_inputs= 0, */
2679 .tuner = UNSET, 2459 .tuner_type = TUNER_ABSENT,
2680 .tuner_type = UNSET,
2681 .tuner_addr = ADDR_UNSET, 2460 .tuner_addr = ADDR_UNSET,
2682 .radio_addr = ADDR_UNSET, 2461 .svhs = NO_SVHS,
2683 .svhs = UNSET,
2684 /* GPIO bits 0-9 used for analog switch: 2462 /* GPIO bits 0-9 used for analog switch:
2685 * 00 - 03: camera selector 2463 * 00 - 03: camera selector
2686 * 04 - 06: channel (controller) selector 2464 * 04 - 06: channel (controller) selector
@@ -2691,7 +2469,7 @@ struct tvcard bttv_tvcards[] = {
2691 */ 2469 */
2692 .gpiomask = 0x0003ff, 2470 .gpiomask = 0x0003ff,
2693 .no_gpioirq = 1, 2471 .no_gpioirq = 1,
2694 .muxsel = { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 }, 2472 .muxsel = MUXSEL(3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3),
2695 .pll = PLL_28, 2473 .pll = PLL_28,
2696 .no_msp34xx = 1, 2474 .no_msp34xx = 1,
2697 .no_tda7432 = 1, 2475 .no_tda7432 = 1,
@@ -2707,15 +2485,13 @@ struct tvcard bttv_tvcards[] = {
2707 */ 2485 */
2708 .name = "Kodicom 4400R (slave)", 2486 .name = "Kodicom 4400R (slave)",
2709 .video_inputs = 16, 2487 .video_inputs = 16,
2710 .audio_inputs = 0, 2488 /* .audio_inputs= 0, */
2711 .tuner = UNSET, 2489 .tuner_type = TUNER_ABSENT,
2712 .tuner_type = UNSET,
2713 .tuner_addr = ADDR_UNSET, 2490 .tuner_addr = ADDR_UNSET,
2714 .radio_addr = ADDR_UNSET, 2491 .svhs = NO_SVHS,
2715 .svhs = UNSET,
2716 .gpiomask = 0x010000, 2492 .gpiomask = 0x010000,
2717 .no_gpioirq = 1, 2493 .no_gpioirq = 1,
2718 .muxsel = { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 }, 2494 .muxsel = MUXSEL(3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3),
2719 .pll = PLL_28, 2495 .pll = PLL_28,
2720 .no_msp34xx = 1, 2496 .no_msp34xx = 1,
2721 .no_tda7432 = 1, 2497 .no_tda7432 = 1,
@@ -2728,27 +2504,23 @@ struct tvcard bttv_tvcards[] = {
2728 /* Adlink RTV24 with special unlock codes */ 2504 /* Adlink RTV24 with special unlock codes */
2729 .name = "Adlink RTV24", 2505 .name = "Adlink RTV24",
2730 .video_inputs = 4, 2506 .video_inputs = 4,
2731 .audio_inputs = 1, 2507 /* .audio_inputs= 1, */
2732 .tuner = 0,
2733 .svhs = 2, 2508 .svhs = 2,
2734 .muxsel = { 2, 3, 1, 0 }, 2509 .muxsel = MUXSEL(2, 3, 1, 0),
2735 .tuner_type = UNSET, 2510 .tuner_type = UNSET,
2736 .tuner_addr = ADDR_UNSET, 2511 .tuner_addr = ADDR_UNSET,
2737 .radio_addr = ADDR_UNSET,
2738 .pll = PLL_28, 2512 .pll = PLL_28,
2739 }, 2513 },
2740 /* ---- card 0x87---------------------------------- */ 2514 /* ---- card 0x87---------------------------------- */
2741 [BTTV_BOARD_DVICO_FUSIONHDTV_5_LITE] = { 2515 [BTTV_BOARD_DVICO_FUSIONHDTV_5_LITE] = {
2742 /* Michael Krufky <mkrufky@m1k.net> */ 2516 /* Michael Krufky <mkrufky@m1k.net> */
2743 .name = "DViCO FusionHDTV 5 Lite", 2517 .name = "DViCO FusionHDTV 5 Lite",
2744 .tuner = 0,
2745 .tuner_type = TUNER_LG_TDVS_H06XF, /* TDVS-H064F */ 2518 .tuner_type = TUNER_LG_TDVS_H06XF, /* TDVS-H064F */
2746 .tuner_addr = ADDR_UNSET, 2519 .tuner_addr = ADDR_UNSET,
2747 .radio_addr = ADDR_UNSET,
2748 .video_inputs = 3, 2520 .video_inputs = 3,
2749 .audio_inputs = 1, 2521 /* .audio_inputs= 1, */
2750 .svhs = 2, 2522 .svhs = 2,
2751 .muxsel = { 2, 3, 1 }, 2523 .muxsel = MUXSEL(2, 3, 1),
2752 .gpiomask = 0x00e00007, 2524 .gpiomask = 0x00e00007,
2753 .gpiomux = { 0x00400005, 0, 0x00000001, 0 }, 2525 .gpiomux = { 0x00400005, 0, 0x00000001, 0 },
2754 .gpiomute = 0x00c00007, 2526 .gpiomute = 0x00c00007,
@@ -2762,75 +2534,68 @@ struct tvcard bttv_tvcards[] = {
2762 /* Mauro Carvalho Chehab <mchehab@infradead.org> */ 2534 /* Mauro Carvalho Chehab <mchehab@infradead.org> */
2763 .name = "Acorp Y878F", 2535 .name = "Acorp Y878F",
2764 .video_inputs = 3, 2536 .video_inputs = 3,
2765 .audio_inputs = 1, 2537 /* .audio_inputs= 1, */
2766 .tuner = 0,
2767 .svhs = 2, 2538 .svhs = 2,
2768 .gpiomask = 0x01fe00, 2539 .gpiomask = 0x01fe00,
2769 .muxsel = { 2, 3, 1, 1 }, 2540 .muxsel = MUXSEL(2, 3, 1, 1),
2770 .gpiomux = { 0x001e00, 0, 0x018000, 0x014000 }, 2541 .gpiomux = { 0x001e00, 0, 0x018000, 0x014000 },
2771 .gpiomute = 0x002000, 2542 .gpiomute = 0x002000,
2772 .needs_tvaudio = 1, 2543 .needs_tvaudio = 1,
2773 .pll = PLL_28, 2544 .pll = PLL_28,
2774 .tuner_type = TUNER_YMEC_TVF66T5_B_DFF, 2545 .tuner_type = TUNER_YMEC_TVF66T5_B_DFF,
2775 .tuner_addr = 0xc1 >>1, 2546 .tuner_addr = 0xc1 >>1,
2776 .radio_addr = 0xc1 >>1,
2777 .has_radio = 1, 2547 .has_radio = 1,
2778 }, 2548 },
2779 /* ---- card 0x89 ---------------------------------- */ 2549 /* ---- card 0x89 ---------------------------------- */
2780 [BTTV_BOARD_CONCEPTRONIC_CTVFMI2] = { 2550 [BTTV_BOARD_CONCEPTRONIC_CTVFMI2] = {
2781 .name = "Conceptronic CTVFMi v2", 2551 .name = "Conceptronic CTVFMi v2",
2782 .video_inputs = 3, 2552 .video_inputs = 3,
2783 .audio_inputs = 1, 2553 /* .audio_inputs= 1, */
2784 .tuner = 0,
2785 .svhs = 2, 2554 .svhs = 2,
2786 .gpiomask = 0x001c0007, 2555 .gpiomask = 0x001c0007,
2787 .muxsel = { 2, 3, 1, 1 }, 2556 .muxsel = MUXSEL(2, 3, 1, 1),
2788 .gpiomux = { 0, 1, 2, 2 }, 2557 .gpiomux = { 0, 1, 2, 2 },
2789 .gpiomute = 3, 2558 .gpiomute = 3,
2790 .needs_tvaudio = 0, 2559 .needs_tvaudio = 0,
2791 .pll = PLL_28, 2560 .pll = PLL_28,
2792 .tuner_type = TUNER_TENA_9533_DI, 2561 .tuner_type = TUNER_TENA_9533_DI,
2793 .tuner_addr = ADDR_UNSET, 2562 .tuner_addr = ADDR_UNSET,
2794 .radio_addr = ADDR_UNSET,
2795 .has_remote = 1, 2563 .has_remote = 1,
2796 .has_radio = 1, 2564 .has_radio = 1,
2797 }, 2565 },
2798 /* ---- card 0x8a ---------------------------------- */ 2566 /* ---- card 0x8a ---------------------------------- */
2799 [BTTV_BOARD_PV_BT878P_2E] = { 2567 [BTTV_BOARD_PV_BT878P_2E] = {
2800 .name = "Prolink Pixelview PV-BT878P+ (Rev.2E)", 2568 .name = "Prolink Pixelview PV-BT878P+ (Rev.2E)",
2801 .video_inputs = 5, 2569 .video_inputs = 5,
2802 .audio_inputs = 1, 2570 /* .audio_inputs= 1, */
2803 .tuner = 0, 2571 .svhs = 3,
2804 .svhs = 3, 2572 .has_dig_in = 1,
2805 .gpiomask = 0x01fe00, 2573 .gpiomask = 0x01fe00,
2806 .muxsel = { 2,3,1,1,-1 }, 2574 .muxsel = MUXSEL(2, 3, 1, 1, 0), /* in 4 is digital */
2807 .digital_mode = DIGITAL_MODE_CAMERA, 2575 /* .digital_mode= DIGITAL_MODE_CAMERA, */
2808 .gpiomux = { 0x00400, 0x10400, 0x04400, 0x80000 }, 2576 .gpiomux = { 0x00400, 0x10400, 0x04400, 0x80000 },
2809 .gpiomute = 0x12400, 2577 .gpiomute = 0x12400,
2810 .no_msp34xx = 1, 2578 .no_msp34xx = 1,
2811 .pll = PLL_28, 2579 .pll = PLL_28,
2812 .tuner_type = TUNER_LG_PAL_FM, 2580 .tuner_type = TUNER_LG_PAL_FM,
2813 .tuner_addr = ADDR_UNSET, 2581 .tuner_addr = ADDR_UNSET,
2814 .radio_addr = ADDR_UNSET, 2582 .has_remote = 1,
2815 .has_remote = 1,
2816 }, 2583 },
2817 /* ---- card 0x8b ---------------------------------- */ 2584 /* ---- card 0x8b ---------------------------------- */
2818 [BTTV_BOARD_PV_M4900] = { 2585 [BTTV_BOARD_PV_M4900] = {
2819 /* Sérgio Fortier <sergiofortier@yahoo.com.br> */ 2586 /* Sérgio Fortier <sergiofortier@yahoo.com.br> */
2820 .name = "Prolink PixelView PlayTV MPEG2 PV-M4900", 2587 .name = "Prolink PixelView PlayTV MPEG2 PV-M4900",
2821 .video_inputs = 3, 2588 .video_inputs = 3,
2822 .audio_inputs = 1, 2589 /* .audio_inputs= 1, */
2823 .tuner = 0,
2824 .svhs = 2, 2590 .svhs = 2,
2825 .gpiomask = 0x3f, 2591 .gpiomask = 0x3f,
2826 .muxsel = { 2, 3, 1, 1 }, 2592 .muxsel = MUXSEL(2, 3, 1, 1),
2827 .gpiomux = { 0x21, 0x20, 0x24, 0x2c }, 2593 .gpiomux = { 0x21, 0x20, 0x24, 0x2c },
2828 .gpiomute = 0x29, 2594 .gpiomute = 0x29,
2829 .no_msp34xx = 1, 2595 .no_msp34xx = 1,
2830 .pll = PLL_28, 2596 .pll = PLL_28,
2831 .tuner_type = TUNER_YMEC_TVF_5533MF, 2597 .tuner_type = TUNER_YMEC_TVF_5533MF,
2832 .tuner_addr = ADDR_UNSET, 2598 .tuner_addr = ADDR_UNSET,
2833 .radio_addr = ADDR_UNSET,
2834 .has_radio = 1, 2599 .has_radio = 1,
2835 .has_remote = 1, 2600 .has_remote = 1,
2836 }, 2601 },
@@ -2850,17 +2615,15 @@ struct tvcard bttv_tvcards[] = {
2850 [BTTV_BOARD_OSPREY440] = { 2615 [BTTV_BOARD_OSPREY440] = {
2851 .name = "Osprey 440", 2616 .name = "Osprey 440",
2852 .video_inputs = 4, 2617 .video_inputs = 4,
2853 .audio_inputs = 2, /* this is meaningless */ 2618 /* .audio_inputs= 2, */
2854 .tuner = UNSET, 2619 .svhs = NO_SVHS,
2855 .svhs = UNSET, 2620 .muxsel = MUXSEL(2, 3, 0, 1), /* 3,0,1 are guesses */
2856 .muxsel = { 2, 3, 0, 1 }, /* 3,0,1 are guesses */
2857 .gpiomask = 0x303, 2621 .gpiomask = 0x303,
2858 .gpiomute = 0x000, /* int + 32kHz */ 2622 .gpiomute = 0x000, /* int + 32kHz */
2859 .gpiomux = { 0, 0, 0x000, 0x100}, 2623 .gpiomux = { 0, 0, 0x000, 0x100},
2860 .pll = PLL_28, 2624 .pll = PLL_28,
2861 .tuner_type = UNSET, 2625 .tuner_type = TUNER_ABSENT,
2862 .tuner_addr = ADDR_UNSET, 2626 .tuner_addr = ADDR_UNSET,
2863 .radio_addr = ADDR_UNSET,
2864 .no_msp34xx = 1, 2627 .no_msp34xx = 1,
2865 .no_tda9875 = 1, 2628 .no_tda9875 = 1,
2866 .no_tda7432 = 1, 2629 .no_tda7432 = 1,
@@ -2869,28 +2632,25 @@ struct tvcard bttv_tvcards[] = {
2869 [BTTV_BOARD_ASOUND_SKYEYE] = { 2632 [BTTV_BOARD_ASOUND_SKYEYE] = {
2870 .name = "Asound Skyeye PCTV", 2633 .name = "Asound Skyeye PCTV",
2871 .video_inputs = 3, 2634 .video_inputs = 3,
2872 .audio_inputs = 1, 2635 /* .audio_inputs= 1, */
2873 .tuner = 0,
2874 .svhs = 2, 2636 .svhs = 2,
2875 .gpiomask = 15, 2637 .gpiomask = 15,
2876 .muxsel = { 2, 3, 1, 1 }, 2638 .muxsel = MUXSEL(2, 3, 1, 1),
2877 .gpiomux = { 2, 0, 0, 0 }, 2639 .gpiomux = { 2, 0, 0, 0 },
2878 .gpiomute = 1, 2640 .gpiomute = 1,
2879 .needs_tvaudio = 1, 2641 .needs_tvaudio = 1,
2880 .pll = PLL_28, 2642 .pll = PLL_28,
2881 .tuner_type = TUNER_PHILIPS_NTSC, 2643 .tuner_type = TUNER_PHILIPS_NTSC,
2882 .tuner_addr = ADDR_UNSET, 2644 .tuner_addr = ADDR_UNSET,
2883 .radio_addr = ADDR_UNSET,
2884 }, 2645 },
2885 /* ---- card 0x8e ---------------------------------- */ 2646 /* ---- card 0x8e ---------------------------------- */
2886 [BTTV_BOARD_SABRENT_TVFM] = { 2647 [BTTV_BOARD_SABRENT_TVFM] = {
2887 .name = "Sabrent TV-FM (bttv version)", 2648 .name = "Sabrent TV-FM (bttv version)",
2888 .video_inputs = 3, 2649 .video_inputs = 3,
2889 .audio_inputs = 1, 2650 /* .audio_inputs= 1, */
2890 .tuner = 0,
2891 .svhs = 2, 2651 .svhs = 2,
2892 .gpiomask = 0x108007, 2652 .gpiomask = 0x108007,
2893 .muxsel = { 2, 3, 1, 1 }, 2653 .muxsel = MUXSEL(2, 3, 1, 1),
2894 .gpiomux = { 100000, 100002, 100002, 100000 }, 2654 .gpiomux = { 100000, 100002, 100002, 100000 },
2895 .no_msp34xx = 1, 2655 .no_msp34xx = 1,
2896 .no_tda9875 = 1, 2656 .no_tda9875 = 1,
@@ -2904,17 +2664,15 @@ struct tvcard bttv_tvcards[] = {
2904 [BTTV_BOARD_HAUPPAUGE_IMPACTVCB] = { 2664 [BTTV_BOARD_HAUPPAUGE_IMPACTVCB] = {
2905 .name = "Hauppauge ImpactVCB (bt878)", 2665 .name = "Hauppauge ImpactVCB (bt878)",
2906 .video_inputs = 4, 2666 .video_inputs = 4,
2907 .audio_inputs = 0, 2667 /* .audio_inputs= 0, */
2908 .tuner = UNSET, 2668 .svhs = NO_SVHS,
2909 .svhs = UNSET,
2910 .gpiomask = 0x0f, /* old: 7 */ 2669 .gpiomask = 0x0f, /* old: 7 */
2911 .muxsel = { 0, 1, 3, 2 }, /* Composite 0-3 */ 2670 .muxsel = MUXSEL(0, 1, 3, 2), /* Composite 0-3 */
2912 .no_msp34xx = 1, 2671 .no_msp34xx = 1,
2913 .no_tda9875 = 1, 2672 .no_tda9875 = 1,
2914 .no_tda7432 = 1, 2673 .no_tda7432 = 1,
2915 .tuner_type = UNSET, 2674 .tuner_type = TUNER_ABSENT,
2916 .tuner_addr = ADDR_UNSET, 2675 .tuner_addr = ADDR_UNSET,
2917 .radio_addr = ADDR_UNSET,
2918 }, 2676 },
2919 [BTTV_BOARD_MACHTV_MAGICTV] = { 2677 [BTTV_BOARD_MACHTV_MAGICTV] = {
2920 /* Julian Calaby <julian.calaby@gmail.com> 2678 /* Julian Calaby <julian.calaby@gmail.com>
@@ -2926,16 +2684,14 @@ struct tvcard bttv_tvcards[] = {
2926 2684
2927 .name = "MagicTV", /* rebranded MachTV */ 2685 .name = "MagicTV", /* rebranded MachTV */
2928 .video_inputs = 3, 2686 .video_inputs = 3,
2929 .audio_inputs = 1, 2687 /* .audio_inputs= 1, */
2930 .tuner = 0,
2931 .svhs = 2, 2688 .svhs = 2,
2932 .gpiomask = 7, 2689 .gpiomask = 7,
2933 .muxsel = { 2, 3, 1, 1 }, 2690 .muxsel = MUXSEL(2, 3, 1, 1),
2934 .gpiomux = { 0, 1, 2, 3 }, 2691 .gpiomux = { 0, 1, 2, 3 },
2935 .gpiomute = 4, 2692 .gpiomute = 4,
2936 .tuner_type = TUNER_TEMIC_4009FR5_PAL, 2693 .tuner_type = TUNER_TEMIC_4009FR5_PAL,
2937 .tuner_addr = ADDR_UNSET, 2694 .tuner_addr = ADDR_UNSET,
2938 .radio_addr = ADDR_UNSET,
2939 .pll = PLL_28, 2695 .pll = PLL_28,
2940 .has_radio = 1, 2696 .has_radio = 1,
2941 .has_remote = 1, 2697 .has_remote = 1,
@@ -2943,36 +2699,30 @@ struct tvcard bttv_tvcards[] = {
2943 [BTTV_BOARD_SSAI_SECURITY] = { 2699 [BTTV_BOARD_SSAI_SECURITY] = {
2944 .name = "SSAI Security Video Interface", 2700 .name = "SSAI Security Video Interface",
2945 .video_inputs = 4, 2701 .video_inputs = 4,
2946 .audio_inputs = 0, 2702 /* .audio_inputs= 0, */
2947 .tuner = UNSET, 2703 .svhs = NO_SVHS,
2948 .svhs = UNSET, 2704 .muxsel = MUXSEL(0, 1, 2, 3),
2949 .muxsel = { 0, 1, 2, 3 }, 2705 .tuner_type = TUNER_ABSENT,
2950 .tuner_type = UNSET,
2951 .tuner_addr = ADDR_UNSET, 2706 .tuner_addr = ADDR_UNSET,
2952 .radio_addr = ADDR_UNSET,
2953 }, 2707 },
2954 [BTTV_BOARD_SSAI_ULTRASOUND] = { 2708 [BTTV_BOARD_SSAI_ULTRASOUND] = {
2955 .name = "SSAI Ultrasound Video Interface", 2709 .name = "SSAI Ultrasound Video Interface",
2956 .video_inputs = 2, 2710 .video_inputs = 2,
2957 .audio_inputs = 0, 2711 /* .audio_inputs= 0, */
2958 .tuner = UNSET,
2959 .svhs = 1, 2712 .svhs = 1,
2960 .muxsel = { 2, 0, 1, 3 }, 2713 .muxsel = MUXSEL(2, 0, 1, 3),
2961 .tuner_type = UNSET, 2714 .tuner_type = TUNER_ABSENT,
2962 .tuner_addr = ADDR_UNSET, 2715 .tuner_addr = ADDR_UNSET,
2963 .radio_addr = ADDR_UNSET,
2964 }, 2716 },
2965 /* ---- card 0x94---------------------------------- */ 2717 /* ---- card 0x94---------------------------------- */
2966 [BTTV_BOARD_DVICO_FUSIONHDTV_2] = { 2718 [BTTV_BOARD_DVICO_FUSIONHDTV_2] = {
2967 .name = "DViCO FusionHDTV 2", 2719 .name = "DViCO FusionHDTV 2",
2968 .tuner = 0,
2969 .tuner_type = TUNER_PHILIPS_FCV1236D, 2720 .tuner_type = TUNER_PHILIPS_FCV1236D,
2970 .tuner_addr = ADDR_UNSET, 2721 .tuner_addr = ADDR_UNSET,
2971 .radio_addr = ADDR_UNSET,
2972 .video_inputs = 3, 2722 .video_inputs = 3,
2973 .audio_inputs = 1, 2723 /* .audio_inputs= 1, */
2974 .svhs = 2, 2724 .svhs = 2,
2975 .muxsel = { 2, 3, 1 }, 2725 .muxsel = MUXSEL(2, 3, 1),
2976 .gpiomask = 0x00e00007, 2726 .gpiomask = 0x00e00007,
2977 .gpiomux = { 0x00400005, 0, 0x00000001, 0 }, 2727 .gpiomux = { 0x00400005, 0, 0x00000001, 0 },
2978 .gpiomute = 0x00c00007, 2728 .gpiomute = 0x00c00007,
@@ -2984,36 +2734,31 @@ struct tvcard bttv_tvcards[] = {
2984 [BTTV_BOARD_TYPHOON_TVTUNERPCI] = { 2734 [BTTV_BOARD_TYPHOON_TVTUNERPCI] = {
2985 .name = "Typhoon TV-Tuner PCI (50684)", 2735 .name = "Typhoon TV-Tuner PCI (50684)",
2986 .video_inputs = 3, 2736 .video_inputs = 3,
2987 .audio_inputs = 1, 2737 /* .audio_inputs= 1, */
2988 .tuner = 0,
2989 .svhs = 2, 2738 .svhs = 2,
2990 .gpiomask = 0x3014f, 2739 .gpiomask = 0x3014f,
2991 .muxsel = { 2, 3, 1, 1 }, 2740 .muxsel = MUXSEL(2, 3, 1, 1),
2992 .gpiomux = { 0x20001,0x10001, 0, 0 }, 2741 .gpiomux = { 0x20001,0x10001, 0, 0 },
2993 .gpiomute = 10, 2742 .gpiomute = 10,
2994 .needs_tvaudio = 1, 2743 .needs_tvaudio = 1,
2995 .pll = PLL_28, 2744 .pll = PLL_28,
2996 .tuner_type = TUNER_PHILIPS_PAL_I, 2745 .tuner_type = TUNER_PHILIPS_PAL_I,
2997 .tuner_addr = ADDR_UNSET, 2746 .tuner_addr = ADDR_UNSET,
2998 .radio_addr = ADDR_UNSET,
2999 }, 2747 },
3000 [BTTV_BOARD_GEOVISION_GV600] = { 2748 [BTTV_BOARD_GEOVISION_GV600] = {
3001 /* emhn@usb.ve */ 2749 /* emhn@usb.ve */
3002 .name = "Geovision GV-600", 2750 .name = "Geovision GV-600",
3003 .video_inputs = 16, 2751 .video_inputs = 16,
3004 .audio_inputs = 0, 2752 /* .audio_inputs= 0, */
3005 .tuner = UNSET, 2753 .svhs = NO_SVHS,
3006 .svhs = UNSET, 2754 .gpiomask = 0x0,
3007 .gpiomask = 0x0, 2755 .muxsel = MUXSEL(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2),
3008 .muxsel = { 2, 2, 2, 2, 2, 2, 2, 2, 2756 .muxsel_hook = geovision_muxsel,
3009 2, 2, 2, 2, 2, 2, 2, 2 }, 2757 .gpiomux = { 0 },
3010 .muxsel_hook = geovision_muxsel, 2758 .no_msp34xx = 1,
3011 .gpiomux = { 0 }, 2759 .pll = PLL_28,
3012 .no_msp34xx = 1, 2760 .tuner_type = TUNER_ABSENT,
3013 .pll = PLL_28, 2761 .tuner_addr = ADDR_UNSET,
3014 .tuner_type = UNSET,
3015 .tuner_addr = ADDR_UNSET,
3016 .radio_addr = ADDR_UNSET,
3017 }, 2762 },
3018 [BTTV_BOARD_KOZUMI_KTV_01C] = { 2763 [BTTV_BOARD_KOZUMI_KTV_01C] = {
3019 /* Mauro Lacy <mauro@lacy.com.ar> 2764 /* Mauro Lacy <mauro@lacy.com.ar>
@@ -3021,17 +2766,15 @@ struct tvcard bttv_tvcards[] = {
3021 2766
3022 .name = "Kozumi KTV-01C", 2767 .name = "Kozumi KTV-01C",
3023 .video_inputs = 3, 2768 .video_inputs = 3,
3024 .audio_inputs = 1, 2769 /* .audio_inputs= 1, */
3025 .tuner = 0,
3026 .svhs = 2, 2770 .svhs = 2,
3027 .gpiomask = 0x008007, 2771 .gpiomask = 0x008007,
3028 .muxsel = { 2, 3, 1, 1 }, 2772 .muxsel = MUXSEL(2, 3, 1, 1),
3029 .gpiomux = { 0, 1, 2, 2 }, /* CONTVFMi */ 2773 .gpiomux = { 0, 1, 2, 2 }, /* CONTVFMi */
3030 .gpiomute = 3, /* CONTVFMi */ 2774 .gpiomute = 3, /* CONTVFMi */
3031 .needs_tvaudio = 0, 2775 .needs_tvaudio = 0,
3032 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3, /* TCL MK3 */ 2776 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3, /* TCL MK3 */
3033 .tuner_addr = ADDR_UNSET, 2777 .tuner_addr = ADDR_UNSET,
3034 .radio_addr = ADDR_UNSET,
3035 .pll = PLL_28, 2778 .pll = PLL_28,
3036 .has_radio = 1, 2779 .has_radio = 1,
3037 .has_remote = 1, 2780 .has_remote = 1,
@@ -3041,8 +2784,7 @@ struct tvcard bttv_tvcards[] = {
3041 Mauro Carvalho Chehab <mchehab@infradead.org */ 2784 Mauro Carvalho Chehab <mchehab@infradead.org */
3042 .name = "Encore ENL TV-FM-2", 2785 .name = "Encore ENL TV-FM-2",
3043 .video_inputs = 3, 2786 .video_inputs = 3,
3044 .audio_inputs = 1, 2787 /* .audio_inputs= 1, */
3045 .tuner = 0,
3046 .svhs = 2, 2788 .svhs = 2,
3047 /* bit 6 -> IR disabled 2789 /* bit 6 -> IR disabled
3048 bit 18/17 = 00 -> mute 2790 bit 18/17 = 00 -> mute
@@ -3051,12 +2793,11 @@ struct tvcard bttv_tvcards[] = {
3051 11 -> internal audio input 2793 11 -> internal audio input
3052 */ 2794 */
3053 .gpiomask = 0x060040, 2795 .gpiomask = 0x060040,
3054 .muxsel = { 2, 3, 3 }, 2796 .muxsel = MUXSEL(2, 3, 3),
3055 .gpiomux = { 0x60000, 0x60000, 0x20000, 0x20000 }, 2797 .gpiomux = { 0x60000, 0x60000, 0x20000, 0x20000 },
3056 .gpiomute = 0, 2798 .gpiomute = 0,
3057 .tuner_type = TUNER_TCL_MF02GIP_5N, 2799 .tuner_type = TUNER_TCL_MF02GIP_5N,
3058 .tuner_addr = ADDR_UNSET, 2800 .tuner_addr = ADDR_UNSET,
3059 .radio_addr = ADDR_UNSET,
3060 .pll = PLL_28, 2801 .pll = PLL_28,
3061 .has_radio = 1, 2802 .has_radio = 1,
3062 .has_remote = 1, 2803 .has_remote = 1,
@@ -3065,50 +2806,111 @@ struct tvcard bttv_tvcards[] = {
3065 /* D.Heer@Phytec.de */ 2806 /* D.Heer@Phytec.de */
3066 .name = "PHYTEC VD-012 (bt878)", 2807 .name = "PHYTEC VD-012 (bt878)",
3067 .video_inputs = 4, 2808 .video_inputs = 4,
3068 .audio_inputs = 0, 2809 /* .audio_inputs= 0, */
3069 .tuner = UNSET, /* card has no tuner */ 2810 .svhs = NO_SVHS,
3070 .svhs = UNSET, /* card has no s-video */
3071 .gpiomask = 0x00, 2811 .gpiomask = 0x00,
3072 .muxsel = { 0, 2, 3, 1 }, 2812 .muxsel = MUXSEL(0, 2, 3, 1),
3073 .gpiomux = { 0, 0, 0, 0 }, /* card has no audio */ 2813 .gpiomux = { 0, 0, 0, 0 }, /* card has no audio */
3074 .needs_tvaudio = 0, 2814 .needs_tvaudio = 0,
3075 .pll = PLL_28, 2815 .pll = PLL_28,
3076 .tuner_type = UNSET, 2816 .tuner_type = TUNER_ABSENT,
3077 .tuner_addr = ADDR_UNSET, 2817 .tuner_addr = ADDR_UNSET,
3078 .radio_addr = ADDR_UNSET,
3079 }, 2818 },
3080 [BTTV_BOARD_VD012_X1] = { 2819 [BTTV_BOARD_VD012_X1] = {
3081 /* D.Heer@Phytec.de */ 2820 /* D.Heer@Phytec.de */
3082 .name = "PHYTEC VD-012-X1 (bt878)", 2821 .name = "PHYTEC VD-012-X1 (bt878)",
3083 .video_inputs = 4, 2822 .video_inputs = 4,
3084 .audio_inputs = 0, 2823 /* .audio_inputs= 0, */
3085 .tuner = UNSET, /* card has no tuner */
3086 .svhs = 3, 2824 .svhs = 3,
3087 .gpiomask = 0x00, 2825 .gpiomask = 0x00,
3088 .muxsel = { 2, 3, 1 }, 2826 .muxsel = MUXSEL(2, 3, 1),
3089 .gpiomux = { 0, 0, 0, 0 }, /* card has no audio */ 2827 .gpiomux = { 0, 0, 0, 0 }, /* card has no audio */
3090 .needs_tvaudio = 0, 2828 .needs_tvaudio = 0,
3091 .pll = PLL_28, 2829 .pll = PLL_28,
3092 .tuner_type = UNSET, 2830 .tuner_type = TUNER_ABSENT,
3093 .tuner_addr = ADDR_UNSET, 2831 .tuner_addr = ADDR_UNSET,
3094 .radio_addr = ADDR_UNSET,
3095 }, 2832 },
3096 [BTTV_BOARD_VD012_X2] = { 2833 [BTTV_BOARD_VD012_X2] = {
3097 /* D.Heer@Phytec.de */ 2834 /* D.Heer@Phytec.de */
3098 .name = "PHYTEC VD-012-X2 (bt878)", 2835 .name = "PHYTEC VD-012-X2 (bt878)",
3099 .video_inputs = 4, 2836 .video_inputs = 4,
3100 .audio_inputs = 0, 2837 /* .audio_inputs= 0, */
3101 .tuner = UNSET, /* card has no tuner */
3102 .svhs = 3, 2838 .svhs = 3,
3103 .gpiomask = 0x00, 2839 .gpiomask = 0x00,
3104 .muxsel = { 3, 2, 1 }, 2840 .muxsel = MUXSEL(3, 2, 1),
3105 .gpiomux = { 0, 0, 0, 0 }, /* card has no audio */ 2841 .gpiomux = { 0, 0, 0, 0 }, /* card has no audio */
3106 .needs_tvaudio = 0, 2842 .needs_tvaudio = 0,
3107 .pll = PLL_28, 2843 .pll = PLL_28,
3108 .tuner_type = UNSET, 2844 .tuner_type = TUNER_ABSENT,
3109 .tuner_addr = ADDR_UNSET, 2845 .tuner_addr = ADDR_UNSET,
3110 .radio_addr = ADDR_UNSET, 2846 },
3111 } 2847 [BTTV_BOARD_GEOVISION_GV800S] = {
2848 /* Bruno Christo <bchristo@inf.ufsm.br>
2849 *
2850 * GeoVision GV-800(S) has 4 Conexant Fusion 878A:
2851 * 1 audio input per BT878A = 4 audio inputs
2852 * 4 video inputs per BT878A = 16 video inputs
2853 * This is the first BT878A chip of the GV-800(S). It's the
2854 * "master" chip and it controls the video inputs through an
2855 * analog multiplexer (a CD22M3494) via some GPIO pins. The
2856 * slaves should use card type 0x9e (following this one).
2857 * There is a EEPROM on the card which is currently not handled.
2858 * The audio input is not working yet.
2859 */
2860 .name = "Geovision GV-800(S) (master)",
2861 .video_inputs = 4,
2862 /* .audio_inputs= 1, */
2863 .tuner_type = TUNER_ABSENT,
2864 .tuner_addr = ADDR_UNSET,
2865 .svhs = NO_SVHS,
2866 .gpiomask = 0xf107f,
2867 .no_gpioirq = 1,
2868 .muxsel = MUXSEL(2, 2, 2, 2),
2869 .pll = PLL_28,
2870 .no_msp34xx = 1,
2871 .no_tda7432 = 1,
2872 .no_tda9875 = 1,
2873 .muxsel_hook = gv800s_muxsel,
2874 },
2875 [BTTV_BOARD_GEOVISION_GV800S_SL] = {
2876 /* Bruno Christo <bchristo@inf.ufsm.br>
2877 *
2878 * GeoVision GV-800(S) has 4 Conexant Fusion 878A:
2879 * 1 audio input per BT878A = 4 audio inputs
2880 * 4 video inputs per BT878A = 16 video inputs
2881 * The 3 other BT878A chips are "slave" chips of the GV-800(S)
2882 * and should use this card type.
2883 * The audio input is not working yet.
2884 */
2885 .name = "Geovision GV-800(S) (slave)",
2886 .video_inputs = 4,
2887 /* .audio_inputs= 1, */
2888 .tuner_type = TUNER_ABSENT,
2889 .tuner_addr = ADDR_UNSET,
2890 .svhs = NO_SVHS,
2891 .gpiomask = 0x00,
2892 .no_gpioirq = 1,
2893 .muxsel = MUXSEL(2, 2, 2, 2),
2894 .pll = PLL_28,
2895 .no_msp34xx = 1,
2896 .no_tda7432 = 1,
2897 .no_tda9875 = 1,
2898 .muxsel_hook = gv800s_muxsel,
2899 },
2900 [BTTV_BOARD_PV183] = {
2901 .name = "ProVideo PV183", /* 0x9f */
2902 .video_inputs = 2,
2903 /* .audio_inputs= 0, */
2904 .svhs = NO_SVHS,
2905 .gpiomask = 0,
2906 .muxsel = MUXSEL(2, 3),
2907 .gpiomux = { 0 },
2908 .needs_tvaudio = 0,
2909 .no_msp34xx = 1,
2910 .pll = PLL_28,
2911 .tuner_type = TUNER_ABSENT,
2912 .tuner_addr = ADDR_UNSET,
2913 },
3112}; 2914};
3113 2915
3114static const unsigned int bttv_num_tvcards = ARRAY_SIZE(bttv_tvcards); 2916static const unsigned int bttv_num_tvcards = ARRAY_SIZE(bttv_tvcards);
@@ -3152,7 +2954,7 @@ void __devinit bttv_idcard(struct bttv *btv)
3152 btv->c.nr, btv->cardid & 0xffff, 2954 btv->c.nr, btv->cardid & 0xffff,
3153 (btv->cardid >> 16) & 0xffff); 2955 (btv->cardid >> 16) & 0xffff);
3154 printk(KERN_DEBUG "please mail id, board name and " 2956 printk(KERN_DEBUG "please mail id, board name and "
3155 "the correct card= insmod option to video4linux-list@redhat.com\n"); 2957 "the correct card= insmod option to linux-media@vger.kernel.org\n");
3156 } 2958 }
3157 } 2959 }
3158 2960
@@ -3403,8 +3205,7 @@ static void init_ids_eagle(struct bttv *btv)
3403 * has its own multiplexer */ 3205 * has its own multiplexer */
3404static void eagle_muxsel(struct bttv *btv, unsigned int input) 3206static void eagle_muxsel(struct bttv *btv, unsigned int input)
3405{ 3207{
3406 btaor((2)<<5, ~(3<<5), BT848_IFORM); 3208 gpio_bits(3, input & 3);
3407 gpio_bits(3,bttv_tvcards[btv->c.type].muxsel[input&7]);
3408 3209
3409 /* composite */ 3210 /* composite */
3410 /* set chroma ADC to sleep */ 3211 /* set chroma ADC to sleep */
@@ -3523,6 +3324,17 @@ void __devinit bttv_init_card1(struct bttv *btv)
3523/* initialization part two -- after registering i2c bus */ 3324/* initialization part two -- after registering i2c bus */
3524void __devinit bttv_init_card2(struct bttv *btv) 3325void __devinit bttv_init_card2(struct bttv *btv)
3525{ 3326{
3327 static const unsigned short tvaudio_addrs[] = {
3328 I2C_ADDR_TDA8425 >> 1,
3329 I2C_ADDR_TEA6300 >> 1,
3330 I2C_ADDR_TEA6420 >> 1,
3331 I2C_ADDR_TDA9840 >> 1,
3332 I2C_ADDR_TDA985x_L >> 1,
3333 I2C_ADDR_TDA985x_H >> 1,
3334 I2C_ADDR_TDA9874 >> 1,
3335 I2C_ADDR_PIC16C54 >> 1,
3336 I2C_CLIENT_END
3337 };
3526 int addr=ADDR_UNSET; 3338 int addr=ADDR_UNSET;
3527 3339
3528 btv->tuner_type = UNSET; 3340 btv->tuner_type = UNSET;
@@ -3629,6 +3441,9 @@ void __devinit bttv_init_card2(struct bttv *btv)
3629 case BTTV_BOARD_KODICOM_4400R: 3441 case BTTV_BOARD_KODICOM_4400R:
3630 kodicom4400r_init(btv); 3442 kodicom4400r_init(btv);
3631 break; 3443 break;
3444 case BTTV_BOARD_GEOVISION_GV800S:
3445 gv800s_init(btv);
3446 break;
3632 } 3447 }
3633 3448
3634 /* pll configuration */ 3449 /* pll configuration */
@@ -3670,13 +3485,12 @@ void __devinit bttv_init_card2(struct bttv *btv)
3670 addr = bttv_tvcards[btv->c.type].tuner_addr; 3485 addr = bttv_tvcards[btv->c.type].tuner_addr;
3671 3486
3672 if (UNSET != bttv_tvcards[btv->c.type].tuner_type) 3487 if (UNSET != bttv_tvcards[btv->c.type].tuner_type)
3673 if(UNSET == btv->tuner_type) 3488 if (UNSET == btv->tuner_type)
3674 btv->tuner_type = bttv_tvcards[btv->c.type].tuner_type; 3489 btv->tuner_type = bttv_tvcards[btv->c.type].tuner_type;
3675 if (UNSET != tuner[btv->c.nr]) 3490 if (UNSET != tuner[btv->c.nr])
3676 btv->tuner_type = tuner[btv->c.nr]; 3491 btv->tuner_type = tuner[btv->c.nr];
3677 3492
3678 if (btv->tuner_type == TUNER_ABSENT || 3493 if (btv->tuner_type == TUNER_ABSENT)
3679 bttv_tvcards[btv->c.type].tuner == UNSET)
3680 printk(KERN_INFO "bttv%d: tuner absent\n", btv->c.nr); 3494 printk(KERN_INFO "bttv%d: tuner absent\n", btv->c.nr);
3681 else if(btv->tuner_type == UNSET) 3495 else if(btv->tuner_type == UNSET)
3682 printk(KERN_WARNING "bttv%d: tuner type unset\n", btv->c.nr); 3496 printk(KERN_WARNING "bttv%d: tuner type unset\n", btv->c.nr);
@@ -3684,14 +3498,35 @@ void __devinit bttv_init_card2(struct bttv *btv)
3684 printk(KERN_INFO "bttv%d: tuner type=%d\n", btv->c.nr, 3498 printk(KERN_INFO "bttv%d: tuner type=%d\n", btv->c.nr,
3685 btv->tuner_type); 3499 btv->tuner_type);
3686 3500
3687 if (btv->tuner_type != UNSET) { 3501 if (autoload != UNSET) {
3502 printk(KERN_WARNING "bttv%d: the autoload option is obsolete.\n", btv->c.nr);
3503 printk(KERN_WARNING "bttv%d: use option msp3400, tda7432 or tvaudio to\n", btv->c.nr);
3504 printk(KERN_WARNING "bttv%d: override which audio module should be used.\n", btv->c.nr);
3505 }
3506
3507 if (UNSET == btv->tuner_type)
3508 btv->tuner_type = TUNER_ABSENT;
3509
3510 if (btv->tuner_type != TUNER_ABSENT) {
3688 struct tuner_setup tun_setup; 3511 struct tuner_setup tun_setup;
3689 3512
3513 /* Load tuner module before issuing tuner config call! */
3514 if (bttv_tvcards[btv->c.type].has_radio)
3515 v4l2_i2c_new_probed_subdev(&btv->c.i2c_adap,
3516 "tuner", "tuner", v4l2_i2c_tuner_addrs(ADDRS_RADIO));
3517 v4l2_i2c_new_probed_subdev(&btv->c.i2c_adap, "tuner",
3518 "tuner", v4l2_i2c_tuner_addrs(ADDRS_DEMOD));
3519 v4l2_i2c_new_probed_subdev(&btv->c.i2c_adap, "tuner",
3520 "tuner", v4l2_i2c_tuner_addrs(ADDRS_TV_WITH_DEMOD));
3521
3690 tun_setup.mode_mask = T_ANALOG_TV | T_DIGITAL_TV; 3522 tun_setup.mode_mask = T_ANALOG_TV | T_DIGITAL_TV;
3691 tun_setup.type = btv->tuner_type; 3523 tun_setup.type = btv->tuner_type;
3692 tun_setup.addr = addr; 3524 tun_setup.addr = addr;
3693 3525
3694 bttv_call_i2c_clients(btv, TUNER_SET_TYPE_ADDR, &tun_setup); 3526 if (bttv_tvcards[btv->c.type].has_radio)
3527 tun_setup.mode_mask |= T_RADIO;
3528
3529 bttv_call_all(btv, tuner, s_type_addr, &tun_setup);
3695 } 3530 }
3696 3531
3697 if (btv->tda9887_conf) { 3532 if (btv->tda9887_conf) {
@@ -3700,10 +3535,13 @@ void __devinit bttv_init_card2(struct bttv *btv)
3700 tda9887_cfg.tuner = TUNER_TDA9887; 3535 tda9887_cfg.tuner = TUNER_TDA9887;
3701 tda9887_cfg.priv = &btv->tda9887_conf; 3536 tda9887_cfg.priv = &btv->tda9887_conf;
3702 3537
3703 bttv_call_i2c_clients(btv, TUNER_SET_CONFIG, &tda9887_cfg); 3538 bttv_call_all(btv, tuner, s_config, &tda9887_cfg);
3704 } 3539 }
3705 3540
3706 btv->svhs = bttv_tvcards[btv->c.type].svhs; 3541 btv->dig = bttv_tvcards[btv->c.type].has_dig_in ?
3542 bttv_tvcards[btv->c.type].video_inputs - 1 : UNSET;
3543 btv->svhs = bttv_tvcards[btv->c.type].svhs == NO_SVHS ?
3544 UNSET : bttv_tvcards[btv->c.type].svhs;
3707 if (svhs[btv->c.nr] != UNSET) 3545 if (svhs[btv->c.nr] != UNSET)
3708 btv->svhs = svhs[btv->c.nr]; 3546 btv->svhs = svhs[btv->c.nr];
3709 if (remote[btv->c.nr] != UNSET) 3547 if (remote[btv->c.nr] != UNSET)
@@ -3720,34 +3558,127 @@ void __devinit bttv_init_card2(struct bttv *btv)
3720 if (bttv_tvcards[btv->c.type].audio_mode_gpio) 3558 if (bttv_tvcards[btv->c.type].audio_mode_gpio)
3721 btv->audio_mode_gpio=bttv_tvcards[btv->c.type].audio_mode_gpio; 3559 btv->audio_mode_gpio=bttv_tvcards[btv->c.type].audio_mode_gpio;
3722 3560
3723 if (!autoload) 3561 if (btv->tuner_type == TUNER_ABSENT)
3724 return;
3725
3726 if (bttv_tvcards[btv->c.type].tuner == UNSET)
3727 return; /* no tuner or related drivers to load */ 3562 return; /* no tuner or related drivers to load */
3728 3563
3564 if (btv->has_saa6588 || saa6588[btv->c.nr]) {
3565 /* Probe for RDS receiver chip */
3566 static const unsigned short addrs[] = {
3567 0x20 >> 1,
3568 0x22 >> 1,
3569 I2C_CLIENT_END
3570 };
3571 struct v4l2_subdev *sd;
3572
3573 sd = v4l2_i2c_new_probed_subdev(&btv->c.i2c_adap,
3574 "saa6588", "saa6588", addrs);
3575 btv->has_saa6588 = (sd != NULL);
3576 }
3577
3729 /* try to detect audio/fader chips */ 3578 /* try to detect audio/fader chips */
3730 if (!bttv_tvcards[btv->c.type].no_msp34xx &&
3731 bttv_I2CRead(btv, I2C_ADDR_MSP3400, "MSP34xx") >=0)
3732 request_module("msp3400");
3733 3579
3734 if (bttv_tvcards[btv->c.type].msp34xx_alt && 3580 /* First check if the user specified the audio chip via a module
3735 bttv_I2CRead(btv, I2C_ADDR_MSP3400_ALT, "MSP34xx (alternate address)") >=0) 3581 option. */
3736 request_module("msp3400"); 3582
3583 switch (audiodev[btv->c.nr]) {
3584 case -1:
3585 return; /* do not load any audio module */
3586
3587 case 0: /* autodetect */
3588 break;
3589
3590 case 1: {
3591 /* The user specified that we should probe for msp3400 */
3592 static const unsigned short addrs[] = {
3593 I2C_ADDR_MSP3400 >> 1,
3594 I2C_ADDR_MSP3400_ALT >> 1,
3595 I2C_CLIENT_END
3596 };
3597
3598 btv->sd_msp34xx = v4l2_i2c_new_probed_subdev(&btv->c.i2c_adap,
3599 "msp3400", "msp3400", addrs);
3600 if (btv->sd_msp34xx)
3601 return;
3602 goto no_audio;
3603 }
3604
3605 case 2: {
3606 /* The user specified that we should probe for tda7432 */
3607 static const unsigned short addrs[] = {
3608 I2C_ADDR_TDA7432 >> 1,
3609 I2C_CLIENT_END
3610 };
3611
3612 if (v4l2_i2c_new_probed_subdev(&btv->c.i2c_adap,
3613 "tda7432", "tda7432", addrs))
3614 return;
3615 goto no_audio;
3616 }
3617
3618 case 3: {
3619 /* The user specified that we should probe for tvaudio */
3620 btv->sd_tvaudio = v4l2_i2c_new_probed_subdev(&btv->c.i2c_adap,
3621 "tvaudio", "tvaudio", tvaudio_addrs);
3622 if (btv->sd_tvaudio)
3623 return;
3624 goto no_audio;
3625 }
3626
3627 default:
3628 printk(KERN_WARNING "bttv%d: unknown audiodev value!\n",
3629 btv->c.nr);
3630 return;
3631 }
3737 3632
3738 if (!bttv_tvcards[btv->c.type].no_tda9875 && 3633 /* There were no overrides, so now we try to discover this through the
3739 bttv_I2CRead(btv, I2C_ADDR_TDA9875, "TDA9875") >=0) 3634 card definition */
3740 request_module("tda9875"); 3635
3636 /* probe for msp3400 first: this driver can detect whether or not
3637 it really is a msp3400, so it will return NULL when the device
3638 found is really something else (e.g. a tea6300). */
3639 if (!bttv_tvcards[btv->c.type].no_msp34xx) {
3640 static const unsigned short addrs[] = {
3641 I2C_ADDR_MSP3400 >> 1,
3642 I2C_CLIENT_END
3643 };
3644
3645 btv->sd_msp34xx = v4l2_i2c_new_probed_subdev(&btv->c.i2c_adap,
3646 "msp3400", "msp3400", addrs);
3647 } else if (bttv_tvcards[btv->c.type].msp34xx_alt) {
3648 static const unsigned short addrs[] = {
3649 I2C_ADDR_MSP3400_ALT >> 1,
3650 I2C_CLIENT_END
3651 };
3652
3653 btv->sd_msp34xx = v4l2_i2c_new_probed_subdev(&btv->c.i2c_adap,
3654 "msp3400", "msp3400", addrs);
3655 }
3741 3656
3742 if (!bttv_tvcards[btv->c.type].no_tda7432 && 3657 /* If we found a msp34xx, then we're done. */
3743 bttv_I2CRead(btv, I2C_ADDR_TDA7432, "TDA7432") >=0) 3658 if (btv->sd_msp34xx)
3744 request_module("tda7432"); 3659 return;
3745 3660
3746 if (bttv_tvcards[btv->c.type].needs_tvaudio) 3661 /* it might also be a tda7432. */
3747 request_module("tvaudio"); 3662 if (!bttv_tvcards[btv->c.type].no_tda7432) {
3663 static const unsigned short addrs[] = {
3664 I2C_ADDR_TDA7432 >> 1,
3665 I2C_CLIENT_END
3666 };
3748 3667
3749 if (btv->tuner_type != UNSET && btv->tuner_type != TUNER_ABSENT) 3668 if (v4l2_i2c_new_probed_subdev(&btv->c.i2c_adap,
3750 request_module("tuner"); 3669 "tda7432", "tda7432", addrs))
3670 return;
3671 }
3672
3673 /* Now see if we can find one of the tvaudio devices. */
3674 btv->sd_tvaudio = v4l2_i2c_new_probed_subdev(&btv->c.i2c_adap,
3675 "tvaudio", "tvaudio", tvaudio_addrs);
3676 if (btv->sd_tvaudio)
3677 return;
3678
3679no_audio:
3680 printk(KERN_WARNING "bttv%d: audio absent, no audio device found!\n",
3681 btv->c.nr);
3751} 3682}
3752 3683
3753 3684
@@ -3819,6 +3750,7 @@ static int terratec_active_radio_upgrade(struct bttv *btv)
3819 printk("bttv%d: Terratec Active Radio Upgrade found.\n", 3750 printk("bttv%d: Terratec Active Radio Upgrade found.\n",
3820 btv->c.nr); 3751 btv->c.nr);
3821 btv->has_radio = 1; 3752 btv->has_radio = 1;
3753 btv->has_saa6588 = 1;
3822 btv->has_matchbox = 1; 3754 btv->has_matchbox = 1;
3823 } else { 3755 } else {
3824 btv->has_radio = 0; 3756 btv->has_radio = 0;
@@ -4067,27 +3999,26 @@ static void __devinit avermedia_eeprom(struct bttv *btv)
4067 btv->has_remote ? "yes" : "no"); 3999 btv->has_remote ? "yes" : "no");
4068} 4000}
4069 4001
4070/* used on Voodoo TV/FM (Voodoo 200), S0 wired to 0x10000 */ 4002/*
4071void bttv_tda9880_setnorm(struct bttv *btv, int norm) 4003 * For Voodoo TV/FM and Voodoo 200. These cards' tuners use a TDA9880
4004 * analog demod, which is not I2C controlled like the newer and more common
4005 * TDA9887 series. Instead is has two tri-state input pins, S0 and S1,
4006 * that control the IF for the video and audio. Apparently, bttv GPIO
4007 * 0x10000 is connected to S0. S0 low selects a 38.9 MHz VIF for B/G/D/K/I
4008 * (i.e., PAL) while high selects 45.75 MHz for M/N (i.e., NTSC).
4009 */
4010u32 bttv_tda9880_setnorm(struct bttv *btv, u32 gpiobits)
4072{ 4011{
4073 /* fix up our card entry */ 4012
4074 if(norm==V4L2_STD_NTSC) { 4013 if (btv->audio == TVAUDIO_INPUT_TUNER) {
4075 bttv_tvcards[BTTV_BOARD_VOODOOTV_FM].gpiomux[TVAUDIO_INPUT_TUNER]=0x957fff; 4014 if (bttv_tvnorms[btv->tvnorm].v4l2_id & V4L2_STD_MN)
4076 bttv_tvcards[BTTV_BOARD_VOODOOTV_FM].gpiomute=0x957fff; 4015 gpiobits |= 0x10000;
4077 bttv_tvcards[BTTV_BOARD_VOODOOTV_200].gpiomux[TVAUDIO_INPUT_TUNER]=0x957fff; 4016 else
4078 bttv_tvcards[BTTV_BOARD_VOODOOTV_200].gpiomute=0x957fff; 4017 gpiobits &= ~0x10000;
4079 dprintk("bttv_tda9880_setnorm to NTSC\n");
4080 }
4081 else {
4082 bttv_tvcards[BTTV_BOARD_VOODOOTV_FM].gpiomux[TVAUDIO_INPUT_TUNER]=0x947fff;
4083 bttv_tvcards[BTTV_BOARD_VOODOOTV_FM].gpiomute=0x947fff;
4084 bttv_tvcards[BTTV_BOARD_VOODOOTV_200].gpiomux[TVAUDIO_INPUT_TUNER]=0x947fff;
4085 bttv_tvcards[BTTV_BOARD_VOODOOTV_200].gpiomute=0x947fff;
4086 dprintk("bttv_tda9880_setnorm to PAL\n");
4087 } 4018 }
4088 /* set GPIO according */ 4019
4089 gpio_bits(bttv_tvcards[btv->c.type].gpiomask, 4020 gpio_bits(bttv_tvcards[btv->c.type].gpiomask, gpiobits);
4090 bttv_tvcards[btv->c.type].gpiomux[btv->audio]); 4021 return gpiobits;
4091} 4022}
4092 4023
4093 4024
@@ -4463,6 +4394,11 @@ void tea5757_set_freq(struct bttv *btv, unsigned short freq)
4463 */ 4394 */
4464static void rv605_muxsel(struct bttv *btv, unsigned int input) 4395static void rv605_muxsel(struct bttv *btv, unsigned int input)
4465{ 4396{
4397 static const u8 muxgpio[] = { 0x3, 0x1, 0x2, 0x4, 0xf, 0x7, 0xe, 0x0,
4398 0xd, 0xb, 0xc, 0x6, 0x9, 0x5, 0x8, 0xa };
4399
4400 gpio_bits(0x07f, muxgpio[input]);
4401
4466 /* reset all conections */ 4402 /* reset all conections */
4467 gpio_bits(0x200,0x200); 4403 gpio_bits(0x200,0x200);
4468 mdelay(1); 4404 mdelay(1);
@@ -4470,7 +4406,6 @@ static void rv605_muxsel(struct bttv *btv, unsigned int input)
4470 mdelay(1); 4406 mdelay(1);
4471 4407
4472 /* create a new connection */ 4408 /* create a new connection */
4473 gpio_bits(0x480,0x080);
4474 gpio_bits(0x480,0x480); 4409 gpio_bits(0x480,0x480);
4475 mdelay(1); 4410 mdelay(1);
4476 gpio_bits(0x480,0x080); 4411 gpio_bits(0x480,0x080);
@@ -4729,8 +4664,7 @@ static void ivc120_muxsel(struct bttv *btv, unsigned int input)
4729 bttv_I2CWrite(btv, I2C_TDA8540_ALT6, 0x02, 4664 bttv_I2CWrite(btv, I2C_TDA8540_ALT6, 0x02,
4730 ((matrix == 2) ? 0x03 : 0x00), 1); /* 9-12 */ 4665 ((matrix == 2) ? 0x03 : 0x00), 1); /* 9-12 */
4731 4666
4732 /* Selects MUX0 for input on the 878 */ 4667 /* 878's MUX0 is already selected for input via muxsel values */
4733 btaor((0)<<5, ~(3<<5), BT848_IFORM);
4734} 4668}
4735 4669
4736 4670
@@ -4814,6 +4748,132 @@ static void PXC200_muxsel(struct bttv *btv, unsigned int input)
4814 printk(KERN_DEBUG "bttv%d: setting input channel to:%d\n", btv->c.nr,(int)mux); 4748 printk(KERN_DEBUG "bttv%d: setting input channel to:%d\n", btv->c.nr,(int)mux);
4815} 4749}
4816 4750
4751static void phytec_muxsel(struct bttv *btv, unsigned int input)
4752{
4753 unsigned int mux = input % 4;
4754
4755 if (input == btv->svhs)
4756 mux = 0;
4757
4758 gpio_bits(0x3, mux);
4759}
4760
4761/*
4762 * GeoVision GV-800(S) functions
4763 * Bruno Christo <bchristo@inf.ufsm.br>
4764*/
4765
4766/* This is a function to control the analog switch, which determines which
4767 * camera is routed to which controller. The switch comprises an X-address
4768 * (gpio bits 0-3, representing the camera, ranging from 0-15), and a
4769 * Y-address (gpio bits 4-6, representing the controller, ranging from 0-3).
4770 * A data value (gpio bit 18) of '1' enables the switch, and '0' disables
4771 * the switch. A STROBE bit (gpio bit 17) latches the data value into the
4772 * specified address. There is also a chip select (gpio bit 16).
4773 * The idea is to set the address and chip select together, bring
4774 * STROBE high, write the data, and finally bring STROBE back to low.
4775 */
4776static void gv800s_write(struct bttv *btv,
4777 unsigned char xaddr,
4778 unsigned char yaddr,
4779 unsigned char data) {
4780 /* On the "master" 878A:
4781 * GPIO bits 0-9 are used for the analog switch:
4782 * 00 - 03: camera selector
4783 * 04 - 06: 878A (controller) selector
4784 * 16: cselect
4785 * 17: strobe
4786 * 18: data (1->on, 0->off)
4787 * 19: reset
4788 */
4789 const u32 ADDRESS = ((xaddr&0xf) | (yaddr&3)<<4);
4790 const u32 CSELECT = 1<<16;
4791 const u32 STROBE = 1<<17;
4792 const u32 DATA = data<<18;
4793
4794 gpio_bits(0x1007f, ADDRESS | CSELECT); /* write ADDRESS and CSELECT */
4795 gpio_bits(0x20000, STROBE); /* STROBE high */
4796 gpio_bits(0x40000, DATA); /* write DATA */
4797 gpio_bits(0x20000, ~STROBE); /* STROBE low */
4798}
4799
4800/*
4801 * GeoVision GV-800(S) muxsel
4802 *
4803 * Each of the 4 cards (controllers) use this function.
4804 * The controller using this function selects the input through the GPIO pins
4805 * of the "master" card. A pointer to this card is stored in master[btv->c.nr].
4806 *
4807 * The parameter 'input' is the requested camera number (0-4) on the controller.
4808 * The map array has the address of each input. Note that the addresses in the
4809 * array are in the sequence the original GeoVision driver uses, that is, set
4810 * every controller to input 0, then to input 1, 2, 3, repeat. This means that
4811 * the physical "camera 1" connector corresponds to controller 0 input 0,
4812 * "camera 2" corresponds to controller 1 input 0, and so on.
4813 *
4814 * After getting the input address, the function then writes the appropriate
4815 * data to the analog switch, and housekeeps the local copy of the switch
4816 * information.
4817 */
4818static void gv800s_muxsel(struct bttv *btv, unsigned int input)
4819{
4820 struct bttv *mctlr;
4821 char *sw_status;
4822 int xaddr, yaddr;
4823 static unsigned int map[4][4] = { { 0x0, 0x4, 0xa, 0x6 },
4824 { 0x1, 0x5, 0xb, 0x7 },
4825 { 0x2, 0x8, 0xc, 0xe },
4826 { 0x3, 0x9, 0xd, 0xf } };
4827 input = input%4;
4828 mctlr = master[btv->c.nr];
4829 if (mctlr == NULL) {
4830 /* do nothing until the "master" is detected */
4831 return;
4832 }
4833 yaddr = (btv->c.nr - mctlr->c.nr) & 3;
4834 sw_status = (char *)(&mctlr->mbox_we);
4835 xaddr = map[yaddr][input] & 0xf;
4836
4837 /* Check if the controller/camera pair has changed, ignore otherwise */
4838 if (sw_status[yaddr] != xaddr) {
4839 /* disable the old switch, enable the new one and save status */
4840 gv800s_write(mctlr, sw_status[yaddr], yaddr, 0);
4841 sw_status[yaddr] = xaddr;
4842 gv800s_write(mctlr, xaddr, yaddr, 1);
4843 }
4844}
4845
4846/* GeoVision GV-800(S) "master" chip init */
4847static void gv800s_init(struct bttv *btv)
4848{
4849 char *sw_status = (char *)(&btv->mbox_we);
4850 int ix;
4851
4852 gpio_inout(0xf107f, 0xf107f);
4853 gpio_write(1<<19); /* reset the analog MUX */
4854 gpio_write(0);
4855
4856 /* Preset camera 0 to the 4 controllers */
4857 for (ix = 0; ix < 4; ix++) {
4858 sw_status[ix] = ix;
4859 gv800s_write(btv, ix, ix, 1);
4860 }
4861
4862 /* Inputs on the "master" controller need this brightness fix */
4863 bttv_I2CWrite(btv, 0x18, 0x5, 0x90, 1);
4864
4865 if (btv->c.nr > BTTV_MAX-4)
4866 return;
4867 /*
4868 * Store the "master" controller pointer in the master
4869 * array for later use in the muxsel function.
4870 */
4871 master[btv->c.nr] = btv;
4872 master[btv->c.nr+1] = btv;
4873 master[btv->c.nr+2] = btv;
4874 master[btv->c.nr+3] = btv;
4875}
4876
4817/* ----------------------------------------------------------------------- */ 4877/* ----------------------------------------------------------------------- */
4818/* motherboard chipset specific stuff */ 4878/* motherboard chipset specific stuff */
4819 4879
diff --git a/drivers/media/video/bt8xx/bttv-driver.c b/drivers/media/video/bt8xx/bttv-driver.c
index c71f394fc0ea..7a8ca0d8356f 100644
--- a/drivers/media/video/bt8xx/bttv-driver.c
+++ b/drivers/media/video/bt8xx/bttv-driver.c
@@ -58,7 +58,7 @@
58 58
59 59
60unsigned int bttv_num; /* number of Bt848s in use */ 60unsigned int bttv_num; /* number of Bt848s in use */
61struct bttv bttvs[BTTV_MAX]; 61struct bttv *bttvs[BTTV_MAX];
62 62
63unsigned int bttv_debug; 63unsigned int bttv_debug;
64unsigned int bttv_verbose = 1; 64unsigned int bttv_verbose = 1;
@@ -167,7 +167,7 @@ static ssize_t show_card(struct device *cd,
167 struct device_attribute *attr, char *buf) 167 struct device_attribute *attr, char *buf)
168{ 168{
169 struct video_device *vfd = container_of(cd, struct video_device, dev); 169 struct video_device *vfd = container_of(cd, struct video_device, dev);
170 struct bttv *btv = dev_get_drvdata(vfd->parent); 170 struct bttv *btv = video_get_drvdata(vfd);
171 return sprintf(buf, "%d\n", btv ? btv->c.type : UNSET); 171 return sprintf(buf, "%d\n", btv ? btv->c.type : UNSET);
172} 172}
173static DEVICE_ATTR(card, S_IRUGO, show_card, NULL); 173static DEVICE_ATTR(card, S_IRUGO, show_card, NULL);
@@ -1040,7 +1040,7 @@ static void bt848A_set_timing(struct bttv *btv)
1040 int table_idx = bttv_tvnorms[btv->tvnorm].sram; 1040 int table_idx = bttv_tvnorms[btv->tvnorm].sram;
1041 int fsc = bttv_tvnorms[btv->tvnorm].Fsc; 1041 int fsc = bttv_tvnorms[btv->tvnorm].Fsc;
1042 1042
1043 if (UNSET == bttv_tvcards[btv->c.type].muxsel[btv->input]) { 1043 if (btv->input == btv->dig) {
1044 dprintk("bttv%d: load digital timing table (table_idx=%d)\n", 1044 dprintk("bttv%d: load digital timing table (table_idx=%d)\n",
1045 btv->c.nr,table_idx); 1045 btv->c.nr,table_idx);
1046 1046
@@ -1142,7 +1142,7 @@ video_mux(struct bttv *btv, unsigned int input)
1142 btand(~BT848_CONTROL_COMP, BT848_E_CONTROL); 1142 btand(~BT848_CONTROL_COMP, BT848_E_CONTROL);
1143 btand(~BT848_CONTROL_COMP, BT848_O_CONTROL); 1143 btand(~BT848_CONTROL_COMP, BT848_O_CONTROL);
1144 } 1144 }
1145 mux = bttv_tvcards[btv->c.type].muxsel[input] & 3; 1145 mux = bttv_muxsel(btv, input);
1146 btaor(mux<<5, ~(3<<5), BT848_IFORM); 1146 btaor(mux<<5, ~(3<<5), BT848_IFORM);
1147 dprintk(KERN_DEBUG "bttv%d: video mux: input=%d mux=%d\n", 1147 dprintk(KERN_DEBUG "bttv%d: video mux: input=%d mux=%d\n",
1148 btv->c.nr,input,mux); 1148 btv->c.nr,input,mux);
@@ -1163,7 +1163,6 @@ audio_mux(struct bttv *btv, int input, int mute)
1163{ 1163{
1164 int gpio_val, signal; 1164 int gpio_val, signal;
1165 struct v4l2_control ctrl; 1165 struct v4l2_control ctrl;
1166 struct i2c_client *c;
1167 1166
1168 gpio_inout(bttv_tvcards[btv->c.type].gpiomask, 1167 gpio_inout(bttv_tvcards[btv->c.type].gpiomask,
1169 bttv_tvcards[btv->c.type].gpiomask); 1168 bttv_tvcards[btv->c.type].gpiomask);
@@ -1180,7 +1179,16 @@ audio_mux(struct bttv *btv, int input, int mute)
1180 else 1179 else
1181 gpio_val = bttv_tvcards[btv->c.type].gpiomux[input]; 1180 gpio_val = bttv_tvcards[btv->c.type].gpiomux[input];
1182 1181
1183 gpio_bits(bttv_tvcards[btv->c.type].gpiomask, gpio_val); 1182 switch (btv->c.type) {
1183 case BTTV_BOARD_VOODOOTV_FM:
1184 case BTTV_BOARD_VOODOOTV_200:
1185 gpio_val = bttv_tda9880_setnorm(btv, gpio_val);
1186 break;
1187
1188 default:
1189 gpio_bits(bttv_tvcards[btv->c.type].gpiomask, gpio_val);
1190 }
1191
1184 if (bttv_gpio) 1192 if (bttv_gpio)
1185 bttv_gpio_tracking(btv, audio_modes[mute ? 4 : input]); 1193 bttv_gpio_tracking(btv, audio_modes[mute ? 4 : input]);
1186 if (in_interrupt()) 1194 if (in_interrupt())
@@ -1188,9 +1196,8 @@ audio_mux(struct bttv *btv, int input, int mute)
1188 1196
1189 ctrl.id = V4L2_CID_AUDIO_MUTE; 1197 ctrl.id = V4L2_CID_AUDIO_MUTE;
1190 ctrl.value = btv->mute; 1198 ctrl.value = btv->mute;
1191 bttv_call_i2c_clients(btv, VIDIOC_S_CTRL, &ctrl); 1199 bttv_call_all(btv, core, s_ctrl, &ctrl);
1192 c = btv->i2c_msp34xx_client; 1200 if (btv->sd_msp34xx) {
1193 if (c) {
1194 struct v4l2_routing route; 1201 struct v4l2_routing route;
1195 1202
1196 /* Note: the inputs tuner/radio/extern/intern are translated 1203 /* Note: the inputs tuner/radio/extern/intern are translated
@@ -1229,15 +1236,14 @@ audio_mux(struct bttv *btv, int input, int mute)
1229 break; 1236 break;
1230 } 1237 }
1231 route.output = MSP_OUTPUT_DEFAULT; 1238 route.output = MSP_OUTPUT_DEFAULT;
1232 c->driver->command(c, VIDIOC_INT_S_AUDIO_ROUTING, &route); 1239 v4l2_subdev_call(btv->sd_msp34xx, audio, s_routing, &route);
1233 } 1240 }
1234 c = btv->i2c_tvaudio_client; 1241 if (btv->sd_tvaudio) {
1235 if (c) {
1236 struct v4l2_routing route; 1242 struct v4l2_routing route;
1237 1243
1238 route.input = input; 1244 route.input = input;
1239 route.output = 0; 1245 route.output = 0;
1240 c->driver->command(c, VIDIOC_INT_S_AUDIO_ROUTING, &route); 1246 v4l2_subdev_call(btv->sd_tvaudio, audio, s_routing, &route);
1241 } 1247 }
1242 return 0; 1248 return 0;
1243} 1249}
@@ -1277,7 +1283,7 @@ bttv_crop_calc_limits(struct bttv_crop *c)
1277} 1283}
1278 1284
1279static void 1285static void
1280bttv_crop_reset(struct bttv_crop *c, int norm) 1286bttv_crop_reset(struct bttv_crop *c, unsigned int norm)
1281{ 1287{
1282 c->rect = bttv_tvnorms[norm].cropcap.defrect; 1288 c->rect = bttv_tvnorms[norm].cropcap.defrect;
1283 bttv_crop_calc_limits(c); 1289 bttv_crop_calc_limits(c);
@@ -1290,16 +1296,13 @@ set_tvnorm(struct bttv *btv, unsigned int norm)
1290 const struct bttv_tvnorm *tvnorm; 1296 const struct bttv_tvnorm *tvnorm;
1291 v4l2_std_id id; 1297 v4l2_std_id id;
1292 1298
1293 if (norm < 0 || norm >= BTTV_TVNORMS) 1299 BUG_ON(norm >= BTTV_TVNORMS);
1294 return -EINVAL; 1300 BUG_ON(btv->tvnorm >= BTTV_TVNORMS);
1295 1301
1296 tvnorm = &bttv_tvnorms[norm]; 1302 tvnorm = &bttv_tvnorms[norm];
1297 1303
1298 if (btv->tvnorm < 0 || 1304 if (!memcmp(&bttv_tvnorms[btv->tvnorm].cropcap, &tvnorm->cropcap,
1299 btv->tvnorm >= BTTV_TVNORMS || 1305 sizeof (tvnorm->cropcap))) {
1300 0 != memcmp(&bttv_tvnorms[btv->tvnorm].cropcap,
1301 &tvnorm->cropcap,
1302 sizeof (tvnorm->cropcap))) {
1303 bttv_crop_reset(&btv->crop[0], norm); 1306 bttv_crop_reset(&btv->crop[0], norm);
1304 btv->crop[1] = btv->crop[0]; /* current = default */ 1307 btv->crop[1] = btv->crop[0]; /* current = default */
1305 1308
@@ -1322,11 +1325,11 @@ set_tvnorm(struct bttv *btv, unsigned int norm)
1322 switch (btv->c.type) { 1325 switch (btv->c.type) {
1323 case BTTV_BOARD_VOODOOTV_FM: 1326 case BTTV_BOARD_VOODOOTV_FM:
1324 case BTTV_BOARD_VOODOOTV_200: 1327 case BTTV_BOARD_VOODOOTV_200:
1325 bttv_tda9880_setnorm(btv,norm); 1328 bttv_tda9880_setnorm(btv, gpio_read());
1326 break; 1329 break;
1327 } 1330 }
1328 id = tvnorm->v4l2_id; 1331 id = tvnorm->v4l2_id;
1329 bttv_call_i2c_clients(btv, VIDIOC_S_STD, &id); 1332 bttv_call_all(btv, tuner, s_std, id);
1330 1333
1331 return 0; 1334 return 0;
1332} 1335}
@@ -1350,8 +1353,8 @@ set_input(struct bttv *btv, unsigned int input, unsigned int norm)
1350 } else { 1353 } else {
1351 video_mux(btv,input); 1354 video_mux(btv,input);
1352 } 1355 }
1353 audio_input(btv,(input == bttv_tvcards[btv->c.type].tuner ? 1356 audio_input(btv, (btv->tuner_type != TUNER_ABSENT && input == 0) ?
1354 TVAUDIO_INPUT_TUNER : TVAUDIO_INPUT_EXTERN)); 1357 TVAUDIO_INPUT_TUNER : TVAUDIO_INPUT_EXTERN);
1355 set_tvnorm(btv, norm); 1358 set_tvnorm(btv, norm);
1356} 1359}
1357 1360
@@ -1470,7 +1473,7 @@ static int bttv_g_ctrl(struct file *file, void *priv,
1470 case V4L2_CID_AUDIO_BALANCE: 1473 case V4L2_CID_AUDIO_BALANCE:
1471 case V4L2_CID_AUDIO_BASS: 1474 case V4L2_CID_AUDIO_BASS:
1472 case V4L2_CID_AUDIO_TREBLE: 1475 case V4L2_CID_AUDIO_TREBLE:
1473 bttv_call_i2c_clients(btv, VIDIOC_G_CTRL, c); 1476 bttv_call_all(btv, core, g_ctrl, c);
1474 break; 1477 break;
1475 1478
1476 case V4L2_CID_PRIVATE_CHROMA_AGC: 1479 case V4L2_CID_PRIVATE_CHROMA_AGC:
@@ -1544,12 +1547,12 @@ static int bttv_s_ctrl(struct file *file, void *f,
1544 if (btv->volume_gpio) 1547 if (btv->volume_gpio)
1545 btv->volume_gpio(btv, c->value); 1548 btv->volume_gpio(btv, c->value);
1546 1549
1547 bttv_call_i2c_clients(btv, VIDIOC_S_CTRL, c); 1550 bttv_call_all(btv, core, s_ctrl, c);
1548 break; 1551 break;
1549 case V4L2_CID_AUDIO_BALANCE: 1552 case V4L2_CID_AUDIO_BALANCE:
1550 case V4L2_CID_AUDIO_BASS: 1553 case V4L2_CID_AUDIO_BASS:
1551 case V4L2_CID_AUDIO_TREBLE: 1554 case V4L2_CID_AUDIO_TREBLE:
1552 bttv_call_i2c_clients(btv, VIDIOC_S_CTRL, c); 1555 bttv_call_all(btv, core, s_ctrl, c);
1553 break; 1556 break;
1554 1557
1555 case V4L2_CID_PRIVATE_CHROMA_AGC: 1558 case V4L2_CID_PRIVATE_CHROMA_AGC:
@@ -1888,20 +1891,15 @@ static int bttv_enum_input(struct file *file, void *priv,
1888{ 1891{
1889 struct bttv_fh *fh = priv; 1892 struct bttv_fh *fh = priv;
1890 struct bttv *btv = fh->btv; 1893 struct bttv *btv = fh->btv;
1891 unsigned int n; 1894 int n;
1892
1893 n = i->index;
1894 1895
1895 if (n >= bttv_tvcards[btv->c.type].video_inputs) 1896 if (i->index >= bttv_tvcards[btv->c.type].video_inputs)
1896 return -EINVAL; 1897 return -EINVAL;
1897 1898
1898 memset(i, 0, sizeof(*i));
1899
1900 i->index = n;
1901 i->type = V4L2_INPUT_TYPE_CAMERA; 1899 i->type = V4L2_INPUT_TYPE_CAMERA;
1902 i->audioset = 1; 1900 i->audioset = 1;
1903 1901
1904 if (i->index == bttv_tvcards[btv->c.type].tuner) { 1902 if (btv->tuner_type != TUNER_ABSENT && i->index == 0) {
1905 sprintf(i->name, "Television"); 1903 sprintf(i->name, "Television");
1906 i->type = V4L2_INPUT_TYPE_TUNER; 1904 i->type = V4L2_INPUT_TYPE_TUNER;
1907 i->tuner = 0; 1905 i->tuner = 0;
@@ -1965,14 +1963,14 @@ static int bttv_s_tuner(struct file *file, void *priv,
1965 if (0 != err) 1963 if (0 != err)
1966 return err; 1964 return err;
1967 1965
1968 if (UNSET == bttv_tvcards[btv->c.type].tuner) 1966 if (btv->tuner_type == TUNER_ABSENT)
1969 return -EINVAL; 1967 return -EINVAL;
1970 1968
1971 if (0 != t->index) 1969 if (0 != t->index)
1972 return -EINVAL; 1970 return -EINVAL;
1973 1971
1974 mutex_lock(&btv->lock); 1972 mutex_lock(&btv->lock);
1975 bttv_call_i2c_clients(btv, VIDIOC_S_TUNER, t); 1973 bttv_call_all(btv, tuner, s_tuner, t);
1976 1974
1977 if (btv->audio_mode_gpio) 1975 if (btv->audio_mode_gpio)
1978 btv->audio_mode_gpio(btv, t, 1); 1976 btv->audio_mode_gpio(btv, t, 1);
@@ -2017,7 +2015,7 @@ static int bttv_s_frequency(struct file *file, void *priv,
2017 return -EINVAL; 2015 return -EINVAL;
2018 mutex_lock(&btv->lock); 2016 mutex_lock(&btv->lock);
2019 btv->freq = f->frequency; 2017 btv->freq = f->frequency;
2020 bttv_call_i2c_clients(btv, VIDIOC_S_FREQUENCY, f); 2018 bttv_call_all(btv, tuner, s_frequency, f);
2021 if (btv->has_matchbox && btv->radio_user) 2019 if (btv->has_matchbox && btv->radio_user)
2022 tea5757_set_freq(btv, btv->freq); 2020 tea5757_set_freq(btv, btv->freq);
2023 mutex_unlock(&btv->lock); 2021 mutex_unlock(&btv->lock);
@@ -2031,7 +2029,7 @@ static int bttv_log_status(struct file *file, void *f)
2031 2029
2032 printk(KERN_INFO "bttv%d: ======== START STATUS CARD #%d ========\n", 2030 printk(KERN_INFO "bttv%d: ======== START STATUS CARD #%d ========\n",
2033 btv->c.nr, btv->c.nr); 2031 btv->c.nr, btv->c.nr);
2034 bttv_call_i2c_clients(btv, VIDIOC_LOG_STATUS, NULL); 2032 bttv_call_all(btv, core, log_status);
2035 printk(KERN_INFO "bttv%d: ======== END STATUS CARD #%d ========\n", 2033 printk(KERN_INFO "bttv%d: ======== END STATUS CARD #%d ========\n",
2036 btv->c.nr, btv->c.nr); 2034 btv->c.nr, btv->c.nr);
2037 return 0; 2035 return 0;
@@ -2659,8 +2657,7 @@ static int bttv_querycap(struct file *file, void *priv,
2659 if (no_overlay <= 0) 2657 if (no_overlay <= 0)
2660 cap->capabilities |= V4L2_CAP_VIDEO_OVERLAY; 2658 cap->capabilities |= V4L2_CAP_VIDEO_OVERLAY;
2661 2659
2662 if (bttv_tvcards[btv->c.type].tuner != UNSET && 2660 if (btv->tuner_type != TUNER_ABSENT)
2663 bttv_tvcards[btv->c.type].tuner != TUNER_ABSENT)
2664 cap->capabilities |= V4L2_CAP_TUNER; 2661 cap->capabilities |= V4L2_CAP_TUNER;
2665 return 0; 2662 return 0;
2666} 2663}
@@ -2927,13 +2924,9 @@ static int bttv_g_parm(struct file *file, void *f,
2927{ 2924{
2928 struct bttv_fh *fh = f; 2925 struct bttv_fh *fh = f;
2929 struct bttv *btv = fh->btv; 2926 struct bttv *btv = fh->btv;
2930 struct v4l2_standard s;
2931 2927
2932 if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 2928 v4l2_video_std_frame_period(bttv_tvnorms[btv->tvnorm].v4l2_id,
2933 return -EINVAL; 2929 &parm->parm.capture.timeperframe);
2934 v4l2_video_std_construct(&s, bttv_tvnorms[btv->tvnorm].v4l2_id,
2935 bttv_tvnorms[btv->tvnorm].name);
2936 parm->parm.capture.timeperframe = s.frameperiod;
2937 return 0; 2930 return 0;
2938} 2931}
2939 2932
@@ -2943,15 +2936,14 @@ static int bttv_g_tuner(struct file *file, void *priv,
2943 struct bttv_fh *fh = priv; 2936 struct bttv_fh *fh = priv;
2944 struct bttv *btv = fh->btv; 2937 struct bttv *btv = fh->btv;
2945 2938
2946 if (UNSET == bttv_tvcards[btv->c.type].tuner) 2939 if (btv->tuner_type == TUNER_ABSENT)
2947 return -EINVAL; 2940 return -EINVAL;
2948 if (0 != t->index) 2941 if (0 != t->index)
2949 return -EINVAL; 2942 return -EINVAL;
2950 2943
2951 mutex_lock(&btv->lock); 2944 mutex_lock(&btv->lock);
2952 memset(t, 0, sizeof(*t));
2953 t->rxsubchans = V4L2_TUNER_SUB_MONO; 2945 t->rxsubchans = V4L2_TUNER_SUB_MONO;
2954 bttv_call_i2c_clients(btv, VIDIOC_G_TUNER, t); 2946 bttv_call_all(btv, tuner, g_tuner, t);
2955 strcpy(t->name, "Television"); 2947 strcpy(t->name, "Television");
2956 t->capability = V4L2_TUNER_CAP_NORM; 2948 t->capability = V4L2_TUNER_CAP_NORM;
2957 t->type = V4L2_TUNER_ANALOG_TV; 2949 t->type = V4L2_TUNER_ANALOG_TV;
@@ -3212,29 +3204,19 @@ err:
3212static int bttv_open(struct file *file) 3204static int bttv_open(struct file *file)
3213{ 3205{
3214 int minor = video_devdata(file)->minor; 3206 int minor = video_devdata(file)->minor;
3215 struct bttv *btv = NULL; 3207 struct bttv *btv = video_drvdata(file);
3216 struct bttv_fh *fh; 3208 struct bttv_fh *fh;
3217 enum v4l2_buf_type type = 0; 3209 enum v4l2_buf_type type = 0;
3218 unsigned int i;
3219 3210
3220 dprintk(KERN_DEBUG "bttv: open minor=%d\n",minor); 3211 dprintk(KERN_DEBUG "bttv: open minor=%d\n",minor);
3221 3212
3222 lock_kernel(); 3213 lock_kernel();
3223 for (i = 0; i < bttv_num; i++) { 3214 if (btv->video_dev->minor == minor) {
3224 if (bttvs[i].video_dev && 3215 type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
3225 bttvs[i].video_dev->minor == minor) { 3216 } else if (btv->vbi_dev->minor == minor) {
3226 btv = &bttvs[i]; 3217 type = V4L2_BUF_TYPE_VBI_CAPTURE;
3227 type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 3218 } else {
3228 break; 3219 WARN_ON(1);
3229 }
3230 if (bttvs[i].vbi_dev &&
3231 bttvs[i].vbi_dev->minor == minor) {
3232 btv = &bttvs[i];
3233 type = V4L2_BUF_TYPE_VBI_CAPTURE;
3234 break;
3235 }
3236 }
3237 if (NULL == btv) {
3238 unlock_kernel(); 3220 unlock_kernel();
3239 return -ENODEV; 3221 return -ENODEV;
3240 } 3222 }
@@ -3424,20 +3406,14 @@ static struct video_device bttv_video_template = {
3424static int radio_open(struct file *file) 3406static int radio_open(struct file *file)
3425{ 3407{
3426 int minor = video_devdata(file)->minor; 3408 int minor = video_devdata(file)->minor;
3427 struct bttv *btv = NULL; 3409 struct bttv *btv = video_drvdata(file);
3428 struct bttv_fh *fh; 3410 struct bttv_fh *fh;
3429 unsigned int i;
3430 3411
3431 dprintk("bttv: open minor=%d\n",minor); 3412 dprintk("bttv: open minor=%d\n",minor);
3432 3413
3433 lock_kernel(); 3414 lock_kernel();
3434 for (i = 0; i < bttv_num; i++) { 3415 WARN_ON(btv->radio_dev && btv->radio_dev->minor != minor);
3435 if (bttvs[i].radio_dev && bttvs[i].radio_dev->minor == minor) { 3416 if (!btv->radio_dev || btv->radio_dev->minor != minor) {
3436 btv = &bttvs[i];
3437 break;
3438 }
3439 }
3440 if (NULL == btv) {
3441 unlock_kernel(); 3417 unlock_kernel();
3442 return -ENODEV; 3418 return -ENODEV;
3443 } 3419 }
@@ -3458,7 +3434,7 @@ static int radio_open(struct file *file)
3458 3434
3459 btv->radio_user++; 3435 btv->radio_user++;
3460 3436
3461 bttv_call_i2c_clients(btv,AUDC_SET_RADIO,NULL); 3437 bttv_call_all(btv, tuner, s_radio);
3462 audio_input(btv,TVAUDIO_INPUT_RADIO); 3438 audio_input(btv,TVAUDIO_INPUT_RADIO);
3463 3439
3464 mutex_unlock(&btv->lock); 3440 mutex_unlock(&btv->lock);
@@ -3478,7 +3454,7 @@ static int radio_release(struct file *file)
3478 3454
3479 btv->radio_user--; 3455 btv->radio_user--;
3480 3456
3481 bttv_call_i2c_clients(btv, RDS_CMD_CLOSE, &cmd); 3457 bttv_call_all(btv, core, ioctl, RDS_CMD_CLOSE, &cmd);
3482 3458
3483 return 0; 3459 return 0;
3484} 3460}
@@ -3503,16 +3479,15 @@ static int radio_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
3503 struct bttv_fh *fh = priv; 3479 struct bttv_fh *fh = priv;
3504 struct bttv *btv = fh->btv; 3480 struct bttv *btv = fh->btv;
3505 3481
3506 if (UNSET == bttv_tvcards[btv->c.type].tuner) 3482 if (btv->tuner_type == TUNER_ABSENT)
3507 return -EINVAL; 3483 return -EINVAL;
3508 if (0 != t->index) 3484 if (0 != t->index)
3509 return -EINVAL; 3485 return -EINVAL;
3510 mutex_lock(&btv->lock); 3486 mutex_lock(&btv->lock);
3511 memset(t, 0, sizeof(*t));
3512 strcpy(t->name, "Radio"); 3487 strcpy(t->name, "Radio");
3513 t->type = V4L2_TUNER_RADIO; 3488 t->type = V4L2_TUNER_RADIO;
3514 3489
3515 bttv_call_i2c_clients(btv, VIDIOC_G_TUNER, t); 3490 bttv_call_all(btv, tuner, g_tuner, t);
3516 3491
3517 if (btv->audio_mode_gpio) 3492 if (btv->audio_mode_gpio)
3518 btv->audio_mode_gpio(btv, t, 0); 3493 btv->audio_mode_gpio(btv, t, 0);
@@ -3554,7 +3529,7 @@ static int radio_s_tuner(struct file *file, void *priv,
3554 if (0 != t->index) 3529 if (0 != t->index)
3555 return -EINVAL; 3530 return -EINVAL;
3556 3531
3557 bttv_call_i2c_clients(btv, VIDIOC_G_TUNER, t); 3532 bttv_call_all(btv, tuner, g_tuner, t);
3558 return 0; 3533 return 0;
3559} 3534}
3560 3535
@@ -3615,7 +3590,7 @@ static ssize_t radio_read(struct file *file, char __user *data,
3615 cmd.instance = file; 3590 cmd.instance = file;
3616 cmd.result = -ENODEV; 3591 cmd.result = -ENODEV;
3617 3592
3618 bttv_call_i2c_clients(btv, RDS_CMD_READ, &cmd); 3593 bttv_call_all(btv, core, ioctl, RDS_CMD_READ, &cmd);
3619 3594
3620 return cmd.result; 3595 return cmd.result;
3621} 3596}
@@ -3628,7 +3603,7 @@ static unsigned int radio_poll(struct file *file, poll_table *wait)
3628 cmd.instance = file; 3603 cmd.instance = file;
3629 cmd.event_list = wait; 3604 cmd.event_list = wait;
3630 cmd.result = -ENODEV; 3605 cmd.result = -ENODEV;
3631 bttv_call_i2c_clients(btv, RDS_CMD_POLL, &cmd); 3606 bttv_call_all(btv, core, ioctl, RDS_CMD_POLL, &cmd);
3632 3607
3633 return cmd.result; 3608 return cmd.result;
3634} 3609}
@@ -3712,14 +3687,14 @@ static void bttv_risc_disasm(struct bttv *btv,
3712 unsigned int i,j,n; 3687 unsigned int i,j,n;
3713 3688
3714 printk("%s: risc disasm: %p [dma=0x%08lx]\n", 3689 printk("%s: risc disasm: %p [dma=0x%08lx]\n",
3715 btv->c.name, risc->cpu, (unsigned long)risc->dma); 3690 btv->c.v4l2_dev.name, risc->cpu, (unsigned long)risc->dma);
3716 for (i = 0; i < (risc->size >> 2); i += n) { 3691 for (i = 0; i < (risc->size >> 2); i += n) {
3717 printk("%s: 0x%lx: ", btv->c.name, 3692 printk("%s: 0x%lx: ", btv->c.v4l2_dev.name,
3718 (unsigned long)(risc->dma + (i<<2))); 3693 (unsigned long)(risc->dma + (i<<2)));
3719 n = bttv_risc_decode(le32_to_cpu(risc->cpu[i])); 3694 n = bttv_risc_decode(le32_to_cpu(risc->cpu[i]));
3720 for (j = 1; j < n; j++) 3695 for (j = 1; j < n; j++)
3721 printk("%s: 0x%lx: 0x%08x [ arg #%d ]\n", 3696 printk("%s: 0x%lx: 0x%08x [ arg #%d ]\n",
3722 btv->c.name, (unsigned long)(risc->dma + ((i+j)<<2)), 3697 btv->c.v4l2_dev.name, (unsigned long)(risc->dma + ((i+j)<<2)),
3723 risc->cpu[i+j], j); 3698 risc->cpu[i+j], j);
3724 if (0 == risc->cpu[i]) 3699 if (0 == risc->cpu[i])
3725 break; 3700 break;
@@ -4195,9 +4170,10 @@ static struct video_device *vdev_init(struct bttv *btv,
4195 return NULL; 4170 return NULL;
4196 *vfd = *template; 4171 *vfd = *template;
4197 vfd->minor = -1; 4172 vfd->minor = -1;
4198 vfd->parent = &btv->c.pci->dev; 4173 vfd->v4l2_dev = &btv->c.v4l2_dev;
4199 vfd->release = video_device_release; 4174 vfd->release = video_device_release;
4200 vfd->debug = bttv_debug; 4175 vfd->debug = bttv_debug;
4176 video_set_drvdata(vfd, btv);
4201 snprintf(vfd->name, sizeof(vfd->name), "BT%d%s %s (%s)", 4177 snprintf(vfd->name, sizeof(vfd->name), "BT%d%s %s (%s)",
4202 btv->id, (btv->id==848 && btv->revision==0x12) ? "A" : "", 4178 btv->id, (btv->id==848 && btv->revision==0x12) ? "A" : "",
4203 type_name, bttv_tvcards[btv->c.type].name); 4179 type_name, bttv_tvcards[btv->c.type].name);
@@ -4307,10 +4283,14 @@ static int __devinit bttv_probe(struct pci_dev *dev,
4307 if (bttv_num == BTTV_MAX) 4283 if (bttv_num == BTTV_MAX)
4308 return -ENOMEM; 4284 return -ENOMEM;
4309 printk(KERN_INFO "bttv: Bt8xx card found (%d).\n", bttv_num); 4285 printk(KERN_INFO "bttv: Bt8xx card found (%d).\n", bttv_num);
4310 btv=&bttvs[bttv_num]; 4286 bttvs[bttv_num] = btv = kzalloc(sizeof(*btv), GFP_KERNEL);
4311 memset(btv,0,sizeof(*btv)); 4287 if (btv == NULL) {
4288 printk(KERN_ERR "bttv: out of memory.\n");
4289 return -ENOMEM;
4290 }
4312 btv->c.nr = bttv_num; 4291 btv->c.nr = bttv_num;
4313 sprintf(btv->c.name,"bttv%d",btv->c.nr); 4292 snprintf(btv->c.v4l2_dev.name, sizeof(btv->c.v4l2_dev.name),
4293 "bttv%d", btv->c.nr);
4314 4294
4315 /* initialize structs / fill in defaults */ 4295 /* initialize structs / fill in defaults */
4316 mutex_init(&btv->lock); 4296 mutex_init(&btv->lock);
@@ -4347,7 +4327,7 @@ static int __devinit bttv_probe(struct pci_dev *dev,
4347 } 4327 }
4348 if (!request_mem_region(pci_resource_start(dev,0), 4328 if (!request_mem_region(pci_resource_start(dev,0),
4349 pci_resource_len(dev,0), 4329 pci_resource_len(dev,0),
4350 btv->c.name)) { 4330 btv->c.v4l2_dev.name)) {
4351 printk(KERN_WARNING "bttv%d: can't request iomem (0x%llx).\n", 4331 printk(KERN_WARNING "bttv%d: can't request iomem (0x%llx).\n",
4352 btv->c.nr, 4332 btv->c.nr,
4353 (unsigned long long)pci_resource_start(dev,0)); 4333 (unsigned long long)pci_resource_start(dev,0));
@@ -4355,7 +4335,12 @@ static int __devinit bttv_probe(struct pci_dev *dev,
4355 } 4335 }
4356 pci_set_master(dev); 4336 pci_set_master(dev);
4357 pci_set_command(dev); 4337 pci_set_command(dev);
4358 pci_set_drvdata(dev,btv); 4338
4339 result = v4l2_device_register(&dev->dev, &btv->c.v4l2_dev);
4340 if (result < 0) {
4341 printk(KERN_WARNING "bttv%d: v4l2_device_register() failed\n", btv->c.nr);
4342 goto fail0;
4343 }
4359 4344
4360 pci_read_config_byte(dev, PCI_CLASS_REVISION, &btv->revision); 4345 pci_read_config_byte(dev, PCI_CLASS_REVISION, &btv->revision);
4361 pci_read_config_byte(dev, PCI_LATENCY_TIMER, &lat); 4346 pci_read_config_byte(dev, PCI_LATENCY_TIMER, &lat);
@@ -4379,7 +4364,7 @@ static int __devinit bttv_probe(struct pci_dev *dev,
4379 /* disable irqs, register irq handler */ 4364 /* disable irqs, register irq handler */
4380 btwrite(0, BT848_INT_MASK); 4365 btwrite(0, BT848_INT_MASK);
4381 result = request_irq(btv->c.pci->irq, bttv_irq, 4366 result = request_irq(btv->c.pci->irq, bttv_irq,
4382 IRQF_SHARED | IRQF_DISABLED,btv->c.name,(void *)btv); 4367 IRQF_SHARED | IRQF_DISABLED, btv->c.v4l2_dev.name, (void *)btv);
4383 if (result < 0) { 4368 if (result < 0) {
4384 printk(KERN_ERR "bttv%d: can't get IRQ %d\n", 4369 printk(KERN_ERR "bttv%d: can't get IRQ %d\n",
4385 bttv_num,btv->c.pci->irq); 4370 bttv_num,btv->c.pci->irq);
@@ -4463,21 +4448,24 @@ static int __devinit bttv_probe(struct pci_dev *dev,
4463 bttv_num++; 4448 bttv_num++;
4464 return 0; 4449 return 0;
4465 4450
4466 fail2: 4451fail2:
4467 free_irq(btv->c.pci->irq,btv); 4452 free_irq(btv->c.pci->irq,btv);
4468 4453
4469 fail1: 4454fail1:
4455 v4l2_device_unregister(&btv->c.v4l2_dev);
4456
4457fail0:
4470 if (btv->bt848_mmio) 4458 if (btv->bt848_mmio)
4471 iounmap(btv->bt848_mmio); 4459 iounmap(btv->bt848_mmio);
4472 release_mem_region(pci_resource_start(btv->c.pci,0), 4460 release_mem_region(pci_resource_start(btv->c.pci,0),
4473 pci_resource_len(btv->c.pci,0)); 4461 pci_resource_len(btv->c.pci,0));
4474 pci_set_drvdata(dev,NULL);
4475 return result; 4462 return result;
4476} 4463}
4477 4464
4478static void __devexit bttv_remove(struct pci_dev *pci_dev) 4465static void __devexit bttv_remove(struct pci_dev *pci_dev)
4479{ 4466{
4480 struct bttv *btv = pci_get_drvdata(pci_dev); 4467 struct v4l2_device *v4l2_dev = pci_get_drvdata(pci_dev);
4468 struct bttv *btv = to_bttv(v4l2_dev);
4481 4469
4482 if (bttv_verbose) 4470 if (bttv_verbose)
4483 printk("bttv%d: unloading\n",btv->c.nr); 4471 printk("bttv%d: unloading\n",btv->c.nr);
@@ -4511,14 +4499,18 @@ static void __devexit bttv_remove(struct pci_dev *pci_dev)
4511 release_mem_region(pci_resource_start(btv->c.pci,0), 4499 release_mem_region(pci_resource_start(btv->c.pci,0),
4512 pci_resource_len(btv->c.pci,0)); 4500 pci_resource_len(btv->c.pci,0));
4513 4501
4514 pci_set_drvdata(pci_dev, NULL); 4502 v4l2_device_unregister(&btv->c.v4l2_dev);
4503 bttvs[btv->c.nr] = NULL;
4504 kfree(btv);
4505
4515 return; 4506 return;
4516} 4507}
4517 4508
4518#ifdef CONFIG_PM 4509#ifdef CONFIG_PM
4519static int bttv_suspend(struct pci_dev *pci_dev, pm_message_t state) 4510static int bttv_suspend(struct pci_dev *pci_dev, pm_message_t state)
4520{ 4511{
4521 struct bttv *btv = pci_get_drvdata(pci_dev); 4512 struct v4l2_device *v4l2_dev = pci_get_drvdata(pci_dev);
4513 struct bttv *btv = to_bttv(v4l2_dev);
4522 struct bttv_buffer_set idle; 4514 struct bttv_buffer_set idle;
4523 unsigned long flags; 4515 unsigned long flags;
4524 4516
@@ -4553,7 +4545,8 @@ static int bttv_suspend(struct pci_dev *pci_dev, pm_message_t state)
4553 4545
4554static int bttv_resume(struct pci_dev *pci_dev) 4546static int bttv_resume(struct pci_dev *pci_dev)
4555{ 4547{
4556 struct bttv *btv = pci_get_drvdata(pci_dev); 4548 struct v4l2_device *v4l2_dev = pci_get_drvdata(pci_dev);
4549 struct bttv *btv = to_bttv(v4l2_dev);
4557 unsigned long flags; 4550 unsigned long flags;
4558 int err; 4551 int err;
4559 4552
diff --git a/drivers/media/video/bt8xx/bttv-i2c.c b/drivers/media/video/bt8xx/bttv-i2c.c
index bcd2cd240a16..a99d92fac3dc 100644
--- a/drivers/media/video/bt8xx/bttv-i2c.c
+++ b/drivers/media/video/bt8xx/bttv-i2c.c
@@ -36,8 +36,6 @@
36#include <linux/jiffies.h> 36#include <linux/jiffies.h>
37#include <asm/io.h> 37#include <asm/io.h>
38 38
39static int attach_inform(struct i2c_client *client);
40
41static int i2c_debug; 39static int i2c_debug;
42static int i2c_hw; 40static int i2c_hw;
43static int i2c_scan; 41static int i2c_scan;
@@ -231,7 +229,8 @@ bttv_i2c_readbytes(struct bttv *btv, const struct i2c_msg *msg, int last)
231 229
232static int bttv_i2c_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs, int num) 230static int bttv_i2c_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs, int num)
233{ 231{
234 struct bttv *btv = i2c_get_adapdata(i2c_adap); 232 struct v4l2_device *v4l2_dev = i2c_get_adapdata(i2c_adap);
233 struct bttv *btv = to_bttv(v4l2_dev);
235 int retval = 0; 234 int retval = 0;
236 int i; 235 int i;
237 236
@@ -265,52 +264,6 @@ static const struct i2c_algorithm bttv_algo = {
265/* ----------------------------------------------------------------------- */ 264/* ----------------------------------------------------------------------- */
266/* I2C functions - common stuff */ 265/* I2C functions - common stuff */
267 266
268static int attach_inform(struct i2c_client *client)
269{
270 struct bttv *btv = i2c_get_adapdata(client->adapter);
271 int addr=ADDR_UNSET;
272
273
274 if (ADDR_UNSET != bttv_tvcards[btv->c.type].tuner_addr)
275 addr = bttv_tvcards[btv->c.type].tuner_addr;
276
277
278 if (bttv_debug)
279 printk(KERN_DEBUG "bttv%d: %s i2c attach [addr=0x%x,client=%s]\n",
280 btv->c.nr, client->driver->driver.name, client->addr,
281 client->name);
282 if (!client->driver->command)
283 return 0;
284
285 if (client->driver->id == I2C_DRIVERID_MSP3400)
286 btv->i2c_msp34xx_client = client;
287 if (client->driver->id == I2C_DRIVERID_TVAUDIO)
288 btv->i2c_tvaudio_client = client;
289 if (btv->tuner_type != UNSET) {
290 struct tuner_setup tun_setup;
291
292 if ((addr==ADDR_UNSET) ||
293 (addr==client->addr)) {
294
295 tun_setup.mode_mask = T_ANALOG_TV | T_DIGITAL_TV | T_RADIO;
296 tun_setup.type = btv->tuner_type;
297 tun_setup.addr = addr;
298 bttv_call_i2c_clients(btv, TUNER_SET_TYPE_ADDR, &tun_setup);
299 }
300
301 }
302
303 return 0;
304}
305
306void bttv_call_i2c_clients(struct bttv *btv, unsigned int cmd, void *arg)
307{
308 if (0 != btv->i2c_rc)
309 return;
310 i2c_clients_command(&btv->c.i2c_adap, cmd, arg);
311}
312
313
314/* read I2C */ 267/* read I2C */
315int bttv_I2CRead(struct bttv *btv, unsigned char addr, char *probe_for) 268int bttv_I2CRead(struct bttv *btv, unsigned char addr, char *probe_for)
316{ 269{
@@ -417,21 +370,15 @@ int __devinit init_bttv_i2c(struct bttv *btv)
417 btv->c.i2c_adap.algo_data = &btv->i2c_algo; 370 btv->c.i2c_adap.algo_data = &btv->i2c_algo;
418 } 371 }
419 btv->c.i2c_adap.owner = THIS_MODULE; 372 btv->c.i2c_adap.owner = THIS_MODULE;
420 btv->c.i2c_adap.class = I2C_CLASS_TV_ANALOG;
421 btv->c.i2c_adap.client_register = attach_inform;
422 373
423 btv->c.i2c_adap.dev.parent = &btv->c.pci->dev; 374 btv->c.i2c_adap.dev.parent = &btv->c.pci->dev;
424 snprintf(btv->c.i2c_adap.name, sizeof(btv->c.i2c_adap.name), 375 snprintf(btv->c.i2c_adap.name, sizeof(btv->c.i2c_adap.name),
425 "bt%d #%d [%s]", btv->id, btv->c.nr, 376 "bt%d #%d [%s]", btv->id, btv->c.nr,
426 btv->use_i2c_hw ? "hw" : "sw"); 377 btv->use_i2c_hw ? "hw" : "sw");
427 378
428 i2c_set_adapdata(&btv->c.i2c_adap, btv); 379 i2c_set_adapdata(&btv->c.i2c_adap, &btv->c.v4l2_dev);
429 btv->i2c_client.adapter = &btv->c.i2c_adap; 380 btv->i2c_client.adapter = &btv->c.i2c_adap;
430 381
431 if (bttv_tvcards[btv->c.type].no_video)
432 btv->c.i2c_adap.class &= ~I2C_CLASS_TV_ANALOG;
433 if (bttv_tvcards[btv->c.type].has_dvb)
434 btv->c.i2c_adap.class |= I2C_CLASS_TV_DIGITAL;
435 382
436 if (btv->use_i2c_hw) { 383 if (btv->use_i2c_hw) {
437 btv->i2c_rc = i2c_add_adapter(&btv->c.i2c_adap); 384 btv->i2c_rc = i2c_add_adapter(&btv->c.i2c_adap);
@@ -441,7 +388,7 @@ int __devinit init_bttv_i2c(struct bttv *btv)
441 btv->i2c_rc = i2c_bit_add_bus(&btv->c.i2c_adap); 388 btv->i2c_rc = i2c_bit_add_bus(&btv->c.i2c_adap);
442 } 389 }
443 if (0 == btv->i2c_rc && i2c_scan) 390 if (0 == btv->i2c_rc && i2c_scan)
444 do_i2c_scan(btv->c.name,&btv->i2c_client); 391 do_i2c_scan(btv->c.v4l2_dev.name, &btv->i2c_client);
445 return btv->i2c_rc; 392 return btv->i2c_rc;
446} 393}
447 394
diff --git a/drivers/media/video/bt8xx/bttv-if.c b/drivers/media/video/bt8xx/bttv-if.c
index ecf07988cd33..a6a540dc9e4b 100644
--- a/drivers/media/video/bt8xx/bttv-if.c
+++ b/drivers/media/video/bt8xx/bttv-if.c
@@ -47,7 +47,10 @@ struct pci_dev* bttv_get_pcidev(unsigned int card)
47{ 47{
48 if (card >= bttv_num) 48 if (card >= bttv_num)
49 return NULL; 49 return NULL;
50 return bttvs[card].c.pci; 50 if (!bttvs[card])
51 return NULL;
52
53 return bttvs[card]->c.pci;
51} 54}
52 55
53 56
@@ -59,7 +62,10 @@ int bttv_gpio_enable(unsigned int card, unsigned long mask, unsigned long data)
59 return -EINVAL; 62 return -EINVAL;
60 } 63 }
61 64
62 btv = &bttvs[card]; 65 btv = bttvs[card];
66 if (!btv)
67 return -ENODEV;
68
63 gpio_inout(mask,data); 69 gpio_inout(mask,data);
64 if (bttv_gpio) 70 if (bttv_gpio)
65 bttv_gpio_tracking(btv,"extern enable"); 71 bttv_gpio_tracking(btv,"extern enable");
@@ -74,7 +80,9 @@ int bttv_read_gpio(unsigned int card, unsigned long *data)
74 return -EINVAL; 80 return -EINVAL;
75 } 81 }
76 82
77 btv = &bttvs[card]; 83 btv = bttvs[card];
84 if (!btv)
85 return -ENODEV;
78 86
79 if(btv->shutdown) { 87 if(btv->shutdown) {
80 return -ENODEV; 88 return -ENODEV;
@@ -94,7 +102,9 @@ int bttv_write_gpio(unsigned int card, unsigned long mask, unsigned long data)
94 return -EINVAL; 102 return -EINVAL;
95 } 103 }
96 104
97 btv = &bttvs[card]; 105 btv = bttvs[card];
106 if (!btv)
107 return -ENODEV;
98 108
99/* prior setting BT848_GPIO_REG_INP is (probably) not needed 109/* prior setting BT848_GPIO_REG_INP is (probably) not needed
100 because direct input is set on init */ 110 because direct input is set on init */
diff --git a/drivers/media/video/bt8xx/bttv-risc.c b/drivers/media/video/bt8xx/bttv-risc.c
index 5b1b8e4c78ba..d16af2836379 100644
--- a/drivers/media/video/bt8xx/bttv-risc.c
+++ b/drivers/media/video/bt8xx/bttv-risc.c
@@ -341,7 +341,7 @@ bttv_calc_geo_old(struct bttv *btv, struct bttv_geometry *geo,
341 int totalwidth = tvnorm->totalwidth; 341 int totalwidth = tvnorm->totalwidth;
342 int scaledtwidth = tvnorm->scaledtwidth; 342 int scaledtwidth = tvnorm->scaledtwidth;
343 343
344 if (bttv_tvcards[btv->c.type].muxsel[btv->input] < 0) { 344 if (btv->input == btv->dig) {
345 swidth = 720; 345 swidth = 720;
346 totalwidth = 858; 346 totalwidth = 858;
347 scaledtwidth = 858; 347 scaledtwidth = 858;
@@ -391,7 +391,7 @@ bttv_calc_geo (struct bttv * btv,
391 && crop->width == tvnorm->cropcap.defrect.width 391 && crop->width == tvnorm->cropcap.defrect.width
392 && crop->height == tvnorm->cropcap.defrect.height 392 && crop->height == tvnorm->cropcap.defrect.height
393 && width <= tvnorm->swidth /* see PAL-Nc et al */) 393 && width <= tvnorm->swidth /* see PAL-Nc et al */)
394 || bttv_tvcards[btv->c.type].muxsel[btv->input] < 0) { 394 || btv->input == btv->dig) {
395 bttv_calc_geo_old(btv, geo, width, height, 395 bttv_calc_geo_old(btv, geo, width, height,
396 both_fields, tvnorm); 396 both_fields, tvnorm);
397 return; 397 return;
diff --git a/drivers/media/video/bt8xx/bttv-vbi.c b/drivers/media/video/bt8xx/bttv-vbi.c
index 6819e21a3773..e79a402fa6cd 100644
--- a/drivers/media/video/bt8xx/bttv-vbi.c
+++ b/drivers/media/video/bt8xx/bttv-vbi.c
@@ -411,7 +411,7 @@ int bttv_g_fmt_vbi_cap(struct file *file, void *f, struct v4l2_format *frt)
411 return 0; 411 return 0;
412} 412}
413 413
414void bttv_vbi_fmt_reset(struct bttv_vbi_fmt *f, int norm) 414void bttv_vbi_fmt_reset(struct bttv_vbi_fmt *f, unsigned int norm)
415{ 415{
416 const struct bttv_tvnorm *tvnorm; 416 const struct bttv_tvnorm *tvnorm;
417 unsigned int real_samples_per_line; 417 unsigned int real_samples_per_line;
diff --git a/drivers/media/video/bt8xx/bttv.h b/drivers/media/video/bt8xx/bttv.h
index 529bf6cf634d..3d36daf206f3 100644
--- a/drivers/media/video/bt8xx/bttv.h
+++ b/drivers/media/video/bt8xx/bttv.h
@@ -14,8 +14,9 @@
14#ifndef _BTTV_H_ 14#ifndef _BTTV_H_
15#define _BTTV_H_ 15#define _BTTV_H_
16 16
17#include <linux/videodev.h> 17#include <linux/videodev2.h>
18#include <linux/i2c.h> 18#include <linux/i2c.h>
19#include <media/v4l2-device.h>
19#include <media/ir-common.h> 20#include <media/ir-common.h>
20#include <media/ir-kbd-i2c.h> 21#include <media/ir-kbd-i2c.h>
21#include <media/i2c-addr.h> 22#include <media/i2c-addr.h>
@@ -180,6 +181,10 @@
180#define BTTV_BOARD_VD012 0x99 181#define BTTV_BOARD_VD012 0x99
181#define BTTV_BOARD_VD012_X1 0x9a 182#define BTTV_BOARD_VD012_X1 0x9a
182#define BTTV_BOARD_VD012_X2 0x9b 183#define BTTV_BOARD_VD012_X2 0x9b
184#define BTTV_BOARD_IVCE8784 0x9c
185#define BTTV_BOARD_GEOVISION_GV800S 0x9d
186#define BTTV_BOARD_GEOVISION_GV800S_SL 0x9e
187#define BTTV_BOARD_PV183 0x9f
183 188
184 189
185/* more card-specific defines */ 190/* more card-specific defines */
@@ -191,12 +196,9 @@
191#define WINVIEW_PT2254_DATA 0x20 196#define WINVIEW_PT2254_DATA 0x20
192#define WINVIEW_PT2254_STROBE 0x80 197#define WINVIEW_PT2254_STROBE 0x80
193 198
194/* digital_mode */
195#define DIGITAL_MODE_VIDEO 1
196#define DIGITAL_MODE_CAMERA 2
197
198struct bttv_core { 199struct bttv_core {
199 /* device structs */ 200 /* device structs */
201 struct v4l2_device v4l2_dev;
200 struct pci_dev *pci; 202 struct pci_dev *pci;
201 struct i2c_adapter i2c_adap; 203 struct i2c_adapter i2c_adap;
202 struct list_head subs; /* struct bttv_sub_device */ 204 struct list_head subs; /* struct bttv_sub_device */
@@ -204,59 +206,79 @@ struct bttv_core {
204 /* device config */ 206 /* device config */
205 unsigned int nr; /* dev nr (for printk("bttv%d: ..."); */ 207 unsigned int nr; /* dev nr (for printk("bttv%d: ..."); */
206 unsigned int type; /* card type (pointer into tvcards[]) */ 208 unsigned int type; /* card type (pointer into tvcards[]) */
207 char name[8]; /* dev name */
208}; 209};
209 210
210struct bttv; 211struct bttv;
211 212
212 213struct tvcard {
213struct tvcard
214{
215 char *name; 214 char *name;
216 unsigned int video_inputs; 215 void (*volume_gpio)(struct bttv *btv, __u16 volume);
217 unsigned int audio_inputs; 216 void (*audio_mode_gpio)(struct bttv *btv, struct v4l2_tuner *tuner, int set);
218 unsigned int tuner; 217 void (*muxsel_hook)(struct bttv *btv, unsigned int input);
219 unsigned int svhs; 218
220 unsigned int digital_mode; // DIGITAL_MODE_CAMERA or DIGITAL_MODE_VIDEO 219 /* MUX bits for each input, two bits per input starting with the LSB */
220 u32 muxsel; /* Use MUXSEL() to set */
221
221 u32 gpiomask; 222 u32 gpiomask;
222 u32 muxsel[16];
223 u32 gpiomux[4]; /* Tuner, Radio, external, internal */ 223 u32 gpiomux[4]; /* Tuner, Radio, external, internal */
224 u32 gpiomute; /* GPIO mute setting */ 224 u32 gpiomute; /* GPIO mute setting */
225 u32 gpiomask2; /* GPIO MUX mask */ 225 u32 gpiomask2; /* GPIO MUX mask */
226 226
227 unsigned int tuner_type;
228 u8 tuner_addr;
229 u8 video_inputs; /* Number of inputs */
230 unsigned int svhs:4; /* Which input is s-video */
231#define NO_SVHS 15
232 unsigned int pll:2;
233#define PLL_NONE 0
234#define PLL_28 1
235#define PLL_35 2
236
227 /* i2c audio flags */ 237 /* i2c audio flags */
228 unsigned int no_msp34xx:1; 238 unsigned int no_msp34xx:1;
229 unsigned int no_tda9875:1; 239 unsigned int no_tda9875:1;
230 unsigned int no_tda7432:1; 240 unsigned int no_tda7432:1;
231 unsigned int needs_tvaudio:1; 241 unsigned int needs_tvaudio:1;
232 unsigned int msp34xx_alt:1; 242 unsigned int msp34xx_alt:1;
243 /* Note: currently no card definition needs to mark the presence
244 of a RDS saa6588 chip. If this is ever needed, then add a new
245 'has_saa6588' bit here. */
233 246
234 /* flag: video pci function is unused */ 247 unsigned int no_video:1; /* video pci function is unused */
235 unsigned int no_video:1;
236 unsigned int has_dvb:1; 248 unsigned int has_dvb:1;
237 unsigned int has_remote:1; 249 unsigned int has_remote:1;
250 unsigned int has_radio:1;
251 unsigned int has_dig_in:1; /* Has digital input (always last input) */
238 unsigned int no_gpioirq:1; 252 unsigned int no_gpioirq:1;
239
240 /* other settings */
241 unsigned int pll;
242#define PLL_NONE 0
243#define PLL_28 1
244#define PLL_35 2
245
246 unsigned int tuner_type;
247 unsigned int tuner_addr;
248 unsigned int radio_addr;
249
250 unsigned int has_radio;
251
252 void (*volume_gpio)(struct bttv *btv, __u16 volume);
253 void (*audio_mode_gpio)(struct bttv *btv, struct v4l2_tuner *tuner, int set);
254
255 void (*muxsel_hook)(struct bttv *btv, unsigned int input);
256}; 253};
257 254
258extern struct tvcard bttv_tvcards[]; 255extern struct tvcard bttv_tvcards[];
259 256
257/*
258 * This bit of cpp voodoo is used to create a macro with a variable number of
259 * arguments (1 to 16). It will pack each argument into a word two bits at a
260 * time. It can't be a function because it needs to be compile time constant to
261 * initialize structures. Since each argument must fit in two bits, it's ok
262 * that they are changed to octal. One should not use hex number, macros, or
263 * anything else with this macro. Just use plain integers from 0 to 3.
264 */
265#define _MUXSELf(a) 0##a << 30
266#define _MUXSELe(a, b...) 0##a << 28 | _MUXSELf(b)
267#define _MUXSELd(a, b...) 0##a << 26 | _MUXSELe(b)
268#define _MUXSELc(a, b...) 0##a << 24 | _MUXSELd(b)
269#define _MUXSELb(a, b...) 0##a << 22 | _MUXSELc(b)
270#define _MUXSELa(a, b...) 0##a << 20 | _MUXSELb(b)
271#define _MUXSEL9(a, b...) 0##a << 18 | _MUXSELa(b)
272#define _MUXSEL8(a, b...) 0##a << 16 | _MUXSEL9(b)
273#define _MUXSEL7(a, b...) 0##a << 14 | _MUXSEL8(b)
274#define _MUXSEL6(a, b...) 0##a << 12 | _MUXSEL7(b)
275#define _MUXSEL5(a, b...) 0##a << 10 | _MUXSEL6(b)
276#define _MUXSEL4(a, b...) 0##a << 8 | _MUXSEL5(b)
277#define _MUXSEL3(a, b...) 0##a << 6 | _MUXSEL4(b)
278#define _MUXSEL2(a, b...) 0##a << 4 | _MUXSEL3(b)
279#define _MUXSEL1(a, b...) 0##a << 2 | _MUXSEL2(b)
280#define MUXSEL(a, b...) (a | _MUXSEL1(b))
281
260/* identification / initialization of the card */ 282/* identification / initialization of the card */
261extern void bttv_idcard(struct bttv *btv); 283extern void bttv_idcard(struct bttv *btv);
262extern void bttv_init_card1(struct bttv *btv); 284extern void bttv_init_card1(struct bttv *btv);
@@ -264,7 +286,7 @@ extern void bttv_init_card2(struct bttv *btv);
264 286
265/* card-specific funtions */ 287/* card-specific funtions */
266extern void tea5757_set_freq(struct bttv *btv, unsigned short freq); 288extern void tea5757_set_freq(struct bttv *btv, unsigned short freq);
267extern void bttv_tda9880_setnorm(struct bttv *btv, int norm); 289extern u32 bttv_tda9880_setnorm(struct bttv *btv, u32 gpiobits);
268 290
269/* extra tweaks for some chipsets */ 291/* extra tweaks for some chipsets */
270extern void bttv_check_chipset(void); 292extern void bttv_check_chipset(void);
@@ -336,7 +358,9 @@ void bttv_gpio_bits(struct bttv_core *core, u32 mask, u32 bits);
336/* ---------------------------------------------------------- */ 358/* ---------------------------------------------------------- */
337/* i2c */ 359/* i2c */
338 360
339extern void bttv_call_i2c_clients(struct bttv *btv, unsigned int cmd, void *arg); 361#define bttv_call_all(btv, o, f, args...) \
362 v4l2_device_call_all(&btv->c.v4l2_dev, 0, o, f, ##args)
363
340extern int bttv_I2CRead(struct bttv *btv, unsigned char addr, char *probe_for); 364extern int bttv_I2CRead(struct bttv *btv, unsigned char addr, char *probe_for);
341extern int bttv_I2CWrite(struct bttv *btv, unsigned char addr, unsigned char b1, 365extern int bttv_I2CWrite(struct bttv *btv, unsigned char addr, unsigned char b1,
342 unsigned char b2, int both); 366 unsigned char b2, int both);
diff --git a/drivers/media/video/bt8xx/bttvp.h b/drivers/media/video/bt8xx/bttvp.h
index 199a4d225caf..96498489199d 100644
--- a/drivers/media/video/bt8xx/bttvp.h
+++ b/drivers/media/video/bt8xx/bttvp.h
@@ -32,7 +32,6 @@
32#include <linux/wait.h> 32#include <linux/wait.h>
33#include <linux/i2c.h> 33#include <linux/i2c.h>
34#include <linux/i2c-algo-bit.h> 34#include <linux/i2c-algo-bit.h>
35#include <linux/videodev.h>
36#include <linux/pci.h> 35#include <linux/pci.h>
37#include <linux/input.h> 36#include <linux/input.h>
38#include <linux/mutex.h> 37#include <linux/mutex.h>
@@ -135,7 +134,7 @@ struct bttv_buffer {
135 134
136 /* bttv specific */ 135 /* bttv specific */
137 const struct bttv_format *fmt; 136 const struct bttv_format *fmt;
138 int tvnorm; 137 unsigned int tvnorm;
139 int btformat; 138 int btformat;
140 int btswap; 139 int btswap;
141 struct bttv_geometry geo; 140 struct bttv_geometry geo;
@@ -154,7 +153,7 @@ struct bttv_buffer_set {
154}; 153};
155 154
156struct bttv_overlay { 155struct bttv_overlay {
157 int tvnorm; 156 unsigned int tvnorm;
158 struct v4l2_rect w; 157 struct v4l2_rect w;
159 enum v4l2_field field; 158 enum v4l2_field field;
160 struct v4l2_clip *clips; 159 struct v4l2_clip *clips;
@@ -174,7 +173,7 @@ struct bttv_vbi_fmt {
174}; 173};
175 174
176/* bttv-vbi.c */ 175/* bttv-vbi.c */
177void bttv_vbi_fmt_reset(struct bttv_vbi_fmt *f, int norm); 176void bttv_vbi_fmt_reset(struct bttv_vbi_fmt *f, unsigned int norm);
178 177
179struct bttv_crop { 178struct bttv_crop {
180 /* A cropping rectangle in struct bttv_tvnorm.cropcap units. */ 179 /* A cropping rectangle in struct bttv_tvnorm.cropcap units. */
@@ -329,7 +328,8 @@ struct bttv {
329 unsigned int cardid; /* pci subsystem id (bt878 based ones) */ 328 unsigned int cardid; /* pci subsystem id (bt878 based ones) */
330 unsigned int tuner_type; /* tuner chip type */ 329 unsigned int tuner_type; /* tuner chip type */
331 unsigned int tda9887_conf; 330 unsigned int tda9887_conf;
332 unsigned int svhs; 331 unsigned int svhs, dig;
332 unsigned int has_saa6588:1;
333 struct bttv_pll_info pll; 333 struct bttv_pll_info pll;
334 int triton1; 334 int triton1;
335 int gpioirq; 335 int gpioirq;
@@ -353,8 +353,8 @@ struct bttv {
353 int i2c_state, i2c_rc; 353 int i2c_state, i2c_rc;
354 int i2c_done; 354 int i2c_done;
355 wait_queue_head_t i2c_queue; 355 wait_queue_head_t i2c_queue;
356 struct i2c_client *i2c_msp34xx_client; 356 struct v4l2_subdev *sd_msp34xx;
357 struct i2c_client *i2c_tvaudio_client; 357 struct v4l2_subdev *sd_tvaudio;
358 358
359 /* video4linux (1) */ 359 /* video4linux (1) */
360 struct video_device *video_dev; 360 struct video_device *video_dev;
@@ -378,7 +378,8 @@ struct bttv {
378 unsigned int audio; 378 unsigned int audio;
379 unsigned int mute; 379 unsigned int mute;
380 unsigned long freq; 380 unsigned long freq;
381 int tvnorm,hue,contrast,bright,saturation; 381 unsigned int tvnorm;
382 int hue, contrast, bright, saturation;
382 struct v4l2_framebuffer fbuf; 383 struct v4l2_framebuffer fbuf;
383 unsigned int field_count; 384 unsigned int field_count;
384 385
@@ -458,10 +459,21 @@ struct bttv {
458 __s32 crop_start; 459 __s32 crop_start;
459}; 460};
460 461
462static inline struct bttv *to_bttv(struct v4l2_device *v4l2_dev)
463{
464 return container_of(v4l2_dev, struct bttv, c.v4l2_dev);
465}
466
461/* our devices */ 467/* our devices */
462#define BTTV_MAX 32 468#define BTTV_MAX 32
463extern unsigned int bttv_num; 469extern unsigned int bttv_num;
464extern struct bttv bttvs[BTTV_MAX]; 470extern struct bttv *bttvs[BTTV_MAX];
471
472static inline unsigned int bttv_muxsel(const struct bttv *btv,
473 unsigned int input)
474{
475 return (bttv_tvcards[btv->c.type].muxsel >> (input * 2)) & 3;
476}
465 477
466#endif 478#endif
467 479
diff --git a/drivers/media/video/cafe_ccic.c b/drivers/media/video/cafe_ccic.c
index 46fd573a4f15..7abe94d9fb4c 100644
--- a/drivers/media/video/cafe_ccic.c
+++ b/drivers/media/video/cafe_ccic.c
@@ -11,6 +11,12 @@
11 * 11 *
12 * Written by Jonathan Corbet, corbet@lwn.net. 12 * Written by Jonathan Corbet, corbet@lwn.net.
13 * 13 *
14 * v4l2_device/v4l2_subdev conversion by:
15 * Copyright (C) 2009 Hans Verkuil <hverkuil@xs4all.nl>
16 *
17 * Note: this conversion is untested! Please contact the linux-media
18 * mailinglist if you can test this, together with the test results.
19 *
14 * This file may be distributed under the terms of the GNU General 20 * This file may be distributed under the terms of the GNU General
15 * Public License, version 2. 21 * Public License, version 2.
16 */ 22 */
@@ -25,7 +31,7 @@
25#include <linux/interrupt.h> 31#include <linux/interrupt.h>
26#include <linux/spinlock.h> 32#include <linux/spinlock.h>
27#include <linux/videodev2.h> 33#include <linux/videodev2.h>
28#include <media/v4l2-common.h> 34#include <media/v4l2-device.h>
29#include <media/v4l2-ioctl.h> 35#include <media/v4l2-ioctl.h>
30#include <media/v4l2-chip-ident.h> 36#include <media/v4l2-chip-ident.h>
31#include <linux/device.h> 37#include <linux/device.h>
@@ -33,7 +39,6 @@
33#include <linux/list.h> 39#include <linux/list.h>
34#include <linux/dma-mapping.h> 40#include <linux/dma-mapping.h>
35#include <linux/delay.h> 41#include <linux/delay.h>
36#include <linux/debugfs.h>
37#include <linux/jiffies.h> 42#include <linux/jiffies.h>
38#include <linux/vmalloc.h> 43#include <linux/vmalloc.h>
39 44
@@ -136,6 +141,7 @@ struct cafe_sio_buffer {
136 */ 141 */
137struct cafe_camera 142struct cafe_camera
138{ 143{
144 struct v4l2_device v4l2_dev;
139 enum cafe_state state; 145 enum cafe_state state;
140 unsigned long flags; /* Buffer status, mainly (dev_lock) */ 146 unsigned long flags; /* Buffer status, mainly (dev_lock) */
141 int users; /* How many open FDs */ 147 int users; /* How many open FDs */
@@ -145,9 +151,10 @@ struct cafe_camera
145 * Subsystem structures. 151 * Subsystem structures.
146 */ 152 */
147 struct pci_dev *pdev; 153 struct pci_dev *pdev;
148 struct video_device v4ldev; 154 struct video_device vdev;
149 struct i2c_adapter i2c_adapter; 155 struct i2c_adapter i2c_adapter;
150 struct i2c_client *sensor; 156 struct v4l2_subdev *sensor;
157 unsigned short sensor_addr;
151 158
152 unsigned char __iomem *regs; 159 unsigned char __iomem *regs;
153 struct list_head dev_list; /* link to other devices */ 160 struct list_head dev_list; /* link to other devices */
@@ -180,10 +187,6 @@ struct cafe_camera
180 /* Misc */ 187 /* Misc */
181 wait_queue_head_t smbus_wait; /* Waiting on i2c events */ 188 wait_queue_head_t smbus_wait; /* Waiting on i2c events */
182 wait_queue_head_t iowait; /* Waiting on frame data */ 189 wait_queue_head_t iowait; /* Waiting on frame data */
183#ifdef CONFIG_VIDEO_ADV_DEBUG
184 struct dentry *dfs_regs;
185 struct dentry *dfs_cam_regs;
186#endif
187}; 190};
188 191
189/* 192/*
@@ -195,6 +198,13 @@ struct cafe_camera
195#define CF_DMA_ACTIVE 3 /* A frame is incoming */ 198#define CF_DMA_ACTIVE 3 /* A frame is incoming */
196#define CF_CONFIG_NEEDED 4 /* Must configure hardware */ 199#define CF_CONFIG_NEEDED 4 /* Must configure hardware */
197 200
201#define sensor_call(cam, o, f, args...) \
202 v4l2_subdev_call(cam->sensor, o, f, ##args)
203
204static inline struct cafe_camera *to_cam(struct v4l2_device *dev)
205{
206 return container_of(dev, struct cafe_camera, v4l2_dev);
207}
198 208
199 209
200/* 210/*
@@ -238,59 +248,7 @@ static void cafe_set_config_needed(struct cafe_camera *cam, int needed)
238 248
239 249
240/* ---------------------------------------------------------------------*/ 250/* ---------------------------------------------------------------------*/
241/*
242 * We keep a simple list of known devices to search at open time.
243 */
244static LIST_HEAD(cafe_dev_list);
245static DEFINE_MUTEX(cafe_dev_list_lock);
246
247static void cafe_add_dev(struct cafe_camera *cam)
248{
249 mutex_lock(&cafe_dev_list_lock);
250 list_add_tail(&cam->dev_list, &cafe_dev_list);
251 mutex_unlock(&cafe_dev_list_lock);
252}
253
254static void cafe_remove_dev(struct cafe_camera *cam)
255{
256 mutex_lock(&cafe_dev_list_lock);
257 list_del(&cam->dev_list);
258 mutex_unlock(&cafe_dev_list_lock);
259}
260
261static struct cafe_camera *cafe_find_dev(int minor)
262{
263 struct cafe_camera *cam;
264
265 mutex_lock(&cafe_dev_list_lock);
266 list_for_each_entry(cam, &cafe_dev_list, dev_list) {
267 if (cam->v4ldev.minor == minor)
268 goto done;
269 }
270 cam = NULL;
271 done:
272 mutex_unlock(&cafe_dev_list_lock);
273 return cam;
274}
275
276
277static struct cafe_camera *cafe_find_by_pdev(struct pci_dev *pdev)
278{
279 struct cafe_camera *cam;
280 251
281 mutex_lock(&cafe_dev_list_lock);
282 list_for_each_entry(cam, &cafe_dev_list, dev_list) {
283 if (cam->pdev == pdev)
284 goto done;
285 }
286 cam = NULL;
287 done:
288 mutex_unlock(&cafe_dev_list_lock);
289 return cam;
290}
291
292
293/* ------------------------------------------------------------------------ */
294/* 252/*
295 * Device register I/O 253 * Device register I/O
296 */ 254 */
@@ -481,18 +439,11 @@ static int cafe_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
481 unsigned short flags, char rw, u8 command, 439 unsigned short flags, char rw, u8 command,
482 int size, union i2c_smbus_data *data) 440 int size, union i2c_smbus_data *data)
483{ 441{
484 struct cafe_camera *cam = i2c_get_adapdata(adapter); 442 struct v4l2_device *v4l2_dev = i2c_get_adapdata(adapter);
443 struct cafe_camera *cam = to_cam(v4l2_dev);
485 int ret = -EINVAL; 444 int ret = -EINVAL;
486 445
487 /* 446 /*
488 * Refuse to talk to anything but OV cam chips. We should
489 * never even see an attempt to do so, but one never knows.
490 */
491 if (cam->sensor && addr != cam->sensor->addr) {
492 cam_err(cam, "funky smbus addr %d\n", addr);
493 return -EINVAL;
494 }
495 /*
496 * This interface would appear to only do byte data ops. OK 447 * This interface would appear to only do byte data ops. OK
497 * it can do word too, but the cam chip has no use for that. 448 * it can do word too, but the cam chip has no use for that.
498 */ 449 */
@@ -530,38 +481,9 @@ static struct i2c_algorithm cafe_smbus_algo = {
530}; 481};
531 482
532/* Somebody is on the bus */ 483/* Somebody is on the bus */
533static int cafe_cam_init(struct cafe_camera *cam);
534static void cafe_ctlr_stop_dma(struct cafe_camera *cam); 484static void cafe_ctlr_stop_dma(struct cafe_camera *cam);
535static void cafe_ctlr_power_down(struct cafe_camera *cam); 485static void cafe_ctlr_power_down(struct cafe_camera *cam);
536 486
537static int cafe_smbus_attach(struct i2c_client *client)
538{
539 struct cafe_camera *cam = i2c_get_adapdata(client->adapter);
540
541 /*
542 * Don't talk to chips we don't recognize.
543 */
544 if (client->driver->id == I2C_DRIVERID_OV7670) {
545 cam->sensor = client;
546 return cafe_cam_init(cam);
547 }
548 return -EINVAL;
549}
550
551static int cafe_smbus_detach(struct i2c_client *client)
552{
553 struct cafe_camera *cam = i2c_get_adapdata(client->adapter);
554
555 if (cam->sensor == client) {
556 cafe_ctlr_stop_dma(cam);
557 cafe_ctlr_power_down(cam);
558 cam_err(cam, "lost the sensor!\n");
559 cam->sensor = NULL; /* Bummer, no camera */
560 cam->state = S_NOTREADY;
561 }
562 return 0;
563}
564
565static int cafe_smbus_setup(struct cafe_camera *cam) 487static int cafe_smbus_setup(struct cafe_camera *cam)
566{ 488{
567 struct i2c_adapter *adap = &cam->i2c_adapter; 489 struct i2c_adapter *adap = &cam->i2c_adapter;
@@ -570,12 +492,10 @@ static int cafe_smbus_setup(struct cafe_camera *cam)
570 cafe_smbus_enable_irq(cam); 492 cafe_smbus_enable_irq(cam);
571 adap->id = I2C_HW_SMBUS_CAFE; 493 adap->id = I2C_HW_SMBUS_CAFE;
572 adap->owner = THIS_MODULE; 494 adap->owner = THIS_MODULE;
573 adap->client_register = cafe_smbus_attach;
574 adap->client_unregister = cafe_smbus_detach;
575 adap->algo = &cafe_smbus_algo; 495 adap->algo = &cafe_smbus_algo;
576 strcpy(adap->name, "cafe_ccic"); 496 strcpy(adap->name, "cafe_ccic");
577 adap->dev.parent = &cam->pdev->dev; 497 adap->dev.parent = &cam->pdev->dev;
578 i2c_set_adapdata(adap, cam); 498 i2c_set_adapdata(adap, &cam->v4l2_dev);
579 ret = i2c_add_adapter(adap); 499 ret = i2c_add_adapter(adap);
580 if (ret) 500 if (ret)
581 printk(KERN_ERR "Unable to register cafe i2c adapter\n"); 501 printk(KERN_ERR "Unable to register cafe i2c adapter\n");
@@ -809,9 +729,9 @@ static void cafe_ctlr_power_up(struct cafe_camera *cam)
809 * Control 1 is power down, set to 0 to operate. 729 * Control 1 is power down, set to 0 to operate.
810 */ 730 */
811 cafe_reg_write(cam, REG_GPR, GPR_C1EN|GPR_C0EN); /* pwr up, reset */ 731 cafe_reg_write(cam, REG_GPR, GPR_C1EN|GPR_C0EN); /* pwr up, reset */
812// mdelay(1); /* Marvell says 1ms will do it */ 732/* mdelay(1); */ /* Marvell says 1ms will do it */
813 cafe_reg_write(cam, REG_GPR, GPR_C1EN|GPR_C0EN|GPR_C0); 733 cafe_reg_write(cam, REG_GPR, GPR_C1EN|GPR_C0EN|GPR_C0);
814// mdelay(1); /* Enough? */ 734/* mdelay(1); */ /* Enough? */
815 spin_unlock_irqrestore(&cam->dev_lock, flags); 735 spin_unlock_irqrestore(&cam->dev_lock, flags);
816 msleep(5); /* Just to be sure */ 736 msleep(5); /* Just to be sure */
817} 737}
@@ -833,23 +753,9 @@ static void cafe_ctlr_power_down(struct cafe_camera *cam)
833 * Communications with the sensor. 753 * Communications with the sensor.
834 */ 754 */
835 755
836static int __cafe_cam_cmd(struct cafe_camera *cam, int cmd, void *arg)
837{
838 struct i2c_client *sc = cam->sensor;
839 int ret;
840
841 if (sc == NULL || sc->driver == NULL || sc->driver->command == NULL)
842 return -EINVAL;
843 ret = sc->driver->command(sc, cmd, arg);
844 if (ret == -EPERM) /* Unsupported command */
845 return 0;
846 return ret;
847}
848
849static int __cafe_cam_reset(struct cafe_camera *cam) 756static int __cafe_cam_reset(struct cafe_camera *cam)
850{ 757{
851 int zero = 0; 758 return sensor_call(cam, core, reset, 0);
852 return __cafe_cam_cmd(cam, VIDIOC_INT_RESET, &zero);
853} 759}
854 760
855/* 761/*
@@ -869,14 +775,13 @@ static int cafe_cam_init(struct cafe_camera *cam)
869 if (ret) 775 if (ret)
870 goto out; 776 goto out;
871 chip.match.type = V4L2_CHIP_MATCH_I2C_ADDR; 777 chip.match.type = V4L2_CHIP_MATCH_I2C_ADDR;
872 chip.match.addr = cam->sensor->addr; 778 chip.match.addr = cam->sensor_addr;
873 ret = __cafe_cam_cmd(cam, VIDIOC_DBG_G_CHIP_IDENT, &chip); 779 ret = sensor_call(cam, core, g_chip_ident, &chip);
874 if (ret) 780 if (ret)
875 goto out; 781 goto out;
876 cam->sensor_type = chip.ident; 782 cam->sensor_type = chip.ident;
877// if (cam->sensor->addr != OV7xx0_SID) {
878 if (cam->sensor_type != V4L2_IDENT_OV7670) { 783 if (cam->sensor_type != V4L2_IDENT_OV7670) {
879 cam_err(cam, "Unsupported sensor type %d", cam->sensor->addr); 784 cam_err(cam, "Unsupported sensor type 0x%x", cam->sensor_type);
880 ret = -EINVAL; 785 ret = -EINVAL;
881 goto out; 786 goto out;
882 } 787 }
@@ -900,21 +805,21 @@ static int cafe_cam_set_flip(struct cafe_camera *cam)
900 memset(&ctrl, 0, sizeof(ctrl)); 805 memset(&ctrl, 0, sizeof(ctrl));
901 ctrl.id = V4L2_CID_VFLIP; 806 ctrl.id = V4L2_CID_VFLIP;
902 ctrl.value = flip; 807 ctrl.value = flip;
903 return __cafe_cam_cmd(cam, VIDIOC_S_CTRL, &ctrl); 808 return sensor_call(cam, core, s_ctrl, &ctrl);
904} 809}
905 810
906 811
907static int cafe_cam_configure(struct cafe_camera *cam) 812static int cafe_cam_configure(struct cafe_camera *cam)
908{ 813{
909 struct v4l2_format fmt; 814 struct v4l2_format fmt;
910 int ret, zero = 0; 815 int ret;
911 816
912 if (cam->state != S_IDLE) 817 if (cam->state != S_IDLE)
913 return -EINVAL; 818 return -EINVAL;
914 fmt.fmt.pix = cam->pix_format; 819 fmt.fmt.pix = cam->pix_format;
915 ret = __cafe_cam_cmd(cam, VIDIOC_INT_INIT, &zero); 820 ret = sensor_call(cam, core, init, 0);
916 if (ret == 0) 821 if (ret == 0)
917 ret = __cafe_cam_cmd(cam, VIDIOC_S_FMT, &fmt); 822 ret = sensor_call(cam, video, s_fmt, &fmt);
918 /* 823 /*
919 * OV7670 does weird things if flip is set *before* format... 824 * OV7670 does weird things if flip is set *before* format...
920 */ 825 */
@@ -1246,8 +1151,6 @@ static int cafe_vidioc_reqbufs(struct file *filp, void *priv,
1246 * Make sure it's something we can do. User pointers could be 1151 * Make sure it's something we can do. User pointers could be
1247 * implemented without great pain, but that's not been done yet. 1152 * implemented without great pain, but that's not been done yet.
1248 */ 1153 */
1249 if (req->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1250 return -EINVAL;
1251 if (req->memory != V4L2_MEMORY_MMAP) 1154 if (req->memory != V4L2_MEMORY_MMAP)
1252 return -EINVAL; 1155 return -EINVAL;
1253 /* 1156 /*
@@ -1311,9 +1214,7 @@ static int cafe_vidioc_querybuf(struct file *filp, void *priv,
1311 int ret = -EINVAL; 1214 int ret = -EINVAL;
1312 1215
1313 mutex_lock(&cam->s_mutex); 1216 mutex_lock(&cam->s_mutex);
1314 if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 1217 if (buf->index >= cam->n_sbufs)
1315 goto out;
1316 if (buf->index < 0 || buf->index >= cam->n_sbufs)
1317 goto out; 1218 goto out;
1318 *buf = cam->sb_bufs[buf->index].v4lbuf; 1219 *buf = cam->sb_bufs[buf->index].v4lbuf;
1319 ret = 0; 1220 ret = 0;
@@ -1331,9 +1232,7 @@ static int cafe_vidioc_qbuf(struct file *filp, void *priv,
1331 unsigned long flags; 1232 unsigned long flags;
1332 1233
1333 mutex_lock(&cam->s_mutex); 1234 mutex_lock(&cam->s_mutex);
1334 if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 1235 if (buf->index >= cam->n_sbufs)
1335 goto out;
1336 if (buf->index < 0 || buf->index >= cam->n_sbufs)
1337 goto out; 1236 goto out;
1338 sbuf = cam->sb_bufs + buf->index; 1237 sbuf = cam->sb_bufs + buf->index;
1339 if (sbuf->v4lbuf.flags & V4L2_BUF_FLAG_QUEUED) { 1238 if (sbuf->v4lbuf.flags & V4L2_BUF_FLAG_QUEUED) {
@@ -1364,8 +1263,6 @@ static int cafe_vidioc_dqbuf(struct file *filp, void *priv,
1364 unsigned long flags; 1263 unsigned long flags;
1365 1264
1366 mutex_lock(&cam->s_mutex); 1265 mutex_lock(&cam->s_mutex);
1367 if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1368 goto out_unlock;
1369 if (cam->state != S_STREAMING) 1266 if (cam->state != S_STREAMING)
1370 goto out_unlock; 1267 goto out_unlock;
1371 if (list_empty(&cam->sb_full) && filp->f_flags & O_NONBLOCK) { 1268 if (list_empty(&cam->sb_full) && filp->f_flags & O_NONBLOCK) {
@@ -1474,11 +1371,8 @@ static int cafe_v4l_mmap(struct file *filp, struct vm_area_struct *vma)
1474 1371
1475static int cafe_v4l_open(struct file *filp) 1372static int cafe_v4l_open(struct file *filp)
1476{ 1373{
1477 struct cafe_camera *cam; 1374 struct cafe_camera *cam = video_drvdata(filp);
1478 1375
1479 cam = cafe_find_dev(video_devdata(filp)->minor);
1480 if (cam == NULL)
1481 return -ENODEV;
1482 filp->private_data = cam; 1376 filp->private_data = cam;
1483 1377
1484 mutex_lock(&cam->s_mutex); 1378 mutex_lock(&cam->s_mutex);
@@ -1532,11 +1426,11 @@ static unsigned int cafe_v4l_poll(struct file *filp,
1532static int cafe_vidioc_queryctrl(struct file *filp, void *priv, 1426static int cafe_vidioc_queryctrl(struct file *filp, void *priv,
1533 struct v4l2_queryctrl *qc) 1427 struct v4l2_queryctrl *qc)
1534{ 1428{
1535 struct cafe_camera *cam = filp->private_data; 1429 struct cafe_camera *cam = priv;
1536 int ret; 1430 int ret;
1537 1431
1538 mutex_lock(&cam->s_mutex); 1432 mutex_lock(&cam->s_mutex);
1539 ret = __cafe_cam_cmd(cam, VIDIOC_QUERYCTRL, qc); 1433 ret = sensor_call(cam, core, queryctrl, qc);
1540 mutex_unlock(&cam->s_mutex); 1434 mutex_unlock(&cam->s_mutex);
1541 return ret; 1435 return ret;
1542} 1436}
@@ -1545,11 +1439,11 @@ static int cafe_vidioc_queryctrl(struct file *filp, void *priv,
1545static int cafe_vidioc_g_ctrl(struct file *filp, void *priv, 1439static int cafe_vidioc_g_ctrl(struct file *filp, void *priv,
1546 struct v4l2_control *ctrl) 1440 struct v4l2_control *ctrl)
1547{ 1441{
1548 struct cafe_camera *cam = filp->private_data; 1442 struct cafe_camera *cam = priv;
1549 int ret; 1443 int ret;
1550 1444
1551 mutex_lock(&cam->s_mutex); 1445 mutex_lock(&cam->s_mutex);
1552 ret = __cafe_cam_cmd(cam, VIDIOC_G_CTRL, ctrl); 1446 ret = sensor_call(cam, core, g_ctrl, ctrl);
1553 mutex_unlock(&cam->s_mutex); 1447 mutex_unlock(&cam->s_mutex);
1554 return ret; 1448 return ret;
1555} 1449}
@@ -1558,11 +1452,11 @@ static int cafe_vidioc_g_ctrl(struct file *filp, void *priv,
1558static int cafe_vidioc_s_ctrl(struct file *filp, void *priv, 1452static int cafe_vidioc_s_ctrl(struct file *filp, void *priv,
1559 struct v4l2_control *ctrl) 1453 struct v4l2_control *ctrl)
1560{ 1454{
1561 struct cafe_camera *cam = filp->private_data; 1455 struct cafe_camera *cam = priv;
1562 int ret; 1456 int ret;
1563 1457
1564 mutex_lock(&cam->s_mutex); 1458 mutex_lock(&cam->s_mutex);
1565 ret = __cafe_cam_cmd(cam, VIDIOC_S_CTRL, ctrl); 1459 ret = sensor_call(cam, core, s_ctrl, ctrl);
1566 mutex_unlock(&cam->s_mutex); 1460 mutex_unlock(&cam->s_mutex);
1567 return ret; 1461 return ret;
1568} 1462}
@@ -1601,10 +1495,8 @@ static int cafe_vidioc_enum_fmt_vid_cap(struct file *filp,
1601 struct cafe_camera *cam = priv; 1495 struct cafe_camera *cam = priv;
1602 int ret; 1496 int ret;
1603 1497
1604 if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1605 return -EINVAL;
1606 mutex_lock(&cam->s_mutex); 1498 mutex_lock(&cam->s_mutex);
1607 ret = __cafe_cam_cmd(cam, VIDIOC_ENUM_FMT, fmt); 1499 ret = sensor_call(cam, video, enum_fmt, fmt);
1608 mutex_unlock(&cam->s_mutex); 1500 mutex_unlock(&cam->s_mutex);
1609 return ret; 1501 return ret;
1610} 1502}
@@ -1617,7 +1509,7 @@ static int cafe_vidioc_try_fmt_vid_cap(struct file *filp, void *priv,
1617 int ret; 1509 int ret;
1618 1510
1619 mutex_lock(&cam->s_mutex); 1511 mutex_lock(&cam->s_mutex);
1620 ret = __cafe_cam_cmd(cam, VIDIOC_TRY_FMT, fmt); 1512 ret = sensor_call(cam, video, try_fmt, fmt);
1621 mutex_unlock(&cam->s_mutex); 1513 mutex_unlock(&cam->s_mutex);
1622 return ret; 1514 return ret;
1623} 1515}
@@ -1726,7 +1618,7 @@ static int cafe_vidioc_g_parm(struct file *filp, void *priv,
1726 int ret; 1618 int ret;
1727 1619
1728 mutex_lock(&cam->s_mutex); 1620 mutex_lock(&cam->s_mutex);
1729 ret = __cafe_cam_cmd(cam, VIDIOC_G_PARM, parms); 1621 ret = sensor_call(cam, video, g_parm, parms);
1730 mutex_unlock(&cam->s_mutex); 1622 mutex_unlock(&cam->s_mutex);
1731 parms->parm.capture.readbuffers = n_dma_bufs; 1623 parms->parm.capture.readbuffers = n_dma_bufs;
1732 return ret; 1624 return ret;
@@ -1739,20 +1631,52 @@ static int cafe_vidioc_s_parm(struct file *filp, void *priv,
1739 int ret; 1631 int ret;
1740 1632
1741 mutex_lock(&cam->s_mutex); 1633 mutex_lock(&cam->s_mutex);
1742 ret = __cafe_cam_cmd(cam, VIDIOC_S_PARM, parms); 1634 ret = sensor_call(cam, video, s_parm, parms);
1743 mutex_unlock(&cam->s_mutex); 1635 mutex_unlock(&cam->s_mutex);
1744 parms->parm.capture.readbuffers = n_dma_bufs; 1636 parms->parm.capture.readbuffers = n_dma_bufs;
1745 return ret; 1637 return ret;
1746} 1638}
1747 1639
1640static int cafe_vidioc_g_chip_ident(struct file *file, void *priv,
1641 struct v4l2_dbg_chip_ident *chip)
1642{
1643 struct cafe_camera *cam = priv;
1748 1644
1749static void cafe_v4l_dev_release(struct video_device *vd) 1645 chip->ident = V4L2_IDENT_NONE;
1646 chip->revision = 0;
1647 if (v4l2_chip_match_host(&chip->match)) {
1648 chip->ident = V4L2_IDENT_CAFE;
1649 return 0;
1650 }
1651 return sensor_call(cam, core, g_chip_ident, chip);
1652}
1653
1654#ifdef CONFIG_VIDEO_ADV_DEBUG
1655static int cafe_vidioc_g_register(struct file *file, void *priv,
1656 struct v4l2_dbg_register *reg)
1750{ 1657{
1751 struct cafe_camera *cam = container_of(vd, struct cafe_camera, v4ldev); 1658 struct cafe_camera *cam = priv;
1752 1659
1753 kfree(cam); 1660 if (v4l2_chip_match_host(&reg->match)) {
1661 reg->val = cafe_reg_read(cam, reg->reg);
1662 reg->size = 4;
1663 return 0;
1664 }
1665 return sensor_call(cam, core, g_register, reg);
1754} 1666}
1755 1667
1668static int cafe_vidioc_s_register(struct file *file, void *priv,
1669 struct v4l2_dbg_register *reg)
1670{
1671 struct cafe_camera *cam = priv;
1672
1673 if (v4l2_chip_match_host(&reg->match)) {
1674 cafe_reg_write(cam, reg->reg, reg->val);
1675 return 0;
1676 }
1677 return sensor_call(cam, core, s_register, reg);
1678}
1679#endif
1756 1680
1757/* 1681/*
1758 * This template device holds all of those v4l2 methods; we 1682 * This template device holds all of those v4l2 methods; we
@@ -1790,6 +1714,11 @@ static const struct v4l2_ioctl_ops cafe_v4l_ioctl_ops = {
1790 .vidioc_s_ctrl = cafe_vidioc_s_ctrl, 1714 .vidioc_s_ctrl = cafe_vidioc_s_ctrl,
1791 .vidioc_g_parm = cafe_vidioc_g_parm, 1715 .vidioc_g_parm = cafe_vidioc_g_parm,
1792 .vidioc_s_parm = cafe_vidioc_s_parm, 1716 .vidioc_s_parm = cafe_vidioc_s_parm,
1717 .vidioc_g_chip_ident = cafe_vidioc_g_chip_ident,
1718#ifdef CONFIG_VIDEO_ADV_DEBUG
1719 .vidioc_g_register = cafe_vidioc_g_register,
1720 .vidioc_s_register = cafe_vidioc_s_register,
1721#endif
1793}; 1722};
1794 1723
1795static struct video_device cafe_v4l_template = { 1724static struct video_device cafe_v4l_template = {
@@ -1800,15 +1729,10 @@ static struct video_device cafe_v4l_template = {
1800 1729
1801 .fops = &cafe_v4l_fops, 1730 .fops = &cafe_v4l_fops,
1802 .ioctl_ops = &cafe_v4l_ioctl_ops, 1731 .ioctl_ops = &cafe_v4l_ioctl_ops,
1803 .release = cafe_v4l_dev_release, 1732 .release = video_device_release_empty,
1804}; 1733};
1805 1734
1806 1735
1807
1808
1809
1810
1811
1812/* ---------------------------------------------------------------------- */ 1736/* ---------------------------------------------------------------------- */
1813/* 1737/*
1814 * Interrupt handler stuff 1738 * Interrupt handler stuff
@@ -1962,127 +1886,6 @@ static irqreturn_t cafe_irq(int irq, void *data)
1962 1886
1963 1887
1964/* -------------------------------------------------------------------------- */ 1888/* -------------------------------------------------------------------------- */
1965#ifdef CONFIG_VIDEO_ADV_DEBUG
1966/*
1967 * Debugfs stuff.
1968 */
1969
1970static char cafe_debug_buf[1024];
1971static struct dentry *cafe_dfs_root;
1972
1973static void cafe_dfs_setup(void)
1974{
1975 cafe_dfs_root = debugfs_create_dir("cafe_ccic", NULL);
1976 if (IS_ERR(cafe_dfs_root)) {
1977 cafe_dfs_root = NULL; /* Never mind */
1978 printk(KERN_NOTICE "cafe_ccic unable to set up debugfs\n");
1979 }
1980}
1981
1982static void cafe_dfs_shutdown(void)
1983{
1984 if (cafe_dfs_root)
1985 debugfs_remove(cafe_dfs_root);
1986}
1987
1988static int cafe_dfs_open(struct inode *inode, struct file *file)
1989{
1990 file->private_data = inode->i_private;
1991 return 0;
1992}
1993
1994static ssize_t cafe_dfs_read_regs(struct file *file,
1995 char __user *buf, size_t count, loff_t *ppos)
1996{
1997 struct cafe_camera *cam = file->private_data;
1998 char *s = cafe_debug_buf;
1999 int offset;
2000
2001 for (offset = 0; offset < 0x44; offset += 4)
2002 s += sprintf(s, "%02x: %08x\n", offset,
2003 cafe_reg_read(cam, offset));
2004 for (offset = 0x88; offset <= 0x90; offset += 4)
2005 s += sprintf(s, "%02x: %08x\n", offset,
2006 cafe_reg_read(cam, offset));
2007 for (offset = 0xb4; offset <= 0xbc; offset += 4)
2008 s += sprintf(s, "%02x: %08x\n", offset,
2009 cafe_reg_read(cam, offset));
2010 for (offset = 0x3000; offset <= 0x300c; offset += 4)
2011 s += sprintf(s, "%04x: %08x\n", offset,
2012 cafe_reg_read(cam, offset));
2013 return simple_read_from_buffer(buf, count, ppos, cafe_debug_buf,
2014 s - cafe_debug_buf);
2015}
2016
2017static const struct file_operations cafe_dfs_reg_ops = {
2018 .owner = THIS_MODULE,
2019 .read = cafe_dfs_read_regs,
2020 .open = cafe_dfs_open
2021};
2022
2023static ssize_t cafe_dfs_read_cam(struct file *file,
2024 char __user *buf, size_t count, loff_t *ppos)
2025{
2026 struct cafe_camera *cam = file->private_data;
2027 char *s = cafe_debug_buf;
2028 int offset;
2029
2030 if (! cam->sensor)
2031 return -EINVAL;
2032 for (offset = 0x0; offset < 0x8a; offset++)
2033 {
2034 u8 v;
2035
2036 cafe_smbus_read_data(cam, cam->sensor->addr, offset, &v);
2037 s += sprintf(s, "%02x: %02x\n", offset, v);
2038 }
2039 return simple_read_from_buffer(buf, count, ppos, cafe_debug_buf,
2040 s - cafe_debug_buf);
2041}
2042
2043static const struct file_operations cafe_dfs_cam_ops = {
2044 .owner = THIS_MODULE,
2045 .read = cafe_dfs_read_cam,
2046 .open = cafe_dfs_open
2047};
2048
2049
2050
2051static void cafe_dfs_cam_setup(struct cafe_camera *cam)
2052{
2053 char fname[40];
2054
2055 if (!cafe_dfs_root)
2056 return;
2057 sprintf(fname, "regs-%d", cam->v4ldev.num);
2058 cam->dfs_regs = debugfs_create_file(fname, 0444, cafe_dfs_root,
2059 cam, &cafe_dfs_reg_ops);
2060 sprintf(fname, "cam-%d", cam->v4ldev.num);
2061 cam->dfs_cam_regs = debugfs_create_file(fname, 0444, cafe_dfs_root,
2062 cam, &cafe_dfs_cam_ops);
2063}
2064
2065
2066static void cafe_dfs_cam_shutdown(struct cafe_camera *cam)
2067{
2068 if (! IS_ERR(cam->dfs_regs))
2069 debugfs_remove(cam->dfs_regs);
2070 if (! IS_ERR(cam->dfs_cam_regs))
2071 debugfs_remove(cam->dfs_cam_regs);
2072}
2073
2074#else
2075
2076#define cafe_dfs_setup()
2077#define cafe_dfs_shutdown()
2078#define cafe_dfs_cam_setup(cam)
2079#define cafe_dfs_cam_shutdown(cam)
2080#endif /* CONFIG_VIDEO_ADV_DEBUG */
2081
2082
2083
2084
2085/* ------------------------------------------------------------------------*/
2086/* 1889/*
2087 * PCI interface stuff. 1890 * PCI interface stuff.
2088 */ 1891 */
@@ -2100,6 +1903,10 @@ static int cafe_pci_probe(struct pci_dev *pdev,
2100 cam = kzalloc(sizeof(struct cafe_camera), GFP_KERNEL); 1903 cam = kzalloc(sizeof(struct cafe_camera), GFP_KERNEL);
2101 if (cam == NULL) 1904 if (cam == NULL)
2102 goto out; 1905 goto out;
1906 ret = v4l2_device_register(&pdev->dev, &cam->v4l2_dev);
1907 if (ret)
1908 goto out_free;
1909
2103 mutex_init(&cam->s_mutex); 1910 mutex_init(&cam->s_mutex);
2104 mutex_lock(&cam->s_mutex); 1911 mutex_lock(&cam->s_mutex);
2105 spin_lock_init(&cam->dev_lock); 1912 spin_lock_init(&cam->dev_lock);
@@ -2118,14 +1925,14 @@ static int cafe_pci_probe(struct pci_dev *pdev,
2118 */ 1925 */
2119 ret = pci_enable_device(pdev); 1926 ret = pci_enable_device(pdev);
2120 if (ret) 1927 if (ret)
2121 goto out_free; 1928 goto out_unreg;
2122 pci_set_master(pdev); 1929 pci_set_master(pdev);
2123 1930
2124 ret = -EIO; 1931 ret = -EIO;
2125 cam->regs = pci_iomap(pdev, 0, 0); 1932 cam->regs = pci_iomap(pdev, 0, 0);
2126 if (! cam->regs) { 1933 if (! cam->regs) {
2127 printk(KERN_ERR "Unable to ioremap cafe-ccic regs\n"); 1934 printk(KERN_ERR "Unable to ioremap cafe-ccic regs\n");
2128 goto out_free; 1935 goto out_unreg;
2129 } 1936 }
2130 ret = request_irq(pdev->irq, cafe_irq, IRQF_SHARED, "cafe-ccic", cam); 1937 ret = request_irq(pdev->irq, cafe_irq, IRQF_SHARED, "cafe-ccic", cam);
2131 if (ret) 1938 if (ret)
@@ -2145,17 +1952,31 @@ static int cafe_pci_probe(struct pci_dev *pdev,
2145 ret = cafe_smbus_setup(cam); 1952 ret = cafe_smbus_setup(cam);
2146 if (ret) 1953 if (ret)
2147 goto out_freeirq; 1954 goto out_freeirq;
1955
1956 cam->sensor_addr = 0x42;
1957 cam->sensor = v4l2_i2c_new_subdev(&cam->i2c_adapter,
1958 "ov7670", "ov7670", cam->sensor_addr);
1959 if (cam->sensor == NULL) {
1960 ret = -ENODEV;
1961 goto out_smbus;
1962 }
1963 ret = cafe_cam_init(cam);
1964 if (ret)
1965 goto out_smbus;
1966
2148 /* 1967 /*
2149 * Get the v4l2 setup done. 1968 * Get the v4l2 setup done.
2150 */ 1969 */
2151 mutex_lock(&cam->s_mutex); 1970 mutex_lock(&cam->s_mutex);
2152 cam->v4ldev = cafe_v4l_template; 1971 cam->vdev = cafe_v4l_template;
2153 cam->v4ldev.debug = 0; 1972 cam->vdev.debug = 0;
2154// cam->v4ldev.debug = V4L2_DEBUG_IOCTL_ARG; 1973/* cam->vdev.debug = V4L2_DEBUG_IOCTL_ARG;*/
2155 cam->v4ldev.parent = &pdev->dev; 1974 cam->vdev.v4l2_dev = &cam->v4l2_dev;
2156 ret = video_register_device(&cam->v4ldev, VFL_TYPE_GRABBER, -1); 1975 ret = video_register_device(&cam->vdev, VFL_TYPE_GRABBER, -1);
2157 if (ret) 1976 if (ret)
2158 goto out_smbus; 1977 goto out_smbus;
1978 video_set_drvdata(&cam->vdev, cam);
1979
2159 /* 1980 /*
2160 * If so requested, try to get our DMA buffers now. 1981 * If so requested, try to get our DMA buffers now.
2161 */ 1982 */
@@ -2165,21 +1986,21 @@ static int cafe_pci_probe(struct pci_dev *pdev,
2165 " will try again later."); 1986 " will try again later.");
2166 } 1987 }
2167 1988
2168 cafe_dfs_cam_setup(cam);
2169 mutex_unlock(&cam->s_mutex); 1989 mutex_unlock(&cam->s_mutex);
2170 cafe_add_dev(cam);
2171 return 0; 1990 return 0;
2172 1991
2173 out_smbus: 1992out_smbus:
2174 cafe_smbus_shutdown(cam); 1993 cafe_smbus_shutdown(cam);
2175 out_freeirq: 1994out_freeirq:
2176 cafe_ctlr_power_down(cam); 1995 cafe_ctlr_power_down(cam);
2177 free_irq(pdev->irq, cam); 1996 free_irq(pdev->irq, cam);
2178 out_iounmap: 1997out_iounmap:
2179 pci_iounmap(pdev, cam->regs); 1998 pci_iounmap(pdev, cam->regs);
2180 out_free: 1999out_free:
2000 v4l2_device_unregister(&cam->v4l2_dev);
2001out_unreg:
2181 kfree(cam); 2002 kfree(cam);
2182 out: 2003out:
2183 return ret; 2004 return ret;
2184} 2005}
2185 2006
@@ -2190,25 +2011,23 @@ static int cafe_pci_probe(struct pci_dev *pdev,
2190static void cafe_shutdown(struct cafe_camera *cam) 2011static void cafe_shutdown(struct cafe_camera *cam)
2191{ 2012{
2192/* FIXME: Make sure we take care of everything here */ 2013/* FIXME: Make sure we take care of everything here */
2193 cafe_dfs_cam_shutdown(cam);
2194 if (cam->n_sbufs > 0) 2014 if (cam->n_sbufs > 0)
2195 /* What if they are still mapped? Shouldn't be, but... */ 2015 /* What if they are still mapped? Shouldn't be, but... */
2196 cafe_free_sio_buffers(cam); 2016 cafe_free_sio_buffers(cam);
2197 cafe_remove_dev(cam);
2198 cafe_ctlr_stop_dma(cam); 2017 cafe_ctlr_stop_dma(cam);
2199 cafe_ctlr_power_down(cam); 2018 cafe_ctlr_power_down(cam);
2200 cafe_smbus_shutdown(cam); 2019 cafe_smbus_shutdown(cam);
2201 cafe_free_dma_bufs(cam); 2020 cafe_free_dma_bufs(cam);
2202 free_irq(cam->pdev->irq, cam); 2021 free_irq(cam->pdev->irq, cam);
2203 pci_iounmap(cam->pdev, cam->regs); 2022 pci_iounmap(cam->pdev, cam->regs);
2204 video_unregister_device(&cam->v4ldev); 2023 video_unregister_device(&cam->vdev);
2205 /* kfree(cam); done in v4l_release () */
2206} 2024}
2207 2025
2208 2026
2209static void cafe_pci_remove(struct pci_dev *pdev) 2027static void cafe_pci_remove(struct pci_dev *pdev)
2210{ 2028{
2211 struct cafe_camera *cam = cafe_find_by_pdev(pdev); 2029 struct v4l2_device *v4l2_dev = dev_get_drvdata(&pdev->dev);
2030 struct cafe_camera *cam = to_cam(v4l2_dev);
2212 2031
2213 if (cam == NULL) { 2032 if (cam == NULL) {
2214 printk(KERN_WARNING "pci_remove on unknown pdev %p\n", pdev); 2033 printk(KERN_WARNING "pci_remove on unknown pdev %p\n", pdev);
@@ -2218,6 +2037,8 @@ static void cafe_pci_remove(struct pci_dev *pdev)
2218 if (cam->users > 0) 2037 if (cam->users > 0)
2219 cam_warn(cam, "Removing a device with users!\n"); 2038 cam_warn(cam, "Removing a device with users!\n");
2220 cafe_shutdown(cam); 2039 cafe_shutdown(cam);
2040 v4l2_device_unregister(&cam->v4l2_dev);
2041 kfree(cam);
2221/* No unlock - it no longer exists */ 2042/* No unlock - it no longer exists */
2222} 2043}
2223 2044
@@ -2228,7 +2049,8 @@ static void cafe_pci_remove(struct pci_dev *pdev)
2228 */ 2049 */
2229static int cafe_pci_suspend(struct pci_dev *pdev, pm_message_t state) 2050static int cafe_pci_suspend(struct pci_dev *pdev, pm_message_t state)
2230{ 2051{
2231 struct cafe_camera *cam = cafe_find_by_pdev(pdev); 2052 struct v4l2_device *v4l2_dev = dev_get_drvdata(&pdev->dev);
2053 struct cafe_camera *cam = to_cam(v4l2_dev);
2232 int ret; 2054 int ret;
2233 enum cafe_state cstate; 2055 enum cafe_state cstate;
2234 2056
@@ -2246,7 +2068,8 @@ static int cafe_pci_suspend(struct pci_dev *pdev, pm_message_t state)
2246 2068
2247static int cafe_pci_resume(struct pci_dev *pdev) 2069static int cafe_pci_resume(struct pci_dev *pdev)
2248{ 2070{
2249 struct cafe_camera *cam = cafe_find_by_pdev(pdev); 2071 struct v4l2_device *v4l2_dev = dev_get_drvdata(&pdev->dev);
2072 struct cafe_camera *cam = to_cam(v4l2_dev);
2250 int ret = 0; 2073 int ret = 0;
2251 2074
2252 ret = pci_restore_state(pdev); 2075 ret = pci_restore_state(pdev);
@@ -2307,13 +2130,11 @@ static int __init cafe_init(void)
2307 2130
2308 printk(KERN_NOTICE "Marvell M88ALP01 'CAFE' Camera Controller version %d\n", 2131 printk(KERN_NOTICE "Marvell M88ALP01 'CAFE' Camera Controller version %d\n",
2309 CAFE_VERSION); 2132 CAFE_VERSION);
2310 cafe_dfs_setup();
2311 ret = pci_register_driver(&cafe_pci_driver); 2133 ret = pci_register_driver(&cafe_pci_driver);
2312 if (ret) { 2134 if (ret) {
2313 printk(KERN_ERR "Unable to register cafe_ccic driver\n"); 2135 printk(KERN_ERR "Unable to register cafe_ccic driver\n");
2314 goto out; 2136 goto out;
2315 } 2137 }
2316 request_module("ov7670"); /* FIXME want something more general */
2317 ret = 0; 2138 ret = 0;
2318 2139
2319 out: 2140 out:
@@ -2324,7 +2145,6 @@ static int __init cafe_init(void)
2324static void __exit cafe_exit(void) 2145static void __exit cafe_exit(void)
2325{ 2146{
2326 pci_unregister_driver(&cafe_pci_driver); 2147 pci_unregister_driver(&cafe_pci_driver);
2327 cafe_dfs_shutdown();
2328} 2148}
2329 2149
2330module_init(cafe_init); 2150module_init(cafe_init);
diff --git a/drivers/media/video/cpia2/cpia2_v4l.c b/drivers/media/video/cpia2/cpia2_v4l.c
index 9c25894fdd8e..d4099f5312ac 100644
--- a/drivers/media/video/cpia2/cpia2_v4l.c
+++ b/drivers/media/video/cpia2/cpia2_v4l.c
@@ -37,6 +37,7 @@
37#include <linux/sched.h> 37#include <linux/sched.h>
38#include <linux/slab.h> 38#include <linux/slab.h>
39#include <linux/init.h> 39#include <linux/init.h>
40#include <linux/videodev.h>
40#include <media/v4l2-ioctl.h> 41#include <media/v4l2-ioctl.h>
41 42
42#include "cpia2.h" 43#include "cpia2.h"
diff --git a/drivers/media/video/cs5345.c b/drivers/media/video/cs5345.c
index 87e91072627a..9714059ee949 100644
--- a/drivers/media/video/cs5345.c
+++ b/drivers/media/video/cs5345.c
@@ -141,11 +141,6 @@ static int cs5345_log_status(struct v4l2_subdev *sd)
141 return 0; 141 return 0;
142} 142}
143 143
144static int cs5345_command(struct i2c_client *client, unsigned cmd, void *arg)
145{
146 return v4l2_subdev_command(i2c_get_clientdata(client), cmd, arg);
147}
148
149/* ----------------------------------------------------------------------- */ 144/* ----------------------------------------------------------------------- */
150 145
151static const struct v4l2_subdev_core_ops cs5345_core_ops = { 146static const struct v4l2_subdev_core_ops cs5345_core_ops = {
@@ -214,8 +209,6 @@ MODULE_DEVICE_TABLE(i2c, cs5345_id);
214 209
215static struct v4l2_i2c_driver_data v4l2_i2c_data = { 210static struct v4l2_i2c_driver_data v4l2_i2c_data = {
216 .name = "cs5345", 211 .name = "cs5345",
217 .driverid = I2C_DRIVERID_CS5345,
218 .command = cs5345_command,
219 .probe = cs5345_probe, 212 .probe = cs5345_probe,
220 .remove = cs5345_remove, 213 .remove = cs5345_remove,
221 .id_table = cs5345_id, 214 .id_table = cs5345_id,
diff --git a/drivers/media/video/cs53l32a.c b/drivers/media/video/cs53l32a.c
index 7292a6316e63..5aeb066857a7 100644
--- a/drivers/media/video/cs53l32a.c
+++ b/drivers/media/video/cs53l32a.c
@@ -29,7 +29,7 @@
29#include <linux/videodev2.h> 29#include <linux/videodev2.h>
30#include <media/v4l2-device.h> 30#include <media/v4l2-device.h>
31#include <media/v4l2-chip-ident.h> 31#include <media/v4l2-chip-ident.h>
32#include <media/v4l2-i2c-drv-legacy.h> 32#include <media/v4l2-i2c-drv.h>
33 33
34MODULE_DESCRIPTION("i2c device driver for cs53l32a Audio ADC"); 34MODULE_DESCRIPTION("i2c device driver for cs53l32a Audio ADC");
35MODULE_AUTHOR("Martin Vaughan"); 35MODULE_AUTHOR("Martin Vaughan");
@@ -41,9 +41,6 @@ module_param(debug, bool, 0644);
41 41
42MODULE_PARM_DESC(debug, "Debugging messages, 0=Off (default), 1=On"); 42MODULE_PARM_DESC(debug, "Debugging messages, 0=Off (default), 1=On");
43 43
44static unsigned short normal_i2c[] = { 0x22 >> 1, I2C_CLIENT_END };
45
46I2C_CLIENT_INSMOD;
47 44
48/* ----------------------------------------------------------------------- */ 45/* ----------------------------------------------------------------------- */
49 46
@@ -122,11 +119,6 @@ static int cs53l32a_log_status(struct v4l2_subdev *sd)
122 return 0; 119 return 0;
123} 120}
124 121
125static int cs53l32a_command(struct i2c_client *client, unsigned cmd, void *arg)
126{
127 return v4l2_subdev_command(i2c_get_clientdata(client), cmd, arg);
128}
129
130/* ----------------------------------------------------------------------- */ 122/* ----------------------------------------------------------------------- */
131 123
132static const struct v4l2_subdev_core_ops cs53l32a_core_ops = { 124static const struct v4l2_subdev_core_ops cs53l32a_core_ops = {
@@ -218,8 +210,6 @@ MODULE_DEVICE_TABLE(i2c, cs53l32a_id);
218 210
219static struct v4l2_i2c_driver_data v4l2_i2c_data = { 211static struct v4l2_i2c_driver_data v4l2_i2c_data = {
220 .name = "cs53l32a", 212 .name = "cs53l32a",
221 .driverid = I2C_DRIVERID_CS53L32A,
222 .command = cs53l32a_command,
223 .remove = cs53l32a_remove, 213 .remove = cs53l32a_remove,
224 .probe = cs53l32a_probe, 214 .probe = cs53l32a_probe,
225 .id_table = cs53l32a_id, 215 .id_table = cs53l32a_id,
diff --git a/drivers/media/video/cx18/Kconfig b/drivers/media/video/cx18/Kconfig
index 8940b5387dec..e8a50a611ebc 100644
--- a/drivers/media/video/cx18/Kconfig
+++ b/drivers/media/video/cx18/Kconfig
@@ -9,7 +9,7 @@ config VIDEO_CX18
9 select VIDEO_CX2341X 9 select VIDEO_CX2341X
10 select VIDEO_CS5345 10 select VIDEO_CS5345
11 select DVB_S5H1409 if !DVB_FE_CUSTOMISE 11 select DVB_S5H1409 if !DVB_FE_CUSTOMISE
12 select MEDIA_TUNER_MXL5005S if !MEDIA_TUNER_CUSTOMIZE 12 select MEDIA_TUNER_MXL5005S if !MEDIA_TUNER_CUSTOMISE
13 ---help--- 13 ---help---
14 This is a video4linux driver for Conexant cx23418 based 14 This is a video4linux driver for Conexant cx23418 based
15 PCI combo video recorder devices. 15 PCI combo video recorder devices.
diff --git a/drivers/media/video/cx18/cx18-audio.c b/drivers/media/video/cx18/cx18-audio.c
index 57beddf0af4d..bb5c5165dd5f 100644
--- a/drivers/media/video/cx18/cx18-audio.c
+++ b/drivers/media/video/cx18/cx18-audio.c
@@ -23,7 +23,6 @@
23 23
24#include "cx18-driver.h" 24#include "cx18-driver.h"
25#include "cx18-io.h" 25#include "cx18-io.h"
26#include "cx18-i2c.h"
27#include "cx18-cards.h" 26#include "cx18-cards.h"
28#include "cx18-audio.h" 27#include "cx18-audio.h"
29 28
@@ -33,55 +32,32 @@
33 settings. */ 32 settings. */
34int cx18_audio_set_io(struct cx18 *cx) 33int cx18_audio_set_io(struct cx18 *cx)
35{ 34{
35 const struct cx18_card_audio_input *in;
36 struct v4l2_routing route; 36 struct v4l2_routing route;
37 u32 audio_input;
38 u32 val; 37 u32 val;
39 int mux_input;
40 int err; 38 int err;
41 39
42 /* Determine which input to use */ 40 /* Determine which input to use */
43 if (test_bit(CX18_F_I_RADIO_USER, &cx->i_flags)) { 41 if (test_bit(CX18_F_I_RADIO_USER, &cx->i_flags))
44 audio_input = cx->card->radio_input.audio_input; 42 in = &cx->card->radio_input;
45 mux_input = cx->card->radio_input.muxer_input; 43 else
46 } else { 44 in = &cx->card->audio_inputs[cx->audio_input];
47 audio_input =
48 cx->card->audio_inputs[cx->audio_input].audio_input;
49 mux_input =
50 cx->card->audio_inputs[cx->audio_input].muxer_input;
51 }
52 45
53 /* handle muxer chips */ 46 /* handle muxer chips */
54 route.input = mux_input; 47 route.input = in->muxer_input;
55 route.output = 0; 48 route.output = 0;
56 cx18_i2c_hw(cx, cx->card->hw_muxer, VIDIOC_INT_S_AUDIO_ROUTING, &route); 49 v4l2_subdev_call(cx->sd_extmux, audio, s_routing, &route);
57 50
58 route.input = audio_input; 51 route.input = in->audio_input;
59 err = cx18_i2c_hw(cx, cx->card->hw_audio_ctrl, 52 err = cx18_call_hw_err(cx, cx->card->hw_audio_ctrl,
60 VIDIOC_INT_S_AUDIO_ROUTING, &route); 53 audio, s_routing, &route);
61 if (err) 54 if (err)
62 return err; 55 return err;
63 56
57 /* FIXME - this internal mux should be abstracted to a subdev */
64 val = cx18_read_reg(cx, CX18_AUDIO_ENABLE) & ~0x30; 58 val = cx18_read_reg(cx, CX18_AUDIO_ENABLE) & ~0x30;
65 val |= (audio_input > CX18_AV_AUDIO_SERIAL2) ? 0x20 : 59 val |= (in->audio_input > CX18_AV_AUDIO_SERIAL2) ? 0x20 :
66 (audio_input << 4); 60 (in->audio_input << 4);
67 cx18_write_reg(cx, val | 0xb00, CX18_AUDIO_ENABLE); 61 cx18_write_reg_expect(cx, val | 0xb00, CX18_AUDIO_ENABLE, val, 0x30);
68 cx18_vapi(cx, CX18_APU_RESETAI, 1, 0);
69 return 0; 62 return 0;
70} 63}
71
72void cx18_audio_set_route(struct cx18 *cx, struct v4l2_routing *route)
73{
74 cx18_i2c_hw(cx, cx->card->hw_audio_ctrl,
75 VIDIOC_INT_S_AUDIO_ROUTING, route);
76}
77
78void cx18_audio_set_audio_clock_freq(struct cx18 *cx, u8 freq)
79{
80 static u32 freqs[3] = { 44100, 48000, 32000 };
81
82 /* The audio clock of the digitizer must match the codec sample
83 rate otherwise you get some very strange effects. */
84 if (freq > 2)
85 return;
86 cx18_call_i2c_clients(cx, VIDIOC_INT_AUDIO_CLOCK_FREQ, &freqs[freq]);
87}
diff --git a/drivers/media/video/cx18/cx18-audio.h b/drivers/media/video/cx18/cx18-audio.h
index cb569a69379c..2731d29b0ab9 100644
--- a/drivers/media/video/cx18/cx18-audio.h
+++ b/drivers/media/video/cx18/cx18-audio.h
@@ -22,5 +22,3 @@
22 */ 22 */
23 23
24int cx18_audio_set_io(struct cx18 *cx); 24int cx18_audio_set_io(struct cx18 *cx);
25void cx18_audio_set_route(struct cx18 *cx, struct v4l2_routing *route);
26void cx18_audio_set_audio_clock_freq(struct cx18 *cx, u8 freq);
diff --git a/drivers/media/video/cx18/cx18-av-audio.c b/drivers/media/video/cx18/cx18-av-audio.c
index a2f0ad570434..9e30983f2ff6 100644
--- a/drivers/media/video/cx18/cx18-av-audio.c
+++ b/drivers/media/video/cx18/cx18-av-audio.c
@@ -464,82 +464,76 @@ static void set_mute(struct cx18 *cx, int mute)
464 } 464 }
465} 465}
466 466
467int cx18_av_audio(struct cx18 *cx, unsigned int cmd, void *arg) 467int cx18_av_s_clock_freq(struct v4l2_subdev *sd, u32 freq)
468{ 468{
469 struct cx18 *cx = v4l2_get_subdevdata(sd);
469 struct cx18_av_state *state = &cx->av_state; 470 struct cx18_av_state *state = &cx->av_state;
470 struct v4l2_control *ctrl = arg;
471 int retval; 471 int retval;
472 u8 v;
472 473
473 switch (cmd) { 474 if (state->aud_input > CX18_AV_AUDIO_SERIAL2) {
474 case VIDIOC_INT_AUDIO_CLOCK_FREQ: 475 v = cx18_av_read(cx, 0x803) & ~0x10;
475 { 476 cx18_av_write_expect(cx, 0x803, v, v, 0x1f);
476 u8 v; 477 cx18_av_write(cx, 0x8d3, 0x1f);
477 if (state->aud_input > CX18_AV_AUDIO_SERIAL2) { 478 }
478 v = cx18_av_read(cx, 0x803) & ~0x10; 479 v = cx18_av_read(cx, 0x810) | 0x1;
479 cx18_av_write_expect(cx, 0x803, v, v, 0x1f); 480 cx18_av_write_expect(cx, 0x810, v, v, 0x0f);
480 cx18_av_write(cx, 0x8d3, 0x1f);
481 }
482 v = cx18_av_read(cx, 0x810) | 0x1;
483 cx18_av_write_expect(cx, 0x810, v, v, 0x0f);
484 481
485 retval = set_audclk_freq(cx, *(u32 *)arg); 482 retval = set_audclk_freq(cx, freq);
486 483
487 v = cx18_av_read(cx, 0x810) & ~0x1; 484 v = cx18_av_read(cx, 0x810) & ~0x1;
488 cx18_av_write_expect(cx, 0x810, v, v, 0x0f); 485 cx18_av_write_expect(cx, 0x810, v, v, 0x0f);
489 if (state->aud_input > CX18_AV_AUDIO_SERIAL2) { 486 if (state->aud_input > CX18_AV_AUDIO_SERIAL2) {
490 v = cx18_av_read(cx, 0x803) | 0x10; 487 v = cx18_av_read(cx, 0x803) | 0x10;
491 cx18_av_write_expect(cx, 0x803, v, v, 0x1f); 488 cx18_av_write_expect(cx, 0x803, v, v, 0x1f);
492 }
493 return retval;
494 } 489 }
490 return retval;
491}
495 492
496 case VIDIOC_G_CTRL: 493int cx18_av_audio_g_ctrl(struct cx18 *cx, struct v4l2_control *ctrl)
497 switch (ctrl->id) { 494{
498 case V4L2_CID_AUDIO_VOLUME: 495 switch (ctrl->id) {
499 ctrl->value = get_volume(cx); 496 case V4L2_CID_AUDIO_VOLUME:
500 break; 497 ctrl->value = get_volume(cx);
501 case V4L2_CID_AUDIO_BASS:
502 ctrl->value = get_bass(cx);
503 break;
504 case V4L2_CID_AUDIO_TREBLE:
505 ctrl->value = get_treble(cx);
506 break;
507 case V4L2_CID_AUDIO_BALANCE:
508 ctrl->value = get_balance(cx);
509 break;
510 case V4L2_CID_AUDIO_MUTE:
511 ctrl->value = get_mute(cx);
512 break;
513 default:
514 return -EINVAL;
515 }
516 break; 498 break;
517 499 case V4L2_CID_AUDIO_BASS:
518 case VIDIOC_S_CTRL: 500 ctrl->value = get_bass(cx);
519 switch (ctrl->id) { 501 break;
520 case V4L2_CID_AUDIO_VOLUME: 502 case V4L2_CID_AUDIO_TREBLE:
521 set_volume(cx, ctrl->value); 503 ctrl->value = get_treble(cx);
522 break; 504 break;
523 case V4L2_CID_AUDIO_BASS: 505 case V4L2_CID_AUDIO_BALANCE:
524 set_bass(cx, ctrl->value); 506 ctrl->value = get_balance(cx);
525 break; 507 break;
526 case V4L2_CID_AUDIO_TREBLE: 508 case V4L2_CID_AUDIO_MUTE:
527 set_treble(cx, ctrl->value); 509 ctrl->value = get_mute(cx);
528 break;
529 case V4L2_CID_AUDIO_BALANCE:
530 set_balance(cx, ctrl->value);
531 break;
532 case V4L2_CID_AUDIO_MUTE:
533 set_mute(cx, ctrl->value);
534 break;
535 default:
536 return -EINVAL;
537 }
538 break; 510 break;
539
540 default: 511 default:
541 return -EINVAL; 512 return -EINVAL;
542 } 513 }
514 return 0;
515}
543 516
517int cx18_av_audio_s_ctrl(struct cx18 *cx, struct v4l2_control *ctrl)
518{
519 switch (ctrl->id) {
520 case V4L2_CID_AUDIO_VOLUME:
521 set_volume(cx, ctrl->value);
522 break;
523 case V4L2_CID_AUDIO_BASS:
524 set_bass(cx, ctrl->value);
525 break;
526 case V4L2_CID_AUDIO_TREBLE:
527 set_treble(cx, ctrl->value);
528 break;
529 case V4L2_CID_AUDIO_BALANCE:
530 set_balance(cx, ctrl->value);
531 break;
532 case V4L2_CID_AUDIO_MUTE:
533 set_mute(cx, ctrl->value);
534 break;
535 default:
536 return -EINVAL;
537 }
544 return 0; 538 return 0;
545} 539}
diff --git a/drivers/media/video/cx18/cx18-av-core.c b/drivers/media/video/cx18/cx18-av-core.c
index 0b1c84b4ddd6..f4dd9d78eb3d 100644
--- a/drivers/media/video/cx18/cx18-av-core.c
+++ b/drivers/media/video/cx18/cx18-av-core.c
@@ -22,8 +22,10 @@
22 * 02110-1301, USA. 22 * 02110-1301, USA.
23 */ 23 */
24 24
25#include <media/v4l2-chip-ident.h>
25#include "cx18-driver.h" 26#include "cx18-driver.h"
26#include "cx18-io.h" 27#include "cx18-io.h"
28#include "cx18-cards.h"
27 29
28int cx18_av_write(struct cx18 *cx, u16 addr, u8 value) 30int cx18_av_write(struct cx18 *cx, u16 addr, u8 value)
29{ 31{
@@ -97,15 +99,6 @@ int cx18_av_and_or4(struct cx18 *cx, u16 addr, u32 and_mask,
97 or_value); 99 or_value);
98} 100}
99 101
100/* ----------------------------------------------------------------------- */
101
102static int set_input(struct cx18 *cx, enum cx18_av_video_input vid_input,
103 enum cx18_av_audio_input aud_input);
104static void log_audio_status(struct cx18 *cx);
105static void log_video_status(struct cx18 *cx);
106
107/* ----------------------------------------------------------------------- */
108
109static void cx18_av_initialize(struct cx18 *cx) 102static void cx18_av_initialize(struct cx18 *cx)
110{ 103{
111 struct cx18_av_state *state = &cx->av_state; 104 struct cx18_av_state *state = &cx->av_state;
@@ -169,9 +162,14 @@ static void cx18_av_initialize(struct cx18 *cx)
169 /* Set VGA_TRACK_RANGE to 0x20 */ 162 /* Set VGA_TRACK_RANGE to 0x20 */
170 cx18_av_and_or4(cx, CXADEC_DFE_CTRL2, 0xFFFF00FF, 0x00002000); 163 cx18_av_and_or4(cx, CXADEC_DFE_CTRL2, 0xFFFF00FF, 0x00002000);
171 164
172 /* Enable VBI capture */ 165 /*
173 cx18_av_write4(cx, CXADEC_OUT_CTRL1, 0x4010253F); 166 * Initial VBI setup
174 /* cx18_av_write4(cx, CXADEC_OUT_CTRL1, 0x4010253E); */ 167 * VIP-1.1, 10 bit mode, enable Raw, disable sliced,
168 * don't clamp raw samples when codes are in use, 1 byte user D-words,
169 * IDID0 has line #, RP code V bit transition on VBLANK, data during
170 * blanking intervals
171 */
172 cx18_av_write4(cx, CXADEC_OUT_CTRL1, 0x4013252e);
175 173
176 /* Set the video input. 174 /* Set the video input.
177 The setting in MODE_CTRL gets lost when we do the above setup */ 175 The setting in MODE_CTRL gets lost when we do the above setup */
@@ -195,11 +193,61 @@ static void cx18_av_initialize(struct cx18 *cx)
195 state->default_volume = ((state->default_volume / 2) + 23) << 9; 193 state->default_volume = ((state->default_volume / 2) + 23) << 9;
196} 194}
197 195
198/* ----------------------------------------------------------------------- */ 196static int cx18_av_reset(struct v4l2_subdev *sd, u32 val)
197{
198 struct cx18 *cx = v4l2_get_subdevdata(sd);
199
200 cx18_av_initialize(cx);
201 return 0;
202}
203
204static int cx18_av_init(struct v4l2_subdev *sd, u32 val)
205{
206 struct cx18_av_state *state = to_cx18_av_state(sd);
207 struct cx18 *cx = v4l2_get_subdevdata(sd);
208
209 switch (val) {
210 case CX18_AV_INIT_PLLS:
211 /*
212 * The crystal freq used in calculations in this driver will be
213 * 28.636360 MHz.
214 * Aim to run the PLLs' VCOs near 400 MHz to minimze errors.
215 */
216
217 /*
218 * VDCLK Integer = 0x0f, Post Divider = 0x04
219 * AIMCLK Integer = 0x0e, Post Divider = 0x16
220 */
221 cx18_av_write4(cx, CXADEC_PLL_CTRL1, 0x160e040f);
222
223 /* VDCLK Fraction = 0x2be2fe */
224 /* xtal * 0xf.15f17f0/4 = 108 MHz: 432 MHz before post divide */
225 cx18_av_write4(cx, CXADEC_VID_PLL_FRAC, 0x002be2fe);
226
227 /* AIMCLK Fraction = 0x05227ad */
228 /* xtal * 0xe.2913d68/0x16 = 48000 * 384: 406 MHz pre post-div*/
229 cx18_av_write4(cx, CXADEC_AUX_PLL_FRAC, 0x005227ad);
230
231 /* SA_MCLK_SEL=1, SA_MCLK_DIV=0x16 */
232 cx18_av_write(cx, CXADEC_I2S_MCLK, 0x56);
233 break;
234
235 case CX18_AV_INIT_NORMAL:
236 default:
237 if (!state->is_initialized) {
238 /* initialize on first use */
239 state->is_initialized = 1;
240 cx18_av_initialize(cx);
241 }
242 break;
243 }
244 return 0;
245}
199 246
200void cx18_av_std_setup(struct cx18 *cx) 247void cx18_av_std_setup(struct cx18 *cx)
201{ 248{
202 struct cx18_av_state *state = &cx->av_state; 249 struct cx18_av_state *state = &cx->av_state;
250 struct v4l2_subdev *sd = &state->sd;
203 v4l2_std_id std = state->std; 251 v4l2_std_id std = state->std;
204 int hblank, hactive, burst, vblank, vactive, sc; 252 int hblank, hactive, burst, vblank, vactive, sc;
205 int vblank656, src_decimation; 253 int vblank656, src_decimation;
@@ -213,6 +261,7 @@ void cx18_av_std_setup(struct cx18 *cx)
213 cx18_av_write(cx, 0x49f, 0x14); 261 cx18_av_write(cx, 0x49f, 0x14);
214 262
215 if (std & V4L2_STD_625_50) { 263 if (std & V4L2_STD_625_50) {
264 /* FIXME - revisit these for Sliced VBI */
216 hblank = 132; 265 hblank = 132;
217 hactive = 720; 266 hactive = 720;
218 burst = 93; 267 burst = 93;
@@ -236,13 +285,40 @@ void cx18_av_std_setup(struct cx18 *cx)
236 sc = 672351; 285 sc = 672351;
237 } 286 }
238 } else { 287 } else {
288 /*
289 * The following relationships of half line counts should hold:
290 * 525 = vsync + vactive + vblank656
291 * 12 = vblank656 - vblank
292 *
293 * vsync: always 6 half-lines of vsync pulses
294 * vactive: half lines of active video
295 * vblank656: half lines, after line 3/mid-266, of blanked video
296 * vblank: half lines, after line 9/272, of blanked video
297 *
298 * As far as I can tell:
299 * vblank656 starts counting from the falling edge of the first
300 * vsync pulse (start of line 4 or mid-266)
301 * vblank starts counting from the after the 6 vsync pulses and
302 * 6 or 5 equalization pulses (start of line 10 or 272)
303 *
304 * For 525 line systems the driver will extract VBI information
305 * from lines 10-21 and lines 273-284.
306 */
307 vblank656 = 38; /* lines 4 - 22 & 266 - 284 */
308 vblank = 26; /* lines 10 - 22 & 272 - 284 */
309 vactive = 481; /* lines 23 - 263 & 285 - 525 */
310
311 /*
312 * For a 13.5 Mpps clock and 15,734.26 Hz line rate, a line is
313 * is 858 pixels = 720 active + 138 blanking. The Hsync leading
314 * edge should happen 1.2 us * 13.5 Mpps ~= 16 pixels after the
315 * end of active video, leaving 122 pixels of hblank to ignore
316 * before active video starts.
317 */
239 hactive = 720; 318 hactive = 720;
240 hblank = 122; 319 hblank = 122;
241 vactive = 487;
242 luma_lpf = 1; 320 luma_lpf = 1;
243 uv_lpf = 1; 321 uv_lpf = 1;
244 vblank = 26;
245 vblank656 = 26;
246 322
247 src_decimation = 0x21f; 323 src_decimation = 0x21f;
248 if (std == V4L2_STD_PAL_60) { 324 if (std == V4L2_STD_PAL_60) {
@@ -265,33 +341,35 @@ void cx18_av_std_setup(struct cx18 *cx)
265 pll_int = cx18_av_read(cx, 0x108); 341 pll_int = cx18_av_read(cx, 0x108);
266 pll_frac = cx18_av_read4(cx, 0x10c) & 0x1ffffff; 342 pll_frac = cx18_av_read4(cx, 0x10c) & 0x1ffffff;
267 pll_post = cx18_av_read(cx, 0x109); 343 pll_post = cx18_av_read(cx, 0x109);
268 CX18_DEBUG_INFO("PLL regs = int: %u, frac: %u, post: %u\n", 344 CX18_DEBUG_INFO_DEV(sd, "PLL regs = int: %u, frac: %u, post: %u\n",
269 pll_int, pll_frac, pll_post); 345 pll_int, pll_frac, pll_post);
270 346
271 if (pll_post) { 347 if (pll_post) {
272 int fin, fsc, pll; 348 int fin, fsc, pll;
273 349
274 pll = (28636360L * ((((u64)pll_int) << 25) + pll_frac)) >> 25; 350 pll = (28636360L * ((((u64)pll_int) << 25) + pll_frac)) >> 25;
275 pll /= pll_post; 351 pll /= pll_post;
276 CX18_DEBUG_INFO("PLL = %d.%06d MHz\n", 352 CX18_DEBUG_INFO_DEV(sd, "PLL = %d.%06d MHz\n",
277 pll / 1000000, pll % 1000000); 353 pll / 1000000, pll % 1000000);
278 CX18_DEBUG_INFO("PLL/8 = %d.%06d MHz\n", 354 CX18_DEBUG_INFO_DEV(sd, "PLL/8 = %d.%06d MHz\n",
279 pll / 8000000, (pll / 8) % 1000000); 355 pll / 8000000, (pll / 8) % 1000000);
280 356
281 fin = ((u64)src_decimation * pll) >> 12; 357 fin = ((u64)src_decimation * pll) >> 12;
282 CX18_DEBUG_INFO("ADC Sampling freq = %d.%06d MHz\n", 358 CX18_DEBUG_INFO_DEV(sd, "ADC Sampling freq = %d.%06d MHz\n",
283 fin / 1000000, fin % 1000000); 359 fin / 1000000, fin % 1000000);
284 360
285 fsc = (((u64)sc) * pll) >> 24L; 361 fsc = (((u64)sc) * pll) >> 24L;
286 CX18_DEBUG_INFO("Chroma sub-carrier freq = %d.%06d MHz\n", 362 CX18_DEBUG_INFO_DEV(sd,
287 fsc / 1000000, fsc % 1000000); 363 "Chroma sub-carrier freq = %d.%06d MHz\n",
288 364 fsc / 1000000, fsc % 1000000);
289 CX18_DEBUG_INFO("hblank %i, hactive %i, " 365
290 "vblank %i , vactive %i, vblank656 %i, src_dec %i," 366 CX18_DEBUG_INFO_DEV(sd, "hblank %i, hactive %i, vblank %i, "
291 "burst 0x%02x, luma_lpf %i, uv_lpf %i, comb 0x%02x," 367 "vactive %i, vblank656 %i, src_dec %i, "
292 " sc 0x%06x\n", 368 "burst 0x%02x, luma_lpf %i, uv_lpf %i, "
293 hblank, hactive, vblank, vactive, vblank656, 369 "comb 0x%02x, sc 0x%06x\n",
294 src_decimation, burst, luma_lpf, uv_lpf, comb, sc); 370 hblank, hactive, vblank, vactive, vblank656,
371 src_decimation, burst, luma_lpf, uv_lpf,
372 comb, sc);
295 } 373 }
296 374
297 /* Sets horizontal blanking delay and active lines */ 375 /* Sets horizontal blanking delay and active lines */
@@ -325,18 +403,16 @@ void cx18_av_std_setup(struct cx18 *cx)
325 cx18_av_write(cx, 0x47d, 0xff & sc >> 8); 403 cx18_av_write(cx, 0x47d, 0xff & sc >> 8);
326 cx18_av_write(cx, 0x47e, 0xff & sc >> 16); 404 cx18_av_write(cx, 0x47e, 0xff & sc >> 16);
327 405
328 /* Sets VBI parameters */
329 if (std & V4L2_STD_625_50) { 406 if (std & V4L2_STD_625_50) {
330 cx18_av_write(cx, 0x47f, 0x01); 407 state->slicer_line_delay = 1;
331 state->vbi_line_offset = 5; 408 state->slicer_line_offset = (6 + state->slicer_line_delay - 2);
332 } else { 409 } else {
333 cx18_av_write(cx, 0x47f, 0x00); 410 state->slicer_line_delay = 0;
334 state->vbi_line_offset = 8; 411 state->slicer_line_offset = (10 + state->slicer_line_delay - 2);
335 } 412 }
413 cx18_av_write(cx, 0x47f, state->slicer_line_delay);
336} 414}
337 415
338/* ----------------------------------------------------------------------- */
339
340static void input_change(struct cx18 *cx) 416static void input_change(struct cx18 *cx)
341{ 417{
342 struct cx18_av_state *state = &cx->av_state; 418 struct cx18_av_state *state = &cx->av_state;
@@ -382,17 +458,26 @@ static void input_change(struct cx18 *cx)
382 } 458 }
383} 459}
384 460
461static int cx18_av_s_frequency(struct v4l2_subdev *sd,
462 struct v4l2_frequency *freq)
463{
464 struct cx18 *cx = v4l2_get_subdevdata(sd);
465 input_change(cx);
466 return 0;
467}
468
385static int set_input(struct cx18 *cx, enum cx18_av_video_input vid_input, 469static int set_input(struct cx18 *cx, enum cx18_av_video_input vid_input,
386 enum cx18_av_audio_input aud_input) 470 enum cx18_av_audio_input aud_input)
387{ 471{
388 struct cx18_av_state *state = &cx->av_state; 472 struct cx18_av_state *state = &cx->av_state;
473 struct v4l2_subdev *sd = &state->sd;
389 u8 is_composite = (vid_input >= CX18_AV_COMPOSITE1 && 474 u8 is_composite = (vid_input >= CX18_AV_COMPOSITE1 &&
390 vid_input <= CX18_AV_COMPOSITE8); 475 vid_input <= CX18_AV_COMPOSITE8);
391 u8 reg; 476 u8 reg;
392 u8 v; 477 u8 v;
393 478
394 CX18_DEBUG_INFO("decoder set video input %d, audio input %d\n", 479 CX18_DEBUG_INFO_DEV(sd, "decoder set video input %d, audio input %d\n",
395 vid_input, aud_input); 480 vid_input, aud_input);
396 481
397 if (is_composite) { 482 if (is_composite) {
398 reg = 0xf0 + (vid_input - CX18_AV_COMPOSITE1); 483 reg = 0xf0 + (vid_input - CX18_AV_COMPOSITE1);
@@ -405,8 +490,8 @@ static int set_input(struct cx18 *cx, enum cx18_av_video_input vid_input,
405 luma > CX18_AV_SVIDEO_LUMA8 || 490 luma > CX18_AV_SVIDEO_LUMA8 ||
406 chroma < CX18_AV_SVIDEO_CHROMA4 || 491 chroma < CX18_AV_SVIDEO_CHROMA4 ||
407 chroma > CX18_AV_SVIDEO_CHROMA8) { 492 chroma > CX18_AV_SVIDEO_CHROMA8) {
408 CX18_ERR("0x%04x is not a valid video input!\n", 493 CX18_ERR_DEV(sd, "0x%04x is not a valid video input!\n",
409 vid_input); 494 vid_input);
410 return -EINVAL; 495 return -EINVAL;
411 } 496 }
412 reg = 0xf0 + ((luma - CX18_AV_SVIDEO_LUMA1) >> 4); 497 reg = 0xf0 + ((luma - CX18_AV_SVIDEO_LUMA1) >> 4);
@@ -431,7 +516,8 @@ static int set_input(struct cx18 *cx, enum cx18_av_video_input vid_input,
431 case CX18_AV_AUDIO8: reg &= ~0xc0; reg |= 0x40; break; 516 case CX18_AV_AUDIO8: reg &= ~0xc0; reg |= 0x40; break;
432 517
433 default: 518 default:
434 CX18_ERR("0x%04x is not a valid audio input!\n", aud_input); 519 CX18_ERR_DEV(sd, "0x%04x is not a valid audio input!\n",
520 aud_input);
435 return -EINVAL; 521 return -EINVAL;
436 } 522 }
437 523
@@ -461,14 +547,118 @@ static int set_input(struct cx18 *cx, enum cx18_av_video_input vid_input,
461 return 0; 547 return 0;
462} 548}
463 549
464/* ----------------------------------------------------------------------- */ 550static int cx18_av_s_video_routing(struct v4l2_subdev *sd,
551 const struct v4l2_routing *route)
552{
553 struct cx18_av_state *state = to_cx18_av_state(sd);
554 struct cx18 *cx = v4l2_get_subdevdata(sd);
555 return set_input(cx, route->input, state->aud_input);
556}
557
558static int cx18_av_s_audio_routing(struct v4l2_subdev *sd,
559 const struct v4l2_routing *route)
560{
561 struct cx18_av_state *state = to_cx18_av_state(sd);
562 struct cx18 *cx = v4l2_get_subdevdata(sd);
563 return set_input(cx, state->vid_input, route->input);
564}
465 565
466static int set_v4lstd(struct cx18 *cx) 566static int cx18_av_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
467{ 567{
468 struct cx18_av_state *state = &cx->av_state; 568 struct cx18_av_state *state = to_cx18_av_state(sd);
569 struct cx18 *cx = v4l2_get_subdevdata(sd);
570 u8 vpres;
571 u8 mode;
572 int val = 0;
573
574 if (state->radio)
575 return 0;
576
577 vpres = cx18_av_read(cx, 0x40e) & 0x20;
578 vt->signal = vpres ? 0xffff : 0x0;
579
580 vt->capability |=
581 V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_LANG1 |
582 V4L2_TUNER_CAP_LANG2 | V4L2_TUNER_CAP_SAP;
583
584 mode = cx18_av_read(cx, 0x804);
585
586 /* get rxsubchans and audmode */
587 if ((mode & 0xf) == 1)
588 val |= V4L2_TUNER_SUB_STEREO;
589 else
590 val |= V4L2_TUNER_SUB_MONO;
591
592 if (mode == 2 || mode == 4)
593 val = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
594
595 if (mode & 0x10)
596 val |= V4L2_TUNER_SUB_SAP;
597
598 vt->rxsubchans = val;
599 vt->audmode = state->audmode;
600 return 0;
601}
602
603static int cx18_av_s_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
604{
605 struct cx18_av_state *state = to_cx18_av_state(sd);
606 struct cx18 *cx = v4l2_get_subdevdata(sd);
607 u8 v;
608
609 if (state->radio)
610 return 0;
611
612 v = cx18_av_read(cx, 0x809);
613 v &= ~0xf;
614
615 switch (vt->audmode) {
616 case V4L2_TUNER_MODE_MONO:
617 /* mono -> mono
618 stereo -> mono
619 bilingual -> lang1 */
620 break;
621 case V4L2_TUNER_MODE_STEREO:
622 case V4L2_TUNER_MODE_LANG1:
623 /* mono -> mono
624 stereo -> stereo
625 bilingual -> lang1 */
626 v |= 0x4;
627 break;
628 case V4L2_TUNER_MODE_LANG1_LANG2:
629 /* mono -> mono
630 stereo -> stereo
631 bilingual -> lang1/lang2 */
632 v |= 0x7;
633 break;
634 case V4L2_TUNER_MODE_LANG2:
635 /* mono -> mono
636 stereo -> stereo
637 bilingual -> lang2 */
638 v |= 0x1;
639 break;
640 default:
641 return -EINVAL;
642 }
643 cx18_av_write_expect(cx, 0x809, v, v, 0xff);
644 state->audmode = vt->audmode;
645 return 0;
646}
647
648static int cx18_av_s_std(struct v4l2_subdev *sd, v4l2_std_id norm)
649{
650 struct cx18_av_state *state = to_cx18_av_state(sd);
651 struct cx18 *cx = v4l2_get_subdevdata(sd);
652
469 u8 fmt = 0; /* zero is autodetect */ 653 u8 fmt = 0; /* zero is autodetect */
470 u8 pal_m = 0; 654 u8 pal_m = 0;
471 655
656 if (state->radio == 0 && state->std == norm)
657 return 0;
658
659 state->radio = 0;
660 state->std = norm;
661
472 /* First tests should be against specific std */ 662 /* First tests should be against specific std */
473 if (state->std == V4L2_STD_NTSC_M_JP) { 663 if (state->std == V4L2_STD_NTSC_M_JP) {
474 fmt = 0x2; 664 fmt = 0x2;
@@ -493,7 +683,7 @@ static int set_v4lstd(struct cx18 *cx)
493 fmt = 0xc; 683 fmt = 0xc;
494 } 684 }
495 685
496 CX18_DEBUG_INFO("changing video std to fmt %i\n", fmt); 686 CX18_DEBUG_INFO_DEV(sd, "changing video std to fmt %i\n", fmt);
497 687
498 /* Follow step 9 of section 3.16 in the cx18_av datasheet. 688 /* Follow step 9 of section 3.16 in the cx18_av datasheet.
499 Without this PAL may display a vertical ghosting effect. 689 Without this PAL may display a vertical ghosting effect.
@@ -511,15 +701,22 @@ static int set_v4lstd(struct cx18 *cx)
511 return 0; 701 return 0;
512} 702}
513 703
514/* ----------------------------------------------------------------------- */ 704static int cx18_av_s_radio(struct v4l2_subdev *sd)
705{
706 struct cx18_av_state *state = to_cx18_av_state(sd);
707 state->radio = 1;
708 return 0;
709}
515 710
516static int set_v4lctrl(struct cx18 *cx, struct v4l2_control *ctrl) 711static int cx18_av_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
517{ 712{
713 struct cx18 *cx = v4l2_get_subdevdata(sd);
714
518 switch (ctrl->id) { 715 switch (ctrl->id) {
519 case V4L2_CID_BRIGHTNESS: 716 case V4L2_CID_BRIGHTNESS:
520 if (ctrl->value < 0 || ctrl->value > 255) { 717 if (ctrl->value < 0 || ctrl->value > 255) {
521 CX18_ERR("invalid brightness setting %d\n", 718 CX18_ERR_DEV(sd, "invalid brightness setting %d\n",
522 ctrl->value); 719 ctrl->value);
523 return -ERANGE; 720 return -ERANGE;
524 } 721 }
525 722
@@ -528,8 +725,8 @@ static int set_v4lctrl(struct cx18 *cx, struct v4l2_control *ctrl)
528 725
529 case V4L2_CID_CONTRAST: 726 case V4L2_CID_CONTRAST:
530 if (ctrl->value < 0 || ctrl->value > 127) { 727 if (ctrl->value < 0 || ctrl->value > 127) {
531 CX18_ERR("invalid contrast setting %d\n", 728 CX18_ERR_DEV(sd, "invalid contrast setting %d\n",
532 ctrl->value); 729 ctrl->value);
533 return -ERANGE; 730 return -ERANGE;
534 } 731 }
535 732
@@ -538,8 +735,8 @@ static int set_v4lctrl(struct cx18 *cx, struct v4l2_control *ctrl)
538 735
539 case V4L2_CID_SATURATION: 736 case V4L2_CID_SATURATION:
540 if (ctrl->value < 0 || ctrl->value > 127) { 737 if (ctrl->value < 0 || ctrl->value > 127) {
541 CX18_ERR("invalid saturation setting %d\n", 738 CX18_ERR_DEV(sd, "invalid saturation setting %d\n",
542 ctrl->value); 739 ctrl->value);
543 return -ERANGE; 740 return -ERANGE;
544 } 741 }
545 742
@@ -548,8 +745,9 @@ static int set_v4lctrl(struct cx18 *cx, struct v4l2_control *ctrl)
548 break; 745 break;
549 746
550 case V4L2_CID_HUE: 747 case V4L2_CID_HUE:
551 if (ctrl->value < -127 || ctrl->value > 127) { 748 if (ctrl->value < -128 || ctrl->value > 127) {
552 CX18_ERR("invalid hue setting %d\n", ctrl->value); 749 CX18_ERR_DEV(sd, "invalid hue setting %d\n",
750 ctrl->value);
553 return -ERANGE; 751 return -ERANGE;
554 } 752 }
555 753
@@ -561,17 +759,18 @@ static int set_v4lctrl(struct cx18 *cx, struct v4l2_control *ctrl)
561 case V4L2_CID_AUDIO_TREBLE: 759 case V4L2_CID_AUDIO_TREBLE:
562 case V4L2_CID_AUDIO_BALANCE: 760 case V4L2_CID_AUDIO_BALANCE:
563 case V4L2_CID_AUDIO_MUTE: 761 case V4L2_CID_AUDIO_MUTE:
564 return cx18_av_audio(cx, VIDIOC_S_CTRL, ctrl); 762 return cx18_av_audio_s_ctrl(cx, ctrl);
565 763
566 default: 764 default:
567 return -EINVAL; 765 return -EINVAL;
568 } 766 }
569
570 return 0; 767 return 0;
571} 768}
572 769
573static int get_v4lctrl(struct cx18 *cx, struct v4l2_control *ctrl) 770static int cx18_av_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
574{ 771{
772 struct cx18 *cx = v4l2_get_subdevdata(sd);
773
575 switch (ctrl->id) { 774 switch (ctrl->id) {
576 case V4L2_CID_BRIGHTNESS: 775 case V4L2_CID_BRIGHTNESS:
577 ctrl->value = (s8)cx18_av_read(cx, 0x414) + 128; 776 ctrl->value = (s8)cx18_av_read(cx, 0x414) + 128;
@@ -590,31 +789,57 @@ static int get_v4lctrl(struct cx18 *cx, struct v4l2_control *ctrl)
590 case V4L2_CID_AUDIO_TREBLE: 789 case V4L2_CID_AUDIO_TREBLE:
591 case V4L2_CID_AUDIO_BALANCE: 790 case V4L2_CID_AUDIO_BALANCE:
592 case V4L2_CID_AUDIO_MUTE: 791 case V4L2_CID_AUDIO_MUTE:
593 return cx18_av_audio(cx, VIDIOC_G_CTRL, ctrl); 792 return cx18_av_audio_g_ctrl(cx, ctrl);
594 default: 793 default:
595 return -EINVAL; 794 return -EINVAL;
596 } 795 }
597
598 return 0; 796 return 0;
599} 797}
600 798
601/* ----------------------------------------------------------------------- */ 799static int cx18_av_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc)
602
603static int get_v4lfmt(struct cx18 *cx, struct v4l2_format *fmt)
604{ 800{
605 switch (fmt->type) { 801 struct cx18_av_state *state = to_cx18_av_state(sd);
606 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: 802
607 return cx18_av_vbi(cx, VIDIOC_G_FMT, fmt); 803 switch (qc->id) {
804 case V4L2_CID_BRIGHTNESS:
805 return v4l2_ctrl_query_fill(qc, 0, 255, 1, 128);
806 case V4L2_CID_CONTRAST:
807 case V4L2_CID_SATURATION:
808 return v4l2_ctrl_query_fill(qc, 0, 127, 1, 64);
809 case V4L2_CID_HUE:
810 return v4l2_ctrl_query_fill(qc, -128, 127, 1, 0);
811 default:
812 break;
813 }
814
815 switch (qc->id) {
816 case V4L2_CID_AUDIO_VOLUME:
817 return v4l2_ctrl_query_fill(qc, 0, 65535,
818 65535 / 100, state->default_volume);
819 case V4L2_CID_AUDIO_MUTE:
820 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 0);
821 case V4L2_CID_AUDIO_BALANCE:
822 case V4L2_CID_AUDIO_BASS:
823 case V4L2_CID_AUDIO_TREBLE:
824 return v4l2_ctrl_query_fill(qc, 0, 65535, 65535 / 100, 32768);
608 default: 825 default:
609 return -EINVAL; 826 return -EINVAL;
610 } 827 }
828 return -EINVAL;
829}
611 830
612 return 0; 831static int cx18_av_g_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt)
832{
833 struct cx18 *cx = v4l2_get_subdevdata(sd);
834
835 return cx18_av_vbi_g_fmt(cx, fmt);
613} 836}
614 837
615static int set_v4lfmt(struct cx18 *cx, struct v4l2_format *fmt) 838static int cx18_av_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt)
616{ 839{
617 struct cx18_av_state *state = &cx->av_state; 840 struct cx18_av_state *state = to_cx18_av_state(sd);
841 struct cx18 *cx = v4l2_get_subdevdata(sd);
842
618 struct v4l2_pix_format *pix; 843 struct v4l2_pix_format *pix;
619 int HSC, VSC, Vsrc, Hsrc, filter, Vlines; 844 int HSC, VSC, Vsrc, Hsrc, filter, Vlines;
620 int is_50Hz = !(state->std & V4L2_STD_525_60); 845 int is_50Hz = !(state->std & V4L2_STD_525_60);
@@ -629,12 +854,26 @@ static int set_v4lfmt(struct cx18 *cx, struct v4l2_format *fmt)
629 Hsrc = (cx18_av_read(cx, 0x472) & 0x3f) << 4; 854 Hsrc = (cx18_av_read(cx, 0x472) & 0x3f) << 4;
630 Hsrc |= (cx18_av_read(cx, 0x471) & 0xf0) >> 4; 855 Hsrc |= (cx18_av_read(cx, 0x471) & 0xf0) >> 4;
631 856
632 Vlines = pix->height + (is_50Hz ? 4 : 7); 857 /*
633 858 * This adjustment reflects the excess of vactive, set in
859 * cx18_av_std_setup(), above standard values:
860 *
861 * 480 + 1 for 60 Hz systems
862 * 576 + 4 for 50 Hz systems
863 */
864 Vlines = pix->height + (is_50Hz ? 4 : 1);
865
866 /*
867 * Invalid height and width scaling requests are:
868 * 1. width less than 1/16 of the source width
869 * 2. width greater than the source width
870 * 3. height less than 1/8 of the source height
871 * 4. height greater than the source height
872 */
634 if ((pix->width * 16 < Hsrc) || (Hsrc < pix->width) || 873 if ((pix->width * 16 < Hsrc) || (Hsrc < pix->width) ||
635 (Vlines * 8 < Vsrc) || (Vsrc < Vlines)) { 874 (Vlines * 8 < Vsrc) || (Vsrc < Vlines)) {
636 CX18_ERR("%dx%d is not a valid size!\n", 875 CX18_ERR_DEV(sd, "%dx%d is not a valid size!\n",
637 pix->width, pix->height); 876 pix->width, pix->height);
638 return -ERANGE; 877 return -ERANGE;
639 } 878 }
640 879
@@ -651,8 +890,9 @@ static int set_v4lfmt(struct cx18 *cx, struct v4l2_format *fmt)
651 else 890 else
652 filter = 3; 891 filter = 3;
653 892
654 CX18_DEBUG_INFO("decoder set size %dx%d -> scale %ux%u\n", 893 CX18_DEBUG_INFO_DEV(sd,
655 pix->width, pix->height, HSC, VSC); 894 "decoder set size %dx%d -> scale %ux%u\n",
895 pix->width, pix->height, HSC, VSC);
656 896
657 /* HSCALE=HSC */ 897 /* HSCALE=HSC */
658 cx18_av_write(cx, 0x418, HSC & 0xff); 898 cx18_av_write(cx, 0x418, HSC & 0xff);
@@ -666,231 +906,32 @@ static int set_v4lfmt(struct cx18 *cx, struct v4l2_format *fmt)
666 break; 906 break;
667 907
668 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: 908 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
669 return cx18_av_vbi(cx, VIDIOC_S_FMT, fmt); 909 return cx18_av_vbi_s_fmt(cx, fmt);
670 910
671 case V4L2_BUF_TYPE_VBI_CAPTURE: 911 case V4L2_BUF_TYPE_VBI_CAPTURE:
672 return cx18_av_vbi(cx, VIDIOC_S_FMT, fmt); 912 return cx18_av_vbi_s_fmt(cx, fmt);
673 913
674 default: 914 default:
675 return -EINVAL; 915 return -EINVAL;
676 } 916 }
677
678 return 0; 917 return 0;
679} 918}
680 919
681/* ----------------------------------------------------------------------- */ 920static int cx18_av_s_stream(struct v4l2_subdev *sd, int enable)
682
683int cx18_av_cmd(struct cx18 *cx, unsigned int cmd, void *arg)
684{ 921{
685 struct cx18_av_state *state = &cx->av_state; 922 struct cx18 *cx = v4l2_get_subdevdata(sd);
686 struct v4l2_tuner *vt = arg;
687 struct v4l2_routing *route = arg;
688
689 /* ignore these commands */
690 switch (cmd) {
691 case TUNER_SET_TYPE_ADDR:
692 return 0;
693 }
694
695 if (!state->is_initialized) {
696 CX18_DEBUG_INFO("cmd %08x triggered fw load\n", cmd);
697 /* initialize on first use */
698 state->is_initialized = 1;
699 cx18_av_initialize(cx);
700 }
701 923
702 switch (cmd) { 924 CX18_DEBUG_INFO_DEV(sd, "%s output\n", enable ? "enable" : "disable");
703 case VIDIOC_INT_DECODE_VBI_LINE: 925 if (enable) {
704 return cx18_av_vbi(cx, cmd, arg);
705
706 case VIDIOC_INT_AUDIO_CLOCK_FREQ:
707 return cx18_av_audio(cx, cmd, arg);
708
709 case VIDIOC_STREAMON:
710 CX18_DEBUG_INFO("enable output\n");
711 cx18_av_write(cx, 0x115, 0x8c); 926 cx18_av_write(cx, 0x115, 0x8c);
712 cx18_av_write(cx, 0x116, 0x07); 927 cx18_av_write(cx, 0x116, 0x07);
713 break; 928 } else {
714
715 case VIDIOC_STREAMOFF:
716 CX18_DEBUG_INFO("disable output\n");
717 cx18_av_write(cx, 0x115, 0x00); 929 cx18_av_write(cx, 0x115, 0x00);
718 cx18_av_write(cx, 0x116, 0x00); 930 cx18_av_write(cx, 0x116, 0x00);
719 break;
720
721 case VIDIOC_LOG_STATUS:
722 log_video_status(cx);
723 log_audio_status(cx);
724 break;
725
726 case VIDIOC_G_CTRL:
727 return get_v4lctrl(cx, (struct v4l2_control *)arg);
728
729 case VIDIOC_S_CTRL:
730 return set_v4lctrl(cx, (struct v4l2_control *)arg);
731
732 case VIDIOC_QUERYCTRL:
733 {
734 struct v4l2_queryctrl *qc = arg;
735
736 switch (qc->id) {
737 case V4L2_CID_BRIGHTNESS:
738 case V4L2_CID_CONTRAST:
739 case V4L2_CID_SATURATION:
740 case V4L2_CID_HUE:
741 return v4l2_ctrl_query_fill_std(qc);
742 default:
743 break;
744 }
745
746 switch (qc->id) {
747 case V4L2_CID_AUDIO_VOLUME:
748 return v4l2_ctrl_query_fill(qc, 0, 65535,
749 65535 / 100, state->default_volume);
750 case V4L2_CID_AUDIO_MUTE:
751 case V4L2_CID_AUDIO_BALANCE:
752 case V4L2_CID_AUDIO_BASS:
753 case V4L2_CID_AUDIO_TREBLE:
754 return v4l2_ctrl_query_fill_std(qc);
755 default:
756 return -EINVAL;
757 }
758 return -EINVAL;
759 }
760
761 case VIDIOC_G_STD:
762 *(v4l2_std_id *)arg = state->std;
763 break;
764
765 case VIDIOC_S_STD:
766 if (state->radio == 0 && state->std == *(v4l2_std_id *)arg)
767 return 0;
768 state->radio = 0;
769 state->std = *(v4l2_std_id *)arg;
770 return set_v4lstd(cx);
771
772 case AUDC_SET_RADIO:
773 state->radio = 1;
774 break;
775
776 case VIDIOC_INT_G_VIDEO_ROUTING:
777 route->input = state->vid_input;
778 route->output = 0;
779 break;
780
781 case VIDIOC_INT_S_VIDEO_ROUTING:
782 return set_input(cx, route->input, state->aud_input);
783
784 case VIDIOC_INT_G_AUDIO_ROUTING:
785 route->input = state->aud_input;
786 route->output = 0;
787 break;
788
789 case VIDIOC_INT_S_AUDIO_ROUTING:
790 return set_input(cx, state->vid_input, route->input);
791
792 case VIDIOC_S_FREQUENCY:
793 input_change(cx);
794 break;
795
796 case VIDIOC_G_TUNER:
797 {
798 u8 vpres = cx18_av_read(cx, 0x40e) & 0x20;
799 u8 mode;
800 int val = 0;
801
802 if (state->radio)
803 break;
804
805 vt->signal = vpres ? 0xffff : 0x0;
806
807 vt->capability |=
808 V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_LANG1 |
809 V4L2_TUNER_CAP_LANG2 | V4L2_TUNER_CAP_SAP;
810
811 mode = cx18_av_read(cx, 0x804);
812
813 /* get rxsubchans and audmode */
814 if ((mode & 0xf) == 1)
815 val |= V4L2_TUNER_SUB_STEREO;
816 else
817 val |= V4L2_TUNER_SUB_MONO;
818
819 if (mode == 2 || mode == 4)
820 val = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
821
822 if (mode & 0x10)
823 val |= V4L2_TUNER_SUB_SAP;
824
825 vt->rxsubchans = val;
826 vt->audmode = state->audmode;
827 break;
828 }
829
830 case VIDIOC_S_TUNER:
831 {
832 u8 v;
833
834 if (state->radio)
835 break;
836
837 v = cx18_av_read(cx, 0x809);
838 v &= ~0xf;
839
840 switch (vt->audmode) {
841 case V4L2_TUNER_MODE_MONO:
842 /* mono -> mono
843 stereo -> mono
844 bilingual -> lang1 */
845 break;
846 case V4L2_TUNER_MODE_STEREO:
847 case V4L2_TUNER_MODE_LANG1:
848 /* mono -> mono
849 stereo -> stereo
850 bilingual -> lang1 */
851 v |= 0x4;
852 break;
853 case V4L2_TUNER_MODE_LANG1_LANG2:
854 /* mono -> mono
855 stereo -> stereo
856 bilingual -> lang1/lang2 */
857 v |= 0x7;
858 break;
859 case V4L2_TUNER_MODE_LANG2:
860 /* mono -> mono
861 stereo -> stereo
862 bilingual -> lang2 */
863 v |= 0x1;
864 break;
865 default:
866 return -EINVAL;
867 }
868 cx18_av_write_expect(cx, 0x809, v, v, 0xff);
869 state->audmode = vt->audmode;
870 break;
871 } 931 }
872
873 case VIDIOC_G_FMT:
874 return get_v4lfmt(cx, (struct v4l2_format *)arg);
875
876 case VIDIOC_S_FMT:
877 return set_v4lfmt(cx, (struct v4l2_format *)arg);
878
879 case VIDIOC_INT_RESET:
880 cx18_av_initialize(cx);
881 break;
882
883 default:
884 return -EINVAL;
885 }
886
887 return 0; 932 return 0;
888} 933}
889 934
890/* ----------------------------------------------------------------------- */
891
892/* ----------------------------------------------------------------------- */
893
894static void log_video_status(struct cx18 *cx) 935static void log_video_status(struct cx18 *cx)
895{ 936{
896 static const char *const fmt_strs[] = { 937 static const char *const fmt_strs[] = {
@@ -903,36 +944,40 @@ static void log_video_status(struct cx18 *cx)
903 }; 944 };
904 945
905 struct cx18_av_state *state = &cx->av_state; 946 struct cx18_av_state *state = &cx->av_state;
947 struct v4l2_subdev *sd = &state->sd;
906 u8 vidfmt_sel = cx18_av_read(cx, 0x400) & 0xf; 948 u8 vidfmt_sel = cx18_av_read(cx, 0x400) & 0xf;
907 u8 gen_stat1 = cx18_av_read(cx, 0x40d); 949 u8 gen_stat1 = cx18_av_read(cx, 0x40d);
908 u8 gen_stat2 = cx18_av_read(cx, 0x40e); 950 u8 gen_stat2 = cx18_av_read(cx, 0x40e);
909 int vid_input = state->vid_input; 951 int vid_input = state->vid_input;
910 952
911 CX18_INFO("Video signal: %spresent\n", 953 CX18_INFO_DEV(sd, "Video signal: %spresent\n",
912 (gen_stat2 & 0x20) ? "" : "not "); 954 (gen_stat2 & 0x20) ? "" : "not ");
913 CX18_INFO("Detected format: %s\n", 955 CX18_INFO_DEV(sd, "Detected format: %s\n",
914 fmt_strs[gen_stat1 & 0xf]); 956 fmt_strs[gen_stat1 & 0xf]);
915 957
916 CX18_INFO("Specified standard: %s\n", 958 CX18_INFO_DEV(sd, "Specified standard: %s\n",
917 vidfmt_sel ? fmt_strs[vidfmt_sel] : "automatic detection"); 959 vidfmt_sel ? fmt_strs[vidfmt_sel]
960 : "automatic detection");
918 961
919 if (vid_input >= CX18_AV_COMPOSITE1 && 962 if (vid_input >= CX18_AV_COMPOSITE1 &&
920 vid_input <= CX18_AV_COMPOSITE8) { 963 vid_input <= CX18_AV_COMPOSITE8) {
921 CX18_INFO("Specified video input: Composite %d\n", 964 CX18_INFO_DEV(sd, "Specified video input: Composite %d\n",
922 vid_input - CX18_AV_COMPOSITE1 + 1); 965 vid_input - CX18_AV_COMPOSITE1 + 1);
923 } else { 966 } else {
924 CX18_INFO("Specified video input: S-Video (Luma In%d, Chroma In%d)\n", 967 CX18_INFO_DEV(sd, "Specified video input: "
925 (vid_input & 0xf0) >> 4, (vid_input & 0xf00) >> 8); 968 "S-Video (Luma In%d, Chroma In%d)\n",
969 (vid_input & 0xf0) >> 4,
970 (vid_input & 0xf00) >> 8);
926 } 971 }
927 972
928 CX18_INFO("Specified audioclock freq: %d Hz\n", state->audclk_freq); 973 CX18_INFO_DEV(sd, "Specified audioclock freq: %d Hz\n",
974 state->audclk_freq);
929} 975}
930 976
931/* ----------------------------------------------------------------------- */
932
933static void log_audio_status(struct cx18 *cx) 977static void log_audio_status(struct cx18 *cx)
934{ 978{
935 struct cx18_av_state *state = &cx->av_state; 979 struct cx18_av_state *state = &cx->av_state;
980 struct v4l2_subdev *sd = &state->sd;
936 u8 download_ctl = cx18_av_read(cx, 0x803); 981 u8 download_ctl = cx18_av_read(cx, 0x803);
937 u8 mod_det_stat0 = cx18_av_read(cx, 0x804); 982 u8 mod_det_stat0 = cx18_av_read(cx, 0x804);
938 u8 mod_det_stat1 = cx18_av_read(cx, 0x805); 983 u8 mod_det_stat1 = cx18_av_read(cx, 0x805);
@@ -955,7 +1000,7 @@ static void log_audio_status(struct cx18 *cx)
955 case 0xfe: p = "forced mode"; break; 1000 case 0xfe: p = "forced mode"; break;
956 default: p = "not defined"; break; 1001 default: p = "not defined"; break;
957 } 1002 }
958 CX18_INFO("Detected audio mode: %s\n", p); 1003 CX18_INFO_DEV(sd, "Detected audio mode: %s\n", p);
959 1004
960 switch (mod_det_stat1) { 1005 switch (mod_det_stat1) {
961 case 0x00: p = "not defined"; break; 1006 case 0x00: p = "not defined"; break;
@@ -980,11 +1025,11 @@ static void log_audio_status(struct cx18 *cx)
980 case 0xff: p = "no detected audio standard"; break; 1025 case 0xff: p = "no detected audio standard"; break;
981 default: p = "not defined"; break; 1026 default: p = "not defined"; break;
982 } 1027 }
983 CX18_INFO("Detected audio standard: %s\n", p); 1028 CX18_INFO_DEV(sd, "Detected audio standard: %s\n", p);
984 CX18_INFO("Audio muted: %s\n", 1029 CX18_INFO_DEV(sd, "Audio muted: %s\n",
985 (mute_ctl & 0x2) ? "yes" : "no"); 1030 (mute_ctl & 0x2) ? "yes" : "no");
986 CX18_INFO("Audio microcontroller: %s\n", 1031 CX18_INFO_DEV(sd, "Audio microcontroller: %s\n",
987 (download_ctl & 0x10) ? "running" : "stopped"); 1032 (download_ctl & 0x10) ? "running" : "stopped");
988 1033
989 switch (audio_config >> 4) { 1034 switch (audio_config >> 4) {
990 case 0x00: p = "undefined"; break; 1035 case 0x00: p = "undefined"; break;
@@ -1005,7 +1050,7 @@ static void log_audio_status(struct cx18 *cx)
1005 case 0x0f: p = "automatic detection"; break; 1050 case 0x0f: p = "automatic detection"; break;
1006 default: p = "undefined"; break; 1051 default: p = "undefined"; break;
1007 } 1052 }
1008 CX18_INFO("Configured audio standard: %s\n", p); 1053 CX18_INFO_DEV(sd, "Configured audio standard: %s\n", p);
1009 1054
1010 if ((audio_config >> 4) < 0xF) { 1055 if ((audio_config >> 4) < 0xF) {
1011 switch (audio_config & 0xF) { 1056 switch (audio_config & 0xF) {
@@ -1019,7 +1064,7 @@ static void log_audio_status(struct cx18 *cx)
1019 case 0x07: p = "DUAL3 (AB)"; break; 1064 case 0x07: p = "DUAL3 (AB)"; break;
1020 default: p = "undefined"; 1065 default: p = "undefined";
1021 } 1066 }
1022 CX18_INFO("Configured audio mode: %s\n", p); 1067 CX18_INFO_DEV(sd, "Configured audio mode: %s\n", p);
1023 } else { 1068 } else {
1024 switch (audio_config & 0xF) { 1069 switch (audio_config & 0xF) {
1025 case 0x00: p = "BG"; break; 1070 case 0x00: p = "BG"; break;
@@ -1037,14 +1082,14 @@ static void log_audio_status(struct cx18 *cx)
1037 case 0x0f: p = "automatic standard and mode detection"; break; 1082 case 0x0f: p = "automatic standard and mode detection"; break;
1038 default: p = "undefined"; break; 1083 default: p = "undefined"; break;
1039 } 1084 }
1040 CX18_INFO("Configured audio system: %s\n", p); 1085 CX18_INFO_DEV(sd, "Configured audio system: %s\n", p);
1041 } 1086 }
1042 1087
1043 if (aud_input) 1088 if (aud_input)
1044 CX18_INFO("Specified audio input: Tuner (In%d)\n", 1089 CX18_INFO_DEV(sd, "Specified audio input: Tuner (In%d)\n",
1045 aud_input); 1090 aud_input);
1046 else 1091 else
1047 CX18_INFO("Specified audio input: External\n"); 1092 CX18_INFO_DEV(sd, "Specified audio input: External\n");
1048 1093
1049 switch (pref_mode & 0xf) { 1094 switch (pref_mode & 0xf) {
1050 case 0: p = "mono/language A"; break; 1095 case 0: p = "mono/language A"; break;
@@ -1057,14 +1102,14 @@ static void log_audio_status(struct cx18 *cx)
1057 case 7: p = "language AB"; break; 1102 case 7: p = "language AB"; break;
1058 default: p = "undefined"; break; 1103 default: p = "undefined"; break;
1059 } 1104 }
1060 CX18_INFO("Preferred audio mode: %s\n", p); 1105 CX18_INFO_DEV(sd, "Preferred audio mode: %s\n", p);
1061 1106
1062 if ((audio_config & 0xf) == 0xf) { 1107 if ((audio_config & 0xf) == 0xf) {
1063 switch ((afc0 >> 3) & 0x1) { 1108 switch ((afc0 >> 3) & 0x1) {
1064 case 0: p = "system DK"; break; 1109 case 0: p = "system DK"; break;
1065 case 1: p = "system L"; break; 1110 case 1: p = "system L"; break;
1066 } 1111 }
1067 CX18_INFO("Selected 65 MHz format: %s\n", p); 1112 CX18_INFO_DEV(sd, "Selected 65 MHz format: %s\n", p);
1068 1113
1069 switch (afc0 & 0x7) { 1114 switch (afc0 & 0x7) {
1070 case 0: p = "Chroma"; break; 1115 case 0: p = "Chroma"; break;
@@ -1074,6 +1119,131 @@ static void log_audio_status(struct cx18 *cx)
1074 case 4: p = "autodetect"; break; 1119 case 4: p = "autodetect"; break;
1075 default: p = "undefined"; break; 1120 default: p = "undefined"; break;
1076 } 1121 }
1077 CX18_INFO("Selected 45 MHz format: %s\n", p); 1122 CX18_INFO_DEV(sd, "Selected 45 MHz format: %s\n", p);
1078 } 1123 }
1079} 1124}
1125
1126static int cx18_av_log_status(struct v4l2_subdev *sd)
1127{
1128 struct cx18 *cx = v4l2_get_subdevdata(sd);
1129 log_video_status(cx);
1130 log_audio_status(cx);
1131 return 0;
1132}
1133
1134static inline int cx18_av_dbg_match(const struct v4l2_dbg_match *match)
1135{
1136 return match->type == V4L2_CHIP_MATCH_HOST && match->addr == 1;
1137}
1138
1139static int cx18_av_g_chip_ident(struct v4l2_subdev *sd,
1140 struct v4l2_dbg_chip_ident *chip)
1141{
1142 struct cx18_av_state *state = to_cx18_av_state(sd);
1143
1144 if (cx18_av_dbg_match(&chip->match)) {
1145 chip->ident = state->id;
1146 chip->revision = state->rev;
1147 }
1148 return 0;
1149}
1150
1151#ifdef CONFIG_VIDEO_ADV_DEBUG
1152static int cx18_av_g_register(struct v4l2_subdev *sd,
1153 struct v4l2_dbg_register *reg)
1154{
1155 struct cx18 *cx = v4l2_get_subdevdata(sd);
1156
1157 if (!cx18_av_dbg_match(&reg->match))
1158 return -EINVAL;
1159 if ((reg->reg & 0x3) != 0)
1160 return -EINVAL;
1161 if (!capable(CAP_SYS_ADMIN))
1162 return -EPERM;
1163 reg->size = 4;
1164 reg->val = cx18_av_read4(cx, reg->reg & 0x00000ffc);
1165 return 0;
1166}
1167
1168static int cx18_av_s_register(struct v4l2_subdev *sd,
1169 struct v4l2_dbg_register *reg)
1170{
1171 struct cx18 *cx = v4l2_get_subdevdata(sd);
1172
1173 if (!cx18_av_dbg_match(&reg->match))
1174 return -EINVAL;
1175 if ((reg->reg & 0x3) != 0)
1176 return -EINVAL;
1177 if (!capable(CAP_SYS_ADMIN))
1178 return -EPERM;
1179 cx18_av_write4(cx, reg->reg & 0x00000ffc, reg->val);
1180 return 0;
1181}
1182#endif
1183
1184static const struct v4l2_subdev_core_ops cx18_av_general_ops = {
1185 .g_chip_ident = cx18_av_g_chip_ident,
1186 .log_status = cx18_av_log_status,
1187 .init = cx18_av_init,
1188 .reset = cx18_av_reset,
1189 .queryctrl = cx18_av_queryctrl,
1190 .g_ctrl = cx18_av_g_ctrl,
1191 .s_ctrl = cx18_av_s_ctrl,
1192#ifdef CONFIG_VIDEO_ADV_DEBUG
1193 .g_register = cx18_av_g_register,
1194 .s_register = cx18_av_s_register,
1195#endif
1196};
1197
1198static const struct v4l2_subdev_tuner_ops cx18_av_tuner_ops = {
1199 .s_radio = cx18_av_s_radio,
1200 .s_frequency = cx18_av_s_frequency,
1201 .g_tuner = cx18_av_g_tuner,
1202 .s_tuner = cx18_av_s_tuner,
1203 .s_std = cx18_av_s_std,
1204};
1205
1206static const struct v4l2_subdev_audio_ops cx18_av_audio_ops = {
1207 .s_clock_freq = cx18_av_s_clock_freq,
1208 .s_routing = cx18_av_s_audio_routing,
1209};
1210
1211static const struct v4l2_subdev_video_ops cx18_av_video_ops = {
1212 .s_routing = cx18_av_s_video_routing,
1213 .decode_vbi_line = cx18_av_decode_vbi_line,
1214 .s_stream = cx18_av_s_stream,
1215 .g_fmt = cx18_av_g_fmt,
1216 .s_fmt = cx18_av_s_fmt,
1217};
1218
1219static const struct v4l2_subdev_ops cx18_av_ops = {
1220 .core = &cx18_av_general_ops,
1221 .tuner = &cx18_av_tuner_ops,
1222 .audio = &cx18_av_audio_ops,
1223 .video = &cx18_av_video_ops,
1224};
1225
1226int cx18_av_probe(struct cx18 *cx)
1227{
1228 struct cx18_av_state *state = &cx->av_state;
1229 struct v4l2_subdev *sd;
1230
1231 state->rev = cx18_av_read4(cx, CXADEC_CHIP_CTRL) & 0xffff;
1232 state->id = ((state->rev >> 4) == CXADEC_CHIP_TYPE_MAKO)
1233 ? V4L2_IDENT_CX23418_843 : V4L2_IDENT_UNKNOWN;
1234
1235 state->vid_input = CX18_AV_COMPOSITE7;
1236 state->aud_input = CX18_AV_AUDIO8;
1237 state->audclk_freq = 48000;
1238 state->audmode = V4L2_TUNER_MODE_LANG1;
1239 state->slicer_line_delay = 0;
1240 state->slicer_line_offset = (10 + state->slicer_line_delay - 2);
1241
1242 sd = &state->sd;
1243 v4l2_subdev_init(sd, &cx18_av_ops);
1244 v4l2_set_subdevdata(sd, cx);
1245 snprintf(sd->name, sizeof(sd->name),
1246 "%s %03x", cx->v4l2_dev.name, (state->rev >> 4));
1247 sd->grp_id = CX18_HW_418_AV;
1248 return v4l2_device_register_subdev(&cx->v4l2_dev, sd);
1249}
diff --git a/drivers/media/video/cx18/cx18-av-core.h b/drivers/media/video/cx18/cx18-av-core.h
index cf68a6039091..c458120e8c90 100644
--- a/drivers/media/video/cx18/cx18-av-core.h
+++ b/drivers/media/video/cx18/cx18-av-core.h
@@ -25,6 +25,8 @@
25#ifndef _CX18_AV_CORE_H_ 25#ifndef _CX18_AV_CORE_H_
26#define _CX18_AV_CORE_H_ 26#define _CX18_AV_CORE_H_
27 27
28#include <media/v4l2-device.h>
29
28struct cx18; 30struct cx18;
29 31
30enum cx18_av_video_input { 32enum cx18_av_video_input {
@@ -73,17 +75,40 @@ enum cx18_av_audio_input {
73}; 75};
74 76
75struct cx18_av_state { 77struct cx18_av_state {
78 struct v4l2_subdev sd;
76 int radio; 79 int radio;
77 v4l2_std_id std; 80 v4l2_std_id std;
78 enum cx18_av_video_input vid_input; 81 enum cx18_av_video_input vid_input;
79 enum cx18_av_audio_input aud_input; 82 enum cx18_av_audio_input aud_input;
80 u32 audclk_freq; 83 u32 audclk_freq;
81 int audmode; 84 int audmode;
82 int vbi_line_offset;
83 int default_volume; 85 int default_volume;
84 u32 id; 86 u32 id;
85 u32 rev; 87 u32 rev;
86 int is_initialized; 88 int is_initialized;
89
90 /*
91 * The VBI slicer starts operating and counting lines, begining at
92 * slicer line count of 1, at D lines after the deassertion of VRESET.
93 * This staring field line, S, is 6 (& 319) or 10 (& 273) for 625 or 525
94 * line systems respectively. Sliced ancillary data captured on VBI
95 * slicer line M is inserted after the VBI slicer is done with line M,
96 * when VBI slicer line count is N = M+1. Thus when the VBI slicer
97 * reports a VBI slicer line number with ancillary data, the IDID0 byte
98 * indicates VBI slicer line N. The actual field line that the captured
99 * data comes from is
100 *
101 * L = M+(S+D-1) = N-1+(S+D-1) = N + (S+D-2).
102 *
103 * L is the line in the field, not frame, from which the VBI data came.
104 * N is the line reported by the slicer in the ancillary data.
105 * D is the slicer_line_delay value programmed into register 0x47f.
106 * S is 6 for 625 line systems or 10 for 525 line systems
107 * (S+D-2) is the slicer_line_offset used to convert slicer reported
108 * line counts to actual field lines.
109 */
110 int slicer_line_delay;
111 int slicer_line_offset;
87}; 112};
88 113
89 114
@@ -298,6 +323,16 @@ struct cx18_av_state {
298#define CXADEC_SELECT_AUDIO_STANDARD_FM 0xF9 /* FM radio */ 323#define CXADEC_SELECT_AUDIO_STANDARD_FM 0xF9 /* FM radio */
299#define CXADEC_SELECT_AUDIO_STANDARD_AUTO 0xFF /* Auto detect */ 324#define CXADEC_SELECT_AUDIO_STANDARD_AUTO 0xFF /* Auto detect */
300 325
326static inline struct cx18_av_state *to_cx18_av_state(struct v4l2_subdev *sd)
327{
328 return container_of(sd, struct cx18_av_state, sd);
329}
330
331enum cx18_av_subdev_init_arg {
332 CX18_AV_INIT_NORMAL = 0,
333 CX18_AV_INIT_PLLS = 1,
334};
335
301/* ----------------------------------------------------------------------- */ 336/* ----------------------------------------------------------------------- */
302/* cx18_av-core.c */ 337/* cx18_av-core.c */
303int cx18_av_write(struct cx18 *cx, u16 addr, u8 value); 338int cx18_av_write(struct cx18 *cx, u16 addr, u8 value);
@@ -310,20 +345,26 @@ u8 cx18_av_read(struct cx18 *cx, u16 addr);
310u32 cx18_av_read4(struct cx18 *cx, u16 addr); 345u32 cx18_av_read4(struct cx18 *cx, u16 addr);
311int cx18_av_and_or(struct cx18 *cx, u16 addr, unsigned mask, u8 value); 346int cx18_av_and_or(struct cx18 *cx, u16 addr, unsigned mask, u8 value);
312int cx18_av_and_or4(struct cx18 *cx, u16 addr, u32 mask, u32 value); 347int cx18_av_and_or4(struct cx18 *cx, u16 addr, u32 mask, u32 value);
313int cx18_av_cmd(struct cx18 *cx, unsigned int cmd, void *arg);
314void cx18_av_std_setup(struct cx18 *cx); 348void cx18_av_std_setup(struct cx18 *cx);
315 349
350int cx18_av_probe(struct cx18 *cx);
351
316/* ----------------------------------------------------------------------- */ 352/* ----------------------------------------------------------------------- */
317/* cx18_av-firmware.c */ 353/* cx18_av-firmware.c */
318int cx18_av_loadfw(struct cx18 *cx); 354int cx18_av_loadfw(struct cx18 *cx);
319 355
320/* ----------------------------------------------------------------------- */ 356/* ----------------------------------------------------------------------- */
321/* cx18_av-audio.c */ 357/* cx18_av-audio.c */
322int cx18_av_audio(struct cx18 *cx, unsigned int cmd, void *arg); 358int cx18_av_audio_g_ctrl(struct cx18 *cx, struct v4l2_control *ctrl);
359int cx18_av_audio_s_ctrl(struct cx18 *cx, struct v4l2_control *ctrl);
360int cx18_av_s_clock_freq(struct v4l2_subdev *sd, u32 freq);
323void cx18_av_audio_set_path(struct cx18 *cx); 361void cx18_av_audio_set_path(struct cx18 *cx);
324 362
325/* ----------------------------------------------------------------------- */ 363/* ----------------------------------------------------------------------- */
326/* cx18_av-vbi.c */ 364/* cx18_av-vbi.c */
327int cx18_av_vbi(struct cx18 *cx, unsigned int cmd, void *arg); 365int cx18_av_decode_vbi_line(struct v4l2_subdev *sd,
366 struct v4l2_decode_vbi_line *vbi);
367int cx18_av_vbi_g_fmt(struct cx18 *cx, struct v4l2_format *fmt);
368int cx18_av_vbi_s_fmt(struct cx18 *cx, struct v4l2_format *fmt);
328 369
329#endif 370#endif
diff --git a/drivers/media/video/cx18/cx18-av-firmware.c b/drivers/media/video/cx18/cx18-av-firmware.c
index c64fd0a05a97..49a55cc8d839 100644
--- a/drivers/media/video/cx18/cx18-av-firmware.c
+++ b/drivers/media/video/cx18/cx18-av-firmware.c
@@ -29,6 +29,7 @@
29 29
30int cx18_av_loadfw(struct cx18 *cx) 30int cx18_av_loadfw(struct cx18 *cx)
31{ 31{
32 struct v4l2_subdev *sd = &cx->av_state.sd;
32 const struct firmware *fw = NULL; 33 const struct firmware *fw = NULL;
33 u32 size; 34 u32 size;
34 u32 v; 35 u32 v;
@@ -36,8 +37,8 @@ int cx18_av_loadfw(struct cx18 *cx)
36 int i; 37 int i;
37 int retries1 = 0; 38 int retries1 = 0;
38 39
39 if (request_firmware(&fw, FWFILE, &cx->dev->dev) != 0) { 40 if (request_firmware(&fw, FWFILE, &cx->pci_dev->dev) != 0) {
40 CX18_ERR("unable to open firmware %s\n", FWFILE); 41 CX18_ERR_DEV(sd, "unable to open firmware %s\n", FWFILE);
41 return -EINVAL; 42 return -EINVAL;
42 } 43 }
43 44
@@ -88,7 +89,7 @@ int cx18_av_loadfw(struct cx18 *cx)
88 retries1++; 89 retries1++;
89 } 90 }
90 if (retries1 >= 5) { 91 if (retries1 >= 5) {
91 CX18_ERR("unable to load firmware %s\n", FWFILE); 92 CX18_ERR_DEV(sd, "unable to load firmware %s\n", FWFILE);
92 release_firmware(fw); 93 release_firmware(fw);
93 return -EIO; 94 return -EIO;
94 } 95 }
@@ -115,9 +116,9 @@ int cx18_av_loadfw(struct cx18 *cx)
115 are generated) */ 116 are generated) */
116 cx18_av_write4(cx, CXADEC_I2S_OUT_CTL, 0x000001A0); 117 cx18_av_write4(cx, CXADEC_I2S_OUT_CTL, 0x000001A0);
117 118
118 /* set alt I2s master clock to /16 and enable alt divider i2s 119 /* set alt I2s master clock to /0x16 and enable alt divider i2s
119 passthrough */ 120 passthrough */
120 cx18_av_write4(cx, CXADEC_PIN_CFG3, 0x5000B687); 121 cx18_av_write4(cx, CXADEC_PIN_CFG3, 0x5600B687);
121 122
122 cx18_av_write4_expect(cx, CXADEC_STD_DET_CTL, 0x000000F6, 0x000000F6, 123 cx18_av_write4_expect(cx, CXADEC_STD_DET_CTL, 0x000000F6, 0x000000F6,
123 0x3F00FFFF); 124 0x3F00FFFF);
@@ -131,7 +132,8 @@ int cx18_av_loadfw(struct cx18 *cx)
131 v = cx18_read_reg(cx, CX18_AUDIO_ENABLE); 132 v = cx18_read_reg(cx, CX18_AUDIO_ENABLE);
132 /* If bit 11 is 1, clear bit 10 */ 133 /* If bit 11 is 1, clear bit 10 */
133 if (v & 0x800) 134 if (v & 0x800)
134 cx18_write_reg(cx, v & 0xFFFFFBFF, CX18_AUDIO_ENABLE); 135 cx18_write_reg_expect(cx, v & 0xFFFFFBFF, CX18_AUDIO_ENABLE,
136 0, 0x400);
135 137
136 /* Enable WW auto audio standard detection */ 138 /* Enable WW auto audio standard detection */
137 v = cx18_av_read4(cx, CXADEC_STD_DET_CTL); 139 v = cx18_av_read4(cx, CXADEC_STD_DET_CTL);
@@ -142,6 +144,6 @@ int cx18_av_loadfw(struct cx18 *cx)
142 144
143 release_firmware(fw); 145 release_firmware(fw);
144 146
145 CX18_INFO("loaded %s firmware (%d bytes)\n", FWFILE, size); 147 CX18_INFO_DEV(sd, "loaded %s firmware (%d bytes)\n", FWFILE, size);
146 return 0; 148 return 0;
147} 149}
diff --git a/drivers/media/video/cx18/cx18-av-vbi.c b/drivers/media/video/cx18/cx18-av-vbi.c
index 1527ea4f6b06..23b31670bf1d 100644
--- a/drivers/media/video/cx18/cx18-av-vbi.c
+++ b/drivers/media/video/cx18/cx18-av-vbi.c
@@ -24,6 +24,52 @@
24 24
25#include "cx18-driver.h" 25#include "cx18-driver.h"
26 26
27/*
28 * For sliced VBI output, we set up to use VIP-1.1, 8-bit mode,
29 * NN counts 1 byte Dwords, an IDID with the VBI line # in it.
30 * Thus, according to the VIP-2 Spec, our VBI ancillary data lines
31 * (should!) look like:
32 * 4 byte EAV code: 0xff 0x00 0x00 0xRP
33 * unknown number of possible idle bytes
34 * 3 byte Anc data preamble: 0x00 0xff 0xff
35 * 1 byte data identifier: ne010iii (parity bits, 010, DID bits)
36 * 1 byte secondary data id: nessssss (parity bits, SDID bits)
37 * 1 byte data word count: necccccc (parity bits, NN Dword count)
38 * 2 byte Internal DID: VBI-line-# 0x80
39 * NN data bytes
40 * 1 byte checksum
41 * Fill bytes needed to fil out to 4*NN bytes of payload
42 *
43 * The RP codes for EAVs when in VIP-1.1 mode, not in raw mode, &
44 * in the vertical blanking interval are:
45 * 0xb0 (Task 0 VerticalBlank HorizontalBlank 0 0 0 0)
46 * 0xf0 (Task EvenField VerticalBlank HorizontalBlank 0 0 0 0)
47 *
48 * Since the V bit is only allowed to toggle in the EAV RP code, just
49 * before the first active region line and for active lines, they are:
50 * 0x90 (Task 0 0 HorizontalBlank 0 0 0 0)
51 * 0xd0 (Task EvenField 0 HorizontalBlank 0 0 0 0)
52 *
53 * The user application DID bytes we care about are:
54 * 0x91 (1 0 010 0 !ActiveLine AncDataPresent)
55 * 0x55 (0 1 010 2ndField !ActiveLine AncDataPresent)
56 *
57 */
58static const u8 sliced_vbi_did[2] = { 0x91, 0x55 };
59
60struct vbi_anc_data {
61 /* u8 eav[4]; */
62 /* u8 idle[]; Variable number of idle bytes */
63 u8 preamble[3];
64 u8 did;
65 u8 sdid;
66 u8 data_count;
67 u8 idid[2];
68 u8 payload[1]; /* data_count of payload */
69 /* u8 checksum; */
70 /* u8 fill[]; Variable number of fill bytes */
71};
72
27static int odd_parity(u8 c) 73static int odd_parity(u8 c)
28{ 74{
29 c ^= (c >> 4); 75 c ^= (c >> 4);
@@ -83,188 +129,189 @@ static int decode_vps(u8 *dst, u8 *p)
83 return err & 0xf0; 129 return err & 0xf0;
84} 130}
85 131
86int cx18_av_vbi(struct cx18 *cx, unsigned int cmd, void *arg) 132int cx18_av_vbi_g_fmt(struct cx18 *cx, struct v4l2_format *fmt)
87{ 133{
88 struct cx18_av_state *state = &cx->av_state; 134 struct cx18_av_state *state = &cx->av_state;
89 struct v4l2_format *fmt;
90 struct v4l2_sliced_vbi_format *svbi; 135 struct v4l2_sliced_vbi_format *svbi;
136 static const u16 lcr2vbi[] = {
137 0, V4L2_SLICED_TELETEXT_B, 0, /* 1 */
138 0, V4L2_SLICED_WSS_625, 0, /* 4 */
139 V4L2_SLICED_CAPTION_525, /* 6 */
140 0, 0, V4L2_SLICED_VPS, 0, 0, /* 9 */
141 0, 0, 0, 0
142 };
143 int is_pal = !(state->std & V4L2_STD_525_60);
144 int i;
91 145
92 switch (cmd) { 146 if (fmt->type != V4L2_BUF_TYPE_SLICED_VBI_CAPTURE)
93 case VIDIOC_G_FMT: 147 return -EINVAL;
94 { 148 svbi = &fmt->fmt.sliced;
95 static u16 lcr2vbi[] = { 149 memset(svbi, 0, sizeof(*svbi));
96 0, V4L2_SLICED_TELETEXT_B, 0, /* 1 */ 150 /* we're done if raw VBI is active */
97 0, V4L2_SLICED_WSS_625, 0, /* 4 */ 151 if ((cx18_av_read(cx, 0x404) & 0x10) == 0)
98 V4L2_SLICED_CAPTION_525, /* 6 */ 152 return 0;
99 0, 0, V4L2_SLICED_VPS, 0, 0, /* 9 */
100 0, 0, 0, 0
101 };
102 int is_pal = !(state->std & V4L2_STD_525_60);
103 int i;
104
105 fmt = arg;
106 if (fmt->type != V4L2_BUF_TYPE_SLICED_VBI_CAPTURE)
107 return -EINVAL;
108 svbi = &fmt->fmt.sliced;
109 memset(svbi, 0, sizeof(*svbi));
110 /* we're done if raw VBI is active */
111 if ((cx18_av_read(cx, 0x404) & 0x10) == 0)
112 break;
113
114 if (is_pal) {
115 for (i = 7; i <= 23; i++) {
116 u8 v = cx18_av_read(cx, 0x424 + i - 7);
117
118 svbi->service_lines[0][i] = lcr2vbi[v >> 4];
119 svbi->service_lines[1][i] = lcr2vbi[v & 0xf];
120 svbi->service_set |= svbi->service_lines[0][i] |
121 svbi->service_lines[1][i];
122 }
123 } else {
124 for (i = 10; i <= 21; i++) {
125 u8 v = cx18_av_read(cx, 0x424 + i - 10);
126
127 svbi->service_lines[0][i] = lcr2vbi[v >> 4];
128 svbi->service_lines[1][i] = lcr2vbi[v & 0xf];
129 svbi->service_set |= svbi->service_lines[0][i] |
130 svbi->service_lines[1][i];
131 }
132 }
133 break;
134 }
135 153
136 case VIDIOC_S_FMT: 154 if (is_pal) {
137 { 155 for (i = 7; i <= 23; i++) {
138 int is_pal = !(state->std & V4L2_STD_525_60); 156 u8 v = cx18_av_read(cx, 0x424 + i - 7);
139 int vbi_offset = is_pal ? 1 : 0; 157
140 int i, x; 158 svbi->service_lines[0][i] = lcr2vbi[v >> 4];
141 u8 lcr[24]; 159 svbi->service_lines[1][i] = lcr2vbi[v & 0xf];
142 160 svbi->service_set |= svbi->service_lines[0][i] |
143 fmt = arg; 161 svbi->service_lines[1][i];
144 if (fmt->type != V4L2_BUF_TYPE_SLICED_VBI_CAPTURE && 162 }
145 fmt->type != V4L2_BUF_TYPE_VBI_CAPTURE) 163 } else {
146 return -EINVAL; 164 for (i = 10; i <= 21; i++) {
147 svbi = &fmt->fmt.sliced; 165 u8 v = cx18_av_read(cx, 0x424 + i - 10);
148 if (fmt->type == V4L2_BUF_TYPE_VBI_CAPTURE) { 166
149 /* raw VBI */ 167 svbi->service_lines[0][i] = lcr2vbi[v >> 4];
150 memset(svbi, 0, sizeof(*svbi)); 168 svbi->service_lines[1][i] = lcr2vbi[v & 0xf];
151 169 svbi->service_set |= svbi->service_lines[0][i] |
152 /* Setup standard */ 170 svbi->service_lines[1][i];
153 cx18_av_std_setup(cx);
154
155 /* VBI Offset */
156 cx18_av_write(cx, 0x47f, vbi_offset);
157 cx18_av_write(cx, 0x404, 0x2e);
158 break;
159 } 171 }
172 }
173 return 0;
174}
160 175
161 for (x = 0; x <= 23; x++) 176int cx18_av_vbi_s_fmt(struct cx18 *cx, struct v4l2_format *fmt)
162 lcr[x] = 0x00; 177{
178 struct cx18_av_state *state = &cx->av_state;
179 struct v4l2_sliced_vbi_format *svbi;
180 int is_pal = !(state->std & V4L2_STD_525_60);
181 int i, x;
182 u8 lcr[24];
183
184 if (fmt->type != V4L2_BUF_TYPE_SLICED_VBI_CAPTURE &&
185 fmt->type != V4L2_BUF_TYPE_VBI_CAPTURE)
186 return -EINVAL;
187 svbi = &fmt->fmt.sliced;
188 if (fmt->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
189 /* raw VBI */
190 memset(svbi, 0, sizeof(*svbi));
163 191
164 /* Setup standard */ 192 /* Setup standard */
165 cx18_av_std_setup(cx); 193 cx18_av_std_setup(cx);
166 194
167 /* Sliced VBI */ 195 /* VBI Offset */
168 cx18_av_write(cx, 0x404, 0x32); /* Ancillary data */ 196 cx18_av_write(cx, 0x47f, state->slicer_line_delay);
169 cx18_av_write(cx, 0x406, 0x13); 197 cx18_av_write(cx, 0x404, 0x2e);
170 cx18_av_write(cx, 0x47f, vbi_offset); 198 return 0;
171 199 }
172 if (is_pal) {
173 for (i = 0; i <= 6; i++)
174 svbi->service_lines[0][i] =
175 svbi->service_lines[1][i] = 0;
176 } else {
177 for (i = 0; i <= 9; i++)
178 svbi->service_lines[0][i] =
179 svbi->service_lines[1][i] = 0;
180
181 for (i = 22; i <= 23; i++)
182 svbi->service_lines[0][i] =
183 svbi->service_lines[1][i] = 0;
184 }
185 200
186 for (i = 7; i <= 23; i++) { 201 for (x = 0; x <= 23; x++)
187 for (x = 0; x <= 1; x++) { 202 lcr[x] = 0x00;
188 switch (svbi->service_lines[1-x][i]) { 203
189 case V4L2_SLICED_TELETEXT_B: 204 /* Setup standard */
190 lcr[i] |= 1 << (4 * x); 205 cx18_av_std_setup(cx);
191 break; 206
192 case V4L2_SLICED_WSS_625: 207 /* Sliced VBI */
193 lcr[i] |= 4 << (4 * x); 208 cx18_av_write(cx, 0x404, 0x32); /* Ancillary data */
194 break; 209 cx18_av_write(cx, 0x406, 0x13);
195 case V4L2_SLICED_CAPTION_525: 210 cx18_av_write(cx, 0x47f, state->slicer_line_delay);
196 lcr[i] |= 6 << (4 * x); 211
197 break; 212 /* Force impossible lines to 0 */
198 case V4L2_SLICED_VPS: 213 if (is_pal) {
199 lcr[i] |= 9 << (4 * x); 214 for (i = 0; i <= 6; i++)
200 break; 215 svbi->service_lines[0][i] =
201 } 216 svbi->service_lines[1][i] = 0;
202 } 217 } else {
203 } 218 for (i = 0; i <= 9; i++)
219 svbi->service_lines[0][i] =
220 svbi->service_lines[1][i] = 0;
221
222 for (i = 22; i <= 23; i++)
223 svbi->service_lines[0][i] =
224 svbi->service_lines[1][i] = 0;
225 }
204 226
205 if (is_pal) { 227 /* Build register values for requested service lines */
206 for (x = 1, i = 0x424; i <= 0x434; i++, x++) 228 for (i = 7; i <= 23; i++) {
207 cx18_av_write(cx, i, lcr[6 + x]); 229 for (x = 0; x <= 1; x++) {
208 } else { 230 switch (svbi->service_lines[1-x][i]) {
209 for (x = 1, i = 0x424; i <= 0x430; i++, x++) 231 case V4L2_SLICED_TELETEXT_B:
210 cx18_av_write(cx, i, lcr[9 + x]); 232 lcr[i] |= 1 << (4 * x);
211 for (i = 0x431; i <= 0x434; i++) 233 break;
212 cx18_av_write(cx, i, 0); 234 case V4L2_SLICED_WSS_625:
235 lcr[i] |= 4 << (4 * x);
236 break;
237 case V4L2_SLICED_CAPTION_525:
238 lcr[i] |= 6 << (4 * x);
239 break;
240 case V4L2_SLICED_VPS:
241 lcr[i] |= 9 << (4 * x);
242 break;
243 }
213 } 244 }
245 }
214 246
215 cx18_av_write(cx, 0x43c, 0x16); 247 if (is_pal) {
216 cx18_av_write(cx, 0x474, is_pal ? 0x2a : 0x22); 248 for (x = 1, i = 0x424; i <= 0x434; i++, x++)
217 break; 249 cx18_av_write(cx, i, lcr[6 + x]);
250 } else {
251 for (x = 1, i = 0x424; i <= 0x430; i++, x++)
252 cx18_av_write(cx, i, lcr[9 + x]);
253 for (i = 0x431; i <= 0x434; i++)
254 cx18_av_write(cx, i, 0);
218 } 255 }
219 256
220 case VIDIOC_INT_DECODE_VBI_LINE: 257 cx18_av_write(cx, 0x43c, 0x16);
221 { 258 /* FIXME - should match vblank set in cx18_av_std_setup() */
222 struct v4l2_decode_vbi_line *vbi = arg; 259 cx18_av_write(cx, 0x474, is_pal ? 0x2a : 26);
223 u8 *p = vbi->p; 260 return 0;
224 int id1, id2, l, err = 0; 261}
262
263int cx18_av_decode_vbi_line(struct v4l2_subdev *sd,
264 struct v4l2_decode_vbi_line *vbi)
265{
266 struct cx18 *cx = v4l2_get_subdevdata(sd);
267 struct cx18_av_state *state = &cx->av_state;
268 struct vbi_anc_data *anc = (struct vbi_anc_data *)vbi->p;
269 u8 *p;
270 int did, sdid, l, err = 0;
271
272 /*
273 * Check for the ancillary data header for sliced VBI
274 */
275 if (anc->preamble[0] ||
276 anc->preamble[1] != 0xff || anc->preamble[2] != 0xff ||
277 (anc->did != sliced_vbi_did[0] &&
278 anc->did != sliced_vbi_did[1])) {
279 vbi->line = vbi->type = 0;
280 return 0;
281 }
225 282
226 if (p[0] || p[1] != 0xff || p[2] != 0xff || 283 did = anc->did;
227 (p[3] != 0x55 && p[3] != 0x91)) { 284 sdid = anc->sdid & 0xf;
228 vbi->line = vbi->type = 0; 285 l = anc->idid[0] & 0x3f;
229 break; 286 l += state->slicer_line_offset;
230 } 287 p = anc->payload;
231 288
232 p += 4; 289 /* Decode the SDID set by the slicer */
233 id1 = p[-1]; 290 switch (sdid) {
234 id2 = p[0] & 0xf; 291 case 1:
235 l = p[2] & 0x3f; 292 sdid = V4L2_SLICED_TELETEXT_B;
236 l += state->vbi_line_offset; 293 break;
237 p += 4; 294 case 4:
238 295 sdid = V4L2_SLICED_WSS_625;
239 switch (id2) { 296 break;
240 case 1: 297 case 6:
241 id2 = V4L2_SLICED_TELETEXT_B; 298 sdid = V4L2_SLICED_CAPTION_525;
242 break; 299 err = !odd_parity(p[0]) || !odd_parity(p[1]);
243 case 4: 300 break;
244 id2 = V4L2_SLICED_WSS_625; 301 case 9:
245 break; 302 sdid = V4L2_SLICED_VPS;
246 case 6: 303 if (decode_vps(p, p) != 0)
247 id2 = V4L2_SLICED_CAPTION_525;
248 err = !odd_parity(p[0]) || !odd_parity(p[1]);
249 break;
250 case 9:
251 id2 = V4L2_SLICED_VPS;
252 if (decode_vps(p, p) != 0)
253 err = 1;
254 break;
255 default:
256 id2 = 0;
257 err = 1; 304 err = 1;
258 break;
259 }
260
261 vbi->type = err ? 0 : id2;
262 vbi->line = err ? 0 : l;
263 vbi->is_second_field = err ? 0 : (id1 == 0x55);
264 vbi->p = p;
265 break; 305 break;
266 } 306 default:
307 sdid = 0;
308 err = 1;
309 break;
267 } 310 }
268 311
312 vbi->type = err ? 0 : sdid;
313 vbi->line = err ? 0 : l;
314 vbi->is_second_field = err ? 0 : (did == sliced_vbi_did[1]);
315 vbi->p = p;
269 return 0; 316 return 0;
270} 317}
diff --git a/drivers/media/video/cx18/cx18-cards.c b/drivers/media/video/cx18/cx18-cards.c
index e274043657dd..9bc221837847 100644
--- a/drivers/media/video/cx18/cx18-cards.c
+++ b/drivers/media/video/cx18/cx18-cards.c
@@ -51,12 +51,12 @@ static struct cx18_card_tuner_i2c cx18_i2c_std = {
51static const struct cx18_card cx18_card_hvr1600_esmt = { 51static const struct cx18_card cx18_card_hvr1600_esmt = {
52 .type = CX18_CARD_HVR_1600_ESMT, 52 .type = CX18_CARD_HVR_1600_ESMT,
53 .name = "Hauppauge HVR-1600", 53 .name = "Hauppauge HVR-1600",
54 .comment = "Raw VBI supported; Sliced VBI is not yet supported\n", 54 .comment = "Simultaneous Digital and Analog TV capture supported\n",
55 .v4l2_capabilities = CX18_CAP_ENCODER, 55 .v4l2_capabilities = CX18_CAP_ENCODER,
56 .hw_audio_ctrl = CX18_HW_CX23418, 56 .hw_audio_ctrl = CX18_HW_418_AV,
57 .hw_muxer = CX18_HW_CS5345, 57 .hw_muxer = CX18_HW_CS5345,
58 .hw_all = CX18_HW_TVEEPROM | CX18_HW_TUNER | 58 .hw_all = CX18_HW_TVEEPROM | CX18_HW_418_AV | CX18_HW_TUNER |
59 CX18_HW_CS5345 | CX18_HW_DVB, 59 CX18_HW_CS5345 | CX18_HW_DVB | CX18_HW_GPIO_RESET_CTRL,
60 .video_inputs = { 60 .video_inputs = {
61 { CX18_CARD_INPUT_VID_TUNER, 0, CX18_AV_COMPOSITE7 }, 61 { CX18_CARD_INPUT_VID_TUNER, 0, CX18_AV_COMPOSITE7 },
62 { CX18_CARD_INPUT_SVIDEO1, 1, CX18_AV_SVIDEO1 }, 62 { CX18_CARD_INPUT_SVIDEO1, 1, CX18_AV_SVIDEO1 },
@@ -97,12 +97,12 @@ static const struct cx18_card cx18_card_hvr1600_esmt = {
97static const struct cx18_card cx18_card_hvr1600_samsung = { 97static const struct cx18_card cx18_card_hvr1600_samsung = {
98 .type = CX18_CARD_HVR_1600_SAMSUNG, 98 .type = CX18_CARD_HVR_1600_SAMSUNG,
99 .name = "Hauppauge HVR-1600 (Preproduction)", 99 .name = "Hauppauge HVR-1600 (Preproduction)",
100 .comment = "Raw VBI supported; Sliced VBI is not yet supported\n", 100 .comment = "Simultaneous Digital and Analog TV capture supported\n",
101 .v4l2_capabilities = CX18_CAP_ENCODER, 101 .v4l2_capabilities = CX18_CAP_ENCODER,
102 .hw_audio_ctrl = CX18_HW_CX23418, 102 .hw_audio_ctrl = CX18_HW_418_AV,
103 .hw_muxer = CX18_HW_CS5345, 103 .hw_muxer = CX18_HW_CS5345,
104 .hw_all = CX18_HW_TVEEPROM | CX18_HW_TUNER | 104 .hw_all = CX18_HW_TVEEPROM | CX18_HW_418_AV | CX18_HW_TUNER |
105 CX18_HW_CS5345 | CX18_HW_DVB, 105 CX18_HW_CS5345 | CX18_HW_DVB | CX18_HW_GPIO_RESET_CTRL,
106 .video_inputs = { 106 .video_inputs = {
107 { CX18_CARD_INPUT_VID_TUNER, 0, CX18_AV_COMPOSITE7 }, 107 { CX18_CARD_INPUT_VID_TUNER, 0, CX18_AV_COMPOSITE7 },
108 { CX18_CARD_INPUT_SVIDEO1, 1, CX18_AV_SVIDEO1 }, 108 { CX18_CARD_INPUT_SVIDEO1, 1, CX18_AV_SVIDEO1 },
@@ -152,10 +152,10 @@ static const struct cx18_card_pci_info cx18_pci_h900[] = {
152static const struct cx18_card cx18_card_h900 = { 152static const struct cx18_card cx18_card_h900 = {
153 .type = CX18_CARD_COMPRO_H900, 153 .type = CX18_CARD_COMPRO_H900,
154 .name = "Compro VideoMate H900", 154 .name = "Compro VideoMate H900",
155 .comment = "Raw VBI supported; Sliced VBI is not yet supported\n", 155 .comment = "Analog TV capture supported\n",
156 .v4l2_capabilities = CX18_CAP_ENCODER, 156 .v4l2_capabilities = CX18_CAP_ENCODER,
157 .hw_audio_ctrl = CX18_HW_CX23418, 157 .hw_audio_ctrl = CX18_HW_418_AV,
158 .hw_all = CX18_HW_TUNER, 158 .hw_all = CX18_HW_418_AV | CX18_HW_TUNER | CX18_HW_GPIO_RESET_CTRL,
159 .video_inputs = { 159 .video_inputs = {
160 { CX18_CARD_INPUT_VID_TUNER, 0, CX18_AV_COMPOSITE2 }, 160 { CX18_CARD_INPUT_VID_TUNER, 0, CX18_AV_COMPOSITE2 },
161 { CX18_CARD_INPUT_SVIDEO1, 1, 161 { CX18_CARD_INPUT_SVIDEO1, 1,
@@ -201,8 +201,8 @@ static const struct cx18_card cx18_card_mpc718 = {
201 .name = "Yuan MPC718", 201 .name = "Yuan MPC718",
202 .comment = "Analog video capture works; some audio line in may not.\n", 202 .comment = "Analog video capture works; some audio line in may not.\n",
203 .v4l2_capabilities = CX18_CAP_ENCODER, 203 .v4l2_capabilities = CX18_CAP_ENCODER,
204 .hw_audio_ctrl = CX18_HW_CX23418, 204 .hw_audio_ctrl = CX18_HW_418_AV,
205 .hw_all = CX18_HW_TUNER, 205 .hw_all = CX18_HW_418_AV | CX18_HW_TUNER | CX18_HW_GPIO_RESET_CTRL,
206 .video_inputs = { 206 .video_inputs = {
207 { CX18_CARD_INPUT_VID_TUNER, 0, CX18_AV_COMPOSITE2 }, 207 { CX18_CARD_INPUT_VID_TUNER, 0, CX18_AV_COMPOSITE2 },
208 { CX18_CARD_INPUT_SVIDEO1, 1, 208 { CX18_CARD_INPUT_SVIDEO1, 1,
@@ -249,11 +249,11 @@ static const struct cx18_card_pci_info cx18_pci_cnxt_raptor_pal[] = {
249static const struct cx18_card cx18_card_cnxt_raptor_pal = { 249static const struct cx18_card cx18_card_cnxt_raptor_pal = {
250 .type = CX18_CARD_CNXT_RAPTOR_PAL, 250 .type = CX18_CARD_CNXT_RAPTOR_PAL,
251 .name = "Conexant Raptor PAL/SECAM", 251 .name = "Conexant Raptor PAL/SECAM",
252 .comment = "Raw VBI supported; Sliced VBI is not yet supported\n", 252 .comment = "Analog TV capture supported\n",
253 .v4l2_capabilities = CX18_CAP_ENCODER, 253 .v4l2_capabilities = CX18_CAP_ENCODER,
254 .hw_audio_ctrl = CX18_HW_CX23418, 254 .hw_audio_ctrl = CX18_HW_418_AV,
255 .hw_muxer = CX18_HW_GPIO, 255 .hw_muxer = CX18_HW_GPIO_MUX,
256 .hw_all = CX18_HW_TUNER | CX18_HW_GPIO, 256 .hw_all = CX18_HW_418_AV | CX18_HW_TUNER | CX18_HW_GPIO_MUX,
257 .video_inputs = { 257 .video_inputs = {
258 { CX18_CARD_INPUT_VID_TUNER, 0, CX18_AV_COMPOSITE2 }, 258 { CX18_CARD_INPUT_VID_TUNER, 0, CX18_AV_COMPOSITE2 },
259 { CX18_CARD_INPUT_SVIDEO1, 1, 259 { CX18_CARD_INPUT_SVIDEO1, 1,
@@ -306,8 +306,8 @@ static const struct cx18_card cx18_card_toshiba_qosmio_dvbt = {
306 .comment = "Experimenters and photos needed for device to work well.\n" 306 .comment = "Experimenters and photos needed for device to work well.\n"
307 "\tTo help, mail the ivtv-devel list (www.ivtvdriver.org).\n", 307 "\tTo help, mail the ivtv-devel list (www.ivtvdriver.org).\n",
308 .v4l2_capabilities = CX18_CAP_ENCODER, 308 .v4l2_capabilities = CX18_CAP_ENCODER,
309 .hw_audio_ctrl = CX18_HW_CX23418, 309 .hw_audio_ctrl = CX18_HW_418_AV,
310 .hw_all = CX18_HW_TUNER, 310 .hw_all = CX18_HW_418_AV | CX18_HW_TUNER | CX18_HW_GPIO_RESET_CTRL,
311 .video_inputs = { 311 .video_inputs = {
312 { CX18_CARD_INPUT_VID_TUNER, 0, CX18_AV_COMPOSITE6 }, 312 { CX18_CARD_INPUT_VID_TUNER, 0, CX18_AV_COMPOSITE6 },
313 { CX18_CARD_INPUT_SVIDEO1, 1, 313 { CX18_CARD_INPUT_SVIDEO1, 1,
@@ -339,19 +339,21 @@ static const struct cx18_card cx18_card_toshiba_qosmio_dvbt = {
339/* Leadtek WinFast PVR2100 */ 339/* Leadtek WinFast PVR2100 */
340 340
341static const struct cx18_card_pci_info cx18_pci_leadtek_pvr2100[] = { 341static const struct cx18_card_pci_info cx18_pci_leadtek_pvr2100[] = {
342 { PCI_DEVICE_ID_CX23418, CX18_PCI_ID_LEADTEK, 0x6f27 }, 342 { PCI_DEVICE_ID_CX23418, CX18_PCI_ID_LEADTEK, 0x6f27 }, /* PVR2100 */
343 { PCI_DEVICE_ID_CX23418, CX18_PCI_ID_LEADTEK, 0x6690 }, /* DVR3100 H */
343 { 0, 0, 0 } 344 { 0, 0, 0 }
344}; 345};
345 346
346static const struct cx18_card cx18_card_leadtek_pvr2100 = { 347static const struct cx18_card cx18_card_leadtek_pvr2100 = {
347 .type = CX18_CARD_LEADTEK_PVR2100, 348 .type = CX18_CARD_LEADTEK_PVR2100,
348 .name = "Leadtek WinFast PVR2100", 349 .name = "Leadtek WinFast PVR2100/DVR3100 H",
349 .comment = "Experimenters and photos needed for device to work well.\n" 350 .comment = "Experimenters and photos needed for device to work well.\n"
350 "\tTo help, mail the ivtv-devel list (www.ivtvdriver.org).\n", 351 "\tTo help, mail the ivtv-devel list (www.ivtvdriver.org).\n",
351 .v4l2_capabilities = CX18_CAP_ENCODER, 352 .v4l2_capabilities = CX18_CAP_ENCODER,
352 .hw_audio_ctrl = CX18_HW_CX23418, 353 .hw_audio_ctrl = CX18_HW_418_AV,
353 .hw_muxer = CX18_HW_GPIO, 354 .hw_muxer = CX18_HW_GPIO_MUX,
354 .hw_all = CX18_HW_TUNER | CX18_HW_GPIO, 355 .hw_all = CX18_HW_418_AV | CX18_HW_TUNER | CX18_HW_GPIO_MUX |
356 CX18_HW_GPIO_RESET_CTRL,
355 .video_inputs = { 357 .video_inputs = {
356 { CX18_CARD_INPUT_VID_TUNER, 0, CX18_AV_COMPOSITE2 }, 358 { CX18_CARD_INPUT_VID_TUNER, 0, CX18_AV_COMPOSITE2 },
357 { CX18_CARD_INPUT_SVIDEO1, 1, 359 { CX18_CARD_INPUT_SVIDEO1, 1,
diff --git a/drivers/media/video/cx18/cx18-cards.h b/drivers/media/video/cx18/cx18-cards.h
index 6fa7bcb42dde..3c552b6b7c4d 100644
--- a/drivers/media/video/cx18/cx18-cards.h
+++ b/drivers/media/video/cx18/cx18-cards.h
@@ -22,12 +22,13 @@
22 */ 22 */
23 23
24/* hardware flags */ 24/* hardware flags */
25#define CX18_HW_TUNER (1 << 0) 25#define CX18_HW_TUNER (1 << 0)
26#define CX18_HW_TVEEPROM (1 << 1) 26#define CX18_HW_TVEEPROM (1 << 1)
27#define CX18_HW_CS5345 (1 << 2) 27#define CX18_HW_CS5345 (1 << 2)
28#define CX18_HW_GPIO (1 << 3) 28#define CX18_HW_DVB (1 << 3)
29#define CX18_HW_CX23418 (1 << 4) 29#define CX18_HW_418_AV (1 << 4)
30#define CX18_HW_DVB (1 << 5) 30#define CX18_HW_GPIO_MUX (1 << 5)
31#define CX18_HW_GPIO_RESET_CTRL (1 << 6)
31 32
32/* video inputs */ 33/* video inputs */
33#define CX18_CARD_INPUT_VID_TUNER 1 34#define CX18_CARD_INPUT_VID_TUNER 1
@@ -49,8 +50,7 @@
49/* V4L2 capability aliases */ 50/* V4L2 capability aliases */
50#define CX18_CAP_ENCODER (V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_TUNER | \ 51#define CX18_CAP_ENCODER (V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_TUNER | \
51 V4L2_CAP_AUDIO | V4L2_CAP_READWRITE | \ 52 V4L2_CAP_AUDIO | V4L2_CAP_READWRITE | \
52 V4L2_CAP_VBI_CAPTURE) 53 V4L2_CAP_VBI_CAPTURE | V4L2_CAP_SLICED_VBI_CAPTURE)
53/* | V4L2_CAP_SLICED_VBI_CAPTURE) not yet */
54 54
55struct cx18_card_video_input { 55struct cx18_card_video_input {
56 u8 video_type; /* video input type */ 56 u8 video_type; /* video input type */
@@ -122,7 +122,7 @@ struct cx18_card {
122 char *comment; 122 char *comment;
123 u32 v4l2_capabilities; 123 u32 v4l2_capabilities;
124 u32 hw_audio_ctrl; /* hardware used for the V4L2 controls (only 124 u32 hw_audio_ctrl; /* hardware used for the V4L2 controls (only
125 1 dev allowed) */ 125 1 dev allowed currently) */
126 u32 hw_muxer; /* hardware used to multiplex audio input */ 126 u32 hw_muxer; /* hardware used to multiplex audio input */
127 u32 hw_all; /* all hardware used by the board */ 127 u32 hw_all; /* all hardware used by the board */
128 struct cx18_card_video_input video_inputs[CX18_CARD_MAX_VIDEO_INPUTS]; 128 struct cx18_card_video_input video_inputs[CX18_CARD_MAX_VIDEO_INPUTS];
diff --git a/drivers/media/video/cx18/cx18-controls.c b/drivers/media/video/cx18/cx18-controls.c
index 17edf305d649..82fc2f9d4021 100644
--- a/drivers/media/video/cx18/cx18-controls.c
+++ b/drivers/media/video/cx18/cx18-controls.c
@@ -22,14 +22,13 @@
22 */ 22 */
23 23
24#include "cx18-driver.h" 24#include "cx18-driver.h"
25#include "cx18-av-core.h"
26#include "cx18-cards.h" 25#include "cx18-cards.h"
27#include "cx18-ioctl.h" 26#include "cx18-ioctl.h"
28#include "cx18-audio.h" 27#include "cx18-audio.h"
29#include "cx18-i2c.h"
30#include "cx18-mailbox.h" 28#include "cx18-mailbox.h"
31#include "cx18-controls.h" 29#include "cx18-controls.h"
32 30
31/* Must be sorted from low to high control ID! */
33static const u32 user_ctrls[] = { 32static const u32 user_ctrls[] = {
34 V4L2_CID_USER_CLASS, 33 V4L2_CID_USER_CLASS,
35 V4L2_CID_BRIGHTNESS, 34 V4L2_CID_BRIGHTNESS,
@@ -66,7 +65,7 @@ int cx18_queryctrl(struct file *file, void *fh, struct v4l2_queryctrl *qctrl)
66 case V4L2_CID_HUE: 65 case V4L2_CID_HUE:
67 case V4L2_CID_SATURATION: 66 case V4L2_CID_SATURATION:
68 case V4L2_CID_CONTRAST: 67 case V4L2_CID_CONTRAST:
69 if (cx18_av_cmd(cx, VIDIOC_QUERYCTRL, qctrl)) 68 if (v4l2_subdev_call(cx->sd_av, core, queryctrl, qctrl))
70 qctrl->flags |= V4L2_CTRL_FLAG_DISABLED; 69 qctrl->flags |= V4L2_CTRL_FLAG_DISABLED;
71 return 0; 70 return 0;
72 71
@@ -76,7 +75,7 @@ int cx18_queryctrl(struct file *file, void *fh, struct v4l2_queryctrl *qctrl)
76 case V4L2_CID_AUDIO_BASS: 75 case V4L2_CID_AUDIO_BASS:
77 case V4L2_CID_AUDIO_TREBLE: 76 case V4L2_CID_AUDIO_TREBLE:
78 case V4L2_CID_AUDIO_LOUDNESS: 77 case V4L2_CID_AUDIO_LOUDNESS:
79 if (cx18_i2c_hw(cx, cx->card->hw_audio_ctrl, VIDIOC_QUERYCTRL, qctrl)) 78 if (v4l2_subdev_call(cx->sd_av, core, queryctrl, qctrl))
80 qctrl->flags |= V4L2_CTRL_FLAG_DISABLED; 79 qctrl->flags |= V4L2_CTRL_FLAG_DISABLED;
81 return 0; 80 return 0;
82 81
@@ -125,7 +124,7 @@ static int cx18_s_ctrl(struct cx18 *cx, struct v4l2_control *vctrl)
125 case V4L2_CID_HUE: 124 case V4L2_CID_HUE:
126 case V4L2_CID_SATURATION: 125 case V4L2_CID_SATURATION:
127 case V4L2_CID_CONTRAST: 126 case V4L2_CID_CONTRAST:
128 return cx18_av_cmd(cx, VIDIOC_S_CTRL, vctrl); 127 return v4l2_subdev_call(cx->sd_av, core, s_ctrl, vctrl);
129 128
130 case V4L2_CID_AUDIO_VOLUME: 129 case V4L2_CID_AUDIO_VOLUME:
131 case V4L2_CID_AUDIO_MUTE: 130 case V4L2_CID_AUDIO_MUTE:
@@ -133,7 +132,7 @@ static int cx18_s_ctrl(struct cx18 *cx, struct v4l2_control *vctrl)
133 case V4L2_CID_AUDIO_BASS: 132 case V4L2_CID_AUDIO_BASS:
134 case V4L2_CID_AUDIO_TREBLE: 133 case V4L2_CID_AUDIO_TREBLE:
135 case V4L2_CID_AUDIO_LOUDNESS: 134 case V4L2_CID_AUDIO_LOUDNESS:
136 return cx18_i2c_hw(cx, cx->card->hw_audio_ctrl, VIDIOC_S_CTRL, vctrl); 135 return v4l2_subdev_call(cx->sd_av, core, s_ctrl, vctrl);
137 136
138 default: 137 default:
139 CX18_DEBUG_IOCTL("invalid control 0x%x\n", vctrl->id); 138 CX18_DEBUG_IOCTL("invalid control 0x%x\n", vctrl->id);
@@ -150,7 +149,7 @@ static int cx18_g_ctrl(struct cx18 *cx, struct v4l2_control *vctrl)
150 case V4L2_CID_HUE: 149 case V4L2_CID_HUE:
151 case V4L2_CID_SATURATION: 150 case V4L2_CID_SATURATION:
152 case V4L2_CID_CONTRAST: 151 case V4L2_CID_CONTRAST:
153 return cx18_av_cmd(cx, VIDIOC_G_CTRL, vctrl); 152 return v4l2_subdev_call(cx->sd_av, core, g_ctrl, vctrl);
154 153
155 case V4L2_CID_AUDIO_VOLUME: 154 case V4L2_CID_AUDIO_VOLUME:
156 case V4L2_CID_AUDIO_MUTE: 155 case V4L2_CID_AUDIO_MUTE:
@@ -158,7 +157,8 @@ static int cx18_g_ctrl(struct cx18 *cx, struct v4l2_control *vctrl)
158 case V4L2_CID_AUDIO_BASS: 157 case V4L2_CID_AUDIO_BASS:
159 case V4L2_CID_AUDIO_TREBLE: 158 case V4L2_CID_AUDIO_TREBLE:
160 case V4L2_CID_AUDIO_LOUDNESS: 159 case V4L2_CID_AUDIO_LOUDNESS:
161 return cx18_i2c_hw(cx, cx->card->hw_audio_ctrl, VIDIOC_G_CTRL, vctrl); 160 return v4l2_subdev_call(cx->sd_av, core, g_ctrl, vctrl);
161
162 default: 162 default:
163 CX18_DEBUG_IOCTL("invalid control 0x%x\n", vctrl->id); 163 CX18_DEBUG_IOCTL("invalid control 0x%x\n", vctrl->id);
164 return -EINVAL; 164 return -EINVAL;
@@ -166,38 +166,57 @@ static int cx18_g_ctrl(struct cx18 *cx, struct v4l2_control *vctrl)
166 return 0; 166 return 0;
167} 167}
168 168
169static int cx18_setup_vbi_fmt(struct cx18 *cx, enum v4l2_mpeg_stream_vbi_fmt fmt) 169static int cx18_setup_vbi_fmt(struct cx18 *cx,
170 enum v4l2_mpeg_stream_vbi_fmt fmt,
171 enum v4l2_mpeg_stream_type type)
170{ 172{
171 if (!(cx->v4l2_cap & V4L2_CAP_SLICED_VBI_CAPTURE)) 173 if (!(cx->v4l2_cap & V4L2_CAP_SLICED_VBI_CAPTURE))
172 return -EINVAL; 174 return -EINVAL;
173 if (atomic_read(&cx->ana_capturing) > 0) 175 if (atomic_read(&cx->ana_capturing) > 0)
174 return -EBUSY; 176 return -EBUSY;
175 177
176 /* First try to allocate sliced VBI buffers if needed. */ 178 if (fmt != V4L2_MPEG_STREAM_VBI_FMT_IVTV ||
177 if (fmt && cx->vbi.sliced_mpeg_data[0] == NULL) { 179 type != V4L2_MPEG_STREAM_TYPE_MPEG2_PS) {
180 /* We don't do VBI insertion aside from IVTV format in a PS */
181 cx->vbi.insert_mpeg = V4L2_MPEG_STREAM_VBI_FMT_NONE;
182 CX18_DEBUG_INFO("disabled insertion of sliced VBI data into "
183 "the MPEG stream\n");
184 return 0;
185 }
186
187 /* Allocate sliced VBI buffers if needed. */
188 if (cx->vbi.sliced_mpeg_data[0] == NULL) {
178 int i; 189 int i;
179 190
180 for (i = 0; i < CX18_VBI_FRAMES; i++) { 191 for (i = 0; i < CX18_VBI_FRAMES; i++) {
181 /* Yuck, hardcoded. Needs to be a define */ 192 cx->vbi.sliced_mpeg_data[i] =
182 cx->vbi.sliced_mpeg_data[i] = kmalloc(2049, GFP_KERNEL); 193 kmalloc(CX18_SLICED_MPEG_DATA_BUFSZ, GFP_KERNEL);
183 if (cx->vbi.sliced_mpeg_data[i] == NULL) { 194 if (cx->vbi.sliced_mpeg_data[i] == NULL) {
184 while (--i >= 0) { 195 while (--i >= 0) {
185 kfree(cx->vbi.sliced_mpeg_data[i]); 196 kfree(cx->vbi.sliced_mpeg_data[i]);
186 cx->vbi.sliced_mpeg_data[i] = NULL; 197 cx->vbi.sliced_mpeg_data[i] = NULL;
187 } 198 }
199 cx->vbi.insert_mpeg =
200 V4L2_MPEG_STREAM_VBI_FMT_NONE;
201 CX18_WARN("Unable to allocate buffers for "
202 "sliced VBI data insertion\n");
188 return -ENOMEM; 203 return -ENOMEM;
189 } 204 }
190 } 205 }
191 } 206 }
192 207
193 cx->vbi.insert_mpeg = fmt; 208 cx->vbi.insert_mpeg = fmt;
209 CX18_DEBUG_INFO("enabled insertion of sliced VBI data into the MPEG PS,"
210 "when sliced VBI is enabled\n");
194 211
195 if (cx->vbi.insert_mpeg == 0) 212 /*
196 return 0; 213 * If our current settings have no lines set for capture, store a valid,
197 /* Need sliced data for mpeg insertion */ 214 * default set of service lines to capture, in our current settings.
215 */
198 if (cx18_get_service_set(cx->vbi.sliced_in) == 0) { 216 if (cx18_get_service_set(cx->vbi.sliced_in) == 0) {
199 if (cx->is_60hz) 217 if (cx->is_60hz)
200 cx->vbi.sliced_in->service_set = V4L2_SLICED_CAPTION_525; 218 cx->vbi.sliced_in->service_set =
219 V4L2_SLICED_CAPTION_525;
201 else 220 else
202 cx->vbi.sliced_in->service_set = V4L2_SLICED_WSS_625; 221 cx->vbi.sliced_in->service_set = V4L2_SLICED_WSS_625;
203 cx18_expand_service_set(cx->vbi.sliced_in, cx->is_50hz); 222 cx18_expand_service_set(cx->vbi.sliced_in, cx->is_50hz);
@@ -259,10 +278,12 @@ int cx18_s_ext_ctrls(struct file *file, void *fh, struct v4l2_ext_controls *c)
259 return err; 278 return err;
260 } 279 }
261 if (c->ctrl_class == V4L2_CTRL_CLASS_MPEG) { 280 if (c->ctrl_class == V4L2_CTRL_CLASS_MPEG) {
281 static u32 freqs[3] = { 44100, 48000, 32000 };
262 struct cx18_api_func_private priv; 282 struct cx18_api_func_private priv;
263 struct cx2341x_mpeg_params p = cx->params; 283 struct cx2341x_mpeg_params p = cx->params;
264 int err = cx2341x_ext_ctrls(&p, atomic_read(&cx->ana_capturing), 284 int err = cx2341x_ext_ctrls(&p, atomic_read(&cx->ana_capturing),
265 c, VIDIOC_S_EXT_CTRLS); 285 c, VIDIOC_S_EXT_CTRLS);
286 unsigned int idx;
266 287
267 if (err) 288 if (err)
268 return err; 289 return err;
@@ -277,16 +298,23 @@ int cx18_s_ext_ctrls(struct file *file, void *fh, struct v4l2_ext_controls *c)
277 fmt.fmt.pix.width = cx->params.width 298 fmt.fmt.pix.width = cx->params.width
278 / (is_mpeg1 ? 2 : 1); 299 / (is_mpeg1 ? 2 : 1);
279 fmt.fmt.pix.height = cx->params.height; 300 fmt.fmt.pix.height = cx->params.height;
280 cx18_av_cmd(cx, VIDIOC_S_FMT, &fmt); 301 v4l2_subdev_call(cx->sd_av, video, s_fmt, &fmt);
281 } 302 }
282 priv.cx = cx; 303 priv.cx = cx;
283 priv.s = &cx->streams[id->type]; 304 priv.s = &cx->streams[id->type];
284 err = cx2341x_update(&priv, cx18_api_func, &cx->params, &p); 305 err = cx2341x_update(&priv, cx18_api_func, &cx->params, &p);
285 if (!err && cx->params.stream_vbi_fmt != p.stream_vbi_fmt) 306 if (!err &&
286 err = cx18_setup_vbi_fmt(cx, p.stream_vbi_fmt); 307 (cx->params.stream_vbi_fmt != p.stream_vbi_fmt ||
308 cx->params.stream_type != p.stream_type))
309 err = cx18_setup_vbi_fmt(cx, p.stream_vbi_fmt,
310 p.stream_type);
287 cx->params = p; 311 cx->params = p;
288 cx->dualwatch_stereo_mode = p.audio_properties & 0x0300; 312 cx->dualwatch_stereo_mode = p.audio_properties & 0x0300;
289 cx18_audio_set_audio_clock_freq(cx, p.audio_properties & 0x03); 313 idx = p.audio_properties & 0x03;
314 /* The audio clock of the digitizer must match the codec sample
315 rate otherwise you get some very strange effects. */
316 if (idx < sizeof(freqs))
317 cx18_call_all(cx, audio, s_clock_freq, freqs[idx]);
290 return err; 318 return err;
291 } 319 }
292 return -EINVAL; 320 return -EINVAL;
diff --git a/drivers/media/video/cx18/cx18-driver.c b/drivers/media/video/cx18/cx18-driver.c
index f50cf2167adc..210c68aaae00 100644
--- a/drivers/media/video/cx18/cx18-driver.c
+++ b/drivers/media/video/cx18/cx18-driver.c
@@ -39,10 +39,6 @@
39 39
40#include <media/tveeprom.h> 40#include <media/tveeprom.h>
41 41
42
43/* var to keep track of the number of array elements in use */
44int cx18_cards_active;
45
46/* If you have already X v4l cards, then set this to X. This way 42/* If you have already X v4l cards, then set this to X. This way
47 the device numbers stay matched. Example: you have a WinTV card 43 the device numbers stay matched. Example: you have a WinTV card
48 without radio and a Compro H900 with. Normally this would give a 44 without radio and a Compro H900 with. Normally this would give a
@@ -50,12 +46,6 @@ int cx18_cards_active;
50 setting this to 1 you ensure that radio0 is now also radio1. */ 46 setting this to 1 you ensure that radio0 is now also radio1. */
51int cx18_first_minor; 47int cx18_first_minor;
52 48
53/* Master variable for all cx18 info */
54struct cx18 *cx18_cards[CX18_MAX_CARDS];
55
56/* Protects cx18_cards_active */
57DEFINE_SPINLOCK(cx18_cards_lock);
58
59/* add your revision and whatnot here */ 49/* add your revision and whatnot here */
60static struct pci_device_id cx18_pci_tbl[] __devinitdata = { 50static struct pci_device_id cx18_pci_tbl[] __devinitdata = {
61 {PCI_VENDOR_ID_CX, PCI_DEVICE_ID_CX23418, 51 {PCI_VENDOR_ID_CX, PCI_DEVICE_ID_CX23418,
@@ -65,6 +55,8 @@ static struct pci_device_id cx18_pci_tbl[] __devinitdata = {
65 55
66MODULE_DEVICE_TABLE(pci, cx18_pci_tbl); 56MODULE_DEVICE_TABLE(pci, cx18_pci_tbl);
67 57
58static atomic_t cx18_instance = ATOMIC_INIT(0);
59
68/* Parameter declarations */ 60/* Parameter declarations */
69static int cardtype[CX18_MAX_CARDS]; 61static int cardtype[CX18_MAX_CARDS];
70static int tuner[CX18_MAX_CARDS] = { -1, -1, -1, -1, -1, -1, -1, -1, 62static int tuner[CX18_MAX_CARDS] = { -1, -1, -1, -1, -1, -1, -1, -1,
@@ -159,7 +151,7 @@ MODULE_PARM_DESC(cardtype,
159 "\t\t\t 4 = Yuan MPC718\n" 151 "\t\t\t 4 = Yuan MPC718\n"
160 "\t\t\t 5 = Conexant Raptor PAL/SECAM\n" 152 "\t\t\t 5 = Conexant Raptor PAL/SECAM\n"
161 "\t\t\t 6 = Toshiba Qosmio DVB-T/Analog\n" 153 "\t\t\t 6 = Toshiba Qosmio DVB-T/Analog\n"
162 "\t\t\t 7 = Leadtek WinFast PVR2100\n" 154 "\t\t\t 7 = Leadtek WinFast PVR2100/DVR3100 H\n"
163 "\t\t\t 0 = Autodetect (default)\n" 155 "\t\t\t 0 = Autodetect (default)\n"
164 "\t\t\t-1 = Ignore this card\n\t\t"); 156 "\t\t\t-1 = Ignore this card\n\t\t");
165MODULE_PARM_DESC(pal, "Set PAL standard: B, G, H, D, K, I, M, N, Nc, 60"); 157MODULE_PARM_DESC(pal, "Set PAL standard: B, G, H, D, K, I, M, N, Nc, 60");
@@ -277,11 +269,16 @@ static void cx18_iounmap(struct cx18 *cx)
277/* Hauppauge card? get values from tveeprom */ 269/* Hauppauge card? get values from tveeprom */
278void cx18_read_eeprom(struct cx18 *cx, struct tveeprom *tv) 270void cx18_read_eeprom(struct cx18 *cx, struct tveeprom *tv)
279{ 271{
272 struct i2c_client c;
280 u8 eedata[256]; 273 u8 eedata[256];
281 274
282 cx->i2c_client[0].addr = 0xA0 >> 1; 275 memset(&c, 0, sizeof(c));
283 tveeprom_read(&cx->i2c_client[0], eedata, sizeof(eedata)); 276 strlcpy(c.name, "cx18 tveeprom tmp", sizeof(c.name));
284 tveeprom_hauppauge_analog(&cx->i2c_client[0], tv, eedata); 277 c.adapter = &cx->i2c_adap[0];
278 c.addr = 0xA0 >> 1;
279
280 tveeprom_read(&c, eedata, sizeof(eedata));
281 tveeprom_hauppauge_analog(&c, tv, eedata);
285} 282}
286 283
287static void cx18_process_eeprom(struct cx18 *cx) 284static void cx18_process_eeprom(struct cx18 *cx)
@@ -448,34 +445,38 @@ static void cx18_process_options(struct cx18 *cx)
448 cx->stream_buf_size[CX18_ENC_STREAM_TYPE_MPG] = enc_mpg_bufsize; 445 cx->stream_buf_size[CX18_ENC_STREAM_TYPE_MPG] = enc_mpg_bufsize;
449 cx->stream_buf_size[CX18_ENC_STREAM_TYPE_IDX] = enc_idx_bufsize; 446 cx->stream_buf_size[CX18_ENC_STREAM_TYPE_IDX] = enc_idx_bufsize;
450 cx->stream_buf_size[CX18_ENC_STREAM_TYPE_YUV] = enc_yuv_bufsize; 447 cx->stream_buf_size[CX18_ENC_STREAM_TYPE_YUV] = enc_yuv_bufsize;
451 cx->stream_buf_size[CX18_ENC_STREAM_TYPE_VBI] = 0; /* computed later */ 448 cx->stream_buf_size[CX18_ENC_STREAM_TYPE_VBI] = vbi_active_samples * 36;
452 cx->stream_buf_size[CX18_ENC_STREAM_TYPE_PCM] = enc_pcm_bufsize; 449 cx->stream_buf_size[CX18_ENC_STREAM_TYPE_PCM] = enc_pcm_bufsize;
453 cx->stream_buf_size[CX18_ENC_STREAM_TYPE_RAD] = 0; /* control no data */ 450 cx->stream_buf_size[CX18_ENC_STREAM_TYPE_RAD] = 0; /* control no data */
454 451
455 /* Except for VBI ensure stream_buffers & stream_buf_size are valid */ 452 /* Ensure stream_buffers & stream_buf_size are valid */
456 for (i = 0; i < CX18_MAX_STREAMS; i++) { 453 for (i = 0; i < CX18_MAX_STREAMS; i++) {
457 /* User said to use 0 buffers */ 454 if (cx->stream_buffers[i] == 0 || /* User said 0 buffers */
458 if (cx->stream_buffers[i] == 0) { 455 cx->options.megabytes[i] <= 0 || /* User said 0 MB total */
459 cx->options.megabytes[i] = 0; 456 cx->stream_buf_size[i] <= 0) { /* User said buf size 0 */
460 cx->stream_buf_size[i] = 0;
461 continue;
462 }
463 /* User said to use 0 MB total */
464 if (cx->options.megabytes[i] <= 0) {
465 cx->options.megabytes[i] = 0; 457 cx->options.megabytes[i] = 0;
466 cx->stream_buffers[i] = 0; 458 cx->stream_buffers[i] = 0;
467 cx->stream_buf_size[i] = 0; 459 cx->stream_buf_size[i] = 0;
468 continue; 460 continue;
469 } 461 }
470 /* VBI is computed later or user said buffer has size 0 */ 462 /*
471 if (cx->stream_buf_size[i] <= 0) { 463 * VBI is a special case where the stream_buf_size is fixed
472 if (i != CX18_ENC_STREAM_TYPE_VBI) { 464 * and already in bytes
473 cx->options.megabytes[i] = 0; 465 */
474 cx->stream_buffers[i] = 0; 466 if (i == CX18_ENC_STREAM_TYPE_VBI) {
475 cx->stream_buf_size[i] = 0; 467 if (cx->stream_buffers[i] < 0) {
468 cx->stream_buffers[i] =
469 cx->options.megabytes[i] * 1024 * 1024
470 / cx->stream_buf_size[i];
471 } else {
472 /* N.B. This might round down to 0 */
473 cx->options.megabytes[i] =
474 cx->stream_buffers[i]
475 * cx->stream_buf_size[i]/(1024 * 1024);
476 } 476 }
477 continue; 477 continue;
478 } 478 }
479 /* All other streams have stream_buf_size in kB at this point */
479 if (cx->stream_buffers[i] < 0) { 480 if (cx->stream_buffers[i] < 0) {
480 cx->stream_buffers[i] = cx->options.megabytes[i] * 1024 481 cx->stream_buffers[i] = cx->options.megabytes[i] * 1024
481 / cx->stream_buf_size[i]; 482 / cx->stream_buf_size[i];
@@ -487,9 +488,9 @@ static void cx18_process_options(struct cx18 *cx)
487 cx->stream_buf_size[i] *= 1024; /* convert from kB to bytes */ 488 cx->stream_buf_size[i] *= 1024; /* convert from kB to bytes */
488 } 489 }
489 490
490 cx->options.cardtype = cardtype[cx->num]; 491 cx->options.cardtype = cardtype[cx->instance];
491 cx->options.tuner = tuner[cx->num]; 492 cx->options.tuner = tuner[cx->instance];
492 cx->options.radio = radio[cx->num]; 493 cx->options.radio = radio[cx->instance];
493 494
494 cx->std = cx18_parse_std(cx); 495 cx->std = cx18_parse_std(cx);
495 if (cx->options.cardtype == -1) { 496 if (cx->options.cardtype == -1) {
@@ -502,7 +503,7 @@ static void cx18_process_options(struct cx18 *cx)
502 else if (cx->options.cardtype != 0) 503 else if (cx->options.cardtype != 0)
503 CX18_ERR("Unknown user specified type, trying to autodetect card\n"); 504 CX18_ERR("Unknown user specified type, trying to autodetect card\n");
504 if (cx->card == NULL) { 505 if (cx->card == NULL) {
505 if (cx->dev->subsystem_vendor == CX18_PCI_ID_HAUPPAUGE) { 506 if (cx->pci_dev->subsystem_vendor == CX18_PCI_ID_HAUPPAUGE) {
506 cx->card = cx18_get_card(CX18_CARD_HVR_1600_ESMT); 507 cx->card = cx18_get_card(CX18_CARD_HVR_1600_ESMT);
507 CX18_INFO("Autodetected Hauppauge card\n"); 508 CX18_INFO("Autodetected Hauppauge card\n");
508 } 509 }
@@ -512,13 +513,13 @@ static void cx18_process_options(struct cx18 *cx)
512 if (cx->card->pci_list == NULL) 513 if (cx->card->pci_list == NULL)
513 continue; 514 continue;
514 for (j = 0; cx->card->pci_list[j].device; j++) { 515 for (j = 0; cx->card->pci_list[j].device; j++) {
515 if (cx->dev->device != 516 if (cx->pci_dev->device !=
516 cx->card->pci_list[j].device) 517 cx->card->pci_list[j].device)
517 continue; 518 continue;
518 if (cx->dev->subsystem_vendor != 519 if (cx->pci_dev->subsystem_vendor !=
519 cx->card->pci_list[j].subsystem_vendor) 520 cx->card->pci_list[j].subsystem_vendor)
520 continue; 521 continue;
521 if (cx->dev->subsystem_device != 522 if (cx->pci_dev->subsystem_device !=
522 cx->card->pci_list[j].subsystem_device) 523 cx->card->pci_list[j].subsystem_device)
523 continue; 524 continue;
524 CX18_INFO("Autodetected %s card\n", cx->card->name); 525 CX18_INFO("Autodetected %s card\n", cx->card->name);
@@ -531,9 +532,10 @@ done:
531 if (cx->card == NULL) { 532 if (cx->card == NULL) {
532 cx->card = cx18_get_card(CX18_CARD_HVR_1600_ESMT); 533 cx->card = cx18_get_card(CX18_CARD_HVR_1600_ESMT);
533 CX18_ERR("Unknown card: vendor/device: [%04x:%04x]\n", 534 CX18_ERR("Unknown card: vendor/device: [%04x:%04x]\n",
534 cx->dev->vendor, cx->dev->device); 535 cx->pci_dev->vendor, cx->pci_dev->device);
535 CX18_ERR(" subsystem vendor/device: [%04x:%04x]\n", 536 CX18_ERR(" subsystem vendor/device: [%04x:%04x]\n",
536 cx->dev->subsystem_vendor, cx->dev->subsystem_device); 537 cx->pci_dev->subsystem_vendor,
538 cx->pci_dev->subsystem_device);
537 CX18_ERR("Defaulting to %s card\n", cx->card->name); 539 CX18_ERR("Defaulting to %s card\n", cx->card->name);
538 CX18_ERR("Please mail the vendor/device and subsystem vendor/device IDs and what kind of\n"); 540 CX18_ERR("Please mail the vendor/device and subsystem vendor/device IDs and what kind of\n");
539 CX18_ERR("card you have to the ivtv-devel mailinglist (www.ivtvdriver.org)\n"); 541 CX18_ERR("card you have to the ivtv-devel mailinglist (www.ivtvdriver.org)\n");
@@ -545,7 +547,7 @@ done:
545} 547}
546 548
547/* Precondition: the cx18 structure has been memset to 0. Only 549/* Precondition: the cx18 structure has been memset to 0. Only
548 the dev and num fields have been filled in. 550 the dev and instance fields have been filled in.
549 No assumptions on the card type may be made here (see cx18_init_struct2 551 No assumptions on the card type may be made here (see cx18_init_struct2
550 for that). 552 for that).
551 */ 553 */
@@ -553,18 +555,14 @@ static int __devinit cx18_init_struct1(struct cx18 *cx)
553{ 555{
554 int i; 556 int i;
555 557
556 cx->base_addr = pci_resource_start(cx->dev, 0); 558 cx->base_addr = pci_resource_start(cx->pci_dev, 0);
557 559
558 mutex_init(&cx->serialize_lock); 560 mutex_init(&cx->serialize_lock);
559 mutex_init(&cx->i2c_bus_lock[0]);
560 mutex_init(&cx->i2c_bus_lock[1]);
561 mutex_init(&cx->gpio_lock); 561 mutex_init(&cx->gpio_lock);
562 mutex_init(&cx->epu2apu_mb_lock); 562 mutex_init(&cx->epu2apu_mb_lock);
563 mutex_init(&cx->epu2cpu_mb_lock); 563 mutex_init(&cx->epu2cpu_mb_lock);
564 564
565 spin_lock_init(&cx->lock); 565 cx->work_queue = create_singlethread_workqueue(cx->v4l2_dev.name);
566
567 cx->work_queue = create_singlethread_workqueue(cx->name);
568 if (cx->work_queue == NULL) { 566 if (cx->work_queue == NULL) {
569 CX18_ERR("Unable to create work hander thread\n"); 567 CX18_ERR("Unable to create work hander thread\n");
570 return -ENOMEM; 568 return -ENOMEM;
@@ -587,7 +585,8 @@ static int __devinit cx18_init_struct1(struct cx18 *cx)
587 (cx->params.video_temporal_filter_mode << 1) | 585 (cx->params.video_temporal_filter_mode << 1) |
588 (cx->params.video_median_filter_type << 2); 586 (cx->params.video_median_filter_type << 2);
589 cx->params.port = CX2341X_PORT_MEMORY; 587 cx->params.port = CX2341X_PORT_MEMORY;
590 cx->params.capabilities = CX2341X_CAP_HAS_TS; 588 cx->params.capabilities =
589 CX2341X_CAP_HAS_TS | CX2341X_CAP_HAS_SLICED_VBI;
591 init_waitqueue_head(&cx->cap_w); 590 init_waitqueue_head(&cx->cap_w);
592 init_waitqueue_head(&cx->mb_apu_waitq); 591 init_waitqueue_head(&cx->mb_apu_waitq);
593 init_waitqueue_head(&cx->mb_cpu_waitq); 592 init_waitqueue_head(&cx->mb_cpu_waitq);
@@ -597,49 +596,6 @@ static int __devinit cx18_init_struct1(struct cx18 *cx)
597 cx->vbi.in.type = V4L2_BUF_TYPE_VBI_CAPTURE; 596 cx->vbi.in.type = V4L2_BUF_TYPE_VBI_CAPTURE;
598 cx->vbi.sliced_in = &cx->vbi.in.fmt.sliced; 597 cx->vbi.sliced_in = &cx->vbi.in.fmt.sliced;
599 598
600 /*
601 * The VBI line sizes depend on the pixel clock and the horiz rate
602 *
603 * (1/Fh)*(2*Fp) = Samples/line
604 * = 4 bytes EAV + Anc data in hblank + 4 bytes SAV + active samples
605 *
606 * Sliced VBI is sent as ancillary data during horizontal blanking
607 * Raw VBI is sent as active video samples during vertcal blanking
608 *
609 * We use a BT.656 pxiel clock of 13.5 MHz and a BT.656 active line
610 * length of 720 pixels @ 4:2:2 sampling. Thus...
611 *
612 * For systems that use a 15.734 kHz horizontal rate, such as
613 * NTSC-M, PAL-M, PAL-60, and other 60 Hz/525 line systems, we have:
614 *
615 * (1/15.734 kHz) * 2 * 13.5 MHz = 1716 samples/line =
616 * 4 bytes SAV + 268 bytes anc data + 4 bytes SAV + 1440 active samples
617 *
618 * For systems that use a 15.625 kHz horizontal rate, such as
619 * PAL-B/G/H, PAL-I, SECAM-L and other 50 Hz/625 line systems, we have:
620 *
621 * (1/15.625 kHz) * 2 * 13.5 MHz = 1728 samples/line =
622 * 4 bytes SAV + 280 bytes anc data + 4 bytes SAV + 1440 active samples
623 *
624 */
625
626 /* FIXME: init these based on tuner std & modify when std changes */
627 /* CX18-AV-Core number of VBI samples output per horizontal line */
628 cx->vbi.raw_decoder_line_size = 1444; /* 4 byte SAV + 2 * 720 */
629 cx->vbi.sliced_decoder_line_size = 272; /* 60 Hz: 268+4, 50 Hz: 280+4 */
630
631 /* CX18-AV-Core VBI samples/line possibly rounded up */
632 cx->vbi.raw_size = 1444; /* Real max size is 1444 */
633 cx->vbi.sliced_size = 284; /* Real max size is 284 */
634
635 /*
636 * CX18-AV-Core SAV/EAV RP codes in VIP 1.x mode
637 * Task Field VerticalBlank HorizontalBlank 0 0 0 0
638 */
639 cx->vbi.raw_decoder_sav_odd_field = 0x20; /* V */
640 cx->vbi.raw_decoder_sav_even_field = 0x60; /* FV */
641 cx->vbi.sliced_decoder_sav_odd_field = 0xB0; /* T VH - actually EAV */
642 cx->vbi.sliced_decoder_sav_even_field = 0xF0; /* TFVH - actually EAV */
643 return 0; 599 return 0;
644} 600}
645 601
@@ -668,15 +624,9 @@ static void __devinit cx18_init_struct2(struct cx18 *cx)
668 i = 0; 624 i = 0;
669 cx->active_input = i; 625 cx->active_input = i;
670 cx->audio_input = cx->card->video_inputs[i].audio_index; 626 cx->audio_input = cx->card->video_inputs[i].audio_index;
671 cx->av_state.vid_input = CX18_AV_COMPOSITE7;
672 cx->av_state.aud_input = CX18_AV_AUDIO8;
673 cx->av_state.audclk_freq = 48000;
674 cx->av_state.audmode = V4L2_TUNER_MODE_LANG1;
675 /* FIXME - 8 is NTSC value, investigate */
676 cx->av_state.vbi_line_offset = 8;
677} 627}
678 628
679static int cx18_setup_pci(struct cx18 *cx, struct pci_dev *dev, 629static int cx18_setup_pci(struct cx18 *cx, struct pci_dev *pci_dev,
680 const struct pci_device_id *pci_id) 630 const struct pci_device_id *pci_id)
681{ 631{
682 u16 cmd; 632 u16 cmd;
@@ -684,124 +634,125 @@ static int cx18_setup_pci(struct cx18 *cx, struct pci_dev *dev,
684 634
685 CX18_DEBUG_INFO("Enabling pci device\n"); 635 CX18_DEBUG_INFO("Enabling pci device\n");
686 636
687 if (pci_enable_device(dev)) { 637 if (pci_enable_device(pci_dev)) {
688 CX18_ERR("Can't enable device %d!\n", cx->num); 638 CX18_ERR("Can't enable device %d!\n", cx->instance);
689 return -EIO; 639 return -EIO;
690 } 640 }
691 if (pci_set_dma_mask(dev, 0xffffffff)) { 641 if (pci_set_dma_mask(pci_dev, 0xffffffff)) {
692 CX18_ERR("No suitable DMA available on card %d.\n", cx->num); 642 CX18_ERR("No suitable DMA available, card %d\n", cx->instance);
693 return -EIO; 643 return -EIO;
694 } 644 }
695 if (!request_mem_region(cx->base_addr, CX18_MEM_SIZE, "cx18 encoder")) { 645 if (!request_mem_region(cx->base_addr, CX18_MEM_SIZE, "cx18 encoder")) {
696 CX18_ERR("Cannot request encoder memory region on card %d.\n", cx->num); 646 CX18_ERR("Cannot request encoder memory region, card %d\n",
647 cx->instance);
697 return -EIO; 648 return -EIO;
698 } 649 }
699 650
700 /* Enable bus mastering and memory mapped IO for the CX23418 */ 651 /* Enable bus mastering and memory mapped IO for the CX23418 */
701 pci_read_config_word(dev, PCI_COMMAND, &cmd); 652 pci_read_config_word(pci_dev, PCI_COMMAND, &cmd);
702 cmd |= PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER; 653 cmd |= PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER;
703 pci_write_config_word(dev, PCI_COMMAND, cmd); 654 pci_write_config_word(pci_dev, PCI_COMMAND, cmd);
704 655
705 pci_read_config_byte(dev, PCI_CLASS_REVISION, &cx->card_rev); 656 pci_read_config_byte(pci_dev, PCI_CLASS_REVISION, &cx->card_rev);
706 pci_read_config_byte(dev, PCI_LATENCY_TIMER, &pci_latency); 657 pci_read_config_byte(pci_dev, PCI_LATENCY_TIMER, &pci_latency);
707 658
708 if (pci_latency < 64 && cx18_pci_latency) { 659 if (pci_latency < 64 && cx18_pci_latency) {
709 CX18_INFO("Unreasonably low latency timer, " 660 CX18_INFO("Unreasonably low latency timer, "
710 "setting to 64 (was %d)\n", pci_latency); 661 "setting to 64 (was %d)\n", pci_latency);
711 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 64); 662 pci_write_config_byte(pci_dev, PCI_LATENCY_TIMER, 64);
712 pci_read_config_byte(dev, PCI_LATENCY_TIMER, &pci_latency); 663 pci_read_config_byte(pci_dev, PCI_LATENCY_TIMER, &pci_latency);
713 } 664 }
714 665
715 CX18_DEBUG_INFO("cx%d (rev %d) at %02x:%02x.%x, " 666 CX18_DEBUG_INFO("cx%d (rev %d) at %02x:%02x.%x, "
716 "irq: %d, latency: %d, memory: 0x%lx\n", 667 "irq: %d, latency: %d, memory: 0x%lx\n",
717 cx->dev->device, cx->card_rev, dev->bus->number, 668 cx->pci_dev->device, cx->card_rev, pci_dev->bus->number,
718 PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn), 669 PCI_SLOT(pci_dev->devfn), PCI_FUNC(pci_dev->devfn),
719 cx->dev->irq, pci_latency, (unsigned long)cx->base_addr); 670 cx->pci_dev->irq, pci_latency, (unsigned long)cx->base_addr);
720 671
721 return 0; 672 return 0;
722} 673}
723 674
724#ifdef MODULE 675static void cx18_init_subdevs(struct cx18 *cx)
725static u32 cx18_request_module(struct cx18 *cx, u32 hw,
726 const char *name, u32 id)
727{
728 if ((hw & id) == 0)
729 return hw;
730 if (request_module(name) != 0) {
731 CX18_ERR("Failed to load module %s\n", name);
732 return hw & ~id;
733 }
734 CX18_DEBUG_INFO("Loaded module %s\n", name);
735 return hw;
736}
737#endif
738
739static void cx18_load_and_init_modules(struct cx18 *cx)
740{ 676{
741 u32 hw = cx->card->hw_all; 677 u32 hw = cx->card->hw_all;
678 u32 device;
742 int i; 679 int i;
743 680
744#ifdef MODULE 681 for (i = 0, device = 1; i < 32; i++, device <<= 1) {
745 /* load modules */
746#ifdef CONFIG_MEDIA_TUNER_MODULE
747 hw = cx18_request_module(cx, hw, "tuner", CX18_HW_TUNER);
748#endif
749#ifdef CONFIG_VIDEO_CS5345_MODULE
750 hw = cx18_request_module(cx, hw, "cs5345", CX18_HW_CS5345);
751#endif
752#endif
753
754 /* check which i2c devices are actually found */
755 for (i = 0; i < 32; i++) {
756 u32 device = 1 << i;
757 682
758 if (!(device & hw)) 683 if (!(device & hw))
759 continue; 684 continue;
760 if (device == CX18_HW_GPIO || device == CX18_HW_TVEEPROM || 685
761 device == CX18_HW_CX23418 || device == CX18_HW_DVB) { 686 switch (device) {
762 /* These 'devices' do not use i2c probing */ 687 case CX18_HW_DVB:
688 case CX18_HW_TVEEPROM:
689 /* These subordinate devices do not use probing */
763 cx->hw_flags |= device; 690 cx->hw_flags |= device;
764 continue; 691 break;
765 } 692 case CX18_HW_418_AV:
766 cx18_i2c_register(cx, i); 693 /* The A/V decoder gets probed earlier to set PLLs */
767 if (cx18_i2c_hw_addr(cx, device) > 0) 694 /* Just note that the card uses it (i.e. has analog) */
768 cx->hw_flags |= device; 695 cx->hw_flags |= device;
696 break;
697 case CX18_HW_GPIO_RESET_CTRL:
698 /*
699 * The Reset Controller gets probed and added to
700 * hw_flags earlier for i2c adapter/bus initialization
701 */
702 break;
703 case CX18_HW_GPIO_MUX:
704 if (cx18_gpio_register(cx, device) == 0)
705 cx->hw_flags |= device;
706 break;
707 default:
708 if (cx18_i2c_register(cx, i) == 0)
709 cx->hw_flags |= device;
710 break;
711 }
769 } 712 }
770 713
771 hw = cx->hw_flags; 714 if (cx->hw_flags & CX18_HW_418_AV)
715 cx->sd_av = cx18_find_hw(cx, CX18_HW_418_AV);
716
717 if (cx->card->hw_muxer != 0)
718 cx->sd_extmux = cx18_find_hw(cx, cx->card->hw_muxer);
772} 719}
773 720
774static int __devinit cx18_probe(struct pci_dev *dev, 721static int __devinit cx18_probe(struct pci_dev *pci_dev,
775 const struct pci_device_id *pci_id) 722 const struct pci_device_id *pci_id)
776{ 723{
777 int retval = 0; 724 int retval = 0;
778 int i; 725 int i;
779 int vbi_buf_size;
780 u32 devtype; 726 u32 devtype;
781 struct cx18 *cx; 727 struct cx18 *cx;
782 728
783 spin_lock(&cx18_cards_lock); 729 /* FIXME - module parameter arrays constrain max instances */
784 730 i = atomic_inc_return(&cx18_instance) - 1;
785 /* Make sure we've got a place for this card */ 731 if (i >= CX18_MAX_CARDS) {
786 if (cx18_cards_active == CX18_MAX_CARDS) { 732 printk(KERN_ERR "cx18: cannot manage card %d, driver has a "
787 printk(KERN_ERR "cx18: Maximum number of cards detected (%d).\n", 733 "limit of 0 - %d\n", i, CX18_MAX_CARDS - 1);
788 cx18_cards_active);
789 spin_unlock(&cx18_cards_lock);
790 return -ENOMEM; 734 return -ENOMEM;
791 } 735 }
792 736
793 cx = kzalloc(sizeof(struct cx18), GFP_ATOMIC); 737 cx = kzalloc(sizeof(struct cx18), GFP_ATOMIC);
794 if (!cx) { 738 if (cx == NULL) {
795 spin_unlock(&cx18_cards_lock); 739 printk(KERN_ERR "cx18: cannot manage card %d, out of memory\n",
740 i);
796 return -ENOMEM; 741 return -ENOMEM;
797 } 742 }
798 cx18_cards[cx18_cards_active] = cx; 743 cx->pci_dev = pci_dev;
799 cx->dev = dev; 744 cx->instance = i;
800 cx->num = cx18_cards_active++;
801 snprintf(cx->name, sizeof(cx->name), "cx18-%d", cx->num);
802 CX18_INFO("Initializing card #%d\n", cx->num);
803 745
804 spin_unlock(&cx18_cards_lock); 746 retval = v4l2_device_register(&pci_dev->dev, &cx->v4l2_dev);
747 if (retval) {
748 printk(KERN_ERR "cx18: v4l2_device_register of card %d failed"
749 "\n", cx->instance);
750 kfree(cx);
751 return retval;
752 }
753 snprintf(cx->v4l2_dev.name, sizeof(cx->v4l2_dev.name), "cx18-%d",
754 cx->instance);
755 CX18_INFO("Initializing card %d\n", cx->instance);
805 756
806 cx18_process_options(cx); 757 cx18_process_options(cx);
807 if (cx->options.cardtype == -1) { 758 if (cx->options.cardtype == -1) {
@@ -816,13 +767,10 @@ static int __devinit cx18_probe(struct pci_dev *dev,
816 CX18_DEBUG_INFO("base addr: 0x%08x\n", cx->base_addr); 767 CX18_DEBUG_INFO("base addr: 0x%08x\n", cx->base_addr);
817 768
818 /* PCI Device Setup */ 769 /* PCI Device Setup */
819 retval = cx18_setup_pci(cx, dev, pci_id); 770 retval = cx18_setup_pci(cx, pci_dev, pci_id);
820 if (retval != 0) 771 if (retval != 0)
821 goto free_workqueue; 772 goto free_workqueue;
822 773
823 /* save cx in the pci struct for later use */
824 pci_set_drvdata(dev, cx);
825
826 /* map io memory */ 774 /* map io memory */
827 CX18_DEBUG_INFO("attempting ioremap at 0x%08x len 0x%08x\n", 775 CX18_DEBUG_INFO("attempting ioremap at 0x%08x len 0x%08x\n",
828 cx->base_addr + CX18_MEM_OFFSET, CX18_MEM_SIZE); 776 cx->base_addr + CX18_MEM_OFFSET, CX18_MEM_SIZE);
@@ -856,6 +804,23 @@ static int __devinit cx18_probe(struct pci_dev *dev,
856 804
857 cx18_gpio_init(cx); 805 cx18_gpio_init(cx);
858 806
807 /* Initialize integrated A/V decoder early to set PLLs, just in case */
808 retval = cx18_av_probe(cx);
809 if (retval) {
810 CX18_ERR("Could not register A/V decoder subdevice\n");
811 goto free_map;
812 }
813 cx18_call_hw(cx, CX18_HW_418_AV, core, init, (u32) CX18_AV_INIT_PLLS);
814
815 /* Initialize GPIO Reset Controller to do chip resets during i2c init */
816 if (cx->card->hw_all & CX18_HW_GPIO_RESET_CTRL) {
817 if (cx18_gpio_register(cx, CX18_HW_GPIO_RESET_CTRL) != 0)
818 CX18_WARN("Could not register GPIO reset controller"
819 "subdevice; proceeding anyway.\n");
820 else
821 cx->hw_flags |= CX18_HW_GPIO_RESET_CTRL;
822 }
823
859 /* active i2c */ 824 /* active i2c */
860 CX18_DEBUG_INFO("activating i2c...\n"); 825 CX18_DEBUG_INFO("activating i2c...\n");
861 retval = init_cx18_i2c(cx); 826 retval = init_cx18_i2c(cx);
@@ -864,8 +829,6 @@ static int __devinit cx18_probe(struct pci_dev *dev,
864 goto free_map; 829 goto free_map;
865 } 830 }
866 831
867 CX18_DEBUG_INFO("Active card count: %d.\n", cx18_cards_active);
868
869 if (cx->card->hw_all & CX18_HW_TVEEPROM) { 832 if (cx->card->hw_all & CX18_HW_TVEEPROM) {
870 /* Based on the model number the cardtype may be changed. 833 /* Based on the model number the cardtype may be changed.
871 The PCI IDs are not always reliable. */ 834 The PCI IDs are not always reliable. */
@@ -881,8 +844,9 @@ static int __devinit cx18_probe(struct pci_dev *dev,
881 cx18_init_scb(cx); 844 cx18_init_scb(cx);
882 845
883 /* Register IRQ */ 846 /* Register IRQ */
884 retval = request_irq(cx->dev->irq, cx18_irq_handler, 847 retval = request_irq(cx->pci_dev->irq, cx18_irq_handler,
885 IRQF_SHARED | IRQF_DISABLED, cx->name, (void *)cx); 848 IRQF_SHARED | IRQF_DISABLED,
849 cx->v4l2_dev.name, (void *)cx);
886 if (retval) { 850 if (retval) {
887 CX18_ERR("Failed to register irq %d\n", retval); 851 CX18_ERR("Failed to register irq %d\n", retval);
888 goto free_i2c; 852 goto free_i2c;
@@ -917,33 +881,14 @@ static int __devinit cx18_probe(struct pci_dev *dev,
917 initialization. */ 881 initialization. */
918 cx18_init_struct2(cx); 882 cx18_init_struct2(cx);
919 883
920 cx18_load_and_init_modules(cx); 884 cx18_init_subdevs(cx);
921 885
922 if (cx->std & V4L2_STD_525_60) { 886 if (cx->std & V4L2_STD_525_60)
923 cx->is_60hz = 1; 887 cx->is_60hz = 1;
924 cx->is_out_60hz = 1; 888 else
925 } else {
926 cx->is_50hz = 1; 889 cx->is_50hz = 1;
927 cx->is_out_50hz = 1;
928 }
929 cx->params.video_gop_size = cx->is_60hz ? 15 : 12;
930
931 /*
932 * FIXME: setting the buffer size based on the tuner standard is
933 * suboptimal, as the CVBS and SVideo inputs could use a different std
934 * and the buffer could end up being too small in that case.
935 */
936 vbi_buf_size = cx->vbi.raw_size * (cx->is_60hz ? 24 : 36) / 2;
937 cx->stream_buf_size[CX18_ENC_STREAM_TYPE_VBI] = vbi_buf_size;
938 890
939 if (cx->stream_buffers[CX18_ENC_STREAM_TYPE_VBI] < 0) 891 cx->params.video_gop_size = cx->is_60hz ? 15 : 12;
940 cx->stream_buffers[CX18_ENC_STREAM_TYPE_VBI] =
941 cx->options.megabytes[CX18_ENC_STREAM_TYPE_VBI] * 1024 * 1024
942 / vbi_buf_size;
943 else
944 cx->options.megabytes[CX18_ENC_STREAM_TYPE_VBI] =
945 cx->stream_buffers[CX18_ENC_STREAM_TYPE_VBI] * vbi_buf_size
946 / (1024 * 1024);
947 892
948 if (cx->options.radio > 0) 893 if (cx->options.radio > 0)
949 cx->v4l2_cap |= V4L2_CAP_RADIO; 894 cx->v4l2_cap |= V4L2_CAP_RADIO;
@@ -956,7 +901,7 @@ static int __devinit cx18_probe(struct pci_dev *dev,
956 setup.mode_mask = T_ANALOG_TV; /* matches TV tuners */ 901 setup.mode_mask = T_ANALOG_TV; /* matches TV tuners */
957 setup.tuner_callback = (setup.type == TUNER_XC2028) ? 902 setup.tuner_callback = (setup.type == TUNER_XC2028) ?
958 cx18_reset_tuner_gpio : NULL; 903 cx18_reset_tuner_gpio : NULL;
959 cx18_call_i2c_clients(cx, TUNER_SET_TYPE_ADDR, &setup); 904 cx18_call_all(cx, tuner, s_type_addr, &setup);
960 if (setup.type == TUNER_XC2028) { 905 if (setup.type == TUNER_XC2028) {
961 static struct xc2028_ctrl ctrl = { 906 static struct xc2028_ctrl ctrl = {
962 .fname = XC2028_DEFAULT_FIRMWARE, 907 .fname = XC2028_DEFAULT_FIRMWARE,
@@ -966,7 +911,7 @@ static int __devinit cx18_probe(struct pci_dev *dev,
966 .tuner = cx->options.tuner, 911 .tuner = cx->options.tuner,
967 .priv = &ctrl, 912 .priv = &ctrl,
968 }; 913 };
969 cx18_call_i2c_clients(cx, TUNER_SET_CONFIG, &cfg); 914 cx18_call_all(cx, tuner, s_config, &cfg);
970 } 915 }
971 } 916 }
972 917
@@ -985,14 +930,13 @@ static int __devinit cx18_probe(struct pci_dev *dev,
985 goto free_streams; 930 goto free_streams;
986 } 931 }
987 932
988 CX18_INFO("Initialized card #%d: %s\n", cx->num, cx->card_name); 933 CX18_INFO("Initialized card: %s\n", cx->card_name);
989
990 return 0; 934 return 0;
991 935
992free_streams: 936free_streams:
993 cx18_streams_cleanup(cx, 1); 937 cx18_streams_cleanup(cx, 1);
994free_irq: 938free_irq:
995 free_irq(cx->dev->irq, (void *)cx); 939 free_irq(cx->pci_dev->irq, (void *)cx);
996free_i2c: 940free_i2c:
997 exit_cx18_i2c(cx); 941 exit_cx18_i2c(cx);
998free_map: 942free_map:
@@ -1006,11 +950,8 @@ err:
1006 retval = -ENODEV; 950 retval = -ENODEV;
1007 CX18_ERR("Error %d on initialization\n", retval); 951 CX18_ERR("Error %d on initialization\n", retval);
1008 952
1009 i = cx->num; 953 v4l2_device_unregister(&cx->v4l2_dev);
1010 spin_lock(&cx18_cards_lock); 954 kfree(cx);
1011 kfree(cx18_cards[i]);
1012 cx18_cards[i] = NULL;
1013 spin_unlock(&cx18_cards_lock);
1014 return retval; 955 return retval;
1015} 956}
1016 957
@@ -1043,8 +984,21 @@ int cx18_init_on_first_open(struct cx18 *cx)
1043 } 984 }
1044 set_bit(CX18_F_I_LOADED_FW, &cx->i_flags); 985 set_bit(CX18_F_I_LOADED_FW, &cx->i_flags);
1045 986
1046 /* Init the firmware twice to work around a silicon bug 987 /*
1047 * transport related. */ 988 * Init the firmware twice to work around a silicon bug
989 * with the digital TS.
990 *
991 * The second firmware load requires us to normalize the APU state,
992 * or the audio for the first analog capture will be badly incorrect.
993 *
994 * I can't seem to call APU_RESETAI and have it succeed without the
995 * APU capturing audio, so we start and stop it here to do the reset
996 */
997
998 /* MPEG Encoding, 224 kbps, MPEG Layer II, 48 ksps */
999 cx18_vapi(cx, CX18_APU_START, 2, CX18_APU_ENCODING_METHOD_MPEG|0xb9, 0);
1000 cx18_vapi(cx, CX18_APU_RESETAI, 0);
1001 cx18_vapi(cx, CX18_APU_STOP, 1, CX18_APU_ENCODING_METHOD_MPEG);
1048 1002
1049 fw_retry_count = 3; 1003 fw_retry_count = 3;
1050 while (--fw_retry_count > 0) { 1004 while (--fw_retry_count > 0) {
@@ -1060,6 +1014,22 @@ int cx18_init_on_first_open(struct cx18 *cx)
1060 return -ENXIO; 1014 return -ENXIO;
1061 } 1015 }
1062 1016
1017 /*
1018 * The second firmware load requires us to normalize the APU state,
1019 * or the audio for the first analog capture will be badly incorrect.
1020 *
1021 * I can't seem to call APU_RESETAI and have it succeed without the
1022 * APU capturing audio, so we start and stop it here to do the reset
1023 */
1024
1025 /* MPEG Encoding, 224 kbps, MPEG Layer II, 48 ksps */
1026 cx18_vapi(cx, CX18_APU_START, 2, CX18_APU_ENCODING_METHOD_MPEG|0xb9, 0);
1027 cx18_vapi(cx, CX18_APU_RESETAI, 0);
1028 cx18_vapi(cx, CX18_APU_STOP, 1, CX18_APU_ENCODING_METHOD_MPEG);
1029
1030 /* Init the A/V decoder, if it hasn't been already */
1031 v4l2_subdev_call(cx->sd_av, core, init, (u32) CX18_AV_INIT_NORMAL);
1032
1063 vf.tuner = 0; 1033 vf.tuner = 0;
1064 vf.type = V4L2_TUNER_ANALOG_TV; 1034 vf.type = V4L2_TUNER_ANALOG_TV;
1065 vf.frequency = 6400; /* the tuner 'baseline' frequency */ 1035 vf.frequency = 6400; /* the tuner 'baseline' frequency */
@@ -1092,9 +1062,11 @@ static void cx18_cancel_epu_work_orders(struct cx18 *cx)
1092 1062
1093static void cx18_remove(struct pci_dev *pci_dev) 1063static void cx18_remove(struct pci_dev *pci_dev)
1094{ 1064{
1095 struct cx18 *cx = pci_get_drvdata(pci_dev); 1065 struct v4l2_device *v4l2_dev = pci_get_drvdata(pci_dev);
1066 struct cx18 *cx = to_cx18(v4l2_dev);
1067 int i;
1096 1068
1097 CX18_DEBUG_INFO("Removing Card #%d\n", cx->num); 1069 CX18_DEBUG_INFO("Removing Card\n");
1098 1070
1099 /* Stop all captures */ 1071 /* Stop all captures */
1100 CX18_DEBUG_INFO("Stopping all streams\n"); 1072 CX18_DEBUG_INFO("Stopping all streams\n");
@@ -1115,15 +1087,22 @@ static void cx18_remove(struct pci_dev *pci_dev)
1115 1087
1116 exit_cx18_i2c(cx); 1088 exit_cx18_i2c(cx);
1117 1089
1118 free_irq(cx->dev->irq, (void *)cx); 1090 free_irq(cx->pci_dev->irq, (void *)cx);
1119 1091
1120 cx18_iounmap(cx); 1092 cx18_iounmap(cx);
1121 1093
1122 release_mem_region(cx->base_addr, CX18_MEM_SIZE); 1094 release_mem_region(cx->base_addr, CX18_MEM_SIZE);
1123 1095
1124 pci_disable_device(cx->dev); 1096 pci_disable_device(cx->pci_dev);
1097
1098 if (cx->vbi.sliced_mpeg_data[0] != NULL)
1099 for (i = 0; i < CX18_VBI_FRAMES; i++)
1100 kfree(cx->vbi.sliced_mpeg_data[i]);
1101
1102 CX18_INFO("Removed %s\n", cx->card_name);
1125 1103
1126 CX18_INFO("Removed %s, card #%d\n", cx->card_name, cx->num); 1104 v4l2_device_unregister(v4l2_dev);
1105 kfree(cx);
1127} 1106}
1128 1107
1129/* define a pci_driver for card detection */ 1108/* define a pci_driver for card detection */
@@ -1138,8 +1117,6 @@ static int module_start(void)
1138{ 1117{
1139 printk(KERN_INFO "cx18: Start initialization, version %s\n", CX18_VERSION); 1118 printk(KERN_INFO "cx18: Start initialization, version %s\n", CX18_VERSION);
1140 1119
1141 memset(cx18_cards, 0, sizeof(cx18_cards));
1142
1143 /* Validate parameters */ 1120 /* Validate parameters */
1144 if (cx18_first_minor < 0 || cx18_first_minor >= CX18_MAX_CARDS) { 1121 if (cx18_first_minor < 0 || cx18_first_minor >= CX18_MAX_CARDS) {
1145 printk(KERN_ERR "cx18: Exiting, cx18_first_minor must be between 0 and %d\n", 1122 printk(KERN_ERR "cx18: Exiting, cx18_first_minor must be between 0 and %d\n",
@@ -1162,16 +1139,7 @@ static int module_start(void)
1162 1139
1163static void module_cleanup(void) 1140static void module_cleanup(void)
1164{ 1141{
1165 int i;
1166
1167 pci_unregister_driver(&cx18_pci_driver); 1142 pci_unregister_driver(&cx18_pci_driver);
1168
1169 for (i = 0; i < cx18_cards_active; i++) {
1170 if (cx18_cards[i] == NULL)
1171 continue;
1172 kfree(cx18_cards[i]);
1173 }
1174
1175} 1143}
1176 1144
1177module_init(module_start); 1145module_init(module_start);
diff --git a/drivers/media/video/cx18/cx18-driver.h b/drivers/media/video/cx18/cx18-driver.h
index 0d2edebc39b4..ece4f281ef42 100644
--- a/drivers/media/video/cx18/cx18-driver.h
+++ b/drivers/media/video/cx18/cx18-driver.h
@@ -48,6 +48,7 @@
48#include <linux/dvb/audio.h> 48#include <linux/dvb/audio.h>
49#include <media/v4l2-common.h> 49#include <media/v4l2-common.h>
50#include <media/v4l2-ioctl.h> 50#include <media/v4l2-ioctl.h>
51#include <media/v4l2-device.h>
51#include <media/tuner.h> 52#include <media/tuner.h>
52#include "cx18-mailbox.h" 53#include "cx18-mailbox.h"
53#include "cx18-av-core.h" 54#include "cx18-av-core.h"
@@ -79,7 +80,7 @@
79#define CX18_CARD_YUAN_MPC718 3 /* Yuan MPC718 */ 80#define CX18_CARD_YUAN_MPC718 3 /* Yuan MPC718 */
80#define CX18_CARD_CNXT_RAPTOR_PAL 4 /* Conexant Raptor PAL */ 81#define CX18_CARD_CNXT_RAPTOR_PAL 4 /* Conexant Raptor PAL */
81#define CX18_CARD_TOSHIBA_QOSMIO_DVBT 5 /* Toshiba Qosmio Interal DVB-T/Analog*/ 82#define CX18_CARD_TOSHIBA_QOSMIO_DVBT 5 /* Toshiba Qosmio Interal DVB-T/Analog*/
82#define CX18_CARD_LEADTEK_PVR2100 6 /* Leadtek WinFast PVR2100 */ 83#define CX18_CARD_LEADTEK_PVR2100 6 /* Leadtek WinFast PVR2100/DVR3100 H */
83#define CX18_CARD_LAST 6 84#define CX18_CARD_LAST 6
84 85
85#define CX18_ENC_STREAM_TYPE_MPG 0 86#define CX18_ENC_STREAM_TYPE_MPG 0
@@ -143,12 +144,12 @@
143/* Flag to turn on high volume debugging */ 144/* Flag to turn on high volume debugging */
144#define CX18_DBGFLG_HIGHVOL (1 << 8) 145#define CX18_DBGFLG_HIGHVOL (1 << 8)
145 146
146/* NOTE: extra space before comma in 'cx->num , ## args' is required for 147/* NOTE: extra space before comma in 'fmt , ## args' is required for
147 gcc-2.95, otherwise it won't compile. */ 148 gcc-2.95, otherwise it won't compile. */
148#define CX18_DEBUG(x, type, fmt, args...) \ 149#define CX18_DEBUG(x, type, fmt, args...) \
149 do { \ 150 do { \
150 if ((x) & cx18_debug) \ 151 if ((x) & cx18_debug) \
151 printk(KERN_INFO "cx18-%d " type ": " fmt, cx->num , ## args); \ 152 v4l2_info(&cx->v4l2_dev, " " type ": " fmt , ## args); \
152 } while (0) 153 } while (0)
153#define CX18_DEBUG_WARN(fmt, args...) CX18_DEBUG(CX18_DBGFLG_WARN, "warning", fmt , ## args) 154#define CX18_DEBUG_WARN(fmt, args...) CX18_DEBUG(CX18_DBGFLG_WARN, "warning", fmt , ## args)
154#define CX18_DEBUG_INFO(fmt, args...) CX18_DEBUG(CX18_DBGFLG_INFO, "info", fmt , ## args) 155#define CX18_DEBUG_INFO(fmt, args...) CX18_DEBUG(CX18_DBGFLG_INFO, "info", fmt , ## args)
@@ -162,7 +163,7 @@
162#define CX18_DEBUG_HIGH_VOL(x, type, fmt, args...) \ 163#define CX18_DEBUG_HIGH_VOL(x, type, fmt, args...) \
163 do { \ 164 do { \
164 if (((x) & cx18_debug) && (cx18_debug & CX18_DBGFLG_HIGHVOL)) \ 165 if (((x) & cx18_debug) && (cx18_debug & CX18_DBGFLG_HIGHVOL)) \
165 printk(KERN_INFO "cx18%d " type ": " fmt, cx->num , ## args); \ 166 v4l2_info(&cx->v4l2_dev, " " type ": " fmt , ## args); \
166 } while (0) 167 } while (0)
167#define CX18_DEBUG_HI_WARN(fmt, args...) CX18_DEBUG_HIGH_VOL(CX18_DBGFLG_WARN, "warning", fmt , ## args) 168#define CX18_DEBUG_HI_WARN(fmt, args...) CX18_DEBUG_HIGH_VOL(CX18_DBGFLG_WARN, "warning", fmt , ## args)
168#define CX18_DEBUG_HI_INFO(fmt, args...) CX18_DEBUG_HIGH_VOL(CX18_DBGFLG_INFO, "info", fmt , ## args) 169#define CX18_DEBUG_HI_INFO(fmt, args...) CX18_DEBUG_HIGH_VOL(CX18_DBGFLG_INFO, "info", fmt , ## args)
@@ -174,9 +175,58 @@
174#define CX18_DEBUG_HI_IRQ(fmt, args...) CX18_DEBUG_HIGH_VOL(CX18_DBGFLG_IRQ, "irq", fmt , ## args) 175#define CX18_DEBUG_HI_IRQ(fmt, args...) CX18_DEBUG_HIGH_VOL(CX18_DBGFLG_IRQ, "irq", fmt , ## args)
175 176
176/* Standard kernel messages */ 177/* Standard kernel messages */
177#define CX18_ERR(fmt, args...) printk(KERN_ERR "cx18-%d: " fmt, cx->num , ## args) 178#define CX18_ERR(fmt, args...) v4l2_err(&cx->v4l2_dev, fmt , ## args)
178#define CX18_WARN(fmt, args...) printk(KERN_WARNING "cx18-%d: " fmt, cx->num , ## args) 179#define CX18_WARN(fmt, args...) v4l2_warn(&cx->v4l2_dev, fmt , ## args)
179#define CX18_INFO(fmt, args...) printk(KERN_INFO "cx18-%d: " fmt, cx->num , ## args) 180#define CX18_INFO(fmt, args...) v4l2_info(&cx->v4l2_dev, fmt , ## args)
181
182/* Messages for internal subdevs to use */
183#define CX18_DEBUG_DEV(x, dev, type, fmt, args...) \
184 do { \
185 if ((x) & cx18_debug) \
186 v4l2_info(dev, " " type ": " fmt , ## args); \
187 } while (0)
188#define CX18_DEBUG_WARN_DEV(dev, fmt, args...) \
189 CX18_DEBUG_DEV(CX18_DBGFLG_WARN, dev, "warning", fmt , ## args)
190#define CX18_DEBUG_INFO_DEV(dev, fmt, args...) \
191 CX18_DEBUG_DEV(CX18_DBGFLG_INFO, dev, "info", fmt , ## args)
192#define CX18_DEBUG_API_DEV(dev, fmt, args...) \
193 CX18_DEBUG_DEV(CX18_DBGFLG_API, dev, "api", fmt , ## args)
194#define CX18_DEBUG_DMA_DEV(dev, fmt, args...) \
195 CX18_DEBUG_DEV(CX18_DBGFLG_DMA, dev, "dma", fmt , ## args)
196#define CX18_DEBUG_IOCTL_DEV(dev, fmt, args...) \
197 CX18_DEBUG_DEV(CX18_DBGFLG_IOCTL, dev, "ioctl", fmt , ## args)
198#define CX18_DEBUG_FILE_DEV(dev, fmt, args...) \
199 CX18_DEBUG_DEV(CX18_DBGFLG_FILE, dev, "file", fmt , ## args)
200#define CX18_DEBUG_I2C_DEV(dev, fmt, args...) \
201 CX18_DEBUG_DEV(CX18_DBGFLG_I2C, dev, "i2c", fmt , ## args)
202#define CX18_DEBUG_IRQ_DEV(dev, fmt, args...) \
203 CX18_DEBUG_DEV(CX18_DBGFLG_IRQ, dev, "irq", fmt , ## args)
204
205#define CX18_DEBUG_HIGH_VOL_DEV(x, dev, type, fmt, args...) \
206 do { \
207 if (((x) & cx18_debug) && (cx18_debug & CX18_DBGFLG_HIGHVOL)) \
208 v4l2_info(dev, " " type ": " fmt , ## args); \
209 } while (0)
210#define CX18_DEBUG_HI_WARN_DEV(dev, fmt, args...) \
211 CX18_DEBUG_HIGH_VOL_DEV(CX18_DBGFLG_WARN, dev, "warning", fmt , ## args)
212#define CX18_DEBUG_HI_INFO_DEV(dev, fmt, args...) \
213 CX18_DEBUG_HIGH_VOL_DEV(CX18_DBGFLG_INFO, dev, "info", fmt , ## args)
214#define CX18_DEBUG_HI_API_DEV(dev, fmt, args...) \
215 CX18_DEBUG_HIGH_VOL_DEV(CX18_DBGFLG_API, dev, "api", fmt , ## args)
216#define CX18_DEBUG_HI_DMA_DEV(dev, fmt, args...) \
217 CX18_DEBUG_HIGH_VOL_DEV(CX18_DBGFLG_DMA, dev, "dma", fmt , ## args)
218#define CX18_DEBUG_HI_IOCTL_DEV(dev, fmt, args...) \
219 CX18_DEBUG_HIGH_VOL_DEV(CX18_DBGFLG_IOCTL, dev, "ioctl", fmt , ## args)
220#define CX18_DEBUG_HI_FILE_DEV(dev, fmt, args...) \
221 CX18_DEBUG_HIGH_VOL_DEV(CX18_DBGFLG_FILE, dev, "file", fmt , ## args)
222#define CX18_DEBUG_HI_I2C_DEV(dev, fmt, args...) \
223 CX18_DEBUG_HIGH_VOL_DEV(CX18_DBGFLG_I2C, dev, "i2c", fmt , ## args)
224#define CX18_DEBUG_HI_IRQ_DEV(dev, fmt, args...) \
225 CX18_DEBUG_HIGH_VOL_DEV(CX18_DBGFLG_IRQ, dev, "irq", fmt , ## args)
226
227#define CX18_ERR_DEV(dev, fmt, args...) v4l2_err(dev, fmt , ## args)
228#define CX18_WARN_DEV(dev, fmt, args...) v4l2_warn(dev, fmt , ## args)
229#define CX18_INFO_DEV(dev, fmt, args...) v4l2_info(dev, fmt , ## args)
180 230
181/* Values for CX18_API_DEC_PLAYBACK_SPEED mpeg_frame_type_mask parameter: */ 231/* Values for CX18_API_DEC_PLAYBACK_SPEED mpeg_frame_type_mask parameter: */
182#define MPEG_FRAME_TYPE_IFRAME 1 232#define MPEG_FRAME_TYPE_IFRAME 1
@@ -279,7 +329,7 @@ struct cx18_epu_work_order {
279struct cx18_stream { 329struct cx18_stream {
280 /* These first four fields are always set, even if the stream 330 /* These first four fields are always set, even if the stream
281 is not actually created. */ 331 is not actually created. */
282 struct video_device *v4l2dev; /* NULL when stream not created */ 332 struct video_device *video_dev; /* NULL when stream not created */
283 struct cx18 *cx; /* for ease of use */ 333 struct cx18 *cx; /* for ease of use */
284 const char *name; /* name of the stream */ 334 const char *name; /* name of the stream */
285 int type; /* stream type */ 335 int type; /* stream type */
@@ -292,7 +342,6 @@ struct cx18_stream {
292 int dma; /* can be PCI_DMA_TODEVICE, 342 int dma; /* can be PCI_DMA_TODEVICE,
293 PCI_DMA_FROMDEVICE or 343 PCI_DMA_FROMDEVICE or
294 PCI_DMA_NONE */ 344 PCI_DMA_NONE */
295 u64 dma_pts;
296 wait_queue_head_t waitq; 345 wait_queue_head_t waitq;
297 346
298 /* Buffer Stats */ 347 /* Buffer Stats */
@@ -318,59 +367,121 @@ struct cx18_open_id {
318/* forward declaration of struct defined in cx18-cards.h */ 367/* forward declaration of struct defined in cx18-cards.h */
319struct cx18_card; 368struct cx18_card;
320 369
370/*
371 * A note about "sliced" VBI data as implemented in this driver:
372 *
373 * Currently we collect the sliced VBI in the form of Ancillary Data
374 * packets, inserted by the AV core decoder/digitizer/slicer in the
375 * horizontal blanking region of the VBI lines, in "raw" mode as far as
376 * the Encoder is concerned. We don't ever tell the Encoder itself
377 * to provide sliced VBI. (AV Core: sliced mode - Encoder: raw mode)
378 *
379 * We then process the ancillary data ourselves to send the sliced data
380 * to the user application directly or build up MPEG-2 private stream 1
381 * packets to splice into (only!) MPEG-2 PS streams for the user app.
382 *
383 * (That's how ivtv essentially does it.)
384 *
385 * The Encoder should be able to extract certain sliced VBI data for
386 * us and provide it in a separate stream or splice it into any type of
387 * MPEG PS or TS stream, but this isn't implemented yet.
388 */
389
390/*
391 * Number of "raw" VBI samples per horizontal line we tell the Encoder to
392 * grab from the decoder/digitizer/slicer output for raw or sliced VBI.
393 * It depends on the pixel clock and the horiz rate:
394 *
395 * (1/Fh)*(2*Fp) = Samples/line
396 * = 4 bytes EAV + Anc data in hblank + 4 bytes SAV + active samples
397 *
398 * Sliced VBI data is sent as ancillary data during horizontal blanking
399 * Raw VBI is sent as active video samples during vertcal blanking
400 *
401 * We use a BT.656 pxiel clock of 13.5 MHz and a BT.656 active line
402 * length of 720 pixels @ 4:2:2 sampling. Thus...
403 *
404 * For systems that use a 15.734 kHz horizontal rate, such as
405 * NTSC-M, PAL-M, PAL-60, and other 60 Hz/525 line systems, we have:
406 *
407 * (1/15.734 kHz) * 2 * 13.5 MHz = 1716 samples/line =
408 * 4 bytes SAV + 268 bytes anc data + 4 bytes SAV + 1440 active samples
409 *
410 * For systems that use a 15.625 kHz horizontal rate, such as
411 * PAL-B/G/H, PAL-I, SECAM-L and other 50 Hz/625 line systems, we have:
412 *
413 * (1/15.625 kHz) * 2 * 13.5 MHz = 1728 samples/line =
414 * 4 bytes SAV + 280 bytes anc data + 4 bytes SAV + 1440 active samples
415 */
416static const u32 vbi_active_samples = 1444; /* 4 byte SAV + 720 Y + 720 U/V */
417static const u32 vbi_hblank_samples_60Hz = 272; /* 4 byte EAV + 268 anc/fill */
418static const u32 vbi_hblank_samples_50Hz = 284; /* 4 byte EAV + 280 anc/fill */
321 419
322#define CX18_VBI_FRAMES 32 420#define CX18_VBI_FRAMES 32
323 421
324/* VBI data */
325struct vbi_info { 422struct vbi_info {
326 u32 enc_size; 423 /* Current state of v4l2 VBI settings for this device */
327 u32 frame;
328 u8 cc_data_odd[256];
329 u8 cc_data_even[256];
330 int cc_pos;
331 u8 cc_no_update;
332 u8 vps[5];
333 u8 vps_found;
334 int wss;
335 u8 wss_found;
336 u8 wss_no_update;
337 u32 raw_decoder_line_size;
338 u8 raw_decoder_sav_odd_field;
339 u8 raw_decoder_sav_even_field;
340 u32 sliced_decoder_line_size;
341 u8 sliced_decoder_sav_odd_field;
342 u8 sliced_decoder_sav_even_field;
343 struct v4l2_format in; 424 struct v4l2_format in;
344 /* convenience pointer to sliced struct in vbi_in union */ 425 struct v4l2_sliced_vbi_format *sliced_in; /* pointer to in.fmt.sliced */
345 struct v4l2_sliced_vbi_format *sliced_in; 426 u32 count; /* Count of VBI data lines: 60 Hz: 12 or 50 Hz: 18 */
346 u32 service_set_in; 427 u32 start[2]; /* First VBI data line per field: 10 & 273 or 6 & 318 */
347 int insert_mpeg;
348 428
349 /* Buffer for the maximum of 2 * 18 * packet_size sliced VBI lines. 429 u32 frame; /* Count of VBI buffers/frames received from Encoder */
350 One for /dev/vbi0 and one for /dev/vbi8 */
351 struct v4l2_sliced_vbi_data sliced_data[36];
352 430
353 /* Buffer for VBI data inserted into MPEG stream. 431 /*
354 The first byte is a dummy byte that's never used. 432 * Vars for creation and insertion of MPEG Private Stream 1 packets
355 The next 16 bytes contain the MPEG header for the VBI data, 433 * of sliced VBI data into an MPEG PS
356 the remainder is the actual VBI data. 434 */
357 The max size accepted by the MPEG VBI reinsertion turns out
358 to be 1552 bytes, which happens to be 4 + (1 + 42) * (2 * 18) bytes,
359 where 4 is a four byte header, 42 is the max sliced VBI payload, 1 is
360 a single line header byte and 2 * 18 is the number of VBI lines per frame.
361 435
362 However, it seems that the data must be 1K aligned, so we have to 436 /* Boolean: create and insert Private Stream 1 packets into the PS */
363 pad the data until the 1 or 2 K boundary. 437 int insert_mpeg;
438
439 /*
440 * Buffer for the maximum of 2 * 18 * packet_size sliced VBI lines.
441 * Used in cx18-vbi.c only for collecting sliced data, and as a source
442 * during conversion of sliced VBI data into MPEG Priv Stream 1 packets.
443 * We don't need to save state here, but the array may have been a bit
444 * too big (2304 bytes) to alloc from the stack.
445 */
446 struct v4l2_sliced_vbi_data sliced_data[36];
364 447
365 This pointer array will allocate 2049 bytes to store each VBI frame. */ 448 /*
449 * A ring buffer of driver-generated MPEG-2 PS
450 * Program Pack/Private Stream 1 packets for sliced VBI data insertion
451 * into the MPEG PS stream.
452 *
453 * In each sliced_mpeg_data[] buffer is:
454 * 16 byte MPEG-2 PS Program Pack Header
455 * 16 byte MPEG-2 Private Stream 1 PES Header
456 * 4 byte magic number: "itv0" or "ITV0"
457 * 4 byte first field line mask, if "itv0"
458 * 4 byte second field line mask, if "itv0"
459 * 36 lines, if "ITV0"; or <36 lines, if "itv0"; of sliced VBI data
460 *
461 * Each line in the payload is
462 * 1 byte line header derived from the SDID (WSS, CC, VPS, etc.)
463 * 42 bytes of line data
464 *
465 * That's a maximum 1552 bytes of payload in the Private Stream 1 packet
466 * which is the payload size a PVR-350 (CX23415) MPEG decoder will
467 * accept for VBI data. So, including the headers, it's a maximum 1584
468 * bytes total.
469 */
470#define CX18_SLICED_MPEG_DATA_MAXSZ 1584
471 /* copy_vbi_buf() needs 8 temp bytes on the end for the worst case */
472#define CX18_SLICED_MPEG_DATA_BUFSZ (CX18_SLICED_MPEG_DATA_MAXSZ+8)
366 u8 *sliced_mpeg_data[CX18_VBI_FRAMES]; 473 u8 *sliced_mpeg_data[CX18_VBI_FRAMES];
367 u32 sliced_mpeg_size[CX18_VBI_FRAMES]; 474 u32 sliced_mpeg_size[CX18_VBI_FRAMES];
368 struct cx18_buffer sliced_mpeg_buf; 475
476 /* Count of Program Pack/Program Stream 1 packets inserted into PS */
369 u32 inserted_frame; 477 u32 inserted_frame;
370 478
371 u32 start[2], count; 479 /*
372 u32 raw_size; 480 * A dummy driver stream transfer buffer with a copy of the next
373 u32 sliced_size; 481 * sliced_mpeg_data[] buffer for output to userland apps.
482 * Only used in cx18-fileops.c, but its state needs to persist at times.
483 */
484 struct cx18_buffer sliced_mpeg_buf;
374}; 485};
375 486
376/* Per cx23418, per I2C bus private algo callback data */ 487/* Per cx23418, per I2C bus private algo callback data */
@@ -383,16 +494,17 @@ struct cx18_i2c_algo_callback_data {
383 494
384/* Struct to hold info about cx18 cards */ 495/* Struct to hold info about cx18 cards */
385struct cx18 { 496struct cx18 {
386 int num; /* board number, -1 during init! */ 497 int instance;
387 char name[8]; /* board name for printk and interrupts (e.g. 'cx180') */ 498 struct pci_dev *pci_dev;
388 struct pci_dev *dev; /* PCI device */ 499 struct v4l2_device v4l2_dev;
500 struct v4l2_subdev *sd_av; /* A/V decoder/digitizer sub-device */
501 struct v4l2_subdev *sd_extmux; /* External multiplexer sub-dev */
502
389 const struct cx18_card *card; /* card information */ 503 const struct cx18_card *card; /* card information */
390 const char *card_name; /* full name of the card */ 504 const char *card_name; /* full name of the card */
391 const struct cx18_card_tuner_i2c *card_i2c; /* i2c addresses to probe for tuner */ 505 const struct cx18_card_tuner_i2c *card_i2c; /* i2c addresses to probe for tuner */
392 u8 is_50hz; 506 u8 is_50hz;
393 u8 is_60hz; 507 u8 is_60hz;
394 u8 is_out_50hz;
395 u8 is_out_60hz;
396 u8 nof_inputs; /* number of video inputs */ 508 u8 nof_inputs; /* number of video inputs */
397 u8 nof_audio_inputs; /* number of audio inputs */ 509 u8 nof_audio_inputs; /* number of audio inputs */
398 u16 buffer_id; /* buffer ID counter */ 510 u16 buffer_id; /* buffer ID counter */
@@ -413,10 +525,7 @@ struct cx18 {
413 525
414 /* dualwatch */ 526 /* dualwatch */
415 unsigned long dualwatch_jiffies; 527 unsigned long dualwatch_jiffies;
416 u16 dualwatch_stereo_mode; 528 u32 dualwatch_stereo_mode;
417
418 /* Digitizer type */
419 int digitizer; /* 0x00EF = saa7114 0x00FO = saa7115 0x0106 = mic */
420 529
421 struct mutex serialize_lock; /* mutex used to serialize open/close/start/stop/ioctl operations */ 530 struct mutex serialize_lock; /* mutex used to serialize open/close/start/stop/ioctl operations */
422 struct cx18_options options; /* User options */ 531 struct cx18_options options; /* User options */
@@ -426,7 +535,6 @@ struct cx18 {
426 unsigned long i_flags; /* global cx18 flags */ 535 unsigned long i_flags; /* global cx18 flags */
427 atomic_t ana_capturing; /* count number of active analog capture streams */ 536 atomic_t ana_capturing; /* count number of active analog capture streams */
428 atomic_t tot_capturing; /* total count number of active capture streams */ 537 atomic_t tot_capturing; /* total count number of active capture streams */
429 spinlock_t lock; /* lock access to this struct */
430 int search_pack_header; 538 int search_pack_header;
431 539
432 int open_id; /* incremented each time an open occurs, used as 540 int open_id; /* incremented each time an open occurs, used as
@@ -468,30 +576,30 @@ struct cx18 {
468 struct i2c_adapter i2c_adap[2]; 576 struct i2c_adapter i2c_adap[2];
469 struct i2c_algo_bit_data i2c_algo[2]; 577 struct i2c_algo_bit_data i2c_algo[2];
470 struct cx18_i2c_algo_callback_data i2c_algo_cb_data[2]; 578 struct cx18_i2c_algo_callback_data i2c_algo_cb_data[2];
471 struct i2c_client i2c_client[2];
472 struct mutex i2c_bus_lock[2];
473 struct i2c_client *i2c_clients[I2C_CLIENTS_MAX];
474 579
475 /* gpio */ 580 /* gpio */
476 u32 gpio_dir; 581 u32 gpio_dir;
477 u32 gpio_val; 582 u32 gpio_val;
478 struct mutex gpio_lock; 583 struct mutex gpio_lock;
584 struct v4l2_subdev sd_gpiomux;
585 struct v4l2_subdev sd_resetctrl;
479 586
480 /* v4l2 and User settings */ 587 /* v4l2 and User settings */
481 588
482 /* codec settings */ 589 /* codec settings */
483 u32 audio_input; 590 u32 audio_input;
484 u32 active_input; 591 u32 active_input;
485 u32 active_output;
486 v4l2_std_id std; 592 v4l2_std_id std;
487 v4l2_std_id tuner_std; /* The norm of the tuner (fixed) */ 593 v4l2_std_id tuner_std; /* The norm of the tuner (fixed) */
488}; 594};
489 595
596static inline struct cx18 *to_cx18(struct v4l2_device *v4l2_dev)
597{
598 return container_of(v4l2_dev, struct cx18, v4l2_dev);
599}
600
490/* Globals */ 601/* Globals */
491extern struct cx18 *cx18_cards[];
492extern int cx18_cards_active;
493extern int cx18_first_minor; 602extern int cx18_first_minor;
494extern spinlock_t cx18_cards_lock;
495 603
496/*==============Prototypes==================*/ 604/*==============Prototypes==================*/
497 605
@@ -511,4 +619,22 @@ static inline int cx18_raw_vbi(const struct cx18 *cx)
511 return cx->vbi.in.type == V4L2_BUF_TYPE_VBI_CAPTURE; 619 return cx->vbi.in.type == V4L2_BUF_TYPE_VBI_CAPTURE;
512} 620}
513 621
622/* Call the specified callback for all subdevs with a grp_id bit matching the
623 * mask in hw (if 0, then match them all). Ignore any errors. */
624#define cx18_call_hw(cx, hw, o, f, args...) \
625 __v4l2_device_call_subdevs(&(cx)->v4l2_dev, \
626 !(hw) || (sd->grp_id & (hw)), o, f , ##args)
627
628#define cx18_call_all(cx, o, f, args...) cx18_call_hw(cx, 0, o, f , ##args)
629
630/* Call the specified callback for all subdevs with a grp_id bit matching the
631 * mask in hw (if 0, then match them all). If the callback returns an error
632 * other than 0 or -ENOIOCTLCMD, then return with that error code. */
633#define cx18_call_hw_err(cx, hw, o, f, args...) \
634 __v4l2_device_call_subdevs_until_err( \
635 &(cx)->v4l2_dev, !(hw) || (sd->grp_id & (hw)), o, f , ##args)
636
637#define cx18_call_all_err(cx, o, f, args...) \
638 cx18_call_hw_err(cx, 0, o, f , ##args)
639
514#endif /* CX18_DRIVER_H */ 640#endif /* CX18_DRIVER_H */
diff --git a/drivers/media/video/cx18/cx18-dvb.c b/drivers/media/video/cx18/cx18-dvb.c
index bd5e6f3fd4d0..3b86f57cd15a 100644
--- a/drivers/media/video/cx18/cx18-dvb.c
+++ b/drivers/media/video/cx18/cx18-dvb.c
@@ -167,7 +167,7 @@ int cx18_dvb_register(struct cx18_stream *stream)
167 167
168 ret = dvb_register_adapter(&dvb->dvb_adapter, 168 ret = dvb_register_adapter(&dvb->dvb_adapter,
169 CX18_DRIVER_NAME, 169 CX18_DRIVER_NAME,
170 THIS_MODULE, &cx->dev->dev, adapter_nr); 170 THIS_MODULE, &cx->pci_dev->dev, adapter_nr);
171 if (ret < 0) 171 if (ret < 0)
172 goto err_out; 172 goto err_out;
173 173
diff --git a/drivers/media/video/cx18/cx18-fileops.c b/drivers/media/video/cx18/cx18-fileops.c
index 055f6e004b2d..4d7d6d5a7f86 100644
--- a/drivers/media/video/cx18/cx18-fileops.c
+++ b/drivers/media/video/cx18/cx18-fileops.c
@@ -128,15 +128,15 @@ static void cx18_release_stream(struct cx18_stream *s)
128static void cx18_dualwatch(struct cx18 *cx) 128static void cx18_dualwatch(struct cx18 *cx)
129{ 129{
130 struct v4l2_tuner vt; 130 struct v4l2_tuner vt;
131 u16 new_bitmap; 131 u32 new_bitmap;
132 u16 new_stereo_mode; 132 u32 new_stereo_mode;
133 const u16 stereo_mask = 0x0300; 133 const u32 stereo_mask = 0x0300;
134 const u16 dual = 0x0200; 134 const u32 dual = 0x0200;
135 u32 h; 135 u32 h;
136 136
137 new_stereo_mode = cx->params.audio_properties & stereo_mask; 137 new_stereo_mode = cx->params.audio_properties & stereo_mask;
138 memset(&vt, 0, sizeof(vt)); 138 memset(&vt, 0, sizeof(vt));
139 cx18_call_i2c_clients(cx, VIDIOC_G_TUNER, &vt); 139 cx18_call_all(cx, tuner, g_tuner, &vt);
140 if (vt.audmode == V4L2_TUNER_MODE_LANG1_LANG2 && 140 if (vt.audmode == V4L2_TUNER_MODE_LANG1_LANG2 &&
141 (vt.rxsubchans & V4L2_TUNER_SUB_LANG2)) 141 (vt.rxsubchans & V4L2_TUNER_SUB_LANG2))
142 new_stereo_mode = dual; 142 new_stereo_mode = dual;
@@ -176,6 +176,8 @@ static struct cx18_buffer *cx18_get_buffer(struct cx18_stream *s, int non_block,
176 *err = 0; 176 *err = 0;
177 while (1) { 177 while (1) {
178 if (s->type == CX18_ENC_STREAM_TYPE_MPG) { 178 if (s->type == CX18_ENC_STREAM_TYPE_MPG) {
179 /* Process pending program info updates and pending
180 VBI data */
179 181
180 if (time_after(jiffies, cx->dualwatch_jiffies + msecs_to_jiffies(1000))) { 182 if (time_after(jiffies, cx->dualwatch_jiffies + msecs_to_jiffies(1000))) {
181 cx->dualwatch_jiffies = jiffies; 183 cx->dualwatch_jiffies = jiffies;
@@ -186,7 +188,6 @@ static struct cx18_buffer *cx18_get_buffer(struct cx18_stream *s, int non_block,
186 while ((buf = cx18_dequeue(s_vbi, &s_vbi->q_full))) { 188 while ((buf = cx18_dequeue(s_vbi, &s_vbi->q_full))) {
187 /* byteswap and process VBI data */ 189 /* byteswap and process VBI data */
188 cx18_process_vbi_data(cx, buf, 190 cx18_process_vbi_data(cx, buf,
189 s_vbi->dma_pts,
190 s_vbi->type); 191 s_vbi->type);
191 cx18_stream_put_buf_fw(s_vbi, buf); 192 cx18_stream_put_buf_fw(s_vbi, buf);
192 } 193 }
@@ -207,8 +208,7 @@ static struct cx18_buffer *cx18_get_buffer(struct cx18_stream *s, int non_block,
207 cx18_buf_swap(buf); 208 cx18_buf_swap(buf);
208 else { 209 else {
209 /* byteswap and process VBI data */ 210 /* byteswap and process VBI data */
210 cx18_process_vbi_data(cx, buf, 211 cx18_process_vbi_data(cx, buf, s->type);
211 s->dma_pts, s->type);
212 } 212 }
213 return buf; 213 return buf;
214 } 214 }
@@ -260,6 +260,20 @@ static size_t cx18_copy_buf_to_user(struct cx18_stream *s,
260 len = ucount; 260 len = ucount;
261 if (cx->vbi.insert_mpeg && s->type == CX18_ENC_STREAM_TYPE_MPG && 261 if (cx->vbi.insert_mpeg && s->type == CX18_ENC_STREAM_TYPE_MPG &&
262 !cx18_raw_vbi(cx) && buf != &cx->vbi.sliced_mpeg_buf) { 262 !cx18_raw_vbi(cx) && buf != &cx->vbi.sliced_mpeg_buf) {
263 /*
264 * Try to find a good splice point in the PS, just before
265 * an MPEG-2 Program Pack start code, and provide only
266 * up to that point to the user, so it's easy to insert VBI data
267 * the next time around.
268 */
269 /* FIXME - This only works for an MPEG-2 PS, not a TS */
270 /*
271 * An MPEG-2 Program Stream (PS) is a series of
272 * MPEG-2 Program Packs terminated by an
273 * MPEG Program End Code after the last Program Pack.
274 * A Program Pack may hold a PS System Header packet and any
275 * number of Program Elementary Stream (PES) Packets
276 */
263 const char *start = buf->buf + buf->readpos; 277 const char *start = buf->buf + buf->readpos;
264 const char *p = start + 1; 278 const char *p = start + 1;
265 const u8 *q; 279 const u8 *q;
@@ -267,38 +281,54 @@ static size_t cx18_copy_buf_to_user(struct cx18_stream *s,
267 int stuffing, i; 281 int stuffing, i;
268 282
269 while (start + len > p) { 283 while (start + len > p) {
284 /* Scan for a 0 to find a potential MPEG-2 start code */
270 q = memchr(p, 0, start + len - p); 285 q = memchr(p, 0, start + len - p);
271 if (q == NULL) 286 if (q == NULL)
272 break; 287 break;
273 p = q + 1; 288 p = q + 1;
289 /*
290 * Keep looking if not a
291 * MPEG-2 Pack header start code: 0x00 0x00 0x01 0xba
292 * or MPEG-2 video PES start code: 0x00 0x00 0x01 0xe0
293 */
274 if ((char *)q + 15 >= buf->buf + buf->bytesused || 294 if ((char *)q + 15 >= buf->buf + buf->bytesused ||
275 q[1] != 0 || q[2] != 1 || q[3] != ch) 295 q[1] != 0 || q[2] != 1 || q[3] != ch)
276 continue; 296 continue;
297
298 /* If expecting the primary video PES */
277 if (!cx->search_pack_header) { 299 if (!cx->search_pack_header) {
300 /* Continue if it couldn't be a PES packet */
278 if ((q[6] & 0xc0) != 0x80) 301 if ((q[6] & 0xc0) != 0x80)
279 continue; 302 continue;
280 if (((q[7] & 0xc0) == 0x80 && 303 /* Check if a PTS or PTS & DTS follow */
281 (q[9] & 0xf0) == 0x20) || 304 if (((q[7] & 0xc0) == 0x80 && /* PTS only */
282 ((q[7] & 0xc0) == 0xc0 && 305 (q[9] & 0xf0) == 0x20) || /* PTS only */
283 (q[9] & 0xf0) == 0x30)) { 306 ((q[7] & 0xc0) == 0xc0 && /* PTS & DTS */
284 ch = 0xba; 307 (q[9] & 0xf0) == 0x30)) { /* DTS follows */
308 /* Assume we found the video PES hdr */
309 ch = 0xba; /* next want a Program Pack*/
285 cx->search_pack_header = 1; 310 cx->search_pack_header = 1;
286 p = q + 9; 311 p = q + 9; /* Skip this video PES hdr */
287 } 312 }
288 continue; 313 continue;
289 } 314 }
315
316 /* We may have found a Program Pack start code */
317
318 /* Get the count of stuffing bytes & verify them */
290 stuffing = q[13] & 7; 319 stuffing = q[13] & 7;
291 /* all stuffing bytes must be 0xff */ 320 /* all stuffing bytes must be 0xff */
292 for (i = 0; i < stuffing; i++) 321 for (i = 0; i < stuffing; i++)
293 if (q[14 + i] != 0xff) 322 if (q[14 + i] != 0xff)
294 break; 323 break;
295 if (i == stuffing && 324 if (i == stuffing && /* right number of stuffing bytes*/
296 (q[4] & 0xc4) == 0x44 && 325 (q[4] & 0xc4) == 0x44 && /* marker check */
297 (q[12] & 3) == 3 && 326 (q[12] & 3) == 3 && /* marker check */
298 q[14 + stuffing] == 0 && 327 q[14 + stuffing] == 0 && /* PES Pack or Sys Hdr */
299 q[15 + stuffing] == 0 && 328 q[15 + stuffing] == 0 &&
300 q[16 + stuffing] == 1) { 329 q[16 + stuffing] == 1) {
301 cx->search_pack_header = 0; 330 /* We declare we actually found a Program Pack*/
331 cx->search_pack_header = 0; /* expect vid PES */
302 len = (char *)q - start; 332 len = (char *)q - start;
303 cx18_setup_sliced_vbi_buf(cx); 333 cx18_setup_sliced_vbi_buf(cx);
304 break; 334 break;
@@ -578,7 +608,7 @@ int cx18_v4l2_close(struct file *filp)
578 /* Mark that the radio is no longer in use */ 608 /* Mark that the radio is no longer in use */
579 clear_bit(CX18_F_I_RADIO_USER, &cx->i_flags); 609 clear_bit(CX18_F_I_RADIO_USER, &cx->i_flags);
580 /* Switch tuner to TV */ 610 /* Switch tuner to TV */
581 cx18_call_i2c_clients(cx, VIDIOC_S_STD, &cx->std); 611 cx18_call_all(cx, tuner, s_std, cx->std);
582 /* Select correct audio input (i.e. TV tuner or Line in) */ 612 /* Select correct audio input (i.e. TV tuner or Line in) */
583 cx18_audio_set_io(cx); 613 cx18_audio_set_io(cx);
584 if (atomic_read(&cx->ana_capturing) > 0) { 614 if (atomic_read(&cx->ana_capturing) > 0) {
@@ -641,7 +671,7 @@ static int cx18_serialized_open(struct cx18_stream *s, struct file *filp)
641 /* We have the radio */ 671 /* We have the radio */
642 cx18_mute(cx); 672 cx18_mute(cx);
643 /* Switch tuner to radio */ 673 /* Switch tuner to radio */
644 cx18_call_i2c_clients(cx, AUDC_SET_RADIO, NULL); 674 cx18_call_all(cx, tuner, s_radio);
645 /* Select the correct audio input (i.e. radio tuner) */ 675 /* Select the correct audio input (i.e. radio tuner) */
646 cx18_audio_set_io(cx); 676 cx18_audio_set_io(cx);
647 /* Done! Unmute and continue. */ 677 /* Done! Unmute and continue. */
@@ -652,38 +682,15 @@ static int cx18_serialized_open(struct cx18_stream *s, struct file *filp)
652 682
653int cx18_v4l2_open(struct file *filp) 683int cx18_v4l2_open(struct file *filp)
654{ 684{
655 int res, x, y = 0; 685 int res;
656 struct cx18 *cx = NULL; 686 struct video_device *video_dev = video_devdata(filp);
657 struct cx18_stream *s = NULL; 687 struct cx18_stream *s = video_get_drvdata(video_dev);
658 int minor = video_devdata(filp)->minor; 688 struct cx18 *cx = s->cx;;
659
660 /* Find which card this open was on */
661 spin_lock(&cx18_cards_lock);
662 for (x = 0; cx == NULL && x < cx18_cards_active; x++) {
663 /* find out which stream this open was on */
664 for (y = 0; y < CX18_MAX_STREAMS; y++) {
665 if (cx18_cards[x] == NULL)
666 continue;
667 s = &cx18_cards[x]->streams[y];
668 if (s->v4l2dev && s->v4l2dev->minor == minor) {
669 cx = cx18_cards[x];
670 break;
671 }
672 }
673 }
674 spin_unlock(&cx18_cards_lock);
675
676 if (cx == NULL) {
677 /* Couldn't find a device registered
678 on that minor, shouldn't happen! */
679 printk(KERN_WARNING "No cx18 device found on minor %d\n",
680 minor);
681 return -ENXIO;
682 }
683 689
684 mutex_lock(&cx->serialize_lock); 690 mutex_lock(&cx->serialize_lock);
685 if (cx18_init_on_first_open(cx)) { 691 if (cx18_init_on_first_open(cx)) {
686 CX18_ERR("Failed to initialize on minor %d\n", minor); 692 CX18_ERR("Failed to initialize on minor %d\n",
693 video_dev->minor);
687 mutex_unlock(&cx->serialize_lock); 694 mutex_unlock(&cx->serialize_lock);
688 return -ENXIO; 695 return -ENXIO;
689 } 696 }
diff --git a/drivers/media/video/cx18/cx18-firmware.c b/drivers/media/video/cx18/cx18-firmware.c
index 1fa95da1575e..83cd559cc609 100644
--- a/drivers/media/video/cx18/cx18-firmware.c
+++ b/drivers/media/video/cx18/cx18-firmware.c
@@ -26,7 +26,6 @@
26#include "cx18-irq.h" 26#include "cx18-irq.h"
27#include "cx18-firmware.h" 27#include "cx18-firmware.h"
28#include "cx18-cards.h" 28#include "cx18-cards.h"
29#include "cx18-av-core.h"
30#include <linux/firmware.h> 29#include <linux/firmware.h>
31 30
32#define CX18_PROC_SOFT_RESET 0xc70010 31#define CX18_PROC_SOFT_RESET 0xc70010
@@ -107,7 +106,7 @@ static int load_cpu_fw_direct(const char *fn, u8 __iomem *mem, struct cx18 *cx)
107 u32 __iomem *dst = (u32 __iomem *)mem; 106 u32 __iomem *dst = (u32 __iomem *)mem;
108 const u32 *src; 107 const u32 *src;
109 108
110 if (request_firmware(&fw, fn, &cx->dev->dev)) { 109 if (request_firmware(&fw, fn, &cx->pci_dev->dev)) {
111 CX18_ERR("Unable to open firmware %s\n", fn); 110 CX18_ERR("Unable to open firmware %s\n", fn);
112 CX18_ERR("Did you put the firmware in the hotplug firmware directory?\n"); 111 CX18_ERR("Did you put the firmware in the hotplug firmware directory?\n");
113 return -ENOMEM; 112 return -ENOMEM;
@@ -151,7 +150,7 @@ static int load_apu_fw_direct(const char *fn, u8 __iomem *dst, struct cx18 *cx,
151 u32 apu_version = 0; 150 u32 apu_version = 0;
152 int sz; 151 int sz;
153 152
154 if (request_firmware(&fw, fn, &cx->dev->dev)) { 153 if (request_firmware(&fw, fn, &cx->pci_dev->dev)) {
155 CX18_ERR("unable to open firmware %s\n", fn); 154 CX18_ERR("unable to open firmware %s\n", fn);
156 CX18_ERR("did you put the firmware in the hotplug firmware directory?\n"); 155 CX18_ERR("did you put the firmware in the hotplug firmware directory?\n");
157 cx18_setup_page(cx, 0); 156 cx18_setup_page(cx, 0);
@@ -286,23 +285,6 @@ void cx18_init_power(struct cx18 *cx, int lowpwr)
286 cx18_write_reg(cx, 0x2BE2FE, CX18_MPEG_CLOCK_PLL_FRAC); 285 cx18_write_reg(cx, 0x2BE2FE, CX18_MPEG_CLOCK_PLL_FRAC);
287 cx18_write_reg(cx, 8, CX18_MPEG_CLOCK_PLL_POST); 286 cx18_write_reg(cx, 8, CX18_MPEG_CLOCK_PLL_POST);
288 287
289 /*
290 * VDCLK Integer = 0x0f, Post Divider = 0x04
291 * AIMCLK Integer = 0x0e, Post Divider = 0x16
292 */
293 cx18_av_write4(cx, CXADEC_PLL_CTRL1, 0x160e040f);
294
295 /* VDCLK Fraction = 0x2be2fe */
296 /* xtal * 0xf.15f17f0/4 = 108 MHz: 432 MHz before post divide */
297 cx18_av_write4(cx, CXADEC_VID_PLL_FRAC, 0x002be2fe);
298
299 /* AIMCLK Fraction = 0x05227ad */
300 /* xtal * 0xe.2913d68/0x16 = 48000 * 384: 406 MHz before post-divide */
301 cx18_av_write4(cx, CXADEC_AUX_PLL_FRAC, 0x005227ad);
302
303 /* SA_MCLK_SEL=1, SA_MCLK_DIV=0x16 */
304 cx18_av_write(cx, CXADEC_I2S_MCLK, 0x56);
305
306 /* Defaults */ 288 /* Defaults */
307 /* APU = SC or SC/2 = 125/62.5 */ 289 /* APU = SC or SC/2 = 125/62.5 */
308 /* EPU = SC = 125 */ 290 /* EPU = SC = 125 */
diff --git a/drivers/media/video/cx18/cx18-gpio.c b/drivers/media/video/cx18/cx18-gpio.c
index 1a99329f33cb..5518d1424f8f 100644
--- a/drivers/media/video/cx18/cx18-gpio.c
+++ b/drivers/media/video/cx18/cx18-gpio.c
@@ -46,6 +46,9 @@
46 * gpio13: cs5345 reset pin 46 * gpio13: cs5345 reset pin
47*/ 47*/
48 48
49/*
50 * File scope utility functions
51 */
49static void gpio_write(struct cx18 *cx) 52static void gpio_write(struct cx18 *cx)
50{ 53{
51 u32 dir_lo = cx->gpio_dir & 0xffff; 54 u32 dir_lo = cx->gpio_dir & 0xffff;
@@ -63,73 +66,201 @@ static void gpio_write(struct cx18 *cx)
63 CX18_REG_GPIO_OUT2, val_hi, dir_hi); 66 CX18_REG_GPIO_OUT2, val_hi, dir_hi);
64} 67}
65 68
66void cx18_reset_i2c_slaves_gpio(struct cx18 *cx) 69static void gpio_update(struct cx18 *cx, u32 mask, u32 data)
67{ 70{
68 const struct cx18_gpio_i2c_slave_reset *p; 71 if (mask == 0)
72 return;
69 73
70 p = &cx->card->gpio_i2c_slave_reset; 74 mutex_lock(&cx->gpio_lock);
75 cx->gpio_val = (cx->gpio_val & ~mask) | (data & mask);
76 gpio_write(cx);
77 mutex_unlock(&cx->gpio_lock);
78}
79
80static void gpio_reset_seq(struct cx18 *cx, u32 active_lo, u32 active_hi,
81 unsigned int assert_msecs,
82 unsigned int recovery_msecs)
83{
84 u32 mask;
71 85
72 if ((p->active_lo_mask | p->active_hi_mask) == 0) 86 mask = active_lo | active_hi;
87 if (mask == 0)
73 return; 88 return;
74 89
75 /* Assuming that the masks are a subset of the bits in gpio_dir */ 90 /*
91 * Assuming that active_hi and active_lo are a subsets of the bits in
92 * gpio_dir. Also assumes that active_lo and active_hi don't overlap
93 * in any bit position
94 */
76 95
77 /* Assert */ 96 /* Assert */
78 mutex_lock(&cx->gpio_lock); 97 gpio_update(cx, mask, ~active_lo);
79 cx->gpio_val = 98 schedule_timeout_uninterruptible(msecs_to_jiffies(assert_msecs));
80 (cx->gpio_val | p->active_hi_mask) & ~(p->active_lo_mask);
81 gpio_write(cx);
82 schedule_timeout_uninterruptible(msecs_to_jiffies(p->msecs_asserted));
83 99
84 /* Deassert */ 100 /* Deassert */
85 cx->gpio_val = 101 gpio_update(cx, mask, ~active_hi);
86 (cx->gpio_val | p->active_lo_mask) & ~(p->active_hi_mask); 102 schedule_timeout_uninterruptible(msecs_to_jiffies(recovery_msecs));
87 gpio_write(cx); 103}
88 schedule_timeout_uninterruptible(msecs_to_jiffies(p->msecs_recovery)); 104
105/*
106 * GPIO Multiplexer - logical device
107 */
108static int gpiomux_log_status(struct v4l2_subdev *sd)
109{
110 struct cx18 *cx = v4l2_get_subdevdata(sd);
111
112 mutex_lock(&cx->gpio_lock);
113 CX18_INFO_DEV(sd, "GPIO: direction 0x%08x, value 0x%08x\n",
114 cx->gpio_dir, cx->gpio_val);
89 mutex_unlock(&cx->gpio_lock); 115 mutex_unlock(&cx->gpio_lock);
116 return 0;
90} 117}
91 118
92void cx18_reset_ir_gpio(void *data) 119static int gpiomux_s_radio(struct v4l2_subdev *sd)
93{ 120{
94 struct cx18 *cx = ((struct cx18_i2c_algo_callback_data *)data)->cx; 121 struct cx18 *cx = v4l2_get_subdevdata(sd);
95 const struct cx18_gpio_i2c_slave_reset *p;
96 122
97 p = &cx->card->gpio_i2c_slave_reset; 123 /*
124 * FIXME - work out the cx->active/audio_input mess - this is
125 * intended to handle the switch to radio mode and set the
126 * audio routing, but we need to update the state in cx
127 */
128 gpio_update(cx, cx->card->gpio_audio_input.mask,
129 cx->card->gpio_audio_input.radio);
130 return 0;
131}
98 132
99 if (p->ir_reset_mask == 0) 133static int gpiomux_s_std(struct v4l2_subdev *sd, v4l2_std_id norm)
100 return; 134{
135 struct cx18 *cx = v4l2_get_subdevdata(sd);
136 u32 data;
101 137
102 CX18_DEBUG_INFO("Resetting IR microcontroller\n"); 138 switch (cx->card->audio_inputs[cx->audio_input].muxer_input) {
139 case 1:
140 data = cx->card->gpio_audio_input.linein;
141 break;
142 case 0:
143 data = cx->card->gpio_audio_input.tuner;
144 break;
145 default:
146 /*
147 * FIXME - work out the cx->active/audio_input mess - this is
148 * intended to handle the switch from radio mode and set the
149 * audio routing, but we need to update the state in cx
150 */
151 data = cx->card->gpio_audio_input.tuner;
152 break;
153 }
154 gpio_update(cx, cx->card->gpio_audio_input.mask, data);
155 return 0;
156}
103 157
104 /* 158static int gpiomux_s_audio_routing(struct v4l2_subdev *sd,
105 Assert timing for the Z8F0811 on HVR-1600 boards: 159 const struct v4l2_routing *route)
106 1. Assert RESET for min of 4 clock cycles at 18.432 MHz to initiate 160{
107 2. Reset then takes 66 WDT cycles at 10 kHz + 16 xtal clock cycles 161 struct cx18 *cx = v4l2_get_subdevdata(sd);
108 (6,601,085 nanoseconds ~= 7 milliseconds) 162 u32 data;
109 3. DBG pin must be high before chip exits reset for normal operation. 163
110 DBG is open drain and hopefully pulled high since we don't 164 switch (route->input) {
111 normally drive it (GPIO 1?) for the HVR-1600 165 case 0:
112 4. Z8F0811 won't exit reset until RESET is deasserted 166 data = cx->card->gpio_audio_input.tuner;
113 */ 167 break;
114 mutex_lock(&cx->gpio_lock); 168 case 1:
115 cx->gpio_val = cx->gpio_val & ~p->ir_reset_mask; 169 data = cx->card->gpio_audio_input.linein;
116 gpio_write(cx); 170 break;
117 mutex_unlock(&cx->gpio_lock); 171 case 2:
118 schedule_timeout_uninterruptible(msecs_to_jiffies(p->msecs_asserted)); 172 data = cx->card->gpio_audio_input.radio;
173 break;
174 default:
175 return -EINVAL;
176 }
177 gpio_update(cx, cx->card->gpio_audio_input.mask, data);
178 return 0;
179}
180
181static const struct v4l2_subdev_core_ops gpiomux_core_ops = {
182 .log_status = gpiomux_log_status,
183};
184
185static const struct v4l2_subdev_tuner_ops gpiomux_tuner_ops = {
186 .s_std = gpiomux_s_std,
187 .s_radio = gpiomux_s_radio,
188};
189
190static const struct v4l2_subdev_audio_ops gpiomux_audio_ops = {
191 .s_routing = gpiomux_s_audio_routing,
192};
193
194static const struct v4l2_subdev_ops gpiomux_ops = {
195 .core = &gpiomux_core_ops,
196 .tuner = &gpiomux_tuner_ops,
197 .audio = &gpiomux_audio_ops,
198};
199
200/*
201 * GPIO Reset Controller - logical device
202 */
203static int resetctrl_log_status(struct v4l2_subdev *sd)
204{
205 struct cx18 *cx = v4l2_get_subdevdata(sd);
119 206
120 /*
121 Zilog comes out of reset, loads reset vector address and executes
122 from there. Required recovery delay unknown.
123 */
124 mutex_lock(&cx->gpio_lock); 207 mutex_lock(&cx->gpio_lock);
125 cx->gpio_val = cx->gpio_val | p->ir_reset_mask; 208 CX18_INFO_DEV(sd, "GPIO: direction 0x%08x, value 0x%08x\n",
126 gpio_write(cx); 209 cx->gpio_dir, cx->gpio_val);
127 mutex_unlock(&cx->gpio_lock); 210 mutex_unlock(&cx->gpio_lock);
128 schedule_timeout_uninterruptible(msecs_to_jiffies(p->msecs_recovery)); 211 return 0;
129} 212}
130EXPORT_SYMBOL(cx18_reset_ir_gpio);
131/* This symbol is exported for use by an infrared module for the IR-blaster */
132 213
214static int resetctrl_reset(struct v4l2_subdev *sd, u32 val)
215{
216 struct cx18 *cx = v4l2_get_subdevdata(sd);
217 const struct cx18_gpio_i2c_slave_reset *p;
218
219 p = &cx->card->gpio_i2c_slave_reset;
220 switch (val) {
221 case CX18_GPIO_RESET_I2C:
222 gpio_reset_seq(cx, p->active_lo_mask, p->active_hi_mask,
223 p->msecs_asserted, p->msecs_recovery);
224 break;
225 case CX18_GPIO_RESET_Z8F0811:
226 /*
227 * Assert timing for the Z8F0811 on HVR-1600 boards:
228 * 1. Assert RESET for min of 4 clock cycles at 18.432 MHz to
229 * initiate
230 * 2. Reset then takes 66 WDT cycles at 10 kHz + 16 xtal clock
231 * cycles (6,601,085 nanoseconds ~= 7 milliseconds)
232 * 3. DBG pin must be high before chip exits reset for normal
233 * operation. DBG is open drain and hopefully pulled high
234 * since we don't normally drive it (GPIO 1?) for the
235 * HVR-1600
236 * 4. Z8F0811 won't exit reset until RESET is deasserted
237 * 5. Zilog comes out of reset, loads reset vector address and
238 * executes from there. Required recovery delay unknown.
239 */
240 gpio_reset_seq(cx, p->ir_reset_mask, 0,
241 p->msecs_asserted, p->msecs_recovery);
242 break;
243 case CX18_GPIO_RESET_XC2028:
244 if (cx->card->tuners[0].tuner == TUNER_XC2028)
245 gpio_reset_seq(cx, (1 << cx->card->xceive_pin), 0,
246 1, 1);
247 break;
248 }
249 return 0;
250}
251
252static const struct v4l2_subdev_core_ops resetctrl_core_ops = {
253 .log_status = resetctrl_log_status,
254 .reset = resetctrl_reset,
255};
256
257static const struct v4l2_subdev_ops resetctrl_ops = {
258 .core = &resetctrl_core_ops,
259};
260
261/*
262 * External entry points
263 */
133void cx18_gpio_init(struct cx18 *cx) 264void cx18_gpio_init(struct cx18 *cx)
134{ 265{
135 mutex_lock(&cx->gpio_lock); 266 mutex_lock(&cx->gpio_lock);
@@ -156,6 +287,49 @@ void cx18_gpio_init(struct cx18 *cx)
156 mutex_unlock(&cx->gpio_lock); 287 mutex_unlock(&cx->gpio_lock);
157} 288}
158 289
290int cx18_gpio_register(struct cx18 *cx, u32 hw)
291{
292 struct v4l2_subdev *sd;
293 const struct v4l2_subdev_ops *ops;
294 char *str;
295
296 switch (hw) {
297 case CX18_HW_GPIO_MUX:
298 sd = &cx->sd_gpiomux;
299 ops = &gpiomux_ops;
300 str = "gpio-mux";
301 break;
302 case CX18_HW_GPIO_RESET_CTRL:
303 sd = &cx->sd_resetctrl;
304 ops = &resetctrl_ops;
305 str = "gpio-reset-ctrl";
306 break;
307 default:
308 return -EINVAL;
309 }
310
311 v4l2_subdev_init(sd, ops);
312 v4l2_set_subdevdata(sd, cx);
313 snprintf(sd->name, sizeof(sd->name), "%s %s", cx->v4l2_dev.name, str);
314 sd->grp_id = hw;
315 return v4l2_device_register_subdev(&cx->v4l2_dev, sd);
316}
317
318void cx18_reset_ir_gpio(void *data)
319{
320 struct cx18 *cx = to_cx18((struct v4l2_device *)data);
321
322 if (cx->card->gpio_i2c_slave_reset.ir_reset_mask == 0)
323 return;
324
325 CX18_DEBUG_INFO("Resetting IR microcontroller\n");
326
327 v4l2_subdev_call(&cx->sd_resetctrl,
328 core, reset, CX18_GPIO_RESET_Z8F0811);
329}
330EXPORT_SYMBOL(cx18_reset_ir_gpio);
331/* This symbol is exported for use by lirc_pvr150 for the IR-blaster */
332
159/* Xceive tuner reset function */ 333/* Xceive tuner reset function */
160int cx18_reset_tuner_gpio(void *dev, int component, int cmd, int value) 334int cx18_reset_tuner_gpio(void *dev, int component, int cmd, int value)
161{ 335{
@@ -163,56 +337,11 @@ int cx18_reset_tuner_gpio(void *dev, int component, int cmd, int value)
163 struct cx18_i2c_algo_callback_data *cb_data = algo->data; 337 struct cx18_i2c_algo_callback_data *cb_data = algo->data;
164 struct cx18 *cx = cb_data->cx; 338 struct cx18 *cx = cb_data->cx;
165 339
166 if (cmd != XC2028_TUNER_RESET) 340 if (cmd != XC2028_TUNER_RESET ||
341 cx->card->tuners[0].tuner != TUNER_XC2028)
167 return 0; 342 return 0;
168 CX18_DEBUG_INFO("Resetting tuner\n");
169 343
170 mutex_lock(&cx->gpio_lock); 344 CX18_DEBUG_INFO("Resetting XCeive tuner\n");
171 cx->gpio_val &= ~(1 << cx->card->xceive_pin); 345 return v4l2_subdev_call(&cx->sd_resetctrl,
172 gpio_write(cx); 346 core, reset, CX18_GPIO_RESET_XC2028);
173 mutex_unlock(&cx->gpio_lock);
174 schedule_timeout_interruptible(msecs_to_jiffies(1));
175
176 mutex_lock(&cx->gpio_lock);
177 cx->gpio_val |= 1 << cx->card->xceive_pin;
178 gpio_write(cx);
179 mutex_unlock(&cx->gpio_lock);
180 schedule_timeout_interruptible(msecs_to_jiffies(1));
181 return 0;
182}
183
184int cx18_gpio(struct cx18 *cx, unsigned int command, void *arg)
185{
186 struct v4l2_routing *route = arg;
187 u32 mask, data;
188
189 switch (command) {
190 case VIDIOC_INT_S_AUDIO_ROUTING:
191 if (route->input > 2)
192 return -EINVAL;
193 mask = cx->card->gpio_audio_input.mask;
194 switch (route->input) {
195 case 0:
196 data = cx->card->gpio_audio_input.tuner;
197 break;
198 case 1:
199 data = cx->card->gpio_audio_input.linein;
200 break;
201 case 2:
202 default:
203 data = cx->card->gpio_audio_input.radio;
204 break;
205 }
206 break;
207
208 default:
209 return -EINVAL;
210 }
211 if (mask) {
212 mutex_lock(&cx->gpio_lock);
213 cx->gpio_val = (cx->gpio_val & ~mask) | (data & mask);
214 gpio_write(cx);
215 mutex_unlock(&cx->gpio_lock);
216 }
217 return 0;
218} 347}
diff --git a/drivers/media/video/cx18/cx18-gpio.h b/drivers/media/video/cx18/cx18-gpio.h
index 39ffccc19d8a..f9a5ca3566af 100644
--- a/drivers/media/video/cx18/cx18-gpio.h
+++ b/drivers/media/video/cx18/cx18-gpio.h
@@ -22,7 +22,13 @@
22 */ 22 */
23 23
24void cx18_gpio_init(struct cx18 *cx); 24void cx18_gpio_init(struct cx18 *cx);
25void cx18_reset_i2c_slaves_gpio(struct cx18 *cx); 25int cx18_gpio_register(struct cx18 *cx, u32 hw);
26
27enum cx18_gpio_reset_type {
28 CX18_GPIO_RESET_I2C = 0,
29 CX18_GPIO_RESET_Z8F0811 = 1,
30 CX18_GPIO_RESET_XC2028 = 2,
31};
32
26void cx18_reset_ir_gpio(void *data); 33void cx18_reset_ir_gpio(void *data);
27int cx18_reset_tuner_gpio(void *dev, int component, int cmd, int value); 34int cx18_reset_tuner_gpio(void *dev, int component, int cmd, int value);
28int cx18_gpio(struct cx18 *cx, unsigned int command, void *arg);
diff --git a/drivers/media/video/cx18/cx18-i2c.c b/drivers/media/video/cx18/cx18-i2c.c
index 83e1c6333126..d092643faf46 100644
--- a/drivers/media/video/cx18/cx18-i2c.c
+++ b/drivers/media/video/cx18/cx18-i2c.c
@@ -26,7 +26,6 @@
26#include "cx18-io.h" 26#include "cx18-io.h"
27#include "cx18-cards.h" 27#include "cx18-cards.h"
28#include "cx18-gpio.h" 28#include "cx18-gpio.h"
29#include "cx18-av-core.h"
30#include "cx18-i2c.h" 29#include "cx18-i2c.h"
31#include "cx18-irq.h" 30#include "cx18-irq.h"
32 31
@@ -43,31 +42,37 @@
43#define CX18_CS5345_I2C_ADDR 0x4c 42#define CX18_CS5345_I2C_ADDR 0x4c
44 43
45/* This array should match the CX18_HW_ defines */ 44/* This array should match the CX18_HW_ defines */
46static const u8 hw_driverids[] = {
47 I2C_DRIVERID_TUNER,
48 I2C_DRIVERID_TVEEPROM,
49 I2C_DRIVERID_CS5345,
50 0, /* CX18_HW_GPIO dummy driver ID */
51 0 /* CX18_HW_CX23418 dummy driver ID */
52};
53
54/* This array should match the CX18_HW_ defines */
55static const u8 hw_addrs[] = { 45static const u8 hw_addrs[] = {
56 0, 46 0, /* CX18_HW_TUNER */
57 0, 47 0, /* CX18_HW_TVEEPROM */
58 CX18_CS5345_I2C_ADDR, 48 CX18_CS5345_I2C_ADDR, /* CX18_HW_CS5345 */
59 0, /* CX18_HW_GPIO dummy driver ID */ 49 0, /* CX18_HW_DVB */
60 0, /* CX18_HW_CX23418 dummy driver ID */ 50 0, /* CX18_HW_418_AV */
51 0, /* CX18_HW_GPIO_MUX */
52 0, /* CX18_HW_GPIO_RESET_CTRL */
61}; 53};
62 54
63/* This array should match the CX18_HW_ defines */ 55/* This array should match the CX18_HW_ defines */
64/* This might well become a card-specific array */ 56/* This might well become a card-specific array */
65static const u8 hw_bus[] = { 57static const u8 hw_bus[] = {
66 0, 58 1, /* CX18_HW_TUNER */
67 0, 59 0, /* CX18_HW_TVEEPROM */
68 0, 60 0, /* CX18_HW_CS5345 */
69 0, /* CX18_HW_GPIO dummy driver ID */ 61 0, /* CX18_HW_DVB */
70 0, /* CX18_HW_CX23418 dummy driver ID */ 62 0, /* CX18_HW_418_AV */
63 0, /* CX18_HW_GPIO_MUX */
64 0, /* CX18_HW_GPIO_RESET_CTRL */
65};
66
67/* This array should match the CX18_HW_ defines */
68static const char * const hw_modules[] = {
69 "tuner", /* CX18_HW_TUNER */
70 NULL, /* CX18_HW_TVEEPROM */
71 "cs5345", /* CX18_HW_CS5345 */
72 NULL, /* CX18_HW_DVB */
73 NULL, /* CX18_HW_418_AV */
74 NULL, /* CX18_HW_GPIO_MUX */
75 NULL, /* CX18_HW_GPIO_RESET_CTRL */
71}; 76};
72 77
73/* This array should match the CX18_HW_ defines */ 78/* This array should match the CX18_HW_ defines */
@@ -75,83 +80,67 @@ static const char * const hw_devicenames[] = {
75 "tuner", 80 "tuner",
76 "tveeprom", 81 "tveeprom",
77 "cs5345", 82 "cs5345",
78 "gpio", 83 "cx23418_DTV",
79 "cx23418", 84 "cx23418_AV",
85 "gpio_mux",
86 "gpio_reset_ctrl",
80}; 87};
81 88
82int cx18_i2c_register(struct cx18 *cx, unsigned idx) 89int cx18_i2c_register(struct cx18 *cx, unsigned idx)
83{ 90{
84 struct i2c_board_info info; 91 struct v4l2_subdev *sd;
85 struct i2c_client *c; 92 int bus = hw_bus[idx];
86 u8 id, bus; 93 struct i2c_adapter *adap = &cx->i2c_adap[bus];
87 int i; 94 const char *mod = hw_modules[idx];
88 95 const char *type = hw_devicenames[idx];
89 CX18_DEBUG_I2C("i2c client register\n"); 96 u32 hw = 1 << idx;
90 if (idx >= ARRAY_SIZE(hw_driverids) || hw_driverids[idx] == 0) 97
98 if (idx >= ARRAY_SIZE(hw_addrs))
91 return -1; 99 return -1;
92 id = hw_driverids[idx];
93 bus = hw_bus[idx];
94 memset(&info, 0, sizeof(info));
95 strlcpy(info.type, hw_devicenames[idx], sizeof(info.type));
96 info.addr = hw_addrs[idx];
97 for (i = 0; i < I2C_CLIENTS_MAX; i++)
98 if (cx->i2c_clients[i] == NULL)
99 break;
100
101 if (i == I2C_CLIENTS_MAX) {
102 CX18_ERR("insufficient room for new I2C client!\n");
103 return -ENOMEM;
104 }
105 100
106 if (id != I2C_DRIVERID_TUNER) { 101 if (hw == CX18_HW_TUNER) {
107 c = i2c_new_device(&cx->i2c_adap[bus], &info); 102 /* special tuner group handling */
108 if (c->driver == NULL) 103 sd = v4l2_i2c_new_probed_subdev(adap, mod, type,
109 i2c_unregister_device(c); 104 cx->card_i2c->radio);
110 else 105 if (sd != NULL)
111 cx->i2c_clients[i] = c; 106 sd->grp_id = hw;
112 return cx->i2c_clients[i] ? 0 : -ENODEV; 107 sd = v4l2_i2c_new_probed_subdev(adap, mod, type,
108 cx->card_i2c->demod);
109 if (sd != NULL)
110 sd->grp_id = hw;
111 sd = v4l2_i2c_new_probed_subdev(adap, mod, type,
112 cx->card_i2c->tv);
113 if (sd != NULL)
114 sd->grp_id = hw;
115 return sd != NULL ? 0 : -1;
113 } 116 }
114 117
115 /* special tuner handling */ 118 /* Is it not an I2C device or one we do not wish to register? */
116 c = i2c_new_probed_device(&cx->i2c_adap[1], &info, cx->card_i2c->radio); 119 if (!hw_addrs[idx])
117 if (c && c->driver == NULL) 120 return -1;
118 i2c_unregister_device(c);
119 else if (c)
120 cx->i2c_clients[i++] = c;
121 c = i2c_new_probed_device(&cx->i2c_adap[1], &info, cx->card_i2c->demod);
122 if (c && c->driver == NULL)
123 i2c_unregister_device(c);
124 else if (c)
125 cx->i2c_clients[i++] = c;
126 c = i2c_new_probed_device(&cx->i2c_adap[1], &info, cx->card_i2c->tv);
127 if (c && c->driver == NULL)
128 i2c_unregister_device(c);
129 else if (c)
130 cx->i2c_clients[i++] = c;
131 return 0;
132}
133 121
134static int attach_inform(struct i2c_client *client) 122 /* It's an I2C device other than an analog tuner */
135{ 123 sd = v4l2_i2c_new_subdev(adap, mod, type, hw_addrs[idx]);
136 return 0; 124 if (sd != NULL)
125 sd->grp_id = hw;
126 return sd != NULL ? 0 : -1;
137} 127}
138 128
139static int detach_inform(struct i2c_client *client) 129/* Find the first member of the subdev group id in hw */
130struct v4l2_subdev *cx18_find_hw(struct cx18 *cx, u32 hw)
140{ 131{
141 int i; 132 struct v4l2_subdev *result = NULL;
142 struct cx18 *cx = (struct cx18 *)i2c_get_adapdata(client->adapter); 133 struct v4l2_subdev *sd;
143 134
144 CX18_DEBUG_I2C("i2c client detach\n"); 135 spin_lock(&cx->v4l2_dev.lock);
145 for (i = 0; i < I2C_CLIENTS_MAX; i++) { 136 v4l2_device_for_each_subdev(sd, &cx->v4l2_dev) {
146 if (cx->i2c_clients[i] == client) { 137 if (sd->grp_id == hw) {
147 cx->i2c_clients[i] = NULL; 138 result = sd;
148 break; 139 break;
149 } 140 }
150 } 141 }
151 CX18_DEBUG_I2C("i2c detach [client=%s,%s]\n", 142 spin_unlock(&cx->v4l2_dev.lock);
152 client->name, (i < I2C_CLIENTS_MAX) ? "ok" : "failed"); 143 return result;
153
154 return 0;
155} 144}
156 145
157static void cx18_setscl(void *data, int state) 146static void cx18_setscl(void *data, int state)
@@ -204,8 +193,6 @@ static struct i2c_adapter cx18_i2c_adap_template = {
204 .id = I2C_HW_B_CX2341X, 193 .id = I2C_HW_B_CX2341X,
205 .algo = NULL, /* set by i2c-algo-bit */ 194 .algo = NULL, /* set by i2c-algo-bit */
206 .algo_data = NULL, /* filled from template */ 195 .algo_data = NULL, /* filled from template */
207 .client_register = attach_inform,
208 .client_unregister = detach_inform,
209 .owner = THIS_MODULE, 196 .owner = THIS_MODULE,
210}; 197};
211 198
@@ -221,152 +208,28 @@ static struct i2c_algo_bit_data cx18_i2c_algo_template = {
221 .timeout = CX18_ALGO_BIT_TIMEOUT*HZ /* jiffies */ 208 .timeout = CX18_ALGO_BIT_TIMEOUT*HZ /* jiffies */
222}; 209};
223 210
224static struct i2c_client cx18_i2c_client_template = {
225 .name = "cx18 internal",
226};
227
228int cx18_call_i2c_client(struct cx18 *cx, int addr, unsigned cmd, void *arg)
229{
230 struct i2c_client *client;
231 int retval;
232 int i;
233
234 CX18_DEBUG_I2C("call_i2c_client addr=%02x\n", addr);
235 for (i = 0; i < I2C_CLIENTS_MAX; i++) {
236 client = cx->i2c_clients[i];
237 if (client == NULL || client->driver == NULL ||
238 client->driver->command == NULL)
239 continue;
240 if (addr == client->addr) {
241 retval = client->driver->command(client, cmd, arg);
242 return retval;
243 }
244 }
245 if (cmd != VIDIOC_DBG_G_CHIP_IDENT)
246 CX18_ERR("i2c addr 0x%02x not found for cmd 0x%x!\n",
247 addr, cmd);
248 return -ENODEV;
249}
250
251/* Find the i2c device based on the driver ID and return
252 its i2c address or -ENODEV if no matching device was found. */
253static int cx18_i2c_id_addr(struct cx18 *cx, u32 id)
254{
255 struct i2c_client *client;
256 int retval = -ENODEV;
257 int i;
258
259 for (i = 0; i < I2C_CLIENTS_MAX; i++) {
260 client = cx->i2c_clients[i];
261 if (client == NULL || client->driver == NULL)
262 continue;
263 if (id == client->driver->id) {
264 retval = client->addr;
265 break;
266 }
267 }
268 return retval;
269}
270
271/* Find the i2c device name matching the CX18_HW_ flag */
272static const char *cx18_i2c_hw_name(u32 hw)
273{
274 int i;
275
276 for (i = 0; i < ARRAY_SIZE(hw_driverids); i++)
277 if (1 << i == hw)
278 return hw_devicenames[i];
279 return "unknown device";
280}
281
282/* Find the i2c device matching the CX18_HW_ flag and return
283 its i2c address or -ENODEV if no matching device was found. */
284int cx18_i2c_hw_addr(struct cx18 *cx, u32 hw)
285{
286 int i;
287
288 for (i = 0; i < ARRAY_SIZE(hw_driverids); i++)
289 if (1 << i == hw)
290 return cx18_i2c_id_addr(cx, hw_driverids[i]);
291 return -ENODEV;
292}
293
294/* Calls i2c device based on CX18_HW_ flag. If hw == 0, then do nothing.
295 If hw == CX18_HW_GPIO then call the gpio handler. */
296int cx18_i2c_hw(struct cx18 *cx, u32 hw, unsigned int cmd, void *arg)
297{
298 int addr;
299
300 if (hw == 0)
301 return 0;
302
303 if (hw == CX18_HW_GPIO)
304 return cx18_gpio(cx, cmd, arg);
305
306 if (hw == CX18_HW_CX23418)
307 return cx18_av_cmd(cx, cmd, arg);
308
309 addr = cx18_i2c_hw_addr(cx, hw);
310 if (addr < 0) {
311 CX18_ERR("i2c hardware 0x%08x (%s) not found for cmd 0x%x!\n",
312 hw, cx18_i2c_hw_name(hw), cmd);
313 return addr;
314 }
315 return cx18_call_i2c_client(cx, addr, cmd, arg);
316}
317
318/* broadcast cmd for all I2C clients and for the gpio subsystem */
319void cx18_call_i2c_clients(struct cx18 *cx, unsigned int cmd, void *arg)
320{
321 if (cx->i2c_adap[0].algo == NULL || cx->i2c_adap[1].algo == NULL) {
322 CX18_ERR("adapter is not set\n");
323 return;
324 }
325 cx18_av_cmd(cx, cmd, arg);
326 i2c_clients_command(&cx->i2c_adap[0], cmd, arg);
327 i2c_clients_command(&cx->i2c_adap[1], cmd, arg);
328 if (cx->hw_flags & CX18_HW_GPIO)
329 cx18_gpio(cx, cmd, arg);
330}
331
332/* init + register i2c algo-bit adapter */ 211/* init + register i2c algo-bit adapter */
333int init_cx18_i2c(struct cx18 *cx) 212int init_cx18_i2c(struct cx18 *cx)
334{ 213{
335 int i; 214 int i;
336 CX18_DEBUG_I2C("i2c init\n"); 215 CX18_DEBUG_I2C("i2c init\n");
337 216
338 /* Sanity checks for the I2C hardware arrays. They must be the
339 * same size and GPIO/CX23418 must be the last entries.
340 */
341 if (ARRAY_SIZE(hw_driverids) != ARRAY_SIZE(hw_addrs) ||
342 ARRAY_SIZE(hw_devicenames) != ARRAY_SIZE(hw_addrs) ||
343 CX18_HW_GPIO != (1 << (ARRAY_SIZE(hw_addrs) - 2)) ||
344 CX18_HW_CX23418 != (1 << (ARRAY_SIZE(hw_addrs) - 1)) ||
345 hw_driverids[ARRAY_SIZE(hw_addrs) - 1]) {
346 CX18_ERR("Mismatched I2C hardware arrays\n");
347 return -ENODEV;
348 }
349
350 for (i = 0; i < 2; i++) { 217 for (i = 0; i < 2; i++) {
351 memcpy(&cx->i2c_adap[i], &cx18_i2c_adap_template, 218 /* Setup algorithm for adapter */
352 sizeof(struct i2c_adapter));
353 memcpy(&cx->i2c_algo[i], &cx18_i2c_algo_template, 219 memcpy(&cx->i2c_algo[i], &cx18_i2c_algo_template,
354 sizeof(struct i2c_algo_bit_data)); 220 sizeof(struct i2c_algo_bit_data));
355 cx->i2c_algo_cb_data[i].cx = cx; 221 cx->i2c_algo_cb_data[i].cx = cx;
356 cx->i2c_algo_cb_data[i].bus_index = i; 222 cx->i2c_algo_cb_data[i].bus_index = i;
357 cx->i2c_algo[i].data = &cx->i2c_algo_cb_data[i]; 223 cx->i2c_algo[i].data = &cx->i2c_algo_cb_data[i];
358 cx->i2c_adap[i].algo_data = &cx->i2c_algo[i];
359 224
225 /* Setup adapter */
226 memcpy(&cx->i2c_adap[i], &cx18_i2c_adap_template,
227 sizeof(struct i2c_adapter));
228 cx->i2c_adap[i].algo_data = &cx->i2c_algo[i];
360 sprintf(cx->i2c_adap[i].name + strlen(cx->i2c_adap[i].name), 229 sprintf(cx->i2c_adap[i].name + strlen(cx->i2c_adap[i].name),
361 " #%d-%d", cx->num, i); 230 " #%d-%d", cx->instance, i);
362 i2c_set_adapdata(&cx->i2c_adap[i], cx); 231 i2c_set_adapdata(&cx->i2c_adap[i], &cx->v4l2_dev);
363 232 cx->i2c_adap[i].dev.parent = &cx->pci_dev->dev;
364 memcpy(&cx->i2c_client[i], &cx18_i2c_client_template,
365 sizeof(struct i2c_client));
366 sprintf(cx->i2c_client[i].name +
367 strlen(cx->i2c_client[i].name), "%d", i);
368 cx->i2c_client[i].adapter = &cx->i2c_adap[i];
369 cx->i2c_adap[i].dev.parent = &cx->dev->dev;
370 } 233 }
371 234
372 if (cx18_read_reg(cx, CX18_REG_I2C_2_WR) != 0x0003c02f) { 235 if (cx18_read_reg(cx, CX18_REG_I2C_2_WR) != 0x0003c02f) {
@@ -402,7 +265,8 @@ int init_cx18_i2c(struct cx18 *cx)
402 cx18_setscl(&cx->i2c_algo_cb_data[1], 1); 265 cx18_setscl(&cx->i2c_algo_cb_data[1], 1);
403 cx18_setsda(&cx->i2c_algo_cb_data[1], 1); 266 cx18_setsda(&cx->i2c_algo_cb_data[1], 1);
404 267
405 cx18_reset_i2c_slaves_gpio(cx); 268 cx18_call_hw(cx, CX18_HW_GPIO_RESET_CTRL,
269 core, reset, (u32) CX18_GPIO_RESET_I2C);
406 270
407 return i2c_bit_add_bus(&cx->i2c_adap[0]) || 271 return i2c_bit_add_bus(&cx->i2c_adap[0]) ||
408 i2c_bit_add_bus(&cx->i2c_adap[1]); 272 i2c_bit_add_bus(&cx->i2c_adap[1]);
diff --git a/drivers/media/video/cx18/cx18-i2c.h b/drivers/media/video/cx18/cx18-i2c.h
index 4869739013bd..bdfd1921e300 100644
--- a/drivers/media/video/cx18/cx18-i2c.h
+++ b/drivers/media/video/cx18/cx18-i2c.h
@@ -21,11 +21,8 @@
21 * 02111-1307 USA 21 * 02111-1307 USA
22 */ 22 */
23 23
24int cx18_i2c_hw_addr(struct cx18 *cx, u32 hw);
25int cx18_i2c_hw(struct cx18 *cx, u32 hw, unsigned int cmd, void *arg);
26int cx18_call_i2c_client(struct cx18 *cx, int addr, unsigned cmd, void *arg);
27void cx18_call_i2c_clients(struct cx18 *cx, unsigned int cmd, void *arg);
28int cx18_i2c_register(struct cx18 *cx, unsigned idx); 24int cx18_i2c_register(struct cx18 *cx, unsigned idx);
25struct v4l2_subdev *cx18_find_hw(struct cx18 *cx, u32 hw);
29 26
30/* init + register i2c algo-bit adapter */ 27/* init + register i2c algo-bit adapter */
31int init_cx18_i2c(struct cx18 *cx); 28int init_cx18_i2c(struct cx18 *cx);
diff --git a/drivers/media/video/cx18/cx18-ioctl.c b/drivers/media/video/cx18/cx18-ioctl.c
index 7086aaba77d6..e4c9e3d8bacd 100644
--- a/drivers/media/video/cx18/cx18-ioctl.c
+++ b/drivers/media/video/cx18/cx18-ioctl.c
@@ -58,12 +58,21 @@ u16 cx18_service2vbi(int type)
58 } 58 }
59} 59}
60 60
61/* Check if VBI services are allowed on the (field, line) for the video std */
61static int valid_service_line(int field, int line, int is_pal) 62static int valid_service_line(int field, int line, int is_pal)
62{ 63{
63 return (is_pal && line >= 6 && (line != 23 || field == 0)) || 64 return (is_pal && line >= 6 &&
65 ((field == 0 && line <= 23) || (field == 1 && line <= 22))) ||
64 (!is_pal && line >= 10 && line < 22); 66 (!is_pal && line >= 10 && line < 22);
65} 67}
66 68
69/*
70 * For a (field, line, std) and inbound potential set of services for that line,
71 * return the first valid service of those passed in the incoming set for that
72 * line in priority order:
73 * CC, VPS, or WSS over TELETEXT for well known lines
74 * TELETEXT, before VPS, before CC, before WSS, for other lines
75 */
67static u16 select_service_from_set(int field, int line, u16 set, int is_pal) 76static u16 select_service_from_set(int field, int line, u16 set, int is_pal)
68{ 77{
69 u16 valid_set = (is_pal ? V4L2_SLICED_VBI_625 : V4L2_SLICED_VBI_525); 78 u16 valid_set = (is_pal ? V4L2_SLICED_VBI_625 : V4L2_SLICED_VBI_525);
@@ -90,6 +99,10 @@ static u16 select_service_from_set(int field, int line, u16 set, int is_pal)
90 return 0; 99 return 0;
91} 100}
92 101
102/*
103 * Expand the service_set of *fmt into valid service_lines for the std,
104 * and clear the passed in fmt->service_set
105 */
93void cx18_expand_service_set(struct v4l2_sliced_vbi_format *fmt, int is_pal) 106void cx18_expand_service_set(struct v4l2_sliced_vbi_format *fmt, int is_pal)
94{ 107{
95 u16 set = fmt->service_set; 108 u16 set = fmt->service_set;
@@ -102,7 +115,25 @@ void cx18_expand_service_set(struct v4l2_sliced_vbi_format *fmt, int is_pal)
102 } 115 }
103} 116}
104 117
118/*
119 * Sanitize the service_lines in *fmt per the video std, and return 1
120 * if any service_line is left as valid after santization
121 */
122static int check_service_set(struct v4l2_sliced_vbi_format *fmt, int is_pal)
123{
124 int f, l;
125 u16 set = 0;
126
127 for (f = 0; f < 2; f++) {
128 for (l = 0; l < 24; l++) {
129 fmt->service_lines[f][l] = select_service_from_set(f, l, fmt->service_lines[f][l], is_pal);
130 set |= fmt->service_lines[f][l];
131 }
132 }
133 return set != 0;
134}
105 135
136/* Compute the service_set from the assumed valid service_lines of *fmt */
106u16 cx18_get_service_set(struct v4l2_sliced_vbi_format *fmt) 137u16 cx18_get_service_set(struct v4l2_sliced_vbi_format *fmt)
107{ 138{
108 int f, l; 139 int f, l;
@@ -129,10 +160,8 @@ static int cx18_g_fmt_vid_cap(struct file *file, void *fh,
129 pixfmt->priv = 0; 160 pixfmt->priv = 0;
130 if (id->type == CX18_ENC_STREAM_TYPE_YUV) { 161 if (id->type == CX18_ENC_STREAM_TYPE_YUV) {
131 pixfmt->pixelformat = V4L2_PIX_FMT_HM12; 162 pixfmt->pixelformat = V4L2_PIX_FMT_HM12;
132 /* YUV size is (Y=(h*w) + UV=(h*(w/2))) */ 163 /* YUV size is (Y=(h*720) + UV=(h*(720/2))) */
133 pixfmt->sizeimage = 164 pixfmt->sizeimage = pixfmt->height * 720 * 3 / 2;
134 pixfmt->height * pixfmt->width +
135 pixfmt->height * (pixfmt->width / 2);
136 pixfmt->bytesperline = 720; 165 pixfmt->bytesperline = 720;
137 } else { 166 } else {
138 pixfmt->pixelformat = V4L2_PIX_FMT_MPEG; 167 pixfmt->pixelformat = V4L2_PIX_FMT_MPEG;
@@ -149,8 +178,8 @@ static int cx18_g_fmt_vbi_cap(struct file *file, void *fh,
149 struct v4l2_vbi_format *vbifmt = &fmt->fmt.vbi; 178 struct v4l2_vbi_format *vbifmt = &fmt->fmt.vbi;
150 179
151 vbifmt->sampling_rate = 27000000; 180 vbifmt->sampling_rate = 27000000;
152 vbifmt->offset = 248; 181 vbifmt->offset = 248; /* FIXME - slightly wrong for both 50 & 60 Hz */
153 vbifmt->samples_per_line = cx->vbi.raw_decoder_line_size - 4; 182 vbifmt->samples_per_line = vbi_active_samples - 4;
154 vbifmt->sample_format = V4L2_PIX_FMT_GREY; 183 vbifmt->sample_format = V4L2_PIX_FMT_GREY;
155 vbifmt->start[0] = cx->vbi.start[0]; 184 vbifmt->start[0] = cx->vbi.start[0];
156 vbifmt->start[1] = cx->vbi.start[1]; 185 vbifmt->start[1] = cx->vbi.start[1];
@@ -164,7 +193,30 @@ static int cx18_g_fmt_vbi_cap(struct file *file, void *fh,
164static int cx18_g_fmt_sliced_vbi_cap(struct file *file, void *fh, 193static int cx18_g_fmt_sliced_vbi_cap(struct file *file, void *fh,
165 struct v4l2_format *fmt) 194 struct v4l2_format *fmt)
166{ 195{
167 return -EINVAL; 196 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
197 struct v4l2_sliced_vbi_format *vbifmt = &fmt->fmt.sliced;
198
199 /* sane, V4L2 spec compliant, defaults */
200 vbifmt->reserved[0] = 0;
201 vbifmt->reserved[1] = 0;
202 vbifmt->io_size = sizeof(struct v4l2_sliced_vbi_data) * 36;
203 memset(vbifmt->service_lines, 0, sizeof(vbifmt->service_lines));
204 vbifmt->service_set = 0;
205
206 /*
207 * Fetch the configured service_lines and total service_set from the
208 * digitizer/slicer. Note, cx18_av_vbi() wipes the passed in
209 * fmt->fmt.sliced under valid calling conditions
210 */
211 if (v4l2_subdev_call(cx->sd_av, video, g_fmt, fmt))
212 return -EINVAL;
213
214 /* Ensure V4L2 spec compliant output */
215 vbifmt->reserved[0] = 0;
216 vbifmt->reserved[1] = 0;
217 vbifmt->io_size = sizeof(struct v4l2_sliced_vbi_data) * 36;
218 vbifmt->service_set = cx18_get_service_set(vbifmt);
219 return 0;
168} 220}
169 221
170static int cx18_try_fmt_vid_cap(struct file *file, void *fh, 222static int cx18_try_fmt_vid_cap(struct file *file, void *fh,
@@ -174,11 +226,18 @@ static int cx18_try_fmt_vid_cap(struct file *file, void *fh,
174 struct cx18 *cx = id->cx; 226 struct cx18 *cx = id->cx;
175 int w = fmt->fmt.pix.width; 227 int w = fmt->fmt.pix.width;
176 int h = fmt->fmt.pix.height; 228 int h = fmt->fmt.pix.height;
229 int min_h = 2;
177 230
178 w = min(w, 720); 231 w = min(w, 720);
179 w = max(w, 1); 232 w = max(w, 2);
233 if (id->type == CX18_ENC_STREAM_TYPE_YUV) {
234 /* YUV height must be a multiple of 32 */
235 h &= ~0x1f;
236 min_h = 32;
237 }
180 h = min(h, cx->is_50hz ? 576 : 480); 238 h = min(h, cx->is_50hz ? 576 : 480);
181 h = max(h, 2); 239 h = max(h, min_h);
240
182 cx18_g_fmt_vid_cap(file, fh, fmt); 241 cx18_g_fmt_vid_cap(file, fh, fmt);
183 fmt->fmt.pix.width = w; 242 fmt->fmt.pix.width = w;
184 fmt->fmt.pix.height = h; 243 fmt->fmt.pix.height = h;
@@ -194,7 +253,20 @@ static int cx18_try_fmt_vbi_cap(struct file *file, void *fh,
194static int cx18_try_fmt_sliced_vbi_cap(struct file *file, void *fh, 253static int cx18_try_fmt_sliced_vbi_cap(struct file *file, void *fh,
195 struct v4l2_format *fmt) 254 struct v4l2_format *fmt)
196{ 255{
197 return -EINVAL; 256 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
257 struct v4l2_sliced_vbi_format *vbifmt = &fmt->fmt.sliced;
258
259 vbifmt->io_size = sizeof(struct v4l2_sliced_vbi_data) * 36;
260 vbifmt->reserved[0] = 0;
261 vbifmt->reserved[1] = 0;
262
263 /* If given a service set, expand it validly & clear passed in set */
264 if (vbifmt->service_set)
265 cx18_expand_service_set(vbifmt, cx->is_50hz);
266 /* Sanitize the service_lines, and compute the new set if any valid */
267 if (check_service_set(vbifmt, cx->is_50hz))
268 vbifmt->service_set = cx18_get_service_set(vbifmt);
269 return 0;
198} 270}
199 271
200static int cx18_s_fmt_vid_cap(struct file *file, void *fh, 272static int cx18_s_fmt_vid_cap(struct file *file, void *fh,
@@ -223,7 +295,7 @@ static int cx18_s_fmt_vid_cap(struct file *file, void *fh,
223 295
224 cx->params.width = w; 296 cx->params.width = w;
225 cx->params.height = h; 297 cx->params.height = h;
226 cx18_av_cmd(cx, VIDIOC_S_FMT, fmt); 298 v4l2_subdev_call(cx->sd_av, video, s_fmt, fmt);
227 return cx18_g_fmt_vid_cap(file, fh, fmt); 299 return cx18_g_fmt_vid_cap(file, fh, fmt);
228} 300}
229 301
@@ -238,54 +310,131 @@ static int cx18_s_fmt_vbi_cap(struct file *file, void *fh,
238 if (ret) 310 if (ret)
239 return ret; 311 return ret;
240 312
313 /*
314 * Changing the Encoder's Raw VBI parameters won't have any effect
315 * if any analog capture is ongoing
316 */
241 if (!cx18_raw_vbi(cx) && atomic_read(&cx->ana_capturing) > 0) 317 if (!cx18_raw_vbi(cx) && atomic_read(&cx->ana_capturing) > 0)
242 return -EBUSY; 318 return -EBUSY;
243 319
320 /*
321 * Set the digitizer registers for raw active VBI.
322 * Note cx18_av_vbi_wipes out alot of the passed in fmt under valid
323 * calling conditions
324 */
325 ret = v4l2_subdev_call(cx->sd_av, video, s_fmt, fmt);
326 if (ret)
327 return ret;
328
329 /* Store our new v4l2 (non-)sliced VBI state */
244 cx->vbi.sliced_in->service_set = 0; 330 cx->vbi.sliced_in->service_set = 0;
245 cx->vbi.in.type = V4L2_BUF_TYPE_VBI_CAPTURE; 331 cx->vbi.in.type = V4L2_BUF_TYPE_VBI_CAPTURE;
246 cx18_av_cmd(cx, VIDIOC_S_FMT, fmt); 332
247 return cx18_g_fmt_vbi_cap(file, fh, fmt); 333 return cx18_g_fmt_vbi_cap(file, fh, fmt);
248} 334}
249 335
250static int cx18_s_fmt_sliced_vbi_cap(struct file *file, void *fh, 336static int cx18_s_fmt_sliced_vbi_cap(struct file *file, void *fh,
251 struct v4l2_format *fmt) 337 struct v4l2_format *fmt)
252{ 338{
253 return -EINVAL; 339 struct cx18_open_id *id = fh;
340 struct cx18 *cx = id->cx;
341 int ret;
342 struct v4l2_sliced_vbi_format *vbifmt = &fmt->fmt.sliced;
343
344 ret = v4l2_prio_check(&cx->prio, &id->prio);
345 if (ret)
346 return ret;
347
348 cx18_try_fmt_sliced_vbi_cap(file, fh, fmt);
349
350 /*
351 * Changing the Encoder's Raw VBI parameters won't have any effect
352 * if any analog capture is ongoing
353 */
354 if (cx18_raw_vbi(cx) && atomic_read(&cx->ana_capturing) > 0)
355 return -EBUSY;
356
357 /*
358 * Set the service_lines requested in the digitizer/slicer registers.
359 * Note, cx18_av_vbi() wipes some "impossible" service lines in the
360 * passed in fmt->fmt.sliced under valid calling conditions
361 */
362 ret = v4l2_subdev_call(cx->sd_av, video, s_fmt, fmt);
363 if (ret)
364 return ret;
365 /* Store our current v4l2 sliced VBI settings */
366 cx->vbi.in.type = V4L2_BUF_TYPE_SLICED_VBI_CAPTURE;
367 memcpy(cx->vbi.sliced_in, vbifmt, sizeof(*cx->vbi.sliced_in));
368 return 0;
254} 369}
255 370
256static int cx18_g_chip_ident(struct file *file, void *fh, 371static int cx18_g_chip_ident(struct file *file, void *fh,
257 struct v4l2_dbg_chip_ident *chip) 372 struct v4l2_dbg_chip_ident *chip)
258{ 373{
259 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx; 374 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
375 int err = 0;
260 376
261 chip->ident = V4L2_IDENT_NONE; 377 chip->ident = V4L2_IDENT_NONE;
262 chip->revision = 0; 378 chip->revision = 0;
263 if (v4l2_chip_match_host(&chip->match)) { 379 switch (chip->match.type) {
264 chip->ident = V4L2_IDENT_CX23418; 380 case V4L2_CHIP_MATCH_HOST:
265 return 0; 381 switch (chip->match.addr) {
382 case 0:
383 chip->ident = V4L2_IDENT_CX23418;
384 chip->revision = cx18_read_reg(cx, 0xC72028);
385 break;
386 case 1:
387 /*
388 * The A/V decoder is always present, but in the rare
389 * case that the card doesn't have analog, we don't
390 * use it. We find it w/o using the cx->sd_av pointer
391 */
392 cx18_call_hw(cx, CX18_HW_418_AV,
393 core, g_chip_ident, chip);
394 break;
395 default:
396 /*
397 * Could return ident = V4L2_IDENT_UNKNOWN if we had
398 * other host chips at higher addresses, but we don't
399 */
400 err = -EINVAL; /* per V4L2 spec */
401 break;
402 }
403 break;
404 case V4L2_CHIP_MATCH_I2C_DRIVER:
405 /* If needed, returns V4L2_IDENT_AMBIGUOUS without extra work */
406 cx18_call_all(cx, core, g_chip_ident, chip);
407 break;
408 case V4L2_CHIP_MATCH_I2C_ADDR:
409 /*
410 * We could return V4L2_IDENT_UNKNOWN, but we don't do the work
411 * to look if a chip is at the address with no driver. That's a
412 * dangerous thing to do with EEPROMs anyway.
413 */
414 cx18_call_all(cx, core, g_chip_ident, chip);
415 break;
416 default:
417 err = -EINVAL;
418 break;
266 } 419 }
267 cx18_call_i2c_clients(cx, VIDIOC_DBG_G_CHIP_IDENT, chip); 420 return err;
268 return 0;
269} 421}
270 422
271#ifdef CONFIG_VIDEO_ADV_DEBUG 423#ifdef CONFIG_VIDEO_ADV_DEBUG
272static int cx18_cxc(struct cx18 *cx, unsigned int cmd, void *arg) 424static int cx18_cxc(struct cx18 *cx, unsigned int cmd, void *arg)
273{ 425{
274 struct v4l2_dbg_register *regs = arg; 426 struct v4l2_dbg_register *regs = arg;
275 unsigned long flags;
276 427
277 if (!capable(CAP_SYS_ADMIN)) 428 if (!capable(CAP_SYS_ADMIN))
278 return -EPERM; 429 return -EPERM;
279 if (regs->reg >= CX18_MEM_OFFSET + CX18_MEM_SIZE) 430 if (regs->reg >= CX18_MEM_OFFSET + CX18_MEM_SIZE)
280 return -EINVAL; 431 return -EINVAL;
281 432
282 spin_lock_irqsave(&cx18_cards_lock, flags);
283 regs->size = 4; 433 regs->size = 4;
284 if (cmd == VIDIOC_DBG_G_REGISTER) 434 if (cmd == VIDIOC_DBG_S_REGISTER)
285 regs->val = cx18_read_enc(cx, regs->reg);
286 else
287 cx18_write_enc(cx, regs->val, regs->reg); 435 cx18_write_enc(cx, regs->val, regs->reg);
288 spin_unlock_irqrestore(&cx18_cards_lock, flags); 436 else
437 regs->val = cx18_read_enc(cx, regs->reg);
289 return 0; 438 return 0;
290} 439}
291 440
@@ -296,7 +445,8 @@ static int cx18_g_register(struct file *file, void *fh,
296 445
297 if (v4l2_chip_match_host(&reg->match)) 446 if (v4l2_chip_match_host(&reg->match))
298 return cx18_cxc(cx, VIDIOC_DBG_G_REGISTER, reg); 447 return cx18_cxc(cx, VIDIOC_DBG_G_REGISTER, reg);
299 cx18_call_i2c_clients(cx, VIDIOC_DBG_G_REGISTER, reg); 448 /* FIXME - errors shouldn't be ignored */
449 cx18_call_all(cx, core, g_register, reg);
300 return 0; 450 return 0;
301} 451}
302 452
@@ -307,7 +457,8 @@ static int cx18_s_register(struct file *file, void *fh,
307 457
308 if (v4l2_chip_match_host(&reg->match)) 458 if (v4l2_chip_match_host(&reg->match))
309 return cx18_cxc(cx, VIDIOC_DBG_S_REGISTER, reg); 459 return cx18_cxc(cx, VIDIOC_DBG_S_REGISTER, reg);
310 cx18_call_i2c_clients(cx, VIDIOC_DBG_S_REGISTER, reg); 460 /* FIXME - errors shouldn't be ignored */
461 cx18_call_all(cx, core, s_register, reg);
311 return 0; 462 return 0;
312} 463}
313#endif 464#endif
@@ -335,7 +486,8 @@ static int cx18_querycap(struct file *file, void *fh,
335 486
336 strlcpy(vcap->driver, CX18_DRIVER_NAME, sizeof(vcap->driver)); 487 strlcpy(vcap->driver, CX18_DRIVER_NAME, sizeof(vcap->driver));
337 strlcpy(vcap->card, cx->card_name, sizeof(vcap->card)); 488 strlcpy(vcap->card, cx->card_name, sizeof(vcap->card));
338 snprintf(vcap->bus_info, sizeof(vcap->bus_info), "PCI:%s", pci_name(cx->dev)); 489 snprintf(vcap->bus_info, sizeof(vcap->bus_info),
490 "PCI:%s", pci_name(cx->pci_dev));
339 vcap->version = CX18_DRIVER_VERSION; /* version */ 491 vcap->version = CX18_DRIVER_VERSION; /* version */
340 vcap->capabilities = cx->v4l2_cap; /* capabilities */ 492 vcap->capabilities = cx->v4l2_cap; /* capabilities */
341 return 0; 493 return 0;
@@ -403,7 +555,8 @@ static int cx18_s_crop(struct file *file, void *fh, struct v4l2_crop *crop)
403 555
404 if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 556 if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
405 return -EINVAL; 557 return -EINVAL;
406 return cx18_av_cmd(cx, VIDIOC_S_CROP, crop); 558 CX18_DEBUG_WARN("VIDIOC_S_CROP not implemented\n");
559 return -EINVAL;
407} 560}
408 561
409static int cx18_g_crop(struct file *file, void *fh, struct v4l2_crop *crop) 562static int cx18_g_crop(struct file *file, void *fh, struct v4l2_crop *crop)
@@ -412,7 +565,8 @@ static int cx18_g_crop(struct file *file, void *fh, struct v4l2_crop *crop)
412 565
413 if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 566 if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
414 return -EINVAL; 567 return -EINVAL;
415 return cx18_av_cmd(cx, VIDIOC_G_CROP, crop); 568 CX18_DEBUG_WARN("VIDIOC_G_CROP not implemented\n");
569 return -EINVAL;
416} 570}
417 571
418static int cx18_enum_fmt_vid_cap(struct file *file, void *fh, 572static int cx18_enum_fmt_vid_cap(struct file *file, void *fh,
@@ -483,7 +637,7 @@ static int cx18_g_frequency(struct file *file, void *fh,
483 if (vf->tuner != 0) 637 if (vf->tuner != 0)
484 return -EINVAL; 638 return -EINVAL;
485 639
486 cx18_call_i2c_clients(cx, VIDIOC_G_FREQUENCY, vf); 640 cx18_call_all(cx, tuner, g_frequency, vf);
487 return 0; 641 return 0;
488} 642}
489 643
@@ -502,7 +656,7 @@ int cx18_s_frequency(struct file *file, void *fh, struct v4l2_frequency *vf)
502 656
503 cx18_mute(cx); 657 cx18_mute(cx);
504 CX18_DEBUG_INFO("v4l2 ioctl: set frequency %d\n", vf->frequency); 658 CX18_DEBUG_INFO("v4l2 ioctl: set frequency %d\n", vf->frequency);
505 cx18_call_i2c_clients(cx, VIDIOC_S_FREQUENCY, vf); 659 cx18_call_all(cx, tuner, s_frequency, vf);
506 cx18_unmute(cx); 660 cx18_unmute(cx);
507 return 0; 661 return 0;
508} 662}
@@ -547,12 +701,11 @@ int cx18_s_std(struct file *file, void *fh, v4l2_std_id *std)
547 cx->vbi.count = cx->is_50hz ? 18 : 12; 701 cx->vbi.count = cx->is_50hz ? 18 : 12;
548 cx->vbi.start[0] = cx->is_50hz ? 6 : 10; 702 cx->vbi.start[0] = cx->is_50hz ? 6 : 10;
549 cx->vbi.start[1] = cx->is_50hz ? 318 : 273; 703 cx->vbi.start[1] = cx->is_50hz ? 318 : 273;
550 cx->vbi.sliced_decoder_line_size = cx->is_60hz ? 272 : 284;
551 CX18_DEBUG_INFO("Switching standard to %llx.\n", 704 CX18_DEBUG_INFO("Switching standard to %llx.\n",
552 (unsigned long long) cx->std); 705 (unsigned long long) cx->std);
553 706
554 /* Tuner */ 707 /* Tuner */
555 cx18_call_i2c_clients(cx, VIDIOC_S_STD, &cx->std); 708 cx18_call_all(cx, tuner, s_std, cx->std);
556 return 0; 709 return 0;
557} 710}
558 711
@@ -569,9 +722,7 @@ static int cx18_s_tuner(struct file *file, void *fh, struct v4l2_tuner *vt)
569 if (vt->index != 0) 722 if (vt->index != 0)
570 return -EINVAL; 723 return -EINVAL;
571 724
572 /* Setting tuner can only set audio mode */ 725 cx18_call_all(cx, tuner, s_tuner, vt);
573 cx18_call_i2c_clients(cx, VIDIOC_S_TUNER, vt);
574
575 return 0; 726 return 0;
576} 727}
577 728
@@ -582,7 +733,7 @@ static int cx18_g_tuner(struct file *file, void *fh, struct v4l2_tuner *vt)
582 if (vt->index != 0) 733 if (vt->index != 0)
583 return -EINVAL; 734 return -EINVAL;
584 735
585 cx18_call_i2c_clients(cx, VIDIOC_G_TUNER, vt); 736 cx18_call_all(cx, tuner, g_tuner, vt);
586 737
587 if (test_bit(CX18_F_I_RADIO_USER, &cx->i_flags)) { 738 if (test_bit(CX18_F_I_RADIO_USER, &cx->i_flags)) {
588 strlcpy(vt->name, "cx18 Radio Tuner", sizeof(vt->name)); 739 strlcpy(vt->name, "cx18 Radio Tuner", sizeof(vt->name));
@@ -598,7 +749,30 @@ static int cx18_g_tuner(struct file *file, void *fh, struct v4l2_tuner *vt)
598static int cx18_g_sliced_vbi_cap(struct file *file, void *fh, 749static int cx18_g_sliced_vbi_cap(struct file *file, void *fh,
599 struct v4l2_sliced_vbi_cap *cap) 750 struct v4l2_sliced_vbi_cap *cap)
600{ 751{
601 return -EINVAL; 752 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
753 int set = cx->is_50hz ? V4L2_SLICED_VBI_625 : V4L2_SLICED_VBI_525;
754 int f, l;
755
756 if (cap->type != V4L2_BUF_TYPE_SLICED_VBI_CAPTURE)
757 return -EINVAL;
758
759 cap->service_set = 0;
760 for (f = 0; f < 2; f++) {
761 for (l = 0; l < 24; l++) {
762 if (valid_service_line(f, l, cx->is_50hz)) {
763 /*
764 * We can find all v4l2 supported vbi services
765 * for the standard, on a valid line for the std
766 */
767 cap->service_lines[f][l] = set;
768 cap->service_set |= set;
769 } else
770 cap->service_lines[f][l] = 0;
771 }
772 }
773 for (f = 0; f < 3; f++)
774 cap->reserved[f] = 0;
775 return 0;
602} 776}
603 777
604static int cx18_g_enc_index(struct file *file, void *fh, 778static int cx18_g_enc_index(struct file *file, void *fh,
@@ -708,13 +882,15 @@ static int cx18_log_status(struct file *file, void *fh)
708 struct v4l2_audio audin; 882 struct v4l2_audio audin;
709 int i; 883 int i;
710 884
711 CX18_INFO("================= START STATUS CARD #%d =================\n", cx->num); 885 CX18_INFO("================= START STATUS CARD #%d "
886 "=================\n", cx->instance);
887 CX18_INFO("Version: %s Card: %s\n", CX18_VERSION, cx->card_name);
712 if (cx->hw_flags & CX18_HW_TVEEPROM) { 888 if (cx->hw_flags & CX18_HW_TVEEPROM) {
713 struct tveeprom tv; 889 struct tveeprom tv;
714 890
715 cx18_read_eeprom(cx, &tv); 891 cx18_read_eeprom(cx, &tv);
716 } 892 }
717 cx18_call_i2c_clients(cx, VIDIOC_LOG_STATUS, NULL); 893 cx18_call_all(cx, core, log_status);
718 cx18_get_input(cx, cx->active_input, &vidin); 894 cx18_get_input(cx, cx->active_input, &vidin);
719 cx18_get_audio_input(cx, cx->audio_input, &audin); 895 cx18_get_audio_input(cx, cx->audio_input, &audin);
720 CX18_INFO("Video Input: %s\n", vidin.name); 896 CX18_INFO("Video Input: %s\n", vidin.name);
@@ -725,12 +901,12 @@ static int cx18_log_status(struct file *file, void *fh)
725 mutex_unlock(&cx->gpio_lock); 901 mutex_unlock(&cx->gpio_lock);
726 CX18_INFO("Tuner: %s\n", 902 CX18_INFO("Tuner: %s\n",
727 test_bit(CX18_F_I_RADIO_USER, &cx->i_flags) ? "Radio" : "TV"); 903 test_bit(CX18_F_I_RADIO_USER, &cx->i_flags) ? "Radio" : "TV");
728 cx2341x_log_status(&cx->params, cx->name); 904 cx2341x_log_status(&cx->params, cx->v4l2_dev.name);
729 CX18_INFO("Status flags: 0x%08lx\n", cx->i_flags); 905 CX18_INFO("Status flags: 0x%08lx\n", cx->i_flags);
730 for (i = 0; i < CX18_MAX_STREAMS; i++) { 906 for (i = 0; i < CX18_MAX_STREAMS; i++) {
731 struct cx18_stream *s = &cx->streams[i]; 907 struct cx18_stream *s = &cx->streams[i];
732 908
733 if (s->v4l2dev == NULL || s->buffers == 0) 909 if (s->video_dev == NULL || s->buffers == 0)
734 continue; 910 continue;
735 CX18_INFO("Stream %s: status 0x%04lx, %d%% of %d KiB (%d buffers) in use\n", 911 CX18_INFO("Stream %s: status 0x%04lx, %d%% of %d KiB (%d buffers) in use\n",
736 s->name, s->s_flags, 912 s->name, s->s_flags,
@@ -740,7 +916,8 @@ static int cx18_log_status(struct file *file, void *fh)
740 CX18_INFO("Read MPEG/VBI: %lld/%lld bytes\n", 916 CX18_INFO("Read MPEG/VBI: %lld/%lld bytes\n",
741 (long long)cx->mpg_data_received, 917 (long long)cx->mpg_data_received,
742 (long long)cx->vbi_data_inserted); 918 (long long)cx->vbi_data_inserted);
743 CX18_INFO("================== END STATUS CARD #%d ==================\n", cx->num); 919 CX18_INFO("================== END STATUS CARD #%d "
920 "==================\n", cx->instance);
744 return 0; 921 return 0;
745} 922}
746 923
@@ -754,7 +931,8 @@ static long cx18_default(struct file *file, void *fh, int cmd, void *arg)
754 931
755 CX18_DEBUG_IOCTL("VIDIOC_INT_S_AUDIO_ROUTING(%d, %d)\n", 932 CX18_DEBUG_IOCTL("VIDIOC_INT_S_AUDIO_ROUTING(%d, %d)\n",
756 route->input, route->output); 933 route->input, route->output);
757 cx18_audio_set_route(cx, route); 934 cx18_call_hw(cx, cx->card->hw_audio_ctrl, audio, s_routing,
935 route);
758 break; 936 break;
759 } 937 }
760 938
@@ -762,7 +940,8 @@ static long cx18_default(struct file *file, void *fh, int cmd, void *arg)
762 u32 val = *(u32 *)arg; 940 u32 val = *(u32 *)arg;
763 941
764 if ((val == 0) || (val & 0x01)) 942 if ((val == 0) || (val & 0x01))
765 cx18_reset_ir_gpio(&cx->i2c_algo_cb_data[0]); 943 cx18_call_hw(cx, CX18_HW_GPIO_RESET_CTRL, core, reset,
944 (u32) CX18_GPIO_RESET_Z8F0811);
766 break; 945 break;
767 } 946 }
768 947
@@ -782,6 +961,8 @@ long cx18_v4l2_ioctl(struct file *filp, unsigned int cmd,
782 961
783 mutex_lock(&cx->serialize_lock); 962 mutex_lock(&cx->serialize_lock);
784 963
964 /* FIXME - consolidate v4l2_prio_check()'s here */
965
785 if (cx18_debug & CX18_DBGFLG_IOCTL) 966 if (cx18_debug & CX18_DBGFLG_IOCTL)
786 vfd->debug = V4L2_DEBUG_IOCTL | V4L2_DEBUG_IOCTL_ARG; 967 vfd->debug = V4L2_DEBUG_IOCTL | V4L2_DEBUG_IOCTL_ARG;
787 res = video_ioctl2(filp, cmd, arg); 968 res = video_ioctl2(filp, cmd, arg);
diff --git a/drivers/media/video/cx18/cx18-mailbox.c b/drivers/media/video/cx18/cx18-mailbox.c
index de5e723fdf44..2226e5791e99 100644
--- a/drivers/media/video/cx18/cx18-mailbox.c
+++ b/drivers/media/video/cx18/cx18-mailbox.c
@@ -83,6 +83,8 @@ static const struct cx18_api_info api_info[] = {
83 API_ENTRY(CPU, CX18_CPU_DE_SET_MDL_ACK, 0), 83 API_ENTRY(CPU, CX18_CPU_DE_SET_MDL_ACK, 0),
84 API_ENTRY(CPU, CX18_CPU_DE_SET_MDL, API_FAST), 84 API_ENTRY(CPU, CX18_CPU_DE_SET_MDL, API_FAST),
85 API_ENTRY(CPU, CX18_CPU_DE_RELEASE_MDL, API_SLOW), 85 API_ENTRY(CPU, CX18_CPU_DE_RELEASE_MDL, API_SLOW),
86 API_ENTRY(APU, CX18_APU_START, 0),
87 API_ENTRY(APU, CX18_APU_STOP, 0),
86 API_ENTRY(APU, CX18_APU_RESETAI, 0), 88 API_ENTRY(APU, CX18_APU_RESETAI, 0),
87 API_ENTRY(CPU, CX18_CPU_DEBUG_PEEK32, 0), 89 API_ENTRY(CPU, CX18_CPU_DEBUG_PEEK32, 0),
88 API_ENTRY(0, 0, 0), 90 API_ENTRY(0, 0, 0),
@@ -98,21 +100,30 @@ static const struct cx18_api_info *find_api_info(u32 cmd)
98 return NULL; 100 return NULL;
99} 101}
100 102
101static void dump_mb(struct cx18 *cx, struct cx18_mailbox *mb, char *name) 103/* Call with buf of n*11+1 bytes */
104static char *u32arr2hex(u32 data[], int n, char *buf)
102{ 105{
103 char argstr[MAX_MB_ARGUMENTS*11+1];
104 char *p; 106 char *p;
105 int i; 107 int i;
106 108
109 for (i = 0, p = buf; i < n; i++, p += 11) {
110 /* kernel snprintf() appends '\0' always */
111 snprintf(p, 12, " %#010x", data[i]);
112 }
113 *p = '\0';
114 return buf;
115}
116
117static void dump_mb(struct cx18 *cx, struct cx18_mailbox *mb, char *name)
118{
119 char argstr[MAX_MB_ARGUMENTS*11+1];
120
107 if (!(cx18_debug & CX18_DBGFLG_API)) 121 if (!(cx18_debug & CX18_DBGFLG_API))
108 return; 122 return;
109 123
110 for (i = 0, p = argstr; i < MAX_MB_ARGUMENTS; i++, p += 11) {
111 /* kernel snprintf() appends '\0' always */
112 snprintf(p, 12, " %#010x", mb->args[i]);
113 }
114 CX18_DEBUG_API("%s: req %#010x ack %#010x cmd %#010x err %#010x args%s" 124 CX18_DEBUG_API("%s: req %#010x ack %#010x cmd %#010x err %#010x args%s"
115 "\n", name, mb->request, mb->ack, mb->cmd, mb->error, argstr); 125 "\n", name, mb->request, mb->ack, mb->cmd, mb->error,
126 u32arr2hex(mb->args, MAX_MB_ARGUMENTS, argstr));
116} 127}
117 128
118 129
@@ -439,7 +450,8 @@ void cx18_api_epu_cmd_irq(struct cx18 *cx, int rpu)
439 "incoming %s to EPU mailbox (sequence no. %u)" 450 "incoming %s to EPU mailbox (sequence no. %u)"
440 "\n", 451 "\n",
441 rpu_str[rpu], rpu_str[rpu], order_mb->request); 452 rpu_str[rpu], rpu_str[rpu], order_mb->request);
442 dump_mb(cx, order_mb, "incoming"); 453 if (cx18_debug & CX18_DBGFLG_WARN)
454 dump_mb(cx, order_mb, "incoming");
443 order->flags = CX18_F_EWO_MB_STALE_UPON_RECEIPT; 455 order->flags = CX18_F_EWO_MB_STALE_UPON_RECEIPT;
444 } 456 }
445 457
@@ -468,16 +480,24 @@ static int cx18_api_call(struct cx18 *cx, u32 cmd, int args, u32 data[])
468 struct mutex *mb_lock; 480 struct mutex *mb_lock;
469 long int timeout, ret; 481 long int timeout, ret;
470 int i; 482 int i;
483 char argstr[MAX_MB_ARGUMENTS*11+1];
471 484
472 if (info == NULL) { 485 if (info == NULL) {
473 CX18_WARN("unknown cmd %x\n", cmd); 486 CX18_WARN("unknown cmd %x\n", cmd);
474 return -EINVAL; 487 return -EINVAL;
475 } 488 }
476 489
477 if (cmd == CX18_CPU_DE_SET_MDL) 490 if (cx18_debug & CX18_DBGFLG_API) { /* only call u32arr2hex if needed */
478 CX18_DEBUG_HI_API("%s\n", info->name); 491 if (cmd == CX18_CPU_DE_SET_MDL) {
479 else 492 if (cx18_debug & CX18_DBGFLG_HIGHVOL)
480 CX18_DEBUG_API("%s\n", info->name); 493 CX18_DEBUG_HI_API("%s\tcmd %#010x args%s\n",
494 info->name, cmd,
495 u32arr2hex(data, args, argstr));
496 } else
497 CX18_DEBUG_API("%s\tcmd %#010x args%s\n",
498 info->name, cmd,
499 u32arr2hex(data, args, argstr));
500 }
481 501
482 switch (info->rpu) { 502 switch (info->rpu) {
483 case APU: 503 case APU:
diff --git a/drivers/media/video/cx18/cx18-queue.c b/drivers/media/video/cx18/cx18-queue.c
index 8d9441e88c4e..3046b8e74345 100644
--- a/drivers/media/video/cx18/cx18-queue.c
+++ b/drivers/media/video/cx18/cx18-queue.c
@@ -204,7 +204,7 @@ int cx18_stream_alloc(struct cx18_stream *s)
204 } 204 }
205 buf->id = cx->buffer_id++; 205 buf->id = cx->buffer_id++;
206 INIT_LIST_HEAD(&buf->list); 206 INIT_LIST_HEAD(&buf->list);
207 buf->dma_handle = pci_map_single(s->cx->dev, 207 buf->dma_handle = pci_map_single(s->cx->pci_dev,
208 buf->buf, s->buf_size, s->dma); 208 buf->buf, s->buf_size, s->dma);
209 cx18_buf_sync_for_cpu(s, buf); 209 cx18_buf_sync_for_cpu(s, buf);
210 cx18_enqueue(s, buf, &s->q_free); 210 cx18_enqueue(s, buf, &s->q_free);
@@ -227,7 +227,7 @@ void cx18_stream_free(struct cx18_stream *s)
227 227
228 /* empty q_free */ 228 /* empty q_free */
229 while ((buf = cx18_dequeue(s, &s->q_free))) { 229 while ((buf = cx18_dequeue(s, &s->q_free))) {
230 pci_unmap_single(s->cx->dev, buf->dma_handle, 230 pci_unmap_single(s->cx->pci_dev, buf->dma_handle,
231 s->buf_size, s->dma); 231 s->buf_size, s->dma);
232 kfree(buf->buf); 232 kfree(buf->buf);
233 kfree(buf); 233 kfree(buf);
diff --git a/drivers/media/video/cx18/cx18-queue.h b/drivers/media/video/cx18/cx18-queue.h
index 456cec3bc28f..4de06269d88f 100644
--- a/drivers/media/video/cx18/cx18-queue.h
+++ b/drivers/media/video/cx18/cx18-queue.h
@@ -29,14 +29,14 @@
29static inline void cx18_buf_sync_for_cpu(struct cx18_stream *s, 29static inline void cx18_buf_sync_for_cpu(struct cx18_stream *s,
30 struct cx18_buffer *buf) 30 struct cx18_buffer *buf)
31{ 31{
32 pci_dma_sync_single_for_cpu(s->cx->dev, buf->dma_handle, 32 pci_dma_sync_single_for_cpu(s->cx->pci_dev, buf->dma_handle,
33 s->buf_size, s->dma); 33 s->buf_size, s->dma);
34} 34}
35 35
36static inline void cx18_buf_sync_for_device(struct cx18_stream *s, 36static inline void cx18_buf_sync_for_device(struct cx18_stream *s,
37 struct cx18_buffer *buf) 37 struct cx18_buffer *buf)
38{ 38{
39 pci_dma_sync_single_for_device(s->cx->dev, buf->dma_handle, 39 pci_dma_sync_single_for_device(s->cx->pci_dev, buf->dma_handle,
40 s->buf_size, s->dma); 40 s->buf_size, s->dma);
41} 41}
42 42
diff --git a/drivers/media/video/cx18/cx18-streams.c b/drivers/media/video/cx18/cx18-streams.c
index 89c1ec94f335..0932b76b2373 100644
--- a/drivers/media/video/cx18/cx18-streams.c
+++ b/drivers/media/video/cx18/cx18-streams.c
@@ -32,7 +32,6 @@
32#include "cx18-streams.h" 32#include "cx18-streams.h"
33#include "cx18-cards.h" 33#include "cx18-cards.h"
34#include "cx18-scb.h" 34#include "cx18-scb.h"
35#include "cx18-av-core.h"
36#include "cx18-dvb.h" 35#include "cx18-dvb.h"
37 36
38#define CX18_DSP0_INTERRUPT_MASK 0xd0004C 37#define CX18_DSP0_INTERRUPT_MASK 0xd0004C
@@ -101,11 +100,11 @@ static struct {
101static void cx18_stream_init(struct cx18 *cx, int type) 100static void cx18_stream_init(struct cx18 *cx, int type)
102{ 101{
103 struct cx18_stream *s = &cx->streams[type]; 102 struct cx18_stream *s = &cx->streams[type];
104 struct video_device *dev = s->v4l2dev; 103 struct video_device *video_dev = s->video_dev;
105 104
106 /* we need to keep v4l2dev, so restore it afterwards */ 105 /* we need to keep video_dev, so restore it afterwards */
107 memset(s, 0, sizeof(*s)); 106 memset(s, 0, sizeof(*s));
108 s->v4l2dev = dev; 107 s->video_dev = video_dev;
109 108
110 /* initialize cx18_stream fields */ 109 /* initialize cx18_stream fields */
111 s->cx = cx; 110 s->cx = cx;
@@ -130,12 +129,12 @@ static int cx18_prep_dev(struct cx18 *cx, int type)
130 struct cx18_stream *s = &cx->streams[type]; 129 struct cx18_stream *s = &cx->streams[type];
131 u32 cap = cx->v4l2_cap; 130 u32 cap = cx->v4l2_cap;
132 int num_offset = cx18_stream_info[type].num_offset; 131 int num_offset = cx18_stream_info[type].num_offset;
133 int num = cx->num + cx18_first_minor + num_offset; 132 int num = cx->instance + cx18_first_minor + num_offset;
134 133
135 /* These four fields are always initialized. If v4l2dev == NULL, then 134 /* These four fields are always initialized. If video_dev == NULL, then
136 this stream is not in use. In that case no other fields but these 135 this stream is not in use. In that case no other fields but these
137 four can be used. */ 136 four can be used. */
138 s->v4l2dev = NULL; 137 s->video_dev = NULL;
139 s->cx = cx; 138 s->cx = cx;
140 s->type = type; 139 s->type = type;
141 s->name = cx18_stream_info[type].name; 140 s->name = cx18_stream_info[type].name;
@@ -163,22 +162,22 @@ static int cx18_prep_dev(struct cx18 *cx, int type)
163 return 0; 162 return 0;
164 163
165 /* allocate and initialize the v4l2 video device structure */ 164 /* allocate and initialize the v4l2 video device structure */
166 s->v4l2dev = video_device_alloc(); 165 s->video_dev = video_device_alloc();
167 if (s->v4l2dev == NULL) { 166 if (s->video_dev == NULL) {
168 CX18_ERR("Couldn't allocate v4l2 video_device for %s\n", 167 CX18_ERR("Couldn't allocate v4l2 video_device for %s\n",
169 s->name); 168 s->name);
170 return -ENOMEM; 169 return -ENOMEM;
171 } 170 }
172 171
173 snprintf(s->v4l2dev->name, sizeof(s->v4l2dev->name), "cx18-%d", 172 snprintf(s->video_dev->name, sizeof(s->video_dev->name), "%s %s",
174 cx->num); 173 cx->v4l2_dev.name, s->name);
175 174
176 s->v4l2dev->num = num; 175 s->video_dev->num = num;
177 s->v4l2dev->parent = &cx->dev->dev; 176 s->video_dev->v4l2_dev = &cx->v4l2_dev;
178 s->v4l2dev->fops = &cx18_v4l2_enc_fops; 177 s->video_dev->fops = &cx18_v4l2_enc_fops;
179 s->v4l2dev->release = video_device_release; 178 s->video_dev->release = video_device_release;
180 s->v4l2dev->tvnorms = V4L2_STD_ALL; 179 s->video_dev->tvnorms = V4L2_STD_ALL;
181 cx18_set_funcs(s->v4l2dev); 180 cx18_set_funcs(s->video_dev);
182 return 0; 181 return 0;
183} 182}
184 183
@@ -227,28 +226,30 @@ static int cx18_reg_dev(struct cx18 *cx, int type)
227 } 226 }
228 } 227 }
229 228
230 if (s->v4l2dev == NULL) 229 if (s->video_dev == NULL)
231 return 0; 230 return 0;
232 231
233 num = s->v4l2dev->num; 232 num = s->video_dev->num;
234 /* card number + user defined offset + device offset */ 233 /* card number + user defined offset + device offset */
235 if (type != CX18_ENC_STREAM_TYPE_MPG) { 234 if (type != CX18_ENC_STREAM_TYPE_MPG) {
236 struct cx18_stream *s_mpg = &cx->streams[CX18_ENC_STREAM_TYPE_MPG]; 235 struct cx18_stream *s_mpg = &cx->streams[CX18_ENC_STREAM_TYPE_MPG];
237 236
238 if (s_mpg->v4l2dev) 237 if (s_mpg->video_dev)
239 num = s_mpg->v4l2dev->num + cx18_stream_info[type].num_offset; 238 num = s_mpg->video_dev->num
239 + cx18_stream_info[type].num_offset;
240 } 240 }
241 video_set_drvdata(s->video_dev, s);
241 242
242 /* Register device. First try the desired minor, then any free one. */ 243 /* Register device. First try the desired minor, then any free one. */
243 ret = video_register_device(s->v4l2dev, vfl_type, num); 244 ret = video_register_device(s->video_dev, vfl_type, num);
244 if (ret < 0) { 245 if (ret < 0) {
245 CX18_ERR("Couldn't register v4l2 device for %s kernel number %d\n", 246 CX18_ERR("Couldn't register v4l2 device for %s kernel number %d\n",
246 s->name, num); 247 s->name, num);
247 video_device_release(s->v4l2dev); 248 video_device_release(s->video_dev);
248 s->v4l2dev = NULL; 249 s->video_dev = NULL;
249 return ret; 250 return ret;
250 } 251 }
251 num = s->v4l2dev->num; 252 num = s->video_dev->num;
252 253
253 switch (vfl_type) { 254 switch (vfl_type) {
254 case VFL_TYPE_GRABBER: 255 case VFL_TYPE_GRABBER:
@@ -312,9 +313,9 @@ void cx18_streams_cleanup(struct cx18 *cx, int unregister)
312 cx->streams[type].dvb.enabled = false; 313 cx->streams[type].dvb.enabled = false;
313 } 314 }
314 315
315 vdev = cx->streams[type].v4l2dev; 316 vdev = cx->streams[type].video_dev;
316 317
317 cx->streams[type].v4l2dev = NULL; 318 cx->streams[type].video_dev = NULL;
318 if (vdev == NULL) 319 if (vdev == NULL)
319 continue; 320 continue;
320 321
@@ -346,46 +347,88 @@ static void cx18_vbi_setup(struct cx18_stream *s)
346 } 347 }
347 348
348 /* setup VBI registers */ 349 /* setup VBI registers */
349 cx18_av_cmd(cx, VIDIOC_S_FMT, &cx->vbi.in); 350 v4l2_subdev_call(cx->sd_av, video, s_fmt, &cx->vbi.in);
350 351
351 /* determine number of lines and total number of VBI bytes. 352 /*
352 A raw line takes 1444 bytes: 4 byte SAV code + 2 * 720 353 * Send the CX18_CPU_SET_RAW_VBI_PARAM API command to setup Encoder Raw
353 A sliced line takes 51 bytes: 4 byte frame header, 4 byte internal 354 * VBI when the first analog capture channel starts, as once it starts
354 header, 42 data bytes + checksum (to be confirmed) */ 355 * (e.g. MPEG), we can't effect any change in the Encoder Raw VBI setup
356 * (i.e. for the VBI capture channels). We also send it for each
357 * analog capture channel anyway just to make sure we get the proper
358 * behavior
359 */
355 if (raw) { 360 if (raw) {
356 lines = cx->vbi.count * 2; 361 lines = cx->vbi.count * 2;
357 } else { 362 } else {
358 lines = cx->is_60hz ? 24 : 38; 363 /*
359 if (cx->is_60hz) 364 * For 525/60 systems, according to the VIP 2 & BT.656 std:
360 lines += 2; 365 * The EAV RP code's Field bit toggles on line 4, a few lines
366 * after the Vertcal Blank bit has already toggled.
367 * Tell the encoder to capture 21-4+1=18 lines per field,
368 * since we want lines 10 through 21.
369 *
370 * FIXME - revisit for 625/50 systems
371 */
372 lines = cx->is_60hz ? (21 - 4 + 1) * 2 : 38;
361 } 373 }
362 374
363 cx->vbi.enc_size = lines *
364 (raw ? cx->vbi.raw_size : cx->vbi.sliced_size);
365
366 data[0] = s->handle; 375 data[0] = s->handle;
367 /* Lines per field */ 376 /* Lines per field */
368 data[1] = (lines / 2) | ((lines / 2) << 16); 377 data[1] = (lines / 2) | ((lines / 2) << 16);
369 /* bytes per line */ 378 /* bytes per line */
370 data[2] = (raw ? cx->vbi.raw_decoder_line_size 379 data[2] = (raw ? vbi_active_samples
371 : cx->vbi.sliced_decoder_line_size); 380 : (cx->is_60hz ? vbi_hblank_samples_60Hz
381 : vbi_hblank_samples_50Hz));
372 /* Every X number of frames a VBI interrupt arrives 382 /* Every X number of frames a VBI interrupt arrives
373 (frames as in 25 or 30 fps) */ 383 (frames as in 25 or 30 fps) */
374 data[3] = 1; 384 data[3] = 1;
375 /* Setup VBI for the cx25840 digitizer */ 385 /*
386 * Set the SAV/EAV RP codes to look for as start/stop points
387 * when in VIP-1.1 mode
388 */
376 if (raw) { 389 if (raw) {
390 /*
391 * Start codes for beginning of "active" line in vertical blank
392 * 0x20 ( VerticalBlank )
393 * 0x60 ( EvenField VerticalBlank )
394 */
377 data[4] = 0x20602060; 395 data[4] = 0x20602060;
396 /*
397 * End codes for end of "active" raw lines and regular lines
398 * 0x30 ( VerticalBlank HorizontalBlank)
399 * 0x70 ( EvenField VerticalBlank HorizontalBlank)
400 * 0x90 (Task HorizontalBlank)
401 * 0xd0 (Task EvenField HorizontalBlank)
402 */
378 data[5] = 0x307090d0; 403 data[5] = 0x307090d0;
379 } else { 404 } else {
405 /*
406 * End codes for active video, we want data in the hblank region
407 * 0xb0 (Task 0 VerticalBlank HorizontalBlank)
408 * 0xf0 (Task EvenField VerticalBlank HorizontalBlank)
409 *
410 * Since the V bit is only allowed to toggle in the EAV RP code,
411 * just before the first active region line, these two
412 * are problematic:
413 * 0x90 (Task HorizontalBlank)
414 * 0xd0 (Task EvenField HorizontalBlank)
415 *
416 * We have set the digitzer such that we don't have to worry
417 * about these problem codes.
418 */
380 data[4] = 0xB0F0B0F0; 419 data[4] = 0xB0F0B0F0;
420 /*
421 * Start codes for beginning of active line in vertical blank
422 * 0xa0 (Task VerticalBlank )
423 * 0xe0 (Task EvenField VerticalBlank )
424 */
381 data[5] = 0xA0E0A0E0; 425 data[5] = 0xA0E0A0E0;
382 } 426 }
383 427
384 CX18_DEBUG_INFO("Setup VBI h: %d lines %x bpl %d fr %d %x %x\n", 428 CX18_DEBUG_INFO("Setup VBI h: %d lines %x bpl %d fr %d %x %x\n",
385 data[0], data[1], data[2], data[3], data[4], data[5]); 429 data[0], data[1], data[2], data[3], data[4], data[5]);
386 430
387 if (s->type == CX18_ENC_STREAM_TYPE_VBI) 431 cx18_api(cx, CX18_CPU_SET_RAW_VBI_PARAM, 6, data);
388 cx18_api(cx, CX18_CPU_SET_RAW_VBI_PARAM, 6, data);
389} 432}
390 433
391struct cx18_queue *cx18_stream_put_buf_fw(struct cx18_stream *s, 434struct cx18_queue *cx18_stream_put_buf_fw(struct cx18_stream *s,
@@ -434,10 +477,10 @@ int cx18_start_v4l2_encode_stream(struct cx18_stream *s)
434 u32 data[MAX_MB_ARGUMENTS]; 477 u32 data[MAX_MB_ARGUMENTS];
435 struct cx18 *cx = s->cx; 478 struct cx18 *cx = s->cx;
436 struct cx18_buffer *buf; 479 struct cx18_buffer *buf;
437 int ts = 0;
438 int captype = 0; 480 int captype = 0;
481 struct cx18_api_func_private priv;
439 482
440 if (s->v4l2dev == NULL && s->dvb.enabled == 0) 483 if (s->video_dev == NULL && s->dvb.enabled == 0)
441 return -EINVAL; 484 return -EINVAL;
442 485
443 CX18_DEBUG_INFO("Start encoder stream %s\n", s->name); 486 CX18_DEBUG_INFO("Start encoder stream %s\n", s->name);
@@ -453,7 +496,6 @@ int cx18_start_v4l2_encode_stream(struct cx18_stream *s)
453 496
454 case CX18_ENC_STREAM_TYPE_TS: 497 case CX18_ENC_STREAM_TYPE_TS:
455 captype = CAPTURE_CHANNEL_TYPE_TS; 498 captype = CAPTURE_CHANNEL_TYPE_TS;
456 ts = 1;
457 break; 499 break;
458 case CX18_ENC_STREAM_TYPE_YUV: 500 case CX18_ENC_STREAM_TYPE_YUV:
459 captype = CAPTURE_CHANNEL_TYPE_YUV; 501 captype = CAPTURE_CHANNEL_TYPE_YUV;
@@ -462,8 +504,16 @@ int cx18_start_v4l2_encode_stream(struct cx18_stream *s)
462 captype = CAPTURE_CHANNEL_TYPE_PCM; 504 captype = CAPTURE_CHANNEL_TYPE_PCM;
463 break; 505 break;
464 case CX18_ENC_STREAM_TYPE_VBI: 506 case CX18_ENC_STREAM_TYPE_VBI:
507#ifdef CX18_ENCODER_PARSES_SLICED
465 captype = cx18_raw_vbi(cx) ? 508 captype = cx18_raw_vbi(cx) ?
466 CAPTURE_CHANNEL_TYPE_VBI : CAPTURE_CHANNEL_TYPE_SLICED_VBI; 509 CAPTURE_CHANNEL_TYPE_VBI : CAPTURE_CHANNEL_TYPE_SLICED_VBI;
510#else
511 /*
512 * Currently we set things up so that Sliced VBI from the
513 * digitizer is handled as Raw VBI by the encoder
514 */
515 captype = CAPTURE_CHANNEL_TYPE_VBI;
516#endif
467 cx->vbi.frame = 0; 517 cx->vbi.frame = 0;
468 cx->vbi.inserted_frame = 0; 518 cx->vbi.inserted_frame = 0;
469 memset(cx->vbi.sliced_mpeg_size, 519 memset(cx->vbi.sliced_mpeg_size,
@@ -473,10 +523,6 @@ int cx18_start_v4l2_encode_stream(struct cx18_stream *s)
473 return -EINVAL; 523 return -EINVAL;
474 } 524 }
475 525
476 /* mute/unmute video */
477 cx18_vapi(cx, CX18_CPU_SET_VIDEO_MUTE, 2,
478 s->handle, !!test_bit(CX18_F_I_RADIO_USER, &cx->i_flags));
479
480 /* Clear Streamoff flags in case left from last capture */ 526 /* Clear Streamoff flags in case left from last capture */
481 clear_bit(CX18_F_S_STREAMOFF, &s->s_flags); 527 clear_bit(CX18_F_S_STREAMOFF, &s->s_flags);
482 528
@@ -484,31 +530,63 @@ int cx18_start_v4l2_encode_stream(struct cx18_stream *s)
484 s->handle = data[0]; 530 s->handle = data[0];
485 cx18_vapi(cx, CX18_CPU_SET_CHANNEL_TYPE, 2, s->handle, captype); 531 cx18_vapi(cx, CX18_CPU_SET_CHANNEL_TYPE, 2, s->handle, captype);
486 532
487 if (atomic_read(&cx->ana_capturing) == 0 && !ts) { 533 /*
488 struct cx18_api_func_private priv; 534 * For everything but CAPTURE_CHANNEL_TYPE_TS, play it safe and
489 535 * set up all the parameters, as it is not obvious which parameters the
490 /* Stuff from Windows, we don't know what it is */ 536 * firmware shares across capture channel types and which it does not.
537 *
538 * Some of the cx18_vapi() calls below apply to only certain capture
539 * channel types. We're hoping there's no harm in calling most of them
540 * anyway, as long as the values are all consistent. Setting some
541 * shared parameters will have no effect once an analog capture channel
542 * has started streaming.
543 */
544 if (captype != CAPTURE_CHANNEL_TYPE_TS) {
491 cx18_vapi(cx, CX18_CPU_SET_VER_CROP_LINE, 2, s->handle, 0); 545 cx18_vapi(cx, CX18_CPU_SET_VER_CROP_LINE, 2, s->handle, 0);
492 cx18_vapi(cx, CX18_CPU_SET_MISC_PARAMETERS, 3, s->handle, 3, 1); 546 cx18_vapi(cx, CX18_CPU_SET_MISC_PARAMETERS, 3, s->handle, 3, 1);
493 cx18_vapi(cx, CX18_CPU_SET_MISC_PARAMETERS, 3, s->handle, 8, 0); 547 cx18_vapi(cx, CX18_CPU_SET_MISC_PARAMETERS, 3, s->handle, 8, 0);
494 cx18_vapi(cx, CX18_CPU_SET_MISC_PARAMETERS, 3, s->handle, 4, 1); 548 cx18_vapi(cx, CX18_CPU_SET_MISC_PARAMETERS, 3, s->handle, 4, 1);
495 cx18_vapi(cx, CX18_CPU_SET_MISC_PARAMETERS, 2, s->handle, 12);
496 549
550 /*
551 * Audio related reset according to
552 * Documentation/video4linux/cx2341x/fw-encoder-api.txt
553 */
554 if (atomic_read(&cx->ana_capturing) == 0)
555 cx18_vapi(cx, CX18_CPU_SET_MISC_PARAMETERS, 2,
556 s->handle, 12);
557
558 /*
559 * Number of lines for Field 1 & Field 2 according to
560 * Documentation/video4linux/cx2341x/fw-encoder-api.txt
561 * Field 1 is 312 for 625 line systems in BT.656
562 * Field 2 is 313 for 625 line systems in BT.656
563 */
497 cx18_vapi(cx, CX18_CPU_SET_CAPTURE_LINE_NO, 3, 564 cx18_vapi(cx, CX18_CPU_SET_CAPTURE_LINE_NO, 3,
498 s->handle, cx->digitizer, cx->digitizer); 565 s->handle, 312, 313);
499 566
500 /* Setup VBI */
501 if (cx->v4l2_cap & V4L2_CAP_VBI_CAPTURE) 567 if (cx->v4l2_cap & V4L2_CAP_VBI_CAPTURE)
502 cx18_vbi_setup(s); 568 cx18_vbi_setup(s);
503 569
504 /* assign program index info. 570 /*
505 Mask 7: select I/P/B, Num_req: 400 max */ 571 * assign program index info.
572 * Mask 7: select I/P/B, Num_req: 400 max
573 * FIXME - currently we have this hardcoded as disabled
574 */
506 cx18_vapi_result(cx, data, CX18_CPU_SET_INDEXTABLE, 1, 0); 575 cx18_vapi_result(cx, data, CX18_CPU_SET_INDEXTABLE, 1, 0);
507 576
508 /* Setup API for Stream */ 577 /* Call out to the common CX2341x API setup for user controls */
509 priv.cx = cx; 578 priv.cx = cx;
510 priv.s = s; 579 priv.s = s;
511 cx2341x_update(&priv, cx18_api_func, NULL, &cx->params); 580 cx2341x_update(&priv, cx18_api_func, NULL, &cx->params);
581
582 /*
583 * When starting a capture and we're set for radio,
584 * ensure the video is muted, despite the user control.
585 */
586 if (!cx->params.video_mute &&
587 test_bit(CX18_F_I_RADIO_USER, &cx->i_flags))
588 cx18_vapi(cx, CX18_CPU_SET_VIDEO_MUTE, 2, s->handle,
589 (cx->params.video_mute_yuv << 8) | 1);
512 } 590 }
513 591
514 if (atomic_read(&cx->tot_capturing) == 0) { 592 if (atomic_read(&cx->tot_capturing) == 0) {
@@ -552,7 +630,7 @@ int cx18_start_v4l2_encode_stream(struct cx18_stream *s)
552 } 630 }
553 631
554 /* you're live! sit back and await interrupts :) */ 632 /* you're live! sit back and await interrupts :) */
555 if (!ts) 633 if (captype != CAPTURE_CHANNEL_TYPE_TS)
556 atomic_inc(&cx->ana_capturing); 634 atomic_inc(&cx->ana_capturing);
557 atomic_inc(&cx->tot_capturing); 635 atomic_inc(&cx->tot_capturing);
558 return 0; 636 return 0;
@@ -565,7 +643,7 @@ void cx18_stop_all_captures(struct cx18 *cx)
565 for (i = CX18_MAX_STREAMS - 1; i >= 0; i--) { 643 for (i = CX18_MAX_STREAMS - 1; i >= 0; i--) {
566 struct cx18_stream *s = &cx->streams[i]; 644 struct cx18_stream *s = &cx->streams[i];
567 645
568 if (s->v4l2dev == NULL && s->dvb.enabled == 0) 646 if (s->video_dev == NULL && s->dvb.enabled == 0)
569 continue; 647 continue;
570 if (test_bit(CX18_F_S_STREAMING, &s->s_flags)) 648 if (test_bit(CX18_F_S_STREAMING, &s->s_flags))
571 cx18_stop_v4l2_encode_stream(s, 0); 649 cx18_stop_v4l2_encode_stream(s, 0);
@@ -577,7 +655,7 @@ int cx18_stop_v4l2_encode_stream(struct cx18_stream *s, int gop_end)
577 struct cx18 *cx = s->cx; 655 struct cx18 *cx = s->cx;
578 unsigned long then; 656 unsigned long then;
579 657
580 if (s->v4l2dev == NULL && s->dvb.enabled == 0) 658 if (s->video_dev == NULL && s->dvb.enabled == 0)
581 return -EINVAL; 659 return -EINVAL;
582 660
583 /* This function assumes that you are allowed to stop the capture 661 /* This function assumes that you are allowed to stop the capture
@@ -629,7 +707,7 @@ u32 cx18_find_handle(struct cx18 *cx)
629 for (i = 0; i < CX18_MAX_STREAMS; i++) { 707 for (i = 0; i < CX18_MAX_STREAMS; i++) {
630 struct cx18_stream *s = &cx->streams[i]; 708 struct cx18_stream *s = &cx->streams[i];
631 709
632 if (s->v4l2dev && (s->handle != CX18_INVALID_TASK_HANDLE)) 710 if (s->video_dev && (s->handle != CX18_INVALID_TASK_HANDLE))
633 return s->handle; 711 return s->handle;
634 } 712 }
635 return CX18_INVALID_TASK_HANDLE; 713 return CX18_INVALID_TASK_HANDLE;
@@ -647,7 +725,7 @@ struct cx18_stream *cx18_handle_to_stream(struct cx18 *cx, u32 handle)
647 s = &cx->streams[i]; 725 s = &cx->streams[i];
648 if (s->handle != handle) 726 if (s->handle != handle)
649 continue; 727 continue;
650 if (s->v4l2dev || s->dvb.enabled) 728 if (s->video_dev || s->dvb.enabled)
651 return s; 729 return s;
652 } 730 }
653 return NULL; 731 return NULL;
diff --git a/drivers/media/video/cx18/cx18-vbi.c b/drivers/media/video/cx18/cx18-vbi.c
index fb595bd548e8..c2aef4add31d 100644
--- a/drivers/media/video/cx18/cx18-vbi.c
+++ b/drivers/media/video/cx18/cx18-vbi.c
@@ -25,7 +25,16 @@
25#include "cx18-vbi.h" 25#include "cx18-vbi.h"
26#include "cx18-ioctl.h" 26#include "cx18-ioctl.h"
27#include "cx18-queue.h" 27#include "cx18-queue.h"
28#include "cx18-av-core.h" 28
29/*
30 * Raster Reference/Protection (RP) bytes, used in Start/End Active
31 * Video codes emitted from the digitzer in VIP 1.x mode, that flag the start
32 * of VBI sample or VBI ancilliary data regions in the digitial ratser line.
33 *
34 * Task FieldEven VerticalBlank HorizontalBlank 0 0 0 0
35 */
36static const u8 raw_vbi_sav_rp[2] = { 0x20, 0x60 }; /* __V_, _FV_ */
37static const u8 sliced_vbi_eav_rp[2] = { 0xb0, 0xf0 }; /* T_VH, TFVH */
29 38
30static void copy_vbi_data(struct cx18 *cx, int lines, u32 pts_stamp) 39static void copy_vbi_data(struct cx18 *cx, int lines, u32 pts_stamp)
31{ 40{
@@ -34,10 +43,17 @@ static void copy_vbi_data(struct cx18 *cx, int lines, u32 pts_stamp)
34 u32 linemask[2] = { 0, 0 }; 43 u32 linemask[2] = { 0, 0 };
35 unsigned short size; 44 unsigned short size;
36 static const u8 mpeg_hdr_data[] = { 45 static const u8 mpeg_hdr_data[] = {
37 0x00, 0x00, 0x01, 0xba, 0x44, 0x00, 0x0c, 0x66, 46 /* MPEG-2 Program Pack */
38 0x24, 0x01, 0x01, 0xd1, 0xd3, 0xfa, 0xff, 0xff, 47 0x00, 0x00, 0x01, 0xba, /* Prog Pack start code */
39 0x00, 0x00, 0x01, 0xbd, 0x00, 0x1a, 0x84, 0x80, 48 0x44, 0x00, 0x0c, 0x66, 0x24, 0x01, /* SCR, SCR Ext, markers */
40 0x07, 0x21, 0x00, 0x5d, 0x63, 0xa7, 0xff, 0xff 49 0x01, 0xd1, 0xd3, /* Mux Rate, markers */
50 0xfa, 0xff, 0xff, /* Res, Suff cnt, Stuff */
51 /* MPEG-2 Private Stream 1 PES Packet */
52 0x00, 0x00, 0x01, 0xbd, /* Priv Stream 1 start */
53 0x00, 0x1a, /* length */
54 0x84, 0x80, 0x07, /* flags, hdr data len */
55 0x21, 0x00, 0x5d, 0x63, 0xa7, /* PTS, markers */
56 0xff, 0xff /* stuffing */
41 }; 57 };
42 const int sd = sizeof(mpeg_hdr_data); /* start of vbi data */ 58 const int sd = sizeof(mpeg_hdr_data); /* start of vbi data */
43 int idx = cx->vbi.frame % CX18_VBI_FRAMES; 59 int idx = cx->vbi.frame % CX18_VBI_FRAMES;
@@ -71,7 +87,9 @@ static void copy_vbi_data(struct cx18 *cx, int lines, u32 pts_stamp)
71 memcpy(dst + sd + 4, dst + sd + 12, line * 43); 87 memcpy(dst + sd + 4, dst + sd + 12, line * 43);
72 size = 4 + ((43 * line + 3) & ~3); 88 size = 4 + ((43 * line + 3) & ~3);
73 } else { 89 } else {
74 memcpy(dst + sd, "cx0", 4); 90 memcpy(dst + sd, "itv0", 4);
91 cpu_to_le32s(&linemask[0]);
92 cpu_to_le32s(&linemask[1]);
75 memcpy(dst + sd + 4, &linemask[0], 8); 93 memcpy(dst + sd + 4, &linemask[0], 8);
76 size = 12 + ((43 * line + 3) & ~3); 94 size = 12 + ((43 * line + 3) & ~3);
77 } 95 }
@@ -86,58 +104,76 @@ static void copy_vbi_data(struct cx18 *cx, int lines, u32 pts_stamp)
86} 104}
87 105
88/* Compress raw VBI format, removes leading SAV codes and surplus space 106/* Compress raw VBI format, removes leading SAV codes and surplus space
89 after the field. 107 after the frame. Returns new compressed size. */
90 Returns new compressed size. */ 108static u32 compress_raw_buf(struct cx18 *cx, u8 *buf, u32 size, u32 hdr_size)
91static u32 compress_raw_buf(struct cx18 *cx, u8 *buf, u32 size)
92{ 109{
93 u32 line_size = cx->vbi.raw_decoder_line_size; 110 u32 line_size = vbi_active_samples;
94 u32 lines = cx->vbi.count; 111 u32 lines = cx->vbi.count * 2;
95 u8 sav1 = cx->vbi.raw_decoder_sav_odd_field;
96 u8 sav2 = cx->vbi.raw_decoder_sav_even_field;
97 u8 *q = buf; 112 u8 *q = buf;
98 u8 *p; 113 u8 *p;
99 int i; 114 int i;
100 115
116 /* Skip the header */
117 buf += hdr_size;
118
101 for (i = 0; i < lines; i++) { 119 for (i = 0; i < lines; i++) {
102 p = buf + i * line_size; 120 p = buf + i * line_size;
103 121
104 /* Look for SAV code */ 122 /* Look for SAV code */
105 if (p[0] != 0xff || p[1] || p[2] || 123 if (p[0] != 0xff || p[1] || p[2] ||
106 (p[3] != sav1 && p[3] != sav2)) 124 (p[3] != raw_vbi_sav_rp[0] &&
125 p[3] != raw_vbi_sav_rp[1]))
107 break; 126 break;
108 memcpy(q, p + 4, line_size - 4); 127 if (i == lines - 1) {
109 q += line_size - 4; 128 /* last line is hdr_size bytes short - extrapolate it */
129 memcpy(q, p + 4, line_size - 4 - hdr_size);
130 q += line_size - 4 - hdr_size;
131 p += line_size - hdr_size - 1;
132 memset(q, (int) *p, hdr_size);
133 } else {
134 memcpy(q, p + 4, line_size - 4);
135 q += line_size - 4;
136 }
110 } 137 }
111 return lines * (line_size - 4); 138 return lines * (line_size - 4);
112} 139}
113 140
114 141static u32 compress_sliced_buf(struct cx18 *cx, u8 *buf, u32 size,
115/* Compressed VBI format, all found sliced blocks put next to one another 142 const u32 hdr_size)
116 Returns new compressed size */
117static u32 compress_sliced_buf(struct cx18 *cx, u32 line, u8 *buf,
118 u32 size, u8 sav)
119{ 143{
120 u32 line_size = cx->vbi.sliced_decoder_line_size;
121 struct v4l2_decode_vbi_line vbi; 144 struct v4l2_decode_vbi_line vbi;
122 int i; 145 int i;
146 u32 line = 0;
147 u32 line_size = cx->is_60hz ? vbi_hblank_samples_60Hz
148 : vbi_hblank_samples_50Hz;
123 149
124 /* find the first valid line */ 150 /* find the first valid line */
125 for (i = 0; i < size; i++, buf++) { 151 for (i = hdr_size, buf += hdr_size; i < size; i++, buf++) {
126 if (buf[0] == 0xff && !buf[1] && !buf[2] && buf[3] == sav) 152 if (buf[0] == 0xff && !buf[1] && !buf[2] &&
153 (buf[3] == sliced_vbi_eav_rp[0] ||
154 buf[3] == sliced_vbi_eav_rp[1]))
127 break; 155 break;
128 } 156 }
129 157
130 size -= i; 158 /*
159 * The last line is short by hdr_size bytes, but for the remaining
160 * checks against size, we pretend that it is not, by counting the
161 * header bytes we knowingly skipped
162 */
163 size -= (i - hdr_size);
131 if (size < line_size) 164 if (size < line_size)
132 return line; 165 return line;
166
133 for (i = 0; i < size / line_size; i++) { 167 for (i = 0; i < size / line_size; i++) {
134 u8 *p = buf + i * line_size; 168 u8 *p = buf + i * line_size;
135 169
136 /* Look for SAV code */ 170 /* Look for EAV code */
137 if (p[0] != 0xff || p[1] || p[2] || p[3] != sav) 171 if (p[0] != 0xff || p[1] || p[2] ||
172 (p[3] != sliced_vbi_eav_rp[0] &&
173 p[3] != sliced_vbi_eav_rp[1]))
138 continue; 174 continue;
139 vbi.p = p + 4; 175 vbi.p = p + 4;
140 cx18_av_cmd(cx, VIDIOC_INT_DECODE_VBI_LINE, &vbi); 176 v4l2_subdev_call(cx->sd_av, video, decode_vbi_line, &vbi);
141 if (vbi.type) { 177 if (vbi.type) {
142 cx->vbi.sliced_data[line].id = vbi.type; 178 cx->vbi.sliced_data[line].id = vbi.type;
143 cx->vbi.sliced_data[line].field = vbi.is_second_field; 179 cx->vbi.sliced_data[line].field = vbi.is_second_field;
@@ -150,51 +186,56 @@ static u32 compress_sliced_buf(struct cx18 *cx, u32 line, u8 *buf,
150} 186}
151 187
152void cx18_process_vbi_data(struct cx18 *cx, struct cx18_buffer *buf, 188void cx18_process_vbi_data(struct cx18 *cx, struct cx18_buffer *buf,
153 u64 pts_stamp, int streamtype) 189 int streamtype)
154{ 190{
191 /*
192 * The CX23418 provides a 12 byte header in its raw VBI buffers to us:
193 * 0x3fffffff [4 bytes of something] [4 byte presentation time stamp]
194 */
195 struct vbi_data_hdr {
196 __be32 magic;
197 __be32 unknown;
198 __be32 pts;
199 } *hdr = (struct vbi_data_hdr *) buf->buf;
200
155 u8 *p = (u8 *) buf->buf; 201 u8 *p = (u8 *) buf->buf;
156 u32 size = buf->bytesused; 202 u32 size = buf->bytesused;
203 u32 pts;
157 int lines; 204 int lines;
158 205
159 if (streamtype != CX18_ENC_STREAM_TYPE_VBI) 206 if (streamtype != CX18_ENC_STREAM_TYPE_VBI)
160 return; 207 return;
161 208
209 /*
210 * The CX23418 sends us data that is 32 bit little-endian swapped,
211 * but we want the raw VBI bytes in the order they were in the raster
212 * line. This has a side effect of making the header big endian
213 */
214 cx18_buf_swap(buf);
215
162 /* Raw VBI data */ 216 /* Raw VBI data */
163 if (cx18_raw_vbi(cx)) { 217 if (cx18_raw_vbi(cx)) {
164 u8 type;
165
166 cx18_buf_swap(buf);
167
168 /* Skip 12 bytes of header that gets stuffed in */
169 size -= 12;
170 memcpy(p, &buf->buf[12], size);
171 type = p[3];
172 218
173 size = buf->bytesused = compress_raw_buf(cx, p, size); 219 size = buf->bytesused =
220 compress_raw_buf(cx, p, size, sizeof(struct vbi_data_hdr));
174 221
175 /* second field of the frame? */ 222 /*
176 if (type == cx->vbi.raw_decoder_sav_even_field) { 223 * Hack needed for compatibility with old VBI software.
177 /* Dirty hack needed for backwards 224 * Write the frame # at the last 4 bytes of the frame
178 compatibility of old VBI software. */ 225 */
179 p += size - 4; 226 p += size - 4;
180 memcpy(p, &cx->vbi.frame, 4); 227 memcpy(p, &cx->vbi.frame, 4);
181 cx->vbi.frame++; 228 cx->vbi.frame++;
182 }
183 return; 229 return;
184 } 230 }
185 231
186 /* Sliced VBI data with data insertion */ 232 /* Sliced VBI data with data insertion */
187 cx18_buf_swap(buf);
188 233
189 /* first field */ 234 pts = (be32_to_cpu(hdr->magic) == 0x3fffffff) ? be32_to_cpu(hdr->pts)
190 lines = compress_sliced_buf(cx, 0, p, size / 2, 235 : 0;
191 cx->vbi.sliced_decoder_sav_odd_field); 236
192 /* second field */ 237 lines = compress_sliced_buf(cx, p, size, sizeof(struct vbi_data_hdr));
193 /* experimentation shows that the second half does not always 238
194 begin at the exact address. So start a bit earlier
195 (hence 32). */
196 lines = compress_sliced_buf(cx, lines, p + size / 2 - 32,
197 size / 2 + 32, cx->vbi.sliced_decoder_sav_even_field);
198 /* always return at least one empty line */ 239 /* always return at least one empty line */
199 if (lines == 0) { 240 if (lines == 0) {
200 cx->vbi.sliced_data[0].id = 0; 241 cx->vbi.sliced_data[0].id = 0;
@@ -206,6 +247,6 @@ void cx18_process_vbi_data(struct cx18 *cx, struct cx18_buffer *buf,
206 memcpy(p, &cx->vbi.sliced_data[0], size); 247 memcpy(p, &cx->vbi.sliced_data[0], size);
207 248
208 if (cx->vbi.insert_mpeg) 249 if (cx->vbi.insert_mpeg)
209 copy_vbi_data(cx, lines, pts_stamp); 250 copy_vbi_data(cx, lines, pts);
210 cx->vbi.frame++; 251 cx->vbi.frame++;
211} 252}
diff --git a/drivers/media/video/cx18/cx18-vbi.h b/drivers/media/video/cx18/cx18-vbi.h
index c56ff7d28f20..e7e1ae427f34 100644
--- a/drivers/media/video/cx18/cx18-vbi.h
+++ b/drivers/media/video/cx18/cx18-vbi.h
@@ -22,5 +22,5 @@
22 */ 22 */
23 23
24void cx18_process_vbi_data(struct cx18 *cx, struct cx18_buffer *buf, 24void cx18_process_vbi_data(struct cx18 *cx, struct cx18_buffer *buf,
25 u64 pts_stamp, int streamtype); 25 int streamtype);
26int cx18_used_line(struct cx18 *cx, int line, int field); 26int cx18_used_line(struct cx18 *cx, int line, int field);
diff --git a/drivers/media/video/cx18/cx18-version.h b/drivers/media/video/cx18/cx18-version.h
index 84c0ff13b607..bd9bd44da791 100644
--- a/drivers/media/video/cx18/cx18-version.h
+++ b/drivers/media/video/cx18/cx18-version.h
@@ -24,8 +24,8 @@
24 24
25#define CX18_DRIVER_NAME "cx18" 25#define CX18_DRIVER_NAME "cx18"
26#define CX18_DRIVER_VERSION_MAJOR 1 26#define CX18_DRIVER_VERSION_MAJOR 1
27#define CX18_DRIVER_VERSION_MINOR 0 27#define CX18_DRIVER_VERSION_MINOR 1
28#define CX18_DRIVER_VERSION_PATCHLEVEL 4 28#define CX18_DRIVER_VERSION_PATCHLEVEL 0
29 29
30#define CX18_VERSION __stringify(CX18_DRIVER_VERSION_MAJOR) "." __stringify(CX18_DRIVER_VERSION_MINOR) "." __stringify(CX18_DRIVER_VERSION_PATCHLEVEL) 30#define CX18_VERSION __stringify(CX18_DRIVER_VERSION_MAJOR) "." __stringify(CX18_DRIVER_VERSION_MINOR) "." __stringify(CX18_DRIVER_VERSION_PATCHLEVEL)
31#define CX18_DRIVER_VERSION KERNEL_VERSION(CX18_DRIVER_VERSION_MAJOR, \ 31#define CX18_DRIVER_VERSION KERNEL_VERSION(CX18_DRIVER_VERSION_MAJOR, \
diff --git a/drivers/media/video/cx18/cx18-video.c b/drivers/media/video/cx18/cx18-video.c
index 2e5c41939330..6fdadedf17a8 100644
--- a/drivers/media/video/cx18/cx18-video.c
+++ b/drivers/media/video/cx18/cx18-video.c
@@ -21,7 +21,6 @@
21 21
22#include "cx18-driver.h" 22#include "cx18-driver.h"
23#include "cx18-video.h" 23#include "cx18-video.h"
24#include "cx18-av-core.h"
25#include "cx18-cards.h" 24#include "cx18-cards.h"
26 25
27void cx18_video_set_io(struct cx18 *cx) 26void cx18_video_set_io(struct cx18 *cx)
@@ -32,7 +31,7 @@ void cx18_video_set_io(struct cx18 *cx)
32 31
33 route.input = cx->card->video_inputs[inp].video_input; 32 route.input = cx->card->video_inputs[inp].video_input;
34 route.output = 0; 33 route.output = 0;
35 cx18_av_cmd(cx, VIDIOC_INT_S_VIDEO_ROUTING, &route); 34 v4l2_subdev_call(cx->sd_av, video, s_routing, &route);
36 35
37 type = cx->card->video_inputs[inp].video_type; 36 type = cx->card->video_inputs[inp].video_type;
38 37
diff --git a/drivers/media/video/cx18/cx23418.h b/drivers/media/video/cx18/cx23418.h
index 601f3a2ab742..9956abf576c5 100644
--- a/drivers/media/video/cx18/cx23418.h
+++ b/drivers/media/video/cx18/cx23418.h
@@ -56,6 +56,22 @@
56#define APU_CMD_MASK 0x10000000 56#define APU_CMD_MASK 0x10000000
57#define APU_CMD_MASK_ACK (APU_CMD_MASK | 0x80000000) 57#define APU_CMD_MASK_ACK (APU_CMD_MASK | 0x80000000)
58 58
59#define CX18_APU_ENCODING_METHOD_MPEG (0 << 28)
60#define CX18_APU_ENCODING_METHOD_AC3 (1 << 28)
61
62/* Description: Command APU to start audio
63 IN[0] - audio parameters (same as CX18_CPU_SET_AUDIO_PARAMETERS?)
64 IN[1] - caller buffer address, or 0
65 ReturnCode - ??? */
66#define CX18_APU_START (APU_CMD_MASK | 0x01)
67
68/* Description: Command APU to stop audio
69 IN[0] - encoding method to stop
70 ReturnCode - ??? */
71#define CX18_APU_STOP (APU_CMD_MASK | 0x02)
72
73/* Description: Command APU to reset the AI
74 ReturnCode - ??? */
59#define CX18_APU_RESETAI (APU_CMD_MASK | 0x05) 75#define CX18_APU_RESETAI (APU_CMD_MASK | 0x05)
60 76
61/* Description: This command indicates that a Memory Descriptor List has been 77/* Description: This command indicates that a Memory Descriptor List has been
diff --git a/drivers/media/video/cx2341x.c b/drivers/media/video/cx2341x.c
index cbbe47fb87b7..8ded52946334 100644
--- a/drivers/media/video/cx2341x.c
+++ b/drivers/media/video/cx2341x.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * cx2341x - generic code for cx23415/6 based devices 2 * cx2341x - generic code for cx23415/6/8 based devices
3 * 3 *
4 * Copyright (C) 2006 Hans Verkuil <hverkuil@xs4all.nl> 4 * Copyright (C) 2006 Hans Verkuil <hverkuil@xs4all.nl>
5 * 5 *
@@ -30,7 +30,7 @@
30#include <media/cx2341x.h> 30#include <media/cx2341x.h>
31#include <media/v4l2-common.h> 31#include <media/v4l2-common.h>
32 32
33MODULE_DESCRIPTION("cx23415/6 driver"); 33MODULE_DESCRIPTION("cx23415/6/8 driver");
34MODULE_AUTHOR("Hans Verkuil"); 34MODULE_AUTHOR("Hans Verkuil");
35MODULE_LICENSE("GPL"); 35MODULE_LICENSE("GPL");
36 36
@@ -38,6 +38,7 @@ static 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
41/* Must be sorted from low to high control ID! */
41const u32 cx2341x_mpeg_ctrls[] = { 42const u32 cx2341x_mpeg_ctrls[] = {
42 V4L2_CID_MPEG_CLASS, 43 V4L2_CID_MPEG_CLASS,
43 V4L2_CID_MPEG_STREAM_TYPE, 44 V4L2_CID_MPEG_STREAM_TYPE,
@@ -50,6 +51,7 @@ const u32 cx2341x_mpeg_ctrls[] = {
50 V4L2_CID_MPEG_AUDIO_EMPHASIS, 51 V4L2_CID_MPEG_AUDIO_EMPHASIS,
51 V4L2_CID_MPEG_AUDIO_CRC, 52 V4L2_CID_MPEG_AUDIO_CRC,
52 V4L2_CID_MPEG_AUDIO_MUTE, 53 V4L2_CID_MPEG_AUDIO_MUTE,
54 V4L2_CID_MPEG_AUDIO_AC3_BITRATE,
53 V4L2_CID_MPEG_VIDEO_ENCODING, 55 V4L2_CID_MPEG_VIDEO_ENCODING,
54 V4L2_CID_MPEG_VIDEO_ASPECT, 56 V4L2_CID_MPEG_VIDEO_ASPECT,
55 V4L2_CID_MPEG_VIDEO_B_FRAMES, 57 V4L2_CID_MPEG_VIDEO_B_FRAMES,
@@ -94,6 +96,7 @@ static const struct cx2341x_mpeg_params default_params = {
94 .audio_sampling_freq = V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000, 96 .audio_sampling_freq = V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000,
95 .audio_encoding = V4L2_MPEG_AUDIO_ENCODING_LAYER_2, 97 .audio_encoding = V4L2_MPEG_AUDIO_ENCODING_LAYER_2,
96 .audio_l2_bitrate = V4L2_MPEG_AUDIO_L2_BITRATE_224K, 98 .audio_l2_bitrate = V4L2_MPEG_AUDIO_L2_BITRATE_224K,
99 .audio_ac3_bitrate = V4L2_MPEG_AUDIO_AC3_BITRATE_224K,
97 .audio_mode = V4L2_MPEG_AUDIO_MODE_STEREO, 100 .audio_mode = V4L2_MPEG_AUDIO_MODE_STEREO,
98 .audio_mode_extension = V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_4, 101 .audio_mode_extension = V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_4,
99 .audio_emphasis = V4L2_MPEG_AUDIO_EMPHASIS_NONE, 102 .audio_emphasis = V4L2_MPEG_AUDIO_EMPHASIS_NONE,
@@ -148,6 +151,9 @@ static int cx2341x_get_ctrl(const struct cx2341x_mpeg_params *params,
148 case V4L2_CID_MPEG_AUDIO_L2_BITRATE: 151 case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
149 ctrl->value = params->audio_l2_bitrate; 152 ctrl->value = params->audio_l2_bitrate;
150 break; 153 break;
154 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
155 ctrl->value = params->audio_ac3_bitrate;
156 break;
151 case V4L2_CID_MPEG_AUDIO_MODE: 157 case V4L2_CID_MPEG_AUDIO_MODE:
152 ctrl->value = params->audio_mode; 158 ctrl->value = params->audio_mode;
153 break; 159 break;
@@ -256,6 +262,12 @@ static int cx2341x_set_ctrl(struct cx2341x_mpeg_params *params, int busy,
256 params->audio_sampling_freq = ctrl->value; 262 params->audio_sampling_freq = ctrl->value;
257 break; 263 break;
258 case V4L2_CID_MPEG_AUDIO_ENCODING: 264 case V4L2_CID_MPEG_AUDIO_ENCODING:
265 if (busy)
266 return -EBUSY;
267 if (params->capabilities & CX2341X_CAP_HAS_AC3)
268 if (ctrl->value != V4L2_MPEG_AUDIO_ENCODING_LAYER_2 &&
269 ctrl->value != V4L2_MPEG_AUDIO_ENCODING_AC3)
270 return -ERANGE;
259 params->audio_encoding = ctrl->value; 271 params->audio_encoding = ctrl->value;
260 break; 272 break;
261 case V4L2_CID_MPEG_AUDIO_L2_BITRATE: 273 case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
@@ -263,6 +275,13 @@ static int cx2341x_set_ctrl(struct cx2341x_mpeg_params *params, int busy,
263 return -EBUSY; 275 return -EBUSY;
264 params->audio_l2_bitrate = ctrl->value; 276 params->audio_l2_bitrate = ctrl->value;
265 break; 277 break;
278 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
279 if (busy)
280 return -EBUSY;
281 if (!(params->capabilities & CX2341X_CAP_HAS_AC3))
282 return -EINVAL;
283 params->audio_ac3_bitrate = ctrl->value;
284 break;
266 case V4L2_CID_MPEG_AUDIO_MODE: 285 case V4L2_CID_MPEG_AUDIO_MODE:
267 params->audio_mode = ctrl->value; 286 params->audio_mode = ctrl->value;
268 break; 287 break;
@@ -481,29 +500,106 @@ int cx2341x_ctrl_query(const struct cx2341x_mpeg_params *params,
481 int err; 500 int err;
482 501
483 switch (qctrl->id) { 502 switch (qctrl->id) {
503 case V4L2_CID_MPEG_STREAM_TYPE:
504 return v4l2_ctrl_query_fill(qctrl,
505 V4L2_MPEG_STREAM_TYPE_MPEG2_PS,
506 V4L2_MPEG_STREAM_TYPE_MPEG2_SVCD, 1,
507 V4L2_MPEG_STREAM_TYPE_MPEG2_PS);
508
509 case V4L2_CID_MPEG_STREAM_VBI_FMT:
510 if (params->capabilities & CX2341X_CAP_HAS_SLICED_VBI)
511 return v4l2_ctrl_query_fill(qctrl,
512 V4L2_MPEG_STREAM_VBI_FMT_NONE,
513 V4L2_MPEG_STREAM_VBI_FMT_IVTV, 1,
514 V4L2_MPEG_STREAM_VBI_FMT_NONE);
515 return cx2341x_ctrl_query_fill(qctrl,
516 V4L2_MPEG_STREAM_VBI_FMT_NONE,
517 V4L2_MPEG_STREAM_VBI_FMT_NONE, 1,
518 default_params.stream_vbi_fmt);
519
520 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
521 return v4l2_ctrl_query_fill(qctrl,
522 V4L2_MPEG_AUDIO_SAMPLING_FREQ_44100,
523 V4L2_MPEG_AUDIO_SAMPLING_FREQ_32000, 1,
524 V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000);
525
484 case V4L2_CID_MPEG_AUDIO_ENCODING: 526 case V4L2_CID_MPEG_AUDIO_ENCODING:
527 if (params->capabilities & CX2341X_CAP_HAS_AC3) {
528 /*
529 * The state of L2 & AC3 bitrate controls can change
530 * when this control changes, but v4l2_ctrl_query_fill()
531 * already sets V4L2_CTRL_FLAG_UPDATE for
532 * V4L2_CID_MPEG_AUDIO_ENCODING, so we don't here.
533 */
534 return v4l2_ctrl_query_fill(qctrl,
535 V4L2_MPEG_AUDIO_ENCODING_LAYER_2,
536 V4L2_MPEG_AUDIO_ENCODING_AC3, 1,
537 default_params.audio_encoding);
538 }
539
485 return v4l2_ctrl_query_fill(qctrl, 540 return v4l2_ctrl_query_fill(qctrl,
486 V4L2_MPEG_AUDIO_ENCODING_LAYER_2, 541 V4L2_MPEG_AUDIO_ENCODING_LAYER_2,
487 V4L2_MPEG_AUDIO_ENCODING_LAYER_2, 1, 542 V4L2_MPEG_AUDIO_ENCODING_LAYER_2, 1,
488 default_params.audio_encoding); 543 default_params.audio_encoding);
489 544
490 case V4L2_CID_MPEG_AUDIO_L2_BITRATE: 545 case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
491 return v4l2_ctrl_query_fill(qctrl, 546 err = v4l2_ctrl_query_fill(qctrl,
492 V4L2_MPEG_AUDIO_L2_BITRATE_192K, 547 V4L2_MPEG_AUDIO_L2_BITRATE_192K,
493 V4L2_MPEG_AUDIO_L2_BITRATE_384K, 1, 548 V4L2_MPEG_AUDIO_L2_BITRATE_384K, 1,
494 default_params.audio_l2_bitrate); 549 default_params.audio_l2_bitrate);
550 if (err)
551 return err;
552 if (params->capabilities & CX2341X_CAP_HAS_AC3 &&
553 params->audio_encoding != V4L2_MPEG_AUDIO_ENCODING_LAYER_2)
554 qctrl->flags |= V4L2_CTRL_FLAG_INACTIVE;
555 return 0;
495 556
496 case V4L2_CID_MPEG_AUDIO_L1_BITRATE: 557 case V4L2_CID_MPEG_AUDIO_MODE:
497 case V4L2_CID_MPEG_AUDIO_L3_BITRATE: 558 return v4l2_ctrl_query_fill(qctrl,
498 return -EINVAL; 559 V4L2_MPEG_AUDIO_MODE_STEREO,
560 V4L2_MPEG_AUDIO_MODE_MONO, 1,
561 V4L2_MPEG_AUDIO_MODE_STEREO);
499 562
500 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION: 563 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION:
501 err = v4l2_ctrl_query_fill_std(qctrl); 564 err = v4l2_ctrl_query_fill(qctrl,
565 V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_4,
566 V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_16, 1,
567 V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_4);
502 if (err == 0 && 568 if (err == 0 &&
503 params->audio_mode != V4L2_MPEG_AUDIO_MODE_JOINT_STEREO) 569 params->audio_mode != V4L2_MPEG_AUDIO_MODE_JOINT_STEREO)
504 qctrl->flags |= V4L2_CTRL_FLAG_INACTIVE; 570 qctrl->flags |= V4L2_CTRL_FLAG_INACTIVE;
505 return err; 571 return err;
506 572
573 case V4L2_CID_MPEG_AUDIO_EMPHASIS:
574 return v4l2_ctrl_query_fill(qctrl,
575 V4L2_MPEG_AUDIO_EMPHASIS_NONE,
576 V4L2_MPEG_AUDIO_EMPHASIS_CCITT_J17, 1,
577 V4L2_MPEG_AUDIO_EMPHASIS_NONE);
578
579 case V4L2_CID_MPEG_AUDIO_CRC:
580 return v4l2_ctrl_query_fill(qctrl,
581 V4L2_MPEG_AUDIO_CRC_NONE,
582 V4L2_MPEG_AUDIO_CRC_CRC16, 1,
583 V4L2_MPEG_AUDIO_CRC_NONE);
584
585 case V4L2_CID_MPEG_AUDIO_MUTE:
586 return v4l2_ctrl_query_fill(qctrl, 0, 1, 1, 0);
587
588 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
589 err = v4l2_ctrl_query_fill(qctrl,
590 V4L2_MPEG_AUDIO_AC3_BITRATE_48K,
591 V4L2_MPEG_AUDIO_AC3_BITRATE_448K, 1,
592 default_params.audio_ac3_bitrate);
593 if (err)
594 return err;
595 if (params->capabilities & CX2341X_CAP_HAS_AC3) {
596 if (params->audio_encoding !=
597 V4L2_MPEG_AUDIO_ENCODING_AC3)
598 qctrl->flags |= V4L2_CTRL_FLAG_INACTIVE;
599 } else
600 qctrl->flags |= V4L2_CTRL_FLAG_DISABLED;
601 return 0;
602
507 case V4L2_CID_MPEG_VIDEO_ENCODING: 603 case V4L2_CID_MPEG_VIDEO_ENCODING:
508 /* this setting is read-only for the cx2341x since the 604 /* this setting is read-only for the cx2341x since the
509 V4L2_CID_MPEG_STREAM_TYPE really determines the 605 V4L2_CID_MPEG_STREAM_TYPE really determines the
@@ -516,32 +612,51 @@ int cx2341x_ctrl_query(const struct cx2341x_mpeg_params *params,
516 qctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; 612 qctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY;
517 return err; 613 return err;
518 614
615 case V4L2_CID_MPEG_VIDEO_ASPECT:
616 return v4l2_ctrl_query_fill(qctrl,
617 V4L2_MPEG_VIDEO_ASPECT_1x1,
618 V4L2_MPEG_VIDEO_ASPECT_221x100, 1,
619 V4L2_MPEG_VIDEO_ASPECT_4x3);
620
621 case V4L2_CID_MPEG_VIDEO_B_FRAMES:
622 return v4l2_ctrl_query_fill(qctrl, 0, 33, 1, 2);
623
624 case V4L2_CID_MPEG_VIDEO_GOP_SIZE:
625 return v4l2_ctrl_query_fill(qctrl, 1, 34, 1,
626 params->is_50hz ? 12 : 15);
627
628 case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE:
629 return v4l2_ctrl_query_fill(qctrl, 0, 1, 1, 1);
630
519 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: 631 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
520 err = v4l2_ctrl_query_fill_std(qctrl); 632 err = v4l2_ctrl_query_fill(qctrl,
633 V4L2_MPEG_VIDEO_BITRATE_MODE_VBR,
634 V4L2_MPEG_VIDEO_BITRATE_MODE_CBR, 1,
635 V4L2_MPEG_VIDEO_BITRATE_MODE_VBR);
521 if (err == 0 && 636 if (err == 0 &&
522 params->video_encoding == V4L2_MPEG_VIDEO_ENCODING_MPEG_1) 637 params->video_encoding == V4L2_MPEG_VIDEO_ENCODING_MPEG_1)
523 qctrl->flags |= V4L2_CTRL_FLAG_INACTIVE; 638 qctrl->flags |= V4L2_CTRL_FLAG_INACTIVE;
524 return err; 639 return err;
525 640
641 case V4L2_CID_MPEG_VIDEO_BITRATE:
642 return v4l2_ctrl_query_fill(qctrl, 0, 27000000, 1, 6000000);
643
526 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK: 644 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK:
527 err = v4l2_ctrl_query_fill_std(qctrl); 645 err = v4l2_ctrl_query_fill(qctrl, 0, 27000000, 1, 8000000);
528 if (err == 0 && 646 if (err == 0 &&
529 params->video_bitrate_mode == 647 params->video_bitrate_mode ==
530 V4L2_MPEG_VIDEO_BITRATE_MODE_CBR) 648 V4L2_MPEG_VIDEO_BITRATE_MODE_CBR)
531 qctrl->flags |= V4L2_CTRL_FLAG_INACTIVE; 649 qctrl->flags |= V4L2_CTRL_FLAG_INACTIVE;
532 return err; 650 return err;
533 651
534 case V4L2_CID_MPEG_STREAM_VBI_FMT: 652 case V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION:
535 if (params->capabilities & CX2341X_CAP_HAS_SLICED_VBI) 653 return v4l2_ctrl_query_fill(qctrl, 0, 255, 1, 0);
536 return v4l2_ctrl_query_fill_std(qctrl);
537 return cx2341x_ctrl_query_fill(qctrl,
538 V4L2_MPEG_STREAM_VBI_FMT_NONE,
539 V4L2_MPEG_STREAM_VBI_FMT_NONE, 1,
540 default_params.stream_vbi_fmt);
541 654
542 case V4L2_CID_MPEG_VIDEO_GOP_SIZE: 655 case V4L2_CID_MPEG_VIDEO_MUTE:
543 return v4l2_ctrl_query_fill(qctrl, 1, 34, 1, 656 return v4l2_ctrl_query_fill(qctrl, 0, 1, 1, 0);
544 params->is_50hz ? 12 : 15); 657
658 case V4L2_CID_MPEG_VIDEO_MUTE_YUV: /* Init YUV (really YCbCr) to black */
659 return v4l2_ctrl_query_fill(qctrl, 0, 0xffffff, 1, 0x008080);
545 660
546 /* CX23415/6 specific */ 661 /* CX23415/6 specific */
547 case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE: 662 case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE:
@@ -643,7 +758,7 @@ int cx2341x_ctrl_query(const struct cx2341x_mpeg_params *params,
643 default_params.stream_insert_nav_packets); 758 default_params.stream_insert_nav_packets);
644 759
645 default: 760 default:
646 return v4l2_ctrl_query_fill_std(qctrl); 761 return -EINVAL;
647 762
648 } 763 }
649} 764}
@@ -671,6 +786,15 @@ const char **cx2341x_ctrl_get_menu(const struct cx2341x_mpeg_params *p, u32 id)
671 NULL 786 NULL
672 }; 787 };
673 788
789 static const char *mpeg_audio_encoding_l2_ac3[] = {
790 "",
791 "MPEG-1/2 Layer II",
792 "",
793 "",
794 "AC-3",
795 NULL
796 };
797
674 static const char *cx2341x_video_spatial_filter_mode_menu[] = { 798 static const char *cx2341x_video_spatial_filter_mode_menu[] = {
675 "Manual", 799 "Manual",
676 "Auto", 800 "Auto",
@@ -711,6 +835,9 @@ const char **cx2341x_ctrl_get_menu(const struct cx2341x_mpeg_params *p, u32 id)
711 case V4L2_CID_MPEG_STREAM_TYPE: 835 case V4L2_CID_MPEG_STREAM_TYPE:
712 return (p->capabilities & CX2341X_CAP_HAS_TS) ? 836 return (p->capabilities & CX2341X_CAP_HAS_TS) ?
713 mpeg_stream_type_with_ts : mpeg_stream_type_without_ts; 837 mpeg_stream_type_with_ts : mpeg_stream_type_without_ts;
838 case V4L2_CID_MPEG_AUDIO_ENCODING:
839 return (p->capabilities & CX2341X_CAP_HAS_AC3) ?
840 mpeg_audio_encoding_l2_ac3 : v4l2_ctrl_get_menu(id);
714 case V4L2_CID_MPEG_AUDIO_L1_BITRATE: 841 case V4L2_CID_MPEG_AUDIO_L1_BITRATE:
715 case V4L2_CID_MPEG_AUDIO_L3_BITRATE: 842 case V4L2_CID_MPEG_AUDIO_L3_BITRATE:
716 return NULL; 843 return NULL;
@@ -730,16 +857,34 @@ const char **cx2341x_ctrl_get_menu(const struct cx2341x_mpeg_params *p, u32 id)
730} 857}
731EXPORT_SYMBOL(cx2341x_ctrl_get_menu); 858EXPORT_SYMBOL(cx2341x_ctrl_get_menu);
732 859
860/* definitions for audio properties bits 29-28 */
861#define CX2341X_AUDIO_ENCODING_METHOD_MPEG 0
862#define CX2341X_AUDIO_ENCODING_METHOD_AC3 1
863#define CX2341X_AUDIO_ENCODING_METHOD_LPCM 2
864
733static void cx2341x_calc_audio_properties(struct cx2341x_mpeg_params *params) 865static void cx2341x_calc_audio_properties(struct cx2341x_mpeg_params *params)
734{ 866{
735 params->audio_properties = (params->audio_sampling_freq << 0) | 867 params->audio_properties =
736 ((3 - params->audio_encoding) << 2) | 868 (params->audio_sampling_freq << 0) |
737 ((1 + params->audio_l2_bitrate) << 4) |
738 (params->audio_mode << 8) | 869 (params->audio_mode << 8) |
739 (params->audio_mode_extension << 10) | 870 (params->audio_mode_extension << 10) |
740 (((params->audio_emphasis == V4L2_MPEG_AUDIO_EMPHASIS_CCITT_J17) 871 (((params->audio_emphasis == V4L2_MPEG_AUDIO_EMPHASIS_CCITT_J17)
741 ? 3 : params->audio_emphasis) << 12) | 872 ? 3 : params->audio_emphasis) << 12) |
742 (params->audio_crc << 14); 873 (params->audio_crc << 14);
874
875 if ((params->capabilities & CX2341X_CAP_HAS_AC3) &&
876 params->audio_encoding == V4L2_MPEG_AUDIO_ENCODING_AC3) {
877 params->audio_properties |=
878 /* Not sure if this MPEG Layer II setting is required */
879 ((3 - V4L2_MPEG_AUDIO_ENCODING_LAYER_2) << 2) |
880 (params->audio_ac3_bitrate << 4) |
881 (CX2341X_AUDIO_ENCODING_METHOD_AC3 << 28);
882 } else {
883 /* Assuming MPEG Layer II */
884 params->audio_properties |=
885 ((3 - params->audio_encoding) << 2) |
886 ((1 + params->audio_l2_bitrate) << 4);
887 }
743} 888}
744 889
745int cx2341x_ext_ctrls(struct cx2341x_mpeg_params *params, int busy, 890int cx2341x_ext_ctrls(struct cx2341x_mpeg_params *params, int busy,
@@ -1022,7 +1167,10 @@ void cx2341x_log_status(const struct cx2341x_mpeg_params *p, const char *prefix)
1022 prefix, 1167 prefix,
1023 cx2341x_menu_item(p, V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ), 1168 cx2341x_menu_item(p, V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ),
1024 cx2341x_menu_item(p, V4L2_CID_MPEG_AUDIO_ENCODING), 1169 cx2341x_menu_item(p, V4L2_CID_MPEG_AUDIO_ENCODING),
1025 cx2341x_menu_item(p, V4L2_CID_MPEG_AUDIO_L2_BITRATE), 1170 cx2341x_menu_item(p,
1171 p->audio_encoding == V4L2_MPEG_AUDIO_ENCODING_AC3
1172 ? V4L2_CID_MPEG_AUDIO_AC3_BITRATE
1173 : V4L2_CID_MPEG_AUDIO_L2_BITRATE),
1026 cx2341x_menu_item(p, V4L2_CID_MPEG_AUDIO_MODE), 1174 cx2341x_menu_item(p, V4L2_CID_MPEG_AUDIO_MODE),
1027 p->audio_mute ? " (muted)" : ""); 1175 p->audio_mute ? " (muted)" : "");
1028 if (p->audio_mode == V4L2_MPEG_AUDIO_MODE_JOINT_STEREO) 1176 if (p->audio_mode == V4L2_MPEG_AUDIO_MODE_JOINT_STEREO)
diff --git a/drivers/media/video/cx23885/Kconfig b/drivers/media/video/cx23885/Kconfig
index 00f1e2e8889e..fd3fc3e3198a 100644
--- a/drivers/media/video/cx23885/Kconfig
+++ b/drivers/media/video/cx23885/Kconfig
@@ -15,12 +15,15 @@ config VIDEO_CX23885
15 select DVB_S5H1411 if !DVB_FE_CUSTOMISE 15 select DVB_S5H1411 if !DVB_FE_CUSTOMISE
16 select DVB_LGDT330X if !DVB_FE_CUSTOMISE 16 select DVB_LGDT330X if !DVB_FE_CUSTOMISE
17 select DVB_ZL10353 if !DVB_FE_CUSTOMISE 17 select DVB_ZL10353 if !DVB_FE_CUSTOMISE
18 select DVB_TDA10048 if !DVB_FE_CUSTOMIZE 18 select DVB_TDA10048 if !DVB_FE_CUSTOMISE
19 select MEDIA_TUNER_MT2131 if !MEDIA_TUNER_CUSTOMIZE 19 select DVB_LNBP21 if !DVB_FE_CUSTOMISE
20 select MEDIA_TUNER_XC2028 if !DVB_FE_CUSTOMIZE 20 select DVB_STV6110 if !DVB_FE_CUSTOMISE
21 select MEDIA_TUNER_TDA8290 if !DVB_FE_CUSTOMIZE 21 select DVB_STV0900 if !DVB_FE_CUSTOMISE
22 select MEDIA_TUNER_TDA18271 if !DVB_FE_CUSTOMIZE 22 select MEDIA_TUNER_MT2131 if !MEDIA_TUNER_CUSTOMISE
23 select MEDIA_TUNER_XC5000 if !DVB_FE_CUSTOMIZE 23 select MEDIA_TUNER_XC2028 if !MEDIA_TUNER_CUSTOMISE
24 select MEDIA_TUNER_TDA8290 if !MEDIA_TUNER_CUSTOMISE
25 select MEDIA_TUNER_TDA18271 if !MEDIA_TUNER_CUSTOMISE
26 select MEDIA_TUNER_XC5000 if !MEDIA_TUNER_CUSTOMISE
24 ---help--- 27 ---help---
25 This is a video4linux driver for Conexant 23885 based 28 This is a video4linux driver for Conexant 23885 based
26 TV cards. 29 TV cards.
diff --git a/drivers/media/video/cx23885/Makefile b/drivers/media/video/cx23885/Makefile
index 29c23b44c13c..ab8ea35c9bfb 100644
--- a/drivers/media/video/cx23885/Makefile
+++ b/drivers/media/video/cx23885/Makefile
@@ -1,4 +1,6 @@
1cx23885-objs := cx23885-cards.o cx23885-video.o cx23885-vbi.o cx23885-core.o cx23885-i2c.o cx23885-dvb.o cx23885-417.o 1cx23885-objs := cx23885-cards.o cx23885-video.o cx23885-vbi.o \
2 cx23885-core.o cx23885-i2c.o cx23885-dvb.o cx23885-417.o \
3 netup-init.o cimax2.o netup-eeprom.o
2 4
3obj-$(CONFIG_VIDEO_CX23885) += cx23885.o 5obj-$(CONFIG_VIDEO_CX23885) += cx23885.o
4 6
diff --git a/drivers/media/video/cx23885/cimax2.c b/drivers/media/video/cx23885/cimax2.c
new file mode 100644
index 000000000000..9a6536998d90
--- /dev/null
+++ b/drivers/media/video/cx23885/cimax2.c
@@ -0,0 +1,472 @@
1/*
2 * cimax2.c
3 *
4 * CIMax2(R) SP2 driver in conjunction with NetUp Dual DVB-S2 CI card
5 *
6 * Copyright (C) 2009 NetUP Inc.
7 * Copyright (C) 2009 Igor M. Liplianin <liplianin@netup.ru>
8 * Copyright (C) 2009 Abylay Ospan <aospan@netup.ru>
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 *
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25
26#include "cx23885.h"
27#include "dvb_ca_en50221.h"
28/**** Bit definitions for MC417_RWD and MC417_OEN registers ***
29 bits 31-16
30+-----------+
31| Reserved |
32+-----------+
33 bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8
34+-------+-------+-------+-------+-------+-------+-------+-------+
35| WR# | RD# | | ACK# | ADHI | ADLO | CS1# | CS0# |
36+-------+-------+-------+-------+-------+-------+-------+-------+
37 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0
38+-------+-------+-------+-------+-------+-------+-------+-------+
39| DATA7| DATA6| DATA5| DATA4| DATA3| DATA2| DATA1| DATA0|
40+-------+-------+-------+-------+-------+-------+-------+-------+
41***/
42/* MC417 */
43#define NETUP_DATA 0x000000ff
44#define NETUP_WR 0x00008000
45#define NETUP_RD 0x00004000
46#define NETUP_ACK 0x00001000
47#define NETUP_ADHI 0x00000800
48#define NETUP_ADLO 0x00000400
49#define NETUP_CS1 0x00000200
50#define NETUP_CS0 0x00000100
51#define NETUP_EN_ALL 0x00001000
52#define NETUP_CTRL_OFF (NETUP_CS1 | NETUP_CS0 | NETUP_WR | NETUP_RD)
53#define NETUP_CI_CTL 0x04
54#define NETUP_CI_RD 1
55
56
57static unsigned int ci_dbg;
58module_param(ci_dbg, int, 0644);
59MODULE_PARM_DESC(ci_dbg, "Enable CI debugging");
60
61#define ci_dbg_print(args...) \
62 do { \
63 if (ci_dbg) \
64 printk(KERN_DEBUG args); \
65 } while (0)
66
67/* stores all private variables for communication with CI */
68struct netup_ci_state {
69 struct dvb_ca_en50221 ca;
70 struct mutex ca_mutex;
71 struct i2c_adapter *i2c_adap;
72 u8 ci_i2c_addr;
73 int status;
74 struct work_struct work;
75 void *priv;
76};
77
78struct mutex gpio_mutex;/* Two CiMax's uses same GPIO lines */
79
80int netup_read_i2c(struct i2c_adapter *i2c_adap, u8 addr, u8 reg,
81 u8 *buf, int len)
82{
83 int ret;
84 struct i2c_msg msg[] = {
85 {
86 .addr = addr,
87 .flags = 0,
88 .buf = &reg,
89 .len = 1
90 }, {
91 .addr = addr,
92 .flags = I2C_M_RD,
93 .buf = buf,
94 .len = len
95 }
96 };
97
98 ret = i2c_transfer(i2c_adap, msg, 2);
99
100 if (ret != 2) {
101 ci_dbg_print("%s: i2c read error, Reg = 0x%02x, Status = %d\n",
102 __func__, reg, ret);
103
104 return -1;
105 }
106
107 ci_dbg_print("%s: i2c read Addr=0x%04x, Reg = 0x%02x, data = %02x\n",
108 __func__, addr, reg, buf[0]);
109
110 return 0;
111}
112
113int netup_write_i2c(struct i2c_adapter *i2c_adap, u8 addr, u8 reg,
114 u8 *buf, int len)
115{
116 int ret;
117 u8 buffer[len + 1];
118
119 struct i2c_msg msg = {
120 .addr = addr,
121 .flags = 0,
122 .buf = &buffer[0],
123 .len = len + 1
124 };
125
126 buffer[0] = reg;
127 memcpy(&buffer[1], buf, len);
128
129 ret = i2c_transfer(i2c_adap, &msg, 1);
130
131 if (ret != 1) {
132 ci_dbg_print("%s: i2c write error, Reg=[0x%02x], Status=%d\n",
133 __func__, reg, ret);
134 return -1;
135 }
136
137 return 0;
138}
139
140int netup_ci_get_mem(struct cx23885_dev *dev)
141{
142 int mem;
143 unsigned long timeout = jiffies + msecs_to_jiffies(1);
144
145 for (;;) {
146 mem = cx_read(MC417_RWD);
147 if ((mem & NETUP_ACK) == 0)
148 break;
149 if (time_after(jiffies, timeout))
150 break;
151 udelay(1);
152 }
153
154 cx_set(MC417_RWD, NETUP_CTRL_OFF);
155
156 return mem & 0xff;
157}
158
159int netup_ci_op_cam(struct dvb_ca_en50221 *en50221, int slot,
160 u8 flag, u8 read, int addr, u8 data)
161{
162 struct netup_ci_state *state = en50221->data;
163 struct cx23885_tsport *port = state->priv;
164 struct cx23885_dev *dev = port->dev;
165
166 u8 store;
167 int mem;
168 int ret;
169
170 if (0 != slot)
171 return -EINVAL;
172
173 ret = netup_read_i2c(state->i2c_adap, state->ci_i2c_addr,
174 0, &store, 1);
175 if (ret != 0)
176 return ret;
177
178 store &= ~0x0c;
179 store |= flag;
180
181 ret = netup_write_i2c(state->i2c_adap, state->ci_i2c_addr,
182 0, &store, 1);
183 if (ret != 0)
184 return ret;
185
186 mutex_lock(&gpio_mutex);
187
188 /* write addr */
189 cx_write(MC417_OEN, NETUP_EN_ALL);
190 cx_write(MC417_RWD, NETUP_CTRL_OFF |
191 NETUP_ADLO | (0xff & addr));
192 cx_clear(MC417_RWD, NETUP_ADLO);
193 cx_write(MC417_RWD, NETUP_CTRL_OFF |
194 NETUP_ADHI | (0xff & (addr >> 8)));
195 cx_clear(MC417_RWD, NETUP_ADHI);
196
197 if (read) /* data in */
198 cx_write(MC417_OEN, NETUP_EN_ALL | NETUP_DATA);
199 else /* data out */
200 cx_write(MC417_RWD, NETUP_CTRL_OFF | data);
201
202 /* choose chip */
203 cx_clear(MC417_RWD,
204 (state->ci_i2c_addr == 0x40) ? NETUP_CS0 : NETUP_CS1);
205 /* read/write */
206 cx_clear(MC417_RWD, (read) ? NETUP_RD : NETUP_WR);
207 mem = netup_ci_get_mem(dev);
208
209 mutex_unlock(&gpio_mutex);
210
211 if (!read)
212 if (mem < 0)
213 return -EREMOTEIO;
214
215 ci_dbg_print("%s: %s: addr=[0x%02x], %s=%x\n", __func__,
216 (read) ? "read" : "write", addr,
217 (flag == NETUP_CI_CTL) ? "ctl" : "mem",
218 (read) ? mem : data);
219
220 if (read)
221 return mem;
222
223 return 0;
224}
225
226int netup_ci_read_attribute_mem(struct dvb_ca_en50221 *en50221,
227 int slot, int addr)
228{
229 return netup_ci_op_cam(en50221, slot, 0, NETUP_CI_RD, addr, 0);
230}
231
232int netup_ci_write_attribute_mem(struct dvb_ca_en50221 *en50221,
233 int slot, int addr, u8 data)
234{
235 return netup_ci_op_cam(en50221, slot, 0, 0, addr, data);
236}
237
238int netup_ci_read_cam_ctl(struct dvb_ca_en50221 *en50221, int slot, u8 addr)
239{
240 return netup_ci_op_cam(en50221, slot, NETUP_CI_CTL,
241 NETUP_CI_RD, addr, 0);
242}
243
244int netup_ci_write_cam_ctl(struct dvb_ca_en50221 *en50221, int slot,
245 u8 addr, u8 data)
246{
247 return netup_ci_op_cam(en50221, slot, NETUP_CI_CTL, 0, addr, data);
248}
249
250int netup_ci_slot_reset(struct dvb_ca_en50221 *en50221, int slot)
251{
252 struct netup_ci_state *state = en50221->data;
253 u8 buf = 0x80;
254 int ret;
255
256 if (0 != slot)
257 return -EINVAL;
258
259 udelay(500);
260 ret = netup_write_i2c(state->i2c_adap, state->ci_i2c_addr,
261 0, &buf, 1);
262
263 if (ret != 0)
264 return ret;
265
266 udelay(500);
267
268 buf = 0x00;
269 ret = netup_write_i2c(state->i2c_adap, state->ci_i2c_addr,
270 0, &buf, 1);
271
272 msleep(1000);
273 dvb_ca_en50221_camready_irq(&state->ca, 0);
274
275 return 0;
276
277}
278
279int netup_ci_slot_shutdown(struct dvb_ca_en50221 *en50221, int slot)
280{
281 /* not implemented */
282 return 0;
283}
284
285int netup_ci_slot_ts_ctl(struct dvb_ca_en50221 *en50221, int slot)
286{
287 struct netup_ci_state *state = en50221->data;
288 u8 buf = 0x60;
289
290 if (0 != slot)
291 return -EINVAL;
292
293 return netup_write_i2c(state->i2c_adap, state->ci_i2c_addr,
294 0, &buf, 1);
295}
296
297/* work handler */
298static void netup_read_ci_status(struct work_struct *work)
299{
300 struct netup_ci_state *state =
301 container_of(work, struct netup_ci_state, work);
302 u8 buf[33];
303 int ret;
304
305 ret = netup_read_i2c(state->i2c_adap, state->ci_i2c_addr,
306 0, &buf[0], 33);
307
308 if (ret != 0)
309 return;
310
311 ci_dbg_print("%s: Slot Status Addr=[0x%04x], Reg=[0x%02x], data=%02x, "
312 "TS config = %02x\n", __func__, state->ci_i2c_addr, 0, buf[0],
313 buf[32]);
314
315 if (buf[0] && 1)
316 state->status = DVB_CA_EN50221_POLL_CAM_PRESENT |
317 DVB_CA_EN50221_POLL_CAM_READY;
318 else
319 state->status = 0;
320}
321
322/* CI irq handler */
323int netup_ci_slot_status(struct cx23885_dev *dev, u32 pci_status)
324{
325 struct cx23885_tsport *port = NULL;
326 struct netup_ci_state *state = NULL;
327
328 if (pci_status & PCI_MSK_GPIO0)
329 port = &dev->ts1;
330 else if (pci_status & PCI_MSK_GPIO1)
331 port = &dev->ts2;
332 else /* who calls ? */
333 return 0;
334
335 state = port->port_priv;
336
337 schedule_work(&state->work);
338
339 return 1;
340}
341
342int netup_poll_ci_slot_status(struct dvb_ca_en50221 *en50221, int slot, int open)
343{
344 struct netup_ci_state *state = en50221->data;
345
346 if (0 != slot)
347 return -EINVAL;
348
349 return state->status;
350}
351
352int netup_ci_init(struct cx23885_tsport *port)
353{
354 struct netup_ci_state *state;
355 u8 cimax_init[34] = {
356 0x00, /* module A control*/
357 0x00, /* auto select mask high A */
358 0x00, /* auto select mask low A */
359 0x00, /* auto select pattern high A */
360 0x00, /* auto select pattern low A */
361 0x44, /* memory access time A */
362 0x00, /* invert input A */
363 0x00, /* RFU */
364 0x00, /* RFU */
365 0x00, /* module B control*/
366 0x00, /* auto select mask high B */
367 0x00, /* auto select mask low B */
368 0x00, /* auto select pattern high B */
369 0x00, /* auto select pattern low B */
370 0x44, /* memory access time B */
371 0x00, /* invert input B */
372 0x00, /* RFU */
373 0x00, /* RFU */
374 0x00, /* auto select mask high Ext */
375 0x00, /* auto select mask low Ext */
376 0x00, /* auto select pattern high Ext */
377 0x00, /* auto select pattern low Ext */
378 0x00, /* RFU */
379 0x02, /* destination - module A */
380 0x01, /* power on (use it like store place) */
381 0x00, /* RFU */
382 0x00, /* int status read only */
383 0x01, /* all int unmasked */
384 0x04, /* int config */
385 0x00, /* USCG1 */
386 0x04, /* ack active low */
387 0x00, /* LOCK = 0 */
388 0x33, /* serial mode, rising in, rising out, MSB first*/
389 0x31, /* syncronization */
390 };
391 int ret;
392
393 ci_dbg_print("%s\n", __func__);
394 state = kzalloc(sizeof(struct netup_ci_state), GFP_KERNEL);
395 if (!state) {
396 ci_dbg_print("%s: Unable create CI structure!\n", __func__);
397 ret = -ENOMEM;
398 goto err;
399 }
400
401 port->port_priv = state;
402
403 switch (port->nr) {
404 case 1:
405 state->ci_i2c_addr = 0x40;
406 mutex_init(&gpio_mutex);
407 break;
408 case 2:
409 state->ci_i2c_addr = 0x41;
410 break;
411 }
412
413 state->i2c_adap = &port->dev->i2c_bus[0].i2c_adap;
414 state->ca.owner = THIS_MODULE;
415 state->ca.read_attribute_mem = netup_ci_read_attribute_mem;
416 state->ca.write_attribute_mem = netup_ci_write_attribute_mem;
417 state->ca.read_cam_control = netup_ci_read_cam_ctl;
418 state->ca.write_cam_control = netup_ci_write_cam_ctl;
419 state->ca.slot_reset = netup_ci_slot_reset;
420 state->ca.slot_shutdown = netup_ci_slot_shutdown;
421 state->ca.slot_ts_enable = netup_ci_slot_ts_ctl;
422 state->ca.poll_slot_status = netup_poll_ci_slot_status;
423 state->ca.data = state;
424 state->priv = port;
425
426 ret = netup_write_i2c(state->i2c_adap, state->ci_i2c_addr,
427 0, &cimax_init[0], 34);
428 /* lock registers */
429 ret |= netup_write_i2c(state->i2c_adap, state->ci_i2c_addr,
430 0x1f, &cimax_init[0x18], 1);
431 /* power on slots */
432 ret |= netup_write_i2c(state->i2c_adap, state->ci_i2c_addr,
433 0x18, &cimax_init[0x18], 1);
434
435 if (0 != ret)
436 goto err;
437
438 ret = dvb_ca_en50221_init(&port->frontends.adapter,
439 &state->ca,
440 /* flags */ 0,
441 /* n_slots */ 1);
442 if (0 != ret)
443 goto err;
444
445 INIT_WORK(&state->work, netup_read_ci_status);
446
447 ci_dbg_print("%s: CI initialized!\n", __func__);
448
449 return 0;
450err:
451 ci_dbg_print("%s: Cannot initialize CI: Error %d.\n", __func__, ret);
452 kfree(state);
453 return ret;
454}
455
456void netup_ci_exit(struct cx23885_tsport *port)
457{
458 struct netup_ci_state *state;
459
460 if (NULL == port)
461 return;
462
463 state = (struct netup_ci_state *)port->port_priv;
464 if (NULL == state)
465 return;
466
467 if (NULL == state->ca.data)
468 return;
469
470 dvb_ca_en50221_release(&state->ca);
471 kfree(state);
472}
diff --git a/drivers/media/video/cx23885/cimax2.h b/drivers/media/video/cx23885/cimax2.h
new file mode 100644
index 000000000000..518744a4c8a5
--- /dev/null
+++ b/drivers/media/video/cx23885/cimax2.h
@@ -0,0 +1,47 @@
1/*
2 * cimax2.h
3 *
4 * CIMax(R) SP2 driver in conjunction with NetUp Dual DVB-S2 CI card
5 *
6 * Copyright (C) 2009 NetUP Inc.
7 * Copyright (C) 2009 Igor M. Liplianin <liplianin@netup.ru>
8 * Copyright (C) 2009 Abylay Ospan <aospan@netup.ru>
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 *
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25
26#ifndef CIMAX2_H
27#define CIMAX2_H
28#include "dvb_ca_en50221.h"
29
30extern int netup_ci_read_attribute_mem(struct dvb_ca_en50221 *en50221,
31 int slot, int addr);
32extern int netup_ci_write_attribute_mem(struct dvb_ca_en50221 *en50221,
33 int slot, int addr, u8 data);
34extern int netup_ci_read_cam_ctl(struct dvb_ca_en50221 *en50221,
35 int slot, u8 addr);
36extern int netup_ci_write_cam_ctl(struct dvb_ca_en50221 *en50221,
37 int slot, u8 addr, u8 data);
38extern int netup_ci_slot_reset(struct dvb_ca_en50221 *en50221, int slot);
39extern int netup_ci_slot_shutdown(struct dvb_ca_en50221 *en50221, int slot);
40extern int netup_ci_slot_ts_ctl(struct dvb_ca_en50221 *en50221, int slot);
41extern int netup_ci_slot_status(struct cx23885_dev *dev, u32 pci_status);
42extern int netup_poll_ci_slot_status(struct dvb_ca_en50221 *en50221,
43 int slot, int open);
44extern int netup_ci_init(struct cx23885_tsport *port);
45extern void netup_ci_exit(struct cx23885_tsport *port);
46
47#endif
diff --git a/drivers/media/video/cx23885/cx23885-417.c b/drivers/media/video/cx23885/cx23885-417.c
index bfe25841dbf4..6f5df90af93e 100644
--- a/drivers/media/video/cx23885/cx23885-417.c
+++ b/drivers/media/video/cx23885/cx23885-417.c
@@ -896,7 +896,7 @@ static int cx23885_load_firmware(struct cx23885_dev *dev)
896 if (retval != 0) { 896 if (retval != 0) {
897 printk(KERN_ERR 897 printk(KERN_ERR
898 "ERROR: Hotplug firmware request failed (%s).\n", 898 "ERROR: Hotplug firmware request failed (%s).\n",
899 CX2341X_FIRM_ENC_FILENAME); 899 CX23885_FIRM_IMAGE_NAME);
900 printk(KERN_ERR "Please fix your hotplug setup, the board will " 900 printk(KERN_ERR "Please fix your hotplug setup, the board will "
901 "not work without firmware loaded!\n"); 901 "not work without firmware loaded!\n");
902 return -1; 902 return -1;
@@ -1198,21 +1198,16 @@ static int vidioc_enum_input(struct file *file, void *priv,
1198 struct cx23885_fh *fh = file->private_data; 1198 struct cx23885_fh *fh = file->private_data;
1199 struct cx23885_dev *dev = fh->dev; 1199 struct cx23885_dev *dev = fh->dev;
1200 struct cx23885_input *input; 1200 struct cx23885_input *input;
1201 unsigned int n; 1201 int n;
1202 1202
1203 n = i->index; 1203 if (i->index >= 4)
1204
1205 if (n >= 4)
1206 return -EINVAL; 1204 return -EINVAL;
1207 1205
1208 input = &cx23885_boards[dev->board].input[n]; 1206 input = &cx23885_boards[dev->board].input[i->index];
1209 1207
1210 if (input->type == 0) 1208 if (input->type == 0)
1211 return -EINVAL; 1209 return -EINVAL;
1212 1210
1213 memset(i, 0, sizeof(*i));
1214 i->index = n;
1215
1216 /* FIXME 1211 /* FIXME
1217 * strcpy(i->name, input->name); */ 1212 * strcpy(i->name, input->name); */
1218 strcpy(i->name, "unset"); 1213 strcpy(i->name, "unset");
@@ -1255,10 +1250,8 @@ static int vidioc_g_tuner(struct file *file, void *priv,
1255 return -EINVAL; 1250 return -EINVAL;
1256 if (0 != t->index) 1251 if (0 != t->index)
1257 return -EINVAL; 1252 return -EINVAL;
1258 memset(t, 0, sizeof(*t));
1259 strcpy(t->name, "Television"); 1253 strcpy(t->name, "Television");
1260 cx23885_call_i2c_clients(&dev->i2c_bus[2], VIDIOC_G_TUNER, t); 1254 call_all(dev, tuner, g_tuner, t);
1261 cx23885_call_i2c_clients(&dev->i2c_bus[1], VIDIOC_G_TUNER, t);
1262 1255
1263 dprintk(1, "VIDIOC_G_TUNER: tuner type %d\n", t->type); 1256 dprintk(1, "VIDIOC_G_TUNER: tuner type %d\n", t->type);
1264 1257
@@ -1275,7 +1268,7 @@ static int vidioc_s_tuner(struct file *file, void *priv,
1275 return -EINVAL; 1268 return -EINVAL;
1276 1269
1277 /* Update the A/V core */ 1270 /* Update the A/V core */
1278 cx23885_call_i2c_clients(&dev->i2c_bus[2], VIDIOC_S_TUNER, t); 1271 call_all(dev, tuner, s_tuner, t);
1279 1272
1280 return 0; 1273 return 0;
1281} 1274}
@@ -1286,14 +1279,12 @@ static int vidioc_g_frequency(struct file *file, void *priv,
1286 struct cx23885_fh *fh = file->private_data; 1279 struct cx23885_fh *fh = file->private_data;
1287 struct cx23885_dev *dev = fh->dev; 1280 struct cx23885_dev *dev = fh->dev;
1288 1281
1289 memset(f, 0, sizeof(*f));
1290 if (UNSET == dev->tuner_type) 1282 if (UNSET == dev->tuner_type)
1291 return -EINVAL; 1283 return -EINVAL;
1292 f->type = V4L2_TUNER_ANALOG_TV; 1284 f->type = V4L2_TUNER_ANALOG_TV;
1293 f->frequency = dev->freq; 1285 f->frequency = dev->freq;
1294 1286
1295 /* Assumption that tuner is always on bus 1 */ 1287 call_all(dev, tuner, g_frequency, f);
1296 cx23885_call_i2c_clients(&dev->i2c_bus[1], VIDIOC_G_FREQUENCY, f);
1297 1288
1298 return 0; 1289 return 0;
1299} 1290}
@@ -1320,8 +1311,7 @@ static int vidioc_s_frequency(struct file *file, void *priv,
1320 return -EINVAL; 1311 return -EINVAL;
1321 dev->freq = f->frequency; 1312 dev->freq = f->frequency;
1322 1313
1323 /* Assumption that tuner is always on bus 1 */ 1314 call_all(dev, tuner, s_frequency, f);
1324 cx23885_call_i2c_clients(&dev->i2c_bus[1], VIDIOC_S_FREQUENCY, f);
1325 1315
1326 cx23885_initialize_codec(dev); 1316 cx23885_initialize_codec(dev);
1327 1317
@@ -1335,7 +1325,7 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
1335 struct cx23885_dev *dev = fh->dev; 1325 struct cx23885_dev *dev = fh->dev;
1336 1326
1337 /* Update the A/V core */ 1327 /* Update the A/V core */
1338 cx23885_call_i2c_clients(&dev->i2c_bus[2], VIDIOC_S_CTRL, ctl); 1328 call_all(dev, core, s_ctrl, ctl);
1339 return 0; 1329 return 0;
1340} 1330}
1341 1331
@@ -1346,7 +1336,6 @@ static int vidioc_querycap(struct file *file, void *priv,
1346 struct cx23885_dev *dev = fh->dev; 1336 struct cx23885_dev *dev = fh->dev;
1347 struct cx23885_tsport *tsport = &dev->ts1; 1337 struct cx23885_tsport *tsport = &dev->ts1;
1348 1338
1349 memset(cap, 0, sizeof(*cap));
1350 strcpy(cap->driver, dev->name); 1339 strcpy(cap->driver, dev->name);
1351 strlcpy(cap->card, cx23885_boards[tsport->dev->board].name, 1340 strlcpy(cap->card, cx23885_boards[tsport->dev->board].name,
1352 sizeof(cap->card)); 1341 sizeof(cap->card));
@@ -1366,16 +1355,10 @@ static int vidioc_querycap(struct file *file, void *priv,
1366static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv, 1355static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
1367 struct v4l2_fmtdesc *f) 1356 struct v4l2_fmtdesc *f)
1368{ 1357{
1369 int index; 1358 if (f->index != 0)
1370
1371 index = f->index;
1372 if (index != 0)
1373 return -EINVAL; 1359 return -EINVAL;
1374 1360
1375 memset(f, 0, sizeof(*f));
1376 f->index = index;
1377 strlcpy(f->description, "MPEG", sizeof(f->description)); 1361 strlcpy(f->description, "MPEG", sizeof(f->description));
1378 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1379 f->pixelformat = V4L2_PIX_FMT_MPEG; 1362 f->pixelformat = V4L2_PIX_FMT_MPEG;
1380 1363
1381 return 0; 1364 return 0;
@@ -1387,8 +1370,6 @@ static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
1387 struct cx23885_fh *fh = file->private_data; 1370 struct cx23885_fh *fh = file->private_data;
1388 struct cx23885_dev *dev = fh->dev; 1371 struct cx23885_dev *dev = fh->dev;
1389 1372
1390 memset(f, 0, sizeof(*f));
1391 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1392 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG; 1373 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
1393 f->fmt.pix.bytesperline = 0; 1374 f->fmt.pix.bytesperline = 0;
1394 f->fmt.pix.sizeimage = 1375 f->fmt.pix.sizeimage =
@@ -1408,12 +1389,10 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
1408 struct cx23885_fh *fh = file->private_data; 1389 struct cx23885_fh *fh = file->private_data;
1409 struct cx23885_dev *dev = fh->dev; 1390 struct cx23885_dev *dev = fh->dev;
1410 1391
1411 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1412 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG; 1392 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
1413 f->fmt.pix.bytesperline = 0; 1393 f->fmt.pix.bytesperline = 0;
1414 f->fmt.pix.sizeimage = 1394 f->fmt.pix.sizeimage =
1415 dev->ts1.ts_packet_size * dev->ts1.ts_packet_count; 1395 dev->ts1.ts_packet_size * dev->ts1.ts_packet_count;
1416 f->fmt.pix.sizeimage =
1417 f->fmt.pix.colorspace = 0; 1396 f->fmt.pix.colorspace = 0;
1418 dprintk(1, "VIDIOC_TRY_FMT: w: %d, h: %d, f: %d\n", 1397 dprintk(1, "VIDIOC_TRY_FMT: w: %d, h: %d, f: %d\n",
1419 dev->ts1.width, dev->ts1.height, fh->mpegq.field); 1398 dev->ts1.width, dev->ts1.height, fh->mpegq.field);
@@ -1426,7 +1405,6 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
1426 struct cx23885_fh *fh = file->private_data; 1405 struct cx23885_fh *fh = file->private_data;
1427 struct cx23885_dev *dev = fh->dev; 1406 struct cx23885_dev *dev = fh->dev;
1428 1407
1429 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1430 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG; 1408 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
1431 f->fmt.pix.bytesperline = 0; 1409 f->fmt.pix.bytesperline = 0;
1432 f->fmt.pix.sizeimage = 1410 f->fmt.pix.sizeimage =
@@ -1543,12 +1521,7 @@ static int vidioc_log_status(struct file *file, void *priv)
1543 printk(KERN_INFO 1521 printk(KERN_INFO
1544 "%s/2: ============ START LOG STATUS ============\n", 1522 "%s/2: ============ START LOG STATUS ============\n",
1545 dev->name); 1523 dev->name);
1546 cx23885_call_i2c_clients(&dev->i2c_bus[0], VIDIOC_LOG_STATUS, 1524 call_all(dev, core, log_status);
1547 NULL);
1548 cx23885_call_i2c_clients(&dev->i2c_bus[1], VIDIOC_LOG_STATUS,
1549 NULL);
1550 cx23885_call_i2c_clients(&dev->i2c_bus[2], VIDIOC_LOG_STATUS,
1551 NULL);
1552 cx2341x_log_status(&dev->mpeg_params, name); 1525 cx2341x_log_status(&dev->mpeg_params, name);
1553 printk(KERN_INFO 1526 printk(KERN_INFO
1554 "%s/2: ============= END LOG STATUS =============\n", 1527 "%s/2: ============= END LOG STATUS =============\n",
diff --git a/drivers/media/video/cx23885/cx23885-cards.c b/drivers/media/video/cx23885/cx23885-cards.c
index caa098beeecf..5e4b7e790d94 100644
--- a/drivers/media/video/cx23885/cx23885-cards.c
+++ b/drivers/media/video/cx23885/cx23885-cards.c
@@ -27,6 +27,7 @@
27 27
28#include "cx23885.h" 28#include "cx23885.h"
29#include "tuner-xc2028.h" 29#include "tuner-xc2028.h"
30#include "netup-init.h"
30 31
31/* ------------------------------------------------------------------ */ 32/* ------------------------------------------------------------------ */
32/* board config info */ 33/* board config info */
@@ -162,6 +163,24 @@ struct cx23885_board cx23885_boards[] = {
162 .name = "Compro VideoMate E650F", 163 .name = "Compro VideoMate E650F",
163 .portc = CX23885_MPEG_DVB, 164 .portc = CX23885_MPEG_DVB,
164 }, 165 },
166 [CX23885_BOARD_TBS_6920] = {
167 .name = "TurboSight TBS 6920",
168 .portb = CX23885_MPEG_DVB,
169 },
170 [CX23885_BOARD_TEVII_S470] = {
171 .name = "TeVii S470",
172 .portb = CX23885_MPEG_DVB,
173 },
174 [CX23885_BOARD_DVBWORLD_2005] = {
175 .name = "DVBWorld DVB-S2 2005",
176 .portb = CX23885_MPEG_DVB,
177 },
178 [CX23885_BOARD_NETUP_DUAL_DVBS2_CI] = {
179 .cimax = 1,
180 .name = "NetUP Dual DVB-S2 CI",
181 .portb = CX23885_MPEG_DVB,
182 .portc = CX23885_MPEG_DVB,
183 },
165}; 184};
166const unsigned int cx23885_bcount = ARRAY_SIZE(cx23885_boards); 185const unsigned int cx23885_bcount = ARRAY_SIZE(cx23885_boards);
167 186
@@ -245,6 +264,22 @@ struct cx23885_subid cx23885_subids[] = {
245 .subvendor = 0x185b, 264 .subvendor = 0x185b,
246 .subdevice = 0xe800, 265 .subdevice = 0xe800,
247 .card = CX23885_BOARD_COMPRO_VIDEOMATE_E650F, 266 .card = CX23885_BOARD_COMPRO_VIDEOMATE_E650F,
267 }, {
268 .subvendor = 0x6920,
269 .subdevice = 0x8888,
270 .card = CX23885_BOARD_TBS_6920,
271 }, {
272 .subvendor = 0xd470,
273 .subdevice = 0x9022,
274 .card = CX23885_BOARD_TEVII_S470,
275 }, {
276 .subvendor = 0x0001,
277 .subdevice = 0x2005,
278 .card = CX23885_BOARD_DVBWORLD_2005,
279 }, {
280 .subvendor = 0x1b55,
281 .subdevice = 0x2a2c,
282 .card = CX23885_BOARD_NETUP_DUAL_DVBS2_CI,
248 }, 283 },
249}; 284};
250const unsigned int cx23885_idcount = ARRAY_SIZE(cx23885_subids); 285const unsigned int cx23885_idcount = ARRAY_SIZE(cx23885_subids);
@@ -552,6 +587,38 @@ void cx23885_gpio_setup(struct cx23885_dev *dev)
552 mdelay(20); 587 mdelay(20);
553 cx_set(GP0_IO, 0x00040004); 588 cx_set(GP0_IO, 0x00040004);
554 break; 589 break;
590 case CX23885_BOARD_TBS_6920:
591 case CX23885_BOARD_TEVII_S470:
592 cx_write(MC417_CTL, 0x00000036);
593 cx_write(MC417_OEN, 0x00001000);
594 cx_write(MC417_RWD, 0x00001800);
595 break;
596 case CX23885_BOARD_NETUP_DUAL_DVBS2_CI:
597 /* GPIO-0 INTA from CiMax1
598 GPIO-1 INTB from CiMax2
599 GPIO-2 reset chips
600 GPIO-3 to GPIO-10 data/addr for CA
601 GPIO-11 ~CS0 to CiMax1
602 GPIO-12 ~CS1 to CiMax2
603 GPIO-13 ADL0 load LSB addr
604 GPIO-14 ADL1 load MSB addr
605 GPIO-15 ~RDY from CiMax
606 GPIO-17 ~RD to CiMax
607 GPIO-18 ~WR to CiMax
608 */
609 cx_set(GP0_IO, 0x00040000); /* GPIO as out */
610 /* GPIO1 and GPIO2 as INTA and INTB from CiMaxes, reset low */
611 cx_clear(GP0_IO, 0x00030004);
612 mdelay(100);/* reset delay */
613 cx_set(GP0_IO, 0x00040004); /* GPIO as out, reset high */
614 cx_write(MC417_CTL, 0x00000037);/* enable GPIO3-18 pins */
615 /* GPIO-15 IN as ~ACK, rest as OUT */
616 cx_write(MC417_OEN, 0x00001000);
617 /* ~RD, ~WR high; ADL0, ADL1 low; ~CS0, ~CS1 high */
618 cx_write(MC417_RWD, 0x0000c300);
619 /* enable irq */
620 cx_write(GPIO_ISM, 0x00000000);/* INTERRUPTS active low*/
621 break;
555 } 622 }
556} 623}
557 624
@@ -632,6 +699,21 @@ void cx23885_card_setup(struct cx23885_dev *dev)
632 ts2->ts_clk_en_val = 0x1; /* Enable TS_CLK */ 699 ts2->ts_clk_en_val = 0x1; /* Enable TS_CLK */
633 ts2->src_sel_val = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO; 700 ts2->src_sel_val = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO;
634 break; 701 break;
702 case CX23885_BOARD_TEVII_S470:
703 case CX23885_BOARD_TBS_6920:
704 case CX23885_BOARD_DVBWORLD_2005:
705 ts1->gen_ctrl_val = 0x5; /* Parallel */
706 ts1->ts_clk_en_val = 0x1; /* Enable TS_CLK */
707 ts1->src_sel_val = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO;
708 break;
709 case CX23885_BOARD_NETUP_DUAL_DVBS2_CI:
710 ts1->gen_ctrl_val = 0xc; /* Serial bus + punctured clock */
711 ts1->ts_clk_en_val = 0x1; /* Enable TS_CLK */
712 ts1->src_sel_val = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO;
713 ts2->gen_ctrl_val = 0xc; /* Serial bus + punctured clock */
714 ts2->ts_clk_en_val = 0x1; /* Enable TS_CLK */
715 ts2->src_sel_val = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO;
716 break;
635 case CX23885_BOARD_HAUPPAUGE_HVR1250: 717 case CX23885_BOARD_HAUPPAUGE_HVR1250:
636 case CX23885_BOARD_HAUPPAUGE_HVR1500: 718 case CX23885_BOARD_HAUPPAUGE_HVR1500:
637 case CX23885_BOARD_HAUPPAUGE_HVR1500Q: 719 case CX23885_BOARD_HAUPPAUGE_HVR1500Q:
@@ -656,7 +738,17 @@ void cx23885_card_setup(struct cx23885_dev *dev)
656 case CX23885_BOARD_HAUPPAUGE_HVR1700: 738 case CX23885_BOARD_HAUPPAUGE_HVR1700:
657 case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H: 739 case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H:
658 case CX23885_BOARD_COMPRO_VIDEOMATE_E650F: 740 case CX23885_BOARD_COMPRO_VIDEOMATE_E650F:
659 request_module("cx25840"); 741 case CX23885_BOARD_NETUP_DUAL_DVBS2_CI:
742 dev->sd_cx25840 = v4l2_i2c_new_subdev(&dev->i2c_bus[2].i2c_adap,
743 "cx25840", "cx25840", 0x88 >> 1);
744 v4l2_subdev_call(dev->sd_cx25840, core, init, 0);
745 break;
746 }
747
748 /* AUX-PLL 27MHz CLK */
749 switch (dev->board) {
750 case CX23885_BOARD_NETUP_DUAL_DVBS2_CI:
751 netup_initialize(dev);
660 break; 752 break;
661 } 753 }
662} 754}
diff --git a/drivers/media/video/cx23885/cx23885-core.c b/drivers/media/video/cx23885/cx23885-core.c
index 8f6fb2add7de..dc7fff22cfdd 100644
--- a/drivers/media/video/cx23885/cx23885-core.c
+++ b/drivers/media/video/cx23885/cx23885-core.c
@@ -31,6 +31,7 @@
31#include <asm/div64.h> 31#include <asm/div64.h>
32 32
33#include "cx23885.h" 33#include "cx23885.h"
34#include "cimax2.h"
34 35
35MODULE_DESCRIPTION("Driver for cx23885 based TV cards"); 36MODULE_DESCRIPTION("Driver for cx23885 based TV cards");
36MODULE_AUTHOR("Steven Toth <stoth@linuxtv.org>"); 37MODULE_AUTHOR("Steven Toth <stoth@linuxtv.org>");
@@ -791,6 +792,8 @@ static int cx23885_dev_setup(struct cx23885_dev *dev)
791 dev->pci_bus = dev->pci->bus->number; 792 dev->pci_bus = dev->pci->bus->number;
792 dev->pci_slot = PCI_SLOT(dev->pci->devfn); 793 dev->pci_slot = PCI_SLOT(dev->pci->devfn);
793 dev->pci_irqmask = 0x001f00; 794 dev->pci_irqmask = 0x001f00;
795 if (cx23885_boards[dev->board].cimax > 0)
796 dev->pci_irqmask |= 0x01800000; /* for CiMaxes */
794 797
795 /* External Master 1 Bus */ 798 /* External Master 1 Bus */
796 dev->i2c_bus[0].nr = 0; 799 dev->i2c_bus[0].nr = 0;
@@ -872,7 +875,7 @@ static int cx23885_dev_setup(struct cx23885_dev *dev)
872 cx23885_i2c_register(&dev->i2c_bus[1]); 875 cx23885_i2c_register(&dev->i2c_bus[1]);
873 cx23885_i2c_register(&dev->i2c_bus[2]); 876 cx23885_i2c_register(&dev->i2c_bus[2]);
874 cx23885_card_setup(dev); 877 cx23885_card_setup(dev);
875 cx23885_call_i2c_clients(&dev->i2c_bus[0], TUNER_SET_STANDBY, NULL); 878 call_all(dev, core, s_standby, 0);
876 cx23885_ir_init(dev); 879 cx23885_ir_init(dev);
877 880
878 if (cx23885_boards[dev->board].porta == CX23885_ANALOG_VIDEO) { 881 if (cx23885_boards[dev->board].porta == CX23885_ANALOG_VIDEO) {
@@ -1643,7 +1646,9 @@ static irqreturn_t cx23885_irq(int irq, void *dev_id)
1643 (pci_status & PCI_MSK_VID_B) || 1646 (pci_status & PCI_MSK_VID_B) ||
1644 (pci_status & PCI_MSK_VID_A) || 1647 (pci_status & PCI_MSK_VID_A) ||
1645 (pci_status & PCI_MSK_AUD_INT) || 1648 (pci_status & PCI_MSK_AUD_INT) ||
1646 (pci_status & PCI_MSK_AUD_EXT)) { 1649 (pci_status & PCI_MSK_AUD_EXT) ||
1650 (pci_status & PCI_MSK_GPIO0) ||
1651 (pci_status & PCI_MSK_GPIO1)) {
1647 1652
1648 if (pci_status & PCI_MSK_RISC_RD) 1653 if (pci_status & PCI_MSK_RISC_RD)
1649 dprintk(7, " (PCI_MSK_RISC_RD 0x%08x)\n", 1654 dprintk(7, " (PCI_MSK_RISC_RD 0x%08x)\n",
@@ -1685,8 +1690,20 @@ static irqreturn_t cx23885_irq(int irq, void *dev_id)
1685 dprintk(7, " (PCI_MSK_AUD_EXT 0x%08x)\n", 1690 dprintk(7, " (PCI_MSK_AUD_EXT 0x%08x)\n",
1686 PCI_MSK_AUD_EXT); 1691 PCI_MSK_AUD_EXT);
1687 1692
1693 if (pci_status & PCI_MSK_GPIO0)
1694 dprintk(7, " (PCI_MSK_GPIO0 0x%08x)\n",
1695 PCI_MSK_GPIO0);
1696
1697 if (pci_status & PCI_MSK_GPIO1)
1698 dprintk(7, " (PCI_MSK_GPIO1 0x%08x)\n",
1699 PCI_MSK_GPIO1);
1688 } 1700 }
1689 1701
1702 if (cx23885_boards[dev->board].cimax > 0 &&
1703 ((pci_status & PCI_MSK_GPIO0) || (pci_status & PCI_MSK_GPIO1)))
1704 /* handled += cx23885_irq_gpio(dev, pci_status); */
1705 handled += netup_ci_slot_status(dev, pci_status);
1706
1690 if (ts1_status) { 1707 if (ts1_status) {
1691 if (cx23885_boards[dev->board].portb == CX23885_MPEG_DVB) 1708 if (cx23885_boards[dev->board].portb == CX23885_MPEG_DVB)
1692 handled += cx23885_irq_ts(ts1, ts1_status); 1709 handled += cx23885_irq_ts(ts1, ts1_status);
@@ -1722,16 +1739,20 @@ static int __devinit cx23885_initdev(struct pci_dev *pci_dev,
1722 if (NULL == dev) 1739 if (NULL == dev)
1723 return -ENOMEM; 1740 return -ENOMEM;
1724 1741
1742 err = v4l2_device_register(&pci_dev->dev, &dev->v4l2_dev);
1743 if (err < 0)
1744 goto fail_free;
1745
1725 /* pci init */ 1746 /* pci init */
1726 dev->pci = pci_dev; 1747 dev->pci = pci_dev;
1727 if (pci_enable_device(pci_dev)) { 1748 if (pci_enable_device(pci_dev)) {
1728 err = -EIO; 1749 err = -EIO;
1729 goto fail_free; 1750 goto fail_unreg;
1730 } 1751 }
1731 1752
1732 if (cx23885_dev_setup(dev) < 0) { 1753 if (cx23885_dev_setup(dev) < 0) {
1733 err = -EINVAL; 1754 err = -EINVAL;
1734 goto fail_free; 1755 goto fail_unreg;
1735 } 1756 }
1736 1757
1737 /* print pci info */ 1758 /* print pci info */
@@ -1758,11 +1779,18 @@ static int __devinit cx23885_initdev(struct pci_dev *pci_dev,
1758 goto fail_irq; 1779 goto fail_irq;
1759 } 1780 }
1760 1781
1761 pci_set_drvdata(pci_dev, dev); 1782 switch (dev->board) {
1783 case CX23885_BOARD_NETUP_DUAL_DVBS2_CI:
1784 cx_set(PCI_INT_MSK, 0x01800000); /* for NetUP */
1785 break;
1786 }
1787
1762 return 0; 1788 return 0;
1763 1789
1764fail_irq: 1790fail_irq:
1765 cx23885_dev_unregister(dev); 1791 cx23885_dev_unregister(dev);
1792fail_unreg:
1793 v4l2_device_unregister(&dev->v4l2_dev);
1766fail_free: 1794fail_free:
1767 kfree(dev); 1795 kfree(dev);
1768 return err; 1796 return err;
@@ -1770,7 +1798,8 @@ fail_free:
1770 1798
1771static void __devexit cx23885_finidev(struct pci_dev *pci_dev) 1799static void __devexit cx23885_finidev(struct pci_dev *pci_dev)
1772{ 1800{
1773 struct cx23885_dev *dev = pci_get_drvdata(pci_dev); 1801 struct v4l2_device *v4l2_dev = pci_get_drvdata(pci_dev);
1802 struct cx23885_dev *dev = to_cx23885(v4l2_dev);
1774 1803
1775 cx23885_shutdown(dev); 1804 cx23885_shutdown(dev);
1776 1805
@@ -1778,13 +1807,13 @@ static void __devexit cx23885_finidev(struct pci_dev *pci_dev)
1778 1807
1779 /* unregister stuff */ 1808 /* unregister stuff */
1780 free_irq(pci_dev->irq, dev); 1809 free_irq(pci_dev->irq, dev);
1781 pci_set_drvdata(pci_dev, NULL);
1782 1810
1783 mutex_lock(&devlist); 1811 mutex_lock(&devlist);
1784 list_del(&dev->devlist); 1812 list_del(&dev->devlist);
1785 mutex_unlock(&devlist); 1813 mutex_unlock(&devlist);
1786 1814
1787 cx23885_dev_unregister(dev); 1815 cx23885_dev_unregister(dev);
1816 v4l2_device_unregister(v4l2_dev);
1788 kfree(dev); 1817 kfree(dev);
1789} 1818}
1790 1819
diff --git a/drivers/media/video/cx23885/cx23885-dvb.c b/drivers/media/video/cx23885/cx23885-dvb.c
index 1c454128a9df..d43c74396767 100644
--- a/drivers/media/video/cx23885/cx23885-dvb.c
+++ b/drivers/media/video/cx23885/cx23885-dvb.c
@@ -30,6 +30,7 @@
30#include "cx23885.h" 30#include "cx23885.h"
31#include <media/v4l2-common.h> 31#include <media/v4l2-common.h>
32 32
33#include "dvb_ca_en50221.h"
33#include "s5h1409.h" 34#include "s5h1409.h"
34#include "s5h1411.h" 35#include "s5h1411.h"
35#include "mt2131.h" 36#include "mt2131.h"
@@ -43,6 +44,13 @@
43#include "dib7000p.h" 44#include "dib7000p.h"
44#include "dibx000_common.h" 45#include "dibx000_common.h"
45#include "zl10353.h" 46#include "zl10353.h"
47#include "stv0900.h"
48#include "stv6110.h"
49#include "lnbh24.h"
50#include "cx24116.h"
51#include "cimax2.h"
52#include "netup-eeprom.h"
53#include "netup-init.h"
46 54
47static unsigned int debug; 55static unsigned int debug;
48 56
@@ -308,11 +316,63 @@ static struct zl10353_config dvico_fusionhdtv_xc3028 = {
308 .no_tuner = 1, 316 .no_tuner = 1,
309}; 317};
310 318
319static struct stv0900_config netup_stv0900_config = {
320 .demod_address = 0x68,
321 .xtal = 27000000,
322 .clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */
323 .diseqc_mode = 2,/* 2/3 PWM */
324 .path1_mode = 2,/*Serial continues clock */
325 .path2_mode = 2,/*Serial continues clock */
326 .tun1_maddress = 0,/* 0x60 */
327 .tun2_maddress = 3,/* 0x63 */
328 .tun1_adc = 1,/* 1 Vpp */
329 .tun2_adc = 1,/* 1 Vpp */
330};
331
332static struct stv6110_config netup_stv6110_tunerconfig_a = {
333 .i2c_address = 0x60,
334 .mclk = 27000000,
335 .iq_wiring = 0,
336};
337
338static struct stv6110_config netup_stv6110_tunerconfig_b = {
339 .i2c_address = 0x63,
340 .mclk = 27000000,
341 .iq_wiring = 1,
342};
343
344static int tbs_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
345{
346 struct cx23885_tsport *port = fe->dvb->priv;
347 struct cx23885_dev *dev = port->dev;
348
349 if (voltage == SEC_VOLTAGE_18)
350 cx_write(MC417_RWD, 0x00001e00);/* GPIO-13 high */
351 else if (voltage == SEC_VOLTAGE_13)
352 cx_write(MC417_RWD, 0x00001a00);/* GPIO-13 low */
353 else
354 cx_write(MC417_RWD, 0x00001800);/* GPIO-12 low */
355 return 0;
356}
357
358static struct cx24116_config tbs_cx24116_config = {
359 .demod_address = 0x05,
360};
361
362static struct cx24116_config tevii_cx24116_config = {
363 .demod_address = 0x55,
364};
365
366static struct cx24116_config dvbworld_cx24116_config = {
367 .demod_address = 0x05,
368};
369
311static int dvb_register(struct cx23885_tsport *port) 370static int dvb_register(struct cx23885_tsport *port)
312{ 371{
313 struct cx23885_dev *dev = port->dev; 372 struct cx23885_dev *dev = port->dev;
314 struct cx23885_i2c *i2c_bus = NULL; 373 struct cx23885_i2c *i2c_bus = NULL;
315 struct videobuf_dvb_frontend *fe0; 374 struct videobuf_dvb_frontend *fe0;
375 int ret;
316 376
317 /* Get the first frontend */ 377 /* Get the first frontend */
318 fe0 = videobuf_dvb_get_frontend(&port->frontends, 1); 378 fe0 = videobuf_dvb_get_frontend(&port->frontends, 1);
@@ -526,6 +586,78 @@ static int dvb_register(struct cx23885_tsport *port)
526 fe->ops.tuner_ops.set_config(fe, &ctl); 586 fe->ops.tuner_ops.set_config(fe, &ctl);
527 } 587 }
528 break; 588 break;
589 case CX23885_BOARD_TBS_6920:
590 i2c_bus = &dev->i2c_bus[0];
591
592 fe0->dvb.frontend = dvb_attach(cx24116_attach,
593 &tbs_cx24116_config,
594 &i2c_bus->i2c_adap);
595 if (fe0->dvb.frontend != NULL)
596 fe0->dvb.frontend->ops.set_voltage = tbs_set_voltage;
597
598 break;
599 case CX23885_BOARD_TEVII_S470:
600 i2c_bus = &dev->i2c_bus[1];
601
602 fe0->dvb.frontend = dvb_attach(cx24116_attach,
603 &tevii_cx24116_config,
604 &i2c_bus->i2c_adap);
605 if (fe0->dvb.frontend != NULL)
606 fe0->dvb.frontend->ops.set_voltage = tbs_set_voltage;
607
608 break;
609 case CX23885_BOARD_DVBWORLD_2005:
610 i2c_bus = &dev->i2c_bus[1];
611
612 fe0->dvb.frontend = dvb_attach(cx24116_attach,
613 &dvbworld_cx24116_config,
614 &i2c_bus->i2c_adap);
615 break;
616 case CX23885_BOARD_NETUP_DUAL_DVBS2_CI:
617 i2c_bus = &dev->i2c_bus[0];
618 switch (port->nr) {
619 /* port B */
620 case 1:
621 fe0->dvb.frontend = dvb_attach(stv0900_attach,
622 &netup_stv0900_config,
623 &i2c_bus->i2c_adap, 0);
624 if (fe0->dvb.frontend != NULL) {
625 if (dvb_attach(stv6110_attach,
626 fe0->dvb.frontend,
627 &netup_stv6110_tunerconfig_a,
628 &i2c_bus->i2c_adap)) {
629 if (!dvb_attach(lnbh24_attach,
630 fe0->dvb.frontend,
631 &i2c_bus->i2c_adap,
632 LNBH24_PCL, 0, 0x09))
633 printk(KERN_ERR
634 "No LNBH24 found!\n");
635
636 }
637 }
638 break;
639 /* port C */
640 case 2:
641 fe0->dvb.frontend = dvb_attach(stv0900_attach,
642 &netup_stv0900_config,
643 &i2c_bus->i2c_adap, 1);
644 if (fe0->dvb.frontend != NULL) {
645 if (dvb_attach(stv6110_attach,
646 fe0->dvb.frontend,
647 &netup_stv6110_tunerconfig_b,
648 &i2c_bus->i2c_adap)) {
649 if (!dvb_attach(lnbh24_attach,
650 fe0->dvb.frontend,
651 &i2c_bus->i2c_adap,
652 LNBH24_PCL, 0, 0x0a))
653 printk(KERN_ERR
654 "No LNBH24 found!\n");
655
656 }
657 }
658 break;
659 }
660 break;
529 default: 661 default:
530 printk(KERN_INFO "%s: The frontend of your DVB/ATSC card " 662 printk(KERN_INFO "%s: The frontend of your DVB/ATSC card "
531 " isn't supported yet\n", 663 " isn't supported yet\n",
@@ -541,15 +673,39 @@ static int dvb_register(struct cx23885_tsport *port)
541 fe0->dvb.frontend->callback = cx23885_tuner_callback; 673 fe0->dvb.frontend->callback = cx23885_tuner_callback;
542 674
543 /* Put the analog decoder in standby to keep it quiet */ 675 /* Put the analog decoder in standby to keep it quiet */
544 cx23885_call_i2c_clients(i2c_bus, TUNER_SET_STANDBY, NULL); 676 call_all(dev, core, s_standby, 0);
545 677
546 if (fe0->dvb.frontend->ops.analog_ops.standby) 678 if (fe0->dvb.frontend->ops.analog_ops.standby)
547 fe0->dvb.frontend->ops.analog_ops.standby(fe0->dvb.frontend); 679 fe0->dvb.frontend->ops.analog_ops.standby(fe0->dvb.frontend);
548 680
549 /* register everything */ 681 /* register everything */
550 return videobuf_dvb_register_bus(&port->frontends, THIS_MODULE, port, 682 ret = videobuf_dvb_register_bus(&port->frontends, THIS_MODULE, port,
551 &dev->pci->dev, adapter_nr, 0); 683 &dev->pci->dev, adapter_nr, 0);
552 684
685 /* init CI & MAC */
686 switch (dev->board) {
687 case CX23885_BOARD_NETUP_DUAL_DVBS2_CI: {
688 static struct netup_card_info cinfo;
689
690 netup_get_card_info(&dev->i2c_bus[0].i2c_adap, &cinfo);
691 memcpy(port->frontends.adapter.proposed_mac,
692 cinfo.port[port->nr - 1].mac, 6);
693 printk(KERN_INFO "NetUP Dual DVB-S2 CI card port%d MAC="
694 "%02X:%02X:%02X:%02X:%02X:%02X\n",
695 port->nr,
696 port->frontends.adapter.proposed_mac[0],
697 port->frontends.adapter.proposed_mac[1],
698 port->frontends.adapter.proposed_mac[2],
699 port->frontends.adapter.proposed_mac[3],
700 port->frontends.adapter.proposed_mac[4],
701 port->frontends.adapter.proposed_mac[5]);
702
703 netup_ci_init(port);
704 break;
705 }
706 }
707
708 return ret;
553} 709}
554 710
555int cx23885_dvb_register(struct cx23885_tsport *port) 711int cx23885_dvb_register(struct cx23885_tsport *port)
@@ -622,6 +778,12 @@ int cx23885_dvb_unregister(struct cx23885_tsport *port)
622 if (fe0->dvb.frontend) 778 if (fe0->dvb.frontend)
623 videobuf_dvb_unregister_bus(&port->frontends); 779 videobuf_dvb_unregister_bus(&port->frontends);
624 780
781 switch (port->dev->board) {
782 case CX23885_BOARD_NETUP_DUAL_DVBS2_CI:
783 netup_ci_exit(port);
784 break;
785 }
786
625 return 0; 787 return 0;
626} 788}
627 789
diff --git a/drivers/media/video/cx23885/cx23885-i2c.c b/drivers/media/video/cx23885/cx23885-i2c.c
index bb7f71a1fcbe..3421bd12056a 100644
--- a/drivers/media/video/cx23885/cx23885-i2c.c
+++ b/drivers/media/video/cx23885/cx23885-i2c.c
@@ -268,64 +268,6 @@ static int i2c_xfer(struct i2c_adapter *i2c_adap,
268 return retval; 268 return retval;
269} 269}
270 270
271static int attach_inform(struct i2c_client *client)
272{
273 struct cx23885_i2c *bus = i2c_get_adapdata(client->adapter);
274 struct cx23885_dev *dev = bus->dev;
275 struct tuner_setup tun_setup;
276
277 dprintk(1, "%s i2c attach [addr=0x%x,client=%s]\n",
278 client->driver->driver.name, client->addr, client->name);
279
280 if (!client->driver->command)
281 return 0;
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
308 return 0;
309}
310
311static int detach_inform(struct i2c_client *client)
312{
313 struct cx23885_dev *dev = i2c_get_adapdata(client->adapter);
314
315 dprintk(1, "i2c detach [client=%s]\n", client->name);
316
317 return 0;
318}
319
320void cx23885_call_i2c_clients(struct cx23885_i2c *bus,
321 unsigned int cmd, void *arg)
322{
323 if (bus->i2c_rc != 0)
324 return;
325
326 i2c_clients_command(&bus->i2c_adap, cmd, arg);
327}
328
329static u32 cx23885_functionality(struct i2c_adapter *adap) 271static u32 cx23885_functionality(struct i2c_adapter *adap)
330{ 272{
331 return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_I2C; 273 return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_I2C;
@@ -343,9 +285,6 @@ static struct i2c_adapter cx23885_i2c_adap_template = {
343 .owner = THIS_MODULE, 285 .owner = THIS_MODULE,
344 .id = I2C_HW_B_CX23885, 286 .id = I2C_HW_B_CX23885,
345 .algo = &cx23885_i2c_algo_template, 287 .algo = &cx23885_i2c_algo_template,
346 .class = I2C_CLASS_TV_ANALOG,
347 .client_register = attach_inform,
348 .client_unregister = detach_inform,
349}; 288};
350 289
351static struct i2c_client cx23885_i2c_client_template = { 290static struct i2c_client cx23885_i2c_client_template = {
@@ -402,15 +341,18 @@ int cx23885_i2c_register(struct cx23885_i2c *bus)
402 341
403 bus->i2c_algo.data = bus; 342 bus->i2c_algo.data = bus;
404 bus->i2c_adap.algo_data = bus; 343 bus->i2c_adap.algo_data = bus;
405 i2c_set_adapdata(&bus->i2c_adap, bus); 344 i2c_set_adapdata(&bus->i2c_adap, &dev->v4l2_dev);
406 i2c_add_adapter(&bus->i2c_adap); 345 i2c_add_adapter(&bus->i2c_adap);
407 346
408 bus->i2c_client.adapter = &bus->i2c_adap; 347 bus->i2c_client.adapter = &bus->i2c_adap;
409 348
410 if (0 == bus->i2c_rc) { 349 if (0 == bus->i2c_rc) {
411 dprintk(1, "%s: i2c bus %d registered\n", dev->name, bus->nr); 350 dprintk(1, "%s: i2c bus %d registered\n", dev->name, bus->nr);
412 if (i2c_scan) 351 if (i2c_scan) {
352 printk(KERN_INFO "%s: scan bus %d:\n",
353 dev->name, bus->nr);
413 do_i2c_scan(dev->name, &bus->i2c_client); 354 do_i2c_scan(dev->name, &bus->i2c_client);
355 }
414 } else 356 } else
415 printk(KERN_WARNING "%s: i2c bus %d register FAILED\n", 357 printk(KERN_WARNING "%s: i2c bus %d register FAILED\n",
416 dev->name, bus->nr); 358 dev->name, bus->nr);
diff --git a/drivers/media/video/cx23885/cx23885-reg.h b/drivers/media/video/cx23885/cx23885-reg.h
index 20b68a236260..eafbe5226bae 100644
--- a/drivers/media/video/cx23885/cx23885-reg.h
+++ b/drivers/media/video/cx23885/cx23885-reg.h
@@ -212,6 +212,8 @@ Channel manager Data Structure entry = 20 DWORD
212 212
213#define DEV_CNTRL2 0x00040000 213#define DEV_CNTRL2 0x00040000
214 214
215#define PCI_MSK_GPIO1 (1 << 24)
216#define PCI_MSK_GPIO0 (1 << 23)
215#define PCI_MSK_APB_DMA (1 << 12) 217#define PCI_MSK_APB_DMA (1 << 12)
216#define PCI_MSK_AL_WR (1 << 11) 218#define PCI_MSK_AL_WR (1 << 11)
217#define PCI_MSK_AL_RD (1 << 10) 219#define PCI_MSK_AL_RD (1 << 10)
diff --git a/drivers/media/video/cx23885/cx23885-video.c b/drivers/media/video/cx23885/cx23885-video.c
index eaa11893bfe9..f0ac62c5dc83 100644
--- a/drivers/media/video/cx23885/cx23885-video.c
+++ b/drivers/media/video/cx23885/cx23885-video.c
@@ -35,11 +35,6 @@
35#include <media/v4l2-common.h> 35#include <media/v4l2-common.h>
36#include <media/v4l2-ioctl.h> 36#include <media/v4l2-ioctl.h>
37 37
38#ifdef CONFIG_VIDEO_V4L1_COMPAT
39/* Include V4L1 specific functions. Should be removed soon */
40#include <linux/videodev.h>
41#endif
42
43MODULE_DESCRIPTION("v4l2 driver module for cx23885 based TV cards"); 38MODULE_DESCRIPTION("v4l2 driver module for cx23885 based TV cards");
44MODULE_AUTHOR("Steven Toth <stoth@linuxtv.org>"); 39MODULE_AUTHOR("Steven Toth <stoth@linuxtv.org>");
45MODULE_LICENSE("GPL"); 40MODULE_LICENSE("GPL");
@@ -244,6 +239,7 @@ static struct cx23885_ctrl cx23885_ctls[] = {
244}; 239};
245static const int CX23885_CTLS = ARRAY_SIZE(cx23885_ctls); 240static const int CX23885_CTLS = ARRAY_SIZE(cx23885_ctls);
246 241
242/* Must be sorted from low to high control ID! */
247static const u32 cx23885_user_ctrls[] = { 243static const u32 cx23885_user_ctrls[] = {
248 V4L2_CID_USER_CLASS, 244 V4L2_CID_USER_CLASS,
249 V4L2_CID_BRIGHTNESS, 245 V4L2_CID_BRIGHTNESS,
@@ -303,11 +299,7 @@ static int cx23885_set_tvnorm(struct cx23885_dev *dev, v4l2_std_id norm)
303 299
304 dev->tvnorm = norm; 300 dev->tvnorm = norm;
305 301
306 /* Tell the analog tuner/demods */ 302 call_all(dev, tuner, s_std, norm);
307 cx23885_call_i2c_clients(&dev->i2c_bus[1], VIDIOC_S_STD, &norm);
308
309 /* Tell the internal A/V decoder */
310 cx23885_call_i2c_clients(&dev->i2c_bus[2], VIDIOC_S_STD, &norm);
311 303
312 return 0; 304 return 0;
313} 305}
@@ -324,8 +316,8 @@ static struct video_device *cx23885_vdev_init(struct cx23885_dev *dev,
324 if (NULL == vfd) 316 if (NULL == vfd)
325 return NULL; 317 return NULL;
326 *vfd = *template; 318 *vfd = *template;
327 vfd->minor = -1; 319 vfd->minor = -1;
328 vfd->parent = &pci->dev; 320 vfd->v4l2_dev = &dev->v4l2_dev;
329 vfd->release = video_device_release; 321 vfd->release = video_device_release;
330 snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)", 322 snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)",
331 dev->name, type, cx23885_boards[dev->board].name); 323 dev->name, type, cx23885_boards[dev->board].name);
@@ -414,8 +406,7 @@ static int cx23885_video_mux(struct cx23885_dev *dev, unsigned int input)
414 route.input = INPUT(input)->vmux; 406 route.input = INPUT(input)->vmux;
415 407
416 /* Tell the internal A/V decoder */ 408 /* Tell the internal A/V decoder */
417 cx23885_call_i2c_clients(&dev->i2c_bus[2], 409 v4l2_subdev_call(dev->sd_cx25840, video, s_routing, &route);
418 VIDIOC_INT_S_VIDEO_ROUTING, &route);
419 410
420 return 0; 411 return 0;
421} 412}
@@ -891,7 +882,7 @@ static int cx23885_get_control(struct cx23885_dev *dev,
891 struct v4l2_control *ctl) 882 struct v4l2_control *ctl)
892{ 883{
893 dprintk(1, "%s() calling cx25840(VIDIOC_G_CTRL)\n", __func__); 884 dprintk(1, "%s() calling cx25840(VIDIOC_G_CTRL)\n", __func__);
894 cx23885_call_i2c_clients(&dev->i2c_bus[2], VIDIOC_G_CTRL, ctl); 885 call_all(dev, core, g_ctrl, ctl);
895 return 0; 886 return 0;
896} 887}
897 888
@@ -1005,7 +996,7 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
1005 fh->vidq.field = f->fmt.pix.field; 996 fh->vidq.field = f->fmt.pix.field;
1006 dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, 997 dprintk(2, "%s() width=%d height=%d field=%d\n", __func__,
1007 fh->width, fh->height, fh->vidq.field); 998 fh->width, fh->height, fh->vidq.field);
1008 cx23885_call_i2c_clients(&dev->i2c_bus[2], VIDIOC_S_FMT, f); 999 call_all(dev, video, s_fmt, f);
1009 return 0; 1000 return 0;
1010} 1001}
1011 1002
@@ -1285,7 +1276,7 @@ static int vidioc_g_frequency(struct file *file, void *priv,
1285 f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; 1276 f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1286 f->frequency = dev->freq; 1277 f->frequency = dev->freq;
1287 1278
1288 cx23885_call_i2c_clients(&dev->i2c_bus[1], VIDIOC_G_FREQUENCY, f); 1279 call_all(dev, tuner, g_frequency, f);
1289 1280
1290 return 0; 1281 return 0;
1291} 1282}
@@ -1300,7 +1291,7 @@ static int cx23885_set_freq(struct cx23885_dev *dev, struct v4l2_frequency *f)
1300 mutex_lock(&dev->lock); 1291 mutex_lock(&dev->lock);
1301 dev->freq = f->frequency; 1292 dev->freq = f->frequency;
1302 1293
1303 cx23885_call_i2c_clients(&dev->i2c_bus[1], VIDIOC_S_FREQUENCY, f); 1294 call_all(dev, tuner, s_frequency, f);
1304 1295
1305 /* When changing channels it is required to reset TVAUDIO */ 1296 /* When changing channels it is required to reset TVAUDIO */
1306 msleep(10); 1297 msleep(10);
@@ -1334,7 +1325,7 @@ static int vidioc_g_register(struct file *file, void *fh,
1334 if (!v4l2_chip_match_host(&reg->match)) 1325 if (!v4l2_chip_match_host(&reg->match))
1335 return -EINVAL; 1326 return -EINVAL;
1336 1327
1337 cx23885_call_i2c_clients(&dev->i2c_bus[2], VIDIOC_DBG_G_REGISTER, reg); 1328 call_all(dev, core, g_register, reg);
1338 1329
1339 return 0; 1330 return 0;
1340} 1331}
@@ -1347,7 +1338,7 @@ static int vidioc_s_register(struct file *file, void *fh,
1347 if (!v4l2_chip_match_host(&reg->match)) 1338 if (!v4l2_chip_match_host(&reg->match))
1348 return -EINVAL; 1339 return -EINVAL;
1349 1340
1350 cx23885_call_i2c_clients(&dev->i2c_bus[2], VIDIOC_DBG_S_REGISTER, reg); 1341 call_all(dev, core, s_register, reg);
1351 1342
1352 return 0; 1343 return 0;
1353} 1344}
@@ -1528,6 +1519,26 @@ int cx23885_video_register(struct cx23885_dev *dev)
1528 /* Don't enable VBI yet */ 1519 /* Don't enable VBI yet */
1529 cx_set(PCI_INT_MSK, 1); 1520 cx_set(PCI_INT_MSK, 1);
1530 1521
1522 if (TUNER_ABSENT != dev->tuner_type) {
1523 struct v4l2_subdev *sd = NULL;
1524
1525 if (dev->tuner_addr)
1526 sd = v4l2_i2c_new_subdev(&dev->i2c_bus[1].i2c_adap,
1527 "tuner", "tuner", dev->tuner_addr);
1528 else
1529 sd = v4l2_i2c_new_probed_subdev(&dev->i2c_bus[1].i2c_adap,
1530 "tuner", "tuner", v4l2_i2c_tuner_addrs(ADDRS_TV));
1531 if (sd) {
1532 struct tuner_setup tun_setup;
1533
1534 tun_setup.mode_mask = T_ANALOG_TV;
1535 tun_setup.type = dev->tuner_type;
1536 tun_setup.addr = v4l2_i2c_subdev_addr(sd);
1537
1538 v4l2_subdev_call(sd, tuner, s_type_addr, &tun_setup);
1539 }
1540 }
1541
1531 1542
1532 /* register v4l devices */ 1543 /* register v4l devices */
1533 dev->video_dev = cx23885_vdev_init(dev, dev->pci, 1544 dev->video_dev = cx23885_vdev_init(dev, dev->pci,
diff --git a/drivers/media/video/cx23885/cx23885.h b/drivers/media/video/cx23885/cx23885.h
index 67828029fc69..02d980a29962 100644
--- a/drivers/media/video/cx23885/cx23885.h
+++ b/drivers/media/video/cx23885/cx23885.h
@@ -24,7 +24,7 @@
24#include <linux/i2c-algo-bit.h> 24#include <linux/i2c-algo-bit.h>
25#include <linux/kdev_t.h> 25#include <linux/kdev_t.h>
26 26
27#include <media/v4l2-common.h> 27#include <media/v4l2-device.h>
28#include <media/tuner.h> 28#include <media/tuner.h>
29#include <media/tveeprom.h> 29#include <media/tveeprom.h>
30#include <media/videobuf-dma-sg.h> 30#include <media/videobuf-dma-sg.h>
@@ -67,6 +67,10 @@
67#define CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP 11 67#define CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP 11
68#define CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H 12 68#define CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H 12
69#define CX23885_BOARD_COMPRO_VIDEOMATE_E650F 13 69#define CX23885_BOARD_COMPRO_VIDEOMATE_E650F 13
70#define CX23885_BOARD_TBS_6920 14
71#define CX23885_BOARD_TEVII_S470 15
72#define CX23885_BOARD_DVBWORLD_2005 16
73#define CX23885_BOARD_NETUP_DUAL_DVBS2_CI 17
70 74
71/* Currently unsupported by the driver: PAL/H, NTSC/Kr, SECAM B/G/H/LC */ 75/* Currently unsupported by the driver: PAL/H, NTSC/Kr, SECAM B/G/H/LC */
72#define CX23885_NORMS (\ 76#define CX23885_NORMS (\
@@ -184,6 +188,7 @@ struct cx23885_board {
184 */ 188 */
185 u32 clk_freq; 189 u32 clk_freq;
186 struct cx23885_input input[MAX_CX23885_INPUT]; 190 struct cx23885_input input[MAX_CX23885_INPUT];
191 int cimax; /* for NetUP */
187}; 192};
188 193
189struct cx23885_subid { 194struct cx23885_subid {
@@ -266,11 +271,13 @@ struct cx23885_tsport {
266 271
267 /* Allow a single tsport to have multiple frontends */ 272 /* Allow a single tsport to have multiple frontends */
268 u32 num_frontends; 273 u32 num_frontends;
274 void *port_priv;
269}; 275};
270 276
271struct cx23885_dev { 277struct cx23885_dev {
272 struct list_head devlist; 278 struct list_head devlist;
273 atomic_t refcount; 279 atomic_t refcount;
280 struct v4l2_device v4l2_dev;
274 281
275 /* pci stuff */ 282 /* pci stuff */
276 struct pci_dev *pci; 283 struct pci_dev *pci;
@@ -316,6 +323,7 @@ struct cx23885_dev {
316 unsigned int radio_type; 323 unsigned int radio_type;
317 unsigned char radio_addr; 324 unsigned char radio_addr;
318 unsigned int has_radio; 325 unsigned int has_radio;
326 struct v4l2_subdev *sd_cx25840;
319 327
320 /* V4l */ 328 /* V4l */
321 u32 freq; 329 u32 freq;
@@ -336,6 +344,14 @@ struct cx23885_dev {
336 344
337}; 345};
338 346
347static inline struct cx23885_dev *to_cx23885(struct v4l2_device *v4l2_dev)
348{
349 return container_of(v4l2_dev, struct cx23885_dev, v4l2_dev);
350}
351
352#define call_all(dev, o, f, args...) \
353 v4l2_device_call_all(&dev->v4l2_dev, 0, o, f, ##args)
354
339extern struct list_head cx23885_devlist; 355extern struct list_head cx23885_devlist;
340 356
341#define SRAM_CH01 0 /* Video A */ 357#define SRAM_CH01 0 /* Video A */
@@ -452,8 +468,6 @@ extern struct videobuf_queue_ops cx23885_vbi_qops;
452/* cx23885-i2c.c */ 468/* cx23885-i2c.c */
453extern int cx23885_i2c_register(struct cx23885_i2c *bus); 469extern int cx23885_i2c_register(struct cx23885_i2c *bus);
454extern int cx23885_i2c_unregister(struct cx23885_i2c *bus); 470extern int cx23885_i2c_unregister(struct cx23885_i2c *bus);
455extern void cx23885_call_i2c_clients(struct cx23885_i2c *bus, unsigned int cmd,
456 void *arg);
457extern void cx23885_av_clk(struct cx23885_dev *dev, int enable); 471extern void cx23885_av_clk(struct cx23885_dev *dev, int enable);
458 472
459/* ----------------------------------------------------------- */ 473/* ----------------------------------------------------------- */
diff --git a/drivers/media/video/cx23885/netup-eeprom.c b/drivers/media/video/cx23885/netup-eeprom.c
new file mode 100644
index 000000000000..042bbbbd48f8
--- /dev/null
+++ b/drivers/media/video/cx23885/netup-eeprom.c
@@ -0,0 +1,107 @@
1
2/*
3 * netup-eeprom.c
4 *
5 * 24LC02 EEPROM driver in conjunction with NetUP Dual DVB-S2 CI card
6 *
7 * Copyright (C) 2009 NetUP Inc.
8 * Copyright (C) 2009 Abylay Ospan <aospan@netup.ru>
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 *
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25
26#
27#include "cx23885.h"
28#include "netup-eeprom.h"
29
30#define EEPROM_I2C_ADDR 0x50
31
32int netup_eeprom_read(struct i2c_adapter *i2c_adap, u8 addr)
33{
34 int ret;
35 unsigned char buf[2];
36
37 /* Read from EEPROM */
38 struct i2c_msg msg[] = {
39 {
40 .addr = EEPROM_I2C_ADDR,
41 .flags = 0,
42 .buf = &buf[0],
43 .len = 1
44 }, {
45 .addr = EEPROM_I2C_ADDR,
46 .flags = I2C_M_RD,
47 .buf = &buf[1],
48 .len = 1
49 }
50
51 };
52
53 buf[0] = addr;
54 buf[1] = 0x0;
55
56 ret = i2c_transfer(i2c_adap, msg, 2);
57
58 if (ret != 2) {
59 printk(KERN_ERR "eeprom i2c read error, status=%d\n", ret);
60 return -1;
61 }
62
63 return buf[1];
64};
65
66int netup_eeprom_write(struct i2c_adapter *i2c_adap, u8 addr, u8 data)
67{
68 int ret;
69 unsigned char bufw[2];
70
71 /* Write into EEPROM */
72 struct i2c_msg msg[] = {
73 {
74 .addr = EEPROM_I2C_ADDR,
75 .flags = 0,
76 .buf = &bufw[0],
77 .len = 2
78 }
79 };
80
81 bufw[0] = addr;
82 bufw[1] = data;
83
84 ret = i2c_transfer(i2c_adap, msg, 1);
85
86 if (ret != 1) {
87 printk(KERN_ERR "eeprom i2c write error, status=%d\n", ret);
88 return -1;
89 }
90
91 mdelay(10); /* prophylactic delay, datasheet write cycle time = 5 ms */
92 return 0;
93};
94
95void netup_get_card_info(struct i2c_adapter *i2c_adap,
96 struct netup_card_info *cinfo)
97{
98 int i, j;
99
100 cinfo->rev = netup_eeprom_read(i2c_adap, 13);
101
102 for (i = 0, j = 0; i < 6; i++, j++)
103 cinfo->port[0].mac[j] = netup_eeprom_read(i2c_adap, i);
104
105 for (i = 6, j = 0; i < 12; i++, j++)
106 cinfo->port[1].mac[j] = netup_eeprom_read(i2c_adap, i);
107};
diff --git a/drivers/media/video/cx23885/netup-eeprom.h b/drivers/media/video/cx23885/netup-eeprom.h
new file mode 100644
index 000000000000..13926e18feba
--- /dev/null
+++ b/drivers/media/video/cx23885/netup-eeprom.h
@@ -0,0 +1,42 @@
1/*
2 * netup-eeprom.h
3 *
4 * 24LC02 EEPROM driver in conjunction with NetUP Dual DVB-S2 CI card
5 *
6 * Copyright (C) 2009 NetUP Inc.
7 * Copyright (C) 2009 Abylay Ospan <aospan@netup.ru>
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 *
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#ifndef NETUP_EEPROM_H
26#define NETUP_EEPROM_H
27
28struct netup_port_info {
29 u8 mac[6];/* card MAC address */
30};
31
32struct netup_card_info {
33 struct netup_port_info port[2];/* ports - 1,2 */
34 u8 rev;/* card revision */
35};
36
37extern int netup_eeprom_read(struct i2c_adapter *i2c_adap, u8 addr);
38extern int netup_eeprom_write(struct i2c_adapter *i2c_adap, u8 addr, u8 data);
39extern void netup_get_card_info(struct i2c_adapter *i2c_adap,
40 struct netup_card_info *cinfo);
41
42#endif
diff --git a/drivers/media/video/cx23885/netup-init.c b/drivers/media/video/cx23885/netup-init.c
new file mode 100644
index 000000000000..f4893e69cd89
--- /dev/null
+++ b/drivers/media/video/cx23885/netup-init.c
@@ -0,0 +1,125 @@
1/*
2 * netup-init.c
3 *
4 * NetUP Dual DVB-S2 CI driver
5 *
6 * Copyright (C) 2009 NetUP Inc.
7 * Copyright (C) 2009 Igor M. Liplianin <liplianin@netup.ru>
8 * Copyright (C) 2009 Abylay Ospan <aospan@netup.ru>
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 *
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25
26#include "cx23885.h"
27
28static void i2c_av_write(struct i2c_adapter *i2c, u16 reg, u8 val)
29{
30 int ret;
31 u8 buf[3];
32 struct i2c_msg msg = {
33 .addr = 0x88 >> 1,
34 .flags = 0,
35 .buf = buf,
36 .len = 3
37 };
38
39 buf[0] = reg >> 8;
40 buf[1] = reg & 0xff;
41 buf[2] = val;
42
43 ret = i2c_transfer(i2c, &msg, 1);
44
45 if (ret != 1)
46 printk(KERN_ERR "%s: i2c write error!\n", __func__);
47}
48
49static void i2c_av_write4(struct i2c_adapter *i2c, u16 reg, u32 val)
50{
51 int ret;
52 u8 buf[6];
53 struct i2c_msg msg = {
54 .addr = 0x88 >> 1,
55 .flags = 0,
56 .buf = buf,
57 .len = 6
58 };
59
60 buf[0] = reg >> 8;
61 buf[1] = reg & 0xff;
62 buf[2] = val & 0xff;
63 buf[3] = (val >> 8) & 0xff;
64 buf[4] = (val >> 16) & 0xff;
65 buf[5] = val >> 24;
66
67 ret = i2c_transfer(i2c, &msg, 1);
68
69 if (ret != 1)
70 printk(KERN_ERR "%s: i2c write error!\n", __func__);
71}
72
73static u8 i2c_av_read(struct i2c_adapter *i2c, u16 reg)
74{
75 int ret;
76 u8 buf[2];
77 struct i2c_msg msg = {
78 .addr = 0x88 >> 1,
79 .flags = 0,
80 .buf = buf,
81 .len = 2
82 };
83
84 buf[0] = reg >> 8;
85 buf[1] = reg & 0xff;
86
87 ret = i2c_transfer(i2c, &msg, 1);
88
89 if (ret != 1)
90 printk(KERN_ERR "%s: i2c write error!\n", __func__);
91
92 msg.flags = I2C_M_RD;
93 msg.len = 1;
94
95 ret = i2c_transfer(i2c, &msg, 1);
96
97 if (ret != 1)
98 printk(KERN_ERR "%s: i2c read error!\n", __func__);
99
100 return buf[0];
101}
102
103static void i2c_av_and_or(struct i2c_adapter *i2c, u16 reg, unsigned and_mask,
104 u8 or_value)
105{
106 i2c_av_write(i2c, reg, (i2c_av_read(i2c, reg) & and_mask) | or_value);
107}
108/* set 27MHz on AUX_CLK */
109void netup_initialize(struct cx23885_dev *dev)
110{
111 struct cx23885_i2c *i2c_bus = &dev->i2c_bus[2];
112 struct i2c_adapter *i2c = &i2c_bus->i2c_adap;
113
114 /* Stop microcontroller */
115 i2c_av_and_or(i2c, 0x803, ~0x10, 0x00);
116
117 /* Aux PLL frac for 27 MHz */
118 i2c_av_write4(i2c, 0x114, 0xea0eb3);
119
120 /* Aux PLL int for 27 MHz */
121 i2c_av_write4(i2c, 0x110, 0x090319);
122
123 /* start microcontroller */
124 i2c_av_and_or(i2c, 0x803, ~0x10, 0x10);
125}
diff --git a/drivers/media/video/cx23885/netup-init.h b/drivers/media/video/cx23885/netup-init.h
new file mode 100644
index 000000000000..d26ae4b1590e
--- /dev/null
+++ b/drivers/media/video/cx23885/netup-init.h
@@ -0,0 +1,25 @@
1/*
2 * netup-init.h
3 *
4 * NetUP Dual DVB-S2 CI driver
5 *
6 * Copyright (C) 2009 NetUP Inc.
7 * Copyright (C) 2009 Igor M. Liplianin <liplianin@netup.ru>
8 * Copyright (C) 2009 Abylay Ospan <aospan@netup.ru>
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 *
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25extern void netup_initialize(struct cx23885_dev *dev);
diff --git a/drivers/media/video/cx25840/cx25840-audio.c b/drivers/media/video/cx25840/cx25840-audio.c
index d199d80ea0a3..93d74bee292a 100644
--- a/drivers/media/video/cx25840/cx25840-audio.c
+++ b/drivers/media/video/cx25840/cx25840-audio.c
@@ -363,75 +363,74 @@ static void set_mute(struct i2c_client *client, int mute)
363 } 363 }
364} 364}
365 365
366int cx25840_audio(struct i2c_client *client, unsigned int cmd, void *arg) 366int cx25840_s_clock_freq(struct v4l2_subdev *sd, u32 freq)
367{ 367{
368 struct cx25840_state *state = to_state(i2c_get_clientdata(client)); 368 struct i2c_client *client = v4l2_get_subdevdata(sd);
369 struct v4l2_control *ctrl = arg; 369 struct cx25840_state *state = to_state(sd);
370 int retval; 370 int retval;
371 371
372 switch (cmd) { 372 if (!state->is_cx25836)
373 case VIDIOC_INT_AUDIO_CLOCK_FREQ: 373 cx25840_and_or(client, 0x810, ~0x1, 1);
374 if (!state->is_cx25836) 374 if (state->aud_input != CX25840_AUDIO_SERIAL) {
375 cx25840_and_or(client, 0x810, ~0x1, 1); 375 cx25840_and_or(client, 0x803, ~0x10, 0);
376 if (state->aud_input != CX25840_AUDIO_SERIAL) { 376 cx25840_write(client, 0x8d3, 0x1f);
377 cx25840_and_or(client, 0x803, ~0x10, 0); 377 }
378 cx25840_write(client, 0x8d3, 0x1f); 378 retval = set_audclk_freq(client, freq);
379 } 379 if (state->aud_input != CX25840_AUDIO_SERIAL)
380 retval = set_audclk_freq(client, *(u32 *)arg); 380 cx25840_and_or(client, 0x803, ~0x10, 0x10);
381 if (state->aud_input != CX25840_AUDIO_SERIAL) { 381 if (!state->is_cx25836)
382 cx25840_and_or(client, 0x803, ~0x10, 0x10); 382 cx25840_and_or(client, 0x810, ~0x1, 0);
383 } 383 return retval;
384 if (!state->is_cx25836) 384}
385 cx25840_and_or(client, 0x810, ~0x1, 0);
386 return retval;
387
388 case VIDIOC_G_CTRL:
389 switch (ctrl->id) {
390 case V4L2_CID_AUDIO_VOLUME:
391 ctrl->value = get_volume(client);
392 break;
393 case V4L2_CID_AUDIO_BASS:
394 ctrl->value = get_bass(client);
395 break;
396 case V4L2_CID_AUDIO_TREBLE:
397 ctrl->value = get_treble(client);
398 break;
399 case V4L2_CID_AUDIO_BALANCE:
400 ctrl->value = get_balance(client);
401 break;
402 case V4L2_CID_AUDIO_MUTE:
403 ctrl->value = get_mute(client);
404 break;
405 default:
406 return -EINVAL;
407 }
408 break;
409 385
410 case VIDIOC_S_CTRL: 386int cx25840_audio_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
411 switch (ctrl->id) { 387{
412 case V4L2_CID_AUDIO_VOLUME: 388 struct i2c_client *client = v4l2_get_subdevdata(sd);
413 set_volume(client, ctrl->value);
414 break;
415 case V4L2_CID_AUDIO_BASS:
416 set_bass(client, ctrl->value);
417 break;
418 case V4L2_CID_AUDIO_TREBLE:
419 set_treble(client, ctrl->value);
420 break;
421 case V4L2_CID_AUDIO_BALANCE:
422 set_balance(client, ctrl->value);
423 break;
424 case V4L2_CID_AUDIO_MUTE:
425 set_mute(client, ctrl->value);
426 break;
427 default:
428 return -EINVAL;
429 }
430 break;
431 389
390 switch (ctrl->id) {
391 case V4L2_CID_AUDIO_VOLUME:
392 ctrl->value = get_volume(client);
393 break;
394 case V4L2_CID_AUDIO_BASS:
395 ctrl->value = get_bass(client);
396 break;
397 case V4L2_CID_AUDIO_TREBLE:
398 ctrl->value = get_treble(client);
399 break;
400 case V4L2_CID_AUDIO_BALANCE:
401 ctrl->value = get_balance(client);
402 break;
403 case V4L2_CID_AUDIO_MUTE:
404 ctrl->value = get_mute(client);
405 break;
432 default: 406 default:
433 return -EINVAL; 407 return -EINVAL;
434 } 408 }
409 return 0;
410}
435 411
412int cx25840_audio_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
413{
414 struct i2c_client *client = v4l2_get_subdevdata(sd);
415
416 switch (ctrl->id) {
417 case V4L2_CID_AUDIO_VOLUME:
418 set_volume(client, ctrl->value);
419 break;
420 case V4L2_CID_AUDIO_BASS:
421 set_bass(client, ctrl->value);
422 break;
423 case V4L2_CID_AUDIO_TREBLE:
424 set_treble(client, ctrl->value);
425 break;
426 case V4L2_CID_AUDIO_BALANCE:
427 set_balance(client, ctrl->value);
428 break;
429 case V4L2_CID_AUDIO_MUTE:
430 set_mute(client, ctrl->value);
431 break;
432 default:
433 return -EINVAL;
434 }
436 return 0; 435 return 0;
437} 436}
diff --git a/drivers/media/video/cx25840/cx25840-core.c b/drivers/media/video/cx25840/cx25840-core.c
index 25eb3bec9e5d..737ee4ea8830 100644
--- a/drivers/media/video/cx25840/cx25840-core.c
+++ b/drivers/media/video/cx25840/cx25840-core.c
@@ -39,7 +39,7 @@
39#include <linux/delay.h> 39#include <linux/delay.h>
40#include <media/v4l2-common.h> 40#include <media/v4l2-common.h>
41#include <media/v4l2-chip-ident.h> 41#include <media/v4l2-chip-ident.h>
42#include <media/v4l2-i2c-drv-legacy.h> 42#include <media/v4l2-i2c-drv.h>
43#include <media/cx25840.h> 43#include <media/cx25840.h>
44 44
45#include "cx25840-core.h" 45#include "cx25840-core.h"
@@ -48,15 +48,12 @@ MODULE_DESCRIPTION("Conexant CX25840 audio/video decoder driver");
48MODULE_AUTHOR("Ulf Eklund, Chris Kennedy, Hans Verkuil, Tyler Trafford"); 48MODULE_AUTHOR("Ulf Eklund, Chris Kennedy, Hans Verkuil, Tyler Trafford");
49MODULE_LICENSE("GPL"); 49MODULE_LICENSE("GPL");
50 50
51static unsigned short normal_i2c[] = { 0x88 >> 1, I2C_CLIENT_END };
52
53static int cx25840_debug; 51static int cx25840_debug;
54 52
55module_param_named(debug,cx25840_debug, int, 0644); 53module_param_named(debug,cx25840_debug, int, 0644);
56 54
57MODULE_PARM_DESC(debug, "Debugging messages [0=Off (default) 1=On]"); 55MODULE_PARM_DESC(debug, "Debugging messages [0=Off (default) 1=On]");
58 56
59I2C_CLIENT_INSMOD;
60 57
61/* ----------------------------------------------------------------------- */ 58/* ----------------------------------------------------------------------- */
62 59
@@ -763,7 +760,7 @@ static int cx25840_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
763 break; 760 break;
764 761
765 case V4L2_CID_HUE: 762 case V4L2_CID_HUE:
766 if (ctrl->value < -127 || ctrl->value > 127) { 763 if (ctrl->value < -128 || ctrl->value > 127) {
767 v4l_err(client, "invalid hue setting %d\n", ctrl->value); 764 v4l_err(client, "invalid hue setting %d\n", ctrl->value);
768 return -ERANGE; 765 return -ERANGE;
769 } 766 }
@@ -778,7 +775,7 @@ static int cx25840_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
778 case V4L2_CID_AUDIO_MUTE: 775 case V4L2_CID_AUDIO_MUTE:
779 if (state->is_cx25836) 776 if (state->is_cx25836)
780 return -EINVAL; 777 return -EINVAL;
781 return cx25840_audio(client, VIDIOC_S_CTRL, ctrl); 778 return cx25840_audio_s_ctrl(sd, ctrl);
782 779
783 default: 780 default:
784 return -EINVAL; 781 return -EINVAL;
@@ -815,7 +812,7 @@ static int cx25840_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
815 case V4L2_CID_AUDIO_MUTE: 812 case V4L2_CID_AUDIO_MUTE:
816 if (state->is_cx25836) 813 if (state->is_cx25836)
817 return -EINVAL; 814 return -EINVAL;
818 return cx25840_audio(client, VIDIOC_G_CTRL, ctrl); 815 return cx25840_audio_g_ctrl(sd, ctrl);
819 default: 816 default:
820 return -EINVAL; 817 return -EINVAL;
821 } 818 }
@@ -827,11 +824,9 @@ static int cx25840_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
827 824
828static int cx25840_g_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt) 825static int cx25840_g_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt)
829{ 826{
830 struct i2c_client *client = v4l2_get_subdevdata(sd);
831
832 switch (fmt->type) { 827 switch (fmt->type) {
833 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: 828 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
834 return cx25840_vbi(client, VIDIOC_G_FMT, fmt); 829 return cx25840_vbi_g_fmt(sd, fmt);
835 default: 830 default:
836 return -EINVAL; 831 return -EINVAL;
837 } 832 }
@@ -893,10 +888,10 @@ static int cx25840_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt)
893 break; 888 break;
894 889
895 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: 890 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
896 return cx25840_vbi(client, VIDIOC_S_FMT, fmt); 891 return cx25840_vbi_s_fmt(sd, fmt);
897 892
898 case V4L2_BUF_TYPE_VBI_CAPTURE: 893 case V4L2_BUF_TYPE_VBI_CAPTURE:
899 return cx25840_vbi(client, VIDIOC_S_FMT, fmt); 894 return cx25840_vbi_s_fmt(sd, fmt);
900 895
901 default: 896 default:
902 return -EINVAL; 897 return -EINVAL;
@@ -1101,6 +1096,16 @@ static void log_audio_status(struct i2c_client *client)
1101 1096
1102/* ----------------------------------------------------------------------- */ 1097/* ----------------------------------------------------------------------- */
1103 1098
1099/* This init operation must be called to load the driver's firmware.
1100 Without this the audio standard detection will fail and you will
1101 only get mono.
1102
1103 Since loading the firmware is often problematic when the driver is
1104 compiled into the kernel I recommend postponing calling this function
1105 until the first open of the video device. Another reason for
1106 postponing it is that loading this firmware takes a long time (seconds)
1107 due to the slow i2c bus speed. So it will speed up the boot process if
1108 you can avoid loading the fw as long as the video device isn't used. */
1104static int cx25840_init(struct v4l2_subdev *sd, u32 val) 1109static int cx25840_init(struct v4l2_subdev *sd, u32 val)
1105{ 1110{
1106 struct cx25840_state *state = to_state(sd); 1111 struct cx25840_state *state = to_state(sd);
@@ -1146,20 +1151,6 @@ static int cx25840_s_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *
1146} 1151}
1147#endif 1152#endif
1148 1153
1149static int cx25840_decode_vbi_line(struct v4l2_subdev *sd, struct v4l2_decode_vbi_line *vbi)
1150{
1151 struct i2c_client *client = v4l2_get_subdevdata(sd);
1152
1153 return cx25840_vbi(client, VIDIOC_INT_DECODE_VBI_LINE, vbi);
1154}
1155
1156static int cx25840_s_clock_freq(struct v4l2_subdev *sd, u32 freq)
1157{
1158 struct i2c_client *client = v4l2_get_subdevdata(sd);
1159
1160 return cx25840_audio(client, VIDIOC_INT_AUDIO_CLOCK_FREQ, &freq);
1161}
1162
1163static int cx25840_s_stream(struct v4l2_subdev *sd, int enable) 1154static int cx25840_s_stream(struct v4l2_subdev *sd, int enable)
1164{ 1155{
1165 struct cx25840_state *state = to_state(sd); 1156 struct cx25840_state *state = to_state(sd);
@@ -1195,10 +1186,12 @@ static int cx25840_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc)
1195 1186
1196 switch (qc->id) { 1187 switch (qc->id) {
1197 case V4L2_CID_BRIGHTNESS: 1188 case V4L2_CID_BRIGHTNESS:
1189 return v4l2_ctrl_query_fill(qc, 0, 255, 1, 128);
1198 case V4L2_CID_CONTRAST: 1190 case V4L2_CID_CONTRAST:
1199 case V4L2_CID_SATURATION: 1191 case V4L2_CID_SATURATION:
1192 return v4l2_ctrl_query_fill(qc, 0, 127, 1, 64);
1200 case V4L2_CID_HUE: 1193 case V4L2_CID_HUE:
1201 return v4l2_ctrl_query_fill_std(qc); 1194 return v4l2_ctrl_query_fill(qc, -128, 127, 1, 0);
1202 default: 1195 default:
1203 break; 1196 break;
1204 } 1197 }
@@ -1210,10 +1203,11 @@ static int cx25840_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc)
1210 return v4l2_ctrl_query_fill(qc, 0, 65535, 1203 return v4l2_ctrl_query_fill(qc, 0, 65535,
1211 65535 / 100, state->default_volume); 1204 65535 / 100, state->default_volume);
1212 case V4L2_CID_AUDIO_MUTE: 1205 case V4L2_CID_AUDIO_MUTE:
1206 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 0);
1213 case V4L2_CID_AUDIO_BALANCE: 1207 case V4L2_CID_AUDIO_BALANCE:
1214 case V4L2_CID_AUDIO_BASS: 1208 case V4L2_CID_AUDIO_BASS:
1215 case V4L2_CID_AUDIO_TREBLE: 1209 case V4L2_CID_AUDIO_TREBLE:
1216 return v4l2_ctrl_query_fill_std(qc); 1210 return v4l2_ctrl_query_fill(qc, 0, 65535, 65535 / 100, 32768);
1217 default: 1211 default:
1218 return -EINVAL; 1212 return -EINVAL;
1219 } 1213 }
@@ -1380,19 +1374,6 @@ static int cx25840_log_status(struct v4l2_subdev *sd)
1380 return 0; 1374 return 0;
1381} 1375}
1382 1376
1383static int cx25840_command(struct i2c_client *client, unsigned cmd, void *arg)
1384{
1385 /* ignore this command */
1386 if (cmd == TUNER_SET_TYPE_ADDR || cmd == TUNER_SET_CONFIG)
1387 return 0;
1388
1389 /* Old-style drivers rely on initialization on first use, so
1390 call the init whenever a command is issued to this driver.
1391 New-style drivers using v4l2_subdev should call init explicitly. */
1392 cx25840_init(i2c_get_clientdata(client), 0);
1393 return v4l2_subdev_command(i2c_get_clientdata(client), cmd, arg);
1394}
1395
1396/* ----------------------------------------------------------------------- */ 1377/* ----------------------------------------------------------------------- */
1397 1378
1398static const struct v4l2_subdev_core_ops cx25840_core_ops = { 1379static const struct v4l2_subdev_core_ops cx25840_core_ops = {
@@ -1528,8 +1509,6 @@ MODULE_DEVICE_TABLE(i2c, cx25840_id);
1528 1509
1529static struct v4l2_i2c_driver_data v4l2_i2c_data = { 1510static struct v4l2_i2c_driver_data v4l2_i2c_data = {
1530 .name = "cx25840", 1511 .name = "cx25840",
1531 .driverid = I2C_DRIVERID_CX25840,
1532 .command = cx25840_command,
1533 .probe = cx25840_probe, 1512 .probe = cx25840_probe,
1534 .remove = cx25840_remove, 1513 .remove = cx25840_remove,
1535 .id_table = cx25840_id, 1514 .id_table = cx25840_id,
diff --git a/drivers/media/video/cx25840/cx25840-core.h b/drivers/media/video/cx25840/cx25840-core.h
index be0558277ca3..9ad0eb86ecfd 100644
--- a/drivers/media/video/cx25840/cx25840-core.h
+++ b/drivers/media/video/cx25840/cx25840-core.h
@@ -75,11 +75,15 @@ int cx25840_loadfw(struct i2c_client *client);
75 75
76/* ----------------------------------------------------------------------- */ 76/* ----------------------------------------------------------------------- */
77/* cx25850-audio.c */ 77/* cx25850-audio.c */
78int cx25840_audio(struct i2c_client *client, unsigned int cmd, void *arg);
79void cx25840_audio_set_path(struct i2c_client *client); 78void cx25840_audio_set_path(struct i2c_client *client);
79int cx25840_s_clock_freq(struct v4l2_subdev *sd, u32 freq);
80int cx25840_audio_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
81int cx25840_audio_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
80 82
81/* ----------------------------------------------------------------------- */ 83/* ----------------------------------------------------------------------- */
82/* cx25850-vbi.c */ 84/* cx25850-vbi.c */
83int cx25840_vbi(struct i2c_client *client, unsigned int cmd, void *arg); 85int cx25840_vbi_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt);
86int cx25840_vbi_g_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt);
87int cx25840_decode_vbi_line(struct v4l2_subdev *sd, struct v4l2_decode_vbi_line *vbi);
84 88
85#endif 89#endif
diff --git a/drivers/media/video/cx25840/cx25840-vbi.c b/drivers/media/video/cx25840/cx25840-vbi.c
index 03f09b288eb8..35f6592f6c47 100644
--- a/drivers/media/video/cx25840/cx25840-vbi.c
+++ b/drivers/media/video/cx25840/cx25840-vbi.c
@@ -82,199 +82,181 @@ static int decode_vps(u8 * dst, u8 * p)
82 return err & 0xf0; 82 return err & 0xf0;
83} 83}
84 84
85int cx25840_vbi(struct i2c_client *client, unsigned int cmd, void *arg) 85int cx25840_vbi_g_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt)
86{ 86{
87 struct cx25840_state *state = to_state(i2c_get_clientdata(client)); 87 struct i2c_client *client = v4l2_get_subdevdata(sd);
88 struct v4l2_format *fmt; 88 struct cx25840_state *state = to_state(sd);
89 struct v4l2_sliced_vbi_format *svbi; 89 struct v4l2_sliced_vbi_format *svbi;
90 static const u16 lcr2vbi[] = {
91 0, V4L2_SLICED_TELETEXT_B, 0, /* 1 */
92 0, V4L2_SLICED_WSS_625, 0, /* 4 */
93 V4L2_SLICED_CAPTION_525, /* 6 */
94 0, 0, V4L2_SLICED_VPS, 0, 0, /* 9 */
95 0, 0, 0, 0
96 };
97 int is_pal = !(state->std & V4L2_STD_525_60);
98 int i;
90 99
91 switch (cmd) { 100 if (fmt->type != V4L2_BUF_TYPE_SLICED_VBI_CAPTURE)
92 case VIDIOC_G_FMT: 101 return -EINVAL;
93 { 102 svbi = &fmt->fmt.sliced;
94 static u16 lcr2vbi[] = { 103 memset(svbi, 0, sizeof(*svbi));
95 0, V4L2_SLICED_TELETEXT_B, 0, /* 1 */ 104 /* we're done if raw VBI is active */
96 0, V4L2_SLICED_WSS_625, 0, /* 4 */ 105 if ((cx25840_read(client, 0x404) & 0x10) == 0)
97 V4L2_SLICED_CAPTION_525, /* 6 */ 106 return 0;
98 0, 0, V4L2_SLICED_VPS, 0, 0, /* 9 */
99 0, 0, 0, 0
100 };
101 int is_pal = !(state->std & V4L2_STD_525_60);
102 int i;
103
104 fmt = arg;
105 if (fmt->type != V4L2_BUF_TYPE_SLICED_VBI_CAPTURE)
106 return -EINVAL;
107 svbi = &fmt->fmt.sliced;
108 memset(svbi, 0, sizeof(*svbi));
109 /* we're done if raw VBI is active */
110 if ((cx25840_read(client, 0x404) & 0x10) == 0)
111 break;
112 107
113 if (is_pal) { 108 if (is_pal) {
114 for (i = 7; i <= 23; i++) { 109 for (i = 7; i <= 23; i++) {
115 u8 v = cx25840_read(client, 0x424 + i - 7); 110 u8 v = cx25840_read(client, 0x424 + i - 7);
116 111
117 svbi->service_lines[0][i] = lcr2vbi[v >> 4]; 112 svbi->service_lines[0][i] = lcr2vbi[v >> 4];
118 svbi->service_lines[1][i] = lcr2vbi[v & 0xf]; 113 svbi->service_lines[1][i] = lcr2vbi[v & 0xf];
119 svbi->service_set |= 114 svbi->service_set |= svbi->service_lines[0][i] |
120 svbi->service_lines[0][i] | svbi->service_lines[1][i]; 115 svbi->service_lines[1][i];
121 }
122 } 116 }
123 else { 117 } else {
124 for (i = 10; i <= 21; i++) { 118 for (i = 10; i <= 21; i++) {
125 u8 v = cx25840_read(client, 0x424 + i - 10); 119 u8 v = cx25840_read(client, 0x424 + i - 10);
126 120
127 svbi->service_lines[0][i] = lcr2vbi[v >> 4]; 121 svbi->service_lines[0][i] = lcr2vbi[v >> 4];
128 svbi->service_lines[1][i] = lcr2vbi[v & 0xf]; 122 svbi->service_lines[1][i] = lcr2vbi[v & 0xf];
129 svbi->service_set |= 123 svbi->service_set |= svbi->service_lines[0][i] |
130 svbi->service_lines[0][i] | svbi->service_lines[1][i]; 124 svbi->service_lines[1][i];
131 }
132 } 125 }
133 break;
134 } 126 }
127 return 0;
128}
135 129
136 case VIDIOC_S_FMT: 130int cx25840_vbi_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt)
137 { 131{
138 int is_pal = !(state->std & V4L2_STD_525_60); 132 struct i2c_client *client = v4l2_get_subdevdata(sd);
139 int vbi_offset = is_pal ? 1 : 0; 133 struct cx25840_state *state = to_state(sd);
140 int i, x; 134 struct v4l2_sliced_vbi_format *svbi;
141 u8 lcr[24]; 135 int is_pal = !(state->std & V4L2_STD_525_60);
142 136 int vbi_offset = is_pal ? 1 : 0;
143 fmt = arg; 137 int i, x;
144 if (fmt->type != V4L2_BUF_TYPE_SLICED_VBI_CAPTURE && 138 u8 lcr[24];
145 fmt->type != V4L2_BUF_TYPE_VBI_CAPTURE) 139
146 return -EINVAL; 140 if (fmt->type != V4L2_BUF_TYPE_SLICED_VBI_CAPTURE &&
147 svbi = &fmt->fmt.sliced; 141 fmt->type != V4L2_BUF_TYPE_VBI_CAPTURE)
148 if (fmt->type == V4L2_BUF_TYPE_VBI_CAPTURE) { 142 return -EINVAL;
149 /* raw VBI */ 143 svbi = &fmt->fmt.sliced;
150 memset(svbi, 0, sizeof(*svbi)); 144 if (fmt->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
151 145 /* raw VBI */
152 /* Setup standard */ 146 memset(svbi, 0, sizeof(*svbi));
153 cx25840_std_setup(client);
154
155 /* VBI Offset */
156 cx25840_write(client, 0x47f, vbi_offset);
157 cx25840_write(client, 0x404, 0x2e);
158 break;
159 }
160
161 for (x = 0; x <= 23; x++)
162 lcr[x] = 0x00;
163 147
164 /* Setup standard */ 148 /* Setup standard */
165 cx25840_std_setup(client); 149 cx25840_std_setup(client);
166 150
167 /* Sliced VBI */ 151 /* VBI Offset */
168 cx25840_write(client, 0x404, 0x32); /* Ancillary data */
169 cx25840_write(client, 0x406, 0x13);
170 cx25840_write(client, 0x47f, vbi_offset); 152 cx25840_write(client, 0x47f, vbi_offset);
153 cx25840_write(client, 0x404, 0x2e);
154 return 0;
155 }
171 156
172 if (is_pal) { 157 for (x = 0; x <= 23; x++)
173 for (i = 0; i <= 6; i++) 158 lcr[x] = 0x00;
174 svbi->service_lines[0][i] = 159
175 svbi->service_lines[1][i] = 0; 160 /* Setup standard */
176 } else { 161 cx25840_std_setup(client);
177 for (i = 0; i <= 9; i++) 162
178 svbi->service_lines[0][i] = 163 /* Sliced VBI */
179 svbi->service_lines[1][i] = 0; 164 cx25840_write(client, 0x404, 0x32); /* Ancillary data */
180 165 cx25840_write(client, 0x406, 0x13);
181 for (i = 22; i <= 23; i++) 166 cx25840_write(client, 0x47f, vbi_offset);
182 svbi->service_lines[0][i] = 167
183 svbi->service_lines[1][i] = 0; 168 if (is_pal) {
184 } 169 for (i = 0; i <= 6; i++)
185 170 svbi->service_lines[0][i] =
186 for (i = 7; i <= 23; i++) { 171 svbi->service_lines[1][i] = 0;
187 for (x = 0; x <= 1; x++) { 172 } else {
188 switch (svbi->service_lines[1-x][i]) { 173 for (i = 0; i <= 9; i++)
189 case V4L2_SLICED_TELETEXT_B: 174 svbi->service_lines[0][i] =
190 lcr[i] |= 1 << (4 * x); 175 svbi->service_lines[1][i] = 0;
191 break; 176
192 case V4L2_SLICED_WSS_625: 177 for (i = 22; i <= 23; i++)
193 lcr[i] |= 4 << (4 * x); 178 svbi->service_lines[0][i] =
194 break; 179 svbi->service_lines[1][i] = 0;
195 case V4L2_SLICED_CAPTION_525: 180 }
196 lcr[i] |= 6 << (4 * x);
197 break;
198 case V4L2_SLICED_VPS:
199 lcr[i] |= 9 << (4 * x);
200 break;
201 }
202 }
203 }
204 181
205 if (is_pal) { 182 for (i = 7; i <= 23; i++) {
206 for (x = 1, i = 0x424; i <= 0x434; i++, x++) { 183 for (x = 0; x <= 1; x++) {
207 cx25840_write(client, i, lcr[6 + x]); 184 switch (svbi->service_lines[1-x][i]) {
208 } 185 case V4L2_SLICED_TELETEXT_B:
209 } 186 lcr[i] |= 1 << (4 * x);
210 else { 187 break;
211 for (x = 1, i = 0x424; i <= 0x430; i++, x++) { 188 case V4L2_SLICED_WSS_625:
212 cx25840_write(client, i, lcr[9 + x]); 189 lcr[i] |= 4 << (4 * x);
213 } 190 break;
214 for (i = 0x431; i <= 0x434; i++) { 191 case V4L2_SLICED_CAPTION_525:
215 cx25840_write(client, i, 0); 192 lcr[i] |= 6 << (4 * x);
193 break;
194 case V4L2_SLICED_VPS:
195 lcr[i] |= 9 << (4 * x);
196 break;
216 } 197 }
217 } 198 }
199 }
218 200
219 cx25840_write(client, 0x43c, 0x16); 201 if (is_pal) {
220 202 for (x = 1, i = 0x424; i <= 0x434; i++, x++)
221 if (is_pal) { 203 cx25840_write(client, i, lcr[6 + x]);
222 cx25840_write(client, 0x474, 0x2a); 204 } else {
223 } else { 205 for (x = 1, i = 0x424; i <= 0x430; i++, x++)
224 cx25840_write(client, 0x474, 0x22); 206 cx25840_write(client, i, lcr[9 + x]);
225 } 207 for (i = 0x431; i <= 0x434; i++)
226 break; 208 cx25840_write(client, i, 0);
227 } 209 }
228 210
229 case VIDIOC_INT_DECODE_VBI_LINE: 211 cx25840_write(client, 0x43c, 0x16);
230 { 212 cx25840_write(client, 0x474, is_pal ? 0x2a : 0x22);
231 struct v4l2_decode_vbi_line *vbi = arg; 213 return 0;
232 u8 *p = vbi->p; 214}
233 int id1, id2, l, err = 0;
234 215
235 if (p[0] || p[1] != 0xff || p[2] != 0xff || 216int cx25840_decode_vbi_line(struct v4l2_subdev *sd, struct v4l2_decode_vbi_line *vbi)
236 (p[3] != 0x55 && p[3] != 0x91)) { 217{
237 vbi->line = vbi->type = 0; 218 struct cx25840_state *state = to_state(sd);
238 break; 219 u8 *p = vbi->p;
239 } 220 int id1, id2, l, err = 0;
221
222 if (p[0] || p[1] != 0xff || p[2] != 0xff ||
223 (p[3] != 0x55 && p[3] != 0x91)) {
224 vbi->line = vbi->type = 0;
225 return 0;
226 }
240 227
241 p += 4; 228 p += 4;
242 id1 = p[-1]; 229 id1 = p[-1];
243 id2 = p[0] & 0xf; 230 id2 = p[0] & 0xf;
244 l = p[2] & 0x3f; 231 l = p[2] & 0x3f;
245 l += state->vbi_line_offset; 232 l += state->vbi_line_offset;
246 p += 4; 233 p += 4;
247 234
248 switch (id2) { 235 switch (id2) {
249 case 1: 236 case 1:
250 id2 = V4L2_SLICED_TELETEXT_B; 237 id2 = V4L2_SLICED_TELETEXT_B;
251 break; 238 break;
252 case 4: 239 case 4:
253 id2 = V4L2_SLICED_WSS_625; 240 id2 = V4L2_SLICED_WSS_625;
254 break; 241 break;
255 case 6: 242 case 6:
256 id2 = V4L2_SLICED_CAPTION_525; 243 id2 = V4L2_SLICED_CAPTION_525;
257 err = !odd_parity(p[0]) || !odd_parity(p[1]); 244 err = !odd_parity(p[0]) || !odd_parity(p[1]);
258 break; 245 break;
259 case 9: 246 case 9:
260 id2 = V4L2_SLICED_VPS; 247 id2 = V4L2_SLICED_VPS;
261 if (decode_vps(p, p) != 0) { 248 if (decode_vps(p, p) != 0)
262 err = 1;
263 }
264 break;
265 default:
266 id2 = 0;
267 err = 1; 249 err = 1;
268 break;
269 }
270
271 vbi->type = err ? 0 : id2;
272 vbi->line = err ? 0 : l;
273 vbi->is_second_field = err ? 0 : (id1 == 0x55);
274 vbi->p = p;
275 break; 250 break;
276 } 251 default:
252 id2 = 0;
253 err = 1;
254 break;
277 } 255 }
278 256
257 vbi->type = err ? 0 : id2;
258 vbi->line = err ? 0 : l;
259 vbi->is_second_field = err ? 0 : (id1 == 0x55);
260 vbi->p = p;
279 return 0; 261 return 0;
280} 262}
diff --git a/drivers/media/video/cx88/Kconfig b/drivers/media/video/cx88/Kconfig
index 2d250a2a7bc3..49952980dab3 100644
--- a/drivers/media/video/cx88/Kconfig
+++ b/drivers/media/video/cx88/Kconfig
@@ -61,7 +61,7 @@ config VIDEO_CX88_DVB
61 select DVB_STV0299 if !DVB_FE_CUSTOMISE 61 select DVB_STV0299 if !DVB_FE_CUSTOMISE
62 select DVB_STV0288 if !DVB_FE_CUSTOMISE 62 select DVB_STV0288 if !DVB_FE_CUSTOMISE
63 select DVB_STB6000 if !DVB_FE_CUSTOMISE 63 select DVB_STB6000 if !DVB_FE_CUSTOMISE
64 select MEDIA_TUNER_SIMPLE if !MEDIA_TUNER_CUSTOMIZE 64 select MEDIA_TUNER_SIMPLE if !MEDIA_TUNER_CUSTOMISE
65 ---help--- 65 ---help---
66 This adds support for DVB/ATSC cards based on the 66 This adds support for DVB/ATSC cards based on the
67 Conexant 2388x chip. 67 Conexant 2388x chip.
diff --git a/drivers/media/video/cx88/cx88-blackbird.c b/drivers/media/video/cx88/cx88-blackbird.c
index 7f5b8bfd08ac..44eacfb0d0d6 100644
--- a/drivers/media/video/cx88/cx88-blackbird.c
+++ b/drivers/media/video/cx88/cx88-blackbird.c
@@ -746,7 +746,6 @@ static int vidioc_enum_fmt_vid_cap (struct file *file, void *priv,
746 return -EINVAL; 746 return -EINVAL;
747 747
748 strlcpy(f->description, "MPEG", sizeof(f->description)); 748 strlcpy(f->description, "MPEG", sizeof(f->description));
749 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
750 f->pixelformat = V4L2_PIX_FMT_MPEG; 749 f->pixelformat = V4L2_PIX_FMT_MPEG;
751 return 0; 750 return 0;
752} 751}
@@ -757,7 +756,6 @@ static int vidioc_g_fmt_vid_cap (struct file *file, void *priv,
757 struct cx8802_fh *fh = priv; 756 struct cx8802_fh *fh = priv;
758 struct cx8802_dev *dev = fh->dev; 757 struct cx8802_dev *dev = fh->dev;
759 758
760 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
761 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG; 759 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
762 f->fmt.pix.bytesperline = 0; 760 f->fmt.pix.bytesperline = 0;
763 f->fmt.pix.sizeimage = dev->ts_packet_size * dev->ts_packet_count; /* 188 * 4 * 1024; */ 761 f->fmt.pix.sizeimage = dev->ts_packet_size * dev->ts_packet_count; /* 188 * 4 * 1024; */
@@ -776,7 +774,6 @@ static int vidioc_try_fmt_vid_cap (struct file *file, void *priv,
776 struct cx8802_fh *fh = priv; 774 struct cx8802_fh *fh = priv;
777 struct cx8802_dev *dev = fh->dev; 775 struct cx8802_dev *dev = fh->dev;
778 776
779 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
780 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG; 777 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
781 f->fmt.pix.bytesperline = 0; 778 f->fmt.pix.bytesperline = 0;
782 f->fmt.pix.sizeimage = dev->ts_packet_size * dev->ts_packet_count; /* 188 * 4 * 1024; */; 779 f->fmt.pix.sizeimage = dev->ts_packet_size * dev->ts_packet_count; /* 188 * 4 * 1024; */;
@@ -793,7 +790,6 @@ static int vidioc_s_fmt_vid_cap (struct file *file, void *priv,
793 struct cx8802_dev *dev = fh->dev; 790 struct cx8802_dev *dev = fh->dev;
794 struct cx88_core *core = dev->core; 791 struct cx88_core *core = dev->core;
795 792
796 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
797 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG; 793 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
798 f->fmt.pix.bytesperline = 0; 794 f->fmt.pix.bytesperline = 0;
799 f->fmt.pix.sizeimage = dev->ts_packet_size * dev->ts_packet_count; /* 188 * 4 * 1024; */; 795 f->fmt.pix.sizeimage = dev->ts_packet_size * dev->ts_packet_count; /* 188 * 4 * 1024; */;
@@ -919,7 +915,7 @@ static int vidioc_log_status (struct file *file, void *priv)
919 snprintf(name, sizeof(name), "%s/2", core->name); 915 snprintf(name, sizeof(name), "%s/2", core->name);
920 printk("%s/2: ============ START LOG STATUS ============\n", 916 printk("%s/2: ============ START LOG STATUS ============\n",
921 core->name); 917 core->name);
922 cx88_call_i2c_clients(core, VIDIOC_LOG_STATUS, NULL); 918 call_all(core, core, log_status);
923 cx2341x_log_status(&dev->params, name); 919 cx2341x_log_status(&dev->params, name);
924 printk("%s/2: ============= END LOG STATUS =============\n", 920 printk("%s/2: ============= END LOG STATUS =============\n",
925 core->name); 921 core->name);
@@ -974,7 +970,7 @@ static int vidioc_g_frequency (struct file *file, void *priv,
974 970
975 f->type = V4L2_TUNER_ANALOG_TV; 971 f->type = V4L2_TUNER_ANALOG_TV;
976 f->frequency = core->freq; 972 f->frequency = core->freq;
977 cx88_call_i2c_clients(core,VIDIOC_G_FREQUENCY,f); 973 call_all(core, tuner, g_frequency, f);
978 974
979 return 0; 975 return 0;
980} 976}
diff --git a/drivers/media/video/cx88/cx88-cards.c b/drivers/media/video/cx88/cx88-cards.c
index 733ede34f93a..0363971a23a8 100644
--- a/drivers/media/video/cx88/cx88-cards.c
+++ b/drivers/media/video/cx88/cx88-cards.c
@@ -732,6 +732,8 @@ static const struct cx88_board cx88_boards[] = {
732 .radio_type = UNSET, 732 .radio_type = UNSET,
733 .tuner_addr = ADDR_UNSET, 733 .tuner_addr = ADDR_UNSET,
734 .radio_addr = ADDR_UNSET, 734 .radio_addr = ADDR_UNSET,
735 /* Some variants use a tda9874 and so need the tvaudio module. */
736 .audio_chip = V4L2_IDENT_TVAUDIO,
735 .input = {{ 737 .input = {{
736 .type = CX88_VMUX_TELEVISION, 738 .type = CX88_VMUX_TELEVISION,
737 .vmux = 0, 739 .vmux = 0,
@@ -1934,6 +1936,39 @@ static const struct cx88_board cx88_boards[] = {
1934 } }, 1936 } },
1935 .mpeg = CX88_MPEG_DVB, 1937 .mpeg = CX88_MPEG_DVB,
1936 }, 1938 },
1939 [CX88_BOARD_TERRATEC_CINERGY_HT_PCI_MKII] = {
1940 .name = "Terratec Cinergy HT PCI MKII",
1941 .tuner_type = TUNER_XC2028,
1942 .tuner_addr = 0x61,
1943 .radio_type = TUNER_XC2028,
1944 .radio_addr = 0x61,
1945 .input = { {
1946 .type = CX88_VMUX_TELEVISION,
1947 .vmux = 0,
1948 .gpio0 = 0x004ff,
1949 .gpio1 = 0x010ff,
1950 .gpio2 = 0x00001,
1951 }, {
1952 .type = CX88_VMUX_COMPOSITE1,
1953 .vmux = 1,
1954 .gpio0 = 0x004fb,
1955 .gpio1 = 0x010ef,
1956 .audioroute = 1,
1957 }, {
1958 .type = CX88_VMUX_SVIDEO,
1959 .vmux = 2,
1960 .gpio0 = 0x004fb,
1961 .gpio1 = 0x010ef,
1962 .audioroute = 1,
1963 } },
1964 .radio = {
1965 .type = CX88_RADIO,
1966 .gpio0 = 0x004ff,
1967 .gpio1 = 0x010ff,
1968 .gpio2 = 0x0ff,
1969 },
1970 .mpeg = CX88_MPEG_DVB,
1971 },
1937}; 1972};
1938 1973
1939/* ------------------------------------------------------------------ */ 1974/* ------------------------------------------------------------------ */
@@ -2343,6 +2378,10 @@ static const struct cx88_subid cx88_subids[] = {
2343 .subvendor = 0xb200, 2378 .subvendor = 0xb200,
2344 .subdevice = 0x4200, 2379 .subdevice = 0x4200,
2345 .card = CX88_BOARD_SATTRADE_ST4200, 2380 .card = CX88_BOARD_SATTRADE_ST4200,
2381 }, {
2382 .subvendor = 0x153b,
2383 .subdevice = 0x1177,
2384 .card = CX88_BOARD_TERRATEC_CINERGY_HT_PCI_MKII,
2346 }, 2385 },
2347}; 2386};
2348 2387
@@ -2819,6 +2858,7 @@ void cx88_setup_xc3028(struct cx88_core *core, struct xc2028_ctrl *ctl)
2819 */ 2858 */
2820 break; 2859 break;
2821 case CX88_BOARD_PINNACLE_HYBRID_PCTV: 2860 case CX88_BOARD_PINNACLE_HYBRID_PCTV:
2861 case CX88_BOARD_TERRATEC_CINERGY_HT_PCI_MKII:
2822 ctl->demod = XC3028_FE_ZARLINK456; 2862 ctl->demod = XC3028_FE_ZARLINK456;
2823 ctl->mts = 1; 2863 ctl->mts = 1;
2824 break; 2864 break;
@@ -2947,7 +2987,7 @@ static void cx88_card_setup(struct cx88_core *core)
2947 tea5767_cfg.tuner = TUNER_TEA5767; 2987 tea5767_cfg.tuner = TUNER_TEA5767;
2948 tea5767_cfg.priv = &ctl; 2988 tea5767_cfg.priv = &ctl;
2949 2989
2950 cx88_call_i2c_clients(core, TUNER_SET_CONFIG, &tea5767_cfg); 2990 call_all(core, tuner, s_config, &tea5767_cfg);
2951 break; 2991 break;
2952 } 2992 }
2953 case CX88_BOARD_TEVII_S420: 2993 case CX88_BOARD_TEVII_S420:
@@ -2972,7 +3012,7 @@ static void cx88_card_setup(struct cx88_core *core)
2972 tun_setup.type = core->board.radio_type; 3012 tun_setup.type = core->board.radio_type;
2973 tun_setup.addr = core->board.radio_addr; 3013 tun_setup.addr = core->board.radio_addr;
2974 tun_setup.tuner_callback = cx88_tuner_callback; 3014 tun_setup.tuner_callback = cx88_tuner_callback;
2975 cx88_call_i2c_clients(core, TUNER_SET_TYPE_ADDR, &tun_setup); 3015 call_all(core, tuner, s_type_addr, &tun_setup);
2976 mode_mask &= ~T_RADIO; 3016 mode_mask &= ~T_RADIO;
2977 } 3017 }
2978 3018
@@ -2982,7 +3022,7 @@ static void cx88_card_setup(struct cx88_core *core)
2982 tun_setup.addr = core->board.tuner_addr; 3022 tun_setup.addr = core->board.tuner_addr;
2983 tun_setup.tuner_callback = cx88_tuner_callback; 3023 tun_setup.tuner_callback = cx88_tuner_callback;
2984 3024
2985 cx88_call_i2c_clients(core, TUNER_SET_TYPE_ADDR, &tun_setup); 3025 call_all(core, tuner, s_type_addr, &tun_setup);
2986 } 3026 }
2987 3027
2988 if (core->board.tda9887_conf) { 3028 if (core->board.tda9887_conf) {
@@ -2991,7 +3031,7 @@ static void cx88_card_setup(struct cx88_core *core)
2991 tda9887_cfg.tuner = TUNER_TDA9887; 3031 tda9887_cfg.tuner = TUNER_TDA9887;
2992 tda9887_cfg.priv = &core->board.tda9887_conf; 3032 tda9887_cfg.priv = &core->board.tda9887_conf;
2993 3033
2994 cx88_call_i2c_clients(core, TUNER_SET_CONFIG, &tda9887_cfg); 3034 call_all(core, tuner, s_config, &tda9887_cfg);
2995 } 3035 }
2996 3036
2997 if (core->board.tuner_type == TUNER_XC2028) { 3037 if (core->board.tuner_type == TUNER_XC2028) {
@@ -3007,9 +3047,9 @@ static void cx88_card_setup(struct cx88_core *core)
3007 xc2028_cfg.priv = &ctl; 3047 xc2028_cfg.priv = &ctl;
3008 info_printk(core, "Asking xc2028/3028 to load firmware %s\n", 3048 info_printk(core, "Asking xc2028/3028 to load firmware %s\n",
3009 ctl.fname); 3049 ctl.fname);
3010 cx88_call_i2c_clients(core, TUNER_SET_CONFIG, &xc2028_cfg); 3050 call_all(core, tuner, s_config, &xc2028_cfg);
3011 } 3051 }
3012 cx88_call_i2c_clients (core, TUNER_SET_STANDBY, NULL); 3052 call_all(core, core, s_standby, 0);
3013} 3053}
3014 3054
3015/* ------------------------------------------------------------------ */ 3055/* ------------------------------------------------------------------ */
@@ -3089,6 +3129,8 @@ struct cx88_core *cx88_core_create(struct pci_dev *pci, int nr)
3089 int i; 3129 int i;
3090 3130
3091 core = kzalloc(sizeof(*core), GFP_KERNEL); 3131 core = kzalloc(sizeof(*core), GFP_KERNEL);
3132 if (core == NULL)
3133 return NULL;
3092 3134
3093 atomic_inc(&core->refcount); 3135 atomic_inc(&core->refcount);
3094 core->pci_bus = pci->bus->number; 3136 core->pci_bus = pci->bus->number;
@@ -3100,7 +3142,15 @@ struct cx88_core *cx88_core_create(struct pci_dev *pci, int nr)
3100 3142
3101 core->nr = nr; 3143 core->nr = nr;
3102 sprintf(core->name, "cx88[%d]", core->nr); 3144 sprintf(core->name, "cx88[%d]", core->nr);
3145
3146 strcpy(core->v4l2_dev.name, core->name);
3147 if (v4l2_device_register(NULL, &core->v4l2_dev)) {
3148 kfree(core);
3149 return NULL;
3150 }
3151
3103 if (0 != cx88_get_resources(core, pci)) { 3152 if (0 != cx88_get_resources(core, pci)) {
3153 v4l2_device_unregister(&core->v4l2_dev);
3104 kfree(core); 3154 kfree(core);
3105 return NULL; 3155 return NULL;
3106 } 3156 }
@@ -3111,6 +3161,11 @@ struct cx88_core *cx88_core_create(struct pci_dev *pci, int nr)
3111 pci_resource_len(pci, 0)); 3161 pci_resource_len(pci, 0));
3112 core->bmmio = (u8 __iomem *)core->lmmio; 3162 core->bmmio = (u8 __iomem *)core->lmmio;
3113 3163
3164 if (core->lmmio == NULL) {
3165 kfree(core);
3166 return NULL;
3167 }
3168
3114 /* board config */ 3169 /* board config */
3115 core->boardnr = UNSET; 3170 core->boardnr = UNSET;
3116 if (card[core->nr] < ARRAY_SIZE(cx88_boards)) 3171 if (card[core->nr] < ARRAY_SIZE(cx88_boards))
@@ -3149,8 +3204,36 @@ struct cx88_core *cx88_core_create(struct pci_dev *pci, int nr)
3149 cx88_i2c_init(core, pci); 3204 cx88_i2c_init(core, pci);
3150 3205
3151 /* load tuner module, if needed */ 3206 /* load tuner module, if needed */
3152 if (TUNER_ABSENT != core->board.tuner_type) 3207 if (TUNER_ABSENT != core->board.tuner_type) {
3153 request_module("tuner"); 3208 /* Ignore 0x6b and 0x6f on cx88 boards.
3209 * FusionHDTV5 RT Gold has an ir receiver at 0x6b
3210 * and an RTC at 0x6f which can get corrupted if probed. */
3211 static const unsigned short tv_addrs[] = {
3212 0x42, 0x43, 0x4a, 0x4b, /* tda8290 */
3213 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
3214 0x68, 0x69, 0x6a, 0x6c, 0x6d, 0x6e,
3215 I2C_CLIENT_END
3216 };
3217 int has_demod = (core->board.tda9887_conf & TDA9887_PRESENT);
3218
3219 /* I don't trust the radio_type as is stored in the card
3220 definitions, so we just probe for it.
3221 The radio_type is sometimes missing, or set to UNSET but
3222 later code configures a tea5767.
3223 */
3224 v4l2_i2c_new_probed_subdev(&core->i2c_adap, "tuner", "tuner",
3225 v4l2_i2c_tuner_addrs(ADDRS_RADIO));
3226 if (has_demod)
3227 v4l2_i2c_new_probed_subdev(&core->i2c_adap, "tuner",
3228 "tuner", v4l2_i2c_tuner_addrs(ADDRS_DEMOD));
3229 if (core->board.tuner_addr == ADDR_UNSET) {
3230 v4l2_i2c_new_probed_subdev(&core->i2c_adap, "tuner",
3231 "tuner", has_demod ? tv_addrs + 4 : tv_addrs);
3232 } else {
3233 v4l2_i2c_new_subdev(&core->i2c_adap,
3234 "tuner", "tuner", core->board.tuner_addr);
3235 }
3236 }
3154 3237
3155 cx88_card_setup(core); 3238 cx88_card_setup(core);
3156 cx88_ir_init(core, pci); 3239 cx88_ir_init(core, pci);
diff --git a/drivers/media/video/cx88/cx88-core.c b/drivers/media/video/cx88/cx88-core.c
index b045874ad04f..f2fb9f30bfc1 100644
--- a/drivers/media/video/cx88/cx88-core.c
+++ b/drivers/media/video/cx88/cx88-core.c
@@ -991,7 +991,7 @@ int cx88_set_tvnorm(struct cx88_core *core, v4l2_std_id norm)
991 set_tvaudio(core); 991 set_tvaudio(core);
992 992
993 // tell i2c chips 993 // tell i2c chips
994 cx88_call_i2c_clients(core,VIDIOC_S_STD,&norm); 994 call_all(core, tuner, s_std, norm);
995 995
996 // done 996 // done
997 return 0; 997 return 0;
@@ -1011,7 +1011,8 @@ struct video_device *cx88_vdev_init(struct cx88_core *core,
1011 return NULL; 1011 return NULL;
1012 *vfd = *template; 1012 *vfd = *template;
1013 vfd->minor = -1; 1013 vfd->minor = -1;
1014 vfd->parent = &pci->dev; 1014 vfd->v4l2_dev = &core->v4l2_dev;
1015 vfd->parent = &pci->dev;
1015 vfd->release = video_device_release; 1016 vfd->release = video_device_release;
1016 snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)", 1017 snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)",
1017 core->name, type, core->board.name); 1018 core->name, type, core->board.name);
@@ -1058,12 +1059,16 @@ void cx88_core_put(struct cx88_core *core, struct pci_dev *pci)
1058 1059
1059 mutex_lock(&devlist); 1060 mutex_lock(&devlist);
1060 cx88_ir_fini(core); 1061 cx88_ir_fini(core);
1061 if (0 == core->i2c_rc) 1062 if (0 == core->i2c_rc) {
1063 if (core->i2c_rtc)
1064 i2c_unregister_device(core->i2c_rtc);
1062 i2c_del_adapter(&core->i2c_adap); 1065 i2c_del_adapter(&core->i2c_adap);
1066 }
1063 list_del(&core->devlist); 1067 list_del(&core->devlist);
1064 iounmap(core->lmmio); 1068 iounmap(core->lmmio);
1065 cx88_devcount--; 1069 cx88_devcount--;
1066 mutex_unlock(&devlist); 1070 mutex_unlock(&devlist);
1071 v4l2_device_unregister(&core->v4l2_dev);
1067 kfree(core); 1072 kfree(core);
1068} 1073}
1069 1074
diff --git a/drivers/media/video/cx88/cx88-dvb.c b/drivers/media/video/cx88/cx88-dvb.c
index aef5297534af..4ff4d9fe0355 100644
--- a/drivers/media/video/cx88/cx88-dvb.c
+++ b/drivers/media/video/cx88/cx88-dvb.c
@@ -241,6 +241,12 @@ static struct mt352_config dvico_fusionhdtv_dual = {
241 .demod_init = dvico_dual_demod_init, 241 .demod_init = dvico_dual_demod_init,
242}; 242};
243 243
244static struct zl10353_config cx88_terratec_cinergy_ht_pci_mkii_config = {
245 .demod_address = (0x1e >> 1),
246 .no_tuner = 1,
247 .if2 = 45600,
248};
249
244#if defined(CONFIG_VIDEO_CX88_VP3054) || (defined(CONFIG_VIDEO_CX88_VP3054_MODULE) && defined(MODULE)) 250#if defined(CONFIG_VIDEO_CX88_VP3054) || (defined(CONFIG_VIDEO_CX88_VP3054_MODULE) && defined(MODULE))
245static int dntv_live_dvbt_pro_demod_init(struct dvb_frontend* fe) 251static int dntv_live_dvbt_pro_demod_init(struct dvb_frontend* fe)
246{ 252{
@@ -1131,6 +1137,16 @@ static int dvb_register(struct cx8802_dev *dev)
1131 if (fe0->dvb.frontend != NULL) 1137 if (fe0->dvb.frontend != NULL)
1132 fe0->dvb.frontend->ops.set_voltage = tevii_dvbs_set_voltage; 1138 fe0->dvb.frontend->ops.set_voltage = tevii_dvbs_set_voltage;
1133 break; 1139 break;
1140 case CX88_BOARD_TERRATEC_CINERGY_HT_PCI_MKII:
1141 fe0->dvb.frontend = dvb_attach(zl10353_attach,
1142 &cx88_terratec_cinergy_ht_pci_mkii_config,
1143 &core->i2c_adap);
1144 if (fe0->dvb.frontend) {
1145 fe0->dvb.frontend->ops.i2c_gate_ctrl = NULL;
1146 if (attach_xc3028(0x61, dev) < 0)
1147 goto frontend_detach;
1148 }
1149 break;
1134 default: 1150 default:
1135 printk(KERN_ERR "%s/2: The frontend of your DVB/ATSC card isn't supported yet\n", 1151 printk(KERN_ERR "%s/2: The frontend of your DVB/ATSC card isn't supported yet\n",
1136 core->name); 1152 core->name);
@@ -1152,7 +1168,7 @@ static int dvb_register(struct cx8802_dev *dev)
1152 fe1->dvb.frontend->ops.ts_bus_ctrl = cx88_dvb_bus_ctrl; 1168 fe1->dvb.frontend->ops.ts_bus_ctrl = cx88_dvb_bus_ctrl;
1153 1169
1154 /* Put the analog decoder in standby to keep it quiet */ 1170 /* Put the analog decoder in standby to keep it quiet */
1155 cx88_call_i2c_clients(core, TUNER_SET_STANDBY, NULL); 1171 call_all(core, core, s_standby, 0);
1156 1172
1157 /* register everything */ 1173 /* register everything */
1158 return videobuf_dvb_register_bus(&dev->frontends, THIS_MODULE, dev, 1174 return videobuf_dvb_register_bus(&dev->frontends, THIS_MODULE, dev,
diff --git a/drivers/media/video/cx88/cx88-i2c.c b/drivers/media/video/cx88/cx88-i2c.c
index c0ff2305d804..996b4ed5a4fc 100644
--- a/drivers/media/video/cx88/cx88-i2c.c
+++ b/drivers/media/video/cx88/cx88-i2c.c
@@ -97,37 +97,6 @@ static int cx8800_bit_getsda(void *data)
97 97
98/* ----------------------------------------------------------------------- */ 98/* ----------------------------------------------------------------------- */
99 99
100static int attach_inform(struct i2c_client *client)
101{
102 struct cx88_core *core = i2c_get_adapdata(client->adapter);
103
104 dprintk(1, "%s i2c attach [addr=0x%x,client=%s]\n",
105 client->driver->driver.name, client->addr, client->name);
106 return 0;
107}
108
109static int detach_inform(struct i2c_client *client)
110{
111 struct cx88_core *core = i2c_get_adapdata(client->adapter);
112
113 dprintk(1, "i2c detach [client=%s]\n", client->name);
114 return 0;
115}
116
117void cx88_call_i2c_clients(struct cx88_core *core, unsigned int cmd, void *arg)
118{
119 if (0 != core->i2c_rc)
120 return;
121
122 if (core->gate_ctrl)
123 core->gate_ctrl(core, 1);
124
125 i2c_clients_command(&core->i2c_adap, cmd, arg);
126
127 if (core->gate_ctrl)
128 core->gate_ctrl(core, 0);
129}
130
131static const struct i2c_algo_bit_data cx8800_i2c_algo_template = { 100static const struct i2c_algo_bit_data cx8800_i2c_algo_template = {
132 .setsda = cx8800_bit_setsda, 101 .setsda = cx8800_bit_setsda,
133 .setscl = cx8800_bit_setscl, 102 .setscl = cx8800_bit_setscl,
@@ -173,20 +142,14 @@ int cx88_i2c_init(struct cx88_core *core, struct pci_dev *pci)
173 memcpy(&core->i2c_algo, &cx8800_i2c_algo_template, 142 memcpy(&core->i2c_algo, &cx8800_i2c_algo_template,
174 sizeof(core->i2c_algo)); 143 sizeof(core->i2c_algo));
175 144
176 if (core->board.tuner_type != TUNER_ABSENT)
177 core->i2c_adap.class |= I2C_CLASS_TV_ANALOG;
178 if (core->board.mpeg & CX88_MPEG_DVB)
179 core->i2c_adap.class |= I2C_CLASS_TV_DIGITAL;
180 145
181 core->i2c_adap.dev.parent = &pci->dev; 146 core->i2c_adap.dev.parent = &pci->dev;
182 strlcpy(core->i2c_adap.name,core->name,sizeof(core->i2c_adap.name)); 147 strlcpy(core->i2c_adap.name,core->name,sizeof(core->i2c_adap.name));
183 core->i2c_adap.owner = THIS_MODULE; 148 core->i2c_adap.owner = THIS_MODULE;
184 core->i2c_adap.id = I2C_HW_B_CX2388x; 149 core->i2c_adap.id = I2C_HW_B_CX2388x;
185 core->i2c_adap.client_register = attach_inform;
186 core->i2c_adap.client_unregister = detach_inform;
187 core->i2c_algo.udelay = i2c_udelay; 150 core->i2c_algo.udelay = i2c_udelay;
188 core->i2c_algo.data = core; 151 core->i2c_algo.data = core;
189 i2c_set_adapdata(&core->i2c_adap,core); 152 i2c_set_adapdata(&core->i2c_adap, &core->v4l2_dev);
190 core->i2c_adap.algo_data = &core->i2c_algo; 153 core->i2c_adap.algo_data = &core->i2c_algo;
191 core->i2c_client.adapter = &core->i2c_adap; 154 core->i2c_client.adapter = &core->i2c_adap;
192 strlcpy(core->i2c_client.name, "cx88xx internal", I2C_NAME_SIZE); 155 strlcpy(core->i2c_client.name, "cx88xx internal", I2C_NAME_SIZE);
@@ -222,8 +185,6 @@ int cx88_i2c_init(struct cx88_core *core, struct pci_dev *pci)
222 185
223/* ----------------------------------------------------------------------- */ 186/* ----------------------------------------------------------------------- */
224 187
225EXPORT_SYMBOL(cx88_call_i2c_clients);
226
227/* 188/*
228 * Local variables: 189 * Local variables:
229 * c-basic-offset: 8 190 * c-basic-offset: 8
diff --git a/drivers/media/video/cx88/cx88-input.c b/drivers/media/video/cx88/cx88-input.c
index 8683d104de72..ec05312a9b62 100644
--- a/drivers/media/video/cx88/cx88-input.c
+++ b/drivers/media/video/cx88/cx88-input.c
@@ -48,8 +48,7 @@ struct cx88_IR {
48 48
49 /* poll external decoder */ 49 /* poll external decoder */
50 int polling; 50 int polling;
51 struct work_struct work; 51 struct delayed_work work;
52 struct timer_list timer;
53 u32 gpio_addr; 52 u32 gpio_addr;
54 u32 last_gpio; 53 u32 last_gpio;
55 u32 mask_keycode; 54 u32 mask_keycode;
@@ -143,27 +142,19 @@ static void cx88_ir_handle_key(struct cx88_IR *ir)
143 } 142 }
144} 143}
145 144
146static void ir_timer(unsigned long data)
147{
148 struct cx88_IR *ir = (struct cx88_IR *)data;
149
150 schedule_work(&ir->work);
151}
152
153static void cx88_ir_work(struct work_struct *work) 145static void cx88_ir_work(struct work_struct *work)
154{ 146{
155 struct cx88_IR *ir = container_of(work, struct cx88_IR, work); 147 struct cx88_IR *ir = container_of(work, struct cx88_IR, work.work);
156 148
157 cx88_ir_handle_key(ir); 149 cx88_ir_handle_key(ir);
158 mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling)); 150 schedule_delayed_work(&ir->work, msecs_to_jiffies(ir->polling));
159} 151}
160 152
161void cx88_ir_start(struct cx88_core *core, struct cx88_IR *ir) 153void cx88_ir_start(struct cx88_core *core, struct cx88_IR *ir)
162{ 154{
163 if (ir->polling) { 155 if (ir->polling) {
164 setup_timer(&ir->timer, ir_timer, (unsigned long)ir); 156 INIT_DELAYED_WORK(&ir->work, cx88_ir_work);
165 INIT_WORK(&ir->work, cx88_ir_work); 157 schedule_delayed_work(&ir->work, 0);
166 schedule_work(&ir->work);
167 } 158 }
168 if (ir->sampling) { 159 if (ir->sampling) {
169 core->pci_irqmask |= PCI_INT_IR_SMPINT; 160 core->pci_irqmask |= PCI_INT_IR_SMPINT;
@@ -179,10 +170,8 @@ void cx88_ir_stop(struct cx88_core *core, struct cx88_IR *ir)
179 core->pci_irqmask &= ~PCI_INT_IR_SMPINT; 170 core->pci_irqmask &= ~PCI_INT_IR_SMPINT;
180 } 171 }
181 172
182 if (ir->polling) { 173 if (ir->polling)
183 del_timer_sync(&ir->timer); 174 cancel_delayed_work_sync(&ir->work);
184 flush_scheduled_work();
185 }
186} 175}
187 176
188/* ---------------------------------------------------------------------- */ 177/* ---------------------------------------------------------------------- */
@@ -226,6 +215,8 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
226 case CX88_BOARD_HAUPPAUGE_HVR3000: 215 case CX88_BOARD_HAUPPAUGE_HVR3000:
227 case CX88_BOARD_HAUPPAUGE_HVR4000: 216 case CX88_BOARD_HAUPPAUGE_HVR4000:
228 case CX88_BOARD_HAUPPAUGE_HVR4000LITE: 217 case CX88_BOARD_HAUPPAUGE_HVR4000LITE:
218 case CX88_BOARD_PCHDTV_HD3000:
219 case CX88_BOARD_PCHDTV_HD5500:
229 ir_codes = ir_codes_hauppauge_new; 220 ir_codes = ir_codes_hauppauge_new;
230 ir_type = IR_TYPE_RC5; 221 ir_type = IR_TYPE_RC5;
231 ir->sampling = 1; 222 ir->sampling = 1;
@@ -466,6 +457,8 @@ void cx88_ir_irq(struct cx88_core *core)
466 case CX88_BOARD_HAUPPAUGE_HVR3000: 457 case CX88_BOARD_HAUPPAUGE_HVR3000:
467 case CX88_BOARD_HAUPPAUGE_HVR4000: 458 case CX88_BOARD_HAUPPAUGE_HVR4000:
468 case CX88_BOARD_HAUPPAUGE_HVR4000LITE: 459 case CX88_BOARD_HAUPPAUGE_HVR4000LITE:
460 case CX88_BOARD_PCHDTV_HD3000:
461 case CX88_BOARD_PCHDTV_HD5500:
469 ircode = ir_decode_biphase(ir->samples, ir->scount, 5, 7); 462 ircode = ir_decode_biphase(ir->samples, ir->scount, 5, 7);
470 ir_dprintk("biphase decoded: %x\n", ircode); 463 ir_dprintk("biphase decoded: %x\n", ircode);
471 /* 464 /*
diff --git a/drivers/media/video/cx88/cx88-video.c b/drivers/media/video/cx88/cx88-video.c
index 791e69d804f9..434237af5184 100644
--- a/drivers/media/video/cx88/cx88-video.c
+++ b/drivers/media/video/cx88/cx88-video.c
@@ -41,11 +41,6 @@
41#include <media/v4l2-common.h> 41#include <media/v4l2-common.h>
42#include <media/v4l2-ioctl.h> 42#include <media/v4l2-ioctl.h>
43 43
44#ifdef CONFIG_VIDEO_V4L1_COMPAT
45/* Include V4L1 specific functions. Should be removed soon */
46#include <linux/videodev.h>
47#endif
48
49MODULE_DESCRIPTION("v4l2 driver module for cx2388x based TV cards"); 44MODULE_DESCRIPTION("v4l2 driver module for cx2388x based TV cards");
50MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]"); 45MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
51MODULE_LICENSE("GPL"); 46MODULE_LICENSE("GPL");
@@ -298,6 +293,7 @@ static struct cx88_ctrl cx8800_ctls[] = {
298}; 293};
299static const int CX8800_CTLS = ARRAY_SIZE(cx8800_ctls); 294static const int CX8800_CTLS = ARRAY_SIZE(cx8800_ctls);
300 295
296/* Must be sorted from low to high control ID! */
301const u32 cx88_user_ctrls[] = { 297const u32 cx88_user_ctrls[] = {
302 V4L2_CID_USER_CLASS, 298 V4L2_CID_USER_CLASS,
303 V4L2_CID_BRIGHTNESS, 299 V4L2_CID_BRIGHTNESS,
@@ -435,8 +431,7 @@ int cx88_video_mux(struct cx88_core *core, unsigned int input)
435 struct v4l2_routing route; 431 struct v4l2_routing route;
436 432
437 route.input = INPUT(input).audioroute; 433 route.input = INPUT(input).audioroute;
438 cx88_call_i2c_clients(core, 434 call_all(core, audio, s_routing, &route);
439 VIDIOC_INT_S_AUDIO_ROUTING, &route);
440 } 435 }
441 /* cx2388's C-ADC is connected to the tuner only. 436 /* cx2388's C-ADC is connected to the tuner only.
442 When used with S-Video, that ADC is busy dealing with 437 When used with S-Video, that ADC is busy dealing with
@@ -831,8 +826,7 @@ static int video_open(struct file *file)
831 struct v4l2_routing route; 826 struct v4l2_routing route;
832 827
833 route.input = core->board.radio.audioroute; 828 route.input = core->board.radio.audioroute;
834 cx88_call_i2c_clients(core, 829 call_all(core, audio, s_routing, &route);
835 VIDIOC_INT_S_AUDIO_ROUTING, &route);
836 } 830 }
837 /* "I2S ADC mode" */ 831 /* "I2S ADC mode" */
838 core->tvaudio = WW_I2SADC; 832 core->tvaudio = WW_I2SADC;
@@ -843,7 +837,7 @@ static int video_open(struct file *file)
843 cx88_set_tvaudio(core); 837 cx88_set_tvaudio(core);
844 cx88_set_stereo(core,V4L2_TUNER_MODE_STEREO,1); 838 cx88_set_stereo(core,V4L2_TUNER_MODE_STEREO,1);
845 } 839 }
846 cx88_call_i2c_clients(core,AUDC_SET_RADIO,NULL); 840 call_all(core, tuner, s_radio);
847 } 841 }
848 unlock_kernel(); 842 unlock_kernel();
849 843
@@ -937,7 +931,7 @@ static int video_release(struct file *file)
937 kfree(fh); 931 kfree(fh);
938 932
939 if(atomic_dec_and_test(&dev->core->users)) 933 if(atomic_dec_and_test(&dev->core->users))
940 cx88_call_i2c_clients (dev->core, TUNER_SET_STANDBY, NULL); 934 call_all(dev->core, core, s_standby, 0);
941 935
942 return 0; 936 return 0;
943} 937}
@@ -1276,15 +1270,12 @@ int cx88_enum_input (struct cx88_core *core,struct v4l2_input *i)
1276 [ CX88_VMUX_DVB ] = "DVB", 1270 [ CX88_VMUX_DVB ] = "DVB",
1277 [ CX88_VMUX_DEBUG ] = "for debug only", 1271 [ CX88_VMUX_DEBUG ] = "for debug only",
1278 }; 1272 };
1279 unsigned int n; 1273 unsigned int n = i->index;
1280 1274
1281 n = i->index;
1282 if (n >= 4) 1275 if (n >= 4)
1283 return -EINVAL; 1276 return -EINVAL;
1284 if (0 == INPUT(n).type) 1277 if (0 == INPUT(n).type)
1285 return -EINVAL; 1278 return -EINVAL;
1286 memset(i,0,sizeof(*i));
1287 i->index = n;
1288 i->type = V4L2_INPUT_TYPE_CAMERA; 1279 i->type = V4L2_INPUT_TYPE_CAMERA;
1289 strcpy(i->name,iname[INPUT(n).type]); 1280 strcpy(i->name,iname[INPUT(n).type]);
1290 if ((CX88_VMUX_TELEVISION == INPUT(n).type) || 1281 if ((CX88_VMUX_TELEVISION == INPUT(n).type) ||
@@ -1402,7 +1393,7 @@ static int vidioc_g_frequency (struct file *file, void *priv,
1402 f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; 1393 f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1403 f->frequency = core->freq; 1394 f->frequency = core->freq;
1404 1395
1405 cx88_call_i2c_clients(core,VIDIOC_G_FREQUENCY,f); 1396 call_all(core, tuner, g_frequency, f);
1406 1397
1407 return 0; 1398 return 0;
1408} 1399}
@@ -1418,7 +1409,7 @@ int cx88_set_freq (struct cx88_core *core,
1418 mutex_lock(&core->lock); 1409 mutex_lock(&core->lock);
1419 core->freq = f->frequency; 1410 core->freq = f->frequency;
1420 cx88_newstation(core); 1411 cx88_newstation(core);
1421 cx88_call_i2c_clients(core,VIDIOC_S_FREQUENCY,f); 1412 call_all(core, tuner, s_frequency, f);
1422 1413
1423 /* When changing channels it is required to reset TVAUDIO */ 1414 /* When changing channels it is required to reset TVAUDIO */
1424 msleep (10); 1415 msleep (10);
@@ -1500,7 +1491,7 @@ static int radio_g_tuner (struct file *file, void *priv,
1500 strcpy(t->name, "Radio"); 1491 strcpy(t->name, "Radio");
1501 t->type = V4L2_TUNER_RADIO; 1492 t->type = V4L2_TUNER_RADIO;
1502 1493
1503 cx88_call_i2c_clients(core,VIDIOC_G_TUNER,t); 1494 call_all(core, tuner, g_tuner, t);
1504 return 0; 1495 return 0;
1505} 1496}
1506 1497
@@ -1520,7 +1511,6 @@ static int radio_g_audio (struct file *file, void *priv, struct v4l2_audio *a)
1520 if (unlikely(a->index)) 1511 if (unlikely(a->index))
1521 return -EINVAL; 1512 return -EINVAL;
1522 1513
1523 memset(a,0,sizeof(*a));
1524 strcpy(a->name,"Radio"); 1514 strcpy(a->name,"Radio");
1525 return 0; 1515 return 0;
1526} 1516}
@@ -1535,7 +1525,7 @@ static int radio_s_tuner (struct file *file, void *priv,
1535 if (0 != t->index) 1525 if (0 != t->index)
1536 return -EINVAL; 1526 return -EINVAL;
1537 1527
1538 cx88_call_i2c_clients(core,VIDIOC_S_TUNER,t); 1528 call_all(core, tuner, s_tuner, t);
1539 1529
1540 return 0; 1530 return 0;
1541} 1531}
@@ -1892,12 +1882,30 @@ static int __devinit cx8800_initdev(struct pci_dev *pci_dev,
1892 /* load and configure helper modules */ 1882 /* load and configure helper modules */
1893 1883
1894 if (core->board.audio_chip == V4L2_IDENT_WM8775) 1884 if (core->board.audio_chip == V4L2_IDENT_WM8775)
1895 request_module("wm8775"); 1885 v4l2_i2c_new_subdev(&core->i2c_adap,
1886 "wm8775", "wm8775", 0x36 >> 1);
1887
1888 if (core->board.audio_chip == V4L2_IDENT_TVAUDIO) {
1889 /* This probes for a tda9874 as is used on some
1890 Pixelview Ultra boards. */
1891 static const unsigned short i2c_addr[] = {
1892 0xb0 >> 1, I2C_CLIENT_END
1893 };
1894
1895 v4l2_i2c_new_probed_subdev(&core->i2c_adap,
1896 "tvaudio", "tvaudio", i2c_addr);
1897 }
1896 1898
1897 switch (core->boardnr) { 1899 switch (core->boardnr) {
1898 case CX88_BOARD_DVICO_FUSIONHDTV_5_GOLD: 1900 case CX88_BOARD_DVICO_FUSIONHDTV_5_GOLD:
1899 case CX88_BOARD_DVICO_FUSIONHDTV_7_GOLD: 1901 case CX88_BOARD_DVICO_FUSIONHDTV_7_GOLD: {
1902 static struct i2c_board_info rtc_info = {
1903 I2C_BOARD_INFO("isl1208", 0x6f)
1904 };
1905
1900 request_module("rtc-isl1208"); 1906 request_module("rtc-isl1208");
1907 core->i2c_rtc = i2c_new_device(&core->i2c_adap, &rtc_info);
1908 }
1901 /* break intentionally omitted */ 1909 /* break intentionally omitted */
1902 case CX88_BOARD_DVICO_FUSIONHDTV_5_PCI_NANO: 1910 case CX88_BOARD_DVICO_FUSIONHDTV_5_PCI_NANO:
1903 request_module("ir-kbd-i2c"); 1911 request_module("ir-kbd-i2c");
diff --git a/drivers/media/video/cx88/cx88.h b/drivers/media/video/cx88/cx88.h
index 6025fdd23344..9a43fdf20fae 100644
--- a/drivers/media/video/cx88/cx88.h
+++ b/drivers/media/video/cx88/cx88.h
@@ -25,7 +25,7 @@
25#include <linux/videodev2.h> 25#include <linux/videodev2.h>
26#include <linux/kdev_t.h> 26#include <linux/kdev_t.h>
27 27
28#include <media/v4l2-common.h> 28#include <media/v4l2-device.h>
29#include <media/tuner.h> 29#include <media/tuner.h>
30#include <media/tveeprom.h> 30#include <media/tveeprom.h>
31#include <media/videobuf-dma-sg.h> 31#include <media/videobuf-dma-sg.h>
@@ -231,6 +231,7 @@ extern struct sram_channel cx88_sram_channels[];
231#define CX88_BOARD_SATTRADE_ST4200 76 231#define CX88_BOARD_SATTRADE_ST4200 76
232#define CX88_BOARD_TBS_8910 77 232#define CX88_BOARD_TBS_8910 77
233#define CX88_BOARD_PROF_6200 78 233#define CX88_BOARD_PROF_6200 78
234#define CX88_BOARD_TERRATEC_CINERGY_HT_PCI_MKII 79
234 235
235enum cx88_itype { 236enum cx88_itype {
236 CX88_VMUX_COMPOSITE1 = 1, 237 CX88_VMUX_COMPOSITE1 = 1,
@@ -302,7 +303,6 @@ struct cx88_dmaqueue {
302 struct btcx_riscmem stopper; 303 struct btcx_riscmem stopper;
303 u32 count; 304 u32 count;
304}; 305};
305struct cx88_core;
306 306
307struct cx88_core { 307struct cx88_core {
308 struct list_head devlist; 308 struct list_head devlist;
@@ -327,6 +327,8 @@ struct cx88_core {
327 u32 i2c_state, i2c_rc; 327 u32 i2c_state, i2c_rc;
328 328
329 /* config info -- analog */ 329 /* config info -- analog */
330 struct v4l2_device v4l2_dev;
331 struct i2c_client *i2c_rtc;
330 unsigned int boardnr; 332 unsigned int boardnr;
331 struct cx88_board board; 333 struct cx88_board board;
332 334
@@ -365,6 +367,22 @@ struct cx88_core {
365 int active_fe_id; 367 int active_fe_id;
366}; 368};
367 369
370static inline struct cx88_core *to_core(struct v4l2_device *v4l2_dev)
371{
372 return container_of(v4l2_dev, struct cx88_core, v4l2_dev);
373}
374
375#define call_all(core, o, f, args...) \
376 do { \
377 if (!core->i2c_rc) { \
378 if (core->gate_ctrl) \
379 core->gate_ctrl(core, 1); \
380 v4l2_device_call_all(&core->v4l2_dev, 0, o, f, ##args); \
381 if (core->gate_ctrl) \
382 core->gate_ctrl(core, 0); \
383 } \
384 } while (0)
385
368struct cx8800_dev; 386struct cx8800_dev;
369struct cx8802_dev; 387struct cx8802_dev;
370 388
@@ -610,8 +628,6 @@ extern struct videobuf_queue_ops cx8800_vbi_qops;
610/* cx88-i2c.c */ 628/* cx88-i2c.c */
611 629
612extern int cx88_i2c_init(struct cx88_core *core, struct pci_dev *pci); 630extern int cx88_i2c_init(struct cx88_core *core, struct pci_dev *pci);
613extern void cx88_call_i2c_clients(struct cx88_core *core,
614 unsigned int cmd, void *arg);
615 631
616 632
617/* ----------------------------------------------------------- */ 633/* ----------------------------------------------------------- */
diff --git a/drivers/media/video/dabusb.c b/drivers/media/video/dabusb.c
index 298810d5262b..ba3709bec3f0 100644
--- a/drivers/media/video/dabusb.c
+++ b/drivers/media/video/dabusb.c
@@ -189,17 +189,20 @@ static void dabusb_iso_complete (struct urb *purb)
189 dst += len; 189 dst += len;
190 } 190 }
191 else 191 else
192 err("dabusb_iso_complete: invalid len %d", len); 192 dev_err(&purb->dev->dev,
193 "dabusb_iso_complete: invalid len %d\n", len);
193 } 194 }
194 else 195 else
195 dev_warn(&purb->dev->dev, "dabusb_iso_complete: corrupted packet status: %d\n", purb->iso_frame_desc[i].status); 196 dev_warn(&purb->dev->dev, "dabusb_iso_complete: corrupted packet status: %d\n", purb->iso_frame_desc[i].status);
196 if (dst != purb->actual_length) 197 if (dst != purb->actual_length)
197 err("dst!=purb->actual_length:%d!=%d", dst, purb->actual_length); 198 dev_err(&purb->dev->dev,
199 "dst!=purb->actual_length:%d!=%d\n",
200 dst, purb->actual_length);
198 } 201 }
199 202
200 if (atomic_dec_and_test (&s->pending_io) && !s->remove_pending && s->state != _stopped) { 203 if (atomic_dec_and_test (&s->pending_io) && !s->remove_pending && s->state != _stopped) {
201 s->overruns++; 204 s->overruns++;
202 err("overrun (%d)", s->overruns); 205 dev_err(&purb->dev->dev, "overrun (%d)\n", s->overruns);
203 } 206 }
204 wake_up (&s->wait); 207 wake_up (&s->wait);
205} 208}
@@ -220,13 +223,14 @@ static int dabusb_alloc_buffers (pdabusb_t s)
220 while (transfer_len < (s->total_buffer_size << 10)) { 223 while (transfer_len < (s->total_buffer_size << 10)) {
221 b = kzalloc(sizeof (buff_t), GFP_KERNEL); 224 b = kzalloc(sizeof (buff_t), GFP_KERNEL);
222 if (!b) { 225 if (!b) {
223 err("kzalloc(sizeof(buff_t))==NULL"); 226 dev_err(&s->usbdev->dev,
227 "kzalloc(sizeof(buff_t))==NULL\n");
224 goto err; 228 goto err;
225 } 229 }
226 b->s = s; 230 b->s = s;
227 b->purb = usb_alloc_urb(packets, GFP_KERNEL); 231 b->purb = usb_alloc_urb(packets, GFP_KERNEL);
228 if (!b->purb) { 232 if (!b->purb) {
229 err("usb_alloc_urb == NULL"); 233 dev_err(&s->usbdev->dev, "usb_alloc_urb == NULL\n");
230 kfree (b); 234 kfree (b);
231 goto err; 235 goto err;
232 } 236 }
@@ -235,7 +239,8 @@ static int dabusb_alloc_buffers (pdabusb_t s)
235 if (!b->purb->transfer_buffer) { 239 if (!b->purb->transfer_buffer) {
236 kfree (b->purb); 240 kfree (b->purb);
237 kfree (b); 241 kfree (b);
238 err("kmalloc(%d)==NULL", transfer_buffer_length); 242 dev_err(&s->usbdev->dev,
243 "kmalloc(%d)==NULL\n", transfer_buffer_length);
239 goto err; 244 goto err;
240 } 245 }
241 246
@@ -279,10 +284,11 @@ static int dabusb_bulk (pdabusb_t s, pbulk_transfer_t pb)
279 284
280 ret=usb_bulk_msg(s->usbdev, pipe, pb->data, pb->size, &actual_length, 100); 285 ret=usb_bulk_msg(s->usbdev, pipe, pb->data, pb->size, &actual_length, 100);
281 if(ret<0) { 286 if(ret<0) {
282 err("dabusb: usb_bulk_msg failed(%d)",ret); 287 dev_err(&s->usbdev->dev,
288 "usb_bulk_msg failed(%d)\n", ret);
283 289
284 if (usb_set_interface (s->usbdev, _DABUSB_IF, 1) < 0) { 290 if (usb_set_interface (s->usbdev, _DABUSB_IF, 1) < 0) {
285 err("set_interface failed"); 291 dev_err(&s->usbdev->dev, "set_interface failed\n");
286 return -EINVAL; 292 return -EINVAL;
287 } 293 }
288 294
@@ -291,7 +297,7 @@ static int dabusb_bulk (pdabusb_t s, pbulk_transfer_t pb)
291 if( ret == -EPIPE ) { 297 if( ret == -EPIPE ) {
292 dev_warn(&s->usbdev->dev, "CLEAR_FEATURE request to remove STALL condition.\n"); 298 dev_warn(&s->usbdev->dev, "CLEAR_FEATURE request to remove STALL condition.\n");
293 if(usb_clear_halt(s->usbdev, usb_pipeendpoint(pipe))) 299 if(usb_clear_halt(s->usbdev, usb_pipeendpoint(pipe)))
294 err("request failed"); 300 dev_err(&s->usbdev->dev, "request failed\n");
295 } 301 }
296 302
297 pb->size = actual_length; 303 pb->size = actual_length;
@@ -305,7 +311,8 @@ static int dabusb_writemem (pdabusb_t s, int pos, const unsigned char *data,
305 unsigned char *transfer_buffer = kmalloc (len, GFP_KERNEL); 311 unsigned char *transfer_buffer = kmalloc (len, GFP_KERNEL);
306 312
307 if (!transfer_buffer) { 313 if (!transfer_buffer) {
308 err("dabusb_writemem: kmalloc(%d) failed.", len); 314 dev_err(&s->usbdev->dev,
315 "dabusb_writemem: kmalloc(%d) failed.\n", len);
309 return -ENOMEM; 316 return -ENOMEM;
310 } 317 }
311 318
@@ -327,13 +334,14 @@ static int dabusb_loadmem (pdabusb_t s, const char *fname)
327{ 334{
328 int ret; 335 int ret;
329 const struct ihex_binrec *rec; 336 const struct ihex_binrec *rec;
330 const struct firmware *fw; 337 const struct firmware *uninitialized_var(fw);
331 338
332 dbg("Enter dabusb_loadmem (internal)"); 339 dbg("Enter dabusb_loadmem (internal)");
333 340
334 ret = request_ihex_firmware(&fw, "dabusb/firmware.fw", &s->usbdev->dev); 341 ret = request_ihex_firmware(&fw, "dabusb/firmware.fw", &s->usbdev->dev);
335 if (ret) { 342 if (ret) {
336 err("Failed to load \"dabusb/firmware.fw\": %d\n", ret); 343 dev_err(&s->usbdev->dev,
344 "Failed to load \"dabusb/firmware.fw\": %d\n", ret);
337 goto out; 345 goto out;
338 } 346 }
339 ret = dabusb_8051_reset (s, 1); 347 ret = dabusb_8051_reset (s, 1);
@@ -346,9 +354,10 @@ static int dabusb_loadmem (pdabusb_t s, const char *fname)
346 ret = dabusb_writemem(s, be32_to_cpu(rec->addr), rec->data, 354 ret = dabusb_writemem(s, be32_to_cpu(rec->addr), rec->data,
347 be16_to_cpu(rec->len)); 355 be16_to_cpu(rec->len));
348 if (ret < 0) { 356 if (ret < 0) {
349 err("dabusb_writemem failed (%d %04X %p %d)", ret, 357 dev_err(&s->usbdev->dev,
350 be32_to_cpu(rec->addr), rec->data, 358 "dabusb_writemem failed (%d %04X %p %d)\n",
351 be16_to_cpu(rec->len)); 359 ret, be32_to_cpu(rec->addr),
360 rec->data, be16_to_cpu(rec->len));
352 break; 361 break;
353 } 362 }
354 } 363 }
@@ -396,13 +405,15 @@ static int dabusb_fpga_download (pdabusb_t s, const char *fname)
396 dbg("Enter dabusb_fpga_download (internal)"); 405 dbg("Enter dabusb_fpga_download (internal)");
397 406
398 if (!b) { 407 if (!b) {
399 err("kmalloc(sizeof(bulk_transfer_t))==NULL"); 408 dev_err(&s->usbdev->dev,
409 "kmalloc(sizeof(bulk_transfer_t))==NULL\n");
400 return -ENOMEM; 410 return -ENOMEM;
401 } 411 }
402 412
403 ret = request_firmware(&fw, "dabusb/bitstream.bin", &s->usbdev->dev); 413 ret = request_firmware(&fw, "dabusb/bitstream.bin", &s->usbdev->dev);
404 if (ret) { 414 if (ret) {
405 err("Failed to load \"dabusb/bitstream.bin\": %d\n", ret); 415 dev_err(&s->usbdev->dev,
416 "Failed to load \"dabusb/bitstream.bin\": %d\n", ret);
406 kfree(b); 417 kfree(b);
407 return ret; 418 return ret;
408 } 419 }
@@ -425,7 +436,7 @@ static int dabusb_fpga_download (pdabusb_t s, const char *fname)
425 memcpy (b->data + 4, fw->data + 74 + n, 60); 436 memcpy (b->data + 4, fw->data + 74 + n, 60);
426 ret = dabusb_bulk (s, b); 437 ret = dabusb_bulk (s, b);
427 if (ret < 0) { 438 if (ret < 0) {
428 err("dabusb_bulk failed."); 439 dev_err(&s->usbdev->dev, "dabusb_bulk failed.\n");
429 break; 440 break;
430 } 441 }
431 mdelay (1); 442 mdelay (1);
@@ -478,9 +489,11 @@ static int dabusb_startrek (pdabusb_t s)
478 489
479 ret = usb_submit_urb (end->purb, GFP_KERNEL); 490 ret = usb_submit_urb (end->purb, GFP_KERNEL);
480 if (ret) { 491 if (ret) {
481 err("usb_submit_urb returned:%d", ret); 492 dev_err(&s->usbdev->dev,
493 "usb_submit_urb returned:%d\n", ret);
482 if (dabusb_add_buf_tail (s, &s->free_buff_list, &s->rec_buff_list)) 494 if (dabusb_add_buf_tail (s, &s->free_buff_list, &s->rec_buff_list))
483 err("startrek: dabusb_add_buf_tail failed"); 495 dev_err(&s->usbdev->dev,
496 "startrek: dabusb_add_buf_tail failed\n");
484 break; 497 break;
485 } 498 }
486 else 499 else
@@ -523,7 +536,8 @@ static ssize_t dabusb_read (struct file *file, char __user *buf, size_t count, l
523 536
524 spin_unlock_irqrestore(&s->lock, flags); 537 spin_unlock_irqrestore(&s->lock, flags);
525 538
526 err("error: rec_buf_list is empty"); 539 dev_err(&s->usbdev->dev,
540 "error: rec_buf_list is empty\n");
527 goto err; 541 goto err;
528 } 542 }
529 543
@@ -552,7 +566,8 @@ static ssize_t dabusb_read (struct file *file, char __user *buf, size_t count, l
552 566
553 if (list_empty (&s->rec_buff_list)) { 567 if (list_empty (&s->rec_buff_list)) {
554 spin_unlock_irqrestore(&s->lock, flags); 568 spin_unlock_irqrestore(&s->lock, flags);
555 err("error: still no buffer available."); 569 dev_err(&s->usbdev->dev,
570 "error: still no buffer available.\n");
556 goto err; 571 goto err;
557 } 572 }
558 spin_unlock_irqrestore(&s->lock, flags); 573 spin_unlock_irqrestore(&s->lock, flags);
@@ -573,7 +588,7 @@ static ssize_t dabusb_read (struct file *file, char __user *buf, size_t count, l
573 dbg("copy_to_user:%p %p %d",buf, purb->transfer_buffer + s->readptr, cnt); 588 dbg("copy_to_user:%p %p %d",buf, purb->transfer_buffer + s->readptr, cnt);
574 589
575 if (copy_to_user (buf, purb->transfer_buffer + s->readptr, cnt)) { 590 if (copy_to_user (buf, purb->transfer_buffer + s->readptr, cnt)) {
576 err("read: copy_to_user failed"); 591 dev_err(&s->usbdev->dev, "read: copy_to_user failed\n");
577 if (!ret) 592 if (!ret)
578 ret = -EFAULT; 593 ret = -EFAULT;
579 goto err; 594 goto err;
@@ -587,7 +602,8 @@ static ssize_t dabusb_read (struct file *file, char __user *buf, size_t count, l
587 if (s->readptr == purb->actual_length) { 602 if (s->readptr == purb->actual_length) {
588 // finished, take next buffer 603 // finished, take next buffer
589 if (dabusb_add_buf_tail (s, &s->free_buff_list, &s->rec_buff_list)) 604 if (dabusb_add_buf_tail (s, &s->free_buff_list, &s->rec_buff_list))
590 err("read: dabusb_add_buf_tail failed"); 605 dev_err(&s->usbdev->dev,
606 "read: dabusb_add_buf_tail failed\n");
591 s->readptr = 0; 607 s->readptr = 0;
592 } 608 }
593 } 609 }
@@ -623,7 +639,7 @@ static int dabusb_open (struct inode *inode, struct file *file)
623 } 639 }
624 if (usb_set_interface (s->usbdev, _DABUSB_IF, 1) < 0) { 640 if (usb_set_interface (s->usbdev, _DABUSB_IF, 1) < 0) {
625 mutex_unlock(&s->mutex); 641 mutex_unlock(&s->mutex);
626 err("set_interface failed"); 642 dev_err(&s->usbdev->dev, "set_interface failed\n");
627 return -EINVAL; 643 return -EINVAL;
628 } 644 }
629 s->opened = 1; 645 s->opened = 1;
@@ -648,7 +664,7 @@ static int dabusb_release (struct inode *inode, struct file *file)
648 664
649 if (!s->remove_pending) { 665 if (!s->remove_pending) {
650 if (usb_set_interface (s->usbdev, _DABUSB_IF, 0) < 0) 666 if (usb_set_interface (s->usbdev, _DABUSB_IF, 0) < 0)
651 err("set_interface failed"); 667 dev_err(&s->usbdev->dev, "set_interface failed\n");
652 } 668 }
653 else 669 else
654 wake_up (&s->remove_ok); 670 wake_up (&s->remove_ok);
@@ -657,7 +673,7 @@ static int dabusb_release (struct inode *inode, struct file *file)
657 return 0; 673 return 0;
658} 674}
659 675
660static int dabusb_ioctl (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) 676static long dabusb_ioctl (struct file *file, unsigned int cmd, unsigned long arg)
661{ 677{
662 pdabusb_t s = (pdabusb_t) file->private_data; 678 pdabusb_t s = (pdabusb_t) file->private_data;
663 pbulk_transfer_t pbulk; 679 pbulk_transfer_t pbulk;
@@ -666,13 +682,17 @@ static int dabusb_ioctl (struct inode *inode, struct file *file, unsigned int cm
666 682
667 dbg("dabusb_ioctl"); 683 dbg("dabusb_ioctl");
668 684
669 if (s->remove_pending) 685 lock_kernel();
686 if (s->remove_pending) {
687 unlock_kernel();
670 return -EIO; 688 return -EIO;
689 }
671 690
672 mutex_lock(&s->mutex); 691 mutex_lock(&s->mutex);
673 692
674 if (!s->usbdev) { 693 if (!s->usbdev) {
675 mutex_unlock(&s->mutex); 694 mutex_unlock(&s->mutex);
695 unlock_kernel();
676 return -EIO; 696 return -EIO;
677 } 697 }
678 698
@@ -713,6 +733,7 @@ static int dabusb_ioctl (struct inode *inode, struct file *file, unsigned int cm
713 break; 733 break;
714 } 734 }
715 mutex_unlock(&s->mutex); 735 mutex_unlock(&s->mutex);
736 unlock_kernel();
716 return ret; 737 return ret;
717} 738}
718 739
@@ -721,7 +742,7 @@ static const struct file_operations dabusb_fops =
721 .owner = THIS_MODULE, 742 .owner = THIS_MODULE,
722 .llseek = no_llseek, 743 .llseek = no_llseek,
723 .read = dabusb_read, 744 .read = dabusb_read,
724 .ioctl = dabusb_ioctl, 745 .unlocked_ioctl = dabusb_ioctl,
725 .open = dabusb_open, 746 .open = dabusb_open,
726 .release = dabusb_release, 747 .release = dabusb_release,
727}; 748};
@@ -764,7 +785,7 @@ static int dabusb_probe (struct usb_interface *intf,
764 s->devnum = intf->minor; 785 s->devnum = intf->minor;
765 786
766 if (usb_reset_configuration (usbdev) < 0) { 787 if (usb_reset_configuration (usbdev) < 0) {
767 err("reset_configuration failed"); 788 dev_err(&intf->dev, "reset_configuration failed\n");
768 goto reject; 789 goto reject;
769 } 790 }
770 if (le16_to_cpu(usbdev->descriptor.idProduct) == 0x2131) { 791 if (le16_to_cpu(usbdev->descriptor.idProduct) == 0x2131) {
@@ -775,7 +796,7 @@ static int dabusb_probe (struct usb_interface *intf,
775 dabusb_fpga_download (s, NULL); 796 dabusb_fpga_download (s, NULL);
776 797
777 if (usb_set_interface (s->usbdev, _DABUSB_IF, 0) < 0) { 798 if (usb_set_interface (s->usbdev, _DABUSB_IF, 0) < 0) {
778 err("set_interface failed"); 799 dev_err(&intf->dev, "set_interface failed\n");
779 goto reject; 800 goto reject;
780 } 801 }
781 } 802 }
diff --git a/drivers/media/video/em28xx/em28xx-audio.c b/drivers/media/video/em28xx/em28xx-audio.c
index f132e31f6edd..0131322475bf 100644
--- a/drivers/media/video/em28xx/em28xx-audio.c
+++ b/drivers/media/video/em28xx/em28xx-audio.c
@@ -56,7 +56,7 @@ MODULE_PARM_DESC(debug, "activates debug info");
56 56
57static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; 57static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
58 58
59static int em28xx_isoc_audio_deinit(struct em28xx *dev) 59static int em28xx_deinit_isoc_audio(struct em28xx *dev)
60{ 60{
61 int i; 61 int i;
62 62
@@ -66,6 +66,7 @@ static int em28xx_isoc_audio_deinit(struct em28xx *dev)
66 usb_kill_urb(dev->adev.urb[i]); 66 usb_kill_urb(dev->adev.urb[i]);
67 else 67 else
68 usb_unlink_urb(dev->adev.urb[i]); 68 usb_unlink_urb(dev->adev.urb[i]);
69
69 usb_free_urb(dev->adev.urb[i]); 70 usb_free_urb(dev->adev.urb[i]);
70 dev->adev.urb[i] = NULL; 71 dev->adev.urb[i] = NULL;
71 72
@@ -87,6 +88,20 @@ static void em28xx_audio_isocirq(struct urb *urb)
87 unsigned int stride; 88 unsigned int stride;
88 struct snd_pcm_substream *substream; 89 struct snd_pcm_substream *substream;
89 struct snd_pcm_runtime *runtime; 90 struct snd_pcm_runtime *runtime;
91
92 switch (urb->status) {
93 case 0: /* success */
94 case -ETIMEDOUT: /* NAK */
95 break;
96 case -ECONNRESET: /* kill */
97 case -ENOENT:
98 case -ESHUTDOWN:
99 return;
100 default: /* error */
101 dprintk("urb completition error %d.\n", urb->status);
102 break;
103 }
104
90 if (dev->adev.capture_pcm_substream) { 105 if (dev->adev.capture_pcm_substream) {
91 substream = dev->adev.capture_pcm_substream; 106 substream = dev->adev.capture_pcm_substream;
92 runtime = substream->runtime; 107 runtime = substream->runtime;
@@ -137,9 +152,6 @@ static void em28xx_audio_isocirq(struct urb *urb)
137 } 152 }
138 urb->status = 0; 153 urb->status = 0;
139 154
140 if (dev->adev.shutdown)
141 return;
142
143 status = usb_submit_urb(urb, GFP_ATOMIC); 155 status = usb_submit_urb(urb, GFP_ATOMIC);
144 if (status < 0) { 156 if (status < 0) {
145 em28xx_errdev("resubmit of audio urb failed (error=%i)\n", 157 em28xx_errdev("resubmit of audio urb failed (error=%i)\n",
@@ -197,8 +209,7 @@ static int em28xx_init_audio_isoc(struct em28xx *dev)
197 for (i = 0; i < EM28XX_AUDIO_BUFS; i++) { 209 for (i = 0; i < EM28XX_AUDIO_BUFS; i++) {
198 errCode = usb_submit_urb(dev->adev.urb[i], GFP_ATOMIC); 210 errCode = usb_submit_urb(dev->adev.urb[i], GFP_ATOMIC);
199 if (errCode) { 211 if (errCode) {
200 em28xx_isoc_audio_deinit(dev); 212 em28xx_deinit_isoc_audio(dev);
201
202 return errCode; 213 return errCode;
203 } 214 }
204 } 215 }
@@ -213,14 +224,16 @@ static int em28xx_cmd(struct em28xx *dev, int cmd, int arg)
213 224
214 switch (cmd) { 225 switch (cmd) {
215 case EM28XX_CAPTURE_STREAM_EN: 226 case EM28XX_CAPTURE_STREAM_EN:
216 if (dev->adev.capture_stream == STREAM_OFF && arg == 1) { 227 if (dev->adev.capture_stream == STREAM_OFF &&
228 arg == EM28XX_START_AUDIO) {
217 dev->adev.capture_stream = STREAM_ON; 229 dev->adev.capture_stream = STREAM_ON;
218 em28xx_init_audio_isoc(dev); 230 em28xx_init_audio_isoc(dev);
219 } else if (dev->adev.capture_stream == STREAM_ON && arg == 0) { 231 } else if (dev->adev.capture_stream == STREAM_ON &&
232 arg == EM28XX_STOP_AUDIO) {
220 dev->adev.capture_stream = STREAM_OFF; 233 dev->adev.capture_stream = STREAM_OFF;
221 em28xx_isoc_audio_deinit(dev); 234 em28xx_deinit_isoc_audio(dev);
222 } else { 235 } else {
223 printk(KERN_ERR "An underrun very likely occurred. " 236 em28xx_errdev("An underrun very likely occurred. "
224 "Ignoring it.\n"); 237 "Ignoring it.\n");
225 } 238 }
226 return 0; 239 return 0;
@@ -234,7 +247,7 @@ static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs,
234{ 247{
235 struct snd_pcm_runtime *runtime = subs->runtime; 248 struct snd_pcm_runtime *runtime = subs->runtime;
236 249
237 dprintk("Alocating vbuffer\n"); 250 dprintk("Allocating vbuffer\n");
238 if (runtime->dma_area) { 251 if (runtime->dma_area) {
239 if (runtime->dma_bytes > size) 252 if (runtime->dma_bytes > size)
240 return 0; 253 return 0;
@@ -302,7 +315,9 @@ static int snd_em28xx_capture_open(struct snd_pcm_substream *substream)
302 dprintk("changing alternate number to 7\n"); 315 dprintk("changing alternate number to 7\n");
303 } 316 }
304 317
318 mutex_lock(&dev->lock);
305 dev->adev.users++; 319 dev->adev.users++;
320 mutex_unlock(&dev->lock);
306 321
307 snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS); 322 snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
308 dev->adev.capture_pcm_substream = substream; 323 dev->adev.capture_pcm_substream = substream;
@@ -317,22 +332,15 @@ err:
317static int snd_em28xx_pcm_close(struct snd_pcm_substream *substream) 332static int snd_em28xx_pcm_close(struct snd_pcm_substream *substream)
318{ 333{
319 struct em28xx *dev = snd_pcm_substream_chip(substream); 334 struct em28xx *dev = snd_pcm_substream_chip(substream);
320 dev->adev.users--;
321 335
322 dprintk("closing device\n"); 336 dprintk("closing device\n");
323 337
324 dev->mute = 1; 338 dev->mute = 1;
325 mutex_lock(&dev->lock); 339 mutex_lock(&dev->lock);
340 dev->adev.users--;
326 em28xx_audio_analog_set(dev); 341 em28xx_audio_analog_set(dev);
327 mutex_unlock(&dev->lock); 342 mutex_unlock(&dev->lock);
328 343
329 if (dev->adev.users == 0 && dev->adev.shutdown == 1) {
330 dprintk("audio users: %d\n", dev->adev.users);
331 dprintk("disabling audio stream!\n");
332 dev->adev.shutdown = 0;
333 dprintk("released lock\n");
334 em28xx_cmd(dev, EM28XX_CAPTURE_STREAM_EN, 0);
335 }
336 return 0; 344 return 0;
337} 345}
338 346
@@ -363,7 +371,7 @@ static int snd_em28xx_hw_capture_free(struct snd_pcm_substream *substream)
363 dprintk("Stop capture, if needed\n"); 371 dprintk("Stop capture, if needed\n");
364 372
365 if (dev->adev.capture_stream == STREAM_ON) 373 if (dev->adev.capture_stream == STREAM_ON)
366 em28xx_cmd(dev, EM28XX_CAPTURE_STREAM_EN, 0); 374 em28xx_cmd(dev, EM28XX_CAPTURE_STREAM_EN, EM28XX_STOP_AUDIO);
367 375
368 return 0; 376 return 0;
369} 377}
@@ -377,33 +385,40 @@ static int snd_em28xx_capture_trigger(struct snd_pcm_substream *substream,
377 int cmd) 385 int cmd)
378{ 386{
379 struct em28xx *dev = snd_pcm_substream_chip(substream); 387 struct em28xx *dev = snd_pcm_substream_chip(substream);
388 int retval;
380 389
381 dprintk("Should %s capture\n", (cmd == SNDRV_PCM_TRIGGER_START)? 390 dprintk("Should %s capture\n", (cmd == SNDRV_PCM_TRIGGER_START) ?
382 "start": "stop"); 391 "start" : "stop");
392
393 spin_lock(&dev->adev.slock);
383 switch (cmd) { 394 switch (cmd) {
384 case SNDRV_PCM_TRIGGER_START: 395 case SNDRV_PCM_TRIGGER_START:
385 em28xx_cmd(dev, EM28XX_CAPTURE_STREAM_EN, 1); 396 em28xx_cmd(dev, EM28XX_CAPTURE_STREAM_EN, EM28XX_START_AUDIO);
386 return 0; 397 retval = 0;
398 break;
387 case SNDRV_PCM_TRIGGER_STOP: 399 case SNDRV_PCM_TRIGGER_STOP:
388 dev->adev.shutdown = 1; 400 em28xx_cmd(dev, EM28XX_CAPTURE_STREAM_EN, EM28XX_STOP_AUDIO);
389 return 0; 401 retval = 0;
402 break;
390 default: 403 default:
391 return -EINVAL; 404 retval = -EINVAL;
392 } 405 }
406
407 spin_unlock(&dev->adev.slock);
408 return retval;
393} 409}
394 410
395static snd_pcm_uframes_t snd_em28xx_capture_pointer(struct snd_pcm_substream 411static snd_pcm_uframes_t snd_em28xx_capture_pointer(struct snd_pcm_substream
396 *substream) 412 *substream)
397{ 413{
398 unsigned long flags; 414 unsigned long flags;
399
400 struct em28xx *dev; 415 struct em28xx *dev;
401 snd_pcm_uframes_t hwptr_done; 416 snd_pcm_uframes_t hwptr_done;
402 417
403 dev = snd_pcm_substream_chip(substream); 418 dev = snd_pcm_substream_chip(substream);
404 spin_lock_irqsave(&dev->adev.slock, flags); 419 spin_lock_irqsave(&dev->adev.slock, flags);
405 hwptr_done = dev->adev.hwptr_done_capture; 420 hwptr_done = dev->adev.hwptr_done_capture;
406 spin_unlock_irqrestore(&dev->adev.slock, flags); 421 spin_unlock_irqrestore(&dev->adev.slock, flags);
407 422
408 return hwptr_done; 423 return hwptr_done;
409} 424}
diff --git a/drivers/media/video/em28xx/em28xx-cards.c b/drivers/media/video/em28xx/em28xx-cards.c
index 3b3ca3f46d52..0f48c0ff5ac3 100644
--- a/drivers/media/video/em28xx/em28xx-cards.c
+++ b/drivers/media/video/em28xx/em28xx-cards.c
@@ -122,6 +122,22 @@ static struct em28xx_reg_seq default_tuner_gpio[] = {
122 { -1, -1, -1, -1}, 122 { -1, -1, -1, -1},
123}; 123};
124 124
125/* Mute/unmute */
126static struct em28xx_reg_seq compro_unmute_tv_gpio[] = {
127 {EM28XX_R08_GPIO, 5, 7, 10},
128 { -1, -1, -1, -1},
129};
130
131static struct em28xx_reg_seq compro_unmute_svid_gpio[] = {
132 {EM28XX_R08_GPIO, 4, 7, 10},
133 { -1, -1, -1, -1},
134};
135
136static struct em28xx_reg_seq compro_mute_gpio[] = {
137 {EM28XX_R08_GPIO, 6, 7, 10},
138 { -1, -1, -1, -1},
139};
140
125/* 141/*
126 * Board definitions 142 * Board definitions
127 */ 143 */
@@ -183,6 +199,25 @@ struct em28xx_board em28xx_boards[] = {
183 .amux = EM28XX_AMUX_LINE_IN, 199 .amux = EM28XX_AMUX_LINE_IN,
184 } }, 200 } },
185 }, 201 },
202 [EM2820_BOARD_GADMEI_TVR200] = {
203 .name = "Gadmei TVR200",
204 .tuner_type = TUNER_LG_PAL_NEW_TAPC,
205 .tda9887_conf = TDA9887_PRESENT,
206 .decoder = EM28XX_SAA711X,
207 .input = { {
208 .type = EM28XX_VMUX_TELEVISION,
209 .vmux = SAA7115_COMPOSITE2,
210 .amux = EM28XX_AMUX_LINE_IN,
211 }, {
212 .type = EM28XX_VMUX_COMPOSITE1,
213 .vmux = SAA7115_COMPOSITE0,
214 .amux = EM28XX_AMUX_LINE_IN,
215 }, {
216 .type = EM28XX_VMUX_SVIDEO,
217 .vmux = SAA7115_SVIDEO3,
218 .amux = EM28XX_AMUX_LINE_IN,
219 } },
220 },
186 [EM2820_BOARD_TERRATEC_CINERGY_250] = { 221 [EM2820_BOARD_TERRATEC_CINERGY_250] = {
187 .name = "Terratec Cinergy 250 USB", 222 .name = "Terratec Cinergy 250 USB",
188 .tuner_type = TUNER_LG_PAL_NEW_TAPC, 223 .tuner_type = TUNER_LG_PAL_NEW_TAPC,
@@ -225,7 +260,7 @@ struct em28xx_board em28xx_boards[] = {
225 .name = "Hauppauge WinTV USB 2", 260 .name = "Hauppauge WinTV USB 2",
226 .tuner_type = TUNER_PHILIPS_FM1236_MK3, 261 .tuner_type = TUNER_PHILIPS_FM1236_MK3,
227 .tda9887_conf = TDA9887_PRESENT | 262 .tda9887_conf = TDA9887_PRESENT |
228 TDA9887_PORT1_ACTIVE| 263 TDA9887_PORT1_ACTIVE |
229 TDA9887_PORT2_ACTIVE, 264 TDA9887_PORT2_ACTIVE,
230 .decoder = EM28XX_TVP5150, 265 .decoder = EM28XX_TVP5150,
231 .has_msp34xx = 1, 266 .has_msp34xx = 1,
@@ -350,26 +385,6 @@ struct em28xx_board em28xx_boards[] = {
350 .amux = EM28XX_AMUX_VIDEO, 385 .amux = EM28XX_AMUX_VIDEO,
351 } }, 386 } },
352 }, 387 },
353 [EM2821_BOARD_PROLINK_PLAYTV_USB2] = {
354 .name = "SIIG AVTuner-PVR/Prolink PlayTV USB 2.0",
355 .valid = EM28XX_BOARD_NOT_VALIDATED,
356 .tuner_type = TUNER_LG_PAL_NEW_TAPC, /* unknown? */
357 .tda9887_conf = TDA9887_PRESENT, /* unknown? */
358 .decoder = EM28XX_SAA711X,
359 .input = { {
360 .type = EM28XX_VMUX_TELEVISION,
361 .vmux = SAA7115_COMPOSITE2,
362 .amux = EM28XX_AMUX_LINE_IN,
363 }, {
364 .type = EM28XX_VMUX_COMPOSITE1,
365 .vmux = SAA7115_COMPOSITE0,
366 .amux = EM28XX_AMUX_LINE_IN,
367 }, {
368 .type = EM28XX_VMUX_SVIDEO,
369 .vmux = SAA7115_SVIDEO3,
370 .amux = EM28XX_AMUX_LINE_IN,
371 } },
372 },
373 [EM2821_BOARD_SUPERCOMP_USB_2] = { 388 [EM2821_BOARD_SUPERCOMP_USB_2] = {
374 .name = "Supercomp USB 2.0 TV", 389 .name = "Supercomp USB 2.0 TV",
375 .valid = EM28XX_BOARD_NOT_VALIDATED, 390 .valid = EM28XX_BOARD_NOT_VALIDATED,
@@ -498,7 +513,7 @@ struct em28xx_board em28xx_boards[] = {
498 }, 513 },
499 [EM2861_BOARD_YAKUMO_MOVIE_MIXER] = { 514 [EM2861_BOARD_YAKUMO_MOVIE_MIXER] = {
500 .name = "Yakumo MovieMixer", 515 .name = "Yakumo MovieMixer",
501 .tuner_type = TUNER_ABSENT, /* Capture only device */ 516 .tuner_type = TUNER_ABSENT, /* Capture only device */
502 .decoder = EM28XX_TVP5150, 517 .decoder = EM28XX_TVP5150,
503 .input = { { 518 .input = { {
504 .type = EM28XX_VMUX_TELEVISION, 519 .type = EM28XX_VMUX_TELEVISION,
@@ -604,6 +619,7 @@ struct em28xx_board em28xx_boards[] = {
604 .mts_firmware = 1, 619 .mts_firmware = 1,
605 .has_dvb = 1, 620 .has_dvb = 1,
606 .dvb_gpio = hauppauge_wintv_hvr_900_digital, 621 .dvb_gpio = hauppauge_wintv_hvr_900_digital,
622 .ir_codes = ir_codes_hauppauge_new,
607 .decoder = EM28XX_TVP5150, 623 .decoder = EM28XX_TVP5150,
608 .input = { { 624 .input = { {
609 .type = EM28XX_VMUX_TELEVISION, 625 .type = EM28XX_VMUX_TELEVISION,
@@ -628,6 +644,7 @@ struct em28xx_board em28xx_boards[] = {
628 .tuner_type = TUNER_XC2028, 644 .tuner_type = TUNER_XC2028,
629 .tuner_gpio = default_tuner_gpio, 645 .tuner_gpio = default_tuner_gpio,
630 .mts_firmware = 1, 646 .mts_firmware = 1,
647 .ir_codes = ir_codes_hauppauge_new,
631 .decoder = EM28XX_TVP5150, 648 .decoder = EM28XX_TVP5150,
632 .input = { { 649 .input = { {
633 .type = EM28XX_VMUX_TELEVISION, 650 .type = EM28XX_VMUX_TELEVISION,
@@ -842,11 +859,11 @@ struct em28xx_board em28xx_boards[] = {
842 } }, 859 } },
843 }, 860 },
844 [EM2800_BOARD_GRABBEEX_USB2800] = { 861 [EM2800_BOARD_GRABBEEX_USB2800] = {
845 .name = "eMPIA Technology, Inc. GrabBeeX+ Video Encoder", 862 .name = "eMPIA Technology, Inc. GrabBeeX+ Video Encoder",
846 .is_em2800 = 1, 863 .is_em2800 = 1,
847 .decoder = EM28XX_SAA711X, 864 .decoder = EM28XX_SAA711X,
848 .tuner_type = TUNER_ABSENT, /* capture only board */ 865 .tuner_type = TUNER_ABSENT, /* capture only board */
849 .input = { { 866 .input = { {
850 .type = EM28XX_VMUX_COMPOSITE1, 867 .type = EM28XX_VMUX_COMPOSITE1,
851 .vmux = SAA7115_COMPOSITE0, 868 .vmux = SAA7115_COMPOSITE0,
852 .amux = EM28XX_AMUX_LINE_IN, 869 .amux = EM28XX_AMUX_LINE_IN,
@@ -897,7 +914,7 @@ struct em28xx_board em28xx_boards[] = {
897 } }, 914 } },
898 }, 915 },
899 [EM2820_BOARD_PINNACLE_DVC_90] = { 916 [EM2820_BOARD_PINNACLE_DVC_90] = {
900 .name = "Pinnacle Dazzle DVC 90/DVC 100", 917 .name = "Pinnacle Dazzle DVC 90/100/101/107 / Kaiser Baas Video to DVD maker",
901 .tuner_type = TUNER_ABSENT, /* capture only board */ 918 .tuner_type = TUNER_ABSENT, /* capture only board */
902 .decoder = EM28XX_SAA711X, 919 .decoder = EM28XX_SAA711X,
903 .input = { { 920 .input = { {
@@ -952,7 +969,7 @@ struct em28xx_board em28xx_boards[] = {
952 } }, 969 } },
953 }, 970 },
954 [EM2820_BOARD_PROLINK_PLAYTV_USB2] = { 971 [EM2820_BOARD_PROLINK_PLAYTV_USB2] = {
955 .name = "Pixelview Prolink PlayTV USB 2.0", 972 .name = "SIIG AVTuner-PVR / Pixelview Prolink PlayTV USB 2.0",
956 .has_snapshot_button = 1, 973 .has_snapshot_button = 1,
957 .tda9887_conf = TDA9887_PRESENT, 974 .tda9887_conf = TDA9887_PRESENT,
958 .tuner_type = TUNER_YMEC_TVF_5533MF, 975 .tuner_type = TUNER_YMEC_TVF_5533MF,
@@ -1198,7 +1215,9 @@ struct em28xx_board em28xx_boards[] = {
1198 .has_dvb = 1, 1215 .has_dvb = 1,
1199 .dvb_gpio = kworld_330u_digital, 1216 .dvb_gpio = kworld_330u_digital,
1200 .xclk = EM28XX_XCLK_FREQUENCY_12MHZ, 1217 .xclk = EM28XX_XCLK_FREQUENCY_12MHZ,
1201 .i2c_speed = EM28XX_I2C_CLK_WAIT_ENABLE | EM28XX_I2C_EEPROM_ON_BOARD | EM28XX_I2C_EEPROM_KEY_VALID, 1218 .i2c_speed = EM28XX_I2C_CLK_WAIT_ENABLE |
1219 EM28XX_I2C_EEPROM_ON_BOARD |
1220 EM28XX_I2C_EEPROM_KEY_VALID,
1202 .input = { { 1221 .input = { {
1203 .type = EM28XX_VMUX_TELEVISION, 1222 .type = EM28XX_VMUX_TELEVISION,
1204 .vmux = TVP5150_COMPOSITE0, 1223 .vmux = TVP5150_COMPOSITE0,
@@ -1223,21 +1242,88 @@ struct em28xx_board em28xx_boards[] = {
1223 .tuner_type = TUNER_LG_PAL_NEW_TAPC, 1242 .tuner_type = TUNER_LG_PAL_NEW_TAPC,
1224 .tda9887_conf = TDA9887_PRESENT, 1243 .tda9887_conf = TDA9887_PRESENT,
1225 .decoder = EM28XX_TVP5150, 1244 .decoder = EM28XX_TVP5150,
1245 .adecoder = EM28XX_TVAUDIO,
1246 .mute_gpio = compro_mute_gpio,
1226 .input = { { 1247 .input = { {
1227 .type = EM28XX_VMUX_TELEVISION, 1248 .type = EM28XX_VMUX_TELEVISION,
1228 .vmux = TVP5150_COMPOSITE0, 1249 .vmux = TVP5150_COMPOSITE0,
1250 .amux = EM28XX_AMUX_VIDEO,
1251 .gpio = compro_unmute_tv_gpio,
1252 }, {
1253 .type = EM28XX_VMUX_SVIDEO,
1254 .vmux = TVP5150_SVIDEO,
1255 .amux = EM28XX_AMUX_LINE_IN,
1256 .gpio = compro_unmute_svid_gpio,
1257 } },
1258 },
1259 [EM2860_BOARD_KAIOMY_TVNPC_U2] = {
1260 .name = "Kaiomy TVnPC U2",
1261 .vchannels = 3,
1262 .tuner_type = TUNER_XC2028,
1263 .tuner_addr = 0x61,
1264 .mts_firmware = 1,
1265 .decoder = EM28XX_TVP5150,
1266 .tuner_gpio = default_tuner_gpio,
1267 .ir_codes = ir_codes_kaiomy,
1268 .input = { {
1269 .type = EM28XX_VMUX_TELEVISION,
1270 .vmux = TVP5150_COMPOSITE0,
1271 .amux = EM28XX_AMUX_VIDEO,
1272
1273 }, {
1274 .type = EM28XX_VMUX_COMPOSITE1,
1275 .vmux = TVP5150_COMPOSITE1,
1229 .amux = EM28XX_AMUX_LINE_IN, 1276 .amux = EM28XX_AMUX_LINE_IN,
1230 }, { 1277 }, {
1231 .type = EM28XX_VMUX_SVIDEO, 1278 .type = EM28XX_VMUX_SVIDEO,
1232 .vmux = TVP5150_SVIDEO, 1279 .vmux = TVP5150_SVIDEO,
1233 .amux = EM28XX_AMUX_LINE_IN, 1280 .amux = EM28XX_AMUX_LINE_IN,
1234 } }, 1281 } },
1282 .radio = {
1283 .type = EM28XX_RADIO,
1284 .amux = EM28XX_AMUX_LINE_IN,
1285 }
1286 },
1287 [EM2860_BOARD_EASYCAP] = {
1288 .name = "Easy Cap Capture DC-60",
1289 .vchannels = 2,
1290 .tuner_type = TUNER_ABSENT,
1291 .decoder = EM28XX_SAA711X,
1292 .input = { {
1293 .type = EM28XX_VMUX_COMPOSITE1,
1294 .vmux = SAA7115_COMPOSITE0,
1295 .amux = EM28XX_AMUX_LINE_IN,
1296 }, {
1297 .type = EM28XX_VMUX_SVIDEO,
1298 .vmux = SAA7115_SVIDEO3,
1299 .amux = EM28XX_AMUX_LINE_IN,
1300 } },
1301 },
1302 [EM2820_BOARD_IODATA_GVMVP_SZ] = {
1303 .name = "IO-DATA GV-MVP/SZ",
1304 .tuner_type = TUNER_PHILIPS_FM1236_MK3,
1305 .tuner_gpio = default_tuner_gpio,
1306 .tda9887_conf = TDA9887_PRESENT,
1307 .decoder = EM28XX_TVP5150,
1308 .input = { {
1309 .type = EM28XX_VMUX_TELEVISION,
1310 .vmux = TVP5150_COMPOSITE0,
1311 .amux = EM28XX_AMUX_VIDEO,
1312 }, { /* Composite has not been tested yet */
1313 .type = EM28XX_VMUX_COMPOSITE1,
1314 .vmux = TVP5150_COMPOSITE1,
1315 .amux = EM28XX_AMUX_VIDEO,
1316 }, { /* S-video has not been tested yet */
1317 .type = EM28XX_VMUX_SVIDEO,
1318 .vmux = TVP5150_SVIDEO,
1319 .amux = EM28XX_AMUX_VIDEO,
1320 } },
1235 }, 1321 },
1236}; 1322};
1237const unsigned int em28xx_bcount = ARRAY_SIZE(em28xx_boards); 1323const unsigned int em28xx_bcount = ARRAY_SIZE(em28xx_boards);
1238 1324
1239/* table of devices that work with this driver */ 1325/* table of devices that work with this driver */
1240struct usb_device_id em28xx_id_table [] = { 1326struct usb_device_id em28xx_id_table[] = {
1241 { USB_DEVICE(0xeb1a, 0x2750), 1327 { USB_DEVICE(0xeb1a, 0x2750),
1242 .driver_info = EM2750_BOARD_UNKNOWN }, 1328 .driver_info = EM2750_BOARD_UNKNOWN },
1243 { USB_DEVICE(0xeb1a, 0x2751), 1329 { USB_DEVICE(0xeb1a, 0x2751),
@@ -1260,6 +1346,8 @@ struct usb_device_id em28xx_id_table [] = {
1260 .driver_info = EM2820_BOARD_UNKNOWN }, 1346 .driver_info = EM2820_BOARD_UNKNOWN },
1261 { USB_DEVICE(0xeb1a, 0xe300), 1347 { USB_DEVICE(0xeb1a, 0xe300),
1262 .driver_info = EM2861_BOARD_KWORLD_PVRTV_300U }, 1348 .driver_info = EM2861_BOARD_KWORLD_PVRTV_300U },
1349 { USB_DEVICE(0xeb1a, 0xe303),
1350 .driver_info = EM2860_BOARD_KAIOMY_TVNPC_U2 },
1263 { USB_DEVICE(0xeb1a, 0xe305), 1351 { USB_DEVICE(0xeb1a, 0xe305),
1264 .driver_info = EM2880_BOARD_KWORLD_DVB_305U }, 1352 .driver_info = EM2880_BOARD_KWORLD_DVB_305U },
1265 { USB_DEVICE(0xeb1a, 0xe310), 1353 { USB_DEVICE(0xeb1a, 0xe310),
@@ -1278,6 +1366,8 @@ struct usb_device_id em28xx_id_table [] = {
1278 .driver_info = EM2800_BOARD_GRABBEEX_USB2800 }, 1366 .driver_info = EM2800_BOARD_GRABBEEX_USB2800 },
1279 { USB_DEVICE(0xeb1a, 0xe357), 1367 { USB_DEVICE(0xeb1a, 0xe357),
1280 .driver_info = EM2870_BOARD_KWORLD_355U }, 1368 .driver_info = EM2870_BOARD_KWORLD_355U },
1369 { USB_DEVICE(0x1b80, 0xe302),
1370 .driver_info = EM2820_BOARD_PINNACLE_DVC_90 }, /* Kaiser Baas Video to DVD maker */
1281 { USB_DEVICE(0x0ccd, 0x0036), 1371 { USB_DEVICE(0x0ccd, 0x0036),
1282 .driver_info = EM2820_BOARD_TERRATEC_CINERGY_250 }, 1372 .driver_info = EM2820_BOARD_TERRATEC_CINERGY_250 },
1283 { USB_DEVICE(0x0ccd, 0x004c), 1373 { USB_DEVICE(0x0ccd, 0x004c),
@@ -1330,6 +1420,8 @@ struct usb_device_id em28xx_id_table [] = {
1330 .driver_info = EM2800_BOARD_LEADTEK_WINFAST_USBII }, 1420 .driver_info = EM2800_BOARD_LEADTEK_WINFAST_USBII },
1331 { USB_DEVICE(0x093b, 0xa005), 1421 { USB_DEVICE(0x093b, 0xa005),
1332 .driver_info = EM2861_BOARD_PLEXTOR_PX_TV100U }, 1422 .driver_info = EM2861_BOARD_PLEXTOR_PX_TV100U },
1423 { USB_DEVICE(0x04bb, 0x0515),
1424 .driver_info = EM2820_BOARD_IODATA_GVMVP_SZ },
1333 { }, 1425 { },
1334}; 1426};
1335MODULE_DEVICE_TABLE(usb, em28xx_id_table); 1427MODULE_DEVICE_TABLE(usb, em28xx_id_table);
@@ -1337,7 +1429,7 @@ MODULE_DEVICE_TABLE(usb, em28xx_id_table);
1337/* 1429/*
1338 * EEPROM hash table for devices with generic USB IDs 1430 * EEPROM hash table for devices with generic USB IDs
1339 */ 1431 */
1340static struct em28xx_hash_table em28xx_eeprom_hash [] = { 1432static struct em28xx_hash_table em28xx_eeprom_hash[] = {
1341 /* P/N: SA 60002070465 Tuner: TVF7533-MF */ 1433 /* P/N: SA 60002070465 Tuner: TVF7533-MF */
1342 {0x6ce05a8f, EM2820_BOARD_PROLINK_PLAYTV_USB2, TUNER_YMEC_TVF_5533MF}, 1434 {0x6ce05a8f, EM2820_BOARD_PROLINK_PLAYTV_USB2, TUNER_YMEC_TVF_5533MF},
1343 {0x72cc5a8b, EM2820_BOARD_PROLINK_PLAYTV_BOX4_USB2, TUNER_YMEC_TVF_5533MF}, 1435 {0x72cc5a8b, EM2820_BOARD_PROLINK_PLAYTV_BOX4_USB2, TUNER_YMEC_TVF_5533MF},
@@ -1349,6 +1441,7 @@ static struct em28xx_hash_table em28xx_i2c_hash[] = {
1349 {0xb06a32c3, EM2800_BOARD_TERRATEC_CINERGY_200, TUNER_LG_PAL_NEW_TAPC}, 1441 {0xb06a32c3, EM2800_BOARD_TERRATEC_CINERGY_200, TUNER_LG_PAL_NEW_TAPC},
1350 {0xf51200e3, EM2800_BOARD_VGEAR_POCKETTV, TUNER_LG_PAL_NEW_TAPC}, 1442 {0xf51200e3, EM2800_BOARD_VGEAR_POCKETTV, TUNER_LG_PAL_NEW_TAPC},
1351 {0x1ba50080, EM2860_BOARD_POINTNIX_INTRAORAL_CAMERA, TUNER_ABSENT}, 1443 {0x1ba50080, EM2860_BOARD_POINTNIX_INTRAORAL_CAMERA, TUNER_ABSENT},
1444 {0xc51200e3, EM2820_BOARD_GADMEI_TVR200, TUNER_LG_PAL_NEW_TAPC},
1352}; 1445};
1353 1446
1354int em28xx_tuner_callback(void *ptr, int component, int command, int arg) 1447int em28xx_tuner_callback(void *ptr, int component, int command, int arg)
@@ -1368,7 +1461,7 @@ int em28xx_tuner_callback(void *ptr, int component, int command, int arg)
1368} 1461}
1369EXPORT_SYMBOL_GPL(em28xx_tuner_callback); 1462EXPORT_SYMBOL_GPL(em28xx_tuner_callback);
1370 1463
1371static void inline em28xx_set_model(struct em28xx *dev) 1464static inline void em28xx_set_model(struct em28xx *dev)
1372{ 1465{
1373 memcpy(&dev->board, &em28xx_boards[dev->model], sizeof(dev->board)); 1466 memcpy(&dev->board, &em28xx_boards[dev->model], sizeof(dev->board));
1374 1467
@@ -1504,6 +1597,34 @@ void em28xx_pre_card_setup(struct em28xx *dev)
1504 /* enables audio for that devices */ 1597 /* enables audio for that devices */
1505 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfd); 1598 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfd);
1506 break; 1599 break;
1600
1601 case EM2860_BOARD_KAIOMY_TVNPC_U2:
1602 em28xx_write_regs(dev, EM28XX_R0F_XCLK, "\x07", 1);
1603 em28xx_write_regs(dev, EM28XX_R06_I2C_CLK, "\x40", 1);
1604 em28xx_write_regs(dev, 0x0d, "\x42", 1);
1605 em28xx_write_regs(dev, 0x08, "\xfd", 1);
1606 msleep(10);
1607 em28xx_write_regs(dev, 0x08, "\xff", 1);
1608 msleep(10);
1609 em28xx_write_regs(dev, 0x08, "\x7f", 1);
1610 msleep(10);
1611 em28xx_write_regs(dev, 0x08, "\x6b", 1);
1612
1613 break;
1614 case EM2860_BOARD_EASYCAP:
1615 em28xx_write_regs(dev, 0x08, "\xf8", 1);
1616 break;
1617
1618 case EM2820_BOARD_IODATA_GVMVP_SZ:
1619 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xff);
1620 msleep(70);
1621 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xf7);
1622 msleep(10);
1623 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfe);
1624 msleep(70);
1625 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfd);
1626 msleep(70);
1627 break;
1507 } 1628 }
1508 1629
1509 em28xx_gpio_set(dev, dev->board.tuner_gpio); 1630 em28xx_gpio_set(dev, dev->board.tuner_gpio);
@@ -1610,7 +1731,7 @@ static int em28xx_hint_board(struct em28xx *dev)
1610 em28xx_errdev("If the board were missdetected, " 1731 em28xx_errdev("If the board were missdetected, "
1611 "please email this log to:\n"); 1732 "please email this log to:\n");
1612 em28xx_errdev("\tV4L Mailing List " 1733 em28xx_errdev("\tV4L Mailing List "
1613 " <video4linux-list@redhat.com>\n"); 1734 " <linux-media@vger.kernel.org>\n");
1614 em28xx_errdev("Board detected as %s\n", 1735 em28xx_errdev("Board detected as %s\n",
1615 em28xx_boards[dev->model].name); 1736 em28xx_boards[dev->model].name);
1616 1737
@@ -1642,7 +1763,7 @@ static int em28xx_hint_board(struct em28xx *dev)
1642 em28xx_errdev("If the board were missdetected, " 1763 em28xx_errdev("If the board were missdetected, "
1643 "please email this log to:\n"); 1764 "please email this log to:\n");
1644 em28xx_errdev("\tV4L Mailing List " 1765 em28xx_errdev("\tV4L Mailing List "
1645 " <video4linux-list@redhat.com>\n"); 1766 " <linux-media@vger.kernel.org>\n");
1646 em28xx_errdev("Board detected as %s\n", 1767 em28xx_errdev("Board detected as %s\n",
1647 em28xx_boards[dev->model].name); 1768 em28xx_boards[dev->model].name);
1648 1769
@@ -1655,7 +1776,7 @@ static int em28xx_hint_board(struct em28xx *dev)
1655 em28xx_errdev("You may try to use card=<n> insmod option to " 1776 em28xx_errdev("You may try to use card=<n> insmod option to "
1656 "workaround that.\n"); 1777 "workaround that.\n");
1657 em28xx_errdev("Please send an email with this log to:\n"); 1778 em28xx_errdev("Please send an email with this log to:\n");
1658 em28xx_errdev("\tV4L Mailing List <video4linux-list@redhat.com>\n"); 1779 em28xx_errdev("\tV4L Mailing List <linux-media@vger.kernel.org>\n");
1659 em28xx_errdev("Board eeprom hash is 0x%08lx\n", dev->hash); 1780 em28xx_errdev("Board eeprom hash is 0x%08lx\n", dev->hash);
1660 em28xx_errdev("Board i2c devicelist hash is 0x%08lx\n", dev->i2c_hash); 1781 em28xx_errdev("Board i2c devicelist hash is 0x%08lx\n", dev->i2c_hash);
1661 1782
@@ -1800,6 +1921,8 @@ void em28xx_card_setup(struct em28xx *dev)
1800 request_module("tvp5150"); 1921 request_module("tvp5150");
1801 if (dev->board.tuner_type != TUNER_ABSENT) 1922 if (dev->board.tuner_type != TUNER_ABSENT)
1802 request_module("tuner"); 1923 request_module("tuner");
1924 if (dev->board.adecoder == EM28XX_TVAUDIO)
1925 request_module("tvaudio");
1803#endif 1926#endif
1804 1927
1805 em28xx_config_tuner(dev); 1928 em28xx_config_tuner(dev);
diff --git a/drivers/media/video/em28xx/em28xx-core.c b/drivers/media/video/em28xx/em28xx-core.c
index 94fb1b639a2e..8f1999ca4803 100644
--- a/drivers/media/video/em28xx/em28xx-core.c
+++ b/drivers/media/video/em28xx/em28xx-core.c
@@ -33,8 +33,8 @@
33/* #define ENABLE_DEBUG_ISOC_FRAMES */ 33/* #define ENABLE_DEBUG_ISOC_FRAMES */
34 34
35static unsigned int core_debug; 35static unsigned int core_debug;
36module_param(core_debug,int,0644); 36module_param(core_debug, int, 0644);
37MODULE_PARM_DESC(core_debug,"enable debug messages [core]"); 37MODULE_PARM_DESC(core_debug, "enable debug messages [core]");
38 38
39#define em28xx_coredbg(fmt, arg...) do {\ 39#define em28xx_coredbg(fmt, arg...) do {\
40 if (core_debug) \ 40 if (core_debug) \
@@ -42,8 +42,8 @@ MODULE_PARM_DESC(core_debug,"enable debug messages [core]");
42 dev->name, __func__ , ##arg); } while (0) 42 dev->name, __func__ , ##arg); } while (0)
43 43
44static unsigned int reg_debug; 44static unsigned int reg_debug;
45module_param(reg_debug,int,0644); 45module_param(reg_debug, int, 0644);
46MODULE_PARM_DESC(reg_debug,"enable debug messages [URB reg]"); 46MODULE_PARM_DESC(reg_debug, "enable debug messages [URB reg]");
47 47
48#define em28xx_regdbg(fmt, arg...) do {\ 48#define em28xx_regdbg(fmt, arg...) do {\
49 if (reg_debug) \ 49 if (reg_debug) \
@@ -77,7 +77,7 @@ int em28xx_read_reg_req_len(struct em28xx *dev, u8 req, u16 reg,
77 return -EINVAL; 77 return -EINVAL;
78 78
79 if (reg_debug) { 79 if (reg_debug) {
80 printk( KERN_DEBUG "(pipe 0x%08x): " 80 printk(KERN_DEBUG "(pipe 0x%08x): "
81 "IN: %02x %02x %02x %02x %02x %02x %02x %02x ", 81 "IN: %02x %02x %02x %02x %02x %02x %02x %02x ",
82 pipe, 82 pipe,
83 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 83 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
@@ -154,7 +154,7 @@ int em28xx_write_regs_req(struct em28xx *dev, u8 req, u16 reg, char *buf,
154 if (reg_debug) { 154 if (reg_debug) {
155 int byte; 155 int byte;
156 156
157 printk( KERN_DEBUG "(pipe 0x%08x): " 157 printk(KERN_DEBUG "(pipe 0x%08x): "
158 "OUT: %02x %02x %02x %02x %02x %02x %02x %02x >>>", 158 "OUT: %02x %02x %02x %02x %02x %02x %02x %02x >>>",
159 pipe, 159 pipe,
160 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 160 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
@@ -378,6 +378,11 @@ static int em28xx_set_audio_source(struct em28xx *dev)
378 } 378 }
379 } 379 }
380 380
381 if (dev->board.mute_gpio && dev->mute)
382 em28xx_gpio_set(dev, dev->board.mute_gpio);
383 else
384 em28xx_gpio_set(dev, INPUT(dev->ctl_input)->gpio);
385
381 ret = em28xx_write_reg_bits(dev, EM28XX_R0E_AUDIOSRC, input, 0xc0); 386 ret = em28xx_write_reg_bits(dev, EM28XX_R0E_AUDIOSRC, input, 0xc0);
382 if (ret < 0) 387 if (ret < 0)
383 return ret; 388 return ret;
@@ -424,7 +429,7 @@ int em28xx_audio_analog_set(struct em28xx *dev)
424 429
425 xclk = dev->board.xclk & 0x7f; 430 xclk = dev->board.xclk & 0x7f;
426 if (!dev->mute) 431 if (!dev->mute)
427 xclk |= 0x80; 432 xclk |= EM28XX_XCLK_AUDIO_UNMUTE;
428 433
429 ret = em28xx_write_reg(dev, EM28XX_R0F_XCLK, xclk); 434 ret = em28xx_write_reg(dev, EM28XX_R0F_XCLK, xclk);
430 if (ret < 0) 435 if (ret < 0)
@@ -462,7 +467,8 @@ int em28xx_audio_analog_set(struct em28xx *dev)
462 if (dev->ctl_aoutput & EM28XX_AOUT_PCM_IN) { 467 if (dev->ctl_aoutput & EM28XX_AOUT_PCM_IN) {
463 int sel = ac97_return_record_select(dev->ctl_aoutput); 468 int sel = ac97_return_record_select(dev->ctl_aoutput);
464 469
465 /* Use the same input for both left and right channels */ 470 /* Use the same input for both left and right
471 channels */
466 sel |= (sel << 8); 472 sel |= (sel << 8);
467 473
468 em28xx_write_ac97(dev, AC97_RECORD_SELECT, sel); 474 em28xx_write_ac97(dev, AC97_RECORD_SELECT, sel);
@@ -698,7 +704,7 @@ static int em28xx_scaler_set(struct em28xx *dev, u16 h, u16 v)
698 em28xx_write_regs(dev, EM28XX_R32_VSCALELOW, (char *)buf, 2); 704 em28xx_write_regs(dev, EM28XX_R32_VSCALELOW, (char *)buf, 2);
699 /* it seems that both H and V scalers must be active 705 /* it seems that both H and V scalers must be active
700 to work correctly */ 706 to work correctly */
701 mode = (h || v)? 0x30: 0x00; 707 mode = (h || v) ? 0x30 : 0x00;
702 } 708 }
703 return em28xx_write_reg_bits(dev, EM28XX_R26_COMPR, mode, 0x30); 709 return em28xx_write_reg_bits(dev, EM28XX_R26_COMPR, mode, 0x30);
704} 710}
@@ -827,6 +833,19 @@ static void em28xx_irq_callback(struct urb *urb)
827 struct em28xx *dev = container_of(dma_q, struct em28xx, vidq); 833 struct em28xx *dev = container_of(dma_q, struct em28xx, vidq);
828 int rc, i; 834 int rc, i;
829 835
836 switch (urb->status) {
837 case 0: /* success */
838 case -ETIMEDOUT: /* NAK */
839 break;
840 case -ECONNRESET: /* kill */
841 case -ENOENT:
842 case -ESHUTDOWN:
843 return;
844 default: /* error */
845 em28xx_isocdbg("urb completition error %d.\n", urb->status);
846 break;
847 }
848
830 /* Copy data from URB */ 849 /* Copy data from URB */
831 spin_lock(&dev->slock); 850 spin_lock(&dev->slock);
832 rc = dev->isoc_ctl.isoc_copy(dev, urb); 851 rc = dev->isoc_ctl.isoc_copy(dev, urb);
@@ -945,7 +964,7 @@ int em28xx_init_isoc(struct em28xx *dev, int max_packets,
945 em28xx_err("unable to allocate %i bytes for transfer" 964 em28xx_err("unable to allocate %i bytes for transfer"
946 " buffer %i%s\n", 965 " buffer %i%s\n",
947 sb_size, i, 966 sb_size, i,
948 in_interrupt()?" while in int":""); 967 in_interrupt() ? " while in int" : "");
949 em28xx_uninit_isoc(dev); 968 em28xx_uninit_isoc(dev);
950 return -ENOMEM; 969 return -ENOMEM;
951 } 970 }
@@ -963,7 +982,7 @@ int em28xx_init_isoc(struct em28xx *dev, int max_packets,
963 em28xx_irq_callback, dma_q, 1); 982 em28xx_irq_callback, dma_q, 1);
964 983
965 urb->number_of_packets = max_packets; 984 urb->number_of_packets = max_packets;
966 urb->transfer_flags = URB_ISO_ASAP; 985 urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
967 986
968 k = 0; 987 k = 0;
969 for (j = 0; j < max_packets; j++) { 988 for (j = 0; j < max_packets; j++) {
diff --git a/drivers/media/video/em28xx/em28xx-dvb.c b/drivers/media/video/em28xx/em28xx-dvb.c
index 9ad8527b3fda..fcd25511209b 100644
--- a/drivers/media/video/em28xx/em28xx-dvb.c
+++ b/drivers/media/video/em28xx/em28xx-dvb.c
@@ -29,9 +29,6 @@
29#include "lgdt330x.h" 29#include "lgdt330x.h"
30#include "zl10353.h" 30#include "zl10353.h"
31#include "s5h1409.h" 31#include "s5h1409.h"
32#ifdef EM28XX_DRX397XD_SUPPORT
33#include "drx397xD.h"
34#endif
35 32
36MODULE_DESCRIPTION("driver for em28xx based DVB cards"); 33MODULE_DESCRIPTION("driver for em28xx based DVB cards");
37MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>"); 34MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
diff --git a/drivers/media/video/em28xx/em28xx-i2c.c b/drivers/media/video/em28xx/em28xx-i2c.c
index d69f0efcc9aa..02c12fe6361b 100644
--- a/drivers/media/video/em28xx/em28xx-i2c.c
+++ b/drivers/media/video/em28xx/em28xx-i2c.c
@@ -402,10 +402,12 @@ static int em28xx_i2c_eeprom(struct em28xx *dev, unsigned char *eedata, int len)
402 dev->name); 402 dev->name);
403 break; 403 break;
404 case 2: 404 case 2:
405 printk(KERN_INFO "%s:\tI2S audio, sample rate=32k\n", dev->name); 405 printk(KERN_INFO "%s:\tI2S audio, sample rate=32k\n",
406 dev->name);
406 break; 407 break;
407 case 3: 408 case 3:
408 printk(KERN_INFO "%s:\tI2S audio, 3 sample rates\n", dev->name); 409 printk(KERN_INFO "%s:\tI2S audio, 3 sample rates\n",
410 dev->name);
409 break; 411 break;
410 } 412 }
411 413
@@ -508,12 +510,17 @@ static int attach_inform(struct i2c_client *client)
508 dprintk1(1, "attach_inform: tvp5150 detected.\n"); 510 dprintk1(1, "attach_inform: tvp5150 detected.\n");
509 break; 511 break;
510 512
513 case 0xb0:
514 dprintk1(1, "attach_inform: tda9874 detected\n");
515 break;
516
511 default: 517 default:
512 if (!dev->tuner_addr) 518 if (!dev->tuner_addr)
513 dev->tuner_addr = client->addr; 519 dev->tuner_addr = client->addr;
514 520
515 dprintk1(1, "attach inform: detected I2C address %x\n", 521 dprintk1(1, "attach inform: detected I2C address %x\n",
516 client->addr << 1); 522 client->addr << 1);
523 dprintk1(1, "driver id %d\n", client->driver->id);
517 524
518 } 525 }
519 526
@@ -552,6 +559,7 @@ static char *i2c_devs[128] = {
552 [0x80 >> 1] = "msp34xx", 559 [0x80 >> 1] = "msp34xx",
553 [0x88 >> 1] = "msp34xx", 560 [0x88 >> 1] = "msp34xx",
554 [0xa0 >> 1] = "eeprom", 561 [0xa0 >> 1] = "eeprom",
562 [0xb0 >> 1] = "tda9874",
555 [0xb8 >> 1] = "tvp5150a", 563 [0xb8 >> 1] = "tvp5150a",
556 [0xba >> 1] = "tvp5150a", 564 [0xba >> 1] = "tvp5150a",
557 [0xc0 >> 1] = "tuner (analog)", 565 [0xc0 >> 1] = "tuner (analog)",
diff --git a/drivers/media/video/em28xx/em28xx-input.c b/drivers/media/video/em28xx/em28xx-input.c
index 0443afe09ff8..a5abfd7a19f5 100644
--- a/drivers/media/video/em28xx/em28xx-input.c
+++ b/drivers/media/video/em28xx/em28xx-input.c
@@ -68,8 +68,7 @@ struct em28xx_IR {
68 68
69 /* poll external decoder */ 69 /* poll external decoder */
70 int polling; 70 int polling;
71 struct work_struct work; 71 struct delayed_work work;
72 struct timer_list timer;
73 unsigned int last_toggle:1; 72 unsigned int last_toggle:1;
74 unsigned int last_readcount; 73 unsigned int last_readcount;
75 unsigned int repeat_interval; 74 unsigned int repeat_interval;
@@ -292,32 +291,23 @@ static void em28xx_ir_handle_key(struct em28xx_IR *ir)
292 return; 291 return;
293} 292}
294 293
295static void ir_timer(unsigned long data)
296{
297 struct em28xx_IR *ir = (struct em28xx_IR *)data;
298
299 schedule_work(&ir->work);
300}
301
302static void em28xx_ir_work(struct work_struct *work) 294static void em28xx_ir_work(struct work_struct *work)
303{ 295{
304 struct em28xx_IR *ir = container_of(work, struct em28xx_IR, work); 296 struct em28xx_IR *ir = container_of(work, struct em28xx_IR, work.work);
305 297
306 em28xx_ir_handle_key(ir); 298 em28xx_ir_handle_key(ir);
307 mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling)); 299 schedule_delayed_work(&ir->work, msecs_to_jiffies(ir->polling));
308} 300}
309 301
310static void em28xx_ir_start(struct em28xx_IR *ir) 302static void em28xx_ir_start(struct em28xx_IR *ir)
311{ 303{
312 setup_timer(&ir->timer, ir_timer, (unsigned long)ir); 304 INIT_DELAYED_WORK(&ir->work, em28xx_ir_work);
313 INIT_WORK(&ir->work, em28xx_ir_work); 305 schedule_delayed_work(&ir->work, 0);
314 schedule_work(&ir->work);
315} 306}
316 307
317static void em28xx_ir_stop(struct em28xx_IR *ir) 308static void em28xx_ir_stop(struct em28xx_IR *ir)
318{ 309{
319 del_timer_sync(&ir->timer); 310 cancel_delayed_work_sync(&ir->work);
320 flush_scheduled_work();
321} 311}
322 312
323int em28xx_ir_init(struct em28xx *dev) 313int em28xx_ir_init(struct em28xx *dev)
diff --git a/drivers/media/video/em28xx/em28xx-video.c b/drivers/media/video/em28xx/em28xx-video.c
index 8e61b2ca9167..575472f1e702 100644
--- a/drivers/media/video/em28xx/em28xx-video.c
+++ b/drivers/media/video/em28xx/em28xx-video.c
@@ -186,7 +186,8 @@ static void em28xx_copy_video(struct em28xx *dev,
186 em28xx_isocdbg("Overflow of %zi bytes past buffer end (1)\n", 186 em28xx_isocdbg("Overflow of %zi bytes past buffer end (1)\n",
187 ((char *)startwrite + lencopy) - 187 ((char *)startwrite + lencopy) -
188 ((char *)outp + buf->vb.size)); 188 ((char *)outp + buf->vb.size));
189 lencopy = remain = (char *)outp + buf->vb.size - (char *)startwrite; 189 remain = (char *)outp + buf->vb.size - (char *)startwrite;
190 lencopy = remain;
190 } 191 }
191 if (lencopy <= 0) 192 if (lencopy <= 0)
192 return; 193 return;
@@ -202,7 +203,8 @@ static void em28xx_copy_video(struct em28xx *dev,
202 else 203 else
203 lencopy = bytesperline; 204 lencopy = bytesperline;
204 205
205 if ((char *)startwrite + lencopy > (char *)outp + buf->vb.size) { 206 if ((char *)startwrite + lencopy > (char *)outp +
207 buf->vb.size) {
206 em28xx_isocdbg("Overflow of %zi bytes past buffer end (2)\n", 208 em28xx_isocdbg("Overflow of %zi bytes past buffer end (2)\n",
207 ((char *)startwrite + lencopy) - 209 ((char *)startwrite + lencopy) -
208 ((char *)outp + buf->vb.size)); 210 ((char *)outp + buf->vb.size));
@@ -347,7 +349,7 @@ static inline int em28xx_isoc_copy(struct em28xx *dev, struct urb *urb)
347 } 349 }
348 if (p[0] == 0x22 && p[1] == 0x5a) { 350 if (p[0] == 0x22 && p[1] == 0x5a) {
349 em28xx_isocdbg("Video frame %d, length=%i, %s\n", p[2], 351 em28xx_isocdbg("Video frame %d, length=%i, %s\n", p[2],
350 len, (p[2] & 1)? "odd" : "even"); 352 len, (p[2] & 1) ? "odd" : "even");
351 353
352 if (!(p[2] & 1)) { 354 if (!(p[2] & 1)) {
353 if (buf != NULL) 355 if (buf != NULL)
@@ -476,7 +478,9 @@ fail:
476static void 478static void
477buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) 479buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
478{ 480{
479 struct em28xx_buffer *buf = container_of(vb, struct em28xx_buffer, vb); 481 struct em28xx_buffer *buf = container_of(vb,
482 struct em28xx_buffer,
483 vb);
480 struct em28xx_fh *fh = vq->priv_data; 484 struct em28xx_fh *fh = vq->priv_data;
481 struct em28xx *dev = fh->dev; 485 struct em28xx *dev = fh->dev;
482 struct em28xx_dmaqueue *vidq = &dev->vidq; 486 struct em28xx_dmaqueue *vidq = &dev->vidq;
@@ -489,7 +493,9 @@ buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
489static void buffer_release(struct videobuf_queue *vq, 493static void buffer_release(struct videobuf_queue *vq,
490 struct videobuf_buffer *vb) 494 struct videobuf_buffer *vb)
491{ 495{
492 struct em28xx_buffer *buf = container_of(vb, struct em28xx_buffer, vb); 496 struct em28xx_buffer *buf = container_of(vb,
497 struct em28xx_buffer,
498 vb);
493 struct em28xx_fh *fh = vq->priv_data; 499 struct em28xx_fh *fh = vq->priv_data;
494 struct em28xx *dev = (struct em28xx *)fh->dev; 500 struct em28xx *dev = (struct em28xx *)fh->dev;
495 501
@@ -534,6 +540,13 @@ static void video_mux(struct em28xx *dev, int index)
534 &route); 540 &route);
535 } 541 }
536 542
543 if (dev->board.adecoder != EM28XX_NOADECODER) {
544 route.input = dev->ctl_ainput;
545 route.output = dev->ctl_aoutput;
546 em28xx_i2c_call_clients(dev, VIDIOC_INT_S_AUDIO_ROUTING,
547 &route);
548 }
549
537 em28xx_audio_analog_set(dev); 550 em28xx_audio_analog_set(dev);
538} 551}
539 552
@@ -557,7 +570,7 @@ static int res_get(struct em28xx_fh *fh)
557 570
558static int res_check(struct em28xx_fh *fh) 571static int res_check(struct em28xx_fh *fh)
559{ 572{
560 return (fh->stream_on); 573 return fh->stream_on;
561} 574}
562 575
563static void res_free(struct em28xx_fh *fh) 576static void res_free(struct em28xx_fh *fh)
@@ -791,7 +804,7 @@ out:
791 return rc; 804 return rc;
792} 805}
793 806
794static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id * norm) 807static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *norm)
795{ 808{
796 struct em28xx_fh *fh = priv; 809 struct em28xx_fh *fh = priv;
797 struct em28xx *dev = fh->dev; 810 struct em28xx *dev = fh->dev;
@@ -1008,8 +1021,13 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
1008 1021
1009 if (dev->board.has_msp34xx) 1022 if (dev->board.has_msp34xx)
1010 em28xx_i2c_call_clients(dev, VIDIOC_G_CTRL, ctrl); 1023 em28xx_i2c_call_clients(dev, VIDIOC_G_CTRL, ctrl);
1011 else 1024 else {
1012 rc = em28xx_get_ctrl(dev, ctrl); 1025 rc = em28xx_get_ctrl(dev, ctrl);
1026 if (rc < 0) {
1027 em28xx_i2c_call_clients(dev, VIDIOC_G_CTRL, ctrl);
1028 rc = 0;
1029 }
1030 }
1013 1031
1014 mutex_unlock(&dev->lock); 1032 mutex_unlock(&dev->lock);
1015 return rc; 1033 return rc;
@@ -1345,7 +1363,7 @@ static int vidioc_querycap(struct file *file, void *priv,
1345 1363
1346 strlcpy(cap->driver, "em28xx", sizeof(cap->driver)); 1364 strlcpy(cap->driver, "em28xx", sizeof(cap->driver));
1347 strlcpy(cap->card, em28xx_boards[dev->model].name, sizeof(cap->card)); 1365 strlcpy(cap->card, em28xx_boards[dev->model].name, sizeof(cap->card));
1348 strlcpy(cap->bus_info, dev_name(&dev->udev->dev), sizeof(cap->bus_info)); 1366 usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info));
1349 1367
1350 cap->version = EM28XX_VERSION_CODE; 1368 cap->version = EM28XX_VERSION_CODE;
1351 1369
@@ -1431,7 +1449,7 @@ static int vidioc_reqbufs(struct file *file, void *priv,
1431 if (rc < 0) 1449 if (rc < 0)
1432 return rc; 1450 return rc;
1433 1451
1434 return (videobuf_reqbufs(&fh->vb_vidq, rb)); 1452 return videobuf_reqbufs(&fh->vb_vidq, rb);
1435} 1453}
1436 1454
1437static int vidioc_querybuf(struct file *file, void *priv, 1455static int vidioc_querybuf(struct file *file, void *priv,
@@ -1445,7 +1463,7 @@ static int vidioc_querybuf(struct file *file, void *priv,
1445 if (rc < 0) 1463 if (rc < 0)
1446 return rc; 1464 return rc;
1447 1465
1448 return (videobuf_querybuf(&fh->vb_vidq, b)); 1466 return videobuf_querybuf(&fh->vb_vidq, b);
1449} 1467}
1450 1468
1451static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *b) 1469static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *b)
@@ -1458,7 +1476,7 @@ static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *b)
1458 if (rc < 0) 1476 if (rc < 0)
1459 return rc; 1477 return rc;
1460 1478
1461 return (videobuf_qbuf(&fh->vb_vidq, b)); 1479 return videobuf_qbuf(&fh->vb_vidq, b);
1462} 1480}
1463 1481
1464static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b) 1482static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b)
@@ -1471,8 +1489,7 @@ static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b)
1471 if (rc < 0) 1489 if (rc < 0)
1472 return rc; 1490 return rc;
1473 1491
1474 return (videobuf_dqbuf(&fh->vb_vidq, b, 1492 return videobuf_dqbuf(&fh->vb_vidq, b, file->f_flags & O_NONBLOCK);
1475 file->f_flags & O_NONBLOCK));
1476} 1493}
1477 1494
1478#ifdef CONFIG_VIDEO_V4L1_COMPAT 1495#ifdef CONFIG_VIDEO_V4L1_COMPAT
@@ -1496,7 +1513,7 @@ static int radio_querycap(struct file *file, void *priv,
1496 1513
1497 strlcpy(cap->driver, "em28xx", sizeof(cap->driver)); 1514 strlcpy(cap->driver, "em28xx", sizeof(cap->driver));
1498 strlcpy(cap->card, em28xx_boards[dev->model].name, sizeof(cap->card)); 1515 strlcpy(cap->card, em28xx_boards[dev->model].name, sizeof(cap->card));
1499 strlcpy(cap->bus_info, dev_name(&dev->udev->dev), sizeof(cap->bus_info)); 1516 usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info));
1500 1517
1501 cap->version = EM28XX_VERSION_CODE; 1518 cap->version = EM28XX_VERSION_CODE;
1502 cap->capabilities = V4L2_CAP_TUNER; 1519 cap->capabilities = V4L2_CAP_TUNER;
@@ -1781,7 +1798,7 @@ em28xx_v4l2_read(struct file *filp, char __user *buf, size_t count,
1781 * em28xx_v4l2_poll() 1798 * em28xx_v4l2_poll()
1782 * will allocate buffers when called for the first time 1799 * will allocate buffers when called for the first time
1783 */ 1800 */
1784static unsigned int em28xx_v4l2_poll(struct file *filp, poll_table * wait) 1801static unsigned int em28xx_v4l2_poll(struct file *filp, poll_table *wait)
1785{ 1802{
1786 struct em28xx_fh *fh = filp->private_data; 1803 struct em28xx_fh *fh = filp->private_data;
1787 struct em28xx *dev = fh->dev; 1804 struct em28xx *dev = fh->dev;
@@ -1934,8 +1951,8 @@ static struct video_device em28xx_radio_template = {
1934 1951
1935 1952
1936static struct video_device *em28xx_vdev_init(struct em28xx *dev, 1953static struct video_device *em28xx_vdev_init(struct em28xx *dev,
1937 const struct video_device *template, 1954 const struct video_device *template,
1938 const char *type_name) 1955 const char *type_name)
1939{ 1956{
1940 struct video_device *vfd; 1957 struct video_device *vfd;
1941 1958
@@ -1984,8 +2001,9 @@ int em28xx_register_analog_devices(struct em28xx *dev)
1984 /* enable vbi capturing */ 2001 /* enable vbi capturing */
1985 2002
1986/* em28xx_write_reg(dev, EM28XX_R0E_AUDIOSRC, 0xc0); audio register */ 2003/* em28xx_write_reg(dev, EM28XX_R0E_AUDIOSRC, 0xc0); audio register */
1987 val = (u8)em28xx_read_reg(dev, EM28XX_R0F_XCLK); 2004 val = (u8)em28xx_read_reg(dev, EM28XX_R0F_XCLK);
1988 em28xx_write_reg(dev, EM28XX_R0F_XCLK, (EM28XX_XCLK_AUDIO_UNMUTE | val)); 2005 em28xx_write_reg(dev, EM28XX_R0F_XCLK,
2006 (EM28XX_XCLK_AUDIO_UNMUTE | val));
1989 em28xx_write_reg(dev, EM28XX_R11_VINCTRL, 0x51); 2007 em28xx_write_reg(dev, EM28XX_R11_VINCTRL, 0x51);
1990 2008
1991 em28xx_set_outfmt(dev); 2009 em28xx_set_outfmt(dev);
@@ -2020,7 +2038,8 @@ int em28xx_register_analog_devices(struct em28xx *dev)
2020 } 2038 }
2021 2039
2022 if (em28xx_boards[dev->model].radio.type == EM28XX_RADIO) { 2040 if (em28xx_boards[dev->model].radio.type == EM28XX_RADIO) {
2023 dev->radio_dev = em28xx_vdev_init(dev, &em28xx_radio_template, "radio"); 2041 dev->radio_dev = em28xx_vdev_init(dev, &em28xx_radio_template,
2042 "radio");
2024 if (!dev->radio_dev) { 2043 if (!dev->radio_dev) {
2025 em28xx_errdev("cannot allocate video_device.\n"); 2044 em28xx_errdev("cannot allocate video_device.\n");
2026 return -ENODEV; 2045 return -ENODEV;
diff --git a/drivers/media/video/em28xx/em28xx.h b/drivers/media/video/em28xx/em28xx.h
index dd2cd36fb1bb..a33a58da016e 100644
--- a/drivers/media/video/em28xx/em28xx.h
+++ b/drivers/media/video/em28xx/em28xx.h
@@ -70,7 +70,6 @@
70#define EM2820_BOARD_VIDEOLOGY_20K14XUSB 30 70#define EM2820_BOARD_VIDEOLOGY_20K14XUSB 30
71#define EM2821_BOARD_USBGEAR_VD204 31 71#define EM2821_BOARD_USBGEAR_VD204 31
72#define EM2821_BOARD_SUPERCOMP_USB_2 32 72#define EM2821_BOARD_SUPERCOMP_USB_2 32
73#define EM2821_BOARD_PROLINK_PLAYTV_USB2 33
74#define EM2860_BOARD_TERRATEC_HYBRID_XS 34 73#define EM2860_BOARD_TERRATEC_HYBRID_XS 34
75#define EM2860_BOARD_TYPHOON_DVD_MAKER 35 74#define EM2860_BOARD_TYPHOON_DVD_MAKER 35
76#define EM2860_BOARD_NETGMBH_CAM 36 75#define EM2860_BOARD_NETGMBH_CAM 36
@@ -98,6 +97,10 @@
98#define EM2820_BOARD_COMPRO_VIDEOMATE_FORYOU 58 97#define EM2820_BOARD_COMPRO_VIDEOMATE_FORYOU 58
99#define EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850 60 98#define EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850 60
100#define EM2820_BOARD_PROLINK_PLAYTV_BOX4_USB2 61 99#define EM2820_BOARD_PROLINK_PLAYTV_BOX4_USB2 61
100#define EM2820_BOARD_GADMEI_TVR200 62
101#define EM2860_BOARD_KAIOMY_TVNPC_U2 63
102#define EM2860_BOARD_EASYCAP 64
103#define EM2820_BOARD_IODATA_GVMVP_SZ 65
101 104
102/* Limits minimum and default number of buffers */ 105/* Limits minimum and default number of buffers */
103#define EM28XX_MIN_BUF 4 106#define EM28XX_MIN_BUF 4
@@ -110,6 +113,10 @@
110#define EM28XX_BOARD_NOT_VALIDATED 1 113#define EM28XX_BOARD_NOT_VALIDATED 1
111#define EM28XX_BOARD_VALIDATED 0 114#define EM28XX_BOARD_VALIDATED 0
112 115
116/* Params for em28xx_cmd() audio */
117#define EM28XX_START_AUDIO 1
118#define EM28XX_STOP_AUDIO 0
119
113/* maximum number of em28xx boards */ 120/* maximum number of em28xx boards */
114#define EM28XX_MAXBOARDS 4 /*FIXME: should be bigger */ 121#define EM28XX_MAXBOARDS 4 /*FIXME: should be bigger */
115 122
@@ -154,7 +161,8 @@
154*/ 161*/
155 162
156/* time to wait when stopping the isoc transfer */ 163/* time to wait when stopping the isoc transfer */
157#define EM28XX_URB_TIMEOUT msecs_to_jiffies(EM28XX_NUM_BUFS * EM28XX_NUM_PACKETS) 164#define EM28XX_URB_TIMEOUT \
165 msecs_to_jiffies(EM28XX_NUM_BUFS * EM28XX_NUM_PACKETS)
158 166
159/* time in msecs to wait for i2c writes to finish */ 167/* time in msecs to wait for i2c writes to finish */
160#define EM2800_I2C_WRITE_TIMEOUT 20 168#define EM2800_I2C_WRITE_TIMEOUT 20
@@ -348,6 +356,11 @@ enum em28xx_decoder {
348 EM28XX_SAA711X, 356 EM28XX_SAA711X,
349}; 357};
350 358
359enum em28xx_adecoder {
360 EM28XX_NOADECODER = 0,
361 EM28XX_TVAUDIO,
362};
363
351struct em28xx_board { 364struct em28xx_board {
352 char *name; 365 char *name;
353 int vchannels; 366 int vchannels;
@@ -361,6 +374,7 @@ struct em28xx_board {
361 struct em28xx_reg_seq *dvb_gpio; 374 struct em28xx_reg_seq *dvb_gpio;
362 struct em28xx_reg_seq *suspend_gpio; 375 struct em28xx_reg_seq *suspend_gpio;
363 struct em28xx_reg_seq *tuner_gpio; 376 struct em28xx_reg_seq *tuner_gpio;
377 struct em28xx_reg_seq *mute_gpio;
364 378
365 unsigned int is_em2800:1; 379 unsigned int is_em2800:1;
366 unsigned int has_msp34xx:1; 380 unsigned int has_msp34xx:1;
@@ -373,6 +387,7 @@ struct em28xx_board {
373 unsigned char xclk, i2c_speed; 387 unsigned char xclk, i2c_speed;
374 388
375 enum em28xx_decoder decoder; 389 enum em28xx_decoder decoder;
390 enum em28xx_adecoder adecoder;
376 391
377 struct em28xx_input input[MAX_EM28XX_INPUT]; 392 struct em28xx_input input[MAX_EM28XX_INPUT];
378 struct em28xx_input radio; 393 struct em28xx_input radio;
@@ -420,7 +435,7 @@ struct em28xx_audio {
420 unsigned int hwptr_done_capture; 435 unsigned int hwptr_done_capture;
421 struct snd_card *sndcard; 436 struct snd_card *sndcard;
422 437
423 int users, shutdown; 438 int users;
424 enum em28xx_stream_state capture_stream; 439 enum em28xx_stream_state capture_stream;
425 spinlock_t slock; 440 spinlock_t slock;
426}; 441};
@@ -523,7 +538,8 @@ struct em28xx {
523 int num_alt; /* Number of alternative settings */ 538 int num_alt; /* Number of alternative settings */
524 unsigned int *alt_max_pkt_size; /* array of wMaxPacketSize */ 539 unsigned int *alt_max_pkt_size; /* array of wMaxPacketSize */
525 struct urb *urb[EM28XX_NUM_BUFS]; /* urb for isoc transfers */ 540 struct urb *urb[EM28XX_NUM_BUFS]; /* urb for isoc transfers */
526 char *transfer_buffer[EM28XX_NUM_BUFS]; /* transfer buffers for isoc transfer */ 541 char *transfer_buffer[EM28XX_NUM_BUFS]; /* transfer buffers for isoc
542 transfer */
527 char urb_buf[URB_MAX_CTRL_SIZE]; /* urb control msg buffer */ 543 char urb_buf[URB_MAX_CTRL_SIZE]; /* urb control msg buffer */
528 544
529 /* helper funcs that call usb_control_msg */ 545 /* helper funcs that call usb_control_msg */
diff --git a/drivers/media/video/gspca/Kconfig b/drivers/media/video/gspca/Kconfig
index ee6a691dff22..578dc4ffc965 100644
--- a/drivers/media/video/gspca/Kconfig
+++ b/drivers/media/video/gspca/Kconfig
@@ -56,6 +56,15 @@ config USB_GSPCA_MARS
56 To compile this driver as a module, choose M here: the 56 To compile this driver as a module, choose M here: the
57 module will be called gspca_mars. 57 module will be called gspca_mars.
58 58
59config USB_GSPCA_MR97310A
60 tristate "Mars-Semi MR97310A USB Camera Driver"
61 depends on VIDEO_V4L2 && USB_GSPCA
62 help
63 Say Y here if you want support for cameras based on the MR97310A chip.
64
65 To compile this driver as a module, choose M here: the
66 module will be called gspca_mr97310a.
67
59config USB_GSPCA_OV519 68config USB_GSPCA_OV519
60 tristate "OV519 USB Camera Driver" 69 tristate "OV519 USB Camera Driver"
61 depends on VIDEO_V4L2 && USB_GSPCA 70 depends on VIDEO_V4L2 && USB_GSPCA
@@ -167,6 +176,24 @@ config USB_GSPCA_SPCA561
167 To compile this driver as a module, choose M here: the 176 To compile this driver as a module, choose M here: the
168 module will be called gspca_spca561. 177 module will be called gspca_spca561.
169 178
179config USB_GSPCA_SQ905
180 tristate "SQ Technologies SQ905 based USB Camera Driver"
181 depends on VIDEO_V4L2 && USB_GSPCA
182 help
183 Say Y here if you want support for cameras based on the SQ905 chip.
184
185 To compile this driver as a module, choose M here: the
186 module will be called gspca_sq905.
187
188config USB_GSPCA_SQ905C
189 tristate "SQ Technologies SQ905C based USB Camera Driver"
190 depends on VIDEO_V4L2 && USB_GSPCA
191 help
192 Say Y here if you want support for cameras based on the SQ905C chip.
193
194 To compile this driver as a module, choose M here: the
195 module will be called gspca_sq905c.
196
170config USB_GSPCA_STK014 197config USB_GSPCA_STK014
171 tristate "Syntek DV4000 (STK014) USB Camera Driver" 198 tristate "Syntek DV4000 (STK014) USB Camera Driver"
172 depends on VIDEO_V4L2 && USB_GSPCA 199 depends on VIDEO_V4L2 && USB_GSPCA
diff --git a/drivers/media/video/gspca/Makefile b/drivers/media/video/gspca/Makefile
index bd8d9ee40504..8a6643e8eb96 100644
--- a/drivers/media/video/gspca/Makefile
+++ b/drivers/media/video/gspca/Makefile
@@ -1,50 +1,56 @@
1obj-$(CONFIG_USB_GSPCA) += gspca_main.o 1obj-$(CONFIG_USB_GSPCA) += gspca_main.o
2obj-$(CONFIG_USB_GSPCA_CONEX) += gspca_conex.o 2obj-$(CONFIG_USB_GSPCA_CONEX) += gspca_conex.o
3obj-$(CONFIG_USB_GSPCA_ETOMS) += gspca_etoms.o 3obj-$(CONFIG_USB_GSPCA_ETOMS) += gspca_etoms.o
4obj-$(CONFIG_USB_GSPCA_FINEPIX) += gspca_finepix.o 4obj-$(CONFIG_USB_GSPCA_FINEPIX) += gspca_finepix.o
5obj-$(CONFIG_USB_GSPCA_MARS) += gspca_mars.o 5obj-$(CONFIG_USB_GSPCA_MARS) += gspca_mars.o
6obj-$(CONFIG_USB_GSPCA_OV519) += gspca_ov519.o 6obj-$(CONFIG_USB_GSPCA_MR97310A) += gspca_mr97310a.o
7obj-$(CONFIG_USB_GSPCA_OV534) += gspca_ov534.o 7obj-$(CONFIG_USB_GSPCA_OV519) += gspca_ov519.o
8obj-$(CONFIG_USB_GSPCA_PAC207) += gspca_pac207.o 8obj-$(CONFIG_USB_GSPCA_OV534) += gspca_ov534.o
9obj-$(CONFIG_USB_GSPCA_PAC7311) += gspca_pac7311.o 9obj-$(CONFIG_USB_GSPCA_PAC207) += gspca_pac207.o
10obj-$(CONFIG_USB_GSPCA_SONIXB) += gspca_sonixb.o 10obj-$(CONFIG_USB_GSPCA_PAC7311) += gspca_pac7311.o
11obj-$(CONFIG_USB_GSPCA_SONIXJ) += gspca_sonixj.o 11obj-$(CONFIG_USB_GSPCA_SONIXB) += gspca_sonixb.o
12obj-$(CONFIG_USB_GSPCA_SPCA500) += gspca_spca500.o 12obj-$(CONFIG_USB_GSPCA_SONIXJ) += gspca_sonixj.o
13obj-$(CONFIG_USB_GSPCA_SPCA501) += gspca_spca501.o 13obj-$(CONFIG_USB_GSPCA_SPCA500) += gspca_spca500.o
14obj-$(CONFIG_USB_GSPCA_SPCA505) += gspca_spca505.o 14obj-$(CONFIG_USB_GSPCA_SPCA501) += gspca_spca501.o
15obj-$(CONFIG_USB_GSPCA_SPCA506) += gspca_spca506.o 15obj-$(CONFIG_USB_GSPCA_SPCA505) += gspca_spca505.o
16obj-$(CONFIG_USB_GSPCA_SPCA508) += gspca_spca508.o 16obj-$(CONFIG_USB_GSPCA_SPCA506) += gspca_spca506.o
17obj-$(CONFIG_USB_GSPCA_SPCA561) += gspca_spca561.o 17obj-$(CONFIG_USB_GSPCA_SPCA508) += gspca_spca508.o
18obj-$(CONFIG_USB_GSPCA_SUNPLUS) += gspca_sunplus.o 18obj-$(CONFIG_USB_GSPCA_SPCA561) += gspca_spca561.o
19obj-$(CONFIG_USB_GSPCA_STK014) += gspca_stk014.o 19obj-$(CONFIG_USB_GSPCA_SQ905) += gspca_sq905.o
20obj-$(CONFIG_USB_GSPCA_T613) += gspca_t613.o 20obj-$(CONFIG_USB_GSPCA_SQ905C) += gspca_sq905c.o
21obj-$(CONFIG_USB_GSPCA_TV8532) += gspca_tv8532.o 21obj-$(CONFIG_USB_GSPCA_SUNPLUS) += gspca_sunplus.o
22obj-$(CONFIG_USB_GSPCA_VC032X) += gspca_vc032x.o 22obj-$(CONFIG_USB_GSPCA_STK014) += gspca_stk014.o
23obj-$(CONFIG_USB_GSPCA_ZC3XX) += gspca_zc3xx.o 23obj-$(CONFIG_USB_GSPCA_T613) += gspca_t613.o
24obj-$(CONFIG_USB_GSPCA_TV8532) += gspca_tv8532.o
25obj-$(CONFIG_USB_GSPCA_VC032X) += gspca_vc032x.o
26obj-$(CONFIG_USB_GSPCA_ZC3XX) += gspca_zc3xx.o
24 27
25gspca_main-objs := gspca.o 28gspca_main-objs := gspca.o
26gspca_conex-objs := conex.o 29gspca_conex-objs := conex.o
27gspca_etoms-objs := etoms.o 30gspca_etoms-objs := etoms.o
28gspca_finepix-objs := finepix.o 31gspca_finepix-objs := finepix.o
29gspca_mars-objs := mars.o 32gspca_mars-objs := mars.o
30gspca_ov519-objs := ov519.o 33gspca_mr97310a-objs := mr97310a.o
31gspca_ov534-objs := ov534.o 34gspca_ov519-objs := ov519.o
32gspca_pac207-objs := pac207.o 35gspca_ov534-objs := ov534.o
33gspca_pac7311-objs := pac7311.o 36gspca_pac207-objs := pac207.o
34gspca_sonixb-objs := sonixb.o 37gspca_pac7311-objs := pac7311.o
35gspca_sonixj-objs := sonixj.o 38gspca_sonixb-objs := sonixb.o
36gspca_spca500-objs := spca500.o 39gspca_sonixj-objs := sonixj.o
37gspca_spca501-objs := spca501.o 40gspca_spca500-objs := spca500.o
38gspca_spca505-objs := spca505.o 41gspca_spca501-objs := spca501.o
39gspca_spca506-objs := spca506.o 42gspca_spca505-objs := spca505.o
40gspca_spca508-objs := spca508.o 43gspca_spca506-objs := spca506.o
41gspca_spca561-objs := spca561.o 44gspca_spca508-objs := spca508.o
42gspca_stk014-objs := stk014.o 45gspca_spca561-objs := spca561.o
43gspca_sunplus-objs := sunplus.o 46gspca_sq905-objs := sq905.o
44gspca_t613-objs := t613.o 47gspca_sq905c-objs := sq905c.o
45gspca_tv8532-objs := tv8532.o 48gspca_stk014-objs := stk014.o
46gspca_vc032x-objs := vc032x.o 49gspca_sunplus-objs := sunplus.o
47gspca_zc3xx-objs := zc3xx.o 50gspca_t613-objs := t613.o
51gspca_tv8532-objs := tv8532.o
52gspca_vc032x-objs := vc032x.o
53gspca_zc3xx-objs := zc3xx.o
48 54
49obj-$(CONFIG_USB_M5602) += m5602/ 55obj-$(CONFIG_USB_M5602) += m5602/
50obj-$(CONFIG_USB_STV06XX) += stv06xx/ 56obj-$(CONFIG_USB_STV06XX) += stv06xx/
diff --git a/drivers/media/video/gspca/conex.c b/drivers/media/video/gspca/conex.c
index 1753f5bb3544..219cfa6fb877 100644
--- a/drivers/media/video/gspca/conex.c
+++ b/drivers/media/video/gspca/conex.c
@@ -36,8 +36,12 @@ struct sd {
36 unsigned char brightness; 36 unsigned char brightness;
37 unsigned char contrast; 37 unsigned char contrast;
38 unsigned char colors; 38 unsigned char colors;
39 u8 quality;
40#define QUALITY_MIN 30
41#define QUALITY_MAX 60
42#define QUALITY_DEF 40
39 43
40 unsigned char qindex; 44 u8 *jpeg_hdr;
41}; 45};
42 46
43/* V4L2 controls supported by the driver */ 47/* V4L2 controls supported by the driver */
@@ -815,14 +819,13 @@ static int sd_config(struct gspca_dev *gspca_dev,
815 struct cam *cam; 819 struct cam *cam;
816 820
817 cam = &gspca_dev->cam; 821 cam = &gspca_dev->cam;
818 cam->epaddr = 0x01;
819 cam->cam_mode = vga_mode; 822 cam->cam_mode = vga_mode;
820 cam->nmodes = sizeof vga_mode / sizeof vga_mode[0]; 823 cam->nmodes = sizeof vga_mode / sizeof vga_mode[0];
821 824
822 sd->qindex = 0; /* set the quantization */
823 sd->brightness = BRIGHTNESS_DEF; 825 sd->brightness = BRIGHTNESS_DEF;
824 sd->contrast = CONTRAST_DEF; 826 sd->contrast = CONTRAST_DEF;
825 sd->colors = COLOR_DEF; 827 sd->colors = COLOR_DEF;
828 sd->quality = QUALITY_DEF;
826 return 0; 829 return 0;
827} 830}
828 831
@@ -839,6 +842,14 @@ static int sd_init(struct gspca_dev *gspca_dev)
839 842
840static int sd_start(struct gspca_dev *gspca_dev) 843static int sd_start(struct gspca_dev *gspca_dev)
841{ 844{
845 struct sd *sd = (struct sd *) gspca_dev;
846
847 /* create the JPEG header */
848 sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL);
849 jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
850 0x22); /* JPEG 411 */
851 jpeg_set_qual(sd->jpeg_hdr, sd->quality);
852
842 cx11646_initsize(gspca_dev); 853 cx11646_initsize(gspca_dev);
843 cx11646_fw(gspca_dev); 854 cx11646_fw(gspca_dev);
844 cx_sensor(gspca_dev); 855 cx_sensor(gspca_dev);
@@ -849,8 +860,11 @@ static int sd_start(struct gspca_dev *gspca_dev)
849/* called on streamoff with alt 0 and on disconnect */ 860/* called on streamoff with alt 0 and on disconnect */
850static void sd_stop0(struct gspca_dev *gspca_dev) 861static void sd_stop0(struct gspca_dev *gspca_dev)
851{ 862{
863 struct sd *sd = (struct sd *) gspca_dev;
852 int retry = 50; 864 int retry = 50;
853 865
866 kfree(sd->jpeg_hdr);
867
854 if (!gspca_dev->present) 868 if (!gspca_dev->present)
855 return; 869 return;
856 reg_w_val(gspca_dev, 0x0000, 0x00); 870 reg_w_val(gspca_dev, 0x0000, 0x00);
@@ -876,6 +890,8 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
876 __u8 *data, /* isoc packet */ 890 __u8 *data, /* isoc packet */
877 int len) /* iso packet length */ 891 int len) /* iso packet length */
878{ 892{
893 struct sd *sd = (struct sd *) gspca_dev;
894
879 if (data[0] == 0xff && data[1] == 0xd8) { 895 if (data[0] == 0xff && data[1] == 0xd8) {
880 896
881 /* start of frame */ 897 /* start of frame */
@@ -883,9 +899,8 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
883 data, 0); 899 data, 0);
884 900
885 /* put the JPEG header in the new frame */ 901 /* put the JPEG header in the new frame */
886 jpeg_put_header(gspca_dev, frame, 902 gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
887 ((struct sd *) gspca_dev)->qindex, 903 sd->jpeg_hdr, JPEG_HDR_SZ);
888 0x22);
889 data += 2; 904 data += 2;
890 len -= 2; 905 len -= 2;
891 } 906 }
@@ -988,6 +1003,34 @@ static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
988 return 0; 1003 return 0;
989} 1004}
990 1005
1006static int sd_set_jcomp(struct gspca_dev *gspca_dev,
1007 struct v4l2_jpegcompression *jcomp)
1008{
1009 struct sd *sd = (struct sd *) gspca_dev;
1010
1011 if (jcomp->quality < QUALITY_MIN)
1012 sd->quality = QUALITY_MIN;
1013 else if (jcomp->quality > QUALITY_MAX)
1014 sd->quality = QUALITY_MAX;
1015 else
1016 sd->quality = jcomp->quality;
1017 if (gspca_dev->streaming)
1018 jpeg_set_qual(sd->jpeg_hdr, sd->quality);
1019 return 0;
1020}
1021
1022static int sd_get_jcomp(struct gspca_dev *gspca_dev,
1023 struct v4l2_jpegcompression *jcomp)
1024{
1025 struct sd *sd = (struct sd *) gspca_dev;
1026
1027 memset(jcomp, 0, sizeof *jcomp);
1028 jcomp->quality = sd->quality;
1029 jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT
1030 | V4L2_JPEG_MARKER_DQT;
1031 return 0;
1032}
1033
991/* sub-driver description */ 1034/* sub-driver description */
992static struct sd_desc sd_desc = { 1035static struct sd_desc sd_desc = {
993 .name = MODULE_NAME, 1036 .name = MODULE_NAME,
@@ -998,6 +1041,8 @@ static struct sd_desc sd_desc = {
998 .start = sd_start, 1041 .start = sd_start,
999 .stop0 = sd_stop0, 1042 .stop0 = sd_stop0,
1000 .pkt_scan = sd_pkt_scan, 1043 .pkt_scan = sd_pkt_scan,
1044 .get_jcomp = sd_get_jcomp,
1045 .set_jcomp = sd_set_jcomp,
1001}; 1046};
1002 1047
1003/* -- module initialisation -- */ 1048/* -- module initialisation -- */
@@ -1029,8 +1074,10 @@ static struct usb_driver sd_driver = {
1029/* -- module insert / remove -- */ 1074/* -- module insert / remove -- */
1030static int __init sd_mod_init(void) 1075static int __init sd_mod_init(void)
1031{ 1076{
1032 if (usb_register(&sd_driver) < 0) 1077 int ret;
1033 return -1; 1078 ret = usb_register(&sd_driver);
1079 if (ret < 0)
1080 return ret;
1034 PDEBUG(D_PROBE, "registered"); 1081 PDEBUG(D_PROBE, "registered");
1035 return 0; 1082 return 0;
1036} 1083}
diff --git a/drivers/media/video/gspca/etoms.c b/drivers/media/video/gspca/etoms.c
index f3cd8ff5cc92..2c20d06a03e8 100644
--- a/drivers/media/video/gspca/etoms.c
+++ b/drivers/media/video/gspca/etoms.c
@@ -472,19 +472,6 @@ static void setbrightness(struct gspca_dev *gspca_dev)
472 reg_w_val(gspca_dev, ET_O_RED + i, brightness); 472 reg_w_val(gspca_dev, ET_O_RED + i, brightness);
473} 473}
474 474
475static void getbrightness(struct gspca_dev *gspca_dev)
476{
477 struct sd *sd = (struct sd *) gspca_dev;
478 int i;
479 int brightness = 0;
480
481 for (i = 0; i < 4; i++) {
482 reg_r(gspca_dev, ET_O_RED + i, 1);
483 brightness += gspca_dev->usb_buf[0];
484 }
485 sd->brightness = brightness >> 3;
486}
487
488static void setcontrast(struct gspca_dev *gspca_dev) 475static void setcontrast(struct gspca_dev *gspca_dev)
489{ 476{
490 struct sd *sd = (struct sd *) gspca_dev; 477 struct sd *sd = (struct sd *) gspca_dev;
@@ -495,19 +482,6 @@ static void setcontrast(struct gspca_dev *gspca_dev)
495 reg_w(gspca_dev, ET_G_RED, RGBG, 6); 482 reg_w(gspca_dev, ET_G_RED, RGBG, 6);
496} 483}
497 484
498static void getcontrast(struct gspca_dev *gspca_dev)
499{
500 struct sd *sd = (struct sd *) gspca_dev;
501 int i;
502 int contrast = 0;
503
504 for (i = 0; i < 4; i++) {
505 reg_r(gspca_dev, ET_G_RED + i, 1);
506 contrast += gspca_dev->usb_buf[0];
507 }
508 sd->contrast = contrast >> 2;
509}
510
511static void setcolors(struct gspca_dev *gspca_dev) 485static void setcolors(struct gspca_dev *gspca_dev)
512{ 486{
513 struct sd *sd = (struct sd *) gspca_dev; 487 struct sd *sd = (struct sd *) gspca_dev;
@@ -658,7 +632,6 @@ static int sd_config(struct gspca_dev *gspca_dev,
658 struct cam *cam; 632 struct cam *cam;
659 633
660 cam = &gspca_dev->cam; 634 cam = &gspca_dev->cam;
661 cam->epaddr = 1;
662 sd->sensor = id->driver_info; 635 sd->sensor = id->driver_info;
663 if (sd->sensor == SENSOR_PAS106) { 636 if (sd->sensor == SENSOR_PAS106) {
664 cam->cam_mode = sif_mode; 637 cam->cam_mode = sif_mode;
@@ -821,7 +794,6 @@ static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
821{ 794{
822 struct sd *sd = (struct sd *) gspca_dev; 795 struct sd *sd = (struct sd *) gspca_dev;
823 796
824 getbrightness(gspca_dev);
825 *val = sd->brightness; 797 *val = sd->brightness;
826 return 0; 798 return 0;
827} 799}
@@ -840,7 +812,6 @@ static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
840{ 812{
841 struct sd *sd = (struct sd *) gspca_dev; 813 struct sd *sd = (struct sd *) gspca_dev;
842 814
843 getcontrast(gspca_dev);
844 *val = sd->contrast; 815 *val = sd->contrast;
845 return 0; 816 return 0;
846} 817}
@@ -859,7 +830,6 @@ static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
859{ 830{
860 struct sd *sd = (struct sd *) gspca_dev; 831 struct sd *sd = (struct sd *) gspca_dev;
861 832
862 getcolors(gspca_dev);
863 *val = sd->colors; 833 *val = sd->colors;
864 return 0; 834 return 0;
865} 835}
@@ -928,8 +898,10 @@ static struct usb_driver sd_driver = {
928/* -- module insert / remove -- */ 898/* -- module insert / remove -- */
929static int __init sd_mod_init(void) 899static int __init sd_mod_init(void)
930{ 900{
931 if (usb_register(&sd_driver) < 0) 901 int ret;
932 return -1; 902 ret = usb_register(&sd_driver);
903 if (ret < 0)
904 return ret;
933 PDEBUG(D_PROBE, "registered"); 905 PDEBUG(D_PROBE, "registered");
934 return 0; 906 return 0;
935} 907}
diff --git a/drivers/media/video/gspca/finepix.c b/drivers/media/video/gspca/finepix.c
index afc8b2dd307b..00e6863ed666 100644
--- a/drivers/media/video/gspca/finepix.c
+++ b/drivers/media/video/gspca/finepix.c
@@ -27,7 +27,7 @@ MODULE_DESCRIPTION("Fujifilm FinePix USB V4L2 driver");
27MODULE_LICENSE("GPL"); 27MODULE_LICENSE("GPL");
28 28
29/* Default timeout, in ms */ 29/* Default timeout, in ms */
30#define FPIX_TIMEOUT (HZ / 10) 30#define FPIX_TIMEOUT 250
31 31
32/* Maximum transfer size to use. The windows driver reads by chunks of 32/* Maximum transfer size to use. The windows driver reads by chunks of
33 * 0x2000 bytes, so do the same. Note: reading more seems to work 33 * 0x2000 bytes, so do the same. Note: reading more seems to work
@@ -38,38 +38,15 @@ MODULE_LICENSE("GPL");
38struct usb_fpix { 38struct usb_fpix {
39 struct gspca_dev gspca_dev; /* !! must be the first item */ 39 struct gspca_dev gspca_dev; /* !! must be the first item */
40 40
41 /* 41 struct work_struct work_struct;
42 * USB stuff 42 struct workqueue_struct *work_thread;
43 */
44 struct usb_ctrlrequest ctrlreq;
45 struct urb *control_urb;
46 struct timer_list bulk_timer;
47
48 enum {
49 FPIX_NOP, /* inactive, else streaming */
50 FPIX_RESET, /* must reset */
51 FPIX_REQ_FRAME, /* requesting a frame */
52 FPIX_READ_FRAME, /* reading frame */
53 } state;
54
55 /*
56 * Driver stuff
57 */
58 struct delayed_work wqe;
59 struct completion can_close;
60 int streaming;
61}; 43};
62 44
63/* Delay after which claim the next frame. If the delay is too small, 45/* Delay after which claim the next frame. If the delay is too small,
64 * the camera will return old frames. On the 4800Z, 20ms is bad, 25ms 46 * the camera will return old frames. On the 4800Z, 20ms is bad, 25ms
65 * will fail every 4 or 5 frames, but 30ms is perfect. */ 47 * will fail every 4 or 5 frames, but 30ms is perfect. On the A210,
66#define NEXT_FRAME_DELAY (((HZ * 30) + 999) / 1000) 48 * 30ms is bad while 35ms is perfect. */
67 49#define NEXT_FRAME_DELAY 35
68#define dev_new_state(new_state) { \
69 PDEBUG(D_STREAM, "new state from %d to %d at %s:%d", \
70 dev->state, new_state, __func__, __LINE__); \
71 dev->state = new_state; \
72}
73 50
74/* These cameras only support 320x200. */ 51/* These cameras only support 320x200. */
75static const struct v4l2_pix_format fpix_mode[1] = { 52static const struct v4l2_pix_format fpix_mode[1] = {
@@ -80,316 +57,183 @@ static const struct v4l2_pix_format fpix_mode[1] = {
80 .priv = 0} 57 .priv = 0}
81}; 58};
82 59
83/* Reads part of a frame */ 60/* send a command to the webcam */
84static void read_frame_part(struct usb_fpix *dev) 61static int command(struct gspca_dev *gspca_dev,
62 int order) /* 0: reset, 1: frame request */
85{ 63{
86 int ret; 64 static u8 order_values[2][12] = {
65 {0xc6, 0, 0, 0, 0, 0, 0, 0, 0x20, 0, 0, 0}, /* reset */
66 {0xd3, 0, 0, 0, 0, 0, 0, 0x01, 0, 0, 0, 0}, /* fr req */
67 };
87 68
88 PDEBUG(D_STREAM, "read_frame_part"); 69 memcpy(gspca_dev->usb_buf, order_values[order], 12);
89 70 return usb_control_msg(gspca_dev->dev,
90 /* Reads part of a frame */ 71 usb_sndctrlpipe(gspca_dev->dev, 0),
91 ret = usb_submit_urb(dev->gspca_dev.urb[0], GFP_ATOMIC); 72 USB_REQ_GET_STATUS,
92 if (ret) { 73 USB_DIR_OUT | USB_TYPE_CLASS |
93 dev_new_state(FPIX_RESET); 74 USB_RECIP_INTERFACE, 0, 0, gspca_dev->usb_buf,
94 schedule_delayed_work(&dev->wqe, 1); 75 12, FPIX_TIMEOUT);
95 PDEBUG(D_STREAM, "usb_submit_urb failed with %d",
96 ret);
97 } else {
98 /* Sometimes we never get a callback, so use a timer.
99 * Is this masking a bug somewhere else? */
100 dev->bulk_timer.expires = jiffies + msecs_to_jiffies(150);
101 add_timer(&dev->bulk_timer);
102 }
103} 76}
104 77
105/* Callback for URBs. */ 78/* workqueue */
106static void urb_callback(struct urb *urb) 79static void dostream(struct work_struct *work)
107{ 80{
108 struct gspca_dev *gspca_dev = urb->context; 81 struct usb_fpix *dev = container_of(work, struct usb_fpix, work_struct);
109 struct usb_fpix *dev = (struct usb_fpix *) gspca_dev; 82 struct gspca_dev *gspca_dev = &dev->gspca_dev;
110 83 struct urb *urb = gspca_dev->urb[0];
111 PDEBUG(D_PACK, 84 u8 *data = urb->transfer_buffer;
112 "enter urb_callback - status=%d, length=%d", 85 struct gspca_frame *frame;
113 urb->status, urb->actual_length); 86 int ret = 0;
114 87 int len;
115 if (dev->state == FPIX_READ_FRAME) 88
116 del_timer(&dev->bulk_timer); 89 /* synchronize with the main driver */
117 90 mutex_lock(&gspca_dev->usb_lock);
118 if (urb->status != 0) { 91 mutex_unlock(&gspca_dev->usb_lock);
119 /* We kill a stuck urb every 50 frames on average, so don't 92 PDEBUG(D_STREAM, "dostream started");
120 * display a log message for that. */ 93
121 if (urb->status != -ECONNRESET) 94 /* loop reading a frame */
122 PDEBUG(D_STREAM, "bad URB status %d", urb->status); 95again:
123 dev_new_state(FPIX_RESET); 96 while (gspca_dev->present && gspca_dev->streaming) {
124 schedule_delayed_work(&dev->wqe, 1); 97
125 } 98 /* request a frame */
126 99 mutex_lock(&gspca_dev->usb_lock);
127 switch (dev->state) { 100 ret = command(gspca_dev, 1);
128 case FPIX_REQ_FRAME: 101 mutex_unlock(&gspca_dev->usb_lock);
129 dev_new_state(FPIX_READ_FRAME); 102 if (ret < 0)
130 read_frame_part(dev); 103 break;
131 break; 104 if (!gspca_dev->present || !gspca_dev->streaming)
132 105 break;
133 case FPIX_READ_FRAME: { 106
134 unsigned char *data = urb->transfer_buffer; 107 /* the frame comes in parts */
135 struct gspca_frame *frame; 108 for (;;) {
136 109 ret = usb_bulk_msg(gspca_dev->dev,
137 frame = gspca_get_i_frame(&dev->gspca_dev); 110 urb->pipe,
138 if (frame == NULL) 111 data,
139 gspca_dev->last_packet_type = DISCARD_PACKET; 112 FPIX_MAX_TRANSFER,
140 if (urb->actual_length < FPIX_MAX_TRANSFER || 113 &len, FPIX_TIMEOUT);
141 (data[urb->actual_length-2] == 0xff && 114 if (ret < 0) {
142 data[urb->actual_length-1] == 0xd9)) { 115 /* Most of the time we get a timeout
143 116 * error. Just restart. */
144 /* If the result is less than what was asked 117 goto again;
145 * for, then it's the end of the 118 }
146 * frame. Sometime the jpeg is not complete, 119 if (!gspca_dev->present || !gspca_dev->streaming)
147 * but there's nothing we can do. We also end 120 goto out;
148 * here if the the jpeg ends right at the end 121 frame = gspca_get_i_frame(&dev->gspca_dev);
149 * of the frame. */ 122 if (frame == NULL)
150 if (frame) 123 gspca_dev->last_packet_type = DISCARD_PACKET;
151 gspca_frame_add(gspca_dev, LAST_PACKET, 124
152 frame, 125 if (len < FPIX_MAX_TRANSFER ||
153 data, urb->actual_length); 126 (data[len - 2] == 0xff &&
154 dev_new_state(FPIX_REQ_FRAME); 127 data[len - 1] == 0xd9)) {
155 schedule_delayed_work(&dev->wqe, NEXT_FRAME_DELAY); 128
156 } else { 129 /* If the result is less than what was asked
130 * for, then it's the end of the
131 * frame. Sometimes the jpeg is not complete,
132 * but there's nothing we can do. We also end
133 * here if the the jpeg ends right at the end
134 * of the frame. */
135 if (frame)
136 frame = gspca_frame_add(gspca_dev,
137 LAST_PACKET,
138 frame,
139 data, len);
140 break;
141 }
157 142
158 /* got a partial image */ 143 /* got a partial image */
159 if (frame) 144 if (frame)
160 gspca_frame_add(gspca_dev, 145 gspca_frame_add(gspca_dev,
161 gspca_dev->last_packet_type 146 gspca_dev->last_packet_type
162 == LAST_PACKET 147 == LAST_PACKET
163 ? FIRST_PACKET : INTER_PACKET, 148 ? FIRST_PACKET : INTER_PACKET,
164 frame, 149 frame, data, len);
165 data, urb->actual_length);
166 read_frame_part(dev);
167 } 150 }
168 break;
169 }
170
171 case FPIX_NOP:
172 case FPIX_RESET:
173 PDEBUG(D_STREAM, "invalid state %d", dev->state);
174 break;
175 }
176}
177 151
178/* Request a new frame */ 152 /* We must wait before trying reading the next
179static void request_frame(struct usb_fpix *dev) 153 * frame. If we don't, or if the delay is too short,
180{ 154 * the camera will disconnect. */
181 int ret; 155 msleep(NEXT_FRAME_DELAY);
182 struct gspca_dev *gspca_dev = &dev->gspca_dev;
183
184 /* Setup command packet */
185 memset(gspca_dev->usb_buf, 0, 12);
186 gspca_dev->usb_buf[0] = 0xd3;
187 gspca_dev->usb_buf[7] = 0x01;
188
189 /* Request a frame */
190 dev->ctrlreq.bRequestType =
191 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE;
192 dev->ctrlreq.bRequest = USB_REQ_GET_STATUS;
193 dev->ctrlreq.wValue = 0;
194 dev->ctrlreq.wIndex = 0;
195 dev->ctrlreq.wLength = cpu_to_le16(12);
196
197 usb_fill_control_urb(dev->control_urb,
198 gspca_dev->dev,
199 usb_sndctrlpipe(gspca_dev->dev, 0),
200 (unsigned char *) &dev->ctrlreq,
201 gspca_dev->usb_buf,
202 12, urb_callback, gspca_dev);
203
204 ret = usb_submit_urb(dev->control_urb, GFP_ATOMIC);
205 if (ret) {
206 dev_new_state(FPIX_RESET);
207 schedule_delayed_work(&dev->wqe, 1);
208 PDEBUG(D_STREAM, "usb_submit_urb failed with %d", ret);
209 }
210}
211
212/*--------------------------------------------------------------------------*/
213
214/* State machine. */
215static void fpix_sm(struct work_struct *work)
216{
217 struct usb_fpix *dev = container_of(work, struct usb_fpix, wqe.work);
218
219 PDEBUG(D_STREAM, "fpix_sm state %d", dev->state);
220
221 /* verify that the device wasn't unplugged */
222 if (!dev->gspca_dev.present) {
223 PDEBUG(D_STREAM, "device is gone");
224 dev_new_state(FPIX_NOP);
225 complete(&dev->can_close);
226 return;
227 }
228
229 if (!dev->streaming) {
230 PDEBUG(D_STREAM, "stopping state machine");
231 dev_new_state(FPIX_NOP);
232 complete(&dev->can_close);
233 return;
234 } 156 }
235 157
236 switch (dev->state) { 158out:
237 case FPIX_RESET: 159 PDEBUG(D_STREAM, "dostream stopped");
238 dev_new_state(FPIX_REQ_FRAME);
239 schedule_delayed_work(&dev->wqe, HZ / 10);
240 break;
241
242 case FPIX_REQ_FRAME:
243 /* get an image */
244 request_frame(dev);
245 break;
246
247 case FPIX_NOP:
248 case FPIX_READ_FRAME:
249 PDEBUG(D_STREAM, "invalid state %d", dev->state);
250 break;
251 }
252} 160}
253 161
254/* this function is called at probe time */ 162/* this function is called at probe time */
255static int sd_config(struct gspca_dev *gspca_dev, 163static int sd_config(struct gspca_dev *gspca_dev,
256 const struct usb_device_id *id) 164 const struct usb_device_id *id)
257{ 165{
166 struct usb_fpix *dev = (struct usb_fpix *) gspca_dev;
258 struct cam *cam = &gspca_dev->cam; 167 struct cam *cam = &gspca_dev->cam;
259 168
260 cam->cam_mode = fpix_mode; 169 cam->cam_mode = fpix_mode;
261 cam->nmodes = 1; 170 cam->nmodes = 1;
262 cam->epaddr = 0x01; /* todo: correct for all cams? */
263 cam->bulk_size = FPIX_MAX_TRANSFER; 171 cam->bulk_size = FPIX_MAX_TRANSFER;
264 172
265/* gspca_dev->nbalt = 1; * use bulk transfer */ 173 INIT_WORK(&dev->work_struct, dostream);
266 return 0;
267}
268
269/* Stop streaming and free the ressources allocated by sd_start. */
270static void sd_stopN(struct gspca_dev *gspca_dev)
271{
272 struct usb_fpix *dev = (struct usb_fpix *) gspca_dev;
273
274 dev->streaming = 0;
275
276 /* Stop the state machine */
277 if (dev->state != FPIX_NOP)
278 wait_for_completion(&dev->can_close);
279}
280
281/* called on streamoff with alt 0 and disconnect */
282static void sd_stop0(struct gspca_dev *gspca_dev)
283{
284 struct usb_fpix *dev = (struct usb_fpix *) gspca_dev;
285
286 usb_free_urb(dev->control_urb);
287 dev->control_urb = NULL;
288}
289
290/* Kill an URB that hasn't completed. */
291static void timeout_kill(unsigned long data)
292{
293 struct urb *urb = (struct urb *) data;
294 174
295 usb_unlink_urb(urb); 175 return 0;
296} 176}
297 177
298/* this function is called at probe and resume time */ 178/* this function is called at probe and resume time */
299static int sd_init(struct gspca_dev *gspca_dev) 179static int sd_init(struct gspca_dev *gspca_dev)
300{ 180{
301 struct usb_fpix *dev = (struct usb_fpix *) gspca_dev;
302
303 INIT_DELAYED_WORK(&dev->wqe, fpix_sm);
304
305 init_timer(&dev->bulk_timer);
306 dev->bulk_timer.function = timeout_kill;
307
308 return 0; 181 return 0;
309} 182}
310 183
184/* start the camera */
311static int sd_start(struct gspca_dev *gspca_dev) 185static int sd_start(struct gspca_dev *gspca_dev)
312{ 186{
313 struct usb_fpix *dev = (struct usb_fpix *) gspca_dev; 187 struct usb_fpix *dev = (struct usb_fpix *) gspca_dev;
314 int ret; 188 int ret, len;
315 int size_ret;
316 189
317 /* Init the device */ 190 /* Init the device */
318 memset(gspca_dev->usb_buf, 0, 12); 191 ret = command(gspca_dev, 0);
319 gspca_dev->usb_buf[0] = 0xc6; 192 if (ret < 0) {
320 gspca_dev->usb_buf[8] = 0x20; 193 PDEBUG(D_STREAM, "init failed %d", ret);
321 194 return ret;
322 ret = usb_control_msg(gspca_dev->dev,
323 usb_sndctrlpipe(gspca_dev->dev, 0),
324 USB_REQ_GET_STATUS,
325 USB_DIR_OUT | USB_TYPE_CLASS |
326 USB_RECIP_INTERFACE, 0, 0, gspca_dev->usb_buf,
327 12, FPIX_TIMEOUT);
328
329 if (ret != 12) {
330 PDEBUG(D_STREAM, "usb_control_msg failed (%d)", ret);
331 ret = -EIO;
332 goto error;
333 } 195 }
334 196
335 /* Read the result of the command. Ignore the result, for it 197 /* Read the result of the command. Ignore the result, for it
336 * varies with the device. */ 198 * varies with the device. */
337 ret = usb_bulk_msg(gspca_dev->dev, 199 ret = usb_bulk_msg(gspca_dev->dev,
338 usb_rcvbulkpipe(gspca_dev->dev, 200 gspca_dev->urb[0]->pipe,
339 gspca_dev->cam.epaddr), 201 gspca_dev->urb[0]->transfer_buffer,
340 gspca_dev->usb_buf, FPIX_MAX_TRANSFER, &size_ret, 202 FPIX_MAX_TRANSFER, &len,
341 FPIX_TIMEOUT); 203 FPIX_TIMEOUT);
342 if (ret != 0) { 204 if (ret < 0) {
343 PDEBUG(D_STREAM, "usb_bulk_msg failed (%d)", ret); 205 PDEBUG(D_STREAM, "usb_bulk_msg failed %d", ret);
344 ret = -EIO; 206 return ret;
345 goto error;
346 } 207 }
347 208
348 /* Request a frame, but don't read it */ 209 /* Request a frame, but don't read it */
349 memset(gspca_dev->usb_buf, 0, 12); 210 ret = command(gspca_dev, 1);
350 gspca_dev->usb_buf[0] = 0xd3; 211 if (ret < 0) {
351 gspca_dev->usb_buf[7] = 0x01; 212 PDEBUG(D_STREAM, "frame request failed %d", ret);
352 213 return ret;
353 ret = usb_control_msg(gspca_dev->dev,
354 usb_sndctrlpipe(gspca_dev->dev, 0),
355 USB_REQ_GET_STATUS,
356 USB_DIR_OUT | USB_TYPE_CLASS |
357 USB_RECIP_INTERFACE, 0, 0, gspca_dev->usb_buf,
358 12, FPIX_TIMEOUT);
359 if (ret != 12) {
360 PDEBUG(D_STREAM, "usb_control_msg failed (%d)", ret);
361 ret = -EIO;
362 goto error;
363 } 214 }
364 215
365 /* Again, reset bulk in endpoint */ 216 /* Again, reset bulk in endpoint */
366 usb_clear_halt(gspca_dev->dev, gspca_dev->cam.epaddr); 217 usb_clear_halt(gspca_dev->dev, gspca_dev->urb[0]->pipe);
367
368 /* Allocate a control URB */
369 dev->control_urb = usb_alloc_urb(0, GFP_KERNEL);
370 if (!dev->control_urb) {
371 PDEBUG(D_STREAM, "No free urbs available");
372 ret = -EIO;
373 goto error;
374 }
375
376 /* Various initializations. */
377 init_completion(&dev->can_close);
378 dev->bulk_timer.data = (unsigned long)dev->gspca_dev.urb[0];
379 dev->gspca_dev.urb[0]->complete = urb_callback;
380 dev->streaming = 1;
381 218
382 /* Schedule a frame request. */ 219 /* Start the workqueue function to do the streaming */
383 dev_new_state(FPIX_REQ_FRAME); 220 dev->work_thread = create_singlethread_workqueue(MODULE_NAME);
384 schedule_delayed_work(&dev->wqe, 1); 221 queue_work(dev->work_thread, &dev->work_struct);
385 222
386 return 0; 223 return 0;
224}
225
226/* called on streamoff with alt==0 and on disconnect */
227/* the usb_lock is held at entry - restore on exit */
228static void sd_stop0(struct gspca_dev *gspca_dev)
229{
230 struct usb_fpix *dev = (struct usb_fpix *) gspca_dev;
387 231
388error: 232 /* wait for the work queue to terminate */
389 /* Free the ressources */ 233 mutex_unlock(&gspca_dev->usb_lock);
390 sd_stopN(gspca_dev); 234 destroy_workqueue(dev->work_thread);
391 sd_stop0(gspca_dev); 235 mutex_lock(&gspca_dev->usb_lock);
392 return ret; 236 dev->work_thread = NULL;
393} 237}
394 238
395/* Table of supported USB devices */ 239/* Table of supported USB devices */
@@ -424,12 +268,11 @@ MODULE_DEVICE_TABLE(usb, device_table);
424 268
425/* sub-driver description */ 269/* sub-driver description */
426static const struct sd_desc sd_desc = { 270static const struct sd_desc sd_desc = {
427 .name = MODULE_NAME, 271 .name = MODULE_NAME,
428 .config = sd_config, 272 .config = sd_config,
429 .init = sd_init, 273 .init = sd_init,
430 .start = sd_start, 274 .start = sd_start,
431 .stopN = sd_stopN, 275 .stop0 = sd_stop0,
432 .stop0 = sd_stop0,
433}; 276};
434 277
435/* -- device connect -- */ 278/* -- device connect -- */
@@ -443,24 +286,28 @@ static int sd_probe(struct usb_interface *intf,
443} 286}
444 287
445static struct usb_driver sd_driver = { 288static struct usb_driver sd_driver = {
446 .name = MODULE_NAME, 289 .name = MODULE_NAME,
447 .id_table = device_table, 290 .id_table = device_table,
448 .probe = sd_probe, 291 .probe = sd_probe,
449 .disconnect = gspca_disconnect, 292 .disconnect = gspca_disconnect,
450#ifdef CONFIG_PM 293#ifdef CONFIG_PM
451 .suspend = gspca_suspend, 294 .suspend = gspca_suspend,
452 .resume = gspca_resume, 295 .resume = gspca_resume,
453#endif 296#endif
454}; 297};
455 298
456/* -- module insert / remove -- */ 299/* -- module insert / remove -- */
457static int __init sd_mod_init(void) 300static int __init sd_mod_init(void)
458{ 301{
459 if (usb_register(&sd_driver) < 0) 302 int ret;
460 return -1; 303
304 ret = usb_register(&sd_driver);
305 if (ret < 0)
306 return ret;
461 PDEBUG(D_PROBE, "registered"); 307 PDEBUG(D_PROBE, "registered");
462 return 0; 308 return 0;
463} 309}
310
464static void __exit sd_mod_exit(void) 311static void __exit sd_mod_exit(void)
465{ 312{
466 usb_deregister(&sd_driver); 313 usb_deregister(&sd_driver);
diff --git a/drivers/media/video/gspca/gspca.c b/drivers/media/video/gspca/gspca.c
index 65e4901f4db7..a75c1ca2db41 100644
--- a/drivers/media/video/gspca/gspca.c
+++ b/drivers/media/video/gspca/gspca.c
@@ -38,15 +38,16 @@
38#include "gspca.h" 38#include "gspca.h"
39 39
40/* global values */ 40/* global values */
41#define DEF_NURBS 2 /* default number of URBs */ 41#define DEF_NURBS 3 /* default number of URBs */
42#if DEF_NURBS > MAX_NURBS
43#error "DEF_NURBS too big"
44#endif
42 45
43MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>"); 46MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>");
44MODULE_DESCRIPTION("GSPCA USB Camera Driver"); 47MODULE_DESCRIPTION("GSPCA USB Camera Driver");
45MODULE_LICENSE("GPL"); 48MODULE_LICENSE("GPL");
46 49
47#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 4, 0) 50#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 5, 0)
48
49static int video_nr = -1;
50 51
51#ifdef GSPCA_DEBUG 52#ifdef GSPCA_DEBUG
52int gspca_debug = D_ERR | D_PROBE; 53int gspca_debug = D_ERR | D_PROBE;
@@ -126,16 +127,18 @@ static void fill_frame(struct gspca_dev *gspca_dev,
126 struct urb *urb) 127 struct urb *urb)
127{ 128{
128 struct gspca_frame *frame; 129 struct gspca_frame *frame;
129 __u8 *data; /* address of data in the iso message */ 130 u8 *data; /* address of data in the iso message */
130 int i, len, st; 131 int i, len, st;
131 cam_pkt_op pkt_scan; 132 cam_pkt_op pkt_scan;
132 133
133 if (urb->status != 0) { 134 if (urb->status != 0) {
135 if (urb->status == -ESHUTDOWN)
136 return; /* disconnection */
134#ifdef CONFIG_PM 137#ifdef CONFIG_PM
135 if (!gspca_dev->frozen) 138 if (!gspca_dev->frozen)
136#endif 139#endif
137 PDEBUG(D_ERR|D_PACK, "urb status: %d", urb->status); 140 PDEBUG(D_ERR|D_PACK, "urb status: %d", urb->status);
138 return; /* disconnection ? */ 141 return;
139 } 142 }
140 pkt_scan = gspca_dev->sd_desc->pkt_scan; 143 pkt_scan = gspca_dev->sd_desc->pkt_scan;
141 for (i = 0; i < urb->number_of_packets; i++) { 144 for (i = 0; i < urb->number_of_packets; i++) {
@@ -166,7 +169,7 @@ static void fill_frame(struct gspca_dev *gspca_dev,
166 /* let the packet be analyzed by the subdriver */ 169 /* let the packet be analyzed by the subdriver */
167 PDEBUG(D_PACK, "packet [%d] o:%d l:%d", 170 PDEBUG(D_PACK, "packet [%d] o:%d l:%d",
168 i, urb->iso_frame_desc[i].offset, len); 171 i, urb->iso_frame_desc[i].offset, len);
169 data = (__u8 *) urb->transfer_buffer 172 data = (u8 *) urb->transfer_buffer
170 + urb->iso_frame_desc[i].offset; 173 + urb->iso_frame_desc[i].offset;
171 pkt_scan(gspca_dev, frame, data, len); 174 pkt_scan(gspca_dev, frame, data, len);
172 } 175 }
@@ -182,8 +185,7 @@ static void fill_frame(struct gspca_dev *gspca_dev,
182 * 185 *
183 * Analyse each packet and call the subdriver for copy to the frame buffer. 186 * Analyse each packet and call the subdriver for copy to the frame buffer.
184 */ 187 */
185static void isoc_irq(struct urb *urb 188static void isoc_irq(struct urb *urb)
186)
187{ 189{
188 struct gspca_dev *gspca_dev = (struct gspca_dev *) urb->context; 190 struct gspca_dev *gspca_dev = (struct gspca_dev *) urb->context;
189 191
@@ -196,8 +198,7 @@ static void isoc_irq(struct urb *urb
196/* 198/*
197 * bulk message interrupt from the USB device 199 * bulk message interrupt from the USB device
198 */ 200 */
199static void bulk_irq(struct urb *urb 201static void bulk_irq(struct urb *urb)
200)
201{ 202{
202 struct gspca_dev *gspca_dev = (struct gspca_dev *) urb->context; 203 struct gspca_dev *gspca_dev = (struct gspca_dev *) urb->context;
203 struct gspca_frame *frame; 204 struct gspca_frame *frame;
@@ -209,6 +210,8 @@ static void bulk_irq(struct urb *urb
209 switch (urb->status) { 210 switch (urb->status) {
210 case 0: 211 case 0:
211 break; 212 break;
213 case -ESHUTDOWN:
214 return; /* disconnection */
212 case -ECONNRESET: 215 case -ECONNRESET:
213 urb->status = 0; 216 urb->status = 0;
214 break; 217 break;
@@ -217,7 +220,7 @@ static void bulk_irq(struct urb *urb
217 if (!gspca_dev->frozen) 220 if (!gspca_dev->frozen)
218#endif 221#endif
219 PDEBUG(D_ERR|D_PACK, "urb status: %d", urb->status); 222 PDEBUG(D_ERR|D_PACK, "urb status: %d", urb->status);
220 return; /* disconnection ? */ 223 return;
221 } 224 }
222 225
223 /* check the availability of the frame buffer */ 226 /* check the availability of the frame buffer */
@@ -322,6 +325,7 @@ static int gspca_is_compressed(__u32 format)
322 case V4L2_PIX_FMT_JPEG: 325 case V4L2_PIX_FMT_JPEG:
323 case V4L2_PIX_FMT_SPCA561: 326 case V4L2_PIX_FMT_SPCA561:
324 case V4L2_PIX_FMT_PAC207: 327 case V4L2_PIX_FMT_PAC207:
328 case V4L2_PIX_FMT_MR97310A:
325 return 1; 329 return 1;
326 } 330 }
327 return 0; 331 return 0;
@@ -422,10 +426,8 @@ static void destroy_urbs(struct gspca_dev *gspca_dev)
422 if (urb == NULL) 426 if (urb == NULL)
423 break; 427 break;
424 428
425 BUG_ON(!gspca_dev->dev);
426 gspca_dev->urb[i] = NULL; 429 gspca_dev->urb[i] = NULL;
427 if (!gspca_dev->present) 430 usb_kill_urb(urb);
428 usb_kill_urb(urb);
429 if (urb->transfer_buffer != NULL) 431 if (urb->transfer_buffer != NULL)
430 usb_buffer_free(gspca_dev->dev, 432 usb_buffer_free(gspca_dev->dev,
431 urb->transfer_buffer_length, 433 urb->transfer_buffer_length,
@@ -439,22 +441,16 @@ static void destroy_urbs(struct gspca_dev *gspca_dev)
439 * look for an input transfer endpoint in an alternate setting 441 * look for an input transfer endpoint in an alternate setting
440 */ 442 */
441static struct usb_host_endpoint *alt_xfer(struct usb_host_interface *alt, 443static struct usb_host_endpoint *alt_xfer(struct usb_host_interface *alt,
442 __u8 epaddr,
443 __u8 xfer) 444 __u8 xfer)
444{ 445{
445 struct usb_host_endpoint *ep; 446 struct usb_host_endpoint *ep;
446 int i, attr; 447 int i, attr;
447 448
448 epaddr |= USB_DIR_IN;
449 for (i = 0; i < alt->desc.bNumEndpoints; i++) { 449 for (i = 0; i < alt->desc.bNumEndpoints; i++) {
450 ep = &alt->endpoint[i]; 450 ep = &alt->endpoint[i];
451 if (ep->desc.bEndpointAddress == epaddr) { 451 attr = ep->desc.bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
452 attr = ep->desc.bmAttributes 452 if (attr == xfer)
453 & USB_ENDPOINT_XFERTYPE_MASK; 453 return ep;
454 if (attr == xfer)
455 return ep;
456 break;
457 }
458 } 454 }
459 return NULL; 455 return NULL;
460} 456}
@@ -478,23 +474,23 @@ static struct usb_host_endpoint *get_ep(struct gspca_dev *gspca_dev)
478 i = gspca_dev->alt; /* previous alt setting */ 474 i = gspca_dev->alt; /* previous alt setting */
479 475
480 /* try isoc */ 476 /* try isoc */
481 while (--i > 0) { /* alt 0 is unusable */ 477 while (--i >= 0) {
482 ep = alt_xfer(&intf->altsetting[i], 478 ep = alt_xfer(&intf->altsetting[i],
483 gspca_dev->cam.epaddr,
484 USB_ENDPOINT_XFER_ISOC); 479 USB_ENDPOINT_XFER_ISOC);
485 if (ep) 480 if (ep)
486 break; 481 break;
487 } 482 }
488 483
489 /* if no isoc, try bulk */ 484 /* if no isoc, try bulk (alt 0 only) */
490 if (ep == NULL) { 485 if (ep == NULL) {
491 ep = alt_xfer(&intf->altsetting[0], 486 ep = alt_xfer(&intf->altsetting[0],
492 gspca_dev->cam.epaddr,
493 USB_ENDPOINT_XFER_BULK); 487 USB_ENDPOINT_XFER_BULK);
494 if (ep == NULL) { 488 if (ep == NULL) {
495 err("no transfer endpoint found"); 489 err("no transfer endpoint found");
496 return NULL; 490 return NULL;
497 } 491 }
492 i = 0;
493 gspca_dev->bulk = 1;
498 } 494 }
499 PDEBUG(D_STREAM, "use alt %d ep 0x%02x", 495 PDEBUG(D_STREAM, "use alt %d ep 0x%02x",
500 i, ep->desc.bEndpointAddress); 496 i, ep->desc.bEndpointAddress);
@@ -521,7 +517,7 @@ static int create_urbs(struct gspca_dev *gspca_dev,
521 /* calculate the packet size and the number of packets */ 517 /* calculate the packet size and the number of packets */
522 psize = le16_to_cpu(ep->desc.wMaxPacketSize); 518 psize = le16_to_cpu(ep->desc.wMaxPacketSize);
523 519
524 if (gspca_dev->alt != 0) { /* isoc */ 520 if (!gspca_dev->bulk) { /* isoc */
525 521
526 /* See paragraph 5.9 / table 5-11 of the usb 2.0 spec. */ 522 /* See paragraph 5.9 / table 5-11 of the usb 2.0 spec. */
527 psize = (psize & 0x07ff) * (1 + ((psize >> 11) & 3)); 523 psize = (psize & 0x07ff) * (1 + ((psize >> 11) & 3));
@@ -601,6 +597,11 @@ static int gspca_init_transfer(struct gspca_dev *gspca_dev)
601 if (mutex_lock_interruptible(&gspca_dev->usb_lock)) 597 if (mutex_lock_interruptible(&gspca_dev->usb_lock))
602 return -ERESTARTSYS; 598 return -ERESTARTSYS;
603 599
600 if (!gspca_dev->present) {
601 ret = -ENODEV;
602 goto out;
603 }
604
604 /* set the higher alternate setting and 605 /* set the higher alternate setting and
605 * loop until urb submit succeeds */ 606 * loop until urb submit succeeds */
606 gspca_dev->alt = gspca_dev->nbalt; 607 gspca_dev->alt = gspca_dev->nbalt;
@@ -616,10 +617,9 @@ static int gspca_init_transfer(struct gspca_dev *gspca_dev)
616 goto out; 617 goto out;
617 618
618 /* clear the bulk endpoint */ 619 /* clear the bulk endpoint */
619 if (gspca_dev->alt == 0) /* if bulk transfer */ 620 if (gspca_dev->bulk)
620 usb_clear_halt(gspca_dev->dev, 621 usb_clear_halt(gspca_dev->dev,
621 usb_rcvintpipe(gspca_dev->dev, 622 gspca_dev->urb[0]->pipe);
622 gspca_dev->cam.epaddr));
623 623
624 /* start the cam */ 624 /* start the cam */
625 ret = gspca_dev->sd_desc->start(gspca_dev); 625 ret = gspca_dev->sd_desc->start(gspca_dev);
@@ -630,7 +630,7 @@ static int gspca_init_transfer(struct gspca_dev *gspca_dev)
630 gspca_dev->streaming = 1; 630 gspca_dev->streaming = 1;
631 631
632 /* some bulk transfers are started by the subdriver */ 632 /* some bulk transfers are started by the subdriver */
633 if (gspca_dev->alt == 0 && gspca_dev->cam.bulk_nurbs == 0) 633 if (gspca_dev->bulk && gspca_dev->cam.bulk_nurbs == 0)
634 break; 634 break;
635 635
636 /* submit the URBs */ 636 /* submit the URBs */
@@ -671,11 +671,14 @@ static int gspca_set_alt0(struct gspca_dev *gspca_dev)
671static void gspca_stream_off(struct gspca_dev *gspca_dev) 671static void gspca_stream_off(struct gspca_dev *gspca_dev)
672{ 672{
673 gspca_dev->streaming = 0; 673 gspca_dev->streaming = 0;
674 if (gspca_dev->present 674 if (gspca_dev->present) {
675 && gspca_dev->sd_desc->stopN) 675 if (gspca_dev->sd_desc->stopN)
676 gspca_dev->sd_desc->stopN(gspca_dev); 676 gspca_dev->sd_desc->stopN(gspca_dev);
677 destroy_urbs(gspca_dev); 677 destroy_urbs(gspca_dev);
678 gspca_set_alt0(gspca_dev); 678 gspca_set_alt0(gspca_dev);
679 }
680
681 /* always call stop0 to free the subdriver's resources */
679 if (gspca_dev->sd_desc->stop0) 682 if (gspca_dev->sd_desc->stop0)
680 gspca_dev->sd_desc->stop0(gspca_dev); 683 gspca_dev->sd_desc->stop0(gspca_dev);
681 PDEBUG(D_STREAM, "stream off OK"); 684 PDEBUG(D_STREAM, "stream off OK");
@@ -762,7 +765,6 @@ static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
762 fmtdesc->pixelformat = fmt_tb[index]; 765 fmtdesc->pixelformat = fmt_tb[index];
763 if (gspca_is_compressed(fmt_tb[index])) 766 if (gspca_is_compressed(fmt_tb[index]))
764 fmtdesc->flags = V4L2_FMT_FLAG_COMPRESSED; 767 fmtdesc->flags = V4L2_FMT_FLAG_COMPRESSED;
765 fmtdesc->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
766 fmtdesc->description[0] = fmtdesc->pixelformat & 0xff; 768 fmtdesc->description[0] = fmtdesc->pixelformat & 0xff;
767 fmtdesc->description[1] = (fmtdesc->pixelformat >> 8) & 0xff; 769 fmtdesc->description[1] = (fmtdesc->pixelformat >> 8) & 0xff;
768 fmtdesc->description[2] = (fmtdesc->pixelformat >> 16) & 0xff; 770 fmtdesc->description[2] = (fmtdesc->pixelformat >> 16) & 0xff;
@@ -957,8 +959,15 @@ static int vidioc_querycap(struct file *file, void *priv,
957 struct v4l2_capability *cap) 959 struct v4l2_capability *cap)
958{ 960{
959 struct gspca_dev *gspca_dev = priv; 961 struct gspca_dev *gspca_dev = priv;
962 int ret;
960 963
961 memset(cap, 0, sizeof *cap); 964 /* protect the access to the usb device */
965 if (mutex_lock_interruptible(&gspca_dev->usb_lock))
966 return -ERESTARTSYS;
967 if (!gspca_dev->present) {
968 ret = -ENODEV;
969 goto out;
970 }
962 strncpy(cap->driver, gspca_dev->sd_desc->name, sizeof cap->driver); 971 strncpy(cap->driver, gspca_dev->sd_desc->name, sizeof cap->driver);
963 if (gspca_dev->dev->product != NULL) { 972 if (gspca_dev->dev->product != NULL) {
964 strncpy(cap->card, gspca_dev->dev->product, 973 strncpy(cap->card, gspca_dev->dev->product,
@@ -969,13 +978,15 @@ static int vidioc_querycap(struct file *file, void *priv,
969 le16_to_cpu(gspca_dev->dev->descriptor.idVendor), 978 le16_to_cpu(gspca_dev->dev->descriptor.idVendor),
970 le16_to_cpu(gspca_dev->dev->descriptor.idProduct)); 979 le16_to_cpu(gspca_dev->dev->descriptor.idProduct));
971 } 980 }
972 strncpy(cap->bus_info, gspca_dev->dev->bus->bus_name, 981 usb_make_path(gspca_dev->dev, cap->bus_info, sizeof(cap->bus_info));
973 sizeof cap->bus_info);
974 cap->version = DRIVER_VERSION_NUMBER; 982 cap->version = DRIVER_VERSION_NUMBER;
975 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE 983 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE
976 | V4L2_CAP_STREAMING 984 | V4L2_CAP_STREAMING
977 | V4L2_CAP_READWRITE; 985 | V4L2_CAP_READWRITE;
978 return 0; 986 ret = 0;
987out:
988 mutex_unlock(&gspca_dev->usb_lock);
989 return ret;
979} 990}
980 991
981static int vidioc_queryctrl(struct file *file, void *priv, 992static int vidioc_queryctrl(struct file *file, void *priv,
@@ -1038,7 +1049,10 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
1038 PDEBUG(D_CONF, "set ctrl [%08x] = %d", ctrl->id, ctrl->value); 1049 PDEBUG(D_CONF, "set ctrl [%08x] = %d", ctrl->id, ctrl->value);
1039 if (mutex_lock_interruptible(&gspca_dev->usb_lock)) 1050 if (mutex_lock_interruptible(&gspca_dev->usb_lock))
1040 return -ERESTARTSYS; 1051 return -ERESTARTSYS;
1041 ret = ctrls->set(gspca_dev, ctrl->value); 1052 if (gspca_dev->present)
1053 ret = ctrls->set(gspca_dev, ctrl->value);
1054 else
1055 ret = -ENODEV;
1042 mutex_unlock(&gspca_dev->usb_lock); 1056 mutex_unlock(&gspca_dev->usb_lock);
1043 return ret; 1057 return ret;
1044 } 1058 }
@@ -1062,7 +1076,10 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
1062 return -EINVAL; 1076 return -EINVAL;
1063 if (mutex_lock_interruptible(&gspca_dev->usb_lock)) 1077 if (mutex_lock_interruptible(&gspca_dev->usb_lock))
1064 return -ERESTARTSYS; 1078 return -ERESTARTSYS;
1065 ret = ctrls->get(gspca_dev, &ctrl->value); 1079 if (gspca_dev->present)
1080 ret = ctrls->get(gspca_dev, &ctrl->value);
1081 else
1082 ret = -ENODEV;
1066 mutex_unlock(&gspca_dev->usb_lock); 1083 mutex_unlock(&gspca_dev->usb_lock);
1067 return ret; 1084 return ret;
1068 } 1085 }
@@ -1081,7 +1098,6 @@ static int vidioc_s_audio(struct file *file, void *priv,
1081static int vidioc_g_audio(struct file *file, void *priv, 1098static int vidioc_g_audio(struct file *file, void *priv,
1082 struct v4l2_audio *audio) 1099 struct v4l2_audio *audio)
1083{ 1100{
1084 memset(audio, 0, sizeof *audio);
1085 strcpy(audio->name, "Microphone"); 1101 strcpy(audio->name, "Microphone");
1086 return 0; 1102 return 0;
1087} 1103}
@@ -1115,7 +1131,6 @@ static int vidioc_enum_input(struct file *file, void *priv,
1115 1131
1116 if (input->index != 0) 1132 if (input->index != 0)
1117 return -EINVAL; 1133 return -EINVAL;
1118 memset(input, 0, sizeof *input);
1119 input->type = V4L2_INPUT_TYPE_CAMERA; 1134 input->type = V4L2_INPUT_TYPE_CAMERA;
1120 strncpy(input->name, gspca_dev->sd_desc->name, 1135 strncpy(input->name, gspca_dev->sd_desc->name,
1121 sizeof input->name); 1136 sizeof input->name);
@@ -1224,10 +1239,7 @@ static int vidioc_streamon(struct file *file, void *priv,
1224 return -EINVAL; 1239 return -EINVAL;
1225 if (mutex_lock_interruptible(&gspca_dev->queue_lock)) 1240 if (mutex_lock_interruptible(&gspca_dev->queue_lock))
1226 return -ERESTARTSYS; 1241 return -ERESTARTSYS;
1227 if (!gspca_dev->present) { 1242
1228 ret = -ENODEV;
1229 goto out;
1230 }
1231 if (gspca_dev->nframes == 0 1243 if (gspca_dev->nframes == 0
1232 || !(gspca_dev->frame[0].v4l2_buf.flags & V4L2_BUF_FLAG_QUEUED)) { 1244 || !(gspca_dev->frame[0].v4l2_buf.flags & V4L2_BUF_FLAG_QUEUED)) {
1233 ret = -EINVAL; 1245 ret = -EINVAL;
@@ -1295,7 +1307,10 @@ static int vidioc_g_jpegcomp(struct file *file, void *priv,
1295 return -EINVAL; 1307 return -EINVAL;
1296 if (mutex_lock_interruptible(&gspca_dev->usb_lock)) 1308 if (mutex_lock_interruptible(&gspca_dev->usb_lock))
1297 return -ERESTARTSYS; 1309 return -ERESTARTSYS;
1298 ret = gspca_dev->sd_desc->get_jcomp(gspca_dev, jpegcomp); 1310 if (gspca_dev->present)
1311 ret = gspca_dev->sd_desc->get_jcomp(gspca_dev, jpegcomp);
1312 else
1313 ret = -ENODEV;
1299 mutex_unlock(&gspca_dev->usb_lock); 1314 mutex_unlock(&gspca_dev->usb_lock);
1300 return ret; 1315 return ret;
1301} 1316}
@@ -1310,7 +1325,10 @@ static int vidioc_s_jpegcomp(struct file *file, void *priv,
1310 return -EINVAL; 1325 return -EINVAL;
1311 if (mutex_lock_interruptible(&gspca_dev->usb_lock)) 1326 if (mutex_lock_interruptible(&gspca_dev->usb_lock))
1312 return -ERESTARTSYS; 1327 return -ERESTARTSYS;
1313 ret = gspca_dev->sd_desc->set_jcomp(gspca_dev, jpegcomp); 1328 if (gspca_dev->present)
1329 ret = gspca_dev->sd_desc->set_jcomp(gspca_dev, jpegcomp);
1330 else
1331 ret = -ENODEV;
1314 mutex_unlock(&gspca_dev->usb_lock); 1332 mutex_unlock(&gspca_dev->usb_lock);
1315 return ret; 1333 return ret;
1316} 1334}
@@ -1320,8 +1338,6 @@ static int vidioc_g_parm(struct file *filp, void *priv,
1320{ 1338{
1321 struct gspca_dev *gspca_dev = priv; 1339 struct gspca_dev *gspca_dev = priv;
1322 1340
1323 memset(parm, 0, sizeof *parm);
1324 parm->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1325 parm->parm.capture.readbuffers = gspca_dev->nbufread; 1341 parm->parm.capture.readbuffers = gspca_dev->nbufread;
1326 1342
1327 if (gspca_dev->sd_desc->get_streamparm) { 1343 if (gspca_dev->sd_desc->get_streamparm) {
@@ -1329,7 +1345,11 @@ static int vidioc_g_parm(struct file *filp, void *priv,
1329 1345
1330 if (mutex_lock_interruptible(&gspca_dev->usb_lock)) 1346 if (mutex_lock_interruptible(&gspca_dev->usb_lock))
1331 return -ERESTARTSYS; 1347 return -ERESTARTSYS;
1332 ret = gspca_dev->sd_desc->get_streamparm(gspca_dev, parm); 1348 if (gspca_dev->present)
1349 ret = gspca_dev->sd_desc->get_streamparm(gspca_dev,
1350 parm);
1351 else
1352 ret = -ENODEV;
1333 mutex_unlock(&gspca_dev->usb_lock); 1353 mutex_unlock(&gspca_dev->usb_lock);
1334 return ret; 1354 return ret;
1335 } 1355 }
@@ -1354,7 +1374,11 @@ static int vidioc_s_parm(struct file *filp, void *priv,
1354 1374
1355 if (mutex_lock_interruptible(&gspca_dev->usb_lock)) 1375 if (mutex_lock_interruptible(&gspca_dev->usb_lock))
1356 return -ERESTARTSYS; 1376 return -ERESTARTSYS;
1357 ret = gspca_dev->sd_desc->set_streamparm(gspca_dev, parm); 1377 if (gspca_dev->present)
1378 ret = gspca_dev->sd_desc->set_streamparm(gspca_dev,
1379 parm);
1380 else
1381 ret = -ENODEV;
1358 mutex_unlock(&gspca_dev->usb_lock); 1382 mutex_unlock(&gspca_dev->usb_lock);
1359 return ret; 1383 return ret;
1360 } 1384 }
@@ -1382,7 +1406,6 @@ static int vidiocgmbuf(struct file *file, void *priv,
1382 { 1406 {
1383 struct v4l2_format fmt; 1407 struct v4l2_format fmt;
1384 1408
1385 memset(&fmt, 0, sizeof fmt);
1386 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 1409 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1387 i = gspca_dev->cam.nmodes - 1; /* highest mode */ 1410 i = gspca_dev->cam.nmodes - 1; /* highest mode */
1388 fmt.fmt.pix.width = gspca_dev->cam.cam_mode[i].width; 1411 fmt.fmt.pix.width = gspca_dev->cam.cam_mode[i].width;
@@ -1528,7 +1551,8 @@ static int frame_wait(struct gspca_dev *gspca_dev,
1528 1551
1529 if (gspca_dev->sd_desc->dq_callback) { 1552 if (gspca_dev->sd_desc->dq_callback) {
1530 mutex_lock(&gspca_dev->usb_lock); 1553 mutex_lock(&gspca_dev->usb_lock);
1531 gspca_dev->sd_desc->dq_callback(gspca_dev); 1554 if (gspca_dev->present)
1555 gspca_dev->sd_desc->dq_callback(gspca_dev);
1532 mutex_unlock(&gspca_dev->usb_lock); 1556 mutex_unlock(&gspca_dev->usb_lock);
1533 } 1557 }
1534 return j; 1558 return j;
@@ -1550,6 +1574,9 @@ static int vidioc_dqbuf(struct file *file, void *priv,
1550 if (v4l2_buf->memory != gspca_dev->memory) 1574 if (v4l2_buf->memory != gspca_dev->memory)
1551 return -EINVAL; 1575 return -EINVAL;
1552 1576
1577 if (!gspca_dev->present)
1578 return -ENODEV;
1579
1553 /* if not streaming, be sure the application will not loop forever */ 1580 /* if not streaming, be sure the application will not loop forever */
1554 if (!(file->f_flags & O_NONBLOCK) 1581 if (!(file->f_flags & O_NONBLOCK)
1555 && !gspca_dev->streaming && gspca_dev->users == 1) 1582 && !gspca_dev->streaming && gspca_dev->users == 1)
@@ -1700,8 +1727,6 @@ static unsigned int dev_poll(struct file *file, poll_table *wait)
1700 PDEBUG(D_FRAM, "poll"); 1727 PDEBUG(D_FRAM, "poll");
1701 1728
1702 poll_wait(file, &gspca_dev->wq, wait); 1729 poll_wait(file, &gspca_dev->wq, wait);
1703 if (!gspca_dev->present)
1704 return POLLERR;
1705 1730
1706 /* if reqbufs is not done, the user would use read() */ 1731 /* if reqbufs is not done, the user would use read() */
1707 if (gspca_dev->nframes == 0) { 1732 if (gspca_dev->nframes == 0) {
@@ -1714,10 +1739,6 @@ static unsigned int dev_poll(struct file *file, poll_table *wait)
1714 1739
1715 if (mutex_lock_interruptible(&gspca_dev->queue_lock) != 0) 1740 if (mutex_lock_interruptible(&gspca_dev->queue_lock) != 0)
1716 return POLLERR; 1741 return POLLERR;
1717 if (!gspca_dev->present) {
1718 ret = POLLERR;
1719 goto out;
1720 }
1721 1742
1722 /* check the next incoming buffer */ 1743 /* check the next incoming buffer */
1723 i = gspca_dev->fr_o; 1744 i = gspca_dev->fr_o;
@@ -1726,8 +1747,9 @@ static unsigned int dev_poll(struct file *file, poll_table *wait)
1726 ret = POLLIN | POLLRDNORM; /* something to read */ 1747 ret = POLLIN | POLLRDNORM; /* something to read */
1727 else 1748 else
1728 ret = 0; 1749 ret = 0;
1729out:
1730 mutex_unlock(&gspca_dev->queue_lock); 1750 mutex_unlock(&gspca_dev->queue_lock);
1751 if (!gspca_dev->present)
1752 return POLLHUP;
1731 return ret; 1753 return ret;
1732} 1754}
1733 1755
@@ -1925,7 +1947,7 @@ int gspca_dev_probe(struct usb_interface *intf,
1925 gspca_dev->present = 1; 1947 gspca_dev->present = 1;
1926 ret = video_register_device(&gspca_dev->vdev, 1948 ret = video_register_device(&gspca_dev->vdev,
1927 VFL_TYPE_GRABBER, 1949 VFL_TYPE_GRABBER,
1928 video_nr); 1950 -1);
1929 if (ret < 0) { 1951 if (ret < 0) {
1930 err("video_register_device err %d", ret); 1952 err("video_register_device err %d", ret);
1931 goto out; 1953 goto out;
@@ -1953,10 +1975,16 @@ void gspca_disconnect(struct usb_interface *intf)
1953 1975
1954 mutex_lock(&gspca_dev->usb_lock); 1976 mutex_lock(&gspca_dev->usb_lock);
1955 gspca_dev->present = 0; 1977 gspca_dev->present = 0;
1956 mutex_unlock(&gspca_dev->usb_lock);
1957 1978
1958 destroy_urbs(gspca_dev); 1979 if (gspca_dev->streaming) {
1980 destroy_urbs(gspca_dev);
1981 wake_up_interruptible(&gspca_dev->wq);
1982 }
1983
1984 /* the device is freed at exit of this function */
1959 gspca_dev->dev = NULL; 1985 gspca_dev->dev = NULL;
1986 mutex_unlock(&gspca_dev->usb_lock);
1987
1960 usb_set_intfdata(intf, NULL); 1988 usb_set_intfdata(intf, NULL);
1961 1989
1962 /* release the device */ 1990 /* release the device */
diff --git a/drivers/media/video/gspca/gspca.h b/drivers/media/video/gspca/gspca.h
index c90af9cb1e07..e4d4cf6ce05a 100644
--- a/drivers/media/video/gspca/gspca.h
+++ b/drivers/media/video/gspca/gspca.h
@@ -33,19 +33,13 @@ extern int gspca_debug;
33#endif 33#endif
34#undef err 34#undef err
35#define err(fmt, args...) \ 35#define err(fmt, args...) \
36 do {\ 36 printk(KERN_ERR MODULE_NAME ": " fmt "\n", ## args)
37 printk(KERN_ERR MODULE_NAME ": " fmt "\n", ## args); \
38 } while (0)
39#undef info 37#undef info
40#define info(fmt, args...) \ 38#define info(fmt, args...) \
41 do {\ 39 printk(KERN_INFO MODULE_NAME ": " fmt "\n", ## args)
42 printk(KERN_INFO MODULE_NAME ": " fmt "\n", ## args); \
43 } while (0)
44#undef warn 40#undef warn
45#define warn(fmt, args...) \ 41#define warn(fmt, args...) \
46 do {\ 42 printk(KERN_WARNING MODULE_NAME ": " fmt "\n", ## args)
47 printk(KERN_WARNING MODULE_NAME ": " fmt "\n", ## args); \
48 } while (0)
49 43
50#define GSPCA_MAX_FRAMES 16 /* maximum number of video frame buffers */ 44#define GSPCA_MAX_FRAMES 16 /* maximum number of video frame buffers */
51/* image transfers */ 45/* image transfers */
@@ -62,7 +56,6 @@ struct cam {
62 * - cannot be > MAX_NURBS 56 * - cannot be > MAX_NURBS
63 * - when 0 and bulk_size != 0 means 57 * - when 0 and bulk_size != 0 means
64 * 1 URB and submit done by subdriver */ 58 * 1 URB and submit done by subdriver */
65 __u8 epaddr;
66}; 59};
67 60
68struct gspca_dev; 61struct gspca_dev;
@@ -174,6 +167,7 @@ struct gspca_dev {
174 __u8 iface; /* USB interface number */ 167 __u8 iface; /* USB interface number */
175 __u8 alt; /* USB alternate setting */ 168 __u8 alt; /* USB alternate setting */
176 __u8 nbalt; /* number of USB alternate settings */ 169 __u8 nbalt; /* number of USB alternate settings */
170 u8 bulk; /* image transfer by 0:isoc / 1:bulk */
177}; 171};
178 172
179int gspca_dev_probe(struct usb_interface *intf, 173int gspca_dev_probe(struct usb_interface *intf,
diff --git a/drivers/media/video/gspca/jpeg.h b/drivers/media/video/gspca/jpeg.h
index d823b47bd4e6..de63c36806c0 100644
--- a/drivers/media/video/gspca/jpeg.h
+++ b/drivers/media/video/gspca/jpeg.h
@@ -24,171 +24,39 @@
24 * 24 *
25 */ 25 */
26 26
27/* start of jpeg frame + quantization table */ 27/*
28static const unsigned char quant[][0x88] = { 28 * generation options
29/* index 0 - Q40*/ 29 * CONEX_CAM Conexant if present
30 { 30 */
31
32/* JPEG header */
33static const u8 jpeg_head[] = {
31 0xff, 0xd8, /* jpeg */ 34 0xff, 0xd8, /* jpeg */
32 0xff, 0xdb, 0x00, 0x84, /* DQT */ 35
330, /* quantization table part 1 */ 36/* quantization table quality 50% */
34 20, 14, 15, 18, 15, 13, 20, 18, 16, 18, 23, 21, 20, 24, 30, 50,
35 33, 30, 28, 28, 30, 61, 44, 46, 36, 50, 73, 64, 76, 75, 71, 64,
36 70, 69, 80, 90, 115, 98, 80, 85, 109, 86, 69, 70, 100, 136, 101,
37 109,
38 119, 123, 129, 130, 129, 78, 96, 141, 151, 140, 125, 150, 115,
39 126, 129, 124,
401, /* quantization table part 2 */
41 21, 23, 23, 30, 26, 30, 59, 33, 33, 59, 124, 83, 70, 83, 124, 124,
42 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124,
43 124, 124, 124,
44 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124,
45 124, 124, 124,
46 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124,
47 124, 124, 124},
48/* index 1 - Q50 */
49 {
50 0xff, 0xd8,
51 0xff, 0xdb, 0x00, 0x84, /* DQT */
520,
53 16, 11, 12, 14, 12, 10, 16, 14, 13, 14, 18, 17, 16, 19, 24, 40,
54 26, 24, 22, 22, 24, 49, 35, 37, 29, 40, 58, 51, 61, 60, 57, 51,
55 56, 55, 64, 72, 92, 78, 64, 68, 87, 69, 55, 56, 80, 109, 81, 87,
56 95, 98, 103, 104, 103, 62, 77, 113, 121, 112, 100, 120, 92, 101,
57 103, 99,
581,
59 17, 18, 18, 24, 21, 24, 47, 26, 26, 47, 99, 66, 56, 66, 99, 99,
60 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
61 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
62 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99},
63/* index 2 Q60 */
64 {
65 0xff, 0xd8,
66 0xff, 0xdb, 0x00, 0x84, /* DQT */
670,
68 13, 9, 10, 11, 10, 8, 13, 11, 10, 11, 14, 14, 13, 15, 19, 32,
69 21, 19, 18, 18, 19, 39, 28, 30, 23, 32, 46, 41, 49, 48, 46, 41,
70 45, 44, 51, 58, 74, 62, 51, 54, 70, 55, 44, 45, 64, 87, 65, 70,
71 76, 78, 82, 83, 82, 50, 62, 90, 97, 90, 80, 96, 74, 81, 82, 79,
721,
73 14, 14, 14, 19, 17, 19, 38, 21, 21, 38, 79, 53, 45, 53, 79, 79,
74 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79,
75 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79,
76 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79},
77/* index 3 - Q70 */
78 {
79 0xff, 0xd8,
80 0xff, 0xdb, 0x00, 0x84, /* DQT */
810,
82 10, 7, 7, 8, 7, 6, 10, 8, 8, 8, 11, 10, 10, 11, 14, 24,
83 16, 14, 13, 13, 14, 29, 21, 22, 17, 24, 35, 31, 37, 36, 34, 31,
84 34, 33, 38, 43, 55, 47, 38, 41, 52, 41, 33, 34, 48, 65, 49, 52,
85 57, 59, 62, 62, 62, 37, 46, 68, 73, 67, 60, 72, 55, 61, 62, 59,
861,
87 10, 11, 11, 14, 13, 14, 28, 16, 16, 28, 59, 40, 34, 40, 59, 59,
88 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59,
89 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59,
90 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59},
91/* index 4 - Q80 */
92 {
93 0xff, 0xd8,
94 0xff, 0xdb, 0x00, 0x84, /* DQT */
950,
96 6, 4, 5, 6, 5, 4, 6, 6, 5, 6, 7, 7, 6, 8, 10, 16,
97 10, 10, 9, 9, 10, 20, 14, 15, 12, 16, 23, 20, 24, 24, 23, 20,
98 22, 22, 26, 29, 37, 31, 26, 27, 35, 28, 22, 22, 32, 44, 32, 35,
99 38, 39, 41, 42, 41, 25, 31, 45, 48, 45, 40, 48, 37, 40, 41, 40,
1001,
101 7, 7, 7, 10, 8, 10, 19, 10, 10, 19, 40, 26, 22, 26, 40, 40,
102 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40,
103 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40,
104 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40},
105/* index 5 - Q85 */
106 {
107 0xff, 0xd8,
108 0xff, 0xdb, 0x00, 0x84, /* DQT */
1090,
110 5, 3, 4, 4, 4, 3, 5, 4, 4, 4, 5, 5, 5, 6, 7, 12,
111 8, 7, 7, 7, 7, 15, 11, 11, 9, 12, 17, 15, 18, 18, 17, 15,
112 17, 17, 19, 22, 28, 23, 19, 20, 26, 21, 17, 17, 24, 33, 24, 26,
113 29, 29, 31, 31, 31, 19, 23, 34, 36, 34, 30, 36, 28, 30, 31, 30,
1141,
115 5, 5, 5, 7, 6, 7, 14, 8, 8, 14, 30, 20, 17, 20, 30, 30,
116 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
117 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
118 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30},
119/* index 6 - 86 */
120{
121 0xff, 0xd8,
122 0xff, 0xdb, 0x00, 0x84, /* DQT */
1230,
124 0x04, 0x03, 0x03, 0x04, 0x03, 0x03, 0x04, 0x04,
125 0x04, 0x04, 0x05, 0x05, 0x04, 0x05, 0x07, 0x0B,
126 0x07, 0x07, 0x06, 0x06, 0x07, 0x0E, 0x0A, 0x0A,
127 0x08, 0x0B, 0x10, 0x0E, 0x11, 0x11, 0x10, 0x0E,
128 0x10, 0x0F, 0x12, 0x14, 0x1A, 0x16, 0x12, 0x13,
129 0x18, 0x13, 0x0F, 0x10, 0x16, 0x1F, 0x17, 0x18,
130 0x1B, 0x1B, 0x1D, 0x1D, 0x1D, 0x11, 0x16, 0x20,
131 0x22, 0x1F, 0x1C, 0x22, 0x1A, 0x1C, 0x1D, 0x1C,
1321,
133 0x05, 0x05, 0x05, 0x07, 0x06, 0x07, 0x0D, 0x07,
134 0x07, 0x0D, 0x1C, 0x12, 0x10, 0x12, 0x1C, 0x1C,
135 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C,
136 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C,
137 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C,
138 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C,
139 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C,
140 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C,
141 },
142/* index 7 - 88 */
143{
144 0xff, 0xd8,
145 0xff, 0xdb, 0x00, 0x84, /* DQT */
1460,
147 0x04, 0x03, 0x03, 0x03, 0x03, 0x02, 0x04, 0x03,
148 0x03, 0x03, 0x04, 0x04, 0x04, 0x05, 0x06, 0x0A,
149 0x06, 0x06, 0x05, 0x05, 0x06, 0x0C, 0x08, 0x09,
150 0x07, 0x0A, 0x0E, 0x0C, 0x0F, 0x0E, 0x0E, 0x0C,
151 0x0D, 0x0D, 0x0F, 0x11, 0x16, 0x13, 0x0F, 0x10,
152 0x15, 0x11, 0x0D, 0x0D, 0x13, 0x1A, 0x13, 0x15,
153 0x17, 0x18, 0x19, 0x19, 0x19, 0x0F, 0x12, 0x1B,
154 0x1D, 0x1B, 0x18, 0x1D, 0x16, 0x18, 0x19, 0x18,
1551,
156 0x04, 0x04, 0x04, 0x06, 0x05, 0x06, 0x0B, 0x06,
157 0x06, 0x0B, 0x18, 0x10, 0x0D, 0x10, 0x18, 0x18,
158 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
159 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
160 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
161 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
162 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
163 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
164},
165/* index 8 - ?? */
166{
167 0xff, 0xd8,
168 0xff, 0xdb, 0x00, 0x84, /* DQT */ 37 0xff, 0xdb, 0x00, 0x84, /* DQT */
1690, 380,
170 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 39#define JPEG_QT0_OFFSET 7
171 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x05, 40 0x10, 0x0b, 0x0c, 0x0e, 0x0c, 0x0a, 0x10, 0x0e,
172 0x03, 0x03, 0x03, 0x03, 0x03, 0x06, 0x04, 0x05, 41 0x0d, 0x0e, 0x12, 0x11, 0x10, 0x13, 0x18, 0x28,
173 0x04, 0x05, 0x07, 0x06, 0x08, 0x08, 0x07, 0x06, 42 0x1a, 0x18, 0x16, 0x16, 0x18, 0x31, 0x23, 0x25,
174 0x07, 0x07, 0x08, 0x09, 0x0C, 0x0A, 0x08, 0x09, 43 0x1d, 0x28, 0x3a, 0x33, 0x3d, 0x3c, 0x39, 0x33,
175 0x0B, 0x09, 0x07, 0x07, 0x0A, 0x0E, 0x0A, 0x0B, 44 0x38, 0x37, 0x40, 0x48, 0x5c, 0x4e, 0x40, 0x44,
176 0x0C, 0x0C, 0x0D, 0x0D, 0x0D, 0x08, 0x0A, 0x0E, 45 0x57, 0x45, 0x37, 0x38, 0x50, 0x6d, 0x51, 0x57,
177 0x0F, 0x0E, 0x0D, 0x0F, 0x0C, 0x0D, 0x0D, 0x0C, 46 0x5f, 0x62, 0x67, 0x68, 0x67, 0x3e, 0x4d, 0x71,
47 0x79, 0x70, 0x64, 0x78, 0x5c, 0x65, 0x67, 0x63,
1781, 481,
179 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x06, 0x03, 49#define JPEG_QT1_OFFSET 72
180 0x03, 0x06, 0x0C, 0x08, 0x07, 0x08, 0x0C, 0x0C, 50 0x11, 0x12, 0x12, 0x18, 0x15, 0x18, 0x2f, 0x1a,
181 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 51 0x1a, 0x2f, 0x63, 0x42, 0x38, 0x42, 0x63, 0x63,
182 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 52 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
183 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 53 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
184 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 54 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
185 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 55 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
186 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C 56 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
187} 57 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
188};
189 58
190/* huffman table + start of SOF0 */ 59/* huffman table */
191static unsigned char huffman[] = {
192 0xff, 0xc4, 0x01, 0xa2, 60 0xff, 0xc4, 0x01, 0xa2,
193 0x00, 0x00, 0x01, 0x05, 0x01, 0x01, 0x01, 0x01, 61 0x00, 0x00, 0x01, 0x05, 0x01, 0x01, 0x01, 0x01,
194 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 62 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -244,58 +112,57 @@ static unsigned char huffman[] = {
244 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 112 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa,
245#ifdef CONEX_CAM 113#ifdef CONEX_CAM
246/* the Conexant frames start with SOF0 */ 114/* the Conexant frames start with SOF0 */
115#define JPEG_HDR_SZ 556
247#else 116#else
248 0xff, 0xc0, 0x00, 0x11, /* SOF0 (start of frame 0 */ 117 0xff, 0xc0, 0x00, 0x11, /* SOF0 (start of frame 0 */
249 0x08, /* data precision */ 118 0x08, /* data precision */
250#endif 119#define JPEG_HEIGHT_OFFSET 561
251}; 120 0x01, 0xe0, /* height */
252 121 0x02, 0x80, /* width */
253#ifndef CONEX_CAM 122 0x03, /* component number */
254/* variable part: 123 0x01,
255 * 0x01, 0xe0, height 124 0x21, /* samples Y */
256 * 0x02, 0x80, width
257 * 0x03, component number
258 * 0x01,
259 * 0x21, samples Y
260 */
261
262/* end of header */
263static unsigned char eoh[] = {
264 0x00, /* quant Y */ 125 0x00, /* quant Y */
265 0x02, 0x11, 0x01, /* samples CbCr - quant CbCr */ 126 0x02, 0x11, 0x01, /* samples CbCr - quant CbCr */
266 0x03, 0x11, 0x01, 127 0x03, 0x11, 0x01,
267 128
268 0xff, 0xda, 0x00, 0x0c, /* SOS (start of scan) */ 129 0xff, 0xda, 0x00, 0x0c, /* SOS (start of scan) */
269 0x03, 0x01, 0x00, 0x02, 0x11, 0x03, 0x11, 0x00, 0x3f, 0x00 130 0x03, 0x01, 0x00, 0x02, 0x11, 0x03, 0x11, 0x00, 0x3f, 0x00
270}; 131#define JPEG_HDR_SZ 589
271#endif 132#endif
133};
272 134
273/* -- output the JPEG header -- */ 135/* define the JPEG header */
274static void jpeg_put_header(struct gspca_dev *gspca_dev, 136static void jpeg_define(u8 *jpeg_hdr,
275 struct gspca_frame *frame, 137 int height,
276 int qindex, 138 int width,
277 int samplesY) 139 int samplesY)
278{ 140{
141 memcpy(jpeg_hdr, jpeg_head, sizeof jpeg_head);
279#ifndef CONEX_CAM 142#ifndef CONEX_CAM
280 unsigned char tmpbuf[8]; 143 jpeg_hdr[JPEG_HEIGHT_OFFSET + 0] = height >> 8;
144 jpeg_hdr[JPEG_HEIGHT_OFFSET + 1] = height & 0xff;
145 jpeg_hdr[JPEG_HEIGHT_OFFSET + 2] = width >> 8;
146 jpeg_hdr[JPEG_HEIGHT_OFFSET + 3] = width & 0xff;
147 jpeg_hdr[JPEG_HEIGHT_OFFSET + 6] = samplesY;
281#endif 148#endif
149}
282 150
283 gspca_frame_add(gspca_dev, FIRST_PACKET, frame, 151/* set the JPEG quality */
284 (unsigned char *) quant[qindex], sizeof quant[0]); 152static void jpeg_set_qual(u8 *jpeg_hdr,
285 gspca_frame_add(gspca_dev, INTER_PACKET, frame, 153 int quality)
286 (unsigned char *) huffman, sizeof huffman); 154{
287#ifndef CONEX_CAM 155 int i, sc;
288 tmpbuf[0] = gspca_dev->height >> 8; 156
289 tmpbuf[1] = gspca_dev->height & 0xff; 157 if (quality < 50)
290 tmpbuf[2] = gspca_dev->width >> 8; 158 sc = 5000 / quality;
291 tmpbuf[3] = gspca_dev->width & 0xff; 159 else
292 tmpbuf[4] = 0x03; /* component number */ 160 sc = 200 - quality * 2;
293 tmpbuf[5] = 0x01; /* first component */ 161 for (i = 0; i < 64; i++) {
294 tmpbuf[6] = samplesY; 162 jpeg_hdr[JPEG_QT0_OFFSET + i] =
295 gspca_frame_add(gspca_dev, INTER_PACKET, frame, 163 (jpeg_head[JPEG_QT0_OFFSET + i] * sc + 50) / 100;
296 tmpbuf, 7); 164 jpeg_hdr[JPEG_QT1_OFFSET + i] =
297 gspca_frame_add(gspca_dev, INTER_PACKET, frame, 165 (jpeg_head[JPEG_QT1_OFFSET + i] * sc + 50) / 100;
298 eoh, sizeof eoh); 166 }
299#endif
300} 167}
301#endif 168#endif
diff --git a/drivers/media/video/gspca/m5602/m5602_core.c b/drivers/media/video/gspca/m5602/m5602_core.c
index ed906fe31287..b35e4838a6e5 100644
--- a/drivers/media/video/gspca/m5602/m5602_core.c
+++ b/drivers/media/video/gspca/m5602/m5602_core.c
@@ -332,7 +332,6 @@ static int m5602_configure(struct gspca_dev *gspca_dev,
332 int err; 332 int err;
333 333
334 cam = &gspca_dev->cam; 334 cam = &gspca_dev->cam;
335 cam->epaddr = M5602_ISOC_ENDPOINT_ADDR;
336 sd->desc = &sd_desc; 335 sd->desc = &sd_desc;
337 336
338 if (dump_bridge) 337 if (dump_bridge)
@@ -374,8 +373,10 @@ static struct usb_driver sd_driver = {
374/* -- module insert / remove -- */ 373/* -- module insert / remove -- */
375static int __init mod_m5602_init(void) 374static int __init mod_m5602_init(void)
376{ 375{
377 if (usb_register(&sd_driver) < 0) 376 int ret;
378 return -1; 377 ret = usb_register(&sd_driver);
378 if (ret < 0)
379 return ret;
379 PDEBUG(D_PROBE, "registered"); 380 PDEBUG(D_PROBE, "registered");
380 return 0; 381 return 0;
381} 382}
diff --git a/drivers/media/video/gspca/mars.c b/drivers/media/video/gspca/mars.c
index 3d2090e67a63..75e8d14e4ac7 100644
--- a/drivers/media/video/gspca/mars.c
+++ b/drivers/media/video/gspca/mars.c
@@ -32,17 +32,91 @@ MODULE_LICENSE("GPL");
32struct sd { 32struct sd {
33 struct gspca_dev gspca_dev; /* !! must be the first item */ 33 struct gspca_dev gspca_dev; /* !! must be the first item */
34 34
35 char qindex; 35 u8 brightness;
36 u8 colors;
37 u8 gamma;
38 u8 sharpness;
39 u8 quality;
40#define QUALITY_MIN 40
41#define QUALITY_MAX 70
42#define QUALITY_DEF 50
43
44 u8 *jpeg_hdr;
36}; 45};
37 46
38/* V4L2 controls supported by the driver */ 47/* V4L2 controls supported by the driver */
48static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
49static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
50static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val);
51static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
52static int sd_setgamma(struct gspca_dev *gspca_dev, __s32 val);
53static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val);
54static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val);
55static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val);
56
39static struct ctrl sd_ctrls[] = { 57static struct ctrl sd_ctrls[] = {
58 {
59 {
60 .id = V4L2_CID_BRIGHTNESS,
61 .type = V4L2_CTRL_TYPE_INTEGER,
62 .name = "Brightness",
63 .minimum = 0,
64 .maximum = 30,
65 .step = 1,
66#define BRIGHTNESS_DEF 15
67 .default_value = BRIGHTNESS_DEF,
68 },
69 .set = sd_setbrightness,
70 .get = sd_getbrightness,
71 },
72 {
73 {
74 .id = V4L2_CID_SATURATION,
75 .type = V4L2_CTRL_TYPE_INTEGER,
76 .name = "Color",
77 .minimum = 1,
78 .maximum = 255,
79 .step = 1,
80#define COLOR_DEF 200
81 .default_value = COLOR_DEF,
82 },
83 .set = sd_setcolors,
84 .get = sd_getcolors,
85 },
86 {
87 {
88 .id = V4L2_CID_GAMMA,
89 .type = V4L2_CTRL_TYPE_INTEGER,
90 .name = "Gamma",
91 .minimum = 0,
92 .maximum = 3,
93 .step = 1,
94#define GAMMA_DEF 1
95 .default_value = GAMMA_DEF,
96 },
97 .set = sd_setgamma,
98 .get = sd_getgamma,
99 },
100 {
101 {
102 .id = V4L2_CID_SHARPNESS,
103 .type = V4L2_CTRL_TYPE_INTEGER,
104 .name = "Sharpness",
105 .minimum = 0,
106 .maximum = 2,
107 .step = 1,
108#define SHARPNESS_DEF 1
109 .default_value = SHARPNESS_DEF,
110 },
111 .set = sd_setsharpness,
112 .get = sd_getsharpness,
113 },
40}; 114};
41 115
42static const struct v4l2_pix_format vga_mode[] = { 116static const struct v4l2_pix_format vga_mode[] = {
43 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, 117 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
44 .bytesperline = 320, 118 .bytesperline = 320,
45 .sizeimage = 320 * 240 * 3 / 8 + 589, 119 .sizeimage = 320 * 240 * 3 / 8 + 590,
46 .colorspace = V4L2_COLORSPACE_JPEG, 120 .colorspace = V4L2_COLORSPACE_JPEG,
47 .priv = 2}, 121 .priv = 2},
48 {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, 122 {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
@@ -52,65 +126,45 @@ static const struct v4l2_pix_format vga_mode[] = {
52 .priv = 1}, 126 .priv = 1},
53}; 127};
54 128
55/* MI Register table //elvis */ 129static const __u8 mi_data[0x20] = {
56enum { 130/* 01 02 03 04 05 06 07 08 */
57 REG_HW_MI_0, 131 0x48, 0x22, 0x01, 0x47, 0x10, 0x00, 0x00, 0x00,
58 REG_HW_MI_1, 132/* 09 0a 0b 0c 0d 0e 0f 10 */
59 REG_HW_MI_2, 133 0x00, 0x01, 0x30, 0x01, 0x30, 0x01, 0x30, 0x01,
60 REG_HW_MI_3, 134/* 11 12 13 14 15 16 17 18 */
61 REG_HW_MI_4, 135 0x30, 0x00, 0x04, 0x00, 0x06, 0x01, 0xe2, 0x02,
62 REG_HW_MI_5, 136/* 19 1a 1b 1c 1d 1e 1f 20 */
63 REG_HW_MI_6, 137 0x82, 0x00, 0x20, 0x17, 0x80, 0x08, 0x0c, 0x00
64 REG_HW_MI_7,
65 REG_HW_MI_9 = 0x09,
66 REG_HW_MI_B = 0x0B,
67 REG_HW_MI_C,
68 REG_HW_MI_D,
69 REG_HW_MI_1E = 0x1E,
70 REG_HW_MI_20 = 0x20,
71 REG_HW_MI_2B = 0x2B,
72 REG_HW_MI_2C,
73 REG_HW_MI_2D,
74 REG_HW_MI_2E,
75 REG_HW_MI_35 = 0x35,
76 REG_HW_MI_5F = 0x5f,
77 REG_HW_MI_60,
78 REG_HW_MI_61,
79 REG_HW_MI_62,
80 REG_HW_MI_63,
81 REG_HW_MI_64,
82 REG_HW_MI_F1 = 0xf1,
83 ATTR_TOTAL_MI_REG = 0xf2
84}; 138};
85 139
86/* the bytes to write are in gspca_dev->usb_buf */ 140/* write <len> bytes from gspca_dev->usb_buf */
87static int reg_w(struct gspca_dev *gspca_dev, 141static int reg_w(struct gspca_dev *gspca_dev,
88 __u16 index, int len) 142 int len)
89{ 143{
90 int rc; 144 int alen, ret;
91 145
92 rc = usb_control_msg(gspca_dev->dev, 146 ret = usb_bulk_msg(gspca_dev->dev,
93 usb_sndbulkpipe(gspca_dev->dev, 4), 147 usb_sndbulkpipe(gspca_dev->dev, 4),
94 0x12, 148 gspca_dev->usb_buf,
95 0xc8, /* ?? */ 149 len,
96 0, /* value */ 150 &alen,
97 index, gspca_dev->usb_buf, len, 500); 151 500); /* timeout in milliseconds */
98 if (rc < 0) 152 if (ret < 0)
99 PDEBUG(D_ERR, "reg write [%02x] error %d", index, rc); 153 PDEBUG(D_ERR, "reg write [%02x] error %d",
100 return rc; 154 gspca_dev->usb_buf[0], ret);
155 return ret;
101} 156}
102 157
103static void bulk_w(struct gspca_dev *gspca_dev, 158static void mi_w(struct gspca_dev *gspca_dev,
104 __u16 *pch, 159 u8 addr,
105 __u16 Address) 160 u8 value)
106{ 161{
107 gspca_dev->usb_buf[0] = 0x1f; 162 gspca_dev->usb_buf[0] = 0x1f;
108 gspca_dev->usb_buf[1] = 0; /* control byte */ 163 gspca_dev->usb_buf[1] = 0; /* control byte */
109 gspca_dev->usb_buf[2] = Address; 164 gspca_dev->usb_buf[2] = addr;
110 gspca_dev->usb_buf[3] = *pch >> 8; /* high byte */ 165 gspca_dev->usb_buf[3] = value;
111 gspca_dev->usb_buf[4] = *pch; /* low byte */
112 166
113 reg_w(gspca_dev, Address, 5); 167 reg_w(gspca_dev, 4);
114} 168}
115 169
116/* this function is called at probe time */ 170/* this function is called at probe time */
@@ -121,10 +175,14 @@ static int sd_config(struct gspca_dev *gspca_dev,
121 struct cam *cam; 175 struct cam *cam;
122 176
123 cam = &gspca_dev->cam; 177 cam = &gspca_dev->cam;
124 cam->epaddr = 0x01;
125 cam->cam_mode = vga_mode; 178 cam->cam_mode = vga_mode;
126 cam->nmodes = ARRAY_SIZE(vga_mode); 179 cam->nmodes = ARRAY_SIZE(vga_mode);
127 sd->qindex = 1; /* set the quantization table */ 180 sd->brightness = BRIGHTNESS_DEF;
181 sd->colors = COLOR_DEF;
182 sd->gamma = GAMMA_DEF;
183 sd->sharpness = SHARPNESS_DEF;
184 sd->quality = QUALITY_DEF;
185 gspca_dev->nbalt = 9; /* use the altsetting 08 */
128 return 0; 186 return 0;
129} 187}
130 188
@@ -136,24 +194,22 @@ static int sd_init(struct gspca_dev *gspca_dev)
136 194
137static int sd_start(struct gspca_dev *gspca_dev) 195static int sd_start(struct gspca_dev *gspca_dev)
138{ 196{
197 struct sd *sd = (struct sd *) gspca_dev;
139 int err_code; 198 int err_code;
140 __u8 *data; 199 u8 *data;
141 __u16 *MI_buf; 200 int i;
142 int h_size, v_size; 201
143 int intpipe; 202 /* create the JPEG header */
144 203 sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL);
145 PDEBUG(D_STREAM, "camera start, iface %d, alt 8", gspca_dev->iface); 204 jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
146 err_code = usb_set_interface(gspca_dev->dev, gspca_dev->iface, 8); 205 0x21); /* JPEG 422 */
147 if (err_code < 0) { 206 jpeg_set_qual(sd->jpeg_hdr, sd->quality);
148 PDEBUG(D_ERR|D_STREAM, "Set packet size: set interface error");
149 return err_code;
150 }
151 207
152 data = gspca_dev->usb_buf; 208 data = gspca_dev->usb_buf;
209
153 data[0] = 0x01; /* address */ 210 data[0] = 0x01; /* address */
154 data[1] = 0x01; 211 data[1] = 0x01;
155 212 err_code = reg_w(gspca_dev, 2);
156 err_code = reg_w(gspca_dev, data[0], 2);
157 if (err_code < 0) 213 if (err_code < 0)
158 return err_code; 214 return err_code;
159 215
@@ -163,30 +219,28 @@ static int sd_start(struct gspca_dev *gspca_dev)
163 data[0] = 0x00; /* address */ 219 data[0] = 0x00; /* address */
164 data[1] = 0x0c | 0x01; /* reg 0 */ 220 data[1] = 0x0c | 0x01; /* reg 0 */
165 data[2] = 0x01; /* reg 1 */ 221 data[2] = 0x01; /* reg 1 */
166 h_size = gspca_dev->width; 222 data[3] = gspca_dev->width / 8; /* h_size , reg 2 */
167 v_size = gspca_dev->height; 223 data[4] = gspca_dev->height / 8; /* v_size , reg 3 */
168 data[3] = h_size / 8; /* h_size , reg 2 */
169 data[4] = v_size / 8; /* v_size , reg 3 */
170 data[5] = 0x30; /* reg 4, MI, PAS5101 : 224 data[5] = 0x30; /* reg 4, MI, PAS5101 :
171 * 0x30 for 24mhz , 0x28 for 12mhz */ 225 * 0x30 for 24mhz , 0x28 for 12mhz */
172 data[6] = 4; /* reg 5, H start */ 226 data[6] = 0x02; /* reg 5, H start - was 0x04 */
173 data[7] = 0xc0; /* reg 6, gamma 1.5 */ 227 data[7] = sd->gamma * 0x40; /* reg 0x06: gamma */
174 data[8] = 3; /* reg 7, V start */ 228 data[8] = 0x01; /* reg 7, V start - was 0x03 */
175/* if (h_size == 320 ) */ 229/* if (h_size == 320 ) */
176/* data[9]= 0x56; * reg 8, 24MHz, 2:1 scale down */ 230/* data[9]= 0x56; * reg 8, 24MHz, 2:1 scale down */
177/* else */ 231/* else */
178 data[9] = 0x52; /* reg 8, 24MHz, no scale down */ 232 data[9] = 0x52; /* reg 8, 24MHz, no scale down */
179 data[10] = 0x5d; /* reg 9, I2C device address 233/*jfm: from win trace*/
180 * [for PAS5101 (0x40)] [for MI (0x5d)] */ 234 data[10] = 0x18;
181 235
182 err_code = reg_w(gspca_dev, data[0], 11); 236 err_code = reg_w(gspca_dev, 11);
183 if (err_code < 0) 237 if (err_code < 0)
184 return err_code; 238 return err_code;
185 239
186 data[0] = 0x23; /* address */ 240 data[0] = 0x23; /* address */
187 data[1] = 0x09; /* reg 35, append frame header */ 241 data[1] = 0x09; /* reg 35, append frame header */
188 242
189 err_code = reg_w(gspca_dev, data[0], 2); 243 err_code = reg_w(gspca_dev, 2);
190 if (err_code < 0) 244 if (err_code < 0)
191 return err_code; 245 return err_code;
192 246
@@ -197,137 +251,57 @@ static int sd_start(struct gspca_dev *gspca_dev)
197/* else */ 251/* else */
198 data[1] = 50; /* 50 reg 60, pc-cam frame size 252 data[1] = 50; /* 50 reg 60, pc-cam frame size
199 * (unit: 4KB) 200KB */ 253 * (unit: 4KB) 200KB */
200 err_code = reg_w(gspca_dev, data[0], 2); 254 err_code = reg_w(gspca_dev, 2);
201 if (err_code < 0) 255 if (err_code < 0)
202 return err_code; 256 return err_code;
203 257
204 if (0) { /* fixed dark-gain */
205 data[1] = 0; /* reg 94, Y Gain (1.75) */
206 data[2] = 0; /* reg 95, UV Gain (1.75) */
207 data[3] = 0x3f; /* reg 96, Y Gain/UV Gain/disable
208 * auto dark-gain */
209 data[4] = 0; /* reg 97, set fixed dark level */
210 data[5] = 0; /* reg 98, don't care */
211 } else { /* auto dark-gain */
212 data[1] = 0; /* reg 94, Y Gain (auto) */
213 data[2] = 0; /* reg 95, UV Gain (1.75) */
214 data[3] = 0x78; /* reg 96, Y Gain/UV Gain/disable
215 * auto dark-gain */
216 switch (gspca_dev->width) {
217/* case 1280: */
218/* data[4] = 154;
219 * reg 97, %3 shadow point (unit: 256 pixel) */
220/* data[5] = 51;
221 * reg 98, %1 highlight point
222 * (uint: 256 pixel) */
223/* break; */
224 default:
225/* case 640: */
226 data[4] = 36; /* reg 97, %3 shadow point
227 * (unit: 256 pixel) */
228 data[5] = 12; /* reg 98, %1 highlight point
229 * (uint: 256 pixel) */
230 break;
231 case 320:
232 data[4] = 9; /* reg 97, %3 shadow point
233 * (unit: 256 pixel) */
234 data[5] = 3; /* reg 98, %1 highlight point
235 * (uint: 256 pixel) */
236 break;
237 }
238 }
239 /* auto dark-gain */ 258 /* auto dark-gain */
240 data[0] = 0x5e; /* address */ 259 data[0] = 0x5e; /* address */
241 260 data[1] = 0; /* reg 94, Y Gain (auto) */
242 err_code = reg_w(gspca_dev, data[0], 6); 261/*jfm: from win trace*/
262 /* reg 0x5f/0x60 (LE) = saturation */
263 /* h (60): xxxx x100
264 * l (5f): xxxx x000 */
265 data[2] = sd->colors << 3;
266 data[3] = ((sd->colors >> 2) & 0xf8) | 0x04;
267 data[4] = sd->brightness; /* reg 0x61 = brightness */
268 data[5] = 0x00;
269
270 err_code = reg_w(gspca_dev, 6);
243 if (err_code < 0) 271 if (err_code < 0)
244 return err_code; 272 return err_code;
245 273
246 data[0] = 0x67; 274 data[0] = 0x67;
247 data[1] = 0x13; /* reg 103, first pixel B, disable sharpness */ 275/*jfm: from win trace*/
248 err_code = reg_w(gspca_dev, data[0], 2); 276 data[1] = sd->sharpness * 4 + 3;
277 data[2] = 0x14;
278 err_code = reg_w(gspca_dev, 3);
249 if (err_code < 0) 279 if (err_code < 0)
250 return err_code; 280 return err_code;
251 281
252 /* 282 data[0] = 0x69;
253 * initialize the value of MI sensor... 283 data[1] = 0x2f;
254 */ 284 data[2] = 0x28;
255 MI_buf = kzalloc(ATTR_TOTAL_MI_REG * sizeof *MI_buf, GFP_KERNEL); 285 data[3] = 0x42;
256 MI_buf[REG_HW_MI_1] = 0x000a; 286 err_code = reg_w(gspca_dev, 4);
257 MI_buf[REG_HW_MI_2] = 0x000c; 287 if (err_code < 0)
258 MI_buf[REG_HW_MI_3] = 0x0405; 288 return err_code;
259 MI_buf[REG_HW_MI_4] = 0x0507; 289
260 /* mi_Attr_Reg_[REG_HW_MI_5] = 0x01ff;//13 */ 290 data[0] = 0x63;
261 MI_buf[REG_HW_MI_5] = 0x0013; /* 13 */ 291 data[1] = 0x07;
262 MI_buf[REG_HW_MI_6] = 0x001f; /* vertical blanking */ 292 err_code = reg_w(gspca_dev, 2);
263 /* mi_Attr_Reg_[REG_HW_MI_6] = 0x0400; // vertical blanking */ 293/*jfm: win trace - many writes here to reg 0x64*/
264 MI_buf[REG_HW_MI_7] = 0x0002; 294 if (err_code < 0)
265 /* mi_Attr_Reg_[REG_HW_MI_9] = 0x015f; */ 295 return err_code;
266 /* mi_Attr_Reg_[REG_HW_MI_9] = 0x030f; */ 296
267 MI_buf[REG_HW_MI_9] = 0x0374; 297 /* initialize the MI sensor */
268 MI_buf[REG_HW_MI_B] = 0x0000; 298 for (i = 0; i < sizeof mi_data; i++)
269 MI_buf[REG_HW_MI_C] = 0x0000; 299 mi_w(gspca_dev, i + 1, mi_data[i]);
270 MI_buf[REG_HW_MI_D] = 0x0000;
271 MI_buf[REG_HW_MI_1E] = 0x8000;
272/* mi_Attr_Reg_[REG_HW_MI_20] = 0x1104; */
273 MI_buf[REG_HW_MI_20] = 0x1104; /* 0x111c; */
274 MI_buf[REG_HW_MI_2B] = 0x0008;
275/* mi_Attr_Reg_[REG_HW_MI_2C] = 0x000f; */
276 MI_buf[REG_HW_MI_2C] = 0x001f; /* lita suggest */
277 MI_buf[REG_HW_MI_2D] = 0x0008;
278 MI_buf[REG_HW_MI_2E] = 0x0008;
279 MI_buf[REG_HW_MI_35] = 0x0051;
280 MI_buf[REG_HW_MI_5F] = 0x0904; /* fail to write */
281 MI_buf[REG_HW_MI_60] = 0x0000;
282 MI_buf[REG_HW_MI_61] = 0x0000;
283 MI_buf[REG_HW_MI_62] = 0x0498;
284 MI_buf[REG_HW_MI_63] = 0x0000;
285 MI_buf[REG_HW_MI_64] = 0x0000;
286 MI_buf[REG_HW_MI_F1] = 0x0001;
287 /* changing while setting up the different value of dx/dy */
288
289 if (gspca_dev->width != 1280) {
290 MI_buf[0x01] = 0x010a;
291 MI_buf[0x02] = 0x014c;
292 MI_buf[0x03] = 0x01e5;
293 MI_buf[0x04] = 0x0287;
294 }
295 MI_buf[0x20] = 0x1104;
296
297 bulk_w(gspca_dev, MI_buf + 1, 1);
298 bulk_w(gspca_dev, MI_buf + 2, 2);
299 bulk_w(gspca_dev, MI_buf + 3, 3);
300 bulk_w(gspca_dev, MI_buf + 4, 4);
301 bulk_w(gspca_dev, MI_buf + 5, 5);
302 bulk_w(gspca_dev, MI_buf + 6, 6);
303 bulk_w(gspca_dev, MI_buf + 7, 7);
304 bulk_w(gspca_dev, MI_buf + 9, 9);
305 bulk_w(gspca_dev, MI_buf + 0x0b, 0x0b);
306 bulk_w(gspca_dev, MI_buf + 0x0c, 0x0c);
307 bulk_w(gspca_dev, MI_buf + 0x0d, 0x0d);
308 bulk_w(gspca_dev, MI_buf + 0x1e, 0x1e);
309 bulk_w(gspca_dev, MI_buf + 0x20, 0x20);
310 bulk_w(gspca_dev, MI_buf + 0x2b, 0x2b);
311 bulk_w(gspca_dev, MI_buf + 0x2c, 0x2c);
312 bulk_w(gspca_dev, MI_buf + 0x2d, 0x2d);
313 bulk_w(gspca_dev, MI_buf + 0x2e, 0x2e);
314 bulk_w(gspca_dev, MI_buf + 0x35, 0x35);
315 bulk_w(gspca_dev, MI_buf + 0x5f, 0x5f);
316 bulk_w(gspca_dev, MI_buf + 0x60, 0x60);
317 bulk_w(gspca_dev, MI_buf + 0x61, 0x61);
318 bulk_w(gspca_dev, MI_buf + 0x62, 0x62);
319 bulk_w(gspca_dev, MI_buf + 0x63, 0x63);
320 bulk_w(gspca_dev, MI_buf + 0x64, 0x64);
321 bulk_w(gspca_dev, MI_buf + 0xf1, 0xf1);
322 kfree(MI_buf);
323
324 intpipe = usb_sndintpipe(gspca_dev->dev, 0);
325 err_code = usb_clear_halt(gspca_dev->dev, intpipe);
326 300
327 data[0] = 0x00; 301 data[0] = 0x00;
328 data[1] = 0x4d; /* ISOC transfering enable... */ 302 data[1] = 0x4d; /* ISOC transfering enable... */
329 reg_w(gspca_dev, data[0], 2); 303 reg_w(gspca_dev, 2);
330 return err_code; 304 return 0;
331} 305}
332 306
333static void sd_stopN(struct gspca_dev *gspca_dev) 307static void sd_stopN(struct gspca_dev *gspca_dev)
@@ -336,11 +310,18 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
336 310
337 gspca_dev->usb_buf[0] = 1; 311 gspca_dev->usb_buf[0] = 1;
338 gspca_dev->usb_buf[1] = 0; 312 gspca_dev->usb_buf[1] = 0;
339 result = reg_w(gspca_dev, gspca_dev->usb_buf[0], 2); 313 result = reg_w(gspca_dev, 2);
340 if (result < 0) 314 if (result < 0)
341 PDEBUG(D_ERR, "Camera Stop failed"); 315 PDEBUG(D_ERR, "Camera Stop failed");
342} 316}
343 317
318static void sd_stop0(struct gspca_dev *gspca_dev)
319{
320 struct sd *sd = (struct sd *) gspca_dev;
321
322 kfree(sd->jpeg_hdr);
323}
324
344static void sd_pkt_scan(struct gspca_dev *gspca_dev, 325static void sd_pkt_scan(struct gspca_dev *gspca_dev,
345 struct gspca_frame *frame, /* target */ 326 struct gspca_frame *frame, /* target */
346 __u8 *data, /* isoc packet */ 327 __u8 *data, /* isoc packet */
@@ -363,16 +344,16 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
363 || data[5 + p] == 0x65 344 || data[5 + p] == 0x65
364 || data[5 + p] == 0x66 345 || data[5 + p] == 0x66
365 || data[5 + p] == 0x67) { 346 || data[5 + p] == 0x67) {
366 PDEBUG(D_PACK, "sof offset: %d leng: %d", 347 PDEBUG(D_PACK, "sof offset: %d len: %d",
367 p, len); 348 p, len);
368 frame = gspca_frame_add(gspca_dev, LAST_PACKET, 349 frame = gspca_frame_add(gspca_dev, LAST_PACKET,
369 frame, data, 0); 350 frame, data, p);
370 351
371 /* put the JPEG header */ 352 /* put the JPEG header */
372 jpeg_put_header(gspca_dev, frame, 353 gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
373 sd->qindex, 0x21); 354 sd->jpeg_hdr, JPEG_HDR_SZ);
374 data += 16; 355 data += p + 16;
375 len -= 16; 356 len -= p + 16;
376 break; 357 break;
377 } 358 }
378 } 359 }
@@ -380,6 +361,121 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
380 gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len); 361 gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
381} 362}
382 363
364static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
365{
366 struct sd *sd = (struct sd *) gspca_dev;
367
368 sd->brightness = val;
369 if (gspca_dev->streaming) {
370 gspca_dev->usb_buf[0] = 0x61;
371 gspca_dev->usb_buf[1] = val;
372 reg_w(gspca_dev, 2);
373 }
374 return 0;
375}
376
377static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
378{
379 struct sd *sd = (struct sd *) gspca_dev;
380
381 *val = sd->brightness;
382 return 0;
383}
384
385static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
386{
387 struct sd *sd = (struct sd *) gspca_dev;
388
389 sd->colors = val;
390 if (gspca_dev->streaming) {
391
392 /* see sd_start */
393 gspca_dev->usb_buf[0] = 0x5f;
394 gspca_dev->usb_buf[1] = sd->colors << 3;
395 gspca_dev->usb_buf[2] = ((sd->colors >> 2) & 0xf8) | 0x04;
396 reg_w(gspca_dev, 3);
397 }
398 return 0;
399}
400
401static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
402{
403 struct sd *sd = (struct sd *) gspca_dev;
404
405 *val = sd->colors;
406 return 0;
407}
408
409static int sd_setgamma(struct gspca_dev *gspca_dev, __s32 val)
410{
411 struct sd *sd = (struct sd *) gspca_dev;
412
413 sd->gamma = val;
414 if (gspca_dev->streaming) {
415 gspca_dev->usb_buf[0] = 0x06;
416 gspca_dev->usb_buf[1] = val * 0x40;
417 reg_w(gspca_dev, 2);
418 }
419 return 0;
420}
421
422static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val)
423{
424 struct sd *sd = (struct sd *) gspca_dev;
425
426 *val = sd->gamma;
427 return 0;
428}
429
430static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val)
431{
432 struct sd *sd = (struct sd *) gspca_dev;
433
434 sd->sharpness = val;
435 if (gspca_dev->streaming) {
436 gspca_dev->usb_buf[0] = 0x67;
437 gspca_dev->usb_buf[1] = val * 4 + 3;
438 reg_w(gspca_dev, 2);
439 }
440 return 0;
441}
442
443static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val)
444{
445 struct sd *sd = (struct sd *) gspca_dev;
446
447 *val = sd->sharpness;
448 return 0;
449}
450
451static int sd_set_jcomp(struct gspca_dev *gspca_dev,
452 struct v4l2_jpegcompression *jcomp)
453{
454 struct sd *sd = (struct sd *) gspca_dev;
455
456 if (jcomp->quality < QUALITY_MIN)
457 sd->quality = QUALITY_MIN;
458 else if (jcomp->quality > QUALITY_MAX)
459 sd->quality = QUALITY_MAX;
460 else
461 sd->quality = jcomp->quality;
462 if (gspca_dev->streaming)
463 jpeg_set_qual(sd->jpeg_hdr, sd->quality);
464 return 0;
465}
466
467static int sd_get_jcomp(struct gspca_dev *gspca_dev,
468 struct v4l2_jpegcompression *jcomp)
469{
470 struct sd *sd = (struct sd *) gspca_dev;
471
472 memset(jcomp, 0, sizeof *jcomp);
473 jcomp->quality = sd->quality;
474 jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT
475 | V4L2_JPEG_MARKER_DQT;
476 return 0;
477}
478
383/* sub-driver description */ 479/* sub-driver description */
384static const struct sd_desc sd_desc = { 480static const struct sd_desc sd_desc = {
385 .name = MODULE_NAME, 481 .name = MODULE_NAME,
@@ -389,7 +485,10 @@ static const struct sd_desc sd_desc = {
389 .init = sd_init, 485 .init = sd_init,
390 .start = sd_start, 486 .start = sd_start,
391 .stopN = sd_stopN, 487 .stopN = sd_stopN,
488 .stop0 = sd_stop0,
392 .pkt_scan = sd_pkt_scan, 489 .pkt_scan = sd_pkt_scan,
490 .get_jcomp = sd_get_jcomp,
491 .set_jcomp = sd_set_jcomp,
393}; 492};
394 493
395/* -- module initialisation -- */ 494/* -- module initialisation -- */
@@ -421,8 +520,11 @@ static struct usb_driver sd_driver = {
421/* -- module insert / remove -- */ 520/* -- module insert / remove -- */
422static int __init sd_mod_init(void) 521static int __init sd_mod_init(void)
423{ 522{
424 if (usb_register(&sd_driver) < 0) 523 int ret;
425 return -1; 524
525 ret = usb_register(&sd_driver);
526 if (ret < 0)
527 return ret;
426 PDEBUG(D_PROBE, "registered"); 528 PDEBUG(D_PROBE, "registered");
427 return 0; 529 return 0;
428} 530}
diff --git a/drivers/media/video/gspca/mr97310a.c b/drivers/media/video/gspca/mr97310a.c
new file mode 100644
index 000000000000..2a901a4a6f00
--- /dev/null
+++ b/drivers/media/video/gspca/mr97310a.c
@@ -0,0 +1,362 @@
1/*
2 * Mars MR97310A library
3 *
4 * Copyright (C) 2009 Kyle Guinn <elyk03@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#define MODULE_NAME "mr97310a"
22
23#include "gspca.h"
24
25MODULE_AUTHOR("Kyle Guinn <elyk03@gmail.com>");
26MODULE_DESCRIPTION("GSPCA/Mars-Semi MR97310A USB Camera Driver");
27MODULE_LICENSE("GPL");
28
29/* specific webcam descriptor */
30struct sd {
31 struct gspca_dev gspca_dev; /* !! must be the first item */
32 u8 sof_read;
33};
34
35/* V4L2 controls supported by the driver */
36static struct ctrl sd_ctrls[] = {
37};
38
39static const struct v4l2_pix_format vga_mode[] = {
40 {160, 120, V4L2_PIX_FMT_MR97310A, V4L2_FIELD_NONE,
41 .bytesperline = 160,
42 .sizeimage = 160 * 120,
43 .colorspace = V4L2_COLORSPACE_SRGB,
44 .priv = 4},
45 {176, 144, V4L2_PIX_FMT_MR97310A, V4L2_FIELD_NONE,
46 .bytesperline = 176,
47 .sizeimage = 176 * 144,
48 .colorspace = V4L2_COLORSPACE_SRGB,
49 .priv = 3},
50 {320, 240, V4L2_PIX_FMT_MR97310A, V4L2_FIELD_NONE,
51 .bytesperline = 320,
52 .sizeimage = 320 * 240,
53 .colorspace = V4L2_COLORSPACE_SRGB,
54 .priv = 2},
55 {352, 288, V4L2_PIX_FMT_MR97310A, V4L2_FIELD_NONE,
56 .bytesperline = 352,
57 .sizeimage = 352 * 288,
58 .colorspace = V4L2_COLORSPACE_SRGB,
59 .priv = 1},
60 {640, 480, V4L2_PIX_FMT_MR97310A, V4L2_FIELD_NONE,
61 .bytesperline = 640,
62 .sizeimage = 640 * 480,
63 .colorspace = V4L2_COLORSPACE_SRGB,
64 .priv = 0},
65};
66
67/* the bytes to write are in gspca_dev->usb_buf */
68static int reg_w(struct gspca_dev *gspca_dev, int len)
69{
70 int rc;
71
72 rc = usb_bulk_msg(gspca_dev->dev,
73 usb_sndbulkpipe(gspca_dev->dev, 4),
74 gspca_dev->usb_buf, len, NULL, 500);
75 if (rc < 0)
76 PDEBUG(D_ERR, "reg write [%02x] error %d",
77 gspca_dev->usb_buf[0], rc);
78 return rc;
79}
80
81/* this function is called at probe time */
82static int sd_config(struct gspca_dev *gspca_dev,
83 const struct usb_device_id *id)
84{
85 struct cam *cam;
86
87 cam = &gspca_dev->cam;
88 cam->cam_mode = vga_mode;
89 cam->nmodes = ARRAY_SIZE(vga_mode);
90 return 0;
91}
92
93/* this function is called at probe and resume time */
94static int sd_init(struct gspca_dev *gspca_dev)
95{
96 return 0;
97}
98
99static int sd_start(struct gspca_dev *gspca_dev)
100{
101 struct sd *sd = (struct sd *) gspca_dev;
102 __u8 *data = gspca_dev->usb_buf;
103 int err_code;
104
105 sd->sof_read = 0;
106
107 /* Note: register descriptions guessed from MR97113A driver */
108
109 data[0] = 0x01;
110 data[1] = 0x01;
111 err_code = reg_w(gspca_dev, 2);
112 if (err_code < 0)
113 return err_code;
114
115 data[0] = 0x00;
116 data[1] = 0x0d;
117 data[2] = 0x01;
118 data[5] = 0x2b;
119 data[7] = 0x00;
120 data[9] = 0x50; /* reg 8, no scale down */
121 data[10] = 0xc0;
122
123 switch (gspca_dev->width) {
124 case 160:
125 data[9] |= 0x0c; /* reg 8, 4:1 scale down */
126 /* fall thru */
127 case 320:
128 data[9] |= 0x04; /* reg 8, 2:1 scale down */
129 /* fall thru */
130 case 640:
131 default:
132 data[3] = 0x50; /* reg 2, H size */
133 data[4] = 0x78; /* reg 3, V size */
134 data[6] = 0x04; /* reg 5, H start */
135 data[8] = 0x03; /* reg 7, V start */
136 break;
137
138 case 176:
139 data[9] |= 0x04; /* reg 8, 2:1 scale down */
140 /* fall thru */
141 case 352:
142 data[3] = 0x2c; /* reg 2, H size */
143 data[4] = 0x48; /* reg 3, V size */
144 data[6] = 0x94; /* reg 5, H start */
145 data[8] = 0x63; /* reg 7, V start */
146 break;
147 }
148
149 err_code = reg_w(gspca_dev, 11);
150 if (err_code < 0)
151 return err_code;
152
153 data[0] = 0x0a;
154 data[1] = 0x80;
155 err_code = reg_w(gspca_dev, 2);
156 if (err_code < 0)
157 return err_code;
158
159 data[0] = 0x14;
160 data[1] = 0x0a;
161 err_code = reg_w(gspca_dev, 2);
162 if (err_code < 0)
163 return err_code;
164
165 data[0] = 0x1b;
166 data[1] = 0x00;
167 err_code = reg_w(gspca_dev, 2);
168 if (err_code < 0)
169 return err_code;
170
171 data[0] = 0x15;
172 data[1] = 0x16;
173 err_code = reg_w(gspca_dev, 2);
174 if (err_code < 0)
175 return err_code;
176
177 data[0] = 0x16;
178 data[1] = 0x10;
179 err_code = reg_w(gspca_dev, 2);
180 if (err_code < 0)
181 return err_code;
182
183 data[0] = 0x17;
184 data[1] = 0x3a;
185 err_code = reg_w(gspca_dev, 2);
186 if (err_code < 0)
187 return err_code;
188
189 data[0] = 0x18;
190 data[1] = 0x68;
191 err_code = reg_w(gspca_dev, 2);
192 if (err_code < 0)
193 return err_code;
194
195 data[0] = 0x1f;
196 data[1] = 0x00;
197 data[2] = 0x02;
198 data[3] = 0x06;
199 data[4] = 0x59;
200 data[5] = 0x0c;
201 data[6] = 0x16;
202 data[7] = 0x00;
203 data[8] = 0x07;
204 data[9] = 0x00;
205 data[10] = 0x01;
206 err_code = reg_w(gspca_dev, 11);
207 if (err_code < 0)
208 return err_code;
209
210 data[0] = 0x1f;
211 data[1] = 0x04;
212 data[2] = 0x11;
213 data[3] = 0x01;
214 err_code = reg_w(gspca_dev, 4);
215 if (err_code < 0)
216 return err_code;
217
218 data[0] = 0x1f;
219 data[1] = 0x00;
220 data[2] = 0x0a;
221 data[3] = 0x00;
222 data[4] = 0x01;
223 data[5] = 0x00;
224 data[6] = 0x00;
225 data[7] = 0x01;
226 data[8] = 0x00;
227 data[9] = 0x0a;
228 err_code = reg_w(gspca_dev, 10);
229 if (err_code < 0)
230 return err_code;
231
232 data[0] = 0x1f;
233 data[1] = 0x04;
234 data[2] = 0x11;
235 data[3] = 0x01;
236 err_code = reg_w(gspca_dev, 4);
237 if (err_code < 0)
238 return err_code;
239
240 data[0] = 0x1f;
241 data[1] = 0x00;
242 data[2] = 0x12;
243 data[3] = 0x00;
244 data[4] = 0x63;
245 data[5] = 0x00;
246 data[6] = 0x70;
247 data[7] = 0x00;
248 data[8] = 0x00;
249 err_code = reg_w(gspca_dev, 9);
250 if (err_code < 0)
251 return err_code;
252
253 data[0] = 0x1f;
254 data[1] = 0x04;
255 data[2] = 0x11;
256 data[3] = 0x01;
257 err_code = reg_w(gspca_dev, 4);
258 if (err_code < 0)
259 return err_code;
260
261 data[0] = 0x00;
262 data[1] = 0x4d; /* ISOC transfering enable... */
263 err_code = reg_w(gspca_dev, 2);
264 return err_code;
265}
266
267static void sd_stopN(struct gspca_dev *gspca_dev)
268{
269 int result;
270
271 gspca_dev->usb_buf[0] = 1;
272 gspca_dev->usb_buf[1] = 0;
273 result = reg_w(gspca_dev, 2);
274 if (result < 0)
275 PDEBUG(D_ERR, "Camera Stop failed");
276}
277
278/* Include pac common sof detection functions */
279#include "pac_common.h"
280
281static void sd_pkt_scan(struct gspca_dev *gspca_dev,
282 struct gspca_frame *frame, /* target */
283 __u8 *data, /* isoc packet */
284 int len) /* iso packet length */
285{
286 unsigned char *sof;
287
288 sof = pac_find_sof(gspca_dev, data, len);
289 if (sof) {
290 int n;
291
292 /* finish decoding current frame */
293 n = sof - data;
294 if (n > sizeof pac_sof_marker)
295 n -= sizeof pac_sof_marker;
296 else
297 n = 0;
298 frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame,
299 data, n);
300 /* Start next frame. */
301 gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
302 pac_sof_marker, sizeof pac_sof_marker);
303 len -= sof - data;
304 data = sof;
305 }
306 gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
307}
308
309/* sub-driver description */
310static const struct sd_desc sd_desc = {
311 .name = MODULE_NAME,
312 .ctrls = sd_ctrls,
313 .nctrls = ARRAY_SIZE(sd_ctrls),
314 .config = sd_config,
315 .init = sd_init,
316 .start = sd_start,
317 .stopN = sd_stopN,
318 .pkt_scan = sd_pkt_scan,
319};
320
321/* -- module initialisation -- */
322static const __devinitdata struct usb_device_id device_table[] = {
323 {USB_DEVICE(0x08ca, 0x0111)},
324 {}
325};
326MODULE_DEVICE_TABLE(usb, device_table);
327
328/* -- device connect -- */
329static int sd_probe(struct usb_interface *intf,
330 const struct usb_device_id *id)
331{
332 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
333 THIS_MODULE);
334}
335
336static struct usb_driver sd_driver = {
337 .name = MODULE_NAME,
338 .id_table = device_table,
339 .probe = sd_probe,
340 .disconnect = gspca_disconnect,
341#ifdef CONFIG_PM
342 .suspend = gspca_suspend,
343 .resume = gspca_resume,
344#endif
345};
346
347/* -- module insert / remove -- */
348static int __init sd_mod_init(void)
349{
350 if (usb_register(&sd_driver) < 0)
351 return -1;
352 PDEBUG(D_PROBE, "registered");
353 return 0;
354}
355static void __exit sd_mod_exit(void)
356{
357 usb_deregister(&sd_driver);
358 PDEBUG(D_PROBE, "deregistered");
359}
360
361module_init(sd_mod_init);
362module_exit(sd_mod_exit);
diff --git a/drivers/media/video/gspca/ov519.c b/drivers/media/video/gspca/ov519.c
index ee232956c812..1fff37b79891 100644
--- a/drivers/media/video/gspca/ov519.c
+++ b/drivers/media/video/gspca/ov519.c
@@ -1360,7 +1360,6 @@ static int sd_config(struct gspca_dev *gspca_dev,
1360 } 1360 }
1361 1361
1362 cam = &gspca_dev->cam; 1362 cam = &gspca_dev->cam;
1363 cam->epaddr = OV511_ENDPOINT_ADDRESS;
1364 if (!sd->sif) { 1363 if (!sd->sif) {
1365 cam->cam_mode = vga_mode; 1364 cam->cam_mode = vga_mode;
1366 cam->nmodes = ARRAY_SIZE(vga_mode); 1365 cam->nmodes = ARRAY_SIZE(vga_mode);
@@ -2177,8 +2176,10 @@ static struct usb_driver sd_driver = {
2177/* -- module insert / remove -- */ 2176/* -- module insert / remove -- */
2178static int __init sd_mod_init(void) 2177static int __init sd_mod_init(void)
2179{ 2178{
2180 if (usb_register(&sd_driver) < 0) 2179 int ret;
2181 return -1; 2180 ret = usb_register(&sd_driver);
2181 if (ret < 0)
2182 return ret;
2182 PDEBUG(D_PROBE, "registered"); 2183 PDEBUG(D_PROBE, "registered");
2183 return 0; 2184 return 0;
2184} 2185}
diff --git a/drivers/media/video/gspca/ov534.c b/drivers/media/video/gspca/ov534.c
index 3bf15e401693..19e0bc60de14 100644
--- a/drivers/media/video/gspca/ov534.c
+++ b/drivers/media/video/gspca/ov534.c
@@ -1,7 +1,8 @@
1/* 1/*
2 * ov534/ov772x gspca driver 2 * ov534 gspca driver
3 * Copyright (C) 2008 Antonio Ospite <ospite@studenti.unina.it> 3 * Copyright (C) 2008 Antonio Ospite <ospite@studenti.unina.it>
4 * Copyright (C) 2008 Jim Paris <jim@jtan.com> 4 * Copyright (C) 2008 Jim Paris <jim@jtan.com>
5 * Copyright (C) 2009 Jean-Francois Moine http://moinejf.free.fr
5 * 6 *
6 * Based on a prototype written by Mark Ferrell <majortrips@gmail.com> 7 * Based on a prototype written by Mark Ferrell <majortrips@gmail.com>
7 * USB protocol reverse engineered by Jim Paris <jim@jtan.com> 8 * USB protocol reverse engineered by Jim Paris <jim@jtan.com>
@@ -26,7 +27,7 @@
26 27
27#include "gspca.h" 28#include "gspca.h"
28 29
29#define OV534_REG_ADDRESS 0xf1 /* ? */ 30#define OV534_REG_ADDRESS 0xf1 /* sensor address */
30#define OV534_REG_SUBADDR 0xf2 31#define OV534_REG_SUBADDR 0xf2
31#define OV534_REG_WRITE 0xf3 32#define OV534_REG_WRITE 0xf3
32#define OV534_REG_READ 0xf4 33#define OV534_REG_READ 0xf4
@@ -46,9 +47,13 @@ MODULE_LICENSE("GPL");
46/* specific webcam descriptor */ 47/* specific webcam descriptor */
47struct sd { 48struct sd {
48 struct gspca_dev gspca_dev; /* !! must be the first item */ 49 struct gspca_dev gspca_dev; /* !! must be the first item */
49 __u32 last_fid;
50 __u32 last_pts; 50 __u32 last_pts;
51 int frame_rate; 51 u16 last_fid;
52 u8 frame_rate;
53
54 u8 sensor;
55#define SENSOR_OV772X 0
56#define SENSOR_OV965X 1
52}; 57};
53 58
54/* V4L2 controls supported by the driver */ 59/* V4L2 controls supported by the driver */
@@ -63,114 +68,7 @@ static const struct v4l2_pix_format vga_mode[] = {
63 .priv = 0}, 68 .priv = 0},
64}; 69};
65 70
66static void ov534_reg_write(struct gspca_dev *gspca_dev, u16 reg, u8 val) 71static const u8 bridge_init_ov722x[][2] = {
67{
68 struct usb_device *udev = gspca_dev->dev;
69 int ret;
70
71 PDEBUG(D_USBO, "reg=0x%04x, val=0%02x", reg, val);
72 gspca_dev->usb_buf[0] = val;
73 ret = usb_control_msg(udev,
74 usb_sndctrlpipe(udev, 0),
75 0x1,
76 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
77 0x0, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT);
78 if (ret < 0)
79 PDEBUG(D_ERR, "write failed");
80}
81
82static u8 ov534_reg_read(struct gspca_dev *gspca_dev, u16 reg)
83{
84 struct usb_device *udev = gspca_dev->dev;
85 int ret;
86
87 ret = usb_control_msg(udev,
88 usb_rcvctrlpipe(udev, 0),
89 0x1,
90 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
91 0x0, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT);
92 PDEBUG(D_USBI, "reg=0x%04x, data=0x%02x", reg, gspca_dev->usb_buf[0]);
93 if (ret < 0)
94 PDEBUG(D_ERR, "read failed");
95 return gspca_dev->usb_buf[0];
96}
97
98/* Two bits control LED: 0x21 bit 7 and 0x23 bit 7.
99 * (direction and output)? */
100static void ov534_set_led(struct gspca_dev *gspca_dev, int status)
101{
102 u8 data;
103
104 PDEBUG(D_CONF, "led status: %d", status);
105
106 data = ov534_reg_read(gspca_dev, 0x21);
107 data |= 0x80;
108 ov534_reg_write(gspca_dev, 0x21, data);
109
110 data = ov534_reg_read(gspca_dev, 0x23);
111 if (status)
112 data |= 0x80;
113 else
114 data &= ~(0x80);
115
116 ov534_reg_write(gspca_dev, 0x23, data);
117}
118
119static int sccb_check_status(struct gspca_dev *gspca_dev)
120{
121 u8 data;
122 int i;
123
124 for (i = 0; i < 5; i++) {
125 data = ov534_reg_read(gspca_dev, OV534_REG_STATUS);
126
127 switch (data) {
128 case 0x00:
129 return 1;
130 case 0x04:
131 return 0;
132 case 0x03:
133 break;
134 default:
135 PDEBUG(D_ERR, "sccb status 0x%02x, attempt %d/5",
136 data, i + 1);
137 }
138 }
139 return 0;
140}
141
142static void sccb_reg_write(struct gspca_dev *gspca_dev, u16 reg, u8 val)
143{
144 PDEBUG(D_USBO, "reg: 0x%04x, val: 0x%02x", reg, val);
145 ov534_reg_write(gspca_dev, OV534_REG_SUBADDR, reg);
146 ov534_reg_write(gspca_dev, OV534_REG_WRITE, val);
147 ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_3);
148
149 if (!sccb_check_status(gspca_dev))
150 PDEBUG(D_ERR, "sccb_reg_write failed");
151}
152
153#ifdef GSPCA_DEBUG
154static u8 sccb_reg_read(struct gspca_dev *gspca_dev, u16 reg)
155{
156 ov534_reg_write(gspca_dev, OV534_REG_SUBADDR, reg);
157 ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_2);
158 if (!sccb_check_status(gspca_dev))
159 PDEBUG(D_ERR, "sccb_reg_read failed 1");
160
161 ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_READ_2);
162 if (!sccb_check_status(gspca_dev))
163 PDEBUG(D_ERR, "sccb_reg_read failed 2");
164
165 return ov534_reg_read(gspca_dev, OV534_REG_READ);
166}
167#endif
168
169static const __u8 ov534_reg_initdata[][2] = {
170 { 0xe7, 0x3a },
171
172 { OV534_REG_ADDRESS, 0x42 }, /* select OV772x sensor */
173
174 { 0xc2, 0x0c }, 72 { 0xc2, 0x0c },
175 { 0x88, 0xf8 }, 73 { 0x88, 0xf8 },
176 { 0xc3, 0x69 }, 74 { 0xc3, 0x69 },
@@ -228,7 +126,7 @@ static const __u8 ov534_reg_initdata[][2] = {
228 { 0xc2, 0x0c }, 126 { 0xc2, 0x0c },
229}; 127};
230 128
231static const __u8 ov772x_reg_initdata[][2] = { 129static const u8 sensor_init_ov722x[][2] = {
232 { 0x12, 0x80 }, 130 { 0x12, 0x80 },
233 { 0x11, 0x01 }, 131 { 0x11, 0x01 },
234 132
@@ -311,6 +209,456 @@ static const __u8 ov772x_reg_initdata[][2] = {
311 { 0x0c, 0xd0 } 209 { 0x0c, 0xd0 }
312}; 210};
313 211
212static const u8 bridge_init_ov965x[][2] = {
213 {0x88, 0xf8},
214 {0x89, 0xff},
215 {0x76, 0x03},
216 {0x92, 0x03},
217 {0x95, 0x10},
218 {0xe2, 0x00},
219 {0xe7, 0x3e},
220 {0x8d, 0x1c},
221 {0x8e, 0x00},
222 {0x8f, 0x00},
223 {0x1f, 0x00},
224 {0xc3, 0xf9},
225 {0x89, 0xff},
226 {0x88, 0xf8},
227 {0x76, 0x03},
228 {0x92, 0x01},
229 {0x93, 0x18},
230 {0x1c, 0x0a},
231 {0x1d, 0x48},
232 {0xc0, 0x50},
233 {0xc1, 0x3c},
234 {0x34, 0x05},
235 {0xc2, 0x0c},
236 {0xc3, 0xf9},
237 {0x34, 0x05},
238 {0xe7, 0x2e},
239 {0x31, 0xf9},
240 {0x35, 0x02},
241 {0xd9, 0x10},
242 {0x25, 0x42},
243 {0x94, 0x11},
244};
245
246static const u8 sensor_init_ov965x[][2] = {
247 {0x12, 0x80}, /* com7 - reset */
248 {0x00, 0x00}, /* gain */
249 {0x01, 0x80}, /* blue */
250 {0x02, 0x80}, /* red */
251 {0x03, 0x1b}, /* vref */
252 {0x04, 0x03}, /* com1 - exposure low bits */
253 {0x0b, 0x57}, /* ver */
254 {0x0e, 0x61}, /* com5 */
255 {0x0f, 0x42}, /* com6 */
256 {0x11, 0x00}, /* clkrc */
257 {0x12, 0x02}, /* com7 */
258 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
259 {0x14, 0x28}, /* com9 */
260 {0x16, 0x24}, /* rsvd16 */
261 {0x17, 0x1d}, /* hstart*/
262 {0x18, 0xbd}, /* hstop */
263 {0x19, 0x01}, /* vstrt */
264 {0x1a, 0x81}, /* vstop*/
265 {0x1e, 0x04}, /* mvfp */
266 {0x24, 0x3c}, /* aew */
267 {0x25, 0x36}, /* aeb */
268 {0x26, 0x71}, /* vpt */
269 {0x27, 0x08}, /* bbias */
270 {0x28, 0x08}, /* gbbias */
271 {0x29, 0x15}, /* gr com */
272 {0x2a, 0x00},
273 {0x2b, 0x00},
274 {0x2c, 0x08}, /* rbias */
275 {0x32, 0xff}, /* href */
276 {0x33, 0x00}, /* chlf */
277 {0x34, 0x3f}, /* arblm */
278 {0x35, 0x00}, /* rsvd35 */
279 {0x36, 0xf8}, /* rsvd36 */
280 {0x38, 0x72}, /* acom38 */
281 {0x39, 0x57}, /* ofon */
282 {0x3a, 0x80}, /* tslb */
283 {0x3b, 0xc4},
284 {0x3d, 0x99}, /* com13 */
285 {0x3f, 0xc1},
286 {0x40, 0xc0}, /* com15 */
287 {0x41, 0x40}, /* com16 */
288 {0x42, 0xc0},
289 {0x43, 0x0a},
290 {0x44, 0xf0},
291 {0x45, 0x46},
292 {0x46, 0x62},
293 {0x47, 0x2a},
294 {0x48, 0x3c},
295 {0x4a, 0xfc},
296 {0x4b, 0xfc},
297 {0x4c, 0x7f},
298 {0x4d, 0x7f},
299 {0x4e, 0x7f},
300 {0x4f, 0x98},
301 {0x50, 0x98},
302 {0x51, 0x00},
303 {0x52, 0x28},
304 {0x53, 0x70},
305 {0x54, 0x98},
306 {0x58, 0x1a},
307 {0x59, 0x85},
308 {0x5a, 0xa9},
309 {0x5b, 0x64},
310 {0x5c, 0x84},
311 {0x5d, 0x53},
312 {0x5e, 0x0e},
313 {0x5f, 0xf0},
314 {0x60, 0xf0},
315 {0x61, 0xf0},
316 {0x62, 0x00}, /* lcc1 */
317 {0x63, 0x00}, /* lcc2 */
318 {0x64, 0x02}, /* lcc3 */
319 {0x65, 0x16}, /* lcc4 */
320 {0x66, 0x01}, /* lcc5 */
321 {0x69, 0x02}, /* hv */
322 {0x6b, 0x5a}, /* dbvl */
323 {0x6c, 0x04},
324 {0x6d, 0x55},
325 {0x6e, 0x00},
326 {0x6f, 0x9d},
327 {0x70, 0x21},
328 {0x71, 0x78},
329 {0x72, 0x00},
330 {0x73, 0x01},
331 {0x74, 0x3a},
332 {0x75, 0x35},
333 {0x76, 0x01},
334 {0x77, 0x02},
335 {0x7a, 0x12},
336 {0x7b, 0x08},
337 {0x7c, 0x16},
338 {0x7d, 0x30},
339 {0x7e, 0x5e},
340 {0x7f, 0x72},
341 {0x80, 0x82},
342 {0x81, 0x8e},
343 {0x82, 0x9a},
344 {0x83, 0xa4},
345 {0x84, 0xac},
346 {0x85, 0xb8},
347 {0x86, 0xc3},
348 {0x87, 0xd6},
349 {0x88, 0xe6},
350 {0x89, 0xf2},
351 {0x8a, 0x03},
352 {0x8c, 0x89},
353 {0x14, 0x28}, /* com9 */
354 {0x90, 0x7d},
355 {0x91, 0x7b},
356 {0x9d, 0x03},
357 {0x9e, 0x04},
358 {0x9f, 0x7a},
359 {0xa0, 0x79},
360 {0xa1, 0x40}, /* aechm */
361 {0xa4, 0x50},
362 {0xa5, 0x68}, /* com26 */
363 {0xa6, 0x4a},
364 {0xa8, 0xc1}, /* acoma8 */
365 {0xa9, 0xef}, /* acoma9 */
366 {0xaa, 0x92},
367 {0xab, 0x04},
368 {0xac, 0x80},
369 {0xad, 0x80},
370 {0xae, 0x80},
371 {0xaf, 0x80},
372 {0xb2, 0xf2},
373 {0xb3, 0x20},
374 {0xb4, 0x20},
375 {0xb5, 0x00},
376 {0xb6, 0xaf},
377 {0xbb, 0xae},
378 {0xbc, 0x7f},
379 {0xdb, 0x7f},
380 {0xbe, 0x7f},
381 {0xbf, 0x7f},
382 {0xc0, 0xe2},
383 {0xc1, 0xc0},
384 {0xc2, 0x01},
385 {0xc3, 0x4e},
386 {0xc6, 0x85},
387 {0xc7, 0x80},
388 {0xc9, 0xe0},
389 {0xca, 0xe8},
390 {0xcb, 0xf0},
391 {0xcc, 0xd8},
392 {0xcd, 0xf1},
393 {0x4f, 0x98},
394 {0x50, 0x98},
395 {0x51, 0x00},
396 {0x52, 0x28},
397 {0x53, 0x70},
398 {0x54, 0x98},
399 {0x58, 0x1a},
400 {0xff, 0x41}, /* read 41, write ff 00 */
401 {0x41, 0x40}, /* com16 */
402 {0xc5, 0x03},
403 {0x6a, 0x02},
404
405 {0x12, 0x62}, /* com7 - VGA + CIF */
406 {0x36, 0xfa}, /* rsvd36 */
407 {0x69, 0x0a}, /* hv */
408 {0x8c, 0x89}, /* com22 */
409 {0x14, 0x28}, /* com9 */
410 {0x3e, 0x0c},
411 {0x41, 0x40}, /* com16 */
412 {0x72, 0x00},
413 {0x73, 0x00},
414 {0x74, 0x3a},
415 {0x75, 0x35},
416 {0x76, 0x01},
417 {0xc7, 0x80},
418 {0x03, 0x12}, /* vref */
419 {0x17, 0x16}, /* hstart */
420 {0x18, 0x02}, /* hstop */
421 {0x19, 0x01}, /* vstrt */
422 {0x1a, 0x3d}, /* vstop */
423 {0x32, 0xff}, /* href */
424 {0xc0, 0xaa},
425};
426
427static const u8 bridge_init_ov965x_2[][2] = {
428 {0x94, 0xaa},
429 {0xf1, 0x60},
430 {0xe5, 0x04},
431 {0xc0, 0x50},
432 {0xc1, 0x3c},
433 {0x8c, 0x00},
434 {0x8d, 0x1c},
435 {0x34, 0x05},
436
437 {0xc2, 0x0c},
438 {0xc3, 0xf9},
439 {0xda, 0x01},
440 {0x50, 0x00},
441 {0x51, 0xa0},
442 {0x52, 0x3c},
443 {0x53, 0x00},
444 {0x54, 0x00},
445 {0x55, 0x00},
446 {0x57, 0x00},
447 {0x5c, 0x00},
448 {0x5a, 0xa0},
449 {0x5b, 0x78},
450 {0x35, 0x02},
451 {0xd9, 0x10},
452 {0x94, 0x11},
453};
454
455static const u8 sensor_init_ov965x_2[][2] = {
456 {0x3b, 0xc4},
457 {0x1e, 0x04}, /* mvfp */
458 {0x13, 0xe0}, /* com8 */
459 {0x00, 0x00}, /* gain */
460 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
461 {0x11, 0x03}, /* clkrc */
462 {0x6b, 0x5a}, /* dblv */
463 {0x6a, 0x05},
464 {0xc5, 0x07},
465 {0xa2, 0x4b},
466 {0xa3, 0x3e},
467 {0x2d, 0x00},
468 {0xff, 0x42}, /* read 42, write ff 00 */
469 {0x42, 0xc0},
470 {0x2d, 0x00},
471 {0xff, 0x42}, /* read 42, write ff 00 */
472 {0x42, 0xc1},
473 {0x3f, 0x01},
474 {0xff, 0x42}, /* read 42, write ff 00 */
475 {0x42, 0xc1},
476 {0x4f, 0x98},
477 {0x50, 0x98},
478 {0x51, 0x00},
479 {0x52, 0x28},
480 {0x53, 0x70},
481 {0x54, 0x98},
482 {0x58, 0x1a},
483 {0xff, 0x41}, /* read 41, write ff 00 */
484 {0x41, 0x40}, /* com16 */
485 {0x56, 0x40},
486 {0x55, 0x8f},
487 {0x10, 0x25}, /* aech - exposure high bits */
488 {0xff, 0x13}, /* read 13, write ff 00 */
489 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
490};
491
492static const u8 bridge_start_ov965x[][2] = {
493 {0xc2, 0x4c},
494 {0xc3, 0xf9},
495 {0x50, 0x00},
496 {0x51, 0xa0},
497 {0x52, 0x78},
498 {0x53, 0x00},
499 {0x54, 0x00},
500 {0x55, 0x00},
501 {0x57, 0x00},
502 {0x5c, 0x00},
503 {0x5a, 0x28},
504 {0x5b, 0x1e},
505 {0x35, 0x00},
506 {0xd9, 0x21},
507 {0x94, 0x11},
508};
509
510static const u8 sensor_start_ov965x[][2] = {
511 {0x3b, 0xe4},
512 {0x1e, 0x04}, /* mvfp */
513 {0x13, 0xe0}, /* com8 */
514 {0x00, 0x00},
515 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
516 {0x11, 0x01}, /* clkrc */
517 {0x6b, 0x5a}, /* dblv */
518 {0x6a, 0x02},
519 {0xc5, 0x03},
520 {0xa2, 0x96},
521 {0xa3, 0x7d},
522 {0xff, 0x13}, /* read 13, write ff 00 */
523 {0x13, 0xe7},
524 {0x3a, 0x80},
525 {0xff, 0x42}, /* read 42, write ff 00 */
526 {0x42, 0xc1},
527};
528
529
530static void ov534_reg_write(struct gspca_dev *gspca_dev, u16 reg, u8 val)
531{
532 struct usb_device *udev = gspca_dev->dev;
533 int ret;
534
535 PDEBUG(D_USBO, "reg=0x%04x, val=0%02x", reg, val);
536 gspca_dev->usb_buf[0] = val;
537 ret = usb_control_msg(udev,
538 usb_sndctrlpipe(udev, 0),
539 0x01,
540 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
541 0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT);
542 if (ret < 0)
543 PDEBUG(D_ERR, "write failed");
544}
545
546static u8 ov534_reg_read(struct gspca_dev *gspca_dev, u16 reg)
547{
548 struct usb_device *udev = gspca_dev->dev;
549 int ret;
550
551 ret = usb_control_msg(udev,
552 usb_rcvctrlpipe(udev, 0),
553 0x01,
554 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
555 0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT);
556 PDEBUG(D_USBI, "reg=0x%04x, data=0x%02x", reg, gspca_dev->usb_buf[0]);
557 if (ret < 0)
558 PDEBUG(D_ERR, "read failed");
559 return gspca_dev->usb_buf[0];
560}
561
562/* Two bits control LED: 0x21 bit 7 and 0x23 bit 7.
563 * (direction and output)? */
564static void ov534_set_led(struct gspca_dev *gspca_dev, int status)
565{
566 u8 data;
567
568 PDEBUG(D_CONF, "led status: %d", status);
569
570 data = ov534_reg_read(gspca_dev, 0x21);
571 data |= 0x80;
572 ov534_reg_write(gspca_dev, 0x21, data);
573
574 data = ov534_reg_read(gspca_dev, 0x23);
575 if (status)
576 data |= 0x80;
577 else
578 data &= ~0x80;
579
580 ov534_reg_write(gspca_dev, 0x23, data);
581
582 if (!status) {
583 data = ov534_reg_read(gspca_dev, 0x21);
584 data &= ~0x80;
585 ov534_reg_write(gspca_dev, 0x21, data);
586 }
587}
588
589static int sccb_check_status(struct gspca_dev *gspca_dev)
590{
591 u8 data;
592 int i;
593
594 for (i = 0; i < 5; i++) {
595 data = ov534_reg_read(gspca_dev, OV534_REG_STATUS);
596
597 switch (data) {
598 case 0x00:
599 return 1;
600 case 0x04:
601 return 0;
602 case 0x03:
603 break;
604 default:
605 PDEBUG(D_ERR, "sccb status 0x%02x, attempt %d/5",
606 data, i + 1);
607 }
608 }
609 return 0;
610}
611
612static void sccb_reg_write(struct gspca_dev *gspca_dev, u8 reg, u8 val)
613{
614 PDEBUG(D_USBO, "reg: 0x%02x, val: 0x%02x", reg, val);
615 ov534_reg_write(gspca_dev, OV534_REG_SUBADDR, reg);
616 ov534_reg_write(gspca_dev, OV534_REG_WRITE, val);
617 ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_3);
618
619 if (!sccb_check_status(gspca_dev))
620 PDEBUG(D_ERR, "sccb_reg_write failed");
621}
622
623static u8 sccb_reg_read(struct gspca_dev *gspca_dev, u16 reg)
624{
625 ov534_reg_write(gspca_dev, OV534_REG_SUBADDR, reg);
626 ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_2);
627 if (!sccb_check_status(gspca_dev))
628 PDEBUG(D_ERR, "sccb_reg_read failed 1");
629
630 ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_READ_2);
631 if (!sccb_check_status(gspca_dev))
632 PDEBUG(D_ERR, "sccb_reg_read failed 2");
633
634 return ov534_reg_read(gspca_dev, OV534_REG_READ);
635}
636
637/* output a bridge sequence (reg - val) */
638static void reg_w_array(struct gspca_dev *gspca_dev,
639 const u8 (*data)[2], int len)
640{
641 while (--len >= 0) {
642 ov534_reg_write(gspca_dev, (*data)[0], (*data)[1]);
643 data++;
644 }
645}
646
647/* output a sensor sequence (reg - val) */
648static void sccb_w_array(struct gspca_dev *gspca_dev,
649 const u8 (*data)[2], int len)
650{
651 while (--len >= 0) {
652 if ((*data)[0] != 0xff) {
653 sccb_reg_write(gspca_dev, (*data)[0], (*data)[1]);
654 } else {
655 sccb_reg_read(gspca_dev, (*data)[1]);
656 sccb_reg_write(gspca_dev, 0xff, 0x00);
657 }
658 data++;
659 }
660}
661
314/* set framerate */ 662/* set framerate */
315static void ov534_set_frame_rate(struct gspca_dev *gspca_dev) 663static void ov534_set_frame_rate(struct gspca_dev *gspca_dev)
316{ 664{
@@ -346,40 +694,17 @@ static void ov534_set_frame_rate(struct gspca_dev *gspca_dev)
346 PDEBUG(D_PROBE, "frame_rate: %d", fr); 694 PDEBUG(D_PROBE, "frame_rate: %d", fr);
347} 695}
348 696
349/* setup method */
350static void ov534_setup(struct gspca_dev *gspca_dev)
351{
352 int i;
353
354 /* Initialize bridge chip */
355 for (i = 0; i < ARRAY_SIZE(ov534_reg_initdata); i++)
356 ov534_reg_write(gspca_dev, ov534_reg_initdata[i][0],
357 ov534_reg_initdata[i][1]);
358
359 PDEBUG(D_PROBE, "sensor is ov%02x%02x",
360 sccb_reg_read(gspca_dev, 0x0a),
361 sccb_reg_read(gspca_dev, 0x0b));
362
363 ov534_set_led(gspca_dev, 1);
364
365 /* Initialize sensor */
366 for (i = 0; i < ARRAY_SIZE(ov772x_reg_initdata); i++)
367 sccb_reg_write(gspca_dev, ov772x_reg_initdata[i][0],
368 ov772x_reg_initdata[i][1]);
369
370 ov534_reg_write(gspca_dev, 0xe0, 0x09);
371 ov534_set_led(gspca_dev, 0);
372}
373
374/* this function is called at probe time */ 697/* this function is called at probe time */
375static int sd_config(struct gspca_dev *gspca_dev, 698static int sd_config(struct gspca_dev *gspca_dev,
376 const struct usb_device_id *id) 699 const struct usb_device_id *id)
377{ 700{
701 struct sd *sd = (struct sd *) gspca_dev;
378 struct cam *cam; 702 struct cam *cam;
379 703
704 sd->sensor = id->driver_info;
705
380 cam = &gspca_dev->cam; 706 cam = &gspca_dev->cam;
381 707
382 cam->epaddr = 0x01;
383 cam->cam_mode = vga_mode; 708 cam->cam_mode = vga_mode;
384 cam->nmodes = ARRAY_SIZE(vga_mode); 709 cam->nmodes = ARRAY_SIZE(vga_mode);
385 710
@@ -392,26 +717,102 @@ static int sd_config(struct gspca_dev *gspca_dev,
392/* this function is called at probe and resume time */ 717/* this function is called at probe and resume time */
393static int sd_init(struct gspca_dev *gspca_dev) 718static int sd_init(struct gspca_dev *gspca_dev)
394{ 719{
395 ov534_setup(gspca_dev); 720 struct sd *sd = (struct sd *) gspca_dev;
396 ov534_set_frame_rate(gspca_dev); 721 u16 sensor_id;
722 static const u8 sensor_addr[2] = {
723 0x42, /* 0 SENSOR_OV772X */
724 0x60, /* 1 SENSOR_OV965X */
725 };
726
727 /* reset bridge */
728 ov534_reg_write(gspca_dev, 0xe7, 0x3a);
729 ov534_reg_write(gspca_dev, 0xe0, 0x08);
730 msleep(100);
731
732 /* initialize the sensor address */
733 ov534_reg_write(gspca_dev, OV534_REG_ADDRESS,
734 sensor_addr[sd->sensor]);
735
736 /* reset sensor */
737 sccb_reg_write(gspca_dev, 0x12, 0x80);
738 msleep(10);
739
740 /* probe the sensor */
741 sccb_reg_read(gspca_dev, 0x0a);
742 sensor_id = sccb_reg_read(gspca_dev, 0x0a) << 8;
743 sccb_reg_read(gspca_dev, 0x0b);
744 sensor_id |= sccb_reg_read(gspca_dev, 0x0b);
745 PDEBUG(D_PROBE, "Sensor ID: %04x", sensor_id);
746
747 /* initialize */
748 switch (sd->sensor) {
749 case SENSOR_OV772X:
750 reg_w_array(gspca_dev, bridge_init_ov722x,
751 ARRAY_SIZE(bridge_init_ov722x));
752 ov534_set_led(gspca_dev, 1);
753 sccb_w_array(gspca_dev, sensor_init_ov722x,
754 ARRAY_SIZE(sensor_init_ov722x));
755 ov534_reg_write(gspca_dev, 0xe0, 0x09);
756 ov534_set_led(gspca_dev, 0);
757 ov534_set_frame_rate(gspca_dev);
758 break;
759 default:
760/* case SENSOR_OV965X: */
761 reg_w_array(gspca_dev, bridge_init_ov965x,
762 ARRAY_SIZE(bridge_init_ov965x));
763 sccb_w_array(gspca_dev, sensor_init_ov965x,
764 ARRAY_SIZE(sensor_init_ov965x));
765 reg_w_array(gspca_dev, bridge_init_ov965x_2,
766 ARRAY_SIZE(bridge_init_ov965x_2));
767 sccb_w_array(gspca_dev, sensor_init_ov965x_2,
768 ARRAY_SIZE(sensor_init_ov965x_2));
769 ov534_reg_write(gspca_dev, 0xe0, 0x00);
770 ov534_reg_write(gspca_dev, 0xe0, 0x01);
771 ov534_set_led(gspca_dev, 0);
772 ov534_reg_write(gspca_dev, 0xe0, 0x00);
773 }
397 774
398 return 0; 775 return 0;
399} 776}
400 777
401static int sd_start(struct gspca_dev *gspca_dev) 778static int sd_start(struct gspca_dev *gspca_dev)
402{ 779{
403 /* start streaming data */ 780 struct sd *sd = (struct sd *) gspca_dev;
404 ov534_set_led(gspca_dev, 1);
405 ov534_reg_write(gspca_dev, 0xe0, 0x00);
406 781
782 switch (sd->sensor) {
783 case SENSOR_OV772X:
784 ov534_set_led(gspca_dev, 1);
785 ov534_reg_write(gspca_dev, 0xe0, 0x00);
786 break;
787 default:
788/* case SENSOR_OV965X: */
789 reg_w_array(gspca_dev, bridge_start_ov965x,
790 ARRAY_SIZE(bridge_start_ov965x));
791 sccb_w_array(gspca_dev, sensor_start_ov965x,
792 ARRAY_SIZE(sensor_start_ov965x));
793 ov534_reg_write(gspca_dev, 0xe0, 0x00);
794 ov534_set_led(gspca_dev, 1);
795/*fixme: other sensor start omitted*/
796 }
407 return 0; 797 return 0;
408} 798}
409 799
410static void sd_stopN(struct gspca_dev *gspca_dev) 800static void sd_stopN(struct gspca_dev *gspca_dev)
411{ 801{
412 /* stop streaming data */ 802 struct sd *sd = (struct sd *) gspca_dev;
413 ov534_reg_write(gspca_dev, 0xe0, 0x09); 803
414 ov534_set_led(gspca_dev, 0); 804 switch (sd->sensor) {
805 case SENSOR_OV772X:
806 ov534_reg_write(gspca_dev, 0xe0, 0x09);
807 ov534_set_led(gspca_dev, 0);
808 break;
809 default:
810/* case SENSOR_OV965X: */
811 ov534_reg_write(gspca_dev, 0xe0, 0x01);
812 ov534_set_led(gspca_dev, 0);
813 ov534_reg_write(gspca_dev, 0xe0, 0x00);
814 break;
815 }
415} 816}
416 817
417/* Values for bmHeaderInfo (Video and Still Image Payload Headers, 2.4.3.3) */ 818/* Values for bmHeaderInfo (Video and Still Image Payload Headers, 2.4.3.3) */
@@ -429,75 +830,75 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev, struct gspca_frame *frame,
429{ 830{
430 struct sd *sd = (struct sd *) gspca_dev; 831 struct sd *sd = (struct sd *) gspca_dev;
431 __u32 this_pts; 832 __u32 this_pts;
432 int this_fid; 833 u16 this_fid;
433 int remaining_len = len; 834 int remaining_len = len;
434 __u8 *next_data = data;
435 835
436scan_next: 836 do {
437 if (remaining_len <= 0) 837 len = min(remaining_len, 2040); /*fixme: was 2048*/
438 return;
439
440 data = next_data;
441 len = min(remaining_len, 2048);
442 remaining_len -= len;
443 next_data += len;
444
445 /* Payloads are prefixed with a UVC-style header. We
446 consider a frame to start when the FID toggles, or the PTS
447 changes. A frame ends when EOF is set, and we've received
448 the correct number of bytes. */
449
450 /* Verify UVC header. Header length is always 12 */
451 if (data[0] != 12 || len < 12) {
452 PDEBUG(D_PACK, "bad header");
453 goto discard;
454 }
455
456 /* Check errors */
457 if (data[1] & UVC_STREAM_ERR) {
458 PDEBUG(D_PACK, "payload error");
459 goto discard;
460 }
461 838
462 /* Extract PTS and FID */ 839 /* Payloads are prefixed with a UVC-style header. We
463 if (!(data[1] & UVC_STREAM_PTS)) { 840 consider a frame to start when the FID toggles, or the PTS
464 PDEBUG(D_PACK, "PTS not present"); 841 changes. A frame ends when EOF is set, and we've received
465 goto discard; 842 the correct number of bytes. */
466 }
467 this_pts = (data[5] << 24) | (data[4] << 16) | (data[3] << 8) | data[2];
468 this_fid = (data[1] & UVC_STREAM_FID) ? 1 : 0;
469
470 /* If PTS or FID has changed, start a new frame. */
471 if (this_pts != sd->last_pts || this_fid != sd->last_fid) {
472 gspca_frame_add(gspca_dev, FIRST_PACKET, frame, NULL, 0);
473 sd->last_pts = this_pts;
474 sd->last_fid = this_fid;
475 }
476 843
477 /* Add the data from this payload */ 844 /* Verify UVC header. Header length is always 12 */
478 gspca_frame_add(gspca_dev, INTER_PACKET, frame, 845 if (data[0] != 12 || len < 12) {
479 data + 12, len - 12); 846 PDEBUG(D_PACK, "bad header");
847 goto discard;
848 }
480 849
481 /* If this packet is marked as EOF, end the frame */ 850 /* Check errors */
482 if (data[1] & UVC_STREAM_EOF) { 851 if (data[1] & UVC_STREAM_ERR) {
483 sd->last_pts = 0; 852 PDEBUG(D_PACK, "payload error");
853 goto discard;
854 }
484 855
485 if ((frame->data_end - frame->data) != 856 /* Extract PTS and FID */
486 (gspca_dev->width * gspca_dev->height * 2)) { 857 if (!(data[1] & UVC_STREAM_PTS)) {
487 PDEBUG(D_PACK, "short frame"); 858 PDEBUG(D_PACK, "PTS not present");
488 goto discard; 859 goto discard;
489 } 860 }
861 this_pts = (data[5] << 24) | (data[4] << 16)
862 | (data[3] << 8) | data[2];
863 this_fid = (data[1] & UVC_STREAM_FID) ? 1 : 0;
864
865 /* If PTS or FID has changed, start a new frame. */
866 if (this_pts != sd->last_pts || this_fid != sd->last_fid) {
867 gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
868 NULL, 0);
869 sd->last_pts = this_pts;
870 sd->last_fid = this_fid;
871 }
490 872
491 gspca_frame_add(gspca_dev, LAST_PACKET, frame, NULL, 0); 873 /* Add the data from this payload */
492 } 874 gspca_frame_add(gspca_dev, INTER_PACKET, frame,
875 data + 12, len - 12);
493 876
494 /* Done this payload */ 877 /* If this packet is marked as EOF, end the frame */
495 goto scan_next; 878 if (data[1] & UVC_STREAM_EOF) {
879 sd->last_pts = 0;
880
881 if (frame->data_end - frame->data !=
882 gspca_dev->width * gspca_dev->height * 2) {
883 PDEBUG(D_PACK, "short frame");
884 goto discard;
885 }
886
887 frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame,
888 NULL, 0);
889 }
890
891 /* Done this payload */
892 goto scan_next;
496 893
497discard: 894discard:
498 /* Discard data until a new frame starts. */ 895 /* Discard data until a new frame starts. */
499 gspca_frame_add(gspca_dev, DISCARD_PACKET, frame, NULL, 0); 896 gspca_frame_add(gspca_dev, DISCARD_PACKET, frame, NULL, 0);
500 goto scan_next; 897
898scan_next:
899 remaining_len -= len;
900 data += len;
901 } while (remaining_len > 0);
501} 902}
502 903
503/* get stream parameters (framerate) */ 904/* get stream parameters (framerate) */
@@ -556,9 +957,8 @@ static const struct sd_desc sd_desc = {
556 957
557/* -- module initialisation -- */ 958/* -- module initialisation -- */
558static const __devinitdata struct usb_device_id device_table[] = { 959static const __devinitdata struct usb_device_id device_table[] = {
559 {USB_DEVICE(0x06f8, 0x3002)}, /* Hercules Blog Webcam */ 960 {USB_DEVICE(0x06f8, 0x3003), .driver_info = SENSOR_OV965X},
560 {USB_DEVICE(0x06f8, 0x3003)}, /* Hercules Dualpix HD Weblog */ 961 {USB_DEVICE(0x1415, 0x2000), .driver_info = SENSOR_OV772X},
561 {USB_DEVICE(0x1415, 0x2000)}, /* Sony HD Eye for PS3 (SLEH 00201) */
562 {} 962 {}
563}; 963};
564 964
@@ -585,8 +985,10 @@ static struct usb_driver sd_driver = {
585/* -- module insert / remove -- */ 985/* -- module insert / remove -- */
586static int __init sd_mod_init(void) 986static int __init sd_mod_init(void)
587{ 987{
588 if (usb_register(&sd_driver) < 0) 988 int ret;
589 return -1; 989 ret = usb_register(&sd_driver);
990 if (ret < 0)
991 return ret;
590 PDEBUG(D_PROBE, "registered"); 992 PDEBUG(D_PROBE, "registered");
591 return 0; 993 return 0;
592} 994}
diff --git a/drivers/media/video/gspca/pac207.c b/drivers/media/video/gspca/pac207.c
index c90ac852bac0..95a97ab684cd 100644
--- a/drivers/media/video/gspca/pac207.c
+++ b/drivers/media/video/gspca/pac207.c
@@ -256,7 +256,6 @@ static int sd_config(struct gspca_dev *gspca_dev,
256 " (vid/pid 0x%04X:0x%04X)", id->idVendor, id->idProduct); 256 " (vid/pid 0x%04X:0x%04X)", id->idVendor, id->idProduct);
257 257
258 cam = &gspca_dev->cam; 258 cam = &gspca_dev->cam;
259 cam->epaddr = 0x05;
260 cam->cam_mode = sif_mode; 259 cam->cam_mode = sif_mode;
261 cam->nmodes = ARRAY_SIZE(sif_mode); 260 cam->nmodes = ARRAY_SIZE(sif_mode);
262 sd->brightness = PAC207_BRIGHTNESS_DEFAULT; 261 sd->brightness = PAC207_BRIGHTNESS_DEFAULT;
@@ -536,6 +535,7 @@ static const __devinitdata struct usb_device_id device_table[] = {
536 {USB_DEVICE(0x093a, 0x2470)}, 535 {USB_DEVICE(0x093a, 0x2470)},
537 {USB_DEVICE(0x093a, 0x2471)}, 536 {USB_DEVICE(0x093a, 0x2471)},
538 {USB_DEVICE(0x093a, 0x2472)}, 537 {USB_DEVICE(0x093a, 0x2472)},
538 {USB_DEVICE(0x093a, 0x2474)},
539 {USB_DEVICE(0x093a, 0x2476)}, 539 {USB_DEVICE(0x093a, 0x2476)},
540 {USB_DEVICE(0x145f, 0x013a)}, 540 {USB_DEVICE(0x145f, 0x013a)},
541 {USB_DEVICE(0x2001, 0xf115)}, 541 {USB_DEVICE(0x2001, 0xf115)},
@@ -565,8 +565,10 @@ static struct usb_driver sd_driver = {
565/* -- module insert / remove -- */ 565/* -- module insert / remove -- */
566static int __init sd_mod_init(void) 566static int __init sd_mod_init(void)
567{ 567{
568 if (usb_register(&sd_driver) < 0) 568 int ret;
569 return -1; 569 ret = usb_register(&sd_driver);
570 if (ret < 0)
571 return ret;
570 PDEBUG(D_PROBE, "registered"); 572 PDEBUG(D_PROBE, "registered");
571 return 0; 573 return 0;
572} 574}
diff --git a/drivers/media/video/gspca/pac7311.c b/drivers/media/video/gspca/pac7311.c
index a9c95cba710e..e1e3a3a50484 100644
--- a/drivers/media/video/gspca/pac7311.c
+++ b/drivers/media/video/gspca/pac7311.c
@@ -498,7 +498,6 @@ static int sd_config(struct gspca_dev *gspca_dev,
498 struct cam *cam; 498 struct cam *cam;
499 499
500 cam = &gspca_dev->cam; 500 cam = &gspca_dev->cam;
501 cam->epaddr = 0x05;
502 501
503 sd->sensor = id->driver_info; 502 sd->sensor = id->driver_info;
504 if (sd->sensor == SENSOR_PAC7302) { 503 if (sd->sensor == SENSOR_PAC7302) {
@@ -1097,8 +1096,10 @@ static struct usb_driver sd_driver = {
1097/* -- module insert / remove -- */ 1096/* -- module insert / remove -- */
1098static int __init sd_mod_init(void) 1097static int __init sd_mod_init(void)
1099{ 1098{
1100 if (usb_register(&sd_driver) < 0) 1099 int ret;
1101 return -1; 1100 ret = usb_register(&sd_driver);
1101 if (ret < 0)
1102 return ret;
1102 PDEBUG(D_PROBE, "registered"); 1103 PDEBUG(D_PROBE, "registered");
1103 return 0; 1104 return 0;
1104} 1105}
diff --git a/drivers/media/video/gspca/sonixb.c b/drivers/media/video/gspca/sonixb.c
index b3e4e0677b68..153d0a91d4b5 100644
--- a/drivers/media/video/gspca/sonixb.c
+++ b/drivers/media/video/gspca/sonixb.c
@@ -870,7 +870,6 @@ static int sd_config(struct gspca_dev *gspca_dev,
870 gspca_dev->ctrl_dis = sensor_data[sd->sensor].ctrl_dis; 870 gspca_dev->ctrl_dis = sensor_data[sd->sensor].ctrl_dis;
871 871
872 cam = &gspca_dev->cam; 872 cam = &gspca_dev->cam;
873 cam->epaddr = 0x01;
874 if (!(sensor_data[sd->sensor].flags & F_SIF)) { 873 if (!(sensor_data[sd->sensor].flags & F_SIF)) {
875 cam->cam_mode = vga_mode; 874 cam->cam_mode = vga_mode;
876 cam->nmodes = ARRAY_SIZE(vga_mode); 875 cam->nmodes = ARRAY_SIZE(vga_mode);
@@ -1272,8 +1271,10 @@ static struct usb_driver sd_driver = {
1272/* -- module insert / remove -- */ 1271/* -- module insert / remove -- */
1273static int __init sd_mod_init(void) 1272static int __init sd_mod_init(void)
1274{ 1273{
1275 if (usb_register(&sd_driver) < 0) 1274 int ret;
1276 return -1; 1275 ret = usb_register(&sd_driver);
1276 if (ret < 0)
1277 return ret;
1277 PDEBUG(D_PROBE, "registered"); 1278 PDEBUG(D_PROBE, "registered");
1278 return 0; 1279 return 0;
1279} 1280}
diff --git a/drivers/media/video/gspca/sonixj.c b/drivers/media/video/gspca/sonixj.c
index 3373b8d9d2a8..c72e19d3ac37 100644
--- a/drivers/media/video/gspca/sonixj.c
+++ b/drivers/media/video/gspca/sonixj.c
@@ -35,36 +35,47 @@ struct sd {
35 struct gspca_dev gspca_dev; /* !! must be the first item */ 35 struct gspca_dev gspca_dev; /* !! must be the first item */
36 36
37 atomic_t avg_lum; 37 atomic_t avg_lum;
38 unsigned int exposure; 38 u32 exposure;
39 39
40 __u16 brightness; 40 u16 brightness;
41 __u8 contrast; 41 u8 contrast;
42 __u8 colors; 42 u8 colors;
43 __u8 autogain; 43 u8 autogain;
44 __u8 blue; 44 u8 blue;
45 __u8 red; 45 u8 red;
46 __u8 vflip; /* ov7630 only */ 46 u8 gamma;
47 __u8 infrared; /* mi0360 only */ 47 u8 vflip; /* ov7630/ov7648 only */
48 48 u8 infrared; /* mt9v111 only */
49 __s8 ag_cnt; 49 u8 quality; /* image quality */
50#define QUALITY_MIN 60
51#define QUALITY_MAX 95
52#define QUALITY_DEF 80
53 u8 jpegqual; /* webcam quality */
54
55 u8 reg18;
56
57 s8 ag_cnt;
50#define AG_CNT_START 13 58#define AG_CNT_START 13
51 59
52 __u8 qindex; 60 u8 bridge;
53 __u8 bridge;
54#define BRIDGE_SN9C102P 0 61#define BRIDGE_SN9C102P 0
55#define BRIDGE_SN9C105 1 62#define BRIDGE_SN9C105 1
56#define BRIDGE_SN9C110 2 63#define BRIDGE_SN9C110 2
57#define BRIDGE_SN9C120 3 64#define BRIDGE_SN9C120 3
58#define BRIDGE_SN9C325 4 65#define BRIDGE_SN9C325 4
59 __u8 sensor; /* Type of image sensor chip */ 66 u8 sensor; /* Type of image sensor chip */
60#define SENSOR_HV7131R 0 67#define SENSOR_HV7131R 0
61#define SENSOR_MI0360 1 68#define SENSOR_MI0360 1
62#define SENSOR_MO4000 2 69#define SENSOR_MO4000 2
63#define SENSOR_OM6802 3 70#define SENSOR_MT9V111 3
64#define SENSOR_OV7630 4 71#define SENSOR_OM6802 4
65#define SENSOR_OV7648 5 72#define SENSOR_OV7630 5
66#define SENSOR_OV7660 6 73#define SENSOR_OV7648 6
67 __u8 i2c_base; 74#define SENSOR_OV7660 7
75#define SENSOR_SP80708 8
76 u8 i2c_base;
77
78 u8 *jpeg_hdr;
68}; 79};
69 80
70/* V4L2 controls supported by the driver */ 81/* V4L2 controls supported by the driver */
@@ -78,6 +89,8 @@ static int sd_setblue_balance(struct gspca_dev *gspca_dev, __s32 val);
78static int sd_getblue_balance(struct gspca_dev *gspca_dev, __s32 *val); 89static int sd_getblue_balance(struct gspca_dev *gspca_dev, __s32 *val);
79static int sd_setred_balance(struct gspca_dev *gspca_dev, __s32 val); 90static int sd_setred_balance(struct gspca_dev *gspca_dev, __s32 val);
80static int sd_getred_balance(struct gspca_dev *gspca_dev, __s32 *val); 91static int sd_getred_balance(struct gspca_dev *gspca_dev, __s32 *val);
92static int sd_setgamma(struct gspca_dev *gspca_dev, __s32 val);
93static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val);
81static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val); 94static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
82static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val); 95static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
83static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val); 96static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val);
@@ -158,6 +171,20 @@ static struct ctrl sd_ctrls[] = {
158 .set = sd_setred_balance, 171 .set = sd_setred_balance,
159 .get = sd_getred_balance, 172 .get = sd_getred_balance,
160 }, 173 },
174 {
175 {
176 .id = V4L2_CID_GAMMA,
177 .type = V4L2_CTRL_TYPE_INTEGER,
178 .name = "Gamma",
179 .minimum = 0,
180 .maximum = 40,
181 .step = 1,
182#define GAMMA_DEF 20
183 .default_value = GAMMA_DEF,
184 },
185 .set = sd_setgamma,
186 .get = sd_getgamma,
187 },
161#define AUTOGAIN_IDX 5 188#define AUTOGAIN_IDX 5
162 { 189 {
163 { 190 {
@@ -173,7 +200,7 @@ static struct ctrl sd_ctrls[] = {
173 .set = sd_setautogain, 200 .set = sd_setautogain,
174 .get = sd_getautogain, 201 .get = sd_getautogain,
175 }, 202 },
176/* ov7630 only */ 203/* ov7630/ov7648 only */
177#define VFLIP_IDX 6 204#define VFLIP_IDX 6
178 { 205 {
179 { 206 {
@@ -183,13 +210,13 @@ static struct ctrl sd_ctrls[] = {
183 .minimum = 0, 210 .minimum = 0,
184 .maximum = 1, 211 .maximum = 1,
185 .step = 1, 212 .step = 1,
186#define VFLIP_DEF 1 213#define VFLIP_DEF 0 /* vflip def = 1 for ov7630 */
187 .default_value = VFLIP_DEF, 214 .default_value = VFLIP_DEF,
188 }, 215 },
189 .set = sd_setvflip, 216 .set = sd_setvflip,
190 .get = sd_getvflip, 217 .get = sd_getvflip,
191 }, 218 },
192/* mi0360 only */ 219/* mt9v111 only */
193#define INFRARED_IDX 7 220#define INFRARED_IDX 7
194 { 221 {
195 { 222 {
@@ -211,18 +238,22 @@ static struct ctrl sd_ctrls[] = {
211static __u32 ctrl_dis[] = { 238static __u32 ctrl_dis[] = {
212 (1 << INFRARED_IDX) | (1 << VFLIP_IDX), 239 (1 << INFRARED_IDX) | (1 << VFLIP_IDX),
213 /* SENSOR_HV7131R 0 */ 240 /* SENSOR_HV7131R 0 */
214 (1 << VFLIP_IDX), 241 (1 << INFRARED_IDX) | (1 << VFLIP_IDX),
215 /* SENSOR_MI0360 1 */ 242 /* SENSOR_MI0360 1 */
216 (1 << INFRARED_IDX) | (1 << VFLIP_IDX), 243 (1 << INFRARED_IDX) | (1 << VFLIP_IDX),
217 /* SENSOR_MO4000 2 */ 244 /* SENSOR_MO4000 2 */
245 (1 << VFLIP_IDX),
246 /* SENSOR_MT9V111 3 */
218 (1 << INFRARED_IDX) | (1 << VFLIP_IDX), 247 (1 << INFRARED_IDX) | (1 << VFLIP_IDX),
219 /* SENSOR_OM6802 3 */ 248 /* SENSOR_OM6802 4 */
220 (1 << AUTOGAIN_IDX) | (1 << INFRARED_IDX), 249 (1 << AUTOGAIN_IDX) | (1 << INFRARED_IDX),
221 /* SENSOR_OV7630 4 */ 250 /* SENSOR_OV7630 5 */
251 (1 << INFRARED_IDX),
252 /* SENSOR_OV7648 6 */
222 (1 << AUTOGAIN_IDX) | (1 << INFRARED_IDX) | (1 << VFLIP_IDX), 253 (1 << AUTOGAIN_IDX) | (1 << INFRARED_IDX) | (1 << VFLIP_IDX),
223 /* SENSOR_OV7648 5 */ 254 /* SENSOR_OV7660 7 */
224 (1 << AUTOGAIN_IDX) | (1 << INFRARED_IDX) | (1 << VFLIP_IDX), 255 (1 << AUTOGAIN_IDX) | (1 << INFRARED_IDX) | (1 << VFLIP_IDX),
225 /* SENSOR_OV7660 6 */ 256 /* SENSOR_SP80708 8 */
226}; 257};
227 258
228static const struct v4l2_pix_format vga_mode[] = { 259static const struct v4l2_pix_format vga_mode[] = {
@@ -243,196 +274,228 @@ static const struct v4l2_pix_format vga_mode[] = {
243 .priv = 0}, 274 .priv = 0},
244}; 275};
245 276
246/*Data from sn9c102p+hv71331r */ 277/*Data from sn9c102p+hv7131r */
247static const __u8 sn_hv7131[] = { 278static const u8 sn_hv7131[0x1c] = {
248/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */ 279/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
249 0x00, 0x03, 0x64, 0x00, 0x1a, 0x20, 0x20, 0x20, 280 0x00, 0x03, 0x64, 0x00, 0x1a, 0x20, 0x20, 0x20,
250/* reg8 reg9 rega regb regc regd rege regf */ 281/* reg8 reg9 rega regb regc regd rege regf */
251 0xa1, 0x11, 0x02, 0x09, 0x00, 0x00, 0x00, 0x10, 282 0xa1, 0x11, 0x02, 0x09, 0x00, 0x00, 0x00, 0x10,
252/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */ 283/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
253 0x03, 0x00, 0x00, 0x01, 0x03, 0x28, 0x1e, 0x41, 284 0x03, 0x00, 0x00, 0x01, 0x03, 0x28, 0x1e, 0x41,
254/* reg18 reg19 reg1a reg1b reg1c reg1d reg1e reg1f */ 285/* reg18 reg19 reg1a reg1b */
255 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 286 0x0a, 0x00, 0x00, 0x00
256}; 287};
257 288
258static const __u8 sn_mi0360[] = { 289static const u8 sn_mi0360[0x1c] = {
259/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */ 290/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
260 0x00, 0x61, 0x44, 0x00, 0x1a, 0x20, 0x20, 0x20, 291 0x00, 0x61, 0x44, 0x00, 0x1a, 0x20, 0x20, 0x20,
261/* reg8 reg9 rega regb regc regd rege regf */ 292/* reg8 reg9 rega regb regc regd rege regf */
262 0xb1, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10, 293 0xb1, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10,
263/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */ 294/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
264 0x03, 0x00, 0x00, 0x02, 0x0a, 0x28, 0x1e, 0x61, 295 0x03, 0x00, 0x00, 0x02, 0x0a, 0x28, 0x1e, 0x61,
265/* reg18 reg19 reg1a reg1b reg1c reg1d reg1e reg1f */ 296/* reg18 reg19 reg1a reg1b */
266 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 297 0x06, 0x00, 0x00, 0x00
267}; 298};
268 299
269static const __u8 sn_mo4000[] = { 300static const u8 sn_mo4000[0x1c] = {
270/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */ 301/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
271 0x12, 0x23, 0x60, 0x00, 0x1a, 0x00, 0x20, 0x18, 302 0x00, 0x23, 0x60, 0x00, 0x1a, 0x00, 0x20, 0x18,
272/* reg8 reg9 rega regb regc regd rege regf */ 303/* reg8 reg9 rega regb regc regd rege regf */
273 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 304 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
274/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */ 305/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
275 0x03, 0x00, 0x0b, 0x0f, 0x14, 0x28, 0x1e, 0x40, 306 0x03, 0x00, 0x0b, 0x0f, 0x14, 0x28, 0x1e, 0x40,
276/* reg18 reg19 reg1a reg1b reg1c reg1d reg1e reg1f */ 307/* reg18 reg19 reg1a reg1b */
277 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 308 0x08, 0x00, 0x00, 0x00
278}; 309};
279 310
280static const __u8 sn_om6802[] = { 311static const u8 sn_mt9v111[0x1c] = {
312/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
313 0x00, 0x61, 0x40, 0x00, 0x1a, 0x20, 0x20, 0x20,
314/* reg8 reg9 rega regb regc regd rege regf */
315 0x81, 0x5c, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
316/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
317 0x03, 0x00, 0x00, 0x02, 0x1c, 0x28, 0x1e, 0x40,
318/* reg18 reg19 reg1a reg1b */
319 0x06, 0x00, 0x00, 0x00
320};
321
322static const u8 sn_om6802[0x1c] = {
281/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */ 323/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
282 0x00, 0x23, 0x72, 0x00, 0x1a, 0x34, 0x27, 0x20, 324 0x00, 0x23, 0x72, 0x00, 0x1a, 0x34, 0x27, 0x20,
283/* reg8 reg9 rega regb regc regd rege regf */ 325/* reg8 reg9 rega regb regc regd rege regf */
284 0x80, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 326 0x80, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
285/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */ 327/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
286 0x03, 0x00, 0x51, 0x01, 0x00, 0x28, 0x1e, 0x40, 328 0x03, 0x00, 0x51, 0x01, 0x00, 0x28, 0x1e, 0x40,
287/* reg18 reg19 reg1a reg1b reg1c reg1d reg1e reg1f */ 329/* reg18 reg19 reg1a reg1b */
288 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 330 0x05, 0x00, 0x00, 0x00
289 0x08, 0x22, 0x44, 0x63, 0x7d, 0x92, 0xa3, 0xaf,
290 0xbc, 0xc4, 0xcd, 0xd5, 0xdc, 0xe1, 0xe8, 0xef,
291 0xf7
292}; 331};
293 332
294static const __u8 sn_ov7630[] = { 333static const u8 sn_ov7630[0x1c] = {
295/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */ 334/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
296 0x00, 0x21, 0x40, 0x00, 0x1a, 0x20, 0x1f, 0x20, 335 0x00, 0x21, 0x40, 0x00, 0x1a, 0x20, 0x1f, 0x20,
297/* reg8 reg9 rega regb regc regd rege regf */ 336/* reg8 reg9 rega regb regc regd rege regf */
298 0xa1, 0x21, 0x76, 0x21, 0x00, 0x00, 0x00, 0x10, 337 0xa1, 0x21, 0x76, 0x21, 0x00, 0x00, 0x00, 0x10,
299/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */ 338/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
300 0x03, 0x00, 0x04, 0x01, 0x0a, 0x28, 0x1e, 0xc2, 339 0x03, 0x00, 0x04, 0x01, 0x0a, 0x28, 0x1e, 0xc2,
301/* reg18 reg19 reg1a reg1b reg1c reg1d reg1e reg1f */ 340/* reg18 reg19 reg1a reg1b */
302 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00 341 0x0b, 0x00, 0x00, 0x00
303}; 342};
304 343
305static const __u8 sn_ov7648[] = { 344static const u8 sn_ov7648[0x1c] = {
306/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */ 345/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
307 0x00, 0x63, 0x40, 0x00, 0x1a, 0x20, 0x20, 0x20, 346 0x00, 0x63, 0x40, 0x00, 0x1a, 0x20, 0x20, 0x20,
308/* reg8 reg9 rega regb regc regd rege regf */ 347/* reg8 reg9 rega regb regc regd rege regf */
309 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 348 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,
310/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */ 349/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
311 0x03, 0x00, 0x00, 0x01, 0x00, 0x28, 0x1e, 0x00, 350 0x03, 0x00, 0x00, 0x01, 0x00, 0x28, 0x1e, 0x00,
312/* reg18 reg19 reg1a reg1b reg1c reg1d reg1e reg1f */ 351/* reg18 reg19 reg1a reg1b */
313 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00 352 0x0b, 0x00, 0x00, 0x00
314}; 353};
315 354
316static const __u8 sn_ov7660[] = { 355static const u8 sn_ov7660[0x1c] = {
317/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */ 356/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
318 0x00, 0x61, 0x40, 0x00, 0x1a, 0x20, 0x20, 0x20, 357 0x00, 0x61, 0x40, 0x00, 0x1a, 0x20, 0x20, 0x20,
319/* reg8 reg9 rega regb regc regd rege regf */ 358/* reg8 reg9 rega regb regc regd rege regf */
320 0x81, 0x21, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10, 359 0x81, 0x21, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10,
321/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */ 360/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
322 0x03, 0x00, 0x01, 0x01, 0x08, 0x28, 0x1e, 0x20, 361 0x03, 0x00, 0x01, 0x01, 0x08, 0x28, 0x1e, 0x20,
323/* reg18 reg19 reg1a reg1b reg1c reg1d reg1e reg1f */ 362/* reg18 reg19 reg1a reg1b */
324 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 363 0x07, 0x00, 0x00, 0x00
364};
365
366static const u8 sn_sp80708[0x1c] = {
367/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
368 0x00, 0x63, 0x60, 0x00, 0x1a, 0x20, 0x20, 0x20,
369/* reg8 reg9 rega regb regc regd rege regf */
370 0x81, 0x18, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
371/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
372 0x03, 0x00, 0x00, 0x03, 0x04, 0x28, 0x1e, 0x00,
373/* reg18 reg19 reg1a reg1b */
374 0x07, 0x00, 0x00, 0x00
325}; 375};
326 376
327/* sequence specific to the sensors - !! index = SENSOR_xxx */ 377/* sequence specific to the sensors - !! index = SENSOR_xxx */
328static const __u8 *sn_tb[] = { 378static const u8 *sn_tb[] = {
329 sn_hv7131, 379 sn_hv7131,
330 sn_mi0360, 380 sn_mi0360,
331 sn_mo4000, 381 sn_mo4000,
382 sn_mt9v111,
332 sn_om6802, 383 sn_om6802,
333 sn_ov7630, 384 sn_ov7630,
334 sn_ov7648, 385 sn_ov7648,
335 sn_ov7660 386 sn_ov7660,
387 sn_sp80708
336}; 388};
337 389
338static const __u8 gamma_def[] = { 390/* default gamma table */
391static const u8 gamma_def[17] = {
339 0x00, 0x2d, 0x46, 0x5a, 0x6c, 0x7c, 0x8b, 0x99, 392 0x00, 0x2d, 0x46, 0x5a, 0x6c, 0x7c, 0x8b, 0x99,
340 0xa6, 0xb2, 0xbf, 0xca, 0xd5, 0xe0, 0xeb, 0xf5, 0xff 393 0xa6, 0xb2, 0xbf, 0xca, 0xd5, 0xe0, 0xeb, 0xf5, 0xff
341}; 394};
395/* gamma for sensors HV7131R and MT9V111 */
396static const u8 gamma_spec_1[17] = {
397 0x08, 0x3a, 0x52, 0x65, 0x75, 0x83, 0x91, 0x9d,
398 0xa9, 0xb4, 0xbe, 0xc8, 0xd2, 0xdb, 0xe4, 0xed, 0xf5
399};
400/* gamma for sensor SP80708 */
401static const u8 gamma_spec_2[17] = {
402 0x0a, 0x2d, 0x4e, 0x68, 0x7d, 0x8f, 0x9f, 0xab,
403 0xb7, 0xc2, 0xcc, 0xd3, 0xd8, 0xde, 0xe2, 0xe5, 0xe6
404};
342 405
343/* color matrix and offsets */ 406/* color matrix and offsets */
344static const __u8 reg84[] = { 407static const u8 reg84[] = {
345 0x14, 0x00, 0x27, 0x00, 0x07, 0x00, /* YR YG YB gains */ 408 0x14, 0x00, 0x27, 0x00, 0x07, 0x00, /* YR YG YB gains */
346 0xe8, 0x0f, 0xda, 0x0f, 0x40, 0x00, /* UR UG UB */ 409 0xe8, 0x0f, 0xda, 0x0f, 0x40, 0x00, /* UR UG UB */
347 0x3e, 0x00, 0xcd, 0x0f, 0xf7, 0x0f, /* VR VG VB */ 410 0x3e, 0x00, 0xcd, 0x0f, 0xf7, 0x0f, /* VR VG VB */
348 0x00, 0x00, 0x00 /* YUV offsets */ 411 0x00, 0x00, 0x00 /* YUV offsets */
349}; 412};
350static const __u8 hv7131r_sensor_init[][8] = { 413static const u8 hv7131r_sensor_init[][8] = {
351 {0xC1, 0x11, 0x01, 0x08, 0x01, 0x00, 0x00, 0x10}, 414 {0xc1, 0x11, 0x01, 0x08, 0x01, 0x00, 0x00, 0x10},
352 {0xB1, 0x11, 0x34, 0x17, 0x7F, 0x00, 0x00, 0x10}, 415 {0xb1, 0x11, 0x34, 0x17, 0x7f, 0x00, 0x00, 0x10},
353 {0xD1, 0x11, 0x40, 0xFF, 0x7F, 0x7F, 0x7F, 0x10}, 416 {0xd1, 0x11, 0x40, 0xff, 0x7f, 0x7f, 0x7f, 0x10},
354 {0x91, 0x11, 0x44, 0x00, 0x00, 0x00, 0x00, 0x10}, 417/* {0x91, 0x11, 0x44, 0x00, 0x00, 0x00, 0x00, 0x10}, */
355 {0xD1, 0x11, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10}, 418 {0xd1, 0x11, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
356 {0xD1, 0x11, 0x14, 0x01, 0xE2, 0x02, 0x82, 0x10}, 419 {0xd1, 0x11, 0x14, 0x01, 0xe2, 0x02, 0x82, 0x10},
357 {0x91, 0x11, 0x18, 0x00, 0x00, 0x00, 0x00, 0x10}, 420/* {0x91, 0x11, 0x18, 0x00, 0x00, 0x00, 0x00, 0x10}, */
358 421
359 {0xA1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10}, 422 {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
360 {0xA1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10}, 423 {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
361 {0xC1, 0x11, 0x25, 0x00, 0x61, 0xA8, 0x00, 0x10}, 424 {0xc1, 0x11, 0x25, 0x00, 0x61, 0xa8, 0x00, 0x10},
362 {0xA1, 0x11, 0x30, 0x22, 0x00, 0x00, 0x00, 0x10}, 425 {0xa1, 0x11, 0x30, 0x22, 0x00, 0x00, 0x00, 0x10},
363 {0xC1, 0x11, 0x31, 0x20, 0x2E, 0x20, 0x00, 0x10}, 426 {0xc1, 0x11, 0x31, 0x20, 0x2e, 0x20, 0x00, 0x10},
364 {0xC1, 0x11, 0x25, 0x00, 0xC3, 0x50, 0x00, 0x10}, 427 {0xc1, 0x11, 0x25, 0x00, 0xc3, 0x50, 0x00, 0x10},
365 {0xA1, 0x11, 0x30, 0x07, 0x00, 0x00, 0x00, 0x10}, /* gain14 */ 428 {0xa1, 0x11, 0x30, 0x07, 0x00, 0x00, 0x00, 0x10}, /* gain14 */
366 {0xC1, 0x11, 0x31, 0x10, 0x10, 0x10, 0x00, 0x10}, /* r g b 101a10 */ 429 {0xc1, 0x11, 0x31, 0x10, 0x10, 0x10, 0x00, 0x10}, /* r g b 101a10 */
367 430
368 {0xA1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10}, 431 {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
369 {0xA1, 0x11, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10}, 432 {0xa1, 0x11, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
370 {0xA1, 0x11, 0x21, 0xD0, 0x00, 0x00, 0x00, 0x10}, 433 {0xa1, 0x11, 0x21, 0xD0, 0x00, 0x00, 0x00, 0x10},
371 {0xA1, 0x11, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10}, 434 {0xa1, 0x11, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
372 {0xA1, 0x11, 0x23, 0x09, 0x00, 0x00, 0x00, 0x10}, 435 {0xa1, 0x11, 0x23, 0x09, 0x00, 0x00, 0x00, 0x10},
373 436
374 {0xA1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10}, 437 {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
375 {0xA1, 0x11, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10}, 438 {0xa1, 0x11, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
376 {0xA1, 0x11, 0x21, 0xD0, 0x00, 0x00, 0x00, 0x10}, 439 {0xa1, 0x11, 0x21, 0xd0, 0x00, 0x00, 0x00, 0x10},
377 {0xA1, 0x11, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10}, 440 {0xa1, 0x11, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
378 {0xA1, 0x11, 0x23, 0x10, 0x00, 0x00, 0x00, 0x10}, 441 {0xa1, 0x11, 0x23, 0x10, 0x00, 0x00, 0x00, 0x10},
379 {} 442 {}
380}; 443};
381static const __u8 mi0360_sensor_init[][8] = { 444static const u8 mi0360_sensor_init[][8] = {
382 {0xB1, 0x5D, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10}, 445 {0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10},
383 {0xB1, 0x5D, 0x0D, 0x00, 0x01, 0x00, 0x00, 0x10}, 446 {0xb1, 0x5d, 0x0d, 0x00, 0x01, 0x00, 0x00, 0x10},
384 {0xB1, 0x5D, 0x0D, 0x00, 0x00, 0x00, 0x00, 0x10}, 447 {0xb1, 0x5d, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x10},
385 {0xD1, 0x5D, 0x01, 0x00, 0x08, 0x00, 0x16, 0x10}, 448 {0xd1, 0x5d, 0x01, 0x00, 0x08, 0x00, 0x16, 0x10},
386 {0xD1, 0x5D, 0x03, 0x01, 0xE2, 0x02, 0x82, 0x10}, 449 {0xd1, 0x5d, 0x03, 0x01, 0xe2, 0x02, 0x82, 0x10},
387 {0xD1, 0x5D, 0x05, 0x00, 0x09, 0x00, 0x53, 0x10}, 450 {0xd1, 0x5d, 0x05, 0x00, 0x09, 0x00, 0x53, 0x10},
388 {0xB1, 0x5D, 0x0D, 0x00, 0x02, 0x00, 0x00, 0x10}, 451 {0xb1, 0x5d, 0x0d, 0x00, 0x02, 0x00, 0x00, 0x10},
389 {0xD1, 0x5D, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x10}, 452 {0xd1, 0x5d, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x10},
390 {0xD1, 0x5D, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x10}, 453 {0xd1, 0x5d, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x10},
391 {0xD1, 0x5D, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x10}, 454 {0xd1, 0x5d, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x10},
392 {0xD1, 0x5D, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10}, 455 {0xd1, 0x5d, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
393 {0xD1, 0x5D, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10}, 456 {0xd1, 0x5d, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
394 {0xD1, 0x5D, 0x14, 0x00, 0x00, 0x00, 0x00, 0x10}, 457 {0xd1, 0x5d, 0x14, 0x00, 0x00, 0x00, 0x00, 0x10},
395 {0xD1, 0x5D, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10}, 458 {0xd1, 0x5d, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10},
396 {0xD1, 0x5D, 0x18, 0x00, 0x00, 0x00, 0x00, 0x10}, 459 {0xd1, 0x5d, 0x18, 0x00, 0x00, 0x00, 0x00, 0x10},
397 {0xD1, 0x5D, 0x1A, 0x00, 0x00, 0x00, 0x00, 0x10}, 460 {0xd1, 0x5d, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x10},
398 {0xD1, 0x5D, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x10}, 461 {0xd1, 0x5d, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x10},
399 {0xB1, 0x5D, 0x32, 0x00, 0x00, 0x00, 0x00, 0x10}, 462 {0xb1, 0x5d, 0x32, 0x00, 0x00, 0x00, 0x00, 0x10},
400 {0xD1, 0x5D, 0x20, 0x91, 0x01, 0x00, 0x00, 0x10}, 463 {0xd1, 0x5d, 0x20, 0x91, 0x01, 0x00, 0x00, 0x10},
401 {0xD1, 0x5D, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10}, 464 {0xd1, 0x5d, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
402 {0xD1, 0x5D, 0x24, 0x00, 0x00, 0x00, 0x00, 0x10}, 465 {0xd1, 0x5d, 0x24, 0x00, 0x00, 0x00, 0x00, 0x10},
403 {0xD1, 0x5D, 0x26, 0x00, 0x00, 0x00, 0x24, 0x10}, 466 {0xd1, 0x5d, 0x26, 0x00, 0x00, 0x00, 0x24, 0x10},
404 {0xD1, 0x5D, 0x2F, 0xF7, 0xB0, 0x00, 0x04, 0x10}, 467 {0xd1, 0x5d, 0x2f, 0xf7, 0xB0, 0x00, 0x04, 0x10},
405 {0xD1, 0x5D, 0x31, 0x00, 0x00, 0x00, 0x00, 0x10}, 468 {0xd1, 0x5d, 0x31, 0x00, 0x00, 0x00, 0x00, 0x10},
406 {0xD1, 0x5D, 0x33, 0x00, 0x00, 0x01, 0x00, 0x10}, 469 {0xd1, 0x5d, 0x33, 0x00, 0x00, 0x01, 0x00, 0x10},
407 {0xB1, 0x5D, 0x3D, 0x06, 0x8F, 0x00, 0x00, 0x10}, 470 {0xb1, 0x5d, 0x3d, 0x06, 0x8f, 0x00, 0x00, 0x10},
408 {0xD1, 0x5D, 0x40, 0x01, 0xE0, 0x00, 0xD1, 0x10}, 471 {0xd1, 0x5d, 0x40, 0x01, 0xe0, 0x00, 0xd1, 0x10},
409 {0xB1, 0x5D, 0x44, 0x00, 0x82, 0x00, 0x00, 0x10}, 472 {0xb1, 0x5d, 0x44, 0x00, 0x82, 0x00, 0x00, 0x10},
410 {0xD1, 0x5D, 0x58, 0x00, 0x78, 0x00, 0x43, 0x10}, 473 {0xd1, 0x5d, 0x58, 0x00, 0x78, 0x00, 0x43, 0x10},
411 {0xD1, 0x5D, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x10}, 474 {0xd1, 0x5d, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x10},
412 {0xD1, 0x5D, 0x5C, 0x00, 0x00, 0x00, 0x00, 0x10}, 475 {0xd1, 0x5d, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x10},
413 {0xD1, 0x5D, 0x5E, 0x00, 0x00, 0xA3, 0x1D, 0x10}, 476 {0xd1, 0x5d, 0x5e, 0x00, 0x00, 0xa3, 0x1d, 0x10},
414 {0xB1, 0x5D, 0x62, 0x04, 0x11, 0x00, 0x00, 0x10}, 477 {0xb1, 0x5d, 0x62, 0x04, 0x11, 0x00, 0x00, 0x10},
415 478
416 {0xB1, 0x5D, 0x20, 0x91, 0x01, 0x00, 0x00, 0x10}, 479 {0xb1, 0x5d, 0x20, 0x91, 0x01, 0x00, 0x00, 0x10},
417 {0xB1, 0x5D, 0x20, 0x11, 0x01, 0x00, 0x00, 0x10}, 480 {0xb1, 0x5d, 0x20, 0x11, 0x01, 0x00, 0x00, 0x10},
418 {0xB1, 0x5D, 0x09, 0x00, 0x64, 0x00, 0x00, 0x10}, 481 {0xb1, 0x5d, 0x09, 0x00, 0x64, 0x00, 0x00, 0x10},
419 {0xD1, 0x5D, 0x2B, 0x00, 0xA0, 0x00, 0xB0, 0x10}, 482 {0xd1, 0x5d, 0x2b, 0x00, 0xa0, 0x00, 0xb0, 0x10},
420 {0xD1, 0x5D, 0x2D, 0x00, 0xA0, 0x00, 0xA0, 0x10}, 483 {0xd1, 0x5d, 0x2d, 0x00, 0xa0, 0x00, 0xa0, 0x10},
421 484
422 {0xB1, 0x5D, 0x0A, 0x00, 0x02, 0x00, 0x00, 0x10}, /* sensor clck ?2 */ 485 {0xb1, 0x5d, 0x0a, 0x00, 0x02, 0x00, 0x00, 0x10}, /* sensor clck ?2 */
423 {0xB1, 0x5D, 0x06, 0x00, 0x30, 0x00, 0x00, 0x10}, 486 {0xb1, 0x5d, 0x06, 0x00, 0x30, 0x00, 0x00, 0x10},
424 {0xB1, 0x5D, 0x05, 0x00, 0x0A, 0x00, 0x00, 0x10}, 487 {0xb1, 0x5d, 0x05, 0x00, 0x0a, 0x00, 0x00, 0x10},
425 {0xB1, 0x5D, 0x09, 0x02, 0x35, 0x00, 0x00, 0x10}, /* exposure 2 */ 488 {0xb1, 0x5d, 0x09, 0x02, 0x35, 0x00, 0x00, 0x10}, /* exposure 2 */
426 489
427 {0xD1, 0x5D, 0x2B, 0x00, 0xB9, 0x00, 0xE3, 0x10}, 490 {0xd1, 0x5d, 0x2b, 0x00, 0xb9, 0x00, 0xe3, 0x10},
428 {0xD1, 0x5D, 0x2D, 0x00, 0x5f, 0x00, 0xB9, 0x10}, /* 42 */ 491 {0xd1, 0x5d, 0x2d, 0x00, 0x5f, 0x00, 0xb9, 0x10}, /* 42 */
429/* {0xB1, 0x5D, 0x35, 0x00, 0x67, 0x00, 0x00, 0x10}, * gain orig */ 492/* {0xb1, 0x5d, 0x35, 0x00, 0x67, 0x00, 0x00, 0x10}, * gain orig */
430/* {0xB1, 0x5D, 0x35, 0x00, 0x20, 0x00, 0x00, 0x10}, * gain */ 493/* {0xb1, 0x5d, 0x35, 0x00, 0x20, 0x00, 0x00, 0x10}, * gain */
431 {0xB1, 0x5D, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10}, /* update */ 494 {0xb1, 0x5d, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10}, /* update */
432 {0xB1, 0x5D, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10}, /* sensor on */ 495 {0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10}, /* sensor on */
433 {} 496 {}
434}; 497};
435static const __u8 mo4000_sensor_init[][8] = { 498static const u8 mo4000_sensor_init[][8] = {
436 {0xa1, 0x21, 0x01, 0x02, 0x00, 0x00, 0x00, 0x10}, 499 {0xa1, 0x21, 0x01, 0x02, 0x00, 0x00, 0x00, 0x10},
437 {0xa1, 0x21, 0x02, 0x00, 0x00, 0x00, 0x00, 0x10}, 500 {0xa1, 0x21, 0x02, 0x00, 0x00, 0x00, 0x00, 0x10},
438 {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10}, 501 {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
@@ -455,7 +518,49 @@ static const __u8 mo4000_sensor_init[][8] = {
455 {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10}, 518 {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
456 {} 519 {}
457}; 520};
458static __u8 om6802_sensor_init[][8] = { 521static const u8 mt9v111_sensor_init[][8] = {
522 {0xb1, 0x5c, 0x0d, 0x00, 0x01, 0x00, 0x00, 0x10}, /* reset? */
523 /* delay 20 ms */
524 {0xb1, 0x5c, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x10},
525 {0xb1, 0x5c, 0x01, 0x00, 0x01, 0x00, 0x00, 0x10}, /* IFP select */
526 {0xb1, 0x5c, 0x08, 0x04, 0x80, 0x00, 0x00, 0x10}, /* output fmt ctrl */
527 {0xb1, 0x5c, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10}, /* op mode ctrl */
528 {0xb1, 0x5c, 0x02, 0x00, 0x16, 0x00, 0x00, 0x10},
529 {0xb1, 0x5c, 0x03, 0x01, 0xe1, 0x00, 0x00, 0x10},
530 {0xb1, 0x5c, 0x04, 0x02, 0x81, 0x00, 0x00, 0x10},
531 {0xb1, 0x5c, 0x05, 0x00, 0x04, 0x00, 0x00, 0x10},
532 {0xb1, 0x5c, 0x01, 0x00, 0x04, 0x00, 0x00, 0x10}, /* sensor select */
533 {0xb1, 0x5c, 0x02, 0x00, 0x16, 0x00, 0x00, 0x10},
534 {0xb1, 0x5c, 0x03, 0x01, 0xe6, 0x00, 0x00, 0x10},
535 {0xb1, 0x5c, 0x04, 0x02, 0x86, 0x00, 0x00, 0x10},
536 {0xb1, 0x5c, 0x05, 0x00, 0x04, 0x00, 0x00, 0x10},
537 {0xb1, 0x5c, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10},
538 {0xb1, 0x5c, 0x08, 0x00, 0x08, 0x00, 0x00, 0x10}, /* row start */
539 {0xb1, 0x5c, 0x0e, 0x00, 0x08, 0x00, 0x00, 0x10},
540 {0xb1, 0x5c, 0x02, 0x00, 0x16, 0x00, 0x00, 0x10}, /* col start */
541 {0xb1, 0x5c, 0x03, 0x01, 0xe7, 0x00, 0x00, 0x10}, /* window height */
542 {0xb1, 0x5c, 0x04, 0x02, 0x87, 0x00, 0x00, 0x10}, /* window width */
543 {0xb1, 0x5c, 0x07, 0x30, 0x02, 0x00, 0x00, 0x10}, /* output ctrl */
544 {0xb1, 0x5c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x10}, /* shutter delay */
545 {0xb1, 0x5c, 0x12, 0x00, 0xb0, 0x00, 0x00, 0x10}, /* zoom col start */
546 {0xb1, 0x5c, 0x13, 0x00, 0x7c, 0x00, 0x00, 0x10}, /* zoom row start */
547 {0xb1, 0x5c, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x10}, /* digital zoom */
548 {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10}, /* read mode */
549 {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
550 /*******/
551 {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
552 {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
553 {0xb1, 0x5c, 0x09, 0x01, 0x2c, 0x00, 0x00, 0x10},
554 {0xd1, 0x5c, 0x2b, 0x00, 0x33, 0x00, 0xa0, 0x10}, /* green1 gain */
555 {0xd1, 0x5c, 0x2d, 0x00, 0xa0, 0x00, 0x33, 0x10}, /* red gain */
556 /*******/
557 {0xb1, 0x5c, 0x06, 0x00, 0x1e, 0x00, 0x00, 0x10}, /* vert blanking */
558 {0xb1, 0x5c, 0x05, 0x00, 0x0a, 0x00, 0x00, 0x10}, /* horiz blanking */
559 {0xd1, 0x5c, 0x2c, 0x00, 0xad, 0x00, 0xad, 0x10}, /* blue gain */
560 {0xb1, 0x5c, 0x35, 0x01, 0xc0, 0x00, 0x00, 0x10}, /* global gain */
561 {}
562};
563static const u8 om6802_sensor_init[][8] = {
459 {0xa0, 0x34, 0x90, 0x05, 0x00, 0x00, 0x00, 0x10}, 564 {0xa0, 0x34, 0x90, 0x05, 0x00, 0x00, 0x00, 0x10},
460 {0xa0, 0x34, 0x49, 0x85, 0x00, 0x00, 0x00, 0x10}, 565 {0xa0, 0x34, 0x49, 0x85, 0x00, 0x00, 0x00, 0x10},
461 {0xa0, 0x34, 0x5a, 0xc0, 0x00, 0x00, 0x00, 0x10}, 566 {0xa0, 0x34, 0x5a, 0xc0, 0x00, 0x00, 0x00, 0x10},
@@ -489,7 +594,7 @@ static __u8 om6802_sensor_init[][8] = {
489/* {0xa0, 0x34, 0x69, 0x01, 0x00, 0x00, 0x00, 0x10}, */ 594/* {0xa0, 0x34, 0x69, 0x01, 0x00, 0x00, 0x00, 0x10}, */
490 {} 595 {}
491}; 596};
492static const __u8 ov7630_sensor_init[][8] = { 597static const u8 ov7630_sensor_init[][8] = {
493 {0xa1, 0x21, 0x76, 0x01, 0x00, 0x00, 0x00, 0x10}, 598 {0xa1, 0x21, 0x76, 0x01, 0x00, 0x00, 0x00, 0x10},
494 {0xa1, 0x21, 0x12, 0xc8, 0x00, 0x00, 0x00, 0x10}, 599 {0xa1, 0x21, 0x12, 0xc8, 0x00, 0x00, 0x00, 0x10},
495/* win: delay 20ms */ 600/* win: delay 20ms */
@@ -543,7 +648,7 @@ static const __u8 ov7630_sensor_init[][8] = {
543 {} 648 {}
544}; 649};
545 650
546static const __u8 ov7648_sensor_init[][8] = { 651static const u8 ov7648_sensor_init[][8] = {
547 {0xa1, 0x21, 0x76, 0x00, 0x00, 0x00, 0x00, 0x10}, 652 {0xa1, 0x21, 0x76, 0x00, 0x00, 0x00, 0x00, 0x10},
548 {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset */ 653 {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset */
549 {0xa1, 0x21, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10}, 654 {0xa1, 0x21, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
@@ -572,7 +677,8 @@ static const __u8 ov7648_sensor_init[][8] = {
572 {0xb1, 0x21, 0x2d, 0x85, 0x00, 0x00, 0x00, 0x10}, 677 {0xb1, 0x21, 0x2d, 0x85, 0x00, 0x00, 0x00, 0x10},
573/*...*/ 678/*...*/
574/* {0xa1, 0x21, 0x12, 0x08, 0x00, 0x00, 0x00, 0x10}, jfm done */ 679/* {0xa1, 0x21, 0x12, 0x08, 0x00, 0x00, 0x00, 0x10}, jfm done */
575/* {0xa1, 0x21, 0x75, 0x06, 0x00, 0x00, 0x00, 0x10}, jfm done */ 680/* {0xa1, 0x21, 0x75, 0x06, 0x00, 0x00, 0x00, 0x10}, * COMN
681 * set by setvflip */
576 {0xa1, 0x21, 0x19, 0x02, 0x00, 0x00, 0x00, 0x10}, 682 {0xa1, 0x21, 0x19, 0x02, 0x00, 0x00, 0x00, 0x10},
577 {0xa1, 0x21, 0x10, 0x32, 0x00, 0x00, 0x00, 0x10}, 683 {0xa1, 0x21, 0x10, 0x32, 0x00, 0x00, 0x00, 0x10},
578/* {0xa1, 0x21, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */ 684/* {0xa1, 0x21, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
@@ -589,7 +695,7 @@ static const __u8 ov7648_sensor_init[][8] = {
589 {} 695 {}
590}; 696};
591 697
592static const __u8 ov7660_sensor_init[][8] = { 698static const u8 ov7660_sensor_init[][8] = {
593 {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset SCCB */ 699 {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset SCCB */
594/* (delay 20ms) */ 700/* (delay 20ms) */
595 {0xa1, 0x21, 0x12, 0x05, 0x00, 0x00, 0x00, 0x10}, 701 {0xa1, 0x21, 0x12, 0x05, 0x00, 0x00, 0x00, 0x10},
@@ -678,28 +784,92 @@ static const __u8 ov7660_sensor_init[][8] = {
678 {} 784 {}
679}; 785};
680 786
681static const __u8 qtable4[] = { 787static const u8 sp80708_sensor_init[][8] = {
682 0x06, 0x04, 0x04, 0x06, 0x04, 0x04, 0x06, 0x06, 0x06, 0x06, 0x08, 0x06, 788 {0xa1, 0x18, 0x06, 0xf9, 0x00, 0x00, 0x00, 0x10},
683 0x06, 0x08, 0x0A, 0x11, 789 {0xa1, 0x18, 0x09, 0x1f, 0x00, 0x00, 0x00, 0x10},
684 0x0A, 0x0A, 0x08, 0x08, 0x0A, 0x15, 0x0F, 0x0F, 0x0C, 0x11, 0x19, 0x15, 790 {0xa1, 0x18, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x10},
685 0x19, 0x19, 0x17, 0x15, 791 {0xa1, 0x18, 0x0d, 0xc0, 0x00, 0x00, 0x00, 0x10},
686 0x17, 0x17, 0x1B, 0x1D, 0x25, 0x21, 0x1B, 0x1D, 0x23, 0x1D, 0x17, 0x17, 792 {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
687 0x21, 0x2E, 0x21, 0x23, 793 {0xa1, 0x18, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x10},
688 0x27, 0x29, 0x2C, 0x2C, 0x2C, 0x19, 0x1F, 0x30, 0x32, 0x2E, 0x29, 0x32, 794 {0xa1, 0x18, 0x10, 0x40, 0x00, 0x00, 0x00, 0x10},
689 0x25, 0x29, 0x2C, 0x29, 795 {0xa1, 0x18, 0x11, 0x4e, 0x00, 0x00, 0x00, 0x10},
690 0x06, 0x08, 0x08, 0x0A, 0x08, 0x0A, 0x13, 0x0A, 0x0A, 0x13, 0x29, 0x1B, 796 {0xa1, 0x18, 0x12, 0x53, 0x00, 0x00, 0x00, 0x10},
691 0x17, 0x1B, 0x29, 0x29, 797 {0xa1, 0x18, 0x15, 0x80, 0x00, 0x00, 0x00, 0x10},
692 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 798 {0xa1, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x10},
693 0x29, 0x29, 0x29, 0x29, 799 {0xa1, 0x18, 0x19, 0x18, 0x00, 0x00, 0x00, 0x10},
694 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 800 {0xa1, 0x18, 0x1a, 0x10, 0x00, 0x00, 0x00, 0x10},
695 0x29, 0x29, 0x29, 0x29, 801 {0xa1, 0x18, 0x1b, 0x10, 0x00, 0x00, 0x00, 0x10},
696 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 802 {0xa1, 0x18, 0x1c, 0x28, 0x00, 0x00, 0x00, 0x10},
697 0x29, 0x29, 0x29, 0x29 803 {0xa1, 0x18, 0x1d, 0x02, 0x00, 0x00, 0x00, 0x10},
804 {0xa1, 0x18, 0x1e, 0x10, 0x00, 0x00, 0x00, 0x10},
805 {0xa1, 0x18, 0x26, 0x04, 0x00, 0x00, 0x00, 0x10},
806 {0xa1, 0x18, 0x27, 0x1e, 0x00, 0x00, 0x00, 0x10},
807 {0xa1, 0x18, 0x28, 0x5a, 0x00, 0x00, 0x00, 0x10},
808 {0xa1, 0x18, 0x29, 0x28, 0x00, 0x00, 0x00, 0x10},
809 {0xa1, 0x18, 0x2a, 0x78, 0x00, 0x00, 0x00, 0x10},
810 {0xa1, 0x18, 0x2b, 0x01, 0x00, 0x00, 0x00, 0x10},
811 {0xa1, 0x18, 0x2c, 0xf7, 0x00, 0x00, 0x00, 0x10},
812 {0xa1, 0x18, 0x2d, 0x2d, 0x00, 0x00, 0x00, 0x10},
813 {0xa1, 0x18, 0x2e, 0xd5, 0x00, 0x00, 0x00, 0x10},
814 {0xa1, 0x18, 0x39, 0x42, 0x00, 0x00, 0x00, 0x10},
815 {0xa1, 0x18, 0x3a, 0x67, 0x00, 0x00, 0x00, 0x10},
816 {0xa1, 0x18, 0x3b, 0x87, 0x00, 0x00, 0x00, 0x10},
817 {0xa1, 0x18, 0x3c, 0xa3, 0x00, 0x00, 0x00, 0x10},
818 {0xa1, 0x18, 0x3d, 0xb0, 0x00, 0x00, 0x00, 0x10},
819 {0xa1, 0x18, 0x3e, 0xbc, 0x00, 0x00, 0x00, 0x10},
820 {0xa1, 0x18, 0x3f, 0xc8, 0x00, 0x00, 0x00, 0x10},
821 {0xa1, 0x18, 0x40, 0xd4, 0x00, 0x00, 0x00, 0x10},
822 {0xa1, 0x18, 0x41, 0xdf, 0x00, 0x00, 0x00, 0x10},
823 {0xa1, 0x18, 0x42, 0xea, 0x00, 0x00, 0x00, 0x10},
824 {0xa1, 0x18, 0x43, 0xf5, 0x00, 0x00, 0x00, 0x10},
825 {0xa1, 0x18, 0x45, 0x80, 0x00, 0x00, 0x00, 0x10},
826 {0xa1, 0x18, 0x46, 0x60, 0x00, 0x00, 0x00, 0x10},
827 {0xa1, 0x18, 0x47, 0x50, 0x00, 0x00, 0x00, 0x10},
828 {0xa1, 0x18, 0x48, 0x30, 0x00, 0x00, 0x00, 0x10},
829 {0xa1, 0x18, 0x49, 0x01, 0x00, 0x00, 0x00, 0x10},
830 {0xa1, 0x18, 0x4d, 0xae, 0x00, 0x00, 0x00, 0x10},
831 {0xa1, 0x18, 0x4e, 0x03, 0x00, 0x00, 0x00, 0x10},
832 {0xa1, 0x18, 0x4f, 0x66, 0x00, 0x00, 0x00, 0x10},
833 {0xa1, 0x18, 0x50, 0x1c, 0x00, 0x00, 0x00, 0x10},
834 {0xa1, 0x18, 0x44, 0x10, 0x00, 0x00, 0x00, 0x10},
835 {0xa1, 0x18, 0x4a, 0x30, 0x00, 0x00, 0x00, 0x10},
836 {0xa1, 0x18, 0x51, 0x80, 0x00, 0x00, 0x00, 0x10},
837 {0xa1, 0x18, 0x52, 0x80, 0x00, 0x00, 0x00, 0x10},
838 {0xa1, 0x18, 0x53, 0x80, 0x00, 0x00, 0x00, 0x10},
839 {0xa1, 0x18, 0x54, 0x80, 0x00, 0x00, 0x00, 0x10},
840 {0xa1, 0x18, 0x55, 0x80, 0x00, 0x00, 0x00, 0x10},
841 {0xa1, 0x18, 0x56, 0x80, 0x00, 0x00, 0x00, 0x10},
842 {0xa1, 0x18, 0x57, 0xe0, 0x00, 0x00, 0x00, 0x10},
843 {0xa1, 0x18, 0x58, 0xc0, 0x00, 0x00, 0x00, 0x10},
844 {0xa1, 0x18, 0x59, 0xab, 0x00, 0x00, 0x00, 0x10},
845 {0xa1, 0x18, 0x5a, 0xa0, 0x00, 0x00, 0x00, 0x10},
846 {0xa1, 0x18, 0x5b, 0x99, 0x00, 0x00, 0x00, 0x10},
847 {0xa1, 0x18, 0x5c, 0x90, 0x00, 0x00, 0x00, 0x10},
848 {0xa1, 0x18, 0x5e, 0x24, 0x00, 0x00, 0x00, 0x10},
849 {0xa1, 0x18, 0x5f, 0x00, 0x00, 0x00, 0x00, 0x10},
850 {0xa1, 0x18, 0x60, 0x00, 0x00, 0x00, 0x00, 0x10},
851 {0xa1, 0x18, 0x61, 0x73, 0x00, 0x00, 0x00, 0x10},
852 {0xa1, 0x18, 0x63, 0x42, 0x00, 0x00, 0x00, 0x10},
853 {0xa1, 0x18, 0x64, 0x42, 0x00, 0x00, 0x00, 0x10},
854 {0xa1, 0x18, 0x65, 0x42, 0x00, 0x00, 0x00, 0x10},
855 {0xa1, 0x18, 0x66, 0x24, 0x00, 0x00, 0x00, 0x10},
856 {0xa1, 0x18, 0x67, 0x24, 0x00, 0x00, 0x00, 0x10},
857 {0xa1, 0x18, 0x68, 0x08, 0x00, 0x00, 0x00, 0x10},
858 {0xa1, 0x18, 0x2f, 0xc9, 0x00, 0x00, 0x00, 0x10},
859 /********/
860 {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
861 {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
862 {0xa1, 0x18, 0x03, 0x01, 0x00, 0x00, 0x00, 0x10},
863 {0xa1, 0x18, 0x04, 0xa4, 0x00, 0x00, 0x00, 0x10},
864 {0xa1, 0x18, 0x14, 0x3f, 0x00, 0x00, 0x00, 0x10},
865 {0xa1, 0x18, 0x5d, 0x80, 0x00, 0x00, 0x00, 0x10},
866 {0xb1, 0x18, 0x11, 0x40, 0x40, 0x00, 0x00, 0x10},
867 {}
698}; 868};
699 869
700/* read <len> bytes to gspca_dev->usb_buf */ 870/* read <len> bytes to gspca_dev->usb_buf */
701static void reg_r(struct gspca_dev *gspca_dev, 871static void reg_r(struct gspca_dev *gspca_dev,
702 __u16 value, int len) 872 u16 value, int len)
703{ 873{
704#ifdef GSPCA_DEBUG 874#ifdef GSPCA_DEBUG
705 if (len > USB_BUF_SZ) { 875 if (len > USB_BUF_SZ) {
@@ -718,10 +888,10 @@ static void reg_r(struct gspca_dev *gspca_dev,
718} 888}
719 889
720static void reg_w1(struct gspca_dev *gspca_dev, 890static void reg_w1(struct gspca_dev *gspca_dev,
721 __u16 value, 891 u16 value,
722 __u8 data) 892 u8 data)
723{ 893{
724 PDEBUG(D_USBO, "reg_w1 [%02x] = %02x", value, data); 894 PDEBUG(D_USBO, "reg_w1 [%04x] = %02x", value, data);
725 gspca_dev->usb_buf[0] = data; 895 gspca_dev->usb_buf[0] = data;
726 usb_control_msg(gspca_dev->dev, 896 usb_control_msg(gspca_dev->dev,
727 usb_sndctrlpipe(gspca_dev->dev, 0), 897 usb_sndctrlpipe(gspca_dev->dev, 0),
@@ -733,11 +903,11 @@ static void reg_w1(struct gspca_dev *gspca_dev,
733 500); 903 500);
734} 904}
735static void reg_w(struct gspca_dev *gspca_dev, 905static void reg_w(struct gspca_dev *gspca_dev,
736 __u16 value, 906 u16 value,
737 const __u8 *buffer, 907 const u8 *buffer,
738 int len) 908 int len)
739{ 909{
740 PDEBUG(D_USBO, "reg_w [%02x] = %02x %02x ..", 910 PDEBUG(D_USBO, "reg_w [%04x] = %02x %02x ..",
741 value, buffer[0], buffer[1]); 911 value, buffer[0], buffer[1]);
742#ifdef GSPCA_DEBUG 912#ifdef GSPCA_DEBUG
743 if (len > USB_BUF_SZ) { 913 if (len > USB_BUF_SZ) {
@@ -756,7 +926,7 @@ static void reg_w(struct gspca_dev *gspca_dev,
756} 926}
757 927
758/* I2C write 1 byte */ 928/* I2C write 1 byte */
759static void i2c_w1(struct gspca_dev *gspca_dev, __u8 reg, __u8 val) 929static void i2c_w1(struct gspca_dev *gspca_dev, u8 reg, u8 val)
760{ 930{
761 struct sd *sd = (struct sd *) gspca_dev; 931 struct sd *sd = (struct sd *) gspca_dev;
762 932
@@ -781,7 +951,7 @@ static void i2c_w1(struct gspca_dev *gspca_dev, __u8 reg, __u8 val)
781 951
782/* I2C write 8 bytes */ 952/* I2C write 8 bytes */
783static void i2c_w8(struct gspca_dev *gspca_dev, 953static void i2c_w8(struct gspca_dev *gspca_dev,
784 const __u8 *buffer) 954 const u8 *buffer)
785{ 955{
786 memcpy(gspca_dev->usb_buf, buffer, 8); 956 memcpy(gspca_dev->usb_buf, buffer, 8);
787 usb_control_msg(gspca_dev->dev, 957 usb_control_msg(gspca_dev->dev,
@@ -795,10 +965,10 @@ static void i2c_w8(struct gspca_dev *gspca_dev,
795} 965}
796 966
797/* read 5 bytes in gspca_dev->usb_buf */ 967/* read 5 bytes in gspca_dev->usb_buf */
798static void i2c_r5(struct gspca_dev *gspca_dev, __u8 reg) 968static void i2c_r5(struct gspca_dev *gspca_dev, u8 reg)
799{ 969{
800 struct sd *sd = (struct sd *) gspca_dev; 970 struct sd *sd = (struct sd *) gspca_dev;
801 __u8 mode[8]; 971 u8 mode[8];
802 972
803 mode[0] = 0x81 | 0x10; 973 mode[0] = 0x81 | 0x10;
804 mode[1] = sd->i2c_base; 974 mode[1] = sd->i2c_base;
@@ -817,7 +987,7 @@ static void i2c_r5(struct gspca_dev *gspca_dev, __u8 reg)
817 reg_r(gspca_dev, 0x0a, 5); 987 reg_r(gspca_dev, 0x0a, 5);
818} 988}
819 989
820static int probesensor(struct gspca_dev *gspca_dev) 990static int hv7131r_probe(struct gspca_dev *gspca_dev)
821{ 991{
822 i2c_w1(gspca_dev, 0x02, 0); /* sensor wakeup */ 992 i2c_w1(gspca_dev, 0x02, 0); /* sensor wakeup */
823 msleep(10); 993 msleep(10);
@@ -839,16 +1009,66 @@ static int probesensor(struct gspca_dev *gspca_dev)
839 return -ENODEV; 1009 return -ENODEV;
840} 1010}
841 1011
1012static void mi0360_probe(struct gspca_dev *gspca_dev)
1013{
1014 struct sd *sd = (struct sd *) gspca_dev;
1015 int i, j;
1016 u16 val = 0;
1017 static const u8 probe_tb[][4][8] = {
1018 { /* mi0360 */
1019 {0xb0, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10},
1020 {0x90, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
1021 {0xa2, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
1022 {0xb0, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10}
1023 },
1024 { /* mt9v111 */
1025 {0xb0, 0x5c, 0x01, 0x00, 0x04, 0x00, 0x00, 0x10},
1026 {0x90, 0x5c, 0x36, 0x00, 0x00, 0x00, 0x00, 0x10},
1027 {0xa2, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
1028 {}
1029 },
1030 };
1031
1032 for (i = 0; i < ARRAY_SIZE(probe_tb); i++) {
1033 reg_w1(gspca_dev, 0x17, 0x62);
1034 reg_w1(gspca_dev, 0x01, 0x08);
1035 for (j = 0; j < 3; j++)
1036 i2c_w8(gspca_dev, probe_tb[i][j]);
1037 msleep(2);
1038 reg_r(gspca_dev, 0x0a, 5);
1039 val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
1040 if (probe_tb[i][3][0] != 0)
1041 i2c_w8(gspca_dev, probe_tb[i][3]);
1042 reg_w1(gspca_dev, 0x01, 0x29);
1043 reg_w1(gspca_dev, 0x17, 0x42);
1044 if (val != 0xffff)
1045 break;
1046 }
1047 switch (val) {
1048 case 0x823a:
1049 PDEBUG(D_PROBE, "Sensor mt9v111");
1050 sd->sensor = SENSOR_MT9V111;
1051 sd->i2c_base = 0x5c;
1052 break;
1053 case 0x8243:
1054 PDEBUG(D_PROBE, "Sensor mi0360");
1055 break;
1056 default:
1057 PDEBUG(D_PROBE, "Unknown sensor %04x - forced to mi0360", val);
1058 break;
1059 }
1060}
1061
842static int configure_gpio(struct gspca_dev *gspca_dev, 1062static int configure_gpio(struct gspca_dev *gspca_dev,
843 const __u8 *sn9c1xx) 1063 const u8 *sn9c1xx)
844{ 1064{
845 struct sd *sd = (struct sd *) gspca_dev; 1065 struct sd *sd = (struct sd *) gspca_dev;
846 const __u8 *reg9a; 1066 const u8 *reg9a;
847 static const __u8 reg9a_def[] = 1067 static const u8 reg9a_def[] =
848 {0x08, 0x40, 0x20, 0x10, 0x00, 0x04}; 1068 {0x08, 0x40, 0x20, 0x10, 0x00, 0x04};
849 static const __u8 reg9a_sn9c325[] = 1069 static const u8 reg9a_sn9c325[] =
850 {0x0a, 0x40, 0x38, 0x30, 0x00, 0x20}; 1070 {0x0a, 0x40, 0x38, 0x30, 0x00, 0x20};
851 static const __u8 regd4[] = {0x60, 0x00, 0x00}; 1071 static const u8 regd4[] = {0x60, 0x00, 0x00};
852 1072
853 reg_w1(gspca_dev, 0xf1, 0x00); 1073 reg_w1(gspca_dev, 0xf1, 0x00);
854 reg_w1(gspca_dev, 0x01, sn9c1xx[1]); 1074 reg_w1(gspca_dev, 0x01, sn9c1xx[1]);
@@ -872,6 +1092,12 @@ static int configure_gpio(struct gspca_dev *gspca_dev,
872 reg_w(gspca_dev, 0x03, &sn9c1xx[3], 0x0f); 1092 reg_w(gspca_dev, 0x03, &sn9c1xx[3], 0x0f);
873 1093
874 switch (sd->sensor) { 1094 switch (sd->sensor) {
1095 case SENSOR_MT9V111:
1096 reg_w1(gspca_dev, 0x01, 0x61);
1097 reg_w1(gspca_dev, 0x17, 0x61);
1098 reg_w1(gspca_dev, 0x01, 0x60);
1099 reg_w1(gspca_dev, 0x01, 0x40);
1100 break;
875 case SENSOR_OM6802: 1101 case SENSOR_OM6802:
876 reg_w1(gspca_dev, 0x02, 0x71); 1102 reg_w1(gspca_dev, 0x02, 0x71);
877 reg_w1(gspca_dev, 0x01, 0x42); 1103 reg_w1(gspca_dev, 0x01, 0x42);
@@ -900,12 +1126,20 @@ static int configure_gpio(struct gspca_dev *gspca_dev,
900 break; 1126 break;
901 } 1127 }
902 /* fall thru */ 1128 /* fall thru */
1129 case SENSOR_SP80708:
1130 reg_w1(gspca_dev, 0x01, 0x63);
1131 reg_w1(gspca_dev, 0x17, 0x20);
1132 reg_w1(gspca_dev, 0x01, 0x62);
1133 reg_w1(gspca_dev, 0x01, 0x42);
1134 mdelay(100);
1135 reg_w1(gspca_dev, 0x02, 0x62);
1136 break;
903 default: 1137 default:
904 reg_w1(gspca_dev, 0x01, 0x43); 1138 reg_w1(gspca_dev, 0x01, 0x43);
905 reg_w1(gspca_dev, 0x17, 0x61); 1139 reg_w1(gspca_dev, 0x17, 0x61);
906 reg_w1(gspca_dev, 0x01, 0x42); 1140 reg_w1(gspca_dev, 0x01, 0x42);
907 if (sd->sensor == SENSOR_HV7131R) { 1141 if (sd->sensor == SENSOR_HV7131R) {
908 if (probesensor(gspca_dev) < 0) 1142 if (hv7131r_probe(gspca_dev) < 0)
909 return -ENODEV; 1143 return -ENODEV;
910 } 1144 }
911 break; 1145 break;
@@ -916,7 +1150,7 @@ static int configure_gpio(struct gspca_dev *gspca_dev,
916static void hv7131R_InitSensor(struct gspca_dev *gspca_dev) 1150static void hv7131R_InitSensor(struct gspca_dev *gspca_dev)
917{ 1151{
918 int i = 0; 1152 int i = 0;
919 static const __u8 SetSensorClk[] = /* 0x08 Mclk */ 1153 static const u8 SetSensorClk[] = /* 0x08 Mclk */
920 { 0xa1, 0x11, 0x01, 0x18, 0x00, 0x00, 0x00, 0x10 }; 1154 { 0xa1, 0x11, 0x01, 0x18, 0x00, 0x00, 0x00, 0x10 };
921 1155
922 while (hv7131r_sensor_init[i][0]) { 1156 while (hv7131r_sensor_init[i][0]) {
@@ -946,6 +1180,19 @@ static void mo4000_InitSensor(struct gspca_dev *gspca_dev)
946 } 1180 }
947} 1181}
948 1182
1183static void mt9v111_InitSensor(struct gspca_dev *gspca_dev)
1184{
1185 int i = 0;
1186
1187 i2c_w8(gspca_dev, mt9v111_sensor_init[i]);
1188 i++;
1189 msleep(20);
1190 while (mt9v111_sensor_init[i][0]) {
1191 i2c_w8(gspca_dev, mt9v111_sensor_init[i]);
1192 i++;
1193 }
1194}
1195
949static void om6802_InitSensor(struct gspca_dev *gspca_dev) 1196static void om6802_InitSensor(struct gspca_dev *gspca_dev)
950{ 1197{
951 int i = 0; 1198 int i = 0;
@@ -1010,6 +1257,19 @@ static void ov7660_InitSensor(struct gspca_dev *gspca_dev)
1010 } 1257 }
1011} 1258}
1012 1259
1260static void sp80708_InitSensor(struct gspca_dev *gspca_dev)
1261{
1262 int i = 0;
1263
1264 i2c_w8(gspca_dev, sp80708_sensor_init[i]); /* reset SCCB */
1265 i++;
1266 msleep(20);
1267 while (sp80708_sensor_init[i][0]) {
1268 i2c_w8(gspca_dev, sp80708_sensor_init[i]);
1269 i++;
1270 }
1271}
1272
1013/* this function is called at probe time */ 1273/* this function is called at probe time */
1014static int sd_config(struct gspca_dev *gspca_dev, 1274static int sd_config(struct gspca_dev *gspca_dev,
1015 const struct usb_device_id *id) 1275 const struct usb_device_id *id)
@@ -1018,7 +1278,6 @@ static int sd_config(struct gspca_dev *gspca_dev,
1018 struct cam *cam; 1278 struct cam *cam;
1019 1279
1020 cam = &gspca_dev->cam; 1280 cam = &gspca_dev->cam;
1021 cam->epaddr = 0x01;
1022 cam->cam_mode = vga_mode; 1281 cam->cam_mode = vga_mode;
1023 cam->nmodes = ARRAY_SIZE(vga_mode); 1282 cam->nmodes = ARRAY_SIZE(vga_mode);
1024 1283
@@ -1026,16 +1285,21 @@ static int sd_config(struct gspca_dev *gspca_dev,
1026 sd->sensor = id->driver_info >> 8; 1285 sd->sensor = id->driver_info >> 8;
1027 sd->i2c_base = id->driver_info; 1286 sd->i2c_base = id->driver_info;
1028 1287
1029 sd->qindex = 4; /* set the quantization table */
1030 sd->brightness = BRIGHTNESS_DEF; 1288 sd->brightness = BRIGHTNESS_DEF;
1031 sd->contrast = CONTRAST_DEF; 1289 sd->contrast = CONTRAST_DEF;
1032 sd->colors = COLOR_DEF; 1290 sd->colors = COLOR_DEF;
1033 sd->blue = BLUE_BALANCE_DEF; 1291 sd->blue = BLUE_BALANCE_DEF;
1034 sd->red = RED_BALANCE_DEF; 1292 sd->red = RED_BALANCE_DEF;
1293 sd->gamma = GAMMA_DEF;
1035 sd->autogain = AUTOGAIN_DEF; 1294 sd->autogain = AUTOGAIN_DEF;
1036 sd->ag_cnt = -1; 1295 sd->ag_cnt = -1;
1037 sd->vflip = VFLIP_DEF; 1296 if (sd->sensor != SENSOR_OV7630)
1297 sd->vflip = 0;
1298 else
1299 sd->vflip = 1;
1038 sd->infrared = INFRARED_DEF; 1300 sd->infrared = INFRARED_DEF;
1301 sd->quality = QUALITY_DEF;
1302 sd->jpegqual = 80;
1039 1303
1040 gspca_dev->ctrl_dis = ctrl_dis[sd->sensor]; 1304 gspca_dev->ctrl_dis = ctrl_dis[sd->sensor];
1041 return 0; 1305 return 0;
@@ -1045,8 +1309,8 @@ static int sd_config(struct gspca_dev *gspca_dev,
1045static int sd_init(struct gspca_dev *gspca_dev) 1309static int sd_init(struct gspca_dev *gspca_dev)
1046{ 1310{
1047 struct sd *sd = (struct sd *) gspca_dev; 1311 struct sd *sd = (struct sd *) gspca_dev;
1048 __u8 regGpio[] = { 0x29, 0x74 }; 1312 u8 regGpio[] = { 0x29, 0x74 };
1049 __u8 regF1; 1313 u8 regF1;
1050 1314
1051 /* setup a selector by bridge */ 1315 /* setup a selector by bridge */
1052 reg_w1(gspca_dev, 0xf1, 0x01); 1316 reg_w1(gspca_dev, 0xf1, 0x01);
@@ -1064,11 +1328,15 @@ static int sd_init(struct gspca_dev *gspca_dev)
1064 case BRIDGE_SN9C105: 1328 case BRIDGE_SN9C105:
1065 if (regF1 != 0x11) 1329 if (regF1 != 0x11)
1066 return -ENODEV; 1330 return -ENODEV;
1331 if (sd->sensor == SENSOR_MI0360)
1332 mi0360_probe(gspca_dev);
1067 reg_w(gspca_dev, 0x01, regGpio, 2); 1333 reg_w(gspca_dev, 0x01, regGpio, 2);
1068 break; 1334 break;
1069 case BRIDGE_SN9C120: 1335 case BRIDGE_SN9C120:
1070 if (regF1 != 0x12) 1336 if (regF1 != 0x12)
1071 return -ENODEV; 1337 return -ENODEV;
1338 if (sd->sensor == SENSOR_MI0360)
1339 mi0360_probe(gspca_dev);
1072 regGpio[1] = 0x70; 1340 regGpio[1] = 0x70;
1073 reg_w(gspca_dev, 0x01, regGpio, 2); 1341 reg_w(gspca_dev, 0x01, regGpio, 2);
1074 break; 1342 break;
@@ -1086,20 +1354,14 @@ static int sd_init(struct gspca_dev *gspca_dev)
1086 return 0; 1354 return 0;
1087} 1355}
1088 1356
1089static unsigned int setexposure(struct gspca_dev *gspca_dev, 1357static u32 setexposure(struct gspca_dev *gspca_dev,
1090 unsigned int expo) 1358 u32 expo)
1091{ 1359{
1092 struct sd *sd = (struct sd *) gspca_dev; 1360 struct sd *sd = (struct sd *) gspca_dev;
1093 static const __u8 doit[] = /* update sensor */
1094 { 0xb1, 0x5d, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10 };
1095 static const __u8 sensorgo[] = /* sensor on */
1096 { 0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10 };
1097 static const __u8 gainMo[] =
1098 { 0xa1, 0x21, 0x00, 0x10, 0x00, 0x00, 0x00, 0x1d };
1099 1361
1100 switch (sd->sensor) { 1362 switch (sd->sensor) {
1101 case SENSOR_HV7131R: { 1363 case SENSOR_HV7131R: {
1102 __u8 Expodoit[] = 1364 u8 Expodoit[] =
1103 { 0xc1, 0x11, 0x25, 0x07, 0x27, 0xc0, 0x00, 0x16 }; 1365 { 0xc1, 0x11, 0x25, 0x07, 0x27, 0xc0, 0x00, 0x16 };
1104 1366
1105 Expodoit[3] = expo >> 16; 1367 Expodoit[3] = expo >> 16;
@@ -1109,8 +1371,12 @@ static unsigned int setexposure(struct gspca_dev *gspca_dev,
1109 break; 1371 break;
1110 } 1372 }
1111 case SENSOR_MI0360: { 1373 case SENSOR_MI0360: {
1112 __u8 expoMi[] = /* exposure 0x0635 -> 4 fp/s 0x10 */ 1374 u8 expoMi[] = /* exposure 0x0635 -> 4 fp/s 0x10 */
1113 { 0xb1, 0x5d, 0x09, 0x06, 0x35, 0x00, 0x00, 0x16 }; 1375 { 0xb1, 0x5d, 0x09, 0x06, 0x35, 0x00, 0x00, 0x16 };
1376 static const u8 doit[] = /* update sensor */
1377 { 0xb1, 0x5d, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10 };
1378 static const u8 sensorgo[] = /* sensor on */
1379 { 0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10 };
1114 1380
1115 if (expo > 0x0635) 1381 if (expo > 0x0635)
1116 expo = 0x0635; 1382 expo = 0x0635;
@@ -1124,10 +1390,12 @@ static unsigned int setexposure(struct gspca_dev *gspca_dev,
1124 break; 1390 break;
1125 } 1391 }
1126 case SENSOR_MO4000: { 1392 case SENSOR_MO4000: {
1127 __u8 expoMof[] = 1393 u8 expoMof[] =
1128 { 0xa1, 0x21, 0x0f, 0x20, 0x00, 0x00, 0x00, 0x10 }; 1394 { 0xa1, 0x21, 0x0f, 0x20, 0x00, 0x00, 0x00, 0x10 };
1129 __u8 expoMo10[] = 1395 u8 expoMo10[] =
1130 { 0xa1, 0x21, 0x10, 0x20, 0x00, 0x00, 0x00, 0x10 }; 1396 { 0xa1, 0x21, 0x10, 0x20, 0x00, 0x00, 0x00, 0x10 };
1397 static const u8 gainMo[] =
1398 { 0xa1, 0x21, 0x00, 0x10, 0x00, 0x00, 0x00, 0x1d };
1131 1399
1132 if (expo > 0x1fff) 1400 if (expo > 0x1fff)
1133 expo = 0x1fff; 1401 expo = 0x1fff;
@@ -1139,14 +1407,27 @@ static unsigned int setexposure(struct gspca_dev *gspca_dev,
1139 | ((expo & 0x0003) << 4); 1407 | ((expo & 0x0003) << 4);
1140 i2c_w8(gspca_dev, expoMo10); 1408 i2c_w8(gspca_dev, expoMo10);
1141 i2c_w8(gspca_dev, gainMo); 1409 i2c_w8(gspca_dev, gainMo);
1142 PDEBUG(D_CONF, "set exposure %d", 1410 PDEBUG(D_FRAM, "set exposure %d",
1143 ((expoMo10[3] & 0x07) << 10) 1411 ((expoMo10[3] & 0x07) << 10)
1144 | (expoMof[3] << 2) 1412 | (expoMof[3] << 2)
1145 | ((expoMo10[3] & 0x30) >> 4)); 1413 | ((expoMo10[3] & 0x30) >> 4));
1146 break; 1414 break;
1147 } 1415 }
1416 case SENSOR_MT9V111: {
1417 u8 expo_c1[] =
1418 { 0xb1, 0x5c, 0x09, 0x00, 0x00, 0x00, 0x00, 0x10 };
1419
1420 if (expo > 0x0280)
1421 expo = 0x0280;
1422 else if (expo < 0x0040)
1423 expo = 0x0040;
1424 expo_c1[3] = expo >> 8;
1425 expo_c1[4] = expo;
1426 i2c_w8(gspca_dev, expo_c1);
1427 break;
1428 }
1148 case SENSOR_OM6802: { 1429 case SENSOR_OM6802: {
1149 __u8 gainOm[] = 1430 u8 gainOm[] =
1150 { 0xa0, 0x34, 0xe5, 0x00, 0x00, 0x00, 0x00, 0x10 }; 1431 { 0xa0, 0x34, 0xe5, 0x00, 0x00, 0x00, 0x00, 0x10 };
1151 1432
1152 if (expo > 0x03ff) 1433 if (expo > 0x03ff)
@@ -1156,7 +1437,7 @@ static unsigned int setexposure(struct gspca_dev *gspca_dev,
1156 gainOm[3] = expo >> 2; 1437 gainOm[3] = expo >> 2;
1157 i2c_w8(gspca_dev, gainOm); 1438 i2c_w8(gspca_dev, gainOm);
1158 reg_w1(gspca_dev, 0x96, (expo >> 5) & 0x1f); 1439 reg_w1(gspca_dev, 0x96, (expo >> 5) & 0x1f);
1159 PDEBUG(D_CONF, "set exposure %d", gainOm[3]); 1440 PDEBUG(D_FRAM, "set exposure %d", gainOm[3]);
1160 break; 1441 break;
1161 } 1442 }
1162 } 1443 }
@@ -1167,7 +1448,7 @@ static void setbrightness(struct gspca_dev *gspca_dev)
1167{ 1448{
1168 struct sd *sd = (struct sd *) gspca_dev; 1449 struct sd *sd = (struct sd *) gspca_dev;
1169 unsigned int expo; 1450 unsigned int expo;
1170 __u8 k2; 1451 u8 k2;
1171 1452
1172 k2 = ((int) sd->brightness - 0x8000) >> 10; 1453 k2 = ((int) sd->brightness - 0x8000) >> 10;
1173 switch (sd->sensor) { 1454 switch (sd->sensor) {
@@ -1184,6 +1465,10 @@ static void setbrightness(struct gspca_dev *gspca_dev)
1184 expo = sd->brightness >> 4; 1465 expo = sd->brightness >> 4;
1185 sd->exposure = setexposure(gspca_dev, expo); 1466 sd->exposure = setexposure(gspca_dev, expo);
1186 break; 1467 break;
1468 case SENSOR_MT9V111:
1469 expo = sd->brightness >> 8;
1470 sd->exposure = setexposure(gspca_dev, expo);
1471 break;
1187 case SENSOR_OM6802: 1472 case SENSOR_OM6802:
1188 expo = sd->brightness >> 6; 1473 expo = sd->brightness >> 6;
1189 sd->exposure = setexposure(gspca_dev, expo); 1474 sd->exposure = setexposure(gspca_dev, expo);
@@ -1191,14 +1476,15 @@ static void setbrightness(struct gspca_dev *gspca_dev)
1191 break; 1476 break;
1192 } 1477 }
1193 1478
1194 reg_w1(gspca_dev, 0x96, k2); /* color matrix Y offset */ 1479 if (sd->sensor != SENSOR_MT9V111)
1480 reg_w1(gspca_dev, 0x96, k2); /* color matrix Y offset */
1195} 1481}
1196 1482
1197static void setcontrast(struct gspca_dev *gspca_dev) 1483static void setcontrast(struct gspca_dev *gspca_dev)
1198{ 1484{
1199 struct sd *sd = (struct sd *) gspca_dev; 1485 struct sd *sd = (struct sd *) gspca_dev;
1200 __u8 k2; 1486 u8 k2;
1201 __u8 contrast[6]; 1487 u8 contrast[6];
1202 1488
1203 k2 = sd->contrast * 0x30 / (CONTRAST_MAX + 1) + 0x10; /* 10..40 */ 1489 k2 = sd->contrast * 0x30 / (CONTRAST_MAX + 1) + 0x10; /* 10..40 */
1204 contrast[0] = (k2 + 1) / 2; /* red */ 1490 contrast[0] = (k2 + 1) / 2; /* red */
@@ -1214,8 +1500,8 @@ static void setcolors(struct gspca_dev *gspca_dev)
1214{ 1500{
1215 struct sd *sd = (struct sd *) gspca_dev; 1501 struct sd *sd = (struct sd *) gspca_dev;
1216 int i, v; 1502 int i, v;
1217 __u8 reg8a[12]; /* U & V gains */ 1503 u8 reg8a[12]; /* U & V gains */
1218 static __s16 uv[6] = { /* same as reg84 in signed decimal */ 1504 static s16 uv[6] = { /* same as reg84 in signed decimal */
1219 -24, -38, 64, /* UR UG UB */ 1505 -24, -38, 64, /* UR UG UB */
1220 62, -51, -9 /* VR VG VB */ 1506 62, -51, -9 /* VR VG VB */
1221 }; 1507 };
@@ -1236,22 +1522,75 @@ static void setredblue(struct gspca_dev *gspca_dev)
1236 reg_w1(gspca_dev, 0x06, sd->blue); 1522 reg_w1(gspca_dev, 0x06, sd->blue);
1237} 1523}
1238 1524
1525static void setgamma(struct gspca_dev *gspca_dev)
1526{
1527 struct sd *sd = (struct sd *) gspca_dev;
1528 int i;
1529 u8 gamma[17];
1530 const u8 *gamma_base;
1531 static const u8 delta[17] = {
1532 0x00, 0x14, 0x1c, 0x1c, 0x1c, 0x1c, 0x1b, 0x1a,
1533 0x18, 0x13, 0x10, 0x0e, 0x08, 0x07, 0x04, 0x02, 0x00
1534 };
1535
1536 switch (sd->sensor) {
1537 case SENSOR_HV7131R:
1538 case SENSOR_MT9V111:
1539 gamma_base = gamma_spec_1;
1540 break;
1541 case SENSOR_SP80708:
1542 gamma_base = gamma_spec_2;
1543 break;
1544 default:
1545 gamma_base = gamma_def;
1546 break;
1547 }
1548
1549 for (i = 0; i < sizeof gamma; i++)
1550 gamma[i] = gamma_base[i]
1551 + delta[i] * (sd->gamma - GAMMA_DEF) / 32;
1552 reg_w(gspca_dev, 0x20, gamma, sizeof gamma);
1553}
1554
1239static void setautogain(struct gspca_dev *gspca_dev) 1555static void setautogain(struct gspca_dev *gspca_dev)
1240{ 1556{
1241 struct sd *sd = (struct sd *) gspca_dev; 1557 struct sd *sd = (struct sd *) gspca_dev;
1242 1558
1243 if (gspca_dev->ctrl_dis & (1 << AUTOGAIN_IDX)) 1559 if (gspca_dev->ctrl_dis & (1 << AUTOGAIN_IDX))
1244 return; 1560 return;
1561 switch (sd->sensor) {
1562 case SENSOR_OV7630:
1563 case SENSOR_OV7648: {
1564 u8 comb;
1565
1566 if (sd->sensor == SENSOR_OV7630)
1567 comb = 0xc0;
1568 else
1569 comb = 0xa0;
1570 if (sd->autogain)
1571 comb |= 0x02;
1572 i2c_w1(&sd->gspca_dev, 0x13, comb);
1573 return;
1574 }
1575 }
1245 if (sd->autogain) 1576 if (sd->autogain)
1246 sd->ag_cnt = AG_CNT_START; 1577 sd->ag_cnt = AG_CNT_START;
1247 else 1578 else
1248 sd->ag_cnt = -1; 1579 sd->ag_cnt = -1;
1249} 1580}
1250 1581
1582/* ov7630/ov7648 only */
1251static void setvflip(struct sd *sd) 1583static void setvflip(struct sd *sd)
1252{ 1584{
1253 i2c_w1(&sd->gspca_dev, 0x75, /* COMN */ 1585 u8 comn;
1254 sd->vflip ? 0x82 : 0x02); 1586
1587 if (sd->sensor == SENSOR_OV7630)
1588 comn = 0x02;
1589 else
1590 comn = 0x06;
1591 if (sd->vflip)
1592 comn |= 0x80;
1593 i2c_w1(&sd->gspca_dev, 0x75, comn);
1255} 1594}
1256 1595
1257static void setinfrared(struct sd *sd) 1596static void setinfrared(struct sd *sd)
@@ -1262,20 +1601,63 @@ static void setinfrared(struct sd *sd)
1262 sd->infrared ? 0x66 : 0x64); 1601 sd->infrared ? 0x66 : 0x64);
1263} 1602}
1264 1603
1604static void setjpegqual(struct gspca_dev *gspca_dev)
1605{
1606 struct sd *sd = (struct sd *) gspca_dev;
1607 int i, sc;
1608
1609 if (sd->jpegqual < 50)
1610 sc = 5000 / sd->jpegqual;
1611 else
1612 sc = 200 - sd->jpegqual * 2;
1613#if USB_BUF_SZ < 64
1614#error "No room enough in usb_buf for quantization table"
1615#endif
1616 for (i = 0; i < 64; i++)
1617 gspca_dev->usb_buf[i] =
1618 (jpeg_head[JPEG_QT0_OFFSET + i] * sc + 50) / 100;
1619 usb_control_msg(gspca_dev->dev,
1620 usb_sndctrlpipe(gspca_dev->dev, 0),
1621 0x08,
1622 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
1623 0x0100, 0,
1624 gspca_dev->usb_buf, 64,
1625 500);
1626 for (i = 0; i < 64; i++)
1627 gspca_dev->usb_buf[i] =
1628 (jpeg_head[JPEG_QT1_OFFSET + i] * sc + 50) / 100;
1629 usb_control_msg(gspca_dev->dev,
1630 usb_sndctrlpipe(gspca_dev->dev, 0),
1631 0x08,
1632 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
1633 0x0140, 0,
1634 gspca_dev->usb_buf, 64,
1635 500);
1636
1637 sd->reg18 ^= 0x40;
1638 reg_w1(gspca_dev, 0x18, sd->reg18);
1639}
1640
1265/* -- start the camera -- */ 1641/* -- start the camera -- */
1266static int sd_start(struct gspca_dev *gspca_dev) 1642static int sd_start(struct gspca_dev *gspca_dev)
1267{ 1643{
1268 struct sd *sd = (struct sd *) gspca_dev; 1644 struct sd *sd = (struct sd *) gspca_dev;
1269 int i; 1645 int i;
1270 __u8 reg1, reg17, reg18; 1646 u8 reg1, reg17;
1271 const __u8 *sn9c1xx; 1647 const u8 *sn9c1xx;
1272 int mode; 1648 int mode;
1273 static const __u8 C0[] = { 0x2d, 0x2d, 0x3a, 0x05, 0x04, 0x3f }; 1649 static const u8 C0[] = { 0x2d, 0x2d, 0x3a, 0x05, 0x04, 0x3f };
1274 static const __u8 CA[] = { 0x28, 0xd8, 0x14, 0xec }; 1650 static const u8 CA[] = { 0x28, 0xd8, 0x14, 0xec };
1275 static const __u8 CE[] = { 0x32, 0xdd, 0x2d, 0xdd }; /* MI0360 */ 1651 static const u8 CE[] = { 0x32, 0xdd, 0x2d, 0xdd }; /* MI0360 */
1276 static const __u8 CE_ov76xx[] = 1652 static const u8 CE_ov76xx[] =
1277 { 0x32, 0xdd, 0x32, 0xdd }; 1653 { 0x32, 0xdd, 0x32, 0xdd };
1278 1654
1655 /* create the JPEG header */
1656 sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL);
1657 jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
1658 0x21); /* JPEG 422 */
1659 jpeg_set_qual(sd->jpeg_hdr, sd->quality);
1660
1279 sn9c1xx = sn_tb[(int) sd->sensor]; 1661 sn9c1xx = sn_tb[(int) sd->sensor];
1280 configure_gpio(gspca_dev, sn9c1xx); 1662 configure_gpio(gspca_dev, sn9c1xx);
1281 1663
@@ -1292,6 +1674,9 @@ static int sd_start(struct gspca_dev *gspca_dev)
1292 reg_w1(gspca_dev, 0xc9, 0x3c); 1674 reg_w1(gspca_dev, 0xc9, 0x3c);
1293 reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]); 1675 reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]);
1294 switch (sd->sensor) { 1676 switch (sd->sensor) {
1677 case SENSOR_MT9V111:
1678 reg17 = 0xe0;
1679 break;
1295 case SENSOR_OV7630: 1680 case SENSOR_OV7630:
1296 reg17 = 0xe2; 1681 reg17 = 0xe2;
1297 break; 1682 break;
@@ -1315,14 +1700,24 @@ static int sd_start(struct gspca_dev *gspca_dev)
1315 reg_w1(gspca_dev, 0x07, sn9c1xx[7]); /* green */ 1700 reg_w1(gspca_dev, 0x07, sn9c1xx[7]); /* green */
1316 reg_w1(gspca_dev, 0x06, sn9c1xx[6]); /* blue */ 1701 reg_w1(gspca_dev, 0x06, sn9c1xx[6]); /* blue */
1317 reg_w1(gspca_dev, 0x14, sn9c1xx[0x14]); 1702 reg_w1(gspca_dev, 0x14, sn9c1xx[0x14]);
1318 reg_w(gspca_dev, 0x20, gamma_def, sizeof gamma_def); 1703
1704 setgamma(gspca_dev);
1705
1319 for (i = 0; i < 8; i++) 1706 for (i = 0; i < 8; i++)
1320 reg_w(gspca_dev, 0x84, reg84, sizeof reg84); 1707 reg_w(gspca_dev, 0x84, reg84, sizeof reg84);
1321 switch (sd->sensor) { 1708 switch (sd->sensor) {
1709 case SENSOR_MT9V111:
1710 reg_w1(gspca_dev, 0x9a, 0x07);
1711 reg_w1(gspca_dev, 0x99, 0x59);
1712 break;
1322 case SENSOR_OV7648: 1713 case SENSOR_OV7648:
1323 reg_w1(gspca_dev, 0x9a, 0x0a); 1714 reg_w1(gspca_dev, 0x9a, 0x0a);
1324 reg_w1(gspca_dev, 0x99, 0x60); 1715 reg_w1(gspca_dev, 0x99, 0x60);
1325 break; 1716 break;
1717 case SENSOR_SP80708:
1718 reg_w1(gspca_dev, 0x9a, 0x05);
1719 reg_w1(gspca_dev, 0x99, 0x59);
1720 break;
1326 case SENSOR_OV7660: 1721 case SENSOR_OV7660:
1327 if (sd->bridge == BRIDGE_SN9C120) { 1722 if (sd->bridge == BRIDGE_SN9C120) {
1328 reg_w1(gspca_dev, 0x9a, 0x05); 1723 reg_w1(gspca_dev, 0x9a, 0x05);
@@ -1358,6 +1753,15 @@ static int sd_start(struct gspca_dev *gspca_dev)
1358/* reg1 = 0x06; * 640 clk 24Mz (done) */ 1753/* reg1 = 0x06; * 640 clk 24Mz (done) */
1359 } 1754 }
1360 break; 1755 break;
1756 case SENSOR_MT9V111:
1757 mt9v111_InitSensor(gspca_dev);
1758 if (mode) {
1759 reg1 = 0x04; /* 320 clk 48Mhz */
1760 } else {
1761/* reg1 = 0x06; * 640 clk 24Mz (done) */
1762 reg17 = 0xc2;
1763 }
1764 break;
1361 case SENSOR_OM6802: 1765 case SENSOR_OM6802:
1362 om6802_InitSensor(gspca_dev); 1766 om6802_InitSensor(gspca_dev);
1363 reg17 = 0x64; /* 640 MCKSIZE */ 1767 reg17 = 0x64; /* 640 MCKSIZE */
@@ -1373,8 +1777,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
1373 reg17 = 0x21; 1777 reg17 = 0x21;
1374/* reg1 = 0x42; * 42 - 46? */ 1778/* reg1 = 0x42; * 42 - 46? */
1375 break; 1779 break;
1376 default: 1780 case SENSOR_OV7660:
1377/* case SENSOR_OV7660: */
1378 ov7660_InitSensor(gspca_dev); 1781 ov7660_InitSensor(gspca_dev);
1379 if (sd->bridge == BRIDGE_SN9C120) { 1782 if (sd->bridge == BRIDGE_SN9C120) {
1380 if (mode) { /* 320x240 - 160x120 */ 1783 if (mode) { /* 320x240 - 160x120 */
@@ -1387,6 +1790,16 @@ static int sd_start(struct gspca_dev *gspca_dev)
1387 * inverse power down */ 1790 * inverse power down */
1388 } 1791 }
1389 break; 1792 break;
1793 default:
1794/* case SENSOR_SP80708: */
1795 sp80708_InitSensor(gspca_dev);
1796 if (mode) {
1797/*?? reg1 = 0x04; * 320 clk 48Mhz */
1798 } else {
1799 reg1 = 0x46; /* 640 clk 48Mz */
1800 reg17 = 0xa2;
1801 }
1802 break;
1390 } 1803 }
1391 reg_w(gspca_dev, 0xc0, C0, 6); 1804 reg_w(gspca_dev, 0xc0, C0, 6);
1392 reg_w(gspca_dev, 0xca, CA, 4); 1805 reg_w(gspca_dev, 0xca, CA, 4);
@@ -1403,20 +1816,13 @@ static int sd_start(struct gspca_dev *gspca_dev)
1403 } 1816 }
1404 1817
1405 /* here change size mode 0 -> VGA; 1 -> CIF */ 1818 /* here change size mode 0 -> VGA; 1 -> CIF */
1406 reg18 = sn9c1xx[0x18] | (mode << 4); 1819 sd->reg18 = sn9c1xx[0x18] | (mode << 4) | 0x40;
1407 reg_w1(gspca_dev, 0x18, reg18 | 0x40); 1820 reg_w1(gspca_dev, 0x18, sd->reg18);
1408 1821 setjpegqual(gspca_dev);
1409 reg_w(gspca_dev, 0x100, qtable4, 0x40);
1410 reg_w(gspca_dev, 0x140, qtable4 + 0x40, 0x40);
1411
1412 reg_w1(gspca_dev, 0x18, reg18);
1413 1822
1414 reg_w1(gspca_dev, 0x17, reg17); 1823 reg_w1(gspca_dev, 0x17, reg17);
1415 reg_w1(gspca_dev, 0x01, reg1); 1824 reg_w1(gspca_dev, 0x01, reg1);
1416 switch (sd->sensor) { 1825 switch (sd->sensor) {
1417 case SENSOR_MI0360:
1418 setinfrared(sd);
1419 break;
1420 case SENSOR_OV7630: 1826 case SENSOR_OV7630:
1421 setvflip(sd); 1827 setvflip(sd);
1422 break; 1828 break;
@@ -1430,14 +1836,14 @@ static int sd_start(struct gspca_dev *gspca_dev)
1430static void sd_stopN(struct gspca_dev *gspca_dev) 1836static void sd_stopN(struct gspca_dev *gspca_dev)
1431{ 1837{
1432 struct sd *sd = (struct sd *) gspca_dev; 1838 struct sd *sd = (struct sd *) gspca_dev;
1433 static const __u8 stophv7131[] = 1839 static const u8 stophv7131[] =
1434 { 0xa1, 0x11, 0x02, 0x09, 0x00, 0x00, 0x00, 0x10 }; 1840 { 0xa1, 0x11, 0x02, 0x09, 0x00, 0x00, 0x00, 0x10 };
1435 static const __u8 stopmi0360[] = 1841 static const u8 stopmi0360[] =
1436 { 0xb1, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10 }; 1842 { 0xb1, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10 };
1437 static const __u8 stopov7648[] = 1843 static const u8 stopov7648[] =
1438 { 0xa1, 0x21, 0x76, 0x20, 0x00, 0x00, 0x00, 0x10 }; 1844 { 0xa1, 0x21, 0x76, 0x20, 0x00, 0x00, 0x00, 0x10 };
1439 __u8 data; 1845 u8 data;
1440 const __u8 *sn9c1xx; 1846 const u8 *sn9c1xx;
1441 1847
1442 data = 0x0b; 1848 data = 0x0b;
1443 switch (sd->sensor) { 1849 switch (sd->sensor) {
@@ -1452,6 +1858,7 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
1452 case SENSOR_OV7648: 1858 case SENSOR_OV7648:
1453 i2c_w8(gspca_dev, stopov7648); 1859 i2c_w8(gspca_dev, stopov7648);
1454 /* fall thru */ 1860 /* fall thru */
1861 case SENSOR_MT9V111:
1455 case SENSOR_OV7630: 1862 case SENSOR_OV7630:
1456 data = 0x29; 1863 data = 0x29;
1457 break; 1864 break;
@@ -1468,13 +1875,20 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
1468 reg_w1(gspca_dev, 0xf1, 0x00); 1875 reg_w1(gspca_dev, 0xf1, 0x00);
1469} 1876}
1470 1877
1878static void sd_stop0(struct gspca_dev *gspca_dev)
1879{
1880 struct sd *sd = (struct sd *) gspca_dev;
1881
1882 kfree(sd->jpeg_hdr);
1883}
1884
1471static void do_autogain(struct gspca_dev *gspca_dev) 1885static void do_autogain(struct gspca_dev *gspca_dev)
1472{ 1886{
1473 struct sd *sd = (struct sd *) gspca_dev; 1887 struct sd *sd = (struct sd *) gspca_dev;
1474 int delta; 1888 int delta;
1475 int expotimes; 1889 int expotimes;
1476 __u8 luma_mean = 130; 1890 u8 luma_mean = 130;
1477 __u8 luma_delta = 20; 1891 u8 luma_delta = 20;
1478 1892
1479 /* Thanks S., without your advice, autobright should not work :) */ 1893 /* Thanks S., without your advice, autobright should not work :) */
1480 if (sd->ag_cnt < 0) 1894 if (sd->ag_cnt < 0)
@@ -1499,6 +1913,7 @@ static void do_autogain(struct gspca_dev *gspca_dev)
1499 default: 1913 default:
1500/* case SENSOR_MO4000: */ 1914/* case SENSOR_MO4000: */
1501/* case SENSOR_MI0360: */ 1915/* case SENSOR_MI0360: */
1916/* case SENSOR_MT9V111: */
1502/* case SENSOR_OM6802: */ 1917/* case SENSOR_OM6802: */
1503 expotimes = sd->exposure; 1918 expotimes = sd->exposure;
1504 expotimes += (luma_mean - delta) >> 6; 1919 expotimes += (luma_mean - delta) >> 6;
@@ -1516,7 +1931,7 @@ static void do_autogain(struct gspca_dev *gspca_dev)
1516/* This function is run at interrupt level. */ 1931/* This function is run at interrupt level. */
1517static void sd_pkt_scan(struct gspca_dev *gspca_dev, 1932static void sd_pkt_scan(struct gspca_dev *gspca_dev,
1518 struct gspca_frame *frame, /* target */ 1933 struct gspca_frame *frame, /* target */
1519 __u8 *data, /* isoc packet */ 1934 u8 *data, /* isoc packet */
1520 int len) /* iso packet length */ 1935 int len) /* iso packet length */
1521{ 1936{
1522 struct sd *sd = (struct sd *) gspca_dev; 1937 struct sd *sd = (struct sd *) gspca_dev;
@@ -1550,7 +1965,8 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
1550 if (gspca_dev->last_packet_type == LAST_PACKET) { 1965 if (gspca_dev->last_packet_type == LAST_PACKET) {
1551 1966
1552 /* put the JPEG 422 header */ 1967 /* put the JPEG 422 header */
1553 jpeg_put_header(gspca_dev, frame, sd->qindex, 0x21); 1968 gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
1969 sd->jpeg_hdr, JPEG_HDR_SZ);
1554 } 1970 }
1555 gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len); 1971 gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
1556} 1972}
@@ -1645,6 +2061,24 @@ static int sd_getred_balance(struct gspca_dev *gspca_dev, __s32 *val)
1645 return 0; 2061 return 0;
1646} 2062}
1647 2063
2064static int sd_setgamma(struct gspca_dev *gspca_dev, __s32 val)
2065{
2066 struct sd *sd = (struct sd *) gspca_dev;
2067
2068 sd->gamma = val;
2069 if (gspca_dev->streaming)
2070 setgamma(gspca_dev);
2071 return 0;
2072}
2073
2074static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val)
2075{
2076 struct sd *sd = (struct sd *) gspca_dev;
2077
2078 *val = sd->gamma;
2079 return 0;
2080}
2081
1648static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val) 2082static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
1649{ 2083{
1650 struct sd *sd = (struct sd *) gspca_dev; 2084 struct sd *sd = (struct sd *) gspca_dev;
@@ -1699,6 +2133,34 @@ static int sd_getinfrared(struct gspca_dev *gspca_dev, __s32 *val)
1699 return 0; 2133 return 0;
1700} 2134}
1701 2135
2136static int sd_set_jcomp(struct gspca_dev *gspca_dev,
2137 struct v4l2_jpegcompression *jcomp)
2138{
2139 struct sd *sd = (struct sd *) gspca_dev;
2140
2141 if (jcomp->quality < QUALITY_MIN)
2142 sd->quality = QUALITY_MIN;
2143 else if (jcomp->quality > QUALITY_MAX)
2144 sd->quality = QUALITY_MAX;
2145 else
2146 sd->quality = jcomp->quality;
2147 if (gspca_dev->streaming)
2148 jpeg_set_qual(sd->jpeg_hdr, sd->quality);
2149 return 0;
2150}
2151
2152static int sd_get_jcomp(struct gspca_dev *gspca_dev,
2153 struct v4l2_jpegcompression *jcomp)
2154{
2155 struct sd *sd = (struct sd *) gspca_dev;
2156
2157 memset(jcomp, 0, sizeof *jcomp);
2158 jcomp->quality = sd->quality;
2159 jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT
2160 | V4L2_JPEG_MARKER_DQT;
2161 return 0;
2162}
2163
1702/* sub-driver description */ 2164/* sub-driver description */
1703static const struct sd_desc sd_desc = { 2165static const struct sd_desc sd_desc = {
1704 .name = MODULE_NAME, 2166 .name = MODULE_NAME,
@@ -1708,8 +2170,11 @@ static const struct sd_desc sd_desc = {
1708 .init = sd_init, 2170 .init = sd_init,
1709 .start = sd_start, 2171 .start = sd_start,
1710 .stopN = sd_stopN, 2172 .stopN = sd_stopN,
2173 .stop0 = sd_stop0,
1711 .pkt_scan = sd_pkt_scan, 2174 .pkt_scan = sd_pkt_scan,
1712 .dq_callback = do_autogain, 2175 .dq_callback = do_autogain,
2176 .get_jcomp = sd_get_jcomp,
2177 .set_jcomp = sd_set_jcomp,
1713}; 2178};
1714 2179
1715/* -- module initialisation -- */ 2180/* -- module initialisation -- */
@@ -1724,9 +2189,7 @@ static const __devinitdata struct usb_device_id device_table[] = {
1724#endif 2189#endif
1725 {USB_DEVICE(0x045e, 0x00f5), BSI(SN9C105, OV7660, 0x21)}, 2190 {USB_DEVICE(0x045e, 0x00f5), BSI(SN9C105, OV7660, 0x21)},
1726 {USB_DEVICE(0x045e, 0x00f7), BSI(SN9C105, OV7660, 0x21)}, 2191 {USB_DEVICE(0x045e, 0x00f7), BSI(SN9C105, OV7660, 0x21)},
1727#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
1728 {USB_DEVICE(0x0471, 0x0327), BSI(SN9C105, MI0360, 0x5d)}, 2192 {USB_DEVICE(0x0471, 0x0327), BSI(SN9C105, MI0360, 0x5d)},
1729#endif
1730 {USB_DEVICE(0x0471, 0x0328), BSI(SN9C105, MI0360, 0x5d)}, 2193 {USB_DEVICE(0x0471, 0x0328), BSI(SN9C105, MI0360, 0x5d)},
1731 {USB_DEVICE(0x0471, 0x0330), BSI(SN9C105, MI0360, 0x5d)}, 2194 {USB_DEVICE(0x0471, 0x0330), BSI(SN9C105, MI0360, 0x5d)},
1732 {USB_DEVICE(0x06f8, 0x3004), BSI(SN9C105, OV7660, 0x21)}, 2195 {USB_DEVICE(0x06f8, 0x3004), BSI(SN9C105, OV7660, 0x21)},
@@ -1764,10 +2227,10 @@ static const __devinitdata struct usb_device_id device_table[] = {
1764 {USB_DEVICE(0x0c45, 0x613a), BSI(SN9C120, OV7648, 0x21)}, 2227 {USB_DEVICE(0x0c45, 0x613a), BSI(SN9C120, OV7648, 0x21)},
1765#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE 2228#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
1766 {USB_DEVICE(0x0c45, 0x613b), BSI(SN9C120, OV7660, 0x21)}, 2229 {USB_DEVICE(0x0c45, 0x613b), BSI(SN9C120, OV7660, 0x21)},
2230#endif
1767 {USB_DEVICE(0x0c45, 0x613c), BSI(SN9C120, HV7131R, 0x11)}, 2231 {USB_DEVICE(0x0c45, 0x613c), BSI(SN9C120, HV7131R, 0x11)},
1768/* {USB_DEVICE(0x0c45, 0x613e), BSI(SN9C120, OV7630, 0x??)}, */ 2232/* {USB_DEVICE(0x0c45, 0x613e), BSI(SN9C120, OV7630, 0x??)}, */
1769#endif 2233 {USB_DEVICE(0x0c45, 0x6143), BSI(SN9C120, SP80708, 0x18)},
1770 {USB_DEVICE(0x0c45, 0x6143), BSI(SN9C120, MI0360, 0x5d)},
1771 {} 2234 {}
1772}; 2235};
1773MODULE_DEVICE_TABLE(usb, device_table); 2236MODULE_DEVICE_TABLE(usb, device_table);
@@ -1794,8 +2257,10 @@ static struct usb_driver sd_driver = {
1794/* -- module insert / remove -- */ 2257/* -- module insert / remove -- */
1795static int __init sd_mod_init(void) 2258static int __init sd_mod_init(void)
1796{ 2259{
1797 if (usb_register(&sd_driver) < 0) 2260 int ret;
1798 return -1; 2261 ret = usb_register(&sd_driver);
2262 if (ret < 0)
2263 return ret;
1799 info("registered"); 2264 info("registered");
1800 return 0; 2265 return 0;
1801} 2266}
diff --git a/drivers/media/video/gspca/spca500.c b/drivers/media/video/gspca/spca500.c
index 942f04cd44dd..6f38fa6d86b6 100644
--- a/drivers/media/video/gspca/spca500.c
+++ b/drivers/media/video/gspca/spca500.c
@@ -38,8 +38,11 @@ struct sd {
38 unsigned char brightness; 38 unsigned char brightness;
39 unsigned char contrast; 39 unsigned char contrast;
40 unsigned char colors; 40 unsigned char colors;
41 u8 quality;
42#define QUALITY_MIN 70
43#define QUALITY_MAX 95
44#define QUALITY_DEF 85
41 45
42 char qindex;
43 char subtype; 46 char subtype;
44#define AgfaCl20 0 47#define AgfaCl20 0
45#define AiptekPocketDV 1 48#define AiptekPocketDV 1
@@ -56,6 +59,8 @@ struct sd {
56#define Optimedia 12 59#define Optimedia 12
57#define PalmPixDC85 13 60#define PalmPixDC85 13
58#define ToptroIndus 14 61#define ToptroIndus 14
62
63 u8 *jpeg_hdr;
59}; 64};
60 65
61/* V4L2 controls supported by the driver */ 66/* V4L2 controls supported by the driver */
@@ -629,7 +634,6 @@ static int sd_config(struct gspca_dev *gspca_dev,
629 struct cam *cam; 634 struct cam *cam;
630 635
631 cam = &gspca_dev->cam; 636 cam = &gspca_dev->cam;
632 cam->epaddr = 0x01;
633 sd->subtype = id->driver_info; 637 sd->subtype = id->driver_info;
634 if (sd->subtype != LogitechClickSmart310) { 638 if (sd->subtype != LogitechClickSmart310) {
635 cam->cam_mode = vga_mode; 639 cam->cam_mode = vga_mode;
@@ -638,10 +642,10 @@ static int sd_config(struct gspca_dev *gspca_dev,
638 cam->cam_mode = sif_mode; 642 cam->cam_mode = sif_mode;
639 cam->nmodes = ARRAY_SIZE(sif_mode); 643 cam->nmodes = ARRAY_SIZE(sif_mode);
640 } 644 }
641 sd->qindex = 5;
642 sd->brightness = BRIGHTNESS_DEF; 645 sd->brightness = BRIGHTNESS_DEF;
643 sd->contrast = CONTRAST_DEF; 646 sd->contrast = CONTRAST_DEF;
644 sd->colors = COLOR_DEF; 647 sd->colors = COLOR_DEF;
648 sd->quality = QUALITY_DEF;
645 return 0; 649 return 0;
646} 650}
647 651
@@ -667,6 +671,12 @@ static int sd_start(struct gspca_dev *gspca_dev)
667 __u8 Data; 671 __u8 Data;
668 __u8 xmult, ymult; 672 __u8 xmult, ymult;
669 673
674 /* create the JPEG header */
675 sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL);
676 jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
677 0x22); /* JPEG 411 */
678 jpeg_set_qual(sd->jpeg_hdr, sd->quality);
679
670 if (sd->subtype == LogitechClickSmart310) { 680 if (sd->subtype == LogitechClickSmart310) {
671 xmult = 0x16; 681 xmult = 0x16;
672 ymult = 0x12; 682 ymult = 0x12;
@@ -713,7 +723,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
713 write_vector(gspca_dev, spca500_visual_defaults); 723 write_vector(gspca_dev, spca500_visual_defaults);
714 spca500_setmode(gspca_dev, xmult, ymult); 724 spca500_setmode(gspca_dev, xmult, ymult);
715 /* enable drop packet */ 725 /* enable drop packet */
716 reg_w(gspca_dev, 0x00, 0x850a, 0x0001); 726 err = reg_w(gspca_dev, 0x00, 0x850a, 0x0001);
727 if (err < 0)
717 PDEBUG(D_ERR, "failed to enable drop packet"); 728 PDEBUG(D_ERR, "failed to enable drop packet");
718 reg_w(gspca_dev, 0x00, 0x8880, 3); 729 reg_w(gspca_dev, 0x00, 0x8880, 3);
719 err = spca50x_setup_qtable(gspca_dev, 730 err = spca50x_setup_qtable(gspca_dev,
@@ -881,6 +892,13 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
881 gspca_dev->usb_buf[0]); 892 gspca_dev->usb_buf[0]);
882} 893}
883 894
895static void sd_stop0(struct gspca_dev *gspca_dev)
896{
897 struct sd *sd = (struct sd *) gspca_dev;
898
899 kfree(sd->jpeg_hdr);
900}
901
884static void sd_pkt_scan(struct gspca_dev *gspca_dev, 902static void sd_pkt_scan(struct gspca_dev *gspca_dev,
885 struct gspca_frame *frame, /* target */ 903 struct gspca_frame *frame, /* target */
886 __u8 *data, /* isoc packet */ 904 __u8 *data, /* isoc packet */
@@ -901,7 +919,8 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
901 ffd9, 2); 919 ffd9, 2);
902 920
903 /* put the JPEG header in the new frame */ 921 /* put the JPEG header in the new frame */
904 jpeg_put_header(gspca_dev, frame, sd->qindex, 0x22); 922 gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
923 sd->jpeg_hdr, JPEG_HDR_SZ);
905 924
906 data += SPCA500_OFFSET_DATA; 925 data += SPCA500_OFFSET_DATA;
907 len -= SPCA500_OFFSET_DATA; 926 len -= SPCA500_OFFSET_DATA;
@@ -937,16 +956,6 @@ static void setbrightness(struct gspca_dev *gspca_dev)
937 (__u8) (sd->brightness - 128)); 956 (__u8) (sd->brightness - 128));
938} 957}
939 958
940static void getbrightness(struct gspca_dev *gspca_dev)
941{
942 struct sd *sd = (struct sd *) gspca_dev;
943 int ret;
944
945 ret = reg_r_12(gspca_dev, 0x00, 0x8167, 1);
946 if (ret >= 0)
947 sd->brightness = ret + 128;
948}
949
950static void setcontrast(struct gspca_dev *gspca_dev) 959static void setcontrast(struct gspca_dev *gspca_dev)
951{ 960{
952 struct sd *sd = (struct sd *) gspca_dev; 961 struct sd *sd = (struct sd *) gspca_dev;
@@ -954,16 +963,6 @@ static void setcontrast(struct gspca_dev *gspca_dev)
954 reg_w(gspca_dev, 0x00, 0x8168, sd->contrast); 963 reg_w(gspca_dev, 0x00, 0x8168, sd->contrast);
955} 964}
956 965
957static void getcontrast(struct gspca_dev *gspca_dev)
958{
959 struct sd *sd = (struct sd *) gspca_dev;
960 int ret;
961
962 ret = reg_r_12(gspca_dev, 0x0, 0x8168, 1);
963 if (ret >= 0)
964 sd->contrast = ret;
965}
966
967static void setcolors(struct gspca_dev *gspca_dev) 966static void setcolors(struct gspca_dev *gspca_dev)
968{ 967{
969 struct sd *sd = (struct sd *) gspca_dev; 968 struct sd *sd = (struct sd *) gspca_dev;
@@ -971,16 +970,6 @@ static void setcolors(struct gspca_dev *gspca_dev)
971 reg_w(gspca_dev, 0x00, 0x8169, sd->colors); 970 reg_w(gspca_dev, 0x00, 0x8169, sd->colors);
972} 971}
973 972
974static void getcolors(struct gspca_dev *gspca_dev)
975{
976 struct sd *sd = (struct sd *) gspca_dev;
977 int ret;
978
979 ret = reg_r_12(gspca_dev, 0x0, 0x8169, 1);
980 if (ret >= 0)
981 sd->colors = ret;
982}
983
984static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val) 973static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
985{ 974{
986 struct sd *sd = (struct sd *) gspca_dev; 975 struct sd *sd = (struct sd *) gspca_dev;
@@ -995,7 +984,6 @@ static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
995{ 984{
996 struct sd *sd = (struct sd *) gspca_dev; 985 struct sd *sd = (struct sd *) gspca_dev;
997 986
998 getbrightness(gspca_dev);
999 *val = sd->brightness; 987 *val = sd->brightness;
1000 return 0; 988 return 0;
1001} 989}
@@ -1014,7 +1002,6 @@ static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
1014{ 1002{
1015 struct sd *sd = (struct sd *) gspca_dev; 1003 struct sd *sd = (struct sd *) gspca_dev;
1016 1004
1017 getcontrast(gspca_dev);
1018 *val = sd->contrast; 1005 *val = sd->contrast;
1019 return 0; 1006 return 0;
1020} 1007}
@@ -1033,11 +1020,38 @@ static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
1033{ 1020{
1034 struct sd *sd = (struct sd *) gspca_dev; 1021 struct sd *sd = (struct sd *) gspca_dev;
1035 1022
1036 getcolors(gspca_dev);
1037 *val = sd->colors; 1023 *val = sd->colors;
1038 return 0; 1024 return 0;
1039} 1025}
1040 1026
1027static int sd_set_jcomp(struct gspca_dev *gspca_dev,
1028 struct v4l2_jpegcompression *jcomp)
1029{
1030 struct sd *sd = (struct sd *) gspca_dev;
1031
1032 if (jcomp->quality < QUALITY_MIN)
1033 sd->quality = QUALITY_MIN;
1034 else if (jcomp->quality > QUALITY_MAX)
1035 sd->quality = QUALITY_MAX;
1036 else
1037 sd->quality = jcomp->quality;
1038 if (gspca_dev->streaming)
1039 jpeg_set_qual(sd->jpeg_hdr, sd->quality);
1040 return 0;
1041}
1042
1043static int sd_get_jcomp(struct gspca_dev *gspca_dev,
1044 struct v4l2_jpegcompression *jcomp)
1045{
1046 struct sd *sd = (struct sd *) gspca_dev;
1047
1048 memset(jcomp, 0, sizeof *jcomp);
1049 jcomp->quality = sd->quality;
1050 jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT
1051 | V4L2_JPEG_MARKER_DQT;
1052 return 0;
1053}
1054
1041/* sub-driver description */ 1055/* sub-driver description */
1042static struct sd_desc sd_desc = { 1056static struct sd_desc sd_desc = {
1043 .name = MODULE_NAME, 1057 .name = MODULE_NAME,
@@ -1047,7 +1061,10 @@ static struct sd_desc sd_desc = {
1047 .init = sd_init, 1061 .init = sd_init,
1048 .start = sd_start, 1062 .start = sd_start,
1049 .stopN = sd_stopN, 1063 .stopN = sd_stopN,
1064 .stop0 = sd_stop0,
1050 .pkt_scan = sd_pkt_scan, 1065 .pkt_scan = sd_pkt_scan,
1066 .get_jcomp = sd_get_jcomp,
1067 .set_jcomp = sd_set_jcomp,
1051}; 1068};
1052 1069
1053/* -- module initialisation -- */ 1070/* -- module initialisation -- */
@@ -1093,8 +1110,10 @@ static struct usb_driver sd_driver = {
1093/* -- module insert / remove -- */ 1110/* -- module insert / remove -- */
1094static int __init sd_mod_init(void) 1111static int __init sd_mod_init(void)
1095{ 1112{
1096 if (usb_register(&sd_driver) < 0) 1113 int ret;
1097 return -1; 1114 ret = usb_register(&sd_driver);
1115 if (ret < 0)
1116 return ret;
1098 PDEBUG(D_PROBE, "registered"); 1117 PDEBUG(D_PROBE, "registered");
1099 return 0; 1118 return 0;
1100} 1119}
diff --git a/drivers/media/video/gspca/spca501.c b/drivers/media/video/gspca/spca501.c
index 82e3e3e2ada1..d48b27c648ca 100644
--- a/drivers/media/video/gspca/spca501.c
+++ b/drivers/media/video/gspca/spca501.c
@@ -1883,10 +1883,6 @@ static void setbrightness(struct gspca_dev *gspca_dev)
1883 reg_write(gspca_dev->dev, SPCA501_REG_CCDSP, 0x12, sd->brightness); 1883 reg_write(gspca_dev->dev, SPCA501_REG_CCDSP, 0x12, sd->brightness);
1884} 1884}
1885 1885
1886static void getbrightness(struct gspca_dev *gspca_dev)
1887{
1888}
1889
1890static void setcontrast(struct gspca_dev *gspca_dev) 1886static void setcontrast(struct gspca_dev *gspca_dev)
1891{ 1887{
1892 struct sd *sd = (struct sd *) gspca_dev; 1888 struct sd *sd = (struct sd *) gspca_dev;
@@ -1897,10 +1893,6 @@ static void setcontrast(struct gspca_dev *gspca_dev)
1897 sd->contrast & 0xff); 1893 sd->contrast & 0xff);
1898} 1894}
1899 1895
1900static void getcontrast(struct gspca_dev *gspca_dev)
1901{
1902}
1903
1904static void setcolors(struct gspca_dev *gspca_dev) 1896static void setcolors(struct gspca_dev *gspca_dev)
1905{ 1897{
1906 struct sd *sd = (struct sd *) gspca_dev; 1898 struct sd *sd = (struct sd *) gspca_dev;
@@ -1908,10 +1900,6 @@ static void setcolors(struct gspca_dev *gspca_dev)
1908 reg_write(gspca_dev->dev, SPCA501_REG_CCDSP, 0x0c, sd->colors); 1900 reg_write(gspca_dev->dev, SPCA501_REG_CCDSP, 0x0c, sd->colors);
1909} 1901}
1910 1902
1911static void getcolors(struct gspca_dev *gspca_dev)
1912{
1913}
1914
1915static void setblue_balance(struct gspca_dev *gspca_dev) 1903static void setblue_balance(struct gspca_dev *gspca_dev)
1916{ 1904{
1917 struct sd *sd = (struct sd *) gspca_dev; 1905 struct sd *sd = (struct sd *) gspca_dev;
@@ -1934,7 +1922,6 @@ static int sd_config(struct gspca_dev *gspca_dev,
1934 struct cam *cam; 1922 struct cam *cam;
1935 1923
1936 cam = &gspca_dev->cam; 1924 cam = &gspca_dev->cam;
1937 cam->epaddr = 0x01;
1938 cam->cam_mode = vga_mode; 1925 cam->cam_mode = vga_mode;
1939 cam->nmodes = sizeof vga_mode / sizeof vga_mode[0]; 1926 cam->nmodes = sizeof vga_mode / sizeof vga_mode[0];
1940 sd->subtype = id->driver_info; 1927 sd->subtype = id->driver_info;
@@ -2084,7 +2071,6 @@ static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
2084{ 2071{
2085 struct sd *sd = (struct sd *) gspca_dev; 2072 struct sd *sd = (struct sd *) gspca_dev;
2086 2073
2087 getbrightness(gspca_dev);
2088 *val = sd->brightness; 2074 *val = sd->brightness;
2089 return 0; 2075 return 0;
2090} 2076}
@@ -2103,7 +2089,6 @@ static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
2103{ 2089{
2104 struct sd *sd = (struct sd *) gspca_dev; 2090 struct sd *sd = (struct sd *) gspca_dev;
2105 2091
2106 getcontrast(gspca_dev);
2107 *val = sd->contrast; 2092 *val = sd->contrast;
2108 return 0; 2093 return 0;
2109} 2094}
@@ -2122,7 +2107,6 @@ static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
2122{ 2107{
2123 struct sd *sd = (struct sd *) gspca_dev; 2108 struct sd *sd = (struct sd *) gspca_dev;
2124 2109
2125 getcolors(gspca_dev);
2126 *val = sd->colors; 2110 *val = sd->colors;
2127 return 0; 2111 return 0;
2128} 2112}
@@ -2211,8 +2195,10 @@ static struct usb_driver sd_driver = {
2211/* -- module insert / remove -- */ 2195/* -- module insert / remove -- */
2212static int __init sd_mod_init(void) 2196static int __init sd_mod_init(void)
2213{ 2197{
2214 if (usb_register(&sd_driver) < 0) 2198 int ret;
2215 return -1; 2199 ret = usb_register(&sd_driver);
2200 if (ret < 0)
2201 return ret;
2216 PDEBUG(D_PROBE, "registered"); 2202 PDEBUG(D_PROBE, "registered");
2217 return 0; 2203 return 0;
2218} 2204}
diff --git a/drivers/media/video/gspca/spca505.c b/drivers/media/video/gspca/spca505.c
index 2a33a29010ee..2acec58b1b97 100644
--- a/drivers/media/video/gspca/spca505.c
+++ b/drivers/media/video/gspca/spca505.c
@@ -31,9 +31,9 @@ MODULE_LICENSE("GPL");
31struct sd { 31struct sd {
32 struct gspca_dev gspca_dev; /* !! must be the first item */ 32 struct gspca_dev gspca_dev; /* !! must be the first item */
33 33
34 unsigned char brightness; 34 u8 brightness;
35 35
36 char subtype; 36 u8 subtype;
37#define IntelPCCameraPro 0 37#define IntelPCCameraPro 0
38#define Nxultra 1 38#define Nxultra 1
39}; 39};
@@ -43,7 +43,6 @@ static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
43static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val); 43static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
44 44
45static struct ctrl sd_ctrls[] = { 45static struct ctrl sd_ctrls[] = {
46#define SD_BRIGHTNESS 0
47 { 46 {
48 { 47 {
49 .id = V4L2_CID_BRIGHTNESS, 48 .id = V4L2_CID_BRIGHTNESS,
@@ -52,7 +51,8 @@ static struct ctrl sd_ctrls[] = {
52 .minimum = 0, 51 .minimum = 0,
53 .maximum = 255, 52 .maximum = 255,
54 .step = 1, 53 .step = 1,
55 .default_value = 127, 54#define BRIGHTNESS_DEF 127
55 .default_value = BRIGHTNESS_DEF,
56 }, 56 },
57 .set = sd_setbrightness, 57 .set = sd_setbrightness,
58 .get = sd_getbrightness, 58 .get = sd_getbrightness,
@@ -64,12 +64,12 @@ static const struct v4l2_pix_format vga_mode[] = {
64 .bytesperline = 160, 64 .bytesperline = 160,
65 .sizeimage = 160 * 120 * 3 / 2, 65 .sizeimage = 160 * 120 * 3 / 2,
66 .colorspace = V4L2_COLORSPACE_SRGB, 66 .colorspace = V4L2_COLORSPACE_SRGB,
67 .priv = 5}, 67 .priv = 4},
68 {176, 144, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE, 68 {176, 144, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
69 .bytesperline = 176, 69 .bytesperline = 176,
70 .sizeimage = 176 * 144 * 3 / 2, 70 .sizeimage = 176 * 144 * 3 / 2,
71 .colorspace = V4L2_COLORSPACE_SRGB, 71 .colorspace = V4L2_COLORSPACE_SRGB,
72 .priv = 4}, 72 .priv = 3},
73 {320, 240, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE, 73 {320, 240, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
74 .bytesperline = 320, 74 .bytesperline = 320,
75 .sizeimage = 320 * 240 * 3 / 2, 75 .sizeimage = 320 * 240 * 3 / 2,
@@ -93,6 +93,7 @@ static const struct v4l2_pix_format vga_mode[] = {
93 93
94#define SPCA50X_USB_CTRL 0x00 /* spca505 */ 94#define SPCA50X_USB_CTRL 0x00 /* spca505 */
95#define SPCA50X_CUSB_ENABLE 0x01 /* spca505 */ 95#define SPCA50X_CUSB_ENABLE 0x01 /* spca505 */
96
96#define SPCA50X_REG_GLOBAL 0x03 /* spca505 */ 97#define SPCA50X_REG_GLOBAL 0x03 /* spca505 */
97#define SPCA50X_GMISC0_IDSEL 0x01 /* Global control device ID select spca505 */ 98#define SPCA50X_GMISC0_IDSEL 0x01 /* Global control device ID select spca505 */
98#define SPCA50X_GLOBAL_MISC0 0x00 /* Global control miscellaneous 0 spca505 */ 99#define SPCA50X_GLOBAL_MISC0 0x00 /* Global control miscellaneous 0 spca505 */
@@ -101,230 +102,230 @@ static const struct v4l2_pix_format vga_mode[] = {
101#define SPCA50X_GLOBAL_MISC3 0x03 /* 505 */ 102#define SPCA50X_GLOBAL_MISC3 0x03 /* 505 */
102#define SPCA50X_GMISC3_SAA7113RST 0x20 /* Not sure about this one spca505 */ 103#define SPCA50X_GMISC3_SAA7113RST 0x20 /* Not sure about this one spca505 */
103 104
105/* Image format and compression control */
106#define SPCA50X_REG_COMPRESS 0x04
107
104/* 108/*
105 * Data to initialize a SPCA505. Common to the CCD and external modes 109 * Data to initialize a SPCA505. Common to the CCD and external modes
106 */ 110 */
107static const __u16 spca505_init_data[][3] = { 111static const u8 spca505_init_data[][3] = {
108 /* line bmRequest,value,index */ 112 /* bmRequest,value,index */
109 /* 1819 */
110 {SPCA50X_REG_GLOBAL, SPCA50X_GMISC3_SAA7113RST, SPCA50X_GLOBAL_MISC3}, 113 {SPCA50X_REG_GLOBAL, SPCA50X_GMISC3_SAA7113RST, SPCA50X_GLOBAL_MISC3},
111 /* Sensor reset */ 114 /* Sensor reset */
112 /* 1822 */ {SPCA50X_REG_GLOBAL, 0x00, SPCA50X_GLOBAL_MISC3}, 115 {SPCA50X_REG_GLOBAL, 0x00, SPCA50X_GLOBAL_MISC3},
113 /* 1825 */ {SPCA50X_REG_GLOBAL, 0x00, SPCA50X_GLOBAL_MISC1}, 116 {SPCA50X_REG_GLOBAL, 0x00, SPCA50X_GLOBAL_MISC1},
114 /* Block USB reset */ 117 /* Block USB reset */
115 /* 1828 */ {SPCA50X_REG_GLOBAL, SPCA50X_GMISC0_IDSEL, 118 {SPCA50X_REG_GLOBAL, SPCA50X_GMISC0_IDSEL, SPCA50X_GLOBAL_MISC0},
116 SPCA50X_GLOBAL_MISC0},
117 119
118 /* 1831 */ {0x5, 0x01, 0x10}, 120 {0x05, 0x01, 0x10},
119 /* Maybe power down some stuff */ 121 /* Maybe power down some stuff */
120 /* 1834 */ {0x5, 0x0f, 0x11}, 122 {0x05, 0x0f, 0x11},
121 123
122 /* Setup internal CCD ? */ 124 /* Setup internal CCD ? */
123 /* 1837 */ {0x6, 0x10, 0x08}, 125 {0x06, 0x10, 0x08},
124 /* 1840 */ {0x6, 0x00, 0x09}, 126 {0x06, 0x00, 0x09},
125 /* 1843 */ {0x6, 0x00, 0x0a}, 127 {0x06, 0x00, 0x0a},
126 /* 1846 */ {0x6, 0x00, 0x0b}, 128 {0x06, 0x00, 0x0b},
127 /* 1849 */ {0x6, 0x10, 0x0c}, 129 {0x06, 0x10, 0x0c},
128 /* 1852 */ {0x6, 0x00, 0x0d}, 130 {0x06, 0x00, 0x0d},
129 /* 1855 */ {0x6, 0x00, 0x0e}, 131 {0x06, 0x00, 0x0e},
130 /* 1858 */ {0x6, 0x00, 0x0f}, 132 {0x06, 0x00, 0x0f},
131 /* 1861 */ {0x6, 0x10, 0x10}, 133 {0x06, 0x10, 0x10},
132 /* 1864 */ {0x6, 0x02, 0x11}, 134 {0x06, 0x02, 0x11},
133 /* 1867 */ {0x6, 0x00, 0x12}, 135 {0x06, 0x00, 0x12},
134 /* 1870 */ {0x6, 0x04, 0x13}, 136 {0x06, 0x04, 0x13},
135 /* 1873 */ {0x6, 0x02, 0x14}, 137 {0x06, 0x02, 0x14},
136 /* 1876 */ {0x6, 0x8a, 0x51}, 138 {0x06, 0x8a, 0x51},
137 /* 1879 */ {0x6, 0x40, 0x52}, 139 {0x06, 0x40, 0x52},
138 /* 1882 */ {0x6, 0xb6, 0x53}, 140 {0x06, 0xb6, 0x53},
139 /* 1885 */ {0x6, 0x3d, 0x54}, 141 {0x06, 0x3d, 0x54},
140 {} 142 {}
141}; 143};
142 144
143/* 145/*
144 * Data to initialize the camera using the internal CCD 146 * Data to initialize the camera using the internal CCD
145 */ 147 */
146static const __u16 spca505_open_data_ccd[][3] = { 148static const u8 spca505_open_data_ccd[][3] = {
147 /* line bmRequest,value,index */ 149 /* bmRequest,value,index */
148 /* Internal CCD data set */ 150 /* Internal CCD data set */
149 /* 1891 */ {0x3, 0x04, 0x01}, 151 {0x03, 0x04, 0x01},
150 /* This could be a reset */ 152 /* This could be a reset */
151 /* 1894 */ {0x3, 0x00, 0x01}, 153 {0x03, 0x00, 0x01},
152 154
153 /* Setup compression and image registers. 0x6 and 0x7 seem to be 155 /* Setup compression and image registers. 0x6 and 0x7 seem to be
154 related to H&V hold, and are resolution mode specific */ 156 related to H&V hold, and are resolution mode specific */
155 /* 1897 */ {0x4, 0x10, 0x01}, 157 {0x04, 0x10, 0x01},
156 /* DIFF(0x50), was (0x10) */ 158 /* DIFF(0x50), was (0x10) */
157 /* 1900 */ {0x4, 0x00, 0x04}, 159 {0x04, 0x00, 0x04},
158 /* 1903 */ {0x4, 0x00, 0x05}, 160 {0x04, 0x00, 0x05},
159 /* 1906 */ {0x4, 0x20, 0x06}, 161 {0x04, 0x20, 0x06},
160 /* 1909 */ {0x4, 0x20, 0x07}, 162 {0x04, 0x20, 0x07},
161 163
162 /* 1912 */ {0x8, 0x0a, 0x00}, 164 {0x08, 0x0a, 0x00},
163 /* DIFF (0x4a), was (0xa) */ 165 /* DIFF (0x4a), was (0xa) */
164 166
165 /* 1915 */ {0x5, 0x00, 0x10}, 167 {0x05, 0x00, 0x10},
166 /* 1918 */ {0x5, 0x00, 0x11}, 168 {0x05, 0x00, 0x11},
167 /* 1921 */ {0x5, 0x00, 0x00}, 169 {0x05, 0x00, 0x00},
168 /* DIFF not written */ 170 /* DIFF not written */
169 /* 1924 */ {0x5, 0x00, 0x01}, 171 {0x05, 0x00, 0x01},
170 /* DIFF not written */ 172 /* DIFF not written */
171 /* 1927 */ {0x5, 0x00, 0x02}, 173 {0x05, 0x00, 0x02},
172 /* DIFF not written */ 174 /* DIFF not written */
173 /* 1930 */ {0x5, 0x00, 0x03}, 175 {0x05, 0x00, 0x03},
174 /* DIFF not written */ 176 /* DIFF not written */
175 /* 1933 */ {0x5, 0x00, 0x04}, 177 {0x05, 0x00, 0x04},
176 /* DIFF not written */ 178 /* DIFF not written */
177 /* 1936 */ {0x5, 0x80, 0x05}, 179 {0x05, 0x80, 0x05},
178 /* DIFF not written */ 180 /* DIFF not written */
179 /* 1939 */ {0x5, 0xe0, 0x06}, 181 {0x05, 0xe0, 0x06},
180 /* DIFF not written */ 182 /* DIFF not written */
181 /* 1942 */ {0x5, 0x20, 0x07}, 183 {0x05, 0x20, 0x07},
182 /* DIFF not written */ 184 /* DIFF not written */
183 /* 1945 */ {0x5, 0xa0, 0x08}, 185 {0x05, 0xa0, 0x08},
184 /* DIFF not written */ 186 /* DIFF not written */
185 /* 1948 */ {0x5, 0x0, 0x12}, 187 {0x05, 0x0, 0x12},
186 /* DIFF not written */ 188 /* DIFF not written */
187 /* 1951 */ {0x5, 0x02, 0x0f}, 189 {0x05, 0x02, 0x0f},
188 /* DIFF not written */ 190 /* DIFF not written */
189 /* 1954 */ {0x5, 0x10, 0x46}, 191 {0x05, 0x10, 0x46},
190 /* DIFF not written */ 192 /* DIFF not written */
191 /* 1957 */ {0x5, 0x8, 0x4a}, 193 {0x05, 0x8, 0x4a},
192 /* DIFF not written */ 194 /* DIFF not written */
193 195
194 /* 1960 */ {0x3, 0x08, 0x03}, 196 {0x03, 0x08, 0x03},
195 /* DIFF (0x3,0x28,0x3) */ 197 /* DIFF (0x3,0x28,0x3) */
196 /* 1963 */ {0x3, 0x08, 0x01}, 198 {0x03, 0x08, 0x01},
197 /* 1966 */ {0x3, 0x0c, 0x03}, 199 {0x03, 0x0c, 0x03},
198 /* DIFF not written */ 200 /* DIFF not written */
199 /* 1969 */ {0x3, 0x21, 0x00}, 201 {0x03, 0x21, 0x00},
200 /* DIFF (0x39) */ 202 /* DIFF (0x39) */
201 203
202/* Extra block copied from init to hopefully ensure CCD is in a sane state */ 204/* Extra block copied from init to hopefully ensure CCD is in a sane state */
203 /* 1837 */ {0x6, 0x10, 0x08}, 205 {0x06, 0x10, 0x08},
204 /* 1840 */ {0x6, 0x00, 0x09}, 206 {0x06, 0x00, 0x09},
205 /* 1843 */ {0x6, 0x00, 0x0a}, 207 {0x06, 0x00, 0x0a},
206 /* 1846 */ {0x6, 0x00, 0x0b}, 208 {0x06, 0x00, 0x0b},
207 /* 1849 */ {0x6, 0x10, 0x0c}, 209 {0x06, 0x10, 0x0c},
208 /* 1852 */ {0x6, 0x00, 0x0d}, 210 {0x06, 0x00, 0x0d},
209 /* 1855 */ {0x6, 0x00, 0x0e}, 211 {0x06, 0x00, 0x0e},
210 /* 1858 */ {0x6, 0x00, 0x0f}, 212 {0x06, 0x00, 0x0f},
211 /* 1861 */ {0x6, 0x10, 0x10}, 213 {0x06, 0x10, 0x10},
212 /* 1864 */ {0x6, 0x02, 0x11}, 214 {0x06, 0x02, 0x11},
213 /* 1867 */ {0x6, 0x00, 0x12}, 215 {0x06, 0x00, 0x12},
214 /* 1870 */ {0x6, 0x04, 0x13}, 216 {0x06, 0x04, 0x13},
215 /* 1873 */ {0x6, 0x02, 0x14}, 217 {0x06, 0x02, 0x14},
216 /* 1876 */ {0x6, 0x8a, 0x51}, 218 {0x06, 0x8a, 0x51},
217 /* 1879 */ {0x6, 0x40, 0x52}, 219 {0x06, 0x40, 0x52},
218 /* 1882 */ {0x6, 0xb6, 0x53}, 220 {0x06, 0xb6, 0x53},
219 /* 1885 */ {0x6, 0x3d, 0x54}, 221 {0x06, 0x3d, 0x54},
220 /* End of extra block */ 222 /* End of extra block */
221 223
222 /* 1972 */ {0x6, 0x3f, 0x1}, 224 {0x06, 0x3f, 0x1},
223 /* Block skipped */ 225 /* Block skipped */
224 /* 1975 */ {0x6, 0x10, 0x02}, 226 {0x06, 0x10, 0x02},
225 /* 1978 */ {0x6, 0x64, 0x07}, 227 {0x06, 0x64, 0x07},
226 /* 1981 */ {0x6, 0x10, 0x08}, 228 {0x06, 0x10, 0x08},
227 /* 1984 */ {0x6, 0x00, 0x09}, 229 {0x06, 0x00, 0x09},
228 /* 1987 */ {0x6, 0x00, 0x0a}, 230 {0x06, 0x00, 0x0a},
229 /* 1990 */ {0x6, 0x00, 0x0b}, 231 {0x06, 0x00, 0x0b},
230 /* 1993 */ {0x6, 0x10, 0x0c}, 232 {0x06, 0x10, 0x0c},
231 /* 1996 */ {0x6, 0x00, 0x0d}, 233 {0x06, 0x00, 0x0d},
232 /* 1999 */ {0x6, 0x00, 0x0e}, 234 {0x06, 0x00, 0x0e},
233 /* 2002 */ {0x6, 0x00, 0x0f}, 235 {0x06, 0x00, 0x0f},
234 /* 2005 */ {0x6, 0x10, 0x10}, 236 {0x06, 0x10, 0x10},
235 /* 2008 */ {0x6, 0x02, 0x11}, 237 {0x06, 0x02, 0x11},
236 /* 2011 */ {0x6, 0x00, 0x12}, 238 {0x06, 0x00, 0x12},
237 /* 2014 */ {0x6, 0x04, 0x13}, 239 {0x06, 0x04, 0x13},
238 /* 2017 */ {0x6, 0x02, 0x14}, 240 {0x06, 0x02, 0x14},
239 /* 2020 */ {0x6, 0x8a, 0x51}, 241 {0x06, 0x8a, 0x51},
240 /* 2023 */ {0x6, 0x40, 0x52}, 242 {0x06, 0x40, 0x52},
241 /* 2026 */ {0x6, 0xb6, 0x53}, 243 {0x06, 0xb6, 0x53},
242 /* 2029 */ {0x6, 0x3d, 0x54}, 244 {0x06, 0x3d, 0x54},
243 /* 2032 */ {0x6, 0x60, 0x57}, 245 {0x06, 0x60, 0x57},
244 /* 2035 */ {0x6, 0x20, 0x58}, 246 {0x06, 0x20, 0x58},
245 /* 2038 */ {0x6, 0x15, 0x59}, 247 {0x06, 0x15, 0x59},
246 /* 2041 */ {0x6, 0x05, 0x5a}, 248 {0x06, 0x05, 0x5a},
247 249
248 /* 2044 */ {0x5, 0x01, 0xc0}, 250 {0x05, 0x01, 0xc0},
249 /* 2047 */ {0x5, 0x10, 0xcb}, 251 {0x05, 0x10, 0xcb},
250 /* 2050 */ {0x5, 0x80, 0xc1}, 252 {0x05, 0x80, 0xc1},
251 /* */ 253 /* */
252 /* 2053 */ {0x5, 0x0, 0xc2}, 254 {0x05, 0x0, 0xc2},
253 /* 4 was 0 */ 255 /* 4 was 0 */
254 /* 2056 */ {0x5, 0x00, 0xca}, 256 {0x05, 0x00, 0xca},
255 /* 2059 */ {0x5, 0x80, 0xc1}, 257 {0x05, 0x80, 0xc1},
256 /* */ 258 /* */
257 /* 2062 */ {0x5, 0x04, 0xc2}, 259 {0x05, 0x04, 0xc2},
258 /* 2065 */ {0x5, 0x00, 0xca}, 260 {0x05, 0x00, 0xca},
259 /* 2068 */ {0x5, 0x0, 0xc1}, 261 {0x05, 0x0, 0xc1},
260 /* */ 262 /* */
261 /* 2071 */ {0x5, 0x00, 0xc2}, 263 {0x05, 0x00, 0xc2},
262 /* 2074 */ {0x5, 0x00, 0xca}, 264 {0x05, 0x00, 0xca},
263 /* 2077 */ {0x5, 0x40, 0xc1}, 265 {0x05, 0x40, 0xc1},
264 /* */ 266 /* */
265 /* 2080 */ {0x5, 0x17, 0xc2}, 267 {0x05, 0x17, 0xc2},
266 /* 2083 */ {0x5, 0x00, 0xca}, 268 {0x05, 0x00, 0xca},
267 /* 2086 */ {0x5, 0x80, 0xc1}, 269 {0x05, 0x80, 0xc1},
268 /* */ 270 /* */
269 /* 2089 */ {0x5, 0x06, 0xc2}, 271 {0x05, 0x06, 0xc2},
270 /* 2092 */ {0x5, 0x00, 0xca}, 272 {0x05, 0x00, 0xca},
271 /* 2095 */ {0x5, 0x80, 0xc1}, 273 {0x05, 0x80, 0xc1},
272 /* */ 274 /* */
273 /* 2098 */ {0x5, 0x04, 0xc2}, 275 {0x05, 0x04, 0xc2},
274 /* 2101 */ {0x5, 0x00, 0xca}, 276 {0x05, 0x00, 0xca},
275 277
276 /* 2104 */ {0x3, 0x4c, 0x3}, 278 {0x03, 0x4c, 0x3},
277 /* 2107 */ {0x3, 0x18, 0x1}, 279 {0x03, 0x18, 0x1},
278 280
279 /* 2110 */ {0x6, 0x70, 0x51}, 281 {0x06, 0x70, 0x51},
280 /* 2113 */ {0x6, 0xbe, 0x53}, 282 {0x06, 0xbe, 0x53},
281 /* 2116 */ {0x6, 0x71, 0x57}, 283 {0x06, 0x71, 0x57},
282 /* 2119 */ {0x6, 0x20, 0x58}, 284 {0x06, 0x20, 0x58},
283 /* 2122 */ {0x6, 0x05, 0x59}, 285 {0x06, 0x05, 0x59},
284 /* 2125 */ {0x6, 0x15, 0x5a}, 286 {0x06, 0x15, 0x5a},
285 287
286 /* 2128 */ {0x4, 0x00, 0x08}, 288 {0x04, 0x00, 0x08},
287 /* Compress = OFF (0x1 to turn on) */ 289 /* Compress = OFF (0x1 to turn on) */
288 /* 2131 */ {0x4, 0x12, 0x09}, 290 {0x04, 0x12, 0x09},
289 /* 2134 */ {0x4, 0x21, 0x0a}, 291 {0x04, 0x21, 0x0a},
290 /* 2137 */ {0x4, 0x10, 0x0b}, 292 {0x04, 0x10, 0x0b},
291 /* 2140 */ {0x4, 0x21, 0x0c}, 293 {0x04, 0x21, 0x0c},
292 /* 2143 */ {0x4, 0x05, 0x00}, 294 {0x04, 0x05, 0x00},
293 /* was 5 (Image Type ? ) */ 295 /* was 5 (Image Type ? ) */
294 /* 2146 */ {0x4, 0x00, 0x01}, 296 {0x04, 0x00, 0x01},
295 297
296 /* 2149 */ {0x6, 0x3f, 0x01}, 298 {0x06, 0x3f, 0x01},
297 299
298 /* 2152 */ {0x4, 0x00, 0x04}, 300 {0x04, 0x00, 0x04},
299 /* 2155 */ {0x4, 0x00, 0x05}, 301 {0x04, 0x00, 0x05},
300 /* 2158 */ {0x4, 0x40, 0x06}, 302 {0x04, 0x40, 0x06},
301 /* 2161 */ {0x4, 0x40, 0x07}, 303 {0x04, 0x40, 0x07},
302 304
303 /* 2164 */ {0x6, 0x1c, 0x17}, 305 {0x06, 0x1c, 0x17},
304 /* 2167 */ {0x6, 0xe2, 0x19}, 306 {0x06, 0xe2, 0x19},
305 /* 2170 */ {0x6, 0x1c, 0x1b}, 307 {0x06, 0x1c, 0x1b},
306 /* 2173 */ {0x6, 0xe2, 0x1d}, 308 {0x06, 0xe2, 0x1d},
307 /* 2176 */ {0x6, 0xaa, 0x1f}, 309 {0x06, 0xaa, 0x1f},
308 /* 2179 */ {0x6, 0x70, 0x20}, 310 {0x06, 0x70, 0x20},
309 311
310 /* 2182 */ {0x5, 0x01, 0x10}, 312 {0x05, 0x01, 0x10},
311 /* 2185 */ {0x5, 0x00, 0x11}, 313 {0x05, 0x00, 0x11},
312 /* 2188 */ {0x5, 0x01, 0x00}, 314 {0x05, 0x01, 0x00},
313 /* 2191 */ {0x5, 0x05, 0x01}, 315 {0x05, 0x05, 0x01},
314 /* 2194 */ {0x5, 0x00, 0xc1}, 316 {0x05, 0x00, 0xc1},
315 /* */ 317 /* */
316 /* 2197 */ {0x5, 0x00, 0xc2}, 318 {0x05, 0x00, 0xc2},
317 /* 2200 */ {0x5, 0x00, 0xca}, 319 {0x05, 0x00, 0xca},
318 320
319 /* 2203 */ {0x6, 0x70, 0x51}, 321 {0x06, 0x70, 0x51},
320 /* 2206 */ {0x6, 0xbe, 0x53}, 322 {0x06, 0xbe, 0x53},
321 {} 323 {}
322}; 324};
323 325
324/* 326/*
325 Made by Tomasz Zablocki (skalamandra@poczta.onet.pl) 327 * Made by Tomasz Zablocki (skalamandra@poczta.onet.pl)
326 * SPCA505b chip based cameras initialization data 328 * SPCA505b chip based cameras initialization data
327 *
328 */ 329 */
329/* jfm */ 330/* jfm */
330#define initial_brightness 0x7f /* 0x0(white)-0xff(black) */ 331#define initial_brightness 0x7f /* 0x0(white)-0xff(black) */
@@ -332,7 +333,7 @@ static const __u16 spca505_open_data_ccd[][3] = {
332/* 333/*
333 * Data to initialize a SPCA505. Common to the CCD and external modes 334 * Data to initialize a SPCA505. Common to the CCD and external modes
334 */ 335 */
335static const __u16 spca505b_init_data[][3] = { 336static const u8 spca505b_init_data[][3] = {
336/* start */ 337/* start */
337 {0x02, 0x00, 0x00}, /* init */ 338 {0x02, 0x00, 0x00}, /* init */
338 {0x02, 0x00, 0x01}, 339 {0x02, 0x00, 0x01},
@@ -396,7 +397,7 @@ static const __u16 spca505b_init_data[][3] = {
396/* 397/*
397 * Data to initialize the camera using the internal CCD 398 * Data to initialize the camera using the internal CCD
398 */ 399 */
399static const __u16 spca505b_open_data_ccd[][3] = { 400static const u8 spca505b_open_data_ccd[][3] = {
400 401
401/* {0x02,0x00,0x00}, */ 402/* {0x02,0x00,0x00}, */
402 {0x03, 0x04, 0x01}, /* rst */ 403 {0x03, 0x04, 0x01}, /* rst */
@@ -426,7 +427,7 @@ static const __u16 spca505b_open_data_ccd[][3] = {
426 {0x05, 0x00, 0x12}, 427 {0x05, 0x00, 0x12},
427 {0x05, 0x6f, 0x00}, 428 {0x05, 0x6f, 0x00},
428 {0x05, initial_brightness >> 6, 0x00}, 429 {0x05, initial_brightness >> 6, 0x00},
429 {0x05, initial_brightness << 2, 0x01}, 430 {0x05, (initial_brightness << 2) & 0xff, 0x01},
430 {0x05, 0x00, 0x02}, 431 {0x05, 0x00, 0x02},
431 {0x05, 0x01, 0x03}, 432 {0x05, 0x01, 0x03},
432 {0x05, 0x00, 0x04}, 433 {0x05, 0x00, 0x04},
@@ -436,7 +437,7 @@ static const __u16 spca505b_open_data_ccd[][3] = {
436 {0x05, 0xa0, 0x08}, 437 {0x05, 0xa0, 0x08},
437 {0x05, 0x00, 0x12}, 438 {0x05, 0x00, 0x12},
438 {0x05, 0x02, 0x0f}, 439 {0x05, 0x02, 0x0f},
439 {0x05, 128, 0x14}, /* max exposure off (0=on) */ 440 {0x05, 0x80, 0x14}, /* max exposure off (0=on) */
440 {0x05, 0x01, 0xb0}, 441 {0x05, 0x01, 0xb0},
441 {0x05, 0x01, 0xbf}, 442 {0x05, 0x01, 0xbf},
442 {0x03, 0x02, 0x06}, 443 {0x03, 0x02, 0x06},
@@ -560,26 +561,26 @@ static const __u16 spca505b_open_data_ccd[][3] = {
560 {0x06, 0x32, 0x20}, 561 {0x06, 0x32, 0x20},
561 562
562 {0x05, initial_brightness >> 6, 0x00}, 563 {0x05, initial_brightness >> 6, 0x00},
563 {0x05, initial_brightness << 2, 0x01}, 564 {0x05, (initial_brightness << 2) & 0xff, 0x01},
564 {0x05, 0x06, 0xc1}, 565 {0x05, 0x06, 0xc1},
565 {0x05, 0x58, 0xc2}, 566 {0x05, 0x58, 0xc2},
566 {0x05, 0x0, 0xca}, 567 {0x05, 0x00, 0xca},
567 {0x05, 0x0, 0x11}, 568 {0x05, 0x00, 0x11},
568 {} 569 {}
569}; 570};
570 571
571static int reg_write(struct usb_device *dev, 572static int reg_write(struct usb_device *dev,
572 __u16 reg, __u16 index, __u16 value) 573 u16 req, u16 index, u16 value)
573{ 574{
574 int ret; 575 int ret;
575 576
576 ret = usb_control_msg(dev, 577 ret = usb_control_msg(dev,
577 usb_sndctrlpipe(dev, 0), 578 usb_sndctrlpipe(dev, 0),
578 reg, 579 req,
579 USB_TYPE_VENDOR | USB_RECIP_DEVICE, 580 USB_TYPE_VENDOR | USB_RECIP_DEVICE,
580 value, index, NULL, 0, 500); 581 value, index, NULL, 0, 500);
581 PDEBUG(D_PACK, "reg write: 0x%02x,0x%02x:0x%02x, 0x%x", 582 PDEBUG(D_USBO, "reg write: 0x%02x,0x%02x:0x%02x, %d",
582 reg, index, value, ret); 583 req, index, value, ret);
583 if (ret < 0) 584 if (ret < 0)
584 PDEBUG(D_ERR, "reg write: error %d", ret); 585 PDEBUG(D_ERR, "reg write: error %d", ret);
585 return ret; 586 return ret;
@@ -587,42 +588,34 @@ static int reg_write(struct usb_device *dev,
587 588
588/* returns: negative is error, pos or zero is data */ 589/* returns: negative is error, pos or zero is data */
589static int reg_read(struct gspca_dev *gspca_dev, 590static int reg_read(struct gspca_dev *gspca_dev,
590 __u16 reg, /* bRequest */ 591 u16 req, /* bRequest */
591 __u16 index, /* wIndex */ 592 u16 index) /* wIndex */
592 __u16 length) /* wLength (1 or 2 only) */
593{ 593{
594 int ret; 594 int ret;
595 595
596 gspca_dev->usb_buf[1] = 0;
597 ret = usb_control_msg(gspca_dev->dev, 596 ret = usb_control_msg(gspca_dev->dev,
598 usb_rcvctrlpipe(gspca_dev->dev, 0), 597 usb_rcvctrlpipe(gspca_dev->dev, 0),
599 reg, 598 req,
600 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 599 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
601 (__u16) 0, /* value */ 600 0, /* value */
602 (__u16) index, 601 index,
603 gspca_dev->usb_buf, length, 602 gspca_dev->usb_buf, 2,
604 500); /* timeout */ 603 500); /* timeout */
605 if (ret < 0) { 604 if (ret < 0)
606 PDEBUG(D_ERR, "reg_read err %d", ret); 605 return ret;
607 return -1;
608 }
609 return (gspca_dev->usb_buf[1] << 8) + gspca_dev->usb_buf[0]; 606 return (gspca_dev->usb_buf[1] << 8) + gspca_dev->usb_buf[0];
610} 607}
611 608
612static int write_vector(struct gspca_dev *gspca_dev, 609static int write_vector(struct gspca_dev *gspca_dev,
613 const __u16 data[][3]) 610 const u8 data[][3])
614{ 611{
615 struct usb_device *dev = gspca_dev->dev; 612 struct usb_device *dev = gspca_dev->dev;
616 int ret, i = 0; 613 int ret, i = 0;
617 614
618 while (data[i][0] != 0 || data[i][1] != 0 || data[i][2] != 0) { 615 while (data[i][0] != 0) {
619 ret = reg_write(dev, data[i][0], data[i][2], data[i][1]); 616 ret = reg_write(dev, data[i][0], data[i][2], data[i][1]);
620 if (ret < 0) { 617 if (ret < 0)
621 PDEBUG(D_ERR,
622 "Register write failed for 0x%x,0x%x,0x%x",
623 data[i][0], data[i][1], data[i][2]);
624 return ret; 618 return ret;
625 }
626 i++; 619 i++;
627 } 620 }
628 return 0; 621 return 0;
@@ -636,14 +629,13 @@ static int sd_config(struct gspca_dev *gspca_dev,
636 struct cam *cam; 629 struct cam *cam;
637 630
638 cam = &gspca_dev->cam; 631 cam = &gspca_dev->cam;
639 cam->epaddr = 0x01;
640 cam->cam_mode = vga_mode; 632 cam->cam_mode = vga_mode;
641 sd->subtype = id->driver_info; 633 sd->subtype = id->driver_info;
642 if (sd->subtype != IntelPCCameraPro) 634 if (sd->subtype != IntelPCCameraPro)
643 cam->nmodes = sizeof vga_mode / sizeof vga_mode[0]; 635 cam->nmodes = ARRAY_SIZE(vga_mode);
644 else /* no 640x480 for IntelPCCameraPro */ 636 else /* no 640x480 for IntelPCCameraPro */
645 cam->nmodes = sizeof vga_mode / sizeof vga_mode[0] - 1; 637 cam->nmodes = ARRAY_SIZE(vga_mode) - 1;
646 sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value; 638 sd->brightness = BRIGHTNESS_DEF;
647 639
648 if (sd->subtype == Nxultra) { 640 if (sd->subtype == Nxultra) {
649 if (write_vector(gspca_dev, spca505b_init_data)) 641 if (write_vector(gspca_dev, spca505b_init_data))
@@ -658,81 +650,71 @@ static int sd_config(struct gspca_dev *gspca_dev,
658/* this function is called at probe and resume time */ 650/* this function is called at probe and resume time */
659static int sd_init(struct gspca_dev *gspca_dev) 651static int sd_init(struct gspca_dev *gspca_dev)
660{ 652{
653 return 0;
654}
655
656static void setbrightness(struct gspca_dev *gspca_dev)
657{
661 struct sd *sd = (struct sd *) gspca_dev; 658 struct sd *sd = (struct sd *) gspca_dev;
662 int ret; 659 u8 brightness = sd->brightness;
660
661 reg_write(gspca_dev->dev, 0x05, 0x00, (255 - brightness) >> 6);
662 reg_write(gspca_dev->dev, 0x05, 0x01, (255 - brightness) << 2);
663}
664
665static int sd_start(struct gspca_dev *gspca_dev)
666{
667 struct sd *sd = (struct sd *) gspca_dev;
668 struct usb_device *dev = gspca_dev->dev;
669 int ret, mode;
670 static u8 mode_tb[][3] = {
671 /* r00 r06 r07 */
672 {0x00, 0x10, 0x10}, /* 640x480 */
673 {0x01, 0x1a, 0x1a}, /* 352x288 */
674 {0x02, 0x1c, 0x1d}, /* 320x240 */
675 {0x04, 0x34, 0x34}, /* 176x144 */
676 {0x05, 0x40, 0x40} /* 160x120 */
677 };
663 678
664 PDEBUG(D_STREAM, "Initializing SPCA505");
665 if (sd->subtype == Nxultra) 679 if (sd->subtype == Nxultra)
666 write_vector(gspca_dev, spca505b_open_data_ccd); 680 write_vector(gspca_dev, spca505b_open_data_ccd);
667 else 681 else
668 write_vector(gspca_dev, spca505_open_data_ccd); 682 write_vector(gspca_dev, spca505_open_data_ccd);
669 ret = reg_read(gspca_dev, 6, 0x16, 2); 683 ret = reg_read(gspca_dev, 0x06, 0x16);
670 684
671 if (ret < 0) { 685 if (ret < 0) {
672 PDEBUG(D_ERR|D_STREAM, 686 PDEBUG(D_ERR|D_CONF,
673 "register read failed for after vector read err = %d", 687 "register read failed err: %d",
674 ret); 688 ret);
675 return -EIO; 689 return ret;
676 } 690 }
677 PDEBUG(D_STREAM, 691 if (ret != 0x0101) {
678 "After vector read returns : 0x%x should be 0x0101", 692 PDEBUG(D_ERR|D_CONF,
679 ret & 0xffff); 693 "After vector read returns 0x%04x should be 0x0101",
680 694 ret);
681 ret = reg_write(gspca_dev->dev, 6, 0x16, 0x0a);
682 if (ret < 0) {
683 PDEBUG(D_ERR, "register write failed for (6,0xa,0x16) err=%d",
684 ret);
685 return -EIO;
686 } 695 }
687 reg_write(gspca_dev->dev, 5, 0xc2, 18);
688 return 0;
689}
690 696
691static int sd_start(struct gspca_dev *gspca_dev) 697 ret = reg_write(gspca_dev->dev, 0x06, 0x16, 0x0a);
692{ 698 if (ret < 0)
693 struct usb_device *dev = gspca_dev->dev; 699 return ret;
694 int ret; 700 reg_write(gspca_dev->dev, 0x05, 0xc2, 0x12);
695 701
696 /* necessary because without it we can see stream 702 /* necessary because without it we can see stream
697 * only once after loading module */ 703 * only once after loading module */
698 /* stopping usb registers Tomasz change */ 704 /* stopping usb registers Tomasz change */
699 reg_write(dev, 0x02, 0x0, 0x0); 705 reg_write(dev, 0x02, 0x00, 0x00);
700 switch (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv) { 706
701 case 0: 707 mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
702 reg_write(dev, 0x04, 0x00, 0x00); 708 reg_write(dev, SPCA50X_REG_COMPRESS, 0x00, mode_tb[mode][0]);
703 reg_write(dev, 0x04, 0x06, 0x10); 709 reg_write(dev, SPCA50X_REG_COMPRESS, 0x06, mode_tb[mode][1]);
704 reg_write(dev, 0x04, 0x07, 0x10); 710 reg_write(dev, SPCA50X_REG_COMPRESS, 0x07, mode_tb[mode][2]);
705 break; 711
706 case 1:
707 reg_write(dev, 0x04, 0x00, 0x01);
708 reg_write(dev, 0x04, 0x06, 0x1a);
709 reg_write(dev, 0x04, 0x07, 0x1a);
710 break;
711 case 2:
712 reg_write(dev, 0x04, 0x00, 0x02);
713 reg_write(dev, 0x04, 0x06, 0x1c);
714 reg_write(dev, 0x04, 0x07, 0x1d);
715 break;
716 case 4:
717 reg_write(dev, 0x04, 0x00, 0x04);
718 reg_write(dev, 0x04, 0x06, 0x34);
719 reg_write(dev, 0x04, 0x07, 0x34);
720 break;
721 default:
722/* case 5: */
723 reg_write(dev, 0x04, 0x00, 0x05);
724 reg_write(dev, 0x04, 0x06, 0x40);
725 reg_write(dev, 0x04, 0x07, 0x40);
726 break;
727 }
728/* Enable ISO packet machine - should we do this here or in ISOC init ? */
729 ret = reg_write(dev, SPCA50X_REG_USB, 712 ret = reg_write(dev, SPCA50X_REG_USB,
730 SPCA50X_USB_CTRL, 713 SPCA50X_USB_CTRL,
731 SPCA50X_CUSB_ENABLE); 714 SPCA50X_CUSB_ENABLE);
732 715
733/* reg_write(dev, 0x5, 0x0, 0x0); */ 716 setbrightness(gspca_dev);
734/* reg_write(dev, 0x5, 0x0, 0x1); */ 717
735/* reg_write(dev, 0x5, 0x11, 0x2); */
736 return ret; 718 return ret;
737} 719}
738 720
@@ -750,15 +732,15 @@ static void sd_stop0(struct gspca_dev *gspca_dev)
750 732
751 /* This maybe reset or power control */ 733 /* This maybe reset or power control */
752 reg_write(gspca_dev->dev, 0x03, 0x03, 0x20); 734 reg_write(gspca_dev->dev, 0x03, 0x03, 0x20);
753 reg_write(gspca_dev->dev, 0x03, 0x01, 0x0); 735 reg_write(gspca_dev->dev, 0x03, 0x01, 0x00);
754 reg_write(gspca_dev->dev, 0x03, 0x00, 0x1); 736 reg_write(gspca_dev->dev, 0x03, 0x00, 0x01);
755 reg_write(gspca_dev->dev, 0x05, 0x10, 0x1); 737 reg_write(gspca_dev->dev, 0x05, 0x10, 0x01);
756 reg_write(gspca_dev->dev, 0x05, 0x11, 0xf); 738 reg_write(gspca_dev->dev, 0x05, 0x11, 0x0f);
757} 739}
758 740
759static void sd_pkt_scan(struct gspca_dev *gspca_dev, 741static void sd_pkt_scan(struct gspca_dev *gspca_dev,
760 struct gspca_frame *frame, /* target */ 742 struct gspca_frame *frame, /* target */
761 __u8 *data, /* isoc packet */ 743 u8 *data, /* isoc packet */
762 int len) /* iso packet length */ 744 int len) /* iso packet length */
763{ 745{
764 switch (data[0]) { 746 switch (data[0]) {
@@ -771,7 +753,6 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
771 data, len); 753 data, len);
772 break; 754 break;
773 case 0xff: /* drop */ 755 case 0xff: /* drop */
774/* gspca_dev->last_packet_type = DISCARD_PACKET; */
775 break; 756 break;
776 default: 757 default:
777 data += 1; 758 data += 1;
@@ -782,24 +763,6 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
782 } 763 }
783} 764}
784 765
785static void setbrightness(struct gspca_dev *gspca_dev)
786{
787 struct sd *sd = (struct sd *) gspca_dev;
788
789 __u8 brightness = sd->brightness;
790 reg_write(gspca_dev->dev, 5, 0x00, (255 - brightness) >> 6);
791 reg_write(gspca_dev->dev, 5, 0x01, (255 - brightness) << 2);
792
793}
794static void getbrightness(struct gspca_dev *gspca_dev)
795{
796 struct sd *sd = (struct sd *) gspca_dev;
797
798 sd->brightness = 255
799 - ((reg_read(gspca_dev, 5, 0x01, 1) >> 2)
800 + (reg_read(gspca_dev, 5, 0x0, 1) << 6));
801}
802
803static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val) 766static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
804{ 767{
805 struct sd *sd = (struct sd *) gspca_dev; 768 struct sd *sd = (struct sd *) gspca_dev;
@@ -814,7 +777,6 @@ static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
814{ 777{
815 struct sd *sd = (struct sd *) gspca_dev; 778 struct sd *sd = (struct sd *) gspca_dev;
816 779
817 getbrightness(gspca_dev);
818 *val = sd->brightness; 780 *val = sd->brightness;
819 return 0; 781 return 0;
820} 782}
@@ -863,8 +825,11 @@ static struct usb_driver sd_driver = {
863/* -- module insert / remove -- */ 825/* -- module insert / remove -- */
864static int __init sd_mod_init(void) 826static int __init sd_mod_init(void)
865{ 827{
866 if (usb_register(&sd_driver) < 0) 828 int ret;
867 return -1; 829
830 ret = usb_register(&sd_driver);
831 if (ret < 0)
832 return ret;
868 PDEBUG(D_PROBE, "registered"); 833 PDEBUG(D_PROBE, "registered");
869 return 0; 834 return 0;
870} 835}
diff --git a/drivers/media/video/gspca/spca506.c b/drivers/media/video/gspca/spca506.c
index 96e2512e0621..3a0c893f942d 100644
--- a/drivers/media/video/gspca/spca506.c
+++ b/drivers/media/video/gspca/spca506.c
@@ -193,24 +193,6 @@ static void spca506_WriteI2c(struct gspca_dev *gspca_dev, __u16 valeur,
193 } 193 }
194} 194}
195 195
196static int spca506_ReadI2c(struct gspca_dev *gspca_dev, __u16 reg)
197{
198 int retry = 60;
199
200 reg_w(gspca_dev->dev, 0x07, SAA7113_I2C_BASE_WRITE, 0x0004);
201 reg_w(gspca_dev->dev, 0x07, reg, 0x0001);
202 reg_w(gspca_dev->dev, 0x07, 0x01, 0x0002);
203 while (--retry) {
204 reg_r(gspca_dev, 0x07, 0x0003, 2);
205 if ((gspca_dev->usb_buf[0] | gspca_dev->usb_buf[1]) == 0x00)
206 break;
207 }
208 if (retry == 0)
209 return -1;
210 reg_r(gspca_dev, 0x07, 0x0000, 1);
211 return gspca_dev->usb_buf[0];
212}
213
214static void spca506_SetNormeInput(struct gspca_dev *gspca_dev, 196static void spca506_SetNormeInput(struct gspca_dev *gspca_dev,
215 __u16 norme, 197 __u16 norme,
216 __u16 channel) 198 __u16 channel)
@@ -303,7 +285,6 @@ static int sd_config(struct gspca_dev *gspca_dev,
303 struct cam *cam; 285 struct cam *cam;
304 286
305 cam = &gspca_dev->cam; 287 cam = &gspca_dev->cam;
306 cam->epaddr = 0x01;
307 cam->cam_mode = vga_mode; 288 cam->cam_mode = vga_mode;
308 cam->nmodes = sizeof vga_mode / sizeof vga_mode[0]; 289 cam->nmodes = sizeof vga_mode / sizeof vga_mode[0];
309 sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value; 290 sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value;
@@ -596,13 +577,6 @@ static void setbrightness(struct gspca_dev *gspca_dev)
596 spca506_WriteI2c(gspca_dev, 0x01, 0x09); 577 spca506_WriteI2c(gspca_dev, 0x01, 0x09);
597} 578}
598 579
599static void getbrightness(struct gspca_dev *gspca_dev)
600{
601 struct sd *sd = (struct sd *) gspca_dev;
602
603 sd->brightness = spca506_ReadI2c(gspca_dev, SAA7113_bright);
604}
605
606static void setcontrast(struct gspca_dev *gspca_dev) 580static void setcontrast(struct gspca_dev *gspca_dev)
607{ 581{
608 struct sd *sd = (struct sd *) gspca_dev; 582 struct sd *sd = (struct sd *) gspca_dev;
@@ -612,13 +586,6 @@ static void setcontrast(struct gspca_dev *gspca_dev)
612 spca506_WriteI2c(gspca_dev, 0x01, 0x09); 586 spca506_WriteI2c(gspca_dev, 0x01, 0x09);
613} 587}
614 588
615static void getcontrast(struct gspca_dev *gspca_dev)
616{
617 struct sd *sd = (struct sd *) gspca_dev;
618
619 sd->contrast = spca506_ReadI2c(gspca_dev, SAA7113_contrast);
620}
621
622static void setcolors(struct gspca_dev *gspca_dev) 589static void setcolors(struct gspca_dev *gspca_dev)
623{ 590{
624 struct sd *sd = (struct sd *) gspca_dev; 591 struct sd *sd = (struct sd *) gspca_dev;
@@ -628,13 +595,6 @@ static void setcolors(struct gspca_dev *gspca_dev)
628 spca506_WriteI2c(gspca_dev, 0x01, 0x09); 595 spca506_WriteI2c(gspca_dev, 0x01, 0x09);
629} 596}
630 597
631static void getcolors(struct gspca_dev *gspca_dev)
632{
633 struct sd *sd = (struct sd *) gspca_dev;
634
635 sd->colors = spca506_ReadI2c(gspca_dev, SAA7113_saturation);
636}
637
638static void sethue(struct gspca_dev *gspca_dev) 598static void sethue(struct gspca_dev *gspca_dev)
639{ 599{
640 struct sd *sd = (struct sd *) gspca_dev; 600 struct sd *sd = (struct sd *) gspca_dev;
@@ -644,13 +604,6 @@ static void sethue(struct gspca_dev *gspca_dev)
644 spca506_WriteI2c(gspca_dev, 0x01, 0x09); 604 spca506_WriteI2c(gspca_dev, 0x01, 0x09);
645} 605}
646 606
647static void gethue(struct gspca_dev *gspca_dev)
648{
649 struct sd *sd = (struct sd *) gspca_dev;
650
651 sd->hue = spca506_ReadI2c(gspca_dev, SAA7113_hue);
652}
653
654static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val) 607static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
655{ 608{
656 struct sd *sd = (struct sd *) gspca_dev; 609 struct sd *sd = (struct sd *) gspca_dev;
@@ -665,7 +618,6 @@ static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
665{ 618{
666 struct sd *sd = (struct sd *) gspca_dev; 619 struct sd *sd = (struct sd *) gspca_dev;
667 620
668 getbrightness(gspca_dev);
669 *val = sd->brightness; 621 *val = sd->brightness;
670 return 0; 622 return 0;
671} 623}
@@ -684,7 +636,6 @@ static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
684{ 636{
685 struct sd *sd = (struct sd *) gspca_dev; 637 struct sd *sd = (struct sd *) gspca_dev;
686 638
687 getcontrast(gspca_dev);
688 *val = sd->contrast; 639 *val = sd->contrast;
689 return 0; 640 return 0;
690} 641}
@@ -703,7 +654,6 @@ static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
703{ 654{
704 struct sd *sd = (struct sd *) gspca_dev; 655 struct sd *sd = (struct sd *) gspca_dev;
705 656
706 getcolors(gspca_dev);
707 *val = sd->colors; 657 *val = sd->colors;
708 return 0; 658 return 0;
709} 659}
@@ -722,7 +672,6 @@ static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val)
722{ 672{
723 struct sd *sd = (struct sd *) gspca_dev; 673 struct sd *sd = (struct sd *) gspca_dev;
724 674
725 gethue(gspca_dev);
726 *val = sd->hue; 675 *val = sd->hue;
727 return 0; 676 return 0;
728} 677}
@@ -772,8 +721,10 @@ static struct usb_driver sd_driver = {
772/* -- module insert / remove -- */ 721/* -- module insert / remove -- */
773static int __init sd_mod_init(void) 722static int __init sd_mod_init(void)
774{ 723{
775 if (usb_register(&sd_driver) < 0) 724 int ret;
776 return -1; 725 ret = usb_register(&sd_driver);
726 if (ret < 0)
727 return ret;
777 PDEBUG(D_PROBE, "registered"); 728 PDEBUG(D_PROBE, "registered");
778 return 0; 729 return 0;
779} 730}
diff --git a/drivers/media/video/gspca/spca508.c b/drivers/media/video/gspca/spca508.c
index be5d740a315d..adacf8437661 100644
--- a/drivers/media/video/gspca/spca508.c
+++ b/drivers/media/video/gspca/spca508.c
@@ -101,8 +101,7 @@ static const struct v4l2_pix_format sif_mode[] = {
101 * Initialization data: this is the first set-up data written to the 101 * Initialization data: this is the first set-up data written to the
102 * device (before the open data). 102 * device (before the open data).
103 */ 103 */
104static const __u16 spca508_init_data[][3] = 104static const u16 spca508_init_data[][2] =
105#define IGN(x) /* nothing */
106{ 105{
107 /* line URB value, index */ 106 /* line URB value, index */
108 /* 44274 1804 */ {0x0000, 0x870b}, 107 /* 44274 1804 */ {0x0000, 0x870b},
@@ -589,11 +588,10 @@ static const __u16 spca508_init_data[][3] =
589 {} 588 {}
590}; 589};
591 590
592
593/* 591/*
594 * Initialization data for Intel EasyPC Camera CS110 592 * Initialization data for Intel EasyPC Camera CS110
595 */ 593 */
596static const __u16 spca508cs110_init_data[][3] = { 594static const u16 spca508cs110_init_data[][2] = {
597 {0x0000, 0x870b}, /* Reset CTL3 */ 595 {0x0000, 0x870b}, /* Reset CTL3 */
598 {0x0003, 0x8111}, /* Soft Reset compression, memory, TG & CDSP */ 596 {0x0003, 0x8111}, /* Soft Reset compression, memory, TG & CDSP */
599 {0x0000, 0x8111}, /* Normal operation on reset */ 597 {0x0000, 0x8111}, /* Normal operation on reset */
@@ -677,7 +675,7 @@ static const __u16 spca508cs110_init_data[][3] = {
677 {} 675 {}
678}; 676};
679 677
680static const __u16 spca508_sightcam_init_data[][3] = { 678static const u16 spca508_sightcam_init_data[][2] = {
681/* This line seems to setup the frame/canvas */ 679/* This line seems to setup the frame/canvas */
682 /*368 */ {0x000f, 0x8402}, 680 /*368 */ {0x000f, 0x8402},
683 681
@@ -760,7 +758,7 @@ static const __u16 spca508_sightcam_init_data[][3] = {
760 {} 758 {}
761}; 759};
762 760
763static const __u16 spca508_sightcam2_init_data[][3] = { 761static const u16 spca508_sightcam2_init_data[][2] = {
764/* 35 */ {0x0020, 0x8112}, 762/* 35 */ {0x0020, 0x8112},
765 763
766/* 36 */ {0x000f, 0x8402}, 764/* 36 */ {0x000f, 0x8402},
@@ -1107,7 +1105,7 @@ static const __u16 spca508_sightcam2_init_data[][3] = {
1107/* 1105/*
1108 * Initialization data for Creative Webcam Vista 1106 * Initialization data for Creative Webcam Vista
1109 */ 1107 */
1110static const __u16 spca508_vista_init_data[][3] = { 1108static const u16 spca508_vista_init_data[][2] = {
1111 {0x0008, 0x8200}, /* Clear register */ 1109 {0x0008, 0x8200}, /* Clear register */
1112 {0x0000, 0x870b}, /* Reset CTL3 */ 1110 {0x0000, 0x870b}, /* Reset CTL3 */
1113 {0x0020, 0x8112}, /* Video Drop packet enable */ 1111 {0x0020, 0x8112}, /* Video Drop packet enable */
@@ -1309,18 +1307,18 @@ static const __u16 spca508_vista_init_data[][3] = {
1309 1307
1310 {0x0050, 0x8703}, 1308 {0x0050, 0x8703},
1311 {0x0002, 0x8704}, /* External input CKIx1 */ 1309 {0x0002, 0x8704}, /* External input CKIx1 */
1312 {0x0001, 0x870C}, /* Select CKOx2 output */ 1310 {0x0001, 0x870c}, /* Select CKOx2 output */
1313 {0x009A, 0x8600}, /* Line memory Read Counter (L) */ 1311 {0x009a, 0x8600}, /* Line memory Read Counter (L) */
1314 {0x0001, 0x8606}, /* 1 Line memory Read Counter (H) Result: (d)410 */ 1312 {0x0001, 0x8606}, /* 1 Line memory Read Counter (H) Result: (d)410 */
1315 {0x0023, 0x8601}, 1313 {0x0023, 0x8601},
1316 {0x0010, 0x8602}, 1314 {0x0010, 0x8602},
1317 {0x000A, 0x8603}, 1315 {0x000a, 0x8603},
1318 {0x009A, 0x8600}, 1316 {0x009A, 0x8600},
1319 {0x0001, 0x865B}, /* 1 Horizontal Offset for Valid Pixel(L) */ 1317 {0x0001, 0x865b}, /* 1 Horizontal Offset for Valid Pixel(L) */
1320 {0x0003, 0x865C}, /* Vertical offset for valid lines (L) */ 1318 {0x0003, 0x865c}, /* Vertical offset for valid lines (L) */
1321 {0x0058, 0x865D}, /* Horizontal valid pixels window (L) */ 1319 {0x0058, 0x865d}, /* Horizontal valid pixels window (L) */
1322 {0x0048, 0x865E}, /* Vertical valid lines window (L) */ 1320 {0x0048, 0x865e}, /* Vertical valid lines window (L) */
1323 {0x0000, 0x865F}, 1321 {0x0000, 0x865f},
1324 1322
1325 {0x0006, 0x8660}, 1323 {0x0006, 0x8660},
1326 /* Enable nibble data input, select nibble input order */ 1324 /* Enable nibble data input, select nibble input order */
@@ -1328,63 +1326,63 @@ static const __u16 spca508_vista_init_data[][3] = {
1328 {0x0013, 0x8608}, /* A11 Coeficients for color correction */ 1326 {0x0013, 0x8608}, /* A11 Coeficients for color correction */
1329 {0x0028, 0x8609}, 1327 {0x0028, 0x8609},
1330 /* Note: these values are confirmed at the end of array */ 1328 /* Note: these values are confirmed at the end of array */
1331 {0x0005, 0x860A}, /* ... */ 1329 {0x0005, 0x860a}, /* ... */
1332 {0x0025, 0x860B}, 1330 {0x0025, 0x860b},
1333 {0x00E1, 0x860C}, 1331 {0x00e1, 0x860c},
1334 {0x00FA, 0x860D}, 1332 {0x00fa, 0x860D},
1335 {0x00F4, 0x860E}, 1333 {0x00f4, 0x860e},
1336 {0x00E8, 0x860F}, 1334 {0x00e8, 0x860f},
1337 {0x0025, 0x8610}, /* A33 Coef. */ 1335 {0x0025, 0x8610}, /* A33 Coef. */
1338 {0x00FC, 0x8611}, /* White balance offset: R */ 1336 {0x00fc, 0x8611}, /* White balance offset: R */
1339 {0x0001, 0x8612}, /* White balance offset: Gr */ 1337 {0x0001, 0x8612}, /* White balance offset: Gr */
1340 {0x00FE, 0x8613}, /* White balance offset: B */ 1338 {0x00fe, 0x8613}, /* White balance offset: B */
1341 {0x0000, 0x8614}, /* White balance offset: Gb */ 1339 {0x0000, 0x8614}, /* White balance offset: Gb */
1342 1340
1343 {0x0064, 0x8651}, /* R gain for white balance (L) */ 1341 {0x0064, 0x8651}, /* R gain for white balance (L) */
1344 {0x0040, 0x8652}, /* Gr gain for white balance (L) */ 1342 {0x0040, 0x8652}, /* Gr gain for white balance (L) */
1345 {0x0066, 0x8653}, /* B gain for white balance (L) */ 1343 {0x0066, 0x8653}, /* B gain for white balance (L) */
1346 {0x0040, 0x8654}, /* Gb gain for white balance (L) */ 1344 {0x0040, 0x8654}, /* Gb gain for white balance (L) */
1347 {0x0001, 0x863F}, /* Enable fixed gamma correction */ 1345 {0x0001, 0x863f}, /* Enable fixed gamma correction */
1348 1346
1349 {0x00A1, 0x8656}, /* Size - Window1: 256x256, Window2: 128x128 */ 1347 {0x00a1, 0x8656}, /* Size - Window1: 256x256, Window2: 128x128 */
1350 /* UV division: UV no change, Enable New edge enhancement */ 1348 /* UV division: UV no change, Enable New edge enhancement */
1351 {0x0018, 0x8657}, /* Edge gain high threshold */ 1349 {0x0018, 0x8657}, /* Edge gain high threshold */
1352 {0x0020, 0x8658}, /* Edge gain low threshold */ 1350 {0x0020, 0x8658}, /* Edge gain low threshold */
1353 {0x000A, 0x8659}, /* Edge bandwidth high threshold */ 1351 {0x000A, 0x8659}, /* Edge bandwidth high threshold */
1354 {0x0005, 0x865A}, /* Edge bandwidth low threshold */ 1352 {0x0005, 0x865a}, /* Edge bandwidth low threshold */
1355 {0x0064, 0x8607}, /* UV filter enable */ 1353 {0x0064, 0x8607}, /* UV filter enable */
1356 1354
1357 {0x0016, 0x8660}, 1355 {0x0016, 0x8660},
1358 {0x0000, 0x86B0}, /* Bad pixels compensation address */ 1356 {0x0000, 0x86b0}, /* Bad pixels compensation address */
1359 {0x00DC, 0x86B1}, /* X coord for bad pixels compensation (L) */ 1357 {0x00dc, 0x86b1}, /* X coord for bad pixels compensation (L) */
1360 {0x0000, 0x86B2}, 1358 {0x0000, 0x86b2},
1361 {0x0009, 0x86B3}, /* Y coord for bad pixels compensation (L) */ 1359 {0x0009, 0x86b3}, /* Y coord for bad pixels compensation (L) */
1362 {0x0000, 0x86B4}, 1360 {0x0000, 0x86b4},
1363 1361
1364 {0x0001, 0x86B0}, 1362 {0x0001, 0x86b0},
1365 {0x00F5, 0x86B1}, 1363 {0x00f5, 0x86b1},
1366 {0x0000, 0x86B2}, 1364 {0x0000, 0x86b2},
1367 {0x00C6, 0x86B3}, 1365 {0x00c6, 0x86b3},
1368 {0x0000, 0x86B4}, 1366 {0x0000, 0x86b4},
1369 1367
1370 {0x0002, 0x86B0}, 1368 {0x0002, 0x86b0},
1371 {0x001C, 0x86B1}, 1369 {0x001c, 0x86b1},
1372 {0x0001, 0x86B2}, 1370 {0x0001, 0x86b2},
1373 {0x00D7, 0x86B3}, 1371 {0x00d7, 0x86b3},
1374 {0x0000, 0x86B4}, 1372 {0x0000, 0x86b4},
1375 1373
1376 {0x0003, 0x86B0}, 1374 {0x0003, 0x86b0},
1377 {0x001C, 0x86B1}, 1375 {0x001c, 0x86b1},
1378 {0x0001, 0x86B2}, 1376 {0x0001, 0x86b2},
1379 {0x00D8, 0x86B3}, 1377 {0x00d8, 0x86b3},
1380 {0x0000, 0x86B4}, 1378 {0x0000, 0x86b4},
1381 1379
1382 {0x0004, 0x86B0}, 1380 {0x0004, 0x86b0},
1383 {0x001D, 0x86B1}, 1381 {0x001d, 0x86b1},
1384 {0x0001, 0x86B2}, 1382 {0x0001, 0x86b2},
1385 {0x00D8, 0x86B3}, 1383 {0x00d8, 0x86b3},
1386 {0x0000, 0x86B4}, 1384 {0x0000, 0x86b4},
1387 {0x001E, 0x8660}, 1385 {0x001e, 0x8660},
1388 1386
1389 /* READ { 0, 0x0000, 0x8608 } -> 1387 /* READ { 0, 0x0000, 0x8608 } ->
1390 0000: 13 */ 1388 0000: 13 */
@@ -1449,7 +1447,7 @@ static int reg_read(struct gspca_dev *gspca_dev,
1449} 1447}
1450 1448
1451static int write_vector(struct gspca_dev *gspca_dev, 1449static int write_vector(struct gspca_dev *gspca_dev,
1452 const __u16 data[][3]) 1450 const u16 data[][2])
1453{ 1451{
1454 struct usb_device *dev = gspca_dev->dev; 1452 struct usb_device *dev = gspca_dev->dev;
1455 int ret, i = 0; 1453 int ret, i = 0;
@@ -1487,7 +1485,6 @@ static int sd_config(struct gspca_dev *gspca_dev,
1487 PDEBUG(D_PROBE, "Window 1 average luminance: %d", data1); 1485 PDEBUG(D_PROBE, "Window 1 average luminance: %d", data1);
1488 1486
1489 cam = &gspca_dev->cam; 1487 cam = &gspca_dev->cam;
1490 cam->epaddr = 0x01;
1491 cam->cam_mode = sif_mode; 1488 cam->cam_mode = sif_mode;
1492 cam->nmodes = ARRAY_SIZE(sif_mode); 1489 cam->nmodes = ARRAY_SIZE(sif_mode);
1493 1490
@@ -1593,13 +1590,6 @@ static void setbrightness(struct gspca_dev *gspca_dev)
1593 reg_write(gspca_dev->dev, 0x8654, brightness); 1590 reg_write(gspca_dev->dev, 0x8654, brightness);
1594} 1591}
1595 1592
1596static void getbrightness(struct gspca_dev *gspca_dev)
1597{
1598 struct sd *sd = (struct sd *) gspca_dev;
1599
1600 sd->brightness = reg_read(gspca_dev, 0x8651);
1601}
1602
1603static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val) 1593static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
1604{ 1594{
1605 struct sd *sd = (struct sd *) gspca_dev; 1595 struct sd *sd = (struct sd *) gspca_dev;
@@ -1614,7 +1604,6 @@ static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
1614{ 1604{
1615 struct sd *sd = (struct sd *) gspca_dev; 1605 struct sd *sd = (struct sd *) gspca_dev;
1616 1606
1617 getbrightness(gspca_dev);
1618 *val = sd->brightness; 1607 *val = sd->brightness;
1619 return 0; 1608 return 0;
1620} 1609}
@@ -1666,8 +1655,11 @@ static struct usb_driver sd_driver = {
1666/* -- module insert / remove -- */ 1655/* -- module insert / remove -- */
1667static int __init sd_mod_init(void) 1656static int __init sd_mod_init(void)
1668{ 1657{
1669 if (usb_register(&sd_driver) < 0) 1658 int ret;
1670 return -1; 1659
1660 ret = usb_register(&sd_driver);
1661 if (ret < 0)
1662 return ret;
1671 PDEBUG(D_PROBE, "registered"); 1663 PDEBUG(D_PROBE, "registered");
1672 return 0; 1664 return 0;
1673} 1665}
diff --git a/drivers/media/video/gspca/spca561.c b/drivers/media/video/gspca/spca561.c
index 3c9288019e96..c99c5e34e211 100644
--- a/drivers/media/video/gspca/spca561.c
+++ b/drivers/media/video/gspca/spca561.c
@@ -141,38 +141,38 @@ static const struct v4l2_pix_format sif_072a_mode[] = {
141#define SPCA561_OFFSET_WIN1GBAVE 14 141#define SPCA561_OFFSET_WIN1GBAVE 14
142#define SPCA561_OFFSET_FREQ 15 142#define SPCA561_OFFSET_FREQ 15
143#define SPCA561_OFFSET_VSYNC 16 143#define SPCA561_OFFSET_VSYNC 16
144#define SPCA561_OFFSET_DATA 1
145#define SPCA561_INDEX_I2C_BASE 0x8800 144#define SPCA561_INDEX_I2C_BASE 0x8800
146#define SPCA561_SNAPBIT 0x20 145#define SPCA561_SNAPBIT 0x20
147#define SPCA561_SNAPCTRL 0x40 146#define SPCA561_SNAPCTRL 0x40
148 147
149static const __u16 rev72a_init_data1[][2] = { 148static const u16 rev72a_reset[][2] = {
150 {0x0000, 0x8114}, /* Software GPIO output data */ 149 {0x0000, 0x8114}, /* Software GPIO output data */
151 {0x0001, 0x8114}, /* Software GPIO output data */ 150 {0x0001, 0x8114}, /* Software GPIO output data */
152 {0x0000, 0x8112}, /* Some kind of reset */ 151 {0x0000, 0x8112}, /* Some kind of reset */
152 {}
153};
154static const __u16 rev72a_init_data1[][2] = {
153 {0x0003, 0x8701}, /* PCLK clock delay adjustment */ 155 {0x0003, 0x8701}, /* PCLK clock delay adjustment */
154 {0x0001, 0x8703}, /* HSYNC from cmos inverted */ 156 {0x0001, 0x8703}, /* HSYNC from cmos inverted */
155 {0x0011, 0x8118}, /* Enable and conf sensor */ 157 {0x0011, 0x8118}, /* Enable and conf sensor */
156 {0x0001, 0x8118}, /* Conf sensor */ 158 {0x0001, 0x8118}, /* Conf sensor */
157 {0x0092, 0x8804}, /* I know nothing about these */ 159 {0x0092, 0x8804}, /* I know nothing about these */
158 {0x0010, 0x8802}, /* 0x88xx registers, so I won't */ 160 {0x0010, 0x8802}, /* 0x88xx registers, so I won't */
159 {0x000d, 0x8805}, /* sensor default setting */
160 {} 161 {}
161}; 162};
162static const __u16 rev72a_init_sensor1[][2] = { 163static const u16 rev72a_init_sensor1[][2] = {
163 /* ms-win values */ 164 {0x0001, 0x000d},
164 {0x0001, 0x0018}, /* 0x01 <- 0x0d */ 165 {0x0002, 0x0018},
165 {0x0002, 0x0065}, /* 0x02 <- 0x18 */ 166 {0x0004, 0x0165},
166 {0x0004, 0x0121}, /* 0x04 <- 0x0165 */ 167 {0x0005, 0x0021},
167 {0x0005, 0x00aa}, /* 0x05 <- 0x21 */ 168 {0x0007, 0x00aa},
168 {0x0007, 0x0004}, /* 0x07 <- 0xaa */ 169 {0x0020, 0x1504},
169 {0x0020, 0x1502}, /* 0x20 <- 0x1504 */ 170 {0x0039, 0x0002},
170 {0x0039, 0x0010}, /* 0x39 <- 0x02 */ 171 {0x0035, 0x0010},
171 {0x0035, 0x0049}, /* 0x35 <- 0x10 */ 172 {0x0009, 0x1049},
172 {0x0009, 0x100b}, /* 0x09 <- 0x1049 */ 173 {0x0028, 0x000b},
173 {0x0028, 0x000f}, /* 0x28 <- 0x0b */ 174 {0x003b, 0x000f},
174 {0x003b, 0x003c}, /* 0x3b <- 0x0f */ 175 {0x003c, 0x0000},
175 {0x003c, 0x0000}, /* 0x3c <- 0x00 */
176 {} 176 {}
177}; 177};
178static const __u16 rev72a_init_data2[][2] = { 178static const __u16 rev72a_init_data2[][2] = {
@@ -190,15 +190,10 @@ static const __u16 rev72a_init_data2[][2] = {
190 {0x0002, 0x8201}, /* Output address for r/w serial EEPROM */ 190 {0x0002, 0x8201}, /* Output address for r/w serial EEPROM */
191 {0x0008, 0x8200}, /* Clear valid bit for serial EEPROM */ 191 {0x0008, 0x8200}, /* Clear valid bit for serial EEPROM */
192 {0x0001, 0x8200}, /* OprMode to be executed by hardware */ 192 {0x0001, 0x8200}, /* OprMode to be executed by hardware */
193 {0x0007, 0x8201}, /* Output address for r/w serial EEPROM */ 193/* from ms-win */
194 {0x0008, 0x8200}, /* Clear valid bit for serial EEPROM */ 194 {0x0000, 0x8611}, /* R offset for white balance */
195 {0x0001, 0x8200}, /* OprMode to be executed by hardware */ 195 {0x00fd, 0x8612}, /* Gr offset for white balance */
196 {0x0010, 0x8660}, /* Compensation memory stuff */ 196 {0x0003, 0x8613}, /* B offset for white balance */
197 {0x0018, 0x8660}, /* Compensation memory stuff */
198
199 {0x0004, 0x8611}, /* R offset for white balance */
200 {0x0004, 0x8612}, /* Gr offset for white balance */
201 {0x0007, 0x8613}, /* B offset for white balance */
202 {0x0000, 0x8614}, /* Gb offset for white balance */ 197 {0x0000, 0x8614}, /* Gb offset for white balance */
203/* from ms-win */ 198/* from ms-win */
204 {0x0035, 0x8651}, /* R gain for white balance */ 199 {0x0035, 0x8651}, /* R gain for white balance */
@@ -206,8 +201,8 @@ static const __u16 rev72a_init_data2[][2] = {
206 {0x005f, 0x8653}, /* B gain for white balance */ 201 {0x005f, 0x8653}, /* B gain for white balance */
207 {0x0040, 0x8654}, /* Gb gain for white balance */ 202 {0x0040, 0x8654}, /* Gb gain for white balance */
208 {0x0002, 0x8502}, /* Maximum average bit rate stuff */ 203 {0x0002, 0x8502}, /* Maximum average bit rate stuff */
209
210 {0x0011, 0x8802}, 204 {0x0011, 0x8802},
205
211 {0x0087, 0x8700}, /* Set master clock (96Mhz????) */ 206 {0x0087, 0x8700}, /* Set master clock (96Mhz????) */
212 {0x0081, 0x8702}, /* Master clock output enable */ 207 {0x0081, 0x8702}, /* Master clock output enable */
213 208
@@ -218,104 +213,15 @@ static const __u16 rev72a_init_data2[][2] = {
218 {0x0003, 0x865c}, /* Vertical offset for valid lines */ 213 {0x0003, 0x865c}, /* Vertical offset for valid lines */
219 {} 214 {}
220}; 215};
221static const __u16 rev72a_init_sensor2[][2] = { 216static const u16 rev72a_init_sensor2[][2] = {
222 /* ms-win values */ 217 {0x0003, 0x0121},
223 {0x0003, 0x0121}, /* 0x03 <- 0x01 0x21 //289 */ 218 {0x0004, 0x0165},
224 {0x0004, 0x0165}, /* 0x04 <- 0x01 0x65 //357 */ 219 {0x0005, 0x002f}, /* blanking control column */
225 {0x0005, 0x002f}, /* 0x05 <- 0x2f */ 220 {0x0006, 0x0000}, /* blanking mode row*/
226 {0x0006, 0x0000}, /* 0x06 <- 0 */ 221 {0x000a, 0x0002},
227 {0x000a, 0x0002}, /* 0x0a <- 2 */ 222 {0x0009, 0x1061}, /* setexposure times && pixel clock
228 {0x0009, 0x1061}, /* 0x09 <- 0x1061 */
229 {0x0035, 0x0014}, /* 0x35 <- 0x14 */
230 {}
231};
232static const __u16 rev72a_init_data3[][2] = {
233 {0x0030, 0x8112}, /* ISO and drop packet enable */
234/*fixme: should stop here*/
235 {0x0000, 0x8112}, /* Some kind of reset ???? */
236 {0x0009, 0x8118}, /* Enable sensor and set standby */
237 {0x0000, 0x8114}, /* Software GPIO output data */
238 {0x0000, 0x8114}, /* Software GPIO output data */
239 {0x0001, 0x8114}, /* Software GPIO output data */
240 {0x0000, 0x8112}, /* Some kind of reset ??? */
241 {0x0003, 0x8701},
242 {0x0001, 0x8703},
243 {0x0011, 0x8118},
244 {0x0001, 0x8118},
245 /***************/
246 {0x0092, 0x8804},
247 {0x0010, 0x8802},
248 {0x000d, 0x8805},
249 {0x0001, 0x8801},
250 {0x0000, 0x8800},
251 {0x0018, 0x8805},
252 {0x0002, 0x8801},
253 {0x0000, 0x8800},
254 {0x0065, 0x8805},
255 {0x0004, 0x8801},
256 {0x0001, 0x8800},
257 {0x0021, 0x8805},
258 {0x0005, 0x8801},
259 {0x0000, 0x8800},
260 {0x00aa, 0x8805},
261 {0x0007, 0x8801}, /* mode 0xaa */
262 {0x0000, 0x8800},
263 {0x0004, 0x8805},
264 {0x0020, 0x8801},
265 {0x0015, 0x8800}, /* mode 0x0415 */
266 {0x0002, 0x8805},
267 {0x0039, 0x8801},
268 {0x0000, 0x8800},
269 {0x0010, 0x8805},
270 {0x0035, 0x8801},
271 {0x0000, 0x8800},
272 {0x0049, 0x8805},
273 {0x0009, 0x8801},
274 {0x0010, 0x8800},
275 {0x000b, 0x8805},
276 {0x0028, 0x8801},
277 {0x0000, 0x8800},
278 {0x000f, 0x8805},
279 {0x003b, 0x8801},
280 {0x0000, 0x8800},
281 {0x0000, 0x8805},
282 {0x003c, 0x8801},
283 {0x0000, 0x8800},
284 {0x0002, 0x8502},
285 {0x0039, 0x8801},
286 {0x0000, 0x8805},
287 {0x0000, 0x8800},
288
289 {0x0087, 0x8700}, /* overwrite by start */
290 {0x0081, 0x8702},
291 {0x0000, 0x8500},
292/* {0x0010, 0x8500}, -- Previous line was this */
293 {0x0002, 0x865b},
294 {0x0003, 0x865c},
295 /***************/
296 {0x0003, 0x8801}, /* 0x121-> 289 */
297 {0x0021, 0x8805},
298 {0x0001, 0x8800},
299 {0x0004, 0x8801}, /* 0x165 -> 357 */
300 {0x0065, 0x8805},
301 {0x0001, 0x8800},
302 {0x0005, 0x8801}, /* 0x2f //blanking control colonne */
303 {0x002f, 0x8805},
304 {0x0000, 0x8800},
305 {0x0006, 0x8801}, /* 0x00 //blanking mode row */
306 {0x0000, 0x8805},
307 {0x0000, 0x8800},
308 {0x000a, 0x8801}, /* 0x01 //0x02 */
309 {0x0001, 0x8805},
310 {0x0000, 0x8800},
311 {0x0009, 0x8801}, /* 0x1061 - setexposure times && pixel clock
312 * 0001 0 | 000 0110 0001 */ 223 * 0001 0 | 000 0110 0001 */
313 {0x0061, 0x8805}, /* 61 31 */ 224 {0x0035, 0x0014},
314 {0x0008, 0x8800}, /* 08 */
315 {0x0035, 0x8801}, /* 0x14 - set gain general */
316 {0x001f, 0x8805}, /* 0x14 */
317 {0x0000, 0x8800},
318 {0x000e, 0x8112}, /* white balance - was 30 */
319 {} 225 {}
320}; 226};
321 227
@@ -460,6 +366,7 @@ static void i2c_write(struct gspca_dev *gspca_dev, __u16 value, __u16 reg)
460 reg_r(gspca_dev, 0x8803, 1); 366 reg_r(gspca_dev, 0x8803, 1);
461 if (!gspca_dev->usb_buf[0]) 367 if (!gspca_dev->usb_buf[0])
462 return; 368 return;
369 msleep(10);
463 } while (--retry); 370 } while (--retry);
464} 371}
465 372
@@ -479,6 +386,7 @@ static int i2c_read(struct gspca_dev *gspca_dev, __u16 reg, __u8 mode)
479 reg_r(gspca_dev, 0x8805, 1); 386 reg_r(gspca_dev, 0x8805, 1);
480 return ((int) value << 8) | gspca_dev->usb_buf[0]; 387 return ((int) value << 8) | gspca_dev->usb_buf[0];
481 } 388 }
389 msleep(10);
482 } while (--retry); 390 } while (--retry);
483 return -1; 391 return -1;
484} 392}
@@ -541,7 +449,6 @@ static int sd_config(struct gspca_dev *gspca_dev,
541 } 449 }
542 450
543 cam = &gspca_dev->cam; 451 cam = &gspca_dev->cam;
544 cam->epaddr = 0x01;
545 gspca_dev->nbalt = 7 + 1; /* choose alternate 7 first */ 452 gspca_dev->nbalt = 7 + 1; /* choose alternate 7 first */
546 453
547 sd->chip_revision = id->driver_info; 454 sd->chip_revision = id->driver_info;
@@ -572,11 +479,13 @@ static int sd_init_12a(struct gspca_dev *gspca_dev)
572static int sd_init_72a(struct gspca_dev *gspca_dev) 479static int sd_init_72a(struct gspca_dev *gspca_dev)
573{ 480{
574 PDEBUG(D_STREAM, "Chip revision: 072a"); 481 PDEBUG(D_STREAM, "Chip revision: 072a");
482 write_vector(gspca_dev, rev72a_reset);
483 msleep(200);
575 write_vector(gspca_dev, rev72a_init_data1); 484 write_vector(gspca_dev, rev72a_init_data1);
576 write_sensor_72a(gspca_dev, rev72a_init_sensor1); 485 write_sensor_72a(gspca_dev, rev72a_init_sensor1);
577 write_vector(gspca_dev, rev72a_init_data2); 486 write_vector(gspca_dev, rev72a_init_data2);
578 write_sensor_72a(gspca_dev, rev72a_init_sensor2); 487 write_sensor_72a(gspca_dev, rev72a_init_sensor2);
579 write_vector(gspca_dev, rev72a_init_data3); 488 reg_w_val(gspca_dev->dev, 0x8112, 0x30);
580 return 0; 489 return 0;
581} 490}
582 491
@@ -731,11 +640,18 @@ static int sd_start_72a(struct gspca_dev *gspca_dev)
731 int Clck; 640 int Clck;
732 int mode; 641 int mode;
733 642
643 write_vector(gspca_dev, rev72a_reset);
644 msleep(200);
645 write_vector(gspca_dev, rev72a_init_data1);
646 write_sensor_72a(gspca_dev, rev72a_init_sensor1);
647
734 mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv; 648 mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
735 switch (mode) { 649 switch (mode) {
736 default: 650 default:
737/* case 0: 651 case 0:
738 case 1: */ 652 Clck = 0x27; /* ms-win 0x87 */
653 break;
654 case 1:
739 Clck = 0x25; 655 Clck = 0x25;
740 break; 656 break;
741 case 2: 657 case 2:
@@ -745,13 +661,14 @@ static int sd_start_72a(struct gspca_dev *gspca_dev)
745 Clck = 0x21; 661 Clck = 0x21;
746 break; 662 break;
747 } 663 }
748 reg_w_val(dev, 0x8500, mode); /* mode */
749 reg_w_val(dev, 0x8700, Clck); /* 0x27 clock */ 664 reg_w_val(dev, 0x8700, Clck); /* 0x27 clock */
750 reg_w_val(dev, 0x8112, 0x10 | 0x20); 665 reg_w_val(dev, 0x8702, 0x81);
666 reg_w_val(dev, 0x8500, mode); /* mode */
667 write_sensor_72a(gspca_dev, rev72a_init_sensor2);
751 setcontrast(gspca_dev); 668 setcontrast(gspca_dev);
752/* setbrightness(gspca_dev); * fixme: bad values */ 669/* setbrightness(gspca_dev); * fixme: bad values */
753 setwhite(gspca_dev);
754 setautogain(gspca_dev); 670 setautogain(gspca_dev);
671 reg_w_val(dev, 0x8112, 0x10 | 0x20);
755 return 0; 672 return 0;
756} 673}
757 674
@@ -867,12 +784,11 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
867{ 784{
868 struct sd *sd = (struct sd *) gspca_dev; 785 struct sd *sd = (struct sd *) gspca_dev;
869 786
870 switch (data[0]) { /* sequence number */ 787 len--;
788 switch (*data++) { /* sequence number */
871 case 0: /* start of frame */ 789 case 0: /* start of frame */
872 frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame, 790 frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame,
873 data, 0); 791 data, 0);
874 data += SPCA561_OFFSET_DATA;
875 len -= SPCA561_OFFSET_DATA;
876 if (data[1] & 0x10) { 792 if (data[1] & 0x10) {
877 /* compressed bayer */ 793 /* compressed bayer */
878 gspca_frame_add(gspca_dev, FIRST_PACKET, 794 gspca_frame_add(gspca_dev, FIRST_PACKET,
@@ -893,8 +809,6 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
893 case 0xff: /* drop (empty mpackets) */ 809 case 0xff: /* drop (empty mpackets) */
894 return; 810 return;
895 } 811 }
896 data++;
897 len--;
898 gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len); 812 gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
899} 813}
900 814
@@ -1197,8 +1111,10 @@ static struct usb_driver sd_driver = {
1197/* -- module insert / remove -- */ 1111/* -- module insert / remove -- */
1198static int __init sd_mod_init(void) 1112static int __init sd_mod_init(void)
1199{ 1113{
1200 if (usb_register(&sd_driver) < 0) 1114 int ret;
1201 return -1; 1115 ret = usb_register(&sd_driver);
1116 if (ret < 0)
1117 return ret;
1202 PDEBUG(D_PROBE, "registered"); 1118 PDEBUG(D_PROBE, "registered");
1203 return 0; 1119 return 0;
1204} 1120}
diff --git a/drivers/media/video/gspca/sq905.c b/drivers/media/video/gspca/sq905.c
new file mode 100644
index 000000000000..04e3ae57a2e3
--- /dev/null
+++ b/drivers/media/video/gspca/sq905.c
@@ -0,0 +1,456 @@
1/*
2 * SQ905 subdriver
3 *
4 * Copyright (C) 2008, 2009 Adam Baker and Theodore Kilgore
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 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21/*
22 * History and Acknowledgments
23 *
24 * The original Linux driver for SQ905 based cameras was written by
25 * Marcell Lengyel and furter developed by many other contributers
26 * and is available from http://sourceforge.net/projects/sqcam/
27 *
28 * This driver takes advantage of the reverse engineering work done for
29 * that driver and for libgphoto2 but shares no code with them.
30 *
31 * This driver has used as a base the finepix driver and other gspca
32 * based drivers and may still contain code fragments taken from those
33 * drivers.
34 */
35
36#define MODULE_NAME "sq905"
37
38#include <linux/workqueue.h>
39#include "gspca.h"
40
41MODULE_AUTHOR("Adam Baker <linux@baker-net.org.uk>, "
42 "Theodore Kilgore <kilgota@auburn.edu>");
43MODULE_DESCRIPTION("GSPCA/SQ905 USB Camera Driver");
44MODULE_LICENSE("GPL");
45
46/* Default timeouts, in ms */
47#define SQ905_CMD_TIMEOUT 500
48#define SQ905_DATA_TIMEOUT 1000
49
50/* Maximum transfer size to use. */
51#define SQ905_MAX_TRANSFER 0x8000
52#define FRAME_HEADER_LEN 64
53
54/* The known modes, or registers. These go in the "value" slot. */
55
56/* 00 is "none" obviously */
57
58#define SQ905_BULK_READ 0x03 /* precedes any bulk read */
59#define SQ905_COMMAND 0x06 /* precedes the command codes below */
60#define SQ905_PING 0x07 /* when reading an "idling" command */
61#define SQ905_READ_DONE 0xc0 /* ack bulk read completed */
62
63/* Any non-zero value in the bottom 2 bits of the 2nd byte of
64 * the ID appears to indicate the camera can do 640*480. If the
65 * LSB of that byte is set the image is just upside down, otherwise
66 * it is rotated 180 degrees. */
67#define SQ905_HIRES_MASK 0x00000300
68#define SQ905_ORIENTATION_MASK 0x00000100
69
70/* Some command codes. These go in the "index" slot. */
71
72#define SQ905_ID 0xf0 /* asks for model string */
73#define SQ905_CONFIG 0x20 /* gets photo alloc. table, not used here */
74#define SQ905_DATA 0x30 /* accesses photo data, not used here */
75#define SQ905_CLEAR 0xa0 /* clear everything */
76#define SQ905_CAPTURE_LOW 0x60 /* Starts capture at 160x120 */
77#define SQ905_CAPTURE_MED 0x61 /* Starts capture at 320x240 */
78#define SQ905_CAPTURE_HIGH 0x62 /* Starts capture at 640x480 (some cams only) */
79/* note that the capture command also controls the output dimensions */
80
81/* Structure to hold all of our device specific stuff */
82struct sd {
83 struct gspca_dev gspca_dev; /* !! must be the first item */
84
85 /*
86 * Driver stuff
87 */
88 struct work_struct work_struct;
89 struct workqueue_struct *work_thread;
90};
91
92static struct v4l2_pix_format sq905_mode[] = {
93 { 160, 120, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
94 .bytesperline = 160,
95 .sizeimage = 160 * 120,
96 .colorspace = V4L2_COLORSPACE_SRGB,
97 .priv = 0},
98 { 320, 240, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
99 .bytesperline = 320,
100 .sizeimage = 320 * 240,
101 .colorspace = V4L2_COLORSPACE_SRGB,
102 .priv = 0},
103 { 640, 480, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
104 .bytesperline = 640,
105 .sizeimage = 640 * 480,
106 .colorspace = V4L2_COLORSPACE_SRGB,
107 .priv = 0}
108};
109
110/*
111 * Send a command to the camera.
112 */
113static int sq905_command(struct gspca_dev *gspca_dev, u16 index)
114{
115 int ret;
116
117 gspca_dev->usb_buf[0] = '\0';
118 ret = usb_control_msg(gspca_dev->dev,
119 usb_sndctrlpipe(gspca_dev->dev, 0),
120 USB_REQ_SYNCH_FRAME, /* request */
121 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
122 SQ905_COMMAND, index, gspca_dev->usb_buf, 1,
123 SQ905_CMD_TIMEOUT);
124 if (ret < 0) {
125 PDEBUG(D_ERR, "%s: usb_control_msg failed (%d)",
126 __func__, ret);
127 return ret;
128 }
129
130 ret = usb_control_msg(gspca_dev->dev,
131 usb_sndctrlpipe(gspca_dev->dev, 0),
132 USB_REQ_SYNCH_FRAME, /* request */
133 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
134 SQ905_PING, 0, gspca_dev->usb_buf, 1,
135 SQ905_CMD_TIMEOUT);
136 if (ret < 0) {
137 PDEBUG(D_ERR, "%s: usb_control_msg failed 2 (%d)",
138 __func__, ret);
139 return ret;
140 }
141
142 return 0;
143}
144
145/*
146 * Acknowledge the end of a frame - see warning on sq905_command.
147 */
148static int sq905_ack_frame(struct gspca_dev *gspca_dev)
149{
150 int ret;
151
152 gspca_dev->usb_buf[0] = '\0';
153 ret = usb_control_msg(gspca_dev->dev,
154 usb_sndctrlpipe(gspca_dev->dev, 0),
155 USB_REQ_SYNCH_FRAME, /* request */
156 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
157 SQ905_READ_DONE, 0, gspca_dev->usb_buf, 1,
158 SQ905_CMD_TIMEOUT);
159 if (ret < 0) {
160 PDEBUG(D_ERR, "%s: usb_control_msg failed (%d)", __func__, ret);
161 return ret;
162 }
163
164 return 0;
165}
166
167/*
168 * request and read a block of data - see warning on sq905_command.
169 */
170static int
171sq905_read_data(struct gspca_dev *gspca_dev, u8 *data, int size)
172{
173 int ret;
174 int act_len;
175
176 gspca_dev->usb_buf[0] = '\0';
177 ret = usb_control_msg(gspca_dev->dev,
178 usb_sndctrlpipe(gspca_dev->dev, 0),
179 USB_REQ_SYNCH_FRAME, /* request */
180 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
181 SQ905_BULK_READ, size, gspca_dev->usb_buf,
182 1, SQ905_CMD_TIMEOUT);
183 if (ret < 0) {
184 PDEBUG(D_ERR, "%s: usb_control_msg failed (%d)", __func__, ret);
185 return ret;
186 }
187 ret = usb_bulk_msg(gspca_dev->dev,
188 usb_rcvbulkpipe(gspca_dev->dev, 0x81),
189 data, size, &act_len, SQ905_DATA_TIMEOUT);
190
191 /* successful, it returns 0, otherwise negative */
192 if (ret < 0 || act_len != size) {
193 PDEBUG(D_ERR, "bulk read fail (%d) len %d/%d",
194 ret, act_len, size);
195 return -EIO;
196 }
197 return 0;
198}
199
200/* This function is called as a workqueue function and runs whenever the camera
201 * is streaming data. Because it is a workqueue function it is allowed to sleep
202 * so we can use synchronous USB calls. To avoid possible collisions with other
203 * threads attempting to use the camera's USB interface we take the gspca
204 * usb_lock when performing USB operations. In practice the only thing we need
205 * to protect against is the usb_set_interface call that gspca makes during
206 * stream_off as the camera doesn't provide any controls that the user could try
207 * to change.
208 */
209static void sq905_dostream(struct work_struct *work)
210{
211 struct sd *dev = container_of(work, struct sd, work_struct);
212 struct gspca_dev *gspca_dev = &dev->gspca_dev;
213 struct gspca_frame *frame;
214 int bytes_left; /* bytes remaining in current frame. */
215 int data_len; /* size to use for the next read. */
216 int header_read; /* true if we have already read the frame header. */
217 int discarding; /* true if we failed to get space for frame. */
218 int packet_type;
219 int frame_sz;
220 int ret;
221 u8 *data;
222 u8 *buffer;
223
224 buffer = kmalloc(SQ905_MAX_TRANSFER, GFP_KERNEL | GFP_DMA);
225 mutex_lock(&gspca_dev->usb_lock);
226 if (!buffer) {
227 PDEBUG(D_ERR, "Couldn't allocate USB buffer");
228 goto quit_stream;
229 }
230
231 frame_sz = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].sizeimage
232 + FRAME_HEADER_LEN;
233
234 while (gspca_dev->present && gspca_dev->streaming) {
235 /* Need a short delay to ensure streaming flag was set by
236 * gspca and to make sure gspca can grab the mutex. */
237 mutex_unlock(&gspca_dev->usb_lock);
238 msleep(1);
239
240 /* request some data and then read it until we have
241 * a complete frame. */
242 bytes_left = frame_sz;
243 header_read = 0;
244 discarding = 0;
245
246 while (bytes_left > 0) {
247 data_len = bytes_left > SQ905_MAX_TRANSFER ?
248 SQ905_MAX_TRANSFER : bytes_left;
249 mutex_lock(&gspca_dev->usb_lock);
250 if (!gspca_dev->present)
251 goto quit_stream;
252 ret = sq905_read_data(gspca_dev, buffer, data_len);
253 if (ret < 0)
254 goto quit_stream;
255 mutex_unlock(&gspca_dev->usb_lock);
256 PDEBUG(D_STREAM,
257 "Got %d bytes out of %d for frame",
258 data_len, bytes_left);
259 bytes_left -= data_len;
260 data = buffer;
261 if (!header_read) {
262 packet_type = FIRST_PACKET;
263 /* The first 64 bytes of each frame are
264 * a header full of FF 00 bytes */
265 data += FRAME_HEADER_LEN;
266 data_len -= FRAME_HEADER_LEN;
267 header_read = 1;
268 } else if (bytes_left == 0) {
269 packet_type = LAST_PACKET;
270 } else {
271 packet_type = INTER_PACKET;
272 }
273 frame = gspca_get_i_frame(gspca_dev);
274 if (frame && !discarding) {
275 frame = gspca_frame_add(gspca_dev, packet_type,
276 frame, data, data_len);
277 /* If entire frame fits in one packet we still
278 need to add a LAST_PACKET */
279 if (packet_type == FIRST_PACKET &&
280 bytes_left == 0)
281 frame = gspca_frame_add(gspca_dev,
282 LAST_PACKET,
283 frame, data, 0);
284 } else {
285 discarding = 1;
286 }
287 }
288 /* acknowledge the frame */
289 mutex_lock(&gspca_dev->usb_lock);
290 if (!gspca_dev->present)
291 goto quit_stream;
292 ret = sq905_ack_frame(gspca_dev);
293 if (ret < 0)
294 goto quit_stream;
295 }
296quit_stream:
297 /* the usb_lock is already acquired */
298 if (gspca_dev->present)
299 sq905_command(gspca_dev, SQ905_CLEAR);
300 mutex_unlock(&gspca_dev->usb_lock);
301 kfree(buffer);
302}
303
304/* This function is called at probe time just before sd_init */
305static int sd_config(struct gspca_dev *gspca_dev,
306 const struct usb_device_id *id)
307{
308 struct cam *cam = &gspca_dev->cam;
309 struct sd *dev = (struct sd *) gspca_dev;
310
311 /* We don't use the buffer gspca allocates so make it small. */
312 cam->bulk_size = 64;
313
314 INIT_WORK(&dev->work_struct, sq905_dostream);
315
316 return 0;
317}
318
319/* called on streamoff with alt==0 and on disconnect */
320/* the usb_lock is held at entry - restore on exit */
321static void sd_stop0(struct gspca_dev *gspca_dev)
322{
323 struct sd *dev = (struct sd *) gspca_dev;
324
325 /* wait for the work queue to terminate */
326 mutex_unlock(&gspca_dev->usb_lock);
327 /* This waits for sq905_dostream to finish */
328 destroy_workqueue(dev->work_thread);
329 dev->work_thread = NULL;
330 mutex_lock(&gspca_dev->usb_lock);
331}
332
333/* this function is called at probe and resume time */
334static int sd_init(struct gspca_dev *gspca_dev)
335{
336 u32 ident;
337 int ret;
338
339 /* connect to the camera and read
340 * the model ID and process that and put it away.
341 */
342 ret = sq905_command(gspca_dev, SQ905_CLEAR);
343 if (ret < 0)
344 return ret;
345 ret = sq905_command(gspca_dev, SQ905_ID);
346 if (ret < 0)
347 return ret;
348 ret = sq905_read_data(gspca_dev, gspca_dev->usb_buf, 4);
349 if (ret < 0)
350 return ret;
351 /* usb_buf is allocated with kmalloc so is aligned.
352 * Camera model number is the right way round if we assume this
353 * reverse engineered ID is supposed to be big endian. */
354 ident = be32_to_cpup((__be32 *)gspca_dev->usb_buf);
355 ret = sq905_command(gspca_dev, SQ905_CLEAR);
356 if (ret < 0)
357 return ret;
358 PDEBUG(D_CONF, "SQ905 camera ID %08x detected", ident);
359 gspca_dev->cam.cam_mode = sq905_mode;
360 gspca_dev->cam.nmodes = ARRAY_SIZE(sq905_mode);
361 if (!(ident & SQ905_HIRES_MASK))
362 gspca_dev->cam.nmodes--;
363 return 0;
364}
365
366/* Set up for getting frames. */
367static int sd_start(struct gspca_dev *gspca_dev)
368{
369 struct sd *dev = (struct sd *) gspca_dev;
370 int ret;
371
372 /* "Open the shutter" and set size, to start capture */
373 switch (gspca_dev->curr_mode) {
374 default:
375/* case 2: */
376 PDEBUG(D_STREAM, "Start streaming at high resolution");
377 ret = sq905_command(&dev->gspca_dev, SQ905_CAPTURE_HIGH);
378 break;
379 case 1:
380 PDEBUG(D_STREAM, "Start streaming at medium resolution");
381 ret = sq905_command(&dev->gspca_dev, SQ905_CAPTURE_MED);
382 break;
383 case 0:
384 PDEBUG(D_STREAM, "Start streaming at low resolution");
385 ret = sq905_command(&dev->gspca_dev, SQ905_CAPTURE_LOW);
386 }
387
388 if (ret < 0) {
389 PDEBUG(D_ERR, "Start streaming command failed");
390 return ret;
391 }
392 /* Start the workqueue function to do the streaming */
393 dev->work_thread = create_singlethread_workqueue(MODULE_NAME);
394 queue_work(dev->work_thread, &dev->work_struct);
395
396 return 0;
397}
398
399/* Table of supported USB devices */
400static const __devinitdata struct usb_device_id device_table[] = {
401 {USB_DEVICE(0x2770, 0x9120)},
402 {}
403};
404
405MODULE_DEVICE_TABLE(usb, device_table);
406
407/* sub-driver description */
408static const struct sd_desc sd_desc = {
409 .name = MODULE_NAME,
410 .config = sd_config,
411 .init = sd_init,
412 .start = sd_start,
413 .stop0 = sd_stop0,
414};
415
416/* -- device connect -- */
417static int sd_probe(struct usb_interface *intf,
418 const struct usb_device_id *id)
419{
420 return gspca_dev_probe(intf, id,
421 &sd_desc,
422 sizeof(struct sd),
423 THIS_MODULE);
424}
425
426static struct usb_driver sd_driver = {
427 .name = MODULE_NAME,
428 .id_table = device_table,
429 .probe = sd_probe,
430 .disconnect = gspca_disconnect,
431#ifdef CONFIG_PM
432 .suspend = gspca_suspend,
433 .resume = gspca_resume,
434#endif
435};
436
437/* -- module insert / remove -- */
438static int __init sd_mod_init(void)
439{
440 int ret;
441
442 ret = usb_register(&sd_driver);
443 if (ret < 0)
444 return ret;
445 PDEBUG(D_PROBE, "registered");
446 return 0;
447}
448
449static void __exit sd_mod_exit(void)
450{
451 usb_deregister(&sd_driver);
452 PDEBUG(D_PROBE, "deregistered");
453}
454
455module_init(sd_mod_init);
456module_exit(sd_mod_exit);
diff --git a/drivers/media/video/gspca/sq905c.c b/drivers/media/video/gspca/sq905c.c
new file mode 100644
index 000000000000..0bcb74a1b143
--- /dev/null
+++ b/drivers/media/video/gspca/sq905c.c
@@ -0,0 +1,328 @@
1/*
2 * SQ905C subdriver
3 *
4 * Copyright (C) 2009 Theodore Kilgore
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 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21/*
22 *
23 * This driver uses work done in
24 * libgphoto2/camlibs/digigr8, Copyright (C) Theodore Kilgore.
25 *
26 * This driver has also used as a base the sq905c driver
27 * and may contain code fragments from it.
28 */
29
30#define MODULE_NAME "sq905c"
31
32#include <linux/workqueue.h>
33#include "gspca.h"
34
35MODULE_AUTHOR("Theodore Kilgore <kilgota@auburn.edu>");
36MODULE_DESCRIPTION("GSPCA/SQ905C USB Camera Driver");
37MODULE_LICENSE("GPL");
38
39/* Default timeouts, in ms */
40#define SQ905C_CMD_TIMEOUT 500
41#define SQ905C_DATA_TIMEOUT 1000
42
43/* Maximum transfer size to use. */
44#define SQ905C_MAX_TRANSFER 0x8000
45
46#define FRAME_HEADER_LEN 0x50
47
48/* Commands. These go in the "value" slot. */
49#define SQ905C_CLEAR 0xa0 /* clear everything */
50#define SQ905C_CAPTURE_LOW 0xa040 /* Starts capture at 160x120 */
51#define SQ905C_CAPTURE_MED 0x1440 /* Starts capture at 320x240 */
52#define SQ905C_CAPTURE_HI 0x2840 /* Starts capture at 320x240 */
53
54/* For capture, this must go in the "index" slot. */
55#define SQ905C_CAPTURE_INDEX 0x110f
56
57/* Structure to hold all of our device specific stuff */
58struct sd {
59 struct gspca_dev gspca_dev; /* !! must be the first item */
60 const struct v4l2_pix_format *cap_mode;
61 /* Driver stuff */
62 struct work_struct work_struct;
63 struct workqueue_struct *work_thread;
64};
65
66/*
67 * Most of these cameras will do 640x480 and 320x240. 160x120 works
68 * in theory but gives very poor output. Therefore, not supported.
69 * The 0x2770:0x9050 cameras have max resolution of 320x240.
70 */
71static struct v4l2_pix_format sq905c_mode[] = {
72 { 320, 240, V4L2_PIX_FMT_SQ905C, V4L2_FIELD_NONE,
73 .bytesperline = 320,
74 .sizeimage = 320 * 240,
75 .colorspace = V4L2_COLORSPACE_SRGB,
76 .priv = 0},
77 { 640, 480, V4L2_PIX_FMT_SQ905C, V4L2_FIELD_NONE,
78 .bytesperline = 640,
79 .sizeimage = 640 * 480,
80 .colorspace = V4L2_COLORSPACE_SRGB,
81 .priv = 0}
82};
83
84/* Send a command to the camera. */
85static int sq905c_command(struct gspca_dev *gspca_dev, u16 command, u16 index)
86{
87 int ret;
88
89 ret = usb_control_msg(gspca_dev->dev,
90 usb_sndctrlpipe(gspca_dev->dev, 0),
91 USB_REQ_SYNCH_FRAME, /* request */
92 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
93 command, index, NULL, 0,
94 SQ905C_CMD_TIMEOUT);
95 if (ret < 0) {
96 PDEBUG(D_ERR, "%s: usb_control_msg failed (%d)",
97 __func__, ret);
98 return ret;
99 }
100
101 return 0;
102}
103
104/* This function is called as a workqueue function and runs whenever the camera
105 * is streaming data. Because it is a workqueue function it is allowed to sleep
106 * so we can use synchronous USB calls. To avoid possible collisions with other
107 * threads attempting to use the camera's USB interface the gspca usb_lock is
108 * used when performing the one USB control operation inside the workqueue,
109 * which tells the camera to close the stream. In practice the only thing
110 * which needs to be protected against is the usb_set_interface call that
111 * gspca makes during stream_off. Otherwise the camera doesn't provide any
112 * controls that the user could try to change.
113 */
114static void sq905c_dostream(struct work_struct *work)
115{
116 struct sd *dev = container_of(work, struct sd, work_struct);
117 struct gspca_dev *gspca_dev = &dev->gspca_dev;
118 struct gspca_frame *frame;
119 int bytes_left; /* bytes remaining in current frame. */
120 int data_len; /* size to use for the next read. */
121 int act_len;
122 int discarding = 0; /* true if we failed to get space for frame. */
123 int packet_type;
124 int ret;
125 u8 *buffer;
126
127 buffer = kmalloc(SQ905C_MAX_TRANSFER, GFP_KERNEL | GFP_DMA);
128 if (!buffer) {
129 PDEBUG(D_ERR, "Couldn't allocate USB buffer");
130 goto quit_stream;
131 }
132
133 while (gspca_dev->present && gspca_dev->streaming) {
134 if (!gspca_dev->present)
135 goto quit_stream;
136 /* Request the header, which tells the size to download */
137 ret = usb_bulk_msg(gspca_dev->dev,
138 usb_rcvbulkpipe(gspca_dev->dev, 0x81),
139 buffer, FRAME_HEADER_LEN, &act_len,
140 SQ905C_DATA_TIMEOUT);
141 PDEBUG(D_STREAM,
142 "Got %d bytes out of %d for header",
143 act_len, FRAME_HEADER_LEN);
144 if (ret < 0 || act_len < FRAME_HEADER_LEN)
145 goto quit_stream;
146 /* size is read from 4 bytes starting 0x40, little endian */
147 bytes_left = buffer[0x40]|(buffer[0x41]<<8)|(buffer[0x42]<<16)
148 |(buffer[0x43]<<24);
149 PDEBUG(D_STREAM, "bytes_left = 0x%x", bytes_left);
150 /* We keep the header. It has other information, too. */
151 packet_type = FIRST_PACKET;
152 frame = gspca_get_i_frame(gspca_dev);
153 if (frame && !discarding) {
154 gspca_frame_add(gspca_dev, packet_type,
155 frame, buffer, FRAME_HEADER_LEN);
156 } else
157 discarding = 1;
158 while (bytes_left > 0) {
159 data_len = bytes_left > SQ905C_MAX_TRANSFER ?
160 SQ905C_MAX_TRANSFER : bytes_left;
161 if (!gspca_dev->present)
162 goto quit_stream;
163 ret = usb_bulk_msg(gspca_dev->dev,
164 usb_rcvbulkpipe(gspca_dev->dev, 0x81),
165 buffer, data_len, &act_len,
166 SQ905C_DATA_TIMEOUT);
167 if (ret < 0 || act_len < data_len)
168 goto quit_stream;
169 PDEBUG(D_STREAM,
170 "Got %d bytes out of %d for frame",
171 data_len, bytes_left);
172 bytes_left -= data_len;
173 if (bytes_left == 0)
174 packet_type = LAST_PACKET;
175 else
176 packet_type = INTER_PACKET;
177 frame = gspca_get_i_frame(gspca_dev);
178 if (frame && !discarding)
179 gspca_frame_add(gspca_dev, packet_type,
180 frame, buffer, data_len);
181 else
182 discarding = 1;
183 }
184 }
185quit_stream:
186 mutex_lock(&gspca_dev->usb_lock);
187 if (gspca_dev->present)
188 sq905c_command(gspca_dev, SQ905C_CLEAR, 0);
189 mutex_unlock(&gspca_dev->usb_lock);
190 kfree(buffer);
191}
192
193/* This function is called at probe time just before sd_init */
194static int sd_config(struct gspca_dev *gspca_dev,
195 const struct usb_device_id *id)
196{
197 struct cam *cam = &gspca_dev->cam;
198 struct sd *dev = (struct sd *) gspca_dev;
199
200 PDEBUG(D_PROBE,
201 "SQ9050 camera detected"
202 " (vid/pid 0x%04X:0x%04X)", id->idVendor, id->idProduct);
203 cam->cam_mode = sq905c_mode;
204 cam->nmodes = 2;
205 if (id->idProduct == 0x9050)
206 cam->nmodes = 1;
207 /* We don't use the buffer gspca allocates so make it small. */
208 cam->bulk_size = 32;
209 INIT_WORK(&dev->work_struct, sq905c_dostream);
210 return 0;
211}
212
213/* called on streamoff with alt==0 and on disconnect */
214/* the usb_lock is held at entry - restore on exit */
215static void sd_stop0(struct gspca_dev *gspca_dev)
216{
217 struct sd *dev = (struct sd *) gspca_dev;
218
219 /* wait for the work queue to terminate */
220 mutex_unlock(&gspca_dev->usb_lock);
221 /* This waits for sq905c_dostream to finish */
222 destroy_workqueue(dev->work_thread);
223 dev->work_thread = NULL;
224 mutex_lock(&gspca_dev->usb_lock);
225}
226
227/* this function is called at probe and resume time */
228static int sd_init(struct gspca_dev *gspca_dev)
229{
230 int ret;
231
232 /* connect to the camera and reset it. */
233 ret = sq905c_command(gspca_dev, SQ905C_CLEAR, 0);
234 return ret;
235}
236
237/* Set up for getting frames. */
238static int sd_start(struct gspca_dev *gspca_dev)
239{
240 struct sd *dev = (struct sd *) gspca_dev;
241 int ret;
242
243 dev->cap_mode = gspca_dev->cam.cam_mode;
244 /* "Open the shutter" and set size, to start capture */
245 switch (gspca_dev->width) {
246 case 640:
247 PDEBUG(D_STREAM, "Start streaming at high resolution");
248 dev->cap_mode++;
249 ret = sq905c_command(gspca_dev, SQ905C_CAPTURE_HI,
250 SQ905C_CAPTURE_INDEX);
251 break;
252 default: /* 320 */
253 PDEBUG(D_STREAM, "Start streaming at medium resolution");
254 ret = sq905c_command(gspca_dev, SQ905C_CAPTURE_MED,
255 SQ905C_CAPTURE_INDEX);
256 }
257
258 if (ret < 0) {
259 PDEBUG(D_ERR, "Start streaming command failed");
260 return ret;
261 }
262 /* Start the workqueue function to do the streaming */
263 dev->work_thread = create_singlethread_workqueue(MODULE_NAME);
264 queue_work(dev->work_thread, &dev->work_struct);
265
266 return 0;
267}
268
269/* Table of supported USB devices */
270static const __devinitdata struct usb_device_id device_table[] = {
271 {USB_DEVICE(0x2770, 0x905c)},
272 {USB_DEVICE(0x2770, 0x9050)},
273 {USB_DEVICE(0x2770, 0x913d)},
274 {}
275};
276
277MODULE_DEVICE_TABLE(usb, device_table);
278
279/* sub-driver description */
280static const struct sd_desc sd_desc = {
281 .name = MODULE_NAME,
282 .config = sd_config,
283 .init = sd_init,
284 .start = sd_start,
285 .stop0 = sd_stop0,
286};
287
288/* -- device connect -- */
289static int sd_probe(struct usb_interface *intf,
290 const struct usb_device_id *id)
291{
292 return gspca_dev_probe(intf, id,
293 &sd_desc,
294 sizeof(struct sd),
295 THIS_MODULE);
296}
297
298static struct usb_driver sd_driver = {
299 .name = MODULE_NAME,
300 .id_table = device_table,
301 .probe = sd_probe,
302 .disconnect = gspca_disconnect,
303#ifdef CONFIG_PM
304 .suspend = gspca_suspend,
305 .resume = gspca_resume,
306#endif
307};
308
309/* -- module insert / remove -- */
310static int __init sd_mod_init(void)
311{
312 int ret;
313
314 ret = usb_register(&sd_driver);
315 if (ret < 0)
316 return ret;
317 PDEBUG(D_PROBE, "registered");
318 return 0;
319}
320
321static void __exit sd_mod_exit(void)
322{
323 usb_deregister(&sd_driver);
324 PDEBUG(D_PROBE, "deregistered");
325}
326
327module_init(sd_mod_init);
328module_exit(sd_mod_exit);
diff --git a/drivers/media/video/gspca/stk014.c b/drivers/media/video/gspca/stk014.c
index 60de9af87fbb..f25be20cf1a6 100644
--- a/drivers/media/video/gspca/stk014.c
+++ b/drivers/media/video/gspca/stk014.c
@@ -35,10 +35,13 @@ struct sd {
35 unsigned char contrast; 35 unsigned char contrast;
36 unsigned char colors; 36 unsigned char colors;
37 unsigned char lightfreq; 37 unsigned char lightfreq;
38}; 38 u8 quality;
39#define QUALITY_MIN 60
40#define QUALITY_MAX 95
41#define QUALITY_DEF 80
39 42
40/* global parameters */ 43 u8 *jpeg_hdr;
41static int sd_quant = 7; /* <= 4 KO - 7: good (enough!) */ 44};
42 45
43/* V4L2 controls supported by the driver */ 46/* V4L2 controls supported by the driver */
44static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val); 47static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
@@ -180,7 +183,7 @@ static int rcv_val(struct gspca_dev *gspca_dev,
180 reg_w(gspca_dev, 0x63b, 0); 183 reg_w(gspca_dev, 0x63b, 0);
181 reg_w(gspca_dev, 0x630, 5); 184 reg_w(gspca_dev, 0x630, 5);
182 ret = usb_bulk_msg(dev, 185 ret = usb_bulk_msg(dev,
183 usb_rcvbulkpipe(dev, 5), 186 usb_rcvbulkpipe(dev, 0x05),
184 gspca_dev->usb_buf, 187 gspca_dev->usb_buf,
185 4, /* length */ 188 4, /* length */
186 &alen, 189 &alen,
@@ -294,15 +297,14 @@ static int sd_config(struct gspca_dev *gspca_dev,
294 const struct usb_device_id *id) 297 const struct usb_device_id *id)
295{ 298{
296 struct sd *sd = (struct sd *) gspca_dev; 299 struct sd *sd = (struct sd *) gspca_dev;
297 struct cam *cam = &gspca_dev->cam;
298 300
299 cam->epaddr = 0x02;
300 gspca_dev->cam.cam_mode = vga_mode; 301 gspca_dev->cam.cam_mode = vga_mode;
301 gspca_dev->cam.nmodes = ARRAY_SIZE(vga_mode); 302 gspca_dev->cam.nmodes = ARRAY_SIZE(vga_mode);
302 sd->brightness = BRIGHTNESS_DEF; 303 sd->brightness = BRIGHTNESS_DEF;
303 sd->contrast = CONTRAST_DEF; 304 sd->contrast = CONTRAST_DEF;
304 sd->colors = COLOR_DEF; 305 sd->colors = COLOR_DEF;
305 sd->lightfreq = FREQ_DEF; 306 sd->lightfreq = FREQ_DEF;
307 sd->quality = QUALITY_DEF;
306 return 0; 308 return 0;
307} 309}
308 310
@@ -326,8 +328,15 @@ static int sd_init(struct gspca_dev *gspca_dev)
326/* -- start the camera -- */ 328/* -- start the camera -- */
327static int sd_start(struct gspca_dev *gspca_dev) 329static int sd_start(struct gspca_dev *gspca_dev)
328{ 330{
331 struct sd *sd = (struct sd *) gspca_dev;
329 int ret, value; 332 int ret, value;
330 333
334 /* create the JPEG header */
335 sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL);
336 jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
337 0x22); /* JPEG 411 */
338 jpeg_set_qual(sd->jpeg_hdr, sd->quality);
339
331 /* work on alternate 1 */ 340 /* work on alternate 1 */
332 usb_set_interface(gspca_dev->dev, gspca_dev->iface, 1); 341 usb_set_interface(gspca_dev->dev, gspca_dev->iface, 1);
333 342
@@ -399,11 +408,19 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
399 PDEBUG(D_STREAM, "camera stopped"); 408 PDEBUG(D_STREAM, "camera stopped");
400} 409}
401 410
411static void sd_stop0(struct gspca_dev *gspca_dev)
412{
413 struct sd *sd = (struct sd *) gspca_dev;
414
415 kfree(sd->jpeg_hdr);
416}
417
402static void sd_pkt_scan(struct gspca_dev *gspca_dev, 418static void sd_pkt_scan(struct gspca_dev *gspca_dev,
403 struct gspca_frame *frame, /* target */ 419 struct gspca_frame *frame, /* target */
404 __u8 *data, /* isoc packet */ 420 __u8 *data, /* isoc packet */
405 int len) /* iso packet length */ 421 int len) /* iso packet length */
406{ 422{
423 struct sd *sd = (struct sd *) gspca_dev;
407 static unsigned char ffd9[] = {0xff, 0xd9}; 424 static unsigned char ffd9[] = {0xff, 0xd9};
408 425
409 /* a frame starts with: 426 /* a frame starts with:
@@ -420,7 +437,8 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
420 ffd9, 2); 437 ffd9, 2);
421 438
422 /* put the JPEG 411 header */ 439 /* put the JPEG 411 header */
423 jpeg_put_header(gspca_dev, frame, sd_quant, 0x22); 440 gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
441 sd->jpeg_hdr, JPEG_HDR_SZ);
424 442
425 /* beginning of the frame */ 443 /* beginning of the frame */
426#define STKHDRSZ 12 444#define STKHDRSZ 12
@@ -520,6 +538,34 @@ static int sd_querymenu(struct gspca_dev *gspca_dev,
520 return -EINVAL; 538 return -EINVAL;
521} 539}
522 540
541static int sd_set_jcomp(struct gspca_dev *gspca_dev,
542 struct v4l2_jpegcompression *jcomp)
543{
544 struct sd *sd = (struct sd *) gspca_dev;
545
546 if (jcomp->quality < QUALITY_MIN)
547 sd->quality = QUALITY_MIN;
548 else if (jcomp->quality > QUALITY_MAX)
549 sd->quality = QUALITY_MAX;
550 else
551 sd->quality = jcomp->quality;
552 if (gspca_dev->streaming)
553 jpeg_set_qual(sd->jpeg_hdr, sd->quality);
554 return 0;
555}
556
557static int sd_get_jcomp(struct gspca_dev *gspca_dev,
558 struct v4l2_jpegcompression *jcomp)
559{
560 struct sd *sd = (struct sd *) gspca_dev;
561
562 memset(jcomp, 0, sizeof *jcomp);
563 jcomp->quality = sd->quality;
564 jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT
565 | V4L2_JPEG_MARKER_DQT;
566 return 0;
567}
568
523/* sub-driver description */ 569/* sub-driver description */
524static const struct sd_desc sd_desc = { 570static const struct sd_desc sd_desc = {
525 .name = MODULE_NAME, 571 .name = MODULE_NAME,
@@ -529,8 +575,11 @@ static const struct sd_desc sd_desc = {
529 .init = sd_init, 575 .init = sd_init,
530 .start = sd_start, 576 .start = sd_start,
531 .stopN = sd_stopN, 577 .stopN = sd_stopN,
578 .stop0 = sd_stop0,
532 .pkt_scan = sd_pkt_scan, 579 .pkt_scan = sd_pkt_scan,
533 .querymenu = sd_querymenu, 580 .querymenu = sd_querymenu,
581 .get_jcomp = sd_get_jcomp,
582 .set_jcomp = sd_set_jcomp,
534}; 583};
535 584
536/* -- module initialisation -- */ 585/* -- module initialisation -- */
@@ -562,8 +611,10 @@ static struct usb_driver sd_driver = {
562/* -- module insert / remove -- */ 611/* -- module insert / remove -- */
563static int __init sd_mod_init(void) 612static int __init sd_mod_init(void)
564{ 613{
565 if (usb_register(&sd_driver) < 0) 614 int ret;
566 return -1; 615 ret = usb_register(&sd_driver);
616 if (ret < 0)
617 return ret;
567 info("registered"); 618 info("registered");
568 return 0; 619 return 0;
569} 620}
@@ -575,6 +626,3 @@ static void __exit sd_mod_exit(void)
575 626
576module_init(sd_mod_init); 627module_init(sd_mod_init);
577module_exit(sd_mod_exit); 628module_exit(sd_mod_exit);
578
579module_param_named(quant, sd_quant, int, 0644);
580MODULE_PARM_DESC(quant, "Quantization index (0..8)");
diff --git a/drivers/media/video/gspca/stv06xx/stv06xx.c b/drivers/media/video/gspca/stv06xx/stv06xx.c
index 13a021e3cbb7..9dff2e65b116 100644
--- a/drivers/media/video/gspca/stv06xx/stv06xx.c
+++ b/drivers/media/video/gspca/stv06xx/stv06xx.c
@@ -429,7 +429,6 @@ static int stv06xx_config(struct gspca_dev *gspca_dev,
429 PDEBUG(D_PROBE, "Configuring camera"); 429 PDEBUG(D_PROBE, "Configuring camera");
430 430
431 cam = &gspca_dev->cam; 431 cam = &gspca_dev->cam;
432 cam->epaddr = STV_ISOC_ENDPOINT_ADDR;
433 sd->desc = sd_desc; 432 sd->desc = sd_desc;
434 gspca_dev->sd_desc = &sd->desc; 433 gspca_dev->sd_desc = &sd->desc;
435 434
@@ -501,8 +500,10 @@ static struct usb_driver sd_driver = {
501/* -- module insert / remove -- */ 500/* -- module insert / remove -- */
502static int __init sd_mod_init(void) 501static int __init sd_mod_init(void)
503{ 502{
504 if (usb_register(&sd_driver) < 0) 503 int ret;
505 return -1; 504 ret = usb_register(&sd_driver);
505 if (ret < 0)
506 return ret;
506 PDEBUG(D_PROBE, "registered"); 507 PDEBUG(D_PROBE, "registered");
507 return 0; 508 return 0;
508} 509}
diff --git a/drivers/media/video/gspca/stv06xx/stv06xx_hdcs.c b/drivers/media/video/gspca/stv06xx/stv06xx_hdcs.c
index 14335a9e4bb5..b16903814203 100644
--- a/drivers/media/video/gspca/stv06xx/stv06xx_hdcs.c
+++ b/drivers/media/video/gspca/stv06xx/stv06xx_hdcs.c
@@ -30,6 +30,66 @@
30 30
31#include "stv06xx_hdcs.h" 31#include "stv06xx_hdcs.h"
32 32
33static const struct ctrl hdcs1x00_ctrl[] = {
34 {
35 {
36 .id = V4L2_CID_EXPOSURE,
37 .type = V4L2_CTRL_TYPE_INTEGER,
38 .name = "exposure",
39 .minimum = 0x00,
40 .maximum = 0xffff,
41 .step = 0x1,
42 .default_value = HDCS_DEFAULT_EXPOSURE,
43 .flags = V4L2_CTRL_FLAG_SLIDER
44 },
45 .set = hdcs_set_exposure,
46 .get = hdcs_get_exposure
47 }, {
48 {
49 .id = V4L2_CID_GAIN,
50 .type = V4L2_CTRL_TYPE_INTEGER,
51 .name = "gain",
52 .minimum = 0x00,
53 .maximum = 0xff,
54 .step = 0x1,
55 .default_value = HDCS_DEFAULT_GAIN,
56 .flags = V4L2_CTRL_FLAG_SLIDER
57 },
58 .set = hdcs_set_gain,
59 .get = hdcs_get_gain
60 }
61};
62
63static struct v4l2_pix_format hdcs1x00_mode[] = {
64 {
65 HDCS_1X00_DEF_WIDTH,
66 HDCS_1X00_DEF_HEIGHT,
67 V4L2_PIX_FMT_SBGGR8,
68 V4L2_FIELD_NONE,
69 .sizeimage =
70 HDCS_1X00_DEF_WIDTH * HDCS_1X00_DEF_HEIGHT,
71 .bytesperline = HDCS_1X00_DEF_WIDTH,
72 .colorspace = V4L2_COLORSPACE_SRGB,
73 .priv = 1
74 }
75};
76
77static const struct ctrl hdcs1020_ctrl[] = {};
78
79static struct v4l2_pix_format hdcs1020_mode[] = {
80 {
81 HDCS_1020_DEF_WIDTH,
82 HDCS_1020_DEF_HEIGHT,
83 V4L2_PIX_FMT_SBGGR8,
84 V4L2_FIELD_NONE,
85 .sizeimage =
86 HDCS_1020_DEF_WIDTH * HDCS_1020_DEF_HEIGHT,
87 .bytesperline = HDCS_1020_DEF_WIDTH,
88 .colorspace = V4L2_COLORSPACE_SRGB,
89 .priv = 1
90 }
91};
92
33enum hdcs_power_state { 93enum hdcs_power_state {
34 HDCS_STATE_SLEEP, 94 HDCS_STATE_SLEEP,
35 HDCS_STATE_IDLE, 95 HDCS_STATE_IDLE,
@@ -353,10 +413,10 @@ static int hdcs_probe_1x00(struct sd *sd)
353 413
354 info("HDCS-1000/1100 sensor detected"); 414 info("HDCS-1000/1100 sensor detected");
355 415
356 sd->gspca_dev.cam.cam_mode = stv06xx_sensor_hdcs1x00.modes; 416 sd->gspca_dev.cam.cam_mode = hdcs1x00_mode;
357 sd->gspca_dev.cam.nmodes = stv06xx_sensor_hdcs1x00.nmodes; 417 sd->gspca_dev.cam.nmodes = ARRAY_SIZE(hdcs1x00_mode);
358 sd->desc.ctrls = stv06xx_sensor_hdcs1x00.ctrls; 418 sd->desc.ctrls = hdcs1x00_ctrl;
359 sd->desc.nctrls = stv06xx_sensor_hdcs1x00.nctrls; 419 sd->desc.nctrls = ARRAY_SIZE(hdcs1x00_ctrl);
360 420
361 hdcs = kmalloc(sizeof(struct hdcs), GFP_KERNEL); 421 hdcs = kmalloc(sizeof(struct hdcs), GFP_KERNEL);
362 if (!hdcs) 422 if (!hdcs)
@@ -412,10 +472,10 @@ static int hdcs_probe_1020(struct sd *sd)
412 472
413 info("HDCS-1020 sensor detected"); 473 info("HDCS-1020 sensor detected");
414 474
415 sd->gspca_dev.cam.cam_mode = stv06xx_sensor_hdcs1020.modes; 475 sd->gspca_dev.cam.cam_mode = hdcs1020_mode;
416 sd->gspca_dev.cam.nmodes = stv06xx_sensor_hdcs1020.nmodes; 476 sd->gspca_dev.cam.nmodes = ARRAY_SIZE(hdcs1020_mode);
417 sd->desc.ctrls = stv06xx_sensor_hdcs1020.ctrls; 477 sd->desc.ctrls = hdcs1020_ctrl;
418 sd->desc.nctrls = stv06xx_sensor_hdcs1020.nctrls; 478 sd->desc.nctrls = ARRAY_SIZE(hdcs1020_ctrl);
419 479
420 hdcs = kmalloc(sizeof(struct hdcs), GFP_KERNEL); 480 hdcs = kmalloc(sizeof(struct hdcs), GFP_KERNEL);
421 if (!hdcs) 481 if (!hdcs)
diff --git a/drivers/media/video/gspca/stv06xx/stv06xx_hdcs.h b/drivers/media/video/gspca/stv06xx/stv06xx_hdcs.h
index 9c7279a4cd88..412f06cf3d5c 100644
--- a/drivers/media/video/gspca/stv06xx/stv06xx_hdcs.h
+++ b/drivers/media/video/gspca/stv06xx/stv06xx_hdcs.h
@@ -152,53 +152,6 @@ const struct stv06xx_sensor stv06xx_sensor_hdcs1x00 = {
152 .stop = hdcs_stop, 152 .stop = hdcs_stop,
153 .disconnect = hdcs_disconnect, 153 .disconnect = hdcs_disconnect,
154 .dump = hdcs_dump, 154 .dump = hdcs_dump,
155
156 .nctrls = 2,
157 .ctrls = {
158 {
159 {
160 .id = V4L2_CID_EXPOSURE,
161 .type = V4L2_CTRL_TYPE_INTEGER,
162 .name = "exposure",
163 .minimum = 0x00,
164 .maximum = 0xffff,
165 .step = 0x1,
166 .default_value = HDCS_DEFAULT_EXPOSURE,
167 .flags = V4L2_CTRL_FLAG_SLIDER
168 },
169 .set = hdcs_set_exposure,
170 .get = hdcs_get_exposure
171 },
172 {
173 {
174 .id = V4L2_CID_GAIN,
175 .type = V4L2_CTRL_TYPE_INTEGER,
176 .name = "gain",
177 .minimum = 0x00,
178 .maximum = 0xff,
179 .step = 0x1,
180 .default_value = HDCS_DEFAULT_GAIN,
181 .flags = V4L2_CTRL_FLAG_SLIDER
182 },
183 .set = hdcs_set_gain,
184 .get = hdcs_get_gain
185 }
186 },
187
188 .nmodes = 1,
189 .modes = {
190 {
191 HDCS_1X00_DEF_WIDTH,
192 HDCS_1X00_DEF_HEIGHT,
193 V4L2_PIX_FMT_SBGGR8,
194 V4L2_FIELD_NONE,
195 .sizeimage =
196 HDCS_1X00_DEF_WIDTH * HDCS_1X00_DEF_HEIGHT,
197 .bytesperline = HDCS_1X00_DEF_WIDTH,
198 .colorspace = V4L2_COLORSPACE_SRGB,
199 .priv = 1
200 }
201 }
202}; 155};
203 156
204const struct stv06xx_sensor stv06xx_sensor_hdcs1020 = { 157const struct stv06xx_sensor stv06xx_sensor_hdcs1020 = {
@@ -207,29 +160,11 @@ const struct stv06xx_sensor stv06xx_sensor_hdcs1020 = {
207 .i2c_addr = (0x55 << 1), 160 .i2c_addr = (0x55 << 1),
208 .i2c_len = 1, 161 .i2c_len = 1,
209 162
210 .nctrls = 0,
211 .ctrls = {},
212
213 .init = hdcs_init, 163 .init = hdcs_init,
214 .probe = hdcs_probe_1020, 164 .probe = hdcs_probe_1020,
215 .start = hdcs_start, 165 .start = hdcs_start,
216 .stop = hdcs_stop, 166 .stop = hdcs_stop,
217 .dump = hdcs_dump, 167 .dump = hdcs_dump,
218
219 .nmodes = 1,
220 .modes = {
221 {
222 HDCS_1020_DEF_WIDTH,
223 HDCS_1020_DEF_HEIGHT,
224 V4L2_PIX_FMT_SBGGR8,
225 V4L2_FIELD_NONE,
226 .sizeimage =
227 HDCS_1020_DEF_WIDTH * HDCS_1020_DEF_HEIGHT,
228 .bytesperline = HDCS_1020_DEF_WIDTH,
229 .colorspace = V4L2_COLORSPACE_SRGB,
230 .priv = 1
231 }
232 }
233}; 168};
234 169
235static const u16 stv_bridge_init[][2] = { 170static const u16 stv_bridge_init[][2] = {
diff --git a/drivers/media/video/gspca/stv06xx/stv06xx_pb0100.c b/drivers/media/video/gspca/stv06xx/stv06xx_pb0100.c
index d0a0f8596454..285221e6b390 100644
--- a/drivers/media/video/gspca/stv06xx/stv06xx_pb0100.c
+++ b/drivers/media/video/gspca/stv06xx/stv06xx_pb0100.c
@@ -46,6 +46,132 @@
46 46
47#include "stv06xx_pb0100.h" 47#include "stv06xx_pb0100.h"
48 48
49static const struct ctrl pb0100_ctrl[] = {
50#define GAIN_IDX 0
51 {
52 {
53 .id = V4L2_CID_GAIN,
54 .type = V4L2_CTRL_TYPE_INTEGER,
55 .name = "Gain",
56 .minimum = 0,
57 .maximum = 255,
58 .step = 1,
59 .default_value = 128
60 },
61 .set = pb0100_set_gain,
62 .get = pb0100_get_gain
63 },
64#define RED_BALANCE_IDX 1
65 {
66 {
67 .id = V4L2_CID_RED_BALANCE,
68 .type = V4L2_CTRL_TYPE_INTEGER,
69 .name = "Red Balance",
70 .minimum = -255,
71 .maximum = 255,
72 .step = 1,
73 .default_value = 0
74 },
75 .set = pb0100_set_red_balance,
76 .get = pb0100_get_red_balance
77 },
78#define BLUE_BALANCE_IDX 2
79 {
80 {
81 .id = V4L2_CID_BLUE_BALANCE,
82 .type = V4L2_CTRL_TYPE_INTEGER,
83 .name = "Blue Balance",
84 .minimum = -255,
85 .maximum = 255,
86 .step = 1,
87 .default_value = 0
88 },
89 .set = pb0100_set_blue_balance,
90 .get = pb0100_get_blue_balance
91 },
92#define EXPOSURE_IDX 3
93 {
94 {
95 .id = V4L2_CID_EXPOSURE,
96 .type = V4L2_CTRL_TYPE_INTEGER,
97 .name = "Exposure",
98 .minimum = 0,
99 .maximum = 511,
100 .step = 1,
101 .default_value = 12
102 },
103 .set = pb0100_set_exposure,
104 .get = pb0100_get_exposure
105 },
106#define AUTOGAIN_IDX 4
107 {
108 {
109 .id = V4L2_CID_AUTOGAIN,
110 .type = V4L2_CTRL_TYPE_BOOLEAN,
111 .name = "Automatic Gain and Exposure",
112 .minimum = 0,
113 .maximum = 1,
114 .step = 1,
115 .default_value = 1
116 },
117 .set = pb0100_set_autogain,
118 .get = pb0100_get_autogain
119 },
120#define AUTOGAIN_TARGET_IDX 5
121 {
122 {
123 .id = V4L2_CTRL_CLASS_USER + 0x1000,
124 .type = V4L2_CTRL_TYPE_INTEGER,
125 .name = "Automatic Gain Target",
126 .minimum = 0,
127 .maximum = 255,
128 .step = 1,
129 .default_value = 128
130 },
131 .set = pb0100_set_autogain_target,
132 .get = pb0100_get_autogain_target
133 },
134#define NATURAL_IDX 6
135 {
136 {
137 .id = V4L2_CTRL_CLASS_USER + 0x1001,
138 .type = V4L2_CTRL_TYPE_BOOLEAN,
139 .name = "Natural Light Source",
140 .minimum = 0,
141 .maximum = 1,
142 .step = 1,
143 .default_value = 1
144 },
145 .set = pb0100_set_natural,
146 .get = pb0100_get_natural
147 }
148};
149
150static struct v4l2_pix_format pb0100_mode[] = {
151/* low res / subsample modes disabled as they are only half res horizontal,
152 halving the vertical resolution does not seem to work */
153 {
154 320,
155 240,
156 V4L2_PIX_FMT_SGRBG8,
157 V4L2_FIELD_NONE,
158 .sizeimage = 320 * 240,
159 .bytesperline = 320,
160 .colorspace = V4L2_COLORSPACE_SRGB,
161 .priv = PB0100_CROP_TO_VGA
162 },
163 {
164 352,
165 288,
166 V4L2_PIX_FMT_SGRBG8,
167 V4L2_FIELD_NONE,
168 .sizeimage = 352 * 288,
169 .bytesperline = 352,
170 .colorspace = V4L2_COLORSPACE_SRGB,
171 .priv = 0
172 }
173};
174
49static int pb0100_probe(struct sd *sd) 175static int pb0100_probe(struct sd *sd)
50{ 176{
51 u16 sensor; 177 u16 sensor;
@@ -59,20 +185,19 @@ static int pb0100_probe(struct sd *sd)
59 185
60 if ((sensor >> 8) == 0x64) { 186 if ((sensor >> 8) == 0x64) {
61 sensor_settings = kmalloc( 187 sensor_settings = kmalloc(
62 stv06xx_sensor_pb0100.nctrls * sizeof(s32), 188 ARRAY_SIZE(pb0100_ctrl) * sizeof(s32),
63 GFP_KERNEL); 189 GFP_KERNEL);
64 if (!sensor_settings) 190 if (!sensor_settings)
65 return -ENOMEM; 191 return -ENOMEM;
66 192
67 info("Photobit pb0100 sensor detected"); 193 info("Photobit pb0100 sensor detected");
68 194
69 sd->gspca_dev.cam.cam_mode = stv06xx_sensor_pb0100.modes; 195 sd->gspca_dev.cam.cam_mode = pb0100_mode;
70 sd->gspca_dev.cam.nmodes = stv06xx_sensor_pb0100.nmodes; 196 sd->gspca_dev.cam.nmodes = ARRAY_SIZE(pb0100_mode);
71 sd->desc.ctrls = stv06xx_sensor_pb0100.ctrls; 197 sd->desc.ctrls = pb0100_ctrl;
72 sd->desc.nctrls = stv06xx_sensor_pb0100.nctrls; 198 sd->desc.nctrls = ARRAY_SIZE(pb0100_ctrl);
73 for (i = 0; i < stv06xx_sensor_pb0100.nctrls; i++) 199 for (i = 0; i < sd->desc.nctrls; i++)
74 sensor_settings[i] = stv06xx_sensor_pb0100. 200 sensor_settings[i] = pb0100_ctrl[i].qctrl.default_value;
75 ctrls[i].qctrl.default_value;
76 sd->sensor_priv = sensor_settings; 201 sd->sensor_priv = sensor_settings;
77 202
78 return 0; 203 return 0;
@@ -143,6 +268,12 @@ out:
143 return (err < 0) ? err : 0; 268 return (err < 0) ? err : 0;
144} 269}
145 270
271static void pb0100_disconnect(struct sd *sd)
272{
273 sd->sensor = NULL;
274 kfree(sd->sensor_priv);
275}
276
146/* FIXME: Sort the init commands out and put them into tables, 277/* FIXME: Sort the init commands out and put them into tables,
147 this is only for getting the camera to work */ 278 this is only for getting the camera to work */
148/* FIXME: No error handling for now, 279/* FIXME: No error handling for now,
diff --git a/drivers/media/video/gspca/stv06xx/stv06xx_pb0100.h b/drivers/media/video/gspca/stv06xx/stv06xx_pb0100.h
index 5ea21a1154c4..4de4fa5ebc57 100644
--- a/drivers/media/video/gspca/stv06xx/stv06xx_pb0100.h
+++ b/drivers/media/video/gspca/stv06xx/stv06xx_pb0100.h
@@ -114,6 +114,7 @@ static int pb0100_start(struct sd *sd);
114static int pb0100_init(struct sd *sd); 114static int pb0100_init(struct sd *sd);
115static int pb0100_stop(struct sd *sd); 115static int pb0100_stop(struct sd *sd);
116static int pb0100_dump(struct sd *sd); 116static int pb0100_dump(struct sd *sd);
117static void pb0100_disconnect(struct sd *sd);
117 118
118/* V4L2 controls supported by the driver */ 119/* V4L2 controls supported by the driver */
119static int pb0100_get_gain(struct gspca_dev *gspca_dev, __s32 *val); 120static int pb0100_get_gain(struct gspca_dev *gspca_dev, __s32 *val);
@@ -137,139 +138,12 @@ const struct stv06xx_sensor stv06xx_sensor_pb0100 = {
137 .i2c_addr = 0xba, 138 .i2c_addr = 0xba,
138 .i2c_len = 2, 139 .i2c_len = 2,
139 140
140 .nctrls = 7,
141 .ctrls = {
142#define GAIN_IDX 0
143 {
144 {
145 .id = V4L2_CID_GAIN,
146 .type = V4L2_CTRL_TYPE_INTEGER,
147 .name = "Gain",
148 .minimum = 0,
149 .maximum = 255,
150 .step = 1,
151 .default_value = 128
152 },
153 .set = pb0100_set_gain,
154 .get = pb0100_get_gain
155 },
156#define RED_BALANCE_IDX 1
157 {
158 {
159 .id = V4L2_CID_RED_BALANCE,
160 .type = V4L2_CTRL_TYPE_INTEGER,
161 .name = "Red Balance",
162 .minimum = -255,
163 .maximum = 255,
164 .step = 1,
165 .default_value = 0
166 },
167 .set = pb0100_set_red_balance,
168 .get = pb0100_get_red_balance
169 },
170#define BLUE_BALANCE_IDX 2
171 {
172 {
173 .id = V4L2_CID_BLUE_BALANCE,
174 .type = V4L2_CTRL_TYPE_INTEGER,
175 .name = "Blue Balance",
176 .minimum = -255,
177 .maximum = 255,
178 .step = 1,
179 .default_value = 0
180 },
181 .set = pb0100_set_blue_balance,
182 .get = pb0100_get_blue_balance
183 },
184#define EXPOSURE_IDX 3
185 {
186 {
187 .id = V4L2_CID_EXPOSURE,
188 .type = V4L2_CTRL_TYPE_INTEGER,
189 .name = "Exposure",
190 .minimum = 0,
191 .maximum = 511,
192 .step = 1,
193 .default_value = 12
194 },
195 .set = pb0100_set_exposure,
196 .get = pb0100_get_exposure
197 },
198#define AUTOGAIN_IDX 4
199 {
200 {
201 .id = V4L2_CID_AUTOGAIN,
202 .type = V4L2_CTRL_TYPE_BOOLEAN,
203 .name = "Automatic Gain and Exposure",
204 .minimum = 0,
205 .maximum = 1,
206 .step = 1,
207 .default_value = 1
208 },
209 .set = pb0100_set_autogain,
210 .get = pb0100_get_autogain
211 },
212#define AUTOGAIN_TARGET_IDX 5
213 {
214 {
215 .id = V4L2_CTRL_CLASS_USER + 0x1000,
216 .type = V4L2_CTRL_TYPE_INTEGER,
217 .name = "Automatic Gain Target",
218 .minimum = 0,
219 .maximum = 255,
220 .step = 1,
221 .default_value = 128
222 },
223 .set = pb0100_set_autogain_target,
224 .get = pb0100_get_autogain_target
225 },
226#define NATURAL_IDX 6
227 {
228 {
229 .id = V4L2_CTRL_CLASS_USER + 0x1001,
230 .type = V4L2_CTRL_TYPE_BOOLEAN,
231 .name = "Natural Light Source",
232 .minimum = 0,
233 .maximum = 1,
234 .step = 1,
235 .default_value = 1
236 },
237 .set = pb0100_set_natural,
238 .get = pb0100_get_natural
239 },
240 },
241
242 .init = pb0100_init, 141 .init = pb0100_init,
243 .probe = pb0100_probe, 142 .probe = pb0100_probe,
244 .start = pb0100_start, 143 .start = pb0100_start,
245 .stop = pb0100_stop, 144 .stop = pb0100_stop,
246 .dump = pb0100_dump, 145 .dump = pb0100_dump,
247 146 .disconnect = pb0100_disconnect,
248 .nmodes = 2,
249 .modes = {
250/* low res / subsample modes disabled as they are only half res horizontal,
251 halving the vertical resolution does not seem to work */
252 {
253 320,
254 240,
255 V4L2_PIX_FMT_SGRBG8,
256 V4L2_FIELD_NONE,
257 .sizeimage = 320 * 240,
258 .bytesperline = 320,
259 .colorspace = V4L2_COLORSPACE_SRGB,
260 .priv = PB0100_CROP_TO_VGA
261 },
262 {
263 352,
264 288,
265 V4L2_PIX_FMT_SGRBG8,
266 V4L2_FIELD_NONE,
267 .sizeimage = 352 * 288,
268 .bytesperline = 352,
269 .colorspace = V4L2_COLORSPACE_SRGB,
270 .priv = 0
271 },
272 }
273}; 147};
274 148
275#endif 149#endif
diff --git a/drivers/media/video/gspca/stv06xx/stv06xx_sensor.h b/drivers/media/video/gspca/stv06xx/stv06xx_sensor.h
index c726dacefa1f..e88c42f7d2f8 100644
--- a/drivers/media/video/gspca/stv06xx/stv06xx_sensor.h
+++ b/drivers/media/video/gspca/stv06xx/stv06xx_sensor.h
@@ -41,8 +41,6 @@ extern const struct stv06xx_sensor stv06xx_sensor_hdcs1x00;
41extern const struct stv06xx_sensor stv06xx_sensor_hdcs1020; 41extern const struct stv06xx_sensor stv06xx_sensor_hdcs1020;
42extern const struct stv06xx_sensor stv06xx_sensor_pb0100; 42extern const struct stv06xx_sensor stv06xx_sensor_pb0100;
43 43
44#define STV06XX_MAX_CTRLS (V4L2_CID_LASTP1 - V4L2_CID_BASE + 10)
45
46struct stv06xx_sensor { 44struct stv06xx_sensor {
47 /* Defines the name of a sensor */ 45 /* Defines the name of a sensor */
48 char name[32]; 46 char name[32];
@@ -81,12 +79,6 @@ struct stv06xx_sensor {
81 79
82 /* Instructs the sensor to dump all its contents */ 80 /* Instructs the sensor to dump all its contents */
83 int (*dump)(struct sd *sd); 81 int (*dump)(struct sd *sd);
84
85 int nctrls;
86 struct ctrl ctrls[STV06XX_MAX_CTRLS];
87
88 char nmodes;
89 struct v4l2_pix_format modes[];
90}; 82};
91 83
92#endif 84#endif
diff --git a/drivers/media/video/gspca/stv06xx/stv06xx_vv6410.c b/drivers/media/video/gspca/stv06xx/stv06xx_vv6410.c
index 1ca91f2a6dee..69c77c932fc0 100644
--- a/drivers/media/video/gspca/stv06xx/stv06xx_vv6410.c
+++ b/drivers/media/video/gspca/stv06xx/stv06xx_vv6410.c
@@ -29,26 +29,92 @@
29 29
30#include "stv06xx_vv6410.h" 30#include "stv06xx_vv6410.h"
31 31
32static struct v4l2_pix_format vv6410_mode[] = {
33 {
34 356,
35 292,
36 V4L2_PIX_FMT_SGRBG8,
37 V4L2_FIELD_NONE,
38 .sizeimage = 356 * 292,
39 .bytesperline = 356,
40 .colorspace = V4L2_COLORSPACE_SRGB,
41 .priv = 0
42 }
43};
44
45static const struct ctrl vv6410_ctrl[] = {
46#define HFLIP_IDX 0
47 {
48 {
49 .id = V4L2_CID_HFLIP,
50 .type = V4L2_CTRL_TYPE_BOOLEAN,
51 .name = "horizontal flip",
52 .minimum = 0,
53 .maximum = 1,
54 .step = 1,
55 .default_value = 0
56 },
57 .set = vv6410_set_hflip,
58 .get = vv6410_get_hflip
59 },
60#define VFLIP_IDX 1
61 {
62 {
63 .id = V4L2_CID_VFLIP,
64 .type = V4L2_CTRL_TYPE_BOOLEAN,
65 .name = "vertical flip",
66 .minimum = 0,
67 .maximum = 1,
68 .step = 1,
69 .default_value = 0
70 },
71 .set = vv6410_set_vflip,
72 .get = vv6410_get_vflip
73 },
74#define GAIN_IDX 2
75 {
76 {
77 .id = V4L2_CID_GAIN,
78 .type = V4L2_CTRL_TYPE_INTEGER,
79 .name = "analog gain",
80 .minimum = 0,
81 .maximum = 15,
82 .step = 1,
83 .default_value = 0
84 },
85 .set = vv6410_set_analog_gain,
86 .get = vv6410_get_analog_gain
87 }
88};
89
32static int vv6410_probe(struct sd *sd) 90static int vv6410_probe(struct sd *sd)
33{ 91{
34 u16 data; 92 u16 data;
35 int err; 93 int err, i;
94 s32 *sensor_settings;
36 95
37 err = stv06xx_read_sensor(sd, VV6410_DEVICEH, &data); 96 err = stv06xx_read_sensor(sd, VV6410_DEVICEH, &data);
38
39 if (err < 0) 97 if (err < 0)
40 return -ENODEV; 98 return -ENODEV;
41 99
42 if (data == 0x19) { 100 if (data == 0x19) {
43 info("vv6410 sensor detected"); 101 info("vv6410 sensor detected");
44 102
45 sd->gspca_dev.cam.cam_mode = stv06xx_sensor_vv6410.modes; 103 sensor_settings = kmalloc(ARRAY_SIZE(vv6410_ctrl) * sizeof(s32),
46 sd->gspca_dev.cam.nmodes = stv06xx_sensor_vv6410.nmodes; 104 GFP_KERNEL);
47 sd->desc.ctrls = stv06xx_sensor_vv6410.ctrls; 105 if (!sensor_settings)
48 sd->desc.nctrls = stv06xx_sensor_vv6410.nctrls; 106 return -ENOMEM;
107
108 sd->gspca_dev.cam.cam_mode = vv6410_mode;
109 sd->gspca_dev.cam.nmodes = ARRAY_SIZE(vv6410_mode);
110 sd->desc.ctrls = vv6410_ctrl;
111 sd->desc.nctrls = ARRAY_SIZE(vv6410_ctrl);
112
113 for (i = 0; i < sd->desc.nctrls; i++)
114 sensor_settings[i] = vv6410_ctrl[i].qctrl.default_value;
115 sd->sensor_priv = sensor_settings;
49 return 0; 116 return 0;
50 } 117 }
51
52 return -ENODEV; 118 return -ENODEV;
53} 119}
54 120
@@ -80,6 +146,12 @@ static int vv6410_init(struct sd *sd)
80 return (err < 0) ? err : 0; 146 return (err < 0) ? err : 0;
81} 147}
82 148
149static void vv6410_disconnect(struct sd *sd)
150{
151 sd->sensor = NULL;
152 kfree(sd->sensor_priv);
153}
154
83static int vv6410_start(struct sd *sd) 155static int vv6410_start(struct sd *sd)
84{ 156{
85 int err; 157 int err;
@@ -156,17 +228,13 @@ static int vv6410_dump(struct sd *sd)
156 228
157static int vv6410_get_hflip(struct gspca_dev *gspca_dev, __s32 *val) 229static int vv6410_get_hflip(struct gspca_dev *gspca_dev, __s32 *val)
158{ 230{
159 int err;
160 u16 i2c_data;
161 struct sd *sd = (struct sd *) gspca_dev; 231 struct sd *sd = (struct sd *) gspca_dev;
232 s32 *sensor_settings = sd->sensor_priv;
162 233
163 err = stv06xx_read_sensor(sd, VV6410_DATAFORMAT, &i2c_data); 234 *val = sensor_settings[HFLIP_IDX];
164
165 *val = (i2c_data & VV6410_HFLIP) ? 1 : 0;
166
167 PDEBUG(D_V4L2, "Read horizontal flip %d", *val); 235 PDEBUG(D_V4L2, "Read horizontal flip %d", *val);
168 236
169 return (err < 0) ? err : 0; 237 return 0;
170} 238}
171 239
172static int vv6410_set_hflip(struct gspca_dev *gspca_dev, __s32 val) 240static int vv6410_set_hflip(struct gspca_dev *gspca_dev, __s32 val)
@@ -174,6 +242,9 @@ static int vv6410_set_hflip(struct gspca_dev *gspca_dev, __s32 val)
174 int err; 242 int err;
175 u16 i2c_data; 243 u16 i2c_data;
176 struct sd *sd = (struct sd *) gspca_dev; 244 struct sd *sd = (struct sd *) gspca_dev;
245 s32 *sensor_settings = sd->sensor_priv;
246
247 sensor_settings[HFLIP_IDX] = val;
177 err = stv06xx_read_sensor(sd, VV6410_DATAFORMAT, &i2c_data); 248 err = stv06xx_read_sensor(sd, VV6410_DATAFORMAT, &i2c_data);
178 if (err < 0) 249 if (err < 0)
179 return err; 250 return err;
@@ -191,17 +262,13 @@ static int vv6410_set_hflip(struct gspca_dev *gspca_dev, __s32 val)
191 262
192static int vv6410_get_vflip(struct gspca_dev *gspca_dev, __s32 *val) 263static int vv6410_get_vflip(struct gspca_dev *gspca_dev, __s32 *val)
193{ 264{
194 int err;
195 u16 i2c_data;
196 struct sd *sd = (struct sd *) gspca_dev; 265 struct sd *sd = (struct sd *) gspca_dev;
266 s32 *sensor_settings = sd->sensor_priv;
197 267
198 err = stv06xx_read_sensor(sd, VV6410_DATAFORMAT, &i2c_data); 268 *val = sensor_settings[VFLIP_IDX];
199
200 *val = (i2c_data & VV6410_VFLIP) ? 1 : 0;
201
202 PDEBUG(D_V4L2, "Read vertical flip %d", *val); 269 PDEBUG(D_V4L2, "Read vertical flip %d", *val);
203 270
204 return (err < 0) ? err : 0; 271 return 0;
205} 272}
206 273
207static int vv6410_set_vflip(struct gspca_dev *gspca_dev, __s32 val) 274static int vv6410_set_vflip(struct gspca_dev *gspca_dev, __s32 val)
@@ -209,6 +276,9 @@ static int vv6410_set_vflip(struct gspca_dev *gspca_dev, __s32 val)
209 int err; 276 int err;
210 u16 i2c_data; 277 u16 i2c_data;
211 struct sd *sd = (struct sd *) gspca_dev; 278 struct sd *sd = (struct sd *) gspca_dev;
279 s32 *sensor_settings = sd->sensor_priv;
280
281 sensor_settings[VFLIP_IDX] = val;
212 err = stv06xx_read_sensor(sd, VV6410_DATAFORMAT, &i2c_data); 282 err = stv06xx_read_sensor(sd, VV6410_DATAFORMAT, &i2c_data);
213 if (err < 0) 283 if (err < 0)
214 return err; 284 return err;
@@ -226,24 +296,23 @@ static int vv6410_set_vflip(struct gspca_dev *gspca_dev, __s32 val)
226 296
227static int vv6410_get_analog_gain(struct gspca_dev *gspca_dev, __s32 *val) 297static int vv6410_get_analog_gain(struct gspca_dev *gspca_dev, __s32 *val)
228{ 298{
229 int err;
230 u16 i2c_data;
231 struct sd *sd = (struct sd *) gspca_dev; 299 struct sd *sd = (struct sd *) gspca_dev;
300 s32 *sensor_settings = sd->sensor_priv;
232 301
233 err = stv06xx_read_sensor(sd, VV6410_ANALOGGAIN, &i2c_data); 302 *val = sensor_settings[GAIN_IDX];
234
235 *val = i2c_data & 0xf;
236 303
237 PDEBUG(D_V4L2, "Read analog gain %d", *val); 304 PDEBUG(D_V4L2, "Read analog gain %d", *val);
238 305
239 return (err < 0) ? err : 0; 306 return 0;
240} 307}
241 308
242static int vv6410_set_analog_gain(struct gspca_dev *gspca_dev, __s32 val) 309static int vv6410_set_analog_gain(struct gspca_dev *gspca_dev, __s32 val)
243{ 310{
244 int err; 311 int err;
245 struct sd *sd = (struct sd *) gspca_dev; 312 struct sd *sd = (struct sd *) gspca_dev;
313 s32 *sensor_settings = sd->sensor_priv;
246 314
315 sensor_settings[GAIN_IDX] = val;
247 PDEBUG(D_V4L2, "Set analog gain to %d", val); 316 PDEBUG(D_V4L2, "Set analog gain to %d", val);
248 err = stv06xx_write_sensor(sd, VV6410_ANALOGGAIN, 0xf0 | (val & 0xf)); 317 err = stv06xx_write_sensor(sd, VV6410_ANALOGGAIN, 0xf0 | (val & 0xf));
249 318
diff --git a/drivers/media/video/gspca/stv06xx/stv06xx_vv6410.h b/drivers/media/video/gspca/stv06xx/stv06xx_vv6410.h
index 3ff8c4ea3362..95ac55891bd4 100644
--- a/drivers/media/video/gspca/stv06xx/stv06xx_vv6410.h
+++ b/drivers/media/video/gspca/stv06xx/stv06xx_vv6410.h
@@ -178,6 +178,7 @@ static int vv6410_start(struct sd *sd);
178static int vv6410_init(struct sd *sd); 178static int vv6410_init(struct sd *sd);
179static int vv6410_stop(struct sd *sd); 179static int vv6410_stop(struct sd *sd);
180static int vv6410_dump(struct sd *sd); 180static int vv6410_dump(struct sd *sd);
181static void vv6410_disconnect(struct sd *sd);
181 182
182/* V4L2 controls supported by the driver */ 183/* V4L2 controls supported by the driver */
183static int vv6410_get_hflip(struct gspca_dev *gspca_dev, __s32 *val); 184static int vv6410_get_hflip(struct gspca_dev *gspca_dev, __s32 *val);
@@ -197,62 +198,7 @@ const struct stv06xx_sensor stv06xx_sensor_vv6410 = {
197 .start = vv6410_start, 198 .start = vv6410_start,
198 .stop = vv6410_stop, 199 .stop = vv6410_stop,
199 .dump = vv6410_dump, 200 .dump = vv6410_dump,
200 201 .disconnect = vv6410_disconnect,
201 .nctrls = 3,
202 .ctrls = {
203 {
204 {
205 .id = V4L2_CID_HFLIP,
206 .type = V4L2_CTRL_TYPE_BOOLEAN,
207 .name = "horizontal flip",
208 .minimum = 0,
209 .maximum = 1,
210 .step = 1,
211 .default_value = 0
212 },
213 .set = vv6410_set_hflip,
214 .get = vv6410_get_hflip
215 }, {
216 {
217 .id = V4L2_CID_VFLIP,
218 .type = V4L2_CTRL_TYPE_BOOLEAN,
219 .name = "vertical flip",
220 .minimum = 0,
221 .maximum = 1,
222 .step = 1,
223 .default_value = 0
224 },
225 .set = vv6410_set_vflip,
226 .get = vv6410_get_vflip
227 }, {
228 {
229 .id = V4L2_CID_GAIN,
230 .type = V4L2_CTRL_TYPE_INTEGER,
231 .name = "analog gain",
232 .minimum = 0,
233 .maximum = 15,
234 .step = 1,
235 .default_value = 0
236 },
237 .set = vv6410_set_analog_gain,
238 .get = vv6410_get_analog_gain
239 }
240 },
241
242 .nmodes = 1,
243 .modes = {
244 {
245 356,
246 292,
247 V4L2_PIX_FMT_SGRBG8,
248 V4L2_FIELD_NONE,
249 .sizeimage =
250 356 * 292,
251 .bytesperline = 356,
252 .colorspace = V4L2_COLORSPACE_SRGB,
253 .priv = 0
254 }
255 }
256}; 202};
257 203
258/* If NULL, only single value to write, stored in len */ 204/* If NULL, only single value to write, stored in len */
diff --git a/drivers/media/video/gspca/sunplus.c b/drivers/media/video/gspca/sunplus.c
index 6d904d5e4c74..c2b8c10c075a 100644
--- a/drivers/media/video/gspca/sunplus.c
+++ b/drivers/media/video/gspca/sunplus.c
@@ -39,8 +39,11 @@ struct sd {
39 unsigned char contrast; 39 unsigned char contrast;
40 unsigned char colors; 40 unsigned char colors;
41 unsigned char autogain; 41 unsigned char autogain;
42 u8 quality;
43#define QUALITY_MIN 70
44#define QUALITY_MAX 95
45#define QUALITY_DEF 85
42 46
43 char qindex;
44 char bridge; 47 char bridge;
45#define BRIDGE_SPCA504 0 48#define BRIDGE_SPCA504 0
46#define BRIDGE_SPCA504B 1 49#define BRIDGE_SPCA504B 1
@@ -52,6 +55,8 @@ struct sd {
52#define LogitechClickSmart420 2 55#define LogitechClickSmart420 2
53#define LogitechClickSmart820 3 56#define LogitechClickSmart820 3
54#define MegapixV4 4 57#define MegapixV4 4
58
59 u8 *jpeg_hdr;
55}; 60};
56 61
57/* V4L2 controls supported by the driver */ 62/* V4L2 controls supported by the driver */
@@ -812,7 +817,6 @@ static int sd_config(struct gspca_dev *gspca_dev,
812 struct cam *cam; 817 struct cam *cam;
813 818
814 cam = &gspca_dev->cam; 819 cam = &gspca_dev->cam;
815 cam->epaddr = 0x01;
816 820
817 sd->bridge = id->driver_info >> 8; 821 sd->bridge = id->driver_info >> 8;
818 sd->subtype = id->driver_info; 822 sd->subtype = id->driver_info;
@@ -850,10 +854,10 @@ static int sd_config(struct gspca_dev *gspca_dev,
850 cam->nmodes = sizeof vga_mode2 / sizeof vga_mode2[0]; 854 cam->nmodes = sizeof vga_mode2 / sizeof vga_mode2[0];
851 break; 855 break;
852 } 856 }
853 sd->qindex = 5; /* set the quantization table */
854 sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value; 857 sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value;
855 sd->contrast = sd_ctrls[SD_CONTRAST].qctrl.default_value; 858 sd->contrast = sd_ctrls[SD_CONTRAST].qctrl.default_value;
856 sd->colors = sd_ctrls[SD_COLOR].qctrl.default_value; 859 sd->colors = sd_ctrls[SD_COLOR].qctrl.default_value;
860 sd->quality = QUALITY_DEF;
857 return 0; 861 return 0;
858} 862}
859 863
@@ -970,6 +974,12 @@ static int sd_start(struct gspca_dev *gspca_dev)
970 __u8 i; 974 __u8 i;
971 __u8 info[6]; 975 __u8 info[6];
972 976
977 /* create the JPEG header */
978 sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL);
979 jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
980 0x22); /* JPEG 411 */
981 jpeg_set_qual(sd->jpeg_hdr, sd->quality);
982
973 if (sd->bridge == BRIDGE_SPCA504B) 983 if (sd->bridge == BRIDGE_SPCA504B)
974 spca504B_setQtable(gspca_dev); 984 spca504B_setQtable(gspca_dev);
975 spca504B_SetSizeType(gspca_dev); 985 spca504B_SetSizeType(gspca_dev);
@@ -1079,6 +1089,13 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
1079 } 1089 }
1080} 1090}
1081 1091
1092static void sd_stop0(struct gspca_dev *gspca_dev)
1093{
1094 struct sd *sd = (struct sd *) gspca_dev;
1095
1096 kfree(sd->jpeg_hdr);
1097}
1098
1082static void sd_pkt_scan(struct gspca_dev *gspca_dev, 1099static void sd_pkt_scan(struct gspca_dev *gspca_dev,
1083 struct gspca_frame *frame, /* target */ 1100 struct gspca_frame *frame, /* target */
1084 __u8 *data, /* isoc packet */ 1101 __u8 *data, /* isoc packet */
@@ -1155,9 +1172,8 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
1155 ffd9, 2); 1172 ffd9, 2);
1156 1173
1157 /* put the JPEG header in the new frame */ 1174 /* put the JPEG header in the new frame */
1158 jpeg_put_header(gspca_dev, frame, 1175 gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
1159 ((struct sd *) gspca_dev)->qindex, 1176 sd->jpeg_hdr, JPEG_HDR_SZ);
1160 0x22);
1161 } 1177 }
1162 1178
1163 /* add 0x00 after 0xff */ 1179 /* add 0x00 after 0xff */
@@ -1198,26 +1214,6 @@ static void setbrightness(struct gspca_dev *gspca_dev)
1198 } 1214 }
1199} 1215}
1200 1216
1201static void getbrightness(struct gspca_dev *gspca_dev)
1202{
1203 struct sd *sd = (struct sd *) gspca_dev;
1204 __u16 brightness = 0;
1205
1206 switch (sd->bridge) {
1207 default:
1208/* case BRIDGE_SPCA533: */
1209/* case BRIDGE_SPCA504B: */
1210/* case BRIDGE_SPCA504: */
1211/* case BRIDGE_SPCA504C: */
1212 brightness = reg_r_12(gspca_dev, 0x00, 0x21a7, 2);
1213 break;
1214 case BRIDGE_SPCA536:
1215 brightness = reg_r_12(gspca_dev, 0x00, 0x20f0, 2);
1216 break;
1217 }
1218 sd->brightness = ((brightness & 0xff) - 128) % 255;
1219}
1220
1221static void setcontrast(struct gspca_dev *gspca_dev) 1217static void setcontrast(struct gspca_dev *gspca_dev)
1222{ 1218{
1223 struct sd *sd = (struct sd *) gspca_dev; 1219 struct sd *sd = (struct sd *) gspca_dev;
@@ -1237,24 +1233,6 @@ static void setcontrast(struct gspca_dev *gspca_dev)
1237 } 1233 }
1238} 1234}
1239 1235
1240static void getcontrast(struct gspca_dev *gspca_dev)
1241{
1242 struct sd *sd = (struct sd *) gspca_dev;
1243
1244 switch (sd->bridge) {
1245 default:
1246/* case BRIDGE_SPCA533: */
1247/* case BRIDGE_SPCA504B: */
1248/* case BRIDGE_SPCA504: */
1249/* case BRIDGE_SPCA504C: */
1250 sd->contrast = reg_r_12(gspca_dev, 0x00, 0x21a8, 2);
1251 break;
1252 case BRIDGE_SPCA536:
1253 sd->contrast = reg_r_12(gspca_dev, 0x00, 0x20f1, 2);
1254 break;
1255 }
1256}
1257
1258static void setcolors(struct gspca_dev *gspca_dev) 1236static void setcolors(struct gspca_dev *gspca_dev)
1259{ 1237{
1260 struct sd *sd = (struct sd *) gspca_dev; 1238 struct sd *sd = (struct sd *) gspca_dev;
@@ -1274,24 +1252,6 @@ static void setcolors(struct gspca_dev *gspca_dev)
1274 } 1252 }
1275} 1253}
1276 1254
1277static void getcolors(struct gspca_dev *gspca_dev)
1278{
1279 struct sd *sd = (struct sd *) gspca_dev;
1280
1281 switch (sd->bridge) {
1282 default:
1283/* case BRIDGE_SPCA533: */
1284/* case BRIDGE_SPCA504B: */
1285/* case BRIDGE_SPCA504: */
1286/* case BRIDGE_SPCA504C: */
1287 sd->colors = reg_r_12(gspca_dev, 0x00, 0x21ae, 2) >> 1;
1288 break;
1289 case BRIDGE_SPCA536:
1290 sd->colors = reg_r_12(gspca_dev, 0x00, 0x20f6, 2) >> 1;
1291 break;
1292 }
1293}
1294
1295static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val) 1255static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
1296{ 1256{
1297 struct sd *sd = (struct sd *) gspca_dev; 1257 struct sd *sd = (struct sd *) gspca_dev;
@@ -1306,7 +1266,6 @@ static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
1306{ 1266{
1307 struct sd *sd = (struct sd *) gspca_dev; 1267 struct sd *sd = (struct sd *) gspca_dev;
1308 1268
1309 getbrightness(gspca_dev);
1310 *val = sd->brightness; 1269 *val = sd->brightness;
1311 return 0; 1270 return 0;
1312} 1271}
@@ -1325,7 +1284,6 @@ static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
1325{ 1284{
1326 struct sd *sd = (struct sd *) gspca_dev; 1285 struct sd *sd = (struct sd *) gspca_dev;
1327 1286
1328 getcontrast(gspca_dev);
1329 *val = sd->contrast; 1287 *val = sd->contrast;
1330 return 0; 1288 return 0;
1331} 1289}
@@ -1344,7 +1302,6 @@ static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
1344{ 1302{
1345 struct sd *sd = (struct sd *) gspca_dev; 1303 struct sd *sd = (struct sd *) gspca_dev;
1346 1304
1347 getcolors(gspca_dev);
1348 *val = sd->colors; 1305 *val = sd->colors;
1349 return 0; 1306 return 0;
1350} 1307}
@@ -1365,6 +1322,34 @@ static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
1365 return 0; 1322 return 0;
1366} 1323}
1367 1324
1325static int sd_set_jcomp(struct gspca_dev *gspca_dev,
1326 struct v4l2_jpegcompression *jcomp)
1327{
1328 struct sd *sd = (struct sd *) gspca_dev;
1329
1330 if (jcomp->quality < QUALITY_MIN)
1331 sd->quality = QUALITY_MIN;
1332 else if (jcomp->quality > QUALITY_MAX)
1333 sd->quality = QUALITY_MAX;
1334 else
1335 sd->quality = jcomp->quality;
1336 if (gspca_dev->streaming)
1337 jpeg_set_qual(sd->jpeg_hdr, sd->quality);
1338 return 0;
1339}
1340
1341static int sd_get_jcomp(struct gspca_dev *gspca_dev,
1342 struct v4l2_jpegcompression *jcomp)
1343{
1344 struct sd *sd = (struct sd *) gspca_dev;
1345
1346 memset(jcomp, 0, sizeof *jcomp);
1347 jcomp->quality = sd->quality;
1348 jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT
1349 | V4L2_JPEG_MARKER_DQT;
1350 return 0;
1351}
1352
1368/* sub-driver description */ 1353/* sub-driver description */
1369static const struct sd_desc sd_desc = { 1354static const struct sd_desc sd_desc = {
1370 .name = MODULE_NAME, 1355 .name = MODULE_NAME,
@@ -1374,7 +1359,10 @@ static const struct sd_desc sd_desc = {
1374 .init = sd_init, 1359 .init = sd_init,
1375 .start = sd_start, 1360 .start = sd_start,
1376 .stopN = sd_stopN, 1361 .stopN = sd_stopN,
1362 .stop0 = sd_stop0,
1377 .pkt_scan = sd_pkt_scan, 1363 .pkt_scan = sd_pkt_scan,
1364 .get_jcomp = sd_get_jcomp,
1365 .set_jcomp = sd_set_jcomp,
1378}; 1366};
1379 1367
1380/* -- module initialisation -- */ 1368/* -- module initialisation -- */
@@ -1465,8 +1453,10 @@ static struct usb_driver sd_driver = {
1465/* -- module insert / remove -- */ 1453/* -- module insert / remove -- */
1466static int __init sd_mod_init(void) 1454static int __init sd_mod_init(void)
1467{ 1455{
1468 if (usb_register(&sd_driver) < 0) 1456 int ret;
1469 return -1; 1457 ret = usb_register(&sd_driver);
1458 if (ret < 0)
1459 return ret;
1470 PDEBUG(D_PROBE, "registered"); 1460 PDEBUG(D_PROBE, "registered");
1471 return 0; 1461 return 0;
1472} 1462}
diff --git a/drivers/media/video/gspca/t613.c b/drivers/media/video/gspca/t613.c
index 6ee111a3cbd1..f63e37e2e4fd 100644
--- a/drivers/media/video/gspca/t613.c
+++ b/drivers/media/video/gspca/t613.c
@@ -37,20 +37,21 @@ MODULE_LICENSE("GPL");
37struct sd { 37struct sd {
38 struct gspca_dev gspca_dev; /* !! must be the first item */ 38 struct gspca_dev gspca_dev; /* !! must be the first item */
39 39
40 unsigned char brightness; 40 u8 brightness;
41 unsigned char contrast; 41 u8 contrast;
42 unsigned char colors; 42 u8 colors;
43 unsigned char autogain; 43 u8 autogain;
44 unsigned char gamma; 44 u8 gamma;
45 unsigned char sharpness; 45 u8 sharpness;
46 unsigned char freq; 46 u8 freq;
47 unsigned char whitebalance; 47 u8 whitebalance;
48 unsigned char mirror; 48 u8 mirror;
49 unsigned char effect; 49 u8 effect;
50 50
51 __u8 sensor; 51 u8 sensor;
52#define SENSOR_TAS5130A 0 52#define SENSOR_OM6802 0
53#define SENSOR_OM6802 1 53#define SENSOR_OTHER 1
54#define SENSOR_TAS5130A 2
54}; 55};
55 56
56/* V4L2 controls supported by the driver */ 57/* V4L2 controls supported by the driver */
@@ -78,7 +79,6 @@ static int sd_querymenu(struct gspca_dev *gspca_dev,
78 struct v4l2_querymenu *menu); 79 struct v4l2_querymenu *menu);
79 80
80static struct ctrl sd_ctrls[] = { 81static struct ctrl sd_ctrls[] = {
81#define SD_BRIGHTNESS 0
82 { 82 {
83 { 83 {
84 .id = V4L2_CID_BRIGHTNESS, 84 .id = V4L2_CID_BRIGHTNESS,
@@ -87,12 +87,12 @@ static struct ctrl sd_ctrls[] = {
87 .minimum = 0, 87 .minimum = 0,
88 .maximum = 14, 88 .maximum = 14,
89 .step = 1, 89 .step = 1,
90 .default_value = 8, 90#define BRIGHTNESS_DEF 8
91 .default_value = BRIGHTNESS_DEF,
91 }, 92 },
92 .set = sd_setbrightness, 93 .set = sd_setbrightness,
93 .get = sd_getbrightness, 94 .get = sd_getbrightness,
94 }, 95 },
95#define SD_CONTRAST 1
96 { 96 {
97 { 97 {
98 .id = V4L2_CID_CONTRAST, 98 .id = V4L2_CID_CONTRAST,
@@ -101,12 +101,12 @@ static struct ctrl sd_ctrls[] = {
101 .minimum = 0, 101 .minimum = 0,
102 .maximum = 0x0d, 102 .maximum = 0x0d,
103 .step = 1, 103 .step = 1,
104 .default_value = 0x07, 104#define CONTRAST_DEF 0x07
105 .default_value = CONTRAST_DEF,
105 }, 106 },
106 .set = sd_setcontrast, 107 .set = sd_setcontrast,
107 .get = sd_getcontrast, 108 .get = sd_getcontrast,
108 }, 109 },
109#define SD_COLOR 2
110 { 110 {
111 { 111 {
112 .id = V4L2_CID_SATURATION, 112 .id = V4L2_CID_SATURATION,
@@ -115,7 +115,8 @@ static struct ctrl sd_ctrls[] = {
115 .minimum = 0, 115 .minimum = 0,
116 .maximum = 0x0f, 116 .maximum = 0x0f,
117 .step = 1, 117 .step = 1,
118 .default_value = 0x05, 118#define COLORS_DEF 0x05
119 .default_value = COLORS_DEF,
119 }, 120 },
120 .set = sd_setcolors, 121 .set = sd_setcolors,
121 .get = sd_getcolors, 122 .get = sd_getcolors,
@@ -135,7 +136,6 @@ static struct ctrl sd_ctrls[] = {
135 .set = sd_setgamma, 136 .set = sd_setgamma,
136 .get = sd_getgamma, 137 .get = sd_getgamma,
137 }, 138 },
138#define SD_AUTOGAIN 4
139 { 139 {
140 { 140 {
141 .id = V4L2_CID_GAIN, /* here, i activate only the lowlight, 141 .id = V4L2_CID_GAIN, /* here, i activate only the lowlight,
@@ -146,12 +146,12 @@ static struct ctrl sd_ctrls[] = {
146 .minimum = 0, 146 .minimum = 0,
147 .maximum = 1, 147 .maximum = 1,
148 .step = 1, 148 .step = 1,
149 .default_value = 0x01, 149#define AUTOGAIN_DEF 0x01
150 .default_value = AUTOGAIN_DEF,
150 }, 151 },
151 .set = sd_setlowlight, 152 .set = sd_setlowlight,
152 .get = sd_getlowlight, 153 .get = sd_getlowlight,
153 }, 154 },
154#define SD_MIRROR 5
155 { 155 {
156 { 156 {
157 .id = V4L2_CID_HFLIP, 157 .id = V4L2_CID_HFLIP,
@@ -160,12 +160,12 @@ static struct ctrl sd_ctrls[] = {
160 .minimum = 0, 160 .minimum = 0,
161 .maximum = 1, 161 .maximum = 1,
162 .step = 1, 162 .step = 1,
163 .default_value = 0, 163#define MIRROR_DEF 0
164 .default_value = MIRROR_DEF,
164 }, 165 },
165 .set = sd_setflip, 166 .set = sd_setflip,
166 .get = sd_getflip 167 .get = sd_getflip
167 }, 168 },
168#define SD_LIGHTFREQ 6
169 { 169 {
170 { 170 {
171 .id = V4L2_CID_POWER_LINE_FREQUENCY, 171 .id = V4L2_CID_POWER_LINE_FREQUENCY,
@@ -174,12 +174,12 @@ static struct ctrl sd_ctrls[] = {
174 .minimum = 1, /* 1 -> 0x50, 2->0x60 */ 174 .minimum = 1, /* 1 -> 0x50, 2->0x60 */
175 .maximum = 2, 175 .maximum = 2,
176 .step = 1, 176 .step = 1,
177 .default_value = 1, 177#define FREQ_DEF 1
178 .default_value = FREQ_DEF,
178 }, 179 },
179 .set = sd_setfreq, 180 .set = sd_setfreq,
180 .get = sd_getfreq}, 181 .get = sd_getfreq},
181 182
182#define SD_WHITE_BALANCE 7
183 { 183 {
184 { 184 {
185 .id = V4L2_CID_WHITE_BALANCE_TEMPERATURE, 185 .id = V4L2_CID_WHITE_BALANCE_TEMPERATURE,
@@ -188,12 +188,12 @@ static struct ctrl sd_ctrls[] = {
188 .minimum = 0, 188 .minimum = 0,
189 .maximum = 1, 189 .maximum = 1,
190 .step = 1, 190 .step = 1,
191 .default_value = 0, 191#define WHITE_BALANCE_DEF 0
192 .default_value = WHITE_BALANCE_DEF,
192 }, 193 },
193 .set = sd_setwhitebalance, 194 .set = sd_setwhitebalance,
194 .get = sd_getwhitebalance 195 .get = sd_getwhitebalance
195 }, 196 },
196#define SD_SHARPNESS 8 /* (aka definition on win) */
197 { 197 {
198 { 198 {
199 .id = V4L2_CID_SHARPNESS, 199 .id = V4L2_CID_SHARPNESS,
@@ -202,12 +202,12 @@ static struct ctrl sd_ctrls[] = {
202 .minimum = 0, 202 .minimum = 0,
203 .maximum = 15, 203 .maximum = 15,
204 .step = 1, 204 .step = 1,
205 .default_value = 0x06, 205#define SHARPNESS_DEF 0x06
206 .default_value = SHARPNESS_DEF,
206 }, 207 },
207 .set = sd_setsharpness, 208 .set = sd_setsharpness,
208 .get = sd_getsharpness, 209 .get = sd_getsharpness,
209 }, 210 },
210#define SD_EFFECTS 9
211 { 211 {
212 { 212 {
213 .id = V4L2_CID_EFFECTS, 213 .id = V4L2_CID_EFFECTS,
@@ -216,7 +216,8 @@ static struct ctrl sd_ctrls[] = {
216 .minimum = 0, 216 .minimum = 0,
217 .maximum = 4, 217 .maximum = 4,
218 .step = 1, 218 .step = 1,
219 .default_value = 0, 219#define EFFECTS_DEF 0
220 .default_value = EFFECTS_DEF,
220 }, 221 },
221 .set = sd_seteffect, 222 .set = sd_seteffect,
222 .get = sd_geteffect 223 .get = sd_geteffect
@@ -263,28 +264,50 @@ static const struct v4l2_pix_format vga_mode_t16[] = {
263 264
264/* sensor specific data */ 265/* sensor specific data */
265struct additional_sensor_data { 266struct additional_sensor_data {
266 const __u8 data1[20]; 267 const u8 data1[10];
267 const __u8 data2[18]; 268 const u8 data2[9];
268 const __u8 data3[18]; 269 const u8 data3[9];
269 const __u8 data4[4]; 270 const u8 data4[4];
270 const __u8 data5[6]; 271 const u8 data5[6];
271 const __u8 stream[4]; 272 const u8 stream[4];
272}; 273};
273 274
274const static struct additional_sensor_data sensor_data[] = { 275static const struct additional_sensor_data sensor_data[] = {
276 { /* OM6802 */
277 .data1 =
278 {0xc2, 0x28, 0x0f, 0x22, 0xcd, 0x27, 0x2c, 0x06,
279 0xb3, 0xfc},
280 .data2 =
281 {0x80, 0xff, 0xff, 0x80, 0xff, 0xff, 0x80, 0xff,
282 0xff},
283 .data4 = /*Freq (50/60Hz). Splitted for test purpose */
284 {0x66, 0xca, 0xa8, 0xf0},
285 .data5 = /* this could be removed later */
286 {0x0c, 0x03, 0xab, 0x13, 0x81, 0x23},
287 .stream =
288 {0x0b, 0x04, 0x0a, 0x78},
289 },
290 { /* OTHER */
291 .data1 =
292 {0xc1, 0x48, 0x04, 0x1b, 0xca, 0x2e, 0x33, 0x3a,
293 0xe8, 0xfc},
294 .data2 =
295 {0x4e, 0x9c, 0xec, 0x40, 0x80, 0xc0, 0x48, 0x96,
296 0xd9},
297 .data4 =
298 {0x66, 0x00, 0xa8, 0xa8},
299 .data5 =
300 {0x0c, 0x03, 0xab, 0x29, 0x81, 0x69},
301 .stream =
302 {0x0b, 0x04, 0x0a, 0x00},
303 },
275 { /* TAS5130A */ 304 { /* TAS5130A */
276 .data1 = 305 .data1 =
277 {0xd0, 0xbb, 0xd1, 0x28, 0xd2, 0x10, 0xd3, 0x10, 306 {0xbb, 0x28, 0x10, 0x10, 0xbb, 0x28, 0x1e, 0x27,
278 0xd4, 0xbb, 0xd5, 0x28, 0xd6, 0x1e, 0xd7, 0x27, 307 0xc8, 0xfc},
279 0xd8, 0xc8, 0xd9, 0xfc},
280 .data2 = 308 .data2 =
281 {0xe0, 0x60, 0xe1, 0xa8, 0xe2, 0xe0, 0xe3, 0x60, 309 {0x60, 0xa8, 0xe0, 0x60, 0xa8, 0xe0, 0x60, 0xa8,
282 0xe4, 0xa8, 0xe5, 0xe0, 0xe6, 0x60, 0xe7, 0xa8, 310 0xe0},
283 0xe8, 0xe0},
284 .data3 =
285 {0xc7, 0x60, 0xc8, 0xa8, 0xc9, 0xe0, 0xca, 0x60,
286 0xcb, 0xa8, 0xcc, 0xe0, 0xcd, 0x60, 0xce, 0xa8,
287 0xcf, 0xe0},
288 .data4 = /* Freq (50/60Hz). Splitted for test purpose */ 311 .data4 = /* Freq (50/60Hz). Splitted for test purpose */
289 {0x66, 0x00, 0xa8, 0xe8}, 312 {0x66, 0x00, 0xa8, 0xe8},
290 .data5 = 313 .data5 =
@@ -292,32 +315,12 @@ const static struct additional_sensor_data sensor_data[] = {
292 .stream = 315 .stream =
293 {0x0b, 0x04, 0x0a, 0x40}, 316 {0x0b, 0x04, 0x0a, 0x40},
294 }, 317 },
295 { /* OM6802 */
296 .data1 =
297 {0xd0, 0xc2, 0xd1, 0x28, 0xd2, 0x0f, 0xd3, 0x22,
298 0xd4, 0xcd, 0xd5, 0x27, 0xd6, 0x2c, 0xd7, 0x06,
299 0xd8, 0xb3, 0xd9, 0xfc},
300 .data2 =
301 {0xe0, 0x80, 0xe1, 0xff, 0xe2, 0xff, 0xe3, 0x80,
302 0xe4, 0xff, 0xe5, 0xff, 0xe6, 0x80, 0xe7, 0xff,
303 0xe8, 0xff},
304 .data3 =
305 {0xc7, 0x80, 0xc8, 0xff, 0xc9, 0xff, 0xca, 0x80,
306 0xcb, 0xff, 0xcc, 0xff, 0xcd, 0x80, 0xce, 0xff,
307 0xcf, 0xff},
308 .data4 = /*Freq (50/60Hz). Splitted for test purpose */
309 {0x66, 0xca, 0xa8, 0xf0 },
310 .data5 = /* this could be removed later */
311 {0x0c, 0x03, 0xab, 0x13, 0x81, 0x23},
312 .stream =
313 {0x0b, 0x04, 0x0a, 0x78},
314 }
315}; 318};
316 319
317#define MAX_EFFECTS 7 320#define MAX_EFFECTS 7
318/* easily done by soft, this table could be removed, 321/* easily done by soft, this table could be removed,
319 * i keep it here just in case */ 322 * i keep it here just in case */
320static const __u8 effects_table[MAX_EFFECTS][6] = { 323static const u8 effects_table[MAX_EFFECTS][6] = {
321 {0xa8, 0xe8, 0xc6, 0xd2, 0xc0, 0x00}, /* Normal */ 324 {0xa8, 0xe8, 0xc6, 0xd2, 0xc0, 0x00}, /* Normal */
322 {0xa8, 0xc8, 0xc6, 0x52, 0xc0, 0x04}, /* Repujar */ 325 {0xa8, 0xc8, 0xc6, 0x52, 0xc0, 0x04}, /* Repujar */
323 {0xa8, 0xe8, 0xc6, 0xd2, 0xc0, 0x20}, /* Monochrome */ 326 {0xa8, 0xe8, 0xc6, 0xd2, 0xc0, 0x20}, /* Monochrome */
@@ -327,90 +330,58 @@ static const __u8 effects_table[MAX_EFFECTS][6] = {
327 {0xa8, 0xc8, 0xc6, 0xd2, 0xc0, 0x40}, /* Negative */ 330 {0xa8, 0xc8, 0xc6, 0xd2, 0xc0, 0x40}, /* Negative */
328}; 331};
329 332
330static const __u8 gamma_table[GAMMA_MAX][34] = { 333static const u8 gamma_table[GAMMA_MAX][17] = {
331 {0x90, 0x00, 0x91, 0x3e, 0x92, 0x69, 0x93, 0x85, /* 0 */ 334 {0x00, 0x3e, 0x69, 0x85, 0x95, 0xa1, 0xae, 0xb9, /* 0 */
332 0x94, 0x95, 0x95, 0xa1, 0x96, 0xae, 0x97, 0xb9, 335 0xc2, 0xcb, 0xd4, 0xdb, 0xe3, 0xea, 0xf1, 0xf8,
333 0x98, 0xc2, 0x99, 0xcb, 0x9a, 0xd4, 0x9b, 0xdb, 336 0xff},
334 0x9c, 0xe3, 0x9d, 0xea, 0x9e, 0xf1, 0x9f, 0xf8, 337 {0x00, 0x33, 0x5a, 0x75, 0x85, 0x93, 0xa1, 0xad, /* 1 */
335 0xa0, 0xff}, 338 0xb7, 0xc2, 0xcb, 0xd4, 0xde, 0xe7, 0xf0, 0xf7,
336 {0x90, 0x00, 0x91, 0x33, 0x92, 0x5a, 0x93, 0x75, /* 1 */ 339 0xff},
337 0x94, 0x85, 0x95, 0x93, 0x96, 0xa1, 0x97, 0xad, 340 {0x00, 0x2f, 0x51, 0x6b, 0x7c, 0x8a, 0x99, 0xa6, /* 2 */
338 0x98, 0xb7, 0x99, 0xc2, 0x9a, 0xcb, 0x9b, 0xd4, 341 0xb1, 0xbc, 0xc6, 0xd0, 0xdb, 0xe4, 0xed, 0xf6,
339 0x9c, 0xde, 0x9D, 0xe7, 0x9e, 0xf0, 0x9f, 0xf7, 342 0xff},
340 0xa0, 0xff}, 343 {0x00, 0x29, 0x48, 0x60, 0x72, 0x81, 0x90, 0x9e, /* 3 */
341 {0x90, 0x00, 0x91, 0x2f, 0x92, 0x51, 0x93, 0x6b, /* 2 */ 344 0xaa, 0xb5, 0xbf, 0xcb, 0xd6, 0xe1, 0xeb, 0xf5,
342 0x94, 0x7c, 0x95, 0x8a, 0x96, 0x99, 0x97, 0xa6, 345 0xff},
343 0x98, 0xb1, 0x99, 0xbc, 0x9a, 0xc6, 0x9b, 0xd0, 346 {0x00, 0x23, 0x3f, 0x55, 0x68, 0x77, 0x86, 0x95, /* 4 */
344 0x9c, 0xdb, 0x9d, 0xe4, 0x9e, 0xed, 0x9f, 0xf6, 347 0xa2, 0xad, 0xb9, 0xc6, 0xd2, 0xde, 0xe9, 0xf4,
345 0xa0, 0xff}, 348 0xff},
346 {0x90, 0x00, 0x91, 0x29, 0x92, 0x48, 0x93, 0x60, /* 3 */ 349 {0x00, 0x1b, 0x33, 0x48, 0x59, 0x69, 0x79, 0x87, /* 5 */
347 0x94, 0x72, 0x95, 0x81, 0x96, 0x90, 0x97, 0x9e, 350 0x96, 0xa3, 0xb1, 0xbe, 0xcc, 0xda, 0xe7, 0xf3,
348 0x98, 0xaa, 0x99, 0xb5, 0x9a, 0xbf, 0x9b, 0xcb, 351 0xff},
349 0x9c, 0xd6, 0x9d, 0xe1, 0x9e, 0xeb, 0x9f, 0xf5, 352 {0x00, 0x02, 0x10, 0x20, 0x32, 0x40, 0x57, 0x67, /* 6 */
350 0xa0, 0xff}, 353 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee,
351 {0x90, 0x00, 0x91, 0x23, 0x92, 0x3f, 0x93, 0x55, /* 4 */ 354 0xff},
352 0x94, 0x68, 0x95, 0x77, 0x96, 0x86, 0x97, 0x95, 355 {0x00, 0x02, 0x14, 0x26, 0x38, 0x4a, 0x60, 0x70, /* 7 */
353 0x98, 0xa2, 0x99, 0xad, 0x9a, 0xb9, 0x9b, 0xc6, 356 0x80, 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0,
354 0x9c, 0xd2, 0x9d, 0xde, 0x9e, 0xe9, 0x9f, 0xf4, 357 0xff},
355 0xa0, 0xff}, 358 {0x00, 0x10, 0x22, 0x35, 0x47, 0x5a, 0x69, 0x79, /* 8 */
356 {0x90, 0x00, 0x91, 0x1b, 0x92, 0x33, 0x93, 0x48, /* 5 */ 359 0x88, 0x97, 0xa7, 0xb6, 0xc4, 0xd3, 0xe0, 0xf0,
357 0x94, 0x59, 0x95, 0x69, 0x96, 0x79, 0x97, 0x87, 360 0xff},
358 0x98, 0x96, 0x99, 0xa3, 0x9a, 0xb1, 0x9b, 0xbe, 361 {0x00, 0x10, 0x26, 0x40, 0x54, 0x65, 0x75, 0x84, /* 9 */
359 0x9c, 0xcc, 0x9d, 0xda, 0x9e, 0xe7, 0x9f, 0xf3, 362 0x93, 0xa1, 0xb0, 0xbd, 0xca, 0xd6, 0xe0, 0xf0,
360 0xa0, 0xff}, 363 0xff},
361 {0x90, 0x00, 0x91, 0x02, 0x92, 0x10, 0x93, 0x20, /* 6 */ 364 {0x00, 0x18, 0x2b, 0x44, 0x60, 0x70, 0x80, 0x8e, /* 10 */
362 0x94, 0x32, 0x95, 0x40, 0x96, 0x57, 0x97, 0x67, 365 0x9c, 0xaa, 0xb7, 0xc4, 0xd0, 0xd8, 0xe2, 0xf0,
363 0x98, 0x77, 0x99, 0x88, 0x9a, 0x99, 0x9b, 0xaa, 366 0xff},
364 0x9c, 0xbb, 0x9d, 0xcc, 0x9e, 0xdd, 0x9f, 0xee, 367 {0x00, 0x1a, 0x34, 0x52, 0x66, 0x7e, 0x8D, 0x9B, /* 11 */
365 0xa0, 0xff}, 368 0xa8, 0xb4, 0xc0, 0xcb, 0xd6, 0xe1, 0xeb, 0xf5,
366 {0x90, 0x00, 0x91, 0x02, 0x92, 0x14, 0x93, 0x26, /* 7 */ 369 0xff},
367 0x94, 0x38, 0x95, 0x4a, 0x96, 0x60, 0x97, 0x70, 370 {0x00, 0x3f, 0x5a, 0x6e, 0x7f, 0x8e, 0x9c, 0xa8, /* 12 */
368 0x98, 0x80, 0x99, 0x90, 0x9a, 0xa0, 0x9b, 0xb0, 371 0xb4, 0xbf, 0xc9, 0xd3, 0xdc, 0xe5, 0xee, 0xf6,
369 0x9c, 0xc0, 0x9D, 0xd0, 0x9e, 0xe0, 0x9f, 0xf0, 372 0xff},
370 0xa0, 0xff}, 373 {0x00, 0x54, 0x6f, 0x83, 0x93, 0xa0, 0xad, 0xb7, /* 13 */
371 {0x90, 0x00, 0x91, 0x10, 0x92, 0x22, 0x93, 0x35, /* 8 */ 374 0xc2, 0xcb, 0xd4, 0xdc, 0xe4, 0xeb, 0xf2, 0xf9,
372 0x94, 0x47, 0x95, 0x5a, 0x96, 0x69, 0x97, 0x79, 375 0xff},
373 0x98, 0x88, 0x99, 0x97, 0x9a, 0xa7, 0x9b, 0xb6, 376 {0x00, 0x6e, 0x88, 0x9a, 0xa8, 0xb3, 0xbd, 0xc6, /* 14 */
374 0x9c, 0xc4, 0x9d, 0xd3, 0x9e, 0xe0, 0x9f, 0xf0, 377 0xcf, 0xd6, 0xdd, 0xe3, 0xe9, 0xef, 0xf4, 0xfa,
375 0xa0, 0xff}, 378 0xff},
376 {0x90, 0x00, 0x91, 0x10, 0x92, 0x26, 0x93, 0x40, /* 9 */ 379 {0x00, 0x93, 0xa8, 0xb7, 0xc1, 0xca, 0xd2, 0xd8, /* 15 */
377 0x94, 0x54, 0x95, 0x65, 0x96, 0x75, 0x97, 0x84, 380 0xde, 0xe3, 0xe8, 0xed, 0xf1, 0xf5, 0xf8, 0xfc,
378 0x98, 0x93, 0x99, 0xa1, 0x9a, 0xb0, 0x9b, 0xbd, 381 0xff}
379 0x9c, 0xca, 0x9d, 0xd6, 0x9e, 0xe0, 0x9f, 0xf0,
380 0xa0, 0xff},
381 {0x90, 0x00, 0x91, 0x18, 0x92, 0x2b, 0x93, 0x44, /* 10 */
382 0x94, 0x60, 0x95, 0x70, 0x96, 0x80, 0x97, 0x8e,
383 0x98, 0x9c, 0x99, 0xaa, 0x9a, 0xb7, 0x9b, 0xc4,
384 0x9c, 0xd0, 0x9d, 0xd8, 0x9e, 0xe2, 0x9f, 0xf0,
385 0xa0, 0xff},
386 {0x90, 0x00, 0x91, 0x1a, 0x92, 0x34, 0x93, 0x52, /* 11 */
387 0x94, 0x66, 0x95, 0x7e, 0x96, 0x8D, 0x97, 0x9B,
388 0x98, 0xa8, 0x99, 0xb4, 0x9a, 0xc0, 0x9b, 0xcb,
389 0x9c, 0xd6, 0x9d, 0xe1, 0x9e, 0xeb, 0x9f, 0xf5,
390 0xa0, 0xff},
391 {0x90, 0x00, 0x91, 0x3f, 0x92, 0x5a, 0x93, 0x6e, /* 12 */
392 0x94, 0x7f, 0x95, 0x8e, 0x96, 0x9c, 0x97, 0xa8,
393 0x98, 0xb4, 0x99, 0xbf, 0x9a, 0xc9, 0x9b, 0xd3,
394 0x9c, 0xdc, 0x9d, 0xe5, 0x9e, 0xee, 0x9f, 0xf6,
395 0xa0, 0xff},
396 {0x90, 0x00, 0x91, 0x54, 0x92, 0x6f, 0x93, 0x83, /* 13 */
397 0x94, 0x93, 0x95, 0xa0, 0x96, 0xad, 0x97, 0xb7,
398 0x98, 0xc2, 0x99, 0xcb, 0x9a, 0xd4, 0x9b, 0xdc,
399 0x9c, 0xe4, 0x9d, 0xeb, 0x9e, 0xf2, 0x9f, 0xf9,
400 0xa0, 0xff},
401 {0x90, 0x00, 0x91, 0x6e, 0x92, 0x88, 0x93, 0x9a, /* 14 */
402 0x94, 0xa8, 0x95, 0xb3, 0x96, 0xbd, 0x97, 0xc6,
403 0x98, 0xcf, 0x99, 0xd6, 0x9a, 0xdd, 0x9b, 0xe3,
404 0x9c, 0xe9, 0x9d, 0xef, 0x9e, 0xf4, 0x9f, 0xfa,
405 0xa0, 0xff},
406 {0x90, 0x00, 0x91, 0x93, 0x92, 0xa8, 0x93, 0xb7, /* 15 */
407 0x94, 0xc1, 0x95, 0xca, 0x96, 0xd2, 0x97, 0xd8,
408 0x98, 0xde, 0x99, 0xe3, 0x9a, 0xe8, 0x9b, 0xed,
409 0x9c, 0xf1, 0x9d, 0xf5, 0x9e, 0xf8, 0x9f, 0xfc,
410 0xa0, 0xff}
411}; 382};
412 383
413static const __u8 tas5130a_sensor_init[][8] = { 384static const u8 tas5130a_sensor_init[][8] = {
414 {0x62, 0x08, 0x63, 0x70, 0x64, 0x1d, 0x60, 0x09}, 385 {0x62, 0x08, 0x63, 0x70, 0x64, 0x1d, 0x60, 0x09},
415 {0x62, 0x20, 0x63, 0x01, 0x64, 0x02, 0x60, 0x09}, 386 {0x62, 0x20, 0x63, 0x01, 0x64, 0x02, 0x60, 0x09},
416 {0x62, 0x07, 0x63, 0x03, 0x64, 0x00, 0x60, 0x09}, 387 {0x62, 0x07, 0x63, 0x03, 0x64, 0x00, 0x60, 0x09},
@@ -418,11 +389,11 @@ static const __u8 tas5130a_sensor_init[][8] = {
418 {}, 389 {},
419}; 390};
420 391
421static __u8 sensor_reset[] = {0x61, 0x68, 0x62, 0xff, 0x60, 0x07}; 392static u8 sensor_reset[] = {0x61, 0x68, 0x62, 0xff, 0x60, 0x07};
422 393
423/* read 1 byte */ 394/* read 1 byte */
424static int reg_r(struct gspca_dev *gspca_dev, 395static u8 reg_r(struct gspca_dev *gspca_dev,
425 __u16 index) 396 u16 index)
426{ 397{
427 usb_control_msg(gspca_dev->dev, 398 usb_control_msg(gspca_dev->dev,
428 usb_rcvctrlpipe(gspca_dev->dev, 0), 399 usb_rcvctrlpipe(gspca_dev->dev, 0),
@@ -435,7 +406,7 @@ static int reg_r(struct gspca_dev *gspca_dev,
435} 406}
436 407
437static void reg_w(struct gspca_dev *gspca_dev, 408static void reg_w(struct gspca_dev *gspca_dev,
438 __u16 index) 409 u16 index)
439{ 410{
440 usb_control_msg(gspca_dev->dev, 411 usb_control_msg(gspca_dev->dev,
441 usb_sndctrlpipe(gspca_dev->dev, 0), 412 usb_sndctrlpipe(gspca_dev->dev, 0),
@@ -446,7 +417,7 @@ static void reg_w(struct gspca_dev *gspca_dev,
446} 417}
447 418
448static void reg_w_buf(struct gspca_dev *gspca_dev, 419static void reg_w_buf(struct gspca_dev *gspca_dev,
449 const __u8 *buffer, __u16 len) 420 const u8 *buffer, u16 len)
450{ 421{
451 if (len <= USB_BUF_SZ) { 422 if (len <= USB_BUF_SZ) {
452 memcpy(gspca_dev->usb_buf, buffer, len); 423 memcpy(gspca_dev->usb_buf, buffer, len);
@@ -457,7 +428,7 @@ static void reg_w_buf(struct gspca_dev *gspca_dev,
457 0x01, 0, 428 0x01, 0,
458 gspca_dev->usb_buf, len, 500); 429 gspca_dev->usb_buf, len, 500);
459 } else { 430 } else {
460 __u8 *tmpbuf; 431 u8 *tmpbuf;
461 432
462 tmpbuf = kmalloc(len, GFP_KERNEL); 433 tmpbuf = kmalloc(len, GFP_KERNEL);
463 memcpy(tmpbuf, buffer, len); 434 memcpy(tmpbuf, buffer, len);
@@ -471,14 +442,41 @@ static void reg_w_buf(struct gspca_dev *gspca_dev,
471 } 442 }
472} 443}
473 444
445/* write values to consecutive registers */
446static void reg_w_ixbuf(struct gspca_dev *gspca_dev,
447 u8 reg,
448 const u8 *buffer, u16 len)
449{
450 int i;
451 u8 *p, *tmpbuf;
452
453 if (len * 2 <= USB_BUF_SZ)
454 p = tmpbuf = gspca_dev->usb_buf;
455 else
456 p = tmpbuf = kmalloc(len * 2, GFP_KERNEL);
457 i = len;
458 while (--i >= 0) {
459 *p++ = reg++;
460 *p++ = *buffer++;
461 }
462 usb_control_msg(gspca_dev->dev,
463 usb_sndctrlpipe(gspca_dev->dev, 0),
464 0,
465 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
466 0x01, 0,
467 tmpbuf, len * 2, 500);
468 if (len * 2 > USB_BUF_SZ)
469 kfree(tmpbuf);
470}
471
474/* Reported as OM6802*/ 472/* Reported as OM6802*/
475static void om6802_sensor_init(struct gspca_dev *gspca_dev) 473static void om6802_sensor_init(struct gspca_dev *gspca_dev)
476{ 474{
477 int i; 475 int i;
478 const __u8 *p; 476 const u8 *p;
479 __u8 byte; 477 u8 byte;
480 __u8 val[6] = {0x62, 0, 0x64, 0, 0x60, 0x05}; 478 u8 val[6] = {0x62, 0, 0x64, 0, 0x60, 0x05};
481 static const __u8 sensor_init[] = { 479 static const u8 sensor_init[] = {
482 0xdf, 0x6d, 480 0xdf, 0x6d,
483 0xdd, 0x18, 481 0xdd, 0x18,
484 0x5a, 0xe0, 482 0x5a, 0xe0,
@@ -497,7 +495,7 @@ static void om6802_sensor_init(struct gspca_dev *gspca_dev)
497 }; 495 };
498 496
499 reg_w_buf(gspca_dev, sensor_reset, sizeof sensor_reset); 497 reg_w_buf(gspca_dev, sensor_reset, sizeof sensor_reset);
500 msleep(5); 498 msleep(100);
501 i = 4; 499 i = 4;
502 while (--i > 0) { 500 while (--i > 0) {
503 byte = reg_r(gspca_dev, 0x0060); 501 byte = reg_r(gspca_dev, 0x0060);
@@ -538,20 +536,20 @@ static int sd_config(struct gspca_dev *gspca_dev,
538 struct cam *cam; 536 struct cam *cam;
539 537
540 cam = &gspca_dev->cam; 538 cam = &gspca_dev->cam;
541 cam->epaddr = 0x01;
542 539
543 cam->cam_mode = vga_mode_t16; 540 cam->cam_mode = vga_mode_t16;
544 cam->nmodes = ARRAY_SIZE(vga_mode_t16); 541 cam->nmodes = ARRAY_SIZE(vga_mode_t16);
545 542
546 sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value; 543 sd->brightness = BRIGHTNESS_DEF;
547 sd->contrast = sd_ctrls[SD_CONTRAST].qctrl.default_value; 544 sd->contrast = CONTRAST_DEF;
548 sd->colors = sd_ctrls[SD_COLOR].qctrl.default_value; 545 sd->colors = COLORS_DEF;
549 sd->gamma = GAMMA_DEF; 546 sd->gamma = GAMMA_DEF;
550 sd->mirror = sd_ctrls[SD_MIRROR].qctrl.default_value; 547 sd->autogain = AUTOGAIN_DEF;
551 sd->freq = sd_ctrls[SD_LIGHTFREQ].qctrl.default_value; 548 sd->mirror = MIRROR_DEF;
552 sd->whitebalance = sd_ctrls[SD_WHITE_BALANCE].qctrl.default_value; 549 sd->freq = FREQ_DEF;
553 sd->sharpness = sd_ctrls[SD_SHARPNESS].qctrl.default_value; 550 sd->whitebalance = WHITE_BALANCE_DEF;
554 sd->effect = sd_ctrls[SD_EFFECTS].qctrl.default_value; 551 sd->sharpness = SHARPNESS_DEF;
552 sd->effect = EFFECTS_DEF;
555 return 0; 553 return 0;
556} 554}
557 555
@@ -559,7 +557,7 @@ static void setbrightness(struct gspca_dev *gspca_dev)
559{ 557{
560 struct sd *sd = (struct sd *) gspca_dev; 558 struct sd *sd = (struct sd *) gspca_dev;
561 unsigned int brightness; 559 unsigned int brightness;
562 __u8 set6[4] = { 0x8f, 0x24, 0xc3, 0x00 }; 560 u8 set6[4] = { 0x8f, 0x24, 0xc3, 0x00 };
563 561
564 brightness = sd->brightness; 562 brightness = sd->brightness;
565 if (brightness < 7) { 563 if (brightness < 7) {
@@ -576,7 +574,7 @@ static void setcontrast(struct gspca_dev *gspca_dev)
576{ 574{
577 struct sd *sd = (struct sd *) gspca_dev; 575 struct sd *sd = (struct sd *) gspca_dev;
578 unsigned int contrast = sd->contrast; 576 unsigned int contrast = sd->contrast;
579 __u16 reg_to_write; 577 u16 reg_to_write;
580 578
581 if (contrast < 7) 579 if (contrast < 7)
582 reg_to_write = 0x8ea9 - contrast * 0x200; 580 reg_to_write = 0x8ea9 - contrast * 0x200;
@@ -589,7 +587,7 @@ static void setcontrast(struct gspca_dev *gspca_dev)
589static void setcolors(struct gspca_dev *gspca_dev) 587static void setcolors(struct gspca_dev *gspca_dev)
590{ 588{
591 struct sd *sd = (struct sd *) gspca_dev; 589 struct sd *sd = (struct sd *) gspca_dev;
592 __u16 reg_to_write; 590 u16 reg_to_write;
593 591
594 reg_to_write = 0x80bb + sd->colors * 0x100; /* was 0xc0 */ 592 reg_to_write = 0x80bb + sd->colors * 0x100; /* was 0xc0 */
595 reg_w(gspca_dev, reg_to_write); 593 reg_w(gspca_dev, reg_to_write);
@@ -600,14 +598,15 @@ static void setgamma(struct gspca_dev *gspca_dev)
600 struct sd *sd = (struct sd *) gspca_dev; 598 struct sd *sd = (struct sd *) gspca_dev;
601 599
602 PDEBUG(D_CONF, "Gamma: %d", sd->gamma); 600 PDEBUG(D_CONF, "Gamma: %d", sd->gamma);
603 reg_w_buf(gspca_dev, gamma_table[sd->gamma], sizeof gamma_table[0]); 601 reg_w_ixbuf(gspca_dev, 0x90,
602 gamma_table[sd->gamma], sizeof gamma_table[0]);
604} 603}
605 604
606static void setwhitebalance(struct gspca_dev *gspca_dev) 605static void setwhitebalance(struct gspca_dev *gspca_dev)
607{ 606{
608 struct sd *sd = (struct sd *) gspca_dev; 607 struct sd *sd = (struct sd *) gspca_dev;
609 608
610 __u8 white_balance[8] = 609 u8 white_balance[8] =
611 {0x87, 0x20, 0x88, 0x20, 0x89, 0x20, 0x80, 0x38}; 610 {0x87, 0x20, 0x88, 0x20, 0x89, 0x20, 0x80, 0x38};
612 611
613 if (sd->whitebalance) 612 if (sd->whitebalance)
@@ -619,7 +618,7 @@ static void setwhitebalance(struct gspca_dev *gspca_dev)
619static void setsharpness(struct gspca_dev *gspca_dev) 618static void setsharpness(struct gspca_dev *gspca_dev)
620{ 619{
621 struct sd *sd = (struct sd *) gspca_dev; 620 struct sd *sd = (struct sd *) gspca_dev;
622 __u16 reg_to_write; 621 u16 reg_to_write;
623 622
624 reg_to_write = 0x0aa6 + 0x1000 * sd->sharpness; 623 reg_to_write = 0x0aa6 + 0x1000 * sd->sharpness;
625 624
@@ -635,18 +634,22 @@ static int sd_init(struct gspca_dev *gspca_dev)
635 * to see the initial parameters.*/ 634 * to see the initial parameters.*/
636 struct sd *sd = (struct sd *) gspca_dev; 635 struct sd *sd = (struct sd *) gspca_dev;
637 int i; 636 int i;
638 __u8 byte, test_byte; 637 u16 sensor_id;
639 638 u8 test_byte = 0;
640 static const __u8 read_indexs[] = 639 u16 reg80, reg8e;
641 { 0x06, 0x07, 0x0a, 0x0b, 0x66, 0x80, 0x81, 0x8e, 0x8f, 0xa5, 640
642 0xa6, 0xa8, 0xbb, 0xbc, 0xc6, 0x00, 0x00 }; 641 static const u8 read_indexs[] =
643 static const __u8 n1[] = 642 { 0x0a, 0x0b, 0x66, 0x80, 0x81, 0x8e, 0x8f, 0xa5,
643 0xa6, 0xa8, 0xbb, 0xbc, 0xc6, 0x00 };
644 static const u8 n1[] =
644 {0x08, 0x03, 0x09, 0x03, 0x12, 0x04}; 645 {0x08, 0x03, 0x09, 0x03, 0x12, 0x04};
645 static const __u8 n2[] = 646 static const u8 n2[] =
646 {0x08, 0x00}; 647 {0x08, 0x00};
647 static const __u8 n3[] = 648 static const u8 n3[6] =
648 {0x61, 0x68, 0x65, 0x0a, 0x60, 0x04}; 649 {0x61, 0x68, 0x65, 0x0a, 0x60, 0x04};
649 static const __u8 n4[] = 650 static const u8 n3_other[6] =
651 {0x61, 0xc2, 0x65, 0x88, 0x60, 0x00};
652 static const u8 n4[] =
650 {0x09, 0x01, 0x12, 0x04, 0x66, 0x8a, 0x80, 0x3c, 653 {0x09, 0x01, 0x12, 0x04, 0x66, 0x8a, 0x80, 0x3c,
651 0x81, 0x22, 0x84, 0x50, 0x8a, 0x78, 0x8b, 0x68, 654 0x81, 0x22, 0x84, 0x50, 0x8a, 0x78, 0x8b, 0x68,
652 0x8c, 0x88, 0x8e, 0x33, 0x8f, 0x24, 0xaa, 0xb1, 655 0x8c, 0x88, 0x8e, 0x33, 0x8f, 0x24, 0xaa, 0xb1,
@@ -656,40 +659,61 @@ static int sd_init(struct gspca_dev *gspca_dev)
656 0x65, 0x0a, 0xbb, 0x86, 0xaf, 0x58, 0xb0, 0x68, 659 0x65, 0x0a, 0xbb, 0x86, 0xaf, 0x58, 0xb0, 0x68,
657 0x87, 0x40, 0x89, 0x2b, 0x8d, 0xff, 0x83, 0x40, 660 0x87, 0x40, 0x89, 0x2b, 0x8d, 0xff, 0x83, 0x40,
658 0xac, 0x84, 0xad, 0x86, 0xaf, 0x46}; 661 0xac, 0x84, 0xad, 0x86, 0xaf, 0x46};
659 static const __u8 nset9[4] = 662 static const u8 n4_other[] =
660 { 0x0b, 0x04, 0x0a, 0x78 }; 663 {0x66, 0x00, 0x7f, 0x00, 0x80, 0xac, 0x81, 0x69,
661 static const __u8 nset8[6] = 664 0x84, 0x40, 0x85, 0x70, 0x86, 0x20, 0x8a, 0x68,
665 0x8b, 0x58, 0x8c, 0x88, 0x8d, 0xff, 0x8e, 0xb8,
666 0x8f, 0x28, 0xa2, 0x60, 0xa5, 0x40, 0xa8, 0xa8,
667 0xac, 0x84, 0xad, 0x84, 0xae, 0x24, 0xaf, 0x56,
668 0xb0, 0x68, 0xb1, 0x00, 0xb2, 0x88, 0xbb, 0xc5,
669 0xbc, 0x4a, 0xbe, 0x36, 0xc2, 0x88, 0xc5, 0xc0,
670 0xc6, 0xda, 0xe9, 0x26, 0xeb, 0x00};
671 static const u8 nset8[6] =
662 { 0xa8, 0xf0, 0xc6, 0x88, 0xc0, 0x00 }; 672 { 0xa8, 0xf0, 0xc6, 0x88, 0xc0, 0x00 };
663 673 static const u8 nset8_other[6] =
664 byte = reg_r(gspca_dev, 0x06); 674 { 0xa8, 0xa8, 0xc6, 0xda, 0xc0, 0x00 };
665 test_byte = reg_r(gspca_dev, 0x07); 675 static const u8 nset9[4] =
666 if (byte == 0x08 && test_byte == 0x07) { 676 { 0x0b, 0x04, 0x0a, 0x78 };
667 PDEBUG(D_CONF, "sensor om6802"); 677 static const u8 nset9_other[4] =
668 sd->sensor = SENSOR_OM6802; 678 { 0x0b, 0x04, 0x0a, 0x00 };
669 } else if (byte == 0x08 && test_byte == 0x01) { 679
670 PDEBUG(D_CONF, "sensor tas5130a"); 680 sensor_id = (reg_r(gspca_dev, 0x06) << 8)
671 sd->sensor = SENSOR_TAS5130A; 681 | reg_r(gspca_dev, 0x07);
672 } else { 682 switch (sensor_id & 0xff0f) {
673 PDEBUG(D_CONF, "unknown sensor %02x %02x", byte, test_byte); 683 case 0x0801:
684 PDEBUG(D_PROBE, "sensor tas5130a");
674 sd->sensor = SENSOR_TAS5130A; 685 sd->sensor = SENSOR_TAS5130A;
686 break;
687 case 0x0803:
688 PDEBUG(D_PROBE, "sensor 'other'");
689 sd->sensor = SENSOR_OTHER;
690 break;
691 case 0x0807:
692 PDEBUG(D_PROBE, "sensor om6802");
693 sd->sensor = SENSOR_OM6802;
694 break;
695 default:
696 PDEBUG(D_ERR|D_PROBE, "unknown sensor %04x", sensor_id);
697 return -EINVAL;
675 } 698 }
676 699
677 reg_w_buf(gspca_dev, n1, sizeof n1); 700 if (sd->sensor != SENSOR_OTHER) {
678 test_byte = 0; 701 reg_w_buf(gspca_dev, n1, sizeof n1);
679 i = 5; 702 i = 5;
680 while (--i >= 0) { 703 while (--i >= 0) {
681 reg_w_buf(gspca_dev, sensor_reset, sizeof sensor_reset); 704 reg_w_buf(gspca_dev, sensor_reset, sizeof sensor_reset);
682 test_byte = reg_r(gspca_dev, 0x0063); 705 test_byte = reg_r(gspca_dev, 0x0063);
683 msleep(100); 706 msleep(100);
684 if (test_byte == 0x17) 707 if (test_byte == 0x17)
685 break; /* OK */ 708 break; /* OK */
686 } 709 }
687 if (i < 0) { 710 if (i < 0) {
688 err("Bad sensor reset %02x", test_byte); 711 err("Bad sensor reset %02x", test_byte);
689/* return -EIO; */ 712/* return -EIO; */
690/*fixme: test - continue */ 713/*fixme: test - continue */
714 }
715 reg_w_buf(gspca_dev, n2, sizeof n2);
691 } 716 }
692 reg_w_buf(gspca_dev, n2, sizeof n2);
693 717
694 i = 0; 718 i = 0;
695 while (read_indexs[i] != 0x00) { 719 while (read_indexs[i] != 0x00) {
@@ -699,21 +723,31 @@ static int sd_init(struct gspca_dev *gspca_dev)
699 i++; 723 i++;
700 } 724 }
701 725
702 reg_w_buf(gspca_dev, n3, sizeof n3); 726 if (sd->sensor != SENSOR_OTHER) {
703 reg_w_buf(gspca_dev, n4, sizeof n4); 727 reg_w_buf(gspca_dev, n3, sizeof n3);
704 reg_r(gspca_dev, 0x0080); 728 reg_w_buf(gspca_dev, n4, sizeof n4);
705 reg_w(gspca_dev, 0x2c80); 729 reg_r(gspca_dev, 0x0080);
730 reg_w(gspca_dev, 0x2c80);
731 reg80 = 0x3880;
732 reg8e = 0x338e;
733 } else {
734 reg_w_buf(gspca_dev, n3_other, sizeof n3_other);
735 reg_w_buf(gspca_dev, n4_other, sizeof n4_other);
736 sd->gamma = 5;
737 reg80 = 0xac80;
738 reg8e = 0xb88e;
739 }
706 740
707 reg_w_buf(gspca_dev, sensor_data[sd->sensor].data1, 741 reg_w_ixbuf(gspca_dev, 0xd0, sensor_data[sd->sensor].data1,
708 sizeof sensor_data[sd->sensor].data1); 742 sizeof sensor_data[sd->sensor].data1);
709 reg_w_buf(gspca_dev, sensor_data[sd->sensor].data3, 743 reg_w_ixbuf(gspca_dev, 0xc7, sensor_data[sd->sensor].data2,
710 sizeof sensor_data[sd->sensor].data3); 744 sizeof sensor_data[sd->sensor].data2);
711 reg_w_buf(gspca_dev, sensor_data[sd->sensor].data2, 745 reg_w_ixbuf(gspca_dev, 0xe0, sensor_data[sd->sensor].data2,
712 sizeof sensor_data[sd->sensor].data2); 746 sizeof sensor_data[sd->sensor].data2);
713 747
714 reg_w(gspca_dev, 0x3880); 748 reg_w(gspca_dev, reg80);
715 reg_w(gspca_dev, 0x3880); 749 reg_w(gspca_dev, reg80);
716 reg_w(gspca_dev, 0x338e); 750 reg_w(gspca_dev, reg8e);
717 751
718 setbrightness(gspca_dev); 752 setbrightness(gspca_dev);
719 setcontrast(gspca_dev); 753 setcontrast(gspca_dev);
@@ -730,16 +764,20 @@ static int sd_init(struct gspca_dev *gspca_dev)
730 sizeof sensor_data[sd->sensor].data4); 764 sizeof sensor_data[sd->sensor].data4);
731 reg_w_buf(gspca_dev, sensor_data[sd->sensor].data5, 765 reg_w_buf(gspca_dev, sensor_data[sd->sensor].data5,
732 sizeof sensor_data[sd->sensor].data5); 766 sizeof sensor_data[sd->sensor].data5);
733 reg_w_buf(gspca_dev, nset8, sizeof nset8); 767 if (sd->sensor != SENSOR_OTHER) {
734 reg_w_buf(gspca_dev, nset9, sizeof nset9); 768 reg_w_buf(gspca_dev, nset8, sizeof nset8);
735 769 reg_w_buf(gspca_dev, nset9, sizeof nset9);
736 reg_w(gspca_dev, 0x2880); 770 reg_w(gspca_dev, 0x2880);
771 } else {
772 reg_w_buf(gspca_dev, nset8_other, sizeof nset8_other);
773 reg_w_buf(gspca_dev, nset9_other, sizeof nset9_other);
774 }
737 775
738 reg_w_buf(gspca_dev, sensor_data[sd->sensor].data1, 776 reg_w_ixbuf(gspca_dev, 0xd0, sensor_data[sd->sensor].data1,
739 sizeof sensor_data[sd->sensor].data1); 777 sizeof sensor_data[sd->sensor].data1);
740 reg_w_buf(gspca_dev, sensor_data[sd->sensor].data3, 778 reg_w_ixbuf(gspca_dev, 0xc7, sensor_data[sd->sensor].data2,
741 sizeof sensor_data[sd->sensor].data3); 779 sizeof sensor_data[sd->sensor].data2);
742 reg_w_buf(gspca_dev, sensor_data[sd->sensor].data2, 780 reg_w_ixbuf(gspca_dev, 0xe0, sensor_data[sd->sensor].data2,
743 sizeof sensor_data[sd->sensor].data2); 781 sizeof sensor_data[sd->sensor].data2);
744 782
745 return 0; 783 return 0;
@@ -748,7 +786,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
748static void setflip(struct gspca_dev *gspca_dev) 786static void setflip(struct gspca_dev *gspca_dev)
749{ 787{
750 struct sd *sd = (struct sd *) gspca_dev; 788 struct sd *sd = (struct sd *) gspca_dev;
751 __u8 flipcmd[8] = 789 u8 flipcmd[8] =
752 {0x62, 0x07, 0x63, 0x03, 0x64, 0x00, 0x60, 0x09}; 790 {0x62, 0x07, 0x63, 0x03, 0x64, 0x00, 0x60, 0x09};
753 791
754 if (sd->mirror) 792 if (sd->mirror)
@@ -778,7 +816,7 @@ static void seteffect(struct gspca_dev *gspca_dev)
778static void setlightfreq(struct gspca_dev *gspca_dev) 816static void setlightfreq(struct gspca_dev *gspca_dev)
779{ 817{
780 struct sd *sd = (struct sd *) gspca_dev; 818 struct sd *sd = (struct sd *) gspca_dev;
781 __u8 freq[4] = { 0x66, 0x40, 0xa8, 0xe8 }; 819 u8 freq[4] = { 0x66, 0x40, 0xa8, 0xe8 };
782 820
783 if (sd->freq == 2) /* 60hz */ 821 if (sd->freq == 2) /* 60hz */
784 freq[1] = 0x00; 822 freq[1] = 0x00;
@@ -791,22 +829,22 @@ static void setlightfreq(struct gspca_dev *gspca_dev)
791static void poll_sensor(struct gspca_dev *gspca_dev) 829static void poll_sensor(struct gspca_dev *gspca_dev)
792{ 830{
793 struct sd *sd = (struct sd *) gspca_dev; 831 struct sd *sd = (struct sd *) gspca_dev;
794 static const __u8 poll1[] = 832 static const u8 poll1[] =
795 {0x67, 0x05, 0x68, 0x81, 0x69, 0x80, 0x6a, 0x82, 833 {0x67, 0x05, 0x68, 0x81, 0x69, 0x80, 0x6a, 0x82,
796 0x6b, 0x68, 0x6c, 0x69, 0x72, 0xd9, 0x73, 0x34, 834 0x6b, 0x68, 0x6c, 0x69, 0x72, 0xd9, 0x73, 0x34,
797 0x74, 0x32, 0x75, 0x92, 0x76, 0x00, 0x09, 0x01, 835 0x74, 0x32, 0x75, 0x92, 0x76, 0x00, 0x09, 0x01,
798 0x60, 0x14}; 836 0x60, 0x14};
799 static const __u8 poll2[] = 837 static const u8 poll2[] =
800 {0x67, 0x02, 0x68, 0x71, 0x69, 0x72, 0x72, 0xa9, 838 {0x67, 0x02, 0x68, 0x71, 0x69, 0x72, 0x72, 0xa9,
801 0x73, 0x02, 0x73, 0x02, 0x60, 0x14}; 839 0x73, 0x02, 0x73, 0x02, 0x60, 0x14};
802 static const __u8 poll3[] = 840 static const u8 poll3[] =
803 {0x87, 0x3f, 0x88, 0x20, 0x89, 0x2d}; 841 {0x87, 0x3f, 0x88, 0x20, 0x89, 0x2d};
804 static const __u8 poll4[] = 842 static const u8 poll4[] =
805 {0xa6, 0x0a, 0xea, 0xcf, 0xbe, 0x26, 0xb1, 0x5f, 843 {0xa6, 0x0a, 0xea, 0xcf, 0xbe, 0x26, 0xb1, 0x5f,
806 0xa1, 0xb1, 0xda, 0x6b, 0xdb, 0x98, 0xdf, 0x0c, 844 0xa1, 0xb1, 0xda, 0x6b, 0xdb, 0x98, 0xdf, 0x0c,
807 0xc2, 0x80, 0xc3, 0x10}; 845 0xc2, 0x80, 0xc3, 0x10};
808 846
809 if (sd->sensor != SENSOR_TAS5130A) { 847 if (sd->sensor == SENSOR_OM6802) {
810 PDEBUG(D_STREAM, "[Sensor requires polling]"); 848 PDEBUG(D_STREAM, "[Sensor requires polling]");
811 reg_w_buf(gspca_dev, poll1, sizeof poll1); 849 reg_w_buf(gspca_dev, poll1, sizeof poll1);
812 reg_w_buf(gspca_dev, poll2, sizeof poll2); 850 reg_w_buf(gspca_dev, poll2, sizeof poll2);
@@ -819,13 +857,14 @@ static int sd_start(struct gspca_dev *gspca_dev)
819{ 857{
820 struct sd *sd = (struct sd *) gspca_dev; 858 struct sd *sd = (struct sd *) gspca_dev;
821 int i, mode; 859 int i, mode;
822 __u8 t2[] = { 0x07, 0x00, 0x0d, 0x60, 0x0e, 0x80 }; 860 u8 t2[] = { 0x07, 0x00, 0x0d, 0x60, 0x0e, 0x80 };
823 static const __u8 t3[] = 861 static const u8 t3[] =
824 { 0xb3, 0x07, 0xb4, 0x00, 0xb5, 0x88, 0xb6, 0x02, 0xb7, 0x06, 862 { 0x07, 0x00, 0x88, 0x02, 0x06, 0x00, 0xe7, 0x01 };
825 0xb8, 0x00, 0xb9, 0xe7, 0xba, 0x01 };
826 863
827 mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode]. priv; 864 mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode]. priv;
828 switch (mode) { 865 switch (mode) {
866 case 0: /* 640x480 (0x00) */
867 break;
829 case 1: /* 352x288 */ 868 case 1: /* 352x288 */
830 t2[1] = 0x40; 869 t2[1] = 0x40;
831 break; 870 break;
@@ -835,14 +874,20 @@ static int sd_start(struct gspca_dev *gspca_dev)
835 case 3: /* 176x144 */ 874 case 3: /* 176x144 */
836 t2[1] = 0x50; 875 t2[1] = 0x50;
837 break; 876 break;
838 case 4: /* 160x120 */ 877 default:
878/* case 4: * 160x120 */
839 t2[1] = 0x20; 879 t2[1] = 0x20;
840 break; 880 break;
841 default: /* 640x480 (0x00) */
842 break;
843 } 881 }
844 882
845 if (sd->sensor == SENSOR_TAS5130A) { 883 switch (sd->sensor) {
884 case SENSOR_OM6802:
885 om6802_sensor_init(gspca_dev);
886 break;
887 case SENSOR_OTHER:
888 break;
889 default:
890/* case SENSOR_TAS5130A: */
846 i = 0; 891 i = 0;
847 while (tas5130a_sensor_init[i][0] != 0) { 892 while (tas5130a_sensor_init[i][0] != 0) {
848 reg_w_buf(gspca_dev, tas5130a_sensor_init[i], 893 reg_w_buf(gspca_dev, tas5130a_sensor_init[i],
@@ -854,14 +899,13 @@ static int sd_start(struct gspca_dev *gspca_dev)
854 reg_w_buf(gspca_dev, tas5130a_sensor_init[3], 899 reg_w_buf(gspca_dev, tas5130a_sensor_init[3],
855 sizeof tas5130a_sensor_init[0]); 900 sizeof tas5130a_sensor_init[0]);
856 reg_w(gspca_dev, 0x3c80); 901 reg_w(gspca_dev, 0x3c80);
857 } else { 902 break;
858 om6802_sensor_init(gspca_dev);
859 } 903 }
860 reg_w_buf(gspca_dev, sensor_data[sd->sensor].data4, 904 reg_w_buf(gspca_dev, sensor_data[sd->sensor].data4,
861 sizeof sensor_data[sd->sensor].data4); 905 sizeof sensor_data[sd->sensor].data4);
862 reg_r(gspca_dev, 0x0012); 906 reg_r(gspca_dev, 0x0012);
863 reg_w_buf(gspca_dev, t2, sizeof t2); 907 reg_w_buf(gspca_dev, t2, sizeof t2);
864 reg_w_buf(gspca_dev, t3, sizeof t3); 908 reg_w_ixbuf(gspca_dev, 0xb3, t3, sizeof t3);
865 reg_w(gspca_dev, 0x0013); 909 reg_w(gspca_dev, 0x0013);
866 msleep(15); 910 msleep(15);
867 reg_w_buf(gspca_dev, sensor_data[sd->sensor].stream, 911 reg_w_buf(gspca_dev, sensor_data[sd->sensor].stream,
@@ -885,16 +929,18 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
885 msleep(20); 929 msleep(20);
886 reg_w_buf(gspca_dev, sensor_data[sd->sensor].stream, 930 reg_w_buf(gspca_dev, sensor_data[sd->sensor].stream,
887 sizeof sensor_data[sd->sensor].stream); 931 sizeof sensor_data[sd->sensor].stream);
888 msleep(20); 932 if (sd->sensor != SENSOR_OTHER) {
889 reg_w(gspca_dev, 0x0309); 933 msleep(20);
934 reg_w(gspca_dev, 0x0309);
935 }
890} 936}
891 937
892static void sd_pkt_scan(struct gspca_dev *gspca_dev, 938static void sd_pkt_scan(struct gspca_dev *gspca_dev,
893 struct gspca_frame *frame, /* target */ 939 struct gspca_frame *frame, /* target */
894 __u8 *data, /* isoc packet */ 940 u8 *data, /* isoc packet */
895 int len) /* iso packet length */ 941 int len) /* iso packet length */
896{ 942{
897 static __u8 ffd9[] = { 0xff, 0xd9 }; 943 static u8 ffd9[] = { 0xff, 0xd9 };
898 944
899 if (data[0] == 0x5a) { 945 if (data[0] == 0x5a) {
900 /* Control Packet, after this came the header again, 946 /* Control Packet, after this came the header again,
@@ -1172,8 +1218,10 @@ static struct usb_driver sd_driver = {
1172/* -- module insert / remove -- */ 1218/* -- module insert / remove -- */
1173static int __init sd_mod_init(void) 1219static int __init sd_mod_init(void)
1174{ 1220{
1175 if (usb_register(&sd_driver) < 0) 1221 int ret;
1176 return -1; 1222 ret = usb_register(&sd_driver);
1223 if (ret < 0)
1224 return ret;
1177 PDEBUG(D_PROBE, "registered"); 1225 PDEBUG(D_PROBE, "registered");
1178 return 0; 1226 return 0;
1179} 1227}
diff --git a/drivers/media/video/gspca/tv8532.c b/drivers/media/video/gspca/tv8532.c
index 94163cceb28a..9f243d7e3110 100644
--- a/drivers/media/video/gspca/tv8532.c
+++ b/drivers/media/video/gspca/tv8532.c
@@ -31,7 +31,6 @@ struct sd {
31 struct gspca_dev gspca_dev; /* !! must be the first item */ 31 struct gspca_dev gspca_dev; /* !! must be the first item */
32 32
33 __u16 brightness; 33 __u16 brightness;
34 __u16 contrast;
35 34
36 __u8 packet; 35 __u8 packet;
37}; 36};
@@ -39,38 +38,22 @@ struct sd {
39/* V4L2 controls supported by the driver */ 38/* V4L2 controls supported by the driver */
40static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val); 39static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
41static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val); 40static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
42static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
43static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
44 41
45static struct ctrl sd_ctrls[] = { 42static struct ctrl sd_ctrls[] = {
46#define SD_BRIGHTNESS 0
47 { 43 {
48 { 44 {
49 .id = V4L2_CID_BRIGHTNESS, 45 .id = V4L2_CID_BRIGHTNESS,
50 .type = V4L2_CTRL_TYPE_INTEGER, 46 .type = V4L2_CTRL_TYPE_INTEGER,
51 .name = "Brightness", 47 .name = "Brightness",
52 .minimum = 1, 48 .minimum = 1,
53 .maximum = 0x2ff, 49 .maximum = 0x15f, /* = 352 - 1 */
54 .step = 1, 50 .step = 1,
55 .default_value = 0x18f, 51#define BRIGHTNESS_DEF 0x14c
52 .default_value = BRIGHTNESS_DEF,
56 }, 53 },
57 .set = sd_setbrightness, 54 .set = sd_setbrightness,
58 .get = sd_getbrightness, 55 .get = sd_getbrightness,
59 }, 56 },
60#define SD_CONTRAST 1
61 {
62 {
63 .id = V4L2_CID_CONTRAST,
64 .type = V4L2_CTRL_TYPE_INTEGER,
65 .name = "Contrast",
66 .minimum = 0,
67 .maximum = 0xffff,
68 .step = 1,
69 .default_value = 0x7fff,
70 },
71 .set = sd_setcontrast,
72 .get = sd_getcontrast,
73 },
74}; 57};
75 58
76static const struct v4l2_pix_format sif_mode[] = { 59static const struct v4l2_pix_format sif_mode[] = {
@@ -86,78 +69,64 @@ static const struct v4l2_pix_format sif_mode[] = {
86 .priv = 0}, 69 .priv = 0},
87}; 70};
88 71
89/* 72/* TV-8532A (ICM532A) registers (LE) */
90 * Initialization data: this is the first set-up data written to the 73#define R00_PART_CONTROL 0x00
91 * device (before the open data). 74#define LATENT_CHANGE 0x80
92 */ 75#define EXPO_CHANGE 0x04
93#define TESTCLK 0x10 /* reg 0x2c -> 0x12 //10 */ 76#define R01_TIMING_CONTROL_LOW 0x01
94#define TESTCOMP 0x90 /* reg 0x28 -> 0x80 */ 77#define CMD_EEprom_Open 0x30
95#define TESTLINE 0x81 /* reg 0x29 -> 0x81 */ 78#define CMD_EEprom_Close 0x29
96#define QCIFLINE 0x41 /* reg 0x29 -> 0x81 */ 79#define R03_TABLE_ADDR 0x03
97#define TESTPTL 0x14 /* reg 0x2D -> 0x14 */ 80#define R04_WTRAM_DATA_L 0x04
98#define TESTPTH 0x01 /* reg 0x2E -> 0x01 */ 81#define R05_WTRAM_DATA_M 0x05
99#define TESTPTBL 0x12 /* reg 0x2F -> 0x0a */ 82#define R06_WTRAM_DATA_H 0x06
100#define TESTPTBH 0x01 /* reg 0x30 -> 0x01 */ 83#define R07_TABLE_LEN 0x07
101#define ADWIDTHL 0xe8 /* reg 0x0c -> 0xe8 */ 84#define R08_RAM_WRITE_ACTION 0x08
102#define ADWIDTHH 0x03 /* reg 0x0d -> 0x03 */ 85#define R0C_AD_WIDTHL 0x0c
103#define ADHEIGHL 0x90 /* reg 0x0e -> 0x91 //93 */ 86#define R0D_AD_WIDTHH 0x0d
104#define ADHEIGHH 0x01 /* reg 0x0f -> 0x01 */ 87#define R0E_AD_HEIGHTL 0x0e
105#define EXPOL 0x8f /* reg 0x1c -> 0x8f */ 88#define R0F_AD_HEIGHTH 0x0f
106#define EXPOH 0x01 /* reg 0x1d -> 0x01 */ 89#define R10_AD_COL_BEGINL 0x10
107#define ADCBEGINL 0x44 /* reg 0x10 -> 0x46 //47 */ 90#define R11_AD_COL_BEGINH 0x11
108#define ADCBEGINH 0x00 /* reg 0x11 -> 0x00 */ 91#define MIRROR 0x04 /* [10] */
109#define ADRBEGINL 0x0a /* reg 0x14 -> 0x0b //0x0c */ 92#define R14_AD_ROW_BEGINL 0x14
110#define ADRBEGINH 0x00 /* reg 0x15 -> 0x00 */ 93#define R15_AD_ROWBEGINH 0x15
111#define TV8532_CMD_UPDATE 0x84 94#define R1C_AD_EXPOSE_TIMEL 0x1c
112 95#define R28_QUANT 0x28
113#define TV8532_EEprom_Add 0x03 96#define R29_LINE 0x29
114#define TV8532_EEprom_DataL 0x04 97#define R2C_POLARITY 0x2c
115#define TV8532_EEprom_DataM 0x05 98#define R2D_POINT 0x2d
116#define TV8532_EEprom_DataH 0x06 99#define R2E_POINTH 0x2e
117#define TV8532_EEprom_TableLength 0x07 100#define R2F_POINTB 0x2f
118#define TV8532_EEprom_Write 0x08 101#define R30_POINTBH 0x30
119#define TV8532_PART_CTRL 0x00 102#define R31_UPD 0x31
120#define TV8532_CTRL 0x01 103#define R2A_HIGH_BUDGET 0x2a
121#define TV8532_CMD_EEprom_Open 0x30 104#define R2B_LOW_BUDGET 0x2b
122#define TV8532_CMD_EEprom_Close 0x29 105#define R34_VID 0x34
123#define TV8532_UDP_UPDATE 0x31 106#define R35_VIDH 0x35
124#define TV8532_GPIO 0x39 107#define R36_PID 0x36
125#define TV8532_GPIO_OE 0x3B 108#define R37_PIDH 0x37
126#define TV8532_REQ_RegWrite 0x02 109#define R39_Test1 0x39 /* GPIO */
127#define TV8532_REQ_RegRead 0x03 110#define R3B_Test3 0x3B /* GPIO */
128 111#define R83_AD_IDH 0x83
129#define TV8532_ADWIDTH_L 0x0C 112#define R91_AD_SLOPEREG 0x91
130#define TV8532_ADWIDTH_H 0x0D 113#define R94_AD_BITCONTROL 0x94
131#define TV8532_ADHEIGHT_L 0x0E 114
132#define TV8532_ADHEIGHT_H 0x0F 115static const u8 eeprom_data[][3] = {
133#define TV8532_EXPOSURE 0x1C 116/* dataH dataM dataL */
134#define TV8532_QUANT_COMP 0x28 117 {0x01, 0x00, 0x01},
135#define TV8532_MODE_PACKET 0x29 118 {0x01, 0x80, 0x11},
136#define TV8532_SETCLK 0x2C 119 {0x05, 0x00, 0x14},
137#define TV8532_POINT_L 0x2D 120 {0x05, 0x00, 0x1c},
138#define TV8532_POINT_H 0x2E 121 {0x0d, 0x00, 0x1e},
139#define TV8532_POINTB_L 0x2F 122 {0x05, 0x00, 0x1f},
140#define TV8532_POINTB_H 0x30 123 {0x05, 0x05, 0x19},
141#define TV8532_BUDGET_L 0x2A 124 {0x05, 0x01, 0x1b},
142#define TV8532_BUDGET_H 0x2B 125 {0x05, 0x09, 0x1e},
143#define TV8532_VID_L 0x34 126 {0x0d, 0x89, 0x2e},
144#define TV8532_VID_H 0x35 127 {0x05, 0x89, 0x2f},
145#define TV8532_PID_L 0x36 128 {0x05, 0x0d, 0xd9},
146#define TV8532_PID_H 0x37 129 {0x05, 0x09, 0xf1},
147#define TV8532_DeviceID 0x83
148#define TV8532_AD_SLOPE 0x91
149#define TV8532_AD_BITCTRL 0x94
150#define TV8532_AD_COLBEGIN_L 0x10
151#define TV8532_AD_COLBEGIN_H 0x11
152#define TV8532_AD_ROWBEGIN_L 0x14
153#define TV8532_AD_ROWBEGIN_H 0x15
154
155static const __u32 tv_8532_eeprom_data[] = {
156/* add dataL dataM dataH */
157 0x00010001, 0x01018011, 0x02050014, 0x0305001c,
158 0x040d001e, 0x0505001f, 0x06050519, 0x0705011b,
159 0x0805091e, 0x090d892e, 0x0a05892f, 0x0b050dd9,
160 0x0c0509f1, 0
161}; 130};
162 131
163static int reg_r(struct gspca_dev *gspca_dev, 132static int reg_r(struct gspca_dev *gspca_dev,
@@ -165,7 +134,7 @@ static int reg_r(struct gspca_dev *gspca_dev,
165{ 134{
166 usb_control_msg(gspca_dev->dev, 135 usb_control_msg(gspca_dev->dev,
167 usb_rcvctrlpipe(gspca_dev->dev, 0), 136 usb_rcvctrlpipe(gspca_dev->dev, 0),
168 TV8532_REQ_RegRead, 137 0x03,
169 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 138 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
170 0, /* value */ 139 0, /* value */
171 index, gspca_dev->usb_buf, 1, 140 index, gspca_dev->usb_buf, 1,
@@ -174,27 +143,27 @@ static int reg_r(struct gspca_dev *gspca_dev,
174} 143}
175 144
176/* write 1 byte */ 145/* write 1 byte */
177static void reg_w_1(struct gspca_dev *gspca_dev, 146static void reg_w1(struct gspca_dev *gspca_dev,
178 __u16 index, __u8 value) 147 __u16 index, __u8 value)
179{ 148{
180 gspca_dev->usb_buf[0] = value; 149 gspca_dev->usb_buf[0] = value;
181 usb_control_msg(gspca_dev->dev, 150 usb_control_msg(gspca_dev->dev,
182 usb_sndctrlpipe(gspca_dev->dev, 0), 151 usb_sndctrlpipe(gspca_dev->dev, 0),
183 TV8532_REQ_RegWrite, 152 0x02,
184 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 153 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
185 0, /* value */ 154 0, /* value */
186 index, gspca_dev->usb_buf, 1, 500); 155 index, gspca_dev->usb_buf, 1, 500);
187} 156}
188 157
189/* write 2 bytes */ 158/* write 2 bytes */
190static void reg_w_2(struct gspca_dev *gspca_dev, 159static void reg_w2(struct gspca_dev *gspca_dev,
191 __u16 index, __u8 val1, __u8 val2) 160 u16 index, u16 value)
192{ 161{
193 gspca_dev->usb_buf[0] = val1; 162 gspca_dev->usb_buf[0] = value;
194 gspca_dev->usb_buf[1] = val2; 163 gspca_dev->usb_buf[1] = value >> 8;
195 usb_control_msg(gspca_dev->dev, 164 usb_control_msg(gspca_dev->dev,
196 usb_sndctrlpipe(gspca_dev->dev, 0), 165 usb_sndctrlpipe(gspca_dev->dev, 0),
197 TV8532_REQ_RegWrite, 166 0x02,
198 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 167 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
199 0, /* value */ 168 0, /* value */
200 index, gspca_dev->usb_buf, 2, 500); 169 index, gspca_dev->usb_buf, 2, 500);
@@ -202,32 +171,18 @@ static void reg_w_2(struct gspca_dev *gspca_dev,
202 171
203static void tv_8532WriteEEprom(struct gspca_dev *gspca_dev) 172static void tv_8532WriteEEprom(struct gspca_dev *gspca_dev)
204{ 173{
205 int i = 0; 174 int i;
206 __u8 reg, data0, data1, data2; 175
207 176 reg_w1(gspca_dev, R01_TIMING_CONTROL_LOW, CMD_EEprom_Open);
208 reg_w_1(gspca_dev, TV8532_GPIO, 0xb0); 177 for (i = 0; i < ARRAY_SIZE(eeprom_data); i++) {
209 reg_w_1(gspca_dev, TV8532_CTRL, TV8532_CMD_EEprom_Open); 178 reg_w1(gspca_dev, R03_TABLE_ADDR, i);
210/* msleep(1); */ 179 reg_w1(gspca_dev, R04_WTRAM_DATA_L, eeprom_data[i][2]);
211 while (tv_8532_eeprom_data[i]) { 180 reg_w1(gspca_dev, R05_WTRAM_DATA_M, eeprom_data[i][1]);
212 reg = (tv_8532_eeprom_data[i] & 0xff000000) >> 24; 181 reg_w1(gspca_dev, R06_WTRAM_DATA_H, eeprom_data[i][0]);
213 reg_w_1(gspca_dev, TV8532_EEprom_Add, reg); 182 reg_w1(gspca_dev, R08_RAM_WRITE_ACTION, 0);
214 /* msleep(1); */
215 data0 = (tv_8532_eeprom_data[i] & 0x000000ff);
216 reg_w_1(gspca_dev, TV8532_EEprom_DataL, data0);
217 /* msleep(1); */
218 data1 = (tv_8532_eeprom_data[i] & 0x0000ff00) >> 8;
219 reg_w_1(gspca_dev, TV8532_EEprom_DataM, data1);
220 /* msleep(1); */
221 data2 = (tv_8532_eeprom_data[i] & 0x00ff0000) >> 16;
222 reg_w_1(gspca_dev, TV8532_EEprom_DataH, data2);
223 /* msleep(1); */
224 reg_w_1(gspca_dev, TV8532_EEprom_Write, 0);
225 /* msleep(10); */
226 i++;
227 } 183 }
228 reg_w_1(gspca_dev, TV8532_EEprom_TableLength, i); 184 reg_w1(gspca_dev, R07_TABLE_LEN, i);
229/* msleep(1); */ 185 reg_w1(gspca_dev, R01_TIMING_CONTROL_LOW, CMD_EEprom_Close);
230 reg_w_1(gspca_dev, TV8532_CTRL, TV8532_CMD_EEprom_Close);
231 msleep(10); 186 msleep(10);
232} 187}
233 188
@@ -238,79 +193,76 @@ static int sd_config(struct gspca_dev *gspca_dev,
238 struct sd *sd = (struct sd *) gspca_dev; 193 struct sd *sd = (struct sd *) gspca_dev;
239 struct cam *cam; 194 struct cam *cam;
240 195
241 tv_8532WriteEEprom(gspca_dev);
242
243 cam = &gspca_dev->cam; 196 cam = &gspca_dev->cam;
244 cam->epaddr = 1;
245 cam->cam_mode = sif_mode; 197 cam->cam_mode = sif_mode;
246 cam->nmodes = sizeof sif_mode / sizeof sif_mode[0]; 198 cam->nmodes = ARRAY_SIZE(sif_mode);
247 199
248 sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value; 200 sd->brightness = BRIGHTNESS_DEF;
249 sd->contrast = sd_ctrls[SD_CONTRAST].qctrl.default_value;
250 return 0; 201 return 0;
251} 202}
252 203
253static void tv_8532ReadRegisters(struct gspca_dev *gspca_dev) 204static void tv_8532ReadRegisters(struct gspca_dev *gspca_dev)
254{ 205{
255 __u8 data; 206 int i;
256 207 static u8 reg_tb[] = {
257 data = reg_r(gspca_dev, 0x0001); 208 R0C_AD_WIDTHL,
258 PDEBUG(D_USBI, "register 0x01-> %x", data); 209 R0D_AD_WIDTHH,
259 data = reg_r(gspca_dev, 0x0002); 210 R28_QUANT,
260 PDEBUG(D_USBI, "register 0x02-> %x", data); 211 R29_LINE,
261 reg_r(gspca_dev, TV8532_ADWIDTH_L); 212 R2C_POLARITY,
262 reg_r(gspca_dev, TV8532_ADWIDTH_H); 213 R2D_POINT,
263 reg_r(gspca_dev, TV8532_QUANT_COMP); 214 R2E_POINTH,
264 reg_r(gspca_dev, TV8532_MODE_PACKET); 215 R2F_POINTB,
265 reg_r(gspca_dev, TV8532_SETCLK); 216 R30_POINTBH,
266 reg_r(gspca_dev, TV8532_POINT_L); 217 R2A_HIGH_BUDGET,
267 reg_r(gspca_dev, TV8532_POINT_H); 218 R2B_LOW_BUDGET,
268 reg_r(gspca_dev, TV8532_POINTB_L); 219 R34_VID,
269 reg_r(gspca_dev, TV8532_POINTB_H); 220 R35_VIDH,
270 reg_r(gspca_dev, TV8532_BUDGET_L); 221 R36_PID,
271 reg_r(gspca_dev, TV8532_BUDGET_H); 222 R37_PIDH,
272 reg_r(gspca_dev, TV8532_VID_L); 223 R83_AD_IDH,
273 reg_r(gspca_dev, TV8532_VID_H); 224 R10_AD_COL_BEGINL,
274 reg_r(gspca_dev, TV8532_PID_L); 225 R11_AD_COL_BEGINH,
275 reg_r(gspca_dev, TV8532_PID_H); 226 R14_AD_ROW_BEGINL,
276 reg_r(gspca_dev, TV8532_DeviceID); 227 R15_AD_ROWBEGINH,
277 reg_r(gspca_dev, TV8532_AD_COLBEGIN_L); 228 0
278 reg_r(gspca_dev, TV8532_AD_COLBEGIN_H); 229 };
279 reg_r(gspca_dev, TV8532_AD_ROWBEGIN_L); 230
280 reg_r(gspca_dev, TV8532_AD_ROWBEGIN_H); 231 i = 0;
232 do {
233 reg_r(gspca_dev, reg_tb[i]);
234 i++;
235 } while (reg_tb[i] != 0);
281} 236}
282 237
283static void tv_8532_setReg(struct gspca_dev *gspca_dev) 238static void tv_8532_setReg(struct gspca_dev *gspca_dev)
284{ 239{
285 reg_w_1(gspca_dev, TV8532_AD_COLBEGIN_L, 240 reg_w1(gspca_dev, R10_AD_COL_BEGINL, 0x44);
286 ADCBEGINL); /* 0x10 */ 241 /* begin active line */
287 reg_w_1(gspca_dev, TV8532_AD_COLBEGIN_H, 242 reg_w1(gspca_dev, R11_AD_COL_BEGINH, 0x00);
288 ADCBEGINH); /* also digital gain */ 243 /* mirror and digital gain */
289 reg_w_1(gspca_dev, TV8532_PART_CTRL, 244 reg_w1(gspca_dev, R00_PART_CONTROL, LATENT_CHANGE | EXPO_CHANGE);
290 TV8532_CMD_UPDATE); /* 0x00<-0x84 */ 245 /* = 0x84 */
291 246
292 reg_w_1(gspca_dev, TV8532_GPIO_OE, 0x0a); 247 reg_w1(gspca_dev, R3B_Test3, 0x0a); /* Test0Sel = 10 */
293 /******************************************************/ 248 /******************************************************/
294 reg_w_1(gspca_dev, TV8532_ADHEIGHT_L, ADHEIGHL); /* 0e */ 249 reg_w1(gspca_dev, R0E_AD_HEIGHTL, 0x90);
295 reg_w_1(gspca_dev, TV8532_ADHEIGHT_H, ADHEIGHH); /* 0f */ 250 reg_w1(gspca_dev, R0F_AD_HEIGHTH, 0x01);
296 reg_w_2(gspca_dev, TV8532_EXPOSURE, 251 reg_w2(gspca_dev, R1C_AD_EXPOSE_TIMEL, 0x018f);
297 EXPOL, EXPOH); /* 350d 0x014c; 1c */ 252 reg_w1(gspca_dev, R10_AD_COL_BEGINL, 0x44);
298 reg_w_1(gspca_dev, TV8532_AD_COLBEGIN_L, 253 /* begin active line */
299 ADCBEGINL); /* 0x10 */ 254 reg_w1(gspca_dev, R11_AD_COL_BEGINH, 0x00);
300 reg_w_1(gspca_dev, TV8532_AD_COLBEGIN_H, 255 /* mirror and digital gain */
301 ADCBEGINH); /* also digital gain */ 256 reg_w1(gspca_dev, R14_AD_ROW_BEGINL, 0x0a);
302 reg_w_1(gspca_dev, TV8532_AD_ROWBEGIN_L, 257
303 ADRBEGINL); /* 0x14 */ 258 reg_w1(gspca_dev, R91_AD_SLOPEREG, 0x00);
304 259 reg_w1(gspca_dev, R94_AD_BITCONTROL, 0x02);
305 reg_w_1(gspca_dev, TV8532_AD_SLOPE, 0x00); /* 0x91 */ 260
306 reg_w_1(gspca_dev, TV8532_AD_BITCTRL, 0x02); /* 0x94 */ 261 reg_w1(gspca_dev, R01_TIMING_CONTROL_LOW, CMD_EEprom_Close);
307 262
308 reg_w_1(gspca_dev, TV8532_CTRL, 263 reg_w1(gspca_dev, R91_AD_SLOPEREG, 0x00);
309 TV8532_CMD_EEprom_Close); /* 0x01 */ 264 reg_w1(gspca_dev, R00_PART_CONTROL, LATENT_CHANGE | EXPO_CHANGE);
310 265 /* = 0x84 */
311 reg_w_1(gspca_dev, TV8532_AD_SLOPE, 0x00); /* 0x91 */
312 reg_w_1(gspca_dev, TV8532_PART_CTRL,
313 TV8532_CMD_UPDATE); /* 0x00<-0x84 */
314} 266}
315 267
316static void tv_8532_PollReg(struct gspca_dev *gspca_dev) 268static void tv_8532_PollReg(struct gspca_dev *gspca_dev)
@@ -319,54 +271,55 @@ static void tv_8532_PollReg(struct gspca_dev *gspca_dev)
319 271
320 /* strange polling from tgc */ 272 /* strange polling from tgc */
321 for (i = 0; i < 10; i++) { 273 for (i = 0; i < 10; i++) {
322 reg_w_1(gspca_dev, TV8532_SETCLK, 274 reg_w1(gspca_dev, R2C_POLARITY, 0x10);
323 TESTCLK); /* 0x48; //0x08; 0x2c */ 275 reg_w1(gspca_dev, R00_PART_CONTROL,
324 reg_w_1(gspca_dev, TV8532_PART_CTRL, TV8532_CMD_UPDATE); 276 LATENT_CHANGE | EXPO_CHANGE);
325 reg_w_1(gspca_dev, TV8532_UDP_UPDATE, 0x01); /* 0x31 */ 277 reg_w1(gspca_dev, R31_UPD, 0x01);
326 } 278 }
327} 279}
328 280
329/* this function is called at probe and resume time */ 281/* this function is called at probe and resume time */
330static int sd_init(struct gspca_dev *gspca_dev) 282static int sd_init(struct gspca_dev *gspca_dev)
331{ 283{
332 reg_w_1(gspca_dev, TV8532_AD_SLOPE, 0x32); 284 tv_8532WriteEEprom(gspca_dev);
333 reg_w_1(gspca_dev, TV8532_AD_BITCTRL, 0x00); 285
286 reg_w1(gspca_dev, R91_AD_SLOPEREG, 0x32); /* slope begin 1,7V,
287 * slope rate 2 */
288 reg_w1(gspca_dev, R94_AD_BITCONTROL, 0x00);
334 tv_8532ReadRegisters(gspca_dev); 289 tv_8532ReadRegisters(gspca_dev);
335 reg_w_1(gspca_dev, TV8532_GPIO_OE, 0x0b); 290 reg_w1(gspca_dev, R3B_Test3, 0x0b);
336 reg_w_2(gspca_dev, TV8532_ADHEIGHT_L, ADHEIGHL, 291 reg_w2(gspca_dev, R0E_AD_HEIGHTL, 0x0190);
337 ADHEIGHH); /* 401d 0x0169; 0e */ 292 reg_w2(gspca_dev, R1C_AD_EXPOSE_TIMEL, 0x018f);
338 reg_w_2(gspca_dev, TV8532_EXPOSURE, EXPOL, 293 reg_w1(gspca_dev, R0C_AD_WIDTHL, 0xe8);
339 EXPOH); /* 350d 0x014c; 1c */ 294 reg_w1(gspca_dev, R0D_AD_WIDTHH, 0x03);
340 reg_w_1(gspca_dev, TV8532_ADWIDTH_L, ADWIDTHL); /* 0x20; 0x0c */
341 reg_w_1(gspca_dev, TV8532_ADWIDTH_H, ADWIDTHH); /* 0x0d */
342 295
343 /*******************************************************************/ 296 /*******************************************************************/
344 reg_w_1(gspca_dev, TV8532_QUANT_COMP, 297 reg_w1(gspca_dev, R28_QUANT, 0x90);
345 TESTCOMP); /* 0x72 compressed mode 0x28 */ 298 /* no compress - fixed Q - quant 0 */
346 reg_w_1(gspca_dev, TV8532_MODE_PACKET, 299 reg_w1(gspca_dev, R29_LINE, 0x81);
347 TESTLINE); /* 0x84; // CIF | 4 packet 0x29 */ 300 /* 0x84; // CIF | 4 packet 0x29 */
348 301
349 /************************************************/ 302 /************************************************/
350 reg_w_1(gspca_dev, TV8532_SETCLK, 303 reg_w1(gspca_dev, R2C_POLARITY, 0x10);
351 TESTCLK); /* 0x48; //0x08; 0x2c */ 304 /* 0x48; //0x08; 0x2c */
352 reg_w_1(gspca_dev, TV8532_POINT_L, 305 reg_w1(gspca_dev, R2D_POINT, 0x14);
353 TESTPTL); /* 0x38; 0x2d */ 306 /* 0x38; 0x2d */
354 reg_w_1(gspca_dev, TV8532_POINT_H, 307 reg_w1(gspca_dev, R2E_POINTH, 0x01);
355 TESTPTH); /* 0x04; 0x2e */ 308 /* 0x04; 0x2e */
356 reg_w_1(gspca_dev, TV8532_POINTB_L, 309 reg_w1(gspca_dev, R2F_POINTB, 0x12);
357 TESTPTBL); /* 0x04; 0x2f */ 310 /* 0x04; 0x2f */
358 reg_w_1(gspca_dev, TV8532_POINTB_H, 311 reg_w1(gspca_dev, R30_POINTBH, 0x01);
359 TESTPTBH); /* 0x04; 0x30 */ 312 /* 0x04; 0x30 */
360 reg_w_1(gspca_dev, TV8532_PART_CTRL, 313 reg_w1(gspca_dev, R00_PART_CONTROL, LATENT_CHANGE | EXPO_CHANGE);
361 TV8532_CMD_UPDATE); /* 0x00<-0x84 */ 314 /* 0x00<-0x84 */
362 /*************************************************/ 315 /*************************************************/
363 reg_w_1(gspca_dev, TV8532_UDP_UPDATE, 0x01); /* 0x31 */ 316 reg_w1(gspca_dev, R31_UPD, 0x01); /* update registers */
364 msleep(200); 317 msleep(200);
365 reg_w_1(gspca_dev, TV8532_UDP_UPDATE, 0x00); /* 0x31 */ 318 reg_w1(gspca_dev, R31_UPD, 0x00); /* end update */
366 /*************************************************/ 319 /*************************************************/
367 tv_8532_setReg(gspca_dev); 320 tv_8532_setReg(gspca_dev);
368 /*************************************************/ 321 /*************************************************/
369 reg_w_1(gspca_dev, TV8532_GPIO_OE, 0x0b); 322 reg_w1(gspca_dev, R3B_Test3, 0x0b); /* Test0Sel = 11 = GPIO */
370 /*************************************************/ 323 /*************************************************/
371 tv_8532_setReg(gspca_dev); 324 tv_8532_setReg(gspca_dev);
372 /*************************************************/ 325 /*************************************************/
@@ -377,11 +330,10 @@ static int sd_init(struct gspca_dev *gspca_dev)
377static void setbrightness(struct gspca_dev *gspca_dev) 330static void setbrightness(struct gspca_dev *gspca_dev)
378{ 331{
379 struct sd *sd = (struct sd *) gspca_dev; 332 struct sd *sd = (struct sd *) gspca_dev;
380 int brightness = sd->brightness;
381 333
382 reg_w_2(gspca_dev, TV8532_EXPOSURE, 334 reg_w2(gspca_dev, R1C_AD_EXPOSE_TIMEL, sd->brightness);
383 brightness >> 8, brightness); /* 1c */ 335 reg_w1(gspca_dev, R00_PART_CONTROL, LATENT_CHANGE | EXPO_CHANGE);
384 reg_w_1(gspca_dev, TV8532_PART_CTRL, TV8532_CMD_UPDATE); 336 /* 0x84 */
385} 337}
386 338
387/* -- start the camera -- */ 339/* -- start the camera -- */
@@ -389,57 +341,50 @@ static int sd_start(struct gspca_dev *gspca_dev)
389{ 341{
390 struct sd *sd = (struct sd *) gspca_dev; 342 struct sd *sd = (struct sd *) gspca_dev;
391 343
392 reg_w_1(gspca_dev, TV8532_AD_SLOPE, 0x32); 344 reg_w1(gspca_dev, R91_AD_SLOPEREG, 0x32); /* slope begin 1,7V,
393 reg_w_1(gspca_dev, TV8532_AD_BITCTRL, 0x00); 345 * slope rate 2 */
346 reg_w1(gspca_dev, R94_AD_BITCONTROL, 0x00);
394 tv_8532ReadRegisters(gspca_dev); 347 tv_8532ReadRegisters(gspca_dev);
395 reg_w_1(gspca_dev, TV8532_GPIO_OE, 0x0b); 348 reg_w1(gspca_dev, R3B_Test3, 0x0b);
396 reg_w_2(gspca_dev, TV8532_ADHEIGHT_L, 349
397 ADHEIGHL, ADHEIGHH); /* 401d 0x0169; 0e */ 350 reg_w2(gspca_dev, R0E_AD_HEIGHTL, 0x0190);
398/* reg_w_2(gspca_dev, TV8532_EXPOSURE,
399 EXPOL, EXPOH); * 350d 0x014c; 1c */
400 setbrightness(gspca_dev); 351 setbrightness(gspca_dev);
401 352
402 reg_w_1(gspca_dev, TV8532_ADWIDTH_L, ADWIDTHL); /* 0x20; 0x0c */ 353 reg_w1(gspca_dev, R0C_AD_WIDTHL, 0xe8); /* 0x20; 0x0c */
403 reg_w_1(gspca_dev, TV8532_ADWIDTH_H, ADWIDTHH); /* 0x0d */ 354 reg_w1(gspca_dev, R0D_AD_WIDTHH, 0x03);
404 355
405 /************************************************/ 356 /************************************************/
406 reg_w_1(gspca_dev, TV8532_QUANT_COMP, 357 reg_w1(gspca_dev, R28_QUANT, 0x90);
407 TESTCOMP); /* 0x72 compressed mode 0x28 */ 358 /* 0x72 compressed mode 0x28 */
408 if (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv) { 359 if (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv) {
409 /* 176x144 */ 360 /* 176x144 */
410 reg_w_1(gspca_dev, TV8532_MODE_PACKET, 361 reg_w1(gspca_dev, R29_LINE, 0x41);
411 QCIFLINE); /* 0x84; // CIF | 4 packet 0x29 */ 362 /* CIF - 2 lines/packet */
412 } else { 363 } else {
413 /* 352x288 */ 364 /* 352x288 */
414 reg_w_1(gspca_dev, TV8532_MODE_PACKET, 365 reg_w1(gspca_dev, R29_LINE, 0x81);
415 TESTLINE); /* 0x84; // CIF | 4 packet 0x29 */ 366 /* CIF - 2 lines/packet */
416 } 367 }
417 /************************************************/ 368 /************************************************/
418 reg_w_1(gspca_dev, TV8532_SETCLK, 369 reg_w1(gspca_dev, R2C_POLARITY, 0x10); /* slow clock */
419 TESTCLK); /* 0x48; //0x08; 0x2c */ 370 reg_w1(gspca_dev, R2D_POINT, 0x14);
420 reg_w_1(gspca_dev, TV8532_POINT_L, 371 reg_w1(gspca_dev, R2E_POINTH, 0x01);
421 TESTPTL); /* 0x38; 0x2d */ 372 reg_w1(gspca_dev, R2F_POINTB, 0x12);
422 reg_w_1(gspca_dev, TV8532_POINT_H, 373 reg_w1(gspca_dev, R30_POINTBH, 0x01);
423 TESTPTH); /* 0x04; 0x2e */ 374 reg_w1(gspca_dev, R00_PART_CONTROL, LATENT_CHANGE | EXPO_CHANGE);
424 reg_w_1(gspca_dev, TV8532_POINTB_L,
425 TESTPTBL); /* 0x04; 0x2f */
426 reg_w_1(gspca_dev, TV8532_POINTB_H,
427 TESTPTBH); /* 0x04; 0x30 */
428 reg_w_1(gspca_dev, TV8532_PART_CTRL,
429 TV8532_CMD_UPDATE); /* 0x00<-0x84 */
430 /************************************************/ 375 /************************************************/
431 reg_w_1(gspca_dev, TV8532_UDP_UPDATE, 0x01); /* 0x31 */ 376 reg_w1(gspca_dev, R31_UPD, 0x01); /* update registers */
432 msleep(200); 377 msleep(200);
433 reg_w_1(gspca_dev, TV8532_UDP_UPDATE, 0x00); /* 0x31 */ 378 reg_w1(gspca_dev, R31_UPD, 0x00); /* end update */
434 /************************************************/ 379 /************************************************/
435 tv_8532_setReg(gspca_dev); 380 tv_8532_setReg(gspca_dev);
436 /************************************************/ 381 /************************************************/
437 reg_w_1(gspca_dev, TV8532_GPIO_OE, 0x0b); 382 reg_w1(gspca_dev, R3B_Test3, 0x0b); /* Test0Sel = 11 = GPIO */
438 /************************************************/ 383 /************************************************/
439 tv_8532_setReg(gspca_dev); 384 tv_8532_setReg(gspca_dev);
440 /************************************************/ 385 /************************************************/
441 tv_8532_PollReg(gspca_dev); 386 tv_8532_PollReg(gspca_dev);
442 reg_w_1(gspca_dev, TV8532_UDP_UPDATE, 0x00); /* 0x31 */ 387 reg_w1(gspca_dev, R31_UPD, 0x00); /* end update */
443 388
444 gspca_dev->empty_packet = 0; /* check the empty packets */ 389 gspca_dev->empty_packet = 0; /* check the empty packets */
445 sd->packet = 0; /* ignore the first packets */ 390 sd->packet = 0; /* ignore the first packets */
@@ -449,7 +394,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
449 394
450static void sd_stopN(struct gspca_dev *gspca_dev) 395static void sd_stopN(struct gspca_dev *gspca_dev)
451{ 396{
452 reg_w_1(gspca_dev, TV8532_GPIO_OE, 0x0b); 397 reg_w1(gspca_dev, R3B_Test3, 0x0b); /* Test0Sel = 11 = GPIO */
453} 398}
454 399
455static void sd_pkt_scan(struct gspca_dev *gspca_dev, 400static void sd_pkt_scan(struct gspca_dev *gspca_dev,
@@ -473,9 +418,9 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
473 418
474 /* each packet contains: 419 /* each packet contains:
475 * - header 2 bytes 420 * - header 2 bytes
476 * - RG line 421 * - RGRG line
477 * - 4 bytes 422 * - 4 bytes
478 * - GB line 423 * - GBGB line
479 * - 4 bytes 424 * - 4 bytes
480 */ 425 */
481 gspca_frame_add(gspca_dev, packet_type0, 426 gspca_frame_add(gspca_dev, packet_type0,
@@ -484,10 +429,6 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
484 frame, data + gspca_dev->width + 6, gspca_dev->width); 429 frame, data + gspca_dev->width + 6, gspca_dev->width);
485} 430}
486 431
487static void setcontrast(struct gspca_dev *gspca_dev)
488{
489}
490
491static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val) 432static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
492{ 433{
493 struct sd *sd = (struct sd *) gspca_dev; 434 struct sd *sd = (struct sd *) gspca_dev;
@@ -506,24 +447,6 @@ static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
506 return 0; 447 return 0;
507} 448}
508 449
509static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
510{
511 struct sd *sd = (struct sd *) gspca_dev;
512
513 sd->contrast = val;
514 if (gspca_dev->streaming)
515 setcontrast(gspca_dev);
516 return 0;
517}
518
519static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
520{
521 struct sd *sd = (struct sd *) gspca_dev;
522
523 *val = sd->contrast;
524 return 0;
525}
526
527/* sub-driver description */ 450/* sub-driver description */
528static const struct sd_desc sd_desc = { 451static const struct sd_desc sd_desc = {
529 .name = MODULE_NAME, 452 .name = MODULE_NAME,
@@ -570,8 +493,10 @@ static struct usb_driver sd_driver = {
570/* -- module insert / remove -- */ 493/* -- module insert / remove -- */
571static int __init sd_mod_init(void) 494static int __init sd_mod_init(void)
572{ 495{
573 if (usb_register(&sd_driver) < 0) 496 int ret;
574 return -1; 497 ret = usb_register(&sd_driver);
498 if (ret < 0)
499 return ret;
575 PDEBUG(D_PROBE, "registered"); 500 PDEBUG(D_PROBE, "registered");
576 return 0; 501 return 0;
577} 502}
diff --git a/drivers/media/video/gspca/vc032x.c b/drivers/media/video/gspca/vc032x.c
index 0525ea51a6de..4c802fb12cd6 100644
--- a/drivers/media/video/gspca/vc032x.c
+++ b/drivers/media/video/gspca/vc032x.c
@@ -37,18 +37,21 @@ struct sd {
37 __u8 lightfreq; 37 __u8 lightfreq;
38 __u8 sharpness; 38 __u8 sharpness;
39 39
40 u8 image_offset;
41
40 char bridge; 42 char bridge;
41#define BRIDGE_VC0321 0 43#define BRIDGE_VC0321 0
42#define BRIDGE_VC0323 1 44#define BRIDGE_VC0323 1
43 char sensor; 45 char sensor;
44#define SENSOR_HV7131R 0 46#define SENSOR_HV7131R 0
45#define SENSOR_MI0360 1 47#define SENSOR_MI0360 1
46#define SENSOR_MI1320 2 48#define SENSOR_MI1310_SOC 2
47#define SENSOR_MI1310_SOC 3 49#define SENSOR_MI1320 3
48#define SENSOR_OV7660 4 50#define SENSOR_MI1320_SOC 4
49#define SENSOR_OV7670 5 51#define SENSOR_OV7660 5
50#define SENSOR_PO1200 6 52#define SENSOR_OV7670 6
51#define SENSOR_PO3130NC 7 53#define SENSOR_PO1200 7
54#define SENSOR_PO3130NC 8
52}; 55};
53 56
54/* V4L2 controls supported by the driver */ 57/* V4L2 controls supported by the driver */
@@ -149,8 +152,50 @@ static const struct v4l2_pix_format vc0323_mode[] = {
149 .sizeimage = 640 * 480 * 3 / 8 + 590, 152 .sizeimage = 640 * 480 * 3 / 8 + 590,
150 .colorspace = V4L2_COLORSPACE_JPEG, 153 .colorspace = V4L2_COLORSPACE_JPEG,
151 .priv = 0}, 154 .priv = 0},
155 {1280, 1024, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, /* mi13x0_soc only */
156 .bytesperline = 1280,
157 .sizeimage = 1280 * 1024 * 1 / 4 + 590,
158 .colorspace = V4L2_COLORSPACE_JPEG,
159 .priv = 2},
160};
161static const struct v4l2_pix_format bi_mode[] = {
162/*fixme: jeg does not work
163 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
164 .bytesperline = 320,
165 .sizeimage = 320 * 240 * 3 / 8 + 590,
166 .colorspace = V4L2_COLORSPACE_JPEG,
167 .priv = 5},
168*/
169 {320, 240, V4L2_PIX_FMT_YVYU, V4L2_FIELD_NONE,
170 .bytesperline = 320,
171 .sizeimage = 320 * 240 * 2,
172 .colorspace = V4L2_COLORSPACE_SRGB,
173 .priv = 4},
174/*
175 {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
176 .bytesperline = 640,
177 .sizeimage = 640 * 480 * 3 / 8 + 590,
178 .colorspace = V4L2_COLORSPACE_JPEG,
179 .priv = 3},
180*/
181 {640, 480, V4L2_PIX_FMT_YVYU, V4L2_FIELD_NONE,
182 .bytesperline = 640,
183 .sizeimage = 640 * 480 * 2,
184 .colorspace = V4L2_COLORSPACE_SRGB,
185 .priv = 2},
186/*
187 {1280, 1024, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
188 .bytesperline = 1280,
189 .sizeimage = 1280 * 1024 * 1 / 4 + 590,
190 .colorspace = V4L2_COLORSPACE_JPEG,
191 .priv = 1},
192*/
193 {1280, 1024, V4L2_PIX_FMT_YVYU, V4L2_FIELD_NONE,
194 .bytesperline = 1280,
195 .sizeimage = 1280 * 1024 * 2,
196 .colorspace = V4L2_COLORSPACE_SRGB,
197 .priv = 0},
152}; 198};
153
154static const struct v4l2_pix_format svga_mode[] = { 199static const struct v4l2_pix_format svga_mode[] = {
155 {800, 600, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, 200 {800, 600, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
156 .bytesperline = 800, 201 .bytesperline = 800,
@@ -400,92 +445,208 @@ static const __u8 mi0360_initQVGA_JPG[][4] = {
400static const __u8 mi1310_socinitVGA_JPG[][4] = { 445static const __u8 mi1310_socinitVGA_JPG[][4] = {
401 {0xb0, 0x03, 0x19, 0xcc}, 446 {0xb0, 0x03, 0x19, 0xcc},
402 {0xb0, 0x04, 0x02, 0xcc}, 447 {0xb0, 0x04, 0x02, 0xcc},
403 {0xb3, 0x00, 0x64, 0xcc}, 448 {0xb3, 0x00, 0x24, 0xcc},
404 {0xb3, 0x00, 0x65, 0xcc}, 449 {0xb3, 0x00, 0x25, 0xcc},
405 {0xb3, 0x05, 0x00, 0xcc}, 450 {0xb3, 0x05, 0x01, 0xcc},
406 {0xb3, 0x06, 0x00, 0xcc}, 451 {0xb3, 0x06, 0x03, 0xcc},
452 {0xb3, 0x5c, 0x01, 0xcc},
407 {0xb3, 0x08, 0x01, 0xcc}, 453 {0xb3, 0x08, 0x01, 0xcc},
408 {0xb3, 0x09, 0x0c, 0xcc}, 454 {0xb3, 0x09, 0x0c, 0xcc},
409 {0xb3, 0x34, 0x02, 0xcc}, 455 {0xb3, 0x34, 0x02, 0xcc},
410 {0xb3, 0x35, 0xdd, 0xcc}, 456 {0xb3, 0x35, 0xdd, 0xcc},
411 {0xb3, 0x02, 0x00, 0xcc},
412 {0xb3, 0x03, 0x0a, 0xcc}, 457 {0xb3, 0x03, 0x0a, 0xcc},
413 {0xb3, 0x04, 0x05, 0xcc}, 458 {0xb3, 0x04, 0x0d, 0xcc},
414 {0xb3, 0x20, 0x00, 0xcc}, 459 {0xb3, 0x20, 0x00, 0xcc},
415 {0xb3, 0x21, 0x00, 0xcc}, 460 {0xb3, 0x21, 0x00, 0xcc},
416 {0xb3, 0x22, 0x03, 0xcc}, 461 {0xb3, 0x22, 0x01, 0xcc},
417 {0xb3, 0x23, 0xc0, 0xcc}, 462 {0xb3, 0x23, 0xe0, 0xcc},
418 {0xb3, 0x14, 0x00, 0xcc}, 463 {0xb3, 0x14, 0x00, 0xcc},
419 {0xb3, 0x15, 0x00, 0xcc}, 464 {0xb3, 0x15, 0x00, 0xcc},
420 {0xb3, 0x16, 0x04, 0xcc}, 465 {0xb3, 0x16, 0x02, 0xcc},
421 {0xb3, 0x17, 0xff, 0xcc}, 466 {0xb3, 0x17, 0x7f, 0xcc},
422 {0xb3, 0x00, 0x65, 0xcc}, 467 {0xb8, 0x01, 0x7d, 0xcc},
423 {0xb8, 0x00, 0x00, 0xcc}, 468 {0xb8, 0x81, 0x09, 0xcc},
424 {0xbc, 0x00, 0xd0, 0xcc}, 469 {0xb8, 0x27, 0x20, 0xcc},
425 {0xbc, 0x01, 0x01, 0xcc}, 470 {0xb8, 0x26, 0x80, 0xcc},
426 {0xf0, 0x00, 0x02, 0xbb}, 471 {0xb3, 0x00, 0x25, 0xcc},
427 {0xc8, 0x9f, 0x0b, 0xbb}, 472 {0xb8, 0x00, 0x13, 0xcc},
428 {0x5b, 0x00, 0x01, 0xbb}, 473 {0xbc, 0x00, 0x71, 0xcc},
429 {0x2f, 0xde, 0x20, 0xbb}, 474 {0xb8, 0x81, 0x01, 0xcc},
475 {0xb8, 0x2c, 0x5a, 0xcc},
476 {0xb8, 0x2d, 0xff, 0xcc},
477 {0xb8, 0x2e, 0xee, 0xcc},
478 {0xb8, 0x2f, 0xfb, 0xcc},
479 {0xb8, 0x30, 0x52, 0xcc},
480 {0xb8, 0x31, 0xf8, 0xcc},
481 {0xb8, 0x32, 0xf1, 0xcc},
482 {0xb8, 0x33, 0xff, 0xcc},
483 {0xb8, 0x34, 0x54, 0xcc},
484 {0xb8, 0x35, 0x00, 0xcc},
485 {0xb8, 0x36, 0x00, 0xcc},
486 {0xb8, 0x37, 0x00, 0xcc},
430 {0xf0, 0x00, 0x00, 0xbb}, 487 {0xf0, 0x00, 0x00, 0xbb},
431 {0x20, 0x03, 0x02, 0xbb}, 488 {0x00, 0x01, 0x00, 0xdd},
489 {0x0d, 0x00, 0x09, 0xbb},
490 {0x0d, 0x00, 0x08, 0xbb},
432 {0xf0, 0x00, 0x01, 0xbb}, 491 {0xf0, 0x00, 0x01, 0xbb},
433 {0x05, 0x00, 0x07, 0xbb}, 492 {0x00, 0x01, 0x00, 0xdd},
434 {0x34, 0x00, 0x00, 0xbb}, 493 {0x06, 0x00, 0x14, 0xbb},
435 {0x35, 0xff, 0x00, 0xbb}, 494 {0x3a, 0x10, 0x00, 0xbb},
436 {0xdc, 0x07, 0x02, 0xbb}, 495 {0x00, 0x00, 0x10, 0xdd},
437 {0xdd, 0x3c, 0x18, 0xbb}, 496 {0x9b, 0x10, 0x00, 0xbb},
438 {0xde, 0x92, 0x6d, 0xbb}, 497 {0x00, 0x00, 0x10, 0xdd},
439 {0xdf, 0xcd, 0xb1, 0xbb},
440 {0xe0, 0xff, 0xe7, 0xbb},
441 {0x06, 0xf0, 0x0d, 0xbb},
442 {0x06, 0x70, 0x0e, 0xbb},
443 {0x4c, 0x00, 0x01, 0xbb},
444 {0x4d, 0x00, 0x01, 0xbb},
445 {0xf0, 0x00, 0x02, 0xbb},
446 {0x2e, 0x0c, 0x55, 0xbb},
447 {0x21, 0xb6, 0x6e, 0xbb},
448 {0x36, 0x30, 0x10, 0xbb},
449 {0x37, 0x00, 0xc1, 0xbb},
450 {0xf0, 0x00, 0x00, 0xbb}, 498 {0xf0, 0x00, 0x00, 0xbb},
451 {0x07, 0x00, 0x84, 0xbb}, 499 {0x00, 0x01, 0x00, 0xdd},
452 {0x08, 0x02, 0x4a, 0xbb}, 500 {0x2b, 0x00, 0x28, 0xbb},
453 {0x05, 0x01, 0x10, 0xbb}, 501 {0x2c, 0x00, 0x30, 0xbb},
454 {0x06, 0x00, 0x39, 0xbb}, 502 {0x2d, 0x00, 0x30, 0xbb},
455 {0xf0, 0x00, 0x02, 0xbb}, 503 {0x2e, 0x00, 0x28, 0xbb},
456 {0x58, 0x02, 0x67, 0xbb}, 504 {0x41, 0x00, 0xd7, 0xbb},
457 {0x57, 0x02, 0x00, 0xbb}, 505 {0x09, 0x02, 0x3a, 0xbb},
458 {0x5a, 0x02, 0x67, 0xbb}, 506 {0x0c, 0x00, 0x00, 0xbb},
459 {0x59, 0x02, 0x00, 0xbb}, 507 {0x20, 0x00, 0x00, 0xbb},
460 {0x5c, 0x12, 0x0d, 0xbb}, 508 {0x05, 0x00, 0x8c, 0xbb},
461 {0x5d, 0x16, 0x11, 0xbb}, 509 {0x06, 0x00, 0x32, 0xbb},
462 {0x39, 0x06, 0x18, 0xbb}, 510 {0x07, 0x00, 0xc6, 0xbb},
463 {0x3a, 0x06, 0x18, 0xbb}, 511 {0x08, 0x00, 0x19, 0xbb},
464 {0x3b, 0x06, 0x18, 0xbb}, 512 {0x24, 0x80, 0x6f, 0xbb},
465 {0x3c, 0x06, 0x18, 0xbb}, 513 {0xc8, 0x00, 0x0f, 0xbb},
466 {0x64, 0x7b, 0x5b, 0xbb}, 514 {0x20, 0x00, 0x0f, 0xbb},
467 {0xf0, 0x00, 0x02, 0xbb},
468 {0x36, 0x30, 0x10, 0xbb},
469 {0x37, 0x00, 0xc0, 0xbb},
470 {0xbc, 0x0e, 0x00, 0xcc},
471 {0xbc, 0x0f, 0x05, 0xcc},
472 {0xbc, 0x10, 0xc0, 0xcc},
473 {0xbc, 0x11, 0x03, 0xcc},
474 {0xb6, 0x00, 0x00, 0xcc}, 515 {0xb6, 0x00, 0x00, 0xcc},
475 {0xb6, 0x03, 0x02, 0xcc}, 516 {0xb6, 0x03, 0x02, 0xcc},
476 {0xb6, 0x02, 0x80, 0xcc}, 517 {0xb6, 0x02, 0x80, 0xcc},
477 {0xb6, 0x05, 0x01, 0xcc}, 518 {0xb6, 0x05, 0x01, 0xcc},
478 {0xb6, 0x04, 0xe0, 0xcc}, 519 {0xb6, 0x04, 0xe0, 0xcc},
479 {0xb6, 0x12, 0xf8, 0xcc}, 520 {0xb6, 0x12, 0x78, 0xcc},
480 {0xb6, 0x13, 0x25, 0xcc},
481 {0xb6, 0x18, 0x02, 0xcc}, 521 {0xb6, 0x18, 0x02, 0xcc},
482 {0xb6, 0x17, 0x58, 0xcc}, 522 {0xb6, 0x17, 0x58, 0xcc},
483 {0xb6, 0x16, 0x00, 0xcc}, 523 {0xb6, 0x16, 0x00, 0xcc},
484 {0xb6, 0x22, 0x12, 0xcc}, 524 {0xb6, 0x22, 0x12, 0xcc},
485 {0xb6, 0x23, 0x0b, 0xcc}, 525 {0xb6, 0x23, 0x0b, 0xcc},
526 {0xb3, 0x02, 0x02, 0xcc},
486 {0xbf, 0xc0, 0x39, 0xcc}, 527 {0xbf, 0xc0, 0x39, 0xcc},
487 {0xbf, 0xc1, 0x04, 0xcc}, 528 {0xbf, 0xc1, 0x04, 0xcc},
488 {0xbf, 0xcc, 0x00, 0xcc}, 529 {0xbf, 0xcc, 0x10, 0xcc},
530 {0xb9, 0x12, 0x00, 0xcc},
531 {0xb9, 0x13, 0x0a, 0xcc},
532 {0xb9, 0x14, 0x0a, 0xcc},
533 {0xb9, 0x15, 0x0a, 0xcc},
534 {0xb9, 0x16, 0x0a, 0xcc},
535 {0xb9, 0x18, 0x00, 0xcc},
536 {0xb9, 0x19, 0x0f, 0xcc},
537 {0xb9, 0x1a, 0x0f, 0xcc},
538 {0xb9, 0x1b, 0x0f, 0xcc},
539 {0xb9, 0x1c, 0x0f, 0xcc},
540 {0xb8, 0x8e, 0x00, 0xcc},
541 {0xb8, 0x8f, 0xff, 0xcc},
542 {0xb3, 0x01, 0x41, 0xcc},
543 {0x03, 0x03, 0xc0, 0xbb},
544 {0x06, 0x00, 0x10, 0xbb},
545 {0xb6, 0x12, 0xf8, 0xcc},
546 {0xb8, 0x0c, 0x20, 0xcc},
547 {0xb8, 0x0d, 0x70, 0xcc},
548 {0xb6, 0x13, 0x13, 0xcc},
549 {0x2f, 0x00, 0xC0, 0xbb},
550 {0xb8, 0xa0, 0x12, 0xcc},
551 {},
552};
553static const __u8 mi1310_socinitQVGA_JPG[][4] = {
554 {0xb0, 0x03, 0x19, 0xcc},
555 {0xb0, 0x04, 0x02, 0xcc},
556 {0xb3, 0x00, 0x24, 0xcc},
557 {0xb3, 0x00, 0x25, 0xcc},
558 {0xb3, 0x05, 0x01, 0xcc},
559 {0xb3, 0x06, 0x03, 0xcc},
560 {0xb3, 0x5c, 0x01, 0xcc},
561 {0xb3, 0x08, 0x01, 0xcc},
562 {0xb3, 0x09, 0x0c, 0xcc},
563 {0xb3, 0x34, 0x02, 0xcc},
564 {0xb3, 0x35, 0xdd, 0xcc},
565 {0xb3, 0x03, 0x0a, 0xcc},
566 {0xb3, 0x04, 0x0d, 0xcc},
567 {0xb3, 0x20, 0x00, 0xcc},
568 {0xb3, 0x21, 0x00, 0xcc},
569 {0xb3, 0x22, 0x01, 0xcc},
570 {0xb3, 0x23, 0xe0, 0xcc},
571 {0xb3, 0x14, 0x00, 0xcc},
572 {0xb3, 0x15, 0x00, 0xcc},
573 {0xb3, 0x16, 0x02, 0xcc},
574 {0xb3, 0x17, 0x7f, 0xcc},
575 {0xb8, 0x01, 0x7d, 0xcc},
576 {0xb8, 0x81, 0x09, 0xcc},
577 {0xb8, 0x27, 0x20, 0xcc},
578 {0xb8, 0x26, 0x80, 0xcc},
579 {0xb3, 0x00, 0x25, 0xcc},
580 {0xb8, 0x00, 0x13, 0xcc},
581 {0xbc, 0x00, 0xd1, 0xcc},
582 {0xb8, 0x81, 0x01, 0xcc},
583 {0xb8, 0x2c, 0x5a, 0xcc},
584 {0xb8, 0x2d, 0xff, 0xcc},
585 {0xb8, 0x2e, 0xee, 0xcc},
586 {0xb8, 0x2f, 0xfb, 0xcc},
587 {0xb8, 0x30, 0x52, 0xcc},
588 {0xb8, 0x31, 0xf8, 0xcc},
589 {0xb8, 0x32, 0xf1, 0xcc},
590 {0xb8, 0x33, 0xff, 0xcc},
591 {0xb8, 0x34, 0x54, 0xcc},
592 {0xb8, 0x35, 0x00, 0xcc},
593 {0xb8, 0x36, 0x00, 0xcc},
594 {0xb8, 0x37, 0x00, 0xcc},
595 {0xf0, 0x00, 0x00, 0xbb},
596 {0x00, 0x01, 0x00, 0xdd},
597 {0x0d, 0x00, 0x09, 0xbb},
598 {0x0d, 0x00, 0x08, 0xbb},
599 {0xf0, 0x00, 0x01, 0xbb},
600 {0x00, 0x01, 0x00, 0xdd},
601 {0x06, 0x00, 0x14, 0xbb},
602 {0x3a, 0x10, 0x00, 0xbb},
603 {0x00, 0x00, 0x10, 0xdd},
604 {0x9b, 0x10, 0x00, 0xbb},
605 {0x00, 0x00, 0x10, 0xdd},
606 {0xf0, 0x00, 0x00, 0xbb},
607 {0x00, 0x01, 0x00, 0xdd},
608 {0x2b, 0x00, 0x28, 0xbb},
609 {0x2c, 0x00, 0x30, 0xbb},
610 {0x2d, 0x00, 0x30, 0xbb},
611 {0x2e, 0x00, 0x28, 0xbb},
612 {0x41, 0x00, 0xd7, 0xbb},
613 {0x09, 0x02, 0x3a, 0xbb},
614 {0x0c, 0x00, 0x00, 0xbb},
615 {0x20, 0x00, 0x00, 0xbb},
616 {0x05, 0x00, 0x8c, 0xbb},
617 {0x06, 0x00, 0x32, 0xbb},
618 {0x07, 0x00, 0xc6, 0xbb},
619 {0x08, 0x00, 0x19, 0xbb},
620 {0x24, 0x80, 0x6f, 0xbb},
621 {0xc8, 0x00, 0x0f, 0xbb},
622 {0x20, 0x00, 0x0f, 0xbb},
623 {0xb6, 0x00, 0x00, 0xcc},
624 {0xb6, 0x03, 0x01, 0xcc},
625 {0xb6, 0x02, 0x40, 0xcc},
626 {0xb6, 0x05, 0x00, 0xcc},
627 {0xb6, 0x04, 0xf0, 0xcc},
628 {0xb6, 0x12, 0x78, 0xcc},
629 {0xb6, 0x18, 0x00, 0xcc},
630 {0xb6, 0x17, 0x96, 0xcc},
631 {0xb6, 0x16, 0x00, 0xcc},
632 {0xb6, 0x22, 0x12, 0xcc},
633 {0xb6, 0x23, 0x0b, 0xcc},
634 {0xb3, 0x02, 0x02, 0xcc},
635 {0xbf, 0xc0, 0x39, 0xcc},
636 {0xbf, 0xc1, 0x04, 0xcc},
637 {0xbf, 0xcc, 0x10, 0xcc},
638 {0xb9, 0x12, 0x00, 0xcc},
639 {0xb9, 0x13, 0x0a, 0xcc},
640 {0xb9, 0x14, 0x0a, 0xcc},
641 {0xb9, 0x15, 0x0a, 0xcc},
642 {0xb9, 0x16, 0x0a, 0xcc},
643 {0xb9, 0x18, 0x00, 0xcc},
644 {0xb9, 0x19, 0x0f, 0xcc},
645 {0xb9, 0x1a, 0x0f, 0xcc},
646 {0xb9, 0x1b, 0x0f, 0xcc},
647 {0xb9, 0x1c, 0x0f, 0xcc},
648 {0xb8, 0x8e, 0x00, 0xcc},
649 {0xb8, 0x8f, 0xff, 0xcc},
489 {0xbc, 0x02, 0x18, 0xcc}, 650 {0xbc, 0x02, 0x18, 0xcc},
490 {0xbc, 0x03, 0x50, 0xcc}, 651 {0xbc, 0x03, 0x50, 0xcc},
491 {0xbc, 0x04, 0x18, 0xcc}, 652 {0xbc, 0x04, 0x18, 0xcc},
@@ -496,131 +657,123 @@ static const __u8 mi1310_socinitVGA_JPG[][4] = {
496 {0xbc, 0x0a, 0x10, 0xcc}, 657 {0xbc, 0x0a, 0x10, 0xcc},
497 {0xbc, 0x0b, 0x00, 0xcc}, 658 {0xbc, 0x0b, 0x00, 0xcc},
498 {0xbc, 0x0c, 0x00, 0xcc}, 659 {0xbc, 0x0c, 0x00, 0xcc},
499 {0xb3, 0x5c, 0x01, 0xcc},
500 {0xf0, 0x00, 0x01, 0xbb},
501 {0x80, 0x00, 0x03, 0xbb},
502 {0x81, 0xc7, 0x14, 0xbb},
503 {0x82, 0xeb, 0xe8, 0xbb},
504 {0x83, 0xfe, 0xf4, 0xbb},
505 {0x84, 0xcd, 0x10, 0xbb},
506 {0x85, 0xf3, 0xee, 0xbb},
507 {0x86, 0xff, 0xf1, 0xbb},
508 {0x87, 0xcd, 0x10, 0xbb},
509 {0x88, 0xf3, 0xee, 0xbb},
510 {0x89, 0x01, 0xf1, 0xbb},
511 {0x8a, 0xe5, 0x17, 0xbb},
512 {0x8b, 0xe8, 0xe2, 0xbb},
513 {0x8c, 0xf7, 0xed, 0xbb},
514 {0x8d, 0x00, 0xff, 0xbb},
515 {0x8e, 0xec, 0x10, 0xbb},
516 {0x8f, 0xf0, 0xed, 0xbb},
517 {0x90, 0xf9, 0xf2, 0xbb},
518 {0x91, 0x00, 0x00, 0xbb},
519 {0x92, 0xe9, 0x0d, 0xbb},
520 {0x93, 0xf4, 0xf2, 0xbb},
521 {0x94, 0xfb, 0xf5, 0xbb},
522 {0x95, 0x00, 0xff, 0xbb},
523 {0xb6, 0x0f, 0x08, 0xbb},
524 {0xb7, 0x3d, 0x16, 0xbb},
525 {0xb8, 0x0c, 0x04, 0xbb},
526 {0xb9, 0x1c, 0x07, 0xbb},
527 {0xba, 0x0a, 0x03, 0xbb},
528 {0xbb, 0x1b, 0x09, 0xbb},
529 {0xbc, 0x17, 0x0d, 0xbb},
530 {0xbd, 0x23, 0x1d, 0xbb},
531 {0xbe, 0x00, 0x28, 0xbb},
532 {0xbf, 0x11, 0x09, 0xbb},
533 {0xc0, 0x16, 0x15, 0xbb},
534 {0xc1, 0x00, 0x1b, 0xbb},
535 {0xc2, 0x0e, 0x07, 0xbb},
536 {0xc3, 0x14, 0x10, 0xbb},
537 {0xc4, 0x00, 0x17, 0xbb},
538 {0x06, 0x74, 0x8e, 0xbb},
539 {0xf0, 0x00, 0x01, 0xbb},
540 {0x06, 0xf4, 0x8e, 0xbb},
541 {0x00, 0x00, 0x50, 0xdd},
542 {0x06, 0x74, 0x8e, 0xbb},
543 {0xf0, 0x00, 0x02, 0xbb},
544 {0x24, 0x50, 0x20, 0xbb},
545 {0xf0, 0x00, 0x02, 0xbb},
546 {0x34, 0x0c, 0x50, 0xbb},
547 {0xb3, 0x01, 0x41, 0xcc}, 660 {0xb3, 0x01, 0x41, 0xcc},
548 {0xf0, 0x00, 0x00, 0xbb},
549 {0x03, 0x03, 0xc0, 0xbb}, 661 {0x03, 0x03, 0xc0, 0xbb},
662 {0x06, 0x00, 0x10, 0xbb},
663 {0xb6, 0x12, 0xf8, 0xcc},
664 {0xb8, 0x0c, 0x20, 0xcc},
665 {0xb8, 0x0d, 0x70, 0xcc},
666 {0xb6, 0x13, 0x13, 0xcc},
667 {0x2f, 0x00, 0xC0, 0xbb},
668 {0xb8, 0xa0, 0x12, 0xcc},
550 {}, 669 {},
551}; 670};
552static const __u8 mi1310_socinitQVGA_JPG[][4] = { 671static const u8 mi1310_soc_InitSXGA_JPG[][4] = {
553 {0xb0, 0x03, 0x19, 0xcc}, {0xb0, 0x04, 0x02, 0xcc}, 672 {0xb0, 0x03, 0x19, 0xcc},
554 {0xb3, 0x00, 0x64, 0xcc}, {0xb3, 0x00, 0x65, 0xcc}, 673 {0xb0, 0x04, 0x02, 0xcc},
555 {0xb3, 0x05, 0x00, 0xcc}, {0xb3, 0x06, 0x00, 0xcc}, 674 {0xb3, 0x00, 0x24, 0xcc},
556 {0xb3, 0x08, 0x01, 0xcc}, {0xb3, 0x09, 0x0c, 0xcc}, 675 {0xb3, 0x00, 0x25, 0xcc},
557 {0xb3, 0x34, 0x02, 0xcc}, {0xb3, 0x35, 0xdd, 0xcc}, 676 {0xb3, 0x05, 0x00, 0xcc},
558 {0xb3, 0x02, 0x00, 0xcc}, {0xb3, 0x03, 0x0a, 0xcc}, 677 {0xb3, 0x06, 0x01, 0xcc},
559 {0xb3, 0x04, 0x05, 0xcc}, {0xb3, 0x20, 0x00, 0xcc}, 678 {0xb3, 0x5c, 0x01, 0xcc},
560 {0xb3, 0x21, 0x00, 0xcc}, {0xb3, 0x22, 0x03, 0xcc}, 679 {0xb3, 0x08, 0x01, 0xcc},
561 {0xb3, 0x23, 0xc0, 0xcc}, {0xb3, 0x14, 0x00, 0xcc}, 680 {0xb3, 0x09, 0x0c, 0xcc},
562 {0xb3, 0x15, 0x00, 0xcc}, {0xb3, 0x16, 0x04, 0xcc}, 681 {0xb3, 0x34, 0x02, 0xcc},
563 {0xb3, 0x17, 0xff, 0xcc}, {0xb3, 0x00, 0x65, 0xcc}, 682 {0xb3, 0x35, 0xdd, 0xcc},
564 {0xb8, 0x00, 0x00, 0xcc}, {0xbc, 0x00, 0xf0, 0xcc}, 683 {0xb3, 0x03, 0x0a, 0xcc},
565 {0xbc, 0x01, 0x01, 0xcc}, {0xf0, 0x00, 0x02, 0xbb}, 684 {0xb3, 0x04, 0x0d, 0xcc},
566 {0xc8, 0x9f, 0x0b, 0xbb}, {0x5b, 0x00, 0x01, 0xbb}, 685 {0xb3, 0x20, 0x00, 0xcc},
567 {0x2f, 0xde, 0x20, 0xbb}, {0xf0, 0x00, 0x00, 0xbb}, 686 {0xb3, 0x21, 0x00, 0xcc},
568 {0x20, 0x03, 0x02, 0xbb}, {0xf0, 0x00, 0x01, 0xbb}, 687 {0xb3, 0x22, 0x04, 0xcc},
569 {0x05, 0x00, 0x07, 0xbb}, {0x34, 0x00, 0x00, 0xbb}, 688 {0xb3, 0x23, 0x00, 0xcc},
570 {0x35, 0xff, 0x00, 0xbb}, {0xdc, 0x07, 0x02, 0xbb}, 689 {0xb3, 0x14, 0x00, 0xcc},
571 {0xdd, 0x3c, 0x18, 0xbb}, {0xde, 0x92, 0x6d, 0xbb}, 690 {0xb3, 0x15, 0x00, 0xcc},
572 {0xdf, 0xcd, 0xb1, 0xbb}, {0xe0, 0xff, 0xe7, 0xbb}, 691 {0xb3, 0x16, 0x04, 0xcc},
573 {0x06, 0xf0, 0x0d, 0xbb}, {0x06, 0x70, 0x0e, 0xbb}, 692 {0xb3, 0x17, 0xff, 0xcc},
574 {0x4c, 0x00, 0x01, 0xbb}, {0x4d, 0x00, 0x01, 0xbb}, 693 {0xb8, 0x01, 0x7d, 0xcc},
575 {0xf0, 0x00, 0x02, 0xbb}, {0x2e, 0x0c, 0x55, 0xbb}, 694 {0xb8, 0x81, 0x09, 0xcc},
576 {0x21, 0xb6, 0x6e, 0xbb}, {0x36, 0x30, 0x10, 0xbb}, 695 {0xb8, 0x27, 0x20, 0xcc},
577 {0x37, 0x00, 0xc1, 0xbb}, {0xf0, 0x00, 0x00, 0xbb}, 696 {0xb8, 0x26, 0x80, 0xcc},
578 {0x07, 0x00, 0x84, 0xbb}, {0x08, 0x02, 0x4a, 0xbb}, 697 {0xb8, 0x06, 0x00, 0xcc},
579 {0x05, 0x01, 0x10, 0xbb}, {0x06, 0x00, 0x39, 0xbb}, 698 {0xb8, 0x07, 0x05, 0xcc},
580 {0xf0, 0x00, 0x02, 0xbb}, {0x58, 0x02, 0x67, 0xbb}, 699 {0xb8, 0x08, 0x00, 0xcc},
581 {0x57, 0x02, 0x00, 0xbb}, {0x5a, 0x02, 0x67, 0xbb}, 700 {0xb8, 0x09, 0x04, 0xcc},
582 {0x59, 0x02, 0x00, 0xbb}, {0x5c, 0x12, 0x0d, 0xbb}, 701 {0xb3, 0x00, 0x25, 0xcc},
583 {0x5d, 0x16, 0x11, 0xbb}, {0x39, 0x06, 0x18, 0xbb}, 702 {0xb8, 0x00, 0x11, 0xcc},
584 {0x3a, 0x06, 0x18, 0xbb}, {0x3b, 0x06, 0x18, 0xbb}, 703 {0xbc, 0x00, 0x71, 0xcc},
585 {0x3c, 0x06, 0x18, 0xbb}, {0x64, 0x7b, 0x5b, 0xbb}, 704 {0xb8, 0x81, 0x01, 0xcc},
586 {0xf0, 0x00, 0x02, 0xbb}, {0x36, 0x30, 0x10, 0xbb}, 705 {0xb8, 0x2c, 0x5a, 0xcc},
587 {0x37, 0x00, 0xc0, 0xbb}, {0xbc, 0x0e, 0x00, 0xcc}, 706 {0xb8, 0x2d, 0xff, 0xcc},
588 {0xbc, 0x0f, 0x05, 0xcc}, {0xbc, 0x10, 0xc0, 0xcc}, 707 {0xb8, 0x2e, 0xee, 0xcc},
589 {0xbc, 0x11, 0x03, 0xcc}, {0xb6, 0x00, 0x00, 0xcc}, 708 {0xb8, 0x2f, 0xfb, 0xcc},
590 {0xb6, 0x03, 0x01, 0xcc}, {0xb6, 0x02, 0x40, 0xcc}, 709 {0xb8, 0x30, 0x52, 0xcc},
591 {0xb6, 0x05, 0x00, 0xcc}, {0xb6, 0x04, 0xf0, 0xcc}, 710 {0xb8, 0x31, 0xf8, 0xcc},
592 {0xb6, 0x12, 0xf8, 0xcc}, {0xb6, 0x13, 0x25, 0xcc}, 711 {0xb8, 0x32, 0xf1, 0xcc},
593 {0xb6, 0x18, 0x00, 0xcc}, {0xb6, 0x17, 0x96, 0xcc}, 712 {0xb8, 0x33, 0xff, 0xcc},
594 {0xb6, 0x16, 0x00, 0xcc}, {0xb6, 0x22, 0x12, 0xcc}, 713 {0xb8, 0x34, 0x54, 0xcc},
595 {0xb6, 0x23, 0x0b, 0xcc}, {0xbf, 0xc0, 0x39, 0xcc}, 714 {0xf0, 0x00, 0x00, 0xbb},
596 {0xbf, 0xc1, 0x04, 0xcc}, {0xbf, 0xcc, 0x00, 0xcc}, 715 {0x00, 0x01, 0x00, 0xdd},
597 {0xb3, 0x5c, 0x01, 0xcc}, {0xf0, 0x00, 0x01, 0xbb}, 716 {0x0d, 0x00, 0x09, 0xbb},
598 {0x80, 0x00, 0x03, 0xbb}, {0x81, 0xc7, 0x14, 0xbb}, 717 {0x0d, 0x00, 0x08, 0xbb},
599 {0x82, 0xeb, 0xe8, 0xbb}, {0x83, 0xfe, 0xf4, 0xbb}, 718 {0xf0, 0x00, 0x01, 0xbb},
600 {0x84, 0xcd, 0x10, 0xbb}, {0x85, 0xf3, 0xee, 0xbb}, 719 {0x00, 0x01, 0x00, 0xdd},
601 {0x86, 0xff, 0xf1, 0xbb}, {0x87, 0xcd, 0x10, 0xbb}, 720 {0x06, 0x00, 0x14, 0xbb},
602 {0x88, 0xf3, 0xee, 0xbb}, {0x89, 0x01, 0xf1, 0xbb}, 721 {0x3a, 0x10, 0x00, 0xbb},
603 {0x8a, 0xe5, 0x17, 0xbb}, {0x8b, 0xe8, 0xe2, 0xbb}, 722 {0x00, 0x00, 0x10, 0xdd},
604 {0x8c, 0xf7, 0xed, 0xbb}, {0x8d, 0x00, 0xff, 0xbb}, 723 {0x9b, 0x10, 0x00, 0xbb},
605 {0x8e, 0xec, 0x10, 0xbb}, {0x8f, 0xf0, 0xed, 0xbb}, 724 {0x00, 0x00, 0x10, 0xdd},
606 {0x90, 0xf9, 0xf2, 0xbb}, {0x91, 0x00, 0x00, 0xbb}, 725 {0xf0, 0x00, 0x00, 0xbb},
607 {0x92, 0xe9, 0x0d, 0xbb}, {0x93, 0xf4, 0xf2, 0xbb}, 726 {0x00, 0x01, 0x00, 0xdd},
608 {0x94, 0xfb, 0xf5, 0xbb}, {0x95, 0x00, 0xff, 0xbb}, 727 {0x2b, 0x00, 0x28, 0xbb},
609 {0xb6, 0x0f, 0x08, 0xbb}, {0xb7, 0x3d, 0x16, 0xbb}, 728 {0x2c, 0x00, 0x30, 0xbb},
610 {0xb8, 0x0c, 0x04, 0xbb}, {0xb9, 0x1c, 0x07, 0xbb}, 729 {0x2d, 0x00, 0x30, 0xbb},
611 {0xba, 0x0a, 0x03, 0xbb}, {0xbb, 0x1b, 0x09, 0xbb}, 730 {0x2e, 0x00, 0x28, 0xbb},
612 {0xbc, 0x17, 0x0d, 0xbb}, {0xbd, 0x23, 0x1d, 0xbb}, 731 {0x41, 0x00, 0xd7, 0xbb},
613 {0xbe, 0x00, 0x28, 0xbb}, {0xbf, 0x11, 0x09, 0xbb}, 732 {0x09, 0x02, 0x3a, 0xbb},
614 {0xc0, 0x16, 0x15, 0xbb}, {0xc1, 0x00, 0x1b, 0xbb}, 733 {0x0c, 0x00, 0x00, 0xbb},
615 {0xc2, 0x0e, 0x07, 0xbb}, {0xc3, 0x14, 0x10, 0xbb}, 734 {0x20, 0x00, 0x00, 0xbb},
616 {0xc4, 0x00, 0x17, 0xbb}, {0x06, 0x74, 0x8e, 0xbb}, 735 {0x05, 0x00, 0x8c, 0xbb},
617 {0xf0, 0x00, 0x01, 0xbb}, {0x06, 0xf4, 0x8e, 0xbb}, 736 {0x06, 0x00, 0x32, 0xbb},
618 {0x00, 0x00, 0x50, 0xdd}, {0x06, 0x74, 0x8e, 0xbb}, 737 {0x07, 0x00, 0xc6, 0xbb},
619 {0xf0, 0x00, 0x02, 0xbb}, {0x24, 0x50, 0x20, 0xbb}, 738 {0x08, 0x00, 0x19, 0xbb},
620 {0xf0, 0x00, 0x02, 0xbb}, {0x34, 0x0c, 0x50, 0xbb}, 739 {0x24, 0x80, 0x6f, 0xbb},
621 {0xb3, 0x01, 0x41, 0xcc}, {0xf0, 0x00, 0x00, 0xbb}, 740 {0xc8, 0x00, 0x0f, 0xbb},
622 {0x03, 0x03, 0xc0, 0xbb}, 741 {0x20, 0x00, 0x03, 0xbb},
623 {}, 742 {0xb6, 0x00, 0x00, 0xcc},
743 {0xb6, 0x03, 0x05, 0xcc},
744 {0xb6, 0x02, 0x00, 0xcc},
745 {0xb6, 0x05, 0x04, 0xcc},
746 {0xb6, 0x04, 0x00, 0xcc},
747 {0xb6, 0x12, 0xf8, 0xcc},
748 {0xb6, 0x18, 0x0a, 0xcc},
749 {0xb6, 0x17, 0x00, 0xcc},
750 {0xb6, 0x16, 0x00, 0xcc},
751 {0xb6, 0x22, 0x12, 0xcc},
752 {0xb6, 0x23, 0x0b, 0xcc},
753 {0xb3, 0x02, 0x02, 0xcc},
754 {0xbf, 0xc0, 0x39, 0xcc},
755 {0xbf, 0xc1, 0x04, 0xcc},
756 {0xbf, 0xcc, 0x10, 0xcc},
757 {0xb9, 0x12, 0x00, 0xcc},
758 {0xb9, 0x13, 0x14, 0xcc},
759 {0xb9, 0x14, 0x14, 0xcc},
760 {0xb9, 0x15, 0x14, 0xcc},
761 {0xb9, 0x16, 0x14, 0xcc},
762 {0xb9, 0x18, 0x00, 0xcc},
763 {0xb9, 0x19, 0x1e, 0xcc},
764 {0xb9, 0x1a, 0x1e, 0xcc},
765 {0xb9, 0x1b, 0x1e, 0xcc},
766 {0xb9, 0x1c, 0x1e, 0xcc},
767 {0xb3, 0x01, 0x41, 0xcc},
768 {0xb8, 0x8e, 0x00, 0xcc},
769 {0xb8, 0x8f, 0xff, 0xcc},
770 {0xb6, 0x12, 0xf8, 0xcc},
771 {0xb8, 0x0c, 0x20, 0xcc},
772 {0xb8, 0x0d, 0x70, 0xcc},
773 {0xb6, 0x13, 0x13, 0xcc},
774 {0x2f, 0x00, 0xC0, 0xbb},
775 {0xb8, 0xa0, 0x12, 0xcc},
776 {}
624}; 777};
625 778
626static const __u8 mi1320_gamma[17] = { 779static const __u8 mi1320_gamma[17] = {
@@ -778,6 +931,722 @@ static const __u8 mi1320_initQVGA_data[][4] = {
778 {} 931 {}
779}; 932};
780 933
934static const u8 mi1320_soc_InitVGA[][4] = {
935 {0xb3, 0x01, 0x01, 0xcc},
936 {0xb0, 0x03, 0x19, 0xcc},
937 {0xb0, 0x04, 0x02, 0xcc},
938 {0x00, 0x00, 0x30, 0xdd},
939 {0xb3, 0x00, 0x64, 0xcc},
940 {0xb3, 0x00, 0x67, 0xcc},
941 {0xb3, 0x05, 0x01, 0xcc},
942 {0xb3, 0x06, 0x01, 0xcc},
943 {0xb3, 0x08, 0x01, 0xcc},
944 {0xb3, 0x09, 0x0c, 0xcc},
945 {0xb3, 0x34, 0x02, 0xcc},
946 {0xb3, 0x35, 0xc8, 0xcc},
947 {0xb3, 0x02, 0x00, 0xcc},
948 {0xb3, 0x03, 0x0a, 0xcc},
949 {0xb3, 0x04, 0x05, 0xcc},
950 {0xb3, 0x20, 0x00, 0xcc},
951 {0xb3, 0x21, 0x00, 0xcc},
952 {0xb3, 0x22, 0x01, 0xcc},
953 {0xb3, 0x23, 0xe0, 0xcc},
954 {0xb3, 0x14, 0x00, 0xcc},
955 {0xb3, 0x15, 0x00, 0xcc},
956 {0xb3, 0x16, 0x02, 0xcc},
957 {0xb3, 0x17, 0x7f, 0xcc},
958 {0xb3, 0x00, 0x67, 0xcc},
959 {0xb8, 0x00, 0x00, 0xcc},
960 {0xbc, 0x00, 0x71, 0xcc},
961 {0xbc, 0x01, 0x01, 0xcc},
962 {0xb3, 0x5c, 0x01, 0xcc},
963 {0xf0, 0x00, 0x02, 0xbb},
964 {0x00, 0x00, 0x10, 0xdd},
965 {0xc8, 0x00, 0x00, 0xbb},
966 {0x00, 0x00, 0x30, 0xdd},
967 {0xf0, 0x00, 0x00, 0xbb},
968 {0x00, 0x00, 0x10, 0xdd},
969 {0x07, 0x00, 0xe0, 0xbb},
970 {0x08, 0x00, 0x0b, 0xbb},
971 {0x21, 0x00, 0x0c, 0xbb},
972 {0x20, 0x01, 0x03, 0xbb},
973 {0xbf, 0xc0, 0x26, 0xcc},
974 {0xbf, 0xc1, 0x02, 0xcc},
975 {0xbf, 0xcc, 0x04, 0xcc},
976 {0xb3, 0x01, 0x41, 0xcc},
977 {0xf0, 0x00, 0x00, 0xbb},
978 {0x05, 0x01, 0x78, 0xbb},
979 {0x06, 0x00, 0x11, 0xbb},
980 {0x07, 0x01, 0x42, 0xbb},
981 {0x08, 0x00, 0x11, 0xbb},
982 {0x20, 0x01, 0x03, 0xbb},
983 {0x21, 0x80, 0x00, 0xbb},
984 {0x22, 0x0d, 0x0f, 0xbb},
985 {0x24, 0x80, 0x00, 0xbb},
986 {0x59, 0x00, 0xff, 0xbb},
987 {0xf0, 0x00, 0x02, 0xbb},
988 {0x39, 0x03, 0xca, 0xbb},
989 {0x3a, 0x06, 0x80, 0xbb},
990 {0x3b, 0x01, 0x52, 0xbb},
991 {0x3c, 0x05, 0x40, 0xbb},
992 {0x57, 0x01, 0x9c, 0xbb},
993 {0x58, 0x01, 0xee, 0xbb},
994 {0x59, 0x00, 0xf0, 0xbb},
995 {0x5a, 0x01, 0x20, 0xbb},
996 {0x5c, 0x1d, 0x17, 0xbb},
997 {0x5d, 0x22, 0x1c, 0xbb},
998 {0x64, 0x1e, 0x1c, 0xbb},
999 {0x5b, 0x00, 0x00, 0xbb},
1000 {0xf0, 0x00, 0x02, 0xbb},
1001 {0x22, 0xa0, 0x78, 0xbb},
1002 {0x23, 0xa0, 0x78, 0xbb},
1003 {0x24, 0x7f, 0x00, 0xbb},
1004 {0x28, 0xea, 0x02, 0xbb},
1005 {0x29, 0x86, 0x7a, 0xbb},
1006 {0x5e, 0x52, 0x4c, 0xbb},
1007 {0x5f, 0x20, 0x24, 0xbb},
1008 {0x60, 0x00, 0x02, 0xbb},
1009 {0x02, 0x00, 0xee, 0xbb},
1010 {0x03, 0x39, 0x23, 0xbb},
1011 {0x04, 0x07, 0x24, 0xbb},
1012 {0x09, 0x00, 0xc0, 0xbb},
1013 {0x0a, 0x00, 0x79, 0xbb},
1014 {0x0b, 0x00, 0x04, 0xbb},
1015 {0x0c, 0x00, 0x5c, 0xbb},
1016 {0x0d, 0x00, 0xd9, 0xbb},
1017 {0x0e, 0x00, 0x53, 0xbb},
1018 {0x0f, 0x00, 0x21, 0xbb},
1019 {0x10, 0x00, 0xa4, 0xbb},
1020 {0x11, 0x00, 0xe5, 0xbb},
1021 {0x15, 0x00, 0x00, 0xbb},
1022 {0x16, 0x00, 0x00, 0xbb},
1023 {0x17, 0x00, 0x00, 0xbb},
1024 {0x18, 0x00, 0x00, 0xbb},
1025 {0x19, 0x00, 0x00, 0xbb},
1026 {0x1a, 0x00, 0x00, 0xbb},
1027 {0x1b, 0x00, 0x00, 0xbb},
1028 {0x1c, 0x00, 0x00, 0xbb},
1029 {0x1d, 0x00, 0x00, 0xbb},
1030 {0x1e, 0x00, 0x00, 0xbb},
1031 {0xf0, 0x00, 0x01, 0xbb},
1032 {0x06, 0xe0, 0x0e, 0xbb},
1033 {0x06, 0x60, 0x0e, 0xbb},
1034 {0xb3, 0x5c, 0x01, 0xcc},
1035 {}
1036};
1037static const u8 mi1320_soc_InitVGA_JPG[][4] = {
1038 {0xb3, 0x01, 0x01, 0xcc},
1039 {0xb0, 0x03, 0x19, 0xcc},
1040 {0xb0, 0x04, 0x02, 0xcc},
1041 {0x00, 0x00, 0x30, 0xdd},
1042 {0xb3, 0x00, 0x64, 0xcc},
1043 {0xb3, 0x00, 0x67, 0xcc},
1044 {0xb3, 0x05, 0x01, 0xcc},
1045 {0xb3, 0x06, 0x01, 0xcc},
1046 {0xb3, 0x08, 0x01, 0xcc},
1047 {0xb3, 0x09, 0x0c, 0xcc},
1048 {0xb3, 0x34, 0x02, 0xcc},
1049 {0xb3, 0x35, 0xc8, 0xcc},
1050 {0xb3, 0x02, 0x00, 0xcc},
1051 {0xb3, 0x03, 0x0a, 0xcc},
1052 {0xb3, 0x04, 0x05, 0xcc},
1053 {0xb3, 0x20, 0x00, 0xcc},
1054 {0xb3, 0x21, 0x00, 0xcc},
1055 {0xb3, 0x22, 0x01, 0xcc},
1056 {0xb3, 0x23, 0xe0, 0xcc},
1057 {0xb3, 0x14, 0x00, 0xcc},
1058 {0xb3, 0x15, 0x00, 0xcc},
1059 {0xb3, 0x16, 0x02, 0xcc},
1060 {0xb3, 0x17, 0x7f, 0xcc},
1061 {0xb3, 0x00, 0x67, 0xcc},
1062 {0xb8, 0x00, 0x00, 0xcc},
1063 {0xbc, 0x00, 0x71, 0xcc},
1064 {0xbc, 0x01, 0x01, 0xcc},
1065 {0xb3, 0x5c, 0x01, 0xcc},
1066 {0xf0, 0x00, 0x02, 0xbb},
1067 {0x00, 0x00, 0x10, 0xdd},
1068 {0xc8, 0x00, 0x00, 0xbb},
1069 {0x00, 0x00, 0x30, 0xdd},
1070 {0xf0, 0x00, 0x00, 0xbb},
1071 {0x00, 0x00, 0x10, 0xdd},
1072 {0x07, 0x00, 0xe0, 0xbb},
1073 {0x08, 0x00, 0x0b, 0xbb},
1074 {0x21, 0x00, 0x0c, 0xbb},
1075 {0x20, 0x01, 0x03, 0xbb},
1076 {0xb6, 0x00, 0x00, 0xcc},
1077 {0xb6, 0x03, 0x02, 0xcc},
1078 {0xb6, 0x02, 0x80, 0xcc},
1079 {0xb6, 0x05, 0x01, 0xcc},
1080 {0xb6, 0x04, 0xe0, 0xcc},
1081 {0xb6, 0x12, 0xf8, 0xcc},
1082 {0xb6, 0x13, 0x05, 0xcc},
1083 {0xb6, 0x18, 0x02, 0xcc},
1084 {0xb6, 0x17, 0x58, 0xcc},
1085 {0xb6, 0x16, 0x00, 0xcc},
1086 {0xb6, 0x22, 0x12, 0xcc},
1087 {0xb6, 0x23, 0x0b, 0xcc},
1088 {0xbf, 0xc0, 0x39, 0xcc},
1089 {0xbf, 0xc1, 0x04, 0xcc},
1090 {0xbf, 0xcc, 0x00, 0xcc},
1091 {0xb3, 0x01, 0x41, 0xcc},
1092 {0xf0, 0x00, 0x00, 0xbb},
1093 {0x05, 0x01, 0x78, 0xbb},
1094 {0x06, 0x00, 0x11, 0xbb},
1095 {0x07, 0x01, 0x42, 0xbb},
1096 {0x08, 0x00, 0x11, 0xbb},
1097 {0x20, 0x01, 0x03, 0xbb},
1098 {0x21, 0x80, 0x00, 0xbb},
1099 {0x22, 0x0d, 0x0f, 0xbb},
1100 {0x24, 0x80, 0x00, 0xbb},
1101 {0x59, 0x00, 0xff, 0xbb},
1102 {0xf0, 0x00, 0x02, 0xbb},
1103 {0x39, 0x03, 0xca, 0xbb},
1104 {0x3a, 0x06, 0x80, 0xbb},
1105 {0x3b, 0x01, 0x52, 0xbb},
1106 {0x3c, 0x05, 0x40, 0xbb},
1107 {0x57, 0x01, 0x9c, 0xbb},
1108 {0x58, 0x01, 0xee, 0xbb},
1109 {0x59, 0x00, 0xf0, 0xbb},
1110 {0x5a, 0x01, 0x20, 0xbb},
1111 {0x5c, 0x1d, 0x17, 0xbb},
1112 {0x5d, 0x22, 0x1c, 0xbb},
1113 {0x64, 0x1e, 0x1c, 0xbb},
1114 {0x5b, 0x00, 0x00, 0xbb},
1115 {0xf0, 0x00, 0x02, 0xbb},
1116 {0x22, 0xa0, 0x78, 0xbb},
1117 {0x23, 0xa0, 0x78, 0xbb},
1118 {0x24, 0x7f, 0x00, 0xbb},
1119 {0x28, 0xea, 0x02, 0xbb},
1120 {0x29, 0x86, 0x7a, 0xbb},
1121 {0x5e, 0x52, 0x4c, 0xbb},
1122 {0x5f, 0x20, 0x24, 0xbb},
1123 {0x60, 0x00, 0x02, 0xbb},
1124 {0x02, 0x00, 0xee, 0xbb},
1125 {0x03, 0x39, 0x23, 0xbb},
1126 {0x04, 0x07, 0x24, 0xbb},
1127 {0x09, 0x00, 0xc0, 0xbb},
1128 {0x0a, 0x00, 0x79, 0xbb},
1129 {0x0b, 0x00, 0x04, 0xbb},
1130 {0x0c, 0x00, 0x5c, 0xbb},
1131 {0x0d, 0x00, 0xd9, 0xbb},
1132 {0x0e, 0x00, 0x53, 0xbb},
1133 {0x0f, 0x00, 0x21, 0xbb},
1134 {0x10, 0x00, 0xa4, 0xbb},
1135 {0x11, 0x00, 0xe5, 0xbb},
1136 {0x15, 0x00, 0x00, 0xbb},
1137 {0x16, 0x00, 0x00, 0xbb},
1138 {0x17, 0x00, 0x00, 0xbb},
1139 {0x18, 0x00, 0x00, 0xbb},
1140 {0x19, 0x00, 0x00, 0xbb},
1141 {0x1a, 0x00, 0x00, 0xbb},
1142 {0x1b, 0x00, 0x00, 0xbb},
1143 {0x1c, 0x00, 0x00, 0xbb},
1144 {0x1d, 0x00, 0x00, 0xbb},
1145 {0x1e, 0x00, 0x00, 0xbb},
1146 {0xf0, 0x00, 0x01, 0xbb},
1147 {0x06, 0xe0, 0x0e, 0xbb},
1148 {0x06, 0x60, 0x0e, 0xbb},
1149 {0xb3, 0x5c, 0x01, 0xcc},
1150 {}
1151};
1152static const u8 mi1320_soc_InitQVGA[][4] = {
1153 {0xb3, 0x01, 0x01, 0xcc},
1154 {0xb0, 0x03, 0x19, 0xcc},
1155 {0xb0, 0x04, 0x02, 0xcc},
1156 {0x00, 0x00, 0x30, 0xdd},
1157 {0xb3, 0x00, 0x64, 0xcc},
1158 {0xb3, 0x00, 0x67, 0xcc},
1159 {0xb3, 0x05, 0x01, 0xcc},
1160 {0xb3, 0x06, 0x01, 0xcc},
1161 {0xb3, 0x08, 0x01, 0xcc},
1162 {0xb3, 0x09, 0x0c, 0xcc},
1163 {0xb3, 0x34, 0x02, 0xcc},
1164 {0xb3, 0x35, 0xc8, 0xcc},
1165 {0xb3, 0x02, 0x00, 0xcc},
1166 {0xb3, 0x03, 0x0a, 0xcc},
1167 {0xb3, 0x04, 0x05, 0xcc},
1168 {0xb3, 0x20, 0x00, 0xcc},
1169 {0xb3, 0x21, 0x00, 0xcc},
1170 {0xb3, 0x22, 0x01, 0xcc},
1171 {0xb3, 0x23, 0xe0, 0xcc},
1172 {0xb3, 0x14, 0x00, 0xcc},
1173 {0xb3, 0x15, 0x00, 0xcc},
1174 {0xb3, 0x16, 0x02, 0xcc},
1175 {0xb3, 0x17, 0x7f, 0xcc},
1176 {0xb3, 0x00, 0x67, 0xcc},
1177 {0xb8, 0x00, 0x00, 0xcc},
1178 {0xbc, 0x00, 0xd1, 0xcc},
1179 {0xbc, 0x01, 0x01, 0xcc},
1180 {0xb3, 0x5c, 0x01, 0xcc},
1181 {0xf0, 0x00, 0x02, 0xbb},
1182 {0x00, 0x00, 0x10, 0xdd},
1183 {0xc8, 0x00, 0x00, 0xbb},
1184 {0x00, 0x00, 0x30, 0xdd},
1185 {0xf0, 0x00, 0x00, 0xbb},
1186 {0x00, 0x00, 0x10, 0xdd},
1187 {0x07, 0x00, 0xe0, 0xbb},
1188 {0x08, 0x00, 0x0b, 0xbb},
1189 {0x21, 0x00, 0x0c, 0xbb},
1190 {0x20, 0x01, 0x03, 0xbb},
1191 {0xbf, 0xc0, 0x26, 0xcc},
1192 {0xbf, 0xc1, 0x02, 0xcc},
1193 {0xbf, 0xcc, 0x04, 0xcc},
1194 {0xbc, 0x02, 0x18, 0xcc},
1195 {0xbc, 0x03, 0x50, 0xcc},
1196 {0xbc, 0x04, 0x18, 0xcc},
1197 {0xbc, 0x05, 0x00, 0xcc},
1198 {0xbc, 0x06, 0x00, 0xcc},
1199 {0xbc, 0x08, 0x30, 0xcc},
1200 {0xbc, 0x09, 0x40, 0xcc},
1201 {0xbc, 0x0a, 0x10, 0xcc},
1202 {0xbc, 0x0b, 0x00, 0xcc},
1203 {0xbc, 0x0c, 0x00, 0xcc},
1204 {0xb3, 0x01, 0x41, 0xcc},
1205 {0xf0, 0x00, 0x00, 0xbb},
1206 {0x05, 0x01, 0x78, 0xbb},
1207 {0x06, 0x00, 0x11, 0xbb},
1208 {0x07, 0x01, 0x42, 0xbb},
1209 {0x08, 0x00, 0x11, 0xbb},
1210 {0x20, 0x01, 0x03, 0xbb},
1211 {0x21, 0x80, 0x00, 0xbb},
1212 {0x22, 0x0d, 0x0f, 0xbb},
1213 {0x24, 0x80, 0x00, 0xbb},
1214 {0x59, 0x00, 0xff, 0xbb},
1215 {0xf0, 0x00, 0x02, 0xbb},
1216 {0x39, 0x03, 0xca, 0xbb},
1217 {0x3a, 0x06, 0x80, 0xbb},
1218 {0x3b, 0x01, 0x52, 0xbb},
1219 {0x3c, 0x05, 0x40, 0xbb},
1220 {0x57, 0x01, 0x9c, 0xbb},
1221 {0x58, 0x01, 0xee, 0xbb},
1222 {0x59, 0x00, 0xf0, 0xbb},
1223 {0x5a, 0x01, 0x20, 0xbb},
1224 {0x5c, 0x1d, 0x17, 0xbb},
1225 {0x5d, 0x22, 0x1c, 0xbb},
1226 {0x64, 0x1e, 0x1c, 0xbb},
1227 {0x5b, 0x00, 0x00, 0xbb},
1228 {0xf0, 0x00, 0x02, 0xbb},
1229 {0x22, 0xa0, 0x78, 0xbb},
1230 {0x23, 0xa0, 0x78, 0xbb},
1231 {0x24, 0x7f, 0x00, 0xbb},
1232 {0x28, 0xea, 0x02, 0xbb},
1233 {0x29, 0x86, 0x7a, 0xbb},
1234 {0x5e, 0x52, 0x4c, 0xbb},
1235 {0x5f, 0x20, 0x24, 0xbb},
1236 {0x60, 0x00, 0x02, 0xbb},
1237 {0x02, 0x00, 0xee, 0xbb},
1238 {0x03, 0x39, 0x23, 0xbb},
1239 {0x04, 0x07, 0x24, 0xbb},
1240 {0x09, 0x00, 0xc0, 0xbb},
1241 {0x0a, 0x00, 0x79, 0xbb},
1242 {0x0b, 0x00, 0x04, 0xbb},
1243 {0x0c, 0x00, 0x5c, 0xbb},
1244 {0x0d, 0x00, 0xd9, 0xbb},
1245 {0x0e, 0x00, 0x53, 0xbb},
1246 {0x0f, 0x00, 0x21, 0xbb},
1247 {0x10, 0x00, 0xa4, 0xbb},
1248 {0x11, 0x00, 0xe5, 0xbb},
1249 {0x15, 0x00, 0x00, 0xbb},
1250 {0x16, 0x00, 0x00, 0xbb},
1251 {0x17, 0x00, 0x00, 0xbb},
1252 {0x18, 0x00, 0x00, 0xbb},
1253 {0x19, 0x00, 0x00, 0xbb},
1254 {0x1a, 0x00, 0x00, 0xbb},
1255 {0x1b, 0x00, 0x00, 0xbb},
1256 {0x1c, 0x00, 0x00, 0xbb},
1257 {0x1d, 0x00, 0x00, 0xbb},
1258 {0x1e, 0x00, 0x00, 0xbb},
1259 {0xf0, 0x00, 0x01, 0xbb},
1260 {0x06, 0xe0, 0x0e, 0xbb},
1261 {0x06, 0x60, 0x0e, 0xbb},
1262 {0xb3, 0x5c, 0x01, 0xcc},
1263 {}
1264};
1265static const u8 mi1320_soc_InitQVGA_JPG[][4] = {
1266 {0xb3, 0x01, 0x01, 0xcc},
1267 {0xb0, 0x03, 0x19, 0xcc},
1268 {0xb0, 0x04, 0x02, 0xcc},
1269 {0x00, 0x00, 0x30, 0xdd},
1270 {0xb3, 0x00, 0x64, 0xcc},
1271 {0xb3, 0x00, 0x67, 0xcc},
1272 {0xb3, 0x05, 0x01, 0xcc},
1273 {0xb3, 0x06, 0x01, 0xcc},
1274 {0xb3, 0x08, 0x01, 0xcc},
1275 {0xb3, 0x09, 0x0c, 0xcc},
1276 {0xb3, 0x34, 0x02, 0xcc},
1277 {0xb3, 0x35, 0xc8, 0xcc},
1278 {0xb3, 0x02, 0x00, 0xcc},
1279 {0xb3, 0x03, 0x0a, 0xcc},
1280 {0xb3, 0x04, 0x05, 0xcc},
1281 {0xb3, 0x20, 0x00, 0xcc},
1282 {0xb3, 0x21, 0x00, 0xcc},
1283 {0xb3, 0x22, 0x01, 0xcc},
1284 {0xb3, 0x23, 0xe0, 0xcc},
1285 {0xb3, 0x14, 0x00, 0xcc},
1286 {0xb3, 0x15, 0x00, 0xcc},
1287 {0xb3, 0x16, 0x02, 0xcc},
1288 {0xb3, 0x17, 0x7f, 0xcc},
1289 {0xb3, 0x00, 0x67, 0xcc},
1290 {0xb8, 0x00, 0x00, 0xcc},
1291 {0xbc, 0x00, 0xd1, 0xcc},
1292 {0xbc, 0x01, 0x01, 0xcc},
1293 {0xb3, 0x5c, 0x01, 0xcc},
1294 {0xf0, 0x00, 0x02, 0xbb},
1295 {0x00, 0x00, 0x10, 0xdd},
1296 {0xc8, 0x00, 0x00, 0xbb},
1297 {0x00, 0x00, 0x30, 0xdd},
1298 {0xf0, 0x00, 0x00, 0xbb},
1299 {0x00, 0x00, 0x10, 0xdd},
1300 {0x07, 0x00, 0xe0, 0xbb},
1301 {0x08, 0x00, 0x0b, 0xbb},
1302 {0x21, 0x00, 0x0c, 0xbb},
1303 {0x20, 0x01, 0x03, 0xbb},
1304 {0xb6, 0x00, 0x00, 0xcc},
1305 {0xb6, 0x03, 0x01, 0xcc},
1306 {0xb6, 0x02, 0x40, 0xcc},
1307 {0xb6, 0x05, 0x00, 0xcc},
1308 {0xb6, 0x04, 0xf0, 0xcc},
1309 {0xb6, 0x12, 0xf8, 0xcc},
1310 {0xb6, 0x13, 0x05, 0xcc},
1311 {0xb6, 0x18, 0x00, 0xcc},
1312 {0xb6, 0x17, 0x96, 0xcc},
1313 {0xb6, 0x16, 0x00, 0xcc},
1314 {0xb6, 0x22, 0x12, 0xcc},
1315 {0xb6, 0x23, 0x0b, 0xcc},
1316 {0xbf, 0xc0, 0x39, 0xcc},
1317 {0xbf, 0xc1, 0x04, 0xcc},
1318 {0xbf, 0xcc, 0x00, 0xcc},
1319 {0xbc, 0x02, 0x18, 0xcc},
1320 {0xbc, 0x03, 0x50, 0xcc},
1321 {0xbc, 0x04, 0x18, 0xcc},
1322 {0xbc, 0x05, 0x00, 0xcc},
1323 {0xbc, 0x06, 0x00, 0xcc},
1324 {0xbc, 0x08, 0x30, 0xcc},
1325 {0xbc, 0x09, 0x40, 0xcc},
1326 {0xbc, 0x0a, 0x10, 0xcc},
1327 {0xbc, 0x0b, 0x00, 0xcc},
1328 {0xbc, 0x0c, 0x00, 0xcc},
1329 {0xb3, 0x01, 0x41, 0xcc},
1330 {0xf0, 0x00, 0x00, 0xbb},
1331 {0x05, 0x01, 0x78, 0xbb},
1332 {0x06, 0x00, 0x11, 0xbb},
1333 {0x07, 0x01, 0x42, 0xbb},
1334 {0x08, 0x00, 0x11, 0xbb},
1335 {0x20, 0x01, 0x03, 0xbb},
1336 {0x21, 0x80, 0x00, 0xbb},
1337 {0x22, 0x0d, 0x0f, 0xbb},
1338 {0x24, 0x80, 0x00, 0xbb},
1339 {0x59, 0x00, 0xff, 0xbb},
1340 {0xf0, 0x00, 0x02, 0xbb},
1341 {0x39, 0x03, 0xca, 0xbb},
1342 {0x3a, 0x06, 0x80, 0xbb},
1343 {0x3b, 0x01, 0x52, 0xbb},
1344 {0x3c, 0x05, 0x40, 0xbb},
1345 {0x57, 0x01, 0x9c, 0xbb},
1346 {0x58, 0x01, 0xee, 0xbb},
1347 {0x59, 0x00, 0xf0, 0xbb},
1348 {0x5a, 0x01, 0x20, 0xbb},
1349 {0x5c, 0x1d, 0x17, 0xbb},
1350 {0x5d, 0x22, 0x1c, 0xbb},
1351 {0x64, 0x1e, 0x1c, 0xbb},
1352 {0x5b, 0x00, 0x00, 0xbb},
1353 {0xf0, 0x00, 0x02, 0xbb},
1354 {0x22, 0xa0, 0x78, 0xbb},
1355 {0x23, 0xa0, 0x78, 0xbb},
1356 {0x24, 0x7f, 0x00, 0xbb},
1357 {0x28, 0xea, 0x02, 0xbb},
1358 {0x29, 0x86, 0x7a, 0xbb},
1359 {0x5e, 0x52, 0x4c, 0xbb},
1360 {0x5f, 0x20, 0x24, 0xbb},
1361 {0x60, 0x00, 0x02, 0xbb},
1362 {0x02, 0x00, 0xee, 0xbb},
1363 {0x03, 0x39, 0x23, 0xbb},
1364 {0x04, 0x07, 0x24, 0xbb},
1365 {0x09, 0x00, 0xc0, 0xbb},
1366 {0x0a, 0x00, 0x79, 0xbb},
1367 {0x0b, 0x00, 0x04, 0xbb},
1368 {0x0c, 0x00, 0x5c, 0xbb},
1369 {0x0d, 0x00, 0xd9, 0xbb},
1370 {0x0e, 0x00, 0x53, 0xbb},
1371 {0x0f, 0x00, 0x21, 0xbb},
1372 {0x10, 0x00, 0xa4, 0xbb},
1373 {0x11, 0x00, 0xe5, 0xbb},
1374 {0x15, 0x00, 0x00, 0xbb},
1375 {0x16, 0x00, 0x00, 0xbb},
1376 {0x17, 0x00, 0x00, 0xbb},
1377 {0x18, 0x00, 0x00, 0xbb},
1378 {0x19, 0x00, 0x00, 0xbb},
1379 {0x1a, 0x00, 0x00, 0xbb},
1380 {0x1b, 0x00, 0x00, 0xbb},
1381 {0x1c, 0x00, 0x00, 0xbb},
1382 {0x1d, 0x00, 0x00, 0xbb},
1383 {0x1e, 0x00, 0x00, 0xbb},
1384 {0xf0, 0x00, 0x01, 0xbb},
1385 {0x06, 0xe0, 0x0e, 0xbb},
1386 {0x06, 0x60, 0x0e, 0xbb},
1387 {0xb3, 0x5c, 0x01, 0xcc},
1388 {}
1389};
1390static const u8 mi1320_soc_InitSXGA_JPG[][4] = {
1391 {0xb3, 0x01, 0x01, 0xcc},
1392 {0xb0, 0x03, 0x19, 0xcc},
1393 {0xb0, 0x04, 0x02, 0xcc},
1394 {0x00, 0x00, 0x33, 0xdd},
1395 {0xb3, 0x00, 0x64, 0xcc},
1396 {0xb3, 0x00, 0x67, 0xcc},
1397 {0xb3, 0x05, 0x00, 0xcc},
1398 {0xb3, 0x06, 0x00, 0xcc},
1399 {0xb3, 0x08, 0x01, 0xcc},
1400 {0xb3, 0x09, 0x0c, 0xcc},
1401 {0xb3, 0x34, 0x02, 0xcc},
1402 {0xb3, 0x35, 0xc8, 0xcc},
1403 {0xb3, 0x02, 0x00, 0xcc},
1404 {0xb3, 0x03, 0x0a, 0xcc},
1405 {0xb3, 0x04, 0x05, 0xcc},
1406 {0xb3, 0x20, 0x00, 0xcc},
1407 {0xb3, 0x21, 0x00, 0xcc},
1408 {0xb3, 0x22, 0x04, 0xcc},
1409 {0xb3, 0x23, 0x00, 0xcc},
1410 {0xb3, 0x14, 0x00, 0xcc},
1411 {0xb3, 0x15, 0x00, 0xcc},
1412 {0xb3, 0x16, 0x04, 0xcc},
1413 {0xb3, 0x17, 0xff, 0xcc},
1414 {0xb3, 0x00, 0x67, 0xcc},
1415 {0xbc, 0x00, 0x71, 0xcc},
1416 {0xbc, 0x01, 0x01, 0xcc},
1417 {0xf0, 0x00, 0x02, 0xbb},
1418 {0x00, 0x00, 0x30, 0xdd},
1419 {0xc8, 0x9f, 0x0b, 0xbb},
1420 {0x00, 0x00, 0x20, 0xdd},
1421 {0x5b, 0x00, 0x01, 0xbb},
1422 {0x00, 0x00, 0x20, 0xdd},
1423 {0xf0, 0x00, 0x00, 0xbb},
1424 {0x00, 0x00, 0x30, 0xdd},
1425 {0x20, 0x01, 0x03, 0xbb},
1426 {0x00, 0x00, 0x20, 0xdd},
1427 {0xb6, 0x00, 0x00, 0xcc},
1428 {0xb6, 0x03, 0x05, 0xcc},
1429 {0xb6, 0x02, 0x00, 0xcc},
1430 {0xb6, 0x05, 0x04, 0xcc},
1431 {0xb6, 0x04, 0x00, 0xcc},
1432 {0xb6, 0x12, 0xf8, 0xcc},
1433 {0xb6, 0x13, 0x29, 0xcc},
1434 {0xb6, 0x18, 0x0a, 0xcc},
1435 {0xb6, 0x17, 0x00, 0xcc},
1436 {0xb6, 0x16, 0x00, 0xcc},
1437 {0xb6, 0x22, 0x12, 0xcc},
1438 {0xb6, 0x23, 0x0b, 0xcc},
1439 {0xbf, 0xc0, 0x39, 0xcc},
1440 {0xbf, 0xc1, 0x04, 0xcc},
1441 {0xbf, 0xcc, 0x00, 0xcc},
1442 {0xb3, 0x5c, 0x01, 0xcc},
1443 {0xb3, 0x01, 0x41, 0xcc},
1444 {0xf0, 0x00, 0x00, 0xbb},
1445 {0x05, 0x01, 0x78, 0xbb},
1446 {0x06, 0x00, 0x11, 0xbb},
1447 {0x07, 0x01, 0x42, 0xbb},
1448 {0x08, 0x00, 0x11, 0xbb},
1449 {0x20, 0x01, 0x03, 0xbb},
1450 {0x21, 0x80, 0x00, 0xbb},
1451 {0x22, 0x0d, 0x0f, 0xbb},
1452 {0x24, 0x80, 0x00, 0xbb},
1453 {0x59, 0x00, 0xff, 0xbb},
1454 {0xf0, 0x00, 0x02, 0xbb},
1455 {0x39, 0x03, 0xca, 0xbb},
1456 {0x3a, 0x06, 0x80, 0xbb},
1457 {0x3b, 0x01, 0x52, 0xbb},
1458 {0x3c, 0x05, 0x40, 0xbb},
1459 {0x57, 0x01, 0x9c, 0xbb},
1460 {0x58, 0x01, 0xee, 0xbb},
1461 {0x59, 0x00, 0xf0, 0xbb},
1462 {0x5a, 0x01, 0x20, 0xbb},
1463 {0x5c, 0x1d, 0x17, 0xbb},
1464 {0x5d, 0x22, 0x1c, 0xbb},
1465 {0x64, 0x1e, 0x1c, 0xbb},
1466 {0x5b, 0x00, 0x00, 0xbb},
1467 {0xf0, 0x00, 0x02, 0xbb},
1468 {0x22, 0xa0, 0x78, 0xbb},
1469 {0x23, 0xa0, 0x78, 0xbb},
1470 {0x24, 0x7f, 0x00, 0xbb},
1471 {0x28, 0xea, 0x02, 0xbb},
1472 {0x29, 0x86, 0x7a, 0xbb},
1473 {0x5e, 0x52, 0x4c, 0xbb},
1474 {0x5f, 0x20, 0x24, 0xbb},
1475 {0x60, 0x00, 0x02, 0xbb},
1476 {0x02, 0x00, 0xee, 0xbb},
1477 {0x03, 0x39, 0x23, 0xbb},
1478 {0x04, 0x07, 0x24, 0xbb},
1479 {0x09, 0x00, 0xc0, 0xbb},
1480 {0x0a, 0x00, 0x79, 0xbb},
1481 {0x0b, 0x00, 0x04, 0xbb},
1482 {0x0c, 0x00, 0x5c, 0xbb},
1483 {0x0d, 0x00, 0xd9, 0xbb},
1484 {0x0e, 0x00, 0x53, 0xbb},
1485 {0x0f, 0x00, 0x21, 0xbb},
1486 {0x10, 0x00, 0xa4, 0xbb},
1487 {0x11, 0x00, 0xe5, 0xbb},
1488 {0x15, 0x00, 0x00, 0xbb},
1489 {0x16, 0x00, 0x00, 0xbb},
1490 {0x17, 0x00, 0x00, 0xbb},
1491 {0x18, 0x00, 0x00, 0xbb},
1492 {0x19, 0x00, 0x00, 0xbb},
1493 {0x1a, 0x00, 0x00, 0xbb},
1494 {0x1b, 0x00, 0x00, 0xbb},
1495 {0x1c, 0x00, 0x00, 0xbb},
1496 {0x1d, 0x00, 0x00, 0xbb},
1497 {0x1e, 0x00, 0x00, 0xbb},
1498 {0xf0, 0x00, 0x01, 0xbb},
1499 {0x06, 0xe0, 0x0e, 0xbb},
1500 {0x06, 0x60, 0x0e, 0xbb},
1501 {0xb3, 0x5c, 0x01, 0xcc},
1502 {0xf0, 0x00, 0x00, 0xbb},
1503 {0x05, 0x01, 0x13, 0xbb},
1504 {0x06, 0x00, 0x11, 0xbb},
1505 {0x07, 0x00, 0x85, 0xbb},
1506 {0x08, 0x00, 0x27, 0xbb},
1507 {0x20, 0x01, 0x03, 0xbb},
1508 {0x21, 0x80, 0x00, 0xbb},
1509 {0x22, 0x0d, 0x0f, 0xbb},
1510 {0x24, 0x80, 0x00, 0xbb},
1511 {0x59, 0x00, 0xff, 0xbb},
1512 {0xf0, 0x00, 0x02, 0xbb},
1513 {0x39, 0x03, 0x0d, 0xbb},
1514 {0x3a, 0x06, 0x1b, 0xbb},
1515 {0x3b, 0x00, 0x95, 0xbb},
1516 {0x3c, 0x04, 0xdb, 0xbb},
1517 {0x57, 0x02, 0x00, 0xbb},
1518 {0x58, 0x02, 0x66, 0xbb},
1519 {0x59, 0x00, 0xff, 0xbb},
1520 {0x5a, 0x01, 0x33, 0xbb},
1521 {0x5c, 0x12, 0x0d, 0xbb},
1522 {0x5d, 0x16, 0x11, 0xbb},
1523 {0x64, 0x5e, 0x1c, 0xbb},
1524 {0x2f, 0x90, 0x00, 0xbb},
1525 {}
1526};
1527static const u8 mi1320_soc_InitSXGA[][4] = {
1528 {0xb3, 0x01, 0x01, 0xcc},
1529 {0xb0, 0x03, 0x19, 0xcc},
1530 {0x00, 0x00, 0x30, 0xdd},
1531 {0xb3, 0x00, 0x64, 0xcc},
1532 {0xb3, 0x00, 0x67, 0xcc},
1533 {0xb3, 0x05, 0x01, 0xcc},
1534 {0xb3, 0x06, 0x01, 0xcc},
1535 {0xb3, 0x08, 0x01, 0xcc},
1536 {0xb3, 0x09, 0x0c, 0xcc},
1537 {0xb3, 0x34, 0x02, 0xcc},
1538 {0xb3, 0x35, 0xc8, 0xcc},
1539 {0xb3, 0x02, 0x00, 0xcc},
1540 {0xb3, 0x03, 0x0a, 0xcc},
1541 {0xb3, 0x04, 0x05, 0xcc},
1542 {0xb3, 0x20, 0x00, 0xcc},
1543 {0xb3, 0x21, 0x00, 0xcc},
1544 {0xb3, 0x22, 0x04, 0xcc},
1545 {0xb3, 0x23, 0x00, 0xcc},
1546 {0xb3, 0x14, 0x00, 0xcc},
1547 {0xb3, 0x15, 0x00, 0xcc},
1548 {0xb3, 0x16, 0x04, 0xcc},
1549 {0xb3, 0x17, 0xff, 0xcc},
1550 {0xb3, 0x00, 0x67, 0xcc},
1551 {0xbc, 0x00, 0x71, 0xcc},
1552 {0xbc, 0x01, 0x01, 0xcc},
1553 {0xb3, 0x5c, 0x01, 0xcc},
1554 {0xf0, 0x00, 0x02, 0xbb},
1555 {0x00, 0x00, 0x30, 0xdd},
1556 {0xc8, 0x9f, 0x0b, 0xbb},
1557 {0x00, 0x00, 0x20, 0xdd},
1558 {0x5b, 0x00, 0x01, 0xbb},
1559 {0x00, 0x00, 0x20, 0xdd},
1560 {0xf0, 0x00, 0x00, 0xbb},
1561 {0x00, 0x00, 0x30, 0xdd},
1562 {0x20, 0x01, 0x03, 0xbb},
1563 {0x00, 0x00, 0x20, 0xdd},
1564 {0xbf, 0xc0, 0x26, 0xcc},
1565 {0xbf, 0xc1, 0x02, 0xcc},
1566 {0xbf, 0xcc, 0x04, 0xcc},
1567 {0xb3, 0x01, 0x41, 0xcc},
1568 {0xf0, 0x00, 0x00, 0xbb},
1569 {0x05, 0x01, 0x78, 0xbb},
1570 {0x06, 0x00, 0x11, 0xbb},
1571 {0x07, 0x01, 0x42, 0xbb},
1572 {0x08, 0x00, 0x11, 0xbb},
1573 {0x20, 0x01, 0x03, 0xbb},
1574 {0x21, 0x80, 0x00, 0xbb},
1575 {0x22, 0x0d, 0x0f, 0xbb},
1576 {0x24, 0x80, 0x00, 0xbb},
1577 {0x59, 0x00, 0xff, 0xbb},
1578 {0xf0, 0x00, 0x02, 0xbb},
1579 {0x39, 0x03, 0xca, 0xbb},
1580 {0x3a, 0x06, 0x80, 0xbb},
1581 {0x3b, 0x01, 0x52, 0xbb},
1582 {0x3c, 0x05, 0x40, 0xbb},
1583 {0x57, 0x01, 0x9c, 0xbb},
1584 {0x58, 0x01, 0xee, 0xbb},
1585 {0x59, 0x00, 0xf0, 0xbb},
1586 {0x5a, 0x01, 0x20, 0xbb},
1587 {0x5c, 0x1d, 0x17, 0xbb},
1588 {0x5d, 0x22, 0x1c, 0xbb},
1589 {0x64, 0x1e, 0x1c, 0xbb},
1590 {0x5b, 0x00, 0x00, 0xbb},
1591 {0xf0, 0x00, 0x02, 0xbb},
1592 {0x22, 0xa0, 0x78, 0xbb},
1593 {0x23, 0xa0, 0x78, 0xbb},
1594 {0x24, 0x7f, 0x00, 0xbb},
1595 {0x28, 0xea, 0x02, 0xbb},
1596 {0x29, 0x86, 0x7a, 0xbb},
1597 {0x5e, 0x52, 0x4c, 0xbb},
1598 {0x5f, 0x20, 0x24, 0xbb},
1599 {0x60, 0x00, 0x02, 0xbb},
1600 {0x02, 0x00, 0xee, 0xbb},
1601 {0x03, 0x39, 0x23, 0xbb},
1602 {0x04, 0x07, 0x24, 0xbb},
1603 {0x09, 0x00, 0xc0, 0xbb},
1604 {0x0a, 0x00, 0x79, 0xbb},
1605 {0x0b, 0x00, 0x04, 0xbb},
1606 {0x0c, 0x00, 0x5c, 0xbb},
1607 {0x0d, 0x00, 0xd9, 0xbb},
1608 {0x0e, 0x00, 0x53, 0xbb},
1609 {0x0f, 0x00, 0x21, 0xbb},
1610 {0x10, 0x00, 0xa4, 0xbb},
1611 {0x11, 0x00, 0xe5, 0xbb},
1612 {0x15, 0x00, 0x00, 0xbb},
1613 {0x16, 0x00, 0x00, 0xbb},
1614 {0x17, 0x00, 0x00, 0xbb},
1615 {0x18, 0x00, 0x00, 0xbb},
1616 {0x19, 0x00, 0x00, 0xbb},
1617 {0x1a, 0x00, 0x00, 0xbb},
1618 {0x1b, 0x00, 0x00, 0xbb},
1619 {0x1c, 0x00, 0x00, 0xbb},
1620 {0x1d, 0x00, 0x00, 0xbb},
1621 {0x1e, 0x00, 0x00, 0xbb},
1622 {0xf0, 0x00, 0x01, 0xbb},
1623 {0x06, 0xe0, 0x0e, 0xbb},
1624 {0x06, 0x60, 0x0e, 0xbb},
1625 {0xb3, 0x5c, 0x01, 0xcc},
1626 {0xf0, 0x00, 0x00, 0xbb},
1627 {0x05, 0x01, 0x13, 0xbb},
1628 {0x06, 0x00, 0x11, 0xbb},
1629 {0x07, 0x00, 0x85, 0xbb},
1630 {0x08, 0x00, 0x27, 0xbb},
1631 {0x20, 0x01, 0x03, 0xbb},
1632 {0x21, 0x80, 0x00, 0xbb},
1633 {0x22, 0x0d, 0x0f, 0xbb},
1634 {0x24, 0x80, 0x00, 0xbb},
1635 {0x59, 0x00, 0xff, 0xbb},
1636 {0xf0, 0x00, 0x02, 0xbb},
1637 {0x39, 0x03, 0x0d, 0xbb},
1638 {0x3a, 0x06, 0x1b, 0xbb},
1639 {0x3b, 0x00, 0x95, 0xbb},
1640 {0x3c, 0x04, 0xdb, 0xbb},
1641 {0x57, 0x02, 0x00, 0xbb},
1642 {0x58, 0x02, 0x66, 0xbb},
1643 {0x59, 0x00, 0xff, 0xbb},
1644 {0x5a, 0x01, 0x33, 0xbb},
1645 {0x5c, 0x12, 0x0d, 0xbb},
1646 {0x5d, 0x16, 0x11, 0xbb},
1647 {0x64, 0x5e, 0x1c, 0xbb},
1648 {}
1649};
781static const __u8 po3130_gamma[17] = { 1650static const __u8 po3130_gamma[17] = {
782 0x00, 0x13, 0x38, 0x59, 0x79, 0x92, 0xa7, 0xb9, 0xc8, 1651 0x00, 0x13, 0x38, 0x59, 0x79, 0x92, 0xa7, 0xb9, 0xc8,
783 0xd4, 0xdf, 0xe7, 0xee, 0xf4, 0xf9, 0xfc, 0xff 1652 0xd4, 0xdf, 0xe7, 0xee, 0xf4, 0xf9, 0xfc, 0xff
@@ -1764,26 +2633,43 @@ static const __u8 po1200_initVGA_data[][4] = {
1764}; 2633};
1765 2634
1766struct sensor_info { 2635struct sensor_info {
1767 int sensorId; 2636 s8 sensorId;
1768 __u8 I2cAdd; 2637 u8 I2cAdd;
1769 __u8 IdAdd; 2638 u8 IdAdd;
1770 __u16 VpId; 2639 u16 VpId;
1771 __u8 m1; 2640 u8 m1;
1772 __u8 m2; 2641 u8 m2;
1773 __u8 op; 2642 u8 op;
1774 }; 2643};
1775 2644
1776static const struct sensor_info sensor_info_data[] = { 2645static const struct sensor_info sensor_info_data[] = {
1777/* sensorId, I2cAdd, IdAdd, VpId, m1, m2, op */ 2646/* sensorId, I2cAdd, IdAdd, VpId, m1, m2, op */
1778 {SENSOR_HV7131R, 0x80 | 0x11, 0x00, 0x0209, 0x24, 0x25, 0x01}, 2647 {-1, 0x80 | 0x30, 0x0a, 0x0000, 0x25, 0x24, 0x05},
1779 {SENSOR_OV7660, 0x80 | 0x21, 0x0a, 0x7660, 0x26, 0x26, 0x05}, 2648 {-1, 0x80 | 0x20, 0x82, 0x0000, 0x24, 0x25, 0x01},
2649/* (tested in vc032x_probe_sensor) */
2650/* {-1, 0x80 | 0x20, 0x83, 0x0000, 0x24, 0x25, 0x01}, */
1780 {SENSOR_PO3130NC, 0x80 | 0x76, 0x00, 0x3130, 0x24, 0x25, 0x01}, 2651 {SENSOR_PO3130NC, 0x80 | 0x76, 0x00, 0x3130, 0x24, 0x25, 0x01},
1781 {SENSOR_MI1320, 0x80 | 0xc8, 0x00, 0x148c, 0x64, 0x65, 0x01},
1782 {SENSOR_OV7670, 0x80 | 0x21, 0x0a, 0x7673, 0x66, 0x67, 0x05},
1783 {SENSOR_MI1310_SOC, 0x80 | 0x5d, 0x00, 0x143a, 0x24, 0x25, 0x01}, 2652 {SENSOR_MI1310_SOC, 0x80 | 0x5d, 0x00, 0x143a, 0x24, 0x25, 0x01},
1784/* (tested in vc032x_probe_sensor) */ 2653/* (tested in vc032x_probe_sensor) */
1785/* {SENSOR_MI0360, 0x80 | 0x5d, 0x00, 0x8243, 0x24, 0x25, 0x01}, */ 2654/* {SENSOR_MI0360, 0x80 | 0x5d, 0x00, 0x8243, 0x24, 0x25, 0x01}, */
2655 {SENSOR_HV7131R, 0x80 | 0x11, 0x00, 0x0209, 0x24, 0x25, 0x01},
2656 {-1, 0x80 | 0x21, 0x0a, 0x0000, 0x21, 0x20, 0x05},
2657 {-1, 0x80 | 0x40, 0x00, 0x0000, 0x20, 0x22, 0x05},
2658 {SENSOR_OV7660, 0x80 | 0x21, 0x0a, 0x7660, 0x26, 0x26, 0x05},
2659/* {SENSOR_PO3130NC, 0x80 | 0x76, 0x00, 0x0000, 0x24, 0x25, 0x01}, */
2660 {-1, 0x80 | 0x6e, 0x00, 0x0000, 0x24, 0x25, 0x01},
2661/* {SENSOR_MI1310_SOC, 0x80 | 0x5d, 0x00, 0x0000, 0x24, 0x25, 0x01}, */
2662/* {-1, 0x80 | 0x30, 0x0a, 0x0000, 0x25, 0x24, 0x05}, */
2663 {-1, 0x80 | 0x11, 0x39, 0x0000, 0x24, 0x25, 0x01},
1786 {SENSOR_PO1200, 0x80 | 0x5c, 0x00, 0x1200, 0x67, 0x67, 0x01}, 2664 {SENSOR_PO1200, 0x80 | 0x5c, 0x00, 0x1200, 0x67, 0x67, 0x01},
2665 {-1, 0x80 | 0x2d, 0x00, 0x0000, 0x65, 0x67, 0x01},
2666 {-1, 0x80 | 0x6e, 0x00, 0x0000, 0x24, 0x25, 0x01},
2667 {-1, 0x80 | 0x56, 0x01, 0x0000, 0x64, 0x67, 0x01},
2668 {SENSOR_MI1320_SOC, 0x80 | 0x48, 0x00, 0x148c, 0x64, 0x67, 0x01},
2669/*fixme: previously detected?*/
2670 {SENSOR_MI1320, 0x80 | 0x48, 0x00, 0x148c, 0x64, 0x65, 0x01},
2671/*fixme: not in the ms-win probe - may be found before?*/
2672 {SENSOR_OV7670, 0x80 | 0x21, 0x0a, 0x7673, 0x66, 0x67, 0x05},
1787}; 2673};
1788 2674
1789/* read 'len' bytes in gspca_dev->usb_buf */ 2675/* read 'len' bytes in gspca_dev->usb_buf */
@@ -1814,51 +2700,49 @@ static void reg_w(struct usb_device *dev,
1814 500); 2700 500);
1815} 2701}
1816 2702
1817static void read_sensor_register(struct gspca_dev *gspca_dev, 2703static u16 read_sensor_register(struct gspca_dev *gspca_dev,
1818 __u16 address, __u16 *value) 2704 u16 address)
1819{ 2705{
1820 struct usb_device *dev = gspca_dev->dev; 2706 struct usb_device *dev = gspca_dev->dev;
1821 __u8 ldata, mdata, hdata; 2707 u8 ldata, mdata, hdata;
1822 int retry = 50; 2708 int retry = 50;
1823 2709
1824 *value = 0;
1825
1826 reg_r(gspca_dev, 0xa1, 0xb33f, 1); 2710 reg_r(gspca_dev, 0xa1, 0xb33f, 1);
1827 /*PDEBUG(D_PROBE, " I2c Bus Busy Wait 0x%02X ", tmpvalue); */
1828 if (!(gspca_dev->usb_buf[0] & 0x02)) { 2711 if (!(gspca_dev->usb_buf[0] & 0x02)) {
1829 PDEBUG(D_ERR, "I2c Bus Busy Wait %d", 2712 PDEBUG(D_ERR, "I2c Bus Busy Wait %02x",
1830 gspca_dev->usb_buf[0] & 0x02); 2713 gspca_dev->usb_buf[0]);
1831 return; 2714 return 0;
1832 } 2715 }
1833 reg_w(dev, 0xa0, address, 0xb33a); 2716 reg_w(dev, 0xa0, address, 0xb33a);
1834 reg_w(dev, 0xa0, 0x02, 0xb339); 2717 reg_w(dev, 0xa0, 0x02, 0xb339);
1835 2718
1836 reg_r(gspca_dev, 0xa1, 0xb33b, 1); 2719 do {
1837 while (retry-- && gspca_dev->usb_buf[0]) {
1838 reg_r(gspca_dev, 0xa1, 0xb33b, 1); 2720 reg_r(gspca_dev, 0xa1, 0xb33b, 1);
1839/* PDEBUG(D_PROBE, "Read again 0xb33b %d", tmpvalue); */ 2721 if (gspca_dev->usb_buf[0] == 0x00)
1840 msleep(1); 2722 break;
1841 } 2723 msleep(40);
2724 } while (--retry >= 0);
2725
1842 reg_r(gspca_dev, 0xa1, 0xb33e, 1); 2726 reg_r(gspca_dev, 0xa1, 0xb33e, 1);
1843 ldata = gspca_dev->usb_buf[0]; 2727 ldata = gspca_dev->usb_buf[0];
1844 reg_r(gspca_dev, 0xa1, 0xb33d, 1); 2728 reg_r(gspca_dev, 0xa1, 0xb33d, 1);
1845 mdata = gspca_dev->usb_buf[0]; 2729 mdata = gspca_dev->usb_buf[0];
1846 reg_r(gspca_dev, 0xa1, 0xb33c, 1); 2730 reg_r(gspca_dev, 0xa1, 0xb33c, 1);
1847 hdata = gspca_dev->usb_buf[0]; 2731 hdata = gspca_dev->usb_buf[0];
1848 PDEBUG(D_PROBE, "Read Sensor %02x%02x %02x", 2732 if (hdata != 0 && mdata != 0 && ldata != 0)
1849 hdata, mdata, ldata); 2733 PDEBUG(D_PROBE, "Read Sensor %02x%02x %02x",
2734 hdata, mdata, ldata);
1850 reg_r(gspca_dev, 0xa1, 0xb334, 1); 2735 reg_r(gspca_dev, 0xa1, 0xb334, 1);
1851 if (gspca_dev->usb_buf[0] == 0x02) 2736 if (gspca_dev->usb_buf[0] == 0x02)
1852 *value = (hdata << 8) + mdata; 2737 return (hdata << 8) + mdata;
1853 else 2738 return hdata;
1854 *value = hdata;
1855} 2739}
1856 2740
1857static int vc032x_probe_sensor(struct gspca_dev *gspca_dev) 2741static int vc032x_probe_sensor(struct gspca_dev *gspca_dev)
1858{ 2742{
1859 struct usb_device *dev = gspca_dev->dev; 2743 struct usb_device *dev = gspca_dev->dev;
1860 int i; 2744 int i;
1861 __u16 value; 2745 u16 value;
1862 const struct sensor_info *ptsensor_info; 2746 const struct sensor_info *ptsensor_info;
1863 2747
1864 reg_r(gspca_dev, 0xa1, 0xbfcf, 1); 2748 reg_r(gspca_dev, 0xa1, 0xbfcf, 1);
@@ -1872,48 +2756,51 @@ static int vc032x_probe_sensor(struct gspca_dev *gspca_dev)
1872 reg_w(dev, 0xa0, 0x0c, 0xb309); 2756 reg_w(dev, 0xa0, 0x0c, 0xb309);
1873 reg_w(dev, 0xa0, ptsensor_info->I2cAdd, 0xb335); 2757 reg_w(dev, 0xa0, ptsensor_info->I2cAdd, 0xb335);
1874 reg_w(dev, 0xa0, ptsensor_info->op, 0xb301); 2758 reg_w(dev, 0xa0, ptsensor_info->op, 0xb301);
1875 read_sensor_register(gspca_dev, ptsensor_info->IdAdd, &value); 2759 value = read_sensor_register(gspca_dev, ptsensor_info->IdAdd);
1876 if (value == ptsensor_info->VpId) 2760 if (value == 0 && ptsensor_info->IdAdd == 0x82)
1877 return ptsensor_info->sensorId; 2761 value = read_sensor_register(gspca_dev, 0x83);
1878 2762 if (value != 0) {
1879 /* special case for MI0360 */ 2763 PDEBUG(D_ERR|D_PROBE, "Sensor ID %04x (%d)",
1880 if (ptsensor_info->sensorId == SENSOR_MI1310_SOC 2764 value, i);
1881 && value == 0x8243) 2765 if (value == ptsensor_info->VpId)
1882 return SENSOR_MI0360; 2766 return ptsensor_info->sensorId;
2767
2768 switch (value) {
2769 case 0x7673:
2770 return SENSOR_OV7670;
2771 case 0x8243:
2772 return SENSOR_MI0360;
2773 }
2774/*fixme: should return here*/
2775 }
1883 } 2776 }
1884 return -1; 2777 return -1;
1885} 2778}
1886 2779
1887static __u8 i2c_write(struct gspca_dev *gspca_dev, 2780static void i2c_write(struct gspca_dev *gspca_dev,
1888 __u8 reg, const __u8 *val, __u8 size) 2781 u8 reg, const u8 *val,
2782 u8 size) /* 1 or 2 */
1889{ 2783{
1890 struct usb_device *dev = gspca_dev->dev; 2784 struct usb_device *dev = gspca_dev->dev;
2785 int retry;
1891 2786
1892 if (size > 3 || size < 1)
1893 return -EINVAL;
1894 reg_r(gspca_dev, 0xa1, 0xb33f, 1); 2787 reg_r(gspca_dev, 0xa1, 0xb33f, 1);
2788/*fixme:should check if (!(gspca_dev->usb_buf[0] & 0x02)) error*/
1895 reg_w(dev, 0xa0, size, 0xb334); 2789 reg_w(dev, 0xa0, size, 0xb334);
1896 reg_w(dev, 0xa0, reg, 0xb33a); 2790 reg_w(dev, 0xa0, reg, 0xb33a);
1897 switch (size) { 2791 reg_w(dev, 0xa0, val[0], 0xb336);
1898 case 1: 2792 if (size > 1)
1899 reg_w(dev, 0xa0, val[0], 0xb336);
1900 break;
1901 case 2:
1902 reg_w(dev, 0xa0, val[0], 0xb336);
1903 reg_w(dev, 0xa0, val[1], 0xb337); 2793 reg_w(dev, 0xa0, val[1], 0xb337);
1904 break;
1905 case 3:
1906 reg_w(dev, 0xa0, val[0], 0xb336);
1907 reg_w(dev, 0xa0, val[1], 0xb337);
1908 reg_w(dev, 0xa0, val[2], 0xb338);
1909 break;
1910 default:
1911 reg_w(dev, 0xa0, 0x01, 0xb334);
1912 return -EINVAL;
1913 }
1914 reg_w(dev, 0xa0, 0x01, 0xb339); 2794 reg_w(dev, 0xa0, 0x01, 0xb339);
1915 reg_r(gspca_dev, 0xa1, 0xb33b, 1); 2795 retry = 4;
1916 return gspca_dev->usb_buf[0] == 0; 2796 do {
2797 reg_r(gspca_dev, 0xa1, 0xb33b, 1);
2798 if (gspca_dev->usb_buf[0] == 0)
2799 break;
2800 msleep(20);
2801 } while (--retry > 0);
2802 if (retry <= 0)
2803 PDEBUG(D_ERR, "i2c_write failed");
1917} 2804}
1918 2805
1919static void put_tab_to_reg(struct gspca_dev *gspca_dev, 2806static void put_tab_to_reg(struct gspca_dev *gspca_dev,
@@ -1938,7 +2825,7 @@ static void usb_exchange(struct gspca_dev *gspca_dev,
1938 return; 2825 return;
1939 case 0xcc: /* normal write */ 2826 case 0xcc: /* normal write */
1940 reg_w(dev, 0xa0, data[i][2], 2827 reg_w(dev, 0xa0, data[i][2],
1941 ((data[i][0])<<8) | data[i][1]); 2828 (data[i][0]) << 8 | data[i][1]);
1942 break; 2829 break;
1943 case 0xaa: /* i2c op */ 2830 case 0xaa: /* i2c op */
1944 i2c_write(gspca_dev, data[i][1], &data[i][2], 1); 2831 i2c_write(gspca_dev, data[i][1], &data[i][2], 1);
@@ -1955,19 +2842,6 @@ static void usb_exchange(struct gspca_dev *gspca_dev,
1955 /*not reached*/ 2842 /*not reached*/
1956} 2843}
1957 2844
1958/*
1959 "GammaT"=hex:04,17,31,4f,6a,83,99,ad,bf,ce,da,e5,ee,f5,fb,ff,ff
1960 "MatrixT"=hex:60,f9,e5,e7,50,05,f3,e6,66
1961 */
1962
1963static void vc0321_reset(struct gspca_dev *gspca_dev)
1964{
1965 reg_w(gspca_dev->dev, 0xa0, 0x00, 0xb04d);
1966 reg_w(gspca_dev->dev, 0xa0, 0x01, 0xb301);
1967 msleep(100);
1968 reg_w(gspca_dev->dev, 0xa0, 0x01, 0xb003);
1969 msleep(100);
1970}
1971 2845
1972/* this function is called at probe time */ 2846/* this function is called at probe time */
1973static int sd_config(struct gspca_dev *gspca_dev, 2847static int sd_config(struct gspca_dev *gspca_dev,
@@ -1979,10 +2853,7 @@ static int sd_config(struct gspca_dev *gspca_dev,
1979 int sensor; 2853 int sensor;
1980 2854
1981 cam = &gspca_dev->cam; 2855 cam = &gspca_dev->cam;
1982 cam->epaddr = 0x02;
1983 sd->bridge = id->driver_info; 2856 sd->bridge = id->driver_info;
1984
1985 vc0321_reset(gspca_dev);
1986 sensor = vc032x_probe_sensor(gspca_dev); 2857 sensor = vc032x_probe_sensor(gspca_dev);
1987 switch (sensor) { 2858 switch (sensor) {
1988 case -1: 2859 case -1:
@@ -2001,6 +2872,9 @@ static int sd_config(struct gspca_dev *gspca_dev,
2001 case SENSOR_MI1320: 2872 case SENSOR_MI1320:
2002 PDEBUG(D_PROBE, "Find Sensor MI1320"); 2873 PDEBUG(D_PROBE, "Find Sensor MI1320");
2003 break; 2874 break;
2875 case SENSOR_MI1320_SOC:
2876 PDEBUG(D_PROBE, "Find Sensor MI1320_SOC");
2877 break;
2004 case SENSOR_OV7660: 2878 case SENSOR_OV7660:
2005 PDEBUG(D_PROBE, "Find Sensor OV7660"); 2879 PDEBUG(D_PROBE, "Find Sensor OV7660");
2006 break; 2880 break;
@@ -2020,12 +2894,23 @@ static int sd_config(struct gspca_dev *gspca_dev,
2020 cam->cam_mode = vc0321_mode; 2894 cam->cam_mode = vc0321_mode;
2021 cam->nmodes = ARRAY_SIZE(vc0321_mode); 2895 cam->nmodes = ARRAY_SIZE(vc0321_mode);
2022 } else { 2896 } else {
2023 if (sensor != SENSOR_PO1200) { 2897 switch (sensor) {
2024 cam->cam_mode = vc0323_mode; 2898 case SENSOR_PO1200:
2025 cam->nmodes = ARRAY_SIZE(vc0323_mode);
2026 } else {
2027 cam->cam_mode = svga_mode; 2899 cam->cam_mode = svga_mode;
2028 cam->nmodes = ARRAY_SIZE(svga_mode); 2900 cam->nmodes = ARRAY_SIZE(svga_mode);
2901 break;
2902 case SENSOR_MI1310_SOC:
2903 cam->cam_mode = vc0323_mode;
2904 cam->nmodes = ARRAY_SIZE(vc0323_mode);
2905 break;
2906 case SENSOR_MI1320_SOC:
2907 cam->cam_mode = bi_mode;
2908 cam->nmodes = ARRAY_SIZE(bi_mode);
2909 break;
2910 default:
2911 cam->cam_mode = vc0323_mode;
2912 cam->nmodes = ARRAY_SIZE(vc0323_mode) - 1;
2913 break;
2029 } 2914 }
2030 } 2915 }
2031 2916
@@ -2061,7 +2946,7 @@ static int sd_config(struct gspca_dev *gspca_dev,
2061 return 0; 2946 return 0;
2062} 2947}
2063 2948
2064/* this function is called at probe and time */ 2949/* this function is called at probe and resume time */
2065static int sd_init(struct gspca_dev *gspca_dev) 2950static int sd_init(struct gspca_dev *gspca_dev)
2066{ 2951{
2067 return 0; 2952 return 0;
@@ -2124,9 +3009,18 @@ static void setsharpness(struct gspca_dev *gspca_dev)
2124static int sd_start(struct gspca_dev *gspca_dev) 3009static int sd_start(struct gspca_dev *gspca_dev)
2125{ 3010{
2126 struct sd *sd = (struct sd *) gspca_dev; 3011 struct sd *sd = (struct sd *) gspca_dev;
3012 const __u8 (*init)[4];
2127 const __u8 *GammaT = NULL; 3013 const __u8 *GammaT = NULL;
2128 const __u8 *MatrixT = NULL; 3014 const __u8 *MatrixT = NULL;
2129 int mode; 3015 int mode;
3016 static const u8 (*mi1320_soc_init[])[4] = {
3017 mi1320_soc_InitSXGA,
3018 mi1320_soc_InitSXGA_JPG,
3019 mi1320_soc_InitVGA,
3020 mi1320_soc_InitVGA_JPG,
3021 mi1320_soc_InitQVGA,
3022 mi1320_soc_InitQVGA_JPG
3023 };
2130 3024
2131 /* Assume start use the good resolution from gspca_dev->mode */ 3025 /* Assume start use the good resolution from gspca_dev->mode */
2132 if (sd->bridge == BRIDGE_VC0321) { 3026 if (sd->bridge == BRIDGE_VC0321) {
@@ -2134,6 +3028,13 @@ static int sd_start(struct gspca_dev *gspca_dev)
2134 reg_w(gspca_dev->dev, 0xa0, 0xff, 0xbfed); 3028 reg_w(gspca_dev->dev, 0xa0, 0xff, 0xbfed);
2135 reg_w(gspca_dev->dev, 0xa0, 0xff, 0xbfee); 3029 reg_w(gspca_dev->dev, 0xa0, 0xff, 0xbfee);
2136 reg_w(gspca_dev->dev, 0xa0, 0xff, 0xbfef); 3030 reg_w(gspca_dev->dev, 0xa0, 0xff, 0xbfef);
3031 sd->image_offset = 46;
3032 } else {
3033 if (gspca_dev->cam.cam_mode[gspca_dev->curr_mode].pixelformat
3034 == V4L2_PIX_FMT_JPEG)
3035 sd->image_offset = 0;
3036 else
3037 sd->image_offset = 32;
2137 } 3038 }
2138 3039
2139 mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv; 3040 mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
@@ -2141,115 +3042,87 @@ static int sd_start(struct gspca_dev *gspca_dev)
2141 case SENSOR_HV7131R: 3042 case SENSOR_HV7131R:
2142 GammaT = hv7131r_gamma; 3043 GammaT = hv7131r_gamma;
2143 MatrixT = hv7131r_matrix; 3044 MatrixT = hv7131r_matrix;
2144 if (mode) { 3045 if (mode)
2145 /* 320x240 */ 3046 init = hv7131r_initQVGA_data; /* 320x240 */
2146 usb_exchange(gspca_dev, hv7131r_initQVGA_data); 3047 else
2147 } else { 3048 init = hv7131r_initVGA_data; /* 640x480 */
2148 /* 640x480 */
2149 usb_exchange(gspca_dev, hv7131r_initVGA_data);
2150 }
2151 break; 3049 break;
2152 case SENSOR_OV7660: 3050 case SENSOR_OV7660:
2153 GammaT = ov7660_gamma; 3051 GammaT = ov7660_gamma;
2154 MatrixT = ov7660_matrix; 3052 MatrixT = ov7660_matrix;
2155 if (mode) { 3053 if (mode)
2156 /* 320x240 */ 3054 init = ov7660_initQVGA_data; /* 320x240 */
2157 usb_exchange(gspca_dev, ov7660_initQVGA_data); 3055 else
2158 } else { 3056 init = ov7660_initVGA_data; /* 640x480 */
2159 /* 640x480 */
2160 usb_exchange(gspca_dev, ov7660_initVGA_data);
2161 }
2162 break; 3057 break;
2163 case SENSOR_OV7670: 3058 case SENSOR_OV7670:
2164 /*GammaT = ov7660_gamma; */ 3059 /*GammaT = ov7660_gamma; */
2165 /*MatrixT = ov7660_matrix; */ 3060 /*MatrixT = ov7660_matrix; */
2166 if (mode) { 3061 if (mode)
2167 /* 320x240 */ 3062 init = ov7670_initQVGA_JPG; /* 320x240 */
2168 usb_exchange(gspca_dev, ov7670_initQVGA_JPG); 3063 else
2169 } else { 3064 init = ov7670_initVGA_JPG; /* 640x480 */
2170 /* 640x480 */
2171 usb_exchange(gspca_dev, ov7670_initVGA_JPG);
2172 }
2173 break; 3065 break;
2174 case SENSOR_MI0360: 3066 case SENSOR_MI0360:
2175 GammaT = mi1320_gamma; 3067 GammaT = mi1320_gamma;
2176 MatrixT = mi0360_matrix; 3068 MatrixT = mi0360_matrix;
2177 if (mode) { 3069 if (mode)
2178 /* 320x240 */ 3070 init = mi0360_initQVGA_JPG; /* 320x240 */
2179 usb_exchange(gspca_dev, mi0360_initQVGA_JPG); 3071 else
2180 } else { 3072 init = mi0360_initVGA_JPG; /* 640x480 */
2181 /* 640x480 */
2182 usb_exchange(gspca_dev, mi0360_initVGA_JPG);
2183 }
2184 break; 3073 break;
2185 case SENSOR_MI1310_SOC: 3074 case SENSOR_MI1310_SOC:
2186 if (mode) { 3075 GammaT = mi1320_gamma;
2187 /* 320x240 */ 3076 MatrixT = mi1320_matrix;
2188 usb_exchange(gspca_dev, mi1310_socinitQVGA_JPG); 3077 switch (mode) {
2189 } else { 3078 case 1:
2190 /* 640x480 */ 3079 init = mi1310_socinitQVGA_JPG; /* 320x240 */
2191 usb_exchange(gspca_dev, mi1310_socinitVGA_JPG); 3080 break;
3081 case 0:
3082 init = mi1310_socinitVGA_JPG; /* 640x480 */
3083 break;
3084 default:
3085 init = mi1310_soc_InitSXGA_JPG; /* 1280x1024 */
3086 break;
2192 } 3087 }
2193 break; 3088 break;
2194 case SENSOR_MI1320: 3089 case SENSOR_MI1320:
2195 GammaT = mi1320_gamma; 3090 GammaT = mi1320_gamma;
2196 MatrixT = mi1320_matrix; 3091 MatrixT = mi1320_matrix;
2197 if (mode) { 3092 if (mode)
2198 /* 320x240 */ 3093 init = mi1320_initQVGA_data; /* 320x240 */
2199 usb_exchange(gspca_dev, mi1320_initQVGA_data); 3094 else
2200 } else { 3095 init = mi1320_initVGA_data; /* 640x480 */
2201 /* 640x480 */ 3096 break;
2202 usb_exchange(gspca_dev, mi1320_initVGA_data); 3097 case SENSOR_MI1320_SOC:
2203 } 3098 GammaT = mi1320_gamma;
3099 MatrixT = mi1320_matrix;
3100 init = mi1320_soc_init[mode];
2204 break; 3101 break;
2205 case SENSOR_PO3130NC: 3102 case SENSOR_PO3130NC:
2206 GammaT = po3130_gamma; 3103 GammaT = po3130_gamma;
2207 MatrixT = po3130_matrix; 3104 MatrixT = po3130_matrix;
2208 if (mode) { 3105 if (mode)
2209 /* 320x240 */ 3106 init = po3130_initQVGA_data; /* 320x240 */
2210 usb_exchange(gspca_dev, po3130_initQVGA_data); 3107 else
2211 } else { 3108 init = po3130_initVGA_data; /* 640x480 */
2212 /* 640x480 */ 3109 usb_exchange(gspca_dev, init);
2213 usb_exchange(gspca_dev, po3130_initVGA_data); 3110 init = po3130_rundata;
2214 }
2215 usb_exchange(gspca_dev, po3130_rundata);
2216 break; 3111 break;
2217 case SENSOR_PO1200: 3112 default:
3113/* case SENSOR_PO1200: */
2218 GammaT = po1200_gamma; 3114 GammaT = po1200_gamma;
2219 MatrixT = po1200_matrix; 3115 MatrixT = po1200_matrix;
2220 usb_exchange(gspca_dev, po1200_initVGA_data); 3116 init = po1200_initVGA_data;
2221 break; 3117 break;
2222 default:
2223 PDEBUG(D_PROBE, "Damned !! no sensor found Bye");
2224 return -EMEDIUMTYPE;
2225 } 3118 }
3119 usb_exchange(gspca_dev, init);
2226 if (GammaT && MatrixT) { 3120 if (GammaT && MatrixT) {
2227 put_tab_to_reg(gspca_dev, GammaT, 17, 0xb84a); 3121 put_tab_to_reg(gspca_dev, GammaT, 17, 0xb84a);
2228 put_tab_to_reg(gspca_dev, GammaT, 17, 0xb85b); 3122 put_tab_to_reg(gspca_dev, GammaT, 17, 0xb85b);
2229 put_tab_to_reg(gspca_dev, GammaT, 17, 0xb86c); 3123 put_tab_to_reg(gspca_dev, GammaT, 17, 0xb86c);
2230 put_tab_to_reg(gspca_dev, MatrixT, 9, 0xb82c); 3124 put_tab_to_reg(gspca_dev, MatrixT, 9, 0xb82c);
2231 3125
2232 /* Seem SHARPNESS */
2233 /*
2234 reg_w(gspca_dev->dev, 0xa0, 0x80, 0xb80a);
2235 reg_w(gspca_dev->dev, 0xa0, 0xff, 0xb80b);
2236 reg_w(gspca_dev->dev, 0xa0, 0xff, 0xb80e);
2237 */
2238 /* all 0x40 ??? do nothing
2239 reg_w(gspca_dev->dev, 0xa0, 0x40, 0xb822);
2240 reg_w(gspca_dev->dev, 0xa0, 0x40, 0xb823);
2241 reg_w(gspca_dev->dev, 0xa0, 0x40, 0xb824);
2242 */
2243 /* Only works for HV7131R ??
2244 reg_r (gspca_dev, 0xa1, 0xb881, 1);
2245 reg_w(gspca_dev->dev, 0xa0, 0xfe01, 0xb881);
2246 reg_w(gspca_dev->dev, 0xa0, 0x79, 0xb801);
2247 */
2248 /* only hv7131r et ov7660
2249 reg_w(gspca_dev->dev, 0xa0, 0x20, 0xb827);
2250 reg_w(gspca_dev->dev, 0xa0, 0xff, 0xb826); * ISP_GAIN 80
2251 reg_w(gspca_dev->dev, 0xa0, 0x23, 0xb800); * ISP CTRL_BAS
2252 */
2253 /* set the led on 0x0892 0x0896 */ 3126 /* set the led on 0x0892 0x0896 */
2254 if (sd->sensor != SENSOR_PO1200) { 3127 if (sd->sensor != SENSOR_PO1200) {
2255 reg_w(gspca_dev->dev, 0x89, 0xffff, 0xfdff); 3128 reg_w(gspca_dev->dev, 0x89, 0xffff, 0xfdff);
@@ -2296,12 +3169,8 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
2296 "vc032x header packet found len %d", len); 3169 "vc032x header packet found len %d", len);
2297 frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame, 3170 frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame,
2298 data, 0); 3171 data, 0);
2299 if (sd->bridge == BRIDGE_VC0321) { 3172 data += sd->image_offset;
2300#define VCHDRSZ 46 3173 len -= sd->image_offset;
2301 data += VCHDRSZ;
2302 len -= VCHDRSZ;
2303#undef VCHDRSZ
2304 }
2305 gspca_frame_add(gspca_dev, FIRST_PACKET, frame, 3174 gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
2306 data, len); 3175 data, len);
2307 return; 3176 return;
@@ -2399,7 +3268,8 @@ static int sd_querymenu(struct gspca_dev *gspca_dev,
2399 case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */ 3268 case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
2400 strcpy((char *) menu->name, "50 Hz"); 3269 strcpy((char *) menu->name, "50 Hz");
2401 return 0; 3270 return 0;
2402 case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */ 3271 default:
3272/* case 2: * V4L2_CID_POWER_LINE_FREQUENCY_60HZ */
2403 strcpy((char *) menu->name, "60 Hz"); 3273 strcpy((char *) menu->name, "60 Hz");
2404 return 0; 3274 return 0;
2405 } 3275 }
@@ -2424,6 +3294,7 @@ static const struct sd_desc sd_desc = {
2424 3294
2425/* -- module initialisation -- */ 3295/* -- module initialisation -- */
2426static const __devinitdata struct usb_device_id device_table[] = { 3296static const __devinitdata struct usb_device_id device_table[] = {
3297 {USB_DEVICE(0x041e, 0x405b), .driver_info = BRIDGE_VC0323},
2427 {USB_DEVICE(0x046d, 0x0892), .driver_info = BRIDGE_VC0321}, 3298 {USB_DEVICE(0x046d, 0x0892), .driver_info = BRIDGE_VC0321},
2428 {USB_DEVICE(0x046d, 0x0896), .driver_info = BRIDGE_VC0321}, 3299 {USB_DEVICE(0x046d, 0x0896), .driver_info = BRIDGE_VC0321},
2429 {USB_DEVICE(0x046d, 0x0897), .driver_info = BRIDGE_VC0321}, 3300 {USB_DEVICE(0x046d, 0x0897), .driver_info = BRIDGE_VC0321},
@@ -2432,6 +3303,7 @@ static const __devinitdata struct usb_device_id device_table[] = {
2432 {USB_DEVICE(0x0ac8, 0x0328), .driver_info = BRIDGE_VC0321}, 3303 {USB_DEVICE(0x0ac8, 0x0328), .driver_info = BRIDGE_VC0321},
2433 {USB_DEVICE(0x0ac8, 0xc001), .driver_info = BRIDGE_VC0321}, 3304 {USB_DEVICE(0x0ac8, 0xc001), .driver_info = BRIDGE_VC0321},
2434 {USB_DEVICE(0x0ac8, 0xc002), .driver_info = BRIDGE_VC0321}, 3305 {USB_DEVICE(0x0ac8, 0xc002), .driver_info = BRIDGE_VC0321},
3306 {USB_DEVICE(0x15b8, 0x6001), .driver_info = BRIDGE_VC0323},
2435 {USB_DEVICE(0x15b8, 0x6002), .driver_info = BRIDGE_VC0323}, 3307 {USB_DEVICE(0x15b8, 0x6002), .driver_info = BRIDGE_VC0323},
2436 {USB_DEVICE(0x17ef, 0x4802), .driver_info = BRIDGE_VC0323}, 3308 {USB_DEVICE(0x17ef, 0x4802), .driver_info = BRIDGE_VC0323},
2437 {} 3309 {}
@@ -2460,8 +3332,11 @@ static struct usb_driver sd_driver = {
2460/* -- module insert / remove -- */ 3332/* -- module insert / remove -- */
2461static int __init sd_mod_init(void) 3333static int __init sd_mod_init(void)
2462{ 3334{
2463 if (usb_register(&sd_driver) < 0) 3335 int ret;
2464 return -1; 3336
3337 ret = usb_register(&sd_driver);
3338 if (ret < 0)
3339 return ret;
2465 PDEBUG(D_PROBE, "registered"); 3340 PDEBUG(D_PROBE, "registered");
2466 return 0; 3341 return 0;
2467} 3342}
diff --git a/drivers/media/video/gspca/zc3xx.c b/drivers/media/video/gspca/zc3xx.c
index ec2a53d53fe2..4fe01d8b6c87 100644
--- a/drivers/media/video/gspca/zc3xx.c
+++ b/drivers/media/video/gspca/zc3xx.c
@@ -23,6 +23,7 @@
23#define MODULE_NAME "zc3xx" 23#define MODULE_NAME "zc3xx"
24 24
25#include "gspca.h" 25#include "gspca.h"
26#include "jpeg.h"
26 27
27MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>, " 28MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>, "
28 "Serge A. Suchkov <Serge.A.S@tochka.ru>"); 29 "Serge A. Suchkov <Serge.A.S@tochka.ru>");
@@ -31,7 +32,7 @@ MODULE_LICENSE("GPL");
31 32
32static int force_sensor = -1; 33static int force_sensor = -1;
33 34
34#include "jpeg.h" 35#define QUANT_VAL 1 /* quantization table */
35#include "zc3xx-reg.h" 36#include "zc3xx-reg.h"
36 37
37/* specific webcam descriptor */ 38/* specific webcam descriptor */
@@ -44,30 +45,36 @@ struct sd {
44 __u8 autogain; 45 __u8 autogain;
45 __u8 lightfreq; 46 __u8 lightfreq;
46 __u8 sharpness; 47 __u8 sharpness;
48 u8 quality; /* image quality */
49#define QUALITY_MIN 40
50#define QUALITY_MAX 60
51#define QUALITY_DEF 50
47 52
48 char qindex;
49 signed char sensor; /* Type of image sensor chip */ 53 signed char sensor; /* Type of image sensor chip */
50/* !! values used in different tables */ 54/* !! values used in different tables */
51#define SENSOR_CS2102 0 55#define SENSOR_ADCM2700 0
52#define SENSOR_CS2102K 1 56#define SENSOR_CS2102 1
53#define SENSOR_GC0305 2 57#define SENSOR_CS2102K 2
54#define SENSOR_HDCS2020b 3 58#define SENSOR_GC0305 3
55#define SENSOR_HV7131B 4 59#define SENSOR_HDCS2020b 4
56#define SENSOR_HV7131C 5 60#define SENSOR_HV7131B 5
57#define SENSOR_ICM105A 6 61#define SENSOR_HV7131C 6
58#define SENSOR_MC501CB 7 62#define SENSOR_ICM105A 7
59#define SENSOR_OV7620 8 63#define SENSOR_MC501CB 8
60/*#define SENSOR_OV7648 8 - same values */ 64#define SENSOR_OV7620 9
61#define SENSOR_OV7630C 9 65/*#define SENSOR_OV7648 9 - same values */
62#define SENSOR_PAS106 10 66#define SENSOR_OV7630C 10
63#define SENSOR_PAS202B 11 67#define SENSOR_PAS106 11
64#define SENSOR_PB0330 12 68#define SENSOR_PAS202B 12
65#define SENSOR_PO2030 13 69#define SENSOR_PB0330 13
66#define SENSOR_TAS5130CK 14 70#define SENSOR_PO2030 14
67#define SENSOR_TAS5130CXX 15 71#define SENSOR_TAS5130CK 15
68#define SENSOR_TAS5130C_VF0250 16 72#define SENSOR_TAS5130CXX 16
69#define SENSOR_MAX 17 73#define SENSOR_TAS5130C_VF0250 17
74#define SENSOR_MAX 18
70 unsigned short chip_revision; 75 unsigned short chip_revision;
76
77 u8 *jpeg_hdr;
71}; 78};
72 79
73/* V4L2 controls supported by the driver */ 80/* V4L2 controls supported by the driver */
@@ -206,6 +213,213 @@ struct usb_action {
206 __u16 idx; 213 __u16 idx;
207}; 214};
208 215
216static const struct usb_action adcm2700_Initial[] = {
217 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, /* 00,00,01,cc */
218 {0xa0, 0x04, ZC3XX_R002_CLOCKSELECT}, /* 00,02,04,cc */
219 {0xa0, 0x00, ZC3XX_R008_CLOCKSETTING}, /* 00,08,03,cc */
220 {0xa0, 0x0a, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,0a,cc */
221 {0xa0, 0xd3, ZC3XX_R08B_I2CDEVICEADDR}, /* 00,8b,d3,cc */
222 {0xa0, 0x02, ZC3XX_R003_FRAMEWIDTHHIGH}, /* 00,03,02,cc */
223 {0xa0, 0x80, ZC3XX_R004_FRAMEWIDTHLOW}, /* 00,04,80,cc */
224 {0xa0, 0x01, ZC3XX_R005_FRAMEHEIGHTHIGH}, /* 00,05,01,cc */
225 {0xa0, 0xd8, ZC3XX_R006_FRAMEHEIGHTLOW}, /* 00,06,d8,cc */
226 {0xa0, 0x01, ZC3XX_R001_SYSTEMOPERATING}, /* 00,01,01,cc */
227 {0xa0, 0x03, ZC3XX_R012_VIDEOCONTROLFUNC}, /* 00,12,03,cc */
228 {0xa0, 0x01, ZC3XX_R012_VIDEOCONTROLFUNC}, /* 00,12,01,cc */
229 {0xa0, 0x05, ZC3XX_R012_VIDEOCONTROLFUNC}, /* 00,12,05,cc */
230 {0xa0, 0x00, ZC3XX_R098_WINYSTARTLOW}, /* 00,98,00,cc */
231 {0xa0, 0x00, ZC3XX_R09A_WINXSTARTLOW}, /* 00,9a,00,cc */
232 {0xa0, 0x00, ZC3XX_R11A_FIRSTYLOW}, /* 01,1a,00,cc */
233 {0xa0, 0x00, ZC3XX_R11C_FIRSTXLOW}, /* 01,1c,00,cc */
234 {0xa0, 0xde, ZC3XX_R09C_WINHEIGHTLOW}, /* 00,9c,de,cc */
235 {0xa0, 0x86, ZC3XX_R09E_WINWIDTHLOW}, /* 00,9e,86,cc */
236 {0xbb, 0x00, 0x0400}, /* 04,00,00,bb */
237 {0xdd, 0x00, 0x0010}, /* 00,00,10,dd */
238 {0xbb, 0x0f, 0x140f}, /* 14,0f,0f,bb */
239 {0xa0, 0xb7, ZC3XX_R101_SENSORCORRECTION}, /* 01,01,37,cc */
240 {0xa0, 0x0d, ZC3XX_R100_OPERATIONMODE}, /* 01,00,0d,cc */
241 {0xa0, 0x06, ZC3XX_R189_AWBSTATUS}, /* 01,89,06,cc */
242 {0xa0, 0x03, ZC3XX_R1C5_SHARPNESSMODE}, /* 01,c5,03,cc */
243 {0xa0, 0x13, ZC3XX_R1CB_SHARPNESS05}, /* 01,cb,13,cc */
244 {0xa0, 0x08, ZC3XX_R250_DEADPIXELSMODE}, /* 02,50,08,cc */
245 {0xa0, 0x08, ZC3XX_R301_EEPROMACCESS}, /* 03,01,08,cc */
246 {0xa0, 0x58, ZC3XX_R116_RGAIN}, /* 01,16,58,cc */
247 {0xa0, 0x5a, ZC3XX_R118_BGAIN}, /* 01,18,5a,cc */
248 {0xa0, 0x02, ZC3XX_R180_AUTOCORRECTENABLE}, /* 01,80,02,cc */
249 {0xa0, 0xd3, ZC3XX_R08B_I2CDEVICEADDR}, /* 00,8b,d3,cc */
250 {0xbb, 0x00, 0x0408}, /* 04,00,08,bb */
251 {0xdd, 0x00, 0x0200}, /* 00,02,00,dd */
252 {0xbb, 0x00, 0x0400}, /* 04,00,00,bb */
253 {0xdd, 0x00, 0x0010}, /* 00,00,10,dd */
254 {0xbb, 0x0f, 0x140f}, /* 14,0f,0f,bb */
255 {0xbb, 0xe0, 0x0c2e}, /* 0c,e0,2e,bb */
256 {0xbb, 0x01, 0x2000}, /* 20,01,00,bb */
257 {0xbb, 0x96, 0x2400}, /* 24,96,00,bb */
258 {0xbb, 0x06, 0x1006}, /* 10,06,06,bb */
259 {0xa0, 0x01, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,01,cc */
260 {0xdd, 0x00, 0x0010}, /* 00,00,10,dd */
261 {0xaa, 0xfe, 0x0002}, /* 00,fe,02,aa */
262 {0xa0, 0x0a, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,0a,cc */
263 {0xdd, 0x00, 0x0010}, /* 00,00,10,dd */
264 {0xbb, 0x5f, 0x2090}, /* 20,5f,90,bb */
265 {0xbb, 0x01, 0x8000}, /* 80,01,00,bb */
266 {0xbb, 0x09, 0x8400}, /* 84,09,00,bb */
267 {0xbb, 0x86, 0x0002}, /* 00,86,02,bb */
268 {0xbb, 0xe6, 0x0401}, /* 04,e6,01,bb */
269 {0xbb, 0x86, 0x0802}, /* 08,86,02,bb */
270 {0xbb, 0xe6, 0x0c01}, /* 0c,e6,01,bb */
271 {0xa0, 0x01, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,01,cc */
272 {0xdd, 0x00, 0x0010}, /* 00,00,10,dd */
273 {0xaa, 0xfe, 0x0000}, /* 00,fe,00,aa */
274 {0xa0, 0x0a, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,0a,cc */
275 {0xdd, 0x00, 0x0010}, /* 00,00,10,dd */
276 {0xa0, 0x01, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,01,cc */
277 {0xaa, 0xfe, 0x0020}, /* 00,fe,20,aa */
278/*mswin+*/
279 {0xa0, 0x01, ZC3XX_R010_CMOSSENSORSELECT},
280 {0xaa, 0xfe, 0x0002},
281 {0xa0, 0x0a, ZC3XX_R010_CMOSSENSORSELECT},
282 {0xaa, 0xb4, 0xcd37},
283 {0xaa, 0xa4, 0x0004},
284 {0xaa, 0xa8, 0x0007},
285 {0xaa, 0xac, 0x0004},
286/*mswin-*/
287 {0xa0, 0x0a, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,0a,cc */
288 {0xa0, 0x01, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,01,cc */
289 {0xdd, 0x00, 0x0010}, /* 00,00,10,dd */
290 {0xaa, 0xfe, 0x0000}, /* 00,fe,00,aa */
291 {0xa0, 0x0a, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,0a,cc */
292 {0xdd, 0x00, 0x0010}, /* 00,00,10,dd */
293 {0xbb, 0x04, 0x0400}, /* 04,04,00,bb */
294 {0xdd, 0x00, 0x0100}, /* 00,01,00,dd */
295 {0xbb, 0x01, 0x0400}, /* 04,01,00,bb */
296 {0xa0, 0x01, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,01,cc */
297 {0xaa, 0xfe, 0x0002}, /* 00,fe,02,aa */
298 {0xa0, 0x0a, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,0a,cc */
299 {0xbb, 0x41, 0x2803}, /* 28,41,03,bb */
300 {0xbb, 0x40, 0x2c03}, /* 2c,40,03,bb */
301 {0xa0, 0x01, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,01,cc */
302 {0xaa, 0xfe, 0x0010}, /* 00,fe,10,aa */
303 {}
304};
305static const struct usb_action adcm2700_InitialScale[] = {
306 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, /* 00,00,01,cc */
307 {0xa0, 0x10, ZC3XX_R002_CLOCKSELECT}, /* 00,02,10,cc */
308 {0xa0, 0x00, ZC3XX_R008_CLOCKSETTING}, /* 00,08,03,cc */
309 {0xa0, 0x0a, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,0a,cc */
310 {0xa0, 0xd3, ZC3XX_R08B_I2CDEVICEADDR}, /* 00,8b,d3,cc */
311 {0xa0, 0x02, ZC3XX_R003_FRAMEWIDTHHIGH}, /* 00,03,02,cc */
312 {0xa0, 0x80, ZC3XX_R004_FRAMEWIDTHLOW}, /* 00,04,80,cc */
313 {0xa0, 0x01, ZC3XX_R005_FRAMEHEIGHTHIGH}, /* 00,05,01,cc */
314 {0xa0, 0xd0, ZC3XX_R006_FRAMEHEIGHTLOW}, /* 00,06,d0,cc */
315 {0xa0, 0x01, ZC3XX_R001_SYSTEMOPERATING}, /* 00,01,01,cc */
316 {0xa0, 0x03, ZC3XX_R012_VIDEOCONTROLFUNC}, /* 00,12,03,cc */
317 {0xa0, 0x01, ZC3XX_R012_VIDEOCONTROLFUNC}, /* 00,12,01,cc */
318 {0xa0, 0x05, ZC3XX_R012_VIDEOCONTROLFUNC}, /* 00,12,05,cc */
319 {0xa0, 0x00, ZC3XX_R098_WINYSTARTLOW}, /* 00,98,00,cc */
320 {0xa0, 0x00, ZC3XX_R09A_WINXSTARTLOW}, /* 00,9a,00,cc */
321 {0xa0, 0x00, ZC3XX_R11A_FIRSTYLOW}, /* 01,1a,00,cc */
322 {0xa0, 0x00, ZC3XX_R11C_FIRSTXLOW}, /* 01,1c,00,cc */
323 {0xa0, 0xd8, ZC3XX_R09C_WINHEIGHTLOW}, /* 00,9c,d8,cc */
324 {0xa0, 0x88, ZC3XX_R09E_WINWIDTHLOW}, /* 00,9e,88,cc */
325 {0xbb, 0x00, 0x0400}, /* 04,00,00,bb */
326 {0xdd, 0x00, 0x0010}, /* 00,00,10,dd */
327 {0xbb, 0x0f, 0x140f}, /* 14,0f,0f,bb */
328 {0xa0, 0xb7, ZC3XX_R101_SENSORCORRECTION}, /* 01,01,37,cc */
329 {0xa0, 0x0d, ZC3XX_R100_OPERATIONMODE}, /* 01,00,0d,cc */
330 {0xa0, 0x06, ZC3XX_R189_AWBSTATUS}, /* 01,89,06,cc */
331 {0xa0, 0x03, ZC3XX_R1C5_SHARPNESSMODE}, /* 01,c5,03,cc */
332 {0xa0, 0x13, ZC3XX_R1CB_SHARPNESS05}, /* 01,cb,13,cc */
333 {0xa0, 0x08, ZC3XX_R250_DEADPIXELSMODE}, /* 02,50,08,cc */
334 {0xa0, 0x08, ZC3XX_R301_EEPROMACCESS}, /* 03,01,08,cc */
335 {0xa0, 0x58, ZC3XX_R116_RGAIN}, /* 01,16,58,cc */
336 {0xa0, 0x5a, ZC3XX_R118_BGAIN}, /* 01,18,5a,cc */
337 {0xa0, 0x02, ZC3XX_R180_AUTOCORRECTENABLE}, /* 01,80,02,cc */
338 {0xa0, 0xd3, ZC3XX_R08B_I2CDEVICEADDR}, /* 00,8b,d3,cc */
339 {0xbb, 0x00, 0x0408}, /* 04,00,08,bb */
340 {0xdd, 0x00, 0x0200}, /* 00,02,00,dd */
341 {0xbb, 0x00, 0x0400}, /* 04,00,00,bb */
342 {0xdd, 0x00, 0x0050}, /* 00,00,50,dd */
343 {0xbb, 0x0f, 0x140f}, /* 14,0f,0f,bb */
344 {0xbb, 0xe0, 0x0c2e}, /* 0c,e0,2e,bb */
345 {0xbb, 0x01, 0x2000}, /* 20,01,00,bb */
346 {0xbb, 0x96, 0x2400}, /* 24,96,00,bb */
347 {0xbb, 0x06, 0x1006}, /* 10,06,06,bb */
348 {0xa0, 0x01, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,01,cc */
349 {0xdd, 0x00, 0x0010}, /* 00,00,10,dd */
350 {0xaa, 0xfe, 0x0002}, /* 00,fe,02,aa */
351 {0xa0, 0x0a, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,0a,cc */
352 {0xdd, 0x00, 0x0010}, /* 00,00,10,dd */
353 {0xbb, 0x5f, 0x2090}, /* 20,5f,90,bb */
354 {0xbb, 0x01, 0x8000}, /* 80,01,00,bb */
355 {0xbb, 0x09, 0x8400}, /* 84,09,00,bb */
356 {0xbb, 0x86, 0x0002}, /* 00,88,02,bb */
357 {0xbb, 0xe6, 0x0401}, /* 04,e6,01,bb */
358 {0xbb, 0x86, 0x0802}, /* 08,88,02,bb */
359 {0xbb, 0xe6, 0x0c01}, /* 0c,e6,01,bb */
360 {0xa0, 0x01, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,01,cc */
361 {0xdd, 0x00, 0x0010}, /* 00,00,10,dd */
362 {0xaa, 0xfe, 0x0000}, /* 00,fe,00,aa */
363 {0xa0, 0x0a, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,0a,cc */
364 {0xdd, 0x00, 0x0010}, /* 00,00,10,dd */
365 {0xa0, 0x01, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,01,cc */
366 {0xaa, 0xfe, 0x0020}, /* 00,fe,20,aa */
367 /*******/
368 {0xa0, 0x0a, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,0a,cc */
369 {0xa0, 0x01, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,01,cc */
370 {0xdd, 0x00, 0x0010}, /* 00,00,10,dd */
371 {0xaa, 0xfe, 0x0000}, /* 00,fe,00,aa */
372 {0xa0, 0x0a, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,0a,cc */
373 {0xdd, 0x00, 0x0010}, /* 00,00,10,dd */
374 {0xbb, 0x04, 0x0400}, /* 04,04,00,bb */
375 {0xdd, 0x00, 0x0100}, /* 00,01,00,dd */
376 {0xbb, 0x01, 0x0400}, /* 04,01,00,bb */
377 {0xa0, 0x01, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,01,cc */
378 {0xaa, 0xfe, 0x0002}, /* 00,fe,02,aa */
379 {0xa0, 0x0a, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,0a,cc */
380 {0xbb, 0x41, 0x2803}, /* 28,41,03,bb */
381 {0xbb, 0x40, 0x2c03}, /* 2c,40,03,bb */
382 {0xa0, 0x01, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,01,cc */
383 {0xaa, 0xfe, 0x0010}, /* 00,fe,10,aa */
384 {}
385};
386static const struct usb_action adcm2700_50HZ[] = {
387 {0xa0, 0x01, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,01,cc */
388 {0xaa, 0xfe, 0x0002}, /* 00,fe,02,aa */
389 {0xa0, 0x0a, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,0a,cc */
390 {0xbb, 0x05, 0x8400}, /* 84,05,00,bb */
391 {0xbb, 0xd0, 0xb007}, /* b0,d0,07,bb */
392 {0xbb, 0xa0, 0xb80f}, /* b8,a0,0f,bb */
393 {0xa0, 0x01, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,01,cc */
394 {0xaa, 0xfe, 0x0010}, /* 00,fe,10,aa */
395 {0xaa, 0x26, 0x00d0}, /* 00,26,d0,aa */
396 {0xaa, 0x28, 0x0002}, /* 00,28,02,aa */
397 {}
398};
399static const struct usb_action adcm2700_60HZ[] = {
400 {0xa0, 0x01, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,01,cc */
401 {0xaa, 0xfe, 0x0002}, /* 00,fe,02,aa */
402 {0xa0, 0x0a, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,0a,cc */
403 {0xbb, 0x07, 0x8400}, /* 84,07,00,bb */
404 {0xbb, 0x82, 0xb006}, /* b0,82,06,bb */
405 {0xbb, 0x04, 0xb80d}, /* b8,04,0d,bb */
406 {0xa0, 0x01, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,01,cc */
407 {0xaa, 0xfe, 0x0010}, /* 00,fe,10,aa */
408 {0xaa, 0x26, 0x0057}, /* 00,26,57,aa */
409 {0xaa, 0x28, 0x0002}, /* 00,28,02,aa */
410 {}
411};
412static const struct usb_action adcm2700_NoFliker[] = {
413 {0xa0, 0x01, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,01,cc */
414 {0xaa, 0xfe, 0x0002}, /* 00,fe,02,aa */
415 {0xa0, 0x0a, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,0a,cc */
416 {0xbb, 0x07, 0x8400}, /* 84,07,00,bb */
417 {0xbb, 0x05, 0xb000}, /* b0,05,00,bb */
418 {0xbb, 0xa0, 0xb801}, /* b8,a0,01,bb */
419 {0xa0, 0x01, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,01,cc */
420 {0xaa, 0xfe, 0x0010}, /* 00,fe,10,aa */
421 {}
422};
209static const struct usb_action cs2102_Initial[] = { 423static const struct usb_action cs2102_Initial[] = {
210 {0xa1, 0x01, 0x0008}, 424 {0xa1, 0x01, 0x0008},
211 {0xa1, 0x01, 0x0008}, 425 {0xa1, 0x01, 0x0008},
@@ -877,7 +1091,7 @@ static const struct usb_action cs2102K_Initial[] = {
877}; 1091};
878 1092
879static const struct usb_action cs2102K_InitialScale[] = { 1093static const struct usb_action cs2102K_InitialScale[] = {
880 {0xa0, 0x11, ZC3XX_R002_CLOCKSELECT}, 1094 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL},
881 {0xa0, 0x00, ZC3XX_R002_CLOCKSELECT}, 1095 {0xa0, 0x00, ZC3XX_R002_CLOCKSELECT},
882 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, 1096 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING},
883 {0xa0, 0x08, ZC3XX_R010_CMOSSENSORSELECT}, 1097 {0xa0, 0x08, ZC3XX_R010_CMOSSENSORSELECT},
@@ -894,6 +1108,7 @@ static const struct usb_action cs2102K_InitialScale[] = {
894 {0xa0, 0x00, ZC3XX_R11C_FIRSTXLOW}, 1108 {0xa0, 0x00, ZC3XX_R11C_FIRSTXLOW},
895 {0xa0, 0xe8, ZC3XX_R09C_WINHEIGHTLOW}, 1109 {0xa0, 0xe8, ZC3XX_R09C_WINHEIGHTLOW},
896 {0xa0, 0x88, ZC3XX_R09E_WINWIDTHLOW}, 1110 {0xa0, 0x88, ZC3XX_R09E_WINWIDTHLOW},
1111/*fixme: next sequence = i2c exchanges*/
897 {0xa0, 0x55, ZC3XX_R08B_I2CDEVICEADDR}, 1112 {0xa0, 0x55, ZC3XX_R08B_I2CDEVICEADDR},
898 {0xa0, 0x18, ZC3XX_R092_I2CADDRESSSELECT}, 1113 {0xa0, 0x18, ZC3XX_R092_I2CADDRESSSELECT},
899 {0xa0, 0x00, ZC3XX_R093_I2CSETVALUE}, 1114 {0xa0, 0x00, ZC3XX_R093_I2CSETVALUE},
@@ -1077,207 +1292,6 @@ static const struct usb_action cs2102K_InitialScale[] = {
1077 {0xa0, 0x60, ZC3XX_R116_RGAIN}, 1292 {0xa0, 0x60, ZC3XX_R116_RGAIN},
1078 {0xa0, 0x40, ZC3XX_R117_GGAIN}, 1293 {0xa0, 0x40, ZC3XX_R117_GGAIN},
1079 {0xa0, 0x4c, ZC3XX_R118_BGAIN}, 1294 {0xa0, 0x4c, ZC3XX_R118_BGAIN},
1080 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL},
1081 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL},
1082 {0xa0, 0x00, ZC3XX_R002_CLOCKSELECT},
1083 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING},
1084 {0xa0, 0x08, ZC3XX_R010_CMOSSENSORSELECT},
1085 {0xa0, 0x02, ZC3XX_R003_FRAMEWIDTHHIGH},
1086 {0xa0, 0x80, ZC3XX_R004_FRAMEWIDTHLOW},
1087 {0xa0, 0x01, ZC3XX_R005_FRAMEHEIGHTHIGH},
1088 {0xa0, 0xe0, ZC3XX_R006_FRAMEHEIGHTLOW},
1089 {0xa0, 0x01, ZC3XX_R001_SYSTEMOPERATING},
1090 {0xa0, 0x03, ZC3XX_R012_VIDEOCONTROLFUNC},
1091 {0xa0, 0x01, ZC3XX_R012_VIDEOCONTROLFUNC},
1092 {0xa0, 0x00, ZC3XX_R098_WINYSTARTLOW},
1093 {0xa0, 0x00, ZC3XX_R09A_WINXSTARTLOW},
1094 {0xa0, 0x00, ZC3XX_R11A_FIRSTYLOW},
1095 {0xa0, 0x00, ZC3XX_R11C_FIRSTXLOW},
1096 {0xa0, 0xe8, ZC3XX_R09C_WINHEIGHTLOW},
1097 {0xa0, 0x88, ZC3XX_R09E_WINWIDTHLOW},
1098 {0xa0, 0x55, ZC3XX_R08B_I2CDEVICEADDR},
1099 {0xa0, 0x18, ZC3XX_R092_I2CADDRESSSELECT},
1100 {0xa0, 0x00, ZC3XX_R093_I2CSETVALUE},
1101 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
1102 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
1103 {0xa0, 0x0A, ZC3XX_R092_I2CADDRESSSELECT},
1104 {0xa0, 0x02, ZC3XX_R093_I2CSETVALUE},
1105 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
1106 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
1107 {0xa0, 0x0B, ZC3XX_R092_I2CADDRESSSELECT},
1108 {0xa0, 0x02, ZC3XX_R093_I2CSETVALUE},
1109 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
1110 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
1111 {0xa0, 0x0C, ZC3XX_R092_I2CADDRESSSELECT},
1112 {0xa0, 0x7b, ZC3XX_R093_I2CSETVALUE},
1113 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
1114 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
1115 {0xa0, 0x0D, ZC3XX_R092_I2CADDRESSSELECT},
1116 {0xa0, 0xA3, ZC3XX_R093_I2CSETVALUE},
1117 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
1118 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
1119 {0xa0, 0x03, ZC3XX_R092_I2CADDRESSSELECT},
1120 {0xa0, 0xfb, ZC3XX_R093_I2CSETVALUE},
1121 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
1122 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
1123 {0xa0, 0x05, ZC3XX_R092_I2CADDRESSSELECT},
1124 {0xa0, 0x00, ZC3XX_R093_I2CSETVALUE},
1125 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
1126 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
1127 {0xa0, 0x06, ZC3XX_R092_I2CADDRESSSELECT},
1128 {0xa0, 0x03, ZC3XX_R093_I2CSETVALUE},
1129 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
1130 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
1131 {0xa0, 0x09, ZC3XX_R092_I2CADDRESSSELECT},
1132 {0xa0, 0x08, ZC3XX_R093_I2CSETVALUE},
1133 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
1134 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
1135 {0xa0, 0x0E, ZC3XX_R092_I2CADDRESSSELECT},
1136 {0xa0, 0x04, ZC3XX_R093_I2CSETVALUE},
1137 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
1138 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
1139 {0xa0, 0x0f, ZC3XX_R092_I2CADDRESSSELECT},
1140 {0xa0, 0x18, ZC3XX_R093_I2CSETVALUE},
1141 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
1142 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
1143 {0xa0, 0x10, ZC3XX_R092_I2CADDRESSSELECT},
1144 {0xa0, 0x18, ZC3XX_R093_I2CSETVALUE},
1145 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
1146 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
1147 {0xa0, 0x11, ZC3XX_R092_I2CADDRESSSELECT},
1148 {0xa0, 0x18, ZC3XX_R093_I2CSETVALUE},
1149 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
1150 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
1151 {0xa0, 0x12, ZC3XX_R092_I2CADDRESSSELECT},
1152 {0xa0, 0x18, ZC3XX_R093_I2CSETVALUE},
1153 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
1154 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
1155 {0xa0, 0x15, ZC3XX_R092_I2CADDRESSSELECT},
1156 {0xa0, 0x00, ZC3XX_R093_I2CSETVALUE},
1157 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
1158 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
1159 {0xa0, 0x16, ZC3XX_R092_I2CADDRESSSELECT},
1160 {0xa0, 0x0c, ZC3XX_R093_I2CSETVALUE},
1161 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
1162 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
1163 {0xa0, 0x17, ZC3XX_R092_I2CADDRESSSELECT},
1164 {0xa0, 0x0C, ZC3XX_R093_I2CSETVALUE},
1165 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
1166 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
1167 {0xa0, 0x18, ZC3XX_R092_I2CADDRESSSELECT},
1168 {0xa0, 0x04, ZC3XX_R093_I2CSETVALUE},
1169 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
1170 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
1171 {0xa0, 0xf7, ZC3XX_R101_SENSORCORRECTION},
1172 {0xa0, 0x05, ZC3XX_R012_VIDEOCONTROLFUNC},
1173 {0xa0, 0x78, ZC3XX_R18D_YTARGET},
1174 {0xa0, 0x0d, ZC3XX_R100_OPERATIONMODE},
1175 {0xa0, 0x06, ZC3XX_R189_AWBSTATUS},
1176 {0xa0, 0x03, ZC3XX_R1C5_SHARPNESSMODE},
1177 {0xa0, 0x13, ZC3XX_R1CB_SHARPNESS05},
1178 {0xa0, 0x20, ZC3XX_R087_EXPTIMEMID},
1179 {0xa0, 0x21, ZC3XX_R088_EXPTIMELOW},
1180 {0xa0, 0x08, ZC3XX_R250_DEADPIXELSMODE},
1181 {0xa0, 0x08, ZC3XX_R301_EEPROMACCESS},
1182 {0xa0, 0x00, 0x01ad},
1183 {0xa0, 0x01, 0x01b1},
1184 {0xa0, 0x02, ZC3XX_R180_AUTOCORRECTENABLE},
1185 {0xa0, 0x60, ZC3XX_R116_RGAIN},
1186 {0xa0, 0x40, ZC3XX_R117_GGAIN},
1187 {0xa0, 0x4c, ZC3XX_R118_BGAIN},
1188 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, /* clock ? */
1189 {0xa0, 0x08, ZC3XX_R1C6_SHARPNESS00}, /* sharpness+ */
1190 {0xa0, 0x0f, ZC3XX_R1CB_SHARPNESS05}, /* sharpness- */
1191 {0xa0, 0x13, ZC3XX_R120_GAMMA00}, /* gamma 4 */
1192 {0xa0, 0x38, ZC3XX_R121_GAMMA01},
1193 {0xa0, 0x59, ZC3XX_R122_GAMMA02},
1194 {0xa0, 0x79, ZC3XX_R123_GAMMA03},
1195 {0xa0, 0x92, ZC3XX_R124_GAMMA04},
1196 {0xa0, 0xa7, ZC3XX_R125_GAMMA05},
1197 {0xa0, 0xb9, ZC3XX_R126_GAMMA06},
1198 {0xa0, 0xc8, ZC3XX_R127_GAMMA07},
1199 {0xa0, 0xd4, ZC3XX_R128_GAMMA08},
1200 {0xa0, 0xdf, ZC3XX_R129_GAMMA09},
1201 {0xa0, 0xe7, ZC3XX_R12A_GAMMA0A},
1202 {0xa0, 0xee, ZC3XX_R12B_GAMMA0B},
1203 {0xa0, 0xf4, ZC3XX_R12C_GAMMA0C},
1204 {0xa0, 0xf9, ZC3XX_R12D_GAMMA0D},
1205 {0xa0, 0xfc, ZC3XX_R12E_GAMMA0E},
1206 {0xa0, 0xff, ZC3XX_R12F_GAMMA0F},
1207 {0xa0, 0x26, ZC3XX_R130_GAMMA10},
1208 {0xa0, 0x22, ZC3XX_R131_GAMMA11},
1209 {0xa0, 0x20, ZC3XX_R132_GAMMA12},
1210 {0xa0, 0x1c, ZC3XX_R133_GAMMA13},
1211 {0xa0, 0x16, ZC3XX_R134_GAMMA14},
1212 {0xa0, 0x13, ZC3XX_R135_GAMMA15},
1213 {0xa0, 0x10, ZC3XX_R136_GAMMA16},
1214 {0xa0, 0x0d, ZC3XX_R137_GAMMA17},
1215 {0xa0, 0x0b, ZC3XX_R138_GAMMA18},
1216 {0xa0, 0x09, ZC3XX_R139_GAMMA19},
1217 {0xa0, 0x07, ZC3XX_R13A_GAMMA1A},
1218 {0xa0, 0x06, ZC3XX_R13B_GAMMA1B},
1219 {0xa0, 0x05, ZC3XX_R13C_GAMMA1C},
1220 {0xa0, 0x04, ZC3XX_R13D_GAMMA1D},
1221 {0xa0, 0x03, ZC3XX_R13E_GAMMA1E},
1222 {0xa0, 0x02, ZC3XX_R13F_GAMMA1F},
1223 {0xa0, 0x58, ZC3XX_R10A_RGB00}, /* matrix */
1224 {0xa0, 0xf4, ZC3XX_R10B_RGB01},
1225 {0xa0, 0xf4, ZC3XX_R10C_RGB02},
1226 {0xa0, 0xf4, ZC3XX_R10D_RGB10},
1227 {0xa0, 0x58, ZC3XX_R10E_RGB11},
1228 {0xa0, 0xf4, ZC3XX_R10F_RGB12},
1229 {0xa0, 0xf4, ZC3XX_R110_RGB20},
1230 {0xa0, 0xf4, ZC3XX_R111_RGB21},
1231 {0xa0, 0x58, ZC3XX_R112_RGB22},
1232 {0xa0, 0x00, ZC3XX_R180_AUTOCORRECTENABLE},
1233 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS},
1234 {0xa0, 0x18, ZC3XX_R092_I2CADDRESSSELECT},
1235 {0xa0, 0x00, ZC3XX_R093_I2CSETVALUE},
1236 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
1237 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
1238 {0xa0, 0x13, ZC3XX_R092_I2CADDRESSSELECT},
1239 {0xa0, 0x22, ZC3XX_R093_I2CSETVALUE},
1240 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
1241 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
1242 {0xa0, 0x14, ZC3XX_R092_I2CADDRESSSELECT},
1243 {0xa0, 0x01, ZC3XX_R093_I2CSETVALUE},
1244 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
1245 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
1246 {0xa0, 0x20, ZC3XX_R092_I2CADDRESSSELECT},
1247 {0xa0, 0x01, ZC3XX_R093_I2CSETVALUE},
1248 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
1249 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
1250 {0xa0, 0x21, ZC3XX_R092_I2CADDRESSSELECT},
1251 {0xa0, 0x22, ZC3XX_R093_I2CSETVALUE},
1252 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
1253 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
1254 {0xa0, 0x18, ZC3XX_R092_I2CADDRESSSELECT},
1255 {0xa0, 0x04, ZC3XX_R093_I2CSETVALUE},
1256 {0xa0, 0x00, ZC3XX_R094_I2CWRITEACK},
1257 {0xa0, 0x01, ZC3XX_R090_I2CCOMMAND},
1258 {0xa0, 0x01, ZC3XX_R0A3_EXPOSURETIMEHIGH},
1259 {0xa0, 0x22, ZC3XX_R0A4_EXPOSURETIMELOW},
1260 {0xa0, 0x00, ZC3XX_R190_EXPOSURELIMITHIGH},
1261 {0xa0, 0x07, ZC3XX_R191_EXPOSURELIMITMID},
1262 {0xa0, 0xee, ZC3XX_R192_EXPOSURELIMITLOW},
1263 {0xa0, 0x00, ZC3XX_R195_ANTIFLICKERHIGH},
1264 {0xa0, 0x00, ZC3XX_R196_ANTIFLICKERMID},
1265 {0xa0, 0x3a, ZC3XX_R197_ANTIFLICKERLOW},
1266 {0xa0, 0x10, ZC3XX_R18C_AEFREEZE},
1267 {0xa0, 0x20, ZC3XX_R18F_AEUNFREEZE},
1268 {0xa0, 0x0c, ZC3XX_R1A9_DIGITALLIMITDIFF},
1269 {0xa0, 0x28, ZC3XX_R1AA_DIGITALGAINSTEP},
1270 {0xa0, 0x04, ZC3XX_R01D_HSYNC_0},
1271 {0xa0, 0x0f, ZC3XX_R01E_HSYNC_1},
1272 {0xa0, 0x19, ZC3XX_R01F_HSYNC_2},
1273 {0xa0, 0x1f, ZC3XX_R020_HSYNC_3},
1274 {0xa0, 0x60, ZC3XX_R11D_GLOBALGAIN},
1275 {0xa0, 0x60, ZC3XX_R11D_GLOBALGAIN},
1276 {0xa0, 0x42, ZC3XX_R180_AUTOCORRECTENABLE},
1277 {0xa0, 0x42, ZC3XX_R180_AUTOCORRECTENABLE},
1278 {0xa0, 0x60, ZC3XX_R116_RGAIN},
1279 {0xa0, 0x40, ZC3XX_R117_GGAIN},
1280 {0xa0, 0x4c, ZC3XX_R118_BGAIN},
1281 {0xa0, 0x04, ZC3XX_R1A7_CALCGLOBALMEAN}, 1295 {0xa0, 0x04, ZC3XX_R1A7_CALCGLOBALMEAN},
1282 {0xa0, 0x20, ZC3XX_R092_I2CADDRESSSELECT}, 1296 {0xa0, 0x20, ZC3XX_R092_I2CADDRESSSELECT},
1283 {0xa0, 0x01, ZC3XX_R093_I2CSETVALUE}, 1297 {0xa0, 0x01, ZC3XX_R093_I2CSETVALUE},
@@ -1334,6 +1348,7 @@ static const struct usb_action cs2102K_InitialScale[] = {
1334 {0xa0, 0x00, ZC3XX_R1A7_CALCGLOBALMEAN}, 1348 {0xa0, 0x00, ZC3XX_R1A7_CALCGLOBALMEAN},
1335 {0xa0, 0x04, ZC3XX_R1A7_CALCGLOBALMEAN}, 1349 {0xa0, 0x04, ZC3XX_R1A7_CALCGLOBALMEAN},
1336 {0xa0, 0x00, ZC3XX_R1A7_CALCGLOBALMEAN}, 1350 {0xa0, 0x00, ZC3XX_R1A7_CALCGLOBALMEAN},
1351/*fixme:what does the next sequence?*/
1337 {0xa0, 0x04, ZC3XX_R1A7_CALCGLOBALMEAN}, 1352 {0xa0, 0x04, ZC3XX_R1A7_CALCGLOBALMEAN},
1338 {0xa0, 0x00, ZC3XX_R1A7_CALCGLOBALMEAN}, 1353 {0xa0, 0x00, ZC3XX_R1A7_CALCGLOBALMEAN},
1339 {0xa0, 0x04, ZC3XX_R1A7_CALCGLOBALMEAN}, 1354 {0xa0, 0x04, ZC3XX_R1A7_CALCGLOBALMEAN},
@@ -6237,7 +6252,7 @@ static const struct usb_action tas5130c_vf0250_NoFlikerScale[] = {
6237 {} 6252 {}
6238}; 6253};
6239 6254
6240static int reg_r_i(struct gspca_dev *gspca_dev, 6255static u8 reg_r_i(struct gspca_dev *gspca_dev,
6241 __u16 index) 6256 __u16 index)
6242{ 6257{
6243 usb_control_msg(gspca_dev->dev, 6258 usb_control_msg(gspca_dev->dev,
@@ -6250,10 +6265,10 @@ static int reg_r_i(struct gspca_dev *gspca_dev,
6250 return gspca_dev->usb_buf[0]; 6265 return gspca_dev->usb_buf[0];
6251} 6266}
6252 6267
6253static int reg_r(struct gspca_dev *gspca_dev, 6268static u8 reg_r(struct gspca_dev *gspca_dev,
6254 __u16 index) 6269 __u16 index)
6255{ 6270{
6256 int ret; 6271 u8 ret;
6257 6272
6258 ret = reg_r_i(gspca_dev, index); 6273 ret = reg_r_i(gspca_dev, index);
6259 PDEBUG(D_USBI, "reg r [%04x] -> %02x", index, ret); 6274 PDEBUG(D_USBI, "reg r [%04x] -> %02x", index, ret);
@@ -6286,8 +6301,8 @@ static __u16 i2c_read(struct gspca_dev *gspca_dev,
6286 __u8 retbyte; 6301 __u8 retbyte;
6287 __u16 retval; 6302 __u16 retval;
6288 6303
6289 reg_w_i(gspca_dev->dev, reg, 0x92); 6304 reg_w_i(gspca_dev->dev, reg, 0x0092);
6290 reg_w_i(gspca_dev->dev, 0x02, 0x90); /* <- read command */ 6305 reg_w_i(gspca_dev->dev, 0x02, 0x0090); /* <- read command */
6291 msleep(25); 6306 msleep(25);
6292 retbyte = reg_r_i(gspca_dev, 0x0091); /* read status */ 6307 retbyte = reg_r_i(gspca_dev, 0x0091); /* read status */
6293 retval = reg_r_i(gspca_dev, 0x0095); /* read Lowbyte */ 6308 retval = reg_r_i(gspca_dev, 0x0095); /* read Lowbyte */
@@ -6332,6 +6347,12 @@ static void usb_exchange(struct gspca_dev *gspca_dev,
6332 action->idx & 0xff, /* valL */ 6347 action->idx & 0xff, /* valL */
6333 action->idx >> 8); /* valH */ 6348 action->idx >> 8); /* valH */
6334 break; 6349 break;
6350 case 0xbb:
6351 i2c_write(gspca_dev,
6352 action->idx >> 8, /* reg */
6353 action->idx & 0xff, /* valL */
6354 action->val); /* valH */
6355 break;
6335 default: 6356 default:
6336/* case 0xdd: * delay */ 6357/* case 0xdd: * delay */
6337 msleep(action->val / 64 + 10); 6358 msleep(action->val / 64 + 10);
@@ -6347,6 +6368,10 @@ static void setmatrix(struct gspca_dev *gspca_dev)
6347 struct sd *sd = (struct sd *) gspca_dev; 6368 struct sd *sd = (struct sd *) gspca_dev;
6348 int i; 6369 int i;
6349 const __u8 *matrix; 6370 const __u8 *matrix;
6371 static const u8 adcm2700_matrix[9] =
6372/* {0x66, 0xed, 0xed, 0xed, 0x66, 0xed, 0xed, 0xed, 0x66}; */
6373/*ms-win*/
6374 {0x74, 0xed, 0xed, 0xed, 0x74, 0xed, 0xed, 0xed, 0x74};
6350 static const __u8 gc0305_matrix[9] = 6375 static const __u8 gc0305_matrix[9] =
6351 {0x50, 0xf8, 0xf8, 0xf8, 0x50, 0xf8, 0xf8, 0xf8, 0x50}; 6376 {0x50, 0xf8, 0xf8, 0xf8, 0x50, 0xf8, 0xf8, 0xf8, 0x50};
6352 static const __u8 ov7620_matrix[9] = 6377 static const __u8 ov7620_matrix[9] =
@@ -6358,23 +6383,24 @@ static void setmatrix(struct gspca_dev *gspca_dev)
6358 static const __u8 vf0250_matrix[9] = 6383 static const __u8 vf0250_matrix[9] =
6359 {0x7b, 0xea, 0xea, 0xea, 0x7b, 0xea, 0xea, 0xea, 0x7b}; 6384 {0x7b, 0xea, 0xea, 0xea, 0x7b, 0xea, 0xea, 0xea, 0x7b};
6360 static const __u8 *matrix_tb[SENSOR_MAX] = { 6385 static const __u8 *matrix_tb[SENSOR_MAX] = {
6361 NULL, /* SENSOR_CS2102 0 */ 6386 adcm2700_matrix, /* SENSOR_ADCM2700 0 */
6362 NULL, /* SENSOR_CS2102K 1 */ 6387 NULL, /* SENSOR_CS2102 1 */
6363 gc0305_matrix, /* SENSOR_GC0305 2 */ 6388 NULL, /* SENSOR_CS2102K 2 */
6364 NULL, /* SENSOR_HDCS2020b 3 */ 6389 gc0305_matrix, /* SENSOR_GC0305 3 */
6365 NULL, /* SENSOR_HV7131B 4 */ 6390 NULL, /* SENSOR_HDCS2020b 4 */
6366 NULL, /* SENSOR_HV7131C 5 */ 6391 NULL, /* SENSOR_HV7131B 5 */
6367 NULL, /* SENSOR_ICM105A 6 */ 6392 NULL, /* SENSOR_HV7131C 6 */
6368 NULL, /* SENSOR_MC501CB 7 */ 6393 NULL, /* SENSOR_ICM105A 7 */
6369 ov7620_matrix, /* SENSOR_OV7620 8 */ 6394 NULL, /* SENSOR_MC501CB 8 */
6370 NULL, /* SENSOR_OV7630C 9 */ 6395 ov7620_matrix, /* SENSOR_OV7620 9 */
6371 NULL, /* SENSOR_PAS106 10 */ 6396 NULL, /* SENSOR_OV7630C 10 */
6372 pas202b_matrix, /* SENSOR_PAS202B 11 */ 6397 NULL, /* SENSOR_PAS106 11 */
6373 NULL, /* SENSOR_PB0330 12 */ 6398 pas202b_matrix, /* SENSOR_PAS202B 12 */
6374 po2030_matrix, /* SENSOR_PO2030 13 */ 6399 NULL, /* SENSOR_PB0330 13 */
6375 NULL, /* SENSOR_TAS5130CK 14 */ 6400 po2030_matrix, /* SENSOR_PO2030 14 */
6376 NULL, /* SENSOR_TAS5130CXX 15 */ 6401 NULL, /* SENSOR_TAS5130CK 15 */
6377 vf0250_matrix, /* SENSOR_TAS5130C_VF0250 16 */ 6402 NULL, /* SENSOR_TAS5130CXX 16 */
6403 vf0250_matrix, /* SENSOR_TAS5130C_VF0250 17 */
6378 }; 6404 };
6379 6405
6380 matrix = matrix_tb[sd->sensor]; 6406 matrix = matrix_tb[sd->sensor];
@@ -6398,8 +6424,11 @@ static void setbrightness(struct gspca_dev *gspca_dev)
6398/*fixme: is it really write to 011d and 018d for all other sensors? */ 6424/*fixme: is it really write to 011d and 018d for all other sensors? */
6399 brightness = sd->brightness; 6425 brightness = sd->brightness;
6400 reg_w(gspca_dev->dev, brightness, 0x011d); 6426 reg_w(gspca_dev->dev, brightness, 0x011d);
6401 if (sd->sensor == SENSOR_HV7131B) 6427 switch (sd->sensor) {
6428 case SENSOR_ADCM2700:
6429 case SENSOR_HV7131B:
6402 return; 6430 return;
6431 }
6403 if (brightness < 0x70) 6432 if (brightness < 0x70)
6404 brightness += 0x10; 6433 brightness += 0x10;
6405 else 6434 else
@@ -6536,10 +6565,10 @@ static void setquality(struct gspca_dev *gspca_dev)
6536{ 6565{
6537 struct sd *sd = (struct sd *) gspca_dev; 6566 struct sd *sd = (struct sd *) gspca_dev;
6538 struct usb_device *dev = gspca_dev->dev; 6567 struct usb_device *dev = gspca_dev->dev;
6539 __u8 quality;
6540 __u8 frxt; 6568 __u8 frxt;
6541 6569
6542 switch (sd->sensor) { 6570 switch (sd->sensor) {
6571 case SENSOR_ADCM2700:
6543 case SENSOR_GC0305: 6572 case SENSOR_GC0305:
6544 case SENSOR_HV7131B: 6573 case SENSOR_HV7131B:
6545 case SENSOR_OV7620: 6574 case SENSOR_OV7620:
@@ -6547,26 +6576,18 @@ static void setquality(struct gspca_dev *gspca_dev)
6547 return; 6576 return;
6548 } 6577 }
6549/*fixme: is it really 0008 0007 0018 for all other sensors? */ 6578/*fixme: is it really 0008 0007 0018 for all other sensors? */
6550 quality = sd->qindex; 6579 reg_w(dev, QUANT_VAL, 0x0008);
6551 reg_w(dev, quality, 0x0008);
6552 frxt = 0x30; 6580 frxt = 0x30;
6553 reg_w(dev, frxt, 0x0007); 6581 reg_w(dev, frxt, 0x0007);
6554 switch (quality) { 6582#if QUANT_VAL == 0 || QUANT_VAL == 1 || QUANT_VAL == 2
6555 case 0: 6583 frxt = 0xff;
6556 case 1: 6584#elif QUANT_VAL == 3
6557 case 2: 6585 frxt = 0xf0;
6558 frxt = 0xff; 6586#elif QUANT_VAL == 4
6559 break; 6587 frxt = 0xe0;
6560 case 3: 6588#else
6561 frxt = 0xf0; 6589 frxt = 0x20;
6562 break; 6590#endif
6563 case 4:
6564 frxt = 0xe0;
6565 break;
6566 case 5:
6567 frxt = 0x20;
6568 break;
6569 }
6570 reg_w(dev, frxt, 0x0018); 6591 reg_w(dev, frxt, 0x0018);
6571} 6592}
6572 6593
@@ -6583,71 +6604,75 @@ static int setlightfreq(struct gspca_dev *gspca_dev)
6583 int i, mode; 6604 int i, mode;
6584 const struct usb_action *zc3_freq; 6605 const struct usb_action *zc3_freq;
6585 static const struct usb_action *freq_tb[SENSOR_MAX][6] = { 6606 static const struct usb_action *freq_tb[SENSOR_MAX][6] = {
6586/* SENSOR_CS2102 0 */ 6607/* SENSOR_ADCM2700 0 */
6608 {adcm2700_NoFliker, adcm2700_NoFliker,
6609 adcm2700_50HZ, adcm2700_50HZ,
6610 adcm2700_60HZ, adcm2700_60HZ},
6611/* SENSOR_CS2102 1 */
6587 {cs2102_NoFliker, cs2102_NoFlikerScale, 6612 {cs2102_NoFliker, cs2102_NoFlikerScale,
6588 cs2102_50HZ, cs2102_50HZScale, 6613 cs2102_50HZ, cs2102_50HZScale,
6589 cs2102_60HZ, cs2102_60HZScale}, 6614 cs2102_60HZ, cs2102_60HZScale},
6590/* SENSOR_CS2102K 1 */ 6615/* SENSOR_CS2102K 2 */
6591 {cs2102_NoFliker, cs2102_NoFlikerScale, 6616 {cs2102_NoFliker, cs2102_NoFlikerScale,
6592 NULL, NULL, /* currently disabled */ 6617 NULL, NULL, /* currently disabled */
6593 NULL, NULL}, 6618 NULL, NULL},
6594/* SENSOR_GC0305 2 */ 6619/* SENSOR_GC0305 3 */
6595 {gc0305_NoFliker, gc0305_NoFliker, 6620 {gc0305_NoFliker, gc0305_NoFliker,
6596 gc0305_50HZ, gc0305_50HZ, 6621 gc0305_50HZ, gc0305_50HZ,
6597 gc0305_60HZ, gc0305_60HZ}, 6622 gc0305_60HZ, gc0305_60HZ},
6598/* SENSOR_HDCS2020b 3 */ 6623/* SENSOR_HDCS2020b 4 */
6599 {hdcs2020b_NoFliker, hdcs2020b_NoFliker, 6624 {hdcs2020b_NoFliker, hdcs2020b_NoFliker,
6600 hdcs2020b_50HZ, hdcs2020b_50HZ, 6625 hdcs2020b_50HZ, hdcs2020b_50HZ,
6601 hdcs2020b_60HZ, hdcs2020b_60HZ}, 6626 hdcs2020b_60HZ, hdcs2020b_60HZ},
6602/* SENSOR_HV7131B 4 */ 6627/* SENSOR_HV7131B 5 */
6603 {hv7131b_NoFlikerScale, hv7131b_NoFliker, 6628 {hv7131b_NoFlikerScale, hv7131b_NoFliker,
6604 hv7131b_50HZScale, hv7131b_50HZ, 6629 hv7131b_50HZScale, hv7131b_50HZ,
6605 hv7131b_60HZScale, hv7131b_60HZ}, 6630 hv7131b_60HZScale, hv7131b_60HZ},
6606/* SENSOR_HV7131C 5 */ 6631/* SENSOR_HV7131C 6 */
6607 {NULL, NULL, 6632 {NULL, NULL,
6608 NULL, NULL, 6633 NULL, NULL,
6609 NULL, NULL}, 6634 NULL, NULL},
6610/* SENSOR_ICM105A 6 */ 6635/* SENSOR_ICM105A 7 */
6611 {icm105a_NoFliker, icm105a_NoFlikerScale, 6636 {icm105a_NoFliker, icm105a_NoFlikerScale,
6612 icm105a_50HZ, icm105a_50HZScale, 6637 icm105a_50HZ, icm105a_50HZScale,
6613 icm105a_60HZ, icm105a_60HZScale}, 6638 icm105a_60HZ, icm105a_60HZScale},
6614/* SENSOR_MC501CB 7 */ 6639/* SENSOR_MC501CB 8 */
6615 {MC501CB_NoFliker, MC501CB_NoFlikerScale, 6640 {MC501CB_NoFliker, MC501CB_NoFlikerScale,
6616 MC501CB_50HZ, MC501CB_50HZScale, 6641 MC501CB_50HZ, MC501CB_50HZScale,
6617 MC501CB_60HZ, MC501CB_60HZScale}, 6642 MC501CB_60HZ, MC501CB_60HZScale},
6618/* SENSOR_OV7620 8 */ 6643/* SENSOR_OV7620 9 */
6619 {OV7620_NoFliker, OV7620_NoFliker, 6644 {OV7620_NoFliker, OV7620_NoFliker,
6620 OV7620_50HZ, OV7620_50HZ, 6645 OV7620_50HZ, OV7620_50HZ,
6621 OV7620_60HZ, OV7620_60HZ}, 6646 OV7620_60HZ, OV7620_60HZ},
6622/* SENSOR_OV7630C 9 */ 6647/* SENSOR_OV7630C 10 */
6623 {NULL, NULL, 6648 {NULL, NULL,
6624 NULL, NULL, 6649 NULL, NULL,
6625 NULL, NULL}, 6650 NULL, NULL},
6626/* SENSOR_PAS106 10 */ 6651/* SENSOR_PAS106 11 */
6627 {pas106b_NoFliker, pas106b_NoFliker, 6652 {pas106b_NoFliker, pas106b_NoFliker,
6628 pas106b_50HZ, pas106b_50HZ, 6653 pas106b_50HZ, pas106b_50HZ,
6629 pas106b_60HZ, pas106b_60HZ}, 6654 pas106b_60HZ, pas106b_60HZ},
6630/* SENSOR_PAS202B 11 */ 6655/* SENSOR_PAS202B 12 */
6631 {pas202b_NoFlikerScale, pas202b_NoFliker, 6656 {pas202b_NoFlikerScale, pas202b_NoFliker,
6632 pas202b_50HZScale, pas202b_50HZ, 6657 pas202b_50HZScale, pas202b_50HZ,
6633 pas202b_60HZScale, pas202b_60HZ}, 6658 pas202b_60HZScale, pas202b_60HZ},
6634/* SENSOR_PB0330 12 */ 6659/* SENSOR_PB0330 13 */
6635 {pb0330_NoFliker, pb0330_NoFlikerScale, 6660 {pb0330_NoFliker, pb0330_NoFlikerScale,
6636 pb0330_50HZ, pb0330_50HZScale, 6661 pb0330_50HZ, pb0330_50HZScale,
6637 pb0330_60HZ, pb0330_60HZScale}, 6662 pb0330_60HZ, pb0330_60HZScale},
6638/* SENSOR_PO2030 13 */ 6663/* SENSOR_PO2030 14 */
6639 {PO2030_NoFliker, PO2030_NoFliker, 6664 {PO2030_NoFliker, PO2030_NoFliker,
6640 PO2030_50HZ, PO2030_50HZ, 6665 PO2030_50HZ, PO2030_50HZ,
6641 PO2030_60HZ, PO2030_60HZ}, 6666 PO2030_60HZ, PO2030_60HZ},
6642/* SENSOR_TAS5130CK 14 */ 6667/* SENSOR_TAS5130CK 15 */
6643 {tas5130cxx_NoFliker, tas5130cxx_NoFlikerScale, 6668 {tas5130cxx_NoFliker, tas5130cxx_NoFlikerScale,
6644 tas5130cxx_50HZ, tas5130cxx_50HZScale, 6669 tas5130cxx_50HZ, tas5130cxx_50HZScale,
6645 tas5130cxx_60HZ, tas5130cxx_60HZScale}, 6670 tas5130cxx_60HZ, tas5130cxx_60HZScale},
6646/* SENSOR_TAS5130CXX 15 */ 6671/* SENSOR_TAS5130CXX 16 */
6647 {tas5130cxx_NoFliker, tas5130cxx_NoFlikerScale, 6672 {tas5130cxx_NoFliker, tas5130cxx_NoFlikerScale,
6648 tas5130cxx_50HZ, tas5130cxx_50HZScale, 6673 tas5130cxx_50HZ, tas5130cxx_50HZScale,
6649 tas5130cxx_60HZ, tas5130cxx_60HZScale}, 6674 tas5130cxx_60HZ, tas5130cxx_60HZScale},
6650/* SENSOR_TAS5130C_VF0250 16 */ 6675/* SENSOR_TAS5130C_VF0250 17 */
6651 {tas5130c_vf0250_NoFliker, tas5130c_vf0250_NoFlikerScale, 6676 {tas5130c_vf0250_NoFliker, tas5130c_vf0250_NoFlikerScale,
6652 tas5130c_vf0250_50HZ, tas5130c_vf0250_50HZScale, 6677 tas5130c_vf0250_50HZ, tas5130c_vf0250_50HZScale,
6653 tas5130c_vf0250_60HZ, tas5130c_vf0250_60HZScale}, 6678 tas5130c_vf0250_60HZ, tas5130c_vf0250_60HZScale},
@@ -6701,6 +6726,7 @@ static void send_unknown(struct usb_device *dev, int sensor)
6701 reg_w(dev, 0x0c, 0x003b); 6726 reg_w(dev, 0x0c, 0x003b);
6702 reg_w(dev, 0x08, 0x0038); 6727 reg_w(dev, 0x08, 0x0038);
6703 break; 6728 break;
6729 case SENSOR_ADCM2700:
6704 case SENSOR_GC0305: 6730 case SENSOR_GC0305:
6705 case SENSOR_OV7620: 6731 case SENSOR_OV7620:
6706 case SENSOR_PB0330: 6732 case SENSOR_PB0330:
@@ -6743,26 +6769,25 @@ static int sif_probe(struct gspca_dev *gspca_dev)
6743static int vga_2wr_probe(struct gspca_dev *gspca_dev) 6769static int vga_2wr_probe(struct gspca_dev *gspca_dev)
6744{ 6770{
6745 struct usb_device *dev = gspca_dev->dev; 6771 struct usb_device *dev = gspca_dev->dev;
6746 __u8 retbyte; 6772 u16 retword;
6747 __u16 checkword;
6748 6773
6749 start_2wr_probe(dev, 0x00); /* HV7131B */ 6774 start_2wr_probe(dev, 0x00); /* HV7131B */
6750 i2c_write(gspca_dev, 0x01, 0xaa, 0x00); 6775 i2c_write(gspca_dev, 0x01, 0xaa, 0x00);
6751 retbyte = i2c_read(gspca_dev, 0x01); 6776 retword = i2c_read(gspca_dev, 0x01);
6752 if (retbyte != 0) 6777 if (retword != 0)
6753 return 0x00; /* HV7131B */ 6778 return 0x00; /* HV7131B */
6754 6779
6755 start_2wr_probe(dev, 0x04); /* CS2102 */ 6780 start_2wr_probe(dev, 0x04); /* CS2102 */
6756 i2c_write(gspca_dev, 0x01, 0xaa, 0x00); 6781 i2c_write(gspca_dev, 0x01, 0xaa, 0x00);
6757 retbyte = i2c_read(gspca_dev, 0x01); 6782 retword = i2c_read(gspca_dev, 0x01);
6758 if (retbyte != 0) 6783 if (retword != 0)
6759 return 0x04; /* CS2102 */ 6784 return 0x04; /* CS2102 */
6760 6785
6761 start_2wr_probe(dev, 0x06); /* OmniVision */ 6786 start_2wr_probe(dev, 0x06); /* OmniVision */
6762 reg_w(dev, 0x08, 0x008d); 6787 reg_w(dev, 0x08, 0x008d);
6763 i2c_write(gspca_dev, 0x11, 0xaa, 0x00); 6788 i2c_write(gspca_dev, 0x11, 0xaa, 0x00);
6764 retbyte = i2c_read(gspca_dev, 0x11); 6789 retword = i2c_read(gspca_dev, 0x11);
6765 if (retbyte != 0) { 6790 if (retword != 0) {
6766 /* (should have returned 0xaa) --> Omnivision? */ 6791 /* (should have returned 0xaa) --> Omnivision? */
6767 /* reg_r 0x10 -> 0x06 --> */ 6792 /* reg_r 0x10 -> 0x06 --> */
6768 goto ov_check; 6793 goto ov_check;
@@ -6770,40 +6795,40 @@ static int vga_2wr_probe(struct gspca_dev *gspca_dev)
6770 6795
6771 start_2wr_probe(dev, 0x08); /* HDCS2020 */ 6796 start_2wr_probe(dev, 0x08); /* HDCS2020 */
6772 i2c_write(gspca_dev, 0x15, 0xaa, 0x00); 6797 i2c_write(gspca_dev, 0x15, 0xaa, 0x00);
6773 retbyte = i2c_read(gspca_dev, 0x15); 6798 retword = i2c_read(gspca_dev, 0x15);
6774 if (retbyte != 0) 6799 if (retword != 0)
6775 return 0x08; /* HDCS2020 */ 6800 return 0x08; /* HDCS2020 */
6776 6801
6777 start_2wr_probe(dev, 0x0a); /* PB0330 */ 6802 start_2wr_probe(dev, 0x0a); /* PB0330 */
6778 i2c_write(gspca_dev, 0x07, 0xaa, 0xaa); 6803 i2c_write(gspca_dev, 0x07, 0xaa, 0xaa);
6779 retbyte = i2c_read(gspca_dev, 0x07); 6804 retword = i2c_read(gspca_dev, 0x07);
6780 if (retbyte != 0) 6805 if (retword != 0)
6781 return 0x0a; /* PB0330 */ 6806 return 0x0a; /* PB0330 */
6782 retbyte = i2c_read(gspca_dev, 0x03); 6807 retword = i2c_read(gspca_dev, 0x03);
6783 if (retbyte != 0) 6808 if (retword != 0)
6784 return 0x0a; /* PB0330 ?? */ 6809 return 0x0a; /* PB0330 ?? */
6785 retbyte = i2c_read(gspca_dev, 0x04); 6810 retword = i2c_read(gspca_dev, 0x04);
6786 if (retbyte != 0) 6811 if (retword != 0)
6787 return 0x0a; /* PB0330 ?? */ 6812 return 0x0a; /* PB0330 ?? */
6788 6813
6789 start_2wr_probe(dev, 0x0c); /* ICM105A */ 6814 start_2wr_probe(dev, 0x0c); /* ICM105A */
6790 i2c_write(gspca_dev, 0x01, 0x11, 0x00); 6815 i2c_write(gspca_dev, 0x01, 0x11, 0x00);
6791 retbyte = i2c_read(gspca_dev, 0x01); 6816 retword = i2c_read(gspca_dev, 0x01);
6792 if (retbyte != 0) 6817 if (retword != 0)
6793 return 0x0c; /* ICM105A */ 6818 return 0x0c; /* ICM105A */
6794 6819
6795 start_2wr_probe(dev, 0x0e); /* PAS202BCB */ 6820 start_2wr_probe(dev, 0x0e); /* PAS202BCB */
6796 reg_w(dev, 0x08, 0x008d); 6821 reg_w(dev, 0x08, 0x008d);
6797 i2c_write(gspca_dev, 0x03, 0xaa, 0x00); 6822 i2c_write(gspca_dev, 0x03, 0xaa, 0x00);
6798 msleep(500); 6823 msleep(500);
6799 retbyte = i2c_read(gspca_dev, 0x03); 6824 retword = i2c_read(gspca_dev, 0x03);
6800 if (retbyte != 0) 6825 if (retword != 0)
6801 return 0x0e; /* PAS202BCB */ 6826 return 0x0e; /* PAS202BCB */
6802 6827
6803 start_2wr_probe(dev, 0x02); /* ?? */ 6828 start_2wr_probe(dev, 0x02); /* ?? */
6804 i2c_write(gspca_dev, 0x01, 0xaa, 0x00); 6829 i2c_write(gspca_dev, 0x01, 0xaa, 0x00);
6805 retbyte = i2c_read(gspca_dev, 0x01); 6830 retword = i2c_read(gspca_dev, 0x01);
6806 if (retbyte != 0) 6831 if (retword != 0)
6807 return 0x02; /* ?? */ 6832 return 0x02; /* ?? */
6808ov_check: 6833ov_check:
6809 reg_r(gspca_dev, 0x0010); /* ?? */ 6834 reg_r(gspca_dev, 0x0010); /* ?? */
@@ -6817,12 +6842,10 @@ ov_check:
6817 msleep(500); 6842 msleep(500);
6818 reg_w(dev, 0x01, 0x0012); 6843 reg_w(dev, 0x01, 0x0012);
6819 i2c_write(gspca_dev, 0x12, 0x80, 0x00); /* sensor reset */ 6844 i2c_write(gspca_dev, 0x12, 0x80, 0x00); /* sensor reset */
6820 retbyte = i2c_read(gspca_dev, 0x0a); 6845 retword = i2c_read(gspca_dev, 0x0a) << 8;
6821 checkword = retbyte << 8; 6846 retword |= i2c_read(gspca_dev, 0x0b);
6822 retbyte = i2c_read(gspca_dev, 0x0b); 6847 PDEBUG(D_PROBE, "probe 2wr ov vga 0x%04x", retword);
6823 checkword |= retbyte; 6848 switch (retword) {
6824 PDEBUG(D_PROBE, "probe 2wr ov vga 0x%04x", checkword);
6825 switch (checkword) {
6826 case 0x7631: /* OV7630C */ 6849 case 0x7631: /* OV7630C */
6827 reg_w(dev, 0x06, 0x0010); 6850 reg_w(dev, 0x06, 0x0010);
6828 break; 6851 break;
@@ -6832,7 +6855,7 @@ ov_check:
6832 default: 6855 default:
6833 return -1; /* not OmniVision */ 6856 return -1; /* not OmniVision */
6834 } 6857 }
6835 return checkword; 6858 return retword;
6836} 6859}
6837 6860
6838struct sensor_by_chipset_revision { 6861struct sensor_by_chipset_revision {
@@ -6845,6 +6868,7 @@ static const struct sensor_by_chipset_revision chipset_revision_sensor[] = {
6845 {0x8001, 0x13}, 6868 {0x8001, 0x13},
6846 {0x8000, 0x14}, /* CS2102K */ 6869 {0x8000, 0x14}, /* CS2102K */
6847 {0x8400, 0x15}, /* TAS5130K */ 6870 {0x8400, 0x15}, /* TAS5130K */
6871 {0x4001, 0x16}, /* ADCM2700 */
6848}; 6872};
6849 6873
6850static int vga_3wr_probe(struct gspca_dev *gspca_dev) 6874static int vga_3wr_probe(struct gspca_dev *gspca_dev)
@@ -6853,7 +6877,7 @@ static int vga_3wr_probe(struct gspca_dev *gspca_dev)
6853 struct usb_device *dev = gspca_dev->dev; 6877 struct usb_device *dev = gspca_dev->dev;
6854 int i; 6878 int i;
6855 __u8 retbyte; 6879 __u8 retbyte;
6856 __u16 checkword; 6880 u16 retword;
6857 6881
6858/*fixme: lack of 8b=b3 (11,12)-> 10, 8b=e0 (14,15,16)-> 12 found in gspcav1*/ 6882/*fixme: lack of 8b=b3 (11,12)-> 10, 8b=e0 (14,15,16)-> 12 found in gspcav1*/
6859 reg_w(dev, 0x02, 0x0010); 6883 reg_w(dev, 0x02, 0x0010);
@@ -6865,27 +6889,25 @@ static int vga_3wr_probe(struct gspca_dev *gspca_dev)
6865 reg_w(dev, 0x03, 0x0012); 6889 reg_w(dev, 0x03, 0x0012);
6866 reg_w(dev, 0x01, 0x0012); 6890 reg_w(dev, 0x01, 0x0012);
6867 reg_w(dev, 0x05, 0x0012); 6891 reg_w(dev, 0x05, 0x0012);
6868 retbyte = i2c_read(gspca_dev, 0x14); 6892 retword = i2c_read(gspca_dev, 0x14);
6869 if (retbyte != 0) 6893 if (retword != 0)
6870 return 0x11; /* HV7131R */ 6894 return 0x11; /* HV7131R */
6871 retbyte = i2c_read(gspca_dev, 0x15); 6895 retword = i2c_read(gspca_dev, 0x15);
6872 if (retbyte != 0) 6896 if (retword != 0)
6873 return 0x11; /* HV7131R */ 6897 return 0x11; /* HV7131R */
6874 retbyte = i2c_read(gspca_dev, 0x16); 6898 retword = i2c_read(gspca_dev, 0x16);
6875 if (retbyte != 0) 6899 if (retword != 0)
6876 return 0x11; /* HV7131R */ 6900 return 0x11; /* HV7131R */
6877 6901
6878 reg_w(dev, 0x02, 0x0010); 6902 reg_w(dev, 0x02, 0x0010);
6879 retbyte = reg_r(gspca_dev, 0x000b); 6903 retword = reg_r(gspca_dev, 0x000b) << 8;
6880 checkword = retbyte << 8; 6904 retword |= reg_r(gspca_dev, 0x000a);
6881 retbyte = reg_r(gspca_dev, 0x000a); 6905 PDEBUG(D_PROBE, "probe 3wr vga 1 0x%04x", retword);
6882 checkword |= retbyte;
6883 PDEBUG(D_PROBE, "probe 3wr vga 1 0x%04x", checkword);
6884 reg_r(gspca_dev, 0x0010); 6906 reg_r(gspca_dev, 0x0010);
6885 /* this is tested only once anyway */ 6907 /* this is tested only once anyway */
6886 for (i = 0; i < ARRAY_SIZE(chipset_revision_sensor); i++) { 6908 for (i = 0; i < ARRAY_SIZE(chipset_revision_sensor); i++) {
6887 if (chipset_revision_sensor[i].revision == checkword) { 6909 if (chipset_revision_sensor[i].revision == retword) {
6888 sd->chip_revision = checkword; 6910 sd->chip_revision = retword;
6889 send_unknown(dev, SENSOR_PB0330); 6911 send_unknown(dev, SENSOR_PB0330);
6890 return chipset_revision_sensor[i].internal_sensor_id; 6912 return chipset_revision_sensor[i].internal_sensor_id;
6891 } 6913 }
@@ -6897,8 +6919,8 @@ static int vga_3wr_probe(struct gspca_dev *gspca_dev)
6897 reg_w(dev, 0x0a, 0x0010); 6919 reg_w(dev, 0x0a, 0x0010);
6898 reg_w(dev, 0x03, 0x0012); 6920 reg_w(dev, 0x03, 0x0012);
6899 reg_w(dev, 0x01, 0x0012); 6921 reg_w(dev, 0x01, 0x0012);
6900 retbyte = i2c_read(gspca_dev, 0x00); 6922 retword = i2c_read(gspca_dev, 0x00);
6901 if (retbyte != 0) { 6923 if (retword != 0) {
6902 PDEBUG(D_PROBE, "probe 3wr vga type 0a ?"); 6924 PDEBUG(D_PROBE, "probe 3wr vga type 0a ?");
6903 return 0x0a; /* ?? */ 6925 return 0x0a; /* ?? */
6904 } 6926 }
@@ -6910,14 +6932,14 @@ static int vga_3wr_probe(struct gspca_dev *gspca_dev)
6910 reg_w(dev, 0x03, 0x0012); 6932 reg_w(dev, 0x03, 0x0012);
6911 msleep(2); 6933 msleep(2);
6912 reg_w(dev, 0x01, 0x0012); 6934 reg_w(dev, 0x01, 0x0012);
6913 retbyte = i2c_read(gspca_dev, 0x00); 6935 retword = i2c_read(gspca_dev, 0x00);
6914 if (retbyte != 0) { 6936 if (retword != 0) {
6915 PDEBUG(D_PROBE, "probe 3wr vga type %02x", retbyte); 6937 PDEBUG(D_PROBE, "probe 3wr vga type %02x", retword);
6916 if (retbyte == 0x11) /* VF0250 */ 6938 if (retword == 0x0011) /* VF0250 */
6917 return 0x0250; 6939 return 0x0250;
6918 if (retbyte == 0x29) /* gc0305 */ 6940 if (retword == 0x0029) /* gc0305 */
6919 send_unknown(dev, SENSOR_GC0305); 6941 send_unknown(dev, SENSOR_GC0305);
6920 return retbyte; 6942 return retword;
6921 } 6943 }
6922 6944
6923 reg_w(dev, 0x01, 0x0000); /* check OmniVision */ 6945 reg_w(dev, 0x01, 0x0000); /* check OmniVision */
@@ -6927,8 +6949,8 @@ static int vga_3wr_probe(struct gspca_dev *gspca_dev)
6927 reg_w(dev, 0x06, 0x0010); 6949 reg_w(dev, 0x06, 0x0010);
6928 reg_w(dev, 0x01, 0x0012); 6950 reg_w(dev, 0x01, 0x0012);
6929 reg_w(dev, 0x05, 0x0012); 6951 reg_w(dev, 0x05, 0x0012);
6930 if (i2c_read(gspca_dev, 0x1c) == 0x7f /* OV7610 - manufacturer ID */ 6952 if (i2c_read(gspca_dev, 0x1c) == 0x007f /* OV7610 - manufacturer ID */
6931 && i2c_read(gspca_dev, 0x1d) == 0xa2) { 6953 && i2c_read(gspca_dev, 0x1d) == 0x00a2) {
6932 send_unknown(dev, SENSOR_OV7620); 6954 send_unknown(dev, SENSOR_OV7620);
6933 return 0x06; /* OmniVision confirm ? */ 6955 return 0x06; /* OmniVision confirm ? */
6934 } 6956 }
@@ -6942,16 +6964,14 @@ static int vga_3wr_probe(struct gspca_dev *gspca_dev)
6942/* msleep(150); */ 6964/* msleep(150); */
6943 reg_w(dev, 0x01, 0x0012); 6965 reg_w(dev, 0x01, 0x0012);
6944 reg_w(dev, 0x05, 0x0012); 6966 reg_w(dev, 0x05, 0x0012);
6945 retbyte = i2c_read(gspca_dev, 0x0000); /* ID 0 */ 6967 retword = i2c_read(gspca_dev, 0x00) << 8; /* ID 0 */
6946 checkword = retbyte << 8; 6968 retword |= i2c_read(gspca_dev, 0x01); /* ID 1 */
6947 retbyte = i2c_read(gspca_dev, 0x0001); /* ID 1 */ 6969 PDEBUG(D_PROBE, "probe 3wr vga 2 0x%04x", retword);
6948 checkword |= retbyte; 6970 if (retword == 0x2030) {
6949 PDEBUG(D_PROBE, "probe 3wr vga 2 0x%04x", checkword);
6950 if (checkword == 0x2030) {
6951 retbyte = i2c_read(gspca_dev, 0x02); /* revision number */ 6971 retbyte = i2c_read(gspca_dev, 0x02); /* revision number */
6952 PDEBUG(D_PROBE, "sensor PO2030 rev 0x%02x", retbyte); 6972 PDEBUG(D_PROBE, "sensor PO2030 rev 0x%02x", retbyte);
6953 send_unknown(dev, SENSOR_PO2030); 6973 send_unknown(dev, SENSOR_PO2030);
6954 return checkword; 6974 return retword;
6955 } 6975 }
6956 6976
6957 reg_w(dev, 0x01, 0x0000); 6977 reg_w(dev, 0x01, 0x0000);
@@ -6962,10 +6982,10 @@ static int vga_3wr_probe(struct gspca_dev *gspca_dev)
6962 reg_w(dev, 0x01, 0x0012); 6982 reg_w(dev, 0x01, 0x0012);
6963 reg_w(dev, 0x05, 0x0001); 6983 reg_w(dev, 0x05, 0x0001);
6964 reg_w(dev, 0xd3, 0x008b); 6984 reg_w(dev, 0xd3, 0x008b);
6965 retbyte = i2c_read(gspca_dev, 0x01); 6985 retword = i2c_read(gspca_dev, 0x01);
6966 if (retbyte != 0) { 6986 if (retword != 0) {
6967 PDEBUG(D_PROBE, "probe 3wr vga type 0a ?"); 6987 PDEBUG(D_PROBE, "probe 3wr vga type 0a ? ret: %04x", retword);
6968 return 0x0a; /* ?? */ 6988 return retword;
6969 } 6989 }
6970 return -1; 6990 return -1;
6971} 6991}
@@ -6973,7 +6993,7 @@ static int vga_3wr_probe(struct gspca_dev *gspca_dev)
6973static int zcxx_probeSensor(struct gspca_dev *gspca_dev) 6993static int zcxx_probeSensor(struct gspca_dev *gspca_dev)
6974{ 6994{
6975 struct sd *sd = (struct sd *) gspca_dev; 6995 struct sd *sd = (struct sd *) gspca_dev;
6976 int sensor, sensor2; 6996 int sensor;
6977 6997
6978 switch (sd->sensor) { 6998 switch (sd->sensor) {
6979 case SENSOR_MC501CB: 6999 case SENSOR_MC501CB:
@@ -6988,16 +7008,9 @@ static int zcxx_probeSensor(struct gspca_dev *gspca_dev)
6988 break; 7008 break;
6989 } 7009 }
6990 sensor = vga_2wr_probe(gspca_dev); 7010 sensor = vga_2wr_probe(gspca_dev);
6991 if (sensor >= 0) { 7011 if (sensor >= 0)
6992 if (sensor < 0x7600)
6993 return sensor;
6994 /* next probe is needed for OmniVision ? */
6995 }
6996 sensor2 = vga_3wr_probe(gspca_dev);
6997 if (sensor2 >= 0
6998 && sensor >= 0)
6999 return sensor; 7012 return sensor;
7000 return sensor2; 7013 return vga_3wr_probe(gspca_dev);
7001} 7014}
7002 7015
7003/* this function is called at probe time */ 7016/* this function is called at probe time */
@@ -7009,23 +7022,24 @@ static int sd_config(struct gspca_dev *gspca_dev,
7009 int sensor; 7022 int sensor;
7010 int vga = 1; /* 1: vga, 0: sif */ 7023 int vga = 1; /* 1: vga, 0: sif */
7011 static const __u8 gamma[SENSOR_MAX] = { 7024 static const __u8 gamma[SENSOR_MAX] = {
7012 5, /* SENSOR_CS2102 0 */ 7025 4, /* SENSOR_ADCM2700 0 */
7013 5, /* SENSOR_CS2102K 1 */ 7026 5, /* SENSOR_CS2102 1 */
7014 4, /* SENSOR_GC0305 2 */ 7027 5, /* SENSOR_CS2102K 2 */
7015 4, /* SENSOR_HDCS2020b 3 */ 7028 4, /* SENSOR_GC0305 3 */
7016 4, /* SENSOR_HV7131B 4 */ 7029 4, /* SENSOR_HDCS2020b 4 */
7017 4, /* SENSOR_HV7131C 5 */ 7030 4, /* SENSOR_HV7131B 5 */
7018 4, /* SENSOR_ICM105A 6 */ 7031 4, /* SENSOR_HV7131C 6 */
7019 4, /* SENSOR_MC501CB 7 */ 7032 4, /* SENSOR_ICM105A 7 */
7020 3, /* SENSOR_OV7620 8 */ 7033 4, /* SENSOR_MC501CB 8 */
7021 4, /* SENSOR_OV7630C 9 */ 7034 3, /* SENSOR_OV7620 9 */
7022 4, /* SENSOR_PAS106 10 */ 7035 4, /* SENSOR_OV7630C 10 */
7023 4, /* SENSOR_PAS202B 11 */ 7036 4, /* SENSOR_PAS106 11 */
7024 4, /* SENSOR_PB0330 12 */ 7037 4, /* SENSOR_PAS202B 12 */
7025 4, /* SENSOR_PO2030 13 */ 7038 4, /* SENSOR_PB0330 13 */
7026 4, /* SENSOR_TAS5130CK 14 */ 7039 4, /* SENSOR_PO2030 14 */
7027 4, /* SENSOR_TAS5130CXX 15 */ 7040 4, /* SENSOR_TAS5130CK 15 */
7028 3, /* SENSOR_TAS5130C_VF0250 16 */ 7041 4, /* SENSOR_TAS5130CXX 16 */
7042 3, /* SENSOR_TAS5130C_VF0250 17 */
7029 }; 7043 };
7030 7044
7031 /* define some sensors from the vendor/product */ 7045 /* define some sensors from the vendor/product */
@@ -7033,7 +7047,7 @@ static int sd_config(struct gspca_dev *gspca_dev,
7033 sd->sensor = id->driver_info; 7047 sd->sensor = id->driver_info;
7034 sensor = zcxx_probeSensor(gspca_dev); 7048 sensor = zcxx_probeSensor(gspca_dev);
7035 if (sensor >= 0) 7049 if (sensor >= 0)
7036 PDEBUG(D_PROBE, "probe sensor -> %02x", sensor); 7050 PDEBUG(D_PROBE, "probe sensor -> %04x", sensor);
7037 if ((unsigned) force_sensor < SENSOR_MAX) { 7051 if ((unsigned) force_sensor < SENSOR_MAX) {
7038 sd->sensor = force_sensor; 7052 sd->sensor = force_sensor;
7039 PDEBUG(D_PROBE, "sensor forced to %d", force_sensor); 7053 PDEBUG(D_PROBE, "sensor forced to %d", force_sensor);
@@ -7112,6 +7126,10 @@ static int sd_config(struct gspca_dev *gspca_dev,
7112 sd->chip_revision); 7126 sd->chip_revision);
7113 sd->sensor = SENSOR_TAS5130CK; 7127 sd->sensor = SENSOR_TAS5130CK;
7114 break; 7128 break;
7129 case 0x16:
7130 PDEBUG(D_PROBE, "Find Sensor ADCM2700");
7131 sd->sensor = SENSOR_ADCM2700;
7132 break;
7115 case 0x29: 7133 case 0x29:
7116 PDEBUG(D_PROBE, "Find Sensor GC0305"); 7134 PDEBUG(D_PROBE, "Find Sensor GC0305");
7117 sd->sensor = SENSOR_GC0305; 7135 sd->sensor = SENSOR_GC0305;
@@ -7129,12 +7147,16 @@ static int sd_config(struct gspca_dev *gspca_dev,
7129 PDEBUG(D_PROBE, "Find Sensor OV7620"); 7147 PDEBUG(D_PROBE, "Find Sensor OV7620");
7130 sd->sensor = SENSOR_OV7620; 7148 sd->sensor = SENSOR_OV7620;
7131 break; 7149 break;
7150 case 0x7631:
7151 PDEBUG(D_PROBE, "Find Sensor OV7630C");
7152 sd->sensor = SENSOR_OV7630C;
7153 break;
7132 case 0x7648: 7154 case 0x7648:
7133 PDEBUG(D_PROBE, "Find Sensor OV7648"); 7155 PDEBUG(D_PROBE, "Find Sensor OV7648");
7134 sd->sensor = SENSOR_OV7620; /* same sensor (?) */ 7156 sd->sensor = SENSOR_OV7620; /* same sensor (?) */
7135 break; 7157 break;
7136 default: 7158 default:
7137 PDEBUG(D_ERR|D_PROBE, "Unknown sensor %02x", sensor); 7159 PDEBUG(D_ERR|D_PROBE, "Unknown sensor %04x", sensor);
7138 return -EINVAL; 7160 return -EINVAL;
7139 } 7161 }
7140 } 7162 }
@@ -7147,7 +7169,6 @@ static int sd_config(struct gspca_dev *gspca_dev,
7147 } 7169 }
7148 7170
7149 cam = &gspca_dev->cam; 7171 cam = &gspca_dev->cam;
7150 cam->epaddr = 0x01;
7151/*fixme:test*/ 7172/*fixme:test*/
7152 gspca_dev->nbalt--; 7173 gspca_dev->nbalt--;
7153 if (vga) { 7174 if (vga) {
@@ -7157,12 +7178,12 @@ static int sd_config(struct gspca_dev *gspca_dev,
7157 cam->cam_mode = sif_mode; 7178 cam->cam_mode = sif_mode;
7158 cam->nmodes = ARRAY_SIZE(sif_mode); 7179 cam->nmodes = ARRAY_SIZE(sif_mode);
7159 } 7180 }
7160 sd->qindex = 1;
7161 sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value; 7181 sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value;
7162 sd->contrast = sd_ctrls[SD_CONTRAST].qctrl.default_value; 7182 sd->contrast = sd_ctrls[SD_CONTRAST].qctrl.default_value;
7163 sd->gamma = gamma[(int) sd->sensor]; 7183 sd->gamma = gamma[(int) sd->sensor];
7164 sd->autogain = sd_ctrls[SD_AUTOGAIN].qctrl.default_value; 7184 sd->autogain = sd_ctrls[SD_AUTOGAIN].qctrl.default_value;
7165 sd->lightfreq = sd_ctrls[SD_FREQ].qctrl.default_value; 7185 sd->lightfreq = sd_ctrls[SD_FREQ].qctrl.default_value;
7186 sd->quality = QUALITY_DEF;
7166 7187
7167 switch (sd->sensor) { 7188 switch (sd->sensor) {
7168 case SENSOR_GC0305: 7189 case SENSOR_GC0305:
@@ -7196,27 +7217,34 @@ static int sd_start(struct gspca_dev *gspca_dev)
7196 const struct usb_action *zc3_init; 7217 const struct usb_action *zc3_init;
7197 int mode; 7218 int mode;
7198 static const struct usb_action *init_tb[SENSOR_MAX][2] = { 7219 static const struct usb_action *init_tb[SENSOR_MAX][2] = {
7199 {cs2102_InitialScale, cs2102_Initial}, /* 0 */ 7220 {adcm2700_Initial, adcm2700_InitialScale}, /* 0 */
7200 {cs2102K_InitialScale, cs2102K_Initial}, /* 1 */ 7221 {cs2102_InitialScale, cs2102_Initial}, /* 1 */
7201 {gc0305_Initial, gc0305_InitialScale}, /* 2 */ 7222 {cs2102K_InitialScale, cs2102K_Initial}, /* 2 */
7202 {hdcs2020xb_InitialScale, hdcs2020xb_Initial}, /* 3 */ 7223 {gc0305_Initial, gc0305_InitialScale}, /* 3 */
7203 {hv7131bxx_InitialScale, hv7131bxx_Initial}, /* 4 */ 7224 {hdcs2020xb_InitialScale, hdcs2020xb_Initial}, /* 4 */
7204 {hv7131cxx_InitialScale, hv7131cxx_Initial}, /* 5 */ 7225 {hv7131bxx_InitialScale, hv7131bxx_Initial}, /* 5 */
7205 {icm105axx_InitialScale, icm105axx_Initial}, /* 6 */ 7226 {hv7131cxx_InitialScale, hv7131cxx_Initial}, /* 6 */
7206 {MC501CB_InitialScale, MC501CB_Initial}, /* 7 */ 7227 {icm105axx_InitialScale, icm105axx_Initial}, /* 7 */
7207 {OV7620_mode0, OV7620_mode1}, /* 8 */ 7228 {MC501CB_InitialScale, MC501CB_Initial}, /* 8 */
7208 {ov7630c_InitialScale, ov7630c_Initial}, /* 9 */ 7229 {OV7620_mode0, OV7620_mode1}, /* 9 */
7209 {pas106b_InitialScale, pas106b_Initial}, /* 10 */ 7230 {ov7630c_InitialScale, ov7630c_Initial}, /* 10 */
7210 {pas202b_Initial, pas202b_InitialScale}, /* 11 */ 7231 {pas106b_InitialScale, pas106b_Initial}, /* 11 */
7211 {pb0330xx_InitialScale, pb0330xx_Initial}, /* 12 */ 7232 {pas202b_Initial, pas202b_InitialScale}, /* 12 */
7233 {pb0330xx_InitialScale, pb0330xx_Initial}, /* 13 */
7212/* or {pb03303x_InitialScale, pb03303x_Initial}, */ 7234/* or {pb03303x_InitialScale, pb03303x_Initial}, */
7213 {PO2030_mode0, PO2030_mode1}, /* 13 */ 7235 {PO2030_mode0, PO2030_mode1}, /* 14 */
7214 {tas5130CK_InitialScale, tas5130CK_Initial}, /* 14 */ 7236 {tas5130CK_InitialScale, tas5130CK_Initial}, /* 15 */
7215 {tas5130cxx_InitialScale, tas5130cxx_Initial}, /* 15 */ 7237 {tas5130cxx_InitialScale, tas5130cxx_Initial}, /* 16 */
7216 {tas5130c_vf0250_InitialScale, tas5130c_vf0250_Initial}, 7238 {tas5130c_vf0250_InitialScale, tas5130c_vf0250_Initial},
7217 /* 16 */ 7239 /* 17 */
7218 }; 7240 };
7219 7241
7242 /* create the JPEG header */
7243 sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL);
7244 jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
7245 0x21); /* JPEG 422 */
7246 jpeg_set_qual(sd->jpeg_hdr, sd->quality);
7247
7220 mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv; 7248 mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
7221 zc3_init = init_tb[(int) sd->sensor][mode]; 7249 zc3_init = init_tb[(int) sd->sensor][mode];
7222 switch (sd->sensor) { 7250 switch (sd->sensor) {
@@ -7243,11 +7271,12 @@ static int sd_start(struct gspca_dev *gspca_dev)
7243 usb_exchange(gspca_dev, zc3_init); 7271 usb_exchange(gspca_dev, zc3_init);
7244 7272
7245 switch (sd->sensor) { 7273 switch (sd->sensor) {
7274 case SENSOR_ADCM2700:
7246 case SENSOR_GC0305: 7275 case SENSOR_GC0305:
7247 case SENSOR_OV7620: 7276 case SENSOR_OV7620:
7248 case SENSOR_PO2030: 7277 case SENSOR_PO2030:
7249 case SENSOR_TAS5130C_VF0250: 7278 case SENSOR_TAS5130C_VF0250:
7250 msleep(100); /* ?? */ 7279/* msleep(100); * ?? */
7251 reg_r(gspca_dev, 0x0002); /* --> 0x40 */ 7280 reg_r(gspca_dev, 0x0002); /* --> 0x40 */
7252 reg_w(dev, 0x09, 0x01ad); /* (from win traces) */ 7281 reg_w(dev, 0x09, 0x01ad); /* (from win traces) */
7253 reg_w(dev, 0x15, 0x01ae); 7282 reg_w(dev, 0x15, 0x01ae);
@@ -7260,6 +7289,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
7260 setmatrix(gspca_dev); 7289 setmatrix(gspca_dev);
7261 setbrightness(gspca_dev); 7290 setbrightness(gspca_dev);
7262 switch (sd->sensor) { 7291 switch (sd->sensor) {
7292 case SENSOR_ADCM2700:
7263 case SENSOR_OV7620: 7293 case SENSOR_OV7620:
7264 reg_r(gspca_dev, 0x0008); 7294 reg_r(gspca_dev, 0x0008);
7265 reg_w(dev, 0x00, 0x0008); 7295 reg_w(dev, 0x00, 0x0008);
@@ -7301,6 +7331,13 @@ static int sd_start(struct gspca_dev *gspca_dev)
7301 setlightfreq(gspca_dev); 7331 setlightfreq(gspca_dev);
7302 7332
7303 switch (sd->sensor) { 7333 switch (sd->sensor) {
7334 case SENSOR_ADCM2700:
7335 reg_w(dev, 0x09, 0x01ad); /* (from win traces) */
7336 reg_w(dev, 0x15, 0x01ae);
7337 reg_w(dev, 0x02, 0x0180);
7338 /* ms-win + */
7339 reg_w(dev, 0x40, 0x0117);
7340 break;
7304 case SENSOR_GC0305: 7341 case SENSOR_GC0305:
7305 reg_w(dev, 0x09, 0x01ad); /* (from win traces) */ 7342 reg_w(dev, 0x09, 0x01ad); /* (from win traces) */
7306 reg_w(dev, 0x15, 0x01ae); 7343 reg_w(dev, 0x15, 0x01ae);
@@ -7323,19 +7360,16 @@ static int sd_start(struct gspca_dev *gspca_dev)
7323 7360
7324 setautogain(gspca_dev); 7361 setautogain(gspca_dev);
7325 switch (sd->sensor) { 7362 switch (sd->sensor) {
7326 case SENSOR_PAS202B:
7327 reg_w(dev, 0x00, 0x0007); /* (from win traces) */
7328 break;
7329 case SENSOR_PO2030: 7363 case SENSOR_PO2030:
7330 msleep(500); 7364 msleep(500);
7331 reg_r(gspca_dev, 0x0008); 7365 reg_r(gspca_dev, 0x0008);
7332 reg_r(gspca_dev, 0x0007); 7366 reg_r(gspca_dev, 0x0007);
7367 /*fall thru*/
7368 case SENSOR_PAS202B:
7333 reg_w(dev, 0x00, 0x0007); /* (from win traces) */ 7369 reg_w(dev, 0x00, 0x0007); /* (from win traces) */
7334 reg_w(dev, 0x02, 0x0008); 7370 reg_w(dev, 0x02, ZC3XX_R008_CLOCKSETTING);
7335 break; 7371 break;
7336 } 7372 }
7337 if (sd->sensor == SENSOR_PAS202B)
7338 reg_w(dev, 0x02, ZC3XX_R008_CLOCKSETTING);
7339 return 0; 7373 return 0;
7340} 7374}
7341 7375
@@ -7344,6 +7378,7 @@ static void sd_stop0(struct gspca_dev *gspca_dev)
7344{ 7378{
7345 struct sd *sd = (struct sd *) gspca_dev; 7379 struct sd *sd = (struct sd *) gspca_dev;
7346 7380
7381 kfree(sd->jpeg_hdr);
7347 if (!gspca_dev->present) 7382 if (!gspca_dev->present)
7348 return; 7383 return;
7349 send_unknown(gspca_dev->dev, sd->sensor); 7384 send_unknown(gspca_dev->dev, sd->sensor);
@@ -7354,14 +7389,15 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
7354 __u8 *data, 7389 __u8 *data,
7355 int len) 7390 int len)
7356{ 7391{
7392 struct sd *sd = (struct sd *) gspca_dev;
7357 7393
7358 if (data[0] == 0xff && data[1] == 0xd8) { /* start of frame */ 7394 if (data[0] == 0xff && data[1] == 0xd8) { /* start of frame */
7359 frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame, 7395 frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame,
7360 data, 0); 7396 data, 0);
7361 /* put the JPEG header in the new frame */ 7397 /* put the JPEG header in the new frame */
7362 jpeg_put_header(gspca_dev, frame, 7398 gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
7363 ((struct sd *) gspca_dev)->qindex, 7399 sd->jpeg_hdr, JPEG_HDR_SZ);
7364 0x21); 7400
7365 /* remove the webcam's header: 7401 /* remove the webcam's header:
7366 * ff d8 ff fe 00 0e 00 00 ss ss 00 01 ww ww hh hh pp pp 7402 * ff d8 ff fe 00 0e 00 00 ss ss 00 01 ww ww hh hh pp pp
7367 * - 'ss ss' is the frame sequence number (BE) 7403 * - 'ss ss' is the frame sequence number (BE)
@@ -7503,6 +7539,34 @@ static int sd_querymenu(struct gspca_dev *gspca_dev,
7503 return -EINVAL; 7539 return -EINVAL;
7504} 7540}
7505 7541
7542static int sd_set_jcomp(struct gspca_dev *gspca_dev,
7543 struct v4l2_jpegcompression *jcomp)
7544{
7545 struct sd *sd = (struct sd *) gspca_dev;
7546
7547 if (jcomp->quality < QUALITY_MIN)
7548 sd->quality = QUALITY_MIN;
7549 else if (jcomp->quality > QUALITY_MAX)
7550 sd->quality = QUALITY_MAX;
7551 else
7552 sd->quality = jcomp->quality;
7553 if (gspca_dev->streaming)
7554 jpeg_set_qual(sd->jpeg_hdr, sd->quality);
7555 return 0;
7556}
7557
7558static int sd_get_jcomp(struct gspca_dev *gspca_dev,
7559 struct v4l2_jpegcompression *jcomp)
7560{
7561 struct sd *sd = (struct sd *) gspca_dev;
7562
7563 memset(jcomp, 0, sizeof *jcomp);
7564 jcomp->quality = sd->quality;
7565 jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT
7566 | V4L2_JPEG_MARKER_DQT;
7567 return 0;
7568}
7569
7506static const struct sd_desc sd_desc = { 7570static const struct sd_desc sd_desc = {
7507 .name = MODULE_NAME, 7571 .name = MODULE_NAME,
7508 .ctrls = sd_ctrls, 7572 .ctrls = sd_ctrls,
@@ -7513,6 +7577,8 @@ static const struct sd_desc sd_desc = {
7513 .stop0 = sd_stop0, 7577 .stop0 = sd_stop0,
7514 .pkt_scan = sd_pkt_scan, 7578 .pkt_scan = sd_pkt_scan,
7515 .querymenu = sd_querymenu, 7579 .querymenu = sd_querymenu,
7580 .get_jcomp = sd_get_jcomp,
7581 .set_jcomp = sd_set_jcomp,
7516}; 7582};
7517 7583
7518static const __devinitdata struct usb_device_id device_table[] = { 7584static const __devinitdata struct usb_device_id device_table[] = {
@@ -7563,11 +7629,9 @@ static const __devinitdata struct usb_device_id device_table[] = {
7563 {USB_DEVICE(0x055f, 0xd004)}, 7629 {USB_DEVICE(0x055f, 0xd004)},
7564 {USB_DEVICE(0x0698, 0x2003)}, 7630 {USB_DEVICE(0x0698, 0x2003)},
7565 {USB_DEVICE(0x0ac8, 0x0301), .driver_info = SENSOR_PAS106}, 7631 {USB_DEVICE(0x0ac8, 0x0301), .driver_info = SENSOR_PAS106},
7566 {USB_DEVICE(0x0ac8, 0x0302)}, 7632 {USB_DEVICE(0x0ac8, 0x0302), .driver_info = SENSOR_PAS106},
7567 {USB_DEVICE(0x0ac8, 0x301b)}, 7633 {USB_DEVICE(0x0ac8, 0x301b)},
7568#if !defined CONFIG_USB_ZC0301 && !defined CONFIG_USB_ZC0301_MODULE
7569 {USB_DEVICE(0x0ac8, 0x303b)}, 7634 {USB_DEVICE(0x0ac8, 0x303b)},
7570#endif
7571 {USB_DEVICE(0x0ac8, 0x305b), .driver_info = SENSOR_TAS5130C_VF0250}, 7635 {USB_DEVICE(0x0ac8, 0x305b), .driver_info = SENSOR_TAS5130C_VF0250},
7572 {USB_DEVICE(0x0ac8, 0x307b)}, 7636 {USB_DEVICE(0x0ac8, 0x307b)},
7573 {USB_DEVICE(0x10fd, 0x0128)}, 7637 {USB_DEVICE(0x10fd, 0x0128)},
@@ -7600,8 +7664,10 @@ static struct usb_driver sd_driver = {
7600 7664
7601static int __init sd_mod_init(void) 7665static int __init sd_mod_init(void)
7602{ 7666{
7603 if (usb_register(&sd_driver) < 0) 7667 int ret;
7604 return -1; 7668 ret = usb_register(&sd_driver);
7669 if (ret < 0)
7670 return ret;
7605 PDEBUG(D_PROBE, "registered"); 7671 PDEBUG(D_PROBE, "registered");
7606 return 0; 7672 return 0;
7607} 7673}
diff --git a/drivers/media/video/hdpvr/Kconfig b/drivers/media/video/hdpvr/Kconfig
new file mode 100644
index 000000000000..de247f3c7d05
--- /dev/null
+++ b/drivers/media/video/hdpvr/Kconfig
@@ -0,0 +1,10 @@
1
2config VIDEO_HDPVR
3 tristate "Hauppauge HD PVR support"
4 depends on VIDEO_DEV
5 ---help---
6 This is a video4linux driver for Hauppauge's HD PVR USB device.
7
8 To compile this driver as a module, choose M here: the
9 module will be called hdpvr
10
diff --git a/drivers/media/video/hdpvr/Makefile b/drivers/media/video/hdpvr/Makefile
new file mode 100644
index 000000000000..e0230fcb2e36
--- /dev/null
+++ b/drivers/media/video/hdpvr/Makefile
@@ -0,0 +1,9 @@
1hdpvr-objs := hdpvr-control.o hdpvr-core.o hdpvr-video.o
2
3hdpvr-$(CONFIG_I2C) += hdpvr-i2c.o
4
5obj-$(CONFIG_VIDEO_HDPVR) += hdpvr.o
6
7EXTRA_CFLAGS += -Idrivers/media/video
8
9EXTRA_CFLAGS += $(extra-cflags-y) $(extra-cflags-m)
diff --git a/drivers/media/video/hdpvr/hdpvr-control.c b/drivers/media/video/hdpvr/hdpvr-control.c
new file mode 100644
index 000000000000..06791749d1a0
--- /dev/null
+++ b/drivers/media/video/hdpvr/hdpvr-control.c
@@ -0,0 +1,201 @@
1/*
2 * Hauppauge HD PVR USB driver - video 4 linux 2 interface
3 *
4 * Copyright (C) 2008 Janne Grunau (j@jannau.net)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, version 2.
9 *
10 */
11
12#include <linux/kernel.h>
13#include <linux/errno.h>
14#include <linux/init.h>
15#include <linux/slab.h>
16#include <linux/module.h>
17#include <linux/usb.h>
18#include <linux/mutex.h>
19
20#include <linux/videodev2.h>
21
22#include <media/v4l2-common.h>
23
24#include "hdpvr.h"
25
26
27int hdpvr_config_call(struct hdpvr_device *dev, uint value, u8 valbuf)
28{
29 int ret;
30 char request_type = 0x38, snd_request = 0x01;
31
32 msleep(10);
33
34 mutex_lock(&dev->usbc_mutex);
35 dev->usbc_buf[0] = valbuf;
36 ret = usb_control_msg(dev->udev,
37 usb_sndctrlpipe(dev->udev, 0),
38 snd_request, 0x00 | request_type,
39 value, CTRL_DEFAULT_INDEX,
40 dev->usbc_buf, 1, 10000);
41
42 mutex_unlock(&dev->usbc_mutex);
43 v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev,
44 "config call request for value 0x%x returned %d\n", value,
45 ret);
46
47 return ret < 0 ? ret : 0;
48}
49
50struct hdpvr_video_info *get_video_info(struct hdpvr_device *dev)
51{
52 struct hdpvr_video_info *vidinf = NULL;
53#ifdef HDPVR_DEBUG
54 char print_buf[15];
55#endif
56 int ret;
57
58 vidinf = kzalloc(sizeof(struct hdpvr_video_info), GFP_KERNEL);
59 if (!vidinf) {
60 v4l2_err(&dev->v4l2_dev, "out of memory\n");
61 goto err;
62 }
63
64 mutex_lock(&dev->usbc_mutex);
65 ret = usb_control_msg(dev->udev,
66 usb_rcvctrlpipe(dev->udev, 0),
67 0x81, 0x80 | 0x38,
68 0x1400, 0x0003,
69 dev->usbc_buf, 5,
70 1000);
71 if (ret == 5) {
72 vidinf->width = dev->usbc_buf[1] << 8 | dev->usbc_buf[0];
73 vidinf->height = dev->usbc_buf[3] << 8 | dev->usbc_buf[2];
74 vidinf->fps = dev->usbc_buf[4];
75 }
76
77#ifdef HDPVR_DEBUG
78 if (hdpvr_debug & MSG_INFO) {
79 hex_dump_to_buffer(dev->usbc_buf, 5, 16, 1, print_buf,
80 sizeof(print_buf), 0);
81 v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev,
82 "get video info returned: %d, %s\n", ret, print_buf);
83 }
84#endif
85 mutex_unlock(&dev->usbc_mutex);
86
87 if (!vidinf->width || !vidinf->height || !vidinf->fps) {
88 kfree(vidinf);
89 vidinf = NULL;
90 }
91err:
92 return vidinf;
93}
94
95int get_input_lines_info(struct hdpvr_device *dev)
96{
97#ifdef HDPVR_DEBUG
98 char print_buf[9];
99#endif
100 int ret, lines;
101
102 mutex_lock(&dev->usbc_mutex);
103 ret = usb_control_msg(dev->udev,
104 usb_rcvctrlpipe(dev->udev, 0),
105 0x81, 0x80 | 0x38,
106 0x1800, 0x0003,
107 dev->usbc_buf, 3,
108 1000);
109
110#ifdef HDPVR_DEBUG
111 if (hdpvr_debug & MSG_INFO) {
112 hex_dump_to_buffer(dev->usbc_buf, 3, 16, 1, print_buf,
113 sizeof(print_buf), 0);
114 v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev,
115 "get input lines info returned: %d, %s\n", ret,
116 print_buf);
117 }
118#endif
119 lines = dev->usbc_buf[1] << 8 | dev->usbc_buf[0];
120 mutex_unlock(&dev->usbc_mutex);
121 return lines;
122}
123
124
125int hdpvr_set_bitrate(struct hdpvr_device *dev)
126{
127 int ret;
128
129 mutex_lock(&dev->usbc_mutex);
130 memset(dev->usbc_buf, 0, 4);
131 dev->usbc_buf[0] = dev->options.bitrate;
132 dev->usbc_buf[2] = dev->options.peak_bitrate;
133
134 ret = usb_control_msg(dev->udev,
135 usb_sndctrlpipe(dev->udev, 0),
136 0x01, 0x38, CTRL_BITRATE_VALUE,
137 CTRL_DEFAULT_INDEX, dev->usbc_buf, 4, 1000);
138 mutex_unlock(&dev->usbc_mutex);
139
140 return ret;
141}
142
143int hdpvr_set_audio(struct hdpvr_device *dev, u8 input,
144 enum v4l2_mpeg_audio_encoding codec)
145{
146 int ret = 0;
147
148 if (dev->flags & HDPVR_FLAG_AC3_CAP) {
149 mutex_lock(&dev->usbc_mutex);
150 memset(dev->usbc_buf, 0, 2);
151 dev->usbc_buf[0] = input;
152 if (codec == V4L2_MPEG_AUDIO_ENCODING_AAC)
153 dev->usbc_buf[1] = 0;
154 else if (codec == V4L2_MPEG_AUDIO_ENCODING_AC3)
155 dev->usbc_buf[1] = 1;
156 else {
157 mutex_unlock(&dev->usbc_mutex);
158 v4l2_err(&dev->v4l2_dev, "invalid audio codec %d\n",
159 codec);
160 ret = -EINVAL;
161 goto error;
162 }
163
164 ret = usb_control_msg(dev->udev,
165 usb_sndctrlpipe(dev->udev, 0),
166 0x01, 0x38, CTRL_AUDIO_INPUT_VALUE,
167 CTRL_DEFAULT_INDEX, dev->usbc_buf, 2,
168 1000);
169 mutex_unlock(&dev->usbc_mutex);
170 if (ret == 2)
171 ret = 0;
172 } else
173 ret = hdpvr_config_call(dev, CTRL_AUDIO_INPUT_VALUE,
174 dev->options.audio_input+1);
175error:
176 return ret;
177}
178
179int hdpvr_set_options(struct hdpvr_device *dev)
180{
181 hdpvr_config_call(dev, CTRL_VIDEO_STD_TYPE, dev->options.video_std);
182
183 hdpvr_config_call(dev, CTRL_VIDEO_INPUT_VALUE,
184 dev->options.video_input+1);
185
186 hdpvr_set_audio(dev, dev->options.audio_input+1,
187 dev->options.audio_codec);
188
189 hdpvr_set_bitrate(dev);
190 hdpvr_config_call(dev, CTRL_BITRATE_MODE_VALUE,
191 dev->options.bitrate_mode);
192 hdpvr_config_call(dev, CTRL_GOP_MODE_VALUE, dev->options.gop_mode);
193
194 hdpvr_config_call(dev, CTRL_BRIGHTNESS, dev->options.brightness);
195 hdpvr_config_call(dev, CTRL_CONTRAST, dev->options.contrast);
196 hdpvr_config_call(dev, CTRL_HUE, dev->options.hue);
197 hdpvr_config_call(dev, CTRL_SATURATION, dev->options.saturation);
198 hdpvr_config_call(dev, CTRL_SHARPNESS, dev->options.sharpness);
199
200 return 0;
201}
diff --git a/drivers/media/video/hdpvr/hdpvr-core.c b/drivers/media/video/hdpvr/hdpvr-core.c
new file mode 100644
index 000000000000..188bd5aea258
--- /dev/null
+++ b/drivers/media/video/hdpvr/hdpvr-core.c
@@ -0,0 +1,466 @@
1/*
2 * Hauppauge HD PVR USB driver
3 *
4 * Copyright (C) 2001-2004 Greg Kroah-Hartman (greg@kroah.com)
5 * Copyright (C) 2008 Janne Grunau (j@jannau.net)
6 * Copyright (C) 2008 John Poet
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation, version 2.
11 *
12 */
13
14#include <linux/kernel.h>
15#include <linux/errno.h>
16#include <linux/init.h>
17#include <linux/slab.h>
18#include <linux/module.h>
19#include <linux/uaccess.h>
20#include <asm/atomic.h>
21#include <linux/usb.h>
22#include <linux/mutex.h>
23#include <linux/i2c.h>
24
25#include <linux/videodev2.h>
26#include <media/v4l2-dev.h>
27#include <media/v4l2-common.h>
28
29#include "hdpvr.h"
30
31static int video_nr[HDPVR_MAX] = {[0 ... (HDPVR_MAX - 1)] = UNSET};
32module_param_array(video_nr, int, NULL, 0);
33MODULE_PARM_DESC(video_nr, "video device number (-1=Auto)");
34
35/* holds the number of currently registered devices */
36static atomic_t dev_nr = ATOMIC_INIT(-1);
37
38int hdpvr_debug;
39module_param(hdpvr_debug, int, S_IRUGO|S_IWUSR);
40MODULE_PARM_DESC(hdpvr_debug, "enable debugging output");
41
42uint default_video_input = HDPVR_VIDEO_INPUTS;
43module_param(default_video_input, uint, S_IRUGO|S_IWUSR);
44MODULE_PARM_DESC(default_video_input, "default video input: 0=Component / "
45 "1=S-Video / 2=Composite");
46
47uint default_audio_input = HDPVR_AUDIO_INPUTS;
48module_param(default_audio_input, uint, S_IRUGO|S_IWUSR);
49MODULE_PARM_DESC(default_audio_input, "default audio input: 0=RCA back / "
50 "1=RCA front / 2=S/PDIF");
51
52static int boost_audio;
53module_param(boost_audio, bool, S_IRUGO|S_IWUSR);
54MODULE_PARM_DESC(boost_audio, "boost the audio signal");
55
56
57/* table of devices that work with this driver */
58static struct usb_device_id hdpvr_table[] = {
59 { USB_DEVICE(HD_PVR_VENDOR_ID, HD_PVR_PRODUCT_ID) },
60 { USB_DEVICE(HD_PVR_VENDOR_ID, HD_PVR_PRODUCT_ID1) },
61 { USB_DEVICE(HD_PVR_VENDOR_ID, HD_PVR_PRODUCT_ID2) },
62 { } /* Terminating entry */
63};
64MODULE_DEVICE_TABLE(usb, hdpvr_table);
65
66
67void hdpvr_delete(struct hdpvr_device *dev)
68{
69 hdpvr_free_buffers(dev);
70
71 if (dev->video_dev)
72 video_device_release(dev->video_dev);
73
74 usb_put_dev(dev->udev);
75}
76
77static void challenge(u8 *bytes)
78{
79 u64 *i64P, tmp64;
80 uint i, idx;
81
82 for (idx = 0; idx < 32; ++idx) {
83
84 if (idx & 0x3)
85 bytes[(idx >> 3) + 3] = bytes[(idx >> 2) & 0x3];
86
87 switch (idx & 0x3) {
88 case 0x3:
89 bytes[2] += bytes[3] * 4 + bytes[4] + bytes[5];
90 bytes[4] += bytes[(idx & 0x1) * 2] * 9 + 9;
91 break;
92 case 0x1:
93 bytes[0] *= 8;
94 bytes[0] += 7*idx + 4;
95 bytes[6] += bytes[3] * 3;
96 break;
97 case 0x0:
98 bytes[3 - (idx >> 3)] = bytes[idx >> 2];
99 bytes[5] += bytes[6] * 3;
100 for (i = 0; i < 3; i++)
101 bytes[3] *= bytes[3] + 1;
102 break;
103 case 0x2:
104 for (i = 0; i < 3; i++)
105 bytes[1] *= bytes[6] + 1;
106 for (i = 0; i < 3; i++) {
107 i64P = (u64 *)bytes;
108 tmp64 = le64_to_cpup(i64P);
109 tmp64 <<= bytes[7] & 0x0f;
110 *i64P += cpu_to_le64(tmp64);
111 }
112 break;
113 }
114 }
115}
116
117/* try to init the device like the windows driver */
118static int device_authorization(struct hdpvr_device *dev)
119{
120
121 int ret, retval = -ENOMEM;
122 char request_type = 0x38, rcv_request = 0x81;
123 char *response;
124#ifdef HDPVR_DEBUG
125 size_t buf_size = 46;
126 char *print_buf = kzalloc(5*buf_size+1, GFP_KERNEL);
127 if (!print_buf) {
128 v4l2_err(&dev->v4l2_dev, "Out of memory\n");
129 goto error;
130 }
131#endif
132
133 mutex_lock(&dev->usbc_mutex);
134 ret = usb_control_msg(dev->udev,
135 usb_rcvctrlpipe(dev->udev, 0),
136 rcv_request, 0x80 | request_type,
137 0x0400, 0x0003,
138 dev->usbc_buf, 46,
139 10000);
140 if (ret != 46) {
141 v4l2_err(&dev->v4l2_dev,
142 "unexpected answer of status request, len %d\n", ret);
143 goto error;
144 }
145#ifdef HDPVR_DEBUG
146 else {
147 hex_dump_to_buffer(dev->usbc_buf, 46, 16, 1, print_buf,
148 sizeof(print_buf), 0);
149 v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev,
150 "Status request returned, len %d: %s\n",
151 ret, print_buf);
152 }
153#endif
154 if (dev->usbc_buf[1] == HDPVR_FIRMWARE_VERSION) {
155 dev->flags &= ~HDPVR_FLAG_AC3_CAP;
156 } else if (dev->usbc_buf[1] == HDPVR_FIRMWARE_VERSION_AC3) {
157 dev->flags |= HDPVR_FLAG_AC3_CAP;
158 } else if (dev->usbc_buf[1] > HDPVR_FIRMWARE_VERSION_AC3) {
159 v4l2_info(&dev->v4l2_dev, "untested firmware version 0x%x, "
160 "the driver might not work\n", dev->usbc_buf[1]);
161 dev->flags |= HDPVR_FLAG_AC3_CAP;
162 } else {
163 v4l2_err(&dev->v4l2_dev, "unknown firmware version 0x%x\n",
164 dev->usbc_buf[1]);
165 ret = -EINVAL;
166 goto error;
167 }
168
169 response = dev->usbc_buf+38;
170#ifdef HDPVR_DEBUG
171 hex_dump_to_buffer(response, 8, 16, 1, print_buf, sizeof(print_buf), 0);
172 v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev, "challenge: %s\n",
173 print_buf);
174#endif
175 challenge(response);
176#ifdef HDPVR_DEBUG
177 hex_dump_to_buffer(response, 8, 16, 1, print_buf, sizeof(print_buf), 0);
178 v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev, " response: %s\n",
179 print_buf);
180#endif
181
182 msleep(100);
183 ret = usb_control_msg(dev->udev,
184 usb_sndctrlpipe(dev->udev, 0),
185 0xd1, 0x00 | request_type,
186 0x0000, 0x0000,
187 response, 8,
188 10000);
189 v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev,
190 "magic request returned %d\n", ret);
191 mutex_unlock(&dev->usbc_mutex);
192
193 retval = ret != 8;
194error:
195 return retval;
196}
197
198static int hdpvr_device_init(struct hdpvr_device *dev)
199{
200 int ret;
201 u8 *buf;
202 struct hdpvr_video_info *vidinf;
203
204 if (device_authorization(dev))
205 return -EACCES;
206
207 /* default options for init */
208 hdpvr_set_options(dev);
209
210 /* set filter options */
211 mutex_lock(&dev->usbc_mutex);
212 buf = dev->usbc_buf;
213 buf[0] = 0x03; buf[1] = 0x03; buf[2] = 0x00; buf[3] = 0x00;
214 ret = usb_control_msg(dev->udev,
215 usb_sndctrlpipe(dev->udev, 0),
216 0x01, 0x38,
217 CTRL_LOW_PASS_FILTER_VALUE, CTRL_DEFAULT_INDEX,
218 buf, 4,
219 1000);
220 v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev,
221 "control request returned %d\n", ret);
222 mutex_unlock(&dev->usbc_mutex);
223
224 vidinf = get_video_info(dev);
225 if (!vidinf)
226 v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev,
227 "no valid video signal or device init failed\n");
228 else
229 kfree(vidinf);
230
231 /* enable fan and bling leds */
232 mutex_lock(&dev->usbc_mutex);
233 buf[0] = 0x1;
234 ret = usb_control_msg(dev->udev,
235 usb_sndctrlpipe(dev->udev, 0),
236 0xd4, 0x38, 0, 0, buf, 1,
237 1000);
238 v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev,
239 "control request returned %d\n", ret);
240
241 /* boost analog audio */
242 buf[0] = boost_audio;
243 ret = usb_control_msg(dev->udev,
244 usb_sndctrlpipe(dev->udev, 0),
245 0xd5, 0x38, 0, 0, buf, 1,
246 1000);
247 v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev,
248 "control request returned %d\n", ret);
249 mutex_unlock(&dev->usbc_mutex);
250
251 dev->status = STATUS_IDLE;
252 return 0;
253}
254
255static const struct hdpvr_options hdpvr_default_options = {
256 .video_std = HDPVR_60HZ,
257 .video_input = HDPVR_COMPONENT,
258 .audio_input = HDPVR_RCA_BACK,
259 .bitrate = 65, /* 6 mbps */
260 .peak_bitrate = 90, /* 9 mbps */
261 .bitrate_mode = HDPVR_CONSTANT,
262 .gop_mode = HDPVR_SIMPLE_IDR_GOP,
263 .audio_codec = V4L2_MPEG_AUDIO_ENCODING_AAC,
264 .brightness = 0x86,
265 .contrast = 0x80,
266 .hue = 0x80,
267 .saturation = 0x80,
268 .sharpness = 0x80,
269};
270
271static int hdpvr_probe(struct usb_interface *interface,
272 const struct usb_device_id *id)
273{
274 struct hdpvr_device *dev;
275 struct usb_host_interface *iface_desc;
276 struct usb_endpoint_descriptor *endpoint;
277 size_t buffer_size;
278 int i;
279 int retval = -ENOMEM;
280
281 /* allocate memory for our device state and initialize it */
282 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
283 if (!dev) {
284 err("Out of memory");
285 goto error;
286 }
287
288 /* register v4l2_device early so it can be used for printks */
289 if (v4l2_device_register(&interface->dev, &dev->v4l2_dev)) {
290 err("v4l2_device_register failed");
291 goto error;
292 }
293
294 mutex_init(&dev->io_mutex);
295 mutex_init(&dev->i2c_mutex);
296 mutex_init(&dev->usbc_mutex);
297 dev->usbc_buf = kmalloc(64, GFP_KERNEL);
298 if (!dev->usbc_buf) {
299 v4l2_err(&dev->v4l2_dev, "Out of memory\n");
300 goto error;
301 }
302
303 init_waitqueue_head(&dev->wait_buffer);
304 init_waitqueue_head(&dev->wait_data);
305
306 dev->workqueue = create_singlethread_workqueue("hdpvr_buffer");
307 if (!dev->workqueue)
308 goto error;
309
310 /* init video transfer queues */
311 INIT_LIST_HEAD(&dev->free_buff_list);
312 INIT_LIST_HEAD(&dev->rec_buff_list);
313
314 dev->options = hdpvr_default_options;
315
316 if (default_video_input < HDPVR_VIDEO_INPUTS)
317 dev->options.video_input = default_video_input;
318
319 if (default_audio_input < HDPVR_AUDIO_INPUTS)
320 dev->options.audio_input = default_audio_input;
321
322 dev->udev = usb_get_dev(interface_to_usbdev(interface));
323
324 /* set up the endpoint information */
325 /* use only the first bulk-in and bulk-out endpoints */
326 iface_desc = interface->cur_altsetting;
327 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
328 endpoint = &iface_desc->endpoint[i].desc;
329
330 if (!dev->bulk_in_endpointAddr &&
331 usb_endpoint_is_bulk_in(endpoint)) {
332 /* USB interface description is buggy, reported max
333 * packet size is 512 bytes, windows driver uses 8192 */
334 buffer_size = 8192;
335 dev->bulk_in_size = buffer_size;
336 dev->bulk_in_endpointAddr = endpoint->bEndpointAddress;
337 }
338
339 }
340 if (!dev->bulk_in_endpointAddr) {
341 v4l2_err(&dev->v4l2_dev, "Could not find bulk-in endpoint\n");
342 goto error;
343 }
344
345 /* init the device */
346 if (hdpvr_device_init(dev)) {
347 v4l2_err(&dev->v4l2_dev, "device init failed\n");
348 goto error;
349 }
350
351 mutex_lock(&dev->io_mutex);
352 if (hdpvr_alloc_buffers(dev, NUM_BUFFERS)) {
353 v4l2_err(&dev->v4l2_dev,
354 "allocating transfer buffers failed\n");
355 goto error;
356 }
357 mutex_unlock(&dev->io_mutex);
358
359 if (hdpvr_register_videodev(dev, &interface->dev,
360 video_nr[atomic_inc_return(&dev_nr)])) {
361 v4l2_err(&dev->v4l2_dev, "registering videodev failed\n");
362 goto error;
363 }
364
365#ifdef CONFIG_I2C
366 /* until i2c is working properly */
367 retval = 0; /* hdpvr_register_i2c_adapter(dev); */
368 if (retval < 0) {
369 v4l2_err(&dev->v4l2_dev, "registering i2c adapter failed\n");
370 goto error;
371 }
372#endif /* CONFIG_I2C */
373
374 /* save our data pointer in this interface device */
375 usb_set_intfdata(interface, dev);
376
377 /* let the user know what node this device is now attached to */
378 v4l2_info(&dev->v4l2_dev, "device now attached to /dev/video%d\n",
379 dev->video_dev->minor);
380 return 0;
381
382error:
383 if (dev) {
384 mutex_unlock(&dev->io_mutex);
385 /* this frees allocated memory */
386 hdpvr_delete(dev);
387 }
388 return retval;
389}
390
391static void hdpvr_disconnect(struct usb_interface *interface)
392{
393 struct hdpvr_device *dev;
394 int minor;
395
396 dev = usb_get_intfdata(interface);
397 usb_set_intfdata(interface, NULL);
398
399 minor = dev->video_dev->minor;
400
401 /* prevent more I/O from starting and stop any ongoing */
402 mutex_lock(&dev->io_mutex);
403 dev->status = STATUS_DISCONNECTED;
404 v4l2_device_disconnect(&dev->v4l2_dev);
405 video_unregister_device(dev->video_dev);
406 wake_up_interruptible(&dev->wait_data);
407 wake_up_interruptible(&dev->wait_buffer);
408 mutex_unlock(&dev->io_mutex);
409 msleep(100);
410 flush_workqueue(dev->workqueue);
411 mutex_lock(&dev->io_mutex);
412 hdpvr_cancel_queue(dev);
413 destroy_workqueue(dev->workqueue);
414 mutex_unlock(&dev->io_mutex);
415
416 /* deregister I2C adapter */
417#ifdef CONFIG_I2C
418 mutex_lock(&dev->i2c_mutex);
419 if (dev->i2c_adapter)
420 i2c_del_adapter(dev->i2c_adapter);
421 kfree(dev->i2c_adapter);
422 dev->i2c_adapter = NULL;
423 mutex_unlock(&dev->i2c_mutex);
424#endif /* CONFIG_I2C */
425
426 atomic_dec(&dev_nr);
427
428 v4l2_info(&dev->v4l2_dev, "device /dev/video%d disconnected\n", minor);
429
430 v4l2_device_unregister(&dev->v4l2_dev);
431 kfree(dev->usbc_buf);
432 kfree(dev);
433}
434
435
436static struct usb_driver hdpvr_usb_driver = {
437 .name = "hdpvr",
438 .probe = hdpvr_probe,
439 .disconnect = hdpvr_disconnect,
440 .id_table = hdpvr_table,
441};
442
443static int __init hdpvr_init(void)
444{
445 int result;
446
447 /* register this driver with the USB subsystem */
448 result = usb_register(&hdpvr_usb_driver);
449 if (result)
450 err("usb_register failed. Error number %d", result);
451
452 return result;
453}
454
455static void __exit hdpvr_exit(void)
456{
457 /* deregister this driver with the USB subsystem */
458 usb_deregister(&hdpvr_usb_driver);
459}
460
461module_init(hdpvr_init);
462module_exit(hdpvr_exit);
463
464MODULE_LICENSE("GPL");
465MODULE_AUTHOR("Janne Grunau");
466MODULE_DESCRIPTION("Hauppauge HD PVR driver");
diff --git a/drivers/media/video/hdpvr/hdpvr-i2c.c b/drivers/media/video/hdpvr/hdpvr-i2c.c
new file mode 100644
index 000000000000..c4b5d1515c10
--- /dev/null
+++ b/drivers/media/video/hdpvr/hdpvr-i2c.c
@@ -0,0 +1,145 @@
1
2/*
3 * Hauppauge HD PVR USB driver
4 *
5 * Copyright (C) 2008 Janne Grunau (j@jannau.net)
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation, version 2.
10 *
11 */
12
13#include <linux/i2c.h>
14
15#include "hdpvr.h"
16
17#define CTRL_READ_REQUEST 0xb8
18#define CTRL_WRITE_REQUEST 0x38
19
20#define REQTYPE_I2C_READ 0xb1
21#define REQTYPE_I2C_WRITE 0xb0
22#define REQTYPE_I2C_WRITE_STATT 0xd0
23
24static int hdpvr_i2c_read(struct hdpvr_device *dev, unsigned char addr,
25 char *data, int len)
26{
27 int ret;
28 char *buf = kmalloc(len, GFP_KERNEL);
29 if (!buf)
30 return -ENOMEM;
31
32 ret = usb_control_msg(dev->udev,
33 usb_rcvctrlpipe(dev->udev, 0),
34 REQTYPE_I2C_READ, CTRL_READ_REQUEST,
35 0x100|addr, 0, buf, len, 1000);
36
37 if (ret == len) {
38 memcpy(data, buf, len);
39 ret = 0;
40 } else if (ret >= 0)
41 ret = -EIO;
42
43 kfree(buf);
44
45 return ret;
46}
47
48static int hdpvr_i2c_write(struct hdpvr_device *dev, unsigned char addr,
49 char *data, int len)
50{
51 int ret;
52 char *buf = kmalloc(len, GFP_KERNEL);
53 if (!buf)
54 return -ENOMEM;
55
56 memcpy(buf, data, len);
57 ret = usb_control_msg(dev->udev,
58 usb_sndctrlpipe(dev->udev, 0),
59 REQTYPE_I2C_WRITE, CTRL_WRITE_REQUEST,
60 0x100|addr, 0, buf, len, 1000);
61
62 if (ret < 0)
63 goto error;
64
65 ret = usb_control_msg(dev->udev,
66 usb_rcvctrlpipe(dev->udev, 0),
67 REQTYPE_I2C_WRITE_STATT, CTRL_READ_REQUEST,
68 0, 0, buf, 2, 1000);
69
70 if (ret == 2)
71 ret = 0;
72 else if (ret >= 0)
73 ret = -EIO;
74
75error:
76 kfree(buf);
77 return ret;
78}
79
80static int hdpvr_transfer(struct i2c_adapter *i2c_adapter, struct i2c_msg *msgs,
81 int num)
82{
83 struct hdpvr_device *dev = i2c_get_adapdata(i2c_adapter);
84 int retval = 0, i, addr;
85
86 if (num <= 0)
87 return 0;
88
89 mutex_lock(&dev->i2c_mutex);
90
91 for (i = 0; i < num && !retval; i++) {
92 addr = msgs[i].addr << 1;
93
94 if (msgs[i].flags & I2C_M_RD)
95 retval = hdpvr_i2c_read(dev, addr, msgs[i].buf,
96 msgs[i].len);
97 else
98 retval = hdpvr_i2c_write(dev, addr, msgs[i].buf,
99 msgs[i].len);
100 }
101
102 mutex_unlock(&dev->i2c_mutex);
103
104 return retval ? retval : num;
105}
106
107static u32 hdpvr_functionality(struct i2c_adapter *adapter)
108{
109 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
110}
111
112static struct i2c_algorithm hdpvr_algo = {
113 .master_xfer = hdpvr_transfer,
114 .functionality = hdpvr_functionality,
115};
116
117int hdpvr_register_i2c_adapter(struct hdpvr_device *dev)
118{
119 struct i2c_adapter *i2c_adap;
120 int retval = -ENOMEM;
121
122 i2c_adap = kzalloc(sizeof(struct i2c_adapter), GFP_KERNEL);
123 if (i2c_adap == NULL)
124 goto error;
125
126 strlcpy(i2c_adap->name, "Hauppauge HD PVR I2C",
127 sizeof(i2c_adap->name));
128 i2c_adap->algo = &hdpvr_algo;
129 i2c_adap->class = I2C_CLASS_TV_ANALOG;
130 i2c_adap->id = I2C_HW_B_HDPVR;
131 i2c_adap->owner = THIS_MODULE;
132 i2c_adap->dev.parent = &dev->udev->dev;
133
134 i2c_set_adapdata(i2c_adap, dev);
135
136 retval = i2c_add_adapter(i2c_adap);
137
138 if (!retval)
139 dev->i2c_adapter = i2c_adap;
140 else
141 kfree(i2c_adap);
142
143error:
144 return retval;
145}
diff --git a/drivers/media/video/hdpvr/hdpvr-video.c b/drivers/media/video/hdpvr/hdpvr-video.c
new file mode 100644
index 000000000000..3e6ffee8dfed
--- /dev/null
+++ b/drivers/media/video/hdpvr/hdpvr-video.c
@@ -0,0 +1,1248 @@
1/*
2 * Hauppauge HD PVR USB driver - video 4 linux 2 interface
3 *
4 * Copyright (C) 2008 Janne Grunau (j@jannau.net)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, version 2.
9 *
10 */
11
12#include <linux/kernel.h>
13#include <linux/errno.h>
14#include <linux/init.h>
15#include <linux/slab.h>
16#include <linux/module.h>
17#include <linux/uaccess.h>
18#include <linux/usb.h>
19#include <linux/mutex.h>
20#include <linux/version.h>
21#include <linux/workqueue.h>
22
23#include <linux/videodev2.h>
24#include <media/v4l2-dev.h>
25#include <media/v4l2-common.h>
26#include <media/v4l2-ioctl.h>
27#include "hdpvr.h"
28
29#define BULK_URB_TIMEOUT 1250 /* 1.25 seconds */
30
31#define print_buffer_status() { \
32 v4l2_dbg(MSG_BUFFER, hdpvr_debug, &dev->v4l2_dev, \
33 "%s:%d buffer stat: %d free, %d proc\n", \
34 __func__, __LINE__, \
35 list_size(&dev->free_buff_list), \
36 list_size(&dev->rec_buff_list)); }
37
38struct hdpvr_fh {
39 struct hdpvr_device *dev;
40};
41
42static uint list_size(struct list_head *list)
43{
44 struct list_head *tmp;
45 uint count = 0;
46
47 list_for_each(tmp, list) {
48 count++;
49 }
50
51 return count;
52}
53
54/*=========================================================================*/
55/* urb callback */
56static void hdpvr_read_bulk_callback(struct urb *urb)
57{
58 struct hdpvr_buffer *buf = (struct hdpvr_buffer *)urb->context;
59 struct hdpvr_device *dev = buf->dev;
60
61 /* marking buffer as received and wake waiting */
62 buf->status = BUFSTAT_READY;
63 wake_up_interruptible(&dev->wait_data);
64}
65
66/*=========================================================================*/
67/* bufffer bits */
68
69/* function expects dev->io_mutex to be hold by caller */
70int hdpvr_cancel_queue(struct hdpvr_device *dev)
71{
72 struct hdpvr_buffer *buf;
73
74 list_for_each_entry(buf, &dev->rec_buff_list, buff_list) {
75 usb_kill_urb(buf->urb);
76 buf->status = BUFSTAT_AVAILABLE;
77 }
78
79 list_splice_init(&dev->rec_buff_list, dev->free_buff_list.prev);
80
81 return 0;
82}
83
84static int hdpvr_free_queue(struct list_head *q)
85{
86 struct list_head *tmp;
87 struct list_head *p;
88 struct hdpvr_buffer *buf;
89 struct urb *urb;
90
91 for (p = q->next; p != q;) {
92 buf = list_entry(p, struct hdpvr_buffer, buff_list);
93
94 urb = buf->urb;
95 usb_buffer_free(urb->dev, urb->transfer_buffer_length,
96 urb->transfer_buffer, urb->transfer_dma);
97 usb_free_urb(urb);
98 tmp = p->next;
99 list_del(p);
100 kfree(buf);
101 p = tmp;
102 }
103
104 return 0;
105}
106
107/* function expects dev->io_mutex to be hold by caller */
108int hdpvr_free_buffers(struct hdpvr_device *dev)
109{
110 hdpvr_cancel_queue(dev);
111
112 hdpvr_free_queue(&dev->free_buff_list);
113 hdpvr_free_queue(&dev->rec_buff_list);
114
115 return 0;
116}
117
118/* function expects dev->io_mutex to be hold by caller */
119int hdpvr_alloc_buffers(struct hdpvr_device *dev, uint count)
120{
121 uint i;
122 int retval = -ENOMEM;
123 u8 *mem;
124 struct hdpvr_buffer *buf;
125 struct urb *urb;
126
127 v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev,
128 "allocating %u buffers\n", count);
129
130 for (i = 0; i < count; i++) {
131
132 buf = kzalloc(sizeof(struct hdpvr_buffer), GFP_KERNEL);
133 if (!buf) {
134 v4l2_err(&dev->v4l2_dev, "cannot allocate buffer\n");
135 goto exit;
136 }
137 buf->dev = dev;
138
139 urb = usb_alloc_urb(0, GFP_KERNEL);
140 if (!urb) {
141 v4l2_err(&dev->v4l2_dev, "cannot allocate urb\n");
142 goto exit;
143 }
144 buf->urb = urb;
145
146 mem = usb_buffer_alloc(dev->udev, dev->bulk_in_size, GFP_KERNEL,
147 &urb->transfer_dma);
148 if (!mem) {
149 v4l2_err(&dev->v4l2_dev,
150 "cannot allocate usb transfer buffer\n");
151 goto exit;
152 }
153
154 usb_fill_bulk_urb(buf->urb, dev->udev,
155 usb_rcvbulkpipe(dev->udev,
156 dev->bulk_in_endpointAddr),
157 mem, dev->bulk_in_size,
158 hdpvr_read_bulk_callback, buf);
159
160 buf->status = BUFSTAT_AVAILABLE;
161 list_add_tail(&buf->buff_list, &dev->free_buff_list);
162 }
163 return 0;
164exit:
165 hdpvr_free_buffers(dev);
166 return retval;
167}
168
169static int hdpvr_submit_buffers(struct hdpvr_device *dev)
170{
171 struct hdpvr_buffer *buf;
172 struct urb *urb;
173 int ret = 0, err_count = 0;
174
175 mutex_lock(&dev->io_mutex);
176
177 while (dev->status == STATUS_STREAMING &&
178 !list_empty(&dev->free_buff_list)) {
179
180 buf = list_entry(dev->free_buff_list.next, struct hdpvr_buffer,
181 buff_list);
182 if (buf->status != BUFSTAT_AVAILABLE) {
183 v4l2_err(&dev->v4l2_dev,
184 "buffer not marked as availbale\n");
185 ret = -EFAULT;
186 goto err;
187 }
188
189 urb = buf->urb;
190 urb->status = 0;
191 urb->actual_length = 0;
192 ret = usb_submit_urb(urb, GFP_KERNEL);
193 if (ret) {
194 v4l2_err(&dev->v4l2_dev,
195 "usb_submit_urb in %s returned %d\n",
196 __func__, ret);
197 if (++err_count > 2)
198 break;
199 continue;
200 }
201 buf->status = BUFSTAT_INPROGRESS;
202 list_move_tail(&buf->buff_list, &dev->rec_buff_list);
203 }
204err:
205 print_buffer_status();
206 mutex_unlock(&dev->io_mutex);
207 return ret;
208}
209
210static struct hdpvr_buffer *hdpvr_get_next_buffer(struct hdpvr_device *dev)
211{
212 struct hdpvr_buffer *buf;
213
214 mutex_lock(&dev->io_mutex);
215
216 if (list_empty(&dev->rec_buff_list)) {
217 mutex_unlock(&dev->io_mutex);
218 return NULL;
219 }
220
221 buf = list_entry(dev->rec_buff_list.next, struct hdpvr_buffer,
222 buff_list);
223 mutex_unlock(&dev->io_mutex);
224
225 return buf;
226}
227
228static void hdpvr_transmit_buffers(struct work_struct *work)
229{
230 struct hdpvr_device *dev = container_of(work, struct hdpvr_device,
231 worker);
232
233 while (dev->status == STATUS_STREAMING) {
234
235 if (hdpvr_submit_buffers(dev)) {
236 v4l2_err(&dev->v4l2_dev, "couldn't submit buffers\n");
237 goto error;
238 }
239 if (wait_event_interruptible(dev->wait_buffer,
240 !list_empty(&dev->free_buff_list) ||
241 dev->status != STATUS_STREAMING))
242 goto error;
243 }
244
245 v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev,
246 "transmit worker exited\n");
247 return;
248error:
249 v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev,
250 "transmit buffers errored\n");
251 dev->status = STATUS_ERROR;
252}
253
254/* function expects dev->io_mutex to be hold by caller */
255static int hdpvr_start_streaming(struct hdpvr_device *dev)
256{
257 int ret;
258 struct hdpvr_video_info *vidinf;
259
260 if (dev->status == STATUS_STREAMING)
261 return 0;
262 else if (dev->status != STATUS_IDLE)
263 return -EAGAIN;
264
265 vidinf = get_video_info(dev);
266
267 if (vidinf) {
268 v4l2_dbg(MSG_BUFFER, hdpvr_debug, &dev->v4l2_dev,
269 "video signal: %dx%d@%dhz\n", vidinf->width,
270 vidinf->height, vidinf->fps);
271 kfree(vidinf);
272
273 /* start streaming 2 request */
274 ret = usb_control_msg(dev->udev,
275 usb_sndctrlpipe(dev->udev, 0),
276 0xb8, 0x38, 0x1, 0, NULL, 0, 8000);
277 v4l2_dbg(MSG_BUFFER, hdpvr_debug, &dev->v4l2_dev,
278 "encoder start control request returned %d\n", ret);
279
280 hdpvr_config_call(dev, CTRL_START_STREAMING_VALUE, 0x00);
281
282 INIT_WORK(&dev->worker, hdpvr_transmit_buffers);
283 queue_work(dev->workqueue, &dev->worker);
284
285 v4l2_dbg(MSG_BUFFER, hdpvr_debug, &dev->v4l2_dev,
286 "streaming started\n");
287 dev->status = STATUS_STREAMING;
288
289 return 0;
290 }
291 msleep(250);
292 v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev,
293 "no video signal at input %d\n", dev->options.video_input);
294 return -EAGAIN;
295}
296
297
298/* function expects dev->io_mutex to be hold by caller */
299static int hdpvr_stop_streaming(struct hdpvr_device *dev)
300{
301 uint actual_length, c = 0;
302 u8 *buf;
303
304 if (dev->status == STATUS_IDLE)
305 return 0;
306 else if (dev->status != STATUS_STREAMING)
307 return -EAGAIN;
308
309 buf = kmalloc(dev->bulk_in_size, GFP_KERNEL);
310 if (!buf)
311 v4l2_err(&dev->v4l2_dev, "failed to allocate temporary buffer "
312 "for emptying the internal device buffer. "
313 "Next capture start will be slow\n");
314
315 dev->status = STATUS_SHUTTING_DOWN;
316 hdpvr_config_call(dev, CTRL_STOP_STREAMING_VALUE, 0x00);
317 mutex_unlock(&dev->io_mutex);
318
319 wake_up_interruptible(&dev->wait_buffer);
320 msleep(50);
321
322 flush_workqueue(dev->workqueue);
323
324 mutex_lock(&dev->io_mutex);
325 /* kill the still outstanding urbs */
326 hdpvr_cancel_queue(dev);
327
328 /* emptying the device buffer beforeshutting it down */
329 while (buf && ++c < 500 &&
330 !usb_bulk_msg(dev->udev,
331 usb_rcvbulkpipe(dev->udev,
332 dev->bulk_in_endpointAddr),
333 buf, dev->bulk_in_size, &actual_length,
334 BULK_URB_TIMEOUT)) {
335 /* wait */
336 msleep(5);
337 v4l2_dbg(MSG_BUFFER, hdpvr_debug, &dev->v4l2_dev,
338 "%2d: got %d bytes\n", c, actual_length);
339 }
340 kfree(buf);
341 v4l2_dbg(MSG_BUFFER, hdpvr_debug, &dev->v4l2_dev,
342 "used %d urbs to empty device buffers\n", c-1);
343 msleep(10);
344
345 dev->status = STATUS_IDLE;
346
347 return 0;
348}
349
350
351/*=======================================================================*/
352/*
353 * video 4 linux 2 file operations
354 */
355
356static int hdpvr_open(struct file *file)
357{
358 struct hdpvr_device *dev;
359 struct hdpvr_fh *fh;
360 int retval = -ENOMEM;
361
362 dev = (struct hdpvr_device *)video_get_drvdata(video_devdata(file));
363 if (!dev) {
364 v4l2_err(&dev->v4l2_dev, "open failing with with ENODEV\n");
365 retval = -ENODEV;
366 goto err;
367 }
368
369 fh = kzalloc(sizeof(struct hdpvr_fh), GFP_KERNEL);
370 if (!fh) {
371 v4l2_err(&dev->v4l2_dev, "Out of memory\n");
372 goto err;
373 }
374 /* lock the device to allow correctly handling errors
375 * in resumption */
376 mutex_lock(&dev->io_mutex);
377 dev->open_count++;
378
379 fh->dev = dev;
380
381 /* save our object in the file's private structure */
382 file->private_data = fh;
383
384 retval = 0;
385err:
386 mutex_unlock(&dev->io_mutex);
387 return retval;
388}
389
390static int hdpvr_release(struct file *file)
391{
392 struct hdpvr_fh *fh = (struct hdpvr_fh *)file->private_data;
393 struct hdpvr_device *dev = fh->dev;
394
395 if (!dev)
396 return -ENODEV;
397
398 mutex_lock(&dev->io_mutex);
399 if (!(--dev->open_count) && dev->status == STATUS_STREAMING)
400 hdpvr_stop_streaming(dev);
401
402 mutex_unlock(&dev->io_mutex);
403
404 return 0;
405}
406
407/*
408 * hdpvr_v4l2_read()
409 * will allocate buffers when called for the first time
410 */
411static ssize_t hdpvr_read(struct file *file, char __user *buffer, size_t count,
412 loff_t *pos)
413{
414 struct hdpvr_fh *fh = file->private_data;
415 struct hdpvr_device *dev = fh->dev;
416 struct hdpvr_buffer *buf = NULL;
417 struct urb *urb;
418 unsigned int ret = 0;
419 int rem, cnt;
420
421 if (*pos)
422 return -ESPIPE;
423
424 if (!dev)
425 return -ENODEV;
426
427 mutex_lock(&dev->io_mutex);
428 if (dev->status == STATUS_IDLE) {
429 if (hdpvr_start_streaming(dev)) {
430 v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev,
431 "start_streaming failed\n");
432 ret = -EIO;
433 msleep(200);
434 dev->status = STATUS_IDLE;
435 mutex_unlock(&dev->io_mutex);
436 goto err;
437 }
438 print_buffer_status();
439 }
440 mutex_unlock(&dev->io_mutex);
441
442 /* wait for the first buffer */
443 if (!(file->f_flags & O_NONBLOCK)) {
444 if (wait_event_interruptible(dev->wait_data,
445 hdpvr_get_next_buffer(dev)))
446 return -ERESTARTSYS;
447 }
448
449 buf = hdpvr_get_next_buffer(dev);
450
451 while (count > 0 && buf) {
452
453 if (buf->status != BUFSTAT_READY &&
454 dev->status != STATUS_DISCONNECTED) {
455 /* return nonblocking */
456 if (file->f_flags & O_NONBLOCK) {
457 if (!ret)
458 ret = -EAGAIN;
459 goto err;
460 }
461
462 if (wait_event_interruptible(dev->wait_data,
463 buf->status == BUFSTAT_READY)) {
464 ret = -ERESTARTSYS;
465 goto err;
466 }
467 }
468
469 if (buf->status != BUFSTAT_READY)
470 break;
471
472 /* set remaining bytes to copy */
473 urb = buf->urb;
474 rem = urb->actual_length - buf->pos;
475 cnt = rem > count ? count : rem;
476
477 if (copy_to_user(buffer, urb->transfer_buffer + buf->pos,
478 cnt)) {
479 v4l2_err(&dev->v4l2_dev, "read: copy_to_user failed\n");
480 if (!ret)
481 ret = -EFAULT;
482 goto err;
483 }
484
485 buf->pos += cnt;
486 count -= cnt;
487 buffer += cnt;
488 ret += cnt;
489
490 /* finished, take next buffer */
491 if (buf->pos == urb->actual_length) {
492 mutex_lock(&dev->io_mutex);
493 buf->pos = 0;
494 buf->status = BUFSTAT_AVAILABLE;
495
496 list_move_tail(&buf->buff_list, &dev->free_buff_list);
497
498 print_buffer_status();
499
500 mutex_unlock(&dev->io_mutex);
501
502 wake_up_interruptible(&dev->wait_buffer);
503
504 buf = hdpvr_get_next_buffer(dev);
505 }
506 }
507err:
508 if (!ret && !buf)
509 ret = -EAGAIN;
510 return ret;
511}
512
513static unsigned int hdpvr_poll(struct file *filp, poll_table *wait)
514{
515 struct hdpvr_buffer *buf = NULL;
516 struct hdpvr_fh *fh = (struct hdpvr_fh *)filp->private_data;
517 struct hdpvr_device *dev = fh->dev;
518 unsigned int mask = 0;
519
520 mutex_lock(&dev->io_mutex);
521
522 if (video_is_unregistered(dev->video_dev))
523 return -EIO;
524
525 if (dev->status == STATUS_IDLE) {
526 if (hdpvr_start_streaming(dev)) {
527 v4l2_dbg(MSG_BUFFER, hdpvr_debug, &dev->v4l2_dev,
528 "start_streaming failed\n");
529 dev->status = STATUS_IDLE;
530 }
531
532 print_buffer_status();
533 }
534 mutex_unlock(&dev->io_mutex);
535
536 buf = hdpvr_get_next_buffer(dev);
537 /* only wait if no data is available */
538 if (!buf || buf->status != BUFSTAT_READY) {
539 poll_wait(filp, &dev->wait_data, wait);
540 buf = hdpvr_get_next_buffer(dev);
541 }
542 if (buf && buf->status == BUFSTAT_READY)
543 mask |= POLLIN | POLLRDNORM;
544
545 return mask;
546}
547
548
549static const struct v4l2_file_operations hdpvr_fops = {
550 .owner = THIS_MODULE,
551 .open = hdpvr_open,
552 .release = hdpvr_release,
553 .read = hdpvr_read,
554 .poll = hdpvr_poll,
555 .unlocked_ioctl = video_ioctl2,
556};
557
558/*=======================================================================*/
559/*
560 * V4L2 ioctl handling
561 */
562
563static int vidioc_querycap(struct file *file, void *priv,
564 struct v4l2_capability *cap)
565{
566 struct hdpvr_device *dev = video_drvdata(file);
567
568 strcpy(cap->driver, "hdpvr");
569 strcpy(cap->card, "Haupauge HD PVR");
570 usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info));
571 cap->version = HDPVR_VERSION;
572 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE |
573 V4L2_CAP_AUDIO |
574 V4L2_CAP_READWRITE;
575 return 0;
576}
577
578static int vidioc_s_std(struct file *file, void *private_data,
579 v4l2_std_id *std)
580{
581 struct hdpvr_fh *fh = file->private_data;
582 struct hdpvr_device *dev = fh->dev;
583 u8 std_type = 1;
584
585 if (*std & (V4L2_STD_NTSC | V4L2_STD_PAL_60))
586 std_type = 0;
587
588 return hdpvr_config_call(dev, CTRL_VIDEO_STD_TYPE, std_type);
589}
590
591static const char *iname[] = {
592 [HDPVR_COMPONENT] = "Component",
593 [HDPVR_SVIDEO] = "S-Video",
594 [HDPVR_COMPOSITE] = "Composite",
595};
596
597static int vidioc_enum_input(struct file *file, void *priv,
598 struct v4l2_input *i)
599{
600 struct hdpvr_fh *fh = file->private_data;
601 struct hdpvr_device *dev = fh->dev;
602 unsigned int n;
603
604 n = i->index;
605 if (n >= HDPVR_VIDEO_INPUTS)
606 return -EINVAL;
607
608 i->type = V4L2_INPUT_TYPE_CAMERA;
609
610 strncpy(i->name, iname[n], sizeof(i->name) - 1);
611 i->name[sizeof(i->name) - 1] = '\0';
612
613 i->audioset = 1<<HDPVR_RCA_FRONT | 1<<HDPVR_RCA_BACK | 1<<HDPVR_SPDIF;
614
615 i->std = dev->video_dev->tvnorms;
616
617 return 0;
618}
619
620static int vidioc_s_input(struct file *file, void *private_data,
621 unsigned int index)
622{
623 struct hdpvr_fh *fh = file->private_data;
624 struct hdpvr_device *dev = fh->dev;
625 int retval;
626
627 if (index >= HDPVR_VIDEO_INPUTS)
628 return -EINVAL;
629
630 if (dev->status != STATUS_IDLE)
631 return -EAGAIN;
632
633 retval = hdpvr_config_call(dev, CTRL_VIDEO_INPUT_VALUE, index+1);
634 if (!retval)
635 dev->options.video_input = index;
636
637 return retval;
638}
639
640static int vidioc_g_input(struct file *file, void *private_data,
641 unsigned int *index)
642{
643 struct hdpvr_fh *fh = file->private_data;
644 struct hdpvr_device *dev = fh->dev;
645
646 *index = dev->options.video_input;
647 return 0;
648}
649
650
651static const char *audio_iname[] = {
652 [HDPVR_RCA_FRONT] = "RCA front",
653 [HDPVR_RCA_BACK] = "RCA back",
654 [HDPVR_SPDIF] = "SPDIF",
655};
656
657static int vidioc_enumaudio(struct file *file, void *priv,
658 struct v4l2_audio *audio)
659{
660 unsigned int n;
661
662 n = audio->index;
663 if (n >= HDPVR_AUDIO_INPUTS)
664 return -EINVAL;
665
666 audio->capability = V4L2_AUDCAP_STEREO;
667
668 strncpy(audio->name, audio_iname[n], sizeof(audio->name) - 1);
669 audio->name[sizeof(audio->name) - 1] = '\0';
670
671 return 0;
672}
673
674static int vidioc_s_audio(struct file *file, void *private_data,
675 struct v4l2_audio *audio)
676{
677 struct hdpvr_fh *fh = file->private_data;
678 struct hdpvr_device *dev = fh->dev;
679 int retval;
680
681 if (audio->index >= HDPVR_AUDIO_INPUTS)
682 return -EINVAL;
683
684 if (dev->status != STATUS_IDLE)
685 return -EAGAIN;
686
687 retval = hdpvr_set_audio(dev, audio->index+1, dev->options.audio_codec);
688 if (!retval)
689 dev->options.audio_input = audio->index;
690
691 return retval;
692}
693
694static int vidioc_g_audio(struct file *file, void *private_data,
695 struct v4l2_audio *audio)
696{
697 struct hdpvr_fh *fh = file->private_data;
698 struct hdpvr_device *dev = fh->dev;
699
700 audio->index = dev->options.audio_input;
701 audio->capability = V4L2_AUDCAP_STEREO;
702 strncpy(audio->name, audio_iname[audio->index], sizeof(audio->name));
703 audio->name[sizeof(audio->name) - 1] = '\0';
704 return 0;
705}
706
707static const s32 supported_v4l2_ctrls[] = {
708 V4L2_CID_BRIGHTNESS,
709 V4L2_CID_CONTRAST,
710 V4L2_CID_SATURATION,
711 V4L2_CID_HUE,
712 V4L2_CID_SHARPNESS,
713 V4L2_CID_MPEG_AUDIO_ENCODING,
714 V4L2_CID_MPEG_VIDEO_ENCODING,
715 V4L2_CID_MPEG_VIDEO_BITRATE_MODE,
716 V4L2_CID_MPEG_VIDEO_BITRATE,
717 V4L2_CID_MPEG_VIDEO_BITRATE_PEAK,
718};
719
720static int fill_queryctrl(struct hdpvr_options *opt, struct v4l2_queryctrl *qc,
721 int ac3)
722{
723 int err;
724
725 switch (qc->id) {
726 case V4L2_CID_BRIGHTNESS:
727 return v4l2_ctrl_query_fill(qc, 0x0, 0xff, 1, 0x86);
728 case V4L2_CID_CONTRAST:
729 return v4l2_ctrl_query_fill(qc, 0x0, 0xff, 1, 0x80);
730 case V4L2_CID_SATURATION:
731 return v4l2_ctrl_query_fill(qc, 0x0, 0xff, 1, 0x80);
732 case V4L2_CID_HUE:
733 return v4l2_ctrl_query_fill(qc, 0x0, 0xff, 1, 0x80);
734 case V4L2_CID_SHARPNESS:
735 return v4l2_ctrl_query_fill(qc, 0x0, 0xff, 1, 0x80);
736 case V4L2_CID_MPEG_AUDIO_ENCODING:
737 return v4l2_ctrl_query_fill(
738 qc, V4L2_MPEG_AUDIO_ENCODING_AAC,
739 ac3 ? V4L2_MPEG_AUDIO_ENCODING_AC3
740 : V4L2_MPEG_AUDIO_ENCODING_AAC,
741 1, V4L2_MPEG_AUDIO_ENCODING_AAC);
742 case V4L2_CID_MPEG_VIDEO_ENCODING:
743 return v4l2_ctrl_query_fill(
744 qc, V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC,
745 V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC, 1,
746 V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC);
747
748/* case V4L2_CID_MPEG_VIDEO_? maybe keyframe interval: */
749/* return v4l2_ctrl_query_fill(qc, 0, 128, 128, 0); */
750 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
751 return v4l2_ctrl_query_fill(
752 qc, V4L2_MPEG_VIDEO_BITRATE_MODE_VBR,
753 V4L2_MPEG_VIDEO_BITRATE_MODE_CBR, 1,
754 V4L2_MPEG_VIDEO_BITRATE_MODE_CBR);
755
756 case V4L2_CID_MPEG_VIDEO_BITRATE:
757 return v4l2_ctrl_query_fill(qc, 1000000, 13500000, 100000,
758 6500000);
759 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK:
760 err = v4l2_ctrl_query_fill(qc, 1100000, 20200000, 100000,
761 9000000);
762 if (!err && opt->bitrate_mode == HDPVR_CONSTANT)
763 qc->flags |= V4L2_CTRL_FLAG_INACTIVE;
764 return err;
765 default:
766 return -EINVAL;
767 }
768}
769
770static int vidioc_queryctrl(struct file *file, void *private_data,
771 struct v4l2_queryctrl *qc)
772{
773 struct hdpvr_fh *fh = file->private_data;
774 struct hdpvr_device *dev = fh->dev;
775 int i, next;
776 u32 id = qc->id;
777
778 memset(qc, 0, sizeof(*qc));
779
780 next = !!(id & V4L2_CTRL_FLAG_NEXT_CTRL);
781 qc->id = id & ~V4L2_CTRL_FLAG_NEXT_CTRL;
782
783 for (i = 0; i < ARRAY_SIZE(supported_v4l2_ctrls); i++) {
784 if (next) {
785 if (qc->id < supported_v4l2_ctrls[i])
786 qc->id = supported_v4l2_ctrls[i];
787 else
788 continue;
789 }
790
791 if (qc->id == supported_v4l2_ctrls[i])
792 return fill_queryctrl(&dev->options, qc,
793 dev->flags & HDPVR_FLAG_AC3_CAP);
794
795 if (qc->id < supported_v4l2_ctrls[i])
796 break;
797 }
798
799 return -EINVAL;
800}
801
802static int vidioc_g_ctrl(struct file *file, void *private_data,
803 struct v4l2_control *ctrl)
804{
805 struct hdpvr_fh *fh = file->private_data;
806 struct hdpvr_device *dev = fh->dev;
807
808 switch (ctrl->id) {
809 case V4L2_CID_BRIGHTNESS:
810 ctrl->value = dev->options.brightness;
811 break;
812 case V4L2_CID_CONTRAST:
813 ctrl->value = dev->options.contrast;
814 break;
815 case V4L2_CID_SATURATION:
816 ctrl->value = dev->options.saturation;
817 break;
818 case V4L2_CID_HUE:
819 ctrl->value = dev->options.hue;
820 break;
821 case V4L2_CID_SHARPNESS:
822 ctrl->value = dev->options.sharpness;
823 break;
824 default:
825 return -EINVAL;
826 }
827 return 0;
828}
829
830static int vidioc_s_ctrl(struct file *file, void *private_data,
831 struct v4l2_control *ctrl)
832{
833 struct hdpvr_fh *fh = file->private_data;
834 struct hdpvr_device *dev = fh->dev;
835 int retval;
836
837 switch (ctrl->id) {
838 case V4L2_CID_BRIGHTNESS:
839 retval = hdpvr_config_call(dev, CTRL_BRIGHTNESS, ctrl->value);
840 if (!retval)
841 dev->options.brightness = ctrl->value;
842 break;
843 case V4L2_CID_CONTRAST:
844 retval = hdpvr_config_call(dev, CTRL_CONTRAST, ctrl->value);
845 if (!retval)
846 dev->options.contrast = ctrl->value;
847 break;
848 case V4L2_CID_SATURATION:
849 retval = hdpvr_config_call(dev, CTRL_SATURATION, ctrl->value);
850 if (!retval)
851 dev->options.saturation = ctrl->value;
852 break;
853 case V4L2_CID_HUE:
854 retval = hdpvr_config_call(dev, CTRL_HUE, ctrl->value);
855 if (!retval)
856 dev->options.hue = ctrl->value;
857 break;
858 case V4L2_CID_SHARPNESS:
859 retval = hdpvr_config_call(dev, CTRL_SHARPNESS, ctrl->value);
860 if (!retval)
861 dev->options.sharpness = ctrl->value;
862 break;
863 default:
864 return -EINVAL;
865 }
866
867 return retval;
868}
869
870
871static int hdpvr_get_ctrl(struct hdpvr_options *opt,
872 struct v4l2_ext_control *ctrl)
873{
874 switch (ctrl->id) {
875 case V4L2_CID_MPEG_AUDIO_ENCODING:
876 ctrl->value = opt->audio_codec;
877 break;
878 case V4L2_CID_MPEG_VIDEO_ENCODING:
879 ctrl->value = V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC;
880 break;
881/* case V4L2_CID_MPEG_VIDEO_B_FRAMES: */
882/* ctrl->value = (opt->gop_mode & 0x2) ? 0 : 128; */
883/* break; */
884 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
885 ctrl->value = opt->bitrate_mode == HDPVR_CONSTANT
886 ? V4L2_MPEG_VIDEO_BITRATE_MODE_CBR
887 : V4L2_MPEG_VIDEO_BITRATE_MODE_VBR;
888 break;
889 case V4L2_CID_MPEG_VIDEO_BITRATE:
890 ctrl->value = opt->bitrate * 100000;
891 break;
892 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK:
893 ctrl->value = opt->peak_bitrate * 100000;
894 break;
895 case V4L2_CID_MPEG_STREAM_TYPE:
896 ctrl->value = V4L2_MPEG_STREAM_TYPE_MPEG2_TS;
897 break;
898 default:
899 return -EINVAL;
900 }
901 return 0;
902}
903
904static int vidioc_g_ext_ctrls(struct file *file, void *priv,
905 struct v4l2_ext_controls *ctrls)
906{
907 struct hdpvr_fh *fh = file->private_data;
908 struct hdpvr_device *dev = fh->dev;
909 int i, err = 0;
910
911 if (ctrls->ctrl_class == V4L2_CTRL_CLASS_MPEG) {
912 for (i = 0; i < ctrls->count; i++) {
913 struct v4l2_ext_control *ctrl = ctrls->controls + i;
914
915 err = hdpvr_get_ctrl(&dev->options, ctrl);
916 if (err) {
917 ctrls->error_idx = i;
918 break;
919 }
920 }
921 return err;
922
923 }
924
925 return -EINVAL;
926}
927
928
929static int hdpvr_try_ctrl(struct v4l2_ext_control *ctrl, int ac3)
930{
931 int ret = -EINVAL;
932
933 switch (ctrl->id) {
934 case V4L2_CID_MPEG_AUDIO_ENCODING:
935 if (ctrl->value == V4L2_MPEG_AUDIO_ENCODING_AAC ||
936 (ac3 && ctrl->value == V4L2_MPEG_AUDIO_ENCODING_AC3))
937 ret = 0;
938 break;
939 case V4L2_CID_MPEG_VIDEO_ENCODING:
940 if (ctrl->value == V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC)
941 ret = 0;
942 break;
943/* case V4L2_CID_MPEG_VIDEO_B_FRAMES: */
944/* if (ctrl->value == 0 || ctrl->value == 128) */
945/* ret = 0; */
946/* break; */
947 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
948 if (ctrl->value == V4L2_MPEG_VIDEO_BITRATE_MODE_CBR ||
949 ctrl->value == V4L2_MPEG_VIDEO_BITRATE_MODE_VBR)
950 ret = 0;
951 break;
952 case V4L2_CID_MPEG_VIDEO_BITRATE:
953 {
954 uint bitrate = ctrl->value / 100000;
955 if (bitrate >= 10 && bitrate <= 135)
956 ret = 0;
957 break;
958 }
959 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK:
960 {
961 uint peak_bitrate = ctrl->value / 100000;
962 if (peak_bitrate >= 10 && peak_bitrate <= 202)
963 ret = 0;
964 break;
965 }
966 case V4L2_CID_MPEG_STREAM_TYPE:
967 if (ctrl->value == V4L2_MPEG_STREAM_TYPE_MPEG2_TS)
968 ret = 0;
969 break;
970 default:
971 return -EINVAL;
972 }
973 return 0;
974}
975
976static int vidioc_try_ext_ctrls(struct file *file, void *priv,
977 struct v4l2_ext_controls *ctrls)
978{
979 struct hdpvr_fh *fh = file->private_data;
980 struct hdpvr_device *dev = fh->dev;
981 int i, err = 0;
982
983 if (ctrls->ctrl_class == V4L2_CTRL_CLASS_MPEG) {
984 for (i = 0; i < ctrls->count; i++) {
985 struct v4l2_ext_control *ctrl = ctrls->controls + i;
986
987 err = hdpvr_try_ctrl(ctrl,
988 dev->flags & HDPVR_FLAG_AC3_CAP);
989 if (err) {
990 ctrls->error_idx = i;
991 break;
992 }
993 }
994 return err;
995 }
996
997 return -EINVAL;
998}
999
1000
1001static int hdpvr_set_ctrl(struct hdpvr_device *dev,
1002 struct v4l2_ext_control *ctrl)
1003{
1004 struct hdpvr_options *opt = &dev->options;
1005 int ret = 0;
1006
1007 switch (ctrl->id) {
1008 case V4L2_CID_MPEG_AUDIO_ENCODING:
1009 if (dev->flags & HDPVR_FLAG_AC3_CAP) {
1010 opt->audio_codec = ctrl->value;
1011 ret = hdpvr_set_audio(dev, opt->audio_input,
1012 opt->audio_codec);
1013 }
1014 break;
1015 case V4L2_CID_MPEG_VIDEO_ENCODING:
1016 break;
1017/* case V4L2_CID_MPEG_VIDEO_B_FRAMES: */
1018/* if (ctrl->value == 0 && !(opt->gop_mode & 0x2)) { */
1019/* opt->gop_mode |= 0x2; */
1020/* hdpvr_config_call(dev, CTRL_GOP_MODE_VALUE, */
1021/* opt->gop_mode); */
1022/* } */
1023/* if (ctrl->value == 128 && opt->gop_mode & 0x2) { */
1024/* opt->gop_mode &= ~0x2; */
1025/* hdpvr_config_call(dev, CTRL_GOP_MODE_VALUE, */
1026/* opt->gop_mode); */
1027/* } */
1028/* break; */
1029 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
1030 if (ctrl->value == V4L2_MPEG_VIDEO_BITRATE_MODE_CBR &&
1031 opt->bitrate_mode != HDPVR_CONSTANT) {
1032 opt->bitrate_mode = HDPVR_CONSTANT;
1033 hdpvr_config_call(dev, CTRL_BITRATE_MODE_VALUE,
1034 opt->bitrate_mode);
1035 }
1036 if (ctrl->value == V4L2_MPEG_VIDEO_BITRATE_MODE_VBR &&
1037 opt->bitrate_mode == HDPVR_CONSTANT) {
1038 opt->bitrate_mode = HDPVR_VARIABLE_AVERAGE;
1039 hdpvr_config_call(dev, CTRL_BITRATE_MODE_VALUE,
1040 opt->bitrate_mode);
1041 }
1042 break;
1043 case V4L2_CID_MPEG_VIDEO_BITRATE: {
1044 uint bitrate = ctrl->value / 100000;
1045
1046 opt->bitrate = bitrate;
1047 if (bitrate >= opt->peak_bitrate)
1048 opt->peak_bitrate = bitrate+1;
1049
1050 hdpvr_set_bitrate(dev);
1051 break;
1052 }
1053 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK: {
1054 uint peak_bitrate = ctrl->value / 100000;
1055
1056 if (opt->bitrate_mode == HDPVR_CONSTANT)
1057 break;
1058
1059 if (opt->bitrate < peak_bitrate) {
1060 opt->peak_bitrate = peak_bitrate;
1061 hdpvr_set_bitrate(dev);
1062 } else
1063 ret = -EINVAL;
1064 break;
1065 }
1066 case V4L2_CID_MPEG_STREAM_TYPE:
1067 break;
1068 default:
1069 return -EINVAL;
1070 }
1071 return ret;
1072}
1073
1074static int vidioc_s_ext_ctrls(struct file *file, void *priv,
1075 struct v4l2_ext_controls *ctrls)
1076{
1077 struct hdpvr_fh *fh = file->private_data;
1078 struct hdpvr_device *dev = fh->dev;
1079 int i, err = 0;
1080
1081 if (ctrls->ctrl_class == V4L2_CTRL_CLASS_MPEG) {
1082 for (i = 0; i < ctrls->count; i++) {
1083 struct v4l2_ext_control *ctrl = ctrls->controls + i;
1084
1085 err = hdpvr_try_ctrl(ctrl,
1086 dev->flags & HDPVR_FLAG_AC3_CAP);
1087 if (err) {
1088 ctrls->error_idx = i;
1089 break;
1090 }
1091 err = hdpvr_set_ctrl(dev, ctrl);
1092 if (err) {
1093 ctrls->error_idx = i;
1094 break;
1095 }
1096 }
1097 return err;
1098
1099 }
1100
1101 return -EINVAL;
1102}
1103
1104static int vidioc_enum_fmt_vid_cap(struct file *file, void *private_data,
1105 struct v4l2_fmtdesc *f)
1106{
1107
1108 if (f->index != 0 || f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1109 return -EINVAL;
1110
1111 f->flags = V4L2_FMT_FLAG_COMPRESSED;
1112 strncpy(f->description, "MPEG2-TS with AVC/AAC streams", 32);
1113 f->pixelformat = V4L2_PIX_FMT_MPEG;
1114
1115 return 0;
1116}
1117
1118static int vidioc_g_fmt_vid_cap(struct file *file, void *private_data,
1119 struct v4l2_format *f)
1120{
1121 struct hdpvr_fh *fh = file->private_data;
1122 struct hdpvr_device *dev = fh->dev;
1123 struct hdpvr_video_info *vid_info;
1124
1125 if (!dev)
1126 return -ENODEV;
1127
1128 vid_info = get_video_info(dev);
1129 if (!vid_info)
1130 return -EFAULT;
1131
1132 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1133 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
1134 f->fmt.pix.width = vid_info->width;
1135 f->fmt.pix.height = vid_info->height;
1136 f->fmt.pix.sizeimage = dev->bulk_in_size;
1137 f->fmt.pix.colorspace = 0;
1138 f->fmt.pix.bytesperline = 0;
1139 f->fmt.pix.field = V4L2_FIELD_ANY;
1140
1141 kfree(vid_info);
1142 return 0;
1143}
1144
1145static int vidioc_encoder_cmd(struct file *filp, void *priv,
1146 struct v4l2_encoder_cmd *a)
1147{
1148 struct hdpvr_fh *fh = filp->private_data;
1149 struct hdpvr_device *dev = fh->dev;
1150 int res;
1151
1152 mutex_lock(&dev->io_mutex);
1153
1154 memset(&a->raw, 0, sizeof(a->raw));
1155 switch (a->cmd) {
1156 case V4L2_ENC_CMD_START:
1157 a->flags = 0;
1158 res = hdpvr_start_streaming(dev);
1159 break;
1160 case V4L2_ENC_CMD_STOP:
1161 res = hdpvr_stop_streaming(dev);
1162 break;
1163 default:
1164 v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev,
1165 "Unsupported encoder cmd %d\n", a->cmd);
1166 res = -EINVAL;
1167 }
1168 mutex_unlock(&dev->io_mutex);
1169 return res;
1170}
1171
1172static int vidioc_try_encoder_cmd(struct file *filp, void *priv,
1173 struct v4l2_encoder_cmd *a)
1174{
1175 switch (a->cmd) {
1176 case V4L2_ENC_CMD_START:
1177 case V4L2_ENC_CMD_STOP:
1178 return 0;
1179 default:
1180 return -EINVAL;
1181 }
1182}
1183
1184static const struct v4l2_ioctl_ops hdpvr_ioctl_ops = {
1185 .vidioc_querycap = vidioc_querycap,
1186 .vidioc_s_std = vidioc_s_std,
1187 .vidioc_enum_input = vidioc_enum_input,
1188 .vidioc_g_input = vidioc_g_input,
1189 .vidioc_s_input = vidioc_s_input,
1190 .vidioc_enumaudio = vidioc_enumaudio,
1191 .vidioc_g_audio = vidioc_g_audio,
1192 .vidioc_s_audio = vidioc_s_audio,
1193 .vidioc_queryctrl = vidioc_queryctrl,
1194 .vidioc_g_ctrl = vidioc_g_ctrl,
1195 .vidioc_s_ctrl = vidioc_s_ctrl,
1196 .vidioc_g_ext_ctrls = vidioc_g_ext_ctrls,
1197 .vidioc_s_ext_ctrls = vidioc_s_ext_ctrls,
1198 .vidioc_try_ext_ctrls = vidioc_try_ext_ctrls,
1199 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
1200 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
1201 .vidioc_encoder_cmd = vidioc_encoder_cmd,
1202 .vidioc_try_encoder_cmd = vidioc_try_encoder_cmd,
1203};
1204
1205static void hdpvr_device_release(struct video_device *vdev)
1206{
1207 struct hdpvr_device *dev = video_get_drvdata(vdev);
1208
1209 hdpvr_delete(dev);
1210}
1211
1212static const struct video_device hdpvr_video_template = {
1213/* .type = VFL_TYPE_GRABBER, */
1214/* .type2 = VID_TYPE_CAPTURE | VID_TYPE_MPEG_ENCODER, */
1215 .fops = &hdpvr_fops,
1216 .release = hdpvr_device_release,
1217 .ioctl_ops = &hdpvr_ioctl_ops,
1218 .tvnorms =
1219 V4L2_STD_NTSC | V4L2_STD_SECAM | V4L2_STD_PAL_B |
1220 V4L2_STD_PAL_G | V4L2_STD_PAL_H | V4L2_STD_PAL_I |
1221 V4L2_STD_PAL_D | V4L2_STD_PAL_M | V4L2_STD_PAL_N |
1222 V4L2_STD_PAL_60,
1223};
1224
1225int hdpvr_register_videodev(struct hdpvr_device *dev, struct device *parent,
1226 int devnum)
1227{
1228 /* setup and register video device */
1229 dev->video_dev = video_device_alloc();
1230 if (!dev->video_dev) {
1231 v4l2_err(&dev->v4l2_dev, "video_device_alloc() failed\n");
1232 goto error;
1233 }
1234
1235 *(dev->video_dev) = hdpvr_video_template;
1236 strcpy(dev->video_dev->name, "Hauppauge HD PVR");
1237 dev->video_dev->parent = parent;
1238 video_set_drvdata(dev->video_dev, dev);
1239
1240 if (video_register_device(dev->video_dev, VFL_TYPE_GRABBER, devnum)) {
1241 v4l2_err(&dev->v4l2_dev, "video_device registration failed\n");
1242 goto error;
1243 }
1244
1245 return 0;
1246error:
1247 return -ENOMEM;
1248}
diff --git a/drivers/media/video/hdpvr/hdpvr.h b/drivers/media/video/hdpvr/hdpvr.h
new file mode 100644
index 000000000000..1edd8759121e
--- /dev/null
+++ b/drivers/media/video/hdpvr/hdpvr.h
@@ -0,0 +1,303 @@
1/*
2 * Hauppauge HD PVR USB driver
3 *
4 * Copyright (C) 2008 Janne Grunau (j@jannau.net)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, version 2.
9 *
10 */
11
12#include <linux/usb.h>
13#include <linux/i2c.h>
14#include <linux/mutex.h>
15#include <linux/workqueue.h>
16#include <linux/videodev2.h>
17
18#include <media/v4l2-device.h>
19
20#define HDPVR_MAJOR_VERSION 0
21#define HDPVR_MINOR_VERSION 2
22#define HDPVR_RELEASE 0
23#define HDPVR_VERSION \
24 KERNEL_VERSION(HDPVR_MAJOR_VERSION, HDPVR_MINOR_VERSION, HDPVR_RELEASE)
25
26#define HDPVR_MAX 8
27
28/* Define these values to match your devices */
29#define HD_PVR_VENDOR_ID 0x2040
30#define HD_PVR_PRODUCT_ID 0x4900
31#define HD_PVR_PRODUCT_ID1 0x4901
32#define HD_PVR_PRODUCT_ID2 0x4902
33
34#define UNSET (-1U)
35
36#define NUM_BUFFERS 64
37
38#define HDPVR_FIRMWARE_VERSION 0x8
39#define HDPVR_FIRMWARE_VERSION_AC3 0xd
40
41/* #define HDPVR_DEBUG */
42
43extern int hdpvr_debug;
44
45#define MSG_INFO 1
46#define MSG_BUFFER 2
47
48struct hdpvr_options {
49 u8 video_std;
50 u8 video_input;
51 u8 audio_input;
52 u8 bitrate; /* in 100kbps */
53 u8 peak_bitrate; /* in 100kbps */
54 u8 bitrate_mode;
55 u8 gop_mode;
56 enum v4l2_mpeg_audio_encoding audio_codec;
57 u8 brightness;
58 u8 contrast;
59 u8 hue;
60 u8 saturation;
61 u8 sharpness;
62};
63
64/* Structure to hold all of our device specific stuff */
65struct hdpvr_device {
66 /* the v4l device for this device */
67 struct video_device *video_dev;
68 /* the usb device for this device */
69 struct usb_device *udev;
70 /* v4l2-device unused */
71 struct v4l2_device v4l2_dev;
72
73 /* the max packet size of the bulk endpoint */
74 size_t bulk_in_size;
75 /* the address of the bulk in endpoint */
76 __u8 bulk_in_endpointAddr;
77
78 /* holds the current device status */
79 __u8 status;
80 /* count the number of openers */
81 uint open_count;
82
83 /* holds the cureent set options */
84 struct hdpvr_options options;
85
86 uint flags;
87
88 /* synchronize I/O */
89 struct mutex io_mutex;
90 /* available buffers */
91 struct list_head free_buff_list;
92 /* in progress buffers */
93 struct list_head rec_buff_list;
94 /* waitqueue for buffers */
95 wait_queue_head_t wait_buffer;
96 /* waitqueue for data */
97 wait_queue_head_t wait_data;
98 /**/
99 struct workqueue_struct *workqueue;
100 /**/
101 struct work_struct worker;
102
103 /* I2C adapter */
104 struct i2c_adapter *i2c_adapter;
105 /* I2C lock */
106 struct mutex i2c_mutex;
107
108 /* usb control transfer buffer and lock */
109 struct mutex usbc_mutex;
110 u8 *usbc_buf;
111};
112
113
114/* buffer one bulk urb of data */
115struct hdpvr_buffer {
116 struct list_head buff_list;
117
118 struct urb *urb;
119
120 struct hdpvr_device *dev;
121
122 uint pos;
123
124 __u8 status;
125};
126
127/* */
128
129struct hdpvr_video_info {
130 u16 width;
131 u16 height;
132 u8 fps;
133};
134
135enum {
136 STATUS_UNINITIALIZED = 0,
137 STATUS_IDLE,
138 STATUS_STARTING,
139 STATUS_SHUTTING_DOWN,
140 STATUS_STREAMING,
141 STATUS_ERROR,
142 STATUS_DISCONNECTED,
143};
144
145enum {
146 HDPVR_FLAG_AC3_CAP = 1,
147};
148
149enum {
150 BUFSTAT_UNINITIALIZED = 0,
151 BUFSTAT_AVAILABLE,
152 BUFSTAT_INPROGRESS,
153 BUFSTAT_READY,
154};
155
156#define CTRL_START_STREAMING_VALUE 0x0700
157#define CTRL_STOP_STREAMING_VALUE 0x0800
158#define CTRL_BITRATE_VALUE 0x1000
159#define CTRL_BITRATE_MODE_VALUE 0x1200
160#define CTRL_GOP_MODE_VALUE 0x1300
161#define CTRL_VIDEO_INPUT_VALUE 0x1500
162#define CTRL_VIDEO_STD_TYPE 0x1700
163#define CTRL_AUDIO_INPUT_VALUE 0x2500
164#define CTRL_BRIGHTNESS 0x2900
165#define CTRL_CONTRAST 0x2a00
166#define CTRL_HUE 0x2b00
167#define CTRL_SATURATION 0x2c00
168#define CTRL_SHARPNESS 0x2d00
169#define CTRL_LOW_PASS_FILTER_VALUE 0x3100
170
171#define CTRL_DEFAULT_INDEX 0x0003
172
173
174 /* :0 s 38 01 1000 0003 0004 4 = 0a00ca00
175 * BITRATE SETTING
176 * 1st and 2nd byte (little endian): average bitrate in 100 000 bit/s
177 * min: 1 mbit/s, max: 13.5 mbit/s
178 * 3rd and 4th byte (little endian): peak bitrate in 100 000 bit/s
179 * min: average + 100kbit/s,
180 * max: 20.2 mbit/s
181 */
182
183 /* :0 s 38 01 1200 0003 0001 1 = 02
184 * BIT RATE MODE
185 * constant = 1, variable (peak) = 2, variable (average) = 3
186 */
187
188 /* :0 s 38 01 1300 0003 0001 1 = 03
189 * GOP MODE (2 bit)
190 * low bit 0/1: advanced/simple GOP
191 * high bit 0/1: IDR(4/32/128) / no IDR (4/32/0)
192 */
193
194 /* :0 s 38 01 1700 0003 0001 1 = 00
195 * VIDEO STANDARD or FREQUNCY 0 = 60hz, 1 = 50hz
196 */
197
198 /* :0 s 38 01 3100 0003 0004 4 = 03030000
199 * FILTER CONTROL
200 * 1st byte luma low pass filter strength,
201 * 2nd byte chroma low pass filter strength,
202 * 3rd byte MF enable chroma, min=0, max=1
203 * 4th byte n
204 */
205
206
207 /* :0 s 38 b9 0001 0000 0000 0 */
208
209
210
211/* :0 s 38 d3 0000 0000 0001 1 = 00 */
212/* ret = usb_control_msg(dev->udev, */
213/* usb_sndctrlpipe(dev->udev, 0), */
214/* 0xd3, 0x38, */
215/* 0, 0, */
216/* "\0", 1, */
217/* 1000); */
218
219/* info("control request returned %d", ret); */
220/* msleep(5000); */
221
222
223 /* :0 s b8 81 1400 0003 0005 5 <
224 * :0 0 5 = d0024002 19
225 * QUERY FRAME SIZE AND RATE
226 * 1st and 2nd byte (little endian): horizontal resolution
227 * 3rd and 4th byte (little endian): vertical resolution
228 * 5th byte: frame rate
229 */
230
231 /* :0 s b8 81 1800 0003 0003 3 <
232 * :0 0 3 = 030104
233 * QUERY SIGNAL AND DETECTED LINES, maybe INPUT
234 */
235
236enum hdpvr_video_std {
237 HDPVR_60HZ = 0,
238 HDPVR_50HZ,
239};
240
241enum hdpvr_video_input {
242 HDPVR_COMPONENT = 0,
243 HDPVR_SVIDEO,
244 HDPVR_COMPOSITE,
245 HDPVR_VIDEO_INPUTS
246};
247
248enum hdpvr_audio_inputs {
249 HDPVR_RCA_BACK = 0,
250 HDPVR_RCA_FRONT,
251 HDPVR_SPDIF,
252 HDPVR_AUDIO_INPUTS
253};
254
255enum hdpvr_bitrate_mode {
256 HDPVR_CONSTANT = 1,
257 HDPVR_VARIABLE_PEAK,
258 HDPVR_VARIABLE_AVERAGE,
259};
260
261enum hdpvr_gop_mode {
262 HDPVR_ADVANCED_IDR_GOP = 0,
263 HDPVR_SIMPLE_IDR_GOP,
264 HDPVR_ADVANCED_NOIDR_GOP,
265 HDPVR_SIMPLE_NOIDR_GOP,
266};
267
268void hdpvr_delete(struct hdpvr_device *dev);
269
270/*========================================================================*/
271/* hardware control functions */
272int hdpvr_set_options(struct hdpvr_device *dev);
273
274int hdpvr_set_bitrate(struct hdpvr_device *dev);
275
276int hdpvr_set_audio(struct hdpvr_device *dev, u8 input,
277 enum v4l2_mpeg_audio_encoding codec);
278
279int hdpvr_config_call(struct hdpvr_device *dev, uint value,
280 unsigned char valbuf);
281
282struct hdpvr_video_info *get_video_info(struct hdpvr_device *dev);
283
284/* :0 s b8 81 1800 0003 0003 3 < */
285/* :0 0 3 = 0301ff */
286int get_input_lines_info(struct hdpvr_device *dev);
287
288
289/*========================================================================*/
290/* v4l2 registration */
291int hdpvr_register_videodev(struct hdpvr_device *dev, struct device *parent,
292 int devnumber);
293
294int hdpvr_cancel_queue(struct hdpvr_device *dev);
295
296/*========================================================================*/
297/* i2c adapter registration */
298int hdpvr_register_i2c_adapter(struct hdpvr_device *dev);
299
300/*========================================================================*/
301/* buffer management */
302int hdpvr_free_buffers(struct hdpvr_device *dev);
303int hdpvr_alloc_buffers(struct hdpvr_device *dev, uint count);
diff --git a/drivers/media/video/hexium_gemini.c b/drivers/media/video/hexium_gemini.c
index 79393d1772e4..8e1463ee1b64 100644
--- a/drivers/media/video/hexium_gemini.c
+++ b/drivers/media/video/hexium_gemini.c
@@ -56,17 +56,6 @@ struct hexium_data
56 u8 byte; 56 u8 byte;
57}; 57};
58 58
59static struct saa7146_extension_ioctls ioctls[] = {
60 { VIDIOC_G_INPUT, SAA7146_EXCLUSIVE },
61 { VIDIOC_S_INPUT, SAA7146_EXCLUSIVE },
62 { VIDIOC_QUERYCTRL, SAA7146_BEFORE },
63 { VIDIOC_ENUMINPUT, SAA7146_EXCLUSIVE },
64 { VIDIOC_S_STD, SAA7146_AFTER },
65 { VIDIOC_G_CTRL, SAA7146_BEFORE },
66 { VIDIOC_S_CTRL, SAA7146_BEFORE },
67 { 0, 0 }
68};
69
70#define HEXIUM_CONTROLS 1 59#define HEXIUM_CONTROLS 1
71static struct v4l2_queryctrl hexium_controls[] = { 60static struct v4l2_queryctrl hexium_controls[] = {
72 { V4L2_CID_PRIVATE_BASE, V4L2_CTRL_TYPE_BOOLEAN, "B/W", 0, 1, 1, 0, 0 }, 61 { V4L2_CID_PRIVATE_BASE, V4L2_CTRL_TYPE_BOOLEAN, "B/W", 0, 1, 1, 0, 0 },
@@ -231,6 +220,132 @@ static int hexium_set_standard(struct hexium *hexium, struct hexium_data *vdec)
231 return 0; 220 return 0;
232} 221}
233 222
223static int vidioc_enum_input(struct file *file, void *fh, struct v4l2_input *i)
224{
225 DEB_EE(("VIDIOC_ENUMINPUT %d.\n", i->index));
226
227 if (i->index < 0 || i->index >= HEXIUM_INPUTS)
228 return -EINVAL;
229
230 memcpy(i, &hexium_inputs[i->index], sizeof(struct v4l2_input));
231
232 DEB_D(("v4l2_ioctl: VIDIOC_ENUMINPUT %d.\n", i->index));
233 return 0;
234}
235
236static int vidioc_g_input(struct file *file, void *fh, unsigned int *input)
237{
238 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
239 struct hexium *hexium = (struct hexium *) dev->ext_priv;
240
241 *input = hexium->cur_input;
242
243 DEB_D(("VIDIOC_G_INPUT: %d\n", *input));
244 return 0;
245}
246
247static int vidioc_s_input(struct file *file, void *fh, unsigned int input)
248{
249 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
250 struct hexium *hexium = (struct hexium *) dev->ext_priv;
251
252 DEB_EE(("VIDIOC_S_INPUT %d.\n", input));
253
254 if (input < 0 || input >= HEXIUM_INPUTS)
255 return -EINVAL;
256
257 hexium->cur_input = input;
258 hexium_set_input(hexium, input);
259 return 0;
260}
261
262/* the saa7146 provides some controls (brightness, contrast, saturation)
263 which gets registered *after* this function. because of this we have
264 to return with a value != 0 even if the function succeded.. */
265static int vidioc_queryctrl(struct file *file, void *fh, struct v4l2_queryctrl *qc)
266{
267 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
268 int i;
269
270 for (i = HEXIUM_CONTROLS - 1; i >= 0; i--) {
271 if (hexium_controls[i].id == qc->id) {
272 *qc = hexium_controls[i];
273 DEB_D(("VIDIOC_QUERYCTRL %d.\n", qc->id));
274 return 0;
275 }
276 }
277 return dev->ext_vv_data->core_ops->vidioc_queryctrl(file, fh, qc);
278}
279
280static int vidioc_g_ctrl(struct file *file, void *fh, struct v4l2_control *vc)
281{
282 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
283 struct hexium *hexium = (struct hexium *) dev->ext_priv;
284 int i;
285
286 for (i = HEXIUM_CONTROLS - 1; i >= 0; i--) {
287 if (hexium_controls[i].id == vc->id)
288 break;
289 }
290
291 if (i < 0)
292 return dev->ext_vv_data->core_ops->vidioc_g_ctrl(file, fh, vc);
293
294 if (vc->id == V4L2_CID_PRIVATE_BASE) {
295 vc->value = hexium->cur_bw;
296 DEB_D(("VIDIOC_G_CTRL BW:%d.\n", vc->value));
297 return 0;
298 }
299 return -EINVAL;
300}
301
302static int vidioc_s_ctrl(struct file *file, void *fh, struct v4l2_control *vc)
303{
304 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
305 struct hexium *hexium = (struct hexium *) dev->ext_priv;
306 int i = 0;
307
308 for (i = HEXIUM_CONTROLS - 1; i >= 0; i--) {
309 if (hexium_controls[i].id == vc->id)
310 break;
311 }
312
313 if (i < 0)
314 return dev->ext_vv_data->core_ops->vidioc_s_ctrl(file, fh, vc);
315
316 if (vc->id == V4L2_CID_PRIVATE_BASE)
317 hexium->cur_bw = vc->value;
318
319 DEB_D(("VIDIOC_S_CTRL BW:%d.\n", hexium->cur_bw));
320
321 if (0 == hexium->cur_bw && V4L2_STD_PAL == hexium->cur_std) {
322 hexium_set_standard(hexium, hexium_pal);
323 return 0;
324 }
325 if (0 == hexium->cur_bw && V4L2_STD_NTSC == hexium->cur_std) {
326 hexium_set_standard(hexium, hexium_ntsc);
327 return 0;
328 }
329 if (0 == hexium->cur_bw && V4L2_STD_SECAM == hexium->cur_std) {
330 hexium_set_standard(hexium, hexium_secam);
331 return 0;
332 }
333 if (1 == hexium->cur_bw && V4L2_STD_PAL == hexium->cur_std) {
334 hexium_set_standard(hexium, hexium_pal_bw);
335 return 0;
336 }
337 if (1 == hexium->cur_bw && V4L2_STD_NTSC == hexium->cur_std) {
338 hexium_set_standard(hexium, hexium_ntsc_bw);
339 return 0;
340 }
341 if (1 == hexium->cur_bw && V4L2_STD_SECAM == hexium->cur_std)
342 /* fixme: is there no bw secam mode? */
343 return -EINVAL;
344
345 return -EINVAL;
346}
347
348
234static struct saa7146_ext_vv vv_data; 349static struct saa7146_ext_vv vv_data;
235 350
236/* this function only gets called when the probing was successful */ 351/* this function only gets called when the probing was successful */
@@ -279,6 +394,12 @@ static int hexium_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_d
279 hexium->cur_input = 0; 394 hexium->cur_input = 0;
280 395
281 saa7146_vv_init(dev, &vv_data); 396 saa7146_vv_init(dev, &vv_data);
397 vv_data.ops.vidioc_queryctrl = vidioc_queryctrl;
398 vv_data.ops.vidioc_g_ctrl = vidioc_g_ctrl;
399 vv_data.ops.vidioc_s_ctrl = vidioc_s_ctrl;
400 vv_data.ops.vidioc_enum_input = vidioc_enum_input;
401 vv_data.ops.vidioc_g_input = vidioc_g_input;
402 vv_data.ops.vidioc_s_input = vidioc_s_input;
282 if (0 != saa7146_register_device(&hexium->video_dev, dev, "hexium gemini", VFL_TYPE_GRABBER)) { 403 if (0 != saa7146_register_device(&hexium->video_dev, dev, "hexium gemini", VFL_TYPE_GRABBER)) {
283 printk("hexium_gemini: cannot register capture v4l2 device. skipping.\n"); 404 printk("hexium_gemini: cannot register capture v4l2 device. skipping.\n");
284 return -1; 405 return -1;
@@ -306,153 +427,6 @@ static int hexium_detach(struct saa7146_dev *dev)
306 return 0; 427 return 0;
307} 428}
308 429
309static long hexium_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
310{
311 struct saa7146_dev *dev = fh->dev;
312 struct hexium *hexium = (struct hexium *) dev->ext_priv;
313/*
314 struct saa7146_vv *vv = dev->vv_data;
315*/
316 switch (cmd) {
317 case VIDIOC_ENUMINPUT:
318 {
319 struct v4l2_input *i = arg;
320 DEB_EE(("VIDIOC_ENUMINPUT %d.\n", i->index));
321
322 if (i->index < 0 || i->index >= HEXIUM_INPUTS) {
323 return -EINVAL;
324 }
325
326 memcpy(i, &hexium_inputs[i->index], sizeof(struct v4l2_input));
327
328 DEB_D(("v4l2_ioctl: VIDIOC_ENUMINPUT %d.\n", i->index));
329 return 0;
330 }
331 case VIDIOC_G_INPUT:
332 {
333 int *input = (int *) arg;
334 *input = hexium->cur_input;
335
336 DEB_D(("VIDIOC_G_INPUT: %d\n", *input));
337 return 0;
338 }
339 case VIDIOC_S_INPUT:
340 {
341 int input = *(int *) arg;
342
343 DEB_EE(("VIDIOC_S_INPUT %d.\n", input));
344
345 if (input < 0 || input >= HEXIUM_INPUTS) {
346 return -EINVAL;
347 }
348
349 hexium->cur_input = input;
350 hexium_set_input(hexium, input);
351
352 return 0;
353 }
354 /* the saa7146 provides some controls (brightness, contrast, saturation)
355 which gets registered *after* this function. because of this we have
356 to return with a value != 0 even if the function succeded.. */
357 case VIDIOC_QUERYCTRL:
358 {
359 struct v4l2_queryctrl *qc = arg;
360 int i;
361
362 for (i = HEXIUM_CONTROLS - 1; i >= 0; i--) {
363 if (hexium_controls[i].id == qc->id) {
364 *qc = hexium_controls[i];
365 DEB_D(("VIDIOC_QUERYCTRL %d.\n", qc->id));
366 return 0;
367 }
368 }
369 return -EAGAIN;
370 }
371 case VIDIOC_G_CTRL:
372 {
373 struct v4l2_control *vc = arg;
374 int i;
375
376 for (i = HEXIUM_CONTROLS - 1; i >= 0; i--) {
377 if (hexium_controls[i].id == vc->id) {
378 break;
379 }
380 }
381
382 if (i < 0) {
383 return -EAGAIN;
384 }
385
386 switch (vc->id) {
387 case V4L2_CID_PRIVATE_BASE:{
388 vc->value = hexium->cur_bw;
389 DEB_D(("VIDIOC_G_CTRL BW:%d.\n", vc->value));
390 return 0;
391 }
392 }
393 return -EINVAL;
394 }
395
396 case VIDIOC_S_CTRL:
397 {
398 struct v4l2_control *vc = arg;
399 int i = 0;
400
401 for (i = HEXIUM_CONTROLS - 1; i >= 0; i--) {
402 if (hexium_controls[i].id == vc->id) {
403 break;
404 }
405 }
406
407 if (i < 0) {
408 return -EAGAIN;
409 }
410
411 switch (vc->id) {
412 case V4L2_CID_PRIVATE_BASE:{
413 hexium->cur_bw = vc->value;
414 break;
415 }
416 }
417
418 DEB_D(("VIDIOC_S_CTRL BW:%d.\n", hexium->cur_bw));
419
420 if (0 == hexium->cur_bw && V4L2_STD_PAL == hexium->cur_std) {
421 hexium_set_standard(hexium, hexium_pal);
422 return 0;
423 }
424 if (0 == hexium->cur_bw && V4L2_STD_NTSC == hexium->cur_std) {
425 hexium_set_standard(hexium, hexium_ntsc);
426 return 0;
427 }
428 if (0 == hexium->cur_bw && V4L2_STD_SECAM == hexium->cur_std) {
429 hexium_set_standard(hexium, hexium_secam);
430 return 0;
431 }
432 if (1 == hexium->cur_bw && V4L2_STD_PAL == hexium->cur_std) {
433 hexium_set_standard(hexium, hexium_pal_bw);
434 return 0;
435 }
436 if (1 == hexium->cur_bw && V4L2_STD_NTSC == hexium->cur_std) {
437 hexium_set_standard(hexium, hexium_ntsc_bw);
438 return 0;
439 }
440 if (1 == hexium->cur_bw && V4L2_STD_SECAM == hexium->cur_std) {
441 /* fixme: is there no bw secam mode? */
442 return -EINVAL;
443 }
444
445 return -EINVAL;
446 }
447 default:
448/*
449 DEB_D(("hexium_ioctl() does not handle this ioctl.\n"));
450*/
451 return -ENOIOCTLCMD;
452 }
453 return 0;
454}
455
456static int std_callback(struct saa7146_dev *dev, struct saa7146_standard *std) 430static int std_callback(struct saa7146_dev *dev, struct saa7146_standard *std)
457{ 431{
458 struct hexium *hexium = (struct hexium *) dev->ext_priv; 432 struct hexium *hexium = (struct hexium *) dev->ext_priv;
@@ -514,8 +488,6 @@ static struct saa7146_ext_vv vv_data = {
514 .stds = &hexium_standards[0], 488 .stds = &hexium_standards[0],
515 .num_stds = sizeof(hexium_standards) / sizeof(struct saa7146_standard), 489 .num_stds = sizeof(hexium_standards) / sizeof(struct saa7146_standard),
516 .std_callback = &std_callback, 490 .std_callback = &std_callback,
517 .ioctls = &ioctls[0],
518 .ioctl = hexium_ioctl,
519}; 491};
520 492
521static struct saa7146_extension hexium_extension = { 493static struct saa7146_extension hexium_extension = {
diff --git a/drivers/media/video/hexium_orion.c b/drivers/media/video/hexium_orion.c
index 074bec711fe0..2bc39f628455 100644
--- a/drivers/media/video/hexium_orion.c
+++ b/drivers/media/video/hexium_orion.c
@@ -57,14 +57,6 @@ struct hexium_data
57 u8 byte; 57 u8 byte;
58}; 58};
59 59
60static struct saa7146_extension_ioctls ioctls[] = {
61 { VIDIOC_G_INPUT, SAA7146_EXCLUSIVE },
62 { VIDIOC_S_INPUT, SAA7146_EXCLUSIVE },
63 { VIDIOC_ENUMINPUT, SAA7146_EXCLUSIVE },
64 { VIDIOC_S_STD, SAA7146_AFTER },
65 { 0, 0 }
66};
67
68struct hexium 60struct hexium
69{ 61{
70 int type; 62 int type;
@@ -329,6 +321,44 @@ static int hexium_set_input(struct hexium *hexium, int input)
329 return 0; 321 return 0;
330} 322}
331 323
324static int vidioc_enum_input(struct file *file, void *fh, struct v4l2_input *i)
325{
326 DEB_EE(("VIDIOC_ENUMINPUT %d.\n", i->index));
327
328 if (i->index < 0 || i->index >= HEXIUM_INPUTS)
329 return -EINVAL;
330
331 memcpy(i, &hexium_inputs[i->index], sizeof(struct v4l2_input));
332
333 DEB_D(("v4l2_ioctl: VIDIOC_ENUMINPUT %d.\n", i->index));
334 return 0;
335}
336
337static int vidioc_g_input(struct file *file, void *fh, unsigned int *input)
338{
339 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
340 struct hexium *hexium = (struct hexium *) dev->ext_priv;
341
342 *input = hexium->cur_input;
343
344 DEB_D(("VIDIOC_G_INPUT: %d\n", *input));
345 return 0;
346}
347
348static int vidioc_s_input(struct file *file, void *fh, unsigned int input)
349{
350 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
351 struct hexium *hexium = (struct hexium *) dev->ext_priv;
352
353 if (input < 0 || input >= HEXIUM_INPUTS)
354 return -EINVAL;
355
356 hexium->cur_input = input;
357 hexium_set_input(hexium, input);
358
359 return 0;
360}
361
332static struct saa7146_ext_vv vv_data; 362static struct saa7146_ext_vv vv_data;
333 363
334/* this function only gets called when the probing was successful */ 364/* this function only gets called when the probing was successful */
@@ -339,6 +369,9 @@ static int hexium_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_d
339 DEB_EE((".\n")); 369 DEB_EE((".\n"));
340 370
341 saa7146_vv_init(dev, &vv_data); 371 saa7146_vv_init(dev, &vv_data);
372 vv_data.ops.vidioc_enum_input = vidioc_enum_input;
373 vv_data.ops.vidioc_g_input = vidioc_g_input;
374 vv_data.ops.vidioc_s_input = vidioc_s_input;
342 if (0 != saa7146_register_device(&hexium->video_dev, dev, "hexium orion", VFL_TYPE_GRABBER)) { 375 if (0 != saa7146_register_device(&hexium->video_dev, dev, "hexium orion", VFL_TYPE_GRABBER)) {
343 printk("hexium_orion: cannot register capture v4l2 device. skipping.\n"); 376 printk("hexium_orion: cannot register capture v4l2 device. skipping.\n");
344 return -1; 377 return -1;
@@ -370,58 +403,6 @@ static int hexium_detach(struct saa7146_dev *dev)
370 return 0; 403 return 0;
371} 404}
372 405
373static long hexium_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
374{
375 struct saa7146_dev *dev = fh->dev;
376 struct hexium *hexium = (struct hexium *) dev->ext_priv;
377/*
378 struct saa7146_vv *vv = dev->vv_data;
379*/
380 switch (cmd) {
381 case VIDIOC_ENUMINPUT:
382 {
383 struct v4l2_input *i = arg;
384 DEB_EE(("VIDIOC_ENUMINPUT %d.\n", i->index));
385
386 if (i->index < 0 || i->index >= HEXIUM_INPUTS) {
387 return -EINVAL;
388 }
389
390 memcpy(i, &hexium_inputs[i->index], sizeof(struct v4l2_input));
391
392 DEB_D(("v4l2_ioctl: VIDIOC_ENUMINPUT %d.\n", i->index));
393 return 0;
394 }
395 case VIDIOC_G_INPUT:
396 {
397 int *input = (int *) arg;
398 *input = hexium->cur_input;
399
400 DEB_D(("VIDIOC_G_INPUT: %d\n", *input));
401 return 0;
402 }
403 case VIDIOC_S_INPUT:
404 {
405 int input = *(int *) arg;
406
407 if (input < 0 || input >= HEXIUM_INPUTS) {
408 return -EINVAL;
409 }
410
411 hexium->cur_input = input;
412 hexium_set_input(hexium, input);
413
414 return 0;
415 }
416 default:
417/*
418 DEB_D(("hexium_ioctl() does not handle this ioctl.\n"));
419*/
420 return -ENOIOCTLCMD;
421 }
422 return 0;
423}
424
425static int std_callback(struct saa7146_dev *dev, struct saa7146_standard *std) 406static int std_callback(struct saa7146_dev *dev, struct saa7146_standard *std)
426{ 407{
427 return 0; 408 return 0;
@@ -479,8 +460,6 @@ static struct saa7146_ext_vv vv_data = {
479 .stds = &hexium_standards[0], 460 .stds = &hexium_standards[0],
480 .num_stds = sizeof(hexium_standards) / sizeof(struct saa7146_standard), 461 .num_stds = sizeof(hexium_standards) / sizeof(struct saa7146_standard),
481 .std_callback = &std_callback, 462 .std_callback = &std_callback,
482 .ioctls = &ioctls[0],
483 .ioctl = hexium_ioctl,
484}; 463};
485 464
486static struct saa7146_extension extension = { 465static struct saa7146_extension extension = {
diff --git a/drivers/media/video/indycam.c b/drivers/media/video/indycam.c
index 84b9e4f2b3b3..3d6940163b12 100644
--- a/drivers/media/video/indycam.c
+++ b/drivers/media/video/indycam.c
@@ -19,10 +19,12 @@
19#include <linux/mm.h> 19#include <linux/mm.h>
20#include <linux/slab.h> 20#include <linux/slab.h>
21 21
22#include <linux/videodev.h>
23/* IndyCam decodes stream of photons into digital image representation ;-) */ 22/* IndyCam decodes stream of photons into digital image representation ;-) */
24#include <linux/video_decoder.h> 23#include <linux/videodev2.h>
25#include <linux/i2c.h> 24#include <linux/i2c.h>
25#include <media/v4l2-device.h>
26#include <media/v4l2-chip-ident.h>
27#include <media/v4l2-i2c-drv.h>
26 28
27#include "indycam.h" 29#include "indycam.h"
28 30
@@ -33,6 +35,7 @@ MODULE_VERSION(INDYCAM_MODULE_VERSION);
33MODULE_AUTHOR("Mikael Nousiainen <tmnousia@cc.hut.fi>"); 35MODULE_AUTHOR("Mikael Nousiainen <tmnousia@cc.hut.fi>");
34MODULE_LICENSE("GPL"); 36MODULE_LICENSE("GPL");
35 37
38
36// #define INDYCAM_DEBUG 39// #define INDYCAM_DEBUG
37 40
38#ifdef INDYCAM_DEBUG 41#ifdef INDYCAM_DEBUG
@@ -44,11 +47,14 @@ MODULE_LICENSE("GPL");
44#endif 47#endif
45 48
46struct indycam { 49struct indycam {
47 struct i2c_client *client; 50 struct v4l2_subdev sd;
48 u8 version; 51 u8 version;
49}; 52};
50 53
51static struct i2c_driver i2c_driver_indycam; 54static inline struct indycam *to_indycam(struct v4l2_subdev *sd)
55{
56 return container_of(sd, struct indycam, sd);
57}
52 58
53static const u8 initseq[] = { 59static const u8 initseq[] = {
54 INDYCAM_CONTROL_AGCENA, /* INDYCAM_CONTROL */ 60 INDYCAM_CONTROL_AGCENA, /* INDYCAM_CONTROL */
@@ -63,8 +69,9 @@ static const u8 initseq[] = {
63 69
64/* IndyCam register handling */ 70/* IndyCam register handling */
65 71
66static int indycam_read_reg(struct i2c_client *client, u8 reg, u8 *value) 72static int indycam_read_reg(struct v4l2_subdev *sd, u8 reg, u8 *value)
67{ 73{
74 struct i2c_client *client = v4l2_get_subdevdata(sd);
68 int ret; 75 int ret;
69 76
70 if (reg == INDYCAM_REG_RESET) { 77 if (reg == INDYCAM_REG_RESET) {
@@ -87,12 +94,12 @@ static int indycam_read_reg(struct i2c_client *client, u8 reg, u8 *value)
87 return 0; 94 return 0;
88} 95}
89 96
90static int indycam_write_reg(struct i2c_client *client, u8 reg, u8 value) 97static int indycam_write_reg(struct v4l2_subdev *sd, u8 reg, u8 value)
91{ 98{
99 struct i2c_client *client = v4l2_get_subdevdata(sd);
92 int err; 100 int err;
93 101
94 if ((reg == INDYCAM_REG_BRIGHTNESS) 102 if (reg == INDYCAM_REG_BRIGHTNESS || reg == INDYCAM_REG_VERSION) {
95 || (reg == INDYCAM_REG_VERSION)) {
96 dprintk("indycam_write_reg(): " 103 dprintk("indycam_write_reg(): "
97 "skipping read-only register %d\n", reg); 104 "skipping read-only register %d\n", reg);
98 return 0; 105 return 0;
@@ -108,13 +115,13 @@ static int indycam_write_reg(struct i2c_client *client, u8 reg, u8 value)
108 return err; 115 return err;
109} 116}
110 117
111static int indycam_write_block(struct i2c_client *client, u8 reg, 118static int indycam_write_block(struct v4l2_subdev *sd, u8 reg,
112 u8 length, u8 *data) 119 u8 length, u8 *data)
113{ 120{
114 int i, err; 121 int i, err;
115 122
116 for (i = 0; i < length; i++) { 123 for (i = 0; i < length; i++) {
117 err = indycam_write_reg(client, reg + i, data[i]); 124 err = indycam_write_reg(sd, reg + i, data[i]);
118 if (err) 125 if (err)
119 return err; 126 return err;
120 } 127 }
@@ -125,79 +132,78 @@ static int indycam_write_block(struct i2c_client *client, u8 reg,
125/* Helper functions */ 132/* Helper functions */
126 133
127#ifdef INDYCAM_DEBUG 134#ifdef INDYCAM_DEBUG
128static void indycam_regdump_debug(struct i2c_client *client) 135static void indycam_regdump_debug(struct v4l2_subdev *sd)
129{ 136{
130 int i; 137 int i;
131 u8 val; 138 u8 val;
132 139
133 for (i = 0; i < 9; i++) { 140 for (i = 0; i < 9; i++) {
134 indycam_read_reg(client, i, &val); 141 indycam_read_reg(sd, i, &val);
135 dprintk("Reg %d = 0x%02x\n", i, val); 142 dprintk("Reg %d = 0x%02x\n", i, val);
136 } 143 }
137} 144}
138#endif 145#endif
139 146
140static int indycam_get_control(struct i2c_client *client, 147static int indycam_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
141 struct indycam_control *ctrl)
142{ 148{
143 struct indycam *camera = i2c_get_clientdata(client); 149 struct indycam *camera = to_indycam(sd);
144 u8 reg; 150 u8 reg;
145 int ret = 0; 151 int ret = 0;
146 152
147 switch (ctrl->type) { 153 switch (ctrl->id) {
148 case INDYCAM_CONTROL_AGC: 154 case V4L2_CID_AUTOGAIN:
149 case INDYCAM_CONTROL_AWB: 155 case V4L2_CID_AUTO_WHITE_BALANCE:
150 ret = indycam_read_reg(client, INDYCAM_REG_CONTROL, &reg); 156 ret = indycam_read_reg(sd, INDYCAM_REG_CONTROL, &reg);
151 if (ret) 157 if (ret)
152 return -EIO; 158 return -EIO;
153 if (ctrl->type == INDYCAM_CONTROL_AGC) 159 if (ctrl->id == V4L2_CID_AUTOGAIN)
154 ctrl->value = (reg & INDYCAM_CONTROL_AGCENA) 160 ctrl->value = (reg & INDYCAM_CONTROL_AGCENA)
155 ? 1 : 0; 161 ? 1 : 0;
156 else 162 else
157 ctrl->value = (reg & INDYCAM_CONTROL_AWBCTL) 163 ctrl->value = (reg & INDYCAM_CONTROL_AWBCTL)
158 ? 1 : 0; 164 ? 1 : 0;
159 break; 165 break;
160 case INDYCAM_CONTROL_SHUTTER: 166 case V4L2_CID_EXPOSURE:
161 ret = indycam_read_reg(client, INDYCAM_REG_SHUTTER, &reg); 167 ret = indycam_read_reg(sd, INDYCAM_REG_SHUTTER, &reg);
162 if (ret) 168 if (ret)
163 return -EIO; 169 return -EIO;
164 ctrl->value = ((s32)reg == 0x00) ? 0xff : ((s32)reg - 1); 170 ctrl->value = ((s32)reg == 0x00) ? 0xff : ((s32)reg - 1);
165 break; 171 break;
166 case INDYCAM_CONTROL_GAIN: 172 case V4L2_CID_GAIN:
167 ret = indycam_read_reg(client, INDYCAM_REG_GAIN, &reg); 173 ret = indycam_read_reg(sd, INDYCAM_REG_GAIN, &reg);
168 if (ret) 174 if (ret)
169 return -EIO; 175 return -EIO;
170 ctrl->value = (s32)reg; 176 ctrl->value = (s32)reg;
171 break; 177 break;
172 case INDYCAM_CONTROL_RED_BALANCE: 178 case V4L2_CID_RED_BALANCE:
173 ret = indycam_read_reg(client, INDYCAM_REG_RED_BALANCE, &reg); 179 ret = indycam_read_reg(sd, INDYCAM_REG_RED_BALANCE, &reg);
174 if (ret) 180 if (ret)
175 return -EIO; 181 return -EIO;
176 ctrl->value = (s32)reg; 182 ctrl->value = (s32)reg;
177 break; 183 break;
178 case INDYCAM_CONTROL_BLUE_BALANCE: 184 case V4L2_CID_BLUE_BALANCE:
179 ret = indycam_read_reg(client, INDYCAM_REG_BLUE_BALANCE, &reg); 185 ret = indycam_read_reg(sd, INDYCAM_REG_BLUE_BALANCE, &reg);
180 if (ret) 186 if (ret)
181 return -EIO; 187 return -EIO;
182 ctrl->value = (s32)reg; 188 ctrl->value = (s32)reg;
183 break; 189 break;
184 case INDYCAM_CONTROL_RED_SATURATION: 190 case INDYCAM_CONTROL_RED_SATURATION:
185 ret = indycam_read_reg(client, 191 ret = indycam_read_reg(sd,
186 INDYCAM_REG_RED_SATURATION, &reg); 192 INDYCAM_REG_RED_SATURATION, &reg);
187 if (ret) 193 if (ret)
188 return -EIO; 194 return -EIO;
189 ctrl->value = (s32)reg; 195 ctrl->value = (s32)reg;
190 break; 196 break;
191 case INDYCAM_CONTROL_BLUE_SATURATION: 197 case INDYCAM_CONTROL_BLUE_SATURATION:
192 ret = indycam_read_reg(client, 198 ret = indycam_read_reg(sd,
193 INDYCAM_REG_BLUE_SATURATION, &reg); 199 INDYCAM_REG_BLUE_SATURATION, &reg);
194 if (ret) 200 if (ret)
195 return -EIO; 201 return -EIO;
196 ctrl->value = (s32)reg; 202 ctrl->value = (s32)reg;
197 break; 203 break;
198 case INDYCAM_CONTROL_GAMMA: 204 case V4L2_CID_GAMMA:
199 if (camera->version == CAMERA_VERSION_MOOSE) { 205 if (camera->version == CAMERA_VERSION_MOOSE) {
200 ret = indycam_read_reg(client, 206 ret = indycam_read_reg(sd,
201 INDYCAM_REG_GAMMA, &reg); 207 INDYCAM_REG_GAMMA, &reg);
202 if (ret) 208 if (ret)
203 return -EIO; 209 return -EIO;
@@ -213,21 +219,20 @@ static int indycam_get_control(struct i2c_client *client,
213 return ret; 219 return ret;
214} 220}
215 221
216static int indycam_set_control(struct i2c_client *client, 222static int indycam_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
217 struct indycam_control *ctrl)
218{ 223{
219 struct indycam *camera = i2c_get_clientdata(client); 224 struct indycam *camera = to_indycam(sd);
220 u8 reg; 225 u8 reg;
221 int ret = 0; 226 int ret = 0;
222 227
223 switch (ctrl->type) { 228 switch (ctrl->id) {
224 case INDYCAM_CONTROL_AGC: 229 case V4L2_CID_AUTOGAIN:
225 case INDYCAM_CONTROL_AWB: 230 case V4L2_CID_AUTO_WHITE_BALANCE:
226 ret = indycam_read_reg(client, INDYCAM_REG_CONTROL, &reg); 231 ret = indycam_read_reg(sd, INDYCAM_REG_CONTROL, &reg);
227 if (ret) 232 if (ret)
228 break; 233 break;
229 234
230 if (ctrl->type == INDYCAM_CONTROL_AGC) { 235 if (ctrl->id == V4L2_CID_AUTOGAIN) {
231 if (ctrl->value) 236 if (ctrl->value)
232 reg |= INDYCAM_CONTROL_AGCENA; 237 reg |= INDYCAM_CONTROL_AGCENA;
233 else 238 else
@@ -239,34 +244,34 @@ static int indycam_set_control(struct i2c_client *client,
239 reg &= ~INDYCAM_CONTROL_AWBCTL; 244 reg &= ~INDYCAM_CONTROL_AWBCTL;
240 } 245 }
241 246
242 ret = indycam_write_reg(client, INDYCAM_REG_CONTROL, reg); 247 ret = indycam_write_reg(sd, INDYCAM_REG_CONTROL, reg);
243 break; 248 break;
244 case INDYCAM_CONTROL_SHUTTER: 249 case V4L2_CID_EXPOSURE:
245 reg = (ctrl->value == 0xff) ? 0x00 : (ctrl->value + 1); 250 reg = (ctrl->value == 0xff) ? 0x00 : (ctrl->value + 1);
246 ret = indycam_write_reg(client, INDYCAM_REG_SHUTTER, reg); 251 ret = indycam_write_reg(sd, INDYCAM_REG_SHUTTER, reg);
247 break; 252 break;
248 case INDYCAM_CONTROL_GAIN: 253 case V4L2_CID_GAIN:
249 ret = indycam_write_reg(client, INDYCAM_REG_GAIN, ctrl->value); 254 ret = indycam_write_reg(sd, INDYCAM_REG_GAIN, ctrl->value);
250 break; 255 break;
251 case INDYCAM_CONTROL_RED_BALANCE: 256 case V4L2_CID_RED_BALANCE:
252 ret = indycam_write_reg(client, INDYCAM_REG_RED_BALANCE, 257 ret = indycam_write_reg(sd, INDYCAM_REG_RED_BALANCE,
253 ctrl->value); 258 ctrl->value);
254 break; 259 break;
255 case INDYCAM_CONTROL_BLUE_BALANCE: 260 case V4L2_CID_BLUE_BALANCE:
256 ret = indycam_write_reg(client, INDYCAM_REG_BLUE_BALANCE, 261 ret = indycam_write_reg(sd, INDYCAM_REG_BLUE_BALANCE,
257 ctrl->value); 262 ctrl->value);
258 break; 263 break;
259 case INDYCAM_CONTROL_RED_SATURATION: 264 case INDYCAM_CONTROL_RED_SATURATION:
260 ret = indycam_write_reg(client, INDYCAM_REG_RED_SATURATION, 265 ret = indycam_write_reg(sd, INDYCAM_REG_RED_SATURATION,
261 ctrl->value); 266 ctrl->value);
262 break; 267 break;
263 case INDYCAM_CONTROL_BLUE_SATURATION: 268 case INDYCAM_CONTROL_BLUE_SATURATION:
264 ret = indycam_write_reg(client, INDYCAM_REG_BLUE_SATURATION, 269 ret = indycam_write_reg(sd, INDYCAM_REG_BLUE_SATURATION,
265 ctrl->value); 270 ctrl->value);
266 break; 271 break;
267 case INDYCAM_CONTROL_GAMMA: 272 case V4L2_CID_GAMMA:
268 if (camera->version == CAMERA_VERSION_MOOSE) { 273 if (camera->version == CAMERA_VERSION_MOOSE) {
269 ret = indycam_write_reg(client, INDYCAM_REG_GAMMA, 274 ret = indycam_write_reg(sd, INDYCAM_REG_GAMMA,
270 ctrl->value); 275 ctrl->value);
271 } 276 }
272 break; 277 break;
@@ -279,192 +284,103 @@ static int indycam_set_control(struct i2c_client *client,
279 284
280/* I2C-interface */ 285/* I2C-interface */
281 286
282static int indycam_attach(struct i2c_adapter *adap, int addr, int kind) 287static int indycam_g_chip_ident(struct v4l2_subdev *sd,
288 struct v4l2_dbg_chip_ident *chip)
289{
290 struct i2c_client *client = v4l2_get_subdevdata(sd);
291 struct indycam *camera = to_indycam(sd);
292
293 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_INDYCAM,
294 camera->version);
295}
296
297/* ----------------------------------------------------------------------- */
298
299static const struct v4l2_subdev_core_ops indycam_core_ops = {
300 .g_chip_ident = indycam_g_chip_ident,
301 .g_ctrl = indycam_g_ctrl,
302 .s_ctrl = indycam_s_ctrl,
303};
304
305static const struct v4l2_subdev_ops indycam_ops = {
306 .core = &indycam_core_ops,
307};
308
309static int indycam_probe(struct i2c_client *client,
310 const struct i2c_device_id *id)
283{ 311{
284 int err = 0; 312 int err = 0;
285 struct indycam *camera; 313 struct indycam *camera;
286 struct i2c_client *client; 314 struct v4l2_subdev *sd;
287 315
288 printk(KERN_INFO "SGI IndyCam driver version %s\n", 316 v4l_info(client, "chip found @ 0x%x (%s)\n",
289 INDYCAM_MODULE_VERSION); 317 client->addr << 1, client->adapter->name);
290 318
291 client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
292 if (!client)
293 return -ENOMEM;
294 camera = kzalloc(sizeof(struct indycam), GFP_KERNEL); 319 camera = kzalloc(sizeof(struct indycam), GFP_KERNEL);
295 if (!camera) { 320 if (!camera)
296 err = -ENOMEM; 321 return -ENOMEM;
297 goto out_free_client;
298 }
299
300 client->addr = addr;
301 client->adapter = adap;
302 client->driver = &i2c_driver_indycam;
303 client->flags = 0;
304 strcpy(client->name, "IndyCam client");
305 i2c_set_clientdata(client, camera);
306
307 camera->client = client;
308 322
309 err = i2c_attach_client(client); 323 sd = &camera->sd;
310 if (err) 324 v4l2_i2c_subdev_init(sd, client, &indycam_ops);
311 goto out_free_camera;
312 325
313 camera->version = i2c_smbus_read_byte_data(client, 326 camera->version = i2c_smbus_read_byte_data(client,
314 INDYCAM_REG_VERSION); 327 INDYCAM_REG_VERSION);
315 if (camera->version != CAMERA_VERSION_INDY && 328 if (camera->version != CAMERA_VERSION_INDY &&
316 camera->version != CAMERA_VERSION_MOOSE) { 329 camera->version != CAMERA_VERSION_MOOSE) {
317 err = -ENODEV; 330 kfree(camera);
318 goto out_detach_client; 331 return -ENODEV;
319 } 332 }
333
320 printk(KERN_INFO "IndyCam v%d.%d detected\n", 334 printk(KERN_INFO "IndyCam v%d.%d detected\n",
321 INDYCAM_VERSION_MAJOR(camera->version), 335 INDYCAM_VERSION_MAJOR(camera->version),
322 INDYCAM_VERSION_MINOR(camera->version)); 336 INDYCAM_VERSION_MINOR(camera->version));
323 337
324 indycam_regdump(client); 338 indycam_regdump(sd);
325 339
326 // initialize 340 // initialize
327 err = indycam_write_block(client, 0, sizeof(initseq), (u8 *)&initseq); 341 err = indycam_write_block(sd, 0, sizeof(initseq), (u8 *)&initseq);
328 if (err) { 342 if (err) {
329 printk(KERN_ERR "IndyCam initialization failed\n"); 343 printk(KERN_ERR "IndyCam initialization failed\n");
330 err = -EIO; 344 kfree(camera);
331 goto out_detach_client; 345 return -EIO;
332 } 346 }
333 347
334 indycam_regdump(client); 348 indycam_regdump(sd);
335 349
336 // white balance 350 // white balance
337 err = indycam_write_reg(client, INDYCAM_REG_CONTROL, 351 err = indycam_write_reg(sd, INDYCAM_REG_CONTROL,
338 INDYCAM_CONTROL_AGCENA | INDYCAM_CONTROL_AWBCTL); 352 INDYCAM_CONTROL_AGCENA | INDYCAM_CONTROL_AWBCTL);
339 if (err) { 353 if (err) {
340 printk(KERN_ERR "IndyCam: White balancing camera failed\n"); 354 printk(KERN_ERR "IndyCam: White balancing camera failed\n");
341 err = -EIO; 355 kfree(camera);
342 goto out_detach_client; 356 return -EIO;
343 } 357 }
344 358
345 indycam_regdump(client); 359 indycam_regdump(sd);
346 360
347 printk(KERN_INFO "IndyCam initialized\n"); 361 printk(KERN_INFO "IndyCam initialized\n");
348 362
349 return 0; 363 return 0;
350
351out_detach_client:
352 i2c_detach_client(client);
353out_free_camera:
354 kfree(camera);
355out_free_client:
356 kfree(client);
357 return err;
358} 364}
359 365
360static int indycam_probe(struct i2c_adapter *adap) 366static int indycam_remove(struct i2c_client *client)
361{ 367{
362 /* Indy specific crap */ 368 struct v4l2_subdev *sd = i2c_get_clientdata(client);
363 if (adap->id == I2C_HW_SGI_VINO)
364 return indycam_attach(adap, INDYCAM_ADDR, 0);
365 /* Feel free to add probe here :-) */
366 return -ENODEV;
367}
368
369static int indycam_detach(struct i2c_client *client)
370{
371 struct indycam *camera = i2c_get_clientdata(client);
372 369
373 i2c_detach_client(client); 370 v4l2_device_unregister_subdev(sd);
374 kfree(camera); 371 kfree(to_indycam(sd));
375 kfree(client);
376 return 0; 372 return 0;
377} 373}
378 374
379static int indycam_command(struct i2c_client *client, unsigned int cmd, 375static const struct i2c_device_id indycam_id[] = {
380 void *arg) 376 { "indycam", 0 },
381{ 377 { }
382 // struct indycam *camera = i2c_get_clientdata(client);
383
384 /* The old video_decoder interface just isn't enough,
385 * so we'll use some custom commands. */
386 switch (cmd) {
387 case DECODER_GET_CAPABILITIES: {
388 struct video_decoder_capability *cap = arg;
389
390 cap->flags = VIDEO_DECODER_NTSC;
391 cap->inputs = 1;
392 cap->outputs = 1;
393 break;
394 }
395 case DECODER_GET_STATUS: {
396 int *iarg = arg;
397
398 *iarg = DECODER_STATUS_GOOD | DECODER_STATUS_NTSC |
399 DECODER_STATUS_COLOR;
400 break;
401 }
402 case DECODER_SET_NORM: {
403 int *iarg = arg;
404
405 switch (*iarg) {
406 case VIDEO_MODE_NTSC:
407 break;
408 default:
409 return -EINVAL;
410 }
411 break;
412 }
413 case DECODER_SET_INPUT: {
414 int *iarg = arg;
415
416 if (*iarg != 0)
417 return -EINVAL;
418 break;
419 }
420 case DECODER_SET_OUTPUT: {
421 int *iarg = arg;
422
423 if (*iarg != 0)
424 return -EINVAL;
425 break;
426 }
427 case DECODER_ENABLE_OUTPUT: {
428 /* Always enabled */
429 break;
430 }
431 case DECODER_SET_PICTURE: {
432 // struct video_picture *pic = arg;
433 /* TODO: convert values for indycam_set_controls() */
434 break;
435 }
436 case DECODER_INDYCAM_GET_CONTROL: {
437 return indycam_get_control(client, arg);
438 }
439 case DECODER_INDYCAM_SET_CONTROL: {
440 return indycam_set_control(client, arg);
441 }
442 default:
443 return -EINVAL;
444 }
445
446 return 0;
447}
448
449static struct i2c_driver i2c_driver_indycam = {
450 .driver = {
451 .name = "indycam",
452 },
453 .id = I2C_DRIVERID_INDYCAM,
454 .attach_adapter = indycam_probe,
455 .detach_client = indycam_detach,
456 .command = indycam_command,
457}; 378};
379MODULE_DEVICE_TABLE(i2c, indycam_id);
458 380
459static int __init indycam_init(void) 381static struct v4l2_i2c_driver_data v4l2_i2c_data = {
460{ 382 .name = "indycam",
461 return i2c_add_driver(&i2c_driver_indycam); 383 .probe = indycam_probe,
462} 384 .remove = indycam_remove,
463 385 .id_table = indycam_id,
464static void __exit indycam_exit(void) 386};
465{
466 i2c_del_driver(&i2c_driver_indycam);
467}
468
469module_init(indycam_init);
470module_exit(indycam_exit);
diff --git a/drivers/media/video/indycam.h b/drivers/media/video/indycam.h
index e6ee82063ed8..881f21c474c4 100644
--- a/drivers/media/video/indycam.h
+++ b/drivers/media/video/indycam.h
@@ -87,22 +87,7 @@
87 87
88/* Driver interface definitions */ 88/* Driver interface definitions */
89 89
90#define INDYCAM_CONTROL_AGC 0 /* boolean */ 90#define INDYCAM_CONTROL_RED_SATURATION (V4L2_CID_PRIVATE_BASE + 0)
91#define INDYCAM_CONTROL_AWB 1 /* boolean */ 91#define INDYCAM_CONTROL_BLUE_SATURATION (V4L2_CID_PRIVATE_BASE + 1)
92#define INDYCAM_CONTROL_SHUTTER 2
93#define INDYCAM_CONTROL_GAIN 3
94#define INDYCAM_CONTROL_RED_BALANCE 4
95#define INDYCAM_CONTROL_BLUE_BALANCE 5
96#define INDYCAM_CONTROL_RED_SATURATION 6
97#define INDYCAM_CONTROL_BLUE_SATURATION 7
98#define INDYCAM_CONTROL_GAMMA 8
99
100struct indycam_control {
101 u8 type;
102 s32 value;
103};
104
105#define DECODER_INDYCAM_GET_CONTROL _IOR('d', 193, struct indycam_control)
106#define DECODER_INDYCAM_SET_CONTROL _IOW('d', 194, struct indycam_control)
107 92
108#endif 93#endif
diff --git a/drivers/media/video/ir-kbd-i2c.c b/drivers/media/video/ir-kbd-i2c.c
index d4658c56eddc..092c7da0f37a 100644
--- a/drivers/media/video/ir-kbd-i2c.c
+++ b/drivers/media/video/ir-kbd-i2c.c
@@ -16,6 +16,8 @@
16 * Henry Wong <henry@stuffedcow.net> 16 * Henry Wong <henry@stuffedcow.net>
17 * Mark Schultz <n9xmj@yahoo.com> 17 * Mark Schultz <n9xmj@yahoo.com>
18 * Brian Rogers <brian_rogers@comcast.net> 18 * Brian Rogers <brian_rogers@comcast.net>
19 * modified for AVerMedia Cardbus by
20 * Oldrich Jedlicka <oldium.pro@seznam.cz>
19 * 21 *
20 * This program is free software; you can redistribute it and/or modify 22 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by 23 * it under the terms of the GNU General Public License as published by
@@ -216,6 +218,46 @@ static int get_key_knc1(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
216 return 1; 218 return 1;
217} 219}
218 220
221static int get_key_avermedia_cardbus(struct IR_i2c *ir,
222 u32 *ir_key, u32 *ir_raw)
223{
224 unsigned char subaddr, key, keygroup;
225 struct i2c_msg msg[] = { { .addr = ir->c.addr, .flags = 0,
226 .buf = &subaddr, .len = 1},
227 { .addr = ir->c.addr, .flags = I2C_M_RD,
228 .buf = &key, .len = 1} };
229 subaddr = 0x0d;
230 if (2 != i2c_transfer(ir->c.adapter, msg, 2)) {
231 dprintk(1, "read error\n");
232 return -EIO;
233 }
234
235 if (key == 0xff)
236 return 0;
237
238 subaddr = 0x0b;
239 msg[1].buf = &keygroup;
240 if (2 != i2c_transfer(ir->c.adapter, msg, 2)) {
241 dprintk(1, "read error\n");
242 return -EIO;
243 }
244
245 if (keygroup == 0xff)
246 return 0;
247
248 dprintk(1, "read key 0x%02x/0x%02x\n", key, keygroup);
249 if (keygroup < 2 || keygroup > 3) {
250 /* Only a warning */
251 dprintk(1, "warning: invalid key group 0x%02x for key 0x%02x\n",
252 keygroup, key);
253 }
254 key |= (keygroup & 1) << 6;
255
256 *ir_key = key;
257 *ir_raw = key;
258 return 1;
259}
260
219/* ----------------------------------------------------------------------- */ 261/* ----------------------------------------------------------------------- */
220 262
221static void ir_key_poll(struct IR_i2c *ir) 263static void ir_key_poll(struct IR_i2c *ir)
@@ -237,15 +279,9 @@ static void ir_key_poll(struct IR_i2c *ir)
237 } 279 }
238} 280}
239 281
240static void ir_timer(unsigned long data)
241{
242 struct IR_i2c *ir = (struct IR_i2c*)data;
243 schedule_work(&ir->work);
244}
245
246static void ir_work(struct work_struct *work) 282static void ir_work(struct work_struct *work)
247{ 283{
248 struct IR_i2c *ir = container_of(work, struct IR_i2c, work); 284 struct IR_i2c *ir = container_of(work, struct IR_i2c, work.work);
249 int polling_interval = 100; 285 int polling_interval = 100;
250 286
251 /* MSI TV@nywhere Plus requires more frequent polling 287 /* MSI TV@nywhere Plus requires more frequent polling
@@ -254,7 +290,7 @@ static void ir_work(struct work_struct *work)
254 polling_interval = 50; 290 polling_interval = 50;
255 291
256 ir_key_poll(ir); 292 ir_key_poll(ir);
257 mod_timer(&ir->timer, jiffies + msecs_to_jiffies(polling_interval)); 293 schedule_delayed_work(&ir->work, msecs_to_jiffies(polling_interval));
258} 294}
259 295
260/* ----------------------------------------------------------------------- */ 296/* ----------------------------------------------------------------------- */
@@ -360,6 +396,12 @@ static int ir_attach(struct i2c_adapter *adap, int addr,
360 ir_type = IR_TYPE_OTHER; 396 ir_type = IR_TYPE_OTHER;
361 } 397 }
362 break; 398 break;
399 case 0x40:
400 name = "AVerMedia Cardbus remote";
401 ir->get_key = get_key_avermedia_cardbus;
402 ir_type = IR_TYPE_OTHER;
403 ir_codes = ir_codes_avermedia_cardbus;
404 break;
363 default: 405 default:
364 /* shouldn't happen */ 406 /* shouldn't happen */
365 printk(DEVNAME ": Huh? unknown i2c address (0x%02x)?\n", addr); 407 printk(DEVNAME ": Huh? unknown i2c address (0x%02x)?\n", addr);
@@ -404,11 +446,8 @@ static int ir_attach(struct i2c_adapter *adap, int addr,
404 ir->input->name, ir->input->phys, adap->name); 446 ir->input->name, ir->input->phys, adap->name);
405 447
406 /* start polling via eventd */ 448 /* start polling via eventd */
407 INIT_WORK(&ir->work, ir_work); 449 INIT_DELAYED_WORK(&ir->work, ir_work);
408 init_timer(&ir->timer); 450 schedule_delayed_work(&ir->work, 0);
409 ir->timer.function = ir_timer;
410 ir->timer.data = (unsigned long)ir;
411 schedule_work(&ir->work);
412 451
413 return 0; 452 return 0;
414 453
@@ -425,8 +464,7 @@ static int ir_detach(struct i2c_client *client)
425 struct IR_i2c *ir = i2c_get_clientdata(client); 464 struct IR_i2c *ir = i2c_get_clientdata(client);
426 465
427 /* kill outstanding polls */ 466 /* kill outstanding polls */
428 del_timer_sync(&ir->timer); 467 cancel_delayed_work_sync(&ir->work);
429 flush_scheduled_work();
430 468
431 /* unregister devices */ 469 /* unregister devices */
432 input_unregister_device(ir->input); 470 input_unregister_device(ir->input);
@@ -524,6 +562,22 @@ static int ir_probe(struct i2c_adapter *adap)
524 ir_attach(adap, msg.addr, 0, 0); 562 ir_attach(adap, msg.addr, 0, 0);
525 } 563 }
526 564
565 /* Special case for AVerMedia Cardbus remote */
566 if (adap->id == I2C_HW_SAA7134) {
567 unsigned char subaddr, data;
568 struct i2c_msg msg[] = { { .addr = 0x40, .flags = 0,
569 .buf = &subaddr, .len = 1},
570 { .addr = 0x40, .flags = I2C_M_RD,
571 .buf = &data, .len = 1} };
572 subaddr = 0x0d;
573 rc = i2c_transfer(adap, msg, 2);
574 dprintk(1, "probe 0x%02x/0x%02x @ %s: %s\n",
575 msg[0].addr, subaddr, adap->name,
576 (2 == rc) ? "yes" : "no");
577 if (2 == rc)
578 ir_attach(adap, msg[0].addr, 0, 0);
579 }
580
527 return 0; 581 return 0;
528} 582}
529 583
diff --git a/drivers/media/video/ivtv/ivtv-controls.c b/drivers/media/video/ivtv/ivtv-controls.c
index 62aa06f5d168..84995bcf4a75 100644
--- a/drivers/media/video/ivtv/ivtv-controls.c
+++ b/drivers/media/video/ivtv/ivtv-controls.c
@@ -26,6 +26,7 @@
26#include "ivtv-mailbox.h" 26#include "ivtv-mailbox.h"
27#include "ivtv-controls.h" 27#include "ivtv-controls.h"
28 28
29/* Must be sorted from low to high control ID! */
29static const u32 user_ctrls[] = { 30static const u32 user_ctrls[] = {
30 V4L2_CID_USER_CLASS, 31 V4L2_CID_USER_CLASS,
31 V4L2_CID_BRIGHTNESS, 32 V4L2_CID_BRIGHTNESS,
diff --git a/drivers/media/video/ivtv/ivtv-driver.c b/drivers/media/video/ivtv/ivtv-driver.c
index c46c990987f9..eca8bf92a225 100644
--- a/drivers/media/video/ivtv/ivtv-driver.c
+++ b/drivers/media/video/ivtv/ivtv-driver.c
@@ -357,7 +357,7 @@ void ivtv_read_eeprom(struct ivtv *itv, struct tveeprom *tv)
357static void ivtv_process_eeprom(struct ivtv *itv) 357static void ivtv_process_eeprom(struct ivtv *itv)
358{ 358{
359 struct tveeprom tv; 359 struct tveeprom tv;
360 int pci_slot = PCI_SLOT(itv->dev->devfn); 360 int pci_slot = PCI_SLOT(itv->pdev->devfn);
361 361
362 ivtv_read_eeprom(itv, &tv); 362 ivtv_read_eeprom(itv, &tv);
363 363
@@ -604,7 +604,7 @@ static void ivtv_process_options(struct ivtv *itv)
604 itv->std = ivtv_parse_std(itv); 604 itv->std = ivtv_parse_std(itv);
605 if (itv->std == 0 && tunertype >= 0) 605 if (itv->std == 0 && tunertype >= 0)
606 itv->std = tunertype ? V4L2_STD_MN : (V4L2_STD_ALL & ~V4L2_STD_MN); 606 itv->std = tunertype ? V4L2_STD_MN : (V4L2_STD_ALL & ~V4L2_STD_MN);
607 itv->has_cx23415 = (itv->dev->device == PCI_DEVICE_ID_IVTV15); 607 itv->has_cx23415 = (itv->pdev->device == PCI_DEVICE_ID_IVTV15);
608 chipname = itv->has_cx23415 ? "cx23415" : "cx23416"; 608 chipname = itv->has_cx23415 ? "cx23415" : "cx23416";
609 if (itv->options.cardtype == -1) { 609 if (itv->options.cardtype == -1) {
610 IVTV_INFO("Ignore card (detected %s based chip)\n", chipname); 610 IVTV_INFO("Ignore card (detected %s based chip)\n", chipname);
@@ -617,9 +617,9 @@ static void ivtv_process_options(struct ivtv *itv)
617 IVTV_ERR("Unknown user specified type, trying to autodetect card\n"); 617 IVTV_ERR("Unknown user specified type, trying to autodetect card\n");
618 } 618 }
619 if (itv->card == NULL) { 619 if (itv->card == NULL) {
620 if (itv->dev->subsystem_vendor == IVTV_PCI_ID_HAUPPAUGE || 620 if (itv->pdev->subsystem_vendor == IVTV_PCI_ID_HAUPPAUGE ||
621 itv->dev->subsystem_vendor == IVTV_PCI_ID_HAUPPAUGE_ALT1 || 621 itv->pdev->subsystem_vendor == IVTV_PCI_ID_HAUPPAUGE_ALT1 ||
622 itv->dev->subsystem_vendor == IVTV_PCI_ID_HAUPPAUGE_ALT2) { 622 itv->pdev->subsystem_vendor == IVTV_PCI_ID_HAUPPAUGE_ALT2) {
623 itv->card = ivtv_get_card(itv->has_cx23415 ? IVTV_CARD_PVR_350 : IVTV_CARD_PVR_150); 623 itv->card = ivtv_get_card(itv->has_cx23415 ? IVTV_CARD_PVR_350 : IVTV_CARD_PVR_150);
624 IVTV_INFO("Autodetected Hauppauge card (%s based)\n", 624 IVTV_INFO("Autodetected Hauppauge card (%s based)\n",
625 chipname); 625 chipname);
@@ -630,13 +630,13 @@ static void ivtv_process_options(struct ivtv *itv)
630 if (itv->card->pci_list == NULL) 630 if (itv->card->pci_list == NULL)
631 continue; 631 continue;
632 for (j = 0; itv->card->pci_list[j].device; j++) { 632 for (j = 0; itv->card->pci_list[j].device; j++) {
633 if (itv->dev->device != 633 if (itv->pdev->device !=
634 itv->card->pci_list[j].device) 634 itv->card->pci_list[j].device)
635 continue; 635 continue;
636 if (itv->dev->subsystem_vendor != 636 if (itv->pdev->subsystem_vendor !=
637 itv->card->pci_list[j].subsystem_vendor) 637 itv->card->pci_list[j].subsystem_vendor)
638 continue; 638 continue;
639 if (itv->dev->subsystem_device != 639 if (itv->pdev->subsystem_device !=
640 itv->card->pci_list[j].subsystem_device) 640 itv->card->pci_list[j].subsystem_device)
641 continue; 641 continue;
642 IVTV_INFO("Autodetected %s card (%s based)\n", 642 IVTV_INFO("Autodetected %s card (%s based)\n",
@@ -650,9 +650,9 @@ done:
650 if (itv->card == NULL) { 650 if (itv->card == NULL) {
651 itv->card = ivtv_get_card(IVTV_CARD_PVR_150); 651 itv->card = ivtv_get_card(IVTV_CARD_PVR_150);
652 IVTV_ERR("Unknown card: vendor/device: [%04x:%04x]\n", 652 IVTV_ERR("Unknown card: vendor/device: [%04x:%04x]\n",
653 itv->dev->vendor, itv->dev->device); 653 itv->pdev->vendor, itv->pdev->device);
654 IVTV_ERR(" subsystem vendor/device: [%04x:%04x]\n", 654 IVTV_ERR(" subsystem vendor/device: [%04x:%04x]\n",
655 itv->dev->subsystem_vendor, itv->dev->subsystem_device); 655 itv->pdev->subsystem_vendor, itv->pdev->subsystem_device);
656 IVTV_ERR(" %s based\n", chipname); 656 IVTV_ERR(" %s based\n", chipname);
657 IVTV_ERR("Defaulting to %s card\n", itv->card->name); 657 IVTV_ERR("Defaulting to %s card\n", itv->card->name);
658 IVTV_ERR("Please mail the vendor/device and subsystem vendor/device IDs and what kind of\n"); 658 IVTV_ERR("Please mail the vendor/device and subsystem vendor/device IDs and what kind of\n");
@@ -671,7 +671,7 @@ done:
671 */ 671 */
672static int __devinit ivtv_init_struct1(struct ivtv *itv) 672static int __devinit ivtv_init_struct1(struct ivtv *itv)
673{ 673{
674 itv->base_addr = pci_resource_start(itv->dev, 0); 674 itv->base_addr = pci_resource_start(itv->pdev, 0);
675 itv->enc_mbox.max_mbox = 2; /* the encoder has 3 mailboxes (0-2) */ 675 itv->enc_mbox.max_mbox = 2; /* the encoder has 3 mailboxes (0-2) */
676 itv->dec_mbox.max_mbox = 1; /* the decoder has 2 mailboxes (0-1) */ 676 itv->dec_mbox.max_mbox = 1; /* the decoder has 2 mailboxes (0-1) */
677 677
@@ -682,7 +682,7 @@ static int __devinit ivtv_init_struct1(struct ivtv *itv)
682 spin_lock_init(&itv->lock); 682 spin_lock_init(&itv->lock);
683 spin_lock_init(&itv->dma_reg_lock); 683 spin_lock_init(&itv->dma_reg_lock);
684 684
685 itv->irq_work_queues = create_singlethread_workqueue(itv->device.name); 685 itv->irq_work_queues = create_singlethread_workqueue(itv->v4l2_dev.name);
686 if (itv->irq_work_queues == NULL) { 686 if (itv->irq_work_queues == NULL) {
687 IVTV_ERR("Could not create ivtv workqueue\n"); 687 IVTV_ERR("Could not create ivtv workqueue\n");
688 return -1; 688 return -1;
@@ -766,7 +766,7 @@ static void __devinit ivtv_init_struct2(struct ivtv *itv)
766 itv->audio_input = itv->card->video_inputs[i].audio_index; 766 itv->audio_input = itv->card->video_inputs[i].audio_index;
767} 767}
768 768
769static int ivtv_setup_pci(struct ivtv *itv, struct pci_dev *dev, 769static int ivtv_setup_pci(struct ivtv *itv, struct pci_dev *pdev,
770 const struct pci_device_id *pci_id) 770 const struct pci_device_id *pci_id)
771{ 771{
772 u16 cmd; 772 u16 cmd;
@@ -775,11 +775,11 @@ static int ivtv_setup_pci(struct ivtv *itv, struct pci_dev *dev,
775 775
776 IVTV_DEBUG_INFO("Enabling pci device\n"); 776 IVTV_DEBUG_INFO("Enabling pci device\n");
777 777
778 if (pci_enable_device(dev)) { 778 if (pci_enable_device(pdev)) {
779 IVTV_ERR("Can't enable device!\n"); 779 IVTV_ERR("Can't enable device!\n");
780 return -EIO; 780 return -EIO;
781 } 781 }
782 if (pci_set_dma_mask(dev, 0xffffffff)) { 782 if (pci_set_dma_mask(pdev, 0xffffffff)) {
783 IVTV_ERR("No suitable DMA available.\n"); 783 IVTV_ERR("No suitable DMA available.\n");
784 return -EIO; 784 return -EIO;
785 } 785 }
@@ -805,11 +805,11 @@ static int ivtv_setup_pci(struct ivtv *itv, struct pci_dev *dev,
805 } 805 }
806 806
807 /* Check for bus mastering */ 807 /* Check for bus mastering */
808 pci_read_config_word(dev, PCI_COMMAND, &cmd); 808 pci_read_config_word(pdev, PCI_COMMAND, &cmd);
809 if (!(cmd & PCI_COMMAND_MASTER)) { 809 if (!(cmd & PCI_COMMAND_MASTER)) {
810 IVTV_DEBUG_INFO("Attempting to enable Bus Mastering\n"); 810 IVTV_DEBUG_INFO("Attempting to enable Bus Mastering\n");
811 pci_set_master(dev); 811 pci_set_master(pdev);
812 pci_read_config_word(dev, PCI_COMMAND, &cmd); 812 pci_read_config_word(pdev, PCI_COMMAND, &cmd);
813 if (!(cmd & PCI_COMMAND_MASTER)) { 813 if (!(cmd & PCI_COMMAND_MASTER)) {
814 IVTV_ERR("Bus Mastering is not enabled\n"); 814 IVTV_ERR("Bus Mastering is not enabled\n");
815 return -ENXIO; 815 return -ENXIO;
@@ -817,26 +817,26 @@ static int ivtv_setup_pci(struct ivtv *itv, struct pci_dev *dev,
817 } 817 }
818 IVTV_DEBUG_INFO("Bus Mastering Enabled.\n"); 818 IVTV_DEBUG_INFO("Bus Mastering Enabled.\n");
819 819
820 pci_read_config_byte(dev, PCI_CLASS_REVISION, &card_rev); 820 pci_read_config_byte(pdev, PCI_CLASS_REVISION, &card_rev);
821 pci_read_config_byte(dev, PCI_LATENCY_TIMER, &pci_latency); 821 pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &pci_latency);
822 822
823 if (pci_latency < 64 && ivtv_pci_latency) { 823 if (pci_latency < 64 && ivtv_pci_latency) {
824 IVTV_INFO("Unreasonably low latency timer, " 824 IVTV_INFO("Unreasonably low latency timer, "
825 "setting to 64 (was %d)\n", pci_latency); 825 "setting to 64 (was %d)\n", pci_latency);
826 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 64); 826 pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 64);
827 pci_read_config_byte(dev, PCI_LATENCY_TIMER, &pci_latency); 827 pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &pci_latency);
828 } 828 }
829 /* This config space value relates to DMA latencies. The 829 /* This config space value relates to DMA latencies. The
830 default value 0x8080 is too low however and will lead 830 default value 0x8080 is too low however and will lead
831 to DMA errors. 0xffff is the max value which solves 831 to DMA errors. 0xffff is the max value which solves
832 these problems. */ 832 these problems. */
833 pci_write_config_dword(dev, 0x40, 0xffff); 833 pci_write_config_dword(pdev, 0x40, 0xffff);
834 834
835 IVTV_DEBUG_INFO("%d (rev %d) at %02x:%02x.%x, " 835 IVTV_DEBUG_INFO("%d (rev %d) at %02x:%02x.%x, "
836 "irq: %d, latency: %d, memory: 0x%lx\n", 836 "irq: %d, latency: %d, memory: 0x%lx\n",
837 itv->dev->device, card_rev, dev->bus->number, 837 pdev->device, card_rev, pdev->bus->number,
838 PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn), 838 PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn),
839 itv->dev->irq, pci_latency, (unsigned long)itv->base_addr); 839 pdev->irq, pci_latency, (unsigned long)itv->base_addr);
840 840
841 return 0; 841 return 0;
842} 842}
@@ -935,7 +935,7 @@ static void ivtv_load_and_init_modules(struct ivtv *itv)
935 } 935 }
936} 936}
937 937
938static int __devinit ivtv_probe(struct pci_dev *dev, 938static int __devinit ivtv_probe(struct pci_dev *pdev,
939 const struct pci_device_id *pci_id) 939 const struct pci_device_id *pci_id)
940{ 940{
941 int retval = 0; 941 int retval = 0;
@@ -945,17 +945,17 @@ static int __devinit ivtv_probe(struct pci_dev *dev,
945 itv = kzalloc(sizeof(struct ivtv), GFP_ATOMIC); 945 itv = kzalloc(sizeof(struct ivtv), GFP_ATOMIC);
946 if (itv == NULL) 946 if (itv == NULL)
947 return -ENOMEM; 947 return -ENOMEM;
948 itv->dev = dev; 948 itv->pdev = pdev;
949 itv->instance = atomic_inc_return(&ivtv_instance) - 1; 949 itv->instance = atomic_inc_return(&ivtv_instance) - 1;
950 950
951 retval = v4l2_device_register(&dev->dev, &itv->device); 951 retval = v4l2_device_register(&pdev->dev, &itv->v4l2_dev);
952 if (retval) { 952 if (retval) {
953 kfree(itv); 953 kfree(itv);
954 return retval; 954 return retval;
955 } 955 }
956 /* "ivtv + PCI ID" is a bit of a mouthful, so use 956 /* "ivtv + PCI ID" is a bit of a mouthful, so use
957 "ivtv + instance" instead. */ 957 "ivtv + instance" instead. */
958 snprintf(itv->device.name, sizeof(itv->device.name), 958 snprintf(itv->v4l2_dev.name, sizeof(itv->v4l2_dev.name),
959 "ivtv%d", itv->instance); 959 "ivtv%d", itv->instance);
960 IVTV_INFO("Initializing card %d\n", itv->instance); 960 IVTV_INFO("Initializing card %d\n", itv->instance);
961 961
@@ -972,12 +972,11 @@ static int __devinit ivtv_probe(struct pci_dev *dev,
972 IVTV_DEBUG_INFO("base addr: 0x%08x\n", itv->base_addr); 972 IVTV_DEBUG_INFO("base addr: 0x%08x\n", itv->base_addr);
973 973
974 /* PCI Device Setup */ 974 /* PCI Device Setup */
975 if ((retval = ivtv_setup_pci(itv, dev, pci_id)) != 0) { 975 retval = ivtv_setup_pci(itv, pdev, pci_id);
976 if (retval == -EIO) 976 if (retval == -EIO)
977 goto free_workqueue; 977 goto free_workqueue;
978 else if (retval == -ENXIO) 978 if (retval == -ENXIO)
979 goto free_mem; 979 goto free_mem;
980 }
981 980
982 /* map io memory */ 981 /* map io memory */
983 IVTV_DEBUG_INFO("attempting ioremap at 0x%08x len 0x%08x\n", 982 IVTV_DEBUG_INFO("attempting ioremap at 0x%08x len 0x%08x\n",
@@ -1154,8 +1153,8 @@ static int __devinit ivtv_probe(struct pci_dev *dev,
1154 ivtv_set_irq_mask(itv, 0xffffffff); 1153 ivtv_set_irq_mask(itv, 0xffffffff);
1155 1154
1156 /* Register IRQ */ 1155 /* Register IRQ */
1157 retval = request_irq(itv->dev->irq, ivtv_irq_handler, 1156 retval = request_irq(itv->pdev->irq, ivtv_irq_handler,
1158 IRQF_SHARED | IRQF_DISABLED, itv->device.name, (void *)itv); 1157 IRQF_SHARED | IRQF_DISABLED, itv->v4l2_dev.name, (void *)itv);
1159 if (retval) { 1158 if (retval) {
1160 IVTV_ERR("Failed to register irq %d\n", retval); 1159 IVTV_ERR("Failed to register irq %d\n", retval);
1161 goto free_i2c; 1160 goto free_i2c;
@@ -1177,7 +1176,7 @@ static int __devinit ivtv_probe(struct pci_dev *dev,
1177free_streams: 1176free_streams:
1178 ivtv_streams_cleanup(itv, 1); 1177 ivtv_streams_cleanup(itv, 1);
1179free_irq: 1178free_irq:
1180 free_irq(itv->dev->irq, (void *)itv); 1179 free_irq(itv->pdev->irq, (void *)itv);
1181free_i2c: 1180free_i2c:
1182 exit_ivtv_i2c(itv); 1181 exit_ivtv_i2c(itv);
1183free_io: 1182free_io:
@@ -1194,7 +1193,7 @@ err:
1194 retval = -ENODEV; 1193 retval = -ENODEV;
1195 IVTV_ERR("Error %d on initialization\n", retval); 1194 IVTV_ERR("Error %d on initialization\n", retval);
1196 1195
1197 v4l2_device_unregister(&itv->device); 1196 v4l2_device_unregister(&itv->v4l2_dev);
1198 kfree(itv); 1197 kfree(itv);
1199 return retval; 1198 return retval;
1200} 1199}
@@ -1292,10 +1291,10 @@ int ivtv_init_on_first_open(struct ivtv *itv)
1292 return 0; 1291 return 0;
1293} 1292}
1294 1293
1295static void ivtv_remove(struct pci_dev *pci_dev) 1294static void ivtv_remove(struct pci_dev *pdev)
1296{ 1295{
1297 struct v4l2_device *dev = dev_get_drvdata(&pci_dev->dev); 1296 struct v4l2_device *v4l2_dev = dev_get_drvdata(&pdev->dev);
1298 struct ivtv *itv = to_ivtv(dev); 1297 struct ivtv *itv = to_ivtv(v4l2_dev);
1299 int i; 1298 int i;
1300 1299
1301 IVTV_DEBUG_INFO("Removing card\n"); 1300 IVTV_DEBUG_INFO("Removing card\n");
@@ -1336,11 +1335,9 @@ static void ivtv_remove(struct pci_dev *pci_dev)
1336 ivtv_streams_cleanup(itv, 1); 1335 ivtv_streams_cleanup(itv, 1);
1337 ivtv_udma_free(itv); 1336 ivtv_udma_free(itv);
1338 1337
1339 v4l2_device_unregister(&itv->device);
1340
1341 exit_ivtv_i2c(itv); 1338 exit_ivtv_i2c(itv);
1342 1339
1343 free_irq(itv->dev->irq, (void *)itv); 1340 free_irq(itv->pdev->irq, (void *)itv);
1344 ivtv_iounmap(itv); 1341 ivtv_iounmap(itv);
1345 1342
1346 release_mem_region(itv->base_addr, IVTV_ENCODER_SIZE); 1343 release_mem_region(itv->base_addr, IVTV_ENCODER_SIZE);
@@ -1348,11 +1345,13 @@ static void ivtv_remove(struct pci_dev *pci_dev)
1348 if (itv->has_cx23415) 1345 if (itv->has_cx23415)
1349 release_mem_region(itv->base_addr + IVTV_DECODER_OFFSET, IVTV_DECODER_SIZE); 1346 release_mem_region(itv->base_addr + IVTV_DECODER_OFFSET, IVTV_DECODER_SIZE);
1350 1347
1351 pci_disable_device(itv->dev); 1348 pci_disable_device(itv->pdev);
1352 for (i = 0; i < IVTV_VBI_FRAMES; i++) 1349 for (i = 0; i < IVTV_VBI_FRAMES; i++)
1353 kfree(itv->vbi.sliced_mpeg_data[i]); 1350 kfree(itv->vbi.sliced_mpeg_data[i]);
1354 1351
1355 printk(KERN_INFO "ivtv: Removed %s\n", itv->card_name); 1352 printk(KERN_INFO "ivtv: Removed %s\n", itv->card_name);
1353
1354 v4l2_device_unregister(&itv->v4l2_dev);
1356 kfree(itv); 1355 kfree(itv);
1357} 1356}
1358 1357
diff --git a/drivers/media/video/ivtv/ivtv-driver.h b/drivers/media/video/ivtv/ivtv-driver.h
index ce8d9b74357e..440f7328a7ed 100644
--- a/drivers/media/video/ivtv/ivtv-driver.h
+++ b/drivers/media/video/ivtv/ivtv-driver.h
@@ -133,7 +133,7 @@ extern int ivtv_debug;
133#define IVTV_DEBUG(x, type, fmt, args...) \ 133#define IVTV_DEBUG(x, type, fmt, args...) \
134 do { \ 134 do { \
135 if ((x) & ivtv_debug) \ 135 if ((x) & ivtv_debug) \
136 v4l2_info(&itv->device, " " type ": " fmt , ##args); \ 136 v4l2_info(&itv->v4l2_dev, " " type ": " fmt , ##args); \
137 } while (0) 137 } while (0)
138#define IVTV_DEBUG_WARN(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_WARN, "warn", fmt , ## args) 138#define IVTV_DEBUG_WARN(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_WARN, "warn", fmt , ## args)
139#define IVTV_DEBUG_INFO(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_INFO, "info", fmt , ## args) 139#define IVTV_DEBUG_INFO(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_INFO, "info", fmt , ## args)
@@ -149,7 +149,7 @@ extern int ivtv_debug;
149#define IVTV_DEBUG_HIGH_VOL(x, type, fmt, args...) \ 149#define IVTV_DEBUG_HIGH_VOL(x, type, fmt, args...) \
150 do { \ 150 do { \
151 if (((x) & ivtv_debug) && (ivtv_debug & IVTV_DBGFLG_HIGHVOL)) \ 151 if (((x) & ivtv_debug) && (ivtv_debug & IVTV_DBGFLG_HIGHVOL)) \
152 v4l2_info(&itv->device, " " type ": " fmt , ##args); \ 152 v4l2_info(&itv->v4l2_dev, " " type ": " fmt , ##args); \
153 } while (0) 153 } while (0)
154#define IVTV_DEBUG_HI_WARN(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_WARN, "warn", fmt , ## args) 154#define IVTV_DEBUG_HI_WARN(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_WARN, "warn", fmt , ## args)
155#define IVTV_DEBUG_HI_INFO(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_INFO, "info", fmt , ## args) 155#define IVTV_DEBUG_HI_INFO(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_INFO, "info", fmt , ## args)
@@ -163,9 +163,9 @@ extern int ivtv_debug;
163#define IVTV_DEBUG_HI_YUV(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_YUV, "yuv", fmt , ## args) 163#define IVTV_DEBUG_HI_YUV(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_YUV, "yuv", fmt , ## args)
164 164
165/* Standard kernel messages */ 165/* Standard kernel messages */
166#define IVTV_ERR(fmt, args...) v4l2_err(&itv->device, fmt , ## args) 166#define IVTV_ERR(fmt, args...) v4l2_err(&itv->v4l2_dev, fmt , ## args)
167#define IVTV_WARN(fmt, args...) v4l2_warn(&itv->device, fmt , ## args) 167#define IVTV_WARN(fmt, args...) v4l2_warn(&itv->v4l2_dev, fmt , ## args)
168#define IVTV_INFO(fmt, args...) v4l2_info(&itv->device, fmt , ## args) 168#define IVTV_INFO(fmt, args...) v4l2_info(&itv->v4l2_dev, fmt , ## args)
169 169
170/* output modes (cx23415 only) */ 170/* output modes (cx23415 only) */
171#define OUT_NONE 0 171#define OUT_NONE 0
@@ -315,7 +315,7 @@ struct ivtv; /* forward reference */
315struct ivtv_stream { 315struct ivtv_stream {
316 /* These first four fields are always set, even if the stream 316 /* These first four fields are always set, even if the stream
317 is not actually created. */ 317 is not actually created. */
318 struct video_device *v4l2dev; /* NULL when stream not created */ 318 struct video_device *vdev; /* NULL when stream not created */
319 struct ivtv *itv; /* for ease of use */ 319 struct ivtv *itv; /* for ease of use */
320 const char *name; /* name of the stream */ 320 const char *name; /* name of the stream */
321 int type; /* stream type */ 321 int type; /* stream type */
@@ -592,7 +592,7 @@ struct ivtv_card;
592/* Struct to hold info about ivtv cards */ 592/* Struct to hold info about ivtv cards */
593struct ivtv { 593struct ivtv {
594 /* General fixed card data */ 594 /* General fixed card data */
595 struct pci_dev *dev; /* PCI device */ 595 struct pci_dev *pdev; /* PCI device */
596 const struct ivtv_card *card; /* card information */ 596 const struct ivtv_card *card; /* card information */
597 const char *card_name; /* full name of the card */ 597 const char *card_name; /* full name of the card */
598 const struct ivtv_card_tuner_i2c *card_i2c; /* i2c addresses to probe for tuner */ 598 const struct ivtv_card_tuner_i2c *card_i2c; /* i2c addresses to probe for tuner */
@@ -612,7 +612,7 @@ struct ivtv {
612 volatile void __iomem *reg_mem; /* pointer to mapped registers */ 612 volatile void __iomem *reg_mem; /* pointer to mapped registers */
613 struct ivtv_options options; /* user options */ 613 struct ivtv_options options; /* user options */
614 614
615 struct v4l2_device device; 615 struct v4l2_device v4l2_dev;
616 struct v4l2_subdev sd_gpio; /* GPIO sub-device */ 616 struct v4l2_subdev sd_gpio; /* GPIO sub-device */
617 u16 instance; 617 u16 instance;
618 618
@@ -696,7 +696,7 @@ struct ivtv {
696 u64 vbi_data_inserted; /* number of VBI bytes inserted into the MPEG stream */ 696 u64 vbi_data_inserted; /* number of VBI bytes inserted into the MPEG stream */
697 u32 last_dec_timing[3]; /* cache last retrieved pts/scr/frame values */ 697 u32 last_dec_timing[3]; /* cache last retrieved pts/scr/frame values */
698 unsigned long dualwatch_jiffies;/* jiffies value of the previous dualwatch check */ 698 unsigned long dualwatch_jiffies;/* jiffies value of the previous dualwatch check */
699 u16 dualwatch_stereo_mode; /* current detected dualwatch stereo mode */ 699 u32 dualwatch_stereo_mode; /* current detected dualwatch stereo mode */
700 700
701 701
702 /* VBI state info */ 702 /* VBI state info */
@@ -719,9 +719,9 @@ struct ivtv {
719 struct osd_info *osd_info; /* ivtvfb private OSD info */ 719 struct osd_info *osd_info; /* ivtvfb private OSD info */
720}; 720};
721 721
722static inline struct ivtv *to_ivtv(struct v4l2_device *dev) 722static inline struct ivtv *to_ivtv(struct v4l2_device *v4l2_dev)
723{ 723{
724 return container_of(dev, struct ivtv, device); 724 return container_of(v4l2_dev, struct ivtv, v4l2_dev);
725} 725}
726 726
727/* Globals */ 727/* Globals */
@@ -788,7 +788,7 @@ static inline int ivtv_raw_vbi(const struct ivtv *itv)
788/* Call the specified callback for all subdevs matching hw (if 0, then 788/* Call the specified callback for all subdevs matching hw (if 0, then
789 match them all). Ignore any errors. */ 789 match them all). Ignore any errors. */
790#define ivtv_call_hw(itv, hw, o, f, args...) \ 790#define ivtv_call_hw(itv, hw, o, f, args...) \
791 __v4l2_device_call_subdevs(&(itv)->device, !(hw) || (sd->grp_id & (hw)), o, f , ##args) 791 __v4l2_device_call_subdevs(&(itv)->v4l2_dev, !(hw) || (sd->grp_id & (hw)), o, f , ##args)
792 792
793#define ivtv_call_all(itv, o, f, args...) ivtv_call_hw(itv, 0, o, f , ##args) 793#define ivtv_call_all(itv, o, f, args...) ivtv_call_hw(itv, 0, o, f , ##args)
794 794
@@ -796,7 +796,7 @@ static inline int ivtv_raw_vbi(const struct ivtv *itv)
796 match them all). If the callback returns an error other than 0 or 796 match them all). If the callback returns an error other than 0 or
797 -ENOIOCTLCMD, then return with that error code. */ 797 -ENOIOCTLCMD, then return with that error code. */
798#define ivtv_call_hw_err(itv, hw, o, f, args...) \ 798#define ivtv_call_hw_err(itv, hw, o, f, args...) \
799 __v4l2_device_call_subdevs_until_err(&(itv)->device, !(hw) || (sd->grp_id & (hw)), o, f , ##args) 799 __v4l2_device_call_subdevs_until_err(&(itv)->v4l2_dev, !(hw) || (sd->grp_id & (hw)), o, f , ##args)
800 800
801#define ivtv_call_all_err(itv, o, f, args...) ivtv_call_hw_err(itv, 0, o, f , ##args) 801#define ivtv_call_all_err(itv, o, f, args...) ivtv_call_hw_err(itv, 0, o, f , ##args)
802 802
diff --git a/drivers/media/video/ivtv/ivtv-fileops.c b/drivers/media/video/ivtv/ivtv-fileops.c
index d594bc29f07f..cfaacf6096d0 100644
--- a/drivers/media/video/ivtv/ivtv-fileops.c
+++ b/drivers/media/video/ivtv/ivtv-fileops.c
@@ -148,10 +148,10 @@ void ivtv_release_stream(struct ivtv_stream *s)
148static void ivtv_dualwatch(struct ivtv *itv) 148static void ivtv_dualwatch(struct ivtv *itv)
149{ 149{
150 struct v4l2_tuner vt; 150 struct v4l2_tuner vt;
151 u16 new_bitmap; 151 u32 new_bitmap;
152 u16 new_stereo_mode; 152 u32 new_stereo_mode;
153 const u16 stereo_mask = 0x0300; 153 const u32 stereo_mask = 0x0300;
154 const u16 dual = 0x0200; 154 const u32 dual = 0x0200;
155 155
156 new_stereo_mode = itv->params.audio_properties & stereo_mask; 156 new_stereo_mode = itv->params.audio_properties & stereo_mask;
157 memset(&vt, 0, sizeof(vt)); 157 memset(&vt, 0, sizeof(vt));
@@ -991,7 +991,7 @@ int ivtv_v4l2_open(struct file *filp)
991 mutex_lock(&itv->serialize_lock); 991 mutex_lock(&itv->serialize_lock);
992 if (ivtv_init_on_first_open(itv)) { 992 if (ivtv_init_on_first_open(itv)) {
993 IVTV_ERR("Failed to initialize on minor %d\n", 993 IVTV_ERR("Failed to initialize on minor %d\n",
994 s->v4l2dev->minor); 994 vdev->minor);
995 mutex_unlock(&itv->serialize_lock); 995 mutex_unlock(&itv->serialize_lock);
996 return -ENXIO; 996 return -ENXIO;
997 } 997 }
diff --git a/drivers/media/video/ivtv/ivtv-firmware.c b/drivers/media/video/ivtv/ivtv-firmware.c
index 6dba55b7e25a..c1b7ec475c27 100644
--- a/drivers/media/video/ivtv/ivtv-firmware.c
+++ b/drivers/media/video/ivtv/ivtv-firmware.c
@@ -52,7 +52,7 @@ static int load_fw_direct(const char *fn, volatile u8 __iomem *mem, struct ivtv
52 int retries = 3; 52 int retries = 3;
53 53
54retry: 54retry:
55 if (retries && request_firmware(&fw, fn, &itv->dev->dev) == 0) { 55 if (retries && request_firmware(&fw, fn, &itv->pdev->dev) == 0) {
56 int i; 56 int i;
57 volatile u32 __iomem *dst = (volatile u32 __iomem *)mem; 57 volatile u32 __iomem *dst = (volatile u32 __iomem *)mem;
58 const u32 *src = (const u32 *)fw->data; 58 const u32 *src = (const u32 *)fw->data;
diff --git a/drivers/media/video/ivtv/ivtv-gpio.c b/drivers/media/video/ivtv/ivtv-gpio.c
index dc2850e87a7e..3321983d89e5 100644
--- a/drivers/media/video/ivtv/ivtv-gpio.c
+++ b/drivers/media/video/ivtv/ivtv-gpio.c
@@ -384,7 +384,7 @@ int ivtv_gpio_init(struct ivtv *itv)
384 write_reg(itv->card->gpio_init.initial_value | pin, IVTV_REG_GPIO_OUT); 384 write_reg(itv->card->gpio_init.initial_value | pin, IVTV_REG_GPIO_OUT);
385 write_reg(itv->card->gpio_init.direction | pin, IVTV_REG_GPIO_DIR); 385 write_reg(itv->card->gpio_init.direction | pin, IVTV_REG_GPIO_DIR);
386 v4l2_subdev_init(&itv->sd_gpio, &subdev_ops); 386 v4l2_subdev_init(&itv->sd_gpio, &subdev_ops);
387 snprintf(itv->sd_gpio.name, sizeof(itv->sd_gpio.name), "%s-gpio", itv->device.name); 387 snprintf(itv->sd_gpio.name, sizeof(itv->sd_gpio.name), "%s-gpio", itv->v4l2_dev.name);
388 itv->sd_gpio.grp_id = IVTV_HW_GPIO; 388 itv->sd_gpio.grp_id = IVTV_HW_GPIO;
389 return v4l2_device_register_subdev(&itv->device, &itv->sd_gpio); 389 return v4l2_device_register_subdev(&itv->v4l2_dev, &itv->sd_gpio);
390} 390}
diff --git a/drivers/media/video/ivtv/ivtv-i2c.c b/drivers/media/video/ivtv/ivtv-i2c.c
index ca1d9557945e..e73a196ecc7a 100644
--- a/drivers/media/video/ivtv/ivtv-i2c.c
+++ b/drivers/media/video/ivtv/ivtv-i2c.c
@@ -194,14 +194,14 @@ struct v4l2_subdev *ivtv_find_hw(struct ivtv *itv, u32 hw)
194 struct v4l2_subdev *result = NULL; 194 struct v4l2_subdev *result = NULL;
195 struct v4l2_subdev *sd; 195 struct v4l2_subdev *sd;
196 196
197 spin_lock(&itv->device.lock); 197 spin_lock(&itv->v4l2_dev.lock);
198 v4l2_device_for_each_subdev(sd, &itv->device) { 198 v4l2_device_for_each_subdev(sd, &itv->v4l2_dev) {
199 if (sd->grp_id == hw) { 199 if (sd->grp_id == hw) {
200 result = sd; 200 result = sd;
201 break; 201 break;
202 } 202 }
203 } 203 }
204 spin_unlock(&itv->device.lock); 204 spin_unlock(&itv->v4l2_dev.lock);
205 return result; 205 return result;
206} 206}
207 207
@@ -472,8 +472,8 @@ static int ivtv_read(struct ivtv *itv, unsigned char addr, unsigned char *data,
472 intervening stop condition */ 472 intervening stop condition */
473static int ivtv_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs, int num) 473static int ivtv_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs, int num)
474{ 474{
475 struct v4l2_device *drv = i2c_get_adapdata(i2c_adap); 475 struct v4l2_device *v4l2_dev = i2c_get_adapdata(i2c_adap);
476 struct ivtv *itv = to_ivtv(drv); 476 struct ivtv *itv = to_ivtv(v4l2_dev);
477 int retval; 477 int retval;
478 int i; 478 int i;
479 479
@@ -604,12 +604,12 @@ int init_ivtv_i2c(struct ivtv *itv)
604 604
605 sprintf(itv->i2c_adap.name + strlen(itv->i2c_adap.name), " #%d", 605 sprintf(itv->i2c_adap.name + strlen(itv->i2c_adap.name), " #%d",
606 itv->instance); 606 itv->instance);
607 i2c_set_adapdata(&itv->i2c_adap, &itv->device); 607 i2c_set_adapdata(&itv->i2c_adap, &itv->v4l2_dev);
608 608
609 memcpy(&itv->i2c_client, &ivtv_i2c_client_template, 609 memcpy(&itv->i2c_client, &ivtv_i2c_client_template,
610 sizeof(struct i2c_client)); 610 sizeof(struct i2c_client));
611 itv->i2c_client.adapter = &itv->i2c_adap; 611 itv->i2c_client.adapter = &itv->i2c_adap;
612 itv->i2c_adap.dev.parent = &itv->dev->dev; 612 itv->i2c_adap.dev.parent = &itv->pdev->dev;
613 613
614 IVTV_DEBUG_I2C("setting scl and sda to 1\n"); 614 IVTV_DEBUG_I2C("setting scl and sda to 1\n");
615 ivtv_setscl(itv, 1); 615 ivtv_setscl(itv, 1);
diff --git a/drivers/media/video/ivtv/ivtv-ioctl.c b/drivers/media/video/ivtv/ivtv-ioctl.c
index c13bd2aa0bea..9a0424298af1 100644
--- a/drivers/media/video/ivtv/ivtv-ioctl.c
+++ b/drivers/media/video/ivtv/ivtv-ioctl.c
@@ -345,10 +345,8 @@ static int ivtv_g_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *f
345 pixfmt->priv = 0; 345 pixfmt->priv = 0;
346 if (id->type == IVTV_ENC_STREAM_TYPE_YUV) { 346 if (id->type == IVTV_ENC_STREAM_TYPE_YUV) {
347 pixfmt->pixelformat = V4L2_PIX_FMT_HM12; 347 pixfmt->pixelformat = V4L2_PIX_FMT_HM12;
348 /* YUV size is (Y=(h*w) + UV=(h*(w/2))) */ 348 /* YUV size is (Y=(h*720) + UV=(h*(720/2))) */
349 pixfmt->sizeimage = 349 pixfmt->sizeimage = pixfmt->height * 720 * 3 / 2;
350 pixfmt->height * pixfmt->width +
351 pixfmt->height * (pixfmt->width / 2);
352 pixfmt->bytesperline = 720; 350 pixfmt->bytesperline = 720;
353 } else { 351 } else {
354 pixfmt->pixelformat = V4L2_PIX_FMT_MPEG; 352 pixfmt->pixelformat = V4L2_PIX_FMT_MPEG;
@@ -469,11 +467,17 @@ static int ivtv_try_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format
469 struct ivtv *itv = id->itv; 467 struct ivtv *itv = id->itv;
470 int w = fmt->fmt.pix.width; 468 int w = fmt->fmt.pix.width;
471 int h = fmt->fmt.pix.height; 469 int h = fmt->fmt.pix.height;
470 int min_h = 2;
472 471
473 w = min(w, 720); 472 w = min(w, 720);
474 w = max(w, 2); 473 w = max(w, 2);
474 if (id->type == IVTV_ENC_STREAM_TYPE_YUV) {
475 /* YUV height must be a multiple of 32 */
476 h &= ~0x1f;
477 min_h = 32;
478 }
475 h = min(h, itv->is_50hz ? 576 : 480); 479 h = min(h, itv->is_50hz ? 576 : 480);
476 h = max(h, 2); 480 h = max(h, min_h);
477 ivtv_g_fmt_vid_cap(file, fh, fmt); 481 ivtv_g_fmt_vid_cap(file, fh, fmt);
478 fmt->fmt.pix.width = w; 482 fmt->fmt.pix.width = w;
479 fmt->fmt.pix.height = h; 483 fmt->fmt.pix.height = h;
@@ -766,7 +770,7 @@ static int ivtv_querycap(struct file *file, void *fh, struct v4l2_capability *vc
766 770
767 strlcpy(vcap->driver, IVTV_DRIVER_NAME, sizeof(vcap->driver)); 771 strlcpy(vcap->driver, IVTV_DRIVER_NAME, sizeof(vcap->driver));
768 strlcpy(vcap->card, itv->card_name, sizeof(vcap->card)); 772 strlcpy(vcap->card, itv->card_name, sizeof(vcap->card));
769 snprintf(vcap->bus_info, sizeof(vcap->bus_info), "PCI:%s", pci_name(itv->dev)); 773 snprintf(vcap->bus_info, sizeof(vcap->bus_info), "PCI:%s", pci_name(itv->pdev));
770 vcap->version = IVTV_DRIVER_VERSION; /* version */ 774 vcap->version = IVTV_DRIVER_VERSION; /* version */
771 vcap->capabilities = itv->v4l2_cap; /* capabilities */ 775 vcap->capabilities = itv->v4l2_cap; /* capabilities */
772 return 0; 776 return 0;
@@ -1513,12 +1517,12 @@ static int ivtv_log_status(struct file *file, void *fh)
1513 } 1517 }
1514 IVTV_INFO("Tuner: %s\n", 1518 IVTV_INFO("Tuner: %s\n",
1515 test_bit(IVTV_F_I_RADIO_USER, &itv->i_flags) ? "Radio" : "TV"); 1519 test_bit(IVTV_F_I_RADIO_USER, &itv->i_flags) ? "Radio" : "TV");
1516 cx2341x_log_status(&itv->params, itv->device.name); 1520 cx2341x_log_status(&itv->params, itv->v4l2_dev.name);
1517 IVTV_INFO("Status flags: 0x%08lx\n", itv->i_flags); 1521 IVTV_INFO("Status flags: 0x%08lx\n", itv->i_flags);
1518 for (i = 0; i < IVTV_MAX_STREAMS; i++) { 1522 for (i = 0; i < IVTV_MAX_STREAMS; i++) {
1519 struct ivtv_stream *s = &itv->streams[i]; 1523 struct ivtv_stream *s = &itv->streams[i];
1520 1524
1521 if (s->v4l2dev == NULL || s->buffers == 0) 1525 if (s->vdev == NULL || s->buffers == 0)
1522 continue; 1526 continue;
1523 IVTV_INFO("Stream %s: status 0x%04lx, %d%% of %d KiB (%d buffers) in use\n", s->name, s->s_flags, 1527 IVTV_INFO("Stream %s: status 0x%04lx, %d%% of %d KiB (%d buffers) in use\n", s->name, s->s_flags,
1524 (s->buffers - s->q_free.buffers) * 100 / s->buffers, 1528 (s->buffers - s->q_free.buffers) * 100 / s->buffers,
diff --git a/drivers/media/video/ivtv/ivtv-irq.c b/drivers/media/video/ivtv/ivtv-irq.c
index f5d00ec5da73..01c14d2b381a 100644
--- a/drivers/media/video/ivtv/ivtv-irq.c
+++ b/drivers/media/video/ivtv/ivtv-irq.c
@@ -46,7 +46,7 @@ static void ivtv_pio_work_handler(struct ivtv *itv)
46 46
47 IVTV_DEBUG_HI_DMA("ivtv_pio_work_handler\n"); 47 IVTV_DEBUG_HI_DMA("ivtv_pio_work_handler\n");
48 if (itv->cur_pio_stream < 0 || itv->cur_pio_stream >= IVTV_MAX_STREAMS || 48 if (itv->cur_pio_stream < 0 || itv->cur_pio_stream >= IVTV_MAX_STREAMS ||
49 s->v4l2dev == NULL || !ivtv_use_pio(s)) { 49 s->vdev == NULL || !ivtv_use_pio(s)) {
50 itv->cur_pio_stream = -1; 50 itv->cur_pio_stream = -1;
51 /* trigger PIO complete user interrupt */ 51 /* trigger PIO complete user interrupt */
52 write_reg(IVTV_IRQ_ENC_PIO_COMPLETE, 0x44); 52 write_reg(IVTV_IRQ_ENC_PIO_COMPLETE, 0x44);
@@ -109,7 +109,7 @@ static int stream_enc_dma_append(struct ivtv_stream *s, u32 data[CX2341X_MBOX_MA
109 int rc; 109 int rc;
110 110
111 /* sanity checks */ 111 /* sanity checks */
112 if (s->v4l2dev == NULL) { 112 if (s->vdev == NULL) {
113 IVTV_DEBUG_WARN("Stream %s not started\n", s->name); 113 IVTV_DEBUG_WARN("Stream %s not started\n", s->name);
114 return -1; 114 return -1;
115 } 115 }
diff --git a/drivers/media/video/ivtv/ivtv-queue.c b/drivers/media/video/ivtv/ivtv-queue.c
index 71bd13e22e2e..ff7b7deded4f 100644
--- a/drivers/media/video/ivtv/ivtv-queue.c
+++ b/drivers/media/video/ivtv/ivtv-queue.c
@@ -230,7 +230,7 @@ int ivtv_stream_alloc(struct ivtv_stream *s)
230 return -ENOMEM; 230 return -ENOMEM;
231 } 231 }
232 if (ivtv_might_use_dma(s)) { 232 if (ivtv_might_use_dma(s)) {
233 s->sg_handle = pci_map_single(itv->dev, s->sg_dma, sizeof(struct ivtv_sg_element), s->dma); 233 s->sg_handle = pci_map_single(itv->pdev, s->sg_dma, sizeof(struct ivtv_sg_element), s->dma);
234 ivtv_stream_sync_for_cpu(s); 234 ivtv_stream_sync_for_cpu(s);
235 } 235 }
236 236
@@ -248,7 +248,7 @@ int ivtv_stream_alloc(struct ivtv_stream *s)
248 } 248 }
249 INIT_LIST_HEAD(&buf->list); 249 INIT_LIST_HEAD(&buf->list);
250 if (ivtv_might_use_dma(s)) { 250 if (ivtv_might_use_dma(s)) {
251 buf->dma_handle = pci_map_single(s->itv->dev, 251 buf->dma_handle = pci_map_single(s->itv->pdev,
252 buf->buf, s->buf_size + 256, s->dma); 252 buf->buf, s->buf_size + 256, s->dma);
253 ivtv_buf_sync_for_cpu(s, buf); 253 ivtv_buf_sync_for_cpu(s, buf);
254 } 254 }
@@ -271,7 +271,7 @@ void ivtv_stream_free(struct ivtv_stream *s)
271 /* empty q_free */ 271 /* empty q_free */
272 while ((buf = ivtv_dequeue(s, &s->q_free))) { 272 while ((buf = ivtv_dequeue(s, &s->q_free))) {
273 if (ivtv_might_use_dma(s)) 273 if (ivtv_might_use_dma(s))
274 pci_unmap_single(s->itv->dev, buf->dma_handle, 274 pci_unmap_single(s->itv->pdev, buf->dma_handle,
275 s->buf_size + 256, s->dma); 275 s->buf_size + 256, s->dma);
276 kfree(buf->buf); 276 kfree(buf->buf);
277 kfree(buf); 277 kfree(buf);
@@ -280,7 +280,7 @@ void ivtv_stream_free(struct ivtv_stream *s)
280 /* Free SG Array/Lists */ 280 /* Free SG Array/Lists */
281 if (s->sg_dma != NULL) { 281 if (s->sg_dma != NULL) {
282 if (s->sg_handle != IVTV_DMA_UNMAPPED) { 282 if (s->sg_handle != IVTV_DMA_UNMAPPED) {
283 pci_unmap_single(s->itv->dev, s->sg_handle, 283 pci_unmap_single(s->itv->pdev, s->sg_handle,
284 sizeof(struct ivtv_sg_element), PCI_DMA_TODEVICE); 284 sizeof(struct ivtv_sg_element), PCI_DMA_TODEVICE);
285 s->sg_handle = IVTV_DMA_UNMAPPED; 285 s->sg_handle = IVTV_DMA_UNMAPPED;
286 } 286 }
diff --git a/drivers/media/video/ivtv/ivtv-queue.h b/drivers/media/video/ivtv/ivtv-queue.h
index 476556afd39a..91233839a26c 100644
--- a/drivers/media/video/ivtv/ivtv-queue.h
+++ b/drivers/media/video/ivtv/ivtv-queue.h
@@ -53,14 +53,14 @@ static inline int ivtv_use_dma(struct ivtv_stream *s)
53static inline void ivtv_buf_sync_for_cpu(struct ivtv_stream *s, struct ivtv_buffer *buf) 53static inline void ivtv_buf_sync_for_cpu(struct ivtv_stream *s, struct ivtv_buffer *buf)
54{ 54{
55 if (ivtv_use_dma(s)) 55 if (ivtv_use_dma(s))
56 pci_dma_sync_single_for_cpu(s->itv->dev, buf->dma_handle, 56 pci_dma_sync_single_for_cpu(s->itv->pdev, buf->dma_handle,
57 s->buf_size + 256, s->dma); 57 s->buf_size + 256, s->dma);
58} 58}
59 59
60static inline void ivtv_buf_sync_for_device(struct ivtv_stream *s, struct ivtv_buffer *buf) 60static inline void ivtv_buf_sync_for_device(struct ivtv_stream *s, struct ivtv_buffer *buf)
61{ 61{
62 if (ivtv_use_dma(s)) 62 if (ivtv_use_dma(s))
63 pci_dma_sync_single_for_device(s->itv->dev, buf->dma_handle, 63 pci_dma_sync_single_for_device(s->itv->pdev, buf->dma_handle,
64 s->buf_size + 256, s->dma); 64 s->buf_size + 256, s->dma);
65} 65}
66 66
@@ -82,14 +82,14 @@ void ivtv_stream_free(struct ivtv_stream *s);
82static inline void ivtv_stream_sync_for_cpu(struct ivtv_stream *s) 82static inline void ivtv_stream_sync_for_cpu(struct ivtv_stream *s)
83{ 83{
84 if (ivtv_use_dma(s)) 84 if (ivtv_use_dma(s))
85 pci_dma_sync_single_for_cpu(s->itv->dev, s->sg_handle, 85 pci_dma_sync_single_for_cpu(s->itv->pdev, s->sg_handle,
86 sizeof(struct ivtv_sg_element), PCI_DMA_TODEVICE); 86 sizeof(struct ivtv_sg_element), PCI_DMA_TODEVICE);
87} 87}
88 88
89static inline void ivtv_stream_sync_for_device(struct ivtv_stream *s) 89static inline void ivtv_stream_sync_for_device(struct ivtv_stream *s)
90{ 90{
91 if (ivtv_use_dma(s)) 91 if (ivtv_use_dma(s))
92 pci_dma_sync_single_for_device(s->itv->dev, s->sg_handle, 92 pci_dma_sync_single_for_device(s->itv->pdev, s->sg_handle,
93 sizeof(struct ivtv_sg_element), PCI_DMA_TODEVICE); 93 sizeof(struct ivtv_sg_element), PCI_DMA_TODEVICE);
94} 94}
95 95
diff --git a/drivers/media/video/ivtv/ivtv-streams.c b/drivers/media/video/ivtv/ivtv-streams.c
index 854a950af78c..15da01710efc 100644
--- a/drivers/media/video/ivtv/ivtv-streams.c
+++ b/drivers/media/video/ivtv/ivtv-streams.c
@@ -137,11 +137,11 @@ static struct {
137static void ivtv_stream_init(struct ivtv *itv, int type) 137static void ivtv_stream_init(struct ivtv *itv, int type)
138{ 138{
139 struct ivtv_stream *s = &itv->streams[type]; 139 struct ivtv_stream *s = &itv->streams[type];
140 struct video_device *dev = s->v4l2dev; 140 struct video_device *vdev = s->vdev;
141 141
142 /* we need to keep v4l2dev, so restore it afterwards */ 142 /* we need to keep vdev, so restore it afterwards */
143 memset(s, 0, sizeof(*s)); 143 memset(s, 0, sizeof(*s));
144 s->v4l2dev = dev; 144 s->vdev = vdev;
145 145
146 /* initialize ivtv_stream fields */ 146 /* initialize ivtv_stream fields */
147 s->itv = itv; 147 s->itv = itv;
@@ -172,10 +172,10 @@ static int ivtv_prep_dev(struct ivtv *itv, int type)
172 int num_offset = ivtv_stream_info[type].num_offset; 172 int num_offset = ivtv_stream_info[type].num_offset;
173 int num = itv->instance + ivtv_first_minor + num_offset; 173 int num = itv->instance + ivtv_first_minor + num_offset;
174 174
175 /* These four fields are always initialized. If v4l2dev == NULL, then 175 /* These four fields are always initialized. If vdev == NULL, then
176 this stream is not in use. In that case no other fields but these 176 this stream is not in use. In that case no other fields but these
177 four can be used. */ 177 four can be used. */
178 s->v4l2dev = NULL; 178 s->vdev = NULL;
179 s->itv = itv; 179 s->itv = itv;
180 s->type = type; 180 s->type = type;
181 s->name = ivtv_stream_info[type].name; 181 s->name = ivtv_stream_info[type].name;
@@ -197,21 +197,21 @@ static int ivtv_prep_dev(struct ivtv *itv, int type)
197 ivtv_stream_init(itv, type); 197 ivtv_stream_init(itv, type);
198 198
199 /* allocate and initialize the v4l2 video device structure */ 199 /* allocate and initialize the v4l2 video device structure */
200 s->v4l2dev = video_device_alloc(); 200 s->vdev = video_device_alloc();
201 if (s->v4l2dev == NULL) { 201 if (s->vdev == NULL) {
202 IVTV_ERR("Couldn't allocate v4l2 video_device for %s\n", s->name); 202 IVTV_ERR("Couldn't allocate v4l2 video_device for %s\n", s->name);
203 return -ENOMEM; 203 return -ENOMEM;
204 } 204 }
205 205
206 snprintf(s->v4l2dev->name, sizeof(s->v4l2dev->name), "%s %s", 206 snprintf(s->vdev->name, sizeof(s->vdev->name), "%s %s",
207 itv->device.name, s->name); 207 itv->v4l2_dev.name, s->name);
208 208
209 s->v4l2dev->num = num; 209 s->vdev->num = num;
210 s->v4l2dev->v4l2_dev = &itv->device; 210 s->vdev->v4l2_dev = &itv->v4l2_dev;
211 s->v4l2dev->fops = ivtv_stream_info[type].fops; 211 s->vdev->fops = ivtv_stream_info[type].fops;
212 s->v4l2dev->release = video_device_release; 212 s->vdev->release = video_device_release;
213 s->v4l2dev->tvnorms = V4L2_STD_ALL; 213 s->vdev->tvnorms = V4L2_STD_ALL;
214 ivtv_set_funcs(s->v4l2dev); 214 ivtv_set_funcs(s->vdev);
215 return 0; 215 return 0;
216} 216}
217 217
@@ -226,7 +226,7 @@ int ivtv_streams_setup(struct ivtv *itv)
226 if (ivtv_prep_dev(itv, type)) 226 if (ivtv_prep_dev(itv, type))
227 break; 227 break;
228 228
229 if (itv->streams[type].v4l2dev == NULL) 229 if (itv->streams[type].vdev == NULL)
230 continue; 230 continue;
231 231
232 /* Allocate Stream */ 232 /* Allocate Stream */
@@ -247,28 +247,28 @@ static int ivtv_reg_dev(struct ivtv *itv, int type)
247 int vfl_type = ivtv_stream_info[type].vfl_type; 247 int vfl_type = ivtv_stream_info[type].vfl_type;
248 int num; 248 int num;
249 249
250 if (s->v4l2dev == NULL) 250 if (s->vdev == NULL)
251 return 0; 251 return 0;
252 252
253 num = s->v4l2dev->num; 253 num = s->vdev->num;
254 /* card number + user defined offset + device offset */ 254 /* card number + user defined offset + device offset */
255 if (type != IVTV_ENC_STREAM_TYPE_MPG) { 255 if (type != IVTV_ENC_STREAM_TYPE_MPG) {
256 struct ivtv_stream *s_mpg = &itv->streams[IVTV_ENC_STREAM_TYPE_MPG]; 256 struct ivtv_stream *s_mpg = &itv->streams[IVTV_ENC_STREAM_TYPE_MPG];
257 257
258 if (s_mpg->v4l2dev) 258 if (s_mpg->vdev)
259 num = s_mpg->v4l2dev->num + ivtv_stream_info[type].num_offset; 259 num = s_mpg->vdev->num + ivtv_stream_info[type].num_offset;
260 } 260 }
261 video_set_drvdata(s->v4l2dev, s); 261 video_set_drvdata(s->vdev, s);
262 262
263 /* Register device. First try the desired minor, then any free one. */ 263 /* Register device. First try the desired minor, then any free one. */
264 if (video_register_device(s->v4l2dev, vfl_type, num)) { 264 if (video_register_device(s->vdev, vfl_type, num)) {
265 IVTV_ERR("Couldn't register v4l2 device for %s kernel number %d\n", 265 IVTV_ERR("Couldn't register v4l2 device for %s kernel number %d\n",
266 s->name, num); 266 s->name, num);
267 video_device_release(s->v4l2dev); 267 video_device_release(s->vdev);
268 s->v4l2dev = NULL; 268 s->vdev = NULL;
269 return -ENOMEM; 269 return -ENOMEM;
270 } 270 }
271 num = s->v4l2dev->num; 271 num = s->vdev->num;
272 272
273 switch (vfl_type) { 273 switch (vfl_type) {
274 case VFL_TYPE_GRABBER: 274 case VFL_TYPE_GRABBER:
@@ -316,9 +316,9 @@ void ivtv_streams_cleanup(struct ivtv *itv, int unregister)
316 316
317 /* Teardown all streams */ 317 /* Teardown all streams */
318 for (type = 0; type < IVTV_MAX_STREAMS; type++) { 318 for (type = 0; type < IVTV_MAX_STREAMS; type++) {
319 struct video_device *vdev = itv->streams[type].v4l2dev; 319 struct video_device *vdev = itv->streams[type].vdev;
320 320
321 itv->streams[type].v4l2dev = NULL; 321 itv->streams[type].vdev = NULL;
322 if (vdev == NULL) 322 if (vdev == NULL)
323 continue; 323 continue;
324 324
@@ -449,7 +449,7 @@ int ivtv_start_v4l2_encode_stream(struct ivtv_stream *s)
449 int captype = 0, subtype = 0; 449 int captype = 0, subtype = 0;
450 int enable_passthrough = 0; 450 int enable_passthrough = 0;
451 451
452 if (s->v4l2dev == NULL) 452 if (s->vdev == NULL)
453 return -EINVAL; 453 return -EINVAL;
454 454
455 IVTV_DEBUG_INFO("Start encoder stream %s\n", s->name); 455 IVTV_DEBUG_INFO("Start encoder stream %s\n", s->name);
@@ -611,7 +611,7 @@ static int ivtv_setup_v4l2_decode_stream(struct ivtv_stream *s)
611 struct cx2341x_mpeg_params *p = &itv->params; 611 struct cx2341x_mpeg_params *p = &itv->params;
612 int datatype; 612 int datatype;
613 613
614 if (s->v4l2dev == NULL) 614 if (s->vdev == NULL)
615 return -EINVAL; 615 return -EINVAL;
616 616
617 IVTV_DEBUG_INFO("Setting some initial decoder settings\n"); 617 IVTV_DEBUG_INFO("Setting some initial decoder settings\n");
@@ -657,7 +657,7 @@ int ivtv_start_v4l2_decode_stream(struct ivtv_stream *s, int gop_offset)
657{ 657{
658 struct ivtv *itv = s->itv; 658 struct ivtv *itv = s->itv;
659 659
660 if (s->v4l2dev == NULL) 660 if (s->vdev == NULL)
661 return -EINVAL; 661 return -EINVAL;
662 662
663 if (test_and_set_bit(IVTV_F_S_STREAMING, &s->s_flags)) 663 if (test_and_set_bit(IVTV_F_S_STREAMING, &s->s_flags))
@@ -705,7 +705,7 @@ void ivtv_stop_all_captures(struct ivtv *itv)
705 for (i = IVTV_MAX_STREAMS - 1; i >= 0; i--) { 705 for (i = IVTV_MAX_STREAMS - 1; i >= 0; i--) {
706 struct ivtv_stream *s = &itv->streams[i]; 706 struct ivtv_stream *s = &itv->streams[i];
707 707
708 if (s->v4l2dev == NULL) 708 if (s->vdev == NULL)
709 continue; 709 continue;
710 if (test_bit(IVTV_F_S_STREAMING, &s->s_flags)) { 710 if (test_bit(IVTV_F_S_STREAMING, &s->s_flags)) {
711 ivtv_stop_v4l2_encode_stream(s, 0); 711 ivtv_stop_v4l2_encode_stream(s, 0);
@@ -720,7 +720,7 @@ int ivtv_stop_v4l2_encode_stream(struct ivtv_stream *s, int gop_end)
720 int cap_type; 720 int cap_type;
721 int stopmode; 721 int stopmode;
722 722
723 if (s->v4l2dev == NULL) 723 if (s->vdev == NULL)
724 return -EINVAL; 724 return -EINVAL;
725 725
726 /* This function assumes that you are allowed to stop the capture 726 /* This function assumes that you are allowed to stop the capture
@@ -834,7 +834,7 @@ int ivtv_stop_v4l2_decode_stream(struct ivtv_stream *s, int flags, u64 pts)
834{ 834{
835 struct ivtv *itv = s->itv; 835 struct ivtv *itv = s->itv;
836 836
837 if (s->v4l2dev == NULL) 837 if (s->vdev == NULL)
838 return -EINVAL; 838 return -EINVAL;
839 839
840 if (s->type != IVTV_DEC_STREAM_TYPE_YUV && s->type != IVTV_DEC_STREAM_TYPE_MPG) 840 if (s->type != IVTV_DEC_STREAM_TYPE_YUV && s->type != IVTV_DEC_STREAM_TYPE_MPG)
@@ -895,7 +895,7 @@ int ivtv_passthrough_mode(struct ivtv *itv, int enable)
895 struct ivtv_stream *yuv_stream = &itv->streams[IVTV_ENC_STREAM_TYPE_YUV]; 895 struct ivtv_stream *yuv_stream = &itv->streams[IVTV_ENC_STREAM_TYPE_YUV];
896 struct ivtv_stream *dec_stream = &itv->streams[IVTV_DEC_STREAM_TYPE_YUV]; 896 struct ivtv_stream *dec_stream = &itv->streams[IVTV_DEC_STREAM_TYPE_YUV];
897 897
898 if (yuv_stream->v4l2dev == NULL || dec_stream->v4l2dev == NULL) 898 if (yuv_stream->vdev == NULL || dec_stream->vdev == NULL)
899 return -EINVAL; 899 return -EINVAL;
900 900
901 IVTV_DEBUG_INFO("ivtv ioctl: Select passthrough mode\n"); 901 IVTV_DEBUG_INFO("ivtv ioctl: Select passthrough mode\n");
diff --git a/drivers/media/video/ivtv/ivtv-udma.c b/drivers/media/video/ivtv/ivtv-udma.c
index 460db03b0ba0..d07ad6c39024 100644
--- a/drivers/media/video/ivtv/ivtv-udma.c
+++ b/drivers/media/video/ivtv/ivtv-udma.c
@@ -93,7 +93,7 @@ void ivtv_udma_alloc(struct ivtv *itv)
93{ 93{
94 if (itv->udma.SG_handle == 0) { 94 if (itv->udma.SG_handle == 0) {
95 /* Map DMA Page Array Buffer */ 95 /* Map DMA Page Array Buffer */
96 itv->udma.SG_handle = pci_map_single(itv->dev, itv->udma.SGarray, 96 itv->udma.SG_handle = pci_map_single(itv->pdev, itv->udma.SGarray,
97 sizeof(itv->udma.SGarray), PCI_DMA_TODEVICE); 97 sizeof(itv->udma.SGarray), PCI_DMA_TODEVICE);
98 ivtv_udma_sync_for_cpu(itv); 98 ivtv_udma_sync_for_cpu(itv);
99 } 99 }
@@ -147,7 +147,7 @@ int ivtv_udma_setup(struct ivtv *itv, unsigned long ivtv_dest_addr,
147 } 147 }
148 148
149 /* Map SG List */ 149 /* Map SG List */
150 dma->SG_length = pci_map_sg(itv->dev, dma->SGlist, dma->page_count, PCI_DMA_TODEVICE); 150 dma->SG_length = pci_map_sg(itv->pdev, dma->SGlist, dma->page_count, PCI_DMA_TODEVICE);
151 151
152 /* Fill SG Array with new values */ 152 /* Fill SG Array with new values */
153 ivtv_udma_fill_sg_array (dma, ivtv_dest_addr, 0, -1); 153 ivtv_udma_fill_sg_array (dma, ivtv_dest_addr, 0, -1);
@@ -172,7 +172,7 @@ void ivtv_udma_unmap(struct ivtv *itv)
172 172
173 /* Unmap Scatterlist */ 173 /* Unmap Scatterlist */
174 if (dma->SG_length) { 174 if (dma->SG_length) {
175 pci_unmap_sg(itv->dev, dma->SGlist, dma->page_count, PCI_DMA_TODEVICE); 175 pci_unmap_sg(itv->pdev, dma->SGlist, dma->page_count, PCI_DMA_TODEVICE);
176 dma->SG_length = 0; 176 dma->SG_length = 0;
177 } 177 }
178 /* sync DMA */ 178 /* sync DMA */
@@ -191,13 +191,13 @@ void ivtv_udma_free(struct ivtv *itv)
191 191
192 /* Unmap SG Array */ 192 /* Unmap SG Array */
193 if (itv->udma.SG_handle) { 193 if (itv->udma.SG_handle) {
194 pci_unmap_single(itv->dev, itv->udma.SG_handle, 194 pci_unmap_single(itv->pdev, itv->udma.SG_handle,
195 sizeof(itv->udma.SGarray), PCI_DMA_TODEVICE); 195 sizeof(itv->udma.SGarray), PCI_DMA_TODEVICE);
196 } 196 }
197 197
198 /* Unmap Scatterlist */ 198 /* Unmap Scatterlist */
199 if (itv->udma.SG_length) { 199 if (itv->udma.SG_length) {
200 pci_unmap_sg(itv->dev, itv->udma.SGlist, itv->udma.page_count, PCI_DMA_TODEVICE); 200 pci_unmap_sg(itv->pdev, itv->udma.SGlist, itv->udma.page_count, PCI_DMA_TODEVICE);
201 } 201 }
202 202
203 for (i = 0; i < IVTV_DMA_SG_OSD_ENT; i++) { 203 for (i = 0; i < IVTV_DMA_SG_OSD_ENT; i++) {
diff --git a/drivers/media/video/ivtv/ivtv-udma.h b/drivers/media/video/ivtv/ivtv-udma.h
index df727e23be0a..ee3c9efb5b72 100644
--- a/drivers/media/video/ivtv/ivtv-udma.h
+++ b/drivers/media/video/ivtv/ivtv-udma.h
@@ -35,13 +35,13 @@ void ivtv_udma_start(struct ivtv *itv);
35 35
36static inline void ivtv_udma_sync_for_device(struct ivtv *itv) 36static inline void ivtv_udma_sync_for_device(struct ivtv *itv)
37{ 37{
38 pci_dma_sync_single_for_device((struct pci_dev *)itv->dev, itv->udma.SG_handle, 38 pci_dma_sync_single_for_device(itv->pdev, itv->udma.SG_handle,
39 sizeof(itv->udma.SGarray), PCI_DMA_TODEVICE); 39 sizeof(itv->udma.SGarray), PCI_DMA_TODEVICE);
40} 40}
41 41
42static inline void ivtv_udma_sync_for_cpu(struct ivtv *itv) 42static inline void ivtv_udma_sync_for_cpu(struct ivtv *itv)
43{ 43{
44 pci_dma_sync_single_for_cpu((struct pci_dev *)itv->dev, itv->udma.SG_handle, 44 pci_dma_sync_single_for_cpu(itv->pdev, itv->udma.SG_handle,
45 sizeof(itv->udma.SGarray), PCI_DMA_TODEVICE); 45 sizeof(itv->udma.SGarray), PCI_DMA_TODEVICE);
46} 46}
47 47
diff --git a/drivers/media/video/ivtv/ivtv-vbi.c b/drivers/media/video/ivtv/ivtv-vbi.c
index 5c5d1c462fef..f420d31b937d 100644
--- a/drivers/media/video/ivtv/ivtv-vbi.c
+++ b/drivers/media/video/ivtv/ivtv-vbi.c
@@ -185,6 +185,8 @@ static void copy_vbi_data(struct ivtv *itv, int lines, u32 pts_stamp)
185 size = 4 + ((43 * line + 3) & ~3); 185 size = 4 + ((43 * line + 3) & ~3);
186 } else { 186 } else {
187 memcpy(dst + sd, "itv0", 4); 187 memcpy(dst + sd, "itv0", 4);
188 cpu_to_le32s(&linemask[0]);
189 cpu_to_le32s(&linemask[1]);
188 memcpy(dst + sd + 4, &linemask[0], 8); 190 memcpy(dst + sd + 4, &linemask[0], 8);
189 size = 12 + ((43 * line + 3) & ~3); 191 size = 12 + ((43 * line + 3) & ~3);
190 } 192 }
diff --git a/drivers/media/video/ivtv/ivtv-version.h b/drivers/media/video/ivtv/ivtv-version.h
index 8cd753d30bf7..b530dec399d3 100644
--- a/drivers/media/video/ivtv/ivtv-version.h
+++ b/drivers/media/video/ivtv/ivtv-version.h
@@ -23,7 +23,7 @@
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 4 25#define IVTV_DRIVER_VERSION_MINOR 4
26#define IVTV_DRIVER_VERSION_PATCHLEVEL 0 26#define IVTV_DRIVER_VERSION_PATCHLEVEL 1
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)
29#define IVTV_DRIVER_VERSION KERNEL_VERSION(IVTV_DRIVER_VERSION_MAJOR,IVTV_DRIVER_VERSION_MINOR,IVTV_DRIVER_VERSION_PATCHLEVEL) 29#define IVTV_DRIVER_VERSION KERNEL_VERSION(IVTV_DRIVER_VERSION_MAJOR,IVTV_DRIVER_VERSION_MINOR,IVTV_DRIVER_VERSION_PATCHLEVEL)
diff --git a/drivers/media/video/ivtv/ivtv-yuv.c b/drivers/media/video/ivtv/ivtv-yuv.c
index ee91107376c7..7912ed6b72ee 100644
--- a/drivers/media/video/ivtv/ivtv-yuv.c
+++ b/drivers/media/video/ivtv/ivtv-yuv.c
@@ -103,7 +103,7 @@ static int ivtv_yuv_prep_user_dma(struct ivtv *itv, struct ivtv_user_dma *dma,
103 dma->page_count = 0; 103 dma->page_count = 0;
104 return -ENOMEM; 104 return -ENOMEM;
105 } 105 }
106 dma->SG_length = pci_map_sg(itv->dev, dma->SGlist, dma->page_count, PCI_DMA_TODEVICE); 106 dma->SG_length = pci_map_sg(itv->pdev, dma->SGlist, dma->page_count, PCI_DMA_TODEVICE);
107 107
108 /* Fill SG Array with new values */ 108 /* Fill SG Array with new values */
109 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);
@@ -910,7 +910,7 @@ static void ivtv_yuv_init(struct ivtv *itv)
910 /* We need a buffer for blanking when Y plane is offset - non-fatal if we can't get one */ 910 /* We need a buffer for blanking when Y plane is offset - non-fatal if we can't get one */
911 yi->blanking_ptr = kzalloc(720 * 16, GFP_KERNEL|__GFP_NOWARN); 911 yi->blanking_ptr = kzalloc(720 * 16, GFP_KERNEL|__GFP_NOWARN);
912 if (yi->blanking_ptr) { 912 if (yi->blanking_ptr) {
913 yi->blanking_dmaptr = pci_map_single(itv->dev, yi->blanking_ptr, 720*16, PCI_DMA_TODEVICE); 913 yi->blanking_dmaptr = pci_map_single(itv->pdev, yi->blanking_ptr, 720*16, PCI_DMA_TODEVICE);
914 } else { 914 } else {
915 yi->blanking_dmaptr = 0; 915 yi->blanking_dmaptr = 0;
916 IVTV_DEBUG_WARN("Failed to allocate yuv blanking buffer\n"); 916 IVTV_DEBUG_WARN("Failed to allocate yuv blanking buffer\n");
@@ -1237,7 +1237,7 @@ void ivtv_yuv_close(struct ivtv *itv)
1237 if (yi->blanking_ptr) { 1237 if (yi->blanking_ptr) {
1238 kfree(yi->blanking_ptr); 1238 kfree(yi->blanking_ptr);
1239 yi->blanking_ptr = NULL; 1239 yi->blanking_ptr = NULL;
1240 pci_unmap_single(itv->dev, yi->blanking_dmaptr, 720*16, PCI_DMA_TODEVICE); 1240 pci_unmap_single(itv->pdev, yi->blanking_dmaptr, 720*16, PCI_DMA_TODEVICE);
1241 } 1241 }
1242 1242
1243 /* Invalidate the old dimension information */ 1243 /* Invalidate the old dimension information */
diff --git a/drivers/media/video/ivtv/ivtvfb.c b/drivers/media/video/ivtv/ivtvfb.c
index 36abd2aef6f1..66e6eb513076 100644
--- a/drivers/media/video/ivtv/ivtvfb.c
+++ b/drivers/media/video/ivtv/ivtvfb.c
@@ -1192,12 +1192,12 @@ static int ivtvfb_init_card(struct ivtv *itv)
1192static int __init ivtvfb_callback_init(struct device *dev, void *p) 1192static int __init ivtvfb_callback_init(struct device *dev, void *p)
1193{ 1193{
1194 struct v4l2_device *v4l2_dev = dev_get_drvdata(dev); 1194 struct v4l2_device *v4l2_dev = dev_get_drvdata(dev);
1195 struct ivtv *itv = container_of(v4l2_dev, struct ivtv, device); 1195 struct ivtv *itv = container_of(v4l2_dev, struct ivtv, v4l2_dev);
1196 1196
1197 if (itv && (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT)) { 1197 if (itv && (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT)) {
1198 if (ivtvfb_init_card(itv) == 0) { 1198 if (ivtvfb_init_card(itv) == 0) {
1199 IVTVFB_INFO("Framebuffer registered on %s\n", 1199 IVTVFB_INFO("Framebuffer registered on %s\n",
1200 itv->device.name); 1200 itv->v4l2_dev.name);
1201 (*(int *)p)++; 1201 (*(int *)p)++;
1202 } 1202 }
1203 } 1203 }
@@ -1207,7 +1207,7 @@ static int __init ivtvfb_callback_init(struct device *dev, void *p)
1207static int ivtvfb_callback_cleanup(struct device *dev, void *p) 1207static int ivtvfb_callback_cleanup(struct device *dev, void *p)
1208{ 1208{
1209 struct v4l2_device *v4l2_dev = dev_get_drvdata(dev); 1209 struct v4l2_device *v4l2_dev = dev_get_drvdata(dev);
1210 struct ivtv *itv = container_of(v4l2_dev, struct ivtv, device); 1210 struct ivtv *itv = container_of(v4l2_dev, struct ivtv, v4l2_dev);
1211 1211
1212 if (itv && (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT)) { 1212 if (itv && (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT)) {
1213 if (unregister_framebuffer(&itv->osd_info->ivtvfb_info)) { 1213 if (unregister_framebuffer(&itv->osd_info->ivtvfb_info)) {
diff --git a/drivers/media/video/ks0127.c b/drivers/media/video/ks0127.c
index bae2d2beb709..841024b6bcdf 100644
--- a/drivers/media/video/ks0127.c
+++ b/drivers/media/video/ks0127.c
@@ -39,19 +39,20 @@
39#include <linux/errno.h> 39#include <linux/errno.h>
40#include <linux/kernel.h> 40#include <linux/kernel.h>
41#include <linux/i2c.h> 41#include <linux/i2c.h>
42#include <linux/video_decoder.h> 42#include <linux/videodev2.h>
43#include <media/v4l2-common.h> 43#include <media/v4l2-device.h>
44#include <media/v4l2-i2c-drv-legacy.h> 44#include <media/v4l2-chip-ident.h>
45#include <media/v4l2-i2c-drv.h>
45#include "ks0127.h" 46#include "ks0127.h"
46 47
47MODULE_DESCRIPTION("KS0127 video decoder driver"); 48MODULE_DESCRIPTION("KS0127 video decoder driver");
48MODULE_AUTHOR("Ryan Drake"); 49MODULE_AUTHOR("Ryan Drake");
49MODULE_LICENSE("GPL"); 50MODULE_LICENSE("GPL");
50 51
51#define KS_TYPE_UNKNOWN 0 52/* Addresses */
52#define KS_TYPE_0122S 1 53#define I2C_KS0127_ADDON 0xD8
53#define KS_TYPE_0127 2 54#define I2C_KS0127_ONBOARD 0xDA
54#define KS_TYPE_0127B 3 55
55 56
56/* ks0127 control registers */ 57/* ks0127 control registers */
57#define KS_STAT 0x00 58#define KS_STAT 0x00
@@ -197,15 +198,17 @@ struct adjust {
197}; 198};
198 199
199struct ks0127 { 200struct ks0127 {
200 int format_width; 201 struct v4l2_subdev sd;
201 int format_height; 202 v4l2_std_id norm;
202 int cap_width; 203 int ident;
203 int cap_height;
204 int norm;
205 int ks_type;
206 u8 regs[256]; 204 u8 regs[256];
207}; 205};
208 206
207static inline struct ks0127 *to_ks0127(struct v4l2_subdev *sd)
208{
209 return container_of(sd, struct ks0127, sd);
210}
211
209 212
210static int debug; /* insmod parameter */ 213static int debug; /* insmod parameter */
211 214
@@ -311,43 +314,45 @@ static void init_reg_defaults(void)
311 */ 314 */
312 315
313 316
314static u8 ks0127_read(struct i2c_client *c, u8 reg) 317static u8 ks0127_read(struct v4l2_subdev *sd, u8 reg)
315{ 318{
319 struct i2c_client *client = v4l2_get_subdevdata(sd);
316 char val = 0; 320 char val = 0;
317 struct i2c_msg msgs[] = { 321 struct i2c_msg msgs[] = {
318 { c->addr, 0, sizeof(reg), &reg }, 322 { client->addr, 0, sizeof(reg), &reg },
319 { c->addr, I2C_M_RD | I2C_M_NO_RD_ACK, sizeof(val), &val } 323 { client->addr, I2C_M_RD | I2C_M_NO_RD_ACK, sizeof(val), &val }
320 }; 324 };
321 int ret; 325 int ret;
322 326
323 ret = i2c_transfer(c->adapter, msgs, ARRAY_SIZE(msgs)); 327 ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
324 if (ret != ARRAY_SIZE(msgs)) 328 if (ret != ARRAY_SIZE(msgs))
325 v4l_dbg(1, debug, c, "read error\n"); 329 v4l2_dbg(1, debug, sd, "read error\n");
326 330
327 return val; 331 return val;
328} 332}
329 333
330 334
331static void ks0127_write(struct i2c_client *c, u8 reg, u8 val) 335static void ks0127_write(struct v4l2_subdev *sd, u8 reg, u8 val)
332{ 336{
333 struct ks0127 *ks = i2c_get_clientdata(c); 337 struct i2c_client *client = v4l2_get_subdevdata(sd);
338 struct ks0127 *ks = to_ks0127(sd);
334 char msg[] = { reg, val }; 339 char msg[] = { reg, val };
335 340
336 if (i2c_master_send(c, msg, sizeof(msg)) != sizeof(msg)) 341 if (i2c_master_send(client, msg, sizeof(msg)) != sizeof(msg))
337 v4l_dbg(1, debug, c, "write error\n"); 342 v4l2_dbg(1, debug, sd, "write error\n");
338 343
339 ks->regs[reg] = val; 344 ks->regs[reg] = val;
340} 345}
341 346
342 347
343/* generic bit-twiddling */ 348/* generic bit-twiddling */
344static void ks0127_and_or(struct i2c_client *client, u8 reg, u8 and_v, u8 or_v) 349static void ks0127_and_or(struct v4l2_subdev *sd, u8 reg, u8 and_v, u8 or_v)
345{ 350{
346 struct ks0127 *ks = i2c_get_clientdata(client); 351 struct ks0127 *ks = to_ks0127(sd);
347 352
348 u8 val = ks->regs[reg]; 353 u8 val = ks->regs[reg];
349 val = (val & and_v) | or_v; 354 val = (val & and_v) | or_v;
350 ks0127_write(client, reg, val); 355 ks0127_write(sd, reg, val);
351} 356}
352 357
353 358
@@ -355,439 +360,363 @@ static void ks0127_and_or(struct i2c_client *client, u8 reg, u8 and_v, u8 or_v)
355/**************************************************************************** 360/****************************************************************************
356* ks0127 private api 361* ks0127 private api
357****************************************************************************/ 362****************************************************************************/
358static void ks0127_reset(struct i2c_client *c) 363static void ks0127_init(struct v4l2_subdev *sd)
359{ 364{
360 struct ks0127 *ks = i2c_get_clientdata(c); 365 struct ks0127 *ks = to_ks0127(sd);
361 u8 *table = reg_defaults; 366 u8 *table = reg_defaults;
362 int i; 367 int i;
363 368
364 ks->ks_type = KS_TYPE_UNKNOWN; 369 ks->ident = V4L2_IDENT_KS0127;
365 370
366 v4l_dbg(1, debug, c, "reset\n"); 371 v4l2_dbg(1, debug, sd, "reset\n");
367 msleep(1); 372 msleep(1);
368 373
369 /* initialize all registers to known values */ 374 /* initialize all registers to known values */
370 /* (except STAT, 0x21, 0x22, TEST and 0x38,0x39) */ 375 /* (except STAT, 0x21, 0x22, TEST and 0x38,0x39) */
371 376
372 for (i = 1; i < 33; i++) 377 for (i = 1; i < 33; i++)
373 ks0127_write(c, i, table[i]); 378 ks0127_write(sd, i, table[i]);
374 379
375 for (i = 35; i < 40; i++) 380 for (i = 35; i < 40; i++)
376 ks0127_write(c, i, table[i]); 381 ks0127_write(sd, i, table[i]);
377 382
378 for (i = 41; i < 56; i++) 383 for (i = 41; i < 56; i++)
379 ks0127_write(c, i, table[i]); 384 ks0127_write(sd, i, table[i]);
380 385
381 for (i = 58; i < 64; i++) 386 for (i = 58; i < 64; i++)
382 ks0127_write(c, i, table[i]); 387 ks0127_write(sd, i, table[i]);
383 388
384 389
385 if ((ks0127_read(c, KS_STAT) & 0x80) == 0) { 390 if ((ks0127_read(sd, KS_STAT) & 0x80) == 0) {
386 ks->ks_type = KS_TYPE_0122S; 391 ks->ident = V4L2_IDENT_KS0122S;
387 v4l_dbg(1, debug, c, "ks0122s found\n"); 392 v4l2_dbg(1, debug, sd, "ks0122s found\n");
388 return; 393 return;
389 } 394 }
390 395
391 switch (ks0127_read(c, KS_CMDE) & 0x0f) { 396 switch (ks0127_read(sd, KS_CMDE) & 0x0f) {
392 case 0: 397 case 0:
393 ks->ks_type = KS_TYPE_0127; 398 v4l2_dbg(1, debug, sd, "ks0127 found\n");
394 v4l_dbg(1, debug, c, "ks0127 found\n");
395 break; 399 break;
396 400
397 case 9: 401 case 9:
398 ks->ks_type = KS_TYPE_0127B; 402 ks->ident = V4L2_IDENT_KS0127B;
399 v4l_dbg(1, debug, c, "ks0127B Revision A found\n"); 403 v4l2_dbg(1, debug, sd, "ks0127B Revision A found\n");
400 break; 404 break;
401 405
402 default: 406 default:
403 v4l_dbg(1, debug, c, "unknown revision\n"); 407 v4l2_dbg(1, debug, sd, "unknown revision\n");
404 break; 408 break;
405 } 409 }
406} 410}
407 411
408static int ks0127_command(struct i2c_client *c, unsigned cmd, void *arg) 412static int ks0127_s_routing(struct v4l2_subdev *sd, const struct v4l2_routing *route)
409{ 413{
410 struct ks0127 *ks = i2c_get_clientdata(c); 414 struct ks0127 *ks = to_ks0127(sd);
411 int *iarg = (int *)arg; 415
412 int status; 416 switch (route->input) {
413 417 case KS_INPUT_COMPOSITE_1:
414 if (!ks) 418 case KS_INPUT_COMPOSITE_2:
415 return -ENODEV; 419 case KS_INPUT_COMPOSITE_3:
420 case KS_INPUT_COMPOSITE_4:
421 case KS_INPUT_COMPOSITE_5:
422 case KS_INPUT_COMPOSITE_6:
423 v4l2_dbg(1, debug, sd,
424 "s_routing %d: Composite\n", route->input);
425 /* autodetect 50/60 Hz */
426 ks0127_and_or(sd, KS_CMDA, 0xfc, 0x00);
427 /* VSE=0 */
428 ks0127_and_or(sd, KS_CMDA, ~0x40, 0x00);
429 /* set input line */
430 ks0127_and_or(sd, KS_CMDB, 0xb0, route->input);
431 /* non-freerunning mode */
432 ks0127_and_or(sd, KS_CMDC, 0x70, 0x0a);
433 /* analog input */
434 ks0127_and_or(sd, KS_CMDD, 0x03, 0x00);
435 /* enable chroma demodulation */
436 ks0127_and_or(sd, KS_CTRACK, 0xcf, 0x00);
437 /* chroma trap, HYBWR=1 */
438 ks0127_and_or(sd, KS_LUMA, 0x00,
439 (reg_defaults[KS_LUMA])|0x0c);
440 /* scaler fullbw, luma comb off */
441 ks0127_and_or(sd, KS_VERTIA, 0x08, 0x81);
442 /* manual chroma comb .25 .5 .25 */
443 ks0127_and_or(sd, KS_VERTIC, 0x0f, 0x90);
444
445 /* chroma path delay */
446 ks0127_and_or(sd, KS_CHROMB, 0x0f, 0x90);
447
448 ks0127_write(sd, KS_UGAIN, reg_defaults[KS_UGAIN]);
449 ks0127_write(sd, KS_VGAIN, reg_defaults[KS_VGAIN]);
450 ks0127_write(sd, KS_UVOFFH, reg_defaults[KS_UVOFFH]);
451 ks0127_write(sd, KS_UVOFFL, reg_defaults[KS_UVOFFL]);
452 break;
416 453
417 switch (cmd) { 454 case KS_INPUT_SVIDEO_1:
418 case DECODER_INIT: 455 case KS_INPUT_SVIDEO_2:
419 v4l_dbg(1, debug, c, "DECODER_INIT\n"); 456 case KS_INPUT_SVIDEO_3:
420 ks0127_reset(c); 457 v4l2_dbg(1, debug, sd,
458 "s_routing %d: S-Video\n", route->input);
459 /* autodetect 50/60 Hz */
460 ks0127_and_or(sd, KS_CMDA, 0xfc, 0x00);
461 /* VSE=0 */
462 ks0127_and_or(sd, KS_CMDA, ~0x40, 0x00);
463 /* set input line */
464 ks0127_and_or(sd, KS_CMDB, 0xb0, route->input);
465 /* non-freerunning mode */
466 ks0127_and_or(sd, KS_CMDC, 0x70, 0x0a);
467 /* analog input */
468 ks0127_and_or(sd, KS_CMDD, 0x03, 0x00);
469 /* enable chroma demodulation */
470 ks0127_and_or(sd, KS_CTRACK, 0xcf, 0x00);
471 ks0127_and_or(sd, KS_LUMA, 0x00,
472 reg_defaults[KS_LUMA]);
473 /* disable luma comb */
474 ks0127_and_or(sd, KS_VERTIA, 0x08,
475 (reg_defaults[KS_VERTIA]&0xf0)|0x01);
476 ks0127_and_or(sd, KS_VERTIC, 0x0f,
477 reg_defaults[KS_VERTIC]&0xf0);
478
479 ks0127_and_or(sd, KS_CHROMB, 0x0f,
480 reg_defaults[KS_CHROMB]&0xf0);
481
482 ks0127_write(sd, KS_UGAIN, reg_defaults[KS_UGAIN]);
483 ks0127_write(sd, KS_VGAIN, reg_defaults[KS_VGAIN]);
484 ks0127_write(sd, KS_UVOFFH, reg_defaults[KS_UVOFFH]);
485 ks0127_write(sd, KS_UVOFFL, reg_defaults[KS_UVOFFL]);
421 break; 486 break;
422 487
423 case DECODER_SET_INPUT: 488 case KS_INPUT_YUV656:
424 switch(*iarg) { 489 v4l2_dbg(1, debug, sd, "s_routing 15: YUV656\n");
425 case KS_INPUT_COMPOSITE_1: 490 if (ks->norm & V4L2_STD_525_60)
426 case KS_INPUT_COMPOSITE_2: 491 /* force 60 Hz */
427 case KS_INPUT_COMPOSITE_3: 492 ks0127_and_or(sd, KS_CMDA, 0xfc, 0x03);
428 case KS_INPUT_COMPOSITE_4: 493 else
429 case KS_INPUT_COMPOSITE_5: 494 /* force 50 Hz */
430 case KS_INPUT_COMPOSITE_6: 495 ks0127_and_or(sd, KS_CMDA, 0xfc, 0x02);
431 v4l_dbg(1, debug, c, 496
432 "DECODER_SET_INPUT %d: Composite\n", *iarg); 497 ks0127_and_or(sd, KS_CMDA, 0xff, 0x40); /* VSE=1 */
433 /* autodetect 50/60 Hz */ 498 /* set input line and VALIGN */
434 ks0127_and_or(c, KS_CMDA, 0xfc, 0x00); 499 ks0127_and_or(sd, KS_CMDB, 0xb0, (route->input | 0x40));
435 /* VSE=0 */ 500 /* freerunning mode, */
436 ks0127_and_or(c, KS_CMDA, ~0x40, 0x00); 501 /* TSTGEN = 1 TSTGFR=11 TSTGPH=0 TSTGPK=0 VMEM=1*/
437 /* set input line */ 502 ks0127_and_or(sd, KS_CMDC, 0x70, 0x87);
438 ks0127_and_or(c, KS_CMDB, 0xb0, *iarg); 503 /* digital input, SYNDIR = 0 INPSL=01 CLKDIR=0 EAV=0 */
439 /* non-freerunning mode */ 504 ks0127_and_or(sd, KS_CMDD, 0x03, 0x08);
440 ks0127_and_or(c, KS_CMDC, 0x70, 0x0a); 505 /* disable chroma demodulation */
441 /* analog input */ 506 ks0127_and_or(sd, KS_CTRACK, 0xcf, 0x30);
442 ks0127_and_or(c, KS_CMDD, 0x03, 0x00); 507 /* HYPK =01 CTRAP = 0 HYBWR=0 PED=1 RGBH=1 UNIT=1 */
443 /* enable chroma demodulation */ 508 ks0127_and_or(sd, KS_LUMA, 0x00, 0x71);
444 ks0127_and_or(c, KS_CTRACK, 0xcf, 0x00); 509 ks0127_and_or(sd, KS_VERTIC, 0x0f,
445 /* chroma trap, HYBWR=1 */ 510 reg_defaults[KS_VERTIC]&0xf0);
446 ks0127_and_or(c, KS_LUMA, 0x00, 511
447 (reg_defaults[KS_LUMA])|0x0c); 512 /* scaler fullbw, luma comb off */
448 /* scaler fullbw, luma comb off */ 513 ks0127_and_or(sd, KS_VERTIA, 0x08, 0x81);
449 ks0127_and_or(c, KS_VERTIA, 0x08, 0x81); 514
450 /* manual chroma comb .25 .5 .25 */ 515 ks0127_and_or(sd, KS_CHROMB, 0x0f,
451 ks0127_and_or(c, KS_VERTIC, 0x0f, 0x90); 516 reg_defaults[KS_CHROMB]&0xf0);
452 517
453 /* chroma path delay */ 518 ks0127_and_or(sd, KS_CON, 0x00, 0x00);
454 ks0127_and_or(c, KS_CHROMB, 0x0f, 0x90); 519 ks0127_and_or(sd, KS_BRT, 0x00, 32); /* spec: 34 */
455 520 /* spec: 229 (e5) */
456 ks0127_write(c, KS_UGAIN, reg_defaults[KS_UGAIN]); 521 ks0127_and_or(sd, KS_SAT, 0x00, 0xe8);
457 ks0127_write(c, KS_VGAIN, reg_defaults[KS_VGAIN]); 522 ks0127_and_or(sd, KS_HUE, 0x00, 0);
458 ks0127_write(c, KS_UVOFFH, reg_defaults[KS_UVOFFH]); 523
459 ks0127_write(c, KS_UVOFFL, reg_defaults[KS_UVOFFL]); 524 ks0127_and_or(sd, KS_UGAIN, 0x00, 238);
460 break; 525 ks0127_and_or(sd, KS_VGAIN, 0x00, 0x00);
461 526
462 case KS_INPUT_SVIDEO_1: 527 /*UOFF:0x30, VOFF:0x30, TSTCGN=1 */
463 case KS_INPUT_SVIDEO_2: 528 ks0127_and_or(sd, KS_UVOFFH, 0x00, 0x4f);
464 case KS_INPUT_SVIDEO_3: 529 ks0127_and_or(sd, KS_UVOFFL, 0x00, 0x00);
465 v4l_dbg(1, debug, c,
466 "DECODER_SET_INPUT %d: S-Video\n", *iarg);
467 /* autodetect 50/60 Hz */
468 ks0127_and_or(c, KS_CMDA, 0xfc, 0x00);
469 /* VSE=0 */
470 ks0127_and_or(c, KS_CMDA, ~0x40, 0x00);
471 /* set input line */
472 ks0127_and_or(c, KS_CMDB, 0xb0, *iarg);
473 /* non-freerunning mode */
474 ks0127_and_or(c, KS_CMDC, 0x70, 0x0a);
475 /* analog input */
476 ks0127_and_or(c, KS_CMDD, 0x03, 0x00);
477 /* enable chroma demodulation */
478 ks0127_and_or(c, KS_CTRACK, 0xcf, 0x00);
479 ks0127_and_or(c, KS_LUMA, 0x00,
480 reg_defaults[KS_LUMA]);
481 /* disable luma comb */
482 ks0127_and_or(c, KS_VERTIA, 0x08,
483 (reg_defaults[KS_VERTIA]&0xf0)|0x01);
484 ks0127_and_or(c, KS_VERTIC, 0x0f,
485 reg_defaults[KS_VERTIC]&0xf0);
486
487 ks0127_and_or(c, KS_CHROMB, 0x0f,
488 reg_defaults[KS_CHROMB]&0xf0);
489
490 ks0127_write(c, KS_UGAIN, reg_defaults[KS_UGAIN]);
491 ks0127_write(c, KS_VGAIN, reg_defaults[KS_VGAIN]);
492 ks0127_write(c, KS_UVOFFH, reg_defaults[KS_UVOFFH]);
493 ks0127_write(c, KS_UVOFFL, reg_defaults[KS_UVOFFL]);
494 break;
495
496 case KS_INPUT_YUV656:
497 v4l_dbg(1, debug, c,
498 "DECODER_SET_INPUT 15: YUV656\n");
499 if (ks->norm == VIDEO_MODE_NTSC ||
500 ks->norm == KS_STD_PAL_M)
501 /* force 60 Hz */
502 ks0127_and_or(c, KS_CMDA, 0xfc, 0x03);
503 else
504 /* force 50 Hz */
505 ks0127_and_or(c, KS_CMDA, 0xfc, 0x02);
506
507 ks0127_and_or(c, KS_CMDA, 0xff, 0x40); /* VSE=1 */
508 /* set input line and VALIGN */
509 ks0127_and_or(c, KS_CMDB, 0xb0, (*iarg | 0x40));
510 /* freerunning mode, */
511 /* TSTGEN = 1 TSTGFR=11 TSTGPH=0 TSTGPK=0 VMEM=1*/
512 ks0127_and_or(c, KS_CMDC, 0x70, 0x87);
513 /* digital input, SYNDIR = 0 INPSL=01 CLKDIR=0 EAV=0 */
514 ks0127_and_or(c, KS_CMDD, 0x03, 0x08);
515 /* disable chroma demodulation */
516 ks0127_and_or(c, KS_CTRACK, 0xcf, 0x30);
517 /* HYPK =01 CTRAP = 0 HYBWR=0 PED=1 RGBH=1 UNIT=1 */
518 ks0127_and_or(c, KS_LUMA, 0x00, 0x71);
519 ks0127_and_or(c, KS_VERTIC, 0x0f,
520 reg_defaults[KS_VERTIC]&0xf0);
521
522 /* scaler fullbw, luma comb off */
523 ks0127_and_or(c, KS_VERTIA, 0x08, 0x81);
524
525 ks0127_and_or(c, KS_CHROMB, 0x0f,
526 reg_defaults[KS_CHROMB]&0xf0);
527
528 ks0127_and_or(c, KS_CON, 0x00, 0x00);
529 ks0127_and_or(c, KS_BRT, 0x00, 32); /* spec: 34 */
530 /* spec: 229 (e5) */
531 ks0127_and_or(c, KS_SAT, 0x00, 0xe8);
532 ks0127_and_or(c, KS_HUE, 0x00, 0);
533
534 ks0127_and_or(c, KS_UGAIN, 0x00, 238);
535 ks0127_and_or(c, KS_VGAIN, 0x00, 0x00);
536
537 /*UOFF:0x30, VOFF:0x30, TSTCGN=1 */
538 ks0127_and_or(c, KS_UVOFFH, 0x00, 0x4f);
539 ks0127_and_or(c, KS_UVOFFL, 0x00, 0x00);
540 break;
541
542 default:
543 v4l_dbg(1, debug, c,
544 "DECODER_SET_INPUT: Unknown input %d\n", *iarg);
545 break;
546 }
547
548 /* hack: CDMLPF sometimes spontaneously switches on; */
549 /* force back off */
550 ks0127_write(c, KS_DEMOD, reg_defaults[KS_DEMOD]);
551 break; 530 break;
552 531
553 case DECODER_SET_OUTPUT: 532 default:
554 switch(*iarg) { 533 v4l2_dbg(1, debug, sd,
555 case KS_OUTPUT_YUV656E: 534 "s_routing: Unknown input %d\n", route->input);
556 v4l_dbg(1, debug, c,
557 "DECODER_SET_OUTPUT: OUTPUT_YUV656E (Missing)\n");
558 return -EINVAL;
559
560 case KS_OUTPUT_EXV:
561 v4l_dbg(1, debug, c,
562 "DECODER_SET_OUTPUT: OUTPUT_EXV\n");
563 ks0127_and_or(c, KS_OFMTA, 0xf0, 0x09);
564 break;
565 }
566 break; 535 break;
536 }
567 537
568 case DECODER_SET_NORM: /* sam This block mixes old and new norm names... */ 538 /* hack: CDMLPF sometimes spontaneously switches on; */
569 /* Set to automatic SECAM/Fsc mode */ 539 /* force back off */
570 ks0127_and_or(c, KS_DEMOD, 0xf0, 0x00); 540 ks0127_write(sd, KS_DEMOD, reg_defaults[KS_DEMOD]);
571 541 return 0;
572 ks->norm = *iarg; 542}
573 switch (*iarg) {
574 /* this is untested !! */
575 /* It just detects PAL_N/NTSC_M (no special frequencies) */
576 /* And you have to set the standard a second time afterwards */
577 case VIDEO_MODE_AUTO:
578 v4l_dbg(1, debug, c,
579 "DECODER_SET_NORM: AUTO\n");
580
581 /* The chip determines the format */
582 /* based on the current field rate */
583 ks0127_and_or(c, KS_CMDA, 0xfc, 0x00);
584 ks0127_and_or(c, KS_CHROMA, 0x9f, 0x20);
585 /* This is wrong for PAL ! As I said, */
586 /* you need to set the standard once again !! */
587 ks->format_height = 240;
588 ks->format_width = 704;
589 break;
590
591 case VIDEO_MODE_NTSC:
592 v4l_dbg(1, debug, c,
593 "DECODER_SET_NORM: NTSC_M\n");
594 ks0127_and_or(c, KS_CHROMA, 0x9f, 0x20);
595 ks->format_height = 240;
596 ks->format_width = 704;
597 break;
598
599 case KS_STD_NTSC_N:
600 v4l_dbg(1, debug, c,
601 "KS0127_SET_NORM: NTSC_N (fixme)\n");
602 ks0127_and_or(c, KS_CHROMA, 0x9f, 0x40);
603 ks->format_height = 240;
604 ks->format_width = 704;
605 break;
606
607 case VIDEO_MODE_PAL:
608 v4l_dbg(1, debug, c,
609 "DECODER_SET_NORM: PAL_N\n");
610 ks0127_and_or(c, KS_CHROMA, 0x9f, 0x20);
611 ks->format_height = 290;
612 ks->format_width = 704;
613 break;
614
615 case KS_STD_PAL_M:
616 v4l_dbg(1, debug, c,
617 "KS0127_SET_NORM: PAL_M (fixme)\n");
618 ks0127_and_or(c, KS_CHROMA, 0x9f, 0x40);
619 ks->format_height = 290;
620 ks->format_width = 704;
621 break;
622
623 case VIDEO_MODE_SECAM:
624 v4l_dbg(1, debug, c,
625 "KS0127_SET_NORM: SECAM\n");
626 ks->format_height = 290;
627 ks->format_width = 704;
628
629 /* set to secam autodetection */
630 ks0127_and_or(c, KS_CHROMA, 0xdf, 0x20);
631 ks0127_and_or(c, KS_DEMOD, 0xf0, 0x00);
632 schedule_timeout_interruptible(HZ/10+1);
633
634 /* did it autodetect? */
635 if (ks0127_read(c, KS_DEMOD) & 0x40)
636 break;
637 543
544static int ks0127_s_std(struct v4l2_subdev *sd, v4l2_std_id std)
545{
546 struct ks0127 *ks = to_ks0127(sd);
547
548 /* Set to automatic SECAM/Fsc mode */
549 ks0127_and_or(sd, KS_DEMOD, 0xf0, 0x00);
550
551 ks->norm = std;
552 if (std & V4L2_STD_NTSC) {
553 v4l2_dbg(1, debug, sd,
554 "s_std: NTSC_M\n");
555 ks0127_and_or(sd, KS_CHROMA, 0x9f, 0x20);
556 } else if (std & V4L2_STD_PAL_N) {
557 v4l2_dbg(1, debug, sd,
558 "s_std: NTSC_N (fixme)\n");
559 ks0127_and_or(sd, KS_CHROMA, 0x9f, 0x40);
560 } else if (std & V4L2_STD_PAL) {
561 v4l2_dbg(1, debug, sd,
562 "s_std: PAL_N\n");
563 ks0127_and_or(sd, KS_CHROMA, 0x9f, 0x20);
564 } else if (std & V4L2_STD_PAL_M) {
565 v4l2_dbg(1, debug, sd,
566 "s_std: PAL_M (fixme)\n");
567 ks0127_and_or(sd, KS_CHROMA, 0x9f, 0x40);
568 } else if (std & V4L2_STD_SECAM) {
569 v4l2_dbg(1, debug, sd,
570 "s_std: SECAM\n");
571
572 /* set to secam autodetection */
573 ks0127_and_or(sd, KS_CHROMA, 0xdf, 0x20);
574 ks0127_and_or(sd, KS_DEMOD, 0xf0, 0x00);
575 schedule_timeout_interruptible(HZ/10+1);
576
577 /* did it autodetect? */
578 if (!(ks0127_read(sd, KS_DEMOD) & 0x40))
638 /* force to secam mode */ 579 /* force to secam mode */
639 ks0127_and_or(c, KS_DEMOD, 0xf0, 0x0f); 580 ks0127_and_or(sd, KS_DEMOD, 0xf0, 0x0f);
640 break; 581 } else {
641 582 v4l2_dbg(1, debug, sd, "s_std: Unknown norm %llx\n",
642 default: 583 (unsigned long long)std);
643 v4l_dbg(1, debug, c,
644 "DECODER_SET_NORM: Unknown norm %d\n", *iarg);
645 break;
646 }
647 break;
648
649 case DECODER_SET_PICTURE:
650 v4l_dbg(1, debug, c,
651 "DECODER_SET_PICTURE: not yet supported\n");
652 return -EINVAL;
653
654 /* sam todo: KS0127_SET_BRIGHTNESS: Merge into DECODER_SET_PICTURE */
655 /* sam todo: KS0127_SET_CONTRAST: Merge into DECODER_SET_PICTURE */
656 /* sam todo: KS0127_SET_HUE: Merge into DECODER_SET_PICTURE? */
657 /* sam todo: KS0127_SET_SATURATION: Merge into DECODER_SET_PICTURE */
658 /* sam todo: KS0127_SET_AGC_MODE: */
659 /* sam todo: KS0127_SET_AGC: */
660 /* sam todo: KS0127_SET_CHROMA_MODE: */
661 /* sam todo: KS0127_SET_PIXCLK_MODE: */
662 /* sam todo: KS0127_SET_GAMMA_MODE: */
663 /* sam todo: KS0127_SET_UGAIN: */
664 /* sam todo: KS0127_SET_VGAIN: */
665 /* sam todo: KS0127_SET_INVALY: */
666 /* sam todo: KS0127_SET_INVALU: */
667 /* sam todo: KS0127_SET_INVALV: */
668 /* sam todo: KS0127_SET_UNUSEY: */
669 /* sam todo: KS0127_SET_UNUSEU: */
670 /* sam todo: KS0127_SET_UNUSEV: */
671 /* sam todo: KS0127_SET_VSALIGN_MODE: */
672
673 case DECODER_ENABLE_OUTPUT:
674 {
675 int enable;
676
677 iarg = arg;
678 enable = (*iarg != 0);
679 if (enable) {
680 v4l_dbg(1, debug, c,
681 "DECODER_ENABLE_OUTPUT on\n");
682 /* All output pins on */
683 ks0127_and_or(c, KS_OFMTA, 0xcf, 0x30);
684 /* Obey the OEN pin */
685 ks0127_and_or(c, KS_CDEM, 0x7f, 0x00);
686 } else {
687 v4l_dbg(1, debug, c,
688 "DECODER_ENABLE_OUTPUT off\n");
689 /* Video output pins off */
690 ks0127_and_or(c, KS_OFMTA, 0xcf, 0x00);
691 /* Ignore the OEN pin */
692 ks0127_and_or(c, KS_CDEM, 0x7f, 0x80);
693 }
694 break;
695 } 584 }
585 return 0;
586}
696 587
697 /* sam todo: KS0127_SET_OUTPUT_MODE: */ 588static int ks0127_s_stream(struct v4l2_subdev *sd, int enable)
698 /* sam todo: KS0127_SET_WIDTH: */ 589{
699 /* sam todo: KS0127_SET_HEIGHT: */ 590 v4l2_dbg(1, debug, sd, "s_stream(%d)\n", enable);
700 /* sam todo: KS0127_SET_HSCALE: */ 591 if (enable) {
701 592 /* All output pins on */
702 case DECODER_GET_STATUS: 593 ks0127_and_or(sd, KS_OFMTA, 0xcf, 0x30);
703 v4l_dbg(1, debug, c, "DECODER_GET_STATUS\n"); 594 /* Obey the OEN pin */
704 *iarg = 0; 595 ks0127_and_or(sd, KS_CDEM, 0x7f, 0x00);
705 status = ks0127_read(c, KS_STAT); 596 } else {
706 if (!(status & 0x20)) /* NOVID not set */ 597 /* Video output pins off */
707 *iarg = (*iarg | DECODER_STATUS_GOOD); 598 ks0127_and_or(sd, KS_OFMTA, 0xcf, 0x00);
708 if ((status & 0x01)) /* CLOCK set */ 599 /* Ignore the OEN pin */
709 *iarg = (*iarg | DECODER_STATUS_COLOR); 600 ks0127_and_or(sd, KS_CDEM, 0x7f, 0x80);
710 if ((status & 0x08)) /* PALDET set */
711 *iarg = (*iarg | DECODER_STATUS_PAL);
712 else
713 *iarg = (*iarg | DECODER_STATUS_NTSC);
714 break;
715
716 /* Catch any unknown command */
717 default:
718 v4l_dbg(1, debug, c, "unknown: 0x%08x\n", cmd);
719 return -EINVAL;
720 } 601 }
721 return 0; 602 return 0;
722} 603}
723 604
605static int ks0127_status(struct v4l2_subdev *sd, u32 *pstatus, v4l2_std_id *pstd)
606{
607 int stat = V4L2_IN_ST_NO_SIGNAL;
608 u8 status;
609 v4l2_std_id std = V4L2_STD_ALL;
610
611 status = ks0127_read(sd, KS_STAT);
612 if (!(status & 0x20)) /* NOVID not set */
613 stat = 0;
614 if (!(status & 0x01)) /* CLOCK set */
615 stat |= V4L2_IN_ST_NO_COLOR;
616 if ((status & 0x08)) /* PALDET set */
617 std = V4L2_STD_PAL;
618 else
619 std = V4L2_STD_NTSC;
620 if (pstd)
621 *pstd = std;
622 if (pstatus)
623 *pstatus = stat;
624 return 0;
625}
626
627static int ks0127_querystd(struct v4l2_subdev *sd, v4l2_std_id *std)
628{
629 v4l2_dbg(1, debug, sd, "querystd\n");
630 return ks0127_status(sd, NULL, std);
631}
724 632
725/* Addresses to scan */ 633static int ks0127_g_input_status(struct v4l2_subdev *sd, u32 *status)
726#define I2C_KS0127_ADDON 0xD8 634{
727#define I2C_KS0127_ONBOARD 0xDA 635 v4l2_dbg(1, debug, sd, "g_input_status\n");
636 return ks0127_status(sd, status, NULL);
637}
638
639static int ks0127_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
640{
641 struct i2c_client *client = v4l2_get_subdevdata(sd);
642 struct ks0127 *ks = to_ks0127(sd);
643
644 return v4l2_chip_ident_i2c_client(client, chip, ks->ident, 0);
645}
646
647/* ----------------------------------------------------------------------- */
728 648
729static unsigned short normal_i2c[] = { 649static const struct v4l2_subdev_core_ops ks0127_core_ops = {
730 I2C_KS0127_ADDON >> 1, 650 .g_chip_ident = ks0127_g_chip_ident,
731 I2C_KS0127_ONBOARD >> 1,
732 I2C_CLIENT_END
733}; 651};
734 652
735I2C_CLIENT_INSMOD; 653static const struct v4l2_subdev_tuner_ops ks0127_tuner_ops = {
654 .s_std = ks0127_s_std,
655};
656
657static const struct v4l2_subdev_video_ops ks0127_video_ops = {
658 .s_routing = ks0127_s_routing,
659 .s_stream = ks0127_s_stream,
660 .querystd = ks0127_querystd,
661 .g_input_status = ks0127_g_input_status,
662};
663
664static const struct v4l2_subdev_ops ks0127_ops = {
665 .core = &ks0127_core_ops,
666 .tuner = &ks0127_tuner_ops,
667 .video = &ks0127_video_ops,
668};
669
670/* ----------------------------------------------------------------------- */
671
736 672
737static int ks0127_probe(struct i2c_client *c, const struct i2c_device_id *id) 673static int ks0127_probe(struct i2c_client *client, const struct i2c_device_id *id)
738{ 674{
739 struct ks0127 *ks; 675 struct ks0127 *ks;
676 struct v4l2_subdev *sd;
740 677
741 v4l_info(c, "%s chip found @ 0x%x (%s)\n", 678 v4l_info(client, "%s chip found @ 0x%x (%s)\n",
742 c->addr == (I2C_KS0127_ADDON >> 1) ? "addon" : "on-board", 679 client->addr == (I2C_KS0127_ADDON >> 1) ? "addon" : "on-board",
743 c->addr << 1, c->adapter->name); 680 client->addr << 1, client->adapter->name);
744 681
745 ks = kzalloc(sizeof(*ks), GFP_KERNEL); 682 ks = kzalloc(sizeof(*ks), GFP_KERNEL);
746 if (ks == NULL) 683 if (ks == NULL)
747 return -ENOMEM; 684 return -ENOMEM;
748 685 sd = &ks->sd;
749 i2c_set_clientdata(c, ks); 686 v4l2_i2c_subdev_init(sd, client, &ks0127_ops);
750
751 ks->ks_type = KS_TYPE_UNKNOWN;
752 687
753 /* power up */ 688 /* power up */
754 init_reg_defaults(); 689 init_reg_defaults();
755 ks0127_write(c, KS_CMDA, 0x2c); 690 ks0127_write(sd, KS_CMDA, 0x2c);
756 mdelay(10); 691 mdelay(10);
757 692
758 /* reset the device */ 693 /* reset the device */
759 ks0127_reset(c); 694 ks0127_init(sd);
760 return 0; 695 return 0;
761} 696}
762 697
763static int ks0127_remove(struct i2c_client *c) 698static int ks0127_remove(struct i2c_client *client)
764{ 699{
765 struct ks0127 *ks = i2c_get_clientdata(c); 700 struct v4l2_subdev *sd = i2c_get_clientdata(client);
766
767 ks0127_write(c, KS_OFMTA, 0x20); /* tristate */
768 ks0127_write(c, KS_CMDA, 0x2c | 0x80); /* power down */
769 701
770 kfree(ks); 702 v4l2_device_unregister_subdev(sd);
703 ks0127_write(sd, KS_OFMTA, 0x20); /* tristate */
704 ks0127_write(sd, KS_CMDA, 0x2c | 0x80); /* power down */
705 kfree(to_ks0127(sd));
771 return 0; 706 return 0;
772} 707}
773 708
774static int ks0127_legacy_probe(struct i2c_adapter *adapter)
775{
776 return adapter->id == I2C_HW_B_ZR36067;
777}
778
779static const struct i2c_device_id ks0127_id[] = { 709static const struct i2c_device_id ks0127_id[] = {
780 { "ks0127", 0 }, 710 { "ks0127", 0 },
711 { "ks0127b", 0 },
712 { "ks0122s", 0 },
781 { } 713 { }
782}; 714};
783MODULE_DEVICE_TABLE(i2c, ks0127_id); 715MODULE_DEVICE_TABLE(i2c, ks0127_id);
784 716
785static struct v4l2_i2c_driver_data v4l2_i2c_data = { 717static struct v4l2_i2c_driver_data v4l2_i2c_data = {
786 .name = "ks0127", 718 .name = "ks0127",
787 .driverid = I2C_DRIVERID_KS0127,
788 .command = ks0127_command,
789 .probe = ks0127_probe, 719 .probe = ks0127_probe,
790 .remove = ks0127_remove, 720 .remove = ks0127_remove,
791 .legacy_probe = ks0127_legacy_probe,
792 .id_table = ks0127_id, 721 .id_table = ks0127_id,
793}; 722};
diff --git a/drivers/media/video/ks0127.h b/drivers/media/video/ks0127.h
index 1ec578833aea..cb8abd5403b3 100644
--- a/drivers/media/video/ks0127.h
+++ b/drivers/media/video/ks0127.h
@@ -24,8 +24,6 @@
24#ifndef KS0127_H 24#ifndef KS0127_H
25#define KS0127_H 25#define KS0127_H
26 26
27#include <linux/videodev.h>
28
29/* input channels */ 27/* input channels */
30#define KS_INPUT_COMPOSITE_1 0 28#define KS_INPUT_COMPOSITE_1 0
31#define KS_INPUT_COMPOSITE_2 1 29#define KS_INPUT_COMPOSITE_2 1
diff --git a/drivers/media/video/m52790.c b/drivers/media/video/m52790.c
index de397ef57b44..1f340fefc49d 100644
--- a/drivers/media/video/m52790.c
+++ b/drivers/media/video/m52790.c
@@ -132,11 +132,6 @@ static int m52790_log_status(struct v4l2_subdev *sd)
132 return 0; 132 return 0;
133} 133}
134 134
135static int m52790_command(struct i2c_client *client, unsigned cmd, void *arg)
136{
137 return v4l2_subdev_command(i2c_get_clientdata(client), cmd, arg);
138}
139
140/* ----------------------------------------------------------------------- */ 135/* ----------------------------------------------------------------------- */
141 136
142static const struct v4l2_subdev_core_ops m52790_core_ops = { 137static const struct v4l2_subdev_core_ops m52790_core_ops = {
@@ -210,8 +205,6 @@ MODULE_DEVICE_TABLE(i2c, m52790_id);
210 205
211static struct v4l2_i2c_driver_data v4l2_i2c_data = { 206static struct v4l2_i2c_driver_data v4l2_i2c_data = {
212 .name = "m52790", 207 .name = "m52790",
213 .driverid = I2C_DRIVERID_M52790,
214 .command = m52790_command,
215 .probe = m52790_probe, 208 .probe = m52790_probe,
216 .remove = m52790_remove, 209 .remove = m52790_remove,
217 .id_table = m52790_id, 210 .id_table = m52790_id,
diff --git a/drivers/media/video/meye.c b/drivers/media/video/meye.c
index b76e33d5c867..2ad11f0999c6 100644
--- a/drivers/media/video/meye.c
+++ b/drivers/media/video/meye.c
@@ -1017,7 +1017,6 @@ static int meyeioc_stilljcapt(int *len)
1017static int vidioc_querycap(struct file *file, void *fh, 1017static int vidioc_querycap(struct file *file, void *fh,
1018 struct v4l2_capability *cap) 1018 struct v4l2_capability *cap)
1019{ 1019{
1020 memset(cap, 0, sizeof(*cap));
1021 strcpy(cap->driver, "meye"); 1020 strcpy(cap->driver, "meye");
1022 strcpy(cap->card, "meye"); 1021 strcpy(cap->card, "meye");
1023 sprintf(cap->bus_info, "PCI:%s", pci_name(meye.mchip_dev)); 1022 sprintf(cap->bus_info, "PCI:%s", pci_name(meye.mchip_dev));
@@ -1036,8 +1035,6 @@ static int vidioc_enum_input(struct file *file, void *fh, struct v4l2_input *i)
1036 if (i->index != 0) 1035 if (i->index != 0)
1037 return -EINVAL; 1036 return -EINVAL;
1038 1037
1039 memset(i, 0, sizeof(*i));
1040 i->index = 0;
1041 strcpy(i->name, "Camera"); 1038 strcpy(i->name, "Camera");
1042 i->type = V4L2_INPUT_TYPE_CAMERA; 1039 i->type = V4L2_INPUT_TYPE_CAMERA;
1043 1040
@@ -1259,22 +1256,13 @@ static int vidioc_enum_fmt_vid_cap(struct file *file, void *fh,
1259 if (f->index > 1) 1256 if (f->index > 1)
1260 return -EINVAL; 1257 return -EINVAL;
1261 1258
1262 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1263 return -EINVAL;
1264
1265 if (f->index == 0) { 1259 if (f->index == 0) {
1266 /* standard YUV 422 capture */ 1260 /* standard YUV 422 capture */
1267 memset(f, 0, sizeof(*f));
1268 f->index = 0;
1269 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1270 f->flags = 0; 1261 f->flags = 0;
1271 strcpy(f->description, "YUV422"); 1262 strcpy(f->description, "YUV422");
1272 f->pixelformat = V4L2_PIX_FMT_YUYV; 1263 f->pixelformat = V4L2_PIX_FMT_YUYV;
1273 } else { 1264 } else {
1274 /* compressed MJPEG capture */ 1265 /* compressed MJPEG capture */
1275 memset(f, 0, sizeof(*f));
1276 f->index = 1;
1277 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1278 f->flags = V4L2_FMT_FLAG_COMPRESSED; 1266 f->flags = V4L2_FMT_FLAG_COMPRESSED;
1279 strcpy(f->description, "MJPEG"); 1267 strcpy(f->description, "MJPEG");
1280 f->pixelformat = V4L2_PIX_FMT_MJPEG; 1268 f->pixelformat = V4L2_PIX_FMT_MJPEG;
@@ -1286,9 +1274,6 @@ static int vidioc_enum_fmt_vid_cap(struct file *file, void *fh,
1286static int vidioc_try_fmt_vid_cap(struct file *file, void *fh, 1274static int vidioc_try_fmt_vid_cap(struct file *file, void *fh,
1287 struct v4l2_format *f) 1275 struct v4l2_format *f)
1288{ 1276{
1289 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1290 return -EINVAL;
1291
1292 if (f->fmt.pix.pixelformat != V4L2_PIX_FMT_YUYV && 1277 if (f->fmt.pix.pixelformat != V4L2_PIX_FMT_YUYV &&
1293 f->fmt.pix.pixelformat != V4L2_PIX_FMT_MJPEG) 1278 f->fmt.pix.pixelformat != V4L2_PIX_FMT_MJPEG)
1294 return -EINVAL; 1279 return -EINVAL;
@@ -1319,12 +1304,6 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *fh,
1319static int vidioc_g_fmt_vid_cap(struct file *file, void *fh, 1304static int vidioc_g_fmt_vid_cap(struct file *file, void *fh,
1320 struct v4l2_format *f) 1305 struct v4l2_format *f)
1321{ 1306{
1322 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1323 return -EINVAL;
1324
1325 memset(&f->fmt.pix, 0, sizeof(struct v4l2_pix_format));
1326 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1327
1328 switch (meye.mchip_mode) { 1307 switch (meye.mchip_mode) {
1329 case MCHIP_HIC_MODE_CONT_OUT: 1308 case MCHIP_HIC_MODE_CONT_OUT:
1330 default: 1309 default:
@@ -1341,8 +1320,6 @@ static int vidioc_g_fmt_vid_cap(struct file *file, void *fh,
1341 f->fmt.pix.bytesperline = f->fmt.pix.width * 2; 1320 f->fmt.pix.bytesperline = f->fmt.pix.width * 2;
1342 f->fmt.pix.sizeimage = f->fmt.pix.height * 1321 f->fmt.pix.sizeimage = f->fmt.pix.height *
1343 f->fmt.pix.bytesperline; 1322 f->fmt.pix.bytesperline;
1344 f->fmt.pix.colorspace = 0;
1345 f->fmt.pix.priv = 0;
1346 1323
1347 return 0; 1324 return 0;
1348} 1325}
@@ -1350,9 +1327,6 @@ static int vidioc_g_fmt_vid_cap(struct file *file, void *fh,
1350static int vidioc_s_fmt_vid_cap(struct file *file, void *fh, 1327static int vidioc_s_fmt_vid_cap(struct file *file, void *fh,
1351 struct v4l2_format *f) 1328 struct v4l2_format *f)
1352{ 1329{
1353 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1354 return -EINVAL;
1355
1356 if (f->fmt.pix.pixelformat != V4L2_PIX_FMT_YUYV && 1330 if (f->fmt.pix.pixelformat != V4L2_PIX_FMT_YUYV &&
1357 f->fmt.pix.pixelformat != V4L2_PIX_FMT_MJPEG) 1331 f->fmt.pix.pixelformat != V4L2_PIX_FMT_MJPEG)
1358 return -EINVAL; 1332 return -EINVAL;
@@ -1398,9 +1372,6 @@ static int vidioc_reqbufs(struct file *file, void *fh,
1398{ 1372{
1399 int i; 1373 int i;
1400 1374
1401 if (req->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1402 return -EINVAL;
1403
1404 if (req->memory != V4L2_MEMORY_MMAP) 1375 if (req->memory != V4L2_MEMORY_MMAP)
1405 return -EINVAL; 1376 return -EINVAL;
1406 1377
@@ -1441,15 +1412,11 @@ static int vidioc_reqbufs(struct file *file, void *fh,
1441 1412
1442static int vidioc_querybuf(struct file *file, void *fh, struct v4l2_buffer *buf) 1413static int vidioc_querybuf(struct file *file, void *fh, struct v4l2_buffer *buf)
1443{ 1414{
1444 int index = buf->index; 1415 unsigned int index = buf->index;
1445 1416
1446 if (index < 0 || index >= gbuffers) 1417 if (index >= gbuffers)
1447 return -EINVAL; 1418 return -EINVAL;
1448 1419
1449 memset(buf, 0, sizeof(*buf));
1450
1451 buf->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1452 buf->index = index;
1453 buf->bytesused = meye.grab_buffer[index].size; 1420 buf->bytesused = meye.grab_buffer[index].size;
1454 buf->flags = V4L2_BUF_FLAG_MAPPED; 1421 buf->flags = V4L2_BUF_FLAG_MAPPED;
1455 1422
@@ -1471,13 +1438,10 @@ static int vidioc_querybuf(struct file *file, void *fh, struct v4l2_buffer *buf)
1471 1438
1472static int vidioc_qbuf(struct file *file, void *fh, struct v4l2_buffer *buf) 1439static int vidioc_qbuf(struct file *file, void *fh, struct v4l2_buffer *buf)
1473{ 1440{
1474 if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1475 return -EINVAL;
1476
1477 if (buf->memory != V4L2_MEMORY_MMAP) 1441 if (buf->memory != V4L2_MEMORY_MMAP)
1478 return -EINVAL; 1442 return -EINVAL;
1479 1443
1480 if (buf->index < 0 || buf->index >= gbuffers) 1444 if (buf->index >= gbuffers)
1481 return -EINVAL; 1445 return -EINVAL;
1482 1446
1483 if (meye.grab_buffer[buf->index].state != MEYE_BUF_UNUSED) 1447 if (meye.grab_buffer[buf->index].state != MEYE_BUF_UNUSED)
@@ -1497,9 +1461,6 @@ static int vidioc_dqbuf(struct file *file, void *fh, struct v4l2_buffer *buf)
1497{ 1461{
1498 int reqnr; 1462 int reqnr;
1499 1463
1500 if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1501 return -EINVAL;
1502
1503 if (buf->memory != V4L2_MEMORY_MMAP) 1464 if (buf->memory != V4L2_MEMORY_MMAP)
1504 return -EINVAL; 1465 return -EINVAL;
1505 1466
diff --git a/drivers/media/video/msp3400-driver.c b/drivers/media/video/msp3400-driver.c
index 4d7a91852117..9e8e06cfe5c6 100644
--- a/drivers/media/video/msp3400-driver.c
+++ b/drivers/media/video/msp3400-driver.c
@@ -366,29 +366,6 @@ int msp_sleep(struct msp_state *state, int timeout)
366} 366}
367 367
368/* ------------------------------------------------------------------------ */ 368/* ------------------------------------------------------------------------ */
369#ifdef CONFIG_VIDEO_ALLOW_V4L1
370static int msp_mode_v4l2_to_v4l1(int rxsubchans, int audmode)
371{
372 if (rxsubchans == V4L2_TUNER_SUB_MONO)
373 return VIDEO_SOUND_MONO;
374 if (rxsubchans == V4L2_TUNER_SUB_STEREO)
375 return VIDEO_SOUND_STEREO;
376 if (audmode == V4L2_TUNER_MODE_LANG2)
377 return VIDEO_SOUND_LANG2;
378 return VIDEO_SOUND_LANG1;
379}
380
381static int msp_mode_v4l1_to_v4l2(int mode)
382{
383 if (mode & VIDEO_SOUND_STEREO)
384 return V4L2_TUNER_MODE_STEREO;
385 if (mode & VIDEO_SOUND_LANG2)
386 return V4L2_TUNER_MODE_LANG2;
387 if (mode & VIDEO_SOUND_LANG1)
388 return V4L2_TUNER_MODE_LANG1;
389 return V4L2_TUNER_MODE_MONO;
390}
391#endif
392 369
393static int msp_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 370static int msp_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
394{ 371{
@@ -482,96 +459,6 @@ static int msp_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
482 return 0; 459 return 0;
483} 460}
484 461
485#ifdef CONFIG_VIDEO_ALLOW_V4L1
486static long msp_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
487{
488 struct msp_state *state = to_state(sd);
489 struct i2c_client *client = v4l2_get_subdevdata(sd);
490
491 switch (cmd) {
492 /* --- v4l ioctls --- */
493 /* take care: bttv does userspace copying, we'll get a
494 kernel pointer here... */
495 case VIDIOCGAUDIO:
496 {
497 struct video_audio *va = arg;
498
499 va->flags |= VIDEO_AUDIO_VOLUME | VIDEO_AUDIO_MUTABLE;
500 if (state->has_sound_processing)
501 va->flags |= VIDEO_AUDIO_BALANCE |
502 VIDEO_AUDIO_BASS |
503 VIDEO_AUDIO_TREBLE;
504 if (state->muted)
505 va->flags |= VIDEO_AUDIO_MUTE;
506 va->volume = state->volume;
507 va->balance = state->volume ? state->balance : 32768;
508 va->bass = state->bass;
509 va->treble = state->treble;
510
511 if (state->radio)
512 break;
513 if (state->opmode == OPMODE_AUTOSELECT)
514 msp_detect_stereo(client);
515 va->mode = msp_mode_v4l2_to_v4l1(state->rxsubchans, state->audmode);
516 break;
517 }
518
519 case VIDIOCSAUDIO:
520 {
521 struct video_audio *va = arg;
522
523 state->muted = (va->flags & VIDEO_AUDIO_MUTE);
524 state->volume = va->volume;
525 state->balance = va->balance;
526 state->bass = va->bass;
527 state->treble = va->treble;
528 msp_set_audio(client);
529
530 if (va->mode != 0 && state->radio == 0 &&
531 state->audmode != msp_mode_v4l1_to_v4l2(va->mode)) {
532 state->audmode = msp_mode_v4l1_to_v4l2(va->mode);
533 msp_set_audmode(client);
534 }
535 break;
536 }
537
538 case VIDIOCSCHAN:
539 {
540 struct video_channel *vc = arg;
541 int update = 0;
542 v4l2_std_id std;
543
544 if (state->radio)
545 update = 1;
546 state->radio = 0;
547 if (vc->norm == VIDEO_MODE_PAL)
548 std = V4L2_STD_PAL;
549 else if (vc->norm == VIDEO_MODE_SECAM)
550 std = V4L2_STD_SECAM;
551 else
552 std = V4L2_STD_NTSC;
553 if (std != state->v4l2_std) {
554 state->v4l2_std = std;
555 update = 1;
556 }
557 if (update)
558 msp_wake_thread(client);
559 break;
560 }
561
562 case VIDIOCSFREQ:
563 {
564 /* new channel -- kick audio carrier scan */
565 msp_wake_thread(client);
566 break;
567 }
568 default:
569 return -ENOIOCTLCMD;
570 }
571 return 0;
572}
573#endif
574
575/* --- v4l2 ioctls --- */ 462/* --- v4l2 ioctls --- */
576static int msp_s_radio(struct v4l2_subdev *sd) 463static int msp_s_radio(struct v4l2_subdev *sd)
577{ 464{
@@ -713,22 +600,24 @@ static int msp_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc)
713 struct msp_state *state = to_state(sd); 600 struct msp_state *state = to_state(sd);
714 601
715 switch (qc->id) { 602 switch (qc->id) {
716 case V4L2_CID_AUDIO_VOLUME: 603 case V4L2_CID_AUDIO_VOLUME:
717 case V4L2_CID_AUDIO_MUTE: 604 return v4l2_ctrl_query_fill(qc, 0, 65535, 65535 / 100, 58880);
718 return v4l2_ctrl_query_fill_std(qc); 605 case V4L2_CID_AUDIO_MUTE:
719 default: 606 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 0);
720 break; 607 default:
608 break;
721 } 609 }
722 if (!state->has_sound_processing) 610 if (!state->has_sound_processing)
723 return -EINVAL; 611 return -EINVAL;
724 switch (qc->id) { 612 switch (qc->id) {
725 case V4L2_CID_AUDIO_LOUDNESS: 613 case V4L2_CID_AUDIO_LOUDNESS:
726 case V4L2_CID_AUDIO_BALANCE: 614 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 0);
727 case V4L2_CID_AUDIO_BASS: 615 case V4L2_CID_AUDIO_BALANCE:
728 case V4L2_CID_AUDIO_TREBLE: 616 case V4L2_CID_AUDIO_BASS:
729 return v4l2_ctrl_query_fill_std(qc); 617 case V4L2_CID_AUDIO_TREBLE:
730 default: 618 return v4l2_ctrl_query_fill(qc, 0, 65535, 65535 / 100, 32768);
731 return -EINVAL; 619 default:
620 return -EINVAL;
732 } 621 }
733 return 0; 622 return 0;
734} 623}
@@ -820,9 +709,6 @@ static const struct v4l2_subdev_core_ops msp_core_ops = {
820 .g_ctrl = msp_g_ctrl, 709 .g_ctrl = msp_g_ctrl,
821 .s_ctrl = msp_s_ctrl, 710 .s_ctrl = msp_s_ctrl,
822 .queryctrl = msp_queryctrl, 711 .queryctrl = msp_queryctrl,
823#ifdef CONFIG_VIDEO_ALLOW_V4L1
824 .ioctl = msp_ioctl,
825#endif
826}; 712};
827 713
828static const struct v4l2_subdev_tuner_ops msp_tuner_ops = { 714static const struct v4l2_subdev_tuner_ops msp_tuner_ops = {
diff --git a/drivers/media/video/mt9m001.c b/drivers/media/video/mt9m001.c
index c1bf75ef2741..fa7e5093edeb 100644
--- a/drivers/media/video/mt9m001.c
+++ b/drivers/media/video/mt9m001.c
@@ -12,7 +12,6 @@
12#include <linux/slab.h> 12#include <linux/slab.h>
13#include <linux/i2c.h> 13#include <linux/i2c.h>
14#include <linux/log2.h> 14#include <linux/log2.h>
15#include <linux/gpio.h>
16 15
17#include <media/v4l2-common.h> 16#include <media/v4l2-common.h>
18#include <media/v4l2-chip-ident.h> 17#include <media/v4l2-chip-ident.h>
@@ -73,9 +72,7 @@ struct mt9m001 {
73 struct i2c_client *client; 72 struct i2c_client *client;
74 struct soc_camera_device icd; 73 struct soc_camera_device icd;
75 int model; /* V4L2_IDENT_MT9M001* codes from v4l2-chip-ident.h */ 74 int model; /* V4L2_IDENT_MT9M001* codes from v4l2-chip-ident.h */
76 int switch_gpio;
77 unsigned char autoexposure; 75 unsigned char autoexposure;
78 unsigned char datawidth;
79}; 76};
80 77
81static int reg_read(struct soc_camera_device *icd, const u8 reg) 78static int reg_read(struct soc_camera_device *icd, const u8 reg)
@@ -181,92 +178,28 @@ static int mt9m001_stop_capture(struct soc_camera_device *icd)
181 return 0; 178 return 0;
182} 179}
183 180
184static int bus_switch_request(struct mt9m001 *mt9m001,
185 struct soc_camera_link *icl)
186{
187#ifdef CONFIG_MT9M001_PCA9536_SWITCH
188 int ret;
189 unsigned int gpio = icl->gpio;
190
191 if (gpio_is_valid(gpio)) {
192 /* We have a data bus switch. */
193 ret = gpio_request(gpio, "mt9m001");
194 if (ret < 0) {
195 dev_err(&mt9m001->client->dev, "Cannot get GPIO %u\n",
196 gpio);
197 return ret;
198 }
199
200 ret = gpio_direction_output(gpio, 0);
201 if (ret < 0) {
202 dev_err(&mt9m001->client->dev,
203 "Cannot set GPIO %u to output\n", gpio);
204 gpio_free(gpio);
205 return ret;
206 }
207 }
208
209 mt9m001->switch_gpio = gpio;
210#else
211 mt9m001->switch_gpio = -EINVAL;
212#endif
213 return 0;
214}
215
216static void bus_switch_release(struct mt9m001 *mt9m001)
217{
218#ifdef CONFIG_MT9M001_PCA9536_SWITCH
219 if (gpio_is_valid(mt9m001->switch_gpio))
220 gpio_free(mt9m001->switch_gpio);
221#endif
222}
223
224static int bus_switch_act(struct mt9m001 *mt9m001, int go8bit)
225{
226#ifdef CONFIG_MT9M001_PCA9536_SWITCH
227 if (!gpio_is_valid(mt9m001->switch_gpio))
228 return -ENODEV;
229
230 gpio_set_value_cansleep(mt9m001->switch_gpio, go8bit);
231 return 0;
232#else
233 return -ENODEV;
234#endif
235}
236
237static int bus_switch_possible(struct mt9m001 *mt9m001)
238{
239#ifdef CONFIG_MT9M001_PCA9536_SWITCH
240 return gpio_is_valid(mt9m001->switch_gpio);
241#else
242 return 0;
243#endif
244}
245
246static int mt9m001_set_bus_param(struct soc_camera_device *icd, 181static int mt9m001_set_bus_param(struct soc_camera_device *icd,
247 unsigned long flags) 182 unsigned long flags)
248{ 183{
249 struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd); 184 struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd);
250 unsigned int width_flag = flags & SOCAM_DATAWIDTH_MASK; 185 struct soc_camera_link *icl = mt9m001->client->dev.platform_data;
251 int ret; 186 unsigned long width_flag = flags & SOCAM_DATAWIDTH_MASK;
252 187
253 /* Flags validity verified in test_bus_param */ 188 /* Only one width bit may be set */
189 if (!is_power_of_2(width_flag))
190 return -EINVAL;
254 191
255 if ((mt9m001->datawidth != 10 && (width_flag == SOCAM_DATAWIDTH_10)) || 192 if (icl->set_bus_param)
256 (mt9m001->datawidth != 9 && (width_flag == SOCAM_DATAWIDTH_9)) || 193 return icl->set_bus_param(icl, width_flag);
257 (mt9m001->datawidth != 8 && (width_flag == SOCAM_DATAWIDTH_8))) {
258 /* Well, we actually only can do 10 or 8 bits... */
259 if (width_flag == SOCAM_DATAWIDTH_9)
260 return -EINVAL;
261 ret = bus_switch_act(mt9m001,
262 width_flag == SOCAM_DATAWIDTH_8);
263 if (ret < 0)
264 return ret;
265 194
266 mt9m001->datawidth = width_flag == SOCAM_DATAWIDTH_8 ? 8 : 10; 195 /*
267 } 196 * Without board specific bus width settings we only support the
197 * sensors native bus width
198 */
199 if (width_flag == SOCAM_DATAWIDTH_10)
200 return 0;
268 201
269 return 0; 202 return -EINVAL;
270} 203}
271 204
272static unsigned long mt9m001_query_bus_param(struct soc_camera_device *icd) 205static unsigned long mt9m001_query_bus_param(struct soc_camera_device *icd)
@@ -274,18 +207,20 @@ static unsigned long mt9m001_query_bus_param(struct soc_camera_device *icd)
274 struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd); 207 struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd);
275 struct soc_camera_link *icl = mt9m001->client->dev.platform_data; 208 struct soc_camera_link *icl = mt9m001->client->dev.platform_data;
276 /* MT9M001 has all capture_format parameters fixed */ 209 /* MT9M001 has all capture_format parameters fixed */
277 unsigned long flags = SOCAM_DATAWIDTH_10 | SOCAM_PCLK_SAMPLE_RISING | 210 unsigned long flags = SOCAM_PCLK_SAMPLE_RISING |
278 SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_HIGH | 211 SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_HIGH |
279 SOCAM_MASTER; 212 SOCAM_DATA_ACTIVE_HIGH | SOCAM_MASTER;
280 213
281 if (bus_switch_possible(mt9m001)) 214 if (icl->query_bus_param)
282 flags |= SOCAM_DATAWIDTH_8; 215 flags |= icl->query_bus_param(icl) & SOCAM_DATAWIDTH_MASK;
216 else
217 flags |= SOCAM_DATAWIDTH_10;
283 218
284 return soc_camera_apply_sensor_flags(icl, flags); 219 return soc_camera_apply_sensor_flags(icl, flags);
285} 220}
286 221
287static int mt9m001_set_fmt(struct soc_camera_device *icd, 222static int mt9m001_set_crop(struct soc_camera_device *icd,
288 __u32 pixfmt, struct v4l2_rect *rect) 223 struct v4l2_rect *rect)
289{ 224{
290 struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd); 225 struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd);
291 int ret; 226 int ret;
@@ -324,6 +259,20 @@ static int mt9m001_set_fmt(struct soc_camera_device *icd,
324 return ret; 259 return ret;
325} 260}
326 261
262static int mt9m001_set_fmt(struct soc_camera_device *icd,
263 struct v4l2_format *f)
264{
265 struct v4l2_rect rect = {
266 .left = icd->x_current,
267 .top = icd->y_current,
268 .width = f->fmt.pix.width,
269 .height = f->fmt.pix.height,
270 };
271
272 /* No support for scaling so far, just crop. TODO: use skipping */
273 return mt9m001_set_crop(icd, &rect);
274}
275
327static int mt9m001_try_fmt(struct soc_camera_device *icd, 276static int mt9m001_try_fmt(struct soc_camera_device *icd,
328 struct v4l2_format *f) 277 struct v4l2_format *f)
329{ 278{
@@ -449,6 +398,7 @@ static struct soc_camera_ops mt9m001_ops = {
449 .release = mt9m001_release, 398 .release = mt9m001_release,
450 .start_capture = mt9m001_start_capture, 399 .start_capture = mt9m001_start_capture,
451 .stop_capture = mt9m001_stop_capture, 400 .stop_capture = mt9m001_stop_capture,
401 .set_crop = mt9m001_set_crop,
452 .set_fmt = mt9m001_set_fmt, 402 .set_fmt = mt9m001_set_fmt,
453 .try_fmt = mt9m001_try_fmt, 403 .try_fmt = mt9m001_try_fmt,
454 .set_bus_param = mt9m001_set_bus_param, 404 .set_bus_param = mt9m001_set_bus_param,
@@ -583,6 +533,7 @@ static int mt9m001_video_probe(struct soc_camera_device *icd)
583 struct soc_camera_link *icl = mt9m001->client->dev.platform_data; 533 struct soc_camera_link *icl = mt9m001->client->dev.platform_data;
584 s32 data; 534 s32 data;
585 int ret; 535 int ret;
536 unsigned long flags;
586 537
587 /* We must have a parent by now. And it cannot be a wrong one. 538 /* We must have a parent by now. And it cannot be a wrong one.
588 * So this entire test is completely redundant. */ 539 * So this entire test is completely redundant. */
@@ -603,18 +554,10 @@ static int mt9m001_video_probe(struct soc_camera_device *icd)
603 case 0x8421: 554 case 0x8421:
604 mt9m001->model = V4L2_IDENT_MT9M001C12ST; 555 mt9m001->model = V4L2_IDENT_MT9M001C12ST;
605 icd->formats = mt9m001_colour_formats; 556 icd->formats = mt9m001_colour_formats;
606 if (gpio_is_valid(icl->gpio))
607 icd->num_formats = ARRAY_SIZE(mt9m001_colour_formats);
608 else
609 icd->num_formats = 1;
610 break; 557 break;
611 case 0x8431: 558 case 0x8431:
612 mt9m001->model = V4L2_IDENT_MT9M001C12STM; 559 mt9m001->model = V4L2_IDENT_MT9M001C12STM;
613 icd->formats = mt9m001_monochrome_formats; 560 icd->formats = mt9m001_monochrome_formats;
614 if (gpio_is_valid(icl->gpio))
615 icd->num_formats = ARRAY_SIZE(mt9m001_monochrome_formats);
616 else
617 icd->num_formats = 1;
618 break; 561 break;
619 default: 562 default:
620 ret = -ENODEV; 563 ret = -ENODEV;
@@ -623,6 +566,26 @@ static int mt9m001_video_probe(struct soc_camera_device *icd)
623 goto ei2c; 566 goto ei2c;
624 } 567 }
625 568
569 icd->num_formats = 0;
570
571 /*
572 * This is a 10bit sensor, so by default we only allow 10bit.
573 * The platform may support different bus widths due to
574 * different routing of the data lines.
575 */
576 if (icl->query_bus_param)
577 flags = icl->query_bus_param(icl);
578 else
579 flags = SOCAM_DATAWIDTH_10;
580
581 if (flags & SOCAM_DATAWIDTH_10)
582 icd->num_formats++;
583 else
584 icd->formats++;
585
586 if (flags & SOCAM_DATAWIDTH_8)
587 icd->num_formats++;
588
626 dev_info(&icd->dev, "Detected a MT9M001 chip ID %x (%s)\n", data, 589 dev_info(&icd->dev, "Detected a MT9M001 chip ID %x (%s)\n", data,
627 data == 0x8431 ? "C12STM" : "C12ST"); 590 data == 0x8431 ? "C12STM" : "C12ST");
628 591
@@ -688,18 +651,10 @@ static int mt9m001_probe(struct i2c_client *client,
688 icd->height_max = 1024; 651 icd->height_max = 1024;
689 icd->y_skip_top = 1; 652 icd->y_skip_top = 1;
690 icd->iface = icl->bus_id; 653 icd->iface = icl->bus_id;
691 /* Default datawidth - this is the only width this camera (normally)
692 * supports. It is only with extra logic that it can support
693 * other widths. Therefore it seems to be a sensible default. */
694 mt9m001->datawidth = 10;
695 /* Simulated autoexposure. If enabled, we calculate shutter width 654 /* Simulated autoexposure. If enabled, we calculate shutter width
696 * ourselves in the driver based on vertical blanking and frame width */ 655 * ourselves in the driver based on vertical blanking and frame width */
697 mt9m001->autoexposure = 1; 656 mt9m001->autoexposure = 1;
698 657
699 ret = bus_switch_request(mt9m001, icl);
700 if (ret)
701 goto eswinit;
702
703 ret = soc_camera_device_register(icd); 658 ret = soc_camera_device_register(icd);
704 if (ret) 659 if (ret)
705 goto eisdr; 660 goto eisdr;
@@ -707,8 +662,6 @@ static int mt9m001_probe(struct i2c_client *client,
707 return 0; 662 return 0;
708 663
709eisdr: 664eisdr:
710 bus_switch_release(mt9m001);
711eswinit:
712 kfree(mt9m001); 665 kfree(mt9m001);
713 return ret; 666 return ret;
714} 667}
@@ -718,7 +671,6 @@ static int mt9m001_remove(struct i2c_client *client)
718 struct mt9m001 *mt9m001 = i2c_get_clientdata(client); 671 struct mt9m001 *mt9m001 = i2c_get_clientdata(client);
719 672
720 soc_camera_device_unregister(&mt9m001->icd); 673 soc_camera_device_unregister(&mt9m001->icd);
721 bus_switch_release(mt9m001);
722 kfree(mt9m001); 674 kfree(mt9m001);
723 675
724 return 0; 676 return 0;
diff --git a/drivers/media/video/mt9m111.c b/drivers/media/video/mt9m111.c
index 5b8e20979cce..cdd1ddb51388 100644
--- a/drivers/media/video/mt9m111.c
+++ b/drivers/media/video/mt9m111.c
@@ -152,7 +152,7 @@ struct mt9m111 {
152 struct soc_camera_device icd; 152 struct soc_camera_device icd;
153 int model; /* V4L2_IDENT_MT9M11x* codes from v4l2-chip-ident.h */ 153 int model; /* V4L2_IDENT_MT9M11x* codes from v4l2-chip-ident.h */
154 enum mt9m111_context context; 154 enum mt9m111_context context;
155 unsigned int left, top, width, height; 155 struct v4l2_rect rect;
156 u32 pixfmt; 156 u32 pixfmt;
157 unsigned char autoexposure; 157 unsigned char autoexposure;
158 unsigned char datawidth; 158 unsigned char datawidth;
@@ -249,12 +249,13 @@ static int mt9m111_set_context(struct soc_camera_device *icd,
249 return reg_write(CONTEXT_CONTROL, valA); 249 return reg_write(CONTEXT_CONTROL, valA);
250} 250}
251 251
252static int mt9m111_setup_rect(struct soc_camera_device *icd) 252static int mt9m111_setup_rect(struct soc_camera_device *icd,
253 struct v4l2_rect *rect)
253{ 254{
254 struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd); 255 struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
255 int ret, is_raw_format; 256 int ret, is_raw_format;
256 int width = mt9m111->width; 257 int width = rect->width;
257 int height = mt9m111->height; 258 int height = rect->height;
258 259
259 if ((mt9m111->pixfmt == V4L2_PIX_FMT_SBGGR8) 260 if ((mt9m111->pixfmt == V4L2_PIX_FMT_SBGGR8)
260 || (mt9m111->pixfmt == V4L2_PIX_FMT_SBGGR16)) 261 || (mt9m111->pixfmt == V4L2_PIX_FMT_SBGGR16))
@@ -262,9 +263,9 @@ static int mt9m111_setup_rect(struct soc_camera_device *icd)
262 else 263 else
263 is_raw_format = 0; 264 is_raw_format = 0;
264 265
265 ret = reg_write(COLUMN_START, mt9m111->left); 266 ret = reg_write(COLUMN_START, rect->left);
266 if (!ret) 267 if (!ret)
267 ret = reg_write(ROW_START, mt9m111->top); 268 ret = reg_write(ROW_START, rect->top);
268 269
269 if (is_raw_format) { 270 if (is_raw_format) {
270 if (!ret) 271 if (!ret)
@@ -393,6 +394,8 @@ static int mt9m111_disable(struct soc_camera_device *icd)
393 394
394static int mt9m111_reset(struct soc_camera_device *icd) 395static int mt9m111_reset(struct soc_camera_device *icd)
395{ 396{
397 struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
398 struct soc_camera_link *icl = mt9m111->client->dev.platform_data;
396 int ret; 399 int ret;
397 400
398 ret = reg_set(RESET, MT9M111_RESET_RESET_MODE); 401 ret = reg_set(RESET, MT9M111_RESET_RESET_MODE);
@@ -401,6 +404,10 @@ static int mt9m111_reset(struct soc_camera_device *icd)
401 if (!ret) 404 if (!ret)
402 ret = reg_clear(RESET, MT9M111_RESET_RESET_MODE 405 ret = reg_clear(RESET, MT9M111_RESET_RESET_MODE
403 | MT9M111_RESET_RESET_SOC); 406 | MT9M111_RESET_RESET_SOC);
407
408 if (icl->reset)
409 icl->reset(&mt9m111->client->dev);
410
404 return ret; 411 return ret;
405} 412}
406 413
@@ -420,7 +427,7 @@ static unsigned long mt9m111_query_bus_param(struct soc_camera_device *icd)
420 struct soc_camera_link *icl = mt9m111->client->dev.platform_data; 427 struct soc_camera_link *icl = mt9m111->client->dev.platform_data;
421 unsigned long flags = SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING | 428 unsigned long flags = SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING |
422 SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_HIGH | 429 SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_HIGH |
423 SOCAM_DATAWIDTH_8; 430 SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8;
424 431
425 return soc_camera_apply_sensor_flags(icl, flags); 432 return soc_camera_apply_sensor_flags(icl, flags);
426} 433}
@@ -430,6 +437,22 @@ static int mt9m111_set_bus_param(struct soc_camera_device *icd, unsigned long f)
430 return 0; 437 return 0;
431} 438}
432 439
440static int mt9m111_set_crop(struct soc_camera_device *icd,
441 struct v4l2_rect *rect)
442{
443 struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
444 int ret;
445
446 dev_dbg(&icd->dev, "%s left=%d, top=%d, width=%d, height=%d\n",
447 __func__, rect->left, rect->top, rect->width,
448 rect->height);
449
450 ret = mt9m111_setup_rect(icd, rect);
451 if (!ret)
452 mt9m111->rect = *rect;
453 return ret;
454}
455
433static int mt9m111_set_pixfmt(struct soc_camera_device *icd, u32 pixfmt) 456static int mt9m111_set_pixfmt(struct soc_camera_device *icd, u32 pixfmt)
434{ 457{
435 struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd); 458 struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
@@ -480,23 +503,27 @@ static int mt9m111_set_pixfmt(struct soc_camera_device *icd, u32 pixfmt)
480} 503}
481 504
482static int mt9m111_set_fmt(struct soc_camera_device *icd, 505static int mt9m111_set_fmt(struct soc_camera_device *icd,
483 __u32 pixfmt, struct v4l2_rect *rect) 506 struct v4l2_format *f)
484{ 507{
485 struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd); 508 struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
509 struct v4l2_pix_format *pix = &f->fmt.pix;
510 struct v4l2_rect rect = {
511 .left = mt9m111->rect.left,
512 .top = mt9m111->rect.top,
513 .width = pix->width,
514 .height = pix->height,
515 };
486 int ret; 516 int ret;
487 517
488 mt9m111->left = rect->left;
489 mt9m111->top = rect->top;
490 mt9m111->width = rect->width;
491 mt9m111->height = rect->height;
492
493 dev_dbg(&icd->dev, "%s fmt=%x left=%d, top=%d, width=%d, height=%d\n", 518 dev_dbg(&icd->dev, "%s fmt=%x left=%d, top=%d, width=%d, height=%d\n",
494 __func__, pixfmt, mt9m111->left, mt9m111->top, mt9m111->width, 519 __func__, pix->pixelformat, rect.left, rect.top, rect.width,
495 mt9m111->height); 520 rect.height);
496 521
497 ret = mt9m111_setup_rect(icd); 522 ret = mt9m111_setup_rect(icd, &rect);
523 if (!ret)
524 ret = mt9m111_set_pixfmt(icd, pix->pixelformat);
498 if (!ret) 525 if (!ret)
499 ret = mt9m111_set_pixfmt(icd, pixfmt); 526 mt9m111->rect = rect;
500 return ret; 527 return ret;
501} 528}
502 529
@@ -627,6 +654,7 @@ static struct soc_camera_ops mt9m111_ops = {
627 .release = mt9m111_release, 654 .release = mt9m111_release,
628 .start_capture = mt9m111_start_capture, 655 .start_capture = mt9m111_start_capture,
629 .stop_capture = mt9m111_stop_capture, 656 .stop_capture = mt9m111_stop_capture,
657 .set_crop = mt9m111_set_crop,
630 .set_fmt = mt9m111_set_fmt, 658 .set_fmt = mt9m111_set_fmt,
631 .try_fmt = mt9m111_try_fmt, 659 .try_fmt = mt9m111_try_fmt,
632 .query_bus_param = mt9m111_query_bus_param, 660 .query_bus_param = mt9m111_query_bus_param,
@@ -811,7 +839,7 @@ static int mt9m111_restore_state(struct soc_camera_device *icd)
811 839
812 mt9m111_set_context(icd, mt9m111->context); 840 mt9m111_set_context(icd, mt9m111->context);
813 mt9m111_set_pixfmt(icd, mt9m111->pixfmt); 841 mt9m111_set_pixfmt(icd, mt9m111->pixfmt);
814 mt9m111_setup_rect(icd); 842 mt9m111_setup_rect(icd, &mt9m111->rect);
815 mt9m111_set_flip(icd, mt9m111->hflip, MT9M111_RMB_MIRROR_COLS); 843 mt9m111_set_flip(icd, mt9m111->hflip, MT9M111_RMB_MIRROR_COLS);
816 mt9m111_set_flip(icd, mt9m111->vflip, MT9M111_RMB_MIRROR_ROWS); 844 mt9m111_set_flip(icd, mt9m111->vflip, MT9M111_RMB_MIRROR_ROWS);
817 mt9m111_set_global_gain(icd, icd->gain); 845 mt9m111_set_global_gain(icd, icd->gain);
diff --git a/drivers/media/video/mt9t031.c b/drivers/media/video/mt9t031.c
index 349d8e365530..23f9ce9d67ef 100644
--- a/drivers/media/video/mt9t031.c
+++ b/drivers/media/video/mt9t031.c
@@ -144,13 +144,11 @@ static int mt9t031_init(struct soc_camera_device *icd)
144 int ret; 144 int ret;
145 145
146 /* Disable chip output, synchronous option update */ 146 /* Disable chip output, synchronous option update */
147 dev_dbg(icd->vdev->parent, "%s\n", __func__);
148
149 ret = reg_write(icd, MT9T031_RESET, 1); 147 ret = reg_write(icd, MT9T031_RESET, 1);
150 if (ret >= 0) 148 if (ret >= 0)
151 ret = reg_write(icd, MT9T031_RESET, 0); 149 ret = reg_write(icd, MT9T031_RESET, 0);
152 if (ret >= 0) 150 if (ret >= 0)
153 ret = reg_clear(icd, MT9T031_OUTPUT_CONTROL, 3); 151 ret = reg_clear(icd, MT9T031_OUTPUT_CONTROL, 2);
154 152
155 return ret >= 0 ? 0 : -EIO; 153 return ret >= 0 ? 0 : -EIO;
156} 154}
@@ -158,14 +156,14 @@ static int mt9t031_init(struct soc_camera_device *icd)
158static int mt9t031_release(struct soc_camera_device *icd) 156static int mt9t031_release(struct soc_camera_device *icd)
159{ 157{
160 /* Disable the chip */ 158 /* Disable the chip */
161 reg_clear(icd, MT9T031_OUTPUT_CONTROL, 3); 159 reg_clear(icd, MT9T031_OUTPUT_CONTROL, 2);
162 return 0; 160 return 0;
163} 161}
164 162
165static int mt9t031_start_capture(struct soc_camera_device *icd) 163static int mt9t031_start_capture(struct soc_camera_device *icd)
166{ 164{
167 /* Switch to master "normal" mode */ 165 /* Switch to master "normal" mode */
168 if (reg_set(icd, MT9T031_OUTPUT_CONTROL, 3) < 0) 166 if (reg_set(icd, MT9T031_OUTPUT_CONTROL, 2) < 0)
169 return -EIO; 167 return -EIO;
170 return 0; 168 return 0;
171} 169}
@@ -173,7 +171,7 @@ static int mt9t031_start_capture(struct soc_camera_device *icd)
173static int mt9t031_stop_capture(struct soc_camera_device *icd) 171static int mt9t031_stop_capture(struct soc_camera_device *icd)
174{ 172{
175 /* Stop sensor readout */ 173 /* Stop sensor readout */
176 if (reg_clear(icd, MT9T031_OUTPUT_CONTROL, 3) < 0) 174 if (reg_clear(icd, MT9T031_OUTPUT_CONTROL, 2) < 0)
177 return -EIO; 175 return -EIO;
178 return 0; 176 return 0;
179} 177}
@@ -186,9 +184,9 @@ static int mt9t031_set_bus_param(struct soc_camera_device *icd,
186 return -EINVAL; 184 return -EINVAL;
187 185
188 if (flags & SOCAM_PCLK_SAMPLE_FALLING) 186 if (flags & SOCAM_PCLK_SAMPLE_FALLING)
189 reg_set(icd, MT9T031_PIXEL_CLOCK_CONTROL, 0x8000);
190 else
191 reg_clear(icd, MT9T031_PIXEL_CLOCK_CONTROL, 0x8000); 187 reg_clear(icd, MT9T031_PIXEL_CLOCK_CONTROL, 0x8000);
188 else
189 reg_set(icd, MT9T031_PIXEL_CLOCK_CONTROL, 0x8000);
192 190
193 return 0; 191 return 0;
194} 192}
@@ -201,67 +199,73 @@ static unsigned long mt9t031_query_bus_param(struct soc_camera_device *icd)
201 return soc_camera_apply_sensor_flags(icl, MT9T031_BUS_PARAM); 199 return soc_camera_apply_sensor_flags(icl, MT9T031_BUS_PARAM);
202} 200}
203 201
204static int mt9t031_set_fmt(struct soc_camera_device *icd, 202/* Round up minima and round down maxima */
205 __u32 pixfmt, struct v4l2_rect *rect) 203static void recalculate_limits(struct soc_camera_device *icd,
204 u16 xskip, u16 yskip)
205{
206 icd->x_min = (MT9T031_COLUMN_SKIP + xskip - 1) / xskip;
207 icd->y_min = (MT9T031_ROW_SKIP + yskip - 1) / yskip;
208 icd->width_min = (MT9T031_MIN_WIDTH + xskip - 1) / xskip;
209 icd->height_min = (MT9T031_MIN_HEIGHT + yskip - 1) / yskip;
210 icd->width_max = MT9T031_MAX_WIDTH / xskip;
211 icd->height_max = MT9T031_MAX_HEIGHT / yskip;
212}
213
214static int mt9t031_set_params(struct soc_camera_device *icd,
215 struct v4l2_rect *rect, u16 xskip, u16 yskip)
206{ 216{
207 struct mt9t031 *mt9t031 = container_of(icd, struct mt9t031, icd); 217 struct mt9t031 *mt9t031 = container_of(icd, struct mt9t031, icd);
208 int ret; 218 int ret;
219 u16 xbin, ybin, width, height, left, top;
209 const u16 hblank = MT9T031_HORIZONTAL_BLANK, 220 const u16 hblank = MT9T031_HORIZONTAL_BLANK,
210 vblank = MT9T031_VERTICAL_BLANK; 221 vblank = MT9T031_VERTICAL_BLANK;
211 u16 xbin, xskip = mt9t031->xskip, ybin, yskip = mt9t031->yskip,
212 width = rect->width * xskip, height = rect->height * yskip;
213 222
214 if (pixfmt) { 223 /* Make sure we don't exceed sensor limits */
215 /* S_FMT - use binning and skipping for scaling, recalculate */ 224 if (rect->left + rect->width > icd->width_max)
216 /* Is this more optimal than just a division? */ 225 rect->left = (icd->width_max - rect->width) / 2 + icd->x_min;
217 for (xskip = 8; xskip > 1; xskip--)
218 if (rect->width * xskip <= icd->width_max)
219 break;
220 226
221 for (yskip = 8; yskip > 1; yskip--) 227 if (rect->top + rect->height > icd->height_max)
222 if (rect->height * yskip <= icd->height_max) 228 rect->top = (icd->height_max - rect->height) / 2 + icd->y_min;
223 break;
224 229
225 width = rect->width * xskip; 230 width = rect->width * xskip;
226 height = rect->height * yskip; 231 height = rect->height * yskip;
227 232 left = rect->left * xskip;
228 dev_dbg(&icd->dev, "xskip %u, width %u, yskip %u, height %u\n", 233 top = rect->top * yskip;
229 xskip, width, yskip, height);
230 }
231 234
232 xbin = min(xskip, (u16)3); 235 xbin = min(xskip, (u16)3);
233 ybin = min(yskip, (u16)3); 236 ybin = min(yskip, (u16)3);
234 237
235 /* Make sure we don't exceed frame limits */ 238 dev_dbg(&icd->dev, "xskip %u, width %u/%u, yskip %u, height %u/%u\n",
236 if (rect->left + width > icd->width_max) 239 xskip, width, rect->width, yskip, height, rect->height);
237 rect->left = (icd->width_max - width) / 2;
238
239 if (rect->top + height > icd->height_max)
240 rect->top = (icd->height_max - height) / 2;
241 240
242 /* Could just do roundup(rect->left, [xy]bin); but this is cheaper */ 241 /* Could just do roundup(rect->left, [xy]bin * 2); but this is cheaper */
243 switch (xbin) { 242 switch (xbin) {
244 case 2: 243 case 2:
245 rect->left = (rect->left + 1) & ~1; 244 left = (left + 3) & ~3;
246 break; 245 break;
247 case 3: 246 case 3:
248 rect->left = roundup(rect->left, 3); 247 left = roundup(left, 6);
249 } 248 }
250 249
251 switch (ybin) { 250 switch (ybin) {
252 case 2: 251 case 2:
253 rect->top = (rect->top + 1) & ~1; 252 top = (top + 3) & ~3;
254 break; 253 break;
255 case 3: 254 case 3:
256 rect->top = roundup(rect->top, 3); 255 top = roundup(top, 6);
257 } 256 }
258 257
258 /* Disable register update, reconfigure atomically */
259 ret = reg_set(icd, MT9T031_OUTPUT_CONTROL, 1);
260 if (ret < 0)
261 return ret;
262
259 /* Blanking and start values - default... */ 263 /* Blanking and start values - default... */
260 ret = reg_write(icd, MT9T031_HORIZONTAL_BLANKING, hblank); 264 ret = reg_write(icd, MT9T031_HORIZONTAL_BLANKING, hblank);
261 if (ret >= 0) 265 if (ret >= 0)
262 ret = reg_write(icd, MT9T031_VERTICAL_BLANKING, vblank); 266 ret = reg_write(icd, MT9T031_VERTICAL_BLANKING, vblank);
263 267
264 if (pixfmt) { 268 if (yskip != mt9t031->yskip || xskip != mt9t031->xskip) {
265 /* Binning, skipping */ 269 /* Binning, skipping */
266 if (ret >= 0) 270 if (ret >= 0)
267 ret = reg_write(icd, MT9T031_COLUMN_ADDRESS_MODE, 271 ret = reg_write(icd, MT9T031_COLUMN_ADDRESS_MODE,
@@ -270,14 +274,14 @@ static int mt9t031_set_fmt(struct soc_camera_device *icd,
270 ret = reg_write(icd, MT9T031_ROW_ADDRESS_MODE, 274 ret = reg_write(icd, MT9T031_ROW_ADDRESS_MODE,
271 ((ybin - 1) << 4) | (yskip - 1)); 275 ((ybin - 1) << 4) | (yskip - 1));
272 } 276 }
273 dev_dbg(&icd->dev, "new left %u, top %u\n", rect->left, rect->top); 277 dev_dbg(&icd->dev, "new physical left %u, top %u\n", left, top);
274 278
275 /* The caller provides a supported format, as guaranteed by 279 /* The caller provides a supported format, as guaranteed by
276 * icd->try_fmt_cap(), soc_camera_s_crop() and soc_camera_cropcap() */ 280 * icd->try_fmt_cap(), soc_camera_s_crop() and soc_camera_cropcap() */
277 if (ret >= 0) 281 if (ret >= 0)
278 ret = reg_write(icd, MT9T031_COLUMN_START, rect->left); 282 ret = reg_write(icd, MT9T031_COLUMN_START, left);
279 if (ret >= 0) 283 if (ret >= 0)
280 ret = reg_write(icd, MT9T031_ROW_START, rect->top); 284 ret = reg_write(icd, MT9T031_ROW_START, top);
281 if (ret >= 0) 285 if (ret >= 0)
282 ret = reg_write(icd, MT9T031_WINDOW_WIDTH, width - 1); 286 ret = reg_write(icd, MT9T031_WINDOW_WIDTH, width - 1);
283 if (ret >= 0) 287 if (ret >= 0)
@@ -297,12 +301,58 @@ static int mt9t031_set_fmt(struct soc_camera_device *icd,
297 } 301 }
298 } 302 }
299 303
300 if (!ret && pixfmt) { 304 /* Re-enable register update, commit all changes */
305 if (ret >= 0)
306 ret = reg_clear(icd, MT9T031_OUTPUT_CONTROL, 1);
307
308 return ret < 0 ? ret : 0;
309}
310
311static int mt9t031_set_crop(struct soc_camera_device *icd,
312 struct v4l2_rect *rect)
313{
314 struct mt9t031 *mt9t031 = container_of(icd, struct mt9t031, icd);
315
316 /* CROP - no change in scaling, or in limits */
317 return mt9t031_set_params(icd, rect, mt9t031->xskip, mt9t031->yskip);
318}
319
320static int mt9t031_set_fmt(struct soc_camera_device *icd,
321 struct v4l2_format *f)
322{
323 struct mt9t031 *mt9t031 = container_of(icd, struct mt9t031, icd);
324 int ret;
325 u16 xskip, yskip;
326 struct v4l2_rect rect = {
327 .left = icd->x_current,
328 .top = icd->y_current,
329 .width = f->fmt.pix.width,
330 .height = f->fmt.pix.height,
331 };
332
333 /*
334 * try_fmt has put rectangle within limits.
335 * S_FMT - use binning and skipping for scaling, recalculate
336 * limits, used for cropping
337 */
338 /* Is this more optimal than just a division? */
339 for (xskip = 8; xskip > 1; xskip--)
340 if (rect.width * xskip <= MT9T031_MAX_WIDTH)
341 break;
342
343 for (yskip = 8; yskip > 1; yskip--)
344 if (rect.height * yskip <= MT9T031_MAX_HEIGHT)
345 break;
346
347 recalculate_limits(icd, xskip, yskip);
348
349 ret = mt9t031_set_params(icd, &rect, xskip, yskip);
350 if (!ret) {
301 mt9t031->xskip = xskip; 351 mt9t031->xskip = xskip;
302 mt9t031->yskip = yskip; 352 mt9t031->yskip = yskip;
303 } 353 }
304 354
305 return ret < 0 ? ret : 0; 355 return ret;
306} 356}
307 357
308static int mt9t031_try_fmt(struct soc_camera_device *icd, 358static int mt9t031_try_fmt(struct soc_camera_device *icd,
@@ -310,14 +360,14 @@ static int mt9t031_try_fmt(struct soc_camera_device *icd,
310{ 360{
311 struct v4l2_pix_format *pix = &f->fmt.pix; 361 struct v4l2_pix_format *pix = &f->fmt.pix;
312 362
313 if (pix->height < icd->height_min) 363 if (pix->height < MT9T031_MIN_HEIGHT)
314 pix->height = icd->height_min; 364 pix->height = MT9T031_MIN_HEIGHT;
315 if (pix->height > icd->height_max) 365 if (pix->height > MT9T031_MAX_HEIGHT)
316 pix->height = icd->height_max; 366 pix->height = MT9T031_MAX_HEIGHT;
317 if (pix->width < icd->width_min) 367 if (pix->width < MT9T031_MIN_WIDTH)
318 pix->width = icd->width_min; 368 pix->width = MT9T031_MIN_WIDTH;
319 if (pix->width > icd->width_max) 369 if (pix->width > MT9T031_MAX_WIDTH)
320 pix->width = icd->width_max; 370 pix->width = MT9T031_MAX_WIDTH;
321 371
322 pix->width &= ~0x01; /* has to be even */ 372 pix->width &= ~0x01; /* has to be even */
323 pix->height &= ~0x01; /* has to be even */ 373 pix->height &= ~0x01; /* has to be even */
@@ -390,6 +440,14 @@ static const struct v4l2_queryctrl mt9t031_controls[] = {
390 .step = 1, 440 .step = 1,
391 .default_value = 0, 441 .default_value = 0,
392 }, { 442 }, {
443 .id = V4L2_CID_HFLIP,
444 .type = V4L2_CTRL_TYPE_BOOLEAN,
445 .name = "Flip Horizontally",
446 .minimum = 0,
447 .maximum = 1,
448 .step = 1,
449 .default_value = 0,
450 }, {
393 .id = V4L2_CID_GAIN, 451 .id = V4L2_CID_GAIN,
394 .type = V4L2_CTRL_TYPE_INTEGER, 452 .type = V4L2_CTRL_TYPE_INTEGER,
395 .name = "Gain", 453 .name = "Gain",
@@ -431,6 +489,7 @@ static struct soc_camera_ops mt9t031_ops = {
431 .release = mt9t031_release, 489 .release = mt9t031_release,
432 .start_capture = mt9t031_start_capture, 490 .start_capture = mt9t031_start_capture,
433 .stop_capture = mt9t031_stop_capture, 491 .stop_capture = mt9t031_stop_capture,
492 .set_crop = mt9t031_set_crop,
434 .set_fmt = mt9t031_set_fmt, 493 .set_fmt = mt9t031_set_fmt,
435 .try_fmt = mt9t031_try_fmt, 494 .try_fmt = mt9t031_try_fmt,
436 .set_bus_param = mt9t031_set_bus_param, 495 .set_bus_param = mt9t031_set_bus_param,
@@ -513,21 +572,23 @@ static int mt9t031_set_control(struct soc_camera_device *icd, struct v4l2_contro
513 if (data < 0) 572 if (data < 0)
514 return -EIO; 573 return -EIO;
515 } else { 574 } else {
516 /* Pack it into 1.125..15 variable step, register values 9..67 */ 575 /* Pack it into 1.125..128 variable step, register values 9..0x7860 */
517 /* We assume qctrl->maximum - qctrl->default_value - 1 > 0 */ 576 /* We assume qctrl->maximum - qctrl->default_value - 1 > 0 */
518 unsigned long range = qctrl->maximum - qctrl->default_value - 1; 577 unsigned long range = qctrl->maximum - qctrl->default_value - 1;
578 /* calculated gain: map 65..127 to 9..1024 step 0.125 */
519 unsigned long gain = ((ctrl->value - qctrl->default_value - 1) * 579 unsigned long gain = ((ctrl->value - qctrl->default_value - 1) *
520 111 + range / 2) / range + 9; 580 1015 + range / 2) / range + 9;
521 581
522 if (gain <= 32) 582 if (gain <= 32) /* calculated gain 9..32 -> 9..32 */
523 data = gain; 583 data = gain;
524 else if (gain <= 64) 584 else if (gain <= 64) /* calculated gain 33..64 -> 0x51..0x60 */
525 data = ((gain - 32) * 16 + 16) / 32 + 80; 585 data = ((gain - 32) * 16 + 16) / 32 + 80;
526 else 586 else
527 data = ((gain - 64) * 7 + 28) / 56 + 96; 587 /* calculated gain 65..1024 -> (1..120) << 8 + 0x60 */
588 data = (((gain - 64 + 7) * 32) & 0xff00) | 0x60;
528 589
529 dev_dbg(&icd->dev, "Setting gain from %d to %d\n", 590 dev_dbg(&icd->dev, "Setting gain from 0x%x to 0x%x\n",
530 reg_read(icd, MT9T031_GLOBAL_GAIN), data); 591 reg_read(icd, MT9T031_GLOBAL_GAIN), data);
531 data = reg_write(icd, MT9T031_GLOBAL_GAIN, data); 592 data = reg_write(icd, MT9T031_GLOBAL_GAIN, data);
532 if (data < 0) 593 if (data < 0)
533 return -EIO; 594 return -EIO;
diff --git a/drivers/media/video/mt9v022.c b/drivers/media/video/mt9v022.c
index b04c8cb1644d..4d3b4813c322 100644
--- a/drivers/media/video/mt9v022.c
+++ b/drivers/media/video/mt9v022.c
@@ -13,7 +13,6 @@
13#include <linux/i2c.h> 13#include <linux/i2c.h>
14#include <linux/delay.h> 14#include <linux/delay.h>
15#include <linux/log2.h> 15#include <linux/log2.h>
16#include <linux/gpio.h>
17 16
18#include <media/v4l2-common.h> 17#include <media/v4l2-common.h>
19#include <media/v4l2-chip-ident.h> 18#include <media/v4l2-chip-ident.h>
@@ -89,9 +88,7 @@ struct mt9v022 {
89 struct i2c_client *client; 88 struct i2c_client *client;
90 struct soc_camera_device icd; 89 struct soc_camera_device icd;
91 int model; /* V4L2_IDENT_MT9V022* codes from v4l2-chip-ident.h */ 90 int model; /* V4L2_IDENT_MT9V022* codes from v4l2-chip-ident.h */
92 int switch_gpio;
93 u16 chip_control; 91 u16 chip_control;
94 unsigned char datawidth;
95}; 92};
96 93
97static int reg_read(struct soc_camera_device *icd, const u8 reg) 94static int reg_read(struct soc_camera_device *icd, const u8 reg)
@@ -209,66 +206,6 @@ static int mt9v022_stop_capture(struct soc_camera_device *icd)
209 return 0; 206 return 0;
210} 207}
211 208
212static int bus_switch_request(struct mt9v022 *mt9v022, struct soc_camera_link *icl)
213{
214#ifdef CONFIG_MT9V022_PCA9536_SWITCH
215 int ret;
216 unsigned int gpio = icl->gpio;
217
218 if (gpio_is_valid(gpio)) {
219 /* We have a data bus switch. */
220 ret = gpio_request(gpio, "mt9v022");
221 if (ret < 0) {
222 dev_err(&mt9v022->client->dev, "Cannot get GPIO %u\n", gpio);
223 return ret;
224 }
225
226 ret = gpio_direction_output(gpio, 0);
227 if (ret < 0) {
228 dev_err(&mt9v022->client->dev,
229 "Cannot set GPIO %u to output\n", gpio);
230 gpio_free(gpio);
231 return ret;
232 }
233 }
234
235 mt9v022->switch_gpio = gpio;
236#else
237 mt9v022->switch_gpio = -EINVAL;
238#endif
239 return 0;
240}
241
242static void bus_switch_release(struct mt9v022 *mt9v022)
243{
244#ifdef CONFIG_MT9V022_PCA9536_SWITCH
245 if (gpio_is_valid(mt9v022->switch_gpio))
246 gpio_free(mt9v022->switch_gpio);
247#endif
248}
249
250static int bus_switch_act(struct mt9v022 *mt9v022, int go8bit)
251{
252#ifdef CONFIG_MT9V022_PCA9536_SWITCH
253 if (!gpio_is_valid(mt9v022->switch_gpio))
254 return -ENODEV;
255
256 gpio_set_value_cansleep(mt9v022->switch_gpio, go8bit);
257 return 0;
258#else
259 return -ENODEV;
260#endif
261}
262
263static int bus_switch_possible(struct mt9v022 *mt9v022)
264{
265#ifdef CONFIG_MT9V022_PCA9536_SWITCH
266 return gpio_is_valid(mt9v022->switch_gpio);
267#else
268 return 0;
269#endif
270}
271
272static int mt9v022_set_bus_param(struct soc_camera_device *icd, 209static int mt9v022_set_bus_param(struct soc_camera_device *icd,
273 unsigned long flags) 210 unsigned long flags)
274{ 211{
@@ -282,19 +219,17 @@ static int mt9v022_set_bus_param(struct soc_camera_device *icd,
282 if (!is_power_of_2(width_flag)) 219 if (!is_power_of_2(width_flag))
283 return -EINVAL; 220 return -EINVAL;
284 221
285 if ((mt9v022->datawidth != 10 && (width_flag == SOCAM_DATAWIDTH_10)) || 222 if (icl->set_bus_param) {
286 (mt9v022->datawidth != 9 && (width_flag == SOCAM_DATAWIDTH_9)) || 223 ret = icl->set_bus_param(icl, width_flag);
287 (mt9v022->datawidth != 8 && (width_flag == SOCAM_DATAWIDTH_8))) { 224 if (ret)
288 /* Well, we actually only can do 10 or 8 bits... */
289 if (width_flag == SOCAM_DATAWIDTH_9)
290 return -EINVAL;
291
292 ret = bus_switch_act(mt9v022,
293 width_flag == SOCAM_DATAWIDTH_8);
294 if (ret < 0)
295 return ret; 225 return ret;
296 226 } else {
297 mt9v022->datawidth = width_flag == SOCAM_DATAWIDTH_8 ? 8 : 10; 227 /*
228 * Without board specific bus width settings we only support the
229 * sensors native bus width
230 */
231 if (width_flag != SOCAM_DATAWIDTH_10)
232 return -EINVAL;
298 } 233 }
299 234
300 flags = soc_camera_apply_sensor_flags(icl, flags); 235 flags = soc_camera_apply_sensor_flags(icl, flags);
@@ -328,44 +263,27 @@ static int mt9v022_set_bus_param(struct soc_camera_device *icd,
328static unsigned long mt9v022_query_bus_param(struct soc_camera_device *icd) 263static unsigned long mt9v022_query_bus_param(struct soc_camera_device *icd)
329{ 264{
330 struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd); 265 struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd);
331 unsigned int width_flag = SOCAM_DATAWIDTH_10; 266 struct soc_camera_link *icl = mt9v022->client->dev.platform_data;
267 unsigned int width_flag;
332 268
333 if (bus_switch_possible(mt9v022)) 269 if (icl->query_bus_param)
334 width_flag |= SOCAM_DATAWIDTH_8; 270 width_flag = icl->query_bus_param(icl) &
271 SOCAM_DATAWIDTH_MASK;
272 else
273 width_flag = SOCAM_DATAWIDTH_10;
335 274
336 return SOCAM_PCLK_SAMPLE_RISING | SOCAM_PCLK_SAMPLE_FALLING | 275 return SOCAM_PCLK_SAMPLE_RISING | SOCAM_PCLK_SAMPLE_FALLING |
337 SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_LOW | 276 SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_LOW |
338 SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW | 277 SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW |
339 SOCAM_MASTER | SOCAM_SLAVE | 278 SOCAM_DATA_ACTIVE_HIGH | SOCAM_MASTER | SOCAM_SLAVE |
340 width_flag; 279 width_flag;
341} 280}
342 281
343static int mt9v022_set_fmt(struct soc_camera_device *icd, 282static int mt9v022_set_crop(struct soc_camera_device *icd,
344 __u32 pixfmt, struct v4l2_rect *rect) 283 struct v4l2_rect *rect)
345{ 284{
346 struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd);
347 int ret; 285 int ret;
348 286
349 /* The caller provides a supported format, as verified per call to
350 * icd->try_fmt(), datawidth is from our supported format list */
351 switch (pixfmt) {
352 case V4L2_PIX_FMT_GREY:
353 case V4L2_PIX_FMT_Y16:
354 if (mt9v022->model != V4L2_IDENT_MT9V022IX7ATM)
355 return -EINVAL;
356 break;
357 case V4L2_PIX_FMT_SBGGR8:
358 case V4L2_PIX_FMT_SBGGR16:
359 if (mt9v022->model != V4L2_IDENT_MT9V022IX7ATC)
360 return -EINVAL;
361 break;
362 case 0:
363 /* No format change, only geometry */
364 break;
365 default:
366 return -EINVAL;
367 }
368
369 /* Like in example app. Contradicts the datasheet though */ 287 /* Like in example app. Contradicts the datasheet though */
370 ret = reg_read(icd, MT9V022_AEC_AGC_ENABLE); 288 ret = reg_read(icd, MT9V022_AEC_AGC_ENABLE);
371 if (ret >= 0) { 289 if (ret >= 0) {
@@ -403,6 +321,42 @@ static int mt9v022_set_fmt(struct soc_camera_device *icd,
403 return 0; 321 return 0;
404} 322}
405 323
324static int mt9v022_set_fmt(struct soc_camera_device *icd,
325 struct v4l2_format *f)
326{
327 struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd);
328 struct v4l2_pix_format *pix = &f->fmt.pix;
329 struct v4l2_rect rect = {
330 .left = icd->x_current,
331 .top = icd->y_current,
332 .width = pix->width,
333 .height = pix->height,
334 };
335
336 /* The caller provides a supported format, as verified per call to
337 * icd->try_fmt(), datawidth is from our supported format list */
338 switch (pix->pixelformat) {
339 case V4L2_PIX_FMT_GREY:
340 case V4L2_PIX_FMT_Y16:
341 if (mt9v022->model != V4L2_IDENT_MT9V022IX7ATM)
342 return -EINVAL;
343 break;
344 case V4L2_PIX_FMT_SBGGR8:
345 case V4L2_PIX_FMT_SBGGR16:
346 if (mt9v022->model != V4L2_IDENT_MT9V022IX7ATC)
347 return -EINVAL;
348 break;
349 case 0:
350 /* No format change, only geometry */
351 break;
352 default:
353 return -EINVAL;
354 }
355
356 /* No support for scaling on this camera, just crop. */
357 return mt9v022_set_crop(icd, &rect);
358}
359
406static int mt9v022_try_fmt(struct soc_camera_device *icd, 360static int mt9v022_try_fmt(struct soc_camera_device *icd,
407 struct v4l2_format *f) 361 struct v4l2_format *f)
408{ 362{
@@ -544,6 +498,7 @@ static struct soc_camera_ops mt9v022_ops = {
544 .release = mt9v022_release, 498 .release = mt9v022_release,
545 .start_capture = mt9v022_start_capture, 499 .start_capture = mt9v022_start_capture,
546 .stop_capture = mt9v022_stop_capture, 500 .stop_capture = mt9v022_stop_capture,
501 .set_crop = mt9v022_set_crop,
547 .set_fmt = mt9v022_set_fmt, 502 .set_fmt = mt9v022_set_fmt,
548 .try_fmt = mt9v022_try_fmt, 503 .try_fmt = mt9v022_try_fmt,
549 .set_bus_param = mt9v022_set_bus_param, 504 .set_bus_param = mt9v022_set_bus_param,
@@ -699,6 +654,7 @@ static int mt9v022_video_probe(struct soc_camera_device *icd)
699 struct soc_camera_link *icl = mt9v022->client->dev.platform_data; 654 struct soc_camera_link *icl = mt9v022->client->dev.platform_data;
700 s32 data; 655 s32 data;
701 int ret; 656 int ret;
657 unsigned long flags;
702 658
703 if (!icd->dev.parent || 659 if (!icd->dev.parent ||
704 to_soc_camera_host(icd->dev.parent)->nr != icd->iface) 660 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
@@ -732,22 +688,36 @@ static int mt9v022_video_probe(struct soc_camera_device *icd)
732 ret = reg_write(icd, MT9V022_PIXEL_OPERATION_MODE, 4 | 0x11); 688 ret = reg_write(icd, MT9V022_PIXEL_OPERATION_MODE, 4 | 0x11);
733 mt9v022->model = V4L2_IDENT_MT9V022IX7ATC; 689 mt9v022->model = V4L2_IDENT_MT9V022IX7ATC;
734 icd->formats = mt9v022_colour_formats; 690 icd->formats = mt9v022_colour_formats;
735 if (gpio_is_valid(icl->gpio))
736 icd->num_formats = ARRAY_SIZE(mt9v022_colour_formats);
737 else
738 icd->num_formats = 1;
739 } else { 691 } else {
740 ret = reg_write(icd, MT9V022_PIXEL_OPERATION_MODE, 0x11); 692 ret = reg_write(icd, MT9V022_PIXEL_OPERATION_MODE, 0x11);
741 mt9v022->model = V4L2_IDENT_MT9V022IX7ATM; 693 mt9v022->model = V4L2_IDENT_MT9V022IX7ATM;
742 icd->formats = mt9v022_monochrome_formats; 694 icd->formats = mt9v022_monochrome_formats;
743 if (gpio_is_valid(icl->gpio))
744 icd->num_formats = ARRAY_SIZE(mt9v022_monochrome_formats);
745 else
746 icd->num_formats = 1;
747 } 695 }
748 696
749 if (!ret) 697 if (ret < 0)
750 ret = soc_camera_video_start(icd); 698 goto eisis;
699
700 icd->num_formats = 0;
701
702 /*
703 * This is a 10bit sensor, so by default we only allow 10bit.
704 * The platform may support different bus widths due to
705 * different routing of the data lines.
706 */
707 if (icl->query_bus_param)
708 flags = icl->query_bus_param(icl);
709 else
710 flags = SOCAM_DATAWIDTH_10;
711
712 if (flags & SOCAM_DATAWIDTH_10)
713 icd->num_formats++;
714 else
715 icd->formats++;
716
717 if (flags & SOCAM_DATAWIDTH_8)
718 icd->num_formats++;
719
720 ret = soc_camera_video_start(icd);
751 if (ret < 0) 721 if (ret < 0)
752 goto eisis; 722 goto eisis;
753 723
@@ -812,14 +782,6 @@ static int mt9v022_probe(struct i2c_client *client,
812 icd->height_max = 480; 782 icd->height_max = 480;
813 icd->y_skip_top = 1; 783 icd->y_skip_top = 1;
814 icd->iface = icl->bus_id; 784 icd->iface = icl->bus_id;
815 /* Default datawidth - this is the only width this camera (normally)
816 * supports. It is only with extra logic that it can support
817 * other widths. Therefore it seems to be a sensible default. */
818 mt9v022->datawidth = 10;
819
820 ret = bus_switch_request(mt9v022, icl);
821 if (ret)
822 goto eswinit;
823 785
824 ret = soc_camera_device_register(icd); 786 ret = soc_camera_device_register(icd);
825 if (ret) 787 if (ret)
@@ -828,8 +790,6 @@ static int mt9v022_probe(struct i2c_client *client,
828 return 0; 790 return 0;
829 791
830eisdr: 792eisdr:
831 bus_switch_release(mt9v022);
832eswinit:
833 kfree(mt9v022); 793 kfree(mt9v022);
834 return ret; 794 return ret;
835} 795}
@@ -839,7 +799,6 @@ static int mt9v022_remove(struct i2c_client *client)
839 struct mt9v022 *mt9v022 = i2c_get_clientdata(client); 799 struct mt9v022 *mt9v022 = i2c_get_clientdata(client);
840 800
841 soc_camera_device_unregister(&mt9v022->icd); 801 soc_camera_device_unregister(&mt9v022->icd);
842 bus_switch_release(mt9v022);
843 kfree(mt9v022); 802 kfree(mt9v022);
844 803
845 return 0; 804 return 0;
diff --git a/drivers/media/video/mx3_camera.c b/drivers/media/video/mx3_camera.c
new file mode 100644
index 000000000000..70629e172e65
--- /dev/null
+++ b/drivers/media/video/mx3_camera.c
@@ -0,0 +1,1220 @@
1/*
2 * V4L2 Driver for i.MX3x camera host
3 *
4 * Copyright (C) 2008
5 * Guennadi Liakhovetski, DENX Software Engineering, <lg@denx.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 version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/init.h>
13#include <linux/module.h>
14#include <linux/version.h>
15#include <linux/videodev2.h>
16#include <linux/platform_device.h>
17#include <linux/clk.h>
18#include <linux/vmalloc.h>
19#include <linux/interrupt.h>
20
21#include <media/v4l2-common.h>
22#include <media/v4l2-dev.h>
23#include <media/videobuf-dma-contig.h>
24#include <media/soc_camera.h>
25
26#include <mach/ipu.h>
27#include <mach/mx3_camera.h>
28
29#define MX3_CAM_DRV_NAME "mx3-camera"
30
31/* CMOS Sensor Interface Registers */
32#define CSI_REG_START 0x60
33
34#define CSI_SENS_CONF (0x60 - CSI_REG_START)
35#define CSI_SENS_FRM_SIZE (0x64 - CSI_REG_START)
36#define CSI_ACT_FRM_SIZE (0x68 - CSI_REG_START)
37#define CSI_OUT_FRM_CTRL (0x6C - CSI_REG_START)
38#define CSI_TST_CTRL (0x70 - CSI_REG_START)
39#define CSI_CCIR_CODE_1 (0x74 - CSI_REG_START)
40#define CSI_CCIR_CODE_2 (0x78 - CSI_REG_START)
41#define CSI_CCIR_CODE_3 (0x7C - CSI_REG_START)
42#define CSI_FLASH_STROBE_1 (0x80 - CSI_REG_START)
43#define CSI_FLASH_STROBE_2 (0x84 - CSI_REG_START)
44
45#define CSI_SENS_CONF_VSYNC_POL_SHIFT 0
46#define CSI_SENS_CONF_HSYNC_POL_SHIFT 1
47#define CSI_SENS_CONF_DATA_POL_SHIFT 2
48#define CSI_SENS_CONF_PIX_CLK_POL_SHIFT 3
49#define CSI_SENS_CONF_SENS_PRTCL_SHIFT 4
50#define CSI_SENS_CONF_SENS_CLKSRC_SHIFT 7
51#define CSI_SENS_CONF_DATA_FMT_SHIFT 8
52#define CSI_SENS_CONF_DATA_WIDTH_SHIFT 10
53#define CSI_SENS_CONF_EXT_VSYNC_SHIFT 15
54#define CSI_SENS_CONF_DIVRATIO_SHIFT 16
55
56#define CSI_SENS_CONF_DATA_FMT_RGB_YUV444 (0UL << CSI_SENS_CONF_DATA_FMT_SHIFT)
57#define CSI_SENS_CONF_DATA_FMT_YUV422 (2UL << CSI_SENS_CONF_DATA_FMT_SHIFT)
58#define CSI_SENS_CONF_DATA_FMT_BAYER (3UL << CSI_SENS_CONF_DATA_FMT_SHIFT)
59
60#define MAX_VIDEO_MEM 16
61
62struct mx3_camera_buffer {
63 /* common v4l buffer stuff -- must be first */
64 struct videobuf_buffer vb;
65 const struct soc_camera_data_format *fmt;
66
67 /* One descriptot per scatterlist (per frame) */
68 struct dma_async_tx_descriptor *txd;
69
70 /* We have to "build" a scatterlist ourselves - one element per frame */
71 struct scatterlist sg;
72};
73
74/**
75 * struct mx3_camera_dev - i.MX3x camera (CSI) object
76 * @dev: camera device, to which the coherent buffer is attached
77 * @icd: currently attached camera sensor
78 * @clk: pointer to clock
79 * @base: remapped register base address
80 * @pdata: platform data
81 * @platform_flags: platform flags
82 * @mclk: master clock frequency in Hz
83 * @capture: list of capture videobuffers
84 * @lock: protects video buffer lists
85 * @active: active video buffer
86 * @idmac_channel: array of pointers to IPU DMAC DMA channels
87 * @soc_host: embedded soc_host object
88 */
89struct mx3_camera_dev {
90 struct device *dev;
91 /*
92 * i.MX3x is only supposed to handle one camera on its Camera Sensor
93 * Interface. If anyone ever builds hardware to enable more than one
94 * camera _simultaneously_, they will have to modify this driver too
95 */
96 struct soc_camera_device *icd;
97 struct clk *clk;
98
99 void __iomem *base;
100
101 struct mx3_camera_pdata *pdata;
102
103 unsigned long platform_flags;
104 unsigned long mclk;
105
106 struct list_head capture;
107 spinlock_t lock; /* Protects video buffer lists */
108 struct mx3_camera_buffer *active;
109
110 /* IDMAC / dmaengine interface */
111 struct idmac_channel *idmac_channel[1]; /* We need one channel */
112
113 struct soc_camera_host soc_host;
114};
115
116struct dma_chan_request {
117 struct mx3_camera_dev *mx3_cam;
118 enum ipu_channel id;
119};
120
121static int mx3_camera_set_bus_param(struct soc_camera_device *icd, __u32 pixfmt);
122
123static u32 csi_reg_read(struct mx3_camera_dev *mx3, off_t reg)
124{
125 return __raw_readl(mx3->base + reg);
126}
127
128static void csi_reg_write(struct mx3_camera_dev *mx3, u32 value, off_t reg)
129{
130 __raw_writel(value, mx3->base + reg);
131}
132
133/* Called from the IPU IDMAC ISR */
134static void mx3_cam_dma_done(void *arg)
135{
136 struct idmac_tx_desc *desc = to_tx_desc(arg);
137 struct dma_chan *chan = desc->txd.chan;
138 struct idmac_channel *ichannel = to_idmac_chan(chan);
139 struct mx3_camera_dev *mx3_cam = ichannel->client;
140 struct videobuf_buffer *vb;
141
142 dev_dbg(chan->device->dev, "callback cookie %d, active DMA 0x%08x\n",
143 desc->txd.cookie, mx3_cam->active ? sg_dma_address(&mx3_cam->active->sg) : 0);
144
145 spin_lock(&mx3_cam->lock);
146 if (mx3_cam->active) {
147 vb = &mx3_cam->active->vb;
148
149 list_del_init(&vb->queue);
150 vb->state = VIDEOBUF_DONE;
151 do_gettimeofday(&vb->ts);
152 vb->field_count++;
153 wake_up(&vb->done);
154 }
155
156 if (list_empty(&mx3_cam->capture)) {
157 mx3_cam->active = NULL;
158 spin_unlock(&mx3_cam->lock);
159
160 /*
161 * stop capture - without further buffers IPU_CHA_BUF0_RDY will
162 * not get updated
163 */
164 return;
165 }
166
167 mx3_cam->active = list_entry(mx3_cam->capture.next,
168 struct mx3_camera_buffer, vb.queue);
169 mx3_cam->active->vb.state = VIDEOBUF_ACTIVE;
170 spin_unlock(&mx3_cam->lock);
171}
172
173static void free_buffer(struct videobuf_queue *vq, struct mx3_camera_buffer *buf)
174{
175 struct soc_camera_device *icd = vq->priv_data;
176 struct videobuf_buffer *vb = &buf->vb;
177 struct dma_async_tx_descriptor *txd = buf->txd;
178 struct idmac_channel *ichan;
179
180 BUG_ON(in_interrupt());
181
182 dev_dbg(&icd->dev, "%s (vb=0x%p) 0x%08lx %d\n", __func__,
183 vb, vb->baddr, vb->bsize);
184
185 /*
186 * This waits until this buffer is out of danger, i.e., until it is no
187 * longer in STATE_QUEUED or STATE_ACTIVE
188 */
189 videobuf_waiton(vb, 0, 0);
190 if (txd) {
191 ichan = to_idmac_chan(txd->chan);
192 async_tx_ack(txd);
193 }
194 videobuf_dma_contig_free(vq, vb);
195 buf->txd = NULL;
196
197 vb->state = VIDEOBUF_NEEDS_INIT;
198}
199
200/*
201 * Videobuf operations
202 */
203
204/*
205 * Calculate the __buffer__ (not data) size and number of buffers.
206 * Called with .vb_lock held
207 */
208static int mx3_videobuf_setup(struct videobuf_queue *vq, unsigned int *count,
209 unsigned int *size)
210{
211 struct soc_camera_device *icd = vq->priv_data;
212 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
213 struct mx3_camera_dev *mx3_cam = ici->priv;
214 /*
215 * bits-per-pixel (depth) as specified in camera's pixel format does
216 * not necessarily match what the camera interface writes to RAM, but
217 * it should be good enough for now.
218 */
219 unsigned int bpp = DIV_ROUND_UP(icd->current_fmt->depth, 8);
220
221 if (!mx3_cam->idmac_channel[0])
222 return -EINVAL;
223
224 *size = icd->width * icd->height * bpp;
225
226 if (!*count)
227 *count = 32;
228
229 if (*size * *count > MAX_VIDEO_MEM * 1024 * 1024)
230 *count = MAX_VIDEO_MEM * 1024 * 1024 / *size;
231
232 return 0;
233}
234
235/* Called with .vb_lock held */
236static int mx3_videobuf_prepare(struct videobuf_queue *vq,
237 struct videobuf_buffer *vb, enum v4l2_field field)
238{
239 struct soc_camera_device *icd = vq->priv_data;
240 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
241 struct mx3_camera_dev *mx3_cam = ici->priv;
242 struct mx3_camera_buffer *buf =
243 container_of(vb, struct mx3_camera_buffer, vb);
244 /* current_fmt _must_ always be set */
245 size_t new_size = icd->width * icd->height *
246 ((icd->current_fmt->depth + 7) >> 3);
247 int ret;
248
249 /*
250 * I think, in buf_prepare you only have to protect global data,
251 * the actual buffer is yours
252 */
253
254 if (buf->fmt != icd->current_fmt ||
255 vb->width != icd->width ||
256 vb->height != icd->height ||
257 vb->field != field) {
258 buf->fmt = icd->current_fmt;
259 vb->width = icd->width;
260 vb->height = icd->height;
261 vb->field = field;
262 if (vb->state != VIDEOBUF_NEEDS_INIT)
263 free_buffer(vq, buf);
264 }
265
266 if (vb->baddr && vb->bsize < new_size) {
267 /* User provided buffer, but it is too small */
268 ret = -ENOMEM;
269 goto out;
270 }
271
272 if (vb->state == VIDEOBUF_NEEDS_INIT) {
273 struct idmac_channel *ichan = mx3_cam->idmac_channel[0];
274 struct scatterlist *sg = &buf->sg;
275
276 /*
277 * The total size of video-buffers that will be allocated / mapped.
278 * *size that we calculated in videobuf_setup gets assigned to
279 * vb->bsize, and now we use the same calculation to get vb->size.
280 */
281 vb->size = new_size;
282
283 /* This actually (allocates and) maps buffers */
284 ret = videobuf_iolock(vq, vb, NULL);
285 if (ret)
286 goto fail;
287
288 /*
289 * We will have to configure the IDMAC channel. It has two slots
290 * for DMA buffers, we shall enter the first two buffers there,
291 * and then submit new buffers in DMA-ready interrupts
292 */
293 sg_init_table(sg, 1);
294 sg_dma_address(sg) = videobuf_to_dma_contig(vb);
295 sg_dma_len(sg) = vb->size;
296
297 buf->txd = ichan->dma_chan.device->device_prep_slave_sg(
298 &ichan->dma_chan, sg, 1, DMA_FROM_DEVICE,
299 DMA_PREP_INTERRUPT);
300 if (!buf->txd) {
301 ret = -EIO;
302 goto fail;
303 }
304
305 buf->txd->callback_param = buf->txd;
306 buf->txd->callback = mx3_cam_dma_done;
307
308 vb->state = VIDEOBUF_PREPARED;
309 }
310
311 return 0;
312
313fail:
314 free_buffer(vq, buf);
315out:
316 return ret;
317}
318
319static enum pixel_fmt fourcc_to_ipu_pix(__u32 fourcc)
320{
321 /* Add more formats as need arises and test possibilities appear... */
322 switch (fourcc) {
323 case V4L2_PIX_FMT_RGB565:
324 return IPU_PIX_FMT_RGB565;
325 case V4L2_PIX_FMT_RGB24:
326 return IPU_PIX_FMT_RGB24;
327 case V4L2_PIX_FMT_RGB332:
328 return IPU_PIX_FMT_RGB332;
329 case V4L2_PIX_FMT_YUV422P:
330 return IPU_PIX_FMT_YVU422P;
331 default:
332 return IPU_PIX_FMT_GENERIC;
333 }
334}
335
336/* Called with .vb_lock held */
337static void mx3_videobuf_queue(struct videobuf_queue *vq,
338 struct videobuf_buffer *vb)
339{
340 struct soc_camera_device *icd = vq->priv_data;
341 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
342 struct mx3_camera_dev *mx3_cam = ici->priv;
343 struct mx3_camera_buffer *buf =
344 container_of(vb, struct mx3_camera_buffer, vb);
345 struct dma_async_tx_descriptor *txd = buf->txd;
346 struct idmac_channel *ichan = to_idmac_chan(txd->chan);
347 struct idmac_video_param *video = &ichan->params.video;
348 const struct soc_camera_data_format *data_fmt = icd->current_fmt;
349 dma_cookie_t cookie;
350 unsigned long flags;
351
352 /* This is the configuration of one sg-element */
353 video->out_pixel_fmt = fourcc_to_ipu_pix(data_fmt->fourcc);
354 video->out_width = icd->width;
355 video->out_height = icd->height;
356 video->out_stride = icd->width;
357
358#ifdef DEBUG
359 /* helps to see what DMA actually has written */
360 memset((void *)vb->baddr, 0xaa, vb->bsize);
361#endif
362
363 spin_lock_irqsave(&mx3_cam->lock, flags);
364
365 list_add_tail(&vb->queue, &mx3_cam->capture);
366
367 if (!mx3_cam->active) {
368 mx3_cam->active = buf;
369 vb->state = VIDEOBUF_ACTIVE;
370 } else {
371 vb->state = VIDEOBUF_QUEUED;
372 }
373
374 spin_unlock_irqrestore(&mx3_cam->lock, flags);
375
376 cookie = txd->tx_submit(txd);
377 dev_dbg(&icd->dev, "Submitted cookie %d DMA 0x%08x\n", cookie, sg_dma_address(&buf->sg));
378 if (cookie >= 0)
379 return;
380
381 /* Submit error */
382 vb->state = VIDEOBUF_PREPARED;
383
384 spin_lock_irqsave(&mx3_cam->lock, flags);
385
386 list_del_init(&vb->queue);
387
388 if (mx3_cam->active == buf)
389 mx3_cam->active = NULL;
390
391 spin_unlock_irqrestore(&mx3_cam->lock, flags);
392}
393
394/* Called with .vb_lock held */
395static void mx3_videobuf_release(struct videobuf_queue *vq,
396 struct videobuf_buffer *vb)
397{
398 struct soc_camera_device *icd = vq->priv_data;
399 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
400 struct mx3_camera_dev *mx3_cam = ici->priv;
401 struct mx3_camera_buffer *buf =
402 container_of(vb, struct mx3_camera_buffer, vb);
403 unsigned long flags;
404
405 dev_dbg(&icd->dev, "Release%s DMA 0x%08x (state %d), queue %sempty\n",
406 mx3_cam->active == buf ? " active" : "", sg_dma_address(&buf->sg),
407 vb->state, list_empty(&vb->queue) ? "" : "not ");
408 spin_lock_irqsave(&mx3_cam->lock, flags);
409 if ((vb->state == VIDEOBUF_ACTIVE || vb->state == VIDEOBUF_QUEUED) &&
410 !list_empty(&vb->queue)) {
411 vb->state = VIDEOBUF_ERROR;
412
413 list_del_init(&vb->queue);
414 if (mx3_cam->active == buf)
415 mx3_cam->active = NULL;
416 }
417 spin_unlock_irqrestore(&mx3_cam->lock, flags);
418 free_buffer(vq, buf);
419}
420
421static struct videobuf_queue_ops mx3_videobuf_ops = {
422 .buf_setup = mx3_videobuf_setup,
423 .buf_prepare = mx3_videobuf_prepare,
424 .buf_queue = mx3_videobuf_queue,
425 .buf_release = mx3_videobuf_release,
426};
427
428static void mx3_camera_init_videobuf(struct videobuf_queue *q,
429 struct soc_camera_device *icd)
430{
431 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
432 struct mx3_camera_dev *mx3_cam = ici->priv;
433
434 videobuf_queue_dma_contig_init(q, &mx3_videobuf_ops, mx3_cam->dev,
435 &mx3_cam->lock,
436 V4L2_BUF_TYPE_VIDEO_CAPTURE,
437 V4L2_FIELD_NONE,
438 sizeof(struct mx3_camera_buffer), icd);
439}
440
441/* First part of ipu_csi_init_interface() */
442static void mx3_camera_activate(struct mx3_camera_dev *mx3_cam,
443 struct soc_camera_device *icd)
444{
445 u32 conf;
446 long rate;
447
448 /* Set default size: ipu_csi_set_window_size() */
449 csi_reg_write(mx3_cam, (640 - 1) | ((480 - 1) << 16), CSI_ACT_FRM_SIZE);
450 /* ...and position to 0:0: ipu_csi_set_window_pos() */
451 conf = csi_reg_read(mx3_cam, CSI_OUT_FRM_CTRL) & 0xffff0000;
452 csi_reg_write(mx3_cam, conf, CSI_OUT_FRM_CTRL);
453
454 /* We use only gated clock synchronisation mode so far */
455 conf = 0 << CSI_SENS_CONF_SENS_PRTCL_SHIFT;
456
457 /* Set generic data, platform-biggest bus-width */
458 conf |= CSI_SENS_CONF_DATA_FMT_BAYER;
459
460 if (mx3_cam->platform_flags & MX3_CAMERA_DATAWIDTH_15)
461 conf |= 3 << CSI_SENS_CONF_DATA_WIDTH_SHIFT;
462 else if (mx3_cam->platform_flags & MX3_CAMERA_DATAWIDTH_10)
463 conf |= 2 << CSI_SENS_CONF_DATA_WIDTH_SHIFT;
464 else if (mx3_cam->platform_flags & MX3_CAMERA_DATAWIDTH_8)
465 conf |= 1 << CSI_SENS_CONF_DATA_WIDTH_SHIFT;
466 else/* if (mx3_cam->platform_flags & MX3_CAMERA_DATAWIDTH_4)*/
467 conf |= 0 << CSI_SENS_CONF_DATA_WIDTH_SHIFT;
468
469 if (mx3_cam->platform_flags & MX3_CAMERA_CLK_SRC)
470 conf |= 1 << CSI_SENS_CONF_SENS_CLKSRC_SHIFT;
471 if (mx3_cam->platform_flags & MX3_CAMERA_EXT_VSYNC)
472 conf |= 1 << CSI_SENS_CONF_EXT_VSYNC_SHIFT;
473 if (mx3_cam->platform_flags & MX3_CAMERA_DP)
474 conf |= 1 << CSI_SENS_CONF_DATA_POL_SHIFT;
475 if (mx3_cam->platform_flags & MX3_CAMERA_PCP)
476 conf |= 1 << CSI_SENS_CONF_PIX_CLK_POL_SHIFT;
477 if (mx3_cam->platform_flags & MX3_CAMERA_HSP)
478 conf |= 1 << CSI_SENS_CONF_HSYNC_POL_SHIFT;
479 if (mx3_cam->platform_flags & MX3_CAMERA_VSP)
480 conf |= 1 << CSI_SENS_CONF_VSYNC_POL_SHIFT;
481
482 /* ipu_csi_init_interface() */
483 csi_reg_write(mx3_cam, conf, CSI_SENS_CONF);
484
485 clk_enable(mx3_cam->clk);
486 rate = clk_round_rate(mx3_cam->clk, mx3_cam->mclk);
487 dev_dbg(&icd->dev, "Set SENS_CONF to %x, rate %ld\n", conf, rate);
488 if (rate)
489 clk_set_rate(mx3_cam->clk, rate);
490}
491
492/* Called with .video_lock held */
493static int mx3_camera_add_device(struct soc_camera_device *icd)
494{
495 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
496 struct mx3_camera_dev *mx3_cam = ici->priv;
497 int ret;
498
499 if (mx3_cam->icd) {
500 ret = -EBUSY;
501 goto ebusy;
502 }
503
504 mx3_camera_activate(mx3_cam, icd);
505 ret = icd->ops->init(icd);
506 if (ret < 0) {
507 clk_disable(mx3_cam->clk);
508 goto einit;
509 }
510
511 mx3_cam->icd = icd;
512
513einit:
514ebusy:
515 if (!ret)
516 dev_info(&icd->dev, "MX3 Camera driver attached to camera %d\n",
517 icd->devnum);
518
519 return ret;
520}
521
522/* Called with .video_lock held */
523static void mx3_camera_remove_device(struct soc_camera_device *icd)
524{
525 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
526 struct mx3_camera_dev *mx3_cam = ici->priv;
527 struct idmac_channel **ichan = &mx3_cam->idmac_channel[0];
528
529 BUG_ON(icd != mx3_cam->icd);
530
531 if (*ichan) {
532 dma_release_channel(&(*ichan)->dma_chan);
533 *ichan = NULL;
534 }
535
536 icd->ops->release(icd);
537
538 clk_disable(mx3_cam->clk);
539
540 mx3_cam->icd = NULL;
541
542 dev_info(&icd->dev, "MX3 Camera driver detached from camera %d\n",
543 icd->devnum);
544}
545
546static bool channel_change_requested(struct soc_camera_device *icd,
547 struct v4l2_rect *rect)
548{
549 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
550 struct mx3_camera_dev *mx3_cam = ici->priv;
551 struct idmac_channel *ichan = mx3_cam->idmac_channel[0];
552
553 /* Do buffers have to be re-allocated or channel re-configured? */
554 return ichan && rect->width * rect->height > icd->width * icd->height;
555}
556
557static int test_platform_param(struct mx3_camera_dev *mx3_cam,
558 unsigned char buswidth, unsigned long *flags)
559{
560 /*
561 * Platform specified synchronization and pixel clock polarities are
562 * only a recommendation and are only used during probing. MX3x
563 * camera interface only works in master mode, i.e., uses HSYNC and
564 * VSYNC signals from the sensor
565 */
566 *flags = SOCAM_MASTER |
567 SOCAM_HSYNC_ACTIVE_HIGH |
568 SOCAM_HSYNC_ACTIVE_LOW |
569 SOCAM_VSYNC_ACTIVE_HIGH |
570 SOCAM_VSYNC_ACTIVE_LOW |
571 SOCAM_PCLK_SAMPLE_RISING |
572 SOCAM_PCLK_SAMPLE_FALLING |
573 SOCAM_DATA_ACTIVE_HIGH |
574 SOCAM_DATA_ACTIVE_LOW;
575
576 /* If requested data width is supported by the platform, use it or any
577 * possible lower value - i.MX31 is smart enough to schift bits */
578 switch (buswidth) {
579 case 15:
580 if (!(mx3_cam->platform_flags & MX3_CAMERA_DATAWIDTH_15))
581 return -EINVAL;
582 *flags |= SOCAM_DATAWIDTH_15 | SOCAM_DATAWIDTH_10 |
583 SOCAM_DATAWIDTH_8 | SOCAM_DATAWIDTH_4;
584 break;
585 case 10:
586 if (!(mx3_cam->platform_flags & MX3_CAMERA_DATAWIDTH_10))
587 return -EINVAL;
588 *flags |= SOCAM_DATAWIDTH_10 | SOCAM_DATAWIDTH_8 |
589 SOCAM_DATAWIDTH_4;
590 break;
591 case 8:
592 if (!(mx3_cam->platform_flags & MX3_CAMERA_DATAWIDTH_8))
593 return -EINVAL;
594 *flags |= SOCAM_DATAWIDTH_8 | SOCAM_DATAWIDTH_4;
595 break;
596 case 4:
597 if (!(mx3_cam->platform_flags & MX3_CAMERA_DATAWIDTH_4))
598 return -EINVAL;
599 *flags |= SOCAM_DATAWIDTH_4;
600 break;
601 default:
602 dev_info(mx3_cam->dev, "Unsupported bus width %d\n", buswidth);
603 return -EINVAL;
604 }
605
606 return 0;
607}
608
609static int mx3_camera_try_bus_param(struct soc_camera_device *icd,
610 const unsigned int depth)
611{
612 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
613 struct mx3_camera_dev *mx3_cam = ici->priv;
614 unsigned long bus_flags, camera_flags;
615 int ret = test_platform_param(mx3_cam, depth, &bus_flags);
616
617 dev_dbg(&ici->dev, "requested bus width %d bit: %d\n", depth, ret);
618
619 if (ret < 0)
620 return ret;
621
622 camera_flags = icd->ops->query_bus_param(icd);
623
624 ret = soc_camera_bus_param_compatible(camera_flags, bus_flags);
625 if (ret < 0)
626 dev_warn(&icd->dev, "Flags incompatible: camera %lx, host %lx\n",
627 camera_flags, bus_flags);
628
629 return ret;
630}
631
632static bool chan_filter(struct dma_chan *chan, void *arg)
633{
634 struct dma_chan_request *rq = arg;
635 struct mx3_camera_pdata *pdata;
636
637 if (!rq)
638 return false;
639
640 pdata = rq->mx3_cam->dev->platform_data;
641
642 return rq->id == chan->chan_id &&
643 pdata->dma_dev == chan->device->dev;
644}
645
646static const struct soc_camera_data_format mx3_camera_formats[] = {
647 {
648 .name = "Bayer (sRGB) 8 bit",
649 .depth = 8,
650 .fourcc = V4L2_PIX_FMT_SBGGR8,
651 .colorspace = V4L2_COLORSPACE_SRGB,
652 }, {
653 .name = "Monochrome 8 bit",
654 .depth = 8,
655 .fourcc = V4L2_PIX_FMT_GREY,
656 .colorspace = V4L2_COLORSPACE_JPEG,
657 },
658};
659
660static bool buswidth_supported(struct soc_camera_host *ici, int depth)
661{
662 struct mx3_camera_dev *mx3_cam = ici->priv;
663
664 switch (depth) {
665 case 4:
666 return !!(mx3_cam->platform_flags & MX3_CAMERA_DATAWIDTH_4);
667 case 8:
668 return !!(mx3_cam->platform_flags & MX3_CAMERA_DATAWIDTH_8);
669 case 10:
670 return !!(mx3_cam->platform_flags & MX3_CAMERA_DATAWIDTH_10);
671 case 15:
672 return !!(mx3_cam->platform_flags & MX3_CAMERA_DATAWIDTH_15);
673 }
674 return false;
675}
676
677static int mx3_camera_get_formats(struct soc_camera_device *icd, int idx,
678 struct soc_camera_format_xlate *xlate)
679{
680 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
681 int formats = 0, buswidth, ret;
682
683 buswidth = icd->formats[idx].depth;
684
685 if (!buswidth_supported(ici, buswidth))
686 return 0;
687
688 ret = mx3_camera_try_bus_param(icd, buswidth);
689 if (ret < 0)
690 return 0;
691
692 switch (icd->formats[idx].fourcc) {
693 case V4L2_PIX_FMT_SGRBG10:
694 formats++;
695 if (xlate) {
696 xlate->host_fmt = &mx3_camera_formats[0];
697 xlate->cam_fmt = icd->formats + idx;
698 xlate->buswidth = buswidth;
699 xlate++;
700 dev_dbg(&ici->dev, "Providing format %s using %s\n",
701 mx3_camera_formats[0].name,
702 icd->formats[idx].name);
703 }
704 goto passthrough;
705 case V4L2_PIX_FMT_Y16:
706 formats++;
707 if (xlate) {
708 xlate->host_fmt = &mx3_camera_formats[1];
709 xlate->cam_fmt = icd->formats + idx;
710 xlate->buswidth = buswidth;
711 xlate++;
712 dev_dbg(&ici->dev, "Providing format %s using %s\n",
713 mx3_camera_formats[0].name,
714 icd->formats[idx].name);
715 }
716 default:
717passthrough:
718 /* Generic pass-through */
719 formats++;
720 if (xlate) {
721 xlate->host_fmt = icd->formats + idx;
722 xlate->cam_fmt = icd->formats + idx;
723 xlate->buswidth = buswidth;
724 xlate++;
725 dev_dbg(&ici->dev,
726 "Providing format %s in pass-through mode\n",
727 icd->formats[idx].name);
728 }
729 }
730
731 return formats;
732}
733
734static void configure_geometry(struct mx3_camera_dev *mx3_cam,
735 struct v4l2_rect *rect)
736{
737 u32 ctrl, width_field, height_field;
738
739 /* Setup frame size - this cannot be changed on-the-fly... */
740 width_field = rect->width - 1;
741 height_field = rect->height - 1;
742 csi_reg_write(mx3_cam, width_field | (height_field << 16), CSI_SENS_FRM_SIZE);
743
744 csi_reg_write(mx3_cam, width_field << 16, CSI_FLASH_STROBE_1);
745 csi_reg_write(mx3_cam, (height_field << 16) | 0x22, CSI_FLASH_STROBE_2);
746
747 csi_reg_write(mx3_cam, width_field | (height_field << 16), CSI_ACT_FRM_SIZE);
748
749 /* ...and position */
750 ctrl = csi_reg_read(mx3_cam, CSI_OUT_FRM_CTRL) & 0xffff0000;
751 /* Sensor does the cropping */
752 csi_reg_write(mx3_cam, ctrl | 0 | (0 << 8), CSI_OUT_FRM_CTRL);
753
754 /*
755 * No need to free resources here if we fail, we'll see if we need to
756 * do this next time we are called
757 */
758}
759
760static int acquire_dma_channel(struct mx3_camera_dev *mx3_cam)
761{
762 dma_cap_mask_t mask;
763 struct dma_chan *chan;
764 struct idmac_channel **ichan = &mx3_cam->idmac_channel[0];
765 /* We have to use IDMAC_IC_7 for Bayer / generic data */
766 struct dma_chan_request rq = {.mx3_cam = mx3_cam,
767 .id = IDMAC_IC_7};
768
769 if (*ichan) {
770 struct videobuf_buffer *vb, *_vb;
771 dma_release_channel(&(*ichan)->dma_chan);
772 *ichan = NULL;
773 mx3_cam->active = NULL;
774 list_for_each_entry_safe(vb, _vb, &mx3_cam->capture, queue) {
775 list_del_init(&vb->queue);
776 vb->state = VIDEOBUF_ERROR;
777 wake_up(&vb->done);
778 }
779 }
780
781 dma_cap_zero(mask);
782 dma_cap_set(DMA_SLAVE, mask);
783 dma_cap_set(DMA_PRIVATE, mask);
784 chan = dma_request_channel(mask, chan_filter, &rq);
785 if (!chan)
786 return -EBUSY;
787
788 *ichan = to_idmac_chan(chan);
789 (*ichan)->client = mx3_cam;
790
791 return 0;
792}
793
794static int mx3_camera_set_crop(struct soc_camera_device *icd,
795 struct v4l2_rect *rect)
796{
797 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
798 struct mx3_camera_dev *mx3_cam = ici->priv;
799
800 /*
801 * We now know pixel formats and can decide upon DMA-channel(s)
802 * So far only direct camera-to-memory is supported
803 */
804 if (channel_change_requested(icd, rect)) {
805 int ret = acquire_dma_channel(mx3_cam);
806 if (ret < 0)
807 return ret;
808 }
809
810 configure_geometry(mx3_cam, rect);
811
812 return icd->ops->set_crop(icd, rect);
813}
814
815static int mx3_camera_set_fmt(struct soc_camera_device *icd,
816 struct v4l2_format *f)
817{
818 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
819 struct mx3_camera_dev *mx3_cam = ici->priv;
820 const struct soc_camera_format_xlate *xlate;
821 struct v4l2_pix_format *pix = &f->fmt.pix;
822 struct v4l2_rect rect = {
823 .left = icd->x_current,
824 .top = icd->y_current,
825 .width = pix->width,
826 .height = pix->height,
827 };
828 int ret;
829
830 xlate = soc_camera_xlate_by_fourcc(icd, pix->pixelformat);
831 if (!xlate) {
832 dev_warn(&ici->dev, "Format %x not found\n", pix->pixelformat);
833 return -EINVAL;
834 }
835
836 ret = acquire_dma_channel(mx3_cam);
837 if (ret < 0)
838 return ret;
839
840 /*
841 * Might have to perform a complete interface initialisation like in
842 * ipu_csi_init_interface() in mxc_v4l2_s_param(). Also consider
843 * mxc_v4l2_s_fmt()
844 */
845
846 configure_geometry(mx3_cam, &rect);
847
848 ret = icd->ops->set_fmt(icd, f);
849 if (!ret) {
850 icd->buswidth = xlate->buswidth;
851 icd->current_fmt = xlate->host_fmt;
852 }
853
854 return ret;
855}
856
857static int mx3_camera_try_fmt(struct soc_camera_device *icd,
858 struct v4l2_format *f)
859{
860 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
861 const struct soc_camera_format_xlate *xlate;
862 struct v4l2_pix_format *pix = &f->fmt.pix;
863 __u32 pixfmt = pix->pixelformat;
864 enum v4l2_field field;
865 int ret;
866
867 xlate = soc_camera_xlate_by_fourcc(icd, pixfmt);
868 if (pixfmt && !xlate) {
869 dev_warn(&ici->dev, "Format %x not found\n", pixfmt);
870 return -EINVAL;
871 }
872
873 /* limit to MX3 hardware capabilities */
874 if (pix->height > 4096)
875 pix->height = 4096;
876 if (pix->width > 4096)
877 pix->width = 4096;
878
879 pix->bytesperline = pix->width *
880 DIV_ROUND_UP(xlate->host_fmt->depth, 8);
881 pix->sizeimage = pix->height * pix->bytesperline;
882
883 /* camera has to see its format, but the user the original one */
884 pix->pixelformat = xlate->cam_fmt->fourcc;
885 /* limit to sensor capabilities */
886 ret = icd->ops->try_fmt(icd, f);
887 pix->pixelformat = xlate->host_fmt->fourcc;
888
889 field = pix->field;
890
891 if (field == V4L2_FIELD_ANY) {
892 pix->field = V4L2_FIELD_NONE;
893 } else if (field != V4L2_FIELD_NONE) {
894 dev_err(&icd->dev, "Field type %d unsupported.\n", field);
895 return -EINVAL;
896 }
897
898 return ret;
899}
900
901static int mx3_camera_reqbufs(struct soc_camera_file *icf,
902 struct v4l2_requestbuffers *p)
903{
904 return 0;
905}
906
907static unsigned int mx3_camera_poll(struct file *file, poll_table *pt)
908{
909 struct soc_camera_file *icf = file->private_data;
910
911 return videobuf_poll_stream(file, &icf->vb_vidq, pt);
912}
913
914static int mx3_camera_querycap(struct soc_camera_host *ici,
915 struct v4l2_capability *cap)
916{
917 /* cap->name is set by the firendly caller:-> */
918 strlcpy(cap->card, "i.MX3x Camera", sizeof(cap->card));
919 cap->version = KERNEL_VERSION(0, 2, 2);
920 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
921
922 return 0;
923}
924
925static int mx3_camera_set_bus_param(struct soc_camera_device *icd, __u32 pixfmt)
926{
927 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
928 struct mx3_camera_dev *mx3_cam = ici->priv;
929 unsigned long bus_flags, camera_flags, common_flags;
930 u32 dw, sens_conf;
931 int ret = test_platform_param(mx3_cam, icd->buswidth, &bus_flags);
932 const struct soc_camera_format_xlate *xlate;
933
934 xlate = soc_camera_xlate_by_fourcc(icd, pixfmt);
935 if (!xlate) {
936 dev_warn(&ici->dev, "Format %x not found\n", pixfmt);
937 return -EINVAL;
938 }
939
940 dev_dbg(&ici->dev, "requested bus width %d bit: %d\n",
941 icd->buswidth, ret);
942
943 if (ret < 0)
944 return ret;
945
946 camera_flags = icd->ops->query_bus_param(icd);
947
948 common_flags = soc_camera_bus_param_compatible(camera_flags, bus_flags);
949 if (!common_flags) {
950 dev_dbg(&ici->dev, "no common flags: camera %lx, host %lx\n",
951 camera_flags, bus_flags);
952 return -EINVAL;
953 }
954
955 /* Make choices, based on platform preferences */
956 if ((common_flags & SOCAM_HSYNC_ACTIVE_HIGH) &&
957 (common_flags & SOCAM_HSYNC_ACTIVE_LOW)) {
958 if (mx3_cam->platform_flags & MX3_CAMERA_HSP)
959 common_flags &= ~SOCAM_HSYNC_ACTIVE_HIGH;
960 else
961 common_flags &= ~SOCAM_HSYNC_ACTIVE_LOW;
962 }
963
964 if ((common_flags & SOCAM_VSYNC_ACTIVE_HIGH) &&
965 (common_flags & SOCAM_VSYNC_ACTIVE_LOW)) {
966 if (mx3_cam->platform_flags & MX3_CAMERA_VSP)
967 common_flags &= ~SOCAM_VSYNC_ACTIVE_HIGH;
968 else
969 common_flags &= ~SOCAM_VSYNC_ACTIVE_LOW;
970 }
971
972 if ((common_flags & SOCAM_DATA_ACTIVE_HIGH) &&
973 (common_flags & SOCAM_DATA_ACTIVE_LOW)) {
974 if (mx3_cam->platform_flags & MX3_CAMERA_DP)
975 common_flags &= ~SOCAM_DATA_ACTIVE_HIGH;
976 else
977 common_flags &= ~SOCAM_DATA_ACTIVE_LOW;
978 }
979
980 if ((common_flags & SOCAM_PCLK_SAMPLE_RISING) &&
981 (common_flags & SOCAM_PCLK_SAMPLE_FALLING)) {
982 if (mx3_cam->platform_flags & MX3_CAMERA_PCP)
983 common_flags &= ~SOCAM_PCLK_SAMPLE_RISING;
984 else
985 common_flags &= ~SOCAM_PCLK_SAMPLE_FALLING;
986 }
987
988 /* Make the camera work in widest common mode, we'll take care of
989 * the rest */
990 if (common_flags & SOCAM_DATAWIDTH_15)
991 common_flags = (common_flags & ~SOCAM_DATAWIDTH_MASK) |
992 SOCAM_DATAWIDTH_15;
993 else if (common_flags & SOCAM_DATAWIDTH_10)
994 common_flags = (common_flags & ~SOCAM_DATAWIDTH_MASK) |
995 SOCAM_DATAWIDTH_10;
996 else if (common_flags & SOCAM_DATAWIDTH_8)
997 common_flags = (common_flags & ~SOCAM_DATAWIDTH_MASK) |
998 SOCAM_DATAWIDTH_8;
999 else
1000 common_flags = (common_flags & ~SOCAM_DATAWIDTH_MASK) |
1001 SOCAM_DATAWIDTH_4;
1002
1003 ret = icd->ops->set_bus_param(icd, common_flags);
1004 if (ret < 0)
1005 return ret;
1006
1007 /*
1008 * So far only gated clock mode is supported. Add a line
1009 * (3 << CSI_SENS_CONF_SENS_PRTCL_SHIFT) |
1010 * below and select the required mode when supporting other
1011 * synchronisation protocols.
1012 */
1013 sens_conf = csi_reg_read(mx3_cam, CSI_SENS_CONF) &
1014 ~((1 << CSI_SENS_CONF_VSYNC_POL_SHIFT) |
1015 (1 << CSI_SENS_CONF_HSYNC_POL_SHIFT) |
1016 (1 << CSI_SENS_CONF_DATA_POL_SHIFT) |
1017 (1 << CSI_SENS_CONF_PIX_CLK_POL_SHIFT) |
1018 (3 << CSI_SENS_CONF_DATA_FMT_SHIFT) |
1019 (3 << CSI_SENS_CONF_DATA_WIDTH_SHIFT));
1020
1021 /* TODO: Support RGB and YUV formats */
1022
1023 /* This has been set in mx3_camera_activate(), but we clear it above */
1024 sens_conf |= CSI_SENS_CONF_DATA_FMT_BAYER;
1025
1026 if (common_flags & SOCAM_PCLK_SAMPLE_FALLING)
1027 sens_conf |= 1 << CSI_SENS_CONF_PIX_CLK_POL_SHIFT;
1028 if (common_flags & SOCAM_HSYNC_ACTIVE_LOW)
1029 sens_conf |= 1 << CSI_SENS_CONF_HSYNC_POL_SHIFT;
1030 if (common_flags & SOCAM_VSYNC_ACTIVE_LOW)
1031 sens_conf |= 1 << CSI_SENS_CONF_VSYNC_POL_SHIFT;
1032 if (common_flags & SOCAM_DATA_ACTIVE_LOW)
1033 sens_conf |= 1 << CSI_SENS_CONF_DATA_POL_SHIFT;
1034
1035 /* Just do what we're asked to do */
1036 switch (xlate->host_fmt->depth) {
1037 case 4:
1038 dw = 0 << CSI_SENS_CONF_DATA_WIDTH_SHIFT;
1039 break;
1040 case 8:
1041 dw = 1 << CSI_SENS_CONF_DATA_WIDTH_SHIFT;
1042 break;
1043 case 10:
1044 dw = 2 << CSI_SENS_CONF_DATA_WIDTH_SHIFT;
1045 break;
1046 default:
1047 /*
1048 * Actually it can only be 15 now, default is just to silence
1049 * compiler warnings
1050 */
1051 case 15:
1052 dw = 3 << CSI_SENS_CONF_DATA_WIDTH_SHIFT;
1053 }
1054
1055 csi_reg_write(mx3_cam, sens_conf | dw, CSI_SENS_CONF);
1056
1057 dev_dbg(&ici->dev, "Set SENS_CONF to %x\n", sens_conf | dw);
1058
1059 return 0;
1060}
1061
1062static struct soc_camera_host_ops mx3_soc_camera_host_ops = {
1063 .owner = THIS_MODULE,
1064 .add = mx3_camera_add_device,
1065 .remove = mx3_camera_remove_device,
1066#ifdef CONFIG_PM
1067 .suspend = mx3_camera_suspend,
1068 .resume = mx3_camera_resume,
1069#endif
1070 .set_crop = mx3_camera_set_crop,
1071 .set_fmt = mx3_camera_set_fmt,
1072 .try_fmt = mx3_camera_try_fmt,
1073 .get_formats = mx3_camera_get_formats,
1074 .init_videobuf = mx3_camera_init_videobuf,
1075 .reqbufs = mx3_camera_reqbufs,
1076 .poll = mx3_camera_poll,
1077 .querycap = mx3_camera_querycap,
1078 .set_bus_param = mx3_camera_set_bus_param,
1079};
1080
1081static int mx3_camera_probe(struct platform_device *pdev)
1082{
1083 struct mx3_camera_dev *mx3_cam;
1084 struct resource *res;
1085 void __iomem *base;
1086 int err = 0;
1087 struct soc_camera_host *soc_host;
1088
1089 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1090 if (!res) {
1091 err = -ENODEV;
1092 goto egetres;
1093 }
1094
1095 mx3_cam = vmalloc(sizeof(*mx3_cam));
1096 if (!mx3_cam) {
1097 dev_err(&pdev->dev, "Could not allocate mx3 camera object\n");
1098 err = -ENOMEM;
1099 goto ealloc;
1100 }
1101 memset(mx3_cam, 0, sizeof(*mx3_cam));
1102
1103 mx3_cam->clk = clk_get(&pdev->dev, "csi_clk");
1104 if (IS_ERR(mx3_cam->clk)) {
1105 err = PTR_ERR(mx3_cam->clk);
1106 goto eclkget;
1107 }
1108
1109 dev_set_drvdata(&pdev->dev, mx3_cam);
1110
1111 mx3_cam->pdata = pdev->dev.platform_data;
1112 mx3_cam->platform_flags = mx3_cam->pdata->flags;
1113 if (!(mx3_cam->platform_flags & (MX3_CAMERA_DATAWIDTH_4 |
1114 MX3_CAMERA_DATAWIDTH_8 | MX3_CAMERA_DATAWIDTH_10 |
1115 MX3_CAMERA_DATAWIDTH_15))) {
1116 /* Platform hasn't set available data widths. This is bad.
1117 * Warn and use a default. */
1118 dev_warn(&pdev->dev, "WARNING! Platform hasn't set available "
1119 "data widths, using default 8 bit\n");
1120 mx3_cam->platform_flags |= MX3_CAMERA_DATAWIDTH_8;
1121 }
1122
1123 mx3_cam->mclk = mx3_cam->pdata->mclk_10khz * 10000;
1124 if (!mx3_cam->mclk) {
1125 dev_warn(&pdev->dev,
1126 "mclk_10khz == 0! Please, fix your platform data. "
1127 "Using default 20MHz\n");
1128 mx3_cam->mclk = 20000000;
1129 }
1130
1131 /* list of video-buffers */
1132 INIT_LIST_HEAD(&mx3_cam->capture);
1133 spin_lock_init(&mx3_cam->lock);
1134
1135 base = ioremap(res->start, res->end - res->start + 1);
1136 if (!base) {
1137 err = -ENOMEM;
1138 goto eioremap;
1139 }
1140
1141 mx3_cam->base = base;
1142 mx3_cam->dev = &pdev->dev;
1143
1144 soc_host = &mx3_cam->soc_host;
1145 soc_host->drv_name = MX3_CAM_DRV_NAME;
1146 soc_host->ops = &mx3_soc_camera_host_ops;
1147 soc_host->priv = mx3_cam;
1148 soc_host->dev.parent = &pdev->dev;
1149 soc_host->nr = pdev->id;
1150 err = soc_camera_host_register(soc_host);
1151 if (err)
1152 goto ecamhostreg;
1153
1154 /* IDMAC interface */
1155 dmaengine_get();
1156
1157 return 0;
1158
1159ecamhostreg:
1160 iounmap(base);
1161eioremap:
1162 clk_put(mx3_cam->clk);
1163eclkget:
1164 vfree(mx3_cam);
1165ealloc:
1166egetres:
1167 return err;
1168}
1169
1170static int __devexit mx3_camera_remove(struct platform_device *pdev)
1171{
1172 struct mx3_camera_dev *mx3_cam = platform_get_drvdata(pdev);
1173
1174 clk_put(mx3_cam->clk);
1175
1176 soc_camera_host_unregister(&mx3_cam->soc_host);
1177
1178 iounmap(mx3_cam->base);
1179
1180 /*
1181 * The channel has either not been allocated,
1182 * or should have been released
1183 */
1184 if (WARN_ON(mx3_cam->idmac_channel[0]))
1185 dma_release_channel(&mx3_cam->idmac_channel[0]->dma_chan);
1186
1187 vfree(mx3_cam);
1188
1189 dmaengine_put();
1190
1191 dev_info(&pdev->dev, "i.MX3x Camera driver unloaded\n");
1192
1193 return 0;
1194}
1195
1196static struct platform_driver mx3_camera_driver = {
1197 .driver = {
1198 .name = MX3_CAM_DRV_NAME,
1199 },
1200 .probe = mx3_camera_probe,
1201 .remove = __exit_p(mx3_camera_remove),
1202};
1203
1204
1205static int __devinit mx3_camera_init(void)
1206{
1207 return platform_driver_register(&mx3_camera_driver);
1208}
1209
1210static void __exit mx3_camera_exit(void)
1211{
1212 platform_driver_unregister(&mx3_camera_driver);
1213}
1214
1215module_init(mx3_camera_init);
1216module_exit(mx3_camera_exit);
1217
1218MODULE_DESCRIPTION("i.MX3x SoC Camera Host driver");
1219MODULE_AUTHOR("Guennadi Liakhovetski <lg@denx.de>");
1220MODULE_LICENSE("GPL v2");
diff --git a/drivers/media/video/mxb.c b/drivers/media/video/mxb.c
index e3cbe14c349a..84aec62e8452 100644
--- a/drivers/media/video/mxb.c
+++ b/drivers/media/video/mxb.c
@@ -25,16 +25,20 @@
25 25
26#include <media/saa7146_vv.h> 26#include <media/saa7146_vv.h>
27#include <media/tuner.h> 27#include <media/tuner.h>
28#include <linux/video_decoder.h>
29#include <media/v4l2-common.h> 28#include <media/v4l2-common.h>
30#include <media/saa7115.h> 29#include <media/saa7115.h>
31 30
32#include "mxb.h" 31#include "mxb.h"
33#include "tea6415c.h" 32#include "tea6415c.h"
34#include "tea6420.h" 33#include "tea6420.h"
35#include "tda9840.h"
36 34
37#define I2C_SAA7111 0x24 35#define I2C_SAA5246A 0x11
36#define I2C_SAA7111A 0x24
37#define I2C_TDA9840 0x42
38#define I2C_TEA6415C 0x43
39#define I2C_TEA6420_1 0x4c
40#define I2C_TEA6420_2 0x4d
41#define I2C_TUNER 0x60
38 42
39#define MXB_BOARD_CAN_DO_VBI(dev) (dev->revision != 0) 43#define MXB_BOARD_CAN_DO_VBI(dev) (dev->revision != 0)
40 44
@@ -79,57 +83,35 @@ static struct {
79static int video_audio_connect[MXB_INPUTS] = 83static int video_audio_connect[MXB_INPUTS] =
80 { 0, 1, 3, 3 }; 84 { 0, 1, 3, 3 };
81 85
82/* these are the necessary input-output-pins for bringing one audio source 86/* These are the necessary input-output-pins for bringing one audio source
83(see above) to the CD-output */ 87 (see above) to the CD-output. Note that gain is set to 0 in this table. */
84static struct tea6420_multiplex TEA6420_cd[MXB_AUDIOS+1][2] = 88static struct v4l2_routing TEA6420_cd[MXB_AUDIOS + 1][2] = {
85 { 89 { { 1, 1 }, { 1, 1 } }, /* Tuner */
86 {{1,1,0},{1,1,0}}, /* Tuner */ 90 { { 5, 1 }, { 6, 1 } }, /* AUX 1 */
87 {{5,1,0},{6,1,0}}, /* AUX 1 */ 91 { { 4, 1 }, { 6, 1 } }, /* AUX 2 */
88 {{4,1,0},{6,1,0}}, /* AUX 2 */ 92 { { 3, 1 }, { 6, 1 } }, /* AUX 3 */
89 {{3,1,0},{6,1,0}}, /* AUX 3 */ 93 { { 1, 1 }, { 3, 1 } }, /* Radio */
90 {{1,1,0},{3,1,0}}, /* Radio */ 94 { { 1, 1 }, { 2, 1 } }, /* CD-Rom */
91 {{1,1,0},{2,1,0}}, /* CD-Rom */ 95 { { 6, 1 }, { 6, 1 } } /* Mute */
92 {{6,1,0},{6,1,0}} /* Mute */ 96};
93 }; 97
94 98/* These are the necessary input-output-pins for bringing one audio source
95/* these are the necessary input-output-pins for bringing one audio source 99 (see above) to the line-output. Note that gain is set to 0 in this table. */
96(see above) to the line-output */ 100static struct v4l2_routing TEA6420_line[MXB_AUDIOS + 1][2] = {
97static struct tea6420_multiplex TEA6420_line[MXB_AUDIOS+1][2] = 101 { { 2, 3 }, { 1, 2 } },
98 { 102 { { 5, 3 }, { 6, 2 } },
99 {{2,3,0},{1,2,0}}, 103 { { 4, 3 }, { 6, 2 } },
100 {{5,3,0},{6,2,0}}, 104 { { 3, 3 }, { 6, 2 } },
101 {{4,3,0},{6,2,0}}, 105 { { 2, 3 }, { 3, 2 } },
102 {{3,3,0},{6,2,0}}, 106 { { 2, 3 }, { 2, 2 } },
103 {{2,3,0},{3,2,0}}, 107 { { 6, 3 }, { 6, 2 } } /* Mute */
104 {{2,3,0},{2,2,0}}, 108};
105 {{6,3,0},{6,2,0}} /* Mute */
106 };
107 109
108#define MAXCONTROLS 1 110#define MAXCONTROLS 1
109static struct v4l2_queryctrl mxb_controls[] = { 111static struct v4l2_queryctrl mxb_controls[] = {
110 { V4L2_CID_AUDIO_MUTE, V4L2_CTRL_TYPE_BOOLEAN, "Mute", 0, 1, 1, 0, 0 }, 112 { V4L2_CID_AUDIO_MUTE, V4L2_CTRL_TYPE_BOOLEAN, "Mute", 0, 1, 1, 0, 0 },
111}; 113};
112 114
113static struct saa7146_extension_ioctls ioctls[] = {
114 { VIDIOC_ENUMINPUT, SAA7146_EXCLUSIVE },
115 { VIDIOC_G_INPUT, SAA7146_EXCLUSIVE },
116 { VIDIOC_S_INPUT, SAA7146_EXCLUSIVE },
117 { VIDIOC_QUERYCTRL, SAA7146_BEFORE },
118 { VIDIOC_G_CTRL, SAA7146_BEFORE },
119 { VIDIOC_S_CTRL, SAA7146_BEFORE },
120 { VIDIOC_G_TUNER, SAA7146_EXCLUSIVE },
121 { VIDIOC_S_TUNER, SAA7146_EXCLUSIVE },
122 { VIDIOC_G_FREQUENCY, SAA7146_EXCLUSIVE },
123 { VIDIOC_S_FREQUENCY, SAA7146_EXCLUSIVE },
124 { VIDIOC_G_AUDIO, SAA7146_EXCLUSIVE },
125 { VIDIOC_S_AUDIO, SAA7146_EXCLUSIVE },
126 { VIDIOC_DBG_G_REGISTER, SAA7146_EXCLUSIVE },
127 { VIDIOC_DBG_S_REGISTER, SAA7146_EXCLUSIVE },
128 { MXB_S_AUDIO_CD, SAA7146_EXCLUSIVE }, /* custom control */
129 { MXB_S_AUDIO_LINE, SAA7146_EXCLUSIVE }, /* custom control */
130 { 0, 0 }
131};
132
133struct mxb 115struct mxb
134{ 116{
135 struct video_device *video_dev; 117 struct video_device *video_dev;
@@ -137,12 +119,12 @@ struct mxb
137 119
138 struct i2c_adapter i2c_adapter; 120 struct i2c_adapter i2c_adapter;
139 121
140 struct i2c_client *saa7111a; 122 struct v4l2_subdev *saa7111a;
141 struct i2c_client *tda9840; 123 struct v4l2_subdev *tda9840;
142 struct i2c_client *tea6415c; 124 struct v4l2_subdev *tea6415c;
143 struct i2c_client *tuner; 125 struct v4l2_subdev *tuner;
144 struct i2c_client *tea6420_1; 126 struct v4l2_subdev *tea6420_1;
145 struct i2c_client *tea6420_2; 127 struct v4l2_subdev *tea6420_2;
146 128
147 int cur_mode; /* current audio mode (mono, stereo, ...) */ 129 int cur_mode; /* current audio mode (mono, stereo, ...) */
148 int cur_input; /* current input */ 130 int cur_input; /* current input */
@@ -150,84 +132,51 @@ struct mxb
150 struct v4l2_frequency cur_freq; /* current frequency the tuner is tuned to */ 132 struct v4l2_frequency cur_freq; /* current frequency the tuner is tuned to */
151}; 133};
152 134
153static struct saa7146_extension extension; 135#define saa7111a_call(mxb, o, f, args...) \
154 136 v4l2_subdev_call(mxb->saa7111a, o, f, ##args)
155static int mxb_check_clients(struct device *dev, void *data) 137#define tea6420_1_call(mxb, o, f, args...) \
156{ 138 v4l2_subdev_call(mxb->tea6420_1, o, f, ##args)
157 struct mxb *mxb = data; 139#define tea6420_2_call(mxb, o, f, args...) \
158 struct i2c_client *client = i2c_verify_client(dev); 140 v4l2_subdev_call(mxb->tea6420_2, o, f, ##args)
159 141#define tda9840_call(mxb, o, f, args...) \
160 if (!client) 142 v4l2_subdev_call(mxb->tda9840, o, f, ##args)
161 return 0; 143#define tea6415c_call(mxb, o, f, args...) \
162 144 v4l2_subdev_call(mxb->tea6415c, o, f, ##args)
163 if (I2C_ADDR_TEA6420_1 == client->addr) 145#define tuner_call(mxb, o, f, args...) \
164 mxb->tea6420_1 = client; 146 v4l2_subdev_call(mxb->tuner, o, f, ##args)
165 if (I2C_ADDR_TEA6420_2 == client->addr) 147#define call_all(dev, o, f, args...) \
166 mxb->tea6420_2 = client; 148 v4l2_device_call_until_err(&dev->v4l2_dev, 0, o, f, ##args)
167 if (I2C_TEA6415C_2 == client->addr)
168 mxb->tea6415c = client;
169 if (I2C_ADDR_TDA9840 == client->addr)
170 mxb->tda9840 = client;
171 if (I2C_SAA7111 == client->addr)
172 mxb->saa7111a = client;
173 if (0x60 == client->addr)
174 mxb->tuner = client;
175 149
176 return 0; 150static struct saa7146_extension extension;
177}
178 151
179static int mxb_probe(struct saa7146_dev* dev) 152static int mxb_probe(struct saa7146_dev *dev)
180{ 153{
181 struct mxb* mxb = NULL; 154 struct mxb *mxb = NULL;
182 int result;
183
184 result = request_module("saa7115");
185 if (result < 0) {
186 printk("mxb: saa7111 i2c module not available.\n");
187 return -ENODEV;
188 }
189 result = request_module("tea6420");
190 if (result < 0) {
191 printk("mxb: tea6420 i2c module not available.\n");
192 return -ENODEV;
193 }
194 result = request_module("tea6415c");
195 if (result < 0) {
196 printk("mxb: tea6415c i2c module not available.\n");
197 return -ENODEV;
198 }
199 result = request_module("tda9840");
200 if (result < 0) {
201 printk("mxb: tda9840 i2c module not available.\n");
202 return -ENODEV;
203 }
204 result = request_module("tuner");
205 if (result < 0) {
206 printk("mxb: tuner i2c module not available.\n");
207 return -ENODEV;
208 }
209 155
210 mxb = kzalloc(sizeof(struct mxb), GFP_KERNEL); 156 mxb = kzalloc(sizeof(struct mxb), GFP_KERNEL);
211 if( NULL == mxb ) { 157 if (mxb == NULL) {
212 DEB_D(("not enough kernel memory.\n")); 158 DEB_D(("not enough kernel memory.\n"));
213 return -ENOMEM; 159 return -ENOMEM;
214 } 160 }
215 161
216 mxb->i2c_adapter = (struct i2c_adapter) {
217 .class = I2C_CLASS_TV_ANALOG,
218 };
219
220 snprintf(mxb->i2c_adapter.name, sizeof(mxb->i2c_adapter.name), "mxb%d", mxb_num); 162 snprintf(mxb->i2c_adapter.name, sizeof(mxb->i2c_adapter.name), "mxb%d", mxb_num);
221 163
222 saa7146_i2c_adapter_prepare(dev, &mxb->i2c_adapter, SAA7146_I2C_BUS_BIT_RATE_480); 164 saa7146_i2c_adapter_prepare(dev, &mxb->i2c_adapter, SAA7146_I2C_BUS_BIT_RATE_480);
223 if(i2c_add_adapter(&mxb->i2c_adapter) < 0) { 165 if (i2c_add_adapter(&mxb->i2c_adapter) < 0) {
224 DEB_S(("cannot register i2c-device. skipping.\n")); 166 DEB_S(("cannot register i2c-device. skipping.\n"));
225 kfree(mxb); 167 kfree(mxb);
226 return -EFAULT; 168 return -EFAULT;
227 } 169 }
228 170
229 /* loop through all i2c-devices on the bus and look who is there */ 171 mxb->saa7111a = v4l2_i2c_new_subdev(&mxb->i2c_adapter, "saa7115", "saa7111", I2C_SAA7111A);
230 device_for_each_child(&mxb->i2c_adapter.dev, mxb, mxb_check_clients); 172 mxb->tea6420_1 = v4l2_i2c_new_subdev(&mxb->i2c_adapter, "tea6420", "tea6420", I2C_TEA6420_1);
173 mxb->tea6420_2 = v4l2_i2c_new_subdev(&mxb->i2c_adapter, "tea6420", "tea6420", I2C_TEA6420_2);
174 mxb->tea6415c = v4l2_i2c_new_subdev(&mxb->i2c_adapter, "tea6415c", "tea6415c", I2C_TEA6415C);
175 mxb->tda9840 = v4l2_i2c_new_subdev(&mxb->i2c_adapter, "tda9840", "tda9840", I2C_TDA9840);
176 mxb->tuner = v4l2_i2c_new_subdev(&mxb->i2c_adapter, "tuner", "tuner", I2C_TUNER);
177 if (v4l2_i2c_new_subdev(&mxb->i2c_adapter, "saa5246a", "saa5246a", I2C_SAA5246A)) {
178 printk(KERN_INFO "mxb: found teletext decoder\n");
179 }
231 180
232 /* check if all devices are present */ 181 /* check if all devices are present */
233 if (!mxb->tea6420_1 || !mxb->tea6420_2 || !mxb->tea6415c || 182 if (!mxb->tea6420_1 || !mxb->tea6420_2 || !mxb->tea6415c ||
@@ -315,47 +264,45 @@ static int mxb_init_done(struct saa7146_dev* dev)
315 struct v4l2_routing route; 264 struct v4l2_routing route;
316 265
317 int i = 0, err = 0; 266 int i = 0, err = 0;
318 struct tea6415c_multiplex vm;
319 267
320 /* select video mode in saa7111a */ 268 /* select video mode in saa7111a */
321 mxb->saa7111a->driver->command(mxb->saa7111a, VIDIOC_S_STD, &std); 269 saa7111a_call(mxb, tuner, s_std, std);
322 270
323 /* select tuner-output on saa7111a */ 271 /* select tuner-output on saa7111a */
324 i = 0; 272 i = 0;
325 route.input = SAA7115_COMPOSITE0; 273 route.input = SAA7115_COMPOSITE0;
326 route.output = SAA7111_FMT_CCIR | SAA7111_VBI_BYPASS; 274 route.output = SAA7111_FMT_CCIR | SAA7111_VBI_BYPASS;
327 mxb->saa7111a->driver->command(mxb->saa7111a, VIDIOC_INT_S_VIDEO_ROUTING, &route); 275 saa7111a_call(mxb, video, s_routing, &route);
328 276
329 /* select a tuner type */ 277 /* select a tuner type */
330 tun_setup.mode_mask = T_ANALOG_TV; 278 tun_setup.mode_mask = T_ANALOG_TV;
331 tun_setup.addr = ADDR_UNSET; 279 tun_setup.addr = ADDR_UNSET;
332 tun_setup.type = TUNER_PHILIPS_PAL; 280 tun_setup.type = TUNER_PHILIPS_PAL;
333 mxb->tuner->driver->command(mxb->tuner, TUNER_SET_TYPE_ADDR, &tun_setup); 281 tuner_call(mxb, tuner, s_type_addr, &tun_setup);
334 /* tune in some frequency on tuner */ 282 /* tune in some frequency on tuner */
335 mxb->cur_freq.tuner = 0; 283 mxb->cur_freq.tuner = 0;
336 mxb->cur_freq.type = V4L2_TUNER_ANALOG_TV; 284 mxb->cur_freq.type = V4L2_TUNER_ANALOG_TV;
337 mxb->cur_freq.frequency = freq; 285 mxb->cur_freq.frequency = freq;
338 mxb->tuner->driver->command(mxb->tuner, VIDIOC_S_FREQUENCY, 286 tuner_call(mxb, tuner, s_frequency, &mxb->cur_freq);
339 &mxb->cur_freq);
340 287
341 /* set a default video standard */ 288 /* set a default video standard */
342 mxb->tuner->driver->command(mxb->tuner, VIDIOC_S_STD, &std); 289 tuner_call(mxb, tuner, s_std, std);
343 290
344 /* mute audio on tea6420s */ 291 /* mute audio on tea6420s */
345 mxb->tea6420_1->driver->command(mxb->tea6420_1, TEA6420_SWITCH, &TEA6420_line[6][0]); 292 tea6420_1_call(mxb, audio, s_routing, &TEA6420_line[6][0]);
346 mxb->tea6420_2->driver->command(mxb->tea6420_2, TEA6420_SWITCH, &TEA6420_line[6][1]); 293 tea6420_2_call(mxb, audio, s_routing, &TEA6420_line[6][1]);
347 mxb->tea6420_1->driver->command(mxb->tea6420_1, TEA6420_SWITCH, &TEA6420_cd[6][0]); 294 tea6420_1_call(mxb, audio, s_routing, &TEA6420_line[6][0]);
348 mxb->tea6420_2->driver->command(mxb->tea6420_2, TEA6420_SWITCH, &TEA6420_cd[6][1]); 295 tea6420_2_call(mxb, audio, s_routing, &TEA6420_line[6][1]);
349 296
350 /* switch to tuner-channel on tea6415c*/ 297 /* switch to tuner-channel on tea6415c */
351 vm.out = 17; 298 route.input = 3;
352 vm.in = 3; 299 route.output = 17;
353 mxb->tea6415c->driver->command(mxb->tea6415c, TEA6415C_SWITCH, &vm); 300 tea6415c_call(mxb, video, s_routing, &route);
354 301
355 /* select tuner-output on multicable on tea6415c*/ 302 /* select tuner-output on multicable on tea6415c */
356 vm.in = 3; 303 route.input = 3;
357 vm.out = 13; 304 route.output = 13;
358 mxb->tea6415c->driver->command(mxb->tea6415c, TEA6415C_SWITCH, &vm); 305 tea6415c_call(mxb, video, s_routing, &route);
359 306
360 /* the rest for mxb */ 307 /* the rest for mxb */
361 mxb->cur_input = 0; 308 mxb->cur_input = 0;
@@ -424,395 +371,414 @@ void mxb_irq_bh(struct saa7146_dev* dev, u32* irq_mask)
424} 371}
425*/ 372*/
426 373
427static struct saa7146_ext_vv vv_data; 374static int vidioc_queryctrl(struct file *file, void *fh, struct v4l2_queryctrl *qc)
428
429/* this function only gets called when the probing was successful */
430static int mxb_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_data *info)
431{ 375{
432 struct mxb *mxb = (struct mxb *)dev->ext_priv; 376 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
433 377 int i;
434 DEB_EE(("dev:%p\n", dev));
435
436 /* checking for i2c-devices can be omitted here, because we
437 already did this in "mxb_vl42_probe" */
438 378
439 saa7146_vv_init(dev, &vv_data); 379 for (i = MAXCONTROLS - 1; i >= 0; i--) {
440 if (saa7146_register_device(&mxb->video_dev, dev, "mxb", VFL_TYPE_GRABBER)) { 380 if (mxb_controls[i].id == qc->id) {
441 ERR(("cannot register capture v4l2 device. skipping.\n")); 381 *qc = mxb_controls[i];
442 return -1; 382 DEB_D(("VIDIOC_QUERYCTRL %d.\n", qc->id));
383 return 0;
384 }
443 } 385 }
386 return dev->ext_vv_data->core_ops->vidioc_queryctrl(file, fh, qc);
387}
444 388
445 /* initialization stuff (vbi) (only for revision > 0 and for extensions which want it)*/ 389static int vidioc_g_ctrl(struct file *file, void *fh, struct v4l2_control *vc)
446 if (MXB_BOARD_CAN_DO_VBI(dev)) { 390{
447 if (saa7146_register_device(&mxb->vbi_dev, dev, "mxb", VFL_TYPE_VBI)) { 391 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
448 ERR(("cannot register vbi v4l2 device. skipping.\n")); 392 struct mxb *mxb = (struct mxb *)dev->ext_priv;
449 } 393 int i;
394
395 for (i = MAXCONTROLS - 1; i >= 0; i--) {
396 if (mxb_controls[i].id == vc->id)
397 break;
450 } 398 }
451 399
452 i2c_use_client(mxb->tea6420_1); 400 if (i < 0)
453 i2c_use_client(mxb->tea6420_2); 401 return dev->ext_vv_data->core_ops->vidioc_g_ctrl(file, fh, vc);
454 i2c_use_client(mxb->tea6415c);
455 i2c_use_client(mxb->tda9840);
456 i2c_use_client(mxb->saa7111a);
457 i2c_use_client(mxb->tuner);
458 402
459 printk("mxb: found Multimedia eXtension Board #%d.\n", mxb_num); 403 if (vc->id == V4L2_CID_AUDIO_MUTE) {
404 vc->value = mxb->cur_mute;
405 DEB_D(("VIDIOC_G_CTRL V4L2_CID_AUDIO_MUTE:%d.\n", vc->value));
406 return 0;
407 }
460 408
461 mxb_num++; 409 DEB_EE(("VIDIOC_G_CTRL V4L2_CID_AUDIO_MUTE:%d.\n", vc->value));
462 mxb_init_done(dev);
463 return 0; 410 return 0;
464} 411}
465 412
466static int mxb_detach(struct saa7146_dev *dev) 413static int vidioc_s_ctrl(struct file *file, void *fh, struct v4l2_control *vc)
467{ 414{
415 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
468 struct mxb *mxb = (struct mxb *)dev->ext_priv; 416 struct mxb *mxb = (struct mxb *)dev->ext_priv;
417 int i = 0;
469 418
470 DEB_EE(("dev:%p\n", dev)); 419 for (i = MAXCONTROLS - 1; i >= 0; i--) {
471 420 if (mxb_controls[i].id == vc->id)
472 i2c_release_client(mxb->tea6420_1); 421 break;
473 i2c_release_client(mxb->tea6420_2); 422 }
474 i2c_release_client(mxb->tea6415c);
475 i2c_release_client(mxb->tda9840);
476 i2c_release_client(mxb->saa7111a);
477 i2c_release_client(mxb->tuner);
478
479 saa7146_unregister_device(&mxb->video_dev,dev);
480 if (MXB_BOARD_CAN_DO_VBI(dev))
481 saa7146_unregister_device(&mxb->vbi_dev, dev);
482 saa7146_vv_release(dev);
483
484 mxb_num--;
485 423
486 i2c_del_adapter(&mxb->i2c_adapter); 424 if (i < 0)
487 kfree(mxb); 425 return dev->ext_vv_data->core_ops->vidioc_s_ctrl(file, fh, vc);
426
427 if (vc->id == V4L2_CID_AUDIO_MUTE) {
428 mxb->cur_mute = vc->value;
429 if (!vc->value) {
430 /* switch the audio-source */
431 tea6420_1_call(mxb, audio, s_routing,
432 &TEA6420_line[video_audio_connect[mxb->cur_input]][0]);
433 tea6420_2_call(mxb, audio, s_routing,
434 &TEA6420_line[video_audio_connect[mxb->cur_input]][1]);
435 } else {
436 tea6420_1_call(mxb, audio, s_routing,
437 &TEA6420_line[6][0]);
438 tea6420_2_call(mxb, audio, s_routing,
439 &TEA6420_line[6][1]);
440 }
441 DEB_EE(("VIDIOC_S_CTRL, V4L2_CID_AUDIO_MUTE: %d.\n", vc->value));
442 }
443 return 0;
444}
488 445
446static int vidioc_enum_input(struct file *file, void *fh, struct v4l2_input *i)
447{
448 DEB_EE(("VIDIOC_ENUMINPUT %d.\n", i->index));
449 if (i->index < 0 || i->index >= MXB_INPUTS)
450 return -EINVAL;
451 memcpy(i, &mxb_inputs[i->index], sizeof(struct v4l2_input));
489 return 0; 452 return 0;
490} 453}
491 454
492static long mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg) 455static int vidioc_g_input(struct file *file, void *fh, unsigned int *i)
493{ 456{
494 struct saa7146_dev *dev = fh->dev; 457 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
495 struct mxb *mxb = (struct mxb *)dev->ext_priv; 458 struct mxb *mxb = (struct mxb *)dev->ext_priv;
496 struct saa7146_vv *vv = dev->vv_data; 459 *i = mxb->cur_input;
497 460
498 switch(cmd) { 461 DEB_EE(("VIDIOC_G_INPUT %d.\n", *i));
499 case VIDIOC_ENUMINPUT: 462 return 0;
500 { 463}
501 struct v4l2_input *i = arg;
502 464
503 DEB_EE(("VIDIOC_ENUMINPUT %d.\n",i->index)); 465static int vidioc_s_input(struct file *file, void *fh, unsigned int input)
504 if (i->index < 0 || i->index >= MXB_INPUTS) 466{
505 return -EINVAL; 467 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
506 memcpy(i, &mxb_inputs[i->index], sizeof(struct v4l2_input)); 468 struct mxb *mxb = (struct mxb *)dev->ext_priv;
507 return 0; 469 struct v4l2_routing route;
508 } 470 int i = 0;
509 /* the saa7146 provides some controls (brightness, contrast, saturation)
510 which gets registered *after* this function. because of this we have
511 to return with a value != 0 even if the function succeded.. */
512 case VIDIOC_QUERYCTRL:
513 {
514 struct v4l2_queryctrl *qc = arg;
515 int i;
516
517 for (i = MAXCONTROLS - 1; i >= 0; i--) {
518 if (mxb_controls[i].id == qc->id) {
519 *qc = mxb_controls[i];
520 DEB_D(("VIDIOC_QUERYCTRL %d.\n", qc->id));
521 return 0;
522 }
523 }
524 return -EAGAIN;
525 }
526 case VIDIOC_G_CTRL:
527 {
528 struct v4l2_control *vc = arg;
529 int i;
530 471
531 for (i = MAXCONTROLS - 1; i >= 0; i--) { 472 DEB_EE(("VIDIOC_S_INPUT %d.\n", input));
532 if (mxb_controls[i].id == vc->id)
533 break;
534 }
535 473
536 if (i < 0) 474 if (input < 0 || input >= MXB_INPUTS)
537 return -EAGAIN; 475 return -EINVAL;
538 476
539 if (vc->id == V4L2_CID_AUDIO_MUTE) { 477 mxb->cur_input = input;
540 vc->value = mxb->cur_mute;
541 DEB_D(("VIDIOC_G_CTRL V4L2_CID_AUDIO_MUTE:%d.\n", vc->value));
542 return 0;
543 }
544 478
545 DEB_EE(("VIDIOC_G_CTRL V4L2_CID_AUDIO_MUTE:%d.\n", vc->value)); 479 saa7146_set_hps_source_and_sync(dev, input_port_selection[input].hps_source,
546 return 0; 480 input_port_selection[input].hps_sync);
547 }
548 481
549 case VIDIOC_S_CTRL: 482 /* prepare switching of tea6415c and saa7111a;
550 { 483 have a look at the 'background'-file for further informations */
551 struct v4l2_control *vc = arg; 484 switch (input) {
552 int i = 0; 485 case TUNER:
486 i = SAA7115_COMPOSITE0;
487 route.input = 3;
488 route.output = 17;
553 489
554 for (i = MAXCONTROLS - 1; i >= 0; i--) { 490 if (tea6415c_call(mxb, video, s_routing, &route)) {
555 if (mxb_controls[i].id == vc->id) 491 printk(KERN_ERR "VIDIOC_S_INPUT: could not address tea6415c #1\n");
556 break; 492 return -EFAULT;
557 } 493 }
494 /* connect tuner-output always to multicable */
495 route.input = 3;
496 route.output = 13;
497 break;
498 case AUX3_YC:
499 /* nothing to be done here. aux3_yc is
500 directly connected to the saa711a */
501 i = SAA7115_SVIDEO1;
502 break;
503 case AUX3:
504 /* nothing to be done here. aux3 is
505 directly connected to the saa711a */
506 i = SAA7115_COMPOSITE1;
507 break;
508 case AUX1:
509 i = SAA7115_COMPOSITE0;
510 route.input = 1;
511 route.output = 17;
512 break;
513 }
558 514
559 if (i < 0) 515 /* switch video in tea6415c only if necessary */
560 return -EAGAIN; 516 switch (input) {
561 517 case TUNER:
562 if (vc->id == V4L2_CID_AUDIO_MUTE) { 518 case AUX1:
563 mxb->cur_mute = vc->value; 519 if (tea6415c_call(mxb, video, s_routing, &route)) {
564 if (!vc->value) { 520 printk(KERN_ERR "VIDIOC_S_INPUT: could not address tea6415c #3\n");
565 /* switch the audio-source */ 521 return -EFAULT;
566 mxb->tea6420_1->driver->command(mxb->tea6420_1, TEA6420_SWITCH,
567 &TEA6420_line[video_audio_connect[mxb->cur_input]][0]);
568 mxb->tea6420_2->driver->command(mxb->tea6420_2, TEA6420_SWITCH,
569 &TEA6420_line[video_audio_connect[mxb->cur_input]][1]);
570 } else {
571 mxb->tea6420_1->driver->command(mxb->tea6420_1, TEA6420_SWITCH,
572 &TEA6420_line[6][0]);
573 mxb->tea6420_2->driver->command(mxb->tea6420_2, TEA6420_SWITCH,
574 &TEA6420_line[6][1]);
575 }
576 DEB_EE(("VIDIOC_S_CTRL, V4L2_CID_AUDIO_MUTE: %d.\n", vc->value));
577 } 522 }
578 return 0; 523 break;
524 default:
525 break;
579 } 526 }
580 case VIDIOC_G_INPUT:
581 {
582 int *input = (int *)arg;
583 *input = mxb->cur_input;
584 527
585 DEB_EE(("VIDIOC_G_INPUT %d.\n", *input)); 528 /* switch video in saa7111a */
586 return 0; 529 route.input = i;
530 route.output = 0;
531 if (saa7111a_call(mxb, video, s_routing, &route))
532 printk(KERN_ERR "VIDIOC_S_INPUT: could not address saa7111a #1.\n");
533
534 /* switch the audio-source only if necessary */
535 if (0 == mxb->cur_mute) {
536 tea6420_1_call(mxb, audio, s_routing,
537 &TEA6420_line[video_audio_connect[input]][0]);
538 tea6420_2_call(mxb, audio, s_routing,
539 &TEA6420_line[video_audio_connect[input]][1]);
587 } 540 }
588 case VIDIOC_S_INPUT:
589 {
590 int input = *(int *)arg;
591 struct tea6415c_multiplex vm;
592 struct v4l2_routing route;
593 int i = 0;
594 541
595 DEB_EE(("VIDIOC_S_INPUT %d.\n", input)); 542 return 0;
543}
596 544
597 if (input < 0 || input >= MXB_INPUTS) 545static int vidioc_g_tuner(struct file *file, void *fh, struct v4l2_tuner *t)
598 return -EINVAL; 546{
547 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
548 struct mxb *mxb = (struct mxb *)dev->ext_priv;
599 549
600 mxb->cur_input = input; 550 if (t->index) {
551 DEB_D(("VIDIOC_G_TUNER: channel %d does not have a tuner attached.\n", t->index));
552 return -EINVAL;
553 }
601 554
602 saa7146_set_hps_source_and_sync(dev, input_port_selection[input].hps_source, 555 DEB_EE(("VIDIOC_G_TUNER: %d\n", t->index));
603 input_port_selection[input].hps_sync);
604 556
605 /* prepare switching of tea6415c and saa7111a; 557 memset(t, 0, sizeof(*t));
606 have a look at the 'background'-file for further informations */ 558 strlcpy(t->name, "TV Tuner", sizeof(t->name));
607 switch (input) { 559 t->type = V4L2_TUNER_ANALOG_TV;
608 case TUNER: 560 t->capability = V4L2_TUNER_CAP_NORM | V4L2_TUNER_CAP_STEREO |
609 i = SAA7115_COMPOSITE0; 561 V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2 | V4L2_TUNER_CAP_SAP;
610 vm.in = 3; 562 t->audmode = mxb->cur_mode;
611 vm.out = 17; 563 return call_all(dev, tuner, g_tuner, t);
564}
612 565
613 if (mxb->tea6415c->driver->command(mxb->tea6415c, TEA6415C_SWITCH, &vm)) { 566static int vidioc_s_tuner(struct file *file, void *fh, struct v4l2_tuner *t)
614 printk(KERN_ERR "VIDIOC_S_INPUT: could not address tea6415c #1\n"); 567{
615 return -EFAULT; 568 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
616 } 569 struct mxb *mxb = (struct mxb *)dev->ext_priv;
617 /* connect tuner-output always to multicable */
618 vm.in = 3;
619 vm.out = 13;
620 break;
621 case AUX3_YC:
622 /* nothing to be done here. aux3_yc is
623 directly connected to the saa711a */
624 i = SAA7115_SVIDEO1;
625 break;
626 case AUX3:
627 /* nothing to be done here. aux3 is
628 directly connected to the saa711a */
629 i = SAA7115_COMPOSITE1;
630 break;
631 case AUX1:
632 i = SAA7115_COMPOSITE0;
633 vm.in = 1;
634 vm.out = 17;
635 break;
636 }
637 570
638 /* switch video in tea6415c only if necessary */ 571 if (t->index) {
639 switch (input) { 572 DEB_D(("VIDIOC_S_TUNER: channel %d does not have a tuner attached.\n", t->index));
640 case TUNER: 573 return -EINVAL;
641 case AUX1: 574 }
642 if (mxb->tea6415c->driver->command(mxb->tea6415c, TEA6415C_SWITCH, &vm)) {
643 printk(KERN_ERR "VIDIOC_S_INPUT: could not address tea6415c #3\n");
644 return -EFAULT;
645 }
646 break;
647 default:
648 break;
649 }
650 575
651 /* switch video in saa7111a */ 576 mxb->cur_mode = t->audmode;
652 route.input = i; 577 return call_all(dev, tuner, s_tuner, t);
653 route.output = 0; 578}
654 if (mxb->saa7111a->driver->command(mxb->saa7111a, VIDIOC_INT_S_VIDEO_ROUTING, &route))
655 printk("VIDIOC_S_INPUT: could not address saa7111a #1.\n");
656
657 /* switch the audio-source only if necessary */
658 if( 0 == mxb->cur_mute ) {
659 mxb->tea6420_1->driver->command(mxb->tea6420_1, TEA6420_SWITCH,
660 &TEA6420_line[video_audio_connect[input]][0]);
661 mxb->tea6420_2->driver->command(mxb->tea6420_2, TEA6420_SWITCH,
662 &TEA6420_line[video_audio_connect[input]][1]);
663 }
664 579
665 return 0; 580static int vidioc_g_frequency(struct file *file, void *fh, struct v4l2_frequency *f)
581{
582 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
583 struct mxb *mxb = (struct mxb *)dev->ext_priv;
584
585 if (mxb->cur_input) {
586 DEB_D(("VIDIOC_G_FREQ: channel %d does not have a tuner!\n",
587 mxb->cur_input));
588 return -EINVAL;
666 } 589 }
667 case VIDIOC_G_TUNER:
668 {
669 struct v4l2_tuner *t = arg;
670 590
671 if (t->index) { 591 *f = mxb->cur_freq;
672 DEB_D(("VIDIOC_G_TUNER: channel %d does not have a tuner attached.\n", t->index));
673 return -EINVAL;
674 }
675 592
676 DEB_EE(("VIDIOC_G_TUNER: %d\n", t->index)); 593 DEB_EE(("VIDIOC_G_FREQ: freq:0x%08x.\n", mxb->cur_freq.frequency));
594 return 0;
595}
677 596
678 memset(t, 0, sizeof(*t)); 597static int vidioc_s_frequency(struct file *file, void *fh, struct v4l2_frequency *f)
679 i2c_clients_command(&mxb->i2c_adapter, cmd, arg); 598{
599 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
600 struct mxb *mxb = (struct mxb *)dev->ext_priv;
601 struct saa7146_vv *vv = dev->vv_data;
680 602
681 strlcpy(t->name, "TV Tuner", sizeof(t->name)); 603 if (f->tuner)
682 t->type = V4L2_TUNER_ANALOG_TV; 604 return -EINVAL;
683 t->capability = V4L2_TUNER_CAP_NORM | V4L2_TUNER_CAP_STEREO | \
684 V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2 | V4L2_TUNER_CAP_SAP;
685 t->audmode = mxb->cur_mode;
686 return 0;
687 }
688 case VIDIOC_S_TUNER:
689 {
690 struct v4l2_tuner *t = arg;
691 605
692 if (t->index) { 606 if (V4L2_TUNER_ANALOG_TV != f->type)
693 DEB_D(("VIDIOC_S_TUNER: channel %d does not have a tuner attached.\n",t->index)); 607 return -EINVAL;
694 return -EINVAL;
695 }
696 608
697 mxb->cur_mode = t->audmode; 609 if (mxb->cur_input) {
698 i2c_clients_command(&mxb->i2c_adapter, cmd, arg); 610 DEB_D(("VIDIOC_S_FREQ: channel %d does not have a tuner!\n", mxb->cur_input));
699 return 0; 611 return -EINVAL;
700 } 612 }
701 case VIDIOC_G_FREQUENCY:
702 {
703 struct v4l2_frequency *f = arg;
704 613
705 if (mxb->cur_input) { 614 mxb->cur_freq = *f;
706 DEB_D(("VIDIOC_G_FREQ: channel %d does not have a tuner!\n", 615 DEB_EE(("VIDIOC_S_FREQUENCY: freq:0x%08x.\n", mxb->cur_freq.frequency));
707 mxb->cur_input));
708 return -EINVAL;
709 }
710 616
711 *f = mxb->cur_freq; 617 /* tune in desired frequency */
618 tuner_call(mxb, tuner, s_frequency, &mxb->cur_freq);
712 619
713 DEB_EE(("VIDIOC_G_FREQ: freq:0x%08x.\n", mxb->cur_freq.frequency)); 620 /* hack: changing the frequency should invalidate the vbi-counter (=> alevt) */
714 return 0; 621 spin_lock(&dev->slock);
622 vv->vbi_fieldcount = 0;
623 spin_unlock(&dev->slock);
624
625 return 0;
626}
627
628static int vidioc_g_audio(struct file *file, void *fh, struct v4l2_audio *a)
629{
630 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
631 struct mxb *mxb = (struct mxb *)dev->ext_priv;
632
633 if (a->index < 0 || a->index > MXB_INPUTS) {
634 DEB_D(("VIDIOC_G_AUDIO %d out of range.\n", a->index));
635 return -EINVAL;
715 } 636 }
716 case VIDIOC_S_FREQUENCY:
717 {
718 struct v4l2_frequency *f = arg;
719 637
720 if (f->tuner) 638 DEB_EE(("VIDIOC_G_AUDIO %d.\n", a->index));
721 return -EINVAL; 639 memcpy(a, &mxb_audios[video_audio_connect[mxb->cur_input]], sizeof(struct v4l2_audio));
640 return 0;
641}
722 642
723 if (V4L2_TUNER_ANALOG_TV != f->type) 643static int vidioc_s_audio(struct file *file, void *fh, struct v4l2_audio *a)
724 return -EINVAL; 644{
645 DEB_D(("VIDIOC_S_AUDIO %d.\n", a->index));
646 return 0;
647}
725 648
726 if (mxb->cur_input) { 649#ifdef CONFIG_VIDEO_ADV_DEBUG
727 DEB_D(("VIDIOC_S_FREQ: channel %d does not have a tuner!\n", mxb->cur_input)); 650static int vidioc_g_register(struct file *file, void *fh, struct v4l2_dbg_register *reg)
728 return -EINVAL; 651{
729 } 652 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
730 653
731 mxb->cur_freq = *f; 654 return call_all(dev, core, g_register, reg);
732 DEB_EE(("VIDIOC_S_FREQUENCY: freq:0x%08x.\n", mxb->cur_freq.frequency)); 655}
733 656
734 /* tune in desired frequency */ 657static int vidioc_s_register(struct file *file, void *fh, struct v4l2_dbg_register *reg)
735 mxb->tuner->driver->command(mxb->tuner, VIDIOC_S_FREQUENCY, &mxb->cur_freq); 658{
659 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
736 660
737 /* hack: changing the frequency should invalidate the vbi-counter (=> alevt) */ 661 return call_all(dev, core, s_register, reg);
738 spin_lock(&dev->slock); 662}
739 vv->vbi_fieldcount = 0; 663#endif
740 spin_unlock(&dev->slock);
741 664
742 return 0; 665static long vidioc_default(struct file *file, void *fh, int cmd, void *arg)
743 } 666{
667 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
668 struct mxb *mxb = (struct mxb *)dev->ext_priv;
669
670 switch (cmd) {
744 case MXB_S_AUDIO_CD: 671 case MXB_S_AUDIO_CD:
745 { 672 {
746 int i = *(int*)arg; 673 int i = *(int *)arg;
747 674
748 if (i < 0 || i >= MXB_AUDIOS) { 675 if (i < 0 || i >= MXB_AUDIOS) {
749 DEB_D(("illegal argument to MXB_S_AUDIO_CD: i:%d.\n",i)); 676 DEB_D(("illegal argument to MXB_S_AUDIO_CD: i:%d.\n", i));
750 return -EINVAL; 677 return -EINVAL;
751 } 678 }
752 679
753 DEB_EE(("MXB_S_AUDIO_CD: i:%d.\n",i)); 680 DEB_EE(("MXB_S_AUDIO_CD: i:%d.\n", i));
754 681
755 mxb->tea6420_1->driver->command(mxb->tea6420_1,TEA6420_SWITCH, &TEA6420_cd[i][0]); 682 tea6420_1_call(mxb, audio, s_routing, &TEA6420_cd[i][0]);
756 mxb->tea6420_2->driver->command(mxb->tea6420_2,TEA6420_SWITCH, &TEA6420_cd[i][1]); 683 tea6420_2_call(mxb, audio, s_routing, &TEA6420_cd[i][1]);
757 684
758 return 0; 685 return 0;
759 } 686 }
760 case MXB_S_AUDIO_LINE: 687 case MXB_S_AUDIO_LINE:
761 { 688 {
762 int i = *(int*)arg; 689 int i = *(int *)arg;
763 690
764 if (i < 0 || i >= MXB_AUDIOS) { 691 if (i < 0 || i >= MXB_AUDIOS) {
765 DEB_D(("illegal argument to MXB_S_AUDIO_LINE: i:%d.\n",i)); 692 DEB_D(("illegal argument to MXB_S_AUDIO_LINE: i:%d.\n", i));
766 return -EINVAL; 693 return -EINVAL;
767 } 694 }
768 695
769 DEB_EE(("MXB_S_AUDIO_LINE: i:%d.\n",i)); 696 DEB_EE(("MXB_S_AUDIO_LINE: i:%d.\n", i));
770 mxb->tea6420_1->driver->command(mxb->tea6420_1,TEA6420_SWITCH, &TEA6420_line[i][0]); 697 tea6420_1_call(mxb, audio, s_routing, &TEA6420_line[i][0]);
771 mxb->tea6420_2->driver->command(mxb->tea6420_2,TEA6420_SWITCH, &TEA6420_line[i][1]); 698 tea6420_2_call(mxb, audio, s_routing, &TEA6420_line[i][1]);
772 699
773 return 0; 700 return 0;
774 } 701 }
775 case VIDIOC_G_AUDIO: 702 default:
776 { 703/*
777 struct v4l2_audio *a = arg; 704 DEB2(printk("does not handle this ioctl.\n"));
705*/
706 return -ENOIOCTLCMD;
707 }
708 return 0;
709}
778 710
779 if (a->index < 0 || a->index > MXB_INPUTS) { 711static struct saa7146_ext_vv vv_data;
780 DEB_D(("VIDIOC_G_AUDIO %d out of range.\n", a->index));
781 return -EINVAL;
782 }
783 712
784 DEB_EE(("VIDIOC_G_AUDIO %d.\n", a->index)); 713/* this function only gets called when the probing was successful */
785 memcpy(a, &mxb_audios[video_audio_connect[mxb->cur_input]], sizeof(struct v4l2_audio)); 714static int mxb_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_data *info)
715{
716 struct mxb *mxb = (struct mxb *)dev->ext_priv;
786 717
787 return 0; 718 DEB_EE(("dev:%p\n", dev));
788 }
789 case VIDIOC_S_AUDIO:
790 {
791 struct v4l2_audio *a = arg;
792 719
793 DEB_D(("VIDIOC_S_AUDIO %d.\n", a->index)); 720 /* checking for i2c-devices can be omitted here, because we
794 return 0; 721 already did this in "mxb_vl42_probe" */
795 } 722
723 saa7146_vv_init(dev, &vv_data);
724 vv_data.ops.vidioc_queryctrl = vidioc_queryctrl;
725 vv_data.ops.vidioc_g_ctrl = vidioc_g_ctrl;
726 vv_data.ops.vidioc_s_ctrl = vidioc_s_ctrl;
727 vv_data.ops.vidioc_enum_input = vidioc_enum_input;
728 vv_data.ops.vidioc_g_input = vidioc_g_input;
729 vv_data.ops.vidioc_s_input = vidioc_s_input;
730 vv_data.ops.vidioc_g_tuner = vidioc_g_tuner;
731 vv_data.ops.vidioc_s_tuner = vidioc_s_tuner;
732 vv_data.ops.vidioc_g_frequency = vidioc_g_frequency;
733 vv_data.ops.vidioc_s_frequency = vidioc_s_frequency;
734 vv_data.ops.vidioc_g_audio = vidioc_g_audio;
735 vv_data.ops.vidioc_s_audio = vidioc_s_audio;
796#ifdef CONFIG_VIDEO_ADV_DEBUG 736#ifdef CONFIG_VIDEO_ADV_DEBUG
797 case VIDIOC_DBG_S_REGISTER: 737 vv_data.ops.vidioc_g_register = vidioc_g_register;
798 case VIDIOC_DBG_G_REGISTER: 738 vv_data.ops.vidioc_s_register = vidioc_s_register;
799 i2c_clients_command(&mxb->i2c_adapter, cmd, arg);
800 return 0;
801#endif 739#endif
802 default: 740 vv_data.ops.vidioc_default = vidioc_default;
803/* 741 if (saa7146_register_device(&mxb->video_dev, dev, "mxb", VFL_TYPE_GRABBER)) {
804 DEB2(printk("does not handle this ioctl.\n")); 742 ERR(("cannot register capture v4l2 device. skipping.\n"));
805*/ 743 return -1;
806 return -ENOIOCTLCMD;
807 } 744 }
745
746 /* initialization stuff (vbi) (only for revision > 0 and for extensions which want it)*/
747 if (MXB_BOARD_CAN_DO_VBI(dev)) {
748 if (saa7146_register_device(&mxb->vbi_dev, dev, "mxb", VFL_TYPE_VBI)) {
749 ERR(("cannot register vbi v4l2 device. skipping.\n"));
750 }
751 }
752
753 printk("mxb: found Multimedia eXtension Board #%d.\n", mxb_num);
754
755 mxb_num++;
756 mxb_init_done(dev);
757 return 0;
758}
759
760static int mxb_detach(struct saa7146_dev *dev)
761{
762 struct mxb *mxb = (struct mxb *)dev->ext_priv;
763
764 DEB_EE(("dev:%p\n", dev));
765
766 saa7146_unregister_device(&mxb->video_dev,dev);
767 if (MXB_BOARD_CAN_DO_VBI(dev))
768 saa7146_unregister_device(&mxb->vbi_dev, dev);
769 saa7146_vv_release(dev);
770
771 mxb_num--;
772
773 i2c_del_adapter(&mxb->i2c_adapter);
774 kfree(mxb);
775
808 return 0; 776 return 0;
809} 777}
810 778
811static int std_callback(struct saa7146_dev *dev, struct saa7146_standard *standard) 779static int std_callback(struct saa7146_dev *dev, struct saa7146_standard *standard)
812{ 780{
813 struct mxb *mxb = (struct mxb *)dev->ext_priv; 781 struct mxb *mxb = (struct mxb *)dev->ext_priv;
814 int zero = 0;
815 int one = 1;
816 782
817 if (V4L2_STD_PAL_I == standard->id) { 783 if (V4L2_STD_PAL_I == standard->id) {
818 v4l2_std_id std = V4L2_STD_PAL_I; 784 v4l2_std_id std = V4L2_STD_PAL_I;
@@ -821,8 +787,8 @@ static int std_callback(struct saa7146_dev *dev, struct saa7146_standard *standa
821 /* set the 7146 gpio register -- I don't know what this does exactly */ 787 /* set the 7146 gpio register -- I don't know what this does exactly */
822 saa7146_write(dev, GPIO_CTRL, 0x00404050); 788 saa7146_write(dev, GPIO_CTRL, 0x00404050);
823 /* unset the 7111 gpio register -- I don't know what this does exactly */ 789 /* unset the 7111 gpio register -- I don't know what this does exactly */
824 mxb->saa7111a->driver->command(mxb->saa7111a, VIDIOC_INT_S_GPIO, &zero); 790 saa7111a_call(mxb, core, s_gpio, 0);
825 mxb->tuner->driver->command(mxb->tuner, VIDIOC_S_STD, &std); 791 tuner_call(mxb, tuner, s_std, std);
826 } else { 792 } else {
827 v4l2_std_id std = V4L2_STD_PAL_BG; 793 v4l2_std_id std = V4L2_STD_PAL_BG;
828 794
@@ -830,8 +796,8 @@ static int std_callback(struct saa7146_dev *dev, struct saa7146_standard *standa
830 /* set the 7146 gpio register -- I don't know what this does exactly */ 796 /* set the 7146 gpio register -- I don't know what this does exactly */
831 saa7146_write(dev, GPIO_CTRL, 0x00404050); 797 saa7146_write(dev, GPIO_CTRL, 0x00404050);
832 /* set the 7111 gpio register -- I don't know what this does exactly */ 798 /* set the 7111 gpio register -- I don't know what this does exactly */
833 mxb->saa7111a->driver->command(mxb->saa7111a, VIDIOC_INT_S_GPIO, &one); 799 saa7111a_call(mxb, core, s_gpio, 1);
834 mxb->tuner->driver->command(mxb->tuner, VIDIOC_S_STD, &std); 800 tuner_call(mxb, tuner, s_std, std);
835 } 801 }
836 return 0; 802 return 0;
837} 803}
@@ -885,8 +851,6 @@ static struct saa7146_ext_vv vv_data = {
885 .stds = &standard[0], 851 .stds = &standard[0],
886 .num_stds = sizeof(standard)/sizeof(struct saa7146_standard), 852 .num_stds = sizeof(standard)/sizeof(struct saa7146_standard),
887 .std_callback = &std_callback, 853 .std_callback = &std_callback,
888 .ioctls = &ioctls[0],
889 .ioctl = mxb_ioctl,
890}; 854};
891 855
892static struct saa7146_extension extension = { 856static struct saa7146_extension extension = {
diff --git a/drivers/media/video/omap24xxcam.c b/drivers/media/video/omap24xxcam.c
index 805faaea6449..5fc4ac0d88f0 100644
--- a/drivers/media/video/omap24xxcam.c
+++ b/drivers/media/video/omap24xxcam.c
@@ -1285,9 +1285,6 @@ static int vidioc_g_parm(struct file *file, void *fh,
1285 struct omap24xxcam_device *cam = ofh->cam; 1285 struct omap24xxcam_device *cam = ofh->cam;
1286 int rval; 1286 int rval;
1287 1287
1288 if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1289 return -EINVAL;
1290
1291 mutex_lock(&cam->mutex); 1288 mutex_lock(&cam->mutex);
1292 rval = vidioc_int_g_parm(cam->sdev, a); 1289 rval = vidioc_int_g_parm(cam->sdev, a);
1293 mutex_unlock(&cam->mutex); 1290 mutex_unlock(&cam->mutex);
@@ -1303,9 +1300,6 @@ static int vidioc_s_parm(struct file *file, void *fh,
1303 struct v4l2_streamparm old_streamparm; 1300 struct v4l2_streamparm old_streamparm;
1304 int rval; 1301 int rval;
1305 1302
1306 if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1307 return -EINVAL;
1308
1309 mutex_lock(&cam->mutex); 1303 mutex_lock(&cam->mutex);
1310 if (cam->streaming) { 1304 if (cam->streaming) {
1311 rval = -EBUSY; 1305 rval = -EBUSY;
@@ -1665,7 +1659,6 @@ static int omap24xxcam_device_register(struct v4l2_int_device *s)
1665 vfd->parent = cam->dev; 1659 vfd->parent = cam->dev;
1666 1660
1667 strlcpy(vfd->name, CAM_NAME, sizeof(vfd->name)); 1661 strlcpy(vfd->name, CAM_NAME, sizeof(vfd->name));
1668 vfd->vfl_type = VID_TYPE_CAPTURE | VID_TYPE_CHROMAKEY;
1669 vfd->fops = &omap24xxcam_fops; 1662 vfd->fops = &omap24xxcam_fops;
1670 vfd->minor = -1; 1663 vfd->minor = -1;
1671 vfd->ioctl_ops = &omap24xxcam_ioctl_fops; 1664 vfd->ioctl_ops = &omap24xxcam_ioctl_fops;
diff --git a/drivers/media/video/ov7670.c b/drivers/media/video/ov7670.c
index 05c14a29375a..0e2184ec994e 100644
--- a/drivers/media/video/ov7670.c
+++ b/drivers/media/video/ov7670.c
@@ -12,18 +12,22 @@
12 */ 12 */
13#include <linux/init.h> 13#include <linux/init.h>
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/slab.h> 15#include <linux/i2c.h>
16#include <linux/delay.h> 16#include <linux/delay.h>
17#include <linux/videodev.h> 17#include <linux/videodev2.h>
18#include <media/v4l2-common.h> 18#include <media/v4l2-device.h>
19#include <media/v4l2-chip-ident.h> 19#include <media/v4l2-chip-ident.h>
20#include <linux/i2c.h> 20#include <media/v4l2-i2c-drv.h>
21 21
22 22
23MODULE_AUTHOR("Jonathan Corbet <corbet@lwn.net>"); 23MODULE_AUTHOR("Jonathan Corbet <corbet@lwn.net>");
24MODULE_DESCRIPTION("A low-level driver for OmniVision ov7670 sensors"); 24MODULE_DESCRIPTION("A low-level driver for OmniVision ov7670 sensors");
25MODULE_LICENSE("GPL"); 25MODULE_LICENSE("GPL");
26 26
27static int debug;
28module_param(debug, bool, 0644);
29MODULE_PARM_DESC(debug, "Debug level (0-1)");
30
27/* 31/*
28 * Basic window sizes. These probably belong somewhere more globally 32 * Basic window sizes. These probably belong somewhere more globally
29 * useful. 33 * useful.
@@ -189,11 +193,16 @@ MODULE_LICENSE("GPL");
189 */ 193 */
190struct ov7670_format_struct; /* coming later */ 194struct ov7670_format_struct; /* coming later */
191struct ov7670_info { 195struct ov7670_info {
196 struct v4l2_subdev sd;
192 struct ov7670_format_struct *fmt; /* Current format */ 197 struct ov7670_format_struct *fmt; /* Current format */
193 unsigned char sat; /* Saturation value */ 198 unsigned char sat; /* Saturation value */
194 int hue; /* Hue value */ 199 int hue; /* Hue value */
195}; 200};
196 201
202static inline struct ov7670_info *to_state(struct v4l2_subdev *sd)
203{
204 return container_of(sd, struct ov7670_info, sd);
205}
197 206
198 207
199 208
@@ -400,24 +409,27 @@ static struct regval_list ov7670_fmt_raw[] = {
400 * Low-level register I/O. 409 * Low-level register I/O.
401 */ 410 */
402 411
403static int ov7670_read(struct i2c_client *c, unsigned char reg, 412static int ov7670_read(struct v4l2_subdev *sd, unsigned char reg,
404 unsigned char *value) 413 unsigned char *value)
405{ 414{
415 struct i2c_client *client = v4l2_get_subdevdata(sd);
406 int ret; 416 int ret;
407 417
408 ret = i2c_smbus_read_byte_data(c, reg); 418 ret = i2c_smbus_read_byte_data(client, reg);
409 if (ret >= 0) { 419 if (ret >= 0) {
410 *value = (unsigned char) ret; 420 *value = (unsigned char)ret;
411 ret = 0; 421 ret = 0;
412 } 422 }
413 return ret; 423 return ret;
414} 424}
415 425
416 426
417static int ov7670_write(struct i2c_client *c, unsigned char reg, 427static int ov7670_write(struct v4l2_subdev *sd, unsigned char reg,
418 unsigned char value) 428 unsigned char value)
419{ 429{
420 int ret = i2c_smbus_write_byte_data(c, reg, value); 430 struct i2c_client *client = v4l2_get_subdevdata(sd);
431 int ret = i2c_smbus_write_byte_data(client, reg, value);
432
421 if (reg == REG_COM7 && (value & COM7_RESET)) 433 if (reg == REG_COM7 && (value & COM7_RESET))
422 msleep(2); /* Wait for reset to run */ 434 msleep(2); /* Wait for reset to run */
423 return ret; 435 return ret;
@@ -427,10 +439,10 @@ static int ov7670_write(struct i2c_client *c, unsigned char reg,
427/* 439/*
428 * Write a list of register settings; ff/ff stops the process. 440 * Write a list of register settings; ff/ff stops the process.
429 */ 441 */
430static int ov7670_write_array(struct i2c_client *c, struct regval_list *vals) 442static int ov7670_write_array(struct v4l2_subdev *sd, struct regval_list *vals)
431{ 443{
432 while (vals->reg_num != 0xff || vals->value != 0xff) { 444 while (vals->reg_num != 0xff || vals->value != 0xff) {
433 int ret = ov7670_write(c, vals->reg_num, vals->value); 445 int ret = ov7670_write(sd, vals->reg_num, vals->value);
434 if (ret < 0) 446 if (ret < 0)
435 return ret; 447 return ret;
436 vals++; 448 vals++;
@@ -442,34 +454,35 @@ static int ov7670_write_array(struct i2c_client *c, struct regval_list *vals)
442/* 454/*
443 * Stuff that knows about the sensor. 455 * Stuff that knows about the sensor.
444 */ 456 */
445static void ov7670_reset(struct i2c_client *client) 457static int ov7670_reset(struct v4l2_subdev *sd, u32 val)
446{ 458{
447 ov7670_write(client, REG_COM7, COM7_RESET); 459 ov7670_write(sd, REG_COM7, COM7_RESET);
448 msleep(1); 460 msleep(1);
461 return 0;
449} 462}
450 463
451 464
452static int ov7670_init(struct i2c_client *client) 465static int ov7670_init(struct v4l2_subdev *sd, u32 val)
453{ 466{
454 return ov7670_write_array(client, ov7670_default_regs); 467 return ov7670_write_array(sd, ov7670_default_regs);
455} 468}
456 469
457 470
458 471
459static int ov7670_detect(struct i2c_client *client) 472static int ov7670_detect(struct v4l2_subdev *sd)
460{ 473{
461 unsigned char v; 474 unsigned char v;
462 int ret; 475 int ret;
463 476
464 ret = ov7670_init(client); 477 ret = ov7670_init(sd, 0);
465 if (ret < 0) 478 if (ret < 0)
466 return ret; 479 return ret;
467 ret = ov7670_read(client, REG_MIDH, &v); 480 ret = ov7670_read(sd, REG_MIDH, &v);
468 if (ret < 0) 481 if (ret < 0)
469 return ret; 482 return ret;
470 if (v != 0x7f) /* OV manuf. id. */ 483 if (v != 0x7f) /* OV manuf. id. */
471 return -ENODEV; 484 return -ENODEV;
472 ret = ov7670_read(client, REG_MIDL, &v); 485 ret = ov7670_read(sd, REG_MIDL, &v);
473 if (ret < 0) 486 if (ret < 0)
474 return ret; 487 return ret;
475 if (v != 0xa2) 488 if (v != 0xa2)
@@ -477,12 +490,12 @@ static int ov7670_detect(struct i2c_client *client)
477 /* 490 /*
478 * OK, we know we have an OmniVision chip...but which one? 491 * OK, we know we have an OmniVision chip...but which one?
479 */ 492 */
480 ret = ov7670_read(client, REG_PID, &v); 493 ret = ov7670_read(sd, REG_PID, &v);
481 if (ret < 0) 494 if (ret < 0)
482 return ret; 495 return ret;
483 if (v != 0x76) /* PID + VER = 0x76 / 0x73 */ 496 if (v != 0x76) /* PID + VER = 0x76 / 0x73 */
484 return -ENODEV; 497 return -ENODEV;
485 ret = ov7670_read(client, REG_VER, &v); 498 ret = ov7670_read(sd, REG_VER, &v);
486 if (ret < 0) 499 if (ret < 0)
487 return ret; 500 return ret;
488 if (v != 0x73) /* PID + VER = 0x76 / 0x73 */ 501 if (v != 0x73) /* PID + VER = 0x76 / 0x73 */
@@ -627,7 +640,7 @@ static struct ov7670_win_size {
627/* 640/*
628 * Store a set of start/stop values into the camera. 641 * Store a set of start/stop values into the camera.
629 */ 642 */
630static int ov7670_set_hw(struct i2c_client *client, int hstart, int hstop, 643static int ov7670_set_hw(struct v4l2_subdev *sd, int hstart, int hstop,
631 int vstart, int vstop) 644 int vstart, int vstop)
632{ 645{
633 int ret; 646 int ret;
@@ -637,26 +650,26 @@ static int ov7670_set_hw(struct i2c_client *client, int hstart, int hstop,
637 * hstart are in href[2:0], bottom 3 of hstop in href[5:3]. There is 650 * hstart are in href[2:0], bottom 3 of hstop in href[5:3]. There is
638 * a mystery "edge offset" value in the top two bits of href. 651 * a mystery "edge offset" value in the top two bits of href.
639 */ 652 */
640 ret = ov7670_write(client, REG_HSTART, (hstart >> 3) & 0xff); 653 ret = ov7670_write(sd, REG_HSTART, (hstart >> 3) & 0xff);
641 ret += ov7670_write(client, REG_HSTOP, (hstop >> 3) & 0xff); 654 ret += ov7670_write(sd, REG_HSTOP, (hstop >> 3) & 0xff);
642 ret += ov7670_read(client, REG_HREF, &v); 655 ret += ov7670_read(sd, REG_HREF, &v);
643 v = (v & 0xc0) | ((hstop & 0x7) << 3) | (hstart & 0x7); 656 v = (v & 0xc0) | ((hstop & 0x7) << 3) | (hstart & 0x7);
644 msleep(10); 657 msleep(10);
645 ret += ov7670_write(client, REG_HREF, v); 658 ret += ov7670_write(sd, REG_HREF, v);
646/* 659/*
647 * Vertical: similar arrangement, but only 10 bits. 660 * Vertical: similar arrangement, but only 10 bits.
648 */ 661 */
649 ret += ov7670_write(client, REG_VSTART, (vstart >> 2) & 0xff); 662 ret += ov7670_write(sd, REG_VSTART, (vstart >> 2) & 0xff);
650 ret += ov7670_write(client, REG_VSTOP, (vstop >> 2) & 0xff); 663 ret += ov7670_write(sd, REG_VSTOP, (vstop >> 2) & 0xff);
651 ret += ov7670_read(client, REG_VREF, &v); 664 ret += ov7670_read(sd, REG_VREF, &v);
652 v = (v & 0xf0) | ((vstop & 0x3) << 2) | (vstart & 0x3); 665 v = (v & 0xf0) | ((vstop & 0x3) << 2) | (vstart & 0x3);
653 msleep(10); 666 msleep(10);
654 ret += ov7670_write(client, REG_VREF, v); 667 ret += ov7670_write(sd, REG_VREF, v);
655 return ret; 668 return ret;
656} 669}
657 670
658 671
659static int ov7670_enum_fmt(struct i2c_client *c, struct v4l2_fmtdesc *fmt) 672static int ov7670_enum_fmt(struct v4l2_subdev *sd, struct v4l2_fmtdesc *fmt)
660{ 673{
661 struct ov7670_format_struct *ofmt; 674 struct ov7670_format_struct *ofmt;
662 675
@@ -671,7 +684,8 @@ static int ov7670_enum_fmt(struct i2c_client *c, struct v4l2_fmtdesc *fmt)
671} 684}
672 685
673 686
674static int ov7670_try_fmt(struct i2c_client *c, struct v4l2_format *fmt, 687static int ov7670_try_fmt_internal(struct v4l2_subdev *sd,
688 struct v4l2_format *fmt,
675 struct ov7670_format_struct **ret_fmt, 689 struct ov7670_format_struct **ret_fmt,
676 struct ov7670_win_size **ret_wsize) 690 struct ov7670_win_size **ret_wsize)
677{ 691{
@@ -715,18 +729,23 @@ static int ov7670_try_fmt(struct i2c_client *c, struct v4l2_format *fmt,
715 return 0; 729 return 0;
716} 730}
717 731
732static int ov7670_try_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt)
733{
734 return ov7670_try_fmt_internal(sd, fmt, NULL, NULL);
735}
736
718/* 737/*
719 * Set a format. 738 * Set a format.
720 */ 739 */
721static int ov7670_s_fmt(struct i2c_client *c, struct v4l2_format *fmt) 740static int ov7670_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt)
722{ 741{
723 int ret; 742 int ret;
724 struct ov7670_format_struct *ovfmt; 743 struct ov7670_format_struct *ovfmt;
725 struct ov7670_win_size *wsize; 744 struct ov7670_win_size *wsize;
726 struct ov7670_info *info = i2c_get_clientdata(c); 745 struct ov7670_info *info = to_state(sd);
727 unsigned char com7, clkrc; 746 unsigned char com7, clkrc = 0;
728 747
729 ret = ov7670_try_fmt(c, fmt, &ovfmt, &wsize); 748 ret = ov7670_try_fmt_internal(sd, fmt, &ovfmt, &wsize);
730 if (ret) 749 if (ret)
731 return ret; 750 return ret;
732 /* 751 /*
@@ -735,7 +754,7 @@ static int ov7670_s_fmt(struct i2c_client *c, struct v4l2_format *fmt)
735 * the colors. 754 * the colors.
736 */ 755 */
737 if (fmt->fmt.pix.pixelformat == V4L2_PIX_FMT_RGB565) { 756 if (fmt->fmt.pix.pixelformat == V4L2_PIX_FMT_RGB565) {
738 ret = ov7670_read(c, REG_CLKRC, &clkrc); 757 ret = ov7670_read(sd, REG_CLKRC, &clkrc);
739 if (ret) 758 if (ret)
740 return ret; 759 return ret;
741 } 760 }
@@ -747,20 +766,20 @@ static int ov7670_s_fmt(struct i2c_client *c, struct v4l2_format *fmt)
747 */ 766 */
748 com7 = ovfmt->regs[0].value; 767 com7 = ovfmt->regs[0].value;
749 com7 |= wsize->com7_bit; 768 com7 |= wsize->com7_bit;
750 ov7670_write(c, REG_COM7, com7); 769 ov7670_write(sd, REG_COM7, com7);
751 /* 770 /*
752 * Now write the rest of the array. Also store start/stops 771 * Now write the rest of the array. Also store start/stops
753 */ 772 */
754 ov7670_write_array(c, ovfmt->regs + 1); 773 ov7670_write_array(sd, ovfmt->regs + 1);
755 ov7670_set_hw(c, wsize->hstart, wsize->hstop, wsize->vstart, 774 ov7670_set_hw(sd, wsize->hstart, wsize->hstop, wsize->vstart,
756 wsize->vstop); 775 wsize->vstop);
757 ret = 0; 776 ret = 0;
758 if (wsize->regs) 777 if (wsize->regs)
759 ret = ov7670_write_array(c, wsize->regs); 778 ret = ov7670_write_array(sd, wsize->regs);
760 info->fmt = ovfmt; 779 info->fmt = ovfmt;
761 780
762 if (fmt->fmt.pix.pixelformat == V4L2_PIX_FMT_RGB565 && ret == 0) 781 if (fmt->fmt.pix.pixelformat == V4L2_PIX_FMT_RGB565 && ret == 0)
763 ret = ov7670_write(c, REG_CLKRC, clkrc); 782 ret = ov7670_write(sd, REG_CLKRC, clkrc);
764 return ret; 783 return ret;
765} 784}
766 785
@@ -768,7 +787,7 @@ static int ov7670_s_fmt(struct i2c_client *c, struct v4l2_format *fmt)
768 * Implement G/S_PARM. There is a "high quality" mode we could try 787 * Implement G/S_PARM. There is a "high quality" mode we could try
769 * to do someday; for now, we just do the frame rate tweak. 788 * to do someday; for now, we just do the frame rate tweak.
770 */ 789 */
771static int ov7670_g_parm(struct i2c_client *c, struct v4l2_streamparm *parms) 790static int ov7670_g_parm(struct v4l2_subdev *sd, struct v4l2_streamparm *parms)
772{ 791{
773 struct v4l2_captureparm *cp = &parms->parm.capture; 792 struct v4l2_captureparm *cp = &parms->parm.capture;
774 unsigned char clkrc; 793 unsigned char clkrc;
@@ -776,7 +795,7 @@ static int ov7670_g_parm(struct i2c_client *c, struct v4l2_streamparm *parms)
776 795
777 if (parms->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 796 if (parms->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
778 return -EINVAL; 797 return -EINVAL;
779 ret = ov7670_read(c, REG_CLKRC, &clkrc); 798 ret = ov7670_read(sd, REG_CLKRC, &clkrc);
780 if (ret < 0) 799 if (ret < 0)
781 return ret; 800 return ret;
782 memset(cp, 0, sizeof(struct v4l2_captureparm)); 801 memset(cp, 0, sizeof(struct v4l2_captureparm));
@@ -788,7 +807,7 @@ static int ov7670_g_parm(struct i2c_client *c, struct v4l2_streamparm *parms)
788 return 0; 807 return 0;
789} 808}
790 809
791static int ov7670_s_parm(struct i2c_client *c, struct v4l2_streamparm *parms) 810static int ov7670_s_parm(struct v4l2_subdev *sd, struct v4l2_streamparm *parms)
792{ 811{
793 struct v4l2_captureparm *cp = &parms->parm.capture; 812 struct v4l2_captureparm *cp = &parms->parm.capture;
794 struct v4l2_fract *tpf = &cp->timeperframe; 813 struct v4l2_fract *tpf = &cp->timeperframe;
@@ -802,7 +821,7 @@ static int ov7670_s_parm(struct i2c_client *c, struct v4l2_streamparm *parms)
802 /* 821 /*
803 * CLKRC has a reserved bit, so let's preserve it. 822 * CLKRC has a reserved bit, so let's preserve it.
804 */ 823 */
805 ret = ov7670_read(c, REG_CLKRC, &clkrc); 824 ret = ov7670_read(sd, REG_CLKRC, &clkrc);
806 if (ret < 0) 825 if (ret < 0)
807 return ret; 826 return ret;
808 if (tpf->numerator == 0 || tpf->denominator == 0) 827 if (tpf->numerator == 0 || tpf->denominator == 0)
@@ -816,7 +835,7 @@ static int ov7670_s_parm(struct i2c_client *c, struct v4l2_streamparm *parms)
816 clkrc = (clkrc & 0x80) | div; 835 clkrc = (clkrc & 0x80) | div;
817 tpf->numerator = 1; 836 tpf->numerator = 1;
818 tpf->denominator = OV7670_FRAME_RATE/div; 837 tpf->denominator = OV7670_FRAME_RATE/div;
819 return ov7670_write(c, REG_CLKRC, clkrc); 838 return ov7670_write(sd, REG_CLKRC, clkrc);
820} 839}
821 840
822 841
@@ -829,7 +848,7 @@ static int ov7670_s_parm(struct i2c_client *c, struct v4l2_streamparm *parms)
829 848
830 849
831 850
832static int ov7670_store_cmatrix(struct i2c_client *client, 851static int ov7670_store_cmatrix(struct v4l2_subdev *sd,
833 int matrix[CMATRIX_LEN]) 852 int matrix[CMATRIX_LEN])
834{ 853{
835 int i, ret; 854 int i, ret;
@@ -839,7 +858,7 @@ static int ov7670_store_cmatrix(struct i2c_client *client,
839 * Weird crap seems to exist in the upper part of 858 * Weird crap seems to exist in the upper part of
840 * the sign bits register, so let's preserve it. 859 * the sign bits register, so let's preserve it.
841 */ 860 */
842 ret = ov7670_read(client, REG_CMATRIX_SIGN, &signbits); 861 ret = ov7670_read(sd, REG_CMATRIX_SIGN, &signbits);
843 signbits &= 0xc0; 862 signbits &= 0xc0;
844 863
845 for (i = 0; i < CMATRIX_LEN; i++) { 864 for (i = 0; i < CMATRIX_LEN; i++) {
@@ -858,9 +877,9 @@ static int ov7670_store_cmatrix(struct i2c_client *client,
858 else 877 else
859 raw = matrix[i] & 0xff; 878 raw = matrix[i] & 0xff;
860 } 879 }
861 ret += ov7670_write(client, REG_CMATRIX_BASE + i, raw); 880 ret += ov7670_write(sd, REG_CMATRIX_BASE + i, raw);
862 } 881 }
863 ret += ov7670_write(client, REG_CMATRIX_SIGN, signbits); 882 ret += ov7670_write(sd, REG_CMATRIX_SIGN, signbits);
864 return ret; 883 return ret;
865} 884}
866 885
@@ -943,29 +962,29 @@ static void ov7670_calc_cmatrix(struct ov7670_info *info,
943 962
944 963
945 964
946static int ov7670_t_sat(struct i2c_client *client, int value) 965static int ov7670_s_sat(struct v4l2_subdev *sd, int value)
947{ 966{
948 struct ov7670_info *info = i2c_get_clientdata(client); 967 struct ov7670_info *info = to_state(sd);
949 int matrix[CMATRIX_LEN]; 968 int matrix[CMATRIX_LEN];
950 int ret; 969 int ret;
951 970
952 info->sat = value; 971 info->sat = value;
953 ov7670_calc_cmatrix(info, matrix); 972 ov7670_calc_cmatrix(info, matrix);
954 ret = ov7670_store_cmatrix(client, matrix); 973 ret = ov7670_store_cmatrix(sd, matrix);
955 return ret; 974 return ret;
956} 975}
957 976
958static int ov7670_q_sat(struct i2c_client *client, __s32 *value) 977static int ov7670_g_sat(struct v4l2_subdev *sd, __s32 *value)
959{ 978{
960 struct ov7670_info *info = i2c_get_clientdata(client); 979 struct ov7670_info *info = to_state(sd);
961 980
962 *value = info->sat; 981 *value = info->sat;
963 return 0; 982 return 0;
964} 983}
965 984
966static int ov7670_t_hue(struct i2c_client *client, int value) 985static int ov7670_s_hue(struct v4l2_subdev *sd, int value)
967{ 986{
968 struct ov7670_info *info = i2c_get_clientdata(client); 987 struct ov7670_info *info = to_state(sd);
969 int matrix[CMATRIX_LEN]; 988 int matrix[CMATRIX_LEN];
970 int ret; 989 int ret;
971 990
@@ -973,14 +992,14 @@ static int ov7670_t_hue(struct i2c_client *client, int value)
973 return -EINVAL; 992 return -EINVAL;
974 info->hue = value; 993 info->hue = value;
975 ov7670_calc_cmatrix(info, matrix); 994 ov7670_calc_cmatrix(info, matrix);
976 ret = ov7670_store_cmatrix(client, matrix); 995 ret = ov7670_store_cmatrix(sd, matrix);
977 return ret; 996 return ret;
978} 997}
979 998
980 999
981static int ov7670_q_hue(struct i2c_client *client, __s32 *value) 1000static int ov7670_g_hue(struct v4l2_subdev *sd, __s32 *value)
982{ 1001{
983 struct ov7670_info *info = i2c_get_clientdata(client); 1002 struct ov7670_info *info = to_state(sd);
984 1003
985 *value = info->hue; 1004 *value = info->hue;
986 return 0; 1005 return 0;
@@ -994,8 +1013,7 @@ static unsigned char ov7670_sm_to_abs(unsigned char v)
994{ 1013{
995 if ((v & 0x80) == 0) 1014 if ((v & 0x80) == 0)
996 return v + 128; 1015 return v + 128;
997 else 1016 return 128 - (v & 0x7f);
998 return 128 - (v & 0x7f);
999} 1017}
1000 1018
1001 1019
@@ -1003,369 +1021,275 @@ static unsigned char ov7670_abs_to_sm(unsigned char v)
1003{ 1021{
1004 if (v > 127) 1022 if (v > 127)
1005 return v & 0x7f; 1023 return v & 0x7f;
1006 else 1024 return (128 - v) | 0x80;
1007 return (128 - v) | 0x80;
1008} 1025}
1009 1026
1010static int ov7670_t_brightness(struct i2c_client *client, int value) 1027static int ov7670_s_brightness(struct v4l2_subdev *sd, int value)
1011{ 1028{
1012 unsigned char com8 = 0, v; 1029 unsigned char com8 = 0, v;
1013 int ret; 1030 int ret;
1014 1031
1015 ov7670_read(client, REG_COM8, &com8); 1032 ov7670_read(sd, REG_COM8, &com8);
1016 com8 &= ~COM8_AEC; 1033 com8 &= ~COM8_AEC;
1017 ov7670_write(client, REG_COM8, com8); 1034 ov7670_write(sd, REG_COM8, com8);
1018 v = ov7670_abs_to_sm(value); 1035 v = ov7670_abs_to_sm(value);
1019 ret = ov7670_write(client, REG_BRIGHT, v); 1036 ret = ov7670_write(sd, REG_BRIGHT, v);
1020 return ret; 1037 return ret;
1021} 1038}
1022 1039
1023static int ov7670_q_brightness(struct i2c_client *client, __s32 *value) 1040static int ov7670_g_brightness(struct v4l2_subdev *sd, __s32 *value)
1024{ 1041{
1025 unsigned char v = 0; 1042 unsigned char v = 0;
1026 int ret = ov7670_read(client, REG_BRIGHT, &v); 1043 int ret = ov7670_read(sd, REG_BRIGHT, &v);
1027 1044
1028 *value = ov7670_sm_to_abs(v); 1045 *value = ov7670_sm_to_abs(v);
1029 return ret; 1046 return ret;
1030} 1047}
1031 1048
1032static int ov7670_t_contrast(struct i2c_client *client, int value) 1049static int ov7670_s_contrast(struct v4l2_subdev *sd, int value)
1033{ 1050{
1034 return ov7670_write(client, REG_CONTRAS, (unsigned char) value); 1051 return ov7670_write(sd, REG_CONTRAS, (unsigned char) value);
1035} 1052}
1036 1053
1037static int ov7670_q_contrast(struct i2c_client *client, __s32 *value) 1054static int ov7670_g_contrast(struct v4l2_subdev *sd, __s32 *value)
1038{ 1055{
1039 unsigned char v = 0; 1056 unsigned char v = 0;
1040 int ret = ov7670_read(client, REG_CONTRAS, &v); 1057 int ret = ov7670_read(sd, REG_CONTRAS, &v);
1041 1058
1042 *value = v; 1059 *value = v;
1043 return ret; 1060 return ret;
1044} 1061}
1045 1062
1046static int ov7670_q_hflip(struct i2c_client *client, __s32 *value) 1063static int ov7670_g_hflip(struct v4l2_subdev *sd, __s32 *value)
1047{ 1064{
1048 int ret; 1065 int ret;
1049 unsigned char v = 0; 1066 unsigned char v = 0;
1050 1067
1051 ret = ov7670_read(client, REG_MVFP, &v); 1068 ret = ov7670_read(sd, REG_MVFP, &v);
1052 *value = (v & MVFP_MIRROR) == MVFP_MIRROR; 1069 *value = (v & MVFP_MIRROR) == MVFP_MIRROR;
1053 return ret; 1070 return ret;
1054} 1071}
1055 1072
1056 1073
1057static int ov7670_t_hflip(struct i2c_client *client, int value) 1074static int ov7670_s_hflip(struct v4l2_subdev *sd, int value)
1058{ 1075{
1059 unsigned char v = 0; 1076 unsigned char v = 0;
1060 int ret; 1077 int ret;
1061 1078
1062 ret = ov7670_read(client, REG_MVFP, &v); 1079 ret = ov7670_read(sd, REG_MVFP, &v);
1063 if (value) 1080 if (value)
1064 v |= MVFP_MIRROR; 1081 v |= MVFP_MIRROR;
1065 else 1082 else
1066 v &= ~MVFP_MIRROR; 1083 v &= ~MVFP_MIRROR;
1067 msleep(10); /* FIXME */ 1084 msleep(10); /* FIXME */
1068 ret += ov7670_write(client, REG_MVFP, v); 1085 ret += ov7670_write(sd, REG_MVFP, v);
1069 return ret; 1086 return ret;
1070} 1087}
1071 1088
1072 1089
1073 1090
1074static int ov7670_q_vflip(struct i2c_client *client, __s32 *value) 1091static int ov7670_g_vflip(struct v4l2_subdev *sd, __s32 *value)
1075{ 1092{
1076 int ret; 1093 int ret;
1077 unsigned char v = 0; 1094 unsigned char v = 0;
1078 1095
1079 ret = ov7670_read(client, REG_MVFP, &v); 1096 ret = ov7670_read(sd, REG_MVFP, &v);
1080 *value = (v & MVFP_FLIP) == MVFP_FLIP; 1097 *value = (v & MVFP_FLIP) == MVFP_FLIP;
1081 return ret; 1098 return ret;
1082} 1099}
1083 1100
1084 1101
1085static int ov7670_t_vflip(struct i2c_client *client, int value) 1102static int ov7670_s_vflip(struct v4l2_subdev *sd, int value)
1086{ 1103{
1087 unsigned char v = 0; 1104 unsigned char v = 0;
1088 int ret; 1105 int ret;
1089 1106
1090 ret = ov7670_read(client, REG_MVFP, &v); 1107 ret = ov7670_read(sd, REG_MVFP, &v);
1091 if (value) 1108 if (value)
1092 v |= MVFP_FLIP; 1109 v |= MVFP_FLIP;
1093 else 1110 else
1094 v &= ~MVFP_FLIP; 1111 v &= ~MVFP_FLIP;
1095 msleep(10); /* FIXME */ 1112 msleep(10); /* FIXME */
1096 ret += ov7670_write(client, REG_MVFP, v); 1113 ret += ov7670_write(sd, REG_MVFP, v);
1097 return ret; 1114 return ret;
1098} 1115}
1099 1116
1100 1117static int ov7670_queryctrl(struct v4l2_subdev *sd,
1101static struct ov7670_control { 1118 struct v4l2_queryctrl *qc)
1102 struct v4l2_queryctrl qc;
1103 int (*query)(struct i2c_client *c, __s32 *value);
1104 int (*tweak)(struct i2c_client *c, int value);
1105} ov7670_controls[] =
1106{ 1119{
1107 { 1120 /* Fill in min, max, step and default value for these controls. */
1108 .qc = { 1121 switch (qc->id) {
1109 .id = V4L2_CID_BRIGHTNESS, 1122 case V4L2_CID_BRIGHTNESS:
1110 .type = V4L2_CTRL_TYPE_INTEGER, 1123 return v4l2_ctrl_query_fill(qc, 0, 255, 1, 128);
1111 .name = "Brightness", 1124 case V4L2_CID_CONTRAST:
1112 .minimum = 0, 1125 return v4l2_ctrl_query_fill(qc, 0, 127, 1, 64);
1113 .maximum = 255, 1126 case V4L2_CID_VFLIP:
1114 .step = 1, 1127 case V4L2_CID_HFLIP:
1115 .default_value = 0x80, 1128 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 0);
1116 .flags = V4L2_CTRL_FLAG_SLIDER 1129 case V4L2_CID_SATURATION:
1117 }, 1130 return v4l2_ctrl_query_fill(qc, 0, 256, 1, 128);
1118 .tweak = ov7670_t_brightness, 1131 case V4L2_CID_HUE:
1119 .query = ov7670_q_brightness, 1132 return v4l2_ctrl_query_fill(qc, -180, 180, 5, 0);
1120 }, 1133 }
1121 { 1134 return -EINVAL;
1122 .qc = { 1135}
1123 .id = V4L2_CID_CONTRAST,
1124 .type = V4L2_CTRL_TYPE_INTEGER,
1125 .name = "Contrast",
1126 .minimum = 0,
1127 .maximum = 127,
1128 .step = 1,
1129 .default_value = 0x40, /* XXX ov7670 spec */
1130 .flags = V4L2_CTRL_FLAG_SLIDER
1131 },
1132 .tweak = ov7670_t_contrast,
1133 .query = ov7670_q_contrast,
1134 },
1135 {
1136 .qc = {
1137 .id = V4L2_CID_SATURATION,
1138 .type = V4L2_CTRL_TYPE_INTEGER,
1139 .name = "Saturation",
1140 .minimum = 0,
1141 .maximum = 256,
1142 .step = 1,
1143 .default_value = 0x80,
1144 .flags = V4L2_CTRL_FLAG_SLIDER
1145 },
1146 .tweak = ov7670_t_sat,
1147 .query = ov7670_q_sat,
1148 },
1149 {
1150 .qc = {
1151 .id = V4L2_CID_HUE,
1152 .type = V4L2_CTRL_TYPE_INTEGER,
1153 .name = "HUE",
1154 .minimum = -180,
1155 .maximum = 180,
1156 .step = 5,
1157 .default_value = 0,
1158 .flags = V4L2_CTRL_FLAG_SLIDER
1159 },
1160 .tweak = ov7670_t_hue,
1161 .query = ov7670_q_hue,
1162 },
1163 {
1164 .qc = {
1165 .id = V4L2_CID_VFLIP,
1166 .type = V4L2_CTRL_TYPE_BOOLEAN,
1167 .name = "Vertical flip",
1168 .minimum = 0,
1169 .maximum = 1,
1170 .step = 1,
1171 .default_value = 0,
1172 },
1173 .tweak = ov7670_t_vflip,
1174 .query = ov7670_q_vflip,
1175 },
1176 {
1177 .qc = {
1178 .id = V4L2_CID_HFLIP,
1179 .type = V4L2_CTRL_TYPE_BOOLEAN,
1180 .name = "Horizontal mirror",
1181 .minimum = 0,
1182 .maximum = 1,
1183 .step = 1,
1184 .default_value = 0,
1185 },
1186 .tweak = ov7670_t_hflip,
1187 .query = ov7670_q_hflip,
1188 },
1189};
1190#define N_CONTROLS (ARRAY_SIZE(ov7670_controls))
1191 1136
1192static struct ov7670_control *ov7670_find_control(__u32 id) 1137static int ov7670_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
1193{ 1138{
1194 int i; 1139 switch (ctrl->id) {
1195 1140 case V4L2_CID_BRIGHTNESS:
1196 for (i = 0; i < N_CONTROLS; i++) 1141 return ov7670_g_brightness(sd, &ctrl->value);
1197 if (ov7670_controls[i].qc.id == id) 1142 case V4L2_CID_CONTRAST:
1198 return ov7670_controls + i; 1143 return ov7670_g_contrast(sd, &ctrl->value);
1199 return NULL; 1144 case V4L2_CID_SATURATION:
1145 return ov7670_g_sat(sd, &ctrl->value);
1146 case V4L2_CID_HUE:
1147 return ov7670_g_hue(sd, &ctrl->value);
1148 case V4L2_CID_VFLIP:
1149 return ov7670_g_vflip(sd, &ctrl->value);
1150 case V4L2_CID_HFLIP:
1151 return ov7670_g_hflip(sd, &ctrl->value);
1152 }
1153 return -EINVAL;
1200} 1154}
1201 1155
1156static int ov7670_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
1157{
1158 switch (ctrl->id) {
1159 case V4L2_CID_BRIGHTNESS:
1160 return ov7670_s_brightness(sd, ctrl->value);
1161 case V4L2_CID_CONTRAST:
1162 return ov7670_s_contrast(sd, ctrl->value);
1163 case V4L2_CID_SATURATION:
1164 return ov7670_s_sat(sd, ctrl->value);
1165 case V4L2_CID_HUE:
1166 return ov7670_s_hue(sd, ctrl->value);
1167 case V4L2_CID_VFLIP:
1168 return ov7670_s_vflip(sd, ctrl->value);
1169 case V4L2_CID_HFLIP:
1170 return ov7670_s_hflip(sd, ctrl->value);
1171 }
1172 return -EINVAL;
1173}
1202 1174
1203static int ov7670_queryctrl(struct i2c_client *client, 1175static int ov7670_g_chip_ident(struct v4l2_subdev *sd,
1204 struct v4l2_queryctrl *qc) 1176 struct v4l2_dbg_chip_ident *chip)
1205{ 1177{
1206 struct ov7670_control *ctrl = ov7670_find_control(qc->id); 1178 struct i2c_client *client = v4l2_get_subdevdata(sd);
1207 1179
1208 if (ctrl == NULL) 1180 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_OV7670, 0);
1209 return -EINVAL;
1210 *qc = ctrl->qc;
1211 return 0;
1212} 1181}
1213 1182
1214static int ov7670_g_ctrl(struct i2c_client *client, struct v4l2_control *ctrl) 1183#ifdef CONFIG_VIDEO_ADV_DEBUG
1184static int ov7670_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg)
1215{ 1185{
1216 struct ov7670_control *octrl = ov7670_find_control(ctrl->id); 1186 struct i2c_client *client = v4l2_get_subdevdata(sd);
1187 unsigned char val = 0;
1217 int ret; 1188 int ret;
1218 1189
1219 if (octrl == NULL) 1190 if (!v4l2_chip_match_i2c_client(client, &reg->match))
1220 return -EINVAL; 1191 return -EINVAL;
1221 ret = octrl->query(client, &ctrl->value); 1192 if (!capable(CAP_SYS_ADMIN))
1222 if (ret >= 0) 1193 return -EPERM;
1223 return 0; 1194 ret = ov7670_read(sd, reg->reg & 0xff, &val);
1195 reg->val = val;
1196 reg->size = 1;
1224 return ret; 1197 return ret;
1225} 1198}
1226 1199
1227static int ov7670_s_ctrl(struct i2c_client *client, struct v4l2_control *ctrl) 1200static int ov7670_s_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg)
1228{ 1201{
1229 struct ov7670_control *octrl = ov7670_find_control(ctrl->id); 1202 struct i2c_client *client = v4l2_get_subdevdata(sd);
1230 int ret;
1231 1203
1232 if (octrl == NULL) 1204 if (!v4l2_chip_match_i2c_client(client, &reg->match))
1233 return -EINVAL; 1205 return -EINVAL;
1234 ret = octrl->tweak(client, ctrl->value); 1206 if (!capable(CAP_SYS_ADMIN))
1235 if (ret >= 0) 1207 return -EPERM;
1236 return 0; 1208 ov7670_write(sd, reg->reg & 0xff, reg->val & 0xff);
1237 return ret; 1209 return 0;
1238} 1210}
1211#endif
1212
1213/* ----------------------------------------------------------------------- */
1214
1215static const struct v4l2_subdev_core_ops ov7670_core_ops = {
1216 .g_chip_ident = ov7670_g_chip_ident,
1217 .g_ctrl = ov7670_g_ctrl,
1218 .s_ctrl = ov7670_s_ctrl,
1219 .queryctrl = ov7670_queryctrl,
1220 .reset = ov7670_reset,
1221 .init = ov7670_init,
1222#ifdef CONFIG_VIDEO_ADV_DEBUG
1223 .g_register = ov7670_g_register,
1224 .s_register = ov7670_s_register,
1225#endif
1226};
1239 1227
1228static const struct v4l2_subdev_video_ops ov7670_video_ops = {
1229 .enum_fmt = ov7670_enum_fmt,
1230 .try_fmt = ov7670_try_fmt,
1231 .s_fmt = ov7670_s_fmt,
1232 .s_parm = ov7670_s_parm,
1233 .g_parm = ov7670_g_parm,
1234};
1240 1235
1236static const struct v4l2_subdev_ops ov7670_ops = {
1237 .core = &ov7670_core_ops,
1238 .video = &ov7670_video_ops,
1239};
1241 1240
1241/* ----------------------------------------------------------------------- */
1242 1242
1243 1243static int ov7670_probe(struct i2c_client *client,
1244 1244 const struct i2c_device_id *id)
1245/*
1246 * Basic i2c stuff.
1247 */
1248static struct i2c_driver ov7670_driver;
1249
1250static int ov7670_attach(struct i2c_adapter *adapter)
1251{ 1245{
1252 int ret; 1246 struct v4l2_subdev *sd;
1253 struct i2c_client *client;
1254 struct ov7670_info *info; 1247 struct ov7670_info *info;
1248 int ret;
1255 1249
1256 /* 1250 info = kzalloc(sizeof(struct ov7670_info), GFP_KERNEL);
1257 * For now: only deal with adapters we recognize. 1251 if (info == NULL)
1258 */
1259 if (adapter->id != I2C_HW_SMBUS_CAFE)
1260 return -ENODEV;
1261
1262 client = kzalloc(sizeof (struct i2c_client), GFP_KERNEL);
1263 if (! client)
1264 return -ENOMEM; 1252 return -ENOMEM;
1265 client->adapter = adapter; 1253 sd = &info->sd;
1266 client->addr = OV7670_I2C_ADDR; 1254 v4l2_i2c_subdev_init(sd, client, &ov7670_ops);
1267 client->driver = &ov7670_driver, 1255
1268 strcpy(client->name, "OV7670"); 1256 /* Make sure it's an ov7670 */
1269 /* 1257 ret = ov7670_detect(sd);
1270 * Set up our info structure. 1258 if (ret) {
1271 */ 1259 v4l_dbg(1, debug, client,
1272 info = kzalloc(sizeof (struct ov7670_info), GFP_KERNEL); 1260 "chip found @ 0x%x (%s) is not an ov7670 chip.\n",
1273 if (! info) { 1261 client->addr << 1, client->adapter->name);
1274 ret = -ENOMEM; 1262 kfree(info);
1275 goto out_free; 1263 return ret;
1276 } 1264 }
1265 v4l_info(client, "chip found @ 0x%02x (%s)\n",
1266 client->addr << 1, client->adapter->name);
1267
1277 info->fmt = &ov7670_formats[0]; 1268 info->fmt = &ov7670_formats[0];
1278 info->sat = 128; /* Review this */ 1269 info->sat = 128; /* Review this */
1279 i2c_set_clientdata(client, info);
1280 1270
1281 /*
1282 * Make sure it's an ov7670
1283 */
1284 ret = ov7670_detect(client);
1285 if (ret)
1286 goto out_free_info;
1287 ret = i2c_attach_client(client);
1288 if (ret)
1289 goto out_free_info;
1290 return 0; 1271 return 0;
1291
1292 out_free_info:
1293 kfree(info);
1294 out_free:
1295 kfree(client);
1296 return ret;
1297} 1272}
1298 1273
1299 1274
1300static int ov7670_detach(struct i2c_client *client) 1275static int ov7670_remove(struct i2c_client *client)
1301{ 1276{
1302 i2c_detach_client(client); 1277 struct v4l2_subdev *sd = i2c_get_clientdata(client);
1303 kfree(i2c_get_clientdata(client));
1304 kfree(client);
1305 return 0;
1306}
1307
1308 1278
1309static int ov7670_command(struct i2c_client *client, unsigned int cmd, 1279 v4l2_device_unregister_subdev(sd);
1310 void *arg) 1280 kfree(to_state(sd));
1311{ 1281 return 0;
1312 switch (cmd) {
1313 case VIDIOC_DBG_G_CHIP_IDENT:
1314 return v4l2_chip_ident_i2c_client(client, arg, V4L2_IDENT_OV7670, 0);
1315
1316 case VIDIOC_INT_RESET:
1317 ov7670_reset(client);
1318 return 0;
1319
1320 case VIDIOC_INT_INIT:
1321 return ov7670_init(client);
1322
1323 case VIDIOC_ENUM_FMT:
1324 return ov7670_enum_fmt(client, (struct v4l2_fmtdesc *) arg);
1325 case VIDIOC_TRY_FMT:
1326 return ov7670_try_fmt(client, (struct v4l2_format *) arg, NULL, NULL);
1327 case VIDIOC_S_FMT:
1328 return ov7670_s_fmt(client, (struct v4l2_format *) arg);
1329 case VIDIOC_QUERYCTRL:
1330 return ov7670_queryctrl(client, (struct v4l2_queryctrl *) arg);
1331 case VIDIOC_S_CTRL:
1332 return ov7670_s_ctrl(client, (struct v4l2_control *) arg);
1333 case VIDIOC_G_CTRL:
1334 return ov7670_g_ctrl(client, (struct v4l2_control *) arg);
1335 case VIDIOC_S_PARM:
1336 return ov7670_s_parm(client, (struct v4l2_streamparm *) arg);
1337 case VIDIOC_G_PARM:
1338 return ov7670_g_parm(client, (struct v4l2_streamparm *) arg);
1339 }
1340 return -EINVAL;
1341} 1282}
1342 1283
1343 1284static const struct i2c_device_id ov7670_id[] = {
1344 1285 { "ov7670", 0 },
1345static struct i2c_driver ov7670_driver = { 1286 { }
1346 .driver = {
1347 .name = "ov7670",
1348 },
1349 .id = I2C_DRIVERID_OV7670,
1350 .attach_adapter = ov7670_attach,
1351 .detach_client = ov7670_detach,
1352 .command = ov7670_command,
1353}; 1287};
1288MODULE_DEVICE_TABLE(i2c, ov7670_id);
1354 1289
1355 1290static struct v4l2_i2c_driver_data v4l2_i2c_data = {
1356/* 1291 .name = "ov7670",
1357 * Module initialization 1292 .probe = ov7670_probe,
1358 */ 1293 .remove = ov7670_remove,
1359static int __init ov7670_mod_init(void) 1294 .id_table = ov7670_id,
1360{ 1295};
1361 printk(KERN_NOTICE "OmniVision ov7670 sensor driver, at your service\n");
1362 return i2c_add_driver(&ov7670_driver);
1363}
1364
1365static void __exit ov7670_mod_exit(void)
1366{
1367 i2c_del_driver(&ov7670_driver);
1368}
1369
1370module_init(ov7670_mod_init);
1371module_exit(ov7670_mod_exit);
diff --git a/drivers/media/video/ov772x.c b/drivers/media/video/ov772x.c
index 3c9e0ba974e9..84b0fc1bb237 100644
--- a/drivers/media/video/ov772x.c
+++ b/drivers/media/video/ov772x.c
@@ -217,10 +217,11 @@
217#define OCAP_4x 0x03 /* 4x */ 217#define OCAP_4x 0x03 /* 4x */
218 218
219/* COM3 */ 219/* COM3 */
220#define SWAP_MASK 0x38 220#define SWAP_MASK (SWAP_RGB | SWAP_YUV | SWAP_ML)
221#define IMG_MASK (VFLIP_IMG | HFLIP_IMG)
221 222
222#define VFIMG_ON_OFF 0x80 /* Vertical flip image ON/OFF selection */ 223#define VFLIP_IMG 0x80 /* Vertical flip image ON/OFF selection */
223#define HMIMG_ON_OFF 0x40 /* Horizontal mirror image ON/OFF selection */ 224#define HFLIP_IMG 0x40 /* Horizontal mirror image ON/OFF selection */
224#define SWAP_RGB 0x20 /* Swap B/R output sequence in RGB mode */ 225#define SWAP_RGB 0x20 /* Swap B/R output sequence in RGB mode */
225#define SWAP_YUV 0x10 /* Swap Y/UV output sequence in YUV mode */ 226#define SWAP_YUV 0x10 /* Swap Y/UV output sequence in YUV mode */
226#define SWAP_ML 0x08 /* Swap output MSB/LSB */ 227#define SWAP_ML 0x08 /* Swap output MSB/LSB */
@@ -271,11 +272,13 @@
271#define SLCT_QVGA 0x40 /* 1 : QVGA */ 272#define SLCT_QVGA 0x40 /* 1 : QVGA */
272#define ITU656_ON_OFF 0x20 /* ITU656 protocol ON/OFF selection */ 273#define ITU656_ON_OFF 0x20 /* ITU656 protocol ON/OFF selection */
273 /* RGB output format control */ 274 /* RGB output format control */
275#define FMT_MASK 0x0c /* Mask of color format */
274#define FMT_GBR422 0x00 /* 00 : GBR 4:2:2 */ 276#define FMT_GBR422 0x00 /* 00 : GBR 4:2:2 */
275#define FMT_RGB565 0x04 /* 01 : RGB 565 */ 277#define FMT_RGB565 0x04 /* 01 : RGB 565 */
276#define FMT_RGB555 0x08 /* 10 : RGB 555 */ 278#define FMT_RGB555 0x08 /* 10 : RGB 555 */
277#define FMT_RGB444 0x0c /* 11 : RGB 444 */ 279#define FMT_RGB444 0x0c /* 11 : RGB 444 */
278 /* Output format control */ 280 /* Output format control */
281#define OFMT_MASK 0x03 /* Mask of output format */
279#define OFMT_YUV 0x00 /* 00 : YUV */ 282#define OFMT_YUV 0x00 /* 00 : YUV */
280#define OFMT_P_BRAW 0x01 /* 01 : Processed Bayer RAW */ 283#define OFMT_P_BRAW 0x01 /* 01 : Processed Bayer RAW */
281#define OFMT_RGB 0x02 /* 10 : RGB */ 284#define OFMT_RGB 0x02 /* 10 : RGB */
@@ -299,7 +302,7 @@
299#define GAIN_2x 0x00 /* 000 : 2x */ 302#define GAIN_2x 0x00 /* 000 : 2x */
300#define GAIN_4x 0x10 /* 001 : 4x */ 303#define GAIN_4x 0x10 /* 001 : 4x */
301#define GAIN_8x 0x20 /* 010 : 8x */ 304#define GAIN_8x 0x20 /* 010 : 8x */
302#define GAIN_16x 0x30 /* 011 : 16x */ 305#define GAIN_16x 0x30 /* 011 : 16x */
303#define GAIN_32x 0x40 /* 100 : 32x */ 306#define GAIN_32x 0x40 /* 100 : 32x */
304#define GAIN_64x 0x50 /* 101 : 64x */ 307#define GAIN_64x 0x50 /* 101 : 64x */
305#define GAIN_128x 0x60 /* 110 : 128x */ 308#define GAIN_128x 0x60 /* 110 : 128x */
@@ -356,13 +359,6 @@
356#define VOSZ_QVGA 0x78 359#define VOSZ_QVGA 0x78
357 360
358/* 361/*
359 * bit configure (32 bit)
360 * this is used in struct ov772x_color_format :: option
361 */
362#define OP_UV 0x00000001
363#define OP_SWAP_RGB 0x00000002
364
365/*
366 * ID 362 * ID
367 */ 363 */
368#define OV7720 0x7720 364#define OV7720 0x7720
@@ -380,8 +376,9 @@ struct regval_list {
380struct ov772x_color_format { 376struct ov772x_color_format {
381 char *name; 377 char *name;
382 __u32 fourcc; 378 __u32 fourcc;
383 const struct regval_list *regs; 379 u8 dsp3;
384 unsigned int option; 380 u8 com3;
381 u8 com7;
385}; 382};
386 383
387struct ov772x_win_size { 384struct ov772x_win_size {
@@ -399,39 +396,13 @@ struct ov772x_priv {
399 const struct ov772x_color_format *fmt; 396 const struct ov772x_color_format *fmt;
400 const struct ov772x_win_size *win; 397 const struct ov772x_win_size *win;
401 int model; 398 int model;
399 unsigned int flag_vflip:1;
400 unsigned int flag_hflip:1;
402}; 401};
403 402
404#define ENDMARKER { 0xff, 0xff } 403#define ENDMARKER { 0xff, 0xff }
405 404
406/* 405/*
407 * register setting for color format
408 */
409static const struct regval_list ov772x_RGB555_regs[] = {
410 { COM3, 0x00 },
411 { COM7, FMT_RGB555 | OFMT_RGB },
412 ENDMARKER,
413};
414
415static const struct regval_list ov772x_RGB565_regs[] = {
416 { COM3, 0x00 },
417 { COM7, FMT_RGB565 | OFMT_RGB },
418 ENDMARKER,
419};
420
421static const struct regval_list ov772x_YYUV_regs[] = {
422 { COM3, SWAP_YUV },
423 { COM7, OFMT_YUV },
424 ENDMARKER,
425};
426
427static const struct regval_list ov772x_UVYY_regs[] = {
428 { COM3, 0x00 },
429 { COM7, OFMT_YUV },
430 ENDMARKER,
431};
432
433
434/*
435 * register setting for window size 406 * register setting for window size
436 */ 407 */
437static const struct regval_list ov772x_qvga_regs[] = { 408static const struct regval_list ov772x_qvga_regs[] = {
@@ -500,38 +471,48 @@ static const struct soc_camera_data_format ov772x_fmt_lists[] = {
500/* 471/*
501 * color format list 472 * color format list
502 */ 473 */
503#define T_YUYV 0
504static const struct ov772x_color_format ov772x_cfmts[] = { 474static const struct ov772x_color_format ov772x_cfmts[] = {
505 [T_YUYV] = { 475 {
506 SETFOURCC(YUYV), 476 SETFOURCC(YUYV),
507 .regs = ov772x_YYUV_regs, 477 .dsp3 = 0x0,
478 .com3 = SWAP_YUV,
479 .com7 = OFMT_YUV,
508 }, 480 },
509 { 481 {
510 SETFOURCC(YVYU), 482 SETFOURCC(YVYU),
511 .regs = ov772x_YYUV_regs, 483 .dsp3 = UV_ON,
512 .option = OP_UV, 484 .com3 = SWAP_YUV,
485 .com7 = OFMT_YUV,
513 }, 486 },
514 { 487 {
515 SETFOURCC(UYVY), 488 SETFOURCC(UYVY),
516 .regs = ov772x_UVYY_regs, 489 .dsp3 = 0x0,
490 .com3 = 0x0,
491 .com7 = OFMT_YUV,
517 }, 492 },
518 { 493 {
519 SETFOURCC(RGB555), 494 SETFOURCC(RGB555),
520 .regs = ov772x_RGB555_regs, 495 .dsp3 = 0x0,
521 .option = OP_SWAP_RGB, 496 .com3 = SWAP_RGB,
497 .com7 = FMT_RGB555 | OFMT_RGB,
522 }, 498 },
523 { 499 {
524 SETFOURCC(RGB555X), 500 SETFOURCC(RGB555X),
525 .regs = ov772x_RGB555_regs, 501 .dsp3 = 0x0,
502 .com3 = 0x0,
503 .com7 = FMT_RGB555 | OFMT_RGB,
526 }, 504 },
527 { 505 {
528 SETFOURCC(RGB565), 506 SETFOURCC(RGB565),
529 .regs = ov772x_RGB565_regs, 507 .dsp3 = 0x0,
530 .option = OP_SWAP_RGB, 508 .com3 = SWAP_RGB,
509 .com7 = FMT_RGB565 | OFMT_RGB,
531 }, 510 },
532 { 511 {
533 SETFOURCC(RGB565X), 512 SETFOURCC(RGB565X),
534 .regs = ov772x_RGB565_regs, 513 .dsp3 = 0x0,
514 .com3 = 0x0,
515 .com7 = FMT_RGB565 | OFMT_RGB,
535 }, 516 },
536}; 517};
537 518
@@ -562,6 +543,27 @@ static const struct ov772x_win_size ov772x_win_qvga = {
562 .regs = ov772x_qvga_regs, 543 .regs = ov772x_qvga_regs,
563}; 544};
564 545
546static const struct v4l2_queryctrl ov772x_controls[] = {
547 {
548 .id = V4L2_CID_VFLIP,
549 .type = V4L2_CTRL_TYPE_BOOLEAN,
550 .name = "Flip Vertically",
551 .minimum = 0,
552 .maximum = 1,
553 .step = 1,
554 .default_value = 0,
555 },
556 {
557 .id = V4L2_CID_HFLIP,
558 .type = V4L2_CTRL_TYPE_BOOLEAN,
559 .name = "Flip Horizontally",
560 .minimum = 0,
561 .maximum = 1,
562 .step = 1,
563 .default_value = 0,
564 },
565};
566
565 567
566/* 568/*
567 * general function 569 * general function
@@ -587,8 +589,11 @@ static int ov772x_mask_set(struct i2c_client *client,
587 u8 set) 589 u8 set)
588{ 590{
589 s32 val = i2c_smbus_read_byte_data(client, command); 591 s32 val = i2c_smbus_read_byte_data(client, command);
592 if (val < 0)
593 return val;
594
590 val &= ~mask; 595 val &= ~mask;
591 val |= set; 596 val |= set & mask;
592 597
593 return i2c_smbus_write_byte_data(client, command, val); 598 return i2c_smbus_write_byte_data(client, command, val);
594} 599}
@@ -635,74 +640,24 @@ static int ov772x_release(struct soc_camera_device *icd)
635static int ov772x_start_capture(struct soc_camera_device *icd) 640static int ov772x_start_capture(struct soc_camera_device *icd)
636{ 641{
637 struct ov772x_priv *priv = container_of(icd, struct ov772x_priv, icd); 642 struct ov772x_priv *priv = container_of(icd, struct ov772x_priv, icd);
638 int ret;
639
640 if (!priv->win)
641 priv->win = &ov772x_win_vga;
642 if (!priv->fmt)
643 priv->fmt = &ov772x_cfmts[T_YUYV];
644
645 /*
646 * reset hardware
647 */
648 ov772x_reset(priv->client);
649 643
650 /* 644 if (!priv->win || !priv->fmt) {
651 * set color format 645 dev_err(&icd->dev, "norm or win select error\n");
652 */ 646 return -EPERM;
653 ret = ov772x_write_array(priv->client, priv->fmt->regs);
654 if (ret < 0)
655 goto start_end;
656
657 /*
658 * set size format
659 */
660 ret = ov772x_write_array(priv->client, priv->win->regs);
661 if (ret < 0)
662 goto start_end;
663
664 /*
665 * set COM7 bit ( QVGA or VGA )
666 */
667 ret = ov772x_mask_set(priv->client,
668 COM7, SLCT_MASK, priv->win->com7_bit);
669 if (ret < 0)
670 goto start_end;
671
672 /*
673 * set UV setting
674 */
675 if (priv->fmt->option & OP_UV) {
676 ret = ov772x_mask_set(priv->client,
677 DSP_CTRL3, UV_MASK, UV_ON);
678 if (ret < 0)
679 goto start_end;
680 } 647 }
681 648
682 /* 649 ov772x_mask_set(priv->client, COM2, SOFT_SLEEP_MODE, 0);
683 * set SWAP setting
684 */
685 if (priv->fmt->option & OP_SWAP_RGB) {
686 ret = ov772x_mask_set(priv->client,
687 COM3, SWAP_MASK, SWAP_RGB);
688 if (ret < 0)
689 goto start_end;
690 }
691 650
692 dev_dbg(&icd->dev, 651 dev_dbg(&icd->dev,
693 "format %s, win %s\n", priv->fmt->name, priv->win->name); 652 "format %s, win %s\n", priv->fmt->name, priv->win->name);
694 653
695start_end: 654 return 0;
696 priv->fmt = NULL;
697 priv->win = NULL;
698
699 return ret;
700} 655}
701 656
702static int ov772x_stop_capture(struct soc_camera_device *icd) 657static int ov772x_stop_capture(struct soc_camera_device *icd)
703{ 658{
704 struct ov772x_priv *priv = container_of(icd, struct ov772x_priv, icd); 659 struct ov772x_priv *priv = container_of(icd, struct ov772x_priv, icd);
705 ov772x_reset(priv->client); 660 ov772x_mask_set(priv->client, COM2, SOFT_SLEEP_MODE, SOFT_SLEEP_MODE);
706 return 0; 661 return 0;
707} 662}
708 663
@@ -718,11 +673,54 @@ static unsigned long ov772x_query_bus_param(struct soc_camera_device *icd)
718 struct soc_camera_link *icl = priv->client->dev.platform_data; 673 struct soc_camera_link *icl = priv->client->dev.platform_data;
719 unsigned long flags = SOCAM_PCLK_SAMPLE_RISING | SOCAM_MASTER | 674 unsigned long flags = SOCAM_PCLK_SAMPLE_RISING | SOCAM_MASTER |
720 SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_HIGH | 675 SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_HIGH |
721 priv->info->buswidth; 676 SOCAM_DATA_ACTIVE_HIGH | priv->info->buswidth;
722 677
723 return soc_camera_apply_sensor_flags(icl, flags); 678 return soc_camera_apply_sensor_flags(icl, flags);
724} 679}
725 680
681static int ov772x_get_control(struct soc_camera_device *icd,
682 struct v4l2_control *ctrl)
683{
684 struct ov772x_priv *priv = container_of(icd, struct ov772x_priv, icd);
685
686 switch (ctrl->id) {
687 case V4L2_CID_VFLIP:
688 ctrl->value = priv->flag_vflip;
689 break;
690 case V4L2_CID_HFLIP:
691 ctrl->value = priv->flag_hflip;
692 break;
693 }
694 return 0;
695}
696
697static int ov772x_set_control(struct soc_camera_device *icd,
698 struct v4l2_control *ctrl)
699{
700 struct ov772x_priv *priv = container_of(icd, struct ov772x_priv, icd);
701 int ret = 0;
702 u8 val;
703
704 switch (ctrl->id) {
705 case V4L2_CID_VFLIP:
706 val = ctrl->value ? VFLIP_IMG : 0x00;
707 priv->flag_vflip = ctrl->value;
708 if (priv->info->flags & OV772X_FLAG_VFLIP)
709 val ^= VFLIP_IMG;
710 ret = ov772x_mask_set(priv->client, COM3, VFLIP_IMG, val);
711 break;
712 case V4L2_CID_HFLIP:
713 val = ctrl->value ? HFLIP_IMG : 0x00;
714 priv->flag_hflip = ctrl->value;
715 if (priv->info->flags & OV772X_FLAG_HFLIP)
716 val ^= HFLIP_IMG;
717 ret = ov772x_mask_set(priv->client, COM3, HFLIP_IMG, val);
718 break;
719 }
720
721 return ret;
722}
723
726static int ov772x_get_chip_id(struct soc_camera_device *icd, 724static int ov772x_get_chip_id(struct soc_camera_device *icd,
727 struct v4l2_dbg_chip_ident *id) 725 struct v4l2_dbg_chip_ident *id)
728{ 726{
@@ -787,13 +785,11 @@ ov772x_select_win(u32 width, u32 height)
787 return win; 785 return win;
788} 786}
789 787
790 788static int ov772x_set_params(struct ov772x_priv *priv, u32 width, u32 height,
791static int ov772x_set_fmt(struct soc_camera_device *icd, 789 u32 pixfmt)
792 __u32 pixfmt,
793 struct v4l2_rect *rect)
794{ 790{
795 struct ov772x_priv *priv = container_of(icd, struct ov772x_priv, icd);
796 int ret = -EINVAL; 791 int ret = -EINVAL;
792 u8 val;
797 int i; 793 int i;
798 794
799 /* 795 /*
@@ -803,19 +799,101 @@ static int ov772x_set_fmt(struct soc_camera_device *icd,
803 for (i = 0; i < ARRAY_SIZE(ov772x_cfmts); i++) { 799 for (i = 0; i < ARRAY_SIZE(ov772x_cfmts); i++) {
804 if (pixfmt == ov772x_cfmts[i].fourcc) { 800 if (pixfmt == ov772x_cfmts[i].fourcc) {
805 priv->fmt = ov772x_cfmts + i; 801 priv->fmt = ov772x_cfmts + i;
806 ret = 0;
807 break; 802 break;
808 } 803 }
809 } 804 }
805 if (!priv->fmt)
806 goto ov772x_set_fmt_error;
810 807
811 /* 808 /*
812 * select win 809 * select win
813 */ 810 */
814 priv->win = ov772x_select_win(rect->width, rect->height); 811 priv->win = ov772x_select_win(width, height);
812
813 /*
814 * reset hardware
815 */
816 ov772x_reset(priv->client);
817
818 /*
819 * set size format
820 */
821 ret = ov772x_write_array(priv->client, priv->win->regs);
822 if (ret < 0)
823 goto ov772x_set_fmt_error;
824
825 /*
826 * set DSP_CTRL3
827 */
828 val = priv->fmt->dsp3;
829 if (val) {
830 ret = ov772x_mask_set(priv->client,
831 DSP_CTRL3, UV_MASK, val);
832 if (ret < 0)
833 goto ov772x_set_fmt_error;
834 }
835
836 /*
837 * set COM3
838 */
839 val = priv->fmt->com3;
840 if (priv->info->flags & OV772X_FLAG_VFLIP)
841 val |= VFLIP_IMG;
842 if (priv->info->flags & OV772X_FLAG_HFLIP)
843 val |= HFLIP_IMG;
844 if (priv->flag_vflip)
845 val ^= VFLIP_IMG;
846 if (priv->flag_hflip)
847 val ^= HFLIP_IMG;
848
849 ret = ov772x_mask_set(priv->client,
850 COM3, SWAP_MASK | IMG_MASK, val);
851 if (ret < 0)
852 goto ov772x_set_fmt_error;
853
854 /*
855 * set COM7
856 */
857 val = priv->win->com7_bit | priv->fmt->com7;
858 ret = ov772x_mask_set(priv->client,
859 COM7, (SLCT_MASK | FMT_MASK | OFMT_MASK),
860 val);
861 if (ret < 0)
862 goto ov772x_set_fmt_error;
863
864 return ret;
865
866ov772x_set_fmt_error:
867
868 ov772x_reset(priv->client);
869 priv->win = NULL;
870 priv->fmt = NULL;
815 871
816 return ret; 872 return ret;
817} 873}
818 874
875static int ov772x_set_crop(struct soc_camera_device *icd,
876 struct v4l2_rect *rect)
877{
878 struct ov772x_priv *priv = container_of(icd, struct ov772x_priv, icd);
879
880 if (!priv->fmt)
881 return -EINVAL;
882
883 return ov772x_set_params(priv, rect->width, rect->height,
884 priv->fmt->fourcc);
885}
886
887static int ov772x_set_fmt(struct soc_camera_device *icd,
888 struct v4l2_format *f)
889{
890 struct ov772x_priv *priv = container_of(icd, struct ov772x_priv, icd);
891 struct v4l2_pix_format *pix = &f->fmt.pix;
892
893 return ov772x_set_params(priv, pix->width, pix->height,
894 pix->pixelformat);
895}
896
819static int ov772x_try_fmt(struct soc_camera_device *icd, 897static int ov772x_try_fmt(struct soc_camera_device *icd,
820 struct v4l2_format *f) 898 struct v4l2_format *f)
821{ 899{
@@ -889,7 +967,6 @@ static int ov772x_video_probe(struct soc_camera_device *icd)
889 i2c_smbus_read_byte_data(priv->client, MIDH), 967 i2c_smbus_read_byte_data(priv->client, MIDH),
890 i2c_smbus_read_byte_data(priv->client, MIDL)); 968 i2c_smbus_read_byte_data(priv->client, MIDL));
891 969
892
893 return soc_camera_video_start(icd); 970 return soc_camera_video_start(icd);
894} 971}
895 972
@@ -906,10 +983,15 @@ static struct soc_camera_ops ov772x_ops = {
906 .release = ov772x_release, 983 .release = ov772x_release,
907 .start_capture = ov772x_start_capture, 984 .start_capture = ov772x_start_capture,
908 .stop_capture = ov772x_stop_capture, 985 .stop_capture = ov772x_stop_capture,
986 .set_crop = ov772x_set_crop,
909 .set_fmt = ov772x_set_fmt, 987 .set_fmt = ov772x_set_fmt,
910 .try_fmt = ov772x_try_fmt, 988 .try_fmt = ov772x_try_fmt,
911 .set_bus_param = ov772x_set_bus_param, 989 .set_bus_param = ov772x_set_bus_param,
912 .query_bus_param = ov772x_query_bus_param, 990 .query_bus_param = ov772x_query_bus_param,
991 .controls = ov772x_controls,
992 .num_controls = ARRAY_SIZE(ov772x_controls),
993 .get_control = ov772x_get_control,
994 .set_control = ov772x_set_control,
913 .get_chip_id = ov772x_get_chip_id, 995 .get_chip_id = ov772x_get_chip_id,
914#ifdef CONFIG_VIDEO_ADV_DEBUG 996#ifdef CONFIG_VIDEO_ADV_DEBUG
915 .get_register = ov772x_get_register, 997 .get_register = ov772x_get_register,
diff --git a/drivers/media/video/ovcamchip/ovcamchip_core.c b/drivers/media/video/ovcamchip/ovcamchip_core.c
index c841f4e4fbe4..d573d8428998 100644
--- a/drivers/media/video/ovcamchip/ovcamchip_core.c
+++ b/drivers/media/video/ovcamchip/ovcamchip_core.c
@@ -15,6 +15,9 @@
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/slab.h> 16#include <linux/slab.h>
17#include <linux/delay.h> 17#include <linux/delay.h>
18#include <linux/i2c.h>
19#include <media/v4l2-device.h>
20#include <media/v4l2-i2c-drv.h>
18#include "ovcamchip_priv.h" 21#include "ovcamchip_priv.h"
19 22
20#define DRIVER_VERSION "v2.27 for Linux 2.6" 23#define DRIVER_VERSION "v2.27 for Linux 2.6"
@@ -44,6 +47,7 @@ MODULE_AUTHOR(DRIVER_AUTHOR);
44MODULE_DESCRIPTION(DRIVER_DESC); 47MODULE_DESCRIPTION(DRIVER_DESC);
45MODULE_LICENSE("GPL"); 48MODULE_LICENSE("GPL");
46 49
50
47/* Registers common to all chips, that are needed for detection */ 51/* Registers common to all chips, that are needed for detection */
48#define GENERIC_REG_ID_HIGH 0x1C /* manufacturer ID MSB */ 52#define GENERIC_REG_ID_HIGH 0x1C /* manufacturer ID MSB */
49#define GENERIC_REG_ID_LOW 0x1D /* manufacturer ID LSB */ 53#define GENERIC_REG_ID_LOW 0x1D /* manufacturer ID LSB */
@@ -61,10 +65,6 @@ static char *chip_names[NUM_CC_TYPES] = {
61 [CC_OV6630AF] = "OV6630AF", 65 [CC_OV6630AF] = "OV6630AF",
62}; 66};
63 67
64/* Forward declarations */
65static struct i2c_driver driver;
66static struct i2c_client client_template;
67
68/* ----------------------------------------------------------------------- */ 68/* ----------------------------------------------------------------------- */
69 69
70int ov_write_regvals(struct i2c_client *c, struct ovcamchip_regvals *rvals) 70int ov_write_regvals(struct i2c_client *c, struct ovcamchip_regvals *rvals)
@@ -253,112 +253,36 @@ static int ovcamchip_detect(struct i2c_client *c)
253 253
254 /* Test for 7xx0 */ 254 /* Test for 7xx0 */
255 PDEBUG(3, "Testing for 0V7xx0"); 255 PDEBUG(3, "Testing for 0V7xx0");
256 c->addr = OV7xx0_SID; 256 if (init_camchip(c) < 0)
257 if (init_camchip(c) < 0) { 257 return -ENODEV;
258 /* Test for 6xx0 */ 258 /* 7-bit addresses with bit 0 set are for the OV7xx0 */
259 PDEBUG(3, "Testing for 0V6xx0"); 259 if (c->addr & 1) {
260 c->addr = OV6xx0_SID;
261 if (init_camchip(c) < 0) {
262 return -ENODEV;
263 } else {
264 if (ov6xx0_detect(c) < 0) {
265 PERROR("Failed to init OV6xx0");
266 return -EIO;
267 }
268 }
269 } else {
270 if (ov7xx0_detect(c) < 0) { 260 if (ov7xx0_detect(c) < 0) {
271 PERROR("Failed to init OV7xx0"); 261 PERROR("Failed to init OV7xx0");
272 return -EIO; 262 return -EIO;
273 } 263 }
264 return 0;
265 }
266 /* Test for 6xx0 */
267 PDEBUG(3, "Testing for 0V6xx0");
268 if (ov6xx0_detect(c) < 0) {
269 PERROR("Failed to init OV6xx0");
270 return -EIO;
274 } 271 }
275
276 return 0; 272 return 0;
277} 273}
278 274
279/* ----------------------------------------------------------------------- */ 275/* ----------------------------------------------------------------------- */
280 276
281static int ovcamchip_attach(struct i2c_adapter *adap) 277static long ovcamchip_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
282{ 278{
283 int rc = 0; 279 struct ovcamchip *ov = to_ovcamchip(sd);
284 struct ovcamchip *ov; 280 struct i2c_client *c = v4l2_get_subdevdata(sd);
285 struct i2c_client *c;
286
287 /* I2C is not a PnP bus, so we can never be certain that we're talking
288 * to the right chip. To prevent damage to EEPROMS and such, only
289 * attach to adapters that are known to contain OV camera chips. */
290
291 switch (adap->id) {
292 case I2C_HW_SMBUS_OV511:
293 case I2C_HW_SMBUS_OV518:
294 case I2C_HW_SMBUS_W9968CF:
295 PDEBUG(1, "Adapter ID 0x%06x accepted", adap->id);
296 break;
297 default:
298 PDEBUG(1, "Adapter ID 0x%06x rejected", adap->id);
299 return -ENODEV;
300 }
301
302 c = kmalloc(sizeof *c, GFP_KERNEL);
303 if (!c) {
304 rc = -ENOMEM;
305 goto no_client;
306 }
307 memcpy(c, &client_template, sizeof *c);
308 c->adapter = adap;
309 strcpy(c->name, "OV????");
310
311 ov = kzalloc(sizeof *ov, GFP_KERNEL);
312 if (!ov) {
313 rc = -ENOMEM;
314 goto no_ov;
315 }
316 i2c_set_clientdata(c, ov);
317
318 rc = ovcamchip_detect(c);
319 if (rc < 0)
320 goto error;
321
322 strcpy(c->name, chip_names[ov->subtype]);
323
324 PDEBUG(1, "Camera chip detection complete");
325
326 i2c_attach_client(c);
327
328 return rc;
329error:
330 kfree(ov);
331no_ov:
332 kfree(c);
333no_client:
334 PDEBUG(1, "returning %d", rc);
335 return rc;
336}
337
338static int ovcamchip_detach(struct i2c_client *c)
339{
340 struct ovcamchip *ov = i2c_get_clientdata(c);
341 int rc;
342
343 rc = ov->sops->free(c);
344 if (rc < 0)
345 return rc;
346
347 i2c_detach_client(c);
348
349 kfree(ov);
350 kfree(c);
351 return 0;
352}
353
354static int ovcamchip_command(struct i2c_client *c, unsigned int cmd, void *arg)
355{
356 struct ovcamchip *ov = i2c_get_clientdata(c);
357 281
358 if (!ov->initialized && 282 if (!ov->initialized &&
359 cmd != OVCAMCHIP_CMD_Q_SUBTYPE && 283 cmd != OVCAMCHIP_CMD_Q_SUBTYPE &&
360 cmd != OVCAMCHIP_CMD_INITIALIZE) { 284 cmd != OVCAMCHIP_CMD_INITIALIZE) {
361 dev_err(&c->dev, "ERROR: Camera chip not initialized yet!\n"); 285 v4l2_err(sd, "Camera chip not initialized yet!\n");
362 return -EPERM; 286 return -EPERM;
363 } 287 }
364 288
@@ -379,10 +303,10 @@ static int ovcamchip_command(struct i2c_client *c, unsigned int cmd, void *arg)
379 303
380 if (ov->mono) { 304 if (ov->mono) {
381 if (ov->subtype != CC_OV7620) 305 if (ov->subtype != CC_OV7620)
382 dev_warn(&c->dev, "Warning: Monochrome not " 306 v4l2_warn(sd, "Monochrome not "
383 "implemented for this chip\n"); 307 "implemented for this chip\n");
384 else 308 else
385 dev_info(&c->dev, "Initializing chip as " 309 v4l2_info(sd, "Initializing chip as "
386 "monochrome\n"); 310 "monochrome\n");
387 } 311 }
388 312
@@ -400,35 +324,72 @@ static int ovcamchip_command(struct i2c_client *c, unsigned int cmd, void *arg)
400 324
401/* ----------------------------------------------------------------------- */ 325/* ----------------------------------------------------------------------- */
402 326
403static struct i2c_driver driver = { 327static const struct v4l2_subdev_core_ops ovcamchip_core_ops = {
404 .driver = { 328 .ioctl = ovcamchip_ioctl,
405 .name = "ovcamchip",
406 },
407 .id = I2C_DRIVERID_OVCAMCHIP,
408 .attach_adapter = ovcamchip_attach,
409 .detach_client = ovcamchip_detach,
410 .command = ovcamchip_command,
411}; 329};
412 330
413static struct i2c_client client_template = { 331static const struct v4l2_subdev_ops ovcamchip_ops = {
414 .name = "(unset)", 332 .core = &ovcamchip_core_ops,
415 .driver = &driver,
416}; 333};
417 334
418static int __init ovcamchip_init(void) 335static int ovcamchip_probe(struct i2c_client *client,
336 const struct i2c_device_id *id)
419{ 337{
420#ifdef DEBUG 338 struct ovcamchip *ov;
421 ovcamchip_debug = debug; 339 struct v4l2_subdev *sd;
422#endif 340 int rc = 0;
341
342 ov = kzalloc(sizeof *ov, GFP_KERNEL);
343 if (!ov) {
344 rc = -ENOMEM;
345 goto no_ov;
346 }
347 sd = &ov->sd;
348 v4l2_i2c_subdev_init(sd, client, &ovcamchip_ops);
349
350 rc = ovcamchip_detect(client);
351 if (rc < 0)
352 goto error;
353
354 v4l_info(client, "%s found @ 0x%02x (%s)\n",
355 chip_names[ov->subtype], client->addr << 1, client->adapter->name);
356
357 PDEBUG(1, "Camera chip detection complete");
423 358
424 PINFO(DRIVER_VERSION " : " DRIVER_DESC); 359 return rc;
425 return i2c_add_driver(&driver); 360error:
361 kfree(ov);
362no_ov:
363 PDEBUG(1, "returning %d", rc);
364 return rc;
426} 365}
427 366
428static void __exit ovcamchip_exit(void) 367static int ovcamchip_remove(struct i2c_client *client)
429{ 368{
430 i2c_del_driver(&driver); 369 struct v4l2_subdev *sd = i2c_get_clientdata(client);
370 struct ovcamchip *ov = to_ovcamchip(sd);
371 int rc;
372
373 v4l2_device_unregister_subdev(sd);
374 rc = ov->sops->free(client);
375 if (rc < 0)
376 return rc;
377
378 kfree(ov);
379 return 0;
431} 380}
432 381
433module_init(ovcamchip_init); 382/* ----------------------------------------------------------------------- */
434module_exit(ovcamchip_exit); 383
384static const struct i2c_device_id ovcamchip_id[] = {
385 { "ovcamchip", 0 },
386 { }
387};
388MODULE_DEVICE_TABLE(i2c, ovcamchip_id);
389
390static struct v4l2_i2c_driver_data v4l2_i2c_data = {
391 .name = "ovcamchip",
392 .probe = ovcamchip_probe,
393 .remove = ovcamchip_remove,
394 .id_table = ovcamchip_id,
395};
diff --git a/drivers/media/video/ovcamchip/ovcamchip_priv.h b/drivers/media/video/ovcamchip/ovcamchip_priv.h
index a05650faedda..4f07b78c88bc 100644
--- a/drivers/media/video/ovcamchip/ovcamchip_priv.h
+++ b/drivers/media/video/ovcamchip/ovcamchip_priv.h
@@ -16,6 +16,7 @@
16#define __LINUX_OVCAMCHIP_PRIV_H 16#define __LINUX_OVCAMCHIP_PRIV_H
17 17
18#include <linux/i2c.h> 18#include <linux/i2c.h>
19#include <media/v4l2-subdev.h>
19#include <media/ovcamchip.h> 20#include <media/ovcamchip.h>
20 21
21#ifdef DEBUG 22#ifdef DEBUG
@@ -46,6 +47,7 @@ struct ovcamchip_ops {
46}; 47};
47 48
48struct ovcamchip { 49struct ovcamchip {
50 struct v4l2_subdev sd;
49 struct ovcamchip_ops *sops; 51 struct ovcamchip_ops *sops;
50 void *spriv; /* Private data for OV7x10.c etc... */ 52 void *spriv; /* Private data for OV7x10.c etc... */
51 int subtype; /* = SEN_OV7610 etc... */ 53 int subtype; /* = SEN_OV7610 etc... */
@@ -53,6 +55,11 @@ struct ovcamchip {
53 int initialized; /* OVCAMCHIP_CMD_INITIALIZE was successful */ 55 int initialized; /* OVCAMCHIP_CMD_INITIALIZE was successful */
54}; 56};
55 57
58static inline struct ovcamchip *to_ovcamchip(struct v4l2_subdev *sd)
59{
60 return container_of(sd, struct ovcamchip, sd);
61}
62
56extern struct ovcamchip_ops ov6x20_ops; 63extern struct ovcamchip_ops ov6x20_ops;
57extern struct ovcamchip_ops ov6x30_ops; 64extern struct ovcamchip_ops ov6x30_ops;
58extern struct ovcamchip_ops ov7x10_ops; 65extern struct ovcamchip_ops ov7x10_ops;
diff --git a/drivers/media/video/pvrusb2/Kconfig b/drivers/media/video/pvrusb2/Kconfig
index 854c2a885358..f9b6001e1dd7 100644
--- a/drivers/media/video/pvrusb2/Kconfig
+++ b/drivers/media/video/pvrusb2/Kconfig
@@ -40,10 +40,10 @@ config VIDEO_PVRUSB2_DVB
40 select DVB_LGDT330X if !DVB_FE_CUSTOMISE 40 select DVB_LGDT330X if !DVB_FE_CUSTOMISE
41 select DVB_S5H1409 if !DVB_FE_CUSTOMISE 41 select DVB_S5H1409 if !DVB_FE_CUSTOMISE
42 select DVB_S5H1411 if !DVB_FE_CUSTOMISE 42 select DVB_S5H1411 if !DVB_FE_CUSTOMISE
43 select DVB_TDA10048 if !DVB_FE_CUSTOMIZE 43 select DVB_TDA10048 if !DVB_FE_CUSTOMISE
44 select MEDIA_TUNER_TDA18271 if !DVB_FE_CUSTOMIZE 44 select MEDIA_TUNER_TDA18271 if !MEDIA_TUNER_CUSTOMISE
45 select MEDIA_TUNER_SIMPLE if !MEDIA_TUNER_CUSTOMIZE 45 select MEDIA_TUNER_SIMPLE if !MEDIA_TUNER_CUSTOMISE
46 select MEDIA_TUNER_TDA8290 if !DVB_FE_CUSTOMIZE 46 select MEDIA_TUNER_TDA8290 if !MEDIA_TUNER_CUSTOMISE
47 ---help--- 47 ---help---
48 48
49 This option enables a DVB interface for the pvrusb2 driver. 49 This option enables a DVB interface for the pvrusb2 driver.
diff --git a/drivers/media/video/pvrusb2/Makefile b/drivers/media/video/pvrusb2/Makefile
index 4fda2de69ab7..de2fc14f043b 100644
--- a/drivers/media/video/pvrusb2/Makefile
+++ b/drivers/media/video/pvrusb2/Makefile
@@ -2,14 +2,15 @@ obj-pvrusb2-sysfs-$(CONFIG_VIDEO_PVRUSB2_SYSFS) := pvrusb2-sysfs.o
2obj-pvrusb2-debugifc-$(CONFIG_VIDEO_PVRUSB2_DEBUGIFC) := pvrusb2-debugifc.o 2obj-pvrusb2-debugifc-$(CONFIG_VIDEO_PVRUSB2_DEBUGIFC) := pvrusb2-debugifc.o
3obj-pvrusb2-dvb-$(CONFIG_VIDEO_PVRUSB2_DVB) := pvrusb2-dvb.o 3obj-pvrusb2-dvb-$(CONFIG_VIDEO_PVRUSB2_DVB) := pvrusb2-dvb.o
4 4
5pvrusb2-objs := pvrusb2-i2c-core.o pvrusb2-i2c-cmd-v4l2.o \ 5pvrusb2-objs := pvrusb2-i2c-core.o \
6 pvrusb2-audio.o pvrusb2-i2c-chips-v4l2.o \ 6 pvrusb2-audio.o \
7 pvrusb2-encoder.o pvrusb2-video-v4l.o \ 7 pvrusb2-encoder.o pvrusb2-video-v4l.o \
8 pvrusb2-eeprom.o pvrusb2-tuner.o \ 8 pvrusb2-eeprom.o \
9 pvrusb2-main.o pvrusb2-hdw.o pvrusb2-v4l2.o \ 9 pvrusb2-main.o pvrusb2-hdw.o pvrusb2-v4l2.o \
10 pvrusb2-ctrl.o pvrusb2-std.o pvrusb2-devattr.o \ 10 pvrusb2-ctrl.o pvrusb2-std.o pvrusb2-devattr.o \
11 pvrusb2-context.o pvrusb2-io.o pvrusb2-ioread.o \ 11 pvrusb2-context.o pvrusb2-io.o pvrusb2-ioread.o \
12 pvrusb2-cx2584x-v4l.o pvrusb2-wm8775.o \ 12 pvrusb2-cx2584x-v4l.o pvrusb2-wm8775.o \
13 pvrusb2-cs53l32a.o \
13 $(obj-pvrusb2-dvb-y) \ 14 $(obj-pvrusb2-dvb-y) \
14 $(obj-pvrusb2-sysfs-y) $(obj-pvrusb2-debugifc-y) 15 $(obj-pvrusb2-sysfs-y) $(obj-pvrusb2-debugifc-y)
15 16
diff --git a/drivers/media/video/pvrusb2/pvrusb2-audio.c b/drivers/media/video/pvrusb2/pvrusb2-audio.c
index cdedaa55f152..ccf2a3c7ad06 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-audio.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-audio.c
@@ -26,14 +26,6 @@
26#include <media/msp3400.h> 26#include <media/msp3400.h>
27#include <media/v4l2-common.h> 27#include <media/v4l2-common.h>
28 28
29struct pvr2_msp3400_handler {
30 struct pvr2_hdw *hdw;
31 struct pvr2_i2c_client *client;
32 struct pvr2_i2c_handler i2c_handler;
33 unsigned long stale_mask;
34};
35
36
37 29
38struct routing_scheme { 30struct routing_scheme {
39 const int *def; 31 const int *def;
@@ -63,123 +55,33 @@ static const struct routing_scheme routing_schemes[] = {
63 }, 55 },
64}; 56};
65 57
66/* This function selects the correct audio input source */ 58void pvr2_msp3400_subdev_update(struct pvr2_hdw *hdw, struct v4l2_subdev *sd)
67static void set_stereo(struct pvr2_msp3400_handler *ctxt)
68{
69 struct pvr2_hdw *hdw = ctxt->hdw;
70 struct v4l2_routing route;
71 const struct routing_scheme *sp;
72 unsigned int sid = hdw->hdw_desc->signal_routing_scheme;
73
74 pvr2_trace(PVR2_TRACE_CHIPS,"i2c msp3400 v4l2 set_stereo");
75
76 if ((sid < ARRAY_SIZE(routing_schemes)) &&
77 ((sp = routing_schemes + sid) != NULL) &&
78 (hdw->input_val >= 0) &&
79 (hdw->input_val < sp->cnt)) {
80 route.input = sp->def[hdw->input_val];
81 } else {
82 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
83 "*** WARNING *** i2c msp3400 v4l2 set_stereo:"
84 " Invalid routing scheme (%u) and/or input (%d)",
85 sid,hdw->input_val);
86 return;
87 }
88 route.output = MSP_OUTPUT(MSP_SC_IN_DSP_SCART1);
89 pvr2_i2c_client_cmd(ctxt->client,VIDIOC_INT_S_AUDIO_ROUTING,&route);
90}
91
92
93static int check_stereo(struct pvr2_msp3400_handler *ctxt)
94{ 59{
95 struct pvr2_hdw *hdw = ctxt->hdw; 60 if (hdw->input_dirty || hdw->force_dirty) {
96 return hdw->input_dirty; 61 struct v4l2_routing route;
97} 62 const struct routing_scheme *sp;
98 63 unsigned int sid = hdw->hdw_desc->signal_routing_scheme;
99 64
100struct pvr2_msp3400_ops { 65 pvr2_trace(PVR2_TRACE_CHIPS, "subdev msp3400 v4l2 set_stereo");
101 void (*update)(struct pvr2_msp3400_handler *); 66
102 int (*check)(struct pvr2_msp3400_handler *); 67 if ((sid < ARRAY_SIZE(routing_schemes)) &&
103}; 68 ((sp = routing_schemes + sid) != NULL) &&
104 69 (hdw->input_val >= 0) &&
105 70 (hdw->input_val < sp->cnt)) {
106static const struct pvr2_msp3400_ops msp3400_ops[] = { 71 route.input = sp->def[hdw->input_val];
107 { .update = set_stereo, .check = check_stereo}, 72 } else {
108}; 73 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
109 74 "*** WARNING *** subdev msp3400 set_input:"
110 75 " Invalid routing scheme (%u)"
111static int msp3400_check(struct pvr2_msp3400_handler *ctxt) 76 " and/or input (%d)",
112{ 77 sid, hdw->input_val);
113 unsigned long msk; 78 return;
114 unsigned int idx;
115
116 for (idx = 0; idx < ARRAY_SIZE(msp3400_ops); idx++) {
117 msk = 1 << idx;
118 if (ctxt->stale_mask & msk) continue;
119 if (msp3400_ops[idx].check(ctxt)) {
120 ctxt->stale_mask |= msk;
121 } 79 }
80 route.output = MSP_OUTPUT(MSP_SC_IN_DSP_SCART1);
81 sd->ops->audio->s_routing(sd, &route);
122 } 82 }
123 return ctxt->stale_mask != 0;
124} 83}
125 84
126
127static void msp3400_update(struct pvr2_msp3400_handler *ctxt)
128{
129 unsigned long msk;
130 unsigned int idx;
131
132 for (idx = 0; idx < ARRAY_SIZE(msp3400_ops); idx++) {
133 msk = 1 << idx;
134 if (!(ctxt->stale_mask & msk)) continue;
135 ctxt->stale_mask &= ~msk;
136 msp3400_ops[idx].update(ctxt);
137 }
138}
139
140
141static void pvr2_msp3400_detach(struct pvr2_msp3400_handler *ctxt)
142{
143 ctxt->client->handler = NULL;
144 kfree(ctxt);
145}
146
147
148static unsigned int pvr2_msp3400_describe(struct pvr2_msp3400_handler *ctxt,
149 char *buf,unsigned int cnt)
150{
151 return scnprintf(buf,cnt,"handler: pvrusb2-audio v4l2");
152}
153
154
155static const struct pvr2_i2c_handler_functions msp3400_funcs = {
156 .detach = (void (*)(void *))pvr2_msp3400_detach,
157 .check = (int (*)(void *))msp3400_check,
158 .update = (void (*)(void *))msp3400_update,
159 .describe = (unsigned int (*)(void *,char *,unsigned int))pvr2_msp3400_describe,
160};
161
162
163int pvr2_i2c_msp3400_setup(struct pvr2_hdw *hdw,struct pvr2_i2c_client *cp)
164{
165 struct pvr2_msp3400_handler *ctxt;
166 if (cp->handler) return 0;
167
168 ctxt = kzalloc(sizeof(*ctxt),GFP_KERNEL);
169 if (!ctxt) return 0;
170
171 ctxt->i2c_handler.func_data = ctxt;
172 ctxt->i2c_handler.func_table = &msp3400_funcs;
173 ctxt->client = cp;
174 ctxt->hdw = hdw;
175 ctxt->stale_mask = (1 << ARRAY_SIZE(msp3400_ops)) - 1;
176 cp->handler = &ctxt->i2c_handler;
177 pvr2_trace(PVR2_TRACE_CHIPS,"i2c 0x%x msp3400 V4L2 handler set up",
178 cp->client->addr);
179 return !0;
180}
181
182
183/* 85/*
184 Stuff for Emacs to see, in order to encourage consistent editing style: 86 Stuff for Emacs to see, in order to encourage consistent editing style:
185 *** Local Variables: *** 87 *** Local Variables: ***
diff --git a/drivers/media/video/pvrusb2/pvrusb2-audio.h b/drivers/media/video/pvrusb2/pvrusb2-audio.h
index ac54eed3721b..e3e63d750891 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-audio.h
+++ b/drivers/media/video/pvrusb2/pvrusb2-audio.h
@@ -22,10 +22,8 @@
22#ifndef __PVRUSB2_AUDIO_H 22#ifndef __PVRUSB2_AUDIO_H
23#define __PVRUSB2_AUDIO_H 23#define __PVRUSB2_AUDIO_H
24 24
25#include "pvrusb2-i2c-core.h" 25#include "pvrusb2-hdw-internal.h"
26 26void pvr2_msp3400_subdev_update(struct pvr2_hdw *, struct v4l2_subdev *);
27int pvr2_i2c_msp3400_setup(struct pvr2_hdw *,struct pvr2_i2c_client *);
28
29#endif /* __PVRUSB2_AUDIO_H */ 27#endif /* __PVRUSB2_AUDIO_H */
30 28
31/* 29/*
diff --git a/drivers/media/video/pvrusb2/pvrusb2-cs53l32a.c b/drivers/media/video/pvrusb2/pvrusb2-cs53l32a.c
new file mode 100644
index 000000000000..b5c3428ebb9f
--- /dev/null
+++ b/drivers/media/video/pvrusb2/pvrusb2-cs53l32a.c
@@ -0,0 +1,95 @@
1/*
2 *
3 *
4 * Copyright (C) 2005 Mike Isely <isely@pobox.com>
5 * Copyright (C) 2004 Aurelien Alleaume <slts@free.fr>
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
24 This source file is specifically designed to interface with the
25 v4l-dvb cs53l32a module.
26
27*/
28
29#include "pvrusb2-cs53l32a.h"
30
31
32#include "pvrusb2-hdw-internal.h"
33#include "pvrusb2-debug.h"
34#include <linux/videodev2.h>
35#include <media/v4l2-common.h>
36#include <linux/errno.h>
37#include <linux/slab.h>
38
39struct routing_scheme {
40 const int *def;
41 unsigned int cnt;
42};
43
44
45static const int routing_scheme1[] = {
46 [PVR2_CVAL_INPUT_TV] = 2, /* 1 or 2 seems to work here */
47 [PVR2_CVAL_INPUT_RADIO] = 2,
48 [PVR2_CVAL_INPUT_COMPOSITE] = 0,
49 [PVR2_CVAL_INPUT_SVIDEO] = 0,
50};
51
52static const struct routing_scheme routing_schemes[] = {
53 [PVR2_ROUTING_SCHEME_ONAIR] = {
54 .def = routing_scheme1,
55 .cnt = ARRAY_SIZE(routing_scheme1),
56 },
57};
58
59
60void pvr2_cs53l32a_subdev_update(struct pvr2_hdw *hdw, struct v4l2_subdev *sd)
61{
62 if (hdw->input_dirty || hdw->force_dirty) {
63 struct v4l2_routing route;
64 const struct routing_scheme *sp;
65 unsigned int sid = hdw->hdw_desc->signal_routing_scheme;
66 pvr2_trace(PVR2_TRACE_CHIPS, "subdev v4l2 set_input(%d)",
67 hdw->input_val);
68 if ((sid < ARRAY_SIZE(routing_schemes)) &&
69 ((sp = routing_schemes + sid) != NULL) &&
70 (hdw->input_val >= 0) &&
71 (hdw->input_val < sp->cnt)) {
72 route.input = sp->def[hdw->input_val];
73 } else {
74 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
75 "*** WARNING *** subdev v4l2 set_input:"
76 " Invalid routing scheme (%u)"
77 " and/or input (%d)",
78 sid, hdw->input_val);
79 return;
80 }
81 route.output = 0;
82 sd->ops->audio->s_routing(sd, &route);
83 }
84}
85
86
87/*
88 Stuff for Emacs to see, in order to encourage consistent editing style:
89 *** Local Variables: ***
90 *** mode: c ***
91 *** fill-column: 70 ***
92 *** tab-width: 8 ***
93 *** c-basic-offset: 8 ***
94 *** End: ***
95 */
diff --git a/drivers/media/video/pvrusb2/pvrusb2-tuner.h b/drivers/media/video/pvrusb2/pvrusb2-cs53l32a.h
index ef4afaf37b0a..53ba548b72a7 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-tuner.h
+++ b/drivers/media/video/pvrusb2/pvrusb2-cs53l32a.h
@@ -2,6 +2,7 @@
2 * 2 *
3 * 3 *
4 * Copyright (C) 2005 Mike Isely <isely@pobox.com> 4 * Copyright (C) 2005 Mike Isely <isely@pobox.com>
5 * Copyright (C) 2004 Aurelien Alleaume <slts@free.fr>
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 8 * it under the terms of the GNU General Public License as published by
@@ -17,14 +18,24 @@
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * 19 *
19 */ 20 */
20#ifndef __PVRUSB2_TUNER_H
21#define __PVRUSB2_TUNER_H
22 21
23#include "pvrusb2-i2c-core.h" 22#ifndef __PVRUSB2_CS53L32A_H
23#define __PVRUSB2_CS53L32A_H
24 24
25int pvr2_i2c_tuner_setup(struct pvr2_hdw *,struct pvr2_i2c_client *); 25/*
26
27 This module connects the pvrusb2 driver to the I2C chip level
28 driver which handles device video processing. This interface is
29 used internally by the driver; higher level code should only
30 interact through the interface provided by pvrusb2-hdw.h.
31
32*/
33
34
35#include "pvrusb2-hdw-internal.h"
36void pvr2_cs53l32a_subdev_update(struct pvr2_hdw *, struct v4l2_subdev *);
26 37
27#endif /* __PVRUSB2_TUNER_H */ 38#endif /* __PVRUSB2_AUDIO_CS53L32A_H */
28 39
29/* 40/*
30 Stuff for Emacs to see, in order to encourage consistent editing style: 41 Stuff for Emacs to see, in order to encourage consistent editing style:
diff --git a/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c b/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c
index 895859ec495a..4e017ff26c36 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c
@@ -28,7 +28,6 @@
28 28
29#include "pvrusb2-cx2584x-v4l.h" 29#include "pvrusb2-cx2584x-v4l.h"
30#include "pvrusb2-video-v4l.h" 30#include "pvrusb2-video-v4l.h"
31#include "pvrusb2-i2c-cmd-v4l2.h"
32 31
33 32
34#include "pvrusb2-hdw-internal.h" 33#include "pvrusb2-hdw-internal.h"
@@ -39,14 +38,6 @@
39#include <linux/errno.h> 38#include <linux/errno.h>
40#include <linux/slab.h> 39#include <linux/slab.h>
41 40
42struct pvr2_v4l_cx2584x {
43 struct pvr2_i2c_handler handler;
44 struct pvr2_decoder_ctrl ctrl;
45 struct pvr2_i2c_client *client;
46 struct pvr2_hdw *hdw;
47 unsigned long stale_mask;
48};
49
50 41
51struct routing_scheme_item { 42struct routing_scheme_item {
52 int vid; 43 int vid;
@@ -110,218 +101,44 @@ static const struct routing_scheme routing_schemes[] = {
110 }, 101 },
111}; 102};
112 103
113static void set_input(struct pvr2_v4l_cx2584x *ctxt) 104void pvr2_cx25840_subdev_update(struct pvr2_hdw *hdw, struct v4l2_subdev *sd)
114{
115 struct pvr2_hdw *hdw = ctxt->hdw;
116 struct v4l2_routing route;
117 enum cx25840_video_input vid_input;
118 enum cx25840_audio_input aud_input;
119 const struct routing_scheme *sp;
120 unsigned int sid = hdw->hdw_desc->signal_routing_scheme;
121
122 memset(&route,0,sizeof(route));
123
124 if ((sid < ARRAY_SIZE(routing_schemes)) &&
125 ((sp = routing_schemes + sid) != NULL) &&
126 (hdw->input_val >= 0) &&
127 (hdw->input_val < sp->cnt)) {
128 vid_input = sp->def[hdw->input_val].vid;
129 aud_input = sp->def[hdw->input_val].aud;
130 } else {
131 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
132 "*** WARNING *** i2c cx2584x set_input:"
133 " Invalid routing scheme (%u) and/or input (%d)",
134 sid,hdw->input_val);
135 return;
136 }
137
138 pvr2_trace(PVR2_TRACE_CHIPS,"i2c cx2584x set_input vid=0x%x aud=0x%x",
139 vid_input,aud_input);
140 route.input = (u32)vid_input;
141 pvr2_i2c_client_cmd(ctxt->client,VIDIOC_INT_S_VIDEO_ROUTING,&route);
142 route.input = (u32)aud_input;
143 pvr2_i2c_client_cmd(ctxt->client,VIDIOC_INT_S_AUDIO_ROUTING,&route);
144}
145
146
147static int check_input(struct pvr2_v4l_cx2584x *ctxt)
148{
149 struct pvr2_hdw *hdw = ctxt->hdw;
150 return hdw->input_dirty != 0;
151}
152
153
154static void set_audio(struct pvr2_v4l_cx2584x *ctxt)
155{
156 u32 val;
157 struct pvr2_hdw *hdw = ctxt->hdw;
158
159 pvr2_trace(PVR2_TRACE_CHIPS,"i2c cx2584x set_audio %d",
160 hdw->srate_val);
161 switch (hdw->srate_val) {
162 default:
163 case V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000:
164 val = 48000;
165 break;
166 case V4L2_MPEG_AUDIO_SAMPLING_FREQ_44100:
167 val = 44100;
168 break;
169 case V4L2_MPEG_AUDIO_SAMPLING_FREQ_32000:
170 val = 32000;
171 break;
172 }
173 pvr2_i2c_client_cmd(ctxt->client,VIDIOC_INT_AUDIO_CLOCK_FREQ,&val);
174}
175
176
177static int check_audio(struct pvr2_v4l_cx2584x *ctxt)
178{
179 struct pvr2_hdw *hdw = ctxt->hdw;
180 return hdw->srate_dirty != 0;
181}
182
183
184struct pvr2_v4l_cx2584x_ops {
185 void (*update)(struct pvr2_v4l_cx2584x *);
186 int (*check)(struct pvr2_v4l_cx2584x *);
187};
188
189
190static const struct pvr2_v4l_cx2584x_ops decoder_ops[] = {
191 { .update = set_input, .check = check_input},
192 { .update = set_audio, .check = check_audio},
193};
194
195
196static void decoder_detach(struct pvr2_v4l_cx2584x *ctxt)
197{ 105{
198 ctxt->client->handler = NULL; 106 pvr2_trace(PVR2_TRACE_CHIPS, "subdev cx2584x update...");
199 pvr2_hdw_set_decoder(ctxt->hdw,NULL); 107 if (hdw->input_dirty || hdw->force_dirty) {
200 kfree(ctxt); 108 struct v4l2_routing route;
201} 109 enum cx25840_video_input vid_input;
202 110 enum cx25840_audio_input aud_input;
203 111 const struct routing_scheme *sp;
204static int decoder_check(struct pvr2_v4l_cx2584x *ctxt) 112 unsigned int sid = hdw->hdw_desc->signal_routing_scheme;
205{ 113
206 unsigned long msk; 114 memset(&route, 0, sizeof(route));
207 unsigned int idx; 115
208 116 if ((sid < ARRAY_SIZE(routing_schemes)) &&
209 for (idx = 0; idx < ARRAY_SIZE(decoder_ops); idx++) { 117 ((sp = routing_schemes + sid) != NULL) &&
210 msk = 1 << idx; 118 (hdw->input_val >= 0) &&
211 if (ctxt->stale_mask & msk) continue; 119 (hdw->input_val < sp->cnt)) {
212 if (decoder_ops[idx].check(ctxt)) { 120 vid_input = sp->def[hdw->input_val].vid;
213 ctxt->stale_mask |= msk; 121 aud_input = sp->def[hdw->input_val].aud;
122 } else {
123 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
124 "*** WARNING *** subdev cx2584x set_input:"
125 " Invalid routing scheme (%u)"
126 " and/or input (%d)",
127 sid, hdw->input_val);
128 return;
214 } 129 }
215 }
216 return ctxt->stale_mask != 0;
217}
218
219 130
220static void decoder_update(struct pvr2_v4l_cx2584x *ctxt) 131 pvr2_trace(PVR2_TRACE_CHIPS,
221{ 132 "subdev cx2584x set_input vid=0x%x aud=0x%x",
222 unsigned long msk; 133 vid_input, aud_input);
223 unsigned int idx; 134 route.input = (u32)vid_input;
224 135 sd->ops->video->s_routing(sd, &route);
225 for (idx = 0; idx < ARRAY_SIZE(decoder_ops); idx++) { 136 route.input = (u32)aud_input;
226 msk = 1 << idx; 137 sd->ops->audio->s_routing(sd, &route);
227 if (!(ctxt->stale_mask & msk)) continue;
228 ctxt->stale_mask &= ~msk;
229 decoder_ops[idx].update(ctxt);
230 } 138 }
231} 139}
232 140
233 141
234static void decoder_enable(struct pvr2_v4l_cx2584x *ctxt,int fl)
235{
236 pvr2_trace(PVR2_TRACE_CHIPS,"i2c cx25840 decoder_enable(%d)",fl);
237 pvr2_v4l2_cmd_stream(ctxt->client,fl);
238}
239
240
241static int decoder_detect(struct pvr2_i2c_client *cp)
242{
243 int ret;
244 /* Attempt to query the decoder - let's see if it will answer */
245 struct v4l2_queryctrl qc;
246
247 memset(&qc,0,sizeof(qc));
248
249 qc.id = V4L2_CID_BRIGHTNESS;
250
251 ret = pvr2_i2c_client_cmd(cp,VIDIOC_QUERYCTRL,&qc);
252 return ret == 0; /* Return true if it answered */
253}
254
255
256static unsigned int decoder_describe(struct pvr2_v4l_cx2584x *ctxt,
257 char *buf,unsigned int cnt)
258{
259 return scnprintf(buf,cnt,"handler: pvrusb2-cx2584x-v4l");
260}
261
262
263static void decoder_reset(struct pvr2_v4l_cx2584x *ctxt)
264{
265 int ret;
266 ret = pvr2_i2c_client_cmd(ctxt->client,VIDIOC_INT_RESET,NULL);
267 pvr2_trace(PVR2_TRACE_CHIPS,"i2c cx25840 decoder_reset (ret=%d)",ret);
268}
269
270
271static const struct pvr2_i2c_handler_functions hfuncs = {
272 .detach = (void (*)(void *))decoder_detach,
273 .check = (int (*)(void *))decoder_check,
274 .update = (void (*)(void *))decoder_update,
275 .describe = (unsigned int (*)(void *,char *,unsigned int))decoder_describe,
276};
277
278
279int pvr2_i2c_cx2584x_v4l_setup(struct pvr2_hdw *hdw,
280 struct pvr2_i2c_client *cp)
281{
282 struct pvr2_v4l_cx2584x *ctxt;
283
284 if (hdw->decoder_ctrl) return 0;
285 if (cp->handler) return 0;
286 if (!decoder_detect(cp)) return 0;
287
288 ctxt = kzalloc(sizeof(*ctxt),GFP_KERNEL);
289 if (!ctxt) return 0;
290
291 ctxt->handler.func_data = ctxt;
292 ctxt->handler.func_table = &hfuncs;
293 ctxt->ctrl.ctxt = ctxt;
294 ctxt->ctrl.detach = (void (*)(void *))decoder_detach;
295 ctxt->ctrl.enable = (void (*)(void *,int))decoder_enable;
296 ctxt->ctrl.force_reset = (void (*)(void*))decoder_reset;
297 ctxt->client = cp;
298 ctxt->hdw = hdw;
299 ctxt->stale_mask = (1 << ARRAY_SIZE(decoder_ops)) - 1;
300 pvr2_hdw_set_decoder(hdw,&ctxt->ctrl);
301 cp->handler = &ctxt->handler;
302 {
303 /*
304 Mike Isely <isely@pobox.com> 19-Nov-2006 - This bit
305 of nuttiness for cx25840 causes that module to
306 correctly set up its video scaling. This is really
307 a problem in the cx25840 module itself, but we work
308 around it here. The problem has not been seen in
309 ivtv because there VBI is supported and set up. We
310 don't do VBI here (at least not yet) and thus we
311 never attempted to even set it up.
312 */
313 struct v4l2_format fmt;
314 memset(&fmt,0,sizeof(fmt));
315 fmt.type = V4L2_BUF_TYPE_SLICED_VBI_CAPTURE;
316 pvr2_i2c_client_cmd(ctxt->client,VIDIOC_S_FMT,&fmt);
317 }
318 pvr2_trace(PVR2_TRACE_CHIPS,"i2c 0x%x cx2584x V4L2 handler set up",
319 cp->client->addr);
320 return !0;
321}
322
323
324
325 142
326/* 143/*
327 Stuff for Emacs to see, in order to encourage consistent editing style: 144 Stuff for Emacs to see, in order to encourage consistent editing style:
diff --git a/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.h b/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.h
index 66abf77f51fd..e35c2322a08c 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.h
+++ b/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.h
@@ -34,9 +34,9 @@
34 34
35 35
36 36
37#include "pvrusb2-i2c-core.h" 37#include "pvrusb2-hdw-internal.h"
38 38
39int pvr2_i2c_cx2584x_v4l_setup(struct pvr2_hdw *,struct pvr2_i2c_client *); 39void pvr2_cx25840_subdev_update(struct pvr2_hdw *, struct v4l2_subdev *sd);
40 40
41 41
42#endif /* __PVRUSB2_CX2584X_V4L_H */ 42#endif /* __PVRUSB2_CX2584X_V4L_H */
diff --git a/drivers/media/video/pvrusb2/pvrusb2-debugifc.c b/drivers/media/video/pvrusb2/pvrusb2-debugifc.c
index ca892fb78a5b..fbe3856bdca6 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-debugifc.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-debugifc.c
@@ -23,7 +23,6 @@
23#include "pvrusb2-debugifc.h" 23#include "pvrusb2-debugifc.h"
24#include "pvrusb2-hdw.h" 24#include "pvrusb2-hdw.h"
25#include "pvrusb2-debug.h" 25#include "pvrusb2-debug.h"
26#include "pvrusb2-i2c-core.h"
27 26
28struct debugifc_mask_item { 27struct debugifc_mask_item {
29 const char *name; 28 const char *name;
@@ -147,10 +146,6 @@ int pvr2_debugifc_print_info(struct pvr2_hdw *hdw,char *buf,unsigned int acnt)
147 bcnt += ccnt; acnt -= ccnt; buf += ccnt; 146 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
148 ccnt = pvr2_hdw_state_report(hdw,buf,acnt); 147 ccnt = pvr2_hdw_state_report(hdw,buf,acnt);
149 bcnt += ccnt; acnt -= ccnt; buf += ccnt; 148 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
150 ccnt = scnprintf(buf,acnt,"Attached I2C modules:\n");
151 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
152 ccnt = pvr2_i2c_report(hdw,buf,acnt);
153 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
154 149
155 return bcnt; 150 return bcnt;
156} 151}
diff --git a/drivers/media/video/pvrusb2/pvrusb2-debugifc.h b/drivers/media/video/pvrusb2/pvrusb2-debugifc.h
index e24ff59f8605..2f8d46761cd0 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-debugifc.h
+++ b/drivers/media/video/pvrusb2/pvrusb2-debugifc.h
@@ -22,16 +22,16 @@
22 22
23struct pvr2_hdw; 23struct pvr2_hdw;
24 24
25/* Non-intrusively print some useful debugging info from inside the
26 driver. This should work even if the driver appears to be
27 wedged. */
28int pvr2_debugifc_print_info(struct pvr2_hdw *,
29 char *buf_ptr,unsigned int buf_size);
30
31/* Print general status of driver. This will also trigger a probe of 25/* Print general status of driver. This will also trigger a probe of
32 the USB link. Unlike print_info(), this one synchronizes with the 26 the USB link. Unlike print_info(), this one synchronizes with the
33 driver so the information should be self-consistent (but it will 27 driver so the information should be self-consistent (but it will
34 hang if the driver is wedged). */ 28 hang if the driver is wedged). */
29int pvr2_debugifc_print_info(struct pvr2_hdw *,
30 char *buf_ptr, unsigned int buf_size);
31
32/* Non-intrusively print some useful debugging info from inside the
33 driver. This should work even if the driver appears to be
34 wedged. */
35int pvr2_debugifc_print_status(struct pvr2_hdw *, 35int pvr2_debugifc_print_status(struct pvr2_hdw *,
36 char *buf_ptr,unsigned int buf_size); 36 char *buf_ptr,unsigned int buf_size);
37 37
diff --git a/drivers/media/video/pvrusb2/pvrusb2-devattr.c b/drivers/media/video/pvrusb2/pvrusb2-devattr.c
index cbe2a3417851..1cb6a260e8b0 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-devattr.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-devattr.c
@@ -46,10 +46,11 @@ pvr2_device_desc structures.
46/*------------------------------------------------------------------------*/ 46/*------------------------------------------------------------------------*/
47/* Hauppauge PVR-USB2 Model 29xxx */ 47/* Hauppauge PVR-USB2 Model 29xxx */
48 48
49static const char *pvr2_client_29xxx[] = { 49static const struct pvr2_device_client_desc pvr2_cli_29xxx[] = {
50 "msp3400", 50 { .module_id = PVR2_CLIENT_ID_SAA7115 },
51 "saa7115", 51 { .module_id = PVR2_CLIENT_ID_MSP3400 },
52 "tuner", 52 { .module_id = PVR2_CLIENT_ID_TUNER },
53 { .module_id = PVR2_CLIENT_ID_DEMOD },
53}; 54};
54 55
55static const char *pvr2_fw1_names_29xxx[] = { 56static const char *pvr2_fw1_names_29xxx[] = {
@@ -59,8 +60,8 @@ static const char *pvr2_fw1_names_29xxx[] = {
59static const struct pvr2_device_desc pvr2_device_29xxx = { 60static const struct pvr2_device_desc pvr2_device_29xxx = {
60 .description = "WinTV PVR USB2 Model Category 29xxx", 61 .description = "WinTV PVR USB2 Model Category 29xxx",
61 .shortname = "29xxx", 62 .shortname = "29xxx",
62 .client_modules.lst = pvr2_client_29xxx, 63 .client_table.lst = pvr2_cli_29xxx,
63 .client_modules.cnt = ARRAY_SIZE(pvr2_client_29xxx), 64 .client_table.cnt = ARRAY_SIZE(pvr2_cli_29xxx),
64 .fx2_firmware.lst = pvr2_fw1_names_29xxx, 65 .fx2_firmware.lst = pvr2_fw1_names_29xxx,
65 .fx2_firmware.cnt = ARRAY_SIZE(pvr2_fw1_names_29xxx), 66 .fx2_firmware.cnt = ARRAY_SIZE(pvr2_fw1_names_29xxx),
66 .flag_has_hauppauge_rom = !0, 67 .flag_has_hauppauge_rom = !0,
@@ -77,10 +78,11 @@ static const struct pvr2_device_desc pvr2_device_29xxx = {
77/*------------------------------------------------------------------------*/ 78/*------------------------------------------------------------------------*/
78/* Hauppauge PVR-USB2 Model 24xxx */ 79/* Hauppauge PVR-USB2 Model 24xxx */
79 80
80static const char *pvr2_client_24xxx[] = { 81static const struct pvr2_device_client_desc pvr2_cli_24xxx[] = {
81 "cx25840", 82 { .module_id = PVR2_CLIENT_ID_CX25840 },
82 "tuner", 83 { .module_id = PVR2_CLIENT_ID_TUNER },
83 "wm8775", 84 { .module_id = PVR2_CLIENT_ID_WM8775 },
85 { .module_id = PVR2_CLIENT_ID_DEMOD },
84}; 86};
85 87
86static const char *pvr2_fw1_names_24xxx[] = { 88static const char *pvr2_fw1_names_24xxx[] = {
@@ -90,8 +92,8 @@ static const char *pvr2_fw1_names_24xxx[] = {
90static const struct pvr2_device_desc pvr2_device_24xxx = { 92static const struct pvr2_device_desc pvr2_device_24xxx = {
91 .description = "WinTV PVR USB2 Model Category 24xxx", 93 .description = "WinTV PVR USB2 Model Category 24xxx",
92 .shortname = "24xxx", 94 .shortname = "24xxx",
93 .client_modules.lst = pvr2_client_24xxx, 95 .client_table.lst = pvr2_cli_24xxx,
94 .client_modules.cnt = ARRAY_SIZE(pvr2_client_24xxx), 96 .client_table.cnt = ARRAY_SIZE(pvr2_cli_24xxx),
95 .fx2_firmware.lst = pvr2_fw1_names_24xxx, 97 .fx2_firmware.lst = pvr2_fw1_names_24xxx,
96 .fx2_firmware.cnt = ARRAY_SIZE(pvr2_fw1_names_24xxx), 98 .fx2_firmware.cnt = ARRAY_SIZE(pvr2_fw1_names_24xxx),
97 .flag_has_cx25840 = !0, 99 .flag_has_cx25840 = !0,
@@ -111,16 +113,16 @@ static const struct pvr2_device_desc pvr2_device_24xxx = {
111/*------------------------------------------------------------------------*/ 113/*------------------------------------------------------------------------*/
112/* GOTVIEW USB2.0 DVD2 */ 114/* GOTVIEW USB2.0 DVD2 */
113 115
114static const char *pvr2_client_gotview_2[] = { 116static const struct pvr2_device_client_desc pvr2_cli_gotview_2[] = {
115 "cx25840", 117 { .module_id = PVR2_CLIENT_ID_CX25840 },
116 "tuner", 118 { .module_id = PVR2_CLIENT_ID_TUNER },
117}; 119};
118 120
119static const struct pvr2_device_desc pvr2_device_gotview_2 = { 121static const struct pvr2_device_desc pvr2_device_gotview_2 = {
120 .description = "Gotview USB 2.0 DVD 2", 122 .description = "Gotview USB 2.0 DVD 2",
121 .shortname = "gv2", 123 .shortname = "gv2",
122 .client_modules.lst = pvr2_client_gotview_2, 124 .client_table.lst = pvr2_cli_gotview_2,
123 .client_modules.cnt = ARRAY_SIZE(pvr2_client_gotview_2), 125 .client_table.cnt = ARRAY_SIZE(pvr2_cli_gotview_2),
124 .flag_has_cx25840 = !0, 126 .flag_has_cx25840 = !0,
125 .default_tuner_type = TUNER_PHILIPS_FM1216ME_MK3, 127 .default_tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
126 .flag_has_analogtuner = !0, 128 .flag_has_analogtuner = !0,
@@ -140,8 +142,8 @@ static const struct pvr2_device_desc pvr2_device_gotview_2 = {
140static const struct pvr2_device_desc pvr2_device_gotview_2d = { 142static const struct pvr2_device_desc pvr2_device_gotview_2d = {
141 .description = "Gotview USB 2.0 DVD Deluxe", 143 .description = "Gotview USB 2.0 DVD Deluxe",
142 .shortname = "gv2d", 144 .shortname = "gv2d",
143 .client_modules.lst = pvr2_client_gotview_2, 145 .client_table.lst = pvr2_cli_gotview_2,
144 .client_modules.cnt = ARRAY_SIZE(pvr2_client_gotview_2), 146 .client_table.cnt = ARRAY_SIZE(pvr2_cli_gotview_2),
145 .flag_has_cx25840 = !0, 147 .flag_has_cx25840 = !0,
146 .default_tuner_type = TUNER_PHILIPS_FM1216ME_MK3, 148 .default_tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
147 .flag_has_analogtuner = !0, 149 .flag_has_analogtuner = !0,
@@ -181,29 +183,29 @@ static int pvr2_lgh06xf_attach(struct pvr2_dvb_adapter *adap)
181 return 0; 183 return 0;
182} 184}
183 185
184static struct pvr2_dvb_props pvr2_onair_creator_fe_props = { 186static const struct pvr2_dvb_props pvr2_onair_creator_fe_props = {
185 .frontend_attach = pvr2_lgdt3303_attach, 187 .frontend_attach = pvr2_lgdt3303_attach,
186 .tuner_attach = pvr2_lgh06xf_attach, 188 .tuner_attach = pvr2_lgh06xf_attach,
187}; 189};
188#endif 190#endif
189 191
190static const char *pvr2_client_onair_creator[] = { 192static const struct pvr2_device_client_desc pvr2_cli_onair_creator[] = {
191 "saa7115", 193 { .module_id = PVR2_CLIENT_ID_SAA7115 },
192 "tuner", 194 { .module_id = PVR2_CLIENT_ID_CS53L32A },
193 "cs53l32a", 195 { .module_id = PVR2_CLIENT_ID_TUNER },
194}; 196};
195 197
196static const struct pvr2_device_desc pvr2_device_onair_creator = { 198static const struct pvr2_device_desc pvr2_device_onair_creator = {
197 .description = "OnAir Creator Hybrid USB tuner", 199 .description = "OnAir Creator Hybrid USB tuner",
198 .shortname = "oac", 200 .shortname = "oac",
199 .client_modules.lst = pvr2_client_onair_creator, 201 .client_table.lst = pvr2_cli_onair_creator,
200 .client_modules.cnt = ARRAY_SIZE(pvr2_client_onair_creator), 202 .client_table.cnt = ARRAY_SIZE(pvr2_cli_onair_creator),
201 .default_tuner_type = TUNER_LG_TDVS_H06XF, 203 .default_tuner_type = TUNER_LG_TDVS_H06XF,
202 .flag_has_analogtuner = !0, 204 .flag_has_analogtuner = !0,
203 .flag_has_composite = !0, 205 .flag_has_composite = !0,
204 .flag_has_svideo = !0, 206 .flag_has_svideo = !0,
205 .flag_digital_requires_cx23416 = !0, 207 .flag_digital_requires_cx23416 = !0,
206 .signal_routing_scheme = PVR2_ROUTING_SCHEME_HAUPPAUGE, 208 .signal_routing_scheme = PVR2_ROUTING_SCHEME_ONAIR,
207 .digital_control_scheme = PVR2_DIGITAL_SCHEME_ONAIR, 209 .digital_control_scheme = PVR2_DIGITAL_SCHEME_ONAIR,
208 .default_std_mask = V4L2_STD_NTSC_M, 210 .default_std_mask = V4L2_STD_NTSC_M,
209#ifdef CONFIG_VIDEO_PVRUSB2_DVB 211#ifdef CONFIG_VIDEO_PVRUSB2_DVB
@@ -241,29 +243,29 @@ static int pvr2_fcv1236d_attach(struct pvr2_dvb_adapter *adap)
241 return 0; 243 return 0;
242} 244}
243 245
244static struct pvr2_dvb_props pvr2_onair_usb2_fe_props = { 246static const struct pvr2_dvb_props pvr2_onair_usb2_fe_props = {
245 .frontend_attach = pvr2_lgdt3302_attach, 247 .frontend_attach = pvr2_lgdt3302_attach,
246 .tuner_attach = pvr2_fcv1236d_attach, 248 .tuner_attach = pvr2_fcv1236d_attach,
247}; 249};
248#endif 250#endif
249 251
250static const char *pvr2_client_onair_usb2[] = { 252static const struct pvr2_device_client_desc pvr2_cli_onair_usb2[] = {
251 "saa7115", 253 { .module_id = PVR2_CLIENT_ID_SAA7115 },
252 "tuner", 254 { .module_id = PVR2_CLIENT_ID_CS53L32A },
253 "cs53l32a", 255 { .module_id = PVR2_CLIENT_ID_TUNER },
254}; 256};
255 257
256static const struct pvr2_device_desc pvr2_device_onair_usb2 = { 258static const struct pvr2_device_desc pvr2_device_onair_usb2 = {
257 .description = "OnAir USB2 Hybrid USB tuner", 259 .description = "OnAir USB2 Hybrid USB tuner",
258 .shortname = "oa2", 260 .shortname = "oa2",
259 .client_modules.lst = pvr2_client_onair_usb2, 261 .client_table.lst = pvr2_cli_onair_usb2,
260 .client_modules.cnt = ARRAY_SIZE(pvr2_client_onair_usb2), 262 .client_table.cnt = ARRAY_SIZE(pvr2_cli_onair_usb2),
261 .default_tuner_type = TUNER_PHILIPS_FCV1236D, 263 .default_tuner_type = TUNER_PHILIPS_FCV1236D,
262 .flag_has_analogtuner = !0, 264 .flag_has_analogtuner = !0,
263 .flag_has_composite = !0, 265 .flag_has_composite = !0,
264 .flag_has_svideo = !0, 266 .flag_has_svideo = !0,
265 .flag_digital_requires_cx23416 = !0, 267 .flag_digital_requires_cx23416 = !0,
266 .signal_routing_scheme = PVR2_ROUTING_SCHEME_HAUPPAUGE, 268 .signal_routing_scheme = PVR2_ROUTING_SCHEME_ONAIR,
267 .digital_control_scheme = PVR2_DIGITAL_SCHEME_ONAIR, 269 .digital_control_scheme = PVR2_DIGITAL_SCHEME_ONAIR,
268 .default_std_mask = V4L2_STD_NTSC_M, 270 .default_std_mask = V4L2_STD_NTSC_M,
269#ifdef CONFIG_VIDEO_PVRUSB2_DVB 271#ifdef CONFIG_VIDEO_PVRUSB2_DVB
@@ -314,15 +316,16 @@ static int pvr2_73xxx_tda18271_8295_attach(struct pvr2_dvb_adapter *adap)
314 return 0; 316 return 0;
315} 317}
316 318
317static struct pvr2_dvb_props pvr2_73xxx_dvb_props = { 319static const struct pvr2_dvb_props pvr2_73xxx_dvb_props = {
318 .frontend_attach = pvr2_tda10048_attach, 320 .frontend_attach = pvr2_tda10048_attach,
319 .tuner_attach = pvr2_73xxx_tda18271_8295_attach, 321 .tuner_attach = pvr2_73xxx_tda18271_8295_attach,
320}; 322};
321#endif 323#endif
322 324
323static const char *pvr2_client_73xxx[] = { 325static const struct pvr2_device_client_desc pvr2_cli_73xxx[] = {
324 "cx25840", 326 { .module_id = PVR2_CLIENT_ID_CX25840 },
325 "tuner", 327 { .module_id = PVR2_CLIENT_ID_TUNER,
328 .i2c_address_list = "\x42"},
326}; 329};
327 330
328static const char *pvr2_fw1_names_73xxx[] = { 331static const char *pvr2_fw1_names_73xxx[] = {
@@ -332,8 +335,8 @@ static const char *pvr2_fw1_names_73xxx[] = {
332static const struct pvr2_device_desc pvr2_device_73xxx = { 335static const struct pvr2_device_desc pvr2_device_73xxx = {
333 .description = "WinTV HVR-1900 Model Category 73xxx", 336 .description = "WinTV HVR-1900 Model Category 73xxx",
334 .shortname = "73xxx", 337 .shortname = "73xxx",
335 .client_modules.lst = pvr2_client_73xxx, 338 .client_table.lst = pvr2_cli_73xxx,
336 .client_modules.cnt = ARRAY_SIZE(pvr2_client_73xxx), 339 .client_table.cnt = ARRAY_SIZE(pvr2_cli_73xxx),
337 .fx2_firmware.lst = pvr2_fw1_names_73xxx, 340 .fx2_firmware.lst = pvr2_fw1_names_73xxx,
338 .fx2_firmware.cnt = ARRAY_SIZE(pvr2_fw1_names_73xxx), 341 .fx2_firmware.cnt = ARRAY_SIZE(pvr2_fw1_names_73xxx),
339 .flag_has_cx25840 = !0, 342 .flag_has_cx25840 = !0,
@@ -418,22 +421,17 @@ static int pvr2_tda18271_8295_attach(struct pvr2_dvb_adapter *adap)
418 return 0; 421 return 0;
419} 422}
420 423
421static struct pvr2_dvb_props pvr2_750xx_dvb_props = { 424static const struct pvr2_dvb_props pvr2_750xx_dvb_props = {
422 .frontend_attach = pvr2_s5h1409_attach, 425 .frontend_attach = pvr2_s5h1409_attach,
423 .tuner_attach = pvr2_tda18271_8295_attach, 426 .tuner_attach = pvr2_tda18271_8295_attach,
424}; 427};
425 428
426static struct pvr2_dvb_props pvr2_751xx_dvb_props = { 429static const struct pvr2_dvb_props pvr2_751xx_dvb_props = {
427 .frontend_attach = pvr2_s5h1411_attach, 430 .frontend_attach = pvr2_s5h1411_attach,
428 .tuner_attach = pvr2_tda18271_8295_attach, 431 .tuner_attach = pvr2_tda18271_8295_attach,
429}; 432};
430#endif 433#endif
431 434
432static const char *pvr2_client_75xxx[] = {
433 "cx25840",
434 "tuner",
435};
436
437static const char *pvr2_fw1_names_75xxx[] = { 435static const char *pvr2_fw1_names_75xxx[] = {
438 "v4l-pvrusb2-73xxx-01.fw", 436 "v4l-pvrusb2-73xxx-01.fw",
439}; 437};
@@ -441,8 +439,8 @@ static const char *pvr2_fw1_names_75xxx[] = {
441static const struct pvr2_device_desc pvr2_device_750xx = { 439static const struct pvr2_device_desc pvr2_device_750xx = {
442 .description = "WinTV HVR-1950 Model Category 750xx", 440 .description = "WinTV HVR-1950 Model Category 750xx",
443 .shortname = "750xx", 441 .shortname = "750xx",
444 .client_modules.lst = pvr2_client_75xxx, 442 .client_table.lst = pvr2_cli_73xxx,
445 .client_modules.cnt = ARRAY_SIZE(pvr2_client_75xxx), 443 .client_table.cnt = ARRAY_SIZE(pvr2_cli_73xxx),
446 .fx2_firmware.lst = pvr2_fw1_names_75xxx, 444 .fx2_firmware.lst = pvr2_fw1_names_75xxx,
447 .fx2_firmware.cnt = ARRAY_SIZE(pvr2_fw1_names_75xxx), 445 .fx2_firmware.cnt = ARRAY_SIZE(pvr2_fw1_names_75xxx),
448 .flag_has_cx25840 = !0, 446 .flag_has_cx25840 = !0,
@@ -463,8 +461,8 @@ static const struct pvr2_device_desc pvr2_device_750xx = {
463static const struct pvr2_device_desc pvr2_device_751xx = { 461static const struct pvr2_device_desc pvr2_device_751xx = {
464 .description = "WinTV HVR-1950 Model Category 751xx", 462 .description = "WinTV HVR-1950 Model Category 751xx",
465 .shortname = "751xx", 463 .shortname = "751xx",
466 .client_modules.lst = pvr2_client_75xxx, 464 .client_table.lst = pvr2_cli_73xxx,
467 .client_modules.cnt = ARRAY_SIZE(pvr2_client_75xxx), 465 .client_table.cnt = ARRAY_SIZE(pvr2_cli_73xxx),
468 .fx2_firmware.lst = pvr2_fw1_names_75xxx, 466 .fx2_firmware.lst = pvr2_fw1_names_75xxx,
469 .fx2_firmware.cnt = ARRAY_SIZE(pvr2_fw1_names_75xxx), 467 .fx2_firmware.cnt = ARRAY_SIZE(pvr2_fw1_names_75xxx),
470 .flag_has_cx25840 = !0, 468 .flag_has_cx25840 = !0,
diff --git a/drivers/media/video/pvrusb2/pvrusb2-devattr.h b/drivers/media/video/pvrusb2/pvrusb2-devattr.h
index cb3a33eb0276..3e553389cbc3 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-devattr.h
+++ b/drivers/media/video/pvrusb2/pvrusb2-devattr.h
@@ -33,6 +33,34 @@
33*/ 33*/
34 34
35 35
36#define PVR2_CLIENT_ID_NULL 0
37#define PVR2_CLIENT_ID_MSP3400 1
38#define PVR2_CLIENT_ID_CX25840 2
39#define PVR2_CLIENT_ID_SAA7115 3
40#define PVR2_CLIENT_ID_TUNER 4
41#define PVR2_CLIENT_ID_CS53L32A 5
42#define PVR2_CLIENT_ID_WM8775 6
43#define PVR2_CLIENT_ID_DEMOD 7
44
45struct pvr2_device_client_desc {
46 /* One ovr PVR2_CLIENT_ID_xxxx */
47 unsigned char module_id;
48
49 /* Null-terminated array of I2C addresses to try in order
50 initialize the module. It's safe to make this null terminated
51 since we're never going to encounter an i2c device with an
52 address of zero. If this is a null pointer or zero-length,
53 then no I2C addresses have been specified, in which case we'll
54 try some compiled in defaults for now. */
55 unsigned char *i2c_address_list;
56};
57
58struct pvr2_device_client_table {
59 const struct pvr2_device_client_desc *lst;
60 unsigned char cnt;
61};
62
63
36struct pvr2_string_table { 64struct pvr2_string_table {
37 const char **lst; 65 const char **lst;
38 unsigned int cnt; 66 unsigned int cnt;
@@ -40,6 +68,7 @@ struct pvr2_string_table {
40 68
41#define PVR2_ROUTING_SCHEME_HAUPPAUGE 0 69#define PVR2_ROUTING_SCHEME_HAUPPAUGE 0
42#define PVR2_ROUTING_SCHEME_GOTVIEW 1 70#define PVR2_ROUTING_SCHEME_GOTVIEW 1
71#define PVR2_ROUTING_SCHEME_ONAIR 2
43 72
44#define PVR2_DIGITAL_SCHEME_NONE 0 73#define PVR2_DIGITAL_SCHEME_NONE 0
45#define PVR2_DIGITAL_SCHEME_HAUPPAUGE 1 74#define PVR2_DIGITAL_SCHEME_HAUPPAUGE 1
@@ -66,6 +95,9 @@ struct pvr2_device_desc {
66 /* List of additional client modules we need to load */ 95 /* List of additional client modules we need to load */
67 struct pvr2_string_table client_modules; 96 struct pvr2_string_table client_modules;
68 97
98 /* List of defined client modules we need to load */
99 struct pvr2_device_client_table client_table;
100
69 /* List of FX2 firmware file names we should search; if empty then 101 /* List of FX2 firmware file names we should search; if empty then
70 FX2 firmware check / load is skipped and we assume the device 102 FX2 firmware check / load is skipped and we assume the device
71 was initialized from internal ROM. */ 103 was initialized from internal ROM. */
@@ -73,7 +105,7 @@ struct pvr2_device_desc {
73 105
74#ifdef CONFIG_VIDEO_PVRUSB2_DVB 106#ifdef CONFIG_VIDEO_PVRUSB2_DVB
75 /* callback functions to handle attachment of digital tuner & demod */ 107 /* callback functions to handle attachment of digital tuner & demod */
76 struct pvr2_dvb_props *dvb_props; 108 const struct pvr2_dvb_props *dvb_props;
77 109
78#endif 110#endif
79 /* Initial standard bits to use for this device, if not zero. 111 /* Initial standard bits to use for this device, if not zero.
diff --git a/drivers/media/video/pvrusb2/pvrusb2-dvb.c b/drivers/media/video/pvrusb2/pvrusb2-dvb.c
index 77b3c3385066..b7f5c49b1dbc 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-dvb.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-dvb.c
@@ -321,7 +321,7 @@ static int pvr2_dvb_adapter_exit(struct pvr2_dvb_adapter *adap)
321static int pvr2_dvb_frontend_init(struct pvr2_dvb_adapter *adap) 321static int pvr2_dvb_frontend_init(struct pvr2_dvb_adapter *adap)
322{ 322{
323 struct pvr2_hdw *hdw = adap->channel.hdw; 323 struct pvr2_hdw *hdw = adap->channel.hdw;
324 struct pvr2_dvb_props *dvb_props = hdw->hdw_desc->dvb_props; 324 const struct pvr2_dvb_props *dvb_props = hdw->hdw_desc->dvb_props;
325 int ret = 0; 325 int ret = 0;
326 326
327 if (dvb_props == NULL) { 327 if (dvb_props == NULL) {
diff --git a/drivers/media/video/pvrusb2/pvrusb2-encoder.c b/drivers/media/video/pvrusb2/pvrusb2-encoder.c
index 273d2a1aa220..54ac5349dee2 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-encoder.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-encoder.c
@@ -347,7 +347,7 @@ static int pvr2_encoder_prep_config(struct pvr2_hdw *hdw)
347 int encMisc3Arg = 0; 347 int encMisc3Arg = 0;
348 348
349#if 0 349#if 0
350 /* This inexplicable bit happens in the Hauppage windows 350 /* This inexplicable bit happens in the Hauppauge windows
351 driver (for both 24xxx and 29xxx devices). However I 351 driver (for both 24xxx and 29xxx devices). However I
352 currently see no difference in behavior with or without 352 currently see no difference in behavior with or without
353 this stuff. Leave this here as a note of its existence, 353 this stuff. Leave this here as a note of its existence,
diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
index de7ee7264be6..5d75eb5211b1 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
@@ -38,6 +38,7 @@
38#include <linux/mutex.h> 38#include <linux/mutex.h>
39#include "pvrusb2-hdw.h" 39#include "pvrusb2-hdw.h"
40#include "pvrusb2-io.h" 40#include "pvrusb2-io.h"
41#include <media/v4l2-device.h>
41#include <media/cx2341x.h> 42#include <media/cx2341x.h>
42#include "pvrusb2-devattr.h" 43#include "pvrusb2-devattr.h"
43 44
@@ -57,8 +58,6 @@
57#define LOCK_TAKE(x) do { mutex_lock(&x##_mutex); x##_held = !0; } while (0) 58#define LOCK_TAKE(x) do { mutex_lock(&x##_mutex); x##_held = !0; } while (0)
58#define LOCK_GIVE(x) do { x##_held = 0; mutex_unlock(&x##_mutex); } while (0) 59#define LOCK_GIVE(x) do { x##_held = 0; mutex_unlock(&x##_mutex); } while (0)
59 60
60struct pvr2_decoder;
61
62typedef int (*pvr2_ctlf_is_dirty)(struct pvr2_ctrl *); 61typedef int (*pvr2_ctlf_is_dirty)(struct pvr2_ctrl *);
63typedef void (*pvr2_ctlf_clear_dirty)(struct pvr2_ctrl *); 62typedef void (*pvr2_ctlf_clear_dirty)(struct pvr2_ctrl *);
64typedef int (*pvr2_ctlf_check_value)(struct pvr2_ctrl *,int); 63typedef int (*pvr2_ctlf_check_value)(struct pvr2_ctrl *,int);
@@ -139,22 +138,6 @@ struct pvr2_ctrl {
139}; 138};
140 139
141 140
142struct pvr2_decoder_ctrl {
143 void *ctxt;
144 void (*detach)(void *);
145 void (*enable)(void *,int);
146 void (*force_reset)(void *);
147};
148
149#define PVR2_I2C_PEND_DETECT 0x01 /* Need to detect a client type */
150#define PVR2_I2C_PEND_CLIENT 0x02 /* Client needs a specific update */
151#define PVR2_I2C_PEND_REFRESH 0x04 /* Client has specific pending bits */
152#define PVR2_I2C_PEND_STALE 0x08 /* Broadcast pending bits */
153
154#define PVR2_I2C_PEND_ALL (PVR2_I2C_PEND_DETECT |\
155 PVR2_I2C_PEND_CLIENT |\
156 PVR2_I2C_PEND_REFRESH |\
157 PVR2_I2C_PEND_STALE)
158 141
159/* Disposition of firmware1 loading situation */ 142/* Disposition of firmware1 loading situation */
160#define FW1_STATE_UNKNOWN 0 143#define FW1_STATE_UNKNOWN 0
@@ -179,6 +162,8 @@ struct pvr2_hdw {
179 struct usb_device *usb_dev; 162 struct usb_device *usb_dev;
180 struct usb_interface *usb_intf; 163 struct usb_interface *usb_intf;
181 164
165 /* Our handle into the v4l2 sub-device architecture */
166 struct v4l2_device v4l2_dev;
182 /* Device description, anything that must adjust behavior based on 167 /* Device description, anything that must adjust behavior based on
183 device specific info will use information held here. */ 168 device specific info will use information held here. */
184 const struct pvr2_device_desc *hdw_desc; 169 const struct pvr2_device_desc *hdw_desc;
@@ -186,7 +171,6 @@ struct pvr2_hdw {
186 /* Kernel worker thread handling */ 171 /* Kernel worker thread handling */
187 struct workqueue_struct *workqueue; 172 struct workqueue_struct *workqueue;
188 struct work_struct workpoll; /* Update driver state */ 173 struct work_struct workpoll; /* Update driver state */
189 struct work_struct worki2csync; /* Update i2c clients */
190 174
191 /* Video spigot */ 175 /* Video spigot */
192 struct pvr2_stream *vid_stream; 176 struct pvr2_stream *vid_stream;
@@ -195,20 +179,26 @@ struct pvr2_hdw {
195 struct mutex big_lock_mutex; 179 struct mutex big_lock_mutex;
196 int big_lock_held; /* For debugging */ 180 int big_lock_held; /* For debugging */
197 181
182 /* This is a simple string which identifies the instance of this
183 driver. It is unique within the set of existing devices, but
184 there is no attempt to keep the name consistent with the same
185 physical device each time. */
198 char name[32]; 186 char name[32];
199 187
188 /* This is a simple string which identifies the physical device
189 instance itself - if possible. (If not possible, then it is
190 based on the specific driver instance, similar to name above.)
191 The idea here is that userspace might hopefully be able to use
192 this recognize specific tuners. It will encode a serial number,
193 if available. */
194 char identifier[32];
195
200 /* I2C stuff */ 196 /* I2C stuff */
201 struct i2c_adapter i2c_adap; 197 struct i2c_adapter i2c_adap;
202 struct i2c_algorithm i2c_algo; 198 struct i2c_algorithm i2c_algo;
203 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT]; 199 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
204 int i2c_cx25840_hack_state; 200 int i2c_cx25840_hack_state;
205 int i2c_linked; 201 int i2c_linked;
206 unsigned int i2c_pend_types; /* Which types of update are needed */
207 unsigned long i2c_pend_mask; /* Change bits we need to scan */
208 unsigned long i2c_stale_mask; /* Pending broadcast change bits */
209 unsigned long i2c_active_mask; /* All change bits currently in use */
210 struct list_head i2c_clients;
211 struct mutex i2c_list_lock;
212 202
213 /* Frequency table */ 203 /* Frequency table */
214 unsigned int freqTable[FREQTABLE_SIZE]; 204 unsigned int freqTable[FREQTABLE_SIZE];
@@ -275,6 +265,7 @@ struct pvr2_hdw {
275 wait_queue_head_t state_wait_data; 265 wait_queue_head_t state_wait_data;
276 266
277 267
268 int force_dirty; /* consider all controls dirty if true */
278 int flag_ok; /* device in known good state */ 269 int flag_ok; /* device in known good state */
279 int flag_disconnected; /* flag_ok == 0 due to disconnect */ 270 int flag_disconnected; /* flag_ok == 0 due to disconnect */
280 int flag_init_ok; /* true if structure is fully initialized */ 271 int flag_init_ok; /* true if structure is fully initialized */
@@ -283,17 +274,13 @@ struct pvr2_hdw {
283 int flag_decoder_missed;/* We've noticed missing decoder */ 274 int flag_decoder_missed;/* We've noticed missing decoder */
284 int flag_tripped; /* Indicates overall failure to start */ 275 int flag_tripped; /* Indicates overall failure to start */
285 276
286 struct pvr2_decoder_ctrl *decoder_ctrl; 277 unsigned int decoder_client_id;
287 278
288 // CPU firmware info (used to help find / save firmware data) 279 // CPU firmware info (used to help find / save firmware data)
289 char *fw_buffer; 280 char *fw_buffer;
290 unsigned int fw_size; 281 unsigned int fw_size;
291 int fw_cpu_flag; /* True if we are dealing with the CPU */ 282 int fw_cpu_flag; /* True if we are dealing with the CPU */
292 283
293 // True if there is a request to trigger logging of state in each
294 // module.
295 int log_requested;
296
297 /* Tuner / frequency control stuff */ 284 /* Tuner / frequency control stuff */
298 unsigned int tuner_type; 285 unsigned int tuner_type;
299 int tuner_updated; 286 int tuner_updated;
@@ -391,7 +378,8 @@ struct pvr2_hdw {
391 378
392/* This function gets the current frequency */ 379/* This function gets the current frequency */
393unsigned long pvr2_hdw_get_cur_freq(struct pvr2_hdw *); 380unsigned long pvr2_hdw_get_cur_freq(struct pvr2_hdw *);
394void pvr2_hdw_set_decoder(struct pvr2_hdw *,struct pvr2_decoder_ctrl *); 381
382void pvr2_hdw_status_poll(struct pvr2_hdw *);
395 383
396#endif /* __PVRUSB2_HDW_INTERNAL_H */ 384#endif /* __PVRUSB2_HDW_INTERNAL_H */
397 385
diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw.c b/drivers/media/video/pvrusb2/pvrusb2-hdw.c
index fa304e5f252a..7a65b42a4f53 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-hdw.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw.c
@@ -24,17 +24,22 @@
24#include <linux/firmware.h> 24#include <linux/firmware.h>
25#include <linux/videodev2.h> 25#include <linux/videodev2.h>
26#include <media/v4l2-common.h> 26#include <media/v4l2-common.h>
27#include <media/tuner.h>
27#include "pvrusb2.h" 28#include "pvrusb2.h"
28#include "pvrusb2-std.h" 29#include "pvrusb2-std.h"
29#include "pvrusb2-util.h" 30#include "pvrusb2-util.h"
30#include "pvrusb2-hdw.h" 31#include "pvrusb2-hdw.h"
31#include "pvrusb2-i2c-core.h" 32#include "pvrusb2-i2c-core.h"
32#include "pvrusb2-tuner.h"
33#include "pvrusb2-eeprom.h" 33#include "pvrusb2-eeprom.h"
34#include "pvrusb2-hdw-internal.h" 34#include "pvrusb2-hdw-internal.h"
35#include "pvrusb2-encoder.h" 35#include "pvrusb2-encoder.h"
36#include "pvrusb2-debug.h" 36#include "pvrusb2-debug.h"
37#include "pvrusb2-fx2-cmd.h" 37#include "pvrusb2-fx2-cmd.h"
38#include "pvrusb2-wm8775.h"
39#include "pvrusb2-video-v4l.h"
40#include "pvrusb2-cx2584x-v4l.h"
41#include "pvrusb2-cs53l32a.h"
42#include "pvrusb2-audio.h"
38 43
39#define TV_MIN_FREQ 55250000L 44#define TV_MIN_FREQ 55250000L
40#define TV_MAX_FREQ 850000000L 45#define TV_MAX_FREQ 850000000L
@@ -104,6 +109,39 @@ MODULE_PARM_DESC(radio_freq, "specify initial radio frequency");
104/* size of a firmware chunk */ 109/* size of a firmware chunk */
105#define FIRMWARE_CHUNK_SIZE 0x2000 110#define FIRMWARE_CHUNK_SIZE 0x2000
106 111
112typedef void (*pvr2_subdev_update_func)(struct pvr2_hdw *,
113 struct v4l2_subdev *);
114
115static const pvr2_subdev_update_func pvr2_module_update_functions[] = {
116 [PVR2_CLIENT_ID_WM8775] = pvr2_wm8775_subdev_update,
117 [PVR2_CLIENT_ID_SAA7115] = pvr2_saa7115_subdev_update,
118 [PVR2_CLIENT_ID_MSP3400] = pvr2_msp3400_subdev_update,
119 [PVR2_CLIENT_ID_CX25840] = pvr2_cx25840_subdev_update,
120 [PVR2_CLIENT_ID_CS53L32A] = pvr2_cs53l32a_subdev_update,
121};
122
123static const char *module_names[] = {
124 [PVR2_CLIENT_ID_MSP3400] = "msp3400",
125 [PVR2_CLIENT_ID_CX25840] = "cx25840",
126 [PVR2_CLIENT_ID_SAA7115] = "saa7115",
127 [PVR2_CLIENT_ID_TUNER] = "tuner",
128 [PVR2_CLIENT_ID_DEMOD] = "tuner",
129 [PVR2_CLIENT_ID_CS53L32A] = "cs53l32a",
130 [PVR2_CLIENT_ID_WM8775] = "wm8775",
131};
132
133
134static const unsigned char *module_i2c_addresses[] = {
135 [PVR2_CLIENT_ID_TUNER] = "\x60\x61\x62\x63",
136 [PVR2_CLIENT_ID_DEMOD] = "\x43",
137 [PVR2_CLIENT_ID_MSP3400] = "\x40",
138 [PVR2_CLIENT_ID_SAA7115] = "\x21",
139 [PVR2_CLIENT_ID_WM8775] = "\x1b",
140 [PVR2_CLIENT_ID_CX25840] = "\x44",
141 [PVR2_CLIENT_ID_CS53L32A] = "\x11",
142};
143
144
107/* Define the list of additional controls we'll dynamically construct based 145/* Define the list of additional controls we'll dynamically construct based
108 on query of the cx2341x module. */ 146 on query of the cx2341x module. */
109struct pvr2_mpeg_ids { 147struct pvr2_mpeg_ids {
@@ -277,7 +315,6 @@ static int pvr2_hdw_set_input(struct pvr2_hdw *hdw,int v);
277static void pvr2_hdw_state_sched(struct pvr2_hdw *); 315static void pvr2_hdw_state_sched(struct pvr2_hdw *);
278static int pvr2_hdw_state_eval(struct pvr2_hdw *); 316static int pvr2_hdw_state_eval(struct pvr2_hdw *);
279static void pvr2_hdw_set_cur_freq(struct pvr2_hdw *,unsigned long); 317static void pvr2_hdw_set_cur_freq(struct pvr2_hdw *,unsigned long);
280static void pvr2_hdw_worker_i2c(struct work_struct *work);
281static void pvr2_hdw_worker_poll(struct work_struct *work); 318static void pvr2_hdw_worker_poll(struct work_struct *work);
282static int pvr2_hdw_wait(struct pvr2_hdw *,int state); 319static int pvr2_hdw_wait(struct pvr2_hdw *,int state);
283static int pvr2_hdw_untrip_unlocked(struct pvr2_hdw *); 320static int pvr2_hdw_untrip_unlocked(struct pvr2_hdw *);
@@ -642,7 +679,7 @@ static int ctrl_freq_max_get(struct pvr2_ctrl *cptr, int *vp)
642 unsigned long fv; 679 unsigned long fv;
643 struct pvr2_hdw *hdw = cptr->hdw; 680 struct pvr2_hdw *hdw = cptr->hdw;
644 if (hdw->tuner_signal_stale) { 681 if (hdw->tuner_signal_stale) {
645 pvr2_i2c_core_status_poll(hdw); 682 pvr2_hdw_status_poll(hdw);
646 } 683 }
647 fv = hdw->tuner_signal_info.rangehigh; 684 fv = hdw->tuner_signal_info.rangehigh;
648 if (!fv) { 685 if (!fv) {
@@ -664,7 +701,7 @@ static int ctrl_freq_min_get(struct pvr2_ctrl *cptr, int *vp)
664 unsigned long fv; 701 unsigned long fv;
665 struct pvr2_hdw *hdw = cptr->hdw; 702 struct pvr2_hdw *hdw = cptr->hdw;
666 if (hdw->tuner_signal_stale) { 703 if (hdw->tuner_signal_stale) {
667 pvr2_i2c_core_status_poll(hdw); 704 pvr2_hdw_status_poll(hdw);
668 } 705 }
669 fv = hdw->tuner_signal_info.rangelow; 706 fv = hdw->tuner_signal_info.rangelow;
670 if (!fv) { 707 if (!fv) {
@@ -858,7 +895,7 @@ static void ctrl_stdcur_clear_dirty(struct pvr2_ctrl *cptr)
858static int ctrl_signal_get(struct pvr2_ctrl *cptr,int *vp) 895static int ctrl_signal_get(struct pvr2_ctrl *cptr,int *vp)
859{ 896{
860 struct pvr2_hdw *hdw = cptr->hdw; 897 struct pvr2_hdw *hdw = cptr->hdw;
861 pvr2_i2c_core_status_poll(hdw); 898 pvr2_hdw_status_poll(hdw);
862 *vp = hdw->tuner_signal_info.signal; 899 *vp = hdw->tuner_signal_info.signal;
863 return 0; 900 return 0;
864} 901}
@@ -868,7 +905,7 @@ static int ctrl_audio_modes_present_get(struct pvr2_ctrl *cptr,int *vp)
868 int val = 0; 905 int val = 0;
869 unsigned int subchan; 906 unsigned int subchan;
870 struct pvr2_hdw *hdw = cptr->hdw; 907 struct pvr2_hdw *hdw = cptr->hdw;
871 pvr2_i2c_core_status_poll(hdw); 908 pvr2_hdw_status_poll(hdw);
872 subchan = hdw->tuner_signal_info.rxsubchans; 909 subchan = hdw->tuner_signal_info.rxsubchans;
873 if (subchan & V4L2_TUNER_SUB_MONO) { 910 if (subchan & V4L2_TUNER_SUB_MONO) {
874 val |= (1 << V4L2_TUNER_MODE_MONO); 911 val |= (1 << V4L2_TUNER_MODE_MONO);
@@ -1283,6 +1320,12 @@ const char *pvr2_hdw_get_bus_info(struct pvr2_hdw *hdw)
1283} 1320}
1284 1321
1285 1322
1323const char *pvr2_hdw_get_device_identifier(struct pvr2_hdw *hdw)
1324{
1325 return hdw->identifier;
1326}
1327
1328
1286unsigned long pvr2_hdw_get_cur_freq(struct pvr2_hdw *hdw) 1329unsigned long pvr2_hdw_get_cur_freq(struct pvr2_hdw *hdw)
1287{ 1330{
1288 return hdw->freqSelector ? hdw->freqValTelevision : hdw->freqValRadio; 1331 return hdw->freqSelector ? hdw->freqValTelevision : hdw->freqValRadio;
@@ -1634,33 +1677,27 @@ static const char *pvr2_get_state_name(unsigned int st)
1634 1677
1635static int pvr2_decoder_enable(struct pvr2_hdw *hdw,int enablefl) 1678static int pvr2_decoder_enable(struct pvr2_hdw *hdw,int enablefl)
1636{ 1679{
1637 if (!hdw->decoder_ctrl) { 1680 /* Even though we really only care about the video decoder chip at
1638 if (!hdw->flag_decoder_missed) { 1681 this point, we'll broadcast stream on/off to all sub-devices
1639 pvr2_trace(PVR2_TRACE_ERROR_LEGS, 1682 anyway, just in case somebody else wants to hear the
1640 "WARNING: No decoder present"); 1683 command... */
1641 hdw->flag_decoder_missed = !0; 1684 pvr2_trace(PVR2_TRACE_CHIPS, "subdev v4l2 stream=%s",
1642 trace_stbit("flag_decoder_missed", 1685 (enablefl ? "on" : "off"));
1643 hdw->flag_decoder_missed); 1686 v4l2_device_call_all(&hdw->v4l2_dev, 0, video, s_stream, enablefl);
1644 } 1687 if (hdw->decoder_client_id) {
1645 return -EIO; 1688 /* We get here if the encoder has been noticed. Otherwise
1689 we'll issue a warning to the user (which should
1690 normally never happen). */
1691 return 0;
1646 } 1692 }
1647 hdw->decoder_ctrl->enable(hdw->decoder_ctrl->ctxt,enablefl); 1693 if (!hdw->flag_decoder_missed) {
1648 return 0; 1694 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
1649} 1695 "WARNING: No decoder present");
1650 1696 hdw->flag_decoder_missed = !0;
1651
1652void pvr2_hdw_set_decoder(struct pvr2_hdw *hdw,struct pvr2_decoder_ctrl *ptr)
1653{
1654 if (hdw->decoder_ctrl == ptr) return;
1655 hdw->decoder_ctrl = ptr;
1656 if (hdw->decoder_ctrl && hdw->flag_decoder_missed) {
1657 hdw->flag_decoder_missed = 0;
1658 trace_stbit("flag_decoder_missed", 1697 trace_stbit("flag_decoder_missed",
1659 hdw->flag_decoder_missed); 1698 hdw->flag_decoder_missed);
1660 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
1661 "Decoder has appeared");
1662 pvr2_hdw_state_sched(hdw);
1663 } 1699 }
1700 return -EIO;
1664} 1701}
1665 1702
1666 1703
@@ -1927,6 +1964,166 @@ static void pvr2_hdw_setup_std(struct pvr2_hdw *hdw)
1927} 1964}
1928 1965
1929 1966
1967static unsigned int pvr2_copy_i2c_addr_list(
1968 unsigned short *dst, const unsigned char *src,
1969 unsigned int dst_max)
1970{
1971 unsigned int cnt = 0;
1972 if (!src) return 0;
1973 while (src[cnt] && (cnt + 1) < dst_max) {
1974 dst[cnt] = src[cnt];
1975 cnt++;
1976 }
1977 dst[cnt] = I2C_CLIENT_END;
1978 return cnt;
1979}
1980
1981
1982static int pvr2_hdw_load_subdev(struct pvr2_hdw *hdw,
1983 const struct pvr2_device_client_desc *cd)
1984{
1985 const char *fname;
1986 unsigned char mid;
1987 struct v4l2_subdev *sd;
1988 unsigned int i2ccnt;
1989 const unsigned char *p;
1990 /* Arbitrary count - max # i2c addresses we will probe */
1991 unsigned short i2caddr[25];
1992
1993 mid = cd->module_id;
1994 fname = (mid < ARRAY_SIZE(module_names)) ? module_names[mid] : NULL;
1995 if (!fname) {
1996 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
1997 "Module ID %u for device %s has no name",
1998 mid,
1999 hdw->hdw_desc->description);
2000 return -EINVAL;
2001 }
2002 pvr2_trace(PVR2_TRACE_INIT,
2003 "Module ID %u (%s) for device %s being loaded...",
2004 mid, fname,
2005 hdw->hdw_desc->description);
2006
2007 i2ccnt = pvr2_copy_i2c_addr_list(i2caddr, cd->i2c_address_list,
2008 ARRAY_SIZE(i2caddr));
2009 if (!i2ccnt && ((p = (mid < ARRAY_SIZE(module_i2c_addresses)) ?
2010 module_i2c_addresses[mid] : NULL) != NULL)) {
2011 /* Second chance: Try default i2c address list */
2012 i2ccnt = pvr2_copy_i2c_addr_list(i2caddr, p,
2013 ARRAY_SIZE(i2caddr));
2014 if (i2ccnt) {
2015 pvr2_trace(PVR2_TRACE_INIT,
2016 "Module ID %u:"
2017 " Using default i2c address list",
2018 mid);
2019 }
2020 }
2021
2022 if (!i2ccnt) {
2023 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
2024 "Module ID %u (%s) for device %s:"
2025 " No i2c addresses",
2026 mid, fname, hdw->hdw_desc->description);
2027 return -EINVAL;
2028 }
2029
2030 /* Note how the 2nd and 3rd arguments are the same for both
2031 * v4l2_i2c_new_subdev() and v4l2_i2c_new_probed_subdev(). Why?
2032 * Well the 2nd argument is the module name to load, while the 3rd
2033 * argument is documented in the framework as being the "chipid" -
2034 * and every other place where I can find examples of this, the
2035 * "chipid" appears to just be the module name again. So here we
2036 * just do the same thing. */
2037 if (i2ccnt == 1) {
2038 pvr2_trace(PVR2_TRACE_INIT,
2039 "Module ID %u:"
2040 " Setting up with specified i2c address 0x%x",
2041 mid, i2caddr[0]);
2042 sd = v4l2_i2c_new_subdev(&hdw->i2c_adap,
2043 fname, fname,
2044 i2caddr[0]);
2045 } else {
2046 pvr2_trace(PVR2_TRACE_INIT,
2047 "Module ID %u:"
2048 " Setting up with address probe list",
2049 mid);
2050 sd = v4l2_i2c_new_probed_subdev(&hdw->i2c_adap,
2051 fname, fname,
2052 i2caddr);
2053 }
2054
2055 if (!sd) {
2056 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
2057 "Module ID %u (%s) for device %s failed to load",
2058 mid, fname, hdw->hdw_desc->description);
2059 return -EIO;
2060 }
2061
2062 /* Tag this sub-device instance with the module ID we know about.
2063 In other places we'll use that tag to determine if the instance
2064 requires special handling. */
2065 sd->grp_id = mid;
2066
2067 pvr2_trace(PVR2_TRACE_INFO, "Attached sub-driver %s", fname);
2068
2069
2070 /* client-specific setup... */
2071 switch (mid) {
2072 case PVR2_CLIENT_ID_CX25840:
2073 hdw->decoder_client_id = mid;
2074 {
2075 /*
2076 Mike Isely <isely@pobox.com> 19-Nov-2006 - This
2077 bit of nuttiness for cx25840 causes that module
2078 to correctly set up its video scaling. This is
2079 really a problem in the cx25840 module itself,
2080 but we work around it here. The problem has not
2081 been seen in ivtv because there VBI is supported
2082 and set up. We don't do VBI here (at least not
2083 yet) and thus we never attempted to even set it
2084 up.
2085 */
2086 struct v4l2_format fmt;
2087 pvr2_trace(PVR2_TRACE_INIT,
2088 "Module ID %u:"
2089 " Executing cx25840 VBI hack",
2090 mid);
2091 memset(&fmt, 0, sizeof(fmt));
2092 fmt.type = V4L2_BUF_TYPE_SLICED_VBI_CAPTURE;
2093 v4l2_device_call_all(&hdw->v4l2_dev, mid,
2094 video, s_fmt, &fmt);
2095 }
2096 break;
2097 case PVR2_CLIENT_ID_SAA7115:
2098 hdw->decoder_client_id = mid;
2099 break;
2100 default: break;
2101 }
2102
2103 return 0;
2104}
2105
2106
2107static void pvr2_hdw_load_modules(struct pvr2_hdw *hdw)
2108{
2109 unsigned int idx;
2110 const struct pvr2_string_table *cm;
2111 const struct pvr2_device_client_table *ct;
2112 int okFl = !0;
2113
2114 cm = &hdw->hdw_desc->client_modules;
2115 for (idx = 0; idx < cm->cnt; idx++) {
2116 request_module(cm->lst[idx]);
2117 }
2118
2119 ct = &hdw->hdw_desc->client_table;
2120 for (idx = 0; idx < ct->cnt; idx++) {
2121 if (pvr2_hdw_load_subdev(hdw, &ct->lst[idx]) < 0) okFl = 0;
2122 }
2123 if (!okFl) pvr2_hdw_render_useless(hdw);
2124}
2125
2126
1930static void pvr2_hdw_setup_low(struct pvr2_hdw *hdw) 2127static void pvr2_hdw_setup_low(struct pvr2_hdw *hdw)
1931{ 2128{
1932 int ret; 2129 int ret;
@@ -1966,9 +2163,7 @@ static void pvr2_hdw_setup_low(struct pvr2_hdw *hdw)
1966 2163
1967 if (!pvr2_hdw_dev_ok(hdw)) return; 2164 if (!pvr2_hdw_dev_ok(hdw)) return;
1968 2165
1969 for (idx = 0; idx < hdw->hdw_desc->client_modules.cnt; idx++) { 2166 hdw->force_dirty = !0;
1970 request_module(hdw->hdw_desc->client_modules.lst[idx]);
1971 }
1972 2167
1973 if (!hdw->hdw_desc->flag_no_powerup) { 2168 if (!hdw->hdw_desc->flag_no_powerup) {
1974 pvr2_hdw_cmd_powerup(hdw); 2169 pvr2_hdw_cmd_powerup(hdw);
@@ -1987,6 +2182,11 @@ static void pvr2_hdw_setup_low(struct pvr2_hdw *hdw)
1987 pvr2_i2c_core_init(hdw); 2182 pvr2_i2c_core_init(hdw);
1988 if (!pvr2_hdw_dev_ok(hdw)) return; 2183 if (!pvr2_hdw_dev_ok(hdw)) return;
1989 2184
2185 pvr2_hdw_load_modules(hdw);
2186 if (!pvr2_hdw_dev_ok(hdw)) return;
2187
2188 v4l2_device_call_all(&hdw->v4l2_dev, 0, core, init, 0);
2189
1990 for (idx = 0; idx < CTRLDEF_COUNT; idx++) { 2190 for (idx = 0; idx < CTRLDEF_COUNT; idx++) {
1991 cptr = hdw->controls + idx; 2191 cptr = hdw->controls + idx;
1992 if (cptr->info->skip_init) continue; 2192 if (cptr->info->skip_init) continue;
@@ -2024,6 +2224,19 @@ static void pvr2_hdw_setup_low(struct pvr2_hdw *hdw)
2024 hdw->std_mask_eeprom = V4L2_STD_ALL; 2224 hdw->std_mask_eeprom = V4L2_STD_ALL;
2025 } 2225 }
2026 2226
2227 if (hdw->serial_number) {
2228 idx = scnprintf(hdw->identifier, sizeof(hdw->identifier) - 1,
2229 "sn-%lu", hdw->serial_number);
2230 } else if (hdw->unit_number >= 0) {
2231 idx = scnprintf(hdw->identifier, sizeof(hdw->identifier) - 1,
2232 "unit-%c",
2233 hdw->unit_number + 'a');
2234 } else {
2235 idx = scnprintf(hdw->identifier, sizeof(hdw->identifier) - 1,
2236 "unit-??");
2237 }
2238 hdw->identifier[idx] = 0;
2239
2027 pvr2_hdw_setup_std(hdw); 2240 pvr2_hdw_setup_std(hdw);
2028 2241
2029 if (!get_default_tuner_type(hdw)) { 2242 if (!get_default_tuner_type(hdw)) {
@@ -2032,8 +2245,6 @@ static void pvr2_hdw_setup_low(struct pvr2_hdw *hdw)
2032 hdw->tuner_type); 2245 hdw->tuner_type);
2033 } 2246 }
2034 2247
2035 pvr2_i2c_core_check_stale(hdw);
2036 hdw->tuner_updated = 0;
2037 2248
2038 if (!pvr2_hdw_dev_ok(hdw)) return; 2249 if (!pvr2_hdw_dev_ok(hdw)) return;
2039 2250
@@ -2171,11 +2382,14 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
2171 struct pvr2_hdw *hdw = NULL; 2382 struct pvr2_hdw *hdw = NULL;
2172 int valid_std_mask; 2383 int valid_std_mask;
2173 struct pvr2_ctrl *cptr; 2384 struct pvr2_ctrl *cptr;
2385 struct usb_device *usb_dev;
2174 const struct pvr2_device_desc *hdw_desc; 2386 const struct pvr2_device_desc *hdw_desc;
2175 __u8 ifnum; 2387 __u8 ifnum;
2176 struct v4l2_queryctrl qctrl; 2388 struct v4l2_queryctrl qctrl;
2177 struct pvr2_ctl_info *ciptr; 2389 struct pvr2_ctl_info *ciptr;
2178 2390
2391 usb_dev = interface_to_usbdev(intf);
2392
2179 hdw_desc = (const struct pvr2_device_desc *)(devid->driver_info); 2393 hdw_desc = (const struct pvr2_device_desc *)(devid->driver_info);
2180 2394
2181 if (hdw_desc == NULL) { 2395 if (hdw_desc == NULL) {
@@ -2360,6 +2574,11 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
2360 hdw->ctl_read_urb = usb_alloc_urb(0,GFP_KERNEL); 2574 hdw->ctl_read_urb = usb_alloc_urb(0,GFP_KERNEL);
2361 if (!hdw->ctl_read_urb) goto fail; 2575 if (!hdw->ctl_read_urb) goto fail;
2362 2576
2577 if (v4l2_device_register(&usb_dev->dev, &hdw->v4l2_dev) != 0) {
2578 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
2579 "Error registering with v4l core, giving up");
2580 goto fail;
2581 }
2363 mutex_lock(&pvr2_unit_mtx); do { 2582 mutex_lock(&pvr2_unit_mtx); do {
2364 for (idx = 0; idx < PVR_NUM; idx++) { 2583 for (idx = 0; idx < PVR_NUM; idx++) {
2365 if (unit_pointers[idx]) continue; 2584 if (unit_pointers[idx]) continue;
@@ -2382,7 +2601,6 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
2382 2601
2383 hdw->workqueue = create_singlethread_workqueue(hdw->name); 2602 hdw->workqueue = create_singlethread_workqueue(hdw->name);
2384 INIT_WORK(&hdw->workpoll,pvr2_hdw_worker_poll); 2603 INIT_WORK(&hdw->workpoll,pvr2_hdw_worker_poll);
2385 INIT_WORK(&hdw->worki2csync,pvr2_hdw_worker_i2c);
2386 2604
2387 pvr2_trace(PVR2_TRACE_INIT,"Driver unit number is %d, name is %s", 2605 pvr2_trace(PVR2_TRACE_INIT,"Driver unit number is %d, name is %s",
2388 hdw->unit_number,hdw->name); 2606 hdw->unit_number,hdw->name);
@@ -2391,12 +2609,9 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
2391 hdw->flag_ok = !0; 2609 hdw->flag_ok = !0;
2392 2610
2393 hdw->usb_intf = intf; 2611 hdw->usb_intf = intf;
2394 hdw->usb_dev = interface_to_usbdev(intf); 2612 hdw->usb_dev = usb_dev;
2395 2613
2396 scnprintf(hdw->bus_info,sizeof(hdw->bus_info), 2614 usb_make_path(hdw->usb_dev, hdw->bus_info, sizeof(hdw->bus_info));
2397 "usb %s address %d",
2398 dev_name(&hdw->usb_dev->dev),
2399 hdw->usb_dev->devnum);
2400 2615
2401 ifnum = hdw->usb_intf->cur_altsetting->desc.bInterfaceNumber; 2616 ifnum = hdw->usb_intf->cur_altsetting->desc.bInterfaceNumber;
2402 usb_set_interface(hdw->usb_dev,ifnum,0); 2617 usb_set_interface(hdw->usb_dev,ifnum,0);
@@ -2454,6 +2669,10 @@ static void pvr2_hdw_remove_usb_stuff(struct pvr2_hdw *hdw)
2454 hdw->ctl_write_buffer = NULL; 2669 hdw->ctl_write_buffer = NULL;
2455 } 2670 }
2456 hdw->flag_disconnected = !0; 2671 hdw->flag_disconnected = !0;
2672 /* If we don't do this, then there will be a dangling struct device
2673 reference to our disappearing device persisting inside the V4L
2674 core... */
2675 v4l2_device_disconnect(&hdw->v4l2_dev);
2457 hdw->usb_dev = NULL; 2676 hdw->usb_dev = NULL;
2458 hdw->usb_intf = NULL; 2677 hdw->usb_intf = NULL;
2459 pvr2_hdw_render_useless(hdw); 2678 pvr2_hdw_render_useless(hdw);
@@ -2481,10 +2700,8 @@ void pvr2_hdw_destroy(struct pvr2_hdw *hdw)
2481 pvr2_stream_destroy(hdw->vid_stream); 2700 pvr2_stream_destroy(hdw->vid_stream);
2482 hdw->vid_stream = NULL; 2701 hdw->vid_stream = NULL;
2483 } 2702 }
2484 if (hdw->decoder_ctrl) {
2485 hdw->decoder_ctrl->detach(hdw->decoder_ctrl->ctxt);
2486 }
2487 pvr2_i2c_core_done(hdw); 2703 pvr2_i2c_core_done(hdw);
2704 v4l2_device_unregister(&hdw->v4l2_dev);
2488 pvr2_hdw_remove_usb_stuff(hdw); 2705 pvr2_hdw_remove_usb_stuff(hdw);
2489 mutex_lock(&pvr2_unit_mtx); do { 2706 mutex_lock(&pvr2_unit_mtx); do {
2490 if ((hdw->unit_number >= 0) && 2707 if ((hdw->unit_number >= 0) &&
@@ -2678,6 +2895,150 @@ static const char *get_ctrl_typename(enum pvr2_ctl_type tp)
2678} 2895}
2679 2896
2680 2897
2898static void pvr2_subdev_set_control(struct pvr2_hdw *hdw, int id,
2899 const char *name, int val)
2900{
2901 struct v4l2_control ctrl;
2902 pvr2_trace(PVR2_TRACE_CHIPS, "subdev v4l2 %s=%d", name, val);
2903 memset(&ctrl, 0, sizeof(ctrl));
2904 ctrl.id = id;
2905 ctrl.value = val;
2906 v4l2_device_call_all(&hdw->v4l2_dev, 0, core, s_ctrl, &ctrl);
2907}
2908
2909#define PVR2_SUBDEV_SET_CONTROL(hdw, id, lab) \
2910 if ((hdw)->lab##_dirty || (hdw)->force_dirty) { \
2911 pvr2_subdev_set_control(hdw, id, #lab, (hdw)->lab##_val); \
2912 }
2913
2914/* Execute whatever commands are required to update the state of all the
2915 sub-devices so that they match our current control values. */
2916static void pvr2_subdev_update(struct pvr2_hdw *hdw)
2917{
2918 struct v4l2_subdev *sd;
2919 unsigned int id;
2920 pvr2_subdev_update_func fp;
2921
2922 pvr2_trace(PVR2_TRACE_CHIPS, "subdev update...");
2923
2924 if (hdw->tuner_updated || hdw->force_dirty) {
2925 struct tuner_setup setup;
2926 pvr2_trace(PVR2_TRACE_CHIPS, "subdev tuner set_type(%d)",
2927 hdw->tuner_type);
2928 if (((int)(hdw->tuner_type)) >= 0) {
2929 setup.addr = ADDR_UNSET;
2930 setup.type = hdw->tuner_type;
2931 setup.mode_mask = T_RADIO | T_ANALOG_TV;
2932 v4l2_device_call_all(&hdw->v4l2_dev, 0,
2933 tuner, s_type_addr, &setup);
2934 }
2935 }
2936
2937 if (hdw->input_dirty || hdw->std_dirty || hdw->force_dirty) {
2938 pvr2_trace(PVR2_TRACE_CHIPS, "subdev v4l2 set_standard");
2939 if (hdw->input_val == PVR2_CVAL_INPUT_RADIO) {
2940 v4l2_device_call_all(&hdw->v4l2_dev, 0,
2941 tuner, s_radio);
2942 } else {
2943 v4l2_std_id vs;
2944 vs = hdw->std_mask_cur;
2945 v4l2_device_call_all(&hdw->v4l2_dev, 0,
2946 tuner, s_std, vs);
2947 }
2948 hdw->tuner_signal_stale = !0;
2949 hdw->cropcap_stale = !0;
2950 }
2951
2952 PVR2_SUBDEV_SET_CONTROL(hdw, V4L2_CID_BRIGHTNESS, brightness);
2953 PVR2_SUBDEV_SET_CONTROL(hdw, V4L2_CID_CONTRAST, contrast);
2954 PVR2_SUBDEV_SET_CONTROL(hdw, V4L2_CID_SATURATION, saturation);
2955 PVR2_SUBDEV_SET_CONTROL(hdw, V4L2_CID_HUE, hue);
2956 PVR2_SUBDEV_SET_CONTROL(hdw, V4L2_CID_AUDIO_MUTE, mute);
2957 PVR2_SUBDEV_SET_CONTROL(hdw, V4L2_CID_AUDIO_VOLUME, volume);
2958 PVR2_SUBDEV_SET_CONTROL(hdw, V4L2_CID_AUDIO_BALANCE, balance);
2959 PVR2_SUBDEV_SET_CONTROL(hdw, V4L2_CID_AUDIO_BASS, bass);
2960 PVR2_SUBDEV_SET_CONTROL(hdw, V4L2_CID_AUDIO_TREBLE, treble);
2961
2962 if (hdw->input_dirty || hdw->audiomode_dirty || hdw->force_dirty) {
2963 struct v4l2_tuner vt;
2964 memset(&vt, 0, sizeof(vt));
2965 vt.audmode = hdw->audiomode_val;
2966 v4l2_device_call_all(&hdw->v4l2_dev, 0, tuner, s_tuner, &vt);
2967 }
2968
2969 if (hdw->freqDirty || hdw->force_dirty) {
2970 unsigned long fv;
2971 struct v4l2_frequency freq;
2972 fv = pvr2_hdw_get_cur_freq(hdw);
2973 pvr2_trace(PVR2_TRACE_CHIPS, "subdev v4l2 set_freq(%lu)", fv);
2974 if (hdw->tuner_signal_stale) pvr2_hdw_status_poll(hdw);
2975 memset(&freq, 0, sizeof(freq));
2976 if (hdw->tuner_signal_info.capability & V4L2_TUNER_CAP_LOW) {
2977 /* ((fv * 1000) / 62500) */
2978 freq.frequency = (fv * 2) / 125;
2979 } else {
2980 freq.frequency = fv / 62500;
2981 }
2982 /* tuner-core currently doesn't seem to care about this, but
2983 let's set it anyway for completeness. */
2984 if (hdw->input_val == PVR2_CVAL_INPUT_RADIO) {
2985 freq.type = V4L2_TUNER_RADIO;
2986 } else {
2987 freq.type = V4L2_TUNER_ANALOG_TV;
2988 }
2989 freq.tuner = 0;
2990 v4l2_device_call_all(&hdw->v4l2_dev, 0, tuner,
2991 s_frequency, &freq);
2992 }
2993
2994 if (hdw->res_hor_dirty || hdw->res_ver_dirty || hdw->force_dirty) {
2995 struct v4l2_format fmt;
2996 memset(&fmt, 0, sizeof(fmt));
2997 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
2998 fmt.fmt.pix.width = hdw->res_hor_val;
2999 fmt.fmt.pix.height = hdw->res_ver_val;
3000 pvr2_trace(PVR2_TRACE_CHIPS, "subdev v4l2 set_size(%dx%d)",
3001 fmt.fmt.pix.width, fmt.fmt.pix.height);
3002 v4l2_device_call_all(&hdw->v4l2_dev, 0, video, s_fmt, &fmt);
3003 }
3004
3005 if (hdw->srate_dirty || hdw->force_dirty) {
3006 u32 val;
3007 pvr2_trace(PVR2_TRACE_CHIPS, "subdev v4l2 set_audio %d",
3008 hdw->srate_val);
3009 switch (hdw->srate_val) {
3010 default:
3011 case V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000:
3012 val = 48000;
3013 break;
3014 case V4L2_MPEG_AUDIO_SAMPLING_FREQ_44100:
3015 val = 44100;
3016 break;
3017 case V4L2_MPEG_AUDIO_SAMPLING_FREQ_32000:
3018 val = 32000;
3019 break;
3020 }
3021 v4l2_device_call_all(&hdw->v4l2_dev, 0,
3022 audio, s_clock_freq, val);
3023 }
3024
3025 /* Unable to set crop parameters; there is apparently no equivalent
3026 for VIDIOC_S_CROP */
3027
3028 v4l2_device_for_each_subdev(sd, &hdw->v4l2_dev) {
3029 id = sd->grp_id;
3030 if (id >= ARRAY_SIZE(pvr2_module_update_functions)) continue;
3031 fp = pvr2_module_update_functions[id];
3032 if (!fp) continue;
3033 (*fp)(hdw, sd);
3034 }
3035
3036 if (hdw->tuner_signal_stale || hdw->cropcap_stale) {
3037 pvr2_hdw_status_poll(hdw);
3038 }
3039}
3040
3041
2681/* Figure out if we need to commit control changes. If so, mark internal 3042/* Figure out if we need to commit control changes. If so, mark internal
2682 state flags to indicate this fact and return true. Otherwise do nothing 3043 state flags to indicate this fact and return true. Otherwise do nothing
2683 else and return false. */ 3044 else and return false. */
@@ -2686,7 +3047,7 @@ static int pvr2_hdw_commit_setup(struct pvr2_hdw *hdw)
2686 unsigned int idx; 3047 unsigned int idx;
2687 struct pvr2_ctrl *cptr; 3048 struct pvr2_ctrl *cptr;
2688 int value; 3049 int value;
2689 int commit_flag = 0; 3050 int commit_flag = hdw->force_dirty;
2690 char buf[100]; 3051 char buf[100];
2691 unsigned int bcnt,ccnt; 3052 unsigned int bcnt,ccnt;
2692 3053
@@ -2842,18 +3203,6 @@ static int pvr2_hdw_commit_execute(struct pvr2_hdw *hdw)
2842 cx2341x_ext_ctrls(&hdw->enc_ctl_state, 0, &cs,VIDIOC_S_EXT_CTRLS); 3203 cx2341x_ext_ctrls(&hdw->enc_ctl_state, 0, &cs,VIDIOC_S_EXT_CTRLS);
2843 } 3204 }
2844 3205
2845 /* Scan i2c core at this point - before we clear all the dirty
2846 bits. Various parts of the i2c core will notice dirty bits as
2847 appropriate and arrange to broadcast or directly send updates to
2848 the client drivers in order to keep everything in sync */
2849 pvr2_i2c_core_check_stale(hdw);
2850
2851 for (idx = 0; idx < hdw->control_cnt; idx++) {
2852 cptr = hdw->controls + idx;
2853 if (!cptr->info->clear_dirty) continue;
2854 cptr->info->clear_dirty(cptr);
2855 }
2856
2857 if (hdw->active_stream_type != hdw->desired_stream_type) { 3206 if (hdw->active_stream_type != hdw->desired_stream_type) {
2858 /* Handle any side effects of stream config here */ 3207 /* Handle any side effects of stream config here */
2859 hdw->active_stream_type = hdw->desired_stream_type; 3208 hdw->active_stream_type = hdw->desired_stream_type;
@@ -2873,8 +3222,16 @@ static int pvr2_hdw_commit_execute(struct pvr2_hdw *hdw)
2873 } 3222 }
2874 } 3223 }
2875 3224
2876 /* Now execute i2c core update */ 3225 /* Check and update state for all sub-devices. */
2877 pvr2_i2c_core_sync(hdw); 3226 pvr2_subdev_update(hdw);
3227
3228 hdw->tuner_updated = 0;
3229 hdw->force_dirty = 0;
3230 for (idx = 0; idx < hdw->control_cnt; idx++) {
3231 cptr = hdw->controls + idx;
3232 if (!cptr->info->clear_dirty) continue;
3233 cptr->info->clear_dirty(cptr);
3234 }
2878 3235
2879 if ((hdw->pathway_state == PVR2_PATHWAY_ANALOG) && 3236 if ((hdw->pathway_state == PVR2_PATHWAY_ANALOG) &&
2880 hdw->state_encoder_run) { 3237 hdw->state_encoder_run) {
@@ -2904,15 +3261,6 @@ int pvr2_hdw_commit_ctl(struct pvr2_hdw *hdw)
2904} 3261}
2905 3262
2906 3263
2907static void pvr2_hdw_worker_i2c(struct work_struct *work)
2908{
2909 struct pvr2_hdw *hdw = container_of(work,struct pvr2_hdw,worki2csync);
2910 LOCK_TAKE(hdw->big_lock); do {
2911 pvr2_i2c_core_sync(hdw);
2912 } while (0); LOCK_GIVE(hdw->big_lock);
2913}
2914
2915
2916static void pvr2_hdw_worker_poll(struct work_struct *work) 3264static void pvr2_hdw_worker_poll(struct work_struct *work)
2917{ 3265{
2918 int fl = 0; 3266 int fl = 0;
@@ -2973,7 +3321,7 @@ int pvr2_hdw_is_hsm(struct pvr2_hdw *hdw)
2973void pvr2_hdw_execute_tuner_poll(struct pvr2_hdw *hdw) 3321void pvr2_hdw_execute_tuner_poll(struct pvr2_hdw *hdw)
2974{ 3322{
2975 LOCK_TAKE(hdw->big_lock); do { 3323 LOCK_TAKE(hdw->big_lock); do {
2976 pvr2_i2c_core_status_poll(hdw); 3324 pvr2_hdw_status_poll(hdw);
2977 } while (0); LOCK_GIVE(hdw->big_lock); 3325 } while (0); LOCK_GIVE(hdw->big_lock);
2978} 3326}
2979 3327
@@ -2983,7 +3331,7 @@ static int pvr2_hdw_check_cropcap(struct pvr2_hdw *hdw)
2983 if (!hdw->cropcap_stale) { 3331 if (!hdw->cropcap_stale) {
2984 return 0; 3332 return 0;
2985 } 3333 }
2986 pvr2_i2c_core_status_poll(hdw); 3334 pvr2_hdw_status_poll(hdw);
2987 if (hdw->cropcap_stale) { 3335 if (hdw->cropcap_stale) {
2988 return -EIO; 3336 return -EIO;
2989 } 3337 }
@@ -3010,7 +3358,7 @@ int pvr2_hdw_get_tuner_status(struct pvr2_hdw *hdw,struct v4l2_tuner *vtp)
3010{ 3358{
3011 LOCK_TAKE(hdw->big_lock); do { 3359 LOCK_TAKE(hdw->big_lock); do {
3012 if (hdw->tuner_signal_stale) { 3360 if (hdw->tuner_signal_stale) {
3013 pvr2_i2c_core_status_poll(hdw); 3361 pvr2_hdw_status_poll(hdw);
3014 } 3362 }
3015 memcpy(vtp,&hdw->tuner_signal_info,sizeof(struct v4l2_tuner)); 3363 memcpy(vtp,&hdw->tuner_signal_info,sizeof(struct v4l2_tuner));
3016 } while (0); LOCK_GIVE(hdw->big_lock); 3364 } while (0); LOCK_GIVE(hdw->big_lock);
@@ -3029,11 +3377,8 @@ void pvr2_hdw_trigger_module_log(struct pvr2_hdw *hdw)
3029{ 3377{
3030 int nr = pvr2_hdw_get_unit_number(hdw); 3378 int nr = pvr2_hdw_get_unit_number(hdw);
3031 LOCK_TAKE(hdw->big_lock); do { 3379 LOCK_TAKE(hdw->big_lock); do {
3032 hdw->log_requested = !0;
3033 printk(KERN_INFO "pvrusb2: ================= START STATUS CARD #%d =================\n", nr); 3380 printk(KERN_INFO "pvrusb2: ================= START STATUS CARD #%d =================\n", nr);
3034 pvr2_i2c_core_check_stale(hdw); 3381 v4l2_device_call_all(&hdw->v4l2_dev, 0, core, log_status);
3035 hdw->log_requested = 0;
3036 pvr2_i2c_core_sync(hdw);
3037 pvr2_trace(PVR2_TRACE_INFO,"cx2341x config:"); 3382 pvr2_trace(PVR2_TRACE_INFO,"cx2341x config:");
3038 cx2341x_log_status(&hdw->enc_ctl_state, "pvrusb2"); 3383 cx2341x_log_status(&hdw->enc_ctl_state, "pvrusb2");
3039 pvr2_hdw_state_log_state(hdw); 3384 pvr2_hdw_state_log_state(hdw);
@@ -3716,22 +4061,16 @@ int pvr2_hdw_cmd_powerdown(struct pvr2_hdw *hdw)
3716 4061
3717int pvr2_hdw_cmd_decoder_reset(struct pvr2_hdw *hdw) 4062int pvr2_hdw_cmd_decoder_reset(struct pvr2_hdw *hdw)
3718{ 4063{
3719 if (!hdw->decoder_ctrl) {
3720 pvr2_trace(PVR2_TRACE_INIT,
3721 "Unable to reset decoder: nothing attached");
3722 return -ENOTTY;
3723 }
3724
3725 if (!hdw->decoder_ctrl->force_reset) {
3726 pvr2_trace(PVR2_TRACE_INIT,
3727 "Unable to reset decoder: not implemented");
3728 return -ENOTTY;
3729 }
3730
3731 pvr2_trace(PVR2_TRACE_INIT, 4064 pvr2_trace(PVR2_TRACE_INIT,
3732 "Requesting decoder reset"); 4065 "Requesting decoder reset");
3733 hdw->decoder_ctrl->force_reset(hdw->decoder_ctrl->ctxt); 4066 if (hdw->decoder_client_id) {
3734 return 0; 4067 v4l2_device_call_all(&hdw->v4l2_dev, hdw->decoder_client_id,
4068 core, reset, 0);
4069 return 0;
4070 }
4071 pvr2_trace(PVR2_TRACE_INIT,
4072 "Unable to reset decoder: nothing attached");
4073 return -ENOTTY;
3735} 4074}
3736 4075
3737 4076
@@ -4476,6 +4815,79 @@ static unsigned int pvr2_hdw_report_unlocked(struct pvr2_hdw *hdw,int which,
4476} 4815}
4477 4816
4478 4817
4818/* Generate report containing info about attached sub-devices and attached
4819 i2c clients, including an indication of which attached i2c clients are
4820 actually sub-devices. */
4821static unsigned int pvr2_hdw_report_clients(struct pvr2_hdw *hdw,
4822 char *buf, unsigned int acnt)
4823{
4824 struct v4l2_subdev *sd;
4825 unsigned int tcnt = 0;
4826 unsigned int ccnt;
4827 struct i2c_client *client;
4828 struct list_head *item;
4829 void *cd;
4830 const char *p;
4831 unsigned int id;
4832
4833 ccnt = scnprintf(buf, acnt, "Associated v4l2-subdev drivers:");
4834 tcnt += ccnt;
4835 v4l2_device_for_each_subdev(sd, &hdw->v4l2_dev) {
4836 id = sd->grp_id;
4837 p = NULL;
4838 if (id < ARRAY_SIZE(module_names)) p = module_names[id];
4839 if (p) {
4840 ccnt = scnprintf(buf + tcnt, acnt - tcnt, " %s", p);
4841 tcnt += ccnt;
4842 } else {
4843 ccnt = scnprintf(buf + tcnt, acnt - tcnt,
4844 " (unknown id=%u)", id);
4845 tcnt += ccnt;
4846 }
4847 }
4848 ccnt = scnprintf(buf + tcnt, acnt - tcnt, "\n");
4849 tcnt += ccnt;
4850
4851 ccnt = scnprintf(buf + tcnt, acnt - tcnt, "I2C clients:\n");
4852 tcnt += ccnt;
4853
4854 mutex_lock(&hdw->i2c_adap.clist_lock);
4855 list_for_each(item, &hdw->i2c_adap.clients) {
4856 client = list_entry(item, struct i2c_client, list);
4857 ccnt = scnprintf(buf + tcnt, acnt - tcnt,
4858 " %s: i2c=%02x", client->name, client->addr);
4859 tcnt += ccnt;
4860 cd = i2c_get_clientdata(client);
4861 v4l2_device_for_each_subdev(sd, &hdw->v4l2_dev) {
4862 if (cd == sd) {
4863 id = sd->grp_id;
4864 p = NULL;
4865 if (id < ARRAY_SIZE(module_names)) {
4866 p = module_names[id];
4867 }
4868 if (p) {
4869 ccnt = scnprintf(buf + tcnt,
4870 acnt - tcnt,
4871 " subdev=%s", p);
4872 tcnt += ccnt;
4873 } else {
4874 ccnt = scnprintf(buf + tcnt,
4875 acnt - tcnt,
4876 " subdev= id %u)",
4877 id);
4878 tcnt += ccnt;
4879 }
4880 break;
4881 }
4882 }
4883 ccnt = scnprintf(buf + tcnt, acnt - tcnt, "\n");
4884 tcnt += ccnt;
4885 }
4886 mutex_unlock(&hdw->i2c_adap.clist_lock);
4887 return tcnt;
4888}
4889
4890
4479unsigned int pvr2_hdw_state_report(struct pvr2_hdw *hdw, 4891unsigned int pvr2_hdw_state_report(struct pvr2_hdw *hdw,
4480 char *buf,unsigned int acnt) 4892 char *buf,unsigned int acnt)
4481{ 4893{
@@ -4490,6 +4902,8 @@ unsigned int pvr2_hdw_state_report(struct pvr2_hdw *hdw,
4490 buf[0] = '\n'; ccnt = 1; 4902 buf[0] = '\n'; ccnt = 1;
4491 bcnt += ccnt; acnt -= ccnt; buf += ccnt; 4903 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
4492 } 4904 }
4905 ccnt = pvr2_hdw_report_clients(hdw, buf, acnt);
4906 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
4493 LOCK_GIVE(hdw->big_lock); 4907 LOCK_GIVE(hdw->big_lock);
4494 return bcnt; 4908 return bcnt;
4495} 4909}
@@ -4497,14 +4911,25 @@ unsigned int pvr2_hdw_state_report(struct pvr2_hdw *hdw,
4497 4911
4498static void pvr2_hdw_state_log_state(struct pvr2_hdw *hdw) 4912static void pvr2_hdw_state_log_state(struct pvr2_hdw *hdw)
4499{ 4913{
4500 char buf[128]; 4914 char buf[256];
4501 unsigned int idx,ccnt; 4915 unsigned int idx, ccnt;
4916 unsigned int lcnt, ucnt;
4502 4917
4503 for (idx = 0; ; idx++) { 4918 for (idx = 0; ; idx++) {
4504 ccnt = pvr2_hdw_report_unlocked(hdw,idx,buf,sizeof(buf)); 4919 ccnt = pvr2_hdw_report_unlocked(hdw,idx,buf,sizeof(buf));
4505 if (!ccnt) break; 4920 if (!ccnt) break;
4506 printk(KERN_INFO "%s %.*s\n",hdw->name,ccnt,buf); 4921 printk(KERN_INFO "%s %.*s\n",hdw->name,ccnt,buf);
4507 } 4922 }
4923 ccnt = pvr2_hdw_report_clients(hdw, buf, sizeof(buf));
4924 ucnt = 0;
4925 while (ucnt < ccnt) {
4926 lcnt = 0;
4927 while ((lcnt + ucnt < ccnt) && (buf[lcnt + ucnt] != '\n')) {
4928 lcnt++;
4929 }
4930 printk(KERN_INFO "%s %.*s\n", hdw->name, lcnt, buf + ucnt);
4931 ucnt += lcnt + 1;
4932 }
4508} 4933}
4509 4934
4510 4935
@@ -4641,6 +5066,30 @@ int pvr2_hdw_gpio_chg_out(struct pvr2_hdw *hdw,u32 msk,u32 val)
4641} 5066}
4642 5067
4643 5068
5069void pvr2_hdw_status_poll(struct pvr2_hdw *hdw)
5070{
5071 struct v4l2_tuner *vtp = &hdw->tuner_signal_info;
5072 memset(vtp, 0, sizeof(*vtp));
5073 hdw->tuner_signal_stale = 0;
5074 /* Note: There apparently is no replacement for VIDIOC_CROPCAP
5075 using v4l2-subdev - therefore we can't support that AT ALL right
5076 now. (Of course, no sub-drivers seem to implement it either.
5077 But now it's a a chicken and egg problem...) */
5078 v4l2_device_call_all(&hdw->v4l2_dev, 0, tuner, g_tuner,
5079 &hdw->tuner_signal_info);
5080 pvr2_trace(PVR2_TRACE_CHIPS, "subdev status poll"
5081 " type=%u strength=%u audio=0x%x cap=0x%x"
5082 " low=%u hi=%u",
5083 vtp->type,
5084 vtp->signal, vtp->rxsubchans, vtp->capability,
5085 vtp->rangelow, vtp->rangehigh);
5086
5087 /* We have to do this to avoid getting into constant polling if
5088 there's nobody to answer a poll of cropcap info. */
5089 hdw->cropcap_stale = 0;
5090}
5091
5092
4644unsigned int pvr2_hdw_get_input_available(struct pvr2_hdw *hdw) 5093unsigned int pvr2_hdw_get_input_available(struct pvr2_hdw *hdw)
4645{ 5094{
4646 return hdw->input_avail_mask; 5095 return hdw->input_avail_mask;
@@ -4736,7 +5185,6 @@ int pvr2_hdw_register_access(struct pvr2_hdw *hdw,
4736 int setFl, u64 *val_ptr) 5185 int setFl, u64 *val_ptr)
4737{ 5186{
4738#ifdef CONFIG_VIDEO_ADV_DEBUG 5187#ifdef CONFIG_VIDEO_ADV_DEBUG
4739 struct pvr2_i2c_client *cp;
4740 struct v4l2_dbg_register req; 5188 struct v4l2_dbg_register req;
4741 int stat = 0; 5189 int stat = 0;
4742 int okFl = 0; 5190 int okFl = 0;
@@ -4746,21 +5194,9 @@ int pvr2_hdw_register_access(struct pvr2_hdw *hdw,
4746 req.match = *match; 5194 req.match = *match;
4747 req.reg = reg_id; 5195 req.reg = reg_id;
4748 if (setFl) req.val = *val_ptr; 5196 if (setFl) req.val = *val_ptr;
4749 mutex_lock(&hdw->i2c_list_lock); do { 5197 /* It would be nice to know if a sub-device answered the request */
4750 list_for_each_entry(cp, &hdw->i2c_clients, list) { 5198 v4l2_device_call_all(&hdw->v4l2_dev, 0, core, g_register, &req);
4751 if (!v4l2_chip_match_i2c_client( 5199 if (!setFl) *val_ptr = req.val;
4752 cp->client,
4753 &req.match)) {
4754 continue;
4755 }
4756 stat = pvr2_i2c_client_cmd(
4757 cp,(setFl ? VIDIOC_DBG_S_REGISTER :
4758 VIDIOC_DBG_G_REGISTER),&req);
4759 if (!setFl) *val_ptr = req.val;
4760 okFl = !0;
4761 break;
4762 }
4763 } while (0); mutex_unlock(&hdw->i2c_list_lock);
4764 if (okFl) { 5200 if (okFl) {
4765 return stat; 5201 return stat;
4766 } 5202 }
diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw.h b/drivers/media/video/pvrusb2/pvrusb2-hdw.h
index 1b4fec337c6b..7b6940554e9a 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-hdw.h
+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw.h
@@ -132,6 +132,9 @@ unsigned long pvr2_hdw_get_sn(struct pvr2_hdw *);
132/* Retrieve bus location info of device */ 132/* Retrieve bus location info of device */
133const char *pvr2_hdw_get_bus_info(struct pvr2_hdw *); 133const char *pvr2_hdw_get_bus_info(struct pvr2_hdw *);
134 134
135/* Retrieve per-instance string identifier for this specific device */
136const char *pvr2_hdw_get_device_identifier(struct pvr2_hdw *);
137
135/* Called when hardware has been unplugged */ 138/* Called when hardware has been unplugged */
136void pvr2_hdw_disconnect(struct pvr2_hdw *); 139void pvr2_hdw_disconnect(struct pvr2_hdw *);
137 140
@@ -236,8 +239,7 @@ void pvr2_hdw_v4l_store_minor_number(struct pvr2_hdw *,
236 enum pvr2_v4l_type index,int); 239 enum pvr2_v4l_type index,int);
237 240
238/* Direct read/write access to chip's registers: 241/* Direct read/write access to chip's registers:
239 match_type - how to interpret match_chip (e.g. driver ID, i2c address) 242 match - specify criteria to identify target chip (this is a v4l dbg struct)
240 match_chip - chip match value (e.g. I2C_DRIVERD_xxxx)
241 reg_id - register number to access 243 reg_id - register number to access
242 setFl - true to set the register, false to read it 244 setFl - true to set the register, false to read it
243 val_ptr - storage location for source / result. */ 245 val_ptr - storage location for source / result. */
diff --git a/drivers/media/video/pvrusb2/pvrusb2-i2c-chips-v4l2.c b/drivers/media/video/pvrusb2/pvrusb2-i2c-chips-v4l2.c
deleted file mode 100644
index 94a47718e88e..000000000000
--- a/drivers/media/video/pvrusb2/pvrusb2-i2c-chips-v4l2.c
+++ /dev/null
@@ -1,113 +0,0 @@
1/*
2 *
3 *
4 * Copyright (C) 2005 Mike Isely <isely@pobox.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
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 */
20
21#include <linux/kernel.h>
22#include "pvrusb2-i2c-core.h"
23#include "pvrusb2-hdw-internal.h"
24#include "pvrusb2-debug.h"
25#include "pvrusb2-i2c-cmd-v4l2.h"
26#include "pvrusb2-audio.h"
27#include "pvrusb2-tuner.h"
28#include "pvrusb2-video-v4l.h"
29#include "pvrusb2-cx2584x-v4l.h"
30#include "pvrusb2-wm8775.h"
31
32#define trace_i2c(...) pvr2_trace(PVR2_TRACE_I2C,__VA_ARGS__)
33
34#define OP_STANDARD 0
35#define OP_AUDIOMODE 1
36#define OP_BCSH 2
37#define OP_VOLUME 3
38#define OP_FREQ 4
39#define OP_AUDIORATE 5
40#define OP_CROP 6
41#define OP_SIZE 7
42#define OP_LOG 8
43
44static const struct pvr2_i2c_op * const ops[] = {
45 [OP_STANDARD] = &pvr2_i2c_op_v4l2_standard,
46 [OP_AUDIOMODE] = &pvr2_i2c_op_v4l2_audiomode,
47 [OP_BCSH] = &pvr2_i2c_op_v4l2_bcsh,
48 [OP_VOLUME] = &pvr2_i2c_op_v4l2_volume,
49 [OP_FREQ] = &pvr2_i2c_op_v4l2_frequency,
50 [OP_CROP] = &pvr2_i2c_op_v4l2_crop,
51 [OP_SIZE] = &pvr2_i2c_op_v4l2_size,
52 [OP_LOG] = &pvr2_i2c_op_v4l2_log,
53};
54
55void pvr2_i2c_probe(struct pvr2_hdw *hdw,struct pvr2_i2c_client *cp)
56{
57 int id;
58 id = cp->client->driver->id;
59 cp->ctl_mask = ((1 << OP_STANDARD) |
60 (1 << OP_AUDIOMODE) |
61 (1 << OP_BCSH) |
62 (1 << OP_VOLUME) |
63 (1 << OP_FREQ) |
64 (1 << OP_CROP) |
65 (1 << OP_SIZE) |
66 (1 << OP_LOG));
67 cp->status_poll = pvr2_v4l2_cmd_status_poll;
68
69 if (id == I2C_DRIVERID_MSP3400) {
70 if (pvr2_i2c_msp3400_setup(hdw,cp)) {
71 return;
72 }
73 }
74 if (id == I2C_DRIVERID_TUNER) {
75 if (pvr2_i2c_tuner_setup(hdw,cp)) {
76 return;
77 }
78 }
79 if (id == I2C_DRIVERID_CX25840) {
80 if (pvr2_i2c_cx2584x_v4l_setup(hdw,cp)) {
81 return;
82 }
83 }
84 if (id == I2C_DRIVERID_WM8775) {
85 if (pvr2_i2c_wm8775_setup(hdw,cp)) {
86 return;
87 }
88 }
89 if (id == I2C_DRIVERID_SAA711X) {
90 if (pvr2_i2c_decoder_v4l_setup(hdw,cp)) {
91 return;
92 }
93 }
94}
95
96
97const struct pvr2_i2c_op *pvr2_i2c_get_op(unsigned int idx)
98{
99 if (idx >= ARRAY_SIZE(ops))
100 return NULL;
101 return ops[idx];
102}
103
104
105/*
106 Stuff for Emacs to see, in order to encourage consistent editing style:
107 *** Local Variables: ***
108 *** mode: c ***
109 *** fill-column: 75 ***
110 *** tab-width: 8 ***
111 *** c-basic-offset: 8 ***
112 *** End: ***
113 */
diff --git a/drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.c b/drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.c
deleted file mode 100644
index 16bb11902a52..000000000000
--- a/drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.c
+++ /dev/null
@@ -1,322 +0,0 @@
1/*
2 *
3 *
4 * Copyright (C) 2005 Mike Isely <isely@pobox.com>
5 * Copyright (C) 2004 Aurelien Alleaume <slts@free.fr>
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#include "pvrusb2-i2c-cmd-v4l2.h"
23#include "pvrusb2-hdw-internal.h"
24#include "pvrusb2-debug.h"
25#include <linux/videodev2.h>
26#include <media/v4l2-common.h>
27
28static void set_standard(struct pvr2_hdw *hdw)
29{
30 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_standard");
31
32 if (hdw->input_val == PVR2_CVAL_INPUT_RADIO) {
33 pvr2_i2c_core_cmd(hdw,AUDC_SET_RADIO,NULL);
34 } else {
35 v4l2_std_id vs;
36 vs = hdw->std_mask_cur;
37 pvr2_i2c_core_cmd(hdw,VIDIOC_S_STD,&vs);
38 }
39 hdw->tuner_signal_stale = !0;
40 hdw->cropcap_stale = !0;
41}
42
43
44static int check_standard(struct pvr2_hdw *hdw)
45{
46 return (hdw->input_dirty != 0) || (hdw->std_dirty != 0);
47}
48
49
50const struct pvr2_i2c_op pvr2_i2c_op_v4l2_standard = {
51 .check = check_standard,
52 .update = set_standard,
53 .name = "v4l2_standard",
54};
55
56
57static void set_bcsh(struct pvr2_hdw *hdw)
58{
59 struct v4l2_control ctrl;
60 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_bcsh"
61 " b=%d c=%d s=%d h=%d",
62 hdw->brightness_val,hdw->contrast_val,
63 hdw->saturation_val,hdw->hue_val);
64 memset(&ctrl,0,sizeof(ctrl));
65 ctrl.id = V4L2_CID_BRIGHTNESS;
66 ctrl.value = hdw->brightness_val;
67 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
68 ctrl.id = V4L2_CID_CONTRAST;
69 ctrl.value = hdw->contrast_val;
70 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
71 ctrl.id = V4L2_CID_SATURATION;
72 ctrl.value = hdw->saturation_val;
73 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
74 ctrl.id = V4L2_CID_HUE;
75 ctrl.value = hdw->hue_val;
76 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
77}
78
79
80static int check_bcsh(struct pvr2_hdw *hdw)
81{
82 return (hdw->brightness_dirty ||
83 hdw->contrast_dirty ||
84 hdw->saturation_dirty ||
85 hdw->hue_dirty);
86}
87
88
89const struct pvr2_i2c_op pvr2_i2c_op_v4l2_bcsh = {
90 .check = check_bcsh,
91 .update = set_bcsh,
92 .name = "v4l2_bcsh",
93};
94
95
96static void set_volume(struct pvr2_hdw *hdw)
97{
98 struct v4l2_control ctrl;
99 pvr2_trace(PVR2_TRACE_CHIPS,
100 "i2c v4l2 set_volume"
101 "(vol=%d bal=%d bas=%d treb=%d mute=%d)",
102 hdw->volume_val,
103 hdw->balance_val,
104 hdw->bass_val,
105 hdw->treble_val,
106 hdw->mute_val);
107 memset(&ctrl,0,sizeof(ctrl));
108 ctrl.id = V4L2_CID_AUDIO_MUTE;
109 ctrl.value = hdw->mute_val ? 1 : 0;
110 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
111 ctrl.id = V4L2_CID_AUDIO_VOLUME;
112 ctrl.value = hdw->volume_val;
113 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
114 ctrl.id = V4L2_CID_AUDIO_BALANCE;
115 ctrl.value = hdw->balance_val;
116 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
117 ctrl.id = V4L2_CID_AUDIO_BASS;
118 ctrl.value = hdw->bass_val;
119 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
120 ctrl.id = V4L2_CID_AUDIO_TREBLE;
121 ctrl.value = hdw->treble_val;
122 pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl);
123}
124
125
126static int check_volume(struct pvr2_hdw *hdw)
127{
128 return (hdw->volume_dirty ||
129 hdw->balance_dirty ||
130 hdw->bass_dirty ||
131 hdw->treble_dirty ||
132 hdw->mute_dirty);
133}
134
135
136const struct pvr2_i2c_op pvr2_i2c_op_v4l2_volume = {
137 .check = check_volume,
138 .update = set_volume,
139 .name = "v4l2_volume",
140};
141
142
143static void set_audiomode(struct pvr2_hdw *hdw)
144{
145 struct v4l2_tuner vt;
146 memset(&vt,0,sizeof(vt));
147 vt.audmode = hdw->audiomode_val;
148 pvr2_i2c_core_cmd(hdw,VIDIOC_S_TUNER,&vt);
149}
150
151
152static int check_audiomode(struct pvr2_hdw *hdw)
153{
154 return (hdw->input_dirty ||
155 hdw->audiomode_dirty);
156}
157
158
159const struct pvr2_i2c_op pvr2_i2c_op_v4l2_audiomode = {
160 .check = check_audiomode,
161 .update = set_audiomode,
162 .name = "v4l2_audiomode",
163};
164
165
166static void set_frequency(struct pvr2_hdw *hdw)
167{
168 unsigned long fv;
169 struct v4l2_frequency freq;
170 fv = pvr2_hdw_get_cur_freq(hdw);
171 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_freq(%lu)",fv);
172 if (hdw->tuner_signal_stale) {
173 pvr2_i2c_core_status_poll(hdw);
174 }
175 memset(&freq,0,sizeof(freq));
176 if (hdw->tuner_signal_info.capability & V4L2_TUNER_CAP_LOW) {
177 // ((fv * 1000) / 62500)
178 freq.frequency = (fv * 2) / 125;
179 } else {
180 freq.frequency = fv / 62500;
181 }
182 /* tuner-core currently doesn't seem to care about this, but
183 let's set it anyway for completeness. */
184 if (hdw->input_val == PVR2_CVAL_INPUT_RADIO) {
185 freq.type = V4L2_TUNER_RADIO;
186 } else {
187 freq.type = V4L2_TUNER_ANALOG_TV;
188 }
189 freq.tuner = 0;
190 pvr2_i2c_core_cmd(hdw,VIDIOC_S_FREQUENCY,&freq);
191}
192
193
194static int check_frequency(struct pvr2_hdw *hdw)
195{
196 return hdw->freqDirty != 0;
197}
198
199
200const struct pvr2_i2c_op pvr2_i2c_op_v4l2_frequency = {
201 .check = check_frequency,
202 .update = set_frequency,
203 .name = "v4l2_freq",
204};
205
206
207static void set_size(struct pvr2_hdw *hdw)
208{
209 struct v4l2_format fmt;
210
211 memset(&fmt,0,sizeof(fmt));
212
213 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
214 fmt.fmt.pix.width = hdw->res_hor_val;
215 fmt.fmt.pix.height = hdw->res_ver_val;
216
217 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_size(%dx%d)",
218 fmt.fmt.pix.width,fmt.fmt.pix.height);
219
220 pvr2_i2c_core_cmd(hdw,VIDIOC_S_FMT,&fmt);
221}
222
223
224static int check_size(struct pvr2_hdw *hdw)
225{
226 return (hdw->res_hor_dirty || hdw->res_ver_dirty);
227}
228
229
230const struct pvr2_i2c_op pvr2_i2c_op_v4l2_size = {
231 .check = check_size,
232 .update = set_size,
233 .name = "v4l2_size",
234};
235
236
237static void set_crop(struct pvr2_hdw *hdw)
238{
239 struct v4l2_crop crop;
240
241 memset(&crop, 0, sizeof crop);
242 crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
243 crop.c.left = hdw->cropl_val;
244 crop.c.top = hdw->cropt_val;
245 crop.c.height = hdw->croph_val;
246 crop.c.width = hdw->cropw_val;
247
248 pvr2_trace(PVR2_TRACE_CHIPS,
249 "i2c v4l2 set_crop crop=%d:%d:%d:%d",
250 crop.c.width, crop.c.height, crop.c.left, crop.c.top);
251
252 pvr2_i2c_core_cmd(hdw, VIDIOC_S_CROP, &crop);
253}
254
255static int check_crop(struct pvr2_hdw *hdw)
256{
257 return (hdw->cropl_dirty || hdw->cropt_dirty ||
258 hdw->cropw_dirty || hdw->croph_dirty);
259}
260
261const struct pvr2_i2c_op pvr2_i2c_op_v4l2_crop = {
262 .check = check_crop,
263 .update = set_crop,
264 .name = "v4l2_crop",
265};
266
267
268static void do_log(struct pvr2_hdw *hdw)
269{
270 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 do_log()");
271 pvr2_i2c_core_cmd(hdw,VIDIOC_LOG_STATUS,NULL);
272
273}
274
275
276static int check_log(struct pvr2_hdw *hdw)
277{
278 return hdw->log_requested != 0;
279}
280
281
282const struct pvr2_i2c_op pvr2_i2c_op_v4l2_log = {
283 .check = check_log,
284 .update = do_log,
285 .name = "v4l2_log",
286};
287
288
289void pvr2_v4l2_cmd_stream(struct pvr2_i2c_client *cp,int fl)
290{
291 pvr2_i2c_client_cmd(cp,
292 (fl ? VIDIOC_STREAMON : VIDIOC_STREAMOFF),NULL);
293}
294
295
296void pvr2_v4l2_cmd_status_poll(struct pvr2_i2c_client *cp)
297{
298 int stat;
299 struct pvr2_hdw *hdw = cp->hdw;
300 if (hdw->cropcap_stale) {
301 hdw->cropcap_info.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
302 stat = pvr2_i2c_client_cmd(cp, VIDIOC_CROPCAP,
303 &hdw->cropcap_info);
304 if (stat == 0) {
305 /* Check was successful, so the data is no
306 longer considered stale. */
307 hdw->cropcap_stale = 0;
308 }
309 }
310 pvr2_i2c_client_cmd(cp, VIDIOC_G_TUNER, &hdw->tuner_signal_info);
311}
312
313
314/*
315 Stuff for Emacs to see, in order to encourage consistent editing style:
316 *** Local Variables: ***
317 *** mode: c ***
318 *** fill-column: 70 ***
319 *** tab-width: 8 ***
320 *** c-basic-offset: 8 ***
321 *** End: ***
322 */
diff --git a/drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.h b/drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.h
deleted file mode 100644
index eb744a20610d..000000000000
--- a/drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.h
+++ /dev/null
@@ -1,50 +0,0 @@
1/*
2 *
3 *
4 * Copyright (C) 2005 Mike Isely <isely@pobox.com>
5 * Copyright (C) 2004 Aurelien Alleaume <slts@free.fr>
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#ifndef __PVRUSB2_CMD_V4L2_H
23#define __PVRUSB2_CMD_V4L2_H
24
25#include "pvrusb2-i2c-core.h"
26
27extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_standard;
28extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_radio;
29extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_bcsh;
30extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_volume;
31extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_frequency;
32extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_crop;
33extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_size;
34extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_audiomode;
35extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_log;
36
37void pvr2_v4l2_cmd_stream(struct pvr2_i2c_client *,int);
38void pvr2_v4l2_cmd_status_poll(struct pvr2_i2c_client *);
39
40#endif /* __PVRUSB2_CMD_V4L2_H */
41
42/*
43 Stuff for Emacs to see, in order to encourage consistent editing style:
44 *** Local Variables: ***
45 *** mode: c ***
46 *** fill-column: 70 ***
47 *** tab-width: 8 ***
48 *** c-basic-offset: 8 ***
49 *** End: ***
50 */
diff --git a/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c b/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
index d6a35401fefb..9464862745fa 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
@@ -18,6 +18,7 @@
18 * 18 *
19 */ 19 */
20 20
21#include <linux/i2c.h>
21#include "pvrusb2-i2c-core.h" 22#include "pvrusb2-i2c-core.h"
22#include "pvrusb2-hdw-internal.h" 23#include "pvrusb2-hdw-internal.h"
23#include "pvrusb2-debug.h" 24#include "pvrusb2-debug.h"
@@ -29,8 +30,7 @@
29/* 30/*
30 31
31 This module attempts to implement a compliant I2C adapter for the pvrusb2 32 This module attempts to implement a compliant I2C adapter for the pvrusb2
32 device. By doing this we can then make use of existing functionality in 33 device.
33 V4L (e.g. tuner.c) rather than rolling our own.
34 34
35*/ 35*/
36 36
@@ -42,10 +42,6 @@ static int ir_mode[PVR_NUM] = { [0 ... PVR_NUM-1] = 1 };
42module_param_array(ir_mode, int, NULL, 0444); 42module_param_array(ir_mode, int, NULL, 0444);
43MODULE_PARM_DESC(ir_mode,"specify: 0=disable IR reception, 1=normal IR"); 43MODULE_PARM_DESC(ir_mode,"specify: 0=disable IR reception, 1=normal IR");
44 44
45static unsigned int pvr2_i2c_client_describe(struct pvr2_i2c_client *cp,
46 unsigned int detail,
47 char *buf,unsigned int maxlen);
48
49static int pvr2_i2c_write(struct pvr2_hdw *hdw, /* Context */ 45static int pvr2_i2c_write(struct pvr2_hdw *hdw, /* Context */
50 u8 i2c_addr, /* I2C address we're talking to */ 46 u8 i2c_addr, /* I2C address we're talking to */
51 u8 *data, /* Data to write */ 47 u8 *data, /* Data to write */
@@ -524,414 +520,13 @@ static u32 pvr2_i2c_functionality(struct i2c_adapter *adap)
524 return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_I2C; 520 return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_I2C;
525} 521}
526 522
527static int pvr2_i2c_core_singleton(struct i2c_client *cp,
528 unsigned int cmd,void *arg)
529{
530 int stat;
531 if (!cp) return -EINVAL;
532 if (!(cp->driver)) return -EINVAL;
533 if (!(cp->driver->command)) return -EINVAL;
534 if (!try_module_get(cp->driver->driver.owner)) return -EAGAIN;
535 stat = cp->driver->command(cp,cmd,arg);
536 module_put(cp->driver->driver.owner);
537 return stat;
538}
539
540int pvr2_i2c_client_cmd(struct pvr2_i2c_client *cp,unsigned int cmd,void *arg)
541{
542 int stat;
543 if (pvrusb2_debug & PVR2_TRACE_I2C_CMD) {
544 char buf[100];
545 unsigned int cnt;
546 cnt = pvr2_i2c_client_describe(cp,PVR2_I2C_DETAIL_DEBUG,
547 buf,sizeof(buf));
548 pvr2_trace(PVR2_TRACE_I2C_CMD,
549 "i2c COMMAND (code=%u 0x%x) to %.*s",
550 cmd,cmd,cnt,buf);
551 }
552 stat = pvr2_i2c_core_singleton(cp->client,cmd,arg);
553 if (pvrusb2_debug & PVR2_TRACE_I2C_CMD) {
554 char buf[100];
555 unsigned int cnt;
556 cnt = pvr2_i2c_client_describe(cp,PVR2_I2C_DETAIL_DEBUG,
557 buf,sizeof(buf));
558 pvr2_trace(PVR2_TRACE_I2C_CMD,
559 "i2c COMMAND to %.*s (ret=%d)",cnt,buf,stat);
560 }
561 return stat;
562}
563
564int pvr2_i2c_core_cmd(struct pvr2_hdw *hdw,unsigned int cmd,void *arg)
565{
566 struct pvr2_i2c_client *cp, *ncp;
567 int stat = -EINVAL;
568
569 if (!hdw) return stat;
570
571 mutex_lock(&hdw->i2c_list_lock);
572 list_for_each_entry_safe(cp, ncp, &hdw->i2c_clients, list) {
573 if (!cp->recv_enable) continue;
574 mutex_unlock(&hdw->i2c_list_lock);
575 stat = pvr2_i2c_client_cmd(cp,cmd,arg);
576 mutex_lock(&hdw->i2c_list_lock);
577 }
578 mutex_unlock(&hdw->i2c_list_lock);
579 return stat;
580}
581
582
583static int handler_check(struct pvr2_i2c_client *cp)
584{
585 struct pvr2_i2c_handler *hp = cp->handler;
586 if (!hp) return 0;
587 if (!hp->func_table->check) return 0;
588 return hp->func_table->check(hp->func_data) != 0;
589}
590
591#define BUFSIZE 500
592
593
594void pvr2_i2c_core_status_poll(struct pvr2_hdw *hdw)
595{
596 struct pvr2_i2c_client *cp;
597 mutex_lock(&hdw->i2c_list_lock); do {
598 struct v4l2_tuner *vtp = &hdw->tuner_signal_info;
599 memset(vtp,0,sizeof(*vtp));
600 list_for_each_entry(cp, &hdw->i2c_clients, list) {
601 if (!cp->detected_flag) continue;
602 if (!cp->status_poll) continue;
603 cp->status_poll(cp);
604 }
605 hdw->tuner_signal_stale = 0;
606 pvr2_trace(PVR2_TRACE_CHIPS,"i2c status poll"
607 " type=%u strength=%u audio=0x%x cap=0x%x"
608 " low=%u hi=%u",
609 vtp->type,
610 vtp->signal,vtp->rxsubchans,vtp->capability,
611 vtp->rangelow,vtp->rangehigh);
612 } while (0); mutex_unlock(&hdw->i2c_list_lock);
613}
614
615
616/* Issue various I2C operations to bring chip-level drivers into sync with
617 state stored in this driver. */
618void pvr2_i2c_core_sync(struct pvr2_hdw *hdw)
619{
620 unsigned long msk;
621 unsigned int idx;
622 struct pvr2_i2c_client *cp, *ncp;
623
624 if (!hdw->i2c_linked) return;
625 if (!(hdw->i2c_pend_types & PVR2_I2C_PEND_ALL)) {
626 return;
627 }
628 mutex_lock(&hdw->i2c_list_lock); do {
629 pvr2_trace(PVR2_TRACE_I2C_CORE,"i2c: core_sync BEGIN");
630 if (hdw->i2c_pend_types & PVR2_I2C_PEND_DETECT) {
631 /* One or more I2C clients have attached since we
632 last synced. So scan the list and identify the
633 new clients. */
634 char *buf;
635 unsigned int cnt;
636 unsigned long amask = 0;
637 buf = kmalloc(BUFSIZE,GFP_KERNEL);
638 pvr2_trace(PVR2_TRACE_I2C_CORE,"i2c: PEND_DETECT");
639 hdw->i2c_pend_types &= ~PVR2_I2C_PEND_DETECT;
640 list_for_each_entry(cp, &hdw->i2c_clients, list) {
641 if (!cp->detected_flag) {
642 cp->ctl_mask = 0;
643 pvr2_i2c_probe(hdw,cp);
644 cp->detected_flag = !0;
645 msk = cp->ctl_mask;
646 cnt = 0;
647 if (buf) {
648 cnt = pvr2_i2c_client_describe(
649 cp,
650 PVR2_I2C_DETAIL_ALL,
651 buf,BUFSIZE);
652 }
653 trace_i2c("Probed: %.*s",cnt,buf);
654 if (handler_check(cp)) {
655 hdw->i2c_pend_types |=
656 PVR2_I2C_PEND_CLIENT;
657 }
658 cp->pend_mask = msk;
659 hdw->i2c_pend_mask |= msk;
660 hdw->i2c_pend_types |=
661 PVR2_I2C_PEND_REFRESH;
662 }
663 amask |= cp->ctl_mask;
664 }
665 hdw->i2c_active_mask = amask;
666 if (buf) kfree(buf);
667 }
668 if (hdw->i2c_pend_types & PVR2_I2C_PEND_STALE) {
669 /* Need to do one or more global updates. Arrange
670 for this to happen. */
671 unsigned long m2;
672 pvr2_trace(PVR2_TRACE_I2C_CORE,
673 "i2c: PEND_STALE (0x%lx)",
674 hdw->i2c_stale_mask);
675 hdw->i2c_pend_types &= ~PVR2_I2C_PEND_STALE;
676 list_for_each_entry(cp, &hdw->i2c_clients, list) {
677 m2 = hdw->i2c_stale_mask;
678 m2 &= cp->ctl_mask;
679 m2 &= ~cp->pend_mask;
680 if (m2) {
681 pvr2_trace(PVR2_TRACE_I2C_CORE,
682 "i2c: cp=%p setting 0x%lx",
683 cp,m2);
684 cp->pend_mask |= m2;
685 }
686 }
687 hdw->i2c_pend_mask |= hdw->i2c_stale_mask;
688 hdw->i2c_stale_mask = 0;
689 hdw->i2c_pend_types |= PVR2_I2C_PEND_REFRESH;
690 }
691 if (hdw->i2c_pend_types & PVR2_I2C_PEND_CLIENT) {
692 /* One or more client handlers are asking for an
693 update. Run through the list of known clients
694 and update each one. */
695 pvr2_trace(PVR2_TRACE_I2C_CORE,"i2c: PEND_CLIENT");
696 hdw->i2c_pend_types &= ~PVR2_I2C_PEND_CLIENT;
697 list_for_each_entry_safe(cp, ncp, &hdw->i2c_clients,
698 list) {
699 if (!cp->handler) continue;
700 if (!cp->handler->func_table->update) continue;
701 pvr2_trace(PVR2_TRACE_I2C_CORE,
702 "i2c: cp=%p update",cp);
703 mutex_unlock(&hdw->i2c_list_lock);
704 cp->handler->func_table->update(
705 cp->handler->func_data);
706 mutex_lock(&hdw->i2c_list_lock);
707 /* If client's update function set some
708 additional pending bits, account for that
709 here. */
710 if (cp->pend_mask & ~hdw->i2c_pend_mask) {
711 hdw->i2c_pend_mask |= cp->pend_mask;
712 hdw->i2c_pend_types |=
713 PVR2_I2C_PEND_REFRESH;
714 }
715 }
716 }
717 if (hdw->i2c_pend_types & PVR2_I2C_PEND_REFRESH) {
718 const struct pvr2_i2c_op *opf;
719 unsigned long pm;
720 /* Some actual updates are pending. Walk through
721 each update type and perform it. */
722 pvr2_trace(PVR2_TRACE_I2C_CORE,"i2c: PEND_REFRESH"
723 " (0x%lx)",hdw->i2c_pend_mask);
724 hdw->i2c_pend_types &= ~PVR2_I2C_PEND_REFRESH;
725 pm = hdw->i2c_pend_mask;
726 hdw->i2c_pend_mask = 0;
727 for (idx = 0, msk = 1; pm; idx++, msk <<= 1) {
728 if (!(pm & msk)) continue;
729 pm &= ~msk;
730 list_for_each_entry(cp, &hdw->i2c_clients,
731 list) {
732 if (cp->pend_mask & msk) {
733 cp->pend_mask &= ~msk;
734 cp->recv_enable = !0;
735 } else {
736 cp->recv_enable = 0;
737 }
738 }
739 opf = pvr2_i2c_get_op(idx);
740 if (!opf) continue;
741 mutex_unlock(&hdw->i2c_list_lock);
742 opf->update(hdw);
743 mutex_lock(&hdw->i2c_list_lock);
744 }
745 }
746 pvr2_trace(PVR2_TRACE_I2C_CORE,"i2c: core_sync END");
747 } while (0); mutex_unlock(&hdw->i2c_list_lock);
748}
749
750int pvr2_i2c_core_check_stale(struct pvr2_hdw *hdw)
751{
752 unsigned long msk,sm,pm;
753 unsigned int idx;
754 const struct pvr2_i2c_op *opf;
755 struct pvr2_i2c_client *cp;
756 unsigned int pt = 0;
757
758 pvr2_trace(PVR2_TRACE_I2C_CORE,"pvr2_i2c_core_check_stale BEGIN");
759
760 pm = hdw->i2c_active_mask;
761 sm = 0;
762 for (idx = 0, msk = 1; pm; idx++, msk <<= 1) {
763 if (!(msk & pm)) continue;
764 pm &= ~msk;
765 opf = pvr2_i2c_get_op(idx);
766 if (!opf) continue;
767 if (opf->check(hdw)) {
768 sm |= msk;
769 }
770 }
771 if (sm) pt |= PVR2_I2C_PEND_STALE;
772
773 list_for_each_entry(cp, &hdw->i2c_clients, list)
774 if (handler_check(cp))
775 pt |= PVR2_I2C_PEND_CLIENT;
776
777 if (pt) {
778 mutex_lock(&hdw->i2c_list_lock); do {
779 hdw->i2c_pend_types |= pt;
780 hdw->i2c_stale_mask |= sm;
781 hdw->i2c_pend_mask |= hdw->i2c_stale_mask;
782 } while (0); mutex_unlock(&hdw->i2c_list_lock);
783 }
784
785 pvr2_trace(PVR2_TRACE_I2C_CORE,
786 "i2c: types=0x%x stale=0x%lx pend=0x%lx",
787 hdw->i2c_pend_types,
788 hdw->i2c_stale_mask,
789 hdw->i2c_pend_mask);
790 pvr2_trace(PVR2_TRACE_I2C_CORE,"pvr2_i2c_core_check_stale END");
791
792 return (hdw->i2c_pend_types & PVR2_I2C_PEND_ALL) != 0;
793}
794
795static unsigned int pvr2_i2c_client_describe(struct pvr2_i2c_client *cp,
796 unsigned int detail,
797 char *buf,unsigned int maxlen)
798{
799 unsigned int ccnt,bcnt;
800 int spcfl = 0;
801 const struct pvr2_i2c_op *opf;
802
803 ccnt = 0;
804 if (detail & PVR2_I2C_DETAIL_DEBUG) {
805 bcnt = scnprintf(buf,maxlen,
806 "ctxt=%p ctl_mask=0x%lx",
807 cp,cp->ctl_mask);
808 ccnt += bcnt; buf += bcnt; maxlen -= bcnt;
809 spcfl = !0;
810 }
811 bcnt = scnprintf(buf,maxlen,
812 "%s%s @ 0x%x",
813 (spcfl ? " " : ""),
814 cp->client->name,
815 cp->client->addr);
816 ccnt += bcnt; buf += bcnt; maxlen -= bcnt;
817 if ((detail & PVR2_I2C_DETAIL_HANDLER) &&
818 cp->handler && cp->handler->func_table->describe) {
819 bcnt = scnprintf(buf,maxlen," (");
820 ccnt += bcnt; buf += bcnt; maxlen -= bcnt;
821 bcnt = cp->handler->func_table->describe(
822 cp->handler->func_data,buf,maxlen);
823 ccnt += bcnt; buf += bcnt; maxlen -= bcnt;
824 bcnt = scnprintf(buf,maxlen,")");
825 ccnt += bcnt; buf += bcnt; maxlen -= bcnt;
826 }
827 if ((detail & PVR2_I2C_DETAIL_CTLMASK) && cp->ctl_mask) {
828 unsigned int idx;
829 unsigned long msk,sm;
830
831 bcnt = scnprintf(buf,maxlen," [");
832 ccnt += bcnt; buf += bcnt; maxlen -= bcnt;
833 sm = 0;
834 spcfl = 0;
835 for (idx = 0, msk = 1; msk; idx++, msk <<= 1) {
836 if (!(cp->ctl_mask & msk)) continue;
837 opf = pvr2_i2c_get_op(idx);
838 if (opf) {
839 bcnt = scnprintf(buf,maxlen,"%s%s",
840 spcfl ? " " : "",
841 opf->name);
842 ccnt += bcnt; buf += bcnt; maxlen -= bcnt;
843 spcfl = !0;
844 } else {
845 sm |= msk;
846 }
847 }
848 if (sm) {
849 bcnt = scnprintf(buf,maxlen,"%s%lx",
850 idx != 0 ? " " : "",sm);
851 ccnt += bcnt; buf += bcnt; maxlen -= bcnt;
852 }
853 bcnt = scnprintf(buf,maxlen,"]");
854 ccnt += bcnt; buf += bcnt; maxlen -= bcnt;
855 }
856 return ccnt;
857}
858
859unsigned int pvr2_i2c_report(struct pvr2_hdw *hdw,
860 char *buf,unsigned int maxlen)
861{
862 unsigned int ccnt,bcnt;
863 struct pvr2_i2c_client *cp;
864 ccnt = 0;
865 mutex_lock(&hdw->i2c_list_lock); do {
866 list_for_each_entry(cp, &hdw->i2c_clients, list) {
867 bcnt = pvr2_i2c_client_describe(
868 cp,
869 (PVR2_I2C_DETAIL_HANDLER|
870 PVR2_I2C_DETAIL_CTLMASK),
871 buf,maxlen);
872 ccnt += bcnt; buf += bcnt; maxlen -= bcnt;
873 bcnt = scnprintf(buf,maxlen,"\n");
874 ccnt += bcnt; buf += bcnt; maxlen -= bcnt;
875 }
876 } while (0); mutex_unlock(&hdw->i2c_list_lock);
877 return ccnt;
878}
879
880static int pvr2_i2c_attach_inform(struct i2c_client *client) 523static int pvr2_i2c_attach_inform(struct i2c_client *client)
881{ 524{
882 struct pvr2_hdw *hdw = (struct pvr2_hdw *)(client->adapter->algo_data);
883 struct pvr2_i2c_client *cp;
884 int fl = !(hdw->i2c_pend_types & PVR2_I2C_PEND_ALL);
885 cp = kzalloc(sizeof(*cp),GFP_KERNEL);
886 trace_i2c("i2c_attach [client=%s @ 0x%x ctxt=%p]",
887 client->name,
888 client->addr,cp);
889 if (!cp) return -ENOMEM;
890 cp->hdw = hdw;
891 INIT_LIST_HEAD(&cp->list);
892 cp->client = client;
893 mutex_lock(&hdw->i2c_list_lock); do {
894 hdw->cropcap_stale = !0;
895 list_add_tail(&cp->list,&hdw->i2c_clients);
896 hdw->i2c_pend_types |= PVR2_I2C_PEND_DETECT;
897 } while (0); mutex_unlock(&hdw->i2c_list_lock);
898 if (fl) queue_work(hdw->workqueue,&hdw->worki2csync);
899 return 0; 525 return 0;
900} 526}
901 527
902static int pvr2_i2c_detach_inform(struct i2c_client *client) 528static int pvr2_i2c_detach_inform(struct i2c_client *client)
903{ 529{
904 struct pvr2_hdw *hdw = (struct pvr2_hdw *)(client->adapter->algo_data);
905 struct pvr2_i2c_client *cp, *ncp;
906 unsigned long amask = 0;
907 int foundfl = 0;
908 mutex_lock(&hdw->i2c_list_lock); do {
909 hdw->cropcap_stale = !0;
910 list_for_each_entry_safe(cp, ncp, &hdw->i2c_clients, list) {
911 if (cp->client == client) {
912 trace_i2c("pvr2_i2c_detach"
913 " [client=%s @ 0x%x ctxt=%p]",
914 client->name,
915 client->addr,cp);
916 if (cp->handler &&
917 cp->handler->func_table->detach) {
918 cp->handler->func_table->detach(
919 cp->handler->func_data);
920 }
921 list_del(&cp->list);
922 kfree(cp);
923 foundfl = !0;
924 continue;
925 }
926 amask |= cp->ctl_mask;
927 }
928 hdw->i2c_active_mask = amask;
929 } while (0); mutex_unlock(&hdw->i2c_list_lock);
930 if (!foundfl) {
931 trace_i2c("pvr2_i2c_detach [client=%s @ 0x%x ctxt=<unknown>]",
932 client->name,
933 client->addr);
934 }
935 return 0; 530 return 0;
936} 531}
937 532
@@ -942,7 +537,7 @@ static struct i2c_algorithm pvr2_i2c_algo_template = {
942 537
943static struct i2c_adapter pvr2_i2c_adap_template = { 538static struct i2c_adapter pvr2_i2c_adap_template = {
944 .owner = THIS_MODULE, 539 .owner = THIS_MODULE,
945 .class = I2C_CLASS_TV_ANALOG, 540 .class = 0,
946 .id = I2C_HW_B_BT848, 541 .id = I2C_HW_B_BT848,
947 .client_register = pvr2_i2c_attach_inform, 542 .client_register = pvr2_i2c_attach_inform,
948 .client_unregister = pvr2_i2c_detach_inform, 543 .client_unregister = pvr2_i2c_detach_inform,
@@ -1009,12 +604,8 @@ void pvr2_i2c_core_init(struct pvr2_hdw *hdw)
1009 hdw->i2c_adap.dev.parent = &hdw->usb_dev->dev; 604 hdw->i2c_adap.dev.parent = &hdw->usb_dev->dev;
1010 hdw->i2c_adap.algo = &hdw->i2c_algo; 605 hdw->i2c_adap.algo = &hdw->i2c_algo;
1011 hdw->i2c_adap.algo_data = hdw; 606 hdw->i2c_adap.algo_data = hdw;
1012 hdw->i2c_pend_mask = 0;
1013 hdw->i2c_stale_mask = 0;
1014 hdw->i2c_active_mask = 0;
1015 INIT_LIST_HEAD(&hdw->i2c_clients);
1016 mutex_init(&hdw->i2c_list_lock);
1017 hdw->i2c_linked = !0; 607 hdw->i2c_linked = !0;
608 i2c_set_adapdata(&hdw->i2c_adap, &hdw->v4l2_dev);
1018 i2c_add_adapter(&hdw->i2c_adap); 609 i2c_add_adapter(&hdw->i2c_adap);
1019 if (hdw->i2c_func[0x18] == i2c_24xxx_ir) { 610 if (hdw->i2c_func[0x18] == i2c_24xxx_ir) {
1020 /* Probe for a different type of IR receiver on this 611 /* Probe for a different type of IR receiver on this
diff --git a/drivers/media/video/pvrusb2/pvrusb2-i2c-core.h b/drivers/media/video/pvrusb2/pvrusb2-i2c-core.h
index 6ef7a1c0e935..6a75769200bd 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-i2c-core.h
+++ b/drivers/media/video/pvrusb2/pvrusb2-i2c-core.h
@@ -20,68 +20,13 @@
20#ifndef __PVRUSB2_I2C_CORE_H 20#ifndef __PVRUSB2_I2C_CORE_H
21#define __PVRUSB2_I2C_CORE_H 21#define __PVRUSB2_I2C_CORE_H
22 22
23#include <linux/list.h>
24#include <linux/i2c.h>
25
26struct pvr2_hdw; 23struct pvr2_hdw;
27struct pvr2_i2c_client;
28struct pvr2_i2c_handler;
29struct pvr2_i2c_handler_functions;
30struct pvr2_i2c_op;
31struct pvr2_i2c_op_functions;
32
33struct pvr2_i2c_client {
34 struct i2c_client *client;
35 struct pvr2_i2c_handler *handler;
36 struct list_head list;
37 struct pvr2_hdw *hdw;
38 int detected_flag;
39 int recv_enable;
40 unsigned long pend_mask;
41 unsigned long ctl_mask;
42 void (*status_poll)(struct pvr2_i2c_client *);
43};
44
45struct pvr2_i2c_handler {
46 void *func_data;
47 const struct pvr2_i2c_handler_functions *func_table;
48};
49
50struct pvr2_i2c_handler_functions {
51 void (*detach)(void *);
52 int (*check)(void *);
53 void (*update)(void *);
54 unsigned int (*describe)(void *,char *,unsigned int);
55};
56
57struct pvr2_i2c_op {
58 int (*check)(struct pvr2_hdw *);
59 void (*update)(struct pvr2_hdw *);
60 const char *name;
61};
62 24
63void pvr2_i2c_core_init(struct pvr2_hdw *); 25void pvr2_i2c_core_init(struct pvr2_hdw *);
64void pvr2_i2c_core_done(struct pvr2_hdw *); 26void pvr2_i2c_core_done(struct pvr2_hdw *);
65 27
66int pvr2_i2c_client_cmd(struct pvr2_i2c_client *,unsigned int cmd,void *arg);
67int pvr2_i2c_core_cmd(struct pvr2_hdw *,unsigned int cmd,void *arg);
68
69int pvr2_i2c_core_check_stale(struct pvr2_hdw *);
70void pvr2_i2c_core_sync(struct pvr2_hdw *);
71void pvr2_i2c_core_status_poll(struct pvr2_hdw *);
72unsigned int pvr2_i2c_report(struct pvr2_hdw *,char *buf,unsigned int maxlen);
73#define PVR2_I2C_DETAIL_DEBUG 0x0001
74#define PVR2_I2C_DETAIL_HANDLER 0x0002
75#define PVR2_I2C_DETAIL_CTLMASK 0x0004
76#define PVR2_I2C_DETAIL_ALL (\
77 PVR2_I2C_DETAIL_DEBUG |\
78 PVR2_I2C_DETAIL_HANDLER |\
79 PVR2_I2C_DETAIL_CTLMASK)
80
81void pvr2_i2c_probe(struct pvr2_hdw *,struct pvr2_i2c_client *);
82const struct pvr2_i2c_op *pvr2_i2c_get_op(unsigned int idx);
83 28
84#endif /* __PVRUSB2_I2C_CORE_H */ 29#endif /* __PVRUSB2_I2C_ADAPTER_H */
85 30
86 31
87/* 32/*
diff --git a/drivers/media/video/pvrusb2/pvrusb2-main.c b/drivers/media/video/pvrusb2/pvrusb2-main.c
index 9b3c874d96d6..8689ddb54420 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-main.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-main.c
@@ -137,10 +137,10 @@ static int __init pvr_init(void)
137 ret = usb_register(&pvr_driver); 137 ret = usb_register(&pvr_driver);
138 138
139 if (ret == 0) 139 if (ret == 0)
140 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":" 140 printk(KERN_INFO "pvrusb2: " DRIVER_VERSION ":"
141 DRIVER_DESC "\n"); 141 DRIVER_DESC "\n");
142 if (pvrusb2_debug) 142 if (pvrusb2_debug)
143 printk(KERN_INFO KBUILD_MODNAME ": Debug mask is %d (0x%x)\n", 143 printk(KERN_INFO "pvrusb2: Debug mask is %d (0x%x)\n",
144 pvrusb2_debug,pvrusb2_debug); 144 pvrusb2_debug,pvrusb2_debug);
145 145
146 pvr2_trace(PVR2_TRACE_INIT,"pvr_init complete"); 146 pvr2_trace(PVR2_TRACE_INIT,"pvr_init complete");
diff --git a/drivers/media/video/pvrusb2/pvrusb2-sysfs.c b/drivers/media/video/pvrusb2/pvrusb2-sysfs.c
index e641cd971453..e20ba1e6e0ea 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-sysfs.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-sysfs.c
@@ -627,16 +627,8 @@ static void class_dev_create(struct pvr2_sysfs *sfp,
627 pvr2_sysfs_trace("Creating class_dev id=%p",class_dev); 627 pvr2_sysfs_trace("Creating class_dev id=%p",class_dev);
628 628
629 class_dev->class = &class_ptr->class; 629 class_dev->class = &class_ptr->class;
630 if (pvr2_hdw_get_sn(sfp->channel.hdw)) { 630 dev_set_name(class_dev, "%s",
631 dev_set_name(class_dev, "sn-%lu", 631 pvr2_hdw_get_device_identifier(sfp->channel.hdw));
632 pvr2_hdw_get_sn(sfp->channel.hdw));
633 } else if (pvr2_hdw_get_unit_number(sfp->channel.hdw) >= 0) {
634 dev_set_name(class_dev, "unit-%c",
635 pvr2_hdw_get_unit_number(sfp->channel.hdw) + 'a');
636 } else {
637 kfree(class_dev);
638 return;
639 }
640 632
641 class_dev->parent = &usb_dev->dev; 633 class_dev->parent = &usb_dev->dev;
642 634
diff --git a/drivers/media/video/pvrusb2/pvrusb2-tuner.c b/drivers/media/video/pvrusb2/pvrusb2-tuner.c
deleted file mode 100644
index 07775d1aad4e..000000000000
--- a/drivers/media/video/pvrusb2/pvrusb2-tuner.c
+++ /dev/null
@@ -1,120 +0,0 @@
1/*
2 *
3 *
4 * Copyright (C) 2005 Mike Isely <isely@pobox.com>
5 * Copyright (C) 2004 Aurelien Alleaume <slts@free.fr>
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#include "pvrusb2.h"
23#include "pvrusb2-util.h"
24#include "pvrusb2-tuner.h"
25#include "pvrusb2-hdw-internal.h"
26#include "pvrusb2-debug.h"
27#include <linux/videodev2.h>
28#include <media/tuner.h>
29#include <media/v4l2-common.h>
30
31struct pvr2_tuner_handler {
32 struct pvr2_hdw *hdw;
33 struct pvr2_i2c_client *client;
34 struct pvr2_i2c_handler i2c_handler;
35 int type_update_fl;
36};
37
38
39static void set_type(struct pvr2_tuner_handler *ctxt)
40{
41 struct pvr2_hdw *hdw = ctxt->hdw;
42 struct tuner_setup setup;
43 pvr2_trace(PVR2_TRACE_CHIPS,"i2c tuner set_type(%d)",hdw->tuner_type);
44 if (((int)(hdw->tuner_type)) < 0) return;
45
46 setup.addr = ADDR_UNSET;
47 setup.type = hdw->tuner_type;
48 setup.mode_mask = T_RADIO | T_ANALOG_TV;
49 /* We may really want mode_mask to be T_ANALOG_TV for now */
50 pvr2_i2c_client_cmd(ctxt->client,TUNER_SET_TYPE_ADDR,&setup);
51 ctxt->type_update_fl = 0;
52}
53
54
55static int tuner_check(struct pvr2_tuner_handler *ctxt)
56{
57 struct pvr2_hdw *hdw = ctxt->hdw;
58 if (hdw->tuner_updated) ctxt->type_update_fl = !0;
59 return ctxt->type_update_fl != 0;
60}
61
62
63static void tuner_update(struct pvr2_tuner_handler *ctxt)
64{
65 if (ctxt->type_update_fl) set_type(ctxt);
66}
67
68
69static void pvr2_tuner_detach(struct pvr2_tuner_handler *ctxt)
70{
71 ctxt->client->handler = NULL;
72 kfree(ctxt);
73}
74
75
76static unsigned int pvr2_tuner_describe(struct pvr2_tuner_handler *ctxt,char *buf,unsigned int cnt)
77{
78 return scnprintf(buf,cnt,"handler: pvrusb2-tuner");
79}
80
81
82static const struct pvr2_i2c_handler_functions tuner_funcs = {
83 .detach = (void (*)(void *))pvr2_tuner_detach,
84 .check = (int (*)(void *))tuner_check,
85 .update = (void (*)(void *))tuner_update,
86 .describe = (unsigned int (*)(void *,char *,unsigned int))pvr2_tuner_describe,
87};
88
89
90int pvr2_i2c_tuner_setup(struct pvr2_hdw *hdw,struct pvr2_i2c_client *cp)
91{
92 struct pvr2_tuner_handler *ctxt;
93 if (cp->handler) return 0;
94
95 ctxt = kzalloc(sizeof(*ctxt),GFP_KERNEL);
96 if (!ctxt) return 0;
97
98 ctxt->i2c_handler.func_data = ctxt;
99 ctxt->i2c_handler.func_table = &tuner_funcs;
100 ctxt->type_update_fl = !0;
101 ctxt->client = cp;
102 ctxt->hdw = hdw;
103 cp->handler = &ctxt->i2c_handler;
104 pvr2_trace(PVR2_TRACE_CHIPS,"i2c 0x%x tuner handler set up",
105 cp->client->addr);
106 return !0;
107}
108
109
110
111
112/*
113 Stuff for Emacs to see, in order to encourage consistent editing style:
114 *** Local Variables: ***
115 *** mode: c ***
116 *** fill-column: 70 ***
117 *** tab-width: 8 ***
118 *** c-basic-offset: 8 ***
119 *** End: ***
120 */
diff --git a/drivers/media/video/pvrusb2/pvrusb2-v4l2.c b/drivers/media/video/pvrusb2/pvrusb2-v4l2.c
index 878fd52a73b3..9e0f2b07b93b 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-v4l2.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-v4l2.c
@@ -91,7 +91,7 @@ static struct v4l2_capability pvr_capability ={
91 .card = "Hauppauge WinTV pvr-usb2", 91 .card = "Hauppauge WinTV pvr-usb2",
92 .bus_info = "usb", 92 .bus_info = "usb",
93 .version = KERNEL_VERSION(0,8,0), 93 .version = KERNEL_VERSION(0,8,0),
94 .capabilities = (V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VBI_CAPTURE | 94 .capabilities = (V4L2_CAP_VIDEO_CAPTURE |
95 V4L2_CAP_TUNER | V4L2_CAP_AUDIO | V4L2_CAP_RADIO | 95 V4L2_CAP_TUNER | V4L2_CAP_AUDIO | V4L2_CAP_RADIO |
96 V4L2_CAP_READWRITE), 96 V4L2_CAP_READWRITE),
97 .reserved = {0,0,0,0} 97 .reserved = {0,0,0,0}
@@ -952,10 +952,6 @@ static long pvr2_v4l2_ioctl(struct file *file,
952 unsigned int cmd, unsigned long arg) 952 unsigned int cmd, unsigned long arg)
953{ 953{
954 954
955/* Temporary hack : use ivtv api until a v4l2 one is available. */
956#define IVTV_IOC_G_CODEC 0xFFEE7703
957#define IVTV_IOC_S_CODEC 0xFFEE7704
958 if (cmd == IVTV_IOC_G_CODEC || cmd == IVTV_IOC_S_CODEC) return 0;
959 return video_usercopy(file, cmd, arg, pvr2_v4l2_do_ioctl); 955 return video_usercopy(file, cmd, arg, pvr2_v4l2_do_ioctl);
960} 956}
961 957
@@ -1268,8 +1264,9 @@ static void pvr2_v4l2_dev_init(struct pvr2_v4l2_dev *dip,
1268 dip->minor_type = pvr2_v4l_type_video; 1264 dip->minor_type = pvr2_v4l_type_video;
1269 nr_ptr = video_nr; 1265 nr_ptr = video_nr;
1270 if (!dip->stream) { 1266 if (!dip->stream) {
1271 err("Failed to set up pvrusb2 v4l video dev" 1267 pr_err(KBUILD_MODNAME
1272 " due to missing stream instance"); 1268 ": Failed to set up pvrusb2 v4l video dev"
1269 " due to missing stream instance\n");
1273 return; 1270 return;
1274 } 1271 }
1275 break; 1272 break;
@@ -1286,8 +1283,8 @@ static void pvr2_v4l2_dev_init(struct pvr2_v4l2_dev *dip,
1286 break; 1283 break;
1287 default: 1284 default:
1288 /* Bail out (this should be impossible) */ 1285 /* Bail out (this should be impossible) */
1289 err("Failed to set up pvrusb2 v4l dev" 1286 pr_err(KBUILD_MODNAME ": Failed to set up pvrusb2 v4l dev"
1290 " due to unrecognized config"); 1287 " due to unrecognized config\n");
1291 return; 1288 return;
1292 } 1289 }
1293 1290
@@ -1303,7 +1300,8 @@ static void pvr2_v4l2_dev_init(struct pvr2_v4l2_dev *dip,
1303 dip->v4l_type, mindevnum) < 0) && 1300 dip->v4l_type, mindevnum) < 0) &&
1304 (video_register_device(&dip->devbase, 1301 (video_register_device(&dip->devbase,
1305 dip->v4l_type, -1) < 0)) { 1302 dip->v4l_type, -1) < 0)) {
1306 err("Failed to register pvrusb2 v4l device"); 1303 pr_err(KBUILD_MODNAME
1304 ": Failed to register pvrusb2 v4l device\n");
1307 } 1305 }
1308 1306
1309 printk(KERN_INFO "pvrusb2: registered device %s%u [%s]\n", 1307 printk(KERN_INFO "pvrusb2: registered device %s%u [%s]\n",
diff --git a/drivers/media/video/pvrusb2/pvrusb2-video-v4l.c b/drivers/media/video/pvrusb2/pvrusb2-video-v4l.c
index 4059648c7056..b3862f5554bd 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-video-v4l.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-video-v4l.c
@@ -28,7 +28,7 @@
28*/ 28*/
29 29
30#include "pvrusb2-video-v4l.h" 30#include "pvrusb2-video-v4l.h"
31#include "pvrusb2-i2c-cmd-v4l2.h" 31
32 32
33 33
34#include "pvrusb2-hdw-internal.h" 34#include "pvrusb2-hdw-internal.h"
@@ -39,15 +39,6 @@
39#include <linux/errno.h> 39#include <linux/errno.h>
40#include <linux/slab.h> 40#include <linux/slab.h>
41 41
42struct pvr2_v4l_decoder {
43 struct pvr2_i2c_handler handler;
44 struct pvr2_decoder_ctrl ctrl;
45 struct pvr2_i2c_client *client;
46 struct pvr2_hdw *hdw;
47 unsigned long stale_mask;
48};
49
50
51struct routing_scheme { 42struct routing_scheme {
52 const int *def; 43 const int *def;
53 unsigned int cnt; 44 unsigned int cnt;
@@ -63,190 +54,51 @@ static const int routing_scheme0[] = {
63 [PVR2_CVAL_INPUT_SVIDEO] = SAA7115_SVIDEO2, 54 [PVR2_CVAL_INPUT_SVIDEO] = SAA7115_SVIDEO2,
64}; 55};
65 56
57static const int routing_scheme1[] = {
58 [PVR2_CVAL_INPUT_TV] = SAA7115_COMPOSITE4,
59 [PVR2_CVAL_INPUT_RADIO] = SAA7115_COMPOSITE5,
60 [PVR2_CVAL_INPUT_COMPOSITE] = SAA7115_COMPOSITE3,
61 [PVR2_CVAL_INPUT_SVIDEO] = SAA7115_SVIDEO2, /* or SVIDEO0, it seems */
62};
63
66static const struct routing_scheme routing_schemes[] = { 64static const struct routing_scheme routing_schemes[] = {
67 [PVR2_ROUTING_SCHEME_HAUPPAUGE] = { 65 [PVR2_ROUTING_SCHEME_HAUPPAUGE] = {
68 .def = routing_scheme0, 66 .def = routing_scheme0,
69 .cnt = ARRAY_SIZE(routing_scheme0), 67 .cnt = ARRAY_SIZE(routing_scheme0),
70 }, 68 },
69 [PVR2_ROUTING_SCHEME_ONAIR] = {
70 .def = routing_scheme1,
71 .cnt = ARRAY_SIZE(routing_scheme1),
72 },
71}; 73};
72 74
73static void set_input(struct pvr2_v4l_decoder *ctxt) 75void pvr2_saa7115_subdev_update(struct pvr2_hdw *hdw, struct v4l2_subdev *sd)
74{
75 struct pvr2_hdw *hdw = ctxt->hdw;
76 struct v4l2_routing route;
77 const struct routing_scheme *sp;
78 unsigned int sid = hdw->hdw_desc->signal_routing_scheme;
79
80 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_input(%d)",hdw->input_val);
81
82 if ((sid < ARRAY_SIZE(routing_schemes)) &&
83 ((sp = routing_schemes + sid) != NULL) &&
84 (hdw->input_val >= 0) &&
85 (hdw->input_val < sp->cnt)) {
86 route.input = sp->def[hdw->input_val];
87 } else {
88 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
89 "*** WARNING *** i2c v4l2 set_input:"
90 " Invalid routing scheme (%u) and/or input (%d)",
91 sid,hdw->input_val);
92 return;
93 }
94
95 route.output = 0;
96 pvr2_i2c_client_cmd(ctxt->client,VIDIOC_INT_S_VIDEO_ROUTING,&route);
97}
98
99
100static int check_input(struct pvr2_v4l_decoder *ctxt)
101{
102 struct pvr2_hdw *hdw = ctxt->hdw;
103 return hdw->input_dirty != 0;
104}
105
106
107static void set_audio(struct pvr2_v4l_decoder *ctxt)
108{
109 u32 val;
110 struct pvr2_hdw *hdw = ctxt->hdw;
111
112 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_audio %d",
113 hdw->srate_val);
114 switch (hdw->srate_val) {
115 default:
116 case V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000:
117 val = 48000;
118 break;
119 case V4L2_MPEG_AUDIO_SAMPLING_FREQ_44100:
120 val = 44100;
121 break;
122 case V4L2_MPEG_AUDIO_SAMPLING_FREQ_32000:
123 val = 32000;
124 break;
125 }
126 pvr2_i2c_client_cmd(ctxt->client,VIDIOC_INT_AUDIO_CLOCK_FREQ,&val);
127}
128
129
130static int check_audio(struct pvr2_v4l_decoder *ctxt)
131{
132 struct pvr2_hdw *hdw = ctxt->hdw;
133 return hdw->srate_dirty != 0;
134}
135
136
137struct pvr2_v4l_decoder_ops {
138 void (*update)(struct pvr2_v4l_decoder *);
139 int (*check)(struct pvr2_v4l_decoder *);
140};
141
142
143static const struct pvr2_v4l_decoder_ops decoder_ops[] = {
144 { .update = set_input, .check = check_input},
145 { .update = set_audio, .check = check_audio},
146};
147
148
149static void decoder_detach(struct pvr2_v4l_decoder *ctxt)
150{ 76{
151 ctxt->client->handler = NULL; 77 if (hdw->input_dirty || hdw->force_dirty) {
152 pvr2_hdw_set_decoder(ctxt->hdw,NULL); 78 struct v4l2_routing route;
153 kfree(ctxt); 79 const struct routing_scheme *sp;
154} 80 unsigned int sid = hdw->hdw_desc->signal_routing_scheme;
155 81 pvr2_trace(PVR2_TRACE_CHIPS, "subdev v4l2 set_input(%d)",
156 82 hdw->input_val);
157static int decoder_check(struct pvr2_v4l_decoder *ctxt) 83 if ((sid < ARRAY_SIZE(routing_schemes)) &&
158{ 84 ((sp = routing_schemes + sid) != NULL) &&
159 unsigned long msk; 85 (hdw->input_val >= 0) &&
160 unsigned int idx; 86 (hdw->input_val < sp->cnt)) {
161 87 route.input = sp->def[hdw->input_val];
162 for (idx = 0; idx < ARRAY_SIZE(decoder_ops); idx++) { 88 } else {
163 msk = 1 << idx; 89 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
164 if (ctxt->stale_mask & msk) continue; 90 "*** WARNING *** subdev v4l2 set_input:"
165 if (decoder_ops[idx].check(ctxt)) { 91 " Invalid routing scheme (%u)"
166 ctxt->stale_mask |= msk; 92 " and/or input (%d)",
93 sid, hdw->input_val);
94 return;
167 } 95 }
96 route.output = 0;
97 sd->ops->video->s_routing(sd, &route);
168 } 98 }
169 return ctxt->stale_mask != 0;
170}
171
172
173static void decoder_update(struct pvr2_v4l_decoder *ctxt)
174{
175 unsigned long msk;
176 unsigned int idx;
177
178 for (idx = 0; idx < ARRAY_SIZE(decoder_ops); idx++) {
179 msk = 1 << idx;
180 if (!(ctxt->stale_mask & msk)) continue;
181 ctxt->stale_mask &= ~msk;
182 decoder_ops[idx].update(ctxt);
183 }
184}
185
186
187static int decoder_detect(struct pvr2_i2c_client *cp)
188{
189 /* Attempt to query the decoder - let's see if it will answer */
190 struct v4l2_tuner vt;
191 int ret;
192
193 memset(&vt,0,sizeof(vt));
194 ret = pvr2_i2c_client_cmd(cp,VIDIOC_G_TUNER,&vt);
195 return ret == 0; /* Return true if it answered */
196}
197
198
199static void decoder_enable(struct pvr2_v4l_decoder *ctxt,int fl)
200{
201 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 decoder_enable(%d)",fl);
202 pvr2_v4l2_cmd_stream(ctxt->client,fl);
203}
204
205
206static unsigned int decoder_describe(struct pvr2_v4l_decoder *ctxt,char *buf,unsigned int cnt)
207{
208 return scnprintf(buf,cnt,"handler: pvrusb2-video-v4l");
209}
210
211
212static const struct pvr2_i2c_handler_functions hfuncs = {
213 .detach = (void (*)(void *))decoder_detach,
214 .check = (int (*)(void *))decoder_check,
215 .update = (void (*)(void *))decoder_update,
216 .describe = (unsigned int (*)(void *,char *,unsigned int))decoder_describe,
217};
218
219
220int pvr2_i2c_decoder_v4l_setup(struct pvr2_hdw *hdw,
221 struct pvr2_i2c_client *cp)
222{
223 struct pvr2_v4l_decoder *ctxt;
224
225 if (hdw->decoder_ctrl) return 0;
226 if (cp->handler) return 0;
227 if (!decoder_detect(cp)) return 0;
228
229 ctxt = kzalloc(sizeof(*ctxt),GFP_KERNEL);
230 if (!ctxt) return 0;
231
232 ctxt->handler.func_data = ctxt;
233 ctxt->handler.func_table = &hfuncs;
234 ctxt->ctrl.ctxt = ctxt;
235 ctxt->ctrl.detach = (void (*)(void *))decoder_detach;
236 ctxt->ctrl.enable = (void (*)(void *,int))decoder_enable;
237 ctxt->client = cp;
238 ctxt->hdw = hdw;
239 ctxt->stale_mask = (1 << ARRAY_SIZE(decoder_ops)) - 1;
240 pvr2_hdw_set_decoder(hdw,&ctxt->ctrl);
241 cp->handler = &ctxt->handler;
242 pvr2_trace(PVR2_TRACE_CHIPS,"i2c 0x%x saa711x V4L2 handler set up",
243 cp->client->addr);
244 return !0;
245} 99}
246 100
247 101
248
249
250/* 102/*
251 Stuff for Emacs to see, in order to encourage consistent editing style: 103 Stuff for Emacs to see, in order to encourage consistent editing style:
252 *** Local Variables: *** 104 *** Local Variables: ***
diff --git a/drivers/media/video/pvrusb2/pvrusb2-video-v4l.h b/drivers/media/video/pvrusb2/pvrusb2-video-v4l.h
index 4ff5b892b303..3b0bd5db602b 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-video-v4l.h
+++ b/drivers/media/video/pvrusb2/pvrusb2-video-v4l.h
@@ -32,11 +32,8 @@
32*/ 32*/
33 33
34 34
35 35#include "pvrusb2-hdw-internal.h"
36#include "pvrusb2-i2c-core.h" 36void pvr2_saa7115_subdev_update(struct pvr2_hdw *, struct v4l2_subdev *);
37
38int pvr2_i2c_decoder_v4l_setup(struct pvr2_hdw *,struct pvr2_i2c_client *);
39
40 37
41#endif /* __PVRUSB2_VIDEO_V4L_H */ 38#endif /* __PVRUSB2_VIDEO_V4L_H */
42 39
diff --git a/drivers/media/video/pvrusb2/pvrusb2-wm8775.c b/drivers/media/video/pvrusb2/pvrusb2-wm8775.c
index f6fcf0ac6118..1670aa4051ce 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-wm8775.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-wm8775.c
@@ -27,7 +27,6 @@
27*/ 27*/
28 28
29#include "pvrusb2-wm8775.h" 29#include "pvrusb2-wm8775.h"
30#include "pvrusb2-i2c-cmd-v4l2.h"
31 30
32 31
33#include "pvrusb2-hdw-internal.h" 32#include "pvrusb2-hdw-internal.h"
@@ -37,128 +36,31 @@
37#include <linux/errno.h> 36#include <linux/errno.h>
38#include <linux/slab.h> 37#include <linux/slab.h>
39 38
40struct pvr2_v4l_wm8775 { 39void pvr2_wm8775_subdev_update(struct pvr2_hdw *hdw, struct v4l2_subdev *sd)
41 struct pvr2_i2c_handler handler;
42 struct pvr2_i2c_client *client;
43 struct pvr2_hdw *hdw;
44 unsigned long stale_mask;
45};
46
47
48static void set_input(struct pvr2_v4l_wm8775 *ctxt)
49{
50 struct v4l2_routing route;
51 struct pvr2_hdw *hdw = ctxt->hdw;
52
53 memset(&route,0,sizeof(route));
54
55 switch(hdw->input_val) {
56 case PVR2_CVAL_INPUT_RADIO:
57 route.input = 1;
58 break;
59 default:
60 /* All other cases just use the second input */
61 route.input = 2;
62 break;
63 }
64 pvr2_trace(PVR2_TRACE_CHIPS,"i2c wm8775 set_input(val=%d route=0x%x)",
65 hdw->input_val,route.input);
66
67 pvr2_i2c_client_cmd(ctxt->client,VIDIOC_INT_S_AUDIO_ROUTING,&route);
68}
69
70static int check_input(struct pvr2_v4l_wm8775 *ctxt)
71{
72 struct pvr2_hdw *hdw = ctxt->hdw;
73 return hdw->input_dirty != 0;
74}
75
76
77struct pvr2_v4l_wm8775_ops {
78 void (*update)(struct pvr2_v4l_wm8775 *);
79 int (*check)(struct pvr2_v4l_wm8775 *);
80};
81
82
83static const struct pvr2_v4l_wm8775_ops wm8775_ops[] = {
84 { .update = set_input, .check = check_input},
85};
86
87
88static unsigned int wm8775_describe(struct pvr2_v4l_wm8775 *ctxt,
89 char *buf,unsigned int cnt)
90{
91 return scnprintf(buf,cnt,"handler: pvrusb2-wm8775");
92}
93
94
95static void wm8775_detach(struct pvr2_v4l_wm8775 *ctxt)
96{ 40{
97 ctxt->client->handler = NULL; 41 if (hdw->input_dirty || hdw->force_dirty) {
98 kfree(ctxt); 42 struct v4l2_routing route;
99} 43
100 44 memset(&route, 0, sizeof(route));
101 45
102static int wm8775_check(struct pvr2_v4l_wm8775 *ctxt) 46 switch (hdw->input_val) {
103{ 47 case PVR2_CVAL_INPUT_RADIO:
104 unsigned long msk; 48 route.input = 1;
105 unsigned int idx; 49 break;
106 50 default:
107 for (idx = 0; idx < ARRAY_SIZE(wm8775_ops); idx++) { 51 /* All other cases just use the second input */
108 msk = 1 << idx; 52 route.input = 2;
109 if (ctxt->stale_mask & msk) continue; 53 break;
110 if (wm8775_ops[idx].check(ctxt)) {
111 ctxt->stale_mask |= msk;
112 } 54 }
113 } 55 pvr2_trace(PVR2_TRACE_CHIPS, "subdev wm8775"
114 return ctxt->stale_mask != 0; 56 " set_input(val=%d route=0x%x)",
115} 57 hdw->input_val, route.input);
116
117
118static void wm8775_update(struct pvr2_v4l_wm8775 *ctxt)
119{
120 unsigned long msk;
121 unsigned int idx;
122 58
123 for (idx = 0; idx < ARRAY_SIZE(wm8775_ops); idx++) { 59 sd->ops->audio->s_routing(sd, &route);
124 msk = 1 << idx;
125 if (!(ctxt->stale_mask & msk)) continue;
126 ctxt->stale_mask &= ~msk;
127 wm8775_ops[idx].update(ctxt);
128 } 60 }
129} 61}
130 62
131 63
132static const struct pvr2_i2c_handler_functions hfuncs = {
133 .detach = (void (*)(void *))wm8775_detach,
134 .check = (int (*)(void *))wm8775_check,
135 .update = (void (*)(void *))wm8775_update,
136 .describe = (unsigned int (*)(void *,char *,unsigned int))wm8775_describe,
137};
138
139
140int pvr2_i2c_wm8775_setup(struct pvr2_hdw *hdw,struct pvr2_i2c_client *cp)
141{
142 struct pvr2_v4l_wm8775 *ctxt;
143
144 if (cp->handler) return 0;
145
146 ctxt = kzalloc(sizeof(*ctxt),GFP_KERNEL);
147 if (!ctxt) return 0;
148
149 ctxt->handler.func_data = ctxt;
150 ctxt->handler.func_table = &hfuncs;
151 ctxt->client = cp;
152 ctxt->hdw = hdw;
153 ctxt->stale_mask = (1 << ARRAY_SIZE(wm8775_ops)) - 1;
154 cp->handler = &ctxt->handler;
155 pvr2_trace(PVR2_TRACE_CHIPS,"i2c 0x%x wm8775 V4L2 handler set up",
156 cp->client->addr);
157 return !0;
158}
159
160
161
162 64
163/* 65/*
164 Stuff for Emacs to see, in order to encourage consistent editing style: 66 Stuff for Emacs to see, in order to encourage consistent editing style:
diff --git a/drivers/media/video/pvrusb2/pvrusb2-wm8775.h b/drivers/media/video/pvrusb2/pvrusb2-wm8775.h
index 807090961255..0577bc7246fb 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-wm8775.h
+++ b/drivers/media/video/pvrusb2/pvrusb2-wm8775.h
@@ -34,9 +34,9 @@
34 34
35 35
36 36
37#include "pvrusb2-i2c-core.h" 37#include "pvrusb2-hdw-internal.h"
38 38
39int pvr2_i2c_wm8775_setup(struct pvr2_hdw *,struct pvr2_i2c_client *); 39void pvr2_wm8775_subdev_update(struct pvr2_hdw *, struct v4l2_subdev *sd);
40 40
41 41
42#endif /* __PVRUSB2_WM8775_H */ 42#endif /* __PVRUSB2_WM8775_H */
diff --git a/drivers/media/video/pwc/Kconfig b/drivers/media/video/pwc/Kconfig
index 7298cf2e1650..8b9f0aa844a1 100644
--- a/drivers/media/video/pwc/Kconfig
+++ b/drivers/media/video/pwc/Kconfig
@@ -35,3 +35,13 @@ config USB_PWC_DEBUG
35 Say Y here in order to have the pwc driver generate verbose debugging 35 Say Y here in order to have the pwc driver generate verbose debugging
36 messages. 36 messages.
37 A special module options 'trace' is used to control the verbosity. 37 A special module options 'trace' is used to control the verbosity.
38
39config USB_PWC_INPUT_EVDEV
40 bool "USB Philips Cameras input events device support"
41 default y
42 depends on USB_PWC && INPUT
43 ---help---
44 This option makes USB Philips cameras register the snapshot button as
45 an input device to report button events.
46
47 If you are in doubt, say Y.
diff --git a/drivers/media/video/pwc/pwc-if.c b/drivers/media/video/pwc/pwc-if.c
index 0d810189dd87..7c542caf248e 100644
--- a/drivers/media/video/pwc/pwc-if.c
+++ b/drivers/media/video/pwc/pwc-if.c
@@ -53,6 +53,7 @@
53 - Xavier Roche: QuickCam Pro 4000 ID 53 - Xavier Roche: QuickCam Pro 4000 ID
54 - Jens Knudsen: QuickCam Zoom ID 54 - Jens Knudsen: QuickCam Zoom ID
55 - J. Debert: QuickCam for Notebooks ID 55 - J. Debert: QuickCam for Notebooks ID
56 - Pham Thanh Nam: webcam snapshot button as an event input device
56*/ 57*/
57 58
58#include <linux/errno.h> 59#include <linux/errno.h>
@@ -61,6 +62,9 @@
61#include <linux/module.h> 62#include <linux/module.h>
62#include <linux/poll.h> 63#include <linux/poll.h>
63#include <linux/slab.h> 64#include <linux/slab.h>
65#ifdef CONFIG_USB_PWC_INPUT_EVDEV
66#include <linux/usb/input.h>
67#endif
64#include <linux/vmalloc.h> 68#include <linux/vmalloc.h>
65#include <asm/io.h> 69#include <asm/io.h>
66 70
@@ -586,6 +590,23 @@ static void pwc_frame_dumped(struct pwc_device *pdev)
586 pdev->vframe_count); 590 pdev->vframe_count);
587} 591}
588 592
593static void pwc_snapshot_button(struct pwc_device *pdev, int down)
594{
595 if (down) {
596 PWC_TRACE("Snapshot button pressed.\n");
597 pdev->snapshot_button_status = 1;
598 } else {
599 PWC_TRACE("Snapshot button released.\n");
600 }
601
602#ifdef CONFIG_USB_PWC_INPUT_EVDEV
603 if (pdev->button_dev) {
604 input_report_key(pdev->button_dev, BTN_0, down);
605 input_sync(pdev->button_dev);
606 }
607#endif
608}
609
589static int pwc_rcv_short_packet(struct pwc_device *pdev, const struct pwc_frame_buf *fbuf) 610static int pwc_rcv_short_packet(struct pwc_device *pdev, const struct pwc_frame_buf *fbuf)
590{ 611{
591 int awake = 0; 612 int awake = 0;
@@ -603,13 +624,7 @@ static int pwc_rcv_short_packet(struct pwc_device *pdev, const struct pwc_frame_
603 pdev->vframes_error++; 624 pdev->vframes_error++;
604 } 625 }
605 if ((ptr[0] ^ pdev->vmirror) & 0x01) { 626 if ((ptr[0] ^ pdev->vmirror) & 0x01) {
606 if (ptr[0] & 0x01) { 627 pwc_snapshot_button(pdev, ptr[0] & 0x01);
607 pdev->snapshot_button_status = 1;
608 PWC_TRACE("Snapshot button pressed.\n");
609 }
610 else {
611 PWC_TRACE("Snapshot button released.\n");
612 }
613 } 628 }
614 if ((ptr[0] ^ pdev->vmirror) & 0x02) { 629 if ((ptr[0] ^ pdev->vmirror) & 0x02) {
615 if (ptr[0] & 0x02) 630 if (ptr[0] & 0x02)
@@ -633,12 +648,7 @@ static int pwc_rcv_short_packet(struct pwc_device *pdev, const struct pwc_frame_
633 else if (pdev->type == 740 || pdev->type == 720) { 648 else if (pdev->type == 740 || pdev->type == 720) {
634 unsigned char *ptr = (unsigned char *)fbuf->data; 649 unsigned char *ptr = (unsigned char *)fbuf->data;
635 if ((ptr[0] ^ pdev->vmirror) & 0x01) { 650 if ((ptr[0] ^ pdev->vmirror) & 0x01) {
636 if (ptr[0] & 0x01) { 651 pwc_snapshot_button(pdev, ptr[0] & 0x01);
637 pdev->snapshot_button_status = 1;
638 PWC_TRACE("Snapshot button pressed.\n");
639 }
640 else
641 PWC_TRACE("Snapshot button released.\n");
642 } 652 }
643 pdev->vmirror = ptr[0] & 0x03; 653 pdev->vmirror = ptr[0] & 0x03;
644 } 654 }
@@ -1115,6 +1125,7 @@ static int pwc_video_open(struct file *file)
1115 } 1125 }
1116 1126
1117 mutex_lock(&pdev->modlock); 1127 mutex_lock(&pdev->modlock);
1128 pwc_construct(pdev); /* set min/max sizes correct */
1118 if (!pdev->usb_init) { 1129 if (!pdev->usb_init) {
1119 PWC_DEBUG_OPEN("Doing first time initialization.\n"); 1130 PWC_DEBUG_OPEN("Doing first time initialization.\n");
1120 pdev->usb_init = 1; 1131 pdev->usb_init = 1;
@@ -1139,7 +1150,6 @@ static int pwc_video_open(struct file *file)
1139 if (pwc_set_leds(pdev, led_on, led_off) < 0) 1150 if (pwc_set_leds(pdev, led_on, led_off) < 0)
1140 PWC_DEBUG_OPEN("Failed to set LED on/off time.\n"); 1151 PWC_DEBUG_OPEN("Failed to set LED on/off time.\n");
1141 1152
1142 pwc_construct(pdev); /* set min/max sizes correct */
1143 1153
1144 /* So far, so good. Allocate memory. */ 1154 /* So far, so good. Allocate memory. */
1145 i = pwc_allocate_buffers(pdev); 1155 i = pwc_allocate_buffers(pdev);
@@ -1216,6 +1226,15 @@ static void pwc_cleanup(struct pwc_device *pdev)
1216{ 1226{
1217 pwc_remove_sysfs_files(pdev->vdev); 1227 pwc_remove_sysfs_files(pdev->vdev);
1218 video_unregister_device(pdev->vdev); 1228 video_unregister_device(pdev->vdev);
1229
1230#ifdef CONFIG_USB_PWC_INPUT_EVDEV
1231 if (pdev->button_dev) {
1232 input_unregister_device(pdev->button_dev);
1233 input_free_device(pdev->button_dev);
1234 kfree(pdev->button_dev->phys);
1235 pdev->button_dev = NULL;
1236 }
1237#endif
1219} 1238}
1220 1239
1221/* Note that all cleanup is done in the reverse order as in _open */ 1240/* Note that all cleanup is done in the reverse order as in _open */
@@ -1483,6 +1502,9 @@ static int usb_pwc_probe(struct usb_interface *intf, const struct usb_device_id
1483 int features = 0; 1502 int features = 0;
1484 int video_nr = -1; /* default: use next available device */ 1503 int video_nr = -1; /* default: use next available device */
1485 char serial_number[30], *name; 1504 char serial_number[30], *name;
1505#ifdef CONFIG_USB_PWC_INPUT_EVDEV
1506 char *phys = NULL;
1507#endif
1486 1508
1487 vendor_id = le16_to_cpu(udev->descriptor.idVendor); 1509 vendor_id = le16_to_cpu(udev->descriptor.idVendor);
1488 product_id = le16_to_cpu(udev->descriptor.idProduct); 1510 product_id = le16_to_cpu(udev->descriptor.idProduct);
@@ -1807,6 +1829,35 @@ static int usb_pwc_probe(struct usb_interface *intf, const struct usb_device_id
1807 pwc_set_leds(pdev, 0, 0); 1829 pwc_set_leds(pdev, 0, 0);
1808 pwc_camera_power(pdev, 0); 1830 pwc_camera_power(pdev, 0);
1809 1831
1832#ifdef CONFIG_USB_PWC_INPUT_EVDEV
1833 /* register webcam snapshot button input device */
1834 pdev->button_dev = input_allocate_device();
1835 if (!pdev->button_dev) {
1836 PWC_ERROR("Err, insufficient memory for webcam snapshot button device.");
1837 return -ENOMEM;
1838 }
1839
1840 pdev->button_dev->name = "PWC snapshot button";
1841 phys = kasprintf(GFP_KERNEL,"usb-%s-%s", pdev->udev->bus->bus_name, pdev->udev->devpath);
1842 if (!phys) {
1843 input_free_device(pdev->button_dev);
1844 return -ENOMEM;
1845 }
1846 pdev->button_dev->phys = phys;
1847 usb_to_input_id(pdev->udev, &pdev->button_dev->id);
1848 pdev->button_dev->dev.parent = &pdev->udev->dev;
1849 pdev->button_dev->evbit[0] = BIT_MASK(EV_KEY);
1850 pdev->button_dev->keybit[BIT_WORD(BTN_0)] = BIT_MASK(BTN_0);
1851
1852 rc = input_register_device(pdev->button_dev);
1853 if (rc) {
1854 input_free_device(pdev->button_dev);
1855 kfree(pdev->button_dev->phys);
1856 pdev->button_dev = NULL;
1857 return rc;
1858 }
1859#endif
1860
1810 return 0; 1861 return 0;
1811 1862
1812err_unreg: 1863err_unreg:
diff --git a/drivers/media/video/pwc/pwc.h b/drivers/media/video/pwc/pwc.h
index 01411fb2337a..0be6f814f539 100644
--- a/drivers/media/video/pwc/pwc.h
+++ b/drivers/media/video/pwc/pwc.h
@@ -37,6 +37,9 @@
37#include <linux/videodev.h> 37#include <linux/videodev.h>
38#include <media/v4l2-common.h> 38#include <media/v4l2-common.h>
39#include <media/v4l2-ioctl.h> 39#include <media/v4l2-ioctl.h>
40#ifdef CONFIG_USB_PWC_INPUT_EVDEV
41#include <linux/input.h>
42#endif
40 43
41#include "pwc-uncompress.h" 44#include "pwc-uncompress.h"
42#include <media/pwc-ioctl.h> 45#include <media/pwc-ioctl.h>
@@ -255,6 +258,9 @@ struct pwc_device
255 int pan_angle; /* in degrees * 100 */ 258 int pan_angle; /* in degrees * 100 */
256 int tilt_angle; /* absolute angle; 0,0 is home position */ 259 int tilt_angle; /* absolute angle; 0,0 is home position */
257 int snapshot_button_status; /* set to 1 when the user push the button, reset to 0 when this value is read */ 260 int snapshot_button_status; /* set to 1 when the user push the button, reset to 0 when this value is read */
261#ifdef CONFIG_USB_PWC_INPUT_EVDEV
262 struct input_dev *button_dev; /* webcam snapshot button input */
263#endif
258 264
259 /*** Misc. data ***/ 265 /*** Misc. data ***/
260 wait_queue_head_t frameq; /* When waiting for a frame to finish... */ 266 wait_queue_head_t frameq; /* When waiting for a frame to finish... */
diff --git a/drivers/media/video/pxa_camera.c b/drivers/media/video/pxa_camera.c
index 0c4ce58c53d5..c522616ef38f 100644
--- a/drivers/media/video/pxa_camera.c
+++ b/drivers/media/video/pxa_camera.c
@@ -878,6 +878,7 @@ static int test_platform_param(struct pxa_camera_dev *pcdev,
878 SOCAM_HSYNC_ACTIVE_LOW | 878 SOCAM_HSYNC_ACTIVE_LOW |
879 SOCAM_VSYNC_ACTIVE_HIGH | 879 SOCAM_VSYNC_ACTIVE_HIGH |
880 SOCAM_VSYNC_ACTIVE_LOW | 880 SOCAM_VSYNC_ACTIVE_LOW |
881 SOCAM_DATA_ACTIVE_HIGH |
881 SOCAM_PCLK_SAMPLE_RISING | 882 SOCAM_PCLK_SAMPLE_RISING |
882 SOCAM_PCLK_SAMPLE_FALLING; 883 SOCAM_PCLK_SAMPLE_FALLING;
883 884
@@ -1149,8 +1150,43 @@ static int pxa_camera_get_formats(struct soc_camera_device *icd, int idx,
1149 return formats; 1150 return formats;
1150} 1151}
1151 1152
1153static int pxa_camera_set_crop(struct soc_camera_device *icd,
1154 struct v4l2_rect *rect)
1155{
1156 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
1157 struct pxa_camera_dev *pcdev = ici->priv;
1158 struct soc_camera_sense sense = {
1159 .master_clock = pcdev->mclk,
1160 .pixel_clock_max = pcdev->ciclk / 4,
1161 };
1162 int ret;
1163
1164 /* If PCLK is used to latch data from the sensor, check sense */
1165 if (pcdev->platform_flags & PXA_CAMERA_PCLK_EN)
1166 icd->sense = &sense;
1167
1168 ret = icd->ops->set_crop(icd, rect);
1169
1170 icd->sense = NULL;
1171
1172 if (ret < 0) {
1173 dev_warn(&ici->dev, "Failed to crop to %ux%u@%u:%u\n",
1174 rect->width, rect->height, rect->left, rect->top);
1175 } else if (sense.flags & SOCAM_SENSE_PCLK_CHANGED) {
1176 if (sense.pixel_clock > sense.pixel_clock_max) {
1177 dev_err(&ici->dev,
1178 "pixel clock %lu set by the camera too high!",
1179 sense.pixel_clock);
1180 return -EIO;
1181 }
1182 recalculate_fifo_timeout(pcdev, sense.pixel_clock);
1183 }
1184
1185 return ret;
1186}
1187
1152static int pxa_camera_set_fmt(struct soc_camera_device *icd, 1188static int pxa_camera_set_fmt(struct soc_camera_device *icd,
1153 __u32 pixfmt, struct v4l2_rect *rect) 1189 struct v4l2_format *f)
1154{ 1190{
1155 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); 1191 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
1156 struct pxa_camera_dev *pcdev = ici->priv; 1192 struct pxa_camera_dev *pcdev = ici->priv;
@@ -1160,35 +1196,30 @@ static int pxa_camera_set_fmt(struct soc_camera_device *icd,
1160 .master_clock = pcdev->mclk, 1196 .master_clock = pcdev->mclk,
1161 .pixel_clock_max = pcdev->ciclk / 4, 1197 .pixel_clock_max = pcdev->ciclk / 4,
1162 }; 1198 };
1199 struct v4l2_pix_format *pix = &f->fmt.pix;
1200 struct v4l2_format cam_f = *f;
1163 int ret; 1201 int ret;
1164 1202
1165 if (pixfmt) { 1203 xlate = soc_camera_xlate_by_fourcc(icd, pix->pixelformat);
1166 xlate = soc_camera_xlate_by_fourcc(icd, pixfmt); 1204 if (!xlate) {
1167 if (!xlate) { 1205 dev_warn(&ici->dev, "Format %x not found\n", pix->pixelformat);
1168 dev_warn(&ici->dev, "Format %x not found\n", pixfmt); 1206 return -EINVAL;
1169 return -EINVAL;
1170 }
1171
1172 cam_fmt = xlate->cam_fmt;
1173 } 1207 }
1174 1208
1209 cam_fmt = xlate->cam_fmt;
1210
1175 /* If PCLK is used to latch data from the sensor, check sense */ 1211 /* If PCLK is used to latch data from the sensor, check sense */
1176 if (pcdev->platform_flags & PXA_CAMERA_PCLK_EN) 1212 if (pcdev->platform_flags & PXA_CAMERA_PCLK_EN)
1177 icd->sense = &sense; 1213 icd->sense = &sense;
1178 1214
1179 switch (pixfmt) { 1215 cam_f.fmt.pix.pixelformat = cam_fmt->fourcc;
1180 case 0: /* Only geometry change */ 1216 ret = icd->ops->set_fmt(icd, &cam_f);
1181 ret = icd->ops->set_fmt(icd, pixfmt, rect);
1182 break;
1183 default:
1184 ret = icd->ops->set_fmt(icd, cam_fmt->fourcc, rect);
1185 }
1186 1217
1187 icd->sense = NULL; 1218 icd->sense = NULL;
1188 1219
1189 if (ret < 0) { 1220 if (ret < 0) {
1190 dev_warn(&ici->dev, "Failed to configure for format %x\n", 1221 dev_warn(&ici->dev, "Failed to configure for format %x\n",
1191 pixfmt); 1222 pix->pixelformat);
1192 } else if (sense.flags & SOCAM_SENSE_PCLK_CHANGED) { 1223 } else if (sense.flags & SOCAM_SENSE_PCLK_CHANGED) {
1193 if (sense.pixel_clock > sense.pixel_clock_max) { 1224 if (sense.pixel_clock > sense.pixel_clock_max) {
1194 dev_err(&ici->dev, 1225 dev_err(&ici->dev,
@@ -1199,7 +1230,7 @@ static int pxa_camera_set_fmt(struct soc_camera_device *icd,
1199 recalculate_fifo_timeout(pcdev, sense.pixel_clock); 1230 recalculate_fifo_timeout(pcdev, sense.pixel_clock);
1200 } 1231 }
1201 1232
1202 if (pixfmt && !ret) { 1233 if (!ret) {
1203 icd->buswidth = xlate->buswidth; 1234 icd->buswidth = xlate->buswidth;
1204 icd->current_fmt = xlate->host_fmt; 1235 icd->current_fmt = xlate->host_fmt;
1205 } 1236 }
@@ -1363,6 +1394,7 @@ static struct soc_camera_host_ops pxa_soc_camera_host_ops = {
1363 .remove = pxa_camera_remove_device, 1394 .remove = pxa_camera_remove_device,
1364 .suspend = pxa_camera_suspend, 1395 .suspend = pxa_camera_suspend,
1365 .resume = pxa_camera_resume, 1396 .resume = pxa_camera_resume,
1397 .set_crop = pxa_camera_set_crop,
1366 .get_formats = pxa_camera_get_formats, 1398 .get_formats = pxa_camera_get_formats,
1367 .set_fmt = pxa_camera_set_fmt, 1399 .set_fmt = pxa_camera_set_fmt,
1368 .try_fmt = pxa_camera_try_fmt, 1400 .try_fmt = pxa_camera_try_fmt,
diff --git a/drivers/media/video/s2255drv.c b/drivers/media/video/s2255drv.c
index 13f85ad363cd..b5be633e3bb0 100644
--- a/drivers/media/video/s2255drv.c
+++ b/drivers/media/video/s2255drv.c
@@ -336,14 +336,19 @@ static long s2255_vendor_req(struct s2255_dev *dev, unsigned char req,
336 u16 index, u16 value, void *buf, 336 u16 index, u16 value, void *buf,
337 s32 buf_len, int bOut); 337 s32 buf_len, int bOut);
338 338
339/* dev_err macro with driver name */
340#define S2255_DRIVER_NAME "s2255"
341#define s2255_dev_err(dev, fmt, arg...) \
342 dev_err(dev, S2255_DRIVER_NAME " - " fmt, ##arg)
343
339#define dprintk(level, fmt, arg...) \ 344#define dprintk(level, fmt, arg...) \
340 do { \ 345 do { \
341 if (*s2255_debug >= (level)) { \ 346 if (*s2255_debug >= (level)) { \
342 printk(KERN_DEBUG "s2255: " fmt, ##arg); \ 347 printk(KERN_DEBUG S2255_DRIVER_NAME \
348 ": " fmt, ##arg); \
343 } \ 349 } \
344 } while (0) 350 } while (0)
345 351
346
347static struct usb_driver s2255_driver; 352static struct usb_driver s2255_driver;
348 353
349 354
@@ -528,14 +533,14 @@ static void s2255_fwchunk_complete(struct urb *urb)
528 int len; 533 int len;
529 dprintk(100, "udev %p urb %p", udev, urb); 534 dprintk(100, "udev %p urb %p", udev, urb);
530 if (urb->status) { 535 if (urb->status) {
531 dev_err(&udev->dev, "URB failed with status %d", urb->status); 536 dev_err(&udev->dev, "URB failed with status %d\n", urb->status);
532 atomic_set(&data->fw_state, S2255_FW_FAILED); 537 atomic_set(&data->fw_state, S2255_FW_FAILED);
533 /* wake up anything waiting for the firmware */ 538 /* wake up anything waiting for the firmware */
534 wake_up(&data->wait_fw); 539 wake_up(&data->wait_fw);
535 return; 540 return;
536 } 541 }
537 if (data->fw_urb == NULL) { 542 if (data->fw_urb == NULL) {
538 dev_err(&udev->dev, "s2255 disconnected\n"); 543 s2255_dev_err(&udev->dev, "disconnected\n");
539 atomic_set(&data->fw_state, S2255_FW_FAILED); 544 atomic_set(&data->fw_state, S2255_FW_FAILED);
540 /* wake up anything waiting for the firmware */ 545 /* wake up anything waiting for the firmware */
541 wake_up(&data->wait_fw); 546 wake_up(&data->wait_fw);
@@ -841,8 +846,7 @@ static int vidioc_querycap(struct file *file, void *priv,
841 struct s2255_dev *dev = fh->dev; 846 struct s2255_dev *dev = fh->dev;
842 strlcpy(cap->driver, "s2255", sizeof(cap->driver)); 847 strlcpy(cap->driver, "s2255", sizeof(cap->driver));
843 strlcpy(cap->card, "s2255", sizeof(cap->card)); 848 strlcpy(cap->card, "s2255", sizeof(cap->card));
844 strlcpy(cap->bus_info, dev_name(&dev->udev->dev), 849 usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info));
845 sizeof(cap->bus_info));
846 cap->version = S2255_VERSION; 850 cap->version = S2255_VERSION;
847 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING; 851 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
848 return 0; 852 return 0;
@@ -1278,7 +1282,7 @@ static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
1278 } 1282 }
1279 1283
1280 if (!res_get(dev, fh)) { 1284 if (!res_get(dev, fh)) {
1281 dev_err(&dev->udev->dev, "s2255: stream busy\n"); 1285 s2255_dev_err(&dev->udev->dev, "stream busy\n");
1282 return -EBUSY; 1286 return -EBUSY;
1283 } 1287 }
1284 1288
@@ -1545,7 +1549,8 @@ static int s2255_open(struct file *file)
1545 1549
1546 switch (atomic_read(&dev->fw_data->fw_state)) { 1550 switch (atomic_read(&dev->fw_data->fw_state)) {
1547 case S2255_FW_FAILED: 1551 case S2255_FW_FAILED:
1548 err("2255 firmware load failed. retrying.\n"); 1552 s2255_dev_err(&dev->udev->dev,
1553 "firmware load failed. retrying.\n");
1549 s2255_fwload_start(dev, 1); 1554 s2255_fwload_start(dev, 1);
1550 wait_event_timeout(dev->fw_data->wait_fw, 1555 wait_event_timeout(dev->fw_data->wait_fw,
1551 ((atomic_read(&dev->fw_data->fw_state) 1556 ((atomic_read(&dev->fw_data->fw_state)
@@ -2173,7 +2178,8 @@ static int s2255_board_init(struct s2255_dev *dev)
2173 2178
2174 printk(KERN_INFO "2255 usb firmware version %d \n", fw_ver); 2179 printk(KERN_INFO "2255 usb firmware version %d \n", fw_ver);
2175 if (fw_ver < CUR_USB_FWVER) 2180 if (fw_ver < CUR_USB_FWVER)
2176 err("usb firmware not up to date %d\n", fw_ver); 2181 dev_err(&dev->udev->dev,
2182 "usb firmware not up to date %d\n", fw_ver);
2177 2183
2178 for (j = 0; j < MAX_CHANNELS; j++) { 2184 for (j = 0; j < MAX_CHANNELS; j++) {
2179 dev->b_acquire[j] = 0; 2185 dev->b_acquire[j] = 0;
@@ -2228,13 +2234,13 @@ static void read_pipe_completion(struct urb *purb)
2228 dprintk(100, "read pipe completion %p, status %d\n", purb, 2234 dprintk(100, "read pipe completion %p, status %d\n", purb,
2229 purb->status); 2235 purb->status);
2230 if (pipe_info == NULL) { 2236 if (pipe_info == NULL) {
2231 err("no context !"); 2237 dev_err(&purb->dev->dev, "no context!\n");
2232 return; 2238 return;
2233 } 2239 }
2234 2240
2235 dev = pipe_info->dev; 2241 dev = pipe_info->dev;
2236 if (dev == NULL) { 2242 if (dev == NULL) {
2237 err("no context !"); 2243 dev_err(&purb->dev->dev, "no context!\n");
2238 return; 2244 return;
2239 } 2245 }
2240 status = purb->status; 2246 status = purb->status;
@@ -2286,7 +2292,7 @@ static int s2255_start_readpipe(struct s2255_dev *dev)
2286 pipe_info->stream_urb = usb_alloc_urb(0, GFP_KERNEL); 2292 pipe_info->stream_urb = usb_alloc_urb(0, GFP_KERNEL);
2287 if (!pipe_info->stream_urb) { 2293 if (!pipe_info->stream_urb) {
2288 dev_err(&dev->udev->dev, 2294 dev_err(&dev->udev->dev,
2289 "ReadStream: Unable to alloc URB"); 2295 "ReadStream: Unable to alloc URB\n");
2290 return -ENOMEM; 2296 return -ENOMEM;
2291 } 2297 }
2292 /* transfer buffer allocated in board_init */ 2298 /* transfer buffer allocated in board_init */
@@ -2391,7 +2397,7 @@ static void s2255_stop_readpipe(struct s2255_dev *dev)
2391 int j; 2397 int j;
2392 2398
2393 if (dev == NULL) { 2399 if (dev == NULL) {
2394 err("s2255: invalid device"); 2400 s2255_dev_err(&dev->udev->dev, "invalid device\n");
2395 return; 2401 return;
2396 } 2402 }
2397 dprintk(4, "stop read pipe\n"); 2403 dprintk(4, "stop read pipe\n");
@@ -2453,7 +2459,7 @@ static int s2255_probe(struct usb_interface *interface,
2453 /* allocate memory for our device state and initialize it to zero */ 2459 /* allocate memory for our device state and initialize it to zero */
2454 dev = kzalloc(sizeof(struct s2255_dev), GFP_KERNEL); 2460 dev = kzalloc(sizeof(struct s2255_dev), GFP_KERNEL);
2455 if (dev == NULL) { 2461 if (dev == NULL) {
2456 err("s2255: out of memory"); 2462 s2255_dev_err(&interface->dev, "out of memory\n");
2457 goto error; 2463 goto error;
2458 } 2464 }
2459 2465
@@ -2487,7 +2493,7 @@ static int s2255_probe(struct usb_interface *interface,
2487 } 2493 }
2488 2494
2489 if (!dev->read_endpoint) { 2495 if (!dev->read_endpoint) {
2490 dev_err(&interface->dev, "Could not find bulk-in endpoint"); 2496 dev_err(&interface->dev, "Could not find bulk-in endpoint\n");
2491 goto error; 2497 goto error;
2492 } 2498 }
2493 2499
@@ -2583,7 +2589,7 @@ static void s2255_disconnect(struct usb_interface *interface)
2583} 2589}
2584 2590
2585static struct usb_driver s2255_driver = { 2591static struct usb_driver s2255_driver = {
2586 .name = "s2255", 2592 .name = S2255_DRIVER_NAME,
2587 .probe = s2255_probe, 2593 .probe = s2255_probe,
2588 .disconnect = s2255_disconnect, 2594 .disconnect = s2255_disconnect,
2589 .id_table = s2255_table, 2595 .id_table = s2255_table,
@@ -2597,7 +2603,8 @@ static int __init usb_s2255_init(void)
2597 result = usb_register(&s2255_driver); 2603 result = usb_register(&s2255_driver);
2598 2604
2599 if (result) 2605 if (result)
2600 err("usb_register failed. Error number %d", result); 2606 pr_err(KBUILD_MODNAME
2607 ": usb_register failed. Error number %d\n", result);
2601 2608
2602 dprintk(2, "s2255_init: done\n"); 2609 dprintk(2, "s2255_init: done\n");
2603 return result; 2610 return result;
diff --git a/drivers/media/video/saa5246a.c b/drivers/media/video/saa5246a.c
index e637e440b6d5..da47b2f05288 100644
--- a/drivers/media/video/saa5246a.c
+++ b/drivers/media/video/saa5246a.c
@@ -46,10 +46,11 @@
46#include <linux/smp_lock.h> 46#include <linux/smp_lock.h>
47#include <linux/mutex.h> 47#include <linux/mutex.h>
48#include <linux/videotext.h> 48#include <linux/videotext.h>
49#include <linux/videodev.h> 49#include <linux/videodev2.h>
50#include <media/v4l2-common.h> 50#include <media/v4l2-device.h>
51#include <media/v4l2-chip-ident.h>
51#include <media/v4l2-ioctl.h> 52#include <media/v4l2-ioctl.h>
52#include <media/v4l2-i2c-drv-legacy.h> 53#include <media/v4l2-i2c-drv.h>
53 54
54MODULE_AUTHOR("Michael Geng <linux@MichaelGeng.de>"); 55MODULE_AUTHOR("Michael Geng <linux@MichaelGeng.de>");
55MODULE_DESCRIPTION("Philips SAA5246A, SAA5281 Teletext decoder driver"); 56MODULE_DESCRIPTION("Philips SAA5246A, SAA5281 Teletext decoder driver");
@@ -388,13 +389,19 @@ MODULE_LICENSE("GPL");
388 389
389struct saa5246a_device 390struct saa5246a_device
390{ 391{
392 struct v4l2_subdev sd;
393 struct video_device *vdev;
391 u8 pgbuf[NUM_DAUS][VTX_VIRTUALSIZE]; 394 u8 pgbuf[NUM_DAUS][VTX_VIRTUALSIZE];
392 int is_searching[NUM_DAUS]; 395 int is_searching[NUM_DAUS];
393 struct i2c_client *client;
394 unsigned long in_use; 396 unsigned long in_use;
395 struct mutex lock; 397 struct mutex lock;
396}; 398};
397 399
400static inline struct saa5246a_device *to_dev(struct v4l2_subdev *sd)
401{
402 return container_of(sd, struct saa5246a_device, sd);
403}
404
398static struct video_device saa_template; /* Declared near bottom */ 405static struct video_device saa_template; /* Declared near bottom */
399 406
400/* 407/*
@@ -403,12 +410,13 @@ static struct video_device saa_template; /* Declared near bottom */
403 410
404static int i2c_sendbuf(struct saa5246a_device *t, int reg, int count, u8 *data) 411static int i2c_sendbuf(struct saa5246a_device *t, int reg, int count, u8 *data)
405{ 412{
413 struct i2c_client *client = v4l2_get_subdevdata(&t->sd);
406 char buf[64]; 414 char buf[64];
407 415
408 buf[0] = reg; 416 buf[0] = reg;
409 memcpy(buf+1, data, count); 417 memcpy(buf+1, data, count);
410 418
411 if(i2c_master_send(t->client, buf, count+1)==count+1) 419 if (i2c_master_send(client, buf, count + 1) == count + 1)
412 return 0; 420 return 0;
413 return -1; 421 return -1;
414} 422}
@@ -436,7 +444,9 @@ static int i2c_senddata(struct saa5246a_device *t, ...)
436 */ 444 */
437static int i2c_getdata(struct saa5246a_device *t, int count, u8 *buf) 445static int i2c_getdata(struct saa5246a_device *t, int count, u8 *buf)
438{ 446{
439 if(i2c_master_recv(t->client, buf, count)!=count) 447 struct i2c_client *client = v4l2_get_subdevdata(&t->sd);
448
449 if (i2c_master_recv(client, buf, count) != count)
440 return -1; 450 return -1;
441 return 0; 451 return 0;
442} 452}
@@ -961,9 +971,6 @@ static int saa5246a_open(struct file *file)
961{ 971{
962 struct saa5246a_device *t = video_drvdata(file); 972 struct saa5246a_device *t = video_drvdata(file);
963 973
964 if (t->client == NULL)
965 return -ENODEV;
966
967 if (test_and_set_bit(0, &t->in_use)) 974 if (test_and_set_bit(0, &t->in_use))
968 return -EBUSY; 975 return -EBUSY;
969 976
@@ -1033,18 +1040,29 @@ static struct video_device saa_template =
1033 .minor = -1, 1040 .minor = -1,
1034}; 1041};
1035 1042
1036/* Addresses to scan */ 1043static int saa5246a_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
1037static unsigned short normal_i2c[] = { 0x22 >> 1, I2C_CLIENT_END }; 1044{
1045 struct i2c_client *client = v4l2_get_subdevdata(sd);
1046
1047 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_SAA5246A, 0);
1048}
1049
1050static const struct v4l2_subdev_core_ops saa5246a_core_ops = {
1051 .g_chip_ident = saa5246a_g_chip_ident,
1052};
1053
1054static const struct v4l2_subdev_ops saa5246a_ops = {
1055 .core = &saa5246a_core_ops,
1056};
1038 1057
1039I2C_CLIENT_INSMOD;
1040 1058
1041static int saa5246a_probe(struct i2c_client *client, 1059static int saa5246a_probe(struct i2c_client *client,
1042 const struct i2c_device_id *id) 1060 const struct i2c_device_id *id)
1043{ 1061{
1044 int pgbuf; 1062 int pgbuf;
1045 int err; 1063 int err;
1046 struct video_device *vd;
1047 struct saa5246a_device *t; 1064 struct saa5246a_device *t;
1065 struct v4l2_subdev *sd;
1048 1066
1049 v4l_info(client, "chip found @ 0x%x (%s)\n", 1067 v4l_info(client, "chip found @ 0x%x (%s)\n",
1050 client->addr << 1, client->adapter->name); 1068 client->addr << 1, client->adapter->name);
@@ -1053,40 +1071,43 @@ static int saa5246a_probe(struct i2c_client *client,
1053 t = kzalloc(sizeof(*t), GFP_KERNEL); 1071 t = kzalloc(sizeof(*t), GFP_KERNEL);
1054 if (t == NULL) 1072 if (t == NULL)
1055 return -ENOMEM; 1073 return -ENOMEM;
1074 sd = &t->sd;
1075 v4l2_i2c_subdev_init(sd, client, &saa5246a_ops);
1056 mutex_init(&t->lock); 1076 mutex_init(&t->lock);
1057 1077
1058 /* Now create a video4linux device */ 1078 /* Now create a video4linux device */
1059 vd = video_device_alloc(); 1079 t->vdev = video_device_alloc();
1060 if (vd == NULL) { 1080 if (t->vdev == NULL) {
1061 kfree(t); 1081 kfree(t);
1062 return -ENOMEM; 1082 return -ENOMEM;
1063 } 1083 }
1064 i2c_set_clientdata(client, vd); 1084 memcpy(t->vdev, &saa_template, sizeof(*t->vdev));
1065 memcpy(vd, &saa_template, sizeof(*vd));
1066 1085
1067 for (pgbuf = 0; pgbuf < NUM_DAUS; pgbuf++) { 1086 for (pgbuf = 0; pgbuf < NUM_DAUS; pgbuf++) {
1068 memset(t->pgbuf[pgbuf], ' ', sizeof(t->pgbuf[0])); 1087 memset(t->pgbuf[pgbuf], ' ', sizeof(t->pgbuf[0]));
1069 t->is_searching[pgbuf] = false; 1088 t->is_searching[pgbuf] = false;
1070 } 1089 }
1071 video_set_drvdata(vd, t); 1090 video_set_drvdata(t->vdev, t);
1072 1091
1073 /* Register it */ 1092 /* Register it */
1074 err = video_register_device(vd, VFL_TYPE_VTX, -1); 1093 err = video_register_device(t->vdev, VFL_TYPE_VTX, -1);
1075 if (err < 0) { 1094 if (err < 0) {
1076 kfree(t); 1095 kfree(t);
1077 video_device_release(vd); 1096 video_device_release(t->vdev);
1097 t->vdev = NULL;
1078 return err; 1098 return err;
1079 } 1099 }
1080 t->client = client;
1081 return 0; 1100 return 0;
1082} 1101}
1083 1102
1084static int saa5246a_remove(struct i2c_client *client) 1103static int saa5246a_remove(struct i2c_client *client)
1085{ 1104{
1086 struct video_device *vd = i2c_get_clientdata(client); 1105 struct v4l2_subdev *sd = i2c_get_clientdata(client);
1106 struct saa5246a_device *t = to_dev(sd);
1087 1107
1088 video_unregister_device(vd); 1108 video_unregister_device(t->vdev);
1089 kfree(video_get_drvdata(vd)); 1109 v4l2_device_unregister_subdev(sd);
1110 kfree(t);
1090 return 0; 1111 return 0;
1091} 1112}
1092 1113
@@ -1098,7 +1119,6 @@ MODULE_DEVICE_TABLE(i2c, saa5246a_id);
1098 1119
1099static struct v4l2_i2c_driver_data v4l2_i2c_data = { 1120static struct v4l2_i2c_driver_data v4l2_i2c_data = {
1100 .name = "saa5246a", 1121 .name = "saa5246a",
1101 .driverid = I2C_DRIVERID_SAA5249,
1102 .probe = saa5246a_probe, 1122 .probe = saa5246a_probe,
1103 .remove = saa5246a_remove, 1123 .remove = saa5246a_remove,
1104 .id_table = saa5246a_id, 1124 .id_table = saa5246a_id,
diff --git a/drivers/media/video/saa5249.c b/drivers/media/video/saa5249.c
index e29765192469..48b27fe48087 100644
--- a/drivers/media/video/saa5249.c
+++ b/drivers/media/video/saa5249.c
@@ -50,15 +50,17 @@
50#include <linux/mutex.h> 50#include <linux/mutex.h>
51#include <linux/delay.h> 51#include <linux/delay.h>
52#include <linux/videotext.h> 52#include <linux/videotext.h>
53#include <linux/videodev.h> 53#include <linux/videodev2.h>
54#include <media/v4l2-common.h> 54#include <media/v4l2-device.h>
55#include <media/v4l2-chip-ident.h>
55#include <media/v4l2-ioctl.h> 56#include <media/v4l2-ioctl.h>
56#include <media/v4l2-i2c-drv-legacy.h> 57#include <media/v4l2-i2c-drv.h>
57 58
58MODULE_AUTHOR("Michael Geng <linux@MichaelGeng.de>"); 59MODULE_AUTHOR("Michael Geng <linux@MichaelGeng.de>");
59MODULE_DESCRIPTION("Philips SAA5249 Teletext decoder driver"); 60MODULE_DESCRIPTION("Philips SAA5249 Teletext decoder driver");
60MODULE_LICENSE("GPL"); 61MODULE_LICENSE("GPL");
61 62
63
62#define VTX_VER_MAJ 1 64#define VTX_VER_MAJ 1
63#define VTX_VER_MIN 8 65#define VTX_VER_MIN 8
64 66
@@ -95,17 +97,23 @@ typedef struct {
95 97
96struct saa5249_device 98struct saa5249_device
97{ 99{
100 struct v4l2_subdev sd;
101 struct video_device *vdev;
98 vdau_t vdau[NUM_DAUS]; /* Data for virtual DAUs (the 5249 only has one */ 102 vdau_t vdau[NUM_DAUS]; /* Data for virtual DAUs (the 5249 only has one */
99 /* real DAU, so we have to simulate some more) */ 103 /* real DAU, so we have to simulate some more) */
100 int vtx_use_count; 104 int vtx_use_count;
101 int is_searching[NUM_DAUS]; 105 int is_searching[NUM_DAUS];
102 int disp_mode; 106 int disp_mode;
103 int virtual_mode; 107 int virtual_mode;
104 struct i2c_client *client;
105 unsigned long in_use; 108 unsigned long in_use;
106 struct mutex lock; 109 struct mutex lock;
107}; 110};
108 111
112static inline struct saa5249_device *to_dev(struct v4l2_subdev *sd)
113{
114 return container_of(sd, struct saa5249_device, sd);
115}
116
109 117
110#define CCTWR 34 /* I²C write/read-address of vtx-chip */ 118#define CCTWR 34 /* I²C write/read-address of vtx-chip */
111#define CCTRD 35 119#define CCTRD 35
@@ -147,12 +155,13 @@ static void jdelay(unsigned long delay)
147 155
148static int i2c_sendbuf(struct saa5249_device *t, int reg, int count, u8 *data) 156static int i2c_sendbuf(struct saa5249_device *t, int reg, int count, u8 *data)
149{ 157{
158 struct i2c_client *client = v4l2_get_subdevdata(&t->sd);
150 char buf[64]; 159 char buf[64];
151 160
152 buf[0] = reg; 161 buf[0] = reg;
153 memcpy(buf+1, data, count); 162 memcpy(buf+1, data, count);
154 163
155 if (i2c_master_send(t->client, buf, count + 1) == count + 1) 164 if (i2c_master_send(client, buf, count + 1) == count + 1)
156 return 0; 165 return 0;
157 return -1; 166 return -1;
158} 167}
@@ -180,7 +189,9 @@ static int i2c_senddata(struct saa5249_device *t, ...)
180 189
181static int i2c_getdata(struct saa5249_device *t, int count, u8 *buf) 190static int i2c_getdata(struct saa5249_device *t, int count, u8 *buf)
182{ 191{
183 if(i2c_master_recv(t->client, buf, count)!=count) 192 struct i2c_client *client = v4l2_get_subdevdata(&t->sd);
193
194 if (i2c_master_recv(client, buf, count) != count)
184 return -1; 195 return -1;
185 return 0; 196 return 0;
186} 197}
@@ -497,9 +508,6 @@ static int saa5249_open(struct file *file)
497 struct saa5249_device *t = video_drvdata(file); 508 struct saa5249_device *t = video_drvdata(file);
498 int pgbuf; 509 int pgbuf;
499 510
500 if (t->client == NULL)
501 return -ENODEV;
502
503 if (test_and_set_bit(0, &t->in_use)) 511 if (test_and_set_bit(0, &t->in_use))
504 return -EBUSY; 512 return -EBUSY;
505 513
@@ -553,18 +561,28 @@ static struct video_device saa_template =
553 .release = video_device_release, 561 .release = video_device_release,
554}; 562};
555 563
556/* Addresses to scan */ 564static int saa5249_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
557static unsigned short normal_i2c[] = { 0x22 >> 1, I2C_CLIENT_END }; 565{
566 struct i2c_client *client = v4l2_get_subdevdata(sd);
567
568 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_SAA5249, 0);
569}
558 570
559I2C_CLIENT_INSMOD; 571static const struct v4l2_subdev_core_ops saa5249_core_ops = {
572 .g_chip_ident = saa5249_g_chip_ident,
573};
574
575static const struct v4l2_subdev_ops saa5249_ops = {
576 .core = &saa5249_core_ops,
577};
560 578
561static int saa5249_probe(struct i2c_client *client, 579static int saa5249_probe(struct i2c_client *client,
562 const struct i2c_device_id *id) 580 const struct i2c_device_id *id)
563{ 581{
564 int pgbuf; 582 int pgbuf;
565 int err; 583 int err;
566 struct video_device *vd;
567 struct saa5249_device *t; 584 struct saa5249_device *t;
585 struct v4l2_subdev *sd;
568 586
569 v4l_info(client, "chip found @ 0x%x (%s)\n", 587 v4l_info(client, "chip found @ 0x%x (%s)\n",
570 client->addr << 1, client->adapter->name); 588 client->addr << 1, client->adapter->name);
@@ -573,16 +591,17 @@ static int saa5249_probe(struct i2c_client *client,
573 t = kzalloc(sizeof(*t), GFP_KERNEL); 591 t = kzalloc(sizeof(*t), GFP_KERNEL);
574 if (t == NULL) 592 if (t == NULL)
575 return -ENOMEM; 593 return -ENOMEM;
594 sd = &t->sd;
595 v4l2_i2c_subdev_init(sd, client, &saa5249_ops);
576 mutex_init(&t->lock); 596 mutex_init(&t->lock);
577 597
578 /* Now create a video4linux device */ 598 /* Now create a video4linux device */
579 vd = kmalloc(sizeof(struct video_device), GFP_KERNEL); 599 t->vdev = video_device_alloc();
580 if (vd == NULL) { 600 if (t->vdev == NULL) {
581 kfree(client); 601 kfree(client);
582 return -ENOMEM; 602 return -ENOMEM;
583 } 603 }
584 i2c_set_clientdata(client, vd); 604 memcpy(t->vdev, &saa_template, sizeof(*t->vdev));
585 memcpy(vd, &saa_template, sizeof(*vd));
586 605
587 for (pgbuf = 0; pgbuf < NUM_DAUS; pgbuf++) { 606 for (pgbuf = 0; pgbuf < NUM_DAUS; pgbuf++) {
588 memset(t->vdau[pgbuf].pgbuf, ' ', sizeof(t->vdau[0].pgbuf)); 607 memset(t->vdau[pgbuf].pgbuf, ' ', sizeof(t->vdau[0].pgbuf));
@@ -593,26 +612,27 @@ static int saa5249_probe(struct i2c_client *client,
593 t->vdau[pgbuf].stopped = true; 612 t->vdau[pgbuf].stopped = true;
594 t->is_searching[pgbuf] = false; 613 t->is_searching[pgbuf] = false;
595 } 614 }
596 video_set_drvdata(vd, t); 615 video_set_drvdata(t->vdev, t);
597 616
598 /* Register it */ 617 /* Register it */
599 err = video_register_device(vd, VFL_TYPE_VTX, -1); 618 err = video_register_device(t->vdev, VFL_TYPE_VTX, -1);
600 if (err < 0) { 619 if (err < 0) {
601 kfree(t); 620 kfree(t);
602 kfree(vd); 621 video_device_release(t->vdev);
622 t->vdev = NULL;
603 return err; 623 return err;
604 } 624 }
605 t->client = client;
606 return 0; 625 return 0;
607} 626}
608 627
609static int saa5249_remove(struct i2c_client *client) 628static int saa5249_remove(struct i2c_client *client)
610{ 629{
611 struct video_device *vd = i2c_get_clientdata(client); 630 struct v4l2_subdev *sd = i2c_get_clientdata(client);
631 struct saa5249_device *t = to_dev(sd);
612 632
613 video_unregister_device(vd); 633 video_unregister_device(t->vdev);
614 kfree(video_get_drvdata(vd)); 634 v4l2_device_unregister_subdev(sd);
615 kfree(vd); 635 kfree(t);
616 return 0; 636 return 0;
617} 637}
618 638
@@ -624,7 +644,6 @@ MODULE_DEVICE_TABLE(i2c, saa5249_id);
624 644
625static struct v4l2_i2c_driver_data v4l2_i2c_data = { 645static struct v4l2_i2c_driver_data v4l2_i2c_data = {
626 .name = "saa5249", 646 .name = "saa5249",
627 .driverid = I2C_DRIVERID_SAA5249,
628 .probe = saa5249_probe, 647 .probe = saa5249_probe,
629 .remove = saa5249_remove, 648 .remove = saa5249_remove,
630 .id_table = saa5249_id, 649 .id_table = saa5249_id,
diff --git a/drivers/media/video/saa6588.c b/drivers/media/video/saa6588.c
index f05024259f01..c25e81af5ce0 100644
--- a/drivers/media/video/saa6588.c
+++ b/drivers/media/video/saa6588.c
@@ -23,7 +23,7 @@
23#include <linux/kernel.h> 23#include <linux/kernel.h>
24#include <linux/i2c.h> 24#include <linux/i2c.h>
25#include <linux/types.h> 25#include <linux/types.h>
26#include <linux/videodev.h> 26#include <linux/videodev2.h>
27#include <linux/init.h> 27#include <linux/init.h>
28#include <linux/errno.h> 28#include <linux/errno.h>
29#include <linux/slab.h> 29#include <linux/slab.h>
@@ -32,15 +32,10 @@
32#include <asm/uaccess.h> 32#include <asm/uaccess.h>
33 33
34#include <media/rds.h> 34#include <media/rds.h>
35#include <media/v4l2-device.h>
36#include <media/v4l2-chip-ident.h>
37#include <media/v4l2-i2c-drv.h>
35 38
36/* Addresses to scan */
37static unsigned short normal_i2c[] = {
38 0x20 >> 1,
39 0x22 >> 1,
40 I2C_CLIENT_END,
41};
42
43I2C_CLIENT_INSMOD;
44 39
45/* insmod options */ 40/* insmod options */
46static unsigned int debug; 41static unsigned int debug;
@@ -72,9 +67,8 @@ MODULE_LICENSE("GPL");
72#define dprintk if (debug) printk 67#define dprintk if (debug) printk
73 68
74struct saa6588 { 69struct saa6588 {
75 struct i2c_client client; 70 struct v4l2_subdev sd;
76 struct work_struct work; 71 struct delayed_work work;
77 struct timer_list timer;
78 spinlock_t lock; 72 spinlock_t lock;
79 unsigned char *buffer; 73 unsigned char *buffer;
80 unsigned int buf_size; 74 unsigned int buf_size;
@@ -86,8 +80,10 @@ struct saa6588 {
86 int data_available_for_read; 80 int data_available_for_read;
87}; 81};
88 82
89static struct i2c_driver driver; 83static inline struct saa6588 *to_saa6588(struct v4l2_subdev *sd)
90static struct i2c_client client_template; 84{
85 return container_of(sd, struct saa6588, sd);
86}
91 87
92/* ---------------------------------------------------------------------- */ 88/* ---------------------------------------------------------------------- */
93 89
@@ -258,6 +254,7 @@ static void block_to_buf(struct saa6588 *s, unsigned char *blockbuf)
258 254
259static void saa6588_i2c_poll(struct saa6588 *s) 255static void saa6588_i2c_poll(struct saa6588 *s)
260{ 256{
257 struct i2c_client *client = v4l2_get_subdevdata(&s->sd);
261 unsigned long flags; 258 unsigned long flags;
262 unsigned char tmpbuf[6]; 259 unsigned char tmpbuf[6];
263 unsigned char blocknum; 260 unsigned char blocknum;
@@ -265,7 +262,7 @@ static void saa6588_i2c_poll(struct saa6588 *s)
265 262
266 /* Although we only need 3 bytes, we have to read at least 6. 263 /* Although we only need 3 bytes, we have to read at least 6.
267 SAA6588 returns garbage otherwise */ 264 SAA6588 returns garbage otherwise */
268 if (6 != i2c_master_recv(&s->client, &tmpbuf[0], 6)) { 265 if (6 != i2c_master_recv(client, &tmpbuf[0], 6)) {
269 if (debug > 1) 266 if (debug > 1)
270 dprintk(PREFIX "read error!\n"); 267 dprintk(PREFIX "read error!\n");
271 return; 268 return;
@@ -316,23 +313,17 @@ static void saa6588_i2c_poll(struct saa6588 *s)
316 wake_up_interruptible(&s->read_queue); 313 wake_up_interruptible(&s->read_queue);
317} 314}
318 315
319static void saa6588_timer(unsigned long data)
320{
321 struct saa6588 *s = (struct saa6588 *)data;
322
323 schedule_work(&s->work);
324}
325
326static void saa6588_work(struct work_struct *work) 316static void saa6588_work(struct work_struct *work)
327{ 317{
328 struct saa6588 *s = container_of(work, struct saa6588, work); 318 struct saa6588 *s = container_of(work, struct saa6588, work.work);
329 319
330 saa6588_i2c_poll(s); 320 saa6588_i2c_poll(s);
331 mod_timer(&s->timer, jiffies + msecs_to_jiffies(20)); 321 schedule_delayed_work(&s->work, msecs_to_jiffies(20));
332} 322}
333 323
334static int saa6588_configure(struct saa6588 *s) 324static int saa6588_configure(struct saa6588 *s)
335{ 325{
326 struct i2c_client *client = v4l2_get_subdevdata(&s->sd);
336 unsigned char buf[3]; 327 unsigned char buf[3];
337 int rc; 328 int rc;
338 329
@@ -380,7 +371,8 @@ static int saa6588_configure(struct saa6588 *s)
380 dprintk(PREFIX "writing: 0w=0x%02x 1w=0x%02x 2w=0x%02x\n", 371 dprintk(PREFIX "writing: 0w=0x%02x 1w=0x%02x 2w=0x%02x\n",
381 buf[0], buf[1], buf[2]); 372 buf[0], buf[1], buf[2]);
382 373
383 if (3 != (rc = i2c_master_send(&s->client, buf, 3))) 374 rc = i2c_master_send(client, buf, 3);
375 if (rc != 3)
384 printk(PREFIX "i2c i/o error: rc == %d (should be 3)\n", rc); 376 printk(PREFIX "i2c i/o error: rc == %d (should be 3)\n", rc);
385 377
386 return 0; 378 return 0;
@@ -388,70 +380,10 @@ static int saa6588_configure(struct saa6588 *s)
388 380
389/* ---------------------------------------------------------------------- */ 381/* ---------------------------------------------------------------------- */
390 382
391static int saa6588_attach(struct i2c_adapter *adap, int addr, int kind) 383static long saa6588_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
392{
393 struct saa6588 *s;
394 client_template.adapter = adap;
395 client_template.addr = addr;
396
397 printk(PREFIX "chip found @ 0x%x\n", addr << 1);
398
399 if (NULL == (s = kmalloc(sizeof(*s), GFP_KERNEL)))
400 return -ENOMEM;
401
402 s->buf_size = bufblocks * 3;
403
404 if (NULL == (s->buffer = kmalloc(s->buf_size, GFP_KERNEL))) {
405 kfree(s);
406 return -ENOMEM;
407 }
408 spin_lock_init(&s->lock);
409 s->client = client_template;
410 s->block_count = 0;
411 s->wr_index = 0;
412 s->rd_index = 0;
413 s->last_blocknum = 0xff;
414 init_waitqueue_head(&s->read_queue);
415 s->data_available_for_read = 0;
416 i2c_set_clientdata(&s->client, s);
417 i2c_attach_client(&s->client);
418
419 saa6588_configure(s);
420
421 /* start polling via eventd */
422 INIT_WORK(&s->work, saa6588_work);
423 init_timer(&s->timer);
424 s->timer.function = saa6588_timer;
425 s->timer.data = (unsigned long)s;
426 schedule_work(&s->work);
427 return 0;
428}
429
430static int saa6588_probe(struct i2c_adapter *adap)
431{
432 if (adap->class & I2C_CLASS_TV_ANALOG)
433 return i2c_probe(adap, &addr_data, saa6588_attach);
434 return 0;
435}
436
437static int saa6588_detach(struct i2c_client *client)
438{
439 struct saa6588 *s = i2c_get_clientdata(client);
440
441 del_timer_sync(&s->timer);
442 flush_scheduled_work();
443
444 i2c_detach_client(client);
445 kfree(s->buffer);
446 kfree(s);
447 return 0;
448}
449
450static int saa6588_command(struct i2c_client *client, unsigned int cmd,
451 void *arg)
452{ 384{
453 struct saa6588 *s = i2c_get_clientdata(client); 385 struct saa6588 *s = to_saa6588(sd);
454 struct rds_command *a = (struct rds_command *)arg; 386 struct rds_command *a = arg;
455 387
456 switch (cmd) { 388 switch (cmd) {
457 /* --- open() for /dev/radio --- */ 389 /* --- open() for /dev/radio --- */
@@ -479,45 +411,94 @@ static int saa6588_command(struct i2c_client *client, unsigned int cmd,
479 411
480 default: 412 default:
481 /* nothing */ 413 /* nothing */
482 break; 414 return -ENOIOCTLCMD;
483 } 415 }
484 return 0; 416 return 0;
485} 417}
486 418
419static int saa6588_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
420{
421 struct i2c_client *client = v4l2_get_subdevdata(sd);
422
423 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_SAA6588, 0);
424}
425
487/* ----------------------------------------------------------------------- */ 426/* ----------------------------------------------------------------------- */
488 427
489static struct i2c_driver driver = { 428static const struct v4l2_subdev_core_ops saa6588_core_ops = {
490 .driver = { 429 .g_chip_ident = saa6588_g_chip_ident,
491 .name = "saa6588", 430 .ioctl = saa6588_ioctl,
492 },
493 .id = -1, /* FIXME */
494 .attach_adapter = saa6588_probe,
495 .detach_client = saa6588_detach,
496 .command = saa6588_command,
497}; 431};
498 432
499static struct i2c_client client_template = { 433static const struct v4l2_subdev_ops saa6588_ops = {
500 .name = "saa6588", 434 .core = &saa6588_core_ops,
501 .driver = &driver,
502}; 435};
503 436
504static int __init saa6588_init_module(void) 437/* ---------------------------------------------------------------------- */
438
439static int saa6588_probe(struct i2c_client *client,
440 const struct i2c_device_id *id)
505{ 441{
506 return i2c_add_driver(&driver); 442 struct saa6588 *s;
443 struct v4l2_subdev *sd;
444
445 v4l_info(client, "saa6588 found @ 0x%x (%s)\n",
446 client->addr << 1, client->adapter->name);
447
448 s = kzalloc(sizeof(*s), GFP_KERNEL);
449 if (s == NULL)
450 return -ENOMEM;
451
452 s->buf_size = bufblocks * 3;
453
454 s->buffer = kmalloc(s->buf_size, GFP_KERNEL);
455 if (s->buffer == NULL) {
456 kfree(s);
457 return -ENOMEM;
458 }
459 sd = &s->sd;
460 v4l2_i2c_subdev_init(sd, client, &saa6588_ops);
461 spin_lock_init(&s->lock);
462 s->block_count = 0;
463 s->wr_index = 0;
464 s->rd_index = 0;
465 s->last_blocknum = 0xff;
466 init_waitqueue_head(&s->read_queue);
467 s->data_available_for_read = 0;
468
469 saa6588_configure(s);
470
471 /* start polling via eventd */
472 INIT_DELAYED_WORK(&s->work, saa6588_work);
473 schedule_delayed_work(&s->work, 0);
474 return 0;
507} 475}
508 476
509static void __exit saa6588_cleanup_module(void) 477static int saa6588_remove(struct i2c_client *client)
510{ 478{
511 i2c_del_driver(&driver); 479 struct v4l2_subdev *sd = i2c_get_clientdata(client);
480 struct saa6588 *s = to_saa6588(sd);
481
482 v4l2_device_unregister_subdev(sd);
483
484 cancel_delayed_work_sync(&s->work);
485
486 kfree(s->buffer);
487 kfree(s);
488 return 0;
512} 489}
513 490
514module_init(saa6588_init_module); 491/* ----------------------------------------------------------------------- */
515module_exit(saa6588_cleanup_module);
516 492
517/* 493static const struct i2c_device_id saa6588_id[] = {
518 * Overrides for Emacs so that we follow Linus's tabbing style. 494 { "saa6588", 0 },
519 * --------------------------------------------------------------------------- 495 { }
520 * Local variables: 496};
521 * c-basic-offset: 8 497MODULE_DEVICE_TABLE(i2c, saa6588_id);
522 * End: 498
523 */ 499static struct v4l2_i2c_driver_data v4l2_i2c_data = {
500 .name = "saa6588",
501 .probe = saa6588_probe,
502 .remove = saa6588_remove,
503 .id_table = saa6588_id,
504};
diff --git a/drivers/media/video/saa7110.c b/drivers/media/video/saa7110.c
index 37860698f782..df4e08d2dceb 100644
--- a/drivers/media/video/saa7110.c
+++ b/drivers/media/video/saa7110.c
@@ -33,15 +33,16 @@
33#include <linux/wait.h> 33#include <linux/wait.h>
34#include <asm/uaccess.h> 34#include <asm/uaccess.h>
35#include <linux/i2c.h> 35#include <linux/i2c.h>
36#include <linux/videodev.h> 36#include <linux/videodev2.h>
37#include <linux/video_decoder.h> 37#include <media/v4l2-device.h>
38#include <media/v4l2-common.h> 38#include <media/v4l2-chip-ident.h>
39#include <media/v4l2-i2c-drv-legacy.h> 39#include <media/v4l2-i2c-drv.h>
40 40
41MODULE_DESCRIPTION("Philips SAA7110 video decoder driver"); 41MODULE_DESCRIPTION("Philips SAA7110 video decoder driver");
42MODULE_AUTHOR("Pauline Middelink"); 42MODULE_AUTHOR("Pauline Middelink");
43MODULE_LICENSE("GPL"); 43MODULE_LICENSE("GPL");
44 44
45
45static int debug; 46static int debug;
46module_param(debug, int, 0); 47module_param(debug, int, 0);
47MODULE_PARM_DESC(debug, "Debug level (0-1)"); 48MODULE_PARM_DESC(debug, "Debug level (0-1)");
@@ -52,9 +53,10 @@ MODULE_PARM_DESC(debug, "Debug level (0-1)");
52#define SAA7110_NR_REG 0x35 53#define SAA7110_NR_REG 0x35
53 54
54struct saa7110 { 55struct saa7110 {
56 struct v4l2_subdev sd;
55 u8 reg[SAA7110_NR_REG]; 57 u8 reg[SAA7110_NR_REG];
56 58
57 int norm; 59 v4l2_std_id norm;
58 int input; 60 int input;
59 int enable; 61 int enable;
60 int bright; 62 int bright;
@@ -65,20 +67,28 @@ struct saa7110 {
65 wait_queue_head_t wq; 67 wait_queue_head_t wq;
66}; 68};
67 69
70static inline struct saa7110 *to_saa7110(struct v4l2_subdev *sd)
71{
72 return container_of(sd, struct saa7110, sd);
73}
74
68/* ----------------------------------------------------------------------- */ 75/* ----------------------------------------------------------------------- */
69/* I2C support functions */ 76/* I2C support functions */
70/* ----------------------------------------------------------------------- */ 77/* ----------------------------------------------------------------------- */
71 78
72static int saa7110_write(struct i2c_client *client, u8 reg, u8 value) 79static int saa7110_write(struct v4l2_subdev *sd, u8 reg, u8 value)
73{ 80{
74 struct saa7110 *decoder = i2c_get_clientdata(client); 81 struct i2c_client *client = v4l2_get_subdevdata(sd);
82 struct saa7110 *decoder = to_saa7110(sd);
75 83
76 decoder->reg[reg] = value; 84 decoder->reg[reg] = value;
77 return i2c_smbus_write_byte_data(client, reg, value); 85 return i2c_smbus_write_byte_data(client, reg, value);
78} 86}
79 87
80static int saa7110_write_block(struct i2c_client *client, const u8 *data, unsigned int len) 88static int saa7110_write_block(struct v4l2_subdev *sd, const u8 *data, unsigned int len)
81{ 89{
90 struct i2c_client *client = v4l2_get_subdevdata(sd);
91 struct saa7110 *decoder = to_saa7110(sd);
82 int ret = -1; 92 int ret = -1;
83 u8 reg = *data; /* first register to write to */ 93 u8 reg = *data; /* first register to write to */
84 94
@@ -89,15 +99,13 @@ static int saa7110_write_block(struct i2c_client *client, const u8 *data, unsign
89 /* the saa7110 has an autoincrement function, use it if 99 /* the saa7110 has an autoincrement function, use it if
90 * the adapter understands raw I2C */ 100 * the adapter understands raw I2C */
91 if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { 101 if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
92 struct saa7110 *decoder = i2c_get_clientdata(client);
93
94 ret = i2c_master_send(client, data, len); 102 ret = i2c_master_send(client, data, len);
95 103
96 /* Cache the written data */ 104 /* Cache the written data */
97 memcpy(decoder->reg + reg, data + 1, len - 1); 105 memcpy(decoder->reg + reg, data + 1, len - 1);
98 } else { 106 } else {
99 for (++data, --len; len; len--) { 107 for (++data, --len; len; len--) {
100 ret = saa7110_write(client, reg++, *data++); 108 ret = saa7110_write(sd, reg++, *data++);
101 if (ret < 0) 109 if (ret < 0)
102 break; 110 break;
103 } 111 }
@@ -106,8 +114,10 @@ static int saa7110_write_block(struct i2c_client *client, const u8 *data, unsign
106 return ret; 114 return ret;
107} 115}
108 116
109static inline int saa7110_read(struct i2c_client *client) 117static inline int saa7110_read(struct v4l2_subdev *sd)
110{ 118{
119 struct i2c_client *client = v4l2_get_subdevdata(sd);
120
111 return i2c_smbus_read_byte(client); 121 return i2c_smbus_read_byte(client);
112} 122}
113 123
@@ -115,11 +125,11 @@ static inline int saa7110_read(struct i2c_client *client)
115/* SAA7110 functions */ 125/* SAA7110 functions */
116/* ----------------------------------------------------------------------- */ 126/* ----------------------------------------------------------------------- */
117 127
118#define FRESP_06H_COMPST 0x03 //0x13 128#define FRESP_06H_COMPST 0x03 /*0x13*/
119#define FRESP_06H_SVIDEO 0x83 //0xC0 129#define FRESP_06H_SVIDEO 0x83 /*0xC0*/
120 130
121 131
122static int saa7110_selmux(struct i2c_client *client, int chan) 132static int saa7110_selmux(struct v4l2_subdev *sd, int chan)
123{ 133{
124 static const unsigned char modes[9][8] = { 134 static const unsigned char modes[9][8] = {
125 /* mode 0 */ 135 /* mode 0 */
@@ -150,17 +160,17 @@ static int saa7110_selmux(struct i2c_client *client, int chan)
150 {FRESP_06H_SVIDEO, 0x3C, 0x27, 0xC1, 0x23, 160 {FRESP_06H_SVIDEO, 0x3C, 0x27, 0xC1, 0x23,
151 0x44, 0x75, 0x21} 161 0x44, 0x75, 0x21}
152 }; 162 };
153 struct saa7110 *decoder = i2c_get_clientdata(client); 163 struct saa7110 *decoder = to_saa7110(sd);
154 const unsigned char *ptr = modes[chan]; 164 const unsigned char *ptr = modes[chan];
155 165
156 saa7110_write(client, 0x06, ptr[0]); /* Luminance control */ 166 saa7110_write(sd, 0x06, ptr[0]); /* Luminance control */
157 saa7110_write(client, 0x20, ptr[1]); /* Analog Control #1 */ 167 saa7110_write(sd, 0x20, ptr[1]); /* Analog Control #1 */
158 saa7110_write(client, 0x21, ptr[2]); /* Analog Control #2 */ 168 saa7110_write(sd, 0x21, ptr[2]); /* Analog Control #2 */
159 saa7110_write(client, 0x22, ptr[3]); /* Mixer Control #1 */ 169 saa7110_write(sd, 0x22, ptr[3]); /* Mixer Control #1 */
160 saa7110_write(client, 0x2C, ptr[4]); /* Mixer Control #2 */ 170 saa7110_write(sd, 0x2C, ptr[4]); /* Mixer Control #2 */
161 saa7110_write(client, 0x30, ptr[5]); /* ADCs gain control */ 171 saa7110_write(sd, 0x30, ptr[5]); /* ADCs gain control */
162 saa7110_write(client, 0x31, ptr[6]); /* Mixer Control #3 */ 172 saa7110_write(sd, 0x31, ptr[6]); /* Mixer Control #3 */
163 saa7110_write(client, 0x21, ptr[7]); /* Analog Control #2 */ 173 saa7110_write(sd, 0x21, ptr[7]); /* Analog Control #2 */
164 decoder->input = chan; 174 decoder->input = chan;
165 175
166 return 0; 176 return 0;
@@ -176,246 +186,260 @@ static const unsigned char initseq[1 + SAA7110_NR_REG] = {
176 /* 0x30 */ 0x44, 0x71, 0x02, 0x8C, 0x02 186 /* 0x30 */ 0x44, 0x71, 0x02, 0x8C, 0x02
177}; 187};
178 188
179static int determine_norm(struct i2c_client *client) 189static v4l2_std_id determine_norm(struct v4l2_subdev *sd)
180{ 190{
181 DEFINE_WAIT(wait); 191 DEFINE_WAIT(wait);
182 struct saa7110 *decoder = i2c_get_clientdata(client); 192 struct saa7110 *decoder = to_saa7110(sd);
183 int status; 193 int status;
184 194
185 /* mode changed, start automatic detection */ 195 /* mode changed, start automatic detection */
186 saa7110_write_block(client, initseq, sizeof(initseq)); 196 saa7110_write_block(sd, initseq, sizeof(initseq));
187 saa7110_selmux(client, decoder->input); 197 saa7110_selmux(sd, decoder->input);
188 prepare_to_wait(&decoder->wq, &wait, TASK_UNINTERRUPTIBLE); 198 prepare_to_wait(&decoder->wq, &wait, TASK_UNINTERRUPTIBLE);
189 schedule_timeout(msecs_to_jiffies(250)); 199 schedule_timeout(msecs_to_jiffies(250));
190 finish_wait(&decoder->wq, &wait); 200 finish_wait(&decoder->wq, &wait);
191 status = saa7110_read(client); 201 status = saa7110_read(sd);
192 if (status & 0x40) { 202 if (status & 0x40) {
193 v4l_dbg(1, debug, client, "status=0x%02x (no signal)\n", status); 203 v4l2_dbg(1, debug, sd, "status=0x%02x (no signal)\n", status);
194 return decoder->norm; // no change 204 return decoder->norm; /* no change*/
195 } 205 }
196 if ((status & 3) == 0) { 206 if ((status & 3) == 0) {
197 saa7110_write(client, 0x06, 0x83); 207 saa7110_write(sd, 0x06, 0x83);
198 if (status & 0x20) { 208 if (status & 0x20) {
199 v4l_dbg(1, debug, client, "status=0x%02x (NTSC/no color)\n", status); 209 v4l2_dbg(1, debug, sd, "status=0x%02x (NTSC/no color)\n", status);
200 //saa7110_write(client,0x2E,0x81); 210 /*saa7110_write(sd,0x2E,0x81);*/
201 return VIDEO_MODE_NTSC; 211 return V4L2_STD_NTSC;
202 } 212 }
203 v4l_dbg(1, debug, client, "status=0x%02x (PAL/no color)\n", status); 213 v4l2_dbg(1, debug, sd, "status=0x%02x (PAL/no color)\n", status);
204 //saa7110_write(client,0x2E,0x9A); 214 /*saa7110_write(sd,0x2E,0x9A);*/
205 return VIDEO_MODE_PAL; 215 return V4L2_STD_PAL;
206 } 216 }
207 //saa7110_write(client,0x06,0x03); 217 /*saa7110_write(sd,0x06,0x03);*/
208 if (status & 0x20) { /* 60Hz */ 218 if (status & 0x20) { /* 60Hz */
209 v4l_dbg(1, debug, client, "status=0x%02x (NTSC)\n", status); 219 v4l2_dbg(1, debug, sd, "status=0x%02x (NTSC)\n", status);
210 saa7110_write(client, 0x0D, 0x86); 220 saa7110_write(sd, 0x0D, 0x86);
211 saa7110_write(client, 0x0F, 0x50); 221 saa7110_write(sd, 0x0F, 0x50);
212 saa7110_write(client, 0x11, 0x2C); 222 saa7110_write(sd, 0x11, 0x2C);
213 //saa7110_write(client,0x2E,0x81); 223 /*saa7110_write(sd,0x2E,0x81);*/
214 return VIDEO_MODE_NTSC; 224 return V4L2_STD_NTSC;
215 } 225 }
216 226
217 /* 50Hz -> PAL/SECAM */ 227 /* 50Hz -> PAL/SECAM */
218 saa7110_write(client, 0x0D, 0x86); 228 saa7110_write(sd, 0x0D, 0x86);
219 saa7110_write(client, 0x0F, 0x10); 229 saa7110_write(sd, 0x0F, 0x10);
220 saa7110_write(client, 0x11, 0x59); 230 saa7110_write(sd, 0x11, 0x59);
221 //saa7110_write(client,0x2E,0x9A); 231 /*saa7110_write(sd,0x2E,0x9A);*/
222 232
223 prepare_to_wait(&decoder->wq, &wait, TASK_UNINTERRUPTIBLE); 233 prepare_to_wait(&decoder->wq, &wait, TASK_UNINTERRUPTIBLE);
224 schedule_timeout(msecs_to_jiffies(250)); 234 schedule_timeout(msecs_to_jiffies(250));
225 finish_wait(&decoder->wq, &wait); 235 finish_wait(&decoder->wq, &wait);
226 236
227 status = saa7110_read(client); 237 status = saa7110_read(sd);
228 if ((status & 0x03) == 0x01) { 238 if ((status & 0x03) == 0x01) {
229 v4l_dbg(1, debug, client, "status=0x%02x (SECAM)\n", status); 239 v4l2_dbg(1, debug, sd, "status=0x%02x (SECAM)\n", status);
230 saa7110_write(client, 0x0D, 0x87); 240 saa7110_write(sd, 0x0D, 0x87);
231 return VIDEO_MODE_SECAM; 241 return V4L2_STD_SECAM;
232 } 242 }
233 v4l_dbg(1, debug, client, "status=0x%02x (PAL)\n", status); 243 v4l2_dbg(1, debug, sd, "status=0x%02x (PAL)\n", status);
234 return VIDEO_MODE_PAL; 244 return V4L2_STD_PAL;
235} 245}
236 246
237static int 247static int saa7110_g_input_status(struct v4l2_subdev *sd, u32 *pstatus)
238saa7110_command (struct i2c_client *client,
239 unsigned int cmd,
240 void *arg)
241{ 248{
242 struct saa7110 *decoder = i2c_get_clientdata(client); 249 struct saa7110 *decoder = to_saa7110(sd);
243 int v; 250 int res = V4L2_IN_ST_NO_SIGNAL;
251 int status = saa7110_read(sd);
252
253 v4l2_dbg(1, debug, sd, "status=0x%02x norm=%llx\n",
254 status, (unsigned long long)decoder->norm);
255 if (!(status & 0x40))
256 res = 0;
257 if (!(status & 0x03))
258 res |= V4L2_IN_ST_NO_COLOR;
259
260 *pstatus = res;
261 return 0;
262}
244 263
245 switch (cmd) { 264static int saa7110_querystd(struct v4l2_subdev *sd, v4l2_std_id *std)
246 case 0: 265{
247 //saa7110_write_block(client, initseq, sizeof(initseq)); 266 *(v4l2_std_id *)std = determine_norm(sd);
248 break; 267 return 0;
268}
249 269
250 case DECODER_GET_CAPABILITIES: 270static int saa7110_s_std(struct v4l2_subdev *sd, v4l2_std_id std)
251 { 271{
252 struct video_decoder_capability *dc = arg; 272 struct saa7110 *decoder = to_saa7110(sd);
273
274 if (decoder->norm != std) {
275 decoder->norm = std;
276 /*saa7110_write(sd, 0x06, 0x03);*/
277 if (std & V4L2_STD_NTSC) {
278 saa7110_write(sd, 0x0D, 0x86);
279 saa7110_write(sd, 0x0F, 0x50);
280 saa7110_write(sd, 0x11, 0x2C);
281 /*saa7110_write(sd, 0x2E, 0x81);*/
282 v4l2_dbg(1, debug, sd, "switched to NTSC\n");
283 } else if (std & V4L2_STD_PAL) {
284 saa7110_write(sd, 0x0D, 0x86);
285 saa7110_write(sd, 0x0F, 0x10);
286 saa7110_write(sd, 0x11, 0x59);
287 /*saa7110_write(sd, 0x2E, 0x9A);*/
288 v4l2_dbg(1, debug, sd, "switched to PAL\n");
289 } else if (std & V4L2_STD_SECAM) {
290 saa7110_write(sd, 0x0D, 0x87);
291 saa7110_write(sd, 0x0F, 0x10);
292 saa7110_write(sd, 0x11, 0x59);
293 /*saa7110_write(sd, 0x2E, 0x9A);*/
294 v4l2_dbg(1, debug, sd, "switched to SECAM\n");
295 } else {
296 return -EINVAL;
297 }
298 }
299 return 0;
300}
253 301
254 dc->flags = 302static int saa7110_s_routing(struct v4l2_subdev *sd, const struct v4l2_routing *route)
255 VIDEO_DECODER_PAL | VIDEO_DECODER_NTSC | 303{
256 VIDEO_DECODER_SECAM | VIDEO_DECODER_AUTO; 304 struct saa7110 *decoder = to_saa7110(sd);
257 dc->inputs = SAA7110_MAX_INPUT; 305
258 dc->outputs = SAA7110_MAX_OUTPUT; 306 if (route->input < 0 || route->input >= SAA7110_MAX_INPUT) {
259 break; 307 v4l2_dbg(1, debug, sd, "input=%d not available\n", route->input);
308 return -EINVAL;
309 }
310 if (decoder->input != route->input) {
311 saa7110_selmux(sd, route->input);
312 v4l2_dbg(1, debug, sd, "switched to input=%d\n", route->input);
260 } 313 }
314 return 0;
315}
261 316
262 case DECODER_GET_STATUS: 317static int saa7110_s_stream(struct v4l2_subdev *sd, int enable)
263 { 318{
264 int status; 319 struct saa7110 *decoder = to_saa7110(sd);
265 int res = 0; 320
266 321 if (decoder->enable != enable) {
267 status = saa7110_read(client); 322 decoder->enable = enable;
268 v4l_dbg(1, debug, client, "status=0x%02x norm=%d\n", 323 saa7110_write(sd, 0x0E, enable ? 0x18 : 0x80);
269 status, decoder->norm); 324 v4l2_dbg(1, debug, sd, "YUV %s\n", enable ? "on" : "off");
270 if (!(status & 0x40))
271 res |= DECODER_STATUS_GOOD;
272 if (status & 0x03)
273 res |= DECODER_STATUS_COLOR;
274
275 switch (decoder->norm) {
276 case VIDEO_MODE_NTSC:
277 res |= DECODER_STATUS_NTSC;
278 break;
279 case VIDEO_MODE_PAL:
280 res |= DECODER_STATUS_PAL;
281 break;
282 case VIDEO_MODE_SECAM:
283 res |= DECODER_STATUS_SECAM;
284 break;
285 }
286 *(int *) arg = res;
287 break;
288 } 325 }
326 return 0;
327}
289 328
290 case DECODER_SET_NORM: 329static int saa7110_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc)
291 v = *(int *) arg; 330{
292 if (decoder->norm != v) { 331 switch (qc->id) {
293 decoder->norm = v; 332 case V4L2_CID_BRIGHTNESS:
294 //saa7110_write(client, 0x06, 0x03); 333 return v4l2_ctrl_query_fill(qc, 0, 255, 1, 128);
295 switch (v) { 334 case V4L2_CID_CONTRAST:
296 case VIDEO_MODE_NTSC: 335 case V4L2_CID_SATURATION:
297 saa7110_write(client, 0x0D, 0x86); 336 return v4l2_ctrl_query_fill(qc, 0, 127, 1, 64);
298 saa7110_write(client, 0x0F, 0x50); 337 case V4L2_CID_HUE:
299 saa7110_write(client, 0x11, 0x2C); 338 return v4l2_ctrl_query_fill(qc, -128, 127, 1, 0);
300 //saa7110_write(client, 0x2E, 0x81); 339 default:
301 v4l_dbg(1, debug, client, "switched to NTSC\n"); 340 return -EINVAL;
302 break; 341 }
303 case VIDEO_MODE_PAL: 342 return 0;
304 saa7110_write(client, 0x0D, 0x86); 343}
305 saa7110_write(client, 0x0F, 0x10);
306 saa7110_write(client, 0x11, 0x59);
307 //saa7110_write(client, 0x2E, 0x9A);
308 v4l_dbg(1, debug, client, "switched to PAL\n");
309 break;
310 case VIDEO_MODE_SECAM:
311 saa7110_write(client, 0x0D, 0x87);
312 saa7110_write(client, 0x0F, 0x10);
313 saa7110_write(client, 0x11, 0x59);
314 //saa7110_write(client, 0x2E, 0x9A);
315 v4l_dbg(1, debug, client, "switched to SECAM\n");
316 break;
317 case VIDEO_MODE_AUTO:
318 v4l_dbg(1, debug, client, "switched to AUTO\n");
319 decoder->norm = determine_norm(client);
320 *(int *) arg = decoder->norm;
321 break;
322 default:
323 return -EPERM;
324 }
325 }
326 break;
327 344
328 case DECODER_SET_INPUT: 345static int saa7110_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
329 v = *(int *) arg; 346{
330 if (v < 0 || v >= SAA7110_MAX_INPUT) { 347 struct saa7110 *decoder = to_saa7110(sd);
331 v4l_dbg(1, debug, client, "input=%d not available\n", v);
332 return -EINVAL;
333 }
334 if (decoder->input != v) {
335 saa7110_selmux(client, v);
336 v4l_dbg(1, debug, client, "switched to input=%d\n", v);
337 }
338 break;
339 348
340 case DECODER_SET_OUTPUT: 349 switch (ctrl->id) {
341 v = *(int *) arg; 350 case V4L2_CID_BRIGHTNESS:
342 /* not much choice of outputs */ 351 ctrl->value = decoder->bright;
343 if (v != 0)
344 return -EINVAL;
345 break; 352 break;
346 353 case V4L2_CID_CONTRAST:
347 case DECODER_ENABLE_OUTPUT: 354 ctrl->value = decoder->contrast;
348 v = *(int *) arg; 355 break;
349 if (decoder->enable != v) { 356 case V4L2_CID_SATURATION:
350 decoder->enable = v; 357 ctrl->value = decoder->sat;
351 saa7110_write(client, 0x0E, v ? 0x18 : 0x80); 358 break;
352 v4l_dbg(1, debug, client, "YUV %s\n", v ? "on" : "off"); 359 case V4L2_CID_HUE:
353 } 360 ctrl->value = decoder->hue;
354 break; 361 break;
362 default:
363 return -EINVAL;
364 }
365 return 0;
366}
355 367
356 case DECODER_SET_PICTURE: 368static int saa7110_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
357 { 369{
358 struct video_picture *pic = arg; 370 struct saa7110 *decoder = to_saa7110(sd);
359 371
360 if (decoder->bright != pic->brightness) { 372 switch (ctrl->id) {
361 /* We want 0 to 255 we get 0-65535 */ 373 case V4L2_CID_BRIGHTNESS:
362 decoder->bright = pic->brightness; 374 if (decoder->bright != ctrl->value) {
363 saa7110_write(client, 0x19, decoder->bright >> 8); 375 decoder->bright = ctrl->value;
364 } 376 saa7110_write(sd, 0x19, decoder->bright);
365 if (decoder->contrast != pic->contrast) {
366 /* We want 0 to 127 we get 0-65535 */
367 decoder->contrast = pic->contrast;
368 saa7110_write(client, 0x13,
369 decoder->contrast >> 9);
370 } 377 }
371 if (decoder->sat != pic->colour) { 378 break;
372 /* We want 0 to 127 we get 0-65535 */ 379 case V4L2_CID_CONTRAST:
373 decoder->sat = pic->colour; 380 if (decoder->contrast != ctrl->value) {
374 saa7110_write(client, 0x12, decoder->sat >> 9); 381 decoder->contrast = ctrl->value;
382 saa7110_write(sd, 0x13, decoder->contrast);
375 } 383 }
376 if (decoder->hue != pic->hue) { 384 break;
377 /* We want -128 to 127 we get 0-65535 */ 385 case V4L2_CID_SATURATION:
378 decoder->hue = pic->hue; 386 if (decoder->sat != ctrl->value) {
379 saa7110_write(client, 0x07, 387 decoder->sat = ctrl->value;
380 (decoder->hue >> 8) - 128); 388 saa7110_write(sd, 0x12, decoder->sat);
381 } 389 }
382 break; 390 break;
383 } 391 case V4L2_CID_HUE:
384 392 if (decoder->hue != ctrl->value) {
385 case DECODER_DUMP: 393 decoder->hue = ctrl->value;
386 if (!debug) 394 saa7110_write(sd, 0x07, decoder->hue);
387 break;
388 for (v = 0; v < SAA7110_NR_REG; v += 16) {
389 int j;
390 v4l_dbg(1, debug, client, "%02x:", v);
391 for (j = 0; j < 16 && v + j < SAA7110_NR_REG; j++)
392 printk(KERN_CONT " %02x", decoder->reg[v + j]);
393 printk(KERN_CONT "\n");
394 } 395 }
395 break; 396 break;
396
397 default: 397 default:
398 v4l_dbg(1, debug, client, "unknown command %08x\n", cmd);
399 return -EINVAL; 398 return -EINVAL;
400 } 399 }
401 return 0; 400 return 0;
402} 401}
403 402
403static int saa7110_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
404{
405 struct i2c_client *client = v4l2_get_subdevdata(sd);
406
407 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_SAA7110, 0);
408}
409
404/* ----------------------------------------------------------------------- */ 410/* ----------------------------------------------------------------------- */
405 411
406/* 412static const struct v4l2_subdev_core_ops saa7110_core_ops = {
407 * Generic i2c probe 413 .g_chip_ident = saa7110_g_chip_ident,
408 * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1' 414 .g_ctrl = saa7110_g_ctrl,
409 */ 415 .s_ctrl = saa7110_s_ctrl,
416 .queryctrl = saa7110_queryctrl,
417};
410 418
411static unsigned short normal_i2c[] = { 0x9c >> 1, 0x9e >> 1, I2C_CLIENT_END }; 419static const struct v4l2_subdev_tuner_ops saa7110_tuner_ops = {
420 .s_std = saa7110_s_std,
421};
412 422
413I2C_CLIENT_INSMOD; 423static const struct v4l2_subdev_video_ops saa7110_video_ops = {
424 .s_routing = saa7110_s_routing,
425 .s_stream = saa7110_s_stream,
426 .querystd = saa7110_querystd,
427 .g_input_status = saa7110_g_input_status,
428};
429
430static const struct v4l2_subdev_ops saa7110_ops = {
431 .core = &saa7110_core_ops,
432 .tuner = &saa7110_tuner_ops,
433 .video = &saa7110_video_ops,
434};
435
436/* ----------------------------------------------------------------------- */
414 437
415static int saa7110_probe(struct i2c_client *client, 438static int saa7110_probe(struct i2c_client *client,
416 const struct i2c_device_id *id) 439 const struct i2c_device_id *id)
417{ 440{
418 struct saa7110 *decoder; 441 struct saa7110 *decoder;
442 struct v4l2_subdev *sd;
419 int rv; 443 int rv;
420 444
421 /* Check if the adapter supports the needed features */ 445 /* Check if the adapter supports the needed features */
@@ -429,7 +453,9 @@ static int saa7110_probe(struct i2c_client *client,
429 decoder = kzalloc(sizeof(struct saa7110), GFP_KERNEL); 453 decoder = kzalloc(sizeof(struct saa7110), GFP_KERNEL);
430 if (!decoder) 454 if (!decoder)
431 return -ENOMEM; 455 return -ENOMEM;
432 decoder->norm = VIDEO_MODE_PAL; 456 sd = &decoder->sd;
457 v4l2_i2c_subdev_init(sd, client, &saa7110_ops);
458 decoder->norm = V4L2_STD_PAL;
433 decoder->input = 0; 459 decoder->input = 0;
434 decoder->enable = 1; 460 decoder->enable = 1;
435 decoder->bright = 32768; 461 decoder->bright = 32768;
@@ -437,30 +463,29 @@ static int saa7110_probe(struct i2c_client *client,
437 decoder->hue = 32768; 463 decoder->hue = 32768;
438 decoder->sat = 32768; 464 decoder->sat = 32768;
439 init_waitqueue_head(&decoder->wq); 465 init_waitqueue_head(&decoder->wq);
440 i2c_set_clientdata(client, decoder);
441 466
442 rv = saa7110_write_block(client, initseq, sizeof(initseq)); 467 rv = saa7110_write_block(sd, initseq, sizeof(initseq));
443 if (rv < 0) { 468 if (rv < 0) {
444 v4l_dbg(1, debug, client, "init status %d\n", rv); 469 v4l2_dbg(1, debug, sd, "init status %d\n", rv);
445 } else { 470 } else {
446 int ver, status; 471 int ver, status;
447 saa7110_write(client, 0x21, 0x10); 472 saa7110_write(sd, 0x21, 0x10);
448 saa7110_write(client, 0x0e, 0x18); 473 saa7110_write(sd, 0x0e, 0x18);
449 saa7110_write(client, 0x0D, 0x04); 474 saa7110_write(sd, 0x0D, 0x04);
450 ver = saa7110_read(client); 475 ver = saa7110_read(sd);
451 saa7110_write(client, 0x0D, 0x06); 476 saa7110_write(sd, 0x0D, 0x06);
452 //mdelay(150); 477 /*mdelay(150);*/
453 status = saa7110_read(client); 478 status = saa7110_read(sd);
454 v4l_dbg(1, debug, client, "version %x, status=0x%02x\n", 479 v4l2_dbg(1, debug, sd, "version %x, status=0x%02x\n",
455 ver, status); 480 ver, status);
456 saa7110_write(client, 0x0D, 0x86); 481 saa7110_write(sd, 0x0D, 0x86);
457 saa7110_write(client, 0x0F, 0x10); 482 saa7110_write(sd, 0x0F, 0x10);
458 saa7110_write(client, 0x11, 0x59); 483 saa7110_write(sd, 0x11, 0x59);
459 //saa7110_write(client, 0x2E, 0x9A); 484 /*saa7110_write(sd, 0x2E, 0x9A);*/
460 } 485 }
461 486
462 //saa7110_selmux(client,0); 487 /*saa7110_selmux(sd,0);*/
463 //determine_norm(client); 488 /*determine_norm(sd);*/
464 /* setup and implicit mode 0 select has been performed */ 489 /* setup and implicit mode 0 select has been performed */
465 490
466 return 0; 491 return 0;
@@ -468,7 +493,10 @@ static int saa7110_probe(struct i2c_client *client,
468 493
469static int saa7110_remove(struct i2c_client *client) 494static int saa7110_remove(struct i2c_client *client)
470{ 495{
471 kfree(i2c_get_clientdata(client)); 496 struct v4l2_subdev *sd = i2c_get_clientdata(client);
497
498 v4l2_device_unregister_subdev(sd);
499 kfree(to_saa7110(sd));
472 return 0; 500 return 0;
473} 501}
474 502
@@ -482,8 +510,6 @@ MODULE_DEVICE_TABLE(i2c, saa7110_id);
482 510
483static struct v4l2_i2c_driver_data v4l2_i2c_data = { 511static struct v4l2_i2c_driver_data v4l2_i2c_data = {
484 .name = "saa7110", 512 .name = "saa7110",
485 .driverid = I2C_DRIVERID_SAA7110,
486 .command = saa7110_command,
487 .probe = saa7110_probe, 513 .probe = saa7110_probe,
488 .remove = saa7110_remove, 514 .remove = saa7110_remove,
489 .id_table = saa7110_id, 515 .id_table = saa7110_id,
diff --git a/drivers/media/video/saa7111.c b/drivers/media/video/saa7111.c
deleted file mode 100644
index a4738a2fb4d3..000000000000
--- a/drivers/media/video/saa7111.c
+++ /dev/null
@@ -1,492 +0,0 @@
1/*
2 * saa7111 - Philips SAA7111A video decoder driver version 0.0.3
3 *
4 * Copyright (C) 1998 Dave Perks <dperks@ibm.net>
5 *
6 * Slight changes for video timing and attachment output by
7 * Wolfgang Scherr <scherr@net4you.net>
8 *
9 * Changes by Ronald Bultje <rbultje@ronald.bitfreak.net>
10 * - moved over to linux>=2.4.x i2c protocol (1/1/2003)
11 *
12 * Changes by Michael Hunold <michael@mihu.de>
13 * - implemented DECODER_SET_GPIO, DECODER_INIT, DECODER_SET_VBI_BYPASS
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 */
29
30#include <linux/module.h>
31#include <linux/types.h>
32#include <linux/ioctl.h>
33#include <asm/uaccess.h>
34#include <linux/i2c.h>
35#include <linux/i2c-id.h>
36#include <linux/videodev.h>
37#include <linux/video_decoder.h>
38#include <media/v4l2-common.h>
39#include <media/v4l2-i2c-drv-legacy.h>
40
41MODULE_DESCRIPTION("Philips SAA7111 video decoder driver");
42MODULE_AUTHOR("Dave Perks");
43MODULE_LICENSE("GPL");
44
45static int debug;
46module_param(debug, int, 0644);
47MODULE_PARM_DESC(debug, "Debug level (0-1)");
48
49/* ----------------------------------------------------------------------- */
50
51#define SAA7111_NR_REG 0x18
52
53struct saa7111 {
54 unsigned char reg[SAA7111_NR_REG];
55
56 int norm;
57 int input;
58 int enable;
59};
60
61/* ----------------------------------------------------------------------- */
62
63static inline int saa7111_write(struct i2c_client *client, u8 reg, u8 value)
64{
65 struct saa7111 *decoder = i2c_get_clientdata(client);
66
67 decoder->reg[reg] = value;
68 return i2c_smbus_write_byte_data(client, reg, value);
69}
70
71static inline void saa7111_write_if_changed(struct i2c_client *client, u8 reg, u8 value)
72{
73 struct saa7111 *decoder = i2c_get_clientdata(client);
74
75 if (decoder->reg[reg] != value) {
76 decoder->reg[reg] = value;
77 i2c_smbus_write_byte_data(client, reg, value);
78 }
79}
80
81static int saa7111_write_block(struct i2c_client *client, const u8 *data, unsigned int len)
82{
83 int ret = -1;
84 u8 reg;
85
86 /* the saa7111 has an autoincrement function, use it if
87 * the adapter understands raw I2C */
88 if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
89 /* do raw I2C, not smbus compatible */
90 struct saa7111 *decoder = i2c_get_clientdata(client);
91 u8 block_data[32];
92 int block_len;
93
94 while (len >= 2) {
95 block_len = 0;
96 block_data[block_len++] = reg = data[0];
97 do {
98 block_data[block_len++] =
99 decoder->reg[reg++] = data[1];
100 len -= 2;
101 data += 2;
102 } while (len >= 2 && data[0] == reg && block_len < 32);
103 ret = i2c_master_send(client, block_data, block_len);
104 if (ret < 0)
105 break;
106 }
107 } else {
108 /* do some slow I2C emulation kind of thing */
109 while (len >= 2) {
110 reg = *data++;
111 ret = saa7111_write(client, reg, *data++);
112 if (ret < 0)
113 break;
114 len -= 2;
115 }
116 }
117
118 return ret;
119}
120
121static int saa7111_init_decoder(struct i2c_client *client,
122 struct video_decoder_init *init)
123{
124 return saa7111_write_block(client, init->data, init->len);
125}
126
127static inline int saa7111_read(struct i2c_client *client, u8 reg)
128{
129 return i2c_smbus_read_byte_data(client, reg);
130}
131
132/* ----------------------------------------------------------------------- */
133
134static const unsigned char saa7111_i2c_init[] = {
135 0x00, 0x00, /* 00 - ID byte */
136 0x01, 0x00, /* 01 - reserved */
137
138 /*front end */
139 0x02, 0xd0, /* 02 - FUSE=3, GUDL=2, MODE=0 */
140 0x03, 0x23, /* 03 - HLNRS=0, VBSL=1, WPOFF=0,
141 * HOLDG=0, GAFIX=0, GAI1=256, GAI2=256 */
142 0x04, 0x00, /* 04 - GAI1=256 */
143 0x05, 0x00, /* 05 - GAI2=256 */
144
145 /* decoder */
146 0x06, 0xf3, /* 06 - HSB at 13(50Hz) / 17(60Hz)
147 * pixels after end of last line */
148 /*0x07, 0x13, * 07 - HSS at 113(50Hz) / 117(60Hz) pixels
149 * after end of last line */
150 0x07, 0xe8, /* 07 - HSS seems to be needed to
151 * work with NTSC, too */
152 0x08, 0xc8, /* 08 - AUFD=1, FSEL=1, EXFIL=0,
153 * VTRC=1, HPLL=0, VNOI=0 */
154 0x09, 0x01, /* 09 - BYPS=0, PREF=0, BPSS=0,
155 * VBLB=0, UPTCV=0, APER=1 */
156 0x0a, 0x80, /* 0a - BRIG=128 */
157 0x0b, 0x47, /* 0b - CONT=1.109 */
158 0x0c, 0x40, /* 0c - SATN=1.0 */
159 0x0d, 0x00, /* 0d - HUE=0 */
160 0x0e, 0x01, /* 0e - CDTO=0, CSTD=0, DCCF=0,
161 * FCTC=0, CHBW=1 */
162 0x0f, 0x00, /* 0f - reserved */
163 0x10, 0x48, /* 10 - OFTS=1, HDEL=0, VRLN=1, YDEL=0 */
164 0x11, 0x1c, /* 11 - GPSW=0, CM99=0, FECO=0, COMPO=1,
165 * OEYC=1, OEHV=1, VIPB=0, COLO=0 */
166 0x12, 0x00, /* 12 - output control 2 */
167 0x13, 0x00, /* 13 - output control 3 */
168 0x14, 0x00, /* 14 - reserved */
169 0x15, 0x00, /* 15 - VBI */
170 0x16, 0x00, /* 16 - VBI */
171 0x17, 0x00, /* 17 - VBI */
172};
173
174static int saa7111_command(struct i2c_client *client, unsigned cmd, void *arg)
175{
176 struct saa7111 *decoder = i2c_get_clientdata(client);
177
178 switch (cmd) {
179 case 0:
180 break;
181 case DECODER_INIT:
182 {
183 struct video_decoder_init *init = arg;
184 struct video_decoder_init vdi;
185
186 if (NULL != init)
187 return saa7111_init_decoder(client, init);
188 vdi.data = saa7111_i2c_init;
189 vdi.len = sizeof(saa7111_i2c_init);
190 return saa7111_init_decoder(client, &vdi);
191 }
192
193 case DECODER_DUMP:
194 {
195 int i;
196
197 for (i = 0; i < SAA7111_NR_REG; i += 16) {
198 int j;
199
200 v4l_info(client, "%03x", i);
201 for (j = 0; j < 16 && i + j < SAA7111_NR_REG; ++j) {
202 printk(KERN_CONT " %02x",
203 saa7111_read(client, i + j));
204 }
205 printk(KERN_CONT "\n");
206 }
207 break;
208 }
209
210 case DECODER_GET_CAPABILITIES:
211 {
212 struct video_decoder_capability *cap = arg;
213
214 cap->flags = VIDEO_DECODER_PAL |
215 VIDEO_DECODER_NTSC |
216 VIDEO_DECODER_SECAM |
217 VIDEO_DECODER_AUTO |
218 VIDEO_DECODER_CCIR;
219 cap->inputs = 8;
220 cap->outputs = 1;
221 break;
222 }
223
224 case DECODER_GET_STATUS:
225 {
226 int *iarg = arg;
227 int status;
228 int res;
229
230 status = saa7111_read(client, 0x1f);
231 v4l_dbg(1, debug, client, "status: 0x%02x\n", status);
232 res = 0;
233 if ((status & (1 << 6)) == 0) {
234 res |= DECODER_STATUS_GOOD;
235 }
236 switch (decoder->norm) {
237 case VIDEO_MODE_NTSC:
238 res |= DECODER_STATUS_NTSC;
239 break;
240 case VIDEO_MODE_PAL:
241 res |= DECODER_STATUS_PAL;
242 break;
243 case VIDEO_MODE_SECAM:
244 res |= DECODER_STATUS_SECAM;
245 break;
246 default:
247 case VIDEO_MODE_AUTO:
248 if ((status & (1 << 5)) != 0) {
249 res |= DECODER_STATUS_NTSC;
250 } else {
251 res |= DECODER_STATUS_PAL;
252 }
253 break;
254 }
255 if ((status & (1 << 0)) != 0) {
256 res |= DECODER_STATUS_COLOR;
257 }
258 *iarg = res;
259 break;
260 }
261
262 case DECODER_SET_GPIO:
263 {
264 int *iarg = arg;
265 if (0 != *iarg) {
266 saa7111_write(client, 0x11,
267 (decoder->reg[0x11] | 0x80));
268 } else {
269 saa7111_write(client, 0x11,
270 (decoder->reg[0x11] & 0x7f));
271 }
272 break;
273 }
274
275 case DECODER_SET_VBI_BYPASS:
276 {
277 int *iarg = arg;
278 if (0 != *iarg) {
279 saa7111_write(client, 0x13,
280 (decoder->reg[0x13] & 0xf0) | 0x0a);
281 } else {
282 saa7111_write(client, 0x13,
283 (decoder->reg[0x13] & 0xf0));
284 }
285 break;
286 }
287
288 case DECODER_SET_NORM:
289 {
290 int *iarg = arg;
291
292 switch (*iarg) {
293
294 case VIDEO_MODE_NTSC:
295 saa7111_write(client, 0x08,
296 (decoder->reg[0x08] & 0x3f) | 0x40);
297 saa7111_write(client, 0x0e,
298 (decoder->reg[0x0e] & 0x8f));
299 break;
300
301 case VIDEO_MODE_PAL:
302 saa7111_write(client, 0x08,
303 (decoder->reg[0x08] & 0x3f) | 0x00);
304 saa7111_write(client, 0x0e,
305 (decoder->reg[0x0e] & 0x8f));
306 break;
307
308 case VIDEO_MODE_SECAM:
309 saa7111_write(client, 0x08,
310 (decoder->reg[0x08] & 0x3f) | 0x00);
311 saa7111_write(client, 0x0e,
312 (decoder->reg[0x0e] & 0x8f) | 0x50);
313 break;
314
315 case VIDEO_MODE_AUTO:
316 saa7111_write(client, 0x08,
317 (decoder->reg[0x08] & 0x3f) | 0x80);
318 saa7111_write(client, 0x0e,
319 (decoder->reg[0x0e] & 0x8f));
320 break;
321
322 default:
323 return -EINVAL;
324
325 }
326 decoder->norm = *iarg;
327 break;
328 }
329
330 case DECODER_SET_INPUT:
331 {
332 int *iarg = arg;
333
334 if (*iarg < 0 || *iarg > 7) {
335 return -EINVAL;
336 }
337
338 if (decoder->input != *iarg) {
339 decoder->input = *iarg;
340 /* select mode */
341 saa7111_write(client, 0x02,
342 (decoder->
343 reg[0x02] & 0xf8) | decoder->input);
344 /* bypass chrominance trap for modes 4..7 */
345 saa7111_write(client, 0x09,
346 (decoder->
347 reg[0x09] & 0x7f) | ((decoder->
348 input >
349 3) ? 0x80 :
350 0));
351 }
352 break;
353 }
354
355 case DECODER_SET_OUTPUT:
356 {
357 int *iarg = arg;
358
359 /* not much choice of outputs */
360 if (*iarg != 0) {
361 return -EINVAL;
362 }
363 break;
364 }
365
366 case DECODER_ENABLE_OUTPUT:
367 {
368 int *iarg = arg;
369 int enable = (*iarg != 0);
370
371 if (decoder->enable != enable) {
372 decoder->enable = enable;
373
374 /* RJ: If output should be disabled (for
375 * playing videos), we also need a open PLL.
376 * The input is set to 0 (where no input
377 * source is connected), although this
378 * is not necessary.
379 *
380 * If output should be enabled, we have to
381 * reverse the above.
382 */
383
384 if (decoder->enable) {
385 saa7111_write(client, 0x02,
386 (decoder->
387 reg[0x02] & 0xf8) |
388 decoder->input);
389 saa7111_write(client, 0x08,
390 (decoder->reg[0x08] & 0xfb));
391 saa7111_write(client, 0x11,
392 (decoder->
393 reg[0x11] & 0xf3) | 0x0c);
394 } else {
395 saa7111_write(client, 0x02,
396 (decoder->reg[0x02] & 0xf8));
397 saa7111_write(client, 0x08,
398 (decoder->
399 reg[0x08] & 0xfb) | 0x04);
400 saa7111_write(client, 0x11,
401 (decoder->reg[0x11] & 0xf3));
402 }
403 }
404 break;
405 }
406
407 case DECODER_SET_PICTURE:
408 {
409 struct video_picture *pic = arg;
410
411 /* We want 0 to 255 we get 0-65535 */
412 saa7111_write_if_changed(client, 0x0a, pic->brightness >> 8);
413 /* We want 0 to 127 we get 0-65535 */
414 saa7111_write(client, 0x0b, pic->contrast >> 9);
415 /* We want 0 to 127 we get 0-65535 */
416 saa7111_write(client, 0x0c, pic->colour >> 9);
417 /* We want -128 to 127 we get 0-65535 */
418 saa7111_write(client, 0x0d, (pic->hue - 32768) >> 8);
419 break;
420 }
421
422 default:
423 return -EINVAL;
424 }
425
426 return 0;
427}
428
429/* ----------------------------------------------------------------------- */
430
431static unsigned short normal_i2c[] = { 0x48 >> 1, I2C_CLIENT_END };
432
433I2C_CLIENT_INSMOD;
434
435static int saa7111_probe(struct i2c_client *client,
436 const struct i2c_device_id *id)
437{
438 int i;
439 struct saa7111 *decoder;
440 struct video_decoder_init vdi;
441
442 /* Check if the adapter supports the needed features */
443 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
444 return -ENODEV;
445
446 v4l_info(client, "chip found @ 0x%x (%s)\n",
447 client->addr << 1, client->adapter->name);
448
449 decoder = kzalloc(sizeof(struct saa7111), GFP_KERNEL);
450 if (decoder == NULL) {
451 kfree(client);
452 return -ENOMEM;
453 }
454 decoder->norm = VIDEO_MODE_NTSC;
455 decoder->input = 0;
456 decoder->enable = 1;
457 i2c_set_clientdata(client, decoder);
458
459 vdi.data = saa7111_i2c_init;
460 vdi.len = sizeof(saa7111_i2c_init);
461 i = saa7111_init_decoder(client, &vdi);
462 if (i < 0) {
463 v4l_dbg(1, debug, client, "init status %d\n", i);
464 } else {
465 v4l_dbg(1, debug, client, "revision %x\n",
466 saa7111_read(client, 0x00) >> 4);
467 }
468 return 0;
469}
470
471static int saa7111_remove(struct i2c_client *client)
472{
473 kfree(i2c_get_clientdata(client));
474 return 0;
475}
476
477/* ----------------------------------------------------------------------- */
478
479static const struct i2c_device_id saa7111_id[] = {
480 { "saa7111_old", 0 }, /* "saa7111" maps to the saa7115 driver */
481 { }
482};
483MODULE_DEVICE_TABLE(i2c, saa7111_id);
484
485static struct v4l2_i2c_driver_data v4l2_i2c_data = {
486 .name = "saa7111",
487 .driverid = I2C_DRIVERID_SAA7111A,
488 .command = saa7111_command,
489 .probe = saa7111_probe,
490 .remove = saa7111_remove,
491 .id_table = saa7111_id,
492};
diff --git a/drivers/media/video/saa7114.c b/drivers/media/video/saa7114.c
deleted file mode 100644
index 7ca709fda5f4..000000000000
--- a/drivers/media/video/saa7114.c
+++ /dev/null
@@ -1,1068 +0,0 @@
1/*
2 * saa7114 - Philips SAA7114H video decoder driver version 0.0.1
3 *
4 * Copyright (C) 2002 Maxim Yevtyushkin <max@linuxmedialabs.com>
5 *
6 * Based on saa7111 driver by Dave Perks
7 *
8 * Copyright (C) 1998 Dave Perks <dperks@ibm.net>
9 *
10 * Slight changes for video timing and attachment output by
11 * Wolfgang Scherr <scherr@net4you.net>
12 *
13 * Changes by Ronald Bultje <rbultje@ronald.bitfreak.net>
14 * - moved over to linux>=2.4.x i2c protocol (1/1/2003)
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 */
30
31#include <linux/module.h>
32#include <linux/types.h>
33#include <linux/ioctl.h>
34#include <asm/uaccess.h>
35#include <linux/i2c.h>
36#include <linux/i2c-id.h>
37#include <linux/videodev.h>
38#include <linux/video_decoder.h>
39#include <media/v4l2-common.h>
40#include <media/v4l2-i2c-drv-legacy.h>
41
42MODULE_DESCRIPTION("Philips SAA7114H video decoder driver");
43MODULE_AUTHOR("Maxim Yevtyushkin");
44MODULE_LICENSE("GPL");
45
46static int debug;
47module_param(debug, int, 0);
48MODULE_PARM_DESC(debug, "Debug level (0-1)");
49
50/* ----------------------------------------------------------------------- */
51
52struct saa7114 {
53 unsigned char reg[0xf0 * 2];
54
55 int norm;
56 int input;
57 int enable;
58 int bright;
59 int contrast;
60 int hue;
61 int sat;
62 int playback;
63};
64
65#define I2C_DELAY 10
66
67
68//#define SAA_7114_NTSC_HSYNC_START (-3)
69//#define SAA_7114_NTSC_HSYNC_STOP (-18)
70
71#define SAA_7114_NTSC_HSYNC_START (-17)
72#define SAA_7114_NTSC_HSYNC_STOP (-32)
73
74//#define SAA_7114_NTSC_HOFFSET (5)
75#define SAA_7114_NTSC_HOFFSET (6)
76#define SAA_7114_NTSC_VOFFSET (10)
77#define SAA_7114_NTSC_WIDTH (720)
78#define SAA_7114_NTSC_HEIGHT (250)
79
80#define SAA_7114_SECAM_HSYNC_START (-17)
81#define SAA_7114_SECAM_HSYNC_STOP (-32)
82
83#define SAA_7114_SECAM_HOFFSET (2)
84#define SAA_7114_SECAM_VOFFSET (10)
85#define SAA_7114_SECAM_WIDTH (720)
86#define SAA_7114_SECAM_HEIGHT (300)
87
88#define SAA_7114_PAL_HSYNC_START (-17)
89#define SAA_7114_PAL_HSYNC_STOP (-32)
90
91#define SAA_7114_PAL_HOFFSET (2)
92#define SAA_7114_PAL_VOFFSET (10)
93#define SAA_7114_PAL_WIDTH (720)
94#define SAA_7114_PAL_HEIGHT (300)
95
96
97
98#define SAA_7114_VERTICAL_CHROMA_OFFSET 0 //0x50504040
99#define SAA_7114_VERTICAL_LUMA_OFFSET 0
100
101#define REG_ADDR(x) (((x) << 1) + 1)
102#define LOBYTE(x) ((unsigned char)((x) & 0xff))
103#define HIBYTE(x) ((unsigned char)(((x) >> 8) & 0xff))
104#define LOWORD(x) ((unsigned short int)((x) & 0xffff))
105#define HIWORD(x) ((unsigned short int)(((x) >> 16) & 0xffff))
106
107
108/* ----------------------------------------------------------------------- */
109
110static inline int saa7114_write(struct i2c_client *client, u8 reg, u8 value)
111{
112 return i2c_smbus_write_byte_data(client, reg, value);
113}
114
115static int saa7114_write_block(struct i2c_client *client, const u8 *data, unsigned int len)
116{
117 int ret = -1;
118 u8 reg;
119
120 /* the saa7114 has an autoincrement function, use it if
121 * the adapter understands raw I2C */
122 if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
123 /* do raw I2C, not smbus compatible */
124 u8 block_data[32];
125 int block_len;
126
127 while (len >= 2) {
128 block_len = 0;
129 block_data[block_len++] = reg = data[0];
130 do {
131 block_data[block_len++] = data[1];
132 reg++;
133 len -= 2;
134 data += 2;
135 } while (len >= 2 && data[0] == reg && block_len < 32);
136 ret = i2c_master_send(client, block_data, block_len);
137 if (ret < 0)
138 break;
139 }
140 } else {
141 /* do some slow I2C emulation kind of thing */
142 while (len >= 2) {
143 reg = *data++;
144 ret = saa7114_write(client, reg, *data++);
145 if (ret < 0)
146 break;
147 len -= 2;
148 }
149 }
150
151 return ret;
152}
153
154static inline int saa7114_read(struct i2c_client *client, u8 reg)
155{
156 return i2c_smbus_read_byte_data(client, reg);
157}
158
159/* ----------------------------------------------------------------------- */
160
161// initially set NTSC, composite
162
163
164static const unsigned char init[] = {
165 0x00, 0x00, /* 00 - ID byte , chip version,
166 * read only */
167 0x01, 0x08, /* 01 - X,X,X,X, IDEL3 to IDEL0 -
168 * horizontal increment delay,
169 * recommended position */
170 0x02, 0x00, /* 02 - FUSE=3, GUDL=2, MODE=0 ;
171 * input control */
172 0x03, 0x10, /* 03 - HLNRS=0, VBSL=1, WPOFF=0,
173 * HOLDG=0, GAFIX=0, GAI1=256, GAI2=256 */
174 0x04, 0x90, /* 04 - GAI1=256 */
175 0x05, 0x90, /* 05 - GAI2=256 */
176 0x06, SAA_7114_NTSC_HSYNC_START, /* 06 - HSB: hsync start,
177 * depends on the video standard */
178 0x07, SAA_7114_NTSC_HSYNC_STOP, /* 07 - HSS: hsync stop, depends
179 *on the video standard */
180 0x08, 0xb8, /* 08 - AUFD=1, FSEL=1, EXFIL=0, VTRC=1,
181 * HPLL: free running in playback, locked
182 * in capture, VNOI=0 */
183 0x09, 0x80, /* 09 - BYPS=0, PREF=0, BPSS=0, VBLB=0,
184 * UPTCV=0, APER=1; depends from input */
185 0x0a, 0x80, /* 0a - BRIG=128 */
186 0x0b, 0x44, /* 0b - CONT=1.109 */
187 0x0c, 0x40, /* 0c - SATN=1.0 */
188 0x0d, 0x00, /* 0d - HUE=0 */
189 0x0e, 0x84, /* 0e - CDTO, CSTD2 to 0, DCVF, FCTC,
190 * CCOMB; depends from video standard */
191 0x0f, 0x24, /* 0f - ACGC,CGAIN6 to CGAIN0; depends
192 * from video standard */
193 0x10, 0x03, /* 10 - OFFU1 to 0, OFFV1 to 0, CHBW,
194 * LCBW2 to 0 */
195 0x11, 0x59, /* 11 - COLO, RTP1, HEDL1 to 0, RTP0,
196 * YDEL2 to 0 */
197 0x12, 0xc9, /* 12 - RT signal control RTSE13 to 10
198 * and 03 to 00 */
199 0x13, 0x80, /* 13 - RT/X port output control */
200 0x14, 0x00, /* 14 - analog, ADC, compatibility control */
201 0x15, 0x00, /* 15 - VGATE start FID change */
202 0x16, 0xfe, /* 16 - VGATE stop */
203 0x17, 0x00, /* 17 - Misc., VGATE MSBs */
204 0x18, 0x40, /* RAWG */
205 0x19, 0x80, /* RAWO */
206 0x1a, 0x00,
207 0x1b, 0x00,
208 0x1c, 0x00,
209 0x1d, 0x00,
210 0x1e, 0x00,
211 0x1f, 0x00, /* status byte, read only */
212 0x20, 0x00, /* video decoder reserved part */
213 0x21, 0x00,
214 0x22, 0x00,
215 0x23, 0x00,
216 0x24, 0x00,
217 0x25, 0x00,
218 0x26, 0x00,
219 0x27, 0x00,
220 0x28, 0x00,
221 0x29, 0x00,
222 0x2a, 0x00,
223 0x2b, 0x00,
224 0x2c, 0x00,
225 0x2d, 0x00,
226 0x2e, 0x00,
227 0x2f, 0x00,
228 0x30, 0xbc, /* audio clock generator */
229 0x31, 0xdf,
230 0x32, 0x02,
231 0x33, 0x00,
232 0x34, 0xcd,
233 0x35, 0xcc,
234 0x36, 0x3a,
235 0x37, 0x00,
236 0x38, 0x03,
237 0x39, 0x10,
238 0x3a, 0x00,
239 0x3b, 0x00,
240 0x3c, 0x00,
241 0x3d, 0x00,
242 0x3e, 0x00,
243 0x3f, 0x00,
244 0x40, 0x00, /* VBI data slicer */
245 0x41, 0xff,
246 0x42, 0xff,
247 0x43, 0xff,
248 0x44, 0xff,
249 0x45, 0xff,
250 0x46, 0xff,
251 0x47, 0xff,
252 0x48, 0xff,
253 0x49, 0xff,
254 0x4a, 0xff,
255 0x4b, 0xff,
256 0x4c, 0xff,
257 0x4d, 0xff,
258 0x4e, 0xff,
259 0x4f, 0xff,
260 0x50, 0xff,
261 0x51, 0xff,
262 0x52, 0xff,
263 0x53, 0xff,
264 0x54, 0xff,
265 0x55, 0xff,
266 0x56, 0xff,
267 0x57, 0xff,
268 0x58, 0x40, // framing code
269 0x59, 0x47, // horizontal offset
270 0x5a, 0x06, // vertical offset
271 0x5b, 0x83, // field offset
272 0x5c, 0x00, // reserved
273 0x5d, 0x3e, // header and data
274 0x5e, 0x00, // sliced data
275 0x5f, 0x00, // reserved
276 0x60, 0x00, /* video decoder reserved part */
277 0x61, 0x00,
278 0x62, 0x00,
279 0x63, 0x00,
280 0x64, 0x00,
281 0x65, 0x00,
282 0x66, 0x00,
283 0x67, 0x00,
284 0x68, 0x00,
285 0x69, 0x00,
286 0x6a, 0x00,
287 0x6b, 0x00,
288 0x6c, 0x00,
289 0x6d, 0x00,
290 0x6e, 0x00,
291 0x6f, 0x00,
292 0x70, 0x00, /* video decoder reserved part */
293 0x71, 0x00,
294 0x72, 0x00,
295 0x73, 0x00,
296 0x74, 0x00,
297 0x75, 0x00,
298 0x76, 0x00,
299 0x77, 0x00,
300 0x78, 0x00,
301 0x79, 0x00,
302 0x7a, 0x00,
303 0x7b, 0x00,
304 0x7c, 0x00,
305 0x7d, 0x00,
306 0x7e, 0x00,
307 0x7f, 0x00,
308 0x80, 0x00, /* X-port, I-port and scaler */
309 0x81, 0x00,
310 0x82, 0x00,
311 0x83, 0x00,
312 0x84, 0xc5,
313 0x85, 0x0d, // hsync and vsync ?
314 0x86, 0x40,
315 0x87, 0x01,
316 0x88, 0x00,
317 0x89, 0x00,
318 0x8a, 0x00,
319 0x8b, 0x00,
320 0x8c, 0x00,
321 0x8d, 0x00,
322 0x8e, 0x00,
323 0x8f, 0x00,
324 0x90, 0x03, /* Task A definition */
325 0x91, 0x08,
326 0x92, 0x00,
327 0x93, 0x40,
328 0x94, 0x00, // window settings
329 0x95, 0x00,
330 0x96, 0x00,
331 0x97, 0x00,
332 0x98, 0x00,
333 0x99, 0x00,
334 0x9a, 0x00,
335 0x9b, 0x00,
336 0x9c, 0x00,
337 0x9d, 0x00,
338 0x9e, 0x00,
339 0x9f, 0x00,
340 0xa0, 0x01, /* horizontal integer prescaling ratio */
341 0xa1, 0x00, /* horizontal prescaler accumulation
342 * sequence length */
343 0xa2, 0x00, /* UV FIR filter, Y FIR filter, prescaler
344 * DC gain */
345 0xa3, 0x00,
346 0xa4, 0x80, // luminance brightness
347 0xa5, 0x40, // luminance gain
348 0xa6, 0x40, // chrominance saturation
349 0xa7, 0x00,
350 0xa8, 0x00, // horizontal luminance scaling increment
351 0xa9, 0x04,
352 0xaa, 0x00, // horizontal luminance phase offset
353 0xab, 0x00,
354 0xac, 0x00, // horizontal chrominance scaling increment
355 0xad, 0x02,
356 0xae, 0x00, // horizontal chrominance phase offset
357 0xaf, 0x00,
358 0xb0, 0x00, // vertical luminance scaling increment
359 0xb1, 0x04,
360 0xb2, 0x00, // vertical chrominance scaling increment
361 0xb3, 0x04,
362 0xb4, 0x00,
363 0xb5, 0x00,
364 0xb6, 0x00,
365 0xb7, 0x00,
366 0xb8, 0x00,
367 0xb9, 0x00,
368 0xba, 0x00,
369 0xbb, 0x00,
370 0xbc, 0x00,
371 0xbd, 0x00,
372 0xbe, 0x00,
373 0xbf, 0x00,
374 0xc0, 0x02, // Task B definition
375 0xc1, 0x08,
376 0xc2, 0x00,
377 0xc3, 0x40,
378 0xc4, 0x00, // window settings
379 0xc5, 0x00,
380 0xc6, 0x00,
381 0xc7, 0x00,
382 0xc8, 0x00,
383 0xc9, 0x00,
384 0xca, 0x00,
385 0xcb, 0x00,
386 0xcc, 0x00,
387 0xcd, 0x00,
388 0xce, 0x00,
389 0xcf, 0x00,
390 0xd0, 0x01, // horizontal integer prescaling ratio
391 0xd1, 0x00, // horizontal prescaler accumulation sequence length
392 0xd2, 0x00, // UV FIR filter, Y FIR filter, prescaler DC gain
393 0xd3, 0x00,
394 0xd4, 0x80, // luminance brightness
395 0xd5, 0x40, // luminance gain
396 0xd6, 0x40, // chrominance saturation
397 0xd7, 0x00,
398 0xd8, 0x00, // horizontal luminance scaling increment
399 0xd9, 0x04,
400 0xda, 0x00, // horizontal luminance phase offset
401 0xdb, 0x00,
402 0xdc, 0x00, // horizontal chrominance scaling increment
403 0xdd, 0x02,
404 0xde, 0x00, // horizontal chrominance phase offset
405 0xdf, 0x00,
406 0xe0, 0x00, // vertical luminance scaling increment
407 0xe1, 0x04,
408 0xe2, 0x00, // vertical chrominance scaling increment
409 0xe3, 0x04,
410 0xe4, 0x00,
411 0xe5, 0x00,
412 0xe6, 0x00,
413 0xe7, 0x00,
414 0xe8, 0x00,
415 0xe9, 0x00,
416 0xea, 0x00,
417 0xeb, 0x00,
418 0xec, 0x00,
419 0xed, 0x00,
420 0xee, 0x00,
421 0xef, 0x00
422};
423
424static int saa7114_command(struct i2c_client *client, unsigned cmd, void *arg)
425{
426 struct saa7114 *decoder = i2c_get_clientdata(client);
427
428 switch (cmd) {
429 case 0:
430 //dprintk(1, KERN_INFO "%s: writing init\n", I2C_NAME(client));
431 //saa7114_write_block(client, init, sizeof(init));
432 break;
433
434 case DECODER_DUMP:
435 {
436 int i;
437
438 if (!debug)
439 break;
440 v4l_info(client, "decoder dump\n");
441
442 for (i = 0; i < 32; i += 16) {
443 int j;
444
445 v4l_info(client, "%03x", i);
446 for (j = 0; j < 16; ++j) {
447 printk(KERN_CONT " %02x",
448 saa7114_read(client, i + j));
449 }
450 printk(KERN_CONT "\n");
451 }
452 break;
453 }
454
455 case DECODER_GET_CAPABILITIES:
456 {
457 struct video_decoder_capability *cap = arg;
458
459 v4l_dbg(1, debug, client, "get capabilities\n");
460
461 cap->flags = VIDEO_DECODER_PAL |
462 VIDEO_DECODER_NTSC |
463 VIDEO_DECODER_AUTO |
464 VIDEO_DECODER_CCIR;
465 cap->inputs = 8;
466 cap->outputs = 1;
467 break;
468 }
469
470 case DECODER_GET_STATUS:
471 {
472 int *iarg = arg;
473 int status;
474 int res;
475
476 status = saa7114_read(client, 0x1f);
477
478 v4l_dbg(1, debug, client, "status: 0x%02x\n", status);
479 res = 0;
480 if ((status & (1 << 6)) == 0) {
481 res |= DECODER_STATUS_GOOD;
482 }
483 switch (decoder->norm) {
484 case VIDEO_MODE_NTSC:
485 res |= DECODER_STATUS_NTSC;
486 break;
487 case VIDEO_MODE_PAL:
488 res |= DECODER_STATUS_PAL;
489 break;
490 case VIDEO_MODE_SECAM:
491 res |= DECODER_STATUS_SECAM;
492 break;
493 default:
494 case VIDEO_MODE_AUTO:
495 if ((status & (1 << 5)) != 0) {
496 res |= DECODER_STATUS_NTSC;
497 } else {
498 res |= DECODER_STATUS_PAL;
499 }
500 break;
501 }
502 if ((status & (1 << 0)) != 0) {
503 res |= DECODER_STATUS_COLOR;
504 }
505 *iarg = res;
506 break;
507 }
508
509 case DECODER_SET_NORM:
510 {
511 int *iarg = arg;
512
513 short int hoff = 0, voff = 0, w = 0, h = 0;
514
515 v4l_dbg(1, debug, client, "set norm\n");
516
517 switch (*iarg) {
518 case VIDEO_MODE_NTSC:
519 v4l_dbg(1, debug, client, "NTSC\n");
520 decoder->reg[REG_ADDR(0x06)] =
521 SAA_7114_NTSC_HSYNC_START;
522 decoder->reg[REG_ADDR(0x07)] =
523 SAA_7114_NTSC_HSYNC_STOP;
524
525 decoder->reg[REG_ADDR(0x08)] = decoder->playback ? 0x7c : 0xb8; // PLL free when playback, PLL close when capture
526
527 decoder->reg[REG_ADDR(0x0e)] = 0x85;
528 decoder->reg[REG_ADDR(0x0f)] = 0x24;
529
530 hoff = SAA_7114_NTSC_HOFFSET;
531 voff = SAA_7114_NTSC_VOFFSET;
532 w = SAA_7114_NTSC_WIDTH;
533 h = SAA_7114_NTSC_HEIGHT;
534
535 break;
536
537 case VIDEO_MODE_PAL:
538 v4l_dbg(1, debug, client, "PAL\n");
539 decoder->reg[REG_ADDR(0x06)] =
540 SAA_7114_PAL_HSYNC_START;
541 decoder->reg[REG_ADDR(0x07)] =
542 SAA_7114_PAL_HSYNC_STOP;
543
544 decoder->reg[REG_ADDR(0x08)] = decoder->playback ? 0x7c : 0xb8; // PLL free when playback, PLL close when capture
545
546 decoder->reg[REG_ADDR(0x0e)] = 0x81;
547 decoder->reg[REG_ADDR(0x0f)] = 0x24;
548
549 hoff = SAA_7114_PAL_HOFFSET;
550 voff = SAA_7114_PAL_VOFFSET;
551 w = SAA_7114_PAL_WIDTH;
552 h = SAA_7114_PAL_HEIGHT;
553
554 break;
555
556 default:
557 v4l_dbg(1, debug, client, "Unknown video mode\n");
558 return -EINVAL;
559 }
560
561
562 decoder->reg[REG_ADDR(0x94)] = LOBYTE(hoff); // hoffset low
563 decoder->reg[REG_ADDR(0x95)] = HIBYTE(hoff) & 0x0f; // hoffset high
564 decoder->reg[REG_ADDR(0x96)] = LOBYTE(w); // width low
565 decoder->reg[REG_ADDR(0x97)] = HIBYTE(w) & 0x0f; // width high
566 decoder->reg[REG_ADDR(0x98)] = LOBYTE(voff); // voffset low
567 decoder->reg[REG_ADDR(0x99)] = HIBYTE(voff) & 0x0f; // voffset high
568 decoder->reg[REG_ADDR(0x9a)] = LOBYTE(h + 2); // height low
569 decoder->reg[REG_ADDR(0x9b)] = HIBYTE(h + 2) & 0x0f; // height high
570 decoder->reg[REG_ADDR(0x9c)] = LOBYTE(w); // out width low
571 decoder->reg[REG_ADDR(0x9d)] = HIBYTE(w) & 0x0f; // out width high
572 decoder->reg[REG_ADDR(0x9e)] = LOBYTE(h); // out height low
573 decoder->reg[REG_ADDR(0x9f)] = HIBYTE(h) & 0x0f; // out height high
574
575 decoder->reg[REG_ADDR(0xc4)] = LOBYTE(hoff); // hoffset low
576 decoder->reg[REG_ADDR(0xc5)] = HIBYTE(hoff) & 0x0f; // hoffset high
577 decoder->reg[REG_ADDR(0xc6)] = LOBYTE(w); // width low
578 decoder->reg[REG_ADDR(0xc7)] = HIBYTE(w) & 0x0f; // width high
579 decoder->reg[REG_ADDR(0xc8)] = LOBYTE(voff); // voffset low
580 decoder->reg[REG_ADDR(0xc9)] = HIBYTE(voff) & 0x0f; // voffset high
581 decoder->reg[REG_ADDR(0xca)] = LOBYTE(h + 2); // height low
582 decoder->reg[REG_ADDR(0xcb)] = HIBYTE(h + 2) & 0x0f; // height high
583 decoder->reg[REG_ADDR(0xcc)] = LOBYTE(w); // out width low
584 decoder->reg[REG_ADDR(0xcd)] = HIBYTE(w) & 0x0f; // out width high
585 decoder->reg[REG_ADDR(0xce)] = LOBYTE(h); // out height low
586 decoder->reg[REG_ADDR(0xcf)] = HIBYTE(h) & 0x0f; // out height high
587
588
589 saa7114_write(client, 0x80, 0x06); // i-port and scaler back end clock selection, task A&B off
590 saa7114_write(client, 0x88, 0xd8); // sw reset scaler
591 saa7114_write(client, 0x88, 0xf8); // sw reset scaler release
592
593 saa7114_write_block(client, decoder->reg + (0x06 << 1),
594 3 << 1);
595 saa7114_write_block(client, decoder->reg + (0x0e << 1),
596 2 << 1);
597 saa7114_write_block(client, decoder->reg + (0x5a << 1),
598 2 << 1);
599
600 saa7114_write_block(client, decoder->reg + (0x94 << 1),
601 (0x9f + 1 - 0x94) << 1);
602 saa7114_write_block(client, decoder->reg + (0xc4 << 1),
603 (0xcf + 1 - 0xc4) << 1);
604
605 saa7114_write(client, 0x88, 0xd8); // sw reset scaler
606 saa7114_write(client, 0x88, 0xf8); // sw reset scaler release
607 saa7114_write(client, 0x80, 0x36); // i-port and scaler back end clock selection
608
609 decoder->norm = *iarg;
610 break;
611 }
612
613 case DECODER_SET_INPUT:
614 {
615 int *iarg = arg;
616
617 v4l_dbg(1, debug, client, "set input (%d)\n", *iarg);
618 if (*iarg < 0 || *iarg > 7) {
619 return -EINVAL;
620 }
621
622 if (decoder->input != *iarg) {
623 v4l_dbg(1, debug, client, "now setting %s input\n",
624 *iarg >= 6 ? "S-Video" : "Composite");
625 decoder->input = *iarg;
626
627 /* select mode */
628 decoder->reg[REG_ADDR(0x02)] =
629 (decoder->
630 reg[REG_ADDR(0x02)] & 0xf0) | (decoder->
631 input <
632 6 ? 0x0 : 0x9);
633 saa7114_write(client, 0x02,
634 decoder->reg[REG_ADDR(0x02)]);
635
636 /* bypass chrominance trap for modes 6..9 */
637 decoder->reg[REG_ADDR(0x09)] =
638 (decoder->
639 reg[REG_ADDR(0x09)] & 0x7f) | (decoder->
640 input <
641 6 ? 0x0 :
642 0x80);
643 saa7114_write(client, 0x09,
644 decoder->reg[REG_ADDR(0x09)]);
645
646 decoder->reg[REG_ADDR(0x0e)] =
647 decoder->input <
648 6 ? decoder->
649 reg[REG_ADDR(0x0e)] | 1 : decoder->
650 reg[REG_ADDR(0x0e)] & ~1;
651 saa7114_write(client, 0x0e,
652 decoder->reg[REG_ADDR(0x0e)]);
653 }
654 break;
655 }
656
657 case DECODER_SET_OUTPUT:
658 {
659 int *iarg = arg;
660
661 v4l_dbg(1, debug, client, "set output\n");
662
663 /* not much choice of outputs */
664 if (*iarg != 0) {
665 return -EINVAL;
666 }
667 break;
668 }
669
670 case DECODER_ENABLE_OUTPUT:
671 {
672 int *iarg = arg;
673 int enable = (*iarg != 0);
674
675 v4l_dbg(1, debug, client, "%s output\n",
676 enable ? "enable" : "disable");
677
678 decoder->playback = !enable;
679
680 if (decoder->enable != enable) {
681 decoder->enable = enable;
682
683 /* RJ: If output should be disabled (for
684 * playing videos), we also need a open PLL.
685 * The input is set to 0 (where no input
686 * source is connected), although this
687 * is not necessary.
688 *
689 * If output should be enabled, we have to
690 * reverse the above.
691 */
692
693 if (decoder->enable) {
694 decoder->reg[REG_ADDR(0x08)] = 0xb8;
695 decoder->reg[REG_ADDR(0x12)] = 0xc9;
696 decoder->reg[REG_ADDR(0x13)] = 0x80;
697 decoder->reg[REG_ADDR(0x87)] = 0x01;
698 } else {
699 decoder->reg[REG_ADDR(0x08)] = 0x7c;
700 decoder->reg[REG_ADDR(0x12)] = 0x00;
701 decoder->reg[REG_ADDR(0x13)] = 0x00;
702 decoder->reg[REG_ADDR(0x87)] = 0x00;
703 }
704
705 saa7114_write_block(client,
706 decoder->reg + (0x12 << 1),
707 2 << 1);
708 saa7114_write(client, 0x08,
709 decoder->reg[REG_ADDR(0x08)]);
710 saa7114_write(client, 0x87,
711 decoder->reg[REG_ADDR(0x87)]);
712 saa7114_write(client, 0x88, 0xd8); // sw reset scaler
713 saa7114_write(client, 0x88, 0xf8); // sw reset scaler release
714 saa7114_write(client, 0x80, 0x36);
715
716 }
717 break;
718 }
719
720 case DECODER_SET_PICTURE:
721 {
722 struct video_picture *pic = arg;
723
724 v4l_dbg(1, debug, client,
725 "decoder set picture bright=%d contrast=%d saturation=%d hue=%d\n",
726 pic->brightness, pic->contrast, pic->colour, pic->hue);
727
728 if (decoder->bright != pic->brightness) {
729 /* We want 0 to 255 we get 0-65535 */
730 decoder->bright = pic->brightness;
731 saa7114_write(client, 0x0a, decoder->bright >> 8);
732 }
733 if (decoder->contrast != pic->contrast) {
734 /* We want 0 to 127 we get 0-65535 */
735 decoder->contrast = pic->contrast;
736 saa7114_write(client, 0x0b,
737 decoder->contrast >> 9);
738 }
739 if (decoder->sat != pic->colour) {
740 /* We want 0 to 127 we get 0-65535 */
741 decoder->sat = pic->colour;
742 saa7114_write(client, 0x0c, decoder->sat >> 9);
743 }
744 if (decoder->hue != pic->hue) {
745 /* We want -128 to 127 we get 0-65535 */
746 decoder->hue = pic->hue;
747 saa7114_write(client, 0x0d,
748 (decoder->hue - 32768) >> 8);
749 }
750 break;
751 }
752
753 default:
754 return -EINVAL;
755 }
756
757 return 0;
758}
759
760/* ----------------------------------------------------------------------- */
761
762static unsigned short normal_i2c[] = { 0x42 >> 1, 0x40 >> 1, I2C_CLIENT_END };
763
764I2C_CLIENT_INSMOD;
765
766static int saa7114_probe(struct i2c_client *client,
767 const struct i2c_device_id *id)
768{
769 int i, err[30];
770 short int hoff = SAA_7114_NTSC_HOFFSET;
771 short int voff = SAA_7114_NTSC_VOFFSET;
772 short int w = SAA_7114_NTSC_WIDTH;
773 short int h = SAA_7114_NTSC_HEIGHT;
774 struct saa7114 *decoder;
775
776 /* Check if the adapter supports the needed features */
777 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
778 return -ENODEV;
779
780 v4l_info(client, "chip found @ 0x%x (%s)\n",
781 client->addr << 1, client->adapter->name);
782
783 decoder = kzalloc(sizeof(struct saa7114), GFP_KERNEL);
784 if (decoder == NULL)
785 return -ENOMEM;
786 decoder->norm = VIDEO_MODE_NTSC;
787 decoder->input = -1;
788 decoder->enable = 1;
789 decoder->bright = 32768;
790 decoder->contrast = 32768;
791 decoder->hue = 32768;
792 decoder->sat = 32768;
793 decoder->playback = 0; // initially capture mode useda
794 i2c_set_clientdata(client, decoder);
795
796 memcpy(decoder->reg, init, sizeof(init));
797
798 decoder->reg[REG_ADDR(0x94)] = LOBYTE(hoff); // hoffset low
799 decoder->reg[REG_ADDR(0x95)] = HIBYTE(hoff) & 0x0f; // hoffset high
800 decoder->reg[REG_ADDR(0x96)] = LOBYTE(w); // width low
801 decoder->reg[REG_ADDR(0x97)] = HIBYTE(w) & 0x0f; // width high
802 decoder->reg[REG_ADDR(0x98)] = LOBYTE(voff); // voffset low
803 decoder->reg[REG_ADDR(0x99)] = HIBYTE(voff) & 0x0f; // voffset high
804 decoder->reg[REG_ADDR(0x9a)] = LOBYTE(h + 2); // height low
805 decoder->reg[REG_ADDR(0x9b)] = HIBYTE(h + 2) & 0x0f; // height high
806 decoder->reg[REG_ADDR(0x9c)] = LOBYTE(w); // out width low
807 decoder->reg[REG_ADDR(0x9d)] = HIBYTE(w) & 0x0f; // out width high
808 decoder->reg[REG_ADDR(0x9e)] = LOBYTE(h); // out height low
809 decoder->reg[REG_ADDR(0x9f)] = HIBYTE(h) & 0x0f; // out height high
810
811 decoder->reg[REG_ADDR(0xc4)] = LOBYTE(hoff); // hoffset low
812 decoder->reg[REG_ADDR(0xc5)] = HIBYTE(hoff) & 0x0f; // hoffset high
813 decoder->reg[REG_ADDR(0xc6)] = LOBYTE(w); // width low
814 decoder->reg[REG_ADDR(0xc7)] = HIBYTE(w) & 0x0f; // width high
815 decoder->reg[REG_ADDR(0xc8)] = LOBYTE(voff); // voffset low
816 decoder->reg[REG_ADDR(0xc9)] = HIBYTE(voff) & 0x0f; // voffset high
817 decoder->reg[REG_ADDR(0xca)] = LOBYTE(h + 2); // height low
818 decoder->reg[REG_ADDR(0xcb)] = HIBYTE(h + 2) & 0x0f; // height high
819 decoder->reg[REG_ADDR(0xcc)] = LOBYTE(w); // out width low
820 decoder->reg[REG_ADDR(0xcd)] = HIBYTE(w) & 0x0f; // out width high
821 decoder->reg[REG_ADDR(0xce)] = LOBYTE(h); // out height low
822 decoder->reg[REG_ADDR(0xcf)] = HIBYTE(h) & 0x0f; // out height high
823
824 decoder->reg[REG_ADDR(0xb8)] =
825 LOBYTE(LOWORD(SAA_7114_VERTICAL_CHROMA_OFFSET));
826 decoder->reg[REG_ADDR(0xb9)] =
827 HIBYTE(LOWORD(SAA_7114_VERTICAL_CHROMA_OFFSET));
828 decoder->reg[REG_ADDR(0xba)] =
829 LOBYTE(HIWORD(SAA_7114_VERTICAL_CHROMA_OFFSET));
830 decoder->reg[REG_ADDR(0xbb)] =
831 HIBYTE(HIWORD(SAA_7114_VERTICAL_CHROMA_OFFSET));
832
833 decoder->reg[REG_ADDR(0xbc)] =
834 LOBYTE(LOWORD(SAA_7114_VERTICAL_LUMA_OFFSET));
835 decoder->reg[REG_ADDR(0xbd)] =
836 HIBYTE(LOWORD(SAA_7114_VERTICAL_LUMA_OFFSET));
837 decoder->reg[REG_ADDR(0xbe)] =
838 LOBYTE(HIWORD(SAA_7114_VERTICAL_LUMA_OFFSET));
839 decoder->reg[REG_ADDR(0xbf)] =
840 HIBYTE(HIWORD(SAA_7114_VERTICAL_LUMA_OFFSET));
841
842 decoder->reg[REG_ADDR(0xe8)] =
843 LOBYTE(LOWORD(SAA_7114_VERTICAL_CHROMA_OFFSET));
844 decoder->reg[REG_ADDR(0xe9)] =
845 HIBYTE(LOWORD(SAA_7114_VERTICAL_CHROMA_OFFSET));
846 decoder->reg[REG_ADDR(0xea)] =
847 LOBYTE(HIWORD(SAA_7114_VERTICAL_CHROMA_OFFSET));
848 decoder->reg[REG_ADDR(0xeb)] =
849 HIBYTE(HIWORD(SAA_7114_VERTICAL_CHROMA_OFFSET));
850
851 decoder->reg[REG_ADDR(0xec)] =
852 LOBYTE(LOWORD(SAA_7114_VERTICAL_LUMA_OFFSET));
853 decoder->reg[REG_ADDR(0xed)] =
854 HIBYTE(LOWORD(SAA_7114_VERTICAL_LUMA_OFFSET));
855 decoder->reg[REG_ADDR(0xee)] =
856 LOBYTE(HIWORD(SAA_7114_VERTICAL_LUMA_OFFSET));
857 decoder->reg[REG_ADDR(0xef)] =
858 HIBYTE(HIWORD(SAA_7114_VERTICAL_LUMA_OFFSET));
859
860
861 decoder->reg[REG_ADDR(0x13)] = 0x80; // RTC0 on
862 decoder->reg[REG_ADDR(0x87)] = 0x01; // I-Port
863 decoder->reg[REG_ADDR(0x12)] = 0xc9; // RTS0
864
865 decoder->reg[REG_ADDR(0x02)] = 0xc0; // set composite1 input, aveasy
866 decoder->reg[REG_ADDR(0x09)] = 0x00; // chrominance trap
867 decoder->reg[REG_ADDR(0x0e)] |= 1; // combfilter on
868
869
870 v4l_dbg(1, debug, client, "starting init\n");
871
872 err[0] =
873 saa7114_write_block(client, decoder->reg + (0x20 << 1),
874 0x10 << 1);
875 err[1] =
876 saa7114_write_block(client, decoder->reg + (0x30 << 1),
877 0x10 << 1);
878 err[2] =
879 saa7114_write_block(client, decoder->reg + (0x63 << 1),
880 (0x7f + 1 - 0x63) << 1);
881 err[3] =
882 saa7114_write_block(client, decoder->reg + (0x89 << 1),
883 6 << 1);
884 err[4] =
885 saa7114_write_block(client, decoder->reg + (0xb8 << 1),
886 8 << 1);
887 err[5] =
888 saa7114_write_block(client, decoder->reg + (0xe8 << 1),
889 8 << 1);
890
891
892 for (i = 0; i <= 5; i++) {
893 if (err[i] < 0) {
894 v4l_dbg(1, debug, client,
895 "init error %d at stage %d, leaving attach.\n",
896 i, err[i]);
897 kfree(decoder);
898 return -EIO;
899 }
900 }
901
902 for (i = 6; i < 8; i++) {
903 v4l_dbg(1, debug, client,
904 "reg[0x%02x] = 0x%02x (0x%02x)\n",
905 i, saa7114_read(client, i),
906 decoder->reg[REG_ADDR(i)]);
907 }
908
909 v4l_dbg(1, debug, client,
910 "performing decoder reset sequence\n");
911
912 err[6] = saa7114_write(client, 0x80, 0x06); // i-port and scaler backend clock selection, task A&B off
913 err[7] = saa7114_write(client, 0x88, 0xd8); // sw reset scaler
914 err[8] = saa7114_write(client, 0x88, 0xf8); // sw reset scaler release
915
916 for (i = 6; i <= 8; i++) {
917 if (err[i] < 0) {
918 v4l_dbg(1, debug, client,
919 "init error %d at stage %d, leaving attach.\n",
920 i, err[i]);
921 kfree(decoder);
922 return -EIO;
923 }
924 }
925
926 v4l_dbg(1, debug, client, "performing the rest of init\n");
927
928 err[9] = saa7114_write(client, 0x01, decoder->reg[REG_ADDR(0x01)]);
929 err[10] = saa7114_write_block(client, decoder->reg + (0x03 << 1), (0x1e + 1 - 0x03) << 1); // big seq
930 err[11] = saa7114_write_block(client, decoder->reg + (0x40 << 1), (0x5f + 1 - 0x40) << 1); // slicer
931 err[12] = saa7114_write_block(client, decoder->reg + (0x81 << 1), 2 << 1); // ?
932 err[13] = saa7114_write_block(client, decoder->reg + (0x83 << 1), 5 << 1); // ?
933 err[14] = saa7114_write_block(client, decoder->reg + (0x90 << 1), 4 << 1); // Task A
934 err[15] =
935 saa7114_write_block(client, decoder->reg + (0x94 << 1),
936 12 << 1);
937 err[16] =
938 saa7114_write_block(client, decoder->reg + (0xa0 << 1),
939 8 << 1);
940 err[17] =
941 saa7114_write_block(client, decoder->reg + (0xa8 << 1),
942 8 << 1);
943 err[18] =
944 saa7114_write_block(client, decoder->reg + (0xb0 << 1),
945 8 << 1);
946 err[19] = saa7114_write_block(client, decoder->reg + (0xc0 << 1), 4 << 1); // Task B
947 err[15] =
948 saa7114_write_block(client, decoder->reg + (0xc4 << 1),
949 12 << 1);
950 err[16] =
951 saa7114_write_block(client, decoder->reg + (0xd0 << 1),
952 8 << 1);
953 err[17] =
954 saa7114_write_block(client, decoder->reg + (0xd8 << 1),
955 8 << 1);
956 err[18] =
957 saa7114_write_block(client, decoder->reg + (0xe0 << 1),
958 8 << 1);
959
960 for (i = 9; i <= 18; i++) {
961 if (err[i] < 0) {
962 v4l_dbg(1, debug, client,
963 "init error %d at stage %d, leaving attach.\n",
964 i, err[i]);
965 kfree(decoder);
966 return -EIO;
967 }
968 }
969
970
971 for (i = 6; i < 8; i++) {
972 v4l_dbg(1, debug, client,
973 "reg[0x%02x] = 0x%02x (0x%02x)\n",
974 i, saa7114_read(client, i),
975 decoder->reg[REG_ADDR(i)]);
976 }
977
978
979 for (i = 0x11; i <= 0x13; i++) {
980 v4l_dbg(1, debug, client,
981 "reg[0x%02x] = 0x%02x (0x%02x)\n",
982 i, saa7114_read(client, i),
983 decoder->reg[REG_ADDR(i)]);
984 }
985
986
987 v4l_dbg(1, debug, client, "setting video input\n");
988
989 err[19] =
990 saa7114_write(client, 0x02, decoder->reg[REG_ADDR(0x02)]);
991 err[20] =
992 saa7114_write(client, 0x09, decoder->reg[REG_ADDR(0x09)]);
993 err[21] =
994 saa7114_write(client, 0x0e, decoder->reg[REG_ADDR(0x0e)]);
995
996 for (i = 19; i <= 21; i++) {
997 if (err[i] < 0) {
998 v4l_dbg(1, debug, client,
999 "init error %d at stage %d, leaving attach.\n",
1000 i, err[i]);
1001 kfree(decoder);
1002 return -EIO;
1003 }
1004 }
1005
1006 v4l_dbg(1, debug, client, "performing decoder reset sequence\n");
1007
1008 err[22] = saa7114_write(client, 0x88, 0xd8); // sw reset scaler
1009 err[23] = saa7114_write(client, 0x88, 0xf8); // sw reset scaler release
1010 err[24] = saa7114_write(client, 0x80, 0x36); // i-port and scaler backend clock selection, task A&B off
1011
1012
1013 for (i = 22; i <= 24; i++) {
1014 if (err[i] < 0) {
1015 v4l_dbg(1, debug, client,
1016 "init error %d at stage %d, leaving attach.\n",
1017 i, err[i]);
1018 kfree(decoder);
1019 return -EIO;
1020 }
1021 }
1022
1023 err[25] = saa7114_write(client, 0x06, init[REG_ADDR(0x06)]);
1024 err[26] = saa7114_write(client, 0x07, init[REG_ADDR(0x07)]);
1025 err[27] = saa7114_write(client, 0x10, init[REG_ADDR(0x10)]);
1026
1027 v4l_dbg(1, debug, client, "chip version %x, decoder status 0x%02x\n",
1028 saa7114_read(client, 0x00) >> 4,
1029 saa7114_read(client, 0x1f));
1030 v4l_dbg(1, debug, client,
1031 "power save control: 0x%02x, scaler status: 0x%02x\n",
1032 saa7114_read(client, 0x88),
1033 saa7114_read(client, 0x8f));
1034
1035
1036 for (i = 0x94; i < 0x96; i++) {
1037 v4l_dbg(1, debug, client,
1038 "reg[0x%02x] = 0x%02x (0x%02x)\n",
1039 i, saa7114_read(client, i),
1040 decoder->reg[REG_ADDR(i)]);
1041 }
1042
1043 //i = saa7114_write_block(client, init, sizeof(init));
1044 return 0;
1045}
1046
1047static int saa7114_remove(struct i2c_client *client)
1048{
1049 kfree(i2c_get_clientdata(client));
1050 return 0;
1051}
1052
1053/* ----------------------------------------------------------------------- */
1054
1055static const struct i2c_device_id saa7114_id[] = {
1056 { "saa7114_old", 0 }, /* "saa7114" maps to the saa7115 driver */
1057 { }
1058};
1059MODULE_DEVICE_TABLE(i2c, saa7114_id);
1060
1061static struct v4l2_i2c_driver_data v4l2_i2c_data = {
1062 .name = "saa7114",
1063 .driverid = I2C_DRIVERID_SAA7114,
1064 .command = saa7114_command,
1065 .probe = saa7114_probe,
1066 .remove = saa7114_remove,
1067 .id_table = saa7114_id,
1068};
diff --git a/drivers/media/video/saa7115.c b/drivers/media/video/saa7115.c
index 46c796c3fec8..cebf159f52cf 100644
--- a/drivers/media/video/saa7115.c
+++ b/drivers/media/video/saa7115.c
@@ -778,7 +778,7 @@ static int saa711x_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
778 break; 778 break;
779 779
780 case V4L2_CID_HUE: 780 case V4L2_CID_HUE:
781 if (ctrl->value < -127 || ctrl->value > 127) { 781 if (ctrl->value < -128 || ctrl->value > 127) {
782 v4l2_err(sd, "invalid hue setting %d\n", ctrl->value); 782 v4l2_err(sd, "invalid hue setting %d\n", ctrl->value);
783 return -ERANGE; 783 return -ERANGE;
784 } 784 }
@@ -931,8 +931,8 @@ static void saa711x_set_v4lstd(struct v4l2_subdev *sd, v4l2_std_id std)
931 /* Prevent unnecessary standard changes. During a standard 931 /* Prevent unnecessary standard changes. During a standard
932 change the I-Port is temporarily disabled. Any devices 932 change the I-Port is temporarily disabled. Any devices
933 reading from that port can get confused. 933 reading from that port can get confused.
934 Note that VIDIOC_S_STD is also used to switch from 934 Note that s_std is also used to switch from
935 radio to TV mode, so if a VIDIOC_S_STD is broadcast to 935 radio to TV mode, so if a s_std is broadcast to
936 all I2C devices then you do not want to have an unwanted 936 all I2C devices then you do not want to have an unwanted
937 side-effect here. */ 937 side-effect here. */
938 if (std == state->std) 938 if (std == state->std)
@@ -1206,10 +1206,12 @@ static int saa711x_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc)
1206{ 1206{
1207 switch (qc->id) { 1207 switch (qc->id) {
1208 case V4L2_CID_BRIGHTNESS: 1208 case V4L2_CID_BRIGHTNESS:
1209 return v4l2_ctrl_query_fill(qc, 0, 255, 1, 128);
1209 case V4L2_CID_CONTRAST: 1210 case V4L2_CID_CONTRAST:
1210 case V4L2_CID_SATURATION: 1211 case V4L2_CID_SATURATION:
1212 return v4l2_ctrl_query_fill(qc, 0, 127, 1, 64);
1211 case V4L2_CID_HUE: 1213 case V4L2_CID_HUE:
1212 return v4l2_ctrl_query_fill_std(qc); 1214 return v4l2_ctrl_query_fill(qc, -128, 127, 1, 0);
1213 default: 1215 default:
1214 return -EINVAL; 1216 return -EINVAL;
1215 } 1217 }
@@ -1308,11 +1310,12 @@ static int saa711x_s_stream(struct v4l2_subdev *sd, int enable)
1308 v4l2_dbg(1, debug, sd, "%s output\n", 1310 v4l2_dbg(1, debug, sd, "%s output\n",
1309 enable ? "enable" : "disable"); 1311 enable ? "enable" : "disable");
1310 1312
1311 if (state->enable != enable) { 1313 if (state->enable == enable)
1312 state->enable = enable; 1314 return 0;
1313 saa711x_write(sd, R_87_I_PORT_I_O_ENA_OUT_CLK_AND_GATED, 1315 state->enable = enable;
1314 state->enable); 1316 if (!saa711x_has_reg(state->ident, R_87_I_PORT_I_O_ENA_OUT_CLK_AND_GATED))
1315 } 1317 return 0;
1318 saa711x_write(sd, R_87_I_PORT_I_O_ENA_OUT_CLK_AND_GATED, state->enable);
1316 return 0; 1319 return 0;
1317} 1320}
1318 1321
@@ -1370,6 +1373,47 @@ static int saa711x_g_vbi_data(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_dat
1370 } 1373 }
1371} 1374}
1372 1375
1376static int saa711x_querystd(struct v4l2_subdev *sd, v4l2_std_id *std)
1377{
1378 struct saa711x_state *state = to_state(sd);
1379 int reg1e;
1380
1381 *std = V4L2_STD_ALL;
1382 if (state->ident != V4L2_IDENT_SAA7115)
1383 return 0;
1384 reg1e = saa711x_read(sd, R_1E_STATUS_BYTE_1_VD_DEC);
1385
1386 switch (reg1e & 0x03) {
1387 case 1:
1388 *std = V4L2_STD_NTSC;
1389 break;
1390 case 2:
1391 *std = V4L2_STD_PAL;
1392 break;
1393 case 3:
1394 *std = V4L2_STD_SECAM;
1395 break;
1396 default:
1397 break;
1398 }
1399 return 0;
1400}
1401
1402static int saa711x_g_input_status(struct v4l2_subdev *sd, u32 *status)
1403{
1404 struct saa711x_state *state = to_state(sd);
1405 int reg1e = 0x80;
1406 int reg1f;
1407
1408 *status = V4L2_IN_ST_NO_SIGNAL;
1409 if (state->ident == V4L2_IDENT_SAA7115)
1410 reg1e = saa711x_read(sd, R_1E_STATUS_BYTE_1_VD_DEC);
1411 reg1f = saa711x_read(sd, R_1F_STATUS_BYTE_2_VD_DEC);
1412 if ((reg1f & 0xc1) == 0x81 && (reg1e & 0xc0) == 0x80)
1413 *status = 0;
1414 return 0;
1415}
1416
1373#ifdef CONFIG_VIDEO_ADV_DEBUG 1417#ifdef CONFIG_VIDEO_ADV_DEBUG
1374static int saa711x_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) 1418static int saa711x_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg)
1375{ 1419{
@@ -1493,6 +1537,8 @@ static const struct v4l2_subdev_video_ops saa711x_video_ops = {
1493 .g_vbi_data = saa711x_g_vbi_data, 1537 .g_vbi_data = saa711x_g_vbi_data,
1494 .decode_vbi_line = saa711x_decode_vbi_line, 1538 .decode_vbi_line = saa711x_decode_vbi_line,
1495 .s_stream = saa711x_s_stream, 1539 .s_stream = saa711x_s_stream,
1540 .querystd = saa711x_querystd,
1541 .g_input_status = saa711x_g_input_status,
1496}; 1542};
1497 1543
1498static const struct v4l2_subdev_ops saa711x_ops = { 1544static const struct v4l2_subdev_ops saa711x_ops = {
diff --git a/drivers/media/video/saa7127.c b/drivers/media/video/saa7127.c
index 05221d47dd4c..128bb8b8dbbf 100644
--- a/drivers/media/video/saa7127.c
+++ b/drivers/media/video/saa7127.c
@@ -810,7 +810,6 @@ MODULE_DEVICE_TABLE(i2c, saa7127_id);
810 810
811static struct v4l2_i2c_driver_data v4l2_i2c_data = { 811static struct v4l2_i2c_driver_data v4l2_i2c_data = {
812 .name = "saa7127", 812 .name = "saa7127",
813 .driverid = I2C_DRIVERID_SAA7127,
814 .probe = saa7127_probe, 813 .probe = saa7127_probe,
815 .remove = saa7127_remove, 814 .remove = saa7127_remove,
816 .id_table = saa7127_id, 815 .id_table = saa7127_id,
diff --git a/drivers/media/video/saa7134/Kconfig b/drivers/media/video/saa7134/Kconfig
index fc2164e28e76..0ba68987bfce 100644
--- a/drivers/media/video/saa7134/Kconfig
+++ b/drivers/media/video/saa7134/Kconfig
@@ -6,6 +6,7 @@ config VIDEO_SAA7134
6 select VIDEO_TUNER 6 select VIDEO_TUNER
7 select VIDEO_TVEEPROM 7 select VIDEO_TVEEPROM
8 select CRC32 8 select CRC32
9 select VIDEO_SAA6588 if VIDEO_HELPER_CHIPS_AUTO
9 ---help--- 10 ---help---
10 This is a video4linux driver for Philips SAA713x based 11 This is a video4linux driver for Philips SAA713x based
11 TV cards. 12 TV cards.
@@ -35,8 +36,16 @@ config VIDEO_SAA7134_DVB
35 select DVB_TDA10086 if !DVB_FE_CUSTOMISE 36 select DVB_TDA10086 if !DVB_FE_CUSTOMISE
36 select DVB_TDA826X if !DVB_FE_CUSTOMISE 37 select DVB_TDA826X if !DVB_FE_CUSTOMISE
37 select DVB_ISL6421 if !DVB_FE_CUSTOMISE 38 select DVB_ISL6421 if !DVB_FE_CUSTOMISE
38 select MEDIA_TUNER_TDA827X if !MEDIA_TUNER_CUSTOMIZE 39 select DVB_ISL6405 if !DVB_FE_CUSTOMISE
39 select MEDIA_TUNER_SIMPLE if !MEDIA_TUNER_CUSTOMIZE 40 select MEDIA_TUNER_TDA827X if !MEDIA_TUNER_CUSTOMISE
41 select MEDIA_TUNER_SIMPLE if !MEDIA_TUNER_CUSTOMISE
42 select DVB_ZL10036 if !DVB_FE_CUSTOMISE
43 select DVB_MT312 if !DVB_FE_CUSTOMISE
44 select DVB_LNBP21 if !DVB_FE_CUSTOMISE
45 select DVB_ZL10353 if !DVB_FE_CUSTOMISE
46 select DVB_LGDT3305 if !DVB_FE_CUSTOMISE
47 select MEDIA_TUNER_TDA18271 if !MEDIA_TUNER_CUSTOMISE
48 select MEDIA_TUNER_TDA8290 if !MEDIA_TUNER_CUSTOMISE
40 ---help--- 49 ---help---
41 This adds support for DVB cards based on the 50 This adds support for DVB cards based on the
42 Philips saa7134 chip. 51 Philips saa7134 chip.
diff --git a/drivers/media/video/saa7134/saa6752hs.c b/drivers/media/video/saa7134/saa6752hs.c
index 1fee6e84a512..dc2213e2f86e 100644
--- a/drivers/media/video/saa7134/saa6752hs.c
+++ b/drivers/media/video/saa7134/saa6752hs.c
@@ -33,9 +33,10 @@
33#include <linux/i2c.h> 33#include <linux/i2c.h>
34#include <linux/types.h> 34#include <linux/types.h>
35#include <linux/videodev2.h> 35#include <linux/videodev2.h>
36#include <media/v4l2-device.h>
36#include <media/v4l2-common.h> 37#include <media/v4l2-common.h>
37#include <media/v4l2-chip-ident.h> 38#include <media/v4l2-chip-ident.h>
38#include <media/v4l2-i2c-drv-legacy.h> 39#include <media/v4l2-i2c-drv.h>
39#include <linux/init.h> 40#include <linux/init.h>
40#include <linux/crc32.h> 41#include <linux/crc32.h>
41 42
@@ -44,10 +45,6 @@
44#define MPEG_TOTAL_TARGET_BITRATE_MAX 27000 45#define MPEG_TOTAL_TARGET_BITRATE_MAX 27000
45#define MPEG_PID_MAX ((1 << 14) - 1) 46#define MPEG_PID_MAX ((1 << 14) - 1)
46 47
47/* Addresses to scan */
48static unsigned short normal_i2c[] = {0x20, I2C_CLIENT_END};
49
50I2C_CLIENT_INSMOD;
51 48
52MODULE_DESCRIPTION("device driver for saa6752hs MPEG2 encoder"); 49MODULE_DESCRIPTION("device driver for saa6752hs MPEG2 encoder");
53MODULE_AUTHOR("Andrew de Quincey"); 50MODULE_AUTHOR("Andrew de Quincey");
@@ -95,6 +92,7 @@ static const struct v4l2_format v4l2_format_table[] =
95}; 92};
96 93
97struct saa6752hs_state { 94struct saa6752hs_state {
95 struct v4l2_subdev sd;
98 int chip; 96 int chip;
99 u32 revision; 97 u32 revision;
100 int has_ac3; 98 int has_ac3;
@@ -115,6 +113,11 @@ enum saa6752hs_command {
115 SAA6752HS_COMMAND_MAX 113 SAA6752HS_COMMAND_MAX
116}; 114};
117 115
116static inline struct saa6752hs_state *to_state(struct v4l2_subdev *sd)
117{
118 return container_of(sd, struct saa6752hs_state, sd);
119}
120
118/* ---------------------------------------------------------------------- */ 121/* ---------------------------------------------------------------------- */
119 122
120static u8 PAT[] = { 123static u8 PAT[] = {
@@ -360,185 +363,191 @@ static int saa6752hs_set_bitrate(struct i2c_client *client,
360 return 0; 363 return 0;
361} 364}
362 365
363static void saa6752hs_set_subsampling(struct i2c_client *client,
364 struct v4l2_format *f)
365{
366 struct saa6752hs_state *h = i2c_get_clientdata(client);
367 int dist_352, dist_480, dist_720;
368
369 /*
370 FIXME: translate and round width/height into EMPRESS
371 subsample type:
372 366
373 type | PAL | NTSC 367static int get_ctrl(int has_ac3, struct saa6752hs_mpeg_params *params,
374 --------------------------- 368 struct v4l2_ext_control *ctrl)
375 SIF | 352x288 | 352x240 369{
376 1/2 D1 | 352x576 | 352x480 370 switch (ctrl->id) {
377 2/3 D1 | 480x576 | 480x480 371 case V4L2_CID_MPEG_STREAM_TYPE:
378 D1 | 720x576 | 720x480 372 ctrl->value = V4L2_MPEG_STREAM_TYPE_MPEG2_TS;
379 */ 373 break;
380 374 case V4L2_CID_MPEG_STREAM_PID_PMT:
381 dist_352 = abs(f->fmt.pix.width - 352); 375 ctrl->value = params->ts_pid_pmt;
382 dist_480 = abs(f->fmt.pix.width - 480); 376 break;
383 dist_720 = abs(f->fmt.pix.width - 720); 377 case V4L2_CID_MPEG_STREAM_PID_AUDIO:
384 if (dist_720 < dist_480) { 378 ctrl->value = params->ts_pid_audio;
385 f->fmt.pix.width = 720; 379 break;
386 f->fmt.pix.height = 576; 380 case V4L2_CID_MPEG_STREAM_PID_VIDEO:
387 h->video_format = SAA6752HS_VF_D1; 381 ctrl->value = params->ts_pid_video;
388 } 382 break;
389 else if (dist_480 < dist_352) { 383 case V4L2_CID_MPEG_STREAM_PID_PCR:
390 f->fmt.pix.width = 480; 384 ctrl->value = params->ts_pid_pcr;
391 f->fmt.pix.height = 576; 385 break;
392 h->video_format = SAA6752HS_VF_2_3_D1; 386 case V4L2_CID_MPEG_AUDIO_ENCODING:
393 } 387 ctrl->value = params->au_encoding;
394 else { 388 break;
395 f->fmt.pix.width = 352; 389 case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
396 if (abs(f->fmt.pix.height - 576) < 390 ctrl->value = params->au_l2_bitrate;
397 abs(f->fmt.pix.height - 288)) { 391 break;
398 f->fmt.pix.height = 576; 392 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
399 h->video_format = SAA6752HS_VF_1_2_D1; 393 if (!has_ac3)
400 } 394 return -EINVAL;
401 else { 395 ctrl->value = params->au_ac3_bitrate;
402 f->fmt.pix.height = 288; 396 break;
403 h->video_format = SAA6752HS_VF_SIF; 397 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
404 } 398 ctrl->value = V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000;
399 break;
400 case V4L2_CID_MPEG_VIDEO_ENCODING:
401 ctrl->value = V4L2_MPEG_VIDEO_ENCODING_MPEG_2;
402 break;
403 case V4L2_CID_MPEG_VIDEO_ASPECT:
404 ctrl->value = params->vi_aspect;
405 break;
406 case V4L2_CID_MPEG_VIDEO_BITRATE:
407 ctrl->value = params->vi_bitrate * 1000;
408 break;
409 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK:
410 ctrl->value = params->vi_bitrate_peak * 1000;
411 break;
412 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
413 ctrl->value = params->vi_bitrate_mode;
414 break;
415 default:
416 return -EINVAL;
405 } 417 }
418 return 0;
406} 419}
407 420
408
409static int handle_ctrl(int has_ac3, struct saa6752hs_mpeg_params *params, 421static int handle_ctrl(int has_ac3, struct saa6752hs_mpeg_params *params,
410 struct v4l2_ext_control *ctrl, unsigned int cmd) 422 struct v4l2_ext_control *ctrl, int set)
411{ 423{
412 int old = 0, new; 424 int old = 0, new;
413 int set = (cmd == VIDIOC_S_EXT_CTRLS);
414 425
415 new = ctrl->value; 426 new = ctrl->value;
416 switch (ctrl->id) { 427 switch (ctrl->id) {
417 case V4L2_CID_MPEG_STREAM_TYPE: 428 case V4L2_CID_MPEG_STREAM_TYPE:
418 old = V4L2_MPEG_STREAM_TYPE_MPEG2_TS; 429 old = V4L2_MPEG_STREAM_TYPE_MPEG2_TS;
419 if (set && new != old) 430 if (set && new != old)
420 return -ERANGE; 431 return -ERANGE;
421 new = old; 432 new = old;
422 break; 433 break;
423 case V4L2_CID_MPEG_STREAM_PID_PMT: 434 case V4L2_CID_MPEG_STREAM_PID_PMT:
424 old = params->ts_pid_pmt; 435 old = params->ts_pid_pmt;
425 if (set && new > MPEG_PID_MAX) 436 if (set && new > MPEG_PID_MAX)
426 return -ERANGE; 437 return -ERANGE;
427 if (new > MPEG_PID_MAX) 438 if (new > MPEG_PID_MAX)
428 new = MPEG_PID_MAX; 439 new = MPEG_PID_MAX;
429 params->ts_pid_pmt = new; 440 params->ts_pid_pmt = new;
430 break; 441 break;
431 case V4L2_CID_MPEG_STREAM_PID_AUDIO: 442 case V4L2_CID_MPEG_STREAM_PID_AUDIO:
432 old = params->ts_pid_audio; 443 old = params->ts_pid_audio;
433 if (set && new > MPEG_PID_MAX) 444 if (set && new > MPEG_PID_MAX)
434 return -ERANGE; 445 return -ERANGE;
435 if (new > MPEG_PID_MAX) 446 if (new > MPEG_PID_MAX)
436 new = MPEG_PID_MAX; 447 new = MPEG_PID_MAX;
437 params->ts_pid_audio = new; 448 params->ts_pid_audio = new;
438 break; 449 break;
439 case V4L2_CID_MPEG_STREAM_PID_VIDEO: 450 case V4L2_CID_MPEG_STREAM_PID_VIDEO:
440 old = params->ts_pid_video; 451 old = params->ts_pid_video;
441 if (set && new > MPEG_PID_MAX) 452 if (set && new > MPEG_PID_MAX)
442 return -ERANGE; 453 return -ERANGE;
443 if (new > MPEG_PID_MAX) 454 if (new > MPEG_PID_MAX)
444 new = MPEG_PID_MAX; 455 new = MPEG_PID_MAX;
445 params->ts_pid_video = new; 456 params->ts_pid_video = new;
446 break; 457 break;
447 case V4L2_CID_MPEG_STREAM_PID_PCR: 458 case V4L2_CID_MPEG_STREAM_PID_PCR:
448 old = params->ts_pid_pcr; 459 old = params->ts_pid_pcr;
449 if (set && new > MPEG_PID_MAX) 460 if (set && new > MPEG_PID_MAX)
450 return -ERANGE; 461 return -ERANGE;
451 if (new > MPEG_PID_MAX) 462 if (new > MPEG_PID_MAX)
452 new = MPEG_PID_MAX; 463 new = MPEG_PID_MAX;
453 params->ts_pid_pcr = new; 464 params->ts_pid_pcr = new;
454 break; 465 break;
455 case V4L2_CID_MPEG_AUDIO_ENCODING: 466 case V4L2_CID_MPEG_AUDIO_ENCODING:
456 old = params->au_encoding; 467 old = params->au_encoding;
457 if (set && new != V4L2_MPEG_AUDIO_ENCODING_LAYER_2 && 468 if (set && new != V4L2_MPEG_AUDIO_ENCODING_LAYER_2 &&
458 (!has_ac3 || new != V4L2_MPEG_AUDIO_ENCODING_AC3)) 469 (!has_ac3 || new != V4L2_MPEG_AUDIO_ENCODING_AC3))
459 return -ERANGE; 470 return -ERANGE;
460 new = old; 471 new = old;
461 break; 472 break;
462 case V4L2_CID_MPEG_AUDIO_L2_BITRATE: 473 case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
463 old = params->au_l2_bitrate; 474 old = params->au_l2_bitrate;
464 if (set && new != V4L2_MPEG_AUDIO_L2_BITRATE_256K && 475 if (set && new != V4L2_MPEG_AUDIO_L2_BITRATE_256K &&
465 new != V4L2_MPEG_AUDIO_L2_BITRATE_384K) 476 new != V4L2_MPEG_AUDIO_L2_BITRATE_384K)
466 return -ERANGE; 477 return -ERANGE;
467 if (new <= V4L2_MPEG_AUDIO_L2_BITRATE_256K) 478 if (new <= V4L2_MPEG_AUDIO_L2_BITRATE_256K)
468 new = V4L2_MPEG_AUDIO_L2_BITRATE_256K; 479 new = V4L2_MPEG_AUDIO_L2_BITRATE_256K;
469 else 480 else
470 new = V4L2_MPEG_AUDIO_L2_BITRATE_384K; 481 new = V4L2_MPEG_AUDIO_L2_BITRATE_384K;
471 params->au_l2_bitrate = new; 482 params->au_l2_bitrate = new;
472 break; 483 break;
473 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE: 484 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
474 if (!has_ac3) 485 if (!has_ac3)
475 return -EINVAL;
476 old = params->au_ac3_bitrate;
477 if (set && new != V4L2_MPEG_AUDIO_AC3_BITRATE_256K &&
478 new != V4L2_MPEG_AUDIO_AC3_BITRATE_384K)
479 return -ERANGE;
480 if (new <= V4L2_MPEG_AUDIO_AC3_BITRATE_256K)
481 new = V4L2_MPEG_AUDIO_AC3_BITRATE_256K;
482 else
483 new = V4L2_MPEG_AUDIO_AC3_BITRATE_384K;
484 params->au_ac3_bitrate = new;
485 break;
486 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
487 old = V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000;
488 if (set && new != old)
489 return -ERANGE;
490 new = old;
491 break;
492 case V4L2_CID_MPEG_VIDEO_ENCODING:
493 old = V4L2_MPEG_VIDEO_ENCODING_MPEG_2;
494 if (set && new != old)
495 return -ERANGE;
496 new = old;
497 break;
498 case V4L2_CID_MPEG_VIDEO_ASPECT:
499 old = params->vi_aspect;
500 if (set && new != V4L2_MPEG_VIDEO_ASPECT_16x9 &&
501 new != V4L2_MPEG_VIDEO_ASPECT_4x3)
502 return -ERANGE;
503 if (new != V4L2_MPEG_VIDEO_ASPECT_16x9)
504 new = V4L2_MPEG_VIDEO_ASPECT_4x3;
505 params->vi_aspect = new;
506 break;
507 case V4L2_CID_MPEG_VIDEO_BITRATE:
508 old = params->vi_bitrate * 1000;
509 new = 1000 * (new / 1000);
510 if (set && new > MPEG_VIDEO_TARGET_BITRATE_MAX * 1000)
511 return -ERANGE;
512 if (new > MPEG_VIDEO_TARGET_BITRATE_MAX * 1000)
513 new = MPEG_VIDEO_TARGET_BITRATE_MAX * 1000;
514 params->vi_bitrate = new / 1000;
515 break;
516 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK:
517 old = params->vi_bitrate_peak * 1000;
518 new = 1000 * (new / 1000);
519 if (set && new > MPEG_VIDEO_TARGET_BITRATE_MAX * 1000)
520 return -ERANGE;
521 if (new > MPEG_VIDEO_TARGET_BITRATE_MAX * 1000)
522 new = MPEG_VIDEO_TARGET_BITRATE_MAX * 1000;
523 params->vi_bitrate_peak = new / 1000;
524 break;
525 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
526 old = params->vi_bitrate_mode;
527 params->vi_bitrate_mode = new;
528 break;
529 default:
530 return -EINVAL; 486 return -EINVAL;
487 old = params->au_ac3_bitrate;
488 if (set && new != V4L2_MPEG_AUDIO_AC3_BITRATE_256K &&
489 new != V4L2_MPEG_AUDIO_AC3_BITRATE_384K)
490 return -ERANGE;
491 if (new <= V4L2_MPEG_AUDIO_AC3_BITRATE_256K)
492 new = V4L2_MPEG_AUDIO_AC3_BITRATE_256K;
493 else
494 new = V4L2_MPEG_AUDIO_AC3_BITRATE_384K;
495 params->au_ac3_bitrate = new;
496 break;
497 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
498 old = V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000;
499 if (set && new != old)
500 return -ERANGE;
501 new = old;
502 break;
503 case V4L2_CID_MPEG_VIDEO_ENCODING:
504 old = V4L2_MPEG_VIDEO_ENCODING_MPEG_2;
505 if (set && new != old)
506 return -ERANGE;
507 new = old;
508 break;
509 case V4L2_CID_MPEG_VIDEO_ASPECT:
510 old = params->vi_aspect;
511 if (set && new != V4L2_MPEG_VIDEO_ASPECT_16x9 &&
512 new != V4L2_MPEG_VIDEO_ASPECT_4x3)
513 return -ERANGE;
514 if (new != V4L2_MPEG_VIDEO_ASPECT_16x9)
515 new = V4L2_MPEG_VIDEO_ASPECT_4x3;
516 params->vi_aspect = new;
517 break;
518 case V4L2_CID_MPEG_VIDEO_BITRATE:
519 old = params->vi_bitrate * 1000;
520 new = 1000 * (new / 1000);
521 if (set && new > MPEG_VIDEO_TARGET_BITRATE_MAX * 1000)
522 return -ERANGE;
523 if (new > MPEG_VIDEO_TARGET_BITRATE_MAX * 1000)
524 new = MPEG_VIDEO_TARGET_BITRATE_MAX * 1000;
525 params->vi_bitrate = new / 1000;
526 break;
527 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK:
528 old = params->vi_bitrate_peak * 1000;
529 new = 1000 * (new / 1000);
530 if (set && new > MPEG_VIDEO_TARGET_BITRATE_MAX * 1000)
531 return -ERANGE;
532 if (new > MPEG_VIDEO_TARGET_BITRATE_MAX * 1000)
533 new = MPEG_VIDEO_TARGET_BITRATE_MAX * 1000;
534 params->vi_bitrate_peak = new / 1000;
535 break;
536 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
537 old = params->vi_bitrate_mode;
538 params->vi_bitrate_mode = new;
539 break;
540 default:
541 return -EINVAL;
531 } 542 }
532 if (cmd == VIDIOC_G_EXT_CTRLS) 543 ctrl->value = new;
533 ctrl->value = old;
534 else
535 ctrl->value = new;
536 return 0; 544 return 0;
537} 545}
538 546
539static int saa6752hs_qctrl(struct saa6752hs_state *h, 547
540 struct v4l2_queryctrl *qctrl) 548static int saa6752hs_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qctrl)
541{ 549{
550 struct saa6752hs_state *h = to_state(sd);
542 struct saa6752hs_mpeg_params *params = &h->params; 551 struct saa6752hs_mpeg_params *params = &h->params;
543 int err; 552 int err;
544 553
@@ -583,7 +592,7 @@ static int saa6752hs_qctrl(struct saa6752hs_state *h,
583 V4L2_MPEG_VIDEO_ASPECT_4x3); 592 V4L2_MPEG_VIDEO_ASPECT_4x3);
584 593
585 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK: 594 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK:
586 err = v4l2_ctrl_query_fill_std(qctrl); 595 err = v4l2_ctrl_query_fill(qctrl, 0, 27000000, 1, 8000000);
587 if (err == 0 && 596 if (err == 0 &&
588 params->vi_bitrate_mode == 597 params->vi_bitrate_mode ==
589 V4L2_MPEG_VIDEO_BITRATE_MODE_CBR) 598 V4L2_MPEG_VIDEO_BITRATE_MODE_CBR)
@@ -597,12 +606,20 @@ static int saa6752hs_qctrl(struct saa6752hs_state *h,
597 V4L2_MPEG_STREAM_TYPE_MPEG2_TS); 606 V4L2_MPEG_STREAM_TYPE_MPEG2_TS);
598 607
599 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: 608 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
609 return v4l2_ctrl_query_fill(qctrl,
610 V4L2_MPEG_VIDEO_BITRATE_MODE_VBR,
611 V4L2_MPEG_VIDEO_BITRATE_MODE_CBR, 1,
612 V4L2_MPEG_VIDEO_BITRATE_MODE_VBR);
600 case V4L2_CID_MPEG_VIDEO_BITRATE: 613 case V4L2_CID_MPEG_VIDEO_BITRATE:
614 return v4l2_ctrl_query_fill(qctrl, 0, 27000000, 1, 6000000);
601 case V4L2_CID_MPEG_STREAM_PID_PMT: 615 case V4L2_CID_MPEG_STREAM_PID_PMT:
616 return v4l2_ctrl_query_fill(qctrl, 0, (1 << 14) - 1, 1, 16);
602 case V4L2_CID_MPEG_STREAM_PID_AUDIO: 617 case V4L2_CID_MPEG_STREAM_PID_AUDIO:
618 return v4l2_ctrl_query_fill(qctrl, 0, (1 << 14) - 1, 1, 260);
603 case V4L2_CID_MPEG_STREAM_PID_VIDEO: 619 case V4L2_CID_MPEG_STREAM_PID_VIDEO:
620 return v4l2_ctrl_query_fill(qctrl, 0, (1 << 14) - 1, 1, 256);
604 case V4L2_CID_MPEG_STREAM_PID_PCR: 621 case V4L2_CID_MPEG_STREAM_PID_PCR:
605 return v4l2_ctrl_query_fill_std(qctrl); 622 return v4l2_ctrl_query_fill(qctrl, 0, (1 << 14) - 1, 1, 259);
606 623
607 default: 624 default:
608 break; 625 break;
@@ -610,8 +627,7 @@ static int saa6752hs_qctrl(struct saa6752hs_state *h,
610 return -EINVAL; 627 return -EINVAL;
611} 628}
612 629
613static int saa6752hs_qmenu(struct saa6752hs_state *h, 630static int saa6752hs_querymenu(struct v4l2_subdev *sd, struct v4l2_querymenu *qmenu)
614 struct v4l2_querymenu *qmenu)
615{ 631{
616 static const u32 mpeg_audio_encoding[] = { 632 static const u32 mpeg_audio_encoding[] = {
617 V4L2_MPEG_AUDIO_ENCODING_LAYER_2, 633 V4L2_MPEG_AUDIO_ENCODING_LAYER_2,
@@ -632,11 +648,12 @@ static int saa6752hs_qmenu(struct saa6752hs_state *h,
632 V4L2_MPEG_AUDIO_AC3_BITRATE_384K, 648 V4L2_MPEG_AUDIO_AC3_BITRATE_384K,
633 V4L2_CTRL_MENU_IDS_END 649 V4L2_CTRL_MENU_IDS_END
634 }; 650 };
651 struct saa6752hs_state *h = to_state(sd);
635 struct v4l2_queryctrl qctrl; 652 struct v4l2_queryctrl qctrl;
636 int err; 653 int err;
637 654
638 qctrl.id = qmenu->id; 655 qctrl.id = qmenu->id;
639 err = saa6752hs_qctrl(h, &qctrl); 656 err = saa6752hs_queryctrl(sd, &qctrl);
640 if (err) 657 if (err)
641 return err; 658 return err;
642 switch (qmenu->id) { 659 switch (qmenu->id) {
@@ -656,17 +673,16 @@ static int saa6752hs_qmenu(struct saa6752hs_state *h,
656 return v4l2_ctrl_query_menu(qmenu, &qctrl, NULL); 673 return v4l2_ctrl_query_menu(qmenu, &qctrl, NULL);
657} 674}
658 675
659static int saa6752hs_init(struct i2c_client *client, u32 leading_null_bytes) 676static int saa6752hs_init(struct v4l2_subdev *sd, u32 leading_null_bytes)
660{ 677{
661 unsigned char buf[9], buf2[4]; 678 unsigned char buf[9], buf2[4];
662 struct saa6752hs_state *h; 679 struct saa6752hs_state *h = to_state(sd);
680 struct i2c_client *client = v4l2_get_subdevdata(sd);
663 unsigned size; 681 unsigned size;
664 u32 crc; 682 u32 crc;
665 unsigned char localPAT[256]; 683 unsigned char localPAT[256];
666 unsigned char localPMT[256]; 684 unsigned char localPMT[256];
667 685
668 h = i2c_get_clientdata(client);
669
670 /* Set video format - must be done first as it resets other settings */ 686 /* Set video format - must be done first as it resets other settings */
671 set_reg8(client, 0x41, h->video_format); 687 set_reg8(client, 0x41, h->video_format);
672 688
@@ -762,7 +778,7 @@ static int saa6752hs_init(struct i2c_client *client, u32 leading_null_bytes)
762 buf[3] = 0x82; 778 buf[3] = 0x82;
763 buf[4] = 0xB0; 779 buf[4] = 0xB0;
764 buf[5] = buf2[0]; 780 buf[5] = buf2[0];
765 switch(h->params.vi_aspect) { 781 switch (h->params.vi_aspect) {
766 case V4L2_MPEG_VIDEO_ASPECT_16x9: 782 case V4L2_MPEG_VIDEO_ASPECT_16x9:
767 buf[6] = buf2[1] | 0x40; 783 buf[6] = buf2[1] | 0x40;
768 break; 784 break;
@@ -770,7 +786,6 @@ static int saa6752hs_init(struct i2c_client *client, u32 leading_null_bytes)
770 default: 786 default:
771 buf[6] = buf2[1] & 0xBF; 787 buf[6] = buf2[1] & 0xBF;
772 break; 788 break;
773 break;
774 } 789 }
775 buf[7] = buf2[2]; 790 buf[7] = buf2[2];
776 buf[8] = buf2[3]; 791 buf[8] = buf2[3];
@@ -779,81 +794,162 @@ static int saa6752hs_init(struct i2c_client *client, u32 leading_null_bytes)
779 return 0; 794 return 0;
780} 795}
781 796
782static int 797static int saa6752hs_do_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ctrls, int set)
783saa6752hs_command(struct i2c_client *client, unsigned int cmd, void *arg)
784{ 798{
785 struct saa6752hs_state *h = i2c_get_clientdata(client); 799 struct saa6752hs_state *h = to_state(sd);
786 struct v4l2_ext_controls *ctrls = arg;
787 struct saa6752hs_mpeg_params params; 800 struct saa6752hs_mpeg_params params;
788 int err = 0;
789 int i; 801 int i;
790 802
791 switch (cmd) { 803 if (ctrls->ctrl_class != V4L2_CTRL_CLASS_MPEG)
792 case VIDIOC_INT_INIT: 804 return -EINVAL;
793 /* apply settings and start encoder */ 805
794 saa6752hs_init(client, *(u32 *)arg); 806 params = h->params;
795 break; 807 for (i = 0; i < ctrls->count; i++) {
796 case VIDIOC_S_EXT_CTRLS: 808 int err = handle_ctrl(h->has_ac3, &params, ctrls->controls + i, set);
797 if (ctrls->ctrl_class != V4L2_CTRL_CLASS_MPEG) 809
798 return -EINVAL; 810 if (err) {
799 /* fall through */ 811 ctrls->error_idx = i;
800 case VIDIOC_TRY_EXT_CTRLS: 812 return err;
801 case VIDIOC_G_EXT_CTRLS:
802 if (ctrls->ctrl_class != V4L2_CTRL_CLASS_MPEG)
803 return -EINVAL;
804 params = h->params;
805 for (i = 0; i < ctrls->count; i++) {
806 err = handle_ctrl(h->has_ac3, &params, ctrls->controls + i, cmd);
807 if (err) {
808 ctrls->error_idx = i;
809 return err;
810 }
811 } 813 }
812 h->params = params;
813 break;
814 case VIDIOC_QUERYCTRL:
815 return saa6752hs_qctrl(h, arg);
816 case VIDIOC_QUERYMENU:
817 return saa6752hs_qmenu(h, arg);
818 case VIDIOC_G_FMT:
819 {
820 struct v4l2_format *f = arg;
821
822 if (h->video_format == SAA6752HS_VF_UNKNOWN)
823 h->video_format = SAA6752HS_VF_D1;
824 f->fmt.pix.width =
825 v4l2_format_table[h->video_format].fmt.pix.width;
826 f->fmt.pix.height =
827 v4l2_format_table[h->video_format].fmt.pix.height;
828 break ;
829 } 814 }
830 case VIDIOC_S_FMT: 815 if (set)
831 { 816 h->params = params;
832 struct v4l2_format *f = arg; 817 return 0;
818}
833 819
834 saa6752hs_set_subsampling(client, f); 820static int saa6752hs_s_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ctrls)
835 break; 821{
822 return saa6752hs_do_ext_ctrls(sd, ctrls, 1);
823}
824
825static int saa6752hs_try_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ctrls)
826{
827 return saa6752hs_do_ext_ctrls(sd, ctrls, 0);
828}
829
830static int saa6752hs_g_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ctrls)
831{
832 struct saa6752hs_state *h = to_state(sd);
833 int i;
834
835 if (ctrls->ctrl_class != V4L2_CTRL_CLASS_MPEG)
836 return -EINVAL;
837
838 for (i = 0; i < ctrls->count; i++) {
839 int err = get_ctrl(h->has_ac3, &h->params, ctrls->controls + i);
840
841 if (err) {
842 ctrls->error_idx = i;
843 return err;
844 }
836 } 845 }
837 case VIDIOC_S_STD: 846 return 0;
838 h->standard = *((v4l2_std_id *) arg); 847}
839 break;
840 848
841 case VIDIOC_DBG_G_CHIP_IDENT: 849static int saa6752hs_g_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
842 return v4l2_chip_ident_i2c_client(client, 850{
843 arg, h->chip, h->revision); 851 struct saa6752hs_state *h = to_state(sd);
844 852
845 default: 853 if (h->video_format == SAA6752HS_VF_UNKNOWN)
846 /* nothing */ 854 h->video_format = SAA6752HS_VF_D1;
847 break; 855 f->fmt.pix.width =
856 v4l2_format_table[h->video_format].fmt.pix.width;
857 f->fmt.pix.height =
858 v4l2_format_table[h->video_format].fmt.pix.height;
859 return 0;
860}
861
862static int saa6752hs_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
863{
864 struct saa6752hs_state *h = to_state(sd);
865 int dist_352, dist_480, dist_720;
866
867 /*
868 FIXME: translate and round width/height into EMPRESS
869 subsample type:
870
871 type | PAL | NTSC
872 ---------------------------
873 SIF | 352x288 | 352x240
874 1/2 D1 | 352x576 | 352x480
875 2/3 D1 | 480x576 | 480x480
876 D1 | 720x576 | 720x480
877 */
878
879 dist_352 = abs(f->fmt.pix.width - 352);
880 dist_480 = abs(f->fmt.pix.width - 480);
881 dist_720 = abs(f->fmt.pix.width - 720);
882 if (dist_720 < dist_480) {
883 f->fmt.pix.width = 720;
884 f->fmt.pix.height = 576;
885 h->video_format = SAA6752HS_VF_D1;
886 } else if (dist_480 < dist_352) {
887 f->fmt.pix.width = 480;
888 f->fmt.pix.height = 576;
889 h->video_format = SAA6752HS_VF_2_3_D1;
890 } else {
891 f->fmt.pix.width = 352;
892 if (abs(f->fmt.pix.height - 576) <
893 abs(f->fmt.pix.height - 288)) {
894 f->fmt.pix.height = 576;
895 h->video_format = SAA6752HS_VF_1_2_D1;
896 } else {
897 f->fmt.pix.height = 288;
898 h->video_format = SAA6752HS_VF_SIF;
899 }
848 } 900 }
901 return 0;
902}
903
904static int saa6752hs_s_std(struct v4l2_subdev *sd, v4l2_std_id std)
905{
906 struct saa6752hs_state *h = to_state(sd);
907
908 h->standard = std;
909 return 0;
910}
849 911
850 return err; 912static int saa6752hs_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
913{
914 struct i2c_client *client = v4l2_get_subdevdata(sd);
915 struct saa6752hs_state *h = to_state(sd);
916
917 return v4l2_chip_ident_i2c_client(client,
918 chip, h->chip, h->revision);
851} 919}
852 920
921/* ----------------------------------------------------------------------- */
922
923static const struct v4l2_subdev_core_ops saa6752hs_core_ops = {
924 .g_chip_ident = saa6752hs_g_chip_ident,
925 .init = saa6752hs_init,
926 .queryctrl = saa6752hs_queryctrl,
927 .querymenu = saa6752hs_querymenu,
928 .g_ext_ctrls = saa6752hs_g_ext_ctrls,
929 .s_ext_ctrls = saa6752hs_s_ext_ctrls,
930 .try_ext_ctrls = saa6752hs_try_ext_ctrls,
931};
932
933static const struct v4l2_subdev_tuner_ops saa6752hs_tuner_ops = {
934 .s_std = saa6752hs_s_std,
935};
936
937static const struct v4l2_subdev_video_ops saa6752hs_video_ops = {
938 .s_fmt = saa6752hs_s_fmt,
939 .g_fmt = saa6752hs_g_fmt,
940};
941
942static const struct v4l2_subdev_ops saa6752hs_ops = {
943 .core = &saa6752hs_core_ops,
944 .tuner = &saa6752hs_tuner_ops,
945 .video = &saa6752hs_video_ops,
946};
947
853static int saa6752hs_probe(struct i2c_client *client, 948static int saa6752hs_probe(struct i2c_client *client,
854 const struct i2c_device_id *id) 949 const struct i2c_device_id *id)
855{ 950{
856 struct saa6752hs_state *h = kzalloc(sizeof(*h), GFP_KERNEL); 951 struct saa6752hs_state *h = kzalloc(sizeof(*h), GFP_KERNEL);
952 struct v4l2_subdev *sd;
857 u8 addr = 0x13; 953 u8 addr = 0x13;
858 u8 data[12]; 954 u8 data[12];
859 955
@@ -861,6 +957,8 @@ static int saa6752hs_probe(struct i2c_client *client,
861 client->addr << 1, client->adapter->name); 957 client->addr << 1, client->adapter->name);
862 if (h == NULL) 958 if (h == NULL)
863 return -ENOMEM; 959 return -ENOMEM;
960 sd = &h->sd;
961 v4l2_i2c_subdev_init(sd, client, &saa6752hs_ops);
864 962
865 i2c_master_send(client, &addr, 1); 963 i2c_master_send(client, &addr, 1);
866 i2c_master_recv(client, data, sizeof(data)); 964 i2c_master_recv(client, data, sizeof(data));
@@ -874,14 +972,15 @@ static int saa6752hs_probe(struct i2c_client *client,
874 } 972 }
875 h->params = param_defaults; 973 h->params = param_defaults;
876 h->standard = 0; /* Assume 625 input lines */ 974 h->standard = 0; /* Assume 625 input lines */
877
878 i2c_set_clientdata(client, h);
879 return 0; 975 return 0;
880} 976}
881 977
882static int saa6752hs_remove(struct i2c_client *client) 978static int saa6752hs_remove(struct i2c_client *client)
883{ 979{
884 kfree(i2c_get_clientdata(client)); 980 struct v4l2_subdev *sd = i2c_get_clientdata(client);
981
982 v4l2_device_unregister_subdev(sd);
983 kfree(to_state(sd));
885 return 0; 984 return 0;
886} 985}
887 986
@@ -893,8 +992,6 @@ MODULE_DEVICE_TABLE(i2c, saa6752hs_id);
893 992
894static struct v4l2_i2c_driver_data v4l2_i2c_data = { 993static struct v4l2_i2c_driver_data v4l2_i2c_data = {
895 .name = "saa6752hs", 994 .name = "saa6752hs",
896 .driverid = I2C_DRIVERID_SAA6752HS,
897 .command = saa6752hs_command,
898 .probe = saa6752hs_probe, 995 .probe = saa6752hs_probe,
899 .remove = saa6752hs_remove, 996 .remove = saa6752hs_remove,
900 .id_table = saa6752hs_id, 997 .id_table = saa6752hs_id,
diff --git a/drivers/media/video/saa7134/saa7134-cards.c b/drivers/media/video/saa7134/saa7134-cards.c
index e2febcd6e529..a790a7246a63 100644
--- a/drivers/media/video/saa7134/saa7134-cards.c
+++ b/drivers/media/video/saa7134/saa7134-cards.c
@@ -31,6 +31,7 @@
31#include <media/v4l2-common.h> 31#include <media/v4l2-common.h>
32#include <media/tveeprom.h> 32#include <media/tveeprom.h>
33#include "tea5767.h" 33#include "tea5767.h"
34#include "tda18271.h"
34 35
35/* commly used strings */ 36/* commly used strings */
36static char name_mute[] = "mute"; 37static char name_mute[] = "mute";
@@ -272,6 +273,7 @@ struct saa7134_board saa7134_boards[] = {
272 .radio_type = UNSET, 273 .radio_type = UNSET,
273 .tuner_addr = ADDR_UNSET, 274 .tuner_addr = ADDR_UNSET,
274 .radio_addr = ADDR_UNSET, 275 .radio_addr = ADDR_UNSET,
276 .empress_addr = 0x20,
275 277
276 .inputs = {{ 278 .inputs = {{
277 .name = name_comp1, 279 .name = name_comp1,
@@ -408,6 +410,7 @@ struct saa7134_board saa7134_boards[] = {
408 .radio_type = UNSET, 410 .radio_type = UNSET,
409 .tuner_addr = ADDR_UNSET, 411 .tuner_addr = ADDR_UNSET,
410 .radio_addr = ADDR_UNSET, 412 .radio_addr = ADDR_UNSET,
413 .empress_addr = 0x20,
411 .tda9887_conf = TDA9887_PRESENT, 414 .tda9887_conf = TDA9887_PRESENT,
412 .gpiomask = 0x820000, 415 .gpiomask = 0x820000,
413 .inputs = {{ 416 .inputs = {{
@@ -818,6 +821,7 @@ struct saa7134_board saa7134_boards[] = {
818 .radio_type = UNSET, 821 .radio_type = UNSET,
819 .tuner_addr = ADDR_UNSET, 822 .tuner_addr = ADDR_UNSET,
820 .radio_addr = ADDR_UNSET, 823 .radio_addr = ADDR_UNSET,
824 .empress_addr = 0x20,
821 .inputs = {{ 825 .inputs = {{
822 .name = name_comp1, 826 .name = name_comp1,
823 .vmux = 4, 827 .vmux = 4,
@@ -977,6 +981,7 @@ struct saa7134_board saa7134_boards[] = {
977 .radio_type = UNSET, 981 .radio_type = UNSET,
978 .tuner_addr = ADDR_UNSET, 982 .tuner_addr = ADDR_UNSET,
979 .radio_addr = ADDR_UNSET, 983 .radio_addr = ADDR_UNSET,
984 .empress_addr = 0x20,
980 .inputs = {{ 985 .inputs = {{
981 .name = name_comp1, 986 .name = name_comp1,
982 .vmux = 1, 987 .vmux = 1,
@@ -1699,6 +1704,7 @@ struct saa7134_board saa7134_boards[] = {
1699 .radio_type = UNSET, 1704 .radio_type = UNSET,
1700 .tuner_addr = ADDR_UNSET, 1705 .tuner_addr = ADDR_UNSET,
1701 .radio_addr = ADDR_UNSET, 1706 .radio_addr = ADDR_UNSET,
1707 .rds_addr = 0x10,
1702 .tda9887_conf = TDA9887_PRESENT, 1708 .tda9887_conf = TDA9887_PRESENT,
1703 .inputs = {{ 1709 .inputs = {{
1704 .name = name_tv, 1710 .name = name_tv,
@@ -2364,6 +2370,7 @@ struct saa7134_board saa7134_boards[] = {
2364 .radio_type = UNSET, 2370 .radio_type = UNSET,
2365 .tuner_addr = ADDR_UNSET, 2371 .tuner_addr = ADDR_UNSET,
2366 .radio_addr = ADDR_UNSET, 2372 .radio_addr = ADDR_UNSET,
2373 .empress_addr = 0x21,
2367 .inputs = {{ 2374 .inputs = {{
2368 .name = "Composite 0", 2375 .name = "Composite 0",
2369 .vmux = 0, 2376 .vmux = 0,
@@ -3291,6 +3298,68 @@ struct saa7134_board saa7134_boards[] = {
3291 .gpio = 0x0200100, 3298 .gpio = 0x0200100,
3292 }, 3299 },
3293 }, 3300 },
3301 [SAA7134_BOARD_HAUPPAUGE_HVR1120] = {
3302 .name = "Hauppauge WinTV-HVR1120 ATSC/QAM-Hybrid",
3303 .audio_clock = 0x00187de7,
3304 .tuner_type = TUNER_PHILIPS_TDA8290,
3305 .radio_type = UNSET,
3306 .tuner_addr = ADDR_UNSET,
3307 .radio_addr = ADDR_UNSET,
3308 .tuner_config = 3,
3309 .mpeg = SAA7134_MPEG_DVB,
3310 .ts_type = SAA7134_MPEG_TS_SERIAL,
3311 .gpiomask = 0x0800100, /* GPIO 21 is an INPUT */
3312 .inputs = {{
3313 .name = name_tv,
3314 .vmux = 1,
3315 .amux = TV,
3316 .tv = 1,
3317 .gpio = 0x0000100,
3318 }, {
3319 .name = name_comp1,
3320 .vmux = 3,
3321 .amux = LINE1,
3322 }, {
3323 .name = name_svideo,
3324 .vmux = 8,
3325 .amux = LINE1,
3326 } },
3327 .radio = {
3328 .name = name_radio,
3329 .amux = TV,
3330 .gpio = 0x0800100, /* GPIO 23 HI for FM */
3331 },
3332 },
3333 [SAA7134_BOARD_HAUPPAUGE_HVR1110R3] = {
3334 .name = "Hauppauge WinTV-HVR1110r3",
3335 .audio_clock = 0x00187de7,
3336 .tuner_type = TUNER_PHILIPS_TDA8290,
3337 .radio_type = UNSET,
3338 .tuner_addr = ADDR_UNSET,
3339 .radio_addr = ADDR_UNSET,
3340 .tuner_config = 3,
3341 .gpiomask = 0x0800100, /* GPIO 21 is an INPUT */
3342 .inputs = {{
3343 .name = name_tv,
3344 .vmux = 1,
3345 .amux = TV,
3346 .tv = 1,
3347 .gpio = 0x0000100,
3348 }, {
3349 .name = name_comp1,
3350 .vmux = 3,
3351 .amux = LINE1,
3352 }, {
3353 .name = name_svideo,
3354 .vmux = 8,
3355 .amux = LINE1,
3356 } },
3357 .radio = {
3358 .name = name_radio,
3359 .amux = TV,
3360 .gpio = 0x0800100, /* GPIO 23 HI for FM */
3361 },
3362 },
3294 [SAA7134_BOARD_CINERGY_HT_PCMCIA] = { 3363 [SAA7134_BOARD_CINERGY_HT_PCMCIA] = {
3295 .name = "Terratec Cinergy HT PCMCIA", 3364 .name = "Terratec Cinergy HT PCMCIA",
3296 .audio_clock = 0x00187de7, 3365 .audio_clock = 0x00187de7,
@@ -4070,6 +4139,7 @@ struct saa7134_board saa7134_boards[] = {
4070 .radio_type = UNSET, 4139 .radio_type = UNSET,
4071 .tuner_addr = ADDR_UNSET, 4140 .tuner_addr = ADDR_UNSET,
4072 .radio_addr = ADDR_UNSET, 4141 .radio_addr = ADDR_UNSET,
4142 .empress_addr = 0x20,
4073 .tda9887_conf = TDA9887_PRESENT, 4143 .tda9887_conf = TDA9887_PRESENT,
4074 .inputs = { { 4144 .inputs = { {
4075 .name = name_tv, 4145 .name = name_tv,
@@ -4106,6 +4176,7 @@ struct saa7134_board saa7134_boards[] = {
4106 .radio_type = UNSET, 4176 .radio_type = UNSET,
4107 .tuner_addr = ADDR_UNSET, 4177 .tuner_addr = ADDR_UNSET,
4108 .radio_addr = ADDR_UNSET, 4178 .radio_addr = ADDR_UNSET,
4179 .empress_addr = 0x20,
4109 .tda9887_conf = TDA9887_PRESENT, 4180 .tda9887_conf = TDA9887_PRESENT,
4110 .inputs = { { 4181 .inputs = { {
4111 .name = name_tv, 4182 .name = name_tv,
@@ -4143,6 +4214,7 @@ struct saa7134_board saa7134_boards[] = {
4143 .radio_type = UNSET, 4214 .radio_type = UNSET,
4144 .tuner_addr = ADDR_UNSET, 4215 .tuner_addr = ADDR_UNSET,
4145 .radio_addr = ADDR_UNSET, 4216 .radio_addr = ADDR_UNSET,
4217 .empress_addr = 0x20,
4146 .tda9887_conf = TDA9887_PRESENT, 4218 .tda9887_conf = TDA9887_PRESENT,
4147 .inputs = { { 4219 .inputs = { {
4148 .name = name_tv, 4220 .name = name_tv,
@@ -4323,13 +4395,13 @@ struct saa7134_board saa7134_boards[] = {
4323 .amux = TV, 4395 .amux = TV,
4324 .tv = 1, 4396 .tv = 1,
4325 }, { 4397 }, {
4326 .name = name_comp, 4398 .name = name_comp1,
4327 .vmux = 0, 4399 .vmux = 3,
4328 .amux = LINE1, 4400 .amux = LINE1,
4329 }, { 4401 }, {
4330 .name = name_svideo, 4402 .name = name_svideo,
4331 .vmux = 8, 4403 .vmux = 8,
4332 .amux = LINE1, 4404 .amux = LINE2,
4333 } }, 4405 } },
4334 .radio = { 4406 .radio = {
4335 .name = name_radio, 4407 .name = name_radio,
@@ -4421,8 +4493,7 @@ struct saa7134_board saa7134_boards[] = {
4421 .radio_type = UNSET, 4493 .radio_type = UNSET,
4422 .tuner_addr = ADDR_UNSET, 4494 .tuner_addr = ADDR_UNSET,
4423 .radio_addr = ADDR_UNSET, 4495 .radio_addr = ADDR_UNSET,
4424 /* no DVB support for now */ 4496 .mpeg = SAA7134_MPEG_DVB,
4425 /* .mpeg = SAA7134_MPEG_DVB, */
4426 .inputs = { { 4497 .inputs = { {
4427 .name = name_comp, 4498 .name = name_comp,
4428 .vmux = 1, 4499 .vmux = 1,
@@ -4441,8 +4512,7 @@ struct saa7134_board saa7134_boards[] = {
4441 .radio_type = UNSET, 4512 .radio_type = UNSET,
4442 .tuner_addr = ADDR_UNSET, 4513 .tuner_addr = ADDR_UNSET,
4443 .radio_addr = ADDR_UNSET, 4514 .radio_addr = ADDR_UNSET,
4444 /* no DVB support for now */ 4515 .mpeg = SAA7134_MPEG_DVB,
4445 /* .mpeg = SAA7134_MPEG_DVB, */
4446 .inputs = { { 4516 .inputs = { {
4447 .name = name_comp, 4517 .name = name_comp,
4448 .vmux = 1, 4518 .vmux = 1,
@@ -4611,7 +4681,7 @@ struct saa7134_board saa7134_boards[] = {
4611 .tuner_type = TUNER_YMEC_TVF_5533MF, 4681 .tuner_type = TUNER_YMEC_TVF_5533MF,
4612 .radio_type = TUNER_TEA5767, 4682 .radio_type = TUNER_TEA5767,
4613 .tuner_addr = ADDR_UNSET, 4683 .tuner_addr = ADDR_UNSET,
4614 .radio_addr = ADDR_UNSET, 4684 .radio_addr = 0x60,
4615 .gpiomask = 0x80000700, 4685 .gpiomask = 0x80000700,
4616 .inputs = { { 4686 .inputs = { {
4617 .name = name_tv, 4687 .name = name_tv,
@@ -5405,6 +5475,36 @@ struct pci_device_id saa7134_pci_tbl[] = {
5405 },{ 5475 },{
5406 .vendor = PCI_VENDOR_ID_PHILIPS, 5476 .vendor = PCI_VENDOR_ID_PHILIPS,
5407 .device = PCI_DEVICE_ID_PHILIPS_SAA7133, 5477 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
5478 .subvendor = 0x0070,
5479 .subdevice = 0x6706,
5480 .driver_data = SAA7134_BOARD_HAUPPAUGE_HVR1120,
5481 },{
5482 .vendor = PCI_VENDOR_ID_PHILIPS,
5483 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
5484 .subvendor = 0x0070,
5485 .subdevice = 0x6707,
5486 .driver_data = SAA7134_BOARD_HAUPPAUGE_HVR1110R3,
5487 },{
5488 .vendor = PCI_VENDOR_ID_PHILIPS,
5489 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
5490 .subvendor = 0x0070,
5491 .subdevice = 0x6708,
5492 .driver_data = SAA7134_BOARD_HAUPPAUGE_HVR1120,
5493 },{
5494 .vendor = PCI_VENDOR_ID_PHILIPS,
5495 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
5496 .subvendor = 0x0070,
5497 .subdevice = 0x6709,
5498 .driver_data = SAA7134_BOARD_HAUPPAUGE_HVR1110R3,
5499 },{
5500 .vendor = PCI_VENDOR_ID_PHILIPS,
5501 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
5502 .subvendor = 0x0070,
5503 .subdevice = 0x670a,
5504 .driver_data = SAA7134_BOARD_HAUPPAUGE_HVR1110R3,
5505 },{
5506 .vendor = PCI_VENDOR_ID_PHILIPS,
5507 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
5408 .subvendor = 0x153b, 5508 .subvendor = 0x153b,
5409 .subdevice = 0x1172, 5509 .subdevice = 0x1172,
5410 .driver_data = SAA7134_BOARD_CINERGY_HT_PCMCIA, 5510 .driver_data = SAA7134_BOARD_CINERGY_HT_PCMCIA,
@@ -5821,8 +5921,8 @@ static int saa7134_xc2028_callback(struct saa7134_dev *dev,
5821} 5921}
5822 5922
5823 5923
5824static int saa7134_tda8290_callback(struct saa7134_dev *dev, 5924static int saa7134_tda8290_827x_callback(struct saa7134_dev *dev,
5825 int command, int arg) 5925 int command, int arg)
5826{ 5926{
5827 u8 sync_control; 5927 u8 sync_control;
5828 5928
@@ -5848,6 +5948,65 @@ static int saa7134_tda8290_callback(struct saa7134_dev *dev,
5848 return 0; 5948 return 0;
5849} 5949}
5850 5950
5951static inline int saa7134_tda18271_hvr11x0_toggle_agc(struct saa7134_dev *dev,
5952 enum tda18271_mode mode)
5953{
5954 /* toggle AGC switch through GPIO 26 */
5955 switch (mode) {
5956 case TDA18271_ANALOG:
5957 saa7134_set_gpio(dev, 26, 0);
5958 break;
5959 case TDA18271_DIGITAL:
5960 saa7134_set_gpio(dev, 26, 1);
5961 break;
5962 default:
5963 return -EINVAL;
5964 }
5965 return 0;
5966}
5967
5968static int saa7134_tda8290_18271_callback(struct saa7134_dev *dev,
5969 int command, int arg)
5970{
5971 int ret = 0;
5972
5973 switch (command) {
5974 case TDA18271_CALLBACK_CMD_AGC_ENABLE: /* 0 */
5975 switch (dev->board) {
5976 case SAA7134_BOARD_HAUPPAUGE_HVR1120:
5977 case SAA7134_BOARD_HAUPPAUGE_HVR1110R3:
5978 ret = saa7134_tda18271_hvr11x0_toggle_agc(dev, arg);
5979 break;
5980 default:
5981 break;
5982 }
5983 break;
5984 default:
5985 ret = -EINVAL;
5986 break;
5987 }
5988 return ret;
5989}
5990
5991static int saa7134_tda8290_callback(struct saa7134_dev *dev,
5992 int command, int arg)
5993{
5994 int ret;
5995
5996 switch (dev->board) {
5997 case SAA7134_BOARD_HAUPPAUGE_HVR1120:
5998 case SAA7134_BOARD_HAUPPAUGE_HVR1110R3:
5999 /* tda8290 + tda18271 */
6000 ret = saa7134_tda8290_18271_callback(dev, command, arg);
6001 break;
6002 default:
6003 /* tda8290 + tda827x */
6004 ret = saa7134_tda8290_827x_callback(dev, command, arg);
6005 break;
6006 }
6007 return ret;
6008}
6009
5851int saa7134_tuner_callback(void *priv, int component, int command, int arg) 6010int saa7134_tuner_callback(void *priv, int component, int command, int arg)
5852{ 6011{
5853 struct saa7134_dev *dev = priv; 6012 struct saa7134_dev *dev = priv;
@@ -5878,11 +6037,16 @@ static void hauppauge_eeprom(struct saa7134_dev *dev, u8 *eeprom_data)
5878 switch (tv.model) { 6037 switch (tv.model) {
5879 case 67019: /* WinTV-HVR1110 (Retail, IR Blaster, hybrid, FM, SVid/Comp, 3.5mm audio in) */ 6038 case 67019: /* WinTV-HVR1110 (Retail, IR Blaster, hybrid, FM, SVid/Comp, 3.5mm audio in) */
5880 case 67109: /* WinTV-HVR1000 (Retail, IR Receive, analog, no FM, SVid/Comp, 3.5mm audio in) */ 6039 case 67109: /* WinTV-HVR1000 (Retail, IR Receive, analog, no FM, SVid/Comp, 3.5mm audio in) */
6040 case 67201: /* WinTV-HVR1120 (Retail, IR Receive, hybrid, FM, SVid/Comp, 3.5mm audio in) */
6041 case 67301: /* WinTV-HVR1000 (Retail, IR Receive, analog, no FM, SVid/Comp, 3.5mm audio in) */
6042 case 67209: /* WinTV-HVR1110 (Retail, IR Receive, hybrid, FM, SVid/Comp, 3.5mm audio in) */
5881 case 67559: /* WinTV-HVR1110 (OEM, no IR, hybrid, FM, SVid/Comp, RCA aud) */ 6043 case 67559: /* WinTV-HVR1110 (OEM, no IR, hybrid, FM, SVid/Comp, RCA aud) */
5882 case 67569: /* WinTV-HVR1110 (OEM, no IR, hybrid, FM) */ 6044 case 67569: /* WinTV-HVR1110 (OEM, no IR, hybrid, FM) */
5883 case 67579: /* WinTV-HVR1110 (OEM, no IR, hybrid, no FM) */ 6045 case 67579: /* WinTV-HVR1110 (OEM, no IR, hybrid, no FM) */
5884 case 67589: /* WinTV-HVR1110 (OEM, no IR, hybrid, no FM, SVid/Comp, RCA aud) */ 6046 case 67589: /* WinTV-HVR1110 (OEM, no IR, hybrid, no FM, SVid/Comp, RCA aud) */
5885 case 67599: /* WinTV-HVR1110 (OEM, no IR, hybrid, no FM, SVid/Comp, RCA aud) */ 6047 case 67599: /* WinTV-HVR1110 (OEM, no IR, hybrid, no FM, SVid/Comp, RCA aud) */
6048 case 67651: /* WinTV-HVR1120 (OEM, no IR, hybrid, FM, SVid/Comp, RCA aud) */
6049 case 67659: /* WinTV-HVR1110 (OEM, no IR, hybrid, FM, SVid/Comp, RCA aud) */
5886 break; 6050 break;
5887 default: 6051 default:
5888 printk(KERN_WARNING "%s: warning: " 6052 printk(KERN_WARNING "%s: warning: "
@@ -6019,6 +6183,11 @@ int saa7134_board_init1(struct saa7134_dev *dev)
6019 msleep(10); 6183 msleep(10);
6020 break; 6184 break;
6021 case SAA7134_BOARD_AVERMEDIA_CARDBUS_506: 6185 case SAA7134_BOARD_AVERMEDIA_CARDBUS_506:
6186 saa7134_set_gpio(dev, 23, 0);
6187 msleep(10);
6188 saa7134_set_gpio(dev, 23, 1);
6189 dev->has_remote = SAA7134_REMOTE_I2C;
6190 break;
6022 case SAA7134_BOARD_AVERMEDIA_M103: 6191 case SAA7134_BOARD_AVERMEDIA_M103:
6023 saa7134_set_gpio(dev, 23, 0); 6192 saa7134_set_gpio(dev, 23, 0);
6024 msleep(10); 6193 msleep(10);
@@ -6054,6 +6223,16 @@ int saa7134_board_init1(struct saa7134_dev *dev)
6054 6223
6055 saa_writeb (SAA7134_PRODUCTION_TEST_MODE, 0x00); 6224 saa_writeb (SAA7134_PRODUCTION_TEST_MODE, 0x00);
6056 break; 6225 break;
6226 case SAA7134_BOARD_HAUPPAUGE_HVR1120:
6227 case SAA7134_BOARD_HAUPPAUGE_HVR1110R3:
6228 /* GPIO 26 high for digital, low for analog */
6229 saa7134_set_gpio(dev, 26, 0);
6230 msleep(1);
6231
6232 saa7134_set_gpio(dev, 22, 0);
6233 msleep(10);
6234 saa7134_set_gpio(dev, 22, 1);
6235 break;
6057 /* i2c remotes */ 6236 /* i2c remotes */
6058 case SAA7134_BOARD_PINNACLE_PCTV_110i: 6237 case SAA7134_BOARD_PINNACLE_PCTV_110i:
6059 case SAA7134_BOARD_PINNACLE_PCTV_310i: 6238 case SAA7134_BOARD_PINNACLE_PCTV_310i:
@@ -6079,15 +6258,15 @@ int saa7134_board_init1(struct saa7134_dev *dev)
6079 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, 0x8c040007, 0x8c040007); 6258 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, 0x8c040007, 0x8c040007);
6080 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, 0x0c0007cd, 0x0c0007cd); 6259 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, 0x0c0007cd, 0x0c0007cd);
6081 break; 6260 break;
6082 case SAA7134_BOARD_AVERMEDIA_A700_PRO:
6083 case SAA7134_BOARD_AVERMEDIA_A700_HYBRID: 6261 case SAA7134_BOARD_AVERMEDIA_A700_HYBRID:
6084 /* write windows gpio values */
6085 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, 0x80040100, 0x80040100);
6086 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, 0x80040100, 0x00040100);
6087 printk("%s: %s: hybrid analog/dvb card\n" 6262 printk("%s: %s: hybrid analog/dvb card\n"
6088 "%s: Sorry, only analog s-video and composite input " 6263 "%s: Sorry, of the analog inputs, only analog s-video and composite "
6089 "are supported for now.\n", 6264 "are supported for now.\n",
6090 dev->name, card(dev).name, dev->name); 6265 dev->name, card(dev).name, dev->name);
6266 case SAA7134_BOARD_AVERMEDIA_A700_PRO:
6267 /* write windows gpio values */
6268 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, 0x80040100, 0x80040100);
6269 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, 0x80040100, 0x00040100);
6091 break; 6270 break;
6092 } 6271 }
6093 return 0; 6272 return 0;
@@ -6109,7 +6288,7 @@ static void saa7134_tuner_setup(struct saa7134_dev *dev)
6109 6288
6110 tun_setup.mode_mask = T_RADIO; 6289 tun_setup.mode_mask = T_RADIO;
6111 6290
6112 saa7134_i2c_call_clients(dev, TUNER_SET_TYPE_ADDR, &tun_setup); 6291 saa_call_all(dev, tuner, s_type_addr, &tun_setup);
6113 mode_mask &= ~T_RADIO; 6292 mode_mask &= ~T_RADIO;
6114 } 6293 }
6115 6294
@@ -6121,7 +6300,7 @@ static void saa7134_tuner_setup(struct saa7134_dev *dev)
6121 6300
6122 tun_setup.mode_mask = mode_mask; 6301 tun_setup.mode_mask = mode_mask;
6123 6302
6124 saa7134_i2c_call_clients(dev, TUNER_SET_TYPE_ADDR, &tun_setup); 6303 saa_call_all(dev, tuner, s_type_addr, &tun_setup);
6125 } 6304 }
6126 6305
6127 if (dev->tda9887_conf) { 6306 if (dev->tda9887_conf) {
@@ -6130,8 +6309,7 @@ static void saa7134_tuner_setup(struct saa7134_dev *dev)
6130 tda9887_cfg.tuner = TUNER_TDA9887; 6309 tda9887_cfg.tuner = TUNER_TDA9887;
6131 tda9887_cfg.priv = &dev->tda9887_conf; 6310 tda9887_cfg.priv = &dev->tda9887_conf;
6132 6311
6133 saa7134_i2c_call_clients(dev, TUNER_SET_CONFIG, 6312 saa_call_all(dev, tuner, s_config, &tda9887_cfg);
6134 &tda9887_cfg);
6135 } 6313 }
6136 6314
6137 if (dev->tuner_type == TUNER_XC2028) { 6315 if (dev->tuner_type == TUNER_XC2028) {
@@ -6158,7 +6336,7 @@ static void saa7134_tuner_setup(struct saa7134_dev *dev)
6158 xc2028_cfg.tuner = TUNER_XC2028; 6336 xc2028_cfg.tuner = TUNER_XC2028;
6159 xc2028_cfg.priv = &ctl; 6337 xc2028_cfg.priv = &ctl;
6160 6338
6161 saa7134_i2c_call_clients(dev, TUNER_SET_CONFIG, &xc2028_cfg); 6339 saa_call_all(dev, tuner, s_config, &xc2028_cfg);
6162 } 6340 }
6163} 6341}
6164 6342
@@ -6168,9 +6346,20 @@ int saa7134_board_init2(struct saa7134_dev *dev)
6168 unsigned char buf; 6346 unsigned char buf;
6169 int board; 6347 int board;
6170 6348
6349 /* Put here the code that enables the chips that are needed
6350 for analog mode and doesn't depend on the tuner attachment.
6351 It is also a good idea to get tuner type from eeprom, etc before
6352 initializing tuner, since we can avoid loading tuner driver
6353 on devices that has TUNER_ABSENT
6354 */
6171 switch (dev->board) { 6355 switch (dev->board) {
6172 case SAA7134_BOARD_BMK_MPEX_NOTUNER: 6356 case SAA7134_BOARD_BMK_MPEX_NOTUNER:
6173 case SAA7134_BOARD_BMK_MPEX_TUNER: 6357 case SAA7134_BOARD_BMK_MPEX_TUNER:
6358 /* Checks if the device has a tuner at 0x60 addr
6359 If the device doesn't have a tuner, TUNER_ABSENT
6360 will be used at tuner_type, avoiding loading tuner
6361 without needing it
6362 */
6174 dev->i2c_client.addr = 0x60; 6363 dev->i2c_client.addr = 0x60;
6175 board = (i2c_master_recv(&dev->i2c_client, &buf, 0) < 0) 6364 board = (i2c_master_recv(&dev->i2c_client, &buf, 0) < 0)
6176 ? SAA7134_BOARD_BMK_MPEX_NOTUNER 6365 ? SAA7134_BOARD_BMK_MPEX_NOTUNER
@@ -6188,11 +6377,15 @@ int saa7134_board_init2(struct saa7134_dev *dev)
6188 u8 subaddr; 6377 u8 subaddr;
6189 u8 data[3]; 6378 u8 data[3];
6190 int ret, tuner_t; 6379 int ret, tuner_t;
6191
6192 struct i2c_msg msg[] = {{.addr=0x50, .flags=0, .buf=&subaddr, .len = 1}, 6380 struct i2c_msg msg[] = {{.addr=0x50, .flags=0, .buf=&subaddr, .len = 1},
6193 {.addr=0x50, .flags=I2C_M_RD, .buf=data, .len = 3}}; 6381 {.addr=0x50, .flags=I2C_M_RD, .buf=data, .len = 3}};
6382
6194 subaddr= 0x14; 6383 subaddr= 0x14;
6195 tuner_t = 0; 6384 tuner_t = 0;
6385
6386 /* Retrieve device data from eeprom, checking for the
6387 proper tuner_type.
6388 */
6196 ret = i2c_transfer(&dev->i2c_adap, msg, 2); 6389 ret = i2c_transfer(&dev->i2c_adap, msg, 2);
6197 if (ret != 2) { 6390 if (ret != 2) {
6198 printk(KERN_ERR "EEPROM read failure\n"); 6391 printk(KERN_ERR "EEPROM read failure\n");
@@ -6248,12 +6441,14 @@ int saa7134_board_init2(struct saa7134_dev *dev)
6248 dev->name, saa7134_boards[dev->board].name); 6441 dev->name, saa7134_boards[dev->board].name);
6249 break; 6442 break;
6250 } 6443 }
6444 /* break intentionally omitted */
6251 case SAA7134_BOARD_VIDEOMATE_DVBT_300: 6445 case SAA7134_BOARD_VIDEOMATE_DVBT_300:
6252 case SAA7134_BOARD_ASUS_EUROPA2_HYBRID: 6446 case SAA7134_BOARD_ASUS_EUROPA2_HYBRID:
6253 { 6447 {
6254 6448
6255 /* The Philips EUROPA based hybrid boards have the tuner connected through 6449 /* The Philips EUROPA based hybrid boards have the tuner
6256 * the channel decoder. We have to make it transparent to find it 6450 connected through the channel decoder. We have to make it
6451 transparent to find it
6257 */ 6452 */
6258 u8 data[] = { 0x07, 0x02}; 6453 u8 data[] = { 0x07, 0x02};
6259 struct i2c_msg msg = {.addr=0x08, .flags=0, .buf=data, .len = sizeof(data)}; 6454 struct i2c_msg msg = {.addr=0x08, .flags=0, .buf=data, .len = sizeof(data)};
@@ -6274,21 +6469,15 @@ int saa7134_board_init2(struct saa7134_dev *dev)
6274 if (dev->board == SAA7134_BOARD_PHILIPS_TIGER_S) { 6469 if (dev->board == SAA7134_BOARD_PHILIPS_TIGER_S) {
6275 dev->tuner_type = TUNER_PHILIPS_TDA8290; 6470 dev->tuner_type = TUNER_PHILIPS_TDA8290;
6276 6471
6277 saa7134_tuner_setup(dev);
6278
6279 data[2] = 0x68; 6472 data[2] = 0x68;
6280 i2c_transfer(&dev->i2c_adap, &msg, 1); 6473 i2c_transfer(&dev->i2c_adap, &msg, 1);
6281 6474 break;
6282 /* Tuner setup is handled before I2C transfer.
6283 Due to that, there's no need to do it later
6284 */
6285 return 0;
6286 } 6475 }
6287 i2c_transfer(&dev->i2c_adap, &msg, 1); 6476 i2c_transfer(&dev->i2c_adap, &msg, 1);
6288 break; 6477 break;
6289 } 6478 }
6290 case SAA7134_BOARD_ASUSTeK_TVFM7135: 6479 case SAA7134_BOARD_ASUSTeK_TVFM7135:
6291 /* The card below is detected as card=53, but is different */ 6480 /* The card below is detected as card=53, but is different */
6292 if (dev->autodetected && (dev->eedata[0x27] == 0x03)) { 6481 if (dev->autodetected && (dev->eedata[0x27] == 0x03)) {
6293 dev->board = SAA7134_BOARD_ASUSTeK_P7131_ANALOG; 6482 dev->board = SAA7134_BOARD_ASUSTeK_P7131_ANALOG;
6294 printk(KERN_INFO "%s: P7131 analog only, using " 6483 printk(KERN_INFO "%s: P7131 analog only, using "
@@ -6296,6 +6485,10 @@ int saa7134_board_init2(struct saa7134_dev *dev)
6296 dev->name, saa7134_boards[dev->board].name); 6485 dev->name, saa7134_boards[dev->board].name);
6297 } 6486 }
6298 break; 6487 break;
6488 case SAA7134_BOARD_HAUPPAUGE_HVR1120:
6489 case SAA7134_BOARD_HAUPPAUGE_HVR1110R3:
6490 hauppauge_eeprom(dev, dev->eedata+0x80);
6491 break;
6299 case SAA7134_BOARD_HAUPPAUGE_HVR1110: 6492 case SAA7134_BOARD_HAUPPAUGE_HVR1110:
6300 hauppauge_eeprom(dev, dev->eedata+0x80); 6493 hauppauge_eeprom(dev, dev->eedata+0x80);
6301 /* break intentionally omitted */ 6494 /* break intentionally omitted */
@@ -6351,22 +6544,6 @@ int saa7134_board_init2(struct saa7134_dev *dev)
6351 i2c_transfer(&dev->i2c_adap, &msg, 1); 6544 i2c_transfer(&dev->i2c_adap, &msg, 1);
6352 break; 6545 break;
6353 } 6546 }
6354 case SAA7134_BOARD_ADS_INSTANT_HDTV_PCI:
6355 case SAA7134_BOARD_KWORLD_ATSC110:
6356 {
6357 /* enable tuner */
6358 int i;
6359 static const u8 buffer [] = { 0x10, 0x12, 0x13, 0x04, 0x16,
6360 0x00, 0x14, 0x04, 0x17, 0x00 };
6361 dev->i2c_client.addr = 0x0a;
6362 for (i = 0; i < 5; i++)
6363 if (2 != i2c_master_send(&dev->i2c_client,
6364 &buffer[i*2], 2))
6365 printk(KERN_WARNING
6366 "%s: Unable to enable tuner(%i).\n",
6367 dev->name, i);
6368 break;
6369 }
6370 case SAA7134_BOARD_VIDEOMATE_DVBT_200: 6547 case SAA7134_BOARD_VIDEOMATE_DVBT_200:
6371 case SAA7134_BOARD_VIDEOMATE_DVBT_200A: 6548 case SAA7134_BOARD_VIDEOMATE_DVBT_200A:
6372 /* The T200 and the T200A share the same pci id. Consequently, 6549 /* The T200 and the T200A share the same pci id. Consequently,
@@ -6375,9 +6552,9 @@ int saa7134_board_init2(struct saa7134_dev *dev)
6375 6552
6376 /* Don't do this if the board was specifically selected with an 6553 /* Don't do this if the board was specifically selected with an
6377 * insmod option or if we have the default configuration T200*/ 6554 * insmod option or if we have the default configuration T200*/
6378 if(!dev->autodetected || (dev->eedata[0x41] == 0xd0)) 6555 if (!dev->autodetected || (dev->eedata[0x41] == 0xd0))
6379 break; 6556 break;
6380 if(dev->eedata[0x41] == 0x02) { 6557 if (dev->eedata[0x41] == 0x02) {
6381 /* Reconfigure board as T200A */ 6558 /* Reconfigure board as T200A */
6382 dev->board = SAA7134_BOARD_VIDEOMATE_DVBT_200A; 6559 dev->board = SAA7134_BOARD_VIDEOMATE_DVBT_200A;
6383 dev->tuner_type = saa7134_boards[dev->board].tuner_type; 6560 dev->tuner_type = saa7134_boards[dev->board].tuner_type;
@@ -6390,6 +6567,58 @@ int saa7134_board_init2(struct saa7134_dev *dev)
6390 break; 6567 break;
6391 } 6568 }
6392 break; 6569 break;
6570 case SAA7134_BOARD_ADS_INSTANT_HDTV_PCI:
6571 case SAA7134_BOARD_KWORLD_ATSC110:
6572 {
6573 struct i2c_msg msg = { .addr = 0x0a, .flags = 0 };
6574 int i;
6575 static u8 buffer[][2] = {
6576 { 0x10, 0x12 },
6577 { 0x13, 0x04 },
6578 { 0x16, 0x00 },
6579 { 0x14, 0x04 },
6580 { 0x17, 0x00 },
6581 };
6582
6583 for (i = 0; i < ARRAY_SIZE(buffer); i++) {
6584 msg.buf = &buffer[i][0];
6585 msg.len = ARRAY_SIZE(buffer[0]);
6586 if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1)
6587 printk(KERN_WARNING
6588 "%s: Unable to enable tuner(%i).\n",
6589 dev->name, i);
6590 }
6591 break;
6592 }
6593 } /* switch() */
6594
6595 /* initialize tuner */
6596 if (TUNER_ABSENT != dev->tuner_type) {
6597 int has_demod = (dev->tda9887_conf & TDA9887_PRESENT);
6598
6599 /* Note: radio tuner address is always filled in,
6600 so we do not need to probe for a radio tuner device. */
6601 if (dev->radio_type != UNSET)
6602 v4l2_i2c_new_subdev(&dev->i2c_adap,
6603 "tuner", "tuner", dev->radio_addr);
6604 if (has_demod)
6605 v4l2_i2c_new_probed_subdev(&dev->i2c_adap, "tuner",
6606 "tuner", v4l2_i2c_tuner_addrs(ADDRS_DEMOD));
6607 if (dev->tuner_addr == ADDR_UNSET) {
6608 enum v4l2_i2c_tuner_type type =
6609 has_demod ? ADDRS_TV_WITH_DEMOD : ADDRS_TV;
6610
6611 v4l2_i2c_new_probed_subdev(&dev->i2c_adap, "tuner",
6612 "tuner", v4l2_i2c_tuner_addrs(type));
6613 } else {
6614 v4l2_i2c_new_subdev(&dev->i2c_adap,
6615 "tuner", "tuner", dev->tuner_addr);
6616 }
6617 }
6618
6619 saa7134_tuner_setup(dev);
6620
6621 switch (dev->board) {
6393 case SAA7134_BOARD_BEHOLD_COLUMBUS_TVFM: 6622 case SAA7134_BOARD_BEHOLD_COLUMBUS_TVFM:
6394 { 6623 {
6395 struct v4l2_priv_tun_config tea5767_cfg; 6624 struct v4l2_priv_tun_config tea5767_cfg;
@@ -6401,12 +6630,10 @@ int saa7134_board_init2(struct saa7134_dev *dev)
6401 ctl.xtal_freq = TEA5767_HIGH_LO_13MHz; 6630 ctl.xtal_freq = TEA5767_HIGH_LO_13MHz;
6402 tea5767_cfg.tuner = TUNER_TEA5767; 6631 tea5767_cfg.tuner = TUNER_TEA5767;
6403 tea5767_cfg.priv = &ctl; 6632 tea5767_cfg.priv = &ctl;
6404 saa7134_i2c_call_clients(dev, TUNER_SET_CONFIG, &tea5767_cfg); 6633 saa_call_all(dev, tuner, s_config, &tea5767_cfg);
6405 break; 6634 break;
6406 } 6635 }
6407 } /* switch() */ 6636 } /* switch() */
6408 6637
6409 saa7134_tuner_setup(dev);
6410
6411 return 0; 6638 return 0;
6412} 6639}
diff --git a/drivers/media/video/saa7134/saa7134-core.c b/drivers/media/video/saa7134/saa7134-core.c
index 99221d726edb..dafa0d88bed0 100644
--- a/drivers/media/video/saa7134/saa7134-core.c
+++ b/drivers/media/video/saa7134/saa7134-core.c
@@ -54,13 +54,9 @@ static unsigned int gpio_tracking;
54module_param(gpio_tracking, int, 0644); 54module_param(gpio_tracking, int, 0644);
55MODULE_PARM_DESC(gpio_tracking,"enable debug messages [gpio]"); 55MODULE_PARM_DESC(gpio_tracking,"enable debug messages [gpio]");
56 56
57static unsigned int alsa; 57static unsigned int alsa = 1;
58module_param(alsa, int, 0644); 58module_param(alsa, int, 0644);
59MODULE_PARM_DESC(alsa,"enable ALSA DMA sound [dmasound]"); 59MODULE_PARM_DESC(alsa,"enable/disable ALSA DMA sound [dmasound]");
60
61static unsigned int oss;
62module_param(oss, int, 0644);
63MODULE_PARM_DESC(oss,"enable OSS DMA sound [dmasound]");
64 60
65static unsigned int latency = UNSET; 61static unsigned int latency = UNSET;
66module_param(latency, int, 0444); 62module_param(latency, int, 0444);
@@ -90,8 +86,10 @@ MODULE_PARM_DESC(radio_nr, "radio device number");
90MODULE_PARM_DESC(tuner, "tuner type"); 86MODULE_PARM_DESC(tuner, "tuner type");
91MODULE_PARM_DESC(card, "card type"); 87MODULE_PARM_DESC(card, "card type");
92 88
93static DEFINE_MUTEX(devlist_lock); 89DEFINE_MUTEX(saa7134_devlist_lock);
90EXPORT_SYMBOL(saa7134_devlist_lock);
94LIST_HEAD(saa7134_devlist); 91LIST_HEAD(saa7134_devlist);
92EXPORT_SYMBOL(saa7134_devlist);
95static LIST_HEAD(mops_list); 93static LIST_HEAD(mops_list);
96static unsigned int saa7134_devcount; 94static unsigned int saa7134_devcount;
97 95
@@ -156,10 +154,10 @@ static void request_module_async(struct work_struct *work){
156 request_module("saa7134-empress"); 154 request_module("saa7134-empress");
157 if (card_is_dvb(dev)) 155 if (card_is_dvb(dev))
158 request_module("saa7134-dvb"); 156 request_module("saa7134-dvb");
159 if (alsa) 157 if (alsa) {
160 request_module("saa7134-alsa"); 158 if (dev->pci->device != PCI_DEVICE_ID_PHILIPS_SAA7130)
161 if (oss) 159 request_module("saa7134-alsa");
162 request_module("saa7134-oss"); 160 }
163} 161}
164 162
165static void request_submodules(struct saa7134_dev *dev) 163static void request_submodules(struct saa7134_dev *dev)
@@ -778,7 +776,7 @@ static struct video_device *vdev_init(struct saa7134_dev *dev,
778 return NULL; 776 return NULL;
779 *vfd = *template; 777 *vfd = *template;
780 vfd->minor = -1; 778 vfd->minor = -1;
781 vfd->parent = &dev->pci->dev; 779 vfd->v4l2_dev = &dev->v4l2_dev;
782 vfd->release = video_device_release; 780 vfd->release = video_device_release;
783 vfd->debug = video_debug; 781 vfd->debug = video_debug;
784 snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)", 782 snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)",
@@ -851,6 +849,10 @@ static int __devinit saa7134_initdev(struct pci_dev *pci_dev,
851 if (NULL == dev) 849 if (NULL == dev)
852 return -ENOMEM; 850 return -ENOMEM;
853 851
852 err = v4l2_device_register(&pci_dev->dev, &dev->v4l2_dev);
853 if (err)
854 goto fail0;
855
854 /* pci init */ 856 /* pci init */
855 dev->pci = pci_dev; 857 dev->pci = pci_dev;
856 if (pci_enable_device(pci_dev)) { 858 if (pci_enable_device(pci_dev)) {
@@ -927,6 +929,8 @@ static int __devinit saa7134_initdev(struct pci_dev *pci_dev,
927 dev->autodetected = card[dev->nr] != dev->board; 929 dev->autodetected = card[dev->nr] != dev->board;
928 dev->tuner_type = saa7134_boards[dev->board].tuner_type; 930 dev->tuner_type = saa7134_boards[dev->board].tuner_type;
929 dev->tuner_addr = saa7134_boards[dev->board].tuner_addr; 931 dev->tuner_addr = saa7134_boards[dev->board].tuner_addr;
932 dev->radio_type = saa7134_boards[dev->board].radio_type;
933 dev->radio_addr = saa7134_boards[dev->board].radio_addr;
930 dev->tda9887_conf = saa7134_boards[dev->board].tda9887_conf; 934 dev->tda9887_conf = saa7134_boards[dev->board].tda9887_conf;
931 if (UNSET != tuner[dev->nr]) 935 if (UNSET != tuner[dev->nr])
932 dev->tuner_type = tuner[dev->nr]; 936 dev->tuner_type = tuner[dev->nr];
@@ -971,23 +975,48 @@ static int __devinit saa7134_initdev(struct pci_dev *pci_dev,
971 /* wait a bit, register i2c bus */ 975 /* wait a bit, register i2c bus */
972 msleep(100); 976 msleep(100);
973 saa7134_i2c_register(dev); 977 saa7134_i2c_register(dev);
974
975 /* initialize hardware #2 */
976 if (TUNER_ABSENT != dev->tuner_type)
977 request_module("tuner");
978 saa7134_board_init2(dev); 978 saa7134_board_init2(dev);
979 979
980 saa7134_hwinit2(dev); 980 saa7134_hwinit2(dev);
981 981
982 /* load i2c helpers */ 982 /* load i2c helpers */
983 if (card_is_empress(dev)) { 983 if (card_is_empress(dev)) {
984 request_module("saa6752hs"); 984 struct v4l2_subdev *sd =
985 v4l2_i2c_new_subdev(&dev->i2c_adap,
986 "saa6752hs", "saa6752hs",
987 saa7134_boards[dev->board].empress_addr);
988
989 if (sd)
990 sd->grp_id = GRP_EMPRESS;
991 }
992
993 if (saa7134_boards[dev->board].rds_addr) {
994 unsigned short addrs[2] = { 0, I2C_CLIENT_END };
995 struct v4l2_subdev *sd;
996
997 addrs[0] = saa7134_boards[dev->board].rds_addr;
998 sd = v4l2_i2c_new_probed_subdev(&dev->i2c_adap, "saa6588",
999 "saa6588", addrs);
1000 if (sd)
1001 printk(KERN_INFO "%s: found RDS decoder\n", dev->name);
985 } 1002 }
986 1003
987 request_submodules(dev); 1004 request_submodules(dev);
988 1005
989 v4l2_prio_init(&dev->prio); 1006 v4l2_prio_init(&dev->prio);
990 1007
1008 mutex_lock(&saa7134_devlist_lock);
1009 list_for_each_entry(mops, &mops_list, next)
1010 mpeg_ops_attach(mops, dev);
1011 list_add_tail(&dev->devlist, &saa7134_devlist);
1012 mutex_unlock(&saa7134_devlist_lock);
1013
1014 /* check for signal */
1015 saa7134_irq_video_signalchange(dev);
1016
1017 if (TUNER_ABSENT != dev->tuner_type)
1018 saa_call_all(dev, core, s_standby, 0);
1019
991 /* register v4l devices */ 1020 /* register v4l devices */
992 if (saa7134_no_overlay > 0) 1021 if (saa7134_no_overlay > 0)
993 printk(KERN_INFO "%s: Overlay support disabled.\n", dev->name); 1022 printk(KERN_INFO "%s: Overlay support disabled.\n", dev->name);
@@ -1023,24 +1052,10 @@ static int __devinit saa7134_initdev(struct pci_dev *pci_dev,
1023 } 1052 }
1024 1053
1025 /* everything worked */ 1054 /* everything worked */
1026 pci_set_drvdata(pci_dev,dev);
1027 saa7134_devcount++; 1055 saa7134_devcount++;
1028 1056
1029 mutex_lock(&devlist_lock); 1057 if (saa7134_dmasound_init && !dev->dmasound.priv_data)
1030 list_for_each_entry(mops, &mops_list, next)
1031 mpeg_ops_attach(mops, dev);
1032 list_add_tail(&dev->devlist,&saa7134_devlist);
1033 mutex_unlock(&devlist_lock);
1034
1035 /* check for signal */
1036 saa7134_irq_video_signalchange(dev);
1037
1038 if (saa7134_dmasound_init && !dev->dmasound.priv_data) {
1039 saa7134_dmasound_init(dev); 1058 saa7134_dmasound_init(dev);
1040 }
1041
1042 if (TUNER_ABSENT != dev->tuner_type)
1043 saa7134_i2c_call_clients(dev, TUNER_SET_STANDBY, NULL);
1044 1059
1045 return 0; 1060 return 0;
1046 1061
@@ -1055,13 +1070,16 @@ static int __devinit saa7134_initdev(struct pci_dev *pci_dev,
1055 release_mem_region(pci_resource_start(pci_dev,0), 1070 release_mem_region(pci_resource_start(pci_dev,0),
1056 pci_resource_len(pci_dev,0)); 1071 pci_resource_len(pci_dev,0));
1057 fail1: 1072 fail1:
1073 v4l2_device_unregister(&dev->v4l2_dev);
1074 fail0:
1058 kfree(dev); 1075 kfree(dev);
1059 return err; 1076 return err;
1060} 1077}
1061 1078
1062static void __devexit saa7134_finidev(struct pci_dev *pci_dev) 1079static void __devexit saa7134_finidev(struct pci_dev *pci_dev)
1063{ 1080{
1064 struct saa7134_dev *dev = pci_get_drvdata(pci_dev); 1081 struct v4l2_device *v4l2_dev = pci_get_drvdata(pci_dev);
1082 struct saa7134_dev *dev = container_of(v4l2_dev, struct saa7134_dev, v4l2_dev);
1065 struct saa7134_mpeg_ops *mops; 1083 struct saa7134_mpeg_ops *mops;
1066 1084
1067 /* Release DMA sound modules if present */ 1085 /* Release DMA sound modules if present */
@@ -1088,11 +1106,11 @@ static void __devexit saa7134_finidev(struct pci_dev *pci_dev)
1088 saa7134_hwfini(dev); 1106 saa7134_hwfini(dev);
1089 1107
1090 /* unregister */ 1108 /* unregister */
1091 mutex_lock(&devlist_lock); 1109 mutex_lock(&saa7134_devlist_lock);
1092 list_del(&dev->devlist); 1110 list_del(&dev->devlist);
1093 list_for_each_entry(mops, &mops_list, next) 1111 list_for_each_entry(mops, &mops_list, next)
1094 mpeg_ops_detach(mops, dev); 1112 mpeg_ops_detach(mops, dev);
1095 mutex_unlock(&devlist_lock); 1113 mutex_unlock(&saa7134_devlist_lock);
1096 saa7134_devcount--; 1114 saa7134_devcount--;
1097 1115
1098 saa7134_i2c_unregister(dev); 1116 saa7134_i2c_unregister(dev);
@@ -1113,7 +1131,8 @@ static void __devexit saa7134_finidev(struct pci_dev *pci_dev)
1113 release_mem_region(pci_resource_start(pci_dev,0), 1131 release_mem_region(pci_resource_start(pci_dev,0),
1114 pci_resource_len(pci_dev,0)); 1132 pci_resource_len(pci_dev,0));
1115 1133
1116 pci_set_drvdata(pci_dev, NULL); 1134
1135 v4l2_device_unregister(&dev->v4l2_dev);
1117 1136
1118 /* free memory */ 1137 /* free memory */
1119 kfree(dev); 1138 kfree(dev);
@@ -1148,8 +1167,8 @@ static int saa7134_buffer_requeue(struct saa7134_dev *dev,
1148 1167
1149static int saa7134_suspend(struct pci_dev *pci_dev , pm_message_t state) 1168static int saa7134_suspend(struct pci_dev *pci_dev , pm_message_t state)
1150{ 1169{
1151 1170 struct v4l2_device *v4l2_dev = pci_get_drvdata(pci_dev);
1152 struct saa7134_dev *dev = pci_get_drvdata(pci_dev); 1171 struct saa7134_dev *dev = container_of(v4l2_dev, struct saa7134_dev, v4l2_dev);
1153 1172
1154 /* disable overlay - apps should enable it explicitly on resume*/ 1173 /* disable overlay - apps should enable it explicitly on resume*/
1155 dev->ovenable = 0; 1174 dev->ovenable = 0;
@@ -1185,7 +1204,8 @@ static int saa7134_suspend(struct pci_dev *pci_dev , pm_message_t state)
1185 1204
1186static int saa7134_resume(struct pci_dev *pci_dev) 1205static int saa7134_resume(struct pci_dev *pci_dev)
1187{ 1206{
1188 struct saa7134_dev *dev = pci_get_drvdata(pci_dev); 1207 struct v4l2_device *v4l2_dev = pci_get_drvdata(pci_dev);
1208 struct saa7134_dev *dev = container_of(v4l2_dev, struct saa7134_dev, v4l2_dev);
1189 unsigned long flags; 1209 unsigned long flags;
1190 1210
1191 pci_set_power_state(pci_dev, PCI_D0); 1211 pci_set_power_state(pci_dev, PCI_D0);
@@ -1247,11 +1267,11 @@ int saa7134_ts_register(struct saa7134_mpeg_ops *ops)
1247{ 1267{
1248 struct saa7134_dev *dev; 1268 struct saa7134_dev *dev;
1249 1269
1250 mutex_lock(&devlist_lock); 1270 mutex_lock(&saa7134_devlist_lock);
1251 list_for_each_entry(dev, &saa7134_devlist, devlist) 1271 list_for_each_entry(dev, &saa7134_devlist, devlist)
1252 mpeg_ops_attach(ops, dev); 1272 mpeg_ops_attach(ops, dev);
1253 list_add_tail(&ops->next,&mops_list); 1273 list_add_tail(&ops->next,&mops_list);
1254 mutex_unlock(&devlist_lock); 1274 mutex_unlock(&saa7134_devlist_lock);
1255 return 0; 1275 return 0;
1256} 1276}
1257 1277
@@ -1259,11 +1279,11 @@ void saa7134_ts_unregister(struct saa7134_mpeg_ops *ops)
1259{ 1279{
1260 struct saa7134_dev *dev; 1280 struct saa7134_dev *dev;
1261 1281
1262 mutex_lock(&devlist_lock); 1282 mutex_lock(&saa7134_devlist_lock);
1263 list_del(&ops->next); 1283 list_del(&ops->next);
1264 list_for_each_entry(dev, &saa7134_devlist, devlist) 1284 list_for_each_entry(dev, &saa7134_devlist, devlist)
1265 mpeg_ops_detach(ops, dev); 1285 mpeg_ops_detach(ops, dev);
1266 mutex_unlock(&devlist_lock); 1286 mutex_unlock(&saa7134_devlist_lock);
1267} 1287}
1268 1288
1269EXPORT_SYMBOL(saa7134_ts_register); 1289EXPORT_SYMBOL(saa7134_ts_register);
@@ -1307,8 +1327,6 @@ module_exit(saa7134_fini);
1307/* ----------------------------------------------------------- */ 1327/* ----------------------------------------------------------- */
1308 1328
1309EXPORT_SYMBOL(saa7134_set_gpio); 1329EXPORT_SYMBOL(saa7134_set_gpio);
1310EXPORT_SYMBOL(saa7134_i2c_call_clients);
1311EXPORT_SYMBOL(saa7134_devlist);
1312EXPORT_SYMBOL(saa7134_boards); 1330EXPORT_SYMBOL(saa7134_boards);
1313 1331
1314/* ----------------- for the DMA sound modules --------------- */ 1332/* ----------------- for the DMA sound modules --------------- */
diff --git a/drivers/media/video/saa7134/saa7134-dvb.c b/drivers/media/video/saa7134/saa7134-dvb.c
index b5370b3e1a3d..4eff1ca8593c 100644
--- a/drivers/media/video/saa7134/saa7134-dvb.c
+++ b/drivers/media/video/saa7134/saa7134-dvb.c
@@ -48,9 +48,15 @@
48#include "isl6405.h" 48#include "isl6405.h"
49#include "lnbp21.h" 49#include "lnbp21.h"
50#include "tuner-simple.h" 50#include "tuner-simple.h"
51#include "tda18271.h"
52#include "lgdt3305.h"
53#include "tda8290.h"
51 54
52#include "zl10353.h" 55#include "zl10353.h"
53 56
57#include "zl10036.h"
58#include "mt312.h"
59
54MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]"); 60MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
55MODULE_LICENSE("GPL"); 61MODULE_LICENSE("GPL");
56 62
@@ -189,7 +195,7 @@ static int mt352_pinnacle_tuner_set_params(struct dvb_frontend* fe,
189 if (fe->ops.i2c_gate_ctrl) 195 if (fe->ops.i2c_gate_ctrl)
190 fe->ops.i2c_gate_ctrl(fe, 1); 196 fe->ops.i2c_gate_ctrl(fe, 1);
191 i2c_transfer(&dev->i2c_adap, &msg, 1); 197 i2c_transfer(&dev->i2c_adap, &msg, 1);
192 saa7134_i2c_call_clients(dev,VIDIOC_S_FREQUENCY,&f); 198 saa_call_all(dev, tuner, s_frequency, &f);
193 msg.buf = on; 199 msg.buf = on;
194 if (fe->ops.i2c_gate_ctrl) 200 if (fe->ops.i2c_gate_ctrl)
195 fe->ops.i2c_gate_ctrl(fe, 1); 201 fe->ops.i2c_gate_ctrl(fe, 1);
@@ -950,6 +956,45 @@ static struct nxt200x_config kworldatsc110 = {
950 .demod_address = 0x0a, 956 .demod_address = 0x0a,
951}; 957};
952 958
959/* ------------------------------------------------------------------ */
960
961static struct mt312_config avertv_a700_mt312 = {
962 .demod_address = 0x0e,
963 .voltage_inverted = 1,
964};
965
966static struct zl10036_config avertv_a700_tuner = {
967 .tuner_address = 0x60,
968};
969
970static struct lgdt3305_config hcw_lgdt3305_config = {
971 .i2c_addr = 0x0e,
972 .mpeg_mode = LGDT3305_MPEG_SERIAL,
973 .tpclk_edge = LGDT3305_TPCLK_RISING_EDGE,
974 .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
975 .deny_i2c_rptr = 1,
976 .spectral_inversion = 1,
977 .qam_if_khz = 4000,
978 .vsb_if_khz = 3250,
979};
980
981static struct tda18271_std_map hauppauge_tda18271_std_map = {
982 .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 4,
983 .if_lvl = 1, .rfagc_top = 0x58, },
984 .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 5,
985 .if_lvl = 1, .rfagc_top = 0x58, },
986};
987
988static struct tda18271_config hcw_tda18271_config = {
989 .std_map = &hauppauge_tda18271_std_map,
990 .gate = TDA18271_GATE_ANALOG,
991 .config = 3,
992};
993
994static struct tda829x_config tda829x_no_probe = {
995 .probe_tuner = TDA829X_DONT_PROBE,
996};
997
953/* ================================================================== 998/* ==================================================================
954 * Core code 999 * Core code
955 */ 1000 */
@@ -1076,6 +1121,19 @@ static int dvb_init(struct saa7134_dev *dev)
1076 &tda827x_cfg_1) < 0) 1121 &tda827x_cfg_1) < 0)
1077 goto dettach_frontend; 1122 goto dettach_frontend;
1078 break; 1123 break;
1124 case SAA7134_BOARD_HAUPPAUGE_HVR1120:
1125 fe0->dvb.frontend = dvb_attach(lgdt3305_attach,
1126 &hcw_lgdt3305_config,
1127 &dev->i2c_adap);
1128 if (fe0->dvb.frontend) {
1129 dvb_attach(tda829x_attach, fe0->dvb.frontend,
1130 &dev->i2c_adap, 0x4b,
1131 &tda829x_no_probe);
1132 dvb_attach(tda18271_attach, fe0->dvb.frontend,
1133 0x60, &dev->i2c_adap,
1134 &hcw_tda18271_config);
1135 }
1136 break;
1079 case SAA7134_BOARD_ASUSTeK_P7131_DUAL: 1137 case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
1080 if (configure_tda827x_fe(dev, &asus_p7131_dual_config, 1138 if (configure_tda827x_fe(dev, &asus_p7131_dual_config,
1081 &tda827x_cfg_0) < 0) 1139 &tda827x_cfg_0) < 0)
@@ -1376,6 +1434,19 @@ static int dvb_init(struct saa7134_dev *dev)
1376 TUNER_PHILIPS_FMD1216ME_MK3); 1434 TUNER_PHILIPS_FMD1216ME_MK3);
1377 } 1435 }
1378 break; 1436 break;
1437 case SAA7134_BOARD_AVERMEDIA_A700_PRO:
1438 case SAA7134_BOARD_AVERMEDIA_A700_HYBRID:
1439 /* Zarlink ZL10313 */
1440 fe0->dvb.frontend = dvb_attach(mt312_attach,
1441 &avertv_a700_mt312, &dev->i2c_adap);
1442 if (fe0->dvb.frontend) {
1443 if (dvb_attach(zl10036_attach, fe0->dvb.frontend,
1444 &avertv_a700_tuner, &dev->i2c_adap) == NULL) {
1445 wprintk("%s: No zl10036 found!\n",
1446 __func__);
1447 }
1448 }
1449 break;
1379 default: 1450 default:
1380 wprintk("Huh? unknown DVB card?\n"); 1451 wprintk("Huh? unknown DVB card?\n");
1381 break; 1452 break;
@@ -1449,7 +1520,7 @@ static int dvb_fini(struct saa7134_dev *dev)
1449 tda9887_cfg.priv = &on; 1520 tda9887_cfg.priv = &on;
1450 1521
1451 /* otherwise we don't detect the tuner on next insmod */ 1522 /* otherwise we don't detect the tuner on next insmod */
1452 saa7134_i2c_call_clients(dev, TUNER_SET_CONFIG, &tda9887_cfg); 1523 saa_call_all(dev, tuner, s_config, &tda9887_cfg);
1453 } else if (dev->board == SAA7134_BOARD_MEDION_MD8800_QUADRO) { 1524 } else if (dev->board == SAA7134_BOARD_MEDION_MD8800_QUADRO) {
1454 if ((dev->eedata[2] == 0x07) && use_frontend) { 1525 if ((dev->eedata[2] == 0x07) && use_frontend) {
1455 /* turn off the 2nd lnb supply */ 1526 /* turn off the 2nd lnb supply */
diff --git a/drivers/media/video/saa7134/saa7134-empress.c b/drivers/media/video/saa7134/saa7134-empress.c
index c9d8beb87a60..9db3472667e5 100644
--- a/drivers/media/video/saa7134/saa7134-empress.c
+++ b/drivers/media/video/saa7134/saa7134-empress.c
@@ -76,7 +76,7 @@ static int ts_init_encoder(struct saa7134_dev* dev)
76 break; 76 break;
77 } 77 }
78 ts_reset_encoder(dev); 78 ts_reset_encoder(dev);
79 saa7134_i2c_call_clients(dev, VIDIOC_INT_INIT, &leading_null_bytes); 79 saa_call_all(dev, core, init, leading_null_bytes);
80 dev->empress_started = 1; 80 dev->empress_started = 1;
81 return 0; 81 return 0;
82} 82}
@@ -234,7 +234,7 @@ static int empress_g_fmt_vid_cap(struct file *file, void *priv,
234{ 234{
235 struct saa7134_dev *dev = file->private_data; 235 struct saa7134_dev *dev = file->private_data;
236 236
237 saa7134_i2c_call_clients(dev, VIDIOC_G_FMT, f); 237 saa_call_all(dev, video, g_fmt, f);
238 238
239 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG; 239 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
240 f->fmt.pix.sizeimage = TS_PACKET_SIZE * dev->ts.nr_packets; 240 f->fmt.pix.sizeimage = TS_PACKET_SIZE * dev->ts.nr_packets;
@@ -247,7 +247,7 @@ static int empress_s_fmt_vid_cap(struct file *file, void *priv,
247{ 247{
248 struct saa7134_dev *dev = file->private_data; 248 struct saa7134_dev *dev = file->private_data;
249 249
250 saa7134_i2c_call_clients(dev, VIDIOC_S_FMT, f); 250 saa_call_all(dev, video, s_fmt, f);
251 251
252 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG; 252 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
253 f->fmt.pix.sizeimage = TS_PACKET_SIZE * dev->ts.nr_packets; 253 f->fmt.pix.sizeimage = TS_PACKET_SIZE * dev->ts.nr_packets;
@@ -317,7 +317,7 @@ static int empress_s_ext_ctrls(struct file *file, void *priv,
317 if (ctrls->ctrl_class != V4L2_CTRL_CLASS_MPEG) 317 if (ctrls->ctrl_class != V4L2_CTRL_CLASS_MPEG)
318 return -EINVAL; 318 return -EINVAL;
319 319
320 err = saa7134_i2c_call_saa6752(dev, VIDIOC_S_EXT_CTRLS, ctrls); 320 err = saa_call_empress(dev, core, s_ext_ctrls, ctrls);
321 ts_init_encoder(dev); 321 ts_init_encoder(dev);
322 322
323 return err; 323 return err;
@@ -330,7 +330,7 @@ static int empress_g_ext_ctrls(struct file *file, void *priv,
330 330
331 if (ctrls->ctrl_class != V4L2_CTRL_CLASS_MPEG) 331 if (ctrls->ctrl_class != V4L2_CTRL_CLASS_MPEG)
332 return -EINVAL; 332 return -EINVAL;
333 return saa7134_i2c_call_saa6752(dev, VIDIOC_G_EXT_CTRLS, ctrls); 333 return saa_call_empress(dev, core, g_ext_ctrls, ctrls);
334} 334}
335 335
336static int empress_g_ctrl(struct file *file, void *priv, 336static int empress_g_ctrl(struct file *file, void *priv,
@@ -352,6 +352,7 @@ static int empress_s_ctrl(struct file *file, void *priv,
352static int empress_queryctrl(struct file *file, void *priv, 352static int empress_queryctrl(struct file *file, void *priv,
353 struct v4l2_queryctrl *c) 353 struct v4l2_queryctrl *c)
354{ 354{
355 /* Must be sorted from low to high control ID! */
355 static const u32 user_ctrls[] = { 356 static const u32 user_ctrls[] = {
356 V4L2_CID_USER_CLASS, 357 V4L2_CID_USER_CLASS,
357 V4L2_CID_BRIGHTNESS, 358 V4L2_CID_BRIGHTNESS,
@@ -364,6 +365,7 @@ static int empress_queryctrl(struct file *file, void *priv,
364 0 365 0
365 }; 366 };
366 367
368 /* Must be sorted from low to high control ID! */
367 static const u32 mpeg_ctrls[] = { 369 static const u32 mpeg_ctrls[] = {
368 V4L2_CID_MPEG_CLASS, 370 V4L2_CID_MPEG_CLASS,
369 V4L2_CID_MPEG_STREAM_TYPE, 371 V4L2_CID_MPEG_STREAM_TYPE,
@@ -388,10 +390,10 @@ static int empress_queryctrl(struct file *file, void *priv,
388 if (c->id == 0) 390 if (c->id == 0)
389 return -EINVAL; 391 return -EINVAL;
390 if (c->id == V4L2_CID_USER_CLASS || c->id == V4L2_CID_MPEG_CLASS) 392 if (c->id == V4L2_CID_USER_CLASS || c->id == V4L2_CID_MPEG_CLASS)
391 return v4l2_ctrl_query_fill_std(c); 393 return v4l2_ctrl_query_fill(c, 0, 0, 0, 0);
392 if (V4L2_CTRL_ID2CLASS(c->id) != V4L2_CTRL_CLASS_MPEG) 394 if (V4L2_CTRL_ID2CLASS(c->id) != V4L2_CTRL_CLASS_MPEG)
393 return saa7134_queryctrl(file, priv, c); 395 return saa7134_queryctrl(file, priv, c);
394 return saa7134_i2c_call_saa6752(dev, VIDIOC_QUERYCTRL, c); 396 return saa_call_empress(dev, core, queryctrl, c);
395} 397}
396 398
397static int empress_querymenu(struct file *file, void *priv, 399static int empress_querymenu(struct file *file, void *priv,
@@ -401,7 +403,7 @@ static int empress_querymenu(struct file *file, void *priv,
401 403
402 if (V4L2_CTRL_ID2CLASS(c->id) != V4L2_CTRL_CLASS_MPEG) 404 if (V4L2_CTRL_ID2CLASS(c->id) != V4L2_CTRL_CLASS_MPEG)
403 return -EINVAL; 405 return -EINVAL;
404 return saa7134_i2c_call_saa6752(dev, VIDIOC_QUERYMENU, c); 406 return saa_call_empress(dev, core, querymenu, c);
405} 407}
406 408
407static int empress_g_chip_ident(struct file *file, void *fh, 409static int empress_g_chip_ident(struct file *file, void *fh,
@@ -411,14 +413,11 @@ static int empress_g_chip_ident(struct file *file, void *fh,
411 413
412 chip->ident = V4L2_IDENT_NONE; 414 chip->ident = V4L2_IDENT_NONE;
413 chip->revision = 0; 415 chip->revision = 0;
414 if (dev->mpeg_i2c_client == NULL)
415 return -EINVAL;
416 if (chip->match.type == V4L2_CHIP_MATCH_I2C_DRIVER && 416 if (chip->match.type == V4L2_CHIP_MATCH_I2C_DRIVER &&
417 !strcmp(chip->match.name, "saa6752hs")) 417 !strcmp(chip->match.name, "saa6752hs"))
418 return saa7134_i2c_call_saa6752(dev, VIDIOC_DBG_G_CHIP_IDENT, chip); 418 return saa_call_empress(dev, core, g_chip_ident, chip);
419 if (chip->match.type == V4L2_CHIP_MATCH_I2C_ADDR && 419 if (chip->match.type == V4L2_CHIP_MATCH_I2C_ADDR)
420 chip->match.addr == dev->mpeg_i2c_client->addr) 420 return saa_call_empress(dev, core, g_chip_ident, chip);
421 return saa7134_i2c_call_saa6752(dev, VIDIOC_DBG_G_CHIP_IDENT, chip);
422 return -EINVAL; 421 return -EINVAL;
423} 422}
424 423
diff --git a/drivers/media/video/saa7134/saa7134-i2c.c b/drivers/media/video/saa7134/saa7134-i2c.c
index 20c1b33caf7b..f3e285aa2fb4 100644
--- a/drivers/media/video/saa7134/saa7134-i2c.c
+++ b/drivers/media/video/saa7134/saa7134-i2c.c
@@ -255,7 +255,7 @@ static int saa7134_i2c_xfer(struct i2c_adapter *i2c_adap,
255 addr = msgs[i].addr << 1; 255 addr = msgs[i].addr << 1;
256 if (msgs[i].flags & I2C_M_RD) 256 if (msgs[i].flags & I2C_M_RD)
257 addr |= 1; 257 addr |= 1;
258 if (i > 0 && msgs[i].flags & I2C_M_RD) { 258 if (i > 0 && msgs[i].flags & I2C_M_RD && msgs[i].addr != 0x40) {
259 /* workaround for a saa7134 i2c bug 259 /* workaround for a saa7134 i2c bug
260 * needed to talk to the mt352 demux 260 * needed to talk to the mt352 demux
261 * thanks to pinnacle for the hint */ 261 * thanks to pinnacle for the hint */
@@ -327,8 +327,6 @@ static int attach_inform(struct i2c_client *client)
327 327
328 d1printk( "%s i2c attach [addr=0x%x,client=%s]\n", 328 d1printk( "%s i2c attach [addr=0x%x,client=%s]\n",
329 client->driver->driver.name, client->addr, client->name); 329 client->driver->driver.name, client->addr, client->name);
330 if (client->addr == 0x20 && client->driver && client->driver->command)
331 dev->mpeg_i2c_client = client;
332 330
333 /* Am I an i2c remote control? */ 331 /* Am I an i2c remote control? */
334 332
@@ -357,7 +355,6 @@ static struct i2c_algorithm saa7134_algo = {
357 355
358static struct i2c_adapter saa7134_adap_template = { 356static struct i2c_adapter saa7134_adap_template = {
359 .owner = THIS_MODULE, 357 .owner = THIS_MODULE,
360 .class = I2C_CLASS_TV_ANALOG,
361 .name = "saa7134", 358 .name = "saa7134",
362 .id = I2C_HW_SAA7134, 359 .id = I2C_HW_SAA7134,
363 .algo = &saa7134_algo, 360 .algo = &saa7134_algo,
@@ -421,29 +418,13 @@ static void do_i2c_scan(char *name, struct i2c_client *c)
421 } 418 }
422} 419}
423 420
424void saa7134_i2c_call_clients(struct saa7134_dev *dev,
425 unsigned int cmd, void *arg)
426{
427 BUG_ON(NULL == dev->i2c_adap.algo_data);
428 i2c_clients_command(&dev->i2c_adap, cmd, arg);
429}
430
431int saa7134_i2c_call_saa6752(struct saa7134_dev *dev,
432 unsigned int cmd, void *arg)
433{
434 if (dev->mpeg_i2c_client == NULL)
435 return -EINVAL;
436 return dev->mpeg_i2c_client->driver->command(dev->mpeg_i2c_client,
437 cmd, arg);
438}
439EXPORT_SYMBOL_GPL(saa7134_i2c_call_saa6752);
440
441int saa7134_i2c_register(struct saa7134_dev *dev) 421int saa7134_i2c_register(struct saa7134_dev *dev)
442{ 422{
443 dev->i2c_adap = saa7134_adap_template; 423 dev->i2c_adap = saa7134_adap_template;
444 dev->i2c_adap.dev.parent = &dev->pci->dev; 424 dev->i2c_adap.dev.parent = &dev->pci->dev;
445 strcpy(dev->i2c_adap.name,dev->name); 425 strcpy(dev->i2c_adap.name,dev->name);
446 dev->i2c_adap.algo_data = dev; 426 dev->i2c_adap.algo_data = dev;
427 i2c_set_adapdata(&dev->i2c_adap, &dev->v4l2_dev);
447 i2c_add_adapter(&dev->i2c_adap); 428 i2c_add_adapter(&dev->i2c_adap);
448 429
449 dev->i2c_client = saa7134_client_template; 430 dev->i2c_client = saa7134_client_template;
diff --git a/drivers/media/video/saa7134/saa7134-ts.c b/drivers/media/video/saa7134/saa7134-ts.c
index ef55a59f0cda..cc8b923afbc0 100644
--- a/drivers/media/video/saa7134/saa7134-ts.c
+++ b/drivers/media/video/saa7134/saa7134-ts.c
@@ -79,8 +79,19 @@ static int buffer_activate(struct saa7134_dev *dev,
79 saa_writeb(SAA7134_TS_SERIAL1, 0x00); 79 saa_writeb(SAA7134_TS_SERIAL1, 0x00);
80 80
81 /* Start TS stream */ 81 /* Start TS stream */
82 saa_writeb(SAA7134_TS_SERIAL0, 0x40); 82 switch (saa7134_boards[dev->board].ts_type) {
83 saa_writeb(SAA7134_TS_PARALLEL, 0xEC); 83 case SAA7134_MPEG_TS_PARALLEL:
84 saa_writeb(SAA7134_TS_SERIAL0, 0x40);
85 saa_writeb(SAA7134_TS_PARALLEL, 0xec);
86 break;
87 case SAA7134_MPEG_TS_SERIAL:
88 saa_writeb(SAA7134_TS_SERIAL0, 0xd8);
89 saa_writeb(SAA7134_TS_PARALLEL, 0x6c);
90 saa_writeb(SAA7134_TS_PARALLEL_SERIAL, 0xbc);
91 saa_writeb(SAA7134_TS_SERIAL1, 0x02);
92 break;
93 }
94
84 dev->ts_state = SAA7134_TS_STARTED; 95 dev->ts_state = SAA7134_TS_STARTED;
85 } 96 }
86 97
diff --git a/drivers/media/video/saa7134/saa7134-video.c b/drivers/media/video/saa7134/saa7134-video.c
index a1f7e351f572..404f70eeb355 100644
--- a/drivers/media/video/saa7134/saa7134-video.c
+++ b/drivers/media/video/saa7134/saa7134-video.c
@@ -30,11 +30,7 @@
30#include "saa7134-reg.h" 30#include "saa7134-reg.h"
31#include "saa7134.h" 31#include "saa7134.h"
32#include <media/v4l2-common.h> 32#include <media/v4l2-common.h>
33 33#include <media/rds.h>
34#ifdef CONFIG_VIDEO_V4L1_COMPAT
35/* Include V4L1 specific functions. Should be removed soon */
36#include <linux/videodev.h>
37#endif
38 34
39/* ------------------------------------------------------------------ */ 35/* ------------------------------------------------------------------ */
40 36
@@ -452,6 +448,7 @@ static const struct v4l2_queryctrl video_ctrls[] = {
452 .name = "y offset odd field", 448 .name = "y offset odd field",
453 .minimum = 0, 449 .minimum = 0,
454 .maximum = 128, 450 .maximum = 128,
451 .step = 1,
455 .default_value = 0, 452 .default_value = 0,
456 .type = V4L2_CTRL_TYPE_INTEGER, 453 .type = V4L2_CTRL_TYPE_INTEGER,
457 },{ 454 },{
@@ -459,6 +456,7 @@ static const struct v4l2_queryctrl video_ctrls[] = {
459 .name = "y offset even field", 456 .name = "y offset even field",
460 .minimum = 0, 457 .minimum = 0,
461 .maximum = 128, 458 .maximum = 128,
459 .step = 1,
462 .default_value = 0, 460 .default_value = 0,
463 .type = V4L2_CTRL_TYPE_INTEGER, 461 .type = V4L2_CTRL_TYPE_INTEGER,
464 },{ 462 },{
@@ -627,10 +625,10 @@ void saa7134_set_tvnorm_hw(struct saa7134_dev *dev)
627 saa7134_set_decoder(dev); 625 saa7134_set_decoder(dev);
628 626
629 if (card_in(dev, dev->ctl_input).tv) 627 if (card_in(dev, dev->ctl_input).tv)
630 saa7134_i2c_call_clients(dev, VIDIOC_S_STD, &dev->tvnorm->id); 628 saa_call_all(dev, tuner, s_std, dev->tvnorm->id);
631 /* Set the correct norm for the saa6752hs. This function 629 /* Set the correct norm for the saa6752hs. This function
632 does nothing if there is no saa6752hs. */ 630 does nothing if there is no saa6752hs. */
633 saa7134_i2c_call_saa6752(dev, VIDIOC_S_STD, &dev->tvnorm->id); 631 saa_call_empress(dev, tuner, s_std, dev->tvnorm->id);
634} 632}
635 633
636static void set_h_prescale(struct saa7134_dev *dev, int task, int prescale) 634static void set_h_prescale(struct saa7134_dev *dev, int task, int prescale)
@@ -1266,8 +1264,7 @@ int saa7134_s_ctrl_internal(struct saa7134_dev *dev, struct saa7134_fh *fh, str
1266 else 1264 else
1267 dev->tda9887_conf &= ~TDA9887_AUTOMUTE; 1265 dev->tda9887_conf &= ~TDA9887_AUTOMUTE;
1268 1266
1269 saa7134_i2c_call_clients(dev, TUNER_SET_CONFIG, 1267 saa_call_all(dev, tuner, s_config, &tda9887_cfg);
1270 &tda9887_cfg);
1271 } 1268 }
1272 break; 1269 break;
1273 } 1270 }
@@ -1334,7 +1331,7 @@ static int video_open(struct file *file)
1334 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 1331 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1335 int radio = 0; 1332 int radio = 0;
1336 1333
1337 lock_kernel(); 1334 mutex_lock(&saa7134_devlist_lock);
1338 list_for_each_entry(dev, &saa7134_devlist, devlist) { 1335 list_for_each_entry(dev, &saa7134_devlist, devlist) {
1339 if (dev->video_dev && (dev->video_dev->minor == minor)) 1336 if (dev->video_dev && (dev->video_dev->minor == minor))
1340 goto found; 1337 goto found;
@@ -1347,19 +1344,20 @@ static int video_open(struct file *file)
1347 goto found; 1344 goto found;
1348 } 1345 }
1349 } 1346 }
1350 unlock_kernel(); 1347 mutex_unlock(&saa7134_devlist_lock);
1351 return -ENODEV; 1348 return -ENODEV;
1352 found: 1349
1350found:
1351 mutex_unlock(&saa7134_devlist_lock);
1353 1352
1354 dprintk("open minor=%d radio=%d type=%s\n",minor,radio, 1353 dprintk("open minor=%d radio=%d type=%s\n",minor,radio,
1355 v4l2_type_names[type]); 1354 v4l2_type_names[type]);
1356 1355
1357 /* allocate + initialize per filehandle data */ 1356 /* allocate + initialize per filehandle data */
1358 fh = kzalloc(sizeof(*fh),GFP_KERNEL); 1357 fh = kzalloc(sizeof(*fh),GFP_KERNEL);
1359 if (NULL == fh) { 1358 if (NULL == fh)
1360 unlock_kernel();
1361 return -ENOMEM; 1359 return -ENOMEM;
1362 } 1360
1363 file->private_data = fh; 1361 file->private_data = fh;
1364 fh->dev = dev; 1362 fh->dev = dev;
1365 fh->radio = radio; 1363 fh->radio = radio;
@@ -1387,12 +1385,11 @@ static int video_open(struct file *file)
1387 if (fh->radio) { 1385 if (fh->radio) {
1388 /* switch to radio mode */ 1386 /* switch to radio mode */
1389 saa7134_tvaudio_setinput(dev,&card(dev).radio); 1387 saa7134_tvaudio_setinput(dev,&card(dev).radio);
1390 saa7134_i2c_call_clients(dev,AUDC_SET_RADIO, NULL); 1388 saa_call_all(dev, tuner, s_radio);
1391 } else { 1389 } else {
1392 /* switch to video/vbi mode */ 1390 /* switch to video/vbi mode */
1393 video_mux(dev,dev->ctl_input); 1391 video_mux(dev,dev->ctl_input);
1394 } 1392 }
1395 unlock_kernel();
1396 return 0; 1393 return 0;
1397} 1394}
1398 1395
@@ -1466,6 +1463,7 @@ static int video_release(struct file *file)
1466{ 1463{
1467 struct saa7134_fh *fh = file->private_data; 1464 struct saa7134_fh *fh = file->private_data;
1468 struct saa7134_dev *dev = fh->dev; 1465 struct saa7134_dev *dev = fh->dev;
1466 struct rds_command cmd;
1469 unsigned long flags; 1467 unsigned long flags;
1470 1468
1471 /* turn off overlay */ 1469 /* turn off overlay */
@@ -1498,7 +1496,9 @@ static int video_release(struct file *file)
1498 saa_andorb(SAA7134_OFMT_DATA_A, 0x1f, 0); 1496 saa_andorb(SAA7134_OFMT_DATA_A, 0x1f, 0);
1499 saa_andorb(SAA7134_OFMT_DATA_B, 0x1f, 0); 1497 saa_andorb(SAA7134_OFMT_DATA_B, 0x1f, 0);
1500 1498
1501 saa7134_i2c_call_clients(dev, TUNER_SET_STANDBY, NULL); 1499 saa_call_all(dev, core, s_standby, 0);
1500 if (fh->radio)
1501 saa_call_all(dev, core, ioctl, RDS_CMD_CLOSE, &cmd);
1502 1502
1503 /* free stuff */ 1503 /* free stuff */
1504 videobuf_mmap_free(&fh->cap); 1504 videobuf_mmap_free(&fh->cap);
@@ -1519,6 +1519,37 @@ static int video_mmap(struct file *file, struct vm_area_struct * vma)
1519 return videobuf_mmap_mapper(saa7134_queue(fh), vma); 1519 return videobuf_mmap_mapper(saa7134_queue(fh), vma);
1520} 1520}
1521 1521
1522static ssize_t radio_read(struct file *file, char __user *data,
1523 size_t count, loff_t *ppos)
1524{
1525 struct saa7134_fh *fh = file->private_data;
1526 struct saa7134_dev *dev = fh->dev;
1527 struct rds_command cmd;
1528
1529 cmd.block_count = count/3;
1530 cmd.buffer = data;
1531 cmd.instance = file;
1532 cmd.result = -ENODEV;
1533
1534 saa_call_all(dev, core, ioctl, RDS_CMD_READ, &cmd);
1535
1536 return cmd.result;
1537}
1538
1539static unsigned int radio_poll(struct file *file, poll_table *wait)
1540{
1541 struct saa7134_fh *fh = file->private_data;
1542 struct saa7134_dev *dev = fh->dev;
1543 struct rds_command cmd;
1544
1545 cmd.instance = file;
1546 cmd.event_list = wait;
1547 cmd.result = -ENODEV;
1548 saa_call_all(dev, core, ioctl, RDS_CMD_POLL, &cmd);
1549
1550 return cmd.result;
1551}
1552
1522/* ------------------------------------------------------------------ */ 1553/* ------------------------------------------------------------------ */
1523 1554
1524static int saa7134_try_get_set_fmt_vbi_cap(struct file *file, void *priv, 1555static int saa7134_try_get_set_fmt_vbi_cap(struct file *file, void *priv,
@@ -2041,7 +2072,7 @@ static int saa7134_s_frequency(struct file *file, void *priv,
2041 mutex_lock(&dev->lock); 2072 mutex_lock(&dev->lock);
2042 dev->ctl_freq = f->frequency; 2073 dev->ctl_freq = f->frequency;
2043 2074
2044 saa7134_i2c_call_clients(dev, VIDIOC_S_FREQUENCY, f); 2075 saa_call_all(dev, tuner, s_frequency, f);
2045 2076
2046 saa7134_tvaudio_do_scan(dev); 2077 saa7134_tvaudio_do_scan(dev);
2047 mutex_unlock(&dev->lock); 2078 mutex_unlock(&dev->lock);
@@ -2299,7 +2330,7 @@ static int radio_g_tuner(struct file *file, void *priv,
2299 strcpy(t->name, "Radio"); 2330 strcpy(t->name, "Radio");
2300 t->type = V4L2_TUNER_RADIO; 2331 t->type = V4L2_TUNER_RADIO;
2301 2332
2302 saa7134_i2c_call_clients(dev, VIDIOC_G_TUNER, t); 2333 saa_call_all(dev, tuner, g_tuner, t);
2303 if (dev->input->amux == TV) { 2334 if (dev->input->amux == TV) {
2304 t->signal = 0xf800 - ((saa_readb(0x581) & 0x1f) << 11); 2335 t->signal = 0xf800 - ((saa_readb(0x581) & 0x1f) << 11);
2305 t->rxsubchans = (saa_readb(0x529) & 0x08) ? 2336 t->rxsubchans = (saa_readb(0x529) & 0x08) ?
@@ -2316,7 +2347,7 @@ static int radio_s_tuner(struct file *file, void *priv,
2316 if (0 != t->index) 2347 if (0 != t->index)
2317 return -EINVAL; 2348 return -EINVAL;
2318 2349
2319 saa7134_i2c_call_clients(dev, VIDIOC_S_TUNER, t); 2350 saa_call_all(dev, tuner, s_tuner, t);
2320 return 0; 2351 return 0;
2321} 2352}
2322 2353
@@ -2443,8 +2474,10 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
2443static const struct v4l2_file_operations radio_fops = { 2474static const struct v4l2_file_operations radio_fops = {
2444 .owner = THIS_MODULE, 2475 .owner = THIS_MODULE,
2445 .open = video_open, 2476 .open = video_open,
2477 .read = radio_read,
2446 .release = video_release, 2478 .release = video_release,
2447 .ioctl = video_ioctl2, 2479 .ioctl = video_ioctl2,
2480 .poll = radio_poll,
2448}; 2481};
2449 2482
2450static const struct v4l2_ioctl_ops radio_ioctl_ops = { 2483static const struct v4l2_ioctl_ops radio_ioctl_ops = {
diff --git a/drivers/media/video/saa7134/saa7134.h b/drivers/media/video/saa7134/saa7134.h
index 14ee265f3374..a2dd326de5b9 100644
--- a/drivers/media/video/saa7134/saa7134.h
+++ b/drivers/media/video/saa7134/saa7134.h
@@ -35,6 +35,7 @@
35 35
36#include <media/v4l2-common.h> 36#include <media/v4l2-common.h>
37#include <media/v4l2-ioctl.h> 37#include <media/v4l2-ioctl.h>
38#include <media/v4l2-device.h>
38#include <media/tuner.h> 39#include <media/tuner.h>
39#include <media/ir-common.h> 40#include <media/ir-common.h>
40#include <media/ir-kbd-i2c.h> 41#include <media/ir-kbd-i2c.h>
@@ -277,6 +278,8 @@ struct saa7134_format {
277#define SAA7134_BOARD_ASUSTeK_TIGER 152 278#define SAA7134_BOARD_ASUSTeK_TIGER 152
278#define SAA7134_BOARD_KWORLD_PLUS_TV_ANALOG 153 279#define SAA7134_BOARD_KWORLD_PLUS_TV_ANALOG 153
279#define SAA7134_BOARD_AVERMEDIA_GO_007_FM_PLUS 154 280#define SAA7134_BOARD_AVERMEDIA_GO_007_FM_PLUS 154
281#define SAA7134_BOARD_HAUPPAUGE_HVR1120 155
282#define SAA7134_BOARD_HAUPPAUGE_HVR1110R3 156
280 283
281#define SAA7134_MAXBOARDS 32 284#define SAA7134_MAXBOARDS 32
282#define SAA7134_INPUT_MAX 8 285#define SAA7134_INPUT_MAX 8
@@ -309,6 +312,11 @@ enum saa7134_mpeg_type {
309 SAA7134_MPEG_DVB, 312 SAA7134_MPEG_DVB,
310}; 313};
311 314
315enum saa7134_mpeg_ts_type {
316 SAA7134_MPEG_TS_PARALLEL = 0,
317 SAA7134_MPEG_TS_SERIAL,
318};
319
312struct saa7134_board { 320struct saa7134_board {
313 char *name; 321 char *name;
314 unsigned int audio_clock; 322 unsigned int audio_clock;
@@ -324,6 +332,8 @@ struct saa7134_board {
324 unsigned int radio_type; 332 unsigned int radio_type;
325 unsigned char tuner_addr; 333 unsigned char tuner_addr;
326 unsigned char radio_addr; 334 unsigned char radio_addr;
335 unsigned char empress_addr;
336 unsigned char rds_addr;
327 337
328 unsigned int tda9887_conf; 338 unsigned int tda9887_conf;
329 unsigned int tuner_config; 339 unsigned int tuner_config;
@@ -331,6 +341,7 @@ struct saa7134_board {
331 /* peripheral I/O */ 341 /* peripheral I/O */
332 enum saa7134_video_out video_out; 342 enum saa7134_video_out video_out;
333 enum saa7134_mpeg_type mpeg; 343 enum saa7134_mpeg_type mpeg;
344 enum saa7134_mpeg_ts_type ts_type;
334 unsigned int vid_port_opts; 345 unsigned int vid_port_opts;
335}; 346};
336 347
@@ -445,7 +456,6 @@ struct saa7134_dmasound {
445 unsigned int bufsize; 456 unsigned int bufsize;
446 struct saa7134_pgtable pt; 457 struct saa7134_pgtable pt;
447 struct videobuf_dmabuf dma; 458 struct videobuf_dmabuf dma;
448 wait_queue_head_t wq;
449 unsigned int dma_blk; 459 unsigned int dma_blk;
450 unsigned int read_offset; 460 unsigned int read_offset;
451 unsigned int read_count; 461 unsigned int read_count;
@@ -482,6 +492,7 @@ struct saa7134_dev {
482 struct mutex lock; 492 struct mutex lock;
483 spinlock_t slock; 493 spinlock_t slock;
484 struct v4l2_prio_state prio; 494 struct v4l2_prio_state prio;
495 struct v4l2_device v4l2_dev;
485 /* workstruct for loading modules */ 496 /* workstruct for loading modules */
486 struct work_struct request_module_wk; 497 struct work_struct request_module_wk;
487 498
@@ -572,7 +583,6 @@ struct saa7134_dev {
572 enum saa7134_ts_status ts_state; 583 enum saa7134_ts_status ts_state;
573 unsigned int buff_cnt; 584 unsigned int buff_cnt;
574 struct saa7134_mpeg_ops *mops; 585 struct saa7134_mpeg_ops *mops;
575 struct i2c_client *mpeg_i2c_client;
576 586
577 /* SAA7134_MPEG_EMPRESS only */ 587 /* SAA7134_MPEG_EMPRESS only */
578 struct video_device *empress_dev; 588 struct video_device *empress_dev;
@@ -588,6 +598,7 @@ struct saa7134_dev {
588 int (*original_set_voltage)(struct dvb_frontend *fe, fe_sec_voltage_t voltage); 598 int (*original_set_voltage)(struct dvb_frontend *fe, fe_sec_voltage_t voltage);
589 int (*original_set_high_voltage)(struct dvb_frontend *fe, long arg); 599 int (*original_set_high_voltage)(struct dvb_frontend *fe, long arg);
590#endif 600#endif
601 void (*gate_ctrl)(struct saa7134_dev *dev, int open);
591}; 602};
592 603
593/* ----------------------------------------------------------- */ 604/* ----------------------------------------------------------- */
@@ -616,10 +627,31 @@ struct saa7134_dev {
616 V4L2_STD_NTSC | V4L2_STD_PAL_M | \ 627 V4L2_STD_NTSC | V4L2_STD_PAL_M | \
617 V4L2_STD_PAL_60) 628 V4L2_STD_PAL_60)
618 629
630#define GRP_EMPRESS (1)
631#define saa_call_all(dev, o, f, args...) do { \
632 if (dev->gate_ctrl) \
633 dev->gate_ctrl(dev, 1); \
634 v4l2_device_call_all(&(dev)->v4l2_dev, 0, o, f , ##args); \
635 if (dev->gate_ctrl) \
636 dev->gate_ctrl(dev, 0); \
637} while (0)
638
639#define saa_call_empress(dev, o, f, args...) ({ \
640 long _rc; \
641 if (dev->gate_ctrl) \
642 dev->gate_ctrl(dev, 1); \
643 _rc = v4l2_device_call_until_err(&(dev)->v4l2_dev, \
644 GRP_EMPRESS, o, f , ##args); \
645 if (dev->gate_ctrl) \
646 dev->gate_ctrl(dev, 0); \
647 _rc; \
648})
649
619/* ----------------------------------------------------------- */ 650/* ----------------------------------------------------------- */
620/* saa7134-core.c */ 651/* saa7134-core.c */
621 652
622extern struct list_head saa7134_devlist; 653extern struct list_head saa7134_devlist;
654extern struct mutex saa7134_devlist_lock;
623extern int saa7134_no_overlay; 655extern int saa7134_no_overlay;
624 656
625void saa7134_track_gpio(struct saa7134_dev *dev, char *msg); 657void saa7134_track_gpio(struct saa7134_dev *dev, char *msg);
@@ -668,10 +700,6 @@ int saa7134_tuner_callback(void *priv, int component, int command, int arg);
668 700
669int saa7134_i2c_register(struct saa7134_dev *dev); 701int saa7134_i2c_register(struct saa7134_dev *dev);
670int saa7134_i2c_unregister(struct saa7134_dev *dev); 702int saa7134_i2c_unregister(struct saa7134_dev *dev);
671void saa7134_i2c_call_clients(struct saa7134_dev *dev,
672 unsigned int cmd, void *arg);
673int saa7134_i2c_call_saa6752(struct saa7134_dev *dev,
674 unsigned int cmd, void *arg);
675 703
676 704
677/* ----------------------------------------------------------- */ 705/* ----------------------------------------------------------- */
diff --git a/drivers/media/video/saa7146.h b/drivers/media/video/saa7146.h
index 2830b5e33aec..9fadb331a40b 100644
--- a/drivers/media/video/saa7146.h
+++ b/drivers/media/video/saa7146.h
@@ -25,8 +25,6 @@
25#include <linux/types.h> 25#include <linux/types.h>
26#include <linux/wait.h> 26#include <linux/wait.h>
27 27
28#include <linux/videodev.h>
29
30#ifndef O_NONCAP 28#ifndef O_NONCAP
31#define O_NONCAP O_TRUNC 29#define O_NONCAP O_TRUNC
32#endif 30#endif
diff --git a/drivers/media/video/saa717x.c b/drivers/media/video/saa717x.c
index 88c5e942f751..25bf2303a6b5 100644
--- a/drivers/media/video/saa717x.c
+++ b/drivers/media/video/saa717x.c
@@ -931,7 +931,7 @@ static int saa717x_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
931 break; 931 break;
932 932
933 case V4L2_CID_HUE: 933 case V4L2_CID_HUE:
934 if (ctrl->value < -127 || ctrl->value > 127) { 934 if (ctrl->value < -128 || ctrl->value > 127) {
935 v4l2_err(sd, "invalid hue setting %d\n", ctrl->value); 935 v4l2_err(sd, "invalid hue setting %d\n", ctrl->value);
936 return -ERANGE; 936 return -ERANGE;
937 } 937 }
@@ -1380,11 +1380,6 @@ static int saa717x_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
1380 return 0; 1380 return 0;
1381} 1381}
1382 1382
1383static int saa717x_command(struct i2c_client *client, unsigned cmd, void *arg)
1384{
1385 return v4l2_subdev_command(i2c_get_clientdata(client), cmd, arg);
1386}
1387
1388/* ----------------------------------------------------------------------- */ 1383/* ----------------------------------------------------------------------- */
1389 1384
1390static const struct v4l2_subdev_core_ops saa717x_core_ops = { 1385static const struct v4l2_subdev_core_ops saa717x_core_ops = {
@@ -1528,10 +1523,7 @@ MODULE_DEVICE_TABLE(i2c, saa717x_id);
1528 1523
1529static struct v4l2_i2c_driver_data v4l2_i2c_data = { 1524static struct v4l2_i2c_driver_data v4l2_i2c_data = {
1530 .name = "saa717x", 1525 .name = "saa717x",
1531 .driverid = I2C_DRIVERID_SAA717X,
1532 .command = saa717x_command,
1533 .probe = saa717x_probe, 1526 .probe = saa717x_probe,
1534 .remove = saa717x_remove, 1527 .remove = saa717x_remove,
1535 .legacy_class = I2C_CLASS_TV_ANALOG | I2C_CLASS_TV_DIGITAL,
1536 .id_table = saa717x_id, 1528 .id_table = saa717x_id,
1537}; 1529};
diff --git a/drivers/media/video/saa7185.c b/drivers/media/video/saa7185.c
index 6debb65152ee..75747b104d07 100644
--- a/drivers/media/video/saa7185.c
+++ b/drivers/media/video/saa7185.c
@@ -30,52 +30,58 @@
30#include <asm/uaccess.h> 30#include <asm/uaccess.h>
31#include <linux/i2c.h> 31#include <linux/i2c.h>
32#include <linux/i2c-id.h> 32#include <linux/i2c-id.h>
33#include <linux/videodev.h> 33#include <linux/videodev2.h>
34#include <linux/video_encoder.h> 34#include <media/v4l2-device.h>
35#include <media/v4l2-common.h> 35#include <media/v4l2-chip-ident.h>
36#include <media/v4l2-i2c-drv-legacy.h> 36#include <media/v4l2-i2c-drv.h>
37 37
38MODULE_DESCRIPTION("Philips SAA7185 video encoder driver"); 38MODULE_DESCRIPTION("Philips SAA7185 video encoder driver");
39MODULE_AUTHOR("Dave Perks"); 39MODULE_AUTHOR("Dave Perks");
40MODULE_LICENSE("GPL"); 40MODULE_LICENSE("GPL");
41 41
42
43static int debug; 42static int debug;
44module_param(debug, int, 0); 43module_param(debug, int, 0);
45MODULE_PARM_DESC(debug, "Debug level (0-1)"); 44MODULE_PARM_DESC(debug, "Debug level (0-1)");
46 45
46
47/* ----------------------------------------------------------------------- */ 47/* ----------------------------------------------------------------------- */
48 48
49struct saa7185 { 49struct saa7185 {
50 struct v4l2_subdev sd;
50 unsigned char reg[128]; 51 unsigned char reg[128];
51 52
52 int norm; 53 v4l2_std_id norm;
53 int enable;
54 int bright;
55 int contrast;
56 int hue;
57 int sat;
58}; 54};
59 55
56static inline struct saa7185 *to_saa7185(struct v4l2_subdev *sd)
57{
58 return container_of(sd, struct saa7185, sd);
59}
60
60/* ----------------------------------------------------------------------- */ 61/* ----------------------------------------------------------------------- */
61 62
62static inline int saa7185_read(struct i2c_client *client) 63static inline int saa7185_read(struct v4l2_subdev *sd)
63{ 64{
65 struct i2c_client *client = v4l2_get_subdevdata(sd);
66
64 return i2c_smbus_read_byte(client); 67 return i2c_smbus_read_byte(client);
65} 68}
66 69
67static int saa7185_write(struct i2c_client *client, u8 reg, u8 value) 70static int saa7185_write(struct v4l2_subdev *sd, u8 reg, u8 value)
68{ 71{
69 struct saa7185 *encoder = i2c_get_clientdata(client); 72 struct i2c_client *client = v4l2_get_subdevdata(sd);
73 struct saa7185 *encoder = to_saa7185(sd);
70 74
71 v4l_dbg(1, debug, client, "%02x set to %02x\n", reg, value); 75 v4l2_dbg(1, debug, sd, "%02x set to %02x\n", reg, value);
72 encoder->reg[reg] = value; 76 encoder->reg[reg] = value;
73 return i2c_smbus_write_byte_data(client, reg, value); 77 return i2c_smbus_write_byte_data(client, reg, value);
74} 78}
75 79
76static int saa7185_write_block(struct i2c_client *client, 80static int saa7185_write_block(struct v4l2_subdev *sd,
77 const u8 *data, unsigned int len) 81 const u8 *data, unsigned int len)
78{ 82{
83 struct i2c_client *client = v4l2_get_subdevdata(sd);
84 struct saa7185 *encoder = to_saa7185(sd);
79 int ret = -1; 85 int ret = -1;
80 u8 reg; 86 u8 reg;
81 87
@@ -83,7 +89,6 @@ static int saa7185_write_block(struct i2c_client *client,
83 * the adapter understands raw I2C */ 89 * the adapter understands raw I2C */
84 if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { 90 if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
85 /* do raw I2C, not smbus compatible */ 91 /* do raw I2C, not smbus compatible */
86 struct saa7185 *encoder = i2c_get_clientdata(client);
87 u8 block_data[32]; 92 u8 block_data[32];
88 int block_len; 93 int block_len;
89 94
@@ -104,7 +109,7 @@ static int saa7185_write_block(struct i2c_client *client,
104 /* do some slow I2C emulation kind of thing */ 109 /* do some slow I2C emulation kind of thing */
105 while (len >= 2) { 110 while (len >= 2) {
106 reg = *data++; 111 reg = *data++;
107 ret = saa7185_write(client, reg, *data++); 112 ret = saa7185_write(sd, reg, *data++);
108 if (ret < 0) 113 if (ret < 0)
109 break; 114 break;
110 len -= 2; 115 len -= 2;
@@ -213,133 +218,106 @@ static const unsigned char init_ntsc[] = {
213 0x66, 0x21, /* FSC3 */ 218 0x66, 0x21, /* FSC3 */
214}; 219};
215 220
216static int saa7185_command(struct i2c_client *client, unsigned cmd, void *arg)
217{
218 struct saa7185 *encoder = i2c_get_clientdata(client);
219
220 switch (cmd) {
221 case 0:
222 saa7185_write_block(client, init_common,
223 sizeof(init_common));
224 switch (encoder->norm) {
225
226 case VIDEO_MODE_NTSC:
227 saa7185_write_block(client, init_ntsc,
228 sizeof(init_ntsc));
229 break;
230
231 case VIDEO_MODE_PAL:
232 saa7185_write_block(client, init_pal,
233 sizeof(init_pal));
234 break;
235 }
236 break;
237 221
238 case ENCODER_GET_CAPABILITIES: 222static int saa7185_init(struct v4l2_subdev *sd, u32 val)
239 { 223{
240 struct video_encoder_capability *cap = arg; 224 struct saa7185 *encoder = to_saa7185(sd);
241 225
242 cap->flags = 226 saa7185_write_block(sd, init_common, sizeof(init_common));
243 VIDEO_ENCODER_PAL | VIDEO_ENCODER_NTSC | 227 if (encoder->norm & V4L2_STD_NTSC)
244 VIDEO_ENCODER_SECAM | VIDEO_ENCODER_CCIR; 228 saa7185_write_block(sd, init_ntsc, sizeof(init_ntsc));
245 cap->inputs = 1; 229 else
246 cap->outputs = 1; 230 saa7185_write_block(sd, init_pal, sizeof(init_pal));
247 break; 231 return 0;
248 } 232}
249 233
250 case ENCODER_SET_NORM: 234static int saa7185_s_std_output(struct v4l2_subdev *sd, v4l2_std_id std)
251 { 235{
252 int *iarg = arg; 236 struct saa7185 *encoder = to_saa7185(sd);
253 237
254 //saa7185_write_block(client, init_common, sizeof(init_common)); 238 if (std & V4L2_STD_NTSC)
239 saa7185_write_block(sd, init_ntsc, sizeof(init_ntsc));
240 else if (std & V4L2_STD_PAL)
241 saa7185_write_block(sd, init_pal, sizeof(init_pal));
242 else
243 return -EINVAL;
244 encoder->norm = std;
245 return 0;
246}
255 247
256 switch (*iarg) { 248static int saa7185_s_routing(struct v4l2_subdev *sd, const struct v4l2_routing *route)
257 case VIDEO_MODE_NTSC: 249{
258 saa7185_write_block(client, init_ntsc, 250 struct saa7185 *encoder = to_saa7185(sd);
259 sizeof(init_ntsc));
260 break;
261 251
262 case VIDEO_MODE_PAL: 252 /* RJ: route->input = 0: input is from SA7111
263 saa7185_write_block(client, init_pal, 253 route->input = 1: input is from ZR36060 */
264 sizeof(init_pal));
265 break;
266 254
267 case VIDEO_MODE_SECAM: 255 switch (route->input) {
268 default: 256 case 0:
269 return -EINVAL; 257 /* turn off colorbar */
270 } 258 saa7185_write(sd, 0x3a, 0x0f);
271 encoder->norm = *iarg; 259 /* Switch RTCE to 1 */
272 break; 260 saa7185_write(sd, 0x61, (encoder->reg[0x61] & 0xf7) | 0x08);
273 } 261 saa7185_write(sd, 0x6e, 0x01);
274
275 case ENCODER_SET_INPUT:
276 {
277 int *iarg = arg;
278
279 /* RJ: *iarg = 0: input is from SA7111
280 *iarg = 1: input is from ZR36060 */
281
282 switch (*iarg) {
283 case 0:
284 /* Switch RTCE to 1 */
285 saa7185_write(client, 0x61,
286 (encoder->reg[0x61] & 0xf7) | 0x08);
287 saa7185_write(client, 0x6e, 0x01);
288 break;
289
290 case 1:
291 /* Switch RTCE to 0 */
292 saa7185_write(client, 0x61,
293 (encoder->reg[0x61] & 0xf7) | 0x00);
294 /* SW: a slight sync problem... */
295 saa7185_write(client, 0x6e, 0x00);
296 break;
297
298 default:
299 return -EINVAL;
300 }
301 break; 262 break;
302 }
303 263
304 case ENCODER_SET_OUTPUT: 264 case 1:
305 { 265 /* turn off colorbar */
306 int *iarg = arg; 266 saa7185_write(sd, 0x3a, 0x0f);
307 267 /* Switch RTCE to 0 */
308 /* not much choice of outputs */ 268 saa7185_write(sd, 0x61, (encoder->reg[0x61] & 0xf7) | 0x00);
309 if (*iarg != 0) 269 /* SW: a slight sync problem... */
310 return -EINVAL; 270 saa7185_write(sd, 0x6e, 0x00);
311 break; 271 break;
312 }
313
314 case ENCODER_ENABLE_OUTPUT:
315 {
316 int *iarg = arg;
317 272
318 encoder->enable = !!*iarg; 273 case 2:
319 saa7185_write(client, 0x61, 274 /* turn on colorbar */
320 (encoder->reg[0x61] & 0xbf) | 275 saa7185_write(sd, 0x3a, 0x8f);
321 (encoder->enable ? 0x00 : 0x40)); 276 /* Switch RTCE to 0 */
277 saa7185_write(sd, 0x61, (encoder->reg[0x61] & 0xf7) | 0x08);
278 /* SW: a slight sync problem... */
279 saa7185_write(sd, 0x6e, 0x01);
322 break; 280 break;
323 }
324 281
325 default: 282 default:
326 return -EINVAL; 283 return -EINVAL;
327 } 284 }
328
329 return 0; 285 return 0;
330} 286}
331 287
288static int saa7185_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
289{
290 struct i2c_client *client = v4l2_get_subdevdata(sd);
291
292 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_SAA7185, 0);
293}
294
332/* ----------------------------------------------------------------------- */ 295/* ----------------------------------------------------------------------- */
333 296
334static unsigned short normal_i2c[] = { 0x88 >> 1, I2C_CLIENT_END }; 297static const struct v4l2_subdev_core_ops saa7185_core_ops = {
298 .g_chip_ident = saa7185_g_chip_ident,
299 .init = saa7185_init,
300};
335 301
336I2C_CLIENT_INSMOD; 302static const struct v4l2_subdev_video_ops saa7185_video_ops = {
303 .s_std_output = saa7185_s_std_output,
304 .s_routing = saa7185_s_routing,
305};
306
307static const struct v4l2_subdev_ops saa7185_ops = {
308 .core = &saa7185_core_ops,
309 .video = &saa7185_video_ops,
310};
311
312
313/* ----------------------------------------------------------------------- */
337 314
338static int saa7185_probe(struct i2c_client *client, 315static int saa7185_probe(struct i2c_client *client,
339 const struct i2c_device_id *id) 316 const struct i2c_device_id *id)
340{ 317{
341 int i; 318 int i;
342 struct saa7185 *encoder; 319 struct saa7185 *encoder;
320 struct v4l2_subdev *sd;
343 321
344 /* Check if the adapter supports the needed features */ 322 /* Check if the adapter supports the needed features */
345 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 323 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
@@ -351,28 +329,29 @@ static int saa7185_probe(struct i2c_client *client,
351 encoder = kzalloc(sizeof(struct saa7185), GFP_KERNEL); 329 encoder = kzalloc(sizeof(struct saa7185), GFP_KERNEL);
352 if (encoder == NULL) 330 if (encoder == NULL)
353 return -ENOMEM; 331 return -ENOMEM;
354 encoder->norm = VIDEO_MODE_NTSC; 332 encoder->norm = V4L2_STD_NTSC;
355 encoder->enable = 1; 333 sd = &encoder->sd;
356 i2c_set_clientdata(client, encoder); 334 v4l2_i2c_subdev_init(sd, client, &saa7185_ops);
357 335
358 i = saa7185_write_block(client, init_common, sizeof(init_common)); 336 i = saa7185_write_block(sd, init_common, sizeof(init_common));
359 if (i >= 0) 337 if (i >= 0)
360 i = saa7185_write_block(client, init_ntsc, sizeof(init_ntsc)); 338 i = saa7185_write_block(sd, init_ntsc, sizeof(init_ntsc));
361 if (i < 0) 339 if (i < 0)
362 v4l_dbg(1, debug, client, "init error %d\n", i); 340 v4l2_dbg(1, debug, sd, "init error %d\n", i);
363 else 341 else
364 v4l_dbg(1, debug, client, "revision 0x%x\n", 342 v4l2_dbg(1, debug, sd, "revision 0x%x\n",
365 saa7185_read(client) >> 5); 343 saa7185_read(sd) >> 5);
366 return 0; 344 return 0;
367} 345}
368 346
369static int saa7185_remove(struct i2c_client *client) 347static int saa7185_remove(struct i2c_client *client)
370{ 348{
371 struct saa7185 *encoder = i2c_get_clientdata(client); 349 struct v4l2_subdev *sd = i2c_get_clientdata(client);
372 350 struct saa7185 *encoder = to_saa7185(sd);
373 saa7185_write(client, 0x61, (encoder->reg[0x61]) | 0x40); /* SW: output off is active */
374 //saa7185_write(client, 0x3a, (encoder->reg[0x3a]) | 0x80); /* SW: color bar */
375 351
352 v4l2_device_unregister_subdev(sd);
353 /* SW: output off is active */
354 saa7185_write(sd, 0x61, (encoder->reg[0x61]) | 0x40);
376 kfree(encoder); 355 kfree(encoder);
377 return 0; 356 return 0;
378} 357}
@@ -387,8 +366,6 @@ MODULE_DEVICE_TABLE(i2c, saa7185_id);
387 366
388static struct v4l2_i2c_driver_data v4l2_i2c_data = { 367static struct v4l2_i2c_driver_data v4l2_i2c_data = {
389 .name = "saa7185", 368 .name = "saa7185",
390 .driverid = I2C_DRIVERID_SAA7185B,
391 .command = saa7185_command,
392 .probe = saa7185_probe, 369 .probe = saa7185_probe,
393 .remove = saa7185_remove, 370 .remove = saa7185_remove,
394 .id_table = saa7185_id, 371 .id_table = saa7185_id,
diff --git a/drivers/media/video/saa7191.c b/drivers/media/video/saa7191.c
index b4018cce3285..3f523aeec56e 100644
--- a/drivers/media/video/saa7191.c
+++ b/drivers/media/video/saa7191.c
@@ -19,9 +19,11 @@
19#include <linux/mm.h> 19#include <linux/mm.h>
20#include <linux/slab.h> 20#include <linux/slab.h>
21 21
22#include <linux/videodev.h> 22#include <linux/videodev2.h>
23#include <linux/video_decoder.h>
24#include <linux/i2c.h> 23#include <linux/i2c.h>
24#include <media/v4l2-device.h>
25#include <media/v4l2-chip-ident.h>
26#include <media/v4l2-i2c-drv.h>
25 27
26#include "saa7191.h" 28#include "saa7191.h"
27 29
@@ -32,6 +34,7 @@ MODULE_VERSION(SAA7191_MODULE_VERSION);
32MODULE_AUTHOR("Mikael Nousiainen <tmnousia@cc.hut.fi>"); 34MODULE_AUTHOR("Mikael Nousiainen <tmnousia@cc.hut.fi>");
33MODULE_LICENSE("GPL"); 35MODULE_LICENSE("GPL");
34 36
37
35// #define SAA7191_DEBUG 38// #define SAA7191_DEBUG
36 39
37#ifdef SAA7191_DEBUG 40#ifdef SAA7191_DEBUG
@@ -44,17 +47,20 @@ MODULE_LICENSE("GPL");
44#define SAA7191_SYNC_DELAY 100 /* milliseconds */ 47#define SAA7191_SYNC_DELAY 100 /* milliseconds */
45 48
46struct saa7191 { 49struct saa7191 {
47 struct i2c_client *client; 50 struct v4l2_subdev sd;
48 51
49 /* the register values are stored here as the actual 52 /* the register values are stored here as the actual
50 * I2C-registers are write-only */ 53 * I2C-registers are write-only */
51 u8 reg[25]; 54 u8 reg[25];
52 55
53 int input; 56 int input;
54 int norm; 57 v4l2_std_id norm;
55}; 58};
56 59
57static struct i2c_driver i2c_driver_saa7191; 60static inline struct saa7191 *to_saa7191(struct v4l2_subdev *sd)
61{
62 return container_of(sd, struct saa7191, sd);
63}
58 64
59static const u8 initseq[] = { 65static const u8 initseq[] = {
60 0, /* Subaddress */ 66 0, /* Subaddress */
@@ -100,15 +106,14 @@ static const u8 initseq[] = {
100 106
101/* SAA7191 register handling */ 107/* SAA7191 register handling */
102 108
103static u8 saa7191_read_reg(struct i2c_client *client, 109static u8 saa7191_read_reg(struct v4l2_subdev *sd, u8 reg)
104 u8 reg)
105{ 110{
106 return ((struct saa7191 *)i2c_get_clientdata(client))->reg[reg]; 111 return to_saa7191(sd)->reg[reg];
107} 112}
108 113
109static int saa7191_read_status(struct i2c_client *client, 114static int saa7191_read_status(struct v4l2_subdev *sd, u8 *value)
110 u8 *value)
111{ 115{
116 struct i2c_client *client = v4l2_get_subdevdata(sd);
112 int ret; 117 int ret;
113 118
114 ret = i2c_master_recv(client, value, 1); 119 ret = i2c_master_recv(client, value, 1);
@@ -121,21 +126,23 @@ static int saa7191_read_status(struct i2c_client *client,
121} 126}
122 127
123 128
124static int saa7191_write_reg(struct i2c_client *client, u8 reg, 129static int saa7191_write_reg(struct v4l2_subdev *sd, u8 reg, u8 value)
125 u8 value)
126{ 130{
127 ((struct saa7191 *)i2c_get_clientdata(client))->reg[reg] = value; 131 struct i2c_client *client = v4l2_get_subdevdata(sd);
132
133 to_saa7191(sd)->reg[reg] = value;
128 return i2c_smbus_write_byte_data(client, reg, value); 134 return i2c_smbus_write_byte_data(client, reg, value);
129} 135}
130 136
131/* the first byte of data must be the first subaddress number (register) */ 137/* the first byte of data must be the first subaddress number (register) */
132static int saa7191_write_block(struct i2c_client *client, 138static int saa7191_write_block(struct v4l2_subdev *sd,
133 u8 length, const u8 *data) 139 u8 length, const u8 *data)
134{ 140{
141 struct i2c_client *client = v4l2_get_subdevdata(sd);
142 struct saa7191 *decoder = to_saa7191(sd);
135 int i; 143 int i;
136 int ret; 144 int ret;
137 145
138 struct saa7191 *decoder = (struct saa7191 *)i2c_get_clientdata(client);
139 for (i = 0; i < (length - 1); i++) { 146 for (i = 0; i < (length - 1); i++) {
140 decoder->reg[data[0] + i] = data[i + 1]; 147 decoder->reg[data[0] + i] = data[i + 1];
141 } 148 }
@@ -152,14 +159,15 @@ static int saa7191_write_block(struct i2c_client *client,
152 159
153/* Helper functions */ 160/* Helper functions */
154 161
155static int saa7191_set_input(struct i2c_client *client, int input) 162static int saa7191_s_routing(struct v4l2_subdev *sd,
163 const struct v4l2_routing *route)
156{ 164{
157 struct saa7191 *decoder = i2c_get_clientdata(client); 165 struct saa7191 *decoder = to_saa7191(sd);
158 u8 luma = saa7191_read_reg(client, SAA7191_REG_LUMA); 166 u8 luma = saa7191_read_reg(sd, SAA7191_REG_LUMA);
159 u8 iock = saa7191_read_reg(client, SAA7191_REG_IOCK); 167 u8 iock = saa7191_read_reg(sd, SAA7191_REG_IOCK);
160 int err; 168 int err;
161 169
162 switch (input) { 170 switch (route->input) {
163 case SAA7191_INPUT_COMPOSITE: /* Set Composite input */ 171 case SAA7191_INPUT_COMPOSITE: /* Set Composite input */
164 iock &= ~(SAA7191_IOCK_CHRS | SAA7191_IOCK_GPSW1 172 iock &= ~(SAA7191_IOCK_CHRS | SAA7191_IOCK_GPSW1
165 | SAA7191_IOCK_GPSW2); 173 | SAA7191_IOCK_GPSW2);
@@ -175,54 +183,50 @@ static int saa7191_set_input(struct i2c_client *client, int input)
175 return -EINVAL; 183 return -EINVAL;
176 } 184 }
177 185
178 err = saa7191_write_reg(client, SAA7191_REG_LUMA, luma); 186 err = saa7191_write_reg(sd, SAA7191_REG_LUMA, luma);
179 if (err) 187 if (err)
180 return -EIO; 188 return -EIO;
181 err = saa7191_write_reg(client, SAA7191_REG_IOCK, iock); 189 err = saa7191_write_reg(sd, SAA7191_REG_IOCK, iock);
182 if (err) 190 if (err)
183 return -EIO; 191 return -EIO;
184 192
185 decoder->input = input; 193 decoder->input = route->input;
186 194
187 return 0; 195 return 0;
188} 196}
189 197
190static int saa7191_set_norm(struct i2c_client *client, int norm) 198static int saa7191_s_std(struct v4l2_subdev *sd, v4l2_std_id norm)
191{ 199{
192 struct saa7191 *decoder = i2c_get_clientdata(client); 200 struct saa7191 *decoder = to_saa7191(sd);
193 u8 stdc = saa7191_read_reg(client, SAA7191_REG_STDC); 201 u8 stdc = saa7191_read_reg(sd, SAA7191_REG_STDC);
194 u8 ctl3 = saa7191_read_reg(client, SAA7191_REG_CTL3); 202 u8 ctl3 = saa7191_read_reg(sd, SAA7191_REG_CTL3);
195 u8 chcv = saa7191_read_reg(client, SAA7191_REG_CHCV); 203 u8 chcv = saa7191_read_reg(sd, SAA7191_REG_CHCV);
196 int err; 204 int err;
197 205
198 switch(norm) { 206 if (norm & V4L2_STD_PAL) {
199 case SAA7191_NORM_PAL:
200 stdc &= ~SAA7191_STDC_SECS; 207 stdc &= ~SAA7191_STDC_SECS;
201 ctl3 &= ~(SAA7191_CTL3_AUFD | SAA7191_CTL3_FSEL); 208 ctl3 &= ~(SAA7191_CTL3_AUFD | SAA7191_CTL3_FSEL);
202 chcv = SAA7191_CHCV_PAL; 209 chcv = SAA7191_CHCV_PAL;
203 break; 210 } else if (norm & V4L2_STD_NTSC) {
204 case SAA7191_NORM_NTSC:
205 stdc &= ~SAA7191_STDC_SECS; 211 stdc &= ~SAA7191_STDC_SECS;
206 ctl3 &= ~SAA7191_CTL3_AUFD; 212 ctl3 &= ~SAA7191_CTL3_AUFD;
207 ctl3 |= SAA7191_CTL3_FSEL; 213 ctl3 |= SAA7191_CTL3_FSEL;
208 chcv = SAA7191_CHCV_NTSC; 214 chcv = SAA7191_CHCV_NTSC;
209 break; 215 } else if (norm & V4L2_STD_SECAM) {
210 case SAA7191_NORM_SECAM:
211 stdc |= SAA7191_STDC_SECS; 216 stdc |= SAA7191_STDC_SECS;
212 ctl3 &= ~(SAA7191_CTL3_AUFD | SAA7191_CTL3_FSEL); 217 ctl3 &= ~(SAA7191_CTL3_AUFD | SAA7191_CTL3_FSEL);
213 chcv = SAA7191_CHCV_PAL; 218 chcv = SAA7191_CHCV_PAL;
214 break; 219 } else {
215 default:
216 return -EINVAL; 220 return -EINVAL;
217 } 221 }
218 222
219 err = saa7191_write_reg(client, SAA7191_REG_CTL3, ctl3); 223 err = saa7191_write_reg(sd, SAA7191_REG_CTL3, ctl3);
220 if (err) 224 if (err)
221 return -EIO; 225 return -EIO;
222 err = saa7191_write_reg(client, SAA7191_REG_STDC, stdc); 226 err = saa7191_write_reg(sd, SAA7191_REG_STDC, stdc);
223 if (err) 227 if (err)
224 return -EIO; 228 return -EIO;
225 err = saa7191_write_reg(client, SAA7191_REG_CHCV, chcv); 229 err = saa7191_write_reg(sd, SAA7191_REG_CHCV, chcv);
226 if (err) 230 if (err)
227 return -EIO; 231 return -EIO;
228 232
@@ -230,19 +234,19 @@ static int saa7191_set_norm(struct i2c_client *client, int norm)
230 234
231 dprintk("ctl3: %02x stdc: %02x chcv: %02x\n", ctl3, 235 dprintk("ctl3: %02x stdc: %02x chcv: %02x\n", ctl3,
232 stdc, chcv); 236 stdc, chcv);
233 dprintk("norm: %d\n", norm); 237 dprintk("norm: %llx\n", norm);
234 238
235 return 0; 239 return 0;
236} 240}
237 241
238static int saa7191_wait_for_signal(struct i2c_client *client, u8 *status) 242static int saa7191_wait_for_signal(struct v4l2_subdev *sd, u8 *status)
239{ 243{
240 int i = 0; 244 int i = 0;
241 245
242 dprintk("Checking for signal...\n"); 246 dprintk("Checking for signal...\n");
243 247
244 for (i = 0; i < SAA7191_SYNC_COUNT; i++) { 248 for (i = 0; i < SAA7191_SYNC_COUNT; i++) {
245 if (saa7191_read_status(client, status)) 249 if (saa7191_read_status(sd, status))
246 return -EIO; 250 return -EIO;
247 251
248 if (((*status) & SAA7191_STATUS_HLCK) == 0) { 252 if (((*status) & SAA7191_STATUS_HLCK) == 0) {
@@ -258,31 +262,34 @@ static int saa7191_wait_for_signal(struct i2c_client *client, u8 *status)
258 return -EBUSY; 262 return -EBUSY;
259} 263}
260 264
261static int saa7191_autodetect_norm_extended(struct i2c_client *client) 265static int saa7191_querystd(struct v4l2_subdev *sd, v4l2_std_id *norm)
262{ 266{
263 u8 stdc = saa7191_read_reg(client, SAA7191_REG_STDC); 267 struct saa7191 *decoder = to_saa7191(sd);
264 u8 ctl3 = saa7191_read_reg(client, SAA7191_REG_CTL3); 268 u8 stdc = saa7191_read_reg(sd, SAA7191_REG_STDC);
269 u8 ctl3 = saa7191_read_reg(sd, SAA7191_REG_CTL3);
265 u8 status; 270 u8 status;
271 v4l2_std_id old_norm = decoder->norm;
266 int err = 0; 272 int err = 0;
267 273
268 dprintk("SAA7191 extended signal auto-detection...\n"); 274 dprintk("SAA7191 extended signal auto-detection...\n");
269 275
276 *norm = V4L2_STD_NTSC | V4L2_STD_PAL | V4L2_STD_SECAM;
270 stdc &= ~SAA7191_STDC_SECS; 277 stdc &= ~SAA7191_STDC_SECS;
271 ctl3 &= ~(SAA7191_CTL3_FSEL); 278 ctl3 &= ~(SAA7191_CTL3_FSEL);
272 279
273 err = saa7191_write_reg(client, SAA7191_REG_STDC, stdc); 280 err = saa7191_write_reg(sd, SAA7191_REG_STDC, stdc);
274 if (err) { 281 if (err) {
275 err = -EIO; 282 err = -EIO;
276 goto out; 283 goto out;
277 } 284 }
278 err = saa7191_write_reg(client, SAA7191_REG_CTL3, ctl3); 285 err = saa7191_write_reg(sd, SAA7191_REG_CTL3, ctl3);
279 if (err) { 286 if (err) {
280 err = -EIO; 287 err = -EIO;
281 goto out; 288 goto out;
282 } 289 }
283 290
284 ctl3 |= SAA7191_CTL3_AUFD; 291 ctl3 |= SAA7191_CTL3_AUFD;
285 err = saa7191_write_reg(client, SAA7191_REG_CTL3, ctl3); 292 err = saa7191_write_reg(sd, SAA7191_REG_CTL3, ctl3);
286 if (err) { 293 if (err) {
287 err = -EIO; 294 err = -EIO;
288 goto out; 295 goto out;
@@ -290,53 +297,54 @@ static int saa7191_autodetect_norm_extended(struct i2c_client *client)
290 297
291 msleep(SAA7191_SYNC_DELAY); 298 msleep(SAA7191_SYNC_DELAY);
292 299
293 err = saa7191_wait_for_signal(client, &status); 300 err = saa7191_wait_for_signal(sd, &status);
294 if (err) 301 if (err)
295 goto out; 302 goto out;
296 303
297 if (status & SAA7191_STATUS_FIDT) { 304 if (status & SAA7191_STATUS_FIDT) {
298 /* 60Hz signal -> NTSC */ 305 /* 60Hz signal -> NTSC */
299 dprintk("60Hz signal: NTSC\n"); 306 dprintk("60Hz signal: NTSC\n");
300 return saa7191_set_norm(client, SAA7191_NORM_NTSC); 307 *norm = V4L2_STD_NTSC;
308 return 0;
301 } 309 }
302 310
303 /* 50Hz signal */ 311 /* 50Hz signal */
304 dprintk("50Hz signal: Trying PAL...\n"); 312 dprintk("50Hz signal: Trying PAL...\n");
305 313
306 /* try PAL first */ 314 /* try PAL first */
307 err = saa7191_set_norm(client, SAA7191_NORM_PAL); 315 err = saa7191_s_std(sd, V4L2_STD_PAL);
308 if (err) 316 if (err)
309 goto out; 317 goto out;
310 318
311 msleep(SAA7191_SYNC_DELAY); 319 msleep(SAA7191_SYNC_DELAY);
312 320
313 err = saa7191_wait_for_signal(client, &status); 321 err = saa7191_wait_for_signal(sd, &status);
314 if (err) 322 if (err)
315 goto out; 323 goto out;
316 324
317 /* not 50Hz ? */ 325 /* not 50Hz ? */
318 if (status & SAA7191_STATUS_FIDT) { 326 if (status & SAA7191_STATUS_FIDT) {
319 dprintk("No 50Hz signal\n"); 327 dprintk("No 50Hz signal\n");
320 err = -EAGAIN; 328 saa7191_s_std(sd, old_norm);
321 goto out; 329 return -EAGAIN;
322 } 330 }
323 331
324 if (status & SAA7191_STATUS_CODE) { 332 if (status & SAA7191_STATUS_CODE) {
325 dprintk("PAL\n"); 333 dprintk("PAL\n");
326 return 0; 334 *norm = V4L2_STD_PAL;
335 return saa7191_s_std(sd, old_norm);
327 } 336 }
328 337
329 dprintk("No color detected with PAL - Trying SECAM...\n"); 338 dprintk("No color detected with PAL - Trying SECAM...\n");
330 339
331 /* no color detected ? -> try SECAM */ 340 /* no color detected ? -> try SECAM */
332 err = saa7191_set_norm(client, 341 err = saa7191_s_std(sd, V4L2_STD_SECAM);
333 SAA7191_NORM_SECAM);
334 if (err) 342 if (err)
335 goto out; 343 goto out;
336 344
337 msleep(SAA7191_SYNC_DELAY); 345 msleep(SAA7191_SYNC_DELAY);
338 346
339 err = saa7191_wait_for_signal(client, &status); 347 err = saa7191_wait_for_signal(sd, &status);
340 if (err) 348 if (err)
341 goto out; 349 goto out;
342 350
@@ -350,32 +358,17 @@ static int saa7191_autodetect_norm_extended(struct i2c_client *client)
350 if (status & SAA7191_STATUS_CODE) { 358 if (status & SAA7191_STATUS_CODE) {
351 /* Color detected -> SECAM */ 359 /* Color detected -> SECAM */
352 dprintk("SECAM\n"); 360 dprintk("SECAM\n");
353 return 0; 361 *norm = V4L2_STD_SECAM;
362 return saa7191_s_std(sd, old_norm);
354 } 363 }
355 364
356 dprintk("No color detected with SECAM - Going back to PAL.\n"); 365 dprintk("No color detected with SECAM - Going back to PAL.\n");
357 366
358 /* still no color detected ?
359 * -> set norm back to PAL */
360 err = saa7191_set_norm(client,
361 SAA7191_NORM_PAL);
362 if (err)
363 goto out;
364
365out: 367out:
366 ctl3 = saa7191_read_reg(client, SAA7191_REG_CTL3); 368 return saa7191_s_std(sd, old_norm);
367 if (ctl3 & SAA7191_CTL3_AUFD) {
368 ctl3 &= ~(SAA7191_CTL3_AUFD);
369 err = saa7191_write_reg(client, SAA7191_REG_CTL3, ctl3);
370 if (err) {
371 err = -EIO;
372 }
373 }
374
375 return err;
376} 369}
377 370
378static int saa7191_autodetect_norm(struct i2c_client *client) 371static int saa7191_autodetect_norm(struct v4l2_subdev *sd)
379{ 372{
380 u8 status; 373 u8 status;
381 374
@@ -383,7 +376,7 @@ static int saa7191_autodetect_norm(struct i2c_client *client)
383 376
384 dprintk("Reading status...\n"); 377 dprintk("Reading status...\n");
385 378
386 if (saa7191_read_status(client, &status)) 379 if (saa7191_read_status(sd, &status))
387 return -EIO; 380 return -EIO;
388 381
389 dprintk("Checking for signal...\n"); 382 dprintk("Checking for signal...\n");
@@ -399,26 +392,25 @@ static int saa7191_autodetect_norm(struct i2c_client *client)
399 if (status & SAA7191_STATUS_FIDT) { 392 if (status & SAA7191_STATUS_FIDT) {
400 /* 60hz signal -> NTSC */ 393 /* 60hz signal -> NTSC */
401 dprintk("NTSC\n"); 394 dprintk("NTSC\n");
402 return saa7191_set_norm(client, SAA7191_NORM_NTSC); 395 return saa7191_s_std(sd, V4L2_STD_NTSC);
403 } else { 396 } else {
404 /* 50hz signal -> PAL */ 397 /* 50hz signal -> PAL */
405 dprintk("PAL\n"); 398 dprintk("PAL\n");
406 return saa7191_set_norm(client, SAA7191_NORM_PAL); 399 return saa7191_s_std(sd, V4L2_STD_PAL);
407 } 400 }
408} 401}
409 402
410static int saa7191_get_control(struct i2c_client *client, 403static int saa7191_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
411 struct saa7191_control *ctrl)
412{ 404{
413 u8 reg; 405 u8 reg;
414 int ret = 0; 406 int ret = 0;
415 407
416 switch (ctrl->type) { 408 switch (ctrl->id) {
417 case SAA7191_CONTROL_BANDPASS: 409 case SAA7191_CONTROL_BANDPASS:
418 case SAA7191_CONTROL_BANDPASS_WEIGHT: 410 case SAA7191_CONTROL_BANDPASS_WEIGHT:
419 case SAA7191_CONTROL_CORING: 411 case SAA7191_CONTROL_CORING:
420 reg = saa7191_read_reg(client, SAA7191_REG_LUMA); 412 reg = saa7191_read_reg(sd, SAA7191_REG_LUMA);
421 switch (ctrl->type) { 413 switch (ctrl->id) {
422 case SAA7191_CONTROL_BANDPASS: 414 case SAA7191_CONTROL_BANDPASS:
423 ctrl->value = ((s32)reg & SAA7191_LUMA_BPSS_MASK) 415 ctrl->value = ((s32)reg & SAA7191_LUMA_BPSS_MASK)
424 >> SAA7191_LUMA_BPSS_SHIFT; 416 >> SAA7191_LUMA_BPSS_SHIFT;
@@ -435,15 +427,15 @@ static int saa7191_get_control(struct i2c_client *client,
435 break; 427 break;
436 case SAA7191_CONTROL_FORCE_COLOUR: 428 case SAA7191_CONTROL_FORCE_COLOUR:
437 case SAA7191_CONTROL_CHROMA_GAIN: 429 case SAA7191_CONTROL_CHROMA_GAIN:
438 reg = saa7191_read_reg(client, SAA7191_REG_GAIN); 430 reg = saa7191_read_reg(sd, SAA7191_REG_GAIN);
439 if (ctrl->type == SAA7191_CONTROL_FORCE_COLOUR) 431 if (ctrl->id == SAA7191_CONTROL_FORCE_COLOUR)
440 ctrl->value = ((s32)reg & SAA7191_GAIN_COLO) ? 1 : 0; 432 ctrl->value = ((s32)reg & SAA7191_GAIN_COLO) ? 1 : 0;
441 else 433 else
442 ctrl->value = ((s32)reg & SAA7191_GAIN_LFIS_MASK) 434 ctrl->value = ((s32)reg & SAA7191_GAIN_LFIS_MASK)
443 >> SAA7191_GAIN_LFIS_SHIFT; 435 >> SAA7191_GAIN_LFIS_SHIFT;
444 break; 436 break;
445 case SAA7191_CONTROL_HUE: 437 case V4L2_CID_HUE:
446 reg = saa7191_read_reg(client, SAA7191_REG_HUEC); 438 reg = saa7191_read_reg(sd, SAA7191_REG_HUEC);
447 if (reg < 0x80) 439 if (reg < 0x80)
448 reg += 0x80; 440 reg += 0x80;
449 else 441 else
@@ -451,18 +443,18 @@ static int saa7191_get_control(struct i2c_client *client,
451 ctrl->value = (s32)reg; 443 ctrl->value = (s32)reg;
452 break; 444 break;
453 case SAA7191_CONTROL_VTRC: 445 case SAA7191_CONTROL_VTRC:
454 reg = saa7191_read_reg(client, SAA7191_REG_STDC); 446 reg = saa7191_read_reg(sd, SAA7191_REG_STDC);
455 ctrl->value = ((s32)reg & SAA7191_STDC_VTRC) ? 1 : 0; 447 ctrl->value = ((s32)reg & SAA7191_STDC_VTRC) ? 1 : 0;
456 break; 448 break;
457 case SAA7191_CONTROL_LUMA_DELAY: 449 case SAA7191_CONTROL_LUMA_DELAY:
458 reg = saa7191_read_reg(client, SAA7191_REG_CTL3); 450 reg = saa7191_read_reg(sd, SAA7191_REG_CTL3);
459 ctrl->value = ((s32)reg & SAA7191_CTL3_YDEL_MASK) 451 ctrl->value = ((s32)reg & SAA7191_CTL3_YDEL_MASK)
460 >> SAA7191_CTL3_YDEL_SHIFT; 452 >> SAA7191_CTL3_YDEL_SHIFT;
461 if (ctrl->value >= 4) 453 if (ctrl->value >= 4)
462 ctrl->value -= 8; 454 ctrl->value -= 8;
463 break; 455 break;
464 case SAA7191_CONTROL_VNR: 456 case SAA7191_CONTROL_VNR:
465 reg = saa7191_read_reg(client, SAA7191_REG_CTL4); 457 reg = saa7191_read_reg(sd, SAA7191_REG_CTL4);
466 ctrl->value = ((s32)reg & SAA7191_CTL4_VNOI_MASK) 458 ctrl->value = ((s32)reg & SAA7191_CTL4_VNOI_MASK)
467 >> SAA7191_CTL4_VNOI_SHIFT; 459 >> SAA7191_CTL4_VNOI_SHIFT;
468 break; 460 break;
@@ -473,18 +465,17 @@ static int saa7191_get_control(struct i2c_client *client,
473 return ret; 465 return ret;
474} 466}
475 467
476static int saa7191_set_control(struct i2c_client *client, 468static int saa7191_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
477 struct saa7191_control *ctrl)
478{ 469{
479 u8 reg; 470 u8 reg;
480 int ret = 0; 471 int ret = 0;
481 472
482 switch (ctrl->type) { 473 switch (ctrl->id) {
483 case SAA7191_CONTROL_BANDPASS: 474 case SAA7191_CONTROL_BANDPASS:
484 case SAA7191_CONTROL_BANDPASS_WEIGHT: 475 case SAA7191_CONTROL_BANDPASS_WEIGHT:
485 case SAA7191_CONTROL_CORING: 476 case SAA7191_CONTROL_CORING:
486 reg = saa7191_read_reg(client, SAA7191_REG_LUMA); 477 reg = saa7191_read_reg(sd, SAA7191_REG_LUMA);
487 switch (ctrl->type) { 478 switch (ctrl->id) {
488 case SAA7191_CONTROL_BANDPASS: 479 case SAA7191_CONTROL_BANDPASS:
489 reg &= ~SAA7191_LUMA_BPSS_MASK; 480 reg &= ~SAA7191_LUMA_BPSS_MASK;
490 reg |= (ctrl->value << SAA7191_LUMA_BPSS_SHIFT) 481 reg |= (ctrl->value << SAA7191_LUMA_BPSS_SHIFT)
@@ -501,12 +492,12 @@ static int saa7191_set_control(struct i2c_client *client,
501 & SAA7191_LUMA_CORI_MASK; 492 & SAA7191_LUMA_CORI_MASK;
502 break; 493 break;
503 } 494 }
504 ret = saa7191_write_reg(client, SAA7191_REG_LUMA, reg); 495 ret = saa7191_write_reg(sd, SAA7191_REG_LUMA, reg);
505 break; 496 break;
506 case SAA7191_CONTROL_FORCE_COLOUR: 497 case SAA7191_CONTROL_FORCE_COLOUR:
507 case SAA7191_CONTROL_CHROMA_GAIN: 498 case SAA7191_CONTROL_CHROMA_GAIN:
508 reg = saa7191_read_reg(client, SAA7191_REG_GAIN); 499 reg = saa7191_read_reg(sd, SAA7191_REG_GAIN);
509 if (ctrl->type == SAA7191_CONTROL_FORCE_COLOUR) { 500 if (ctrl->id == SAA7191_CONTROL_FORCE_COLOUR) {
510 if (ctrl->value) 501 if (ctrl->value)
511 reg |= SAA7191_GAIN_COLO; 502 reg |= SAA7191_GAIN_COLO;
512 else 503 else
@@ -516,41 +507,41 @@ static int saa7191_set_control(struct i2c_client *client,
516 reg |= (ctrl->value << SAA7191_GAIN_LFIS_SHIFT) 507 reg |= (ctrl->value << SAA7191_GAIN_LFIS_SHIFT)
517 & SAA7191_GAIN_LFIS_MASK; 508 & SAA7191_GAIN_LFIS_MASK;
518 } 509 }
519 ret = saa7191_write_reg(client, SAA7191_REG_GAIN, reg); 510 ret = saa7191_write_reg(sd, SAA7191_REG_GAIN, reg);
520 break; 511 break;
521 case SAA7191_CONTROL_HUE: 512 case V4L2_CID_HUE:
522 reg = ctrl->value & 0xff; 513 reg = ctrl->value & 0xff;
523 if (reg < 0x80) 514 if (reg < 0x80)
524 reg += 0x80; 515 reg += 0x80;
525 else 516 else
526 reg -= 0x80; 517 reg -= 0x80;
527 ret = saa7191_write_reg(client, SAA7191_REG_HUEC, reg); 518 ret = saa7191_write_reg(sd, SAA7191_REG_HUEC, reg);
528 break; 519 break;
529 case SAA7191_CONTROL_VTRC: 520 case SAA7191_CONTROL_VTRC:
530 reg = saa7191_read_reg(client, SAA7191_REG_STDC); 521 reg = saa7191_read_reg(sd, SAA7191_REG_STDC);
531 if (ctrl->value) 522 if (ctrl->value)
532 reg |= SAA7191_STDC_VTRC; 523 reg |= SAA7191_STDC_VTRC;
533 else 524 else
534 reg &= ~SAA7191_STDC_VTRC; 525 reg &= ~SAA7191_STDC_VTRC;
535 ret = saa7191_write_reg(client, SAA7191_REG_STDC, reg); 526 ret = saa7191_write_reg(sd, SAA7191_REG_STDC, reg);
536 break; 527 break;
537 case SAA7191_CONTROL_LUMA_DELAY: { 528 case SAA7191_CONTROL_LUMA_DELAY: {
538 s32 value = ctrl->value; 529 s32 value = ctrl->value;
539 if (value < 0) 530 if (value < 0)
540 value += 8; 531 value += 8;
541 reg = saa7191_read_reg(client, SAA7191_REG_CTL3); 532 reg = saa7191_read_reg(sd, SAA7191_REG_CTL3);
542 reg &= ~SAA7191_CTL3_YDEL_MASK; 533 reg &= ~SAA7191_CTL3_YDEL_MASK;
543 reg |= (value << SAA7191_CTL3_YDEL_SHIFT) 534 reg |= (value << SAA7191_CTL3_YDEL_SHIFT)
544 & SAA7191_CTL3_YDEL_MASK; 535 & SAA7191_CTL3_YDEL_MASK;
545 ret = saa7191_write_reg(client, SAA7191_REG_CTL3, reg); 536 ret = saa7191_write_reg(sd, SAA7191_REG_CTL3, reg);
546 break; 537 break;
547 } 538 }
548 case SAA7191_CONTROL_VNR: 539 case SAA7191_CONTROL_VNR:
549 reg = saa7191_read_reg(client, SAA7191_REG_CTL4); 540 reg = saa7191_read_reg(sd, SAA7191_REG_CTL4);
550 reg &= ~SAA7191_CTL4_VNOI_MASK; 541 reg &= ~SAA7191_CTL4_VNOI_MASK;
551 reg |= (ctrl->value << SAA7191_CTL4_VNOI_SHIFT) 542 reg |= (ctrl->value << SAA7191_CTL4_VNOI_SHIFT)
552 & SAA7191_CTL4_VNOI_MASK; 543 & SAA7191_CTL4_VNOI_MASK;
553 ret = saa7191_write_reg(client, SAA7191_REG_CTL4, reg); 544 ret = saa7191_write_reg(sd, SAA7191_REG_CTL4, reg);
554 break; 545 break;
555 default: 546 default:
556 ret = -EINVAL; 547 ret = -EINVAL;
@@ -561,247 +552,108 @@ static int saa7191_set_control(struct i2c_client *client,
561 552
562/* I2C-interface */ 553/* I2C-interface */
563 554
564static int saa7191_attach(struct i2c_adapter *adap, int addr, int kind) 555static int saa7191_g_input_status(struct v4l2_subdev *sd, u32 *status)
565{ 556{
566 int err = 0; 557 u8 status_reg;
567 struct saa7191 *decoder; 558 int res = V4L2_IN_ST_NO_SIGNAL;
568 struct i2c_client *client;
569
570 printk(KERN_INFO "Philips SAA7191 driver version %s\n",
571 SAA7191_MODULE_VERSION);
572
573 client = kzalloc(sizeof(*client), GFP_KERNEL);
574 if (!client)
575 return -ENOMEM;
576 decoder = kzalloc(sizeof(*decoder), GFP_KERNEL);
577 if (!decoder) {
578 err = -ENOMEM;
579 goto out_free_client;
580 }
581
582 client->addr = addr;
583 client->adapter = adap;
584 client->driver = &i2c_driver_saa7191;
585 client->flags = 0;
586 strcpy(client->name, "saa7191 client");
587 i2c_set_clientdata(client, decoder);
588
589 decoder->client = client;
590
591 err = i2c_attach_client(client);
592 if (err)
593 goto out_free_decoder;
594
595 err = saa7191_write_block(client, sizeof(initseq), initseq);
596 if (err) {
597 printk(KERN_ERR "SAA7191 initialization failed\n");
598 goto out_detach_client;
599 }
600
601 printk(KERN_INFO "SAA7191 initialized\n");
602
603 decoder->input = SAA7191_INPUT_COMPOSITE;
604 decoder->norm = SAA7191_NORM_PAL;
605
606 err = saa7191_autodetect_norm(client);
607 if (err && (err != -EBUSY)) {
608 printk(KERN_ERR "SAA7191: Signal auto-detection failed\n");
609 }
610 559
560 if (saa7191_read_status(sd, &status_reg))
561 return -EIO;
562 if ((status_reg & SAA7191_STATUS_HLCK) == 0)
563 res = 0;
564 if (!(status_reg & SAA7191_STATUS_CODE))
565 res |= V4L2_IN_ST_NO_COLOR;
566 *status = res;
611 return 0; 567 return 0;
612
613out_detach_client:
614 i2c_detach_client(client);
615out_free_decoder:
616 kfree(decoder);
617out_free_client:
618 kfree(client);
619 return err;
620} 568}
621 569
622static int saa7191_probe(struct i2c_adapter *adap)
623{
624 /* Always connected to VINO */
625 if (adap->id == I2C_HW_SGI_VINO)
626 return saa7191_attach(adap, SAA7191_ADDR, 0);
627 /* Feel free to add probe here :-) */
628 return -ENODEV;
629}
630 570
631static int saa7191_detach(struct i2c_client *client) 571static int saa7191_g_chip_ident(struct v4l2_subdev *sd,
572 struct v4l2_dbg_chip_ident *chip)
632{ 573{
633 struct saa7191 *decoder = i2c_get_clientdata(client); 574 struct i2c_client *client = v4l2_get_subdevdata(sd);
634 575
635 i2c_detach_client(client); 576 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_SAA7191, 0);
636 kfree(decoder);
637 kfree(client);
638 return 0;
639} 577}
640 578
641static int saa7191_command(struct i2c_client *client, unsigned int cmd, 579/* ----------------------------------------------------------------------- */
642 void *arg)
643{
644 struct saa7191 *decoder = i2c_get_clientdata(client);
645 580
646 switch (cmd) { 581static const struct v4l2_subdev_core_ops saa7191_core_ops = {
647 case DECODER_GET_CAPABILITIES: { 582 .g_chip_ident = saa7191_g_chip_ident,
648 struct video_decoder_capability *cap = arg; 583 .g_ctrl = saa7191_g_ctrl,
584 .s_ctrl = saa7191_s_ctrl,
585};
649 586
650 cap->flags = VIDEO_DECODER_PAL | VIDEO_DECODER_NTSC | 587static const struct v4l2_subdev_tuner_ops saa7191_tuner_ops = {
651 VIDEO_DECODER_SECAM | VIDEO_DECODER_AUTO; 588 .s_std = saa7191_s_std,
652 cap->inputs = (client->adapter->id == I2C_HW_SGI_VINO) ? 2 : 1; 589};
653 cap->outputs = 1;
654 break;
655 }
656 case DECODER_GET_STATUS: {
657 int *iarg = arg;
658 u8 status;
659 int res = 0;
660 590
661 if (saa7191_read_status(client, &status)) { 591static const struct v4l2_subdev_video_ops saa7191_video_ops = {
662 return -EIO; 592 .s_routing = saa7191_s_routing,
663 } 593 .querystd = saa7191_querystd,
664 if ((status & SAA7191_STATUS_HLCK) == 0) 594 .g_input_status = saa7191_g_input_status,
665 res |= DECODER_STATUS_GOOD; 595};
666 if (status & SAA7191_STATUS_CODE)
667 res |= DECODER_STATUS_COLOR;
668 switch (decoder->norm) {
669 case SAA7191_NORM_NTSC:
670 res |= DECODER_STATUS_NTSC;
671 break;
672 case SAA7191_NORM_PAL:
673 res |= DECODER_STATUS_PAL;
674 break;
675 case SAA7191_NORM_SECAM:
676 res |= DECODER_STATUS_SECAM;
677 break;
678 case SAA7191_NORM_AUTO:
679 default:
680 if (status & SAA7191_STATUS_FIDT)
681 res |= DECODER_STATUS_NTSC;
682 else
683 res |= DECODER_STATUS_PAL;
684 break;
685 }
686 *iarg = res;
687 break;
688 }
689 case DECODER_SET_NORM: {
690 int *iarg = arg;
691
692 switch (*iarg) {
693 case VIDEO_MODE_AUTO:
694 return saa7191_autodetect_norm(client);
695 case VIDEO_MODE_PAL:
696 return saa7191_set_norm(client, SAA7191_NORM_PAL);
697 case VIDEO_MODE_NTSC:
698 return saa7191_set_norm(client, SAA7191_NORM_NTSC);
699 case VIDEO_MODE_SECAM:
700 return saa7191_set_norm(client, SAA7191_NORM_SECAM);
701 default:
702 return -EINVAL;
703 }
704 break;
705 }
706 case DECODER_SET_INPUT: {
707 int *iarg = arg;
708
709 switch (client->adapter->id) {
710 case I2C_HW_SGI_VINO:
711 return saa7191_set_input(client, *iarg);
712 default:
713 if (*iarg != 0)
714 return -EINVAL;
715 }
716 break;
717 }
718 case DECODER_SET_OUTPUT: {
719 int *iarg = arg;
720 596
721 /* not much choice of outputs */ 597static const struct v4l2_subdev_ops saa7191_ops = {
722 if (*iarg != 0) 598 .core = &saa7191_core_ops,
723 return -EINVAL; 599 .video = &saa7191_video_ops,
724 break; 600 .tuner = &saa7191_tuner_ops,
725 } 601};
726 case DECODER_ENABLE_OUTPUT: {
727 /* Always enabled */
728 break;
729 }
730 case DECODER_SET_PICTURE: {
731 struct video_picture *pic = arg;
732 unsigned val;
733 int err;
734 602
735 val = (pic->hue >> 8) - 0x80; 603static int saa7191_probe(struct i2c_client *client,
604 const struct i2c_device_id *id)
605{
606 int err = 0;
607 struct saa7191 *decoder;
608 struct v4l2_subdev *sd;
736 609
737 err = saa7191_write_reg(client, SAA7191_REG_HUEC, val); 610 v4l_info(client, "chip found @ 0x%x (%s)\n",
738 if (err) 611 client->addr << 1, client->adapter->name);
739 return -EIO;
740 612
741 break; 613 decoder = kzalloc(sizeof(*decoder), GFP_KERNEL);
742 } 614 if (!decoder)
743 case DECODER_SAA7191_GET_STATUS: { 615 return -ENOMEM;
744 struct saa7191_status *status = arg;
745 u8 status_reg;
746 616
747 if (saa7191_read_status(client, &status_reg)) 617 sd = &decoder->sd;
748 return -EIO; 618 v4l2_i2c_subdev_init(sd, client, &saa7191_ops);
749 619
750 status->signal = ((status_reg & SAA7191_STATUS_HLCK) == 0) 620 err = saa7191_write_block(sd, sizeof(initseq), initseq);
751 ? 1 : 0; 621 if (err) {
752 status->signal_60hz = (status_reg & SAA7191_STATUS_FIDT) 622 printk(KERN_ERR "SAA7191 initialization failed\n");
753 ? 1 : 0; 623 kfree(decoder);
754 status->color = (status_reg & SAA7191_STATUS_CODE) ? 1 : 0; 624 return err;
625 }
755 626
756 status->input = decoder->input; 627 printk(KERN_INFO "SAA7191 initialized\n");
757 status->norm = decoder->norm;
758 628
759 break; 629 decoder->input = SAA7191_INPUT_COMPOSITE;
760 } 630 decoder->norm = V4L2_STD_PAL;
761 case DECODER_SAA7191_SET_NORM: { 631
762 int *norm = arg; 632 err = saa7191_autodetect_norm(sd);
763 633 if (err && (err != -EBUSY))
764 switch (*norm) { 634 printk(KERN_ERR "SAA7191: Signal auto-detection failed\n");
765 case SAA7191_NORM_AUTO:
766 return saa7191_autodetect_norm(client);
767 case SAA7191_NORM_AUTO_EXT:
768 return saa7191_autodetect_norm_extended(client);
769 default:
770 return saa7191_set_norm(client, *norm);
771 }
772 }
773 case DECODER_SAA7191_GET_CONTROL: {
774 return saa7191_get_control(client, arg);
775 }
776 case DECODER_SAA7191_SET_CONTROL: {
777 return saa7191_set_control(client, arg);
778 }
779 default:
780 return -EINVAL;
781 }
782 635
783 return 0; 636 return 0;
784} 637}
785 638
786static struct i2c_driver i2c_driver_saa7191 = { 639static int saa7191_remove(struct i2c_client *client)
787 .driver = {
788 .name = "saa7191",
789 },
790 .id = I2C_DRIVERID_SAA7191,
791 .attach_adapter = saa7191_probe,
792 .detach_client = saa7191_detach,
793 .command = saa7191_command
794};
795
796static int saa7191_init(void)
797{ 640{
798 return i2c_add_driver(&i2c_driver_saa7191); 641 struct v4l2_subdev *sd = i2c_get_clientdata(client);
799}
800 642
801static void saa7191_exit(void) 643 v4l2_device_unregister_subdev(sd);
802{ 644 kfree(to_saa7191(sd));
803 i2c_del_driver(&i2c_driver_saa7191); 645 return 0;
804} 646}
805 647
806module_init(saa7191_init); 648static const struct i2c_device_id saa7191_id[] = {
807module_exit(saa7191_exit); 649 { "saa7191", 0 },
650 { }
651};
652MODULE_DEVICE_TABLE(i2c, saa7191_id);
653
654static struct v4l2_i2c_driver_data v4l2_i2c_data = {
655 .name = "saa7191",
656 .probe = saa7191_probe,
657 .remove = saa7191_remove,
658 .id_table = saa7191_id,
659};
diff --git a/drivers/media/video/saa7191.h b/drivers/media/video/saa7191.h
index a2310da1940d..803c74d6066f 100644
--- a/drivers/media/video/saa7191.h
+++ b/drivers/media/video/saa7191.h
@@ -176,11 +176,9 @@
176#define SAA7191_INPUT_COMPOSITE 0 176#define SAA7191_INPUT_COMPOSITE 0
177#define SAA7191_INPUT_SVIDEO 1 177#define SAA7191_INPUT_SVIDEO 1
178 178
179#define SAA7191_NORM_AUTO 0
180#define SAA7191_NORM_PAL 1 179#define SAA7191_NORM_PAL 1
181#define SAA7191_NORM_NTSC 2 180#define SAA7191_NORM_NTSC 2
182#define SAA7191_NORM_SECAM 3 181#define SAA7191_NORM_SECAM 3
183#define SAA7191_NORM_AUTO_EXT 4 /* extended auto-detection */
184 182
185struct saa7191_status { 183struct saa7191_status {
186 /* 0=no signal, 1=signal detected */ 184 /* 0=no signal, 1=signal detected */
@@ -232,24 +230,16 @@ struct saa7191_status {
232#define SAA7191_VNR_MAX 0x03 230#define SAA7191_VNR_MAX 0x03
233#define SAA7191_VNR_DEFAULT 0x00 231#define SAA7191_VNR_DEFAULT 0x00
234 232
235#define SAA7191_CONTROL_BANDPASS 0 233#define SAA7191_CONTROL_BANDPASS (V4L2_CID_PRIVATE_BASE + 0)
236#define SAA7191_CONTROL_BANDPASS_WEIGHT 1 234#define SAA7191_CONTROL_BANDPASS_WEIGHT (V4L2_CID_PRIVATE_BASE + 1)
237#define SAA7191_CONTROL_CORING 2 235#define SAA7191_CONTROL_CORING (V4L2_CID_PRIVATE_BASE + 2)
238#define SAA7191_CONTROL_FORCE_COLOUR 3 /* boolean */ 236#define SAA7191_CONTROL_FORCE_COLOUR (V4L2_CID_PRIVATE_BASE + 3)
239#define SAA7191_CONTROL_CHROMA_GAIN 4 237#define SAA7191_CONTROL_CHROMA_GAIN (V4L2_CID_PRIVATE_BASE + 4)
240#define SAA7191_CONTROL_HUE 5 238#define SAA7191_CONTROL_VTRC (V4L2_CID_PRIVATE_BASE + 5)
241#define SAA7191_CONTROL_VTRC 6 /* boolean */ 239#define SAA7191_CONTROL_LUMA_DELAY (V4L2_CID_PRIVATE_BASE + 6)
242#define SAA7191_CONTROL_LUMA_DELAY 7 240#define SAA7191_CONTROL_VNR (V4L2_CID_PRIVATE_BASE + 7)
243#define SAA7191_CONTROL_VNR 8
244
245struct saa7191_control {
246 u8 type;
247 s32 value;
248};
249 241
250#define DECODER_SAA7191_GET_STATUS _IOR('d', 195, struct saa7191_status) 242#define DECODER_SAA7191_GET_STATUS _IOR('d', 195, struct saa7191_status)
251#define DECODER_SAA7191_SET_NORM _IOW('d', 196, int) 243#define DECODER_SAA7191_SET_NORM _IOW('d', 196, int)
252#define DECODER_SAA7191_GET_CONTROL _IOR('d', 197, struct saa7191_control)
253#define DECODER_SAA7191_SET_CONTROL _IOW('d', 198, struct saa7191_control)
254 244
255#endif 245#endif
diff --git a/drivers/media/video/sh_mobile_ceu_camera.c b/drivers/media/video/sh_mobile_ceu_camera.c
index ddcb81d0b81a..b5e37a530c62 100644
--- a/drivers/media/video/sh_mobile_ceu_camera.c
+++ b/drivers/media/video/sh_mobile_ceu_camera.c
@@ -94,13 +94,37 @@ struct sh_mobile_ceu_dev {
94 spinlock_t lock; 94 spinlock_t lock;
95 struct list_head capture; 95 struct list_head capture;
96 struct videobuf_buffer *active; 96 struct videobuf_buffer *active;
97 int is_interlace; 97 int is_interlaced;
98 98
99 struct sh_mobile_ceu_info *pdata; 99 struct sh_mobile_ceu_info *pdata;
100 100
101 const struct soc_camera_data_format *camera_fmt; 101 const struct soc_camera_data_format *camera_fmt;
102}; 102};
103 103
104static unsigned long make_bus_param(struct sh_mobile_ceu_dev *pcdev)
105{
106 unsigned long flags;
107
108 flags = SOCAM_MASTER |
109 SOCAM_PCLK_SAMPLE_RISING |
110 SOCAM_HSYNC_ACTIVE_HIGH |
111 SOCAM_HSYNC_ACTIVE_LOW |
112 SOCAM_VSYNC_ACTIVE_HIGH |
113 SOCAM_VSYNC_ACTIVE_LOW |
114 SOCAM_DATA_ACTIVE_HIGH;
115
116 if (pcdev->pdata->flags & SH_CEU_FLAG_USE_8BIT_BUS)
117 flags |= SOCAM_DATAWIDTH_8;
118
119 if (pcdev->pdata->flags & SH_CEU_FLAG_USE_16BIT_BUS)
120 flags |= SOCAM_DATAWIDTH_16;
121
122 if (flags & SOCAM_DATAWIDTH_MASK)
123 return flags;
124
125 return 0;
126}
127
104static void ceu_write(struct sh_mobile_ceu_dev *priv, 128static void ceu_write(struct sh_mobile_ceu_dev *priv,
105 unsigned long reg_offs, u32 data) 129 unsigned long reg_offs, u32 data)
106{ 130{
@@ -150,6 +174,7 @@ static void free_buffer(struct videobuf_queue *vq,
150 if (in_interrupt()) 174 if (in_interrupt())
151 BUG(); 175 BUG();
152 176
177 videobuf_waiton(&buf->vb, 0, 0);
153 videobuf_dma_contig_free(vq, &buf->vb); 178 videobuf_dma_contig_free(vq, &buf->vb);
154 dev_dbg(&icd->dev, "%s freed\n", __func__); 179 dev_dbg(&icd->dev, "%s freed\n", __func__);
155 buf->vb.state = VIDEOBUF_NEEDS_INIT; 180 buf->vb.state = VIDEOBUF_NEEDS_INIT;
@@ -181,7 +206,7 @@ static void sh_mobile_ceu_capture(struct sh_mobile_ceu_dev *pcdev)
181 206
182 phys_addr_top = videobuf_to_dma_contig(pcdev->active); 207 phys_addr_top = videobuf_to_dma_contig(pcdev->active);
183 ceu_write(pcdev, CDAYR, phys_addr_top); 208 ceu_write(pcdev, CDAYR, phys_addr_top);
184 if (pcdev->is_interlace) { 209 if (pcdev->is_interlaced) {
185 phys_addr_bottom = phys_addr_top + icd->width; 210 phys_addr_bottom = phys_addr_top + icd->width;
186 ceu_write(pcdev, CDBYR, phys_addr_bottom); 211 ceu_write(pcdev, CDBYR, phys_addr_bottom);
187 } 212 }
@@ -193,7 +218,7 @@ static void sh_mobile_ceu_capture(struct sh_mobile_ceu_dev *pcdev)
193 case V4L2_PIX_FMT_NV61: 218 case V4L2_PIX_FMT_NV61:
194 phys_addr_top += icd->width * icd->height; 219 phys_addr_top += icd->width * icd->height;
195 ceu_write(pcdev, CDACR, phys_addr_top); 220 ceu_write(pcdev, CDACR, phys_addr_top);
196 if (pcdev->is_interlace) { 221 if (pcdev->is_interlaced) {
197 phys_addr_bottom = phys_addr_top + icd->width; 222 phys_addr_bottom = phys_addr_top + icd->width;
198 ceu_write(pcdev, CDBCR, phys_addr_bottom); 223 ceu_write(pcdev, CDBCR, phys_addr_bottom);
199 } 224 }
@@ -396,7 +421,7 @@ static int sh_mobile_ceu_set_bus_param(struct soc_camera_device *icd,
396 421
397 camera_flags = icd->ops->query_bus_param(icd); 422 camera_flags = icd->ops->query_bus_param(icd);
398 common_flags = soc_camera_bus_param_compatible(camera_flags, 423 common_flags = soc_camera_bus_param_compatible(camera_flags,
399 pcdev->pdata->flags); 424 make_bus_param(pcdev));
400 if (!common_flags) 425 if (!common_flags)
401 return -EINVAL; 426 return -EINVAL;
402 427
@@ -457,7 +482,7 @@ static int sh_mobile_ceu_set_bus_param(struct soc_camera_device *icd,
457 ceu_write(pcdev, CAMCR, value); 482 ceu_write(pcdev, CAMCR, value);
458 483
459 ceu_write(pcdev, CAPCR, 0x00300000); 484 ceu_write(pcdev, CAPCR, 0x00300000);
460 ceu_write(pcdev, CAIFR, (pcdev->is_interlace) ? 0x101 : 0); 485 ceu_write(pcdev, CAIFR, pcdev->is_interlaced ? 0x101 : 0);
461 486
462 mdelay(1); 487 mdelay(1);
463 488
@@ -473,7 +498,7 @@ static int sh_mobile_ceu_set_bus_param(struct soc_camera_device *icd,
473 } 498 }
474 499
475 height = icd->height; 500 height = icd->height;
476 if (pcdev->is_interlace) { 501 if (pcdev->is_interlaced) {
477 height /= 2; 502 height /= 2;
478 cdwdr_width *= 2; 503 cdwdr_width *= 2;
479 } 504 }
@@ -517,7 +542,7 @@ static int sh_mobile_ceu_try_bus_param(struct soc_camera_device *icd)
517 542
518 camera_flags = icd->ops->query_bus_param(icd); 543 camera_flags = icd->ops->query_bus_param(icd);
519 common_flags = soc_camera_bus_param_compatible(camera_flags, 544 common_flags = soc_camera_bus_param_compatible(camera_flags,
520 pcdev->pdata->flags); 545 make_bus_param(pcdev));
521 if (!common_flags) 546 if (!common_flags)
522 return -EINVAL; 547 return -EINVAL;
523 548
@@ -562,11 +587,29 @@ static int sh_mobile_ceu_get_formats(struct soc_camera_device *icd, int idx,
562 if (ret < 0) 587 if (ret < 0)
563 return 0; 588 return 0;
564 589
590 /* Beginning of a pass */
591 if (!idx)
592 icd->host_priv = NULL;
593
565 switch (icd->formats[idx].fourcc) { 594 switch (icd->formats[idx].fourcc) {
566 case V4L2_PIX_FMT_UYVY: 595 case V4L2_PIX_FMT_UYVY:
567 case V4L2_PIX_FMT_VYUY: 596 case V4L2_PIX_FMT_VYUY:
568 case V4L2_PIX_FMT_YUYV: 597 case V4L2_PIX_FMT_YUYV:
569 case V4L2_PIX_FMT_YVYU: 598 case V4L2_PIX_FMT_YVYU:
599 if (icd->host_priv)
600 goto add_single_format;
601
602 /*
603 * Our case is simple so far: for any of the above four camera
604 * formats we add all our four synthesized NV* formats, so,
605 * just marking the device with a single flag suffices. If
606 * the format generation rules are more complex, you would have
607 * to actually hang your already added / counted formats onto
608 * the host_priv pointer and check whether the format you're
609 * going to add now is already there.
610 */
611 icd->host_priv = (void *)sh_mobile_ceu_formats;
612
570 n = ARRAY_SIZE(sh_mobile_ceu_formats); 613 n = ARRAY_SIZE(sh_mobile_ceu_formats);
571 formats += n; 614 formats += n;
572 for (k = 0; xlate && k < n; k++) { 615 for (k = 0; xlate && k < n; k++) {
@@ -579,6 +622,7 @@ static int sh_mobile_ceu_get_formats(struct soc_camera_device *icd, int idx,
579 icd->formats[idx].name); 622 icd->formats[idx].name);
580 } 623 }
581 default: 624 default:
625add_single_format:
582 /* Generic pass-through */ 626 /* Generic pass-through */
583 formats++; 627 formats++;
584 if (xlate) { 628 if (xlate) {
@@ -595,24 +639,30 @@ static int sh_mobile_ceu_get_formats(struct soc_camera_device *icd, int idx,
595 return formats; 639 return formats;
596} 640}
597 641
642static int sh_mobile_ceu_set_crop(struct soc_camera_device *icd,
643 struct v4l2_rect *rect)
644{
645 return icd->ops->set_crop(icd, rect);
646}
647
598static int sh_mobile_ceu_set_fmt(struct soc_camera_device *icd, 648static int sh_mobile_ceu_set_fmt(struct soc_camera_device *icd,
599 __u32 pixfmt, struct v4l2_rect *rect) 649 struct v4l2_format *f)
600{ 650{
601 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); 651 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
602 struct sh_mobile_ceu_dev *pcdev = ici->priv; 652 struct sh_mobile_ceu_dev *pcdev = ici->priv;
653 __u32 pixfmt = f->fmt.pix.pixelformat;
603 const struct soc_camera_format_xlate *xlate; 654 const struct soc_camera_format_xlate *xlate;
655 struct v4l2_format cam_f = *f;
604 int ret; 656 int ret;
605 657
606 if (!pixfmt)
607 return icd->ops->set_fmt(icd, pixfmt, rect);
608
609 xlate = soc_camera_xlate_by_fourcc(icd, pixfmt); 658 xlate = soc_camera_xlate_by_fourcc(icd, pixfmt);
610 if (!xlate) { 659 if (!xlate) {
611 dev_warn(&ici->dev, "Format %x not found\n", pixfmt); 660 dev_warn(&ici->dev, "Format %x not found\n", pixfmt);
612 return -EINVAL; 661 return -EINVAL;
613 } 662 }
614 663
615 ret = icd->ops->set_fmt(icd, xlate->cam_fmt->fourcc, rect); 664 cam_f.fmt.pix.pixelformat = xlate->cam_fmt->fourcc;
665 ret = icd->ops->set_fmt(icd, &cam_f);
616 666
617 if (!ret) { 667 if (!ret) {
618 icd->buswidth = xlate->buswidth; 668 icd->buswidth = xlate->buswidth;
@@ -662,13 +712,13 @@ static int sh_mobile_ceu_try_fmt(struct soc_camera_device *icd,
662 712
663 switch (f->fmt.pix.field) { 713 switch (f->fmt.pix.field) {
664 case V4L2_FIELD_INTERLACED: 714 case V4L2_FIELD_INTERLACED:
665 pcdev->is_interlace = 1; 715 pcdev->is_interlaced = 1;
666 break; 716 break;
667 case V4L2_FIELD_ANY: 717 case V4L2_FIELD_ANY:
668 f->fmt.pix.field = V4L2_FIELD_NONE; 718 f->fmt.pix.field = V4L2_FIELD_NONE;
669 /* fall-through */ 719 /* fall-through */
670 case V4L2_FIELD_NONE: 720 case V4L2_FIELD_NONE:
671 pcdev->is_interlace = 0; 721 pcdev->is_interlaced = 0;
672 break; 722 break;
673 default: 723 default:
674 ret = -EINVAL; 724 ret = -EINVAL;
@@ -734,7 +784,8 @@ static void sh_mobile_ceu_init_videobuf(struct videobuf_queue *q,
734 &sh_mobile_ceu_videobuf_ops, 784 &sh_mobile_ceu_videobuf_ops,
735 &ici->dev, &pcdev->lock, 785 &ici->dev, &pcdev->lock,
736 V4L2_BUF_TYPE_VIDEO_CAPTURE, 786 V4L2_BUF_TYPE_VIDEO_CAPTURE,
737 V4L2_FIELD_ANY, 787 pcdev->is_interlaced ?
788 V4L2_FIELD_INTERLACED : V4L2_FIELD_NONE,
738 sizeof(struct sh_mobile_ceu_buffer), 789 sizeof(struct sh_mobile_ceu_buffer),
739 icd); 790 icd);
740} 791}
@@ -744,6 +795,7 @@ static struct soc_camera_host_ops sh_mobile_ceu_host_ops = {
744 .add = sh_mobile_ceu_add_device, 795 .add = sh_mobile_ceu_add_device,
745 .remove = sh_mobile_ceu_remove_device, 796 .remove = sh_mobile_ceu_remove_device,
746 .get_formats = sh_mobile_ceu_get_formats, 797 .get_formats = sh_mobile_ceu_get_formats,
798 .set_crop = sh_mobile_ceu_set_crop,
747 .set_fmt = sh_mobile_ceu_set_fmt, 799 .set_fmt = sh_mobile_ceu_set_fmt,
748 .try_fmt = sh_mobile_ceu_try_fmt, 800 .try_fmt = sh_mobile_ceu_try_fmt,
749 .reqbufs = sh_mobile_ceu_reqbufs, 801 .reqbufs = sh_mobile_ceu_reqbufs,
diff --git a/drivers/media/video/sn9c102/sn9c102_devtable.h b/drivers/media/video/sn9c102/sn9c102_devtable.h
index 8cb3457e778d..38a716020d7f 100644
--- a/drivers/media/video/sn9c102/sn9c102_devtable.h
+++ b/drivers/media/video/sn9c102/sn9c102_devtable.h
@@ -96,9 +96,7 @@ static const struct usb_device_id sn9c102_id_table[] = {
96#if !defined CONFIG_USB_GSPCA && !defined CONFIG_USB_GSPCA_MODULE 96#if !defined CONFIG_USB_GSPCA && !defined CONFIG_USB_GSPCA_MODULE
97 { SN9C102_USB_DEVICE(0x045e, 0x00f5, BRIDGE_SN9C105), }, 97 { SN9C102_USB_DEVICE(0x045e, 0x00f5, BRIDGE_SN9C105), },
98 { SN9C102_USB_DEVICE(0x045e, 0x00f7, BRIDGE_SN9C105), }, 98 { SN9C102_USB_DEVICE(0x045e, 0x00f7, BRIDGE_SN9C105), },
99#endif
100 { SN9C102_USB_DEVICE(0x0471, 0x0327, BRIDGE_SN9C105), }, 99 { SN9C102_USB_DEVICE(0x0471, 0x0327, BRIDGE_SN9C105), },
101#if !defined CONFIG_USB_GSPCA && !defined CONFIG_USB_GSPCA_MODULE
102 { SN9C102_USB_DEVICE(0x0471, 0x0328, BRIDGE_SN9C105), }, 100 { SN9C102_USB_DEVICE(0x0471, 0x0328, BRIDGE_SN9C105), },
103#endif 101#endif
104 { SN9C102_USB_DEVICE(0x0c45, 0x60c0, BRIDGE_SN9C105), }, 102 { SN9C102_USB_DEVICE(0x0c45, 0x60c0, BRIDGE_SN9C105), },
@@ -123,7 +121,9 @@ static const struct usb_device_id sn9c102_id_table[] = {
123 { SN9C102_USB_DEVICE(0x0c45, 0x613a, BRIDGE_SN9C120), }, 121 { SN9C102_USB_DEVICE(0x0c45, 0x613a, BRIDGE_SN9C120), },
124#endif 122#endif
125 { SN9C102_USB_DEVICE(0x0c45, 0x613b, BRIDGE_SN9C120), }, 123 { SN9C102_USB_DEVICE(0x0c45, 0x613b, BRIDGE_SN9C120), },
124#if !defined CONFIG_USB_GSPCA && !defined CONFIG_USB_GSPCA_MODULE
126 { SN9C102_USB_DEVICE(0x0c45, 0x613c, BRIDGE_SN9C120), }, 125 { SN9C102_USB_DEVICE(0x0c45, 0x613c, BRIDGE_SN9C120), },
126#endif
127 { SN9C102_USB_DEVICE(0x0c45, 0x613e, BRIDGE_SN9C120), }, 127 { SN9C102_USB_DEVICE(0x0c45, 0x613e, BRIDGE_SN9C120), },
128 { } 128 { }
129}; 129};
diff --git a/drivers/media/video/soc_camera.c b/drivers/media/video/soc_camera.c
index fcb05f06de8f..6d8bfd4d97e2 100644
--- a/drivers/media/video/soc_camera.c
+++ b/drivers/media/video/soc_camera.c
@@ -30,6 +30,10 @@
30#include <media/videobuf-core.h> 30#include <media/videobuf-core.h>
31#include <media/soc_camera.h> 31#include <media/soc_camera.h>
32 32
33/* Default to VGA resolution */
34#define DEFAULT_WIDTH 640
35#define DEFAULT_HEIGHT 480
36
33static LIST_HEAD(hosts); 37static LIST_HEAD(hosts);
34static LIST_HEAD(devices); 38static LIST_HEAD(devices);
35static DEFINE_MUTEX(list_lock); 39static DEFINE_MUTEX(list_lock);
@@ -256,6 +260,46 @@ static void soc_camera_free_user_formats(struct soc_camera_device *icd)
256 vfree(icd->user_formats); 260 vfree(icd->user_formats);
257} 261}
258 262
263/* Called with .vb_lock held */
264static int soc_camera_set_fmt(struct soc_camera_file *icf,
265 struct v4l2_format *f)
266{
267 struct soc_camera_device *icd = icf->icd;
268 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
269 struct v4l2_pix_format *pix = &f->fmt.pix;
270 int ret;
271
272 /* We always call try_fmt() before set_fmt() or set_crop() */
273 ret = ici->ops->try_fmt(icd, f);
274 if (ret < 0)
275 return ret;
276
277 ret = ici->ops->set_fmt(icd, f);
278 if (ret < 0) {
279 return ret;
280 } else if (!icd->current_fmt ||
281 icd->current_fmt->fourcc != pix->pixelformat) {
282 dev_err(&ici->dev,
283 "Host driver hasn't set up current format correctly!\n");
284 return -EINVAL;
285 }
286
287 icd->width = pix->width;
288 icd->height = pix->height;
289 icf->vb_vidq.field =
290 icd->field = pix->field;
291
292 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
293 dev_warn(&icd->dev, "Attention! Wrong buf-type %d\n",
294 f->type);
295
296 dev_dbg(&icd->dev, "set width: %d height: %d\n",
297 icd->width, icd->height);
298
299 /* set physical bus parameters */
300 return ici->ops->set_bus_param(icd, pix->pixelformat);
301}
302
259static int soc_camera_open(struct file *file) 303static int soc_camera_open(struct file *file)
260{ 304{
261 struct video_device *vdev; 305 struct video_device *vdev;
@@ -297,14 +341,28 @@ static int soc_camera_open(struct file *file)
297 341
298 /* Now we really have to activate the camera */ 342 /* Now we really have to activate the camera */
299 if (icd->use_count == 1) { 343 if (icd->use_count == 1) {
300 ret = soc_camera_init_user_formats(icd); 344 /* Restore parameters before the last close() per V4L2 API */
301 if (ret < 0) 345 struct v4l2_format f = {
302 goto eiufmt; 346 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
347 .fmt.pix = {
348 .width = icd->width,
349 .height = icd->height,
350 .field = icd->field,
351 .pixelformat = icd->current_fmt->fourcc,
352 .colorspace = icd->current_fmt->colorspace,
353 },
354 };
355
303 ret = ici->ops->add(icd); 356 ret = ici->ops->add(icd);
304 if (ret < 0) { 357 if (ret < 0) {
305 dev_err(&icd->dev, "Couldn't activate the camera: %d\n", ret); 358 dev_err(&icd->dev, "Couldn't activate the camera: %d\n", ret);
306 goto eiciadd; 359 goto eiciadd;
307 } 360 }
361
362 /* Try to configure with default parameters */
363 ret = soc_camera_set_fmt(icf, &f);
364 if (ret < 0)
365 goto esfmt;
308 } 366 }
309 367
310 mutex_unlock(&icd->video_lock); 368 mutex_unlock(&icd->video_lock);
@@ -316,10 +374,13 @@ static int soc_camera_open(struct file *file)
316 374
317 return 0; 375 return 0;
318 376
319 /* First two errors are entered with the .video_lock held */ 377 /*
378 * First three errors are entered with the .video_lock held
379 * and use_count == 1
380 */
381esfmt:
382 ici->ops->remove(icd);
320eiciadd: 383eiciadd:
321 soc_camera_free_user_formats(icd);
322eiufmt:
323 icd->use_count--; 384 icd->use_count--;
324 mutex_unlock(&icd->video_lock); 385 mutex_unlock(&icd->video_lock);
325 module_put(ici->ops->owner); 386 module_put(ici->ops->owner);
@@ -339,10 +400,9 @@ static int soc_camera_close(struct file *file)
339 400
340 mutex_lock(&icd->video_lock); 401 mutex_lock(&icd->video_lock);
341 icd->use_count--; 402 icd->use_count--;
342 if (!icd->use_count) { 403 if (!icd->use_count)
343 ici->ops->remove(icd); 404 ici->ops->remove(icd);
344 soc_camera_free_user_formats(icd); 405
345 }
346 mutex_unlock(&icd->video_lock); 406 mutex_unlock(&icd->video_lock);
347 407
348 module_put(icd->ops->owner); 408 module_put(icd->ops->owner);
@@ -415,18 +475,10 @@ static int soc_camera_s_fmt_vid_cap(struct file *file, void *priv,
415{ 475{
416 struct soc_camera_file *icf = file->private_data; 476 struct soc_camera_file *icf = file->private_data;
417 struct soc_camera_device *icd = icf->icd; 477 struct soc_camera_device *icd = icf->icd;
418 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
419 struct v4l2_pix_format *pix = &f->fmt.pix;
420 __u32 pixfmt = pix->pixelformat;
421 int ret; 478 int ret;
422 struct v4l2_rect rect;
423 479
424 WARN_ON(priv != file->private_data); 480 WARN_ON(priv != file->private_data);
425 481
426 ret = soc_camera_try_fmt_vid_cap(file, priv, f);
427 if (ret < 0)
428 return ret;
429
430 mutex_lock(&icf->vb_vidq.vb_lock); 482 mutex_lock(&icf->vb_vidq.vb_lock);
431 483
432 if (videobuf_queue_is_busy(&icf->vb_vidq)) { 484 if (videobuf_queue_is_busy(&icf->vb_vidq)) {
@@ -435,33 +487,7 @@ static int soc_camera_s_fmt_vid_cap(struct file *file, void *priv,
435 goto unlock; 487 goto unlock;
436 } 488 }
437 489
438 rect.left = icd->x_current; 490 ret = soc_camera_set_fmt(icf, f);
439 rect.top = icd->y_current;
440 rect.width = pix->width;
441 rect.height = pix->height;
442 ret = ici->ops->set_fmt(icd, pix->pixelformat, &rect);
443 if (ret < 0) {
444 goto unlock;
445 } else if (!icd->current_fmt ||
446 icd->current_fmt->fourcc != pixfmt) {
447 dev_err(&ici->dev,
448 "Host driver hasn't set up current format correctly!\n");
449 ret = -EINVAL;
450 goto unlock;
451 }
452
453 icd->width = rect.width;
454 icd->height = rect.height;
455 icf->vb_vidq.field = pix->field;
456 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
457 dev_warn(&icd->dev, "Attention! Wrong buf-type %d\n",
458 f->type);
459
460 dev_dbg(&icd->dev, "set width: %d height: %d\n",
461 icd->width, icd->height);
462
463 /* set physical bus parameters */
464 ret = ici->ops->set_bus_param(icd, pixfmt);
465 491
466unlock: 492unlock:
467 mutex_unlock(&icf->vb_vidq.vb_lock); 493 mutex_unlock(&icf->vb_vidq.vb_lock);
@@ -648,8 +674,8 @@ static int soc_camera_cropcap(struct file *file, void *fh,
648 a->bounds.height = icd->height_max; 674 a->bounds.height = icd->height_max;
649 a->defrect.left = icd->x_min; 675 a->defrect.left = icd->x_min;
650 a->defrect.top = icd->y_min; 676 a->defrect.top = icd->y_min;
651 a->defrect.width = 640; 677 a->defrect.width = DEFAULT_WIDTH;
652 a->defrect.height = 480; 678 a->defrect.height = DEFAULT_HEIGHT;
653 a->pixelaspect.numerator = 1; 679 a->pixelaspect.numerator = 1;
654 a->pixelaspect.denominator = 1; 680 a->pixelaspect.denominator = 1;
655 681
@@ -685,7 +711,7 @@ static int soc_camera_s_crop(struct file *file, void *fh,
685 /* Cropping is allowed during a running capture, guard consistency */ 711 /* Cropping is allowed during a running capture, guard consistency */
686 mutex_lock(&icf->vb_vidq.vb_lock); 712 mutex_lock(&icf->vb_vidq.vb_lock);
687 713
688 ret = ici->ops->set_fmt(icd, 0, &a->c); 714 ret = ici->ops->set_crop(icd, &a->c);
689 if (!ret) { 715 if (!ret) {
690 icd->width = a->c.width; 716 icd->width = a->c.width;
691 icd->height = a->c.height; 717 icd->height = a->c.height;
@@ -844,9 +870,18 @@ static int soc_camera_probe(struct device *dev)
844 qctrl = soc_camera_find_qctrl(icd->ops, V4L2_CID_EXPOSURE); 870 qctrl = soc_camera_find_qctrl(icd->ops, V4L2_CID_EXPOSURE);
845 icd->exposure = qctrl ? qctrl->default_value : 871 icd->exposure = qctrl ? qctrl->default_value :
846 (unsigned short)~0; 872 (unsigned short)~0;
873
874 ret = soc_camera_init_user_formats(icd);
875 if (ret < 0)
876 goto eiufmt;
877
878 icd->height = DEFAULT_HEIGHT;
879 icd->width = DEFAULT_WIDTH;
880 icd->field = V4L2_FIELD_ANY;
847 } 881 }
848 ici->ops->remove(icd);
849 882
883eiufmt:
884 ici->ops->remove(icd);
850eiadd: 885eiadd:
851 mutex_unlock(&icd->video_lock); 886 mutex_unlock(&icd->video_lock);
852 module_put(ici->ops->owner); 887 module_put(ici->ops->owner);
@@ -865,6 +900,8 @@ static int soc_camera_remove(struct device *dev)
865 if (icd->ops->remove) 900 if (icd->ops->remove)
866 icd->ops->remove(icd); 901 icd->ops->remove(icd);
867 902
903 soc_camera_free_user_formats(icd);
904
868 return 0; 905 return 0;
869} 906}
870 907
@@ -918,6 +955,7 @@ int soc_camera_host_register(struct soc_camera_host *ici)
918 if (!ici || !ici->ops || 955 if (!ici || !ici->ops ||
919 !ici->ops->try_fmt || 956 !ici->ops->try_fmt ||
920 !ici->ops->set_fmt || 957 !ici->ops->set_fmt ||
958 !ici->ops->set_crop ||
921 !ici->ops->set_bus_param || 959 !ici->ops->set_bus_param ||
922 !ici->ops->querycap || 960 !ici->ops->querycap ||
923 !ici->ops->init_videobuf || 961 !ici->ops->init_videobuf ||
@@ -998,6 +1036,7 @@ int soc_camera_device_register(struct soc_camera_device *icd)
998 !icd->ops->release || 1036 !icd->ops->release ||
999 !icd->ops->start_capture || 1037 !icd->ops->start_capture ||
1000 !icd->ops->stop_capture || 1038 !icd->ops->stop_capture ||
1039 !icd->ops->set_crop ||
1001 !icd->ops->set_fmt || 1040 !icd->ops->set_fmt ||
1002 !icd->ops->try_fmt || 1041 !icd->ops->try_fmt ||
1003 !icd->ops->query_bus_param || 1042 !icd->ops->query_bus_param ||
diff --git a/drivers/media/video/soc_camera_platform.c b/drivers/media/video/soc_camera_platform.c
index 013ab06e3180..c48676356ab7 100644
--- a/drivers/media/video/soc_camera_platform.c
+++ b/drivers/media/video/soc_camera_platform.c
@@ -79,8 +79,14 @@ soc_camera_platform_query_bus_param(struct soc_camera_device *icd)
79 return p->bus_param; 79 return p->bus_param;
80} 80}
81 81
82static int soc_camera_platform_set_crop(struct soc_camera_device *icd,
83 struct v4l2_rect *rect)
84{
85 return 0;
86}
87
82static int soc_camera_platform_set_fmt(struct soc_camera_device *icd, 88static int soc_camera_platform_set_fmt(struct soc_camera_device *icd,
83 __u32 pixfmt, struct v4l2_rect *rect) 89 struct v4l2_format *f)
84{ 90{
85 return 0; 91 return 0;
86} 92}
@@ -125,6 +131,7 @@ static struct soc_camera_ops soc_camera_platform_ops = {
125 .release = soc_camera_platform_release, 131 .release = soc_camera_platform_release,
126 .start_capture = soc_camera_platform_start_capture, 132 .start_capture = soc_camera_platform_start_capture,
127 .stop_capture = soc_camera_platform_stop_capture, 133 .stop_capture = soc_camera_platform_stop_capture,
134 .set_crop = soc_camera_platform_set_crop,
128 .set_fmt = soc_camera_platform_set_fmt, 135 .set_fmt = soc_camera_platform_set_fmt,
129 .try_fmt = soc_camera_platform_try_fmt, 136 .try_fmt = soc_camera_platform_try_fmt,
130 .set_bus_param = soc_camera_platform_set_bus_param, 137 .set_bus_param = soc_camera_platform_set_bus_param,
diff --git a/drivers/media/video/stk-webcam.c b/drivers/media/video/stk-webcam.c
index 26378cf390fc..1a6d39cbd6f3 100644
--- a/drivers/media/video/stk-webcam.c
+++ b/drivers/media/video/stk-webcam.c
@@ -933,8 +933,6 @@ static int stk_vidioc_s_ctrl(struct file *filp,
933static int stk_vidioc_enum_fmt_vid_cap(struct file *filp, 933static int stk_vidioc_enum_fmt_vid_cap(struct file *filp,
934 void *priv, struct v4l2_fmtdesc *fmtd) 934 void *priv, struct v4l2_fmtdesc *fmtd)
935{ 935{
936 fmtd->flags = 0;
937
938 switch (fmtd->index) { 936 switch (fmtd->index) {
939 case 0: 937 case 0:
940 fmtd->pixelformat = V4L2_PIX_FMT_RGB565; 938 fmtd->pixelformat = V4L2_PIX_FMT_RGB565;
@@ -992,7 +990,6 @@ static int stk_vidioc_g_fmt_vid_cap(struct file *filp,
992 pix_format->height = stk_sizes[i].h; 990 pix_format->height = stk_sizes[i].h;
993 pix_format->field = V4L2_FIELD_NONE; 991 pix_format->field = V4L2_FIELD_NONE;
994 pix_format->colorspace = V4L2_COLORSPACE_SRGB; 992 pix_format->colorspace = V4L2_COLORSPACE_SRGB;
995 pix_format->priv = 0;
996 pix_format->pixelformat = dev->vsettings.palette; 993 pix_format->pixelformat = dev->vsettings.palette;
997 if (dev->vsettings.palette == V4L2_PIX_FMT_SBGGR8) 994 if (dev->vsettings.palette == V4L2_PIX_FMT_SBGGR8)
998 pix_format->bytesperline = pix_format->width; 995 pix_format->bytesperline = pix_format->width;
@@ -1115,8 +1112,6 @@ static int stk_vidioc_reqbufs(struct file *filp,
1115 1112
1116 if (dev == NULL) 1113 if (dev == NULL)
1117 return -ENODEV; 1114 return -ENODEV;
1118 if (rb->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1119 return -EINVAL;
1120 if (rb->memory != V4L2_MEMORY_MMAP) 1115 if (rb->memory != V4L2_MEMORY_MMAP)
1121 return -EINVAL; 1116 return -EINVAL;
1122 if (is_streaming(dev) 1117 if (is_streaming(dev)
@@ -1139,16 +1134,10 @@ static int stk_vidioc_reqbufs(struct file *filp,
1139static int stk_vidioc_querybuf(struct file *filp, 1134static int stk_vidioc_querybuf(struct file *filp,
1140 void *priv, struct v4l2_buffer *buf) 1135 void *priv, struct v4l2_buffer *buf)
1141{ 1136{
1142 int index;
1143 struct stk_camera *dev = priv; 1137 struct stk_camera *dev = priv;
1144 struct stk_sio_buffer *sbuf; 1138 struct stk_sio_buffer *sbuf;
1145 1139
1146 if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 1140 if (buf->index < 0 || buf->index >= dev->n_sbufs)
1147 return -EINVAL;
1148
1149 index = buf->index;
1150
1151 if (index < 0 || index >= dev->n_sbufs)
1152 return -EINVAL; 1141 return -EINVAL;
1153 sbuf = dev->sio_bufs + buf->index; 1142 sbuf = dev->sio_bufs + buf->index;
1154 *buf = sbuf->v4lbuf; 1143 *buf = sbuf->v4lbuf;
@@ -1161,8 +1150,6 @@ static int stk_vidioc_qbuf(struct file *filp,
1161 struct stk_camera *dev = priv; 1150 struct stk_camera *dev = priv;
1162 struct stk_sio_buffer *sbuf; 1151 struct stk_sio_buffer *sbuf;
1163 unsigned long flags; 1152 unsigned long flags;
1164 if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1165 return -EINVAL;
1166 1153
1167 if (buf->memory != V4L2_MEMORY_MMAP) 1154 if (buf->memory != V4L2_MEMORY_MMAP)
1168 return -EINVAL; 1155 return -EINVAL;
@@ -1189,8 +1176,7 @@ static int stk_vidioc_dqbuf(struct file *filp,
1189 unsigned long flags; 1176 unsigned long flags;
1190 int ret; 1177 int ret;
1191 1178
1192 if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE 1179 if (!is_streaming(dev))
1193 || !is_streaming(dev))
1194 return -EINVAL; 1180 return -EINVAL;
1195 1181
1196 if (filp->f_flags & O_NONBLOCK && list_empty(&dev->sio_full)) 1182 if (filp->f_flags & O_NONBLOCK && list_empty(&dev->sio_full))
@@ -1249,16 +1235,10 @@ static int stk_vidioc_streamoff(struct file *filp,
1249static int stk_vidioc_g_parm(struct file *filp, 1235static int stk_vidioc_g_parm(struct file *filp,
1250 void *priv, struct v4l2_streamparm *sp) 1236 void *priv, struct v4l2_streamparm *sp)
1251{ 1237{
1252 if (sp->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1253 return -EINVAL;
1254
1255 sp->parm.capture.capability = 0;
1256 sp->parm.capture.capturemode = 0;
1257 /*FIXME This is not correct */ 1238 /*FIXME This is not correct */
1258 sp->parm.capture.timeperframe.numerator = 1; 1239 sp->parm.capture.timeperframe.numerator = 1;
1259 sp->parm.capture.timeperframe.denominator = 30; 1240 sp->parm.capture.timeperframe.denominator = 30;
1260 sp->parm.capture.readbuffers = 2; 1241 sp->parm.capture.readbuffers = 2;
1261 sp->parm.capture.extendedmode = 0;
1262 return 0; 1242 return 0;
1263} 1243}
1264 1244
diff --git a/drivers/media/video/tcm825x.c b/drivers/media/video/tcm825x.c
index 29991d1cf13e..b30c49248217 100644
--- a/drivers/media/video/tcm825x.c
+++ b/drivers/media/video/tcm825x.c
@@ -50,7 +50,7 @@ struct tcm825x_sensor {
50}; 50};
51 51
52/* list of image formats supported by TCM825X sensor */ 52/* list of image formats supported by TCM825X sensor */
53const static struct v4l2_fmtdesc tcm825x_formats[] = { 53static const struct v4l2_fmtdesc tcm825x_formats[] = {
54 { 54 {
55 .description = "YUYV (YUV 4:2:2), packed", 55 .description = "YUYV (YUV 4:2:2), packed",
56 .pixelformat = V4L2_PIX_FMT_UYVY, 56 .pixelformat = V4L2_PIX_FMT_UYVY,
@@ -76,15 +76,15 @@ const static struct v4l2_fmtdesc tcm825x_formats[] = {
76 * TCM825X register configuration for all combinations of pixel format and 76 * TCM825X register configuration for all combinations of pixel format and
77 * image size 77 * image size
78 */ 78 */
79const static struct tcm825x_reg subqcif = { 0x20, TCM825X_PICSIZ }; 79static const struct tcm825x_reg subqcif = { 0x20, TCM825X_PICSIZ };
80const static struct tcm825x_reg qcif = { 0x18, TCM825X_PICSIZ }; 80static const struct tcm825x_reg qcif = { 0x18, TCM825X_PICSIZ };
81const static struct tcm825x_reg cif = { 0x14, TCM825X_PICSIZ }; 81static const struct tcm825x_reg cif = { 0x14, TCM825X_PICSIZ };
82const static struct tcm825x_reg qqvga = { 0x0c, TCM825X_PICSIZ }; 82static const struct tcm825x_reg qqvga = { 0x0c, TCM825X_PICSIZ };
83const static struct tcm825x_reg qvga = { 0x04, TCM825X_PICSIZ }; 83static const struct tcm825x_reg qvga = { 0x04, TCM825X_PICSIZ };
84const static struct tcm825x_reg vga = { 0x00, TCM825X_PICSIZ }; 84static const struct tcm825x_reg vga = { 0x00, TCM825X_PICSIZ };
85 85
86const static struct tcm825x_reg yuv422 = { 0x00, TCM825X_PICFMT }; 86static const struct tcm825x_reg yuv422 = { 0x00, TCM825X_PICFMT };
87const static struct tcm825x_reg rgb565 = { 0x02, TCM825X_PICFMT }; 87static const struct tcm825x_reg rgb565 = { 0x02, TCM825X_PICFMT };
88 88
89/* Our own specific controls */ 89/* Our own specific controls */
90#define V4L2_CID_ALC V4L2_CID_PRIVATE_BASE 90#define V4L2_CID_ALC V4L2_CID_PRIVATE_BASE
@@ -248,10 +248,10 @@ static struct vcontrol {
248}; 248};
249 249
250 250
251const static struct tcm825x_reg *tcm825x_siz_reg[NUM_IMAGE_SIZES] = 251static const struct tcm825x_reg *tcm825x_siz_reg[NUM_IMAGE_SIZES] =
252{ &subqcif, &qqvga, &qcif, &qvga, &cif, &vga }; 252{ &subqcif, &qqvga, &qcif, &qvga, &cif, &vga };
253 253
254const static struct tcm825x_reg *tcm825x_fmt_reg[NUM_PIXEL_FORMATS] = 254static const struct tcm825x_reg *tcm825x_fmt_reg[NUM_PIXEL_FORMATS] =
255{ &yuv422, &rgb565 }; 255{ &yuv422, &rgb565 };
256 256
257/* 257/*
diff --git a/drivers/media/video/tcm825x.h b/drivers/media/video/tcm825x.h
index 770ebacfa344..5b7e69682368 100644
--- a/drivers/media/video/tcm825x.h
+++ b/drivers/media/video/tcm825x.h
@@ -188,7 +188,7 @@ struct tcm825x_platform_data {
188/* Array of image sizes supported by TCM825X. These must be ordered from 188/* Array of image sizes supported by TCM825X. These must be ordered from
189 * smallest image size to largest. 189 * smallest image size to largest.
190 */ 190 */
191const static struct capture_size tcm825x_sizes[] = { 191static const struct capture_size tcm825x_sizes[] = {
192 { 128, 96 }, /* subQCIF */ 192 { 128, 96 }, /* subQCIF */
193 { 160, 120 }, /* QQVGA */ 193 { 160, 120 }, /* QQVGA */
194 { 176, 144 }, /* QCIF */ 194 { 176, 144 }, /* QCIF */
diff --git a/drivers/media/video/tda7432.c b/drivers/media/video/tda7432.c
index 0c020585fffb..005f8a468031 100644
--- a/drivers/media/video/tda7432.c
+++ b/drivers/media/video/tda7432.c
@@ -50,7 +50,7 @@
50#include <media/v4l2-device.h> 50#include <media/v4l2-device.h>
51#include <media/v4l2-ioctl.h> 51#include <media/v4l2-ioctl.h>
52#include <media/i2c-addr.h> 52#include <media/i2c-addr.h>
53#include <media/v4l2-i2c-drv-legacy.h> 53#include <media/v4l2-i2c-drv.h>
54 54
55#ifndef VIDEO_AUDIO_BALANCE 55#ifndef VIDEO_AUDIO_BALANCE
56# define VIDEO_AUDIO_BALANCE 32 56# define VIDEO_AUDIO_BALANCE 32
@@ -69,13 +69,6 @@ MODULE_PARM_DESC(maxvol,"Set maximium volume to +20db (0), default is 0db(1)");
69module_param(maxvol, int, S_IRUGO | S_IWUSR); 69module_param(maxvol, int, S_IRUGO | S_IWUSR);
70 70
71 71
72/* Address to scan (I2C address of this chip) */
73static unsigned short normal_i2c[] = {
74 I2C_ADDR_TDA7432 >> 1,
75 I2C_CLIENT_END,
76};
77
78I2C_CLIENT_INSMOD;
79 72
80/* Structure of address and subaddresses for the tda7432 */ 73/* Structure of address and subaddresses for the tda7432 */
81 74
@@ -421,21 +414,18 @@ static int tda7432_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
421static int tda7432_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc) 414static int tda7432_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc)
422{ 415{
423 switch (qc->id) { 416 switch (qc->id) {
424 case V4L2_CID_AUDIO_MUTE:
425 case V4L2_CID_AUDIO_VOLUME: 417 case V4L2_CID_AUDIO_VOLUME:
418 return v4l2_ctrl_query_fill(qc, 0, 65535, 65535 / 100, 58880);
419 case V4L2_CID_AUDIO_MUTE:
420 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 0);
426 case V4L2_CID_AUDIO_BALANCE: 421 case V4L2_CID_AUDIO_BALANCE:
427 case V4L2_CID_AUDIO_BASS: 422 case V4L2_CID_AUDIO_BASS:
428 case V4L2_CID_AUDIO_TREBLE: 423 case V4L2_CID_AUDIO_TREBLE:
429 return v4l2_ctrl_query_fill_std(qc); 424 return v4l2_ctrl_query_fill(qc, 0, 65535, 65535 / 100, 32768);
430 } 425 }
431 return -EINVAL; 426 return -EINVAL;
432} 427}
433 428
434static int tda7432_command(struct i2c_client *client, unsigned cmd, void *arg)
435{
436 return v4l2_subdev_command(i2c_get_clientdata(client), cmd, arg);
437}
438
439/* ----------------------------------------------------------------------- */ 429/* ----------------------------------------------------------------------- */
440 430
441static const struct v4l2_subdev_core_ops tda7432_core_ops = { 431static const struct v4l2_subdev_core_ops tda7432_core_ops = {
@@ -498,8 +488,6 @@ MODULE_DEVICE_TABLE(i2c, tda7432_id);
498 488
499static struct v4l2_i2c_driver_data v4l2_i2c_data = { 489static struct v4l2_i2c_driver_data v4l2_i2c_data = {
500 .name = "tda7432", 490 .name = "tda7432",
501 .driverid = I2C_DRIVERID_TDA7432,
502 .command = tda7432_command,
503 .probe = tda7432_probe, 491 .probe = tda7432_probe,
504 .remove = tda7432_remove, 492 .remove = tda7432_remove,
505 .id_table = tda7432_id, 493 .id_table = tda7432_id,
diff --git a/drivers/media/video/tda9840.c b/drivers/media/video/tda9840.c
index 6afb7059502d..fe1158094c24 100644
--- a/drivers/media/video/tda9840.c
+++ b/drivers/media/video/tda9840.c
@@ -30,8 +30,8 @@
30#include <linux/ioctl.h> 30#include <linux/ioctl.h>
31#include <linux/i2c.h> 31#include <linux/i2c.h>
32#include <media/v4l2-device.h> 32#include <media/v4l2-device.h>
33#include <media/v4l2-i2c-drv-legacy.h> 33#include <media/v4l2-chip-ident.h>
34#include "tda9840.h" 34#include <media/v4l2-i2c-drv.h>
35 35
36MODULE_AUTHOR("Michael Hunold <michael@mihu.de>"); 36MODULE_AUTHOR("Michael Hunold <michael@mihu.de>");
37MODULE_DESCRIPTION("tda9840 driver"); 37MODULE_DESCRIPTION("tda9840 driver");
@@ -56,11 +56,6 @@ MODULE_PARM_DESC(debug, "Debug level (0-1)");
56#define TDA9840_SET_BOTH_R 0x16 56#define TDA9840_SET_BOTH_R 0x16
57#define TDA9840_SET_EXTERNAL 0x7a 57#define TDA9840_SET_EXTERNAL 0x7a
58 58
59/* addresses to scan, found only at 0x42 (7-Bit) */
60static unsigned short normal_i2c[] = { I2C_ADDR_TDA9840, I2C_CLIENT_END };
61
62/* magic definition of all other variables and things */
63I2C_CLIENT_INSMOD;
64 59
65static void tda9840_write(struct v4l2_subdev *sd, u8 reg, u8 val) 60static void tda9840_write(struct v4l2_subdev *sd, u8 reg, u8 val)
66{ 61{
@@ -137,60 +132,17 @@ static int tda9840_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *t)
137 return 0; 132 return 0;
138} 133}
139 134
140static long tda9840_ioctl(struct v4l2_subdev *sd, unsigned cmd, void *arg) 135static int tda9840_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
141{ 136{
142 int byte; 137 struct i2c_client *client = v4l2_get_subdevdata(sd);
143
144 switch (cmd) {
145 case TDA9840_LEVEL_ADJUST:
146 byte = *(int *)arg;
147 v4l2_dbg(1, debug, sd, "TDA9840_LEVEL_ADJUST: %d\n", byte);
148
149 /* check for correct range */
150 if (byte > 25 || byte < -20)
151 return -EINVAL;
152
153 /* calculate actual value to set, see specs, page 18 */
154 byte /= 5;
155 if (0 < byte)
156 byte += 0x8;
157 else
158 byte = -byte;
159 tda9840_write(sd, LEVEL_ADJUST, byte);
160 break;
161
162 case TDA9840_STEREO_ADJUST:
163 byte = *(int *)arg;
164 v4l2_dbg(1, debug, sd, "TDA9840_STEREO_ADJUST: %d\n", byte);
165
166 /* check for correct range */
167 if (byte > 25 || byte < -24)
168 return -EINVAL;
169
170 /* calculate actual value to set */
171 byte /= 5;
172 if (0 < byte)
173 byte += 0x20;
174 else
175 byte = -byte;
176
177 tda9840_write(sd, STEREO_ADJUST, byte);
178 break;
179 default:
180 return -ENOIOCTLCMD;
181 }
182 return 0;
183}
184 138
185static int tda9840_command(struct i2c_client *client, unsigned cmd, void *arg) 139 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_TDA9840, 0);
186{
187 return v4l2_subdev_command(i2c_get_clientdata(client), cmd, arg);
188} 140}
189 141
190/* ----------------------------------------------------------------------- */ 142/* ----------------------------------------------------------------------- */
191 143
192static const struct v4l2_subdev_core_ops tda9840_core_ops = { 144static const struct v4l2_subdev_core_ops tda9840_core_ops = {
193 .ioctl = tda9840_ioctl, 145 .g_chip_ident = tda9840_g_chip_ident,
194}; 146};
195 147
196static const struct v4l2_subdev_tuner_ops tda9840_tuner_ops = { 148static const struct v4l2_subdev_tuner_ops tda9840_tuner_ops = {
@@ -209,8 +161,6 @@ static int tda9840_probe(struct i2c_client *client,
209 const struct i2c_device_id *id) 161 const struct i2c_device_id *id)
210{ 162{
211 struct v4l2_subdev *sd; 163 struct v4l2_subdev *sd;
212 int result;
213 int byte;
214 164
215 /* let's see whether this adapter can support what we need */ 165 /* let's see whether this adapter can support what we need */
216 if (!i2c_check_functionality(client->adapter, 166 if (!i2c_check_functionality(client->adapter,
@@ -227,15 +177,9 @@ static int tda9840_probe(struct i2c_client *client,
227 v4l2_i2c_subdev_init(sd, client, &tda9840_ops); 177 v4l2_i2c_subdev_init(sd, client, &tda9840_ops);
228 178
229 /* set initial values for level & stereo - adjustment, mode */ 179 /* set initial values for level & stereo - adjustment, mode */
230 byte = 0; 180 tda9840_write(sd, LEVEL_ADJUST, 0);
231 result = tda9840_ioctl(sd, TDA9840_LEVEL_ADJUST, &byte); 181 tda9840_write(sd, STEREO_ADJUST, 0);
232 result |= tda9840_ioctl(sd, TDA9840_STEREO_ADJUST, &byte);
233 tda9840_write(sd, SWITCH, TDA9840_SET_STEREO); 182 tda9840_write(sd, SWITCH, TDA9840_SET_STEREO);
234 if (result) {
235 v4l2_dbg(1, debug, sd, "could not initialize tda9840\n");
236 kfree(sd);
237 return -ENODEV;
238 }
239 return 0; 183 return 0;
240} 184}
241 185
@@ -248,12 +192,7 @@ static int tda9840_remove(struct i2c_client *client)
248 return 0; 192 return 0;
249} 193}
250 194
251static int tda9840_legacy_probe(struct i2c_adapter *adapter) 195
252{
253 /* Let's see whether this is a known adapter we can attach to.
254 Prevents conflicts with tvaudio.c. */
255 return adapter->id == I2C_HW_SAA7146;
256}
257static const struct i2c_device_id tda9840_id[] = { 196static const struct i2c_device_id tda9840_id[] = {
258 { "tda9840", 0 }, 197 { "tda9840", 0 },
259 { } 198 { }
@@ -262,10 +201,7 @@ MODULE_DEVICE_TABLE(i2c, tda9840_id);
262 201
263static struct v4l2_i2c_driver_data v4l2_i2c_data = { 202static struct v4l2_i2c_driver_data v4l2_i2c_data = {
264 .name = "tda9840", 203 .name = "tda9840",
265 .driverid = I2C_DRIVERID_TDA9840,
266 .command = tda9840_command,
267 .probe = tda9840_probe, 204 .probe = tda9840_probe,
268 .remove = tda9840_remove, 205 .remove = tda9840_remove,
269 .legacy_probe = tda9840_legacy_probe,
270 .id_table = tda9840_id, 206 .id_table = tda9840_id,
271}; 207};
diff --git a/drivers/media/video/tda9840.h b/drivers/media/video/tda9840.h
deleted file mode 100644
index dc12ae7caf6f..000000000000
--- a/drivers/media/video/tda9840.h
+++ /dev/null
@@ -1,14 +0,0 @@
1#ifndef __INCLUDED_TDA9840__
2#define __INCLUDED_TDA9840__
3
4#define I2C_ADDR_TDA9840 0x42
5
6/* values may range between +2.5 and -2.0;
7 the value has to be multiplied with 10 */
8#define TDA9840_LEVEL_ADJUST _IOW('v',3,int)
9
10/* values may range between +2.5 and -2.4;
11 the value has to be multiplied with 10 */
12#define TDA9840_STEREO_ADJUST _IOW('v',4,int)
13
14#endif
diff --git a/drivers/media/video/tda9875.c b/drivers/media/video/tda9875.c
index 00c6cbe06ab0..24e2b7d2ae58 100644
--- a/drivers/media/video/tda9875.c
+++ b/drivers/media/video/tda9875.c
@@ -28,20 +28,13 @@
28#include <linux/i2c.h> 28#include <linux/i2c.h>
29#include <linux/videodev2.h> 29#include <linux/videodev2.h>
30#include <media/v4l2-device.h> 30#include <media/v4l2-device.h>
31#include <media/v4l2-i2c-drv-legacy.h> 31#include <media/v4l2-i2c-drv.h>
32#include <media/i2c-addr.h> 32#include <media/i2c-addr.h>
33 33
34static int debug; /* insmod parameter */ 34static int debug; /* insmod parameter */
35module_param(debug, int, S_IRUGO | S_IWUSR); 35module_param(debug, int, S_IRUGO | S_IWUSR);
36MODULE_LICENSE("GPL"); 36MODULE_LICENSE("GPL");
37 37
38/* Addresses to scan */
39static unsigned short normal_i2c[] = {
40 I2C_ADDR_TDA9875 >> 1,
41 I2C_CLIENT_END
42};
43
44I2C_CLIENT_INSMOD;
45 38
46/* This is a superset of the TDA9875 */ 39/* This is a superset of the TDA9875 */
47struct tda9875 { 40struct tda9875 {
@@ -313,18 +306,14 @@ static int tda9875_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc)
313{ 306{
314 switch (qc->id) { 307 switch (qc->id) {
315 case V4L2_CID_AUDIO_VOLUME: 308 case V4L2_CID_AUDIO_VOLUME:
309 return v4l2_ctrl_query_fill(qc, 0, 65535, 65535 / 100, 58880);
316 case V4L2_CID_AUDIO_BASS: 310 case V4L2_CID_AUDIO_BASS:
317 case V4L2_CID_AUDIO_TREBLE: 311 case V4L2_CID_AUDIO_TREBLE:
318 return v4l2_ctrl_query_fill_std(qc); 312 return v4l2_ctrl_query_fill(qc, 0, 65535, 65535 / 100, 32768);
319 } 313 }
320 return -EINVAL; 314 return -EINVAL;
321} 315}
322 316
323static int tda9875_command(struct i2c_client *client, unsigned cmd, void *arg)
324{
325 return v4l2_subdev_command(i2c_get_clientdata(client), cmd, arg);
326}
327
328/* ----------------------------------------------------------------------- */ 317/* ----------------------------------------------------------------------- */
329 318
330static const struct v4l2_subdev_core_ops tda9875_core_ops = { 319static const struct v4l2_subdev_core_ops tda9875_core_ops = {
@@ -401,8 +390,6 @@ MODULE_DEVICE_TABLE(i2c, tda9875_id);
401 390
402static struct v4l2_i2c_driver_data v4l2_i2c_data = { 391static struct v4l2_i2c_driver_data v4l2_i2c_data = {
403 .name = "tda9875", 392 .name = "tda9875",
404 .driverid = I2C_DRIVERID_TDA9875,
405 .command = tda9875_command,
406 .probe = tda9875_probe, 393 .probe = tda9875_probe,
407 .remove = tda9875_remove, 394 .remove = tda9875_remove,
408 .id_table = tda9875_id, 395 .id_table = tda9875_id,
diff --git a/drivers/media/video/tea6415c.c b/drivers/media/video/tea6415c.c
index 7519fd1f57ef..d61c56f42bcd 100644
--- a/drivers/media/video/tea6415c.c
+++ b/drivers/media/video/tea6415c.c
@@ -32,7 +32,8 @@
32#include <linux/ioctl.h> 32#include <linux/ioctl.h>
33#include <linux/i2c.h> 33#include <linux/i2c.h>
34#include <media/v4l2-device.h> 34#include <media/v4l2-device.h>
35#include <media/v4l2-i2c-drv-legacy.h> 35#include <media/v4l2-chip-ident.h>
36#include <media/v4l2-i2c-drv.h>
36#include "tea6415c.h" 37#include "tea6415c.h"
37 38
38MODULE_AUTHOR("Michael Hunold <michael@mihu.de>"); 39MODULE_AUTHOR("Michael Hunold <michael@mihu.de>");
@@ -44,25 +45,22 @@ module_param(debug, int, 0644);
44 45
45MODULE_PARM_DESC(debug, "Debug level (0-1)"); 46MODULE_PARM_DESC(debug, "Debug level (0-1)");
46 47
47/* addresses to scan, found only at 0x03 and/or 0x43 (7-bit) */
48static unsigned short normal_i2c[] = { I2C_TEA6415C_1, I2C_TEA6415C_2, I2C_CLIENT_END };
49 48
50/* magic definition of all other variables and things */ 49/* makes a connection between the input-pin 'i' and the output-pin 'o' */
51I2C_CLIENT_INSMOD; 50static int tea6415c_s_routing(struct v4l2_subdev *sd, const struct v4l2_routing *route)
52
53/* makes a connection between the input-pin 'i' and the output-pin 'o'
54 for the tea6415c-client 'client' */
55static int switch_matrix(struct i2c_client *client, int i, int o)
56{ 51{
52 struct i2c_client *client = v4l2_get_subdevdata(sd);
57 u8 byte = 0; 53 u8 byte = 0;
54 u32 i = route->input;
55 u32 o = route->output;
58 int ret; 56 int ret;
59 57
60 v4l_dbg(1, debug, client, "i=%d, o=%d\n", i, o); 58 v4l2_dbg(1, debug, sd, "i=%d, o=%d\n", i, o);
61 59
62 /* check if the pins are valid */ 60 /* check if the pins are valid */
63 if (0 == ((1 == i || 3 == i || 5 == i || 6 == i || 8 == i || 10 == i || 20 == i || 11 == i) 61 if (0 == ((1 == i || 3 == i || 5 == i || 6 == i || 8 == i || 10 == i || 20 == i || 11 == i)
64 && (18 == o || 17 == o || 16 == o || 15 == o || 14 == o || 13 == o))) 62 && (18 == o || 17 == o || 16 == o || 15 == o || 14 == o || 13 == o)))
65 return -1; 63 return -EINVAL;
66 64
67 /* to understand this, have a look at the tea6415c-specs (p.5) */ 65 /* to understand this, have a look at the tea6415c-specs (p.5) */
68 switch (o) { 66 switch (o) {
@@ -115,37 +113,33 @@ static int switch_matrix(struct i2c_client *client, int i, int o)
115 113
116 ret = i2c_smbus_write_byte(client, byte); 114 ret = i2c_smbus_write_byte(client, byte);
117 if (ret) { 115 if (ret) {
118 v4l_dbg(1, debug, client, 116 v4l2_dbg(1, debug, sd,
119 "i2c_smbus_write_byte() failed, ret:%d\n", ret); 117 "i2c_smbus_write_byte() failed, ret:%d\n", ret);
120 return -EIO; 118 return -EIO;
121 } 119 }
122 return ret; 120 return ret;
123} 121}
124 122
125static long tea6415c_ioctl(struct v4l2_subdev *sd, unsigned cmd, void *arg) 123static int tea6415c_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
126{ 124{
127 if (cmd == TEA6415C_SWITCH) { 125 struct i2c_client *client = v4l2_get_subdevdata(sd);
128 struct i2c_client *client = v4l2_get_subdevdata(sd);
129 struct tea6415c_multiplex *v = (struct tea6415c_multiplex *)arg;
130 126
131 return switch_matrix(client, v->in, v->out); 127 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_TEA6415C, 0);
132 }
133 return -ENOIOCTLCMD;
134}
135
136static int tea6415c_command(struct i2c_client *client, unsigned cmd, void *arg)
137{
138 return v4l2_subdev_command(i2c_get_clientdata(client), cmd, arg);
139} 128}
140 129
141/* ----------------------------------------------------------------------- */ 130/* ----------------------------------------------------------------------- */
142 131
143static const struct v4l2_subdev_core_ops tea6415c_core_ops = { 132static const struct v4l2_subdev_core_ops tea6415c_core_ops = {
144 .ioctl = tea6415c_ioctl, 133 .g_chip_ident = tea6415c_g_chip_ident,
134};
135
136static const struct v4l2_subdev_video_ops tea6415c_video_ops = {
137 .s_routing = tea6415c_s_routing,
145}; 138};
146 139
147static const struct v4l2_subdev_ops tea6415c_ops = { 140static const struct v4l2_subdev_ops tea6415c_ops = {
148 .core = &tea6415c_core_ops, 141 .core = &tea6415c_core_ops,
142 .video = &tea6415c_video_ops,
149}; 143};
150 144
151/* this function is called by i2c_probe */ 145/* this function is called by i2c_probe */
@@ -176,12 +170,6 @@ static int tea6415c_remove(struct i2c_client *client)
176 return 0; 170 return 0;
177} 171}
178 172
179static int tea6415c_legacy_probe(struct i2c_adapter *adapter)
180{
181 /* Let's see whether this is a known adapter we can attach to.
182 Prevents conflicts with tvaudio.c. */
183 return adapter->id == I2C_HW_SAA7146;
184}
185 173
186static const struct i2c_device_id tea6415c_id[] = { 174static const struct i2c_device_id tea6415c_id[] = {
187 { "tea6415c", 0 }, 175 { "tea6415c", 0 },
@@ -191,10 +179,7 @@ MODULE_DEVICE_TABLE(i2c, tea6415c_id);
191 179
192static struct v4l2_i2c_driver_data v4l2_i2c_data = { 180static struct v4l2_i2c_driver_data v4l2_i2c_data = {
193 .name = "tea6415c", 181 .name = "tea6415c",
194 .driverid = I2C_DRIVERID_TEA6415C,
195 .command = tea6415c_command,
196 .probe = tea6415c_probe, 182 .probe = tea6415c_probe,
197 .remove = tea6415c_remove, 183 .remove = tea6415c_remove,
198 .legacy_probe = tea6415c_legacy_probe,
199 .id_table = tea6415c_id, 184 .id_table = tea6415c_id,
200}; 185};
diff --git a/drivers/media/video/tea6415c.h b/drivers/media/video/tea6415c.h
index f84ed80050b3..3a47d697536e 100644
--- a/drivers/media/video/tea6415c.h
+++ b/drivers/media/video/tea6415c.h
@@ -1,10 +1,6 @@
1#ifndef __INCLUDED_TEA6415C__ 1#ifndef __INCLUDED_TEA6415C__
2#define __INCLUDED_TEA6415C__ 2#define __INCLUDED_TEA6415C__
3 3
4/* possible i2c-addresses */
5#define I2C_TEA6415C_1 0x03
6#define I2C_TEA6415C_2 0x43
7
8/* the tea6415c's design is quite brain-dead. although there are 4/* the tea6415c's design is quite brain-dead. although there are
9 8 inputs and 6 outputs, these aren't enumerated in any way. because 5 8 inputs and 6 outputs, these aren't enumerated in any way. because
10 I don't want to say "connect input pin 20 to output pin 17", I define 6 I don't want to say "connect input pin 20 to output pin 17", I define
@@ -28,12 +24,4 @@
28#define TEA6415C_INPUT7 1 24#define TEA6415C_INPUT7 1
29#define TEA6415C_INPUT8 11 25#define TEA6415C_INPUT8 11
30 26
31struct tea6415c_multiplex
32{
33 int in; /* input-pin */
34 int out; /* output-pin */
35};
36
37#define TEA6415C_SWITCH _IOW('v',1,struct tea6415c_multiplex)
38
39#endif 27#endif
diff --git a/drivers/media/video/tea6420.c b/drivers/media/video/tea6420.c
index 081e74fa3b2e..34922232402a 100644
--- a/drivers/media/video/tea6420.c
+++ b/drivers/media/video/tea6420.c
@@ -32,7 +32,8 @@
32#include <linux/ioctl.h> 32#include <linux/ioctl.h>
33#include <linux/i2c.h> 33#include <linux/i2c.h>
34#include <media/v4l2-device.h> 34#include <media/v4l2-device.h>
35#include <media/v4l2-i2c-drv-legacy.h> 35#include <media/v4l2-chip-ident.h>
36#include <media/v4l2-i2c-drv.h>
36#include "tea6420.h" 37#include "tea6420.h"
37 38
38MODULE_AUTHOR("Michael Hunold <michael@mihu.de>"); 39MODULE_AUTHOR("Michael Hunold <michael@mihu.de>");
@@ -44,24 +45,23 @@ module_param(debug, int, 0644);
44 45
45MODULE_PARM_DESC(debug, "Debug level (0-1)"); 46MODULE_PARM_DESC(debug, "Debug level (0-1)");
46 47
47/* addresses to scan, found only at 0x4c and/or 0x4d (7-Bit) */
48static unsigned short normal_i2c[] = { I2C_ADDR_TEA6420_1, I2C_ADDR_TEA6420_2, I2C_CLIENT_END };
49
50/* magic definition of all other variables and things */
51I2C_CLIENT_INSMOD;
52 48
53/* make a connection between the input 'i' and the output 'o' 49/* make a connection between the input 'i' and the output 'o'
54 with gain 'g' for the tea6420-client 'client' (note: i = 6 means 'mute') */ 50 with gain 'g' (note: i = 6 means 'mute') */
55static int tea6420_switch(struct i2c_client *client, int i, int o, int g) 51static int tea6420_s_routing(struct v4l2_subdev *sd, const struct v4l2_routing *route)
56{ 52{
53 struct i2c_client *client = v4l2_get_subdevdata(sd);
54 int i = route->input;
55 int o = route->output & 0xf;
56 int g = (route->output >> 4) & 0xf;
57 u8 byte; 57 u8 byte;
58 int ret; 58 int ret;
59 59
60 v4l_dbg(1, debug, client, "i=%d, o=%d, g=%d\n", i, o, g); 60 v4l2_dbg(1, debug, sd, "i=%d, o=%d, g=%d\n", i, o, g);
61 61
62 /* check if the parameters are valid */ 62 /* check if the parameters are valid */
63 if (i < 1 || i > 6 || o < 1 || o > 4 || g < 0 || g > 6 || g % 2 != 0) 63 if (i < 1 || i > 6 || o < 1 || o > 4 || g < 0 || g > 6 || g % 2 != 0)
64 return -1; 64 return -EINVAL;
65 65
66 byte = ((o - 1) << 5); 66 byte = ((o - 1) << 5);
67 byte |= (i - 1); 67 byte |= (i - 1);
@@ -83,37 +83,33 @@ static int tea6420_switch(struct i2c_client *client, int i, int o, int g)
83 83
84 ret = i2c_smbus_write_byte(client, byte); 84 ret = i2c_smbus_write_byte(client, byte);
85 if (ret) { 85 if (ret) {
86 v4l_dbg(1, debug, client, 86 v4l2_dbg(1, debug, sd,
87 "i2c_smbus_write_byte() failed, ret:%d\n", ret); 87 "i2c_smbus_write_byte() failed, ret:%d\n", ret);
88 return -EIO; 88 return -EIO;
89 } 89 }
90 return 0; 90 return 0;
91} 91}
92 92
93static long tea6420_ioctl(struct v4l2_subdev *sd, unsigned cmd, void *arg) 93static int tea6420_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
94{ 94{
95 if (cmd == TEA6420_SWITCH) { 95 struct i2c_client *client = v4l2_get_subdevdata(sd);
96 struct i2c_client *client = v4l2_get_subdevdata(sd);
97 struct tea6420_multiplex *a = (struct tea6420_multiplex *)arg;
98 96
99 return tea6420_switch(client, a->in, a->out, a->gain); 97 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_TEA6420, 0);
100 }
101 return -ENOIOCTLCMD;
102}
103
104static int tea6420_command(struct i2c_client *client, unsigned cmd, void *arg)
105{
106 return v4l2_subdev_command(i2c_get_clientdata(client), cmd, arg);
107} 98}
108 99
109/* ----------------------------------------------------------------------- */ 100/* ----------------------------------------------------------------------- */
110 101
111static const struct v4l2_subdev_core_ops tea6420_core_ops = { 102static const struct v4l2_subdev_core_ops tea6420_core_ops = {
112 .ioctl = tea6420_ioctl, 103 .g_chip_ident = tea6420_g_chip_ident,
104};
105
106static const struct v4l2_subdev_audio_ops tea6420_audio_ops = {
107 .s_routing = tea6420_s_routing,
113}; 108};
114 109
115static const struct v4l2_subdev_ops tea6420_ops = { 110static const struct v4l2_subdev_ops tea6420_ops = {
116 .core = &tea6420_core_ops, 111 .core = &tea6420_core_ops,
112 .audio = &tea6420_audio_ops,
117}; 113};
118 114
119/* this function is called by i2c_probe */ 115/* this function is called by i2c_probe */
@@ -130,20 +126,24 @@ static int tea6420_probe(struct i2c_client *client,
130 v4l_info(client, "chip found @ 0x%x (%s)\n", 126 v4l_info(client, "chip found @ 0x%x (%s)\n",
131 client->addr << 1, client->adapter->name); 127 client->addr << 1, client->adapter->name);
132 128
129 sd = kmalloc(sizeof(struct v4l2_subdev), GFP_KERNEL);
130 if (sd == NULL)
131 return -ENOMEM;
132 v4l2_i2c_subdev_init(sd, client, &tea6420_ops);
133
133 /* set initial values: set "mute"-input to all outputs at gain 0 */ 134 /* set initial values: set "mute"-input to all outputs at gain 0 */
134 err = 0; 135 err = 0;
135 for (i = 1; i < 5; i++) { 136 for (i = 1; i < 5; i++) {
136 err += tea6420_switch(client, 6, i, 0); 137 struct v4l2_routing route;
138
139 route.input = 6;
140 route.output = i;
141 err += tea6420_s_routing(sd, &route);
137 } 142 }
138 if (err) { 143 if (err) {
139 v4l_dbg(1, debug, client, "could not initialize tea6420\n"); 144 v4l_dbg(1, debug, client, "could not initialize tea6420\n");
140 return -ENODEV; 145 return -ENODEV;
141 } 146 }
142
143 sd = kmalloc(sizeof(struct v4l2_subdev), GFP_KERNEL);
144 if (sd == NULL)
145 return -ENOMEM;
146 v4l2_i2c_subdev_init(sd, client, &tea6420_ops);
147 return 0; 147 return 0;
148} 148}
149 149
@@ -156,12 +156,6 @@ static int tea6420_remove(struct i2c_client *client)
156 return 0; 156 return 0;
157} 157}
158 158
159static int tea6420_legacy_probe(struct i2c_adapter *adapter)
160{
161 /* Let's see whether this is a known adapter we can attach to.
162 Prevents conflicts with tvaudio.c. */
163 return adapter->id == I2C_HW_SAA7146;
164}
165 159
166static const struct i2c_device_id tea6420_id[] = { 160static const struct i2c_device_id tea6420_id[] = {
167 { "tea6420", 0 }, 161 { "tea6420", 0 },
@@ -171,10 +165,7 @@ MODULE_DEVICE_TABLE(i2c, tea6420_id);
171 165
172static struct v4l2_i2c_driver_data v4l2_i2c_data = { 166static struct v4l2_i2c_driver_data v4l2_i2c_data = {
173 .name = "tea6420", 167 .name = "tea6420",
174 .driverid = I2C_DRIVERID_TEA6420,
175 .command = tea6420_command,
176 .probe = tea6420_probe, 168 .probe = tea6420_probe,
177 .remove = tea6420_remove, 169 .remove = tea6420_remove,
178 .legacy_probe = tea6420_legacy_probe,
179 .id_table = tea6420_id, 170 .id_table = tea6420_id,
180}; 171};
diff --git a/drivers/media/video/tea6420.h b/drivers/media/video/tea6420.h
index 5ef7c18e0c54..4aa3edb3e193 100644
--- a/drivers/media/video/tea6420.h
+++ b/drivers/media/video/tea6420.h
@@ -1,17 +1,24 @@
1#ifndef __INCLUDED_TEA6420__ 1#ifndef __INCLUDED_TEA6420__
2#define __INCLUDED_TEA6420__ 2#define __INCLUDED_TEA6420__
3 3
4/* possible addresses */ 4/* input pins */
5#define I2C_ADDR_TEA6420_1 0x4c 5#define TEA6420_OUTPUT1 1
6#define I2C_ADDR_TEA6420_2 0x4d 6#define TEA6420_OUTPUT2 2
7#define TEA6420_OUTPUT3 3
8#define TEA6420_OUTPUT4 4
7 9
8struct tea6420_multiplex 10/* output pins */
9{ 11#define TEA6420_INPUT1 1
10 int in; /* input of audio switch */ 12#define TEA6420_INPUT2 2
11 int out; /* output of audio switch */ 13#define TEA6420_INPUT3 3
12 int gain; /* gain of connection */ 14#define TEA6420_INPUT4 4
13}; 15#define TEA6420_INPUT5 5
16#define TEA6420_INPUT6 6
14 17
15#define TEA6420_SWITCH _IOW('v',1,struct tea6420_multiplex) 18/* gain on the output pins, ORed with the output pin */
19#define TEA6420_GAIN0 0x00
20#define TEA6420_GAIN2 0x20
21#define TEA6420_GAIN4 0x40
22#define TEA6420_GAIN6 0x60
16 23
17#endif 24#endif
diff --git a/drivers/media/video/tlv320aic23b.c b/drivers/media/video/tlv320aic23b.c
index 5c95ecd09dc2..07789c64814c 100644
--- a/drivers/media/video/tlv320aic23b.c
+++ b/drivers/media/video/tlv320aic23b.c
@@ -31,15 +31,12 @@
31#include <linux/i2c-id.h> 31#include <linux/i2c-id.h>
32#include <linux/videodev2.h> 32#include <linux/videodev2.h>
33#include <media/v4l2-device.h> 33#include <media/v4l2-device.h>
34#include <media/v4l2-i2c-drv-legacy.h> 34#include <media/v4l2-i2c-drv.h>
35 35
36MODULE_DESCRIPTION("tlv320aic23b driver"); 36MODULE_DESCRIPTION("tlv320aic23b driver");
37MODULE_AUTHOR("Scott Alfter, Ulf Eklund, Hans Verkuil"); 37MODULE_AUTHOR("Scott Alfter, Ulf Eklund, Hans Verkuil");
38MODULE_LICENSE("GPL"); 38MODULE_LICENSE("GPL");
39 39
40static unsigned short normal_i2c[] = { 0x34 >> 1, I2C_CLIENT_END };
41
42I2C_CLIENT_INSMOD;
43 40
44/* ----------------------------------------------------------------------- */ 41/* ----------------------------------------------------------------------- */
45 42
@@ -121,11 +118,6 @@ static int tlv320aic23b_log_status(struct v4l2_subdev *sd)
121 return 0; 118 return 0;
122} 119}
123 120
124static int tlv320aic23b_command(struct i2c_client *client, unsigned cmd, void *arg)
125{
126 return v4l2_subdev_command(i2c_get_clientdata(client), cmd, arg);
127}
128
129/* ----------------------------------------------------------------------- */ 121/* ----------------------------------------------------------------------- */
130 122
131static const struct v4l2_subdev_core_ops tlv320aic23b_core_ops = { 123static const struct v4l2_subdev_core_ops tlv320aic23b_core_ops = {
@@ -208,8 +200,6 @@ MODULE_DEVICE_TABLE(i2c, tlv320aic23b_id);
208 200
209static struct v4l2_i2c_driver_data v4l2_i2c_data = { 201static struct v4l2_i2c_driver_data v4l2_i2c_data = {
210 .name = "tlv320aic23b", 202 .name = "tlv320aic23b",
211 .driverid = I2C_DRIVERID_TLV320AIC23B,
212 .command = tlv320aic23b_command,
213 .probe = tlv320aic23b_probe, 203 .probe = tlv320aic23b_probe,
214 .remove = tlv320aic23b_remove, 204 .remove = tlv320aic23b_remove,
215 .id_table = tlv320aic23b_id, 205 .id_table = tlv320aic23b_id,
diff --git a/drivers/media/video/tuner-core.c b/drivers/media/video/tuner-core.c
index 30640fbfd0f9..72d41032742d 100644
--- a/drivers/media/video/tuner-core.c
+++ b/drivers/media/video/tuner-core.c
@@ -364,7 +364,8 @@ static void set_type(struct i2c_client *c, unsigned int type,
364 } 364 }
365 365
366 t->type = type; 366 t->type = type;
367 t->config = new_config; 367 /* prevent invalid config values */
368 t->config = ((new_config >= 0) && (new_config < 256)) ? new_config : 0;
368 if (tuner_callback != NULL) { 369 if (tuner_callback != NULL) {
369 tuner_dbg("defining GPIO callback\n"); 370 tuner_dbg("defining GPIO callback\n");
370 t->fe.callback = tuner_callback; 371 t->fe.callback = tuner_callback;
@@ -452,7 +453,8 @@ static void set_type(struct i2c_client *c, unsigned int type,
452 struct dvb_tuner_ops *xc_tuner_ops; 453 struct dvb_tuner_ops *xc_tuner_ops;
453 454
454 xc5000_cfg.i2c_address = t->i2c->addr; 455 xc5000_cfg.i2c_address = t->i2c->addr;
455 xc5000_cfg.if_khz = 5380; 456 /* if_khz will be set when the digital dvb_attach() occurs */
457 xc5000_cfg.if_khz = 0;
456 if (!dvb_attach(xc5000_attach, 458 if (!dvb_attach(xc5000_attach,
457 &t->fe, t->i2c->adapter, &xc5000_cfg)) 459 &t->fe, t->i2c->adapter, &xc5000_cfg))
458 goto attach_failed; 460 goto attach_failed;
@@ -776,8 +778,7 @@ static int tuner_s_radio(struct v4l2_subdev *sd)
776 struct tuner *t = to_tuner(sd); 778 struct tuner *t = to_tuner(sd);
777 struct i2c_client *client = v4l2_get_subdevdata(sd); 779 struct i2c_client *client = v4l2_get_subdevdata(sd);
778 780
779 if (set_mode(client, t, V4L2_TUNER_RADIO, "AUDC_SET_RADIO") 781 if (set_mode(client, t, V4L2_TUNER_RADIO, "s_radio") == -EINVAL)
780 == -EINVAL)
781 return 0; 782 return 0;
782 if (t->radio_freq) 783 if (t->radio_freq)
783 set_freq(client, t->radio_freq); 784 set_freq(client, t->radio_freq);
@@ -791,7 +792,7 @@ static int tuner_s_standby(struct v4l2_subdev *sd, u32 standby)
791 792
792 tuner_dbg("Putting tuner to sleep\n"); 793 tuner_dbg("Putting tuner to sleep\n");
793 794
794 if (check_mode(t, "TUNER_SET_STANDBY") == -EINVAL) 795 if (check_mode(t, "s_standby") == -EINVAL)
795 return 0; 796 return 0;
796 t->mode = T_STANDBY; 797 t->mode = T_STANDBY;
797 if (analog_ops->standby) 798 if (analog_ops->standby)
@@ -799,132 +800,6 @@ static int tuner_s_standby(struct v4l2_subdev *sd, u32 standby)
799 return 0; 800 return 0;
800} 801}
801 802
802#ifdef CONFIG_VIDEO_ALLOW_V4L1
803static long tuner_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
804{
805 struct tuner *t = to_tuner(sd);
806 struct i2c_client *client = v4l2_get_subdevdata(sd);
807 struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops;
808 struct dvb_tuner_ops *fe_tuner_ops = &t->fe.ops.tuner_ops;
809
810 switch (cmd) {
811 case VIDIOCSAUDIO:
812 if (check_mode(t, "VIDIOCSAUDIO") == -EINVAL)
813 return 0;
814 if (check_v4l2(t) == -EINVAL)
815 return 0;
816
817 /* Should be implemented, since bttv calls it */
818 tuner_dbg("VIDIOCSAUDIO not implemented.\n");
819 break;
820 case VIDIOCSCHAN:
821 {
822 static const v4l2_std_id map[] = {
823 [VIDEO_MODE_PAL] = V4L2_STD_PAL,
824 [VIDEO_MODE_NTSC] = V4L2_STD_NTSC_M,
825 [VIDEO_MODE_SECAM] = V4L2_STD_SECAM,
826 [4 /* bttv */ ] = V4L2_STD_PAL_M,
827 [5 /* bttv */ ] = V4L2_STD_PAL_N,
828 [6 /* bttv */ ] = V4L2_STD_NTSC_M_JP,
829 };
830 struct video_channel *vc = arg;
831
832 if (check_v4l2(t) == -EINVAL)
833 return 0;
834
835 if (set_mode(client,t,V4L2_TUNER_ANALOG_TV, "VIDIOCSCHAN")==-EINVAL)
836 return 0;
837
838 if (vc->norm < ARRAY_SIZE(map))
839 t->std = map[vc->norm];
840 tuner_fixup_std(t);
841 if (t->tv_freq)
842 set_tv_freq(client, t->tv_freq);
843 return 0;
844 }
845 case VIDIOCSFREQ:
846 {
847 unsigned long *v = arg;
848
849 if (check_mode(t, "VIDIOCSFREQ") == -EINVAL)
850 return 0;
851 if (check_v4l2(t) == -EINVAL)
852 return 0;
853
854 set_freq(client, *v);
855 return 0;
856 }
857 case VIDIOCGTUNER:
858 {
859 struct video_tuner *vt = arg;
860
861 if (check_mode(t, "VIDIOCGTUNER") == -EINVAL)
862 return 0;
863 if (check_v4l2(t) == -EINVAL)
864 return 0;
865
866 if (V4L2_TUNER_RADIO == t->mode) {
867 if (fe_tuner_ops->get_status) {
868 u32 tuner_status;
869
870 fe_tuner_ops->get_status(&t->fe, &tuner_status);
871 if (tuner_status & TUNER_STATUS_STEREO)
872 vt->flags |= VIDEO_TUNER_STEREO_ON;
873 else
874 vt->flags &= ~VIDEO_TUNER_STEREO_ON;
875 } else {
876 if (analog_ops->is_stereo) {
877 if (analog_ops->is_stereo(&t->fe))
878 vt->flags |=
879 VIDEO_TUNER_STEREO_ON;
880 else
881 vt->flags &=
882 ~VIDEO_TUNER_STEREO_ON;
883 }
884 }
885 if (analog_ops->has_signal)
886 vt->signal =
887 analog_ops->has_signal(&t->fe);
888
889 vt->flags |= VIDEO_TUNER_LOW; /* Allow freqs at 62.5 Hz */
890
891 vt->rangelow = radio_range[0] * 16000;
892 vt->rangehigh = radio_range[1] * 16000;
893
894 } else {
895 vt->rangelow = tv_range[0] * 16;
896 vt->rangehigh = tv_range[1] * 16;
897 }
898
899 return 0;
900 }
901 case VIDIOCGAUDIO:
902 {
903 struct video_audio *va = arg;
904
905 if (check_mode(t, "VIDIOCGAUDIO") == -EINVAL)
906 return 0;
907 if (check_v4l2(t) == -EINVAL)
908 return 0;
909
910 if (V4L2_TUNER_RADIO == t->mode) {
911 if (fe_tuner_ops->get_status) {
912 u32 tuner_status;
913
914 fe_tuner_ops->get_status(&t->fe, &tuner_status);
915 va->mode = (tuner_status & TUNER_STATUS_STEREO)
916 ? VIDEO_SOUND_STEREO : VIDEO_SOUND_MONO;
917 } else if (analog_ops->is_stereo)
918 va->mode = analog_ops->is_stereo(&t->fe)
919 ? VIDEO_SOUND_STEREO : VIDEO_SOUND_MONO;
920 }
921 return 0;
922 }
923 }
924 return -ENOIOCTLCMD;
925}
926#endif
927
928static int tuner_s_config(struct v4l2_subdev *sd, const struct v4l2_priv_tun_config *cfg) 803static int tuner_s_config(struct v4l2_subdev *sd, const struct v4l2_priv_tun_config *cfg)
929{ 804{
930 struct tuner *t = to_tuner(sd); 805 struct tuner *t = to_tuner(sd);
@@ -950,8 +825,7 @@ static int tuner_s_std(struct v4l2_subdev *sd, v4l2_std_id std)
950 struct tuner *t = to_tuner(sd); 825 struct tuner *t = to_tuner(sd);
951 struct i2c_client *client = v4l2_get_subdevdata(sd); 826 struct i2c_client *client = v4l2_get_subdevdata(sd);
952 827
953 if (set_mode(client, t, V4L2_TUNER_ANALOG_TV, "VIDIOC_S_STD") 828 if (set_mode(client, t, V4L2_TUNER_ANALOG_TV, "s_std") == -EINVAL)
954 == -EINVAL)
955 return 0; 829 return 0;
956 830
957 switch_v4l2(); 831 switch_v4l2();
@@ -968,8 +842,7 @@ static int tuner_s_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *f)
968 struct tuner *t = to_tuner(sd); 842 struct tuner *t = to_tuner(sd);
969 struct i2c_client *client = v4l2_get_subdevdata(sd); 843 struct i2c_client *client = v4l2_get_subdevdata(sd);
970 844
971 if (set_mode(client, t, f->type, "VIDIOC_S_FREQUENCY") 845 if (set_mode(client, t, f->type, "s_frequency") == -EINVAL)
972 == -EINVAL)
973 return 0; 846 return 0;
974 switch_v4l2(); 847 switch_v4l2();
975 set_freq(client, f->frequency); 848 set_freq(client, f->frequency);
@@ -982,7 +855,7 @@ static int tuner_g_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *f)
982 struct tuner *t = to_tuner(sd); 855 struct tuner *t = to_tuner(sd);
983 struct dvb_tuner_ops *fe_tuner_ops = &t->fe.ops.tuner_ops; 856 struct dvb_tuner_ops *fe_tuner_ops = &t->fe.ops.tuner_ops;
984 857
985 if (check_mode(t, "VIDIOC_G_FREQUENCY") == -EINVAL) 858 if (check_mode(t, "g_frequency") == -EINVAL)
986 return 0; 859 return 0;
987 switch_v4l2(); 860 switch_v4l2();
988 f->type = t->mode; 861 f->type = t->mode;
@@ -1006,7 +879,7 @@ static int tuner_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
1006 struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops; 879 struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops;
1007 struct dvb_tuner_ops *fe_tuner_ops = &t->fe.ops.tuner_ops; 880 struct dvb_tuner_ops *fe_tuner_ops = &t->fe.ops.tuner_ops;
1008 881
1009 if (check_mode(t, "VIDIOC_G_TUNER") == -EINVAL) 882 if (check_mode(t, "g_tuner") == -EINVAL)
1010 return 0; 883 return 0;
1011 switch_v4l2(); 884 switch_v4l2();
1012 885
@@ -1055,7 +928,7 @@ static int tuner_s_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
1055 struct tuner *t = to_tuner(sd); 928 struct tuner *t = to_tuner(sd);
1056 struct i2c_client *client = v4l2_get_subdevdata(sd); 929 struct i2c_client *client = v4l2_get_subdevdata(sd);
1057 930
1058 if (check_mode(t, "VIDIOC_S_TUNER") == -EINVAL) 931 if (check_mode(t, "s_tuner") == -EINVAL)
1059 return 0; 932 return 0;
1060 933
1061 switch_v4l2(); 934 switch_v4l2();
@@ -1112,9 +985,6 @@ static int tuner_resume(struct i2c_client *c)
1112static const struct v4l2_subdev_core_ops tuner_core_ops = { 985static const struct v4l2_subdev_core_ops tuner_core_ops = {
1113 .log_status = tuner_log_status, 986 .log_status = tuner_log_status,
1114 .s_standby = tuner_s_standby, 987 .s_standby = tuner_s_standby,
1115#ifdef CONFIG_VIDEO_ALLOW_V4L1
1116 .ioctl = tuner_ioctl,
1117#endif
1118}; 988};
1119 989
1120static const struct v4l2_subdev_tuner_ops tuner_tuner_ops = { 990static const struct v4l2_subdev_tuner_ops tuner_tuner_ops = {
diff --git a/drivers/media/video/tvaudio.c b/drivers/media/video/tvaudio.c
index 076ed5bf48b1..226bf3565ac9 100644
--- a/drivers/media/video/tvaudio.c
+++ b/drivers/media/video/tvaudio.c
@@ -26,7 +26,7 @@
26#include <linux/delay.h> 26#include <linux/delay.h>
27#include <linux/errno.h> 27#include <linux/errno.h>
28#include <linux/slab.h> 28#include <linux/slab.h>
29#include <linux/videodev.h> 29#include <linux/videodev2.h>
30#include <linux/i2c.h> 30#include <linux/i2c.h>
31#include <linux/init.h> 31#include <linux/init.h>
32#include <linux/kthread.h> 32#include <linux/kthread.h>
@@ -1047,6 +1047,116 @@ static int tda9874a_initialize(struct CHIPSTATE *chip)
1047 return 0; 1047 return 0;
1048} 1048}
1049 1049
1050/* ---------------------------------------------------------------------- */
1051/* audio chip description - defines+functions for tda9875 */
1052/* The TDA9875 is made by Philips Semiconductor
1053 * http://www.semiconductors.philips.com
1054 * TDA9875: I2C-bus controlled DSP audio processor, FM demodulator
1055 *
1056 */
1057
1058/* subaddresses for TDA9875 */
1059#define TDA9875_MUT 0x12 /*General mute (value --> 0b11001100*/
1060#define TDA9875_CFG 0x01 /* Config register (value --> 0b00000000 */
1061#define TDA9875_DACOS 0x13 /*DAC i/o select (ADC) 0b0000100*/
1062#define TDA9875_LOSR 0x16 /*Line output select regirter 0b0100 0001*/
1063
1064#define TDA9875_CH1V 0x0c /*Channel 1 volume (mute)*/
1065#define TDA9875_CH2V 0x0d /*Channel 2 volume (mute)*/
1066#define TDA9875_SC1 0x14 /*SCART 1 in (mono)*/
1067#define TDA9875_SC2 0x15 /*SCART 2 in (mono)*/
1068
1069#define TDA9875_ADCIS 0x17 /*ADC input select (mono) 0b0110 000*/
1070#define TDA9875_AER 0x19 /*Audio effect (AVL+Pseudo) 0b0000 0110*/
1071#define TDA9875_MCS 0x18 /*Main channel select (DAC) 0b0000100*/
1072#define TDA9875_MVL 0x1a /* Main volume gauche */
1073#define TDA9875_MVR 0x1b /* Main volume droite */
1074#define TDA9875_MBA 0x1d /* Main Basse */
1075#define TDA9875_MTR 0x1e /* Main treble */
1076#define TDA9875_ACS 0x1f /* Auxilary channel select (FM) 0b0000000*/
1077#define TDA9875_AVL 0x20 /* Auxilary volume gauche */
1078#define TDA9875_AVR 0x21 /* Auxilary volume droite */
1079#define TDA9875_ABA 0x22 /* Auxilary Basse */
1080#define TDA9875_ATR 0x23 /* Auxilary treble */
1081
1082#define TDA9875_MSR 0x02 /* Monitor select register */
1083#define TDA9875_C1MSB 0x03 /* Carrier 1 (FM) frequency register MSB */
1084#define TDA9875_C1MIB 0x04 /* Carrier 1 (FM) frequency register (16-8]b */
1085#define TDA9875_C1LSB 0x05 /* Carrier 1 (FM) frequency register LSB */
1086#define TDA9875_C2MSB 0x06 /* Carrier 2 (nicam) frequency register MSB */
1087#define TDA9875_C2MIB 0x07 /* Carrier 2 (nicam) frequency register (16-8]b */
1088#define TDA9875_C2LSB 0x08 /* Carrier 2 (nicam) frequency register LSB */
1089#define TDA9875_DCR 0x09 /* Demodulateur configuration regirter*/
1090#define TDA9875_DEEM 0x0a /* FM de-emphasis regirter*/
1091#define TDA9875_FMAT 0x0b /* FM Matrix regirter*/
1092
1093/* values */
1094#define TDA9875_MUTE_ON 0xff /* general mute */
1095#define TDA9875_MUTE_OFF 0xcc /* general no mute */
1096
1097static int tda9875_initialize(struct CHIPSTATE *chip)
1098{
1099 chip_write(chip, TDA9875_CFG, 0xd0); /*reg de config 0 (reset)*/
1100 chip_write(chip, TDA9875_MSR, 0x03); /* Monitor 0b00000XXX*/
1101 chip_write(chip, TDA9875_C1MSB, 0x00); /*Car1(FM) MSB XMHz*/
1102 chip_write(chip, TDA9875_C1MIB, 0x00); /*Car1(FM) MIB XMHz*/
1103 chip_write(chip, TDA9875_C1LSB, 0x00); /*Car1(FM) LSB XMHz*/
1104 chip_write(chip, TDA9875_C2MSB, 0x00); /*Car2(NICAM) MSB XMHz*/
1105 chip_write(chip, TDA9875_C2MIB, 0x00); /*Car2(NICAM) MIB XMHz*/
1106 chip_write(chip, TDA9875_C2LSB, 0x00); /*Car2(NICAM) LSB XMHz*/
1107 chip_write(chip, TDA9875_DCR, 0x00); /*Demod config 0x00*/
1108 chip_write(chip, TDA9875_DEEM, 0x44); /*DE-Emph 0b0100 0100*/
1109 chip_write(chip, TDA9875_FMAT, 0x00); /*FM Matrix reg 0x00*/
1110 chip_write(chip, TDA9875_SC1, 0x00); /* SCART 1 (SC1)*/
1111 chip_write(chip, TDA9875_SC2, 0x01); /* SCART 2 (sc2)*/
1112
1113 chip_write(chip, TDA9875_CH1V, 0x10); /* Channel volume 1 mute*/
1114 chip_write(chip, TDA9875_CH2V, 0x10); /* Channel volume 2 mute */
1115 chip_write(chip, TDA9875_DACOS, 0x02); /* sig DAC i/o(in:nicam)*/
1116 chip_write(chip, TDA9875_ADCIS, 0x6f); /* sig ADC input(in:mono)*/
1117 chip_write(chip, TDA9875_LOSR, 0x00); /* line out (in:mono)*/
1118 chip_write(chip, TDA9875_AER, 0x00); /*06 Effect (AVL+PSEUDO) */
1119 chip_write(chip, TDA9875_MCS, 0x44); /* Main ch select (DAC) */
1120 chip_write(chip, TDA9875_MVL, 0x03); /* Vol Main left 10dB */
1121 chip_write(chip, TDA9875_MVR, 0x03); /* Vol Main right 10dB*/
1122 chip_write(chip, TDA9875_MBA, 0x00); /* Main Bass Main 0dB*/
1123 chip_write(chip, TDA9875_MTR, 0x00); /* Main Treble Main 0dB*/
1124 chip_write(chip, TDA9875_ACS, 0x44); /* Aux chan select (dac)*/
1125 chip_write(chip, TDA9875_AVL, 0x00); /* Vol Aux left 0dB*/
1126 chip_write(chip, TDA9875_AVR, 0x00); /* Vol Aux right 0dB*/
1127 chip_write(chip, TDA9875_ABA, 0x00); /* Aux Bass Main 0dB*/
1128 chip_write(chip, TDA9875_ATR, 0x00); /* Aux Aigus Main 0dB*/
1129
1130 chip_write(chip, TDA9875_MUT, 0xcc); /* General mute */
1131 return 0;
1132}
1133
1134static int tda9875_volume(int val) { return (unsigned char)(val / 602 - 84); }
1135static int tda9875_bass(int val) { return (unsigned char)(max(-12, val / 2115 - 15)); }
1136static int tda9875_treble(int val) { return (unsigned char)(val / 2622 - 12); }
1137
1138/* ----------------------------------------------------------------------- */
1139
1140
1141/* *********************** *
1142 * i2c interface functions *
1143 * *********************** */
1144
1145static int tda9875_checkit(struct CHIPSTATE *chip)
1146{
1147 struct v4l2_subdev *sd = &chip->sd;
1148 int dic, rev;
1149
1150 dic = chip_read2(chip, 254);
1151 rev = chip_read2(chip, 255);
1152
1153 if (dic == 0 || dic == 2) { /* tda9875 and tda9875A */
1154 v4l2_info(sd, "found tda9875%s rev. %d.\n",
1155 dic == 0 ? "" : "A", rev);
1156 return 1;
1157 }
1158 return 0;
1159}
1050 1160
1051/* ---------------------------------------------------------------------- */ 1161/* ---------------------------------------------------------------------- */
1052/* audio chip descriptions - defines+functions for tea6420 */ 1162/* audio chip descriptions - defines+functions for tea6420 */
@@ -1280,6 +1390,7 @@ static int tda9850 = 1;
1280static int tda9855 = 1; 1390static int tda9855 = 1;
1281static int tda9873 = 1; 1391static int tda9873 = 1;
1282static int tda9874a = 1; 1392static int tda9874a = 1;
1393static int tda9875 = 1;
1283static int tea6300; /* default 0 - address clash with msp34xx */ 1394static int tea6300; /* default 0 - address clash with msp34xx */
1284static int tea6320; /* default 0 - address clash with msp34xx */ 1395static int tea6320; /* default 0 - address clash with msp34xx */
1285static int tea6420 = 1; 1396static int tea6420 = 1;
@@ -1292,6 +1403,7 @@ module_param(tda9850, int, 0444);
1292module_param(tda9855, int, 0444); 1403module_param(tda9855, int, 0444);
1293module_param(tda9873, int, 0444); 1404module_param(tda9873, int, 0444);
1294module_param(tda9874a, int, 0444); 1405module_param(tda9874a, int, 0444);
1406module_param(tda9875, int, 0444);
1295module_param(tea6300, int, 0444); 1407module_param(tea6300, int, 0444);
1296module_param(tea6320, int, 0444); 1408module_param(tea6320, int, 0444);
1297module_param(tea6420, int, 0444); 1409module_param(tea6420, int, 0444);
@@ -1349,6 +1461,26 @@ static struct CHIPDESC chiplist[] = {
1349 .setmode = tda9874a_setmode, 1461 .setmode = tda9874a_setmode,
1350 }, 1462 },
1351 { 1463 {
1464 .name = "tda9875",
1465 .insmodopt = &tda9875,
1466 .addr_lo = I2C_ADDR_TDA9875 >> 1,
1467 .addr_hi = I2C_ADDR_TDA9875 >> 1,
1468 .flags = CHIP_HAS_VOLUME | CHIP_HAS_BASSTREBLE,
1469
1470 /* callbacks */
1471 .initialize = tda9875_initialize,
1472 .checkit = tda9875_checkit,
1473 .volfunc = tda9875_volume,
1474 .bassfunc = tda9875_bass,
1475 .treblefunc = tda9875_treble,
1476 .leftreg = TDA9875_MVL,
1477 .rightreg = TDA9875_MVR,
1478 .bassreg = TDA9875_MBA,
1479 .treblereg = TDA9875_MTR,
1480 .leftinit = 58880,
1481 .rightinit = 58880,
1482 },
1483 {
1352 .name = "tda9850", 1484 .name = "tda9850",
1353 .insmodopt = &tda9850, 1485 .insmodopt = &tda9850,
1354 .addr_lo = I2C_ADDR_TDA985x_L >> 1, 1486 .addr_lo = I2C_ADDR_TDA985x_L >> 1,
@@ -1511,6 +1643,8 @@ static int tvaudio_g_ctrl(struct v4l2_subdev *sd,
1511 1643
1512 switch (ctrl->id) { 1644 switch (ctrl->id) {
1513 case V4L2_CID_AUDIO_MUTE: 1645 case V4L2_CID_AUDIO_MUTE:
1646 if (!(desc->flags & CHIP_HAS_INPUTSEL))
1647 break;
1514 ctrl->value=chip->muted; 1648 ctrl->value=chip->muted;
1515 return 0; 1649 return 0;
1516 case V4L2_CID_AUDIO_VOLUME: 1650 case V4L2_CID_AUDIO_VOLUME:
@@ -1552,6 +1686,9 @@ static int tvaudio_s_ctrl(struct v4l2_subdev *sd,
1552 1686
1553 switch (ctrl->id) { 1687 switch (ctrl->id) {
1554 case V4L2_CID_AUDIO_MUTE: 1688 case V4L2_CID_AUDIO_MUTE:
1689 if (!(desc->flags & CHIP_HAS_INPUTSEL))
1690 break;
1691
1555 if (ctrl->value < 0 || ctrl->value >= 2) 1692 if (ctrl->value < 0 || ctrl->value >= 2)
1556 return -ERANGE; 1693 return -ERANGE;
1557 chip->muted = ctrl->value; 1694 chip->muted = ctrl->value;
@@ -1636,21 +1773,26 @@ static int tvaudio_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc)
1636 1773
1637 switch (qc->id) { 1774 switch (qc->id) {
1638 case V4L2_CID_AUDIO_MUTE: 1775 case V4L2_CID_AUDIO_MUTE:
1776 if (desc->flags & CHIP_HAS_INPUTSEL)
1777 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 0);
1639 break; 1778 break;
1640 case V4L2_CID_AUDIO_VOLUME: 1779 case V4L2_CID_AUDIO_VOLUME:
1780 if (desc->flags & CHIP_HAS_VOLUME)
1781 return v4l2_ctrl_query_fill(qc, 0, 65535, 65535 / 100, 58880);
1782 break;
1641 case V4L2_CID_AUDIO_BALANCE: 1783 case V4L2_CID_AUDIO_BALANCE:
1642 if (!(desc->flags & CHIP_HAS_VOLUME)) 1784 if (desc->flags & CHIP_HAS_VOLUME)
1643 return -EINVAL; 1785 return v4l2_ctrl_query_fill(qc, 0, 65535, 65535 / 100, 32768);
1644 break; 1786 break;
1645 case V4L2_CID_AUDIO_BASS: 1787 case V4L2_CID_AUDIO_BASS:
1646 case V4L2_CID_AUDIO_TREBLE: 1788 case V4L2_CID_AUDIO_TREBLE:
1647 if (!(desc->flags & CHIP_HAS_BASSTREBLE)) 1789 if (desc->flags & CHIP_HAS_BASSTREBLE)
1648 return -EINVAL; 1790 return v4l2_ctrl_query_fill(qc, 0, 65535, 65535 / 100, 32768);
1649 break; 1791 break;
1650 default: 1792 default:
1651 return -EINVAL; 1793 break;
1652 } 1794 }
1653 return v4l2_ctrl_query_fill_std(qc); 1795 return -EINVAL;
1654} 1796}
1655 1797
1656static int tvaudio_s_routing(struct v4l2_subdev *sd, const struct v4l2_routing *rt) 1798static int tvaudio_s_routing(struct v4l2_subdev *sd, const struct v4l2_routing *rt)
@@ -1658,7 +1800,9 @@ static int tvaudio_s_routing(struct v4l2_subdev *sd, const struct v4l2_routing *
1658 struct CHIPSTATE *chip = to_state(sd); 1800 struct CHIPSTATE *chip = to_state(sd);
1659 struct CHIPDESC *desc = chip->desc; 1801 struct CHIPDESC *desc = chip->desc;
1660 1802
1661 if (!(desc->flags & CHIP_HAS_INPUTSEL) || rt->input >= 4) 1803 if (!(desc->flags & CHIP_HAS_INPUTSEL))
1804 return 0;
1805 if (rt->input >= 4)
1662 return -EINVAL; 1806 return -EINVAL;
1663 /* There are four inputs: tuner, radio, extern and intern. */ 1807 /* There are four inputs: tuner, radio, extern and intern. */
1664 chip->input = rt->input; 1808 chip->input = rt->input;
@@ -1675,8 +1819,11 @@ static int tvaudio_s_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
1675 struct CHIPDESC *desc = chip->desc; 1819 struct CHIPDESC *desc = chip->desc;
1676 int mode = 0; 1820 int mode = 0;
1677 1821
1822 if (!desc->setmode)
1823 return 0;
1678 if (chip->radio) 1824 if (chip->radio)
1679 return 0; 1825 return 0;
1826
1680 switch (vt->audmode) { 1827 switch (vt->audmode) {
1681 case V4L2_TUNER_MODE_MONO: 1828 case V4L2_TUNER_MODE_MONO:
1682 case V4L2_TUNER_MODE_STEREO: 1829 case V4L2_TUNER_MODE_STEREO:
@@ -1692,7 +1839,7 @@ static int tvaudio_s_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
1692 } 1839 }
1693 chip->audmode = vt->audmode; 1840 chip->audmode = vt->audmode;
1694 1841
1695 if (desc->setmode && mode) { 1842 if (mode) {
1696 chip->watch_stereo = 0; 1843 chip->watch_stereo = 0;
1697 /* del_timer(&chip->wt); */ 1844 /* del_timer(&chip->wt); */
1698 chip->mode = mode; 1845 chip->mode = mode;
@@ -1707,15 +1854,17 @@ static int tvaudio_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
1707 struct CHIPDESC *desc = chip->desc; 1854 struct CHIPDESC *desc = chip->desc;
1708 int mode = V4L2_TUNER_MODE_MONO; 1855 int mode = V4L2_TUNER_MODE_MONO;
1709 1856
1857 if (!desc->getmode)
1858 return 0;
1710 if (chip->radio) 1859 if (chip->radio)
1711 return 0; 1860 return 0;
1861
1712 vt->audmode = chip->audmode; 1862 vt->audmode = chip->audmode;
1713 vt->rxsubchans = 0; 1863 vt->rxsubchans = 0;
1714 vt->capability = V4L2_TUNER_CAP_STEREO | 1864 vt->capability = V4L2_TUNER_CAP_STEREO |
1715 V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2; 1865 V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2;
1716 1866
1717 if (desc->getmode) 1867 mode = desc->getmode(chip);
1718 mode = desc->getmode(chip);
1719 1868
1720 if (mode & V4L2_TUNER_MODE_MONO) 1869 if (mode & V4L2_TUNER_MODE_MONO)
1721 vt->rxsubchans |= V4L2_TUNER_SUB_MONO; 1870 vt->rxsubchans |= V4L2_TUNER_SUB_MONO;
@@ -1901,6 +2050,7 @@ static int tvaudio_probe(struct i2c_client *client, const struct i2c_device_id *
1901 } 2050 }
1902 2051
1903 chip->thread = NULL; 2052 chip->thread = NULL;
2053 init_timer(&chip->wt);
1904 if (desc->flags & CHIP_NEED_CHECKMODE) { 2054 if (desc->flags & CHIP_NEED_CHECKMODE) {
1905 if (!desc->getmode || !desc->setmode) { 2055 if (!desc->getmode || !desc->setmode) {
1906 /* This shouldn't be happen. Warn user, but keep working 2056 /* This shouldn't be happen. Warn user, but keep working
@@ -1910,7 +2060,6 @@ static int tvaudio_probe(struct i2c_client *client, const struct i2c_device_id *
1910 return 0; 2060 return 0;
1911 } 2061 }
1912 /* start async thread */ 2062 /* start async thread */
1913 init_timer(&chip->wt);
1914 chip->wt.function = chip_thread_wake; 2063 chip->wt.function = chip_thread_wake;
1915 chip->wt.data = (unsigned long)chip; 2064 chip->wt.data = (unsigned long)chip;
1916 chip->thread = kthread_run(chip_thread, chip, client->name); 2065 chip->thread = kthread_run(chip_thread, chip, client->name);
diff --git a/drivers/media/video/tveeprom.c b/drivers/media/video/tveeprom.c
index 78277abb733b..e24a38c7fa46 100644
--- a/drivers/media/video/tveeprom.c
+++ b/drivers/media/video/tveeprom.c
@@ -261,7 +261,12 @@ hauppauge_tuner[] =
261 { TUNER_ABSENT, "MaxLinear MXL5005_v2"}, 261 { TUNER_ABSENT, "MaxLinear MXL5005_v2"},
262 { TUNER_PHILIPS_TDA8290, "Philips 18271_8295"}, 262 { TUNER_PHILIPS_TDA8290, "Philips 18271_8295"},
263 /* 150-159 */ 263 /* 150-159 */
264 { TUNER_ABSENT, "Xceive XC5000"}, 264 { TUNER_XC5000, "Xceive XC5000"},
265 { TUNER_ABSENT, "Xceive XC3028L"},
266 { TUNER_ABSENT, "NXP 18271C2_716x"},
267 { TUNER_ABSENT, "Xceive XC4000"},
268 { TUNER_ABSENT, "Dibcom 7070"},
269 { TUNER_PHILIPS_TDA8290, "NXP 18271C2"},
265}; 270};
266 271
267/* Use V4L2_IDENT_AMBIGUOUS for those audio 'chips' that are 272/* Use V4L2_IDENT_AMBIGUOUS for those audio 'chips' that are
diff --git a/drivers/media/video/tvp514x.c b/drivers/media/video/tvp514x.c
index 8e23aa53c29a..4262e60b8116 100644
--- a/drivers/media/video/tvp514x.c
+++ b/drivers/media/video/tvp514x.c
@@ -86,9 +86,12 @@ struct tvp514x_std_info {
86 struct v4l2_standard standard; 86 struct v4l2_standard standard;
87}; 87};
88 88
89static struct tvp514x_reg tvp514x_reg_list_default[0x40];
89/** 90/**
90 * struct tvp514x_decoded - TVP5146/47 decoder object 91 * struct tvp514x_decoder - TVP5146/47 decoder object
91 * @v4l2_int_device: Slave handle 92 * @v4l2_int_device: Slave handle
93 * @tvp514x_slave: Slave pointer which is used by @v4l2_int_device
94 * @tvp514x_regs: copy of hw's regs with preset values.
92 * @pdata: Board specific 95 * @pdata: Board specific
93 * @client: I2C client data 96 * @client: I2C client data
94 * @id: Entry from I2C table 97 * @id: Entry from I2C table
@@ -103,7 +106,9 @@ struct tvp514x_std_info {
103 * @route: input and output routing at chip level 106 * @route: input and output routing at chip level
104 */ 107 */
105struct tvp514x_decoder { 108struct tvp514x_decoder {
106 struct v4l2_int_device *v4l2_int_device; 109 struct v4l2_int_device v4l2_int_device;
110 struct v4l2_int_slave tvp514x_slave;
111 struct tvp514x_reg tvp514x_regs[ARRAY_SIZE(tvp514x_reg_list_default)];
107 const struct tvp514x_platform_data *pdata; 112 const struct tvp514x_platform_data *pdata;
108 struct i2c_client *client; 113 struct i2c_client *client;
109 114
@@ -124,7 +129,7 @@ struct tvp514x_decoder {
124}; 129};
125 130
126/* TVP514x default register values */ 131/* TVP514x default register values */
127static struct tvp514x_reg tvp514x_reg_list[] = { 132static struct tvp514x_reg tvp514x_reg_list_default[] = {
128 {TOK_WRITE, REG_INPUT_SEL, 0x05}, /* Composite selected */ 133 {TOK_WRITE, REG_INPUT_SEL, 0x05}, /* Composite selected */
129 {TOK_WRITE, REG_AFE_GAIN_CTRL, 0x0F}, 134 {TOK_WRITE, REG_AFE_GAIN_CTRL, 0x0F},
130 {TOK_WRITE, REG_VIDEO_STD, 0x00}, /* Auto mode */ 135 {TOK_WRITE, REG_VIDEO_STD, 0x00}, /* Auto mode */
@@ -422,7 +427,7 @@ static int tvp514x_configure(struct tvp514x_decoder *decoder)
422 427
423 /* common register initialization */ 428 /* common register initialization */
424 err = 429 err =
425 tvp514x_write_regs(decoder->client, tvp514x_reg_list); 430 tvp514x_write_regs(decoder->client, decoder->tvp514x_regs);
426 if (err) 431 if (err)
427 return err; 432 return err;
428 433
@@ -580,7 +585,8 @@ static int ioctl_s_std(struct v4l2_int_device *s, v4l2_std_id *std_id)
580 return err; 585 return err;
581 586
582 decoder->current_std = i; 587 decoder->current_std = i;
583 tvp514x_reg_list[REG_VIDEO_STD].val = decoder->std_list[i].video_std; 588 decoder->tvp514x_regs[REG_VIDEO_STD].val =
589 decoder->std_list[i].video_std;
584 590
585 v4l_dbg(1, debug, decoder->client, "Standard set to: %s", 591 v4l_dbg(1, debug, decoder->client, "Standard set to: %s",
586 decoder->std_list[i].standard.name); 592 decoder->std_list[i].standard.name);
@@ -625,8 +631,8 @@ static int ioctl_s_routing(struct v4l2_int_device *s,
625 if (err) 631 if (err)
626 return err; 632 return err;
627 633
628 tvp514x_reg_list[REG_INPUT_SEL].val = input_sel; 634 decoder->tvp514x_regs[REG_INPUT_SEL].val = input_sel;
629 tvp514x_reg_list[REG_OUTPUT_FORMATTER1].val = output_sel; 635 decoder->tvp514x_regs[REG_OUTPUT_FORMATTER1].val = output_sel;
630 636
631 /* Clear status */ 637 /* Clear status */
632 msleep(LOCK_RETRY_DELAY); 638 msleep(LOCK_RETRY_DELAY);
@@ -686,7 +692,7 @@ static int ioctl_s_routing(struct v4l2_int_device *s,
686 break; /* Input detected */ 692 break; /* Input detected */
687 } 693 }
688 694
689 if ((current_std == STD_INVALID) || (try_count < 0)) 695 if ((current_std == STD_INVALID) || (try_count <= 0))
690 return -EINVAL; 696 return -EINVAL;
691 697
692 decoder->current_std = current_std; 698 decoder->current_std = current_std;
@@ -719,10 +725,9 @@ ioctl_queryctrl(struct v4l2_int_device *s, struct v4l2_queryctrl *qctrl)
719 725
720 switch (qctrl->id) { 726 switch (qctrl->id) {
721 case V4L2_CID_BRIGHTNESS: 727 case V4L2_CID_BRIGHTNESS:
722 /* Brightness supported is same as standard one (0-255), 728 /* Brightness supported is (0-255),
723 * so make use of standard API provided.
724 */ 729 */
725 err = v4l2_ctrl_query_fill_std(qctrl); 730 err = v4l2_ctrl_query_fill(qctrl, 0, 255, 1, 128);
726 break; 731 break;
727 case V4L2_CID_CONTRAST: 732 case V4L2_CID_CONTRAST:
728 case V4L2_CID_SATURATION: 733 case V4L2_CID_SATURATION:
@@ -779,16 +784,16 @@ ioctl_g_ctrl(struct v4l2_int_device *s, struct v4l2_control *ctrl)
779 784
780 switch (ctrl->id) { 785 switch (ctrl->id) {
781 case V4L2_CID_BRIGHTNESS: 786 case V4L2_CID_BRIGHTNESS:
782 ctrl->value = tvp514x_reg_list[REG_BRIGHTNESS].val; 787 ctrl->value = decoder->tvp514x_regs[REG_BRIGHTNESS].val;
783 break; 788 break;
784 case V4L2_CID_CONTRAST: 789 case V4L2_CID_CONTRAST:
785 ctrl->value = tvp514x_reg_list[REG_CONTRAST].val; 790 ctrl->value = decoder->tvp514x_regs[REG_CONTRAST].val;
786 break; 791 break;
787 case V4L2_CID_SATURATION: 792 case V4L2_CID_SATURATION:
788 ctrl->value = tvp514x_reg_list[REG_SATURATION].val; 793 ctrl->value = decoder->tvp514x_regs[REG_SATURATION].val;
789 break; 794 break;
790 case V4L2_CID_HUE: 795 case V4L2_CID_HUE:
791 ctrl->value = tvp514x_reg_list[REG_HUE].val; 796 ctrl->value = decoder->tvp514x_regs[REG_HUE].val;
792 if (ctrl->value == 0x7F) 797 if (ctrl->value == 0x7F)
793 ctrl->value = 180; 798 ctrl->value = 180;
794 else if (ctrl->value == 0x80) 799 else if (ctrl->value == 0x80)
@@ -798,7 +803,7 @@ ioctl_g_ctrl(struct v4l2_int_device *s, struct v4l2_control *ctrl)
798 803
799 break; 804 break;
800 case V4L2_CID_AUTOGAIN: 805 case V4L2_CID_AUTOGAIN:
801 ctrl->value = tvp514x_reg_list[REG_AFE_GAIN_CTRL].val; 806 ctrl->value = decoder->tvp514x_regs[REG_AFE_GAIN_CTRL].val;
802 if ((ctrl->value & 0x3) == 3) 807 if ((ctrl->value & 0x3) == 3)
803 ctrl->value = 1; 808 ctrl->value = 1;
804 else 809 else
@@ -848,7 +853,7 @@ ioctl_s_ctrl(struct v4l2_int_device *s, struct v4l2_control *ctrl)
848 value); 853 value);
849 if (err) 854 if (err)
850 return err; 855 return err;
851 tvp514x_reg_list[REG_BRIGHTNESS].val = value; 856 decoder->tvp514x_regs[REG_BRIGHTNESS].val = value;
852 break; 857 break;
853 case V4L2_CID_CONTRAST: 858 case V4L2_CID_CONTRAST:
854 if (ctrl->value < 0 || ctrl->value > 255) { 859 if (ctrl->value < 0 || ctrl->value > 255) {
@@ -861,7 +866,7 @@ ioctl_s_ctrl(struct v4l2_int_device *s, struct v4l2_control *ctrl)
861 value); 866 value);
862 if (err) 867 if (err)
863 return err; 868 return err;
864 tvp514x_reg_list[REG_CONTRAST].val = value; 869 decoder->tvp514x_regs[REG_CONTRAST].val = value;
865 break; 870 break;
866 case V4L2_CID_SATURATION: 871 case V4L2_CID_SATURATION:
867 if (ctrl->value < 0 || ctrl->value > 255) { 872 if (ctrl->value < 0 || ctrl->value > 255) {
@@ -874,7 +879,7 @@ ioctl_s_ctrl(struct v4l2_int_device *s, struct v4l2_control *ctrl)
874 value); 879 value);
875 if (err) 880 if (err)
876 return err; 881 return err;
877 tvp514x_reg_list[REG_SATURATION].val = value; 882 decoder->tvp514x_regs[REG_SATURATION].val = value;
878 break; 883 break;
879 case V4L2_CID_HUE: 884 case V4L2_CID_HUE:
880 if (value == 180) 885 if (value == 180)
@@ -893,7 +898,7 @@ ioctl_s_ctrl(struct v4l2_int_device *s, struct v4l2_control *ctrl)
893 value); 898 value);
894 if (err) 899 if (err)
895 return err; 900 return err;
896 tvp514x_reg_list[REG_HUE].val = value; 901 decoder->tvp514x_regs[REG_HUE].val = value;
897 break; 902 break;
898 case V4L2_CID_AUTOGAIN: 903 case V4L2_CID_AUTOGAIN:
899 if (value == 1) 904 if (value == 1)
@@ -910,7 +915,7 @@ ioctl_s_ctrl(struct v4l2_int_device *s, struct v4l2_control *ctrl)
910 value); 915 value);
911 if (err) 916 if (err)
912 return err; 917 return err;
913 tvp514x_reg_list[REG_AFE_GAIN_CTRL].val = value; 918 decoder->tvp514x_regs[REG_AFE_GAIN_CTRL].val = value;
914 break; 919 break;
915 default: 920 default:
916 v4l_err(decoder->client, 921 v4l_err(decoder->client,
@@ -1275,7 +1280,7 @@ static int ioctl_init(struct v4l2_int_device *s)
1275 struct tvp514x_decoder *decoder = s->priv; 1280 struct tvp514x_decoder *decoder = s->priv;
1276 1281
1277 /* Set default standard to auto */ 1282 /* Set default standard to auto */
1278 tvp514x_reg_list[REG_VIDEO_STD].val = 1283 decoder->tvp514x_regs[REG_VIDEO_STD].val =
1279 VIDEO_STD_AUTO_SWITCH_BIT; 1284 VIDEO_STD_AUTO_SWITCH_BIT;
1280 1285
1281 return tvp514x_configure(decoder); 1286 return tvp514x_configure(decoder);
@@ -1344,11 +1349,6 @@ static struct v4l2_int_ioctl_desc tvp514x_ioctl_desc[] = {
1344 (v4l2_int_ioctl_func *) ioctl_s_routing}, 1349 (v4l2_int_ioctl_func *) ioctl_s_routing},
1345}; 1350};
1346 1351
1347static struct v4l2_int_slave tvp514x_slave = {
1348 .ioctls = tvp514x_ioctl_desc,
1349 .num_ioctls = ARRAY_SIZE(tvp514x_ioctl_desc),
1350};
1351
1352static struct tvp514x_decoder tvp514x_dev = { 1352static struct tvp514x_decoder tvp514x_dev = {
1353 .state = STATE_NOT_DETECTED, 1353 .state = STATE_NOT_DETECTED,
1354 1354
@@ -1369,17 +1369,15 @@ static struct tvp514x_decoder tvp514x_dev = {
1369 .current_std = STD_NTSC_MJ, 1369 .current_std = STD_NTSC_MJ,
1370 .std_list = tvp514x_std_list, 1370 .std_list = tvp514x_std_list,
1371 .num_stds = ARRAY_SIZE(tvp514x_std_list), 1371 .num_stds = ARRAY_SIZE(tvp514x_std_list),
1372 1372 .v4l2_int_device = {
1373}; 1373 .module = THIS_MODULE,
1374 1374 .name = TVP514X_MODULE_NAME,
1375static struct v4l2_int_device tvp514x_int_device = { 1375 .type = v4l2_int_type_slave,
1376 .module = THIS_MODULE, 1376 },
1377 .name = TVP514X_MODULE_NAME, 1377 .tvp514x_slave = {
1378 .priv = &tvp514x_dev, 1378 .ioctls = tvp514x_ioctl_desc,
1379 .type = v4l2_int_type_slave, 1379 .num_ioctls = ARRAY_SIZE(tvp514x_ioctl_desc),
1380 .u = { 1380 },
1381 .slave = &tvp514x_slave,
1382 },
1383}; 1381};
1384 1382
1385/** 1383/**
@@ -1392,26 +1390,37 @@ static struct v4l2_int_device tvp514x_int_device = {
1392static int 1390static int
1393tvp514x_probe(struct i2c_client *client, const struct i2c_device_id *id) 1391tvp514x_probe(struct i2c_client *client, const struct i2c_device_id *id)
1394{ 1392{
1395 struct tvp514x_decoder *decoder = &tvp514x_dev; 1393 struct tvp514x_decoder *decoder;
1396 int err; 1394 int err;
1397 1395
1398 /* Check if the adapter supports the needed features */ 1396 /* Check if the adapter supports the needed features */
1399 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 1397 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
1400 return -EIO; 1398 return -EIO;
1401 1399
1402 decoder->pdata = client->dev.platform_data; 1400 decoder = kzalloc(sizeof(*decoder), GFP_KERNEL);
1403 if (!decoder->pdata) { 1401 if (!decoder)
1402 return -ENOMEM;
1403
1404 if (!client->dev.platform_data) {
1404 v4l_err(client, "No platform data!!\n"); 1405 v4l_err(client, "No platform data!!\n");
1405 return -ENODEV; 1406 err = -ENODEV;
1407 goto out_free;
1406 } 1408 }
1409
1410 *decoder = tvp514x_dev;
1411 decoder->v4l2_int_device.priv = decoder;
1412 decoder->pdata = client->dev.platform_data;
1413 decoder->v4l2_int_device.u.slave = &decoder->tvp514x_slave;
1414 memcpy(decoder->tvp514x_regs, tvp514x_reg_list_default,
1415 sizeof(tvp514x_reg_list_default));
1407 /* 1416 /*
1408 * Fetch platform specific data, and configure the 1417 * Fetch platform specific data, and configure the
1409 * tvp514x_reg_list[] accordingly. Since this is one 1418 * tvp514x_reg_list[] accordingly. Since this is one
1410 * time configuration, no need to preserve. 1419 * time configuration, no need to preserve.
1411 */ 1420 */
1412 tvp514x_reg_list[REG_OUTPUT_FORMATTER2].val |= 1421 decoder->tvp514x_regs[REG_OUTPUT_FORMATTER2].val |=
1413 (decoder->pdata->clk_polarity << 1); 1422 (decoder->pdata->clk_polarity << 1);
1414 tvp514x_reg_list[REG_SYNC_CONTROL].val |= 1423 decoder->tvp514x_regs[REG_SYNC_CONTROL].val |=
1415 ((decoder->pdata->hs_polarity << 2) | 1424 ((decoder->pdata->hs_polarity << 2) |
1416 (decoder->pdata->vs_polarity << 3)); 1425 (decoder->pdata->vs_polarity << 3));
1417 /* 1426 /*
@@ -1419,23 +1428,27 @@ tvp514x_probe(struct i2c_client *client, const struct i2c_device_id *id)
1419 */ 1428 */
1420 decoder->id = (struct i2c_device_id *)id; 1429 decoder->id = (struct i2c_device_id *)id;
1421 /* Attach to Master */ 1430 /* Attach to Master */
1422 strcpy(tvp514x_int_device.u.slave->attach_to, decoder->pdata->master); 1431 strcpy(decoder->v4l2_int_device.u.slave->attach_to,
1423 decoder->v4l2_int_device = &tvp514x_int_device; 1432 decoder->pdata->master);
1424 decoder->client = client; 1433 decoder->client = client;
1425 i2c_set_clientdata(client, decoder); 1434 i2c_set_clientdata(client, decoder);
1426 1435
1427 /* Register with V4L2 layer as slave device */ 1436 /* Register with V4L2 layer as slave device */
1428 err = v4l2_int_device_register(decoder->v4l2_int_device); 1437 err = v4l2_int_device_register(&decoder->v4l2_int_device);
1429 if (err) { 1438 if (err) {
1430 i2c_set_clientdata(client, NULL); 1439 i2c_set_clientdata(client, NULL);
1431 v4l_err(client, 1440 v4l_err(client,
1432 "Unable to register to v4l2. Err[%d]\n", err); 1441 "Unable to register to v4l2. Err[%d]\n", err);
1442 goto out_free;
1433 1443
1434 } else 1444 } else
1435 v4l_info(client, "Registered to v4l2 master %s!!\n", 1445 v4l_info(client, "Registered to v4l2 master %s!!\n",
1436 decoder->pdata->master); 1446 decoder->pdata->master);
1437
1438 return 0; 1447 return 0;
1448
1449out_free:
1450 kfree(decoder);
1451 return err;
1439} 1452}
1440 1453
1441/** 1454/**
@@ -1452,9 +1465,9 @@ static int __exit tvp514x_remove(struct i2c_client *client)
1452 if (!client->adapter) 1465 if (!client->adapter)
1453 return -ENODEV; /* our client isn't attached */ 1466 return -ENODEV; /* our client isn't attached */
1454 1467
1455 v4l2_int_device_unregister(decoder->v4l2_int_device); 1468 v4l2_int_device_unregister(&decoder->v4l2_int_device);
1456 i2c_set_clientdata(client, NULL); 1469 i2c_set_clientdata(client, NULL);
1457 1470 kfree(decoder);
1458 return 0; 1471 return 0;
1459} 1472}
1460/* 1473/*
diff --git a/drivers/media/video/tvp5150.c b/drivers/media/video/tvp5150.c
index 2cd64ef27b95..3a5a95f134b4 100644
--- a/drivers/media/video/tvp5150.c
+++ b/drivers/media/video/tvp5150.c
@@ -8,7 +8,6 @@
8#include <linux/i2c.h> 8#include <linux/i2c.h>
9#include <linux/videodev2.h> 9#include <linux/videodev2.h>
10#include <linux/delay.h> 10#include <linux/delay.h>
11#include <linux/video_decoder.h>
12#include <media/v4l2-device.h> 11#include <media/v4l2-device.h>
13#include <media/tvp5150.h> 12#include <media/tvp5150.h>
14#include <media/v4l2-i2c-drv-legacy.h> 13#include <media/v4l2-i2c-drv-legacy.h>
@@ -632,7 +631,7 @@ static int tvp5150_g_sliced_vbi_cap(struct v4l2_subdev *sd,
632 const struct i2c_vbi_ram_value *regs = vbi_ram_default; 631 const struct i2c_vbi_ram_value *regs = vbi_ram_default;
633 int line; 632 int line;
634 633
635 v4l2_dbg(1, debug, sd, "VIDIOC_G_SLICED_VBI_CAP\n"); 634 v4l2_dbg(1, debug, sd, "g_sliced_vbi_cap\n");
636 memset(cap, 0, sizeof *cap); 635 memset(cap, 0, sizeof *cap);
637 636
638 while (regs->reg != (u16)-1 ) { 637 while (regs->reg != (u16)-1 ) {
@@ -831,7 +830,7 @@ static int tvp5150_reset(struct v4l2_subdev *sd, u32 val)
831 830
832static int tvp5150_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 831static int tvp5150_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
833{ 832{
834 v4l2_dbg(1, debug, sd, "VIDIOC_G_CTRL called\n"); 833 v4l2_dbg(1, debug, sd, "g_ctrl called\n");
835 834
836 switch (ctrl->id) { 835 switch (ctrl->id) {
837 case V4L2_CID_BRIGHTNESS: 836 case V4L2_CID_BRIGHTNESS:
@@ -861,7 +860,7 @@ static int tvp5150_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
861 if (ctrl->value < tvp5150_qctrl[i].minimum || 860 if (ctrl->value < tvp5150_qctrl[i].minimum ||
862 ctrl->value > tvp5150_qctrl[i].maximum) 861 ctrl->value > tvp5150_qctrl[i].maximum)
863 return -ERANGE; 862 return -ERANGE;
864 v4l2_dbg(1, debug, sd, "VIDIOC_S_CTRL: id=%d, value=%d\n", 863 v4l2_dbg(1, debug, sd, "s_ctrl: id=%d, value=%d\n",
865 ctrl->id, ctrl->value); 864 ctrl->id, ctrl->value);
866 break; 865 break;
867 } 866 }
@@ -1015,7 +1014,7 @@ static int tvp5150_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc)
1015{ 1014{
1016 int i; 1015 int i;
1017 1016
1018 v4l2_dbg(1, debug, sd, "VIDIOC_QUERYCTRL called\n"); 1017 v4l2_dbg(1, debug, sd, "queryctrl called\n");
1019 1018
1020 for (i = 0; i < ARRAY_SIZE(tvp5150_qctrl); i++) 1019 for (i = 0; i < ARRAY_SIZE(tvp5150_qctrl); i++)
1021 if (qc->id && qc->id == tvp5150_qctrl[i].id) { 1020 if (qc->id && qc->id == tvp5150_qctrl[i].id) {
@@ -1126,7 +1125,6 @@ MODULE_DEVICE_TABLE(i2c, tvp5150_id);
1126 1125
1127static struct v4l2_i2c_driver_data v4l2_i2c_data = { 1126static struct v4l2_i2c_driver_data v4l2_i2c_data = {
1128 .name = "tvp5150", 1127 .name = "tvp5150",
1129 .driverid = I2C_DRIVERID_TVP5150,
1130 .command = tvp5150_command, 1128 .command = tvp5150_command,
1131 .probe = tvp5150_probe, 1129 .probe = tvp5150_probe,
1132 .remove = tvp5150_remove, 1130 .remove = tvp5150_remove,
diff --git a/drivers/media/video/tw9910.c b/drivers/media/video/tw9910.c
index 52c0357faa5d..a39947643992 100644
--- a/drivers/media/video/tw9910.c
+++ b/drivers/media/video/tw9910.c
@@ -460,9 +460,11 @@ static int tw9910_mask_set(struct i2c_client *client, u8 command,
460 u8 mask, u8 set) 460 u8 mask, u8 set)
461{ 461{
462 s32 val = i2c_smbus_read_byte_data(client, command); 462 s32 val = i2c_smbus_read_byte_data(client, command);
463 if (val < 0)
464 return val;
463 465
464 val &= ~mask; 466 val &= ~mask;
465 val |= set; 467 val |= set & mask;
466 468
467 return i2c_smbus_write_byte_data(client, command, val); 469 return i2c_smbus_write_byte_data(client, command, val);
468} 470}
@@ -639,8 +641,8 @@ static int tw9910_set_register(struct soc_camera_device *icd,
639} 641}
640#endif 642#endif
641 643
642static int tw9910_set_fmt(struct soc_camera_device *icd, __u32 pixfmt, 644static int tw9910_set_crop(struct soc_camera_device *icd,
643 struct v4l2_rect *rect) 645 struct v4l2_rect *rect)
644{ 646{
645 struct tw9910_priv *priv = container_of(icd, struct tw9910_priv, icd); 647 struct tw9910_priv *priv = container_of(icd, struct tw9910_priv, icd);
646 int ret = -EINVAL; 648 int ret = -EINVAL;
@@ -731,8 +733,33 @@ tw9910_set_fmt_error:
731 return ret; 733 return ret;
732} 734}
733 735
736static int tw9910_set_fmt(struct soc_camera_device *icd,
737 struct v4l2_format *f)
738{
739 struct v4l2_pix_format *pix = &f->fmt.pix;
740 struct v4l2_rect rect = {
741 .left = icd->x_current,
742 .top = icd->y_current,
743 .width = pix->width,
744 .height = pix->height,
745 };
746 int i;
747
748 /*
749 * check color format
750 */
751 for (i = 0; i < ARRAY_SIZE(tw9910_color_fmt); i++)
752 if (pix->pixelformat == tw9910_color_fmt[i].fourcc)
753 break;
754
755 if (i == ARRAY_SIZE(tw9910_color_fmt))
756 return -EINVAL;
757
758 return tw9910_set_crop(icd, &rect);
759}
760
734static int tw9910_try_fmt(struct soc_camera_device *icd, 761static int tw9910_try_fmt(struct soc_camera_device *icd,
735 struct v4l2_format *f) 762 struct v4l2_format *f)
736{ 763{
737 struct v4l2_pix_format *pix = &f->fmt.pix; 764 struct v4l2_pix_format *pix = &f->fmt.pix;
738 const struct tw9910_scale_ctrl *scale; 765 const struct tw9910_scale_ctrl *scale;
@@ -820,6 +847,7 @@ static struct soc_camera_ops tw9910_ops = {
820 .release = tw9910_release, 847 .release = tw9910_release,
821 .start_capture = tw9910_start_capture, 848 .start_capture = tw9910_start_capture,
822 .stop_capture = tw9910_stop_capture, 849 .stop_capture = tw9910_stop_capture,
850 .set_crop = tw9910_set_crop,
823 .set_fmt = tw9910_set_fmt, 851 .set_fmt = tw9910_set_fmt,
824 .try_fmt = tw9910_try_fmt, 852 .try_fmt = tw9910_try_fmt,
825 .set_bus_param = tw9910_set_bus_param, 853 .set_bus_param = tw9910_set_bus_param,
diff --git a/drivers/media/video/upd64031a.c b/drivers/media/video/upd64031a.c
index f4522bb08916..c0ac651bb358 100644
--- a/drivers/media/video/upd64031a.c
+++ b/drivers/media/video/upd64031a.c
@@ -187,11 +187,6 @@ static int upd64031a_s_register(struct v4l2_subdev *sd, struct v4l2_dbg_register
187} 187}
188#endif 188#endif
189 189
190static int upd64031a_command(struct i2c_client *client, unsigned cmd, void *arg)
191{
192 return v4l2_subdev_command(i2c_get_clientdata(client), cmd, arg);
193}
194
195/* ----------------------------------------------------------------------- */ 190/* ----------------------------------------------------------------------- */
196 191
197static const struct v4l2_subdev_core_ops upd64031a_core_ops = { 192static const struct v4l2_subdev_core_ops upd64031a_core_ops = {
@@ -267,8 +262,6 @@ MODULE_DEVICE_TABLE(i2c, upd64031a_id);
267 262
268static struct v4l2_i2c_driver_data v4l2_i2c_data = { 263static struct v4l2_i2c_driver_data v4l2_i2c_data = {
269 .name = "upd64031a", 264 .name = "upd64031a",
270 .driverid = I2C_DRIVERID_UPD64031A,
271 .command = upd64031a_command,
272 .probe = upd64031a_probe, 265 .probe = upd64031a_probe,
273 .remove = upd64031a_remove, 266 .remove = upd64031a_remove,
274 .id_table = upd64031a_id, 267 .id_table = upd64031a_id,
diff --git a/drivers/media/video/upd64083.c b/drivers/media/video/upd64083.c
index a5fb74bf2407..410c915d51fa 100644
--- a/drivers/media/video/upd64083.c
+++ b/drivers/media/video/upd64083.c
@@ -164,11 +164,6 @@ static int upd64083_log_status(struct v4l2_subdev *sd)
164 return 0; 164 return 0;
165} 165}
166 166
167static int upd64083_command(struct i2c_client *client, unsigned cmd, void *arg)
168{
169 return v4l2_subdev_command(i2c_get_clientdata(client), cmd, arg);
170}
171
172/* ----------------------------------------------------------------------- */ 167/* ----------------------------------------------------------------------- */
173 168
174static const struct v4l2_subdev_core_ops upd64083_core_ops = { 169static const struct v4l2_subdev_core_ops upd64083_core_ops = {
@@ -239,8 +234,6 @@ MODULE_DEVICE_TABLE(i2c, upd64083_id);
239 234
240static struct v4l2_i2c_driver_data v4l2_i2c_data = { 235static struct v4l2_i2c_driver_data v4l2_i2c_data = {
241 .name = "upd64083", 236 .name = "upd64083",
242 .driverid = I2C_DRIVERID_UPD64083,
243 .command = upd64083_command,
244 .probe = upd64083_probe, 237 .probe = upd64083_probe,
245 .remove = upd64083_remove, 238 .remove = upd64083_remove,
246 .id_table = upd64083_id, 239 .id_table = upd64083_id,
diff --git a/drivers/media/video/usbvideo/vicam.c b/drivers/media/video/usbvideo/vicam.c
index 2f1106338c08..8d73979596f9 100644
--- a/drivers/media/video/usbvideo/vicam.c
+++ b/drivers/media/video/usbvideo/vicam.c
@@ -191,7 +191,7 @@ initialize_camera(struct vicam_camera *cam)
191{ 191{
192 int err; 192 int err;
193 const struct ihex_binrec *rec; 193 const struct ihex_binrec *rec;
194 const struct firmware *fw; 194 const struct firmware *uninitialized_var(fw);
195 195
196 err = request_ihex_firmware(&fw, "vicam/firmware.fw", &cam->udev->dev); 196 err = request_ihex_firmware(&fw, "vicam/firmware.fw", &cam->udev->dev);
197 if (err) { 197 if (err) {
diff --git a/drivers/media/video/usbvision/usbvision-core.c b/drivers/media/video/usbvision/usbvision-core.c
index 9e4f50639975..a0feb1c97736 100644
--- a/drivers/media/video/usbvision/usbvision-core.c
+++ b/drivers/media/video/usbvision/usbvision-core.c
@@ -36,7 +36,6 @@
36#include <linux/spinlock.h> 36#include <linux/spinlock.h>
37#include <asm/io.h> 37#include <asm/io.h>
38#include <linux/videodev2.h> 38#include <linux/videodev2.h>
39#include <linux/video_decoder.h>
40#include <linux/i2c.h> 39#include <linux/i2c.h>
41 40
42#include <media/saa7115.h> 41#include <media/saa7115.h>
@@ -381,8 +380,9 @@ int usbvision_scratch_alloc(struct usb_usbvision *usbvision)
381 usbvision->scratch = vmalloc_32(scratch_buf_size); 380 usbvision->scratch = vmalloc_32(scratch_buf_size);
382 scratch_reset(usbvision); 381 scratch_reset(usbvision);
383 if(usbvision->scratch == NULL) { 382 if(usbvision->scratch == NULL) {
384 err("%s: unable to allocate %d bytes for scratch", 383 dev_err(&usbvision->dev->dev,
385 __func__, scratch_buf_size); 384 "%s: unable to allocate %d bytes for scratch\n",
385 __func__, scratch_buf_size);
386 return -ENOMEM; 386 return -ENOMEM;
387 } 387 }
388 return 0; 388 return 0;
@@ -491,8 +491,9 @@ int usbvision_decompress_alloc(struct usb_usbvision *usbvision)
491 int IFB_size = MAX_FRAME_WIDTH * MAX_FRAME_HEIGHT * 3 / 2; 491 int IFB_size = MAX_FRAME_WIDTH * MAX_FRAME_HEIGHT * 3 / 2;
492 usbvision->IntraFrameBuffer = vmalloc_32(IFB_size); 492 usbvision->IntraFrameBuffer = vmalloc_32(IFB_size);
493 if (usbvision->IntraFrameBuffer == NULL) { 493 if (usbvision->IntraFrameBuffer == NULL) {
494 err("%s: unable to allocate %d for compr. frame buffer", 494 dev_err(&usbvision->dev->dev,
495 __func__, IFB_size); 495 "%s: unable to allocate %d for compr. frame buffer\n",
496 __func__, IFB_size);
496 return -ENOMEM; 497 return -ENOMEM;
497 } 498 }
498 return 0; 499 return 0;
@@ -1514,8 +1515,9 @@ static void usbvision_isocIrq(struct urb *urb)
1514 errCode = usb_submit_urb (urb, GFP_ATOMIC); 1515 errCode = usb_submit_urb (urb, GFP_ATOMIC);
1515 1516
1516 if(errCode) { 1517 if(errCode) {
1517 err("%s: usb_submit_urb failed: error %d", 1518 dev_err(&usbvision->dev->dev,
1518 __func__, errCode); 1519 "%s: usb_submit_urb failed: error %d\n",
1520 __func__, errCode);
1519 } 1521 }
1520 1522
1521 return; 1523 return;
@@ -1546,7 +1548,8 @@ int usbvision_read_reg(struct usb_usbvision *usbvision, unsigned char reg)
1546 0, (__u16) reg, buffer, 1, HZ); 1548 0, (__u16) reg, buffer, 1, HZ);
1547 1549
1548 if (errCode < 0) { 1550 if (errCode < 0) {
1549 err("%s: failed: error %d", __func__, errCode); 1551 dev_err(&usbvision->dev->dev,
1552 "%s: failed: error %d\n", __func__, errCode);
1550 return errCode; 1553 return errCode;
1551 } 1554 }
1552 return buffer[0]; 1555 return buffer[0];
@@ -1574,7 +1577,8 @@ int usbvision_write_reg(struct usb_usbvision *usbvision, unsigned char reg,
1574 USB_RECIP_ENDPOINT, 0, (__u16) reg, &value, 1, HZ); 1577 USB_RECIP_ENDPOINT, 0, (__u16) reg, &value, 1, HZ);
1575 1578
1576 if (errCode < 0) { 1579 if (errCode < 0) {
1577 err("%s: failed: error %d", __func__, errCode); 1580 dev_err(&usbvision->dev->dev,
1581 "%s: failed: error %d\n", __func__, errCode);
1578 } 1582 }
1579 return errCode; 1583 return errCode;
1580} 1584}
@@ -1850,7 +1854,8 @@ int usbvision_set_output(struct usb_usbvision *usbvision, int width,
1850 0, (__u16) USBVISION_LXSIZE_O, value, 4, HZ); 1854 0, (__u16) USBVISION_LXSIZE_O, value, 4, HZ);
1851 1855
1852 if (errCode < 0) { 1856 if (errCode < 0) {
1853 err("%s failed: error %d", __func__, errCode); 1857 dev_err(&usbvision->dev->dev,
1858 "%s failed: error %d\n", __func__, errCode);
1854 return errCode; 1859 return errCode;
1855 } 1860 }
1856 usbvision->curwidth = usbvision->stretch_width * UsbWidth; 1861 usbvision->curwidth = usbvision->stretch_width * UsbWidth;
@@ -2236,7 +2241,7 @@ static int usbvision_set_dram_settings(struct usb_usbvision *usbvision)
2236 (__u16) USBVISION_DRM_PRM1, value, 8, HZ); 2241 (__u16) USBVISION_DRM_PRM1, value, 8, HZ);
2237 2242
2238 if (rc < 0) { 2243 if (rc < 0) {
2239 err("%sERROR=%d", __func__, rc); 2244 dev_err(&usbvision->dev->dev, "%sERROR=%d\n", __func__, rc);
2240 return rc; 2245 return rc;
2241 } 2246 }
2242 2247
@@ -2432,8 +2437,9 @@ int usbvision_set_alternate(struct usb_usbvision *dev)
2432 PDEBUG(DBG_FUNC,"setting alternate %d with wMaxPacketSize=%u", dev->ifaceAlt,dev->isocPacketSize); 2437 PDEBUG(DBG_FUNC,"setting alternate %d with wMaxPacketSize=%u", dev->ifaceAlt,dev->isocPacketSize);
2433 errCode = usb_set_interface(dev->dev, dev->iface, dev->ifaceAlt); 2438 errCode = usb_set_interface(dev->dev, dev->iface, dev->ifaceAlt);
2434 if (errCode < 0) { 2439 if (errCode < 0) {
2435 err ("cannot change alternate number to %d (error=%i)", 2440 dev_err(&dev->dev->dev,
2436 dev->ifaceAlt, errCode); 2441 "cannot change alternate number to %d (error=%i)\n",
2442 dev->ifaceAlt, errCode);
2437 return errCode; 2443 return errCode;
2438 } 2444 }
2439 } 2445 }
@@ -2484,7 +2490,8 @@ int usbvision_init_isoc(struct usb_usbvision *usbvision)
2484 2490
2485 urb = usb_alloc_urb(USBVISION_URB_FRAMES, GFP_KERNEL); 2491 urb = usb_alloc_urb(USBVISION_URB_FRAMES, GFP_KERNEL);
2486 if (urb == NULL) { 2492 if (urb == NULL) {
2487 err("%s: usb_alloc_urb() failed", __func__); 2493 dev_err(&usbvision->dev->dev,
2494 "%s: usb_alloc_urb() failed\n", __func__);
2488 return -ENOMEM; 2495 return -ENOMEM;
2489 } 2496 }
2490 usbvision->sbuf[bufIdx].urb = urb; 2497 usbvision->sbuf[bufIdx].urb = urb;
@@ -2496,7 +2503,7 @@ int usbvision_init_isoc(struct usb_usbvision *usbvision)
2496 urb->dev = dev; 2503 urb->dev = dev;
2497 urb->context = usbvision; 2504 urb->context = usbvision;
2498 urb->pipe = usb_rcvisocpipe(dev, usbvision->video_endp); 2505 urb->pipe = usb_rcvisocpipe(dev, usbvision->video_endp);
2499 urb->transfer_flags = URB_ISO_ASAP; 2506 urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
2500 urb->interval = 1; 2507 urb->interval = 1;
2501 urb->transfer_buffer = usbvision->sbuf[bufIdx].data; 2508 urb->transfer_buffer = usbvision->sbuf[bufIdx].data;
2502 urb->complete = usbvision_isocIrq; 2509 urb->complete = usbvision_isocIrq;
@@ -2516,8 +2523,9 @@ int usbvision_init_isoc(struct usb_usbvision *usbvision)
2516 errCode = usb_submit_urb(usbvision->sbuf[bufIdx].urb, 2523 errCode = usb_submit_urb(usbvision->sbuf[bufIdx].urb,
2517 GFP_KERNEL); 2524 GFP_KERNEL);
2518 if (errCode) { 2525 if (errCode) {
2519 err("%s: usb_submit_urb(%d) failed: error %d", 2526 dev_err(&usbvision->dev->dev,
2520 __func__, bufIdx, errCode); 2527 "%s: usb_submit_urb(%d) failed: error %d\n",
2528 __func__, bufIdx, errCode);
2521 } 2529 }
2522 } 2530 }
2523 2531
@@ -2566,8 +2574,9 @@ void usbvision_stop_isoc(struct usb_usbvision *usbvision)
2566 errCode = usb_set_interface(usbvision->dev, usbvision->iface, 2574 errCode = usb_set_interface(usbvision->dev, usbvision->iface,
2567 usbvision->ifaceAlt); 2575 usbvision->ifaceAlt);
2568 if (errCode < 0) { 2576 if (errCode < 0) {
2569 err("%s: usb_set_interface() failed: error %d", 2577 dev_err(&usbvision->dev->dev,
2570 __func__, errCode); 2578 "%s: usb_set_interface() failed: error %d\n",
2579 __func__, errCode);
2571 usbvision->last_error = errCode; 2580 usbvision->last_error = errCode;
2572 } 2581 }
2573 regValue = (16-usbvision_read_reg(usbvision, USBVISION_ALTER_REG)) & 0x0F; 2582 regValue = (16-usbvision_read_reg(usbvision, USBVISION_ALTER_REG)) & 0x0F;
@@ -2623,7 +2632,7 @@ int usbvision_muxsel(struct usb_usbvision *usbvision, int channel)
2623 } 2632 }
2624 route.input = mode[channel]; 2633 route.input = mode[channel];
2625 route.output = 0; 2634 route.output = 0;
2626 call_i2c_clients(usbvision, VIDIOC_INT_S_VIDEO_ROUTING,&route); 2635 call_all(usbvision, video, s_routing, &route);
2627 usbvision_set_audio(usbvision, audio[channel]); 2636 usbvision_set_audio(usbvision, audio[channel]);
2628 return 0; 2637 return 0;
2629} 2638}
diff --git a/drivers/media/video/usbvision/usbvision-i2c.c b/drivers/media/video/usbvision/usbvision-i2c.c
index 6b66ae4f430f..dd2f8f27c73b 100644
--- a/drivers/media/video/usbvision/usbvision-i2c.c
+++ b/drivers/media/video/usbvision/usbvision-i2c.c
@@ -119,7 +119,8 @@ static inline int usb_find_address(struct i2c_adapter *i2c_adap,
119 /* try extended address code... */ 119 /* try extended address code... */
120 ret = try_write_address(i2c_adap, addr, retries); 120 ret = try_write_address(i2c_adap, addr, retries);
121 if (ret != 1) { 121 if (ret != 1) {
122 err("died at extended address code, while writing"); 122 dev_err(&i2c_adap->dev,
123 "died at extended address code, while writing\n");
123 return -EREMOTEIO; 124 return -EREMOTEIO;
124 } 125 }
125 add[0] = addr; 126 add[0] = addr;
@@ -128,7 +129,8 @@ static inline int usb_find_address(struct i2c_adapter *i2c_adap,
128 addr |= 0x01; 129 addr |= 0x01;
129 ret = try_read_address(i2c_adap, addr, retries); 130 ret = try_read_address(i2c_adap, addr, retries);
130 if (ret != 1) { 131 if (ret != 1) {
131 err("died at extended address code, while reading"); 132 dev_err(&i2c_adap->dev,
133 "died at extended address code, while reading\n");
132 return -EREMOTEIO; 134 return -EREMOTEIO;
133 } 135 }
134 } 136 }
@@ -200,72 +202,78 @@ static struct i2c_algorithm usbvision_algo = {
200}; 202};
201 203
202 204
203/*
204 * registering functions to load algorithms at runtime
205 */
206static int usbvision_i2c_usb_add_bus(struct i2c_adapter *adap)
207{
208 PDEBUG(DBG_I2C, "I2C debugging is enabled [i2c]");
209 PDEBUG(DBG_I2C, "ALGO debugging is enabled [i2c]");
210
211 /* register new adapter to i2c module... */
212
213 adap->algo = &usbvision_algo;
214
215 adap->timeout = 100; /* default values, should */
216 adap->retries = 3; /* be replaced by defines */
217
218 i2c_add_adapter(adap);
219
220 PDEBUG(DBG_I2C,"i2c bus for %s registered", adap->name);
221
222 return 0;
223}
224
225/* ----------------------------------------------------------------------- */ 205/* ----------------------------------------------------------------------- */
226/* usbvision specific I2C functions */ 206/* usbvision specific I2C functions */
227/* ----------------------------------------------------------------------- */ 207/* ----------------------------------------------------------------------- */
228static struct i2c_adapter i2c_adap_template; 208static struct i2c_adapter i2c_adap_template;
229static struct i2c_client i2c_client_template;
230 209
231int usbvision_i2c_register(struct usb_usbvision *usbvision) 210int usbvision_i2c_register(struct usb_usbvision *usbvision)
232{ 211{
212 static unsigned short saa711x_addrs[] = {
213 0x4a >> 1, 0x48 >> 1, /* SAA7111, SAA7111A and SAA7113 */
214 0x42 >> 1, 0x40 >> 1, /* SAA7114, SAA7115 and SAA7118 */
215 I2C_CLIENT_END };
216
233 memcpy(&usbvision->i2c_adap, &i2c_adap_template, 217 memcpy(&usbvision->i2c_adap, &i2c_adap_template,
234 sizeof(struct i2c_adapter)); 218 sizeof(struct i2c_adapter));
235 memcpy(&usbvision->i2c_client, &i2c_client_template,
236 sizeof(struct i2c_client));
237 219
238 sprintf(usbvision->i2c_adap.name + strlen(usbvision->i2c_adap.name), 220 sprintf(usbvision->i2c_adap.name + strlen(usbvision->i2c_adap.name),
239 " #%d", usbvision->vdev->num); 221 " #%d", usbvision->vdev->num);
240 PDEBUG(DBG_I2C,"Adaptername: %s", usbvision->i2c_adap.name); 222 PDEBUG(DBG_I2C,"Adaptername: %s", usbvision->i2c_adap.name);
241 usbvision->i2c_adap.dev.parent = &usbvision->dev->dev; 223 usbvision->i2c_adap.dev.parent = &usbvision->dev->dev;
242 224
243 i2c_set_adapdata(&usbvision->i2c_adap, usbvision); 225 i2c_set_adapdata(&usbvision->i2c_adap, &usbvision->v4l2_dev);
244 i2c_set_clientdata(&usbvision->i2c_client, usbvision);
245
246 usbvision->i2c_client.adapter = &usbvision->i2c_adap;
247 226
248 if (usbvision_write_reg(usbvision, USBVISION_SER_MODE, USBVISION_IIC_LRNACK) < 0) { 227 if (usbvision_write_reg(usbvision, USBVISION_SER_MODE, USBVISION_IIC_LRNACK) < 0) {
249 printk(KERN_ERR "usbvision_register: can't write reg\n"); 228 printk(KERN_ERR "usbvision_register: can't write reg\n");
250 return -EBUSY; 229 return -EBUSY;
251 } 230 }
252 231
253#ifdef CONFIG_MODULES 232 PDEBUG(DBG_I2C, "I2C debugging is enabled [i2c]");
233 PDEBUG(DBG_I2C, "ALGO debugging is enabled [i2c]");
234
235 /* register new adapter to i2c module... */
236
237 usbvision->i2c_adap.algo = &usbvision_algo;
238
239 usbvision->i2c_adap.timeout = 100; /* default values, should */
240 usbvision->i2c_adap.retries = 3; /* be replaced by defines */
241
242 i2c_add_adapter(&usbvision->i2c_adap);
243
244 PDEBUG(DBG_I2C, "i2c bus for %s registered", usbvision->i2c_adap.name);
245
254 /* Request the load of the i2c modules we need */ 246 /* Request the load of the i2c modules we need */
255 switch (usbvision_device_data[usbvision->DevModel].Codec) { 247 switch (usbvision_device_data[usbvision->DevModel].Codec) {
256 case CODEC_SAA7113: 248 case CODEC_SAA7113:
257 request_module("saa7115");
258 break;
259 case CODEC_SAA7111: 249 case CODEC_SAA7111:
260 request_module("saa7115"); 250 v4l2_i2c_new_probed_subdev(&usbvision->i2c_adap, "saa7115",
251 "saa7115_auto", saa711x_addrs);
261 break; 252 break;
262 } 253 }
263 if (usbvision_device_data[usbvision->DevModel].Tuner == 1) { 254 if (usbvision_device_data[usbvision->DevModel].Tuner == 1) {
264 request_module("tuner"); 255 struct v4l2_subdev *sd;
256 enum v4l2_i2c_tuner_type type;
257 struct tuner_setup tun_setup;
258
259 sd = v4l2_i2c_new_probed_subdev(&usbvision->i2c_adap, "tuner",
260 "tuner", v4l2_i2c_tuner_addrs(ADDRS_DEMOD));
261 /* depending on whether we found a demod or not, select
262 the tuner type. */
263 type = sd ? ADDRS_TV_WITH_DEMOD : ADDRS_TV;
264
265 sd = v4l2_i2c_new_probed_subdev(&usbvision->i2c_adap, "tuner",
266 "tuner", v4l2_i2c_tuner_addrs(type));
267
268 if (usbvision->tuner_type != -1) {
269 tun_setup.mode_mask = T_ANALOG_TV | T_RADIO;
270 tun_setup.type = usbvision->tuner_type;
271 tun_setup.addr = v4l2_i2c_subdev_addr(sd);
272 call_all(usbvision, tuner, s_type_addr, &tun_setup);
273 }
265 } 274 }
266#endif
267 275
268 return usbvision_i2c_usb_add_bus(&usbvision->i2c_adap); 276 return 0;
269} 277}
270 278
271int usbvision_i2c_unregister(struct usb_usbvision *usbvision) 279int usbvision_i2c_unregister(struct usb_usbvision *usbvision)
@@ -278,67 +286,6 @@ int usbvision_i2c_unregister(struct usb_usbvision *usbvision)
278 return 0; 286 return 0;
279} 287}
280 288
281void call_i2c_clients(struct usb_usbvision *usbvision, unsigned int cmd,
282 void *arg)
283{
284 i2c_clients_command(&usbvision->i2c_adap, cmd, arg);
285}
286
287static int attach_inform(struct i2c_client *client)
288{
289 struct usb_usbvision *usbvision;
290
291 usbvision = (struct usb_usbvision *)i2c_get_adapdata(client->adapter);
292
293 switch (client->addr << 1) {
294 case 0x42 << 1:
295 case 0x43 << 1:
296 case 0x4a << 1:
297 case 0x4b << 1:
298 PDEBUG(DBG_I2C,"attach_inform: tda9887 detected.");
299 break;
300 case 0x42:
301 PDEBUG(DBG_I2C,"attach_inform: saa7114 detected.");
302 break;
303 case 0x4a:
304 PDEBUG(DBG_I2C,"attach_inform: saa7113 detected.");
305 break;
306 case 0x48:
307 PDEBUG(DBG_I2C,"attach_inform: saa7111 detected.");
308 break;
309 case 0xa0:
310 PDEBUG(DBG_I2C,"attach_inform: eeprom detected.");
311 break;
312
313 default:
314 {
315 struct tuner_setup tun_setup;
316
317 PDEBUG(DBG_I2C,"attach inform: detected I2C address %x", client->addr << 1);
318 usbvision->tuner_addr = client->addr;
319
320 if ((usbvision->have_tuner) && (usbvision->tuner_type != -1)) {
321 tun_setup.mode_mask = T_ANALOG_TV | T_RADIO;
322 tun_setup.type = usbvision->tuner_type;
323 tun_setup.addr = usbvision->tuner_addr;
324 call_i2c_clients(usbvision, TUNER_SET_TYPE_ADDR, &tun_setup);
325 }
326 }
327 break;
328 }
329 return 0;
330}
331
332static int detach_inform(struct i2c_client *client)
333{
334 struct usb_usbvision *usbvision;
335
336 usbvision = (struct usb_usbvision *)i2c_get_adapdata(client->adapter);
337
338 PDEBUG(DBG_I2C,"usbvision[%d] detaches %s", usbvision->nr, client->name);
339 return 0;
340}
341
342static int 289static int
343usbvision_i2c_read_max4(struct usb_usbvision *usbvision, unsigned char addr, 290usbvision_i2c_read_max4(struct usb_usbvision *usbvision, unsigned char addr,
344 char *buf, short len) 291 char *buf, short len)
@@ -511,14 +458,6 @@ static int usbvision_i2c_read(struct usb_usbvision *usbvision, unsigned char add
511static struct i2c_adapter i2c_adap_template = { 458static struct i2c_adapter i2c_adap_template = {
512 .owner = THIS_MODULE, 459 .owner = THIS_MODULE,
513 .name = "usbvision", 460 .name = "usbvision",
514 .id = I2C_HW_B_BT848, /* FIXME */
515 .client_register = attach_inform,
516 .client_unregister = detach_inform,
517 .class = I2C_CLASS_TV_ANALOG,
518};
519
520static struct i2c_client i2c_client_template = {
521 .name = "usbvision internal",
522}; 461};
523 462
524/* 463/*
diff --git a/drivers/media/video/usbvision/usbvision-video.c b/drivers/media/video/usbvision/usbvision-video.c
index 2622de003a45..fa62a2fd7b22 100644
--- a/drivers/media/video/usbvision/usbvision-video.c
+++ b/drivers/media/video/usbvision/usbvision-video.c
@@ -59,7 +59,6 @@
59#include <linux/spinlock.h> 59#include <linux/spinlock.h>
60#include <asm/io.h> 60#include <asm/io.h>
61#include <linux/videodev2.h> 61#include <linux/videodev2.h>
62#include <linux/video_decoder.h>
63#include <linux/i2c.h> 62#include <linux/i2c.h>
64 63
65#include <media/saa7115.h> 64#include <media/saa7115.h>
@@ -212,7 +211,7 @@ static ssize_t show_hue(struct device *cd,
212 ctrl.id = V4L2_CID_HUE; 211 ctrl.id = V4L2_CID_HUE;
213 ctrl.value = 0; 212 ctrl.value = 0;
214 if(usbvision->user) 213 if(usbvision->user)
215 call_i2c_clients(usbvision, VIDIOC_G_CTRL, &ctrl); 214 call_all(usbvision, core, g_ctrl, &ctrl);
216 return sprintf(buf, "%d\n", ctrl.value); 215 return sprintf(buf, "%d\n", ctrl.value);
217} 216}
218static DEVICE_ATTR(hue, S_IRUGO, show_hue, NULL); 217static DEVICE_ATTR(hue, S_IRUGO, show_hue, NULL);
@@ -227,7 +226,7 @@ static ssize_t show_contrast(struct device *cd,
227 ctrl.id = V4L2_CID_CONTRAST; 226 ctrl.id = V4L2_CID_CONTRAST;
228 ctrl.value = 0; 227 ctrl.value = 0;
229 if(usbvision->user) 228 if(usbvision->user)
230 call_i2c_clients(usbvision, VIDIOC_G_CTRL, &ctrl); 229 call_all(usbvision, core, g_ctrl, &ctrl);
231 return sprintf(buf, "%d\n", ctrl.value); 230 return sprintf(buf, "%d\n", ctrl.value);
232} 231}
233static DEVICE_ATTR(contrast, S_IRUGO, show_contrast, NULL); 232static DEVICE_ATTR(contrast, S_IRUGO, show_contrast, NULL);
@@ -242,7 +241,7 @@ static ssize_t show_brightness(struct device *cd,
242 ctrl.id = V4L2_CID_BRIGHTNESS; 241 ctrl.id = V4L2_CID_BRIGHTNESS;
243 ctrl.value = 0; 242 ctrl.value = 0;
244 if(usbvision->user) 243 if(usbvision->user)
245 call_i2c_clients(usbvision, VIDIOC_G_CTRL, &ctrl); 244 call_all(usbvision, core, g_ctrl, &ctrl);
246 return sprintf(buf, "%d\n", ctrl.value); 245 return sprintf(buf, "%d\n", ctrl.value);
247} 246}
248static DEVICE_ATTR(brightness, S_IRUGO, show_brightness, NULL); 247static DEVICE_ATTR(brightness, S_IRUGO, show_brightness, NULL);
@@ -257,7 +256,7 @@ static ssize_t show_saturation(struct device *cd,
257 ctrl.id = V4L2_CID_SATURATION; 256 ctrl.id = V4L2_CID_SATURATION;
258 ctrl.value = 0; 257 ctrl.value = 0;
259 if(usbvision->user) 258 if(usbvision->user)
260 call_i2c_clients(usbvision, VIDIOC_G_CTRL, &ctrl); 259 call_all(usbvision, core, g_ctrl, &ctrl);
261 return sprintf(buf, "%d\n", ctrl.value); 260 return sprintf(buf, "%d\n", ctrl.value);
262} 261}
263static DEVICE_ATTR(saturation, S_IRUGO, show_saturation, NULL); 262static DEVICE_ATTR(saturation, S_IRUGO, show_saturation, NULL);
@@ -329,7 +328,7 @@ static void usbvision_create_sysfs(struct video_device *vdev)
329 return; 328 return;
330 } while (0); 329 } while (0);
331 330
332 err("%s error: %d\n", __func__, res); 331 dev_err(&vdev->dev, "%s error: %d\n", __func__, res);
333} 332}
334 333
335static void usbvision_remove_sysfs(struct video_device *vdev) 334static void usbvision_remove_sysfs(struct video_device *vdev)
@@ -487,8 +486,9 @@ static int vidioc_g_register (struct file *file, void *priv,
487 /* NT100x has a 8-bit register space */ 486 /* NT100x has a 8-bit register space */
488 errCode = usbvision_read_reg(usbvision, reg->reg&0xff); 487 errCode = usbvision_read_reg(usbvision, reg->reg&0xff);
489 if (errCode < 0) { 488 if (errCode < 0) {
490 err("%s: VIDIOC_DBG_G_REGISTER failed: error %d", 489 dev_err(&usbvision->vdev->dev,
491 __func__, errCode); 490 "%s: VIDIOC_DBG_G_REGISTER failed: error %d\n",
491 __func__, errCode);
492 return errCode; 492 return errCode;
493 } 493 }
494 reg->val = errCode; 494 reg->val = errCode;
@@ -507,8 +507,9 @@ static int vidioc_s_register (struct file *file, void *priv,
507 /* NT100x has a 8-bit register space */ 507 /* NT100x has a 8-bit register space */
508 errCode = usbvision_write_reg(usbvision, reg->reg&0xff, reg->val); 508 errCode = usbvision_write_reg(usbvision, reg->reg&0xff, reg->val);
509 if (errCode < 0) { 509 if (errCode < 0) {
510 err("%s: VIDIOC_DBG_S_REGISTER failed: error %d", 510 dev_err(&usbvision->vdev->dev,
511 __func__, errCode); 511 "%s: VIDIOC_DBG_S_REGISTER failed: error %d\n",
512 __func__, errCode);
512 return errCode; 513 return errCode;
513 } 514 }
514 return 0; 515 return 0;
@@ -524,8 +525,7 @@ static int vidioc_querycap (struct file *file, void *priv,
524 strlcpy(vc->card, 525 strlcpy(vc->card,
525 usbvision_device_data[usbvision->DevModel].ModelString, 526 usbvision_device_data[usbvision->DevModel].ModelString,
526 sizeof(vc->card)); 527 sizeof(vc->card));
527 strlcpy(vc->bus_info, dev_name(&usbvision->dev->dev), 528 usb_make_path(usbvision->dev, vc->bus_info, sizeof(vc->bus_info));
528 sizeof(vc->bus_info));
529 vc->version = USBVISION_DRIVER_VERSION; 529 vc->version = USBVISION_DRIVER_VERSION;
530 vc->capabilities = V4L2_CAP_VIDEO_CAPTURE | 530 vc->capabilities = V4L2_CAP_VIDEO_CAPTURE |
531 V4L2_CAP_AUDIO | 531 V4L2_CAP_AUDIO |
@@ -621,8 +621,7 @@ static int vidioc_s_std (struct file *file, void *priv, v4l2_std_id *id)
621 usbvision->tvnormId=*id; 621 usbvision->tvnormId=*id;
622 622
623 mutex_lock(&usbvision->lock); 623 mutex_lock(&usbvision->lock);
624 call_i2c_clients(usbvision, VIDIOC_S_STD, 624 call_all(usbvision, tuner, s_std, usbvision->tvnormId);
625 &usbvision->tvnormId);
626 mutex_unlock(&usbvision->lock); 625 mutex_unlock(&usbvision->lock);
627 /* propagate the change to the decoder */ 626 /* propagate the change to the decoder */
628 usbvision_muxsel(usbvision, usbvision->ctl_input); 627 usbvision_muxsel(usbvision, usbvision->ctl_input);
@@ -644,7 +643,7 @@ static int vidioc_g_tuner (struct file *file, void *priv,
644 strcpy(vt->name, "Television"); 643 strcpy(vt->name, "Television");
645 } 644 }
646 /* Let clients fill in the remainder of this struct */ 645 /* Let clients fill in the remainder of this struct */
647 call_i2c_clients(usbvision,VIDIOC_G_TUNER,vt); 646 call_all(usbvision, tuner, g_tuner, vt);
648 647
649 return 0; 648 return 0;
650} 649}
@@ -658,7 +657,7 @@ static int vidioc_s_tuner (struct file *file, void *priv,
658 if (!usbvision->have_tuner || vt->index) 657 if (!usbvision->have_tuner || vt->index)
659 return -EINVAL; 658 return -EINVAL;
660 /* let clients handle this */ 659 /* let clients handle this */
661 call_i2c_clients(usbvision,VIDIOC_S_TUNER,vt); 660 call_all(usbvision, tuner, s_tuner, vt);
662 661
663 return 0; 662 return 0;
664} 663}
@@ -689,7 +688,7 @@ static int vidioc_s_frequency (struct file *file, void *priv,
689 return -EINVAL; 688 return -EINVAL;
690 689
691 usbvision->freq = freq->frequency; 690 usbvision->freq = freq->frequency;
692 call_i2c_clients(usbvision, VIDIOC_S_FREQUENCY, freq); 691 call_all(usbvision, tuner, s_frequency, freq);
693 692
694 return 0; 693 return 0;
695} 694}
@@ -698,7 +697,6 @@ static int vidioc_g_audio (struct file *file, void *priv, struct v4l2_audio *a)
698{ 697{
699 struct usb_usbvision *usbvision = video_drvdata(file); 698 struct usb_usbvision *usbvision = video_drvdata(file);
700 699
701 memset(a,0,sizeof(*a));
702 if(usbvision->radio) { 700 if(usbvision->radio) {
703 strcpy(a->name,"Radio"); 701 strcpy(a->name,"Radio");
704 } else { 702 } else {
@@ -722,12 +720,8 @@ static int vidioc_queryctrl (struct file *file, void *priv,
722 struct v4l2_queryctrl *ctrl) 720 struct v4l2_queryctrl *ctrl)
723{ 721{
724 struct usb_usbvision *usbvision = video_drvdata(file); 722 struct usb_usbvision *usbvision = video_drvdata(file);
725 int id=ctrl->id;
726 723
727 memset(ctrl,0,sizeof(*ctrl)); 724 call_all(usbvision, core, queryctrl, ctrl);
728 ctrl->id=id;
729
730 call_i2c_clients(usbvision, VIDIOC_QUERYCTRL, ctrl);
731 725
732 if (!ctrl->type) 726 if (!ctrl->type)
733 return -EINVAL; 727 return -EINVAL;
@@ -739,7 +733,7 @@ static int vidioc_g_ctrl (struct file *file, void *priv,
739 struct v4l2_control *ctrl) 733 struct v4l2_control *ctrl)
740{ 734{
741 struct usb_usbvision *usbvision = video_drvdata(file); 735 struct usb_usbvision *usbvision = video_drvdata(file);
742 call_i2c_clients(usbvision, VIDIOC_G_CTRL, ctrl); 736 call_all(usbvision, core, g_ctrl, ctrl);
743 737
744 return 0; 738 return 0;
745} 739}
@@ -748,7 +742,7 @@ static int vidioc_s_ctrl (struct file *file, void *priv,
748 struct v4l2_control *ctrl) 742 struct v4l2_control *ctrl)
749{ 743{
750 struct usb_usbvision *usbvision = video_drvdata(file); 744 struct usb_usbvision *usbvision = video_drvdata(file);
751 call_i2c_clients(usbvision, VIDIOC_S_CTRL, ctrl); 745 call_all(usbvision, core, s_ctrl, ctrl);
752 746
753 return 0; 747 return 0;
754} 748}
@@ -763,8 +757,7 @@ static int vidioc_reqbufs (struct file *file,
763 757
764 /* Check input validity: 758 /* Check input validity:
765 the user must do a VIDEO CAPTURE and MMAP method. */ 759 the user must do a VIDEO CAPTURE and MMAP method. */
766 if((vr->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) || 760 if (vr->memory != V4L2_MEMORY_MMAP)
767 (vr->memory != V4L2_MEMORY_MMAP))
768 return -EINVAL; 761 return -EINVAL;
769 762
770 if(usbvision->streaming == Stream_On) { 763 if(usbvision->streaming == Stream_On) {
@@ -789,9 +782,6 @@ static int vidioc_querybuf (struct file *file,
789 782
790 /* FIXME : must control 783 /* FIXME : must control
791 that buffers are mapped (VIDIOC_REQBUFS has been called) */ 784 that buffers are mapped (VIDIOC_REQBUFS has been called) */
792 if(vb->type != V4L2_CAP_VIDEO_CAPTURE) {
793 return -EINVAL;
794 }
795 if(vb->index>=usbvision->num_frames) { 785 if(vb->index>=usbvision->num_frames) {
796 return -EINVAL; 786 return -EINVAL;
797 } 787 }
@@ -825,9 +815,6 @@ static int vidioc_qbuf (struct file *file, void *priv, struct v4l2_buffer *vb)
825 unsigned long lock_flags; 815 unsigned long lock_flags;
826 816
827 /* FIXME : works only on VIDEO_CAPTURE MODE, MMAP. */ 817 /* FIXME : works only on VIDEO_CAPTURE MODE, MMAP. */
828 if(vb->type != V4L2_CAP_VIDEO_CAPTURE) {
829 return -EINVAL;
830 }
831 if(vb->index>=usbvision->num_frames) { 818 if(vb->index>=usbvision->num_frames) {
832 return -EINVAL; 819 return -EINVAL;
833 } 820 }
@@ -862,9 +849,6 @@ static int vidioc_dqbuf (struct file *file, void *priv, struct v4l2_buffer *vb)
862 struct usbvision_frame *f; 849 struct usbvision_frame *f;
863 unsigned long lock_flags; 850 unsigned long lock_flags;
864 851
865 if (vb->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
866 return -EINVAL;
867
868 if (list_empty(&(usbvision->outqueue))) { 852 if (list_empty(&(usbvision->outqueue))) {
869 if (usbvision->streaming == Stream_Idle) 853 if (usbvision->streaming == Stream_Idle)
870 return -EINVAL; 854 return -EINVAL;
@@ -899,10 +883,9 @@ static int vidioc_dqbuf (struct file *file, void *priv, struct v4l2_buffer *vb)
899static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i) 883static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
900{ 884{
901 struct usb_usbvision *usbvision = video_drvdata(file); 885 struct usb_usbvision *usbvision = video_drvdata(file);
902 int b=V4L2_BUF_TYPE_VIDEO_CAPTURE;
903 886
904 usbvision->streaming = Stream_On; 887 usbvision->streaming = Stream_On;
905 call_i2c_clients(usbvision,VIDIOC_STREAMON , &b); 888 call_all(usbvision, video, s_stream, 1);
906 889
907 return 0; 890 return 0;
908} 891}
@@ -911,7 +894,6 @@ static int vidioc_streamoff(struct file *file,
911 void *priv, enum v4l2_buf_type type) 894 void *priv, enum v4l2_buf_type type)
912{ 895{
913 struct usb_usbvision *usbvision = video_drvdata(file); 896 struct usb_usbvision *usbvision = video_drvdata(file);
914 int b=V4L2_BUF_TYPE_VIDEO_CAPTURE;
915 897
916 if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 898 if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
917 return -EINVAL; 899 return -EINVAL;
@@ -919,7 +901,7 @@ static int vidioc_streamoff(struct file *file,
919 if(usbvision->streaming == Stream_On) { 901 if(usbvision->streaming == Stream_On) {
920 usbvision_stream_interrupt(usbvision); 902 usbvision_stream_interrupt(usbvision);
921 /* Stop all video streamings */ 903 /* Stop all video streamings */
922 call_i2c_clients(usbvision,VIDIOC_STREAMOFF , &b); 904 call_all(usbvision, video, s_stream, 0);
923 } 905 }
924 usbvision_empty_framequeues(usbvision); 906 usbvision_empty_framequeues(usbvision);
925 907
@@ -932,11 +914,8 @@ static int vidioc_enum_fmt_vid_cap (struct file *file, void *priv,
932 if(vfd->index>=USBVISION_SUPPORTED_PALETTES-1) { 914 if(vfd->index>=USBVISION_SUPPORTED_PALETTES-1) {
933 return -EINVAL; 915 return -EINVAL;
934 } 916 }
935 vfd->flags = 0;
936 vfd->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
937 strcpy(vfd->description,usbvision_v4l2_format[vfd->index].desc); 917 strcpy(vfd->description,usbvision_v4l2_format[vfd->index].desc);
938 vfd->pixelformat = usbvision_v4l2_format[vfd->index].format; 918 vfd->pixelformat = usbvision_v4l2_format[vfd->index].format;
939 memset(vfd->reserved, 0, sizeof(vfd->reserved));
940 return 0; 919 return 0;
941} 920}
942 921
@@ -1042,7 +1021,7 @@ static ssize_t usbvision_v4l2_read(struct file *file, char __user *buf,
1042 if(usbvision->streaming != Stream_On) { 1021 if(usbvision->streaming != Stream_On) {
1043 /* no stream is running, make it running ! */ 1022 /* no stream is running, make it running ! */
1044 usbvision->streaming = Stream_On; 1023 usbvision->streaming = Stream_On;
1045 call_i2c_clients(usbvision,VIDIOC_STREAMON , NULL); 1024 call_all(usbvision, video, s_stream, 1);
1046 } 1025 }
1047 1026
1048 /* Then, enqueue as many frames as possible 1027 /* Then, enqueue as many frames as possible
@@ -1189,7 +1168,9 @@ static int usbvision_radio_open(struct file *file)
1189 mutex_lock(&usbvision->lock); 1168 mutex_lock(&usbvision->lock);
1190 1169
1191 if (usbvision->user) { 1170 if (usbvision->user) {
1192 err("%s: Someone tried to open an already opened USBVision Radio!", __func__); 1171 dev_err(&usbvision->rdev->dev,
1172 "%s: Someone tried to open an already opened USBVision Radio!\n",
1173 __func__);
1193 errCode = -EBUSY; 1174 errCode = -EBUSY;
1194 } 1175 }
1195 else { 1176 else {
@@ -1211,7 +1192,7 @@ static int usbvision_radio_open(struct file *file)
1211 1192
1212 // If so far no errors then we shall start the radio 1193 // If so far no errors then we shall start the radio
1213 usbvision->radio = 1; 1194 usbvision->radio = 1;
1214 call_i2c_clients(usbvision,AUDC_SET_RADIO,&usbvision->tuner_type); 1195 call_all(usbvision, tuner, s_radio);
1215 usbvision_set_audio(usbvision, USBVISION_AUDIO_RADIO); 1196 usbvision_set_audio(usbvision, USBVISION_AUDIO_RADIO);
1216 usbvision->user++; 1197 usbvision->user++;
1217 } 1198 }
@@ -1413,7 +1394,8 @@ static struct video_device *usbvision_vdev_init(struct usb_usbvision *usbvision,
1413 struct video_device *vdev; 1394 struct video_device *vdev;
1414 1395
1415 if (usb_dev == NULL) { 1396 if (usb_dev == NULL) {
1416 err("%s: usbvision->dev is not set", __func__); 1397 dev_err(&usbvision->dev->dev,
1398 "%s: usbvision->dev is not set\n", __func__);
1417 return NULL; 1399 return NULL;
1418 } 1400 }
1419 1401
@@ -1423,7 +1405,7 @@ static struct video_device *usbvision_vdev_init(struct usb_usbvision *usbvision,
1423 } 1405 }
1424 *vdev = *vdev_template; 1406 *vdev = *vdev_template;
1425// vdev->minor = -1; 1407// vdev->minor = -1;
1426 vdev->parent = &usb_dev->dev; 1408 vdev->v4l2_dev = &usbvision->v4l2_dev;
1427 snprintf(vdev->name, sizeof(vdev->name), "%s", name); 1409 snprintf(vdev->name, sizeof(vdev->name), "%s", name);
1428 video_set_drvdata(vdev, usbvision); 1410 video_set_drvdata(vdev, usbvision);
1429 return vdev; 1411 return vdev;
@@ -1524,7 +1506,9 @@ static int __devinit usbvision_register_video(struct usb_usbvision *usbvision)
1524 return 0; 1506 return 0;
1525 1507
1526 err_exit: 1508 err_exit:
1527 err("USBVision[%d]: video_register_device() failed", usbvision->nr); 1509 dev_err(&usbvision->dev->dev,
1510 "USBVision[%d]: video_register_device() failed\n",
1511 usbvision->nr);
1528 usbvision_unregister_video(usbvision); 1512 usbvision_unregister_video(usbvision);
1529 return -1; 1513 return -1;
1530} 1514}
@@ -1542,33 +1526,30 @@ static struct usb_usbvision *usbvision_alloc(struct usb_device *dev)
1542{ 1526{
1543 struct usb_usbvision *usbvision; 1527 struct usb_usbvision *usbvision;
1544 1528
1545 if ((usbvision = kzalloc(sizeof(struct usb_usbvision), GFP_KERNEL)) == 1529 usbvision = kzalloc(sizeof(struct usb_usbvision), GFP_KERNEL);
1546 NULL) { 1530 if (usbvision == NULL)
1547 goto err_exit; 1531 return NULL;
1548 }
1549 1532
1550 usbvision->dev = dev; 1533 usbvision->dev = dev;
1534 if (v4l2_device_register(&dev->dev, &usbvision->v4l2_dev))
1535 goto err_free;
1551 1536
1552 mutex_init(&usbvision->lock); /* available */ 1537 mutex_init(&usbvision->lock); /* available */
1553 1538
1554 // prepare control urb for control messages during interrupts 1539 // prepare control urb for control messages during interrupts
1555 usbvision->ctrlUrb = usb_alloc_urb(USBVISION_URB_FRAMES, GFP_KERNEL); 1540 usbvision->ctrlUrb = usb_alloc_urb(USBVISION_URB_FRAMES, GFP_KERNEL);
1556 if (usbvision->ctrlUrb == NULL) { 1541 if (usbvision->ctrlUrb == NULL)
1557 goto err_exit; 1542 goto err_unreg;
1558 }
1559 init_waitqueue_head(&usbvision->ctrlUrb_wq); 1543 init_waitqueue_head(&usbvision->ctrlUrb_wq);
1560 1544
1561 usbvision_init_powerOffTimer(usbvision); 1545 usbvision_init_powerOffTimer(usbvision);
1562 1546
1563 return usbvision; 1547 return usbvision;
1564 1548
1565err_exit: 1549err_unreg:
1566 if (usbvision && usbvision->ctrlUrb) { 1550 v4l2_device_unregister(&usbvision->v4l2_dev);
1567 usb_free_urb(usbvision->ctrlUrb); 1551err_free:
1568 } 1552 kfree(usbvision);
1569 if (usbvision) {
1570 kfree(usbvision);
1571 }
1572 return NULL; 1553 return NULL;
1573} 1554}
1574 1555
@@ -1598,6 +1579,7 @@ static void usbvision_release(struct usb_usbvision *usbvision)
1598 usb_free_urb(usbvision->ctrlUrb); 1579 usb_free_urb(usbvision->ctrlUrb);
1599 } 1580 }
1600 1581
1582 v4l2_device_unregister(&usbvision->v4l2_dev);
1601 kfree(usbvision); 1583 kfree(usbvision);
1602 1584
1603 PDEBUG(DBG_PROBE, "success"); 1585 PDEBUG(DBG_PROBE, "success");
@@ -1675,20 +1657,20 @@ static int __devinit usbvision_probe(struct usb_interface *intf,
1675 } 1657 }
1676 endpoint = &interface->endpoint[1].desc; 1658 endpoint = &interface->endpoint[1].desc;
1677 if (!usb_endpoint_xfer_isoc(endpoint)) { 1659 if (!usb_endpoint_xfer_isoc(endpoint)) {
1678 err("%s: interface %d. has non-ISO endpoint!", 1660 dev_err(&intf->dev, "%s: interface %d. has non-ISO endpoint!\n",
1679 __func__, ifnum); 1661 __func__, ifnum);
1680 err("%s: Endpoint attributes %d", 1662 dev_err(&intf->dev, "%s: Endpoint attributes %d",
1681 __func__, endpoint->bmAttributes); 1663 __func__, endpoint->bmAttributes);
1682 return -ENODEV; 1664 return -ENODEV;
1683 } 1665 }
1684 if (usb_endpoint_dir_out(endpoint)) { 1666 if (usb_endpoint_dir_out(endpoint)) {
1685 err("%s: interface %d. has ISO OUT endpoint!", 1667 dev_err(&intf->dev, "%s: interface %d. has ISO OUT endpoint!\n",
1686 __func__, ifnum); 1668 __func__, ifnum);
1687 return -ENODEV; 1669 return -ENODEV;
1688 } 1670 }
1689 1671
1690 if ((usbvision = usbvision_alloc(dev)) == NULL) { 1672 if ((usbvision = usbvision_alloc(dev)) == NULL) {
1691 err("%s: couldn't allocate USBVision struct", __func__); 1673 dev_err(&intf->dev, "%s: couldn't allocate USBVision struct\n", __func__);
1692 return -ENOMEM; 1674 return -ENOMEM;
1693 } 1675 }
1694 1676
@@ -1711,7 +1693,7 @@ static int __devinit usbvision_probe(struct usb_interface *intf,
1711 usbvision->alt_max_pkt_size = kmalloc(32* 1693 usbvision->alt_max_pkt_size = kmalloc(32*
1712 usbvision->num_alt,GFP_KERNEL); 1694 usbvision->num_alt,GFP_KERNEL);
1713 if (usbvision->alt_max_pkt_size == NULL) { 1695 if (usbvision->alt_max_pkt_size == NULL) {
1714 err("usbvision: out of memory!\n"); 1696 dev_err(&intf->dev, "usbvision: out of memory!\n");
1715 mutex_unlock(&usbvision->lock); 1697 mutex_unlock(&usbvision->lock);
1716 return -ENOMEM; 1698 return -ENOMEM;
1717 } 1699 }
@@ -1733,8 +1715,6 @@ static int __devinit usbvision_probe(struct usb_interface *intf,
1733 usbvision->tuner_type = usbvision_device_data[model].TunerType; 1715 usbvision->tuner_type = usbvision_device_data[model].TunerType;
1734 } 1716 }
1735 1717
1736 usbvision->tuner_addr = ADDR_UNSET;
1737
1738 usbvision->DevModel = model; 1718 usbvision->DevModel = model;
1739 usbvision->remove_pending = 0; 1719 usbvision->remove_pending = 0;
1740 usbvision->iface = ifnum; 1720 usbvision->iface = ifnum;
@@ -1772,7 +1752,8 @@ static void __devexit usbvision_disconnect(struct usb_interface *intf)
1772 PDEBUG(DBG_PROBE, ""); 1752 PDEBUG(DBG_PROBE, "");
1773 1753
1774 if (usbvision == NULL) { 1754 if (usbvision == NULL) {
1775 err("%s: usb_get_intfdata() failed", __func__); 1755 dev_err(&usbvision->dev->dev,
1756 "%s: usb_get_intfdata() failed\n", __func__);
1776 return; 1757 return;
1777 } 1758 }
1778 usb_set_intfdata (intf, NULL); 1759 usb_set_intfdata (intf, NULL);
@@ -1782,6 +1763,8 @@ static void __devexit usbvision_disconnect(struct usb_interface *intf)
1782 // At this time we ask to cancel outstanding URBs 1763 // At this time we ask to cancel outstanding URBs
1783 usbvision_stop_isoc(usbvision); 1764 usbvision_stop_isoc(usbvision);
1784 1765
1766 v4l2_device_disconnect(&usbvision->v4l2_dev);
1767
1785 if (usbvision->power) { 1768 if (usbvision->power) {
1786 usbvision_i2c_unregister(usbvision); 1769 usbvision_i2c_unregister(usbvision);
1787 usbvision_power_off(usbvision); 1770 usbvision_power_off(usbvision);
diff --git a/drivers/media/video/usbvision/usbvision.h b/drivers/media/video/usbvision/usbvision.h
index 20d7ec624999..f8d7458daf3e 100644
--- a/drivers/media/video/usbvision/usbvision.h
+++ b/drivers/media/video/usbvision/usbvision.h
@@ -6,7 +6,7 @@
6 * Dwaine Garden <dwainegarden@rogers.com> 6 * Dwaine Garden <dwainegarden@rogers.com>
7 * 7 *
8 * 8 *
9 * Report problems to v4l MailingList : http://www.redhat.com/mailman/listinfo/video4linux-list 9 * Report problems to v4l MailingList: linux-media@vger.kernel.org
10 * 10 *
11 * This module is part of usbvision driver project. 11 * This module is part of usbvision driver project.
12 * Updates to driver completed by Dwaine P. Garden 12 * Updates to driver completed by Dwaine P. Garden
@@ -35,7 +35,7 @@
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 <linux/mutex.h>
38#include <media/v4l2-common.h> 38#include <media/v4l2-device.h>
39#include <media/tuner.h> 39#include <media/tuner.h>
40#include <linux/videodev2.h> 40#include <linux/videodev2.h>
41 41
@@ -357,13 +357,13 @@ extern struct usbvision_device_data_st usbvision_device_data[];
357extern struct usb_device_id usbvision_table[]; 357extern struct usb_device_id usbvision_table[];
358 358
359struct usb_usbvision { 359struct usb_usbvision {
360 struct v4l2_device v4l2_dev;
360 struct video_device *vdev; /* Video Device */ 361 struct video_device *vdev; /* Video Device */
361 struct video_device *rdev; /* Radio Device */ 362 struct video_device *rdev; /* Radio Device */
362 struct video_device *vbi; /* VBI Device */ 363 struct video_device *vbi; /* VBI Device */
363 364
364 /* i2c Declaration Section*/ 365 /* i2c Declaration Section*/
365 struct i2c_adapter i2c_adap; 366 struct i2c_adapter i2c_adap;
366 struct i2c_client i2c_client;
367 367
368 struct urb *ctrlUrb; 368 struct urb *ctrlUrb;
369 unsigned char ctrlUrbBuffer[8]; 369 unsigned char ctrlUrbBuffer[8];
@@ -374,7 +374,6 @@ struct usb_usbvision {
374 /* configuration part */ 374 /* configuration part */
375 int have_tuner; 375 int have_tuner;
376 int tuner_type; 376 int tuner_type;
377 int tuner_addr;
378 int bridgeType; // NT1003, NT1004, NT1005 377 int bridgeType; // NT1003, NT1004, NT1005
379 int radio; 378 int radio;
380 int video_inputs; // # of inputs 379 int video_inputs; // # of inputs
@@ -464,6 +463,8 @@ struct usb_usbvision {
464 int ComprBlockTypes[4]; 463 int ComprBlockTypes[4];
465}; 464};
466 465
466#define call_all(usbvision, o, f, args...) \
467 v4l2_device_call_all(&usbvision->v4l2_dev, 0, o, f, ##args)
467 468
468/* --------------------------------------------------------------- */ 469/* --------------------------------------------------------------- */
469/* defined in usbvision-i2c.c */ 470/* defined in usbvision-i2c.c */
@@ -475,7 +476,6 @@ struct usb_usbvision {
475/* ----------------------------------------------------------------------- */ 476/* ----------------------------------------------------------------------- */
476int usbvision_i2c_register(struct usb_usbvision *usbvision); 477int usbvision_i2c_register(struct usb_usbvision *usbvision);
477int usbvision_i2c_unregister(struct usb_usbvision *usbvision); 478int usbvision_i2c_unregister(struct usb_usbvision *usbvision);
478void call_i2c_clients(struct usb_usbvision *usbvision, unsigned int cmd,void *arg);
479 479
480/* defined in usbvision-core.c */ 480/* defined in usbvision-core.c */
481int usbvision_read_reg(struct usb_usbvision *usbvision, unsigned char reg); 481int usbvision_read_reg(struct usb_usbvision *usbvision, unsigned char reg);
diff --git a/drivers/media/video/uvc/uvc_ctrl.c b/drivers/media/video/uvc/uvc_ctrl.c
index d2576f6391c0..0d7e38d6ff6a 100644
--- a/drivers/media/video/uvc/uvc_ctrl.c
+++ b/drivers/media/video/uvc/uvc_ctrl.c
@@ -786,7 +786,7 @@ int uvc_query_v4l2_ctrl(struct uvc_video_device *video,
786 memset(v4l2_ctrl, 0, sizeof *v4l2_ctrl); 786 memset(v4l2_ctrl, 0, sizeof *v4l2_ctrl);
787 v4l2_ctrl->id = mapping->id; 787 v4l2_ctrl->id = mapping->id;
788 v4l2_ctrl->type = mapping->v4l2_type; 788 v4l2_ctrl->type = mapping->v4l2_type;
789 strncpy(v4l2_ctrl->name, mapping->name, sizeof v4l2_ctrl->name); 789 strlcpy(v4l2_ctrl->name, mapping->name, sizeof v4l2_ctrl->name);
790 v4l2_ctrl->flags = 0; 790 v4l2_ctrl->flags = 0;
791 791
792 if (!(ctrl->info->flags & UVC_CONTROL_SET_CUR)) 792 if (!(ctrl->info->flags & UVC_CONTROL_SET_CUR))
diff --git a/drivers/media/video/uvc/uvc_driver.c b/drivers/media/video/uvc/uvc_driver.c
index b12873265cc5..399412d7f020 100644
--- a/drivers/media/video/uvc/uvc_driver.c
+++ b/drivers/media/video/uvc/uvc_driver.c
@@ -314,7 +314,7 @@ static int uvc_parse_format(struct uvc_device *dev,
314 fmtdesc = uvc_format_by_guid(&buffer[5]); 314 fmtdesc = uvc_format_by_guid(&buffer[5]);
315 315
316 if (fmtdesc != NULL) { 316 if (fmtdesc != NULL) {
317 strncpy(format->name, fmtdesc->name, 317 strlcpy(format->name, fmtdesc->name,
318 sizeof format->name); 318 sizeof format->name);
319 format->fcc = fmtdesc->fcc; 319 format->fcc = fmtdesc->fcc;
320 } else { 320 } else {
@@ -345,7 +345,7 @@ static int uvc_parse_format(struct uvc_device *dev,
345 return -EINVAL; 345 return -EINVAL;
346 } 346 }
347 347
348 strncpy(format->name, "MJPEG", sizeof format->name); 348 strlcpy(format->name, "MJPEG", sizeof format->name);
349 format->fcc = V4L2_PIX_FMT_MJPEG; 349 format->fcc = V4L2_PIX_FMT_MJPEG;
350 format->flags = UVC_FMT_FLAG_COMPRESSED; 350 format->flags = UVC_FMT_FLAG_COMPRESSED;
351 format->bpp = 0; 351 format->bpp = 0;
@@ -363,13 +363,13 @@ static int uvc_parse_format(struct uvc_device *dev,
363 363
364 switch (buffer[8] & 0x7f) { 364 switch (buffer[8] & 0x7f) {
365 case 0: 365 case 0:
366 strncpy(format->name, "SD-DV", sizeof format->name); 366 strlcpy(format->name, "SD-DV", sizeof format->name);
367 break; 367 break;
368 case 1: 368 case 1:
369 strncpy(format->name, "SDL-DV", sizeof format->name); 369 strlcpy(format->name, "SDL-DV", sizeof format->name);
370 break; 370 break;
371 case 2: 371 case 2:
372 strncpy(format->name, "HD-DV", sizeof format->name); 372 strlcpy(format->name, "HD-DV", sizeof format->name);
373 break; 373 break;
374 default: 374 default:
375 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming" 375 uvc_trace(UVC_TRACE_DESCR, "device %d videostreaming"
@@ -379,7 +379,7 @@ static int uvc_parse_format(struct uvc_device *dev,
379 return -EINVAL; 379 return -EINVAL;
380 } 380 }
381 381
382 strncat(format->name, buffer[8] & (1 << 7) ? " 60Hz" : " 50Hz", 382 strlcat(format->name, buffer[8] & (1 << 7) ? " 60Hz" : " 50Hz",
383 sizeof format->name); 383 sizeof format->name);
384 384
385 format->fcc = V4L2_PIX_FMT_DV; 385 format->fcc = V4L2_PIX_FMT_DV;
@@ -1526,7 +1526,7 @@ static int uvc_register_video(struct uvc_device *dev)
1526 vdev->minor = -1; 1526 vdev->minor = -1;
1527 vdev->fops = &uvc_fops; 1527 vdev->fops = &uvc_fops;
1528 vdev->release = video_device_release; 1528 vdev->release = video_device_release;
1529 strncpy(vdev->name, dev->name, sizeof vdev->name); 1529 strlcpy(vdev->name, dev->name, sizeof vdev->name);
1530 1530
1531 /* Set the driver data before calling video_register_device, otherwise 1531 /* Set the driver data before calling video_register_device, otherwise
1532 * uvc_v4l2_open might race us. 1532 * uvc_v4l2_open might race us.
@@ -1621,7 +1621,7 @@ static int uvc_probe(struct usb_interface *intf,
1621 dev->quirks = id->driver_info | uvc_quirks_param; 1621 dev->quirks = id->driver_info | uvc_quirks_param;
1622 1622
1623 if (udev->product != NULL) 1623 if (udev->product != NULL)
1624 strncpy(dev->name, udev->product, sizeof dev->name); 1624 strlcpy(dev->name, udev->product, sizeof dev->name);
1625 else 1625 else
1626 snprintf(dev->name, sizeof dev->name, 1626 snprintf(dev->name, sizeof dev->name,
1627 "UVC Camera (%04x:%04x)", 1627 "UVC Camera (%04x:%04x)",
@@ -1833,6 +1833,15 @@ static struct usb_device_id uvc_ids[] = {
1833 .bInterfaceClass = USB_CLASS_VENDOR_SPEC, 1833 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
1834 .bInterfaceSubClass = 1, 1834 .bInterfaceSubClass = 1,
1835 .bInterfaceProtocol = 0 }, 1835 .bInterfaceProtocol = 0 },
1836 /* Alcor Micro AU3820 (Future Boy PC USB Webcam) */
1837 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
1838 | USB_DEVICE_ID_MATCH_INT_INFO,
1839 .idVendor = 0x058f,
1840 .idProduct = 0x3820,
1841 .bInterfaceClass = USB_CLASS_VIDEO,
1842 .bInterfaceSubClass = 1,
1843 .bInterfaceProtocol = 0,
1844 .driver_info = UVC_QUIRK_PROBE_MINMAX },
1836 /* Apple Built-In iSight */ 1845 /* Apple Built-In iSight */
1837 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 1846 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
1838 | USB_DEVICE_ID_MATCH_INT_INFO, 1847 | USB_DEVICE_ID_MATCH_INT_INFO,
@@ -1852,6 +1861,15 @@ static struct usb_device_id uvc_ids[] = {
1852 .bInterfaceSubClass = 1, 1861 .bInterfaceSubClass = 1,
1853 .bInterfaceProtocol = 0, 1862 .bInterfaceProtocol = 0,
1854 .driver_info = UVC_QUIRK_STREAM_NO_FID }, 1863 .driver_info = UVC_QUIRK_STREAM_NO_FID },
1864 /* ViMicro */
1865 { .match_flags = USB_DEVICE_ID_MATCH_VENDOR
1866 | USB_DEVICE_ID_MATCH_INT_INFO,
1867 .idVendor = 0x0ac8,
1868 .idProduct = 0x0000,
1869 .bInterfaceClass = USB_CLASS_VIDEO,
1870 .bInterfaceSubClass = 1,
1871 .bInterfaceProtocol = 0,
1872 .driver_info = UVC_QUIRK_FIX_BANDWIDTH },
1855 /* MT6227 */ 1873 /* MT6227 */
1856 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 1874 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
1857 | USB_DEVICE_ID_MATCH_INT_INFO, 1875 | USB_DEVICE_ID_MATCH_INT_INFO,
@@ -1879,7 +1897,7 @@ static struct usb_device_id uvc_ids[] = {
1879 .bInterfaceSubClass = 1, 1897 .bInterfaceSubClass = 1,
1880 .bInterfaceProtocol = 0, 1898 .bInterfaceProtocol = 0,
1881 .driver_info = UVC_QUIRK_STREAM_NO_FID }, 1899 .driver_info = UVC_QUIRK_STREAM_NO_FID },
1882 /* Asus F9SG */ 1900 /* Syntek (Asus F9SG) */
1883 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 1901 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
1884 | USB_DEVICE_ID_MATCH_INT_INFO, 1902 | USB_DEVICE_ID_MATCH_INT_INFO,
1885 .idVendor = 0x174f, 1903 .idVendor = 0x174f,
@@ -1897,6 +1915,15 @@ static struct usb_device_id uvc_ids[] = {
1897 .bInterfaceSubClass = 1, 1915 .bInterfaceSubClass = 1,
1898 .bInterfaceProtocol = 0, 1916 .bInterfaceProtocol = 0,
1899 .driver_info = UVC_QUIRK_STREAM_NO_FID }, 1917 .driver_info = UVC_QUIRK_STREAM_NO_FID },
1918 /* Syntek (JAOtech Smart Terminal) */
1919 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
1920 | USB_DEVICE_ID_MATCH_INT_INFO,
1921 .idVendor = 0x174f,
1922 .idProduct = 0x8a34,
1923 .bInterfaceClass = USB_CLASS_VIDEO,
1924 .bInterfaceSubClass = 1,
1925 .bInterfaceProtocol = 0,
1926 .driver_info = UVC_QUIRK_STREAM_NO_FID },
1900 /* Lenovo Thinkpad SL500 */ 1927 /* Lenovo Thinkpad SL500 */
1901 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 1928 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
1902 | USB_DEVICE_ID_MATCH_INT_INFO, 1929 | USB_DEVICE_ID_MATCH_INT_INFO,
diff --git a/drivers/media/video/uvc/uvc_status.c b/drivers/media/video/uvc/uvc_status.c
index c705f248da88..21d87124986b 100644
--- a/drivers/media/video/uvc/uvc_status.c
+++ b/drivers/media/video/uvc/uvc_status.c
@@ -24,26 +24,19 @@
24#ifdef CONFIG_USB_VIDEO_CLASS_INPUT_EVDEV 24#ifdef CONFIG_USB_VIDEO_CLASS_INPUT_EVDEV
25static int uvc_input_init(struct uvc_device *dev) 25static int uvc_input_init(struct uvc_device *dev)
26{ 26{
27 struct usb_device *udev = dev->udev;
28 struct input_dev *input; 27 struct input_dev *input;
29 char *phys = NULL;
30 int ret; 28 int ret;
31 29
32 input = input_allocate_device(); 30 input = input_allocate_device();
33 if (input == NULL) 31 if (input == NULL)
34 return -ENOMEM; 32 return -ENOMEM;
35 33
36 phys = kmalloc(6 + strlen(udev->bus->bus_name) + strlen(udev->devpath), 34 usb_make_path(dev->udev, dev->input_phys, sizeof(dev->input_phys));
37 GFP_KERNEL); 35 strlcat(dev->input_phys, "/button", sizeof(dev->input_phys));
38 if (phys == NULL) {
39 ret = -ENOMEM;
40 goto error;
41 }
42 sprintf(phys, "usb-%s-%s", udev->bus->bus_name, udev->devpath);
43 36
44 input->name = dev->name; 37 input->name = dev->name;
45 input->phys = phys; 38 input->phys = dev->input_phys;
46 usb_to_input_id(udev, &input->id); 39 usb_to_input_id(dev->udev, &input->id);
47 input->dev.parent = &dev->intf->dev; 40 input->dev.parent = &dev->intf->dev;
48 41
49 __set_bit(EV_KEY, input->evbit); 42 __set_bit(EV_KEY, input->evbit);
@@ -57,7 +50,6 @@ static int uvc_input_init(struct uvc_device *dev)
57 50
58error: 51error:
59 input_free_device(input); 52 input_free_device(input);
60 kfree(phys);
61 return ret; 53 return ret;
62} 54}
63 55
diff --git a/drivers/media/video/uvc/uvc_v4l2.c b/drivers/media/video/uvc/uvc_v4l2.c
index d681519d0c8a..2a80caa54fb4 100644
--- a/drivers/media/video/uvc/uvc_v4l2.c
+++ b/drivers/media/video/uvc/uvc_v4l2.c
@@ -55,7 +55,7 @@ static int uvc_v4l2_query_menu(struct uvc_video_device *video,
55 return -EINVAL; 55 return -EINVAL;
56 56
57 menu_info = &mapping->menu_info[query_menu->index]; 57 menu_info = &mapping->menu_info[query_menu->index];
58 strncpy(query_menu->name, menu_info->name, 32); 58 strlcpy(query_menu->name, menu_info->name, sizeof query_menu->name);
59 return 0; 59 return 0;
60} 60}
61 61
@@ -486,10 +486,10 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
486 struct v4l2_capability *cap = arg; 486 struct v4l2_capability *cap = arg;
487 487
488 memset(cap, 0, sizeof *cap); 488 memset(cap, 0, sizeof *cap);
489 strncpy(cap->driver, "uvcvideo", sizeof cap->driver); 489 strlcpy(cap->driver, "uvcvideo", sizeof cap->driver);
490 strncpy(cap->card, vdev->name, 32); 490 strlcpy(cap->card, vdev->name, sizeof cap->card);
491 strncpy(cap->bus_info, video->dev->udev->bus->bus_name, 491 usb_make_path(video->dev->udev,
492 sizeof cap->bus_info); 492 cap->bus_info, sizeof(cap->bus_info));
493 cap->version = DRIVER_VERSION_NUMBER; 493 cap->version = DRIVER_VERSION_NUMBER;
494 if (video->streaming->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) 494 if (video->streaming->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
495 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE 495 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE
@@ -620,7 +620,7 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
620 620
621 memset(input, 0, sizeof *input); 621 memset(input, 0, sizeof *input);
622 input->index = index; 622 input->index = index;
623 strncpy(input->name, iterm->name, sizeof input->name); 623 strlcpy(input->name, iterm->name, sizeof input->name);
624 if (UVC_ENTITY_TYPE(iterm) == ITT_CAMERA) 624 if (UVC_ENTITY_TYPE(iterm) == ITT_CAMERA)
625 input->type = V4L2_INPUT_TYPE_CAMERA; 625 input->type = V4L2_INPUT_TYPE_CAMERA;
626 break; 626 break;
@@ -673,16 +673,22 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
673 { 673 {
674 struct v4l2_fmtdesc *fmt = arg; 674 struct v4l2_fmtdesc *fmt = arg;
675 struct uvc_format *format; 675 struct uvc_format *format;
676 enum v4l2_buf_type type = fmt->type;
677 __u32 index = fmt->index;
676 678
677 if (fmt->type != video->streaming->type || 679 if (fmt->type != video->streaming->type ||
678 fmt->index >= video->streaming->nformats) 680 fmt->index >= video->streaming->nformats)
679 return -EINVAL; 681 return -EINVAL;
680 682
683 memset(fmt, 0, sizeof(*fmt));
684 fmt->index = index;
685 fmt->type = type;
686
681 format = &video->streaming->format[fmt->index]; 687 format = &video->streaming->format[fmt->index];
682 fmt->flags = 0; 688 fmt->flags = 0;
683 if (format->flags & UVC_FMT_FLAG_COMPRESSED) 689 if (format->flags & UVC_FMT_FLAG_COMPRESSED)
684 fmt->flags |= V4L2_FMT_FLAG_COMPRESSED; 690 fmt->flags |= V4L2_FMT_FLAG_COMPRESSED;
685 strncpy(fmt->description, format->name, 691 strlcpy(fmt->description, format->name,
686 sizeof fmt->description); 692 sizeof fmt->description);
687 fmt->description[sizeof fmt->description - 1] = 0; 693 fmt->description[sizeof fmt->description - 1] = 0;
688 fmt->pixelformat = format->fcc; 694 fmt->pixelformat = format->fcc;
diff --git a/drivers/media/video/uvc/uvc_video.c b/drivers/media/video/uvc/uvc_video.c
index 9bc4705be78d..a95e17329c5b 100644
--- a/drivers/media/video/uvc/uvc_video.c
+++ b/drivers/media/video/uvc/uvc_video.c
@@ -61,7 +61,7 @@ int uvc_query_ctrl(struct uvc_device *dev, __u8 query, __u8 unit,
61 return 0; 61 return 0;
62} 62}
63 63
64static void uvc_fixup_buffer_size(struct uvc_video_device *video, 64static void uvc_fixup_video_ctrl(struct uvc_video_device *video,
65 struct uvc_streaming_control *ctrl) 65 struct uvc_streaming_control *ctrl)
66{ 66{
67 struct uvc_format *format; 67 struct uvc_format *format;
@@ -84,6 +84,31 @@ static void uvc_fixup_buffer_size(struct uvc_video_device *video,
84 video->dev->uvc_version < 0x0110)) 84 video->dev->uvc_version < 0x0110))
85 ctrl->dwMaxVideoFrameSize = 85 ctrl->dwMaxVideoFrameSize =
86 frame->dwMaxVideoFrameBufferSize; 86 frame->dwMaxVideoFrameBufferSize;
87
88 if (video->dev->quirks & UVC_QUIRK_FIX_BANDWIDTH &&
89 video->streaming->intf->num_altsetting > 1) {
90 u32 interval;
91 u32 bandwidth;
92
93 interval = (ctrl->dwFrameInterval > 100000)
94 ? ctrl->dwFrameInterval
95 : frame->dwFrameInterval[0];
96
97 /* Compute a bandwidth estimation by multiplying the frame
98 * size by the number of video frames per second, divide the
99 * result by the number of USB frames (or micro-frames for
100 * high-speed devices) per second and add the UVC header size
101 * (assumed to be 12 bytes long).
102 */
103 bandwidth = frame->wWidth * frame->wHeight / 8 * format->bpp;
104 bandwidth *= 10000000 / interval + 1;
105 bandwidth /= 1000;
106 if (video->dev->udev->speed == USB_SPEED_HIGH)
107 bandwidth /= 8;
108 bandwidth += 12;
109
110 ctrl->dwMaxPayloadTransferSize = bandwidth;
111 }
87} 112}
88 113
89static int uvc_get_video_ctrl(struct uvc_video_device *video, 114static int uvc_get_video_ctrl(struct uvc_video_device *video,
@@ -158,10 +183,11 @@ static int uvc_get_video_ctrl(struct uvc_video_device *video,
158 ctrl->bMaxVersion = 0; 183 ctrl->bMaxVersion = 0;
159 } 184 }
160 185
161 /* Some broken devices return a null or wrong dwMaxVideoFrameSize. 186 /* Some broken devices return null or wrong dwMaxVideoFrameSize and
162 * Try to get the value from the format and frame descriptors. 187 * dwMaxPayloadTransferSize fields. Try to get the value from the
188 * format and frame descriptors.
163 */ 189 */
164 uvc_fixup_buffer_size(video, ctrl); 190 uvc_fixup_video_ctrl(video, ctrl);
165 ret = 0; 191 ret = 0;
166 192
167out: 193out:
@@ -540,6 +566,9 @@ static void uvc_video_decode_bulk(struct urb *urb,
540 u8 *mem; 566 u8 *mem;
541 int len, ret; 567 int len, ret;
542 568
569 if (urb->actual_length == 0)
570 return;
571
543 mem = urb->transfer_buffer; 572 mem = urb->transfer_buffer;
544 len = urb->actual_length; 573 len = urb->actual_length;
545 video->bulk.payload_size += len; 574 video->bulk.payload_size += len;
@@ -699,27 +728,47 @@ static void uvc_free_urb_buffers(struct uvc_video_device *video)
699 * already allocated when resuming from suspend, in which case it will 728 * already allocated when resuming from suspend, in which case it will
700 * return without touching the buffers. 729 * return without touching the buffers.
701 * 730 *
702 * Return 0 on success or -ENOMEM when out of memory. 731 * Limit the buffer size to UVC_MAX_PACKETS bulk/isochronous packets. If the
732 * system is too low on memory try successively smaller numbers of packets
733 * until allocation succeeds.
734 *
735 * Return the number of allocated packets on success or 0 when out of memory.
703 */ 736 */
704static int uvc_alloc_urb_buffers(struct uvc_video_device *video, 737static int uvc_alloc_urb_buffers(struct uvc_video_device *video,
705 unsigned int size) 738 unsigned int size, unsigned int psize, gfp_t gfp_flags)
706{ 739{
740 unsigned int npackets;
707 unsigned int i; 741 unsigned int i;
708 742
709 /* Buffers are already allocated, bail out. */ 743 /* Buffers are already allocated, bail out. */
710 if (video->urb_size) 744 if (video->urb_size)
711 return 0; 745 return 0;
712 746
713 for (i = 0; i < UVC_URBS; ++i) { 747 /* Compute the number of packets. Bulk endpoints might transfer UVC
714 video->urb_buffer[i] = usb_buffer_alloc(video->dev->udev, 748 * payloads accross multiple URBs.
715 size, GFP_KERNEL, &video->urb_dma[i]); 749 */
716 if (video->urb_buffer[i] == NULL) { 750 npackets = DIV_ROUND_UP(size, psize);
717 uvc_free_urb_buffers(video); 751 if (npackets > UVC_MAX_PACKETS)
718 return -ENOMEM; 752 npackets = UVC_MAX_PACKETS;
753
754 /* Retry allocations until one succeed. */
755 for (; npackets > 1; npackets /= 2) {
756 for (i = 0; i < UVC_URBS; ++i) {
757 video->urb_buffer[i] = usb_buffer_alloc(
758 video->dev->udev, psize * npackets,
759 gfp_flags | __GFP_NOWARN, &video->urb_dma[i]);
760 if (!video->urb_buffer[i]) {
761 uvc_free_urb_buffers(video);
762 break;
763 }
764 }
765
766 if (i == UVC_URBS) {
767 video->urb_size = psize * npackets;
768 return npackets;
719 } 769 }
720 } 770 }
721 771
722 video->urb_size = size;
723 return 0; 772 return 0;
724} 773}
725 774
@@ -753,29 +802,19 @@ static int uvc_init_video_isoc(struct uvc_video_device *video,
753{ 802{
754 struct urb *urb; 803 struct urb *urb;
755 unsigned int npackets, i, j; 804 unsigned int npackets, i, j;
756 __u16 psize; 805 u16 psize;
757 __u32 size; 806 u32 size;
758 807
759 /* Compute the number of isochronous packets to allocate by dividing
760 * the maximum video frame size by the packet size. Limit the result
761 * to UVC_MAX_ISO_PACKETS.
762 */
763 psize = le16_to_cpu(ep->desc.wMaxPacketSize); 808 psize = le16_to_cpu(ep->desc.wMaxPacketSize);
764 psize = (psize & 0x07ff) * (1 + ((psize >> 11) & 3)); 809 psize = (psize & 0x07ff) * (1 + ((psize >> 11) & 3));
765
766 size = video->streaming->ctrl.dwMaxVideoFrameSize; 810 size = video->streaming->ctrl.dwMaxVideoFrameSize;
767 if (size > UVC_MAX_FRAME_SIZE)
768 return -EINVAL;
769 811
770 npackets = DIV_ROUND_UP(size, psize); 812 npackets = uvc_alloc_urb_buffers(video, size, psize, gfp_flags);
771 if (npackets > UVC_MAX_ISO_PACKETS) 813 if (npackets == 0)
772 npackets = UVC_MAX_ISO_PACKETS; 814 return -ENOMEM;
773 815
774 size = npackets * psize; 816 size = npackets * psize;
775 817
776 if (uvc_alloc_urb_buffers(video, size) < 0)
777 return -ENOMEM;
778
779 for (i = 0; i < UVC_URBS; ++i) { 818 for (i = 0; i < UVC_URBS; ++i) {
780 urb = usb_alloc_urb(npackets, gfp_flags); 819 urb = usb_alloc_urb(npackets, gfp_flags);
781 if (urb == NULL) { 820 if (urb == NULL) {
@@ -814,25 +853,20 @@ static int uvc_init_video_bulk(struct uvc_video_device *video,
814 struct usb_host_endpoint *ep, gfp_t gfp_flags) 853 struct usb_host_endpoint *ep, gfp_t gfp_flags)
815{ 854{
816 struct urb *urb; 855 struct urb *urb;
817 unsigned int pipe, i; 856 unsigned int npackets, pipe, i;
818 __u16 psize; 857 u16 psize;
819 __u32 size; 858 u32 size;
820 859
821 /* Compute the bulk URB size. Some devices set the maximum payload
822 * size to a value too high for memory-constrained devices. We must
823 * then transfer the payload accross multiple URBs. To be consistant
824 * with isochronous mode, allocate maximum UVC_MAX_ISO_PACKETS per bulk
825 * URB.
826 */
827 psize = le16_to_cpu(ep->desc.wMaxPacketSize) & 0x07ff; 860 psize = le16_to_cpu(ep->desc.wMaxPacketSize) & 0x07ff;
828 size = video->streaming->ctrl.dwMaxPayloadTransferSize; 861 size = video->streaming->ctrl.dwMaxPayloadTransferSize;
829 video->bulk.max_payload_size = size; 862 video->bulk.max_payload_size = size;
830 if (size > psize * UVC_MAX_ISO_PACKETS)
831 size = psize * UVC_MAX_ISO_PACKETS;
832 863
833 if (uvc_alloc_urb_buffers(video, size) < 0) 864 npackets = uvc_alloc_urb_buffers(video, size, psize, gfp_flags);
865 if (npackets == 0)
834 return -ENOMEM; 866 return -ENOMEM;
835 867
868 size = npackets * psize;
869
836 if (usb_endpoint_dir_in(&ep->desc)) 870 if (usb_endpoint_dir_in(&ep->desc))
837 pipe = usb_rcvbulkpipe(video->dev->udev, 871 pipe = usb_rcvbulkpipe(video->dev->udev,
838 ep->desc.bEndpointAddress); 872 ep->desc.bEndpointAddress);
@@ -1021,11 +1055,20 @@ int uvc_video_init(struct uvc_video_device *video)
1021 */ 1055 */
1022 usb_set_interface(video->dev->udev, video->streaming->intfnum, 0); 1056 usb_set_interface(video->dev->udev, video->streaming->intfnum, 0);
1023 1057
1024 /* Some webcams don't suport GET_DEF requests on the probe control. We 1058 /* Set the streaming probe control with default streaming parameters
1025 * fall back to GET_CUR if GET_DEF fails. 1059 * retrieved from the device. Webcams that don't suport GET_DEF
1060 * requests on the probe control will just keep their current streaming
1061 * parameters.
1062 */
1063 if (uvc_get_video_ctrl(video, probe, 1, GET_DEF) == 0)
1064 uvc_set_video_ctrl(video, probe, 1);
1065
1066 /* Initialize the streaming parameters with the probe control current
1067 * value. This makes sure SET_CUR requests on the streaming commit
1068 * control will always use values retrieved from a successful GET_CUR
1069 * request on the probe control, as required by the UVC specification.
1026 */ 1070 */
1027 if ((ret = uvc_get_video_ctrl(video, probe, 1, GET_DEF)) < 0 && 1071 if ((ret = uvc_get_video_ctrl(video, probe, 1, GET_CUR)) < 0)
1028 (ret = uvc_get_video_ctrl(video, probe, 1, GET_CUR)) < 0)
1029 return ret; 1072 return ret;
1030 1073
1031 /* Check if the default format descriptor exists. Use the first 1074 /* Check if the default format descriptor exists. Use the first
diff --git a/drivers/media/video/uvc/uvcvideo.h b/drivers/media/video/uvc/uvcvideo.h
index 027947ea9b6e..e5014e668f99 100644
--- a/drivers/media/video/uvc/uvcvideo.h
+++ b/drivers/media/video/uvc/uvcvideo.h
@@ -296,10 +296,8 @@ struct uvc_xu_control {
296 296
297/* Number of isochronous URBs. */ 297/* Number of isochronous URBs. */
298#define UVC_URBS 5 298#define UVC_URBS 5
299/* Maximum number of packets per isochronous URB. */ 299/* Maximum number of packets per URB. */
300#define UVC_MAX_ISO_PACKETS 40 300#define UVC_MAX_PACKETS 32
301/* Maximum frame size in bytes, for sanity checking. */
302#define UVC_MAX_FRAME_SIZE (16*1024*1024)
303/* Maximum number of video buffers. */ 301/* Maximum number of video buffers. */
304#define UVC_MAX_VIDEO_BUFFERS 32 302#define UVC_MAX_VIDEO_BUFFERS 32
305/* Maximum status buffer size in bytes of interrupt URB. */ 303/* Maximum status buffer size in bytes of interrupt URB. */
@@ -316,6 +314,7 @@ struct uvc_xu_control {
316#define UVC_QUIRK_STREAM_NO_FID 0x00000010 314#define UVC_QUIRK_STREAM_NO_FID 0x00000010
317#define UVC_QUIRK_IGNORE_SELECTOR_UNIT 0x00000020 315#define UVC_QUIRK_IGNORE_SELECTOR_UNIT 0x00000020
318#define UVC_QUIRK_PRUNE_CONTROLS 0x00000040 316#define UVC_QUIRK_PRUNE_CONTROLS 0x00000040
317#define UVC_QUIRK_FIX_BANDWIDTH 0x00000080
319 318
320/* Format flags */ 319/* Format flags */
321#define UVC_FMT_FLAG_COMPRESSED 0x00000001 320#define UVC_FMT_FLAG_COMPRESSED 0x00000001
@@ -649,6 +648,7 @@ struct uvc_device {
649 struct urb *int_urb; 648 struct urb *int_urb;
650 __u8 *status; 649 __u8 *status;
651 struct input_dev *input; 650 struct input_dev *input;
651 char input_phys[64];
652 652
653 /* Video Streaming interfaces */ 653 /* Video Streaming interfaces */
654 struct list_head streaming; 654 struct list_head streaming;
diff --git a/drivers/media/video/v4l2-common.c b/drivers/media/video/v4l2-common.c
index b8f2be8d5c0e..1da8cb836cb6 100644
--- a/drivers/media/video/v4l2-common.c
+++ b/drivers/media/video/v4l2-common.c
@@ -334,6 +334,12 @@ const char **v4l2_ctrl_get_menu(u32 id)
334 "Aperture Priority Mode", 334 "Aperture Priority Mode",
335 NULL 335 NULL
336 }; 336 };
337 static const char *colorfx[] = {
338 "None",
339 "Black & White",
340 "Sepia",
341 NULL
342 };
337 343
338 switch (id) { 344 switch (id) {
339 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: 345 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
@@ -370,6 +376,8 @@ const char **v4l2_ctrl_get_menu(u32 id)
370 return camera_power_line_frequency; 376 return camera_power_line_frequency;
371 case V4L2_CID_EXPOSURE_AUTO: 377 case V4L2_CID_EXPOSURE_AUTO:
372 return camera_exposure_auto; 378 return camera_exposure_auto;
379 case V4L2_CID_COLORFX:
380 return colorfx;
373 default: 381 default:
374 return NULL; 382 return NULL;
375 } 383 }
@@ -382,16 +390,16 @@ const char *v4l2_ctrl_get_name(u32 id)
382 switch (id) { 390 switch (id) {
383 /* USER controls */ 391 /* USER controls */
384 case V4L2_CID_USER_CLASS: return "User Controls"; 392 case V4L2_CID_USER_CLASS: return "User Controls";
393 case V4L2_CID_BRIGHTNESS: return "Brightness";
394 case V4L2_CID_CONTRAST: return "Contrast";
395 case V4L2_CID_SATURATION: return "Saturation";
396 case V4L2_CID_HUE: return "Hue";
385 case V4L2_CID_AUDIO_VOLUME: return "Volume"; 397 case V4L2_CID_AUDIO_VOLUME: return "Volume";
386 case V4L2_CID_AUDIO_MUTE: return "Mute";
387 case V4L2_CID_AUDIO_BALANCE: return "Balance"; 398 case V4L2_CID_AUDIO_BALANCE: return "Balance";
388 case V4L2_CID_AUDIO_BASS: return "Bass"; 399 case V4L2_CID_AUDIO_BASS: return "Bass";
389 case V4L2_CID_AUDIO_TREBLE: return "Treble"; 400 case V4L2_CID_AUDIO_TREBLE: return "Treble";
401 case V4L2_CID_AUDIO_MUTE: return "Mute";
390 case V4L2_CID_AUDIO_LOUDNESS: return "Loudness"; 402 case V4L2_CID_AUDIO_LOUDNESS: return "Loudness";
391 case V4L2_CID_BRIGHTNESS: return "Brightness";
392 case V4L2_CID_CONTRAST: return "Contrast";
393 case V4L2_CID_SATURATION: return "Saturation";
394 case V4L2_CID_HUE: return "Hue";
395 case V4L2_CID_BLACK_LEVEL: return "Black Level"; 403 case V4L2_CID_BLACK_LEVEL: return "Black Level";
396 case V4L2_CID_AUTO_WHITE_BALANCE: return "White Balance, Automatic"; 404 case V4L2_CID_AUTO_WHITE_BALANCE: return "White Balance, Automatic";
397 case V4L2_CID_DO_WHITE_BALANCE: return "Do White Balance"; 405 case V4L2_CID_DO_WHITE_BALANCE: return "Do White Balance";
@@ -412,6 +420,7 @@ const char *v4l2_ctrl_get_name(u32 id)
412 case V4L2_CID_BACKLIGHT_COMPENSATION: return "Backlight Compensation"; 420 case V4L2_CID_BACKLIGHT_COMPENSATION: return "Backlight Compensation";
413 case V4L2_CID_CHROMA_AGC: return "Chroma AGC"; 421 case V4L2_CID_CHROMA_AGC: return "Chroma AGC";
414 case V4L2_CID_COLOR_KILLER: return "Color Killer"; 422 case V4L2_CID_COLOR_KILLER: return "Color Killer";
423 case V4L2_CID_COLORFX: return "Color Effects";
415 424
416 /* MPEG controls */ 425 /* MPEG controls */
417 case V4L2_CID_MPEG_CLASS: return "MPEG Encoder Controls"; 426 case V4L2_CID_MPEG_CLASS: return "MPEG Encoder Controls";
@@ -490,16 +499,25 @@ int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 ste
490 case V4L2_CID_HFLIP: 499 case V4L2_CID_HFLIP:
491 case V4L2_CID_VFLIP: 500 case V4L2_CID_VFLIP:
492 case V4L2_CID_HUE_AUTO: 501 case V4L2_CID_HUE_AUTO:
502 case V4L2_CID_CHROMA_AGC:
503 case V4L2_CID_COLOR_KILLER:
493 case V4L2_CID_MPEG_AUDIO_MUTE: 504 case V4L2_CID_MPEG_AUDIO_MUTE:
494 case V4L2_CID_MPEG_VIDEO_MUTE: 505 case V4L2_CID_MPEG_VIDEO_MUTE:
495 case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE: 506 case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE:
496 case V4L2_CID_MPEG_VIDEO_PULLDOWN: 507 case V4L2_CID_MPEG_VIDEO_PULLDOWN:
497 case V4L2_CID_EXPOSURE_AUTO_PRIORITY: 508 case V4L2_CID_EXPOSURE_AUTO_PRIORITY:
509 case V4L2_CID_FOCUS_AUTO:
498 case V4L2_CID_PRIVACY: 510 case V4L2_CID_PRIVACY:
499 qctrl->type = V4L2_CTRL_TYPE_BOOLEAN; 511 qctrl->type = V4L2_CTRL_TYPE_BOOLEAN;
500 min = 0; 512 min = 0;
501 max = step = 1; 513 max = step = 1;
502 break; 514 break;
515 case V4L2_CID_PAN_RESET:
516 case V4L2_CID_TILT_RESET:
517 qctrl->type = V4L2_CTRL_TYPE_BUTTON;
518 qctrl->flags |= V4L2_CTRL_FLAG_WRITE_ONLY;
519 min = max = step = def = 0;
520 break;
503 case V4L2_CID_POWER_LINE_FREQUENCY: 521 case V4L2_CID_POWER_LINE_FREQUENCY:
504 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: 522 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
505 case V4L2_CID_MPEG_AUDIO_ENCODING: 523 case V4L2_CID_MPEG_AUDIO_ENCODING:
@@ -517,6 +535,7 @@ int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 ste
517 case V4L2_CID_MPEG_STREAM_TYPE: 535 case V4L2_CID_MPEG_STREAM_TYPE:
518 case V4L2_CID_MPEG_STREAM_VBI_FMT: 536 case V4L2_CID_MPEG_STREAM_VBI_FMT:
519 case V4L2_CID_EXPOSURE_AUTO: 537 case V4L2_CID_EXPOSURE_AUTO:
538 case V4L2_CID_COLORFX:
520 qctrl->type = V4L2_CTRL_TYPE_MENU; 539 qctrl->type = V4L2_CTRL_TYPE_MENU;
521 step = 1; 540 step = 1;
522 break; 541 break;
@@ -547,161 +566,29 @@ int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 ste
547 case V4L2_CID_CONTRAST: 566 case V4L2_CID_CONTRAST:
548 case V4L2_CID_SATURATION: 567 case V4L2_CID_SATURATION:
549 case V4L2_CID_HUE: 568 case V4L2_CID_HUE:
569 case V4L2_CID_RED_BALANCE:
570 case V4L2_CID_BLUE_BALANCE:
571 case V4L2_CID_GAMMA:
572 case V4L2_CID_SHARPNESS:
550 qctrl->flags |= V4L2_CTRL_FLAG_SLIDER; 573 qctrl->flags |= V4L2_CTRL_FLAG_SLIDER;
551 break; 574 break;
575 case V4L2_CID_PAN_RELATIVE:
576 case V4L2_CID_TILT_RELATIVE:
577 case V4L2_CID_FOCUS_RELATIVE:
578 case V4L2_CID_ZOOM_RELATIVE:
579 qctrl->flags |= V4L2_CTRL_FLAG_WRITE_ONLY;
580 break;
552 } 581 }
553 qctrl->minimum = min; 582 qctrl->minimum = min;
554 qctrl->maximum = max; 583 qctrl->maximum = max;
555 qctrl->step = step; 584 qctrl->step = step;
556 qctrl->default_value = def; 585 qctrl->default_value = def;
557 qctrl->reserved[0] = qctrl->reserved[1] = 0; 586 qctrl->reserved[0] = qctrl->reserved[1] = 0;
558 snprintf(qctrl->name, sizeof(qctrl->name), name); 587 strlcpy(qctrl->name, name, sizeof(qctrl->name));
559 return 0; 588 return 0;
560} 589}
561EXPORT_SYMBOL(v4l2_ctrl_query_fill); 590EXPORT_SYMBOL(v4l2_ctrl_query_fill);
562 591
563/* Fill in a struct v4l2_queryctrl with standard values based on
564 the control ID. */
565int v4l2_ctrl_query_fill_std(struct v4l2_queryctrl *qctrl)
566{
567 switch (qctrl->id) {
568 /* USER controls */
569 case V4L2_CID_USER_CLASS:
570 case V4L2_CID_MPEG_CLASS:
571 return v4l2_ctrl_query_fill(qctrl, 0, 0, 0, 0);
572 case V4L2_CID_AUDIO_VOLUME:
573 return v4l2_ctrl_query_fill(qctrl, 0, 65535, 65535 / 100, 58880);
574 case V4L2_CID_AUDIO_MUTE:
575 case V4L2_CID_AUDIO_LOUDNESS:
576 return v4l2_ctrl_query_fill(qctrl, 0, 1, 1, 0);
577 case V4L2_CID_AUDIO_BALANCE:
578 case V4L2_CID_AUDIO_BASS:
579 case V4L2_CID_AUDIO_TREBLE:
580 return v4l2_ctrl_query_fill(qctrl, 0, 65535, 65535 / 100, 32768);
581 case V4L2_CID_BRIGHTNESS:
582 return v4l2_ctrl_query_fill(qctrl, 0, 255, 1, 128);
583 case V4L2_CID_CONTRAST:
584 case V4L2_CID_SATURATION:
585 return v4l2_ctrl_query_fill(qctrl, 0, 127, 1, 64);
586 case V4L2_CID_HUE:
587 return v4l2_ctrl_query_fill(qctrl, -128, 127, 1, 0);
588
589 /* MPEG controls */
590 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
591 return v4l2_ctrl_query_fill(qctrl,
592 V4L2_MPEG_AUDIO_SAMPLING_FREQ_44100,
593 V4L2_MPEG_AUDIO_SAMPLING_FREQ_32000, 1,
594 V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000);
595 case V4L2_CID_MPEG_AUDIO_ENCODING:
596 return v4l2_ctrl_query_fill(qctrl,
597 V4L2_MPEG_AUDIO_ENCODING_LAYER_1,
598 V4L2_MPEG_AUDIO_ENCODING_AC3, 1,
599 V4L2_MPEG_AUDIO_ENCODING_LAYER_2);
600 case V4L2_CID_MPEG_AUDIO_L1_BITRATE:
601 return v4l2_ctrl_query_fill(qctrl,
602 V4L2_MPEG_AUDIO_L1_BITRATE_32K,
603 V4L2_MPEG_AUDIO_L1_BITRATE_448K, 1,
604 V4L2_MPEG_AUDIO_L1_BITRATE_256K);
605 case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
606 return v4l2_ctrl_query_fill(qctrl,
607 V4L2_MPEG_AUDIO_L2_BITRATE_32K,
608 V4L2_MPEG_AUDIO_L2_BITRATE_384K, 1,
609 V4L2_MPEG_AUDIO_L2_BITRATE_224K);
610 case V4L2_CID_MPEG_AUDIO_L3_BITRATE:
611 return v4l2_ctrl_query_fill(qctrl,
612 V4L2_MPEG_AUDIO_L3_BITRATE_32K,
613 V4L2_MPEG_AUDIO_L3_BITRATE_320K, 1,
614 V4L2_MPEG_AUDIO_L3_BITRATE_192K);
615 case V4L2_CID_MPEG_AUDIO_AAC_BITRATE:
616 return v4l2_ctrl_query_fill(qctrl, 0, 6400, 1, 3200000);
617 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
618 return v4l2_ctrl_query_fill(qctrl,
619 V4L2_MPEG_AUDIO_AC3_BITRATE_32K,
620 V4L2_MPEG_AUDIO_AC3_BITRATE_640K, 1,
621 V4L2_MPEG_AUDIO_AC3_BITRATE_384K);
622 case V4L2_CID_MPEG_AUDIO_MODE:
623 return v4l2_ctrl_query_fill(qctrl,
624 V4L2_MPEG_AUDIO_MODE_STEREO,
625 V4L2_MPEG_AUDIO_MODE_MONO, 1,
626 V4L2_MPEG_AUDIO_MODE_STEREO);
627 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION:
628 return v4l2_ctrl_query_fill(qctrl,
629 V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_4,
630 V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_16, 1,
631 V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_4);
632 case V4L2_CID_MPEG_AUDIO_EMPHASIS:
633 return v4l2_ctrl_query_fill(qctrl,
634 V4L2_MPEG_AUDIO_EMPHASIS_NONE,
635 V4L2_MPEG_AUDIO_EMPHASIS_CCITT_J17, 1,
636 V4L2_MPEG_AUDIO_EMPHASIS_NONE);
637 case V4L2_CID_MPEG_AUDIO_CRC:
638 return v4l2_ctrl_query_fill(qctrl,
639 V4L2_MPEG_AUDIO_CRC_NONE,
640 V4L2_MPEG_AUDIO_CRC_CRC16, 1,
641 V4L2_MPEG_AUDIO_CRC_NONE);
642 case V4L2_CID_MPEG_AUDIO_MUTE:
643 return v4l2_ctrl_query_fill(qctrl, 0, 1, 1, 0);
644 case V4L2_CID_MPEG_VIDEO_ENCODING:
645 return v4l2_ctrl_query_fill(qctrl,
646 V4L2_MPEG_VIDEO_ENCODING_MPEG_1,
647 V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC, 1,
648 V4L2_MPEG_VIDEO_ENCODING_MPEG_2);
649 case V4L2_CID_MPEG_VIDEO_ASPECT:
650 return v4l2_ctrl_query_fill(qctrl,
651 V4L2_MPEG_VIDEO_ASPECT_1x1,
652 V4L2_MPEG_VIDEO_ASPECT_221x100, 1,
653 V4L2_MPEG_VIDEO_ASPECT_4x3);
654 case V4L2_CID_MPEG_VIDEO_B_FRAMES:
655 return v4l2_ctrl_query_fill(qctrl, 0, 33, 1, 2);
656 case V4L2_CID_MPEG_VIDEO_GOP_SIZE:
657 return v4l2_ctrl_query_fill(qctrl, 1, 34, 1, 12);
658 case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE:
659 return v4l2_ctrl_query_fill(qctrl, 0, 1, 1, 1);
660 case V4L2_CID_MPEG_VIDEO_PULLDOWN:
661 return v4l2_ctrl_query_fill(qctrl, 0, 1, 1, 0);
662 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
663 return v4l2_ctrl_query_fill(qctrl,
664 V4L2_MPEG_VIDEO_BITRATE_MODE_VBR,
665 V4L2_MPEG_VIDEO_BITRATE_MODE_CBR, 1,
666 V4L2_MPEG_VIDEO_BITRATE_MODE_VBR);
667 case V4L2_CID_MPEG_VIDEO_BITRATE:
668 return v4l2_ctrl_query_fill(qctrl, 0, 27000000, 1, 6000000);
669 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK:
670 return v4l2_ctrl_query_fill(qctrl, 0, 27000000, 1, 8000000);
671 case V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION:
672 return v4l2_ctrl_query_fill(qctrl, 0, 255, 1, 0);
673 case V4L2_CID_MPEG_VIDEO_MUTE:
674 return v4l2_ctrl_query_fill(qctrl, 0, 1, 1, 0);
675 case V4L2_CID_MPEG_VIDEO_MUTE_YUV: /* Init YUV (really YCbCr) to black */
676 return v4l2_ctrl_query_fill(qctrl, 0, 0xffffff, 1, 0x008080);
677 case V4L2_CID_MPEG_STREAM_TYPE:
678 return v4l2_ctrl_query_fill(qctrl,
679 V4L2_MPEG_STREAM_TYPE_MPEG2_PS,
680 V4L2_MPEG_STREAM_TYPE_MPEG2_SVCD, 1,
681 V4L2_MPEG_STREAM_TYPE_MPEG2_PS);
682 case V4L2_CID_MPEG_STREAM_PID_PMT:
683 return v4l2_ctrl_query_fill(qctrl, 0, (1 << 14) - 1, 1, 16);
684 case V4L2_CID_MPEG_STREAM_PID_AUDIO:
685 return v4l2_ctrl_query_fill(qctrl, 0, (1 << 14) - 1, 1, 260);
686 case V4L2_CID_MPEG_STREAM_PID_VIDEO:
687 return v4l2_ctrl_query_fill(qctrl, 0, (1 << 14) - 1, 1, 256);
688 case V4L2_CID_MPEG_STREAM_PID_PCR:
689 return v4l2_ctrl_query_fill(qctrl, 0, (1 << 14) - 1, 1, 259);
690 case V4L2_CID_MPEG_STREAM_PES_ID_AUDIO:
691 return v4l2_ctrl_query_fill(qctrl, 0, 255, 1, 0);
692 case V4L2_CID_MPEG_STREAM_PES_ID_VIDEO:
693 return v4l2_ctrl_query_fill(qctrl, 0, 255, 1, 0);
694 case V4L2_CID_MPEG_STREAM_VBI_FMT:
695 return v4l2_ctrl_query_fill(qctrl,
696 V4L2_MPEG_STREAM_VBI_FMT_NONE,
697 V4L2_MPEG_STREAM_VBI_FMT_IVTV, 1,
698 V4L2_MPEG_STREAM_VBI_FMT_NONE);
699 default:
700 return -EINVAL;
701 }
702}
703EXPORT_SYMBOL(v4l2_ctrl_query_fill_std);
704
705/* Fill in a struct v4l2_querymenu based on the struct v4l2_queryctrl and 592/* Fill in a struct v4l2_querymenu based on the struct v4l2_queryctrl and
706 the menu. The qctrl pointer may be NULL, in which case it is ignored. 593 the menu. The qctrl pointer may be NULL, in which case it is ignored.
707 If menu_items is NULL, then the menu items are retrieved using 594 If menu_items is NULL, then the menu items are retrieved using
@@ -720,7 +607,7 @@ int v4l2_ctrl_query_menu(struct v4l2_querymenu *qmenu, struct v4l2_queryctrl *qc
720 for (i = 0; i < qmenu->index && menu_items[i]; i++) ; 607 for (i = 0; i < qmenu->index && menu_items[i]; i++) ;
721 if (menu_items[i] == NULL || menu_items[i][0] == '\0') 608 if (menu_items[i] == NULL || menu_items[i][0] == '\0')
722 return -EINVAL; 609 return -EINVAL;
723 snprintf(qmenu->name, sizeof(qmenu->name), menu_items[qmenu->index]); 610 strlcpy(qmenu->name, menu_items[qmenu->index], sizeof(qmenu->name));
724 return 0; 611 return 0;
725} 612}
726EXPORT_SYMBOL(v4l2_ctrl_query_menu); 613EXPORT_SYMBOL(v4l2_ctrl_query_menu);
@@ -737,8 +624,8 @@ int v4l2_ctrl_query_menu_valid_items(struct v4l2_querymenu *qmenu, const u32 *id
737 return -EINVAL; 624 return -EINVAL;
738 while (*ids != V4L2_CTRL_MENU_IDS_END) { 625 while (*ids != V4L2_CTRL_MENU_IDS_END) {
739 if (*ids++ == qmenu->index) { 626 if (*ids++ == qmenu->index) {
740 snprintf(qmenu->name, sizeof(qmenu->name), 627 strlcpy(qmenu->name, menu_items[qmenu->index],
741 menu_items[qmenu->index]); 628 sizeof(qmenu->name));
742 return 0; 629 return 0;
743 } 630 }
744 } 631 }
@@ -749,7 +636,7 @@ EXPORT_SYMBOL(v4l2_ctrl_query_menu_valid_items);
749/* ctrl_classes points to an array of u32 pointers, the last element is 636/* ctrl_classes points to an array of u32 pointers, the last element is
750 a NULL pointer. Each u32 array is a 0-terminated array of control IDs. 637 a NULL pointer. Each u32 array is a 0-terminated array of control IDs.
751 Each array must be sorted low to high and belong to the same control 638 Each array must be sorted low to high and belong to the same control
752 class. The array of u32 pointer must also be sorted, from low class IDs 639 class. The array of u32 pointers must also be sorted, from low class IDs
753 to high class IDs. 640 to high class IDs.
754 641
755 This function returns the first ID that follows after the given ID. 642 This function returns the first ID that follows after the given ID.
@@ -910,10 +797,10 @@ struct v4l2_subdev *v4l2_i2c_new_subdev(struct i2c_adapter *adapter,
910 struct i2c_board_info info; 797 struct i2c_board_info info;
911 798
912 BUG_ON(!dev); 799 BUG_ON(!dev);
913#ifdef MODULE 800
914 if (module_name) 801 if (module_name)
915 request_module(module_name); 802 request_module(module_name);
916#endif 803
917 /* Setup the i2c board info with the device type and 804 /* Setup the i2c board info with the device type and
918 the device address. */ 805 the device address. */
919 memset(&info, 0, sizeof(info)); 806 memset(&info, 0, sizeof(info));
@@ -927,11 +814,11 @@ struct v4l2_subdev *v4l2_i2c_new_subdev(struct i2c_adapter *adapter,
927 We need better support from the kernel so that we 814 We need better support from the kernel so that we
928 can easily wait for the load to finish. */ 815 can easily wait for the load to finish. */
929 if (client == NULL || client->driver == NULL) 816 if (client == NULL || client->driver == NULL)
930 return NULL; 817 goto error;
931 818
932 /* Lock the module so we can safely get the v4l2_subdev pointer */ 819 /* Lock the module so we can safely get the v4l2_subdev pointer */
933 if (!try_module_get(client->driver->driver.owner)) 820 if (!try_module_get(client->driver->driver.owner))
934 return NULL; 821 goto error;
935 sd = i2c_get_clientdata(client); 822 sd = i2c_get_clientdata(client);
936 823
937 /* Register with the v4l2_device which increases the module's 824 /* Register with the v4l2_device which increases the module's
@@ -940,8 +827,13 @@ struct v4l2_subdev *v4l2_i2c_new_subdev(struct i2c_adapter *adapter,
940 sd = NULL; 827 sd = NULL;
941 /* Decrease the module use count to match the first try_module_get. */ 828 /* Decrease the module use count to match the first try_module_get. */
942 module_put(client->driver->driver.owner); 829 module_put(client->driver->driver.owner);
943 return sd;
944 830
831error:
832 /* If we have a client but no subdev, then something went wrong and
833 we must unregister the client. */
834 if (client && sd == NULL)
835 i2c_unregister_device(client);
836 return sd;
945} 837}
946EXPORT_SYMBOL_GPL(v4l2_i2c_new_subdev); 838EXPORT_SYMBOL_GPL(v4l2_i2c_new_subdev);
947 839
@@ -958,10 +850,10 @@ struct v4l2_subdev *v4l2_i2c_new_probed_subdev(struct i2c_adapter *adapter,
958 struct i2c_board_info info; 850 struct i2c_board_info info;
959 851
960 BUG_ON(!dev); 852 BUG_ON(!dev);
961#ifdef MODULE 853
962 if (module_name) 854 if (module_name)
963 request_module(module_name); 855 request_module(module_name);
964#endif 856
965 /* Setup the i2c board info with the device type and 857 /* Setup the i2c board info with the device type and
966 the device address. */ 858 the device address. */
967 memset(&info, 0, sizeof(info)); 859 memset(&info, 0, sizeof(info));
@@ -974,11 +866,11 @@ struct v4l2_subdev *v4l2_i2c_new_probed_subdev(struct i2c_adapter *adapter,
974 We need better support from the kernel so that we 866 We need better support from the kernel so that we
975 can easily wait for the load to finish. */ 867 can easily wait for the load to finish. */
976 if (client == NULL || client->driver == NULL) 868 if (client == NULL || client->driver == NULL)
977 return NULL; 869 goto error;
978 870
979 /* Lock the module so we can safely get the v4l2_subdev pointer */ 871 /* Lock the module so we can safely get the v4l2_subdev pointer */
980 if (!try_module_get(client->driver->driver.owner)) 872 if (!try_module_get(client->driver->driver.owner))
981 return NULL; 873 goto error;
982 sd = i2c_get_clientdata(client); 874 sd = i2c_get_clientdata(client);
983 875
984 /* Register with the v4l2_device which increases the module's 876 /* Register with the v4l2_device which increases the module's
@@ -987,8 +879,59 @@ struct v4l2_subdev *v4l2_i2c_new_probed_subdev(struct i2c_adapter *adapter,
987 sd = NULL; 879 sd = NULL;
988 /* Decrease the module use count to match the first try_module_get. */ 880 /* Decrease the module use count to match the first try_module_get. */
989 module_put(client->driver->driver.owner); 881 module_put(client->driver->driver.owner);
882
883error:
884 /* If we have a client but no subdev, then something went wrong and
885 we must unregister the client. */
886 if (client && sd == NULL)
887 i2c_unregister_device(client);
990 return sd; 888 return sd;
991} 889}
992EXPORT_SYMBOL_GPL(v4l2_i2c_new_probed_subdev); 890EXPORT_SYMBOL_GPL(v4l2_i2c_new_probed_subdev);
993 891
892/* Return i2c client address of v4l2_subdev. */
893unsigned short v4l2_i2c_subdev_addr(struct v4l2_subdev *sd)
894{
895 struct i2c_client *client = v4l2_get_subdevdata(sd);
896
897 return client ? client->addr : I2C_CLIENT_END;
898}
899EXPORT_SYMBOL_GPL(v4l2_i2c_subdev_addr);
900
901/* Return a list of I2C tuner addresses to probe. Use only if the tuner
902 addresses are unknown. */
903const unsigned short *v4l2_i2c_tuner_addrs(enum v4l2_i2c_tuner_type type)
904{
905 static const unsigned short radio_addrs[] = {
906#if defined(CONFIG_MEDIA_TUNER_TEA5761) || defined(CONFIG_MEDIA_TUNER_TEA5761_MODULE)
907 0x10,
908#endif
909 0x60,
910 I2C_CLIENT_END
911 };
912 static const unsigned short demod_addrs[] = {
913 0x42, 0x43, 0x4a, 0x4b,
914 I2C_CLIENT_END
915 };
916 static const unsigned short tv_addrs[] = {
917 0x42, 0x43, 0x4a, 0x4b, /* tda8290 */
918 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
919 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
920 I2C_CLIENT_END
921 };
922
923 switch (type) {
924 case ADDRS_RADIO:
925 return radio_addrs;
926 case ADDRS_DEMOD:
927 return demod_addrs;
928 case ADDRS_TV:
929 return tv_addrs;
930 case ADDRS_TV_WITH_DEMOD:
931 return tv_addrs + 4;
932 }
933 return NULL;
934}
935EXPORT_SYMBOL_GPL(v4l2_i2c_tuner_addrs);
936
994#endif 937#endif
diff --git a/drivers/media/video/v4l2-compat-ioctl32.c b/drivers/media/video/v4l2-compat-ioctl32.c
index 110376be5d2b..0056b115b42e 100644
--- a/drivers/media/video/v4l2-compat-ioctl32.c
+++ b/drivers/media/video/v4l2-compat-ioctl32.c
@@ -1047,7 +1047,6 @@ long v4l2_compat_ioctl32(struct file *file, unsigned int cmd, unsigned long arg)
1047 case VIDIOC_DBG_S_REGISTER: 1047 case VIDIOC_DBG_S_REGISTER:
1048 case VIDIOC_DBG_G_REGISTER: 1048 case VIDIOC_DBG_G_REGISTER:
1049 case VIDIOC_DBG_G_CHIP_IDENT: 1049 case VIDIOC_DBG_G_CHIP_IDENT:
1050 case VIDIOC_G_CHIP_IDENT_OLD:
1051 case VIDIOC_S_HW_FREQ_SEEK: 1050 case VIDIOC_S_HW_FREQ_SEEK:
1052 ret = do_video_ioctl(file, cmd, arg); 1051 ret = do_video_ioctl(file, cmd, arg);
1053 break; 1052 break;
diff --git a/drivers/media/video/v4l2-dev.c b/drivers/media/video/v4l2-dev.c
index 13f87c22e78d..91228b3df07d 100644
--- a/drivers/media/video/v4l2-dev.c
+++ b/drivers/media/video/v4l2-dev.c
@@ -198,6 +198,23 @@ static long v4l2_unlocked_ioctl(struct file *filp,
198 return vdev->fops->unlocked_ioctl(filp, cmd, arg); 198 return vdev->fops->unlocked_ioctl(filp, cmd, arg);
199} 199}
200 200
201#ifdef CONFIG_MMU
202#define v4l2_get_unmapped_area NULL
203#else
204static unsigned long v4l2_get_unmapped_area(struct file *filp,
205 unsigned long addr, unsigned long len, unsigned long pgoff,
206 unsigned long flags)
207{
208 struct video_device *vdev = video_devdata(filp);
209
210 if (!vdev->fops->get_unmapped_area)
211 return -ENOSYS;
212 if (video_is_unregistered(vdev))
213 return -ENODEV;
214 return vdev->fops->get_unmapped_area(filp, addr, len, pgoff, flags);
215}
216#endif
217
201static int v4l2_mmap(struct file *filp, struct vm_area_struct *vm) 218static int v4l2_mmap(struct file *filp, struct vm_area_struct *vm)
202{ 219{
203 struct video_device *vdev = video_devdata(filp); 220 struct video_device *vdev = video_devdata(filp);
@@ -250,6 +267,7 @@ static const struct file_operations v4l2_unlocked_fops = {
250 .read = v4l2_read, 267 .read = v4l2_read,
251 .write = v4l2_write, 268 .write = v4l2_write,
252 .open = v4l2_open, 269 .open = v4l2_open,
270 .get_unmapped_area = v4l2_get_unmapped_area,
253 .mmap = v4l2_mmap, 271 .mmap = v4l2_mmap,
254 .unlocked_ioctl = v4l2_unlocked_ioctl, 272 .unlocked_ioctl = v4l2_unlocked_ioctl,
255#ifdef CONFIG_COMPAT 273#ifdef CONFIG_COMPAT
@@ -265,6 +283,7 @@ static const struct file_operations v4l2_fops = {
265 .read = v4l2_read, 283 .read = v4l2_read,
266 .write = v4l2_write, 284 .write = v4l2_write,
267 .open = v4l2_open, 285 .open = v4l2_open,
286 .get_unmapped_area = v4l2_get_unmapped_area,
268 .mmap = v4l2_mmap, 287 .mmap = v4l2_mmap,
269 .ioctl = v4l2_ioctl, 288 .ioctl = v4l2_ioctl,
270#ifdef CONFIG_COMPAT 289#ifdef CONFIG_COMPAT
@@ -288,37 +307,38 @@ static const struct file_operations v4l2_fops = {
288 */ 307 */
289static int get_index(struct video_device *vdev, int num) 308static int get_index(struct video_device *vdev, int num)
290{ 309{
291 u32 used = 0; 310 /* This can be static since this function is called with the global
292 const int max_index = sizeof(used) * 8 - 1; 311 videodev_lock held. */
312 static DECLARE_BITMAP(used, VIDEO_NUM_DEVICES);
293 int i; 313 int i;
294 314
295 /* Currently a single v4l driver instance cannot create more than 315 if (num >= VIDEO_NUM_DEVICES) {
296 32 devices.
297 Increase to u64 or an array of u32 if more are needed. */
298 if (num > max_index) {
299 printk(KERN_ERR "videodev: %s num is too large\n", __func__); 316 printk(KERN_ERR "videodev: %s num is too large\n", __func__);
300 return -EINVAL; 317 return -EINVAL;
301 } 318 }
302 319
303 /* Some drivers do not set the parent. In that case always return 0. */ 320 /* Some drivers do not set the parent. In that case always return
321 num or 0. */
304 if (vdev->parent == NULL) 322 if (vdev->parent == NULL)
305 return 0; 323 return num >= 0 ? num : 0;
324
325 bitmap_zero(used, VIDEO_NUM_DEVICES);
306 326
307 for (i = 0; i < VIDEO_NUM_DEVICES; i++) { 327 for (i = 0; i < VIDEO_NUM_DEVICES; i++) {
308 if (video_device[i] != NULL && 328 if (video_device[i] != NULL &&
309 video_device[i]->parent == vdev->parent) { 329 video_device[i]->parent == vdev->parent) {
310 used |= 1 << video_device[i]->index; 330 set_bit(video_device[i]->index, used);
311 } 331 }
312 } 332 }
313 333
314 if (num >= 0) { 334 if (num >= 0) {
315 if (used & (1 << num)) 335 if (test_bit(num, used))
316 return -ENFILE; 336 return -ENFILE;
317 return num; 337 return num;
318 } 338 }
319 339
320 i = ffz(used); 340 i = find_first_zero_bit(used, VIDEO_NUM_DEVICES);
321 return i > max_index ? -ENFILE : i; 341 return i == VIDEO_NUM_DEVICES ? -ENFILE : i;
322} 342}
323 343
324int video_register_device(struct video_device *vdev, int type, int nr) 344int video_register_device(struct video_device *vdev, int type, int nr)
@@ -365,12 +385,11 @@ int video_register_device_index(struct video_device *vdev, int type, int nr,
365 385
366 /* A minor value of -1 marks this video device as never 386 /* A minor value of -1 marks this video device as never
367 having been registered */ 387 having been registered */
368 if (vdev) 388 vdev->minor = -1;
369 vdev->minor = -1;
370 389
371 /* the release callback MUST be present */ 390 /* the release callback MUST be present */
372 WARN_ON(!vdev || !vdev->release); 391 WARN_ON(!vdev->release);
373 if (!vdev || !vdev->release) 392 if (!vdev->release)
374 return -EINVAL; 393 return -EINVAL;
375 394
376 /* Part 1: check device type */ 395 /* Part 1: check device type */
@@ -395,7 +414,7 @@ int video_register_device_index(struct video_device *vdev, int type, int nr,
395 414
396 vdev->vfl_type = type; 415 vdev->vfl_type = type;
397 vdev->cdev = NULL; 416 vdev->cdev = NULL;
398 if (vdev->v4l2_dev) 417 if (vdev->v4l2_dev && vdev->v4l2_dev->dev)
399 vdev->parent = vdev->v4l2_dev->dev; 418 vdev->parent = vdev->v4l2_dev->dev;
400 419
401 /* Part 2: find a free minor, kernel number and device index. */ 420 /* Part 2: find a free minor, kernel number and device index. */
@@ -582,6 +601,7 @@ module_exit(videodev_exit)
582MODULE_AUTHOR("Alan Cox, Mauro Carvalho Chehab <mchehab@infradead.org>"); 601MODULE_AUTHOR("Alan Cox, Mauro Carvalho Chehab <mchehab@infradead.org>");
583MODULE_DESCRIPTION("Device registrar for Video4Linux drivers v2"); 602MODULE_DESCRIPTION("Device registrar for Video4Linux drivers v2");
584MODULE_LICENSE("GPL"); 603MODULE_LICENSE("GPL");
604MODULE_ALIAS_CHARDEV_MAJOR(VIDEO_MAJOR);
585 605
586 606
587/* 607/*
diff --git a/drivers/media/video/v4l2-device.c b/drivers/media/video/v4l2-device.c
index 8a4b74f3129f..94aa485ade52 100644
--- a/drivers/media/video/v4l2-device.c
+++ b/drivers/media/video/v4l2-device.c
@@ -26,48 +26,66 @@
26 26
27int v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev) 27int v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev)
28{ 28{
29 if (dev == NULL || v4l2_dev == NULL) 29 if (v4l2_dev == NULL)
30 return -EINVAL; 30 return -EINVAL;
31 /* Warn if we apparently re-register a device */ 31
32 WARN_ON(dev_get_drvdata(dev) != NULL);
33 INIT_LIST_HEAD(&v4l2_dev->subdevs); 32 INIT_LIST_HEAD(&v4l2_dev->subdevs);
34 spin_lock_init(&v4l2_dev->lock); 33 spin_lock_init(&v4l2_dev->lock);
35 v4l2_dev->dev = dev; 34 v4l2_dev->dev = dev;
36 snprintf(v4l2_dev->name, sizeof(v4l2_dev->name), "%s %s", 35 if (dev == NULL) {
36 /* If dev == NULL, then name must be filled in by the caller */
37 WARN_ON(!v4l2_dev->name[0]);
38 return 0;
39 }
40
41 /* Set name to driver name + device name if it is empty. */
42 if (!v4l2_dev->name[0])
43 snprintf(v4l2_dev->name, sizeof(v4l2_dev->name), "%s %s",
37 dev->driver->name, dev_name(dev)); 44 dev->driver->name, dev_name(dev));
45 if (dev_get_drvdata(dev))
46 v4l2_warn(v4l2_dev, "Non-NULL drvdata on register\n");
38 dev_set_drvdata(dev, v4l2_dev); 47 dev_set_drvdata(dev, v4l2_dev);
39 return 0; 48 return 0;
40} 49}
41EXPORT_SYMBOL_GPL(v4l2_device_register); 50EXPORT_SYMBOL_GPL(v4l2_device_register);
42 51
52void v4l2_device_disconnect(struct v4l2_device *v4l2_dev)
53{
54 if (v4l2_dev->dev) {
55 dev_set_drvdata(v4l2_dev->dev, NULL);
56 v4l2_dev->dev = NULL;
57 }
58}
59EXPORT_SYMBOL_GPL(v4l2_device_disconnect);
60
43void v4l2_device_unregister(struct v4l2_device *v4l2_dev) 61void v4l2_device_unregister(struct v4l2_device *v4l2_dev)
44{ 62{
45 struct v4l2_subdev *sd, *next; 63 struct v4l2_subdev *sd, *next;
46 64
47 if (v4l2_dev == NULL || v4l2_dev->dev == NULL) 65 if (v4l2_dev == NULL)
48 return; 66 return;
49 dev_set_drvdata(v4l2_dev->dev, NULL); 67 v4l2_device_disconnect(v4l2_dev);
50 /* unregister subdevs */ 68
69 /* Unregister subdevs */
51 list_for_each_entry_safe(sd, next, &v4l2_dev->subdevs, list) 70 list_for_each_entry_safe(sd, next, &v4l2_dev->subdevs, list)
52 v4l2_device_unregister_subdev(sd); 71 v4l2_device_unregister_subdev(sd);
53
54 v4l2_dev->dev = NULL;
55} 72}
56EXPORT_SYMBOL_GPL(v4l2_device_unregister); 73EXPORT_SYMBOL_GPL(v4l2_device_unregister);
57 74
58int v4l2_device_register_subdev(struct v4l2_device *dev, struct v4l2_subdev *sd) 75int v4l2_device_register_subdev(struct v4l2_device *v4l2_dev,
76 struct v4l2_subdev *sd)
59{ 77{
60 /* Check for valid input */ 78 /* Check for valid input */
61 if (dev == NULL || sd == NULL || !sd->name[0]) 79 if (v4l2_dev == NULL || sd == NULL || !sd->name[0])
62 return -EINVAL; 80 return -EINVAL;
63 /* Warn if we apparently re-register a subdev */ 81 /* Warn if we apparently re-register a subdev */
64 WARN_ON(sd->dev != NULL); 82 WARN_ON(sd->v4l2_dev != NULL);
65 if (!try_module_get(sd->owner)) 83 if (!try_module_get(sd->owner))
66 return -ENODEV; 84 return -ENODEV;
67 sd->dev = dev; 85 sd->v4l2_dev = v4l2_dev;
68 spin_lock(&dev->lock); 86 spin_lock(&v4l2_dev->lock);
69 list_add_tail(&sd->list, &dev->subdevs); 87 list_add_tail(&sd->list, &v4l2_dev->subdevs);
70 spin_unlock(&dev->lock); 88 spin_unlock(&v4l2_dev->lock);
71 return 0; 89 return 0;
72} 90}
73EXPORT_SYMBOL_GPL(v4l2_device_register_subdev); 91EXPORT_SYMBOL_GPL(v4l2_device_register_subdev);
@@ -75,12 +93,12 @@ EXPORT_SYMBOL_GPL(v4l2_device_register_subdev);
75void v4l2_device_unregister_subdev(struct v4l2_subdev *sd) 93void v4l2_device_unregister_subdev(struct v4l2_subdev *sd)
76{ 94{
77 /* return if it isn't registered */ 95 /* return if it isn't registered */
78 if (sd == NULL || sd->dev == NULL) 96 if (sd == NULL || sd->v4l2_dev == NULL)
79 return; 97 return;
80 spin_lock(&sd->dev->lock); 98 spin_lock(&sd->v4l2_dev->lock);
81 list_del(&sd->list); 99 list_del(&sd->list);
82 spin_unlock(&sd->dev->lock); 100 spin_unlock(&sd->v4l2_dev->lock);
83 sd->dev = NULL; 101 sd->v4l2_dev = NULL;
84 module_put(sd->owner); 102 module_put(sd->owner);
85} 103}
86EXPORT_SYMBOL_GPL(v4l2_device_unregister_subdev); 104EXPORT_SYMBOL_GPL(v4l2_device_unregister_subdev);
diff --git a/drivers/media/video/v4l2-ioctl.c b/drivers/media/video/v4l2-ioctl.c
index 52d687b165e0..f41c6f506f42 100644
--- a/drivers/media/video/v4l2-ioctl.c
+++ b/drivers/media/video/v4l2-ioctl.c
@@ -17,6 +17,7 @@
17#include <linux/kernel.h> 17#include <linux/kernel.h>
18 18
19#define __OLD_VIDIOC_ /* To allow fixing old calls */ 19#define __OLD_VIDIOC_ /* To allow fixing old calls */
20#include <linux/videodev.h>
20#include <linux/videodev2.h> 21#include <linux/videodev2.h>
21 22
22#ifdef CONFIG_VIDEO_V4L1 23#ifdef CONFIG_VIDEO_V4L1
@@ -24,7 +25,7 @@
24#endif 25#endif
25#include <media/v4l2-common.h> 26#include <media/v4l2-common.h>
26#include <media/v4l2-ioctl.h> 27#include <media/v4l2-ioctl.h>
27#include <linux/video_decoder.h> 28#include <media/v4l2-chip-ident.h>
28 29
29#define dbgarg(cmd, fmt, arg...) \ 30#define dbgarg(cmd, fmt, arg...) \
30 do { \ 31 do { \
@@ -100,25 +101,27 @@ const char *v4l2_norm_to_name(v4l2_std_id id)
100} 101}
101EXPORT_SYMBOL(v4l2_norm_to_name); 102EXPORT_SYMBOL(v4l2_norm_to_name);
102 103
104/* Returns frame period for the given standard */
105void v4l2_video_std_frame_period(int id, struct v4l2_fract *frameperiod)
106{
107 if (id & V4L2_STD_525_60) {
108 frameperiod->numerator = 1001;
109 frameperiod->denominator = 30000;
110 } else {
111 frameperiod->numerator = 1;
112 frameperiod->denominator = 25;
113 }
114}
115EXPORT_SYMBOL(v4l2_video_std_frame_period);
116
103/* Fill in the fields of a v4l2_standard structure according to the 117/* Fill in the fields of a v4l2_standard structure according to the
104 'id' and 'transmission' parameters. Returns negative on error. */ 118 'id' and 'transmission' parameters. Returns negative on error. */
105int v4l2_video_std_construct(struct v4l2_standard *vs, 119int v4l2_video_std_construct(struct v4l2_standard *vs,
106 int id, const char *name) 120 int id, const char *name)
107{ 121{
108 u32 index = vs->index; 122 vs->id = id;
109 123 v4l2_video_std_frame_period(id, &vs->frameperiod);
110 memset(vs, 0, sizeof(struct v4l2_standard)); 124 vs->framelines = (id & V4L2_STD_525_60) ? 525 : 625;
111 vs->index = index;
112 vs->id = id;
113 if (id & V4L2_STD_525_60) {
114 vs->frameperiod.numerator = 1001;
115 vs->frameperiod.denominator = 30000;
116 vs->framelines = 525;
117 } else {
118 vs->frameperiod.numerator = 1;
119 vs->frameperiod.denominator = 25;
120 vs->framelines = 625;
121 }
122 strlcpy(vs->name, name, sizeof(vs->name)); 125 strlcpy(vs->name, name, sizeof(vs->name));
123 return 0; 126 return 0;
124} 127}
@@ -273,19 +276,6 @@ static const char *v4l2_ioctls[] = {
273#define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls) 276#define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
274 277
275static const char *v4l2_int_ioctls[] = { 278static const char *v4l2_int_ioctls[] = {
276#ifdef CONFIG_VIDEO_V4L1_COMPAT
277 [_IOC_NR(DECODER_GET_CAPABILITIES)] = "DECODER_GET_CAPABILITIES",
278 [_IOC_NR(DECODER_GET_STATUS)] = "DECODER_GET_STATUS",
279 [_IOC_NR(DECODER_SET_NORM)] = "DECODER_SET_NORM",
280 [_IOC_NR(DECODER_SET_INPUT)] = "DECODER_SET_INPUT",
281 [_IOC_NR(DECODER_SET_OUTPUT)] = "DECODER_SET_OUTPUT",
282 [_IOC_NR(DECODER_ENABLE_OUTPUT)] = "DECODER_ENABLE_OUTPUT",
283 [_IOC_NR(DECODER_SET_PICTURE)] = "DECODER_SET_PICTURE",
284 [_IOC_NR(DECODER_SET_GPIO)] = "DECODER_SET_GPIO",
285 [_IOC_NR(DECODER_INIT)] = "DECODER_INIT",
286 [_IOC_NR(DECODER_SET_VBI_BYPASS)] = "DECODER_SET_VBI_BYPASS",
287 [_IOC_NR(DECODER_DUMP)] = "DECODER_DUMP",
288#endif
289 [_IOC_NR(AUDC_SET_RADIO)] = "AUDC_SET_RADIO", 279 [_IOC_NR(AUDC_SET_RADIO)] = "AUDC_SET_RADIO",
290 280
291 [_IOC_NR(TUNER_SET_TYPE_ADDR)] = "TUNER_SET_TYPE_ADDR", 281 [_IOC_NR(TUNER_SET_TYPE_ADDR)] = "TUNER_SET_TYPE_ADDR",
@@ -654,8 +644,6 @@ static long __video_do_ioctl(struct file *file,
654 if (cmd == VIDIOCGMBUF) { 644 if (cmd == VIDIOCGMBUF) {
655 struct video_mbuf *p = arg; 645 struct video_mbuf *p = arg;
656 646
657 memset(p, 0, sizeof(*p));
658
659 if (!ops->vidiocgmbuf) 647 if (!ops->vidiocgmbuf)
660 return ret; 648 return ret;
661 ret = ops->vidiocgmbuf(file, fh, p); 649 ret = ops->vidiocgmbuf(file, fh, p);
@@ -682,7 +670,6 @@ static long __video_do_ioctl(struct file *file,
682 case VIDIOC_QUERYCAP: 670 case VIDIOC_QUERYCAP:
683 { 671 {
684 struct v4l2_capability *cap = (struct v4l2_capability *)arg; 672 struct v4l2_capability *cap = (struct v4l2_capability *)arg;
685 memset(cap, 0, sizeof(*cap));
686 673
687 if (!ops->vidioc_querycap) 674 if (!ops->vidioc_querycap)
688 break; 675 break;
@@ -725,16 +712,8 @@ static long __video_do_ioctl(struct file *file,
725 case VIDIOC_ENUM_FMT: 712 case VIDIOC_ENUM_FMT:
726 { 713 {
727 struct v4l2_fmtdesc *f = arg; 714 struct v4l2_fmtdesc *f = arg;
728 enum v4l2_buf_type type;
729 unsigned int index;
730
731 index = f->index;
732 type = f->type;
733 memset(f, 0, sizeof(*f));
734 f->index = index;
735 f->type = type;
736 715
737 switch (type) { 716 switch (f->type) {
738 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 717 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
739 if (ops->vidioc_enum_fmt_vid_cap) 718 if (ops->vidioc_enum_fmt_vid_cap)
740 ret = ops->vidioc_enum_fmt_vid_cap(file, fh, f); 719 ret = ops->vidioc_enum_fmt_vid_cap(file, fh, f);
@@ -771,8 +750,6 @@ static long __video_do_ioctl(struct file *file,
771 { 750 {
772 struct v4l2_format *f = (struct v4l2_format *)arg; 751 struct v4l2_format *f = (struct v4l2_format *)arg;
773 752
774 memset(f->fmt.raw_data, 0, sizeof(f->fmt.raw_data));
775
776 /* FIXME: Should be one dump per type */ 753 /* FIXME: Should be one dump per type */
777 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names)); 754 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
778 755
@@ -1088,7 +1065,6 @@ static long __video_do_ioctl(struct file *file,
1088 return -EINVAL; 1065 return -EINVAL;
1089 1066
1090 v4l2_video_std_construct(p, curr_id, descr); 1067 v4l2_video_std_construct(p, curr_id, descr);
1091 p->index = index;
1092 1068
1093 dbgarg(cmd, "index=%d, id=0x%Lx, name=%s, fps=%d/%d, " 1069 dbgarg(cmd, "index=%d, id=0x%Lx, name=%s, fps=%d/%d, "
1094 "framelines=%d\n", p->index, 1070 "framelines=%d\n", p->index,
@@ -1153,12 +1129,9 @@ static long __video_do_ioctl(struct file *file,
1153 case VIDIOC_ENUMINPUT: 1129 case VIDIOC_ENUMINPUT:
1154 { 1130 {
1155 struct v4l2_input *p = arg; 1131 struct v4l2_input *p = arg;
1156 int i = p->index;
1157 1132
1158 if (!ops->vidioc_enum_input) 1133 if (!ops->vidioc_enum_input)
1159 break; 1134 break;
1160 memset(p, 0, sizeof(*p));
1161 p->index = i;
1162 1135
1163 ret = ops->vidioc_enum_input(file, fh, p); 1136 ret = ops->vidioc_enum_input(file, fh, p);
1164 if (!ret) 1137 if (!ret)
@@ -1197,12 +1170,9 @@ static long __video_do_ioctl(struct file *file,
1197 case VIDIOC_ENUMOUTPUT: 1170 case VIDIOC_ENUMOUTPUT:
1198 { 1171 {
1199 struct v4l2_output *p = arg; 1172 struct v4l2_output *p = arg;
1200 int i = p->index;
1201 1173
1202 if (!ops->vidioc_enum_output) 1174 if (!ops->vidioc_enum_output)
1203 break; 1175 break;
1204 memset(p, 0, sizeof(*p));
1205 p->index = i;
1206 1176
1207 ret = ops->vidioc_enum_output(file, fh, p); 1177 ret = ops->vidioc_enum_output(file, fh, p);
1208 if (!ret) 1178 if (!ret)
@@ -1378,13 +1348,10 @@ static long __video_do_ioctl(struct file *file,
1378 case VIDIOC_G_AUDIO: 1348 case VIDIOC_G_AUDIO:
1379 { 1349 {
1380 struct v4l2_audio *p = arg; 1350 struct v4l2_audio *p = arg;
1381 __u32 index = p->index;
1382 1351
1383 if (!ops->vidioc_g_audio) 1352 if (!ops->vidioc_g_audio)
1384 break; 1353 break;
1385 1354
1386 memset(p, 0, sizeof(*p));
1387 p->index = index;
1388 ret = ops->vidioc_g_audio(file, fh, p); 1355 ret = ops->vidioc_g_audio(file, fh, p);
1389 if (!ret) 1356 if (!ret)
1390 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, " 1357 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
@@ -1426,7 +1393,7 @@ static long __video_do_ioctl(struct file *file,
1426 1393
1427 if (!ops->vidioc_g_audout) 1394 if (!ops->vidioc_g_audout)
1428 break; 1395 break;
1429 dbgarg(cmd, "Enum for index=%d\n", p->index); 1396
1430 ret = ops->vidioc_g_audout(file, fh, p); 1397 ret = ops->vidioc_g_audout(file, fh, p);
1431 if (!ret) 1398 if (!ret)
1432 dbgarg2("index=%d, name=%s, capability=%d, " 1399 dbgarg2("index=%d, name=%s, capability=%d, "
@@ -1479,15 +1446,10 @@ static long __video_do_ioctl(struct file *file,
1479 case VIDIOC_G_CROP: 1446 case VIDIOC_G_CROP:
1480 { 1447 {
1481 struct v4l2_crop *p = arg; 1448 struct v4l2_crop *p = arg;
1482 __u32 type;
1483 1449
1484 if (!ops->vidioc_g_crop) 1450 if (!ops->vidioc_g_crop)
1485 break; 1451 break;
1486 1452
1487 type = p->type;
1488 memset(p, 0, sizeof(*p));
1489 p->type = type;
1490
1491 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names)); 1453 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1492 ret = ops->vidioc_g_crop(file, fh, p); 1454 ret = ops->vidioc_g_crop(file, fh, p);
1493 if (!ret) 1455 if (!ret)
@@ -1508,16 +1470,11 @@ static long __video_do_ioctl(struct file *file,
1508 case VIDIOC_CROPCAP: 1470 case VIDIOC_CROPCAP:
1509 { 1471 {
1510 struct v4l2_cropcap *p = arg; 1472 struct v4l2_cropcap *p = arg;
1511 __u32 type;
1512 1473
1513 /*FIXME: Should also show v4l2_fract pixelaspect */ 1474 /*FIXME: Should also show v4l2_fract pixelaspect */
1514 if (!ops->vidioc_cropcap) 1475 if (!ops->vidioc_cropcap)
1515 break; 1476 break;
1516 1477
1517 type = p->type;
1518 memset(p, 0, sizeof(*p));
1519 p->type = type;
1520
1521 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names)); 1478 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1522 ret = ops->vidioc_cropcap(file, fh, p); 1479 ret = ops->vidioc_cropcap(file, fh, p);
1523 if (!ret) { 1480 if (!ret) {
@@ -1533,8 +1490,6 @@ static long __video_do_ioctl(struct file *file,
1533 if (!ops->vidioc_g_jpegcomp) 1490 if (!ops->vidioc_g_jpegcomp)
1534 break; 1491 break;
1535 1492
1536 memset(p, 0, sizeof(*p));
1537
1538 ret = ops->vidioc_g_jpegcomp(file, fh, p); 1493 ret = ops->vidioc_g_jpegcomp(file, fh, p);
1539 if (!ret) 1494 if (!ret)
1540 dbgarg(cmd, "quality=%d, APPn=%d, " 1495 dbgarg(cmd, "quality=%d, APPn=%d, "
@@ -1575,7 +1530,6 @@ static long __video_do_ioctl(struct file *file,
1575 1530
1576 if (!ops->vidioc_encoder_cmd) 1531 if (!ops->vidioc_encoder_cmd)
1577 break; 1532 break;
1578 memset(&p->raw, 0, sizeof(p->raw));
1579 ret = ops->vidioc_encoder_cmd(file, fh, p); 1533 ret = ops->vidioc_encoder_cmd(file, fh, p);
1580 if (!ret) 1534 if (!ret)
1581 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags); 1535 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
@@ -1587,7 +1541,6 @@ static long __video_do_ioctl(struct file *file,
1587 1541
1588 if (!ops->vidioc_try_encoder_cmd) 1542 if (!ops->vidioc_try_encoder_cmd)
1589 break; 1543 break;
1590 memset(&p->raw, 0, sizeof(p->raw));
1591 ret = ops->vidioc_try_encoder_cmd(file, fh, p); 1544 ret = ops->vidioc_try_encoder_cmd(file, fh, p);
1592 if (!ret) 1545 if (!ret)
1593 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags); 1546 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
@@ -1596,23 +1549,18 @@ static long __video_do_ioctl(struct file *file,
1596 case VIDIOC_G_PARM: 1549 case VIDIOC_G_PARM:
1597 { 1550 {
1598 struct v4l2_streamparm *p = arg; 1551 struct v4l2_streamparm *p = arg;
1599 __u32 type = p->type;
1600
1601 memset(p, 0, sizeof(*p));
1602 p->type = type;
1603 1552
1604 if (ops->vidioc_g_parm) { 1553 if (ops->vidioc_g_parm) {
1554 ret = check_fmt(ops, p->type);
1555 if (ret)
1556 break;
1605 ret = ops->vidioc_g_parm(file, fh, p); 1557 ret = ops->vidioc_g_parm(file, fh, p);
1606 } else { 1558 } else {
1607 struct v4l2_standard s;
1608
1609 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 1559 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1610 return -EINVAL; 1560 return -EINVAL;
1611 1561
1612 v4l2_video_std_construct(&s, vfd->current_norm, 1562 v4l2_video_std_frame_period(vfd->current_norm,
1613 v4l2_norm_to_name(vfd->current_norm)); 1563 &p->parm.capture.timeperframe);
1614
1615 p->parm.capture.timeperframe = s.frameperiod;
1616 ret = 0; 1564 ret = 0;
1617 } 1565 }
1618 1566
@@ -1625,6 +1573,10 @@ static long __video_do_ioctl(struct file *file,
1625 1573
1626 if (!ops->vidioc_s_parm) 1574 if (!ops->vidioc_s_parm)
1627 break; 1575 break;
1576 ret = check_fmt(ops, p->type);
1577 if (ret)
1578 break;
1579
1628 dbgarg(cmd, "type=%d\n", p->type); 1580 dbgarg(cmd, "type=%d\n", p->type);
1629 ret = ops->vidioc_s_parm(file, fh, p); 1581 ret = ops->vidioc_s_parm(file, fh, p);
1630 break; 1582 break;
@@ -1632,14 +1584,10 @@ static long __video_do_ioctl(struct file *file,
1632 case VIDIOC_G_TUNER: 1584 case VIDIOC_G_TUNER:
1633 { 1585 {
1634 struct v4l2_tuner *p = arg; 1586 struct v4l2_tuner *p = arg;
1635 __u32 index = p->index;
1636 1587
1637 if (!ops->vidioc_g_tuner) 1588 if (!ops->vidioc_g_tuner)
1638 break; 1589 break;
1639 1590
1640 memset(p, 0, sizeof(*p));
1641 p->index = index;
1642
1643 ret = ops->vidioc_g_tuner(file, fh, p); 1591 ret = ops->vidioc_g_tuner(file, fh, p);
1644 if (!ret) 1592 if (!ret)
1645 dbgarg(cmd, "index=%d, name=%s, type=%d, " 1593 dbgarg(cmd, "index=%d, name=%s, type=%d, "
@@ -1676,8 +1624,6 @@ static long __video_do_ioctl(struct file *file,
1676 if (!ops->vidioc_g_frequency) 1624 if (!ops->vidioc_g_frequency)
1677 break; 1625 break;
1678 1626
1679 memset(p->reserved, 0, sizeof(p->reserved));
1680
1681 ret = ops->vidioc_g_frequency(file, fh, p); 1627 ret = ops->vidioc_g_frequency(file, fh, p);
1682 if (!ret) 1628 if (!ret)
1683 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n", 1629 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
@@ -1698,12 +1644,13 @@ static long __video_do_ioctl(struct file *file,
1698 case VIDIOC_G_SLICED_VBI_CAP: 1644 case VIDIOC_G_SLICED_VBI_CAP:
1699 { 1645 {
1700 struct v4l2_sliced_vbi_cap *p = arg; 1646 struct v4l2_sliced_vbi_cap *p = arg;
1701 __u32 type = p->type;
1702 1647
1703 if (!ops->vidioc_g_sliced_vbi_cap) 1648 if (!ops->vidioc_g_sliced_vbi_cap)
1704 break; 1649 break;
1705 memset(p, 0, sizeof(*p)); 1650
1706 p->type = type; 1651 /* Clear up to type, everything after type is zerod already */
1652 memset(p, 0, offsetof(struct v4l2_sliced_vbi_cap, type));
1653
1707 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names)); 1654 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1708 ret = ops->vidioc_g_sliced_vbi_cap(file, fh, p); 1655 ret = ops->vidioc_g_sliced_vbi_cap(file, fh, p);
1709 if (!ret) 1656 if (!ret)
@@ -1745,16 +1692,13 @@ static long __video_do_ioctl(struct file *file,
1745 1692
1746 if (!ops->vidioc_g_chip_ident) 1693 if (!ops->vidioc_g_chip_ident)
1747 break; 1694 break;
1695 p->ident = V4L2_IDENT_NONE;
1696 p->revision = 0;
1748 ret = ops->vidioc_g_chip_ident(file, fh, p); 1697 ret = ops->vidioc_g_chip_ident(file, fh, p);
1749 if (!ret) 1698 if (!ret)
1750 dbgarg(cmd, "chip_ident=%u, revision=0x%x\n", p->ident, p->revision); 1699 dbgarg(cmd, "chip_ident=%u, revision=0x%x\n", p->ident, p->revision);
1751 break; 1700 break;
1752 } 1701 }
1753 case VIDIOC_G_CHIP_IDENT_OLD:
1754 printk(KERN_ERR "VIDIOC_G_CHIP_IDENT has been deprecated and will disappear in 2.6.30.\n");
1755 printk(KERN_ERR "It is a debugging ioctl and must not be used in applications!\n");
1756 return -EINVAL;
1757
1758 case VIDIOC_S_HW_FREQ_SEEK: 1702 case VIDIOC_S_HW_FREQ_SEEK:
1759 { 1703 {
1760 struct v4l2_hw_freq_seek *p = arg; 1704 struct v4l2_hw_freq_seek *p = arg;
@@ -1774,8 +1718,6 @@ static long __video_do_ioctl(struct file *file,
1774 if (!ops->vidioc_enum_framesizes) 1718 if (!ops->vidioc_enum_framesizes)
1775 break; 1719 break;
1776 1720
1777 memset(p, 0, sizeof(*p));
1778
1779 ret = ops->vidioc_enum_framesizes(file, fh, p); 1721 ret = ops->vidioc_enum_framesizes(file, fh, p);
1780 dbgarg(cmd, 1722 dbgarg(cmd,
1781 "index=%d, pixelformat=%d, type=%d ", 1723 "index=%d, pixelformat=%d, type=%d ",
@@ -1807,8 +1749,6 @@ static long __video_do_ioctl(struct file *file,
1807 if (!ops->vidioc_enum_frameintervals) 1749 if (!ops->vidioc_enum_frameintervals)
1808 break; 1750 break;
1809 1751
1810 memset(p, 0, sizeof(*p));
1811
1812 ret = ops->vidioc_enum_frameintervals(file, fh, p); 1752 ret = ops->vidioc_enum_frameintervals(file, fh, p);
1813 dbgarg(cmd, 1753 dbgarg(cmd,
1814 "index=%d, pixelformat=%d, width=%d, height=%d, type=%d ", 1754 "index=%d, pixelformat=%d, width=%d, height=%d, type=%d ",
@@ -1857,6 +1797,45 @@ static long __video_do_ioctl(struct file *file,
1857 return ret; 1797 return ret;
1858} 1798}
1859 1799
1800/* In some cases, only a few fields are used as input, i.e. when the app sets
1801 * "index" and then the driver fills in the rest of the structure for the thing
1802 * with that index. We only need to copy up the first non-input field. */
1803static unsigned long cmd_input_size(unsigned int cmd)
1804{
1805 /* Size of structure up to and including 'field' */
1806#define CMDINSIZE(cmd, type, field) \
1807 case VIDIOC_##cmd: \
1808 return offsetof(struct v4l2_##type, field) + \
1809 sizeof(((struct v4l2_##type *)0)->field);
1810
1811 switch (cmd) {
1812 CMDINSIZE(ENUM_FMT, fmtdesc, type);
1813 CMDINSIZE(G_FMT, format, type);
1814 CMDINSIZE(QUERYBUF, buffer, type);
1815 CMDINSIZE(G_PARM, streamparm, type);
1816 CMDINSIZE(ENUMSTD, standard, index);
1817 CMDINSIZE(ENUMINPUT, input, index);
1818 CMDINSIZE(G_CTRL, control, id);
1819 CMDINSIZE(G_TUNER, tuner, index);
1820 CMDINSIZE(QUERYCTRL, queryctrl, id);
1821 CMDINSIZE(QUERYMENU, querymenu, index);
1822 CMDINSIZE(ENUMOUTPUT, output, index);
1823 CMDINSIZE(G_MODULATOR, modulator, index);
1824 CMDINSIZE(G_FREQUENCY, frequency, tuner);
1825 CMDINSIZE(CROPCAP, cropcap, type);
1826 CMDINSIZE(G_CROP, crop, type);
1827 CMDINSIZE(ENUMAUDIO, audio, index);
1828 CMDINSIZE(ENUMAUDOUT, audioout, index);
1829 CMDINSIZE(ENCODER_CMD, encoder_cmd, flags);
1830 CMDINSIZE(TRY_ENCODER_CMD, encoder_cmd, flags);
1831 CMDINSIZE(G_SLICED_VBI_CAP, sliced_vbi_cap, type);
1832 CMDINSIZE(ENUM_FRAMESIZES, frmsizeenum, pixel_format);
1833 CMDINSIZE(ENUM_FRAMEINTERVALS, frmivalenum, height);
1834 default:
1835 return _IOC_SIZE(cmd);
1836 }
1837}
1838
1860long video_ioctl2(struct file *file, 1839long video_ioctl2(struct file *file,
1861 unsigned int cmd, unsigned long arg) 1840 unsigned int cmd, unsigned long arg)
1862{ 1841{
@@ -1875,13 +1854,7 @@ long video_ioctl2(struct file *file,
1875 cmd == VIDIOC_TRY_EXT_CTRLS); 1854 cmd == VIDIOC_TRY_EXT_CTRLS);
1876 1855
1877 /* Copy arguments into temp kernel buffer */ 1856 /* Copy arguments into temp kernel buffer */
1878 switch (_IOC_DIR(cmd)) { 1857 if (_IOC_DIR(cmd) != _IOC_NONE) {
1879 case _IOC_NONE:
1880 parg = NULL;
1881 break;
1882 case _IOC_READ:
1883 case _IOC_WRITE:
1884 case (_IOC_WRITE | _IOC_READ):
1885 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) { 1858 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
1886 parg = sbuf; 1859 parg = sbuf;
1887 } else { 1860 } else {
@@ -1893,10 +1866,19 @@ long video_ioctl2(struct file *file,
1893 } 1866 }
1894 1867
1895 err = -EFAULT; 1868 err = -EFAULT;
1896 if (_IOC_DIR(cmd) & _IOC_WRITE) 1869 if (_IOC_DIR(cmd) & _IOC_WRITE) {
1897 if (copy_from_user(parg, (void __user *)arg, _IOC_SIZE(cmd))) 1870 unsigned long n = cmd_input_size(cmd);
1871
1872 if (copy_from_user(parg, (void __user *)arg, n))
1898 goto out; 1873 goto out;
1899 break; 1874
1875 /* zero out anything we don't copy from userspace */
1876 if (n < _IOC_SIZE(cmd))
1877 memset((u8 *)parg + n, 0, _IOC_SIZE(cmd) - n);
1878 } else {
1879 /* read-only ioctl */
1880 memset(parg, 0, _IOC_SIZE(cmd));
1881 }
1900 } 1882 }
1901 1883
1902 if (is_ext_ctrl) { 1884 if (is_ext_ctrl) {
diff --git a/drivers/media/video/v4l2-subdev.c b/drivers/media/video/v4l2-subdev.c
index 21208805ea9b..dc881671d536 100644
--- a/drivers/media/video/v4l2-subdev.c
+++ b/drivers/media/video/v4l2-subdev.c
@@ -33,6 +33,12 @@ int v4l2_subdev_command(struct v4l2_subdev *sd, unsigned cmd, void *arg)
33 return v4l2_subdev_call(sd, core, g_ctrl, arg); 33 return v4l2_subdev_call(sd, core, g_ctrl, arg);
34 case VIDIOC_S_CTRL: 34 case VIDIOC_S_CTRL:
35 return v4l2_subdev_call(sd, core, s_ctrl, arg); 35 return v4l2_subdev_call(sd, core, s_ctrl, arg);
36 case VIDIOC_G_EXT_CTRLS:
37 return v4l2_subdev_call(sd, core, g_ext_ctrls, arg);
38 case VIDIOC_S_EXT_CTRLS:
39 return v4l2_subdev_call(sd, core, s_ext_ctrls, arg);
40 case VIDIOC_TRY_EXT_CTRLS:
41 return v4l2_subdev_call(sd, core, try_ext_ctrls, arg);
36 case VIDIOC_QUERYMENU: 42 case VIDIOC_QUERYMENU:
37 return v4l2_subdev_call(sd, core, querymenu, arg); 43 return v4l2_subdev_call(sd, core, querymenu, arg);
38 case VIDIOC_LOG_STATUS: 44 case VIDIOC_LOG_STATUS:
@@ -92,16 +98,28 @@ int v4l2_subdev_command(struct v4l2_subdev *sd, unsigned cmd, void *arg)
92 return v4l2_subdev_call(sd, video, g_vbi_data, arg); 98 return v4l2_subdev_call(sd, video, g_vbi_data, arg);
93 case VIDIOC_G_SLICED_VBI_CAP: 99 case VIDIOC_G_SLICED_VBI_CAP:
94 return v4l2_subdev_call(sd, video, g_sliced_vbi_cap, arg); 100 return v4l2_subdev_call(sd, video, g_sliced_vbi_cap, arg);
101 case VIDIOC_ENUM_FMT:
102 return v4l2_subdev_call(sd, video, enum_fmt, arg);
103 case VIDIOC_TRY_FMT:
104 return v4l2_subdev_call(sd, video, try_fmt, arg);
95 case VIDIOC_S_FMT: 105 case VIDIOC_S_FMT:
96 return v4l2_subdev_call(sd, video, s_fmt, arg); 106 return v4l2_subdev_call(sd, video, s_fmt, arg);
97 case VIDIOC_G_FMT: 107 case VIDIOC_G_FMT:
98 return v4l2_subdev_call(sd, video, g_fmt, arg); 108 return v4l2_subdev_call(sd, video, g_fmt, arg);
99 case VIDIOC_INT_S_STD_OUTPUT: 109 case VIDIOC_INT_S_STD_OUTPUT:
100 return v4l2_subdev_call(sd, video, s_std_output, *(v4l2_std_id *)arg); 110 return v4l2_subdev_call(sd, video, s_std_output, *(v4l2_std_id *)arg);
111 case VIDIOC_QUERYSTD:
112 return v4l2_subdev_call(sd, video, querystd, arg);
113 case VIDIOC_INT_G_INPUT_STATUS:
114 return v4l2_subdev_call(sd, video, g_input_status, arg);
101 case VIDIOC_STREAMON: 115 case VIDIOC_STREAMON:
102 return v4l2_subdev_call(sd, video, s_stream, 1); 116 return v4l2_subdev_call(sd, video, s_stream, 1);
103 case VIDIOC_STREAMOFF: 117 case VIDIOC_STREAMOFF:
104 return v4l2_subdev_call(sd, video, s_stream, 0); 118 return v4l2_subdev_call(sd, video, s_stream, 0);
119 case VIDIOC_S_PARM:
120 return v4l2_subdev_call(sd, video, s_parm, arg);
121 case VIDIOC_G_PARM:
122 return v4l2_subdev_call(sd, video, g_parm, arg);
105 123
106 default: 124 default:
107 return v4l2_subdev_call(sd, core, ioctl, cmd, arg); 125 return v4l2_subdev_call(sd, core, ioctl, cmd, arg);
diff --git a/drivers/media/video/videobuf-dma-contig.c b/drivers/media/video/videobuf-dma-contig.c
index 31944b11e6ea..6109fb5f34e2 100644
--- a/drivers/media/video/videobuf-dma-contig.c
+++ b/drivers/media/video/videobuf-dma-contig.c
@@ -400,7 +400,7 @@ void videobuf_dma_contig_free(struct videobuf_queue *q,
400 So, it should free memory only if the memory were allocated for 400 So, it should free memory only if the memory were allocated for
401 read() operation. 401 read() operation.
402 */ 402 */
403 if ((buf->memory != V4L2_MEMORY_USERPTR) || !buf->baddr) 403 if ((buf->memory != V4L2_MEMORY_USERPTR) || buf->baddr)
404 return; 404 return;
405 405
406 if (!mem) 406 if (!mem)
diff --git a/drivers/media/video/videobuf-vmalloc.c b/drivers/media/video/videobuf-vmalloc.c
index be65a2fb3976..30ae30f99ccc 100644
--- a/drivers/media/video/videobuf-vmalloc.c
+++ b/drivers/media/video/videobuf-vmalloc.c
@@ -425,7 +425,7 @@ void videobuf_vmalloc_free (struct videobuf_buffer *buf)
425 So, it should free memory only if the memory were allocated for 425 So, it should free memory only if the memory were allocated for
426 read() operation. 426 read() operation.
427 */ 427 */
428 if ((buf->memory != V4L2_MEMORY_USERPTR) || (buf->baddr == 0)) 428 if ((buf->memory != V4L2_MEMORY_USERPTR) || buf->baddr)
429 return; 429 return;
430 430
431 if (!mem) 431 if (!mem)
diff --git a/drivers/media/video/vino.c b/drivers/media/video/vino.c
index 88bf845a3d56..8da4dd1e0e94 100644
--- a/drivers/media/video/vino.c
+++ b/drivers/media/video/vino.c
@@ -8,6 +8,12 @@
8 * 8 *
9 * Based on the previous version of the driver for 2.4 kernels by: 9 * Based on the previous version of the driver for 2.4 kernels by:
10 * Copyright (C) 2003 Ladislav Michl <ladis@linux-mips.org> 10 * Copyright (C) 2003 Ladislav Michl <ladis@linux-mips.org>
11 *
12 * v4l2_device/v4l2_subdev conversion by:
13 * Copyright (C) 2009 Hans Verkuil <hverkuil@xs4all.nl>
14 *
15 * Note: this conversion is untested! Please contact the linux-media
16 * mailinglist if you can test this, together with the test results.
11 */ 17 */
12 18
13/* 19/*
@@ -33,12 +39,10 @@
33#include <linux/kmod.h> 39#include <linux/kmod.h>
34 40
35#include <linux/i2c.h> 41#include <linux/i2c.h>
36#include <linux/i2c-algo-sgi.h>
37 42
38#include <linux/videodev2.h> 43#include <linux/videodev2.h>
39#include <media/v4l2-common.h> 44#include <media/v4l2-device.h>
40#include <media/v4l2-ioctl.h> 45#include <media/v4l2-ioctl.h>
41#include <linux/video_decoder.h>
42#include <linux/mutex.h> 46#include <linux/mutex.h>
43 47
44#include <asm/paccess.h> 48#include <asm/paccess.h>
@@ -139,13 +143,23 @@ MODULE_LICENSE("GPL");
139#define VINO_DATA_NORM_PAL 1 143#define VINO_DATA_NORM_PAL 1
140#define VINO_DATA_NORM_SECAM 2 144#define VINO_DATA_NORM_SECAM 2
141#define VINO_DATA_NORM_D1 3 145#define VINO_DATA_NORM_D1 3
142/* The following are special entries that can be used to
143 * autodetect the norm. */
144#define VINO_DATA_NORM_AUTO 0xfe
145#define VINO_DATA_NORM_AUTO_EXT 0xff
146 146
147#define VINO_DATA_NORM_COUNT 4 147#define VINO_DATA_NORM_COUNT 4
148 148
149/* I2C controller flags */
150#define SGI_I2C_FORCE_IDLE (0 << 0)
151#define SGI_I2C_NOT_IDLE (1 << 0)
152#define SGI_I2C_WRITE (0 << 1)
153#define SGI_I2C_READ (1 << 1)
154#define SGI_I2C_RELEASE_BUS (0 << 2)
155#define SGI_I2C_HOLD_BUS (1 << 2)
156#define SGI_I2C_XFER_DONE (0 << 4)
157#define SGI_I2C_XFER_BUSY (1 << 4)
158#define SGI_I2C_ACK (0 << 5)
159#define SGI_I2C_NACK (1 << 5)
160#define SGI_I2C_BUS_OK (0 << 7)
161#define SGI_I2C_BUS_ERR (1 << 7)
162
149/* Internal data structure definitions */ 163/* Internal data structure definitions */
150 164
151struct vino_input { 165struct vino_input {
@@ -289,22 +303,20 @@ struct vino_channel_settings {
289 struct vino_interrupt_data int_data; 303 struct vino_interrupt_data int_data;
290 304
291 /* V4L support */ 305 /* V4L support */
292 struct video_device *v4l_device; 306 struct video_device *vdev;
293};
294
295struct vino_client {
296 /* the channel which owns this client:
297 * VINO_NO_CHANNEL, VINO_CHANNEL_A or VINO_CHANNEL_B */
298 unsigned int owner;
299 struct i2c_client *driver;
300}; 307};
301 308
302struct vino_settings { 309struct vino_settings {
310 struct v4l2_device v4l2_dev;
303 struct vino_channel_settings a; 311 struct vino_channel_settings a;
304 struct vino_channel_settings b; 312 struct vino_channel_settings b;
305 313
306 struct vino_client decoder; 314 /* the channel which owns this client:
307 struct vino_client camera; 315 * VINO_NO_CHANNEL, VINO_CHANNEL_A or VINO_CHANNEL_B */
316 unsigned int decoder_owner;
317 struct v4l2_subdev *decoder;
318 unsigned int camera_owner;
319 struct v4l2_subdev *camera;
308 320
309 /* a lock for vino register access */ 321 /* a lock for vino register access */
310 spinlock_t vino_lock; 322 spinlock_t vino_lock;
@@ -344,11 +356,16 @@ static struct sgi_vino *vino;
344 356
345static struct vino_settings *vino_drvdata; 357static struct vino_settings *vino_drvdata;
346 358
359#define camera_call(o, f, args...) \
360 v4l2_subdev_call(vino_drvdata->camera, o, f, ##args)
361#define decoder_call(o, f, args...) \
362 v4l2_subdev_call(vino_drvdata->decoder, o, f, ##args)
363
347static const char *vino_driver_name = "vino"; 364static const char *vino_driver_name = "vino";
348static const char *vino_driver_description = "SGI VINO"; 365static const char *vino_driver_description = "SGI VINO";
349static const char *vino_bus_name = "GIO64 bus"; 366static const char *vino_bus_name = "GIO64 bus";
350static const char *vino_v4l_device_name_a = "SGI VINO Channel A"; 367static const char *vino_vdev_name_a = "SGI VINO Channel A";
351static const char *vino_v4l_device_name_b = "SGI VINO Channel B"; 368static const char *vino_vdev_name_b = "SGI VINO Channel B";
352 369
353static void vino_capture_tasklet(unsigned long channel); 370static void vino_capture_tasklet(unsigned long channel);
354 371
@@ -360,11 +377,11 @@ static const struct vino_input vino_inputs[] = {
360 .name = "Composite", 377 .name = "Composite",
361 .std = V4L2_STD_NTSC | V4L2_STD_PAL 378 .std = V4L2_STD_NTSC | V4L2_STD_PAL
362 | V4L2_STD_SECAM, 379 | V4L2_STD_SECAM,
363 },{ 380 }, {
364 .name = "S-Video", 381 .name = "S-Video",
365 .std = V4L2_STD_NTSC | V4L2_STD_PAL 382 .std = V4L2_STD_NTSC | V4L2_STD_PAL
366 | V4L2_STD_SECAM, 383 | V4L2_STD_SECAM,
367 },{ 384 }, {
368 .name = "D1/IndyCam", 385 .name = "D1/IndyCam",
369 .std = V4L2_STD_NTSC, 386 .std = V4L2_STD_NTSC,
370 } 387 }
@@ -376,17 +393,17 @@ static const struct vino_data_format vino_data_formats[] = {
376 .bpp = 1, 393 .bpp = 1,
377 .pixelformat = V4L2_PIX_FMT_GREY, 394 .pixelformat = V4L2_PIX_FMT_GREY,
378 .colorspace = V4L2_COLORSPACE_SMPTE170M, 395 .colorspace = V4L2_COLORSPACE_SMPTE170M,
379 },{ 396 }, {
380 .description = "8-bit dithered RGB 3-3-2", 397 .description = "8-bit dithered RGB 3-3-2",
381 .bpp = 1, 398 .bpp = 1,
382 .pixelformat = V4L2_PIX_FMT_RGB332, 399 .pixelformat = V4L2_PIX_FMT_RGB332,
383 .colorspace = V4L2_COLORSPACE_SRGB, 400 .colorspace = V4L2_COLORSPACE_SRGB,
384 },{ 401 }, {
385 .description = "32-bit RGB", 402 .description = "32-bit RGB",
386 .bpp = 4, 403 .bpp = 4,
387 .pixelformat = V4L2_PIX_FMT_RGB32, 404 .pixelformat = V4L2_PIX_FMT_RGB32,
388 .colorspace = V4L2_COLORSPACE_SRGB, 405 .colorspace = V4L2_COLORSPACE_SRGB,
389 },{ 406 }, {
390 .description = "YUV 4:2:2", 407 .description = "YUV 4:2:2",
391 .bpp = 2, 408 .bpp = 2,
392 .pixelformat = V4L2_PIX_FMT_YUYV, // XXX: swapped? 409 .pixelformat = V4L2_PIX_FMT_YUYV, // XXX: swapped?
@@ -417,7 +434,7 @@ static const struct vino_data_norm vino_data_norms[] = {
417 + VINO_NTSC_HEIGHT / 2 - 1, 434 + VINO_NTSC_HEIGHT / 2 - 1,
418 .right = VINO_NTSC_WIDTH, 435 .right = VINO_NTSC_WIDTH,
419 }, 436 },
420 },{ 437 }, {
421 .description = "PAL", 438 .description = "PAL",
422 .std = V4L2_STD_PAL, 439 .std = V4L2_STD_PAL,
423 .fps_min = 5, 440 .fps_min = 5,
@@ -439,7 +456,7 @@ static const struct vino_data_norm vino_data_norms[] = {
439 + VINO_PAL_HEIGHT / 2 - 1, 456 + VINO_PAL_HEIGHT / 2 - 1,
440 .right = VINO_PAL_WIDTH, 457 .right = VINO_PAL_WIDTH,
441 }, 458 },
442 },{ 459 }, {
443 .description = "SECAM", 460 .description = "SECAM",
444 .std = V4L2_STD_SECAM, 461 .std = V4L2_STD_SECAM,
445 .fps_min = 5, 462 .fps_min = 5,
@@ -461,7 +478,7 @@ static const struct vino_data_norm vino_data_norms[] = {
461 + VINO_PAL_HEIGHT / 2 - 1, 478 + VINO_PAL_HEIGHT / 2 - 1,
462 .right = VINO_PAL_WIDTH, 479 .right = VINO_PAL_WIDTH,
463 }, 480 },
464 },{ 481 }, {
465 .description = "NTSC/D1", 482 .description = "NTSC/D1",
466 .std = V4L2_STD_NTSC, 483 .std = V4L2_STD_NTSC,
467 .fps_min = 6, 484 .fps_min = 6,
@@ -497,9 +514,7 @@ struct v4l2_queryctrl vino_indycam_v4l2_controls[] = {
497 .maximum = 1, 514 .maximum = 1,
498 .step = 1, 515 .step = 1,
499 .default_value = INDYCAM_AGC_DEFAULT, 516 .default_value = INDYCAM_AGC_DEFAULT,
500 .flags = 0, 517 }, {
501 .reserved = { INDYCAM_CONTROL_AGC, 0 },
502 },{
503 .id = V4L2_CID_AUTO_WHITE_BALANCE, 518 .id = V4L2_CID_AUTO_WHITE_BALANCE,
504 .type = V4L2_CTRL_TYPE_BOOLEAN, 519 .type = V4L2_CTRL_TYPE_BOOLEAN,
505 .name = "Automatic White Balance", 520 .name = "Automatic White Balance",
@@ -507,9 +522,7 @@ struct v4l2_queryctrl vino_indycam_v4l2_controls[] = {
507 .maximum = 1, 522 .maximum = 1,
508 .step = 1, 523 .step = 1,
509 .default_value = INDYCAM_AWB_DEFAULT, 524 .default_value = INDYCAM_AWB_DEFAULT,
510 .flags = 0, 525 }, {
511 .reserved = { INDYCAM_CONTROL_AWB, 0 },
512 },{
513 .id = V4L2_CID_GAIN, 526 .id = V4L2_CID_GAIN,
514 .type = V4L2_CTRL_TYPE_INTEGER, 527 .type = V4L2_CTRL_TYPE_INTEGER,
515 .name = "Gain", 528 .name = "Gain",
@@ -517,29 +530,23 @@ struct v4l2_queryctrl vino_indycam_v4l2_controls[] = {
517 .maximum = INDYCAM_GAIN_MAX, 530 .maximum = INDYCAM_GAIN_MAX,
518 .step = 1, 531 .step = 1,
519 .default_value = INDYCAM_GAIN_DEFAULT, 532 .default_value = INDYCAM_GAIN_DEFAULT,
520 .flags = 0, 533 }, {
521 .reserved = { INDYCAM_CONTROL_GAIN, 0 }, 534 .id = INDYCAM_CONTROL_RED_SATURATION,
522 },{
523 .id = V4L2_CID_PRIVATE_BASE,
524 .type = V4L2_CTRL_TYPE_INTEGER, 535 .type = V4L2_CTRL_TYPE_INTEGER,
525 .name = "Red Saturation", 536 .name = "Red Saturation",
526 .minimum = INDYCAM_RED_SATURATION_MIN, 537 .minimum = INDYCAM_RED_SATURATION_MIN,
527 .maximum = INDYCAM_RED_SATURATION_MAX, 538 .maximum = INDYCAM_RED_SATURATION_MAX,
528 .step = 1, 539 .step = 1,
529 .default_value = INDYCAM_RED_SATURATION_DEFAULT, 540 .default_value = INDYCAM_RED_SATURATION_DEFAULT,
530 .flags = 0, 541 }, {
531 .reserved = { INDYCAM_CONTROL_RED_SATURATION, 0 }, 542 .id = INDYCAM_CONTROL_BLUE_SATURATION,
532 },{
533 .id = V4L2_CID_PRIVATE_BASE + 1,
534 .type = V4L2_CTRL_TYPE_INTEGER, 543 .type = V4L2_CTRL_TYPE_INTEGER,
535 .name = "Blue Saturation", 544 .name = "Blue Saturation",
536 .minimum = INDYCAM_BLUE_SATURATION_MIN, 545 .minimum = INDYCAM_BLUE_SATURATION_MIN,
537 .maximum = INDYCAM_BLUE_SATURATION_MAX, 546 .maximum = INDYCAM_BLUE_SATURATION_MAX,
538 .step = 1, 547 .step = 1,
539 .default_value = INDYCAM_BLUE_SATURATION_DEFAULT, 548 .default_value = INDYCAM_BLUE_SATURATION_DEFAULT,
540 .flags = 0, 549 }, {
541 .reserved = { INDYCAM_CONTROL_BLUE_SATURATION, 0 },
542 },{
543 .id = V4L2_CID_RED_BALANCE, 550 .id = V4L2_CID_RED_BALANCE,
544 .type = V4L2_CTRL_TYPE_INTEGER, 551 .type = V4L2_CTRL_TYPE_INTEGER,
545 .name = "Red Balance", 552 .name = "Red Balance",
@@ -547,9 +554,7 @@ struct v4l2_queryctrl vino_indycam_v4l2_controls[] = {
547 .maximum = INDYCAM_RED_BALANCE_MAX, 554 .maximum = INDYCAM_RED_BALANCE_MAX,
548 .step = 1, 555 .step = 1,
549 .default_value = INDYCAM_RED_BALANCE_DEFAULT, 556 .default_value = INDYCAM_RED_BALANCE_DEFAULT,
550 .flags = 0, 557 }, {
551 .reserved = { INDYCAM_CONTROL_RED_BALANCE, 0 },
552 },{
553 .id = V4L2_CID_BLUE_BALANCE, 558 .id = V4L2_CID_BLUE_BALANCE,
554 .type = V4L2_CTRL_TYPE_INTEGER, 559 .type = V4L2_CTRL_TYPE_INTEGER,
555 .name = "Blue Balance", 560 .name = "Blue Balance",
@@ -557,9 +562,7 @@ struct v4l2_queryctrl vino_indycam_v4l2_controls[] = {
557 .maximum = INDYCAM_BLUE_BALANCE_MAX, 562 .maximum = INDYCAM_BLUE_BALANCE_MAX,
558 .step = 1, 563 .step = 1,
559 .default_value = INDYCAM_BLUE_BALANCE_DEFAULT, 564 .default_value = INDYCAM_BLUE_BALANCE_DEFAULT,
560 .flags = 0, 565 }, {
561 .reserved = { INDYCAM_CONTROL_BLUE_BALANCE, 0 },
562 },{
563 .id = V4L2_CID_EXPOSURE, 566 .id = V4L2_CID_EXPOSURE,
564 .type = V4L2_CTRL_TYPE_INTEGER, 567 .type = V4L2_CTRL_TYPE_INTEGER,
565 .name = "Shutter Control", 568 .name = "Shutter Control",
@@ -567,9 +570,7 @@ struct v4l2_queryctrl vino_indycam_v4l2_controls[] = {
567 .maximum = INDYCAM_SHUTTER_MAX, 570 .maximum = INDYCAM_SHUTTER_MAX,
568 .step = 1, 571 .step = 1,
569 .default_value = INDYCAM_SHUTTER_DEFAULT, 572 .default_value = INDYCAM_SHUTTER_DEFAULT,
570 .flags = 0, 573 }, {
571 .reserved = { INDYCAM_CONTROL_SHUTTER, 0 },
572 },{
573 .id = V4L2_CID_GAMMA, 574 .id = V4L2_CID_GAMMA,
574 .type = V4L2_CTRL_TYPE_INTEGER, 575 .type = V4L2_CTRL_TYPE_INTEGER,
575 .name = "Gamma", 576 .name = "Gamma",
@@ -577,8 +578,6 @@ struct v4l2_queryctrl vino_indycam_v4l2_controls[] = {
577 .maximum = INDYCAM_GAMMA_MAX, 578 .maximum = INDYCAM_GAMMA_MAX,
578 .step = 1, 579 .step = 1,
579 .default_value = INDYCAM_GAMMA_DEFAULT, 580 .default_value = INDYCAM_GAMMA_DEFAULT,
580 .flags = 0,
581 .reserved = { INDYCAM_CONTROL_GAMMA, 0 },
582 } 581 }
583}; 582};
584 583
@@ -593,209 +592,73 @@ struct v4l2_queryctrl vino_saa7191_v4l2_controls[] = {
593 .maximum = SAA7191_HUE_MAX, 592 .maximum = SAA7191_HUE_MAX,
594 .step = 1, 593 .step = 1,
595 .default_value = SAA7191_HUE_DEFAULT, 594 .default_value = SAA7191_HUE_DEFAULT,
596 .flags = 0, 595 }, {
597 .reserved = { SAA7191_CONTROL_HUE, 0 }, 596 .id = SAA7191_CONTROL_BANDPASS,
598 },{
599 .id = V4L2_CID_PRIVATE_BASE,
600 .type = V4L2_CTRL_TYPE_INTEGER, 597 .type = V4L2_CTRL_TYPE_INTEGER,
601 .name = "Luminance Bandpass", 598 .name = "Luminance Bandpass",
602 .minimum = SAA7191_BANDPASS_MIN, 599 .minimum = SAA7191_BANDPASS_MIN,
603 .maximum = SAA7191_BANDPASS_MAX, 600 .maximum = SAA7191_BANDPASS_MAX,
604 .step = 1, 601 .step = 1,
605 .default_value = SAA7191_BANDPASS_DEFAULT, 602 .default_value = SAA7191_BANDPASS_DEFAULT,
606 .flags = 0, 603 }, {
607 .reserved = { SAA7191_CONTROL_BANDPASS, 0 }, 604 .id = SAA7191_CONTROL_BANDPASS_WEIGHT,
608 },{
609 .id = V4L2_CID_PRIVATE_BASE + 1,
610 .type = V4L2_CTRL_TYPE_INTEGER, 605 .type = V4L2_CTRL_TYPE_INTEGER,
611 .name = "Luminance Bandpass Weight", 606 .name = "Luminance Bandpass Weight",
612 .minimum = SAA7191_BANDPASS_WEIGHT_MIN, 607 .minimum = SAA7191_BANDPASS_WEIGHT_MIN,
613 .maximum = SAA7191_BANDPASS_WEIGHT_MAX, 608 .maximum = SAA7191_BANDPASS_WEIGHT_MAX,
614 .step = 1, 609 .step = 1,
615 .default_value = SAA7191_BANDPASS_WEIGHT_DEFAULT, 610 .default_value = SAA7191_BANDPASS_WEIGHT_DEFAULT,
616 .flags = 0, 611 }, {
617 .reserved = { SAA7191_CONTROL_BANDPASS_WEIGHT, 0 }, 612 .id = SAA7191_CONTROL_CORING,
618 },{
619 .id = V4L2_CID_PRIVATE_BASE + 2,
620 .type = V4L2_CTRL_TYPE_INTEGER, 613 .type = V4L2_CTRL_TYPE_INTEGER,
621 .name = "HF Luminance Coring", 614 .name = "HF Luminance Coring",
622 .minimum = SAA7191_CORING_MIN, 615 .minimum = SAA7191_CORING_MIN,
623 .maximum = SAA7191_CORING_MAX, 616 .maximum = SAA7191_CORING_MAX,
624 .step = 1, 617 .step = 1,
625 .default_value = SAA7191_CORING_DEFAULT, 618 .default_value = SAA7191_CORING_DEFAULT,
626 .flags = 0, 619 }, {
627 .reserved = { SAA7191_CONTROL_CORING, 0 }, 620 .id = SAA7191_CONTROL_FORCE_COLOUR,
628 },{
629 .id = V4L2_CID_PRIVATE_BASE + 3,
630 .type = V4L2_CTRL_TYPE_BOOLEAN, 621 .type = V4L2_CTRL_TYPE_BOOLEAN,
631 .name = "Force Colour", 622 .name = "Force Colour",
632 .minimum = SAA7191_FORCE_COLOUR_MIN, 623 .minimum = SAA7191_FORCE_COLOUR_MIN,
633 .maximum = SAA7191_FORCE_COLOUR_MAX, 624 .maximum = SAA7191_FORCE_COLOUR_MAX,
634 .step = 1, 625 .step = 1,
635 .default_value = SAA7191_FORCE_COLOUR_DEFAULT, 626 .default_value = SAA7191_FORCE_COLOUR_DEFAULT,
636 .flags = 0, 627 }, {
637 .reserved = { SAA7191_CONTROL_FORCE_COLOUR, 0 }, 628 .id = SAA7191_CONTROL_CHROMA_GAIN,
638 },{
639 .id = V4L2_CID_PRIVATE_BASE + 4,
640 .type = V4L2_CTRL_TYPE_INTEGER, 629 .type = V4L2_CTRL_TYPE_INTEGER,
641 .name = "Chrominance Gain Control", 630 .name = "Chrominance Gain Control",
642 .minimum = SAA7191_CHROMA_GAIN_MIN, 631 .minimum = SAA7191_CHROMA_GAIN_MIN,
643 .maximum = SAA7191_CHROMA_GAIN_MAX, 632 .maximum = SAA7191_CHROMA_GAIN_MAX,
644 .step = 1, 633 .step = 1,
645 .default_value = SAA7191_CHROMA_GAIN_DEFAULT, 634 .default_value = SAA7191_CHROMA_GAIN_DEFAULT,
646 .flags = 0, 635 }, {
647 .reserved = { SAA7191_CONTROL_CHROMA_GAIN, 0 }, 636 .id = SAA7191_CONTROL_VTRC,
648 },{
649 .id = V4L2_CID_PRIVATE_BASE + 5,
650 .type = V4L2_CTRL_TYPE_BOOLEAN, 637 .type = V4L2_CTRL_TYPE_BOOLEAN,
651 .name = "VTR Time Constant", 638 .name = "VTR Time Constant",
652 .minimum = SAA7191_VTRC_MIN, 639 .minimum = SAA7191_VTRC_MIN,
653 .maximum = SAA7191_VTRC_MAX, 640 .maximum = SAA7191_VTRC_MAX,
654 .step = 1, 641 .step = 1,
655 .default_value = SAA7191_VTRC_DEFAULT, 642 .default_value = SAA7191_VTRC_DEFAULT,
656 .flags = 0, 643 }, {
657 .reserved = { SAA7191_CONTROL_VTRC, 0 }, 644 .id = SAA7191_CONTROL_LUMA_DELAY,
658 },{
659 .id = V4L2_CID_PRIVATE_BASE + 6,
660 .type = V4L2_CTRL_TYPE_INTEGER, 645 .type = V4L2_CTRL_TYPE_INTEGER,
661 .name = "Luminance Delay Compensation", 646 .name = "Luminance Delay Compensation",
662 .minimum = SAA7191_LUMA_DELAY_MIN, 647 .minimum = SAA7191_LUMA_DELAY_MIN,
663 .maximum = SAA7191_LUMA_DELAY_MAX, 648 .maximum = SAA7191_LUMA_DELAY_MAX,
664 .step = 1, 649 .step = 1,
665 .default_value = SAA7191_LUMA_DELAY_DEFAULT, 650 .default_value = SAA7191_LUMA_DELAY_DEFAULT,
666 .flags = 0, 651 }, {
667 .reserved = { SAA7191_CONTROL_LUMA_DELAY, 0 }, 652 .id = SAA7191_CONTROL_VNR,
668 },{
669 .id = V4L2_CID_PRIVATE_BASE + 7,
670 .type = V4L2_CTRL_TYPE_INTEGER, 653 .type = V4L2_CTRL_TYPE_INTEGER,
671 .name = "Vertical Noise Reduction", 654 .name = "Vertical Noise Reduction",
672 .minimum = SAA7191_VNR_MIN, 655 .minimum = SAA7191_VNR_MIN,
673 .maximum = SAA7191_VNR_MAX, 656 .maximum = SAA7191_VNR_MAX,
674 .step = 1, 657 .step = 1,
675 .default_value = SAA7191_VNR_DEFAULT, 658 .default_value = SAA7191_VNR_DEFAULT,
676 .flags = 0,
677 .reserved = { SAA7191_CONTROL_VNR, 0 },
678 } 659 }
679}; 660};
680 661
681/* VINO I2C bus functions */
682
683unsigned i2c_vino_getctrl(void *data)
684{
685 return vino->i2c_control;
686}
687
688void i2c_vino_setctrl(void *data, unsigned val)
689{
690 vino->i2c_control = val;
691}
692
693unsigned i2c_vino_rdata(void *data)
694{
695 return vino->i2c_data;
696}
697
698void i2c_vino_wdata(void *data, unsigned val)
699{
700 vino->i2c_data = val;
701}
702
703static struct i2c_algo_sgi_data i2c_sgi_vino_data =
704{
705 .getctrl = &i2c_vino_getctrl,
706 .setctrl = &i2c_vino_setctrl,
707 .rdata = &i2c_vino_rdata,
708 .wdata = &i2c_vino_wdata,
709 .xfer_timeout = 200,
710 .ack_timeout = 1000,
711};
712
713/*
714 * There are two possible clients on VINO I2C bus, so we limit usage only
715 * to them.
716 */
717static int i2c_vino_client_reg(struct i2c_client *client)
718{
719 unsigned long flags;
720 int ret = 0;
721
722 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
723 switch (client->driver->id) {
724 case I2C_DRIVERID_SAA7191:
725 if (vino_drvdata->decoder.driver)
726 ret = -EBUSY;
727 else
728 vino_drvdata->decoder.driver = client;
729 break;
730 case I2C_DRIVERID_INDYCAM:
731 if (vino_drvdata->camera.driver)
732 ret = -EBUSY;
733 else
734 vino_drvdata->camera.driver = client;
735 break;
736 default:
737 ret = -ENODEV;
738 }
739 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
740
741 return ret;
742}
743
744static int i2c_vino_client_unreg(struct i2c_client *client)
745{
746 unsigned long flags;
747 int ret = 0;
748
749 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
750 if (client == vino_drvdata->decoder.driver) {
751 if (vino_drvdata->decoder.owner != VINO_NO_CHANNEL)
752 ret = -EBUSY;
753 else
754 vino_drvdata->decoder.driver = NULL;
755 } else if (client == vino_drvdata->camera.driver) {
756 if (vino_drvdata->camera.owner != VINO_NO_CHANNEL)
757 ret = -EBUSY;
758 else
759 vino_drvdata->camera.driver = NULL;
760 }
761 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
762
763 return ret;
764}
765
766static struct i2c_adapter vino_i2c_adapter =
767{
768 .name = "VINO I2C bus",
769 .id = I2C_HW_SGI_VINO,
770 .algo_data = &i2c_sgi_vino_data,
771 .client_register = &i2c_vino_client_reg,
772 .client_unregister = &i2c_vino_client_unreg,
773};
774
775static int vino_i2c_add_bus(void)
776{
777 return i2c_sgi_add_bus(&vino_i2c_adapter);
778}
779
780static int vino_i2c_del_bus(void)
781{
782 return i2c_del_adapter(&vino_i2c_adapter);
783}
784
785static int i2c_camera_command(unsigned int cmd, void *arg)
786{
787 return vino_drvdata->camera.driver->
788 driver->command(vino_drvdata->camera.driver,
789 cmd, arg);
790}
791
792static int i2c_decoder_command(unsigned int cmd, void *arg)
793{
794 return vino_drvdata->decoder.driver->
795 driver->command(vino_drvdata->decoder.driver,
796 cmd, arg);
797}
798
799/* VINO framebuffer/DMA descriptor management */ 662/* VINO framebuffer/DMA descriptor management */
800 663
801static void vino_free_buffer_with_count(struct vino_framebuffer *fb, 664static void vino_free_buffer_with_count(struct vino_framebuffer *fb,
@@ -1741,6 +1604,184 @@ static inline void vino_set_default_framerate(struct
1741 vino_set_framerate(vcs, vino_data_norms[vcs->data_norm].fps_max); 1604 vino_set_framerate(vcs, vino_data_norms[vcs->data_norm].fps_max);
1742} 1605}
1743 1606
1607/* VINO I2C bus functions */
1608
1609struct i2c_algo_sgi_data {
1610 void *data; /* private data for lowlevel routines */
1611 unsigned (*getctrl)(void *data);
1612 void (*setctrl)(void *data, unsigned val);
1613 unsigned (*rdata)(void *data);
1614 void (*wdata)(void *data, unsigned val);
1615
1616 int xfer_timeout;
1617 int ack_timeout;
1618};
1619
1620static int wait_xfer_done(struct i2c_algo_sgi_data *adap)
1621{
1622 int i;
1623
1624 for (i = 0; i < adap->xfer_timeout; i++) {
1625 if ((adap->getctrl(adap->data) & SGI_I2C_XFER_BUSY) == 0)
1626 return 0;
1627 udelay(1);
1628 }
1629
1630 return -ETIMEDOUT;
1631}
1632
1633static int wait_ack(struct i2c_algo_sgi_data *adap)
1634{
1635 int i;
1636
1637 if (wait_xfer_done(adap))
1638 return -ETIMEDOUT;
1639 for (i = 0; i < adap->ack_timeout; i++) {
1640 if ((adap->getctrl(adap->data) & SGI_I2C_NACK) == 0)
1641 return 0;
1642 udelay(1);
1643 }
1644
1645 return -ETIMEDOUT;
1646}
1647
1648static int force_idle(struct i2c_algo_sgi_data *adap)
1649{
1650 int i;
1651
1652 adap->setctrl(adap->data, SGI_I2C_FORCE_IDLE);
1653 for (i = 0; i < adap->xfer_timeout; i++) {
1654 if ((adap->getctrl(adap->data) & SGI_I2C_NOT_IDLE) == 0)
1655 goto out;
1656 udelay(1);
1657 }
1658 return -ETIMEDOUT;
1659out:
1660 if (adap->getctrl(adap->data) & SGI_I2C_BUS_ERR)
1661 return -EIO;
1662 return 0;
1663}
1664
1665static int do_address(struct i2c_algo_sgi_data *adap, unsigned int addr,
1666 int rd)
1667{
1668 if (rd)
1669 adap->setctrl(adap->data, SGI_I2C_NOT_IDLE);
1670 /* Check if bus is idle, eventually force it to do so */
1671 if (adap->getctrl(adap->data) & SGI_I2C_NOT_IDLE)
1672 if (force_idle(adap))
1673 return -EIO;
1674 /* Write out the i2c chip address and specify operation */
1675 adap->setctrl(adap->data,
1676 SGI_I2C_HOLD_BUS | SGI_I2C_WRITE | SGI_I2C_NOT_IDLE);
1677 if (rd)
1678 addr |= 1;
1679 adap->wdata(adap->data, addr);
1680 if (wait_ack(adap))
1681 return -EIO;
1682 return 0;
1683}
1684
1685static int i2c_read(struct i2c_algo_sgi_data *adap, unsigned char *buf,
1686 unsigned int len)
1687{
1688 int i;
1689
1690 adap->setctrl(adap->data,
1691 SGI_I2C_HOLD_BUS | SGI_I2C_READ | SGI_I2C_NOT_IDLE);
1692 for (i = 0; i < len; i++) {
1693 if (wait_xfer_done(adap))
1694 return -EIO;
1695 buf[i] = adap->rdata(adap->data);
1696 }
1697 adap->setctrl(adap->data, SGI_I2C_RELEASE_BUS | SGI_I2C_FORCE_IDLE);
1698
1699 return 0;
1700
1701}
1702
1703static int i2c_write(struct i2c_algo_sgi_data *adap, unsigned char *buf,
1704 unsigned int len)
1705{
1706 int i;
1707
1708 /* We are already in write state */
1709 for (i = 0; i < len; i++) {
1710 adap->wdata(adap->data, buf[i]);
1711 if (wait_ack(adap))
1712 return -EIO;
1713 }
1714 return 0;
1715}
1716
1717static int sgi_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs,
1718 int num)
1719{
1720 struct i2c_algo_sgi_data *adap = i2c_adap->algo_data;
1721 struct i2c_msg *p;
1722 int i, err = 0;
1723
1724 for (i = 0; !err && i < num; i++) {
1725 p = &msgs[i];
1726 err = do_address(adap, p->addr, p->flags & I2C_M_RD);
1727 if (err || !p->len)
1728 continue;
1729 if (p->flags & I2C_M_RD)
1730 err = i2c_read(adap, p->buf, p->len);
1731 else
1732 err = i2c_write(adap, p->buf, p->len);
1733 }
1734
1735 return (err < 0) ? err : i;
1736}
1737
1738static u32 sgi_func(struct i2c_adapter *adap)
1739{
1740 return I2C_FUNC_SMBUS_EMUL;
1741}
1742
1743static const struct i2c_algorithm sgi_algo = {
1744 .master_xfer = sgi_xfer,
1745 .functionality = sgi_func,
1746};
1747
1748static unsigned i2c_vino_getctrl(void *data)
1749{
1750 return vino->i2c_control;
1751}
1752
1753static void i2c_vino_setctrl(void *data, unsigned val)
1754{
1755 vino->i2c_control = val;
1756}
1757
1758static unsigned i2c_vino_rdata(void *data)
1759{
1760 return vino->i2c_data;
1761}
1762
1763static void i2c_vino_wdata(void *data, unsigned val)
1764{
1765 vino->i2c_data = val;
1766}
1767
1768static struct i2c_algo_sgi_data i2c_sgi_vino_data = {
1769 .getctrl = &i2c_vino_getctrl,
1770 .setctrl = &i2c_vino_setctrl,
1771 .rdata = &i2c_vino_rdata,
1772 .wdata = &i2c_vino_wdata,
1773 .xfer_timeout = 200,
1774 .ack_timeout = 1000,
1775};
1776
1777static struct i2c_adapter vino_i2c_adapter = {
1778 .name = "VINO I2C bus",
1779 .id = I2C_HW_SGI_VINO,
1780 .algo = &sgi_algo,
1781 .algo_data = &i2c_sgi_vino_data,
1782 .owner = THIS_MODULE,
1783};
1784
1744/* 1785/*
1745 * Prepare VINO for DMA transfer... 1786 * Prepare VINO for DMA transfer...
1746 * (execute only with vino_lock and input_lock locked) 1787 * (execute only with vino_lock and input_lock locked)
@@ -2490,86 +2531,15 @@ static int vino_get_saa7191_input(int input)
2490 } 2531 }
2491} 2532}
2492 2533
2493static int vino_get_saa7191_norm(unsigned int data_norm)
2494{
2495 switch (data_norm) {
2496 case VINO_DATA_NORM_AUTO:
2497 return SAA7191_NORM_AUTO;
2498 case VINO_DATA_NORM_AUTO_EXT:
2499 return SAA7191_NORM_AUTO_EXT;
2500 case VINO_DATA_NORM_PAL:
2501 return SAA7191_NORM_PAL;
2502 case VINO_DATA_NORM_NTSC:
2503 return SAA7191_NORM_NTSC;
2504 case VINO_DATA_NORM_SECAM:
2505 return SAA7191_NORM_SECAM;
2506 default:
2507 printk(KERN_ERR "VINO: vino_get_saa7191_norm(): "
2508 "invalid norm!\n");
2509 return -1;
2510 }
2511}
2512
2513static int vino_get_from_saa7191_norm(int saa7191_norm)
2514{
2515 switch (saa7191_norm) {
2516 case SAA7191_NORM_PAL:
2517 return VINO_DATA_NORM_PAL;
2518 case SAA7191_NORM_NTSC:
2519 return VINO_DATA_NORM_NTSC;
2520 case SAA7191_NORM_SECAM:
2521 return VINO_DATA_NORM_SECAM;
2522 default:
2523 printk(KERN_ERR "VINO: vino_get_from_saa7191_norm(): "
2524 "invalid norm!\n");
2525 return VINO_DATA_NORM_NONE;
2526 }
2527}
2528
2529static int vino_saa7191_set_norm(unsigned int *data_norm)
2530{
2531 int saa7191_norm, new_data_norm;
2532 int err = 0;
2533
2534 saa7191_norm = vino_get_saa7191_norm(*data_norm);
2535
2536 err = i2c_decoder_command(DECODER_SAA7191_SET_NORM,
2537 &saa7191_norm);
2538 if (err)
2539 goto out;
2540
2541 if ((*data_norm == VINO_DATA_NORM_AUTO)
2542 || (*data_norm == VINO_DATA_NORM_AUTO_EXT)) {
2543 struct saa7191_status status;
2544
2545 err = i2c_decoder_command(DECODER_SAA7191_GET_STATUS,
2546 &status);
2547 if (err)
2548 goto out;
2549
2550 new_data_norm =
2551 vino_get_from_saa7191_norm(status.norm);
2552 if (new_data_norm == VINO_DATA_NORM_NONE) {
2553 err = -EINVAL;
2554 goto out;
2555 }
2556
2557 *data_norm = (unsigned int)new_data_norm;
2558 }
2559
2560out:
2561 return err;
2562}
2563
2564/* execute with input_lock locked */ 2534/* execute with input_lock locked */
2565static int vino_is_input_owner(struct vino_channel_settings *vcs) 2535static int vino_is_input_owner(struct vino_channel_settings *vcs)
2566{ 2536{
2567 switch(vcs->input) { 2537 switch(vcs->input) {
2568 case VINO_INPUT_COMPOSITE: 2538 case VINO_INPUT_COMPOSITE:
2569 case VINO_INPUT_SVIDEO: 2539 case VINO_INPUT_SVIDEO:
2570 return (vino_drvdata->decoder.owner == vcs->channel); 2540 return vino_drvdata->decoder_owner == vcs->channel;
2571 case VINO_INPUT_D1: 2541 case VINO_INPUT_D1:
2572 return (vino_drvdata->camera.owner == vcs->channel); 2542 return vino_drvdata->camera_owner == vcs->channel;
2573 default: 2543 default:
2574 return 0; 2544 return 0;
2575 } 2545 }
@@ -2585,23 +2555,22 @@ static int vino_acquire_input(struct vino_channel_settings *vcs)
2585 spin_lock_irqsave(&vino_drvdata->input_lock, flags); 2555 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
2586 2556
2587 /* First try D1 and then SAA7191 */ 2557 /* First try D1 and then SAA7191 */
2588 if (vino_drvdata->camera.driver 2558 if (vino_drvdata->camera
2589 && (vino_drvdata->camera.owner == VINO_NO_CHANNEL)) { 2559 && (vino_drvdata->camera_owner == VINO_NO_CHANNEL)) {
2590 i2c_use_client(vino_drvdata->camera.driver); 2560 vino_drvdata->camera_owner = vcs->channel;
2591 vino_drvdata->camera.owner = vcs->channel;
2592 vcs->input = VINO_INPUT_D1; 2561 vcs->input = VINO_INPUT_D1;
2593 vcs->data_norm = VINO_DATA_NORM_D1; 2562 vcs->data_norm = VINO_DATA_NORM_D1;
2594 } else if (vino_drvdata->decoder.driver 2563 } else if (vino_drvdata->decoder
2595 && (vino_drvdata->decoder.owner == VINO_NO_CHANNEL)) { 2564 && (vino_drvdata->decoder_owner == VINO_NO_CHANNEL)) {
2596 int input, data_norm; 2565 int input;
2597 int saa7191_input; 2566 int data_norm;
2567 v4l2_std_id norm;
2568 struct v4l2_routing route = { 0, 0 };
2598 2569
2599 i2c_use_client(vino_drvdata->decoder.driver);
2600 input = VINO_INPUT_COMPOSITE; 2570 input = VINO_INPUT_COMPOSITE;
2601 2571
2602 saa7191_input = vino_get_saa7191_input(input); 2572 route.input = vino_get_saa7191_input(input);
2603 ret = i2c_decoder_command(DECODER_SET_INPUT, 2573 ret = decoder_call(video, s_routing, &route);
2604 &saa7191_input);
2605 if (ret) { 2574 if (ret) {
2606 ret = -EINVAL; 2575 ret = -EINVAL;
2607 goto out; 2576 goto out;
@@ -2612,12 +2581,15 @@ static int vino_acquire_input(struct vino_channel_settings *vcs)
2612 /* Don't hold spinlocks while auto-detecting norm 2581 /* Don't hold spinlocks while auto-detecting norm
2613 * as it may take a while... */ 2582 * as it may take a while... */
2614 2583
2615 data_norm = VINO_DATA_NORM_AUTO_EXT; 2584 ret = decoder_call(video, querystd, &norm);
2616 2585 if (!ret) {
2617 ret = vino_saa7191_set_norm(&data_norm); 2586 for (data_norm = 0; data_norm < 3; data_norm++) {
2618 if ((ret == -EBUSY) || (ret == -EAGAIN)) { 2587 if (vino_data_norms[data_norm].std & norm)
2619 data_norm = VINO_DATA_NORM_PAL; 2588 break;
2620 ret = vino_saa7191_set_norm(&data_norm); 2589 }
2590 if (data_norm == 3)
2591 data_norm = VINO_DATA_NORM_PAL;
2592 ret = decoder_call(tuner, s_std, norm);
2621 } 2593 }
2622 2594
2623 spin_lock_irqsave(&vino_drvdata->input_lock, flags); 2595 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
@@ -2627,7 +2599,7 @@ static int vino_acquire_input(struct vino_channel_settings *vcs)
2627 goto out; 2599 goto out;
2628 } 2600 }
2629 2601
2630 vino_drvdata->decoder.owner = vcs->channel; 2602 vino_drvdata->decoder_owner = vcs->channel;
2631 2603
2632 vcs->input = input; 2604 vcs->input = input;
2633 vcs->data_norm = data_norm; 2605 vcs->data_norm = data_norm;
@@ -2672,25 +2644,24 @@ static int vino_set_input(struct vino_channel_settings *vcs, int input)
2672 switch (input) { 2644 switch (input) {
2673 case VINO_INPUT_COMPOSITE: 2645 case VINO_INPUT_COMPOSITE:
2674 case VINO_INPUT_SVIDEO: 2646 case VINO_INPUT_SVIDEO:
2675 if (!vino_drvdata->decoder.driver) { 2647 if (!vino_drvdata->decoder) {
2676 ret = -EINVAL; 2648 ret = -EINVAL;
2677 goto out; 2649 goto out;
2678 } 2650 }
2679 2651
2680 if (vino_drvdata->decoder.owner == VINO_NO_CHANNEL) { 2652 if (vino_drvdata->decoder_owner == VINO_NO_CHANNEL) {
2681 i2c_use_client(vino_drvdata->decoder.driver); 2653 vino_drvdata->decoder_owner = vcs->channel;
2682 vino_drvdata->decoder.owner = vcs->channel;
2683 } 2654 }
2684 2655
2685 if (vino_drvdata->decoder.owner == vcs->channel) { 2656 if (vino_drvdata->decoder_owner == vcs->channel) {
2686 int data_norm; 2657 int data_norm;
2687 int saa7191_input; 2658 v4l2_std_id norm;
2659 struct v4l2_routing route = { 0, 0 };
2688 2660
2689 saa7191_input = vino_get_saa7191_input(input); 2661 route.input = vino_get_saa7191_input(input);
2690 ret = i2c_decoder_command(DECODER_SET_INPUT, 2662 ret = decoder_call(video, s_routing, &route);
2691 &saa7191_input);
2692 if (ret) { 2663 if (ret) {
2693 vino_drvdata->decoder.owner = VINO_NO_CHANNEL; 2664 vino_drvdata->decoder_owner = VINO_NO_CHANNEL;
2694 ret = -EINVAL; 2665 ret = -EINVAL;
2695 goto out; 2666 goto out;
2696 } 2667 }
@@ -2700,18 +2671,21 @@ static int vino_set_input(struct vino_channel_settings *vcs, int input)
2700 /* Don't hold spinlocks while auto-detecting norm 2671 /* Don't hold spinlocks while auto-detecting norm
2701 * as it may take a while... */ 2672 * as it may take a while... */
2702 2673
2703 data_norm = VINO_DATA_NORM_AUTO_EXT; 2674 ret = decoder_call(video, querystd, &norm);
2704 2675 if (!ret) {
2705 ret = vino_saa7191_set_norm(&data_norm); 2676 for (data_norm = 0; data_norm < 3; data_norm++) {
2706 if ((ret == -EBUSY) || (ret == -EAGAIN)) { 2677 if (vino_data_norms[data_norm].std & norm)
2707 data_norm = VINO_DATA_NORM_PAL; 2678 break;
2708 ret = vino_saa7191_set_norm(&data_norm); 2679 }
2680 if (data_norm == 3)
2681 data_norm = VINO_DATA_NORM_PAL;
2682 ret = decoder_call(tuner, s_std, norm);
2709 } 2683 }
2710 2684
2711 spin_lock_irqsave(&vino_drvdata->input_lock, flags); 2685 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
2712 2686
2713 if (ret) { 2687 if (ret) {
2714 vino_drvdata->decoder.owner = VINO_NO_CHANNEL; 2688 vino_drvdata->decoder_owner = VINO_NO_CHANNEL;
2715 ret = -EINVAL; 2689 ret = -EINVAL;
2716 goto out; 2690 goto out;
2717 } 2691 }
@@ -2728,37 +2702,31 @@ static int vino_set_input(struct vino_channel_settings *vcs, int input)
2728 vcs->data_norm = vcs2->data_norm; 2702 vcs->data_norm = vcs2->data_norm;
2729 } 2703 }
2730 2704
2731 if (vino_drvdata->camera.owner == vcs->channel) { 2705 if (vino_drvdata->camera_owner == vcs->channel) {
2732 /* Transfer the ownership or release the input */ 2706 /* Transfer the ownership or release the input */
2733 if (vcs2->input == VINO_INPUT_D1) { 2707 if (vcs2->input == VINO_INPUT_D1) {
2734 vino_drvdata->camera.owner = vcs2->channel; 2708 vino_drvdata->camera_owner = vcs2->channel;
2735 } else { 2709 } else {
2736 i2c_release_client(vino_drvdata-> 2710 vino_drvdata->camera_owner = VINO_NO_CHANNEL;
2737 camera.driver);
2738 vino_drvdata->camera.owner = VINO_NO_CHANNEL;
2739 } 2711 }
2740 } 2712 }
2741 break; 2713 break;
2742 case VINO_INPUT_D1: 2714 case VINO_INPUT_D1:
2743 if (!vino_drvdata->camera.driver) { 2715 if (!vino_drvdata->camera) {
2744 ret = -EINVAL; 2716 ret = -EINVAL;
2745 goto out; 2717 goto out;
2746 } 2718 }
2747 2719
2748 if (vino_drvdata->camera.owner == VINO_NO_CHANNEL) { 2720 if (vino_drvdata->camera_owner == VINO_NO_CHANNEL)
2749 i2c_use_client(vino_drvdata->camera.driver); 2721 vino_drvdata->camera_owner = vcs->channel;
2750 vino_drvdata->camera.owner = vcs->channel;
2751 }
2752 2722
2753 if (vino_drvdata->decoder.owner == vcs->channel) { 2723 if (vino_drvdata->decoder_owner == vcs->channel) {
2754 /* Transfer the ownership or release the input */ 2724 /* Transfer the ownership or release the input */
2755 if ((vcs2->input == VINO_INPUT_COMPOSITE) || 2725 if ((vcs2->input == VINO_INPUT_COMPOSITE) ||
2756 (vcs2->input == VINO_INPUT_SVIDEO)) { 2726 (vcs2->input == VINO_INPUT_SVIDEO)) {
2757 vino_drvdata->decoder.owner = vcs2->channel; 2727 vino_drvdata->decoder_owner = vcs2->channel;
2758 } else { 2728 } else {
2759 i2c_release_client(vino_drvdata-> 2729 vino_drvdata->decoder_owner = VINO_NO_CHANNEL;
2760 decoder.driver);
2761 vino_drvdata->decoder.owner = VINO_NO_CHANNEL;
2762 } 2730 }
2763 } 2731 }
2764 2732
@@ -2795,20 +2763,18 @@ static void vino_release_input(struct vino_channel_settings *vcs)
2795 /* Release ownership of the channel 2763 /* Release ownership of the channel
2796 * and if the other channel takes input from 2764 * and if the other channel takes input from
2797 * the same source, transfer the ownership */ 2765 * the same source, transfer the ownership */
2798 if (vino_drvdata->camera.owner == vcs->channel) { 2766 if (vino_drvdata->camera_owner == vcs->channel) {
2799 if (vcs2->input == VINO_INPUT_D1) { 2767 if (vcs2->input == VINO_INPUT_D1) {
2800 vino_drvdata->camera.owner = vcs2->channel; 2768 vino_drvdata->camera_owner = vcs2->channel;
2801 } else { 2769 } else {
2802 i2c_release_client(vino_drvdata->camera.driver); 2770 vino_drvdata->camera_owner = VINO_NO_CHANNEL;
2803 vino_drvdata->camera.owner = VINO_NO_CHANNEL;
2804 } 2771 }
2805 } else if (vino_drvdata->decoder.owner == vcs->channel) { 2772 } else if (vino_drvdata->decoder_owner == vcs->channel) {
2806 if ((vcs2->input == VINO_INPUT_COMPOSITE) || 2773 if ((vcs2->input == VINO_INPUT_COMPOSITE) ||
2807 (vcs2->input == VINO_INPUT_SVIDEO)) { 2774 (vcs2->input == VINO_INPUT_SVIDEO)) {
2808 vino_drvdata->decoder.owner = vcs2->channel; 2775 vino_drvdata->decoder_owner = vcs2->channel;
2809 } else { 2776 } else {
2810 i2c_release_client(vino_drvdata->decoder.driver); 2777 vino_drvdata->decoder_owner = VINO_NO_CHANNEL;
2811 vino_drvdata->decoder.owner = VINO_NO_CHANNEL;
2812 } 2778 }
2813 } 2779 }
2814 vcs->input = VINO_INPUT_NONE; 2780 vcs->input = VINO_INPUT_NONE;
@@ -2829,18 +2795,16 @@ static int vino_set_data_norm(struct vino_channel_settings *vcs,
2829 switch (vcs->input) { 2795 switch (vcs->input) {
2830 case VINO_INPUT_D1: 2796 case VINO_INPUT_D1:
2831 /* only one "norm" supported */ 2797 /* only one "norm" supported */
2832 if ((data_norm != VINO_DATA_NORM_D1) 2798 if (data_norm != VINO_DATA_NORM_D1)
2833 && (data_norm != VINO_DATA_NORM_AUTO)
2834 && (data_norm != VINO_DATA_NORM_AUTO_EXT))
2835 return -EINVAL; 2799 return -EINVAL;
2836 break; 2800 break;
2837 case VINO_INPUT_COMPOSITE: 2801 case VINO_INPUT_COMPOSITE:
2838 case VINO_INPUT_SVIDEO: { 2802 case VINO_INPUT_SVIDEO: {
2803 v4l2_std_id norm;
2804
2839 if ((data_norm != VINO_DATA_NORM_PAL) 2805 if ((data_norm != VINO_DATA_NORM_PAL)
2840 && (data_norm != VINO_DATA_NORM_NTSC) 2806 && (data_norm != VINO_DATA_NORM_NTSC)
2841 && (data_norm != VINO_DATA_NORM_SECAM) 2807 && (data_norm != VINO_DATA_NORM_SECAM))
2842 && (data_norm != VINO_DATA_NORM_AUTO)
2843 && (data_norm != VINO_DATA_NORM_AUTO_EXT))
2844 return -EINVAL; 2808 return -EINVAL;
2845 2809
2846 spin_unlock_irqrestore(&vino_drvdata->input_lock, *flags); 2810 spin_unlock_irqrestore(&vino_drvdata->input_lock, *flags);
@@ -2848,7 +2812,8 @@ static int vino_set_data_norm(struct vino_channel_settings *vcs,
2848 /* Don't hold spinlocks while setting norm 2812 /* Don't hold spinlocks while setting norm
2849 * as it may take a while... */ 2813 * as it may take a while... */
2850 2814
2851 err = vino_saa7191_set_norm(&data_norm); 2815 norm = vino_data_norms[data_norm].std;
2816 err = decoder_call(tuner, s_std, norm);
2852 2817
2853 spin_lock_irqsave(&vino_drvdata->input_lock, *flags); 2818 spin_lock_irqsave(&vino_drvdata->input_lock, *flags);
2854 2819
@@ -2884,41 +2849,13 @@ static int vino_find_data_format(__u32 pixelformat)
2884 return VINO_DATA_FMT_NONE; 2849 return VINO_DATA_FMT_NONE;
2885} 2850}
2886 2851
2887static int vino_enum_data_norm(struct vino_channel_settings *vcs, __u32 index) 2852static int vino_int_enum_input(struct vino_channel_settings *vcs, __u32 index)
2888{
2889 int data_norm = VINO_DATA_NORM_NONE;
2890 unsigned long flags;
2891
2892 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
2893 switch(vcs->input) {
2894 case VINO_INPUT_COMPOSITE:
2895 case VINO_INPUT_SVIDEO:
2896 if (index == 0) {
2897 data_norm = VINO_DATA_NORM_PAL;
2898 } else if (index == 1) {
2899 data_norm = VINO_DATA_NORM_NTSC;
2900 } else if (index == 2) {
2901 data_norm = VINO_DATA_NORM_SECAM;
2902 }
2903 break;
2904 case VINO_INPUT_D1:
2905 if (index == 0) {
2906 data_norm = VINO_DATA_NORM_D1;
2907 }
2908 break;
2909 }
2910 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
2911
2912 return data_norm;
2913}
2914
2915static int vino_enum_input(struct vino_channel_settings *vcs, __u32 index)
2916{ 2853{
2917 int input = VINO_INPUT_NONE; 2854 int input = VINO_INPUT_NONE;
2918 unsigned long flags; 2855 unsigned long flags;
2919 2856
2920 spin_lock_irqsave(&vino_drvdata->input_lock, flags); 2857 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
2921 if (vino_drvdata->decoder.driver && vino_drvdata->camera.driver) { 2858 if (vino_drvdata->decoder && vino_drvdata->camera) {
2922 switch (index) { 2859 switch (index) {
2923 case 0: 2860 case 0:
2924 input = VINO_INPUT_COMPOSITE; 2861 input = VINO_INPUT_COMPOSITE;
@@ -2930,7 +2867,7 @@ static int vino_enum_input(struct vino_channel_settings *vcs, __u32 index)
2930 input = VINO_INPUT_D1; 2867 input = VINO_INPUT_D1;
2931 break; 2868 break;
2932 } 2869 }
2933 } else if (vino_drvdata->decoder.driver) { 2870 } else if (vino_drvdata->decoder) {
2934 switch (index) { 2871 switch (index) {
2935 case 0: 2872 case 0:
2936 input = VINO_INPUT_COMPOSITE; 2873 input = VINO_INPUT_COMPOSITE;
@@ -2939,7 +2876,7 @@ static int vino_enum_input(struct vino_channel_settings *vcs, __u32 index)
2939 input = VINO_INPUT_SVIDEO; 2876 input = VINO_INPUT_SVIDEO;
2940 break; 2877 break;
2941 } 2878 }
2942 } else if (vino_drvdata->camera.driver) { 2879 } else if (vino_drvdata->camera) {
2943 switch (index) { 2880 switch (index) {
2944 case 0: 2881 case 0:
2945 input = VINO_INPUT_D1; 2882 input = VINO_INPUT_D1;
@@ -2957,7 +2894,7 @@ static __u32 vino_find_input_index(struct vino_channel_settings *vcs)
2957 __u32 index = 0; 2894 __u32 index = 0;
2958 // FIXME: detect when no inputs available 2895 // FIXME: detect when no inputs available
2959 2896
2960 if (vino_drvdata->decoder.driver && vino_drvdata->camera.driver) { 2897 if (vino_drvdata->decoder && vino_drvdata->camera) {
2961 switch (vcs->input) { 2898 switch (vcs->input) {
2962 case VINO_INPUT_COMPOSITE: 2899 case VINO_INPUT_COMPOSITE:
2963 index = 0; 2900 index = 0;
@@ -2969,7 +2906,7 @@ static __u32 vino_find_input_index(struct vino_channel_settings *vcs)
2969 index = 2; 2906 index = 2;
2970 break; 2907 break;
2971 } 2908 }
2972 } else if (vino_drvdata->decoder.driver) { 2909 } else if (vino_drvdata->decoder) {
2973 switch (vcs->input) { 2910 switch (vcs->input) {
2974 case VINO_INPUT_COMPOSITE: 2911 case VINO_INPUT_COMPOSITE:
2975 index = 0; 2912 index = 0;
@@ -2978,7 +2915,7 @@ static __u32 vino_find_input_index(struct vino_channel_settings *vcs)
2978 index = 1; 2915 index = 1;
2979 break; 2916 break;
2980 } 2917 }
2981 } else if (vino_drvdata->camera.driver) { 2918 } else if (vino_drvdata->camera) {
2982 switch (vcs->input) { 2919 switch (vcs->input) {
2983 case VINO_INPUT_D1: 2920 case VINO_INPUT_D1:
2984 index = 0; 2921 index = 0;
@@ -2991,7 +2928,8 @@ static __u32 vino_find_input_index(struct vino_channel_settings *vcs)
2991 2928
2992/* V4L2 ioctls */ 2929/* V4L2 ioctls */
2993 2930
2994static void vino_v4l2_querycap(struct v4l2_capability *cap) 2931static int vino_querycap(struct file *file, void *__fh,
2932 struct v4l2_capability *cap)
2995{ 2933{
2996 memset(cap, 0, sizeof(struct v4l2_capability)); 2934 memset(cap, 0, sizeof(struct v4l2_capability));
2997 2935
@@ -3003,16 +2941,18 @@ static void vino_v4l2_querycap(struct v4l2_capability *cap)
3003 V4L2_CAP_VIDEO_CAPTURE | 2941 V4L2_CAP_VIDEO_CAPTURE |
3004 V4L2_CAP_STREAMING; 2942 V4L2_CAP_STREAMING;
3005 // V4L2_CAP_OVERLAY, V4L2_CAP_READWRITE 2943 // V4L2_CAP_OVERLAY, V4L2_CAP_READWRITE
2944 return 0;
3006} 2945}
3007 2946
3008static int vino_v4l2_enuminput(struct vino_channel_settings *vcs, 2947static int vino_enum_input(struct file *file, void *__fh,
3009 struct v4l2_input *i) 2948 struct v4l2_input *i)
3010{ 2949{
2950 struct vino_channel_settings *vcs = video_drvdata(file);
3011 __u32 index = i->index; 2951 __u32 index = i->index;
3012 int input; 2952 int input;
3013 dprintk("requested index = %d\n", index); 2953 dprintk("requested index = %d\n", index);
3014 2954
3015 input = vino_enum_input(vcs, index); 2955 input = vino_int_enum_input(vcs, index);
3016 if (input == VINO_INPUT_NONE) 2956 if (input == VINO_INPUT_NONE)
3017 return -EINVAL; 2957 return -EINVAL;
3018 2958
@@ -3023,20 +2963,15 @@ static int vino_v4l2_enuminput(struct vino_channel_settings *vcs,
3023 i->std = vino_inputs[input].std; 2963 i->std = vino_inputs[input].std;
3024 strcpy(i->name, vino_inputs[input].name); 2964 strcpy(i->name, vino_inputs[input].name);
3025 2965
3026 if ((input == VINO_INPUT_COMPOSITE) 2966 if (input == VINO_INPUT_COMPOSITE || input == VINO_INPUT_SVIDEO)
3027 || (input == VINO_INPUT_SVIDEO)) { 2967 decoder_call(video, g_input_status, &i->status);
3028 struct saa7191_status status;
3029 i2c_decoder_command(DECODER_SAA7191_GET_STATUS, &status);
3030 i->status |= status.signal ? 0 : V4L2_IN_ST_NO_SIGNAL;
3031 i->status |= status.color ? 0 : V4L2_IN_ST_NO_COLOR;
3032 }
3033
3034 return 0; 2968 return 0;
3035} 2969}
3036 2970
3037static int vino_v4l2_g_input(struct vino_channel_settings *vcs, 2971static int vino_g_input(struct file *file, void *__fh,
3038 unsigned int *i) 2972 unsigned int *i)
3039{ 2973{
2974 struct vino_channel_settings *vcs = video_drvdata(file);
3040 __u32 index; 2975 __u32 index;
3041 int input; 2976 int input;
3042 unsigned long flags; 2977 unsigned long flags;
@@ -3057,52 +2992,24 @@ static int vino_v4l2_g_input(struct vino_channel_settings *vcs,
3057 return 0; 2992 return 0;
3058} 2993}
3059 2994
3060static int vino_v4l2_s_input(struct vino_channel_settings *vcs, 2995static int vino_s_input(struct file *file, void *__fh,
3061 unsigned int *i) 2996 unsigned int i)
3062{ 2997{
2998 struct vino_channel_settings *vcs = video_drvdata(file);
3063 int input; 2999 int input;
3064 dprintk("requested input = %d\n", *i); 3000 dprintk("requested input = %d\n", i);
3065 3001
3066 input = vino_enum_input(vcs, *i); 3002 input = vino_int_enum_input(vcs, i);
3067 if (input == VINO_INPUT_NONE) 3003 if (input == VINO_INPUT_NONE)
3068 return -EINVAL; 3004 return -EINVAL;
3069 3005
3070 return vino_set_input(vcs, input); 3006 return vino_set_input(vcs, input);
3071} 3007}
3072 3008
3073static int vino_v4l2_enumstd(struct vino_channel_settings *vcs, 3009static int vino_querystd(struct file *file, void *__fh,
3074 struct v4l2_standard *s)
3075{
3076 int index = s->index;
3077 int data_norm;
3078
3079 data_norm = vino_enum_data_norm(vcs, index);
3080 dprintk("standard index = %d\n", index);
3081
3082 if (data_norm == VINO_DATA_NORM_NONE)
3083 return -EINVAL;
3084
3085 dprintk("standard name = %s\n",
3086 vino_data_norms[data_norm].description);
3087
3088 memset(s, 0, sizeof(struct v4l2_standard));
3089 s->index = index;
3090
3091 s->id = vino_data_norms[data_norm].std;
3092 s->frameperiod.numerator = 1;
3093 s->frameperiod.denominator =
3094 vino_data_norms[data_norm].fps_max;
3095 s->framelines =
3096 vino_data_norms[data_norm].framelines;
3097 strcpy(s->name,
3098 vino_data_norms[data_norm].description);
3099
3100 return 0;
3101}
3102
3103static int vino_v4l2_querystd(struct vino_channel_settings *vcs,
3104 v4l2_std_id *std) 3010 v4l2_std_id *std)
3105{ 3011{
3012 struct vino_channel_settings *vcs = video_drvdata(file);
3106 unsigned long flags; 3013 unsigned long flags;
3107 int err = 0; 3014 int err = 0;
3108 3015
@@ -3114,19 +3021,7 @@ static int vino_v4l2_querystd(struct vino_channel_settings *vcs,
3114 break; 3021 break;
3115 case VINO_INPUT_COMPOSITE: 3022 case VINO_INPUT_COMPOSITE:
3116 case VINO_INPUT_SVIDEO: { 3023 case VINO_INPUT_SVIDEO: {
3117 struct saa7191_status status; 3024 decoder_call(video, querystd, std);
3118
3119 i2c_decoder_command(DECODER_SAA7191_GET_STATUS, &status);
3120
3121 if (status.signal) {
3122 if (status.signal_60hz) {
3123 *std = V4L2_STD_NTSC;
3124 } else {
3125 *std = V4L2_STD_PAL | V4L2_STD_SECAM;
3126 }
3127 } else {
3128 *std = vino_inputs[vcs->input].std;
3129 }
3130 break; 3025 break;
3131 } 3026 }
3132 default: 3027 default:
@@ -3138,9 +3033,10 @@ static int vino_v4l2_querystd(struct vino_channel_settings *vcs,
3138 return err; 3033 return err;
3139} 3034}
3140 3035
3141static int vino_v4l2_g_std(struct vino_channel_settings *vcs, 3036static int vino_g_std(struct file *file, void *__fh,
3142 v4l2_std_id *std) 3037 v4l2_std_id *std)
3143{ 3038{
3039 struct vino_channel_settings *vcs = video_drvdata(file);
3144 unsigned long flags; 3040 unsigned long flags;
3145 3041
3146 spin_lock_irqsave(&vino_drvdata->input_lock, flags); 3042 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
@@ -3153,9 +3049,10 @@ static int vino_v4l2_g_std(struct vino_channel_settings *vcs,
3153 return 0; 3049 return 0;
3154} 3050}
3155 3051
3156static int vino_v4l2_s_std(struct vino_channel_settings *vcs, 3052static int vino_s_std(struct file *file, void *__fh,
3157 v4l2_std_id *std) 3053 v4l2_std_id *std)
3158{ 3054{
3055 struct vino_channel_settings *vcs = video_drvdata(file);
3159 unsigned long flags; 3056 unsigned long flags;
3160 int ret = 0; 3057 int ret = 0;
3161 3058
@@ -3176,12 +3073,7 @@ static int vino_v4l2_s_std(struct vino_channel_settings *vcs,
3176 if (vcs->input == VINO_INPUT_D1) 3073 if (vcs->input == VINO_INPUT_D1)
3177 goto out; 3074 goto out;
3178 3075
3179 if (((*std) & V4L2_STD_PAL) 3076 if ((*std) & V4L2_STD_PAL) {
3180 && ((*std) & V4L2_STD_NTSC)
3181 && ((*std) & V4L2_STD_SECAM)) {
3182 ret = vino_set_data_norm(vcs, VINO_DATA_NORM_AUTO_EXT,
3183 &flags);
3184 } else if ((*std) & V4L2_STD_PAL) {
3185 ret = vino_set_data_norm(vcs, VINO_DATA_NORM_PAL, 3077 ret = vino_set_data_norm(vcs, VINO_DATA_NORM_PAL,
3186 &flags); 3078 &flags);
3187 } else if ((*std) & V4L2_STD_NTSC) { 3079 } else if ((*std) & V4L2_STD_NTSC) {
@@ -3207,185 +3099,144 @@ out:
3207 return ret; 3099 return ret;
3208} 3100}
3209 3101
3210static int vino_v4l2_enum_fmt(struct vino_channel_settings *vcs, 3102static int vino_enum_fmt_vid_cap(struct file *file, void *__fh,
3211 struct v4l2_fmtdesc *fd) 3103 struct v4l2_fmtdesc *fd)
3212{ 3104{
3213 enum v4l2_buf_type type = fd->type; 3105 dprintk("format index = %d\n", fd->index);
3214 int index = fd->index;
3215 dprintk("format index = %d\n", index);
3216 3106
3217 switch (fd->type) { 3107 if (fd->index >= VINO_DATA_FMT_COUNT)
3218 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
3219 if ((fd->index < 0) ||
3220 (fd->index >= VINO_DATA_FMT_COUNT))
3221 return -EINVAL;
3222 dprintk("format name = %s\n",
3223 vino_data_formats[index].description);
3224
3225 memset(fd, 0, sizeof(struct v4l2_fmtdesc));
3226 fd->index = index;
3227 fd->type = type;
3228 fd->pixelformat = vino_data_formats[index].pixelformat;
3229 strcpy(fd->description, vino_data_formats[index].description);
3230 break;
3231 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
3232 default:
3233 return -EINVAL; 3108 return -EINVAL;
3234 } 3109 dprintk("format name = %s\n", vino_data_formats[fd->index].description);
3235 3110
3111 fd->pixelformat = vino_data_formats[fd->index].pixelformat;
3112 strcpy(fd->description, vino_data_formats[fd->index].description);
3236 return 0; 3113 return 0;
3237} 3114}
3238 3115
3239static int vino_v4l2_try_fmt(struct vino_channel_settings *vcs, 3116static int vino_try_fmt_vid_cap(struct file *file, void *__fh,
3240 struct v4l2_format *f) 3117 struct v4l2_format *f)
3241{ 3118{
3119 struct vino_channel_settings *vcs = video_drvdata(file);
3242 struct vino_channel_settings tempvcs; 3120 struct vino_channel_settings tempvcs;
3243 unsigned long flags; 3121 unsigned long flags;
3122 struct v4l2_pix_format *pf = &f->fmt.pix;
3244 3123
3245 switch (f->type) { 3124 dprintk("requested: w = %d, h = %d\n",
3246 case V4L2_BUF_TYPE_VIDEO_CAPTURE: { 3125 pf->width, pf->height);
3247 struct v4l2_pix_format *pf = &f->fmt.pix;
3248
3249 dprintk("requested: w = %d, h = %d\n",
3250 pf->width, pf->height);
3251
3252 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3253 memcpy(&tempvcs, vcs, sizeof(struct vino_channel_settings));
3254 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3255 3126
3256 tempvcs.data_format = vino_find_data_format(pf->pixelformat); 3127 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3257 if (tempvcs.data_format == VINO_DATA_FMT_NONE) { 3128 memcpy(&tempvcs, vcs, sizeof(struct vino_channel_settings));
3258 tempvcs.data_format = VINO_DATA_FMT_GREY; 3129 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3259 pf->pixelformat =
3260 vino_data_formats[tempvcs.data_format].
3261 pixelformat;
3262 }
3263 3130
3264 /* data format must be set before clipping/scaling */ 3131 tempvcs.data_format = vino_find_data_format(pf->pixelformat);
3265 vino_set_scaling(&tempvcs, pf->width, pf->height); 3132 if (tempvcs.data_format == VINO_DATA_FMT_NONE) {
3133 tempvcs.data_format = VINO_DATA_FMT_GREY;
3134 pf->pixelformat =
3135 vino_data_formats[tempvcs.data_format].
3136 pixelformat;
3137 }
3266 3138
3267 dprintk("data format = %s\n", 3139 /* data format must be set before clipping/scaling */
3268 vino_data_formats[tempvcs.data_format].description); 3140 vino_set_scaling(&tempvcs, pf->width, pf->height);
3269 3141
3270 pf->width = (tempvcs.clipping.right - tempvcs.clipping.left) / 3142 dprintk("data format = %s\n",
3271 tempvcs.decimation; 3143 vino_data_formats[tempvcs.data_format].description);
3272 pf->height = (tempvcs.clipping.bottom - tempvcs.clipping.top) /
3273 tempvcs.decimation;
3274 3144
3275 pf->field = V4L2_FIELD_INTERLACED; 3145 pf->width = (tempvcs.clipping.right - tempvcs.clipping.left) /
3276 pf->bytesperline = tempvcs.line_size; 3146 tempvcs.decimation;
3277 pf->sizeimage = tempvcs.line_size * 3147 pf->height = (tempvcs.clipping.bottom - tempvcs.clipping.top) /
3278 (tempvcs.clipping.bottom - tempvcs.clipping.top) / 3148 tempvcs.decimation;
3279 tempvcs.decimation;
3280 pf->colorspace =
3281 vino_data_formats[tempvcs.data_format].colorspace;
3282 3149
3283 pf->priv = 0; 3150 pf->field = V4L2_FIELD_INTERLACED;
3284 break; 3151 pf->bytesperline = tempvcs.line_size;
3285 } 3152 pf->sizeimage = tempvcs.line_size *
3286 case V4L2_BUF_TYPE_VIDEO_OVERLAY: 3153 (tempvcs.clipping.bottom - tempvcs.clipping.top) /
3287 default: 3154 tempvcs.decimation;
3288 return -EINVAL; 3155 pf->colorspace =
3289 } 3156 vino_data_formats[tempvcs.data_format].colorspace;
3290 3157
3158 pf->priv = 0;
3291 return 0; 3159 return 0;
3292} 3160}
3293 3161
3294static int vino_v4l2_g_fmt(struct vino_channel_settings *vcs, 3162static int vino_g_fmt_vid_cap(struct file *file, void *__fh,
3295 struct v4l2_format *f) 3163 struct v4l2_format *f)
3296{ 3164{
3165 struct vino_channel_settings *vcs = video_drvdata(file);
3297 unsigned long flags; 3166 unsigned long flags;
3167 struct v4l2_pix_format *pf = &f->fmt.pix;
3298 3168
3299 switch (f->type) { 3169 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3300 case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
3301 struct v4l2_pix_format *pf = &f->fmt.pix;
3302
3303 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3304
3305 pf->width = (vcs->clipping.right - vcs->clipping.left) /
3306 vcs->decimation;
3307 pf->height = (vcs->clipping.bottom - vcs->clipping.top) /
3308 vcs->decimation;
3309 pf->pixelformat =
3310 vino_data_formats[vcs->data_format].pixelformat;
3311 3170
3312 pf->field = V4L2_FIELD_INTERLACED; 3171 pf->width = (vcs->clipping.right - vcs->clipping.left) /
3313 pf->bytesperline = vcs->line_size; 3172 vcs->decimation;
3314 pf->sizeimage = vcs->line_size * 3173 pf->height = (vcs->clipping.bottom - vcs->clipping.top) /
3315 (vcs->clipping.bottom - vcs->clipping.top) / 3174 vcs->decimation;
3316 vcs->decimation; 3175 pf->pixelformat =
3317 pf->colorspace = 3176 vino_data_formats[vcs->data_format].pixelformat;
3318 vino_data_formats[vcs->data_format].colorspace;
3319 3177
3320 pf->priv = 0; 3178 pf->field = V4L2_FIELD_INTERLACED;
3179 pf->bytesperline = vcs->line_size;
3180 pf->sizeimage = vcs->line_size *
3181 (vcs->clipping.bottom - vcs->clipping.top) /
3182 vcs->decimation;
3183 pf->colorspace =
3184 vino_data_formats[vcs->data_format].colorspace;
3321 3185
3322 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags); 3186 pf->priv = 0;
3323 break;
3324 }
3325 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
3326 default:
3327 return -EINVAL;
3328 }
3329 3187
3188 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3330 return 0; 3189 return 0;
3331} 3190}
3332 3191
3333static int vino_v4l2_s_fmt(struct vino_channel_settings *vcs, 3192static int vino_s_fmt_vid_cap(struct file *file, void *__fh,
3334 struct v4l2_format *f) 3193 struct v4l2_format *f)
3335{ 3194{
3195 struct vino_channel_settings *vcs = video_drvdata(file);
3336 int data_format; 3196 int data_format;
3337 unsigned long flags; 3197 unsigned long flags;
3198 struct v4l2_pix_format *pf = &f->fmt.pix;
3338 3199
3339 switch (f->type) { 3200 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3340 case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
3341 struct v4l2_pix_format *pf = &f->fmt.pix;
3342
3343 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3344 3201
3345 data_format = vino_find_data_format(pf->pixelformat); 3202 data_format = vino_find_data_format(pf->pixelformat);
3346 3203
3347 if (data_format == VINO_DATA_FMT_NONE) { 3204 if (data_format == VINO_DATA_FMT_NONE) {
3348 vcs->data_format = VINO_DATA_FMT_GREY; 3205 vcs->data_format = VINO_DATA_FMT_GREY;
3349 pf->pixelformat = 3206 pf->pixelformat =
3350 vino_data_formats[vcs->data_format]. 3207 vino_data_formats[vcs->data_format].
3351 pixelformat; 3208 pixelformat;
3352 } else { 3209 } else {
3353 vcs->data_format = data_format; 3210 vcs->data_format = data_format;
3354 } 3211 }
3355 3212
3356 /* data format must be set before clipping/scaling */ 3213 /* data format must be set before clipping/scaling */
3357 vino_set_scaling(vcs, pf->width, pf->height); 3214 vino_set_scaling(vcs, pf->width, pf->height);
3358 3215
3359 dprintk("data format = %s\n", 3216 dprintk("data format = %s\n",
3360 vino_data_formats[vcs->data_format].description); 3217 vino_data_formats[vcs->data_format].description);
3361 3218
3362 pf->width = vcs->clipping.right - vcs->clipping.left; 3219 pf->width = vcs->clipping.right - vcs->clipping.left;
3363 pf->height = vcs->clipping.bottom - vcs->clipping.top; 3220 pf->height = vcs->clipping.bottom - vcs->clipping.top;
3364 3221
3365 pf->field = V4L2_FIELD_INTERLACED; 3222 pf->field = V4L2_FIELD_INTERLACED;
3366 pf->bytesperline = vcs->line_size; 3223 pf->bytesperline = vcs->line_size;
3367 pf->sizeimage = vcs->line_size * 3224 pf->sizeimage = vcs->line_size *
3368 (vcs->clipping.bottom - vcs->clipping.top) / 3225 (vcs->clipping.bottom - vcs->clipping.top) /
3369 vcs->decimation; 3226 vcs->decimation;
3370 pf->colorspace = 3227 pf->colorspace =
3371 vino_data_formats[vcs->data_format].colorspace; 3228 vino_data_formats[vcs->data_format].colorspace;
3372 3229
3373 pf->priv = 0; 3230 pf->priv = 0;
3374
3375 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3376 break;
3377 }
3378 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
3379 default:
3380 return -EINVAL;
3381 }
3382 3231
3232 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3383 return 0; 3233 return 0;
3384} 3234}
3385 3235
3386static int vino_v4l2_cropcap(struct vino_channel_settings *vcs, 3236static int vino_cropcap(struct file *file, void *__fh,
3387 struct v4l2_cropcap *ccap) 3237 struct v4l2_cropcap *ccap)
3388{ 3238{
3239 struct vino_channel_settings *vcs = video_drvdata(file);
3389 const struct vino_data_norm *norm; 3240 const struct vino_data_norm *norm;
3390 unsigned long flags; 3241 unsigned long flags;
3391 3242
@@ -3415,9 +3266,10 @@ static int vino_v4l2_cropcap(struct vino_channel_settings *vcs,
3415 return 0; 3266 return 0;
3416} 3267}
3417 3268
3418static int vino_v4l2_g_crop(struct vino_channel_settings *vcs, 3269static int vino_g_crop(struct file *file, void *__fh,
3419 struct v4l2_crop *c) 3270 struct v4l2_crop *c)
3420{ 3271{
3272 struct vino_channel_settings *vcs = video_drvdata(file);
3421 unsigned long flags; 3273 unsigned long flags;
3422 3274
3423 switch (c->type) { 3275 switch (c->type) {
@@ -3439,9 +3291,10 @@ static int vino_v4l2_g_crop(struct vino_channel_settings *vcs,
3439 return 0; 3291 return 0;
3440} 3292}
3441 3293
3442static int vino_v4l2_s_crop(struct vino_channel_settings *vcs, 3294static int vino_s_crop(struct file *file, void *__fh,
3443 struct v4l2_crop *c) 3295 struct v4l2_crop *c)
3444{ 3296{
3297 struct vino_channel_settings *vcs = video_drvdata(file);
3445 unsigned long flags; 3298 unsigned long flags;
3446 3299
3447 switch (c->type) { 3300 switch (c->type) {
@@ -3461,108 +3314,83 @@ static int vino_v4l2_s_crop(struct vino_channel_settings *vcs,
3461 return 0; 3314 return 0;
3462} 3315}
3463 3316
3464static int vino_v4l2_g_parm(struct vino_channel_settings *vcs, 3317static int vino_g_parm(struct file *file, void *__fh,
3465 struct v4l2_streamparm *sp) 3318 struct v4l2_streamparm *sp)
3466{ 3319{
3320 struct vino_channel_settings *vcs = video_drvdata(file);
3467 unsigned long flags; 3321 unsigned long flags;
3322 struct v4l2_captureparm *cp = &sp->parm.capture;
3468 3323
3469 switch (sp->type) { 3324 cp->capability = V4L2_CAP_TIMEPERFRAME;
3470 case V4L2_BUF_TYPE_VIDEO_CAPTURE: { 3325 cp->timeperframe.numerator = 1;
3471 struct v4l2_captureparm *cp = &sp->parm.capture;
3472 memset(cp, 0, sizeof(struct v4l2_captureparm));
3473 3326
3474 cp->capability = V4L2_CAP_TIMEPERFRAME; 3327 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3475 cp->timeperframe.numerator = 1;
3476 3328
3477 spin_lock_irqsave(&vino_drvdata->input_lock, flags); 3329 cp->timeperframe.denominator = vcs->fps;
3478 3330
3479 cp->timeperframe.denominator = vcs->fps; 3331 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3480 3332
3481 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags); 3333 /* TODO: cp->readbuffers = xxx; */
3482
3483 // TODO: cp->readbuffers = xxx;
3484 break;
3485 }
3486 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
3487 default:
3488 return -EINVAL;
3489 }
3490 3334
3491 return 0; 3335 return 0;
3492} 3336}
3493 3337
3494static int vino_v4l2_s_parm(struct vino_channel_settings *vcs, 3338static int vino_s_parm(struct file *file, void *__fh,
3495 struct v4l2_streamparm *sp) 3339 struct v4l2_streamparm *sp)
3496{ 3340{
3341 struct vino_channel_settings *vcs = video_drvdata(file);
3497 unsigned long flags; 3342 unsigned long flags;
3343 struct v4l2_captureparm *cp = &sp->parm.capture;
3498 3344
3499 switch (sp->type) { 3345 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3500 case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
3501 struct v4l2_captureparm *cp = &sp->parm.capture;
3502
3503 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3504
3505 if ((cp->timeperframe.numerator == 0) ||
3506 (cp->timeperframe.denominator == 0)) {
3507 /* reset framerate */
3508 vino_set_default_framerate(vcs);
3509 } else {
3510 vino_set_framerate(vcs, cp->timeperframe.denominator /
3511 cp->timeperframe.numerator);
3512 }
3513
3514 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3515 3346
3516 // TODO: set buffers according to cp->readbuffers 3347 if ((cp->timeperframe.numerator == 0) ||
3517 break; 3348 (cp->timeperframe.denominator == 0)) {
3518 } 3349 /* reset framerate */
3519 case V4L2_BUF_TYPE_VIDEO_OVERLAY: 3350 vino_set_default_framerate(vcs);
3520 default: 3351 } else {
3521 return -EINVAL; 3352 vino_set_framerate(vcs, cp->timeperframe.denominator /
3353 cp->timeperframe.numerator);
3522 } 3354 }
3523 3355
3356 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3357
3524 return 0; 3358 return 0;
3525} 3359}
3526 3360
3527static int vino_v4l2_reqbufs(struct vino_channel_settings *vcs, 3361static int vino_reqbufs(struct file *file, void *__fh,
3528 struct v4l2_requestbuffers *rb) 3362 struct v4l2_requestbuffers *rb)
3529{ 3363{
3364 struct vino_channel_settings *vcs = video_drvdata(file);
3365
3530 if (vcs->reading) 3366 if (vcs->reading)
3531 return -EBUSY; 3367 return -EBUSY;
3532 3368
3533 switch (rb->type) { 3369 /* TODO: check queue type */
3534 case V4L2_BUF_TYPE_VIDEO_CAPTURE: { 3370 if (rb->memory != V4L2_MEMORY_MMAP) {
3535 // TODO: check queue type 3371 dprintk("type not mmap\n");
3536 if (rb->memory != V4L2_MEMORY_MMAP) { 3372 return -EINVAL;
3537 dprintk("type not mmap\n"); 3373 }
3538 return -EINVAL;
3539 }
3540 3374
3541 dprintk("count = %d\n", rb->count); 3375 dprintk("count = %d\n", rb->count);
3542 if (rb->count > 0) { 3376 if (rb->count > 0) {
3543 if (vino_is_capturing(vcs)) { 3377 if (vino_is_capturing(vcs)) {
3544 dprintk("busy, capturing\n"); 3378 dprintk("busy, capturing\n");
3545 return -EBUSY; 3379 return -EBUSY;
3546 } 3380 }
3547 3381
3548 if (vino_queue_has_mapped_buffers(&vcs->fb_queue)) { 3382 if (vino_queue_has_mapped_buffers(&vcs->fb_queue)) {
3549 dprintk("busy, buffers still mapped\n"); 3383 dprintk("busy, buffers still mapped\n");
3550 return -EBUSY; 3384 return -EBUSY;
3551 } else {
3552 vcs->streaming = 0;
3553 vino_queue_free(&vcs->fb_queue);
3554 vino_queue_init(&vcs->fb_queue, &rb->count);
3555 }
3556 } else { 3385 } else {
3557 vcs->streaming = 0; 3386 vcs->streaming = 0;
3558 vino_capture_stop(vcs);
3559 vino_queue_free(&vcs->fb_queue); 3387 vino_queue_free(&vcs->fb_queue);
3388 vino_queue_init(&vcs->fb_queue, &rb->count);
3560 } 3389 }
3561 break; 3390 } else {
3562 } 3391 vcs->streaming = 0;
3563 case V4L2_BUF_TYPE_VIDEO_OVERLAY: 3392 vino_capture_stop(vcs);
3564 default: 3393 vino_queue_free(&vcs->fb_queue);
3565 return -EINVAL;
3566 } 3394 }
3567 3395
3568 return 0; 3396 return 0;
@@ -3606,156 +3434,135 @@ static void vino_v4l2_get_buffer_status(struct vino_channel_settings *vcs,
3606 fb->id, fb->size, fb->data_size, fb->offset); 3434 fb->id, fb->size, fb->data_size, fb->offset);
3607} 3435}
3608 3436
3609static int vino_v4l2_querybuf(struct vino_channel_settings *vcs, 3437static int vino_querybuf(struct file *file, void *__fh,
3610 struct v4l2_buffer *b) 3438 struct v4l2_buffer *b)
3611{ 3439{
3440 struct vino_channel_settings *vcs = video_drvdata(file);
3441 struct vino_framebuffer *fb;
3442
3612 if (vcs->reading) 3443 if (vcs->reading)
3613 return -EBUSY; 3444 return -EBUSY;
3614 3445
3615 switch (b->type) { 3446 /* TODO: check queue type */
3616 case V4L2_BUF_TYPE_VIDEO_CAPTURE: { 3447 if (b->index >= vino_queue_get_length(&vcs->fb_queue)) {
3617 struct vino_framebuffer *fb; 3448 dprintk("invalid index = %d\n",
3618 3449 b->index);
3619 // TODO: check queue type 3450 return -EINVAL;
3620 if (b->index >= vino_queue_get_length(&vcs->fb_queue)) {
3621 dprintk("invalid index = %d\n",
3622 b->index);
3623 return -EINVAL;
3624 }
3625
3626 fb = vino_queue_get_buffer(&vcs->fb_queue,
3627 b->index);
3628 if (fb == NULL) {
3629 dprintk("vino_queue_get_buffer() failed");
3630 return -EINVAL;
3631 }
3632
3633 vino_v4l2_get_buffer_status(vcs, fb, b);
3634 break;
3635 } 3451 }
3636 case V4L2_BUF_TYPE_VIDEO_OVERLAY: 3452
3637 default: 3453 fb = vino_queue_get_buffer(&vcs->fb_queue,
3454 b->index);
3455 if (fb == NULL) {
3456 dprintk("vino_queue_get_buffer() failed");
3638 return -EINVAL; 3457 return -EINVAL;
3639 } 3458 }
3640 3459
3460 vino_v4l2_get_buffer_status(vcs, fb, b);
3461
3641 return 0; 3462 return 0;
3642} 3463}
3643 3464
3644static int vino_v4l2_qbuf(struct vino_channel_settings *vcs, 3465static int vino_qbuf(struct file *file, void *__fh,
3645 struct v4l2_buffer *b) 3466 struct v4l2_buffer *b)
3646{ 3467{
3468 struct vino_channel_settings *vcs = video_drvdata(file);
3469 struct vino_framebuffer *fb;
3470 int ret;
3471
3647 if (vcs->reading) 3472 if (vcs->reading)
3648 return -EBUSY; 3473 return -EBUSY;
3649 3474
3650 switch (b->type) { 3475 /* TODO: check queue type */
3651 case V4L2_BUF_TYPE_VIDEO_CAPTURE: { 3476 if (b->memory != V4L2_MEMORY_MMAP) {
3652 struct vino_framebuffer *fb; 3477 dprintk("type not mmap\n");
3653 int ret; 3478 return -EINVAL;
3654 3479 }
3655 // TODO: check queue type
3656 if (b->memory != V4L2_MEMORY_MMAP) {
3657 dprintk("type not mmap\n");
3658 return -EINVAL;
3659 }
3660 3480
3661 fb = vino_capture_enqueue(vcs, b->index); 3481 fb = vino_capture_enqueue(vcs, b->index);
3662 if (fb == NULL) 3482 if (fb == NULL)
3663 return -EINVAL; 3483 return -EINVAL;
3664 3484
3665 vino_v4l2_get_buffer_status(vcs, fb, b); 3485 vino_v4l2_get_buffer_status(vcs, fb, b);
3666 3486
3667 if (vcs->streaming) { 3487 if (vcs->streaming) {
3668 ret = vino_capture_next(vcs, 1); 3488 ret = vino_capture_next(vcs, 1);
3669 if (ret) 3489 if (ret)
3670 return ret; 3490 return ret;
3671 }
3672 break;
3673 }
3674 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
3675 default:
3676 return -EINVAL;
3677 } 3491 }
3678 3492
3679 return 0; 3493 return 0;
3680} 3494}
3681 3495
3682static int vino_v4l2_dqbuf(struct vino_channel_settings *vcs, 3496static int vino_dqbuf(struct file *file, void *__fh,
3683 struct v4l2_buffer *b, 3497 struct v4l2_buffer *b)
3684 unsigned int nonblocking)
3685{ 3498{
3499 struct vino_channel_settings *vcs = video_drvdata(file);
3500 unsigned int nonblocking = file->f_flags & O_NONBLOCK;
3501 struct vino_framebuffer *fb;
3502 unsigned int incoming, outgoing;
3503 int err;
3504
3686 if (vcs->reading) 3505 if (vcs->reading)
3687 return -EBUSY; 3506 return -EBUSY;
3688 3507
3689 switch (b->type) { 3508 /* TODO: check queue type */
3690 case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
3691 struct vino_framebuffer *fb;
3692 unsigned int incoming, outgoing;
3693 int err;
3694 3509
3695 // TODO: check queue type 3510 err = vino_queue_get_incoming(&vcs->fb_queue, &incoming);
3511 if (err) {
3512 dprintk("vino_queue_get_incoming() failed\n");
3513 return -EINVAL;
3514 }
3515 err = vino_queue_get_outgoing(&vcs->fb_queue, &outgoing);
3516 if (err) {
3517 dprintk("vino_queue_get_outgoing() failed\n");
3518 return -EINVAL;
3519 }
3696 3520
3697 err = vino_queue_get_incoming(&vcs->fb_queue, &incoming); 3521 dprintk("incoming = %d, outgoing = %d\n", incoming, outgoing);
3698 if (err) { 3522
3699 dprintk("vino_queue_get_incoming() failed\n"); 3523 if (outgoing == 0) {
3524 if (incoming == 0) {
3525 dprintk("no incoming or outgoing buffers\n");
3700 return -EINVAL; 3526 return -EINVAL;
3701 } 3527 }
3702 err = vino_queue_get_outgoing(&vcs->fb_queue, &outgoing); 3528 if (nonblocking) {
3703 if (err) { 3529 dprintk("non-blocking I/O was selected and "
3704 dprintk("vino_queue_get_outgoing() failed\n"); 3530 "there are no buffers to dequeue\n");
3705 return -EINVAL; 3531 return -EAGAIN;
3706 } 3532 }
3707 3533
3708 dprintk("incoming = %d, outgoing = %d\n", incoming, outgoing); 3534 err = vino_wait_for_frame(vcs);
3709 3535 if (err) {
3710 if (outgoing == 0) {
3711 if (incoming == 0) {
3712 dprintk("no incoming or outgoing buffers\n");
3713 return -EINVAL;
3714 }
3715 if (nonblocking) {
3716 dprintk("non-blocking I/O was selected and "
3717 "there are no buffers to dequeue\n");
3718 return -EAGAIN;
3719 }
3720
3721 err = vino_wait_for_frame(vcs); 3536 err = vino_wait_for_frame(vcs);
3722 if (err) { 3537 if (err) {
3723 err = vino_wait_for_frame(vcs); 3538 /* interrupted or no frames captured because of
3724 if (err) { 3539 * frame skipping */
3725 /* interrupted or 3540 /* vino_capture_failed(vcs); */
3726 * no frames captured because 3541 return -EIO;
3727 * of frame skipping */
3728 // vino_capture_failed(vcs);
3729 return -EIO;
3730 }
3731 } 3542 }
3732 } 3543 }
3544 }
3733 3545
3734 fb = vino_queue_remove(&vcs->fb_queue, &b->index); 3546 fb = vino_queue_remove(&vcs->fb_queue, &b->index);
3735 if (fb == NULL) { 3547 if (fb == NULL) {
3736 dprintk("vino_queue_remove() failed\n"); 3548 dprintk("vino_queue_remove() failed\n");
3737 return -EINVAL; 3549 return -EINVAL;
3738 } 3550 }
3739
3740 err = vino_check_buffer(vcs, fb);
3741 3551
3742 vino_v4l2_get_buffer_status(vcs, fb, b); 3552 err = vino_check_buffer(vcs, fb);
3743 3553
3744 if (err) 3554 vino_v4l2_get_buffer_status(vcs, fb, b);
3745 return -EIO;
3746 3555
3747 break; 3556 if (err)
3748 } 3557 return -EIO;
3749 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
3750 default:
3751 return -EINVAL;
3752 }
3753 3558
3754 return 0; 3559 return 0;
3755} 3560}
3756 3561
3757static int vino_v4l2_streamon(struct vino_channel_settings *vcs) 3562static int vino_streamon(struct file *file, void *__fh,
3563 enum v4l2_buf_type i)
3758{ 3564{
3565 struct vino_channel_settings *vcs = video_drvdata(file);
3759 unsigned int incoming; 3566 unsigned int incoming;
3760 int ret; 3567 int ret;
3761 if (vcs->reading) 3568 if (vcs->reading)
@@ -3792,8 +3599,10 @@ static int vino_v4l2_streamon(struct vino_channel_settings *vcs)
3792 return 0; 3599 return 0;
3793} 3600}
3794 3601
3795static int vino_v4l2_streamoff(struct vino_channel_settings *vcs) 3602static int vino_streamoff(struct file *file, void *__fh,
3603 enum v4l2_buf_type i)
3796{ 3604{
3605 struct vino_channel_settings *vcs = video_drvdata(file);
3797 if (vcs->reading) 3606 if (vcs->reading)
3798 return -EBUSY; 3607 return -EBUSY;
3799 3608
@@ -3806,9 +3615,10 @@ static int vino_v4l2_streamoff(struct vino_channel_settings *vcs)
3806 return 0; 3615 return 0;
3807} 3616}
3808 3617
3809static int vino_v4l2_queryctrl(struct vino_channel_settings *vcs, 3618static int vino_queryctrl(struct file *file, void *__fh,
3810 struct v4l2_queryctrl *queryctrl) 3619 struct v4l2_queryctrl *queryctrl)
3811{ 3620{
3621 struct vino_channel_settings *vcs = video_drvdata(file);
3812 unsigned long flags; 3622 unsigned long flags;
3813 int i; 3623 int i;
3814 int err = 0; 3624 int err = 0;
@@ -3855,9 +3665,10 @@ static int vino_v4l2_queryctrl(struct vino_channel_settings *vcs,
3855 return err; 3665 return err;
3856} 3666}
3857 3667
3858static int vino_v4l2_g_ctrl(struct vino_channel_settings *vcs, 3668static int vino_g_ctrl(struct file *file, void *__fh,
3859 struct v4l2_control *control) 3669 struct v4l2_control *control)
3860{ 3670{
3671 struct vino_channel_settings *vcs = video_drvdata(file);
3861 unsigned long flags; 3672 unsigned long flags;
3862 int i; 3673 int i;
3863 int err = 0; 3674 int err = 0;
@@ -3866,56 +3677,38 @@ static int vino_v4l2_g_ctrl(struct vino_channel_settings *vcs,
3866 3677
3867 switch (vcs->input) { 3678 switch (vcs->input) {
3868 case VINO_INPUT_D1: { 3679 case VINO_INPUT_D1: {
3869 struct indycam_control indycam_ctrl; 3680 err = -EINVAL;
3870
3871 for (i = 0; i < VINO_INDYCAM_V4L2_CONTROL_COUNT; i++) { 3681 for (i = 0; i < VINO_INDYCAM_V4L2_CONTROL_COUNT; i++) {
3872 if (vino_indycam_v4l2_controls[i].id == 3682 if (vino_indycam_v4l2_controls[i].id == control->id) {
3873 control->id) { 3683 err = 0;
3874 goto found1; 3684 break;
3875 } 3685 }
3876 } 3686 }
3877 3687
3878 err = -EINVAL; 3688 if (err)
3879 goto out;
3880
3881found1:
3882 indycam_ctrl.type = vino_indycam_v4l2_controls[i].reserved[0];
3883
3884 err = i2c_camera_command(DECODER_INDYCAM_GET_CONTROL,
3885 &indycam_ctrl);
3886 if (err) {
3887 err = -EINVAL;
3888 goto out; 3689 goto out;
3889 }
3890 3690
3891 control->value = indycam_ctrl.value; 3691 err = camera_call(core, g_ctrl, control);
3692 if (err)
3693 err = -EINVAL;
3892 break; 3694 break;
3893 } 3695 }
3894 case VINO_INPUT_COMPOSITE: 3696 case VINO_INPUT_COMPOSITE:
3895 case VINO_INPUT_SVIDEO: { 3697 case VINO_INPUT_SVIDEO: {
3896 struct saa7191_control saa7191_ctrl; 3698 err = -EINVAL;
3897
3898 for (i = 0; i < VINO_SAA7191_V4L2_CONTROL_COUNT; i++) { 3699 for (i = 0; i < VINO_SAA7191_V4L2_CONTROL_COUNT; i++) {
3899 if (vino_saa7191_v4l2_controls[i].id == 3700 if (vino_saa7191_v4l2_controls[i].id == control->id) {
3900 control->id) { 3701 err = 0;
3901 goto found2; 3702 break;
3902 } 3703 }
3903 } 3704 }
3904 3705
3905 err = -EINVAL; 3706 if (err)
3906 goto out;
3907
3908found2:
3909 saa7191_ctrl.type = vino_saa7191_v4l2_controls[i].reserved[0];
3910
3911 err = i2c_decoder_command(DECODER_SAA7191_GET_CONTROL,
3912 &saa7191_ctrl);
3913 if (err) {
3914 err = -EINVAL;
3915 goto out; 3707 goto out;
3916 }
3917 3708
3918 control->value = saa7191_ctrl.value; 3709 err = decoder_call(core, g_ctrl, control);
3710 if (err)
3711 err = -EINVAL;
3919 break; 3712 break;
3920 } 3713 }
3921 default: 3714 default:
@@ -3928,9 +3721,10 @@ out:
3928 return err; 3721 return err;
3929} 3722}
3930 3723
3931static int vino_v4l2_s_ctrl(struct vino_channel_settings *vcs, 3724static int vino_s_ctrl(struct file *file, void *__fh,
3932 struct v4l2_control *control) 3725 struct v4l2_control *control)
3933{ 3726{
3727 struct vino_channel_settings *vcs = video_drvdata(file);
3934 unsigned long flags; 3728 unsigned long flags;
3935 int i; 3729 int i;
3936 int err = 0; 3730 int err = 0;
@@ -3944,65 +3738,43 @@ static int vino_v4l2_s_ctrl(struct vino_channel_settings *vcs,
3944 3738
3945 switch (vcs->input) { 3739 switch (vcs->input) {
3946 case VINO_INPUT_D1: { 3740 case VINO_INPUT_D1: {
3947 struct indycam_control indycam_ctrl; 3741 err = -EINVAL;
3948
3949 for (i = 0; i < VINO_INDYCAM_V4L2_CONTROL_COUNT; i++) { 3742 for (i = 0; i < VINO_INDYCAM_V4L2_CONTROL_COUNT; i++) {
3950 if (vino_indycam_v4l2_controls[i].id == 3743 if (vino_indycam_v4l2_controls[i].id == control->id) {
3951 control->id) { 3744 err = 0;
3952 if ((control->value >= 3745 break;
3953 vino_indycam_v4l2_controls[i].minimum)
3954 && (control->value <=
3955 vino_indycam_v4l2_controls[i].
3956 maximum)) {
3957 goto found1;
3958 } else {
3959 err = -ERANGE;
3960 goto out;
3961 }
3962 } 3746 }
3963 } 3747 }
3964 3748 if (err)
3965 err = -EINVAL; 3749 goto out;
3966 goto out; 3750 if (control->value < vino_indycam_v4l2_controls[i].minimum ||
3967 3751 control->value > vino_indycam_v4l2_controls[i].maximum) {
3968found1: 3752 err = -ERANGE;
3969 indycam_ctrl.type = vino_indycam_v4l2_controls[i].reserved[0]; 3753 goto out;
3970 indycam_ctrl.value = control->value; 3754 }
3971 3755 err = camera_call(core, s_ctrl, control);
3972 err = i2c_camera_command(DECODER_INDYCAM_SET_CONTROL,
3973 &indycam_ctrl);
3974 if (err) 3756 if (err)
3975 err = -EINVAL; 3757 err = -EINVAL;
3976 break; 3758 break;
3977 } 3759 }
3978 case VINO_INPUT_COMPOSITE: 3760 case VINO_INPUT_COMPOSITE:
3979 case VINO_INPUT_SVIDEO: { 3761 case VINO_INPUT_SVIDEO: {
3980 struct saa7191_control saa7191_ctrl; 3762 err = -EINVAL;
3981
3982 for (i = 0; i < VINO_SAA7191_V4L2_CONTROL_COUNT; i++) { 3763 for (i = 0; i < VINO_SAA7191_V4L2_CONTROL_COUNT; i++) {
3983 if (vino_saa7191_v4l2_controls[i].id == 3764 if (vino_saa7191_v4l2_controls[i].id == control->id) {
3984 control->id) { 3765 err = 0;
3985 if ((control->value >= 3766 break;
3986 vino_saa7191_v4l2_controls[i].minimum)
3987 && (control->value <=
3988 vino_saa7191_v4l2_controls[i].
3989 maximum)) {
3990 goto found2;
3991 } else {
3992 err = -ERANGE;
3993 goto out;
3994 }
3995 } 3767 }
3996 } 3768 }
3997 err = -EINVAL; 3769 if (err)
3998 goto out; 3770 goto out;
3999 3771 if (control->value < vino_saa7191_v4l2_controls[i].minimum ||
4000found2: 3772 control->value > vino_saa7191_v4l2_controls[i].maximum) {
4001 saa7191_ctrl.type = vino_saa7191_v4l2_controls[i].reserved[0]; 3773 err = -ERANGE;
4002 saa7191_ctrl.value = control->value; 3774 goto out;
3775 }
4003 3776
4004 err = i2c_decoder_command(DECODER_SAA7191_SET_CONTROL, 3777 err = decoder_call(core, s_ctrl, control);
4005 &saa7191_ctrl);
4006 if (err) 3778 if (err)
4007 err = -EINVAL; 3779 err = -EINVAL;
4008 break; 3780 break;
@@ -4233,116 +4005,9 @@ over:
4233 ret = POLLIN | POLLRDNORM; 4005 ret = POLLIN | POLLRDNORM;
4234 4006
4235error: 4007error:
4236
4237 return ret; 4008 return ret;
4238} 4009}
4239 4010
4240static long vino_do_ioctl(struct file *file, unsigned int cmd, void *arg)
4241{
4242 struct vino_channel_settings *vcs = video_drvdata(file);
4243
4244#ifdef VINO_DEBUG
4245 switch (_IOC_TYPE(cmd)) {
4246 case 'v':
4247 dprintk("ioctl(): V4L1 unsupported (0x%08x)\n", cmd);
4248 break;
4249 case 'V':
4250 dprintk("ioctl(): V4L2 %s (0x%08x)\n",
4251 v4l2_ioctl_names[_IOC_NR(cmd)], cmd);
4252 break;
4253 default:
4254 dprintk("ioctl(): unsupported command 0x%08x\n", cmd);
4255 }
4256#endif
4257
4258 switch (cmd) {
4259 /* V4L2 interface */
4260 case VIDIOC_QUERYCAP: {
4261 vino_v4l2_querycap(arg);
4262 break;
4263 }
4264 case VIDIOC_ENUMINPUT: {
4265 return vino_v4l2_enuminput(vcs, arg);
4266 }
4267 case VIDIOC_G_INPUT: {
4268 return vino_v4l2_g_input(vcs, arg);
4269 }
4270 case VIDIOC_S_INPUT: {
4271 return vino_v4l2_s_input(vcs, arg);
4272 }
4273 case VIDIOC_ENUMSTD: {
4274 return vino_v4l2_enumstd(vcs, arg);
4275 }
4276 case VIDIOC_QUERYSTD: {
4277 return vino_v4l2_querystd(vcs, arg);
4278 }
4279 case VIDIOC_G_STD: {
4280 return vino_v4l2_g_std(vcs, arg);
4281 }
4282 case VIDIOC_S_STD: {
4283 return vino_v4l2_s_std(vcs, arg);
4284 }
4285 case VIDIOC_ENUM_FMT: {
4286 return vino_v4l2_enum_fmt(vcs, arg);
4287 }
4288 case VIDIOC_TRY_FMT: {
4289 return vino_v4l2_try_fmt(vcs, arg);
4290 }
4291 case VIDIOC_G_FMT: {
4292 return vino_v4l2_g_fmt(vcs, arg);
4293 }
4294 case VIDIOC_S_FMT: {
4295 return vino_v4l2_s_fmt(vcs, arg);
4296 }
4297 case VIDIOC_CROPCAP: {
4298 return vino_v4l2_cropcap(vcs, arg);
4299 }
4300 case VIDIOC_G_CROP: {
4301 return vino_v4l2_g_crop(vcs, arg);
4302 }
4303 case VIDIOC_S_CROP: {
4304 return vino_v4l2_s_crop(vcs, arg);
4305 }
4306 case VIDIOC_G_PARM: {
4307 return vino_v4l2_g_parm(vcs, arg);
4308 }
4309 case VIDIOC_S_PARM: {
4310 return vino_v4l2_s_parm(vcs, arg);
4311 }
4312 case VIDIOC_REQBUFS: {
4313 return vino_v4l2_reqbufs(vcs, arg);
4314 }
4315 case VIDIOC_QUERYBUF: {
4316 return vino_v4l2_querybuf(vcs, arg);
4317 }
4318 case VIDIOC_QBUF: {
4319 return vino_v4l2_qbuf(vcs, arg);
4320 }
4321 case VIDIOC_DQBUF: {
4322 return vino_v4l2_dqbuf(vcs, arg, file->f_flags & O_NONBLOCK);
4323 }
4324 case VIDIOC_STREAMON: {
4325 return vino_v4l2_streamon(vcs);
4326 }
4327 case VIDIOC_STREAMOFF: {
4328 return vino_v4l2_streamoff(vcs);
4329 }
4330 case VIDIOC_QUERYCTRL: {
4331 return vino_v4l2_queryctrl(vcs, arg);
4332 }
4333 case VIDIOC_G_CTRL: {
4334 return vino_v4l2_g_ctrl(vcs, arg);
4335 }
4336 case VIDIOC_S_CTRL: {
4337 return vino_v4l2_s_ctrl(vcs, arg);
4338 }
4339 default:
4340 return -ENOIOCTLCMD;
4341 }
4342
4343 return 0;
4344}
4345
4346static long vino_ioctl(struct file *file, 4011static long vino_ioctl(struct file *file,
4347 unsigned int cmd, unsigned long arg) 4012 unsigned int cmd, unsigned long arg)
4348{ 4013{
@@ -4352,7 +4017,7 @@ static long vino_ioctl(struct file *file,
4352 if (mutex_lock_interruptible(&vcs->mutex)) 4017 if (mutex_lock_interruptible(&vcs->mutex))
4353 return -EINTR; 4018 return -EINTR;
4354 4019
4355 ret = video_usercopy(file, cmd, arg, vino_do_ioctl); 4020 ret = video_ioctl2(file, cmd, arg);
4356 4021
4357 mutex_unlock(&vcs->mutex); 4022 mutex_unlock(&vcs->mutex);
4358 4023
@@ -4364,45 +4029,75 @@ static long vino_ioctl(struct file *file,
4364/* __initdata */ 4029/* __initdata */
4365static int vino_init_stage; 4030static int vino_init_stage;
4366 4031
4032const struct v4l2_ioctl_ops vino_ioctl_ops = {
4033 .vidioc_enum_fmt_vid_cap = vino_enum_fmt_vid_cap,
4034 .vidioc_g_fmt_vid_cap = vino_g_fmt_vid_cap,
4035 .vidioc_s_fmt_vid_cap = vino_s_fmt_vid_cap,
4036 .vidioc_try_fmt_vid_cap = vino_try_fmt_vid_cap,
4037 .vidioc_querycap = vino_querycap,
4038 .vidioc_enum_input = vino_enum_input,
4039 .vidioc_g_input = vino_g_input,
4040 .vidioc_s_input = vino_s_input,
4041 .vidioc_g_std = vino_g_std,
4042 .vidioc_s_std = vino_s_std,
4043 .vidioc_querystd = vino_querystd,
4044 .vidioc_cropcap = vino_cropcap,
4045 .vidioc_s_crop = vino_s_crop,
4046 .vidioc_g_crop = vino_g_crop,
4047 .vidioc_s_parm = vino_s_parm,
4048 .vidioc_g_parm = vino_g_parm,
4049 .vidioc_reqbufs = vino_reqbufs,
4050 .vidioc_querybuf = vino_querybuf,
4051 .vidioc_qbuf = vino_qbuf,
4052 .vidioc_dqbuf = vino_dqbuf,
4053 .vidioc_streamon = vino_streamon,
4054 .vidioc_streamoff = vino_streamoff,
4055 .vidioc_queryctrl = vino_queryctrl,
4056 .vidioc_g_ctrl = vino_g_ctrl,
4057 .vidioc_s_ctrl = vino_s_ctrl,
4058};
4059
4367static const struct v4l2_file_operations vino_fops = { 4060static const struct v4l2_file_operations vino_fops = {
4368 .owner = THIS_MODULE, 4061 .owner = THIS_MODULE,
4369 .open = vino_open, 4062 .open = vino_open,
4370 .release = vino_close, 4063 .release = vino_close,
4371 .ioctl = vino_ioctl, 4064 .unlocked_ioctl = vino_ioctl,
4372 .mmap = vino_mmap, 4065 .mmap = vino_mmap,
4373 .poll = vino_poll, 4066 .poll = vino_poll,
4374}; 4067};
4375 4068
4376static struct video_device v4l_device_template = { 4069static struct video_device vdev_template = {
4377 .name = "NOT SET", 4070 .name = "NOT SET",
4378 .fops = &vino_fops, 4071 .fops = &vino_fops,
4072 .ioctl_ops = &vino_ioctl_ops,
4073 .tvnorms = V4L2_STD_NTSC | V4L2_STD_PAL | V4L2_STD_SECAM,
4379 .minor = -1, 4074 .minor = -1,
4380}; 4075};
4381 4076
4382static void vino_module_cleanup(int stage) 4077static void vino_module_cleanup(int stage)
4383{ 4078{
4384 switch(stage) { 4079 switch(stage) {
4080 case 11:
4081 video_unregister_device(vino_drvdata->b.vdev);
4082 vino_drvdata->b.vdev = NULL;
4385 case 10: 4083 case 10:
4386 video_unregister_device(vino_drvdata->b.v4l_device); 4084 video_unregister_device(vino_drvdata->a.vdev);
4387 vino_drvdata->b.v4l_device = NULL; 4085 vino_drvdata->a.vdev = NULL;
4388 case 9: 4086 case 9:
4389 video_unregister_device(vino_drvdata->a.v4l_device); 4087 i2c_del_adapter(&vino_i2c_adapter);
4390 vino_drvdata->a.v4l_device = NULL;
4391 case 8: 4088 case 8:
4392 vino_i2c_del_bus();
4393 case 7:
4394 free_irq(SGI_VINO_IRQ, NULL); 4089 free_irq(SGI_VINO_IRQ, NULL);
4090 case 7:
4091 if (vino_drvdata->b.vdev) {
4092 video_device_release(vino_drvdata->b.vdev);
4093 vino_drvdata->b.vdev = NULL;
4094 }
4395 case 6: 4095 case 6:
4396 if (vino_drvdata->b.v4l_device) { 4096 if (vino_drvdata->a.vdev) {
4397 video_device_release(vino_drvdata->b.v4l_device); 4097 video_device_release(vino_drvdata->a.vdev);
4398 vino_drvdata->b.v4l_device = NULL; 4098 vino_drvdata->a.vdev = NULL;
4399 } 4099 }
4400 case 5: 4100 case 5:
4401 if (vino_drvdata->a.v4l_device) {
4402 video_device_release(vino_drvdata->a.v4l_device);
4403 vino_drvdata->a.v4l_device = NULL;
4404 }
4405 case 4:
4406 /* all entries in dma_cpu dummy table have the same address */ 4101 /* all entries in dma_cpu dummy table have the same address */
4407 dma_unmap_single(NULL, 4102 dma_unmap_single(NULL,
4408 vino_drvdata->dummy_desc_table.dma_cpu[0], 4103 vino_drvdata->dummy_desc_table.dma_cpu[0],
@@ -4412,8 +4107,10 @@ static void vino_module_cleanup(int stage)
4412 (void *)vino_drvdata-> 4107 (void *)vino_drvdata->
4413 dummy_desc_table.dma_cpu, 4108 dummy_desc_table.dma_cpu,
4414 vino_drvdata->dummy_desc_table.dma); 4109 vino_drvdata->dummy_desc_table.dma);
4415 case 3: 4110 case 4:
4416 free_page(vino_drvdata->dummy_page); 4111 free_page(vino_drvdata->dummy_page);
4112 case 3:
4113 v4l2_device_unregister(&vino_drvdata->v4l2_dev);
4417 case 2: 4114 case 2:
4418 kfree(vino_drvdata); 4115 kfree(vino_drvdata);
4419 case 1: 4116 case 1:
@@ -4468,6 +4165,7 @@ static int vino_probe(void)
4468static int vino_init(void) 4165static int vino_init(void)
4469{ 4166{
4470 dma_addr_t dma_dummy_address; 4167 dma_addr_t dma_dummy_address;
4168 int err;
4471 int i; 4169 int i;
4472 4170
4473 vino_drvdata = kzalloc(sizeof(struct vino_settings), GFP_KERNEL); 4171 vino_drvdata = kzalloc(sizeof(struct vino_settings), GFP_KERNEL);
@@ -4476,6 +4174,12 @@ static int vino_init(void)
4476 return -ENOMEM; 4174 return -ENOMEM;
4477 } 4175 }
4478 vino_init_stage++; 4176 vino_init_stage++;
4177 strlcpy(vino_drvdata->v4l2_dev.name, "vino",
4178 sizeof(vino_drvdata->v4l2_dev.name));
4179 err = v4l2_device_register(NULL, &vino_drvdata->v4l2_dev);
4180 if (err)
4181 return err;
4182 vino_init_stage++;
4479 4183
4480 /* create a dummy dma descriptor */ 4184 /* create a dummy dma descriptor */
4481 vino_drvdata->dummy_page = get_zeroed_page(GFP_KERNEL | GFP_DMA); 4185 vino_drvdata->dummy_page = get_zeroed_page(GFP_KERNEL | GFP_DMA);
@@ -4542,25 +4246,27 @@ static int vino_init_channel_settings(struct vino_channel_settings *vcs,
4542 spin_lock_init(&vcs->fb_queue.queue_lock); 4246 spin_lock_init(&vcs->fb_queue.queue_lock);
4543 init_waitqueue_head(&vcs->fb_queue.frame_wait_queue); 4247 init_waitqueue_head(&vcs->fb_queue.frame_wait_queue);
4544 4248
4545 vcs->v4l_device = video_device_alloc(); 4249 vcs->vdev = video_device_alloc();
4546 if (!vcs->v4l_device) { 4250 if (!vcs->vdev) {
4547 vino_module_cleanup(vino_init_stage); 4251 vino_module_cleanup(vino_init_stage);
4548 return -ENOMEM; 4252 return -ENOMEM;
4549 } 4253 }
4550 vino_init_stage++; 4254 vino_init_stage++;
4551 4255
4552 memcpy(vcs->v4l_device, &v4l_device_template, 4256 memcpy(vcs->vdev, &vdev_template,
4553 sizeof(struct video_device)); 4257 sizeof(struct video_device));
4554 strcpy(vcs->v4l_device->name, name); 4258 strcpy(vcs->vdev->name, name);
4555 vcs->v4l_device->release = video_device_release; 4259 vcs->vdev->release = video_device_release;
4260 vcs->vdev->v4l2_dev = &vino_drvdata->v4l2_dev;
4556 4261
4557 video_set_drvdata(vcs->v4l_device, vcs); 4262 video_set_drvdata(vcs->vdev, vcs);
4558 4263
4559 return 0; 4264 return 0;
4560} 4265}
4561 4266
4562static int __init vino_module_init(void) 4267static int __init vino_module_init(void)
4563{ 4268{
4269 unsigned short addr[] = { 0, I2C_CLIENT_END };
4564 int ret; 4270 int ret;
4565 4271
4566 printk(KERN_INFO "SGI VINO driver version %s\n", 4272 printk(KERN_INFO "SGI VINO driver version %s\n",
@@ -4580,12 +4286,12 @@ static int __init vino_module_init(void)
4580 spin_lock_init(&vino_drvdata->input_lock); 4286 spin_lock_init(&vino_drvdata->input_lock);
4581 4287
4582 ret = vino_init_channel_settings(&vino_drvdata->a, VINO_CHANNEL_A, 4288 ret = vino_init_channel_settings(&vino_drvdata->a, VINO_CHANNEL_A,
4583 vino_v4l_device_name_a); 4289 vino_vdev_name_a);
4584 if (ret) 4290 if (ret)
4585 return ret; 4291 return ret;
4586 4292
4587 ret = vino_init_channel_settings(&vino_drvdata->b, VINO_CHANNEL_B, 4293 ret = vino_init_channel_settings(&vino_drvdata->b, VINO_CHANNEL_B,
4588 vino_v4l_device_name_b); 4294 vino_vdev_name_b);
4589 if (ret) 4295 if (ret)
4590 return ret; 4296 return ret;
4591 4297
@@ -4601,15 +4307,16 @@ static int __init vino_module_init(void)
4601 } 4307 }
4602 vino_init_stage++; 4308 vino_init_stage++;
4603 4309
4604 ret = vino_i2c_add_bus(); 4310 ret = i2c_add_adapter(&vino_i2c_adapter);
4605 if (ret) { 4311 if (ret) {
4606 printk(KERN_ERR "VINO I2C bus registration failed\n"); 4312 printk(KERN_ERR "VINO I2C bus registration failed\n");
4607 vino_module_cleanup(vino_init_stage); 4313 vino_module_cleanup(vino_init_stage);
4608 return ret; 4314 return ret;
4609 } 4315 }
4316 i2c_set_adapdata(&vino_i2c_adapter, &vino_drvdata->v4l2_dev);
4610 vino_init_stage++; 4317 vino_init_stage++;
4611 4318
4612 ret = video_register_device(vino_drvdata->a.v4l_device, 4319 ret = video_register_device(vino_drvdata->a.vdev,
4613 VFL_TYPE_GRABBER, -1); 4320 VFL_TYPE_GRABBER, -1);
4614 if (ret < 0) { 4321 if (ret < 0) {
4615 printk(KERN_ERR "VINO channel A Video4Linux-device " 4322 printk(KERN_ERR "VINO channel A Video4Linux-device "
@@ -4619,7 +4326,7 @@ static int __init vino_module_init(void)
4619 } 4326 }
4620 vino_init_stage++; 4327 vino_init_stage++;
4621 4328
4622 ret = video_register_device(vino_drvdata->b.v4l_device, 4329 ret = video_register_device(vino_drvdata->b.vdev,
4623 VFL_TYPE_GRABBER, -1); 4330 VFL_TYPE_GRABBER, -1);
4624 if (ret < 0) { 4331 if (ret < 0) {
4625 printk(KERN_ERR "VINO channel B Video4Linux-device " 4332 printk(KERN_ERR "VINO channel B Video4Linux-device "
@@ -4629,10 +4336,12 @@ static int __init vino_module_init(void)
4629 } 4336 }
4630 vino_init_stage++; 4337 vino_init_stage++;
4631 4338
4632#ifdef MODULE 4339 addr[0] = 0x45;
4633 request_module("saa7191"); 4340 vino_drvdata->decoder = v4l2_i2c_new_probed_subdev(&vino_i2c_adapter,
4634 request_module("indycam"); 4341 "saa7191", "saa7191", addr);
4635#endif 4342 addr[0] = 0x2b;
4343 vino_drvdata->camera = v4l2_i2c_new_probed_subdev(&vino_i2c_adapter,
4344 "indycam", "indycam", addr);
4636 4345
4637 dprintk("init complete!\n"); 4346 dprintk("init complete!\n");
4638 4347
diff --git a/drivers/media/video/vivi.c b/drivers/media/video/vivi.c
index 81d5aa5cf331..fbfefae7886f 100644
--- a/drivers/media/video/vivi.c
+++ b/drivers/media/video/vivi.c
@@ -28,17 +28,14 @@
28#include <linux/mutex.h> 28#include <linux/mutex.h>
29#include <linux/videodev2.h> 29#include <linux/videodev2.h>
30#include <linux/dma-mapping.h> 30#include <linux/dma-mapping.h>
31#ifdef CONFIG_VIDEO_V4L1_COMPAT
32/* Include V4L1 specific functions. Should be removed soon */
33#include <linux/videodev.h>
34#endif
35#include <linux/interrupt.h> 31#include <linux/interrupt.h>
36#include <media/videobuf-vmalloc.h>
37#include <media/v4l2-common.h>
38#include <media/v4l2-ioctl.h>
39#include <linux/kthread.h> 32#include <linux/kthread.h>
40#include <linux/highmem.h> 33#include <linux/highmem.h>
41#include <linux/freezer.h> 34#include <linux/freezer.h>
35#include <media/videobuf-vmalloc.h>
36#include <media/v4l2-device.h>
37#include <media/v4l2-ioctl.h>
38#include "font.h"
42 39
43#define VIVI_MODULE_NAME "vivi" 40#define VIVI_MODULE_NAME "vivi"
44 41
@@ -47,18 +44,32 @@
47#define WAKE_DENOMINATOR 1001 44#define WAKE_DENOMINATOR 1001
48#define BUFFER_TIMEOUT msecs_to_jiffies(500) /* 0.5 seconds */ 45#define BUFFER_TIMEOUT msecs_to_jiffies(500) /* 0.5 seconds */
49 46
50#include "font.h"
51
52#define VIVI_MAJOR_VERSION 0 47#define VIVI_MAJOR_VERSION 0
53#define VIVI_MINOR_VERSION 5 48#define VIVI_MINOR_VERSION 6
54#define VIVI_RELEASE 0 49#define VIVI_RELEASE 0
55#define VIVI_VERSION \ 50#define VIVI_VERSION \
56 KERNEL_VERSION(VIVI_MAJOR_VERSION, VIVI_MINOR_VERSION, VIVI_RELEASE) 51 KERNEL_VERSION(VIVI_MAJOR_VERSION, VIVI_MINOR_VERSION, VIVI_RELEASE)
57 52
58/* Declare static vars that will be used as parameters */ 53MODULE_DESCRIPTION("Video Technology Magazine Virtual Video Capture Board");
59static unsigned int vid_limit = 16; /* Video memory limit, in Mb */ 54MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
60static int video_nr = -1; /* /dev/videoN, -1 for autodetect */ 55MODULE_LICENSE("Dual BSD/GPL");
61static int n_devs = 1; /* Number of virtual devices */ 56
57static unsigned video_nr = -1;
58module_param(video_nr, uint, 0644);
59MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect");
60
61static unsigned n_devs = 1;
62module_param(n_devs, uint, 0644);
63MODULE_PARM_DESC(n_devs, "number of video devices to create");
64
65static unsigned debug;
66module_param(debug, uint, 0644);
67MODULE_PARM_DESC(debug, "activates debug info");
68
69static unsigned int vid_limit = 16;
70module_param(vid_limit, uint, 0644);
71MODULE_PARM_DESC(vid_limit, "capture memory limit in megabytes");
72
62 73
63/* supported controls */ 74/* supported controls */
64static struct v4l2_queryctrl vivi_qctrl[] = { 75static struct v4l2_queryctrl vivi_qctrl[] = {
@@ -69,7 +80,7 @@ static struct v4l2_queryctrl vivi_qctrl[] = {
69 .maximum = 65535, 80 .maximum = 65535,
70 .step = 65535/100, 81 .step = 65535/100,
71 .default_value = 65535, 82 .default_value = 65535,
72 .flags = 0, 83 .flags = V4L2_CTRL_FLAG_SLIDER,
73 .type = V4L2_CTRL_TYPE_INTEGER, 84 .type = V4L2_CTRL_TYPE_INTEGER,
74 }, { 85 }, {
75 .id = V4L2_CID_BRIGHTNESS, 86 .id = V4L2_CID_BRIGHTNESS,
@@ -79,7 +90,7 @@ static struct v4l2_queryctrl vivi_qctrl[] = {
79 .maximum = 255, 90 .maximum = 255,
80 .step = 1, 91 .step = 1,
81 .default_value = 127, 92 .default_value = 127,
82 .flags = 0, 93 .flags = V4L2_CTRL_FLAG_SLIDER,
83 }, { 94 }, {
84 .id = V4L2_CID_CONTRAST, 95 .id = V4L2_CID_CONTRAST,
85 .type = V4L2_CTRL_TYPE_INTEGER, 96 .type = V4L2_CTRL_TYPE_INTEGER,
@@ -88,7 +99,7 @@ static struct v4l2_queryctrl vivi_qctrl[] = {
88 .maximum = 255, 99 .maximum = 255,
89 .step = 0x1, 100 .step = 0x1,
90 .default_value = 0x10, 101 .default_value = 0x10,
91 .flags = 0, 102 .flags = V4L2_CTRL_FLAG_SLIDER,
92 }, { 103 }, {
93 .id = V4L2_CID_SATURATION, 104 .id = V4L2_CID_SATURATION,
94 .type = V4L2_CTRL_TYPE_INTEGER, 105 .type = V4L2_CTRL_TYPE_INTEGER,
@@ -97,7 +108,7 @@ static struct v4l2_queryctrl vivi_qctrl[] = {
97 .maximum = 255, 108 .maximum = 255,
98 .step = 0x1, 109 .step = 0x1,
99 .default_value = 127, 110 .default_value = 127,
100 .flags = 0, 111 .flags = V4L2_CTRL_FLAG_SLIDER,
101 }, { 112 }, {
102 .id = V4L2_CID_HUE, 113 .id = V4L2_CID_HUE,
103 .type = V4L2_CTRL_TYPE_INTEGER, 114 .type = V4L2_CTRL_TYPE_INTEGER,
@@ -106,17 +117,12 @@ static struct v4l2_queryctrl vivi_qctrl[] = {
106 .maximum = 127, 117 .maximum = 127,
107 .step = 0x1, 118 .step = 0x1,
108 .default_value = 0, 119 .default_value = 0,
109 .flags = 0, 120 .flags = V4L2_CTRL_FLAG_SLIDER,
110 } 121 }
111}; 122};
112 123
113static int qctl_regs[ARRAY_SIZE(vivi_qctrl)]; 124#define dprintk(dev, level, fmt, arg...) \
114 125 v4l2_dbg(level, debug, &dev->v4l2_dev, fmt, ## arg)
115#define dprintk(dev, level, fmt, arg...) \
116 do { \
117 if (dev->vfd->debug >= (level)) \
118 printk(KERN_DEBUG "vivi: " fmt , ## arg); \
119 } while (0)
120 126
121/* ------------------------------------------------------------------ 127/* ------------------------------------------------------------------
122 Basic structures 128 Basic structures
@@ -206,6 +212,7 @@ static LIST_HEAD(vivi_devlist);
206 212
207struct vivi_dev { 213struct vivi_dev {
208 struct list_head vivi_devlist; 214 struct list_head vivi_devlist;
215 struct v4l2_device v4l2_dev;
209 216
210 spinlock_t slock; 217 spinlock_t slock;
211 struct mutex mutex; 218 struct mutex mutex;
@@ -223,6 +230,12 @@ struct vivi_dev {
223 char timestr[13]; 230 char timestr[13];
224 231
225 int mv_count; /* Controls bars movement */ 232 int mv_count; /* Controls bars movement */
233
234 /* Input Number */
235 int input;
236
237 /* Control 'registers' */
238 int qctl_regs[ARRAY_SIZE(vivi_qctrl)];
226}; 239};
227 240
228struct vivi_fh { 241struct vivi_fh {
@@ -235,6 +248,7 @@ struct vivi_fh {
235 248
236 enum v4l2_buf_type type; 249 enum v4l2_buf_type type;
237 unsigned char bars[8][3]; 250 unsigned char bars[8][3];
251 int input; /* Input Number on bars */
238}; 252};
239 253
240/* ------------------------------------------------------------------ 254/* ------------------------------------------------------------------
@@ -254,18 +268,72 @@ enum colors {
254 BLACK, 268 BLACK,
255}; 269};
256 270
257static u8 bars[8][3] = {
258 /* R G B */ 271 /* R G B */
259 {204, 204, 204}, /* white */ 272#define COLOR_WHITE {204, 204, 204}
260 {208, 208, 0}, /* ambar */ 273#define COLOR_AMBAR {208, 208, 0}
261 { 0, 206, 206}, /* cyan */ 274#define COLOR_CIAN { 0, 206, 206}
262 { 0, 239, 0}, /* green */ 275#define COLOR_GREEN { 0, 239, 0}
263 {239, 0, 239}, /* magenta */ 276#define COLOR_MAGENTA {239, 0, 239}
264 {205, 0, 0}, /* red */ 277#define COLOR_RED {205, 0, 0}
265 { 0, 0, 255}, /* blue */ 278#define COLOR_BLUE { 0, 0, 255}
266 { 0, 0, 0}, /* black */ 279#define COLOR_BLACK { 0, 0, 0}
280
281struct bar_std {
282 u8 bar[8][3];
267}; 283};
268 284
285/* Maximum number of bars are 10 - otherwise, the input print code
286 should be modified */
287static struct bar_std bars[] = {
288 { /* Standard ITU-R color bar sequence */
289 {
290 COLOR_WHITE,
291 COLOR_AMBAR,
292 COLOR_CIAN,
293 COLOR_GREEN,
294 COLOR_MAGENTA,
295 COLOR_RED,
296 COLOR_BLUE,
297 COLOR_BLACK,
298 }
299 }, {
300 {
301 COLOR_WHITE,
302 COLOR_AMBAR,
303 COLOR_BLACK,
304 COLOR_WHITE,
305 COLOR_AMBAR,
306 COLOR_BLACK,
307 COLOR_WHITE,
308 COLOR_AMBAR,
309 }
310 }, {
311 {
312 COLOR_WHITE,
313 COLOR_CIAN,
314 COLOR_BLACK,
315 COLOR_WHITE,
316 COLOR_CIAN,
317 COLOR_BLACK,
318 COLOR_WHITE,
319 COLOR_CIAN,
320 }
321 }, {
322 {
323 COLOR_WHITE,
324 COLOR_GREEN,
325 COLOR_BLACK,
326 COLOR_WHITE,
327 COLOR_GREEN,
328 COLOR_BLACK,
329 COLOR_WHITE,
330 COLOR_GREEN,
331 }
332 },
333};
334
335#define NUM_INPUTS ARRAY_SIZE(bars)
336
269#define TO_Y(r, g, b) \ 337#define TO_Y(r, g, b) \
270 (((16829 * r + 33039 * g + 6416 * b + 32768) >> 16) + 16) 338 (((16829 * r + 33039 * g + 6416 * b + 32768) >> 16) + 16)
271/* RGB to V(Cr) Color transform */ 339/* RGB to V(Cr) Color transform */
@@ -275,9 +343,10 @@ static u8 bars[8][3] = {
275#define TO_U(r, g, b) \ 343#define TO_U(r, g, b) \
276 (((-9714 * r - 19070 * g + 28784 * b + 32768) >> 16) + 128) 344 (((-9714 * r - 19070 * g + 28784 * b + 32768) >> 16) + 128)
277 345
278#define TSTAMP_MIN_Y 24 346#define TSTAMP_MIN_Y 24
279#define TSTAMP_MAX_Y TSTAMP_MIN_Y+15 347#define TSTAMP_MAX_Y (TSTAMP_MIN_Y + 15)
280#define TSTAMP_MIN_X 64 348#define TSTAMP_INPUT_X 10
349#define TSTAMP_MIN_X (54 + TSTAMP_INPUT_X)
281 350
282static void gen_twopix(struct vivi_fh *fh, unsigned char *buf, int colorpos) 351static void gen_twopix(struct vivi_fh *fh, unsigned char *buf, int colorpos)
283{ 352{
@@ -392,9 +461,29 @@ static void gen_line(struct vivi_fh *fh, char *basep, int inipos, int wmax,
392 pos += 4; /* only 16 bpp supported for now */ 461 pos += 4; /* only 16 bpp supported for now */
393 } 462 }
394 463
395 /* Checks if it is possible to show timestamp */ 464 /* Prints input entry number */
465
466 /* Checks if it is possible to input number */
396 if (TSTAMP_MAX_Y >= hmax) 467 if (TSTAMP_MAX_Y >= hmax)
397 goto end; 468 goto end;
469
470 if (TSTAMP_INPUT_X + strlen(timestr) >= wmax)
471 goto end;
472
473 if (line >= TSTAMP_MIN_Y && line <= TSTAMP_MAX_Y) {
474 chr = rom8x16_bits[fh->input * 16 + line - TSTAMP_MIN_Y];
475 pos = TSTAMP_INPUT_X;
476 for (i = 0; i < 7; i++) {
477 /* Draw white font on black background */
478 if (chr & 1 << (7 - i))
479 gen_twopix(fh, basep + pos, WHITE);
480 else
481 gen_twopix(fh, basep + pos, BLACK);
482 pos += 2;
483 }
484 }
485
486 /* Checks if it is possible to show timestamp */
398 if (TSTAMP_MIN_X + strlen(timestr) >= wmax) 487 if (TSTAMP_MIN_X + strlen(timestr) >= wmax)
399 goto end; 488 goto end;
400 489
@@ -577,7 +666,7 @@ static int vivi_start_thread(struct vivi_fh *fh)
577 dma_q->kthread = kthread_run(vivi_thread, fh, "vivi"); 666 dma_q->kthread = kthread_run(vivi_thread, fh, "vivi");
578 667
579 if (IS_ERR(dma_q->kthread)) { 668 if (IS_ERR(dma_q->kthread)) {
580 printk(KERN_ERR "vivi: kernel_thread() failed\n"); 669 v4l2_err(&dev->v4l2_dev, "kernel_thread() failed\n");
581 return PTR_ERR(dma_q->kthread); 670 return PTR_ERR(dma_q->kthread);
582 } 671 }
583 /* Wakes thread */ 672 /* Wakes thread */
@@ -720,8 +809,12 @@ static struct videobuf_queue_ops vivi_video_qops = {
720static int vidioc_querycap(struct file *file, void *priv, 809static int vidioc_querycap(struct file *file, void *priv,
721 struct v4l2_capability *cap) 810 struct v4l2_capability *cap)
722{ 811{
812 struct vivi_fh *fh = priv;
813 struct vivi_dev *dev = fh->dev;
814
723 strcpy(cap->driver, "vivi"); 815 strcpy(cap->driver, "vivi");
724 strcpy(cap->card, "vivi"); 816 strcpy(cap->card, "vivi");
817 strlcpy(cap->bus_info, dev->v4l2_dev.name, sizeof(cap->bus_info));
725 cap->version = VIVI_VERSION; 818 cap->version = VIVI_VERSION;
726 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | 819 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE |
727 V4L2_CAP_STREAMING | 820 V4L2_CAP_STREAMING |
@@ -807,38 +900,19 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
807 return 0; 900 return 0;
808} 901}
809 902
810/*FIXME: This seems to be generic enough to be at videodev2 */ 903/* precalculate color bar values to speed up rendering */
811static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, 904static void precalculate_bars(struct vivi_fh *fh)
812 struct v4l2_format *f)
813{ 905{
814 struct vivi_fh *fh = priv; 906 struct vivi_dev *dev = fh->dev;
815 struct videobuf_queue *q = &fh->vb_vidq;
816 unsigned char r, g, b; 907 unsigned char r, g, b;
817 int k, is_yuv; 908 int k, is_yuv;
818 909
819 int ret = vidioc_try_fmt_vid_cap(file, fh, f); 910 fh->input = dev->input;
820 if (ret < 0)
821 return (ret);
822
823 mutex_lock(&q->vb_lock);
824
825 if (videobuf_queue_is_busy(&fh->vb_vidq)) {
826 dprintk(fh->dev, 1, "%s queue busy\n", __func__);
827 ret = -EBUSY;
828 goto out;
829 }
830
831 fh->fmt = get_format(f);
832 fh->width = f->fmt.pix.width;
833 fh->height = f->fmt.pix.height;
834 fh->vb_vidq.field = f->fmt.pix.field;
835 fh->type = f->type;
836 911
837 /* precalculate color bar values to speed up rendering */
838 for (k = 0; k < 8; k++) { 912 for (k = 0; k < 8; k++) {
839 r = bars[k][0]; 913 r = bars[fh->input].bar[k][0];
840 g = bars[k][1]; 914 g = bars[fh->input].bar[k][1];
841 b = bars[k][2]; 915 b = bars[fh->input].bar[k][2];
842 is_yuv = 0; 916 is_yuv = 0;
843 917
844 switch (fh->fmt->fourcc) { 918 switch (fh->fmt->fourcc) {
@@ -871,11 +945,40 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
871 } 945 }
872 } 946 }
873 947
948}
949
950/*FIXME: This seems to be generic enough to be at videodev2 */
951static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
952 struct v4l2_format *f)
953{
954 struct vivi_fh *fh = priv;
955 struct videobuf_queue *q = &fh->vb_vidq;
956
957 int ret = vidioc_try_fmt_vid_cap(file, fh, f);
958 if (ret < 0)
959 return ret;
960
961 mutex_lock(&q->vb_lock);
962
963 if (videobuf_queue_is_busy(&fh->vb_vidq)) {
964 dprintk(fh->dev, 1, "%s queue busy\n", __func__);
965 ret = -EBUSY;
966 goto out;
967 }
968
969 fh->fmt = get_format(f);
970 fh->width = f->fmt.pix.width;
971 fh->height = f->fmt.pix.height;
972 fh->vb_vidq.field = f->fmt.pix.field;
973 fh->type = f->type;
974
975 precalculate_bars(fh);
976
874 ret = 0; 977 ret = 0;
875out: 978out:
876 mutex_unlock(&q->vb_lock); 979 mutex_unlock(&q->vb_lock);
877 980
878 return (ret); 981 return ret;
879} 982}
880 983
881static int vidioc_reqbufs(struct file *file, void *priv, 984static int vidioc_reqbufs(struct file *file, void *priv,
@@ -950,27 +1053,36 @@ static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *i)
950static int vidioc_enum_input(struct file *file, void *priv, 1053static int vidioc_enum_input(struct file *file, void *priv,
951 struct v4l2_input *inp) 1054 struct v4l2_input *inp)
952{ 1055{
953 if (inp->index != 0) 1056 if (inp->index >= NUM_INPUTS)
954 return -EINVAL; 1057 return -EINVAL;
955 1058
956 inp->type = V4L2_INPUT_TYPE_CAMERA; 1059 inp->type = V4L2_INPUT_TYPE_CAMERA;
957 inp->std = V4L2_STD_525_60; 1060 inp->std = V4L2_STD_525_60;
958 strcpy(inp->name, "Camera"); 1061 sprintf(inp->name, "Camera %u", inp->index);
959 1062
960 return (0); 1063 return (0);
961} 1064}
962 1065
963static int vidioc_g_input(struct file *file, void *priv, unsigned int *i) 1066static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
964{ 1067{
965 *i = 0; 1068 struct vivi_fh *fh = priv;
1069 struct vivi_dev *dev = fh->dev;
1070
1071 *i = dev->input;
966 1072
967 return (0); 1073 return (0);
968} 1074}
969static int vidioc_s_input(struct file *file, void *priv, unsigned int i) 1075static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
970{ 1076{
971 if (i > 0) 1077 struct vivi_fh *fh = priv;
1078 struct vivi_dev *dev = fh->dev;
1079
1080 if (i >= NUM_INPUTS)
972 return -EINVAL; 1081 return -EINVAL;
973 1082
1083 dev->input = i;
1084 precalculate_bars(fh);
1085
974 return (0); 1086 return (0);
975} 1087}
976 1088
@@ -993,12 +1105,14 @@ static int vidioc_queryctrl(struct file *file, void *priv,
993static int vidioc_g_ctrl(struct file *file, void *priv, 1105static int vidioc_g_ctrl(struct file *file, void *priv,
994 struct v4l2_control *ctrl) 1106 struct v4l2_control *ctrl)
995{ 1107{
1108 struct vivi_fh *fh = priv;
1109 struct vivi_dev *dev = fh->dev;
996 int i; 1110 int i;
997 1111
998 for (i = 0; i < ARRAY_SIZE(vivi_qctrl); i++) 1112 for (i = 0; i < ARRAY_SIZE(vivi_qctrl); i++)
999 if (ctrl->id == vivi_qctrl[i].id) { 1113 if (ctrl->id == vivi_qctrl[i].id) {
1000 ctrl->value = qctl_regs[i]; 1114 ctrl->value = dev->qctl_regs[i];
1001 return (0); 1115 return 0;
1002 } 1116 }
1003 1117
1004 return -EINVAL; 1118 return -EINVAL;
@@ -1006,16 +1120,18 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
1006static int vidioc_s_ctrl(struct file *file, void *priv, 1120static int vidioc_s_ctrl(struct file *file, void *priv,
1007 struct v4l2_control *ctrl) 1121 struct v4l2_control *ctrl)
1008{ 1122{
1123 struct vivi_fh *fh = priv;
1124 struct vivi_dev *dev = fh->dev;
1009 int i; 1125 int i;
1010 1126
1011 for (i = 0; i < ARRAY_SIZE(vivi_qctrl); i++) 1127 for (i = 0; i < ARRAY_SIZE(vivi_qctrl); i++)
1012 if (ctrl->id == vivi_qctrl[i].id) { 1128 if (ctrl->id == vivi_qctrl[i].id) {
1013 if (ctrl->value < vivi_qctrl[i].minimum 1129 if (ctrl->value < vivi_qctrl[i].minimum ||
1014 || ctrl->value > vivi_qctrl[i].maximum) { 1130 ctrl->value > vivi_qctrl[i].maximum) {
1015 return (-ERANGE); 1131 return -ERANGE;
1016 } 1132 }
1017 qctl_regs[i] = ctrl->value; 1133 dev->qctl_regs[i] = ctrl->value;
1018 return (0); 1134 return 0;
1019 } 1135 }
1020 return -EINVAL; 1136 return -EINVAL;
1021} 1137}
@@ -1026,32 +1142,20 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
1026 1142
1027static int vivi_open(struct file *file) 1143static int vivi_open(struct file *file)
1028{ 1144{
1029 int minor = video_devdata(file)->minor; 1145 struct vivi_dev *dev = video_drvdata(file);
1030 struct vivi_dev *dev;
1031 struct vivi_fh *fh = NULL; 1146 struct vivi_fh *fh = NULL;
1032 int i;
1033 int retval = 0; 1147 int retval = 0;
1034 1148
1035 printk(KERN_DEBUG "vivi: open called (minor=%d)\n", minor);
1036
1037 lock_kernel();
1038 list_for_each_entry(dev, &vivi_devlist, vivi_devlist)
1039 if (dev->vfd->minor == minor)
1040 goto found;
1041 unlock_kernel();
1042 return -ENODEV;
1043
1044found:
1045 mutex_lock(&dev->mutex); 1149 mutex_lock(&dev->mutex);
1046 dev->users++; 1150 dev->users++;
1047 1151
1048 if (dev->users > 1) { 1152 if (dev->users > 1) {
1049 dev->users--; 1153 dev->users--;
1050 retval = -EBUSY; 1154 mutex_unlock(&dev->mutex);
1051 goto unlock; 1155 return -EBUSY;
1052 } 1156 }
1053 1157
1054 dprintk(dev, 1, "open minor=%d type=%s users=%d\n", minor, 1158 dprintk(dev, 1, "open /dev/video%d type=%s users=%d\n", dev->vfd->num,
1055 v4l2_type_names[V4L2_BUF_TYPE_VIDEO_CAPTURE], dev->users); 1159 v4l2_type_names[V4L2_BUF_TYPE_VIDEO_CAPTURE], dev->users);
1056 1160
1057 /* allocate + initialize per filehandle data */ 1161 /* allocate + initialize per filehandle data */
@@ -1059,14 +1163,11 @@ found:
1059 if (NULL == fh) { 1163 if (NULL == fh) {
1060 dev->users--; 1164 dev->users--;
1061 retval = -ENOMEM; 1165 retval = -ENOMEM;
1062 goto unlock;
1063 } 1166 }
1064unlock:
1065 mutex_unlock(&dev->mutex); 1167 mutex_unlock(&dev->mutex);
1066 if (retval) { 1168
1067 unlock_kernel(); 1169 if (retval)
1068 return retval; 1170 return retval;
1069 }
1070 1171
1071 file->private_data = fh; 1172 file->private_data = fh;
1072 fh->dev = dev; 1173 fh->dev = dev;
@@ -1076,10 +1177,6 @@ unlock:
1076 fh->width = 640; 1177 fh->width = 640;
1077 fh->height = 480; 1178 fh->height = 480;
1078 1179
1079 /* Put all controls at a sane state */
1080 for (i = 0; i < ARRAY_SIZE(vivi_qctrl); i++)
1081 qctl_regs[i] = vivi_qctrl[i].default_value;
1082
1083 /* Resets frame counters */ 1180 /* Resets frame counters */
1084 dev->h = 0; 1181 dev->h = 0;
1085 dev->m = 0; 1182 dev->m = 0;
@@ -1095,7 +1192,6 @@ unlock:
1095 sizeof(struct vivi_buffer), fh); 1192 sizeof(struct vivi_buffer), fh);
1096 1193
1097 vivi_start_thread(fh); 1194 vivi_start_thread(fh);
1098 unlock_kernel();
1099 1195
1100 return 0; 1196 return 0;
1101} 1197}
@@ -1151,32 +1247,6 @@ static int vivi_close(struct file *file)
1151 return 0; 1247 return 0;
1152} 1248}
1153 1249
1154static int vivi_release(void)
1155{
1156 struct vivi_dev *dev;
1157 struct list_head *list;
1158
1159 while (!list_empty(&vivi_devlist)) {
1160 list = vivi_devlist.next;
1161 list_del(list);
1162 dev = list_entry(list, struct vivi_dev, vivi_devlist);
1163
1164 if (-1 != dev->vfd->minor) {
1165 printk(KERN_INFO "%s: unregistering /dev/video%d\n",
1166 VIVI_MODULE_NAME, dev->vfd->num);
1167 video_unregister_device(dev->vfd);
1168 } else {
1169 printk(KERN_INFO "%s: releasing /dev/video%d\n",
1170 VIVI_MODULE_NAME, dev->vfd->num);
1171 video_device_release(dev->vfd);
1172 }
1173
1174 kfree(dev);
1175 }
1176
1177 return 0;
1178}
1179
1180static int vivi_mmap(struct file *file, struct vm_area_struct *vma) 1250static int vivi_mmap(struct file *file, struct vm_area_struct *vma)
1181{ 1251{
1182 struct vivi_fh *fh = file->private_data; 1252 struct vivi_fh *fh = file->private_data;
@@ -1239,87 +1309,130 @@ static struct video_device vivi_template = {
1239 .tvnorms = V4L2_STD_525_60, 1309 .tvnorms = V4L2_STD_525_60,
1240 .current_norm = V4L2_STD_NTSC_M, 1310 .current_norm = V4L2_STD_NTSC_M,
1241}; 1311};
1312
1242/* ----------------------------------------------------------------- 1313/* -----------------------------------------------------------------
1243 Initialization and module stuff 1314 Initialization and module stuff
1244 ------------------------------------------------------------------*/ 1315 ------------------------------------------------------------------*/
1245 1316
1246/* This routine allocates from 1 to n_devs virtual drivers. 1317static int vivi_release(void)
1318{
1319 struct vivi_dev *dev;
1320 struct list_head *list;
1247 1321
1248 The real maximum number of virtual drivers will depend on how many drivers 1322 while (!list_empty(&vivi_devlist)) {
1249 will succeed. This is limited to the maximum number of devices that 1323 list = vivi_devlist.next;
1250 videodev supports. Since there are 64 minors for video grabbers, this is 1324 list_del(list);
1251 currently the theoretical maximum limit. However, a further limit does 1325 dev = list_entry(list, struct vivi_dev, vivi_devlist);
1252 exist at videodev that forbids any driver to register more than 32 video 1326
1253 grabbers. 1327 v4l2_info(&dev->v4l2_dev, "unregistering /dev/video%d\n",
1254 */ 1328 dev->vfd->num);
1255static int __init vivi_init(void) 1329 video_unregister_device(dev->vfd);
1330 v4l2_device_unregister(&dev->v4l2_dev);
1331 kfree(dev);
1332 }
1333
1334 return 0;
1335}
1336
1337static int __init vivi_create_instance(int inst)
1256{ 1338{
1257 int ret = -ENOMEM, i;
1258 struct vivi_dev *dev; 1339 struct vivi_dev *dev;
1259 struct video_device *vfd; 1340 struct video_device *vfd;
1341 int ret, i;
1260 1342
1261 if (n_devs <= 0) 1343 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
1262 n_devs = 1; 1344 if (!dev)
1345 return -ENOMEM;
1263 1346
1264 for (i = 0; i < n_devs; i++) { 1347 snprintf(dev->v4l2_dev.name, sizeof(dev->v4l2_dev.name),
1265 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 1348 "%s-%03d", VIVI_MODULE_NAME, inst);
1266 if (!dev) 1349 ret = v4l2_device_register(NULL, &dev->v4l2_dev);
1267 break; 1350 if (ret)
1351 goto free_dev;
1268 1352
1269 /* init video dma queues */ 1353 /* init video dma queues */
1270 INIT_LIST_HEAD(&dev->vidq.active); 1354 INIT_LIST_HEAD(&dev->vidq.active);
1271 init_waitqueue_head(&dev->vidq.wq); 1355 init_waitqueue_head(&dev->vidq.wq);
1272 1356
1273 /* initialize locks */ 1357 /* initialize locks */
1274 spin_lock_init(&dev->slock); 1358 spin_lock_init(&dev->slock);
1275 mutex_init(&dev->mutex); 1359 mutex_init(&dev->mutex);
1276 1360
1277 vfd = video_device_alloc(); 1361 ret = -ENOMEM;
1278 if (!vfd) { 1362 vfd = video_device_alloc();
1279 kfree(dev); 1363 if (!vfd)
1280 break; 1364 goto unreg_dev;
1281 }
1282 1365
1283 *vfd = vivi_template; 1366 *vfd = vivi_template;
1284 1367
1285 ret = video_register_device(vfd, VFL_TYPE_GRABBER, video_nr); 1368 ret = video_register_device(vfd, VFL_TYPE_GRABBER, video_nr);
1286 if (ret < 0) { 1369 if (ret < 0)
1287 video_device_release(vfd); 1370 goto rel_vdev;
1288 kfree(dev);
1289 1371
1290 /* If some registers succeeded, keep driver */ 1372 video_set_drvdata(vfd, dev);
1291 if (i)
1292 ret = 0;
1293 1373
1294 break; 1374 /* Set all controls to their default value. */
1295 } 1375 for (i = 0; i < ARRAY_SIZE(vivi_qctrl); i++)
1376 dev->qctl_regs[i] = vivi_qctrl[i].default_value;
1377
1378 /* Now that everything is fine, let's add it to device list */
1379 list_add_tail(&dev->vivi_devlist, &vivi_devlist);
1380
1381 snprintf(vfd->name, sizeof(vfd->name), "%s (%i)",
1382 vivi_template.name, vfd->num);
1383
1384 if (video_nr >= 0)
1385 video_nr++;
1296 1386
1297 /* Now that everything is fine, let's add it to device list */ 1387 dev->vfd = vfd;
1298 list_add_tail(&dev->vivi_devlist, &vivi_devlist); 1388 v4l2_info(&dev->v4l2_dev, "V4L2 device registered as /dev/video%d\n",
1389 vfd->num);
1390 return 0;
1391
1392rel_vdev:
1393 video_device_release(vfd);
1394unreg_dev:
1395 v4l2_device_unregister(&dev->v4l2_dev);
1396free_dev:
1397 kfree(dev);
1398 return ret;
1399}
1400
1401/* This routine allocates from 1 to n_devs virtual drivers.
1299 1402
1300 snprintf(vfd->name, sizeof(vfd->name), "%s (%i)", 1403 The real maximum number of virtual drivers will depend on how many drivers
1301 vivi_template.name, vfd->minor); 1404 will succeed. This is limited to the maximum number of devices that
1405 videodev supports, which is equal to VIDEO_NUM_DEVICES.
1406 */
1407static int __init vivi_init(void)
1408{
1409 int ret = 0, i;
1302 1410
1303 if (video_nr >= 0) 1411 if (n_devs <= 0)
1304 video_nr++; 1412 n_devs = 1;
1305 1413
1306 dev->vfd = vfd; 1414 for (i = 0; i < n_devs; i++) {
1307 printk(KERN_INFO "%s: V4L2 device registered as /dev/video%d\n", 1415 ret = vivi_create_instance(i);
1308 VIVI_MODULE_NAME, vfd->num); 1416 if (ret) {
1417 /* If some instantiations succeeded, keep driver */
1418 if (i)
1419 ret = 0;
1420 break;
1421 }
1309 } 1422 }
1310 1423
1311 if (ret < 0) { 1424 if (ret < 0) {
1312 vivi_release();
1313 printk(KERN_INFO "Error %d while loading vivi driver\n", ret); 1425 printk(KERN_INFO "Error %d while loading vivi driver\n", ret);
1314 } else { 1426 return ret;
1315 printk(KERN_INFO "Video Technology Magazine Virtual Video " 1427 }
1428
1429 printk(KERN_INFO "Video Technology Magazine Virtual Video "
1316 "Capture Board ver %u.%u.%u successfully loaded.\n", 1430 "Capture Board ver %u.%u.%u successfully loaded.\n",
1317 (VIVI_VERSION >> 16) & 0xFF, (VIVI_VERSION >> 8) & 0xFF, 1431 (VIVI_VERSION >> 16) & 0xFF, (VIVI_VERSION >> 8) & 0xFF,
1318 VIVI_VERSION & 0xFF); 1432 VIVI_VERSION & 0xFF);
1319 1433
1320 /* n_devs will reflect the actual number of allocated devices */ 1434 /* n_devs will reflect the actual number of allocated devices */
1321 n_devs = i; 1435 n_devs = i;
1322 }
1323 1436
1324 return ret; 1437 return ret;
1325} 1438}
@@ -1331,19 +1444,3 @@ static void __exit vivi_exit(void)
1331 1444
1332module_init(vivi_init); 1445module_init(vivi_init);
1333module_exit(vivi_exit); 1446module_exit(vivi_exit);
1334
1335MODULE_DESCRIPTION("Video Technology Magazine Virtual Video Capture Board");
1336MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
1337MODULE_LICENSE("Dual BSD/GPL");
1338
1339module_param(video_nr, uint, 0444);
1340MODULE_PARM_DESC(video_nr, "video iminor start number");
1341
1342module_param(n_devs, uint, 0444);
1343MODULE_PARM_DESC(n_devs, "number of video devices to create");
1344
1345module_param_named(debug, vivi_template.debug, int, 0444);
1346MODULE_PARM_DESC(debug, "activates debug info");
1347
1348module_param(vid_limit, int, 0644);
1349MODULE_PARM_DESC(vid_limit, "capture memory limit in megabytes");
diff --git a/drivers/media/video/vp27smpx.c b/drivers/media/video/vp27smpx.c
index 5d73f66d9f55..42e23a4fa607 100644
--- a/drivers/media/video/vp27smpx.c
+++ b/drivers/media/video/vp27smpx.c
@@ -129,11 +129,6 @@ static int vp27smpx_log_status(struct v4l2_subdev *sd)
129 return 0; 129 return 0;
130} 130}
131 131
132static int vp27smpx_command(struct i2c_client *client, unsigned cmd, void *arg)
133{
134 return v4l2_subdev_command(i2c_get_clientdata(client), cmd, arg);
135}
136
137/* ----------------------------------------------------------------------- */ 132/* ----------------------------------------------------------------------- */
138 133
139static const struct v4l2_subdev_core_ops vp27smpx_core_ops = { 134static const struct v4l2_subdev_core_ops vp27smpx_core_ops = {
@@ -206,8 +201,6 @@ MODULE_DEVICE_TABLE(i2c, vp27smpx_id);
206 201
207static struct v4l2_i2c_driver_data v4l2_i2c_data = { 202static struct v4l2_i2c_driver_data v4l2_i2c_data = {
208 .name = "vp27smpx", 203 .name = "vp27smpx",
209 .driverid = I2C_DRIVERID_VP27SMPX,
210 .command = vp27smpx_command,
211 .probe = vp27smpx_probe, 204 .probe = vp27smpx_probe,
212 .remove = vp27smpx_remove, 205 .remove = vp27smpx_remove,
213 .id_table = vp27smpx_id, 206 .id_table = vp27smpx_id,
diff --git a/drivers/media/video/vpx3220.c b/drivers/media/video/vpx3220.c
index 67aa0db4b81a..2fa7e8bb5746 100644
--- a/drivers/media/video/vpx3220.c
+++ b/drivers/media/video/vpx3220.c
@@ -24,10 +24,10 @@
24#include <linux/types.h> 24#include <linux/types.h>
25#include <asm/uaccess.h> 25#include <asm/uaccess.h>
26#include <linux/i2c.h> 26#include <linux/i2c.h>
27#include <media/v4l2-common.h> 27#include <linux/videodev2.h>
28#include <media/v4l2-i2c-drv-legacy.h> 28#include <media/v4l2-device.h>
29#include <linux/videodev.h> 29#include <media/v4l2-chip-ident.h>
30#include <linux/video_decoder.h> 30#include <media/v4l2-i2c-drv.h>
31 31
32MODULE_DESCRIPTION("vpx3220a/vpx3216b/vpx3214c video decoder driver"); 32MODULE_DESCRIPTION("vpx3220a/vpx3216b/vpx3214c video decoder driver");
33MODULE_AUTHOR("Laurent Pinchart"); 33MODULE_AUTHOR("Laurent Pinchart");
@@ -37,14 +37,17 @@ static int debug;
37module_param(debug, int, 0); 37module_param(debug, int, 0);
38MODULE_PARM_DESC(debug, "Debug level (0-1)"); 38MODULE_PARM_DESC(debug, "Debug level (0-1)");
39 39
40
40#define VPX_TIMEOUT_COUNT 10 41#define VPX_TIMEOUT_COUNT 10
41 42
42/* ----------------------------------------------------------------------- */ 43/* ----------------------------------------------------------------------- */
43 44
44struct vpx3220 { 45struct vpx3220 {
46 struct v4l2_subdev sd;
45 unsigned char reg[255]; 47 unsigned char reg[255];
46 48
47 int norm; 49 v4l2_std_id norm;
50 int ident;
48 int input; 51 int input;
49 int enable; 52 int enable;
50 int bright; 53 int bright;
@@ -53,30 +56,38 @@ struct vpx3220 {
53 int sat; 56 int sat;
54}; 57};
55 58
59static inline struct vpx3220 *to_vpx3220(struct v4l2_subdev *sd)
60{
61 return container_of(sd, struct vpx3220, sd);
62}
63
56static char *inputs[] = { "internal", "composite", "svideo" }; 64static char *inputs[] = { "internal", "composite", "svideo" };
57 65
58/* ----------------------------------------------------------------------- */ 66/* ----------------------------------------------------------------------- */
59 67
60static inline int vpx3220_write(struct i2c_client *client, u8 reg, u8 value) 68static inline int vpx3220_write(struct v4l2_subdev *sd, u8 reg, u8 value)
61{ 69{
70 struct i2c_client *client = v4l2_get_subdevdata(sd);
62 struct vpx3220 *decoder = i2c_get_clientdata(client); 71 struct vpx3220 *decoder = i2c_get_clientdata(client);
63 72
64 decoder->reg[reg] = value; 73 decoder->reg[reg] = value;
65 return i2c_smbus_write_byte_data(client, reg, value); 74 return i2c_smbus_write_byte_data(client, reg, value);
66} 75}
67 76
68static inline int vpx3220_read(struct i2c_client *client, u8 reg) 77static inline int vpx3220_read(struct v4l2_subdev *sd, u8 reg)
69{ 78{
79 struct i2c_client *client = v4l2_get_subdevdata(sd);
80
70 return i2c_smbus_read_byte_data(client, reg); 81 return i2c_smbus_read_byte_data(client, reg);
71} 82}
72 83
73static int vpx3220_fp_status(struct i2c_client *client) 84static int vpx3220_fp_status(struct v4l2_subdev *sd)
74{ 85{
75 unsigned char status; 86 unsigned char status;
76 unsigned int i; 87 unsigned int i;
77 88
78 for (i = 0; i < VPX_TIMEOUT_COUNT; i++) { 89 for (i = 0; i < VPX_TIMEOUT_COUNT; i++) {
79 status = vpx3220_read(client, 0x29); 90 status = vpx3220_read(sd, 0x29);
80 91
81 if (!(status & 4)) 92 if (!(status & 4))
82 return 0; 93 return 0;
@@ -90,57 +101,60 @@ static int vpx3220_fp_status(struct i2c_client *client)
90 return -1; 101 return -1;
91} 102}
92 103
93static int vpx3220_fp_write(struct i2c_client *client, u8 fpaddr, u16 data) 104static int vpx3220_fp_write(struct v4l2_subdev *sd, u8 fpaddr, u16 data)
94{ 105{
106 struct i2c_client *client = v4l2_get_subdevdata(sd);
107
95 /* Write the 16-bit address to the FPWR register */ 108 /* Write the 16-bit address to the FPWR register */
96 if (i2c_smbus_write_word_data(client, 0x27, swab16(fpaddr)) == -1) { 109 if (i2c_smbus_write_word_data(client, 0x27, swab16(fpaddr)) == -1) {
97 v4l_dbg(1, debug, client, "%s: failed\n", __func__); 110 v4l2_dbg(1, debug, sd, "%s: failed\n", __func__);
98 return -1; 111 return -1;
99 } 112 }
100 113
101 if (vpx3220_fp_status(client) < 0) 114 if (vpx3220_fp_status(sd) < 0)
102 return -1; 115 return -1;
103 116
104 /* Write the 16-bit data to the FPDAT register */ 117 /* Write the 16-bit data to the FPDAT register */
105 if (i2c_smbus_write_word_data(client, 0x28, swab16(data)) == -1) { 118 if (i2c_smbus_write_word_data(client, 0x28, swab16(data)) == -1) {
106 v4l_dbg(1, debug, client, "%s: failed\n", __func__); 119 v4l2_dbg(1, debug, sd, "%s: failed\n", __func__);
107 return -1; 120 return -1;
108 } 121 }
109 122
110 return 0; 123 return 0;
111} 124}
112 125
113static u16 vpx3220_fp_read(struct i2c_client *client, u16 fpaddr) 126static u16 vpx3220_fp_read(struct v4l2_subdev *sd, u16 fpaddr)
114{ 127{
128 struct i2c_client *client = v4l2_get_subdevdata(sd);
115 s16 data; 129 s16 data;
116 130
117 /* Write the 16-bit address to the FPRD register */ 131 /* Write the 16-bit address to the FPRD register */
118 if (i2c_smbus_write_word_data(client, 0x26, swab16(fpaddr)) == -1) { 132 if (i2c_smbus_write_word_data(client, 0x26, swab16(fpaddr)) == -1) {
119 v4l_dbg(1, debug, client, "%s: failed\n", __func__); 133 v4l2_dbg(1, debug, sd, "%s: failed\n", __func__);
120 return -1; 134 return -1;
121 } 135 }
122 136
123 if (vpx3220_fp_status(client) < 0) 137 if (vpx3220_fp_status(sd) < 0)
124 return -1; 138 return -1;
125 139
126 /* Read the 16-bit data from the FPDAT register */ 140 /* Read the 16-bit data from the FPDAT register */
127 data = i2c_smbus_read_word_data(client, 0x28); 141 data = i2c_smbus_read_word_data(client, 0x28);
128 if (data == -1) { 142 if (data == -1) {
129 v4l_dbg(1, debug, client, "%s: failed\n", __func__); 143 v4l2_dbg(1, debug, sd, "%s: failed\n", __func__);
130 return -1; 144 return -1;
131 } 145 }
132 146
133 return swab16(data); 147 return swab16(data);
134} 148}
135 149
136static int vpx3220_write_block(struct i2c_client *client, const u8 *data, unsigned int len) 150static int vpx3220_write_block(struct v4l2_subdev *sd, const u8 *data, unsigned int len)
137{ 151{
138 u8 reg; 152 u8 reg;
139 int ret = -1; 153 int ret = -1;
140 154
141 while (len >= 2) { 155 while (len >= 2) {
142 reg = *data++; 156 reg = *data++;
143 ret = vpx3220_write(client, reg, *data++); 157 ret = vpx3220_write(sd, reg, *data++);
144 if (ret < 0) 158 if (ret < 0)
145 break; 159 break;
146 len -= 2; 160 len -= 2;
@@ -149,7 +163,7 @@ static int vpx3220_write_block(struct i2c_client *client, const u8 *data, unsign
149 return ret; 163 return ret;
150} 164}
151 165
152static int vpx3220_write_fp_block(struct i2c_client *client, 166static int vpx3220_write_fp_block(struct v4l2_subdev *sd,
153 const u16 *data, unsigned int len) 167 const u16 *data, unsigned int len)
154{ 168{
155 u8 reg; 169 u8 reg;
@@ -157,7 +171,7 @@ static int vpx3220_write_fp_block(struct i2c_client *client,
157 171
158 while (len > 1) { 172 while (len > 1) {
159 reg = *data++; 173 reg = *data++;
160 ret |= vpx3220_fp_write(client, reg, *data++); 174 ret |= vpx3220_fp_write(sd, reg, *data++);
161 len -= 2; 175 len -= 2;
162 } 176 }
163 177
@@ -259,276 +273,277 @@ static const unsigned short init_fp[] = {
259 0x4b, 0x298, /* PLL gain */ 273 0x4b, 0x298, /* PLL gain */
260}; 274};
261 275
262static void vpx3220_dump_i2c(struct i2c_client *client)
263{
264 int len = sizeof(init_common);
265 const unsigned char *data = init_common;
266 276
267 while (len > 1) { 277static int vpx3220_init(struct v4l2_subdev *sd, u32 val)
268 v4l_dbg(1, debug, client, "i2c reg 0x%02x data 0x%02x\n", 278{
269 *data, vpx3220_read(client, *data)); 279 struct vpx3220 *decoder = to_vpx3220(sd);
270 data += 2; 280
271 len -= 2; 281 vpx3220_write_block(sd, init_common, sizeof(init_common));
272 } 282 vpx3220_write_fp_block(sd, init_fp, sizeof(init_fp) >> 1);
283 if (decoder->norm & V4L2_STD_NTSC)
284 vpx3220_write_fp_block(sd, init_ntsc, sizeof(init_ntsc) >> 1);
285 else if (decoder->norm & V4L2_STD_PAL)
286 vpx3220_write_fp_block(sd, init_pal, sizeof(init_pal) >> 1);
287 else if (decoder->norm & V4L2_STD_SECAM)
288 vpx3220_write_fp_block(sd, init_secam, sizeof(init_secam) >> 1);
289 else
290 vpx3220_write_fp_block(sd, init_pal, sizeof(init_pal) >> 1);
291 return 0;
273} 292}
274 293
275static int vpx3220_command(struct i2c_client *client, unsigned cmd, void *arg) 294static int vpx3220_status(struct v4l2_subdev *sd, u32 *pstatus, v4l2_std_id *pstd)
276{ 295{
277 struct vpx3220 *decoder = i2c_get_clientdata(client); 296 int res = V4L2_IN_ST_NO_SIGNAL, status;
297 v4l2_std_id std = 0;
278 298
279 switch (cmd) { 299 status = vpx3220_fp_read(sd, 0x0f3);
280 case 0: 300
281 { 301 v4l2_dbg(1, debug, sd, "status: 0x%04x\n", status);
282 vpx3220_write_block(client, init_common, 302
283 sizeof(init_common)); 303 if (status < 0)
284 vpx3220_write_fp_block(client, init_fp, 304 return status;
285 sizeof(init_fp) >> 1);
286 switch (decoder->norm) {
287 case VIDEO_MODE_NTSC:
288 vpx3220_write_fp_block(client, init_ntsc,
289 sizeof(init_ntsc) >> 1);
290 break;
291 305
292 case VIDEO_MODE_PAL: 306 if ((status & 0x20) == 0) {
293 vpx3220_write_fp_block(client, init_pal, 307 res = 0;
294 sizeof(init_pal) >> 1); 308
309 switch (status & 0x18) {
310 case 0x00:
311 case 0x10:
312 case 0x14:
313 case 0x18:
314 std = V4L2_STD_PAL;
295 break; 315 break;
296 case VIDEO_MODE_SECAM: 316
297 vpx3220_write_fp_block(client, init_secam, 317 case 0x08:
298 sizeof(init_secam) >> 1); 318 std = V4L2_STD_SECAM;
299 break; 319 break;
300 default: 320
301 vpx3220_write_fp_block(client, init_pal, 321 case 0x04:
302 sizeof(init_pal) >> 1); 322 case 0x0c:
323 case 0x1c:
324 std = V4L2_STD_NTSC;
303 break; 325 break;
304 } 326 }
305 break;
306 }
307
308 case DECODER_DUMP:
309 {
310 vpx3220_dump_i2c(client);
311 break;
312 } 327 }
328 if (pstd)
329 *pstd = std;
330 if (pstatus)
331 *pstatus = status;
332 return 0;
333}
313 334
314 case DECODER_GET_CAPABILITIES: 335static int vpx3220_querystd(struct v4l2_subdev *sd, v4l2_std_id *std)
315 { 336{
316 struct video_decoder_capability *cap = arg; 337 v4l2_dbg(1, debug, sd, "querystd\n");
338 return vpx3220_status(sd, NULL, std);
339}
317 340
318 v4l_dbg(1, debug, client, "DECODER_GET_CAPABILITIES\n"); 341static int vpx3220_g_input_status(struct v4l2_subdev *sd, u32 *status)
342{
343 v4l2_dbg(1, debug, sd, "g_input_status\n");
344 return vpx3220_status(sd, status, NULL);
345}
319 346
320 cap->flags = VIDEO_DECODER_PAL | 347static int vpx3220_s_std(struct v4l2_subdev *sd, v4l2_std_id std)
321 VIDEO_DECODER_NTSC | 348{
322 VIDEO_DECODER_SECAM | 349 struct vpx3220 *decoder = to_vpx3220(sd);
323 VIDEO_DECODER_AUTO | 350 int temp_input;
324 VIDEO_DECODER_CCIR; 351
325 cap->inputs = 3; 352 /* Here we back up the input selection because it gets
326 cap->outputs = 1; 353 overwritten when we fill the registers with the
327 break; 354 choosen video norm */
355 temp_input = vpx3220_fp_read(sd, 0xf2);
356
357 v4l2_dbg(1, debug, sd, "s_std %llx\n", (unsigned long long)std);
358 if (std & V4L2_STD_NTSC) {
359 vpx3220_write_fp_block(sd, init_ntsc, sizeof(init_ntsc) >> 1);
360 v4l2_dbg(1, debug, sd, "norm switched to NTSC\n");
361 } else if (std & V4L2_STD_PAL) {
362 vpx3220_write_fp_block(sd, init_pal, sizeof(init_pal) >> 1);
363 v4l2_dbg(1, debug, sd, "norm switched to PAL\n");
364 } else if (std & V4L2_STD_SECAM) {
365 vpx3220_write_fp_block(sd, init_secam, sizeof(init_secam) >> 1);
366 v4l2_dbg(1, debug, sd, "norm switched to SECAM\n");
367 } else {
368 return -EINVAL;
328 } 369 }
329 370
330 case DECODER_GET_STATUS: 371 decoder->norm = std;
331 {
332 int res = 0, status;
333 372
334 v4l_dbg(1, debug, client, "DECODER_GET_STATUS\n"); 373 /* And here we set the backed up video input again */
335 374 vpx3220_fp_write(sd, 0xf2, temp_input | 0x0010);
336 status = vpx3220_fp_read(client, 0x0f3); 375 udelay(10);
337 376 return 0;
338 v4l_dbg(1, debug, client, "status: 0x%04x\n", status); 377}
339
340 if (status < 0)
341 return status;
342 378
343 if ((status & 0x20) == 0) { 379static int vpx3220_s_routing(struct v4l2_subdev *sd, const struct v4l2_routing *route)
344 res |= DECODER_STATUS_GOOD | DECODER_STATUS_COLOR; 380{
381 int data;
345 382
346 switch (status & 0x18) { 383 /* RJ: route->input = 0: ST8 (PCTV) input
347 case 0x00: 384 route->input = 1: COMPOSITE input
348 case 0x10: 385 route->input = 2: SVHS input */
349 case 0x14:
350 case 0x18:
351 res |= DECODER_STATUS_PAL;
352 break;
353 386
354 case 0x08: 387 const int input[3][2] = {
355 res |= DECODER_STATUS_SECAM; 388 {0x0c, 0},
356 break; 389 {0x0d, 0},
390 {0x0e, 1}
391 };
357 392
358 case 0x04: 393 if (route->input < 0 || route->input > 2)
359 case 0x0c: 394 return -EINVAL;
360 case 0x1c:
361 res |= DECODER_STATUS_NTSC;
362 break;
363 }
364 }
365 395
366 *(int *) arg = res; 396 v4l2_dbg(1, debug, sd, "input switched to %s\n", inputs[route->input]);
367 break;
368 }
369 397
370 case DECODER_SET_NORM: 398 vpx3220_write(sd, 0x33, input[route->input][0]);
371 {
372 int *iarg = arg, data;
373 int temp_input;
374
375 /* Here we back up the input selection because it gets
376 overwritten when we fill the registers with the
377 choosen video norm */
378 temp_input = vpx3220_fp_read(client, 0xf2);
379
380 v4l_dbg(1, debug, client, "DECODER_SET_NORM %d\n", *iarg);
381 switch (*iarg) {
382 case VIDEO_MODE_NTSC:
383 vpx3220_write_fp_block(client, init_ntsc,
384 sizeof(init_ntsc) >> 1);
385 v4l_dbg(1, debug, client, "norm switched to NTSC\n");
386 break;
387 399
388 case VIDEO_MODE_PAL: 400 data = vpx3220_fp_read(sd, 0xf2) & ~(0x0020);
389 vpx3220_write_fp_block(client, init_pal, 401 if (data < 0)
390 sizeof(init_pal) >> 1); 402 return data;
391 v4l_dbg(1, debug, client, "norm switched to PAL\n"); 403 /* 0x0010 is required to latch the setting */
392 break; 404 vpx3220_fp_write(sd, 0xf2,
405 data | (input[route->input][1] << 5) | 0x0010);
393 406
394 case VIDEO_MODE_SECAM: 407 udelay(10);
395 vpx3220_write_fp_block(client, init_secam, 408 return 0;
396 sizeof(init_secam) >> 1); 409}
397 v4l_dbg(1, debug, client, "norm switched to SECAM\n");
398 break;
399 410
400 case VIDEO_MODE_AUTO: 411static int vpx3220_s_stream(struct v4l2_subdev *sd, int enable)
401 /* FIXME This is only preliminary support */ 412{
402 data = vpx3220_fp_read(client, 0xf2) & 0x20; 413 v4l2_dbg(1, debug, sd, "s_stream %s\n", enable ? "on" : "off");
403 vpx3220_fp_write(client, 0xf2, 0x00c0 | data);
404 v4l_dbg(1, debug, client, "norm switched to AUTO\n");
405 break;
406 414
407 default: 415 vpx3220_write(sd, 0xf2, (enable ? 0x1b : 0x00));
408 return -EINVAL; 416 return 0;
409 } 417}
410 decoder->norm = *iarg;
411 418
412 /* And here we set the backed up video input again */ 419static int vpx3220_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc)
413 vpx3220_fp_write(client, 0xf2, temp_input | 0x0010); 420{
414 udelay(10); 421 switch (qc->id) {
422 case V4L2_CID_BRIGHTNESS:
423 v4l2_ctrl_query_fill(qc, -128, 127, 1, 0);
415 break; 424 break;
416 }
417
418 case DECODER_SET_INPUT:
419 {
420 int *iarg = arg, data;
421
422 /* RJ: *iarg = 0: ST8 (PCTV) input
423 *iarg = 1: COMPOSITE input
424 *iarg = 2: SVHS input */
425
426 const int input[3][2] = {
427 {0x0c, 0},
428 {0x0d, 0},
429 {0x0e, 1}
430 };
431 425
432 if (*iarg < 0 || *iarg > 2) 426 case V4L2_CID_CONTRAST:
433 return -EINVAL; 427 v4l2_ctrl_query_fill(qc, 0, 63, 1, 32);
434
435 v4l_dbg(1, debug, client, "input switched to %s\n", inputs[*iarg]);
436
437 vpx3220_write(client, 0x33, input[*iarg][0]);
438
439 data = vpx3220_fp_read(client, 0xf2) & ~(0x0020);
440 if (data < 0)
441 return data;
442 /* 0x0010 is required to latch the setting */
443 vpx3220_fp_write(client, 0xf2,
444 data | (input[*iarg][1] << 5) | 0x0010);
445
446 udelay(10);
447 break; 428 break;
448 }
449 429
450 case DECODER_SET_OUTPUT: 430 case V4L2_CID_SATURATION:
451 { 431 v4l2_ctrl_query_fill(qc, 0, 4095, 1, 2048);
452 int *iarg = arg; 432 break;
453 433
454 /* not much choice of outputs */ 434 case V4L2_CID_HUE:
455 if (*iarg != 0) { 435 v4l2_ctrl_query_fill(qc, -512, 511, 1, 0);
456 return -EINVAL;
457 }
458 break; 436 break;
459 }
460 437
461 case DECODER_ENABLE_OUTPUT: 438 default:
462 { 439 return -EINVAL;
463 int *iarg = arg; 440 }
441 return 0;
442}
464 443
465 v4l_dbg(1, debug, client, "DECODER_ENABLE_OUTPUT %d\n", *iarg); 444static int vpx3220_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
445{
446 struct vpx3220 *decoder = to_vpx3220(sd);
466 447
467 vpx3220_write(client, 0xf2, (*iarg ? 0x1b : 0x00)); 448 switch (ctrl->id) {
449 case V4L2_CID_BRIGHTNESS:
450 ctrl->value = decoder->bright;
451 break;
452 case V4L2_CID_CONTRAST:
453 ctrl->value = decoder->contrast;
468 break; 454 break;
455 case V4L2_CID_SATURATION:
456 ctrl->value = decoder->sat;
457 break;
458 case V4L2_CID_HUE:
459 ctrl->value = decoder->hue;
460 break;
461 default:
462 return -EINVAL;
469 } 463 }
464 return 0;
465}
470 466
471 case DECODER_SET_PICTURE: 467static int vpx3220_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
472 { 468{
473 struct video_picture *pic = arg; 469 struct vpx3220 *decoder = to_vpx3220(sd);
474 470
475 if (decoder->bright != pic->brightness) { 471 switch (ctrl->id) {
476 /* We want -128 to 128 we get 0-65535 */ 472 case V4L2_CID_BRIGHTNESS:
477 decoder->bright = pic->brightness; 473 if (decoder->bright != ctrl->value) {
478 vpx3220_write(client, 0xe6, 474 decoder->bright = ctrl->value;
479 (decoder->bright - 32768) >> 8); 475 vpx3220_write(sd, 0xe6, decoder->bright);
480 } 476 }
481 if (decoder->contrast != pic->contrast) { 477 break;
482 /* We want 0 to 64 we get 0-65535 */ 478 case V4L2_CID_CONTRAST:
479 if (decoder->contrast != ctrl->value) {
483 /* Bit 7 and 8 is for noise shaping */ 480 /* Bit 7 and 8 is for noise shaping */
484 decoder->contrast = pic->contrast; 481 decoder->contrast = ctrl->value;
485 vpx3220_write(client, 0xe7, 482 vpx3220_write(sd, 0xe7, decoder->contrast + 192);
486 (decoder->contrast >> 10) + 192);
487 } 483 }
488 if (decoder->sat != pic->colour) { 484 break;
489 /* We want 0 to 4096 we get 0-65535 */ 485 case V4L2_CID_SATURATION:
490 decoder->sat = pic->colour; 486 if (decoder->sat != ctrl->value) {
491 vpx3220_fp_write(client, 0xa0, 487 decoder->sat = ctrl->value;
492 decoder->sat >> 4); 488 vpx3220_fp_write(sd, 0xa0, decoder->sat);
493 } 489 }
494 if (decoder->hue != pic->hue) { 490 break;
495 /* We want -512 to 512 we get 0-65535 */ 491 case V4L2_CID_HUE:
496 decoder->hue = pic->hue; 492 if (decoder->hue != ctrl->value) {
497 vpx3220_fp_write(client, 0x1c, 493 decoder->hue = ctrl->value;
498 ((decoder->hue - 32768) >> 6) & 0xFFF); 494 vpx3220_fp_write(sd, 0x1c, decoder->hue);
499 } 495 }
500 break; 496 break;
501 }
502
503 default: 497 default:
504 return -EINVAL; 498 return -EINVAL;
505 } 499 }
506
507 return 0; 500 return 0;
508} 501}
509 502
510static int vpx3220_init_client(struct i2c_client *client) 503static int vpx3220_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
511{ 504{
512 vpx3220_write_block(client, init_common, sizeof(init_common)); 505 struct vpx3220 *decoder = to_vpx3220(sd);
513 vpx3220_write_fp_block(client, init_fp, sizeof(init_fp) >> 1); 506 struct i2c_client *client = v4l2_get_subdevdata(sd);
514 /* Default to PAL */
515 vpx3220_write_fp_block(client, init_pal, sizeof(init_pal) >> 1);
516 507
517 return 0; 508 return v4l2_chip_ident_i2c_client(client, chip, decoder->ident, 0);
518} 509}
519 510
511/* ----------------------------------------------------------------------- */
512
513static const struct v4l2_subdev_core_ops vpx3220_core_ops = {
514 .g_chip_ident = vpx3220_g_chip_ident,
515 .init = vpx3220_init,
516 .g_ctrl = vpx3220_g_ctrl,
517 .s_ctrl = vpx3220_s_ctrl,
518 .queryctrl = vpx3220_queryctrl,
519};
520
521static const struct v4l2_subdev_tuner_ops vpx3220_tuner_ops = {
522 .s_std = vpx3220_s_std,
523};
524
525static const struct v4l2_subdev_video_ops vpx3220_video_ops = {
526 .s_routing = vpx3220_s_routing,
527 .s_stream = vpx3220_s_stream,
528 .querystd = vpx3220_querystd,
529 .g_input_status = vpx3220_g_input_status,
530};
531
532static const struct v4l2_subdev_ops vpx3220_ops = {
533 .core = &vpx3220_core_ops,
534 .tuner = &vpx3220_tuner_ops,
535 .video = &vpx3220_video_ops,
536};
537
520/* ----------------------------------------------------------------------- 538/* -----------------------------------------------------------------------
521 * Client management code 539 * Client management code
522 */ 540 */
523 541
524static unsigned short normal_i2c[] = { 0x86 >> 1, 0x8e >> 1, I2C_CLIENT_END };
525
526I2C_CLIENT_INSMOD;
527
528static int vpx3220_probe(struct i2c_client *client, 542static int vpx3220_probe(struct i2c_client *client,
529 const struct i2c_device_id *id) 543 const struct i2c_device_id *id)
530{ 544{
531 struct vpx3220 *decoder; 545 struct vpx3220 *decoder;
546 struct v4l2_subdev *sd;
532 const char *name = NULL; 547 const char *name = NULL;
533 u8 ver; 548 u8 ver;
534 u16 pn; 549 u16 pn;
@@ -541,18 +556,20 @@ static int vpx3220_probe(struct i2c_client *client,
541 decoder = kzalloc(sizeof(struct vpx3220), GFP_KERNEL); 556 decoder = kzalloc(sizeof(struct vpx3220), GFP_KERNEL);
542 if (decoder == NULL) 557 if (decoder == NULL)
543 return -ENOMEM; 558 return -ENOMEM;
544 decoder->norm = VIDEO_MODE_PAL; 559 sd = &decoder->sd;
560 v4l2_i2c_subdev_init(sd, client, &vpx3220_ops);
561 decoder->norm = V4L2_STD_PAL;
545 decoder->input = 0; 562 decoder->input = 0;
546 decoder->enable = 1; 563 decoder->enable = 1;
547 decoder->bright = 32768; 564 decoder->bright = 32768;
548 decoder->contrast = 32768; 565 decoder->contrast = 32768;
549 decoder->hue = 32768; 566 decoder->hue = 32768;
550 decoder->sat = 32768; 567 decoder->sat = 32768;
551 i2c_set_clientdata(client, decoder);
552 568
553 ver = i2c_smbus_read_byte_data(client, 0x00); 569 ver = i2c_smbus_read_byte_data(client, 0x00);
554 pn = (i2c_smbus_read_byte_data(client, 0x02) << 8) + 570 pn = (i2c_smbus_read_byte_data(client, 0x02) << 8) +
555 i2c_smbus_read_byte_data(client, 0x01); 571 i2c_smbus_read_byte_data(client, 0x01);
572 decoder->ident = V4L2_IDENT_VPX3220A;
556 if (ver == 0xec) { 573 if (ver == 0xec) {
557 switch (pn) { 574 switch (pn) {
558 case 0x4680: 575 case 0x4680:
@@ -560,26 +577,34 @@ static int vpx3220_probe(struct i2c_client *client,
560 break; 577 break;
561 case 0x4260: 578 case 0x4260:
562 name = "vpx3216b"; 579 name = "vpx3216b";
580 decoder->ident = V4L2_IDENT_VPX3216B;
563 break; 581 break;
564 case 0x4280: 582 case 0x4280:
565 name = "vpx3214c"; 583 name = "vpx3214c";
584 decoder->ident = V4L2_IDENT_VPX3214C;
566 break; 585 break;
567 } 586 }
568 } 587 }
569 if (name) 588 if (name)
570 v4l_info(client, "%s found @ 0x%x (%s)\n", name, 589 v4l2_info(sd, "%s found @ 0x%x (%s)\n", name,
571 client->addr << 1, client->adapter->name); 590 client->addr << 1, client->adapter->name);
572 else 591 else
573 v4l_info(client, "chip (%02x:%04x) found @ 0x%x (%s)\n", 592 v4l2_info(sd, "chip (%02x:%04x) found @ 0x%x (%s)\n",
574 ver, pn, client->addr << 1, client->adapter->name); 593 ver, pn, client->addr << 1, client->adapter->name);
575 594
576 vpx3220_init_client(client); 595 vpx3220_write_block(sd, init_common, sizeof(init_common));
596 vpx3220_write_fp_block(sd, init_fp, sizeof(init_fp) >> 1);
597 /* Default to PAL */
598 vpx3220_write_fp_block(sd, init_pal, sizeof(init_pal) >> 1);
577 return 0; 599 return 0;
578} 600}
579 601
580static int vpx3220_remove(struct i2c_client *client) 602static int vpx3220_remove(struct i2c_client *client)
581{ 603{
582 kfree(i2c_get_clientdata(client)); 604 struct v4l2_subdev *sd = i2c_get_clientdata(client);
605
606 v4l2_device_unregister_subdev(sd);
607 kfree(to_vpx3220(sd));
583 return 0; 608 return 0;
584} 609}
585 610
@@ -593,8 +618,6 @@ MODULE_DEVICE_TABLE(i2c, vpx3220_id);
593 618
594static struct v4l2_i2c_driver_data v4l2_i2c_data = { 619static struct v4l2_i2c_driver_data v4l2_i2c_data = {
595 .name = "vpx3220", 620 .name = "vpx3220",
596 .driverid = I2C_DRIVERID_VPX3220,
597 .command = vpx3220_command,
598 .probe = vpx3220_probe, 621 .probe = vpx3220_probe,
599 .remove = vpx3220_remove, 622 .remove = vpx3220_remove,
600 .id_table = vpx3220_id, 623 .id_table = vpx3220_id,
diff --git a/drivers/media/video/w9966.c b/drivers/media/video/w9966.c
index 038ff32b01b8..dcade619cbd8 100644
--- a/drivers/media/video/w9966.c
+++ b/drivers/media/video/w9966.c
@@ -57,7 +57,7 @@
57#include <linux/module.h> 57#include <linux/module.h>
58#include <linux/init.h> 58#include <linux/init.h>
59#include <linux/delay.h> 59#include <linux/delay.h>
60#include <linux/videodev2.h> 60#include <linux/videodev.h>
61#include <media/v4l2-common.h> 61#include <media/v4l2-common.h>
62#include <media/v4l2-ioctl.h> 62#include <media/v4l2-ioctl.h>
63#include <linux/parport.h> 63#include <linux/parport.h>
diff --git a/drivers/media/video/w9968cf.c b/drivers/media/video/w9968cf.c
index 105a832531f2..3b08bc4af909 100644
--- a/drivers/media/video/w9968cf.c
+++ b/drivers/media/video/w9968cf.c
@@ -42,6 +42,7 @@
42#include <asm/page.h> 42#include <asm/page.h>
43#include <asm/uaccess.h> 43#include <asm/uaccess.h>
44#include <linux/page-flags.h> 44#include <linux/page-flags.h>
45#include <linux/videodev.h>
45#include <media/v4l2-ioctl.h> 46#include <media/v4l2-ioctl.h>
46 47
47#include "w9968cf.h" 48#include "w9968cf.h"
@@ -68,7 +69,6 @@ MODULE_VERSION(W9968CF_MODULE_VERSION);
68MODULE_LICENSE(W9968CF_MODULE_LICENSE); 69MODULE_LICENSE(W9968CF_MODULE_LICENSE);
69MODULE_SUPPORTED_DEVICE("Video"); 70MODULE_SUPPORTED_DEVICE("Video");
70 71
71static int ovmod_load = W9968CF_OVMOD_LOAD;
72static unsigned short simcams = W9968CF_SIMCAMS; 72static unsigned short simcams = W9968CF_SIMCAMS;
73static short video_nr[]={[0 ... W9968CF_MAX_DEVICES-1] = -1}; /*-1=first free*/ 73static short video_nr[]={[0 ... W9968CF_MAX_DEVICES-1] = -1}; /*-1=first free*/
74static unsigned int packet_size[] = {[0 ... W9968CF_MAX_DEVICES-1] = 74static unsigned int packet_size[] = {[0 ... W9968CF_MAX_DEVICES-1] =
@@ -111,9 +111,6 @@ static int specific_debug = W9968CF_SPECIFIC_DEBUG;
111 111
112static unsigned int param_nv[24]; /* number of values per parameter */ 112static unsigned int param_nv[24]; /* number of values per parameter */
113 113
114#ifdef CONFIG_MODULES
115module_param(ovmod_load, bool, 0644);
116#endif
117module_param(simcams, ushort, 0644); 114module_param(simcams, ushort, 0644);
118module_param_array(video_nr, short, &param_nv[0], 0444); 115module_param_array(video_nr, short, &param_nv[0], 0444);
119module_param_array(packet_size, uint, &param_nv[1], 0444); 116module_param_array(packet_size, uint, &param_nv[1], 0444);
@@ -144,18 +141,6 @@ module_param(debug, ushort, 0644);
144module_param(specific_debug, bool, 0644); 141module_param(specific_debug, bool, 0644);
145#endif 142#endif
146 143
147#ifdef CONFIG_MODULES
148MODULE_PARM_DESC(ovmod_load,
149 "\n<0|1> Automatic 'ovcamchip' module loading."
150 "\n0 disabled, 1 enabled."
151 "\nIf enabled,'insmod' searches for the required 'ovcamchip'"
152 "\nmodule in the system, according to its configuration, and"
153 "\nattempts to load that module automatically. This action is"
154 "\nperformed once as soon as the 'w9968cf' module is loaded"
155 "\ninto memory."
156 "\nDefault value is "__MODULE_STRING(W9968CF_OVMOD_LOAD)"."
157 "\n");
158#endif
159MODULE_PARM_DESC(simcams, 144MODULE_PARM_DESC(simcams,
160 "\n<n> Number of cameras allowed to stream simultaneously." 145 "\n<n> Number of cameras allowed to stream simultaneously."
161 "\nn may vary from 0 to " 146 "\nn may vary from 0 to "
@@ -443,8 +428,6 @@ static int w9968cf_i2c_smbus_xfer(struct i2c_adapter*, u16 addr,
443 unsigned short flags, char read_write, 428 unsigned short flags, char read_write,
444 u8 command, int size, union i2c_smbus_data*); 429 u8 command, int size, union i2c_smbus_data*);
445static u32 w9968cf_i2c_func(struct i2c_adapter*); 430static u32 w9968cf_i2c_func(struct i2c_adapter*);
446static int w9968cf_i2c_attach_inform(struct i2c_client*);
447static int w9968cf_i2c_detach_inform(struct i2c_client*);
448 431
449/* Memory management */ 432/* Memory management */
450static void* rvmalloc(unsigned long size); 433static void* rvmalloc(unsigned long size);
@@ -1443,19 +1426,11 @@ w9968cf_i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
1443 unsigned short flags, char read_write, u8 command, 1426 unsigned short flags, char read_write, u8 command,
1444 int size, union i2c_smbus_data *data) 1427 int size, union i2c_smbus_data *data)
1445{ 1428{
1446 struct w9968cf_device* cam = i2c_get_adapdata(adapter); 1429 struct v4l2_device *v4l2_dev = i2c_get_adapdata(adapter);
1430 struct w9968cf_device *cam = to_cam(v4l2_dev);
1447 u8 i; 1431 u8 i;
1448 int err = 0; 1432 int err = 0;
1449 1433
1450 switch (addr) {
1451 case OV6xx0_SID:
1452 case OV7xx0_SID:
1453 break;
1454 default:
1455 DBG(4, "Rejected slave ID 0x%04X", addr)
1456 return -EINVAL;
1457 }
1458
1459 if (size == I2C_SMBUS_BYTE) { 1434 if (size == I2C_SMBUS_BYTE) {
1460 /* Why addr <<= 1? See OVXXX0_SID defines in ovcamchip.h */ 1435 /* Why addr <<= 1? See OVXXX0_SID defines in ovcamchip.h */
1461 addr <<= 1; 1436 addr <<= 1;
@@ -1463,8 +1438,17 @@ w9968cf_i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
1463 if (read_write == I2C_SMBUS_WRITE) 1438 if (read_write == I2C_SMBUS_WRITE)
1464 err = w9968cf_i2c_adap_write_byte(cam, addr, command); 1439 err = w9968cf_i2c_adap_write_byte(cam, addr, command);
1465 else if (read_write == I2C_SMBUS_READ) 1440 else if (read_write == I2C_SMBUS_READ)
1466 err = w9968cf_i2c_adap_read_byte(cam,addr,&data->byte); 1441 for (i = 1; i <= W9968CF_I2C_RW_RETRIES; i++) {
1467 1442 err = w9968cf_i2c_adap_read_byte(cam, addr,
1443 &data->byte);
1444 if (err) {
1445 if (w9968cf_smbus_refresh_bus(cam)) {
1446 err = -EIO;
1447 break;
1448 }
1449 } else
1450 break;
1451 }
1468 } else if (size == I2C_SMBUS_BYTE_DATA) { 1452 } else if (size == I2C_SMBUS_BYTE_DATA) {
1469 addr <<= 1; 1453 addr <<= 1;
1470 1454
@@ -1491,7 +1475,6 @@ w9968cf_i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
1491 DBG(4, "Unsupported I2C transfer mode (%d)", size) 1475 DBG(4, "Unsupported I2C transfer mode (%d)", size)
1492 return -EINVAL; 1476 return -EINVAL;
1493 } 1477 }
1494
1495 return err; 1478 return err;
1496} 1479}
1497 1480
@@ -1504,44 +1487,6 @@ static u32 w9968cf_i2c_func(struct i2c_adapter* adap)
1504} 1487}
1505 1488
1506 1489
1507static int w9968cf_i2c_attach_inform(struct i2c_client* client)
1508{
1509 struct w9968cf_device* cam = i2c_get_adapdata(client->adapter);
1510 int id = client->driver->id, err = 0;
1511
1512 if (id == I2C_DRIVERID_OVCAMCHIP) {
1513 cam->sensor_client = client;
1514 err = w9968cf_sensor_init(cam);
1515 if (err) {
1516 cam->sensor_client = NULL;
1517 return err;
1518 }
1519 } else {
1520 DBG(4, "Rejected client [%s] with driver [%s]",
1521 client->name, client->driver->driver.name)
1522 return -EINVAL;
1523 }
1524
1525 DBG(5, "I2C attach client [%s] with driver [%s]",
1526 client->name, client->driver->driver.name)
1527
1528 return 0;
1529}
1530
1531
1532static int w9968cf_i2c_detach_inform(struct i2c_client* client)
1533{
1534 struct w9968cf_device* cam = i2c_get_adapdata(client->adapter);
1535
1536 if (cam->sensor_client == client)
1537 cam->sensor_client = NULL;
1538
1539 DBG(5, "I2C detach client [%s]", client->name)
1540
1541 return 0;
1542}
1543
1544
1545static int w9968cf_i2c_init(struct w9968cf_device* cam) 1490static int w9968cf_i2c_init(struct w9968cf_device* cam)
1546{ 1491{
1547 int err = 0; 1492 int err = 0;
@@ -1554,15 +1499,13 @@ static int w9968cf_i2c_init(struct w9968cf_device* cam)
1554 static struct i2c_adapter adap = { 1499 static struct i2c_adapter adap = {
1555 .id = I2C_HW_SMBUS_W9968CF, 1500 .id = I2C_HW_SMBUS_W9968CF,
1556 .owner = THIS_MODULE, 1501 .owner = THIS_MODULE,
1557 .client_register = w9968cf_i2c_attach_inform,
1558 .client_unregister = w9968cf_i2c_detach_inform,
1559 .algo = &algo, 1502 .algo = &algo,
1560 }; 1503 };
1561 1504
1562 memcpy(&cam->i2c_adapter, &adap, sizeof(struct i2c_adapter)); 1505 memcpy(&cam->i2c_adapter, &adap, sizeof(struct i2c_adapter));
1563 strcpy(cam->i2c_adapter.name, "w9968cf"); 1506 strcpy(cam->i2c_adapter.name, "w9968cf");
1564 cam->i2c_adapter.dev.parent = &cam->usbdev->dev; 1507 cam->i2c_adapter.dev.parent = &cam->usbdev->dev;
1565 i2c_set_adapdata(&cam->i2c_adapter, cam); 1508 i2c_set_adapdata(&cam->i2c_adapter, &cam->v4l2_dev);
1566 1509
1567 DBG(6, "Registering I2C adapter with kernel...") 1510 DBG(6, "Registering I2C adapter with kernel...")
1568 1511
@@ -2165,13 +2108,9 @@ w9968cf_sensor_get_control(struct w9968cf_device* cam, int cid, int* val)
2165static int 2108static int
2166w9968cf_sensor_cmd(struct w9968cf_device* cam, unsigned int cmd, void* arg) 2109w9968cf_sensor_cmd(struct w9968cf_device* cam, unsigned int cmd, void* arg)
2167{ 2110{
2168 struct i2c_client* c = cam->sensor_client; 2111 int rc;
2169 int rc = 0;
2170
2171 if (!c || !c->driver || !c->driver->command)
2172 return -EINVAL;
2173 2112
2174 rc = c->driver->command(c, cmd, arg); 2113 rc = v4l2_subdev_call(cam->sensor_sd, core, ioctl, cmd, arg);
2175 /* The I2C driver returns -EPERM on non-supported controls */ 2114 /* The I2C driver returns -EPERM on non-supported controls */
2176 return (rc < 0 && rc != -EPERM) ? rc : 0; 2115 return (rc < 0 && rc != -EPERM) ? rc : 0;
2177} 2116}
@@ -2346,7 +2285,7 @@ static int w9968cf_sensor_init(struct w9968cf_device* cam)
2346 goto error; 2285 goto error;
2347 2286
2348 /* NOTE: Make sure width and height are a multiple of 16 */ 2287 /* NOTE: Make sure width and height are a multiple of 16 */
2349 switch (cam->sensor_client->addr) { 2288 switch (v4l2_i2c_subdev_addr(cam->sensor_sd)) {
2350 case OV6xx0_SID: 2289 case OV6xx0_SID:
2351 cam->maxwidth = 352; 2290 cam->maxwidth = 352;
2352 cam->maxheight = 288; 2291 cam->maxheight = 288;
@@ -2651,6 +2590,7 @@ static void w9968cf_release_resources(struct w9968cf_device* cam)
2651 w9968cf_deallocate_memory(cam); 2590 w9968cf_deallocate_memory(cam);
2652 kfree(cam->control_buffer); 2591 kfree(cam->control_buffer);
2653 kfree(cam->data_buffer); 2592 kfree(cam->data_buffer);
2593 v4l2_device_unregister(&cam->v4l2_dev);
2654 2594
2655 mutex_unlock(&w9968cf_devlist_mutex); 2595 mutex_unlock(&w9968cf_devlist_mutex);
2656} 2596}
@@ -3480,6 +3420,11 @@ w9968cf_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
3480 struct list_head* ptr; 3420 struct list_head* ptr;
3481 u8 sc = 0; /* number of simultaneous cameras */ 3421 u8 sc = 0; /* number of simultaneous cameras */
3482 static unsigned short dev_nr; /* 0 - we are handling device number n */ 3422 static unsigned short dev_nr; /* 0 - we are handling device number n */
3423 static unsigned short addrs[] = {
3424 OV7xx0_SID,
3425 OV6xx0_SID,
3426 I2C_CLIENT_END
3427 };
3483 3428
3484 if (le16_to_cpu(udev->descriptor.idVendor) == winbond_id_table[0].idVendor && 3429 if (le16_to_cpu(udev->descriptor.idVendor) == winbond_id_table[0].idVendor &&
3485 le16_to_cpu(udev->descriptor.idProduct) == winbond_id_table[0].idProduct) 3430 le16_to_cpu(udev->descriptor.idProduct) == winbond_id_table[0].idProduct)
@@ -3495,12 +3440,14 @@ w9968cf_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
3495 if (!cam) 3440 if (!cam)
3496 return -ENOMEM; 3441 return -ENOMEM;
3497 3442
3443 err = v4l2_device_register(&udev->dev, &cam->v4l2_dev);
3444 if (err)
3445 goto fail0;
3446
3498 mutex_init(&cam->dev_mutex); 3447 mutex_init(&cam->dev_mutex);
3499 mutex_lock(&cam->dev_mutex); 3448 mutex_lock(&cam->dev_mutex);
3500 3449
3501 cam->usbdev = udev; 3450 cam->usbdev = udev;
3502 /* NOTE: a local copy is used to avoid possible race conditions */
3503 memcpy(&cam->dev, &udev->dev, sizeof(struct device));
3504 3451
3505 DBG(2, "%s detected", symbolic(camlist, mod_id)) 3452 DBG(2, "%s detected", symbolic(camlist, mod_id))
3506 3453
@@ -3549,7 +3496,7 @@ w9968cf_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
3549 cam->v4ldev->minor = video_nr[dev_nr]; 3496 cam->v4ldev->minor = video_nr[dev_nr];
3550 cam->v4ldev->release = video_device_release; 3497 cam->v4ldev->release = video_device_release;
3551 video_set_drvdata(cam->v4ldev, cam); 3498 video_set_drvdata(cam->v4ldev, cam);
3552 cam->v4ldev->parent = &cam->dev; 3499 cam->v4ldev->v4l2_dev = &cam->v4l2_dev;
3553 3500
3554 err = video_register_device(cam->v4ldev, VFL_TYPE_GRABBER, 3501 err = video_register_device(cam->v4ldev, VFL_TYPE_GRABBER,
3555 video_nr[dev_nr]); 3502 video_nr[dev_nr]);
@@ -3576,9 +3523,13 @@ w9968cf_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
3576 w9968cf_turn_on_led(cam); 3523 w9968cf_turn_on_led(cam);
3577 3524
3578 w9968cf_i2c_init(cam); 3525 w9968cf_i2c_init(cam);
3526 cam->sensor_sd = v4l2_i2c_new_probed_subdev(&cam->i2c_adapter,
3527 "ovcamchip", "ovcamchip", addrs);
3579 3528
3580 usb_set_intfdata(intf, cam); 3529 usb_set_intfdata(intf, cam);
3581 mutex_unlock(&cam->dev_mutex); 3530 mutex_unlock(&cam->dev_mutex);
3531
3532 err = w9968cf_sensor_init(cam);
3582 return 0; 3533 return 0;
3583 3534
3584fail: /* Free unused memory */ 3535fail: /* Free unused memory */
@@ -3587,6 +3538,8 @@ fail: /* Free unused memory */
3587 if (cam->v4ldev) 3538 if (cam->v4ldev)
3588 video_device_release(cam->v4ldev); 3539 video_device_release(cam->v4ldev);
3589 mutex_unlock(&cam->dev_mutex); 3540 mutex_unlock(&cam->dev_mutex);
3541 v4l2_device_unregister(&cam->v4l2_dev);
3542fail0:
3590 kfree(cam); 3543 kfree(cam);
3591 return err; 3544 return err;
3592} 3545}
@@ -3597,15 +3550,16 @@ static void w9968cf_usb_disconnect(struct usb_interface* intf)
3597 struct w9968cf_device* cam = 3550 struct w9968cf_device* cam =
3598 (struct w9968cf_device*)usb_get_intfdata(intf); 3551 (struct w9968cf_device*)usb_get_intfdata(intf);
3599 3552
3600 down_write(&w9968cf_disconnect);
3601
3602 if (cam) { 3553 if (cam) {
3554 down_write(&w9968cf_disconnect);
3603 /* Prevent concurrent accesses to data */ 3555 /* Prevent concurrent accesses to data */
3604 mutex_lock(&cam->dev_mutex); 3556 mutex_lock(&cam->dev_mutex);
3605 3557
3606 cam->disconnected = 1; 3558 cam->disconnected = 1;
3607 3559
3608 DBG(2, "Disconnecting %s...", symbolic(camlist, cam->id)) 3560 DBG(2, "Disconnecting %s...", symbolic(camlist, cam->id));
3561
3562 v4l2_device_disconnect(&cam->v4l2_dev);
3609 3563
3610 wake_up_interruptible_all(&cam->open); 3564 wake_up_interruptible_all(&cam->open);
3611 3565
@@ -3621,12 +3575,12 @@ static void w9968cf_usb_disconnect(struct usb_interface* intf)
3621 w9968cf_release_resources(cam); 3575 w9968cf_release_resources(cam);
3622 3576
3623 mutex_unlock(&cam->dev_mutex); 3577 mutex_unlock(&cam->dev_mutex);
3578 up_write(&w9968cf_disconnect);
3624 3579
3625 if (!cam->users) 3580 if (!cam->users) {
3626 kfree(cam); 3581 kfree(cam);
3582 }
3627 } 3583 }
3628
3629 up_write(&w9968cf_disconnect);
3630} 3584}
3631 3585
3632 3586
@@ -3650,9 +3604,6 @@ static int __init w9968cf_module_init(void)
3650 KDBG(2, W9968CF_MODULE_NAME" "W9968CF_MODULE_VERSION) 3604 KDBG(2, W9968CF_MODULE_NAME" "W9968CF_MODULE_VERSION)
3651 KDBG(3, W9968CF_MODULE_AUTHOR) 3605 KDBG(3, W9968CF_MODULE_AUTHOR)
3652 3606
3653 if (ovmod_load)
3654 request_module("ovcamchip");
3655
3656 if ((err = usb_register(&w9968cf_usb_driver))) 3607 if ((err = usb_register(&w9968cf_usb_driver)))
3657 return err; 3608 return err;
3658 3609
diff --git a/drivers/media/video/w9968cf.h b/drivers/media/video/w9968cf.h
index 30032e15e23c..fdfc6a4e1c8f 100644
--- a/drivers/media/video/w9968cf.h
+++ b/drivers/media/video/w9968cf.h
@@ -33,6 +33,7 @@
33#include <linux/rwsem.h> 33#include <linux/rwsem.h>
34#include <linux/mutex.h> 34#include <linux/mutex.h>
35 35
36#include <media/v4l2-device.h>
36#include <media/ovcamchip.h> 37#include <media/ovcamchip.h>
37 38
38#include "w9968cf_vpp.h" 39#include "w9968cf_vpp.h"
@@ -42,7 +43,6 @@
42 * Default values * 43 * Default values *
43 ****************************************************************************/ 44 ****************************************************************************/
44 45
45#define W9968CF_OVMOD_LOAD 1 /* automatic 'ovcamchip' module loading */
46#define W9968CF_VPPMOD_LOAD 1 /* automatic 'w9968cf-vpp' module loading */ 46#define W9968CF_VPPMOD_LOAD 1 /* automatic 'w9968cf-vpp' module loading */
47 47
48/* Comment/uncomment the following line to enable/disable debugging messages */ 48/* Comment/uncomment the following line to enable/disable debugging messages */
@@ -195,10 +195,9 @@ enum w9968cf_vpp_flag {
195 195
196/* Main device driver structure */ 196/* Main device driver structure */
197struct w9968cf_device { 197struct w9968cf_device {
198 struct device dev; /* device structure */
199
200 enum w9968cf_model_id id; /* private device identifier */ 198 enum w9968cf_model_id id; /* private device identifier */
201 199
200 struct v4l2_device v4l2_dev;
202 struct video_device* v4ldev; /* -> V4L structure */ 201 struct video_device* v4ldev; /* -> V4L structure */
203 struct list_head v4llist; /* entry of the list of V4L cameras */ 202 struct list_head v4llist; /* entry of the list of V4L cameras */
204 203
@@ -265,7 +264,7 @@ struct w9968cf_device {
265 264
266 /* I2C interface to kernel */ 265 /* I2C interface to kernel */
267 struct i2c_adapter i2c_adapter; 266 struct i2c_adapter i2c_adapter;
268 struct i2c_client* sensor_client; 267 struct v4l2_subdev *sensor_sd;
269 268
270 /* Locks */ 269 /* Locks */
271 struct mutex dev_mutex, /* for probe, disconnect,open and close */ 270 struct mutex dev_mutex, /* for probe, disconnect,open and close */
@@ -277,6 +276,11 @@ struct w9968cf_device {
277 char command[16]; /* name of the program holding the device */ 276 char command[16]; /* name of the program holding the device */
278}; 277};
279 278
279static inline struct w9968cf_device *to_cam(struct v4l2_device *v4l2_dev)
280{
281 return container_of(v4l2_dev, struct w9968cf_device, v4l2_dev);
282}
283
280 284
281/**************************************************************************** 285/****************************************************************************
282 * Macros for debugging * 286 * Macros for debugging *
@@ -291,14 +295,14 @@ struct w9968cf_device {
291 if ( ((specific_debug) && (debug == (level))) || \ 295 if ( ((specific_debug) && (debug == (level))) || \
292 ((!specific_debug) && (debug >= (level))) ) { \ 296 ((!specific_debug) && (debug >= (level))) ) { \
293 if ((level) == 1) \ 297 if ((level) == 1) \
294 dev_err(&cam->dev, fmt "\n", ## args); \ 298 v4l2_err(&cam->v4l2_dev, fmt "\n", ## args); \
295 else if ((level) == 2 || (level) == 3) \ 299 else if ((level) == 2 || (level) == 3) \
296 dev_info(&cam->dev, fmt "\n", ## args); \ 300 v4l2_info(&cam->v4l2_dev, fmt "\n", ## args); \
297 else if ((level) == 4) \ 301 else if ((level) == 4) \
298 dev_warn(&cam->dev, fmt "\n", ## args); \ 302 v4l2_warn(&cam->v4l2_dev, fmt "\n", ## args); \
299 else if ((level) >= 5) \ 303 else if ((level) >= 5) \
300 dev_info(&cam->dev, "[%s:%d] " fmt "\n", \ 304 v4l2_info(&cam->v4l2_dev, "[%s:%d] " fmt "\n", \
301 __func__, __LINE__ , ## args); \ 305 __func__, __LINE__ , ## args); \
302 } \ 306 } \
303} 307}
304/* For generic kernel (not device specific) messages */ 308/* For generic kernel (not device specific) messages */
@@ -321,7 +325,7 @@ struct w9968cf_device {
321 325
322#undef PDBG 326#undef PDBG
323#define PDBG(fmt, args...) \ 327#define PDBG(fmt, args...) \
324dev_info(&cam->dev, "[%s:%d] " fmt "\n", __func__, __LINE__ , ## args); 328v4l2_info(&cam->v4l2_dev, "[%s:%d] " fmt "\n", __func__, __LINE__ , ## args);
325 329
326#undef PDBGG 330#undef PDBGG
327#define PDBGG(fmt, args...) do {;} while(0); /* nothing: it's a placeholder */ 331#define PDBGG(fmt, args...) do {;} while(0); /* nothing: it's a placeholder */
diff --git a/drivers/media/video/wm8739.c b/drivers/media/video/wm8739.c
index f2864d5cd180..b572ce288e14 100644
--- a/drivers/media/video/wm8739.c
+++ b/drivers/media/video/wm8739.c
@@ -252,11 +252,6 @@ static int wm8739_log_status(struct v4l2_subdev *sd)
252 return 0; 252 return 0;
253} 253}
254 254
255static int wm8739_command(struct i2c_client *client, unsigned cmd, void *arg)
256{
257 return v4l2_subdev_command(i2c_get_clientdata(client), cmd, arg);
258}
259
260/* ----------------------------------------------------------------------- */ 255/* ----------------------------------------------------------------------- */
261 256
262static const struct v4l2_subdev_core_ops wm8739_core_ops = { 257static const struct v4l2_subdev_core_ops wm8739_core_ops = {
@@ -343,8 +338,6 @@ MODULE_DEVICE_TABLE(i2c, wm8739_id);
343 338
344static struct v4l2_i2c_driver_data v4l2_i2c_data = { 339static struct v4l2_i2c_driver_data v4l2_i2c_data = {
345 .name = "wm8739", 340 .name = "wm8739",
346 .driverid = I2C_DRIVERID_WM8739,
347 .command = wm8739_command,
348 .probe = wm8739_probe, 341 .probe = wm8739_probe,
349 .remove = wm8739_remove, 342 .remove = wm8739_remove,
350 .id_table = wm8739_id, 343 .id_table = wm8739_id,
diff --git a/drivers/media/video/wm8775.c b/drivers/media/video/wm8775.c
index 53fcd42843e0..eddf11abe1d9 100644
--- a/drivers/media/video/wm8775.c
+++ b/drivers/media/video/wm8775.c
@@ -34,15 +34,12 @@
34#include <linux/videodev2.h> 34#include <linux/videodev2.h>
35#include <media/v4l2-device.h> 35#include <media/v4l2-device.h>
36#include <media/v4l2-chip-ident.h> 36#include <media/v4l2-chip-ident.h>
37#include <media/v4l2-i2c-drv-legacy.h> 37#include <media/v4l2-i2c-drv.h>
38 38
39MODULE_DESCRIPTION("wm8775 driver"); 39MODULE_DESCRIPTION("wm8775 driver");
40MODULE_AUTHOR("Ulf Eklund, Hans Verkuil"); 40MODULE_AUTHOR("Ulf Eklund, Hans Verkuil");
41MODULE_LICENSE("GPL"); 41MODULE_LICENSE("GPL");
42 42
43static unsigned short normal_i2c[] = { 0x36 >> 1, I2C_CLIENT_END };
44
45I2C_CLIENT_INSMOD;
46 43
47 44
48/* ----------------------------------------------------------------------- */ 45/* ----------------------------------------------------------------------- */
@@ -161,11 +158,6 @@ static int wm8775_s_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *fre
161 return 0; 158 return 0;
162} 159}
163 160
164static int wm8775_command(struct i2c_client *client, unsigned cmd, void *arg)
165{
166 return v4l2_subdev_command(i2c_get_clientdata(client), cmd, arg);
167}
168
169/* ----------------------------------------------------------------------- */ 161/* ----------------------------------------------------------------------- */
170 162
171static const struct v4l2_subdev_core_ops wm8775_core_ops = { 163static const struct v4l2_subdev_core_ops wm8775_core_ops = {
@@ -268,8 +260,6 @@ MODULE_DEVICE_TABLE(i2c, wm8775_id);
268 260
269static struct v4l2_i2c_driver_data v4l2_i2c_data = { 261static struct v4l2_i2c_driver_data v4l2_i2c_data = {
270 .name = "wm8775", 262 .name = "wm8775",
271 .driverid = I2C_DRIVERID_WM8775,
272 .command = wm8775_command,
273 .probe = wm8775_probe, 263 .probe = wm8775_probe,
274 .remove = wm8775_remove, 264 .remove = wm8775_remove,
275 .id_table = wm8775_id, 265 .id_table = wm8775_id,
diff --git a/drivers/media/video/zc0301/zc0301_sensor.h b/drivers/media/video/zc0301/zc0301_sensor.h
index b0cd49c438a3..3a408de91b9c 100644
--- a/drivers/media/video/zc0301/zc0301_sensor.h
+++ b/drivers/media/video/zc0301/zc0301_sensor.h
@@ -58,12 +58,20 @@ zc0301_attach_sensor(struct zc0301_device* cam, struct zc0301_sensor* sensor);
58 .idProduct = (prod), \ 58 .idProduct = (prod), \
59 .bInterfaceClass = (intclass) 59 .bInterfaceClass = (intclass)
60 60
61#if !defined CONFIG_USB_GSPCA && !defined CONFIG_USB_GSPCA_MODULE
61#define ZC0301_ID_TABLE \ 62#define ZC0301_ID_TABLE \
62static const struct usb_device_id zc0301_id_table[] = { \ 63static const struct usb_device_id zc0301_id_table[] = { \
63 { ZC0301_USB_DEVICE(0x046d, 0x08ae, 0xff), }, /* PAS202 */ \ 64 { ZC0301_USB_DEVICE(0x046d, 0x08ae, 0xff), }, /* PAS202 */ \
64 { ZC0301_USB_DEVICE(0x0ac8, 0x303b, 0xff), }, /* PB-0330 */ \ 65 { ZC0301_USB_DEVICE(0x0ac8, 0x303b, 0xff), }, /* PB-0330 */ \
65 { } \ 66 { } \
66}; 67};
68#else
69#define ZC0301_ID_TABLE \
70static const struct usb_device_id zc0301_id_table[] = { \
71 { ZC0301_USB_DEVICE(0x046d, 0x08ae, 0xff), }, /* PAS202 */ \
72 { } \
73};
74#endif
67 75
68/*****************************************************************************/ 76/*****************************************************************************/
69 77
diff --git a/drivers/media/video/zoran/Kconfig b/drivers/media/video/zoran/Kconfig
index 8666e19f31a7..fd4120e4c104 100644
--- a/drivers/media/video/zoran/Kconfig
+++ b/drivers/media/video/zoran/Kconfig
@@ -1,6 +1,6 @@
1config VIDEO_ZORAN 1config VIDEO_ZORAN
2 tristate "Zoran ZR36057/36067 Video For Linux" 2 tristate "Zoran ZR36057/36067 Video For Linux"
3 depends on PCI && I2C_ALGOBIT && VIDEO_V4L1 && VIRT_TO_BUS 3 depends on PCI && I2C_ALGOBIT && VIDEO_V4L2 && VIRT_TO_BUS
4 help 4 help
5 Say Y for support for MJPEG capture cards based on the Zoran 5 Say Y for support for MJPEG capture cards based on the Zoran
6 36057/36067 PCI controller chipset. This includes the Iomega 6 36057/36067 PCI controller chipset. This includes the Iomega
@@ -32,7 +32,7 @@ config VIDEO_ZORAN_ZR36060
32config VIDEO_ZORAN_BUZ 32config VIDEO_ZORAN_BUZ
33 tristate "Iomega Buz support" 33 tristate "Iomega Buz support"
34 depends on VIDEO_ZORAN_ZR36060 34 depends on VIDEO_ZORAN_ZR36060
35 select VIDEO_SAA7111 if VIDEO_HELPER_CHIPS_AUTO 35 select VIDEO_SAA711X if VIDEO_HELPER_CHIPS_AUTO
36 select VIDEO_SAA7185 if VIDEO_HELPER_CHIPS_AUTO 36 select VIDEO_SAA7185 if VIDEO_HELPER_CHIPS_AUTO
37 help 37 help
38 Support for the Iomega Buz MJPEG capture/playback card. 38 Support for the Iomega Buz MJPEG capture/playback card.
@@ -58,7 +58,7 @@ config VIDEO_ZORAN_LML33
58config VIDEO_ZORAN_LML33R10 58config VIDEO_ZORAN_LML33R10
59 tristate "Linux Media Labs LML33R10 support" 59 tristate "Linux Media Labs LML33R10 support"
60 depends on VIDEO_ZORAN_ZR36060 60 depends on VIDEO_ZORAN_ZR36060
61 select VIDEO_SAA7114 if VIDEO_HELPER_CHIPS_AUTO 61 select VIDEO_SAA711X if VIDEO_HELPER_CHIPS_AUTO
62 select VIDEO_ADV7170 if VIDEO_HELPER_CHIPS_AUTO 62 select VIDEO_ADV7170 if VIDEO_HELPER_CHIPS_AUTO
63 help 63 help
64 support for the Linux Media Labs LML33R10 MJPEG capture/playback 64 support for the Linux Media Labs LML33R10 MJPEG capture/playback
@@ -66,7 +66,7 @@ config VIDEO_ZORAN_LML33R10
66 66
67config VIDEO_ZORAN_AVS6EYES 67config VIDEO_ZORAN_AVS6EYES
68 tristate "AverMedia 6 Eyes support (EXPERIMENTAL)" 68 tristate "AverMedia 6 Eyes support (EXPERIMENTAL)"
69 depends on VIDEO_ZORAN_ZR36060 && EXPERIMENTAL && VIDEO_V4L1 69 depends on VIDEO_ZORAN_ZR36060 && EXPERIMENTAL
70 select VIDEO_BT856 if VIDEO_HELPER_CHIPS_AUTO 70 select VIDEO_BT856 if VIDEO_HELPER_CHIPS_AUTO
71 select VIDEO_BT866 if VIDEO_HELPER_CHIPS_AUTO 71 select VIDEO_BT866 if VIDEO_HELPER_CHIPS_AUTO
72 select VIDEO_KS0127 if VIDEO_HELPER_CHIPS_AUTO 72 select VIDEO_KS0127 if VIDEO_HELPER_CHIPS_AUTO
diff --git a/drivers/media/video/zoran/videocodec.h b/drivers/media/video/zoran/videocodec.h
index 97a3bbeda505..5c27b251354e 100644
--- a/drivers/media/video/zoran/videocodec.h
+++ b/drivers/media/video/zoran/videocodec.h
@@ -97,7 +97,7 @@
97 available) - it returns 0 if the mode is possible 97 available) - it returns 0 if the mode is possible
98 set_size -> this fn-ref. sets the norm and image size for 98 set_size -> this fn-ref. sets the norm and image size for
99 compression/decompression (returns 0 on success) 99 compression/decompression (returns 0 on success)
100 the norm param is defined in videodev.h (VIDEO_MODE_*) 100 the norm param is defined in videodev2.h (V4L2_STD_*)
101 101
102 additional setup may be available, too - but the codec should work with 102 additional setup may be available, too - but the codec should work with
103 some default values even without this 103 some default values even without this
@@ -144,9 +144,8 @@ M zr36055[1] 0001 0000c001 00000000 (zr36050[1])
144#ifndef __LINUX_VIDEOCODEC_H 144#ifndef __LINUX_VIDEOCODEC_H
145#define __LINUX_VIDEOCODEC_H 145#define __LINUX_VIDEOCODEC_H
146 146
147#include <linux/videodev.h> 147#include <linux/videodev2.h>
148 148
149//should be in videodev.h ??? (VID_DO_....)
150#define CODEC_DO_COMPRESSION 0 149#define CODEC_DO_COMPRESSION 0
151#define CODEC_DO_EXPANSION 1 150#define CODEC_DO_EXPANSION 1
152 151
@@ -237,10 +236,6 @@ struct vfe_settings {
237 __u32 width, height; /* Area to capture */ 236 __u32 width, height; /* Area to capture */
238 __u16 decimation; /* Decimation divider */ 237 __u16 decimation; /* Decimation divider */
239 __u16 flags; /* Flags for capture */ 238 __u16 flags; /* Flags for capture */
240/* flags are the same as in struct video_capture - see videodev.h:
241#define VIDEO_CAPTURE_ODD 0
242#define VIDEO_CAPTURE_EVEN 1
243*/
244 __u16 quality; /* quality of the video */ 239 __u16 quality; /* quality of the video */
245}; 240};
246 241
diff --git a/drivers/media/video/zoran/zoran.h b/drivers/media/video/zoran/zoran.h
index e873a916250f..afecf32f1a87 100644
--- a/drivers/media/video/zoran/zoran.h
+++ b/drivers/media/video/zoran/zoran.h
@@ -31,6 +31,8 @@
31#ifndef _BUZ_H_ 31#ifndef _BUZ_H_
32#define _BUZ_H_ 32#define _BUZ_H_
33 33
34#include <media/v4l2-device.h>
35
34struct zoran_requestbuffers { 36struct zoran_requestbuffers {
35 unsigned long count; /* Number of buffers for MJPEG grabbing */ 37 unsigned long count; /* Number of buffers for MJPEG grabbing */
36 unsigned long size; /* Size PER BUFFER in bytes */ 38 unsigned long size; /* Size PER BUFFER in bytes */
@@ -170,7 +172,7 @@ Private IOCTL to set up for displaying MJPEG
170#endif 172#endif
171#define V4L_MASK_FRAME (V4L_MAX_FRAME - 1) 173#define V4L_MASK_FRAME (V4L_MAX_FRAME - 1)
172 174
173#define MAX_KMALLOC_MEM (128*1024) 175#define MAX_FRAME (BUZ_MAX_FRAME > VIDEO_MAX_FRAME ? BUZ_MAX_FRAME : VIDEO_MAX_FRAME)
174 176
175#include "zr36057.h" 177#include "zr36057.h"
176 178
@@ -240,9 +242,6 @@ enum gpcs_type {
240 242
241struct zoran_format { 243struct zoran_format {
242 char *name; 244 char *name;
243#ifdef CONFIG_VIDEO_V4L1_COMPAT
244 int palette;
245#endif
246 __u32 fourcc; 245 __u32 fourcc;
247 int colorspace; 246 int colorspace;
248 int depth; 247 int depth;
@@ -283,21 +282,21 @@ struct zoran_mapping {
283 int count; 282 int count;
284}; 283};
285 284
286struct zoran_jpg_buffer { 285struct zoran_buffer {
287 struct zoran_mapping *map;
288 __le32 *frag_tab; /* addresses of frag table */
289 u32 frag_tab_bus; /* same value cached to save time in ISR */
290 enum zoran_buffer_state state; /* non-zero if corresponding buffer is in use in grab queue */
291 struct zoran_sync bs; /* DONE: info to return to application */
292};
293
294struct zoran_v4l_buffer {
295 struct zoran_mapping *map; 286 struct zoran_mapping *map;
296 char *fbuffer; /* virtual address of frame buffer */ 287 enum zoran_buffer_state state; /* state: unused/pending/dma/done */
297 unsigned long fbuffer_phys; /* physical address of frame buffer */ 288 struct zoran_sync bs; /* DONE: info to return to application */
298 unsigned long fbuffer_bus; /* bus address of frame buffer */ 289 union {
299 enum zoran_buffer_state state; /* state: unused/pending/done */ 290 struct {
300 struct zoran_sync bs; /* DONE: info to return to application */ 291 __le32 *frag_tab; /* addresses of frag table */
292 u32 frag_tab_bus; /* same value cached to save time in ISR */
293 } jpg;
294 struct {
295 char *fbuffer; /* virtual address of frame buffer */
296 unsigned long fbuffer_phys;/* physical address of frame buffer */
297 unsigned long fbuffer_bus;/* bus address of frame buffer */
298 } v4l;
299 };
301}; 300};
302 301
303enum zoran_lock_activity { 302enum zoran_lock_activity {
@@ -307,21 +306,13 @@ enum zoran_lock_activity {
307}; 306};
308 307
309/* buffer collections */ 308/* buffer collections */
310struct zoran_jpg_struct { 309struct zoran_buffer_col {
311 enum zoran_lock_activity active; /* feature currently in use? */ 310 enum zoran_lock_activity active; /* feature currently in use? */
312 struct zoran_jpg_buffer buffer[BUZ_MAX_FRAME]; /* buffers */ 311 unsigned int num_buffers, buffer_size;
313 int num_buffers, buffer_size; 312 struct zoran_buffer buffer[MAX_FRAME]; /* buffers */
314 u8 allocated; /* Flag if buffers are allocated */ 313 u8 allocated; /* Flag if buffers are allocated */
315 u8 ready_to_be_freed; /* hack - see zoran_driver.c */
316 u8 need_contiguous; /* Flag if contiguous buffers are needed */ 314 u8 need_contiguous; /* Flag if contiguous buffers are needed */
317}; 315 /* only applies to jpg buffers, raw buffers are always contiguous */
318
319struct zoran_v4l_struct {
320 enum zoran_lock_activity active; /* feature currently in use? */
321 struct zoran_v4l_buffer buffer[VIDEO_MAX_FRAME]; /* buffers */
322 int num_buffers, buffer_size;
323 u8 allocated; /* Flag if buffers are allocated */
324 u8 ready_to_be_freed; /* hack - see zoran_driver.c */
325}; 316};
326 317
327struct zoran; 318struct zoran;
@@ -330,23 +321,27 @@ struct zoran;
330struct zoran_fh { 321struct zoran_fh {
331 struct zoran *zr; 322 struct zoran *zr;
332 323
333 enum zoran_map_mode map_mode; /* Flag which bufferset will map by next mmap() */ 324 enum zoran_map_mode map_mode; /* Flag which bufferset will map by next mmap() */
334 325
335 struct zoran_overlay_settings overlay_settings; 326 struct zoran_overlay_settings overlay_settings;
336 u32 *overlay_mask; /* overlay mask */ 327 u32 *overlay_mask; /* overlay mask */
337 enum zoran_lock_activity overlay_active; /* feature currently in use? */ 328 enum zoran_lock_activity overlay_active;/* feature currently in use? */
338 329
339 struct zoran_v4l_settings v4l_settings; /* structure with a lot of things to play with */ 330 struct zoran_buffer_col buffers; /* buffers' info */
340 struct zoran_v4l_struct v4l_buffers; /* V4L buffers' info */
341 331
332 struct zoran_v4l_settings v4l_settings; /* structure with a lot of things to play with */
342 struct zoran_jpg_settings jpg_settings; /* structure with a lot of things to play with */ 333 struct zoran_jpg_settings jpg_settings; /* structure with a lot of things to play with */
343 struct zoran_jpg_struct jpg_buffers; /* MJPEG buffers' info */
344}; 334};
345 335
346struct card_info { 336struct card_info {
347 enum card_type type; 337 enum card_type type;
348 char name[32]; 338 char name[32];
349 u16 i2c_decoder, i2c_encoder; /* I2C types */ 339 const char *i2c_decoder; /* i2c decoder device */
340 const char *mod_decoder; /* i2c decoder module */
341 const unsigned short *addrs_decoder;
342 const char *i2c_encoder; /* i2c encoder device */
343 const char *mod_encoder; /* i2c encoder module */
344 const unsigned short *addrs_encoder;
350 u16 video_vfe, video_codec; /* videocodec types */ 345 u16 video_vfe, video_codec; /* videocodec types */
351 u16 audio_chip; /* audio type */ 346 u16 audio_chip; /* audio type */
352 347
@@ -356,7 +351,7 @@ struct card_info {
356 char name[32]; 351 char name[32];
357 } input[BUZ_MAX_INPUT]; 352 } input[BUZ_MAX_INPUT];
358 353
359 int norms; 354 v4l2_std_id norms;
360 struct tvnorm *tvn[3]; /* supported TV norms */ 355 struct tvnorm *tvn[3]; /* supported TV norms */
361 356
362 u32 jpeg_int; /* JPEG interrupt */ 357 u32 jpeg_int; /* JPEG interrupt */
@@ -377,14 +372,15 @@ struct card_info {
377}; 372};
378 373
379struct zoran { 374struct zoran {
375 struct v4l2_device v4l2_dev;
380 struct video_device *video_dev; 376 struct video_device *video_dev;
381 377
382 struct i2c_adapter i2c_adapter; /* */ 378 struct i2c_adapter i2c_adapter; /* */
383 struct i2c_algo_bit_data i2c_algo; /* */ 379 struct i2c_algo_bit_data i2c_algo; /* */
384 u32 i2cbr; 380 u32 i2cbr;
385 381
386 struct i2c_client *decoder; /* video decoder i2c client */ 382 struct v4l2_subdev *decoder; /* video decoder sub-device */
387 struct i2c_client *encoder; /* video encoder i2c client */ 383 struct v4l2_subdev *encoder; /* video encoder sub-device */
388 384
389 struct videocodec *codec; /* video codec */ 385 struct videocodec *codec; /* video codec */
390 struct videocodec *vfe; /* video front end */ 386 struct videocodec *vfe; /* video front end */
@@ -405,9 +401,15 @@ struct zoran {
405 spinlock_t spinlock; /* Spinlock */ 401 spinlock_t spinlock; /* Spinlock */
406 402
407 /* Video for Linux parameters */ 403 /* Video for Linux parameters */
408 int input, norm; /* card's norm and input - norm=VIDEO_MODE_* */ 404 int input; /* card's norm and input - norm=VIDEO_MODE_* */
409 int hue, saturation, contrast, brightness; /* Current picture params */ 405 v4l2_std_id norm;
410 struct video_buffer buffer; /* Current buffer params */ 406
407 /* Current buffer params */
408 void *vbuf_base;
409 int vbuf_height, vbuf_width;
410 int vbuf_depth;
411 int vbuf_bytesperline;
412
411 struct zoran_overlay_settings overlay_settings; 413 struct zoran_overlay_settings overlay_settings;
412 u32 *overlay_mask; /* overlay mask */ 414 u32 *overlay_mask; /* overlay mask */
413 enum zoran_lock_activity overlay_active; /* feature currently in use? */ 415 enum zoran_lock_activity overlay_active; /* feature currently in use? */
@@ -427,7 +429,7 @@ struct zoran {
427 unsigned long v4l_pend_tail; 429 unsigned long v4l_pend_tail;
428 unsigned long v4l_sync_tail; 430 unsigned long v4l_sync_tail;
429 int v4l_pend[V4L_MAX_FRAME]; 431 int v4l_pend[V4L_MAX_FRAME];
430 struct zoran_v4l_struct v4l_buffers; /* V4L buffers' info */ 432 struct zoran_buffer_col v4l_buffers; /* V4L buffers' info */
431 433
432 /* Buz MJPEG parameters */ 434 /* Buz MJPEG parameters */
433 enum zoran_codec_mode codec_mode; /* status of codec */ 435 enum zoran_codec_mode codec_mode; /* status of codec */
@@ -454,7 +456,7 @@ struct zoran {
454 int jpg_pend[BUZ_MAX_FRAME]; 456 int jpg_pend[BUZ_MAX_FRAME];
455 457
456 /* array indexed by frame number */ 458 /* array indexed by frame number */
457 struct zoran_jpg_struct jpg_buffers; /* MJPEG buffers' info */ 459 struct zoran_buffer_col jpg_buffers; /* MJPEG buffers' info */
458 460
459 /* Additional stuff for testing */ 461 /* Additional stuff for testing */
460#ifdef CONFIG_PROC_FS 462#ifdef CONFIG_PROC_FS
@@ -488,6 +490,11 @@ struct zoran {
488 wait_queue_head_t test_q; 490 wait_queue_head_t test_q;
489}; 491};
490 492
493static inline struct zoran *to_zoran(struct v4l2_device *v4l2_dev)
494{
495 return container_of(v4l2_dev, struct zoran, v4l2_dev);
496}
497
491/* There was something called _ALPHA_BUZ that used the PCI address instead of 498/* There was something called _ALPHA_BUZ that used the PCI address instead of
492 * the kernel iomapped address for btread/btwrite. */ 499 * the kernel iomapped address for btread/btwrite. */
493#define btwrite(dat,adr) writel((dat), zr->zr36057_mem+(adr)) 500#define btwrite(dat,adr) writel((dat), zr->zr36057_mem+(adr))
diff --git a/drivers/media/video/zoran/zoran_card.c b/drivers/media/video/zoran/zoran_card.c
index 5d2f090aa0f8..f91bba435ed5 100644
--- a/drivers/media/video/zoran/zoran_card.c
+++ b/drivers/media/video/zoran/zoran_card.c
@@ -38,8 +38,7 @@
38#include <linux/proc_fs.h> 38#include <linux/proc_fs.h>
39#include <linux/i2c.h> 39#include <linux/i2c.h>
40#include <linux/i2c-algo-bit.h> 40#include <linux/i2c-algo-bit.h>
41#include <linux/videodev.h> 41#include <linux/videodev2.h>
42#include <media/v4l2-common.h>
43#include <linux/spinlock.h> 42#include <linux/spinlock.h>
44#include <linux/sem.h> 43#include <linux/sem.h>
45#include <linux/kmod.h> 44#include <linux/kmod.h>
@@ -47,11 +46,10 @@
47 46
48#include <linux/pci.h> 47#include <linux/pci.h>
49#include <linux/interrupt.h> 48#include <linux/interrupt.h>
50#include <linux/video_decoder.h>
51#include <linux/video_encoder.h>
52#include <linux/mutex.h> 49#include <linux/mutex.h>
53 50#include <linux/io.h>
54#include <asm/io.h> 51#include <media/v4l2-common.h>
52#include <media/bt819.h>
55 53
56#include "videocodec.h" 54#include "videocodec.h"
57#include "zoran.h" 55#include "zoran.h"
@@ -108,25 +106,8 @@ static int video_nr[BUZ_MAX] = { [0 ... (BUZ_MAX-1)] = -1 };
108module_param_array(video_nr, int, NULL, 0444); 106module_param_array(video_nr, int, NULL, 0444);
109MODULE_PARM_DESC(video_nr, "Video device number (-1=Auto)"); 107MODULE_PARM_DESC(video_nr, "Video device number (-1=Auto)");
110 108
111/* 109int v4l_nbufs = 4;
112 Number and size of grab buffers for Video 4 Linux 110int v4l_bufsize = 864; /* Everybody should be able to work with this setting */
113 The vast majority of applications should not need more than 2,
114 the very popular BTTV driver actually does ONLY have 2.
115 Time sensitive applications might need more, the maximum
116 is VIDEO_MAX_FRAME (defined in <linux/videodev.h>).
117
118 The size is set so that the maximum possible request
119 can be satisfied. Decrease it, if bigphys_area alloc'd
120 memory is low. If you don't have the bigphys_area patch,
121 set it to 128 KB. Will you allow only to grab small
122 images with V4L, but that's better than nothing.
123
124 v4l_bufsize has to be given in KB !
125
126*/
127
128int v4l_nbufs = 2;
129int v4l_bufsize = 128; /* Everybody should be able to work with this setting */
130module_param(v4l_nbufs, int, 0644); 111module_param(v4l_nbufs, int, 0644);
131MODULE_PARM_DESC(v4l_nbufs, "Maximum number of V4L buffers to use"); 112MODULE_PARM_DESC(v4l_nbufs, "Maximum number of V4L buffers to use");
132module_param(v4l_bufsize, int, 0644); 113module_param(v4l_bufsize, int, 0644);
@@ -273,7 +254,7 @@ zr36016_write (struct videocodec *codec,
273static void 254static void
274dc10_init (struct zoran *zr) 255dc10_init (struct zoran *zr)
275{ 256{
276 dprintk(3, KERN_DEBUG "%s: dc10_init()\n", ZR_DEVNAME(zr)); 257 dprintk(3, KERN_DEBUG "%s: %s\n", ZR_DEVNAME(zr), __func__);
277 258
278 /* Pixel clock selection */ 259 /* Pixel clock selection */
279 GPIO(zr, 4, 0); 260 GPIO(zr, 4, 0);
@@ -285,13 +266,13 @@ dc10_init (struct zoran *zr)
285static void 266static void
286dc10plus_init (struct zoran *zr) 267dc10plus_init (struct zoran *zr)
287{ 268{
288 dprintk(3, KERN_DEBUG "%s: dc10plus_init()\n", ZR_DEVNAME(zr)); 269 dprintk(3, KERN_DEBUG "%s: %s\n", ZR_DEVNAME(zr), __func__);
289} 270}
290 271
291static void 272static void
292buz_init (struct zoran *zr) 273buz_init (struct zoran *zr)
293{ 274{
294 dprintk(3, KERN_DEBUG "%s: buz_init()\n", ZR_DEVNAME(zr)); 275 dprintk(3, KERN_DEBUG "%s: %s\n", ZR_DEVNAME(zr), __func__);
295 276
296 /* some stuff from Iomega */ 277 /* some stuff from Iomega */
297 pci_write_config_dword(zr->pci_dev, 0xfc, 0x90680f15); 278 pci_write_config_dword(zr->pci_dev, 0xfc, 0x90680f15);
@@ -302,7 +283,7 @@ buz_init (struct zoran *zr)
302static void 283static void
303lml33_init (struct zoran *zr) 284lml33_init (struct zoran *zr)
304{ 285{
305 dprintk(3, KERN_DEBUG "%s: lml33_init()\n", ZR_DEVNAME(zr)); 286 dprintk(3, KERN_DEBUG "%s: %s\n", ZR_DEVNAME(zr), __func__);
306 287
307 GPIO(zr, 2, 1); // Set Composite input/output 288 GPIO(zr, 2, 1); // Set Composite input/output
308} 289}
@@ -332,50 +313,6 @@ avs6eyes_init (struct zoran *zr)
332} 313}
333 314
334static char * 315static char *
335i2cid_to_modulename (u16 i2c_id)
336{
337 char *name = NULL;
338
339 switch (i2c_id) {
340 case I2C_DRIVERID_SAA7110:
341 name = "saa7110";
342 break;
343 case I2C_DRIVERID_SAA7111A:
344 name = "saa7111";
345 break;
346 case I2C_DRIVERID_SAA7114:
347 name = "saa7114";
348 break;
349 case I2C_DRIVERID_SAA7185B:
350 name = "saa7185";
351 break;
352 case I2C_DRIVERID_ADV7170:
353 name = "adv7170";
354 break;
355 case I2C_DRIVERID_ADV7175:
356 name = "adv7175";
357 break;
358 case I2C_DRIVERID_BT819:
359 name = "bt819";
360 break;
361 case I2C_DRIVERID_BT856:
362 name = "bt856";
363 break;
364 case I2C_DRIVERID_BT866:
365 name = "bt866";
366 break;
367 case I2C_DRIVERID_VPX3220:
368 name = "vpx3220";
369 break;
370 case I2C_DRIVERID_KS0127:
371 name = "ks0127";
372 break;
373 }
374
375 return name;
376}
377
378static char *
379codecid_to_modulename (u16 codecid) 316codecid_to_modulename (u16 codecid)
380{ 317{
381 char *name = NULL; 318 char *name = NULL;
@@ -425,11 +362,24 @@ static struct tvnorm f60ccir601_lm33r10 = { 858, 720, 56+54, 788, 525, 480, 16 }
425static struct tvnorm f50ccir601_avs6eyes = { 864, 720, 74, 804, 625, 576, 18 }; 362static struct tvnorm f50ccir601_avs6eyes = { 864, 720, 74, 804, 625, 576, 18 };
426static struct tvnorm f60ccir601_avs6eyes = { 858, 720, 56, 788, 525, 480, 16 }; 363static struct tvnorm f60ccir601_avs6eyes = { 858, 720, 56, 788, 525, 480, 16 };
427 364
365static const unsigned short vpx3220_addrs[] = { 0x43, 0x47, I2C_CLIENT_END };
366static const unsigned short saa7110_addrs[] = { 0x4e, 0x4f, I2C_CLIENT_END };
367static const unsigned short saa7111_addrs[] = { 0x25, 0x24, I2C_CLIENT_END };
368static const unsigned short saa7114_addrs[] = { 0x21, 0x20, I2C_CLIENT_END };
369static const unsigned short adv717x_addrs[] = { 0x6a, 0x6b, 0x2a, 0x2b, I2C_CLIENT_END };
370static const unsigned short ks0127_addrs[] = { 0x6c, 0x6d, I2C_CLIENT_END };
371static const unsigned short saa7185_addrs[] = { 0x44, I2C_CLIENT_END };
372static const unsigned short bt819_addrs[] = { 0x45, I2C_CLIENT_END };
373static const unsigned short bt856_addrs[] = { 0x44, I2C_CLIENT_END };
374static const unsigned short bt866_addrs[] = { 0x44, I2C_CLIENT_END };
375
428static struct card_info zoran_cards[NUM_CARDS] __devinitdata = { 376static struct card_info zoran_cards[NUM_CARDS] __devinitdata = {
429 { 377 {
430 .type = DC10_old, 378 .type = DC10_old,
431 .name = "DC10(old)", 379 .name = "DC10(old)",
432 .i2c_decoder = I2C_DRIVERID_VPX3220, 380 .i2c_decoder = "vpx3220a",
381 .mod_decoder = "vpx3220",
382 .addrs_decoder = vpx3220_addrs,
433 .video_codec = CODEC_TYPE_ZR36050, 383 .video_codec = CODEC_TYPE_ZR36050,
434 .video_vfe = CODEC_TYPE_ZR36016, 384 .video_vfe = CODEC_TYPE_ZR36016,
435 385
@@ -439,7 +389,7 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = {
439 { 2, "S-Video" }, 389 { 2, "S-Video" },
440 { 0, "Internal/comp" } 390 { 0, "Internal/comp" }
441 }, 391 },
442 .norms = 3, 392 .norms = V4L2_STD_NTSC|V4L2_STD_PAL|V4L2_STD_SECAM,
443 .tvn = { 393 .tvn = {
444 &f50sqpixel_dc10, 394 &f50sqpixel_dc10,
445 &f60sqpixel_dc10, 395 &f60sqpixel_dc10,
@@ -457,8 +407,12 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = {
457 }, { 407 }, {
458 .type = DC10_new, 408 .type = DC10_new,
459 .name = "DC10(new)", 409 .name = "DC10(new)",
460 .i2c_decoder = I2C_DRIVERID_SAA7110, 410 .i2c_decoder = "saa7110",
461 .i2c_encoder = I2C_DRIVERID_ADV7175, 411 .mod_decoder = "saa7110",
412 .addrs_decoder = saa7110_addrs,
413 .i2c_encoder = "adv7175",
414 .mod_encoder = "adv7175",
415 .addrs_encoder = adv717x_addrs,
462 .video_codec = CODEC_TYPE_ZR36060, 416 .video_codec = CODEC_TYPE_ZR36060,
463 417
464 .inputs = 3, 418 .inputs = 3,
@@ -467,7 +421,7 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = {
467 { 7, "S-Video" }, 421 { 7, "S-Video" },
468 { 5, "Internal/comp" } 422 { 5, "Internal/comp" }
469 }, 423 },
470 .norms = 3, 424 .norms = V4L2_STD_NTSC|V4L2_STD_PAL|V4L2_STD_SECAM,
471 .tvn = { 425 .tvn = {
472 &f50sqpixel, 426 &f50sqpixel,
473 &f60sqpixel, 427 &f60sqpixel,
@@ -484,8 +438,12 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = {
484 }, { 438 }, {
485 .type = DC10plus, 439 .type = DC10plus,
486 .name = "DC10plus", 440 .name = "DC10plus",
487 .i2c_decoder = I2C_DRIVERID_SAA7110, 441 .i2c_decoder = "saa7110",
488 .i2c_encoder = I2C_DRIVERID_ADV7175, 442 .mod_decoder = "saa7110",
443 .addrs_decoder = saa7110_addrs,
444 .i2c_encoder = "adv7175",
445 .mod_encoder = "adv7175",
446 .addrs_encoder = adv717x_addrs,
489 .video_codec = CODEC_TYPE_ZR36060, 447 .video_codec = CODEC_TYPE_ZR36060,
490 448
491 .inputs = 3, 449 .inputs = 3,
@@ -494,7 +452,7 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = {
494 { 7, "S-Video" }, 452 { 7, "S-Video" },
495 { 5, "Internal/comp" } 453 { 5, "Internal/comp" }
496 }, 454 },
497 .norms = 3, 455 .norms = V4L2_STD_NTSC|V4L2_STD_PAL|V4L2_STD_SECAM,
498 .tvn = { 456 .tvn = {
499 &f50sqpixel, 457 &f50sqpixel,
500 &f60sqpixel, 458 &f60sqpixel,
@@ -512,8 +470,12 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = {
512 }, { 470 }, {
513 .type = DC30, 471 .type = DC30,
514 .name = "DC30", 472 .name = "DC30",
515 .i2c_decoder = I2C_DRIVERID_VPX3220, 473 .i2c_decoder = "vpx3220a",
516 .i2c_encoder = I2C_DRIVERID_ADV7175, 474 .mod_decoder = "vpx3220",
475 .addrs_decoder = vpx3220_addrs,
476 .i2c_encoder = "adv7175",
477 .mod_encoder = "adv7175",
478 .addrs_encoder = adv717x_addrs,
517 .video_codec = CODEC_TYPE_ZR36050, 479 .video_codec = CODEC_TYPE_ZR36050,
518 .video_vfe = CODEC_TYPE_ZR36016, 480 .video_vfe = CODEC_TYPE_ZR36016,
519 481
@@ -523,7 +485,7 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = {
523 { 2, "S-Video" }, 485 { 2, "S-Video" },
524 { 0, "Internal/comp" } 486 { 0, "Internal/comp" }
525 }, 487 },
526 .norms = 3, 488 .norms = V4L2_STD_NTSC|V4L2_STD_PAL|V4L2_STD_SECAM,
527 .tvn = { 489 .tvn = {
528 &f50sqpixel_dc10, 490 &f50sqpixel_dc10,
529 &f60sqpixel_dc10, 491 &f60sqpixel_dc10,
@@ -541,8 +503,12 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = {
541 }, { 503 }, {
542 .type = DC30plus, 504 .type = DC30plus,
543 .name = "DC30plus", 505 .name = "DC30plus",
544 .i2c_decoder = I2C_DRIVERID_VPX3220, 506 .i2c_decoder = "vpx3220a",
545 .i2c_encoder = I2C_DRIVERID_ADV7175, 507 .mod_decoder = "vpx3220",
508 .addrs_decoder = vpx3220_addrs,
509 .i2c_encoder = "adv7175",
510 .mod_encoder = "adv7175",
511 .addrs_encoder = adv717x_addrs,
546 .video_codec = CODEC_TYPE_ZR36050, 512 .video_codec = CODEC_TYPE_ZR36050,
547 .video_vfe = CODEC_TYPE_ZR36016, 513 .video_vfe = CODEC_TYPE_ZR36016,
548 514
@@ -552,7 +518,7 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = {
552 { 2, "S-Video" }, 518 { 2, "S-Video" },
553 { 0, "Internal/comp" } 519 { 0, "Internal/comp" }
554 }, 520 },
555 .norms = 3, 521 .norms = V4L2_STD_NTSC|V4L2_STD_PAL|V4L2_STD_SECAM,
556 .tvn = { 522 .tvn = {
557 &f50sqpixel_dc10, 523 &f50sqpixel_dc10,
558 &f60sqpixel_dc10, 524 &f60sqpixel_dc10,
@@ -570,8 +536,12 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = {
570 }, { 536 }, {
571 .type = LML33, 537 .type = LML33,
572 .name = "LML33", 538 .name = "LML33",
573 .i2c_decoder = I2C_DRIVERID_BT819, 539 .i2c_decoder = "bt819a",
574 .i2c_encoder = I2C_DRIVERID_BT856, 540 .mod_decoder = "bt819",
541 .addrs_decoder = bt819_addrs,
542 .i2c_encoder = "bt856",
543 .mod_encoder = "bt856",
544 .addrs_encoder = bt856_addrs,
575 .video_codec = CODEC_TYPE_ZR36060, 545 .video_codec = CODEC_TYPE_ZR36060,
576 546
577 .inputs = 2, 547 .inputs = 2,
@@ -579,7 +549,7 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = {
579 { 0, "Composite" }, 549 { 0, "Composite" },
580 { 7, "S-Video" } 550 { 7, "S-Video" }
581 }, 551 },
582 .norms = 2, 552 .norms = V4L2_STD_NTSC|V4L2_STD_PAL,
583 .tvn = { 553 .tvn = {
584 &f50ccir601_lml33, 554 &f50ccir601_lml33,
585 &f60ccir601_lml33, 555 &f60ccir601_lml33,
@@ -597,8 +567,12 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = {
597 }, { 567 }, {
598 .type = LML33R10, 568 .type = LML33R10,
599 .name = "LML33R10", 569 .name = "LML33R10",
600 .i2c_decoder = I2C_DRIVERID_SAA7114, 570 .i2c_decoder = "saa7114",
601 .i2c_encoder = I2C_DRIVERID_ADV7170, 571 .mod_decoder = "saa7115",
572 .addrs_decoder = saa7114_addrs,
573 .i2c_encoder = "adv7170",
574 .mod_encoder = "adv7170",
575 .addrs_encoder = adv717x_addrs,
602 .video_codec = CODEC_TYPE_ZR36060, 576 .video_codec = CODEC_TYPE_ZR36060,
603 577
604 .inputs = 2, 578 .inputs = 2,
@@ -606,7 +580,7 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = {
606 { 0, "Composite" }, 580 { 0, "Composite" },
607 { 7, "S-Video" } 581 { 7, "S-Video" }
608 }, 582 },
609 .norms = 2, 583 .norms = V4L2_STD_NTSC|V4L2_STD_PAL,
610 .tvn = { 584 .tvn = {
611 &f50ccir601_lm33r10, 585 &f50ccir601_lm33r10,
612 &f60ccir601_lm33r10, 586 &f60ccir601_lm33r10,
@@ -624,8 +598,12 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = {
624 }, { 598 }, {
625 .type = BUZ, 599 .type = BUZ,
626 .name = "Buz", 600 .name = "Buz",
627 .i2c_decoder = I2C_DRIVERID_SAA7111A, 601 .i2c_decoder = "saa7111",
628 .i2c_encoder = I2C_DRIVERID_SAA7185B, 602 .mod_decoder = "saa7115",
603 .addrs_decoder = saa7111_addrs,
604 .i2c_encoder = "saa7185",
605 .mod_encoder = "saa7185",
606 .addrs_encoder = saa7185_addrs,
629 .video_codec = CODEC_TYPE_ZR36060, 607 .video_codec = CODEC_TYPE_ZR36060,
630 608
631 .inputs = 2, 609 .inputs = 2,
@@ -633,7 +611,7 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = {
633 { 3, "Composite" }, 611 { 3, "Composite" },
634 { 7, "S-Video" } 612 { 7, "S-Video" }
635 }, 613 },
636 .norms = 3, 614 .norms = V4L2_STD_NTSC|V4L2_STD_PAL|V4L2_STD_SECAM,
637 .tvn = { 615 .tvn = {
638 &f50ccir601, 616 &f50ccir601,
639 &f60ccir601, 617 &f60ccir601,
@@ -653,8 +631,12 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = {
653 .name = "6-Eyes", 631 .name = "6-Eyes",
654 /* AverMedia chose not to brand the 6-Eyes. Thus it 632 /* AverMedia chose not to brand the 6-Eyes. Thus it
655 can't be autodetected, and requires card=x. */ 633 can't be autodetected, and requires card=x. */
656 .i2c_decoder = I2C_DRIVERID_KS0127, 634 .i2c_decoder = "ks0127",
657 .i2c_encoder = I2C_DRIVERID_BT866, 635 .mod_decoder = "ks0127",
636 .addrs_decoder = ks0127_addrs,
637 .i2c_encoder = "bt866",
638 .mod_encoder = "bt866",
639 .addrs_encoder = bt866_addrs,
658 .video_codec = CODEC_TYPE_ZR36060, 640 .video_codec = CODEC_TYPE_ZR36060,
659 641
660 .inputs = 10, 642 .inputs = 10,
@@ -670,7 +652,7 @@ static struct card_info zoran_cards[NUM_CARDS] __devinitdata = {
670 {10, "S-Video 3" }, 652 {10, "S-Video 3" },
671 {15, "YCbCr" } 653 {15, "YCbCr" }
672 }, 654 },
673 .norms = 2, 655 .norms = V4L2_STD_NTSC|V4L2_STD_PAL,
674 .tvn = { 656 .tvn = {
675 &f50ccir601_avs6eyes, 657 &f50ccir601_avs6eyes,
676 &f60ccir601_avs6eyes, 658 &f60ccir601_avs6eyes,
@@ -735,69 +717,6 @@ zoran_i2c_setscl (void *data,
735 btwrite(zr->i2cbr, ZR36057_I2CBR); 717 btwrite(zr->i2cbr, ZR36057_I2CBR);
736} 718}
737 719
738static int
739zoran_i2c_client_register (struct i2c_client *client)
740{
741 struct zoran *zr = (struct zoran *) i2c_get_adapdata(client->adapter);
742 int res = 0;
743
744 dprintk(2,
745 KERN_DEBUG "%s: i2c_client_register() - driver id = %d\n",
746 ZR_DEVNAME(zr), client->driver->id);
747
748 mutex_lock(&zr->resource_lock);
749
750 if (zr->user > 0) {
751 /* we're already busy, so we keep a reference to
752 * them... Could do a lot of stuff here, but this
753 * is easiest. (Did I ever mention I'm a lazy ass?)
754 */
755 res = -EBUSY;
756 goto clientreg_unlock_and_return;
757 }
758
759 if (client->driver->id == zr->card.i2c_decoder)
760 zr->decoder = client;
761 else if (client->driver->id == zr->card.i2c_encoder)
762 zr->encoder = client;
763 else {
764 res = -ENODEV;
765 goto clientreg_unlock_and_return;
766 }
767
768clientreg_unlock_and_return:
769 mutex_unlock(&zr->resource_lock);
770
771 return res;
772}
773
774static int
775zoran_i2c_client_unregister (struct i2c_client *client)
776{
777 struct zoran *zr = (struct zoran *) i2c_get_adapdata(client->adapter);
778 int res = 0;
779
780 dprintk(2, KERN_DEBUG "%s: i2c_client_unregister()\n", ZR_DEVNAME(zr));
781
782 mutex_lock(&zr->resource_lock);
783
784 if (zr->user > 0) {
785 res = -EBUSY;
786 goto clientunreg_unlock_and_return;
787 }
788
789 /* try to locate it */
790 if (client == zr->encoder) {
791 zr->encoder = NULL;
792 } else if (client == zr->decoder) {
793 zr->decoder = NULL;
794 snprintf(ZR_DEVNAME(zr), sizeof(ZR_DEVNAME(zr)), "MJPEG[%d]", zr->id);
795 }
796clientunreg_unlock_and_return:
797 mutex_unlock(&zr->resource_lock);
798 return res;
799}
800
801static const struct i2c_algo_bit_data zoran_i2c_bit_data_template = { 720static const struct i2c_algo_bit_data zoran_i2c_bit_data_template = {
802 .setsda = zoran_i2c_setsda, 721 .setsda = zoran_i2c_setsda,
803 .setscl = zoran_i2c_setscl, 722 .setscl = zoran_i2c_setscl,
@@ -813,13 +732,10 @@ zoran_register_i2c (struct zoran *zr)
813 memcpy(&zr->i2c_algo, &zoran_i2c_bit_data_template, 732 memcpy(&zr->i2c_algo, &zoran_i2c_bit_data_template,
814 sizeof(struct i2c_algo_bit_data)); 733 sizeof(struct i2c_algo_bit_data));
815 zr->i2c_algo.data = zr; 734 zr->i2c_algo.data = zr;
816 zr->i2c_adapter.class = I2C_CLASS_TV_ANALOG;
817 zr->i2c_adapter.id = I2C_HW_B_ZR36067; 735 zr->i2c_adapter.id = I2C_HW_B_ZR36067;
818 zr->i2c_adapter.client_register = zoran_i2c_client_register;
819 zr->i2c_adapter.client_unregister = zoran_i2c_client_unregister;
820 strlcpy(zr->i2c_adapter.name, ZR_DEVNAME(zr), 736 strlcpy(zr->i2c_adapter.name, ZR_DEVNAME(zr),
821 sizeof(zr->i2c_adapter.name)); 737 sizeof(zr->i2c_adapter.name));
822 i2c_set_adapdata(&zr->i2c_adapter, zr); 738 i2c_set_adapdata(&zr->i2c_adapter, &zr->v4l2_dev);
823 zr->i2c_adapter.algo_data = &zr->i2c_algo; 739 zr->i2c_adapter.algo_data = &zr->i2c_algo;
824 zr->i2c_adapter.dev.parent = &zr->pci_dev->dev; 740 zr->i2c_adapter.dev.parent = &zr->pci_dev->dev;
825 return i2c_bit_add_bus(&zr->i2c_adapter); 741 return i2c_bit_add_bus(&zr->i2c_adapter);
@@ -835,19 +751,20 @@ zoran_unregister_i2c (struct zoran *zr)
835 751
836int 752int
837zoran_check_jpg_settings (struct zoran *zr, 753zoran_check_jpg_settings (struct zoran *zr,
838 struct zoran_jpg_settings *settings) 754 struct zoran_jpg_settings *settings,
755 int try)
839{ 756{
840 int err = 0, err0 = 0; 757 int err = 0, err0 = 0;
841 758
842 dprintk(4, 759 dprintk(4,
843 KERN_DEBUG 760 KERN_DEBUG
844 "%s: check_jpg_settings() - dec: %d, Hdcm: %d, Vdcm: %d, Tdcm: %d\n", 761 "%s: %s - dec: %d, Hdcm: %d, Vdcm: %d, Tdcm: %d\n",
845 ZR_DEVNAME(zr), settings->decimation, settings->HorDcm, 762 ZR_DEVNAME(zr), __func__, settings->decimation, settings->HorDcm,
846 settings->VerDcm, settings->TmpDcm); 763 settings->VerDcm, settings->TmpDcm);
847 dprintk(4, 764 dprintk(4,
848 KERN_DEBUG 765 KERN_DEBUG
849 "%s: check_jpg_settings() - x: %d, y: %d, w: %d, y: %d\n", 766 "%s: %s - x: %d, y: %d, w: %d, y: %d\n",
850 ZR_DEVNAME(zr), settings->img_x, settings->img_y, 767 ZR_DEVNAME(zr), __func__, settings->img_x, settings->img_y,
851 settings->img_width, settings->img_height); 768 settings->img_width, settings->img_height);
852 /* Check decimation, set default values for decimation = 1, 2, 4 */ 769 /* Check decimation, set default values for decimation = 1, 2, 4 */
853 switch (settings->decimation) { 770 switch (settings->decimation) {
@@ -879,8 +796,8 @@ zoran_check_jpg_settings (struct zoran *zr,
879 if (zr->card.type == DC10_new) { 796 if (zr->card.type == DC10_new) {
880 dprintk(1, 797 dprintk(1,
881 KERN_DEBUG 798 KERN_DEBUG
882 "%s: check_jpg_settings() - HDec by 4 is not supported on the DC10\n", 799 "%s: %s - HDec by 4 is not supported on the DC10\n",
883 ZR_DEVNAME(zr)); 800 ZR_DEVNAME(zr), __func__);
884 err0++; 801 err0++;
885 break; 802 break;
886 } 803 }
@@ -900,50 +817,73 @@ zoran_check_jpg_settings (struct zoran *zr,
900 /* We have to check the data the user has set */ 817 /* We have to check the data the user has set */
901 818
902 if (settings->HorDcm != 1 && settings->HorDcm != 2 && 819 if (settings->HorDcm != 1 && settings->HorDcm != 2 &&
903 (zr->card.type == DC10_new || settings->HorDcm != 4)) 820 (zr->card.type == DC10_new || settings->HorDcm != 4)) {
821 settings->HorDcm = clamp(settings->HorDcm, 1, 2);
904 err0++; 822 err0++;
905 if (settings->VerDcm != 1 && settings->VerDcm != 2) 823 }
824 if (settings->VerDcm != 1 && settings->VerDcm != 2) {
825 settings->VerDcm = clamp(settings->VerDcm, 1, 2);
906 err0++; 826 err0++;
907 if (settings->TmpDcm != 1 && settings->TmpDcm != 2) 827 }
828 if (settings->TmpDcm != 1 && settings->TmpDcm != 2) {
829 settings->TmpDcm = clamp(settings->TmpDcm, 1, 2);
908 err0++; 830 err0++;
831 }
909 if (settings->field_per_buff != 1 && 832 if (settings->field_per_buff != 1 &&
910 settings->field_per_buff != 2) 833 settings->field_per_buff != 2) {
834 settings->field_per_buff = clamp(settings->field_per_buff, 1, 2);
911 err0++; 835 err0++;
912 if (settings->img_x < 0) 836 }
837 if (settings->img_x < 0) {
838 settings->img_x = 0;
913 err0++; 839 err0++;
914 if (settings->img_y < 0) 840 }
841 if (settings->img_y < 0) {
842 settings->img_y = 0;
915 err0++; 843 err0++;
916 if (settings->img_width < 0) 844 }
845 if (settings->img_width < 0 || settings->img_width > BUZ_MAX_WIDTH) {
846 settings->img_width = clamp(settings->img_width, 0, (int)BUZ_MAX_WIDTH);
917 err0++; 847 err0++;
918 if (settings->img_height < 0) 848 }
849 if (settings->img_height < 0 || settings->img_height > BUZ_MAX_HEIGHT / 2) {
850 settings->img_height = clamp(settings->img_height, 0, BUZ_MAX_HEIGHT / 2);
919 err0++; 851 err0++;
920 if (settings->img_x + settings->img_width > BUZ_MAX_WIDTH) 852 }
853 if (settings->img_x + settings->img_width > BUZ_MAX_WIDTH) {
854 settings->img_x = BUZ_MAX_WIDTH - settings->img_width;
921 err0++; 855 err0++;
922 if (settings->img_y + settings->img_height > 856 }
923 BUZ_MAX_HEIGHT / 2) 857 if (settings->img_y + settings->img_height > BUZ_MAX_HEIGHT / 2) {
858 settings->img_y = BUZ_MAX_HEIGHT / 2 - settings->img_height;
859 err0++;
860 }
861 if (settings->img_width % (16 * settings->HorDcm) != 0) {
862 settings->img_width -= settings->img_width % (16 * settings->HorDcm);
863 if (settings->img_width == 0)
864 settings->img_width = 16 * settings->HorDcm;
865 err0++;
866 }
867 if (settings->img_height % (8 * settings->VerDcm) != 0) {
868 settings->img_height -= settings->img_height % (8 * settings->VerDcm);
869 if (settings->img_height == 0)
870 settings->img_height = 8 * settings->VerDcm;
924 err0++; 871 err0++;
925 if (settings->HorDcm && settings->VerDcm) {
926 if (settings->img_width %
927 (16 * settings->HorDcm) != 0)
928 err0++;
929 if (settings->img_height %
930 (8 * settings->VerDcm) != 0)
931 err0++;
932 } 872 }
933 873
934 if (err0) { 874 if (!try && err0) {
935 dprintk(1, 875 dprintk(1,
936 KERN_ERR 876 KERN_ERR
937 "%s: check_jpg_settings() - error in params for decimation = 0\n", 877 "%s: %s - error in params for decimation = 0\n",
938 ZR_DEVNAME(zr)); 878 ZR_DEVNAME(zr), __func__);
939 err++; 879 err++;
940 } 880 }
941 break; 881 break;
942 default: 882 default:
943 dprintk(1, 883 dprintk(1,
944 KERN_ERR 884 KERN_ERR
945 "%s: check_jpg_settings() - decimation = %d, must be 0, 1, 2 or 4\n", 885 "%s: %s - decimation = %d, must be 0, 1, 2 or 4\n",
946 ZR_DEVNAME(zr), settings->decimation); 886 ZR_DEVNAME(zr), __func__, settings->decimation);
947 err++; 887 err++;
948 break; 888 break;
949 } 889 }
@@ -1021,12 +961,10 @@ zoran_open_init_params (struct zoran *zr)
1021 sizeof(zr->jpg_settings.jpg_comp.COM_data)); 961 sizeof(zr->jpg_settings.jpg_comp.COM_data));
1022 zr->jpg_settings.jpg_comp.jpeg_markers = 962 zr->jpg_settings.jpg_comp.jpeg_markers =
1023 JPEG_MARKER_DHT | JPEG_MARKER_DQT; 963 JPEG_MARKER_DHT | JPEG_MARKER_DQT;
1024 i = zoran_check_jpg_settings(zr, &zr->jpg_settings); 964 i = zoran_check_jpg_settings(zr, &zr->jpg_settings, 0);
1025 if (i) 965 if (i)
1026 dprintk(1, 966 dprintk(1, KERN_ERR "%s: %s internal error\n",
1027 KERN_ERR 967 ZR_DEVNAME(zr), __func__);
1028 "%s: zoran_open_init_params() internal error\n",
1029 ZR_DEVNAME(zr));
1030 968
1031 clear_interrupt_counters(zr); 969 clear_interrupt_counters(zr);
1032 zr->testing = 0; 970 zr->testing = 0;
@@ -1062,13 +1000,11 @@ static int __devinit
1062zr36057_init (struct zoran *zr) 1000zr36057_init (struct zoran *zr)
1063{ 1001{
1064 int j, err; 1002 int j, err;
1065 int two = 2;
1066 int zero = 0;
1067 1003
1068 dprintk(1, 1004 dprintk(1,
1069 KERN_INFO 1005 KERN_INFO
1070 "%s: zr36057_init() - initializing card[%d], zr=%p\n", 1006 "%s: %s - initializing card[%d], zr=%p\n",
1071 ZR_DEVNAME(zr), zr->id, zr); 1007 ZR_DEVNAME(zr), __func__, zr->id, zr);
1072 1008
1073 /* default setup of all parameters which will persist between opens */ 1009 /* default setup of all parameters which will persist between opens */
1074 zr->user = 0; 1010 zr->user = 0;
@@ -1079,24 +1015,32 @@ zr36057_init (struct zoran *zr)
1079 zr->jpg_buffers.allocated = 0; 1015 zr->jpg_buffers.allocated = 0;
1080 zr->v4l_buffers.allocated = 0; 1016 zr->v4l_buffers.allocated = 0;
1081 1017
1082 zr->buffer.base = (void *) vidmem; 1018 zr->vbuf_base = (void *) vidmem;
1083 zr->buffer.width = 0; 1019 zr->vbuf_width = 0;
1084 zr->buffer.height = 0; 1020 zr->vbuf_height = 0;
1085 zr->buffer.depth = 0; 1021 zr->vbuf_depth = 0;
1086 zr->buffer.bytesperline = 0; 1022 zr->vbuf_bytesperline = 0;
1087 1023
1088 /* Avoid nonsense settings from user for default input/norm */ 1024 /* Avoid nonsense settings from user for default input/norm */
1089 if (default_norm < VIDEO_MODE_PAL && 1025 if (default_norm < 0 && default_norm > 2)
1090 default_norm > VIDEO_MODE_SECAM) 1026 default_norm = 0;
1091 default_norm = VIDEO_MODE_PAL; 1027 if (default_norm == 0) {
1092 zr->norm = default_norm; 1028 zr->norm = V4L2_STD_PAL;
1093 if (!(zr->timing = zr->card.tvn[zr->norm])) { 1029 zr->timing = zr->card.tvn[0];
1030 } else if (default_norm == 1) {
1031 zr->norm = V4L2_STD_NTSC;
1032 zr->timing = zr->card.tvn[1];
1033 } else {
1034 zr->norm = V4L2_STD_SECAM;
1035 zr->timing = zr->card.tvn[2];
1036 }
1037 if (zr->timing == NULL) {
1094 dprintk(1, 1038 dprintk(1,
1095 KERN_WARNING 1039 KERN_WARNING
1096 "%s: zr36057_init() - default TV standard not supported by hardware. PAL will be used.\n", 1040 "%s: %s - default TV standard not supported by hardware. PAL will be used.\n",
1097 ZR_DEVNAME(zr)); 1041 ZR_DEVNAME(zr), __func__);
1098 zr->norm = VIDEO_MODE_PAL; 1042 zr->norm = V4L2_STD_PAL;
1099 zr->timing = zr->card.tvn[zr->norm]; 1043 zr->timing = zr->card.tvn[0];
1100 } 1044 }
1101 1045
1102 if (default_input > zr->card.inputs-1) { 1046 if (default_input > zr->card.inputs-1) {
@@ -1108,12 +1052,6 @@ zr36057_init (struct zoran *zr)
1108 } 1052 }
1109 zr->input = default_input; 1053 zr->input = default_input;
1110 1054
1111 /* Should the following be reset at every open ? */
1112 zr->hue = 32768;
1113 zr->contrast = 32768;
1114 zr->saturation = 32768;
1115 zr->brightness = 32768;
1116
1117 /* default setup (will be repeated at every open) */ 1055 /* default setup (will be repeated at every open) */
1118 zoran_open_init_params(zr); 1056 zoran_open_init_params(zr);
1119 1057
@@ -1124,8 +1062,8 @@ zr36057_init (struct zoran *zr)
1124 if (!zr->stat_com || !zr->video_dev) { 1062 if (!zr->stat_com || !zr->video_dev) {
1125 dprintk(1, 1063 dprintk(1,
1126 KERN_ERR 1064 KERN_ERR
1127 "%s: zr36057_init() - kmalloc (STAT_COM) failed\n", 1065 "%s: %s - kmalloc (STAT_COM) failed\n",
1128 ZR_DEVNAME(zr)); 1066 ZR_DEVNAME(zr), __func__);
1129 err = -ENOMEM; 1067 err = -ENOMEM;
1130 goto exit_free; 1068 goto exit_free;
1131 } 1069 }
@@ -1137,6 +1075,7 @@ zr36057_init (struct zoran *zr)
1137 * Now add the template and register the device unit. 1075 * Now add the template and register the device unit.
1138 */ 1076 */
1139 memcpy(zr->video_dev, &zoran_template, sizeof(zoran_template)); 1077 memcpy(zr->video_dev, &zoran_template, sizeof(zoran_template));
1078 zr->video_dev->parent = &zr->pci_dev->dev;
1140 strcpy(zr->video_dev->name, ZR_DEVNAME(zr)); 1079 strcpy(zr->video_dev->name, ZR_DEVNAME(zr));
1141 err = video_register_device(zr->video_dev, VFL_TYPE_GRABBER, video_nr[zr->id]); 1080 err = video_register_device(zr->video_dev, VFL_TYPE_GRABBER, video_nr[zr->id]);
1142 if (err < 0) 1081 if (err < 0)
@@ -1148,8 +1087,10 @@ zr36057_init (struct zoran *zr)
1148 detect_guest_activity(zr); 1087 detect_guest_activity(zr);
1149 test_interrupts(zr); 1088 test_interrupts(zr);
1150 if (!pass_through) { 1089 if (!pass_through) {
1151 decoder_command(zr, DECODER_ENABLE_OUTPUT, &zero); 1090 struct v4l2_routing route = { 2, 0 };
1152 encoder_command(zr, ENCODER_SET_INPUT, &two); 1091
1092 decoder_call(zr, video, s_stream, 0);
1093 encoder_call(zr, video, s_routing, &route);
1153 } 1094 }
1154 1095
1155 zr->zoran_proc = NULL; 1096 zr->zoran_proc = NULL;
@@ -1164,7 +1105,8 @@ exit_free:
1164 1105
1165static void __devexit zoran_remove(struct pci_dev *pdev) 1106static void __devexit zoran_remove(struct pci_dev *pdev)
1166{ 1107{
1167 struct zoran *zr = pci_get_drvdata(pdev); 1108 struct v4l2_device *v4l2_dev = dev_get_drvdata(&pdev->dev);
1109 struct zoran *zr = to_zoran(v4l2_dev);
1168 1110
1169 if (!zr->initialized) 1111 if (!zr->initialized)
1170 goto exit_free; 1112 goto exit_free;
@@ -1197,7 +1139,7 @@ static void __devexit zoran_remove(struct pci_dev *pdev)
1197 pci_disable_device(zr->pci_dev); 1139 pci_disable_device(zr->pci_dev);
1198 video_unregister_device(zr->video_dev); 1140 video_unregister_device(zr->video_dev);
1199exit_free: 1141exit_free:
1200 pci_set_drvdata(pdev, NULL); 1142 v4l2_device_unregister(&zr->v4l2_dev);
1201 kfree(zr); 1143 kfree(zr);
1202} 1144}
1203 1145
@@ -1215,10 +1157,8 @@ zoran_setup_videocodec (struct zoran *zr,
1215 1157
1216 m = kmalloc(sizeof(struct videocodec_master), GFP_KERNEL); 1158 m = kmalloc(sizeof(struct videocodec_master), GFP_KERNEL);
1217 if (!m) { 1159 if (!m) {
1218 dprintk(1, 1160 dprintk(1, KERN_ERR "%s: %s - no memory\n",
1219 KERN_ERR 1161 ZR_DEVNAME(zr), __func__);
1220 "%s: zoran_setup_videocodec() - no memory\n",
1221 ZR_DEVNAME(zr));
1222 return m; 1162 return m;
1223 } 1163 }
1224 1164
@@ -1256,6 +1196,18 @@ zoran_setup_videocodec (struct zoran *zr,
1256 return m; 1196 return m;
1257} 1197}
1258 1198
1199static void zoran_subdev_notify(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
1200{
1201 struct zoran *zr = to_zoran(sd->v4l2_dev);
1202
1203 /* Bt819 needs to reset its FIFO buffer using #FRST pin and
1204 LML33 card uses GPIO(7) for that. */
1205 if (cmd == BT819_FIFO_RESET_LOW)
1206 GPIO(zr, 7, 0);
1207 else if (cmd == BT819_FIFO_RESET_HIGH)
1208 GPIO(zr, 7, 1);
1209}
1210
1259/* 1211/*
1260 * Scan for a Buz card (actually for the PCI controller ZR36057), 1212 * Scan for a Buz card (actually for the PCI controller ZR36057),
1261 * request the irq and map the io memory 1213 * request the irq and map the io memory
@@ -1269,34 +1221,33 @@ static int __devinit zoran_probe(struct pci_dev *pdev,
1269 struct videocodec_master *master_vfe = NULL; 1221 struct videocodec_master *master_vfe = NULL;
1270 struct videocodec_master *master_codec = NULL; 1222 struct videocodec_master *master_codec = NULL;
1271 int card_num; 1223 int card_num;
1272 char *i2c_enc_name, *i2c_dec_name, *codec_name, *vfe_name; 1224 char *codec_name, *vfe_name;
1273 unsigned int nr; 1225 unsigned int nr;
1274 1226
1275 1227
1276 nr = zoran_num++; 1228 nr = zoran_num++;
1277 if (nr >= BUZ_MAX) { 1229 if (nr >= BUZ_MAX) {
1278 dprintk(1, 1230 dprintk(1, KERN_ERR "%s: driver limited to %d card(s) maximum\n",
1279 KERN_ERR
1280 "%s: driver limited to %d card(s) maximum\n",
1281 ZORAN_NAME, BUZ_MAX); 1231 ZORAN_NAME, BUZ_MAX);
1282 return -ENOENT; 1232 return -ENOENT;
1283 } 1233 }
1284 1234
1285 zr = kzalloc(sizeof(struct zoran), GFP_KERNEL); 1235 zr = kzalloc(sizeof(struct zoran), GFP_KERNEL);
1286 if (!zr) { 1236 if (!zr) {
1287 dprintk(1, 1237 dprintk(1, KERN_ERR "%s: %s - kzalloc failed\n",
1288 KERN_ERR 1238 ZORAN_NAME, __func__);
1289 "%s: find_zr36057() - kzalloc failed\n",
1290 ZORAN_NAME);
1291 return -ENOMEM; 1239 return -ENOMEM;
1292 } 1240 }
1241 zr->v4l2_dev.notify = zoran_subdev_notify;
1242 if (v4l2_device_register(&pdev->dev, &zr->v4l2_dev))
1243 goto zr_free_mem;
1293 zr->pci_dev = pdev; 1244 zr->pci_dev = pdev;
1294 zr->id = nr; 1245 zr->id = nr;
1295 snprintf(ZR_DEVNAME(zr), sizeof(ZR_DEVNAME(zr)), "MJPEG[%u]", zr->id); 1246 snprintf(ZR_DEVNAME(zr), sizeof(ZR_DEVNAME(zr)), "MJPEG[%u]", zr->id);
1296 spin_lock_init(&zr->spinlock); 1247 spin_lock_init(&zr->spinlock);
1297 mutex_init(&zr->resource_lock); 1248 mutex_init(&zr->resource_lock);
1298 if (pci_enable_device(pdev)) 1249 if (pci_enable_device(pdev))
1299 goto zr_free_mem; 1250 goto zr_unreg;
1300 pci_read_config_byte(zr->pci_dev, PCI_CLASS_REVISION, &zr->revision); 1251 pci_read_config_byte(zr->pci_dev, PCI_CLASS_REVISION, &zr->revision);
1301 1252
1302 dprintk(1, 1253 dprintk(1,
@@ -1323,7 +1274,7 @@ static int __devinit zoran_probe(struct pci_dev *pdev,
1323 KERN_ERR 1274 KERN_ERR
1324 "%s: It is not possible to auto-detect ZR36057 based cards\n", 1275 "%s: It is not possible to auto-detect ZR36057 based cards\n",
1325 ZR_DEVNAME(zr)); 1276 ZR_DEVNAME(zr));
1326 goto zr_free_mem; 1277 goto zr_unreg;
1327 } 1278 }
1328 1279
1329 card_num = ent->driver_data; 1280 card_num = ent->driver_data;
@@ -1332,7 +1283,7 @@ static int __devinit zoran_probe(struct pci_dev *pdev,
1332 KERN_ERR 1283 KERN_ERR
1333 "%s: Unknown card, try specifying card=X module parameter\n", 1284 "%s: Unknown card, try specifying card=X module parameter\n",
1334 ZR_DEVNAME(zr)); 1285 ZR_DEVNAME(zr));
1335 goto zr_free_mem; 1286 goto zr_unreg;
1336 } 1287 }
1337 dprintk(3, 1288 dprintk(3,
1338 KERN_DEBUG 1289 KERN_DEBUG
@@ -1345,7 +1296,7 @@ static int __devinit zoran_probe(struct pci_dev *pdev,
1345 KERN_ERR 1296 KERN_ERR
1346 "%s: User specified card type %d out of range (0 .. %d)\n", 1297 "%s: User specified card type %d out of range (0 .. %d)\n",
1347 ZR_DEVNAME(zr), card_num, NUM_CARDS - 1); 1298 ZR_DEVNAME(zr), card_num, NUM_CARDS - 1);
1348 goto zr_free_mem; 1299 goto zr_unreg;
1349 } 1300 }
1350 } 1301 }
1351 1302
@@ -1360,11 +1311,9 @@ static int __devinit zoran_probe(struct pci_dev *pdev,
1360 1311
1361 zr->zr36057_mem = pci_ioremap_bar(zr->pci_dev, 0); 1312 zr->zr36057_mem = pci_ioremap_bar(zr->pci_dev, 0);
1362 if (!zr->zr36057_mem) { 1313 if (!zr->zr36057_mem) {
1363 dprintk(1, 1314 dprintk(1, KERN_ERR "%s: %s() - ioremap failed\n",
1364 KERN_ERR
1365 "%s: %s() - ioremap failed\n",
1366 ZR_DEVNAME(zr), __func__); 1315 ZR_DEVNAME(zr), __func__);
1367 goto zr_free_mem; 1316 goto zr_unreg;
1368 } 1317 }
1369 1318
1370 result = request_irq(zr->pci_dev->irq, zoran_irq, 1319 result = request_irq(zr->pci_dev->irq, zoran_irq,
@@ -1373,18 +1322,18 @@ static int __devinit zoran_probe(struct pci_dev *pdev,
1373 if (result == -EINVAL) { 1322 if (result == -EINVAL) {
1374 dprintk(1, 1323 dprintk(1,
1375 KERN_ERR 1324 KERN_ERR
1376 "%s: find_zr36057() - bad irq number or handler\n", 1325 "%s: %s - bad irq number or handler\n",
1377 ZR_DEVNAME(zr)); 1326 ZR_DEVNAME(zr), __func__);
1378 } else if (result == -EBUSY) { 1327 } else if (result == -EBUSY) {
1379 dprintk(1, 1328 dprintk(1,
1380 KERN_ERR 1329 KERN_ERR
1381 "%s: find_zr36057() - IRQ %d busy, change your PnP config in BIOS\n", 1330 "%s: %s - IRQ %d busy, change your PnP config in BIOS\n",
1382 ZR_DEVNAME(zr), zr->pci_dev->irq); 1331 ZR_DEVNAME(zr), __func__, zr->pci_dev->irq);
1383 } else { 1332 } else {
1384 dprintk(1, 1333 dprintk(1,
1385 KERN_ERR 1334 KERN_ERR
1386 "%s: find_zr36057() - can't assign irq, error code %d\n", 1335 "%s: %s - can't assign irq, error code %d\n",
1387 ZR_DEVNAME(zr), result); 1336 ZR_DEVNAME(zr), __func__, result);
1388 } 1337 }
1389 goto zr_unmap; 1338 goto zr_unmap;
1390 } 1339 }
@@ -1394,9 +1343,7 @@ static int __devinit zoran_probe(struct pci_dev *pdev,
1394 &latency); 1343 &latency);
1395 need_latency = zr->revision > 1 ? 32 : 48; 1344 need_latency = zr->revision > 1 ? 32 : 48;
1396 if (latency != need_latency) { 1345 if (latency != need_latency) {
1397 dprintk(2, 1346 dprintk(2, KERN_INFO "%s: Changing PCI latency from %d to %d\n",
1398 KERN_INFO
1399 "%s: Changing PCI latency from %d to %d\n",
1400 ZR_DEVNAME(zr), latency, need_latency); 1347 ZR_DEVNAME(zr), latency, need_latency);
1401 pci_write_config_byte(zr->pci_dev, PCI_LATENCY_TIMER, 1348 pci_write_config_byte(zr->pci_dev, PCI_LATENCY_TIMER,
1402 need_latency); 1349 need_latency);
@@ -1407,54 +1354,20 @@ static int __devinit zoran_probe(struct pci_dev *pdev,
1407 dprintk(2, KERN_INFO "%s: Initializing i2c bus...\n", 1354 dprintk(2, KERN_INFO "%s: Initializing i2c bus...\n",
1408 ZR_DEVNAME(zr)); 1355 ZR_DEVNAME(zr));
1409 1356
1410 /* i2c decoder */
1411 if (decoder[zr->id] != -1) {
1412 i2c_dec_name = i2cid_to_modulename(decoder[zr->id]);
1413 zr->card.i2c_decoder = decoder[zr->id];
1414 } else if (zr->card.i2c_decoder != 0) {
1415 i2c_dec_name = i2cid_to_modulename(zr->card.i2c_decoder);
1416 } else {
1417 i2c_dec_name = NULL;
1418 }
1419
1420 if (i2c_dec_name) {
1421 result = request_module(i2c_dec_name);
1422 if (result < 0) {
1423 dprintk(1,
1424 KERN_ERR
1425 "%s: failed to load module %s: %d\n",
1426 ZR_DEVNAME(zr), i2c_dec_name, result);
1427 }
1428 }
1429
1430 /* i2c encoder */
1431 if (encoder[zr->id] != -1) {
1432 i2c_enc_name = i2cid_to_modulename(encoder[zr->id]);
1433 zr->card.i2c_encoder = encoder[zr->id];
1434 } else if (zr->card.i2c_encoder != 0) {
1435 i2c_enc_name = i2cid_to_modulename(zr->card.i2c_encoder);
1436 } else {
1437 i2c_enc_name = NULL;
1438 }
1439
1440 if (i2c_enc_name) {
1441 result = request_module(i2c_enc_name);
1442 if (result < 0) {
1443 dprintk(1,
1444 KERN_ERR
1445 "%s: failed to load module %s: %d\n",
1446 ZR_DEVNAME(zr), i2c_enc_name, result);
1447 }
1448 }
1449
1450 if (zoran_register_i2c(zr) < 0) { 1357 if (zoran_register_i2c(zr) < 0) {
1451 dprintk(1, 1358 dprintk(1, KERN_ERR "%s: %s - can't initialize i2c bus\n",
1452 KERN_ERR 1359 ZR_DEVNAME(zr), __func__);
1453 "%s: find_zr36057() - can't initialize i2c bus\n",
1454 ZR_DEVNAME(zr));
1455 goto zr_free_irq; 1360 goto zr_free_irq;
1456 } 1361 }
1457 1362
1363 zr->decoder = v4l2_i2c_new_probed_subdev(&zr->i2c_adapter,
1364 zr->card.mod_decoder, zr->card.i2c_decoder, zr->card.addrs_decoder);
1365
1366 if (zr->card.mod_encoder)
1367 zr->encoder = v4l2_i2c_new_probed_subdev(&zr->i2c_adapter,
1368 zr->card.mod_encoder, zr->card.i2c_encoder,
1369 zr->card.addrs_encoder);
1370
1458 dprintk(2, 1371 dprintk(2,
1459 KERN_INFO "%s: Initializing videocodec bus...\n", 1372 KERN_INFO "%s: Initializing videocodec bus...\n",
1460 ZR_DEVNAME(zr)); 1373 ZR_DEVNAME(zr));
@@ -1495,17 +1408,13 @@ static int __devinit zoran_probe(struct pci_dev *pdev,
1495 goto zr_unreg_i2c; 1408 goto zr_unreg_i2c;
1496 zr->codec = videocodec_attach(master_codec); 1409 zr->codec = videocodec_attach(master_codec);
1497 if (!zr->codec) { 1410 if (!zr->codec) {
1498 dprintk(1, 1411 dprintk(1, KERN_ERR "%s: %s - no codec found\n",
1499 KERN_ERR 1412 ZR_DEVNAME(zr), __func__);
1500 "%s: find_zr36057() - no codec found\n",
1501 ZR_DEVNAME(zr));
1502 goto zr_free_codec; 1413 goto zr_free_codec;
1503 } 1414 }
1504 if (zr->codec->type != zr->card.video_codec) { 1415 if (zr->codec->type != zr->card.video_codec) {
1505 dprintk(1, 1416 dprintk(1, KERN_ERR "%s: %s - wrong codec\n",
1506 KERN_ERR 1417 ZR_DEVNAME(zr), __func__);
1507 "%s: find_zr36057() - wrong codec\n",
1508 ZR_DEVNAME(zr));
1509 goto zr_detach_codec; 1418 goto zr_detach_codec;
1510 } 1419 }
1511 } 1420 }
@@ -1515,17 +1424,13 @@ static int __devinit zoran_probe(struct pci_dev *pdev,
1515 goto zr_detach_codec; 1424 goto zr_detach_codec;
1516 zr->vfe = videocodec_attach(master_vfe); 1425 zr->vfe = videocodec_attach(master_vfe);
1517 if (!zr->vfe) { 1426 if (!zr->vfe) {
1518 dprintk(1, 1427 dprintk(1, KERN_ERR "%s: %s - no VFE found\n",
1519 KERN_ERR 1428 ZR_DEVNAME(zr), __func__);
1520 "%s: find_zr36057() - no VFE found\n",
1521 ZR_DEVNAME(zr));
1522 goto zr_free_vfe; 1429 goto zr_free_vfe;
1523 } 1430 }
1524 if (zr->vfe->type != zr->card.video_vfe) { 1431 if (zr->vfe->type != zr->card.video_vfe) {
1525 dprintk(1, 1432 dprintk(1, KERN_ERR "%s: %s = wrong VFE\n",
1526 KERN_ERR 1433 ZR_DEVNAME(zr), __func__);
1527 "%s: find_zr36057() = wrong VFE\n",
1528 ZR_DEVNAME(zr));
1529 goto zr_detach_vfe; 1434 goto zr_detach_vfe;
1530 } 1435 }
1531 } 1436 }
@@ -1533,8 +1438,7 @@ static int __devinit zoran_probe(struct pci_dev *pdev,
1533 /* take care of Natoma chipset and a revision 1 zr36057 */ 1438 /* take care of Natoma chipset and a revision 1 zr36057 */
1534 if ((pci_pci_problems & PCIPCI_NATOMA) && zr->revision <= 1) { 1439 if ((pci_pci_problems & PCIPCI_NATOMA) && zr->revision <= 1) {
1535 zr->jpg_buffers.need_contiguous = 1; 1440 zr->jpg_buffers.need_contiguous = 1;
1536 dprintk(1, 1441 dprintk(1, KERN_INFO
1537 KERN_INFO
1538 "%s: ZR36057/Natoma bug, max. buffer size is 128K\n", 1442 "%s: ZR36057/Natoma bug, max. buffer size is 128K\n",
1539 ZR_DEVNAME(zr)); 1443 ZR_DEVNAME(zr));
1540 } 1444 }
@@ -1544,8 +1448,6 @@ static int __devinit zoran_probe(struct pci_dev *pdev,
1544 1448
1545 zoran_proc_init(zr); 1449 zoran_proc_init(zr);
1546 1450
1547 pci_set_drvdata(pdev, zr);
1548
1549 return 0; 1451 return 0;
1550 1452
1551zr_detach_vfe: 1453zr_detach_vfe:
@@ -1563,6 +1465,8 @@ zr_free_irq:
1563 free_irq(zr->pci_dev->irq, zr); 1465 free_irq(zr->pci_dev->irq, zr);
1564zr_unmap: 1466zr_unmap:
1565 iounmap(zr->zr36057_mem); 1467 iounmap(zr->zr36057_mem);
1468zr_unreg:
1469 v4l2_device_unregister(&zr->v4l2_dev);
1566zr_free_mem: 1470zr_free_mem:
1567 kfree(zr); 1471 kfree(zr);
1568 1472
@@ -1613,9 +1517,6 @@ static int __init zoran_init(void)
1613 ZORAN_NAME, vidmem); 1517 ZORAN_NAME, vidmem);
1614 } 1518 }
1615 1519
1616 /* random nonsense */
1617 dprintk(6, KERN_DEBUG "Jotti is een held!\n");
1618
1619 /* some mainboards might not do PCI-PCI data transfer well */ 1520 /* some mainboards might not do PCI-PCI data transfer well */
1620 if (pci_pci_problems & (PCIPCI_FAIL|PCIAGP_FAIL|PCIPCI_ALIMAGIK)) { 1521 if (pci_pci_problems & (PCIPCI_FAIL|PCIAGP_FAIL|PCIPCI_ALIMAGIK)) {
1621 dprintk(1, 1522 dprintk(1,
diff --git a/drivers/media/video/zoran/zoran_card.h b/drivers/media/video/zoran/zoran_card.h
index 4507bdc5e338..4936fead73e8 100644
--- a/drivers/media/video/zoran/zoran_card.h
+++ b/drivers/media/video/zoran/zoran_card.h
@@ -44,7 +44,8 @@ extern int zr36067_debug;
44extern struct video_device zoran_template; 44extern struct video_device zoran_template;
45 45
46extern int zoran_check_jpg_settings(struct zoran *zr, 46extern int zoran_check_jpg_settings(struct zoran *zr,
47 struct zoran_jpg_settings *settings); 47 struct zoran_jpg_settings *settings,
48 int try);
48extern void zoran_open_init_params(struct zoran *zr); 49extern void zoran_open_init_params(struct zoran *zr);
49extern void zoran_vdev_release(struct video_device *vdev); 50extern void zoran_vdev_release(struct video_device *vdev);
50 51
diff --git a/drivers/media/video/zoran/zoran_device.c b/drivers/media/video/zoran/zoran_device.c
index 5d948ff7faf0..e0223deed35e 100644
--- a/drivers/media/video/zoran/zoran_device.c
+++ b/drivers/media/video/zoran/zoran_device.c
@@ -36,13 +36,12 @@
36#include <linux/proc_fs.h> 36#include <linux/proc_fs.h>
37#include <linux/i2c.h> 37#include <linux/i2c.h>
38#include <linux/i2c-algo-bit.h> 38#include <linux/i2c-algo-bit.h>
39#include <linux/videodev.h> 39#include <linux/videodev2.h>
40#include <media/v4l2-common.h>
40#include <linux/spinlock.h> 41#include <linux/spinlock.h>
41#include <linux/sem.h> 42#include <linux/sem.h>
42 43
43#include <linux/pci.h> 44#include <linux/pci.h>
44#include <linux/video_decoder.h>
45#include <linux/video_encoder.h>
46#include <linux/delay.h> 45#include <linux/delay.h>
47#include <linux/wait.h> 46#include <linux/wait.h>
48 47
@@ -312,9 +311,9 @@ zr36057_adjust_vfe (struct zoran *zr,
312 case BUZ_MODE_MOTION_COMPRESS: 311 case BUZ_MODE_MOTION_COMPRESS:
313 case BUZ_MODE_IDLE: 312 case BUZ_MODE_IDLE:
314 default: 313 default:
315 if (zr->norm == VIDEO_MODE_NTSC || 314 if ((zr->norm & V4L2_STD_NTSC) ||
316 (zr->card.type == LML33R10 && 315 (zr->card.type == LML33R10 &&
317 zr->norm == VIDEO_MODE_PAL)) 316 (zr->norm & V4L2_STD_PAL)))
318 btand(~ZR36057_VFESPFR_ExtFl, ZR36057_VFESPFR); 317 btand(~ZR36057_VFESPFR_ExtFl, ZR36057_VFESPFR);
319 else 318 else
320 btor(ZR36057_VFESPFR_ExtFl, ZR36057_VFESPFR); 319 btor(ZR36057_VFESPFR_ExtFl, ZR36057_VFESPFR);
@@ -355,14 +354,6 @@ zr36057_set_vfe (struct zoran *zr,
355 dprintk(2, KERN_INFO "%s: set_vfe() - width = %d, height = %d\n", 354 dprintk(2, KERN_INFO "%s: set_vfe() - width = %d, height = %d\n",
356 ZR_DEVNAME(zr), video_width, video_height); 355 ZR_DEVNAME(zr), video_width, video_height);
357 356
358 if (zr->norm != VIDEO_MODE_PAL &&
359 zr->norm != VIDEO_MODE_NTSC &&
360 zr->norm != VIDEO_MODE_SECAM) {
361 dprintk(1,
362 KERN_ERR "%s: set_vfe() - norm = %d not valid\n",
363 ZR_DEVNAME(zr), zr->norm);
364 return;
365 }
366 if (video_width < BUZ_MIN_WIDTH || 357 if (video_width < BUZ_MIN_WIDTH ||
367 video_height < BUZ_MIN_HEIGHT || 358 video_height < BUZ_MIN_HEIGHT ||
368 video_width > Wa || video_height > Ha) { 359 video_width > Wa || video_height > Ha) {
@@ -426,7 +417,7 @@ zr36057_set_vfe (struct zoran *zr,
426 * we get the correct colors when uncompressing to the screen */ 417 * we get the correct colors when uncompressing to the screen */
427 //reg |= ZR36057_VFESPFR_VCLKPol; /**/ 418 //reg |= ZR36057_VFESPFR_VCLKPol; /**/
428 /* RJ: Don't know if that is needed for NTSC also */ 419 /* RJ: Don't know if that is needed for NTSC also */
429 if (zr->norm != VIDEO_MODE_NTSC) 420 if (!(zr->norm & V4L2_STD_NTSC))
430 reg |= ZR36057_VFESPFR_ExtFl; // NEEDED!!!!!!! Wolfgang 421 reg |= ZR36057_VFESPFR_ExtFl; // NEEDED!!!!!!! Wolfgang
431 reg |= ZR36057_VFESPFR_TopField; 422 reg |= ZR36057_VFESPFR_TopField;
432 if (HorDcm >= 48) { 423 if (HorDcm >= 48) {
@@ -497,11 +488,11 @@ zr36057_overlay (struct zoran *zr,
497 * All error messages are internal driver checking only! */ 488 * All error messages are internal driver checking only! */
498 489
499 /* video display top and bottom registers */ 490 /* video display top and bottom registers */
500 reg = (long) zr->buffer.base + 491 reg = (long) zr->vbuf_base +
501 zr->overlay_settings.x * 492 zr->overlay_settings.x *
502 ((zr->overlay_settings.format->depth + 7) / 8) + 493 ((zr->overlay_settings.format->depth + 7) / 8) +
503 zr->overlay_settings.y * 494 zr->overlay_settings.y *
504 zr->buffer.bytesperline; 495 zr->vbuf_bytesperline;
505 btwrite(reg, ZR36057_VDTR); 496 btwrite(reg, ZR36057_VDTR);
506 if (reg & 3) 497 if (reg & 3)
507 dprintk(1, 498 dprintk(1,
@@ -509,15 +500,15 @@ zr36057_overlay (struct zoran *zr,
509 "%s: zr36057_overlay() - video_address not aligned\n", 500 "%s: zr36057_overlay() - video_address not aligned\n",
510 ZR_DEVNAME(zr)); 501 ZR_DEVNAME(zr));
511 if (zr->overlay_settings.height > BUZ_MAX_HEIGHT / 2) 502 if (zr->overlay_settings.height > BUZ_MAX_HEIGHT / 2)
512 reg += zr->buffer.bytesperline; 503 reg += zr->vbuf_bytesperline;
513 btwrite(reg, ZR36057_VDBR); 504 btwrite(reg, ZR36057_VDBR);
514 505
515 /* video stride, status, and frame grab register */ 506 /* video stride, status, and frame grab register */
516 reg = zr->buffer.bytesperline - 507 reg = zr->vbuf_bytesperline -
517 zr->overlay_settings.width * 508 zr->overlay_settings.width *
518 ((zr->overlay_settings.format->depth + 7) / 8); 509 ((zr->overlay_settings.format->depth + 7) / 8);
519 if (zr->overlay_settings.height > BUZ_MAX_HEIGHT / 2) 510 if (zr->overlay_settings.height > BUZ_MAX_HEIGHT / 2)
520 reg += zr->buffer.bytesperline; 511 reg += zr->vbuf_bytesperline;
521 if (reg & 3) 512 if (reg & 3)
522 dprintk(1, 513 dprintk(1,
523 KERN_ERR 514 KERN_ERR
@@ -544,12 +535,8 @@ zr36057_overlay (struct zoran *zr,
544 * and the maximum window size is BUZ_MAX_WIDTH * BUZ_MAX_HEIGHT pixels. 535 * and the maximum window size is BUZ_MAX_WIDTH * BUZ_MAX_HEIGHT pixels.
545 */ 536 */
546 537
547void 538void write_overlay_mask(struct zoran_fh *fh, struct v4l2_clip *vp, int count)
548write_overlay_mask (struct file *file,
549 struct video_clip *vp,
550 int count)
551{ 539{
552 struct zoran_fh *fh = file->private_data;
553 struct zoran *zr = fh->zr; 540 struct zoran *zr = fh->zr;
554 unsigned mask_line_size = (BUZ_MAX_WIDTH + 31) / 32; 541 unsigned mask_line_size = (BUZ_MAX_WIDTH + 31) / 32;
555 u32 *mask; 542 u32 *mask;
@@ -563,10 +550,10 @@ write_overlay_mask (struct file *file,
563 550
564 for (i = 0; i < count; ++i) { 551 for (i = 0; i < count; ++i) {
565 /* pick up local copy of clip */ 552 /* pick up local copy of clip */
566 x = vp[i].x; 553 x = vp[i].c.left;
567 y = vp[i].y; 554 y = vp[i].c.top;
568 width = vp[i].width; 555 width = vp[i].c.width;
569 height = vp[i].height; 556 height = vp[i].c.height;
570 557
571 /* trim clips that extend beyond the window */ 558 /* trim clips that extend beyond the window */
572 if (x < 0) { 559 if (x < 0) {
@@ -981,11 +968,10 @@ void
981zr36057_enable_jpg (struct zoran *zr, 968zr36057_enable_jpg (struct zoran *zr,
982 enum zoran_codec_mode mode) 969 enum zoran_codec_mode mode)
983{ 970{
984 static int zero;
985 static int one = 1;
986 struct vfe_settings cap; 971 struct vfe_settings cap;
987 int field_size = 972 int field_size =
988 zr->jpg_buffers.buffer_size / zr->jpg_settings.field_per_buff; 973 zr->jpg_buffers.buffer_size / zr->jpg_settings.field_per_buff;
974 struct v4l2_routing route = { 0, 0 };
989 975
990 zr->codec_mode = mode; 976 zr->codec_mode = mode;
991 977
@@ -1007,8 +993,9 @@ zr36057_enable_jpg (struct zoran *zr,
1007 * the video bus direction set to input. 993 * the video bus direction set to input.
1008 */ 994 */
1009 set_videobus_dir(zr, 0); 995 set_videobus_dir(zr, 0);
1010 decoder_command(zr, DECODER_ENABLE_OUTPUT, &one); 996 decoder_call(zr, video, s_stream, 1);
1011 encoder_command(zr, ENCODER_SET_INPUT, &zero); 997 route.input = 0;
998 encoder_call(zr, video, s_routing, &route);
1012 999
1013 /* Take the JPEG codec and the VFE out of sleep */ 1000 /* Take the JPEG codec and the VFE out of sleep */
1014 jpeg_codec_sleep(zr, 0); 1001 jpeg_codec_sleep(zr, 0);
@@ -1054,9 +1041,10 @@ zr36057_enable_jpg (struct zoran *zr,
1054 /* In motion decompression mode, the decoder output must be disabled, and 1041 /* In motion decompression mode, the decoder output must be disabled, and
1055 * the video bus direction set to output. 1042 * the video bus direction set to output.
1056 */ 1043 */
1057 decoder_command(zr, DECODER_ENABLE_OUTPUT, &zero); 1044 decoder_call(zr, video, s_stream, 0);
1058 set_videobus_dir(zr, 1); 1045 set_videobus_dir(zr, 1);
1059 encoder_command(zr, ENCODER_SET_INPUT, &one); 1046 route.input = 1;
1047 encoder_call(zr, video, s_routing, &route);
1060 1048
1061 /* Take the JPEG codec and the VFE out of sleep */ 1049 /* Take the JPEG codec and the VFE out of sleep */
1062 jpeg_codec_sleep(zr, 0); 1050 jpeg_codec_sleep(zr, 0);
@@ -1100,8 +1088,9 @@ zr36057_enable_jpg (struct zoran *zr,
1100 jpeg_codec_sleep(zr, 1); 1088 jpeg_codec_sleep(zr, 1);
1101 zr36057_adjust_vfe(zr, mode); 1089 zr36057_adjust_vfe(zr, mode);
1102 1090
1103 decoder_command(zr, DECODER_ENABLE_OUTPUT, &one); 1091 decoder_call(zr, video, s_stream, 1);
1104 encoder_command(zr, ENCODER_SET_INPUT, &zero); 1092 route.input = 0;
1093 encoder_call(zr, video, s_routing, &route);
1105 1094
1106 dprintk(2, KERN_INFO "%s: enable_jpg(IDLE)\n", ZR_DEVNAME(zr)); 1095 dprintk(2, KERN_INFO "%s: enable_jpg(IDLE)\n", ZR_DEVNAME(zr));
1107 break; 1096 break;
@@ -1132,7 +1121,7 @@ zoran_feed_stat_com (struct zoran *zr)
1132 if (!(zr->stat_com[i] & cpu_to_le32(1))) 1121 if (!(zr->stat_com[i] & cpu_to_le32(1)))
1133 break; 1122 break;
1134 zr->stat_com[i] = 1123 zr->stat_com[i] =
1135 cpu_to_le32(zr->jpg_buffers.buffer[frame].frag_tab_bus); 1124 cpu_to_le32(zr->jpg_buffers.buffer[frame].jpg.frag_tab_bus);
1136 } else { 1125 } else {
1137 /* fill 2 stat_com entries */ 1126 /* fill 2 stat_com entries */
1138 i = ((zr->jpg_dma_head - 1127 i = ((zr->jpg_dma_head -
@@ -1140,9 +1129,9 @@ zoran_feed_stat_com (struct zoran *zr)
1140 if (!(zr->stat_com[i] & cpu_to_le32(1))) 1129 if (!(zr->stat_com[i] & cpu_to_le32(1)))
1141 break; 1130 break;
1142 zr->stat_com[i] = 1131 zr->stat_com[i] =
1143 cpu_to_le32(zr->jpg_buffers.buffer[frame].frag_tab_bus); 1132 cpu_to_le32(zr->jpg_buffers.buffer[frame].jpg.frag_tab_bus);
1144 zr->stat_com[i + 1] = 1133 zr->stat_com[i + 1] =
1145 cpu_to_le32(zr->jpg_buffers.buffer[frame].frag_tab_bus); 1134 cpu_to_le32(zr->jpg_buffers.buffer[frame].jpg.frag_tab_bus);
1146 } 1135 }
1147 zr->jpg_buffers.buffer[frame].state = BUZ_STATE_DMA; 1136 zr->jpg_buffers.buffer[frame].state = BUZ_STATE_DMA;
1148 zr->jpg_dma_head++; 1137 zr->jpg_dma_head++;
@@ -1162,7 +1151,7 @@ zoran_reap_stat_com (struct zoran *zr)
1162 u32 stat_com; 1151 u32 stat_com;
1163 unsigned int seq; 1152 unsigned int seq;
1164 unsigned int dif; 1153 unsigned int dif;
1165 struct zoran_jpg_buffer *buffer; 1154 struct zoran_buffer *buffer;
1166 int frame; 1155 int frame;
1167 1156
1168 /* In motion decompress we don't have a hardware frame counter, 1157 /* In motion decompress we don't have a hardware frame counter,
@@ -1208,22 +1197,52 @@ zoran_reap_stat_com (struct zoran *zr)
1208 } 1197 }
1209} 1198}
1210 1199
1200static void zoran_restart(struct zoran *zr)
1201{
1202 /* Now the stat_comm buffer is ready for restart */
1203 int status = 0, mode;
1204
1205 if (zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) {
1206 decoder_call(zr, video, g_input_status, &status);
1207 mode = CODEC_DO_COMPRESSION;
1208 } else {
1209 status = V4L2_IN_ST_NO_SIGNAL;
1210 mode = CODEC_DO_EXPANSION;
1211 }
1212 if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS ||
1213 !(status & V4L2_IN_ST_NO_SIGNAL)) {
1214 /********** RESTART code *************/
1215 jpeg_codec_reset(zr);
1216 zr->codec->set_mode(zr->codec, mode);
1217 zr36057_set_jpg(zr, zr->codec_mode);
1218 jpeg_start(zr);
1219
1220 if (zr->num_errors <= 8)
1221 dprintk(2, KERN_INFO "%s: Restart\n",
1222 ZR_DEVNAME(zr));
1223
1224 zr->JPEG_missed = 0;
1225 zr->JPEG_error = 2;
1226 /********** End RESTART code ***********/
1227 }
1228}
1229
1211static void 1230static void
1212error_handler (struct zoran *zr, 1231error_handler (struct zoran *zr,
1213 u32 astat, 1232 u32 astat,
1214 u32 stat) 1233 u32 stat)
1215{ 1234{
1235 int i, j;
1236
1216 /* This is JPEG error handling part */ 1237 /* This is JPEG error handling part */
1217 if ((zr->codec_mode != BUZ_MODE_MOTION_COMPRESS) && 1238 if (zr->codec_mode != BUZ_MODE_MOTION_COMPRESS &&
1218 (zr->codec_mode != BUZ_MODE_MOTION_DECOMPRESS)) { 1239 zr->codec_mode != BUZ_MODE_MOTION_DECOMPRESS) {
1219 //dprintk(1, KERN_ERR "%s: Internal error: error handling request in mode %d\n", ZR_DEVNAME(zr), zr->codec_mode);
1220 return; 1240 return;
1221 } 1241 }
1222 1242
1223 if ((stat & 1) == 0 && 1243 if ((stat & 1) == 0 &&
1224 zr->codec_mode == BUZ_MODE_MOTION_COMPRESS && 1244 zr->codec_mode == BUZ_MODE_MOTION_COMPRESS &&
1225 zr->jpg_dma_tail - zr->jpg_que_tail >= 1245 zr->jpg_dma_tail - zr->jpg_que_tail >= zr->jpg_buffers.num_buffers) {
1226 zr->jpg_buffers.num_buffers) {
1227 /* No free buffers... */ 1246 /* No free buffers... */
1228 zoran_reap_stat_com(zr); 1247 zoran_reap_stat_com(zr);
1229 zoran_feed_stat_com(zr); 1248 zoran_feed_stat_com(zr);
@@ -1232,142 +1251,95 @@ error_handler (struct zoran *zr,
1232 return; 1251 return;
1233 } 1252 }
1234 1253
1235 if (zr->JPEG_error != 1) { 1254 if (zr->JPEG_error == 1) {
1236 /* 1255 zoran_restart(zr);
1237 * First entry: error just happened during normal operation 1256 return;
1238 * 1257 }
1239 * In BUZ_MODE_MOTION_COMPRESS:
1240 *
1241 * Possible glitch in TV signal. In this case we should
1242 * stop the codec and wait for good quality signal before
1243 * restarting it to avoid further problems
1244 *
1245 * In BUZ_MODE_MOTION_DECOMPRESS:
1246 *
1247 * Bad JPEG frame: we have to mark it as processed (codec crashed
1248 * and was not able to do it itself), and to remove it from queue.
1249 */
1250 btand(~ZR36057_JMC_Go_en, ZR36057_JMC);
1251 udelay(1);
1252 stat = stat | (post_office_read(zr, 7, 0) & 3) << 8;
1253 btwrite(0, ZR36057_JPC);
1254 btor(ZR36057_MCTCR_CFlush, ZR36057_MCTCR);
1255 jpeg_codec_reset(zr);
1256 jpeg_codec_sleep(zr, 1);
1257 zr->JPEG_error = 1;
1258 zr->num_errors++;
1259
1260 /* Report error */
1261 if (zr36067_debug > 1 && zr->num_errors <= 8) {
1262 long frame;
1263 frame =
1264 zr->jpg_pend[zr->jpg_dma_tail & BUZ_MASK_FRAME];
1265 printk(KERN_ERR
1266 "%s: JPEG error stat=0x%08x(0x%08x) queue_state=%ld/%ld/%ld/%ld seq=%ld frame=%ld. Codec stopped. ",
1267 ZR_DEVNAME(zr), stat, zr->last_isr,
1268 zr->jpg_que_tail, zr->jpg_dma_tail,
1269 zr->jpg_dma_head, zr->jpg_que_head,
1270 zr->jpg_seq_num, frame);
1271 printk("stat_com frames:");
1272 {
1273 int i, j;
1274 for (j = 0; j < BUZ_NUM_STAT_COM; j++) {
1275 for (i = 0;
1276 i < zr->jpg_buffers.num_buffers;
1277 i++) {
1278 if (le32_to_cpu(zr->stat_com[j]) ==
1279 zr->jpg_buffers.
1280 buffer[i].
1281 frag_tab_bus) {
1282 printk("% d->%d",
1283 j, i);
1284 }
1285 }
1286 }
1287 printk("\n");
1288 }
1289 }
1290 /* Find an entry in stat_com and rotate contents */
1291 {
1292 int i;
1293
1294 if (zr->jpg_settings.TmpDcm == 1)
1295 i = (zr->jpg_dma_tail -
1296 zr->jpg_err_shift) & BUZ_MASK_STAT_COM;
1297 else
1298 i = ((zr->jpg_dma_tail -
1299 zr->jpg_err_shift) & 1) * 2;
1300 if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS) {
1301 /* Mimic zr36067 operation */
1302 zr->stat_com[i] |= cpu_to_le32(1);
1303 if (zr->jpg_settings.TmpDcm != 1)
1304 zr->stat_com[i + 1] |= cpu_to_le32(1);
1305 /* Refill */
1306 zoran_reap_stat_com(zr);
1307 zoran_feed_stat_com(zr);
1308 wake_up_interruptible(&zr->jpg_capq);
1309 /* Find an entry in stat_com again after refill */
1310 if (zr->jpg_settings.TmpDcm == 1)
1311 i = (zr->jpg_dma_tail -
1312 zr->jpg_err_shift) &
1313 BUZ_MASK_STAT_COM;
1314 else
1315 i = ((zr->jpg_dma_tail -
1316 zr->jpg_err_shift) & 1) * 2;
1317 }
1318 if (i) {
1319 /* Rotate stat_comm entries to make current entry first */
1320 int j;
1321 __le32 bus_addr[BUZ_NUM_STAT_COM];
1322
1323 /* Here we are copying the stat_com array, which
1324 * is already in little endian format, so
1325 * no endian conversions here
1326 */
1327 memcpy(bus_addr, zr->stat_com,
1328 sizeof(bus_addr));
1329 for (j = 0; j < BUZ_NUM_STAT_COM; j++) {
1330 zr->stat_com[j] =
1331 bus_addr[(i + j) &
1332 BUZ_MASK_STAT_COM];
1333 1258
1334 } 1259 /*
1335 zr->jpg_err_shift += i; 1260 * First entry: error just happened during normal operation
1336 zr->jpg_err_shift &= BUZ_MASK_STAT_COM; 1261 *
1262 * In BUZ_MODE_MOTION_COMPRESS:
1263 *
1264 * Possible glitch in TV signal. In this case we should
1265 * stop the codec and wait for good quality signal before
1266 * restarting it to avoid further problems
1267 *
1268 * In BUZ_MODE_MOTION_DECOMPRESS:
1269 *
1270 * Bad JPEG frame: we have to mark it as processed (codec crashed
1271 * and was not able to do it itself), and to remove it from queue.
1272 */
1273 btand(~ZR36057_JMC_Go_en, ZR36057_JMC);
1274 udelay(1);
1275 stat = stat | (post_office_read(zr, 7, 0) & 3) << 8;
1276 btwrite(0, ZR36057_JPC);
1277 btor(ZR36057_MCTCR_CFlush, ZR36057_MCTCR);
1278 jpeg_codec_reset(zr);
1279 jpeg_codec_sleep(zr, 1);
1280 zr->JPEG_error = 1;
1281 zr->num_errors++;
1282
1283 /* Report error */
1284 if (zr36067_debug > 1 && zr->num_errors <= 8) {
1285 long frame;
1286
1287 frame = zr->jpg_pend[zr->jpg_dma_tail & BUZ_MASK_FRAME];
1288 printk(KERN_ERR
1289 "%s: JPEG error stat=0x%08x(0x%08x) queue_state=%ld/%ld/%ld/%ld seq=%ld frame=%ld. Codec stopped. ",
1290 ZR_DEVNAME(zr), stat, zr->last_isr,
1291 zr->jpg_que_tail, zr->jpg_dma_tail,
1292 zr->jpg_dma_head, zr->jpg_que_head,
1293 zr->jpg_seq_num, frame);
1294 printk(KERN_INFO "stat_com frames:");
1295 for (j = 0; j < BUZ_NUM_STAT_COM; j++) {
1296 for (i = 0; i < zr->jpg_buffers.num_buffers; i++) {
1297 if (le32_to_cpu(zr->stat_com[j]) == zr->jpg_buffers.buffer[i].jpg.frag_tab_bus)
1298 printk(KERN_CONT "% d->%d", j, i);
1337 } 1299 }
1338 if (zr->codec_mode == BUZ_MODE_MOTION_COMPRESS)
1339 zr->jpg_err_seq = zr->jpg_seq_num; /* + 1; */
1340 } 1300 }
1301 printk(KERN_CONT "\n");
1341 } 1302 }
1303 /* Find an entry in stat_com and rotate contents */
1304 if (zr->jpg_settings.TmpDcm == 1)
1305 i = (zr->jpg_dma_tail - zr->jpg_err_shift) & BUZ_MASK_STAT_COM;
1306 else
1307 i = ((zr->jpg_dma_tail - zr->jpg_err_shift) & 1) * 2;
1308 if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS) {
1309 /* Mimic zr36067 operation */
1310 zr->stat_com[i] |= cpu_to_le32(1);
1311 if (zr->jpg_settings.TmpDcm != 1)
1312 zr->stat_com[i + 1] |= cpu_to_le32(1);
1313 /* Refill */
1314 zoran_reap_stat_com(zr);
1315 zoran_feed_stat_com(zr);
1316 wake_up_interruptible(&zr->jpg_capq);
1317 /* Find an entry in stat_com again after refill */
1318 if (zr->jpg_settings.TmpDcm == 1)
1319 i = (zr->jpg_dma_tail - zr->jpg_err_shift) & BUZ_MASK_STAT_COM;
1320 else
1321 i = ((zr->jpg_dma_tail - zr->jpg_err_shift) & 1) * 2;
1322 }
1323 if (i) {
1324 /* Rotate stat_comm entries to make current entry first */
1325 int j;
1326 __le32 bus_addr[BUZ_NUM_STAT_COM];
1327
1328 /* Here we are copying the stat_com array, which
1329 * is already in little endian format, so
1330 * no endian conversions here
1331 */
1332 memcpy(bus_addr, zr->stat_com, sizeof(bus_addr));
1342 1333
1343 /* Now the stat_comm buffer is ready for restart */ 1334 for (j = 0; j < BUZ_NUM_STAT_COM; j++)
1344 do { 1335 zr->stat_com[j] = bus_addr[(i + j) & BUZ_MASK_STAT_COM];
1345 int status, mode;
1346
1347 if (zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) {
1348 decoder_command(zr, DECODER_GET_STATUS, &status);
1349 mode = CODEC_DO_COMPRESSION;
1350 } else {
1351 status = 0;
1352 mode = CODEC_DO_EXPANSION;
1353 }
1354 if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS ||
1355 (status & DECODER_STATUS_GOOD)) {
1356 /********** RESTART code *************/
1357 jpeg_codec_reset(zr);
1358 zr->codec->set_mode(zr->codec, mode);
1359 zr36057_set_jpg(zr, zr->codec_mode);
1360 jpeg_start(zr);
1361
1362 if (zr->num_errors <= 8)
1363 dprintk(2, KERN_INFO "%s: Restart\n",
1364 ZR_DEVNAME(zr));
1365 1336
1366 zr->JPEG_missed = 0; 1337 zr->jpg_err_shift += i;
1367 zr->JPEG_error = 2; 1338 zr->jpg_err_shift &= BUZ_MASK_STAT_COM;
1368 /********** End RESTART code ***********/ 1339 }
1369 } 1340 if (zr->codec_mode == BUZ_MODE_MOTION_COMPRESS)
1370 } while (0); 1341 zr->jpg_err_seq = zr->jpg_seq_num; /* + 1; */
1342 zoran_restart(zr);
1371} 1343}
1372 1344
1373irqreturn_t 1345irqreturn_t
@@ -1425,10 +1397,8 @@ zoran_irq (int irq,
1425 * We simply ignore them */ 1397 * We simply ignore them */
1426 1398
1427 if (zr->v4l_memgrab_active) { 1399 if (zr->v4l_memgrab_active) {
1428
1429 /* A lot more checks should be here ... */ 1400 /* A lot more checks should be here ... */
1430 if ((btread(ZR36057_VSSFGR) & 1401 if ((btread(ZR36057_VSSFGR) & ZR36057_VSSFGR_SnapShot) == 0)
1431 ZR36057_VSSFGR_SnapShot) == 0)
1432 dprintk(1, 1402 dprintk(1,
1433 KERN_WARNING 1403 KERN_WARNING
1434 "%s: BuzIRQ with SnapShot off ???\n", 1404 "%s: BuzIRQ with SnapShot off ???\n",
@@ -1436,10 +1406,7 @@ zoran_irq (int irq,
1436 1406
1437 if (zr->v4l_grab_frame != NO_GRAB_ACTIVE) { 1407 if (zr->v4l_grab_frame != NO_GRAB_ACTIVE) {
1438 /* There is a grab on a frame going on, check if it has finished */ 1408 /* There is a grab on a frame going on, check if it has finished */
1439 1409 if ((btread(ZR36057_VSSFGR) & ZR36057_VSSFGR_FrameGrab) == 0) {
1440 if ((btread(ZR36057_VSSFGR) &
1441 ZR36057_VSSFGR_FrameGrab) ==
1442 0) {
1443 /* it is finished, notify the user */ 1410 /* it is finished, notify the user */
1444 1411
1445 zr->v4l_buffers.buffer[zr->v4l_grab_frame].state = BUZ_STATE_DONE; 1412 zr->v4l_buffers.buffer[zr->v4l_grab_frame].state = BUZ_STATE_DONE;
@@ -1457,9 +1424,7 @@ zoran_irq (int irq,
1457 1424
1458 if (zr->v4l_grab_frame == NO_GRAB_ACTIVE && 1425 if (zr->v4l_grab_frame == NO_GRAB_ACTIVE &&
1459 zr->v4l_pend_tail != zr->v4l_pend_head) { 1426 zr->v4l_pend_tail != zr->v4l_pend_head) {
1460 1427 int frame = zr->v4l_pend[zr->v4l_pend_tail & V4L_MASK_FRAME];
1461 int frame = zr->v4l_pend[zr->v4l_pend_tail &
1462 V4L_MASK_FRAME];
1463 u32 reg; 1428 u32 reg;
1464 1429
1465 zr->v4l_grab_frame = frame; 1430 zr->v4l_grab_frame = frame;
@@ -1468,27 +1433,17 @@ zoran_irq (int irq,
1468 1433
1469 /* Buffer address */ 1434 /* Buffer address */
1470 1435
1471 reg = 1436 reg = zr->v4l_buffers.buffer[frame].v4l.fbuffer_bus;
1472 zr->v4l_buffers.buffer[frame].
1473 fbuffer_bus;
1474 btwrite(reg, ZR36057_VDTR); 1437 btwrite(reg, ZR36057_VDTR);
1475 if (zr->v4l_settings.height > 1438 if (zr->v4l_settings.height > BUZ_MAX_HEIGHT / 2)
1476 BUZ_MAX_HEIGHT / 2) 1439 reg += zr->v4l_settings.bytesperline;
1477 reg +=
1478 zr->v4l_settings.
1479 bytesperline;
1480 btwrite(reg, ZR36057_VDBR); 1440 btwrite(reg, ZR36057_VDBR);
1481 1441
1482 /* video stride, status, and frame grab register */ 1442 /* video stride, status, and frame grab register */
1483 reg = 0; 1443 reg = 0;
1484 if (zr->v4l_settings.height > 1444 if (zr->v4l_settings.height > BUZ_MAX_HEIGHT / 2)
1485 BUZ_MAX_HEIGHT / 2) 1445 reg += zr->v4l_settings.bytesperline;
1486 reg += 1446 reg = (reg << ZR36057_VSSFGR_DispStride);
1487 zr->v4l_settings.
1488 bytesperline;
1489 reg =
1490 (reg <<
1491 ZR36057_VSSFGR_DispStride);
1492 reg |= ZR36057_VSSFGR_VidOvf; 1447 reg |= ZR36057_VSSFGR_VidOvf;
1493 reg |= ZR36057_VSSFGR_SnapShot; 1448 reg |= ZR36057_VSSFGR_SnapShot;
1494 reg |= ZR36057_VSSFGR_FrameGrab; 1449 reg |= ZR36057_VSSFGR_FrameGrab;
@@ -1506,77 +1461,66 @@ zoran_irq (int irq,
1506#if (IRQ_MASK & ZR36057_ISR_CodRepIRQ) 1461#if (IRQ_MASK & ZR36057_ISR_CodRepIRQ)
1507 if (astat & ZR36057_ISR_CodRepIRQ) { 1462 if (astat & ZR36057_ISR_CodRepIRQ) {
1508 zr->intr_counter_CodRepIRQ++; 1463 zr->intr_counter_CodRepIRQ++;
1509 IDEBUG(printk 1464 IDEBUG(printk(KERN_DEBUG "%s: ZR36057_ISR_CodRepIRQ\n",
1510 (KERN_DEBUG "%s: ZR36057_ISR_CodRepIRQ\n",
1511 ZR_DEVNAME(zr))); 1465 ZR_DEVNAME(zr)));
1512 btand(~ZR36057_ICR_CodRepIRQ, ZR36057_ICR); 1466 btand(~ZR36057_ICR_CodRepIRQ, ZR36057_ICR);
1513 } 1467 }
1514#endif /* (IRQ_MASK & ZR36057_ISR_CodRepIRQ) */ 1468#endif /* (IRQ_MASK & ZR36057_ISR_CodRepIRQ) */
1515 1469
1516#if (IRQ_MASK & ZR36057_ISR_JPEGRepIRQ) 1470#if (IRQ_MASK & ZR36057_ISR_JPEGRepIRQ)
1517 if (astat & ZR36057_ISR_JPEGRepIRQ) { 1471 if ((astat & ZR36057_ISR_JPEGRepIRQ) &&
1518 1472 (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS ||
1519 if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS || 1473 zr->codec_mode == BUZ_MODE_MOTION_COMPRESS)) {
1520 zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) { 1474 if (zr36067_debug > 1 && (!zr->frame_num || zr->JPEG_error)) {
1521 if (zr36067_debug > 1 && 1475 char sc[] = "0000";
1522 (!zr->frame_num || zr->JPEG_error)) { 1476 char sv[5];
1523 printk(KERN_INFO 1477 int i;
1524 "%s: first frame ready: state=0x%08x odd_even=%d field_per_buff=%d delay=%d\n", 1478
1525 ZR_DEVNAME(zr), stat, 1479 printk(KERN_INFO
1526 zr->jpg_settings.odd_even, 1480 "%s: first frame ready: state=0x%08x odd_even=%d field_per_buff=%d delay=%d\n",
1527 zr->jpg_settings. 1481 ZR_DEVNAME(zr), stat,
1528 field_per_buff, 1482 zr->jpg_settings.odd_even,
1529 zr->JPEG_missed); 1483 zr->jpg_settings.field_per_buff,
1530 { 1484 zr->JPEG_missed);
1531 char sc[] = "0000"; 1485
1532 char sv[5]; 1486 strcpy(sv, sc);
1533 int i; 1487 for (i = 0; i < 4; i++) {
1534 strcpy(sv, sc); 1488 if (le32_to_cpu(zr->stat_com[i]) & 1)
1535 for (i = 0; i < 4; i++) { 1489 sv[i] = '1';
1536 if (le32_to_cpu(zr->stat_com[i]) & 1)
1537 sv[i] = '1';
1538 }
1539 sv[4] = 0;
1540 printk(KERN_INFO
1541 "%s: stat_com=%s queue_state=%ld/%ld/%ld/%ld\n",
1542 ZR_DEVNAME(zr), sv,
1543 zr->jpg_que_tail,
1544 zr->jpg_dma_tail,
1545 zr->jpg_dma_head,
1546 zr->jpg_que_head);
1547 }
1548 } else {
1549 if (zr->JPEG_missed > zr->JPEG_max_missed) // Get statistics
1550 zr->JPEG_max_missed =
1551 zr->JPEG_missed;
1552 if (zr->JPEG_missed <
1553 zr->JPEG_min_missed)
1554 zr->JPEG_min_missed =
1555 zr->JPEG_missed;
1556 } 1490 }
1491 sv[4] = 0;
1492 printk(KERN_INFO
1493 "%s: stat_com=%s queue_state=%ld/%ld/%ld/%ld\n",
1494 ZR_DEVNAME(zr), sv,
1495 zr->jpg_que_tail,
1496 zr->jpg_dma_tail,
1497 zr->jpg_dma_head,
1498 zr->jpg_que_head);
1499 } else {
1500 /* Get statistics */
1501 if (zr->JPEG_missed > zr->JPEG_max_missed)
1502 zr->JPEG_max_missed = zr->JPEG_missed;
1503 if (zr->JPEG_missed < zr->JPEG_min_missed)
1504 zr->JPEG_min_missed = zr->JPEG_missed;
1505 }
1557 1506
1558 if (zr36067_debug > 2 && zr->frame_num < 6) { 1507 if (zr36067_debug > 2 && zr->frame_num < 6) {
1559 int i; 1508 int i;
1560 printk("%s: seq=%ld stat_com:", 1509
1561 ZR_DEVNAME(zr), zr->jpg_seq_num); 1510 printk(KERN_INFO "%s: seq=%ld stat_com:",
1562 for (i = 0; i < 4; i++) { 1511 ZR_DEVNAME(zr), zr->jpg_seq_num);
1563 printk(" %08x", 1512 for (i = 0; i < 4; i++) {
1564 le32_to_cpu(zr->stat_com[i])); 1513 printk(KERN_CONT " %08x",
1565 } 1514 le32_to_cpu(zr->stat_com[i]));
1566 printk("\n");
1567 } 1515 }
1568 zr->frame_num++; 1516 printk(KERN_CONT "\n");
1569 zr->JPEG_missed = 0; 1517 }
1570 zr->JPEG_error = 0; 1518 zr->frame_num++;
1571 zoran_reap_stat_com(zr); 1519 zr->JPEG_missed = 0;
1572 zoran_feed_stat_com(zr); 1520 zr->JPEG_error = 0;
1573 wake_up_interruptible(&zr->jpg_capq); 1521 zoran_reap_stat_com(zr);
1574 } /*else { 1522 zoran_feed_stat_com(zr);
1575 dprintk(1, 1523 wake_up_interruptible(&zr->jpg_capq);
1576 KERN_ERR
1577 "%s: JPEG interrupt while not in motion (de)compress mode!\n",
1578 ZR_DEVNAME(zr));
1579 }*/
1580 } 1524 }
1581#endif /* (IRQ_MASK & ZR36057_ISR_JPEGRepIRQ) */ 1525#endif /* (IRQ_MASK & ZR36057_ISR_JPEGRepIRQ) */
1582 1526
@@ -1585,8 +1529,7 @@ zoran_irq (int irq,
1585 zr->JPEG_missed > 25 || 1529 zr->JPEG_missed > 25 ||
1586 zr->JPEG_error == 1 || 1530 zr->JPEG_error == 1 ||
1587 ((zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS) && 1531 ((zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS) &&
1588 (zr->frame_num & (zr->JPEG_missed > 1532 (zr->frame_num & (zr->JPEG_missed > zr->jpg_settings.field_per_buff)))) {
1589 zr->jpg_settings.field_per_buff)))) {
1590 error_handler(zr, astat, stat); 1533 error_handler(zr, astat, stat);
1591 } 1534 }
1592 1535
@@ -1628,7 +1571,7 @@ zoran_set_pci_master (struct zoran *zr,
1628void 1571void
1629zoran_init_hardware (struct zoran *zr) 1572zoran_init_hardware (struct zoran *zr)
1630{ 1573{
1631 int j, zero = 0; 1574 struct v4l2_routing route = { 0, 0 };
1632 1575
1633 /* Enable bus-mastering */ 1576 /* Enable bus-mastering */
1634 zoran_set_pci_master(zr, 1); 1577 zoran_set_pci_master(zr, 1);
@@ -1638,15 +1581,16 @@ zoran_init_hardware (struct zoran *zr)
1638 zr->card.init(zr); 1581 zr->card.init(zr);
1639 } 1582 }
1640 1583
1641 j = zr->card.input[zr->input].muxsel; 1584 route.input = zr->card.input[zr->input].muxsel;
1642 1585
1643 decoder_command(zr, 0, NULL); 1586 decoder_call(zr, core, init, 0);
1644 decoder_command(zr, DECODER_SET_NORM, &zr->norm); 1587 decoder_call(zr, tuner, s_std, zr->norm);
1645 decoder_command(zr, DECODER_SET_INPUT, &j); 1588 decoder_call(zr, video, s_routing, &route);
1646 1589
1647 encoder_command(zr, 0, NULL); 1590 encoder_call(zr, core, init, 0);
1648 encoder_command(zr, ENCODER_SET_NORM, &zr->norm); 1591 encoder_call(zr, video, s_std_output, zr->norm);
1649 encoder_command(zr, ENCODER_SET_INPUT, &zero); 1592 route.input = 0;
1593 encoder_call(zr, video, s_routing, &route);
1650 1594
1651 /* toggle JPEG codec sleep to sync PLL */ 1595 /* toggle JPEG codec sleep to sync PLL */
1652 jpeg_codec_sleep(zr, 1); 1596 jpeg_codec_sleep(zr, 1);
@@ -1706,42 +1650,3 @@ zr36057_init_vfe (struct zoran *zr)
1706 reg |= ZR36057_VDCR_Triton; 1650 reg |= ZR36057_VDCR_Triton;
1707 btwrite(reg, ZR36057_VDCR); 1651 btwrite(reg, ZR36057_VDCR);
1708} 1652}
1709
1710/*
1711 * Interface to decoder and encoder chips using i2c bus
1712 */
1713
1714int
1715decoder_command (struct zoran *zr,
1716 int cmd,
1717 void *data)
1718{
1719 if (zr->decoder == NULL)
1720 return -EIO;
1721
1722 if (zr->card.type == LML33 &&
1723 (cmd == DECODER_SET_NORM || cmd == DECODER_SET_INPUT)) {
1724 int res;
1725
1726 // Bt819 needs to reset its FIFO buffer using #FRST pin and
1727 // LML33 card uses GPIO(7) for that.
1728 GPIO(zr, 7, 0);
1729 res = zr->decoder->driver->command(zr->decoder, cmd, data);
1730 // Pull #FRST high.
1731 GPIO(zr, 7, 1);
1732 return res;
1733 } else
1734 return zr->decoder->driver->command(zr->decoder, cmd,
1735 data);
1736}
1737
1738int
1739encoder_command (struct zoran *zr,
1740 int cmd,
1741 void *data)
1742{
1743 if (zr->encoder == NULL)
1744 return -1;
1745
1746 return zr->encoder->driver->command(zr->encoder, cmd, data);
1747}
diff --git a/drivers/media/video/zoran/zoran_device.h b/drivers/media/video/zoran/zoran_device.h
index 74c6c8edb7d0..07f2c23ff740 100644
--- a/drivers/media/video/zoran/zoran_device.h
+++ b/drivers/media/video/zoran/zoran_device.h
@@ -54,8 +54,8 @@ extern int jpeg_codec_reset(struct zoran *zr);
54/* zr360x7 access to raw capture */ 54/* zr360x7 access to raw capture */
55extern void zr36057_overlay(struct zoran *zr, 55extern void zr36057_overlay(struct zoran *zr,
56 int on); 56 int on);
57extern void write_overlay_mask(struct file *file, 57extern void write_overlay_mask(struct zoran_fh *fh,
58 struct video_clip *vp, 58 struct v4l2_clip *vp,
59 int count); 59 int count);
60extern void zr36057_set_memgrab(struct zoran *zr, 60extern void zr36057_set_memgrab(struct zoran *zr,
61 int mode); 61 int mode);
@@ -87,11 +87,9 @@ extern int jpg_bufsize;
87extern int pass_through; 87extern int pass_through;
88 88
89/* i2c */ 89/* i2c */
90extern int decoder_command(struct zoran *zr, 90#define decoder_call(zr, o, f, args...) \
91 int cmd, 91 v4l2_subdev_call(zr->decoder, o, f, ##args)
92 void *data); 92#define encoder_call(zr, o, f, args...) \
93extern int encoder_command(struct zoran *zr, 93 v4l2_subdev_call(zr->encoder, o, f, ##args)
94 int cmd,
95 void *data);
96 94
97#endif /* __ZORAN_DEVICE_H__ */ 95#endif /* __ZORAN_DEVICE_H__ */
diff --git a/drivers/media/video/zoran/zoran_driver.c b/drivers/media/video/zoran/zoran_driver.c
index 120ef235e63d..f16e57cf11e4 100644
--- a/drivers/media/video/zoran/zoran_driver.c
+++ b/drivers/media/video/zoran/zoran_driver.c
@@ -58,16 +58,6 @@
58#include <linux/i2c-algo-bit.h> 58#include <linux/i2c-algo-bit.h>
59 59
60#include <linux/spinlock.h> 60#include <linux/spinlock.h>
61#define MAP_NR(x) virt_to_page(x)
62#define ZORAN_VID_TYPE ( \
63 VID_TYPE_CAPTURE | \
64 VID_TYPE_OVERLAY | \
65 VID_TYPE_CLIPPING | \
66 VID_TYPE_FRAMERAM | \
67 VID_TYPE_SCALES | \
68 VID_TYPE_MJPEG_DECODER | \
69 VID_TYPE_MJPEG_ENCODER \
70 )
71 61
72#include <linux/videodev.h> 62#include <linux/videodev.h>
73#include <media/v4l2-common.h> 63#include <media/v4l2-common.h>
@@ -79,36 +69,17 @@
79#include <asm/uaccess.h> 69#include <asm/uaccess.h>
80#include <linux/proc_fs.h> 70#include <linux/proc_fs.h>
81 71
82#include <linux/video_decoder.h>
83#include <linux/video_encoder.h>
84#include <linux/mutex.h> 72#include <linux/mutex.h>
85#include "zoran.h" 73#include "zoran.h"
86#include "zoran_device.h" 74#include "zoran_device.h"
87#include "zoran_card.h" 75#include "zoran_card.h"
88 76
89 /* we declare some card type definitions here, they mean
90 * the same as the v4l1 ZORAN_VID_TYPE above, except it's v4l2 */
91#define ZORAN_V4L2_VID_FLAGS ( \
92 V4L2_CAP_STREAMING |\
93 V4L2_CAP_VIDEO_CAPTURE |\
94 V4L2_CAP_VIDEO_OUTPUT |\
95 V4L2_CAP_VIDEO_OVERLAY \
96 )
97
98
99#if defined(CONFIG_VIDEO_V4L1_COMPAT)
100#define ZFMT(pal, fcc, cs) \
101 .palette = (pal), .fourcc = (fcc), .colorspace = (cs)
102#else
103#define ZFMT(pal, fcc, cs) \
104 .fourcc = (fcc), .colorspace = (cs)
105#endif
106 77
107const struct zoran_format zoran_formats[] = { 78const struct zoran_format zoran_formats[] = {
108 { 79 {
109 .name = "15-bit RGB LE", 80 .name = "15-bit RGB LE",
110 ZFMT(VIDEO_PALETTE_RGB555, 81 .fourcc = V4L2_PIX_FMT_RGB555,
111 V4L2_PIX_FMT_RGB555, V4L2_COLORSPACE_SRGB), 82 .colorspace = V4L2_COLORSPACE_SRGB,
112 .depth = 15, 83 .depth = 15,
113 .flags = ZORAN_FORMAT_CAPTURE | 84 .flags = ZORAN_FORMAT_CAPTURE |
114 ZORAN_FORMAT_OVERLAY, 85 ZORAN_FORMAT_OVERLAY,
@@ -116,16 +87,16 @@ const struct zoran_format zoran_formats[] = {
116 ZR36057_VFESPFR_LittleEndian, 87 ZR36057_VFESPFR_LittleEndian,
117 }, { 88 }, {
118 .name = "15-bit RGB BE", 89 .name = "15-bit RGB BE",
119 ZFMT(-1, 90 .fourcc = V4L2_PIX_FMT_RGB555X,
120 V4L2_PIX_FMT_RGB555X, V4L2_COLORSPACE_SRGB), 91 .colorspace = V4L2_COLORSPACE_SRGB,
121 .depth = 15, 92 .depth = 15,
122 .flags = ZORAN_FORMAT_CAPTURE | 93 .flags = ZORAN_FORMAT_CAPTURE |
123 ZORAN_FORMAT_OVERLAY, 94 ZORAN_FORMAT_OVERLAY,
124 .vfespfr = ZR36057_VFESPFR_RGB555|ZR36057_VFESPFR_ErrDif, 95 .vfespfr = ZR36057_VFESPFR_RGB555|ZR36057_VFESPFR_ErrDif,
125 }, { 96 }, {
126 .name = "16-bit RGB LE", 97 .name = "16-bit RGB LE",
127 ZFMT(VIDEO_PALETTE_RGB565, 98 .fourcc = V4L2_PIX_FMT_RGB565,
128 V4L2_PIX_FMT_RGB565, V4L2_COLORSPACE_SRGB), 99 .colorspace = V4L2_COLORSPACE_SRGB,
129 .depth = 16, 100 .depth = 16,
130 .flags = ZORAN_FORMAT_CAPTURE | 101 .flags = ZORAN_FORMAT_CAPTURE |
131 ZORAN_FORMAT_OVERLAY, 102 ZORAN_FORMAT_OVERLAY,
@@ -133,56 +104,56 @@ const struct zoran_format zoran_formats[] = {
133 ZR36057_VFESPFR_LittleEndian, 104 ZR36057_VFESPFR_LittleEndian,
134 }, { 105 }, {
135 .name = "16-bit RGB BE", 106 .name = "16-bit RGB BE",
136 ZFMT(-1, 107 .fourcc = V4L2_PIX_FMT_RGB565X,
137 V4L2_PIX_FMT_RGB565X, V4L2_COLORSPACE_SRGB), 108 .colorspace = V4L2_COLORSPACE_SRGB,
138 .depth = 16, 109 .depth = 16,
139 .flags = ZORAN_FORMAT_CAPTURE | 110 .flags = ZORAN_FORMAT_CAPTURE |
140 ZORAN_FORMAT_OVERLAY, 111 ZORAN_FORMAT_OVERLAY,
141 .vfespfr = ZR36057_VFESPFR_RGB565|ZR36057_VFESPFR_ErrDif, 112 .vfespfr = ZR36057_VFESPFR_RGB565|ZR36057_VFESPFR_ErrDif,
142 }, { 113 }, {
143 .name = "24-bit RGB", 114 .name = "24-bit RGB",
144 ZFMT(VIDEO_PALETTE_RGB24, 115 .fourcc = V4L2_PIX_FMT_BGR24,
145 V4L2_PIX_FMT_BGR24, V4L2_COLORSPACE_SRGB), 116 .colorspace = V4L2_COLORSPACE_SRGB,
146 .depth = 24, 117 .depth = 24,
147 .flags = ZORAN_FORMAT_CAPTURE | 118 .flags = ZORAN_FORMAT_CAPTURE |
148 ZORAN_FORMAT_OVERLAY, 119 ZORAN_FORMAT_OVERLAY,
149 .vfespfr = ZR36057_VFESPFR_RGB888|ZR36057_VFESPFR_Pack24, 120 .vfespfr = ZR36057_VFESPFR_RGB888|ZR36057_VFESPFR_Pack24,
150 }, { 121 }, {
151 .name = "32-bit RGB LE", 122 .name = "32-bit RGB LE",
152 ZFMT(VIDEO_PALETTE_RGB32, 123 .fourcc = V4L2_PIX_FMT_BGR32,
153 V4L2_PIX_FMT_BGR32, V4L2_COLORSPACE_SRGB), 124 .colorspace = V4L2_COLORSPACE_SRGB,
154 .depth = 32, 125 .depth = 32,
155 .flags = ZORAN_FORMAT_CAPTURE | 126 .flags = ZORAN_FORMAT_CAPTURE |
156 ZORAN_FORMAT_OVERLAY, 127 ZORAN_FORMAT_OVERLAY,
157 .vfespfr = ZR36057_VFESPFR_RGB888|ZR36057_VFESPFR_LittleEndian, 128 .vfespfr = ZR36057_VFESPFR_RGB888|ZR36057_VFESPFR_LittleEndian,
158 }, { 129 }, {
159 .name = "32-bit RGB BE", 130 .name = "32-bit RGB BE",
160 ZFMT(-1, 131 .fourcc = V4L2_PIX_FMT_RGB32,
161 V4L2_PIX_FMT_RGB32, V4L2_COLORSPACE_SRGB), 132 .colorspace = V4L2_COLORSPACE_SRGB,
162 .depth = 32, 133 .depth = 32,
163 .flags = ZORAN_FORMAT_CAPTURE | 134 .flags = ZORAN_FORMAT_CAPTURE |
164 ZORAN_FORMAT_OVERLAY, 135 ZORAN_FORMAT_OVERLAY,
165 .vfespfr = ZR36057_VFESPFR_RGB888, 136 .vfespfr = ZR36057_VFESPFR_RGB888,
166 }, { 137 }, {
167 .name = "4:2:2, packed, YUYV", 138 .name = "4:2:2, packed, YUYV",
168 ZFMT(VIDEO_PALETTE_YUV422, 139 .fourcc = V4L2_PIX_FMT_YUYV,
169 V4L2_PIX_FMT_YUYV, V4L2_COLORSPACE_SMPTE170M), 140 .colorspace = V4L2_COLORSPACE_SMPTE170M,
170 .depth = 16, 141 .depth = 16,
171 .flags = ZORAN_FORMAT_CAPTURE | 142 .flags = ZORAN_FORMAT_CAPTURE |
172 ZORAN_FORMAT_OVERLAY, 143 ZORAN_FORMAT_OVERLAY,
173 .vfespfr = ZR36057_VFESPFR_YUV422, 144 .vfespfr = ZR36057_VFESPFR_YUV422,
174 }, { 145 }, {
175 .name = "4:2:2, packed, UYVY", 146 .name = "4:2:2, packed, UYVY",
176 ZFMT(VIDEO_PALETTE_UYVY, 147 .fourcc = V4L2_PIX_FMT_UYVY,
177 V4L2_PIX_FMT_UYVY, V4L2_COLORSPACE_SMPTE170M), 148 .colorspace = V4L2_COLORSPACE_SMPTE170M,
178 .depth = 16, 149 .depth = 16,
179 .flags = ZORAN_FORMAT_CAPTURE | 150 .flags = ZORAN_FORMAT_CAPTURE |
180 ZORAN_FORMAT_OVERLAY, 151 ZORAN_FORMAT_OVERLAY,
181 .vfespfr = ZR36057_VFESPFR_YUV422|ZR36057_VFESPFR_LittleEndian, 152 .vfespfr = ZR36057_VFESPFR_YUV422|ZR36057_VFESPFR_LittleEndian,
182 }, { 153 }, {
183 .name = "Hardware-encoded Motion-JPEG", 154 .name = "Hardware-encoded Motion-JPEG",
184 ZFMT(-1, 155 .fourcc = V4L2_PIX_FMT_MJPEG,
185 V4L2_PIX_FMT_MJPEG, V4L2_COLORSPACE_SMPTE170M), 156 .colorspace = V4L2_COLORSPACE_SMPTE170M,
186 .depth = 0, 157 .depth = 0,
187 .flags = ZORAN_FORMAT_CAPTURE | 158 .flags = ZORAN_FORMAT_CAPTURE |
188 ZORAN_FORMAT_PLAYBACK | 159 ZORAN_FORMAT_PLAYBACK |
@@ -191,13 +162,6 @@ const struct zoran_format zoran_formats[] = {
191}; 162};
192#define NUM_FORMATS ARRAY_SIZE(zoran_formats) 163#define NUM_FORMATS ARRAY_SIZE(zoran_formats)
193 164
194// RJ: Test only - want to test BUZ_USE_HIMEM even when CONFIG_BIGPHYS_AREA is defined
195
196
197static int lock_norm; /* 0 = default 1 = Don't change TV standard (norm) */
198module_param(lock_norm, int, 0644);
199MODULE_PARM_DESC(lock_norm, "Prevent norm changes (1 = ignore, >1 = fail)");
200
201 /* small helper function for calculating buffersizes for v4l2 165 /* small helper function for calculating buffersizes for v4l2
202 * we calculate the nearest higher power-of-two, which 166 * we calculate the nearest higher power-of-two, which
203 * will be the recommended buffersize */ 167 * will be the recommended buffersize */
@@ -222,221 +186,106 @@ zoran_v4l2_calc_bufsize (struct zoran_jpg_settings *settings)
222} 186}
223 187
224/* forward references */ 188/* forward references */
225static void v4l_fbuffer_free(struct file *file); 189static void v4l_fbuffer_free(struct zoran_fh *fh);
226static void jpg_fbuffer_free(struct file *file); 190static void jpg_fbuffer_free(struct zoran_fh *fh);
191
192/* Set mapping mode */
193static void map_mode_raw(struct zoran_fh *fh)
194{
195 fh->map_mode = ZORAN_MAP_MODE_RAW;
196 fh->buffers.buffer_size = v4l_bufsize;
197 fh->buffers.num_buffers = v4l_nbufs;
198}
199static void map_mode_jpg(struct zoran_fh *fh, int play)
200{
201 fh->map_mode = play ? ZORAN_MAP_MODE_JPG_PLAY : ZORAN_MAP_MODE_JPG_REC;
202 fh->buffers.buffer_size = jpg_bufsize;
203 fh->buffers.num_buffers = jpg_nbufs;
204}
205static inline const char *mode_name(enum zoran_map_mode mode)
206{
207 return mode == ZORAN_MAP_MODE_RAW ? "V4L" : "JPG";
208}
227 209
228/* 210/*
229 * Allocate the V4L grab buffers 211 * Allocate the V4L grab buffers
230 * 212 *
231 * These have to be pysically contiguous. 213 * These have to be pysically contiguous.
232 * If v4l_bufsize <= MAX_KMALLOC_MEM we use kmalloc
233 * else we try to allocate them with bigphysarea_alloc_pages
234 * if the bigphysarea patch is present in the kernel,
235 * else we try to use high memory (if the user has bootet
236 * Linux with the necessary memory left over).
237 */ 214 */
238 215
239static unsigned long 216static int v4l_fbuffer_alloc(struct zoran_fh *fh)
240get_high_mem (unsigned long size)
241{ 217{
242/*
243 * Check if there is usable memory at the end of Linux memory
244 * of at least size. Return the physical address of this memory,
245 * return 0 on failure.
246 *
247 * The idea is from Alexandro Rubini's book "Linux device drivers".
248 * The driver from him which is downloadable from O'Reilly's
249 * web site misses the "virt_to_phys(high_memory)" part
250 * (and therefore doesn't work at all - at least with 2.2.x kernels).
251 *
252 * It should be unnecessary to mention that THIS IS DANGEROUS,
253 * if more than one driver at a time has the idea to use this memory!!!!
254 */
255
256 volatile unsigned char __iomem *mem;
257 unsigned char c;
258 unsigned long hi_mem_ph;
259 unsigned long i;
260
261 /* Map the high memory to user space */
262
263 hi_mem_ph = virt_to_phys(high_memory);
264
265 mem = ioremap(hi_mem_ph, size);
266 if (!mem) {
267 dprintk(1,
268 KERN_ERR "%s: get_high_mem() - ioremap failed\n",
269 ZORAN_NAME);
270 return 0;
271 }
272
273 for (i = 0; i < size; i++) {
274 /* Check if it is memory */
275 c = i & 0xff;
276 writeb(c, mem + i);
277 if (readb(mem + i) != c)
278 break;
279 c = 255 - c;
280 writeb(c, mem + i);
281 if (readb(mem + i) != c)
282 break;
283 writeb(0, mem + i); /* zero out memory */
284
285 /* give the kernel air to breath */
286 if ((i & 0x3ffff) == 0x3ffff)
287 schedule();
288 }
289
290 iounmap(mem);
291
292 if (i != size) {
293 dprintk(1,
294 KERN_ERR
295 "%s: get_high_mem() - requested %lu, avail %lu\n",
296 ZORAN_NAME, size, i);
297 return 0;
298 }
299
300 return hi_mem_ph;
301}
302
303static int
304v4l_fbuffer_alloc (struct file *file)
305{
306 struct zoran_fh *fh = file->private_data;
307 struct zoran *zr = fh->zr; 218 struct zoran *zr = fh->zr;
308 int i, off; 219 int i, off;
309 unsigned char *mem; 220 unsigned char *mem;
310 unsigned long pmem = 0;
311 221
312 /* we might have old buffers lying around... */ 222 for (i = 0; i < fh->buffers.num_buffers; i++) {
313 if (fh->v4l_buffers.ready_to_be_freed) { 223 if (fh->buffers.buffer[i].v4l.fbuffer)
314 v4l_fbuffer_free(file);
315 }
316
317 for (i = 0; i < fh->v4l_buffers.num_buffers; i++) {
318 if (fh->v4l_buffers.buffer[i].fbuffer)
319 dprintk(2, 224 dprintk(2,
320 KERN_WARNING 225 KERN_WARNING
321 "%s: v4l_fbuffer_alloc() - buffer %d allready allocated!?\n", 226 "%s: %s - buffer %d already allocated!?\n",
322 ZR_DEVNAME(zr), i); 227 ZR_DEVNAME(zr), __func__, i);
323 228
324 //udelay(20); 229 //udelay(20);
325 if (fh->v4l_buffers.buffer_size <= MAX_KMALLOC_MEM) { 230 mem = kmalloc(fh->buffers.buffer_size,
326 /* Use kmalloc */ 231 GFP_KERNEL | __GFP_NOWARN);
327 232 if (!mem) {
328 mem = kmalloc(fh->v4l_buffers.buffer_size, GFP_KERNEL); 233 dprintk(1,
329 if (!mem) { 234 KERN_ERR
330 dprintk(1, 235 "%s: %s - kmalloc for V4L buf %d failed\n",
331 KERN_ERR 236 ZR_DEVNAME(zr), __func__, i);
332 "%s: v4l_fbuffer_alloc() - kmalloc for V4L buf %d failed\n", 237 v4l_fbuffer_free(fh);
333 ZR_DEVNAME(zr), i); 238 return -ENOBUFS;
334 v4l_fbuffer_free(file);
335 return -ENOBUFS;
336 }
337 fh->v4l_buffers.buffer[i].fbuffer = mem;
338 fh->v4l_buffers.buffer[i].fbuffer_phys =
339 virt_to_phys(mem);
340 fh->v4l_buffers.buffer[i].fbuffer_bus =
341 virt_to_bus(mem);
342 for (off = 0; off < fh->v4l_buffers.buffer_size;
343 off += PAGE_SIZE)
344 SetPageReserved(MAP_NR(mem + off));
345 dprintk(4,
346 KERN_INFO
347 "%s: v4l_fbuffer_alloc() - V4L frame %d mem 0x%lx (bus: 0x%lx)\n",
348 ZR_DEVNAME(zr), i, (unsigned long) mem,
349 virt_to_bus(mem));
350 } else {
351
352 /* Use high memory which has been left at boot time */
353
354 /* Ok., Ok. this is an evil hack - we make
355 * the assumption that physical addresses are
356 * the same as bus addresses (true at least
357 * for Intel processors). The whole method of
358 * obtaining and using this memory is not very
359 * nice - but I hope it saves some poor users
360 * from kernel hacking, which might have even
361 * more evil results */
362
363 if (i == 0) {
364 int size =
365 fh->v4l_buffers.num_buffers *
366 fh->v4l_buffers.buffer_size;
367
368 pmem = get_high_mem(size);
369 if (pmem == 0) {
370 dprintk(1,
371 KERN_ERR
372 "%s: v4l_fbuffer_alloc() - get_high_mem (size = %d KB) for V4L bufs failed\n",
373 ZR_DEVNAME(zr), size >> 10);
374 return -ENOBUFS;
375 }
376 fh->v4l_buffers.buffer[0].fbuffer = NULL;
377 fh->v4l_buffers.buffer[0].fbuffer_phys = pmem;
378 fh->v4l_buffers.buffer[0].fbuffer_bus = pmem;
379 dprintk(4,
380 KERN_INFO
381 "%s: v4l_fbuffer_alloc() - using %d KB high memory\n",
382 ZR_DEVNAME(zr), size >> 10);
383 } else {
384 fh->v4l_buffers.buffer[i].fbuffer = NULL;
385 fh->v4l_buffers.buffer[i].fbuffer_phys =
386 pmem + i * fh->v4l_buffers.buffer_size;
387 fh->v4l_buffers.buffer[i].fbuffer_bus =
388 pmem + i * fh->v4l_buffers.buffer_size;
389 }
390 } 239 }
240 fh->buffers.buffer[i].v4l.fbuffer = mem;
241 fh->buffers.buffer[i].v4l.fbuffer_phys = virt_to_phys(mem);
242 fh->buffers.buffer[i].v4l.fbuffer_bus = virt_to_bus(mem);
243 for (off = 0; off < fh->buffers.buffer_size;
244 off += PAGE_SIZE)
245 SetPageReserved(virt_to_page(mem + off));
246 dprintk(4,
247 KERN_INFO
248 "%s: %s - V4L frame %d mem 0x%lx (bus: 0x%llx)\n",
249 ZR_DEVNAME(zr), __func__, i, (unsigned long) mem,
250 (unsigned long long)virt_to_bus(mem));
391 } 251 }
392 252
393 fh->v4l_buffers.allocated = 1; 253 fh->buffers.allocated = 1;
394 254
395 return 0; 255 return 0;
396} 256}
397 257
398/* free the V4L grab buffers */ 258/* free the V4L grab buffers */
399static void 259static void v4l_fbuffer_free(struct zoran_fh *fh)
400v4l_fbuffer_free (struct file *file)
401{ 260{
402 struct zoran_fh *fh = file->private_data;
403 struct zoran *zr = fh->zr; 261 struct zoran *zr = fh->zr;
404 int i, off; 262 int i, off;
405 unsigned char *mem; 263 unsigned char *mem;
406 264
407 dprintk(4, KERN_INFO "%s: v4l_fbuffer_free()\n", ZR_DEVNAME(zr)); 265 dprintk(4, KERN_INFO "%s: %s\n", ZR_DEVNAME(zr), __func__);
408 266
409 for (i = 0; i < fh->v4l_buffers.num_buffers; i++) { 267 for (i = 0; i < fh->buffers.num_buffers; i++) {
410 if (!fh->v4l_buffers.buffer[i].fbuffer) 268 if (!fh->buffers.buffer[i].v4l.fbuffer)
411 continue; 269 continue;
412 270
413 if (fh->v4l_buffers.buffer_size <= MAX_KMALLOC_MEM) { 271 mem = fh->buffers.buffer[i].v4l.fbuffer;
414 mem = fh->v4l_buffers.buffer[i].fbuffer; 272 for (off = 0; off < fh->buffers.buffer_size;
415 for (off = 0; off < fh->v4l_buffers.buffer_size; 273 off += PAGE_SIZE)
416 off += PAGE_SIZE) 274 ClearPageReserved(virt_to_page(mem + off));
417 ClearPageReserved(MAP_NR(mem + off)); 275 kfree(fh->buffers.buffer[i].v4l.fbuffer);
418 kfree((void *) fh->v4l_buffers.buffer[i].fbuffer); 276 fh->buffers.buffer[i].v4l.fbuffer = NULL;
419 }
420 fh->v4l_buffers.buffer[i].fbuffer = NULL;
421 } 277 }
422 278
423 fh->v4l_buffers.allocated = 0; 279 fh->buffers.allocated = 0;
424 fh->v4l_buffers.ready_to_be_freed = 0;
425} 280}
426 281
427/* 282/*
428 * Allocate the MJPEG grab buffers. 283 * Allocate the MJPEG grab buffers.
429 * 284 *
430 * If the requested buffer size is smaller than MAX_KMALLOC_MEM,
431 * kmalloc is used to request a physically contiguous area,
432 * else we allocate the memory in framgents with get_zeroed_page.
433 *
434 * If a Natoma chipset is present and this is a revision 1 zr36057, 285 * If a Natoma chipset is present and this is a revision 1 zr36057,
435 * each MJPEG buffer needs to be physically contiguous. 286 * each MJPEG buffer needs to be physically contiguous.
436 * (RJ: This statement is from Dave Perks' original driver, 287 * (RJ: This statement is from Dave Perks' original driver,
437 * I could never check it because I have a zr36067) 288 * I could never check it because I have a zr36067)
438 * The driver cares about this because it reduces the buffer
439 * size to MAX_KMALLOC_MEM in that case (which forces contiguous allocation).
440 * 289 *
441 * RJ: The contents grab buffers needs never be accessed in the driver. 290 * RJ: The contents grab buffers needs never be accessed in the driver.
442 * Therefore there is no need to allocate them with vmalloc in order 291 * Therefore there is no need to allocate them with vmalloc in order
@@ -458,162 +307,128 @@ v4l_fbuffer_free (struct file *file)
458 * and fragment buffers are not little-endian. 307 * and fragment buffers are not little-endian.
459 */ 308 */
460 309
461static int 310static int jpg_fbuffer_alloc(struct zoran_fh *fh)
462jpg_fbuffer_alloc (struct file *file)
463{ 311{
464 struct zoran_fh *fh = file->private_data;
465 struct zoran *zr = fh->zr; 312 struct zoran *zr = fh->zr;
466 int i, j, off; 313 int i, j, off;
467 unsigned long mem; 314 u8 *mem;
468
469 /* we might have old buffers lying around */
470 if (fh->jpg_buffers.ready_to_be_freed) {
471 jpg_fbuffer_free(file);
472 }
473 315
474 for (i = 0; i < fh->jpg_buffers.num_buffers; i++) { 316 for (i = 0; i < fh->buffers.num_buffers; i++) {
475 if (fh->jpg_buffers.buffer[i].frag_tab) 317 if (fh->buffers.buffer[i].jpg.frag_tab)
476 dprintk(2, 318 dprintk(2,
477 KERN_WARNING 319 KERN_WARNING
478 "%s: jpg_fbuffer_alloc() - buffer %d allready allocated!?\n", 320 "%s: %s - buffer %d already allocated!?\n",
479 ZR_DEVNAME(zr), i); 321 ZR_DEVNAME(zr), __func__, i);
480 322
481 /* Allocate fragment table for this buffer */ 323 /* Allocate fragment table for this buffer */
482 324
483 mem = get_zeroed_page(GFP_KERNEL); 325 mem = (void *)get_zeroed_page(GFP_KERNEL);
484 if (mem == 0) { 326 if (mem == 0) {
485 dprintk(1, 327 dprintk(1,
486 KERN_ERR 328 KERN_ERR
487 "%s: jpg_fbuffer_alloc() - get_zeroed_page (frag_tab) failed for buffer %d\n", 329 "%s: %s - get_zeroed_page (frag_tab) failed for buffer %d\n",
488 ZR_DEVNAME(zr), i); 330 ZR_DEVNAME(zr), __func__, i);
489 jpg_fbuffer_free(file); 331 jpg_fbuffer_free(fh);
490 return -ENOBUFS; 332 return -ENOBUFS;
491 } 333 }
492 fh->jpg_buffers.buffer[i].frag_tab = (__le32 *) mem; 334 fh->buffers.buffer[i].jpg.frag_tab = (__le32 *)mem;
493 fh->jpg_buffers.buffer[i].frag_tab_bus = 335 fh->buffers.buffer[i].jpg.frag_tab_bus = virt_to_bus(mem);
494 virt_to_bus((void *) mem); 336
495 337 if (fh->buffers.need_contiguous) {
496 //if (alloc_contig) { 338 mem = kmalloc(fh->buffers.buffer_size, GFP_KERNEL);
497 if (fh->jpg_buffers.need_contiguous) { 339 if (mem == NULL) {
498 mem =
499 (unsigned long) kmalloc(fh->jpg_buffers.
500 buffer_size,
501 GFP_KERNEL);
502 if (mem == 0) {
503 dprintk(1, 340 dprintk(1,
504 KERN_ERR 341 KERN_ERR
505 "%s: jpg_fbuffer_alloc() - kmalloc failed for buffer %d\n", 342 "%s: %s - kmalloc failed for buffer %d\n",
506 ZR_DEVNAME(zr), i); 343 ZR_DEVNAME(zr), __func__, i);
507 jpg_fbuffer_free(file); 344 jpg_fbuffer_free(fh);
508 return -ENOBUFS; 345 return -ENOBUFS;
509 } 346 }
510 fh->jpg_buffers.buffer[i].frag_tab[0] = 347 fh->buffers.buffer[i].jpg.frag_tab[0] =
511 cpu_to_le32(virt_to_bus((void *) mem)); 348 cpu_to_le32(virt_to_bus(mem));
512 fh->jpg_buffers.buffer[i].frag_tab[1] = 349 fh->buffers.buffer[i].jpg.frag_tab[1] =
513 cpu_to_le32(((fh->jpg_buffers.buffer_size / 4) << 1) | 1); 350 cpu_to_le32((fh->buffers.buffer_size >> 1) | 1);
514 for (off = 0; off < fh->jpg_buffers.buffer_size; 351 for (off = 0; off < fh->buffers.buffer_size; off += PAGE_SIZE)
515 off += PAGE_SIZE) 352 SetPageReserved(virt_to_page(mem + off));
516 SetPageReserved(MAP_NR(mem + off));
517 } else { 353 } else {
518 /* jpg_bufsize is allreay page aligned */ 354 /* jpg_bufsize is already page aligned */
519 for (j = 0; 355 for (j = 0; j < fh->buffers.buffer_size / PAGE_SIZE; j++) {
520 j < fh->jpg_buffers.buffer_size / PAGE_SIZE; 356 mem = (void *)get_zeroed_page(GFP_KERNEL);
521 j++) { 357 if (mem == NULL) {
522 mem = get_zeroed_page(GFP_KERNEL);
523 if (mem == 0) {
524 dprintk(1, 358 dprintk(1,
525 KERN_ERR 359 KERN_ERR
526 "%s: jpg_fbuffer_alloc() - get_zeroed_page failed for buffer %d\n", 360 "%s: %s - get_zeroed_page failed for buffer %d\n",
527 ZR_DEVNAME(zr), i); 361 ZR_DEVNAME(zr), __func__, i);
528 jpg_fbuffer_free(file); 362 jpg_fbuffer_free(fh);
529 return -ENOBUFS; 363 return -ENOBUFS;
530 } 364 }
531 365
532 fh->jpg_buffers.buffer[i].frag_tab[2 * j] = 366 fh->buffers.buffer[i].jpg.frag_tab[2 * j] =
533 cpu_to_le32(virt_to_bus((void *) mem)); 367 cpu_to_le32(virt_to_bus(mem));
534 fh->jpg_buffers.buffer[i].frag_tab[2 * j + 368 fh->buffers.buffer[i].jpg.frag_tab[2 * j + 1] =
535 1] = 369 cpu_to_le32((PAGE_SIZE >> 2) << 1);
536 cpu_to_le32((PAGE_SIZE / 4) << 1); 370 SetPageReserved(virt_to_page(mem));
537 SetPageReserved(MAP_NR(mem));
538 } 371 }
539 372
540 fh->jpg_buffers.buffer[i].frag_tab[2 * j - 1] |= cpu_to_le32(1); 373 fh->buffers.buffer[i].jpg.frag_tab[2 * j - 1] |= cpu_to_le32(1);
541 } 374 }
542 } 375 }
543 376
544 dprintk(4, 377 dprintk(4,
545 KERN_DEBUG "%s: jpg_fbuffer_alloc() - %d KB allocated\n", 378 KERN_DEBUG "%s: %s - %d KB allocated\n",
546 ZR_DEVNAME(zr), 379 ZR_DEVNAME(zr), __func__,
547 (fh->jpg_buffers.num_buffers * 380 (fh->buffers.num_buffers * fh->buffers.buffer_size) >> 10);
548 fh->jpg_buffers.buffer_size) >> 10);
549 381
550 fh->jpg_buffers.allocated = 1; 382 fh->buffers.allocated = 1;
551 383
552 return 0; 384 return 0;
553} 385}
554 386
555/* free the MJPEG grab buffers */ 387/* free the MJPEG grab buffers */
556static void 388static void jpg_fbuffer_free(struct zoran_fh *fh)
557jpg_fbuffer_free (struct file *file)
558{ 389{
559 struct zoran_fh *fh = file->private_data;
560 struct zoran *zr = fh->zr; 390 struct zoran *zr = fh->zr;
561 int i, j, off; 391 int i, j, off;
562 unsigned char *mem; 392 unsigned char *mem;
393 __le32 frag_tab;
394 struct zoran_buffer *buffer;
563 395
564 dprintk(4, KERN_DEBUG "%s: jpg_fbuffer_free()\n", ZR_DEVNAME(zr)); 396 dprintk(4, KERN_DEBUG "%s: %s\n", ZR_DEVNAME(zr), __func__);
565 397
566 for (i = 0; i < fh->jpg_buffers.num_buffers; i++) { 398 for (i = 0, buffer = &fh->buffers.buffer[0];
567 if (!fh->jpg_buffers.buffer[i].frag_tab) 399 i < fh->buffers.num_buffers; i++, buffer++) {
400 if (!buffer->jpg.frag_tab)
568 continue; 401 continue;
569 402
570 //if (alloc_contig) { 403 if (fh->buffers.need_contiguous) {
571 if (fh->jpg_buffers.need_contiguous) { 404 frag_tab = buffer->jpg.frag_tab[0];
572 if (fh->jpg_buffers.buffer[i].frag_tab[0]) { 405
573 mem = (unsigned char *) bus_to_virt(le32_to_cpu( 406 if (frag_tab) {
574 fh->jpg_buffers.buffer[i].frag_tab[0])); 407 mem = bus_to_virt(le32_to_cpu(frag_tab));
575 for (off = 0; 408 for (off = 0; off < fh->buffers.buffer_size; off += PAGE_SIZE)
576 off < fh->jpg_buffers.buffer_size; 409 ClearPageReserved(virt_to_page(mem + off));
577 off += PAGE_SIZE)
578 ClearPageReserved(MAP_NR
579 (mem + off));
580 kfree(mem); 410 kfree(mem);
581 fh->jpg_buffers.buffer[i].frag_tab[0] = 0; 411 buffer->jpg.frag_tab[0] = 0;
582 fh->jpg_buffers.buffer[i].frag_tab[1] = 0; 412 buffer->jpg.frag_tab[1] = 0;
583 } 413 }
584 } else { 414 } else {
585 for (j = 0; 415 for (j = 0; j < fh->buffers.buffer_size / PAGE_SIZE; j++) {
586 j < fh->jpg_buffers.buffer_size / PAGE_SIZE; 416 frag_tab = buffer->jpg.frag_tab[2 * j];
587 j++) { 417
588 if (!fh->jpg_buffers.buffer[i]. 418 if (!frag_tab)
589 frag_tab[2 * j])
590 break; 419 break;
591 ClearPageReserved(MAP_NR 420 ClearPageReserved(virt_to_page(bus_to_virt(le32_to_cpu(frag_tab))));
592 (bus_to_virt 421 free_page((unsigned long)bus_to_virt(le32_to_cpu(frag_tab)));
593 (le32_to_cpu 422 buffer->jpg.frag_tab[2 * j] = 0;
594 (fh->jpg_buffers. 423 buffer->jpg.frag_tab[2 * j + 1] = 0;
595 buffer[i].frag_tab[2 *
596 j]))));
597 free_page((unsigned long)
598 bus_to_virt
599 (le32_to_cpu
600 (fh->jpg_buffers.
601 buffer[i].
602 frag_tab[2 * j])));
603 fh->jpg_buffers.buffer[i].frag_tab[2 * j] =
604 0;
605 fh->jpg_buffers.buffer[i].frag_tab[2 * j +
606 1] = 0;
607 } 424 }
608 } 425 }
609 426
610 free_page((unsigned long) fh->jpg_buffers.buffer[i]. 427 free_page((unsigned long)buffer->jpg.frag_tab);
611 frag_tab); 428 buffer->jpg.frag_tab = NULL;
612 fh->jpg_buffers.buffer[i].frag_tab = NULL;
613 } 429 }
614 430
615 fh->jpg_buffers.allocated = 0; 431 fh->buffers.allocated = 0;
616 fh->jpg_buffers.ready_to_be_freed = 0;
617} 432}
618 433
619/* 434/*
@@ -621,12 +436,11 @@ jpg_fbuffer_free (struct file *file)
621 */ 436 */
622 437
623static int 438static int
624zoran_v4l_set_format (struct file *file, 439zoran_v4l_set_format (struct zoran_fh *fh,
625 int width, 440 int width,
626 int height, 441 int height,
627 const struct zoran_format *format) 442 const struct zoran_format *format)
628{ 443{
629 struct zoran_fh *fh = file->private_data;
630 struct zoran *zr = fh->zr; 444 struct zoran *zr = fh->zr;
631 int bpp; 445 int bpp;
632 446
@@ -636,19 +450,19 @@ zoran_v4l_set_format (struct file *file,
636 height > BUZ_MAX_HEIGHT || width > BUZ_MAX_WIDTH) { 450 height > BUZ_MAX_HEIGHT || width > BUZ_MAX_WIDTH) {
637 dprintk(1, 451 dprintk(1,
638 KERN_ERR 452 KERN_ERR
639 "%s: v4l_set_format() - wrong frame size (%dx%d)\n", 453 "%s: %s - wrong frame size (%dx%d)\n",
640 ZR_DEVNAME(zr), width, height); 454 ZR_DEVNAME(zr), __func__, width, height);
641 return -EINVAL; 455 return -EINVAL;
642 } 456 }
643 457
644 bpp = (format->depth + 7) / 8; 458 bpp = (format->depth + 7) / 8;
645 459
646 /* Check against available buffer size */ 460 /* Check against available buffer size */
647 if (height * width * bpp > fh->v4l_buffers.buffer_size) { 461 if (height * width * bpp > fh->buffers.buffer_size) {
648 dprintk(1, 462 dprintk(1,
649 KERN_ERR 463 KERN_ERR
650 "%s: v4l_set_format() - video buffer size (%d kB) is too small\n", 464 "%s: %s - video buffer size (%d kB) is too small\n",
651 ZR_DEVNAME(zr), fh->v4l_buffers.buffer_size >> 10); 465 ZR_DEVNAME(zr), __func__, fh->buffers.buffer_size >> 10);
652 return -EINVAL; 466 return -EINVAL;
653 } 467 }
654 468
@@ -657,8 +471,8 @@ zoran_v4l_set_format (struct file *file,
657 if ((bpp == 2 && (width & 1)) || (bpp == 3 && (width & 3))) { 471 if ((bpp == 2 && (width & 1)) || (bpp == 3 && (width & 3))) {
658 dprintk(1, 472 dprintk(1,
659 KERN_ERR 473 KERN_ERR
660 "%s: v4l_set_format() - wrong frame alingment\n", 474 "%s: %s - wrong frame alignment\n",
661 ZR_DEVNAME(zr)); 475 ZR_DEVNAME(zr), __func__);
662 return -EINVAL; 476 return -EINVAL;
663 } 477 }
664 478
@@ -670,43 +484,40 @@ zoran_v4l_set_format (struct file *file,
670 return 0; 484 return 0;
671} 485}
672 486
673static int 487static int zoran_v4l_queue_frame(struct zoran_fh *fh, int num)
674zoran_v4l_queue_frame (struct file *file,
675 int num)
676{ 488{
677 struct zoran_fh *fh = file->private_data;
678 struct zoran *zr = fh->zr; 489 struct zoran *zr = fh->zr;
679 unsigned long flags; 490 unsigned long flags;
680 int res = 0; 491 int res = 0;
681 492
682 if (!fh->v4l_buffers.allocated) { 493 if (!fh->buffers.allocated) {
683 dprintk(1, 494 dprintk(1,
684 KERN_ERR 495 KERN_ERR
685 "%s: v4l_queue_frame() - buffers not yet allocated\n", 496 "%s: %s - buffers not yet allocated\n",
686 ZR_DEVNAME(zr)); 497 ZR_DEVNAME(zr), __func__);
687 res = -ENOMEM; 498 res = -ENOMEM;
688 } 499 }
689 500
690 /* No grabbing outside the buffer range! */ 501 /* No grabbing outside the buffer range! */
691 if (num >= fh->v4l_buffers.num_buffers || num < 0) { 502 if (num >= fh->buffers.num_buffers || num < 0) {
692 dprintk(1, 503 dprintk(1,
693 KERN_ERR 504 KERN_ERR
694 "%s: v4l_queue_frame() - buffer %d is out of range\n", 505 "%s: %s - buffer %d is out of range\n",
695 ZR_DEVNAME(zr), num); 506 ZR_DEVNAME(zr), __func__, num);
696 res = -EINVAL; 507 res = -EINVAL;
697 } 508 }
698 509
699 spin_lock_irqsave(&zr->spinlock, flags); 510 spin_lock_irqsave(&zr->spinlock, flags);
700 511
701 if (fh->v4l_buffers.active == ZORAN_FREE) { 512 if (fh->buffers.active == ZORAN_FREE) {
702 if (zr->v4l_buffers.active == ZORAN_FREE) { 513 if (zr->v4l_buffers.active == ZORAN_FREE) {
703 zr->v4l_buffers = fh->v4l_buffers; 514 zr->v4l_buffers = fh->buffers;
704 fh->v4l_buffers.active = ZORAN_ACTIVE; 515 fh->buffers.active = ZORAN_ACTIVE;
705 } else { 516 } else {
706 dprintk(1, 517 dprintk(1,
707 KERN_ERR 518 KERN_ERR
708 "%s: v4l_queue_frame() - another session is already capturing\n", 519 "%s: %s - another session is already capturing\n",
709 ZR_DEVNAME(zr)); 520 ZR_DEVNAME(zr), __func__);
710 res = -EBUSY; 521 res = -EBUSY;
711 } 522 }
712 } 523 }
@@ -717,7 +528,7 @@ zoran_v4l_queue_frame (struct file *file,
717 default: 528 default:
718 case BUZ_STATE_PEND: 529 case BUZ_STATE_PEND:
719 if (zr->v4l_buffers.active == ZORAN_FREE) { 530 if (zr->v4l_buffers.active == ZORAN_FREE) {
720 fh->v4l_buffers.active = ZORAN_FREE; 531 fh->buffers.active = ZORAN_FREE;
721 zr->v4l_buffers.allocated = 0; 532 zr->v4l_buffers.allocated = 0;
722 } 533 }
723 res = -EBUSY; /* what are you doing? */ 534 res = -EBUSY; /* what are you doing? */
@@ -725,19 +536,17 @@ zoran_v4l_queue_frame (struct file *file,
725 case BUZ_STATE_DONE: 536 case BUZ_STATE_DONE:
726 dprintk(2, 537 dprintk(2,
727 KERN_WARNING 538 KERN_WARNING
728 "%s: v4l_queue_frame() - queueing buffer %d in state DONE!?\n", 539 "%s: %s - queueing buffer %d in state DONE!?\n",
729 ZR_DEVNAME(zr), num); 540 ZR_DEVNAME(zr), __func__, num);
730 case BUZ_STATE_USER: 541 case BUZ_STATE_USER:
731 /* since there is at least one unused buffer there's room for at least 542 /* since there is at least one unused buffer there's room for at least
732 * one more pend[] entry */ 543 * one more pend[] entry */
733 zr->v4l_pend[zr->v4l_pend_head++ & 544 zr->v4l_pend[zr->v4l_pend_head++ & V4L_MASK_FRAME] = num;
734 V4L_MASK_FRAME] = num;
735 zr->v4l_buffers.buffer[num].state = BUZ_STATE_PEND; 545 zr->v4l_buffers.buffer[num].state = BUZ_STATE_PEND;
736 zr->v4l_buffers.buffer[num].bs.length = 546 zr->v4l_buffers.buffer[num].bs.length =
737 fh->v4l_settings.bytesperline * 547 fh->v4l_settings.bytesperline *
738 zr->v4l_settings.height; 548 zr->v4l_settings.height;
739 fh->v4l_buffers.buffer[num] = 549 fh->buffers.buffer[num] = zr->v4l_buffers.buffer[num];
740 zr->v4l_buffers.buffer[num];
741 break; 550 break;
742 } 551 }
743 } 552 }
@@ -745,65 +554,7 @@ zoran_v4l_queue_frame (struct file *file,
745 spin_unlock_irqrestore(&zr->spinlock, flags); 554 spin_unlock_irqrestore(&zr->spinlock, flags);
746 555
747 if (!res && zr->v4l_buffers.active == ZORAN_FREE) 556 if (!res && zr->v4l_buffers.active == ZORAN_FREE)
748 zr->v4l_buffers.active = fh->v4l_buffers.active; 557 zr->v4l_buffers.active = fh->buffers.active;
749
750 return res;
751}
752
753static int
754v4l_grab (struct file *file,
755 struct video_mmap *mp)
756{
757 struct zoran_fh *fh = file->private_data;
758 struct zoran *zr = fh->zr;
759 int res = 0, i;
760
761 for (i = 0; i < NUM_FORMATS; i++) {
762 if (zoran_formats[i].palette == mp->format &&
763 zoran_formats[i].flags & ZORAN_FORMAT_CAPTURE &&
764 !(zoran_formats[i].flags & ZORAN_FORMAT_COMPRESSED))
765 break;
766 }
767 if (i == NUM_FORMATS || zoran_formats[i].depth == 0) {
768 dprintk(1,
769 KERN_ERR
770 "%s: v4l_grab() - wrong bytes-per-pixel format\n",
771 ZR_DEVNAME(zr));
772 return -EINVAL;
773 }
774
775 /*
776 * To minimize the time spent in the IRQ routine, we avoid setting up
777 * the video front end there.
778 * If this grab has different parameters from a running streaming capture
779 * we stop the streaming capture and start it over again.
780 */
781 if (zr->v4l_memgrab_active &&
782 (zr->v4l_settings.width != mp->width ||
783 zr->v4l_settings.height != mp->height ||
784 zr->v4l_settings.format->palette != mp->format)) {
785 res = wait_grab_pending(zr);
786 if (res)
787 return res;
788 }
789 if ((res = zoran_v4l_set_format(file,
790 mp->width,
791 mp->height,
792 &zoran_formats[i])))
793 return res;
794 zr->v4l_settings = fh->v4l_settings;
795
796 /* queue the frame in the pending queue */
797 if ((res = zoran_v4l_queue_frame(file, mp->frame))) {
798 fh->v4l_buffers.active = ZORAN_FREE;
799 return res;
800 }
801
802 /* put the 36057 into frame grabbing mode */
803 if (!res && !zr->v4l_memgrab_active)
804 zr36057_set_memgrab(zr, 1);
805
806 //dprintk(4, KERN_INFO "%s: Frame grab 3...\n", ZR_DEVNAME(zr));
807 558
808 return res; 559 return res;
809} 560}
@@ -812,27 +563,24 @@ v4l_grab (struct file *file,
812 * Sync on a V4L buffer 563 * Sync on a V4L buffer
813 */ 564 */
814 565
815static int 566static int v4l_sync(struct zoran_fh *fh, int frame)
816v4l_sync (struct file *file,
817 int frame)
818{ 567{
819 struct zoran_fh *fh = file->private_data;
820 struct zoran *zr = fh->zr; 568 struct zoran *zr = fh->zr;
821 unsigned long flags; 569 unsigned long flags;
822 570
823 if (fh->v4l_buffers.active == ZORAN_FREE) { 571 if (fh->buffers.active == ZORAN_FREE) {
824 dprintk(1, 572 dprintk(1,
825 KERN_ERR 573 KERN_ERR
826 "%s: v4l_sync() - no grab active for this session\n", 574 "%s: %s - no grab active for this session\n",
827 ZR_DEVNAME(zr)); 575 ZR_DEVNAME(zr), __func__);
828 return -EINVAL; 576 return -EINVAL;
829 } 577 }
830 578
831 /* check passed-in frame number */ 579 /* check passed-in frame number */
832 if (frame >= fh->v4l_buffers.num_buffers || frame < 0) { 580 if (frame >= fh->buffers.num_buffers || frame < 0) {
833 dprintk(1, 581 dprintk(1,
834 KERN_ERR "%s: v4l_sync() - frame %d is invalid\n", 582 KERN_ERR "%s: %s - frame %d is invalid\n",
835 ZR_DEVNAME(zr), frame); 583 ZR_DEVNAME(zr), __func__, frame);
836 return -EINVAL; 584 return -EINVAL;
837 } 585 }
838 586
@@ -840,15 +588,14 @@ v4l_sync (struct file *file,
840 if (zr->v4l_buffers.buffer[frame].state == BUZ_STATE_USER) { 588 if (zr->v4l_buffers.buffer[frame].state == BUZ_STATE_USER) {
841 dprintk(1, 589 dprintk(1,
842 KERN_ERR 590 KERN_ERR
843 "%s: v4l_sync() - attempt to sync on a buffer which was not queued?\n", 591 "%s: %s - attempt to sync on a buffer which was not queued?\n",
844 ZR_DEVNAME(zr)); 592 ZR_DEVNAME(zr), __func__);
845 return -EPROTO; 593 return -EPROTO;
846 } 594 }
847 595
848 /* wait on this buffer to get ready */ 596 /* wait on this buffer to get ready */
849 if (!wait_event_interruptible_timeout(zr->v4l_capq, 597 if (!wait_event_interruptible_timeout(zr->v4l_capq,
850 (zr->v4l_buffers.buffer[frame].state != BUZ_STATE_PEND), 598 (zr->v4l_buffers.buffer[frame].state != BUZ_STATE_PEND), 10*HZ))
851 10*HZ))
852 return -ETIME; 599 return -ETIME;
853 if (signal_pending(current)) 600 if (signal_pending(current))
854 return -ERESTARTSYS; 601 return -ERESTARTSYS;
@@ -856,11 +603,11 @@ v4l_sync (struct file *file,
856 /* buffer should now be in BUZ_STATE_DONE */ 603 /* buffer should now be in BUZ_STATE_DONE */
857 if (zr->v4l_buffers.buffer[frame].state != BUZ_STATE_DONE) 604 if (zr->v4l_buffers.buffer[frame].state != BUZ_STATE_DONE)
858 dprintk(2, 605 dprintk(2,
859 KERN_ERR "%s: v4l_sync() - internal state error\n", 606 KERN_ERR "%s: %s - internal state error\n",
860 ZR_DEVNAME(zr)); 607 ZR_DEVNAME(zr), __func__);
861 608
862 zr->v4l_buffers.buffer[frame].state = BUZ_STATE_USER; 609 zr->v4l_buffers.buffer[frame].state = BUZ_STATE_USER;
863 fh->v4l_buffers.buffer[frame] = zr->v4l_buffers.buffer[frame]; 610 fh->buffers.buffer[frame] = zr->v4l_buffers.buffer[frame];
864 611
865 spin_lock_irqsave(&zr->spinlock, flags); 612 spin_lock_irqsave(&zr->spinlock, flags);
866 613
@@ -868,8 +615,7 @@ v4l_sync (struct file *file,
868 if (zr->v4l_pend_tail == zr->v4l_pend_head) { 615 if (zr->v4l_pend_tail == zr->v4l_pend_head) {
869 zr36057_set_memgrab(zr, 0); 616 zr36057_set_memgrab(zr, 0);
870 if (zr->v4l_buffers.active == ZORAN_ACTIVE) { 617 if (zr->v4l_buffers.active == ZORAN_ACTIVE) {
871 fh->v4l_buffers.active = zr->v4l_buffers.active = 618 fh->buffers.active = zr->v4l_buffers.active = ZORAN_FREE;
872 ZORAN_FREE;
873 zr->v4l_buffers.allocated = 0; 619 zr->v4l_buffers.allocated = 0;
874 } 620 }
875 } 621 }
@@ -883,31 +629,28 @@ v4l_sync (struct file *file,
883 * Queue a MJPEG buffer for capture/playback 629 * Queue a MJPEG buffer for capture/playback
884 */ 630 */
885 631
886static int 632static int zoran_jpg_queue_frame(struct zoran_fh *fh, int num,
887zoran_jpg_queue_frame (struct file *file, 633 enum zoran_codec_mode mode)
888 int num,
889 enum zoran_codec_mode mode)
890{ 634{
891 struct zoran_fh *fh = file->private_data;
892 struct zoran *zr = fh->zr; 635 struct zoran *zr = fh->zr;
893 unsigned long flags; 636 unsigned long flags;
894 int res = 0; 637 int res = 0;
895 638
896 /* Check if buffers are allocated */ 639 /* Check if buffers are allocated */
897 if (!fh->jpg_buffers.allocated) { 640 if (!fh->buffers.allocated) {
898 dprintk(1, 641 dprintk(1,
899 KERN_ERR 642 KERN_ERR
900 "%s: jpg_queue_frame() - buffers not yet allocated\n", 643 "%s: %s - buffers not yet allocated\n",
901 ZR_DEVNAME(zr)); 644 ZR_DEVNAME(zr), __func__);
902 return -ENOMEM; 645 return -ENOMEM;
903 } 646 }
904 647
905 /* No grabbing outside the buffer range! */ 648 /* No grabbing outside the buffer range! */
906 if (num >= fh->jpg_buffers.num_buffers || num < 0) { 649 if (num >= fh->buffers.num_buffers || num < 0) {
907 dprintk(1, 650 dprintk(1,
908 KERN_ERR 651 KERN_ERR
909 "%s: jpg_queue_frame() - buffer %d out of range\n", 652 "%s: %s - buffer %d out of range\n",
910 ZR_DEVNAME(zr), num); 653 ZR_DEVNAME(zr), __func__, num);
911 return -EINVAL; 654 return -EINVAL;
912 } 655 }
913 656
@@ -918,20 +661,20 @@ zoran_jpg_queue_frame (struct file *file,
918 /* wrong codec mode active - invalid */ 661 /* wrong codec mode active - invalid */
919 dprintk(1, 662 dprintk(1,
920 KERN_ERR 663 KERN_ERR
921 "%s: jpg_queue_frame() - codec in wrong mode\n", 664 "%s: %s - codec in wrong mode\n",
922 ZR_DEVNAME(zr)); 665 ZR_DEVNAME(zr), __func__);
923 return -EINVAL; 666 return -EINVAL;
924 } 667 }
925 668
926 if (fh->jpg_buffers.active == ZORAN_FREE) { 669 if (fh->buffers.active == ZORAN_FREE) {
927 if (zr->jpg_buffers.active == ZORAN_FREE) { 670 if (zr->jpg_buffers.active == ZORAN_FREE) {
928 zr->jpg_buffers = fh->jpg_buffers; 671 zr->jpg_buffers = fh->buffers;
929 fh->jpg_buffers.active = ZORAN_ACTIVE; 672 fh->buffers.active = ZORAN_ACTIVE;
930 } else { 673 } else {
931 dprintk(1, 674 dprintk(1,
932 KERN_ERR 675 KERN_ERR
933 "%s: jpg_queue_frame() - another session is already capturing\n", 676 "%s: %s - another session is already capturing\n",
934 ZR_DEVNAME(zr)); 677 ZR_DEVNAME(zr), __func__);
935 res = -EBUSY; 678 res = -EBUSY;
936 } 679 }
937 } 680 }
@@ -948,23 +691,21 @@ zoran_jpg_queue_frame (struct file *file,
948 case BUZ_STATE_DONE: 691 case BUZ_STATE_DONE:
949 dprintk(2, 692 dprintk(2,
950 KERN_WARNING 693 KERN_WARNING
951 "%s: jpg_queue_frame() - queing frame in BUZ_STATE_DONE state!?\n", 694 "%s: %s - queing frame in BUZ_STATE_DONE state!?\n",
952 ZR_DEVNAME(zr)); 695 ZR_DEVNAME(zr), __func__);
953 case BUZ_STATE_USER: 696 case BUZ_STATE_USER:
954 /* since there is at least one unused buffer there's room for at 697 /* since there is at least one unused buffer there's room for at
955 *least one more pend[] entry */ 698 *least one more pend[] entry */
956 zr->jpg_pend[zr->jpg_que_head++ & BUZ_MASK_FRAME] = 699 zr->jpg_pend[zr->jpg_que_head++ & BUZ_MASK_FRAME] = num;
957 num;
958 zr->jpg_buffers.buffer[num].state = BUZ_STATE_PEND; 700 zr->jpg_buffers.buffer[num].state = BUZ_STATE_PEND;
959 fh->jpg_buffers.buffer[num] = 701 fh->buffers.buffer[num] = zr->jpg_buffers.buffer[num];
960 zr->jpg_buffers.buffer[num];
961 zoran_feed_stat_com(zr); 702 zoran_feed_stat_com(zr);
962 break; 703 break;
963 default: 704 default:
964 case BUZ_STATE_DMA: 705 case BUZ_STATE_DMA:
965 case BUZ_STATE_PEND: 706 case BUZ_STATE_PEND:
966 if (zr->jpg_buffers.active == ZORAN_FREE) { 707 if (zr->jpg_buffers.active == ZORAN_FREE) {
967 fh->jpg_buffers.active = ZORAN_FREE; 708 fh->buffers.active = ZORAN_FREE;
968 zr->jpg_buffers.allocated = 0; 709 zr->jpg_buffers.allocated = 0;
969 } 710 }
970 res = -EBUSY; /* what are you doing? */ 711 res = -EBUSY; /* what are you doing? */
@@ -974,47 +715,41 @@ zoran_jpg_queue_frame (struct file *file,
974 715
975 spin_unlock_irqrestore(&zr->spinlock, flags); 716 spin_unlock_irqrestore(&zr->spinlock, flags);
976 717
977 if (!res && zr->jpg_buffers.active == ZORAN_FREE) { 718 if (!res && zr->jpg_buffers.active == ZORAN_FREE)
978 zr->jpg_buffers.active = fh->jpg_buffers.active; 719 zr->jpg_buffers.active = fh->buffers.active;
979 }
980 720
981 return res; 721 return res;
982} 722}
983 723
984static int 724static int jpg_qbuf(struct zoran_fh *fh, int frame, enum zoran_codec_mode mode)
985jpg_qbuf (struct file *file,
986 int frame,
987 enum zoran_codec_mode mode)
988{ 725{
989 struct zoran_fh *fh = file->private_data;
990 struct zoran *zr = fh->zr; 726 struct zoran *zr = fh->zr;
991 int res = 0; 727 int res = 0;
992 728
993 /* Does the user want to stop streaming? */ 729 /* Does the user want to stop streaming? */
994 if (frame < 0) { 730 if (frame < 0) {
995 if (zr->codec_mode == mode) { 731 if (zr->codec_mode == mode) {
996 if (fh->jpg_buffers.active == ZORAN_FREE) { 732 if (fh->buffers.active == ZORAN_FREE) {
997 dprintk(1, 733 dprintk(1,
998 KERN_ERR 734 KERN_ERR
999 "%s: jpg_qbuf(-1) - session not active\n", 735 "%s: %s(-1) - session not active\n",
1000 ZR_DEVNAME(zr)); 736 ZR_DEVNAME(zr), __func__);
1001 return -EINVAL; 737 return -EINVAL;
1002 } 738 }
1003 fh->jpg_buffers.active = zr->jpg_buffers.active = 739 fh->buffers.active = zr->jpg_buffers.active = ZORAN_FREE;
1004 ZORAN_FREE;
1005 zr->jpg_buffers.allocated = 0; 740 zr->jpg_buffers.allocated = 0;
1006 zr36057_enable_jpg(zr, BUZ_MODE_IDLE); 741 zr36057_enable_jpg(zr, BUZ_MODE_IDLE);
1007 return 0; 742 return 0;
1008 } else { 743 } else {
1009 dprintk(1, 744 dprintk(1,
1010 KERN_ERR 745 KERN_ERR
1011 "%s: jpg_qbuf() - stop streaming but not in streaming mode\n", 746 "%s: %s - stop streaming but not in streaming mode\n",
1012 ZR_DEVNAME(zr)); 747 ZR_DEVNAME(zr), __func__);
1013 return -EINVAL; 748 return -EINVAL;
1014 } 749 }
1015 } 750 }
1016 751
1017 if ((res = zoran_jpg_queue_frame(file, frame, mode))) 752 if ((res = zoran_jpg_queue_frame(fh, frame, mode)))
1018 return res; 753 return res;
1019 754
1020 /* Start the jpeg codec when the first frame is queued */ 755 /* Start the jpeg codec when the first frame is queued */
@@ -1028,28 +763,25 @@ jpg_qbuf (struct file *file,
1028 * Sync on a MJPEG buffer 763 * Sync on a MJPEG buffer
1029 */ 764 */
1030 765
1031static int 766static int jpg_sync(struct zoran_fh *fh, struct zoran_sync *bs)
1032jpg_sync (struct file *file,
1033 struct zoran_sync *bs)
1034{ 767{
1035 struct zoran_fh *fh = file->private_data;
1036 struct zoran *zr = fh->zr; 768 struct zoran *zr = fh->zr;
1037 unsigned long flags; 769 unsigned long flags;
1038 int frame; 770 int frame;
1039 771
1040 if (fh->jpg_buffers.active == ZORAN_FREE) { 772 if (fh->buffers.active == ZORAN_FREE) {
1041 dprintk(1, 773 dprintk(1,
1042 KERN_ERR 774 KERN_ERR
1043 "%s: jpg_sync() - capture is not currently active\n", 775 "%s: %s - capture is not currently active\n",
1044 ZR_DEVNAME(zr)); 776 ZR_DEVNAME(zr), __func__);
1045 return -EINVAL; 777 return -EINVAL;
1046 } 778 }
1047 if (zr->codec_mode != BUZ_MODE_MOTION_DECOMPRESS && 779 if (zr->codec_mode != BUZ_MODE_MOTION_DECOMPRESS &&
1048 zr->codec_mode != BUZ_MODE_MOTION_COMPRESS) { 780 zr->codec_mode != BUZ_MODE_MOTION_COMPRESS) {
1049 dprintk(1, 781 dprintk(1,
1050 KERN_ERR 782 KERN_ERR
1051 "%s: jpg_sync() - codec not in streaming mode\n", 783 "%s: %s - codec not in streaming mode\n",
1052 ZR_DEVNAME(zr)); 784 ZR_DEVNAME(zr), __func__);
1053 return -EINVAL; 785 return -EINVAL;
1054 } 786 }
1055 if (!wait_event_interruptible_timeout(zr->jpg_capq, 787 if (!wait_event_interruptible_timeout(zr->jpg_capq,
@@ -1064,8 +796,8 @@ jpg_sync (struct file *file,
1064 sizeof(isr), &isr); 796 sizeof(isr), &isr);
1065 dprintk(1, 797 dprintk(1,
1066 KERN_ERR 798 KERN_ERR
1067 "%s: jpg_sync() - timeout: codec isr=0x%02x\n", 799 "%s: %s - timeout: codec isr=0x%02x\n",
1068 ZR_DEVNAME(zr), isr); 800 ZR_DEVNAME(zr), __func__, isr);
1069 801
1070 return -ETIME; 802 return -ETIME;
1071 803
@@ -1083,28 +815,26 @@ jpg_sync (struct file *file,
1083 /* buffer should now be in BUZ_STATE_DONE */ 815 /* buffer should now be in BUZ_STATE_DONE */
1084 if (zr->jpg_buffers.buffer[frame].state != BUZ_STATE_DONE) 816 if (zr->jpg_buffers.buffer[frame].state != BUZ_STATE_DONE)
1085 dprintk(2, 817 dprintk(2,
1086 KERN_ERR "%s: jpg_sync() - internal state error\n", 818 KERN_ERR "%s: %s - internal state error\n",
1087 ZR_DEVNAME(zr)); 819 ZR_DEVNAME(zr), __func__);
1088 820
1089 *bs = zr->jpg_buffers.buffer[frame].bs; 821 *bs = zr->jpg_buffers.buffer[frame].bs;
1090 bs->frame = frame; 822 bs->frame = frame;
1091 zr->jpg_buffers.buffer[frame].state = BUZ_STATE_USER; 823 zr->jpg_buffers.buffer[frame].state = BUZ_STATE_USER;
1092 fh->jpg_buffers.buffer[frame] = zr->jpg_buffers.buffer[frame]; 824 fh->buffers.buffer[frame] = zr->jpg_buffers.buffer[frame];
1093 825
1094 spin_unlock_irqrestore(&zr->spinlock, flags); 826 spin_unlock_irqrestore(&zr->spinlock, flags);
1095 827
1096 return 0; 828 return 0;
1097} 829}
1098 830
1099static void 831static void zoran_open_init_session(struct zoran_fh *fh)
1100zoran_open_init_session (struct file *file)
1101{ 832{
1102 int i; 833 int i;
1103 struct zoran_fh *fh = file->private_data;
1104 struct zoran *zr = fh->zr; 834 struct zoran *zr = fh->zr;
1105 835
1106 /* Per default, map the V4L Buffers */ 836 /* Per default, map the V4L Buffers */
1107 fh->map_mode = ZORAN_MAP_MODE_RAW; 837 map_mode_raw(fh);
1108 838
1109 /* take over the card's current settings */ 839 /* take over the card's current settings */
1110 fh->overlay_settings = zr->overlay_settings; 840 fh->overlay_settings = zr->overlay_settings;
@@ -1114,40 +844,21 @@ zoran_open_init_session (struct file *file)
1114 844
1115 /* v4l settings */ 845 /* v4l settings */
1116 fh->v4l_settings = zr->v4l_settings; 846 fh->v4l_settings = zr->v4l_settings;
1117
1118 /* v4l_buffers */
1119 memset(&fh->v4l_buffers, 0, sizeof(struct zoran_v4l_struct));
1120 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
1121 fh->v4l_buffers.buffer[i].state = BUZ_STATE_USER; /* nothing going on */
1122 fh->v4l_buffers.buffer[i].bs.frame = i;
1123 }
1124 fh->v4l_buffers.allocated = 0;
1125 fh->v4l_buffers.ready_to_be_freed = 0;
1126 fh->v4l_buffers.active = ZORAN_FREE;
1127 fh->v4l_buffers.buffer_size = v4l_bufsize;
1128 fh->v4l_buffers.num_buffers = v4l_nbufs;
1129
1130 /* jpg settings */ 847 /* jpg settings */
1131 fh->jpg_settings = zr->jpg_settings; 848 fh->jpg_settings = zr->jpg_settings;
1132 849
1133 /* jpg_buffers */ 850 /* buffers */
1134 memset(&fh->jpg_buffers, 0, sizeof(struct zoran_jpg_struct)); 851 memset(&fh->buffers, 0, sizeof(fh->buffers));
1135 for (i = 0; i < BUZ_MAX_FRAME; i++) { 852 for (i = 0; i < MAX_FRAME; i++) {
1136 fh->jpg_buffers.buffer[i].state = BUZ_STATE_USER; /* nothing going on */ 853 fh->buffers.buffer[i].state = BUZ_STATE_USER; /* nothing going on */
1137 fh->jpg_buffers.buffer[i].bs.frame = i; 854 fh->buffers.buffer[i].bs.frame = i;
1138 } 855 }
1139 fh->jpg_buffers.need_contiguous = zr->jpg_buffers.need_contiguous; 856 fh->buffers.allocated = 0;
1140 fh->jpg_buffers.allocated = 0; 857 fh->buffers.active = ZORAN_FREE;
1141 fh->jpg_buffers.ready_to_be_freed = 0;
1142 fh->jpg_buffers.active = ZORAN_FREE;
1143 fh->jpg_buffers.buffer_size = jpg_bufsize;
1144 fh->jpg_buffers.num_buffers = jpg_nbufs;
1145} 858}
1146 859
1147static void 860static void zoran_close_end_session(struct zoran_fh *fh)
1148zoran_close_end_session (struct file *file)
1149{ 861{
1150 struct zoran_fh *fh = file->private_data;
1151 struct zoran *zr = fh->zr; 862 struct zoran *zr = fh->zr;
1152 863
1153 /* overlay */ 864 /* overlay */
@@ -1159,36 +870,32 @@ zoran_close_end_session (struct file *file)
1159 zr->overlay_mask = NULL; 870 zr->overlay_mask = NULL;
1160 } 871 }
1161 872
1162 /* v4l capture */ 873 if (fh->map_mode == ZORAN_MAP_MODE_RAW) {
1163 if (fh->v4l_buffers.active != ZORAN_FREE) { 874 /* v4l capture */
1164 unsigned long flags; 875 if (fh->buffers.active != ZORAN_FREE) {
876 unsigned long flags;
1165 877
1166 spin_lock_irqsave(&zr->spinlock, flags); 878 spin_lock_irqsave(&zr->spinlock, flags);
1167 zr36057_set_memgrab(zr, 0); 879 zr36057_set_memgrab(zr, 0);
1168 zr->v4l_buffers.allocated = 0; 880 zr->v4l_buffers.allocated = 0;
1169 zr->v4l_buffers.active = fh->v4l_buffers.active = 881 zr->v4l_buffers.active = fh->buffers.active = ZORAN_FREE;
1170 ZORAN_FREE; 882 spin_unlock_irqrestore(&zr->spinlock, flags);
1171 spin_unlock_irqrestore(&zr->spinlock, flags); 883 }
1172 }
1173
1174 /* v4l buffers */
1175 if (fh->v4l_buffers.allocated ||
1176 fh->v4l_buffers.ready_to_be_freed) {
1177 v4l_fbuffer_free(file);
1178 }
1179 884
1180 /* jpg capture */ 885 /* v4l buffers */
1181 if (fh->jpg_buffers.active != ZORAN_FREE) { 886 if (fh->buffers.allocated)
1182 zr36057_enable_jpg(zr, BUZ_MODE_IDLE); 887 v4l_fbuffer_free(fh);
1183 zr->jpg_buffers.allocated = 0; 888 } else {
1184 zr->jpg_buffers.active = fh->jpg_buffers.active = 889 /* jpg capture */
1185 ZORAN_FREE; 890 if (fh->buffers.active != ZORAN_FREE) {
1186 } 891 zr36057_enable_jpg(zr, BUZ_MODE_IDLE);
892 zr->jpg_buffers.allocated = 0;
893 zr->jpg_buffers.active = fh->buffers.active = ZORAN_FREE;
894 }
1187 895
1188 /* jpg buffers */ 896 /* jpg buffers */
1189 if (fh->jpg_buffers.allocated || 897 if (fh->buffers.allocated)
1190 fh->jpg_buffers.ready_to_be_freed) { 898 jpg_fbuffer_free(fh);
1191 jpg_fbuffer_free(file);
1192 } 899 }
1193} 900}
1194 901
@@ -1202,15 +909,11 @@ static int zoran_open(struct file *file)
1202 struct zoran_fh *fh; 909 struct zoran_fh *fh;
1203 int res, first_open = 0; 910 int res, first_open = 0;
1204 911
1205 dprintk(2, KERN_INFO "%s: zoran_open(%s, pid=[%d]), users(-)=%d\n", 912 dprintk(2, KERN_INFO "%s: %s(%s, pid=[%d]), users(-)=%d\n",
1206 ZR_DEVNAME(zr), current->comm, task_pid_nr(current), zr->user + 1); 913 ZR_DEVNAME(zr), __func__, current->comm, task_pid_nr(current), zr->user + 1);
1207 914
1208 lock_kernel(); 915 lock_kernel();
1209 916
1210 /* see fs/device.c - the kernel already locks during open(),
1211 * so locking ourselves only causes deadlocks */
1212 /*mutex_lock(&zr->resource_lock);*/
1213
1214 if (zr->user >= 2048) { 917 if (zr->user >= 2048) {
1215 dprintk(1, KERN_ERR "%s: too many users (%d) on device\n", 918 dprintk(1, KERN_ERR "%s: too many users (%d) on device\n",
1216 ZR_DEVNAME(zr), zr->user); 919 ZR_DEVNAME(zr), zr->user);
@@ -1218,41 +921,15 @@ static int zoran_open(struct file *file)
1218 goto fail_unlock; 921 goto fail_unlock;
1219 } 922 }
1220 923
1221 if (!zr->decoder) {
1222 dprintk(1,
1223 KERN_ERR "%s: no TV decoder loaded for device!\n",
1224 ZR_DEVNAME(zr));
1225 res = -EIO;
1226 goto fail_unlock;
1227 }
1228
1229 if (!try_module_get(zr->decoder->driver->driver.owner)) {
1230 dprintk(1,
1231 KERN_ERR
1232 "%s: failed to grab ownership of video decoder\n",
1233 ZR_DEVNAME(zr));
1234 res = -EIO;
1235 goto fail_unlock;
1236 }
1237 if (zr->encoder &&
1238 !try_module_get(zr->encoder->driver->driver.owner)) {
1239 dprintk(1,
1240 KERN_ERR
1241 "%s: failed to grab ownership of video encoder\n",
1242 ZR_DEVNAME(zr));
1243 res = -EIO;
1244 goto fail_decoder;
1245 }
1246
1247 /* now, create the open()-specific file_ops struct */ 924 /* now, create the open()-specific file_ops struct */
1248 fh = kzalloc(sizeof(struct zoran_fh), GFP_KERNEL); 925 fh = kzalloc(sizeof(struct zoran_fh), GFP_KERNEL);
1249 if (!fh) { 926 if (!fh) {
1250 dprintk(1, 927 dprintk(1,
1251 KERN_ERR 928 KERN_ERR
1252 "%s: zoran_open() - allocation of zoran_fh failed\n", 929 "%s: %s - allocation of zoran_fh failed\n",
1253 ZR_DEVNAME(zr)); 930 ZR_DEVNAME(zr), __func__);
1254 res = -ENOMEM; 931 res = -ENOMEM;
1255 goto fail_encoder; 932 goto fail_unlock;
1256 } 933 }
1257 /* used to be BUZ_MAX_WIDTH/HEIGHT, but that gives overflows 934 /* used to be BUZ_MAX_WIDTH/HEIGHT, but that gives overflows
1258 * on norm-change! */ 935 * on norm-change! */
@@ -1261,8 +938,8 @@ static int zoran_open(struct file *file)
1261 if (!fh->overlay_mask) { 938 if (!fh->overlay_mask) {
1262 dprintk(1, 939 dprintk(1,
1263 KERN_ERR 940 KERN_ERR
1264 "%s: zoran_open() - allocation of overlay_mask failed\n", 941 "%s: %s - allocation of overlay_mask failed\n",
1265 ZR_DEVNAME(zr)); 942 ZR_DEVNAME(zr), __func__);
1266 res = -ENOMEM; 943 res = -ENOMEM;
1267 goto fail_fh; 944 goto fail_fh;
1268 } 945 }
@@ -1284,18 +961,13 @@ static int zoran_open(struct file *file)
1284 /* set file_ops stuff */ 961 /* set file_ops stuff */
1285 file->private_data = fh; 962 file->private_data = fh;
1286 fh->zr = zr; 963 fh->zr = zr;
1287 zoran_open_init_session(file); 964 zoran_open_init_session(fh);
1288 unlock_kernel(); 965 unlock_kernel();
1289 966
1290 return 0; 967 return 0;
1291 968
1292fail_fh: 969fail_fh:
1293 kfree(fh); 970 kfree(fh);
1294fail_encoder:
1295 if (zr->encoder)
1296 module_put(zr->encoder->driver->driver.owner);
1297fail_decoder:
1298 module_put(zr->decoder->driver->driver.owner);
1299fail_unlock: 971fail_unlock:
1300 unlock_kernel(); 972 unlock_kernel();
1301 973
@@ -1311,14 +983,14 @@ zoran_close(struct file *file)
1311 struct zoran_fh *fh = file->private_data; 983 struct zoran_fh *fh = file->private_data;
1312 struct zoran *zr = fh->zr; 984 struct zoran *zr = fh->zr;
1313 985
1314 dprintk(2, KERN_INFO "%s: zoran_close(%s, pid=[%d]), users(+)=%d\n", 986 dprintk(2, KERN_INFO "%s: %s(%s, pid=[%d]), users(+)=%d\n",
1315 ZR_DEVNAME(zr), current->comm, task_pid_nr(current), zr->user - 1); 987 ZR_DEVNAME(zr), __func__, current->comm, task_pid_nr(current), zr->user - 1);
1316 988
1317 /* kernel locks (fs/device.c), so don't do that ourselves 989 /* kernel locks (fs/device.c), so don't do that ourselves
1318 * (prevents deadlocks) */ 990 * (prevents deadlocks) */
1319 /*mutex_lock(&zr->resource_lock);*/ 991 /*mutex_lock(&zr->resource_lock);*/
1320 992
1321 zoran_close_end_session(file); 993 zoran_close_end_session(fh);
1322 994
1323 if (zr->user-- == 1) { /* Last process */ 995 if (zr->user-- == 1) { /* Last process */
1324 /* Clean up JPEG process */ 996 /* Clean up JPEG process */
@@ -1346,9 +1018,10 @@ zoran_close(struct file *file)
1346 zoran_set_pci_master(zr, 0); 1018 zoran_set_pci_master(zr, 0);
1347 1019
1348 if (!pass_through) { /* Switch to color bar */ 1020 if (!pass_through) { /* Switch to color bar */
1349 int zero = 0, two = 2; 1021 struct v4l2_routing route = { 2, 0 };
1350 decoder_command(zr, DECODER_ENABLE_OUTPUT, &zero); 1022
1351 encoder_command(zr, ENCODER_SET_INPUT, &two); 1023 decoder_call(zr, video, s_stream, 0);
1024 encoder_call(zr, video, s_routing, &route);
1352 } 1025 }
1353 } 1026 }
1354 1027
@@ -1356,14 +1029,7 @@ zoran_close(struct file *file)
1356 kfree(fh->overlay_mask); 1029 kfree(fh->overlay_mask);
1357 kfree(fh); 1030 kfree(fh);
1358 1031
1359 /* release locks on the i2c modules */ 1032 dprintk(4, KERN_INFO "%s: %s done\n", ZR_DEVNAME(zr), __func__);
1360 module_put(zr->decoder->driver->driver.owner);
1361 if (zr->encoder)
1362 module_put(zr->encoder->driver->driver.owner);
1363
1364 /*mutex_unlock(&zr->resource_lock);*/
1365
1366 dprintk(4, KERN_INFO "%s: zoran_close() done\n", ZR_DEVNAME(zr));
1367 1033
1368 return 0; 1034 return 0;
1369} 1035}
@@ -1391,15 +1057,13 @@ zoran_write (struct file *file,
1391 return -EINVAL; 1057 return -EINVAL;
1392} 1058}
1393 1059
1394static int 1060static int setup_fbuffer(struct zoran_fh *fh,
1395setup_fbuffer (struct file *file,
1396 void *base, 1061 void *base,
1397 const struct zoran_format *fmt, 1062 const struct zoran_format *fmt,
1398 int width, 1063 int width,
1399 int height, 1064 int height,
1400 int bytesperline) 1065 int bytesperline)
1401{ 1066{
1402 struct zoran_fh *fh = file->private_data;
1403 struct zoran *zr = fh->zr; 1067 struct zoran *zr = fh->zr;
1404 1068
1405 /* (Ronald) v4l/v4l2 guidelines */ 1069 /* (Ronald) v4l/v4l2 guidelines */
@@ -1427,8 +1091,8 @@ setup_fbuffer (struct file *file,
1427 * friendly and silently do as if nothing went wrong */ 1091 * friendly and silently do as if nothing went wrong */
1428 dprintk(3, 1092 dprintk(3,
1429 KERN_ERR 1093 KERN_ERR
1430 "%s: setup_fbuffer() - forced overlay turnoff because framebuffer changed\n", 1094 "%s: %s - forced overlay turnoff because framebuffer changed\n",
1431 ZR_DEVNAME(zr)); 1095 ZR_DEVNAME(zr), __func__);
1432 zr36057_overlay(zr, 0); 1096 zr36057_overlay(zr, 0);
1433 } 1097 }
1434#endif 1098#endif
@@ -1436,31 +1100,31 @@ setup_fbuffer (struct file *file,
1436 if (!(fmt->flags & ZORAN_FORMAT_OVERLAY)) { 1100 if (!(fmt->flags & ZORAN_FORMAT_OVERLAY)) {
1437 dprintk(1, 1101 dprintk(1,
1438 KERN_ERR 1102 KERN_ERR
1439 "%s: setup_fbuffer() - no valid overlay format given\n", 1103 "%s: %s - no valid overlay format given\n",
1440 ZR_DEVNAME(zr)); 1104 ZR_DEVNAME(zr), __func__);
1441 return -EINVAL; 1105 return -EINVAL;
1442 } 1106 }
1443 if (height <= 0 || width <= 0 || bytesperline <= 0) { 1107 if (height <= 0 || width <= 0 || bytesperline <= 0) {
1444 dprintk(1, 1108 dprintk(1,
1445 KERN_ERR 1109 KERN_ERR
1446 "%s: setup_fbuffer() - invalid height/width/bpl value (%d|%d|%d)\n", 1110 "%s: %s - invalid height/width/bpl value (%d|%d|%d)\n",
1447 ZR_DEVNAME(zr), width, height, bytesperline); 1111 ZR_DEVNAME(zr), __func__, width, height, bytesperline);
1448 return -EINVAL; 1112 return -EINVAL;
1449 } 1113 }
1450 if (bytesperline & 3) { 1114 if (bytesperline & 3) {
1451 dprintk(1, 1115 dprintk(1,
1452 KERN_ERR 1116 KERN_ERR
1453 "%s: setup_fbuffer() - bytesperline (%d) must be 4-byte aligned\n", 1117 "%s: %s - bytesperline (%d) must be 4-byte aligned\n",
1454 ZR_DEVNAME(zr), bytesperline); 1118 ZR_DEVNAME(zr), __func__, bytesperline);
1455 return -EINVAL; 1119 return -EINVAL;
1456 } 1120 }
1457 1121
1458 zr->buffer.base = (void *) ((unsigned long) base & ~3); 1122 zr->vbuf_base = (void *) ((unsigned long) base & ~3);
1459 zr->buffer.height = height; 1123 zr->vbuf_height = height;
1460 zr->buffer.width = width; 1124 zr->vbuf_width = width;
1461 zr->buffer.depth = fmt->depth; 1125 zr->vbuf_depth = fmt->depth;
1462 zr->overlay_settings.format = fmt; 1126 zr->overlay_settings.format = fmt;
1463 zr->buffer.bytesperline = bytesperline; 1127 zr->vbuf_bytesperline = bytesperline;
1464 1128
1465 /* The user should set new window parameters */ 1129 /* The user should set new window parameters */
1466 zr->overlay_settings.is_set = 0; 1130 zr->overlay_settings.is_set = 0;
@@ -1469,35 +1133,27 @@ setup_fbuffer (struct file *file,
1469} 1133}
1470 1134
1471 1135
1472static int 1136static int setup_window(struct zoran_fh *fh, int x, int y, int width, int height,
1473setup_window (struct file *file, 1137 struct v4l2_clip __user *clips, int clipcount, void __user *bitmap)
1474 int x,
1475 int y,
1476 int width,
1477 int height,
1478 struct video_clip __user *clips,
1479 int clipcount,
1480 void __user *bitmap)
1481{ 1138{
1482 struct zoran_fh *fh = file->private_data;
1483 struct zoran *zr = fh->zr; 1139 struct zoran *zr = fh->zr;
1484 struct video_clip *vcp = NULL; 1140 struct v4l2_clip *vcp = NULL;
1485 int on, end; 1141 int on, end;
1486 1142
1487 1143
1488 if (!zr->buffer.base) { 1144 if (!zr->vbuf_base) {
1489 dprintk(1, 1145 dprintk(1,
1490 KERN_ERR 1146 KERN_ERR
1491 "%s: setup_window() - frame buffer has to be set first\n", 1147 "%s: %s - frame buffer has to be set first\n",
1492 ZR_DEVNAME(zr)); 1148 ZR_DEVNAME(zr), __func__);
1493 return -EINVAL; 1149 return -EINVAL;
1494 } 1150 }
1495 1151
1496 if (!fh->overlay_settings.format) { 1152 if (!fh->overlay_settings.format) {
1497 dprintk(1, 1153 dprintk(1,
1498 KERN_ERR 1154 KERN_ERR
1499 "%s: setup_window() - no overlay format set\n", 1155 "%s: %s - no overlay format set\n",
1500 ZR_DEVNAME(zr)); 1156 ZR_DEVNAME(zr), __func__);
1501 return -EINVAL; 1157 return -EINVAL;
1502 } 1158 }
1503 1159
@@ -1505,13 +1161,13 @@ setup_window (struct file *file,
1505 * The video front end needs 4-byte alinged line sizes, we correct that 1161 * The video front end needs 4-byte alinged line sizes, we correct that
1506 * silently here if necessary 1162 * silently here if necessary
1507 */ 1163 */
1508 if (zr->buffer.depth == 15 || zr->buffer.depth == 16) { 1164 if (zr->vbuf_depth == 15 || zr->vbuf_depth == 16) {
1509 end = (x + width) & ~1; /* round down */ 1165 end = (x + width) & ~1; /* round down */
1510 x = (x + 1) & ~1; /* round up */ 1166 x = (x + 1) & ~1; /* round up */
1511 width = end - x; 1167 width = end - x;
1512 } 1168 }
1513 1169
1514 if (zr->buffer.depth == 24) { 1170 if (zr->vbuf_depth == 24) {
1515 end = (x + width) & ~3; /* round down */ 1171 end = (x + width) & ~3; /* round down */
1516 x = (x + 3) & ~3; /* round up */ 1172 x = (x + 3) & ~3; /* round up */
1517 width = end - x; 1173 width = end - x;
@@ -1527,8 +1183,8 @@ setup_window (struct file *file,
1527 width > BUZ_MAX_WIDTH || height > BUZ_MAX_HEIGHT) { 1183 width > BUZ_MAX_WIDTH || height > BUZ_MAX_HEIGHT) {
1528 dprintk(1, 1184 dprintk(1,
1529 KERN_ERR 1185 KERN_ERR
1530 "%s: setup_window() - width = %d or height = %d invalid\n", 1186 "%s: %s - width = %d or height = %d invalid\n",
1531 ZR_DEVNAME(zr), width, height); 1187 ZR_DEVNAME(zr), __func__, width, height);
1532 return -EINVAL; 1188 return -EINVAL;
1533 } 1189 }
1534 1190
@@ -1566,20 +1222,20 @@ setup_window (struct file *file,
1566 } 1222 }
1567 } else if (clipcount > 0) { 1223 } else if (clipcount > 0) {
1568 /* write our own bitmap from the clips */ 1224 /* write our own bitmap from the clips */
1569 vcp = vmalloc(sizeof(struct video_clip) * (clipcount + 4)); 1225 vcp = vmalloc(sizeof(struct v4l2_clip) * (clipcount + 4));
1570 if (vcp == NULL) { 1226 if (vcp == NULL) {
1571 dprintk(1, 1227 dprintk(1,
1572 KERN_ERR 1228 KERN_ERR
1573 "%s: setup_window() - Alloc of clip mask failed\n", 1229 "%s: %s - Alloc of clip mask failed\n",
1574 ZR_DEVNAME(zr)); 1230 ZR_DEVNAME(zr), __func__);
1575 return -ENOMEM; 1231 return -ENOMEM;
1576 } 1232 }
1577 if (copy_from_user 1233 if (copy_from_user
1578 (vcp, clips, sizeof(struct video_clip) * clipcount)) { 1234 (vcp, clips, sizeof(struct v4l2_clip) * clipcount)) {
1579 vfree(vcp); 1235 vfree(vcp);
1580 return -EFAULT; 1236 return -EFAULT;
1581 } 1237 }
1582 write_overlay_mask(file, vcp, clipcount); 1238 write_overlay_mask(fh, vcp, clipcount);
1583 vfree(vcp); 1239 vfree(vcp);
1584 } 1240 }
1585 1241
@@ -1595,11 +1251,8 @@ setup_window (struct file *file,
1595 return wait_grab_pending(zr); 1251 return wait_grab_pending(zr);
1596} 1252}
1597 1253
1598static int 1254static int setup_overlay(struct zoran_fh *fh, int on)
1599setup_overlay (struct file *file,
1600 int on)
1601{ 1255{
1602 struct zoran_fh *fh = file->private_data;
1603 struct zoran *zr = fh->zr; 1256 struct zoran *zr = fh->zr;
1604 1257
1605 /* If there is nothing to do, return immediatly */ 1258 /* If there is nothing to do, return immediatly */
@@ -1612,16 +1265,16 @@ setup_overlay (struct file *file,
1612 fh->overlay_active == ZORAN_FREE) { 1265 fh->overlay_active == ZORAN_FREE) {
1613 dprintk(1, 1266 dprintk(1,
1614 KERN_ERR 1267 KERN_ERR
1615 "%s: setup_overlay() - overlay is already active for another session\n", 1268 "%s: %s - overlay is already active for another session\n",
1616 ZR_DEVNAME(zr)); 1269 ZR_DEVNAME(zr), __func__);
1617 return -EBUSY; 1270 return -EBUSY;
1618 } 1271 }
1619 if (!on && zr->overlay_active != ZORAN_FREE && 1272 if (!on && zr->overlay_active != ZORAN_FREE &&
1620 fh->overlay_active == ZORAN_FREE) { 1273 fh->overlay_active == ZORAN_FREE) {
1621 dprintk(1, 1274 dprintk(1,
1622 KERN_ERR 1275 KERN_ERR
1623 "%s: setup_overlay() - you cannot cancel someone else's session\n", 1276 "%s: %s - you cannot cancel someone else's session\n",
1624 ZR_DEVNAME(zr)); 1277 ZR_DEVNAME(zr), __func__);
1625 return -EPERM; 1278 return -EPERM;
1626 } 1279 }
1627 1280
@@ -1634,18 +1287,18 @@ setup_overlay (struct file *file,
1634 zr36057_overlay(zr, 0); 1287 zr36057_overlay(zr, 0);
1635 zr->overlay_mask = NULL; 1288 zr->overlay_mask = NULL;
1636 } else { 1289 } else {
1637 if (!zr->buffer.base || !fh->overlay_settings.is_set) { 1290 if (!zr->vbuf_base || !fh->overlay_settings.is_set) {
1638 dprintk(1, 1291 dprintk(1,
1639 KERN_ERR 1292 KERN_ERR
1640 "%s: setup_overlay() - buffer or window not set\n", 1293 "%s: %s - buffer or window not set\n",
1641 ZR_DEVNAME(zr)); 1294 ZR_DEVNAME(zr), __func__);
1642 return -EINVAL; 1295 return -EINVAL;
1643 } 1296 }
1644 if (!fh->overlay_settings.format) { 1297 if (!fh->overlay_settings.format) {
1645 dprintk(1, 1298 dprintk(1,
1646 KERN_ERR 1299 KERN_ERR
1647 "%s: setup_overlay() - no overlay format set\n", 1300 "%s: %s - no overlay format set\n",
1648 ZR_DEVNAME(zr)); 1301 ZR_DEVNAME(zr), __func__);
1649 return -EINVAL; 1302 return -EINVAL;
1650 } 1303 }
1651 zr->overlay_active = fh->overlay_active = ZORAN_LOCKED; 1304 zr->overlay_active = fh->overlay_active = ZORAN_LOCKED;
@@ -1662,41 +1315,47 @@ setup_overlay (struct file *file,
1662 return wait_grab_pending(zr); 1315 return wait_grab_pending(zr);
1663} 1316}
1664 1317
1665 /* get the status of a buffer in the clients buffer queue */ 1318/* get the status of a buffer in the clients buffer queue */
1666static int 1319static int zoran_v4l2_buffer_status(struct zoran_fh *fh,
1667zoran_v4l2_buffer_status (struct file *file, 1320 struct v4l2_buffer *buf, int num)
1668 struct v4l2_buffer *buf,
1669 int num)
1670{ 1321{
1671 struct zoran_fh *fh = file->private_data;
1672 struct zoran *zr = fh->zr; 1322 struct zoran *zr = fh->zr;
1323 unsigned long flags;
1673 1324
1674 buf->flags = V4L2_BUF_FLAG_MAPPED; 1325 buf->flags = V4L2_BUF_FLAG_MAPPED;
1675 1326
1676 switch (fh->map_mode) { 1327 switch (fh->map_mode) {
1677 case ZORAN_MAP_MODE_RAW: 1328 case ZORAN_MAP_MODE_RAW:
1678
1679 /* check range */ 1329 /* check range */
1680 if (num < 0 || num >= fh->v4l_buffers.num_buffers || 1330 if (num < 0 || num >= fh->buffers.num_buffers ||
1681 !fh->v4l_buffers.allocated) { 1331 !fh->buffers.allocated) {
1682 dprintk(1, 1332 dprintk(1,
1683 KERN_ERR 1333 KERN_ERR
1684 "%s: v4l2_buffer_status() - wrong number or buffers not allocated\n", 1334 "%s: %s - wrong number or buffers not allocated\n",
1685 ZR_DEVNAME(zr)); 1335 ZR_DEVNAME(zr), __func__);
1686 return -EINVAL; 1336 return -EINVAL;
1687 } 1337 }
1688 1338
1339 spin_lock_irqsave(&zr->spinlock, flags);
1340 dprintk(3,
1341 KERN_DEBUG
1342 "%s: %s() - raw active=%c, buffer %d: state=%c, map=%c\n",
1343 ZR_DEVNAME(zr), __func__,
1344 "FAL"[fh->buffers.active], num,
1345 "UPMD"[zr->v4l_buffers.buffer[num].state],
1346 fh->buffers.buffer[num].map ? 'Y' : 'N');
1347 spin_unlock_irqrestore(&zr->spinlock, flags);
1348
1689 buf->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 1349 buf->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1690 buf->length = fh->v4l_buffers.buffer_size; 1350 buf->length = fh->buffers.buffer_size;
1691 1351
1692 /* get buffer */ 1352 /* get buffer */
1693 buf->bytesused = fh->v4l_buffers.buffer[num].bs.length; 1353 buf->bytesused = fh->buffers.buffer[num].bs.length;
1694 if (fh->v4l_buffers.buffer[num].state == BUZ_STATE_DONE || 1354 if (fh->buffers.buffer[num].state == BUZ_STATE_DONE ||
1695 fh->v4l_buffers.buffer[num].state == BUZ_STATE_USER) { 1355 fh->buffers.buffer[num].state == BUZ_STATE_USER) {
1696 buf->sequence = fh->v4l_buffers.buffer[num].bs.seq; 1356 buf->sequence = fh->buffers.buffer[num].bs.seq;
1697 buf->flags |= V4L2_BUF_FLAG_DONE; 1357 buf->flags |= V4L2_BUF_FLAG_DONE;
1698 buf->timestamp = 1358 buf->timestamp = fh->buffers.buffer[num].bs.timestamp;
1699 fh->v4l_buffers.buffer[num].bs.timestamp;
1700 } else { 1359 } else {
1701 buf->flags |= V4L2_BUF_FLAG_QUEUED; 1360 buf->flags |= V4L2_BUF_FLAG_QUEUED;
1702 } 1361 }
@@ -1712,28 +1371,26 @@ zoran_v4l2_buffer_status (struct file *file,
1712 case ZORAN_MAP_MODE_JPG_PLAY: 1371 case ZORAN_MAP_MODE_JPG_PLAY:
1713 1372
1714 /* check range */ 1373 /* check range */
1715 if (num < 0 || num >= fh->jpg_buffers.num_buffers || 1374 if (num < 0 || num >= fh->buffers.num_buffers ||
1716 !fh->jpg_buffers.allocated) { 1375 !fh->buffers.allocated) {
1717 dprintk(1, 1376 dprintk(1,
1718 KERN_ERR 1377 KERN_ERR
1719 "%s: v4l2_buffer_status() - wrong number or buffers not allocated\n", 1378 "%s: %s - wrong number or buffers not allocated\n",
1720 ZR_DEVNAME(zr)); 1379 ZR_DEVNAME(zr), __func__);
1721 return -EINVAL; 1380 return -EINVAL;
1722 } 1381 }
1723 1382
1724 buf->type = (fh->map_mode == ZORAN_MAP_MODE_JPG_REC) ? 1383 buf->type = (fh->map_mode == ZORAN_MAP_MODE_JPG_REC) ?
1725 V4L2_BUF_TYPE_VIDEO_CAPTURE : 1384 V4L2_BUF_TYPE_VIDEO_CAPTURE :
1726 V4L2_BUF_TYPE_VIDEO_OUTPUT; 1385 V4L2_BUF_TYPE_VIDEO_OUTPUT;
1727 buf->length = fh->jpg_buffers.buffer_size; 1386 buf->length = fh->buffers.buffer_size;
1728 1387
1729 /* these variables are only written after frame has been captured */ 1388 /* these variables are only written after frame has been captured */
1730 if (fh->jpg_buffers.buffer[num].state == BUZ_STATE_DONE || 1389 if (fh->buffers.buffer[num].state == BUZ_STATE_DONE ||
1731 fh->jpg_buffers.buffer[num].state == BUZ_STATE_USER) { 1390 fh->buffers.buffer[num].state == BUZ_STATE_USER) {
1732 buf->sequence = fh->jpg_buffers.buffer[num].bs.seq; 1391 buf->sequence = fh->buffers.buffer[num].bs.seq;
1733 buf->timestamp = 1392 buf->timestamp = fh->buffers.buffer[num].bs.timestamp;
1734 fh->jpg_buffers.buffer[num].bs.timestamp; 1393 buf->bytesused = fh->buffers.buffer[num].bs.length;
1735 buf->bytesused =
1736 fh->jpg_buffers.buffer[num].bs.length;
1737 buf->flags |= V4L2_BUF_FLAG_DONE; 1394 buf->flags |= V4L2_BUF_FLAG_DONE;
1738 } else { 1395 } else {
1739 buf->flags |= V4L2_BUF_FLAG_QUEUED; 1396 buf->flags |= V4L2_BUF_FLAG_QUEUED;
@@ -1741,14 +1398,11 @@ zoran_v4l2_buffer_status (struct file *file,
1741 1398
1742 /* which fields are these? */ 1399 /* which fields are these? */
1743 if (fh->jpg_settings.TmpDcm != 1) 1400 if (fh->jpg_settings.TmpDcm != 1)
1744 buf->field = 1401 buf->field = fh->jpg_settings.odd_even ?
1745 fh->jpg_settings. 1402 V4L2_FIELD_TOP : V4L2_FIELD_BOTTOM;
1746 odd_even ? V4L2_FIELD_TOP : V4L2_FIELD_BOTTOM;
1747 else 1403 else
1748 buf->field = 1404 buf->field = fh->jpg_settings.odd_even ?
1749 fh->jpg_settings. 1405 V4L2_FIELD_SEQ_TB : V4L2_FIELD_SEQ_BT;
1750 odd_even ? V4L2_FIELD_SEQ_TB :
1751 V4L2_FIELD_SEQ_BT;
1752 1406
1753 break; 1407 break;
1754 1408
@@ -1756,8 +1410,8 @@ zoran_v4l2_buffer_status (struct file *file,
1756 1410
1757 dprintk(5, 1411 dprintk(5,
1758 KERN_ERR 1412 KERN_ERR
1759 "%s: v4l2_buffer_status() - invalid buffer type|map_mode (%d|%d)\n", 1413 "%s: %s - invalid buffer type|map_mode (%d|%d)\n",
1760 ZR_DEVNAME(zr), buf->type, fh->map_mode); 1414 ZR_DEVNAME(zr), __func__, buf->type, fh->map_mode);
1761 return -EINVAL; 1415 return -EINVAL;
1762 } 1416 }
1763 1417
@@ -1770,81 +1424,55 @@ zoran_v4l2_buffer_status (struct file *file,
1770 1424
1771static int 1425static int
1772zoran_set_norm (struct zoran *zr, 1426zoran_set_norm (struct zoran *zr,
1773 int norm) /* VIDEO_MODE_* */ 1427 v4l2_std_id norm)
1774{ 1428{
1775 int norm_encoder, on; 1429 int on;
1776 1430
1777 if (zr->v4l_buffers.active != ZORAN_FREE || 1431 if (zr->v4l_buffers.active != ZORAN_FREE ||
1778 zr->jpg_buffers.active != ZORAN_FREE) { 1432 zr->jpg_buffers.active != ZORAN_FREE) {
1779 dprintk(1, 1433 dprintk(1,
1780 KERN_WARNING 1434 KERN_WARNING
1781 "%s: set_norm() called while in playback/capture mode\n", 1435 "%s: %s called while in playback/capture mode\n",
1782 ZR_DEVNAME(zr)); 1436 ZR_DEVNAME(zr), __func__);
1783 return -EBUSY; 1437 return -EBUSY;
1784 } 1438 }
1785 1439
1786 if (lock_norm && norm != zr->norm) { 1440 if (!(norm & zr->card.norms)) {
1787 if (lock_norm > 1) {
1788 dprintk(1,
1789 KERN_WARNING
1790 "%s: set_norm() - TV standard is locked, can not switch norm\n",
1791 ZR_DEVNAME(zr));
1792 return -EPERM;
1793 } else {
1794 dprintk(1,
1795 KERN_WARNING
1796 "%s: set_norm() - TV standard is locked, norm was not changed\n",
1797 ZR_DEVNAME(zr));
1798 norm = zr->norm;
1799 }
1800 }
1801
1802 if (norm != VIDEO_MODE_AUTO &&
1803 (norm < 0 || norm >= zr->card.norms ||
1804 !zr->card.tvn[norm])) {
1805 dprintk(1, 1441 dprintk(1,
1806 KERN_ERR "%s: set_norm() - unsupported norm %d\n", 1442 KERN_ERR "%s: %s - unsupported norm %llx\n",
1807 ZR_DEVNAME(zr), norm); 1443 ZR_DEVNAME(zr), __func__, norm);
1808 return -EINVAL; 1444 return -EINVAL;
1809 } 1445 }
1810 1446
1811 if (norm == VIDEO_MODE_AUTO) { 1447 if (norm == V4L2_STD_ALL) {
1812 int status; 1448 int status = 0;
1449 v4l2_std_id std = 0;
1813 1450
1814 /* if we have autodetect, ... */ 1451 decoder_call(zr, video, querystd, &std);
1815 struct video_decoder_capability caps; 1452 decoder_call(zr, tuner, s_std, std);
1816 decoder_command(zr, DECODER_GET_CAPABILITIES, &caps);
1817 if (!(caps.flags & VIDEO_DECODER_AUTO)) {
1818 dprintk(1, KERN_ERR "%s: norm=auto unsupported\n",
1819 ZR_DEVNAME(zr));
1820 return -EINVAL;
1821 }
1822
1823 decoder_command(zr, DECODER_SET_NORM, &norm);
1824 1453
1825 /* let changes come into effect */ 1454 /* let changes come into effect */
1826 ssleep(2); 1455 ssleep(2);
1827 1456
1828 decoder_command(zr, DECODER_GET_STATUS, &status); 1457 decoder_call(zr, video, g_input_status, &status);
1829 if (!(status & DECODER_STATUS_GOOD)) { 1458 if (status & V4L2_IN_ST_NO_SIGNAL) {
1830 dprintk(1, 1459 dprintk(1,
1831 KERN_ERR 1460 KERN_ERR
1832 "%s: set_norm() - no norm detected\n", 1461 "%s: %s - no norm detected\n",
1833 ZR_DEVNAME(zr)); 1462 ZR_DEVNAME(zr), __func__);
1834 /* reset norm */ 1463 /* reset norm */
1835 decoder_command(zr, DECODER_SET_NORM, &zr->norm); 1464 decoder_call(zr, tuner, s_std, zr->norm);
1836 return -EIO; 1465 return -EIO;
1837 } 1466 }
1838 1467
1839 if (status & DECODER_STATUS_NTSC) 1468 norm = std;
1840 norm = VIDEO_MODE_NTSC;
1841 else if (status & DECODER_STATUS_SECAM)
1842 norm = VIDEO_MODE_SECAM;
1843 else
1844 norm = VIDEO_MODE_PAL;
1845 } 1469 }
1846 zr->timing = zr->card.tvn[norm]; 1470 if (norm & V4L2_STD_SECAM)
1847 norm_encoder = norm; 1471 zr->timing = zr->card.tvn[2];
1472 else if (norm & V4L2_STD_NTSC)
1473 zr->timing = zr->card.tvn[1];
1474 else
1475 zr->timing = zr->card.tvn[0];
1848 1476
1849 /* We switch overlay off and on since a change in the 1477 /* We switch overlay off and on since a change in the
1850 * norm needs different VFE settings */ 1478 * norm needs different VFE settings */
@@ -1852,8 +1480,8 @@ zoran_set_norm (struct zoran *zr,
1852 if (on) 1480 if (on)
1853 zr36057_overlay(zr, 0); 1481 zr36057_overlay(zr, 0);
1854 1482
1855 decoder_command(zr, DECODER_SET_NORM, &norm); 1483 decoder_call(zr, tuner, s_std, norm);
1856 encoder_command(zr, ENCODER_SET_NORM, &norm_encoder); 1484 encoder_call(zr, video, s_std_output, norm);
1857 1485
1858 if (on) 1486 if (on)
1859 zr36057_overlay(zr, 1); 1487 zr36057_overlay(zr, 1);
@@ -1868,7 +1496,7 @@ static int
1868zoran_set_input (struct zoran *zr, 1496zoran_set_input (struct zoran *zr,
1869 int input) 1497 int input)
1870{ 1498{
1871 int realinput; 1499 struct v4l2_routing route = { 0, 0 };
1872 1500
1873 if (input == zr->input) { 1501 if (input == zr->input) {
1874 return 0; 1502 return 0;
@@ -1878,23 +1506,23 @@ zoran_set_input (struct zoran *zr,
1878 zr->jpg_buffers.active != ZORAN_FREE) { 1506 zr->jpg_buffers.active != ZORAN_FREE) {
1879 dprintk(1, 1507 dprintk(1,
1880 KERN_WARNING 1508 KERN_WARNING
1881 "%s: set_input() called while in playback/capture mode\n", 1509 "%s: %s called while in playback/capture mode\n",
1882 ZR_DEVNAME(zr)); 1510 ZR_DEVNAME(zr), __func__);
1883 return -EBUSY; 1511 return -EBUSY;
1884 } 1512 }
1885 1513
1886 if (input < 0 || input >= zr->card.inputs) { 1514 if (input < 0 || input >= zr->card.inputs) {
1887 dprintk(1, 1515 dprintk(1,
1888 KERN_ERR 1516 KERN_ERR
1889 "%s: set_input() - unnsupported input %d\n", 1517 "%s: %s - unnsupported input %d\n",
1890 ZR_DEVNAME(zr), input); 1518 ZR_DEVNAME(zr), __func__, input);
1891 return -EINVAL; 1519 return -EINVAL;
1892 } 1520 }
1893 1521
1894 realinput = zr->card.input[input].muxsel; 1522 route.input = zr->card.input[input].muxsel;
1895 zr->input = input; 1523 zr->input = input;
1896 1524
1897 decoder_command(zr, DECODER_SET_INPUT, &realinput); 1525 decoder_call(zr, video, s_routing, &route);
1898 1526
1899 return 0; 1527 return 0;
1900} 1528}
@@ -1903,410 +1531,14 @@ zoran_set_input (struct zoran *zr,
1903 * ioctl routine 1531 * ioctl routine
1904 */ 1532 */
1905 1533
1906static long zoran_do_ioctl(struct file *file, unsigned int cmd, void *arg) 1534#ifdef CONFIG_VIDEO_V4L1_COMPAT
1535static long zoran_default(struct file *file, void *__fh, int cmd, void *arg)
1907{ 1536{
1908 struct zoran_fh *fh = file->private_data; 1537 struct zoran_fh *fh = __fh;
1909 struct zoran *zr = fh->zr; 1538 struct zoran *zr = fh->zr;
1910 /* CAREFUL: used in multiple places here */
1911 struct zoran_jpg_settings settings; 1539 struct zoran_jpg_settings settings;
1912 1540
1913 /* we might have older buffers lying around... We don't want
1914 * to wait, but we do want to try cleaning them up ASAP. So
1915 * we try to obtain the lock and free them. If that fails, we
1916 * don't do anything and wait for the next turn. In the end,
1917 * zoran_close() or a new allocation will still free them...
1918 * This is just a 'the sooner the better' extra 'feature'
1919 *
1920 * We don't free the buffers right on munmap() because that
1921 * causes oopses (kfree() inside munmap() oopses for no
1922 * apparent reason - it's also not reproduceable in any way,
1923 * but moving the free code outside the munmap() handler fixes
1924 * all this... If someone knows why, please explain me (Ronald)
1925 */
1926 if (mutex_trylock(&zr->resource_lock)) {
1927 /* we obtained it! Let's try to free some things */
1928 if (fh->jpg_buffers.ready_to_be_freed)
1929 jpg_fbuffer_free(file);
1930 if (fh->v4l_buffers.ready_to_be_freed)
1931 v4l_fbuffer_free(file);
1932
1933 mutex_unlock(&zr->resource_lock);
1934 }
1935
1936 switch (cmd) { 1541 switch (cmd) {
1937
1938 case VIDIOCGCAP:
1939 {
1940 struct video_capability *vcap = arg;
1941
1942 dprintk(3, KERN_DEBUG "%s: VIDIOCGCAP\n", ZR_DEVNAME(zr));
1943
1944 memset(vcap, 0, sizeof(struct video_capability));
1945 strncpy(vcap->name, ZR_DEVNAME(zr), sizeof(vcap->name)-1);
1946 vcap->type = ZORAN_VID_TYPE;
1947
1948 vcap->channels = zr->card.inputs;
1949 vcap->audios = 0;
1950 mutex_lock(&zr->resource_lock);
1951 vcap->maxwidth = BUZ_MAX_WIDTH;
1952 vcap->maxheight = BUZ_MAX_HEIGHT;
1953 vcap->minwidth = BUZ_MIN_WIDTH;
1954 vcap->minheight = BUZ_MIN_HEIGHT;
1955 mutex_unlock(&zr->resource_lock);
1956
1957 return 0;
1958 }
1959 break;
1960
1961 case VIDIOCGCHAN:
1962 {
1963 struct video_channel *vchan = arg;
1964 int channel = vchan->channel;
1965
1966 dprintk(3, KERN_DEBUG "%s: VIDIOCGCHAN - channel=%d\n",
1967 ZR_DEVNAME(zr), vchan->channel);
1968
1969 memset(vchan, 0, sizeof(struct video_channel));
1970 if (channel > zr->card.inputs || channel < 0) {
1971 dprintk(1,
1972 KERN_ERR
1973 "%s: VIDIOCGCHAN on not existing channel %d\n",
1974 ZR_DEVNAME(zr), channel);
1975 return -EINVAL;
1976 }
1977
1978 strcpy(vchan->name, zr->card.input[channel].name);
1979
1980 vchan->tuners = 0;
1981 vchan->flags = 0;
1982 vchan->type = VIDEO_TYPE_CAMERA;
1983 mutex_lock(&zr->resource_lock);
1984 vchan->norm = zr->norm;
1985 mutex_unlock(&zr->resource_lock);
1986 vchan->channel = channel;
1987
1988 return 0;
1989 }
1990 break;
1991
1992 /* RJ: the documentation at http://roadrunner.swansea.linux.org.uk/v4lapi.shtml says:
1993 *
1994 * * "The VIDIOCSCHAN ioctl takes an integer argument and switches the capture to this input."
1995 * * ^^^^^^^
1996 * * The famos BTTV driver has it implemented with a struct video_channel argument
1997 * * and we follow it for compatibility reasons
1998 * *
1999 * * BTW: this is the only way the user can set the norm!
2000 */
2001
2002 case VIDIOCSCHAN:
2003 {
2004 struct video_channel *vchan = arg;
2005 int res;
2006
2007 dprintk(3,
2008 KERN_DEBUG
2009 "%s: VIDIOCSCHAN - channel=%d, norm=%d\n",
2010 ZR_DEVNAME(zr), vchan->channel, vchan->norm);
2011
2012 mutex_lock(&zr->resource_lock);
2013 if ((res = zoran_set_input(zr, vchan->channel)))
2014 goto schan_unlock_and_return;
2015 if ((res = zoran_set_norm(zr, vchan->norm)))
2016 goto schan_unlock_and_return;
2017
2018 /* Make sure the changes come into effect */
2019 res = wait_grab_pending(zr);
2020 schan_unlock_and_return:
2021 mutex_unlock(&zr->resource_lock);
2022 return res;
2023 }
2024 break;
2025
2026 case VIDIOCGPICT:
2027 {
2028 struct video_picture *vpict = arg;
2029
2030 dprintk(3, KERN_DEBUG "%s: VIDIOCGPICT\n", ZR_DEVNAME(zr));
2031
2032 memset(vpict, 0, sizeof(struct video_picture));
2033 mutex_lock(&zr->resource_lock);
2034 vpict->hue = zr->hue;
2035 vpict->brightness = zr->brightness;
2036 vpict->contrast = zr->contrast;
2037 vpict->colour = zr->saturation;
2038 if (fh->overlay_settings.format) {
2039 vpict->depth = fh->overlay_settings.format->depth;
2040 vpict->palette = fh->overlay_settings.format->palette;
2041 } else {
2042 vpict->depth = 0;
2043 }
2044 mutex_unlock(&zr->resource_lock);
2045
2046 return 0;
2047 }
2048 break;
2049
2050 case VIDIOCSPICT:
2051 {
2052 struct video_picture *vpict = arg;
2053 int i;
2054
2055 dprintk(3,
2056 KERN_DEBUG
2057 "%s: VIDIOCSPICT - bri=%d, hue=%d, col=%d, con=%d, dep=%d, pal=%d\n",
2058 ZR_DEVNAME(zr), vpict->brightness, vpict->hue,
2059 vpict->colour, vpict->contrast, vpict->depth,
2060 vpict->palette);
2061
2062 for (i = 0; i < NUM_FORMATS; i++) {
2063 const struct zoran_format *fmt = &zoran_formats[i];
2064
2065 if (fmt->palette != -1 &&
2066 fmt->flags & ZORAN_FORMAT_OVERLAY &&
2067 fmt->palette == vpict->palette &&
2068 fmt->depth == vpict->depth)
2069 break;
2070 }
2071 if (i == NUM_FORMATS) {
2072 dprintk(1,
2073 KERN_ERR
2074 "%s: VIDIOCSPICT - Invalid palette %d\n",
2075 ZR_DEVNAME(zr), vpict->palette);
2076 return -EINVAL;
2077 }
2078
2079 mutex_lock(&zr->resource_lock);
2080
2081 decoder_command(zr, DECODER_SET_PICTURE, vpict);
2082
2083 zr->hue = vpict->hue;
2084 zr->contrast = vpict->contrast;
2085 zr->saturation = vpict->colour;
2086 zr->brightness = vpict->brightness;
2087
2088 fh->overlay_settings.format = &zoran_formats[i];
2089
2090 mutex_unlock(&zr->resource_lock);
2091
2092 return 0;
2093 }
2094 break;
2095
2096 case VIDIOCCAPTURE:
2097 {
2098 int *on = arg, res;
2099
2100 dprintk(3, KERN_DEBUG "%s: VIDIOCCAPTURE - on=%d\n",
2101 ZR_DEVNAME(zr), *on);
2102
2103 mutex_lock(&zr->resource_lock);
2104 res = setup_overlay(file, *on);
2105 mutex_unlock(&zr->resource_lock);
2106
2107 return res;
2108 }
2109 break;
2110
2111 case VIDIOCGWIN:
2112 {
2113 struct video_window *vwin = arg;
2114
2115 dprintk(3, KERN_DEBUG "%s: VIDIOCGWIN\n", ZR_DEVNAME(zr));
2116
2117 memset(vwin, 0, sizeof(struct video_window));
2118 mutex_lock(&zr->resource_lock);
2119 vwin->x = fh->overlay_settings.x;
2120 vwin->y = fh->overlay_settings.y;
2121 vwin->width = fh->overlay_settings.width;
2122 vwin->height = fh->overlay_settings.height;
2123 mutex_unlock(&zr->resource_lock);
2124 vwin->clipcount = 0;
2125 return 0;
2126 }
2127 break;
2128
2129 case VIDIOCSWIN:
2130 {
2131 struct video_window *vwin = arg;
2132 int res;
2133
2134 dprintk(3,
2135 KERN_DEBUG
2136 "%s: VIDIOCSWIN - x=%d, y=%d, w=%d, h=%d, clipcount=%d\n",
2137 ZR_DEVNAME(zr), vwin->x, vwin->y, vwin->width,
2138 vwin->height, vwin->clipcount);
2139
2140 mutex_lock(&zr->resource_lock);
2141 res =
2142 setup_window(file, vwin->x, vwin->y, vwin->width,
2143 vwin->height, vwin->clips,
2144 vwin->clipcount, NULL);
2145 mutex_unlock(&zr->resource_lock);
2146
2147 return res;
2148 }
2149 break;
2150
2151 case VIDIOCGFBUF:
2152 {
2153 struct video_buffer *vbuf = arg;
2154
2155 dprintk(3, KERN_DEBUG "%s: VIDIOCGFBUF\n", ZR_DEVNAME(zr));
2156
2157 mutex_lock(&zr->resource_lock);
2158 *vbuf = zr->buffer;
2159 mutex_unlock(&zr->resource_lock);
2160 return 0;
2161 }
2162 break;
2163
2164 case VIDIOCSFBUF:
2165 {
2166 struct video_buffer *vbuf = arg;
2167 int i, res = 0;
2168
2169 dprintk(3,
2170 KERN_DEBUG
2171 "%s: VIDIOCSFBUF - base=%p, w=%d, h=%d, depth=%d, bpl=%d\n",
2172 ZR_DEVNAME(zr), vbuf->base, vbuf->width,
2173 vbuf->height, vbuf->depth, vbuf->bytesperline);
2174
2175 for (i = 0; i < NUM_FORMATS; i++)
2176 if (zoran_formats[i].depth == vbuf->depth)
2177 break;
2178 if (i == NUM_FORMATS) {
2179 dprintk(1,
2180 KERN_ERR
2181 "%s: VIDIOCSFBUF - invalid fbuf depth %d\n",
2182 ZR_DEVNAME(zr), vbuf->depth);
2183 return -EINVAL;
2184 }
2185
2186 mutex_lock(&zr->resource_lock);
2187 res =
2188 setup_fbuffer(file, vbuf->base, &zoran_formats[i],
2189 vbuf->width, vbuf->height,
2190 vbuf->bytesperline);
2191 mutex_unlock(&zr->resource_lock);
2192
2193 return res;
2194 }
2195 break;
2196
2197 case VIDIOCSYNC:
2198 {
2199 int *frame = arg, res;
2200
2201 dprintk(3, KERN_DEBUG "%s: VIDIOCSYNC - frame=%d\n",
2202 ZR_DEVNAME(zr), *frame);
2203
2204 mutex_lock(&zr->resource_lock);
2205 res = v4l_sync(file, *frame);
2206 mutex_unlock(&zr->resource_lock);
2207 if (!res)
2208 zr->v4l_sync_tail++;
2209 return res;
2210 }
2211 break;
2212
2213 case VIDIOCMCAPTURE:
2214 {
2215 struct video_mmap *vmap = arg;
2216 int res;
2217
2218 dprintk(3,
2219 KERN_DEBUG
2220 "%s: VIDIOCMCAPTURE - frame=%d, geom=%dx%d, fmt=%d\n",
2221 ZR_DEVNAME(zr), vmap->frame, vmap->width, vmap->height,
2222 vmap->format);
2223
2224 mutex_lock(&zr->resource_lock);
2225 res = v4l_grab(file, vmap);
2226 mutex_unlock(&zr->resource_lock);
2227 return res;
2228 }
2229 break;
2230
2231 case VIDIOCGMBUF:
2232 {
2233 struct video_mbuf *vmbuf = arg;
2234 int i, res = 0;
2235
2236 dprintk(3, KERN_DEBUG "%s: VIDIOCGMBUF\n", ZR_DEVNAME(zr));
2237
2238 vmbuf->size =
2239 fh->v4l_buffers.num_buffers *
2240 fh->v4l_buffers.buffer_size;
2241 vmbuf->frames = fh->v4l_buffers.num_buffers;
2242 for (i = 0; i < vmbuf->frames; i++) {
2243 vmbuf->offsets[i] =
2244 i * fh->v4l_buffers.buffer_size;
2245 }
2246
2247 mutex_lock(&zr->resource_lock);
2248
2249 if (fh->jpg_buffers.allocated || fh->v4l_buffers.allocated) {
2250 dprintk(1,
2251 KERN_ERR
2252 "%s: VIDIOCGMBUF - buffers already allocated\n",
2253 ZR_DEVNAME(zr));
2254 res = -EINVAL;
2255 goto v4l1reqbuf_unlock_and_return;
2256 }
2257
2258 if (v4l_fbuffer_alloc(file)) {
2259 res = -ENOMEM;
2260 goto v4l1reqbuf_unlock_and_return;
2261 }
2262
2263 /* The next mmap will map the V4L buffers */
2264 fh->map_mode = ZORAN_MAP_MODE_RAW;
2265 v4l1reqbuf_unlock_and_return:
2266 mutex_unlock(&zr->resource_lock);
2267
2268 return res;
2269 }
2270 break;
2271
2272 case VIDIOCGUNIT:
2273 {
2274 struct video_unit *vunit = arg;
2275
2276 dprintk(3, KERN_DEBUG "%s: VIDIOCGUNIT\n", ZR_DEVNAME(zr));
2277
2278 vunit->video = zr->video_dev->minor;
2279 vunit->vbi = VIDEO_NO_UNIT;
2280 vunit->radio = VIDEO_NO_UNIT;
2281 vunit->audio = VIDEO_NO_UNIT;
2282 vunit->teletext = VIDEO_NO_UNIT;
2283
2284 return 0;
2285 }
2286 break;
2287
2288 /*
2289 * RJ: In principal we could support subcaptures for V4L grabbing.
2290 * Not even the famous BTTV driver has them, however.
2291 * If there should be a strong demand, one could consider
2292 * to implement them.
2293 */
2294 case VIDIOCGCAPTURE:
2295 {
2296 dprintk(3, KERN_ERR "%s: VIDIOCGCAPTURE not supported\n",
2297 ZR_DEVNAME(zr));
2298 return -EINVAL;
2299 }
2300 break;
2301
2302 case VIDIOCSCAPTURE:
2303 {
2304 dprintk(3, KERN_ERR "%s: VIDIOCSCAPTURE not supported\n",
2305 ZR_DEVNAME(zr));
2306 return -EINVAL;
2307 }
2308 break;
2309
2310 case BUZIOC_G_PARAMS: 1542 case BUZIOC_G_PARAMS:
2311 { 1543 {
2312 struct zoran_params *bparams = arg; 1544 struct zoran_params *bparams = arg;
@@ -2319,7 +1551,13 @@ static long zoran_do_ioctl(struct file *file, unsigned int cmd, void *arg)
2319 1551
2320 mutex_lock(&zr->resource_lock); 1552 mutex_lock(&zr->resource_lock);
2321 1553
2322 bparams->norm = zr->norm; 1554 if (zr->norm & V4L2_STD_NTSC)
1555 bparams->norm = VIDEO_MODE_NTSC;
1556 else if (zr->norm & V4L2_STD_PAL)
1557 bparams->norm = VIDEO_MODE_PAL;
1558 else
1559 bparams->norm = VIDEO_MODE_SECAM;
1560
2323 bparams->input = zr->input; 1561 bparams->input = zr->input;
2324 1562
2325 bparams->decimation = fh->jpg_settings.decimation; 1563 bparams->decimation = fh->jpg_settings.decimation;
@@ -2352,7 +1590,6 @@ static long zoran_do_ioctl(struct file *file, unsigned int cmd, void *arg)
2352 1590
2353 return 0; 1591 return 0;
2354 } 1592 }
2355 break;
2356 1593
2357 case BUZIOC_S_PARAMS: 1594 case BUZIOC_S_PARAMS:
2358 { 1595 {
@@ -2395,18 +1632,17 @@ static long zoran_do_ioctl(struct file *file, unsigned int cmd, void *arg)
2395 1632
2396 /* Check the params first before overwriting our 1633 /* Check the params first before overwriting our
2397 * nternal values */ 1634 * nternal values */
2398 if (zoran_check_jpg_settings(zr, &settings)) { 1635 if (zoran_check_jpg_settings(zr, &settings, 0)) {
2399 res = -EINVAL; 1636 res = -EINVAL;
2400 goto sparams_unlock_and_return; 1637 goto sparams_unlock_and_return;
2401 } 1638 }
2402 1639
2403 fh->jpg_settings = settings; 1640 fh->jpg_settings = settings;
2404 sparams_unlock_and_return: 1641sparams_unlock_and_return:
2405 mutex_unlock(&zr->resource_lock); 1642 mutex_unlock(&zr->resource_lock);
2406 1643
2407 return res; 1644 return res;
2408 } 1645 }
2409 break;
2410 1646
2411 case BUZIOC_REQBUFS: 1647 case BUZIOC_REQBUFS:
2412 { 1648 {
@@ -2430,38 +1666,34 @@ static long zoran_do_ioctl(struct file *file, unsigned int cmd, void *arg)
2430 * tables to a Maximum of 2 MB */ 1666 * tables to a Maximum of 2 MB */
2431 if (breq->size > jpg_bufsize) 1667 if (breq->size > jpg_bufsize)
2432 breq->size = jpg_bufsize; 1668 breq->size = jpg_bufsize;
2433 if (fh->jpg_buffers.need_contiguous &&
2434 breq->size > MAX_KMALLOC_MEM)
2435 breq->size = MAX_KMALLOC_MEM;
2436 1669
2437 mutex_lock(&zr->resource_lock); 1670 mutex_lock(&zr->resource_lock);
2438 1671
2439 if (fh->jpg_buffers.allocated || fh->v4l_buffers.allocated) { 1672 if (fh->buffers.allocated) {
2440 dprintk(1, 1673 dprintk(1,
2441 KERN_ERR 1674 KERN_ERR
2442 "%s: BUZIOC_REQBUFS - buffers allready allocated\n", 1675 "%s: BUZIOC_REQBUFS - buffers already allocated\n",
2443 ZR_DEVNAME(zr)); 1676 ZR_DEVNAME(zr));
2444 res = -EBUSY; 1677 res = -EBUSY;
2445 goto jpgreqbuf_unlock_and_return; 1678 goto jpgreqbuf_unlock_and_return;
2446 } 1679 }
2447 1680
2448 fh->jpg_buffers.num_buffers = breq->count; 1681 /* The next mmap will map the MJPEG buffers - could
2449 fh->jpg_buffers.buffer_size = breq->size; 1682 * also be *_PLAY, but it doesn't matter here */
1683 map_mode_jpg(fh, 0);
1684 fh->buffers.num_buffers = breq->count;
1685 fh->buffers.buffer_size = breq->size;
2450 1686
2451 if (jpg_fbuffer_alloc(file)) { 1687 if (jpg_fbuffer_alloc(fh)) {
2452 res = -ENOMEM; 1688 res = -ENOMEM;
2453 goto jpgreqbuf_unlock_and_return; 1689 goto jpgreqbuf_unlock_and_return;
2454 } 1690 }
2455 1691
2456 /* The next mmap will map the MJPEG buffers - could 1692jpgreqbuf_unlock_and_return:
2457 * also be *_PLAY, but it doesn't matter here */
2458 fh->map_mode = ZORAN_MAP_MODE_JPG_REC;
2459 jpgreqbuf_unlock_and_return:
2460 mutex_unlock(&zr->resource_lock); 1693 mutex_unlock(&zr->resource_lock);
2461 1694
2462 return res; 1695 return res;
2463 } 1696 }
2464 break;
2465 1697
2466 case BUZIOC_QBUF_CAPT: 1698 case BUZIOC_QBUF_CAPT:
2467 { 1699 {
@@ -2471,12 +1703,11 @@ static long zoran_do_ioctl(struct file *file, unsigned int cmd, void *arg)
2471 ZR_DEVNAME(zr), *frame); 1703 ZR_DEVNAME(zr), *frame);
2472 1704
2473 mutex_lock(&zr->resource_lock); 1705 mutex_lock(&zr->resource_lock);
2474 res = jpg_qbuf(file, *frame, BUZ_MODE_MOTION_COMPRESS); 1706 res = jpg_qbuf(fh, *frame, BUZ_MODE_MOTION_COMPRESS);
2475 mutex_unlock(&zr->resource_lock); 1707 mutex_unlock(&zr->resource_lock);
2476 1708
2477 return res; 1709 return res;
2478 } 1710 }
2479 break;
2480 1711
2481 case BUZIOC_QBUF_PLAY: 1712 case BUZIOC_QBUF_PLAY:
2482 { 1713 {
@@ -2486,12 +1717,11 @@ static long zoran_do_ioctl(struct file *file, unsigned int cmd, void *arg)
2486 ZR_DEVNAME(zr), *frame); 1717 ZR_DEVNAME(zr), *frame);
2487 1718
2488 mutex_lock(&zr->resource_lock); 1719 mutex_lock(&zr->resource_lock);
2489 res = jpg_qbuf(file, *frame, BUZ_MODE_MOTION_DECOMPRESS); 1720 res = jpg_qbuf(fh, *frame, BUZ_MODE_MOTION_DECOMPRESS);
2490 mutex_unlock(&zr->resource_lock); 1721 mutex_unlock(&zr->resource_lock);
2491 1722
2492 return res; 1723 return res;
2493 } 1724 }
2494 break;
2495 1725
2496 case BUZIOC_SYNC: 1726 case BUZIOC_SYNC:
2497 { 1727 {
@@ -2501,17 +1731,26 @@ static long zoran_do_ioctl(struct file *file, unsigned int cmd, void *arg)
2501 dprintk(3, KERN_DEBUG "%s: BUZIOC_SYNC\n", ZR_DEVNAME(zr)); 1731 dprintk(3, KERN_DEBUG "%s: BUZIOC_SYNC\n", ZR_DEVNAME(zr));
2502 1732
2503 mutex_lock(&zr->resource_lock); 1733 mutex_lock(&zr->resource_lock);
2504 res = jpg_sync(file, bsync); 1734
1735 if (fh->map_mode == ZORAN_MAP_MODE_RAW) {
1736 dprintk(2, KERN_WARNING
1737 "%s: %s - not in jpg capture mode\n",
1738 ZR_DEVNAME(zr), __func__);
1739 res = -EINVAL;
1740 } else {
1741 res = jpg_sync(fh, bsync);
1742 }
2505 mutex_unlock(&zr->resource_lock); 1743 mutex_unlock(&zr->resource_lock);
2506 1744
2507 return res; 1745 return res;
2508 } 1746 }
2509 break;
2510 1747
2511 case BUZIOC_G_STATUS: 1748 case BUZIOC_G_STATUS:
2512 { 1749 {
2513 struct zoran_status *bstat = arg; 1750 struct zoran_status *bstat = arg;
2514 int norm, input, status, res = 0; 1751 struct v4l2_routing route = { 0, 0 };
1752 int status = 0, res = 0;
1753 v4l2_std_id norm;
2515 1754
2516 dprintk(3, KERN_DEBUG "%s: BUZIOC_G_STATUS\n", ZR_DEVNAME(zr)); 1755 dprintk(3, KERN_DEBUG "%s: BUZIOC_G_STATUS\n", ZR_DEVNAME(zr));
2517 1756
@@ -2523,8 +1762,7 @@ static long zoran_do_ioctl(struct file *file, unsigned int cmd, void *arg)
2523 return -EINVAL; 1762 return -EINVAL;
2524 } 1763 }
2525 1764
2526 input = zr->card.input[bstat->input].muxsel; 1765 route.input = zr->card.input[bstat->input].muxsel;
2527 norm = VIDEO_MODE_AUTO;
2528 1766
2529 mutex_lock(&zr->resource_lock); 1767 mutex_lock(&zr->resource_lock);
2530 1768
@@ -2537,1629 +1775,1262 @@ static long zoran_do_ioctl(struct file *file, unsigned int cmd, void *arg)
2537 goto gstat_unlock_and_return; 1775 goto gstat_unlock_and_return;
2538 } 1776 }
2539 1777
2540 decoder_command(zr, DECODER_SET_INPUT, &input); 1778 decoder_call(zr, video, s_routing, &route);
2541 decoder_command(zr, DECODER_SET_NORM, &norm);
2542 1779
2543 /* sleep 1 second */ 1780 /* sleep 1 second */
2544 ssleep(1); 1781 ssleep(1);
2545 1782
2546 /* Get status of video decoder */ 1783 /* Get status of video decoder */
2547 decoder_command(zr, DECODER_GET_STATUS, &status); 1784 decoder_call(zr, video, querystd, &norm);
1785 decoder_call(zr, video, g_input_status, &status);
2548 1786
2549 /* restore previous input and norm */ 1787 /* restore previous input and norm */
2550 input = zr->card.input[zr->input].muxsel; 1788 route.input = zr->card.input[zr->input].muxsel;
2551 decoder_command(zr, DECODER_SET_INPUT, &input); 1789 decoder_call(zr, video, s_routing, &route);
2552 decoder_command(zr, DECODER_SET_NORM, &zr->norm); 1790gstat_unlock_and_return:
2553 gstat_unlock_and_return:
2554 mutex_unlock(&zr->resource_lock); 1791 mutex_unlock(&zr->resource_lock);
2555 1792
2556 if (!res) { 1793 if (!res) {
2557 bstat->signal = 1794 bstat->signal =
2558 (status & DECODER_STATUS_GOOD) ? 1 : 0; 1795 (status & V4L2_IN_ST_NO_SIGNAL) ? 0 : 1;
2559 if (status & DECODER_STATUS_NTSC) 1796 if (norm & V4L2_STD_NTSC)
2560 bstat->norm = VIDEO_MODE_NTSC; 1797 bstat->norm = VIDEO_MODE_NTSC;
2561 else if (status & DECODER_STATUS_SECAM) 1798 else if (norm & V4L2_STD_SECAM)
2562 bstat->norm = VIDEO_MODE_SECAM; 1799 bstat->norm = VIDEO_MODE_SECAM;
2563 else 1800 else
2564 bstat->norm = VIDEO_MODE_PAL; 1801 bstat->norm = VIDEO_MODE_PAL;
2565 1802
2566 bstat->color = 1803 bstat->color =
2567 (status & DECODER_STATUS_COLOR) ? 1 : 0; 1804 (status & V4L2_IN_ST_NO_COLOR) ? 0 : 1;
2568 } 1805 }
2569 1806
2570 return res; 1807 return res;
2571 } 1808 }
2572 break;
2573
2574 /* The new video4linux2 capture interface - much nicer than video4linux1, since
2575 * it allows for integrating the JPEG capturing calls inside standard v4l2
2576 */
2577
2578 case VIDIOC_QUERYCAP:
2579 {
2580 struct v4l2_capability *cap = arg;
2581 1809
2582 dprintk(3, KERN_DEBUG "%s: VIDIOC_QUERYCAP\n", ZR_DEVNAME(zr)); 1810 default:
2583 1811 return -EINVAL;
2584 memset(cap, 0, sizeof(*cap));
2585 strncpy(cap->card, ZR_DEVNAME(zr), sizeof(cap->card)-1);
2586 strncpy(cap->driver, "zoran", sizeof(cap->driver)-1);
2587 snprintf(cap->bus_info, sizeof(cap->bus_info), "PCI:%s",
2588 pci_name(zr->pci_dev));
2589 cap->version =
2590 KERNEL_VERSION(MAJOR_VERSION, MINOR_VERSION,
2591 RELEASE_VERSION);
2592 cap->capabilities = ZORAN_V4L2_VID_FLAGS;
2593
2594 return 0;
2595 } 1812 }
2596 break; 1813}
2597 1814
2598 case VIDIOC_ENUM_FMT: 1815static int zoran_vidiocgmbuf(struct file *file, void *__fh, struct video_mbuf *vmbuf)
2599 { 1816{
2600 struct v4l2_fmtdesc *fmt = arg; 1817 struct zoran_fh *fh = __fh;
2601 int index = fmt->index, num = -1, i, flag = 0, type = 1818 struct zoran *zr = fh->zr;
2602 fmt->type; 1819 int i, res = 0;
2603 1820
2604 dprintk(3, KERN_DEBUG "%s: VIDIOC_ENUM_FMT - index=%d\n",
2605 ZR_DEVNAME(zr), fmt->index);
2606 1821
2607 switch (fmt->type) { 1822 mutex_lock(&zr->resource_lock);
2608 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
2609 flag = ZORAN_FORMAT_CAPTURE;
2610 break;
2611 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
2612 flag = ZORAN_FORMAT_PLAYBACK;
2613 break;
2614 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
2615 flag = ZORAN_FORMAT_OVERLAY;
2616 break;
2617 default:
2618 dprintk(1,
2619 KERN_ERR
2620 "%s: VIDIOC_ENUM_FMT - unknown type %d\n",
2621 ZR_DEVNAME(zr), fmt->type);
2622 return -EINVAL;
2623 }
2624 1823
2625 for (i = 0; i < NUM_FORMATS; i++) { 1824 if (fh->buffers.allocated) {
2626 if (zoran_formats[i].flags & flag) 1825 dprintk(1,
2627 num++; 1826 KERN_ERR
2628 if (num == fmt->index) 1827 "%s: VIDIOCGMBUF - buffers already allocated\n",
2629 break; 1828 ZR_DEVNAME(zr));
2630 } 1829 res = -EINVAL;
2631 if (fmt->index < 0 /* late, but not too late */ || 1830 goto v4l1reqbuf_unlock_and_return;
2632 i == NUM_FORMATS) 1831 }
2633 return -EINVAL;
2634 1832
2635 memset(fmt, 0, sizeof(*fmt)); 1833 /* The next mmap will map the V4L buffers */
2636 fmt->index = index; 1834 map_mode_raw(fh);
2637 fmt->type = type;
2638 strncpy(fmt->description, zoran_formats[i].name, sizeof(fmt->description)-1);
2639 fmt->pixelformat = zoran_formats[i].fourcc;
2640 if (zoran_formats[i].flags & ZORAN_FORMAT_COMPRESSED)
2641 fmt->flags |= V4L2_FMT_FLAG_COMPRESSED;
2642 1835
2643 return 0; 1836 if (v4l_fbuffer_alloc(fh)) {
1837 res = -ENOMEM;
1838 goto v4l1reqbuf_unlock_and_return;
2644 } 1839 }
2645 break;
2646
2647 case VIDIOC_G_FMT:
2648 {
2649 struct v4l2_format *fmt = arg;
2650 int type = fmt->type;
2651 1840
2652 dprintk(5, KERN_DEBUG "%s: VIDIOC_G_FMT\n", ZR_DEVNAME(zr)); 1841 vmbuf->size = fh->buffers.num_buffers * fh->buffers.buffer_size;
1842 vmbuf->frames = fh->buffers.num_buffers;
1843 for (i = 0; i < vmbuf->frames; i++)
1844 vmbuf->offsets[i] = i * fh->buffers.buffer_size;
2653 1845
2654 memset(fmt, 0, sizeof(*fmt)); 1846v4l1reqbuf_unlock_and_return:
2655 fmt->type = type; 1847 mutex_unlock(&zr->resource_lock);
2656 1848
2657 switch (fmt->type) { 1849 return res;
2658 case V4L2_BUF_TYPE_VIDEO_OVERLAY: 1850}
1851#endif
2659 1852
2660 mutex_lock(&zr->resource_lock); 1853static int zoran_querycap(struct file *file, void *__fh, struct v4l2_capability *cap)
1854{
1855 struct zoran_fh *fh = __fh;
1856 struct zoran *zr = fh->zr;
2661 1857
2662 fmt->fmt.win.w.left = fh->overlay_settings.x; 1858 memset(cap, 0, sizeof(*cap));
2663 fmt->fmt.win.w.top = fh->overlay_settings.y; 1859 strncpy(cap->card, ZR_DEVNAME(zr), sizeof(cap->card)-1);
2664 fmt->fmt.win.w.width = fh->overlay_settings.width; 1860 strncpy(cap->driver, "zoran", sizeof(cap->driver)-1);
2665 fmt->fmt.win.w.height = 1861 snprintf(cap->bus_info, sizeof(cap->bus_info), "PCI:%s",
2666 fh->overlay_settings.height; 1862 pci_name(zr->pci_dev));
2667 if (fh->overlay_settings.width * 2 > 1863 cap->version = KERNEL_VERSION(MAJOR_VERSION, MINOR_VERSION,
2668 BUZ_MAX_HEIGHT) 1864 RELEASE_VERSION);
2669 fmt->fmt.win.field = V4L2_FIELD_INTERLACED; 1865 cap->capabilities = V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_CAPTURE |
2670 else 1866 V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_VIDEO_OVERLAY;
2671 fmt->fmt.win.field = V4L2_FIELD_TOP; 1867 return 0;
1868}
2672 1869
2673 mutex_unlock(&zr->resource_lock); 1870static int zoran_enum_fmt(struct zoran *zr, struct v4l2_fmtdesc *fmt, int flag)
1871{
1872 int num = -1, i;
2674 1873
1874 for (i = 0; i < NUM_FORMATS; i++) {
1875 if (zoran_formats[i].flags & flag)
1876 num++;
1877 if (num == fmt->index)
2675 break; 1878 break;
1879 }
1880 if (fmt->index < 0 /* late, but not too late */ || i == NUM_FORMATS)
1881 return -EINVAL;
2676 1882
2677 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 1883 strncpy(fmt->description, zoran_formats[i].name, sizeof(fmt->description)-1);
2678 case V4L2_BUF_TYPE_VIDEO_OUTPUT: 1884 fmt->pixelformat = zoran_formats[i].fourcc;
2679 1885 if (zoran_formats[i].flags & ZORAN_FORMAT_COMPRESSED)
2680 mutex_lock(&zr->resource_lock); 1886 fmt->flags |= V4L2_FMT_FLAG_COMPRESSED;
2681 1887 return 0;
2682 if (fmt->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && 1888}
2683 fh->map_mode == ZORAN_MAP_MODE_RAW) {
2684
2685 fmt->fmt.pix.width =
2686 fh->v4l_settings.width;
2687 fmt->fmt.pix.height =
2688 fh->v4l_settings.height;
2689 fmt->fmt.pix.sizeimage =
2690 fh->v4l_settings.bytesperline *
2691 fh->v4l_settings.height;
2692 fmt->fmt.pix.pixelformat =
2693 fh->v4l_settings.format->fourcc;
2694 fmt->fmt.pix.colorspace =
2695 fh->v4l_settings.format->colorspace;
2696 fmt->fmt.pix.bytesperline =
2697 fh->v4l_settings.bytesperline;
2698 if (BUZ_MAX_HEIGHT <
2699 (fh->v4l_settings.height * 2))
2700 fmt->fmt.pix.field =
2701 V4L2_FIELD_INTERLACED;
2702 else
2703 fmt->fmt.pix.field =
2704 V4L2_FIELD_TOP;
2705
2706 } else {
2707
2708 fmt->fmt.pix.width =
2709 fh->jpg_settings.img_width /
2710 fh->jpg_settings.HorDcm;
2711 fmt->fmt.pix.height =
2712 fh->jpg_settings.img_height /
2713 (fh->jpg_settings.VerDcm *
2714 fh->jpg_settings.TmpDcm);
2715 fmt->fmt.pix.sizeimage =
2716 zoran_v4l2_calc_bufsize(&fh->
2717 jpg_settings);
2718 fmt->fmt.pix.pixelformat =
2719 V4L2_PIX_FMT_MJPEG;
2720 if (fh->jpg_settings.TmpDcm == 1)
2721 fmt->fmt.pix.field =
2722 (fh->jpg_settings.
2723 odd_even ? V4L2_FIELD_SEQ_BT :
2724 V4L2_FIELD_SEQ_BT);
2725 else
2726 fmt->fmt.pix.field =
2727 (fh->jpg_settings.
2728 odd_even ? V4L2_FIELD_TOP :
2729 V4L2_FIELD_BOTTOM);
2730
2731 fmt->fmt.pix.bytesperline = 0;
2732 fmt->fmt.pix.colorspace =
2733 V4L2_COLORSPACE_SMPTE170M;
2734 }
2735
2736 mutex_unlock(&zr->resource_lock);
2737 1889
2738 break; 1890static int zoran_enum_fmt_vid_cap(struct file *file, void *__fh,
1891 struct v4l2_fmtdesc *f)
1892{
1893 struct zoran_fh *fh = __fh;
1894 struct zoran *zr = fh->zr;
2739 1895
2740 default: 1896 return zoran_enum_fmt(zr, f, ZORAN_FORMAT_CAPTURE);
2741 dprintk(1, 1897}
2742 KERN_ERR
2743 "%s: VIDIOC_G_FMT - unsupported type %d\n",
2744 ZR_DEVNAME(zr), fmt->type);
2745 return -EINVAL;
2746 }
2747 return 0;
2748 }
2749 break;
2750 1898
2751 case VIDIOC_S_FMT: 1899static int zoran_enum_fmt_vid_out(struct file *file, void *__fh,
2752 { 1900 struct v4l2_fmtdesc *f)
2753 struct v4l2_format *fmt = arg; 1901{
2754 int i, res = 0; 1902 struct zoran_fh *fh = __fh;
2755 __le32 printformat; 1903 struct zoran *zr = fh->zr;
2756
2757 dprintk(3, KERN_DEBUG "%s: VIDIOC_S_FMT - type=%d, ",
2758 ZR_DEVNAME(zr), fmt->type);
2759
2760 switch (fmt->type) {
2761 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
2762
2763 dprintk(3, "x=%d, y=%d, w=%d, h=%d, cnt=%d, map=0x%p\n",
2764 fmt->fmt.win.w.left, fmt->fmt.win.w.top,
2765 fmt->fmt.win.w.width,
2766 fmt->fmt.win.w.height,
2767 fmt->fmt.win.clipcount,
2768 fmt->fmt.win.bitmap);
2769 mutex_lock(&zr->resource_lock);
2770 res =
2771 setup_window(file, fmt->fmt.win.w.left,
2772 fmt->fmt.win.w.top,
2773 fmt->fmt.win.w.width,
2774 fmt->fmt.win.w.height,
2775 (struct video_clip __user *)
2776 fmt->fmt.win.clips,
2777 fmt->fmt.win.clipcount,
2778 fmt->fmt.win.bitmap);
2779 mutex_unlock(&zr->resource_lock);
2780 return res;
2781 break;
2782 1904
2783 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 1905 return zoran_enum_fmt(zr, f, ZORAN_FORMAT_PLAYBACK);
2784 case V4L2_BUF_TYPE_VIDEO_OUTPUT: 1906}
2785
2786 printformat =
2787 __cpu_to_le32(fmt->fmt.pix.pixelformat);
2788 dprintk(3, "size=%dx%d, fmt=0x%x (%4.4s)\n",
2789 fmt->fmt.pix.width, fmt->fmt.pix.height,
2790 fmt->fmt.pix.pixelformat,
2791 (char *) &printformat);
2792
2793 /* we can be requested to do JPEG/raw playback/capture */
2794 if (!
2795 (fmt->type == V4L2_BUF_TYPE_VIDEO_CAPTURE ||
2796 (fmt->type == V4L2_BUF_TYPE_VIDEO_OUTPUT &&
2797 fmt->fmt.pix.pixelformat ==
2798 V4L2_PIX_FMT_MJPEG))) {
2799 dprintk(1,
2800 KERN_ERR
2801 "%s: VIDIOC_S_FMT - unknown type %d/0x%x(%4.4s) combination\n",
2802 ZR_DEVNAME(zr), fmt->type,
2803 fmt->fmt.pix.pixelformat,
2804 (char *) &printformat);
2805 return -EINVAL;
2806 }
2807 1907
2808 if (fmt->fmt.pix.pixelformat == V4L2_PIX_FMT_MJPEG) { 1908static int zoran_enum_fmt_vid_overlay(struct file *file, void *__fh,
2809 mutex_lock(&zr->resource_lock); 1909 struct v4l2_fmtdesc *f)
1910{
1911 struct zoran_fh *fh = __fh;
1912 struct zoran *zr = fh->zr;
2810 1913
2811 settings = fh->jpg_settings; 1914 return zoran_enum_fmt(zr, f, ZORAN_FORMAT_OVERLAY);
1915}
2812 1916
2813 if (fh->v4l_buffers.allocated || 1917static int zoran_g_fmt_vid_out(struct file *file, void *__fh,
2814 fh->jpg_buffers.allocated) { 1918 struct v4l2_format *fmt)
2815 dprintk(1, 1919{
2816 KERN_ERR 1920 struct zoran_fh *fh = __fh;
2817 "%s: VIDIOC_S_FMT - cannot change capture mode\n", 1921 struct zoran *zr = fh->zr;
2818 ZR_DEVNAME(zr));
2819 res = -EBUSY;
2820 goto sfmtjpg_unlock_and_return;
2821 }
2822 1922
2823 /* we actually need to set 'real' parameters now */ 1923 mutex_lock(&zr->resource_lock);
2824 if ((fmt->fmt.pix.height * 2) >
2825 BUZ_MAX_HEIGHT)
2826 settings.TmpDcm = 1;
2827 else
2828 settings.TmpDcm = 2;
2829 settings.decimation = 0;
2830 if (fmt->fmt.pix.height <=
2831 fh->jpg_settings.img_height / 2)
2832 settings.VerDcm = 2;
2833 else
2834 settings.VerDcm = 1;
2835 if (fmt->fmt.pix.width <=
2836 fh->jpg_settings.img_width / 4)
2837 settings.HorDcm = 4;
2838 else if (fmt->fmt.pix.width <=
2839 fh->jpg_settings.img_width / 2)
2840 settings.HorDcm = 2;
2841 else
2842 settings.HorDcm = 1;
2843 if (settings.TmpDcm == 1)
2844 settings.field_per_buff = 2;
2845 else
2846 settings.field_per_buff = 1;
2847
2848 /* check */
2849 if ((res =
2850 zoran_check_jpg_settings(zr,
2851 &settings)))
2852 goto sfmtjpg_unlock_and_return;
2853
2854 /* it's ok, so set them */
2855 fh->jpg_settings = settings;
2856
2857 /* tell the user what we actually did */
2858 fmt->fmt.pix.width =
2859 settings.img_width / settings.HorDcm;
2860 fmt->fmt.pix.height =
2861 settings.img_height * 2 /
2862 (settings.TmpDcm * settings.VerDcm);
2863 if (settings.TmpDcm == 1)
2864 fmt->fmt.pix.field =
2865 (fh->jpg_settings.
2866 odd_even ? V4L2_FIELD_SEQ_TB :
2867 V4L2_FIELD_SEQ_BT);
2868 else
2869 fmt->fmt.pix.field =
2870 (fh->jpg_settings.
2871 odd_even ? V4L2_FIELD_TOP :
2872 V4L2_FIELD_BOTTOM);
2873 fh->jpg_buffers.buffer_size =
2874 zoran_v4l2_calc_bufsize(&fh->
2875 jpg_settings);
2876 fmt->fmt.pix.bytesperline = 0;
2877 fmt->fmt.pix.sizeimage =
2878 fh->jpg_buffers.buffer_size;
2879 fmt->fmt.pix.colorspace =
2880 V4L2_COLORSPACE_SMPTE170M;
2881
2882 /* we hereby abuse this variable to show that
2883 * we're gonna do mjpeg capture */
2884 fh->map_mode =
2885 (fmt->type ==
2886 V4L2_BUF_TYPE_VIDEO_CAPTURE) ?
2887 ZORAN_MAP_MODE_JPG_REC :
2888 ZORAN_MAP_MODE_JPG_PLAY;
2889 sfmtjpg_unlock_and_return:
2890 mutex_unlock(&zr->resource_lock);
2891 } else {
2892 for (i = 0; i < NUM_FORMATS; i++)
2893 if (fmt->fmt.pix.pixelformat ==
2894 zoran_formats[i].fourcc)
2895 break;
2896 if (i == NUM_FORMATS) {
2897 dprintk(1,
2898 KERN_ERR
2899 "%s: VIDIOC_S_FMT - unknown/unsupported format 0x%x (%4.4s)\n",
2900 ZR_DEVNAME(zr),
2901 fmt->fmt.pix.pixelformat,
2902 (char *) &printformat);
2903 return -EINVAL;
2904 }
2905 mutex_lock(&zr->resource_lock);
2906 if (fh->jpg_buffers.allocated ||
2907 (fh->v4l_buffers.allocated &&
2908 fh->v4l_buffers.active !=
2909 ZORAN_FREE)) {
2910 dprintk(1,
2911 KERN_ERR
2912 "%s: VIDIOC_S_FMT - cannot change capture mode\n",
2913 ZR_DEVNAME(zr));
2914 res = -EBUSY;
2915 goto sfmtv4l_unlock_and_return;
2916 }
2917 if (fmt->fmt.pix.height > BUZ_MAX_HEIGHT)
2918 fmt->fmt.pix.height =
2919 BUZ_MAX_HEIGHT;
2920 if (fmt->fmt.pix.width > BUZ_MAX_WIDTH)
2921 fmt->fmt.pix.width = BUZ_MAX_WIDTH;
2922
2923 if ((res =
2924 zoran_v4l_set_format(file,
2925 fmt->fmt.pix.
2926 width,
2927 fmt->fmt.pix.
2928 height,
2929 &zoran_formats
2930 [i])))
2931 goto sfmtv4l_unlock_and_return;
2932
2933 /* tell the user the
2934 * results/missing stuff */
2935 fmt->fmt.pix.bytesperline =
2936 fh->v4l_settings.bytesperline;
2937 fmt->fmt.pix.sizeimage =
2938 fh->v4l_settings.height *
2939 fh->v4l_settings.bytesperline;
2940 fmt->fmt.pix.colorspace =
2941 fh->v4l_settings.format->colorspace;
2942 if (BUZ_MAX_HEIGHT <
2943 (fh->v4l_settings.height * 2))
2944 fmt->fmt.pix.field =
2945 V4L2_FIELD_INTERLACED;
2946 else
2947 fmt->fmt.pix.field =
2948 V4L2_FIELD_TOP;
2949
2950 fh->map_mode = ZORAN_MAP_MODE_RAW;
2951 sfmtv4l_unlock_and_return:
2952 mutex_unlock(&zr->resource_lock);
2953 }
2954 1924
2955 break; 1925 fmt->fmt.pix.width = fh->jpg_settings.img_width / fh->jpg_settings.HorDcm;
1926 fmt->fmt.pix.height = fh->jpg_settings.img_height * 2 /
1927 (fh->jpg_settings.VerDcm * fh->jpg_settings.TmpDcm);
1928 fmt->fmt.pix.sizeimage = zoran_v4l2_calc_bufsize(&fh->jpg_settings);
1929 fmt->fmt.pix.pixelformat = V4L2_PIX_FMT_MJPEG;
1930 if (fh->jpg_settings.TmpDcm == 1)
1931 fmt->fmt.pix.field = (fh->jpg_settings.odd_even ?
1932 V4L2_FIELD_SEQ_TB : V4L2_FIELD_SEQ_BT);
1933 else
1934 fmt->fmt.pix.field = (fh->jpg_settings.odd_even ?
1935 V4L2_FIELD_TOP : V4L2_FIELD_BOTTOM);
1936 fmt->fmt.pix.bytesperline = 0;
1937 fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
2956 1938
2957 default: 1939 mutex_unlock(&zr->resource_lock);
2958 dprintk(1, 1940 return 0;
2959 KERN_ERR 1941}
2960 "%s: VIDIOC_S_FMT - unsupported type %d\n",
2961 ZR_DEVNAME(zr), fmt->type);
2962 return -EINVAL;
2963 }
2964 1942
2965 return res; 1943static int zoran_g_fmt_vid_cap(struct file *file, void *__fh,
2966 } 1944 struct v4l2_format *fmt)
2967 break; 1945{
1946 struct zoran_fh *fh = __fh;
1947 struct zoran *zr = fh->zr;
2968 1948
2969 case VIDIOC_G_FBUF: 1949 if (fh->map_mode != ZORAN_MAP_MODE_RAW)
2970 { 1950 return zoran_g_fmt_vid_out(file, fh, fmt);
2971 struct v4l2_framebuffer *fb = arg;
2972 1951
2973 dprintk(3, KERN_DEBUG "%s: VIDIOC_G_FBUF\n", ZR_DEVNAME(zr)); 1952 mutex_lock(&zr->resource_lock);
1953 fmt->fmt.pix.width = fh->v4l_settings.width;
1954 fmt->fmt.pix.height = fh->v4l_settings.height;
1955 fmt->fmt.pix.sizeimage = fh->v4l_settings.bytesperline *
1956 fh->v4l_settings.height;
1957 fmt->fmt.pix.pixelformat = fh->v4l_settings.format->fourcc;
1958 fmt->fmt.pix.colorspace = fh->v4l_settings.format->colorspace;
1959 fmt->fmt.pix.bytesperline = fh->v4l_settings.bytesperline;
1960 if (BUZ_MAX_HEIGHT < (fh->v4l_settings.height * 2))
1961 fmt->fmt.pix.field = V4L2_FIELD_INTERLACED;
1962 else
1963 fmt->fmt.pix.field = V4L2_FIELD_TOP;
1964 mutex_unlock(&zr->resource_lock);
1965 return 0;
1966}
2974 1967
2975 memset(fb, 0, sizeof(*fb)); 1968static int zoran_g_fmt_vid_overlay(struct file *file, void *__fh,
2976 mutex_lock(&zr->resource_lock); 1969 struct v4l2_format *fmt)
2977 fb->base = zr->buffer.base; 1970{
2978 fb->fmt.width = zr->buffer.width; 1971 struct zoran_fh *fh = __fh;
2979 fb->fmt.height = zr->buffer.height; 1972 struct zoran *zr = fh->zr;
2980 if (zr->overlay_settings.format) {
2981 fb->fmt.pixelformat =
2982 fh->overlay_settings.format->fourcc;
2983 }
2984 fb->fmt.bytesperline = zr->buffer.bytesperline;
2985 mutex_unlock(&zr->resource_lock);
2986 fb->fmt.colorspace = V4L2_COLORSPACE_SRGB;
2987 fb->fmt.field = V4L2_FIELD_INTERLACED;
2988 fb->flags = V4L2_FBUF_FLAG_OVERLAY;
2989 fb->capability = V4L2_FBUF_CAP_LIST_CLIPPING;
2990 1973
2991 return 0; 1974 mutex_lock(&zr->resource_lock);
2992 }
2993 break;
2994 1975
2995 case VIDIOC_S_FBUF: 1976 fmt->fmt.win.w.left = fh->overlay_settings.x;
2996 { 1977 fmt->fmt.win.w.top = fh->overlay_settings.y;
2997 int i, res = 0; 1978 fmt->fmt.win.w.width = fh->overlay_settings.width;
2998 struct v4l2_framebuffer *fb = arg; 1979 fmt->fmt.win.w.height = fh->overlay_settings.height;
2999 __le32 printformat = __cpu_to_le32(fb->fmt.pixelformat); 1980 if (fh->overlay_settings.width * 2 > BUZ_MAX_HEIGHT)
1981 fmt->fmt.win.field = V4L2_FIELD_INTERLACED;
1982 else
1983 fmt->fmt.win.field = V4L2_FIELD_TOP;
3000 1984
3001 dprintk(3, 1985 mutex_unlock(&zr->resource_lock);
3002 KERN_DEBUG 1986 return 0;
3003 "%s: VIDIOC_S_FBUF - base=0x%p, size=%dx%d, bpl=%d, fmt=0x%x (%4.4s)\n", 1987}
3004 ZR_DEVNAME(zr), fb->base, fb->fmt.width, fb->fmt.height,
3005 fb->fmt.bytesperline, fb->fmt.pixelformat,
3006 (char *) &printformat);
3007 1988
3008 for (i = 0; i < NUM_FORMATS; i++) 1989static int zoran_try_fmt_vid_overlay(struct file *file, void *__fh,
3009 if (zoran_formats[i].fourcc == fb->fmt.pixelformat) 1990 struct v4l2_format *fmt)
3010 break; 1991{
3011 if (i == NUM_FORMATS) { 1992 struct zoran_fh *fh = __fh;
3012 dprintk(1, 1993 struct zoran *zr = fh->zr;
3013 KERN_ERR
3014 "%s: VIDIOC_S_FBUF - format=0x%x (%4.4s) not allowed\n",
3015 ZR_DEVNAME(zr), fb->fmt.pixelformat,
3016 (char *) &printformat);
3017 return -EINVAL;
3018 }
3019 1994
3020 mutex_lock(&zr->resource_lock); 1995 mutex_lock(&zr->resource_lock);
3021 res =
3022 setup_fbuffer(file, fb->base, &zoran_formats[i],
3023 fb->fmt.width, fb->fmt.height,
3024 fb->fmt.bytesperline);
3025 mutex_unlock(&zr->resource_lock);
3026 1996
3027 return res; 1997 if (fmt->fmt.win.w.width > BUZ_MAX_WIDTH)
3028 } 1998 fmt->fmt.win.w.width = BUZ_MAX_WIDTH;
3029 break; 1999 if (fmt->fmt.win.w.width < BUZ_MIN_WIDTH)
2000 fmt->fmt.win.w.width = BUZ_MIN_WIDTH;
2001 if (fmt->fmt.win.w.height > BUZ_MAX_HEIGHT)
2002 fmt->fmt.win.w.height = BUZ_MAX_HEIGHT;
2003 if (fmt->fmt.win.w.height < BUZ_MIN_HEIGHT)
2004 fmt->fmt.win.w.height = BUZ_MIN_HEIGHT;
3030 2005
3031 case VIDIOC_OVERLAY: 2006 mutex_unlock(&zr->resource_lock);
3032 { 2007 return 0;
3033 int *on = arg, res; 2008}
3034 2009
3035 dprintk(3, KERN_DEBUG "%s: VIDIOC_PREVIEW - on=%d\n", 2010static int zoran_try_fmt_vid_out(struct file *file, void *__fh,
3036 ZR_DEVNAME(zr), *on); 2011 struct v4l2_format *fmt)
2012{
2013 struct zoran_fh *fh = __fh;
2014 struct zoran *zr = fh->zr;
2015 struct zoran_jpg_settings settings;
2016 int res = 0;
3037 2017
3038 mutex_lock(&zr->resource_lock); 2018 if (fmt->fmt.pix.pixelformat != V4L2_PIX_FMT_MJPEG)
3039 res = setup_overlay(file, *on); 2019 return -EINVAL;
3040 mutex_unlock(&zr->resource_lock);
3041 2020
3042 return res; 2021 mutex_lock(&zr->resource_lock);
3043 } 2022 settings = fh->jpg_settings;
3044 break;
3045 2023
3046 case VIDIOC_REQBUFS: 2024 /* we actually need to set 'real' parameters now */
3047 { 2025 if ((fmt->fmt.pix.height * 2) > BUZ_MAX_HEIGHT)
3048 struct v4l2_requestbuffers *req = arg; 2026 settings.TmpDcm = 1;
3049 int res = 0; 2027 else
2028 settings.TmpDcm = 2;
2029 settings.decimation = 0;
2030 if (fmt->fmt.pix.height <= fh->jpg_settings.img_height / 2)
2031 settings.VerDcm = 2;
2032 else
2033 settings.VerDcm = 1;
2034 if (fmt->fmt.pix.width <= fh->jpg_settings.img_width / 4)
2035 settings.HorDcm = 4;
2036 else if (fmt->fmt.pix.width <= fh->jpg_settings.img_width / 2)
2037 settings.HorDcm = 2;
2038 else
2039 settings.HorDcm = 1;
2040 if (settings.TmpDcm == 1)
2041 settings.field_per_buff = 2;
2042 else
2043 settings.field_per_buff = 1;
3050 2044
3051 dprintk(3, KERN_DEBUG "%s: VIDIOC_REQBUFS - type=%d\n", 2045 if (settings.HorDcm > 1) {
3052 ZR_DEVNAME(zr), req->type); 2046 settings.img_x = (BUZ_MAX_WIDTH == 720) ? 8 : 0;
2047 settings.img_width = (BUZ_MAX_WIDTH == 720) ? 704 : BUZ_MAX_WIDTH;
2048 } else {
2049 settings.img_x = 0;
2050 settings.img_width = BUZ_MAX_WIDTH;
2051 }
2052
2053 /* check */
2054 res = zoran_check_jpg_settings(zr, &settings, 1);
2055 if (res)
2056 goto tryfmt_unlock_and_return;
2057
2058 /* tell the user what we actually did */
2059 fmt->fmt.pix.width = settings.img_width / settings.HorDcm;
2060 fmt->fmt.pix.height = settings.img_height * 2 /
2061 (settings.TmpDcm * settings.VerDcm);
2062 if (settings.TmpDcm == 1)
2063 fmt->fmt.pix.field = (fh->jpg_settings.odd_even ?
2064 V4L2_FIELD_SEQ_TB : V4L2_FIELD_SEQ_BT);
2065 else
2066 fmt->fmt.pix.field = (fh->jpg_settings.odd_even ?
2067 V4L2_FIELD_TOP : V4L2_FIELD_BOTTOM);
3053 2068
3054 if (req->memory != V4L2_MEMORY_MMAP) { 2069 fmt->fmt.pix.sizeimage = zoran_v4l2_calc_bufsize(&settings);
3055 dprintk(1, 2070 fmt->fmt.pix.bytesperline = 0;
3056 KERN_ERR 2071 fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
3057 "%s: only MEMORY_MMAP capture is supported, not %d\n", 2072tryfmt_unlock_and_return:
3058 ZR_DEVNAME(zr), req->memory); 2073 mutex_unlock(&zr->resource_lock);
3059 return -EINVAL; 2074 return res;
3060 } 2075}
3061 2076
3062 mutex_lock(&zr->resource_lock); 2077static int zoran_try_fmt_vid_cap(struct file *file, void *__fh,
2078 struct v4l2_format *fmt)
2079{
2080 struct zoran_fh *fh = __fh;
2081 struct zoran *zr = fh->zr;
2082 int bpp;
2083 int i;
3063 2084
3064 if (fh->v4l_buffers.allocated || fh->jpg_buffers.allocated) { 2085 if (fmt->fmt.pix.pixelformat == V4L2_PIX_FMT_MJPEG)
3065 dprintk(1, 2086 return zoran_try_fmt_vid_out(file, fh, fmt);
3066 KERN_ERR
3067 "%s: VIDIOC_REQBUFS - buffers allready allocated\n",
3068 ZR_DEVNAME(zr));
3069 res = -EBUSY;
3070 goto v4l2reqbuf_unlock_and_return;
3071 }
3072 2087
3073 if (fh->map_mode == ZORAN_MAP_MODE_RAW && 2088 mutex_lock(&zr->resource_lock);
3074 req->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
3075 2089
3076 /* control user input */ 2090 for (i = 0; i < NUM_FORMATS; i++)
3077 if (req->count < 2) 2091 if (zoran_formats[i].fourcc == fmt->fmt.pix.pixelformat)
3078 req->count = 2; 2092 break;
3079 if (req->count > v4l_nbufs)
3080 req->count = v4l_nbufs;
3081 fh->v4l_buffers.num_buffers = req->count;
3082 2093
3083 if (v4l_fbuffer_alloc(file)) { 2094 if (i == NUM_FORMATS) {
3084 res = -ENOMEM; 2095 mutex_unlock(&zr->resource_lock);
3085 goto v4l2reqbuf_unlock_and_return; 2096 return -EINVAL;
3086 } 2097 }
3087 2098
3088 /* The next mmap will map the V4L buffers */ 2099 bpp = (zoran_formats[i].depth + 7) / 8;
3089 fh->map_mode = ZORAN_MAP_MODE_RAW; 2100 fmt->fmt.pix.width &= ~((bpp == 2) ? 1 : 3);
2101 if (fmt->fmt.pix.width > BUZ_MAX_WIDTH)
2102 fmt->fmt.pix.width = BUZ_MAX_WIDTH;
2103 if (fmt->fmt.pix.width < BUZ_MIN_WIDTH)
2104 fmt->fmt.pix.width = BUZ_MIN_WIDTH;
2105 if (fmt->fmt.pix.height > BUZ_MAX_HEIGHT)
2106 fmt->fmt.pix.height = BUZ_MAX_HEIGHT;
2107 if (fmt->fmt.pix.height < BUZ_MIN_HEIGHT)
2108 fmt->fmt.pix.height = BUZ_MIN_HEIGHT;
2109 mutex_unlock(&zr->resource_lock);
3090 2110
3091 } else if (fh->map_mode == ZORAN_MAP_MODE_JPG_REC || 2111 return 0;
3092 fh->map_mode == ZORAN_MAP_MODE_JPG_PLAY) { 2112}
3093 2113
3094 /* we need to calculate size ourselves now */ 2114static int zoran_s_fmt_vid_overlay(struct file *file, void *__fh,
3095 if (req->count < 4) 2115 struct v4l2_format *fmt)
3096 req->count = 4; 2116{
3097 if (req->count > jpg_nbufs) 2117 struct zoran_fh *fh = __fh;
3098 req->count = jpg_nbufs; 2118 struct zoran *zr = fh->zr;
3099 fh->jpg_buffers.num_buffers = req->count; 2119 int res;
3100 fh->jpg_buffers.buffer_size = 2120
3101 zoran_v4l2_calc_bufsize(&fh->jpg_settings); 2121 dprintk(3, "x=%d, y=%d, w=%d, h=%d, cnt=%d, map=0x%p\n",
2122 fmt->fmt.win.w.left, fmt->fmt.win.w.top,
2123 fmt->fmt.win.w.width,
2124 fmt->fmt.win.w.height,
2125 fmt->fmt.win.clipcount,
2126 fmt->fmt.win.bitmap);
2127 mutex_lock(&zr->resource_lock);
2128 res = setup_window(fh, fmt->fmt.win.w.left, fmt->fmt.win.w.top,
2129 fmt->fmt.win.w.width, fmt->fmt.win.w.height,
2130 (struct v4l2_clip __user *)fmt->fmt.win.clips,
2131 fmt->fmt.win.clipcount, fmt->fmt.win.bitmap);
2132 mutex_unlock(&zr->resource_lock);
2133 return res;
2134}
3102 2135
3103 if (jpg_fbuffer_alloc(file)) { 2136static int zoran_s_fmt_vid_out(struct file *file, void *__fh,
3104 res = -ENOMEM; 2137 struct v4l2_format *fmt)
3105 goto v4l2reqbuf_unlock_and_return; 2138{
3106 } 2139 struct zoran_fh *fh = __fh;
2140 struct zoran *zr = fh->zr;
2141 __le32 printformat = __cpu_to_le32(fmt->fmt.pix.pixelformat);
2142 struct zoran_jpg_settings settings;
2143 int res = 0;
3107 2144
3108 /* The next mmap will map the MJPEG buffers */ 2145 dprintk(3, "size=%dx%d, fmt=0x%x (%4.4s)\n",
3109 if (req->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) 2146 fmt->fmt.pix.width, fmt->fmt.pix.height,
3110 fh->map_mode = ZORAN_MAP_MODE_JPG_REC; 2147 fmt->fmt.pix.pixelformat,
3111 else 2148 (char *) &printformat);
3112 fh->map_mode = ZORAN_MAP_MODE_JPG_PLAY; 2149 if (fmt->fmt.pix.pixelformat != V4L2_PIX_FMT_MJPEG)
2150 return -EINVAL;
3113 2151
3114 } else { 2152 mutex_lock(&zr->resource_lock);
3115 dprintk(1,
3116 KERN_ERR
3117 "%s: VIDIOC_REQBUFS - unknown type %d\n",
3118 ZR_DEVNAME(zr), req->type);
3119 res = -EINVAL;
3120 goto v4l2reqbuf_unlock_and_return;
3121 }
3122 v4l2reqbuf_unlock_and_return:
3123 mutex_unlock(&zr->resource_lock);
3124 2153
3125 return 0; 2154 if (fh->buffers.allocated) {
2155 dprintk(1, KERN_ERR "%s: VIDIOC_S_FMT - cannot change capture mode\n",
2156 ZR_DEVNAME(zr));
2157 res = -EBUSY;
2158 goto sfmtjpg_unlock_and_return;
3126 } 2159 }
3127 break;
3128 2160
3129 case VIDIOC_QUERYBUF: 2161 settings = fh->jpg_settings;
3130 {
3131 struct v4l2_buffer *buf = arg;
3132 __u32 type = buf->type;
3133 int index = buf->index, res;
3134 2162
3135 dprintk(3, 2163 /* we actually need to set 'real' parameters now */
3136 KERN_DEBUG 2164 if (fmt->fmt.pix.height * 2 > BUZ_MAX_HEIGHT)
3137 "%s: VIDIOC_QUERYBUF - index=%d, type=%d\n", 2165 settings.TmpDcm = 1;
3138 ZR_DEVNAME(zr), buf->index, buf->type); 2166 else
3139 2167 settings.TmpDcm = 2;
3140 memset(buf, 0, sizeof(*buf)); 2168 settings.decimation = 0;
3141 buf->type = type; 2169 if (fmt->fmt.pix.height <= fh->jpg_settings.img_height / 2)
3142 buf->index = index; 2170 settings.VerDcm = 2;
3143 2171 else
3144 mutex_lock(&zr->resource_lock); 2172 settings.VerDcm = 1;
3145 res = zoran_v4l2_buffer_status(file, buf, buf->index); 2173 if (fmt->fmt.pix.width <= fh->jpg_settings.img_width / 4)
3146 mutex_unlock(&zr->resource_lock); 2174 settings.HorDcm = 4;
2175 else if (fmt->fmt.pix.width <= fh->jpg_settings.img_width / 2)
2176 settings.HorDcm = 2;
2177 else
2178 settings.HorDcm = 1;
2179 if (settings.TmpDcm == 1)
2180 settings.field_per_buff = 2;
2181 else
2182 settings.field_per_buff = 1;
3147 2183
3148 return res; 2184 if (settings.HorDcm > 1) {
2185 settings.img_x = (BUZ_MAX_WIDTH == 720) ? 8 : 0;
2186 settings.img_width = (BUZ_MAX_WIDTH == 720) ? 704 : BUZ_MAX_WIDTH;
2187 } else {
2188 settings.img_x = 0;
2189 settings.img_width = BUZ_MAX_WIDTH;
3149 } 2190 }
3150 break;
3151 2191
3152 case VIDIOC_QBUF: 2192 /* check */
3153 { 2193 res = zoran_check_jpg_settings(zr, &settings, 0);
3154 struct v4l2_buffer *buf = arg; 2194 if (res)
3155 int res = 0, codec_mode, buf_type; 2195 goto sfmtjpg_unlock_and_return;
3156 2196
3157 dprintk(3, 2197 /* it's ok, so set them */
3158 KERN_DEBUG "%s: VIDIOC_QBUF - type=%d, index=%d\n", 2198 fh->jpg_settings = settings;
3159 ZR_DEVNAME(zr), buf->type, buf->index);
3160 2199
3161 mutex_lock(&zr->resource_lock); 2200 map_mode_jpg(fh, fmt->type == V4L2_BUF_TYPE_VIDEO_OUTPUT);
2201 fh->buffers.buffer_size = zoran_v4l2_calc_bufsize(&fh->jpg_settings);
3162 2202
3163 switch (fh->map_mode) { 2203 /* tell the user what we actually did */
3164 case ZORAN_MAP_MODE_RAW: 2204 fmt->fmt.pix.width = settings.img_width / settings.HorDcm;
3165 if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) { 2205 fmt->fmt.pix.height = settings.img_height * 2 /
3166 dprintk(1, 2206 (settings.TmpDcm * settings.VerDcm);
3167 KERN_ERR 2207 if (settings.TmpDcm == 1)
3168 "%s: VIDIOC_QBUF - invalid buf->type=%d for map_mode=%d\n", 2208 fmt->fmt.pix.field = (fh->jpg_settings.odd_even ?
3169 ZR_DEVNAME(zr), buf->type, fh->map_mode); 2209 V4L2_FIELD_SEQ_TB : V4L2_FIELD_SEQ_BT);
3170 res = -EINVAL; 2210 else
3171 goto qbuf_unlock_and_return; 2211 fmt->fmt.pix.field = (fh->jpg_settings.odd_even ?
3172 } 2212 V4L2_FIELD_TOP : V4L2_FIELD_BOTTOM);
2213 fmt->fmt.pix.bytesperline = 0;
2214 fmt->fmt.pix.sizeimage = fh->buffers.buffer_size;
2215 fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
3173 2216
3174 res = zoran_v4l_queue_frame(file, buf->index); 2217sfmtjpg_unlock_and_return:
3175 if (res) 2218 mutex_unlock(&zr->resource_lock);
3176 goto qbuf_unlock_and_return; 2219 return res;
3177 if (!zr->v4l_memgrab_active && 2220}
3178 fh->v4l_buffers.active == ZORAN_LOCKED)
3179 zr36057_set_memgrab(zr, 1);
3180 break;
3181 2221
3182 case ZORAN_MAP_MODE_JPG_REC: 2222static int zoran_s_fmt_vid_cap(struct file *file, void *__fh,
3183 case ZORAN_MAP_MODE_JPG_PLAY: 2223 struct v4l2_format *fmt)
3184 if (fh->map_mode == ZORAN_MAP_MODE_JPG_PLAY) { 2224{
3185 buf_type = V4L2_BUF_TYPE_VIDEO_OUTPUT; 2225 struct zoran_fh *fh = __fh;
3186 codec_mode = BUZ_MODE_MOTION_DECOMPRESS; 2226 struct zoran *zr = fh->zr;
3187 } else { 2227 int i;
3188 buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 2228 int res = 0;
3189 codec_mode = BUZ_MODE_MOTION_COMPRESS;
3190 }
3191 2229
3192 if (buf->type != buf_type) { 2230 if (fmt->fmt.pix.pixelformat == V4L2_PIX_FMT_MJPEG)
3193 dprintk(1, 2231 return zoran_s_fmt_vid_out(file, fh, fmt);
3194 KERN_ERR
3195 "%s: VIDIOC_QBUF - invalid buf->type=%d for map_mode=%d\n",
3196 ZR_DEVNAME(zr), buf->type, fh->map_mode);
3197 res = -EINVAL;
3198 goto qbuf_unlock_and_return;
3199 }
3200 2232
3201 res = 2233 for (i = 0; i < NUM_FORMATS; i++)
3202 zoran_jpg_queue_frame(file, buf->index, 2234 if (fmt->fmt.pix.pixelformat == zoran_formats[i].fourcc)
3203 codec_mode);
3204 if (res != 0)
3205 goto qbuf_unlock_and_return;
3206 if (zr->codec_mode == BUZ_MODE_IDLE &&
3207 fh->jpg_buffers.active == ZORAN_LOCKED) {
3208 zr36057_enable_jpg(zr, codec_mode);
3209 }
3210 break; 2235 break;
3211 2236 if (i == NUM_FORMATS) {
3212 default: 2237 dprintk(1, KERN_ERR "%s: VIDIOC_S_FMT - unknown/unsupported format 0x%x\n",
3213 dprintk(1, 2238 ZR_DEVNAME(zr), fmt->fmt.pix.pixelformat);
3214 KERN_ERR 2239 return -EINVAL;
3215 "%s: VIDIOC_QBUF - unsupported type %d\n",
3216 ZR_DEVNAME(zr), buf->type);
3217 res = -EINVAL;
3218 goto qbuf_unlock_and_return;
3219 }
3220 qbuf_unlock_and_return:
3221 mutex_unlock(&zr->resource_lock);
3222
3223 return res;
3224 } 2240 }
3225 break;
3226 2241
3227 case VIDIOC_DQBUF: 2242 mutex_lock(&zr->resource_lock);
3228 {
3229 struct v4l2_buffer *buf = arg;
3230 int res = 0, buf_type, num = -1; /* compiler borks here (?) */
3231
3232 dprintk(3, KERN_DEBUG "%s: VIDIOC_DQBUF - type=%d\n",
3233 ZR_DEVNAME(zr), buf->type);
3234
3235 mutex_lock(&zr->resource_lock);
3236 2243
3237 switch (fh->map_mode) { 2244 if ((fh->map_mode != ZORAN_MAP_MODE_RAW && fh->buffers.allocated) ||
3238 case ZORAN_MAP_MODE_RAW: 2245 fh->buffers.active != ZORAN_FREE) {
3239 if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) { 2246 dprintk(1, KERN_ERR "%s: VIDIOC_S_FMT - cannot change capture mode\n",
3240 dprintk(1, 2247 ZR_DEVNAME(zr));
3241 KERN_ERR 2248 res = -EBUSY;
3242 "%s: VIDIOC_QBUF - invalid buf->type=%d for map_mode=%d\n", 2249 goto sfmtv4l_unlock_and_return;
3243 ZR_DEVNAME(zr), buf->type, fh->map_mode); 2250 }
3244 res = -EINVAL; 2251 if (fmt->fmt.pix.height > BUZ_MAX_HEIGHT)
3245 goto dqbuf_unlock_and_return; 2252 fmt->fmt.pix.height = BUZ_MAX_HEIGHT;
3246 } 2253 if (fmt->fmt.pix.width > BUZ_MAX_WIDTH)
2254 fmt->fmt.pix.width = BUZ_MAX_WIDTH;
2255
2256 map_mode_raw(fh);
2257
2258 res = zoran_v4l_set_format(fh, fmt->fmt.pix.width, fmt->fmt.pix.height,
2259 &zoran_formats[i]);
2260 if (res)
2261 goto sfmtv4l_unlock_and_return;
2262
2263 /* tell the user the results/missing stuff */
2264 fmt->fmt.pix.bytesperline = fh->v4l_settings.bytesperline;
2265 fmt->fmt.pix.sizeimage = fh->v4l_settings.height * fh->v4l_settings.bytesperline;
2266 fmt->fmt.pix.colorspace = fh->v4l_settings.format->colorspace;
2267 if (BUZ_MAX_HEIGHT < (fh->v4l_settings.height * 2))
2268 fmt->fmt.pix.field = V4L2_FIELD_INTERLACED;
2269 else
2270 fmt->fmt.pix.field = V4L2_FIELD_TOP;
3247 2271
3248 num = zr->v4l_pend[zr->v4l_sync_tail & V4L_MASK_FRAME]; 2272sfmtv4l_unlock_and_return:
3249 if (file->f_flags & O_NONBLOCK && 2273 mutex_unlock(&zr->resource_lock);
3250 zr->v4l_buffers.buffer[num].state != 2274 return res;
3251 BUZ_STATE_DONE) { 2275}
3252 res = -EAGAIN;
3253 goto dqbuf_unlock_and_return;
3254 }
3255 res = v4l_sync(file, num);
3256 if (res)
3257 goto dqbuf_unlock_and_return;
3258 else
3259 zr->v4l_sync_tail++;
3260 res = zoran_v4l2_buffer_status(file, buf, num);
3261 break;
3262 2276
3263 case ZORAN_MAP_MODE_JPG_REC: 2277static int zoran_g_fbuf(struct file *file, void *__fh,
3264 case ZORAN_MAP_MODE_JPG_PLAY: 2278 struct v4l2_framebuffer *fb)
3265 { 2279{
3266 struct zoran_sync bs; 2280 struct zoran_fh *fh = __fh;
2281 struct zoran *zr = fh->zr;
3267 2282
3268 if (fh->map_mode == ZORAN_MAP_MODE_JPG_PLAY) 2283 memset(fb, 0, sizeof(*fb));
3269 buf_type = V4L2_BUF_TYPE_VIDEO_OUTPUT; 2284 mutex_lock(&zr->resource_lock);
3270 else 2285 fb->base = zr->vbuf_base;
3271 buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 2286 fb->fmt.width = zr->vbuf_width;
2287 fb->fmt.height = zr->vbuf_height;
2288 if (zr->overlay_settings.format)
2289 fb->fmt.pixelformat = fh->overlay_settings.format->fourcc;
2290 fb->fmt.bytesperline = zr->vbuf_bytesperline;
2291 mutex_unlock(&zr->resource_lock);
2292 fb->fmt.colorspace = V4L2_COLORSPACE_SRGB;
2293 fb->fmt.field = V4L2_FIELD_INTERLACED;
2294 fb->flags = V4L2_FBUF_FLAG_OVERLAY;
2295 fb->capability = V4L2_FBUF_CAP_LIST_CLIPPING;
3272 2296
3273 if (buf->type != buf_type) { 2297 return 0;
3274 dprintk(1, 2298}
3275 KERN_ERR
3276 "%s: VIDIOC_QBUF - invalid buf->type=%d for map_mode=%d\n",
3277 ZR_DEVNAME(zr), buf->type, fh->map_mode);
3278 res = -EINVAL;
3279 goto dqbuf_unlock_and_return;
3280 }
3281 2299
3282 num = 2300static int zoran_s_fbuf(struct file *file, void *__fh,
3283 zr->jpg_pend[zr-> 2301 struct v4l2_framebuffer *fb)
3284 jpg_que_tail & BUZ_MASK_FRAME]; 2302{
2303 struct zoran_fh *fh = __fh;
2304 struct zoran *zr = fh->zr;
2305 int i, res = 0;
2306 __le32 printformat = __cpu_to_le32(fb->fmt.pixelformat);
3285 2307
3286 if (file->f_flags & O_NONBLOCK && 2308 for (i = 0; i < NUM_FORMATS; i++)
3287 zr->jpg_buffers.buffer[num].state != 2309 if (zoran_formats[i].fourcc == fb->fmt.pixelformat)
3288 BUZ_STATE_DONE) {
3289 res = -EAGAIN;
3290 goto dqbuf_unlock_and_return;
3291 }
3292 res = jpg_sync(file, &bs);
3293 if (res)
3294 goto dqbuf_unlock_and_return;
3295 res =
3296 zoran_v4l2_buffer_status(file, buf, bs.frame);
3297 break; 2310 break;
3298 } 2311 if (i == NUM_FORMATS) {
3299 2312 dprintk(1, KERN_ERR "%s: VIDIOC_S_FBUF - format=0x%x (%4.4s) not allowed\n",
3300 default: 2313 ZR_DEVNAME(zr), fb->fmt.pixelformat,
3301 dprintk(1, 2314 (char *)&printformat);
3302 KERN_ERR 2315 return -EINVAL;
3303 "%s: VIDIOC_DQBUF - unsupported type %d\n",
3304 ZR_DEVNAME(zr), buf->type);
3305 res = -EINVAL;
3306 goto dqbuf_unlock_and_return;
3307 }
3308 dqbuf_unlock_and_return:
3309 mutex_unlock(&zr->resource_lock);
3310
3311 return res;
3312 } 2316 }
3313 break;
3314 2317
3315 case VIDIOC_STREAMON: 2318 mutex_lock(&zr->resource_lock);
3316 { 2319 res = setup_fbuffer(fh, fb->base, &zoran_formats[i], fb->fmt.width,
3317 int res = 0; 2320 fb->fmt.height, fb->fmt.bytesperline);
2321 mutex_unlock(&zr->resource_lock);
3318 2322
3319 dprintk(3, KERN_DEBUG "%s: VIDIOC_STREAMON\n", ZR_DEVNAME(zr)); 2323 return res;
2324}
3320 2325
3321 mutex_lock(&zr->resource_lock); 2326static int zoran_overlay(struct file *file, void *__fh, unsigned int on)
2327{
2328 struct zoran_fh *fh = __fh;
2329 struct zoran *zr = fh->zr;
2330 int res;
3322 2331
3323 switch (fh->map_mode) { 2332 mutex_lock(&zr->resource_lock);
3324 case ZORAN_MAP_MODE_RAW: /* raw capture */ 2333 res = setup_overlay(fh, on);
3325 if (zr->v4l_buffers.active != ZORAN_ACTIVE || 2334 mutex_unlock(&zr->resource_lock);
3326 fh->v4l_buffers.active != ZORAN_ACTIVE) {
3327 res = -EBUSY;
3328 goto strmon_unlock_and_return;
3329 }
3330 2335
3331 zr->v4l_buffers.active = fh->v4l_buffers.active = 2336 return res;
3332 ZORAN_LOCKED; 2337}
3333 zr->v4l_settings = fh->v4l_settings;
3334 2338
3335 zr->v4l_sync_tail = zr->v4l_pend_tail; 2339static int zoran_streamoff(struct file *file, void *__fh, enum v4l2_buf_type type);
3336 if (!zr->v4l_memgrab_active &&
3337 zr->v4l_pend_head != zr->v4l_pend_tail) {
3338 zr36057_set_memgrab(zr, 1);
3339 }
3340 break;
3341 2340
3342 case ZORAN_MAP_MODE_JPG_REC: 2341static int zoran_reqbufs(struct file *file, void *__fh, struct v4l2_requestbuffers *req)
3343 case ZORAN_MAP_MODE_JPG_PLAY: 2342{
3344 /* what is the codec mode right now? */ 2343 struct zoran_fh *fh = __fh;
3345 if (zr->jpg_buffers.active != ZORAN_ACTIVE || 2344 struct zoran *zr = fh->zr;
3346 fh->jpg_buffers.active != ZORAN_ACTIVE) { 2345 int res = 0;
3347 res = -EBUSY;
3348 goto strmon_unlock_and_return;
3349 }
3350 2346
3351 zr->jpg_buffers.active = fh->jpg_buffers.active = 2347 if (req->memory != V4L2_MEMORY_MMAP) {
3352 ZORAN_LOCKED; 2348 dprintk(2,
2349 KERN_ERR
2350 "%s: only MEMORY_MMAP capture is supported, not %d\n",
2351 ZR_DEVNAME(zr), req->memory);
2352 return -EINVAL;
2353 }
3353 2354
3354 if (zr->jpg_que_head != zr->jpg_que_tail) { 2355 if (req->count == 0)
3355 /* Start the jpeg codec when the first frame is queued */ 2356 return zoran_streamoff(file, fh, req->type);
3356 jpeg_start(zr);
3357 }
3358 2357
3359 break; 2358 mutex_lock(&zr->resource_lock);
3360 default: 2359 if (fh->buffers.allocated) {
3361 dprintk(1, 2360 dprintk(2,
3362 KERN_ERR 2361 KERN_ERR
3363 "%s: VIDIOC_STREAMON - invalid map mode %d\n", 2362 "%s: VIDIOC_REQBUFS - buffers already allocated\n",
3364 ZR_DEVNAME(zr), fh->map_mode); 2363 ZR_DEVNAME(zr));
3365 res = -EINVAL; 2364 res = -EBUSY;
3366 goto strmon_unlock_and_return; 2365 goto v4l2reqbuf_unlock_and_return;
3367 }
3368 strmon_unlock_and_return:
3369 mutex_unlock(&zr->resource_lock);
3370
3371 return res;
3372 } 2366 }
3373 break;
3374 2367
3375 case VIDIOC_STREAMOFF: 2368 if (fh->map_mode == ZORAN_MAP_MODE_RAW &&
3376 { 2369 req->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
3377 int i, res = 0; 2370 /* control user input */
2371 if (req->count < 2)
2372 req->count = 2;
2373 if (req->count > v4l_nbufs)
2374 req->count = v4l_nbufs;
3378 2375
3379 dprintk(3, KERN_DEBUG "%s: VIDIOC_STREAMOFF\n", ZR_DEVNAME(zr)); 2376 /* The next mmap will map the V4L buffers */
2377 map_mode_raw(fh);
2378 fh->buffers.num_buffers = req->count;
3380 2379
3381 mutex_lock(&zr->resource_lock); 2380 if (v4l_fbuffer_alloc(fh)) {
2381 res = -ENOMEM;
2382 goto v4l2reqbuf_unlock_and_return;
2383 }
2384 } else if (fh->map_mode == ZORAN_MAP_MODE_JPG_REC ||
2385 fh->map_mode == ZORAN_MAP_MODE_JPG_PLAY) {
2386 /* we need to calculate size ourselves now */
2387 if (req->count < 4)
2388 req->count = 4;
2389 if (req->count > jpg_nbufs)
2390 req->count = jpg_nbufs;
3382 2391
3383 switch (fh->map_mode) { 2392 /* The next mmap will map the MJPEG buffers */
3384 case ZORAN_MAP_MODE_RAW: /* raw capture */ 2393 map_mode_jpg(fh, req->type == V4L2_BUF_TYPE_VIDEO_OUTPUT);
3385 if (fh->v4l_buffers.active == ZORAN_FREE && 2394 fh->buffers.num_buffers = req->count;
3386 zr->v4l_buffers.active != ZORAN_FREE) { 2395 fh->buffers.buffer_size = zoran_v4l2_calc_bufsize(&fh->jpg_settings);
3387 res = -EPERM; /* stay off other's settings! */
3388 goto strmoff_unlock_and_return;
3389 }
3390 if (zr->v4l_buffers.active == ZORAN_FREE)
3391 goto strmoff_unlock_and_return;
3392 2396
3393 /* unload capture */ 2397 if (jpg_fbuffer_alloc(fh)) {
3394 if (zr->v4l_memgrab_active) { 2398 res = -ENOMEM;
3395 unsigned long flags; 2399 goto v4l2reqbuf_unlock_and_return;
2400 }
2401 } else {
2402 dprintk(1,
2403 KERN_ERR
2404 "%s: VIDIOC_REQBUFS - unknown type %d\n",
2405 ZR_DEVNAME(zr), req->type);
2406 res = -EINVAL;
2407 goto v4l2reqbuf_unlock_and_return;
2408 }
2409v4l2reqbuf_unlock_and_return:
2410 mutex_unlock(&zr->resource_lock);
3396 2411
3397 spin_lock_irqsave(&zr->spinlock, flags); 2412 return res;
3398 zr36057_set_memgrab(zr, 0); 2413}
3399 spin_unlock_irqrestore(&zr->spinlock, flags);
3400 }
3401 2414
3402 for (i = 0; i < fh->v4l_buffers.num_buffers; i++) 2415static int zoran_querybuf(struct file *file, void *__fh, struct v4l2_buffer *buf)
3403 zr->v4l_buffers.buffer[i].state = 2416{
3404 BUZ_STATE_USER; 2417 struct zoran_fh *fh = __fh;
3405 fh->v4l_buffers = zr->v4l_buffers; 2418 struct zoran *zr = fh->zr;
2419 int res;
3406 2420
3407 zr->v4l_buffers.active = fh->v4l_buffers.active = 2421 mutex_lock(&zr->resource_lock);
3408 ZORAN_FREE; 2422 res = zoran_v4l2_buffer_status(fh, buf, buf->index);
2423 mutex_unlock(&zr->resource_lock);
3409 2424
3410 zr->v4l_grab_seq = 0; 2425 return res;
3411 zr->v4l_pend_head = zr->v4l_pend_tail = 0; 2426}
3412 zr->v4l_sync_tail = 0;
3413 2427
3414 break; 2428static int zoran_qbuf(struct file *file, void *__fh, struct v4l2_buffer *buf)
2429{
2430 struct zoran_fh *fh = __fh;
2431 struct zoran *zr = fh->zr;
2432 int res = 0, codec_mode, buf_type;
3415 2433
3416 case ZORAN_MAP_MODE_JPG_REC: 2434 mutex_lock(&zr->resource_lock);
3417 case ZORAN_MAP_MODE_JPG_PLAY: 2435
3418 if (fh->jpg_buffers.active == ZORAN_FREE && 2436 switch (fh->map_mode) {
3419 zr->jpg_buffers.active != ZORAN_FREE) { 2437 case ZORAN_MAP_MODE_RAW:
3420 res = -EPERM; /* stay off other's settings! */ 2438 if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
3421 goto strmoff_unlock_and_return; 2439 dprintk(1, KERN_ERR
3422 } 2440 "%s: VIDIOC_QBUF - invalid buf->type=%d for map_mode=%d\n",
3423 if (zr->jpg_buffers.active == ZORAN_FREE) 2441 ZR_DEVNAME(zr), buf->type, fh->map_mode);
3424 goto strmoff_unlock_and_return;
3425
3426 res =
3427 jpg_qbuf(file, -1,
3428 (fh->map_mode ==
3429 ZORAN_MAP_MODE_JPG_REC) ?
3430 BUZ_MODE_MOTION_COMPRESS :
3431 BUZ_MODE_MOTION_DECOMPRESS);
3432 if (res)
3433 goto strmoff_unlock_and_return;
3434 break;
3435 default:
3436 dprintk(1,
3437 KERN_ERR
3438 "%s: VIDIOC_STREAMOFF - invalid map mode %d\n",
3439 ZR_DEVNAME(zr), fh->map_mode);
3440 res = -EINVAL; 2442 res = -EINVAL;
3441 goto strmoff_unlock_and_return; 2443 goto qbuf_unlock_and_return;
3442 } 2444 }
3443 strmoff_unlock_and_return:
3444 mutex_unlock(&zr->resource_lock);
3445 2445
3446 return res; 2446 res = zoran_v4l_queue_frame(fh, buf->index);
3447 } 2447 if (res)
2448 goto qbuf_unlock_and_return;
2449 if (!zr->v4l_memgrab_active && fh->buffers.active == ZORAN_LOCKED)
2450 zr36057_set_memgrab(zr, 1);
3448 break; 2451 break;
3449 2452
3450 case VIDIOC_QUERYCTRL: 2453 case ZORAN_MAP_MODE_JPG_REC:
3451 { 2454 case ZORAN_MAP_MODE_JPG_PLAY:
3452 struct v4l2_queryctrl *ctrl = arg; 2455 if (fh->map_mode == ZORAN_MAP_MODE_JPG_PLAY) {
3453 2456 buf_type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
3454 dprintk(3, KERN_DEBUG "%s: VIDIOC_QUERYCTRL - id=%d\n", 2457 codec_mode = BUZ_MODE_MOTION_DECOMPRESS;
3455 ZR_DEVNAME(zr), ctrl->id); 2458 } else {
3456 2459 buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
3457 /* we only support hue/saturation/contrast/brightness */ 2460 codec_mode = BUZ_MODE_MOTION_COMPRESS;
3458 if (ctrl->id < V4L2_CID_BRIGHTNESS ||
3459 ctrl->id > V4L2_CID_HUE)
3460 return -EINVAL;
3461 else {
3462 int id = ctrl->id;
3463 memset(ctrl, 0, sizeof(*ctrl));
3464 ctrl->id = id;
3465 } 2461 }
3466 2462
3467 switch (ctrl->id) { 2463 if (buf->type != buf_type) {
3468 case V4L2_CID_BRIGHTNESS: 2464 dprintk(1, KERN_ERR
3469 strncpy(ctrl->name, "Brightness", sizeof(ctrl->name)-1); 2465 "%s: VIDIOC_QBUF - invalid buf->type=%d for map_mode=%d\n",
3470 break; 2466 ZR_DEVNAME(zr), buf->type, fh->map_mode);
3471 case V4L2_CID_CONTRAST: 2467 res = -EINVAL;
3472 strncpy(ctrl->name, "Contrast", sizeof(ctrl->name)-1); 2468 goto qbuf_unlock_and_return;
3473 break;
3474 case V4L2_CID_SATURATION:
3475 strncpy(ctrl->name, "Saturation", sizeof(ctrl->name)-1);
3476 break;
3477 case V4L2_CID_HUE:
3478 strncpy(ctrl->name, "Hue", sizeof(ctrl->name)-1);
3479 break;
3480 } 2469 }
3481 2470
3482 ctrl->minimum = 0; 2471 res = zoran_jpg_queue_frame(fh, buf->index, codec_mode);
3483 ctrl->maximum = 65535; 2472 if (res != 0)
3484 ctrl->step = 1; 2473 goto qbuf_unlock_and_return;
3485 ctrl->default_value = 32768; 2474 if (zr->codec_mode == BUZ_MODE_IDLE &&
3486 ctrl->type = V4L2_CTRL_TYPE_INTEGER; 2475 fh->buffers.active == ZORAN_LOCKED)
2476 zr36057_enable_jpg(zr, codec_mode);
3487 2477
3488 return 0;
3489 }
3490 break; 2478 break;
3491 2479
3492 case VIDIOC_G_CTRL: 2480 default:
3493 { 2481 dprintk(1, KERN_ERR
3494 struct v4l2_control *ctrl = arg; 2482 "%s: VIDIOC_QBUF - unsupported type %d\n",
3495 2483 ZR_DEVNAME(zr), buf->type);
3496 dprintk(3, KERN_DEBUG "%s: VIDIOC_G_CTRL - id=%d\n", 2484 res = -EINVAL;
3497 ZR_DEVNAME(zr), ctrl->id);
3498
3499 /* we only support hue/saturation/contrast/brightness */
3500 if (ctrl->id < V4L2_CID_BRIGHTNESS ||
3501 ctrl->id > V4L2_CID_HUE)
3502 return -EINVAL;
3503
3504 mutex_lock(&zr->resource_lock);
3505 switch (ctrl->id) {
3506 case V4L2_CID_BRIGHTNESS:
3507 ctrl->value = zr->brightness;
3508 break;
3509 case V4L2_CID_CONTRAST:
3510 ctrl->value = zr->contrast;
3511 break;
3512 case V4L2_CID_SATURATION:
3513 ctrl->value = zr->saturation;
3514 break;
3515 case V4L2_CID_HUE:
3516 ctrl->value = zr->hue;
3517 break;
3518 }
3519 mutex_unlock(&zr->resource_lock);
3520
3521 return 0;
3522 }
3523 break; 2485 break;
2486 }
2487qbuf_unlock_and_return:
2488 mutex_unlock(&zr->resource_lock);
3524 2489
3525 case VIDIOC_S_CTRL: 2490 return res;
3526 { 2491}
3527 struct v4l2_control *ctrl = arg;
3528 struct video_picture pict;
3529 2492
3530 dprintk(3, KERN_DEBUG "%s: VIDIOC_S_CTRL - id=%d\n", 2493static int zoran_dqbuf(struct file *file, void *__fh, struct v4l2_buffer *buf)
3531 ZR_DEVNAME(zr), ctrl->id); 2494{
2495 struct zoran_fh *fh = __fh;
2496 struct zoran *zr = fh->zr;
2497 int res = 0, buf_type, num = -1; /* compiler borks here (?) */
3532 2498
3533 /* we only support hue/saturation/contrast/brightness */ 2499 mutex_lock(&zr->resource_lock);
3534 if (ctrl->id < V4L2_CID_BRIGHTNESS ||
3535 ctrl->id > V4L2_CID_HUE)
3536 return -EINVAL;
3537 2500
3538 if (ctrl->value < 0 || ctrl->value > 65535) { 2501 switch (fh->map_mode) {
3539 dprintk(1, 2502 case ZORAN_MAP_MODE_RAW:
3540 KERN_ERR 2503 if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
3541 "%s: VIDIOC_S_CTRL - invalid value %d for id=%d\n", 2504 dprintk(1, KERN_ERR
3542 ZR_DEVNAME(zr), ctrl->value, ctrl->id); 2505 "%s: VIDIOC_QBUF - invalid buf->type=%d for map_mode=%d\n",
3543 return -EINVAL; 2506 ZR_DEVNAME(zr), buf->type, fh->map_mode);
2507 res = -EINVAL;
2508 goto dqbuf_unlock_and_return;
3544 } 2509 }
3545 2510
3546 mutex_lock(&zr->resource_lock); 2511 num = zr->v4l_pend[zr->v4l_sync_tail & V4L_MASK_FRAME];
3547 switch (ctrl->id) { 2512 if (file->f_flags & O_NONBLOCK &&
3548 case V4L2_CID_BRIGHTNESS: 2513 zr->v4l_buffers.buffer[num].state != BUZ_STATE_DONE) {
3549 zr->brightness = ctrl->value; 2514 res = -EAGAIN;
3550 break; 2515 goto dqbuf_unlock_and_return;
3551 case V4L2_CID_CONTRAST:
3552 zr->contrast = ctrl->value;
3553 break;
3554 case V4L2_CID_SATURATION:
3555 zr->saturation = ctrl->value;
3556 break;
3557 case V4L2_CID_HUE:
3558 zr->hue = ctrl->value;
3559 break;
3560 } 2516 }
3561 pict.brightness = zr->brightness; 2517 res = v4l_sync(fh, num);
3562 pict.contrast = zr->contrast; 2518 if (res)
3563 pict.colour = zr->saturation; 2519 goto dqbuf_unlock_and_return;
3564 pict.hue = zr->hue; 2520 zr->v4l_sync_tail++;
3565 2521 res = zoran_v4l2_buffer_status(fh, buf, num);
3566 decoder_command(zr, DECODER_SET_PICTURE, &pict);
3567
3568 mutex_unlock(&zr->resource_lock);
3569
3570 return 0;
3571 }
3572 break; 2522 break;
3573 2523
3574 case VIDIOC_ENUMSTD: 2524 case ZORAN_MAP_MODE_JPG_REC:
2525 case ZORAN_MAP_MODE_JPG_PLAY:
3575 { 2526 {
3576 struct v4l2_standard *std = arg; 2527 struct zoran_sync bs;
3577 2528
3578 dprintk(3, KERN_DEBUG "%s: VIDIOC_ENUMSTD - index=%d\n", 2529 if (fh->map_mode == ZORAN_MAP_MODE_JPG_PLAY)
3579 ZR_DEVNAME(zr), std->index); 2530 buf_type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
2531 else
2532 buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
3580 2533
3581 if (std->index < 0 || std->index >= (zr->card.norms + 1)) 2534 if (buf->type != buf_type) {
3582 return -EINVAL; 2535 dprintk(1, KERN_ERR
3583 else { 2536 "%s: VIDIOC_QBUF - invalid buf->type=%d for map_mode=%d\n",
3584 int id = std->index; 2537 ZR_DEVNAME(zr), buf->type, fh->map_mode);
3585 memset(std, 0, sizeof(*std)); 2538 res = -EINVAL;
3586 std->index = id; 2539 goto dqbuf_unlock_and_return;
3587 } 2540 }
3588 2541
3589 if (std->index == zr->card.norms) { 2542 num = zr->jpg_pend[zr->jpg_que_tail & BUZ_MASK_FRAME];
3590 /* if we have autodetect, ... */
3591 struct video_decoder_capability caps;
3592 decoder_command(zr, DECODER_GET_CAPABILITIES,
3593 &caps);
3594 if (caps.flags & VIDEO_DECODER_AUTO) {
3595 std->id = V4L2_STD_ALL;
3596 strncpy(std->name, "Autodetect", sizeof(std->name)-1);
3597 return 0;
3598 } else
3599 return -EINVAL;
3600 }
3601 switch (std->index) {
3602 case 0:
3603 std->id = V4L2_STD_PAL;
3604 strncpy(std->name, "PAL", sizeof(std->name)-1);
3605 std->frameperiod.numerator = 1;
3606 std->frameperiod.denominator = 25;
3607 std->framelines = zr->card.tvn[0]->Ht;
3608 break;
3609 case 1:
3610 std->id = V4L2_STD_NTSC;
3611 strncpy(std->name, "NTSC", sizeof(std->name)-1);
3612 std->frameperiod.numerator = 1001;
3613 std->frameperiod.denominator = 30000;
3614 std->framelines = zr->card.tvn[1]->Ht;
3615 break;
3616 case 2:
3617 std->id = V4L2_STD_SECAM;
3618 strncpy(std->name, "SECAM", sizeof(std->name)-1);
3619 std->frameperiod.numerator = 1;
3620 std->frameperiod.denominator = 25;
3621 std->framelines = zr->card.tvn[2]->Ht;
3622 break;
3623 }
3624 2543
3625 return 0; 2544 if (file->f_flags & O_NONBLOCK &&
2545 zr->jpg_buffers.buffer[num].state != BUZ_STATE_DONE) {
2546 res = -EAGAIN;
2547 goto dqbuf_unlock_and_return;
2548 }
2549 res = jpg_sync(fh, &bs);
2550 if (res)
2551 goto dqbuf_unlock_and_return;
2552 res = zoran_v4l2_buffer_status(fh, buf, bs.frame);
2553 break;
3626 } 2554 }
2555
2556 default:
2557 dprintk(1, KERN_ERR
2558 "%s: VIDIOC_DQBUF - unsupported type %d\n",
2559 ZR_DEVNAME(zr), buf->type);
2560 res = -EINVAL;
3627 break; 2561 break;
2562 }
2563dqbuf_unlock_and_return:
2564 mutex_unlock(&zr->resource_lock);
3628 2565
3629 case VIDIOC_G_STD: 2566 return res;
3630 { 2567}
3631 v4l2_std_id *std = arg;
3632 int norm;
3633 2568
3634 dprintk(3, KERN_DEBUG "%s: VIDIOC_G_STD\n", ZR_DEVNAME(zr)); 2569static int zoran_streamon(struct file *file, void *__fh, enum v4l2_buf_type type)
2570{
2571 struct zoran_fh *fh = __fh;
2572 struct zoran *zr = fh->zr;
2573 int res = 0;
3635 2574
3636 mutex_lock(&zr->resource_lock); 2575 mutex_lock(&zr->resource_lock);
3637 norm = zr->norm;
3638 mutex_unlock(&zr->resource_lock);
3639 2576
3640 switch (norm) { 2577 switch (fh->map_mode) {
3641 case VIDEO_MODE_PAL: 2578 case ZORAN_MAP_MODE_RAW: /* raw capture */
3642 *std = V4L2_STD_PAL; 2579 if (zr->v4l_buffers.active != ZORAN_ACTIVE ||
3643 break; 2580 fh->buffers.active != ZORAN_ACTIVE) {
3644 case VIDEO_MODE_NTSC: 2581 res = -EBUSY;
3645 *std = V4L2_STD_NTSC; 2582 goto strmon_unlock_and_return;
3646 break;
3647 case VIDEO_MODE_SECAM:
3648 *std = V4L2_STD_SECAM;
3649 break;
3650 } 2583 }
3651 2584
3652 return 0; 2585 zr->v4l_buffers.active = fh->buffers.active = ZORAN_LOCKED;
3653 } 2586 zr->v4l_settings = fh->v4l_settings;
2587
2588 zr->v4l_sync_tail = zr->v4l_pend_tail;
2589 if (!zr->v4l_memgrab_active &&
2590 zr->v4l_pend_head != zr->v4l_pend_tail) {
2591 zr36057_set_memgrab(zr, 1);
2592 }
3654 break; 2593 break;
3655 2594
3656 case VIDIOC_S_STD: 2595 case ZORAN_MAP_MODE_JPG_REC:
3657 { 2596 case ZORAN_MAP_MODE_JPG_PLAY:
3658 int norm = -1, res = 0; 2597 /* what is the codec mode right now? */
3659 v4l2_std_id *std = arg; 2598 if (zr->jpg_buffers.active != ZORAN_ACTIVE ||
3660 2599 fh->buffers.active != ZORAN_ACTIVE) {
3661 dprintk(3, KERN_DEBUG "%s: VIDIOC_S_STD - norm=0x%llx\n", 2600 res = -EBUSY;
3662 ZR_DEVNAME(zr), (unsigned long long)*std); 2601 goto strmon_unlock_and_return;
3663
3664 if ((*std & V4L2_STD_PAL) && !(*std & ~V4L2_STD_PAL))
3665 norm = VIDEO_MODE_PAL;
3666 else if ((*std & V4L2_STD_NTSC) && !(*std & ~V4L2_STD_NTSC))
3667 norm = VIDEO_MODE_NTSC;
3668 else if ((*std & V4L2_STD_SECAM) && !(*std & ~V4L2_STD_SECAM))
3669 norm = VIDEO_MODE_SECAM;
3670 else if (*std == V4L2_STD_ALL)
3671 norm = VIDEO_MODE_AUTO;
3672 else {
3673 dprintk(1,
3674 KERN_ERR
3675 "%s: VIDIOC_S_STD - invalid norm 0x%llx\n",
3676 ZR_DEVNAME(zr), (unsigned long long)*std);
3677 return -EINVAL;
3678 } 2602 }
3679 2603
3680 mutex_lock(&zr->resource_lock); 2604 zr->jpg_buffers.active = fh->buffers.active = ZORAN_LOCKED;
3681 if ((res = zoran_set_norm(zr, norm)))
3682 goto sstd_unlock_and_return;
3683 2605
3684 res = wait_grab_pending(zr); 2606 if (zr->jpg_que_head != zr->jpg_que_tail) {
3685 sstd_unlock_and_return: 2607 /* Start the jpeg codec when the first frame is queued */
3686 mutex_unlock(&zr->resource_lock); 2608 jpeg_start(zr);
3687 return res; 2609 }
3688 }
3689 break; 2610 break;
3690 2611
3691 case VIDIOC_ENUMINPUT: 2612 default:
3692 { 2613 dprintk(1,
3693 struct v4l2_input *inp = arg; 2614 KERN_ERR
3694 int status; 2615 "%s: VIDIOC_STREAMON - invalid map mode %d\n",
3695 2616 ZR_DEVNAME(zr), fh->map_mode);
3696 dprintk(3, KERN_DEBUG "%s: VIDIOC_ENUMINPUT - index=%d\n", 2617 res = -EINVAL;
3697 ZR_DEVNAME(zr), inp->index); 2618 break;
2619 }
2620strmon_unlock_and_return:
2621 mutex_unlock(&zr->resource_lock);
3698 2622
3699 if (inp->index < 0 || inp->index >= zr->card.inputs) 2623 return res;
3700 return -EINVAL; 2624}
3701 else {
3702 int id = inp->index;
3703 memset(inp, 0, sizeof(*inp));
3704 inp->index = id;
3705 }
3706 2625
3707 strncpy(inp->name, zr->card.input[inp->index].name, 2626static int zoran_streamoff(struct file *file, void *__fh, enum v4l2_buf_type type)
3708 sizeof(inp->name) - 1); 2627{
3709 inp->type = V4L2_INPUT_TYPE_CAMERA; 2628 struct zoran_fh *fh = __fh;
3710 inp->std = V4L2_STD_ALL; 2629 struct zoran *zr = fh->zr;
2630 int i, res = 0;
2631 unsigned long flags;
3711 2632
3712 /* Get status of video decoder */ 2633 mutex_lock(&zr->resource_lock);
3713 mutex_lock(&zr->resource_lock);
3714 decoder_command(zr, DECODER_GET_STATUS, &status);
3715 mutex_unlock(&zr->resource_lock);
3716 2634
3717 if (!(status & DECODER_STATUS_GOOD)) { 2635 switch (fh->map_mode) {
3718 inp->status |= V4L2_IN_ST_NO_POWER; 2636 case ZORAN_MAP_MODE_RAW: /* raw capture */
3719 inp->status |= V4L2_IN_ST_NO_SIGNAL; 2637 if (fh->buffers.active == ZORAN_FREE &&
2638 zr->v4l_buffers.active != ZORAN_FREE) {
2639 res = -EPERM; /* stay off other's settings! */
2640 goto strmoff_unlock_and_return;
3720 } 2641 }
3721 if (!(status & DECODER_STATUS_COLOR)) 2642 if (zr->v4l_buffers.active == ZORAN_FREE)
3722 inp->status |= V4L2_IN_ST_NO_COLOR; 2643 goto strmoff_unlock_and_return;
3723 2644
3724 return 0; 2645 spin_lock_irqsave(&zr->spinlock, flags);
3725 } 2646 /* unload capture */
3726 break; 2647 if (zr->v4l_memgrab_active) {
3727 2648
3728 case VIDIOC_G_INPUT: 2649 zr36057_set_memgrab(zr, 0);
3729 { 2650 }
3730 int *input = arg;
3731 2651
3732 dprintk(3, KERN_DEBUG "%s: VIDIOC_G_INPUT\n", ZR_DEVNAME(zr)); 2652 for (i = 0; i < fh->buffers.num_buffers; i++)
2653 zr->v4l_buffers.buffer[i].state = BUZ_STATE_USER;
2654 fh->buffers = zr->v4l_buffers;
3733 2655
3734 mutex_lock(&zr->resource_lock); 2656 zr->v4l_buffers.active = fh->buffers.active = ZORAN_FREE;
3735 *input = zr->input;
3736 mutex_unlock(&zr->resource_lock);
3737 2657
3738 return 0; 2658 zr->v4l_grab_seq = 0;
3739 } 2659 zr->v4l_pend_head = zr->v4l_pend_tail = 0;
3740 break; 2660 zr->v4l_sync_tail = 0;
3741 2661
3742 case VIDIOC_S_INPUT: 2662 spin_unlock_irqrestore(&zr->spinlock, flags);
3743 {
3744 int *input = arg, res = 0;
3745 2663
3746 dprintk(3, KERN_DEBUG "%s: VIDIOC_S_INPUT - input=%d\n", 2664 break;
3747 ZR_DEVNAME(zr), *input);
3748 2665
3749 mutex_lock(&zr->resource_lock); 2666 case ZORAN_MAP_MODE_JPG_REC:
3750 if ((res = zoran_set_input(zr, *input))) 2667 case ZORAN_MAP_MODE_JPG_PLAY:
3751 goto sinput_unlock_and_return; 2668 if (fh->buffers.active == ZORAN_FREE &&
2669 zr->jpg_buffers.active != ZORAN_FREE) {
2670 res = -EPERM; /* stay off other's settings! */
2671 goto strmoff_unlock_and_return;
2672 }
2673 if (zr->jpg_buffers.active == ZORAN_FREE)
2674 goto strmoff_unlock_and_return;
3752 2675
3753 /* Make sure the changes come into effect */ 2676 res = jpg_qbuf(fh, -1,
3754 res = wait_grab_pending(zr); 2677 (fh->map_mode == ZORAN_MAP_MODE_JPG_REC) ?
3755 sinput_unlock_and_return: 2678 BUZ_MODE_MOTION_COMPRESS :
3756 mutex_unlock(&zr->resource_lock); 2679 BUZ_MODE_MOTION_DECOMPRESS);
3757 return res; 2680 if (res)
3758 } 2681 goto strmoff_unlock_and_return;
2682 break;
2683 default:
2684 dprintk(1, KERN_ERR
2685 "%s: VIDIOC_STREAMOFF - invalid map mode %d\n",
2686 ZR_DEVNAME(zr), fh->map_mode);
2687 res = -EINVAL;
3759 break; 2688 break;
2689 }
2690strmoff_unlock_and_return:
2691 mutex_unlock(&zr->resource_lock);
3760 2692
3761 case VIDIOC_ENUMOUTPUT: 2693 return res;
3762 { 2694}
3763 struct v4l2_output *outp = arg;
3764 2695
3765 dprintk(3, KERN_DEBUG "%s: VIDIOC_ENUMOUTPUT - index=%d\n", 2696static int zoran_queryctrl(struct file *file, void *__fh,
3766 ZR_DEVNAME(zr), outp->index); 2697 struct v4l2_queryctrl *ctrl)
2698{
2699 struct zoran_fh *fh = __fh;
2700 struct zoran *zr = fh->zr;
3767 2701
3768 if (outp->index != 0) 2702 /* we only support hue/saturation/contrast/brightness */
3769 return -EINVAL; 2703 if (ctrl->id < V4L2_CID_BRIGHTNESS ||
2704 ctrl->id > V4L2_CID_HUE)
2705 return -EINVAL;
3770 2706
3771 memset(outp, 0, sizeof(*outp)); 2707 decoder_call(zr, core, queryctrl, ctrl);
3772 outp->index = 0;
3773 outp->type = V4L2_OUTPUT_TYPE_ANALOGVGAOVERLAY;
3774 strncpy(outp->name, "Autodetect", sizeof(outp->name)-1);
3775 2708
3776 return 0; 2709 return 0;
3777 } 2710}
3778 break;
3779 2711
3780 case VIDIOC_G_OUTPUT: 2712static int zoran_g_ctrl(struct file *file, void *__fh, struct v4l2_control *ctrl)
3781 { 2713{
3782 int *output = arg; 2714 struct zoran_fh *fh = __fh;
2715 struct zoran *zr = fh->zr;
3783 2716
3784 dprintk(3, KERN_DEBUG "%s: VIDIOC_G_OUTPUT\n", ZR_DEVNAME(zr)); 2717 /* we only support hue/saturation/contrast/brightness */
2718 if (ctrl->id < V4L2_CID_BRIGHTNESS ||
2719 ctrl->id > V4L2_CID_HUE)
2720 return -EINVAL;
3785 2721
3786 *output = 0; 2722 mutex_lock(&zr->resource_lock);
2723 decoder_call(zr, core, g_ctrl, ctrl);
2724 mutex_unlock(&zr->resource_lock);
3787 2725
3788 return 0; 2726 return 0;
3789 } 2727}
3790 break;
3791 2728
3792 case VIDIOC_S_OUTPUT: 2729static int zoran_s_ctrl(struct file *file, void *__fh, struct v4l2_control *ctrl)
3793 { 2730{
3794 int *output = arg; 2731 struct zoran_fh *fh = __fh;
2732 struct zoran *zr = fh->zr;
3795 2733
3796 dprintk(3, KERN_DEBUG "%s: VIDIOC_S_OUTPUT - output=%d\n", 2734 /* we only support hue/saturation/contrast/brightness */
3797 ZR_DEVNAME(zr), *output); 2735 if (ctrl->id < V4L2_CID_BRIGHTNESS ||
2736 ctrl->id > V4L2_CID_HUE)
2737 return -EINVAL;
3798 2738
3799 if (*output != 0) 2739 mutex_lock(&zr->resource_lock);
3800 return -EINVAL; 2740 decoder_call(zr, core, s_ctrl, ctrl);
2741 mutex_unlock(&zr->resource_lock);
3801 2742
3802 return 0; 2743 return 0;
3803 } 2744}
3804 break;
3805 2745
3806 /* cropping (sub-frame capture) */ 2746static int zoran_g_std(struct file *file, void *__fh, v4l2_std_id *std)
3807 case VIDIOC_CROPCAP: 2747{
3808 { 2748 struct zoran_fh *fh = __fh;
3809 struct v4l2_cropcap *cropcap = arg; 2749 struct zoran *zr = fh->zr;
3810 int type = cropcap->type, res = 0;
3811 2750
3812 dprintk(3, KERN_ERR "%s: VIDIOC_CROPCAP - type=%d\n", 2751 mutex_lock(&zr->resource_lock);
3813 ZR_DEVNAME(zr), cropcap->type); 2752 *std = zr->norm;
2753 mutex_unlock(&zr->resource_lock);
2754 return 0;
2755}
3814 2756
3815 memset(cropcap, 0, sizeof(*cropcap)); 2757static int zoran_s_std(struct file *file, void *__fh, v4l2_std_id *std)
3816 cropcap->type = type; 2758{
2759 struct zoran_fh *fh = __fh;
2760 struct zoran *zr = fh->zr;
2761 int res = 0;
3817 2762
3818 mutex_lock(&zr->resource_lock); 2763 mutex_lock(&zr->resource_lock);
2764 res = zoran_set_norm(zr, *std);
2765 if (res)
2766 goto sstd_unlock_and_return;
3819 2767
3820 if (cropcap->type != V4L2_BUF_TYPE_VIDEO_OUTPUT && 2768 res = wait_grab_pending(zr);
3821 (cropcap->type != V4L2_BUF_TYPE_VIDEO_CAPTURE || 2769sstd_unlock_and_return:
3822 fh->map_mode == ZORAN_MAP_MODE_RAW)) { 2770 mutex_unlock(&zr->resource_lock);
3823 dprintk(1, 2771 return res;
3824 KERN_ERR 2772}
3825 "%s: VIDIOC_CROPCAP - subcapture only supported for compressed capture\n",
3826 ZR_DEVNAME(zr));
3827 res = -EINVAL;
3828 goto cropcap_unlock_and_return;
3829 }
3830 2773
3831 cropcap->bounds.top = cropcap->bounds.left = 0; 2774static int zoran_enum_input(struct file *file, void *__fh,
3832 cropcap->bounds.width = BUZ_MAX_WIDTH; 2775 struct v4l2_input *inp)
3833 cropcap->bounds.height = BUZ_MAX_HEIGHT; 2776{
3834 cropcap->defrect.top = cropcap->defrect.left = 0; 2777 struct zoran_fh *fh = __fh;
3835 cropcap->defrect.width = BUZ_MIN_WIDTH; 2778 struct zoran *zr = fh->zr;
3836 cropcap->defrect.height = BUZ_MIN_HEIGHT;
3837 cropcap_unlock_and_return:
3838 mutex_unlock(&zr->resource_lock);
3839 return res;
3840 }
3841 break;
3842 2779
3843 case VIDIOC_G_CROP: 2780 if (inp->index < 0 || inp->index >= zr->card.inputs)
3844 { 2781 return -EINVAL;
3845 struct v4l2_crop *crop = arg; 2782 else {
3846 int type = crop->type, res = 0; 2783 int id = inp->index;
2784 memset(inp, 0, sizeof(*inp));
2785 inp->index = id;
2786 }
3847 2787
3848 dprintk(3, KERN_ERR "%s: VIDIOC_G_CROP - type=%d\n", 2788 strncpy(inp->name, zr->card.input[inp->index].name,
3849 ZR_DEVNAME(zr), crop->type); 2789 sizeof(inp->name) - 1);
2790 inp->type = V4L2_INPUT_TYPE_CAMERA;
2791 inp->std = V4L2_STD_ALL;
3850 2792
3851 memset(crop, 0, sizeof(*crop)); 2793 /* Get status of video decoder */
3852 crop->type = type; 2794 mutex_lock(&zr->resource_lock);
2795 decoder_call(zr, video, g_input_status, &inp->status);
2796 mutex_unlock(&zr->resource_lock);
2797 return 0;
2798}
3853 2799
3854 mutex_lock(&zr->resource_lock); 2800static int zoran_g_input(struct file *file, void *__fh, unsigned int *input)
2801{
2802 struct zoran_fh *fh = __fh;
2803 struct zoran *zr = fh->zr;
3855 2804
3856 if (crop->type != V4L2_BUF_TYPE_VIDEO_OUTPUT && 2805 mutex_lock(&zr->resource_lock);
3857 (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE || 2806 *input = zr->input;
3858 fh->map_mode == ZORAN_MAP_MODE_RAW)) { 2807 mutex_unlock(&zr->resource_lock);
3859 dprintk(1,
3860 KERN_ERR
3861 "%s: VIDIOC_G_CROP - subcapture only supported for compressed capture\n",
3862 ZR_DEVNAME(zr));
3863 res = -EINVAL;
3864 goto gcrop_unlock_and_return;
3865 }
3866 2808
3867 crop->c.top = fh->jpg_settings.img_y; 2809 return 0;
3868 crop->c.left = fh->jpg_settings.img_x; 2810}
3869 crop->c.width = fh->jpg_settings.img_width;
3870 crop->c.height = fh->jpg_settings.img_height;
3871 2811
3872 gcrop_unlock_and_return: 2812static int zoran_s_input(struct file *file, void *__fh, unsigned int input)
3873 mutex_unlock(&zr->resource_lock); 2813{
2814 struct zoran_fh *fh = __fh;
2815 struct zoran *zr = fh->zr;
2816 int res;
3874 2817
3875 return res; 2818 mutex_lock(&zr->resource_lock);
3876 } 2819 res = zoran_set_input(zr, input);
3877 break; 2820 if (res)
2821 goto sinput_unlock_and_return;
3878 2822
3879 case VIDIOC_S_CROP: 2823 /* Make sure the changes come into effect */
3880 { 2824 res = wait_grab_pending(zr);
3881 struct v4l2_crop *crop = arg; 2825sinput_unlock_and_return:
3882 int res = 0; 2826 mutex_unlock(&zr->resource_lock);
2827 return res;
2828}
3883 2829
3884 settings = fh->jpg_settings; 2830static int zoran_enum_output(struct file *file, void *__fh,
2831 struct v4l2_output *outp)
2832{
2833 if (outp->index != 0)
2834 return -EINVAL;
3885 2835
3886 dprintk(3, 2836 memset(outp, 0, sizeof(*outp));
3887 KERN_ERR 2837 outp->index = 0;
3888 "%s: VIDIOC_S_CROP - type=%d, x=%d,y=%d,w=%d,h=%d\n", 2838 outp->type = V4L2_OUTPUT_TYPE_ANALOGVGAOVERLAY;
3889 ZR_DEVNAME(zr), crop->type, crop->c.left, crop->c.top, 2839 strncpy(outp->name, "Autodetect", sizeof(outp->name)-1);
3890 crop->c.width, crop->c.height);
3891 2840
3892 mutex_lock(&zr->resource_lock); 2841 return 0;
2842}
3893 2843
3894 if (fh->jpg_buffers.allocated || fh->v4l_buffers.allocated) { 2844static int zoran_g_output(struct file *file, void *__fh, unsigned int *output)
3895 dprintk(1, 2845{
3896 KERN_ERR 2846 *output = 0;
3897 "%s: VIDIOC_S_CROP - cannot change settings while active\n",
3898 ZR_DEVNAME(zr));
3899 res = -EBUSY;
3900 goto scrop_unlock_and_return;
3901 }
3902 2847
3903 if (crop->type != V4L2_BUF_TYPE_VIDEO_OUTPUT && 2848 return 0;
3904 (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE || 2849}
3905 fh->map_mode == ZORAN_MAP_MODE_RAW)) {
3906 dprintk(1,
3907 KERN_ERR
3908 "%s: VIDIOC_G_CROP - subcapture only supported for compressed capture\n",
3909 ZR_DEVNAME(zr));
3910 res = -EINVAL;
3911 goto scrop_unlock_and_return;
3912 }
3913 2850
3914 /* move into a form that we understand */ 2851static int zoran_s_output(struct file *file, void *__fh, unsigned int output)
3915 settings.img_x = crop->c.left; 2852{
3916 settings.img_y = crop->c.top; 2853 if (output != 0)
3917 settings.img_width = crop->c.width; 2854 return -EINVAL;
3918 settings.img_height = crop->c.height;
3919 2855
3920 /* check validity */ 2856 return 0;
3921 if ((res = zoran_check_jpg_settings(zr, &settings))) 2857}
3922 goto scrop_unlock_and_return;
3923 2858
3924 /* accept */ 2859/* cropping (sub-frame capture) */
3925 fh->jpg_settings = settings; 2860static int zoran_cropcap(struct file *file, void *__fh,
2861 struct v4l2_cropcap *cropcap)
2862{
2863 struct zoran_fh *fh = __fh;
2864 struct zoran *zr = fh->zr;
2865 int type = cropcap->type, res = 0;
3926 2866
3927 scrop_unlock_and_return: 2867 memset(cropcap, 0, sizeof(*cropcap));
3928 mutex_unlock(&zr->resource_lock); 2868 cropcap->type = type;
3929 return res;
3930 }
3931 break;
3932 2869
3933 case VIDIOC_G_JPEGCOMP: 2870 mutex_lock(&zr->resource_lock);
3934 {
3935 struct v4l2_jpegcompression *params = arg;
3936 2871
3937 dprintk(3, KERN_DEBUG "%s: VIDIOC_G_JPEGCOMP\n", 2872 if (cropcap->type != V4L2_BUF_TYPE_VIDEO_OUTPUT &&
2873 (cropcap->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
2874 fh->map_mode == ZORAN_MAP_MODE_RAW)) {
2875 dprintk(1, KERN_ERR
2876 "%s: VIDIOC_CROPCAP - subcapture only supported for compressed capture\n",
3938 ZR_DEVNAME(zr)); 2877 ZR_DEVNAME(zr));
2878 res = -EINVAL;
2879 goto cropcap_unlock_and_return;
2880 }
3939 2881
3940 memset(params, 0, sizeof(*params)); 2882 cropcap->bounds.top = cropcap->bounds.left = 0;
2883 cropcap->bounds.width = BUZ_MAX_WIDTH;
2884 cropcap->bounds.height = BUZ_MAX_HEIGHT;
2885 cropcap->defrect.top = cropcap->defrect.left = 0;
2886 cropcap->defrect.width = BUZ_MIN_WIDTH;
2887 cropcap->defrect.height = BUZ_MIN_HEIGHT;
2888cropcap_unlock_and_return:
2889 mutex_unlock(&zr->resource_lock);
2890 return res;
2891}
3941 2892
3942 mutex_lock(&zr->resource_lock); 2893static int zoran_g_crop(struct file *file, void *__fh, struct v4l2_crop *crop)
2894{
2895 struct zoran_fh *fh = __fh;
2896 struct zoran *zr = fh->zr;
2897 int type = crop->type, res = 0;
3943 2898
3944 params->quality = fh->jpg_settings.jpg_comp.quality; 2899 memset(crop, 0, sizeof(*crop));
3945 params->APPn = fh->jpg_settings.jpg_comp.APPn; 2900 crop->type = type;
3946 memcpy(params->APP_data,
3947 fh->jpg_settings.jpg_comp.APP_data,
3948 fh->jpg_settings.jpg_comp.APP_len);
3949 params->APP_len = fh->jpg_settings.jpg_comp.APP_len;
3950 memcpy(params->COM_data,
3951 fh->jpg_settings.jpg_comp.COM_data,
3952 fh->jpg_settings.jpg_comp.COM_len);
3953 params->COM_len = fh->jpg_settings.jpg_comp.COM_len;
3954 params->jpeg_markers =
3955 fh->jpg_settings.jpg_comp.jpeg_markers;
3956 2901
3957 mutex_unlock(&zr->resource_lock); 2902 mutex_lock(&zr->resource_lock);
3958 2903
3959 return 0; 2904 if (crop->type != V4L2_BUF_TYPE_VIDEO_OUTPUT &&
2905 (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
2906 fh->map_mode == ZORAN_MAP_MODE_RAW)) {
2907 dprintk(1,
2908 KERN_ERR
2909 "%s: VIDIOC_G_CROP - subcapture only supported for compressed capture\n",
2910 ZR_DEVNAME(zr));
2911 res = -EINVAL;
2912 goto gcrop_unlock_and_return;
3960 } 2913 }
3961 break;
3962
3963 case VIDIOC_S_JPEGCOMP:
3964 {
3965 struct v4l2_jpegcompression *params = arg;
3966 int res = 0;
3967 2914
3968 settings = fh->jpg_settings; 2915 crop->c.top = fh->jpg_settings.img_y;
2916 crop->c.left = fh->jpg_settings.img_x;
2917 crop->c.width = fh->jpg_settings.img_width;
2918 crop->c.height = fh->jpg_settings.img_height;
3969 2919
3970 dprintk(3, 2920gcrop_unlock_and_return:
3971 KERN_DEBUG 2921 mutex_unlock(&zr->resource_lock);
3972 "%s: VIDIOC_S_JPEGCOMP - quality=%d, APPN=%d, APP_len=%d, COM_len=%d\n",
3973 ZR_DEVNAME(zr), params->quality, params->APPn,
3974 params->APP_len, params->COM_len);
3975 2922
3976 settings.jpg_comp = *params; 2923 return res;
2924}
3977 2925
3978 mutex_lock(&zr->resource_lock); 2926static int zoran_s_crop(struct file *file, void *__fh, struct v4l2_crop *crop)
2927{
2928 struct zoran_fh *fh = __fh;
2929 struct zoran *zr = fh->zr;
2930 int res = 0;
2931 struct zoran_jpg_settings settings;
3979 2932
3980 if (fh->v4l_buffers.active != ZORAN_FREE || 2933 settings = fh->jpg_settings;
3981 fh->jpg_buffers.active != ZORAN_FREE) {
3982 dprintk(1,
3983 KERN_WARNING
3984 "%s: VIDIOC_S_JPEGCOMP called while in playback/capture mode\n",
3985 ZR_DEVNAME(zr));
3986 res = -EBUSY;
3987 goto sjpegc_unlock_and_return;
3988 }
3989 2934
3990 if ((res = zoran_check_jpg_settings(zr, &settings))) 2935 mutex_lock(&zr->resource_lock);
3991 goto sjpegc_unlock_and_return;
3992 if (!fh->jpg_buffers.allocated)
3993 fh->jpg_buffers.buffer_size =
3994 zoran_v4l2_calc_bufsize(&fh->jpg_settings);
3995 fh->jpg_settings.jpg_comp = *params = settings.jpg_comp;
3996 sjpegc_unlock_and_return:
3997 mutex_unlock(&zr->resource_lock);
3998 2936
3999 return 0; 2937 if (fh->buffers.allocated) {
2938 dprintk(1, KERN_ERR
2939 "%s: VIDIOC_S_CROP - cannot change settings while active\n",
2940 ZR_DEVNAME(zr));
2941 res = -EBUSY;
2942 goto scrop_unlock_and_return;
4000 } 2943 }
4001 break;
4002 2944
4003 case VIDIOC_QUERYSTD: /* why is this useful? */ 2945 if (crop->type != V4L2_BUF_TYPE_VIDEO_OUTPUT &&
4004 { 2946 (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
4005 v4l2_std_id *std = arg; 2947 fh->map_mode == ZORAN_MAP_MODE_RAW)) {
4006 2948 dprintk(1, KERN_ERR
4007 dprintk(3, 2949 "%s: VIDIOC_G_CROP - subcapture only supported for compressed capture\n",
4008 KERN_DEBUG "%s: VIDIOC_QUERY_STD - std=0x%llx\n", 2950 ZR_DEVNAME(zr));
4009 ZR_DEVNAME(zr), (unsigned long long)*std); 2951 res = -EINVAL;
4010 2952 goto scrop_unlock_and_return;
4011 if (*std == V4L2_STD_ALL || *std == V4L2_STD_NTSC ||
4012 *std == V4L2_STD_PAL || (*std == V4L2_STD_SECAM &&
4013 zr->card.norms == 3)) {
4014 return 0;
4015 }
4016
4017 return -EINVAL;
4018 } 2953 }
4019 break;
4020 2954
4021 case VIDIOC_TRY_FMT: 2955 /* move into a form that we understand */
4022 { 2956 settings.img_x = crop->c.left;
4023 struct v4l2_format *fmt = arg; 2957 settings.img_y = crop->c.top;
4024 int res = 0; 2958 settings.img_width = crop->c.width;
2959 settings.img_height = crop->c.height;
4025 2960
4026 dprintk(3, KERN_DEBUG "%s: VIDIOC_TRY_FMT - type=%d\n", 2961 /* check validity */
4027 ZR_DEVNAME(zr), fmt->type); 2962 res = zoran_check_jpg_settings(zr, &settings, 0);
2963 if (res)
2964 goto scrop_unlock_and_return;
4028 2965
4029 switch (fmt->type) { 2966 /* accept */
4030 case V4L2_BUF_TYPE_VIDEO_OVERLAY: 2967 fh->jpg_settings = settings;
4031 mutex_lock(&zr->resource_lock);
4032 2968
4033 if (fmt->fmt.win.w.width > BUZ_MAX_WIDTH) 2969scrop_unlock_and_return:
4034 fmt->fmt.win.w.width = BUZ_MAX_WIDTH; 2970 mutex_unlock(&zr->resource_lock);
4035 if (fmt->fmt.win.w.width < BUZ_MIN_WIDTH) 2971 return res;
4036 fmt->fmt.win.w.width = BUZ_MIN_WIDTH; 2972}
4037 if (fmt->fmt.win.w.height > BUZ_MAX_HEIGHT)
4038 fmt->fmt.win.w.height = BUZ_MAX_HEIGHT;
4039 if (fmt->fmt.win.w.height < BUZ_MIN_HEIGHT)
4040 fmt->fmt.win.w.height = BUZ_MIN_HEIGHT;
4041 2973
4042 mutex_unlock(&zr->resource_lock); 2974static int zoran_g_jpegcomp(struct file *file, void *__fh,
4043 break; 2975 struct v4l2_jpegcompression *params)
2976{
2977 struct zoran_fh *fh = __fh;
2978 struct zoran *zr = fh->zr;
2979 memset(params, 0, sizeof(*params));
4044 2980
4045 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 2981 mutex_lock(&zr->resource_lock);
4046 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
4047 if (fmt->fmt.pix.bytesperline > 0)
4048 return -EINVAL;
4049 2982
4050 mutex_lock(&zr->resource_lock); 2983 params->quality = fh->jpg_settings.jpg_comp.quality;
4051 2984 params->APPn = fh->jpg_settings.jpg_comp.APPn;
4052 if (fmt->fmt.pix.pixelformat == V4L2_PIX_FMT_MJPEG) { 2985 memcpy(params->APP_data,
4053 settings = fh->jpg_settings; 2986 fh->jpg_settings.jpg_comp.APP_data,
4054 2987 fh->jpg_settings.jpg_comp.APP_len);
4055 /* we actually need to set 'real' parameters now */ 2988 params->APP_len = fh->jpg_settings.jpg_comp.APP_len;
4056 if ((fmt->fmt.pix.height * 2) > 2989 memcpy(params->COM_data,
4057 BUZ_MAX_HEIGHT) 2990 fh->jpg_settings.jpg_comp.COM_data,
4058 settings.TmpDcm = 1; 2991 fh->jpg_settings.jpg_comp.COM_len);
4059 else 2992 params->COM_len = fh->jpg_settings.jpg_comp.COM_len;
4060 settings.TmpDcm = 2; 2993 params->jpeg_markers =
4061 settings.decimation = 0; 2994 fh->jpg_settings.jpg_comp.jpeg_markers;
4062 if (fmt->fmt.pix.height <=
4063 fh->jpg_settings.img_height / 2)
4064 settings.VerDcm = 2;
4065 else
4066 settings.VerDcm = 1;
4067 if (fmt->fmt.pix.width <=
4068 fh->jpg_settings.img_width / 4)
4069 settings.HorDcm = 4;
4070 else if (fmt->fmt.pix.width <=
4071 fh->jpg_settings.img_width / 2)
4072 settings.HorDcm = 2;
4073 else
4074 settings.HorDcm = 1;
4075 if (settings.TmpDcm == 1)
4076 settings.field_per_buff = 2;
4077 else
4078 settings.field_per_buff = 1;
4079
4080 /* check */
4081 if ((res =
4082 zoran_check_jpg_settings(zr,
4083 &settings)))
4084 goto tryfmt_unlock_and_return;
4085
4086 /* tell the user what we actually did */
4087 fmt->fmt.pix.width =
4088 settings.img_width / settings.HorDcm;
4089 fmt->fmt.pix.height =
4090 settings.img_height * 2 /
4091 (settings.TmpDcm * settings.VerDcm);
4092 if (settings.TmpDcm == 1)
4093 fmt->fmt.pix.field =
4094 (fh->jpg_settings.
4095 odd_even ? V4L2_FIELD_SEQ_TB :
4096 V4L2_FIELD_SEQ_BT);
4097 else
4098 fmt->fmt.pix.field =
4099 (fh->jpg_settings.
4100 odd_even ? V4L2_FIELD_TOP :
4101 V4L2_FIELD_BOTTOM);
4102
4103 fmt->fmt.pix.sizeimage =
4104 zoran_v4l2_calc_bufsize(&settings);
4105 } else if (fmt->type ==
4106 V4L2_BUF_TYPE_VIDEO_CAPTURE) {
4107 int i;
4108
4109 for (i = 0; i < NUM_FORMATS; i++)
4110 if (zoran_formats[i].fourcc ==
4111 fmt->fmt.pix.pixelformat)
4112 break;
4113 if (i == NUM_FORMATS) {
4114 res = -EINVAL;
4115 goto tryfmt_unlock_and_return;
4116 }
4117 2995
4118 if (fmt->fmt.pix.width > BUZ_MAX_WIDTH) 2996 mutex_unlock(&zr->resource_lock);
4119 fmt->fmt.pix.width = BUZ_MAX_WIDTH;
4120 if (fmt->fmt.pix.width < BUZ_MIN_WIDTH)
4121 fmt->fmt.pix.width = BUZ_MIN_WIDTH;
4122 if (fmt->fmt.pix.height > BUZ_MAX_HEIGHT)
4123 fmt->fmt.pix.height =
4124 BUZ_MAX_HEIGHT;
4125 if (fmt->fmt.pix.height < BUZ_MIN_HEIGHT)
4126 fmt->fmt.pix.height =
4127 BUZ_MIN_HEIGHT;
4128 } else {
4129 res = -EINVAL;
4130 goto tryfmt_unlock_and_return;
4131 }
4132 tryfmt_unlock_and_return:
4133 mutex_unlock(&zr->resource_lock);
4134 2997
4135 return res; 2998 return 0;
4136 break; 2999}
4137 3000
4138 default: 3001static int zoran_s_jpegcomp(struct file *file, void *__fh,
4139 return -EINVAL; 3002 struct v4l2_jpegcompression *params)
4140 } 3003{
3004 struct zoran_fh *fh = __fh;
3005 struct zoran *zr = fh->zr;
3006 int res = 0;
3007 struct zoran_jpg_settings settings;
4141 3008
4142 return 0; 3009 settings = fh->jpg_settings;
4143 }
4144 break;
4145 3010
4146 default: 3011 settings.jpg_comp = *params;
4147 dprintk(1, KERN_DEBUG "%s: UNKNOWN ioctl cmd: 0x%x\n", 3012
4148 ZR_DEVNAME(zr), cmd); 3013 mutex_lock(&zr->resource_lock);
4149 return -ENOIOCTLCMD;
4150 break;
4151 3014
3015 if (fh->buffers.active != ZORAN_FREE) {
3016 dprintk(1, KERN_WARNING
3017 "%s: VIDIOC_S_JPEGCOMP called while in playback/capture mode\n",
3018 ZR_DEVNAME(zr));
3019 res = -EBUSY;
3020 goto sjpegc_unlock_and_return;
4152 } 3021 }
4153 return 0;
4154}
4155 3022
3023 res = zoran_check_jpg_settings(zr, &settings, 0);
3024 if (res)
3025 goto sjpegc_unlock_and_return;
3026 if (!fh->buffers.allocated)
3027 fh->buffers.buffer_size =
3028 zoran_v4l2_calc_bufsize(&fh->jpg_settings);
3029 fh->jpg_settings.jpg_comp = *params = settings.jpg_comp;
3030sjpegc_unlock_and_return:
3031 mutex_unlock(&zr->resource_lock);
4156 3032
4157static long 3033 return res;
4158zoran_ioctl(struct file *file,
4159 unsigned int cmd,
4160 unsigned long arg)
4161{
4162 return video_usercopy(file, cmd, arg, zoran_do_ioctl);
4163} 3034}
4164 3035
4165static unsigned int 3036static unsigned int
@@ -4191,11 +3062,11 @@ zoran_poll (struct file *file,
4191 KERN_DEBUG 3062 KERN_DEBUG
4192 "%s: %s() raw - active=%c, sync_tail=%lu/%c, pend_tail=%lu, pend_head=%lu\n", 3063 "%s: %s() raw - active=%c, sync_tail=%lu/%c, pend_tail=%lu, pend_head=%lu\n",
4193 ZR_DEVNAME(zr), __func__, 3064 ZR_DEVNAME(zr), __func__,
4194 "FAL"[fh->v4l_buffers.active], zr->v4l_sync_tail, 3065 "FAL"[fh->buffers.active], zr->v4l_sync_tail,
4195 "UPMD"[zr->v4l_buffers.buffer[frame].state], 3066 "UPMD"[zr->v4l_buffers.buffer[frame].state],
4196 zr->v4l_pend_tail, zr->v4l_pend_head); 3067 zr->v4l_pend_tail, zr->v4l_pend_head);
4197 /* Process is the one capturing? */ 3068 /* Process is the one capturing? */
4198 if (fh->v4l_buffers.active != ZORAN_FREE && 3069 if (fh->buffers.active != ZORAN_FREE &&
4199 /* Buffer ready to DQBUF? */ 3070 /* Buffer ready to DQBUF? */
4200 zr->v4l_buffers.buffer[frame].state == BUZ_STATE_DONE) 3071 zr->v4l_buffers.buffer[frame].state == BUZ_STATE_DONE)
4201 res = POLLIN | POLLRDNORM; 3072 res = POLLIN | POLLRDNORM;
@@ -4213,10 +3084,10 @@ zoran_poll (struct file *file,
4213 KERN_DEBUG 3084 KERN_DEBUG
4214 "%s: %s() jpg - active=%c, que_tail=%lu/%c, que_head=%lu, dma=%lu/%lu\n", 3085 "%s: %s() jpg - active=%c, que_tail=%lu/%c, que_head=%lu, dma=%lu/%lu\n",
4215 ZR_DEVNAME(zr), __func__, 3086 ZR_DEVNAME(zr), __func__,
4216 "FAL"[fh->jpg_buffers.active], zr->jpg_que_tail, 3087 "FAL"[fh->buffers.active], zr->jpg_que_tail,
4217 "UPMD"[zr->jpg_buffers.buffer[frame].state], 3088 "UPMD"[zr->jpg_buffers.buffer[frame].state],
4218 zr->jpg_que_head, zr->jpg_dma_tail, zr->jpg_dma_head); 3089 zr->jpg_que_head, zr->jpg_dma_tail, zr->jpg_dma_head);
4219 if (fh->jpg_buffers.active != ZORAN_FREE && 3090 if (fh->buffers.active != ZORAN_FREE &&
4220 zr->jpg_buffers.buffer[frame].state == BUZ_STATE_DONE) { 3091 zr->jpg_buffers.buffer[frame].state == BUZ_STATE_DONE) {
4221 if (fh->map_mode == ZORAN_MAP_MODE_JPG_REC) 3092 if (fh->map_mode == ZORAN_MAP_MODE_JPG_REC)
4222 res = POLLIN | POLLRDNORM; 3093 res = POLLIN | POLLRDNORM;
@@ -4230,8 +3101,8 @@ zoran_poll (struct file *file,
4230 default: 3101 default:
4231 dprintk(1, 3102 dprintk(1,
4232 KERN_ERR 3103 KERN_ERR
4233 "%s: zoran_poll() - internal error, unknown map_mode=%d\n", 3104 "%s: %s - internal error, unknown map_mode=%d\n",
4234 ZR_DEVNAME(zr), fh->map_mode); 3105 ZR_DEVNAME(zr), __func__, fh->map_mode);
4235 res = POLLNVAL; 3106 res = POLLNVAL;
4236 } 3107 }
4237 3108
@@ -4265,98 +3136,53 @@ static void
4265zoran_vm_close (struct vm_area_struct *vma) 3136zoran_vm_close (struct vm_area_struct *vma)
4266{ 3137{
4267 struct zoran_mapping *map = vma->vm_private_data; 3138 struct zoran_mapping *map = vma->vm_private_data;
4268 struct file *file = map->file; 3139 struct zoran_fh *fh = map->file->private_data;
4269 struct zoran_fh *fh = file->private_data;
4270 struct zoran *zr = fh->zr; 3140 struct zoran *zr = fh->zr;
4271 int i; 3141 int i;
4272 3142
4273 map->count--; 3143 if (--map->count > 0)
4274 if (map->count == 0) { 3144 return;
4275 switch (fh->map_mode) {
4276 case ZORAN_MAP_MODE_JPG_REC:
4277 case ZORAN_MAP_MODE_JPG_PLAY:
4278
4279 dprintk(3, KERN_INFO "%s: munmap(MJPEG)\n",
4280 ZR_DEVNAME(zr));
4281 3145
4282 for (i = 0; i < fh->jpg_buffers.num_buffers; i++) { 3146 dprintk(3, KERN_INFO "%s: %s - munmap(%s)\n", ZR_DEVNAME(zr),
4283 if (fh->jpg_buffers.buffer[i].map == map) { 3147 __func__, mode_name(fh->map_mode));
4284 fh->jpg_buffers.buffer[i].map =
4285 NULL;
4286 }
4287 }
4288 kfree(map);
4289
4290 for (i = 0; i < fh->jpg_buffers.num_buffers; i++)
4291 if (fh->jpg_buffers.buffer[i].map)
4292 break;
4293 if (i == fh->jpg_buffers.num_buffers) {
4294 mutex_lock(&zr->resource_lock);
4295
4296 if (fh->jpg_buffers.active != ZORAN_FREE) {
4297 jpg_qbuf(file, -1, zr->codec_mode);
4298 zr->jpg_buffers.allocated = 0;
4299 zr->jpg_buffers.active =
4300 fh->jpg_buffers.active =
4301 ZORAN_FREE;
4302 }
4303 //jpg_fbuffer_free(file);
4304 fh->jpg_buffers.allocated = 0;
4305 fh->jpg_buffers.ready_to_be_freed = 1;
4306
4307 mutex_unlock(&zr->resource_lock);
4308 }
4309 3148
4310 break; 3149 for (i = 0; i < fh->buffers.num_buffers; i++) {
4311 3150 if (fh->buffers.buffer[i].map == map)
4312 case ZORAN_MAP_MODE_RAW: 3151 fh->buffers.buffer[i].map = NULL;
4313 3152 }
4314 dprintk(3, KERN_INFO "%s: munmap(V4L)\n", 3153 kfree(map);
4315 ZR_DEVNAME(zr));
4316
4317 for (i = 0; i < fh->v4l_buffers.num_buffers; i++) {
4318 if (fh->v4l_buffers.buffer[i].map == map) {
4319 /* unqueue/unmap */
4320 fh->v4l_buffers.buffer[i].map =
4321 NULL;
4322 }
4323 }
4324 kfree(map);
4325 3154
4326 for (i = 0; i < fh->v4l_buffers.num_buffers; i++) 3155 /* Any buffers still mapped? */
4327 if (fh->v4l_buffers.buffer[i].map) 3156 for (i = 0; i < fh->buffers.num_buffers; i++)
4328 break; 3157 if (fh->buffers.buffer[i].map)
4329 if (i == fh->v4l_buffers.num_buffers) { 3158 return;
4330 mutex_lock(&zr->resource_lock);
4331
4332 if (fh->v4l_buffers.active != ZORAN_FREE) {
4333 unsigned long flags;
4334
4335 spin_lock_irqsave(&zr->spinlock, flags);
4336 zr36057_set_memgrab(zr, 0);
4337 zr->v4l_buffers.allocated = 0;
4338 zr->v4l_buffers.active =
4339 fh->v4l_buffers.active =
4340 ZORAN_FREE;
4341 spin_unlock_irqrestore(&zr->spinlock, flags);
4342 }
4343 //v4l_fbuffer_free(file);
4344 fh->v4l_buffers.allocated = 0;
4345 fh->v4l_buffers.ready_to_be_freed = 1;
4346 3159
4347 mutex_unlock(&zr->resource_lock); 3160 dprintk(3, KERN_INFO "%s: %s - free %s buffers\n", ZR_DEVNAME(zr),
4348 } 3161 __func__, mode_name(fh->map_mode));
4349 3162
4350 break; 3163 mutex_lock(&zr->resource_lock);
4351 3164
4352 default: 3165 if (fh->map_mode == ZORAN_MAP_MODE_RAW) {
4353 printk(KERN_ERR 3166 if (fh->buffers.active != ZORAN_FREE) {
4354 "%s: munmap() - internal error - unknown map mode %d\n", 3167 unsigned long flags;
4355 ZR_DEVNAME(zr), fh->map_mode);
4356 break;
4357 3168
3169 spin_lock_irqsave(&zr->spinlock, flags);
3170 zr36057_set_memgrab(zr, 0);
3171 zr->v4l_buffers.allocated = 0;
3172 zr->v4l_buffers.active = fh->buffers.active = ZORAN_FREE;
3173 spin_unlock_irqrestore(&zr->spinlock, flags);
4358 } 3174 }
3175 v4l_fbuffer_free(fh);
3176 } else {
3177 if (fh->buffers.active != ZORAN_FREE) {
3178 jpg_qbuf(fh, -1, zr->codec_mode);
3179 zr->jpg_buffers.allocated = 0;
3180 zr->jpg_buffers.active = fh->buffers.active = ZORAN_FREE;
3181 }
3182 jpg_fbuffer_free(fh);
4359 } 3183 }
3184
3185 mutex_unlock(&zr->resource_lock);
4360} 3186}
4361 3187
4362static struct vm_operations_struct zoran_vm_ops = { 3188static struct vm_operations_struct zoran_vm_ops = {
@@ -4379,90 +3205,106 @@ zoran_mmap (struct file *file,
4379 int res = 0; 3205 int res = 0;
4380 3206
4381 dprintk(3, 3207 dprintk(3,
4382 KERN_INFO "%s: mmap(%s) of 0x%08lx-0x%08lx (size=%lu)\n", 3208 KERN_INFO "%s: %s(%s) of 0x%08lx-0x%08lx (size=%lu)\n",
4383 ZR_DEVNAME(zr), 3209 ZR_DEVNAME(zr), __func__,
4384 fh->map_mode == ZORAN_MAP_MODE_RAW ? "V4L" : "MJPEG", 3210 mode_name(fh->map_mode), vma->vm_start, vma->vm_end, size);
4385 vma->vm_start, vma->vm_end, size);
4386 3211
4387 if (!(vma->vm_flags & VM_SHARED) || !(vma->vm_flags & VM_READ) || 3212 if (!(vma->vm_flags & VM_SHARED) || !(vma->vm_flags & VM_READ) ||
4388 !(vma->vm_flags & VM_WRITE)) { 3213 !(vma->vm_flags & VM_WRITE)) {
4389 dprintk(1, 3214 dprintk(1,
4390 KERN_ERR 3215 KERN_ERR
4391 "%s: mmap() - no MAP_SHARED/PROT_{READ,WRITE} given\n", 3216 "%s: %s - no MAP_SHARED/PROT_{READ,WRITE} given\n",
4392 ZR_DEVNAME(zr)); 3217 ZR_DEVNAME(zr), __func__);
4393 return -EINVAL; 3218 return -EINVAL;
4394 } 3219 }
4395 3220
4396 switch (fh->map_mode) { 3221 mutex_lock(&zr->resource_lock);
4397 3222
4398 case ZORAN_MAP_MODE_JPG_REC: 3223 if (!fh->buffers.allocated) {
4399 case ZORAN_MAP_MODE_JPG_PLAY: 3224 dprintk(1,
3225 KERN_ERR
3226 "%s: %s(%s) - buffers not yet allocated\n",
3227 ZR_DEVNAME(zr), __func__, mode_name(fh->map_mode));
3228 res = -ENOMEM;
3229 goto mmap_unlock_and_return;
3230 }
4400 3231
4401 /* lock */ 3232 first = offset / fh->buffers.buffer_size;
4402 mutex_lock(&zr->resource_lock); 3233 last = first - 1 + size / fh->buffers.buffer_size;
3234 if (offset % fh->buffers.buffer_size != 0 ||
3235 size % fh->buffers.buffer_size != 0 || first < 0 ||
3236 last < 0 || first >= fh->buffers.num_buffers ||
3237 last >= fh->buffers.buffer_size) {
3238 dprintk(1,
3239 KERN_ERR
3240 "%s: %s(%s) - offset=%lu or size=%lu invalid for bufsize=%d and numbufs=%d\n",
3241 ZR_DEVNAME(zr), __func__, mode_name(fh->map_mode), offset, size,
3242 fh->buffers.buffer_size,
3243 fh->buffers.num_buffers);
3244 res = -EINVAL;
3245 goto mmap_unlock_and_return;
3246 }
4403 3247
4404 /* Map the MJPEG buffers */ 3248 /* Check if any buffers are already mapped */
4405 if (!fh->jpg_buffers.allocated) { 3249 for (i = first; i <= last; i++) {
3250 if (fh->buffers.buffer[i].map) {
4406 dprintk(1, 3251 dprintk(1,
4407 KERN_ERR 3252 KERN_ERR
4408 "%s: zoran_mmap(MJPEG) - buffers not yet allocated\n", 3253 "%s: %s(%s) - buffer %d already mapped\n",
4409 ZR_DEVNAME(zr)); 3254 ZR_DEVNAME(zr), __func__, mode_name(fh->map_mode), i);
4410 res = -ENOMEM; 3255 res = -EBUSY;
4411 goto jpg_mmap_unlock_and_return; 3256 goto mmap_unlock_and_return;
4412 } 3257 }
3258 }
4413 3259
4414 first = offset / fh->jpg_buffers.buffer_size; 3260 /* map these buffers */
4415 last = first - 1 + size / fh->jpg_buffers.buffer_size; 3261 map = kmalloc(sizeof(struct zoran_mapping), GFP_KERNEL);
4416 if (offset % fh->jpg_buffers.buffer_size != 0 || 3262 if (!map) {
4417 size % fh->jpg_buffers.buffer_size != 0 || first < 0 || 3263 res = -ENOMEM;
4418 last < 0 || first >= fh->jpg_buffers.num_buffers || 3264 goto mmap_unlock_and_return;
4419 last >= fh->jpg_buffers.num_buffers) { 3265 }
4420 dprintk(1, 3266 map->file = file;
4421 KERN_ERR 3267 map->count = 1;
4422 "%s: mmap(MJPEG) - offset=%lu or size=%lu invalid for bufsize=%d and numbufs=%d\n", 3268
4423 ZR_DEVNAME(zr), offset, size, 3269 vma->vm_ops = &zoran_vm_ops;
4424 fh->jpg_buffers.buffer_size, 3270 vma->vm_flags |= VM_DONTEXPAND;
4425 fh->jpg_buffers.num_buffers); 3271 vma->vm_private_data = map;
4426 res = -EINVAL; 3272
4427 goto jpg_mmap_unlock_and_return; 3273 if (fh->map_mode == ZORAN_MAP_MODE_RAW) {
4428 }
4429 for (i = first; i <= last; i++) { 3274 for (i = first; i <= last; i++) {
4430 if (fh->jpg_buffers.buffer[i].map) { 3275 todo = size;
3276 if (todo > fh->buffers.buffer_size)
3277 todo = fh->buffers.buffer_size;
3278 page = fh->buffers.buffer[i].v4l.fbuffer_phys;
3279 if (remap_pfn_range(vma, start, page >> PAGE_SHIFT,
3280 todo, PAGE_SHARED)) {
4431 dprintk(1, 3281 dprintk(1,
4432 KERN_ERR 3282 KERN_ERR
4433 "%s: mmap(MJPEG) - buffer %d already mapped\n", 3283 "%s: %s(V4L) - remap_pfn_range failed\n",
4434 ZR_DEVNAME(zr), i); 3284 ZR_DEVNAME(zr), __func__);
4435 res = -EBUSY; 3285 res = -EAGAIN;
4436 goto jpg_mmap_unlock_and_return; 3286 goto mmap_unlock_and_return;
4437 } 3287 }
3288 size -= todo;
3289 start += todo;
3290 fh->buffers.buffer[i].map = map;
3291 if (size == 0)
3292 break;
4438 } 3293 }
4439 3294 } else {
4440 /* map these buffers (v4l_buffers[i]) */
4441 map = kmalloc(sizeof(struct zoran_mapping), GFP_KERNEL);
4442 if (!map) {
4443 res = -ENOMEM;
4444 goto jpg_mmap_unlock_and_return;
4445 }
4446 map->file = file;
4447 map->count = 1;
4448
4449 vma->vm_ops = &zoran_vm_ops;
4450 vma->vm_flags |= VM_DONTEXPAND;
4451 vma->vm_private_data = map;
4452
4453 for (i = first; i <= last; i++) { 3295 for (i = first; i <= last; i++) {
4454 for (j = 0; 3296 for (j = 0;
4455 j < fh->jpg_buffers.buffer_size / PAGE_SIZE; 3297 j < fh->buffers.buffer_size / PAGE_SIZE;
4456 j++) { 3298 j++) {
4457 fraglen = 3299 fraglen =
4458 (le32_to_cpu(fh->jpg_buffers.buffer[i]. 3300 (le32_to_cpu(fh->buffers.buffer[i].jpg.
4459 frag_tab[2 * j + 1]) & ~1) << 1; 3301 frag_tab[2 * j + 1]) & ~1) << 1;
4460 todo = size; 3302 todo = size;
4461 if (todo > fraglen) 3303 if (todo > fraglen)
4462 todo = fraglen; 3304 todo = fraglen;
4463 pos = 3305 pos =
4464 le32_to_cpu(fh->jpg_buffers. 3306 le32_to_cpu(fh->buffers.
4465 buffer[i].frag_tab[2 * j]); 3307 buffer[i].jpg.frag_tab[2 * j]);
4466 /* should just be pos on i386 */ 3308 /* should just be pos on i386 */
4467 page = virt_to_phys(bus_to_virt(pos)) 3309 page = virt_to_phys(bus_to_virt(pos))
4468 >> PAGE_SHIFT; 3310 >> PAGE_SHIFT;
@@ -4470,123 +3312,82 @@ zoran_mmap (struct file *file,
4470 todo, PAGE_SHARED)) { 3312 todo, PAGE_SHARED)) {
4471 dprintk(1, 3313 dprintk(1,
4472 KERN_ERR 3314 KERN_ERR
4473 "%s: zoran_mmap(V4L) - remap_pfn_range failed\n", 3315 "%s: %s(V4L) - remap_pfn_range failed\n",
4474 ZR_DEVNAME(zr)); 3316 ZR_DEVNAME(zr), __func__);
4475 res = -EAGAIN; 3317 res = -EAGAIN;
4476 goto jpg_mmap_unlock_and_return; 3318 goto mmap_unlock_and_return;
4477 } 3319 }
4478 size -= todo; 3320 size -= todo;
4479 start += todo; 3321 start += todo;
4480 if (size == 0) 3322 if (size == 0)
4481 break; 3323 break;
4482 if (le32_to_cpu(fh->jpg_buffers.buffer[i]. 3324 if (le32_to_cpu(fh->buffers.buffer[i].jpg.
4483 frag_tab[2 * j + 1]) & 1) 3325 frag_tab[2 * j + 1]) & 1)
4484 break; /* was last fragment */ 3326 break; /* was last fragment */
4485 } 3327 }
4486 fh->jpg_buffers.buffer[i].map = map; 3328 fh->buffers.buffer[i].map = map;
4487 if (size == 0) 3329 if (size == 0)
4488 break; 3330 break;
4489 3331
4490 } 3332 }
4491 jpg_mmap_unlock_and_return:
4492 mutex_unlock(&zr->resource_lock);
4493
4494 break;
4495
4496 case ZORAN_MAP_MODE_RAW:
4497
4498 mutex_lock(&zr->resource_lock);
4499
4500 /* Map the V4L buffers */
4501 if (!fh->v4l_buffers.allocated) {
4502 dprintk(1,
4503 KERN_ERR
4504 "%s: zoran_mmap(V4L) - buffers not yet allocated\n",
4505 ZR_DEVNAME(zr));
4506 res = -ENOMEM;
4507 goto v4l_mmap_unlock_and_return;
4508 }
4509
4510 first = offset / fh->v4l_buffers.buffer_size;
4511 last = first - 1 + size / fh->v4l_buffers.buffer_size;
4512 if (offset % fh->v4l_buffers.buffer_size != 0 ||
4513 size % fh->v4l_buffers.buffer_size != 0 || first < 0 ||
4514 last < 0 || first >= fh->v4l_buffers.num_buffers ||
4515 last >= fh->v4l_buffers.buffer_size) {
4516 dprintk(1,
4517 KERN_ERR
4518 "%s: mmap(V4L) - offset=%lu or size=%lu invalid for bufsize=%d and numbufs=%d\n",
4519 ZR_DEVNAME(zr), offset, size,
4520 fh->v4l_buffers.buffer_size,
4521 fh->v4l_buffers.num_buffers);
4522 res = -EINVAL;
4523 goto v4l_mmap_unlock_and_return;
4524 }
4525 for (i = first; i <= last; i++) {
4526 if (fh->v4l_buffers.buffer[i].map) {
4527 dprintk(1,
4528 KERN_ERR
4529 "%s: mmap(V4L) - buffer %d already mapped\n",
4530 ZR_DEVNAME(zr), i);
4531 res = -EBUSY;
4532 goto v4l_mmap_unlock_and_return;
4533 }
4534 }
4535
4536 /* map these buffers (v4l_buffers[i]) */
4537 map = kmalloc(sizeof(struct zoran_mapping), GFP_KERNEL);
4538 if (!map) {
4539 res = -ENOMEM;
4540 goto v4l_mmap_unlock_and_return;
4541 }
4542 map->file = file;
4543 map->count = 1;
4544
4545 vma->vm_ops = &zoran_vm_ops;
4546 vma->vm_flags |= VM_DONTEXPAND;
4547 vma->vm_private_data = map;
4548
4549 for (i = first; i <= last; i++) {
4550 todo = size;
4551 if (todo > fh->v4l_buffers.buffer_size)
4552 todo = fh->v4l_buffers.buffer_size;
4553 page = fh->v4l_buffers.buffer[i].fbuffer_phys;
4554 if (remap_pfn_range(vma, start, page >> PAGE_SHIFT,
4555 todo, PAGE_SHARED)) {
4556 dprintk(1,
4557 KERN_ERR
4558 "%s: zoran_mmap(V4L)i - remap_pfn_range failed\n",
4559 ZR_DEVNAME(zr));
4560 res = -EAGAIN;
4561 goto v4l_mmap_unlock_and_return;
4562 }
4563 size -= todo;
4564 start += todo;
4565 fh->v4l_buffers.buffer[i].map = map;
4566 if (size == 0)
4567 break;
4568 }
4569 v4l_mmap_unlock_and_return:
4570 mutex_unlock(&zr->resource_lock);
4571
4572 break;
4573
4574 default:
4575 dprintk(1,
4576 KERN_ERR
4577 "%s: zoran_mmap() - internal error - unknown map mode %d\n",
4578 ZR_DEVNAME(zr), fh->map_mode);
4579 break;
4580 } 3333 }
4581 3334
3335mmap_unlock_and_return:
3336 mutex_unlock(&zr->resource_lock);
3337
4582 return 0; 3338 return 0;
4583} 3339}
4584 3340
3341static const struct v4l2_ioctl_ops zoran_ioctl_ops = {
3342 .vidioc_querycap = zoran_querycap,
3343 .vidioc_cropcap = zoran_cropcap,
3344 .vidioc_s_crop = zoran_s_crop,
3345 .vidioc_g_crop = zoran_g_crop,
3346 .vidioc_enum_input = zoran_enum_input,
3347 .vidioc_g_input = zoran_g_input,
3348 .vidioc_s_input = zoran_s_input,
3349 .vidioc_enum_output = zoran_enum_output,
3350 .vidioc_g_output = zoran_g_output,
3351 .vidioc_s_output = zoran_s_output,
3352 .vidioc_g_fbuf = zoran_g_fbuf,
3353 .vidioc_s_fbuf = zoran_s_fbuf,
3354 .vidioc_g_std = zoran_g_std,
3355 .vidioc_s_std = zoran_s_std,
3356 .vidioc_g_jpegcomp = zoran_g_jpegcomp,
3357 .vidioc_s_jpegcomp = zoran_s_jpegcomp,
3358 .vidioc_overlay = zoran_overlay,
3359 .vidioc_reqbufs = zoran_reqbufs,
3360 .vidioc_querybuf = zoran_querybuf,
3361 .vidioc_qbuf = zoran_qbuf,
3362 .vidioc_dqbuf = zoran_dqbuf,
3363 .vidioc_streamon = zoran_streamon,
3364 .vidioc_streamoff = zoran_streamoff,
3365 .vidioc_enum_fmt_vid_cap = zoran_enum_fmt_vid_cap,
3366 .vidioc_enum_fmt_vid_out = zoran_enum_fmt_vid_out,
3367 .vidioc_enum_fmt_vid_overlay = zoran_enum_fmt_vid_overlay,
3368 .vidioc_g_fmt_vid_cap = zoran_g_fmt_vid_cap,
3369 .vidioc_g_fmt_vid_out = zoran_g_fmt_vid_out,
3370 .vidioc_g_fmt_vid_overlay = zoran_g_fmt_vid_overlay,
3371 .vidioc_s_fmt_vid_cap = zoran_s_fmt_vid_cap,
3372 .vidioc_s_fmt_vid_out = zoran_s_fmt_vid_out,
3373 .vidioc_s_fmt_vid_overlay = zoran_s_fmt_vid_overlay,
3374 .vidioc_try_fmt_vid_cap = zoran_try_fmt_vid_cap,
3375 .vidioc_try_fmt_vid_out = zoran_try_fmt_vid_out,
3376 .vidioc_try_fmt_vid_overlay = zoran_try_fmt_vid_overlay,
3377 .vidioc_queryctrl = zoran_queryctrl,
3378 .vidioc_s_ctrl = zoran_s_ctrl,
3379 .vidioc_g_ctrl = zoran_g_ctrl,
3380#ifdef CONFIG_VIDEO_V4L1_COMPAT
3381 .vidioc_default = zoran_default,
3382 .vidiocgmbuf = zoran_vidiocgmbuf,
3383#endif
3384};
3385
4585static const struct v4l2_file_operations zoran_fops = { 3386static const struct v4l2_file_operations zoran_fops = {
4586 .owner = THIS_MODULE, 3387 .owner = THIS_MODULE,
4587 .open = zoran_open, 3388 .open = zoran_open,
4588 .release = zoran_close, 3389 .release = zoran_close,
4589 .ioctl = zoran_ioctl, 3390 .ioctl = video_ioctl2,
4590 .read = zoran_read, 3391 .read = zoran_read,
4591 .write = zoran_write, 3392 .write = zoran_write,
4592 .mmap = zoran_mmap, 3393 .mmap = zoran_mmap,
@@ -4596,7 +3397,9 @@ static const struct v4l2_file_operations zoran_fops = {
4596struct video_device zoran_template __devinitdata = { 3397struct video_device zoran_template __devinitdata = {
4597 .name = ZORAN_NAME, 3398 .name = ZORAN_NAME,
4598 .fops = &zoran_fops, 3399 .fops = &zoran_fops,
3400 .ioctl_ops = &zoran_ioctl_ops,
4599 .release = &zoran_vdev_release, 3401 .release = &zoran_vdev_release,
3402 .tvnorms = V4L2_STD_NTSC | V4L2_STD_PAL | V4L2_STD_SECAM,
4600 .minor = -1 3403 .minor = -1
4601}; 3404};
4602 3405
diff --git a/drivers/media/video/zoran/zoran_procfs.c b/drivers/media/video/zoran/zoran_procfs.c
index 870bc5a70e3f..f1423b777db1 100644
--- a/drivers/media/video/zoran/zoran_procfs.c
+++ b/drivers/media/video/zoran/zoran_procfs.c
@@ -36,7 +36,7 @@
36#include <linux/pci.h> 36#include <linux/pci.h>
37#include <linux/i2c.h> 37#include <linux/i2c.h>
38#include <linux/i2c-algo-bit.h> 38#include <linux/i2c-algo-bit.h>
39#include <linux/videodev.h> 39#include <linux/videodev2.h>
40#include <linux/spinlock.h> 40#include <linux/spinlock.h>
41#include <linux/sem.h> 41#include <linux/sem.h>
42#include <linux/seq_file.h> 42#include <linux/seq_file.h>
diff --git a/drivers/media/video/zoran/zr36016.c b/drivers/media/video/zoran/zr36016.c
index 00d132bcd1e4..21c088ea9046 100644
--- a/drivers/media/video/zoran/zr36016.c
+++ b/drivers/media/video/zoran/zr36016.c
@@ -34,15 +34,10 @@
34#include <linux/types.h> 34#include <linux/types.h>
35#include <linux/wait.h> 35#include <linux/wait.h>
36 36
37/* includes for structures and defines regarding video
38 #include<linux/videodev.h> */
39
40/* I/O commands, error codes */ 37/* I/O commands, error codes */
41#include <asm/io.h> 38#include <asm/io.h>
42//#include<errno.h>
43 39
44/* v4l API */ 40/* v4l API */
45#include <linux/videodev.h>
46 41
47/* headerfile of this module */ 42/* headerfile of this module */
48#include"zr36016.h" 43#include"zr36016.h"
diff --git a/drivers/media/video/zoran/zr36050.c b/drivers/media/video/zoran/zr36050.c
index cf8b271a1c8f..639dd87c663f 100644
--- a/drivers/media/video/zoran/zr36050.c
+++ b/drivers/media/video/zoran/zr36050.c
@@ -34,12 +34,8 @@
34#include <linux/types.h> 34#include <linux/types.h>
35#include <linux/wait.h> 35#include <linux/wait.h>
36 36
37/* includes for structures and defines regarding video
38 #include<linux/videodev.h> */
39
40/* I/O commands, error codes */ 37/* I/O commands, error codes */
41#include <asm/io.h> 38#include <asm/io.h>
42//#include<errno.h>
43 39
44/* headerfile of this module */ 40/* headerfile of this module */
45#include "zr36050.h" 41#include "zr36050.h"
diff --git a/drivers/media/video/zoran/zr36060.c b/drivers/media/video/zoran/zr36060.c
index 8e74054d5ef1..008746ff7746 100644
--- a/drivers/media/video/zoran/zr36060.c
+++ b/drivers/media/video/zoran/zr36060.c
@@ -34,12 +34,8 @@
34#include <linux/types.h> 34#include <linux/types.h>
35#include <linux/wait.h> 35#include <linux/wait.h>
36 36
37/* includes for structures and defines regarding video
38 #include<linux/videodev.h> */
39
40/* I/O commands, error codes */ 37/* I/O commands, error codes */
41#include <asm/io.h> 38#include <asm/io.h>
42//#include<errno.h>
43 39
44/* headerfile of this module */ 40/* headerfile of this module */
45#include "zr36060.h" 41#include "zr36060.h"
diff --git a/drivers/media/video/zr364xx.c b/drivers/media/video/zr364xx.c
index 93023560f324..221409fe1682 100644
--- a/drivers/media/video/zr364xx.c
+++ b/drivers/media/video/zr364xx.c
@@ -96,6 +96,7 @@ static struct usb_device_id device_table[] = {
96 {USB_DEVICE(0x06d6, 0x003b), .driver_info = METHOD0 }, 96 {USB_DEVICE(0x06d6, 0x003b), .driver_info = METHOD0 },
97 {USB_DEVICE(0x0a17, 0x004e), .driver_info = METHOD2 }, 97 {USB_DEVICE(0x0a17, 0x004e), .driver_info = METHOD2 },
98 {USB_DEVICE(0x041e, 0x405d), .driver_info = METHOD2 }, 98 {USB_DEVICE(0x041e, 0x405d), .driver_info = METHOD2 },
99 {USB_DEVICE(0x08ca, 0x2102), .driver_info = METHOD2 },
99 {} /* Terminating entry */ 100 {} /* Terminating entry */
100}; 101};
101 102
@@ -425,7 +426,6 @@ static ssize_t zr364xx_read(struct file *file, char __user *buf, size_t cnt,
425static int zr364xx_vidioc_querycap(struct file *file, void *priv, 426static int zr364xx_vidioc_querycap(struct file *file, void *priv,
426 struct v4l2_capability *cap) 427 struct v4l2_capability *cap)
427{ 428{
428 memset(cap, 0, sizeof(*cap));
429 strcpy(cap->driver, DRIVER_DESC); 429 strcpy(cap->driver, DRIVER_DESC);
430 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE; 430 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE;
431 return 0; 431 return 0;
@@ -436,8 +436,6 @@ static int zr364xx_vidioc_enum_input(struct file *file, void *priv,
436{ 436{
437 if (i->index != 0) 437 if (i->index != 0)
438 return -EINVAL; 438 return -EINVAL;
439 memset(i, 0, sizeof(*i));
440 i->index = 0;
441 strcpy(i->name, DRIVER_DESC " Camera"); 439 strcpy(i->name, DRIVER_DESC " Camera");
442 i->type = V4L2_INPUT_TYPE_CAMERA; 440 i->type = V4L2_INPUT_TYPE_CAMERA;
443 return 0; 441 return 0;
@@ -529,11 +527,6 @@ static int zr364xx_vidioc_enum_fmt_vid_cap(struct file *file,
529{ 527{
530 if (f->index > 0) 528 if (f->index > 0)
531 return -EINVAL; 529 return -EINVAL;
532 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
533 return -EINVAL;
534 memset(f, 0, sizeof(*f));
535 f->index = 0;
536 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
537 f->flags = V4L2_FMT_FLAG_COMPRESSED; 530 f->flags = V4L2_FMT_FLAG_COMPRESSED;
538 strcpy(f->description, "JPEG"); 531 strcpy(f->description, "JPEG");
539 f->pixelformat = V4L2_PIX_FMT_JPEG; 532 f->pixelformat = V4L2_PIX_FMT_JPEG;
@@ -550,8 +543,6 @@ static int zr364xx_vidioc_try_fmt_vid_cap(struct file *file, void *priv,
550 return -ENODEV; 543 return -ENODEV;
551 cam = video_get_drvdata(vdev); 544 cam = video_get_drvdata(vdev);
552 545
553 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
554 return -EINVAL;
555 if (f->fmt.pix.pixelformat != V4L2_PIX_FMT_JPEG) 546 if (f->fmt.pix.pixelformat != V4L2_PIX_FMT_JPEG)
556 return -EINVAL; 547 return -EINVAL;
557 if (f->fmt.pix.field != V4L2_FIELD_ANY && 548 if (f->fmt.pix.field != V4L2_FIELD_ANY &&
@@ -577,10 +568,6 @@ static int zr364xx_vidioc_g_fmt_vid_cap(struct file *file, void *priv,
577 return -ENODEV; 568 return -ENODEV;
578 cam = video_get_drvdata(vdev); 569 cam = video_get_drvdata(vdev);
579 570
580 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
581 return -EINVAL;
582 memset(&f->fmt.pix, 0, sizeof(struct v4l2_pix_format));
583 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
584 f->fmt.pix.pixelformat = V4L2_PIX_FMT_JPEG; 571 f->fmt.pix.pixelformat = V4L2_PIX_FMT_JPEG;
585 f->fmt.pix.field = V4L2_FIELD_NONE; 572 f->fmt.pix.field = V4L2_FIELD_NONE;
586 f->fmt.pix.width = cam->width; 573 f->fmt.pix.width = cam->width;
@@ -602,8 +589,6 @@ static int zr364xx_vidioc_s_fmt_vid_cap(struct file *file, void *priv,
602 return -ENODEV; 589 return -ENODEV;
603 cam = video_get_drvdata(vdev); 590 cam = video_get_drvdata(vdev);
604 591
605 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
606 return -EINVAL;
607 if (f->fmt.pix.pixelformat != V4L2_PIX_FMT_JPEG) 592 if (f->fmt.pix.pixelformat != V4L2_PIX_FMT_JPEG)
608 return -EINVAL; 593 return -EINVAL;
609 if (f->fmt.pix.field != V4L2_FIELD_ANY && 594 if (f->fmt.pix.field != V4L2_FIELD_ANY &&
diff --git a/drivers/net/fec_mpc52xx.c b/drivers/net/fec_mpc52xx.c
index cd8e98b45ec5..049b0a7e01f3 100644
--- a/drivers/net/fec_mpc52xx.c
+++ b/drivers/net/fec_mpc52xx.c
@@ -1123,9 +1123,9 @@ static int mpc52xx_fec_of_resume(struct of_device *op)
1123#endif 1123#endif
1124 1124
1125static struct of_device_id mpc52xx_fec_match[] = { 1125static struct of_device_id mpc52xx_fec_match[] = {
1126 { .type = "network", .compatible = "fsl,mpc5200b-fec", }, 1126 { .compatible = "fsl,mpc5200b-fec", },
1127 { .type = "network", .compatible = "fsl,mpc5200-fec", }, 1127 { .compatible = "fsl,mpc5200-fec", },
1128 { .type = "network", .compatible = "mpc5200-fec", }, 1128 { .compatible = "mpc5200-fec", },
1129 { } 1129 { }
1130}; 1130};
1131 1131
diff --git a/drivers/net/meth.c b/drivers/net/meth.c
index c336a1f42510..aa08987f6e81 100644
--- a/drivers/net/meth.c
+++ b/drivers/net/meth.c
@@ -398,7 +398,7 @@ static void meth_rx(struct net_device* dev, unsigned long int_status)
398 int len = (status & 0xffff) - 4; /* omit CRC */ 398 int len = (status & 0xffff) - 4; /* omit CRC */
399 /* length sanity check */ 399 /* length sanity check */
400 if (len < 60 || len > 1518) { 400 if (len < 60 || len > 1518) {
401 printk(KERN_DEBUG "%s: bogus packet size: %ld, status=%#2lx.\n", 401 printk(KERN_DEBUG "%s: bogus packet size: %ld, status=%#2Lx.\n",
402 dev->name, priv->rx_write, 402 dev->name, priv->rx_write,
403 priv->rx_ring[priv->rx_write]->status.raw); 403 priv->rx_ring[priv->rx_write]->status.raw);
404 dev->stats.rx_errors++; 404 dev->stats.rx_errors++;
diff --git a/drivers/net/smc91x.h b/drivers/net/smc91x.h
index 6c44f86ae3fd..912308eec865 100644
--- a/drivers/net/smc91x.h
+++ b/drivers/net/smc91x.h
@@ -346,38 +346,6 @@ static inline void LPD7_SMC_outsw (unsigned char* a, int r,
346#define RPC_LSA_DEFAULT RPC_LED_TX_RX 346#define RPC_LSA_DEFAULT RPC_LED_TX_RX
347#define RPC_LSB_DEFAULT RPC_LED_100_10 347#define RPC_LSB_DEFAULT RPC_LED_100_10
348 348
349#elif defined(CONFIG_SOC_AU1X00)
350
351#include <au1xxx.h>
352
353/* We can only do 16-bit reads and writes in the static memory space. */
354#define SMC_CAN_USE_8BIT 0
355#define SMC_CAN_USE_16BIT 1
356#define SMC_CAN_USE_32BIT 0
357#define SMC_IO_SHIFT 0
358#define SMC_NOWAIT 1
359
360#define SMC_inw(a, r) au_readw((unsigned long)((a) + (r)))
361#define SMC_insw(a, r, p, l) \
362 do { \
363 unsigned long _a = (unsigned long)((a) + (r)); \
364 int _l = (l); \
365 u16 *_p = (u16 *)(p); \
366 while (_l-- > 0) \
367 *_p++ = au_readw(_a); \
368 } while(0)
369#define SMC_outw(v, a, r) au_writew(v, (unsigned long)((a) + (r)))
370#define SMC_outsw(a, r, p, l) \
371 do { \
372 unsigned long _a = (unsigned long)((a) + (r)); \
373 int _l = (l); \
374 const u16 *_p = (const u16 *)(p); \
375 while (_l-- > 0) \
376 au_writew(*_p++ , _a); \
377 } while(0)
378
379#define SMC_IRQ_FLAGS (0)
380
381#elif defined(CONFIG_ARCH_VERSATILE) 349#elif defined(CONFIG_ARCH_VERSATILE)
382 350
383#define SMC_CAN_USE_8BIT 1 351#define SMC_CAN_USE_8BIT 1
diff --git a/drivers/pci/dmar.c b/drivers/pci/dmar.c
index 5f333403c2ea..d313039e2fdf 100644
--- a/drivers/pci/dmar.c
+++ b/drivers/pci/dmar.c
@@ -31,6 +31,8 @@
31#include <linux/iova.h> 31#include <linux/iova.h>
32#include <linux/intel-iommu.h> 32#include <linux/intel-iommu.h>
33#include <linux/timer.h> 33#include <linux/timer.h>
34#include <linux/irq.h>
35#include <linux/interrupt.h>
34 36
35#undef PREFIX 37#undef PREFIX
36#define PREFIX "DMAR:" 38#define PREFIX "DMAR:"
@@ -509,6 +511,7 @@ int alloc_iommu(struct dmar_drhd_unit *drhd)
509 return -ENOMEM; 511 return -ENOMEM;
510 512
511 iommu->seq_id = iommu_allocated++; 513 iommu->seq_id = iommu_allocated++;
514 sprintf (iommu->name, "dmar%d", iommu->seq_id);
512 515
513 iommu->reg = ioremap(drhd->reg_base_addr, VTD_PAGE_SIZE); 516 iommu->reg = ioremap(drhd->reg_base_addr, VTD_PAGE_SIZE);
514 if (!iommu->reg) { 517 if (!iommu->reg) {
@@ -751,6 +754,42 @@ int qi_flush_iotlb(struct intel_iommu *iommu, u16 did, u64 addr,
751} 754}
752 755
753/* 756/*
757 * Disable Queued Invalidation interface.
758 */
759void dmar_disable_qi(struct intel_iommu *iommu)
760{
761 unsigned long flags;
762 u32 sts;
763 cycles_t start_time = get_cycles();
764
765 if (!ecap_qis(iommu->ecap))
766 return;
767
768 spin_lock_irqsave(&iommu->register_lock, flags);
769
770 sts = dmar_readq(iommu->reg + DMAR_GSTS_REG);
771 if (!(sts & DMA_GSTS_QIES))
772 goto end;
773
774 /*
775 * Give a chance to HW to complete the pending invalidation requests.
776 */
777 while ((readl(iommu->reg + DMAR_IQT_REG) !=
778 readl(iommu->reg + DMAR_IQH_REG)) &&
779 (DMAR_OPERATION_TIMEOUT > (get_cycles() - start_time)))
780 cpu_relax();
781
782 iommu->gcmd &= ~DMA_GCMD_QIE;
783
784 writel(iommu->gcmd, iommu->reg + DMAR_GCMD_REG);
785
786 IOMMU_WAIT_OP(iommu, DMAR_GSTS_REG, readl,
787 !(sts & DMA_GSTS_QIES), sts);
788end:
789 spin_unlock_irqrestore(&iommu->register_lock, flags);
790}
791
792/*
754 * Enable Queued Invalidation interface. This is a must to support 793 * Enable Queued Invalidation interface. This is a must to support
755 * interrupt-remapping. Also used by DMA-remapping, which replaces 794 * interrupt-remapping. Also used by DMA-remapping, which replaces
756 * register based IOTLB invalidation. 795 * register based IOTLB invalidation.
@@ -770,20 +809,20 @@ int dmar_enable_qi(struct intel_iommu *iommu)
770 if (iommu->qi) 809 if (iommu->qi)
771 return 0; 810 return 0;
772 811
773 iommu->qi = kmalloc(sizeof(*qi), GFP_KERNEL); 812 iommu->qi = kmalloc(sizeof(*qi), GFP_ATOMIC);
774 if (!iommu->qi) 813 if (!iommu->qi)
775 return -ENOMEM; 814 return -ENOMEM;
776 815
777 qi = iommu->qi; 816 qi = iommu->qi;
778 817
779 qi->desc = (void *)(get_zeroed_page(GFP_KERNEL)); 818 qi->desc = (void *)(get_zeroed_page(GFP_ATOMIC));
780 if (!qi->desc) { 819 if (!qi->desc) {
781 kfree(qi); 820 kfree(qi);
782 iommu->qi = 0; 821 iommu->qi = 0;
783 return -ENOMEM; 822 return -ENOMEM;
784 } 823 }
785 824
786 qi->desc_status = kmalloc(QI_LENGTH * sizeof(int), GFP_KERNEL); 825 qi->desc_status = kmalloc(QI_LENGTH * sizeof(int), GFP_ATOMIC);
787 if (!qi->desc_status) { 826 if (!qi->desc_status) {
788 free_page((unsigned long) qi->desc); 827 free_page((unsigned long) qi->desc);
789 kfree(qi); 828 kfree(qi);
@@ -812,3 +851,254 @@ int dmar_enable_qi(struct intel_iommu *iommu)
812 851
813 return 0; 852 return 0;
814} 853}
854
855/* iommu interrupt handling. Most stuff are MSI-like. */
856
857enum faulttype {
858 DMA_REMAP,
859 INTR_REMAP,
860 UNKNOWN,
861};
862
863static const char *dma_remap_fault_reasons[] =
864{
865 "Software",
866 "Present bit in root entry is clear",
867 "Present bit in context entry is clear",
868 "Invalid context entry",
869 "Access beyond MGAW",
870 "PTE Write access is not set",
871 "PTE Read access is not set",
872 "Next page table ptr is invalid",
873 "Root table address invalid",
874 "Context table ptr is invalid",
875 "non-zero reserved fields in RTP",
876 "non-zero reserved fields in CTP",
877 "non-zero reserved fields in PTE",
878};
879
880static const char *intr_remap_fault_reasons[] =
881{
882 "Detected reserved fields in the decoded interrupt-remapped request",
883 "Interrupt index exceeded the interrupt-remapping table size",
884 "Present field in the IRTE entry is clear",
885 "Error accessing interrupt-remapping table pointed by IRTA_REG",
886 "Detected reserved fields in the IRTE entry",
887 "Blocked a compatibility format interrupt request",
888 "Blocked an interrupt request due to source-id verification failure",
889};
890
891#define MAX_FAULT_REASON_IDX (ARRAY_SIZE(fault_reason_strings) - 1)
892
893const char *dmar_get_fault_reason(u8 fault_reason, int *fault_type)
894{
895 if (fault_reason >= 0x20 && (fault_reason <= 0x20 +
896 ARRAY_SIZE(intr_remap_fault_reasons))) {
897 *fault_type = INTR_REMAP;
898 return intr_remap_fault_reasons[fault_reason - 0x20];
899 } else if (fault_reason < ARRAY_SIZE(dma_remap_fault_reasons)) {
900 *fault_type = DMA_REMAP;
901 return dma_remap_fault_reasons[fault_reason];
902 } else {
903 *fault_type = UNKNOWN;
904 return "Unknown";
905 }
906}
907
908void dmar_msi_unmask(unsigned int irq)
909{
910 struct intel_iommu *iommu = get_irq_data(irq);
911 unsigned long flag;
912
913 /* unmask it */
914 spin_lock_irqsave(&iommu->register_lock, flag);
915 writel(0, iommu->reg + DMAR_FECTL_REG);
916 /* Read a reg to force flush the post write */
917 readl(iommu->reg + DMAR_FECTL_REG);
918 spin_unlock_irqrestore(&iommu->register_lock, flag);
919}
920
921void dmar_msi_mask(unsigned int irq)
922{
923 unsigned long flag;
924 struct intel_iommu *iommu = get_irq_data(irq);
925
926 /* mask it */
927 spin_lock_irqsave(&iommu->register_lock, flag);
928 writel(DMA_FECTL_IM, iommu->reg + DMAR_FECTL_REG);
929 /* Read a reg to force flush the post write */
930 readl(iommu->reg + DMAR_FECTL_REG);
931 spin_unlock_irqrestore(&iommu->register_lock, flag);
932}
933
934void dmar_msi_write(int irq, struct msi_msg *msg)
935{
936 struct intel_iommu *iommu = get_irq_data(irq);
937 unsigned long flag;
938
939 spin_lock_irqsave(&iommu->register_lock, flag);
940 writel(msg->data, iommu->reg + DMAR_FEDATA_REG);
941 writel(msg->address_lo, iommu->reg + DMAR_FEADDR_REG);
942 writel(msg->address_hi, iommu->reg + DMAR_FEUADDR_REG);
943 spin_unlock_irqrestore(&iommu->register_lock, flag);
944}
945
946void dmar_msi_read(int irq, struct msi_msg *msg)
947{
948 struct intel_iommu *iommu = get_irq_data(irq);
949 unsigned long flag;
950
951 spin_lock_irqsave(&iommu->register_lock, flag);
952 msg->data = readl(iommu->reg + DMAR_FEDATA_REG);
953 msg->address_lo = readl(iommu->reg + DMAR_FEADDR_REG);
954 msg->address_hi = readl(iommu->reg + DMAR_FEUADDR_REG);
955 spin_unlock_irqrestore(&iommu->register_lock, flag);
956}
957
958static int dmar_fault_do_one(struct intel_iommu *iommu, int type,
959 u8 fault_reason, u16 source_id, unsigned long long addr)
960{
961 const char *reason;
962 int fault_type;
963
964 reason = dmar_get_fault_reason(fault_reason, &fault_type);
965
966 if (fault_type == INTR_REMAP)
967 printk(KERN_ERR "INTR-REMAP: Request device [[%02x:%02x.%d] "
968 "fault index %llx\n"
969 "INTR-REMAP:[fault reason %02d] %s\n",
970 (source_id >> 8), PCI_SLOT(source_id & 0xFF),
971 PCI_FUNC(source_id & 0xFF), addr >> 48,
972 fault_reason, reason);
973 else
974 printk(KERN_ERR
975 "DMAR:[%s] Request device [%02x:%02x.%d] "
976 "fault addr %llx \n"
977 "DMAR:[fault reason %02d] %s\n",
978 (type ? "DMA Read" : "DMA Write"),
979 (source_id >> 8), PCI_SLOT(source_id & 0xFF),
980 PCI_FUNC(source_id & 0xFF), addr, fault_reason, reason);
981 return 0;
982}
983
984#define PRIMARY_FAULT_REG_LEN (16)
985irqreturn_t dmar_fault(int irq, void *dev_id)
986{
987 struct intel_iommu *iommu = dev_id;
988 int reg, fault_index;
989 u32 fault_status;
990 unsigned long flag;
991
992 spin_lock_irqsave(&iommu->register_lock, flag);
993 fault_status = readl(iommu->reg + DMAR_FSTS_REG);
994 if (fault_status)
995 printk(KERN_ERR "DRHD: handling fault status reg %x\n",
996 fault_status);
997
998 /* TBD: ignore advanced fault log currently */
999 if (!(fault_status & DMA_FSTS_PPF))
1000 goto clear_rest;
1001
1002 fault_index = dma_fsts_fault_record_index(fault_status);
1003 reg = cap_fault_reg_offset(iommu->cap);
1004 while (1) {
1005 u8 fault_reason;
1006 u16 source_id;
1007 u64 guest_addr;
1008 int type;
1009 u32 data;
1010
1011 /* highest 32 bits */
1012 data = readl(iommu->reg + reg +
1013 fault_index * PRIMARY_FAULT_REG_LEN + 12);
1014 if (!(data & DMA_FRCD_F))
1015 break;
1016
1017 fault_reason = dma_frcd_fault_reason(data);
1018 type = dma_frcd_type(data);
1019
1020 data = readl(iommu->reg + reg +
1021 fault_index * PRIMARY_FAULT_REG_LEN + 8);
1022 source_id = dma_frcd_source_id(data);
1023
1024 guest_addr = dmar_readq(iommu->reg + reg +
1025 fault_index * PRIMARY_FAULT_REG_LEN);
1026 guest_addr = dma_frcd_page_addr(guest_addr);
1027 /* clear the fault */
1028 writel(DMA_FRCD_F, iommu->reg + reg +
1029 fault_index * PRIMARY_FAULT_REG_LEN + 12);
1030
1031 spin_unlock_irqrestore(&iommu->register_lock, flag);
1032
1033 dmar_fault_do_one(iommu, type, fault_reason,
1034 source_id, guest_addr);
1035
1036 fault_index++;
1037 if (fault_index > cap_num_fault_regs(iommu->cap))
1038 fault_index = 0;
1039 spin_lock_irqsave(&iommu->register_lock, flag);
1040 }
1041clear_rest:
1042 /* clear all the other faults */
1043 fault_status = readl(iommu->reg + DMAR_FSTS_REG);
1044 writel(fault_status, iommu->reg + DMAR_FSTS_REG);
1045
1046 spin_unlock_irqrestore(&iommu->register_lock, flag);
1047 return IRQ_HANDLED;
1048}
1049
1050int dmar_set_interrupt(struct intel_iommu *iommu)
1051{
1052 int irq, ret;
1053
1054 /*
1055 * Check if the fault interrupt is already initialized.
1056 */
1057 if (iommu->irq)
1058 return 0;
1059
1060 irq = create_irq();
1061 if (!irq) {
1062 printk(KERN_ERR "IOMMU: no free vectors\n");
1063 return -EINVAL;
1064 }
1065
1066 set_irq_data(irq, iommu);
1067 iommu->irq = irq;
1068
1069 ret = arch_setup_dmar_msi(irq);
1070 if (ret) {
1071 set_irq_data(irq, NULL);
1072 iommu->irq = 0;
1073 destroy_irq(irq);
1074 return 0;
1075 }
1076
1077 ret = request_irq(irq, dmar_fault, 0, iommu->name, iommu);
1078 if (ret)
1079 printk(KERN_ERR "IOMMU: can't request irq\n");
1080 return ret;
1081}
1082
1083int __init enable_drhd_fault_handling(void)
1084{
1085 struct dmar_drhd_unit *drhd;
1086
1087 /*
1088 * Enable fault control interrupt.
1089 */
1090 for_each_drhd_unit(drhd) {
1091 int ret;
1092 struct intel_iommu *iommu = drhd->iommu;
1093 ret = dmar_set_interrupt(iommu);
1094
1095 if (ret) {
1096 printk(KERN_ERR "DRHD %Lx: failed to enable fault, "
1097 " interrupt, ret %d\n",
1098 (unsigned long long)drhd->reg_base_addr, ret);
1099 return -1;
1100 }
1101 }
1102
1103 return 0;
1104}
diff --git a/drivers/pci/intel-iommu.c b/drivers/pci/intel-iommu.c
index f3f686581a90..49402c399232 100644
--- a/drivers/pci/intel-iommu.c
+++ b/drivers/pci/intel-iommu.c
@@ -1004,194 +1004,6 @@ static int iommu_disable_translation(struct intel_iommu *iommu)
1004 return 0; 1004 return 0;
1005} 1005}
1006 1006
1007/* iommu interrupt handling. Most stuff are MSI-like. */
1008
1009static const char *fault_reason_strings[] =
1010{
1011 "Software",
1012 "Present bit in root entry is clear",
1013 "Present bit in context entry is clear",
1014 "Invalid context entry",
1015 "Access beyond MGAW",
1016 "PTE Write access is not set",
1017 "PTE Read access is not set",
1018 "Next page table ptr is invalid",
1019 "Root table address invalid",
1020 "Context table ptr is invalid",
1021 "non-zero reserved fields in RTP",
1022 "non-zero reserved fields in CTP",
1023 "non-zero reserved fields in PTE",
1024};
1025#define MAX_FAULT_REASON_IDX (ARRAY_SIZE(fault_reason_strings) - 1)
1026
1027const char *dmar_get_fault_reason(u8 fault_reason)
1028{
1029 if (fault_reason > MAX_FAULT_REASON_IDX)
1030 return "Unknown";
1031 else
1032 return fault_reason_strings[fault_reason];
1033}
1034
1035void dmar_msi_unmask(unsigned int irq)
1036{
1037 struct intel_iommu *iommu = get_irq_data(irq);
1038 unsigned long flag;
1039
1040 /* unmask it */
1041 spin_lock_irqsave(&iommu->register_lock, flag);
1042 writel(0, iommu->reg + DMAR_FECTL_REG);
1043 /* Read a reg to force flush the post write */
1044 readl(iommu->reg + DMAR_FECTL_REG);
1045 spin_unlock_irqrestore(&iommu->register_lock, flag);
1046}
1047
1048void dmar_msi_mask(unsigned int irq)
1049{
1050 unsigned long flag;
1051 struct intel_iommu *iommu = get_irq_data(irq);
1052
1053 /* mask it */
1054 spin_lock_irqsave(&iommu->register_lock, flag);
1055 writel(DMA_FECTL_IM, iommu->reg + DMAR_FECTL_REG);
1056 /* Read a reg to force flush the post write */
1057 readl(iommu->reg + DMAR_FECTL_REG);
1058 spin_unlock_irqrestore(&iommu->register_lock, flag);
1059}
1060
1061void dmar_msi_write(int irq, struct msi_msg *msg)
1062{
1063 struct intel_iommu *iommu = get_irq_data(irq);
1064 unsigned long flag;
1065
1066 spin_lock_irqsave(&iommu->register_lock, flag);
1067 writel(msg->data, iommu->reg + DMAR_FEDATA_REG);
1068 writel(msg->address_lo, iommu->reg + DMAR_FEADDR_REG);
1069 writel(msg->address_hi, iommu->reg + DMAR_FEUADDR_REG);
1070 spin_unlock_irqrestore(&iommu->register_lock, flag);
1071}
1072
1073void dmar_msi_read(int irq, struct msi_msg *msg)
1074{
1075 struct intel_iommu *iommu = get_irq_data(irq);
1076 unsigned long flag;
1077
1078 spin_lock_irqsave(&iommu->register_lock, flag);
1079 msg->data = readl(iommu->reg + DMAR_FEDATA_REG);
1080 msg->address_lo = readl(iommu->reg + DMAR_FEADDR_REG);
1081 msg->address_hi = readl(iommu->reg + DMAR_FEUADDR_REG);
1082 spin_unlock_irqrestore(&iommu->register_lock, flag);
1083}
1084
1085static int iommu_page_fault_do_one(struct intel_iommu *iommu, int type,
1086 u8 fault_reason, u16 source_id, unsigned long long addr)
1087{
1088 const char *reason;
1089
1090 reason = dmar_get_fault_reason(fault_reason);
1091
1092 printk(KERN_ERR
1093 "DMAR:[%s] Request device [%02x:%02x.%d] "
1094 "fault addr %llx \n"
1095 "DMAR:[fault reason %02d] %s\n",
1096 (type ? "DMA Read" : "DMA Write"),
1097 (source_id >> 8), PCI_SLOT(source_id & 0xFF),
1098 PCI_FUNC(source_id & 0xFF), addr, fault_reason, reason);
1099 return 0;
1100}
1101
1102#define PRIMARY_FAULT_REG_LEN (16)
1103static irqreturn_t iommu_page_fault(int irq, void *dev_id)
1104{
1105 struct intel_iommu *iommu = dev_id;
1106 int reg, fault_index;
1107 u32 fault_status;
1108 unsigned long flag;
1109
1110 spin_lock_irqsave(&iommu->register_lock, flag);
1111 fault_status = readl(iommu->reg + DMAR_FSTS_REG);
1112
1113 /* TBD: ignore advanced fault log currently */
1114 if (!(fault_status & DMA_FSTS_PPF))
1115 goto clear_overflow;
1116
1117 fault_index = dma_fsts_fault_record_index(fault_status);
1118 reg = cap_fault_reg_offset(iommu->cap);
1119 while (1) {
1120 u8 fault_reason;
1121 u16 source_id;
1122 u64 guest_addr;
1123 int type;
1124 u32 data;
1125
1126 /* highest 32 bits */
1127 data = readl(iommu->reg + reg +
1128 fault_index * PRIMARY_FAULT_REG_LEN + 12);
1129 if (!(data & DMA_FRCD_F))
1130 break;
1131
1132 fault_reason = dma_frcd_fault_reason(data);
1133 type = dma_frcd_type(data);
1134
1135 data = readl(iommu->reg + reg +
1136 fault_index * PRIMARY_FAULT_REG_LEN + 8);
1137 source_id = dma_frcd_source_id(data);
1138
1139 guest_addr = dmar_readq(iommu->reg + reg +
1140 fault_index * PRIMARY_FAULT_REG_LEN);
1141 guest_addr = dma_frcd_page_addr(guest_addr);
1142 /* clear the fault */
1143 writel(DMA_FRCD_F, iommu->reg + reg +
1144 fault_index * PRIMARY_FAULT_REG_LEN + 12);
1145
1146 spin_unlock_irqrestore(&iommu->register_lock, flag);
1147
1148 iommu_page_fault_do_one(iommu, type, fault_reason,
1149 source_id, guest_addr);
1150
1151 fault_index++;
1152 if (fault_index > cap_num_fault_regs(iommu->cap))
1153 fault_index = 0;
1154 spin_lock_irqsave(&iommu->register_lock, flag);
1155 }
1156clear_overflow:
1157 /* clear primary fault overflow */
1158 fault_status = readl(iommu->reg + DMAR_FSTS_REG);
1159 if (fault_status & DMA_FSTS_PFO)
1160 writel(DMA_FSTS_PFO, iommu->reg + DMAR_FSTS_REG);
1161
1162 spin_unlock_irqrestore(&iommu->register_lock, flag);
1163 return IRQ_HANDLED;
1164}
1165
1166int dmar_set_interrupt(struct intel_iommu *iommu)
1167{
1168 int irq, ret;
1169
1170 irq = create_irq();
1171 if (!irq) {
1172 printk(KERN_ERR "IOMMU: no free vectors\n");
1173 return -EINVAL;
1174 }
1175
1176 set_irq_data(irq, iommu);
1177 iommu->irq = irq;
1178
1179 ret = arch_setup_dmar_msi(irq);
1180 if (ret) {
1181 set_irq_data(irq, NULL);
1182 iommu->irq = 0;
1183 destroy_irq(irq);
1184 return 0;
1185 }
1186
1187 /* Force fault register is cleared */
1188 iommu_page_fault(irq, iommu);
1189
1190 ret = request_irq(irq, iommu_page_fault, 0, iommu->name, iommu);
1191 if (ret)
1192 printk(KERN_ERR "IOMMU: can't request irq\n");
1193 return ret;
1194}
1195 1007
1196static int iommu_init_domains(struct intel_iommu *iommu) 1008static int iommu_init_domains(struct intel_iommu *iommu)
1197{ 1009{
@@ -1987,7 +1799,7 @@ static int __init init_dmars(void)
1987 struct dmar_rmrr_unit *rmrr; 1799 struct dmar_rmrr_unit *rmrr;
1988 struct pci_dev *pdev; 1800 struct pci_dev *pdev;
1989 struct intel_iommu *iommu; 1801 struct intel_iommu *iommu;
1990 int i, ret, unit = 0; 1802 int i, ret;
1991 1803
1992 /* 1804 /*
1993 * for each drhd 1805 * for each drhd
@@ -2043,11 +1855,40 @@ static int __init init_dmars(void)
2043 } 1855 }
2044 } 1856 }
2045 1857
1858 /*
1859 * Start from the sane iommu hardware state.
1860 */
2046 for_each_drhd_unit(drhd) { 1861 for_each_drhd_unit(drhd) {
2047 if (drhd->ignored) 1862 if (drhd->ignored)
2048 continue; 1863 continue;
2049 1864
2050 iommu = drhd->iommu; 1865 iommu = drhd->iommu;
1866
1867 /*
1868 * If the queued invalidation is already initialized by us
1869 * (for example, while enabling interrupt-remapping) then
1870 * we got the things already rolling from a sane state.
1871 */
1872 if (iommu->qi)
1873 continue;
1874
1875 /*
1876 * Clear any previous faults.
1877 */
1878 dmar_fault(-1, iommu);
1879 /*
1880 * Disable queued invalidation if supported and already enabled
1881 * before OS handover.
1882 */
1883 dmar_disable_qi(iommu);
1884 }
1885
1886 for_each_drhd_unit(drhd) {
1887 if (drhd->ignored)
1888 continue;
1889
1890 iommu = drhd->iommu;
1891
2051 if (dmar_enable_qi(iommu)) { 1892 if (dmar_enable_qi(iommu)) {
2052 /* 1893 /*
2053 * Queued Invalidate not enabled, use Register Based 1894 * Queued Invalidate not enabled, use Register Based
@@ -2109,7 +1950,6 @@ static int __init init_dmars(void)
2109 if (drhd->ignored) 1950 if (drhd->ignored)
2110 continue; 1951 continue;
2111 iommu = drhd->iommu; 1952 iommu = drhd->iommu;
2112 sprintf (iommu->name, "dmar%d", unit++);
2113 1953
2114 iommu_flush_write_buffer(iommu); 1954 iommu_flush_write_buffer(iommu);
2115 1955
@@ -2284,11 +2124,13 @@ error:
2284 return 0; 2124 return 0;
2285} 2125}
2286 2126
2287dma_addr_t intel_map_single(struct device *hwdev, phys_addr_t paddr, 2127static dma_addr_t intel_map_page(struct device *dev, struct page *page,
2288 size_t size, int dir) 2128 unsigned long offset, size_t size,
2129 enum dma_data_direction dir,
2130 struct dma_attrs *attrs)
2289{ 2131{
2290 return __intel_map_single(hwdev, paddr, size, dir, 2132 return __intel_map_single(dev, page_to_phys(page) + offset, size,
2291 to_pci_dev(hwdev)->dma_mask); 2133 dir, to_pci_dev(dev)->dma_mask);
2292} 2134}
2293 2135
2294static void flush_unmaps(void) 2136static void flush_unmaps(void)
@@ -2352,8 +2194,9 @@ static void add_unmap(struct dmar_domain *dom, struct iova *iova)
2352 spin_unlock_irqrestore(&async_umap_flush_lock, flags); 2194 spin_unlock_irqrestore(&async_umap_flush_lock, flags);
2353} 2195}
2354 2196
2355void intel_unmap_single(struct device *dev, dma_addr_t dev_addr, size_t size, 2197static void intel_unmap_page(struct device *dev, dma_addr_t dev_addr,
2356 int dir) 2198 size_t size, enum dma_data_direction dir,
2199 struct dma_attrs *attrs)
2357{ 2200{
2358 struct pci_dev *pdev = to_pci_dev(dev); 2201 struct pci_dev *pdev = to_pci_dev(dev);
2359 struct dmar_domain *domain; 2202 struct dmar_domain *domain;
@@ -2397,8 +2240,14 @@ void intel_unmap_single(struct device *dev, dma_addr_t dev_addr, size_t size,
2397 } 2240 }
2398} 2241}
2399 2242
2400void *intel_alloc_coherent(struct device *hwdev, size_t size, 2243static void intel_unmap_single(struct device *dev, dma_addr_t dev_addr, size_t size,
2401 dma_addr_t *dma_handle, gfp_t flags) 2244 int dir)
2245{
2246 intel_unmap_page(dev, dev_addr, size, dir, NULL);
2247}
2248
2249static void *intel_alloc_coherent(struct device *hwdev, size_t size,
2250 dma_addr_t *dma_handle, gfp_t flags)
2402{ 2251{
2403 void *vaddr; 2252 void *vaddr;
2404 int order; 2253 int order;
@@ -2421,8 +2270,8 @@ void *intel_alloc_coherent(struct device *hwdev, size_t size,
2421 return NULL; 2270 return NULL;
2422} 2271}
2423 2272
2424void intel_free_coherent(struct device *hwdev, size_t size, void *vaddr, 2273static void intel_free_coherent(struct device *hwdev, size_t size, void *vaddr,
2425 dma_addr_t dma_handle) 2274 dma_addr_t dma_handle)
2426{ 2275{
2427 int order; 2276 int order;
2428 2277
@@ -2435,8 +2284,9 @@ void intel_free_coherent(struct device *hwdev, size_t size, void *vaddr,
2435 2284
2436#define SG_ENT_VIRT_ADDRESS(sg) (sg_virt((sg))) 2285#define SG_ENT_VIRT_ADDRESS(sg) (sg_virt((sg)))
2437 2286
2438void intel_unmap_sg(struct device *hwdev, struct scatterlist *sglist, 2287static void intel_unmap_sg(struct device *hwdev, struct scatterlist *sglist,
2439 int nelems, int dir) 2288 int nelems, enum dma_data_direction dir,
2289 struct dma_attrs *attrs)
2440{ 2290{
2441 int i; 2291 int i;
2442 struct pci_dev *pdev = to_pci_dev(hwdev); 2292 struct pci_dev *pdev = to_pci_dev(hwdev);
@@ -2493,8 +2343,8 @@ static int intel_nontranslate_map_sg(struct device *hddev,
2493 return nelems; 2343 return nelems;
2494} 2344}
2495 2345
2496int intel_map_sg(struct device *hwdev, struct scatterlist *sglist, int nelems, 2346static int intel_map_sg(struct device *hwdev, struct scatterlist *sglist, int nelems,
2497 int dir) 2347 enum dma_data_direction dir, struct dma_attrs *attrs)
2498{ 2348{
2499 void *addr; 2349 void *addr;
2500 int i; 2350 int i;
@@ -2574,13 +2424,19 @@ int intel_map_sg(struct device *hwdev, struct scatterlist *sglist, int nelems,
2574 return nelems; 2424 return nelems;
2575} 2425}
2576 2426
2577static struct dma_mapping_ops intel_dma_ops = { 2427static int intel_mapping_error(struct device *dev, dma_addr_t dma_addr)
2428{
2429 return !dma_addr;
2430}
2431
2432struct dma_map_ops intel_dma_ops = {
2578 .alloc_coherent = intel_alloc_coherent, 2433 .alloc_coherent = intel_alloc_coherent,
2579 .free_coherent = intel_free_coherent, 2434 .free_coherent = intel_free_coherent,
2580 .map_single = intel_map_single,
2581 .unmap_single = intel_unmap_single,
2582 .map_sg = intel_map_sg, 2435 .map_sg = intel_map_sg,
2583 .unmap_sg = intel_unmap_sg, 2436 .unmap_sg = intel_unmap_sg,
2437 .map_page = intel_map_page,
2438 .unmap_page = intel_unmap_page,
2439 .mapping_error = intel_mapping_error,
2584}; 2440};
2585 2441
2586static inline int iommu_domain_cache_init(void) 2442static inline int iommu_domain_cache_init(void)
diff --git a/drivers/pci/intr_remapping.c b/drivers/pci/intr_remapping.c
index 9d07a05d26f1..b041a409f4a7 100644
--- a/drivers/pci/intr_remapping.c
+++ b/drivers/pci/intr_remapping.c
@@ -117,21 +117,22 @@ int get_irte(int irq, struct irte *entry)
117{ 117{
118 int index; 118 int index;
119 struct irq_2_iommu *irq_iommu; 119 struct irq_2_iommu *irq_iommu;
120 unsigned long flags;
120 121
121 if (!entry) 122 if (!entry)
122 return -1; 123 return -1;
123 124
124 spin_lock(&irq_2_ir_lock); 125 spin_lock_irqsave(&irq_2_ir_lock, flags);
125 irq_iommu = valid_irq_2_iommu(irq); 126 irq_iommu = valid_irq_2_iommu(irq);
126 if (!irq_iommu) { 127 if (!irq_iommu) {
127 spin_unlock(&irq_2_ir_lock); 128 spin_unlock_irqrestore(&irq_2_ir_lock, flags);
128 return -1; 129 return -1;
129 } 130 }
130 131
131 index = irq_iommu->irte_index + irq_iommu->sub_handle; 132 index = irq_iommu->irte_index + irq_iommu->sub_handle;
132 *entry = *(irq_iommu->iommu->ir_table->base + index); 133 *entry = *(irq_iommu->iommu->ir_table->base + index);
133 134
134 spin_unlock(&irq_2_ir_lock); 135 spin_unlock_irqrestore(&irq_2_ir_lock, flags);
135 return 0; 136 return 0;
136} 137}
137 138
@@ -141,6 +142,7 @@ int alloc_irte(struct intel_iommu *iommu, int irq, u16 count)
141 struct irq_2_iommu *irq_iommu; 142 struct irq_2_iommu *irq_iommu;
142 u16 index, start_index; 143 u16 index, start_index;
143 unsigned int mask = 0; 144 unsigned int mask = 0;
145 unsigned long flags;
144 int i; 146 int i;
145 147
146 if (!count) 148 if (!count)
@@ -170,7 +172,7 @@ int alloc_irte(struct intel_iommu *iommu, int irq, u16 count)
170 return -1; 172 return -1;
171 } 173 }
172 174
173 spin_lock(&irq_2_ir_lock); 175 spin_lock_irqsave(&irq_2_ir_lock, flags);
174 do { 176 do {
175 for (i = index; i < index + count; i++) 177 for (i = index; i < index + count; i++)
176 if (table->base[i].present) 178 if (table->base[i].present)
@@ -182,7 +184,7 @@ int alloc_irte(struct intel_iommu *iommu, int irq, u16 count)
182 index = (index + count) % INTR_REMAP_TABLE_ENTRIES; 184 index = (index + count) % INTR_REMAP_TABLE_ENTRIES;
183 185
184 if (index == start_index) { 186 if (index == start_index) {
185 spin_unlock(&irq_2_ir_lock); 187 spin_unlock_irqrestore(&irq_2_ir_lock, flags);
186 printk(KERN_ERR "can't allocate an IRTE\n"); 188 printk(KERN_ERR "can't allocate an IRTE\n");
187 return -1; 189 return -1;
188 } 190 }
@@ -193,7 +195,7 @@ int alloc_irte(struct intel_iommu *iommu, int irq, u16 count)
193 195
194 irq_iommu = irq_2_iommu_alloc(irq); 196 irq_iommu = irq_2_iommu_alloc(irq);
195 if (!irq_iommu) { 197 if (!irq_iommu) {
196 spin_unlock(&irq_2_ir_lock); 198 spin_unlock_irqrestore(&irq_2_ir_lock, flags);
197 printk(KERN_ERR "can't allocate irq_2_iommu\n"); 199 printk(KERN_ERR "can't allocate irq_2_iommu\n");
198 return -1; 200 return -1;
199 } 201 }
@@ -203,7 +205,7 @@ int alloc_irte(struct intel_iommu *iommu, int irq, u16 count)
203 irq_iommu->sub_handle = 0; 205 irq_iommu->sub_handle = 0;
204 irq_iommu->irte_mask = mask; 206 irq_iommu->irte_mask = mask;
205 207
206 spin_unlock(&irq_2_ir_lock); 208 spin_unlock_irqrestore(&irq_2_ir_lock, flags);
207 209
208 return index; 210 return index;
209} 211}
@@ -223,30 +225,32 @@ int map_irq_to_irte_handle(int irq, u16 *sub_handle)
223{ 225{
224 int index; 226 int index;
225 struct irq_2_iommu *irq_iommu; 227 struct irq_2_iommu *irq_iommu;
228 unsigned long flags;
226 229
227 spin_lock(&irq_2_ir_lock); 230 spin_lock_irqsave(&irq_2_ir_lock, flags);
228 irq_iommu = valid_irq_2_iommu(irq); 231 irq_iommu = valid_irq_2_iommu(irq);
229 if (!irq_iommu) { 232 if (!irq_iommu) {
230 spin_unlock(&irq_2_ir_lock); 233 spin_unlock_irqrestore(&irq_2_ir_lock, flags);
231 return -1; 234 return -1;
232 } 235 }
233 236
234 *sub_handle = irq_iommu->sub_handle; 237 *sub_handle = irq_iommu->sub_handle;
235 index = irq_iommu->irte_index; 238 index = irq_iommu->irte_index;
236 spin_unlock(&irq_2_ir_lock); 239 spin_unlock_irqrestore(&irq_2_ir_lock, flags);
237 return index; 240 return index;
238} 241}
239 242
240int set_irte_irq(int irq, struct intel_iommu *iommu, u16 index, u16 subhandle) 243int set_irte_irq(int irq, struct intel_iommu *iommu, u16 index, u16 subhandle)
241{ 244{
242 struct irq_2_iommu *irq_iommu; 245 struct irq_2_iommu *irq_iommu;
246 unsigned long flags;
243 247
244 spin_lock(&irq_2_ir_lock); 248 spin_lock_irqsave(&irq_2_ir_lock, flags);
245 249
246 irq_iommu = irq_2_iommu_alloc(irq); 250 irq_iommu = irq_2_iommu_alloc(irq);
247 251
248 if (!irq_iommu) { 252 if (!irq_iommu) {
249 spin_unlock(&irq_2_ir_lock); 253 spin_unlock_irqrestore(&irq_2_ir_lock, flags);
250 printk(KERN_ERR "can't allocate irq_2_iommu\n"); 254 printk(KERN_ERR "can't allocate irq_2_iommu\n");
251 return -1; 255 return -1;
252 } 256 }
@@ -256,7 +260,7 @@ int set_irte_irq(int irq, struct intel_iommu *iommu, u16 index, u16 subhandle)
256 irq_iommu->sub_handle = subhandle; 260 irq_iommu->sub_handle = subhandle;
257 irq_iommu->irte_mask = 0; 261 irq_iommu->irte_mask = 0;
258 262
259 spin_unlock(&irq_2_ir_lock); 263 spin_unlock_irqrestore(&irq_2_ir_lock, flags);
260 264
261 return 0; 265 return 0;
262} 266}
@@ -264,11 +268,12 @@ int set_irte_irq(int irq, struct intel_iommu *iommu, u16 index, u16 subhandle)
264int clear_irte_irq(int irq, struct intel_iommu *iommu, u16 index) 268int clear_irte_irq(int irq, struct intel_iommu *iommu, u16 index)
265{ 269{
266 struct irq_2_iommu *irq_iommu; 270 struct irq_2_iommu *irq_iommu;
271 unsigned long flags;
267 272
268 spin_lock(&irq_2_ir_lock); 273 spin_lock_irqsave(&irq_2_ir_lock, flags);
269 irq_iommu = valid_irq_2_iommu(irq); 274 irq_iommu = valid_irq_2_iommu(irq);
270 if (!irq_iommu) { 275 if (!irq_iommu) {
271 spin_unlock(&irq_2_ir_lock); 276 spin_unlock_irqrestore(&irq_2_ir_lock, flags);
272 return -1; 277 return -1;
273 } 278 }
274 279
@@ -277,7 +282,7 @@ int clear_irte_irq(int irq, struct intel_iommu *iommu, u16 index)
277 irq_iommu->sub_handle = 0; 282 irq_iommu->sub_handle = 0;
278 irq_2_iommu(irq)->irte_mask = 0; 283 irq_2_iommu(irq)->irte_mask = 0;
279 284
280 spin_unlock(&irq_2_ir_lock); 285 spin_unlock_irqrestore(&irq_2_ir_lock, flags);
281 286
282 return 0; 287 return 0;
283} 288}
@@ -289,11 +294,12 @@ int modify_irte(int irq, struct irte *irte_modified)
289 struct irte *irte; 294 struct irte *irte;
290 struct intel_iommu *iommu; 295 struct intel_iommu *iommu;
291 struct irq_2_iommu *irq_iommu; 296 struct irq_2_iommu *irq_iommu;
297 unsigned long flags;
292 298
293 spin_lock(&irq_2_ir_lock); 299 spin_lock_irqsave(&irq_2_ir_lock, flags);
294 irq_iommu = valid_irq_2_iommu(irq); 300 irq_iommu = valid_irq_2_iommu(irq);
295 if (!irq_iommu) { 301 if (!irq_iommu) {
296 spin_unlock(&irq_2_ir_lock); 302 spin_unlock_irqrestore(&irq_2_ir_lock, flags);
297 return -1; 303 return -1;
298 } 304 }
299 305
@@ -302,11 +308,11 @@ int modify_irte(int irq, struct irte *irte_modified)
302 index = irq_iommu->irte_index + irq_iommu->sub_handle; 308 index = irq_iommu->irte_index + irq_iommu->sub_handle;
303 irte = &iommu->ir_table->base[index]; 309 irte = &iommu->ir_table->base[index];
304 310
305 set_64bit((unsigned long *)irte, irte_modified->low | (1 << 1)); 311 set_64bit((unsigned long *)irte, irte_modified->low);
306 __iommu_flush_cache(iommu, irte, sizeof(*irte)); 312 __iommu_flush_cache(iommu, irte, sizeof(*irte));
307 313
308 rc = qi_flush_iec(iommu, index, 0); 314 rc = qi_flush_iec(iommu, index, 0);
309 spin_unlock(&irq_2_ir_lock); 315 spin_unlock_irqrestore(&irq_2_ir_lock, flags);
310 316
311 return rc; 317 return rc;
312} 318}
@@ -317,11 +323,12 @@ int flush_irte(int irq)
317 int index; 323 int index;
318 struct intel_iommu *iommu; 324 struct intel_iommu *iommu;
319 struct irq_2_iommu *irq_iommu; 325 struct irq_2_iommu *irq_iommu;
326 unsigned long flags;
320 327
321 spin_lock(&irq_2_ir_lock); 328 spin_lock_irqsave(&irq_2_ir_lock, flags);
322 irq_iommu = valid_irq_2_iommu(irq); 329 irq_iommu = valid_irq_2_iommu(irq);
323 if (!irq_iommu) { 330 if (!irq_iommu) {
324 spin_unlock(&irq_2_ir_lock); 331 spin_unlock_irqrestore(&irq_2_ir_lock, flags);
325 return -1; 332 return -1;
326 } 333 }
327 334
@@ -330,7 +337,7 @@ int flush_irte(int irq)
330 index = irq_iommu->irte_index + irq_iommu->sub_handle; 337 index = irq_iommu->irte_index + irq_iommu->sub_handle;
331 338
332 rc = qi_flush_iec(iommu, index, irq_iommu->irte_mask); 339 rc = qi_flush_iec(iommu, index, irq_iommu->irte_mask);
333 spin_unlock(&irq_2_ir_lock); 340 spin_unlock_irqrestore(&irq_2_ir_lock, flags);
334 341
335 return rc; 342 return rc;
336} 343}
@@ -363,11 +370,12 @@ int free_irte(int irq)
363 struct irte *irte; 370 struct irte *irte;
364 struct intel_iommu *iommu; 371 struct intel_iommu *iommu;
365 struct irq_2_iommu *irq_iommu; 372 struct irq_2_iommu *irq_iommu;
373 unsigned long flags;
366 374
367 spin_lock(&irq_2_ir_lock); 375 spin_lock_irqsave(&irq_2_ir_lock, flags);
368 irq_iommu = valid_irq_2_iommu(irq); 376 irq_iommu = valid_irq_2_iommu(irq);
369 if (!irq_iommu) { 377 if (!irq_iommu) {
370 spin_unlock(&irq_2_ir_lock); 378 spin_unlock_irqrestore(&irq_2_ir_lock, flags);
371 return -1; 379 return -1;
372 } 380 }
373 381
@@ -378,7 +386,7 @@ int free_irte(int irq)
378 386
379 if (!irq_iommu->sub_handle) { 387 if (!irq_iommu->sub_handle) {
380 for (i = 0; i < (1 << irq_iommu->irte_mask); i++) 388 for (i = 0; i < (1 << irq_iommu->irte_mask); i++)
381 set_64bit((unsigned long *)irte, 0); 389 set_64bit((unsigned long *)(irte + i), 0);
382 rc = qi_flush_iec(iommu, index, irq_iommu->irte_mask); 390 rc = qi_flush_iec(iommu, index, irq_iommu->irte_mask);
383 } 391 }
384 392
@@ -387,7 +395,7 @@ int free_irte(int irq)
387 irq_iommu->sub_handle = 0; 395 irq_iommu->sub_handle = 0;
388 irq_iommu->irte_mask = 0; 396 irq_iommu->irte_mask = 0;
389 397
390 spin_unlock(&irq_2_ir_lock); 398 spin_unlock_irqrestore(&irq_2_ir_lock, flags);
391 399
392 return rc; 400 return rc;
393} 401}
@@ -439,12 +447,12 @@ static int setup_intr_remapping(struct intel_iommu *iommu, int mode)
439 struct page *pages; 447 struct page *pages;
440 448
441 ir_table = iommu->ir_table = kzalloc(sizeof(struct ir_table), 449 ir_table = iommu->ir_table = kzalloc(sizeof(struct ir_table),
442 GFP_KERNEL); 450 GFP_ATOMIC);
443 451
444 if (!iommu->ir_table) 452 if (!iommu->ir_table)
445 return -ENOMEM; 453 return -ENOMEM;
446 454
447 pages = alloc_pages(GFP_KERNEL | __GFP_ZERO, INTR_REMAP_PAGE_ORDER); 455 pages = alloc_pages(GFP_ATOMIC | __GFP_ZERO, INTR_REMAP_PAGE_ORDER);
448 456
449 if (!pages) { 457 if (!pages) {
450 printk(KERN_ERR "failed to allocate pages of order %d\n", 458 printk(KERN_ERR "failed to allocate pages of order %d\n",
@@ -459,11 +467,55 @@ static int setup_intr_remapping(struct intel_iommu *iommu, int mode)
459 return 0; 467 return 0;
460} 468}
461 469
470/*
471 * Disable Interrupt Remapping.
472 */
473static void disable_intr_remapping(struct intel_iommu *iommu)
474{
475 unsigned long flags;
476 u32 sts;
477
478 if (!ecap_ir_support(iommu->ecap))
479 return;
480
481 spin_lock_irqsave(&iommu->register_lock, flags);
482
483 sts = dmar_readq(iommu->reg + DMAR_GSTS_REG);
484 if (!(sts & DMA_GSTS_IRES))
485 goto end;
486
487 iommu->gcmd &= ~DMA_GCMD_IRE;
488 writel(iommu->gcmd, iommu->reg + DMAR_GCMD_REG);
489
490 IOMMU_WAIT_OP(iommu, DMAR_GSTS_REG,
491 readl, !(sts & DMA_GSTS_IRES), sts);
492
493end:
494 spin_unlock_irqrestore(&iommu->register_lock, flags);
495}
496
462int __init enable_intr_remapping(int eim) 497int __init enable_intr_remapping(int eim)
463{ 498{
464 struct dmar_drhd_unit *drhd; 499 struct dmar_drhd_unit *drhd;
465 int setup = 0; 500 int setup = 0;
466 501
502 for_each_drhd_unit(drhd) {
503 struct intel_iommu *iommu = drhd->iommu;
504
505 /*
506 * Clear previous faults.
507 */
508 dmar_fault(-1, iommu);
509
510 /*
511 * Disable intr remapping and queued invalidation, if already
512 * enabled prior to OS handover.
513 */
514 disable_intr_remapping(iommu);
515
516 dmar_disable_qi(iommu);
517 }
518
467 /* 519 /*
468 * check for the Interrupt-remapping support 520 * check for the Interrupt-remapping support
469 */ 521 */
diff --git a/drivers/ps3/ps3av.c b/drivers/ps3/ps3av.c
index 5324978b73fb..235e87fcb49f 100644
--- a/drivers/ps3/ps3av.c
+++ b/drivers/ps3/ps3av.c
@@ -838,7 +838,7 @@ static int ps3av_get_hw_conf(struct ps3av *ps3av)
838} 838}
839 839
840/* set mode using id */ 840/* set mode using id */
841int ps3av_set_video_mode(u32 id) 841int ps3av_set_video_mode(int id)
842{ 842{
843 int size; 843 int size;
844 u32 option; 844 u32 option;
@@ -940,7 +940,7 @@ EXPORT_SYMBOL_GPL(ps3av_audio_mute);
940static int ps3av_probe(struct ps3_system_bus_device *dev) 940static int ps3av_probe(struct ps3_system_bus_device *dev)
941{ 941{
942 int res; 942 int res;
943 u32 id; 943 int id;
944 944
945 dev_dbg(&dev->core, " -> %s:%d\n", __func__, __LINE__); 945 dev_dbg(&dev->core, " -> %s:%d\n", __func__, __LINE__);
946 dev_dbg(&dev->core, " timeout=%d\n", timeout); 946 dev_dbg(&dev->core, " timeout=%d\n", timeout);
@@ -962,8 +962,10 @@ static int ps3av_probe(struct ps3_system_bus_device *dev)
962 init_completion(&ps3av->done); 962 init_completion(&ps3av->done);
963 complete(&ps3av->done); 963 complete(&ps3av->done);
964 ps3av->wq = create_singlethread_workqueue("ps3avd"); 964 ps3av->wq = create_singlethread_workqueue("ps3avd");
965 if (!ps3av->wq) 965 if (!ps3av->wq) {
966 res = -ENOMEM;
966 goto fail; 967 goto fail;
968 }
967 969
968 switch (ps3_os_area_get_av_multi_out()) { 970 switch (ps3_os_area_get_av_multi_out()) {
969 case PS3_PARAM_AV_MULTI_OUT_NTSC: 971 case PS3_PARAM_AV_MULTI_OUT_NTSC:
@@ -994,6 +996,12 @@ static int ps3av_probe(struct ps3_system_bus_device *dev)
994 safe_mode = 1; 996 safe_mode = 1;
995#endif /* CONFIG_FB */ 997#endif /* CONFIG_FB */
996 id = ps3av_auto_videomode(&ps3av->av_hw_conf); 998 id = ps3av_auto_videomode(&ps3av->av_hw_conf);
999 if (id < 0) {
1000 printk(KERN_ERR "%s: invalid id :%d\n", __func__, id);
1001 res = -EINVAL;
1002 goto fail;
1003 }
1004
997 safe_mode = 0; 1005 safe_mode = 0;
998 1006
999 mutex_lock(&ps3av->mutex); 1007 mutex_lock(&ps3av->mutex);
@@ -1007,7 +1015,7 @@ static int ps3av_probe(struct ps3_system_bus_device *dev)
1007fail: 1015fail:
1008 kfree(ps3av); 1016 kfree(ps3av);
1009 ps3av = NULL; 1017 ps3av = NULL;
1010 return -ENOMEM; 1018 return res;
1011} 1019}
1012 1020
1013static int ps3av_remove(struct ps3_system_bus_device *dev) 1021static int ps3av_remove(struct ps3_system_bus_device *dev)
diff --git a/drivers/serial/cpm_uart/cpm_uart_core.c b/drivers/serial/cpm_uart/cpm_uart_core.c
index bde4b4b0b80f..5c6ef51da274 100644
--- a/drivers/serial/cpm_uart/cpm_uart_core.c
+++ b/drivers/serial/cpm_uart/cpm_uart_core.c
@@ -406,6 +406,18 @@ static int cpm_uart_startup(struct uart_port *port)
406 406
407 pr_debug("CPM uart[%d]:startup\n", port->line); 407 pr_debug("CPM uart[%d]:startup\n", port->line);
408 408
409 /* If the port is not the console, make sure rx is disabled. */
410 if (!(pinfo->flags & FLAG_CONSOLE)) {
411 /* Disable UART rx */
412 if (IS_SMC(pinfo)) {
413 clrbits16(&pinfo->smcp->smc_smcmr, SMCMR_REN);
414 clrbits8(&pinfo->smcp->smc_smcm, SMCM_RX);
415 } else {
416 clrbits32(&pinfo->sccp->scc_gsmrl, SCC_GSMRL_ENR);
417 clrbits16(&pinfo->sccp->scc_sccm, UART_SCCM_RX);
418 }
419 cpm_line_cr_cmd(pinfo, CPM_CR_INIT_TRX);
420 }
409 /* Install interrupt handler. */ 421 /* Install interrupt handler. */
410 retval = request_irq(port->irq, cpm_uart_int, 0, "cpm_uart", port); 422 retval = request_irq(port->irq, cpm_uart_int, 0, "cpm_uart", port);
411 if (retval) 423 if (retval)
@@ -420,8 +432,6 @@ static int cpm_uart_startup(struct uart_port *port)
420 setbits32(&pinfo->sccp->scc_gsmrl, (SCC_GSMRL_ENR | SCC_GSMRL_ENT)); 432 setbits32(&pinfo->sccp->scc_gsmrl, (SCC_GSMRL_ENR | SCC_GSMRL_ENT));
421 } 433 }
422 434
423 if (!(pinfo->flags & FLAG_CONSOLE))
424 cpm_line_cr_cmd(pinfo, CPM_CR_INIT_TRX);
425 return 0; 435 return 0;
426} 436}
427 437
diff --git a/drivers/serial/mpc52xx_uart.c b/drivers/serial/mpc52xx_uart.c
index 0c3a2ab1612c..7f72f8ceaa6f 100644
--- a/drivers/serial/mpc52xx_uart.c
+++ b/drivers/serial/mpc52xx_uart.c
@@ -50,8 +50,8 @@
50/* OF Platform device Usage : 50/* OF Platform device Usage :
51 * 51 *
52 * This driver is only used for PSCs configured in uart mode. The device 52 * This driver is only used for PSCs configured in uart mode. The device
53 * tree will have a node for each PSC in uart mode w/ device_type = "serial" 53 * tree will have a node for each PSC with "mpc52xx-psc-uart" in the compatible
54 * and "mpc52xx-psc-uart" in the compatible string 54 * list.
55 * 55 *
56 * By default, PSC devices are enumerated in the order they are found. However 56 * By default, PSC devices are enumerated in the order they are found. However
57 * a particular PSC number can be forces by adding 'device_no = <port#>' 57 * a particular PSC number can be forces by adding 'device_no = <port#>'
@@ -522,7 +522,7 @@ mpc52xx_uart_startup(struct uart_port *port)
522 522
523 /* Request IRQ */ 523 /* Request IRQ */
524 ret = request_irq(port->irq, mpc52xx_uart_int, 524 ret = request_irq(port->irq, mpc52xx_uart_int,
525 IRQF_DISABLED | IRQF_SAMPLE_RANDOM | IRQF_SHARED, 525 IRQF_DISABLED | IRQF_SAMPLE_RANDOM,
526 "mpc52xx_psc_uart", port); 526 "mpc52xx_psc_uart", port);
527 if (ret) 527 if (ret)
528 return ret; 528 return ret;
@@ -1212,30 +1212,18 @@ mpc52xx_uart_of_resume(struct of_device *op)
1212#endif 1212#endif
1213 1213
1214static void 1214static void
1215mpc52xx_uart_of_assign(struct device_node *np, int idx) 1215mpc52xx_uart_of_assign(struct device_node *np)
1216{ 1216{
1217 int free_idx = -1;
1218 int i; 1217 int i;
1219 1218
1220 /* Find the first free node */ 1219 /* Find the first free PSC number */
1221 for (i = 0; i < MPC52xx_PSC_MAXNUM; i++) { 1220 for (i = 0; i < MPC52xx_PSC_MAXNUM; i++) {
1222 if (mpc52xx_uart_nodes[i] == NULL) { 1221 if (mpc52xx_uart_nodes[i] == NULL) {
1223 free_idx = i; 1222 of_node_get(np);
1224 break; 1223 mpc52xx_uart_nodes[i] = np;
1224 return;
1225 } 1225 }
1226 } 1226 }
1227
1228 if ((idx < 0) || (idx >= MPC52xx_PSC_MAXNUM))
1229 idx = free_idx;
1230
1231 if (idx < 0)
1232 return; /* No free slot; abort */
1233
1234 of_node_get(np);
1235 /* If the slot is already occupied, then swap slots */
1236 if (mpc52xx_uart_nodes[idx] && (free_idx != -1))
1237 mpc52xx_uart_nodes[free_idx] = mpc52xx_uart_nodes[idx];
1238 mpc52xx_uart_nodes[idx] = np;
1239} 1227}
1240 1228
1241static void 1229static void
@@ -1243,23 +1231,17 @@ mpc52xx_uart_of_enumerate(void)
1243{ 1231{
1244 static int enum_done; 1232 static int enum_done;
1245 struct device_node *np; 1233 struct device_node *np;
1246 const unsigned int *devno;
1247 const struct of_device_id *match; 1234 const struct of_device_id *match;
1248 int i; 1235 int i;
1249 1236
1250 if (enum_done) 1237 if (enum_done)
1251 return; 1238 return;
1252 1239
1253 for_each_node_by_type(np, "serial") { 1240 /* Assign index to each PSC in device tree */
1241 for_each_matching_node(np, mpc52xx_uart_of_match) {
1254 match = of_match_node(mpc52xx_uart_of_match, np); 1242 match = of_match_node(mpc52xx_uart_of_match, np);
1255 if (!match)
1256 continue;
1257
1258 psc_ops = match->data; 1243 psc_ops = match->data;
1259 1244 mpc52xx_uart_of_assign(np);
1260 /* Is a particular device number requested? */
1261 devno = of_get_property(np, "port-number", NULL);
1262 mpc52xx_uart_of_assign(np, devno ? *devno : -1);
1263 } 1245 }
1264 1246
1265 enum_done = 1; 1247 enum_done = 1;
diff --git a/drivers/sh/maple/maple.c b/drivers/sh/maple/maple.c
index cab1ab7cfb78..93c20e135ee1 100644
--- a/drivers/sh/maple/maple.c
+++ b/drivers/sh/maple/maple.c
@@ -776,7 +776,7 @@ static struct maple_driver maple_unsupported_device = {
776 .bus = &maple_bus_type, 776 .bus = &maple_bus_type,
777 }, 777 },
778}; 778};
779/** 779/*
780 * maple_bus_type - core maple bus structure 780 * maple_bus_type - core maple bus structure
781 */ 781 */
782struct bus_type maple_bus_type = { 782struct bus_type maple_bus_type = {
diff --git a/drivers/spi/xilinx_spi.c b/drivers/spi/xilinx_spi.c
index fe7e5f35e5d0..494d3f756e29 100644
--- a/drivers/spi/xilinx_spi.c
+++ b/drivers/spi/xilinx_spi.c
@@ -354,7 +354,7 @@ static int __init xilinx_spi_of_probe(struct of_device *ofdev,
354 if (xspi->regs == NULL) { 354 if (xspi->regs == NULL) {
355 rc = -ENOMEM; 355 rc = -ENOMEM;
356 dev_warn(&ofdev->dev, "ioremap failure\n"); 356 dev_warn(&ofdev->dev, "ioremap failure\n");
357 goto put_master; 357 goto release_mem;
358 } 358 }
359 xspi->irq = r_irq->start; 359 xspi->irq = r_irq->start;
360 360
@@ -365,7 +365,7 @@ static int __init xilinx_spi_of_probe(struct of_device *ofdev,
365 prop = of_get_property(ofdev->node, "xlnx,num-ss-bits", &len); 365 prop = of_get_property(ofdev->node, "xlnx,num-ss-bits", &len);
366 if (!prop || len < sizeof(*prop)) { 366 if (!prop || len < sizeof(*prop)) {
367 dev_warn(&ofdev->dev, "no 'xlnx,num-ss-bits' property\n"); 367 dev_warn(&ofdev->dev, "no 'xlnx,num-ss-bits' property\n");
368 goto put_master; 368 goto unmap_io;
369 } 369 }
370 master->num_chipselect = *prop; 370 master->num_chipselect = *prop;
371 371
@@ -397,6 +397,8 @@ free_irq:
397 free_irq(xspi->irq, xspi); 397 free_irq(xspi->irq, xspi);
398unmap_io: 398unmap_io:
399 iounmap(xspi->regs); 399 iounmap(xspi->regs);
400release_mem:
401 release_mem_region(r_mem->start, resource_size(r_mem));
400put_master: 402put_master:
401 spi_master_put(master); 403 spi_master_put(master);
402 return rc; 404 return rc;
@@ -406,6 +408,7 @@ static int __devexit xilinx_spi_remove(struct of_device *ofdev)
406{ 408{
407 struct xilinx_spi *xspi; 409 struct xilinx_spi *xspi;
408 struct spi_master *master; 410 struct spi_master *master;
411 struct resource r_mem;
409 412
410 master = platform_get_drvdata(ofdev); 413 master = platform_get_drvdata(ofdev);
411 xspi = spi_master_get_devdata(master); 414 xspi = spi_master_get_devdata(master);
@@ -413,6 +416,8 @@ static int __devexit xilinx_spi_remove(struct of_device *ofdev)
413 spi_bitbang_stop(&xspi->bitbang); 416 spi_bitbang_stop(&xspi->bitbang);
414 free_irq(xspi->irq, xspi); 417 free_irq(xspi->irq, xspi);
415 iounmap(xspi->regs); 418 iounmap(xspi->regs);
419 if (!of_address_to_resource(ofdev->node, 0, &r_mem))
420 release_mem_region(r_mem.start, resource_size(&r_mem));
416 dev_set_drvdata(&ofdev->dev, 0); 421 dev_set_drvdata(&ofdev->dev, 0);
417 spi_master_put(xspi->bitbang.master); 422 spi_master_put(xspi->bitbang.master);
418 423
diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 55f64af072a4..63024145215d 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -772,7 +772,7 @@ config TXX9_WDT
772 772
773config GEF_WDT 773config GEF_WDT
774 tristate "GE Fanuc Watchdog Timer" 774 tristate "GE Fanuc Watchdog Timer"
775 depends on GEF_SBC610 775 depends on GEF_SBC610 || GEF_SBC310 || GEF_PPC9A
776 ---help--- 776 ---help---
777 Watchdog timer found in a number of GE Fanuc single board computers. 777 Watchdog timer found in a number of GE Fanuc single board computers.
778 778