aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2011-01-06 21:32:12 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2011-01-06 21:32:12 -0500
commit9e9bc9736756f25d6c47b4eba0ebf25b20a6f153 (patch)
tree647240f479c5f23910c3e6194d1c35b6ba54d75e /drivers
parent3c0cb7c31c206aaedb967e44b98442bbeb17a6c4 (diff)
parente3c92215198cb6aa00ad38db2780faa6b72e0a3f (diff)
Merge branch 'v4l_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-2.6
* 'v4l_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-2.6: (255 commits) [media] radio-aimslab.c: Fix gcc 4.5+ bug [media] cx25821: Fix compilation breakage due to BKL dependency [media] v4l2-compat-ioctl32: fix compile warning [media] zoran: fix compiler warning [media] tda18218: fix compile warning [media] ngene: fix compile warning [media] DVB: IR support for TechnoTrend CT-3650 [media] cx23885, cimax2.c: Fix case of two CAM insertion irq [media] ir-nec-decoder: fix repeat key issue [media] staging: se401 depends on USB [media] staging: usbvideo/vicam depends on USB [media] soc_camera: Add the ability to bind regulators to soc_camedra devices [media] V4L2: Add a v4l2-subdev (soc-camera) driver for OmniVision OV2640 sensor [media] v4l: soc-camera: switch to .unlocked_ioctl [media] v4l: ov772x: simplify pointer dereference [media] ov9640: fix OmniVision OV9640 sensor driver's priv data retrieving [media] ov9640: use macro to request OmniVision OV9640 sensor private data [media] ivtv-i2c: Fix two warnings [media] staging/lirc: Update lirc TODO files [media] cx88: Remove the obsolete i2c_adapter.id field ...
Diffstat (limited to 'drivers')
-rw-r--r--drivers/input/misc/Kconfig18
-rw-r--r--drivers/input/misc/Makefile1
-rw-r--r--drivers/media/IR/ir-functions.c356
-rw-r--r--drivers/media/IR/ir-keytable.c710
-rw-r--r--drivers/media/IR/ir-sysfs.c362
-rw-r--r--drivers/media/IR/keymaps/rc-tbs-nec.c73
-rw-r--r--drivers/media/IR/keymaps/rc-tt-1500.c82
-rw-r--r--drivers/media/IR/rc-map.c107
-rw-r--r--drivers/media/Kconfig53
-rw-r--r--drivers/media/Makefile2
-rw-r--r--drivers/media/common/saa7146_video.c32
-rw-r--r--drivers/media/common/tuners/max2165.c10
-rw-r--r--drivers/media/common/tuners/tda18218.c2
-rw-r--r--drivers/media/dvb/dm1105/Kconfig3
-rw-r--r--drivers/media/dvb/dm1105/dm1105.c44
-rw-r--r--drivers/media/dvb/dvb-core/dmxdev.c4
-rw-r--r--drivers/media/dvb/dvb-usb/Kconfig2
-rw-r--r--drivers/media/dvb/dvb-usb/a800.c6
-rw-r--r--drivers/media/dvb/dvb-usb/af9005-remote.c16
-rw-r--r--drivers/media/dvb/dvb-usb/af9005.c16
-rw-r--r--drivers/media/dvb/dvb-usb/af9005.h4
-rw-r--r--drivers/media/dvb/dvb-usb/af9015.c22
-rw-r--r--drivers/media/dvb/dvb-usb/anysee.c4
-rw-r--r--drivers/media/dvb/dvb-usb/az6027.c13
-rw-r--r--drivers/media/dvb/dvb-usb/cinergyT2-core.c6
-rw-r--r--drivers/media/dvb/dvb-usb/cxusb.c62
-rw-r--r--drivers/media/dvb/dvb-usb/dib0700.h2
-rw-r--r--drivers/media/dvb/dvb-usb/dib0700_core.c18
-rw-r--r--drivers/media/dvb/dvb-usb/dib0700_devices.c146
-rw-r--r--drivers/media/dvb/dvb-usb/dibusb-common.c4
-rw-r--r--drivers/media/dvb/dvb-usb/dibusb-mb.c16
-rw-r--r--drivers/media/dvb/dvb-usb/dibusb-mc.c4
-rw-r--r--drivers/media/dvb/dvb-usb/dibusb.h2
-rw-r--r--drivers/media/dvb/dvb-usb/digitv.c14
-rw-r--r--drivers/media/dvb/dvb-usb/dtt200u.c18
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-ids.h1
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-remote.c103
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb.h28
-rw-r--r--drivers/media/dvb/dvb-usb/dw2102.c54
-rw-r--r--drivers/media/dvb/dvb-usb/gp8psk.c28
-rw-r--r--drivers/media/dvb/dvb-usb/gp8psk.h8
-rw-r--r--drivers/media/dvb/dvb-usb/lmedm04.c329
-rw-r--r--drivers/media/dvb/dvb-usb/m920x.c24
-rw-r--r--drivers/media/dvb/dvb-usb/nova-t-usb2.c18
-rw-r--r--drivers/media/dvb/dvb-usb/opera1.c16
-rw-r--r--drivers/media/dvb/dvb-usb/ttusb2.c35
-rw-r--r--drivers/media/dvb/dvb-usb/vp702x.c12
-rw-r--r--drivers/media/dvb/dvb-usb/vp7045.c12
-rw-r--r--drivers/media/dvb/frontends/Kconfig10
-rw-r--r--drivers/media/dvb/frontends/Makefile2
-rw-r--r--drivers/media/dvb/frontends/af9013.c2
-rw-r--r--drivers/media/dvb/frontends/atbm8830.c8
-rw-r--r--drivers/media/dvb/frontends/au8522_decoder.c51
-rw-r--r--drivers/media/dvb/frontends/au8522_priv.h2
-rw-r--r--drivers/media/dvb/frontends/dib7000m.c10
-rw-r--r--drivers/media/dvb/frontends/dib7000p.c10
-rw-r--r--drivers/media/dvb/frontends/ix2505v.c2
-rw-r--r--drivers/media/dvb/frontends/lgs8gxx.c11
-rw-r--r--drivers/media/dvb/frontends/mb86a20s.c615
-rw-r--r--drivers/media/dvb/frontends/mb86a20s.h52
-rw-r--r--drivers/media/dvb/frontends/s921.c548
-rw-r--r--drivers/media/dvb/frontends/s921.h47
-rw-r--r--drivers/media/dvb/frontends/s921_core.c216
-rw-r--r--drivers/media/dvb/frontends/s921_core.h114
-rw-r--r--drivers/media/dvb/frontends/s921_module.c192
-rw-r--r--drivers/media/dvb/frontends/s921_module.h49
-rw-r--r--drivers/media/dvb/frontends/stb0899_drv.c2
-rw-r--r--drivers/media/dvb/frontends/stb6100.c198
-rw-r--r--drivers/media/dvb/frontends/stv090x.c6
-rw-r--r--drivers/media/dvb/mantis/Kconfig2
-rw-r--r--drivers/media/dvb/mantis/hopper_cards.c2
-rw-r--r--drivers/media/dvb/mantis/hopper_vp3028.c6
-rw-r--r--drivers/media/dvb/mantis/mantis_cards.c2
-rw-r--r--drivers/media/dvb/mantis/mantis_common.h4
-rw-r--r--drivers/media/dvb/mantis/mantis_dvb.c17
-rw-r--r--drivers/media/dvb/mantis/mantis_input.c76
-rw-r--r--drivers/media/dvb/mantis/mantis_ioc.c4
-rw-r--r--drivers/media/dvb/mantis/mantis_ioc.h2
-rw-r--r--drivers/media/dvb/mantis/mantis_vp1033.c2
-rw-r--r--drivers/media/dvb/mantis/mantis_vp1034.c10
-rw-r--r--drivers/media/dvb/mantis/mantis_vp1041.c6
-rw-r--r--drivers/media/dvb/mantis/mantis_vp2033.c4
-rw-r--r--drivers/media/dvb/mantis/mantis_vp2040.c4
-rw-r--r--drivers/media/dvb/mantis/mantis_vp3030.c8
-rw-r--r--drivers/media/dvb/ngene/ngene-core.c8
-rw-r--r--drivers/media/dvb/siano/Kconfig2
-rw-r--r--drivers/media/dvb/siano/smscoreapi.c2
-rw-r--r--drivers/media/dvb/siano/smsir.c52
-rw-r--r--drivers/media/dvb/siano/smsir.h5
-rw-r--r--drivers/media/dvb/siano/smsusb.c9
-rw-r--r--drivers/media/dvb/ttpci/Kconfig3
-rw-r--r--drivers/media/dvb/ttpci/av7110_v4l.c4
-rw-r--r--drivers/media/dvb/ttpci/budget-av.c6
-rw-r--r--drivers/media/dvb/ttpci/budget-ci.c54
-rw-r--r--drivers/media/radio/Kconfig16
-rw-r--r--drivers/media/radio/Makefile1
-rw-r--r--drivers/media/radio/radio-aimslab.c23
-rw-r--r--drivers/media/radio/radio-wl1273.c2330
-rw-r--r--drivers/media/radio/si470x/radio-si470x.h1
-rw-r--r--drivers/media/radio/si4713-i2c.c74
-rw-r--r--drivers/media/radio/si4713-i2c.h5
-rw-r--r--drivers/media/rc/Kconfig (renamed from drivers/media/IR/Kconfig)70
-rw-r--r--drivers/media/rc/Makefile (renamed from drivers/media/IR/Makefile)8
-rw-r--r--drivers/media/rc/ene_ir.c (renamed from drivers/media/IR/ene_ir.c)131
-rw-r--r--drivers/media/rc/ene_ir.h (renamed from drivers/media/IR/ene_ir.h)3
-rw-r--r--drivers/media/rc/imon.c (renamed from drivers/media/IR/imon.c)107
-rw-r--r--drivers/media/rc/ir-jvc-decoder.c (renamed from drivers/media/IR/ir-jvc-decoder.c)17
-rw-r--r--drivers/media/rc/ir-lirc-codec.c (renamed from drivers/media/IR/ir-lirc-codec.c)132
-rw-r--r--drivers/media/rc/ir-nec-decoder.c (renamed from drivers/media/IR/ir-nec-decoder.c)27
-rw-r--r--drivers/media/rc/ir-raw.c (renamed from drivers/media/IR/ir-raw-event.c)197
-rw-r--r--drivers/media/rc/ir-rc5-decoder.c (renamed from drivers/media/IR/ir-rc5-decoder.c)17
-rw-r--r--drivers/media/rc/ir-rc5-sz-decoder.c (renamed from drivers/media/IR/ir-rc5-sz-decoder.c)17
-rw-r--r--drivers/media/rc/ir-rc6-decoder.c (renamed from drivers/media/IR/ir-rc6-decoder.c)21
-rw-r--r--drivers/media/rc/ir-sony-decoder.c (renamed from drivers/media/IR/ir-sony-decoder.c)15
-rw-r--r--drivers/media/rc/keymaps/Kconfig (renamed from drivers/media/IR/keymaps/Kconfig)2
-rw-r--r--drivers/media/rc/keymaps/Makefile (renamed from drivers/media/IR/keymaps/Makefile)2
-rw-r--r--drivers/media/rc/keymaps/rc-adstech-dvb-t-pci.c (renamed from drivers/media/IR/keymaps/rc-adstech-dvb-t-pci.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-alink-dtu-m.c (renamed from drivers/media/IR/keymaps/rc-alink-dtu-m.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-anysee.c (renamed from drivers/media/IR/keymaps/rc-anysee.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-apac-viewcomp.c (renamed from drivers/media/IR/keymaps/rc-apac-viewcomp.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-asus-pc39.c (renamed from drivers/media/IR/keymaps/rc-asus-pc39.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-ati-tv-wonder-hd-600.c (renamed from drivers/media/IR/keymaps/rc-ati-tv-wonder-hd-600.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-avermedia-a16d.c (renamed from drivers/media/IR/keymaps/rc-avermedia-a16d.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-avermedia-cardbus.c (renamed from drivers/media/IR/keymaps/rc-avermedia-cardbus.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-avermedia-dvbt.c (renamed from drivers/media/IR/keymaps/rc-avermedia-dvbt.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-avermedia-m135a.c (renamed from drivers/media/IR/keymaps/rc-avermedia-m135a.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-avermedia-m733a-rm-k6.c (renamed from drivers/media/IR/keymaps/rc-avermedia-m733a-rm-k6.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-avermedia-rm-ks.c (renamed from drivers/media/IR/keymaps/rc-avermedia-rm-ks.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-avermedia.c (renamed from drivers/media/IR/keymaps/rc-avermedia.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-avertv-303.c (renamed from drivers/media/IR/keymaps/rc-avertv-303.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-azurewave-ad-tu700.c (renamed from drivers/media/IR/keymaps/rc-azurewave-ad-tu700.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-behold-columbus.c (renamed from drivers/media/IR/keymaps/rc-behold-columbus.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-behold.c (renamed from drivers/media/IR/keymaps/rc-behold.c)78
-rw-r--r--drivers/media/rc/keymaps/rc-budget-ci-old.c (renamed from drivers/media/IR/keymaps/rc-budget-ci-old.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-cinergy-1400.c (renamed from drivers/media/IR/keymaps/rc-cinergy-1400.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-cinergy.c (renamed from drivers/media/IR/keymaps/rc-cinergy.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-dib0700-nec.c (renamed from drivers/media/IR/keymaps/rc-dib0700-nec.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-dib0700-rc5.c (renamed from drivers/media/IR/keymaps/rc-dib0700-rc5.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-digitalnow-tinytwin.c (renamed from drivers/media/IR/keymaps/rc-digitalnow-tinytwin.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-digittrade.c (renamed from drivers/media/IR/keymaps/rc-digittrade.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-dm1105-nec.c (renamed from drivers/media/IR/keymaps/rc-dm1105-nec.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-dntv-live-dvb-t.c (renamed from drivers/media/IR/keymaps/rc-dntv-live-dvb-t.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-dntv-live-dvbt-pro.c (renamed from drivers/media/IR/keymaps/rc-dntv-live-dvbt-pro.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-em-terratec.c (renamed from drivers/media/IR/keymaps/rc-em-terratec.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-encore-enltv-fm53.c (renamed from drivers/media/IR/keymaps/rc-encore-enltv-fm53.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-encore-enltv.c (renamed from drivers/media/IR/keymaps/rc-encore-enltv.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-encore-enltv2.c (renamed from drivers/media/IR/keymaps/rc-encore-enltv2.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-evga-indtube.c (renamed from drivers/media/IR/keymaps/rc-evga-indtube.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-eztv.c (renamed from drivers/media/IR/keymaps/rc-eztv.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-flydvb.c (renamed from drivers/media/IR/keymaps/rc-flydvb.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-flyvideo.c (renamed from drivers/media/IR/keymaps/rc-flyvideo.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-fusionhdtv-mce.c (renamed from drivers/media/IR/keymaps/rc-fusionhdtv-mce.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-gadmei-rm008z.c (renamed from drivers/media/IR/keymaps/rc-gadmei-rm008z.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-genius-tvgo-a11mce.c (renamed from drivers/media/IR/keymaps/rc-genius-tvgo-a11mce.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-gotview7135.c (renamed from drivers/media/IR/keymaps/rc-gotview7135.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-hauppauge-new.c (renamed from drivers/media/IR/keymaps/rc-hauppauge-new.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-imon-mce.c (renamed from drivers/media/IR/keymaps/rc-imon-mce.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-imon-pad.c (renamed from drivers/media/IR/keymaps/rc-imon-pad.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-iodata-bctv7e.c (renamed from drivers/media/IR/keymaps/rc-iodata-bctv7e.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-kaiomy.c (renamed from drivers/media/IR/keymaps/rc-kaiomy.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-kworld-315u.c (renamed from drivers/media/IR/keymaps/rc-kworld-315u.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-kworld-plus-tv-analog.c (renamed from drivers/media/IR/keymaps/rc-kworld-plus-tv-analog.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-leadtek-y04g0051.c (renamed from drivers/media/IR/keymaps/rc-leadtek-y04g0051.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-lirc.c (renamed from drivers/media/IR/keymaps/rc-lirc.c)12
-rw-r--r--drivers/media/rc/keymaps/rc-lme2510.c (renamed from drivers/media/IR/keymaps/rc-lme2510.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-manli.c (renamed from drivers/media/IR/keymaps/rc-manli.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-msi-digivox-ii.c (renamed from drivers/media/IR/keymaps/rc-msi-digivox-ii.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-msi-digivox-iii.c (renamed from drivers/media/IR/keymaps/rc-msi-digivox-iii.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-msi-tvanywhere-plus.c (renamed from drivers/media/IR/keymaps/rc-msi-tvanywhere-plus.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-msi-tvanywhere.c (renamed from drivers/media/IR/keymaps/rc-msi-tvanywhere.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-nebula.c (renamed from drivers/media/IR/keymaps/rc-nebula.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-nec-terratec-cinergy-xs.c (renamed from drivers/media/IR/keymaps/rc-nec-terratec-cinergy-xs.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-norwood.c (renamed from drivers/media/IR/keymaps/rc-norwood.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-npgtech.c (renamed from drivers/media/IR/keymaps/rc-npgtech.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-pctv-sedna.c (renamed from drivers/media/IR/keymaps/rc-pctv-sedna.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-pinnacle-color.c (renamed from drivers/media/IR/keymaps/rc-pinnacle-color.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-pinnacle-grey.c (renamed from drivers/media/IR/keymaps/rc-pinnacle-grey.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-pinnacle-pctv-hd.c (renamed from drivers/media/IR/keymaps/rc-pinnacle-pctv-hd.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-pixelview-002t.c77
-rw-r--r--drivers/media/rc/keymaps/rc-pixelview-mk12.c (renamed from drivers/media/IR/keymaps/rc-pixelview-mk12.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-pixelview-new.c (renamed from drivers/media/IR/keymaps/rc-pixelview-new.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-pixelview.c (renamed from drivers/media/IR/keymaps/rc-pixelview.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-powercolor-real-angel.c (renamed from drivers/media/IR/keymaps/rc-powercolor-real-angel.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-proteus-2309.c (renamed from drivers/media/IR/keymaps/rc-proteus-2309.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-purpletv.c (renamed from drivers/media/IR/keymaps/rc-purpletv.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-pv951.c (renamed from drivers/media/IR/keymaps/rc-pv951.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-rc5-hauppauge-new.c (renamed from drivers/media/IR/keymaps/rc-rc5-hauppauge-new.c)48
-rw-r--r--drivers/media/rc/keymaps/rc-rc5-tv.c (renamed from drivers/media/IR/keymaps/rc-rc5-tv.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-rc6-mce.c (renamed from drivers/media/IR/keymaps/rc-rc6-mce.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-real-audio-220-32-keys.c (renamed from drivers/media/IR/keymaps/rc-real-audio-220-32-keys.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-streamzap.c (renamed from drivers/media/IR/keymaps/rc-streamzap.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-tbs-nec.c75
-rw-r--r--drivers/media/rc/keymaps/rc-terratec-cinergy-xs.c (renamed from drivers/media/IR/keymaps/rc-terratec-cinergy-xs.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-terratec-slim.c (renamed from drivers/media/IR/keymaps/rc-terratec-slim.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-tevii-nec.c (renamed from drivers/media/IR/keymaps/rc-tevii-nec.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-total-media-in-hand.c (renamed from drivers/media/IR/keymaps/rc-total-media-in-hand.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-trekstor.c (renamed from drivers/media/IR/keymaps/rc-trekstor.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-tt-1500.c82
-rw-r--r--drivers/media/rc/keymaps/rc-twinhan1027.c (renamed from drivers/media/IR/keymaps/rc-twinhan1027.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-videomate-m1f.c92
-rw-r--r--drivers/media/rc/keymaps/rc-videomate-s350.c (renamed from drivers/media/IR/keymaps/rc-videomate-s350.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-videomate-tv-pvr.c (renamed from drivers/media/IR/keymaps/rc-videomate-tv-pvr.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-winfast-usbii-deluxe.c (renamed from drivers/media/IR/keymaps/rc-winfast-usbii-deluxe.c)10
-rw-r--r--drivers/media/rc/keymaps/rc-winfast.c (renamed from drivers/media/IR/keymaps/rc-winfast.c)10
-rw-r--r--drivers/media/rc/lirc_dev.c (renamed from drivers/media/IR/lirc_dev.c)8
-rw-r--r--drivers/media/rc/mceusb.c (renamed from drivers/media/IR/mceusb.c)114
-rw-r--r--drivers/media/rc/nuvoton-cir.c (renamed from drivers/media/IR/nuvoton-cir.c)94
-rw-r--r--drivers/media/rc/nuvoton-cir.h (renamed from drivers/media/IR/nuvoton-cir.h)3
-rw-r--r--drivers/media/rc/rc-core-priv.h (renamed from drivers/media/IR/ir-core-priv.h)34
-rw-r--r--drivers/media/rc/rc-loopback.c260
-rw-r--r--drivers/media/rc/rc-main.c1135
-rw-r--r--drivers/media/rc/streamzap.c (renamed from drivers/media/IR/streamzap.c)81
-rw-r--r--drivers/media/rc/winbond-cir.c (renamed from drivers/input/misc/winbond-cir.c)886
-rw-r--r--drivers/media/video/Kconfig36
-rw-r--r--drivers/media/video/Makefile12
-rw-r--r--drivers/media/video/au0828/au0828-video.c118
-rw-r--r--drivers/media/video/au0828/au0828.h6
-rw-r--r--drivers/media/video/bt8xx/Kconfig4
-rw-r--r--drivers/media/video/bt8xx/bttv-driver.c48
-rw-r--r--drivers/media/video/bt8xx/bttv-input.c238
-rw-r--r--drivers/media/video/bt8xx/bttv.h1
-rw-r--r--drivers/media/video/bt8xx/bttvp.h34
-rw-r--r--drivers/media/video/cafe_ccic.c5
-rw-r--r--drivers/media/video/cpia2/cpia2_v4l.c38
-rw-r--r--drivers/media/video/cx18/Kconfig3
-rw-r--r--drivers/media/video/cx18/cx18-cards.c64
-rw-r--r--drivers/media/video/cx18/cx18-controls.c2
-rw-r--r--drivers/media/video/cx18/cx18-driver.c11
-rw-r--r--drivers/media/video/cx18/cx18-driver.h13
-rw-r--r--drivers/media/video/cx18/cx18-dvb.c64
-rw-r--r--drivers/media/video/cx18/cx18-i2c.c2
-rw-r--r--drivers/media/video/cx18/cx18-mailbox.c6
-rw-r--r--drivers/media/video/cx18/cx18-streams.c45
-rw-r--r--drivers/media/video/cx18/cx18-streams.h3
-rw-r--r--drivers/media/video/cx231xx/Kconfig19
-rw-r--r--drivers/media/video/cx231xx/Makefile5
-rw-r--r--drivers/media/video/cx231xx/cx231xx-417.c4
-rw-r--r--drivers/media/video/cx231xx/cx231xx-avcore.c7
-rw-r--r--drivers/media/video/cx231xx/cx231xx-cards.c65
-rw-r--r--drivers/media/video/cx231xx/cx231xx-core.c12
-rw-r--r--drivers/media/video/cx231xx/cx231xx-dvb.c40
-rw-r--r--drivers/media/video/cx231xx/cx231xx-input.c112
-rw-r--r--drivers/media/video/cx231xx/cx231xx-video.c12
-rw-r--r--drivers/media/video/cx231xx/cx231xx.h26
-rw-r--r--drivers/media/video/cx2341x.c8
-rw-r--r--drivers/media/video/cx23885/Kconfig2
-rw-r--r--drivers/media/video/cx23885/cimax2.c24
-rw-r--r--drivers/media/video/cx23885/cx23885-cards.c33
-rw-r--r--drivers/media/video/cx23885/cx23885-input.c70
-rw-r--r--drivers/media/video/cx23885/cx23885-video.c33
-rw-r--r--drivers/media/video/cx23885/cx23885.h6
-rw-r--r--drivers/media/video/cx23885/cx23888-ir.c2
-rw-r--r--drivers/media/video/cx25840/cx25840-ir.c2
-rw-r--r--drivers/media/video/cx88/Kconfig3
-rw-r--r--drivers/media/video/cx88/cx88-blackbird.c2
-rw-r--r--drivers/media/video/cx88/cx88-cards.c2
-rw-r--r--drivers/media/video/cx88/cx88-dvb.c8
-rw-r--r--drivers/media/video/cx88/cx88-i2c.c1
-rw-r--r--drivers/media/video/cx88/cx88-input.c282
-rw-r--r--drivers/media/video/cx88/cx88-video.c12
-rw-r--r--drivers/media/video/cx88/cx88-vp3054-i2c.c1
-rw-r--r--drivers/media/video/davinci/vpfe_capture.c2
-rw-r--r--drivers/media/video/em28xx/Kconfig5
-rw-r--r--drivers/media/video/em28xx/em28xx-cards.c76
-rw-r--r--drivers/media/video/em28xx/em28xx-dvb.c16
-rw-r--r--drivers/media/video/em28xx/em28xx-input.c78
-rw-r--r--drivers/media/video/em28xx/em28xx-vbi.c1
-rw-r--r--drivers/media/video/em28xx/em28xx-video.c30
-rw-r--r--drivers/media/video/em28xx/em28xx.h4
-rw-r--r--drivers/media/video/et61x251/et61x251_core.c1
-rw-r--r--drivers/media/video/fsl-viu.c26
-rw-r--r--drivers/media/video/gspca/cpia1.c12
-rw-r--r--drivers/media/video/gspca/gspca.c64
-rw-r--r--drivers/media/video/gspca/gspca.h4
-rw-r--r--drivers/media/video/gspca/m5602/m5602_ov9650.c2
-rw-r--r--drivers/media/video/gspca/ov519.c1683
-rw-r--r--drivers/media/video/gspca/ov534.c14
-rw-r--r--drivers/media/video/gspca/ov534_9.c1
-rw-r--r--drivers/media/video/gspca/pac207.c4
-rw-r--r--drivers/media/video/gspca/pac7302.c2
-rw-r--r--drivers/media/video/gspca/pac7311.c2
-rw-r--r--drivers/media/video/gspca/sn9c20x.c141
-rw-r--r--drivers/media/video/gspca/sonixb.c236
-rw-r--r--drivers/media/video/gspca/sonixj.c20
-rw-r--r--drivers/media/video/gspca/spca561.c2
-rw-r--r--drivers/media/video/gspca/sq905c.c1
-rw-r--r--drivers/media/video/gspca/sq930x.c28
-rw-r--r--drivers/media/video/gspca/stv06xx/stv06xx.c57
-rw-r--r--drivers/media/video/gspca/stv06xx/stv06xx_hdcs.h11
-rw-r--r--drivers/media/video/gspca/stv06xx/stv06xx_pb0100.c18
-rw-r--r--drivers/media/video/gspca/stv06xx/stv06xx_pb0100.h3
-rw-r--r--drivers/media/video/gspca/stv06xx/stv06xx_sensor.h4
-rw-r--r--drivers/media/video/gspca/stv06xx/stv06xx_st6422.c291
-rw-r--r--drivers/media/video/gspca/stv06xx/stv06xx_st6422.h13
-rw-r--r--drivers/media/video/gspca/stv06xx/stv06xx_vv6410.h9
-rw-r--r--drivers/media/video/gspca/t613.c2
-rw-r--r--drivers/media/video/gspca/tv8532.c2
-rw-r--r--drivers/media/video/gspca/vc032x.c74
-rw-r--r--drivers/media/video/gspca/w996Xcf.c325
-rw-r--r--drivers/media/video/gspca/xirlink_cit.c194
-rw-r--r--drivers/media/video/gspca/zc3xx.c292
-rw-r--r--drivers/media/video/hdpvr/hdpvr-core.c5
-rw-r--r--drivers/media/video/hdpvr/hdpvr-i2c.c53
-rw-r--r--drivers/media/video/hdpvr/hdpvr.h6
-rw-r--r--drivers/media/video/hexium_gemini.c18
-rw-r--r--drivers/media/video/hexium_orion.c18
-rw-r--r--drivers/media/video/imx074.c1
-rw-r--r--drivers/media/video/ir-kbd-i2c.c76
-rw-r--r--drivers/media/video/ivtv/Kconfig3
-rw-r--r--drivers/media/video/ivtv/ivtv-cards.c5
-rw-r--r--drivers/media/video/ivtv/ivtv-cards.h4
-rw-r--r--drivers/media/video/ivtv/ivtv-driver.c28
-rw-r--r--drivers/media/video/ivtv/ivtv-fileops.c4
-rw-r--r--drivers/media/video/ivtv/ivtv-i2c.c43
-rw-r--r--drivers/media/video/ivtv/ivtv-vbi.c115
-rw-r--r--drivers/media/video/ivtv/ivtv-vbi.h5
-rw-r--r--drivers/media/video/mem2mem_testdev.c21
-rw-r--r--drivers/media/video/mt9m001.c1
-rw-r--r--drivers/media/video/mt9m111.c1
-rw-r--r--drivers/media/video/mt9t031.c1
-rw-r--r--drivers/media/video/mt9v022.c1
-rw-r--r--drivers/media/video/mx1_camera.c7
-rw-r--r--drivers/media/video/mx2_camera.c3
-rw-r--r--drivers/media/video/mx3_camera.c5
-rw-r--r--drivers/media/video/mxb.c8
-rw-r--r--drivers/media/video/omap/omap_vout.c1
-rw-r--r--drivers/media/video/omap1_camera.c4
-rw-r--r--drivers/media/video/ov2640.c1205
-rw-r--r--drivers/media/video/ov772x.c17
-rw-r--r--drivers/media/video/ov9640.c19
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-ctrl.c6
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h2
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-sysfs.c2
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-v4l2.c4
-rw-r--r--drivers/media/video/pwc/pwc-ctrl.c7
-rw-r--r--drivers/media/video/pwc/pwc-if.c68
-rw-r--r--drivers/media/video/pwc/pwc-v4l.c30
-rw-r--r--drivers/media/video/pwc/pwc.h1
-rw-r--r--drivers/media/video/pxa_camera.c2
-rw-r--r--drivers/media/video/rj54n1cb0c.c1
-rw-r--r--drivers/media/video/s2255drv.c43
-rw-r--r--drivers/media/video/s5p-fimc/fimc-core.c2
-rw-r--r--drivers/media/video/saa6588.c14
-rw-r--r--drivers/media/video/saa7115.c11
-rw-r--r--drivers/media/video/saa7134/Kconfig2
-rw-r--r--drivers/media/video/saa7134/saa7134-cards.c148
-rw-r--r--drivers/media/video/saa7134/saa7134-dvb.c69
-rw-r--r--drivers/media/video/saa7134/saa7134-input.c435
-rw-r--r--drivers/media/video/saa7134/saa7134-tvaudio.c12
-rw-r--r--drivers/media/video/saa7134/saa7134-video.c26
-rw-r--r--drivers/media/video/saa7134/saa7134.h26
-rw-r--r--drivers/media/video/saa7164/saa7164-api.c123
-rw-r--r--drivers/media/video/saa7164/saa7164-buffer.c92
-rw-r--r--drivers/media/video/saa7164/saa7164-bus.c16
-rw-r--r--drivers/media/video/saa7164/saa7164-cards.c2
-rw-r--r--drivers/media/video/saa7164/saa7164-cmd.c10
-rw-r--r--drivers/media/video/saa7164/saa7164-core.c40
-rw-r--r--drivers/media/video/saa7164/saa7164-encoder.c33
-rw-r--r--drivers/media/video/saa7164/saa7164-fw.c12
-rw-r--r--drivers/media/video/saa7164/saa7164-i2c.c4
-rw-r--r--drivers/media/video/saa7164/saa7164-vbi.c37
-rw-r--r--drivers/media/video/saa7164/saa7164.h17
-rw-r--r--drivers/media/video/sh_mobile_ceu_camera.c2
-rw-r--r--drivers/media/video/sn9c102/sn9c102_core.c1
-rw-r--r--drivers/media/video/sn9c102/sn9c102_devtable.h4
-rw-r--r--drivers/media/video/soc_camera.c133
-rw-r--r--drivers/media/video/sr030pc30.c2
-rw-r--r--drivers/media/video/stk-webcam.c148
-rw-r--r--drivers/media/video/tea6415c.c2
-rw-r--r--drivers/media/video/timblogiw.c893
-rw-r--r--drivers/media/video/tlg2300/Kconfig4
-rw-r--r--drivers/media/video/usbvideo/Kconfig45
-rw-r--r--drivers/media/video/usbvideo/Makefile4
-rw-r--r--drivers/media/video/usbvideo/ibmcam.c3977
-rw-r--r--drivers/media/video/usbvideo/konicawc.c992
-rw-r--r--drivers/media/video/usbvideo/ultracam.c685
-rw-r--r--drivers/media/video/usbvision/usbvision-cards.c1860
-rw-r--r--drivers/media/video/usbvision/usbvision-core.c1635
-rw-r--r--drivers/media/video/usbvision/usbvision-i2c.c55
-rw-r--r--drivers/media/video/usbvision/usbvision-video.c625
-rw-r--r--drivers/media/video/usbvision/usbvision.h267
-rw-r--r--drivers/media/video/uvc/uvc_v4l2.c7
-rw-r--r--drivers/media/video/v4l1-compat.c1277
-rw-r--r--drivers/media/video/v4l2-common.c6
-rw-r--r--drivers/media/video/v4l2-compat-ioctl32.c330
-rw-r--r--drivers/media/video/v4l2-ctrls.c55
-rw-r--r--drivers/media/video/v4l2-ioctl.c86
-rw-r--r--drivers/media/video/via-camera.c13
-rw-r--r--drivers/media/video/videobuf-core.c30
-rw-r--r--drivers/media/video/videobuf-dma-sg.c34
-rw-r--r--drivers/media/video/vino.c3
-rw-r--r--drivers/media/video/vivi.c12
-rw-r--r--drivers/media/video/zoran/zoran.h107
-rw-r--r--drivers/media/video/zoran/zoran_card.c2
-rw-r--r--drivers/media/video/zoran/zoran_device.c2
-rw-r--r--drivers/media/video/zoran/zoran_driver.c328
-rw-r--r--drivers/mfd/Kconfig10
-rw-r--r--drivers/mfd/Makefile1
-rw-r--r--drivers/mfd/timberdale.c61
-rw-r--r--drivers/mfd/timberdale.h2
-rw-r--r--drivers/mfd/wl1273-core.c148
-rw-r--r--drivers/staging/Kconfig6
-rw-r--r--drivers/staging/Makefile5
-rw-r--r--drivers/staging/cpia/Kconfig39
-rw-r--r--drivers/staging/cpia/Makefile5
-rw-r--r--drivers/staging/cpia/TODO8
-rw-r--r--drivers/staging/cpia/cpia.c4028
-rw-r--r--drivers/staging/cpia/cpia.h432
-rw-r--r--drivers/staging/cpia/cpia_pp.c869
-rw-r--r--drivers/staging/cpia/cpia_usb.c640
-rw-r--r--drivers/staging/cx25821/Kconfig4
-rw-r--r--drivers/staging/cx25821/cx25821-alsa.c71
-rw-r--r--drivers/staging/cx25821/cx25821-audio-upstream.c66
-rw-r--r--drivers/staging/cx25821/cx25821-cards.c2
-rw-r--r--drivers/staging/cx25821/cx25821-core.c191
-rw-r--r--drivers/staging/cx25821/cx25821-i2c.c19
-rw-r--r--drivers/staging/cx25821/cx25821-medusa-video.c7
-rw-r--r--drivers/staging/cx25821/cx25821-video-upstream-ch2.c63
-rw-r--r--drivers/staging/cx25821/cx25821-video-upstream.c90
-rw-r--r--drivers/staging/cx25821/cx25821-video.c116
-rw-r--r--drivers/staging/cx25821/cx25821-video.h15
-rw-r--r--drivers/staging/cx25821/cx25821.h9
-rw-r--r--drivers/staging/dabusb/Kconfig14
-rw-r--r--drivers/staging/dabusb/Makefile2
-rw-r--r--drivers/staging/dabusb/TODO5
-rw-r--r--drivers/staging/dabusb/dabusb.c (renamed from drivers/media/video/dabusb.c)0
-rw-r--r--drivers/staging/dabusb/dabusb.h (renamed from drivers/media/video/dabusb.h)0
-rw-r--r--drivers/staging/dt3155v4l/dt3155v4l.c3
-rw-r--r--drivers/staging/go7007/Kconfig4
-rw-r--r--drivers/staging/lirc/Kconfig29
-rw-r--r--drivers/staging/lirc/Makefile1
-rw-r--r--drivers/staging/lirc/TODO.lirc_i2c3
-rw-r--r--drivers/staging/lirc/TODO.lirc_zilog13
-rw-r--r--drivers/staging/lirc/lirc_i2c.c536
-rw-r--r--drivers/staging/lirc/lirc_zilog.c48
-rw-r--r--drivers/staging/se401/Kconfig13
-rw-r--r--drivers/staging/se401/Makefile1
-rw-r--r--drivers/staging/se401/TODO5
-rw-r--r--drivers/staging/se401/se401.c (renamed from drivers/media/video/se401.c)0
-rw-r--r--drivers/staging/se401/se401.h (renamed from drivers/media/video/se401.h)2
-rw-r--r--drivers/staging/se401/videodev.h318
-rw-r--r--drivers/staging/stradis/Kconfig7
-rw-r--r--drivers/staging/stradis/Makefile3
-rw-r--r--drivers/staging/stradis/TODO6
-rw-r--r--drivers/staging/stradis/stradis.c2222
-rw-r--r--drivers/staging/tm6000/Kconfig2
-rw-r--r--drivers/staging/tm6000/TODO2
-rw-r--r--drivers/staging/tm6000/tm6000-cards.c48
-rw-r--r--drivers/staging/tm6000/tm6000-core.c29
-rw-r--r--drivers/staging/tm6000/tm6000-i2c.c39
-rw-r--r--drivers/staging/tm6000/tm6000-input.c287
-rw-r--r--drivers/staging/tm6000/tm6000-video.c17
-rw-r--r--drivers/staging/tm6000/tm6000.h3
-rw-r--r--drivers/staging/usbvideo/Kconfig15
-rw-r--r--drivers/staging/usbvideo/Makefile2
-rw-r--r--drivers/staging/usbvideo/TODO5
-rw-r--r--drivers/staging/usbvideo/usbvideo.c (renamed from drivers/media/video/usbvideo/usbvideo.c)0
-rw-r--r--drivers/staging/usbvideo/usbvideo.h (renamed from drivers/media/video/usbvideo/usbvideo.h)2
-rw-r--r--drivers/staging/usbvideo/vicam.c (renamed from drivers/media/video/usbvideo/vicam.c)2
-rw-r--r--drivers/staging/usbvideo/videodev.h318
460 files changed, 17443 insertions, 27815 deletions
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index b99b8cbde02f..c1a81bcdb319 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -294,24 +294,6 @@ config INPUT_SGI_BTNS
294 To compile this driver as a module, choose M here: the 294 To compile this driver as a module, choose M here: the
295 module will be called sgi_btns. 295 module will be called sgi_btns.
296 296
297config INPUT_WINBOND_CIR
298 tristate "Winbond IR remote control"
299 depends on X86 && PNP
300 select NEW_LEDS
301 select LEDS_CLASS
302 select LEDS_TRIGGERS
303 select BITREVERSE
304 help
305 Say Y here if you want to use the IR remote functionality found
306 in some Winbond SuperI/O chips. Currently only the WPCD376I
307 chip is supported (included in some Intel Media series motherboards).
308
309 IR Receive and wake-on-IR from suspend and power-off is currently
310 supported.
311
312 To compile this driver as a module, choose M here: the module will be
313 called winbond_cir.
314
315config HP_SDC_RTC 297config HP_SDC_RTC
316 tristate "HP SDC Real Time Clock" 298 tristate "HP SDC Real Time Clock"
317 depends on (GSC || HP300) && SERIO 299 depends on (GSC || HP300) && SERIO
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index 1fe1f6c8b737..06b2b5154038 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -38,7 +38,6 @@ obj-$(CONFIG_INPUT_SPARCSPKR) += sparcspkr.o
38obj-$(CONFIG_INPUT_TWL4030_PWRBUTTON) += twl4030-pwrbutton.o 38obj-$(CONFIG_INPUT_TWL4030_PWRBUTTON) += twl4030-pwrbutton.o
39obj-$(CONFIG_INPUT_TWL4030_VIBRA) += twl4030-vibra.o 39obj-$(CONFIG_INPUT_TWL4030_VIBRA) += twl4030-vibra.o
40obj-$(CONFIG_INPUT_UINPUT) += uinput.o 40obj-$(CONFIG_INPUT_UINPUT) += uinput.o
41obj-$(CONFIG_INPUT_WINBOND_CIR) += winbond-cir.o
42obj-$(CONFIG_INPUT_WISTRON_BTNS) += wistron_btns.o 41obj-$(CONFIG_INPUT_WISTRON_BTNS) += wistron_btns.o
43obj-$(CONFIG_INPUT_WM831X_ON) += wm831x-on.o 42obj-$(CONFIG_INPUT_WM831X_ON) += wm831x-on.o
44obj-$(CONFIG_INPUT_YEALINK) += yealink.o 43obj-$(CONFIG_INPUT_YEALINK) += yealink.o
diff --git a/drivers/media/IR/ir-functions.c b/drivers/media/IR/ir-functions.c
deleted file mode 100644
index db591e421887..000000000000
--- a/drivers/media/IR/ir-functions.c
+++ /dev/null
@@ -1,356 +0,0 @@
1/*
2 *
3 * some common structs and functions to handle infrared remotes via
4 * input layer ...
5 *
6 * (c) 2003 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23#include <linux/module.h>
24#include <linux/string.h>
25#include <linux/jiffies.h>
26#include <media/ir-common.h>
27#include "ir-core-priv.h"
28
29/* -------------------------------------------------------------------------- */
30
31MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
32MODULE_LICENSE("GPL");
33
34static int repeat = 1;
35module_param(repeat, int, 0444);
36MODULE_PARM_DESC(repeat,"auto-repeat for IR keys (default: on)");
37
38/* -------------------------------------------------------------------------- */
39
40static void ir_input_key_event(struct input_dev *dev, struct ir_input_state *ir)
41{
42 if (KEY_RESERVED == ir->keycode) {
43 printk(KERN_INFO "%s: unknown key: key=0x%02x down=%d\n",
44 dev->name, ir->ir_key, ir->keypressed);
45 return;
46 }
47 IR_dprintk(1,"%s: key event code=%d down=%d\n",
48 dev->name,ir->keycode,ir->keypressed);
49 input_report_key(dev,ir->keycode,ir->keypressed);
50 input_sync(dev);
51}
52
53/* -------------------------------------------------------------------------- */
54
55int ir_input_init(struct input_dev *dev, struct ir_input_state *ir,
56 const u64 ir_type)
57{
58 ir->ir_type = ir_type;
59
60 if (repeat)
61 set_bit(EV_REP, dev->evbit);
62
63 return 0;
64}
65EXPORT_SYMBOL_GPL(ir_input_init);
66
67
68void ir_input_nokey(struct input_dev *dev, struct ir_input_state *ir)
69{
70 if (ir->keypressed) {
71 ir->keypressed = 0;
72 ir_input_key_event(dev,ir);
73 }
74}
75EXPORT_SYMBOL_GPL(ir_input_nokey);
76
77void ir_input_keydown(struct input_dev *dev, struct ir_input_state *ir,
78 u32 ir_key)
79{
80 u32 keycode = ir_g_keycode_from_table(dev, ir_key);
81
82 if (ir->keypressed && ir->keycode != keycode) {
83 ir->keypressed = 0;
84 ir_input_key_event(dev,ir);
85 }
86 if (!ir->keypressed) {
87 ir->ir_key = ir_key;
88 ir->keycode = keycode;
89 ir->keypressed = 1;
90 ir_input_key_event(dev,ir);
91 }
92}
93EXPORT_SYMBOL_GPL(ir_input_keydown);
94
95/* -------------------------------------------------------------------------- */
96/* extract mask bits out of data and pack them into the result */
97u32 ir_extract_bits(u32 data, u32 mask)
98{
99 u32 vbit = 1, value = 0;
100
101 do {
102 if (mask&1) {
103 if (data&1)
104 value |= vbit;
105 vbit<<=1;
106 }
107 data>>=1;
108 } while (mask>>=1);
109
110 return value;
111}
112EXPORT_SYMBOL_GPL(ir_extract_bits);
113
114static int inline getbit(u32 *samples, int bit)
115{
116 return (samples[bit/32] & (1 << (31-(bit%32)))) ? 1 : 0;
117}
118
119/* sump raw samples for visual debugging ;) */
120int ir_dump_samples(u32 *samples, int count)
121{
122 int i, bit, start;
123
124 printk(KERN_DEBUG "ir samples: ");
125 start = 0;
126 for (i = 0; i < count * 32; i++) {
127 bit = getbit(samples,i);
128 if (bit)
129 start = 1;
130 if (0 == start)
131 continue;
132 printk("%s", bit ? "#" : "_");
133 }
134 printk("\n");
135 return 0;
136}
137EXPORT_SYMBOL_GPL(ir_dump_samples);
138
139/* decode raw samples, pulse distance coding used by NEC remotes */
140int ir_decode_pulsedistance(u32 *samples, int count, int low, int high)
141{
142 int i,last,bit,len;
143 u32 curBit;
144 u32 value;
145
146 /* find start burst */
147 for (i = len = 0; i < count * 32; i++) {
148 bit = getbit(samples,i);
149 if (bit) {
150 len++;
151 } else {
152 if (len >= 29)
153 break;
154 len = 0;
155 }
156 }
157
158 /* start burst to short */
159 if (len < 29)
160 return 0xffffffff;
161
162 /* find start silence */
163 for (len = 0; i < count * 32; i++) {
164 bit = getbit(samples,i);
165 if (bit) {
166 break;
167 } else {
168 len++;
169 }
170 }
171
172 /* silence to short */
173 if (len < 7)
174 return 0xffffffff;
175
176 /* go decoding */
177 len = 0;
178 last = 1;
179 value = 0; curBit = 1;
180 for (; i < count * 32; i++) {
181 bit = getbit(samples,i);
182 if (last) {
183 if(bit) {
184 continue;
185 } else {
186 len = 1;
187 }
188 } else {
189 if (bit) {
190 if (len > (low + high) /2)
191 value |= curBit;
192 curBit <<= 1;
193 if (curBit == 1)
194 break;
195 } else {
196 len++;
197 }
198 }
199 last = bit;
200 }
201
202 return value;
203}
204EXPORT_SYMBOL_GPL(ir_decode_pulsedistance);
205
206/* decode raw samples, biphase coding, used by rc5 for example */
207int ir_decode_biphase(u32 *samples, int count, int low, int high)
208{
209 int i,last,bit,len,flips;
210 u32 value;
211
212 /* find start bit (1) */
213 for (i = 0; i < 32; i++) {
214 bit = getbit(samples,i);
215 if (bit)
216 break;
217 }
218
219 /* go decoding */
220 len = 0;
221 flips = 0;
222 value = 1;
223 for (; i < count * 32; i++) {
224 if (len > high)
225 break;
226 if (flips > 1)
227 break;
228 last = bit;
229 bit = getbit(samples,i);
230 if (last == bit) {
231 len++;
232 continue;
233 }
234 if (len < low) {
235 len++;
236 flips++;
237 continue;
238 }
239 value <<= 1;
240 value |= bit;
241 flips = 0;
242 len = 1;
243 }
244 return value;
245}
246EXPORT_SYMBOL_GPL(ir_decode_biphase);
247
248/* RC5 decoding stuff, moved from bttv-input.c to share it with
249 * saa7134 */
250
251/* decode raw bit pattern to RC5 code */
252u32 ir_rc5_decode(unsigned int code)
253{
254 unsigned int org_code = code;
255 unsigned int pair;
256 unsigned int rc5 = 0;
257 int i;
258
259 for (i = 0; i < 14; ++i) {
260 pair = code & 0x3;
261 code >>= 2;
262
263 rc5 <<= 1;
264 switch (pair) {
265 case 0:
266 case 2:
267 break;
268 case 1:
269 rc5 |= 1;
270 break;
271 case 3:
272 IR_dprintk(1, "ir-common: ir_rc5_decode(%x) bad code\n", org_code);
273 return 0;
274 }
275 }
276 IR_dprintk(1, "ir-common: code=%x, rc5=%x, start=%x, toggle=%x, address=%x, "
277 "instr=%x\n", rc5, org_code, RC5_START(rc5),
278 RC5_TOGGLE(rc5), RC5_ADDR(rc5), RC5_INSTR(rc5));
279 return rc5;
280}
281EXPORT_SYMBOL_GPL(ir_rc5_decode);
282
283void ir_rc5_timer_end(unsigned long data)
284{
285 struct card_ir *ir = (struct card_ir *)data;
286 struct timeval tv;
287 unsigned long current_jiffies, timeout;
288 u32 gap;
289 u32 rc5 = 0;
290
291 /* get time */
292 current_jiffies = jiffies;
293 do_gettimeofday(&tv);
294
295 /* avoid overflow with gap >1s */
296 if (tv.tv_sec - ir->base_time.tv_sec > 1) {
297 gap = 200000;
298 } else {
299 gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
300 tv.tv_usec - ir->base_time.tv_usec;
301 }
302
303 /* signal we're ready to start a new code */
304 ir->active = 0;
305
306 /* Allow some timer jitter (RC5 is ~24ms anyway so this is ok) */
307 if (gap < 28000) {
308 IR_dprintk(1, "ir-common: spurious timer_end\n");
309 return;
310 }
311
312 if (ir->last_bit < 20) {
313 /* ignore spurious codes (caused by light/other remotes) */
314 IR_dprintk(1, "ir-common: short code: %x\n", ir->code);
315 } else {
316 ir->code = (ir->code << ir->shift_by) | 1;
317 rc5 = ir_rc5_decode(ir->code);
318
319 /* two start bits? */
320 if (RC5_START(rc5) != ir->start) {
321 IR_dprintk(1, "ir-common: rc5 start bits invalid: %u\n", RC5_START(rc5));
322
323 /* right address? */
324 } else if (RC5_ADDR(rc5) == ir->addr) {
325 u32 toggle = RC5_TOGGLE(rc5);
326 u32 instr = RC5_INSTR(rc5);
327
328 /* Good code, decide if repeat/repress */
329 if (toggle != RC5_TOGGLE(ir->last_rc5) ||
330 instr != RC5_INSTR(ir->last_rc5)) {
331 IR_dprintk(1, "ir-common: instruction %x, toggle %x\n", instr,
332 toggle);
333 ir_input_nokey(ir->dev, &ir->ir);
334 ir_input_keydown(ir->dev, &ir->ir, instr);
335 }
336
337 /* Set/reset key-up timer */
338 timeout = current_jiffies +
339 msecs_to_jiffies(ir->rc5_key_timeout);
340 mod_timer(&ir->timer_keyup, timeout);
341
342 /* Save code for repeat test */
343 ir->last_rc5 = rc5;
344 }
345 }
346}
347EXPORT_SYMBOL_GPL(ir_rc5_timer_end);
348
349void ir_rc5_timer_keyup(unsigned long data)
350{
351 struct card_ir *ir = (struct card_ir *)data;
352
353 IR_dprintk(1, "ir-common: key released\n");
354 ir_input_nokey(ir->dev, &ir->ir);
355}
356EXPORT_SYMBOL_GPL(ir_rc5_timer_keyup);
diff --git a/drivers/media/IR/ir-keytable.c b/drivers/media/IR/ir-keytable.c
deleted file mode 100644
index f60107c3b091..000000000000
--- a/drivers/media/IR/ir-keytable.c
+++ /dev/null
@@ -1,710 +0,0 @@
1/* ir-keytable.c - handle IR scancode->keycode tables
2 *
3 * Copyright (C) 2009 by Mauro Carvalho Chehab <mchehab@redhat.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation version 2 of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14
15
16#include <linux/input.h>
17#include <linux/slab.h>
18#include "ir-core-priv.h"
19
20/* Sizes are in bytes, 256 bytes allows for 32 entries on x64 */
21#define IR_TAB_MIN_SIZE 256
22#define IR_TAB_MAX_SIZE 8192
23
24/* FIXME: IR_KEYPRESS_TIMEOUT should be protocol specific */
25#define IR_KEYPRESS_TIMEOUT 250
26
27/**
28 * ir_create_table() - initializes a scancode table
29 * @rc_tab: the ir_scancode_table to initialize
30 * @name: name to assign to the table
31 * @ir_type: ir type to assign to the new table
32 * @size: initial size of the table
33 * @return: zero on success or a negative error code
34 *
35 * This routine will initialize the ir_scancode_table and will allocate
36 * memory to hold at least the specified number elements.
37 */
38static int ir_create_table(struct ir_scancode_table *rc_tab,
39 const char *name, u64 ir_type, size_t size)
40{
41 rc_tab->name = name;
42 rc_tab->ir_type = ir_type;
43 rc_tab->alloc = roundup_pow_of_two(size * sizeof(struct ir_scancode));
44 rc_tab->size = rc_tab->alloc / sizeof(struct ir_scancode);
45 rc_tab->scan = kmalloc(rc_tab->alloc, GFP_KERNEL);
46 if (!rc_tab->scan)
47 return -ENOMEM;
48
49 IR_dprintk(1, "Allocated space for %u keycode entries (%u bytes)\n",
50 rc_tab->size, rc_tab->alloc);
51 return 0;
52}
53
54/**
55 * ir_free_table() - frees memory allocated by a scancode table
56 * @rc_tab: the table whose mappings need to be freed
57 *
58 * This routine will free memory alloctaed for key mappings used by given
59 * scancode table.
60 */
61static void ir_free_table(struct ir_scancode_table *rc_tab)
62{
63 rc_tab->size = 0;
64 kfree(rc_tab->scan);
65 rc_tab->scan = NULL;
66}
67
68/**
69 * ir_resize_table() - resizes a scancode table if necessary
70 * @rc_tab: the ir_scancode_table to resize
71 * @gfp_flags: gfp flags to use when allocating memory
72 * @return: zero on success or a negative error code
73 *
74 * This routine will shrink the ir_scancode_table if it has lots of
75 * unused entries and grow it if it is full.
76 */
77static int ir_resize_table(struct ir_scancode_table *rc_tab, gfp_t gfp_flags)
78{
79 unsigned int oldalloc = rc_tab->alloc;
80 unsigned int newalloc = oldalloc;
81 struct ir_scancode *oldscan = rc_tab->scan;
82 struct ir_scancode *newscan;
83
84 if (rc_tab->size == rc_tab->len) {
85 /* All entries in use -> grow keytable */
86 if (rc_tab->alloc >= IR_TAB_MAX_SIZE)
87 return -ENOMEM;
88
89 newalloc *= 2;
90 IR_dprintk(1, "Growing table to %u bytes\n", newalloc);
91 }
92
93 if ((rc_tab->len * 3 < rc_tab->size) && (oldalloc > IR_TAB_MIN_SIZE)) {
94 /* Less than 1/3 of entries in use -> shrink keytable */
95 newalloc /= 2;
96 IR_dprintk(1, "Shrinking table to %u bytes\n", newalloc);
97 }
98
99 if (newalloc == oldalloc)
100 return 0;
101
102 newscan = kmalloc(newalloc, gfp_flags);
103 if (!newscan) {
104 IR_dprintk(1, "Failed to kmalloc %u bytes\n", newalloc);
105 return -ENOMEM;
106 }
107
108 memcpy(newscan, rc_tab->scan, rc_tab->len * sizeof(struct ir_scancode));
109 rc_tab->scan = newscan;
110 rc_tab->alloc = newalloc;
111 rc_tab->size = rc_tab->alloc / sizeof(struct ir_scancode);
112 kfree(oldscan);
113 return 0;
114}
115
116/**
117 * ir_update_mapping() - set a keycode in the scancode->keycode table
118 * @dev: the struct input_dev device descriptor
119 * @rc_tab: scancode table to be adjusted
120 * @index: index of the mapping that needs to be updated
121 * @keycode: the desired keycode
122 * @return: previous keycode assigned to the mapping
123 *
124 * This routine is used to update scancode->keycopde mapping at given
125 * position.
126 */
127static unsigned int ir_update_mapping(struct input_dev *dev,
128 struct ir_scancode_table *rc_tab,
129 unsigned int index,
130 unsigned int new_keycode)
131{
132 int old_keycode = rc_tab->scan[index].keycode;
133 int i;
134
135 /* Did the user wish to remove the mapping? */
136 if (new_keycode == KEY_RESERVED || new_keycode == KEY_UNKNOWN) {
137 IR_dprintk(1, "#%d: Deleting scan 0x%04x\n",
138 index, rc_tab->scan[index].scancode);
139 rc_tab->len--;
140 memmove(&rc_tab->scan[index], &rc_tab->scan[index+ 1],
141 (rc_tab->len - index) * sizeof(struct ir_scancode));
142 } else {
143 IR_dprintk(1, "#%d: %s scan 0x%04x with key 0x%04x\n",
144 index,
145 old_keycode == KEY_RESERVED ? "New" : "Replacing",
146 rc_tab->scan[index].scancode, new_keycode);
147 rc_tab->scan[index].keycode = new_keycode;
148 __set_bit(new_keycode, dev->keybit);
149 }
150
151 if (old_keycode != KEY_RESERVED) {
152 /* A previous mapping was updated... */
153 __clear_bit(old_keycode, dev->keybit);
154 /* ... but another scancode might use the same keycode */
155 for (i = 0; i < rc_tab->len; i++) {
156 if (rc_tab->scan[i].keycode == old_keycode) {
157 __set_bit(old_keycode, dev->keybit);
158 break;
159 }
160 }
161
162 /* Possibly shrink the keytable, failure is not a problem */
163 ir_resize_table(rc_tab, GFP_ATOMIC);
164 }
165
166 return old_keycode;
167}
168
169/**
170 * ir_locate_scancode() - set a keycode in the scancode->keycode table
171 * @ir_dev: the struct ir_input_dev device descriptor
172 * @rc_tab: scancode table to be searched
173 * @scancode: the desired scancode
174 * @resize: controls whether we allowed to resize the table to
175 * accomodate not yet present scancodes
176 * @return: index of the mapping containing scancode in question
177 * or -1U in case of failure.
178 *
179 * This routine is used to locate given scancode in ir_scancode_table.
180 * If scancode is not yet present the routine will allocate a new slot
181 * for it.
182 */
183static unsigned int ir_establish_scancode(struct ir_input_dev *ir_dev,
184 struct ir_scancode_table *rc_tab,
185 unsigned int scancode,
186 bool resize)
187{
188 unsigned int i;
189
190 /*
191 * Unfortunately, some hardware-based IR decoders don't provide
192 * all bits for the complete IR code. In general, they provide only
193 * the command part of the IR code. Yet, as it is possible to replace
194 * the provided IR with another one, it is needed to allow loading
195 * IR tables from other remotes. So,
196 */
197 if (ir_dev->props && ir_dev->props->scanmask)
198 scancode &= ir_dev->props->scanmask;
199
200 /* First check if we already have a mapping for this ir command */
201 for (i = 0; i < rc_tab->len; i++) {
202 if (rc_tab->scan[i].scancode == scancode)
203 return i;
204
205 /* Keytable is sorted from lowest to highest scancode */
206 if (rc_tab->scan[i].scancode >= scancode)
207 break;
208 }
209
210 /* No previous mapping found, we might need to grow the table */
211 if (rc_tab->size == rc_tab->len) {
212 if (!resize || ir_resize_table(rc_tab, GFP_ATOMIC))
213 return -1U;
214 }
215
216 /* i is the proper index to insert our new keycode */
217 if (i < rc_tab->len)
218 memmove(&rc_tab->scan[i + 1], &rc_tab->scan[i],
219 (rc_tab->len - i) * sizeof(struct ir_scancode));
220 rc_tab->scan[i].scancode = scancode;
221 rc_tab->scan[i].keycode = KEY_RESERVED;
222 rc_tab->len++;
223
224 return i;
225}
226
227/**
228 * ir_setkeycode() - set a keycode in the scancode->keycode table
229 * @dev: the struct input_dev device descriptor
230 * @scancode: the desired scancode
231 * @keycode: result
232 * @return: -EINVAL if the keycode could not be inserted, otherwise zero.
233 *
234 * This routine is used to handle evdev EVIOCSKEY ioctl.
235 */
236static int ir_setkeycode(struct input_dev *dev,
237 const struct input_keymap_entry *ke,
238 unsigned int *old_keycode)
239{
240 struct ir_input_dev *ir_dev = input_get_drvdata(dev);
241 struct ir_scancode_table *rc_tab = &ir_dev->rc_tab;
242 unsigned int index;
243 unsigned int scancode;
244 int retval;
245 unsigned long flags;
246
247 spin_lock_irqsave(&rc_tab->lock, flags);
248
249 if (ke->flags & INPUT_KEYMAP_BY_INDEX) {
250 index = ke->index;
251 if (index >= rc_tab->len) {
252 retval = -EINVAL;
253 goto out;
254 }
255 } else {
256 retval = input_scancode_to_scalar(ke, &scancode);
257 if (retval)
258 goto out;
259
260 index = ir_establish_scancode(ir_dev, rc_tab, scancode, true);
261 if (index >= rc_tab->len) {
262 retval = -ENOMEM;
263 goto out;
264 }
265 }
266
267 *old_keycode = ir_update_mapping(dev, rc_tab, index, ke->keycode);
268
269out:
270 spin_unlock_irqrestore(&rc_tab->lock, flags);
271 return retval;
272}
273
274/**
275 * ir_setkeytable() - sets several entries in the scancode->keycode table
276 * @dev: the struct input_dev device descriptor
277 * @to: the struct ir_scancode_table to copy entries to
278 * @from: the struct ir_scancode_table to copy entries from
279 * @return: -ENOMEM if all keycodes could not be inserted, otherwise zero.
280 *
281 * This routine is used to handle table initialization.
282 */
283static int ir_setkeytable(struct ir_input_dev *ir_dev,
284 const struct ir_scancode_table *from)
285{
286 struct ir_scancode_table *rc_tab = &ir_dev->rc_tab;
287 unsigned int i, index;
288 int rc;
289
290 rc = ir_create_table(&ir_dev->rc_tab,
291 from->name, from->ir_type, from->size);
292 if (rc)
293 return rc;
294
295 IR_dprintk(1, "Allocated space for %u keycode entries (%u bytes)\n",
296 rc_tab->size, rc_tab->alloc);
297
298 for (i = 0; i < from->size; i++) {
299 index = ir_establish_scancode(ir_dev, rc_tab,
300 from->scan[i].scancode, false);
301 if (index >= rc_tab->len) {
302 rc = -ENOMEM;
303 break;
304 }
305
306 ir_update_mapping(ir_dev->input_dev, rc_tab, index,
307 from->scan[i].keycode);
308 }
309
310 if (rc)
311 ir_free_table(rc_tab);
312
313 return rc;
314}
315
316/**
317 * ir_lookup_by_scancode() - locate mapping by scancode
318 * @rc_tab: the &struct ir_scancode_table to search
319 * @scancode: scancode to look for in the table
320 * @return: index in the table, -1U if not found
321 *
322 * This routine performs binary search in RC keykeymap table for
323 * given scancode.
324 */
325static unsigned int ir_lookup_by_scancode(const struct ir_scancode_table *rc_tab,
326 unsigned int scancode)
327{
328 int start = 0;
329 int end = rc_tab->len - 1;
330 int mid;
331
332 while (start <= end) {
333 mid = (start + end) / 2;
334 if (rc_tab->scan[mid].scancode < scancode)
335 start = mid + 1;
336 else if (rc_tab->scan[mid].scancode > scancode)
337 end = mid - 1;
338 else
339 return mid;
340 }
341
342 return -1U;
343}
344
345/**
346 * ir_getkeycode() - get a keycode from the scancode->keycode table
347 * @dev: the struct input_dev device descriptor
348 * @scancode: the desired scancode
349 * @keycode: used to return the keycode, if found, or KEY_RESERVED
350 * @return: always returns zero.
351 *
352 * This routine is used to handle evdev EVIOCGKEY ioctl.
353 */
354static int ir_getkeycode(struct input_dev *dev,
355 struct input_keymap_entry *ke)
356{
357 struct ir_input_dev *ir_dev = input_get_drvdata(dev);
358 struct ir_scancode_table *rc_tab = &ir_dev->rc_tab;
359 struct ir_scancode *entry;
360 unsigned long flags;
361 unsigned int index;
362 unsigned int scancode;
363 int retval;
364
365 spin_lock_irqsave(&rc_tab->lock, flags);
366
367 if (ke->flags & INPUT_KEYMAP_BY_INDEX) {
368 index = ke->index;
369 } else {
370 retval = input_scancode_to_scalar(ke, &scancode);
371 if (retval)
372 goto out;
373
374 index = ir_lookup_by_scancode(rc_tab, scancode);
375 }
376
377 if (index >= rc_tab->len) {
378 if (!(ke->flags & INPUT_KEYMAP_BY_INDEX))
379 IR_dprintk(1, "unknown key for scancode 0x%04x\n",
380 scancode);
381 retval = -EINVAL;
382 goto out;
383 }
384
385 entry = &rc_tab->scan[index];
386
387 ke->index = index;
388 ke->keycode = entry->keycode;
389 ke->len = sizeof(entry->scancode);
390 memcpy(ke->scancode, &entry->scancode, sizeof(entry->scancode));
391
392 retval = 0;
393
394out:
395 spin_unlock_irqrestore(&rc_tab->lock, flags);
396 return retval;
397}
398
399/**
400 * ir_g_keycode_from_table() - gets the keycode that corresponds to a scancode
401 * @input_dev: the struct input_dev descriptor of the device
402 * @scancode: the scancode that we're seeking
403 *
404 * This routine is used by the input routines when a key is pressed at the
405 * IR. The scancode is received and needs to be converted into a keycode.
406 * If the key is not found, it returns KEY_RESERVED. Otherwise, returns the
407 * corresponding keycode from the table.
408 */
409u32 ir_g_keycode_from_table(struct input_dev *dev, u32 scancode)
410{
411 struct ir_input_dev *ir_dev = input_get_drvdata(dev);
412 struct ir_scancode_table *rc_tab = &ir_dev->rc_tab;
413 unsigned int keycode;
414 unsigned int index;
415 unsigned long flags;
416
417 spin_lock_irqsave(&rc_tab->lock, flags);
418
419 index = ir_lookup_by_scancode(rc_tab, scancode);
420 keycode = index < rc_tab->len ?
421 rc_tab->scan[index].keycode : KEY_RESERVED;
422
423 spin_unlock_irqrestore(&rc_tab->lock, flags);
424
425 if (keycode != KEY_RESERVED)
426 IR_dprintk(1, "%s: scancode 0x%04x keycode 0x%02x\n",
427 dev->name, scancode, keycode);
428
429 return keycode;
430}
431EXPORT_SYMBOL_GPL(ir_g_keycode_from_table);
432
433/**
434 * ir_keyup() - generates input event to cleanup a key press
435 * @ir: the struct ir_input_dev descriptor of the device
436 *
437 * This routine is used to signal that a key has been released on the
438 * remote control. It reports a keyup input event via input_report_key().
439 */
440void ir_keyup(struct ir_input_dev *ir)
441{
442 if (!ir->keypressed)
443 return;
444
445 IR_dprintk(1, "keyup key 0x%04x\n", ir->last_keycode);
446 input_report_key(ir->input_dev, ir->last_keycode, 0);
447 input_sync(ir->input_dev);
448 ir->keypressed = false;
449}
450EXPORT_SYMBOL_GPL(ir_keyup);
451
452/**
453 * ir_timer_keyup() - generates a keyup event after a timeout
454 * @cookie: a pointer to struct ir_input_dev passed to setup_timer()
455 *
456 * This routine will generate a keyup event some time after a keydown event
457 * is generated when no further activity has been detected.
458 */
459static void ir_timer_keyup(unsigned long cookie)
460{
461 struct ir_input_dev *ir = (struct ir_input_dev *)cookie;
462 unsigned long flags;
463
464 /*
465 * ir->keyup_jiffies is used to prevent a race condition if a
466 * hardware interrupt occurs at this point and the keyup timer
467 * event is moved further into the future as a result.
468 *
469 * The timer will then be reactivated and this function called
470 * again in the future. We need to exit gracefully in that case
471 * to allow the input subsystem to do its auto-repeat magic or
472 * a keyup event might follow immediately after the keydown.
473 */
474 spin_lock_irqsave(&ir->keylock, flags);
475 if (time_is_before_eq_jiffies(ir->keyup_jiffies))
476 ir_keyup(ir);
477 spin_unlock_irqrestore(&ir->keylock, flags);
478}
479
480/**
481 * ir_repeat() - notifies the IR core that a key is still pressed
482 * @dev: the struct input_dev descriptor of the device
483 *
484 * This routine is used by IR decoders when a repeat message which does
485 * not include the necessary bits to reproduce the scancode has been
486 * received.
487 */
488void ir_repeat(struct input_dev *dev)
489{
490 unsigned long flags;
491 struct ir_input_dev *ir = input_get_drvdata(dev);
492
493 spin_lock_irqsave(&ir->keylock, flags);
494
495 input_event(dev, EV_MSC, MSC_SCAN, ir->last_scancode);
496
497 if (!ir->keypressed)
498 goto out;
499
500 ir->keyup_jiffies = jiffies + msecs_to_jiffies(IR_KEYPRESS_TIMEOUT);
501 mod_timer(&ir->timer_keyup, ir->keyup_jiffies);
502
503out:
504 spin_unlock_irqrestore(&ir->keylock, flags);
505}
506EXPORT_SYMBOL_GPL(ir_repeat);
507
508/**
509 * ir_keydown() - generates input event for a key press
510 * @dev: the struct input_dev descriptor of the device
511 * @scancode: the scancode that we're seeking
512 * @toggle: the toggle value (protocol dependent, if the protocol doesn't
513 * support toggle values, this should be set to zero)
514 *
515 * This routine is used by the input routines when a key is pressed at the
516 * IR. It gets the keycode for a scancode and reports an input event via
517 * input_report_key().
518 */
519void ir_keydown(struct input_dev *dev, int scancode, u8 toggle)
520{
521 unsigned long flags;
522 struct ir_input_dev *ir = input_get_drvdata(dev);
523
524 u32 keycode = ir_g_keycode_from_table(dev, scancode);
525
526 spin_lock_irqsave(&ir->keylock, flags);
527
528 input_event(dev, EV_MSC, MSC_SCAN, scancode);
529
530 /* Repeat event? */
531 if (ir->keypressed &&
532 ir->last_scancode == scancode &&
533 ir->last_toggle == toggle)
534 goto set_timer;
535
536 /* Release old keypress */
537 ir_keyup(ir);
538
539 ir->last_scancode = scancode;
540 ir->last_toggle = toggle;
541 ir->last_keycode = keycode;
542
543
544 if (keycode == KEY_RESERVED)
545 goto out;
546
547
548 /* Register a keypress */
549 ir->keypressed = true;
550 IR_dprintk(1, "%s: key down event, key 0x%04x, scancode 0x%04x\n",
551 dev->name, keycode, scancode);
552 input_report_key(dev, ir->last_keycode, 1);
553 input_sync(dev);
554
555set_timer:
556 ir->keyup_jiffies = jiffies + msecs_to_jiffies(IR_KEYPRESS_TIMEOUT);
557 mod_timer(&ir->timer_keyup, ir->keyup_jiffies);
558out:
559 spin_unlock_irqrestore(&ir->keylock, flags);
560}
561EXPORT_SYMBOL_GPL(ir_keydown);
562
563static int ir_open(struct input_dev *input_dev)
564{
565 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
566
567 return ir_dev->props->open(ir_dev->props->priv);
568}
569
570static void ir_close(struct input_dev *input_dev)
571{
572 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
573
574 ir_dev->props->close(ir_dev->props->priv);
575}
576
577/**
578 * __ir_input_register() - sets the IR keycode table and add the handlers
579 * for keymap table get/set
580 * @input_dev: the struct input_dev descriptor of the device
581 * @rc_tab: the struct ir_scancode_table table of scancode/keymap
582 *
583 * This routine is used to initialize the input infrastructure
584 * to work with an IR.
585 * It will register the input/evdev interface for the device and
586 * register the syfs code for IR class
587 */
588int __ir_input_register(struct input_dev *input_dev,
589 const struct ir_scancode_table *rc_tab,
590 struct ir_dev_props *props,
591 const char *driver_name)
592{
593 struct ir_input_dev *ir_dev;
594 int rc;
595
596 if (rc_tab->scan == NULL || !rc_tab->size)
597 return -EINVAL;
598
599 ir_dev = kzalloc(sizeof(*ir_dev), GFP_KERNEL);
600 if (!ir_dev)
601 return -ENOMEM;
602
603 ir_dev->driver_name = kasprintf(GFP_KERNEL, "%s", driver_name);
604 if (!ir_dev->driver_name) {
605 rc = -ENOMEM;
606 goto out_dev;
607 }
608
609 input_dev->getkeycode_new = ir_getkeycode;
610 input_dev->setkeycode_new = ir_setkeycode;
611 input_set_drvdata(input_dev, ir_dev);
612 ir_dev->input_dev = input_dev;
613
614 spin_lock_init(&ir_dev->rc_tab.lock);
615 spin_lock_init(&ir_dev->keylock);
616 setup_timer(&ir_dev->timer_keyup, ir_timer_keyup, (unsigned long)ir_dev);
617
618 if (props) {
619 ir_dev->props = props;
620 if (props->open)
621 input_dev->open = ir_open;
622 if (props->close)
623 input_dev->close = ir_close;
624 }
625
626 set_bit(EV_KEY, input_dev->evbit);
627 set_bit(EV_REP, input_dev->evbit);
628 set_bit(EV_MSC, input_dev->evbit);
629 set_bit(MSC_SCAN, input_dev->mscbit);
630
631 rc = ir_setkeytable(ir_dev, rc_tab);
632 if (rc)
633 goto out_name;
634
635 rc = ir_register_class(input_dev);
636 if (rc < 0)
637 goto out_table;
638
639 if (ir_dev->props)
640 if (ir_dev->props->driver_type == RC_DRIVER_IR_RAW) {
641 rc = ir_raw_event_register(input_dev);
642 if (rc < 0)
643 goto out_event;
644 }
645
646 rc = ir_register_input(input_dev);
647 if (rc < 0)
648 goto out_event;
649
650 IR_dprintk(1, "Registered input device on %s for %s remote%s.\n",
651 driver_name, rc_tab->name,
652 (ir_dev->props && ir_dev->props->driver_type == RC_DRIVER_IR_RAW) ?
653 " in raw mode" : "");
654
655 /*
656 * Default delay of 250ms is too short for some protocols, expecially
657 * since the timeout is currently set to 250ms. Increase it to 500ms,
658 * to avoid wrong repetition of the keycodes.
659 */
660 input_dev->rep[REP_DELAY] = 500;
661
662 return 0;
663
664out_event:
665 ir_unregister_class(input_dev);
666out_table:
667 ir_free_table(&ir_dev->rc_tab);
668out_name:
669 kfree(ir_dev->driver_name);
670out_dev:
671 kfree(ir_dev);
672 return rc;
673}
674EXPORT_SYMBOL_GPL(__ir_input_register);
675
676/**
677 * ir_input_unregister() - unregisters IR and frees resources
678 * @input_dev: the struct input_dev descriptor of the device
679
680 * This routine is used to free memory and de-register interfaces.
681 */
682void ir_input_unregister(struct input_dev *input_dev)
683{
684 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
685
686 if (!ir_dev)
687 return;
688
689 IR_dprintk(1, "Freed keycode table\n");
690
691 del_timer_sync(&ir_dev->timer_keyup);
692 if (ir_dev->props)
693 if (ir_dev->props->driver_type == RC_DRIVER_IR_RAW)
694 ir_raw_event_unregister(input_dev);
695
696 ir_free_table(&ir_dev->rc_tab);
697
698 ir_unregister_class(input_dev);
699
700 kfree(ir_dev->driver_name);
701 kfree(ir_dev);
702}
703EXPORT_SYMBOL_GPL(ir_input_unregister);
704
705int ir_core_debug; /* ir_debug level (0,1,2) */
706EXPORT_SYMBOL_GPL(ir_core_debug);
707module_param_named(debug, ir_core_debug, int, 0644);
708
709MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
710MODULE_LICENSE("GPL");
diff --git a/drivers/media/IR/ir-sysfs.c b/drivers/media/IR/ir-sysfs.c
deleted file mode 100644
index 38423a8da871..000000000000
--- a/drivers/media/IR/ir-sysfs.c
+++ /dev/null
@@ -1,362 +0,0 @@
1/* ir-sysfs.c - sysfs interface for RC devices (/sys/class/rc)
2 *
3 * Copyright (C) 2009-2010 by Mauro Carvalho Chehab <mchehab@redhat.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation version 2 of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14
15#include <linux/slab.h>
16#include <linux/input.h>
17#include <linux/device.h>
18#include "ir-core-priv.h"
19
20#define IRRCV_NUM_DEVICES 256
21
22/* bit array to represent IR sysfs device number */
23static unsigned long ir_core_dev_number;
24
25/* class for /sys/class/rc */
26static char *ir_devnode(struct device *dev, mode_t *mode)
27{
28 return kasprintf(GFP_KERNEL, "rc/%s", dev_name(dev));
29}
30
31static struct class ir_input_class = {
32 .name = "rc",
33 .devnode = ir_devnode,
34};
35
36static struct {
37 u64 type;
38 char *name;
39} proto_names[] = {
40 { IR_TYPE_UNKNOWN, "unknown" },
41 { IR_TYPE_RC5, "rc-5" },
42 { IR_TYPE_NEC, "nec" },
43 { IR_TYPE_RC6, "rc-6" },
44 { IR_TYPE_JVC, "jvc" },
45 { IR_TYPE_SONY, "sony" },
46 { IR_TYPE_RC5_SZ, "rc-5-sz" },
47 { IR_TYPE_LIRC, "lirc" },
48};
49
50#define PROTO_NONE "none"
51
52/**
53 * show_protocols() - shows the current IR protocol(s)
54 * @d: the device descriptor
55 * @mattr: the device attribute struct (unused)
56 * @buf: a pointer to the output buffer
57 *
58 * This routine is a callback routine for input read the IR protocol type(s).
59 * it is trigged by reading /sys/class/rc/rc?/protocols.
60 * It returns the protocol names of supported protocols.
61 * Enabled protocols are printed in brackets.
62 */
63static ssize_t show_protocols(struct device *d,
64 struct device_attribute *mattr, char *buf)
65{
66 struct ir_input_dev *ir_dev = dev_get_drvdata(d);
67 u64 allowed, enabled;
68 char *tmp = buf;
69 int i;
70
71 /* Device is being removed */
72 if (!ir_dev)
73 return -EINVAL;
74
75 if (ir_dev->props && ir_dev->props->driver_type == RC_DRIVER_SCANCODE) {
76 enabled = ir_dev->rc_tab.ir_type;
77 allowed = ir_dev->props->allowed_protos;
78 } else if (ir_dev->raw) {
79 enabled = ir_dev->raw->enabled_protocols;
80 allowed = ir_raw_get_allowed_protocols();
81 } else
82 return sprintf(tmp, "[builtin]\n");
83
84 IR_dprintk(1, "allowed - 0x%llx, enabled - 0x%llx\n",
85 (long long)allowed,
86 (long long)enabled);
87
88 for (i = 0; i < ARRAY_SIZE(proto_names); i++) {
89 if (allowed & enabled & proto_names[i].type)
90 tmp += sprintf(tmp, "[%s] ", proto_names[i].name);
91 else if (allowed & proto_names[i].type)
92 tmp += sprintf(tmp, "%s ", proto_names[i].name);
93 }
94
95 if (tmp != buf)
96 tmp--;
97 *tmp = '\n';
98 return tmp + 1 - buf;
99}
100
101/**
102 * store_protocols() - changes the current IR protocol(s)
103 * @d: the device descriptor
104 * @mattr: the device attribute struct (unused)
105 * @buf: a pointer to the input buffer
106 * @len: length of the input buffer
107 *
108 * This routine is a callback routine for changing the IR protocol type.
109 * It is trigged by writing to /sys/class/rc/rc?/protocols.
110 * Writing "+proto" will add a protocol to the list of enabled protocols.
111 * Writing "-proto" will remove a protocol from the list of enabled protocols.
112 * Writing "proto" will enable only "proto".
113 * Writing "none" will disable all protocols.
114 * Returns -EINVAL if an invalid protocol combination or unknown protocol name
115 * is used, otherwise @len.
116 */
117static ssize_t store_protocols(struct device *d,
118 struct device_attribute *mattr,
119 const char *data,
120 size_t len)
121{
122 struct ir_input_dev *ir_dev = dev_get_drvdata(d);
123 bool enable, disable;
124 const char *tmp;
125 u64 type;
126 u64 mask;
127 int rc, i, count = 0;
128 unsigned long flags;
129
130 /* Device is being removed */
131 if (!ir_dev)
132 return -EINVAL;
133
134 if (ir_dev->props && ir_dev->props->driver_type == RC_DRIVER_SCANCODE)
135 type = ir_dev->rc_tab.ir_type;
136 else if (ir_dev->raw)
137 type = ir_dev->raw->enabled_protocols;
138 else {
139 IR_dprintk(1, "Protocol switching not supported\n");
140 return -EINVAL;
141 }
142
143 while ((tmp = strsep((char **) &data, " \n")) != NULL) {
144 if (!*tmp)
145 break;
146
147 if (*tmp == '+') {
148 enable = true;
149 disable = false;
150 tmp++;
151 } else if (*tmp == '-') {
152 enable = false;
153 disable = true;
154 tmp++;
155 } else {
156 enable = false;
157 disable = false;
158 }
159
160 if (!enable && !disable && !strncasecmp(tmp, PROTO_NONE, sizeof(PROTO_NONE))) {
161 tmp += sizeof(PROTO_NONE);
162 mask = 0;
163 count++;
164 } else {
165 for (i = 0; i < ARRAY_SIZE(proto_names); i++) {
166 if (!strncasecmp(tmp, proto_names[i].name, strlen(proto_names[i].name))) {
167 tmp += strlen(proto_names[i].name);
168 mask = proto_names[i].type;
169 break;
170 }
171 }
172 if (i == ARRAY_SIZE(proto_names)) {
173 IR_dprintk(1, "Unknown protocol: '%s'\n", tmp);
174 return -EINVAL;
175 }
176 count++;
177 }
178
179 if (enable)
180 type |= mask;
181 else if (disable)
182 type &= ~mask;
183 else
184 type = mask;
185 }
186
187 if (!count) {
188 IR_dprintk(1, "Protocol not specified\n");
189 return -EINVAL;
190 }
191
192 if (ir_dev->props && ir_dev->props->change_protocol) {
193 rc = ir_dev->props->change_protocol(ir_dev->props->priv,
194 type);
195 if (rc < 0) {
196 IR_dprintk(1, "Error setting protocols to 0x%llx\n",
197 (long long)type);
198 return -EINVAL;
199 }
200 }
201
202 if (ir_dev->props && ir_dev->props->driver_type == RC_DRIVER_SCANCODE) {
203 spin_lock_irqsave(&ir_dev->rc_tab.lock, flags);
204 ir_dev->rc_tab.ir_type = type;
205 spin_unlock_irqrestore(&ir_dev->rc_tab.lock, flags);
206 } else {
207 ir_dev->raw->enabled_protocols = type;
208 }
209
210 IR_dprintk(1, "Current protocol(s): 0x%llx\n",
211 (long long)type);
212
213 return len;
214}
215
216#define ADD_HOTPLUG_VAR(fmt, val...) \
217 do { \
218 int err = add_uevent_var(env, fmt, val); \
219 if (err) \
220 return err; \
221 } while (0)
222
223static int rc_dev_uevent(struct device *device, struct kobj_uevent_env *env)
224{
225 struct ir_input_dev *ir_dev = dev_get_drvdata(device);
226
227 if (ir_dev->rc_tab.name)
228 ADD_HOTPLUG_VAR("NAME=%s", ir_dev->rc_tab.name);
229 if (ir_dev->driver_name)
230 ADD_HOTPLUG_VAR("DRV_NAME=%s", ir_dev->driver_name);
231
232 return 0;
233}
234
235/*
236 * Static device attribute struct with the sysfs attributes for IR's
237 */
238static DEVICE_ATTR(protocols, S_IRUGO | S_IWUSR,
239 show_protocols, store_protocols);
240
241static struct attribute *rc_dev_attrs[] = {
242 &dev_attr_protocols.attr,
243 NULL,
244};
245
246static struct attribute_group rc_dev_attr_grp = {
247 .attrs = rc_dev_attrs,
248};
249
250static const struct attribute_group *rc_dev_attr_groups[] = {
251 &rc_dev_attr_grp,
252 NULL
253};
254
255static struct device_type rc_dev_type = {
256 .groups = rc_dev_attr_groups,
257 .uevent = rc_dev_uevent,
258};
259
260/**
261 * ir_register_class() - creates the sysfs for /sys/class/rc/rc?
262 * @input_dev: the struct input_dev descriptor of the device
263 *
264 * This routine is used to register the syfs code for IR class
265 */
266int ir_register_class(struct input_dev *input_dev)
267{
268 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
269 int devno = find_first_zero_bit(&ir_core_dev_number,
270 IRRCV_NUM_DEVICES);
271
272 if (unlikely(devno < 0))
273 return devno;
274
275 ir_dev->dev.type = &rc_dev_type;
276 ir_dev->devno = devno;
277
278 ir_dev->dev.class = &ir_input_class;
279 ir_dev->dev.parent = input_dev->dev.parent;
280 input_dev->dev.parent = &ir_dev->dev;
281 dev_set_name(&ir_dev->dev, "rc%d", devno);
282 dev_set_drvdata(&ir_dev->dev, ir_dev);
283 return device_register(&ir_dev->dev);
284};
285
286/**
287 * ir_register_input - registers ir input device with input subsystem
288 * @input_dev: the struct input_dev descriptor of the device
289 */
290
291int ir_register_input(struct input_dev *input_dev)
292{
293 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
294 int rc;
295 const char *path;
296
297
298 rc = input_register_device(input_dev);
299 if (rc < 0) {
300 device_del(&ir_dev->dev);
301 return rc;
302 }
303
304 __module_get(THIS_MODULE);
305
306 path = kobject_get_path(&ir_dev->dev.kobj, GFP_KERNEL);
307 printk(KERN_INFO "%s: %s as %s\n",
308 dev_name(&ir_dev->dev),
309 input_dev->name ? input_dev->name : "Unspecified device",
310 path ? path : "N/A");
311 kfree(path);
312
313 set_bit(ir_dev->devno, &ir_core_dev_number);
314 return 0;
315}
316
317/**
318 * ir_unregister_class() - removes the sysfs for sysfs for
319 * /sys/class/rc/rc?
320 * @input_dev: the struct input_dev descriptor of the device
321 *
322 * This routine is used to unregister the syfs code for IR class
323 */
324void ir_unregister_class(struct input_dev *input_dev)
325{
326 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
327
328 input_set_drvdata(input_dev, NULL);
329 clear_bit(ir_dev->devno, &ir_core_dev_number);
330 input_unregister_device(input_dev);
331 device_del(&ir_dev->dev);
332
333 module_put(THIS_MODULE);
334}
335
336/*
337 * Init/exit code for the module. Basically, creates/removes /sys/class/rc
338 */
339
340static int __init ir_core_init(void)
341{
342 int rc = class_register(&ir_input_class);
343 if (rc) {
344 printk(KERN_ERR "ir_core: unable to register rc class\n");
345 return rc;
346 }
347
348 /* Initialize/load the decoders/keymap code that will be used */
349 ir_raw_init();
350 ir_rcmap_init();
351
352 return 0;
353}
354
355static void __exit ir_core_exit(void)
356{
357 class_unregister(&ir_input_class);
358 ir_rcmap_cleanup();
359}
360
361module_init(ir_core_init);
362module_exit(ir_core_exit);
diff --git a/drivers/media/IR/keymaps/rc-tbs-nec.c b/drivers/media/IR/keymaps/rc-tbs-nec.c
deleted file mode 100644
index 3309631e6f80..000000000000
--- a/drivers/media/IR/keymaps/rc-tbs-nec.c
+++ /dev/null
@@ -1,73 +0,0 @@
1/* tbs-nec.h - Keytable for tbs_nec Remote Controller
2 *
3 * keymap imported from ir-keymaps.c
4 *
5 * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
12
13#include <media/rc-map.h>
14
15static struct ir_scancode tbs_nec[] = {
16 { 0x04, KEY_POWER2}, /*power*/
17 { 0x14, KEY_MUTE}, /*mute*/
18 { 0x07, KEY_1},
19 { 0x06, KEY_2},
20 { 0x05, KEY_3},
21 { 0x0b, KEY_4},
22 { 0x0a, KEY_5},
23 { 0x09, KEY_6},
24 { 0x0f, KEY_7},
25 { 0x0e, KEY_8},
26 { 0x0d, KEY_9},
27 { 0x12, KEY_0},
28 { 0x16, KEY_CHANNELUP}, /*ch+*/
29 { 0x11, KEY_CHANNELDOWN},/*ch-*/
30 { 0x13, KEY_VOLUMEUP}, /*vol+*/
31 { 0x0c, KEY_VOLUMEDOWN},/*vol-*/
32 { 0x03, KEY_RECORD}, /*rec*/
33 { 0x18, KEY_PAUSE}, /*pause*/
34 { 0x19, KEY_OK}, /*ok*/
35 { 0x1a, KEY_CAMERA}, /* snapshot */
36 { 0x01, KEY_UP},
37 { 0x10, KEY_LEFT},
38 { 0x02, KEY_RIGHT},
39 { 0x08, KEY_DOWN},
40 { 0x15, KEY_FAVORITES},
41 { 0x17, KEY_SUBTITLE},
42 { 0x1d, KEY_ZOOM},
43 { 0x1f, KEY_EXIT},
44 { 0x1e, KEY_MENU},
45 { 0x1c, KEY_EPG},
46 { 0x00, KEY_PREVIOUS},
47 { 0x1b, KEY_MODE},
48};
49
50static struct rc_keymap tbs_nec_map = {
51 .map = {
52 .scan = tbs_nec,
53 .size = ARRAY_SIZE(tbs_nec),
54 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */
55 .name = RC_MAP_TBS_NEC,
56 }
57};
58
59static int __init init_rc_map_tbs_nec(void)
60{
61 return ir_register_map(&tbs_nec_map);
62}
63
64static void __exit exit_rc_map_tbs_nec(void)
65{
66 ir_unregister_map(&tbs_nec_map);
67}
68
69module_init(init_rc_map_tbs_nec)
70module_exit(exit_rc_map_tbs_nec)
71
72MODULE_LICENSE("GPL");
73MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-tt-1500.c b/drivers/media/IR/keymaps/rc-tt-1500.c
deleted file mode 100644
index bc88de011d5d..000000000000
--- a/drivers/media/IR/keymaps/rc-tt-1500.c
+++ /dev/null
@@ -1,82 +0,0 @@
1/* tt-1500.h - Keytable for tt_1500 Remote Controller
2 *
3 * keymap imported from ir-keymaps.c
4 *
5 * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
12
13#include <media/rc-map.h>
14
15/* for the Technotrend 1500 bundled remotes (grey and black): */
16
17static struct ir_scancode tt_1500[] = {
18 { 0x01, KEY_POWER },
19 { 0x02, KEY_SHUFFLE }, /* ? double-arrow key */
20 { 0x03, KEY_1 },
21 { 0x04, KEY_2 },
22 { 0x05, KEY_3 },
23 { 0x06, KEY_4 },
24 { 0x07, KEY_5 },
25 { 0x08, KEY_6 },
26 { 0x09, KEY_7 },
27 { 0x0a, KEY_8 },
28 { 0x0b, KEY_9 },
29 { 0x0c, KEY_0 },
30 { 0x0d, KEY_UP },
31 { 0x0e, KEY_LEFT },
32 { 0x0f, KEY_OK },
33 { 0x10, KEY_RIGHT },
34 { 0x11, KEY_DOWN },
35 { 0x12, KEY_INFO },
36 { 0x13, KEY_EXIT },
37 { 0x14, KEY_RED },
38 { 0x15, KEY_GREEN },
39 { 0x16, KEY_YELLOW },
40 { 0x17, KEY_BLUE },
41 { 0x18, KEY_MUTE },
42 { 0x19, KEY_TEXT },
43 { 0x1a, KEY_MODE }, /* ? TV/Radio */
44 { 0x21, KEY_OPTION },
45 { 0x22, KEY_EPG },
46 { 0x23, KEY_CHANNELUP },
47 { 0x24, KEY_CHANNELDOWN },
48 { 0x25, KEY_VOLUMEUP },
49 { 0x26, KEY_VOLUMEDOWN },
50 { 0x27, KEY_SETUP },
51 { 0x3a, KEY_RECORD }, /* these keys are only in the black remote */
52 { 0x3b, KEY_PLAY },
53 { 0x3c, KEY_STOP },
54 { 0x3d, KEY_REWIND },
55 { 0x3e, KEY_PAUSE },
56 { 0x3f, KEY_FORWARD },
57};
58
59static struct rc_keymap tt_1500_map = {
60 .map = {
61 .scan = tt_1500,
62 .size = ARRAY_SIZE(tt_1500),
63 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */
64 .name = RC_MAP_TT_1500,
65 }
66};
67
68static int __init init_rc_map_tt_1500(void)
69{
70 return ir_register_map(&tt_1500_map);
71}
72
73static void __exit exit_rc_map_tt_1500(void)
74{
75 ir_unregister_map(&tt_1500_map);
76}
77
78module_init(init_rc_map_tt_1500)
79module_exit(exit_rc_map_tt_1500)
80
81MODULE_LICENSE("GPL");
82MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/rc-map.c b/drivers/media/IR/rc-map.c
deleted file mode 100644
index 689143f2fff0..000000000000
--- a/drivers/media/IR/rc-map.c
+++ /dev/null
@@ -1,107 +0,0 @@
1/* ir-raw-event.c - handle IR Pulse/Space event
2 *
3 * Copyright (C) 2010 by Mauro Carvalho Chehab <mchehab@redhat.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation version 2 of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14
15#include <media/ir-core.h>
16#include <linux/spinlock.h>
17#include <linux/delay.h>
18
19/* Used to handle IR raw handler extensions */
20static LIST_HEAD(rc_map_list);
21static DEFINE_SPINLOCK(rc_map_lock);
22
23static struct rc_keymap *seek_rc_map(const char *name)
24{
25 struct rc_keymap *map = NULL;
26
27 spin_lock(&rc_map_lock);
28 list_for_each_entry(map, &rc_map_list, list) {
29 if (!strcmp(name, map->map.name)) {
30 spin_unlock(&rc_map_lock);
31 return map;
32 }
33 }
34 spin_unlock(&rc_map_lock);
35
36 return NULL;
37}
38
39struct ir_scancode_table *get_rc_map(const char *name)
40{
41
42 struct rc_keymap *map;
43
44 map = seek_rc_map(name);
45#ifdef MODULE
46 if (!map) {
47 int rc = request_module(name);
48 if (rc < 0) {
49 printk(KERN_ERR "Couldn't load IR keymap %s\n", name);
50 return NULL;
51 }
52 msleep(20); /* Give some time for IR to register */
53
54 map = seek_rc_map(name);
55 }
56#endif
57 if (!map) {
58 printk(KERN_ERR "IR keymap %s not found\n", name);
59 return NULL;
60 }
61
62 printk(KERN_INFO "Registered IR keymap %s\n", map->map.name);
63
64 return &map->map;
65}
66EXPORT_SYMBOL_GPL(get_rc_map);
67
68int ir_register_map(struct rc_keymap *map)
69{
70 spin_lock(&rc_map_lock);
71 list_add_tail(&map->list, &rc_map_list);
72 spin_unlock(&rc_map_lock);
73 return 0;
74}
75EXPORT_SYMBOL_GPL(ir_register_map);
76
77void ir_unregister_map(struct rc_keymap *map)
78{
79 spin_lock(&rc_map_lock);
80 list_del(&map->list);
81 spin_unlock(&rc_map_lock);
82}
83EXPORT_SYMBOL_GPL(ir_unregister_map);
84
85
86static struct ir_scancode empty[] = {
87 { 0x2a, KEY_COFFEE },
88};
89
90static struct rc_keymap empty_map = {
91 .map = {
92 .scan = empty,
93 .size = ARRAY_SIZE(empty),
94 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */
95 .name = RC_MAP_EMPTY,
96 }
97};
98
99int ir_rcmap_init(void)
100{
101 return ir_register_map(&empty_map);
102}
103
104void ir_rcmap_cleanup(void)
105{
106 ir_unregister_map(&empty_map);
107}
diff --git a/drivers/media/Kconfig b/drivers/media/Kconfig
index a28541b2b1a2..81b3ba83cc65 100644
--- a/drivers/media/Kconfig
+++ b/drivers/media/Kconfig
@@ -40,35 +40,6 @@ config VIDEO_V4L2_COMMON
40 depends on (I2C || I2C=n) && VIDEO_DEV 40 depends on (I2C || I2C=n) && VIDEO_DEV
41 default (I2C || I2C=n) && VIDEO_DEV 41 default (I2C || I2C=n) && VIDEO_DEV
42 42
43config VIDEO_ALLOW_V4L1
44 bool "Enable Video For Linux API 1 (DEPRECATED)"
45 depends on VIDEO_DEV && VIDEO_V4L2_COMMON
46 default VIDEO_DEV && VIDEO_V4L2_COMMON
47 ---help---
48 Enables drivers based on the legacy V4L1 API.
49
50 This api were developed to be used at Kernel 2.2 and 2.4, but
51 lacks support for several video standards. There are several
52 drivers at kernel that still depends on it.
53
54 If you are unsure as to whether this is required, answer Y.
55
56config VIDEO_V4L1_COMPAT
57 bool "Enable Video For Linux API 1 compatible Layer" if !VIDEO_ALLOW_V4L1
58 depends on VIDEO_DEV
59 default y
60 ---help---
61 Enables a compatibility API used by most V4L2 devices to allow
62 its usage with legacy applications that supports only V4L1 api.
63
64 Documentation for the original API is included in the file
65 <Documentation/video4linux/API.html>.
66
67 User tools for this are available from
68 <ftp://ftp.uk.linux.org/pub/linux/video4linux/>.
69
70 If you are unsure as to whether this is required, answer Y.
71
72# 43#
73# DVB Core 44# DVB Core
74# 45#
@@ -99,7 +70,7 @@ config VIDEO_MEDIA
99comment "Multimedia drivers" 70comment "Multimedia drivers"
100 71
101source "drivers/media/common/Kconfig" 72source "drivers/media/common/Kconfig"
102source "drivers/media/IR/Kconfig" 73source "drivers/media/rc/Kconfig"
103 74
104# 75#
105# Tuner drivers for DVB and V4L 76# Tuner drivers for DVB and V4L
@@ -121,26 +92,4 @@ source "drivers/media/radio/Kconfig"
121 92
122source "drivers/media/dvb/Kconfig" 93source "drivers/media/dvb/Kconfig"
123 94
124config DAB
125 boolean "DAB adapters"
126 ---help---
127 Allow selecting support for Digital Audio Broadcasting (DAB)
128 Receiver adapters.
129
130if DAB
131config USB_DABUSB
132 tristate "DABUSB driver"
133 depends on USB
134 ---help---
135 A Digital Audio Broadcasting (DAB) Receiver for USB and Linux
136 brought to you by the DAB-Team
137 <http://wwwbode.cs.tum.edu/Par/arch/dab/>. This driver can be taken
138 as an example for URB-based bulk, control, and isochronous
139 transactions. URB's are explained in
140 <Documentation/usb/URB.txt>.
141
142 To compile this driver as a module, choose M here: the
143 module will be called dabusb.
144endif # DAB
145
146endif # MEDIA_SUPPORT 95endif # MEDIA_SUPPORT
diff --git a/drivers/media/Makefile b/drivers/media/Makefile
index 499b0810d019..b603ea645ede 100644
--- a/drivers/media/Makefile
+++ b/drivers/media/Makefile
@@ -2,7 +2,7 @@
2# Makefile for the kernel multimedia device drivers. 2# Makefile for the kernel multimedia device drivers.
3# 3#
4 4
5obj-y += common/ IR/ video/ 5obj-y += common/ rc/ video/
6 6
7obj-$(CONFIG_VIDEO_DEV) += radio/ 7obj-$(CONFIG_VIDEO_DEV) += radio/
8obj-$(CONFIG_DVB_CORE) += dvb/ 8obj-$(CONFIG_DVB_CORE) += dvb/
diff --git a/drivers/media/common/saa7146_video.c b/drivers/media/common/saa7146_video.c
index d246910129e8..0ac5c619aecf 100644
--- a/drivers/media/common/saa7146_video.c
+++ b/drivers/media/common/saa7146_video.c
@@ -1129,35 +1129,6 @@ static int vidioc_g_chip_ident(struct file *file, void *__fh,
1129 core, g_chip_ident, chip); 1129 core, g_chip_ident, chip);
1130} 1130}
1131 1131
1132#ifdef CONFIG_VIDEO_V4L1_COMPAT
1133static int vidiocgmbuf(struct file *file, void *__fh, struct video_mbuf *mbuf)
1134{
1135 struct saa7146_fh *fh = __fh;
1136 struct videobuf_queue *q = &fh->video_q;
1137 int err, i;
1138
1139 /* fixme: number of capture buffers and sizes for v4l apps */
1140 int gbuffers = 2;
1141 int gbufsize = 768 * 576 * 4;
1142
1143 DEB_D(("VIDIOCGMBUF \n"));
1144
1145 q = &fh->video_q;
1146 err = videobuf_mmap_setup(q, gbuffers, gbufsize,
1147 V4L2_MEMORY_MMAP);
1148 if (err < 0)
1149 return err;
1150
1151 gbuffers = err;
1152 memset(mbuf, 0, sizeof(*mbuf));
1153 mbuf->frames = gbuffers;
1154 mbuf->size = gbuffers * gbufsize;
1155 for (i = 0; i < gbuffers; i++)
1156 mbuf->offsets[i] = i * gbufsize;
1157 return 0;
1158}
1159#endif
1160
1161const struct v4l2_ioctl_ops saa7146_video_ioctl_ops = { 1132const struct v4l2_ioctl_ops saa7146_video_ioctl_ops = {
1162 .vidioc_querycap = vidioc_querycap, 1133 .vidioc_querycap = vidioc_querycap,
1163 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap, 1134 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
@@ -1186,9 +1157,6 @@ const struct v4l2_ioctl_ops saa7146_video_ioctl_ops = {
1186 .vidioc_streamon = vidioc_streamon, 1157 .vidioc_streamon = vidioc_streamon,
1187 .vidioc_streamoff = vidioc_streamoff, 1158 .vidioc_streamoff = vidioc_streamoff,
1188 .vidioc_g_parm = vidioc_g_parm, 1159 .vidioc_g_parm = vidioc_g_parm,
1189#ifdef CONFIG_VIDEO_V4L1_COMPAT
1190 .vidiocgmbuf = vidiocgmbuf,
1191#endif
1192}; 1160};
1193 1161
1194/*********************************************************************************/ 1162/*********************************************************************************/
diff --git a/drivers/media/common/tuners/max2165.c b/drivers/media/common/tuners/max2165.c
index 937e4b00d7ee..9883617b7862 100644
--- a/drivers/media/common/tuners/max2165.c
+++ b/drivers/media/common/tuners/max2165.c
@@ -52,13 +52,12 @@ static int max2165_write_reg(struct max2165_priv *priv, u8 reg, u8 data)
52 msg.addr = priv->config->i2c_address; 52 msg.addr = priv->config->i2c_address;
53 53
54 if (debug >= 2) 54 if (debug >= 2)
55 printk(KERN_DEBUG "%s: reg=0x%02X, data=0x%02X\n", 55 dprintk("%s: reg=0x%02X, data=0x%02X\n", __func__, reg, data);
56 __func__, reg, data);
57 56
58 ret = i2c_transfer(priv->i2c, &msg, 1); 57 ret = i2c_transfer(priv->i2c, &msg, 1);
59 58
60 if (ret != 1) 59 if (ret != 1)
61 dprintk(KERN_DEBUG "%s: error reg=0x%x, data=0x%x, ret=%i\n", 60 dprintk("%s: error reg=0x%x, data=0x%x, ret=%i\n",
62 __func__, reg, data, ret); 61 __func__, reg, data, ret);
63 62
64 return (ret != 1) ? -EIO : 0; 63 return (ret != 1) ? -EIO : 0;
@@ -78,14 +77,13 @@ static int max2165_read_reg(struct max2165_priv *priv, u8 reg, u8 *p_data)
78 77
79 ret = i2c_transfer(priv->i2c, msg, 2); 78 ret = i2c_transfer(priv->i2c, msg, 2);
80 if (ret != 2) { 79 if (ret != 2) {
81 dprintk(KERN_DEBUG "%s: error reg=0x%x, ret=%i\n", 80 dprintk("%s: error reg=0x%x, ret=%i\n", __func__, reg, ret);
82 __func__, reg, ret);
83 return -EIO; 81 return -EIO;
84 } 82 }
85 83
86 *p_data = b1[0]; 84 *p_data = b1[0];
87 if (debug >= 2) 85 if (debug >= 2)
88 printk(KERN_DEBUG "%s: reg=0x%02X, data=0x%02X\n", 86 dprintk("%s: reg=0x%02X, data=0x%02X\n",
89 __func__, reg, b1[0]); 87 __func__, reg, b1[0]);
90 return 0; 88 return 0;
91} 89}
diff --git a/drivers/media/common/tuners/tda18218.c b/drivers/media/common/tuners/tda18218.c
index 8da1fdeddaa7..aacfe2387e28 100644
--- a/drivers/media/common/tuners/tda18218.c
+++ b/drivers/media/common/tuners/tda18218.c
@@ -28,7 +28,7 @@ MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
28/* write multiple registers */ 28/* write multiple registers */
29static int tda18218_wr_regs(struct tda18218_priv *priv, u8 reg, u8 *val, u8 len) 29static int tda18218_wr_regs(struct tda18218_priv *priv, u8 reg, u8 *val, u8 len)
30{ 30{
31 int ret; 31 int ret = 0;
32 u8 buf[1+len], quotient, remainder, i, msg_len, msg_len_max; 32 u8 buf[1+len], quotient, remainder, i, msg_len, msg_len_max;
33 struct i2c_msg msg[1] = { 33 struct i2c_msg msg[1] = {
34 { 34 {
diff --git a/drivers/media/dvb/dm1105/Kconfig b/drivers/media/dvb/dm1105/Kconfig
index a6ceb08f1183..f3de0a4d63f2 100644
--- a/drivers/media/dvb/dm1105/Kconfig
+++ b/drivers/media/dvb/dm1105/Kconfig
@@ -1,7 +1,6 @@
1config DVB_DM1105 1config DVB_DM1105
2 tristate "SDMC DM1105 based PCI cards" 2 tristate "SDMC DM1105 based PCI cards"
3 depends on DVB_CORE && PCI && I2C 3 depends on DVB_CORE && PCI && I2C
4 depends on INPUT
5 select DVB_PLL if !DVB_FE_CUSTOMISE 4 select DVB_PLL if !DVB_FE_CUSTOMISE
6 select DVB_STV0299 if !DVB_FE_CUSTOMISE 5 select DVB_STV0299 if !DVB_FE_CUSTOMISE
7 select DVB_STV0288 if !DVB_FE_CUSTOMISE 6 select DVB_STV0288 if !DVB_FE_CUSTOMISE
@@ -9,7 +8,7 @@ config DVB_DM1105
9 select DVB_CX24116 if !DVB_FE_CUSTOMISE 8 select DVB_CX24116 if !DVB_FE_CUSTOMISE
10 select DVB_SI21XX if !DVB_FE_CUSTOMISE 9 select DVB_SI21XX if !DVB_FE_CUSTOMISE
11 select DVB_DS3000 if !DVB_FE_CUSTOMISE 10 select DVB_DS3000 if !DVB_FE_CUSTOMISE
12 depends on VIDEO_IR 11 depends on RC_CORE
13 help 12 help
14 Support for cards based on the SDMC DM1105 PCI chip like 13 Support for cards based on the SDMC DM1105 PCI chip like
15 DvbWorld 2002 14 DvbWorld 2002
diff --git a/drivers/media/dvb/dm1105/dm1105.c b/drivers/media/dvb/dm1105/dm1105.c
index 5d404f1bf036..2d8b4044be36 100644
--- a/drivers/media/dvb/dm1105/dm1105.c
+++ b/drivers/media/dvb/dm1105/dm1105.c
@@ -26,9 +26,8 @@
26#include <linux/proc_fs.h> 26#include <linux/proc_fs.h>
27#include <linux/pci.h> 27#include <linux/pci.h>
28#include <linux/dma-mapping.h> 28#include <linux/dma-mapping.h>
29#include <linux/input.h>
30#include <linux/slab.h> 29#include <linux/slab.h>
31#include <media/ir-core.h> 30#include <media/rc-core.h>
32 31
33#include "demux.h" 32#include "demux.h"
34#include "dmxdev.h" 33#include "dmxdev.h"
@@ -266,7 +265,7 @@ static void dm1105_card_list(struct pci_dev *pci)
266 265
267/* infrared remote control */ 266/* infrared remote control */
268struct infrared { 267struct infrared {
269 struct input_dev *input_dev; 268 struct rc_dev *dev;
270 char input_phys[32]; 269 char input_phys[32];
271 struct work_struct work; 270 struct work_struct work;
272 u32 ir_command; 271 u32 ir_command;
@@ -532,7 +531,7 @@ static void dm1105_emit_key(struct work_struct *work)
532 531
533 data = (ircom >> 8) & 0x7f; 532 data = (ircom >> 8) & 0x7f;
534 533
535 ir_keydown(ir->input_dev, data, 0); 534 rc_keydown(ir->dev, data, 0);
536} 535}
537 536
538/* work handler */ 537/* work handler */
@@ -593,46 +592,47 @@ static irqreturn_t dm1105_irq(int irq, void *dev_id)
593 592
594int __devinit dm1105_ir_init(struct dm1105_dev *dm1105) 593int __devinit dm1105_ir_init(struct dm1105_dev *dm1105)
595{ 594{
596 struct input_dev *input_dev; 595 struct rc_dev *dev;
597 char *ir_codes = RC_MAP_DM1105_NEC;
598 int err = -ENOMEM; 596 int err = -ENOMEM;
599 597
600 input_dev = input_allocate_device(); 598 dev = rc_allocate_device();
601 if (!input_dev) 599 if (!dev)
602 return -ENOMEM; 600 return -ENOMEM;
603 601
604 dm1105->ir.input_dev = input_dev;
605 snprintf(dm1105->ir.input_phys, sizeof(dm1105->ir.input_phys), 602 snprintf(dm1105->ir.input_phys, sizeof(dm1105->ir.input_phys),
606 "pci-%s/ir0", pci_name(dm1105->pdev)); 603 "pci-%s/ir0", pci_name(dm1105->pdev));
607 604
608 input_dev->name = "DVB on-card IR receiver"; 605 dev->driver_name = MODULE_NAME;
609 input_dev->phys = dm1105->ir.input_phys; 606 dev->map_name = RC_MAP_DM1105_NEC;
610 input_dev->id.bustype = BUS_PCI; 607 dev->driver_type = RC_DRIVER_SCANCODE;
611 input_dev->id.version = 1; 608 dev->input_name = "DVB on-card IR receiver";
609 dev->input_phys = dm1105->ir.input_phys;
610 dev->input_id.bustype = BUS_PCI;
611 dev->input_id.version = 1;
612 if (dm1105->pdev->subsystem_vendor) { 612 if (dm1105->pdev->subsystem_vendor) {
613 input_dev->id.vendor = dm1105->pdev->subsystem_vendor; 613 dev->input_id.vendor = dm1105->pdev->subsystem_vendor;
614 input_dev->id.product = dm1105->pdev->subsystem_device; 614 dev->input_id.product = dm1105->pdev->subsystem_device;
615 } else { 615 } else {
616 input_dev->id.vendor = dm1105->pdev->vendor; 616 dev->input_id.vendor = dm1105->pdev->vendor;
617 input_dev->id.product = dm1105->pdev->device; 617 dev->input_id.product = dm1105->pdev->device;
618 } 618 }
619 619 dev->dev.parent = &dm1105->pdev->dev;
620 input_dev->dev.parent = &dm1105->pdev->dev;
621 620
622 INIT_WORK(&dm1105->ir.work, dm1105_emit_key); 621 INIT_WORK(&dm1105->ir.work, dm1105_emit_key);
623 622
624 err = ir_input_register(input_dev, ir_codes, NULL, MODULE_NAME); 623 err = rc_register_device(dev);
625 if (err < 0) { 624 if (err < 0) {
626 input_free_device(input_dev); 625 rc_free_device(dev);
627 return err; 626 return err;
628 } 627 }
629 628
629 dm1105->ir.dev = dev;
630 return 0; 630 return 0;
631} 631}
632 632
633void __devexit dm1105_ir_exit(struct dm1105_dev *dm1105) 633void __devexit dm1105_ir_exit(struct dm1105_dev *dm1105)
634{ 634{
635 ir_input_unregister(dm1105->ir.input_dev); 635 rc_unregister_device(dm1105->ir.dev);
636} 636}
637 637
638static int __devinit dm1105_hw_init(struct dm1105_dev *dev) 638static int __devinit dm1105_hw_init(struct dm1105_dev *dev)
diff --git a/drivers/media/dvb/dvb-core/dmxdev.c b/drivers/media/dvb/dvb-core/dmxdev.c
index ad1f61d301e1..e4b5c03ae516 100644
--- a/drivers/media/dvb/dvb-core/dmxdev.c
+++ b/drivers/media/dvb/dvb-core/dmxdev.c
@@ -572,13 +572,13 @@ static int dvb_dmxdev_start_feed(struct dmxdev *dmxdev,
572 dmx_output_t otype; 572 dmx_output_t otype;
573 int ret; 573 int ret;
574 int ts_type; 574 int ts_type;
575 enum dmx_ts_pes ts_pes; 575 dmx_pes_type_t ts_pes;
576 struct dmx_ts_feed *tsfeed; 576 struct dmx_ts_feed *tsfeed;
577 577
578 feed->ts = NULL; 578 feed->ts = NULL;
579 otype = para->output; 579 otype = para->output;
580 580
581 ts_pes = (enum dmx_ts_pes)para->pes_type; 581 ts_pes = para->pes_type;
582 582
583 if (ts_pes < DMX_PES_OTHER) 583 if (ts_pes < DMX_PES_OTHER)
584 ts_type = TS_DECODER; 584 ts_type = TS_DECODER;
diff --git a/drivers/media/dvb/dvb-usb/Kconfig b/drivers/media/dvb/dvb-usb/Kconfig
index 2525d3b3c88d..3d48ba019342 100644
--- a/drivers/media/dvb/dvb-usb/Kconfig
+++ b/drivers/media/dvb/dvb-usb/Kconfig
@@ -1,6 +1,6 @@
1config DVB_USB 1config DVB_USB
2 tristate "Support for various USB DVB devices" 2 tristate "Support for various USB DVB devices"
3 depends on DVB_CORE && USB && I2C && IR_CORE 3 depends on DVB_CORE && USB && I2C && RC_CORE
4 help 4 help
5 By enabling this you will be able to choose the various supported 5 By enabling this you will be able to choose the various supported
6 USB1.1 and USB2.0 DVB devices. 6 USB1.1 and USB2.0 DVB devices.
diff --git a/drivers/media/dvb/dvb-usb/a800.c b/drivers/media/dvb/dvb-usb/a800.c
index a5c363727133..53b93a4b6f8a 100644
--- a/drivers/media/dvb/dvb-usb/a800.c
+++ b/drivers/media/dvb/dvb-usb/a800.c
@@ -37,7 +37,7 @@ static int a800_identify_state(struct usb_device *udev, struct dvb_usb_device_pr
37 return 0; 37 return 0;
38} 38}
39 39
40static struct ir_scancode ir_codes_a800_table[] = { 40static struct rc_map_table rc_map_a800_table[] = {
41 { 0x0201, KEY_PROG1 }, /* SOURCE */ 41 { 0x0201, KEY_PROG1 }, /* SOURCE */
42 { 0x0200, KEY_POWER }, /* POWER */ 42 { 0x0200, KEY_POWER }, /* POWER */
43 { 0x0205, KEY_1 }, /* 1 */ 43 { 0x0205, KEY_1 }, /* 1 */
@@ -148,8 +148,8 @@ static struct dvb_usb_device_properties a800_properties = {
148 148
149 .rc.legacy = { 149 .rc.legacy = {
150 .rc_interval = DEFAULT_RC_INTERVAL, 150 .rc_interval = DEFAULT_RC_INTERVAL,
151 .rc_key_map = ir_codes_a800_table, 151 .rc_map_table = rc_map_a800_table,
152 .rc_key_map_size = ARRAY_SIZE(ir_codes_a800_table), 152 .rc_map_size = ARRAY_SIZE(rc_map_a800_table),
153 .rc_query = a800_rc_query, 153 .rc_query = a800_rc_query,
154 }, 154 },
155 155
diff --git a/drivers/media/dvb/dvb-usb/af9005-remote.c b/drivers/media/dvb/dvb-usb/af9005-remote.c
index 696207fe37ec..c3bc64ed405c 100644
--- a/drivers/media/dvb/dvb-usb/af9005-remote.c
+++ b/drivers/media/dvb/dvb-usb/af9005-remote.c
@@ -33,7 +33,7 @@ MODULE_PARM_DESC(debug,
33 33
34#define deb_decode(args...) dprintk(dvb_usb_af9005_remote_debug,0x01,args) 34#define deb_decode(args...) dprintk(dvb_usb_af9005_remote_debug,0x01,args)
35 35
36struct ir_scancode ir_codes_af9005_table[] = { 36struct rc_map_table rc_map_af9005_table[] = {
37 37
38 {0x01b7, KEY_POWER}, 38 {0x01b7, KEY_POWER},
39 {0x01a7, KEY_VOLUMEUP}, 39 {0x01a7, KEY_VOLUMEUP},
@@ -74,7 +74,7 @@ struct ir_scancode ir_codes_af9005_table[] = {
74 {0x00d5, KEY_GOTO}, /* marked jump on the remote */ 74 {0x00d5, KEY_GOTO}, /* marked jump on the remote */
75}; 75};
76 76
77int ir_codes_af9005_table_size = ARRAY_SIZE(ir_codes_af9005_table); 77int rc_map_af9005_table_size = ARRAY_SIZE(rc_map_af9005_table);
78 78
79static int repeatable_keys[] = { 79static int repeatable_keys[] = {
80 KEY_VOLUMEUP, 80 KEY_VOLUMEUP,
@@ -130,10 +130,10 @@ int af9005_rc_decode(struct dvb_usb_device *d, u8 * data, int len, u32 * event,
130 deb_decode("code != inverted code\n"); 130 deb_decode("code != inverted code\n");
131 return 0; 131 return 0;
132 } 132 }
133 for (i = 0; i < ir_codes_af9005_table_size; i++) { 133 for (i = 0; i < rc_map_af9005_table_size; i++) {
134 if (rc5_custom(&ir_codes_af9005_table[i]) == cust 134 if (rc5_custom(&rc_map_af9005_table[i]) == cust
135 && rc5_data(&ir_codes_af9005_table[i]) == dat) { 135 && rc5_data(&rc_map_af9005_table[i]) == dat) {
136 *event = ir_codes_af9005_table[i].keycode; 136 *event = rc_map_af9005_table[i].keycode;
137 *state = REMOTE_KEY_PRESSED; 137 *state = REMOTE_KEY_PRESSED;
138 deb_decode 138 deb_decode
139 ("key pressed, event %x\n", *event); 139 ("key pressed, event %x\n", *event);
@@ -146,8 +146,8 @@ int af9005_rc_decode(struct dvb_usb_device *d, u8 * data, int len, u32 * event,
146 return 0; 146 return 0;
147} 147}
148 148
149EXPORT_SYMBOL(ir_codes_af9005_table); 149EXPORT_SYMBOL(rc_map_af9005_table);
150EXPORT_SYMBOL(ir_codes_af9005_table_size); 150EXPORT_SYMBOL(rc_map_af9005_table_size);
151EXPORT_SYMBOL(af9005_rc_decode); 151EXPORT_SYMBOL(af9005_rc_decode);
152 152
153MODULE_AUTHOR("Luca Olivetti <luca@ventoso.org>"); 153MODULE_AUTHOR("Luca Olivetti <luca@ventoso.org>");
diff --git a/drivers/media/dvb/dvb-usb/af9005.c b/drivers/media/dvb/dvb-usb/af9005.c
index 8ecba8848bcf..51f6439dcfd5 100644
--- a/drivers/media/dvb/dvb-usb/af9005.c
+++ b/drivers/media/dvb/dvb-usb/af9005.c
@@ -1027,8 +1027,8 @@ static struct dvb_usb_device_properties af9005_properties = {
1027 1027
1028 .rc.legacy = { 1028 .rc.legacy = {
1029 .rc_interval = 200, 1029 .rc_interval = 200,
1030 .rc_key_map = NULL, 1030 .rc_map_table = NULL,
1031 .rc_key_map_size = 0, 1031 .rc_map_size = 0,
1032 .rc_query = af9005_rc_query, 1032 .rc_query = af9005_rc_query,
1033 }, 1033 },
1034 1034
@@ -1070,14 +1070,14 @@ static int __init af9005_usb_module_init(void)
1070 return result; 1070 return result;
1071 } 1071 }
1072 rc_decode = symbol_request(af9005_rc_decode); 1072 rc_decode = symbol_request(af9005_rc_decode);
1073 rc_keys = symbol_request(ir_codes_af9005_table); 1073 rc_keys = symbol_request(rc_map_af9005_table);
1074 rc_keys_size = symbol_request(ir_codes_af9005_table_size); 1074 rc_keys_size = symbol_request(rc_map_af9005_table_size);
1075 if (rc_decode == NULL || rc_keys == NULL || rc_keys_size == NULL) { 1075 if (rc_decode == NULL || rc_keys == NULL || rc_keys_size == NULL) {
1076 err("af9005_rc_decode function not found, disabling remote"); 1076 err("af9005_rc_decode function not found, disabling remote");
1077 af9005_properties.rc.legacy.rc_query = NULL; 1077 af9005_properties.rc.legacy.rc_query = NULL;
1078 } else { 1078 } else {
1079 af9005_properties.rc.legacy.rc_key_map = rc_keys; 1079 af9005_properties.rc.legacy.rc_map_table = rc_keys;
1080 af9005_properties.rc.legacy.rc_key_map_size = *rc_keys_size; 1080 af9005_properties.rc.legacy.rc_map_size = *rc_keys_size;
1081 } 1081 }
1082 1082
1083 return 0; 1083 return 0;
@@ -1089,9 +1089,9 @@ static void __exit af9005_usb_module_exit(void)
1089 if (rc_decode != NULL) 1089 if (rc_decode != NULL)
1090 symbol_put(af9005_rc_decode); 1090 symbol_put(af9005_rc_decode);
1091 if (rc_keys != NULL) 1091 if (rc_keys != NULL)
1092 symbol_put(ir_codes_af9005_table); 1092 symbol_put(rc_map_af9005_table);
1093 if (rc_keys_size != NULL) 1093 if (rc_keys_size != NULL)
1094 symbol_put(ir_codes_af9005_table_size); 1094 symbol_put(rc_map_af9005_table_size);
1095 /* deregister this driver from the USB subsystem */ 1095 /* deregister this driver from the USB subsystem */
1096 usb_deregister(&af9005_usb_driver); 1096 usb_deregister(&af9005_usb_driver);
1097} 1097}
diff --git a/drivers/media/dvb/dvb-usb/af9005.h b/drivers/media/dvb/dvb-usb/af9005.h
index 3c1fbd1c5d60..c71c77bd7f4b 100644
--- a/drivers/media/dvb/dvb-usb/af9005.h
+++ b/drivers/media/dvb/dvb-usb/af9005.h
@@ -3490,7 +3490,7 @@ extern u8 regmask[8];
3490/* remote control decoder */ 3490/* remote control decoder */
3491extern int af9005_rc_decode(struct dvb_usb_device *d, u8 * data, int len, 3491extern int af9005_rc_decode(struct dvb_usb_device *d, u8 * data, int len,
3492 u32 * event, int *state); 3492 u32 * event, int *state);
3493extern struct ir_scancode ir_codes_af9005_table[]; 3493extern struct rc_map_table rc_map_af9005_table[];
3494extern int ir_codes_af9005_table_size; 3494extern int rc_map_af9005_table_size;
3495 3495
3496#endif 3496#endif
diff --git a/drivers/media/dvb/dvb-usb/af9015.c b/drivers/media/dvb/dvb-usb/af9015.c
index 31c0a0ed39f5..8671ca362c81 100644
--- a/drivers/media/dvb/dvb-usb/af9015.c
+++ b/drivers/media/dvb/dvb-usb/af9015.c
@@ -1041,13 +1041,13 @@ static int af9015_rc_query(struct dvb_usb_device *d)
1041 priv->rc_keycode = buf[12] << 16 | 1041 priv->rc_keycode = buf[12] << 16 |
1042 buf[13] << 8 | buf[14]; 1042 buf[13] << 8 | buf[14];
1043 } 1043 }
1044 ir_keydown(d->rc_input_dev, priv->rc_keycode, 0); 1044 rc_keydown(d->rc_dev, priv->rc_keycode, 0);
1045 } else { 1045 } else {
1046 priv->rc_keycode = 0; /* clear just for sure */ 1046 priv->rc_keycode = 0; /* clear just for sure */
1047 } 1047 }
1048 } else if (priv->rc_repeat != buf[6] || buf[0]) { 1048 } else if (priv->rc_repeat != buf[6] || buf[0]) {
1049 deb_rc("%s: key repeated\n", __func__); 1049 deb_rc("%s: key repeated\n", __func__);
1050 ir_keydown(d->rc_input_dev, priv->rc_keycode, 0); 1050 rc_keydown(d->rc_dev, priv->rc_keycode, 0);
1051 } else { 1051 } else {
1052 deb_rc("%s: no key press\n", __func__); 1052 deb_rc("%s: no key press\n", __func__);
1053 } 1053 }
@@ -1344,13 +1344,11 @@ static struct dvb_usb_device_properties af9015_properties[] = {
1344 .identify_state = af9015_identify_state, 1344 .identify_state = af9015_identify_state,
1345 1345
1346 .rc.core = { 1346 .rc.core = {
1347 .protocol = IR_TYPE_NEC, 1347 .protocol = RC_TYPE_NEC,
1348 .module_name = "af9015", 1348 .module_name = "af9015",
1349 .rc_query = af9015_rc_query, 1349 .rc_query = af9015_rc_query,
1350 .rc_interval = AF9015_RC_INTERVAL, 1350 .rc_interval = AF9015_RC_INTERVAL,
1351 .rc_props = { 1351 .allowed_protos = RC_TYPE_NEC,
1352 .allowed_protos = IR_TYPE_NEC,
1353 },
1354 }, 1352 },
1355 1353
1356 .i2c_algo = &af9015_i2c_algo, 1354 .i2c_algo = &af9015_i2c_algo,
@@ -1474,13 +1472,11 @@ static struct dvb_usb_device_properties af9015_properties[] = {
1474 .identify_state = af9015_identify_state, 1472 .identify_state = af9015_identify_state,
1475 1473
1476 .rc.core = { 1474 .rc.core = {
1477 .protocol = IR_TYPE_NEC, 1475 .protocol = RC_TYPE_NEC,
1478 .module_name = "af9015", 1476 .module_name = "af9015",
1479 .rc_query = af9015_rc_query, 1477 .rc_query = af9015_rc_query,
1480 .rc_interval = AF9015_RC_INTERVAL, 1478 .rc_interval = AF9015_RC_INTERVAL,
1481 .rc_props = { 1479 .allowed_protos = RC_TYPE_NEC,
1482 .allowed_protos = IR_TYPE_NEC,
1483 },
1484 }, 1480 },
1485 1481
1486 .i2c_algo = &af9015_i2c_algo, 1482 .i2c_algo = &af9015_i2c_algo,
@@ -1588,13 +1584,11 @@ static struct dvb_usb_device_properties af9015_properties[] = {
1588 .identify_state = af9015_identify_state, 1584 .identify_state = af9015_identify_state,
1589 1585
1590 .rc.core = { 1586 .rc.core = {
1591 .protocol = IR_TYPE_NEC, 1587 .protocol = RC_TYPE_NEC,
1592 .module_name = "af9015", 1588 .module_name = "af9015",
1593 .rc_query = af9015_rc_query, 1589 .rc_query = af9015_rc_query,
1594 .rc_interval = AF9015_RC_INTERVAL, 1590 .rc_interval = AF9015_RC_INTERVAL,
1595 .rc_props = { 1591 .allowed_protos = RC_TYPE_NEC,
1596 .allowed_protos = IR_TYPE_NEC,
1597 },
1598 }, 1592 },
1599 1593
1600 .i2c_algo = &af9015_i2c_algo, 1594 .i2c_algo = &af9015_i2c_algo,
diff --git a/drivers/media/dvb/dvb-usb/anysee.c b/drivers/media/dvb/dvb-usb/anysee.c
index 1759d26bca42..6b402e943539 100644
--- a/drivers/media/dvb/dvb-usb/anysee.c
+++ b/drivers/media/dvb/dvb-usb/anysee.c
@@ -394,7 +394,7 @@ static int anysee_rc_query(struct dvb_usb_device *d)
394 394
395 if (ircode[0]) { 395 if (ircode[0]) {
396 deb_rc("%s: key pressed %02x\n", __func__, ircode[1]); 396 deb_rc("%s: key pressed %02x\n", __func__, ircode[1]);
397 ir_keydown(d->rc_input_dev, 0x08 << 8 | ircode[1], 0); 397 rc_keydown(d->rc_dev, 0x08 << 8 | ircode[1], 0);
398 } 398 }
399 399
400 return 0; 400 return 0;
@@ -476,7 +476,7 @@ static struct dvb_usb_device_properties anysee_properties = {
476 476
477 .rc.core = { 477 .rc.core = {
478 .rc_codes = RC_MAP_ANYSEE, 478 .rc_codes = RC_MAP_ANYSEE,
479 .protocol = IR_TYPE_OTHER, 479 .protocol = RC_TYPE_OTHER,
480 .module_name = "anysee", 480 .module_name = "anysee",
481 .rc_query = anysee_rc_query, 481 .rc_query = anysee_rc_query,
482 .rc_interval = 250, /* windows driver uses 500ms */ 482 .rc_interval = 250, /* windows driver uses 500ms */
diff --git a/drivers/media/dvb/dvb-usb/az6027.c b/drivers/media/dvb/dvb-usb/az6027.c
index 62c58288469f..57e2444d51ab 100644
--- a/drivers/media/dvb/dvb-usb/az6027.c
+++ b/drivers/media/dvb/dvb-usb/az6027.c
@@ -386,7 +386,7 @@ static int az6027_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
386} 386}
387 387
388/* keys for the enclosed remote control */ 388/* keys for the enclosed remote control */
389static struct ir_scancode ir_codes_az6027_table[] = { 389static struct rc_map_table rc_map_az6027_table[] = {
390 { 0x01, KEY_1 }, 390 { 0x01, KEY_1 },
391 { 0x02, KEY_2 }, 391 { 0x02, KEY_2 },
392}; 392};
@@ -1089,6 +1089,7 @@ static struct usb_device_id az6027_usb_table[] = {
1089 { USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_DVBS2CI_V2) }, 1089 { USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_DVBS2CI_V2) },
1090 { USB_DEVICE(USB_VID_TECHNISAT, USB_PID_TECHNISAT_USB2_HDCI_V1) }, 1090 { USB_DEVICE(USB_VID_TECHNISAT, USB_PID_TECHNISAT_USB2_HDCI_V1) },
1091 { USB_DEVICE(USB_VID_TECHNISAT, USB_PID_TECHNISAT_USB2_HDCI_V2) }, 1091 { USB_DEVICE(USB_VID_TECHNISAT, USB_PID_TECHNISAT_USB2_HDCI_V2) },
1092 { USB_DEVICE(USB_VID_ELGATO, USB_PID_ELGATO_EYETV_SAT) },
1092 { }, 1093 { },
1093}; 1094};
1094 1095
@@ -1126,15 +1127,15 @@ static struct dvb_usb_device_properties az6027_properties = {
1126 .read_mac_address = az6027_read_mac_addr, 1127 .read_mac_address = az6027_read_mac_addr,
1127 */ 1128 */
1128 .rc.legacy = { 1129 .rc.legacy = {
1129 .rc_key_map = ir_codes_az6027_table, 1130 .rc_map_table = rc_map_az6027_table,
1130 .rc_key_map_size = ARRAY_SIZE(ir_codes_az6027_table), 1131 .rc_map_size = ARRAY_SIZE(rc_map_az6027_table),
1131 .rc_interval = 400, 1132 .rc_interval = 400,
1132 .rc_query = az6027_rc_query, 1133 .rc_query = az6027_rc_query,
1133 }, 1134 },
1134 1135
1135 .i2c_algo = &az6027_i2c_algo, 1136 .i2c_algo = &az6027_i2c_algo,
1136 1137
1137 .num_device_descs = 5, 1138 .num_device_descs = 6,
1138 .devices = { 1139 .devices = {
1139 { 1140 {
1140 .name = "AZUREWAVE DVB-S/S2 USB2.0 (AZ6027)", 1141 .name = "AZUREWAVE DVB-S/S2 USB2.0 (AZ6027)",
@@ -1156,6 +1157,10 @@ static struct dvb_usb_device_properties az6027_properties = {
1156 .name = "Technisat SkyStar USB 2 HD CI", 1157 .name = "Technisat SkyStar USB 2 HD CI",
1157 .cold_ids = { &az6027_usb_table[4], NULL }, 1158 .cold_ids = { &az6027_usb_table[4], NULL },
1158 .warm_ids = { NULL }, 1159 .warm_ids = { NULL },
1160 }, {
1161 .name = "Elgato EyeTV Sat",
1162 .cold_ids = { &az6027_usb_table[5], NULL },
1163 .warm_ids = { NULL },
1159 }, 1164 },
1160 { NULL }, 1165 { NULL },
1161 } 1166 }
diff --git a/drivers/media/dvb/dvb-usb/cinergyT2-core.c b/drivers/media/dvb/dvb-usb/cinergyT2-core.c
index 4f5aa83fc1fc..16f2ce2bc15a 100644
--- a/drivers/media/dvb/dvb-usb/cinergyT2-core.c
+++ b/drivers/media/dvb/dvb-usb/cinergyT2-core.c
@@ -84,7 +84,7 @@ static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
84 return 0; 84 return 0;
85} 85}
86 86
87static struct ir_scancode ir_codes_cinergyt2_table[] = { 87static struct rc_map_table rc_map_cinergyt2_table[] = {
88 { 0x0401, KEY_POWER }, 88 { 0x0401, KEY_POWER },
89 { 0x0402, KEY_1 }, 89 { 0x0402, KEY_1 },
90 { 0x0403, KEY_2 }, 90 { 0x0403, KEY_2 },
@@ -219,8 +219,8 @@ static struct dvb_usb_device_properties cinergyt2_properties = {
219 219
220 .rc.legacy = { 220 .rc.legacy = {
221 .rc_interval = 50, 221 .rc_interval = 50,
222 .rc_key_map = ir_codes_cinergyt2_table, 222 .rc_map_table = rc_map_cinergyt2_table,
223 .rc_key_map_size = ARRAY_SIZE(ir_codes_cinergyt2_table), 223 .rc_map_size = ARRAY_SIZE(rc_map_cinergyt2_table),
224 .rc_query = cinergyt2_rc_query, 224 .rc_query = cinergyt2_rc_query,
225 }, 225 },
226 226
diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
index cd9f362c37b2..acb5fb2d2e73 100644
--- a/drivers/media/dvb/dvb-usb/cxusb.c
+++ b/drivers/media/dvb/dvb-usb/cxusb.c
@@ -385,7 +385,7 @@ static int cxusb_d680_dmb_streaming_ctrl(
385 385
386static int cxusb_rc_query(struct dvb_usb_device *d, u32 *event, int *state) 386static int cxusb_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
387{ 387{
388 struct ir_scancode *keymap = d->props.rc.legacy.rc_key_map; 388 struct rc_map_table *keymap = d->props.rc.legacy.rc_map_table;
389 u8 ircode[4]; 389 u8 ircode[4];
390 int i; 390 int i;
391 391
@@ -394,7 +394,7 @@ static int cxusb_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
394 *event = 0; 394 *event = 0;
395 *state = REMOTE_NO_KEY_PRESSED; 395 *state = REMOTE_NO_KEY_PRESSED;
396 396
397 for (i = 0; i < d->props.rc.legacy.rc_key_map_size; i++) { 397 for (i = 0; i < d->props.rc.legacy.rc_map_size; i++) {
398 if (rc5_custom(&keymap[i]) == ircode[2] && 398 if (rc5_custom(&keymap[i]) == ircode[2] &&
399 rc5_data(&keymap[i]) == ircode[3]) { 399 rc5_data(&keymap[i]) == ircode[3]) {
400 *event = keymap[i].keycode; 400 *event = keymap[i].keycode;
@@ -410,7 +410,7 @@ static int cxusb_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
410static int cxusb_bluebird2_rc_query(struct dvb_usb_device *d, u32 *event, 410static int cxusb_bluebird2_rc_query(struct dvb_usb_device *d, u32 *event,
411 int *state) 411 int *state)
412{ 412{
413 struct ir_scancode *keymap = d->props.rc.legacy.rc_key_map; 413 struct rc_map_table *keymap = d->props.rc.legacy.rc_map_table;
414 u8 ircode[4]; 414 u8 ircode[4];
415 int i; 415 int i;
416 struct i2c_msg msg = { .addr = 0x6b, .flags = I2C_M_RD, 416 struct i2c_msg msg = { .addr = 0x6b, .flags = I2C_M_RD,
@@ -422,7 +422,7 @@ static int cxusb_bluebird2_rc_query(struct dvb_usb_device *d, u32 *event,
422 if (cxusb_i2c_xfer(&d->i2c_adap, &msg, 1) != 1) 422 if (cxusb_i2c_xfer(&d->i2c_adap, &msg, 1) != 1)
423 return 0; 423 return 0;
424 424
425 for (i = 0; i < d->props.rc.legacy.rc_key_map_size; i++) { 425 for (i = 0; i < d->props.rc.legacy.rc_map_size; i++) {
426 if (rc5_custom(&keymap[i]) == ircode[1] && 426 if (rc5_custom(&keymap[i]) == ircode[1] &&
427 rc5_data(&keymap[i]) == ircode[2]) { 427 rc5_data(&keymap[i]) == ircode[2]) {
428 *event = keymap[i].keycode; 428 *event = keymap[i].keycode;
@@ -438,7 +438,7 @@ static int cxusb_bluebird2_rc_query(struct dvb_usb_device *d, u32 *event,
438static int cxusb_d680_dmb_rc_query(struct dvb_usb_device *d, u32 *event, 438static int cxusb_d680_dmb_rc_query(struct dvb_usb_device *d, u32 *event,
439 int *state) 439 int *state)
440{ 440{
441 struct ir_scancode *keymap = d->props.rc.legacy.rc_key_map; 441 struct rc_map_table *keymap = d->props.rc.legacy.rc_map_table;
442 u8 ircode[2]; 442 u8 ircode[2];
443 int i; 443 int i;
444 444
@@ -448,7 +448,7 @@ static int cxusb_d680_dmb_rc_query(struct dvb_usb_device *d, u32 *event,
448 if (cxusb_ctrl_msg(d, 0x10, NULL, 0, ircode, 2) < 0) 448 if (cxusb_ctrl_msg(d, 0x10, NULL, 0, ircode, 2) < 0)
449 return 0; 449 return 0;
450 450
451 for (i = 0; i < d->props.rc.legacy.rc_key_map_size; i++) { 451 for (i = 0; i < d->props.rc.legacy.rc_map_size; i++) {
452 if (rc5_custom(&keymap[i]) == ircode[0] && 452 if (rc5_custom(&keymap[i]) == ircode[0] &&
453 rc5_data(&keymap[i]) == ircode[1]) { 453 rc5_data(&keymap[i]) == ircode[1]) {
454 *event = keymap[i].keycode; 454 *event = keymap[i].keycode;
@@ -461,7 +461,7 @@ static int cxusb_d680_dmb_rc_query(struct dvb_usb_device *d, u32 *event,
461 return 0; 461 return 0;
462} 462}
463 463
464static struct ir_scancode ir_codes_dvico_mce_table[] = { 464static struct rc_map_table rc_map_dvico_mce_table[] = {
465 { 0xfe02, KEY_TV }, 465 { 0xfe02, KEY_TV },
466 { 0xfe0e, KEY_MP3 }, 466 { 0xfe0e, KEY_MP3 },
467 { 0xfe1a, KEY_DVD }, 467 { 0xfe1a, KEY_DVD },
@@ -509,7 +509,7 @@ static struct ir_scancode ir_codes_dvico_mce_table[] = {
509 { 0xfe4e, KEY_POWER }, 509 { 0xfe4e, KEY_POWER },
510}; 510};
511 511
512static struct ir_scancode ir_codes_dvico_portable_table[] = { 512static struct rc_map_table rc_map_dvico_portable_table[] = {
513 { 0xfc02, KEY_SETUP }, /* Profile */ 513 { 0xfc02, KEY_SETUP }, /* Profile */
514 { 0xfc43, KEY_POWER2 }, 514 { 0xfc43, KEY_POWER2 },
515 { 0xfc06, KEY_EPG }, 515 { 0xfc06, KEY_EPG },
@@ -548,7 +548,7 @@ static struct ir_scancode ir_codes_dvico_portable_table[] = {
548 { 0xfc00, KEY_UNKNOWN }, /* HD */ 548 { 0xfc00, KEY_UNKNOWN }, /* HD */
549}; 549};
550 550
551static struct ir_scancode ir_codes_d680_dmb_table[] = { 551static struct rc_map_table rc_map_d680_dmb_table[] = {
552 { 0x0038, KEY_UNKNOWN }, /* TV/AV */ 552 { 0x0038, KEY_UNKNOWN }, /* TV/AV */
553 { 0x080c, KEY_ZOOM }, 553 { 0x080c, KEY_ZOOM },
554 { 0x0800, KEY_0 }, 554 { 0x0800, KEY_0 },
@@ -923,7 +923,7 @@ static int cxusb_dualdig4_frontend_attach(struct dvb_usb_adapter *adap)
923 return -EIO; 923 return -EIO;
924 924
925 /* try to determine if there is no IR decoder on the I2C bus */ 925 /* try to determine if there is no IR decoder on the I2C bus */
926 for (i = 0; adap->dev->props.rc.legacy.rc_key_map != NULL && i < 5; i++) { 926 for (i = 0; adap->dev->props.rc.legacy.rc_map_table != NULL && i < 5; i++) {
927 msleep(20); 927 msleep(20);
928 if (cxusb_i2c_xfer(&adap->dev->i2c_adap, &msg, 1) != 1) 928 if (cxusb_i2c_xfer(&adap->dev->i2c_adap, &msg, 1) != 1)
929 goto no_IR; 929 goto no_IR;
@@ -931,7 +931,7 @@ static int cxusb_dualdig4_frontend_attach(struct dvb_usb_adapter *adap)
931 continue; 931 continue;
932 if (ircode[2] + ircode[3] != 0xff) { 932 if (ircode[2] + ircode[3] != 0xff) {
933no_IR: 933no_IR:
934 adap->dev->props.rc.legacy.rc_key_map = NULL; 934 adap->dev->props.rc.legacy.rc_map_table = NULL;
935 info("No IR receiver detected on this device."); 935 info("No IR receiver detected on this device.");
936 break; 936 break;
937 } 937 }
@@ -1453,8 +1453,8 @@ static struct dvb_usb_device_properties cxusb_bluebird_lgh064f_properties = {
1453 1453
1454 .rc.legacy = { 1454 .rc.legacy = {
1455 .rc_interval = 100, 1455 .rc_interval = 100,
1456 .rc_key_map = ir_codes_dvico_portable_table, 1456 .rc_map_table = rc_map_dvico_portable_table,
1457 .rc_key_map_size = ARRAY_SIZE(ir_codes_dvico_portable_table), 1457 .rc_map_size = ARRAY_SIZE(rc_map_dvico_portable_table),
1458 .rc_query = cxusb_rc_query, 1458 .rc_query = cxusb_rc_query,
1459 }, 1459 },
1460 1460
@@ -1506,8 +1506,8 @@ static struct dvb_usb_device_properties cxusb_bluebird_dee1601_properties = {
1506 1506
1507 .rc.legacy = { 1507 .rc.legacy = {
1508 .rc_interval = 150, 1508 .rc_interval = 150,
1509 .rc_key_map = ir_codes_dvico_mce_table, 1509 .rc_map_table = rc_map_dvico_mce_table,
1510 .rc_key_map_size = ARRAY_SIZE(ir_codes_dvico_mce_table), 1510 .rc_map_size = ARRAY_SIZE(rc_map_dvico_mce_table),
1511 .rc_query = cxusb_rc_query, 1511 .rc_query = cxusb_rc_query,
1512 }, 1512 },
1513 1513
@@ -1567,8 +1567,8 @@ static struct dvb_usb_device_properties cxusb_bluebird_lgz201_properties = {
1567 1567
1568 .rc.legacy = { 1568 .rc.legacy = {
1569 .rc_interval = 100, 1569 .rc_interval = 100,
1570 .rc_key_map = ir_codes_dvico_portable_table, 1570 .rc_map_table = rc_map_dvico_portable_table,
1571 .rc_key_map_size = ARRAY_SIZE(ir_codes_dvico_portable_table), 1571 .rc_map_size = ARRAY_SIZE(rc_map_dvico_portable_table),
1572 .rc_query = cxusb_rc_query, 1572 .rc_query = cxusb_rc_query,
1573 }, 1573 },
1574 1574
@@ -1619,8 +1619,8 @@ static struct dvb_usb_device_properties cxusb_bluebird_dtt7579_properties = {
1619 1619
1620 .rc.legacy = { 1620 .rc.legacy = {
1621 .rc_interval = 100, 1621 .rc_interval = 100,
1622 .rc_key_map = ir_codes_dvico_portable_table, 1622 .rc_map_table = rc_map_dvico_portable_table,
1623 .rc_key_map_size = ARRAY_SIZE(ir_codes_dvico_portable_table), 1623 .rc_map_size = ARRAY_SIZE(rc_map_dvico_portable_table),
1624 .rc_query = cxusb_rc_query, 1624 .rc_query = cxusb_rc_query,
1625 }, 1625 },
1626 1626
@@ -1670,8 +1670,8 @@ static struct dvb_usb_device_properties cxusb_bluebird_dualdig4_properties = {
1670 1670
1671 .rc.legacy = { 1671 .rc.legacy = {
1672 .rc_interval = 100, 1672 .rc_interval = 100,
1673 .rc_key_map = ir_codes_dvico_mce_table, 1673 .rc_map_table = rc_map_dvico_mce_table,
1674 .rc_key_map_size = ARRAY_SIZE(ir_codes_dvico_mce_table), 1674 .rc_map_size = ARRAY_SIZE(rc_map_dvico_mce_table),
1675 .rc_query = cxusb_bluebird2_rc_query, 1675 .rc_query = cxusb_bluebird2_rc_query,
1676 }, 1676 },
1677 1677
@@ -1720,8 +1720,8 @@ static struct dvb_usb_device_properties cxusb_bluebird_nano2_properties = {
1720 1720
1721 .rc.legacy = { 1721 .rc.legacy = {
1722 .rc_interval = 100, 1722 .rc_interval = 100,
1723 .rc_key_map = ir_codes_dvico_portable_table, 1723 .rc_map_table = rc_map_dvico_portable_table,
1724 .rc_key_map_size = ARRAY_SIZE(ir_codes_dvico_portable_table), 1724 .rc_map_size = ARRAY_SIZE(rc_map_dvico_portable_table),
1725 .rc_query = cxusb_bluebird2_rc_query, 1725 .rc_query = cxusb_bluebird2_rc_query,
1726 }, 1726 },
1727 1727
@@ -1772,8 +1772,8 @@ static struct dvb_usb_device_properties cxusb_bluebird_nano2_needsfirmware_prope
1772 1772
1773 .rc.legacy = { 1773 .rc.legacy = {
1774 .rc_interval = 100, 1774 .rc_interval = 100,
1775 .rc_key_map = ir_codes_dvico_portable_table, 1775 .rc_map_table = rc_map_dvico_portable_table,
1776 .rc_key_map_size = ARRAY_SIZE(ir_codes_dvico_portable_table), 1776 .rc_map_size = ARRAY_SIZE(rc_map_dvico_portable_table),
1777 .rc_query = cxusb_rc_query, 1777 .rc_query = cxusb_rc_query,
1778 }, 1778 },
1779 1779
@@ -1865,8 +1865,8 @@ struct dvb_usb_device_properties cxusb_bluebird_dualdig4_rev2_properties = {
1865 1865
1866 .rc.legacy = { 1866 .rc.legacy = {
1867 .rc_interval = 100, 1867 .rc_interval = 100,
1868 .rc_key_map = ir_codes_dvico_mce_table, 1868 .rc_map_table = rc_map_dvico_mce_table,
1869 .rc_key_map_size = ARRAY_SIZE(ir_codes_dvico_mce_table), 1869 .rc_map_size = ARRAY_SIZE(rc_map_dvico_mce_table),
1870 .rc_query = cxusb_rc_query, 1870 .rc_query = cxusb_rc_query,
1871 }, 1871 },
1872 1872
@@ -1915,8 +1915,8 @@ static struct dvb_usb_device_properties cxusb_d680_dmb_properties = {
1915 1915
1916 .rc.legacy = { 1916 .rc.legacy = {
1917 .rc_interval = 100, 1917 .rc_interval = 100,
1918 .rc_key_map = ir_codes_d680_dmb_table, 1918 .rc_map_table = rc_map_d680_dmb_table,
1919 .rc_key_map_size = ARRAY_SIZE(ir_codes_d680_dmb_table), 1919 .rc_map_size = ARRAY_SIZE(rc_map_d680_dmb_table),
1920 .rc_query = cxusb_d680_dmb_rc_query, 1920 .rc_query = cxusb_d680_dmb_rc_query,
1921 }, 1921 },
1922 1922
@@ -1966,8 +1966,8 @@ static struct dvb_usb_device_properties cxusb_mygica_d689_properties = {
1966 1966
1967 .rc.legacy = { 1967 .rc.legacy = {
1968 .rc_interval = 100, 1968 .rc_interval = 100,
1969 .rc_key_map = ir_codes_d680_dmb_table, 1969 .rc_map_table = rc_map_d680_dmb_table,
1970 .rc_key_map_size = ARRAY_SIZE(ir_codes_d680_dmb_table), 1970 .rc_map_size = ARRAY_SIZE(rc_map_d680_dmb_table),
1971 .rc_query = cxusb_d680_dmb_rc_query, 1971 .rc_query = cxusb_d680_dmb_rc_query,
1972 }, 1972 },
1973 1973
diff --git a/drivers/media/dvb/dvb-usb/dib0700.h b/drivers/media/dvb/dvb-usb/dib0700.h
index c2c9d236ec7e..3537d65c04bc 100644
--- a/drivers/media/dvb/dvb-usb/dib0700.h
+++ b/drivers/media/dvb/dvb-usb/dib0700.h
@@ -60,7 +60,7 @@ extern int dib0700_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff);
60extern struct i2c_algorithm dib0700_i2c_algo; 60extern struct i2c_algorithm dib0700_i2c_algo;
61extern int dib0700_identify_state(struct usb_device *udev, struct dvb_usb_device_properties *props, 61extern int dib0700_identify_state(struct usb_device *udev, struct dvb_usb_device_properties *props,
62 struct dvb_usb_device_description **desc, int *cold); 62 struct dvb_usb_device_description **desc, int *cold);
63extern int dib0700_change_protocol(void *priv, u64 ir_type); 63extern int dib0700_change_protocol(struct rc_dev *dev, u64 rc_type);
64 64
65extern int dib0700_device_count; 65extern int dib0700_device_count;
66extern int dvb_usb_dib0700_ir_proto; 66extern int dvb_usb_dib0700_ir_proto;
diff --git a/drivers/media/dvb/dvb-usb/dib0700_core.c b/drivers/media/dvb/dvb-usb/dib0700_core.c
index 48397f103d32..8ca48f76dfa9 100644
--- a/drivers/media/dvb/dvb-usb/dib0700_core.c
+++ b/drivers/media/dvb/dvb-usb/dib0700_core.c
@@ -471,19 +471,19 @@ int dib0700_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
471 return dib0700_ctrl_wr(adap->dev, b, 4); 471 return dib0700_ctrl_wr(adap->dev, b, 4);
472} 472}
473 473
474int dib0700_change_protocol(void *priv, u64 ir_type) 474int dib0700_change_protocol(struct rc_dev *rc, u64 rc_type)
475{ 475{
476 struct dvb_usb_device *d = priv; 476 struct dvb_usb_device *d = rc->priv;
477 struct dib0700_state *st = d->priv; 477 struct dib0700_state *st = d->priv;
478 u8 rc_setup[3] = { REQUEST_SET_RC, 0, 0 }; 478 u8 rc_setup[3] = { REQUEST_SET_RC, 0, 0 };
479 int new_proto, ret; 479 int new_proto, ret;
480 480
481 /* Set the IR mode */ 481 /* Set the IR mode */
482 if (ir_type == IR_TYPE_RC5) 482 if (rc_type == RC_TYPE_RC5)
483 new_proto = 1; 483 new_proto = 1;
484 else if (ir_type == IR_TYPE_NEC) 484 else if (rc_type == RC_TYPE_NEC)
485 new_proto = 0; 485 new_proto = 0;
486 else if (ir_type == IR_TYPE_RC6) { 486 else if (rc_type == RC_TYPE_RC6) {
487 if (st->fw_version < 0x10200) 487 if (st->fw_version < 0x10200)
488 return -EINVAL; 488 return -EINVAL;
489 489
@@ -499,7 +499,7 @@ int dib0700_change_protocol(void *priv, u64 ir_type)
499 return ret; 499 return ret;
500 } 500 }
501 501
502 d->props.rc.core.protocol = ir_type; 502 d->props.rc.core.protocol = rc_type;
503 503
504 return ret; 504 return ret;
505} 505}
@@ -535,7 +535,7 @@ static void dib0700_rc_urb_completion(struct urb *purb)
535 if (d == NULL) 535 if (d == NULL)
536 return; 536 return;
537 537
538 if (d->rc_input_dev == NULL) { 538 if (d->rc_dev == NULL) {
539 /* This will occur if disable_rc_polling=1 */ 539 /* This will occur if disable_rc_polling=1 */
540 usb_free_urb(purb); 540 usb_free_urb(purb);
541 return; 541 return;
@@ -562,7 +562,7 @@ static void dib0700_rc_urb_completion(struct urb *purb)
562 purb->actual_length); 562 purb->actual_length);
563 563
564 switch (d->props.rc.core.protocol) { 564 switch (d->props.rc.core.protocol) {
565 case IR_TYPE_NEC: 565 case RC_TYPE_NEC:
566 toggle = 0; 566 toggle = 0;
567 567
568 /* NEC protocol sends repeat code as 0 0 0 FF */ 568 /* NEC protocol sends repeat code as 0 0 0 FF */
@@ -600,7 +600,7 @@ static void dib0700_rc_urb_completion(struct urb *purb)
600 goto resubmit; 600 goto resubmit;
601 } 601 }
602 602
603 ir_keydown(d->rc_input_dev, keycode, toggle); 603 rc_keydown(d->rc_dev, keycode, toggle);
604 604
605resubmit: 605resubmit:
606 /* Clean the buffer before we requeue */ 606 /* Clean the buffer before we requeue */
diff --git a/drivers/media/dvb/dvb-usb/dib0700_devices.c b/drivers/media/dvb/dvb-usb/dib0700_devices.c
index e06acd1fecb6..defd83964ce2 100644
--- a/drivers/media/dvb/dvb-usb/dib0700_devices.c
+++ b/drivers/media/dvb/dvb-usb/dib0700_devices.c
@@ -510,7 +510,7 @@ static int dib0700_rc_query_old_firmware(struct dvb_usb_device *d)
510 510
511 d->last_event = 0; 511 d->last_event = 0;
512 switch (d->props.rc.core.protocol) { 512 switch (d->props.rc.core.protocol) {
513 case IR_TYPE_NEC: 513 case RC_TYPE_NEC:
514 /* NEC protocol sends repeat code as 0 0 0 FF */ 514 /* NEC protocol sends repeat code as 0 0 0 FF */
515 if ((key[3-2] == 0x00) && (key[3-3] == 0x00) && 515 if ((key[3-2] == 0x00) && (key[3-3] == 0x00) &&
516 (key[3] == 0xff)) 516 (key[3] == 0xff))
@@ -520,13 +520,13 @@ static int dib0700_rc_query_old_firmware(struct dvb_usb_device *d)
520 d->last_event = keycode; 520 d->last_event = keycode;
521 } 521 }
522 522
523 ir_keydown(d->rc_input_dev, keycode, 0); 523 rc_keydown(d->rc_dev, keycode, 0);
524 break; 524 break;
525 default: 525 default:
526 /* RC-5 protocol changes toggle bit on new keypress */ 526 /* RC-5 protocol changes toggle bit on new keypress */
527 keycode = key[3-2] << 8 | key[3-3]; 527 keycode = key[3-2] << 8 | key[3-3];
528 toggle = key[3-1]; 528 toggle = key[3-1];
529 ir_keydown(d->rc_input_dev, keycode, toggle); 529 rc_keydown(d->rc_dev, keycode, toggle);
530 530
531 break; 531 break;
532 } 532 }
@@ -1924,12 +1924,10 @@ struct dvb_usb_device_properties dib0700_devices[] = {
1924 .rc_interval = DEFAULT_RC_INTERVAL, 1924 .rc_interval = DEFAULT_RC_INTERVAL,
1925 .rc_codes = RC_MAP_DIB0700_RC5_TABLE, 1925 .rc_codes = RC_MAP_DIB0700_RC5_TABLE,
1926 .rc_query = dib0700_rc_query_old_firmware, 1926 .rc_query = dib0700_rc_query_old_firmware,
1927 .rc_props = { 1927 .allowed_protos = RC_TYPE_RC5 |
1928 .allowed_protos = IR_TYPE_RC5 | 1928 RC_TYPE_RC6 |
1929 IR_TYPE_RC6 | 1929 RC_TYPE_NEC,
1930 IR_TYPE_NEC, 1930 .change_protocol = dib0700_change_protocol,
1931 .change_protocol = dib0700_change_protocol,
1932 },
1933 }, 1931 },
1934 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES, 1932 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
1935 1933
@@ -1960,12 +1958,10 @@ struct dvb_usb_device_properties dib0700_devices[] = {
1960 .rc_interval = DEFAULT_RC_INTERVAL, 1958 .rc_interval = DEFAULT_RC_INTERVAL,
1961 .rc_codes = RC_MAP_DIB0700_RC5_TABLE, 1959 .rc_codes = RC_MAP_DIB0700_RC5_TABLE,
1962 .rc_query = dib0700_rc_query_old_firmware, 1960 .rc_query = dib0700_rc_query_old_firmware,
1963 .rc_props = { 1961 .allowed_protos = RC_TYPE_RC5 |
1964 .allowed_protos = IR_TYPE_RC5 | 1962 RC_TYPE_RC6 |
1965 IR_TYPE_RC6 | 1963 RC_TYPE_NEC,
1966 IR_TYPE_NEC, 1964 .change_protocol = dib0700_change_protocol,
1967 .change_protocol = dib0700_change_protocol,
1968 },
1969 }, 1965 },
1970 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES, 1966 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
1971 1967
@@ -2021,12 +2017,10 @@ struct dvb_usb_device_properties dib0700_devices[] = {
2021 .rc_interval = DEFAULT_RC_INTERVAL, 2017 .rc_interval = DEFAULT_RC_INTERVAL,
2022 .rc_codes = RC_MAP_DIB0700_RC5_TABLE, 2018 .rc_codes = RC_MAP_DIB0700_RC5_TABLE,
2023 .rc_query = dib0700_rc_query_old_firmware, 2019 .rc_query = dib0700_rc_query_old_firmware,
2024 .rc_props = { 2020 .allowed_protos = RC_TYPE_RC5 |
2025 .allowed_protos = IR_TYPE_RC5 | 2021 RC_TYPE_RC6 |
2026 IR_TYPE_RC6 | 2022 RC_TYPE_NEC,
2027 IR_TYPE_NEC, 2023 .change_protocol = dib0700_change_protocol,
2028 .change_protocol = dib0700_change_protocol,
2029 },
2030 }, 2024 },
2031 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES, 2025 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
2032 2026
@@ -2065,12 +2059,10 @@ struct dvb_usb_device_properties dib0700_devices[] = {
2065 .rc_codes = RC_MAP_DIB0700_RC5_TABLE, 2059 .rc_codes = RC_MAP_DIB0700_RC5_TABLE,
2066 .module_name = "dib0700", 2060 .module_name = "dib0700",
2067 .rc_query = dib0700_rc_query_old_firmware, 2061 .rc_query = dib0700_rc_query_old_firmware,
2068 .rc_props = { 2062 .allowed_protos = RC_TYPE_RC5 |
2069 .allowed_protos = IR_TYPE_RC5 | 2063 RC_TYPE_RC6 |
2070 IR_TYPE_RC6 | 2064 RC_TYPE_NEC,
2071 IR_TYPE_NEC, 2065 .change_protocol = dib0700_change_protocol,
2072 .change_protocol = dib0700_change_protocol,
2073 },
2074 }, 2066 },
2075 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES, 2067 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
2076 2068
@@ -2143,12 +2135,10 @@ struct dvb_usb_device_properties dib0700_devices[] = {
2143 .rc_codes = RC_MAP_DIB0700_RC5_TABLE, 2135 .rc_codes = RC_MAP_DIB0700_RC5_TABLE,
2144 .module_name = "dib0700", 2136 .module_name = "dib0700",
2145 .rc_query = dib0700_rc_query_old_firmware, 2137 .rc_query = dib0700_rc_query_old_firmware,
2146 .rc_props = { 2138 .allowed_protos = RC_TYPE_RC5 |
2147 .allowed_protos = IR_TYPE_RC5 | 2139 RC_TYPE_RC6 |
2148 IR_TYPE_RC6 | 2140 RC_TYPE_NEC,
2149 IR_TYPE_NEC, 2141 .change_protocol = dib0700_change_protocol,
2150 .change_protocol = dib0700_change_protocol,
2151 },
2152 }, 2142 },
2153 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES, 2143 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
2154 2144
@@ -2189,12 +2179,10 @@ struct dvb_usb_device_properties dib0700_devices[] = {
2189 .rc_codes = RC_MAP_DIB0700_RC5_TABLE, 2179 .rc_codes = RC_MAP_DIB0700_RC5_TABLE,
2190 .module_name = "dib0700", 2180 .module_name = "dib0700",
2191 .rc_query = dib0700_rc_query_old_firmware, 2181 .rc_query = dib0700_rc_query_old_firmware,
2192 .rc_props = { 2182 .allowed_protos = RC_TYPE_RC5 |
2193 .allowed_protos = IR_TYPE_RC5 | 2183 RC_TYPE_RC6 |
2194 IR_TYPE_RC6 | 2184 RC_TYPE_NEC,
2195 IR_TYPE_NEC, 2185 .change_protocol = dib0700_change_protocol,
2196 .change_protocol = dib0700_change_protocol,
2197 },
2198 }, 2186 },
2199 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES, 2187 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
2200 2188
@@ -2259,12 +2247,10 @@ struct dvb_usb_device_properties dib0700_devices[] = {
2259 .rc_codes = RC_MAP_DIB0700_RC5_TABLE, 2247 .rc_codes = RC_MAP_DIB0700_RC5_TABLE,
2260 .module_name = "dib0700", 2248 .module_name = "dib0700",
2261 .rc_query = dib0700_rc_query_old_firmware, 2249 .rc_query = dib0700_rc_query_old_firmware,
2262 .rc_props = { 2250 .allowed_protos = RC_TYPE_RC5 |
2263 .allowed_protos = IR_TYPE_RC5 | 2251 RC_TYPE_RC6 |
2264 IR_TYPE_RC6 | 2252 RC_TYPE_NEC,
2265 IR_TYPE_NEC, 2253 .change_protocol = dib0700_change_protocol,
2266 .change_protocol = dib0700_change_protocol,
2267 },
2268 }, 2254 },
2269 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES, 2255 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
2270 2256
@@ -2308,12 +2294,10 @@ struct dvb_usb_device_properties dib0700_devices[] = {
2308 .rc_codes = RC_MAP_DIB0700_NEC_TABLE, 2294 .rc_codes = RC_MAP_DIB0700_NEC_TABLE,
2309 .module_name = "dib0700", 2295 .module_name = "dib0700",
2310 .rc_query = dib0700_rc_query_old_firmware, 2296 .rc_query = dib0700_rc_query_old_firmware,
2311 .rc_props = { 2297 .allowed_protos = RC_TYPE_RC5 |
2312 .allowed_protos = IR_TYPE_RC5 | 2298 RC_TYPE_RC6 |
2313 IR_TYPE_RC6 | 2299 RC_TYPE_NEC,
2314 IR_TYPE_NEC, 2300 .change_protocol = dib0700_change_protocol,
2315 .change_protocol = dib0700_change_protocol,
2316 },
2317 }, 2301 },
2318 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES, 2302 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
2319 2303
@@ -2379,12 +2363,10 @@ struct dvb_usb_device_properties dib0700_devices[] = {
2379 .rc_codes = RC_MAP_DIB0700_RC5_TABLE, 2363 .rc_codes = RC_MAP_DIB0700_RC5_TABLE,
2380 .module_name = "dib0700", 2364 .module_name = "dib0700",
2381 .rc_query = dib0700_rc_query_old_firmware, 2365 .rc_query = dib0700_rc_query_old_firmware,
2382 .rc_props = { 2366 .allowed_protos = RC_TYPE_RC5 |
2383 .allowed_protos = IR_TYPE_RC5 | 2367 RC_TYPE_RC6 |
2384 IR_TYPE_RC6 | 2368 RC_TYPE_NEC,
2385 IR_TYPE_NEC, 2369 .change_protocol = dib0700_change_protocol,
2386 .change_protocol = dib0700_change_protocol,
2387 },
2388 }, 2370 },
2389 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES, 2371 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
2390 .num_adapters = 1, 2372 .num_adapters = 1,
@@ -2417,12 +2399,10 @@ struct dvb_usb_device_properties dib0700_devices[] = {
2417 .rc_codes = RC_MAP_DIB0700_RC5_TABLE, 2399 .rc_codes = RC_MAP_DIB0700_RC5_TABLE,
2418 .module_name = "dib0700", 2400 .module_name = "dib0700",
2419 .rc_query = dib0700_rc_query_old_firmware, 2401 .rc_query = dib0700_rc_query_old_firmware,
2420 .rc_props = { 2402 .allowed_protos = RC_TYPE_RC5 |
2421 .allowed_protos = IR_TYPE_RC5 | 2403 RC_TYPE_RC6 |
2422 IR_TYPE_RC6 | 2404 RC_TYPE_NEC,
2423 IR_TYPE_NEC, 2405 .change_protocol = dib0700_change_protocol,
2424 .change_protocol = dib0700_change_protocol,
2425 },
2426 }, 2406 },
2427 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES, 2407 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
2428 .num_adapters = 1, 2408 .num_adapters = 1,
@@ -2487,12 +2467,10 @@ struct dvb_usb_device_properties dib0700_devices[] = {
2487 .rc_codes = RC_MAP_DIB0700_RC5_TABLE, 2467 .rc_codes = RC_MAP_DIB0700_RC5_TABLE,
2488 .module_name = "dib0700", 2468 .module_name = "dib0700",
2489 .rc_query = dib0700_rc_query_old_firmware, 2469 .rc_query = dib0700_rc_query_old_firmware,
2490 .rc_props = { 2470 .allowed_protos = RC_TYPE_RC5 |
2491 .allowed_protos = IR_TYPE_RC5 | 2471 RC_TYPE_RC6 |
2492 IR_TYPE_RC6 | 2472 RC_TYPE_NEC,
2493 IR_TYPE_NEC, 2473 .change_protocol = dib0700_change_protocol,
2494 .change_protocol = dib0700_change_protocol,
2495 },
2496 }, 2474 },
2497 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES, 2475 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
2498 .num_adapters = 1, 2476 .num_adapters = 1,
@@ -2533,12 +2511,10 @@ struct dvb_usb_device_properties dib0700_devices[] = {
2533 .rc_codes = RC_MAP_DIB0700_NEC_TABLE, 2511 .rc_codes = RC_MAP_DIB0700_NEC_TABLE,
2534 .module_name = "dib0700", 2512 .module_name = "dib0700",
2535 .rc_query = dib0700_rc_query_old_firmware, 2513 .rc_query = dib0700_rc_query_old_firmware,
2536 .rc_props = { 2514 .allowed_protos = RC_TYPE_RC5 |
2537 .allowed_protos = IR_TYPE_RC5 | 2515 RC_TYPE_RC6 |
2538 IR_TYPE_RC6 | 2516 RC_TYPE_NEC,
2539 IR_TYPE_NEC, 2517 .change_protocol = dib0700_change_protocol,
2540 .change_protocol = dib0700_change_protocol,
2541 },
2542 }, 2518 },
2543 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES, 2519 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
2544 .num_adapters = 2, 2520 .num_adapters = 2,
@@ -2584,12 +2560,10 @@ struct dvb_usb_device_properties dib0700_devices[] = {
2584 .rc_codes = RC_MAP_DIB0700_RC5_TABLE, 2560 .rc_codes = RC_MAP_DIB0700_RC5_TABLE,
2585 .module_name = "dib0700", 2561 .module_name = "dib0700",
2586 .rc_query = dib0700_rc_query_old_firmware, 2562 .rc_query = dib0700_rc_query_old_firmware,
2587 .rc_props = { 2563 .allowed_protos = RC_TYPE_RC5 |
2588 .allowed_protos = IR_TYPE_RC5 | 2564 RC_TYPE_RC6 |
2589 IR_TYPE_RC6 | 2565 RC_TYPE_NEC,
2590 IR_TYPE_NEC, 2566 .change_protocol = dib0700_change_protocol,
2591 .change_protocol = dib0700_change_protocol,
2592 },
2593 }, 2567 },
2594 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES, 2568 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
2595 .num_adapters = 1, 2569 .num_adapters = 1,
@@ -2623,12 +2597,10 @@ struct dvb_usb_device_properties dib0700_devices[] = {
2623 .rc_codes = RC_MAP_DIB0700_RC5_TABLE, 2597 .rc_codes = RC_MAP_DIB0700_RC5_TABLE,
2624 .module_name = "dib0700", 2598 .module_name = "dib0700",
2625 .rc_query = dib0700_rc_query_old_firmware, 2599 .rc_query = dib0700_rc_query_old_firmware,
2626 .rc_props = { 2600 .allowed_protos = RC_TYPE_RC5 |
2627 .allowed_protos = IR_TYPE_RC5 | 2601 RC_TYPE_RC6 |
2628 IR_TYPE_RC6 | 2602 RC_TYPE_NEC,
2629 IR_TYPE_NEC, 2603 .change_protocol = dib0700_change_protocol,
2630 .change_protocol = dib0700_change_protocol,
2631 },
2632 }, 2604 },
2633 }, 2605 },
2634}; 2606};
diff --git a/drivers/media/dvb/dvb-usb/dibusb-common.c b/drivers/media/dvb/dvb-usb/dibusb-common.c
index ba991aa21aff..956f7ae2e510 100644
--- a/drivers/media/dvb/dvb-usb/dibusb-common.c
+++ b/drivers/media/dvb/dvb-usb/dibusb-common.c
@@ -327,7 +327,7 @@ EXPORT_SYMBOL(dibusb_dib3000mc_tuner_attach);
327/* 327/*
328 * common remote control stuff 328 * common remote control stuff
329 */ 329 */
330struct ir_scancode ir_codes_dibusb_table[] = { 330struct rc_map_table rc_map_dibusb_table[] = {
331 /* Key codes for the little Artec T1/Twinhan/HAMA/ remote. */ 331 /* Key codes for the little Artec T1/Twinhan/HAMA/ remote. */
332 { 0x0016, KEY_POWER }, 332 { 0x0016, KEY_POWER },
333 { 0x0010, KEY_MUTE }, 333 { 0x0010, KEY_MUTE },
@@ -456,7 +456,7 @@ struct ir_scancode ir_codes_dibusb_table[] = {
456 { 0x804e, KEY_ENTER }, 456 { 0x804e, KEY_ENTER },
457 { 0x804f, KEY_VOLUMEDOWN }, 457 { 0x804f, KEY_VOLUMEDOWN },
458}; 458};
459EXPORT_SYMBOL(ir_codes_dibusb_table); 459EXPORT_SYMBOL(rc_map_dibusb_table);
460 460
461int dibusb_rc_query(struct dvb_usb_device *d, u32 *event, int *state) 461int dibusb_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
462{ 462{
diff --git a/drivers/media/dvb/dvb-usb/dibusb-mb.c b/drivers/media/dvb/dvb-usb/dibusb-mb.c
index 8e3c0d2cce16..04d91bdd3562 100644
--- a/drivers/media/dvb/dvb-usb/dibusb-mb.c
+++ b/drivers/media/dvb/dvb-usb/dibusb-mb.c
@@ -213,8 +213,8 @@ static struct dvb_usb_device_properties dibusb1_1_properties = {
213 213
214 .rc.legacy = { 214 .rc.legacy = {
215 .rc_interval = DEFAULT_RC_INTERVAL, 215 .rc_interval = DEFAULT_RC_INTERVAL,
216 .rc_key_map = ir_codes_dibusb_table, 216 .rc_map_table = rc_map_dibusb_table,
217 .rc_key_map_size = 111, /* wow, that is ugly ... I want to load it to the driver dynamically */ 217 .rc_map_size = 111, /* wow, that is ugly ... I want to load it to the driver dynamically */
218 .rc_query = dibusb_rc_query, 218 .rc_query = dibusb_rc_query,
219 }, 219 },
220 220
@@ -299,8 +299,8 @@ static struct dvb_usb_device_properties dibusb1_1_an2235_properties = {
299 299
300 .rc.legacy = { 300 .rc.legacy = {
301 .rc_interval = DEFAULT_RC_INTERVAL, 301 .rc_interval = DEFAULT_RC_INTERVAL,
302 .rc_key_map = ir_codes_dibusb_table, 302 .rc_map_table = rc_map_dibusb_table,
303 .rc_key_map_size = 111, /* wow, that is ugly ... I want to load it to the driver dynamically */ 303 .rc_map_size = 111, /* wow, that is ugly ... I want to load it to the driver dynamically */
304 .rc_query = dibusb_rc_query, 304 .rc_query = dibusb_rc_query,
305 }, 305 },
306 306
@@ -365,8 +365,8 @@ static struct dvb_usb_device_properties dibusb2_0b_properties = {
365 365
366 .rc.legacy = { 366 .rc.legacy = {
367 .rc_interval = DEFAULT_RC_INTERVAL, 367 .rc_interval = DEFAULT_RC_INTERVAL,
368 .rc_key_map = ir_codes_dibusb_table, 368 .rc_map_table = rc_map_dibusb_table,
369 .rc_key_map_size = 111, /* wow, that is ugly ... I want to load it to the driver dynamically */ 369 .rc_map_size = 111, /* wow, that is ugly ... I want to load it to the driver dynamically */
370 .rc_query = dibusb_rc_query, 370 .rc_query = dibusb_rc_query,
371 }, 371 },
372 372
@@ -424,8 +424,8 @@ static struct dvb_usb_device_properties artec_t1_usb2_properties = {
424 424
425 .rc.legacy = { 425 .rc.legacy = {
426 .rc_interval = DEFAULT_RC_INTERVAL, 426 .rc_interval = DEFAULT_RC_INTERVAL,
427 .rc_key_map = ir_codes_dibusb_table, 427 .rc_map_table = rc_map_dibusb_table,
428 .rc_key_map_size = 111, /* wow, that is ugly ... I want to load it to the driver dynamically */ 428 .rc_map_size = 111, /* wow, that is ugly ... I want to load it to the driver dynamically */
429 .rc_query = dibusb_rc_query, 429 .rc_query = dibusb_rc_query,
430 }, 430 },
431 431
diff --git a/drivers/media/dvb/dvb-usb/dibusb-mc.c b/drivers/media/dvb/dvb-usb/dibusb-mc.c
index 1cbc41cb4e8f..c1d9094b61e5 100644
--- a/drivers/media/dvb/dvb-usb/dibusb-mc.c
+++ b/drivers/media/dvb/dvb-usb/dibusb-mc.c
@@ -83,8 +83,8 @@ static struct dvb_usb_device_properties dibusb_mc_properties = {
83 83
84 .rc.legacy = { 84 .rc.legacy = {
85 .rc_interval = DEFAULT_RC_INTERVAL, 85 .rc_interval = DEFAULT_RC_INTERVAL,
86 .rc_key_map = ir_codes_dibusb_table, 86 .rc_map_table = rc_map_dibusb_table,
87 .rc_key_map_size = 111, /* FIXME */ 87 .rc_map_size = 111, /* FIXME */
88 .rc_query = dibusb_rc_query, 88 .rc_query = dibusb_rc_query,
89 }, 89 },
90 90
diff --git a/drivers/media/dvb/dvb-usb/dibusb.h b/drivers/media/dvb/dvb-usb/dibusb.h
index 61a6bf389472..e47c321b3ffc 100644
--- a/drivers/media/dvb/dvb-usb/dibusb.h
+++ b/drivers/media/dvb/dvb-usb/dibusb.h
@@ -124,7 +124,7 @@ extern int dibusb2_0_power_ctrl(struct dvb_usb_device *, int);
124#define DEFAULT_RC_INTERVAL 150 124#define DEFAULT_RC_INTERVAL 150
125//#define DEFAULT_RC_INTERVAL 100000 125//#define DEFAULT_RC_INTERVAL 100000
126 126
127extern struct ir_scancode ir_codes_dibusb_table[]; 127extern struct rc_map_table rc_map_dibusb_table[];
128extern int dibusb_rc_query(struct dvb_usb_device *, u32 *, int *); 128extern int dibusb_rc_query(struct dvb_usb_device *, u32 *, int *);
129extern int dibusb_read_eeprom_byte(struct dvb_usb_device *, u8, u8 *); 129extern int dibusb_read_eeprom_byte(struct dvb_usb_device *, u8, u8 *);
130 130
diff --git a/drivers/media/dvb/dvb-usb/digitv.c b/drivers/media/dvb/dvb-usb/digitv.c
index 13d006bb19db..f2dbce7edb3b 100644
--- a/drivers/media/dvb/dvb-usb/digitv.c
+++ b/drivers/media/dvb/dvb-usb/digitv.c
@@ -161,7 +161,7 @@ static int digitv_tuner_attach(struct dvb_usb_adapter *adap)
161 return 0; 161 return 0;
162} 162}
163 163
164static struct ir_scancode ir_codes_digitv_table[] = { 164static struct rc_map_table rc_map_digitv_table[] = {
165 { 0x5f55, KEY_0 }, 165 { 0x5f55, KEY_0 },
166 { 0x6f55, KEY_1 }, 166 { 0x6f55, KEY_1 },
167 { 0x9f55, KEY_2 }, 167 { 0x9f55, KEY_2 },
@@ -237,10 +237,10 @@ static int digitv_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
237 /* if something is inside the buffer, simulate key press */ 237 /* if something is inside the buffer, simulate key press */
238 if (key[1] != 0) 238 if (key[1] != 0)
239 { 239 {
240 for (i = 0; i < d->props.rc.legacy.rc_key_map_size; i++) { 240 for (i = 0; i < d->props.rc.legacy.rc_map_size; i++) {
241 if (rc5_custom(&d->props.rc.legacy.rc_key_map[i]) == key[1] && 241 if (rc5_custom(&d->props.rc.legacy.rc_map_table[i]) == key[1] &&
242 rc5_data(&d->props.rc.legacy.rc_key_map[i]) == key[2]) { 242 rc5_data(&d->props.rc.legacy.rc_map_table[i]) == key[2]) {
243 *event = d->props.rc.legacy.rc_key_map[i].keycode; 243 *event = d->props.rc.legacy.rc_map_table[i].keycode;
244 *state = REMOTE_KEY_PRESSED; 244 *state = REMOTE_KEY_PRESSED;
245 return 0; 245 return 0;
246 } 246 }
@@ -312,8 +312,8 @@ static struct dvb_usb_device_properties digitv_properties = {
312 312
313 .rc.legacy = { 313 .rc.legacy = {
314 .rc_interval = 1000, 314 .rc_interval = 1000,
315 .rc_key_map = ir_codes_digitv_table, 315 .rc_map_table = rc_map_digitv_table,
316 .rc_key_map_size = ARRAY_SIZE(ir_codes_digitv_table), 316 .rc_map_size = ARRAY_SIZE(rc_map_digitv_table),
317 .rc_query = digitv_rc_query, 317 .rc_query = digitv_rc_query,
318 }, 318 },
319 319
diff --git a/drivers/media/dvb/dvb-usb/dtt200u.c b/drivers/media/dvb/dvb-usb/dtt200u.c
index ca495e07f35c..ecd86eca2548 100644
--- a/drivers/media/dvb/dvb-usb/dtt200u.c
+++ b/drivers/media/dvb/dvb-usb/dtt200u.c
@@ -57,7 +57,7 @@ static int dtt200u_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid,
57 57
58/* remote control */ 58/* remote control */
59/* key list for the tiny remote control (Yakumo, don't know about the others) */ 59/* key list for the tiny remote control (Yakumo, don't know about the others) */
60static struct ir_scancode ir_codes_dtt200u_table[] = { 60static struct rc_map_table rc_map_dtt200u_table[] = {
61 { 0x8001, KEY_MUTE }, 61 { 0x8001, KEY_MUTE },
62 { 0x8002, KEY_CHANNELDOWN }, 62 { 0x8002, KEY_CHANNELDOWN },
63 { 0x8003, KEY_VOLUMEDOWN }, 63 { 0x8003, KEY_VOLUMEDOWN },
@@ -163,8 +163,8 @@ static struct dvb_usb_device_properties dtt200u_properties = {
163 163
164 .rc.legacy = { 164 .rc.legacy = {
165 .rc_interval = 300, 165 .rc_interval = 300,
166 .rc_key_map = ir_codes_dtt200u_table, 166 .rc_map_table = rc_map_dtt200u_table,
167 .rc_key_map_size = ARRAY_SIZE(ir_codes_dtt200u_table), 167 .rc_map_size = ARRAY_SIZE(rc_map_dtt200u_table),
168 .rc_query = dtt200u_rc_query, 168 .rc_query = dtt200u_rc_query,
169 }, 169 },
170 170
@@ -210,8 +210,8 @@ static struct dvb_usb_device_properties wt220u_properties = {
210 210
211 .rc.legacy = { 211 .rc.legacy = {
212 .rc_interval = 300, 212 .rc_interval = 300,
213 .rc_key_map = ir_codes_dtt200u_table, 213 .rc_map_table = rc_map_dtt200u_table,
214 .rc_key_map_size = ARRAY_SIZE(ir_codes_dtt200u_table), 214 .rc_map_size = ARRAY_SIZE(rc_map_dtt200u_table),
215 .rc_query = dtt200u_rc_query, 215 .rc_query = dtt200u_rc_query,
216 }, 216 },
217 217
@@ -257,8 +257,8 @@ static struct dvb_usb_device_properties wt220u_fc_properties = {
257 257
258 .rc.legacy = { 258 .rc.legacy = {
259 .rc_interval = 300, 259 .rc_interval = 300,
260 .rc_key_map = ir_codes_dtt200u_table, 260 .rc_map_table = rc_map_dtt200u_table,
261 .rc_key_map_size = ARRAY_SIZE(ir_codes_dtt200u_table), 261 .rc_map_size = ARRAY_SIZE(rc_map_dtt200u_table),
262 .rc_query = dtt200u_rc_query, 262 .rc_query = dtt200u_rc_query,
263 }, 263 },
264 264
@@ -304,8 +304,8 @@ static struct dvb_usb_device_properties wt220u_zl0353_properties = {
304 304
305 .rc.legacy = { 305 .rc.legacy = {
306 .rc_interval = 300, 306 .rc_interval = 300,
307 .rc_key_map = ir_codes_dtt200u_table, 307 .rc_map_table = rc_map_dtt200u_table,
308 .rc_key_map_size = ARRAY_SIZE(ir_codes_dtt200u_table), 308 .rc_map_size = ARRAY_SIZE(rc_map_dtt200u_table),
309 .rc_query = dtt200u_rc_query, 309 .rc_query = dtt200u_rc_query,
310 }, 310 },
311 311
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-ids.h b/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
index 192a40ce583d..1a6310b61923 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
@@ -301,6 +301,7 @@
301#define USB_PID_ELGATO_EYETV_DIVERSITY 0x0011 301#define USB_PID_ELGATO_EYETV_DIVERSITY 0x0011
302#define USB_PID_ELGATO_EYETV_DTT 0x0021 302#define USB_PID_ELGATO_EYETV_DTT 0x0021
303#define USB_PID_ELGATO_EYETV_DTT_Dlx 0x0020 303#define USB_PID_ELGATO_EYETV_DTT_Dlx 0x0020
304#define USB_PID_ELGATO_EYETV_SAT 0x002a
304#define USB_PID_DVB_T_USB_STICK_HIGH_SPEED_COLD 0x5000 305#define USB_PID_DVB_T_USB_STICK_HIGH_SPEED_COLD 0x5000
305#define USB_PID_DVB_T_USB_STICK_HIGH_SPEED_WARM 0x5001 306#define USB_PID_DVB_T_USB_STICK_HIGH_SPEED_WARM 0x5001
306#define USB_PID_FRIIO_WHITE 0x0001 307#define USB_PID_FRIIO_WHITE 0x0001
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-remote.c b/drivers/media/dvb/dvb-usb/dvb-usb-remote.c
index b579fed3ab3f..c6498f536dff 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-remote.c
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-remote.c
@@ -13,11 +13,11 @@ static int legacy_dvb_usb_getkeycode(struct input_dev *dev,
13{ 13{
14 struct dvb_usb_device *d = input_get_drvdata(dev); 14 struct dvb_usb_device *d = input_get_drvdata(dev);
15 15
16 struct ir_scancode *keymap = d->props.rc.legacy.rc_key_map; 16 struct rc_map_table *keymap = d->props.rc.legacy.rc_map_table;
17 int i; 17 int i;
18 18
19 /* See if we can match the raw key code. */ 19 /* See if we can match the raw key code. */
20 for (i = 0; i < d->props.rc.legacy.rc_key_map_size; i++) 20 for (i = 0; i < d->props.rc.legacy.rc_map_size; i++)
21 if (keymap[i].scancode == scancode) { 21 if (keymap[i].scancode == scancode) {
22 *keycode = keymap[i].keycode; 22 *keycode = keymap[i].keycode;
23 return 0; 23 return 0;
@@ -28,7 +28,7 @@ static int legacy_dvb_usb_getkeycode(struct input_dev *dev,
28 * otherwise, input core won't let legacy_dvb_usb_setkeycode 28 * otherwise, input core won't let legacy_dvb_usb_setkeycode
29 * to work 29 * to work
30 */ 30 */
31 for (i = 0; i < d->props.rc.legacy.rc_key_map_size; i++) 31 for (i = 0; i < d->props.rc.legacy.rc_map_size; i++)
32 if (keymap[i].keycode == KEY_RESERVED || 32 if (keymap[i].keycode == KEY_RESERVED ||
33 keymap[i].keycode == KEY_UNKNOWN) { 33 keymap[i].keycode == KEY_UNKNOWN) {
34 *keycode = KEY_RESERVED; 34 *keycode = KEY_RESERVED;
@@ -43,18 +43,18 @@ static int legacy_dvb_usb_setkeycode(struct input_dev *dev,
43{ 43{
44 struct dvb_usb_device *d = input_get_drvdata(dev); 44 struct dvb_usb_device *d = input_get_drvdata(dev);
45 45
46 struct ir_scancode *keymap = d->props.rc.legacy.rc_key_map; 46 struct rc_map_table *keymap = d->props.rc.legacy.rc_map_table;
47 int i; 47 int i;
48 48
49 /* Search if it is replacing an existing keycode */ 49 /* Search if it is replacing an existing keycode */
50 for (i = 0; i < d->props.rc.legacy.rc_key_map_size; i++) 50 for (i = 0; i < d->props.rc.legacy.rc_map_size; i++)
51 if (keymap[i].scancode == scancode) { 51 if (keymap[i].scancode == scancode) {
52 keymap[i].keycode = keycode; 52 keymap[i].keycode = keycode;
53 return 0; 53 return 0;
54 } 54 }
55 55
56 /* Search if is there a clean entry. If so, use it */ 56 /* Search if is there a clean entry. If so, use it */
57 for (i = 0; i < d->props.rc.legacy.rc_key_map_size; i++) 57 for (i = 0; i < d->props.rc.legacy.rc_map_size; i++)
58 if (keymap[i].keycode == KEY_RESERVED || 58 if (keymap[i].keycode == KEY_RESERVED ||
59 keymap[i].keycode == KEY_UNKNOWN) { 59 keymap[i].keycode == KEY_UNKNOWN) {
60 keymap[i].scancode = scancode; 60 keymap[i].scancode = scancode;
@@ -106,10 +106,10 @@ static void legacy_dvb_usb_read_remote_control(struct work_struct *work)
106 d->last_event = event; 106 d->last_event = event;
107 case REMOTE_KEY_REPEAT: 107 case REMOTE_KEY_REPEAT:
108 deb_rc("key repeated\n"); 108 deb_rc("key repeated\n");
109 input_event(d->rc_input_dev, EV_KEY, event, 1); 109 input_event(d->input_dev, EV_KEY, event, 1);
110 input_sync(d->rc_input_dev); 110 input_sync(d->input_dev);
111 input_event(d->rc_input_dev, EV_KEY, d->last_event, 0); 111 input_event(d->input_dev, EV_KEY, d->last_event, 0);
112 input_sync(d->rc_input_dev); 112 input_sync(d->input_dev);
113 break; 113 break;
114 default: 114 default:
115 break; 115 break;
@@ -154,20 +154,32 @@ schedule:
154 schedule_delayed_work(&d->rc_query_work,msecs_to_jiffies(d->props.rc.legacy.rc_interval)); 154 schedule_delayed_work(&d->rc_query_work,msecs_to_jiffies(d->props.rc.legacy.rc_interval));
155} 155}
156 156
157static int legacy_dvb_usb_remote_init(struct dvb_usb_device *d, 157static int legacy_dvb_usb_remote_init(struct dvb_usb_device *d)
158 struct input_dev *input_dev)
159{ 158{
160 int i, err, rc_interval; 159 int i, err, rc_interval;
160 struct input_dev *input_dev;
161
162 input_dev = input_allocate_device();
163 if (!input_dev)
164 return -ENOMEM;
165
166 input_dev->evbit[0] = BIT_MASK(EV_KEY);
167 input_dev->name = "IR-receiver inside an USB DVB receiver";
168 input_dev->phys = d->rc_phys;
169 usb_to_input_id(d->udev, &input_dev->id);
170 input_dev->dev.parent = &d->udev->dev;
171 d->input_dev = input_dev;
172 d->rc_dev = NULL;
161 173
162 input_dev->getkeycode = legacy_dvb_usb_getkeycode; 174 input_dev->getkeycode = legacy_dvb_usb_getkeycode;
163 input_dev->setkeycode = legacy_dvb_usb_setkeycode; 175 input_dev->setkeycode = legacy_dvb_usb_setkeycode;
164 176
165 /* set the bits for the keys */ 177 /* set the bits for the keys */
166 deb_rc("key map size: %d\n", d->props.rc.legacy.rc_key_map_size); 178 deb_rc("key map size: %d\n", d->props.rc.legacy.rc_map_size);
167 for (i = 0; i < d->props.rc.legacy.rc_key_map_size; i++) { 179 for (i = 0; i < d->props.rc.legacy.rc_map_size; i++) {
168 deb_rc("setting bit for event %d item %d\n", 180 deb_rc("setting bit for event %d item %d\n",
169 d->props.rc.legacy.rc_key_map[i].keycode, i); 181 d->props.rc.legacy.rc_map_table[i].keycode, i);
170 set_bit(d->props.rc.legacy.rc_key_map[i].keycode, input_dev->keybit); 182 set_bit(d->props.rc.legacy.rc_map_table[i].keycode, input_dev->keybit);
171 } 183 }
172 184
173 /* setting these two values to non-zero, we have to manage key repeats */ 185 /* setting these two values to non-zero, we have to manage key repeats */
@@ -221,18 +233,34 @@ static void dvb_usb_read_remote_control(struct work_struct *work)
221 msecs_to_jiffies(d->props.rc.core.rc_interval)); 233 msecs_to_jiffies(d->props.rc.core.rc_interval));
222} 234}
223 235
224static int rc_core_dvb_usb_remote_init(struct dvb_usb_device *d, 236static int rc_core_dvb_usb_remote_init(struct dvb_usb_device *d)
225 struct input_dev *input_dev)
226{ 237{
227 int err, rc_interval; 238 int err, rc_interval;
239 struct rc_dev *dev;
240
241 dev = rc_allocate_device();
242 if (!dev)
243 return -ENOMEM;
228 244
229 d->props.rc.core.rc_props.priv = d; 245 dev->driver_name = d->props.rc.core.module_name;
230 err = ir_input_register(input_dev, 246 dev->map_name = d->props.rc.core.rc_codes;
231 d->props.rc.core.rc_codes, 247 dev->change_protocol = d->props.rc.core.change_protocol;
232 &d->props.rc.core.rc_props, 248 dev->allowed_protos = d->props.rc.core.allowed_protos;
233 d->props.rc.core.module_name); 249 dev->driver_type = RC_DRIVER_SCANCODE;
234 if (err < 0) 250 usb_to_input_id(d->udev, &dev->input_id);
251 dev->input_name = "IR-receiver inside an USB DVB receiver";
252 dev->input_phys = d->rc_phys;
253 dev->dev.parent = &d->udev->dev;
254 dev->priv = d;
255
256 err = rc_register_device(dev);
257 if (err < 0) {
258 rc_free_device(dev);
235 return err; 259 return err;
260 }
261
262 d->input_dev = NULL;
263 d->rc_dev = dev;
236 264
237 if (!d->props.rc.core.rc_query || d->props.rc.core.bulk_mode) 265 if (!d->props.rc.core.rc_query || d->props.rc.core.bulk_mode)
238 return 0; 266 return 0;
@@ -251,13 +279,12 @@ static int rc_core_dvb_usb_remote_init(struct dvb_usb_device *d,
251 279
252int dvb_usb_remote_init(struct dvb_usb_device *d) 280int dvb_usb_remote_init(struct dvb_usb_device *d)
253{ 281{
254 struct input_dev *input_dev;
255 int err; 282 int err;
256 283
257 if (dvb_usb_disable_rc_polling) 284 if (dvb_usb_disable_rc_polling)
258 return 0; 285 return 0;
259 286
260 if (d->props.rc.legacy.rc_key_map && d->props.rc.legacy.rc_query) 287 if (d->props.rc.legacy.rc_map_table && d->props.rc.legacy.rc_query)
261 d->props.rc.mode = DVB_RC_LEGACY; 288 d->props.rc.mode = DVB_RC_LEGACY;
262 else if (d->props.rc.core.rc_codes) 289 else if (d->props.rc.core.rc_codes)
263 d->props.rc.mode = DVB_RC_CORE; 290 d->props.rc.mode = DVB_RC_CORE;
@@ -267,26 +294,14 @@ int dvb_usb_remote_init(struct dvb_usb_device *d)
267 usb_make_path(d->udev, d->rc_phys, sizeof(d->rc_phys)); 294 usb_make_path(d->udev, d->rc_phys, sizeof(d->rc_phys));
268 strlcat(d->rc_phys, "/ir0", sizeof(d->rc_phys)); 295 strlcat(d->rc_phys, "/ir0", sizeof(d->rc_phys));
269 296
270 input_dev = input_allocate_device();
271 if (!input_dev)
272 return -ENOMEM;
273
274 input_dev->evbit[0] = BIT_MASK(EV_KEY);
275 input_dev->name = "IR-receiver inside an USB DVB receiver";
276 input_dev->phys = d->rc_phys;
277 usb_to_input_id(d->udev, &input_dev->id);
278 input_dev->dev.parent = &d->udev->dev;
279
280 /* Start the remote-control polling. */ 297 /* Start the remote-control polling. */
281 if (d->props.rc.legacy.rc_interval < 40) 298 if (d->props.rc.legacy.rc_interval < 40)
282 d->props.rc.legacy.rc_interval = 100; /* default */ 299 d->props.rc.legacy.rc_interval = 100; /* default */
283 300
284 d->rc_input_dev = input_dev;
285
286 if (d->props.rc.mode == DVB_RC_LEGACY) 301 if (d->props.rc.mode == DVB_RC_LEGACY)
287 err = legacy_dvb_usb_remote_init(d, input_dev); 302 err = legacy_dvb_usb_remote_init(d);
288 else 303 else
289 err = rc_core_dvb_usb_remote_init(d, input_dev); 304 err = rc_core_dvb_usb_remote_init(d);
290 if (err) 305 if (err)
291 return err; 306 return err;
292 307
@@ -301,9 +316,9 @@ int dvb_usb_remote_exit(struct dvb_usb_device *d)
301 cancel_rearming_delayed_work(&d->rc_query_work); 316 cancel_rearming_delayed_work(&d->rc_query_work);
302 flush_scheduled_work(); 317 flush_scheduled_work();
303 if (d->props.rc.mode == DVB_RC_LEGACY) 318 if (d->props.rc.mode == DVB_RC_LEGACY)
304 input_unregister_device(d->rc_input_dev); 319 input_unregister_device(d->input_dev);
305 else 320 else
306 ir_input_unregister(d->rc_input_dev); 321 rc_unregister_device(d->rc_dev);
307 } 322 }
308 d->state &= ~DVB_USB_STATE_REMOTE; 323 d->state &= ~DVB_USB_STATE_REMOTE;
309 return 0; 324 return 0;
@@ -316,7 +331,7 @@ int dvb_usb_nec_rc_key_to_event(struct dvb_usb_device *d,
316 u8 keybuf[5], u32 *event, int *state) 331 u8 keybuf[5], u32 *event, int *state)
317{ 332{
318 int i; 333 int i;
319 struct ir_scancode *keymap = d->props.rc.legacy.rc_key_map; 334 struct rc_map_table *keymap = d->props.rc.legacy.rc_map_table;
320 *event = 0; 335 *event = 0;
321 *state = REMOTE_NO_KEY_PRESSED; 336 *state = REMOTE_NO_KEY_PRESSED;
322 switch (keybuf[0]) { 337 switch (keybuf[0]) {
@@ -329,7 +344,7 @@ int dvb_usb_nec_rc_key_to_event(struct dvb_usb_device *d,
329 break; 344 break;
330 } 345 }
331 /* See if we can match the raw key code. */ 346 /* See if we can match the raw key code. */
332 for (i = 0; i < d->props.rc.legacy.rc_key_map_size; i++) 347 for (i = 0; i < d->props.rc.legacy.rc_map_size; i++)
333 if (rc5_custom(&keymap[i]) == keybuf[1] && 348 if (rc5_custom(&keymap[i]) == keybuf[1] &&
334 rc5_data(&keymap[i]) == keybuf[3]) { 349 rc5_data(&keymap[i]) == keybuf[3]) {
335 *event = keymap[i].keycode; 350 *event = keymap[i].keycode;
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb.h b/drivers/media/dvb/dvb-usb/dvb-usb.h
index 34f7b3ba8cc7..65fa9268e7f7 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb.h
+++ b/drivers/media/dvb/dvb-usb/dvb-usb.h
@@ -14,7 +14,7 @@
14#include <linux/usb.h> 14#include <linux/usb.h>
15#include <linux/firmware.h> 15#include <linux/firmware.h>
16#include <linux/mutex.h> 16#include <linux/mutex.h>
17#include <media/ir-core.h> 17#include <media/rc-core.h>
18 18
19#include "dvb_frontend.h" 19#include "dvb_frontend.h"
20#include "dvb_demux.h" 20#include "dvb_demux.h"
@@ -75,17 +75,17 @@ struct dvb_usb_device_description {
75 struct usb_device_id *warm_ids[DVB_USB_ID_MAX_NUM]; 75 struct usb_device_id *warm_ids[DVB_USB_ID_MAX_NUM];
76}; 76};
77 77
78static inline u8 rc5_custom(struct ir_scancode *key) 78static inline u8 rc5_custom(struct rc_map_table *key)
79{ 79{
80 return (key->scancode >> 8) & 0xff; 80 return (key->scancode >> 8) & 0xff;
81} 81}
82 82
83static inline u8 rc5_data(struct ir_scancode *key) 83static inline u8 rc5_data(struct rc_map_table *key)
84{ 84{
85 return key->scancode & 0xff; 85 return key->scancode & 0xff;
86} 86}
87 87
88static inline u8 rc5_scan(struct ir_scancode *key) 88static inline u8 rc5_scan(struct rc_map_table *key)
89{ 89{
90 return key->scancode & 0xffff; 90 return key->scancode & 0xffff;
91} 91}
@@ -159,9 +159,9 @@ struct dvb_usb_adapter_properties {
159 159
160/** 160/**
161 * struct dvb_rc_legacy - old properties of remote controller 161 * struct dvb_rc_legacy - old properties of remote controller
162 * @rc_key_map: a hard-wired array of struct ir_scancode (NULL to disable 162 * @rc_map_table: a hard-wired array of struct rc_map_table (NULL to disable
163 * remote control handling). 163 * remote control handling).
164 * @rc_key_map_size: number of items in @rc_key_map. 164 * @rc_map_size: number of items in @rc_map_table.
165 * @rc_query: called to query an event event. 165 * @rc_query: called to query an event event.
166 * @rc_interval: time in ms between two queries. 166 * @rc_interval: time in ms between two queries.
167 */ 167 */
@@ -170,8 +170,8 @@ struct dvb_rc_legacy {
170#define REMOTE_NO_KEY_PRESSED 0x00 170#define REMOTE_NO_KEY_PRESSED 0x00
171#define REMOTE_KEY_PRESSED 0x01 171#define REMOTE_KEY_PRESSED 0x01
172#define REMOTE_KEY_REPEAT 0x02 172#define REMOTE_KEY_REPEAT 0x02
173 struct ir_scancode *rc_key_map; 173 struct rc_map_table *rc_map_table;
174 int rc_key_map_size; 174 int rc_map_size;
175 int (*rc_query) (struct dvb_usb_device *, u32 *, int *); 175 int (*rc_query) (struct dvb_usb_device *, u32 *, int *);
176 int rc_interval; 176 int rc_interval;
177}; 177};
@@ -180,18 +180,20 @@ struct dvb_rc_legacy {
180 * struct dvb_rc properties of remote controller, using rc-core 180 * struct dvb_rc properties of remote controller, using rc-core
181 * @rc_codes: name of rc codes table 181 * @rc_codes: name of rc codes table
182 * @protocol: type of protocol(s) currently used by the driver 182 * @protocol: type of protocol(s) currently used by the driver
183 * @allowed_protos: protocol(s) supported by the driver
184 * @change_protocol: callback to change protocol
183 * @rc_query: called to query an event event. 185 * @rc_query: called to query an event event.
184 * @rc_interval: time in ms between two queries. 186 * @rc_interval: time in ms between two queries.
185 * @rc_props: remote controller properties
186 * @bulk_mode: device supports bulk mode for RC (disable polling mode) 187 * @bulk_mode: device supports bulk mode for RC (disable polling mode)
187 */ 188 */
188struct dvb_rc { 189struct dvb_rc {
189 char *rc_codes; 190 char *rc_codes;
190 u64 protocol; 191 u64 protocol;
192 u64 allowed_protos;
193 int (*change_protocol)(struct rc_dev *dev, u64 rc_type);
191 char *module_name; 194 char *module_name;
192 int (*rc_query) (struct dvb_usb_device *d); 195 int (*rc_query) (struct dvb_usb_device *d);
193 int rc_interval; 196 int rc_interval;
194 struct ir_dev_props rc_props;
195 bool bulk_mode; /* uses bulk mode */ 197 bool bulk_mode; /* uses bulk mode */
196}; 198};
197 199
@@ -385,7 +387,8 @@ struct dvb_usb_adapter {
385 * 387 *
386 * @i2c_adap: device's i2c_adapter if it uses I2CoverUSB 388 * @i2c_adap: device's i2c_adapter if it uses I2CoverUSB
387 * 389 *
388 * @rc_input_dev: input device for the remote control. 390 * @rc_dev: rc device for the remote control (rc-core mode)
391 * @input_dev: input device for the remote control (legacy mode)
389 * @rc_query_work: struct work_struct frequent rc queries 392 * @rc_query_work: struct work_struct frequent rc queries
390 * @last_event: last triggered event 393 * @last_event: last triggered event
391 * @last_state: last state (no, pressed, repeat) 394 * @last_state: last state (no, pressed, repeat)
@@ -418,7 +421,8 @@ struct dvb_usb_device {
418 struct dvb_usb_adapter adapter[MAX_NO_OF_ADAPTER_PER_DEVICE]; 421 struct dvb_usb_adapter adapter[MAX_NO_OF_ADAPTER_PER_DEVICE];
419 422
420 /* remote control */ 423 /* remote control */
421 struct input_dev *rc_input_dev; 424 struct rc_dev *rc_dev;
425 struct input_dev *input_dev;
422 char rc_phys[64]; 426 char rc_phys[64];
423 struct delayed_work rc_query_work; 427 struct delayed_work rc_query_work;
424 u32 last_event; 428 u32 last_event;
diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
index 774df88dc6e3..2c307ba0d28b 100644
--- a/drivers/media/dvb/dvb-usb/dw2102.c
+++ b/drivers/media/dvb/dvb-usb/dw2102.c
@@ -73,8 +73,8 @@
73 "Please see linux/Documentation/dvb/ for more details " \ 73 "Please see linux/Documentation/dvb/ for more details " \
74 "on firmware-problems." 74 "on firmware-problems."
75 75
76struct ir_codes_dvb_usb_table_table { 76struct rc_map_dvb_usb_table_table {
77 struct ir_scancode *rc_keys; 77 struct rc_map_table *rc_keys;
78 int rc_keys_size; 78 int rc_keys_size;
79}; 79};
80 80
@@ -948,7 +948,7 @@ static int dw3101_tuner_attach(struct dvb_usb_adapter *adap)
948 return 0; 948 return 0;
949} 949}
950 950
951static struct ir_scancode ir_codes_dw210x_table[] = { 951static struct rc_map_table rc_map_dw210x_table[] = {
952 { 0xf80a, KEY_Q }, /*power*/ 952 { 0xf80a, KEY_Q }, /*power*/
953 { 0xf80c, KEY_M }, /*mute*/ 953 { 0xf80c, KEY_M }, /*mute*/
954 { 0xf811, KEY_1 }, 954 { 0xf811, KEY_1 },
@@ -982,7 +982,7 @@ static struct ir_scancode ir_codes_dw210x_table[] = {
982 { 0xf81b, KEY_B }, /*recall*/ 982 { 0xf81b, KEY_B }, /*recall*/
983}; 983};
984 984
985static struct ir_scancode ir_codes_tevii_table[] = { 985static struct rc_map_table rc_map_tevii_table[] = {
986 { 0xf80a, KEY_POWER }, 986 { 0xf80a, KEY_POWER },
987 { 0xf80c, KEY_MUTE }, 987 { 0xf80c, KEY_MUTE },
988 { 0xf811, KEY_1 }, 988 { 0xf811, KEY_1 },
@@ -1032,7 +1032,7 @@ static struct ir_scancode ir_codes_tevii_table[] = {
1032 { 0xf858, KEY_SWITCHVIDEOMODE }, 1032 { 0xf858, KEY_SWITCHVIDEOMODE },
1033}; 1033};
1034 1034
1035static struct ir_scancode ir_codes_tbs_table[] = { 1035static struct rc_map_table rc_map_tbs_table[] = {
1036 { 0xf884, KEY_POWER }, 1036 { 0xf884, KEY_POWER },
1037 { 0xf894, KEY_MUTE }, 1037 { 0xf894, KEY_MUTE },
1038 { 0xf887, KEY_1 }, 1038 { 0xf887, KEY_1 },
@@ -1067,16 +1067,16 @@ static struct ir_scancode ir_codes_tbs_table[] = {
1067 { 0xf89b, KEY_MODE } 1067 { 0xf89b, KEY_MODE }
1068}; 1068};
1069 1069
1070static struct ir_codes_dvb_usb_table_table keys_tables[] = { 1070static struct rc_map_dvb_usb_table_table keys_tables[] = {
1071 { ir_codes_dw210x_table, ARRAY_SIZE(ir_codes_dw210x_table) }, 1071 { rc_map_dw210x_table, ARRAY_SIZE(rc_map_dw210x_table) },
1072 { ir_codes_tevii_table, ARRAY_SIZE(ir_codes_tevii_table) }, 1072 { rc_map_tevii_table, ARRAY_SIZE(rc_map_tevii_table) },
1073 { ir_codes_tbs_table, ARRAY_SIZE(ir_codes_tbs_table) }, 1073 { rc_map_tbs_table, ARRAY_SIZE(rc_map_tbs_table) },
1074}; 1074};
1075 1075
1076static int dw2102_rc_query(struct dvb_usb_device *d, u32 *event, int *state) 1076static int dw2102_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
1077{ 1077{
1078 struct ir_scancode *keymap = d->props.rc.legacy.rc_key_map; 1078 struct rc_map_table *keymap = d->props.rc.legacy.rc_map_table;
1079 int keymap_size = d->props.rc.legacy.rc_key_map_size; 1079 int keymap_size = d->props.rc.legacy.rc_map_size;
1080 u8 key[2]; 1080 u8 key[2];
1081 struct i2c_msg msg = { 1081 struct i2c_msg msg = {
1082 .addr = DW2102_RC_QUERY, 1082 .addr = DW2102_RC_QUERY,
@@ -1185,14 +1185,14 @@ static int dw2102_load_firmware(struct usb_device *dev,
1185 /* init registers */ 1185 /* init registers */
1186 switch (dev->descriptor.idProduct) { 1186 switch (dev->descriptor.idProduct) {
1187 case USB_PID_PROF_1100: 1187 case USB_PID_PROF_1100:
1188 s6x0_properties.rc.legacy.rc_key_map = ir_codes_tbs_table; 1188 s6x0_properties.rc.legacy.rc_map_table = rc_map_tbs_table;
1189 s6x0_properties.rc.legacy.rc_key_map_size = 1189 s6x0_properties.rc.legacy.rc_map_size =
1190 ARRAY_SIZE(ir_codes_tbs_table); 1190 ARRAY_SIZE(rc_map_tbs_table);
1191 break; 1191 break;
1192 case USB_PID_TEVII_S650: 1192 case USB_PID_TEVII_S650:
1193 dw2104_properties.rc.legacy.rc_key_map = ir_codes_tevii_table; 1193 dw2104_properties.rc.legacy.rc_map_table = rc_map_tevii_table;
1194 dw2104_properties.rc.legacy.rc_key_map_size = 1194 dw2104_properties.rc.legacy.rc_map_size =
1195 ARRAY_SIZE(ir_codes_tevii_table); 1195 ARRAY_SIZE(rc_map_tevii_table);
1196 case USB_PID_DW2104: 1196 case USB_PID_DW2104:
1197 reset = 1; 1197 reset = 1;
1198 dw210x_op_rw(dev, 0xc4, 0x0000, 0, &reset, 1, 1198 dw210x_op_rw(dev, 0xc4, 0x0000, 0, &reset, 1,
@@ -1257,8 +1257,8 @@ static struct dvb_usb_device_properties dw2102_properties = {
1257 .i2c_algo = &dw2102_serit_i2c_algo, 1257 .i2c_algo = &dw2102_serit_i2c_algo,
1258 1258
1259 .rc.legacy = { 1259 .rc.legacy = {
1260 .rc_key_map = ir_codes_dw210x_table, 1260 .rc_map_table = rc_map_dw210x_table,
1261 .rc_key_map_size = ARRAY_SIZE(ir_codes_dw210x_table), 1261 .rc_map_size = ARRAY_SIZE(rc_map_dw210x_table),
1262 .rc_interval = 150, 1262 .rc_interval = 150,
1263 .rc_query = dw2102_rc_query, 1263 .rc_query = dw2102_rc_query,
1264 }, 1264 },
@@ -1310,8 +1310,8 @@ static struct dvb_usb_device_properties dw2104_properties = {
1310 1310
1311 .i2c_algo = &dw2104_i2c_algo, 1311 .i2c_algo = &dw2104_i2c_algo,
1312 .rc.legacy = { 1312 .rc.legacy = {
1313 .rc_key_map = ir_codes_dw210x_table, 1313 .rc_map_table = rc_map_dw210x_table,
1314 .rc_key_map_size = ARRAY_SIZE(ir_codes_dw210x_table), 1314 .rc_map_size = ARRAY_SIZE(rc_map_dw210x_table),
1315 .rc_interval = 150, 1315 .rc_interval = 150,
1316 .rc_query = dw2102_rc_query, 1316 .rc_query = dw2102_rc_query,
1317 }, 1317 },
@@ -1359,8 +1359,8 @@ static struct dvb_usb_device_properties dw3101_properties = {
1359 1359
1360 .i2c_algo = &dw3101_i2c_algo, 1360 .i2c_algo = &dw3101_i2c_algo,
1361 .rc.legacy = { 1361 .rc.legacy = {
1362 .rc_key_map = ir_codes_dw210x_table, 1362 .rc_map_table = rc_map_dw210x_table,
1363 .rc_key_map_size = ARRAY_SIZE(ir_codes_dw210x_table), 1363 .rc_map_size = ARRAY_SIZE(rc_map_dw210x_table),
1364 .rc_interval = 150, 1364 .rc_interval = 150,
1365 .rc_query = dw2102_rc_query, 1365 .rc_query = dw2102_rc_query,
1366 }, 1366 },
@@ -1404,8 +1404,8 @@ static struct dvb_usb_device_properties s6x0_properties = {
1404 1404
1405 .i2c_algo = &s6x0_i2c_algo, 1405 .i2c_algo = &s6x0_i2c_algo,
1406 .rc.legacy = { 1406 .rc.legacy = {
1407 .rc_key_map = ir_codes_tevii_table, 1407 .rc_map_table = rc_map_tevii_table,
1408 .rc_key_map_size = ARRAY_SIZE(ir_codes_tevii_table), 1408 .rc_map_size = ARRAY_SIZE(rc_map_tevii_table),
1409 .rc_interval = 150, 1409 .rc_interval = 150,
1410 .rc_query = dw2102_rc_query, 1410 .rc_query = dw2102_rc_query,
1411 }, 1411 },
@@ -1468,8 +1468,8 @@ static int dw2102_probe(struct usb_interface *intf,
1468 /* fill only different fields */ 1468 /* fill only different fields */
1469 p7500->firmware = "dvb-usb-p7500.fw"; 1469 p7500->firmware = "dvb-usb-p7500.fw";
1470 p7500->devices[0] = d7500; 1470 p7500->devices[0] = d7500;
1471 p7500->rc.legacy.rc_key_map = ir_codes_tbs_table; 1471 p7500->rc.legacy.rc_map_table = rc_map_tbs_table;
1472 p7500->rc.legacy.rc_key_map_size = ARRAY_SIZE(ir_codes_tbs_table); 1472 p7500->rc.legacy.rc_map_size = ARRAY_SIZE(rc_map_tbs_table);
1473 p7500->adapter->frontend_attach = prof_7500_frontend_attach; 1473 p7500->adapter->frontend_attach = prof_7500_frontend_attach;
1474 1474
1475 if (0 == dvb_usb_device_init(intf, &dw2102_properties, 1475 if (0 == dvb_usb_device_init(intf, &dw2102_properties,
diff --git a/drivers/media/dvb/dvb-usb/gp8psk.c b/drivers/media/dvb/dvb-usb/gp8psk.c
index c821293dbc22..1cb3d9a66e02 100644
--- a/drivers/media/dvb/dvb-usb/gp8psk.c
+++ b/drivers/media/dvb/dvb-usb/gp8psk.c
@@ -24,6 +24,33 @@ MODULE_PARM_DESC(debug, "set debugging level (1=info,xfer=2,rc=4 (or-able))." DV
24 24
25DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); 25DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
26 26
27static int gp8psk_get_fw_version(struct dvb_usb_device *d, u8 *fw_vers)
28{
29 return (gp8psk_usb_in_op(d, GET_FW_VERS, 0, 0, fw_vers, 6));
30}
31
32static int gp8psk_get_fpga_version(struct dvb_usb_device *d, u8 *fpga_vers)
33{
34 return (gp8psk_usb_in_op(d, GET_FPGA_VERS, 0, 0, fpga_vers, 1));
35}
36
37static void gp8psk_info(struct dvb_usb_device *d)
38{
39 u8 fpga_vers, fw_vers[6];
40
41 if (!gp8psk_get_fw_version(d, fw_vers))
42 info("FW Version = %i.%02i.%i (0x%x) Build %4i/%02i/%02i",
43 fw_vers[2], fw_vers[1], fw_vers[0], GP8PSK_FW_VERS(fw_vers),
44 2000 + fw_vers[5], fw_vers[4], fw_vers[3]);
45 else
46 info("failed to get FW version");
47
48 if (!gp8psk_get_fpga_version(d, &fpga_vers))
49 info("FPGA Version = %i", fpga_vers);
50 else
51 info("failed to get FPGA version");
52}
53
27int gp8psk_usb_in_op(struct dvb_usb_device *d, u8 req, u16 value, u16 index, u8 *b, int blen) 54int gp8psk_usb_in_op(struct dvb_usb_device *d, u8 req, u16 value, u16 index, u8 *b, int blen)
28{ 55{
29 int ret = 0,try = 0; 56 int ret = 0,try = 0;
@@ -146,6 +173,7 @@ static int gp8psk_power_ctrl(struct dvb_usb_device *d, int onoff)
146 gp8psk_usb_out_op(d, CW3K_INIT, 1, 0, NULL, 0); 173 gp8psk_usb_out_op(d, CW3K_INIT, 1, 0, NULL, 0);
147 if (gp8psk_usb_in_op(d, BOOT_8PSK, 1, 0, &buf, 1)) 174 if (gp8psk_usb_in_op(d, BOOT_8PSK, 1, 0, &buf, 1))
148 return -EINVAL; 175 return -EINVAL;
176 gp8psk_info(d);
149 } 177 }
150 178
151 if (gp_product_id == USB_PID_GENPIX_8PSK_REV_1_WARM) 179 if (gp_product_id == USB_PID_GENPIX_8PSK_REV_1_WARM)
diff --git a/drivers/media/dvb/dvb-usb/gp8psk.h b/drivers/media/dvb/dvb-usb/gp8psk.h
index e83a57506cfa..831749a518cb 100644
--- a/drivers/media/dvb/dvb-usb/gp8psk.h
+++ b/drivers/media/dvb/dvb-usb/gp8psk.h
@@ -25,7 +25,6 @@ extern int dvb_usb_gp8psk_debug;
25#define deb_xfer(args...) dprintk(dvb_usb_gp8psk_debug,0x02,args) 25#define deb_xfer(args...) dprintk(dvb_usb_gp8psk_debug,0x02,args)
26#define deb_rc(args...) dprintk(dvb_usb_gp8psk_debug,0x04,args) 26#define deb_rc(args...) dprintk(dvb_usb_gp8psk_debug,0x04,args)
27#define deb_fe(args...) dprintk(dvb_usb_gp8psk_debug,0x08,args) 27#define deb_fe(args...) dprintk(dvb_usb_gp8psk_debug,0x08,args)
28/* gp8psk commands */
29 28
30/* Twinhan Vendor requests */ 29/* Twinhan Vendor requests */
31#define TH_COMMAND_IN 0xC0 30#define TH_COMMAND_IN 0xC0
@@ -49,8 +48,10 @@ extern int dvb_usb_gp8psk_debug;
49#define SET_DVB_MODE 0x8E 48#define SET_DVB_MODE 0x8E
50#define SET_DN_SWITCH 0x8F 49#define SET_DN_SWITCH 0x8F
51#define GET_SIGNAL_LOCK 0x90 /* in */ 50#define GET_SIGNAL_LOCK 0x90 /* in */
51#define GET_FW_VERS 0x92
52#define GET_SERIAL_NUMBER 0x93 /* in */ 52#define GET_SERIAL_NUMBER 0x93 /* in */
53#define USE_EXTRA_VOLT 0x94 53#define USE_EXTRA_VOLT 0x94
54#define GET_FPGA_VERS 0x95
54#define CW3K_INIT 0x9d 55#define CW3K_INIT 0x9d
55 56
56/* PSK_configuration bits */ 57/* PSK_configuration bits */
@@ -88,6 +89,11 @@ extern int dvb_usb_gp8psk_debug;
88#define PRODUCT_STRING_READ 0x0D 89#define PRODUCT_STRING_READ 0x0D
89#define FW_BCD_VERSION_READ 0x14 90#define FW_BCD_VERSION_READ 0x14
90 91
92/* firmware revision id's */
93#define GP8PSK_FW_REV1 0x020604
94#define GP8PSK_FW_REV2 0x020704
95#define GP8PSK_FW_VERS(_fw_vers) ((_fw_vers)[2]<<0x10 | (_fw_vers)[1]<<0x08 | (_fw_vers)[0])
96
91extern struct dvb_frontend * gp8psk_fe_attach(struct dvb_usb_device *d); 97extern struct dvb_frontend * gp8psk_fe_attach(struct dvb_usb_device *d);
92extern int gp8psk_usb_in_op(struct dvb_usb_device *d, u8 req, u16 value, u16 index, u8 *b, int blen); 98extern int gp8psk_usb_in_op(struct dvb_usb_device *d, u8 req, u16 value, u16 index, u8 *b, int blen);
93extern int gp8psk_usb_out_op(struct dvb_usb_device *d, u8 req, u16 value, 99extern int gp8psk_usb_out_op(struct dvb_usb_device *d, u8 req, u16 value,
diff --git a/drivers/media/dvb/dvb-usb/lmedm04.c b/drivers/media/dvb/dvb-usb/lmedm04.c
index d939fbbf9fe6..9eea4188303b 100644
--- a/drivers/media/dvb/dvb-usb/lmedm04.c
+++ b/drivers/media/dvb/dvb-usb/lmedm04.c
@@ -61,7 +61,7 @@
61#define DVB_USB_LOG_PREFIX "LME2510(C)" 61#define DVB_USB_LOG_PREFIX "LME2510(C)"
62#include <linux/usb.h> 62#include <linux/usb.h>
63#include <linux/usb/input.h> 63#include <linux/usb/input.h>
64#include <media/ir-core.h> 64#include <media/rc-core.h>
65 65
66#include "dvb-usb.h" 66#include "dvb-usb.h"
67#include "lmedm04.h" 67#include "lmedm04.h"
@@ -112,7 +112,6 @@ struct lme2510_state {
112 u8 i2c_tuner_gate_r; 112 u8 i2c_tuner_gate_r;
113 u8 i2c_tuner_addr; 113 u8 i2c_tuner_addr;
114 u8 stream_on; 114 u8 stream_on;
115 u8 one_tune;
116 void *buffer; 115 void *buffer;
117 struct urb *lme_urb; 116 struct urb *lme_urb;
118 void *usb_buffer; 117 void *usb_buffer;
@@ -125,7 +124,7 @@ static int lme2510_bulk_write(struct usb_device *dev,
125 int ret, actual_l; 124 int ret, actual_l;
126 125
127 ret = usb_bulk_msg(dev, usb_sndbulkpipe(dev, pipe), 126 ret = usb_bulk_msg(dev, usb_sndbulkpipe(dev, pipe),
128 snd, len , &actual_l, 500); 127 snd, len , &actual_l, 100);
129 return ret; 128 return ret;
130} 129}
131 130
@@ -135,7 +134,7 @@ static int lme2510_bulk_read(struct usb_device *dev,
135 int ret, actual_l; 134 int ret, actual_l;
136 135
137 ret = usb_bulk_msg(dev, usb_rcvbulkpipe(dev, pipe), 136 ret = usb_bulk_msg(dev, usb_rcvbulkpipe(dev, pipe),
138 rev, len , &actual_l, 500); 137 rev, len , &actual_l, 200);
139 return ret; 138 return ret;
140} 139}
141 140
@@ -167,7 +166,7 @@ static int lme2510_usb_talk(struct dvb_usb_device *d,
167 166
168 ret |= lme2510_bulk_write(d->udev, buff, wlen , 0x01); 167 ret |= lme2510_bulk_write(d->udev, buff, wlen , 0x01);
169 168
170 msleep(12); 169 msleep(10);
171 170
172 ret |= usb_clear_halt(d->udev, usb_rcvbulkpipe(d->udev, 0x01)); 171 ret |= usb_clear_halt(d->udev, usb_rcvbulkpipe(d->udev, 0x01));
173 172
@@ -182,15 +181,13 @@ static int lme2510_usb_talk(struct dvb_usb_device *d,
182 return (ret < 0) ? -ENODEV : 0; 181 return (ret < 0) ? -ENODEV : 0;
183} 182}
184 183
185static int lme2510_usb_talk_restart(struct dvb_usb_device *d, 184static int lme2510_stream_restart(struct dvb_usb_device *d)
186 u8 *wbuf, int wlen, u8 *rbuf, int rlen) { 185{
187 static u8 stream_on[] = LME_ST_ON_W; 186 static u8 stream_on[] = LME_ST_ON_W;
188 int ret; 187 int ret;
189 u8 rbuff[10]; 188 u8 rbuff[10];
190 /*Send Normal Command*/
191 ret = lme2510_usb_talk(d, wbuf, wlen, rbuf, rlen);
192 /*Restart Stream Command*/ 189 /*Restart Stream Command*/
193 ret |= lme2510_usb_talk(d, stream_on, sizeof(stream_on), 190 ret = lme2510_usb_talk(d, stream_on, sizeof(stream_on),
194 rbuff, sizeof(rbuff)); 191 rbuff, sizeof(rbuff));
195 return ret; 192 return ret;
196} 193}
@@ -201,7 +198,7 @@ static int lme2510_remote_keypress(struct dvb_usb_adapter *adap, u16 keypress)
201 deb_info(1, "INT Key Keypress =%04x", keypress); 198 deb_info(1, "INT Key Keypress =%04x", keypress);
202 199
203 if (keypress > 0) 200 if (keypress > 0)
204 ir_keydown(d->rc_input_dev, keypress, 0); 201 rc_keydown(d->rc_dev, keypress, 0);
205 202
206 return 0; 203 return 0;
207} 204}
@@ -254,11 +251,16 @@ static void lme2510_int_response(struct urb *lme_urb)
254 case TUNER_S7395: 251 case TUNER_S7395:
255 /* Tweak for earlier firmware*/ 252 /* Tweak for earlier firmware*/
256 if (ibuf[1] == 0x03) { 253 if (ibuf[1] == 0x03) {
254 if (ibuf[2] > 1)
255 st->signal_lock = ibuf[2];
257 st->signal_level = ibuf[3]; 256 st->signal_level = ibuf[3];
258 st->signal_sn = ibuf[4]; 257 st->signal_sn = ibuf[4];
259 } else { 258 } else {
260 st->signal_level = ibuf[4]; 259 st->signal_level = ibuf[4];
261 st->signal_sn = ibuf[5]; 260 st->signal_sn = ibuf[5];
261 st->signal_lock =
262 (st->signal_lock & 0xf7) +
263 ((ibuf[2] & 0x01) << 0x03);
262 } 264 }
263 break; 265 break;
264 default: 266 default:
@@ -341,11 +343,10 @@ static int lme2510_msg(struct dvb_usb_device *d,
341 st->signal_lock = rbuf[1]; 343 st->signal_lock = rbuf[1];
342 if ((st->stream_on & 1) && 344 if ((st->stream_on & 1) &&
343 (st->signal_lock & 0x10)) { 345 (st->signal_lock & 0x10)) {
344 lme2510_usb_talk_restart(d, 346 lme2510_stream_restart(d);
345 wbuf, wlen, rbuf, rlen);
346 st->i2c_talk_onoff = 0; 347 st->i2c_talk_onoff = 0;
347 } 348 }
348 msleep(80); 349 msleep(80);
349 } 350 }
350 } 351 }
351 break; 352 break;
@@ -355,15 +356,12 @@ static int lme2510_msg(struct dvb_usb_device *d,
355 st->signal_lock = rbuf[1]; 356 st->signal_lock = rbuf[1];
356 if ((st->stream_on & 1) && 357 if ((st->stream_on & 1) &&
357 (st->signal_lock & 0x8)) { 358 (st->signal_lock & 0x8)) {
358 lme2510_usb_talk_restart(d, 359 lme2510_stream_restart(d);
359 wbuf, wlen, rbuf, rlen);
360 st->i2c_talk_onoff = 0; 360 st->i2c_talk_onoff = 0;
361 } 361 }
362 } 362 }
363 if ((wbuf[3] != 0x6) & (wbuf[3] != 0x5)) 363 if ((wbuf[3] != 0x6) & (wbuf[3] != 0x5))
364 msleep(5); 364 msleep(5);
365
366
367 } 365 }
368 break; 366 break;
369 default: 367 default:
@@ -385,18 +383,16 @@ static int lme2510_msg(struct dvb_usb_device *d,
385 rbuf[0] = 0x55; 383 rbuf[0] = 0x55;
386 rbuf[1] = st->signal_sn; 384 rbuf[1] = st->signal_sn;
387 break; 385 break;
388 /*DiSEqC functions as per TDA10086*/ 386 case 0x15:
389 case 0x36: 387 case 0x16:
390 case 0x48: 388 case 0x17:
391 case 0x49: 389 case 0x18:
392 case 0x4a: 390 rbuf[0] = 0x55;
393 case 0x4b: 391 rbuf[1] = 0x00;
394 case 0x4c: 392 break;
395 case 0x4d:
396 if (wbuf[2] == 0x1c)
397 lme2510_usb_talk_restart(d,
398 wbuf, wlen, rbuf, rlen);
399 default: 393 default:
394 lme2510_usb_talk(d, wbuf, wlen, rbuf, rlen);
395 st->i2c_talk_onoff = 1;
400 break; 396 break;
401 } 397 }
402 break; 398 break;
@@ -413,39 +409,22 @@ static int lme2510_msg(struct dvb_usb_device *d,
413 break; 409 break;
414 case 0x24: 410 case 0x24:
415 rbuf[0] = 0x55; 411 rbuf[0] = 0x55;
416 rbuf[1] = (st->signal_level & 0x80) 412 rbuf[1] = st->signal_lock;
417 ? 0 : st->signal_lock;
418 break;
419 case 0x6:
420 if (wbuf[2] == 0xd0)
421 lme2510_usb_talk(d,
422 wbuf, wlen, rbuf, rlen);
423 break;
424 case 0x1:
425 if (st->one_tune > 0)
426 break;
427 st->one_tune++;
428 st->i2c_talk_onoff = 1;
429 /*DiSEqC functions as per STV0288*/
430 case 0x5:
431 case 0x7:
432 case 0x8:
433 case 0x9:
434 case 0xa:
435 case 0xb:
436 if (wbuf[2] == 0xd0)
437 lme2510_usb_talk_restart(d,
438 wbuf, wlen, rbuf, rlen);
439 break; 413 break;
440 default: 414 case 0x2e:
415 case 0x26:
416 case 0x27:
441 rbuf[0] = 0x55; 417 rbuf[0] = 0x55;
442 rbuf[1] = 0x00; 418 rbuf[1] = 0x00;
443 break; 419 break;
420 default:
421 lme2510_usb_talk(d, wbuf, wlen, rbuf, rlen);
422 st->i2c_talk_onoff = 1;
423 break;
444 } 424 }
445 break; 425 break;
446 default: 426 default:
447 break; 427 break;
448
449 } 428 }
450 429
451 deb_info(4, "I2C From Interupt Message out(%02x) in(%02x)", 430 deb_info(4, "I2C From Interupt Message out(%02x) in(%02x)",
@@ -548,35 +527,26 @@ static int lme2510_identify_state(struct usb_device *udev,
548static int lme2510_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff) 527static int lme2510_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
549{ 528{
550 struct lme2510_state *st = adap->dev->priv; 529 struct lme2510_state *st = adap->dev->priv;
551 static u8 stream_on[] = LME_ST_ON_W;
552 static u8 clear_reg_3[] = LME_CLEAR_PID; 530 static u8 clear_reg_3[] = LME_CLEAR_PID;
553 static u8 rbuf[1]; 531 static u8 rbuf[1];
554 static u8 timeout; 532 int ret = 0, rlen = sizeof(rbuf);
555 int ret = 0, len = 2, rlen = sizeof(rbuf);
556 533
557 deb_info(1, "STM (%02x)", onoff); 534 deb_info(1, "STM (%02x)", onoff);
558 535
559 if (onoff == 1) { 536 /* Streaming is started by FE_HAS_LOCK */
560 st->i2c_talk_onoff = 0; 537 if (onoff == 1)
561 timeout = 0;
562 /* wait for i2C to be free */
563 while (mutex_lock_interruptible(&adap->dev->i2c_mutex) < 0) {
564 timeout++;
565 if (timeout > 5)
566 return -ENODEV;
567 }
568 msleep(100);
569 ret |= lme2510_usb_talk(adap->dev,
570 stream_on, len, rbuf, rlen);
571 st->stream_on = 1; 538 st->stream_on = 1;
572 st->one_tune = 0; 539 else {
573 mutex_unlock(&adap->dev->i2c_mutex);
574 } else {
575 deb_info(1, "STM Steam Off"); 540 deb_info(1, "STM Steam Off");
541 /* mutex is here only to avoid collision with I2C */
542 ret = mutex_lock_interruptible(&adap->dev->i2c_mutex);
543
576 ret |= lme2510_usb_talk(adap->dev, clear_reg_3, 544 ret |= lme2510_usb_talk(adap->dev, clear_reg_3,
577 sizeof(clear_reg_3), rbuf, rlen); 545 sizeof(clear_reg_3), rbuf, rlen);
578 st->stream_on = 0; 546 st->stream_on = 0;
579 st->i2c_talk_onoff = 1; 547 st->i2c_talk_onoff = 1;
548
549 mutex_unlock(&adap->dev->i2c_mutex);
580 } 550 }
581 551
582 return (ret < 0) ? -ENODEV : 0; 552 return (ret < 0) ? -ENODEV : 0;
@@ -585,41 +555,40 @@ static int lme2510_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
585static int lme2510_int_service(struct dvb_usb_adapter *adap) 555static int lme2510_int_service(struct dvb_usb_adapter *adap)
586{ 556{
587 struct dvb_usb_device *d = adap->dev; 557 struct dvb_usb_device *d = adap->dev;
588 struct input_dev *input_dev; 558 struct rc_dev *rc;
589 char *ir_codes = RC_MAP_LME2510; 559 int ret;
590 int ret = 0;
591 560
592 info("STA Configuring Remote"); 561 info("STA Configuring Remote");
593 562
594 usb_make_path(d->udev, d->rc_phys, sizeof(d->rc_phys)); 563 rc = rc_allocate_device();
595 564 if (!rc)
596 strlcat(d->rc_phys, "/ir0", sizeof(d->rc_phys));
597
598 input_dev = input_allocate_device();
599 if (!input_dev)
600 return -ENOMEM; 565 return -ENOMEM;
601 566
602 input_dev->name = "LME2510 Remote Control"; 567 usb_make_path(d->udev, d->rc_phys, sizeof(d->rc_phys));
603 input_dev->phys = d->rc_phys; 568 strlcat(d->rc_phys, "/ir0", sizeof(d->rc_phys));
604
605 usb_to_input_id(d->udev, &input_dev->id);
606 569
607 ret |= ir_input_register(input_dev, ir_codes, NULL, "LME 2510"); 570 rc->input_name = "LME2510 Remote Control";
571 rc->input_phys = d->rc_phys;
572 rc->map_name = RC_MAP_LME2510;
573 rc->driver_name = "LME 2510";
574 usb_to_input_id(d->udev, &rc->input_id);
608 575
576 ret = rc_register_device(rc);
609 if (ret) { 577 if (ret) {
610 input_free_device(input_dev); 578 rc_free_device(rc);
611 return ret; 579 return ret;
612 } 580 }
581 d->rc_dev = rc;
613 582
614 d->rc_input_dev = input_dev;
615 /* Start the Interupt */ 583 /* Start the Interupt */
616 ret = lme2510_int_read(adap); 584 ret = lme2510_int_read(adap);
617
618 if (ret < 0) { 585 if (ret < 0) {
619 ir_input_unregister(input_dev); 586 rc_unregister_device(rc);
620 input_free_device(input_dev); 587 info("INT Unable to start Interupt Service");
588 return -ENODEV;
621 } 589 }
622 return (ret < 0) ? -ENODEV : 0; 590
591 return 0;
623} 592}
624 593
625static u8 check_sum(u8 *p, u8 len) 594static u8 check_sum(u8 *p, u8 len)
@@ -668,6 +637,7 @@ static int lme2510_download_firmware(struct usb_device *dev,
668 ret |= (data[0] == 0x88) ? 0 : -1; 637 ret |= (data[0] == 0x88) ? 0 : -1;
669 } 638 }
670 } 639 }
640
671 usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), 641 usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
672 0x06, 0x80, 0x0200, 0x00, data, 0x0109, 1000); 642 0x06, 0x80, 0x0200, 0x00, data, 0x0109, 1000);
673 643
@@ -701,10 +671,11 @@ static void lme_coldreset(struct usb_device *dev)
701 info("FRM Firmware Cold Reset"); 671 info("FRM Firmware Cold Reset");
702 ret |= lme2510_bulk_write(dev, data , len_in, 1); /*Cold Resetting*/ 672 ret |= lme2510_bulk_write(dev, data , len_in, 1); /*Cold Resetting*/
703 ret |= lme2510_bulk_read(dev, data, len_in, 1); 673 ret |= lme2510_bulk_read(dev, data, len_in, 1);
674
704 return; 675 return;
705} 676}
706 677
707static void lme_firmware_switch(struct usb_device *udev, int cold) 678static int lme_firmware_switch(struct usb_device *udev, int cold)
708{ 679{
709 const struct firmware *fw = NULL; 680 const struct firmware *fw = NULL;
710 char lme2510c_s7395[] = "dvb-usb-lme2510c-s7395.fw"; 681 char lme2510c_s7395[] = "dvb-usb-lme2510c-s7395.fw";
@@ -712,8 +683,10 @@ static void lme_firmware_switch(struct usb_device *udev, int cold)
712 char *firm_msg[] = {"Loading", "Switching to"}; 683 char *firm_msg[] = {"Loading", "Switching to"};
713 int ret; 684 int ret;
714 685
686 cold = (cold > 0) ? (cold & 1) : 0;
687
715 if (udev->descriptor.idProduct == 0x1122) 688 if (udev->descriptor.idProduct == 0x1122)
716 return; 689 return 0;
717 690
718 switch (dvb_usb_lme2510_firmware) { 691 switch (dvb_usb_lme2510_firmware) {
719 case 0: 692 case 0:
@@ -740,22 +713,28 @@ static void lme_firmware_switch(struct usb_device *udev, int cold)
740 cold = 0; 713 cold = 0;
741 break; 714 break;
742 } 715 }
716
743 release_firmware(fw); 717 release_firmware(fw);
744 if (cold) 718
719 if (cold) {
745 lme_coldreset(udev); 720 lme_coldreset(udev);
746 return; 721 return -ENODEV;
722 }
723
724 return ret;
747} 725}
748 726
749static int lme2510_kill_urb(struct usb_data_stream *stream) 727static int lme2510_kill_urb(struct usb_data_stream *stream)
750{ 728{
751 int i; 729 int i;
730
752 for (i = 0; i < stream->urbs_submitted; i++) { 731 for (i = 0; i < stream->urbs_submitted; i++) {
753 deb_info(3, "killing URB no. %d.", i); 732 deb_info(3, "killing URB no. %d.", i);
754
755 /* stop the URB */ 733 /* stop the URB */
756 usb_kill_urb(stream->urb_list[i]); 734 usb_kill_urb(stream->urb_list[i]);
757 } 735 }
758 stream->urbs_submitted = 0; 736 stream->urbs_submitted = 0;
737
759 return 0; 738 return 0;
760} 739}
761 740
@@ -783,18 +762,13 @@ static int dm04_lme2510_set_voltage(struct dvb_frontend *fe,
783 fe_sec_voltage_t voltage) 762 fe_sec_voltage_t voltage)
784{ 763{
785 struct dvb_usb_adapter *adap = fe->dvb->priv; 764 struct dvb_usb_adapter *adap = fe->dvb->priv;
786 struct lme2510_state *st = adap->dev->priv;
787 static u8 voltage_low[] = LME_VOLTAGE_L; 765 static u8 voltage_low[] = LME_VOLTAGE_L;
788 static u8 voltage_high[] = LME_VOLTAGE_H; 766 static u8 voltage_high[] = LME_VOLTAGE_H;
789 static u8 lnb_on[] = LNB_ON;
790 static u8 lnb_off[] = LNB_OFF;
791 static u8 rbuf[1]; 767 static u8 rbuf[1];
792 int ret = 0, len = 3, rlen = 1; 768 int ret = 0, len = 3, rlen = 1;
793 769
794 if (st->stream_on == 1) 770 if (mutex_lock_interruptible(&adap->dev->i2c_mutex) < 0)
795 return 0; 771 return -EAGAIN;
796
797 ret |= lme2510_usb_talk(adap->dev, lnb_on, len, rbuf, rlen);
798 772
799 switch (voltage) { 773 switch (voltage) {
800 case SEC_VOLTAGE_18: 774 case SEC_VOLTAGE_18:
@@ -803,94 +777,143 @@ static int dm04_lme2510_set_voltage(struct dvb_frontend *fe,
803 break; 777 break;
804 778
805 case SEC_VOLTAGE_OFF: 779 case SEC_VOLTAGE_OFF:
806 ret |= lme2510_usb_talk(adap->dev,
807 lnb_off, len, rbuf, rlen);
808 case SEC_VOLTAGE_13: 780 case SEC_VOLTAGE_13:
809 default: 781 default:
810 ret |= lme2510_usb_talk(adap->dev, 782 ret |= lme2510_usb_talk(adap->dev,
811 voltage_low, len, rbuf, rlen); 783 voltage_low, len, rbuf, rlen);
812 break; 784 break;
785 }
813 786
787 mutex_unlock(&adap->dev->i2c_mutex);
814 788
815 };
816 st->i2c_talk_onoff = 1;
817 return (ret < 0) ? -ENODEV : 0; 789 return (ret < 0) ? -ENODEV : 0;
818} 790}
819 791
792static int lme_name(struct dvb_usb_adapter *adap)
793{
794 struct lme2510_state *st = adap->dev->priv;
795 const char *desc = adap->dev->desc->name;
796 char *fe_name[] = {"", " LG TDQY-P001F", " SHARP:BS2F7HZ7395"};
797 char *name = adap->fe->ops.info.name;
798
799 strlcpy(name, desc, 128);
800 strlcat(name, fe_name[st->tuner_config], 128);
801
802 return 0;
803}
804
820static int dm04_lme2510_frontend_attach(struct dvb_usb_adapter *adap) 805static int dm04_lme2510_frontend_attach(struct dvb_usb_adapter *adap)
821{ 806{
822 int ret = 0;
823 struct lme2510_state *st = adap->dev->priv; 807 struct lme2510_state *st = adap->dev->priv;
824 808
825 /* Interupt Start */ 809 int ret = 0;
826 ret = lme2510_int_service(adap);
827 if (ret < 0) {
828 info("INT Unable to start Interupt Service");
829 return -ENODEV;
830 }
831 810
832 st->i2c_talk_onoff = 1; 811 st->i2c_talk_onoff = 1;
833 st->i2c_gate = 4;
834 812
813 st->i2c_gate = 4;
835 adap->fe = dvb_attach(tda10086_attach, &tda10086_config, 814 adap->fe = dvb_attach(tda10086_attach, &tda10086_config,
836 &adap->dev->i2c_adap); 815 &adap->dev->i2c_adap);
837 816
838 if (adap->fe) { 817 if (adap->fe) {
839 info("TUN Found Frontend TDA10086"); 818 info("TUN Found Frontend TDA10086");
840 memcpy(&adap->fe->ops.info.name,
841 &"DM04_LG_TDQY-P001F DVB-S", 24);
842 adap->fe->ops.set_voltage = dm04_lme2510_set_voltage;
843 st->i2c_tuner_gate_w = 4; 819 st->i2c_tuner_gate_w = 4;
844 st->i2c_tuner_gate_r = 4; 820 st->i2c_tuner_gate_r = 4;
845 st->i2c_tuner_addr = 0xc0; 821 st->i2c_tuner_addr = 0xc0;
846 if (dvb_attach(tda826x_attach, adap->fe, 0xc0, 822 st->tuner_config = TUNER_LG;
847 &adap->dev->i2c_adap, 1)) { 823 if (dvb_usb_lme2510_firmware != 1) {
848 info("TUN TDA8263 Found"); 824 dvb_usb_lme2510_firmware = 1;
849 st->tuner_config = TUNER_LG; 825 ret = lme_firmware_switch(adap->dev->udev, 1);
850 if (dvb_usb_lme2510_firmware != 1) { 826 } else /*stops LG/Sharp multi tuner problems*/
851 dvb_usb_lme2510_firmware = 1; 827 dvb_usb_lme2510_firmware = 0;
852 lme_firmware_switch(adap->dev->udev, 1); 828 goto end;
853 }
854 return 0;
855 }
856 kfree(adap->fe);
857 adap->fe = NULL;
858 } 829 }
830
859 st->i2c_gate = 5; 831 st->i2c_gate = 5;
860 adap->fe = dvb_attach(stv0288_attach, &lme_config, 832 adap->fe = dvb_attach(stv0288_attach, &lme_config,
861 &adap->dev->i2c_adap); 833 &adap->dev->i2c_adap);
862 834
863 if (adap->fe) { 835 if (adap->fe) {
864 info("FE Found Stv0288"); 836 info("FE Found Stv0288");
865 memcpy(&adap->fe->ops.info.name,
866 &"DM04_SHARP:BS2F7HZ7395", 22);
867 adap->fe->ops.set_voltage = dm04_lme2510_set_voltage;
868 st->i2c_tuner_gate_w = 4; 837 st->i2c_tuner_gate_w = 4;
869 st->i2c_tuner_gate_r = 5; 838 st->i2c_tuner_gate_r = 5;
870 st->i2c_tuner_addr = 0xc0; 839 st->i2c_tuner_addr = 0xc0;
871 if (dvb_attach(ix2505v_attach , adap->fe, &lme_tuner, 840 st->tuner_config = TUNER_S7395;
872 &adap->dev->i2c_adap)) { 841 if (dvb_usb_lme2510_firmware != 0) {
873 st->tuner_config = TUNER_S7395; 842 dvb_usb_lme2510_firmware = 0;
874 info("TUN Sharp IX2505V silicon tuner"); 843 ret = lme_firmware_switch(adap->dev->udev, 1);
875 if (dvb_usb_lme2510_firmware != 0) {
876 dvb_usb_lme2510_firmware = 0;
877 lme_firmware_switch(adap->dev->udev, 1);
878 }
879 return 0;
880 } 844 }
845 } else {
846 info("DM04 Not Supported");
847 return -ENODEV;
848 }
849
850end: if (ret) {
881 kfree(adap->fe); 851 kfree(adap->fe);
882 adap->fe = NULL; 852 adap->fe = NULL;
853 return -ENODEV;
883 } 854 }
884 855
885 info("DM04 Not Supported"); 856 adap->fe->ops.set_voltage = dm04_lme2510_set_voltage;
886 return -ENODEV; 857 ret = lme_name(adap);
858
859 return ret;
860}
861
862static int dm04_lme2510_tuner(struct dvb_usb_adapter *adap)
863{
864 struct lme2510_state *st = adap->dev->priv;
865 char *tun_msg[] = {"", "TDA8263", "IX2505V"};
866 int ret = 0;
867
868 switch (st->tuner_config) {
869 case TUNER_LG:
870 if (dvb_attach(tda826x_attach, adap->fe, 0xc0,
871 &adap->dev->i2c_adap, 1))
872 ret = st->tuner_config;
873 break;
874 case TUNER_S7395:
875 if (dvb_attach(ix2505v_attach , adap->fe, &lme_tuner,
876 &adap->dev->i2c_adap))
877 ret = st->tuner_config;
878 break;
879 default:
880 break;
881 }
882
883 if (ret)
884 info("TUN Found %s tuner", tun_msg[ret]);
885 else {
886 info("TUN No tuner found --- reseting device");
887 lme_coldreset(adap->dev->udev);
888 return -ENODEV;
889 }
890
891 /* Start the Interupt & Remote*/
892 ret = lme2510_int_service(adap);
893
894 return ret;
887} 895}
888 896
889static int lme2510_powerup(struct dvb_usb_device *d, int onoff) 897static int lme2510_powerup(struct dvb_usb_device *d, int onoff)
890{ 898{
891 struct lme2510_state *st = d->priv; 899 struct lme2510_state *st = d->priv;
900 static u8 lnb_on[] = LNB_ON;
901 static u8 lnb_off[] = LNB_OFF;
902 static u8 rbuf[1];
903 int ret, len = 3, rlen = 1;
904
905 ret = mutex_lock_interruptible(&d->i2c_mutex);
906
907 if (onoff)
908 ret |= lme2510_usb_talk(d, lnb_on, len, rbuf, rlen);
909 else
910 ret |= lme2510_usb_talk(d, lnb_off, len, rbuf, rlen);
911
892 st->i2c_talk_onoff = 1; 912 st->i2c_talk_onoff = 1;
893 return 0; 913
914 mutex_unlock(&d->i2c_mutex);
915
916 return ret;
894} 917}
895 918
896/* DVB USB Driver stuff */ 919/* DVB USB Driver stuff */
@@ -951,6 +974,7 @@ static struct dvb_usb_device_properties lme2510_properties = {
951 { 974 {
952 .streaming_ctrl = lme2510_streaming_ctrl, 975 .streaming_ctrl = lme2510_streaming_ctrl,
953 .frontend_attach = dm04_lme2510_frontend_attach, 976 .frontend_attach = dm04_lme2510_frontend_attach,
977 .tuner_attach = dm04_lme2510_tuner,
954 /* parameter for the MPEG2-data transfer */ 978 /* parameter for the MPEG2-data transfer */
955 .stream = { 979 .stream = {
956 .type = USB_BULK, 980 .type = USB_BULK,
@@ -971,7 +995,7 @@ static struct dvb_usb_device_properties lme2510_properties = {
971 .generic_bulk_ctrl_endpoint = 0, 995 .generic_bulk_ctrl_endpoint = 0,
972 .num_device_descs = 1, 996 .num_device_descs = 1,
973 .devices = { 997 .devices = {
974 { "DM04 LME2510 DVB-S USB 2.0", 998 { "DM04_LME2510_DVB-S",
975 { &lme2510_table[0], NULL }, 999 { &lme2510_table[0], NULL },
976 }, 1000 },
977 1001
@@ -989,6 +1013,7 @@ static struct dvb_usb_device_properties lme2510c_properties = {
989 { 1013 {
990 .streaming_ctrl = lme2510_streaming_ctrl, 1014 .streaming_ctrl = lme2510_streaming_ctrl,
991 .frontend_attach = dm04_lme2510_frontend_attach, 1015 .frontend_attach = dm04_lme2510_frontend_attach,
1016 .tuner_attach = dm04_lme2510_tuner,
992 /* parameter for the MPEG2-data transfer */ 1017 /* parameter for the MPEG2-data transfer */
993 .stream = { 1018 .stream = {
994 .type = USB_BULK, 1019 .type = USB_BULK,
@@ -1009,7 +1034,7 @@ static struct dvb_usb_device_properties lme2510c_properties = {
1009 .generic_bulk_ctrl_endpoint = 0, 1034 .generic_bulk_ctrl_endpoint = 0,
1010 .num_device_descs = 1, 1035 .num_device_descs = 1,
1011 .devices = { 1036 .devices = {
1012 { "DM04 LME2510C USB2.0", 1037 { "DM04_LME2510C_DVB-S",
1013 { &lme2510_table[1], NULL }, 1038 { &lme2510_table[1], NULL },
1014 }, 1039 },
1015 } 1040 }
@@ -1036,7 +1061,7 @@ void *lme2510_exit_int(struct dvb_usb_device *d)
1036 usb_free_coherent(d->udev, 5000, st->buffer, 1061 usb_free_coherent(d->udev, 5000, st->buffer,
1037 st->lme_urb->transfer_dma); 1062 st->lme_urb->transfer_dma);
1038 info("Interupt Service Stopped"); 1063 info("Interupt Service Stopped");
1039 ir_input_unregister(d->rc_input_dev); 1064 rc_unregister_device(d->rc_dev);
1040 info("Remote Stopped"); 1065 info("Remote Stopped");
1041 } 1066 }
1042 return buffer; 1067 return buffer;
@@ -1055,7 +1080,7 @@ void lme2510_exit(struct usb_interface *intf)
1055} 1080}
1056 1081
1057static struct usb_driver lme2510_driver = { 1082static struct usb_driver lme2510_driver = {
1058 .name = "LME2510C_DVBS", 1083 .name = "LME2510C_DVB-S",
1059 .probe = lme2510_probe, 1084 .probe = lme2510_probe,
1060 .disconnect = lme2510_exit, 1085 .disconnect = lme2510_exit,
1061 .id_table = lme2510_table, 1086 .id_table = lme2510_table,
@@ -1083,6 +1108,6 @@ module_init(lme2510_module_init);
1083module_exit(lme2510_module_exit); 1108module_exit(lme2510_module_exit);
1084 1109
1085MODULE_AUTHOR("Malcolm Priestley <tvboxspy@gmail.com>"); 1110MODULE_AUTHOR("Malcolm Priestley <tvboxspy@gmail.com>");
1086MODULE_DESCRIPTION("LM2510(C) DVB-S USB2.0"); 1111MODULE_DESCRIPTION("LME2510(C) DVB-S USB2.0");
1087MODULE_VERSION("1.60"); 1112MODULE_VERSION("1.74");
1088MODULE_LICENSE("GPL"); 1113MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/dvb-usb/m920x.c b/drivers/media/dvb/dvb-usb/m920x.c
index bdef1a18b664..da9dc91ce910 100644
--- a/drivers/media/dvb/dvb-usb/m920x.c
+++ b/drivers/media/dvb/dvb-usb/m920x.c
@@ -142,9 +142,9 @@ static int m920x_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
142 if ((ret = m920x_read(d->udev, M9206_CORE, 0x0, M9206_RC_KEY, rc_state + 1, 1)) != 0) 142 if ((ret = m920x_read(d->udev, M9206_CORE, 0x0, M9206_RC_KEY, rc_state + 1, 1)) != 0)
143 goto unlock; 143 goto unlock;
144 144
145 for (i = 0; i < d->props.rc.legacy.rc_key_map_size; i++) 145 for (i = 0; i < d->props.rc.legacy.rc_map_size; i++)
146 if (rc5_data(&d->props.rc.legacy.rc_key_map[i]) == rc_state[1]) { 146 if (rc5_data(&d->props.rc.legacy.rc_map_table[i]) == rc_state[1]) {
147 *event = d->props.rc.legacy.rc_key_map[i].keycode; 147 *event = d->props.rc.legacy.rc_map_table[i].keycode;
148 148
149 switch(rc_state[0]) { 149 switch(rc_state[0]) {
150 case 0x80: 150 case 0x80:
@@ -589,7 +589,7 @@ static struct m920x_inits pinnacle310e_init[] = {
589}; 589};
590 590
591/* ir keymaps */ 591/* ir keymaps */
592static struct ir_scancode ir_codes_megasky_table[] = { 592static struct rc_map_table rc_map_megasky_table[] = {
593 { 0x0012, KEY_POWER }, 593 { 0x0012, KEY_POWER },
594 { 0x001e, KEY_CYCLEWINDOWS }, /* min/max */ 594 { 0x001e, KEY_CYCLEWINDOWS }, /* min/max */
595 { 0x0002, KEY_CHANNELUP }, 595 { 0x0002, KEY_CHANNELUP },
@@ -608,7 +608,7 @@ static struct ir_scancode ir_codes_megasky_table[] = {
608 { 0x000e, KEY_COFFEE }, /* "MTS" */ 608 { 0x000e, KEY_COFFEE }, /* "MTS" */
609}; 609};
610 610
611static struct ir_scancode ir_codes_tvwalkertwin_table[] = { 611static struct rc_map_table rc_map_tvwalkertwin_table[] = {
612 { 0x0001, KEY_ZOOM }, /* Full Screen */ 612 { 0x0001, KEY_ZOOM }, /* Full Screen */
613 { 0x0002, KEY_CAMERA }, /* snapshot */ 613 { 0x0002, KEY_CAMERA }, /* snapshot */
614 { 0x0003, KEY_MUTE }, 614 { 0x0003, KEY_MUTE },
@@ -628,7 +628,7 @@ static struct ir_scancode ir_codes_tvwalkertwin_table[] = {
628 { 0x001e, KEY_VOLUMEUP }, 628 { 0x001e, KEY_VOLUMEUP },
629}; 629};
630 630
631static struct ir_scancode ir_codes_pinnacle310e_table[] = { 631static struct rc_map_table rc_map_pinnacle310e_table[] = {
632 { 0x16, KEY_POWER }, 632 { 0x16, KEY_POWER },
633 { 0x17, KEY_FAVORITES }, 633 { 0x17, KEY_FAVORITES },
634 { 0x0f, KEY_TEXT }, 634 { 0x0f, KEY_TEXT },
@@ -786,8 +786,8 @@ static struct dvb_usb_device_properties megasky_properties = {
786 786
787 .rc.legacy = { 787 .rc.legacy = {
788 .rc_interval = 100, 788 .rc_interval = 100,
789 .rc_key_map = ir_codes_megasky_table, 789 .rc_map_table = rc_map_megasky_table,
790 .rc_key_map_size = ARRAY_SIZE(ir_codes_megasky_table), 790 .rc_map_size = ARRAY_SIZE(rc_map_megasky_table),
791 .rc_query = m920x_rc_query, 791 .rc_query = m920x_rc_query,
792 }, 792 },
793 793
@@ -889,8 +889,8 @@ static struct dvb_usb_device_properties tvwalkertwin_properties = {
889 889
890 .rc.legacy = { 890 .rc.legacy = {
891 .rc_interval = 100, 891 .rc_interval = 100,
892 .rc_key_map = ir_codes_tvwalkertwin_table, 892 .rc_map_table = rc_map_tvwalkertwin_table,
893 .rc_key_map_size = ARRAY_SIZE(ir_codes_tvwalkertwin_table), 893 .rc_map_size = ARRAY_SIZE(rc_map_tvwalkertwin_table),
894 .rc_query = m920x_rc_query, 894 .rc_query = m920x_rc_query,
895 }, 895 },
896 896
@@ -998,8 +998,8 @@ static struct dvb_usb_device_properties pinnacle_pctv310e_properties = {
998 998
999 .rc.legacy = { 999 .rc.legacy = {
1000 .rc_interval = 100, 1000 .rc_interval = 100,
1001 .rc_key_map = ir_codes_pinnacle310e_table, 1001 .rc_map_table = rc_map_pinnacle310e_table,
1002 .rc_key_map_size = ARRAY_SIZE(ir_codes_pinnacle310e_table), 1002 .rc_map_size = ARRAY_SIZE(rc_map_pinnacle310e_table),
1003 .rc_query = m920x_rc_query, 1003 .rc_query = m920x_rc_query,
1004 }, 1004 },
1005 1005
diff --git a/drivers/media/dvb/dvb-usb/nova-t-usb2.c b/drivers/media/dvb/dvb-usb/nova-t-usb2.c
index 181f36a12e2a..9d3cd2de46fc 100644
--- a/drivers/media/dvb/dvb-usb/nova-t-usb2.c
+++ b/drivers/media/dvb/dvb-usb/nova-t-usb2.c
@@ -21,7 +21,7 @@ DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
21#define deb_ee(args...) dprintk(debug,0x02,args) 21#define deb_ee(args...) dprintk(debug,0x02,args)
22 22
23/* Hauppauge NOVA-T USB2 keys */ 23/* Hauppauge NOVA-T USB2 keys */
24static struct ir_scancode ir_codes_haupp_table[] = { 24static struct rc_map_table rc_map_haupp_table[] = {
25 { 0x1e00, KEY_0 }, 25 { 0x1e00, KEY_0 },
26 { 0x1e01, KEY_1 }, 26 { 0x1e01, KEY_1 },
27 { 0x1e02, KEY_2 }, 27 { 0x1e02, KEY_2 },
@@ -91,14 +91,14 @@ static int nova_t_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
91 91
92 deb_rc("raw key code 0x%02x, 0x%02x, 0x%02x to c: %02x d: %02x toggle: %d\n",key[1],key[2],key[3],custom,data,toggle); 92 deb_rc("raw key code 0x%02x, 0x%02x, 0x%02x to c: %02x d: %02x toggle: %d\n",key[1],key[2],key[3],custom,data,toggle);
93 93
94 for (i = 0; i < ARRAY_SIZE(ir_codes_haupp_table); i++) { 94 for (i = 0; i < ARRAY_SIZE(rc_map_haupp_table); i++) {
95 if (rc5_data(&ir_codes_haupp_table[i]) == data && 95 if (rc5_data(&rc_map_haupp_table[i]) == data &&
96 rc5_custom(&ir_codes_haupp_table[i]) == custom) { 96 rc5_custom(&rc_map_haupp_table[i]) == custom) {
97 97
98 deb_rc("c: %x, d: %x\n", rc5_data(&ir_codes_haupp_table[i]), 98 deb_rc("c: %x, d: %x\n", rc5_data(&rc_map_haupp_table[i]),
99 rc5_custom(&ir_codes_haupp_table[i])); 99 rc5_custom(&rc_map_haupp_table[i]));
100 100
101 *event = ir_codes_haupp_table[i].keycode; 101 *event = rc_map_haupp_table[i].keycode;
102 *state = REMOTE_KEY_PRESSED; 102 *state = REMOTE_KEY_PRESSED;
103 if (st->old_toggle == toggle) { 103 if (st->old_toggle == toggle) {
104 if (st->last_repeat_count++ < 2) 104 if (st->last_repeat_count++ < 2)
@@ -197,8 +197,8 @@ static struct dvb_usb_device_properties nova_t_properties = {
197 197
198 .rc.legacy = { 198 .rc.legacy = {
199 .rc_interval = 100, 199 .rc_interval = 100,
200 .rc_key_map = ir_codes_haupp_table, 200 .rc_map_table = rc_map_haupp_table,
201 .rc_key_map_size = ARRAY_SIZE(ir_codes_haupp_table), 201 .rc_map_size = ARRAY_SIZE(rc_map_haupp_table),
202 .rc_query = nova_t_rc_query, 202 .rc_query = nova_t_rc_query,
203 }, 203 },
204 204
diff --git a/drivers/media/dvb/dvb-usb/opera1.c b/drivers/media/dvb/dvb-usb/opera1.c
index f896337b4535..1f1b7d6980a5 100644
--- a/drivers/media/dvb/dvb-usb/opera1.c
+++ b/drivers/media/dvb/dvb-usb/opera1.c
@@ -35,7 +35,7 @@
35struct opera1_state { 35struct opera1_state {
36 u32 last_key_pressed; 36 u32 last_key_pressed;
37}; 37};
38struct ir_codes_opera_table { 38struct rc_map_opera_table {
39 u32 keycode; 39 u32 keycode;
40 u32 event; 40 u32 event;
41}; 41};
@@ -331,7 +331,7 @@ static int opera1_pid_filter_control(struct dvb_usb_adapter *adap, int onoff)
331 return 0; 331 return 0;
332} 332}
333 333
334static struct ir_scancode ir_codes_opera1_table[] = { 334static struct rc_map_table rc_map_opera1_table[] = {
335 {0x5fa0, KEY_1}, 335 {0x5fa0, KEY_1},
336 {0x51af, KEY_2}, 336 {0x51af, KEY_2},
337 {0x5da2, KEY_3}, 337 {0x5da2, KEY_3},
@@ -404,12 +404,12 @@ static int opera1_rc_query(struct dvb_usb_device *dev, u32 * event, int *state)
404 404
405 send_key = (send_key & 0xffff) | 0x0100; 405 send_key = (send_key & 0xffff) | 0x0100;
406 406
407 for (i = 0; i < ARRAY_SIZE(ir_codes_opera1_table); i++) { 407 for (i = 0; i < ARRAY_SIZE(rc_map_opera1_table); i++) {
408 if (rc5_scan(&ir_codes_opera1_table[i]) == (send_key & 0xffff)) { 408 if (rc5_scan(&rc_map_opera1_table[i]) == (send_key & 0xffff)) {
409 *state = REMOTE_KEY_PRESSED; 409 *state = REMOTE_KEY_PRESSED;
410 *event = ir_codes_opera1_table[i].keycode; 410 *event = rc_map_opera1_table[i].keycode;
411 opst->last_key_pressed = 411 opst->last_key_pressed =
412 ir_codes_opera1_table[i].keycode; 412 rc_map_opera1_table[i].keycode;
413 break; 413 break;
414 } 414 }
415 opst->last_key_pressed = 0; 415 opst->last_key_pressed = 0;
@@ -497,8 +497,8 @@ static struct dvb_usb_device_properties opera1_properties = {
497 .i2c_algo = &opera1_i2c_algo, 497 .i2c_algo = &opera1_i2c_algo,
498 498
499 .rc.legacy = { 499 .rc.legacy = {
500 .rc_key_map = ir_codes_opera1_table, 500 .rc_map_table = rc_map_opera1_table,
501 .rc_key_map_size = ARRAY_SIZE(ir_codes_opera1_table), 501 .rc_map_size = ARRAY_SIZE(rc_map_opera1_table),
502 .rc_interval = 200, 502 .rc_interval = 200,
503 .rc_query = opera1_rc_query, 503 .rc_query = opera1_rc_query,
504 }, 504 },
diff --git a/drivers/media/dvb/dvb-usb/ttusb2.c b/drivers/media/dvb/dvb-usb/ttusb2.c
index a6de489a6a39..0d4709ff9cbb 100644
--- a/drivers/media/dvb/dvb-usb/ttusb2.c
+++ b/drivers/media/dvb/dvb-usb/ttusb2.c
@@ -43,6 +43,7 @@ DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
43 43
44struct ttusb2_state { 44struct ttusb2_state {
45 u8 id; 45 u8 id;
46 u16 last_rc_key;
46}; 47};
47 48
48static int ttusb2_msg(struct dvb_usb_device *d, u8 cmd, 49static int ttusb2_msg(struct dvb_usb_device *d, u8 cmd,
@@ -128,6 +129,33 @@ static struct i2c_algorithm ttusb2_i2c_algo = {
128 .functionality = ttusb2_i2c_func, 129 .functionality = ttusb2_i2c_func,
129}; 130};
130 131
132/* command to poll IR receiver (copied from pctv452e.c) */
133#define CMD_GET_IR_CODE 0x1b
134
135/* IR */
136static int tt3650_rc_query(struct dvb_usb_device *d)
137{
138 int ret;
139 u8 rx[9]; /* A CMD_GET_IR_CODE reply is 9 bytes long */
140 struct ttusb2_state *st = d->priv;
141 ret = ttusb2_msg(d, CMD_GET_IR_CODE, NULL, 0, rx, sizeof(rx));
142 if (ret != 0)
143 return ret;
144
145 if (rx[8] & 0x01) {
146 /* got a "press" event */
147 st->last_rc_key = (rx[3] << 8) | rx[2];
148 deb_info("%s: cmd=0x%02x sys=0x%02x\n", __func__, rx[2], rx[3]);
149 rc_keydown(d->rc_dev, st->last_rc_key, 0);
150 } else if (st->last_rc_key) {
151 rc_keyup(d->rc_dev);
152 st->last_rc_key = 0;
153 }
154
155 return 0;
156}
157
158
131/* Callbacks for DVB USB */ 159/* Callbacks for DVB USB */
132static int ttusb2_identify_state (struct usb_device *udev, struct 160static int ttusb2_identify_state (struct usb_device *udev, struct
133 dvb_usb_device_properties *props, struct dvb_usb_device_description **desc, 161 dvb_usb_device_properties *props, struct dvb_usb_device_description **desc,
@@ -345,6 +373,13 @@ static struct dvb_usb_device_properties ttusb2_properties_ct3650 = {
345 373
346 .size_of_priv = sizeof(struct ttusb2_state), 374 .size_of_priv = sizeof(struct ttusb2_state),
347 375
376 .rc.core = {
377 .rc_interval = 150, /* Less than IR_KEYPRESS_TIMEOUT */
378 .rc_codes = RC_MAP_TT_1500,
379 .rc_query = tt3650_rc_query,
380 .allowed_protos = RC_TYPE_UNKNOWN,
381 },
382
348 .num_adapters = 1, 383 .num_adapters = 1,
349 .adapter = { 384 .adapter = {
350 { 385 {
diff --git a/drivers/media/dvb/dvb-usb/vp702x.c b/drivers/media/dvb/dvb-usb/vp702x.c
index 5c9f3275aaa0..7890e75600df 100644
--- a/drivers/media/dvb/dvb-usb/vp702x.c
+++ b/drivers/media/dvb/dvb-usb/vp702x.c
@@ -174,7 +174,7 @@ static int vp702x_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
174} 174}
175 175
176/* keys for the enclosed remote control */ 176/* keys for the enclosed remote control */
177static struct ir_scancode ir_codes_vp702x_table[] = { 177static struct rc_map_table rc_map_vp702x_table[] = {
178 { 0x0001, KEY_1 }, 178 { 0x0001, KEY_1 },
179 { 0x0002, KEY_2 }, 179 { 0x0002, KEY_2 },
180}; 180};
@@ -197,10 +197,10 @@ static int vp702x_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
197 return 0; 197 return 0;
198 } 198 }
199 199
200 for (i = 0; i < ARRAY_SIZE(ir_codes_vp702x_table); i++) 200 for (i = 0; i < ARRAY_SIZE(rc_map_vp702x_table); i++)
201 if (rc5_custom(&ir_codes_vp702x_table[i]) == key[1]) { 201 if (rc5_custom(&rc_map_vp702x_table[i]) == key[1]) {
202 *state = REMOTE_KEY_PRESSED; 202 *state = REMOTE_KEY_PRESSED;
203 *event = ir_codes_vp702x_table[i].keycode; 203 *event = rc_map_vp702x_table[i].keycode;
204 break; 204 break;
205 } 205 }
206 return 0; 206 return 0;
@@ -284,8 +284,8 @@ static struct dvb_usb_device_properties vp702x_properties = {
284 .read_mac_address = vp702x_read_mac_addr, 284 .read_mac_address = vp702x_read_mac_addr,
285 285
286 .rc.legacy = { 286 .rc.legacy = {
287 .rc_key_map = ir_codes_vp702x_table, 287 .rc_map_table = rc_map_vp702x_table,
288 .rc_key_map_size = ARRAY_SIZE(ir_codes_vp702x_table), 288 .rc_map_size = ARRAY_SIZE(rc_map_vp702x_table),
289 .rc_interval = 400, 289 .rc_interval = 400,
290 .rc_query = vp702x_rc_query, 290 .rc_query = vp702x_rc_query,
291 }, 291 },
diff --git a/drivers/media/dvb/dvb-usb/vp7045.c b/drivers/media/dvb/dvb-usb/vp7045.c
index f13791ca5994..ab0ab3c35e80 100644
--- a/drivers/media/dvb/dvb-usb/vp7045.c
+++ b/drivers/media/dvb/dvb-usb/vp7045.c
@@ -99,7 +99,7 @@ static int vp7045_power_ctrl(struct dvb_usb_device *d, int onoff)
99 99
100/* The keymapping struct. Somehow this should be loaded to the driver, but 100/* The keymapping struct. Somehow this should be loaded to the driver, but
101 * currently it is hardcoded. */ 101 * currently it is hardcoded. */
102static struct ir_scancode ir_codes_vp7045_table[] = { 102static struct rc_map_table rc_map_vp7045_table[] = {
103 { 0x0016, KEY_POWER }, 103 { 0x0016, KEY_POWER },
104 { 0x0010, KEY_MUTE }, 104 { 0x0010, KEY_MUTE },
105 { 0x0003, KEY_1 }, 105 { 0x0003, KEY_1 },
@@ -165,10 +165,10 @@ static int vp7045_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
165 return 0; 165 return 0;
166 } 166 }
167 167
168 for (i = 0; i < ARRAY_SIZE(ir_codes_vp7045_table); i++) 168 for (i = 0; i < ARRAY_SIZE(rc_map_vp7045_table); i++)
169 if (rc5_data(&ir_codes_vp7045_table[i]) == key) { 169 if (rc5_data(&rc_map_vp7045_table[i]) == key) {
170 *state = REMOTE_KEY_PRESSED; 170 *state = REMOTE_KEY_PRESSED;
171 *event = ir_codes_vp7045_table[i].keycode; 171 *event = rc_map_vp7045_table[i].keycode;
172 break; 172 break;
173 } 173 }
174 return 0; 174 return 0;
@@ -261,8 +261,8 @@ static struct dvb_usb_device_properties vp7045_properties = {
261 261
262 .rc.legacy = { 262 .rc.legacy = {
263 .rc_interval = 400, 263 .rc_interval = 400,
264 .rc_key_map = ir_codes_vp7045_table, 264 .rc_map_table = rc_map_vp7045_table,
265 .rc_key_map_size = ARRAY_SIZE(ir_codes_vp7045_table), 265 .rc_map_size = ARRAY_SIZE(rc_map_vp7045_table),
266 .rc_query = vp7045_rc_query, 266 .rc_query = vp7045_rc_query,
267 }, 267 },
268 268
diff --git a/drivers/media/dvb/frontends/Kconfig b/drivers/media/dvb/frontends/Kconfig
index 96b27016670e..ef3e43a03199 100644
--- a/drivers/media/dvb/frontends/Kconfig
+++ b/drivers/media/dvb/frontends/Kconfig
@@ -497,7 +497,7 @@ comment "ISDB-T (terrestrial) frontends"
497 depends on DVB_CORE 497 depends on DVB_CORE
498 498
499config DVB_S921 499config DVB_S921
500 tristate "Sharp S921 tuner" 500 tristate "Sharp S921 frontend"
501 depends on DVB_CORE && I2C 501 depends on DVB_CORE && I2C
502 default m if DVB_FE_CUSTOMISE 502 default m if DVB_FE_CUSTOMISE
503 help 503 help
@@ -512,6 +512,14 @@ config DVB_DIB8000
512 A driver for DiBcom's DiB8000 ISDB-T/ISDB-Tsb demodulator. 512 A driver for DiBcom's DiB8000 ISDB-T/ISDB-Tsb demodulator.
513 Say Y when you want to support this frontend. 513 Say Y when you want to support this frontend.
514 514
515config DVB_MB86A20S
516 tristate "Fujitsu mb86a20s"
517 depends on DVB_CORE && I2C
518 default m if DVB_FE_CUSTOMISE
519 help
520 A driver for Fujitsu mb86a20s ISDB-T/ISDB-Tsb demodulator.
521 Say Y when you want to support this frontend.
522
515comment "Digital terrestrial only tuners/PLL" 523comment "Digital terrestrial only tuners/PLL"
516 depends on DVB_CORE 524 depends on DVB_CORE
517 525
diff --git a/drivers/media/dvb/frontends/Makefile b/drivers/media/dvb/frontends/Makefile
index 9a31985c0dfb..b1d9525aa7e3 100644
--- a/drivers/media/dvb/frontends/Makefile
+++ b/drivers/media/dvb/frontends/Makefile
@@ -5,7 +5,6 @@
5EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/ 5EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/
6EXTRA_CFLAGS += -Idrivers/media/common/tuners/ 6EXTRA_CFLAGS += -Idrivers/media/common/tuners/
7 7
8s921-objs := s921_module.o s921_core.o
9stb0899-objs = stb0899_drv.o stb0899_algo.o 8stb0899-objs = stb0899_drv.o stb0899_algo.o
10stv0900-objs = stv0900_core.o stv0900_sw.o 9stv0900-objs = stv0900_core.o stv0900_sw.o
11au8522-objs = au8522_dig.o au8522_decoder.o 10au8522-objs = au8522_dig.o au8522_decoder.o
@@ -82,4 +81,5 @@ obj-$(CONFIG_DVB_ISL6423) += isl6423.o
82obj-$(CONFIG_DVB_EC100) += ec100.o 81obj-$(CONFIG_DVB_EC100) += ec100.o
83obj-$(CONFIG_DVB_DS3000) += ds3000.o 82obj-$(CONFIG_DVB_DS3000) += ds3000.o
84obj-$(CONFIG_DVB_MB86A16) += mb86a16.o 83obj-$(CONFIG_DVB_MB86A16) += mb86a16.o
84obj-$(CONFIG_DVB_MB86A20S) += mb86a20s.o
85obj-$(CONFIG_DVB_IX2505V) += ix2505v.o 85obj-$(CONFIG_DVB_IX2505V) += ix2505v.o
diff --git a/drivers/media/dvb/frontends/af9013.c b/drivers/media/dvb/frontends/af9013.c
index e2a95c07bab4..ce222055526d 100644
--- a/drivers/media/dvb/frontends/af9013.c
+++ b/drivers/media/dvb/frontends/af9013.c
@@ -964,7 +964,7 @@ error:
964static int af9013_update_signal_strength(struct dvb_frontend *fe) 964static int af9013_update_signal_strength(struct dvb_frontend *fe)
965{ 965{
966 struct af9013_state *state = fe->demodulator_priv; 966 struct af9013_state *state = fe->demodulator_priv;
967 int ret; 967 int ret = 0;
968 u8 rf_gain, if_gain; 968 u8 rf_gain, if_gain;
969 int signal_strength; 969 int signal_strength;
970 970
diff --git a/drivers/media/dvb/frontends/atbm8830.c b/drivers/media/dvb/frontends/atbm8830.c
index 43aac2f85c2e..1539ea1f81ac 100644
--- a/drivers/media/dvb/frontends/atbm8830.c
+++ b/drivers/media/dvb/frontends/atbm8830.c
@@ -50,8 +50,7 @@ static int atbm8830_write_reg(struct atbm_state *priv, u16 reg, u8 data)
50 msg2.addr = dev_addr; 50 msg2.addr = dev_addr;
51 51
52 if (debug >= 2) 52 if (debug >= 2)
53 printk(KERN_DEBUG "%s: reg=0x%04X, data=0x%02X\n", 53 dprintk("%s: reg=0x%04X, data=0x%02X\n", __func__, reg, data);
54 __func__, reg, data);
55 54
56 ret = i2c_transfer(priv->i2c, &msg1, 1); 55 ret = i2c_transfer(priv->i2c, &msg1, 1);
57 if (ret != 1) 56 if (ret != 1)
@@ -77,8 +76,7 @@ static int atbm8830_read_reg(struct atbm_state *priv, u16 reg, u8 *p_data)
77 76
78 ret = i2c_transfer(priv->i2c, &msg1, 1); 77 ret = i2c_transfer(priv->i2c, &msg1, 1);
79 if (ret != 1) { 78 if (ret != 1) {
80 dprintk(KERN_DEBUG "%s: error reg=0x%04x, ret=%i\n", 79 dprintk("%s: error reg=0x%04x, ret=%i\n", __func__, reg, ret);
81 __func__, reg, ret);
82 return -EIO; 80 return -EIO;
83 } 81 }
84 82
@@ -88,7 +86,7 @@ static int atbm8830_read_reg(struct atbm_state *priv, u16 reg, u8 *p_data)
88 86
89 *p_data = buf2[0]; 87 *p_data = buf2[0];
90 if (debug >= 2) 88 if (debug >= 2)
91 printk(KERN_DEBUG "%s: reg=0x%04X, data=0x%02X\n", 89 dprintk("%s: reg=0x%04X, data=0x%02X\n",
92 __func__, reg, buf2[0]); 90 __func__, reg, buf2[0]);
93 91
94 return 0; 92 return 0;
diff --git a/drivers/media/dvb/frontends/au8522_decoder.c b/drivers/media/dvb/frontends/au8522_decoder.c
index 6d9c5943eb3d..b537891a4cc9 100644
--- a/drivers/media/dvb/frontends/au8522_decoder.c
+++ b/drivers/media/dvb/frontends/au8522_decoder.c
@@ -278,10 +278,18 @@ static void setup_decoder_defaults(struct au8522_state *state, u8 input_mode)
278 AU8522_TVDEC_COMB_HDIF_THR2_REG06AH_CVBS); 278 AU8522_TVDEC_COMB_HDIF_THR2_REG06AH_CVBS);
279 au8522_writereg(state, AU8522_TVDEC_COMB_HDIF_THR3_REG06BH, 279 au8522_writereg(state, AU8522_TVDEC_COMB_HDIF_THR3_REG06BH,
280 AU8522_TVDEC_COMB_HDIF_THR3_REG06BH_CVBS); 280 AU8522_TVDEC_COMB_HDIF_THR3_REG06BH_CVBS);
281 au8522_writereg(state, AU8522_TVDEC_COMB_DCDIF_THR1_REG06CH, 281 if (input_mode == AU8522_INPUT_CONTROL_REG081H_SVIDEO_CH13 ||
282 AU8522_TVDEC_COMB_DCDIF_THR1_REG06CH_CVBS); 282 input_mode == AU8522_INPUT_CONTROL_REG081H_SVIDEO_CH24) {
283 au8522_writereg(state, AU8522_TVDEC_COMB_DCDIF_THR2_REG06DH, 283 au8522_writereg(state, AU8522_TVDEC_COMB_DCDIF_THR1_REG06CH,
284 AU8522_TVDEC_COMB_DCDIF_THR2_REG06DH_CVBS); 284 AU8522_TVDEC_COMB_DCDIF_THR1_REG06CH_SVIDEO);
285 au8522_writereg(state, AU8522_TVDEC_COMB_DCDIF_THR2_REG06DH,
286 AU8522_TVDEC_COMB_DCDIF_THR2_REG06DH_SVIDEO);
287 } else {
288 au8522_writereg(state, AU8522_TVDEC_COMB_DCDIF_THR1_REG06CH,
289 AU8522_TVDEC_COMB_DCDIF_THR1_REG06CH_CVBS);
290 au8522_writereg(state, AU8522_TVDEC_COMB_DCDIF_THR2_REG06DH,
291 AU8522_TVDEC_COMB_DCDIF_THR2_REG06DH_CVBS);
292 }
285 au8522_writereg(state, AU8522_TVDEC_COMB_DCDIF_THR3_REG06EH, 293 au8522_writereg(state, AU8522_TVDEC_COMB_DCDIF_THR3_REG06EH,
286 AU8522_TVDEC_COMB_DCDIF_THR3_REG06EH_CVBS); 294 AU8522_TVDEC_COMB_DCDIF_THR3_REG06EH_CVBS);
287 au8522_writereg(state, AU8522_TVDEC_UV_SEP_THR_REG06FH, 295 au8522_writereg(state, AU8522_TVDEC_UV_SEP_THR_REG06FH,
@@ -347,9 +355,11 @@ static void au8522_setup_cvbs_mode(struct au8522_state *state)
347 au8522_writereg(state, AU8522_MODULE_CLOCK_CONTROL_REG0A3H, 355 au8522_writereg(state, AU8522_MODULE_CLOCK_CONTROL_REG0A3H,
348 AU8522_MODULE_CLOCK_CONTROL_REG0A3H_CVBS); 356 AU8522_MODULE_CLOCK_CONTROL_REG0A3H_CVBS);
349 357
358 /* PGA in automatic mode */
350 au8522_writereg(state, AU8522_PGA_CONTROL_REG082H, 0x00); 359 au8522_writereg(state, AU8522_PGA_CONTROL_REG082H, 0x00);
351 au8522_writereg(state, AU8522_CLAMPING_CONTROL_REG083H, 0x0e); 360
352 au8522_writereg(state, AU8522_PGA_CONTROL_REG082H, 0x10); 361 /* Enable clamping control */
362 au8522_writereg(state, AU8522_CLAMPING_CONTROL_REG083H, 0x00);
353 363
354 au8522_writereg(state, AU8522_INPUT_CONTROL_REG081H, 364 au8522_writereg(state, AU8522_INPUT_CONTROL_REG081H,
355 AU8522_INPUT_CONTROL_REG081H_CVBS_CH1); 365 AU8522_INPUT_CONTROL_REG081H_CVBS_CH1);
@@ -366,14 +376,14 @@ static void au8522_setup_cvbs_tuner_mode(struct au8522_state *state)
366 au8522_writereg(state, AU8522_MODULE_CLOCK_CONTROL_REG0A3H, 376 au8522_writereg(state, AU8522_MODULE_CLOCK_CONTROL_REG0A3H,
367 AU8522_MODULE_CLOCK_CONTROL_REG0A3H_CVBS); 377 AU8522_MODULE_CLOCK_CONTROL_REG0A3H_CVBS);
368 378
369 /* It's not clear why they turn off the PGA before enabling the clamp 379 /* It's not clear why we have to have the PGA in automatic mode while
370 control, but the Windows trace does it so we will too... */ 380 enabling clamp control, but it's what Windows does */
371 au8522_writereg(state, AU8522_PGA_CONTROL_REG082H, 0x00); 381 au8522_writereg(state, AU8522_PGA_CONTROL_REG082H, 0x00);
372 382
373 /* Enable clamping control */ 383 /* Enable clamping control */
374 au8522_writereg(state, AU8522_CLAMPING_CONTROL_REG083H, 0x0e); 384 au8522_writereg(state, AU8522_CLAMPING_CONTROL_REG083H, 0x0e);
375 385
376 /* Turn on the PGA */ 386 /* Disable automatic PGA (since the CVBS is coming from the tuner) */
377 au8522_writereg(state, AU8522_PGA_CONTROL_REG082H, 0x10); 387 au8522_writereg(state, AU8522_PGA_CONTROL_REG082H, 0x10);
378 388
379 /* Set input mode to CVBS on channel 4 with SIF audio input enabled */ 389 /* Set input mode to CVBS on channel 4 with SIF audio input enabled */
@@ -396,7 +406,10 @@ static void au8522_setup_svideo_mode(struct au8522_state *state)
396 au8522_writereg(state, AU8522_INPUT_CONTROL_REG081H, 406 au8522_writereg(state, AU8522_INPUT_CONTROL_REG081H,
397 AU8522_INPUT_CONTROL_REG081H_SVIDEO_CH13); 407 AU8522_INPUT_CONTROL_REG081H_SVIDEO_CH13);
398 408
399 /* Disable clamping control (required for S-video) */ 409 /* PGA in automatic mode */
410 au8522_writereg(state, AU8522_PGA_CONTROL_REG082H, 0x00);
411
412 /* Enable clamping control */
400 au8522_writereg(state, AU8522_CLAMPING_CONTROL_REG083H, 0x00); 413 au8522_writereg(state, AU8522_CLAMPING_CONTROL_REG083H, 0x00);
401 414
402 setup_decoder_defaults(state, 415 setup_decoder_defaults(state,
@@ -410,29 +423,15 @@ static void au8522_setup_svideo_mode(struct au8522_state *state)
410 423
411static void disable_audio_input(struct au8522_state *state) 424static void disable_audio_input(struct au8522_state *state)
412{ 425{
413 /* This can probably be optimized */
414 au8522_writereg(state, AU8522_AUDIO_VOLUME_L_REG0F2H, 0x00); 426 au8522_writereg(state, AU8522_AUDIO_VOLUME_L_REG0F2H, 0x00);
415 au8522_writereg(state, AU8522_AUDIO_VOLUME_R_REG0F3H, 0x00); 427 au8522_writereg(state, AU8522_AUDIO_VOLUME_R_REG0F3H, 0x00);
416 au8522_writereg(state, AU8522_AUDIO_VOLUME_REG0F4H, 0x00); 428 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 429
430 au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H, 0x04); 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); 431 au8522_writereg(state, AU8522_I2S_CTRL_2_REG112H, 0x02);
433 432
434 au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H, 433 au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H,
435 AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_CVBS); 434 AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_SVIDEO);
436} 435}
437 436
438/* 0=disable, 1=SIF */ 437/* 0=disable, 1=SIF */
@@ -622,7 +621,7 @@ static int au8522_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc)
622 return v4l2_ctrl_query_fill(qc, 0, 255, 1, 621 return v4l2_ctrl_query_fill(qc, 0, 255, 1,
623 AU8522_TVDEC_CONTRAST_REG00BH_CVBS); 622 AU8522_TVDEC_CONTRAST_REG00BH_CVBS);
624 case V4L2_CID_BRIGHTNESS: 623 case V4L2_CID_BRIGHTNESS:
625 return v4l2_ctrl_query_fill(qc, 0, 255, 1, 128); 624 return v4l2_ctrl_query_fill(qc, 0, 255, 1, 109);
626 case V4L2_CID_SATURATION: 625 case V4L2_CID_SATURATION:
627 return v4l2_ctrl_query_fill(qc, 0, 255, 1, 128); 626 return v4l2_ctrl_query_fill(qc, 0, 255, 1, 128);
628 case V4L2_CID_HUE: 627 case V4L2_CID_HUE:
diff --git a/drivers/media/dvb/frontends/au8522_priv.h b/drivers/media/dvb/frontends/au8522_priv.h
index 609cf04bc312..751e17d692a9 100644
--- a/drivers/media/dvb/frontends/au8522_priv.h
+++ b/drivers/media/dvb/frontends/au8522_priv.h
@@ -397,7 +397,9 @@ void au8522_release_state(struct au8522_state *state);
397#define AU8522_TVDEC_COMB_HDIF_THR2_REG06AH_CVBS 0x0A 397#define AU8522_TVDEC_COMB_HDIF_THR2_REG06AH_CVBS 0x0A
398#define AU8522_TVDEC_COMB_HDIF_THR3_REG06BH_CVBS 0x32 398#define AU8522_TVDEC_COMB_HDIF_THR3_REG06BH_CVBS 0x32
399#define AU8522_TVDEC_COMB_DCDIF_THR1_REG06CH_CVBS 0x34 399#define AU8522_TVDEC_COMB_DCDIF_THR1_REG06CH_CVBS 0x34
400#define AU8522_TVDEC_COMB_DCDIF_THR1_REG06CH_SVIDEO 0x2a
400#define AU8522_TVDEC_COMB_DCDIF_THR2_REG06DH_CVBS 0x05 401#define AU8522_TVDEC_COMB_DCDIF_THR2_REG06DH_CVBS 0x05
402#define AU8522_TVDEC_COMB_DCDIF_THR2_REG06DH_SVIDEO 0x15
401#define AU8522_TVDEC_COMB_DCDIF_THR3_REG06EH_CVBS 0x6E 403#define AU8522_TVDEC_COMB_DCDIF_THR3_REG06EH_CVBS 0x6E
402#define AU8522_TVDEC_UV_SEP_THR_REG06FH_CVBS 0x0F 404#define AU8522_TVDEC_UV_SEP_THR_REG06FH_CVBS 0x0F
403#define AU8522_TVDEC_COMB_DC_THR1_NTSC_REG070H_CVBS 0x80 405#define AU8522_TVDEC_COMB_DC_THR1_NTSC_REG070H_CVBS 0x80
diff --git a/drivers/media/dvb/frontends/dib7000m.c b/drivers/media/dvb/frontends/dib7000m.c
index 0f09fd31cb29..c7f5ccf54aa5 100644
--- a/drivers/media/dvb/frontends/dib7000m.c
+++ b/drivers/media/dvb/frontends/dib7000m.c
@@ -805,7 +805,7 @@ static void dib7000m_set_channel(struct dib7000m_state *state, struct dvb_fronte
805 value = 0; 805 value = 0;
806 switch (ch->u.ofdm.transmission_mode) { 806 switch (ch->u.ofdm.transmission_mode) {
807 case TRANSMISSION_MODE_2K: value |= (0 << 7); break; 807 case TRANSMISSION_MODE_2K: value |= (0 << 7); break;
808 case /* 4K MODE */ 255: value |= (2 << 7); break; 808 case TRANSMISSION_MODE_4K: value |= (2 << 7); break;
809 default: 809 default:
810 case TRANSMISSION_MODE_8K: value |= (1 << 7); break; 810 case TRANSMISSION_MODE_8K: value |= (1 << 7); break;
811 } 811 }
@@ -866,7 +866,7 @@ static void dib7000m_set_channel(struct dib7000m_state *state, struct dvb_fronte
866 /* P_dvsy_sync_wait */ 866 /* P_dvsy_sync_wait */
867 switch (ch->u.ofdm.transmission_mode) { 867 switch (ch->u.ofdm.transmission_mode) {
868 case TRANSMISSION_MODE_8K: value = 256; break; 868 case TRANSMISSION_MODE_8K: value = 256; break;
869 case /* 4K MODE */ 255: value = 128; break; 869 case TRANSMISSION_MODE_4K: value = 128; break;
870 case TRANSMISSION_MODE_2K: 870 case TRANSMISSION_MODE_2K:
871 default: value = 64; break; 871 default: value = 64; break;
872 } 872 }
@@ -1020,7 +1020,7 @@ static int dib7000m_tune(struct dvb_frontend *demod, struct dvb_frontend_paramet
1020 value = (6 << 8) | 0x80; 1020 value = (6 << 8) | 0x80;
1021 switch (ch->u.ofdm.transmission_mode) { 1021 switch (ch->u.ofdm.transmission_mode) {
1022 case TRANSMISSION_MODE_2K: value |= (7 << 12); break; 1022 case TRANSMISSION_MODE_2K: value |= (7 << 12); break;
1023 case /* 4K MODE */ 255: value |= (8 << 12); break; 1023 case TRANSMISSION_MODE_4K: value |= (8 << 12); break;
1024 default: 1024 default:
1025 case TRANSMISSION_MODE_8K: value |= (9 << 12); break; 1025 case TRANSMISSION_MODE_8K: value |= (9 << 12); break;
1026 } 1026 }
@@ -1030,7 +1030,7 @@ static int dib7000m_tune(struct dvb_frontend *demod, struct dvb_frontend_paramet
1030 value = (0 << 4); 1030 value = (0 << 4);
1031 switch (ch->u.ofdm.transmission_mode) { 1031 switch (ch->u.ofdm.transmission_mode) {
1032 case TRANSMISSION_MODE_2K: value |= 0x6; break; 1032 case TRANSMISSION_MODE_2K: value |= 0x6; break;
1033 case /* 4K MODE */ 255: value |= 0x7; break; 1033 case TRANSMISSION_MODE_4K: value |= 0x7; break;
1034 default: 1034 default:
1035 case TRANSMISSION_MODE_8K: value |= 0x8; break; 1035 case TRANSMISSION_MODE_8K: value |= 0x8; break;
1036 } 1036 }
@@ -1040,7 +1040,7 @@ static int dib7000m_tune(struct dvb_frontend *demod, struct dvb_frontend_paramet
1040 value = (0 << 4); 1040 value = (0 << 4);
1041 switch (ch->u.ofdm.transmission_mode) { 1041 switch (ch->u.ofdm.transmission_mode) {
1042 case TRANSMISSION_MODE_2K: value |= 0x6; break; 1042 case TRANSMISSION_MODE_2K: value |= 0x6; break;
1043 case /* 4K MODE */ 255: value |= 0x7; break; 1043 case TRANSMISSION_MODE_4K: value |= 0x7; break;
1044 default: 1044 default:
1045 case TRANSMISSION_MODE_8K: value |= 0x8; break; 1045 case TRANSMISSION_MODE_8K: value |= 0x8; break;
1046 } 1046 }
diff --git a/drivers/media/dvb/frontends/dib7000p.c b/drivers/media/dvb/frontends/dib7000p.c
index 3aed0d433921..6aa02cb80733 100644
--- a/drivers/media/dvb/frontends/dib7000p.c
+++ b/drivers/media/dvb/frontends/dib7000p.c
@@ -717,7 +717,7 @@ static void dib7000p_set_channel(struct dib7000p_state *state, struct dvb_fronte
717 value = 0; 717 value = 0;
718 switch (ch->u.ofdm.transmission_mode) { 718 switch (ch->u.ofdm.transmission_mode) {
719 case TRANSMISSION_MODE_2K: value |= (0 << 7); break; 719 case TRANSMISSION_MODE_2K: value |= (0 << 7); break;
720 case /* 4K MODE */ 255: value |= (2 << 7); break; 720 case TRANSMISSION_MODE_4K: value |= (2 << 7); break;
721 default: 721 default:
722 case TRANSMISSION_MODE_8K: value |= (1 << 7); break; 722 case TRANSMISSION_MODE_8K: value |= (1 << 7); break;
723 } 723 }
@@ -770,7 +770,7 @@ static void dib7000p_set_channel(struct dib7000p_state *state, struct dvb_fronte
770 /* P_dvsy_sync_wait */ 770 /* P_dvsy_sync_wait */
771 switch (ch->u.ofdm.transmission_mode) { 771 switch (ch->u.ofdm.transmission_mode) {
772 case TRANSMISSION_MODE_8K: value = 256; break; 772 case TRANSMISSION_MODE_8K: value = 256; break;
773 case /* 4K MODE */ 255: value = 128; break; 773 case TRANSMISSION_MODE_4K: value = 128; break;
774 case TRANSMISSION_MODE_2K: 774 case TRANSMISSION_MODE_2K:
775 default: value = 64; break; 775 default: value = 64; break;
776 } 776 }
@@ -994,7 +994,7 @@ static int dib7000p_tune(struct dvb_frontend *demod, struct dvb_frontend_paramet
994 tmp = (6 << 8) | 0x80; 994 tmp = (6 << 8) | 0x80;
995 switch (ch->u.ofdm.transmission_mode) { 995 switch (ch->u.ofdm.transmission_mode) {
996 case TRANSMISSION_MODE_2K: tmp |= (7 << 12); break; 996 case TRANSMISSION_MODE_2K: tmp |= (7 << 12); break;
997 case /* 4K MODE */ 255: tmp |= (8 << 12); break; 997 case TRANSMISSION_MODE_4K: tmp |= (8 << 12); break;
998 default: 998 default:
999 case TRANSMISSION_MODE_8K: tmp |= (9 << 12); break; 999 case TRANSMISSION_MODE_8K: tmp |= (9 << 12); break;
1000 } 1000 }
@@ -1004,7 +1004,7 @@ static int dib7000p_tune(struct dvb_frontend *demod, struct dvb_frontend_paramet
1004 tmp = (0 << 4); 1004 tmp = (0 << 4);
1005 switch (ch->u.ofdm.transmission_mode) { 1005 switch (ch->u.ofdm.transmission_mode) {
1006 case TRANSMISSION_MODE_2K: tmp |= 0x6; break; 1006 case TRANSMISSION_MODE_2K: tmp |= 0x6; break;
1007 case /* 4K MODE */ 255: tmp |= 0x7; break; 1007 case TRANSMISSION_MODE_4K: tmp |= 0x7; break;
1008 default: 1008 default:
1009 case TRANSMISSION_MODE_8K: tmp |= 0x8; break; 1009 case TRANSMISSION_MODE_8K: tmp |= 0x8; break;
1010 } 1010 }
@@ -1014,7 +1014,7 @@ static int dib7000p_tune(struct dvb_frontend *demod, struct dvb_frontend_paramet
1014 tmp = (0 << 4); 1014 tmp = (0 << 4);
1015 switch (ch->u.ofdm.transmission_mode) { 1015 switch (ch->u.ofdm.transmission_mode) {
1016 case TRANSMISSION_MODE_2K: tmp |= 0x6; break; 1016 case TRANSMISSION_MODE_2K: tmp |= 0x6; break;
1017 case /* 4K MODE */ 255: tmp |= 0x7; break; 1017 case TRANSMISSION_MODE_4K: tmp |= 0x7; break;
1018 default: 1018 default:
1019 case TRANSMISSION_MODE_8K: tmp |= 0x8; break; 1019 case TRANSMISSION_MODE_8K: tmp |= 0x8; break;
1020 } 1020 }
diff --git a/drivers/media/dvb/frontends/ix2505v.c b/drivers/media/dvb/frontends/ix2505v.c
index 55f2eba7bc96..6360c681ded9 100644
--- a/drivers/media/dvb/frontends/ix2505v.c
+++ b/drivers/media/dvb/frontends/ix2505v.c
@@ -72,7 +72,7 @@ static int ix2505v_read_status_reg(struct ix2505v_state *state)
72 ret = i2c_transfer(state->i2c, msg, 1); 72 ret = i2c_transfer(state->i2c, msg, 1);
73 deb_i2c("Read %s ", __func__); 73 deb_i2c("Read %s ", __func__);
74 74
75 return (ret = 1) ? (int) b2[0] : -1; 75 return (ret == 1) ? (int) b2[0] : -1;
76} 76}
77 77
78static int ix2505v_write(struct ix2505v_state *state, u8 buf[], u8 count) 78static int ix2505v_write(struct ix2505v_state *state, u8 buf[], u8 count)
diff --git a/drivers/media/dvb/frontends/lgs8gxx.c b/drivers/media/dvb/frontends/lgs8gxx.c
index 0fcddc4569d2..1172b54689f8 100644
--- a/drivers/media/dvb/frontends/lgs8gxx.c
+++ b/drivers/media/dvb/frontends/lgs8gxx.c
@@ -60,13 +60,12 @@ static int lgs8gxx_write_reg(struct lgs8gxx_state *priv, u8 reg, u8 data)
60 msg.addr += 0x02; 60 msg.addr += 0x02;
61 61
62 if (debug >= 2) 62 if (debug >= 2)
63 printk(KERN_DEBUG "%s: reg=0x%02X, data=0x%02X\n", 63 dprintk("%s: reg=0x%02X, data=0x%02X\n", __func__, reg, data);
64 __func__, reg, data);
65 64
66 ret = i2c_transfer(priv->i2c, &msg, 1); 65 ret = i2c_transfer(priv->i2c, &msg, 1);
67 66
68 if (ret != 1) 67 if (ret != 1)
69 dprintk(KERN_DEBUG "%s: error reg=0x%x, data=0x%x, ret=%i\n", 68 dprintk("%s: error reg=0x%x, data=0x%x, ret=%i\n",
70 __func__, reg, data, ret); 69 __func__, reg, data, ret);
71 70
72 return (ret != 1) ? -1 : 0; 71 return (ret != 1) ? -1 : 0;
@@ -91,15 +90,13 @@ static int lgs8gxx_read_reg(struct lgs8gxx_state *priv, u8 reg, u8 *p_data)
91 90
92 ret = i2c_transfer(priv->i2c, msg, 2); 91 ret = i2c_transfer(priv->i2c, msg, 2);
93 if (ret != 2) { 92 if (ret != 2) {
94 dprintk(KERN_DEBUG "%s: error reg=0x%x, ret=%i\n", 93 dprintk("%s: error reg=0x%x, ret=%i\n", __func__, reg, ret);
95 __func__, reg, ret);
96 return -1; 94 return -1;
97 } 95 }
98 96
99 *p_data = b1[0]; 97 *p_data = b1[0];
100 if (debug >= 2) 98 if (debug >= 2)
101 printk(KERN_DEBUG "%s: reg=0x%02X, data=0x%02X\n", 99 dprintk("%s: reg=0x%02X, data=0x%02X\n", __func__, reg, b1[0]);
102 __func__, reg, b1[0]);
103 return 0; 100 return 0;
104} 101}
105 102
diff --git a/drivers/media/dvb/frontends/mb86a20s.c b/drivers/media/dvb/frontends/mb86a20s.c
new file mode 100644
index 000000000000..d3ad3e75a35a
--- /dev/null
+++ b/drivers/media/dvb/frontends/mb86a20s.c
@@ -0,0 +1,615 @@
1/*
2 * Fujitu mb86a20s ISDB-T/ISDB-Tsb Module driver
3 *
4 * Copyright (C) 2010 Mauro Carvalho Chehab <mchehab@redhat.com>
5 * Copyright (C) 2009-2010 Douglas Landgraf <dougsland@redhat.com>
6 *
7 * FIXME: Need to port to DVB v5.2 API
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation version 2.
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 GNU
16 * General Public License for more details.
17 */
18
19#include <linux/kernel.h>
20#include <asm/div64.h>
21
22#include "dvb_frontend.h"
23#include "mb86a20s.h"
24
25static int debug = 1;
26module_param(debug, int, 0644);
27MODULE_PARM_DESC(debug, "Activates frontend debugging (default:0)");
28
29#define rc(args...) do { \
30 printk(KERN_ERR "mb86a20s: " args); \
31} while (0)
32
33#define dprintk(args...) \
34 do { \
35 if (debug) { \
36 printk(KERN_DEBUG "mb86a20s: %s: ", __func__); \
37 printk(args); \
38 } \
39 } while (0)
40
41struct mb86a20s_state {
42 struct i2c_adapter *i2c;
43 const struct mb86a20s_config *config;
44
45 struct dvb_frontend frontend;
46};
47
48struct regdata {
49 u8 reg;
50 u8 data;
51};
52
53/*
54 * Initialization sequence: Use whatevere default values that PV SBTVD
55 * does on its initialisation, obtained via USB snoop
56 */
57static struct regdata mb86a20s_init[] = {
58 { 0x70, 0x0f },
59 { 0x70, 0xff },
60 { 0x08, 0x01 },
61 { 0x09, 0x3e },
62 { 0x50, 0xd1 },
63 { 0x51, 0x22 },
64 { 0x39, 0x01 },
65 { 0x71, 0x00 },
66 { 0x28, 0x2a },
67 { 0x29, 0x00 },
68 { 0x2a, 0xff },
69 { 0x2b, 0x80 },
70 { 0x28, 0x20 },
71 { 0x29, 0x33 },
72 { 0x2a, 0xdf },
73 { 0x2b, 0xa9 },
74 { 0x3b, 0x21 },
75 { 0x3c, 0x3a },
76 { 0x01, 0x0d },
77 { 0x04, 0x08 },
78 { 0x05, 0x05 },
79 { 0x04, 0x0e },
80 { 0x05, 0x00 },
81 { 0x04, 0x0f },
82 { 0x05, 0x14 },
83 { 0x04, 0x0b },
84 { 0x05, 0x8c },
85 { 0x04, 0x00 },
86 { 0x05, 0x00 },
87 { 0x04, 0x01 },
88 { 0x05, 0x07 },
89 { 0x04, 0x02 },
90 { 0x05, 0x0f },
91 { 0x04, 0x03 },
92 { 0x05, 0xa0 },
93 { 0x04, 0x09 },
94 { 0x05, 0x00 },
95 { 0x04, 0x0a },
96 { 0x05, 0xff },
97 { 0x04, 0x27 },
98 { 0x05, 0x64 },
99 { 0x04, 0x28 },
100 { 0x05, 0x00 },
101 { 0x04, 0x1e },
102 { 0x05, 0xff },
103 { 0x04, 0x29 },
104 { 0x05, 0x0a },
105 { 0x04, 0x32 },
106 { 0x05, 0x0a },
107 { 0x04, 0x14 },
108 { 0x05, 0x02 },
109 { 0x04, 0x04 },
110 { 0x05, 0x00 },
111 { 0x04, 0x05 },
112 { 0x05, 0x22 },
113 { 0x04, 0x06 },
114 { 0x05, 0x0e },
115 { 0x04, 0x07 },
116 { 0x05, 0xd8 },
117 { 0x04, 0x12 },
118 { 0x05, 0x00 },
119 { 0x04, 0x13 },
120 { 0x05, 0xff },
121 { 0x52, 0x01 },
122 { 0x50, 0xa7 },
123 { 0x51, 0x00 },
124 { 0x50, 0xa8 },
125 { 0x51, 0xff },
126 { 0x50, 0xa9 },
127 { 0x51, 0xff },
128 { 0x50, 0xaa },
129 { 0x51, 0x00 },
130 { 0x50, 0xab },
131 { 0x51, 0xff },
132 { 0x50, 0xac },
133 { 0x51, 0xff },
134 { 0x50, 0xad },
135 { 0x51, 0x00 },
136 { 0x50, 0xae },
137 { 0x51, 0xff },
138 { 0x50, 0xaf },
139 { 0x51, 0xff },
140 { 0x5e, 0x07 },
141 { 0x50, 0xdc },
142 { 0x51, 0x01 },
143 { 0x50, 0xdd },
144 { 0x51, 0xf4 },
145 { 0x50, 0xde },
146 { 0x51, 0x01 },
147 { 0x50, 0xdf },
148 { 0x51, 0xf4 },
149 { 0x50, 0xe0 },
150 { 0x51, 0x01 },
151 { 0x50, 0xe1 },
152 { 0x51, 0xf4 },
153 { 0x50, 0xb0 },
154 { 0x51, 0x07 },
155 { 0x50, 0xb2 },
156 { 0x51, 0xff },
157 { 0x50, 0xb3 },
158 { 0x51, 0xff },
159 { 0x50, 0xb4 },
160 { 0x51, 0xff },
161 { 0x50, 0xb5 },
162 { 0x51, 0xff },
163 { 0x50, 0xb6 },
164 { 0x51, 0xff },
165 { 0x50, 0xb7 },
166 { 0x51, 0xff },
167 { 0x50, 0x50 },
168 { 0x51, 0x02 },
169 { 0x50, 0x51 },
170 { 0x51, 0x04 },
171 { 0x45, 0x04 },
172 { 0x48, 0x04 },
173 { 0x50, 0xd5 },
174 { 0x51, 0x01 }, /* Serial */
175 { 0x50, 0xd6 },
176 { 0x51, 0x1f },
177 { 0x50, 0xd2 },
178 { 0x51, 0x03 },
179 { 0x50, 0xd7 },
180 { 0x51, 0x3f },
181 { 0x1c, 0x01 },
182 { 0x28, 0x06 },
183 { 0x29, 0x00 },
184 { 0x2a, 0x00 },
185 { 0x2b, 0x03 },
186 { 0x28, 0x07 },
187 { 0x29, 0x00 },
188 { 0x2a, 0x00 },
189 { 0x2b, 0x0d },
190 { 0x28, 0x08 },
191 { 0x29, 0x00 },
192 { 0x2a, 0x00 },
193 { 0x2b, 0x02 },
194 { 0x28, 0x09 },
195 { 0x29, 0x00 },
196 { 0x2a, 0x00 },
197 { 0x2b, 0x01 },
198 { 0x28, 0x0a },
199 { 0x29, 0x00 },
200 { 0x2a, 0x00 },
201 { 0x2b, 0x21 },
202 { 0x28, 0x0b },
203 { 0x29, 0x00 },
204 { 0x2a, 0x00 },
205 { 0x2b, 0x29 },
206 { 0x28, 0x0c },
207 { 0x29, 0x00 },
208 { 0x2a, 0x00 },
209 { 0x2b, 0x16 },
210 { 0x28, 0x0d },
211 { 0x29, 0x00 },
212 { 0x2a, 0x00 },
213 { 0x2b, 0x31 },
214 { 0x28, 0x0e },
215 { 0x29, 0x00 },
216 { 0x2a, 0x00 },
217 { 0x2b, 0x0e },
218 { 0x28, 0x0f },
219 { 0x29, 0x00 },
220 { 0x2a, 0x00 },
221 { 0x2b, 0x4e },
222 { 0x28, 0x10 },
223 { 0x29, 0x00 },
224 { 0x2a, 0x00 },
225 { 0x2b, 0x46 },
226 { 0x28, 0x11 },
227 { 0x29, 0x00 },
228 { 0x2a, 0x00 },
229 { 0x2b, 0x0f },
230 { 0x28, 0x12 },
231 { 0x29, 0x00 },
232 { 0x2a, 0x00 },
233 { 0x2b, 0x56 },
234 { 0x28, 0x13 },
235 { 0x29, 0x00 },
236 { 0x2a, 0x00 },
237 { 0x2b, 0x35 },
238 { 0x28, 0x14 },
239 { 0x29, 0x00 },
240 { 0x2a, 0x01 },
241 { 0x2b, 0xbe },
242 { 0x28, 0x15 },
243 { 0x29, 0x00 },
244 { 0x2a, 0x01 },
245 { 0x2b, 0x84 },
246 { 0x28, 0x16 },
247 { 0x29, 0x00 },
248 { 0x2a, 0x03 },
249 { 0x2b, 0xee },
250 { 0x28, 0x17 },
251 { 0x29, 0x00 },
252 { 0x2a, 0x00 },
253 { 0x2b, 0x98 },
254 { 0x28, 0x18 },
255 { 0x29, 0x00 },
256 { 0x2a, 0x00 },
257 { 0x2b, 0x9f },
258 { 0x28, 0x19 },
259 { 0x29, 0x00 },
260 { 0x2a, 0x07 },
261 { 0x2b, 0xb2 },
262 { 0x28, 0x1a },
263 { 0x29, 0x00 },
264 { 0x2a, 0x06 },
265 { 0x2b, 0xc2 },
266 { 0x28, 0x1b },
267 { 0x29, 0x00 },
268 { 0x2a, 0x07 },
269 { 0x2b, 0x4a },
270 { 0x28, 0x1c },
271 { 0x29, 0x00 },
272 { 0x2a, 0x01 },
273 { 0x2b, 0xbc },
274 { 0x28, 0x1d },
275 { 0x29, 0x00 },
276 { 0x2a, 0x04 },
277 { 0x2b, 0xba },
278 { 0x28, 0x1e },
279 { 0x29, 0x00 },
280 { 0x2a, 0x06 },
281 { 0x2b, 0x14 },
282 { 0x50, 0x1e },
283 { 0x51, 0x5d },
284 { 0x50, 0x22 },
285 { 0x51, 0x00 },
286 { 0x50, 0x23 },
287 { 0x51, 0xc8 },
288 { 0x50, 0x24 },
289 { 0x51, 0x00 },
290 { 0x50, 0x25 },
291 { 0x51, 0xf0 },
292 { 0x50, 0x26 },
293 { 0x51, 0x00 },
294 { 0x50, 0x27 },
295 { 0x51, 0xc3 },
296 { 0x50, 0x39 },
297 { 0x51, 0x02 },
298 { 0x50, 0xd5 },
299 { 0x51, 0x01 },
300 { 0xd0, 0x00 },
301};
302
303static struct regdata mb86a20s_reset_reception[] = {
304 { 0x70, 0xf0 },
305 { 0x70, 0xff },
306 { 0x08, 0x01 },
307 { 0x08, 0x00 },
308};
309
310static int mb86a20s_i2c_writereg(struct mb86a20s_state *state,
311 u8 i2c_addr, int reg, int data)
312{
313 u8 buf[] = { reg, data };
314 struct i2c_msg msg = {
315 .addr = i2c_addr, .flags = 0, .buf = buf, .len = 2
316 };
317 int rc;
318
319 rc = i2c_transfer(state->i2c, &msg, 1);
320 if (rc != 1) {
321 printk("%s: writereg rcor(rc == %i, reg == 0x%02x,"
322 " data == 0x%02x)\n", __func__, rc, reg, data);
323 return rc;
324 }
325
326 return 0;
327}
328
329static int mb86a20s_i2c_writeregdata(struct mb86a20s_state *state,
330 u8 i2c_addr, struct regdata *rd, int size)
331{
332 int i, rc;
333
334 for (i = 0; i < size; i++) {
335 rc = mb86a20s_i2c_writereg(state, i2c_addr, rd[i].reg,
336 rd[i].data);
337 if (rc < 0)
338 return rc;
339 }
340 return 0;
341}
342
343static int mb86a20s_i2c_readreg(struct mb86a20s_state *state,
344 u8 i2c_addr, u8 reg)
345{
346 u8 val;
347 int rc;
348 struct i2c_msg msg[] = {
349 { .addr = i2c_addr, .flags = 0, .buf = &reg, .len = 1 },
350 { .addr = i2c_addr, .flags = I2C_M_RD, .buf = &val, .len = 1 }
351 };
352
353 rc = i2c_transfer(state->i2c, msg, 2);
354
355 if (rc != 2) {
356 rc("%s: reg=0x%x (rcor=%d)\n", __func__, reg, rc);
357 return rc;
358 }
359
360 return val;
361}
362
363#define mb86a20s_readreg(state, reg) \
364 mb86a20s_i2c_readreg(state, state->config->demod_address, reg)
365#define mb86a20s_writereg(state, reg, val) \
366 mb86a20s_i2c_writereg(state, state->config->demod_address, reg, val)
367#define mb86a20s_writeregdata(state, regdata) \
368 mb86a20s_i2c_writeregdata(state, state->config->demod_address, \
369 regdata, ARRAY_SIZE(regdata))
370
371static int mb86a20s_initfe(struct dvb_frontend *fe)
372{
373 struct mb86a20s_state *state = fe->demodulator_priv;
374 int rc;
375 u8 regD5 = 1;
376
377 dprintk("\n");
378
379 if (fe->ops.i2c_gate_ctrl)
380 fe->ops.i2c_gate_ctrl(fe, 0);
381
382 /* Initialize the frontend */
383 rc = mb86a20s_writeregdata(state, mb86a20s_init);
384 if (rc < 0)
385 return rc;
386
387 if (!state->config->is_serial) {
388 regD5 &= ~1;
389
390 rc = mb86a20s_writereg(state, 0x50, 0xd5);
391 if (rc < 0)
392 return rc;
393 rc = mb86a20s_writereg(state, 0x51, regD5);
394 if (rc < 0)
395 return rc;
396 }
397
398 if (fe->ops.i2c_gate_ctrl)
399 fe->ops.i2c_gate_ctrl(fe, 1);
400
401 return 0;
402}
403
404static int mb86a20s_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
405{
406 struct mb86a20s_state *state = fe->demodulator_priv;
407 unsigned rf_max, rf_min, rf;
408 u8 val;
409
410 dprintk("\n");
411
412 if (fe->ops.i2c_gate_ctrl)
413 fe->ops.i2c_gate_ctrl(fe, 0);
414
415 /* Does a binary search to get RF strength */
416 rf_max = 0xfff;
417 rf_min = 0;
418 do {
419 rf = (rf_max + rf_min) / 2;
420 mb86a20s_writereg(state, 0x04, 0x1f);
421 mb86a20s_writereg(state, 0x05, rf >> 8);
422 mb86a20s_writereg(state, 0x04, 0x20);
423 mb86a20s_writereg(state, 0x04, rf);
424
425 val = mb86a20s_readreg(state, 0x02);
426 if (val & 0x08)
427 rf_min = (rf_max + rf_min) / 2;
428 else
429 rf_max = (rf_max + rf_min) / 2;
430 if (rf_max - rf_min < 4) {
431 *strength = (((rf_max + rf_min) / 2) * 65535) / 4095;
432 break;
433 }
434 } while (1);
435
436 dprintk("signal strength = %d\n", *strength);
437
438 if (fe->ops.i2c_gate_ctrl)
439 fe->ops.i2c_gate_ctrl(fe, 1);
440
441 return 0;
442}
443
444static int mb86a20s_read_status(struct dvb_frontend *fe, fe_status_t *status)
445{
446 struct mb86a20s_state *state = fe->demodulator_priv;
447 u8 val;
448
449 dprintk("\n");
450 *status = 0;
451
452 if (fe->ops.i2c_gate_ctrl)
453 fe->ops.i2c_gate_ctrl(fe, 0);
454 val = mb86a20s_readreg(state, 0x0a) & 0xf;
455 if (fe->ops.i2c_gate_ctrl)
456 fe->ops.i2c_gate_ctrl(fe, 1);
457
458 if (val >= 2)
459 *status |= FE_HAS_SIGNAL;
460
461 if (val >= 4)
462 *status |= FE_HAS_CARRIER;
463
464 if (val >= 5)
465 *status |= FE_HAS_VITERBI;
466
467 if (val >= 7)
468 *status |= FE_HAS_SYNC;
469
470 if (val >= 8) /* Maybe 9? */
471 *status |= FE_HAS_LOCK;
472
473 dprintk("val = %d, status = 0x%02x\n", val, *status);
474
475 return 0;
476}
477
478static int mb86a20s_set_frontend(struct dvb_frontend *fe,
479 struct dvb_frontend_parameters *p)
480{
481 struct mb86a20s_state *state = fe->demodulator_priv;
482 int rc;
483
484 dprintk("\n");
485
486 if (fe->ops.i2c_gate_ctrl)
487 fe->ops.i2c_gate_ctrl(fe, 1);
488 fe->ops.tuner_ops.set_params(fe, p);
489
490 if (fe->ops.i2c_gate_ctrl)
491 fe->ops.i2c_gate_ctrl(fe, 0);
492 rc = mb86a20s_writeregdata(state, mb86a20s_reset_reception);
493 if (fe->ops.i2c_gate_ctrl)
494 fe->ops.i2c_gate_ctrl(fe, 1);
495
496 return rc;
497}
498
499static int mb86a20s_get_frontend(struct dvb_frontend *fe,
500 struct dvb_frontend_parameters *p)
501{
502
503 /* FIXME: For now, it does nothing */
504
505 fe->dtv_property_cache.bandwidth_hz = 6000000;
506 fe->dtv_property_cache.transmission_mode = TRANSMISSION_MODE_AUTO;
507 fe->dtv_property_cache.guard_interval = GUARD_INTERVAL_AUTO;
508 fe->dtv_property_cache.isdbt_partial_reception = 0;
509
510 return 0;
511}
512
513static int mb86a20s_tune(struct dvb_frontend *fe,
514 struct dvb_frontend_parameters *params,
515 unsigned int mode_flags,
516 unsigned int *delay,
517 fe_status_t *status)
518{
519 int rc = 0;
520
521 dprintk("\n");
522
523 if (params != NULL)
524 rc = mb86a20s_set_frontend(fe, params);
525
526 if (!(mode_flags & FE_TUNE_MODE_ONESHOT))
527 mb86a20s_read_status(fe, status);
528
529 return rc;
530}
531
532static void mb86a20s_release(struct dvb_frontend *fe)
533{
534 struct mb86a20s_state *state = fe->demodulator_priv;
535
536 dprintk("\n");
537
538 kfree(state);
539}
540
541static struct dvb_frontend_ops mb86a20s_ops;
542
543struct dvb_frontend *mb86a20s_attach(const struct mb86a20s_config *config,
544 struct i2c_adapter *i2c)
545{
546 u8 rev;
547
548 /* allocate memory for the internal state */
549 struct mb86a20s_state *state =
550 kzalloc(sizeof(struct mb86a20s_state), GFP_KERNEL);
551
552 dprintk("\n");
553 if (state == NULL) {
554 rc("Unable to kzalloc\n");
555 goto error;
556 }
557
558 /* setup the state */
559 state->config = config;
560 state->i2c = i2c;
561
562 /* create dvb_frontend */
563 memcpy(&state->frontend.ops, &mb86a20s_ops,
564 sizeof(struct dvb_frontend_ops));
565 state->frontend.demodulator_priv = state;
566
567 /* Check if it is a mb86a20s frontend */
568 rev = mb86a20s_readreg(state, 0);
569
570 if (rev == 0x13) {
571 printk(KERN_INFO "Detected a Fujitsu mb86a20s frontend\n");
572 } else {
573 printk(KERN_ERR "Frontend revision %d is unknown - aborting.\n",
574 rev);
575 goto error;
576 }
577
578 return &state->frontend;
579
580error:
581 kfree(state);
582 return NULL;
583}
584EXPORT_SYMBOL(mb86a20s_attach);
585
586static struct dvb_frontend_ops mb86a20s_ops = {
587 /* Use dib8000 values per default */
588 .info = {
589 .name = "Fujitsu mb86A20s",
590 .type = FE_OFDM,
591 .caps = FE_CAN_INVERSION_AUTO | FE_CAN_RECOVER |
592 FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
593 FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
594 FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 |
595 FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_QAM_AUTO |
596 FE_CAN_GUARD_INTERVAL_AUTO | FE_CAN_HIERARCHY_AUTO,
597 /* Actually, those values depend on the used tuner */
598 .frequency_min = 45000000,
599 .frequency_max = 864000000,
600 .frequency_stepsize = 62500,
601 },
602
603 .release = mb86a20s_release,
604
605 .init = mb86a20s_initfe,
606 .set_frontend = mb86a20s_set_frontend,
607 .get_frontend = mb86a20s_get_frontend,
608 .read_status = mb86a20s_read_status,
609 .read_signal_strength = mb86a20s_read_signal_strength,
610 .tune = mb86a20s_tune,
611};
612
613MODULE_DESCRIPTION("DVB Frontend module for Fujitsu mb86A20s hardware");
614MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
615MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/mb86a20s.h b/drivers/media/dvb/frontends/mb86a20s.h
new file mode 100644
index 000000000000..bf22e77888b9
--- /dev/null
+++ b/drivers/media/dvb/frontends/mb86a20s.h
@@ -0,0 +1,52 @@
1/*
2 * Fujitsu mb86a20s driver
3 *
4 * Copyright (C) 2010 Mauro Carvalho Chehab <mchehab@redhat.com>
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 * 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 GNU
13 * General Public License for more details.
14 */
15
16#ifndef MB86A20S_H
17#define MB86A20S_H
18
19#include <linux/dvb/frontend.h>
20
21/**
22 * struct mb86a20s_config - Define the per-device attributes of the frontend
23 *
24 * @demod_address: the demodulator's i2c address
25 */
26
27struct mb86a20s_config {
28 u8 demod_address;
29 bool is_serial;
30};
31
32#if defined(CONFIG_DVB_MB86A20S) || (defined(CONFIG_DVB_MB86A20S_MODULE) \
33 && defined(MODULE))
34extern struct dvb_frontend *mb86a20s_attach(const struct mb86a20s_config *config,
35 struct i2c_adapter *i2c);
36extern struct i2c_adapter *mb86a20s_get_tuner_i2c_adapter(struct dvb_frontend *);
37#else
38static inline struct dvb_frontend *mb86a20s_attach(
39 const struct mb86a20s_config *config, struct i2c_adapter *i2c)
40{
41 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
42 return NULL;
43}
44static struct i2c_adapter *
45 mb86a20s_get_tuner_i2c_adapter(struct dvb_frontend *fe)
46{
47 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
48 return NULL;
49}
50#endif
51
52#endif /* MB86A20S */
diff --git a/drivers/media/dvb/frontends/s921.c b/drivers/media/dvb/frontends/s921.c
new file mode 100644
index 000000000000..ca0103d5f148
--- /dev/null
+++ b/drivers/media/dvb/frontends/s921.c
@@ -0,0 +1,548 @@
1/*
2 * Sharp VA3A5JZ921 One Seg Broadcast Module driver
3 * This device is labeled as just S. 921 at the top of the frontend can
4 *
5 * Copyright (C) 2009-2010 Mauro Carvalho Chehab <mchehab@redhat.com>
6 * Copyright (C) 2009-2010 Douglas Landgraf <dougsland@redhat.com>
7 *
8 * Developed for Leadership SBTVD 1seg device sold in Brazil
9 *
10 * Frontend module based on cx24123 driver, getting some info from
11 * the old s921 driver.
12 *
13 * FIXME: Need to port to DVB v5.2 API
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License as
17 * published by the Free Software Foundation version 2.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * General Public License for more details.
23 */
24
25#include <linux/kernel.h>
26#include <asm/div64.h>
27
28#include "dvb_frontend.h"
29#include "s921.h"
30
31static int debug = 1;
32module_param(debug, int, 0644);
33MODULE_PARM_DESC(debug, "Activates frontend debugging (default:0)");
34
35#define rc(args...) do { \
36 printk(KERN_ERR "s921: " args); \
37} while (0)
38
39#define dprintk(args...) \
40 do { \
41 if (debug) { \
42 printk(KERN_DEBUG "s921: %s: ", __func__); \
43 printk(args); \
44 } \
45 } while (0)
46
47struct s921_state {
48 struct i2c_adapter *i2c;
49 const struct s921_config *config;
50
51 struct dvb_frontend frontend;
52
53 /* The Demod can't easily provide these, we cache them */
54 u32 currentfreq;
55};
56
57/*
58 * Various tuner defaults need to be established for a given frequency kHz.
59 * fixme: The bounds on the bands do not match the doc in real life.
60 * fixme: Some of them have been moved, other might need adjustment.
61 */
62static struct s921_bandselect_val {
63 u32 freq_low;
64 u8 band_reg;
65} s921_bandselect[] = {
66 { 0, 0x7b },
67 { 485140000, 0x5b },
68 { 515140000, 0x3b },
69 { 545140000, 0x1b },
70 { 599140000, 0xfb },
71 { 623140000, 0xdb },
72 { 659140000, 0xbb },
73 { 713140000, 0x9b },
74};
75
76struct regdata {
77 u8 reg;
78 u8 data;
79};
80
81static struct regdata s921_init[] = {
82 { 0x01, 0x80 }, /* Probably, a reset sequence */
83 { 0x01, 0x40 },
84 { 0x01, 0x80 },
85 { 0x01, 0x40 },
86
87 { 0x02, 0x00 },
88 { 0x03, 0x40 },
89 { 0x04, 0x01 },
90 { 0x05, 0x00 },
91 { 0x06, 0x00 },
92 { 0x07, 0x00 },
93 { 0x08, 0x00 },
94 { 0x09, 0x00 },
95 { 0x0a, 0x00 },
96 { 0x0b, 0x5a },
97 { 0x0c, 0x00 },
98 { 0x0d, 0x00 },
99 { 0x0f, 0x00 },
100 { 0x13, 0x1b },
101 { 0x14, 0x80 },
102 { 0x15, 0x40 },
103 { 0x17, 0x70 },
104 { 0x18, 0x01 },
105 { 0x19, 0x12 },
106 { 0x1a, 0x01 },
107 { 0x1b, 0x12 },
108 { 0x1c, 0xa0 },
109 { 0x1d, 0x00 },
110 { 0x1e, 0x0a },
111 { 0x1f, 0x08 },
112 { 0x20, 0x40 },
113 { 0x21, 0xff },
114 { 0x22, 0x4c },
115 { 0x23, 0x4e },
116 { 0x24, 0x4c },
117 { 0x25, 0x00 },
118 { 0x26, 0x00 },
119 { 0x27, 0xf4 },
120 { 0x28, 0x60 },
121 { 0x29, 0x88 },
122 { 0x2a, 0x40 },
123 { 0x2b, 0x40 },
124 { 0x2c, 0xff },
125 { 0x2d, 0x00 },
126 { 0x2e, 0xff },
127 { 0x2f, 0x00 },
128 { 0x30, 0x20 },
129 { 0x31, 0x06 },
130 { 0x32, 0x0c },
131 { 0x34, 0x0f },
132 { 0x37, 0xfe },
133 { 0x38, 0x00 },
134 { 0x39, 0x63 },
135 { 0x3a, 0x10 },
136 { 0x3b, 0x10 },
137 { 0x47, 0x00 },
138 { 0x49, 0xe5 },
139 { 0x4b, 0x00 },
140 { 0x50, 0xc0 },
141 { 0x52, 0x20 },
142 { 0x54, 0x5a },
143 { 0x55, 0x5b },
144 { 0x56, 0x40 },
145 { 0x57, 0x70 },
146 { 0x5c, 0x50 },
147 { 0x5d, 0x00 },
148 { 0x62, 0x17 },
149 { 0x63, 0x2f },
150 { 0x64, 0x6f },
151 { 0x68, 0x00 },
152 { 0x69, 0x89 },
153 { 0x6a, 0x00 },
154 { 0x6b, 0x00 },
155 { 0x6c, 0x00 },
156 { 0x6d, 0x00 },
157 { 0x6e, 0x00 },
158 { 0x70, 0x10 },
159 { 0x71, 0x00 },
160 { 0x75, 0x00 },
161 { 0x76, 0x30 },
162 { 0x77, 0x01 },
163 { 0xaf, 0x00 },
164 { 0xb0, 0xa0 },
165 { 0xb2, 0x3d },
166 { 0xb3, 0x25 },
167 { 0xb4, 0x8b },
168 { 0xb5, 0x4b },
169 { 0xb6, 0x3f },
170 { 0xb7, 0xff },
171 { 0xb8, 0xff },
172 { 0xb9, 0xfc },
173 { 0xba, 0x00 },
174 { 0xbb, 0x00 },
175 { 0xbc, 0x00 },
176 { 0xd0, 0x30 },
177 { 0xe4, 0x84 },
178 { 0xf0, 0x48 },
179 { 0xf1, 0x19 },
180 { 0xf2, 0x5a },
181 { 0xf3, 0x8e },
182 { 0xf4, 0x2d },
183 { 0xf5, 0x07 },
184 { 0xf6, 0x5a },
185 { 0xf7, 0xba },
186 { 0xf8, 0xd7 },
187};
188
189static struct regdata s921_prefreq[] = {
190 { 0x47, 0x60 },
191 { 0x68, 0x00 },
192 { 0x69, 0x89 },
193 { 0xf0, 0x48 },
194 { 0xf1, 0x19 },
195};
196
197static struct regdata s921_postfreq[] = {
198 { 0xf5, 0xae },
199 { 0xf6, 0xb7 },
200 { 0xf7, 0xba },
201 { 0xf8, 0xd7 },
202 { 0x68, 0x0a },
203 { 0x69, 0x09 },
204};
205
206static int s921_i2c_writereg(struct s921_state *state,
207 u8 i2c_addr, int reg, int data)
208{
209 u8 buf[] = { reg, data };
210 struct i2c_msg msg = {
211 .addr = i2c_addr, .flags = 0, .buf = buf, .len = 2
212 };
213 int rc;
214
215 rc = i2c_transfer(state->i2c, &msg, 1);
216 if (rc != 1) {
217 printk("%s: writereg rcor(rc == %i, reg == 0x%02x,"
218 " data == 0x%02x)\n", __func__, rc, reg, data);
219 return rc;
220 }
221
222 return 0;
223}
224
225static int s921_i2c_writeregdata(struct s921_state *state, u8 i2c_addr,
226 struct regdata *rd, int size)
227{
228 int i, rc;
229
230 for (i = 0; i < size; i++) {
231 rc = s921_i2c_writereg(state, i2c_addr, rd[i].reg, rd[i].data);
232 if (rc < 0)
233 return rc;
234 }
235 return 0;
236}
237
238static int s921_i2c_readreg(struct s921_state *state, u8 i2c_addr, u8 reg)
239{
240 u8 val;
241 int rc;
242 struct i2c_msg msg[] = {
243 { .addr = i2c_addr, .flags = 0, .buf = &reg, .len = 1 },
244 { .addr = i2c_addr, .flags = I2C_M_RD, .buf = &val, .len = 1 }
245 };
246
247 rc = i2c_transfer(state->i2c, msg, 2);
248
249 if (rc != 2) {
250 rc("%s: reg=0x%x (rcor=%d)\n", __func__, reg, rc);
251 return rc;
252 }
253
254 return val;
255}
256
257#define s921_readreg(state, reg) \
258 s921_i2c_readreg(state, state->config->demod_address, reg)
259#define s921_writereg(state, reg, val) \
260 s921_i2c_writereg(state, state->config->demod_address, reg, val)
261#define s921_writeregdata(state, regdata) \
262 s921_i2c_writeregdata(state, state->config->demod_address, \
263 regdata, ARRAY_SIZE(regdata))
264
265static int s921_pll_tune(struct dvb_frontend *fe,
266 struct dvb_frontend_parameters *p)
267{
268 struct s921_state *state = fe->demodulator_priv;
269 int band, rc, i;
270 unsigned long f_offset;
271 u8 f_switch;
272 u64 offset;
273
274 dprintk("frequency=%i\n", p->frequency);
275
276 for (band = 0; band < ARRAY_SIZE(s921_bandselect); band++)
277 if (p->frequency < s921_bandselect[band].freq_low)
278 break;
279 band--;
280
281 if (band < 0) {
282 rc("%s: frequency out of range\n", __func__);
283 return -EINVAL;
284 }
285
286 f_switch = s921_bandselect[band].band_reg;
287
288 offset = ((u64)p->frequency) * 258;
289 do_div(offset, 6000000);
290 f_offset = ((unsigned long)offset) + 2321;
291
292 rc = s921_writeregdata(state, s921_prefreq);
293 if (rc < 0)
294 return rc;
295
296 rc = s921_writereg(state, 0xf2, (f_offset >> 8) & 0xff);
297 if (rc < 0)
298 return rc;
299
300 rc = s921_writereg(state, 0xf3, f_offset & 0xff);
301 if (rc < 0)
302 return rc;
303
304 rc = s921_writereg(state, 0xf4, f_switch);
305 if (rc < 0)
306 return rc;
307
308 rc = s921_writeregdata(state, s921_postfreq);
309 if (rc < 0)
310 return rc;
311
312 for (i = 0 ; i < 6; i++) {
313 rc = s921_readreg(state, 0x80);
314 dprintk("status 0x80: %02x\n", rc);
315 }
316 rc = s921_writereg(state, 0x01, 0x40);
317 if (rc < 0)
318 return rc;
319
320 rc = s921_readreg(state, 0x01);
321 dprintk("status 0x01: %02x\n", rc);
322
323 rc = s921_readreg(state, 0x80);
324 dprintk("status 0x80: %02x\n", rc);
325
326 rc = s921_readreg(state, 0x80);
327 dprintk("status 0x80: %02x\n", rc);
328
329 rc = s921_readreg(state, 0x32);
330 dprintk("status 0x32: %02x\n", rc);
331
332 dprintk("pll tune band=%d, pll=%d\n", f_switch, (int)f_offset);
333
334 return 0;
335}
336
337static int s921_initfe(struct dvb_frontend *fe)
338{
339 struct s921_state *state = fe->demodulator_priv;
340 int rc;
341
342 dprintk("\n");
343
344 rc = s921_writeregdata(state, s921_init);
345 if (rc < 0)
346 return rc;
347
348 return 0;
349}
350
351static int s921_read_status(struct dvb_frontend *fe, fe_status_t *status)
352{
353 struct s921_state *state = fe->demodulator_priv;
354 int regstatus, rc;
355
356 *status = 0;
357
358 rc = s921_readreg(state, 0x81);
359 if (rc < 0)
360 return rc;
361
362 regstatus = rc << 8;
363
364 rc = s921_readreg(state, 0x82);
365 if (rc < 0)
366 return rc;
367
368 regstatus |= rc;
369
370 dprintk("status = %04x\n", regstatus);
371
372 /* Full Sync - We don't know what each bit means on regs 0x81/0x82 */
373 if ((regstatus & 0xff) == 0x40) {
374 *status = FE_HAS_SIGNAL |
375 FE_HAS_CARRIER |
376 FE_HAS_VITERBI |
377 FE_HAS_SYNC |
378 FE_HAS_LOCK;
379 } else if (regstatus & 0x40) {
380 /* This is close to Full Sync, but not enough to get useful info */
381 *status = FE_HAS_SIGNAL |
382 FE_HAS_CARRIER |
383 FE_HAS_VITERBI |
384 FE_HAS_SYNC;
385 }
386
387 return 0;
388}
389
390static int s921_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
391{
392 fe_status_t status;
393 struct s921_state *state = fe->demodulator_priv;
394 int rc;
395
396 /* FIXME: Use the proper register for it... 0x80? */
397 rc = s921_read_status(fe, &status);
398 if (rc < 0)
399 return rc;
400
401 *strength = (status & FE_HAS_LOCK) ? 0xffff : 0;
402
403 dprintk("strength = 0x%04x\n", *strength);
404
405 rc = s921_readreg(state, 0x01);
406 dprintk("status 0x01: %02x\n", rc);
407
408 rc = s921_readreg(state, 0x80);
409 dprintk("status 0x80: %02x\n", rc);
410
411 rc = s921_readreg(state, 0x32);
412 dprintk("status 0x32: %02x\n", rc);
413
414 return 0;
415}
416
417static int s921_set_frontend(struct dvb_frontend *fe,
418 struct dvb_frontend_parameters *p)
419{
420 struct s921_state *state = fe->demodulator_priv;
421 int rc;
422
423 dprintk("\n");
424
425 /* FIXME: We don't know how to use non-auto mode */
426
427 rc = s921_pll_tune(fe, p);
428 if (rc < 0)
429 return rc;
430
431 state->currentfreq = p->frequency;
432
433 return 0;
434}
435
436static int s921_get_frontend(struct dvb_frontend *fe,
437 struct dvb_frontend_parameters *p)
438{
439 struct s921_state *state = fe->demodulator_priv;
440
441 /* FIXME: Probably it is possible to get it from regs f1 and f2 */
442 p->frequency = state->currentfreq;
443
444 return 0;
445}
446
447static int s921_tune(struct dvb_frontend *fe,
448 struct dvb_frontend_parameters *params,
449 unsigned int mode_flags,
450 unsigned int *delay,
451 fe_status_t *status)
452{
453 int rc = 0;
454
455 dprintk("\n");
456
457 if (params != NULL)
458 rc = s921_set_frontend(fe, params);
459
460 if (!(mode_flags & FE_TUNE_MODE_ONESHOT))
461 s921_read_status(fe, status);
462
463 return rc;
464}
465
466static int s921_get_algo(struct dvb_frontend *fe)
467{
468 return 1; /* FE_ALGO_HW */
469}
470
471static void s921_release(struct dvb_frontend *fe)
472{
473 struct s921_state *state = fe->demodulator_priv;
474
475 dprintk("\n");
476 kfree(state);
477}
478
479static struct dvb_frontend_ops s921_ops;
480
481struct dvb_frontend *s921_attach(const struct s921_config *config,
482 struct i2c_adapter *i2c)
483{
484 /* allocate memory for the internal state */
485 struct s921_state *state =
486 kzalloc(sizeof(struct s921_state), GFP_KERNEL);
487
488 dprintk("\n");
489 if (state == NULL) {
490 rc("Unable to kzalloc\n");
491 goto rcor;
492 }
493
494 /* setup the state */
495 state->config = config;
496 state->i2c = i2c;
497
498 /* create dvb_frontend */
499 memcpy(&state->frontend.ops, &s921_ops,
500 sizeof(struct dvb_frontend_ops));
501 state->frontend.demodulator_priv = state;
502
503 return &state->frontend;
504
505rcor:
506 kfree(state);
507
508 return NULL;
509}
510EXPORT_SYMBOL(s921_attach);
511
512static struct dvb_frontend_ops s921_ops = {
513 /* Use dib8000 values per default */
514 .info = {
515 .name = "Sharp S921",
516 .type = FE_OFDM,
517 .frequency_min = 470000000,
518 /*
519 * Max should be 770MHz instead, according with Sharp docs,
520 * but Leadership doc says it works up to 806 MHz. This is
521 * required to get channel 69, used in Brazil
522 */
523 .frequency_max = 806000000,
524 .frequency_tolerance = 0,
525 .caps = FE_CAN_INVERSION_AUTO |
526 FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
527 FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
528 FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 |
529 FE_CAN_QAM_AUTO | FE_CAN_TRANSMISSION_MODE_AUTO |
530 FE_CAN_GUARD_INTERVAL_AUTO | FE_CAN_RECOVER |
531 FE_CAN_HIERARCHY_AUTO,
532 },
533
534 .release = s921_release,
535
536 .init = s921_initfe,
537 .set_frontend = s921_set_frontend,
538 .get_frontend = s921_get_frontend,
539 .read_status = s921_read_status,
540 .read_signal_strength = s921_read_signal_strength,
541 .tune = s921_tune,
542 .get_frontend_algo = s921_get_algo,
543};
544
545MODULE_DESCRIPTION("DVB Frontend module for Sharp S921 hardware");
546MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
547MODULE_AUTHOR("Douglas Landgraf <dougsland@redhat.com>");
548MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/s921.h b/drivers/media/dvb/frontends/s921.h
new file mode 100644
index 000000000000..f220d8299c81
--- /dev/null
+++ b/drivers/media/dvb/frontends/s921.h
@@ -0,0 +1,47 @@
1/*
2 * Sharp s921 driver
3 *
4 * Copyright (C) 2009 Mauro Carvalho Chehab <mchehab@redhat.com>
5 * Copyright (C) 2009 Douglas Landgraf <dougsland@redhat.com>
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 * 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 GNU
14 * General Public License for more details.
15 */
16
17#ifndef S921_H
18#define S921_H
19
20#include <linux/dvb/frontend.h>
21
22struct s921_config {
23 /* the demodulator's i2c address */
24 u8 demod_address;
25};
26
27#if defined(CONFIG_DVB_S921) || (defined(CONFIG_DVB_S921_MODULE) \
28 && defined(MODULE))
29extern struct dvb_frontend *s921_attach(const struct s921_config *config,
30 struct i2c_adapter *i2c);
31extern struct i2c_adapter *s921_get_tuner_i2c_adapter(struct dvb_frontend *);
32#else
33static inline struct dvb_frontend *s921_attach(
34 const struct s921_config *config, struct i2c_adapter *i2c)
35{
36 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
37 return NULL;
38}
39static struct i2c_adapter *
40 s921_get_tuner_i2c_adapter(struct dvb_frontend *fe)
41{
42 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
43 return NULL;
44}
45#endif
46
47#endif /* S921_H */
diff --git a/drivers/media/dvb/frontends/s921_core.c b/drivers/media/dvb/frontends/s921_core.c
deleted file mode 100644
index 974b52be9aea..000000000000
--- a/drivers/media/dvb/frontends/s921_core.c
+++ /dev/null
@@ -1,216 +0,0 @@
1/*
2 * Driver for Sharp s921 driver
3 *
4 * Copyright (C) 2008 Markus Rechberger <mrechberger@sundtek.de>
5 *
6 */
7
8
9#include <linux/kernel.h>
10#include <linux/module.h>
11#include <linux/delay.h>
12#include "s921_core.h"
13
14static int s921_isdb_init(struct s921_isdb_t *dev);
15static int s921_isdb_set_parameters(struct s921_isdb_t *dev, struct s921_isdb_t_transmission_mode_params *params);
16static int s921_isdb_tune(struct s921_isdb_t *dev, struct s921_isdb_t_tune_params *params);
17static int s921_isdb_get_status(struct s921_isdb_t *dev, void *data);
18
19static u8 init_table[]={ 0x01, 0x40, 0x02, 0x00, 0x03, 0x40, 0x04, 0x01,
20 0x05, 0x00, 0x06, 0x00, 0x07, 0x00, 0x08, 0x00,
21 0x09, 0x00, 0x0a, 0x00, 0x0b, 0x5a, 0x0c, 0x00,
22 0x0d, 0x00, 0x0f, 0x00, 0x13, 0x1b, 0x14, 0x80,
23 0x15, 0x40, 0x17, 0x70, 0x18, 0x01, 0x19, 0x12,
24 0x1a, 0x01, 0x1b, 0x12, 0x1c, 0xa0, 0x1d, 0x00,
25 0x1e, 0x0a, 0x1f, 0x08, 0x20, 0x40, 0x21, 0xff,
26 0x22, 0x4c, 0x23, 0x4e, 0x24, 0x4c, 0x25, 0x00,
27 0x26, 0x00, 0x27, 0xf4, 0x28, 0x60, 0x29, 0x88,
28 0x2a, 0x40, 0x2b, 0x40, 0x2c, 0xff, 0x2d, 0x00,
29 0x2e, 0xff, 0x2f, 0x00, 0x30, 0x20, 0x31, 0x06,
30 0x32, 0x0c, 0x34, 0x0f, 0x37, 0xfe, 0x38, 0x00,
31 0x39, 0x63, 0x3a, 0x10, 0x3b, 0x10, 0x47, 0x00,
32 0x49, 0xe5, 0x4b, 0x00, 0x50, 0xc0, 0x52, 0x20,
33 0x54, 0x5a, 0x55, 0x5b, 0x56, 0x40, 0x57, 0x70,
34 0x5c, 0x50, 0x5d, 0x00, 0x62, 0x17, 0x63, 0x2f,
35 0x64, 0x6f, 0x68, 0x00, 0x69, 0x89, 0x6a, 0x00,
36 0x6b, 0x00, 0x6c, 0x00, 0x6d, 0x00, 0x6e, 0x00,
37 0x70, 0x00, 0x71, 0x00, 0x75, 0x00, 0x76, 0x30,
38 0x77, 0x01, 0xaf, 0x00, 0xb0, 0xa0, 0xb2, 0x3d,
39 0xb3, 0x25, 0xb4, 0x8b, 0xb5, 0x4b, 0xb6, 0x3f,
40 0xb7, 0xff, 0xb8, 0xff, 0xb9, 0xfc, 0xba, 0x00,
41 0xbb, 0x00, 0xbc, 0x00, 0xd0, 0x30, 0xe4, 0x84,
42 0xf0, 0x48, 0xf1, 0x19, 0xf2, 0x5a, 0xf3, 0x8e,
43 0xf4, 0x2d, 0xf5, 0x07, 0xf6, 0x5a, 0xf7, 0xba,
44 0xf8, 0xd7 };
45
46static u8 c_table[]={ 0x58, 0x8a, 0x7b, 0x59, 0x8c, 0x7b, 0x5a, 0x8e, 0x5b,
47 0x5b, 0x90, 0x5b, 0x5c, 0x92, 0x5b, 0x5d, 0x94, 0x5b,
48 0x5e, 0x96, 0x5b, 0x5f, 0x98, 0x3b, 0x60, 0x9a, 0x3b,
49 0x61, 0x9c, 0x3b, 0x62, 0x9e, 0x3b, 0x63, 0xa0, 0x3b,
50 0x64, 0xa2, 0x1b, 0x65, 0xa4, 0x1b, 0x66, 0xa6, 0x1b,
51 0x67, 0xa8, 0x1b, 0x68, 0xaa, 0x1b, 0x69, 0xac, 0x1b,
52 0x6a, 0xae, 0x1b, 0x6b, 0xb0, 0x1b, 0x6c, 0xb2, 0x1b,
53 0x6d, 0xb4, 0xfb, 0x6e, 0xb6, 0xfb, 0x6f, 0xb8, 0xfb,
54 0x70, 0xba, 0xfb, 0x71, 0xbc, 0xdb, 0x72, 0xbe, 0xdb,
55 0x73, 0xc0, 0xdb, 0x74, 0xc2, 0xdb, 0x75, 0xc4, 0xdb,
56 0x76, 0xc6, 0xdb, 0x77, 0xc8, 0xbb, 0x78, 0xca, 0xbb,
57 0x79, 0xcc, 0xbb, 0x7a, 0xce, 0xbb, 0x7b, 0xd0, 0xbb,
58 0x7c, 0xd2, 0xbb, 0x7d, 0xd4, 0xbb, 0x7e, 0xd6, 0xbb,
59 0x7f, 0xd8, 0xbb, 0x80, 0xda, 0x9b, 0x81, 0xdc, 0x9b,
60 0x82, 0xde, 0x9b, 0x83, 0xe0, 0x9b, 0x84, 0xe2, 0x9b,
61 0x85, 0xe4, 0x9b, 0x86, 0xe6, 0x9b, 0x87, 0xe8, 0x9b,
62 0x88, 0xea, 0x9b, 0x89, 0xec, 0x9b };
63
64int s921_isdb_cmd(struct s921_isdb_t *dev, u32 cmd, void *data) {
65 switch(cmd) {
66 case ISDB_T_CMD_INIT:
67 s921_isdb_init(dev);
68 break;
69 case ISDB_T_CMD_SET_PARAM:
70 s921_isdb_set_parameters(dev, data);
71 break;
72 case ISDB_T_CMD_TUNE:
73 s921_isdb_tune(dev, data);
74 break;
75 case ISDB_T_CMD_GET_STATUS:
76 s921_isdb_get_status(dev, data);
77 break;
78 default:
79 printk("unhandled command\n");
80 return -EINVAL;
81 }
82 return 0;
83}
84
85static int s921_isdb_init(struct s921_isdb_t *dev) {
86 unsigned int i;
87 unsigned int ret;
88 printk("isdb_init\n");
89 for (i = 0; i < sizeof(init_table); i+=2) {
90 ret = dev->i2c_write(dev->priv_dev, init_table[i], init_table[i+1]);
91 if (ret != 0) {
92 printk("i2c write failed\n");
93 return ret;
94 }
95 }
96 return 0;
97}
98
99static int s921_isdb_set_parameters(struct s921_isdb_t *dev, struct s921_isdb_t_transmission_mode_params *params) {
100
101 int ret;
102 /* auto is sufficient for now, lateron this should be reflected in an extra interface */
103
104
105
106 ret = dev->i2c_write(dev->priv_dev, 0xb0, 0xa0); //mod_b2);
107 ret = dev->i2c_write(dev->priv_dev, 0xb2, 0x3d); //mod_b2);
108
109 if (ret < 0)
110 return -EINVAL;
111
112 ret = dev->i2c_write(dev->priv_dev, 0xb3, 0x25); //mod_b3);
113 if (ret < 0)
114 return -EINVAL;
115
116 ret = dev->i2c_write(dev->priv_dev, 0xb4, 0x8b); //mod_b4);
117 if (ret < 0)
118 return -EINVAL;
119
120 ret = dev->i2c_write(dev->priv_dev, 0xb5, 0x4b); //mod_b5);
121 if (ret < 0)
122 return -EINVAL;
123
124 ret = dev->i2c_write(dev->priv_dev, 0xb6, 0x3f); //mod_b6);
125 if (ret < 0)
126 return -EINVAL;
127
128 ret = dev->i2c_write(dev->priv_dev, 0xb7, 0x3f); //mod_b7);
129 if (ret < 0)
130 return -EINVAL;
131
132 return E_OK;
133}
134
135static int s921_isdb_tune(struct s921_isdb_t *dev, struct s921_isdb_t_tune_params *params) {
136
137 int ret;
138 int index;
139
140 index = (params->frequency - 473143000)/6000000;
141
142 if (index > 48) {
143 return -EINVAL;
144 }
145
146 dev->i2c_write(dev->priv_dev, 0x47, 0x60);
147
148 ret = dev->i2c_write(dev->priv_dev, 0x68, 0x00);
149 if (ret < 0)
150 return -EINVAL;
151
152 ret = dev->i2c_write(dev->priv_dev, 0x69, 0x89);
153 if (ret < 0)
154 return -EINVAL;
155
156 ret = dev->i2c_write(dev->priv_dev, 0xf0, 0x48);
157 if (ret < 0)
158 return -EINVAL;
159
160 ret = dev->i2c_write(dev->priv_dev, 0xf1, 0x19);
161 if (ret < 0)
162 return -EINVAL;
163
164 ret = dev->i2c_write(dev->priv_dev, 0xf2, c_table[index*3]);
165 if (ret < 0)
166 return -EINVAL;
167
168 ret = dev->i2c_write(dev->priv_dev, 0xf3, c_table[index*3+1]);
169 if (ret < 0)
170 return -EINVAL;
171
172 ret = dev->i2c_write(dev->priv_dev, 0xf4, c_table[index*3+2]);
173 if (ret < 0)
174 return -EINVAL;
175
176 ret = dev->i2c_write(dev->priv_dev, 0xf5, 0xae);
177 if (ret < 0)
178 return -EINVAL;
179
180 ret = dev->i2c_write(dev->priv_dev, 0xf6, 0xb7);
181 if (ret < 0)
182 return -EINVAL;
183
184 ret = dev->i2c_write(dev->priv_dev, 0xf7, 0xba);
185 if (ret < 0)
186 return -EINVAL;
187
188 ret = dev->i2c_write(dev->priv_dev, 0xf8, 0xd7);
189 if (ret < 0)
190 return -EINVAL;
191
192 ret = dev->i2c_write(dev->priv_dev, 0x68, 0x0a);
193 if (ret < 0)
194 return -EINVAL;
195
196 ret = dev->i2c_write(dev->priv_dev, 0x69, 0x09);
197 if (ret < 0)
198 return -EINVAL;
199
200 dev->i2c_write(dev->priv_dev, 0x01, 0x40);
201 return 0;
202}
203
204static int s921_isdb_get_status(struct s921_isdb_t *dev, void *data) {
205 unsigned int *ret = (unsigned int*)data;
206 u8 ifagc_dt;
207 u8 rfagc_dt;
208
209 mdelay(10);
210 ifagc_dt = dev->i2c_read(dev->priv_dev, 0x81);
211 rfagc_dt = dev->i2c_read(dev->priv_dev, 0x82);
212 if (rfagc_dt == 0x40) {
213 *ret = 1;
214 }
215 return 0;
216}
diff --git a/drivers/media/dvb/frontends/s921_core.h b/drivers/media/dvb/frontends/s921_core.h
deleted file mode 100644
index de2f10a44e72..000000000000
--- a/drivers/media/dvb/frontends/s921_core.h
+++ /dev/null
@@ -1,114 +0,0 @@
1#ifndef _S921_CORE_H
2#define _S921_CORE_H
3//#define u8 unsigned int
4//#define u32 unsigned int
5
6
7
8//#define EINVAL -1
9#define E_OK 0
10
11struct s921_isdb_t {
12 void *priv_dev;
13 int (*i2c_write)(void *dev, u8 reg, u8 val);
14 int (*i2c_read)(void *dev, u8 reg);
15};
16
17#define ISDB_T_CMD_INIT 0
18#define ISDB_T_CMD_SET_PARAM 1
19#define ISDB_T_CMD_TUNE 2
20#define ISDB_T_CMD_GET_STATUS 3
21
22struct s921_isdb_t_tune_params {
23 u32 frequency;
24};
25
26struct s921_isdb_t_status {
27};
28
29struct s921_isdb_t_transmission_mode_params {
30 u8 mode;
31 u8 layer_a_mode;
32#define ISDB_T_LA_MODE_1 0
33#define ISDB_T_LA_MODE_2 1
34#define ISDB_T_LA_MODE_3 2
35 u8 layer_a_carrier_modulation;
36#define ISDB_T_LA_CM_DQPSK 0
37#define ISDB_T_LA_CM_QPSK 1
38#define ISDB_T_LA_CM_16QAM 2
39#define ISDB_T_LA_CM_64QAM 3
40#define ISDB_T_LA_CM_NOLAYER 4
41 u8 layer_a_code_rate;
42#define ISDB_T_LA_CR_1_2 0
43#define ISDB_T_LA_CR_2_3 1
44#define ISDB_T_LA_CR_3_4 2
45#define ISDB_T_LA_CR_5_6 4
46#define ISDB_T_LA_CR_7_8 8
47#define ISDB_T_LA_CR_NOLAYER 16
48 u8 layer_a_time_interleave;
49#define ISDB_T_LA_TI_0 0
50#define ISDB_T_LA_TI_1 1
51#define ISDB_T_LA_TI_2 2
52#define ISDB_T_LA_TI_4 4
53#define ISDB_T_LA_TI_8 8
54#define ISDB_T_LA_TI_16 16
55#define ISDB_T_LA_TI_32 32
56 u8 layer_a_nseg;
57
58 u8 layer_b_mode;
59#define ISDB_T_LB_MODE_1 0
60#define ISDB_T_LB_MODE_2 1
61#define ISDB_T_LB_MODE_3 2
62 u8 layer_b_carrier_modulation;
63#define ISDB_T_LB_CM_DQPSK 0
64#define ISDB_T_LB_CM_QPSK 1
65#define ISDB_T_LB_CM_16QAM 2
66#define ISDB_T_LB_CM_64QAM 3
67#define ISDB_T_LB_CM_NOLAYER 4
68 u8 layer_b_code_rate;
69#define ISDB_T_LB_CR_1_2 0
70#define ISDB_T_LB_CR_2_3 1
71#define ISDB_T_LB_CR_3_4 2
72#define ISDB_T_LB_CR_5_6 4
73#define ISDB_T_LB_CR_7_8 8
74#define ISDB_T_LB_CR_NOLAYER 16
75 u8 layer_b_time_interleave;
76#define ISDB_T_LB_TI_0 0
77#define ISDB_T_LB_TI_1 1
78#define ISDB_T_LB_TI_2 2
79#define ISDB_T_LB_TI_4 4
80#define ISDB_T_LB_TI_8 8
81#define ISDB_T_LB_TI_16 16
82#define ISDB_T_LB_TI_32 32
83 u8 layer_b_nseg;
84
85 u8 layer_c_mode;
86#define ISDB_T_LC_MODE_1 0
87#define ISDB_T_LC_MODE_2 1
88#define ISDB_T_LC_MODE_3 2
89 u8 layer_c_carrier_modulation;
90#define ISDB_T_LC_CM_DQPSK 0
91#define ISDB_T_LC_CM_QPSK 1
92#define ISDB_T_LC_CM_16QAM 2
93#define ISDB_T_LC_CM_64QAM 3
94#define ISDB_T_LC_CM_NOLAYER 4
95 u8 layer_c_code_rate;
96#define ISDB_T_LC_CR_1_2 0
97#define ISDB_T_LC_CR_2_3 1
98#define ISDB_T_LC_CR_3_4 2
99#define ISDB_T_LC_CR_5_6 4
100#define ISDB_T_LC_CR_7_8 8
101#define ISDB_T_LC_CR_NOLAYER 16
102 u8 layer_c_time_interleave;
103#define ISDB_T_LC_TI_0 0
104#define ISDB_T_LC_TI_1 1
105#define ISDB_T_LC_TI_2 2
106#define ISDB_T_LC_TI_4 4
107#define ISDB_T_LC_TI_8 8
108#define ISDB_T_LC_TI_16 16
109#define ISDB_T_LC_TI_32 32
110 u8 layer_c_nseg;
111};
112
113int s921_isdb_cmd(struct s921_isdb_t *dev, u32 cmd, void *data);
114#endif
diff --git a/drivers/media/dvb/frontends/s921_module.c b/drivers/media/dvb/frontends/s921_module.c
deleted file mode 100644
index 0eefff61cc50..000000000000
--- a/drivers/media/dvb/frontends/s921_module.c
+++ /dev/null
@@ -1,192 +0,0 @@
1/*
2 * Driver for Sharp s921 driver
3 *
4 * Copyright (C) 2008 Markus Rechberger <mrechberger@sundtek.de>
5 *
6 * All rights reserved.
7 *
8 */
9
10#include <linux/kernel.h>
11#include <linux/module.h>
12#include <linux/slab.h>
13#include <linux/delay.h>
14#include "dvb_frontend.h"
15#include "s921_module.h"
16#include "s921_core.h"
17
18static unsigned int debug = 0;
19module_param(debug, int, 0644);
20MODULE_PARM_DESC(debug,"s921 debugging (default off)");
21
22#define dprintk(fmt, args...) if (debug) do {\
23 printk("s921 debug: " fmt, ##args); } while (0)
24
25struct s921_state
26{
27 struct dvb_frontend frontend;
28 fe_modulation_t current_modulation;
29 __u32 snr;
30 __u32 current_frequency;
31 __u8 addr;
32 struct s921_isdb_t dev;
33 struct i2c_adapter *i2c;
34};
35
36static int s921_set_parameters(struct dvb_frontend *fe, struct dvb_frontend_parameters *param) {
37 struct s921_state *state = (struct s921_state *)fe->demodulator_priv;
38 struct s921_isdb_t_transmission_mode_params params;
39 struct s921_isdb_t_tune_params tune_params;
40
41 tune_params.frequency = param->frequency;
42 s921_isdb_cmd(&state->dev, ISDB_T_CMD_SET_PARAM, &params);
43 s921_isdb_cmd(&state->dev, ISDB_T_CMD_TUNE, &tune_params);
44 mdelay(100);
45 return 0;
46}
47
48static int s921_init(struct dvb_frontend *fe) {
49 printk("s921 init\n");
50 return 0;
51}
52
53static int s921_sleep(struct dvb_frontend *fe) {
54 printk("s921 sleep\n");
55 return 0;
56}
57
58static int s921_read_status(struct dvb_frontend *fe, fe_status_t *status)
59{
60 struct s921_state *state = (struct s921_state *)fe->demodulator_priv;
61 unsigned int ret;
62 mdelay(5);
63 s921_isdb_cmd(&state->dev, ISDB_T_CMD_GET_STATUS, &ret);
64 *status = 0;
65
66 printk("status: %02x\n", ret);
67 if (ret == 1) {
68 *status |= FE_HAS_CARRIER;
69 *status |= FE_HAS_VITERBI;
70 *status |= FE_HAS_LOCK;
71 *status |= FE_HAS_SYNC;
72 *status |= FE_HAS_SIGNAL;
73 }
74
75 return 0;
76}
77
78static int s921_read_ber(struct dvb_frontend *fe, __u32 *ber)
79{
80 dprintk("read ber\n");
81 return 0;
82}
83
84static int s921_read_snr(struct dvb_frontend *fe, __u16 *snr)
85{
86 dprintk("read snr\n");
87 return 0;
88}
89
90static int s921_read_ucblocks(struct dvb_frontend *fe, __u32 *ucblocks)
91{
92 dprintk("read ucblocks\n");
93 return 0;
94}
95
96static void s921_release(struct dvb_frontend *fe)
97{
98 struct s921_state *state = (struct s921_state *)fe->demodulator_priv;
99 kfree(state);
100}
101
102static struct dvb_frontend_ops demod_s921={
103 .info = {
104 .name = "SHARP S921",
105 .type = FE_OFDM,
106 .frequency_min = 473143000,
107 .frequency_max = 767143000,
108 .frequency_stepsize = 6000000,
109 .frequency_tolerance = 0,
110 .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 |
111 FE_CAN_FEC_3_4 | FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 |
112 FE_CAN_FEC_AUTO |
113 FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
114 FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_GUARD_INTERVAL_AUTO |
115 FE_CAN_HIERARCHY_AUTO | FE_CAN_RECOVER |
116 FE_CAN_MUTE_TS
117 },
118 .init = s921_init,
119 .sleep = s921_sleep,
120 .set_frontend = s921_set_parameters,
121 .read_snr = s921_read_snr,
122 .read_ber = s921_read_ber,
123 .read_status = s921_read_status,
124 .read_ucblocks = s921_read_ucblocks,
125 .release = s921_release,
126};
127
128static int s921_write(void *dev, u8 reg, u8 val) {
129 struct s921_state *state = dev;
130 char buf[2]={reg,val};
131 int err;
132 struct i2c_msg i2cmsgs = {
133 .addr = state->addr,
134 .flags = 0,
135 .len = 2,
136 .buf = buf
137 };
138
139 if((err = i2c_transfer(state->i2c, &i2cmsgs, 1))<0) {
140 printk("%s i2c_transfer error %d\n", __func__, err);
141 if (err < 0)
142 return err;
143 else
144 return -EREMOTEIO;
145 }
146
147 return 0;
148}
149
150static int s921_read(void *dev, u8 reg) {
151 struct s921_state *state = dev;
152 u8 b1;
153 int ret;
154 struct i2c_msg msg[2] = { { .addr = state->addr,
155 .flags = 0,
156 .buf = &reg, .len = 1 },
157 { .addr = state->addr,
158 .flags = I2C_M_RD,
159 .buf = &b1, .len = 1 } };
160
161 ret = i2c_transfer(state->i2c, msg, 2);
162 if (ret != 2)
163 return ret;
164 return b1;
165}
166
167struct dvb_frontend* s921_attach(const struct s921_config *config,
168 struct i2c_adapter *i2c)
169{
170
171 struct s921_state *state;
172 state = kzalloc(sizeof(struct s921_state), GFP_KERNEL);
173 if (state == NULL)
174 return NULL;
175
176 state->addr = config->i2c_address;
177 state->i2c = i2c;
178 state->dev.i2c_write = &s921_write;
179 state->dev.i2c_read = &s921_read;
180 state->dev.priv_dev = state;
181
182 s921_isdb_cmd(&state->dev, ISDB_T_CMD_INIT, NULL);
183
184 memcpy(&state->frontend.ops, &demod_s921, sizeof(struct dvb_frontend_ops));
185 state->frontend.demodulator_priv = state;
186 return &state->frontend;
187}
188
189EXPORT_SYMBOL_GPL(s921_attach);
190MODULE_AUTHOR("Markus Rechberger <mrechberger@empiatech.com>");
191MODULE_DESCRIPTION("Sharp S921 ISDB-T 1Seg");
192MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/s921_module.h b/drivers/media/dvb/frontends/s921_module.h
deleted file mode 100644
index 78660424ba95..000000000000
--- a/drivers/media/dvb/frontends/s921_module.h
+++ /dev/null
@@ -1,49 +0,0 @@
1/*
2 * Driver for DVB-T s921 demodulator
3 *
4 * Copyright (C) 2008 Markus Rechberger <mrechberger@sundtek.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 S921_MODULE_H
23#define S921_MODULE_H
24
25#include <linux/dvb/frontend.h>
26#include "s921_core.h"
27
28int s921_isdb_init(struct s921_isdb_t *dev);
29int s921_isdb_cmd(struct s921_isdb_t *dev, u32 cmd, void *data);
30
31struct s921_config
32{
33 /* demodulator's I2C address */
34 u8 i2c_address;
35};
36
37#if defined(CONFIG_DVB_S921) || (defined(CONFIG_DVB_S921_MODULE) && defined(MODULE))
38extern struct dvb_frontend* s921_attach(const struct s921_config *config,
39 struct i2c_adapter *i2c);
40#else
41static inline struct dvb_frontend* s921_attach(const struct s921_config *config,
42 struct i2c_adapter *i2c)
43{
44 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
45 return NULL;
46}
47#endif /* CONFIG_DVB_S921 */
48
49#endif /* S921_H */
diff --git a/drivers/media/dvb/frontends/stb0899_drv.c b/drivers/media/dvb/frontends/stb0899_drv.c
index 8e38fcee564e..37a222d9ddb3 100644
--- a/drivers/media/dvb/frontends/stb0899_drv.c
+++ b/drivers/media/dvb/frontends/stb0899_drv.c
@@ -714,7 +714,7 @@ static int stb0899_send_diseqc_msg(struct dvb_frontend *fe, struct dvb_diseqc_ma
714 reg = stb0899_read_reg(state, STB0899_DISCNTRL1); 714 reg = stb0899_read_reg(state, STB0899_DISCNTRL1);
715 STB0899_SETFIELD_VAL(DISPRECHARGE, reg, 0); 715 STB0899_SETFIELD_VAL(DISPRECHARGE, reg, 0);
716 stb0899_write_reg(state, STB0899_DISCNTRL1, reg); 716 stb0899_write_reg(state, STB0899_DISCNTRL1, reg);
717 717 msleep(100);
718 return 0; 718 return 0;
719} 719}
720 720
diff --git a/drivers/media/dvb/frontends/stb6100.c b/drivers/media/dvb/frontends/stb6100.c
index 80a9e4cba631..64673b8b64a2 100644
--- a/drivers/media/dvb/frontends/stb6100.c
+++ b/drivers/media/dvb/frontends/stb6100.c
@@ -51,7 +51,7 @@ module_param(verbose, int, 0644);
51 if (x > y) \ 51 if (x > y) \
52 printk(format, ##arg); \ 52 printk(format, ##arg); \
53 } \ 53 } \
54} while(0) 54} while (0)
55 55
56struct stb6100_lkup { 56struct stb6100_lkup {
57 u32 val_low; 57 u32 val_low;
@@ -117,7 +117,10 @@ static const struct stb6100_regmask stb6100_template[] = {
117 [STB6100_TEST3] = { 0x00, 0xde }, 117 [STB6100_TEST3] = { 0x00, 0xde },
118}; 118};
119 119
120static void stb6100_normalise_regs(u8 regs[]) 120/*
121 * Currently unused. Some boards might need it in the future
122 */
123static inline void stb6100_normalise_regs(u8 regs[])
121{ 124{
122 int i; 125 int i;
123 126
@@ -157,13 +160,25 @@ static int stb6100_read_reg(struct stb6100_state *state, u8 reg)
157 u8 regs[STB6100_NUMREGS]; 160 u8 regs[STB6100_NUMREGS];
158 int rc; 161 int rc;
159 162
163 struct i2c_msg msg = {
164 .addr = state->config->tuner_address + reg,
165 .flags = I2C_M_RD,
166 .buf = regs,
167 .len = 1
168 };
169
170 rc = i2c_transfer(state->i2c, &msg, 1);
171
160 if (unlikely(reg >= STB6100_NUMREGS)) { 172 if (unlikely(reg >= STB6100_NUMREGS)) {
161 dprintk(verbose, FE_ERROR, 1, "Invalid register offset 0x%x", reg); 173 dprintk(verbose, FE_ERROR, 1, "Invalid register offset 0x%x", reg);
162 return -EINVAL; 174 return -EINVAL;
163 } 175 }
164 if ((rc = stb6100_read_regs(state, regs)) < 0) 176 if (unlikely(verbose > FE_DEBUG)) {
165 return rc; 177 dprintk(verbose, FE_DEBUG, 1, " Read from 0x%02x", state->config->tuner_address);
166 return (unsigned int)regs[reg]; 178 dprintk(verbose, FE_DEBUG, 1, " %s: 0x%02x", stb6100_regnames[reg], regs[0]);
179 }
180
181 return (unsigned int)regs[0];
167} 182}
168 183
169static int stb6100_write_reg_range(struct stb6100_state *state, u8 buf[], int start, int len) 184static int stb6100_write_reg_range(struct stb6100_state *state, u8 buf[], int start, int len)
@@ -211,20 +226,17 @@ static int stb6100_write_reg(struct stb6100_state *state, u8 reg, u8 data)
211 return stb6100_write_reg_range(state, &data, reg, 1); 226 return stb6100_write_reg_range(state, &data, reg, 1);
212} 227}
213 228
214static int stb6100_write_regs(struct stb6100_state *state, u8 regs[])
215{
216 stb6100_normalise_regs(regs);
217 return stb6100_write_reg_range(state, &regs[1], 1, STB6100_NUMREGS - 1);
218}
219 229
220static int stb6100_get_status(struct dvb_frontend *fe, u32 *status) 230static int stb6100_get_status(struct dvb_frontend *fe, u32 *status)
221{ 231{
222 int rc; 232 int rc;
223 struct stb6100_state *state = fe->tuner_priv; 233 struct stb6100_state *state = fe->tuner_priv;
224 234
225 if ((rc = stb6100_read_reg(state, STB6100_LD)) < 0) 235 rc = stb6100_read_reg(state, STB6100_LD);
236 if (rc < 0) {
237 dprintk(verbose, FE_ERROR, 1, "%s failed", __func__);
226 return rc; 238 return rc;
227 239 }
228 return (rc & STB6100_LD_LOCK) ? TUNER_STATUS_LOCKED : 0; 240 return (rc & STB6100_LD_LOCK) ? TUNER_STATUS_LOCKED : 0;
229} 241}
230 242
@@ -234,7 +246,8 @@ static int stb6100_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
234 u8 f; 246 u8 f;
235 struct stb6100_state *state = fe->tuner_priv; 247 struct stb6100_state *state = fe->tuner_priv;
236 248
237 if ((rc = stb6100_read_reg(state, STB6100_F)) < 0) 249 rc = stb6100_read_reg(state, STB6100_F);
250 if (rc < 0)
238 return rc; 251 return rc;
239 f = rc & STB6100_F_F; 252 f = rc & STB6100_F_F;
240 253
@@ -265,14 +278,21 @@ static int stb6100_set_bandwidth(struct dvb_frontend *fe, u32 bandwidth)
265 /* Turn on LPF bandwidth setting clock control, 278 /* Turn on LPF bandwidth setting clock control,
266 * set bandwidth, wait 10ms, turn off. 279 * set bandwidth, wait 10ms, turn off.
267 */ 280 */
268 if ((rc = stb6100_write_reg(state, STB6100_FCCK, 0x0d | STB6100_FCCK_FCCK)) < 0) 281 rc = stb6100_write_reg(state, STB6100_FCCK, 0x0d | STB6100_FCCK_FCCK);
282 if (rc < 0)
269 return rc; 283 return rc;
270 if ((rc = stb6100_write_reg(state, STB6100_F, 0xc0 | tmp)) < 0) 284 rc = stb6100_write_reg(state, STB6100_F, 0xc0 | tmp);
285 if (rc < 0)
271 return rc; 286 return rc;
272 msleep(1); 287
273 if ((rc = stb6100_write_reg(state, STB6100_FCCK, 0x0d)) < 0) 288 msleep(5); /* This is dangerous as another (related) thread may start */
289
290 rc = stb6100_write_reg(state, STB6100_FCCK, 0x0d);
291 if (rc < 0)
274 return rc; 292 return rc;
275 293
294 msleep(10); /* This is dangerous as another (related) thread may start */
295
276 return 0; 296 return 0;
277} 297}
278 298
@@ -284,7 +304,8 @@ static int stb6100_get_frequency(struct dvb_frontend *fe, u32 *frequency)
284 struct stb6100_state *state = fe->tuner_priv; 304 struct stb6100_state *state = fe->tuner_priv;
285 u8 regs[STB6100_NUMREGS]; 305 u8 regs[STB6100_NUMREGS];
286 306
287 if ((rc = stb6100_read_regs(state, regs)) < 0) 307 rc = stb6100_read_regs(state, regs);
308 if (rc < 0)
288 return rc; 309 return rc;
289 310
290 odiv = (regs[STB6100_VCO] & STB6100_VCO_ODIV) >> STB6100_VCO_ODIV_SHIFT; 311 odiv = (regs[STB6100_VCO] & STB6100_VCO_ODIV) >> STB6100_VCO_ODIV_SHIFT;
@@ -312,8 +333,7 @@ static int stb6100_set_frequency(struct dvb_frontend *fe, u32 frequency)
312 u8 regs[STB6100_NUMREGS]; 333 u8 regs[STB6100_NUMREGS];
313 u8 g, psd2, odiv; 334 u8 g, psd2, odiv;
314 335
315 if ((rc = stb6100_read_regs(state, regs)) < 0) 336 dprintk(verbose, FE_DEBUG, 1, "Version 2010-8-14 13:51");
316 return rc;
317 337
318 if (fe->ops.get_frontend) { 338 if (fe->ops.get_frontend) {
319 dprintk(verbose, FE_DEBUG, 1, "Get frontend parameters"); 339 dprintk(verbose, FE_DEBUG, 1, "Get frontend parameters");
@@ -321,96 +341,140 @@ static int stb6100_set_frequency(struct dvb_frontend *fe, u32 frequency)
321 } 341 }
322 srate = p.u.qpsk.symbol_rate; 342 srate = p.u.qpsk.symbol_rate;
323 343
324 regs[STB6100_DLB] = 0xdc; 344 /* Set up tuner cleanly, LPF calibration on */
325 /* Disable LPEN */ 345 rc = stb6100_write_reg(state, STB6100_FCCK, 0x4d | STB6100_FCCK_FCCK);
326 regs[STB6100_LPEN] &= ~STB6100_LPEN_LPEN; /* PLL Loop disabled */ 346 if (rc < 0)
347 return rc; /* allow LPF calibration */
327 348
328 if ((rc = stb6100_write_regs(state, regs)) < 0) 349 /* PLL Loop disabled, bias on, VCO on, synth on */
350 regs[STB6100_LPEN] = 0xeb;
351 rc = stb6100_write_reg(state, STB6100_LPEN, regs[STB6100_LPEN]);
352 if (rc < 0)
329 return rc; 353 return rc;
330 354
331 /* Baseband gain. */ 355 /* Program the registers with their data values */
332 if (srate >= 15000000)
333 g = 9; // +4 dB
334 else if (srate >= 5000000)
335 g = 11; // +8 dB
336 else
337 g = 14; // +14 dB
338
339 regs[STB6100_G] = (regs[STB6100_G] & ~STB6100_G_G) | g;
340 regs[STB6100_G] &= ~STB6100_G_GCT; /* mask GCT */
341 regs[STB6100_G] |= (1 << 5); /* 2Vp-p Mode */
342 356
343 /* VCO divide ratio (LO divide ratio, VCO prescaler enable). */ 357 /* VCO divide ratio (LO divide ratio, VCO prescaler enable). */
344 if (frequency <= 1075000) 358 if (frequency <= 1075000)
345 odiv = 1; 359 odiv = 1;
346 else 360 else
347 odiv = 0; 361 odiv = 0;
348 regs[STB6100_VCO] = (regs[STB6100_VCO] & ~STB6100_VCO_ODIV) | (odiv << STB6100_VCO_ODIV_SHIFT);
349 362
350 if ((frequency > 1075000) && (frequency <= 1325000)) 363 /* VCO enabled, seach clock off as per LL3.7, 3.4.1 */
351 psd2 = 0; 364 regs[STB6100_VCO] = 0xe0 | (odiv << STB6100_VCO_ODIV_SHIFT);
352 else
353 psd2 = 1;
354 regs[STB6100_K] = (regs[STB6100_K] & ~STB6100_K_PSD2) | (psd2 << STB6100_K_PSD2_SHIFT);
355 365
356 /* OSM */ 366 /* OSM */
357 for (ptr = lkup; 367 for (ptr = lkup;
358 (ptr->val_high != 0) && !CHKRANGE(frequency, ptr->val_low, ptr->val_high); 368 (ptr->val_high != 0) && !CHKRANGE(frequency, ptr->val_low, ptr->val_high);
359 ptr++); 369 ptr++);
370
360 if (ptr->val_high == 0) { 371 if (ptr->val_high == 0) {
361 printk(KERN_ERR "%s: frequency out of range: %u kHz\n", __func__, frequency); 372 printk(KERN_ERR "%s: frequency out of range: %u kHz\n", __func__, frequency);
362 return -EINVAL; 373 return -EINVAL;
363 } 374 }
364 regs[STB6100_VCO] = (regs[STB6100_VCO] & ~STB6100_VCO_OSM) | ptr->reg; 375 regs[STB6100_VCO] = (regs[STB6100_VCO] & ~STB6100_VCO_OSM) | ptr->reg;
376 rc = stb6100_write_reg(state, STB6100_VCO, regs[STB6100_VCO]);
377 if (rc < 0)
378 return rc;
365 379
380 if ((frequency > 1075000) && (frequency <= 1325000))
381 psd2 = 0;
382 else
383 psd2 = 1;
366 /* F(VCO) = F(LO) * (ODIV == 0 ? 2 : 4) */ 384 /* F(VCO) = F(LO) * (ODIV == 0 ? 2 : 4) */
367 fvco = frequency << (1 + odiv); 385 fvco = frequency << (1 + odiv);
368 /* N(I) = floor(f(VCO) / (f(XTAL) * (PSD2 ? 2 : 1))) */ 386 /* N(I) = floor(f(VCO) / (f(XTAL) * (PSD2 ? 2 : 1))) */
369 nint = fvco / (state->reference << psd2); 387 nint = fvco / (state->reference << psd2);
370 /* N(F) = round(f(VCO) / f(XTAL) * (PSD2 ? 2 : 1) - N(I)) * 2 ^ 9 */ 388 /* N(F) = round(f(VCO) / f(XTAL) * (PSD2 ? 2 : 1) - N(I)) * 2 ^ 9 */
371 nfrac = DIV_ROUND_CLOSEST((fvco - (nint * state->reference << psd2)) 389 nfrac = DIV_ROUND_CLOSEST((fvco - (nint * state->reference << psd2))
372 << (9 - psd2), 390 << (9 - psd2), state->reference);
373 state->reference); 391
392 /* NI */
393 regs[STB6100_NI] = nint;
394 rc = stb6100_write_reg(state, STB6100_NI, regs[STB6100_NI]);
395 if (rc < 0)
396 return rc;
397
398 /* NF */
399 regs[STB6100_NF_LSB] = nfrac;
400 rc = stb6100_write_reg(state, STB6100_NF_LSB, regs[STB6100_NF_LSB]);
401 if (rc < 0)
402 return rc;
403
404 /* K */
405 regs[STB6100_K] = (0x38 & ~STB6100_K_PSD2) | (psd2 << STB6100_K_PSD2_SHIFT);
406 regs[STB6100_K] = (regs[STB6100_K] & ~STB6100_K_NF_MSB) | ((nfrac >> 8) & STB6100_K_NF_MSB);
407 rc = stb6100_write_reg(state, STB6100_K, regs[STB6100_K]);
408 if (rc < 0)
409 return rc;
410
411 /* G Baseband gain. */
412 if (srate >= 15000000)
413 g = 9; /* +4 dB */
414 else if (srate >= 5000000)
415 g = 11; /* +8 dB */
416 else
417 g = 14; /* +14 dB */
418
419 regs[STB6100_G] = (0x10 & ~STB6100_G_G) | g;
420 regs[STB6100_G] &= ~STB6100_G_GCT; /* mask GCT */
421 regs[STB6100_G] |= (1 << 5); /* 2Vp-p Mode */
422 rc = stb6100_write_reg(state, STB6100_G, regs[STB6100_G]);
423 if (rc < 0)
424 return rc;
425
426 /* F we don't write as it is set up in BW set */
427
428 /* DLB set DC servo loop BW to 160Hz (LLA 3.8 / 2.1) */
429 regs[STB6100_DLB] = 0xcc;
430 rc = stb6100_write_reg(state, STB6100_DLB, regs[STB6100_DLB]);
431 if (rc < 0)
432 return rc;
433
374 dprintk(verbose, FE_DEBUG, 1, 434 dprintk(verbose, FE_DEBUG, 1,
375 "frequency = %u, srate = %u, g = %u, odiv = %u, psd2 = %u, fxtal = %u, osm = %u, fvco = %u, N(I) = %u, N(F) = %u", 435 "frequency = %u, srate = %u, g = %u, odiv = %u, psd2 = %u, fxtal = %u, osm = %u, fvco = %u, N(I) = %u, N(F) = %u",
376 frequency, srate, (unsigned int)g, (unsigned int)odiv, 436 frequency, srate, (unsigned int)g, (unsigned int)odiv,
377 (unsigned int)psd2, state->reference, 437 (unsigned int)psd2, state->reference,
378 ptr->reg, fvco, nint, nfrac); 438 ptr->reg, fvco, nint, nfrac);
379 regs[STB6100_NI] = nint;
380 regs[STB6100_NF_LSB] = nfrac;
381 regs[STB6100_K] = (regs[STB6100_K] & ~STB6100_K_NF_MSB) | ((nfrac >> 8) & STB6100_K_NF_MSB);
382 regs[STB6100_VCO] |= STB6100_VCO_OSCH; /* VCO search enabled */
383 regs[STB6100_VCO] |= STB6100_VCO_OCK; /* VCO search clock off */
384 regs[STB6100_FCCK] |= STB6100_FCCK_FCCK; /* LPF BW setting clock enabled */
385 regs[STB6100_LPEN] &= ~STB6100_LPEN_LPEN; /* PLL loop disabled */
386 /* Power up. */
387 regs[STB6100_LPEN] |= STB6100_LPEN_SYNP | STB6100_LPEN_OSCP | STB6100_LPEN_BEN;
388 439
389 msleep(2); 440 /* Set up the test registers */
390 if ((rc = stb6100_write_regs(state, regs)) < 0) 441 regs[STB6100_TEST1] = 0x8f;
442 rc = stb6100_write_reg(state, STB6100_TEST1, regs[STB6100_TEST1]);
443 if (rc < 0)
444 return rc;
445 regs[STB6100_TEST3] = 0xde;
446 rc = stb6100_write_reg(state, STB6100_TEST3, regs[STB6100_TEST3]);
447 if (rc < 0)
391 return rc; 448 return rc;
392 449
393 msleep(2); 450 /* Bring up tuner according to LLA 3.7 3.4.1, step 2 */
394 regs[STB6100_LPEN] |= STB6100_LPEN_LPEN; /* PLL loop enabled */ 451 regs[STB6100_LPEN] = 0xfb; /* PLL Loop enabled, bias on, VCO on, synth on */
395 if ((rc = stb6100_write_reg(state, STB6100_LPEN, regs[STB6100_LPEN])) < 0) 452 rc = stb6100_write_reg(state, STB6100_LPEN, regs[STB6100_LPEN]);
453 if (rc < 0)
396 return rc; 454 return rc;
397 455
456 msleep(2);
457
458 /* Bring up tuner according to LLA 3.7 3.4.1, step 3 */
398 regs[STB6100_VCO] &= ~STB6100_VCO_OCK; /* VCO fast search */ 459 regs[STB6100_VCO] &= ~STB6100_VCO_OCK; /* VCO fast search */
399 if ((rc = stb6100_write_reg(state, STB6100_VCO, regs[STB6100_VCO])) < 0) 460 rc = stb6100_write_reg(state, STB6100_VCO, regs[STB6100_VCO]);
461 if (rc < 0)
400 return rc; 462 return rc;
401 463
402 msleep(10); /* wait for LO to lock */ 464 msleep(10); /* This is dangerous as another (related) thread may start */ /* wait for LO to lock */
465
403 regs[STB6100_VCO] &= ~STB6100_VCO_OSCH; /* vco search disabled */ 466 regs[STB6100_VCO] &= ~STB6100_VCO_OSCH; /* vco search disabled */
404 regs[STB6100_VCO] |= STB6100_VCO_OCK; /* search clock off */ 467 regs[STB6100_VCO] |= STB6100_VCO_OCK; /* search clock off */
405 if ((rc = stb6100_write_reg(state, STB6100_VCO, regs[STB6100_VCO])) < 0) 468 rc = stb6100_write_reg(state, STB6100_VCO, regs[STB6100_VCO]);
406 return rc; 469 if (rc < 0)
407 regs[STB6100_FCCK] &= ~STB6100_FCCK_FCCK; /* LPF BW clock disabled */
408 stb6100_normalise_regs(regs);
409 if ((rc = stb6100_write_reg_range(state, &regs[1], 1, STB6100_NUMREGS - 3)) < 0)
410 return rc; 470 return rc;
411 471
412 msleep(100); 472 rc = stb6100_write_reg(state, STB6100_FCCK, 0x0d);
473 if (rc < 0)
474 return rc; /* Stop LPF calibration */
413 475
476 msleep(10); /* This is dangerous as another (related) thread may start */
477 /* wait for stabilisation, (should not be necessary) */
414 return 0; 478 return 0;
415} 479}
416 480
@@ -433,8 +497,8 @@ static int stb6100_init(struct dvb_frontend *fe)
433 state->bandwidth = status->bandwidth * 1000; /* Hz */ 497 state->bandwidth = status->bandwidth * 1000; /* Hz */
434 state->reference = status->refclock / 1000; /* kHz */ 498 state->reference = status->refclock / 1000; /* kHz */
435 499
436 /* Set default bandwidth. */ 500 /* Set default bandwidth. Modified, PN 13-May-10 */
437 return stb6100_set_bandwidth(fe, state->bandwidth); 501 return 0;
438} 502}
439 503
440static int stb6100_get_state(struct dvb_frontend *fe, 504static int stb6100_get_state(struct dvb_frontend *fe,
diff --git a/drivers/media/dvb/frontends/stv090x.c b/drivers/media/dvb/frontends/stv090x.c
index 425e7a43ae19..4e0fc2c8a41c 100644
--- a/drivers/media/dvb/frontends/stv090x.c
+++ b/drivers/media/dvb/frontends/stv090x.c
@@ -1483,8 +1483,8 @@ static int stv090x_start_search(struct stv090x_state *state)
1483 if (STV090x_WRITE_DEMOD(state, FFECFG, 0x41) < 0) 1483 if (STV090x_WRITE_DEMOD(state, FFECFG, 0x41) < 0)
1484 goto err; 1484 goto err;
1485 1485
1486 if ((state->search_mode == STV090x_DVBS1) || 1486 if ((state->search_mode == STV090x_SEARCH_DVBS1) ||
1487 (state->search_mode == STV090x_DSS) || 1487 (state->search_mode == STV090x_SEARCH_DSS) ||
1488 (state->search_mode == STV090x_SEARCH_AUTO)) { 1488 (state->search_mode == STV090x_SEARCH_AUTO)) {
1489 1489
1490 if (STV090x_WRITE_DEMOD(state, VITSCALE, 0x82) < 0) 1490 if (STV090x_WRITE_DEMOD(state, VITSCALE, 0x82) < 0)
@@ -2940,7 +2940,7 @@ static int stv090x_optimize_track(struct stv090x_state *state)
2940 STV090x_WRITE_DEMOD(state, ERRCTRL1, 0x67); /* PER */ 2940 STV090x_WRITE_DEMOD(state, ERRCTRL1, 0x67); /* PER */
2941 break; 2941 break;
2942 2942
2943 case STV090x_UNKNOWN: 2943 case STV090x_ERROR:
2944 default: 2944 default:
2945 reg = STV090x_READ_DEMOD(state, DMDCFGMD); 2945 reg = STV090x_READ_DEMOD(state, DMDCFGMD);
2946 STV090x_SETFIELD_Px(reg, DVBS1_ENABLE_FIELD, 1); 2946 STV090x_SETFIELD_Px(reg, DVBS1_ENABLE_FIELD, 1);
diff --git a/drivers/media/dvb/mantis/Kconfig b/drivers/media/dvb/mantis/Kconfig
index fd0830ed10d8..a13a50503134 100644
--- a/drivers/media/dvb/mantis/Kconfig
+++ b/drivers/media/dvb/mantis/Kconfig
@@ -1,6 +1,6 @@
1config MANTIS_CORE 1config MANTIS_CORE
2 tristate "Mantis/Hopper PCI bridge based devices" 2 tristate "Mantis/Hopper PCI bridge based devices"
3 depends on PCI && I2C && INPUT && IR_CORE 3 depends on PCI && I2C && INPUT && RC_CORE
4 4
5 help 5 help
6 Support for PCI cards based on the Mantis and Hopper PCi bridge. 6 Support for PCI cards based on the Mantis and Hopper PCi bridge.
diff --git a/drivers/media/dvb/mantis/hopper_cards.c b/drivers/media/dvb/mantis/hopper_cards.c
index 09e9fc785189..70e73afefb3d 100644
--- a/drivers/media/dvb/mantis/hopper_cards.c
+++ b/drivers/media/dvb/mantis/hopper_cards.c
@@ -251,6 +251,8 @@ static struct pci_device_id hopper_pci_table[] = {
251 { } 251 { }
252}; 252};
253 253
254MODULE_DEVICE_TABLE(pci, hopper_pci_table);
255
254static struct pci_driver hopper_pci_driver = { 256static struct pci_driver hopper_pci_driver = {
255 .name = DRIVER_NAME, 257 .name = DRIVER_NAME,
256 .id_table = hopper_pci_table, 258 .id_table = hopper_pci_table,
diff --git a/drivers/media/dvb/mantis/hopper_vp3028.c b/drivers/media/dvb/mantis/hopper_vp3028.c
index 96674c78e86b..68a29f8bdf73 100644
--- a/drivers/media/dvb/mantis/hopper_vp3028.c
+++ b/drivers/media/dvb/mantis/hopper_vp3028.c
@@ -47,17 +47,17 @@ static int vp3028_frontend_init(struct mantis_pci *mantis, struct dvb_frontend *
47 struct mantis_hwconfig *config = mantis->hwconfig; 47 struct mantis_hwconfig *config = mantis->hwconfig;
48 int err = 0; 48 int err = 0;
49 49
50 gpio_set_bits(mantis, config->reset, 0); 50 mantis_gpio_set_bits(mantis, config->reset, 0);
51 msleep(100); 51 msleep(100);
52 err = mantis_frontend_power(mantis, POWER_ON); 52 err = mantis_frontend_power(mantis, POWER_ON);
53 msleep(100); 53 msleep(100);
54 gpio_set_bits(mantis, config->reset, 1); 54 mantis_gpio_set_bits(mantis, config->reset, 1);
55 55
56 err = mantis_frontend_power(mantis, POWER_ON); 56 err = mantis_frontend_power(mantis, POWER_ON);
57 if (err == 0) { 57 if (err == 0) {
58 msleep(250); 58 msleep(250);
59 dprintk(MANTIS_ERROR, 1, "Probing for 10353 (DVB-T)"); 59 dprintk(MANTIS_ERROR, 1, "Probing for 10353 (DVB-T)");
60 fe = zl10353_attach(&hopper_vp3028_config, adapter); 60 fe = dvb_attach(zl10353_attach, &hopper_vp3028_config, adapter);
61 61
62 if (!fe) 62 if (!fe)
63 return -1; 63 return -1;
diff --git a/drivers/media/dvb/mantis/mantis_cards.c b/drivers/media/dvb/mantis/mantis_cards.c
index cf4b39ffdaad..40da225098cc 100644
--- a/drivers/media/dvb/mantis/mantis_cards.c
+++ b/drivers/media/dvb/mantis/mantis_cards.c
@@ -281,6 +281,8 @@ static struct pci_device_id mantis_pci_table[] = {
281 { } 281 { }
282}; 282};
283 283
284MODULE_DEVICE_TABLE(pci, mantis_pci_table);
285
284static struct pci_driver mantis_pci_driver = { 286static struct pci_driver mantis_pci_driver = {
285 .name = DRIVER_NAME, 287 .name = DRIVER_NAME,
286 .id_table = mantis_pci_table, 288 .id_table = mantis_pci_table,
diff --git a/drivers/media/dvb/mantis/mantis_common.h b/drivers/media/dvb/mantis/mantis_common.h
index d0b645a483c9..bd400d21b81f 100644
--- a/drivers/media/dvb/mantis/mantis_common.h
+++ b/drivers/media/dvb/mantis/mantis_common.h
@@ -171,7 +171,9 @@ struct mantis_pci {
171 struct work_struct uart_work; 171 struct work_struct uart_work;
172 spinlock_t uart_lock; 172 spinlock_t uart_lock;
173 173
174 struct input_dev *rc; 174 struct rc_dev *rc;
175 char input_name[80];
176 char input_phys[80];
175}; 177};
176 178
177#define MANTIS_HIF_STATUS (mantis->gpio_status) 179#define MANTIS_HIF_STATUS (mantis->gpio_status)
diff --git a/drivers/media/dvb/mantis/mantis_dvb.c b/drivers/media/dvb/mantis/mantis_dvb.c
index 99d82eec3b03..e5180e45d310 100644
--- a/drivers/media/dvb/mantis/mantis_dvb.c
+++ b/drivers/media/dvb/mantis/mantis_dvb.c
@@ -47,15 +47,15 @@ int mantis_frontend_power(struct mantis_pci *mantis, enum mantis_power power)
47 switch (power) { 47 switch (power) {
48 case POWER_ON: 48 case POWER_ON:
49 dprintk(MANTIS_DEBUG, 1, "Power ON"); 49 dprintk(MANTIS_DEBUG, 1, "Power ON");
50 gpio_set_bits(mantis, config->power, POWER_ON); 50 mantis_gpio_set_bits(mantis, config->power, POWER_ON);
51 msleep(100); 51 msleep(100);
52 gpio_set_bits(mantis, config->power, POWER_ON); 52 mantis_gpio_set_bits(mantis, config->power, POWER_ON);
53 msleep(100); 53 msleep(100);
54 break; 54 break;
55 55
56 case POWER_OFF: 56 case POWER_OFF:
57 dprintk(MANTIS_DEBUG, 1, "Power OFF"); 57 dprintk(MANTIS_DEBUG, 1, "Power OFF");
58 gpio_set_bits(mantis, config->power, POWER_OFF); 58 mantis_gpio_set_bits(mantis, config->power, POWER_OFF);
59 msleep(100); 59 msleep(100);
60 break; 60 break;
61 61
@@ -73,13 +73,13 @@ void mantis_frontend_soft_reset(struct mantis_pci *mantis)
73 struct mantis_hwconfig *config = mantis->hwconfig; 73 struct mantis_hwconfig *config = mantis->hwconfig;
74 74
75 dprintk(MANTIS_DEBUG, 1, "Frontend RESET"); 75 dprintk(MANTIS_DEBUG, 1, "Frontend RESET");
76 gpio_set_bits(mantis, config->reset, 0); 76 mantis_gpio_set_bits(mantis, config->reset, 0);
77 msleep(100); 77 msleep(100);
78 gpio_set_bits(mantis, config->reset, 0); 78 mantis_gpio_set_bits(mantis, config->reset, 0);
79 msleep(100); 79 msleep(100);
80 gpio_set_bits(mantis, config->reset, 1); 80 mantis_gpio_set_bits(mantis, config->reset, 1);
81 msleep(100); 81 msleep(100);
82 gpio_set_bits(mantis, config->reset, 1); 82 mantis_gpio_set_bits(mantis, config->reset, 1);
83 msleep(100); 83 msleep(100);
84 84
85 return; 85 return;
@@ -117,6 +117,7 @@ static int mantis_dvb_start_feed(struct dvb_demux_feed *dvbdmxfeed)
117 if (mantis->feeds == 1) { 117 if (mantis->feeds == 1) {
118 dprintk(MANTIS_DEBUG, 1, "mantis start feed & dma"); 118 dprintk(MANTIS_DEBUG, 1, "mantis start feed & dma");
119 mantis_dma_start(mantis); 119 mantis_dma_start(mantis);
120 tasklet_enable(&mantis->tasklet);
120 } 121 }
121 122
122 return mantis->feeds; 123 return mantis->feeds;
@@ -136,6 +137,7 @@ static int mantis_dvb_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
136 mantis->feeds--; 137 mantis->feeds--;
137 if (mantis->feeds == 0) { 138 if (mantis->feeds == 0) {
138 dprintk(MANTIS_DEBUG, 1, "mantis stop feed and dma"); 139 dprintk(MANTIS_DEBUG, 1, "mantis stop feed and dma");
140 tasklet_disable(&mantis->tasklet);
139 mantis_dma_stop(mantis); 141 mantis_dma_stop(mantis);
140 } 142 }
141 143
@@ -216,6 +218,7 @@ int __devinit mantis_dvb_init(struct mantis_pci *mantis)
216 218
217 dvb_net_init(&mantis->dvb_adapter, &mantis->dvbnet, &mantis->demux.dmx); 219 dvb_net_init(&mantis->dvb_adapter, &mantis->dvbnet, &mantis->demux.dmx);
218 tasklet_init(&mantis->tasklet, mantis_dma_xfer, (unsigned long) mantis); 220 tasklet_init(&mantis->tasklet, mantis_dma_xfer, (unsigned long) mantis);
221 tasklet_disable(&mantis->tasklet);
219 if (mantis->hwconfig) { 222 if (mantis->hwconfig) {
220 result = config->frontend_init(mantis, mantis->fe); 223 result = config->frontend_init(mantis, mantis->fe);
221 if (result < 0) { 224 if (result < 0) {
diff --git a/drivers/media/dvb/mantis/mantis_input.c b/drivers/media/dvb/mantis/mantis_input.c
index a99489b8418b..db6d54d3fec0 100644
--- a/drivers/media/dvb/mantis/mantis_input.c
+++ b/drivers/media/dvb/mantis/mantis_input.c
@@ -18,8 +18,7 @@
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/ 19*/
20 20
21#include <linux/input.h> 21#include <media/rc-core.h>
22#include <media/ir-core.h>
23#include <linux/pci.h> 22#include <linux/pci.h>
24 23
25#include "dmxdev.h" 24#include "dmxdev.h"
@@ -33,8 +32,9 @@
33#include "mantis_uart.h" 32#include "mantis_uart.h"
34 33
35#define MODULE_NAME "mantis_core" 34#define MODULE_NAME "mantis_core"
35#define RC_MAP_MANTIS "rc-mantis"
36 36
37static struct ir_scancode mantis_ir_table[] = { 37static struct rc_map_table mantis_ir_table[] = {
38 { 0x29, KEY_POWER }, 38 { 0x29, KEY_POWER },
39 { 0x28, KEY_FAVORITES }, 39 { 0x28, KEY_FAVORITES },
40 { 0x30, KEY_TEXT }, 40 { 0x30, KEY_TEXT },
@@ -95,53 +95,65 @@ static struct ir_scancode mantis_ir_table[] = {
95 { 0x00, KEY_BLUE }, 95 { 0x00, KEY_BLUE },
96}; 96};
97 97
98struct ir_scancode_table ir_mantis = { 98static struct rc_map_list ir_mantis_map = {
99 .scan = mantis_ir_table, 99 .map = {
100 .size = ARRAY_SIZE(mantis_ir_table), 100 .scan = mantis_ir_table,
101 .size = ARRAY_SIZE(mantis_ir_table),
102 .rc_type = RC_TYPE_UNKNOWN,
103 .name = RC_MAP_MANTIS,
104 }
101}; 105};
102EXPORT_SYMBOL_GPL(ir_mantis);
103 106
104int mantis_input_init(struct mantis_pci *mantis) 107int mantis_input_init(struct mantis_pci *mantis)
105{ 108{
106 struct input_dev *rc; 109 struct rc_dev *dev;
107 char name[80], dev[80];
108 int err; 110 int err;
109 111
110 rc = input_allocate_device(); 112 err = rc_map_register(&ir_mantis_map);
111 if (!rc) { 113 if (err)
112 dprintk(MANTIS_ERROR, 1, "Input device allocate failed"); 114 goto out;
113 return -ENOMEM;
114 }
115 115
116 sprintf(name, "Mantis %s IR receiver", mantis->hwconfig->model_name); 116 dev = rc_allocate_device();
117 sprintf(dev, "pci-%s/ir0", pci_name(mantis->pdev)); 117 if (!dev) {
118 dprintk(MANTIS_ERROR, 1, "Remote device allocation failed");
119 err = -ENOMEM;
120 goto out_map;
121 }
118 122
119 rc->name = name; 123 sprintf(mantis->input_name, "Mantis %s IR receiver", mantis->hwconfig->model_name);
120 rc->phys = dev; 124 sprintf(mantis->input_phys, "pci-%s/ir0", pci_name(mantis->pdev));
121 125
122 rc->id.bustype = BUS_PCI; 126 dev->input_name = mantis->input_name;
123 rc->id.vendor = mantis->vendor_id; 127 dev->input_phys = mantis->input_phys;
124 rc->id.product = mantis->device_id; 128 dev->input_id.bustype = BUS_PCI;
125 rc->id.version = 1; 129 dev->input_id.vendor = mantis->vendor_id;
126 rc->dev = mantis->pdev->dev; 130 dev->input_id.product = mantis->device_id;
131 dev->input_id.version = 1;
132 dev->driver_name = MODULE_NAME;
133 dev->map_name = RC_MAP_MANTIS;
134 dev->dev.parent = &mantis->pdev->dev;
127 135
128 err = __ir_input_register(rc, &ir_mantis, NULL, MODULE_NAME); 136 err = rc_register_device(dev);
129 if (err) { 137 if (err) {
130 dprintk(MANTIS_ERROR, 1, "IR device registration failed, ret = %d", err); 138 dprintk(MANTIS_ERROR, 1, "IR device registration failed, ret = %d", err);
131 input_free_device(rc); 139 goto out_dev;
132 return -ENODEV;
133 } 140 }
134 141
135 mantis->rc = rc; 142 mantis->rc = dev;
136
137 return 0; 143 return 0;
144
145out_dev:
146 rc_free_device(dev);
147out_map:
148 rc_map_unregister(&ir_mantis_map);
149out:
150 return err;
138} 151}
139 152
140int mantis_exit(struct mantis_pci *mantis) 153int mantis_exit(struct mantis_pci *mantis)
141{ 154{
142 struct input_dev *rc = mantis->rc; 155 rc_unregister_device(mantis->rc);
143 156 rc_map_unregister(&ir_mantis_map);
144 ir_input_unregister(rc);
145
146 return 0; 157 return 0;
147} 158}
159
diff --git a/drivers/media/dvb/mantis/mantis_ioc.c b/drivers/media/dvb/mantis/mantis_ioc.c
index fe31cfb0b158..479086dbb9a8 100644
--- a/drivers/media/dvb/mantis/mantis_ioc.c
+++ b/drivers/media/dvb/mantis/mantis_ioc.c
@@ -75,7 +75,7 @@ int mantis_get_mac(struct mantis_pci *mantis)
75EXPORT_SYMBOL_GPL(mantis_get_mac); 75EXPORT_SYMBOL_GPL(mantis_get_mac);
76 76
77/* Turn the given bit on or off. */ 77/* Turn the given bit on or off. */
78void gpio_set_bits(struct mantis_pci *mantis, u32 bitpos, u8 value) 78void mantis_gpio_set_bits(struct mantis_pci *mantis, u32 bitpos, u8 value)
79{ 79{
80 u32 cur; 80 u32 cur;
81 81
@@ -90,7 +90,7 @@ void gpio_set_bits(struct mantis_pci *mantis, u32 bitpos, u8 value)
90 mmwrite(mantis->gpio_status, MANTIS_GPIF_ADDR); 90 mmwrite(mantis->gpio_status, MANTIS_GPIF_ADDR);
91 mmwrite(0x00, MANTIS_GPIF_DOUT); 91 mmwrite(0x00, MANTIS_GPIF_DOUT);
92} 92}
93EXPORT_SYMBOL_GPL(gpio_set_bits); 93EXPORT_SYMBOL_GPL(mantis_gpio_set_bits);
94 94
95int mantis_stream_control(struct mantis_pci *mantis, enum mantis_stream_control stream_ctl) 95int mantis_stream_control(struct mantis_pci *mantis, enum mantis_stream_control stream_ctl)
96{ 96{
diff --git a/drivers/media/dvb/mantis/mantis_ioc.h b/drivers/media/dvb/mantis/mantis_ioc.h
index 188fe5a81614..d56e002b2955 100644
--- a/drivers/media/dvb/mantis/mantis_ioc.h
+++ b/drivers/media/dvb/mantis/mantis_ioc.h
@@ -44,7 +44,7 @@ enum mantis_stream_control {
44}; 44};
45 45
46extern int mantis_get_mac(struct mantis_pci *mantis); 46extern int mantis_get_mac(struct mantis_pci *mantis);
47extern void gpio_set_bits(struct mantis_pci *mantis, u32 bitpos, u8 value); 47extern void mantis_gpio_set_bits(struct mantis_pci *mantis, u32 bitpos, u8 value);
48 48
49extern int mantis_stream_control(struct mantis_pci *mantis, enum mantis_stream_control stream_ctl); 49extern int mantis_stream_control(struct mantis_pci *mantis, enum mantis_stream_control stream_ctl);
50 50
diff --git a/drivers/media/dvb/mantis/mantis_vp1033.c b/drivers/media/dvb/mantis/mantis_vp1033.c
index 4a723bda0031..deec927c7f7a 100644
--- a/drivers/media/dvb/mantis/mantis_vp1033.c
+++ b/drivers/media/dvb/mantis/mantis_vp1033.c
@@ -173,7 +173,7 @@ static int vp1033_frontend_init(struct mantis_pci *mantis, struct dvb_frontend *
173 msleep(250); 173 msleep(250);
174 174
175 dprintk(MANTIS_ERROR, 1, "Probing for STV0299 (DVB-S)"); 175 dprintk(MANTIS_ERROR, 1, "Probing for STV0299 (DVB-S)");
176 fe = stv0299_attach(&lgtdqcs001f_config, adapter); 176 fe = dvb_attach(stv0299_attach, &lgtdqcs001f_config, adapter);
177 177
178 if (fe) { 178 if (fe) {
179 fe->ops.tuner_ops.set_params = lgtdqcs001f_tuner_set; 179 fe->ops.tuner_ops.set_params = lgtdqcs001f_tuner_set;
diff --git a/drivers/media/dvb/mantis/mantis_vp1034.c b/drivers/media/dvb/mantis/mantis_vp1034.c
index 8e6ae558ee57..26bc0cbe84d4 100644
--- a/drivers/media/dvb/mantis/mantis_vp1034.c
+++ b/drivers/media/dvb/mantis/mantis_vp1034.c
@@ -50,13 +50,13 @@ int vp1034_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
50 switch (voltage) { 50 switch (voltage) {
51 case SEC_VOLTAGE_13: 51 case SEC_VOLTAGE_13:
52 dprintk(MANTIS_ERROR, 1, "Polarization=[13V]"); 52 dprintk(MANTIS_ERROR, 1, "Polarization=[13V]");
53 gpio_set_bits(mantis, 13, 1); 53 mantis_gpio_set_bits(mantis, 13, 1);
54 gpio_set_bits(mantis, 14, 0); 54 mantis_gpio_set_bits(mantis, 14, 0);
55 break; 55 break;
56 case SEC_VOLTAGE_18: 56 case SEC_VOLTAGE_18:
57 dprintk(MANTIS_ERROR, 1, "Polarization=[18V]"); 57 dprintk(MANTIS_ERROR, 1, "Polarization=[18V]");
58 gpio_set_bits(mantis, 13, 1); 58 mantis_gpio_set_bits(mantis, 13, 1);
59 gpio_set_bits(mantis, 14, 1); 59 mantis_gpio_set_bits(mantis, 14, 1);
60 break; 60 break;
61 case SEC_VOLTAGE_OFF: 61 case SEC_VOLTAGE_OFF:
62 dprintk(MANTIS_ERROR, 1, "Frontend (dummy) POWERDOWN"); 62 dprintk(MANTIS_ERROR, 1, "Frontend (dummy) POWERDOWN");
@@ -82,7 +82,7 @@ static int vp1034_frontend_init(struct mantis_pci *mantis, struct dvb_frontend *
82 msleep(250); 82 msleep(250);
83 83
84 dprintk(MANTIS_ERROR, 1, "Probing for MB86A16 (DVB-S/DSS)"); 84 dprintk(MANTIS_ERROR, 1, "Probing for MB86A16 (DVB-S/DSS)");
85 fe = mb86a16_attach(&vp1034_mb86a16_config, adapter); 85 fe = dvb_attach(mb86a16_attach, &vp1034_mb86a16_config, adapter);
86 if (fe) { 86 if (fe) {
87 dprintk(MANTIS_ERROR, 1, 87 dprintk(MANTIS_ERROR, 1,
88 "found MB86A16 DVB-S/DSS frontend @0x%02x", 88 "found MB86A16 DVB-S/DSS frontend @0x%02x",
diff --git a/drivers/media/dvb/mantis/mantis_vp1041.c b/drivers/media/dvb/mantis/mantis_vp1041.c
index d1aa2bc0c155..38a436ca2fdf 100644
--- a/drivers/media/dvb/mantis/mantis_vp1041.c
+++ b/drivers/media/dvb/mantis/mantis_vp1041.c
@@ -316,14 +316,14 @@ static int vp1041_frontend_init(struct mantis_pci *mantis, struct dvb_frontend *
316 if (err == 0) { 316 if (err == 0) {
317 mantis_frontend_soft_reset(mantis); 317 mantis_frontend_soft_reset(mantis);
318 msleep(250); 318 msleep(250);
319 mantis->fe = stb0899_attach(&vp1041_stb0899_config, adapter); 319 mantis->fe = dvb_attach(stb0899_attach, &vp1041_stb0899_config, adapter);
320 if (mantis->fe) { 320 if (mantis->fe) {
321 dprintk(MANTIS_ERROR, 1, 321 dprintk(MANTIS_ERROR, 1,
322 "found STB0899 DVB-S/DVB-S2 frontend @0x%02x", 322 "found STB0899 DVB-S/DVB-S2 frontend @0x%02x",
323 vp1041_stb0899_config.demod_address); 323 vp1041_stb0899_config.demod_address);
324 324
325 if (stb6100_attach(mantis->fe, &vp1041_stb6100_config, adapter)) { 325 if (dvb_attach(stb6100_attach, mantis->fe, &vp1041_stb6100_config, adapter)) {
326 if (!lnbp21_attach(mantis->fe, adapter, 0, 0)) 326 if (!dvb_attach(lnbp21_attach, mantis->fe, adapter, 0, 0))
327 dprintk(MANTIS_ERROR, 1, "No LNBP21 found!"); 327 dprintk(MANTIS_ERROR, 1, "No LNBP21 found!");
328 } 328 }
329 } else { 329 } else {
diff --git a/drivers/media/dvb/mantis/mantis_vp2033.c b/drivers/media/dvb/mantis/mantis_vp2033.c
index 10ce81790a8c..06da0ddf05a7 100644
--- a/drivers/media/dvb/mantis/mantis_vp2033.c
+++ b/drivers/media/dvb/mantis/mantis_vp2033.c
@@ -132,7 +132,7 @@ static int vp2033_frontend_init(struct mantis_pci *mantis, struct dvb_frontend *
132 msleep(250); 132 msleep(250);
133 133
134 dprintk(MANTIS_ERROR, 1, "Probing for CU1216 (DVB-C)"); 134 dprintk(MANTIS_ERROR, 1, "Probing for CU1216 (DVB-C)");
135 fe = tda10021_attach(&vp2033_tda1002x_cu1216_config, 135 fe = dvb_attach(tda10021_attach, &vp2033_tda1002x_cu1216_config,
136 adapter, 136 adapter,
137 read_pwm(mantis)); 137 read_pwm(mantis));
138 138
@@ -141,7 +141,7 @@ static int vp2033_frontend_init(struct mantis_pci *mantis, struct dvb_frontend *
141 "found Philips CU1216 DVB-C frontend (TDA10021) @ 0x%02x", 141 "found Philips CU1216 DVB-C frontend (TDA10021) @ 0x%02x",
142 vp2033_tda1002x_cu1216_config.demod_address); 142 vp2033_tda1002x_cu1216_config.demod_address);
143 } else { 143 } else {
144 fe = tda10023_attach(&vp2033_tda10023_cu1216_config, 144 fe = dvb_attach(tda10023_attach, &vp2033_tda10023_cu1216_config,
145 adapter, 145 adapter,
146 read_pwm(mantis)); 146 read_pwm(mantis));
147 147
diff --git a/drivers/media/dvb/mantis/mantis_vp2040.c b/drivers/media/dvb/mantis/mantis_vp2040.c
index a7ca233e800b..f72b137b7652 100644
--- a/drivers/media/dvb/mantis/mantis_vp2040.c
+++ b/drivers/media/dvb/mantis/mantis_vp2040.c
@@ -132,7 +132,7 @@ static int vp2040_frontend_init(struct mantis_pci *mantis, struct dvb_frontend *
132 msleep(250); 132 msleep(250);
133 133
134 dprintk(MANTIS_ERROR, 1, "Probing for CU1216 (DVB-C)"); 134 dprintk(MANTIS_ERROR, 1, "Probing for CU1216 (DVB-C)");
135 fe = tda10021_attach(&vp2040_tda1002x_cu1216_config, 135 fe = dvb_attach(tda10021_attach, &vp2040_tda1002x_cu1216_config,
136 adapter, 136 adapter,
137 read_pwm(mantis)); 137 read_pwm(mantis));
138 138
@@ -141,7 +141,7 @@ static int vp2040_frontend_init(struct mantis_pci *mantis, struct dvb_frontend *
141 "found Philips CU1216 DVB-C frontend (TDA10021) @ 0x%02x", 141 "found Philips CU1216 DVB-C frontend (TDA10021) @ 0x%02x",
142 vp2040_tda1002x_cu1216_config.demod_address); 142 vp2040_tda1002x_cu1216_config.demod_address);
143 } else { 143 } else {
144 fe = tda10023_attach(&vp2040_tda10023_cu1216_config, 144 fe = dvb_attach(tda10023_attach, &vp2040_tda10023_cu1216_config,
145 adapter, 145 adapter,
146 read_pwm(mantis)); 146 read_pwm(mantis));
147 147
diff --git a/drivers/media/dvb/mantis/mantis_vp3030.c b/drivers/media/dvb/mantis/mantis_vp3030.c
index 1f4334214953..c09308cd3ac6 100644
--- a/drivers/media/dvb/mantis/mantis_vp3030.c
+++ b/drivers/media/dvb/mantis/mantis_vp3030.c
@@ -59,21 +59,21 @@ static int vp3030_frontend_init(struct mantis_pci *mantis, struct dvb_frontend *
59 struct mantis_hwconfig *config = mantis->hwconfig; 59 struct mantis_hwconfig *config = mantis->hwconfig;
60 int err = 0; 60 int err = 0;
61 61
62 gpio_set_bits(mantis, config->reset, 0); 62 mantis_gpio_set_bits(mantis, config->reset, 0);
63 msleep(100); 63 msleep(100);
64 err = mantis_frontend_power(mantis, POWER_ON); 64 err = mantis_frontend_power(mantis, POWER_ON);
65 msleep(100); 65 msleep(100);
66 gpio_set_bits(mantis, config->reset, 1); 66 mantis_gpio_set_bits(mantis, config->reset, 1);
67 67
68 if (err == 0) { 68 if (err == 0) {
69 msleep(250); 69 msleep(250);
70 dprintk(MANTIS_ERROR, 1, "Probing for 10353 (DVB-T)"); 70 dprintk(MANTIS_ERROR, 1, "Probing for 10353 (DVB-T)");
71 fe = zl10353_attach(&mantis_vp3030_config, adapter); 71 fe = dvb_attach(zl10353_attach, &mantis_vp3030_config, adapter);
72 72
73 if (!fe) 73 if (!fe)
74 return -1; 74 return -1;
75 75
76 tda665x_attach(fe, &env57h12d5_config, adapter); 76 dvb_attach(tda665x_attach, fe, &env57h12d5_config, adapter);
77 } else { 77 } else {
78 dprintk(MANTIS_ERROR, 1, "Frontend on <%s> POWER ON failed! <%d>", 78 dprintk(MANTIS_ERROR, 1, "Frontend on <%s> POWER ON failed! <%d>",
79 adapter->name, 79 adapter->name,
diff --git a/drivers/media/dvb/ngene/ngene-core.c b/drivers/media/dvb/ngene/ngene-core.c
index 3a7ef71087be..dc073bdc623a 100644
--- a/drivers/media/dvb/ngene/ngene-core.c
+++ b/drivers/media/dvb/ngene/ngene-core.c
@@ -1304,7 +1304,6 @@ static void ngene_stop(struct ngene *dev)
1304static int ngene_start(struct ngene *dev) 1304static int ngene_start(struct ngene *dev)
1305{ 1305{
1306 int stat; 1306 int stat;
1307 unsigned long flags;
1308 int i; 1307 int i;
1309 1308
1310 pci_set_master(dev->pci_dev); 1309 pci_set_master(dev->pci_dev);
@@ -1337,6 +1336,8 @@ static int ngene_start(struct ngene *dev)
1337#ifdef CONFIG_PCI_MSI 1336#ifdef CONFIG_PCI_MSI
1338 /* enable MSI if kernel and card support it */ 1337 /* enable MSI if kernel and card support it */
1339 if (pci_msi_enabled() && dev->card_info->msi_supported) { 1338 if (pci_msi_enabled() && dev->card_info->msi_supported) {
1339 unsigned long flags;
1340
1340 ngwritel(0, NGENE_INT_ENABLE); 1341 ngwritel(0, NGENE_INT_ENABLE);
1341 free_irq(dev->pci_dev->irq, dev); 1342 free_irq(dev->pci_dev->irq, dev);
1342 stat = pci_enable_msi(dev->pci_dev); 1343 stat = pci_enable_msi(dev->pci_dev);
@@ -1515,7 +1516,7 @@ static int init_channels(struct ngene *dev)
1515 1516
1516void __devexit ngene_remove(struct pci_dev *pdev) 1517void __devexit ngene_remove(struct pci_dev *pdev)
1517{ 1518{
1518 struct ngene *dev = (struct ngene *)pci_get_drvdata(pdev); 1519 struct ngene *dev = pci_get_drvdata(pdev);
1519 int i; 1520 int i;
1520 1521
1521 tasklet_kill(&dev->event_tasklet); 1522 tasklet_kill(&dev->event_tasklet);
@@ -1536,12 +1537,11 @@ int __devinit ngene_probe(struct pci_dev *pci_dev,
1536 if (pci_enable_device(pci_dev) < 0) 1537 if (pci_enable_device(pci_dev) < 0)
1537 return -ENODEV; 1538 return -ENODEV;
1538 1539
1539 dev = vmalloc(sizeof(struct ngene)); 1540 dev = vzalloc(sizeof(struct ngene));
1540 if (dev == NULL) { 1541 if (dev == NULL) {
1541 stat = -ENOMEM; 1542 stat = -ENOMEM;
1542 goto fail0; 1543 goto fail0;
1543 } 1544 }
1544 memset(dev, 0, sizeof(struct ngene));
1545 1545
1546 dev->pci_dev = pci_dev; 1546 dev->pci_dev = pci_dev;
1547 dev->card_info = (struct ngene_info *)id->driver_data; 1547 dev->card_info = (struct ngene_info *)id->driver_data;
diff --git a/drivers/media/dvb/siano/Kconfig b/drivers/media/dvb/siano/Kconfig
index e520bceee0af..bc6456eb2c4f 100644
--- a/drivers/media/dvb/siano/Kconfig
+++ b/drivers/media/dvb/siano/Kconfig
@@ -4,7 +4,7 @@
4 4
5config SMS_SIANO_MDTV 5config SMS_SIANO_MDTV
6 tristate "Siano SMS1xxx based MDTV receiver" 6 tristate "Siano SMS1xxx based MDTV receiver"
7 depends on DVB_CORE && IR_CORE && HAS_DMA 7 depends on DVB_CORE && RC_CORE && HAS_DMA
8 ---help--- 8 ---help---
9 Choose Y or M here if you have MDTV receiver with a Siano chipset. 9 Choose Y or M here if you have MDTV receiver with a Siano chipset.
10 10
diff --git a/drivers/media/dvb/siano/smscoreapi.c b/drivers/media/dvb/siano/smscoreapi.c
index 135e45bd00c7..78765ed28063 100644
--- a/drivers/media/dvb/siano/smscoreapi.c
+++ b/drivers/media/dvb/siano/smscoreapi.c
@@ -438,7 +438,7 @@ static int smscore_init_ir(struct smscore_device_t *coredev)
438 int rc; 438 int rc;
439 void *buffer; 439 void *buffer;
440 440
441 coredev->ir.input_dev = NULL; 441 coredev->ir.dev = NULL;
442 ir_io = sms_get_board(smscore_get_board_id(coredev))->board_cfg.ir; 442 ir_io = sms_get_board(smscore_get_board_id(coredev))->board_cfg.ir;
443 if (ir_io) {/* only if IR port exist we use IR sub-module */ 443 if (ir_io) {/* only if IR port exist we use IR sub-module */
444 sms_info("IR loading"); 444 sms_info("IR loading");
diff --git a/drivers/media/dvb/siano/smsir.c b/drivers/media/dvb/siano/smsir.c
index a27c44a8af5a..37bc5c4b8ad8 100644
--- a/drivers/media/dvb/siano/smsir.c
+++ b/drivers/media/dvb/siano/smsir.c
@@ -45,25 +45,24 @@ void sms_ir_event(struct smscore_device_t *coredev, const char *buf, int len)
45 ev.duration = abs(samples[i]) * 1000; /* Convert to ns */ 45 ev.duration = abs(samples[i]) * 1000; /* Convert to ns */
46 ev.pulse = (samples[i] > 0) ? false : true; 46 ev.pulse = (samples[i] > 0) ? false : true;
47 47
48 ir_raw_event_store(coredev->ir.input_dev, &ev); 48 ir_raw_event_store(coredev->ir.dev, &ev);
49 } 49 }
50 ir_raw_event_handle(coredev->ir.input_dev); 50 ir_raw_event_handle(coredev->ir.dev);
51} 51}
52 52
53int sms_ir_init(struct smscore_device_t *coredev) 53int sms_ir_init(struct smscore_device_t *coredev)
54{ 54{
55 struct input_dev *input_dev; 55 int err;
56 int board_id = smscore_get_board_id(coredev); 56 int board_id = smscore_get_board_id(coredev);
57 struct rc_dev *dev;
57 58
58 sms_log("Allocating input device"); 59 sms_log("Allocating rc device");
59 input_dev = input_allocate_device(); 60 dev = rc_allocate_device();
60 if (!input_dev) { 61 if (!dev) {
61 sms_err("Not enough memory"); 62 sms_err("Not enough memory");
62 return -ENOMEM; 63 return -ENOMEM;
63 } 64 }
64 65
65 coredev->ir.input_dev = input_dev;
66
67 coredev->ir.controller = 0; /* Todo: vega/nova SPI number */ 66 coredev->ir.controller = 0; /* Todo: vega/nova SPI number */
68 coredev->ir.timeout = IR_DEFAULT_TIMEOUT; 67 coredev->ir.timeout = IR_DEFAULT_TIMEOUT;
69 sms_log("IR port %d, timeout %d ms", 68 sms_log("IR port %d, timeout %d ms",
@@ -75,38 +74,41 @@ int sms_ir_init(struct smscore_device_t *coredev)
75 strlcpy(coredev->ir.phys, coredev->devpath, sizeof(coredev->ir.phys)); 74 strlcpy(coredev->ir.phys, coredev->devpath, sizeof(coredev->ir.phys));
76 strlcat(coredev->ir.phys, "/ir0", sizeof(coredev->ir.phys)); 75 strlcat(coredev->ir.phys, "/ir0", sizeof(coredev->ir.phys));
77 76
78 input_dev->name = coredev->ir.name; 77 dev->input_name = coredev->ir.name;
79 input_dev->phys = coredev->ir.phys; 78 dev->input_phys = coredev->ir.phys;
80 input_dev->dev.parent = coredev->device; 79 dev->dev.parent = coredev->device;
81 80
82#if 0 81#if 0
83 /* TODO: properly initialize the parameters bellow */ 82 /* TODO: properly initialize the parameters bellow */
84 input_dev->id.bustype = BUS_USB; 83 dev->input_id.bustype = BUS_USB;
85 input_dev->id.version = 1; 84 dev->input_id.version = 1;
86 input_dev->id.vendor = le16_to_cpu(dev->udev->descriptor.idVendor); 85 dev->input_id.vendor = le16_to_cpu(dev->udev->descriptor.idVendor);
87 input_dev->id.product = le16_to_cpu(dev->udev->descriptor.idProduct); 86 dev->input_id.product = le16_to_cpu(dev->udev->descriptor.idProduct);
88#endif 87#endif
89 88
90 coredev->ir.props.priv = coredev; 89 dev->priv = coredev;
91 coredev->ir.props.driver_type = RC_DRIVER_IR_RAW; 90 dev->driver_type = RC_DRIVER_IR_RAW;
92 coredev->ir.props.allowed_protos = IR_TYPE_ALL; 91 dev->allowed_protos = RC_TYPE_ALL;
92 dev->map_name = sms_get_board(board_id)->rc_codes;
93 dev->driver_name = MODULE_NAME;
93 94
94 sms_log("Input device (IR) %s is set for key events", input_dev->name); 95 sms_log("Input device (IR) %s is set for key events", dev->input_name);
95 96
96 if (ir_input_register(input_dev, sms_get_board(board_id)->rc_codes, 97 err = rc_register_device(dev);
97 &coredev->ir.props, MODULE_NAME)) { 98 if (err < 0) {
98 sms_err("Failed to register device"); 99 sms_err("Failed to register device");
99 input_free_device(input_dev); 100 rc_free_device(dev);
100 return -EACCES; 101 return err;
101 } 102 }
102 103
104 coredev->ir.dev = dev;
103 return 0; 105 return 0;
104} 106}
105 107
106void sms_ir_exit(struct smscore_device_t *coredev) 108void sms_ir_exit(struct smscore_device_t *coredev)
107{ 109{
108 if (coredev->ir.input_dev) 110 if (coredev->ir.dev)
109 ir_input_unregister(coredev->ir.input_dev); 111 rc_unregister_device(coredev->ir.dev);
110 112
111 sms_log(""); 113 sms_log("");
112} 114}
diff --git a/drivers/media/dvb/siano/smsir.h b/drivers/media/dvb/siano/smsir.h
index 926e247523bd..ae92b3a8587e 100644
--- a/drivers/media/dvb/siano/smsir.h
+++ b/drivers/media/dvb/siano/smsir.h
@@ -28,20 +28,19 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
28#define __SMS_IR_H__ 28#define __SMS_IR_H__
29 29
30#include <linux/input.h> 30#include <linux/input.h>
31#include <media/ir-core.h> 31#include <media/rc-core.h>
32 32
33#define IR_DEFAULT_TIMEOUT 100 33#define IR_DEFAULT_TIMEOUT 100
34 34
35struct smscore_device_t; 35struct smscore_device_t;
36 36
37struct ir_t { 37struct ir_t {
38 struct input_dev *input_dev; 38 struct rc_dev *dev;
39 char name[40]; 39 char name[40];
40 char phys[32]; 40 char phys[32];
41 41
42 char *rc_codes; 42 char *rc_codes;
43 u64 protocol; 43 u64 protocol;
44 struct ir_dev_props props;
45 44
46 u32 timeout; 45 u32 timeout;
47 u32 controller; 46 u32 controller;
diff --git a/drivers/media/dvb/siano/smsusb.c b/drivers/media/dvb/siano/smsusb.c
index 50d4338610e0..0b8da57cf4c3 100644
--- a/drivers/media/dvb/siano/smsusb.c
+++ b/drivers/media/dvb/siano/smsusb.c
@@ -288,8 +288,7 @@ static int smsusb1_setmode(void *context, int mode)
288 288
289static void smsusb_term_device(struct usb_interface *intf) 289static void smsusb_term_device(struct usb_interface *intf)
290{ 290{
291 struct smsusb_device_t *dev = 291 struct smsusb_device_t *dev = usb_get_intfdata(intf);
292 (struct smsusb_device_t *) usb_get_intfdata(intf);
293 292
294 if (dev) { 293 if (dev) {
295 smsusb_stop_streaming(dev); 294 smsusb_stop_streaming(dev);
@@ -445,8 +444,7 @@ static void smsusb_disconnect(struct usb_interface *intf)
445 444
446static int smsusb_suspend(struct usb_interface *intf, pm_message_t msg) 445static int smsusb_suspend(struct usb_interface *intf, pm_message_t msg)
447{ 446{
448 struct smsusb_device_t *dev = 447 struct smsusb_device_t *dev = usb_get_intfdata(intf);
449 (struct smsusb_device_t *)usb_get_intfdata(intf);
450 printk(KERN_INFO "%s: Entering status %d.\n", __func__, msg.event); 448 printk(KERN_INFO "%s: Entering status %d.\n", __func__, msg.event);
451 smsusb_stop_streaming(dev); 449 smsusb_stop_streaming(dev);
452 return 0; 450 return 0;
@@ -455,8 +453,7 @@ static int smsusb_suspend(struct usb_interface *intf, pm_message_t msg)
455static int smsusb_resume(struct usb_interface *intf) 453static int smsusb_resume(struct usb_interface *intf)
456{ 454{
457 int rc, i; 455 int rc, i;
458 struct smsusb_device_t *dev = 456 struct smsusb_device_t *dev = usb_get_intfdata(intf);
459 (struct smsusb_device_t *)usb_get_intfdata(intf);
460 struct usb_device *udev = interface_to_usbdev(intf); 457 struct usb_device *udev = interface_to_usbdev(intf);
461 458
462 printk(KERN_INFO "%s: Entering.\n", __func__); 459 printk(KERN_INFO "%s: Entering.\n", __func__);
diff --git a/drivers/media/dvb/ttpci/Kconfig b/drivers/media/dvb/ttpci/Kconfig
index debea8d1d31c..44afab2fdc2d 100644
--- a/drivers/media/dvb/ttpci/Kconfig
+++ b/drivers/media/dvb/ttpci/Kconfig
@@ -89,7 +89,6 @@ config DVB_BUDGET
89config DVB_BUDGET_CI 89config DVB_BUDGET_CI
90 tristate "Budget cards with onboard CI connector" 90 tristate "Budget cards with onboard CI connector"
91 depends on DVB_BUDGET_CORE && I2C 91 depends on DVB_BUDGET_CORE && I2C
92 depends on INPUT # due to IR
93 select DVB_STV0297 if !DVB_FE_CUSTOMISE 92 select DVB_STV0297 if !DVB_FE_CUSTOMISE
94 select DVB_STV0299 if !DVB_FE_CUSTOMISE 93 select DVB_STV0299 if !DVB_FE_CUSTOMISE
95 select DVB_TDA1004X if !DVB_FE_CUSTOMISE 94 select DVB_TDA1004X if !DVB_FE_CUSTOMISE
@@ -98,7 +97,7 @@ config DVB_BUDGET_CI
98 select DVB_LNBP21 if !DVB_FE_CUSTOMISE 97 select DVB_LNBP21 if !DVB_FE_CUSTOMISE
99 select DVB_TDA10023 if !DVB_FE_CUSTOMISE 98 select DVB_TDA10023 if !DVB_FE_CUSTOMISE
100 select MEDIA_TUNER_TDA827X if !MEDIA_TUNER_CUSTOMISE 99 select MEDIA_TUNER_TDA827X if !MEDIA_TUNER_CUSTOMISE
101 depends on VIDEO_IR 100 depends on RC_CORE
102 help 101 help
103 Support for simple SAA7146 based DVB cards 102 Support for simple SAA7146 based DVB cards
104 (so called Budget- or Nova-PCI cards) without onboard 103 (so called Budget- or Nova-PCI cards) without onboard
diff --git a/drivers/media/dvb/ttpci/av7110_v4l.c b/drivers/media/dvb/ttpci/av7110_v4l.c
index ac20c5bbfa43..cdd31cae46c4 100644
--- a/drivers/media/dvb/ttpci/av7110_v4l.c
+++ b/drivers/media/dvb/ttpci/av7110_v4l.c
@@ -100,6 +100,7 @@ static struct v4l2_input inputs[4] = {
100 .tuner = 0, /* ignored */ 100 .tuner = 0, /* ignored */
101 .std = V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 101 .std = V4L2_STD_PAL_BG|V4L2_STD_NTSC_M,
102 .status = 0, 102 .status = 0,
103 .capabilities = V4L2_IN_CAP_STD,
103 }, { 104 }, {
104 .index = 1, 105 .index = 1,
105 .name = "Television", 106 .name = "Television",
@@ -108,6 +109,7 @@ static struct v4l2_input inputs[4] = {
108 .tuner = 0, 109 .tuner = 0,
109 .std = V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 110 .std = V4L2_STD_PAL_BG|V4L2_STD_NTSC_M,
110 .status = 0, 111 .status = 0,
112 .capabilities = V4L2_IN_CAP_STD,
111 }, { 113 }, {
112 .index = 2, 114 .index = 2,
113 .name = "Video", 115 .name = "Video",
@@ -116,6 +118,7 @@ static struct v4l2_input inputs[4] = {
116 .tuner = 0, 118 .tuner = 0,
117 .std = V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 119 .std = V4L2_STD_PAL_BG|V4L2_STD_NTSC_M,
118 .status = 0, 120 .status = 0,
121 .capabilities = V4L2_IN_CAP_STD,
119 }, { 122 }, {
120 .index = 3, 123 .index = 3,
121 .name = "Y/C", 124 .name = "Y/C",
@@ -124,6 +127,7 @@ static struct v4l2_input inputs[4] = {
124 .tuner = 0, 127 .tuner = 0,
125 .std = V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 128 .std = V4L2_STD_PAL_BG|V4L2_STD_NTSC_M,
126 .status = 0, 129 .status = 0,
130 .capabilities = V4L2_IN_CAP_STD,
127 } 131 }
128}; 132};
129 133
diff --git a/drivers/media/dvb/ttpci/budget-av.c b/drivers/media/dvb/ttpci/budget-av.c
index 97afc01f60d0..e957d7690bcc 100644
--- a/drivers/media/dvb/ttpci/budget-av.c
+++ b/drivers/media/dvb/ttpci/budget-av.c
@@ -1406,8 +1406,10 @@ static int budget_av_detach(struct saa7146_dev *dev)
1406 1406
1407#define KNC1_INPUTS 2 1407#define KNC1_INPUTS 2
1408static struct v4l2_input knc1_inputs[KNC1_INPUTS] = { 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}, 1409 { 0, "Composite", V4L2_INPUT_TYPE_TUNER, 1, 0,
1410 {1, "S-Video", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG | V4L2_STD_NTSC_M, 0}, 1410 V4L2_STD_PAL_BG | V4L2_STD_NTSC_M, 0, V4L2_IN_CAP_STD },
1411 { 1, "S-Video", V4L2_INPUT_TYPE_CAMERA, 2, 0,
1412 V4L2_STD_PAL_BG | V4L2_STD_NTSC_M, 0, V4L2_IN_CAP_STD },
1411}; 1413};
1412 1414
1413static int vidioc_enum_input(struct file *file, void *fh, struct v4l2_input *i) 1415static int vidioc_enum_input(struct file *file, void *fh, struct v4l2_input *i)
diff --git a/drivers/media/dvb/ttpci/budget-ci.c b/drivers/media/dvb/ttpci/budget-ci.c
index a9c2c326df4b..b82756db5bd1 100644
--- a/drivers/media/dvb/ttpci/budget-ci.c
+++ b/drivers/media/dvb/ttpci/budget-ci.c
@@ -33,9 +33,8 @@
33#include <linux/errno.h> 33#include <linux/errno.h>
34#include <linux/slab.h> 34#include <linux/slab.h>
35#include <linux/interrupt.h> 35#include <linux/interrupt.h>
36#include <linux/input.h>
37#include <linux/spinlock.h> 36#include <linux/spinlock.h>
38#include <media/ir-core.h> 37#include <media/rc-core.h>
39 38
40#include "budget.h" 39#include "budget.h"
41 40
@@ -96,7 +95,7 @@ MODULE_PARM_DESC(ir_debug, "enable debugging information for IR decoding");
96DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); 95DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
97 96
98struct budget_ci_ir { 97struct budget_ci_ir {
99 struct input_dev *dev; 98 struct rc_dev *dev;
100 struct tasklet_struct msp430_irq_tasklet; 99 struct tasklet_struct msp430_irq_tasklet;
101 char name[72]; /* 40 + 32 for (struct saa7146_dev).name */ 100 char name[72]; /* 40 + 32 for (struct saa7146_dev).name */
102 char phys[32]; 101 char phys[32];
@@ -118,7 +117,7 @@ struct budget_ci {
118static void msp430_ir_interrupt(unsigned long data) 117static void msp430_ir_interrupt(unsigned long data)
119{ 118{
120 struct budget_ci *budget_ci = (struct budget_ci *) data; 119 struct budget_ci *budget_ci = (struct budget_ci *) data;
121 struct input_dev *dev = budget_ci->ir.dev; 120 struct rc_dev *dev = budget_ci->ir.dev;
122 u32 command = ttpci_budget_debiread(&budget_ci->budget, DEBINOSWAP, DEBIADDR_IR, 2, 1, 0) >> 8; 121 u32 command = ttpci_budget_debiread(&budget_ci->budget, DEBINOSWAP, DEBIADDR_IR, 2, 1, 0) >> 8;
123 122
124 /* 123 /*
@@ -160,19 +159,17 @@ static void msp430_ir_interrupt(unsigned long data)
160 budget_ci->ir.rc5_device != (command & 0x1f)) 159 budget_ci->ir.rc5_device != (command & 0x1f))
161 return; 160 return;
162 161
163 ir_keydown(dev, budget_ci->ir.ir_key, (command & 0x20) ? 1 : 0); 162 rc_keydown(dev, budget_ci->ir.ir_key, (command & 0x20) ? 1 : 0);
164} 163}
165 164
166static int msp430_ir_init(struct budget_ci *budget_ci) 165static int msp430_ir_init(struct budget_ci *budget_ci)
167{ 166{
168 struct saa7146_dev *saa = budget_ci->budget.dev; 167 struct saa7146_dev *saa = budget_ci->budget.dev;
169 struct input_dev *input_dev = budget_ci->ir.dev; 168 struct rc_dev *dev;
170 int error; 169 int error;
171 char *ir_codes = NULL;
172 170
173 171 dev = rc_allocate_device();
174 budget_ci->ir.dev = input_dev = input_allocate_device(); 172 if (!dev) {
175 if (!input_dev) {
176 printk(KERN_ERR "budget_ci: IR interface initialisation failed\n"); 173 printk(KERN_ERR "budget_ci: IR interface initialisation failed\n");
177 return -ENOMEM; 174 return -ENOMEM;
178 } 175 }
@@ -182,19 +179,20 @@ static int msp430_ir_init(struct budget_ci *budget_ci)
182 snprintf(budget_ci->ir.phys, sizeof(budget_ci->ir.phys), 179 snprintf(budget_ci->ir.phys, sizeof(budget_ci->ir.phys),
183 "pci-%s/ir0", pci_name(saa->pci)); 180 "pci-%s/ir0", pci_name(saa->pci));
184 181
185 input_dev->name = budget_ci->ir.name; 182 dev->driver_name = MODULE_NAME;
186 183 dev->input_name = budget_ci->ir.name;
187 input_dev->phys = budget_ci->ir.phys; 184 dev->input_phys = budget_ci->ir.phys;
188 input_dev->id.bustype = BUS_PCI; 185 dev->input_id.bustype = BUS_PCI;
189 input_dev->id.version = 1; 186 dev->input_id.version = 1;
187 dev->scanmask = 0xff;
190 if (saa->pci->subsystem_vendor) { 188 if (saa->pci->subsystem_vendor) {
191 input_dev->id.vendor = saa->pci->subsystem_vendor; 189 dev->input_id.vendor = saa->pci->subsystem_vendor;
192 input_dev->id.product = saa->pci->subsystem_device; 190 dev->input_id.product = saa->pci->subsystem_device;
193 } else { 191 } else {
194 input_dev->id.vendor = saa->pci->vendor; 192 dev->input_id.vendor = saa->pci->vendor;
195 input_dev->id.product = saa->pci->device; 193 dev->input_id.product = saa->pci->device;
196 } 194 }
197 input_dev->dev.parent = &saa->pci->dev; 195 dev->dev.parent = &saa->pci->dev;
198 196
199 if (rc5_device < 0) 197 if (rc5_device < 0)
200 budget_ci->ir.rc5_device = IR_DEVICE_ANY; 198 budget_ci->ir.rc5_device = IR_DEVICE_ANY;
@@ -208,7 +206,7 @@ static int msp430_ir_init(struct budget_ci *budget_ci)
208 case 0x1011: 206 case 0x1011:
209 case 0x1012: 207 case 0x1012:
210 /* The hauppauge keymap is a superset of these remotes */ 208 /* The hauppauge keymap is a superset of these remotes */
211 ir_codes = RC_MAP_HAUPPAUGE_NEW; 209 dev->map_name = RC_MAP_HAUPPAUGE_NEW;
212 210
213 if (rc5_device < 0) 211 if (rc5_device < 0)
214 budget_ci->ir.rc5_device = 0x1f; 212 budget_ci->ir.rc5_device = 0x1f;
@@ -218,23 +216,22 @@ static int msp430_ir_init(struct budget_ci *budget_ci)
218 case 0x1019: 216 case 0x1019:
219 case 0x101a: 217 case 0x101a:
220 /* for the Technotrend 1500 bundled remote */ 218 /* for the Technotrend 1500 bundled remote */
221 ir_codes = RC_MAP_TT_1500; 219 dev->map_name = RC_MAP_TT_1500;
222 break; 220 break;
223 default: 221 default:
224 /* unknown remote */ 222 /* unknown remote */
225 ir_codes = RC_MAP_BUDGET_CI_OLD; 223 dev->map_name = RC_MAP_BUDGET_CI_OLD;
226 break; 224 break;
227 } 225 }
228 226
229 error = ir_input_register(input_dev, ir_codes, NULL, MODULE_NAME); 227 error = rc_register_device(dev);
230 if (error) { 228 if (error) {
231 printk(KERN_ERR "budget_ci: could not init driver for IR device (code %d)\n", error); 229 printk(KERN_ERR "budget_ci: could not init driver for IR device (code %d)\n", error);
230 rc_free_device(dev);
232 return error; 231 return error;
233 } 232 }
234 233
235 /* note: these must be after input_register_device */ 234 budget_ci->ir.dev = dev;
236 input_dev->rep[REP_DELAY] = 400;
237 input_dev->rep[REP_PERIOD] = 250;
238 235
239 tasklet_init(&budget_ci->ir.msp430_irq_tasklet, msp430_ir_interrupt, 236 tasklet_init(&budget_ci->ir.msp430_irq_tasklet, msp430_ir_interrupt,
240 (unsigned long) budget_ci); 237 (unsigned long) budget_ci);
@@ -248,13 +245,12 @@ static int msp430_ir_init(struct budget_ci *budget_ci)
248static void msp430_ir_deinit(struct budget_ci *budget_ci) 245static void msp430_ir_deinit(struct budget_ci *budget_ci)
249{ 246{
250 struct saa7146_dev *saa = budget_ci->budget.dev; 247 struct saa7146_dev *saa = budget_ci->budget.dev;
251 struct input_dev *dev = budget_ci->ir.dev;
252 248
253 SAA7146_IER_DISABLE(saa, MASK_06); 249 SAA7146_IER_DISABLE(saa, MASK_06);
254 saa7146_setgpio(saa, 3, SAA7146_GPIO_INPUT); 250 saa7146_setgpio(saa, 3, SAA7146_GPIO_INPUT);
255 tasklet_kill(&budget_ci->ir.msp430_irq_tasklet); 251 tasklet_kill(&budget_ci->ir.msp430_irq_tasklet);
256 252
257 ir_input_unregister(dev); 253 rc_unregister_device(budget_ci->ir.dev);
258} 254}
259 255
260static int ciintf_read_attribute_mem(struct dvb_ca_en50221 *ca, int slot, int address) 256static int ciintf_read_attribute_mem(struct dvb_ca_en50221 *ca, int slot, int address)
diff --git a/drivers/media/radio/Kconfig b/drivers/media/radio/Kconfig
index 83567b898d09..3c5a4739ed70 100644
--- a/drivers/media/radio/Kconfig
+++ b/drivers/media/radio/Kconfig
@@ -452,4 +452,20 @@ config RADIO_TIMBERDALE
452 found behind the Timberdale FPGA on the Russellville board. 452 found behind the Timberdale FPGA on the Russellville board.
453 Enabling this driver will automatically select the DSP and tuner. 453 Enabling this driver will automatically select the DSP and tuner.
454 454
455config RADIO_WL1273
456 tristate "Texas Instruments WL1273 I2C FM Radio"
457 depends on I2C && VIDEO_V4L2
458 select MFD_WL1273_CORE
459 select FW_LOADER
460 ---help---
461 Choose Y here if you have this FM radio chip.
462
463 In order to control your radio card, you will need to use programs
464 that are compatible with the Video For Linux 2 API. Information on
465 this API and pointers to "v4l2" programs may be found at
466 <file:Documentation/video4linux/API.html>.
467
468 To compile this driver as a module, choose M here: the
469 module will be called radio-wl1273.
470
455endif # RADIO_ADAPTERS 471endif # RADIO_ADAPTERS
diff --git a/drivers/media/radio/Makefile b/drivers/media/radio/Makefile
index f615583b4837..d2970748a69f 100644
--- a/drivers/media/radio/Makefile
+++ b/drivers/media/radio/Makefile
@@ -26,5 +26,6 @@ obj-$(CONFIG_RADIO_TEA5764) += radio-tea5764.o
26obj-$(CONFIG_RADIO_SAA7706H) += saa7706h.o 26obj-$(CONFIG_RADIO_SAA7706H) += saa7706h.o
27obj-$(CONFIG_RADIO_TEF6862) += tef6862.o 27obj-$(CONFIG_RADIO_TEF6862) += tef6862.o
28obj-$(CONFIG_RADIO_TIMBERDALE) += radio-timb.o 28obj-$(CONFIG_RADIO_TIMBERDALE) += radio-timb.o
29obj-$(CONFIG_RADIO_WL1273) += radio-wl1273.o
29 30
30EXTRA_CFLAGS += -Isound 31EXTRA_CFLAGS += -Isound
diff --git a/drivers/media/radio/radio-aimslab.c b/drivers/media/radio/radio-aimslab.c
index 05e832f61c3e..6cc5d130fbc8 100644
--- a/drivers/media/radio/radio-aimslab.c
+++ b/drivers/media/radio/radio-aimslab.c
@@ -31,7 +31,6 @@
31#include <linux/module.h> /* Modules */ 31#include <linux/module.h> /* Modules */
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 */
35#include <linux/videodev2.h> /* kernel radio structs */ 34#include <linux/videodev2.h> /* kernel radio structs */
36#include <linux/version.h> /* for KERNEL_VERSION MACRO */ 35#include <linux/version.h> /* for KERNEL_VERSION MACRO */
37#include <linux/io.h> /* outb, outb_p */ 36#include <linux/io.h> /* outb, outb_p */
@@ -71,27 +70,17 @@ static struct rtrack rtrack_card;
71 70
72/* local things */ 71/* local things */
73 72
74static void sleep_delay(long n)
75{
76 /* Sleep nicely for 'n' uS */
77 int d = n / msecs_to_jiffies(1000);
78 if (!d)
79 udelay(n);
80 else
81 msleep(jiffies_to_msecs(d));
82}
83
84static void rt_decvol(struct rtrack *rt) 73static void rt_decvol(struct rtrack *rt)
85{ 74{
86 outb(0x58, rt->io); /* volume down + sigstr + on */ 75 outb(0x58, rt->io); /* volume down + sigstr + on */
87 sleep_delay(100000); 76 msleep(100);
88 outb(0xd8, rt->io); /* volume steady + sigstr + on */ 77 outb(0xd8, rt->io); /* volume steady + sigstr + on */
89} 78}
90 79
91static void rt_incvol(struct rtrack *rt) 80static void rt_incvol(struct rtrack *rt)
92{ 81{
93 outb(0x98, rt->io); /* volume up + sigstr + on */ 82 outb(0x98, rt->io); /* volume up + sigstr + on */
94 sleep_delay(100000); 83 msleep(100);
95 outb(0xd8, rt->io); /* volume steady + sigstr + on */ 84 outb(0xd8, rt->io); /* volume steady + sigstr + on */
96} 85}
97 86
@@ -120,7 +109,7 @@ static int rt_setvol(struct rtrack *rt, int vol)
120 109
121 if (vol == 0) { /* volume = 0 means mute the card */ 110 if (vol == 0) { /* volume = 0 means mute the card */
122 outb(0x48, rt->io); /* volume down but still "on" */ 111 outb(0x48, rt->io); /* volume down but still "on" */
123 sleep_delay(2000000); /* make sure it's totally down */ 112 msleep(2000); /* make sure it's totally down */
124 outb(0xd0, rt->io); /* volume steady, off */ 113 outb(0xd0, rt->io); /* volume steady, off */
125 rt->curvol = 0; /* track the volume state! */ 114 rt->curvol = 0; /* track the volume state! */
126 mutex_unlock(&rt->lock); 115 mutex_unlock(&rt->lock);
@@ -155,7 +144,7 @@ static void send_0_byte(struct rtrack *rt)
155 outb_p(128+64+16+8+ 1, rt->io); /* on + wr-enable + data low */ 144 outb_p(128+64+16+8+ 1, rt->io); /* on + wr-enable + data low */
156 outb_p(128+64+16+8+2+1, rt->io); /* clock */ 145 outb_p(128+64+16+8+2+1, rt->io); /* clock */
157 } 146 }
158 sleep_delay(1000); 147 msleep(1);
159} 148}
160 149
161static void send_1_byte(struct rtrack *rt) 150static void send_1_byte(struct rtrack *rt)
@@ -169,7 +158,7 @@ static void send_1_byte(struct rtrack *rt)
169 outb_p(128+64+16+8+4+2+1, rt->io); /* clock */ 158 outb_p(128+64+16+8+4+2+1, rt->io); /* clock */
170 } 159 }
171 160
172 sleep_delay(1000); 161 msleep(1);
173} 162}
174 163
175static int rt_setfreq(struct rtrack *rt, unsigned long freq) 164static int rt_setfreq(struct rtrack *rt, unsigned long freq)
@@ -420,7 +409,7 @@ static int __init rtrack_init(void)
420 409
421 /* this ensures that the volume is all the way down */ 410 /* this ensures that the volume is all the way down */
422 outb(0x48, rt->io); /* volume down but still "on" */ 411 outb(0x48, rt->io); /* volume down but still "on" */
423 sleep_delay(2000000); /* make sure it's totally down */ 412 msleep(2000); /* make sure it's totally down */
424 outb(0xc0, rt->io); /* steady volume, mute card */ 413 outb(0xc0, rt->io); /* steady volume, mute card */
425 414
426 if (video_register_device(&rt->vdev, VFL_TYPE_RADIO, radio_nr) < 0) { 415 if (video_register_device(&rt->vdev, VFL_TYPE_RADIO, radio_nr) < 0) {
diff --git a/drivers/media/radio/radio-wl1273.c b/drivers/media/radio/radio-wl1273.c
new file mode 100644
index 000000000000..dd6bd364efa0
--- /dev/null
+++ b/drivers/media/radio/radio-wl1273.c
@@ -0,0 +1,2330 @@
1/*
2 * Driver for the Texas Instruments WL1273 FM radio.
3 *
4 * Copyright (C) 2010 Nokia Corporation
5 * Author: Matti J. Aaltonen <matti.j.aaltonen@nokia.com>
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 * version 2 as 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#include <linux/delay.h>
22#include <linux/firmware.h>
23#include <linux/interrupt.h>
24#include <linux/mfd/wl1273-core.h>
25#include <linux/slab.h>
26#include <media/v4l2-common.h>
27#include <media/v4l2-ctrls.h>
28#include <media/v4l2-device.h>
29#include <media/v4l2-ioctl.h>
30
31#define DRIVER_DESC "Wl1273 FM Radio"
32
33#define WL1273_POWER_SET_OFF 0
34#define WL1273_POWER_SET_FM BIT(0)
35#define WL1273_POWER_SET_RDS BIT(1)
36#define WL1273_POWER_SET_RETENTION BIT(4)
37
38#define WL1273_PUPD_SET_OFF 0x00
39#define WL1273_PUPD_SET_ON 0x01
40#define WL1273_PUPD_SET_RETENTION 0x10
41
42#define WL1273_FREQ(x) (x * 10000 / 625)
43#define WL1273_INV_FREQ(x) (x * 625 / 10000)
44
45/*
46 * static int radio_nr - The number of the radio device
47 *
48 * The default is 0.
49 */
50static int radio_nr;
51module_param(radio_nr, int, 0);
52MODULE_PARM_DESC(radio_nr, "The number of the radio device. Default = 0");
53
54struct wl1273_device {
55 char *bus_type;
56
57 u8 forbidden;
58 unsigned int preemphasis;
59 unsigned int spacing;
60 unsigned int tx_power;
61 unsigned int rx_frequency;
62 unsigned int tx_frequency;
63 unsigned int rangelow;
64 unsigned int rangehigh;
65 unsigned int band;
66 bool stereo;
67
68 /* RDS */
69 unsigned int rds_on;
70 struct delayed_work work;
71
72 wait_queue_head_t read_queue;
73 struct mutex lock; /* for serializing fm radio operations */
74 struct completion busy;
75
76 unsigned char *buffer;
77 unsigned int buf_size;
78 unsigned int rd_index;
79 unsigned int wr_index;
80
81 /* Selected interrupts */
82 u16 irq_flags;
83 u16 irq_received;
84
85 struct v4l2_ctrl_handler ctrl_handler;
86 struct v4l2_device v4l2dev;
87 struct video_device videodev;
88 struct device *dev;
89 struct wl1273_core *core;
90 struct file *owner;
91 char *write_buf;
92 unsigned int rds_users;
93};
94
95#define WL1273_IRQ_MASK (WL1273_FR_EVENT | \
96 WL1273_POW_ENB_EVENT)
97
98/*
99 * static unsigned int rds_buf - the number of RDS buffer blocks used.
100 *
101 * The default number is 100.
102 */
103static unsigned int rds_buf = 100;
104module_param(rds_buf, uint, 0);
105MODULE_PARM_DESC(rds_buf, "Number of RDS buffer entries. Default = 100");
106
107static int wl1273_fm_read_reg(struct wl1273_core *core, u8 reg, u16 *value)
108{
109 struct i2c_client *client = core->client;
110 u8 b[2];
111 int r;
112
113 r = i2c_smbus_read_i2c_block_data(client, reg, sizeof(b), b);
114 if (r != 2) {
115 dev_err(&client->dev, "%s: Read: %d fails.\n", __func__, reg);
116 return -EREMOTEIO;
117 }
118
119 *value = (u16)b[0] << 8 | b[1];
120
121 return 0;
122}
123
124static int wl1273_fm_write_cmd(struct wl1273_core *core, u8 cmd, u16 param)
125{
126 struct i2c_client *client = core->client;
127 u8 buf[] = { (param >> 8) & 0xff, param & 0xff };
128 int r;
129
130 r = i2c_smbus_write_i2c_block_data(client, cmd, sizeof(buf), buf);
131 if (r) {
132 dev_err(&client->dev, "%s: Cmd: %d fails.\n", __func__, cmd);
133 return r;
134 }
135
136 return 0;
137}
138
139static int wl1273_fm_write_data(struct wl1273_core *core, u8 *data, u16 len)
140{
141 struct i2c_client *client = core->client;
142 struct i2c_msg msg;
143 int r;
144
145 msg.addr = client->addr;
146 msg.flags = 0;
147 msg.buf = data;
148 msg.len = len;
149
150 r = i2c_transfer(client->adapter, &msg, 1);
151 if (r != 1) {
152 dev_err(&client->dev, "%s: write error.\n", __func__);
153 return -EREMOTEIO;
154 }
155
156 return 0;
157}
158
159static int wl1273_fm_write_fw(struct wl1273_core *core,
160 __u8 *fw, int len)
161{
162 struct i2c_client *client = core->client;
163 struct i2c_msg msg;
164 int i, r = 0;
165
166 msg.addr = client->addr;
167 msg.flags = 0;
168
169 for (i = 0; i <= len; i++) {
170 msg.len = fw[0];
171 msg.buf = fw + 1;
172
173 fw += msg.len + 1;
174 dev_dbg(&client->dev, "%s:len[%d]: %d\n", __func__, i, msg.len);
175
176 r = i2c_transfer(client->adapter, &msg, 1);
177 if (r < 0 && i < len + 1)
178 break;
179 }
180
181 dev_dbg(&client->dev, "%s: i: %d\n", __func__, i);
182 dev_dbg(&client->dev, "%s: len + 1: %d\n", __func__, len + 1);
183
184 /* Last transfer always fails. */
185 if (i == len || r == 1)
186 r = 0;
187
188 return r;
189}
190
191/**
192 * wl1273_fm_set_audio() - Set audio mode.
193 * @core: A pointer to the device struct.
194 * @new_mode: The new audio mode.
195 *
196 * Audio modes are WL1273_AUDIO_DIGITAL and WL1273_AUDIO_ANALOG.
197 */
198static int wl1273_fm_set_audio(struct wl1273_core *core, unsigned int new_mode)
199{
200 int r = 0;
201
202 if (core->mode == WL1273_MODE_OFF ||
203 core->mode == WL1273_MODE_SUSPENDED)
204 return -EPERM;
205
206 if (core->mode == WL1273_MODE_RX && new_mode == WL1273_AUDIO_DIGITAL) {
207 r = wl1273_fm_write_cmd(core, WL1273_PCM_MODE_SET,
208 WL1273_PCM_DEF_MODE);
209 if (r)
210 goto out;
211
212 r = wl1273_fm_write_cmd(core, WL1273_I2S_MODE_CONFIG_SET,
213 core->i2s_mode);
214 if (r)
215 goto out;
216
217 r = wl1273_fm_write_cmd(core, WL1273_AUDIO_ENABLE,
218 WL1273_AUDIO_ENABLE_I2S);
219 if (r)
220 goto out;
221
222 } else if (core->mode == WL1273_MODE_RX &&
223 new_mode == WL1273_AUDIO_ANALOG) {
224 r = wl1273_fm_write_cmd(core, WL1273_AUDIO_ENABLE,
225 WL1273_AUDIO_ENABLE_ANALOG);
226 if (r)
227 goto out;
228
229 } else if (core->mode == WL1273_MODE_TX &&
230 new_mode == WL1273_AUDIO_DIGITAL) {
231 r = wl1273_fm_write_cmd(core, WL1273_I2S_MODE_CONFIG_SET,
232 core->i2s_mode);
233 if (r)
234 goto out;
235
236 r = wl1273_fm_write_cmd(core, WL1273_AUDIO_IO_SET,
237 WL1273_AUDIO_IO_SET_I2S);
238 if (r)
239 goto out;
240
241 } else if (core->mode == WL1273_MODE_TX &&
242 new_mode == WL1273_AUDIO_ANALOG) {
243 r = wl1273_fm_write_cmd(core, WL1273_AUDIO_IO_SET,
244 WL1273_AUDIO_IO_SET_ANALOG);
245 if (r)
246 goto out;
247 }
248
249 core->audio_mode = new_mode;
250out:
251 return r;
252}
253
254/**
255 * wl1273_fm_set_volume() - Set volume.
256 * @core: A pointer to the device struct.
257 * @volume: The new volume value.
258 */
259static int wl1273_fm_set_volume(struct wl1273_core *core, unsigned int volume)
260{
261 u16 val;
262 int r;
263
264 if (volume > WL1273_MAX_VOLUME)
265 return -EINVAL;
266
267 if (core->volume == volume)
268 return 0;
269
270 val = volume;
271 r = wl1273_fm_read_reg(core, WL1273_VOLUME_SET, &val);
272 if (r)
273 return r;
274
275 core->volume = volume;
276 return 0;
277}
278
279#define WL1273_FIFO_HAS_DATA(status) (1 << 5 & status)
280#define WL1273_RDS_CORRECTABLE_ERROR (1 << 3)
281#define WL1273_RDS_UNCORRECTABLE_ERROR (1 << 4)
282
283static int wl1273_fm_rds(struct wl1273_device *radio)
284{
285 struct wl1273_core *core = radio->core;
286 struct i2c_client *client = core->client;
287 u16 val;
288 u8 b0 = WL1273_RDS_DATA_GET, status;
289 struct v4l2_rds_data rds = { 0, 0, 0 };
290 struct i2c_msg msg[] = {
291 {
292 .addr = client->addr,
293 .flags = 0,
294 .buf = &b0,
295 .len = 1,
296 },
297 {
298 .addr = client->addr,
299 .flags = I2C_M_RD,
300 .buf = (u8 *) &rds,
301 .len = sizeof(rds),
302 }
303 };
304 int r;
305
306 if (core->mode != WL1273_MODE_RX)
307 return 0;
308
309 r = wl1273_fm_read_reg(core, WL1273_RDS_SYNC_GET, &val);
310 if (r)
311 return r;
312
313 if ((val & 0x01) == 0) {
314 /* RDS decoder not synchronized */
315 return -EAGAIN;
316 }
317
318 /* copy all four RDS blocks to internal buffer */
319 do {
320 r = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg));
321 if (r != ARRAY_SIZE(msg)) {
322 dev_err(radio->dev, WL1273_FM_DRIVER_NAME
323 ": %s: read_rds error r == %i)\n",
324 __func__, r);
325 }
326
327 status = rds.block;
328
329 if (!WL1273_FIFO_HAS_DATA(status))
330 break;
331
332 /* copy bits 0-2 (the block ID) to bits 3-5 */
333 rds.block = V4L2_RDS_BLOCK_MSK & status;
334 rds.block |= rds.block << 3;
335
336 /* copy the error bits to standard positions */
337 if (WL1273_RDS_UNCORRECTABLE_ERROR & status) {
338 rds.block |= V4L2_RDS_BLOCK_ERROR;
339 rds.block &= ~V4L2_RDS_BLOCK_CORRECTED;
340 } else if (WL1273_RDS_CORRECTABLE_ERROR & status) {
341 rds.block &= ~V4L2_RDS_BLOCK_ERROR;
342 rds.block |= V4L2_RDS_BLOCK_CORRECTED;
343 }
344
345 /* copy RDS block to internal buffer */
346 memcpy(&radio->buffer[radio->wr_index], &rds, RDS_BLOCK_SIZE);
347 radio->wr_index += 3;
348
349 /* wrap write pointer */
350 if (radio->wr_index >= radio->buf_size)
351 radio->wr_index = 0;
352
353 /* check for overflow & start over */
354 if (radio->wr_index == radio->rd_index) {
355 dev_dbg(radio->dev, "RDS OVERFLOW");
356
357 radio->rd_index = 0;
358 radio->wr_index = 0;
359 break;
360 }
361 } while (WL1273_FIFO_HAS_DATA(status));
362
363 /* wake up read queue */
364 if (radio->wr_index != radio->rd_index)
365 wake_up_interruptible(&radio->read_queue);
366
367 return 0;
368}
369
370static irqreturn_t wl1273_fm_irq_thread_handler(int irq, void *dev_id)
371{
372 struct wl1273_device *radio = dev_id;
373 struct wl1273_core *core = radio->core;
374 u16 flags;
375 int r;
376
377 r = wl1273_fm_read_reg(core, WL1273_FLAG_GET, &flags);
378 if (r)
379 goto out;
380
381 if (flags & WL1273_BL_EVENT) {
382 radio->irq_received = flags;
383 dev_dbg(radio->dev, "IRQ: BL\n");
384 }
385
386 if (flags & WL1273_RDS_EVENT) {
387 msleep(200);
388
389 wl1273_fm_rds(radio);
390 }
391
392 if (flags & WL1273_BBLK_EVENT)
393 dev_dbg(radio->dev, "IRQ: BBLK\n");
394
395 if (flags & WL1273_LSYNC_EVENT)
396 dev_dbg(radio->dev, "IRQ: LSYNC\n");
397
398 if (flags & WL1273_LEV_EVENT) {
399 u16 level;
400
401 r = wl1273_fm_read_reg(core, WL1273_RSSI_LVL_GET, &level);
402 if (r)
403 goto out;
404
405 if (level > 14)
406 dev_dbg(radio->dev, "IRQ: LEV: 0x%x04\n", level);
407 }
408
409 if (flags & WL1273_IFFR_EVENT)
410 dev_dbg(radio->dev, "IRQ: IFFR\n");
411
412 if (flags & WL1273_PI_EVENT)
413 dev_dbg(radio->dev, "IRQ: PI\n");
414
415 if (flags & WL1273_PD_EVENT)
416 dev_dbg(radio->dev, "IRQ: PD\n");
417
418 if (flags & WL1273_STIC_EVENT)
419 dev_dbg(radio->dev, "IRQ: STIC\n");
420
421 if (flags & WL1273_MAL_EVENT)
422 dev_dbg(radio->dev, "IRQ: MAL\n");
423
424 if (flags & WL1273_POW_ENB_EVENT) {
425 complete(&radio->busy);
426 dev_dbg(radio->dev, "NOT BUSY\n");
427 dev_dbg(radio->dev, "IRQ: POW_ENB\n");
428 }
429
430 if (flags & WL1273_SCAN_OVER_EVENT)
431 dev_dbg(radio->dev, "IRQ: SCAN_OVER\n");
432
433 if (flags & WL1273_ERROR_EVENT)
434 dev_dbg(radio->dev, "IRQ: ERROR\n");
435
436 if (flags & WL1273_FR_EVENT) {
437 u16 freq;
438
439 dev_dbg(radio->dev, "IRQ: FR:\n");
440
441 if (core->mode == WL1273_MODE_RX) {
442 r = wl1273_fm_write_cmd(core, WL1273_TUNER_MODE_SET,
443 TUNER_MODE_STOP_SEARCH);
444 if (r) {
445 dev_err(radio->dev,
446 "%s: TUNER_MODE_SET fails: %d\n",
447 __func__, r);
448 goto out;
449 }
450
451 r = wl1273_fm_read_reg(core, WL1273_FREQ_SET, &freq);
452 if (r)
453 goto out;
454
455 if (radio->band == WL1273_BAND_JAPAN)
456 radio->rx_frequency = WL1273_BAND_JAPAN_LOW +
457 freq * 50;
458 else
459 radio->rx_frequency = WL1273_BAND_OTHER_LOW +
460 freq * 50;
461 /*
462 * The driver works better with this msleep,
463 * the documentation doesn't mention it.
464 */
465 usleep_range(10000, 15000);
466
467 dev_dbg(radio->dev, "%dkHz\n", radio->rx_frequency);
468
469 } else {
470 r = wl1273_fm_read_reg(core, WL1273_CHANL_SET, &freq);
471 if (r)
472 goto out;
473
474 dev_dbg(radio->dev, "%dkHz\n", freq);
475 }
476 dev_dbg(radio->dev, "%s: NOT BUSY\n", __func__);
477 }
478
479out:
480 wl1273_fm_write_cmd(core, WL1273_INT_MASK_SET,
481 radio->irq_flags);
482 complete(&radio->busy);
483
484 return IRQ_HANDLED;
485}
486
487static int wl1273_fm_set_tx_freq(struct wl1273_device *radio, unsigned int freq)
488{
489 struct wl1273_core *core = radio->core;
490 int r = 0;
491
492 if (freq < WL1273_BAND_TX_LOW) {
493 dev_err(radio->dev,
494 "Frequency out of range: %d < %d\n", freq,
495 WL1273_BAND_TX_LOW);
496 return -ERANGE;
497 }
498
499 if (freq > WL1273_BAND_TX_HIGH) {
500 dev_err(radio->dev,
501 "Frequency out of range: %d > %d\n", freq,
502 WL1273_BAND_TX_HIGH);
503 return -ERANGE;
504 }
505
506 /*
507 * The driver works better with this sleep,
508 * the documentation doesn't mention it.
509 */
510 usleep_range(5000, 10000);
511
512 dev_dbg(radio->dev, "%s: freq: %d kHz\n", __func__, freq);
513
514 /* Set the current tx channel */
515 r = wl1273_fm_write_cmd(core, WL1273_CHANL_SET, freq / 10);
516 if (r)
517 return r;
518
519 INIT_COMPLETION(radio->busy);
520
521 /* wait for the FR IRQ */
522 r = wait_for_completion_timeout(&radio->busy, msecs_to_jiffies(2000));
523 if (!r)
524 return -ETIMEDOUT;
525
526 dev_dbg(radio->dev, "WL1273_CHANL_SET: %d\n", r);
527
528 /* Enable the output power */
529 r = wl1273_fm_write_cmd(core, WL1273_POWER_ENB_SET, 1);
530 if (r)
531 return r;
532
533 INIT_COMPLETION(radio->busy);
534
535 /* wait for the POWER_ENB IRQ */
536 r = wait_for_completion_timeout(&radio->busy, msecs_to_jiffies(1000));
537 if (!r)
538 return -ETIMEDOUT;
539
540 radio->tx_frequency = freq;
541 dev_dbg(radio->dev, "WL1273_POWER_ENB_SET: %d\n", r);
542
543 return 0;
544}
545
546static int wl1273_fm_set_rx_freq(struct wl1273_device *radio, unsigned int freq)
547{
548 struct wl1273_core *core = radio->core;
549 int r, f;
550
551 if (freq < radio->rangelow) {
552 dev_err(radio->dev,
553 "Frequency out of range: %d < %d\n", freq,
554 radio->rangelow);
555 r = -ERANGE;
556 goto err;
557 }
558
559 if (freq > radio->rangehigh) {
560 dev_err(radio->dev,
561 "Frequency out of range: %d > %d\n", freq,
562 radio->rangehigh);
563 r = -ERANGE;
564 goto err;
565 }
566
567 dev_dbg(radio->dev, "%s: %dkHz\n", __func__, freq);
568
569 wl1273_fm_write_cmd(core, WL1273_INT_MASK_SET, radio->irq_flags);
570
571 if (radio->band == WL1273_BAND_JAPAN)
572 f = (freq - WL1273_BAND_JAPAN_LOW) / 50;
573 else
574 f = (freq - WL1273_BAND_OTHER_LOW) / 50;
575
576 r = wl1273_fm_write_cmd(core, WL1273_FREQ_SET, f);
577 if (r) {
578 dev_err(radio->dev, "FREQ_SET fails\n");
579 goto err;
580 }
581
582 r = wl1273_fm_write_cmd(core, WL1273_TUNER_MODE_SET, TUNER_MODE_PRESET);
583 if (r) {
584 dev_err(radio->dev, "TUNER_MODE_SET fails\n");
585 goto err;
586 }
587
588 INIT_COMPLETION(radio->busy);
589
590 r = wait_for_completion_timeout(&radio->busy, msecs_to_jiffies(2000));
591 if (!r) {
592 dev_err(radio->dev, "%s: TIMEOUT\n", __func__);
593 return -ETIMEDOUT;
594 }
595
596 radio->rd_index = 0;
597 radio->wr_index = 0;
598 radio->rx_frequency = freq;
599 return 0;
600err:
601 return r;
602}
603
604static int wl1273_fm_get_freq(struct wl1273_device *radio)
605{
606 struct wl1273_core *core = radio->core;
607 unsigned int freq;
608 u16 f;
609 int r;
610
611 if (core->mode == WL1273_MODE_RX) {
612 r = wl1273_fm_read_reg(core, WL1273_FREQ_SET, &f);
613 if (r)
614 return r;
615
616 dev_dbg(radio->dev, "Freq get: 0x%04x\n", f);
617 if (radio->band == WL1273_BAND_JAPAN)
618 freq = WL1273_BAND_JAPAN_LOW + 50 * f;
619 else
620 freq = WL1273_BAND_OTHER_LOW + 50 * f;
621 } else {
622 r = wl1273_fm_read_reg(core, WL1273_CHANL_SET, &f);
623 if (r)
624 return r;
625
626 freq = f * 10;
627 }
628
629 return freq;
630}
631
632/**
633 * wl1273_fm_upload_firmware_patch() - Upload the firmware.
634 * @radio: A pointer to the device struct.
635 *
636 * The firmware file consists of arrays of bytes where the first byte
637 * gives the array length. The first byte in the file gives the
638 * number of these arrays.
639 */
640static int wl1273_fm_upload_firmware_patch(struct wl1273_device *radio)
641{
642 struct wl1273_core *core = radio->core;
643 unsigned int packet_num;
644 const struct firmware *fw_p;
645 const char *fw_name = "radio-wl1273-fw.bin";
646 struct device *dev = radio->dev;
647 __u8 *ptr;
648 int r;
649
650 dev_dbg(dev, "%s:\n", __func__);
651
652 /*
653 * Uploading the firmware patch is not always necessary,
654 * so we only print an info message.
655 */
656 if (request_firmware(&fw_p, fw_name, dev)) {
657 dev_info(dev, "%s - %s not found\n", __func__, fw_name);
658
659 return 0;
660 }
661
662 ptr = (__u8 *) fw_p->data;
663 packet_num = ptr[0];
664 dev_dbg(dev, "%s: packets: %d\n", __func__, packet_num);
665
666 r = wl1273_fm_write_fw(core, ptr + 1, packet_num);
667 if (r) {
668 dev_err(dev, "FW upload error: %d\n", r);
669 goto out;
670 }
671
672 /* ignore possible error here */
673 wl1273_fm_write_cmd(core, WL1273_RESET, 0);
674
675 dev_dbg(dev, "%s - download OK, r: %d\n", __func__, r);
676out:
677 release_firmware(fw_p);
678 return r;
679}
680
681static int wl1273_fm_stop(struct wl1273_device *radio)
682{
683 struct wl1273_core *core = radio->core;
684
685 if (core->mode == WL1273_MODE_RX) {
686 int r = wl1273_fm_write_cmd(core, WL1273_POWER_SET,
687 WL1273_POWER_SET_OFF);
688 if (r)
689 dev_err(radio->dev, "%s: POWER_SET fails: %d\n",
690 __func__, r);
691 } else if (core->mode == WL1273_MODE_TX) {
692 int r = wl1273_fm_write_cmd(core, WL1273_PUPD_SET,
693 WL1273_PUPD_SET_OFF);
694 if (r)
695 dev_err(radio->dev,
696 "%s: PUPD_SET fails: %d\n", __func__, r);
697 }
698
699 if (core->pdata->disable) {
700 core->pdata->disable();
701 dev_dbg(radio->dev, "Back to reset\n");
702 }
703
704 return 0;
705}
706
707static int wl1273_fm_start(struct wl1273_device *radio, int new_mode)
708{
709 struct wl1273_core *core = radio->core;
710 struct wl1273_fm_platform_data *pdata = core->pdata;
711 struct device *dev = radio->dev;
712 int r = -EINVAL;
713
714 if (pdata->enable && core->mode == WL1273_MODE_OFF) {
715 dev_dbg(radio->dev, "Out of reset\n");
716
717 pdata->enable();
718 msleep(250);
719 }
720
721 if (new_mode == WL1273_MODE_RX) {
722 u16 val = WL1273_POWER_SET_FM;
723
724 if (radio->rds_on)
725 val |= WL1273_POWER_SET_RDS;
726
727 /* If this fails try again */
728 r = wl1273_fm_write_cmd(core, WL1273_POWER_SET, val);
729 if (r) {
730 msleep(100);
731
732 r = wl1273_fm_write_cmd(core, WL1273_POWER_SET, val);
733 if (r) {
734 dev_err(dev, "%s: POWER_SET fails\n", __func__);
735 goto fail;
736 }
737 }
738
739 /* rds buffer configuration */
740 radio->wr_index = 0;
741 radio->rd_index = 0;
742
743 } else if (new_mode == WL1273_MODE_TX) {
744 /* If this fails try again once */
745 r = wl1273_fm_write_cmd(core, WL1273_PUPD_SET,
746 WL1273_PUPD_SET_ON);
747 if (r) {
748 msleep(100);
749 r = wl1273_fm_write_cmd(core, WL1273_PUPD_SET,
750 WL1273_PUPD_SET_ON);
751 if (r) {
752 dev_err(dev, "%s: PUPD_SET fails\n", __func__);
753 goto fail;
754 }
755 }
756
757 if (radio->rds_on)
758 r = wl1273_fm_write_cmd(core, WL1273_RDS_DATA_ENB, 1);
759 else
760 r = wl1273_fm_write_cmd(core, WL1273_RDS_DATA_ENB, 0);
761 } else {
762 dev_warn(dev, "%s: Illegal mode.\n", __func__);
763 }
764
765 if (core->mode == WL1273_MODE_OFF) {
766 r = wl1273_fm_upload_firmware_patch(radio);
767 if (r)
768 dev_warn(dev, "Firmware upload failed.\n");
769
770 /*
771 * Sometimes the chip is in a wrong power state at this point.
772 * So we set the power once again.
773 */
774 if (new_mode == WL1273_MODE_RX) {
775 u16 val = WL1273_POWER_SET_FM;
776
777 if (radio->rds_on)
778 val |= WL1273_POWER_SET_RDS;
779
780 r = wl1273_fm_write_cmd(core, WL1273_POWER_SET, val);
781 if (r) {
782 dev_err(dev, "%s: POWER_SET fails\n", __func__);
783 goto fail;
784 }
785 } else if (new_mode == WL1273_MODE_TX) {
786 r = wl1273_fm_write_cmd(core, WL1273_PUPD_SET,
787 WL1273_PUPD_SET_ON);
788 if (r) {
789 dev_err(dev, "%s: PUPD_SET fails\n", __func__);
790 goto fail;
791 }
792 }
793 }
794
795 return 0;
796fail:
797 if (pdata->disable)
798 pdata->disable();
799
800 dev_dbg(dev, "%s: return: %d\n", __func__, r);
801 return r;
802}
803
804static int wl1273_fm_suspend(struct wl1273_device *radio)
805{
806 struct wl1273_core *core = radio->core;
807 int r = 0;
808
809 /* Cannot go from OFF to SUSPENDED */
810 if (core->mode == WL1273_MODE_RX)
811 r = wl1273_fm_write_cmd(core, WL1273_POWER_SET,
812 WL1273_POWER_SET_RETENTION);
813 else if (core->mode == WL1273_MODE_TX)
814 r = wl1273_fm_write_cmd(core, WL1273_PUPD_SET,
815 WL1273_PUPD_SET_RETENTION);
816 else
817 r = -EINVAL;
818
819 if (r) {
820 dev_err(radio->dev, "%s: POWER_SET fails: %d\n", __func__, r);
821 goto out;
822 }
823
824out:
825 return r;
826}
827
828static int wl1273_fm_set_mode(struct wl1273_device *radio, int mode)
829{
830 struct wl1273_core *core = radio->core;
831 struct device *dev = radio->dev;
832 int old_mode;
833 int r;
834
835 dev_dbg(dev, "%s\n", __func__);
836 dev_dbg(dev, "Forbidden modes: 0x%02x\n", radio->forbidden);
837
838 old_mode = core->mode;
839 if (mode & radio->forbidden) {
840 r = -EPERM;
841 goto out;
842 }
843
844 switch (mode) {
845 case WL1273_MODE_RX:
846 case WL1273_MODE_TX:
847 r = wl1273_fm_start(radio, mode);
848 if (r) {
849 dev_err(dev, "%s: Cannot start.\n", __func__);
850 wl1273_fm_stop(radio);
851 goto out;
852 }
853
854 core->mode = mode;
855 r = wl1273_fm_write_cmd(core, WL1273_INT_MASK_SET,
856 radio->irq_flags);
857 if (r) {
858 dev_err(dev, "INT_MASK_SET fails.\n");
859 goto out;
860 }
861
862 /* remember previous settings */
863 if (mode == WL1273_MODE_RX) {
864 r = wl1273_fm_set_rx_freq(radio, radio->rx_frequency);
865 if (r) {
866 dev_err(dev, "set freq fails: %d.\n", r);
867 goto out;
868 }
869
870 r = core->set_volume(core, core->volume);
871 if (r) {
872 dev_err(dev, "set volume fails: %d.\n", r);
873 goto out;
874 }
875
876 dev_dbg(dev, "%s: Set vol: %d.\n", __func__,
877 core->volume);
878 } else {
879 r = wl1273_fm_set_tx_freq(radio, radio->tx_frequency);
880 if (r) {
881 dev_err(dev, "set freq fails: %d.\n", r);
882 goto out;
883 }
884 }
885
886 dev_dbg(radio->dev, "%s: Set audio mode.\n", __func__);
887
888 r = core->set_audio(core, core->audio_mode);
889 if (r)
890 dev_err(dev, "Cannot set audio mode.\n");
891 break;
892
893 case WL1273_MODE_OFF:
894 r = wl1273_fm_stop(radio);
895 if (r)
896 dev_err(dev, "%s: Off fails: %d\n", __func__, r);
897 else
898 core->mode = WL1273_MODE_OFF;
899
900 break;
901
902 case WL1273_MODE_SUSPENDED:
903 r = wl1273_fm_suspend(radio);
904 if (r)
905 dev_err(dev, "%s: Suspend fails: %d\n", __func__, r);
906 else
907 core->mode = WL1273_MODE_SUSPENDED;
908
909 break;
910
911 default:
912 dev_err(dev, "%s: Unknown mode: %d\n", __func__, mode);
913 r = -EINVAL;
914 break;
915 }
916out:
917 if (r)
918 core->mode = old_mode;
919
920 return r;
921}
922
923static int wl1273_fm_set_seek(struct wl1273_device *radio,
924 unsigned int wrap_around,
925 unsigned int seek_upward,
926 int level)
927{
928 struct wl1273_core *core = radio->core;
929 int r = 0;
930 unsigned int dir = (seek_upward == 0) ? 0 : 1;
931 unsigned int f;
932
933 f = radio->rx_frequency;
934 dev_dbg(radio->dev, "rx_frequency: %d\n", f);
935
936 if (dir && f + radio->spacing <= radio->rangehigh)
937 r = wl1273_fm_set_rx_freq(radio, f + radio->spacing);
938 else if (dir && wrap_around)
939 r = wl1273_fm_set_rx_freq(radio, radio->rangelow);
940 else if (f - radio->spacing >= radio->rangelow)
941 r = wl1273_fm_set_rx_freq(radio, f - radio->spacing);
942 else if (wrap_around)
943 r = wl1273_fm_set_rx_freq(radio, radio->rangehigh);
944
945 if (r)
946 goto out;
947
948 if (level < SCHAR_MIN || level > SCHAR_MAX)
949 return -EINVAL;
950
951 INIT_COMPLETION(radio->busy);
952 dev_dbg(radio->dev, "%s: BUSY\n", __func__);
953
954 r = wl1273_fm_write_cmd(core, WL1273_INT_MASK_SET, radio->irq_flags);
955 if (r)
956 goto out;
957
958 dev_dbg(radio->dev, "%s\n", __func__);
959
960 r = wl1273_fm_write_cmd(core, WL1273_SEARCH_LVL_SET, level);
961 if (r)
962 goto out;
963
964 r = wl1273_fm_write_cmd(core, WL1273_SEARCH_DIR_SET, dir);
965 if (r)
966 goto out;
967
968 r = wl1273_fm_write_cmd(core, WL1273_TUNER_MODE_SET,
969 TUNER_MODE_AUTO_SEEK);
970 if (r)
971 goto out;
972
973 wait_for_completion_timeout(&radio->busy, msecs_to_jiffies(1000));
974 if (!(radio->irq_received & WL1273_BL_EVENT))
975 goto out;
976
977 radio->irq_received &= ~WL1273_BL_EVENT;
978
979 if (!wrap_around)
980 goto out;
981
982 /* Wrap around */
983 dev_dbg(radio->dev, "Wrap around in HW seek.\n");
984
985 if (seek_upward)
986 f = radio->rangelow;
987 else
988 f = radio->rangehigh;
989
990 r = wl1273_fm_set_rx_freq(radio, f);
991 if (r)
992 goto out;
993
994 INIT_COMPLETION(radio->busy);
995 dev_dbg(radio->dev, "%s: BUSY\n", __func__);
996
997 r = wl1273_fm_write_cmd(core, WL1273_TUNER_MODE_SET,
998 TUNER_MODE_AUTO_SEEK);
999 if (r)
1000 goto out;
1001
1002 wait_for_completion_timeout(&radio->busy, msecs_to_jiffies(1000));
1003out:
1004 dev_dbg(radio->dev, "%s: Err: %d\n", __func__, r);
1005 return r;
1006}
1007
1008/**
1009 * wl1273_fm_get_tx_ctune() - Get the TX tuning capacitor value.
1010 * @radio: A pointer to the device struct.
1011 */
1012static unsigned int wl1273_fm_get_tx_ctune(struct wl1273_device *radio)
1013{
1014 struct wl1273_core *core = radio->core;
1015 struct device *dev = radio->dev;
1016 u16 val;
1017 int r;
1018
1019 if (core->mode == WL1273_MODE_OFF ||
1020 core->mode == WL1273_MODE_SUSPENDED)
1021 return -EPERM;
1022
1023 r = wl1273_fm_read_reg(core, WL1273_READ_FMANT_TUNE_VALUE, &val);
1024 if (r) {
1025 dev_err(dev, "%s: read error: %d\n", __func__, r);
1026 goto out;
1027 }
1028
1029out:
1030 return val;
1031}
1032
1033/**
1034 * wl1273_fm_set_preemphasis() - Set the TX pre-emphasis value.
1035 * @radio: A pointer to the device struct.
1036 * @preemphasis: The new pre-amphasis value.
1037 *
1038 * Possible pre-emphasis values are: V4L2_PREEMPHASIS_DISABLED,
1039 * V4L2_PREEMPHASIS_50_uS and V4L2_PREEMPHASIS_75_uS.
1040 */
1041static int wl1273_fm_set_preemphasis(struct wl1273_device *radio,
1042 unsigned int preemphasis)
1043{
1044 struct wl1273_core *core = radio->core;
1045 int r;
1046 u16 em;
1047
1048 if (core->mode == WL1273_MODE_OFF ||
1049 core->mode == WL1273_MODE_SUSPENDED)
1050 return -EPERM;
1051
1052 mutex_lock(&core->lock);
1053
1054 switch (preemphasis) {
1055 case V4L2_PREEMPHASIS_DISABLED:
1056 em = 1;
1057 break;
1058 case V4L2_PREEMPHASIS_50_uS:
1059 em = 0;
1060 break;
1061 case V4L2_PREEMPHASIS_75_uS:
1062 em = 2;
1063 break;
1064 default:
1065 r = -EINVAL;
1066 goto out;
1067 }
1068
1069 r = wl1273_fm_write_cmd(core, WL1273_PREMPH_SET, em);
1070 if (r)
1071 goto out;
1072
1073 radio->preemphasis = preemphasis;
1074
1075out:
1076 mutex_unlock(&core->lock);
1077 return r;
1078}
1079
1080static int wl1273_fm_rds_on(struct wl1273_device *radio)
1081{
1082 struct wl1273_core *core = radio->core;
1083 int r;
1084
1085 dev_dbg(radio->dev, "%s\n", __func__);
1086 if (radio->rds_on)
1087 return 0;
1088
1089 r = wl1273_fm_write_cmd(core, WL1273_POWER_SET,
1090 WL1273_POWER_SET_FM | WL1273_POWER_SET_RDS);
1091 if (r)
1092 goto out;
1093
1094 r = wl1273_fm_set_rx_freq(radio, radio->rx_frequency);
1095 if (r)
1096 dev_err(radio->dev, "set freq fails: %d.\n", r);
1097out:
1098 return r;
1099}
1100
1101static int wl1273_fm_rds_off(struct wl1273_device *radio)
1102{
1103 struct wl1273_core *core = radio->core;
1104 int r;
1105
1106 if (!radio->rds_on)
1107 return 0;
1108
1109 radio->irq_flags &= ~WL1273_RDS_EVENT;
1110
1111 r = wl1273_fm_write_cmd(core, WL1273_INT_MASK_SET, radio->irq_flags);
1112 if (r)
1113 goto out;
1114
1115 /* stop rds reception */
1116 cancel_delayed_work(&radio->work);
1117
1118 /* Service pending read */
1119 wake_up_interruptible(&radio->read_queue);
1120
1121 dev_dbg(radio->dev, "%s\n", __func__);
1122
1123 r = wl1273_fm_write_cmd(core, WL1273_POWER_SET, WL1273_POWER_SET_FM);
1124 if (r)
1125 goto out;
1126
1127 r = wl1273_fm_set_rx_freq(radio, radio->rx_frequency);
1128 if (r)
1129 dev_err(radio->dev, "set freq fails: %d.\n", r);
1130out:
1131 dev_dbg(radio->dev, "%s: exiting...\n", __func__);
1132
1133 return r;
1134}
1135
1136static int wl1273_fm_set_rds(struct wl1273_device *radio, unsigned int new_mode)
1137{
1138 int r = 0;
1139 struct wl1273_core *core = radio->core;
1140
1141 if (core->mode == WL1273_MODE_OFF ||
1142 core->mode == WL1273_MODE_SUSPENDED)
1143 return -EPERM;
1144
1145 if (new_mode == WL1273_RDS_RESET) {
1146 r = wl1273_fm_write_cmd(core, WL1273_RDS_CNTRL_SET, 1);
1147 return r;
1148 }
1149
1150 if (core->mode == WL1273_MODE_TX && new_mode == WL1273_RDS_OFF) {
1151 r = wl1273_fm_write_cmd(core, WL1273_RDS_DATA_ENB, 0);
1152 } else if (core->mode == WL1273_MODE_TX && new_mode == WL1273_RDS_ON) {
1153 r = wl1273_fm_write_cmd(core, WL1273_RDS_DATA_ENB, 1);
1154 } else if (core->mode == WL1273_MODE_RX && new_mode == WL1273_RDS_OFF) {
1155 r = wl1273_fm_rds_off(radio);
1156 } else if (core->mode == WL1273_MODE_RX && new_mode == WL1273_RDS_ON) {
1157 r = wl1273_fm_rds_on(radio);
1158 } else {
1159 dev_err(radio->dev, "%s: Unknown mode: %d\n",
1160 __func__, new_mode);
1161 r = -EINVAL;
1162 }
1163
1164 if (!r)
1165 radio->rds_on = (new_mode == WL1273_RDS_ON) ? true : false;
1166
1167 return r;
1168}
1169
1170static ssize_t wl1273_fm_fops_write(struct file *file, const char __user *buf,
1171 size_t count, loff_t *ppos)
1172{
1173 struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
1174 u16 val;
1175 int r;
1176
1177 dev_dbg(radio->dev, "%s\n", __func__);
1178
1179 if (radio->core->mode != WL1273_MODE_TX)
1180 return count;
1181
1182 if (radio->rds_users == 0) {
1183 dev_warn(radio->dev, "%s: RDS not on.\n", __func__);
1184 return 0;
1185 }
1186
1187 if (mutex_lock_interruptible(&radio->core->lock))
1188 return -EINTR;
1189 /*
1190 * Multiple processes can open the device, but only
1191 * one gets to write to it.
1192 */
1193 if (radio->owner && radio->owner != file) {
1194 r = -EBUSY;
1195 goto out;
1196 }
1197 radio->owner = file;
1198
1199 /* Manual Mode */
1200 if (count > 255)
1201 val = 255;
1202 else
1203 val = count;
1204
1205 wl1273_fm_write_cmd(radio->core, WL1273_RDS_CONFIG_DATA_SET, val);
1206
1207 if (copy_from_user(radio->write_buf + 1, buf, val)) {
1208 r = -EFAULT;
1209 goto out;
1210 }
1211
1212 dev_dbg(radio->dev, "Count: %d\n", val);
1213 dev_dbg(radio->dev, "From user: \"%s\"\n", radio->write_buf);
1214
1215 radio->write_buf[0] = WL1273_RDS_DATA_SET;
1216 wl1273_fm_write_data(radio->core, radio->write_buf, val + 1);
1217
1218 r = val;
1219out:
1220 mutex_unlock(&radio->core->lock);
1221
1222 return r;
1223}
1224
1225static unsigned int wl1273_fm_fops_poll(struct file *file,
1226 struct poll_table_struct *pts)
1227{
1228 struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
1229 struct wl1273_core *core = radio->core;
1230
1231 if (radio->owner && radio->owner != file)
1232 return -EBUSY;
1233
1234 radio->owner = file;
1235
1236 if (core->mode == WL1273_MODE_RX) {
1237 poll_wait(file, &radio->read_queue, pts);
1238
1239 if (radio->rd_index != radio->wr_index)
1240 return POLLIN | POLLRDNORM;
1241
1242 } else if (core->mode == WL1273_MODE_TX) {
1243 return POLLOUT | POLLWRNORM;
1244 }
1245
1246 return 0;
1247}
1248
1249static int wl1273_fm_fops_open(struct file *file)
1250{
1251 struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
1252 struct wl1273_core *core = radio->core;
1253 int r = 0;
1254
1255 dev_dbg(radio->dev, "%s\n", __func__);
1256
1257 if (core->mode == WL1273_MODE_RX && radio->rds_on &&
1258 !radio->rds_users) {
1259 dev_dbg(radio->dev, "%s: Mode: %d\n", __func__, core->mode);
1260
1261 if (mutex_lock_interruptible(&core->lock))
1262 return -EINTR;
1263
1264 radio->irq_flags |= WL1273_RDS_EVENT;
1265
1266 r = wl1273_fm_write_cmd(core, WL1273_INT_MASK_SET,
1267 radio->irq_flags);
1268 if (r) {
1269 mutex_unlock(&core->lock);
1270 goto out;
1271 }
1272
1273 radio->rds_users++;
1274
1275 mutex_unlock(&core->lock);
1276 }
1277out:
1278 return r;
1279}
1280
1281static int wl1273_fm_fops_release(struct file *file)
1282{
1283 struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
1284 struct wl1273_core *core = radio->core;
1285 int r = 0;
1286
1287 dev_dbg(radio->dev, "%s\n", __func__);
1288
1289 if (radio->rds_users > 0) {
1290 radio->rds_users--;
1291 if (radio->rds_users == 0) {
1292 if (mutex_lock_interruptible(&core->lock))
1293 return -EINTR;
1294
1295 radio->irq_flags &= ~WL1273_RDS_EVENT;
1296
1297 if (core->mode == WL1273_MODE_RX) {
1298 r = wl1273_fm_write_cmd(core,
1299 WL1273_INT_MASK_SET,
1300 radio->irq_flags);
1301 if (r) {
1302 mutex_unlock(&core->lock);
1303 goto out;
1304 }
1305 }
1306 mutex_unlock(&core->lock);
1307 }
1308 }
1309
1310 if (file == radio->owner)
1311 radio->owner = NULL;
1312out:
1313 return r;
1314}
1315
1316static ssize_t wl1273_fm_fops_read(struct file *file, char __user *buf,
1317 size_t count, loff_t *ppos)
1318{
1319 int r = 0;
1320 struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
1321 struct wl1273_core *core = radio->core;
1322 unsigned int block_count = 0;
1323 u16 val;
1324
1325 dev_dbg(radio->dev, "%s\n", __func__);
1326
1327 if (radio->core->mode != WL1273_MODE_RX)
1328 return 0;
1329
1330 if (radio->rds_users == 0) {
1331 dev_warn(radio->dev, "%s: RDS not on.\n", __func__);
1332 return 0;
1333 }
1334
1335 if (mutex_lock_interruptible(&core->lock))
1336 return -EINTR;
1337
1338 /*
1339 * Multiple processes can open the device, but only
1340 * one at a time gets read access.
1341 */
1342 if (radio->owner && radio->owner != file) {
1343 r = -EBUSY;
1344 goto out;
1345 }
1346 radio->owner = file;
1347
1348 r = wl1273_fm_read_reg(core, WL1273_RDS_SYNC_GET, &val);
1349 if (r) {
1350 dev_err(radio->dev, "%s: Get RDS_SYNC fails.\n", __func__);
1351 goto out;
1352 } else if (val == 0) {
1353 dev_info(radio->dev, "RDS_SYNC: Not synchronized\n");
1354 r = -ENODATA;
1355 goto out;
1356 }
1357
1358 /* block if no new data available */
1359 while (radio->wr_index == radio->rd_index) {
1360 if (file->f_flags & O_NONBLOCK) {
1361 r = -EWOULDBLOCK;
1362 goto out;
1363 }
1364
1365 dev_dbg(radio->dev, "%s: Wait for RDS data.\n", __func__);
1366 if (wait_event_interruptible(radio->read_queue,
1367 radio->wr_index !=
1368 radio->rd_index) < 0) {
1369 r = -EINTR;
1370 goto out;
1371 }
1372 }
1373
1374 /* calculate block count from byte count */
1375 count /= RDS_BLOCK_SIZE;
1376
1377 /* copy RDS blocks from the internal buffer and to user buffer */
1378 while (block_count < count) {
1379 if (radio->rd_index == radio->wr_index)
1380 break;
1381
1382 /* always transfer complete RDS blocks */
1383 if (copy_to_user(buf, &radio->buffer[radio->rd_index],
1384 RDS_BLOCK_SIZE))
1385 break;
1386
1387 /* increment and wrap the read pointer */
1388 radio->rd_index += RDS_BLOCK_SIZE;
1389 if (radio->rd_index >= radio->buf_size)
1390 radio->rd_index = 0;
1391
1392 /* increment counters */
1393 block_count++;
1394 buf += RDS_BLOCK_SIZE;
1395 r += RDS_BLOCK_SIZE;
1396 }
1397
1398out:
1399 dev_dbg(radio->dev, "%s: exit\n", __func__);
1400 mutex_unlock(&core->lock);
1401
1402 return r;
1403}
1404
1405static const struct v4l2_file_operations wl1273_fops = {
1406 .owner = THIS_MODULE,
1407 .read = wl1273_fm_fops_read,
1408 .write = wl1273_fm_fops_write,
1409 .poll = wl1273_fm_fops_poll,
1410 .ioctl = video_ioctl2,
1411 .open = wl1273_fm_fops_open,
1412 .release = wl1273_fm_fops_release,
1413};
1414
1415static int wl1273_fm_vidioc_querycap(struct file *file, void *priv,
1416 struct v4l2_capability *capability)
1417{
1418 struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
1419
1420 dev_dbg(radio->dev, "%s\n", __func__);
1421
1422 strlcpy(capability->driver, WL1273_FM_DRIVER_NAME,
1423 sizeof(capability->driver));
1424 strlcpy(capability->card, "Texas Instruments Wl1273 FM Radio",
1425 sizeof(capability->card));
1426 strlcpy(capability->bus_info, radio->bus_type,
1427 sizeof(capability->bus_info));
1428
1429 capability->capabilities = V4L2_CAP_HW_FREQ_SEEK |
1430 V4L2_CAP_TUNER | V4L2_CAP_RADIO | V4L2_CAP_AUDIO |
1431 V4L2_CAP_RDS_CAPTURE | V4L2_CAP_MODULATOR |
1432 V4L2_CAP_RDS_OUTPUT;
1433
1434 return 0;
1435}
1436
1437static int wl1273_fm_vidioc_g_input(struct file *file, void *priv,
1438 unsigned int *i)
1439{
1440 struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
1441
1442 dev_dbg(radio->dev, "%s\n", __func__);
1443
1444 *i = 0;
1445
1446 return 0;
1447}
1448
1449static int wl1273_fm_vidioc_s_input(struct file *file, void *priv,
1450 unsigned int i)
1451{
1452 struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
1453
1454 dev_dbg(radio->dev, "%s\n", __func__);
1455
1456 if (i != 0)
1457 return -EINVAL;
1458
1459 return 0;
1460}
1461
1462/**
1463 * wl1273_fm_set_tx_power() - Set the transmission power value.
1464 * @core: A pointer to the device struct.
1465 * @power: The new power value.
1466 */
1467static int wl1273_fm_set_tx_power(struct wl1273_device *radio, u16 power)
1468{
1469 int r;
1470
1471 if (radio->core->mode == WL1273_MODE_OFF ||
1472 radio->core->mode == WL1273_MODE_SUSPENDED)
1473 return -EPERM;
1474
1475 mutex_lock(&radio->core->lock);
1476
1477 /* Convert the dBuV value to chip presentation */
1478 r = wl1273_fm_write_cmd(radio->core, WL1273_POWER_LEV_SET, 122 - power);
1479 if (r)
1480 goto out;
1481
1482 radio->tx_power = power;
1483
1484out:
1485 mutex_unlock(&radio->core->lock);
1486 return r;
1487}
1488
1489#define WL1273_SPACING_50kHz 1
1490#define WL1273_SPACING_100kHz 2
1491#define WL1273_SPACING_200kHz 4
1492
1493static int wl1273_fm_tx_set_spacing(struct wl1273_device *radio,
1494 unsigned int spacing)
1495{
1496 int r;
1497
1498 if (spacing == 0) {
1499 r = wl1273_fm_write_cmd(radio->core, WL1273_SCAN_SPACING_SET,
1500 WL1273_SPACING_100kHz);
1501 radio->spacing = 100;
1502 } else if (spacing - 50000 < 25000) {
1503 r = wl1273_fm_write_cmd(radio->core, WL1273_SCAN_SPACING_SET,
1504 WL1273_SPACING_50kHz);
1505 radio->spacing = 50;
1506 } else if (spacing - 100000 < 50000) {
1507 r = wl1273_fm_write_cmd(radio->core, WL1273_SCAN_SPACING_SET,
1508 WL1273_SPACING_100kHz);
1509 radio->spacing = 100;
1510 } else {
1511 r = wl1273_fm_write_cmd(radio->core, WL1273_SCAN_SPACING_SET,
1512 WL1273_SPACING_200kHz);
1513 radio->spacing = 200;
1514 }
1515
1516 return r;
1517}
1518
1519static int wl1273_fm_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
1520{
1521 struct wl1273_device *radio = ctrl->priv;
1522 struct wl1273_core *core = radio->core;
1523
1524 dev_dbg(radio->dev, "%s\n", __func__);
1525
1526 if (mutex_lock_interruptible(&core->lock))
1527 return -EINTR;
1528
1529 switch (ctrl->id) {
1530 case V4L2_CID_TUNE_ANTENNA_CAPACITOR:
1531 ctrl->val = wl1273_fm_get_tx_ctune(radio);
1532 break;
1533
1534 default:
1535 dev_warn(radio->dev, "%s: Unknown IOCTL: %d\n",
1536 __func__, ctrl->id);
1537 break;
1538 }
1539
1540 mutex_unlock(&core->lock);
1541
1542 return 0;
1543}
1544
1545#define WL1273_MUTE_SOFT_ENABLE (1 << 0)
1546#define WL1273_MUTE_AC (1 << 1)
1547#define WL1273_MUTE_HARD_LEFT (1 << 2)
1548#define WL1273_MUTE_HARD_RIGHT (1 << 3)
1549#define WL1273_MUTE_SOFT_FORCE (1 << 4)
1550
1551static inline struct wl1273_device *to_radio(struct v4l2_ctrl *ctrl)
1552{
1553 return container_of(ctrl->handler, struct wl1273_device, ctrl_handler);
1554}
1555
1556static int wl1273_fm_vidioc_s_ctrl(struct v4l2_ctrl *ctrl)
1557{
1558 struct wl1273_device *radio = to_radio(ctrl);
1559 struct wl1273_core *core = radio->core;
1560 int r = 0;
1561
1562 dev_dbg(radio->dev, "%s\n", __func__);
1563
1564 switch (ctrl->id) {
1565 case V4L2_CID_AUDIO_MUTE:
1566 if (mutex_lock_interruptible(&core->lock))
1567 return -EINTR;
1568
1569 if (core->mode == WL1273_MODE_RX && ctrl->val)
1570 r = wl1273_fm_write_cmd(core,
1571 WL1273_MUTE_STATUS_SET,
1572 WL1273_MUTE_HARD_LEFT |
1573 WL1273_MUTE_HARD_RIGHT);
1574 else if (core->mode == WL1273_MODE_RX)
1575 r = wl1273_fm_write_cmd(core,
1576 WL1273_MUTE_STATUS_SET, 0x0);
1577 else if (core->mode == WL1273_MODE_TX && ctrl->val)
1578 r = wl1273_fm_write_cmd(core, WL1273_MUTE, 1);
1579 else if (core->mode == WL1273_MODE_TX)
1580 r = wl1273_fm_write_cmd(core, WL1273_MUTE, 0);
1581
1582 mutex_unlock(&core->lock);
1583 break;
1584
1585 case V4L2_CID_AUDIO_VOLUME:
1586 if (ctrl->val == 0)
1587 r = wl1273_fm_set_mode(radio, WL1273_MODE_OFF);
1588 else
1589 r = core->set_volume(core, core->volume);
1590 break;
1591
1592 case V4L2_CID_TUNE_PREEMPHASIS:
1593 r = wl1273_fm_set_preemphasis(radio, ctrl->val);
1594 break;
1595
1596 case V4L2_CID_TUNE_POWER_LEVEL:
1597 r = wl1273_fm_set_tx_power(radio, ctrl->val);
1598 break;
1599
1600 default:
1601 dev_warn(radio->dev, "%s: Unknown IOCTL: %d\n",
1602 __func__, ctrl->id);
1603 break;
1604 }
1605
1606 dev_dbg(radio->dev, "%s\n", __func__);
1607 return r;
1608}
1609
1610static int wl1273_fm_vidioc_g_audio(struct file *file, void *priv,
1611 struct v4l2_audio *audio)
1612{
1613 struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
1614
1615 dev_dbg(radio->dev, "%s\n", __func__);
1616
1617 if (audio->index > 1)
1618 return -EINVAL;
1619
1620 strlcpy(audio->name, "Radio", sizeof(audio->name));
1621 audio->capability = V4L2_AUDCAP_STEREO;
1622
1623 return 0;
1624}
1625
1626static int wl1273_fm_vidioc_s_audio(struct file *file, void *priv,
1627 struct v4l2_audio *audio)
1628{
1629 struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
1630
1631 dev_dbg(radio->dev, "%s\n", __func__);
1632
1633 if (audio->index != 0)
1634 return -EINVAL;
1635
1636 return 0;
1637}
1638
1639#define WL1273_RDS_NOT_SYNCHRONIZED 0
1640#define WL1273_RDS_SYNCHRONIZED 1
1641
1642static int wl1273_fm_vidioc_g_tuner(struct file *file, void *priv,
1643 struct v4l2_tuner *tuner)
1644{
1645 struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
1646 struct wl1273_core *core = radio->core;
1647 u16 val;
1648 int r;
1649
1650 dev_dbg(radio->dev, "%s\n", __func__);
1651
1652 if (tuner->index > 0)
1653 return -EINVAL;
1654
1655 strlcpy(tuner->name, WL1273_FM_DRIVER_NAME, sizeof(tuner->name));
1656 tuner->type = V4L2_TUNER_RADIO;
1657
1658 tuner->rangelow = WL1273_FREQ(WL1273_BAND_JAPAN_LOW);
1659 tuner->rangehigh = WL1273_FREQ(WL1273_BAND_OTHER_HIGH);
1660
1661 tuner->capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_RDS |
1662 V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_RDS_BLOCK_IO;
1663
1664 if (radio->stereo)
1665 tuner->audmode = V4L2_TUNER_MODE_STEREO;
1666 else
1667 tuner->audmode = V4L2_TUNER_MODE_MONO;
1668
1669 if (core->mode != WL1273_MODE_RX)
1670 return 0;
1671
1672 if (mutex_lock_interruptible(&core->lock))
1673 return -EINTR;
1674
1675 r = wl1273_fm_read_reg(core, WL1273_STEREO_GET, &val);
1676 if (r)
1677 goto out;
1678
1679 if (val == 1)
1680 tuner->rxsubchans = V4L2_TUNER_SUB_STEREO;
1681 else
1682 tuner->rxsubchans = V4L2_TUNER_SUB_MONO;
1683
1684 r = wl1273_fm_read_reg(core, WL1273_RSSI_LVL_GET, &val);
1685 if (r)
1686 goto out;
1687
1688 tuner->signal = (s16) val;
1689 dev_dbg(radio->dev, "Signal: %d\n", tuner->signal);
1690
1691 tuner->afc = 0;
1692
1693 r = wl1273_fm_read_reg(core, WL1273_RDS_SYNC_GET, &val);
1694 if (r)
1695 goto out;
1696
1697 if (val == WL1273_RDS_SYNCHRONIZED)
1698 tuner->rxsubchans |= V4L2_TUNER_SUB_RDS;
1699out:
1700 mutex_unlock(&core->lock);
1701
1702 return r;
1703}
1704
1705static int wl1273_fm_vidioc_s_tuner(struct file *file, void *priv,
1706 struct v4l2_tuner *tuner)
1707{
1708 struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
1709 struct wl1273_core *core = radio->core;
1710 int r = 0;
1711
1712 dev_dbg(radio->dev, "%s\n", __func__);
1713 dev_dbg(radio->dev, "tuner->index: %d\n", tuner->index);
1714 dev_dbg(radio->dev, "tuner->name: %s\n", tuner->name);
1715 dev_dbg(radio->dev, "tuner->capability: 0x%04x\n", tuner->capability);
1716 dev_dbg(radio->dev, "tuner->rxsubchans: 0x%04x\n", tuner->rxsubchans);
1717 dev_dbg(radio->dev, "tuner->rangelow: %d\n", tuner->rangelow);
1718 dev_dbg(radio->dev, "tuner->rangehigh: %d\n", tuner->rangehigh);
1719
1720 if (tuner->index > 0)
1721 return -EINVAL;
1722
1723 if (mutex_lock_interruptible(&core->lock))
1724 return -EINTR;
1725
1726 r = wl1273_fm_set_mode(radio, WL1273_MODE_RX);
1727 if (r)
1728 goto out;
1729
1730 if (tuner->rxsubchans & V4L2_TUNER_SUB_RDS)
1731 r = wl1273_fm_set_rds(radio, WL1273_RDS_ON);
1732 else
1733 r = wl1273_fm_set_rds(radio, WL1273_RDS_OFF);
1734
1735 if (r)
1736 dev_warn(radio->dev, "%s: RDS fails: %d\n", __func__, r);
1737
1738 if (tuner->audmode == V4L2_TUNER_MODE_MONO) {
1739 r = wl1273_fm_write_cmd(core, WL1273_MOST_MODE_SET,
1740 WL1273_RX_MONO);
1741 if (r < 0) {
1742 dev_warn(radio->dev, "%s: MOST_MODE fails: %d\n",
1743 __func__, r);
1744 goto out;
1745 }
1746 radio->stereo = false;
1747 } else if (tuner->audmode == V4L2_TUNER_MODE_STEREO) {
1748 r = wl1273_fm_write_cmd(core, WL1273_MOST_MODE_SET,
1749 WL1273_RX_STEREO);
1750 if (r < 0) {
1751 dev_warn(radio->dev, "%s: MOST_MODE fails: %d\n",
1752 __func__, r);
1753 goto out;
1754 }
1755 radio->stereo = true;
1756 } else {
1757 dev_err(radio->dev, "%s: tuner->audmode: %d\n",
1758 __func__, tuner->audmode);
1759 r = -EINVAL;
1760 goto out;
1761 }
1762
1763out:
1764 mutex_unlock(&core->lock);
1765
1766 return r;
1767}
1768
1769static int wl1273_fm_vidioc_g_frequency(struct file *file, void *priv,
1770 struct v4l2_frequency *freq)
1771{
1772 struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
1773 struct wl1273_core *core = radio->core;
1774
1775 dev_dbg(radio->dev, "%s\n", __func__);
1776
1777 if (mutex_lock_interruptible(&core->lock))
1778 return -EINTR;
1779
1780 freq->type = V4L2_TUNER_RADIO;
1781 freq->frequency = WL1273_FREQ(wl1273_fm_get_freq(radio));
1782
1783 mutex_unlock(&core->lock);
1784
1785 return 0;
1786}
1787
1788static int wl1273_fm_vidioc_s_frequency(struct file *file, void *priv,
1789 struct v4l2_frequency *freq)
1790{
1791 struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
1792 struct wl1273_core *core = radio->core;
1793 int r;
1794
1795 dev_dbg(radio->dev, "%s: %d\n", __func__, freq->frequency);
1796
1797 if (freq->type != V4L2_TUNER_RADIO) {
1798 dev_dbg(radio->dev,
1799 "freq->type != V4L2_TUNER_RADIO: %d\n", freq->type);
1800 return -EINVAL;
1801 }
1802
1803 if (mutex_lock_interruptible(&core->lock))
1804 return -EINTR;
1805
1806 if (core->mode == WL1273_MODE_RX) {
1807 dev_dbg(radio->dev, "freq: %d\n", freq->frequency);
1808
1809 r = wl1273_fm_set_rx_freq(radio,
1810 WL1273_INV_FREQ(freq->frequency));
1811 if (r)
1812 dev_warn(radio->dev, WL1273_FM_DRIVER_NAME
1813 ": set frequency failed with %d\n", r);
1814 } else {
1815 r = wl1273_fm_set_tx_freq(radio,
1816 WL1273_INV_FREQ(freq->frequency));
1817 if (r)
1818 dev_warn(radio->dev, WL1273_FM_DRIVER_NAME
1819 ": set frequency failed with %d\n", r);
1820 }
1821
1822 mutex_unlock(&core->lock);
1823
1824 dev_dbg(radio->dev, "wl1273_vidioc_s_frequency: DONE\n");
1825 return r;
1826}
1827
1828#define WL1273_DEFAULT_SEEK_LEVEL 7
1829
1830static int wl1273_fm_vidioc_s_hw_freq_seek(struct file *file, void *priv,
1831 struct v4l2_hw_freq_seek *seek)
1832{
1833 struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
1834 struct wl1273_core *core = radio->core;
1835 int r;
1836
1837 dev_dbg(radio->dev, "%s\n", __func__);
1838
1839 if (seek->tuner != 0 || seek->type != V4L2_TUNER_RADIO)
1840 return -EINVAL;
1841
1842 if (mutex_lock_interruptible(&core->lock))
1843 return -EINTR;
1844
1845 r = wl1273_fm_set_mode(radio, WL1273_MODE_RX);
1846 if (r)
1847 goto out;
1848
1849 r = wl1273_fm_tx_set_spacing(radio, seek->spacing);
1850 if (r)
1851 dev_warn(radio->dev, "HW seek failed: %d\n", r);
1852
1853 r = wl1273_fm_set_seek(radio, seek->wrap_around, seek->seek_upward,
1854 WL1273_DEFAULT_SEEK_LEVEL);
1855 if (r)
1856 dev_warn(radio->dev, "HW seek failed: %d\n", r);
1857
1858out:
1859 mutex_unlock(&core->lock);
1860 return r;
1861}
1862
1863static int wl1273_fm_vidioc_s_modulator(struct file *file, void *priv,
1864 struct v4l2_modulator *modulator)
1865{
1866 struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
1867 struct wl1273_core *core = radio->core;
1868 int r = 0;
1869
1870 dev_dbg(radio->dev, "%s\n", __func__);
1871
1872 if (modulator->index > 0)
1873 return -EINVAL;
1874
1875 if (mutex_lock_interruptible(&core->lock))
1876 return -EINTR;
1877
1878 r = wl1273_fm_set_mode(radio, WL1273_MODE_TX);
1879 if (r)
1880 goto out;
1881
1882 if (modulator->txsubchans & V4L2_TUNER_SUB_RDS)
1883 r = wl1273_fm_set_rds(radio, WL1273_RDS_ON);
1884 else
1885 r = wl1273_fm_set_rds(radio, WL1273_RDS_OFF);
1886
1887 if (modulator->txsubchans & V4L2_TUNER_SUB_MONO)
1888 r = wl1273_fm_write_cmd(core, WL1273_MONO_SET, WL1273_TX_MONO);
1889 else
1890 r = wl1273_fm_write_cmd(core, WL1273_MONO_SET,
1891 WL1273_RX_STEREO);
1892 if (r < 0)
1893 dev_warn(radio->dev, WL1273_FM_DRIVER_NAME
1894 "MONO_SET fails: %d\n", r);
1895out:
1896 mutex_unlock(&core->lock);
1897
1898 return r;
1899}
1900
1901static int wl1273_fm_vidioc_g_modulator(struct file *file, void *priv,
1902 struct v4l2_modulator *modulator)
1903{
1904 struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
1905 struct wl1273_core *core = radio->core;
1906 u16 val;
1907 int r;
1908
1909 dev_dbg(radio->dev, "%s\n", __func__);
1910
1911 strlcpy(modulator->name, WL1273_FM_DRIVER_NAME,
1912 sizeof(modulator->name));
1913
1914 modulator->rangelow = WL1273_FREQ(WL1273_BAND_JAPAN_LOW);
1915 modulator->rangehigh = WL1273_FREQ(WL1273_BAND_OTHER_HIGH);
1916
1917 modulator->capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_RDS |
1918 V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_RDS_BLOCK_IO;
1919
1920 if (core->mode != WL1273_MODE_TX)
1921 return 0;
1922
1923 if (mutex_lock_interruptible(&core->lock))
1924 return -EINTR;
1925
1926 r = wl1273_fm_read_reg(core, WL1273_MONO_SET, &val);
1927 if (r)
1928 goto out;
1929
1930 if (val == WL1273_TX_STEREO)
1931 modulator->txsubchans = V4L2_TUNER_SUB_STEREO;
1932 else
1933 modulator->txsubchans = V4L2_TUNER_SUB_MONO;
1934
1935 if (radio->rds_on)
1936 modulator->txsubchans |= V4L2_TUNER_SUB_RDS;
1937out:
1938 mutex_unlock(&core->lock);
1939
1940 return 0;
1941}
1942
1943static int wl1273_fm_vidioc_log_status(struct file *file, void *priv)
1944{
1945 struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
1946 struct wl1273_core *core = radio->core;
1947 struct device *dev = radio->dev;
1948 u16 val;
1949 int r;
1950
1951 dev_info(dev, DRIVER_DESC);
1952
1953 if (core->mode == WL1273_MODE_OFF) {
1954 dev_info(dev, "Mode: Off\n");
1955 return 0;
1956 }
1957
1958 if (core->mode == WL1273_MODE_SUSPENDED) {
1959 dev_info(dev, "Mode: Suspended\n");
1960 return 0;
1961 }
1962
1963 r = wl1273_fm_read_reg(core, WL1273_ASIC_ID_GET, &val);
1964 if (r)
1965 dev_err(dev, "%s: Get ASIC_ID fails.\n", __func__);
1966 else
1967 dev_info(dev, "ASIC_ID: 0x%04x\n", val);
1968
1969 r = wl1273_fm_read_reg(core, WL1273_ASIC_VER_GET, &val);
1970 if (r)
1971 dev_err(dev, "%s: Get ASIC_VER fails.\n", __func__);
1972 else
1973 dev_info(dev, "ASIC Version: 0x%04x\n", val);
1974
1975 r = wl1273_fm_read_reg(core, WL1273_FIRM_VER_GET, &val);
1976 if (r)
1977 dev_err(dev, "%s: Get FIRM_VER fails.\n", __func__);
1978 else
1979 dev_info(dev, "FW version: %d(0x%04x)\n", val, val);
1980
1981 r = wl1273_fm_read_reg(core, WL1273_BAND_SET, &val);
1982 if (r)
1983 dev_err(dev, "%s: Get BAND fails.\n", __func__);
1984 else
1985 dev_info(dev, "BAND: %d\n", val);
1986
1987 if (core->mode == WL1273_MODE_TX) {
1988 r = wl1273_fm_read_reg(core, WL1273_PUPD_SET, &val);
1989 if (r)
1990 dev_err(dev, "%s: Get PUPD fails.\n", __func__);
1991 else
1992 dev_info(dev, "PUPD: 0x%04x\n", val);
1993
1994 r = wl1273_fm_read_reg(core, WL1273_CHANL_SET, &val);
1995 if (r)
1996 dev_err(dev, "%s: Get CHANL fails.\n", __func__);
1997 else
1998 dev_info(dev, "Tx frequency: %dkHz\n", val*10);
1999 } else if (core->mode == WL1273_MODE_RX) {
2000 int bf = radio->rangelow;
2001
2002 r = wl1273_fm_read_reg(core, WL1273_FREQ_SET, &val);
2003 if (r)
2004 dev_err(dev, "%s: Get FREQ fails.\n", __func__);
2005 else
2006 dev_info(dev, "RX Frequency: %dkHz\n", bf + val*50);
2007
2008 r = wl1273_fm_read_reg(core, WL1273_MOST_MODE_SET, &val);
2009 if (r)
2010 dev_err(dev, "%s: Get MOST_MODE fails.\n",
2011 __func__);
2012 else if (val == 0)
2013 dev_info(dev, "MOST_MODE: Stereo according to blend\n");
2014 else if (val == 1)
2015 dev_info(dev, "MOST_MODE: Force mono output\n");
2016 else
2017 dev_info(dev, "MOST_MODE: Unexpected value: %d\n", val);
2018
2019 r = wl1273_fm_read_reg(core, WL1273_MOST_BLEND_SET, &val);
2020 if (r)
2021 dev_err(dev, "%s: Get MOST_BLEND fails.\n", __func__);
2022 else if (val == 0)
2023 dev_info(dev,
2024 "MOST_BLEND: Switched blend & hysteresis.\n");
2025 else if (val == 1)
2026 dev_info(dev, "MOST_BLEND: Soft blend.\n");
2027 else
2028 dev_info(dev, "MOST_BLEND: Unexpected val: %d\n", val);
2029
2030 r = wl1273_fm_read_reg(core, WL1273_STEREO_GET, &val);
2031 if (r)
2032 dev_err(dev, "%s: Get STEREO fails.\n", __func__);
2033 else if (val == 0)
2034 dev_info(dev, "STEREO: Not detected\n");
2035 else if (val == 1)
2036 dev_info(dev, "STEREO: Detected\n");
2037 else
2038 dev_info(dev, "STEREO: Unexpected value: %d\n", val);
2039
2040 r = wl1273_fm_read_reg(core, WL1273_RSSI_LVL_GET, &val);
2041 if (r)
2042 dev_err(dev, "%s: Get RSSI_LVL fails.\n", __func__);
2043 else
2044 dev_info(dev, "RX signal strength: %d\n", (s16) val);
2045
2046 r = wl1273_fm_read_reg(core, WL1273_POWER_SET, &val);
2047 if (r)
2048 dev_err(dev, "%s: Get POWER fails.\n", __func__);
2049 else
2050 dev_info(dev, "POWER: 0x%04x\n", val);
2051
2052 r = wl1273_fm_read_reg(core, WL1273_INT_MASK_SET, &val);
2053 if (r)
2054 dev_err(dev, "%s: Get INT_MASK fails.\n", __func__);
2055 else
2056 dev_info(dev, "INT_MASK: 0x%04x\n", val);
2057
2058 r = wl1273_fm_read_reg(core, WL1273_RDS_SYNC_GET, &val);
2059 if (r)
2060 dev_err(dev, "%s: Get RDS_SYNC fails.\n",
2061 __func__);
2062 else if (val == 0)
2063 dev_info(dev, "RDS_SYNC: Not synchronized\n");
2064
2065 else if (val == 1)
2066 dev_info(dev, "RDS_SYNC: Synchronized\n");
2067 else
2068 dev_info(dev, "RDS_SYNC: Unexpected value: %d\n", val);
2069
2070 r = wl1273_fm_read_reg(core, WL1273_I2S_MODE_CONFIG_SET, &val);
2071 if (r)
2072 dev_err(dev, "%s: Get I2S_MODE_CONFIG fails.\n",
2073 __func__);
2074 else
2075 dev_info(dev, "I2S_MODE_CONFIG: 0x%04x\n", val);
2076
2077 r = wl1273_fm_read_reg(core, WL1273_VOLUME_SET, &val);
2078 if (r)
2079 dev_err(dev, "%s: Get VOLUME fails.\n", __func__);
2080 else
2081 dev_info(dev, "VOLUME: 0x%04x\n", val);
2082 }
2083
2084 return 0;
2085}
2086
2087static void wl1273_vdev_release(struct video_device *dev)
2088{
2089}
2090
2091static const struct v4l2_ctrl_ops wl1273_ctrl_ops = {
2092 .s_ctrl = wl1273_fm_vidioc_s_ctrl,
2093 .g_volatile_ctrl = wl1273_fm_g_volatile_ctrl,
2094};
2095
2096static const struct v4l2_ioctl_ops wl1273_ioctl_ops = {
2097 .vidioc_querycap = wl1273_fm_vidioc_querycap,
2098 .vidioc_g_input = wl1273_fm_vidioc_g_input,
2099 .vidioc_s_input = wl1273_fm_vidioc_s_input,
2100 .vidioc_g_audio = wl1273_fm_vidioc_g_audio,
2101 .vidioc_s_audio = wl1273_fm_vidioc_s_audio,
2102 .vidioc_g_tuner = wl1273_fm_vidioc_g_tuner,
2103 .vidioc_s_tuner = wl1273_fm_vidioc_s_tuner,
2104 .vidioc_g_frequency = wl1273_fm_vidioc_g_frequency,
2105 .vidioc_s_frequency = wl1273_fm_vidioc_s_frequency,
2106 .vidioc_s_hw_freq_seek = wl1273_fm_vidioc_s_hw_freq_seek,
2107 .vidioc_g_modulator = wl1273_fm_vidioc_g_modulator,
2108 .vidioc_s_modulator = wl1273_fm_vidioc_s_modulator,
2109 .vidioc_log_status = wl1273_fm_vidioc_log_status,
2110};
2111
2112static struct video_device wl1273_viddev_template = {
2113 .fops = &wl1273_fops,
2114 .ioctl_ops = &wl1273_ioctl_ops,
2115 .name = WL1273_FM_DRIVER_NAME,
2116 .release = wl1273_vdev_release,
2117};
2118
2119static int wl1273_fm_radio_remove(struct platform_device *pdev)
2120{
2121 struct wl1273_device *radio = platform_get_drvdata(pdev);
2122 struct wl1273_core *core = radio->core;
2123
2124 dev_info(&pdev->dev, "%s.\n", __func__);
2125
2126 free_irq(core->client->irq, radio);
2127 core->pdata->free_resources();
2128
2129 v4l2_ctrl_handler_free(&radio->ctrl_handler);
2130 video_unregister_device(&radio->videodev);
2131 v4l2_device_unregister(&radio->v4l2dev);
2132 kfree(radio->buffer);
2133 kfree(radio->write_buf);
2134 kfree(radio);
2135
2136 return 0;
2137}
2138
2139static int __devinit wl1273_fm_radio_probe(struct platform_device *pdev)
2140{
2141 struct wl1273_core **core = pdev->dev.platform_data;
2142 struct wl1273_device *radio;
2143 struct v4l2_ctrl *ctrl;
2144 int r = 0;
2145
2146 pr_debug("%s\n", __func__);
2147
2148 if (!core) {
2149 dev_err(&pdev->dev, "No platform data.\n");
2150 r = -EINVAL;
2151 goto pdata_err;
2152 }
2153
2154 radio = kzalloc(sizeof(*radio), GFP_KERNEL);
2155 if (!radio) {
2156 r = -ENOMEM;
2157 goto pdata_err;
2158 }
2159
2160 /* RDS buffer allocation */
2161 radio->buf_size = rds_buf * RDS_BLOCK_SIZE;
2162 radio->buffer = kmalloc(radio->buf_size, GFP_KERNEL);
2163 if (!radio->buffer) {
2164 pr_err("Cannot allocate memory for RDS buffer.\n");
2165 r = -ENOMEM;
2166 goto err_kmalloc;
2167 }
2168
2169 radio->core = *core;
2170 radio->irq_flags = WL1273_IRQ_MASK;
2171 radio->dev = &radio->core->client->dev;
2172 radio->rds_on = false;
2173 radio->core->mode = WL1273_MODE_OFF;
2174 radio->tx_power = 118;
2175 radio->core->audio_mode = WL1273_AUDIO_ANALOG;
2176 radio->band = WL1273_BAND_OTHER;
2177 radio->core->i2s_mode = WL1273_I2S_DEF_MODE;
2178 radio->core->channel_number = 2;
2179 radio->core->volume = WL1273_DEFAULT_VOLUME;
2180 radio->rx_frequency = WL1273_BAND_OTHER_LOW;
2181 radio->tx_frequency = WL1273_BAND_OTHER_HIGH;
2182 radio->rangelow = WL1273_BAND_OTHER_LOW;
2183 radio->rangehigh = WL1273_BAND_OTHER_HIGH;
2184 radio->stereo = true;
2185 radio->bus_type = "I2C";
2186
2187 radio->core->write = wl1273_fm_write_cmd;
2188 radio->core->set_audio = wl1273_fm_set_audio;
2189 radio->core->set_volume = wl1273_fm_set_volume;
2190
2191 if (radio->core->pdata->request_resources) {
2192 r = radio->core->pdata->request_resources(radio->core->client);
2193 if (r) {
2194 dev_err(radio->dev, WL1273_FM_DRIVER_NAME
2195 ": Cannot get platform data\n");
2196 goto err_resources;
2197 }
2198
2199 dev_dbg(radio->dev, "irq: %d\n", radio->core->client->irq);
2200
2201 r = request_threaded_irq(radio->core->client->irq, NULL,
2202 wl1273_fm_irq_thread_handler,
2203 IRQF_ONESHOT | IRQF_TRIGGER_FALLING,
2204 "wl1273-fm", radio);
2205 if (r < 0) {
2206 dev_err(radio->dev, WL1273_FM_DRIVER_NAME
2207 ": Unable to register IRQ handler: %d\n", r);
2208 goto err_request_irq;
2209 }
2210 } else {
2211 dev_err(radio->dev, WL1273_FM_DRIVER_NAME ": Core WL1273 IRQ"
2212 " not configured");
2213 r = -EINVAL;
2214 goto err_resources;
2215 }
2216
2217 init_completion(&radio->busy);
2218 init_waitqueue_head(&radio->read_queue);
2219
2220 radio->write_buf = kmalloc(256, GFP_KERNEL);
2221 if (!radio->write_buf) {
2222 r = -ENOMEM;
2223 goto write_buf_err;
2224 }
2225
2226 radio->dev = &pdev->dev;
2227 radio->v4l2dev.ctrl_handler = &radio->ctrl_handler;
2228 radio->rds_users = 0;
2229
2230 r = v4l2_device_register(&pdev->dev, &radio->v4l2dev);
2231 if (r) {
2232 dev_err(&pdev->dev, "Cannot register v4l2_device.\n");
2233 goto device_register_err;
2234 }
2235
2236 /* V4L2 configuration */
2237 memcpy(&radio->videodev, &wl1273_viddev_template,
2238 sizeof(wl1273_viddev_template));
2239
2240 radio->videodev.v4l2_dev = &radio->v4l2dev;
2241
2242 v4l2_ctrl_handler_init(&radio->ctrl_handler, 6);
2243
2244 /* add in ascending ID order */
2245 v4l2_ctrl_new_std(&radio->ctrl_handler, &wl1273_ctrl_ops,
2246 V4L2_CID_AUDIO_VOLUME, 0, WL1273_MAX_VOLUME, 1,
2247 WL1273_DEFAULT_VOLUME);
2248
2249 v4l2_ctrl_new_std(&radio->ctrl_handler, &wl1273_ctrl_ops,
2250 V4L2_CID_AUDIO_MUTE, 0, 1, 1, 1);
2251
2252 v4l2_ctrl_new_std_menu(&radio->ctrl_handler, &wl1273_ctrl_ops,
2253 V4L2_CID_TUNE_PREEMPHASIS,
2254 V4L2_PREEMPHASIS_75_uS, 0x03,
2255 V4L2_PREEMPHASIS_50_uS);
2256
2257 v4l2_ctrl_new_std(&radio->ctrl_handler, &wl1273_ctrl_ops,
2258 V4L2_CID_TUNE_POWER_LEVEL, 91, 122, 1, 118);
2259
2260 ctrl = v4l2_ctrl_new_std(&radio->ctrl_handler, &wl1273_ctrl_ops,
2261 V4L2_CID_TUNE_ANTENNA_CAPACITOR,
2262 0, 255, 1, 255);
2263 if (ctrl)
2264 ctrl->is_volatile = 1;
2265
2266 if (radio->ctrl_handler.error) {
2267 r = radio->ctrl_handler.error;
2268 dev_err(&pdev->dev, "Ctrl handler error: %d\n", r);
2269 goto handler_init_err;
2270 }
2271
2272 video_set_drvdata(&radio->videodev, radio);
2273 platform_set_drvdata(pdev, radio);
2274
2275 /* register video device */
2276 r = video_register_device(&radio->videodev, VFL_TYPE_RADIO, radio_nr);
2277 if (r) {
2278 dev_err(&pdev->dev, WL1273_FM_DRIVER_NAME
2279 ": Could not register video device\n");
2280 goto handler_init_err;
2281 }
2282
2283 return 0;
2284
2285handler_init_err:
2286 v4l2_ctrl_handler_free(&radio->ctrl_handler);
2287 v4l2_device_unregister(&radio->v4l2dev);
2288device_register_err:
2289 kfree(radio->write_buf);
2290write_buf_err:
2291 free_irq(radio->core->client->irq, radio);
2292err_request_irq:
2293 radio->core->pdata->free_resources();
2294err_resources:
2295 kfree(radio->buffer);
2296err_kmalloc:
2297 kfree(radio);
2298pdata_err:
2299 return r;
2300}
2301
2302MODULE_ALIAS("platform:wl1273_fm_radio");
2303
2304static struct platform_driver wl1273_fm_radio_driver = {
2305 .probe = wl1273_fm_radio_probe,
2306 .remove = __devexit_p(wl1273_fm_radio_remove),
2307 .driver = {
2308 .name = "wl1273_fm_radio",
2309 .owner = THIS_MODULE,
2310 },
2311};
2312
2313static int __init wl1273_fm_module_init(void)
2314{
2315 pr_info("%s\n", __func__);
2316 return platform_driver_register(&wl1273_fm_radio_driver);
2317}
2318module_init(wl1273_fm_module_init);
2319
2320static void __exit wl1273_fm_module_exit(void)
2321{
2322 flush_scheduled_work();
2323 platform_driver_unregister(&wl1273_fm_radio_driver);
2324 pr_info(DRIVER_DESC ", Exiting.\n");
2325}
2326module_exit(wl1273_fm_module_exit);
2327
2328MODULE_AUTHOR("Matti Aaltonen <matti.j.aaltonen@nokia.com>");
2329MODULE_DESCRIPTION(DRIVER_DESC);
2330MODULE_LICENSE("GPL");
diff --git a/drivers/media/radio/si470x/radio-si470x.h b/drivers/media/radio/si470x/radio-si470x.h
index b9914d7a0c9f..4a4e908db04c 100644
--- a/drivers/media/radio/si470x/radio-si470x.h
+++ b/drivers/media/radio/si470x/radio-si470x.h
@@ -37,7 +37,6 @@
37#include <linux/mutex.h> 37#include <linux/mutex.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#include <media/rds.h>
41#include <asm/unaligned.h> 40#include <asm/unaligned.h>
42 41
43 42
diff --git a/drivers/media/radio/si4713-i2c.c b/drivers/media/radio/si4713-i2c.c
index a6e6f1987a3a..0fab6f8f7e24 100644
--- a/drivers/media/radio/si4713-i2c.c
+++ b/drivers/media/radio/si4713-i2c.c
@@ -27,6 +27,8 @@
27#include <linux/interrupt.h> 27#include <linux/interrupt.h>
28#include <linux/i2c.h> 28#include <linux/i2c.h>
29#include <linux/slab.h> 29#include <linux/slab.h>
30#include <linux/gpio.h>
31#include <linux/regulator/consumer.h>
30#include <media/v4l2-device.h> 32#include <media/v4l2-device.h>
31#include <media/v4l2-ioctl.h> 33#include <media/v4l2-ioctl.h>
32#include <media/v4l2-common.h> 34#include <media/v4l2-common.h>
@@ -43,6 +45,11 @@ MODULE_AUTHOR("Eduardo Valentin <eduardo.valentin@nokia.com>");
43MODULE_DESCRIPTION("I2C driver for Si4713 FM Radio Transmitter"); 45MODULE_DESCRIPTION("I2C driver for Si4713 FM Radio Transmitter");
44MODULE_VERSION("0.0.1"); 46MODULE_VERSION("0.0.1");
45 47
48static const char *si4713_supply_names[SI4713_NUM_SUPPLIES] = {
49 "vio",
50 "vdd",
51};
52
46#define DEFAULT_RDS_PI 0x00 53#define DEFAULT_RDS_PI 0x00
47#define DEFAULT_RDS_PTY 0x00 54#define DEFAULT_RDS_PTY 0x00
48#define DEFAULT_RDS_PS_NAME "" 55#define DEFAULT_RDS_PS_NAME ""
@@ -369,7 +376,17 @@ static int si4713_powerup(struct si4713_device *sdev)
369 if (sdev->power_state) 376 if (sdev->power_state)
370 return 0; 377 return 0;
371 378
372 sdev->platform_data->set_power(1); 379 err = regulator_bulk_enable(ARRAY_SIZE(sdev->supplies),
380 sdev->supplies);
381 if (err) {
382 v4l2_err(&sdev->sd, "Failed to enable supplies: %d\n", err);
383 return err;
384 }
385 if (gpio_is_valid(sdev->gpio_reset)) {
386 udelay(50);
387 gpio_set_value(sdev->gpio_reset, 1);
388 }
389
373 err = si4713_send_command(sdev, SI4713_CMD_POWER_UP, 390 err = si4713_send_command(sdev, SI4713_CMD_POWER_UP,
374 args, ARRAY_SIZE(args), 391 args, ARRAY_SIZE(args),
375 resp, ARRAY_SIZE(resp), 392 resp, ARRAY_SIZE(resp),
@@ -384,7 +401,13 @@ static int si4713_powerup(struct si4713_device *sdev)
384 err = si4713_write_property(sdev, SI4713_GPO_IEN, 401 err = si4713_write_property(sdev, SI4713_GPO_IEN,
385 SI4713_STC_INT | SI4713_CTS); 402 SI4713_STC_INT | SI4713_CTS);
386 } else { 403 } else {
387 sdev->platform_data->set_power(0); 404 if (gpio_is_valid(sdev->gpio_reset))
405 gpio_set_value(sdev->gpio_reset, 0);
406 err = regulator_bulk_disable(ARRAY_SIZE(sdev->supplies),
407 sdev->supplies);
408 if (err)
409 v4l2_err(&sdev->sd,
410 "Failed to disable supplies: %d\n", err);
388 } 411 }
389 412
390 return err; 413 return err;
@@ -411,7 +434,13 @@ static int si4713_powerdown(struct si4713_device *sdev)
411 v4l2_dbg(1, debug, &sdev->sd, "Power down response: 0x%02x\n", 434 v4l2_dbg(1, debug, &sdev->sd, "Power down response: 0x%02x\n",
412 resp[0]); 435 resp[0]);
413 v4l2_dbg(1, debug, &sdev->sd, "Device in reset mode\n"); 436 v4l2_dbg(1, debug, &sdev->sd, "Device in reset mode\n");
414 sdev->platform_data->set_power(0); 437 if (gpio_is_valid(sdev->gpio_reset))
438 gpio_set_value(sdev->gpio_reset, 0);
439 err = regulator_bulk_disable(ARRAY_SIZE(sdev->supplies),
440 sdev->supplies);
441 if (err)
442 v4l2_err(&sdev->sd,
443 "Failed to disable supplies: %d\n", err);
415 sdev->power_state = POWER_OFF; 444 sdev->power_state = POWER_OFF;
416 } 445 }
417 446
@@ -1967,7 +1996,8 @@ static int si4713_probe(struct i2c_client *client,
1967 const struct i2c_device_id *id) 1996 const struct i2c_device_id *id)
1968{ 1997{
1969 struct si4713_device *sdev; 1998 struct si4713_device *sdev;
1970 int rval; 1999 struct si4713_platform_data *pdata = client->dev.platform_data;
2000 int rval, i;
1971 2001
1972 sdev = kzalloc(sizeof *sdev, GFP_KERNEL); 2002 sdev = kzalloc(sizeof *sdev, GFP_KERNEL);
1973 if (!sdev) { 2003 if (!sdev) {
@@ -1976,11 +2006,26 @@ static int si4713_probe(struct i2c_client *client,
1976 goto exit; 2006 goto exit;
1977 } 2007 }
1978 2008
1979 sdev->platform_data = client->dev.platform_data; 2009 sdev->gpio_reset = -1;
1980 if (!sdev->platform_data) { 2010 if (pdata && gpio_is_valid(pdata->gpio_reset)) {
1981 v4l2_err(&sdev->sd, "No platform data registered.\n"); 2011 rval = gpio_request(pdata->gpio_reset, "si4713 reset");
1982 rval = -ENODEV; 2012 if (rval) {
1983 goto free_sdev; 2013 dev_err(&client->dev,
2014 "Failed to request gpio: %d\n", rval);
2015 goto free_sdev;
2016 }
2017 sdev->gpio_reset = pdata->gpio_reset;
2018 gpio_direction_output(sdev->gpio_reset, 0);
2019 }
2020
2021 for (i = 0; i < ARRAY_SIZE(sdev->supplies); i++)
2022 sdev->supplies[i].supply = si4713_supply_names[i];
2023
2024 rval = regulator_bulk_get(&client->dev, ARRAY_SIZE(sdev->supplies),
2025 sdev->supplies);
2026 if (rval) {
2027 dev_err(&client->dev, "Cannot get regulators: %d\n", rval);
2028 goto free_gpio;
1984 } 2029 }
1985 2030
1986 v4l2_i2c_subdev_init(&sdev->sd, client, &si4713_subdev_ops); 2031 v4l2_i2c_subdev_init(&sdev->sd, client, &si4713_subdev_ops);
@@ -1994,7 +2039,7 @@ static int si4713_probe(struct i2c_client *client,
1994 client->name, sdev); 2039 client->name, sdev);
1995 if (rval < 0) { 2040 if (rval < 0) {
1996 v4l2_err(&sdev->sd, "Could not request IRQ\n"); 2041 v4l2_err(&sdev->sd, "Could not request IRQ\n");
1997 goto free_sdev; 2042 goto put_reg;
1998 } 2043 }
1999 v4l2_dbg(1, debug, &sdev->sd, "IRQ requested.\n"); 2044 v4l2_dbg(1, debug, &sdev->sd, "IRQ requested.\n");
2000 } else { 2045 } else {
@@ -2012,6 +2057,11 @@ static int si4713_probe(struct i2c_client *client,
2012free_irq: 2057free_irq:
2013 if (client->irq) 2058 if (client->irq)
2014 free_irq(client->irq, sdev); 2059 free_irq(client->irq, sdev);
2060put_reg:
2061 regulator_bulk_free(ARRAY_SIZE(sdev->supplies), sdev->supplies);
2062free_gpio:
2063 if (gpio_is_valid(sdev->gpio_reset))
2064 gpio_free(sdev->gpio_reset);
2015free_sdev: 2065free_sdev:
2016 kfree(sdev); 2066 kfree(sdev);
2017exit: 2067exit:
@@ -2031,7 +2081,9 @@ static int si4713_remove(struct i2c_client *client)
2031 free_irq(client->irq, sdev); 2081 free_irq(client->irq, sdev);
2032 2082
2033 v4l2_device_unregister_subdev(sd); 2083 v4l2_device_unregister_subdev(sd);
2034 2084 regulator_bulk_free(ARRAY_SIZE(sdev->supplies), sdev->supplies);
2085 if (gpio_is_valid(sdev->gpio_reset))
2086 gpio_free(sdev->gpio_reset);
2035 kfree(sdev); 2087 kfree(sdev);
2036 2088
2037 return 0; 2089 return 0;
diff --git a/drivers/media/radio/si4713-i2c.h b/drivers/media/radio/si4713-i2c.h
index faf8cff124f1..c6dfa7fb101c 100644
--- a/drivers/media/radio/si4713-i2c.h
+++ b/drivers/media/radio/si4713-i2c.h
@@ -211,6 +211,8 @@ struct acomp_info {
211 u32 enabled; 211 u32 enabled;
212}; 212};
213 213
214#define SI4713_NUM_SUPPLIES 2
215
214/* 216/*
215 * si4713_device - private data 217 * si4713_device - private data
216 */ 218 */
@@ -220,11 +222,12 @@ struct si4713_device {
220 /* private data structures */ 222 /* private data structures */
221 struct mutex mutex; 223 struct mutex mutex;
222 struct completion work; 224 struct completion work;
223 struct si4713_platform_data *platform_data;
224 struct rds_info rds_info; 225 struct rds_info rds_info;
225 struct limiter_info limiter_info; 226 struct limiter_info limiter_info;
226 struct pilot_info pilot_info; 227 struct pilot_info pilot_info;
227 struct acomp_info acomp_info; 228 struct acomp_info acomp_info;
229 struct regulator_bulk_data supplies[SI4713_NUM_SUPPLIES];
230 int gpio_reset;
228 u32 frequency; 231 u32 frequency;
229 u32 preemphasis; 232 u32 preemphasis;
230 u32 mute; 233 u32 mute;
diff --git a/drivers/media/IR/Kconfig b/drivers/media/rc/Kconfig
index aa4163eb7a83..3785162f928e 100644
--- a/drivers/media/IR/Kconfig
+++ b/drivers/media/rc/Kconfig
@@ -1,21 +1,17 @@
1menuconfig IR_CORE 1menuconfig RC_CORE
2 tristate "Infrared remote controller adapters" 2 tristate "Remote Controller adapters"
3 depends on INPUT 3 depends on INPUT
4 default INPUT 4 default INPUT
5 ---help--- 5 ---help---
6 Enable support for Remote Controllers on Linux. This is 6 Enable support for Remote Controllers on Linux. This is
7 needed in order to support several video capture adapters. 7 needed in order to support several video capture adapters.
8 Currently, all supported devices use InfraRed.
8 9
9 Enable this option if you have a video capture board even 10 Enable this option if you have a video capture board even
10 if you don't need IR, as otherwise, you may not be able to 11 if you don't need IR, as otherwise, you may not be able to
11 compile the driver for your adapter. 12 compile the driver for your adapter.
12 13
13config VIDEO_IR 14if RC_CORE
14 tristate
15 depends on IR_CORE
16 default IR_CORE
17
18if IR_CORE
19 15
20config LIRC 16config LIRC
21 tristate 17 tristate
@@ -28,11 +24,11 @@ config LIRC
28 LIRC daemon handles protocol decoding for IR reception and 24 LIRC daemon handles protocol decoding for IR reception and
29 encoding for IR transmitting (aka "blasting"). 25 encoding for IR transmitting (aka "blasting").
30 26
31source "drivers/media/IR/keymaps/Kconfig" 27source "drivers/media/rc/keymaps/Kconfig"
32 28
33config IR_NEC_DECODER 29config IR_NEC_DECODER
34 tristate "Enable IR raw decoder for the NEC protocol" 30 tristate "Enable IR raw decoder for the NEC protocol"
35 depends on IR_CORE 31 depends on RC_CORE
36 select BITREVERSE 32 select BITREVERSE
37 default y 33 default y
38 34
@@ -42,7 +38,7 @@ config IR_NEC_DECODER
42 38
43config IR_RC5_DECODER 39config IR_RC5_DECODER
44 tristate "Enable IR raw decoder for the RC-5 protocol" 40 tristate "Enable IR raw decoder for the RC-5 protocol"
45 depends on IR_CORE 41 depends on RC_CORE
46 select BITREVERSE 42 select BITREVERSE
47 default y 43 default y
48 44
@@ -52,7 +48,7 @@ config IR_RC5_DECODER
52 48
53config IR_RC6_DECODER 49config IR_RC6_DECODER
54 tristate "Enable IR raw decoder for the RC6 protocol" 50 tristate "Enable IR raw decoder for the RC6 protocol"
55 depends on IR_CORE 51 depends on RC_CORE
56 select BITREVERSE 52 select BITREVERSE
57 default y 53 default y
58 54
@@ -62,7 +58,7 @@ config IR_RC6_DECODER
62 58
63config IR_JVC_DECODER 59config IR_JVC_DECODER
64 tristate "Enable IR raw decoder for the JVC protocol" 60 tristate "Enable IR raw decoder for the JVC protocol"
65 depends on IR_CORE 61 depends on RC_CORE
66 select BITREVERSE 62 select BITREVERSE
67 default y 63 default y
68 64
@@ -72,7 +68,7 @@ config IR_JVC_DECODER
72 68
73config IR_SONY_DECODER 69config IR_SONY_DECODER
74 tristate "Enable IR raw decoder for the Sony protocol" 70 tristate "Enable IR raw decoder for the Sony protocol"
75 depends on IR_CORE 71 depends on RC_CORE
76 default y 72 default y
77 73
78 ---help--- 74 ---help---
@@ -81,7 +77,7 @@ config IR_SONY_DECODER
81 77
82config IR_RC5_SZ_DECODER 78config IR_RC5_SZ_DECODER
83 tristate "Enable IR raw decoder for the RC-5 (streamzap) protocol" 79 tristate "Enable IR raw decoder for the RC-5 (streamzap) protocol"
84 depends on IR_CORE 80 depends on RC_CORE
85 select BITREVERSE 81 select BITREVERSE
86 default y 82 default y
87 83
@@ -93,7 +89,7 @@ config IR_RC5_SZ_DECODER
93 89
94config IR_LIRC_CODEC 90config IR_LIRC_CODEC
95 tristate "Enable IR to LIRC bridge" 91 tristate "Enable IR to LIRC bridge"
96 depends on IR_CORE 92 depends on RC_CORE
97 depends on LIRC 93 depends on LIRC
98 default y 94 default y
99 95
@@ -104,7 +100,7 @@ config IR_LIRC_CODEC
104config IR_ENE 100config IR_ENE
105 tristate "ENE eHome Receiver/Transceiver (pnp id: ENE0100/ENE02xxx)" 101 tristate "ENE eHome Receiver/Transceiver (pnp id: ENE0100/ENE02xxx)"
106 depends on PNP 102 depends on PNP
107 depends on IR_CORE 103 depends on RC_CORE
108 ---help--- 104 ---help---
109 Say Y here to enable support for integrated infrared receiver 105 Say Y here to enable support for integrated infrared receiver
110 /transceiver made by ENE. 106 /transceiver made by ENE.
@@ -118,7 +114,7 @@ config IR_ENE
118config IR_IMON 114config IR_IMON
119 tristate "SoundGraph iMON Receiver and Display" 115 tristate "SoundGraph iMON Receiver and Display"
120 depends on USB_ARCH_HAS_HCD 116 depends on USB_ARCH_HAS_HCD
121 depends on IR_CORE 117 depends on RC_CORE
122 select USB 118 select USB
123 ---help--- 119 ---help---
124 Say Y here if you want to use a SoundGraph iMON (aka Antec Veris) 120 Say Y here if you want to use a SoundGraph iMON (aka Antec Veris)
@@ -130,7 +126,7 @@ config IR_IMON
130config IR_MCEUSB 126config IR_MCEUSB
131 tristate "Windows Media Center Ed. eHome Infrared Transceiver" 127 tristate "Windows Media Center Ed. eHome Infrared Transceiver"
132 depends on USB_ARCH_HAS_HCD 128 depends on USB_ARCH_HAS_HCD
133 depends on IR_CORE 129 depends on RC_CORE
134 select USB 130 select USB
135 ---help--- 131 ---help---
136 Say Y here if you want to use a Windows Media Center Edition 132 Say Y here if you want to use a Windows Media Center Edition
@@ -142,7 +138,7 @@ config IR_MCEUSB
142config IR_NUVOTON 138config IR_NUVOTON
143 tristate "Nuvoton w836x7hg Consumer Infrared Transceiver" 139 tristate "Nuvoton w836x7hg Consumer Infrared Transceiver"
144 depends on PNP 140 depends on PNP
145 depends on IR_CORE 141 depends on RC_CORE
146 ---help--- 142 ---help---
147 Say Y here to enable support for integrated infrared receiver 143 Say Y here to enable support for integrated infrared receiver
148 /transciever made by Nuvoton (formerly Winbond). This chip is 144 /transciever made by Nuvoton (formerly Winbond). This chip is
@@ -155,7 +151,7 @@ config IR_NUVOTON
155config IR_STREAMZAP 151config IR_STREAMZAP
156 tristate "Streamzap PC Remote IR Receiver" 152 tristate "Streamzap PC Remote IR Receiver"
157 depends on USB_ARCH_HAS_HCD 153 depends on USB_ARCH_HAS_HCD
158 depends on IR_CORE 154 depends on RC_CORE
159 select USB 155 select USB
160 ---help--- 156 ---help---
161 Say Y here if you want to use a Streamzap PC Remote 157 Say Y here if you want to use a Streamzap PC Remote
@@ -164,4 +160,34 @@ config IR_STREAMZAP
164 To compile this driver as a module, choose M here: the 160 To compile this driver as a module, choose M here: the
165 module will be called streamzap. 161 module will be called streamzap.
166 162
167endif #IR_CORE 163config IR_WINBOND_CIR
164 tristate "Winbond IR remote control"
165 depends on X86 && PNP
166 depends on RC_CORE
167 select NEW_LEDS
168 select LEDS_CLASS
169 select LEDS_TRIGGERS
170 select BITREVERSE
171 ---help---
172 Say Y here if you want to use the IR remote functionality found
173 in some Winbond SuperI/O chips. Currently only the WPCD376I
174 chip is supported (included in some Intel Media series
175 motherboards).
176
177 To compile this driver as a module, choose M here: the module will
178 be called winbond_cir.
179
180config RC_LOOPBACK
181 tristate "Remote Control Loopback Driver"
182 depends on RC_CORE
183 ---help---
184 Say Y here if you want support for the remote control loopback
185 driver which allows TX data to be sent back as RX data.
186 This is mostly useful for debugging purposes.
187
188 If you're not sure, select N here.
189
190 To compile this driver as a module, choose M here: the module will
191 be called rc_loopback.
192
193endif #RC_CORE
diff --git a/drivers/media/IR/Makefile b/drivers/media/rc/Makefile
index f9574adab82a..67b4f7fe2577 100644
--- a/drivers/media/IR/Makefile
+++ b/drivers/media/rc/Makefile
@@ -1,10 +1,8 @@
1ir-common-objs := ir-functions.o 1rc-core-objs := rc-main.o ir-raw.o
2ir-core-objs := ir-keytable.o ir-sysfs.o ir-raw-event.o rc-map.o
3 2
4obj-y += keymaps/ 3obj-y += keymaps/
5 4
6obj-$(CONFIG_IR_CORE) += ir-core.o 5obj-$(CONFIG_RC_CORE) += rc-core.o
7obj-$(CONFIG_VIDEO_IR) += ir-common.o
8obj-$(CONFIG_LIRC) += lirc_dev.o 6obj-$(CONFIG_LIRC) += lirc_dev.o
9obj-$(CONFIG_IR_NEC_DECODER) += ir-nec-decoder.o 7obj-$(CONFIG_IR_NEC_DECODER) += ir-nec-decoder.o
10obj-$(CONFIG_IR_RC5_DECODER) += ir-rc5-decoder.o 8obj-$(CONFIG_IR_RC5_DECODER) += ir-rc5-decoder.o
@@ -20,3 +18,5 @@ obj-$(CONFIG_IR_MCEUSB) += mceusb.o
20obj-$(CONFIG_IR_NUVOTON) += nuvoton-cir.o 18obj-$(CONFIG_IR_NUVOTON) += nuvoton-cir.o
21obj-$(CONFIG_IR_ENE) += ene_ir.o 19obj-$(CONFIG_IR_ENE) += ene_ir.o
22obj-$(CONFIG_IR_STREAMZAP) += streamzap.o 20obj-$(CONFIG_IR_STREAMZAP) += streamzap.o
21obj-$(CONFIG_IR_WINBOND_CIR) += winbond-cir.o
22obj-$(CONFIG_RC_LOOPBACK) += rc-loopback.o
diff --git a/drivers/media/IR/ene_ir.c b/drivers/media/rc/ene_ir.c
index 7637babcd262..80b3c319f698 100644
--- a/drivers/media/IR/ene_ir.c
+++ b/drivers/media/rc/ene_ir.c
@@ -37,9 +37,7 @@
37#include <linux/interrupt.h> 37#include <linux/interrupt.h>
38#include <linux/sched.h> 38#include <linux/sched.h>
39#include <linux/slab.h> 39#include <linux/slab.h>
40#include <linux/input.h> 40#include <media/rc-core.h>
41#include <media/ir-core.h>
42#include <media/ir-common.h>
43#include "ene_ir.h" 41#include "ene_ir.h"
44 42
45static int sample_period; 43static int sample_period;
@@ -357,7 +355,7 @@ void ene_rx_sense_carrier(struct ene_device *dev)
357 ev.carrier_report = true; 355 ev.carrier_report = true;
358 ev.carrier = carrier; 356 ev.carrier = carrier;
359 ev.duty_cycle = duty_cycle; 357 ev.duty_cycle = duty_cycle;
360 ir_raw_event_store(dev->idev, &ev); 358 ir_raw_event_store(dev->rdev, &ev);
361 } 359 }
362} 360}
363 361
@@ -448,32 +446,32 @@ static void ene_rx_setup(struct ene_device *dev)
448 446
449select_timeout: 447select_timeout:
450 if (dev->rx_fan_input_inuse) { 448 if (dev->rx_fan_input_inuse) {
451 dev->props->rx_resolution = MS_TO_NS(ENE_FW_SAMPLE_PERIOD_FAN); 449 dev->rdev->rx_resolution = MS_TO_NS(ENE_FW_SAMPLE_PERIOD_FAN);
452 450
453 /* Fan input doesn't support timeouts, it just ends the 451 /* Fan input doesn't support timeouts, it just ends the
454 input with a maximum sample */ 452 input with a maximum sample */
455 dev->props->min_timeout = dev->props->max_timeout = 453 dev->rdev->min_timeout = dev->rdev->max_timeout =
456 MS_TO_NS(ENE_FW_SMPL_BUF_FAN_MSK * 454 MS_TO_NS(ENE_FW_SMPL_BUF_FAN_MSK *
457 ENE_FW_SAMPLE_PERIOD_FAN); 455 ENE_FW_SAMPLE_PERIOD_FAN);
458 } else { 456 } else {
459 dev->props->rx_resolution = MS_TO_NS(sample_period); 457 dev->rdev->rx_resolution = MS_TO_NS(sample_period);
460 458
461 /* Theoreticly timeout is unlimited, but we cap it 459 /* Theoreticly timeout is unlimited, but we cap it
462 * because it was seen that on one device, it 460 * because it was seen that on one device, it
463 * would stop sending spaces after around 250 msec. 461 * would stop sending spaces after around 250 msec.
464 * Besides, this is close to 2^32 anyway and timeout is u32. 462 * Besides, this is close to 2^32 anyway and timeout is u32.
465 */ 463 */
466 dev->props->min_timeout = MS_TO_NS(127 * sample_period); 464 dev->rdev->min_timeout = MS_TO_NS(127 * sample_period);
467 dev->props->max_timeout = MS_TO_NS(200000); 465 dev->rdev->max_timeout = MS_TO_NS(200000);
468 } 466 }
469 467
470 if (dev->hw_learning_and_tx_capable) 468 if (dev->hw_learning_and_tx_capable)
471 dev->props->tx_resolution = MS_TO_NS(sample_period); 469 dev->rdev->tx_resolution = MS_TO_NS(sample_period);
472 470
473 if (dev->props->timeout > dev->props->max_timeout) 471 if (dev->rdev->timeout > dev->rdev->max_timeout)
474 dev->props->timeout = dev->props->max_timeout; 472 dev->rdev->timeout = dev->rdev->max_timeout;
475 if (dev->props->timeout < dev->props->min_timeout) 473 if (dev->rdev->timeout < dev->rdev->min_timeout)
476 dev->props->timeout = dev->props->min_timeout; 474 dev->rdev->timeout = dev->rdev->min_timeout;
477} 475}
478 476
479/* Enable the device for receive */ 477/* Enable the device for receive */
@@ -504,7 +502,7 @@ static void ene_rx_enable(struct ene_device *dev)
504 ene_set_reg_mask(dev, ENE_FW1, ENE_FW1_ENABLE | ENE_FW1_IRQ); 502 ene_set_reg_mask(dev, ENE_FW1, ENE_FW1_ENABLE | ENE_FW1_IRQ);
505 503
506 /* enter idle mode */ 504 /* enter idle mode */
507 ir_raw_event_set_idle(dev->idev, true); 505 ir_raw_event_set_idle(dev->rdev, true);
508 dev->rx_enabled = true; 506 dev->rx_enabled = true;
509} 507}
510 508
@@ -518,7 +516,7 @@ static void ene_rx_disable(struct ene_device *dev)
518 /* disable hardware IRQ and firmware flag */ 516 /* disable hardware IRQ and firmware flag */
519 ene_clear_reg_mask(dev, ENE_FW1, ENE_FW1_ENABLE | ENE_FW1_IRQ); 517 ene_clear_reg_mask(dev, ENE_FW1, ENE_FW1_ENABLE | ENE_FW1_IRQ);
520 518
521 ir_raw_event_set_idle(dev->idev, true); 519 ir_raw_event_set_idle(dev->rdev, true);
522 dev->rx_enabled = false; 520 dev->rx_enabled = false;
523} 521}
524 522
@@ -805,10 +803,10 @@ static irqreturn_t ene_isr(int irq, void *data)
805 803
806 ev.duration = MS_TO_NS(hw_sample); 804 ev.duration = MS_TO_NS(hw_sample);
807 ev.pulse = pulse; 805 ev.pulse = pulse;
808 ir_raw_event_store_with_filter(dev->idev, &ev); 806 ir_raw_event_store_with_filter(dev->rdev, &ev);
809 } 807 }
810 808
811 ir_raw_event_handle(dev->idev); 809 ir_raw_event_handle(dev->rdev);
812unlock: 810unlock:
813 spin_unlock_irqrestore(&dev->hw_lock, flags); 811 spin_unlock_irqrestore(&dev->hw_lock, flags);
814 return retval; 812 return retval;
@@ -823,7 +821,7 @@ static void ene_setup_default_settings(struct ene_device *dev)
823 dev->learning_mode_enabled = learning_mode_force; 821 dev->learning_mode_enabled = learning_mode_force;
824 822
825 /* Set reasonable default timeout */ 823 /* Set reasonable default timeout */
826 dev->props->timeout = MS_TO_NS(150000); 824 dev->rdev->timeout = MS_TO_NS(150000);
827} 825}
828 826
829/* Upload all hardware settings at once. Used at load and resume time */ 827/* Upload all hardware settings at once. Used at load and resume time */
@@ -838,9 +836,9 @@ static void ene_setup_hw_settings(struct ene_device *dev)
838} 836}
839 837
840/* outside interface: called on first open*/ 838/* outside interface: called on first open*/
841static int ene_open(void *data) 839static int ene_open(struct rc_dev *rdev)
842{ 840{
843 struct ene_device *dev = (struct ene_device *)data; 841 struct ene_device *dev = rdev->priv;
844 unsigned long flags; 842 unsigned long flags;
845 843
846 spin_lock_irqsave(&dev->hw_lock, flags); 844 spin_lock_irqsave(&dev->hw_lock, flags);
@@ -850,9 +848,9 @@ static int ene_open(void *data)
850} 848}
851 849
852/* outside interface: called on device close*/ 850/* outside interface: called on device close*/
853static void ene_close(void *data) 851static void ene_close(struct rc_dev *rdev)
854{ 852{
855 struct ene_device *dev = (struct ene_device *)data; 853 struct ene_device *dev = rdev->priv;
856 unsigned long flags; 854 unsigned long flags;
857 spin_lock_irqsave(&dev->hw_lock, flags); 855 spin_lock_irqsave(&dev->hw_lock, flags);
858 856
@@ -861,9 +859,9 @@ static void ene_close(void *data)
861} 859}
862 860
863/* outside interface: set transmitter mask */ 861/* outside interface: set transmitter mask */
864static int ene_set_tx_mask(void *data, u32 tx_mask) 862static int ene_set_tx_mask(struct rc_dev *rdev, u32 tx_mask)
865{ 863{
866 struct ene_device *dev = (struct ene_device *)data; 864 struct ene_device *dev = rdev->priv;
867 dbg("TX: attempt to set transmitter mask %02x", tx_mask); 865 dbg("TX: attempt to set transmitter mask %02x", tx_mask);
868 866
869 /* invalid txmask */ 867 /* invalid txmask */
@@ -879,9 +877,9 @@ static int ene_set_tx_mask(void *data, u32 tx_mask)
879} 877}
880 878
881/* outside interface : set tx carrier */ 879/* outside interface : set tx carrier */
882static int ene_set_tx_carrier(void *data, u32 carrier) 880static int ene_set_tx_carrier(struct rc_dev *rdev, u32 carrier)
883{ 881{
884 struct ene_device *dev = (struct ene_device *)data; 882 struct ene_device *dev = rdev->priv;
885 u32 period = 2000000 / carrier; 883 u32 period = 2000000 / carrier;
886 884
887 dbg("TX: attempt to set tx carrier to %d kHz", carrier); 885 dbg("TX: attempt to set tx carrier to %d kHz", carrier);
@@ -900,9 +898,9 @@ static int ene_set_tx_carrier(void *data, u32 carrier)
900} 898}
901 899
902/*outside interface : set tx duty cycle */ 900/*outside interface : set tx duty cycle */
903static int ene_set_tx_duty_cycle(void *data, u32 duty_cycle) 901static int ene_set_tx_duty_cycle(struct rc_dev *rdev, u32 duty_cycle)
904{ 902{
905 struct ene_device *dev = (struct ene_device *)data; 903 struct ene_device *dev = rdev->priv;
906 dbg("TX: setting duty cycle to %d%%", duty_cycle); 904 dbg("TX: setting duty cycle to %d%%", duty_cycle);
907 dev->tx_duty_cycle = duty_cycle; 905 dev->tx_duty_cycle = duty_cycle;
908 ene_tx_set_carrier(dev); 906 ene_tx_set_carrier(dev);
@@ -910,9 +908,9 @@ static int ene_set_tx_duty_cycle(void *data, u32 duty_cycle)
910} 908}
911 909
912/* outside interface: enable learning mode */ 910/* outside interface: enable learning mode */
913static int ene_set_learning_mode(void *data, int enable) 911static int ene_set_learning_mode(struct rc_dev *rdev, int enable)
914{ 912{
915 struct ene_device *dev = (struct ene_device *)data; 913 struct ene_device *dev = rdev->priv;
916 unsigned long flags; 914 unsigned long flags;
917 if (enable == dev->learning_mode_enabled) 915 if (enable == dev->learning_mode_enabled)
918 return 0; 916 return 0;
@@ -926,9 +924,9 @@ static int ene_set_learning_mode(void *data, int enable)
926 return 0; 924 return 0;
927} 925}
928 926
929static int ene_set_carrier_report(void *data, int enable) 927static int ene_set_carrier_report(struct rc_dev *rdev, int enable)
930{ 928{
931 struct ene_device *dev = (struct ene_device *)data; 929 struct ene_device *dev = rdev->priv;
932 unsigned long flags; 930 unsigned long flags;
933 931
934 if (enable == dev->carrier_detect_enabled) 932 if (enable == dev->carrier_detect_enabled)
@@ -944,18 +942,20 @@ static int ene_set_carrier_report(void *data, int enable)
944} 942}
945 943
946/* outside interface: enable or disable idle mode */ 944/* outside interface: enable or disable idle mode */
947static void ene_set_idle(void *data, bool idle) 945static void ene_set_idle(struct rc_dev *rdev, bool idle)
948{ 946{
947 struct ene_device *dev = rdev->priv;
948
949 if (idle) { 949 if (idle) {
950 ene_rx_reset((struct ene_device *)data); 950 ene_rx_reset(dev);
951 dbg("RX: end of data"); 951 dbg("RX: end of data");
952 } 952 }
953} 953}
954 954
955/* outside interface: transmit */ 955/* outside interface: transmit */
956static int ene_transmit(void *data, int *buf, u32 n) 956static int ene_transmit(struct rc_dev *rdev, int *buf, u32 n)
957{ 957{
958 struct ene_device *dev = (struct ene_device *)data; 958 struct ene_device *dev = rdev->priv;
959 unsigned long flags; 959 unsigned long flags;
960 960
961 dev->tx_buffer = buf; 961 dev->tx_buffer = buf;
@@ -992,16 +992,13 @@ static int ene_transmit(void *data, int *buf, u32 n)
992static int ene_probe(struct pnp_dev *pnp_dev, const struct pnp_device_id *id) 992static int ene_probe(struct pnp_dev *pnp_dev, const struct pnp_device_id *id)
993{ 993{
994 int error = -ENOMEM; 994 int error = -ENOMEM;
995 struct ir_dev_props *ir_props; 995 struct rc_dev *rdev;
996 struct input_dev *input_dev;
997 struct ene_device *dev; 996 struct ene_device *dev;
998 997
999 /* allocate memory */ 998 /* allocate memory */
1000 input_dev = input_allocate_device();
1001 ir_props = kzalloc(sizeof(struct ir_dev_props), GFP_KERNEL);
1002 dev = kzalloc(sizeof(struct ene_device), GFP_KERNEL); 999 dev = kzalloc(sizeof(struct ene_device), GFP_KERNEL);
1003 1000 rdev = rc_allocate_device();
1004 if (!input_dev || !ir_props || !dev) 1001 if (!dev || !rdev)
1005 goto error1; 1002 goto error1;
1006 1003
1007 /* validate resources */ 1004 /* validate resources */
@@ -1054,24 +1051,25 @@ static int ene_probe(struct pnp_dev *pnp_dev, const struct pnp_device_id *id)
1054 if (!dev->hw_learning_and_tx_capable) 1051 if (!dev->hw_learning_and_tx_capable)
1055 learning_mode_force = false; 1052 learning_mode_force = false;
1056 1053
1057 ir_props->driver_type = RC_DRIVER_IR_RAW; 1054 rdev->driver_type = RC_DRIVER_IR_RAW;
1058 ir_props->allowed_protos = IR_TYPE_ALL; 1055 rdev->allowed_protos = RC_TYPE_ALL;
1059 ir_props->priv = dev; 1056 rdev->priv = dev;
1060 ir_props->open = ene_open; 1057 rdev->open = ene_open;
1061 ir_props->close = ene_close; 1058 rdev->close = ene_close;
1062 ir_props->s_idle = ene_set_idle; 1059 rdev->s_idle = ene_set_idle;
1063 1060 rdev->driver_name = ENE_DRIVER_NAME;
1064 dev->props = ir_props; 1061 rdev->map_name = RC_MAP_RC6_MCE;
1065 dev->idev = input_dev; 1062 rdev->input_name = "ENE eHome Infrared Remote Receiver";
1066 1063
1067 if (dev->hw_learning_and_tx_capable) { 1064 if (dev->hw_learning_and_tx_capable) {
1068 ir_props->s_learning_mode = ene_set_learning_mode; 1065 rdev->s_learning_mode = ene_set_learning_mode;
1069 init_completion(&dev->tx_complete); 1066 init_completion(&dev->tx_complete);
1070 ir_props->tx_ir = ene_transmit; 1067 rdev->tx_ir = ene_transmit;
1071 ir_props->s_tx_mask = ene_set_tx_mask; 1068 rdev->s_tx_mask = ene_set_tx_mask;
1072 ir_props->s_tx_carrier = ene_set_tx_carrier; 1069 rdev->s_tx_carrier = ene_set_tx_carrier;
1073 ir_props->s_tx_duty_cycle = ene_set_tx_duty_cycle; 1070 rdev->s_tx_duty_cycle = ene_set_tx_duty_cycle;
1074 ir_props->s_carrier_report = ene_set_carrier_report; 1071 rdev->s_carrier_report = ene_set_carrier_report;
1072 rdev->input_name = "ENE eHome Infrared Remote Transceiver";
1075 } 1073 }
1076 1074
1077 ene_rx_setup_hw_buffer(dev); 1075 ene_rx_setup_hw_buffer(dev);
@@ -1081,16 +1079,11 @@ static int ene_probe(struct pnp_dev *pnp_dev, const struct pnp_device_id *id)
1081 device_set_wakeup_capable(&pnp_dev->dev, true); 1079 device_set_wakeup_capable(&pnp_dev->dev, true);
1082 device_set_wakeup_enable(&pnp_dev->dev, true); 1080 device_set_wakeup_enable(&pnp_dev->dev, true);
1083 1081
1084 if (dev->hw_learning_and_tx_capable) 1082 error = rc_register_device(rdev);
1085 input_dev->name = "ENE eHome Infrared Remote Transceiver"; 1083 if (error < 0)
1086 else
1087 input_dev->name = "ENE eHome Infrared Remote Receiver";
1088
1089 error = -ENODEV;
1090 if (ir_input_register(input_dev, RC_MAP_RC6_MCE, ir_props,
1091 ENE_DRIVER_NAME))
1092 goto error; 1084 goto error;
1093 1085
1086 dev->rdev = rdev;
1094 ene_notice("driver has been succesfully loaded"); 1087 ene_notice("driver has been succesfully loaded");
1095 return 0; 1088 return 0;
1096error: 1089error:
@@ -1099,8 +1092,7 @@ error:
1099 if (dev && dev->hw_io >= 0) 1092 if (dev && dev->hw_io >= 0)
1100 release_region(dev->hw_io, ENE_IO_SIZE); 1093 release_region(dev->hw_io, ENE_IO_SIZE);
1101error1: 1094error1:
1102 input_free_device(input_dev); 1095 rc_free_device(rdev);
1103 kfree(ir_props);
1104 kfree(dev); 1096 kfree(dev);
1105 return error; 1097 return error;
1106} 1098}
@@ -1118,8 +1110,7 @@ static void ene_remove(struct pnp_dev *pnp_dev)
1118 1110
1119 free_irq(dev->irq, dev); 1111 free_irq(dev->irq, dev);
1120 release_region(dev->hw_io, ENE_IO_SIZE); 1112 release_region(dev->hw_io, ENE_IO_SIZE);
1121 ir_input_unregister(dev->idev); 1113 rc_unregister_device(dev->rdev);
1122 kfree(dev->props);
1123 kfree(dev); 1114 kfree(dev);
1124} 1115}
1125 1116
diff --git a/drivers/media/IR/ene_ir.h b/drivers/media/rc/ene_ir.h
index f5870667a433..c179baf34cb4 100644
--- a/drivers/media/IR/ene_ir.h
+++ b/drivers/media/rc/ene_ir.h
@@ -205,8 +205,7 @@
205 205
206struct ene_device { 206struct ene_device {
207 struct pnp_dev *pnp_dev; 207 struct pnp_dev *pnp_dev;
208 struct input_dev *idev; 208 struct rc_dev *rdev;
209 struct ir_dev_props *props;
210 209
211 /* hw IO settings */ 210 /* hw IO settings */
212 long hw_io; 211 long hw_io;
diff --git a/drivers/media/IR/imon.c b/drivers/media/rc/imon.c
index bc118066bc38..6811512b4e83 100644
--- a/drivers/media/IR/imon.c
+++ b/drivers/media/rc/imon.c
@@ -38,7 +38,7 @@
38#include <linux/input.h> 38#include <linux/input.h>
39#include <linux/usb.h> 39#include <linux/usb.h>
40#include <linux/usb/input.h> 40#include <linux/usb/input.h>
41#include <media/ir-core.h> 41#include <media/rc-core.h>
42 42
43#include <linux/time.h> 43#include <linux/time.h>
44#include <linux/timer.h> 44#include <linux/timer.h>
@@ -88,7 +88,6 @@ static ssize_t lcd_write(struct file *file, const char *buf,
88 88
89struct imon_context { 89struct imon_context {
90 struct device *dev; 90 struct device *dev;
91 struct ir_dev_props *props;
92 /* Newer devices have two interfaces */ 91 /* Newer devices have two interfaces */
93 struct usb_device *usbdev_intf0; 92 struct usb_device *usbdev_intf0;
94 struct usb_device *usbdev_intf1; 93 struct usb_device *usbdev_intf1;
@@ -123,7 +122,7 @@ struct imon_context {
123 u16 vendor; /* usb vendor ID */ 122 u16 vendor; /* usb vendor ID */
124 u16 product; /* usb product ID */ 123 u16 product; /* usb product ID */
125 124
126 struct input_dev *rdev; /* input device for remote */ 125 struct rc_dev *rdev; /* rc-core device for remote */
127 struct input_dev *idev; /* input device for panel & IR mouse */ 126 struct input_dev *idev; /* input device for panel & IR mouse */
128 struct input_dev *touch; /* input device for touchscreen */ 127 struct input_dev *touch; /* input device for touchscreen */
129 128
@@ -132,7 +131,7 @@ struct imon_context {
132 u32 last_keycode; /* last reported input keycode */ 131 u32 last_keycode; /* last reported input keycode */
133 u32 rc_scancode; /* the computed remote scancode */ 132 u32 rc_scancode; /* the computed remote scancode */
134 u8 rc_toggle; /* the computed remote toggle bit */ 133 u8 rc_toggle; /* the computed remote toggle bit */
135 u64 ir_type; /* iMON or MCE (RC6) IR protocol? */ 134 u64 rc_type; /* iMON or MCE (RC6) IR protocol? */
136 bool release_code; /* some keys send a release code */ 135 bool release_code; /* some keys send a release code */
137 136
138 u8 display_type; /* store the display type */ 137 u8 display_type; /* store the display type */
@@ -984,27 +983,27 @@ static void imon_touch_display_timeout(unsigned long data)
984 * really just RC-6), but only one or the other at a time, as the signals 983 * really just RC-6), but only one or the other at a time, as the signals
985 * are decoded onboard the receiver. 984 * are decoded onboard the receiver.
986 */ 985 */
987int imon_ir_change_protocol(void *priv, u64 ir_type) 986static int imon_ir_change_protocol(struct rc_dev *rc, u64 rc_type)
988{ 987{
989 int retval; 988 int retval;
990 struct imon_context *ictx = priv; 989 struct imon_context *ictx = rc->priv;
991 struct device *dev = ictx->dev; 990 struct device *dev = ictx->dev;
992 bool pad_mouse; 991 bool pad_mouse;
993 unsigned char ir_proto_packet[] = { 992 unsigned char ir_proto_packet[] = {
994 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86 }; 993 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86 };
995 994
996 if (ir_type && !(ir_type & ictx->props->allowed_protos)) 995 if (rc_type && !(rc_type & rc->allowed_protos))
997 dev_warn(dev, "Looks like you're trying to use an IR protocol " 996 dev_warn(dev, "Looks like you're trying to use an IR protocol "
998 "this device does not support\n"); 997 "this device does not support\n");
999 998
1000 switch (ir_type) { 999 switch (rc_type) {
1001 case IR_TYPE_RC6: 1000 case RC_TYPE_RC6:
1002 dev_dbg(dev, "Configuring IR receiver for MCE protocol\n"); 1001 dev_dbg(dev, "Configuring IR receiver for MCE protocol\n");
1003 ir_proto_packet[0] = 0x01; 1002 ir_proto_packet[0] = 0x01;
1004 pad_mouse = false; 1003 pad_mouse = false;
1005 break; 1004 break;
1006 case IR_TYPE_UNKNOWN: 1005 case RC_TYPE_UNKNOWN:
1007 case IR_TYPE_OTHER: 1006 case RC_TYPE_OTHER:
1008 dev_dbg(dev, "Configuring IR receiver for iMON protocol\n"); 1007 dev_dbg(dev, "Configuring IR receiver for iMON protocol\n");
1009 if (pad_stabilize && !nomouse) 1008 if (pad_stabilize && !nomouse)
1010 pad_mouse = true; 1009 pad_mouse = true;
@@ -1013,7 +1012,7 @@ int imon_ir_change_protocol(void *priv, u64 ir_type)
1013 pad_mouse = false; 1012 pad_mouse = false;
1014 } 1013 }
1015 /* ir_proto_packet[0] = 0x00; // already the default */ 1014 /* ir_proto_packet[0] = 0x00; // already the default */
1016 ir_type = IR_TYPE_OTHER; 1015 rc_type = RC_TYPE_OTHER;
1017 break; 1016 break;
1018 default: 1017 default:
1019 dev_warn(dev, "Unsupported IR protocol specified, overriding " 1018 dev_warn(dev, "Unsupported IR protocol specified, overriding "
@@ -1025,7 +1024,7 @@ int imon_ir_change_protocol(void *priv, u64 ir_type)
1025 pad_mouse = false; 1024 pad_mouse = false;
1026 } 1025 }
1027 /* ir_proto_packet[0] = 0x00; // already the default */ 1026 /* ir_proto_packet[0] = 0x00; // already the default */
1028 ir_type = IR_TYPE_OTHER; 1027 rc_type = RC_TYPE_OTHER;
1029 break; 1028 break;
1030 } 1029 }
1031 1030
@@ -1035,7 +1034,7 @@ int imon_ir_change_protocol(void *priv, u64 ir_type)
1035 if (retval) 1034 if (retval)
1036 goto out; 1035 goto out;
1037 1036
1038 ictx->ir_type = ir_type; 1037 ictx->rc_type = rc_type;
1039 ictx->pad_mouse = pad_mouse; 1038 ictx->pad_mouse = pad_mouse;
1040 1039
1041out: 1040out:
@@ -1147,14 +1146,14 @@ static u32 imon_remote_key_lookup(struct imon_context *ictx, u32 scancode)
1147 bool is_release_code = false; 1146 bool is_release_code = false;
1148 1147
1149 /* Look for the initial press of a button */ 1148 /* Look for the initial press of a button */
1150 keycode = ir_g_keycode_from_table(ictx->rdev, scancode); 1149 keycode = rc_g_keycode_from_table(ictx->rdev, scancode);
1151 ictx->rc_toggle = 0x0; 1150 ictx->rc_toggle = 0x0;
1152 ictx->rc_scancode = scancode; 1151 ictx->rc_scancode = scancode;
1153 1152
1154 /* Look for the release of a button */ 1153 /* Look for the release of a button */
1155 if (keycode == KEY_RESERVED) { 1154 if (keycode == KEY_RESERVED) {
1156 release = scancode & ~0x4000; 1155 release = scancode & ~0x4000;
1157 keycode = ir_g_keycode_from_table(ictx->rdev, release); 1156 keycode = rc_g_keycode_from_table(ictx->rdev, release);
1158 if (keycode != KEY_RESERVED) 1157 if (keycode != KEY_RESERVED)
1159 is_release_code = true; 1158 is_release_code = true;
1160 } 1159 }
@@ -1183,7 +1182,7 @@ static u32 imon_mce_key_lookup(struct imon_context *ictx, u32 scancode)
1183 scancode = scancode | MCE_KEY_MASK | MCE_TOGGLE_BIT; 1182 scancode = scancode | MCE_KEY_MASK | MCE_TOGGLE_BIT;
1184 1183
1185 ictx->rc_scancode = scancode; 1184 ictx->rc_scancode = scancode;
1186 keycode = ir_g_keycode_from_table(ictx->rdev, scancode); 1185 keycode = rc_g_keycode_from_table(ictx->rdev, scancode);
1187 1186
1188 /* not used in mce mode, but make sure we know its false */ 1187 /* not used in mce mode, but make sure we know its false */
1189 ictx->release_code = false; 1188 ictx->release_code = false;
@@ -1307,7 +1306,7 @@ static void imon_pad_to_keys(struct imon_context *ictx, unsigned char *buf)
1307 rel_x = buf[2]; 1306 rel_x = buf[2];
1308 rel_y = buf[3]; 1307 rel_y = buf[3];
1309 1308
1310 if (ictx->ir_type == IR_TYPE_OTHER && pad_stabilize) { 1309 if (ictx->rc_type == RC_TYPE_OTHER && pad_stabilize) {
1311 if ((buf[1] == 0) && ((rel_x != 0) || (rel_y != 0))) { 1310 if ((buf[1] == 0) && ((rel_x != 0) || (rel_y != 0))) {
1312 dir = stabilize((int)rel_x, (int)rel_y, 1311 dir = stabilize((int)rel_x, (int)rel_y,
1313 timeout, threshold); 1312 timeout, threshold);
@@ -1374,7 +1373,7 @@ static void imon_pad_to_keys(struct imon_context *ictx, unsigned char *buf)
1374 buf[0] = 0x01; 1373 buf[0] = 0x01;
1375 buf[1] = buf[4] = buf[5] = buf[6] = buf[7] = 0; 1374 buf[1] = buf[4] = buf[5] = buf[6] = buf[7] = 0;
1376 1375
1377 if (ictx->ir_type == IR_TYPE_OTHER && pad_stabilize) { 1376 if (ictx->rc_type == RC_TYPE_OTHER && pad_stabilize) {
1378 dir = stabilize((int)rel_x, (int)rel_y, 1377 dir = stabilize((int)rel_x, (int)rel_y,
1379 timeout, threshold); 1378 timeout, threshold);
1380 if (!dir) { 1379 if (!dir) {
@@ -1479,17 +1478,12 @@ static void imon_incoming_packet(struct imon_context *ictx,
1479 bool norelease = false; 1478 bool norelease = false;
1480 int i; 1479 int i;
1481 u64 scancode; 1480 u64 scancode;
1482 struct input_dev *rdev = NULL;
1483 struct ir_input_dev *irdev = NULL;
1484 int press_type = 0; 1481 int press_type = 0;
1485 int msec; 1482 int msec;
1486 struct timeval t; 1483 struct timeval t;
1487 static struct timeval prev_time = { 0, 0 }; 1484 static struct timeval prev_time = { 0, 0 };
1488 u8 ktype; 1485 u8 ktype;
1489 1486
1490 rdev = ictx->rdev;
1491 irdev = input_get_drvdata(rdev);
1492
1493 /* filter out junk data on the older 0xffdc imon devices */ 1487 /* filter out junk data on the older 0xffdc imon devices */
1494 if ((buf[0] == 0xff) && (buf[1] == 0xff) && (buf[2] == 0xff)) 1488 if ((buf[0] == 0xff) && (buf[1] == 0xff) && (buf[2] == 0xff))
1495 return; 1489 return;
@@ -1501,7 +1495,7 @@ static void imon_incoming_packet(struct imon_context *ictx,
1501 kc = imon_panel_key_lookup(scancode); 1495 kc = imon_panel_key_lookup(scancode);
1502 } else { 1496 } else {
1503 scancode = be32_to_cpu(*((u32 *)buf)); 1497 scancode = be32_to_cpu(*((u32 *)buf));
1504 if (ictx->ir_type == IR_TYPE_RC6) { 1498 if (ictx->rc_type == RC_TYPE_RC6) {
1505 ktype = IMON_KEY_IMON; 1499 ktype = IMON_KEY_IMON;
1506 if (buf[0] == 0x80) 1500 if (buf[0] == 0x80)
1507 ktype = IMON_KEY_MCE; 1501 ktype = IMON_KEY_MCE;
@@ -1570,9 +1564,9 @@ static void imon_incoming_packet(struct imon_context *ictx,
1570 1564
1571 if (ktype != IMON_KEY_PANEL) { 1565 if (ktype != IMON_KEY_PANEL) {
1572 if (press_type == 0) 1566 if (press_type == 0)
1573 ir_keyup(irdev); 1567 rc_keyup(ictx->rdev);
1574 else { 1568 else {
1575 ir_keydown(rdev, ictx->rc_scancode, ictx->rc_toggle); 1569 rc_keydown(ictx->rdev, ictx->rc_scancode, ictx->rc_toggle);
1576 spin_lock_irqsave(&ictx->kc_lock, flags); 1570 spin_lock_irqsave(&ictx->kc_lock, flags);
1577 ictx->last_keycode = ictx->kc; 1571 ictx->last_keycode = ictx->kc;
1578 spin_unlock_irqrestore(&ictx->kc_lock, flags); 1572 spin_unlock_irqrestore(&ictx->kc_lock, flags);
@@ -1715,7 +1709,7 @@ static void imon_get_ffdc_type(struct imon_context *ictx)
1715{ 1709{
1716 u8 ffdc_cfg_byte = ictx->usb_rx_buf[6]; 1710 u8 ffdc_cfg_byte = ictx->usb_rx_buf[6];
1717 u8 detected_display_type = IMON_DISPLAY_TYPE_NONE; 1711 u8 detected_display_type = IMON_DISPLAY_TYPE_NONE;
1718 u64 allowed_protos = IR_TYPE_OTHER; 1712 u64 allowed_protos = RC_TYPE_OTHER;
1719 1713
1720 switch (ffdc_cfg_byte) { 1714 switch (ffdc_cfg_byte) {
1721 /* iMON Knob, no display, iMON IR + vol knob */ 1715 /* iMON Knob, no display, iMON IR + vol knob */
@@ -1744,13 +1738,13 @@ static void imon_get_ffdc_type(struct imon_context *ictx)
1744 case 0x9e: 1738 case 0x9e:
1745 dev_info(ictx->dev, "0xffdc iMON VFD, MCE IR"); 1739 dev_info(ictx->dev, "0xffdc iMON VFD, MCE IR");
1746 detected_display_type = IMON_DISPLAY_TYPE_VFD; 1740 detected_display_type = IMON_DISPLAY_TYPE_VFD;
1747 allowed_protos = IR_TYPE_RC6; 1741 allowed_protos = RC_TYPE_RC6;
1748 break; 1742 break;
1749 /* iMON LCD, MCE IR */ 1743 /* iMON LCD, MCE IR */
1750 case 0x9f: 1744 case 0x9f:
1751 dev_info(ictx->dev, "0xffdc iMON LCD, MCE IR"); 1745 dev_info(ictx->dev, "0xffdc iMON LCD, MCE IR");
1752 detected_display_type = IMON_DISPLAY_TYPE_LCD; 1746 detected_display_type = IMON_DISPLAY_TYPE_LCD;
1753 allowed_protos = IR_TYPE_RC6; 1747 allowed_protos = RC_TYPE_RC6;
1754 break; 1748 break;
1755 default: 1749 default:
1756 dev_info(ictx->dev, "Unknown 0xffdc device, " 1750 dev_info(ictx->dev, "Unknown 0xffdc device, "
@@ -1762,8 +1756,8 @@ static void imon_get_ffdc_type(struct imon_context *ictx)
1762 printk(KERN_CONT " (id 0x%02x)\n", ffdc_cfg_byte); 1756 printk(KERN_CONT " (id 0x%02x)\n", ffdc_cfg_byte);
1763 1757
1764 ictx->display_type = detected_display_type; 1758 ictx->display_type = detected_display_type;
1765 ictx->props->allowed_protos = allowed_protos; 1759 ictx->rdev->allowed_protos = allowed_protos;
1766 ictx->ir_type = allowed_protos; 1760 ictx->rc_type = allowed_protos;
1767} 1761}
1768 1762
1769static void imon_set_display_type(struct imon_context *ictx) 1763static void imon_set_display_type(struct imon_context *ictx)
@@ -1816,18 +1810,15 @@ static void imon_set_display_type(struct imon_context *ictx)
1816 ictx->display_type = configured_display_type; 1810 ictx->display_type = configured_display_type;
1817} 1811}
1818 1812
1819static struct input_dev *imon_init_rdev(struct imon_context *ictx) 1813static struct rc_dev *imon_init_rdev(struct imon_context *ictx)
1820{ 1814{
1821 struct input_dev *rdev; 1815 struct rc_dev *rdev;
1822 struct ir_dev_props *props;
1823 int ret; 1816 int ret;
1824 char *ir_codes = NULL;
1825 const unsigned char fp_packet[] = { 0x40, 0x00, 0x00, 0x00, 1817 const unsigned char fp_packet[] = { 0x40, 0x00, 0x00, 0x00,
1826 0x00, 0x00, 0x00, 0x88 }; 1818 0x00, 0x00, 0x00, 0x88 };
1827 1819
1828 rdev = input_allocate_device(); 1820 rdev = rc_allocate_device();
1829 props = kzalloc(sizeof(*props), GFP_KERNEL); 1821 if (!rdev) {
1830 if (!rdev || !props) {
1831 dev_err(ictx->dev, "remote control dev allocation failed\n"); 1822 dev_err(ictx->dev, "remote control dev allocation failed\n");
1832 goto out; 1823 goto out;
1833 } 1824 }
@@ -1838,18 +1829,20 @@ static struct input_dev *imon_init_rdev(struct imon_context *ictx)
1838 sizeof(ictx->phys_rdev)); 1829 sizeof(ictx->phys_rdev));
1839 strlcat(ictx->phys_rdev, "/input0", sizeof(ictx->phys_rdev)); 1830 strlcat(ictx->phys_rdev, "/input0", sizeof(ictx->phys_rdev));
1840 1831
1841 rdev->name = ictx->name_rdev; 1832 rdev->input_name = ictx->name_rdev;
1842 rdev->phys = ictx->phys_rdev; 1833 rdev->input_phys = ictx->phys_rdev;
1843 usb_to_input_id(ictx->usbdev_intf0, &rdev->id); 1834 usb_to_input_id(ictx->usbdev_intf0, &rdev->input_id);
1844 rdev->dev.parent = ictx->dev; 1835 rdev->dev.parent = ictx->dev;
1845 rdev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
1846 input_set_drvdata(rdev, ictx);
1847 1836
1848 props->priv = ictx; 1837 rdev->priv = ictx;
1849 props->driver_type = RC_DRIVER_SCANCODE; 1838 rdev->driver_type = RC_DRIVER_SCANCODE;
1850 props->allowed_protos = IR_TYPE_OTHER | IR_TYPE_RC6; /* iMON PAD or MCE */ 1839 rdev->allowed_protos = RC_TYPE_OTHER | RC_TYPE_RC6; /* iMON PAD or MCE */
1851 props->change_protocol = imon_ir_change_protocol; 1840 rdev->change_protocol = imon_ir_change_protocol;
1852 ictx->props = props; 1841 rdev->driver_name = MOD_NAME;
1842 if (ictx->rc_type == RC_TYPE_RC6)
1843 rdev->map_name = RC_MAP_IMON_MCE;
1844 else
1845 rdev->map_name = RC_MAP_IMON_PAD;
1853 1846
1854 /* Enable front-panel buttons and/or knobs */ 1847 /* Enable front-panel buttons and/or knobs */
1855 memcpy(ictx->usb_tx_buf, &fp_packet, sizeof(fp_packet)); 1848 memcpy(ictx->usb_tx_buf, &fp_packet, sizeof(fp_packet));
@@ -1863,12 +1856,7 @@ static struct input_dev *imon_init_rdev(struct imon_context *ictx)
1863 1856
1864 imon_set_display_type(ictx); 1857 imon_set_display_type(ictx);
1865 1858
1866 if (ictx->ir_type == IR_TYPE_RC6) 1859 ret = rc_register_device(rdev);
1867 ir_codes = RC_MAP_IMON_MCE;
1868 else
1869 ir_codes = RC_MAP_IMON_PAD;
1870
1871 ret = ir_input_register(rdev, ir_codes, props, MOD_NAME);
1872 if (ret < 0) { 1860 if (ret < 0) {
1873 dev_err(ictx->dev, "remote input dev register failed\n"); 1861 dev_err(ictx->dev, "remote input dev register failed\n");
1874 goto out; 1862 goto out;
@@ -1877,8 +1865,7 @@ static struct input_dev *imon_init_rdev(struct imon_context *ictx)
1877 return rdev; 1865 return rdev;
1878 1866
1879out: 1867out:
1880 kfree(props); 1868 rc_free_device(rdev);
1881 input_free_device(rdev);
1882 return NULL; 1869 return NULL;
1883} 1870}
1884 1871
@@ -2149,7 +2136,7 @@ static struct imon_context *imon_init_intf0(struct usb_interface *intf)
2149 return ictx; 2136 return ictx;
2150 2137
2151urb_submit_failed: 2138urb_submit_failed:
2152 ir_input_unregister(ictx->rdev); 2139 rc_unregister_device(ictx->rdev);
2153rdev_setup_failed: 2140rdev_setup_failed:
2154 input_unregister_device(ictx->idev); 2141 input_unregister_device(ictx->idev);
2155idev_setup_failed: 2142idev_setup_failed:
@@ -2287,7 +2274,7 @@ static int __devinit imon_probe(struct usb_interface *interface,
2287 mutex_lock(&driver_lock); 2274 mutex_lock(&driver_lock);
2288 2275
2289 first_if = usb_ifnum_to_if(usbdev, 0); 2276 first_if = usb_ifnum_to_if(usbdev, 0);
2290 first_if_ctx = (struct imon_context *)usb_get_intfdata(first_if); 2277 first_if_ctx = usb_get_intfdata(first_if);
2291 2278
2292 if (ifnum == 0) { 2279 if (ifnum == 0) {
2293 ictx = imon_init_intf0(interface); 2280 ictx = imon_init_intf0(interface);
@@ -2376,7 +2363,7 @@ static void __devexit imon_disconnect(struct usb_interface *interface)
2376 ictx->dev_present_intf0 = false; 2363 ictx->dev_present_intf0 = false;
2377 usb_kill_urb(ictx->rx_urb_intf0); 2364 usb_kill_urb(ictx->rx_urb_intf0);
2378 input_unregister_device(ictx->idev); 2365 input_unregister_device(ictx->idev);
2379 ir_input_unregister(ictx->rdev); 2366 rc_unregister_device(ictx->rdev);
2380 if (ictx->display_supported) { 2367 if (ictx->display_supported) {
2381 if (ictx->display_type == IMON_DISPLAY_TYPE_LCD) 2368 if (ictx->display_type == IMON_DISPLAY_TYPE_LCD)
2382 usb_deregister_dev(interface, &imon_lcd_class); 2369 usb_deregister_dev(interface, &imon_lcd_class);
diff --git a/drivers/media/IR/ir-jvc-decoder.c b/drivers/media/rc/ir-jvc-decoder.c
index 63dca6e5458b..624449afaa61 100644
--- a/drivers/media/IR/ir-jvc-decoder.c
+++ b/drivers/media/rc/ir-jvc-decoder.c
@@ -13,7 +13,7 @@
13 */ 13 */
14 14
15#include <linux/bitrev.h> 15#include <linux/bitrev.h>
16#include "ir-core-priv.h" 16#include "rc-core-priv.h"
17 17
18#define JVC_NBITS 16 /* dev(8) + func(8) */ 18#define JVC_NBITS 16 /* dev(8) + func(8) */
19#define JVC_UNIT 525000 /* ns */ 19#define JVC_UNIT 525000 /* ns */
@@ -37,17 +37,16 @@ enum jvc_state {
37 37
38/** 38/**
39 * ir_jvc_decode() - Decode one JVC pulse or space 39 * ir_jvc_decode() - Decode one JVC pulse or space
40 * @input_dev: the struct input_dev descriptor of the device 40 * @dev: the struct rc_dev descriptor of the device
41 * @duration: the struct ir_raw_event descriptor of the pulse/space 41 * @duration: the struct ir_raw_event descriptor of the pulse/space
42 * 42 *
43 * This function returns -EINVAL if the pulse violates the state machine 43 * This function returns -EINVAL if the pulse violates the state machine
44 */ 44 */
45static int ir_jvc_decode(struct input_dev *input_dev, struct ir_raw_event ev) 45static int ir_jvc_decode(struct rc_dev *dev, struct ir_raw_event ev)
46{ 46{
47 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); 47 struct jvc_dec *data = &dev->raw->jvc;
48 struct jvc_dec *data = &ir_dev->raw->jvc;
49 48
50 if (!(ir_dev->raw->enabled_protocols & IR_TYPE_JVC)) 49 if (!(dev->raw->enabled_protocols & RC_TYPE_JVC))
51 return 0; 50 return 0;
52 51
53 if (!is_timing_event(ev)) { 52 if (!is_timing_event(ev)) {
@@ -140,12 +139,12 @@ again:
140 scancode = (bitrev8((data->bits >> 8) & 0xff) << 8) | 139 scancode = (bitrev8((data->bits >> 8) & 0xff) << 8) |
141 (bitrev8((data->bits >> 0) & 0xff) << 0); 140 (bitrev8((data->bits >> 0) & 0xff) << 0);
142 IR_dprintk(1, "JVC scancode 0x%04x\n", scancode); 141 IR_dprintk(1, "JVC scancode 0x%04x\n", scancode);
143 ir_keydown(input_dev, scancode, data->toggle); 142 rc_keydown(dev, scancode, data->toggle);
144 data->first = false; 143 data->first = false;
145 data->old_bits = data->bits; 144 data->old_bits = data->bits;
146 } else if (data->bits == data->old_bits) { 145 } else if (data->bits == data->old_bits) {
147 IR_dprintk(1, "JVC repeat\n"); 146 IR_dprintk(1, "JVC repeat\n");
148 ir_repeat(input_dev); 147 rc_repeat(dev);
149 } else { 148 } else {
150 IR_dprintk(1, "JVC invalid repeat msg\n"); 149 IR_dprintk(1, "JVC invalid repeat msg\n");
151 break; 150 break;
@@ -174,7 +173,7 @@ out:
174} 173}
175 174
176static struct ir_raw_handler jvc_handler = { 175static struct ir_raw_handler jvc_handler = {
177 .protocols = IR_TYPE_JVC, 176 .protocols = RC_TYPE_JVC,
178 .decode = ir_jvc_decode, 177 .decode = ir_jvc_decode,
179}; 178};
180 179
diff --git a/drivers/media/IR/ir-lirc-codec.c b/drivers/media/rc/ir-lirc-codec.c
index 9fc0db9d344d..f011c5d9dea1 100644
--- a/drivers/media/IR/ir-lirc-codec.c
+++ b/drivers/media/rc/ir-lirc-codec.c
@@ -16,29 +16,28 @@
16#include <linux/wait.h> 16#include <linux/wait.h>
17#include <media/lirc.h> 17#include <media/lirc.h>
18#include <media/lirc_dev.h> 18#include <media/lirc_dev.h>
19#include <media/ir-core.h> 19#include <media/rc-core.h>
20#include "ir-core-priv.h" 20#include "rc-core-priv.h"
21 21
22#define LIRCBUF_SIZE 256 22#define LIRCBUF_SIZE 256
23 23
24/** 24/**
25 * ir_lirc_decode() - Send raw IR data to lirc_dev to be relayed to the 25 * ir_lirc_decode() - Send raw IR data to lirc_dev to be relayed to the
26 * lircd userspace daemon for decoding. 26 * lircd userspace daemon for decoding.
27 * @input_dev: the struct input_dev descriptor of the device 27 * @input_dev: the struct rc_dev descriptor of the device
28 * @duration: the struct ir_raw_event descriptor of the pulse/space 28 * @duration: the struct ir_raw_event descriptor of the pulse/space
29 * 29 *
30 * This function returns -EINVAL if the lirc interfaces aren't wired up. 30 * This function returns -EINVAL if the lirc interfaces aren't wired up.
31 */ 31 */
32static int ir_lirc_decode(struct input_dev *input_dev, struct ir_raw_event ev) 32static int ir_lirc_decode(struct rc_dev *dev, struct ir_raw_event ev)
33{ 33{
34 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); 34 struct lirc_codec *lirc = &dev->raw->lirc;
35 struct lirc_codec *lirc = &ir_dev->raw->lirc;
36 int sample; 35 int sample;
37 36
38 if (!(ir_dev->raw->enabled_protocols & IR_TYPE_LIRC)) 37 if (!(dev->raw->enabled_protocols & RC_TYPE_LIRC))
39 return 0; 38 return 0;
40 39
41 if (!ir_dev->raw->lirc.drv || !ir_dev->raw->lirc.drv->rbuf) 40 if (!dev->raw->lirc.drv || !dev->raw->lirc.drv->rbuf)
42 return -EINVAL; 41 return -EINVAL;
43 42
44 /* Packet start */ 43 /* Packet start */
@@ -79,7 +78,7 @@ static int ir_lirc_decode(struct input_dev *input_dev, struct ir_raw_event ev)
79 (u64)LIRC_VALUE_MASK); 78 (u64)LIRC_VALUE_MASK);
80 79
81 gap_sample = LIRC_SPACE(lirc->gap_duration); 80 gap_sample = LIRC_SPACE(lirc->gap_duration);
82 lirc_buffer_write(ir_dev->raw->lirc.drv->rbuf, 81 lirc_buffer_write(dev->raw->lirc.drv->rbuf,
83 (unsigned char *) &gap_sample); 82 (unsigned char *) &gap_sample);
84 lirc->gap = false; 83 lirc->gap = false;
85 } 84 }
@@ -88,9 +87,9 @@ static int ir_lirc_decode(struct input_dev *input_dev, struct ir_raw_event ev)
88 LIRC_SPACE(ev.duration / 1000); 87 LIRC_SPACE(ev.duration / 1000);
89 } 88 }
90 89
91 lirc_buffer_write(ir_dev->raw->lirc.drv->rbuf, 90 lirc_buffer_write(dev->raw->lirc.drv->rbuf,
92 (unsigned char *) &sample); 91 (unsigned char *) &sample);
93 wake_up(&ir_dev->raw->lirc.drv->rbuf->wait_poll); 92 wake_up(&dev->raw->lirc.drv->rbuf->wait_poll);
94 93
95 return 0; 94 return 0;
96} 95}
@@ -99,9 +98,10 @@ static ssize_t ir_lirc_transmit_ir(struct file *file, const char *buf,
99 size_t n, loff_t *ppos) 98 size_t n, loff_t *ppos)
100{ 99{
101 struct lirc_codec *lirc; 100 struct lirc_codec *lirc;
102 struct ir_input_dev *ir_dev; 101 struct rc_dev *dev;
103 int *txbuf; /* buffer with values to transmit */ 102 int *txbuf; /* buffer with values to transmit */
104 int ret = 0, count; 103 int ret = 0;
104 size_t count;
105 105
106 lirc = lirc_get_pdata(file); 106 lirc = lirc_get_pdata(file);
107 if (!lirc) 107 if (!lirc)
@@ -111,21 +111,21 @@ static ssize_t ir_lirc_transmit_ir(struct file *file, const char *buf,
111 return -EINVAL; 111 return -EINVAL;
112 112
113 count = n / sizeof(int); 113 count = n / sizeof(int);
114 if (count > LIRCBUF_SIZE || count % 2 == 0) 114 if (count > LIRCBUF_SIZE || count % 2 == 0 || n % sizeof(int) != 0)
115 return -EINVAL; 115 return -EINVAL;
116 116
117 txbuf = memdup_user(buf, n); 117 txbuf = memdup_user(buf, n);
118 if (IS_ERR(txbuf)) 118 if (IS_ERR(txbuf))
119 return PTR_ERR(txbuf); 119 return PTR_ERR(txbuf);
120 120
121 ir_dev = lirc->ir_dev; 121 dev = lirc->dev;
122 if (!ir_dev) { 122 if (!dev) {
123 ret = -EFAULT; 123 ret = -EFAULT;
124 goto out; 124 goto out;
125 } 125 }
126 126
127 if (ir_dev->props && ir_dev->props->tx_ir) 127 if (dev->tx_ir)
128 ret = ir_dev->props->tx_ir(ir_dev->props->priv, txbuf, (u32)n); 128 ret = dev->tx_ir(dev, txbuf, (u32)n);
129 129
130out: 130out:
131 kfree(txbuf); 131 kfree(txbuf);
@@ -136,21 +136,18 @@ static long ir_lirc_ioctl(struct file *filep, unsigned int cmd,
136 unsigned long __user arg) 136 unsigned long __user arg)
137{ 137{
138 struct lirc_codec *lirc; 138 struct lirc_codec *lirc;
139 struct ir_input_dev *ir_dev; 139 struct rc_dev *dev;
140 int ret = 0; 140 int ret = 0;
141 void *drv_data;
142 __u32 val = 0, tmp; 141 __u32 val = 0, tmp;
143 142
144 lirc = lirc_get_pdata(filep); 143 lirc = lirc_get_pdata(filep);
145 if (!lirc) 144 if (!lirc)
146 return -EFAULT; 145 return -EFAULT;
147 146
148 ir_dev = lirc->ir_dev; 147 dev = lirc->dev;
149 if (!ir_dev || !ir_dev->props || !ir_dev->props->priv) 148 if (!dev)
150 return -EFAULT; 149 return -EFAULT;
151 150
152 drv_data = ir_dev->props->priv;
153
154 if (_IOC_DIR(cmd) & _IOC_WRITE) { 151 if (_IOC_DIR(cmd) & _IOC_WRITE) {
155 ret = get_user(val, (__u32 *)arg); 152 ret = get_user(val, (__u32 *)arg);
156 if (ret) 153 if (ret)
@@ -171,84 +168,85 @@ static long ir_lirc_ioctl(struct file *filep, unsigned int cmd,
171 168
172 /* TX settings */ 169 /* TX settings */
173 case LIRC_SET_TRANSMITTER_MASK: 170 case LIRC_SET_TRANSMITTER_MASK:
174 if (!ir_dev->props->s_tx_mask) 171 if (!dev->s_tx_mask)
175 return -EINVAL; 172 return -EINVAL;
176 173
177 return ir_dev->props->s_tx_mask(drv_data, val); 174 return dev->s_tx_mask(dev, val);
178 175
179 case LIRC_SET_SEND_CARRIER: 176 case LIRC_SET_SEND_CARRIER:
180 if (!ir_dev->props->s_tx_carrier) 177 if (!dev->s_tx_carrier)
181 return -EINVAL; 178 return -EINVAL;
182 179
183 return ir_dev->props->s_tx_carrier(drv_data, val); 180 return dev->s_tx_carrier(dev, val);
184 181
185 case LIRC_SET_SEND_DUTY_CYCLE: 182 case LIRC_SET_SEND_DUTY_CYCLE:
186 if (!ir_dev->props->s_tx_duty_cycle) 183 if (!dev->s_tx_duty_cycle)
187 return -ENOSYS; 184 return -ENOSYS;
188 185
189 if (val <= 0 || val >= 100) 186 if (val <= 0 || val >= 100)
190 return -EINVAL; 187 return -EINVAL;
191 188
192 return ir_dev->props->s_tx_duty_cycle(drv_data, val); 189 return dev->s_tx_duty_cycle(dev, val);
193 190
194 /* RX settings */ 191 /* RX settings */
195 case LIRC_SET_REC_CARRIER: 192 case LIRC_SET_REC_CARRIER:
196 if (!ir_dev->props->s_rx_carrier_range) 193 if (!dev->s_rx_carrier_range)
197 return -ENOSYS; 194 return -ENOSYS;
198 195
199 if (val <= 0) 196 if (val <= 0)
200 return -EINVAL; 197 return -EINVAL;
201 198
202 return ir_dev->props->s_rx_carrier_range(drv_data, 199 return dev->s_rx_carrier_range(dev,
203 ir_dev->raw->lirc.carrier_low, val); 200 dev->raw->lirc.carrier_low,
201 val);
204 202
205 case LIRC_SET_REC_CARRIER_RANGE: 203 case LIRC_SET_REC_CARRIER_RANGE:
206 if (val <= 0) 204 if (val <= 0)
207 return -EINVAL; 205 return -EINVAL;
208 206
209 ir_dev->raw->lirc.carrier_low = val; 207 dev->raw->lirc.carrier_low = val;
210 return 0; 208 return 0;
211 209
212 case LIRC_GET_REC_RESOLUTION: 210 case LIRC_GET_REC_RESOLUTION:
213 val = ir_dev->props->rx_resolution; 211 val = dev->rx_resolution;
214 break; 212 break;
215 213
216 case LIRC_SET_WIDEBAND_RECEIVER: 214 case LIRC_SET_WIDEBAND_RECEIVER:
217 if (!ir_dev->props->s_learning_mode) 215 if (!dev->s_learning_mode)
218 return -ENOSYS; 216 return -ENOSYS;
219 217
220 return ir_dev->props->s_learning_mode(drv_data, !!val); 218 return dev->s_learning_mode(dev, !!val);
221 219
222 case LIRC_SET_MEASURE_CARRIER_MODE: 220 case LIRC_SET_MEASURE_CARRIER_MODE:
223 if (!ir_dev->props->s_carrier_report) 221 if (!dev->s_carrier_report)
224 return -ENOSYS; 222 return -ENOSYS;
225 223
226 return ir_dev->props->s_carrier_report(drv_data, !!val); 224 return dev->s_carrier_report(dev, !!val);
227 225
228 /* Generic timeout support */ 226 /* Generic timeout support */
229 case LIRC_GET_MIN_TIMEOUT: 227 case LIRC_GET_MIN_TIMEOUT:
230 if (!ir_dev->props->max_timeout) 228 if (!dev->max_timeout)
231 return -ENOSYS; 229 return -ENOSYS;
232 val = ir_dev->props->min_timeout / 1000; 230 val = dev->min_timeout / 1000;
233 break; 231 break;
234 232
235 case LIRC_GET_MAX_TIMEOUT: 233 case LIRC_GET_MAX_TIMEOUT:
236 if (!ir_dev->props->max_timeout) 234 if (!dev->max_timeout)
237 return -ENOSYS; 235 return -ENOSYS;
238 val = ir_dev->props->max_timeout / 1000; 236 val = dev->max_timeout / 1000;
239 break; 237 break;
240 238
241 case LIRC_SET_REC_TIMEOUT: 239 case LIRC_SET_REC_TIMEOUT:
242 if (!ir_dev->props->max_timeout) 240 if (!dev->max_timeout)
243 return -ENOSYS; 241 return -ENOSYS;
244 242
245 tmp = val * 1000; 243 tmp = val * 1000;
246 244
247 if (tmp < ir_dev->props->min_timeout || 245 if (tmp < dev->min_timeout ||
248 tmp > ir_dev->props->max_timeout) 246 tmp > dev->max_timeout)
249 return -EINVAL; 247 return -EINVAL;
250 248
251 ir_dev->props->timeout = tmp; 249 dev->timeout = tmp;
252 break; 250 break;
253 251
254 case LIRC_SET_REC_TIMEOUT_REPORTS: 252 case LIRC_SET_REC_TIMEOUT_REPORTS:
@@ -289,9 +287,8 @@ static struct file_operations lirc_fops = {
289 .llseek = no_llseek, 287 .llseek = no_llseek,
290}; 288};
291 289
292static int ir_lirc_register(struct input_dev *input_dev) 290static int ir_lirc_register(struct rc_dev *dev)
293{ 291{
294 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
295 struct lirc_driver *drv; 292 struct lirc_driver *drv;
296 struct lirc_buffer *rbuf; 293 struct lirc_buffer *rbuf;
297 int rc = -ENOMEM; 294 int rc = -ENOMEM;
@@ -310,44 +307,40 @@ static int ir_lirc_register(struct input_dev *input_dev)
310 goto rbuf_init_failed; 307 goto rbuf_init_failed;
311 308
312 features = LIRC_CAN_REC_MODE2; 309 features = LIRC_CAN_REC_MODE2;
313 if (ir_dev->props->tx_ir) { 310 if (dev->tx_ir) {
314
315 features |= LIRC_CAN_SEND_PULSE; 311 features |= LIRC_CAN_SEND_PULSE;
316 if (ir_dev->props->s_tx_mask) 312 if (dev->s_tx_mask)
317 features |= LIRC_CAN_SET_TRANSMITTER_MASK; 313 features |= LIRC_CAN_SET_TRANSMITTER_MASK;
318 if (ir_dev->props->s_tx_carrier) 314 if (dev->s_tx_carrier)
319 features |= LIRC_CAN_SET_SEND_CARRIER; 315 features |= LIRC_CAN_SET_SEND_CARRIER;
320 316 if (dev->s_tx_duty_cycle)
321 if (ir_dev->props->s_tx_duty_cycle)
322 features |= LIRC_CAN_SET_SEND_DUTY_CYCLE; 317 features |= LIRC_CAN_SET_SEND_DUTY_CYCLE;
323 } 318 }
324 319
325 if (ir_dev->props->s_rx_carrier_range) 320 if (dev->s_rx_carrier_range)
326 features |= LIRC_CAN_SET_REC_CARRIER | 321 features |= LIRC_CAN_SET_REC_CARRIER |
327 LIRC_CAN_SET_REC_CARRIER_RANGE; 322 LIRC_CAN_SET_REC_CARRIER_RANGE;
328 323
329 if (ir_dev->props->s_learning_mode) 324 if (dev->s_learning_mode)
330 features |= LIRC_CAN_USE_WIDEBAND_RECEIVER; 325 features |= LIRC_CAN_USE_WIDEBAND_RECEIVER;
331 326
332 if (ir_dev->props->s_carrier_report) 327 if (dev->s_carrier_report)
333 features |= LIRC_CAN_MEASURE_CARRIER; 328 features |= LIRC_CAN_MEASURE_CARRIER;
334 329
335 330 if (dev->max_timeout)
336 if (ir_dev->props->max_timeout)
337 features |= LIRC_CAN_SET_REC_TIMEOUT; 331 features |= LIRC_CAN_SET_REC_TIMEOUT;
338 332
339
340 snprintf(drv->name, sizeof(drv->name), "ir-lirc-codec (%s)", 333 snprintf(drv->name, sizeof(drv->name), "ir-lirc-codec (%s)",
341 ir_dev->driver_name); 334 dev->driver_name);
342 drv->minor = -1; 335 drv->minor = -1;
343 drv->features = features; 336 drv->features = features;
344 drv->data = &ir_dev->raw->lirc; 337 drv->data = &dev->raw->lirc;
345 drv->rbuf = rbuf; 338 drv->rbuf = rbuf;
346 drv->set_use_inc = &ir_lirc_open; 339 drv->set_use_inc = &ir_lirc_open;
347 drv->set_use_dec = &ir_lirc_close; 340 drv->set_use_dec = &ir_lirc_close;
348 drv->code_length = sizeof(struct ir_raw_event) * 8; 341 drv->code_length = sizeof(struct ir_raw_event) * 8;
349 drv->fops = &lirc_fops; 342 drv->fops = &lirc_fops;
350 drv->dev = &ir_dev->dev; 343 drv->dev = &dev->dev;
351 drv->owner = THIS_MODULE; 344 drv->owner = THIS_MODULE;
352 345
353 drv->minor = lirc_register_driver(drv); 346 drv->minor = lirc_register_driver(drv);
@@ -356,8 +349,8 @@ static int ir_lirc_register(struct input_dev *input_dev)
356 goto lirc_register_failed; 349 goto lirc_register_failed;
357 } 350 }
358 351
359 ir_dev->raw->lirc.drv = drv; 352 dev->raw->lirc.drv = drv;
360 ir_dev->raw->lirc.ir_dev = ir_dev; 353 dev->raw->lirc.dev = dev;
361 return 0; 354 return 0;
362 355
363lirc_register_failed: 356lirc_register_failed:
@@ -369,10 +362,9 @@ rbuf_alloc_failed:
369 return rc; 362 return rc;
370} 363}
371 364
372static int ir_lirc_unregister(struct input_dev *input_dev) 365static int ir_lirc_unregister(struct rc_dev *dev)
373{ 366{
374 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); 367 struct lirc_codec *lirc = &dev->raw->lirc;
375 struct lirc_codec *lirc = &ir_dev->raw->lirc;
376 368
377 lirc_unregister_driver(lirc->drv->minor); 369 lirc_unregister_driver(lirc->drv->minor);
378 lirc_buffer_free(lirc->drv->rbuf); 370 lirc_buffer_free(lirc->drv->rbuf);
@@ -382,7 +374,7 @@ static int ir_lirc_unregister(struct input_dev *input_dev)
382} 374}
383 375
384static struct ir_raw_handler lirc_handler = { 376static struct ir_raw_handler lirc_handler = {
385 .protocols = IR_TYPE_LIRC, 377 .protocols = RC_TYPE_LIRC,
386 .decode = ir_lirc_decode, 378 .decode = ir_lirc_decode,
387 .raw_register = ir_lirc_register, 379 .raw_register = ir_lirc_register,
388 .raw_unregister = ir_lirc_unregister, 380 .raw_unregister = ir_lirc_unregister,
diff --git a/drivers/media/IR/ir-nec-decoder.c b/drivers/media/rc/ir-nec-decoder.c
index 70993f79c8a2..7b58b4a1729b 100644
--- a/drivers/media/IR/ir-nec-decoder.c
+++ b/drivers/media/rc/ir-nec-decoder.c
@@ -13,7 +13,7 @@
13 */ 13 */
14 14
15#include <linux/bitrev.h> 15#include <linux/bitrev.h>
16#include "ir-core-priv.h" 16#include "rc-core-priv.h"
17 17
18#define NEC_NBITS 32 18#define NEC_NBITS 32
19#define NEC_UNIT 562500 /* ns */ 19#define NEC_UNIT 562500 /* ns */
@@ -39,19 +39,18 @@ enum nec_state {
39 39
40/** 40/**
41 * ir_nec_decode() - Decode one NEC pulse or space 41 * ir_nec_decode() - Decode one NEC pulse or space
42 * @input_dev: the struct input_dev descriptor of the device 42 * @dev: the struct rc_dev descriptor of the device
43 * @duration: the struct ir_raw_event descriptor of the pulse/space 43 * @duration: the struct ir_raw_event descriptor of the pulse/space
44 * 44 *
45 * This function returns -EINVAL if the pulse violates the state machine 45 * This function returns -EINVAL if the pulse violates the state machine
46 */ 46 */
47static int ir_nec_decode(struct input_dev *input_dev, struct ir_raw_event ev) 47static int ir_nec_decode(struct rc_dev *dev, struct ir_raw_event ev)
48{ 48{
49 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); 49 struct nec_dec *data = &dev->raw->nec;
50 struct nec_dec *data = &ir_dev->raw->nec;
51 u32 scancode; 50 u32 scancode;
52 u8 address, not_address, command, not_command; 51 u8 address, not_address, command, not_command;
53 52
54 if (!(ir_dev->raw->enabled_protocols & IR_TYPE_NEC)) 53 if (!(dev->raw->enabled_protocols & RC_TYPE_NEC))
55 return 0; 54 return 0;
56 55
57 if (!is_timing_event(ev)) { 56 if (!is_timing_event(ev)) {
@@ -89,9 +88,13 @@ static int ir_nec_decode(struct input_dev *input_dev, struct ir_raw_event ev)
89 data->state = STATE_BIT_PULSE; 88 data->state = STATE_BIT_PULSE;
90 return 0; 89 return 0;
91 } else if (eq_margin(ev.duration, NEC_REPEAT_SPACE, NEC_UNIT / 2)) { 90 } else if (eq_margin(ev.duration, NEC_REPEAT_SPACE, NEC_UNIT / 2)) {
92 ir_repeat(input_dev); 91 if (!dev->keypressed) {
93 IR_dprintk(1, "Repeat last key\n"); 92 IR_dprintk(1, "Discarding last key repeat: event after key up\n");
94 data->state = STATE_TRAILER_PULSE; 93 } else {
94 rc_repeat(dev);
95 IR_dprintk(1, "Repeat last key\n");
96 data->state = STATE_TRAILER_PULSE;
97 }
95 return 0; 98 return 0;
96 } 99 }
97 100
@@ -115,7 +118,7 @@ static int ir_nec_decode(struct input_dev *input_dev, struct ir_raw_event ev)
115 geq_margin(ev.duration, 118 geq_margin(ev.duration,
116 NEC_TRAILER_SPACE, NEC_UNIT / 2)) { 119 NEC_TRAILER_SPACE, NEC_UNIT / 2)) {
117 IR_dprintk(1, "Repeat last key\n"); 120 IR_dprintk(1, "Repeat last key\n");
118 ir_repeat(input_dev); 121 rc_repeat(dev);
119 data->state = STATE_INACTIVE; 122 data->state = STATE_INACTIVE;
120 return 0; 123 return 0;
121 124
@@ -179,7 +182,7 @@ static int ir_nec_decode(struct input_dev *input_dev, struct ir_raw_event ev)
179 if (data->is_nec_x) 182 if (data->is_nec_x)
180 data->necx_repeat = true; 183 data->necx_repeat = true;
181 184
182 ir_keydown(input_dev, scancode, 0); 185 rc_keydown(dev, scancode, 0);
183 data->state = STATE_INACTIVE; 186 data->state = STATE_INACTIVE;
184 return 0; 187 return 0;
185 } 188 }
@@ -191,7 +194,7 @@ static int ir_nec_decode(struct input_dev *input_dev, struct ir_raw_event ev)
191} 194}
192 195
193static struct ir_raw_handler nec_handler = { 196static struct ir_raw_handler nec_handler = {
194 .protocols = IR_TYPE_NEC, 197 .protocols = RC_TYPE_NEC,
195 .decode = ir_nec_decode, 198 .decode = ir_nec_decode,
196}; 199};
197 200
diff --git a/drivers/media/IR/ir-raw-event.c b/drivers/media/rc/ir-raw.c
index a06a07e4e0b1..185baddcbf14 100644
--- a/drivers/media/IR/ir-raw-event.c
+++ b/drivers/media/rc/ir-raw.c
@@ -1,4 +1,4 @@
1/* ir-raw-event.c - handle IR Pulse/Space event 1/* ir-raw.c - handle IR pulse/space events
2 * 2 *
3 * Copyright (C) 2010 by Mauro Carvalho Chehab <mchehab@redhat.com> 3 * Copyright (C) 2010 by Mauro Carvalho Chehab <mchehab@redhat.com>
4 * 4 *
@@ -16,7 +16,7 @@
16#include <linux/mutex.h> 16#include <linux/mutex.h>
17#include <linux/sched.h> 17#include <linux/sched.h>
18#include <linux/freezer.h> 18#include <linux/freezer.h>
19#include "ir-core-priv.h" 19#include "rc-core-priv.h"
20 20
21/* Define the max number of pulse/space transitions to buffer */ 21/* Define the max number of pulse/space transitions to buffer */
22#define MAX_IR_EVENT_SIZE 512 22#define MAX_IR_EVENT_SIZE 512
@@ -64,7 +64,7 @@ static int ir_raw_event_thread(void *data)
64 64
65 mutex_lock(&ir_raw_handler_lock); 65 mutex_lock(&ir_raw_handler_lock);
66 list_for_each_entry(handler, &ir_raw_handler_list, list) 66 list_for_each_entry(handler, &ir_raw_handler_list, list)
67 handler->decode(raw->input_dev, ev); 67 handler->decode(raw->dev, ev);
68 raw->prev_ev = ev; 68 raw->prev_ev = ev;
69 mutex_unlock(&ir_raw_handler_lock); 69 mutex_unlock(&ir_raw_handler_lock);
70 } 70 }
@@ -74,7 +74,7 @@ static int ir_raw_event_thread(void *data)
74 74
75/** 75/**
76 * ir_raw_event_store() - pass a pulse/space duration to the raw ir decoders 76 * ir_raw_event_store() - pass a pulse/space duration to the raw ir decoders
77 * @input_dev: the struct input_dev device descriptor 77 * @dev: the struct rc_dev device descriptor
78 * @ev: the struct ir_raw_event descriptor of the pulse/space 78 * @ev: the struct ir_raw_event descriptor of the pulse/space
79 * 79 *
80 * This routine (which may be called from an interrupt context) stores a 80 * This routine (which may be called from an interrupt context) stores a
@@ -82,17 +82,15 @@ static int ir_raw_event_thread(void *data)
82 * signalled as positive values and spaces as negative values. A zero value 82 * signalled as positive values and spaces as negative values. A zero value
83 * will reset the decoding state machines. 83 * will reset the decoding state machines.
84 */ 84 */
85int ir_raw_event_store(struct input_dev *input_dev, struct ir_raw_event *ev) 85int ir_raw_event_store(struct rc_dev *dev, struct ir_raw_event *ev)
86{ 86{
87 struct ir_input_dev *ir = input_get_drvdata(input_dev); 87 if (!dev->raw)
88
89 if (!ir->raw)
90 return -EINVAL; 88 return -EINVAL;
91 89
92 IR_dprintk(2, "sample: (%05dus %s)\n", 90 IR_dprintk(2, "sample: (%05dus %s)\n",
93 TO_US(ev->duration), TO_STR(ev->pulse)); 91 TO_US(ev->duration), TO_STR(ev->pulse));
94 92
95 if (kfifo_in(&ir->raw->kfifo, ev, sizeof(*ev)) != sizeof(*ev)) 93 if (kfifo_in(&dev->raw->kfifo, ev, sizeof(*ev)) != sizeof(*ev))
96 return -ENOMEM; 94 return -ENOMEM;
97 95
98 return 0; 96 return 0;
@@ -101,7 +99,7 @@ EXPORT_SYMBOL_GPL(ir_raw_event_store);
101 99
102/** 100/**
103 * ir_raw_event_store_edge() - notify raw ir decoders of the start of a pulse/space 101 * ir_raw_event_store_edge() - notify raw ir decoders of the start of a pulse/space
104 * @input_dev: the struct input_dev device descriptor 102 * @dev: the struct rc_dev device descriptor
105 * @type: the type of the event that has occurred 103 * @type: the type of the event that has occurred
106 * 104 *
107 * This routine (which may be called from an interrupt context) is used to 105 * This routine (which may be called from an interrupt context) is used to
@@ -110,50 +108,49 @@ EXPORT_SYMBOL_GPL(ir_raw_event_store);
110 * hardware which does not provide durations directly but only interrupts 108 * hardware which does not provide durations directly but only interrupts
111 * (or similar events) on state change. 109 * (or similar events) on state change.
112 */ 110 */
113int ir_raw_event_store_edge(struct input_dev *input_dev, enum raw_event_type type) 111int ir_raw_event_store_edge(struct rc_dev *dev, enum raw_event_type type)
114{ 112{
115 struct ir_input_dev *ir = input_get_drvdata(input_dev);
116 ktime_t now; 113 ktime_t now;
117 s64 delta; /* ns */ 114 s64 delta; /* ns */
118 struct ir_raw_event ev; 115 struct ir_raw_event ev;
119 int rc = 0; 116 int rc = 0;
120 117
121 if (!ir->raw) 118 if (!dev->raw)
122 return -EINVAL; 119 return -EINVAL;
123 120
124 now = ktime_get(); 121 now = ktime_get();
125 delta = ktime_to_ns(ktime_sub(now, ir->raw->last_event)); 122 delta = ktime_to_ns(ktime_sub(now, dev->raw->last_event));
126 123
127 /* Check for a long duration since last event or if we're 124 /* Check for a long duration since last event or if we're
128 * being called for the first time, note that delta can't 125 * being called for the first time, note that delta can't
129 * possibly be negative. 126 * possibly be negative.
130 */ 127 */
131 ev.duration = 0; 128 ev.duration = 0;
132 if (delta > IR_MAX_DURATION || !ir->raw->last_type) 129 if (delta > IR_MAX_DURATION || !dev->raw->last_type)
133 type |= IR_START_EVENT; 130 type |= IR_START_EVENT;
134 else 131 else
135 ev.duration = delta; 132 ev.duration = delta;
136 133
137 if (type & IR_START_EVENT) 134 if (type & IR_START_EVENT)
138 ir_raw_event_reset(input_dev); 135 ir_raw_event_reset(dev);
139 else if (ir->raw->last_type & IR_SPACE) { 136 else if (dev->raw->last_type & IR_SPACE) {
140 ev.pulse = false; 137 ev.pulse = false;
141 rc = ir_raw_event_store(input_dev, &ev); 138 rc = ir_raw_event_store(dev, &ev);
142 } else if (ir->raw->last_type & IR_PULSE) { 139 } else if (dev->raw->last_type & IR_PULSE) {
143 ev.pulse = true; 140 ev.pulse = true;
144 rc = ir_raw_event_store(input_dev, &ev); 141 rc = ir_raw_event_store(dev, &ev);
145 } else 142 } else
146 return 0; 143 return 0;
147 144
148 ir->raw->last_event = now; 145 dev->raw->last_event = now;
149 ir->raw->last_type = type; 146 dev->raw->last_type = type;
150 return rc; 147 return rc;
151} 148}
152EXPORT_SYMBOL_GPL(ir_raw_event_store_edge); 149EXPORT_SYMBOL_GPL(ir_raw_event_store_edge);
153 150
154/** 151/**
155 * ir_raw_event_store_with_filter() - pass next pulse/space to decoders with some processing 152 * ir_raw_event_store_with_filter() - pass next pulse/space to decoders with some processing
156 * @input_dev: the struct input_dev device descriptor 153 * @dev: the struct rc_dev device descriptor
157 * @type: the type of the event that has occurred 154 * @type: the type of the event that has occurred
158 * 155 *
159 * This routine (which may be called from an interrupt context) works 156 * This routine (which may be called from an interrupt context) works
@@ -161,84 +158,76 @@ EXPORT_SYMBOL_GPL(ir_raw_event_store_edge);
161 * This routine is intended for devices with limited internal buffer 158 * This routine is intended for devices with limited internal buffer
162 * It automerges samples of same type, and handles timeouts 159 * It automerges samples of same type, and handles timeouts
163 */ 160 */
164int ir_raw_event_store_with_filter(struct input_dev *input_dev, 161int ir_raw_event_store_with_filter(struct rc_dev *dev, struct ir_raw_event *ev)
165 struct ir_raw_event *ev)
166{ 162{
167 struct ir_input_dev *ir = input_get_drvdata(input_dev); 163 if (!dev->raw)
168 struct ir_raw_event_ctrl *raw = ir->raw;
169
170 if (!raw || !ir->props)
171 return -EINVAL; 164 return -EINVAL;
172 165
173 /* Ignore spaces in idle mode */ 166 /* Ignore spaces in idle mode */
174 if (ir->idle && !ev->pulse) 167 if (dev->idle && !ev->pulse)
175 return 0; 168 return 0;
176 else if (ir->idle) 169 else if (dev->idle)
177 ir_raw_event_set_idle(input_dev, false); 170 ir_raw_event_set_idle(dev, false);
178 171
179 if (!raw->this_ev.duration) { 172 if (!dev->raw->this_ev.duration)
180 raw->this_ev = *ev; 173 dev->raw->this_ev = *ev;
181 } else if (ev->pulse == raw->this_ev.pulse) { 174 else if (ev->pulse == dev->raw->this_ev.pulse)
182 raw->this_ev.duration += ev->duration; 175 dev->raw->this_ev.duration += ev->duration;
183 } else { 176 else {
184 ir_raw_event_store(input_dev, &raw->this_ev); 177 ir_raw_event_store(dev, &dev->raw->this_ev);
185 raw->this_ev = *ev; 178 dev->raw->this_ev = *ev;
186 } 179 }
187 180
188 /* Enter idle mode if nessesary */ 181 /* Enter idle mode if nessesary */
189 if (!ev->pulse && ir->props->timeout && 182 if (!ev->pulse && dev->timeout &&
190 raw->this_ev.duration >= ir->props->timeout) { 183 dev->raw->this_ev.duration >= dev->timeout)
191 ir_raw_event_set_idle(input_dev, true); 184 ir_raw_event_set_idle(dev, true);
192 } 185
193 return 0; 186 return 0;
194} 187}
195EXPORT_SYMBOL_GPL(ir_raw_event_store_with_filter); 188EXPORT_SYMBOL_GPL(ir_raw_event_store_with_filter);
196 189
197/** 190/**
198 * ir_raw_event_set_idle() - hint the ir core if device is receiving 191 * ir_raw_event_set_idle() - provide hint to rc-core when the device is idle or not
199 * IR data or not 192 * @dev: the struct rc_dev device descriptor
200 * @input_dev: the struct input_dev device descriptor 193 * @idle: whether the device is idle or not
201 * @idle: the hint value
202 */ 194 */
203void ir_raw_event_set_idle(struct input_dev *input_dev, bool idle) 195void ir_raw_event_set_idle(struct rc_dev *dev, bool idle)
204{ 196{
205 struct ir_input_dev *ir = input_get_drvdata(input_dev); 197 if (!dev->raw)
206 struct ir_raw_event_ctrl *raw = ir->raw;
207
208 if (!ir->props || !ir->raw)
209 return; 198 return;
210 199
211 IR_dprintk(2, "%s idle mode\n", idle ? "enter" : "leave"); 200 IR_dprintk(2, "%s idle mode\n", idle ? "enter" : "leave");
212 201
213 if (idle) { 202 if (idle) {
214 raw->this_ev.timeout = true; 203 dev->raw->this_ev.timeout = true;
215 ir_raw_event_store(input_dev, &raw->this_ev); 204 ir_raw_event_store(dev, &dev->raw->this_ev);
216 init_ir_raw_event(&raw->this_ev); 205 init_ir_raw_event(&dev->raw->this_ev);
217 } 206 }
218 207
219 if (ir->props->s_idle) 208 if (dev->s_idle)
220 ir->props->s_idle(ir->props->priv, idle); 209 dev->s_idle(dev, idle);
221 ir->idle = idle; 210
211 dev->idle = idle;
222} 212}
223EXPORT_SYMBOL_GPL(ir_raw_event_set_idle); 213EXPORT_SYMBOL_GPL(ir_raw_event_set_idle);
224 214
225/** 215/**
226 * ir_raw_event_handle() - schedules the decoding of stored ir data 216 * ir_raw_event_handle() - schedules the decoding of stored ir data
227 * @input_dev: the struct input_dev device descriptor 217 * @dev: the struct rc_dev device descriptor
228 * 218 *
229 * This routine will signal the workqueue to start decoding stored ir data. 219 * This routine will tell rc-core to start decoding stored ir data.
230 */ 220 */
231void ir_raw_event_handle(struct input_dev *input_dev) 221void ir_raw_event_handle(struct rc_dev *dev)
232{ 222{
233 struct ir_input_dev *ir = input_get_drvdata(input_dev);
234 unsigned long flags; 223 unsigned long flags;
235 224
236 if (!ir->raw) 225 if (!dev->raw)
237 return; 226 return;
238 227
239 spin_lock_irqsave(&ir->raw->lock, flags); 228 spin_lock_irqsave(&dev->raw->lock, flags);
240 wake_up_process(ir->raw->thread); 229 wake_up_process(dev->raw->thread);
241 spin_unlock_irqrestore(&ir->raw->lock, flags); 230 spin_unlock_irqrestore(&dev->raw->lock, flags);
242} 231}
243EXPORT_SYMBOL_GPL(ir_raw_event_handle); 232EXPORT_SYMBOL_GPL(ir_raw_event_handle);
244 233
@@ -256,69 +245,69 @@ ir_raw_get_allowed_protocols()
256/* 245/*
257 * Used to (un)register raw event clients 246 * Used to (un)register raw event clients
258 */ 247 */
259int ir_raw_event_register(struct input_dev *input_dev) 248int ir_raw_event_register(struct rc_dev *dev)
260{ 249{
261 struct ir_input_dev *ir = input_get_drvdata(input_dev);
262 int rc; 250 int rc;
263 struct ir_raw_handler *handler; 251 struct ir_raw_handler *handler;
264 252
265 ir->raw = kzalloc(sizeof(*ir->raw), GFP_KERNEL); 253 if (!dev)
266 if (!ir->raw) 254 return -EINVAL;
267 return -ENOMEM;
268 255
269 ir->raw->input_dev = input_dev; 256 dev->raw = kzalloc(sizeof(*dev->raw), GFP_KERNEL);
257 if (!dev->raw)
258 return -ENOMEM;
270 259
271 ir->raw->enabled_protocols = ~0; 260 dev->raw->dev = dev;
272 rc = kfifo_alloc(&ir->raw->kfifo, sizeof(s64) * MAX_IR_EVENT_SIZE, 261 dev->raw->enabled_protocols = ~0;
262 rc = kfifo_alloc(&dev->raw->kfifo,
263 sizeof(struct ir_raw_event) * MAX_IR_EVENT_SIZE,
273 GFP_KERNEL); 264 GFP_KERNEL);
274 if (rc < 0) { 265 if (rc < 0)
275 kfree(ir->raw); 266 goto out;
276 ir->raw = NULL;
277 return rc;
278 }
279 267
280 spin_lock_init(&ir->raw->lock); 268 spin_lock_init(&dev->raw->lock);
281 ir->raw->thread = kthread_run(ir_raw_event_thread, ir->raw, 269 dev->raw->thread = kthread_run(ir_raw_event_thread, dev->raw,
282 "rc%u", (unsigned int)ir->devno); 270 "rc%ld", dev->devno);
283 271
284 if (IS_ERR(ir->raw->thread)) { 272 if (IS_ERR(dev->raw->thread)) {
285 int ret = PTR_ERR(ir->raw->thread); 273 rc = PTR_ERR(dev->raw->thread);
286 274 goto out;
287 kfree(ir->raw);
288 ir->raw = NULL;
289 return ret;
290 } 275 }
291 276
292 mutex_lock(&ir_raw_handler_lock); 277 mutex_lock(&ir_raw_handler_lock);
293 list_add_tail(&ir->raw->list, &ir_raw_client_list); 278 list_add_tail(&dev->raw->list, &ir_raw_client_list);
294 list_for_each_entry(handler, &ir_raw_handler_list, list) 279 list_for_each_entry(handler, &ir_raw_handler_list, list)
295 if (handler->raw_register) 280 if (handler->raw_register)
296 handler->raw_register(ir->raw->input_dev); 281 handler->raw_register(dev);
297 mutex_unlock(&ir_raw_handler_lock); 282 mutex_unlock(&ir_raw_handler_lock);
298 283
299 return 0; 284 return 0;
285
286out:
287 kfree(dev->raw);
288 dev->raw = NULL;
289 return rc;
300} 290}
301 291
302void ir_raw_event_unregister(struct input_dev *input_dev) 292void ir_raw_event_unregister(struct rc_dev *dev)
303{ 293{
304 struct ir_input_dev *ir = input_get_drvdata(input_dev);
305 struct ir_raw_handler *handler; 294 struct ir_raw_handler *handler;
306 295
307 if (!ir->raw) 296 if (!dev || !dev->raw)
308 return; 297 return;
309 298
310 kthread_stop(ir->raw->thread); 299 kthread_stop(dev->raw->thread);
311 300
312 mutex_lock(&ir_raw_handler_lock); 301 mutex_lock(&ir_raw_handler_lock);
313 list_del(&ir->raw->list); 302 list_del(&dev->raw->list);
314 list_for_each_entry(handler, &ir_raw_handler_list, list) 303 list_for_each_entry(handler, &ir_raw_handler_list, list)
315 if (handler->raw_unregister) 304 if (handler->raw_unregister)
316 handler->raw_unregister(ir->raw->input_dev); 305 handler->raw_unregister(dev);
317 mutex_unlock(&ir_raw_handler_lock); 306 mutex_unlock(&ir_raw_handler_lock);
318 307
319 kfifo_free(&ir->raw->kfifo); 308 kfifo_free(&dev->raw->kfifo);
320 kfree(ir->raw); 309 kfree(dev->raw);
321 ir->raw = NULL; 310 dev->raw = NULL;
322} 311}
323 312
324/* 313/*
@@ -333,7 +322,7 @@ int ir_raw_handler_register(struct ir_raw_handler *ir_raw_handler)
333 list_add_tail(&ir_raw_handler->list, &ir_raw_handler_list); 322 list_add_tail(&ir_raw_handler->list, &ir_raw_handler_list);
334 if (ir_raw_handler->raw_register) 323 if (ir_raw_handler->raw_register)
335 list_for_each_entry(raw, &ir_raw_client_list, list) 324 list_for_each_entry(raw, &ir_raw_client_list, list)
336 ir_raw_handler->raw_register(raw->input_dev); 325 ir_raw_handler->raw_register(raw->dev);
337 available_protocols |= ir_raw_handler->protocols; 326 available_protocols |= ir_raw_handler->protocols;
338 mutex_unlock(&ir_raw_handler_lock); 327 mutex_unlock(&ir_raw_handler_lock);
339 328
@@ -349,7 +338,7 @@ void ir_raw_handler_unregister(struct ir_raw_handler *ir_raw_handler)
349 list_del(&ir_raw_handler->list); 338 list_del(&ir_raw_handler->list);
350 if (ir_raw_handler->raw_unregister) 339 if (ir_raw_handler->raw_unregister)
351 list_for_each_entry(raw, &ir_raw_client_list, list) 340 list_for_each_entry(raw, &ir_raw_client_list, list)
352 ir_raw_handler->raw_unregister(raw->input_dev); 341 ir_raw_handler->raw_unregister(raw->dev);
353 available_protocols &= ~ir_raw_handler->protocols; 342 available_protocols &= ~ir_raw_handler->protocols;
354 mutex_unlock(&ir_raw_handler_lock); 343 mutex_unlock(&ir_raw_handler_lock);
355} 344}
@@ -368,7 +357,7 @@ static void init_decoders(struct work_struct *work)
368 load_lirc_codec(); 357 load_lirc_codec();
369 358
370 /* If needed, we may later add some init code. In this case, 359 /* If needed, we may later add some init code. In this case,
371 it is needed to change the CONFIG_MODULE test at ir-core.h 360 it is needed to change the CONFIG_MODULE test at rc-core.h
372 */ 361 */
373} 362}
374#endif 363#endif
diff --git a/drivers/media/IR/ir-rc5-decoder.c b/drivers/media/rc/ir-rc5-decoder.c
index 572ed4ca8c68..ebdba5539916 100644
--- a/drivers/media/IR/ir-rc5-decoder.c
+++ b/drivers/media/rc/ir-rc5-decoder.c
@@ -20,7 +20,7 @@
20 * the first two bits are start bits, and a third one is a filing bit 20 * the first two bits are start bits, and a third one is a filing bit
21 */ 21 */
22 22
23#include "ir-core-priv.h" 23#include "rc-core-priv.h"
24 24
25#define RC5_NBITS 14 25#define RC5_NBITS 14
26#define RC5X_NBITS 20 26#define RC5X_NBITS 20
@@ -40,19 +40,18 @@ enum rc5_state {
40 40
41/** 41/**
42 * ir_rc5_decode() - Decode one RC-5 pulse or space 42 * ir_rc5_decode() - Decode one RC-5 pulse or space
43 * @input_dev: the struct input_dev descriptor of the device 43 * @dev: the struct rc_dev descriptor of the device
44 * @ev: the struct ir_raw_event descriptor of the pulse/space 44 * @ev: the struct ir_raw_event descriptor of the pulse/space
45 * 45 *
46 * This function returns -EINVAL if the pulse violates the state machine 46 * This function returns -EINVAL if the pulse violates the state machine
47 */ 47 */
48static int ir_rc5_decode(struct input_dev *input_dev, struct ir_raw_event ev) 48static int ir_rc5_decode(struct rc_dev *dev, struct ir_raw_event ev)
49{ 49{
50 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); 50 struct rc5_dec *data = &dev->raw->rc5;
51 struct rc5_dec *data = &ir_dev->raw->rc5;
52 u8 toggle; 51 u8 toggle;
53 u32 scancode; 52 u32 scancode;
54 53
55 if (!(ir_dev->raw->enabled_protocols & IR_TYPE_RC5)) 54 if (!(dev->raw->enabled_protocols & RC_TYPE_RC5))
56 return 0; 55 return 0;
57 56
58 if (!is_timing_event(ev)) { 57 if (!is_timing_event(ev)) {
@@ -96,7 +95,7 @@ again:
96 return 0; 95 return 0;
97 96
98 case STATE_BIT_END: 97 case STATE_BIT_END:
99 if (!is_transition(&ev, &ir_dev->raw->prev_ev)) 98 if (!is_transition(&ev, &dev->raw->prev_ev))
100 break; 99 break;
101 100
102 if (data->count == data->wanted_bits) 101 if (data->count == data->wanted_bits)
@@ -151,7 +150,7 @@ again:
151 scancode, toggle); 150 scancode, toggle);
152 } 151 }
153 152
154 ir_keydown(input_dev, scancode, toggle); 153 rc_keydown(dev, scancode, toggle);
155 data->state = STATE_INACTIVE; 154 data->state = STATE_INACTIVE;
156 return 0; 155 return 0;
157 } 156 }
@@ -164,7 +163,7 @@ out:
164} 163}
165 164
166static struct ir_raw_handler rc5_handler = { 165static struct ir_raw_handler rc5_handler = {
167 .protocols = IR_TYPE_RC5, 166 .protocols = RC_TYPE_RC5,
168 .decode = ir_rc5_decode, 167 .decode = ir_rc5_decode,
169}; 168};
170 169
diff --git a/drivers/media/IR/ir-rc5-sz-decoder.c b/drivers/media/rc/ir-rc5-sz-decoder.c
index 7c413501a3f7..90aa8868629a 100644
--- a/drivers/media/IR/ir-rc5-sz-decoder.c
+++ b/drivers/media/rc/ir-rc5-sz-decoder.c
@@ -20,7 +20,7 @@
20 * the first two bits are start bits, and a third one is a filing bit 20 * the first two bits are start bits, and a third one is a filing bit
21 */ 21 */
22 22
23#include "ir-core-priv.h" 23#include "rc-core-priv.h"
24 24
25#define RC5_SZ_NBITS 15 25#define RC5_SZ_NBITS 15
26#define RC5_UNIT 888888 /* ns */ 26#define RC5_UNIT 888888 /* ns */
@@ -36,19 +36,18 @@ enum rc5_sz_state {
36 36
37/** 37/**
38 * ir_rc5_sz_decode() - Decode one RC-5 Streamzap pulse or space 38 * ir_rc5_sz_decode() - Decode one RC-5 Streamzap pulse or space
39 * @input_dev: the struct input_dev descriptor of the device 39 * @dev: the struct rc_dev descriptor of the device
40 * @ev: the struct ir_raw_event descriptor of the pulse/space 40 * @ev: the struct ir_raw_event descriptor of the pulse/space
41 * 41 *
42 * This function returns -EINVAL if the pulse violates the state machine 42 * This function returns -EINVAL if the pulse violates the state machine
43 */ 43 */
44static int ir_rc5_sz_decode(struct input_dev *input_dev, struct ir_raw_event ev) 44static int ir_rc5_sz_decode(struct rc_dev *dev, struct ir_raw_event ev)
45{ 45{
46 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); 46 struct rc5_sz_dec *data = &dev->raw->rc5_sz;
47 struct rc5_sz_dec *data = &ir_dev->raw->rc5_sz;
48 u8 toggle, command, system; 47 u8 toggle, command, system;
49 u32 scancode; 48 u32 scancode;
50 49
51 if (!(ir_dev->raw->enabled_protocols & IR_TYPE_RC5_SZ)) 50 if (!(dev->raw->enabled_protocols & RC_TYPE_RC5_SZ))
52 return 0; 51 return 0;
53 52
54 if (!is_timing_event(ev)) { 53 if (!is_timing_event(ev)) {
@@ -91,7 +90,7 @@ again:
91 return 0; 90 return 0;
92 91
93 case STATE_BIT_END: 92 case STATE_BIT_END:
94 if (!is_transition(&ev, &ir_dev->raw->prev_ev)) 93 if (!is_transition(&ev, &dev->raw->prev_ev))
95 break; 94 break;
96 95
97 if (data->count == data->wanted_bits) 96 if (data->count == data->wanted_bits)
@@ -115,7 +114,7 @@ again:
115 IR_dprintk(1, "RC5-sz scancode 0x%04x (toggle: %u)\n", 114 IR_dprintk(1, "RC5-sz scancode 0x%04x (toggle: %u)\n",
116 scancode, toggle); 115 scancode, toggle);
117 116
118 ir_keydown(input_dev, scancode, toggle); 117 rc_keydown(dev, scancode, toggle);
119 data->state = STATE_INACTIVE; 118 data->state = STATE_INACTIVE;
120 return 0; 119 return 0;
121 } 120 }
@@ -128,7 +127,7 @@ out:
128} 127}
129 128
130static struct ir_raw_handler rc5_sz_handler = { 129static struct ir_raw_handler rc5_sz_handler = {
131 .protocols = IR_TYPE_RC5_SZ, 130 .protocols = RC_TYPE_RC5_SZ,
132 .decode = ir_rc5_sz_decode, 131 .decode = ir_rc5_sz_decode,
133}; 132};
134 133
diff --git a/drivers/media/IR/ir-rc6-decoder.c b/drivers/media/rc/ir-rc6-decoder.c
index d25da91f44ff..755dafa3871b 100644
--- a/drivers/media/IR/ir-rc6-decoder.c
+++ b/drivers/media/rc/ir-rc6-decoder.c
@@ -12,7 +12,7 @@
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 */ 13 */
14 14
15#include "ir-core-priv.h" 15#include "rc-core-priv.h"
16 16
17/* 17/*
18 * This decoder currently supports: 18 * This decoder currently supports:
@@ -70,19 +70,18 @@ static enum rc6_mode rc6_mode(struct rc6_dec *data)
70 70
71/** 71/**
72 * ir_rc6_decode() - Decode one RC6 pulse or space 72 * ir_rc6_decode() - Decode one RC6 pulse or space
73 * @input_dev: the struct input_dev descriptor of the device 73 * @dev: the struct rc_dev descriptor of the device
74 * @ev: the struct ir_raw_event descriptor of the pulse/space 74 * @ev: the struct ir_raw_event descriptor of the pulse/space
75 * 75 *
76 * This function returns -EINVAL if the pulse violates the state machine 76 * This function returns -EINVAL if the pulse violates the state machine
77 */ 77 */
78static int ir_rc6_decode(struct input_dev *input_dev, struct ir_raw_event ev) 78static int ir_rc6_decode(struct rc_dev *dev, struct ir_raw_event ev)
79{ 79{
80 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); 80 struct rc6_dec *data = &dev->raw->rc6;
81 struct rc6_dec *data = &ir_dev->raw->rc6;
82 u32 scancode; 81 u32 scancode;
83 u8 toggle; 82 u8 toggle;
84 83
85 if (!(ir_dev->raw->enabled_protocols & IR_TYPE_RC6)) 84 if (!(dev->raw->enabled_protocols & RC_TYPE_RC6))
86 return 0; 85 return 0;
87 86
88 if (!is_timing_event(ev)) { 87 if (!is_timing_event(ev)) {
@@ -139,7 +138,7 @@ again:
139 return 0; 138 return 0;
140 139
141 case STATE_HEADER_BIT_END: 140 case STATE_HEADER_BIT_END:
142 if (!is_transition(&ev, &ir_dev->raw->prev_ev)) 141 if (!is_transition(&ev, &dev->raw->prev_ev))
143 break; 142 break;
144 143
145 if (data->count == RC6_HEADER_NBITS) 144 if (data->count == RC6_HEADER_NBITS)
@@ -159,7 +158,7 @@ again:
159 return 0; 158 return 0;
160 159
161 case STATE_TOGGLE_END: 160 case STATE_TOGGLE_END:
162 if (!is_transition(&ev, &ir_dev->raw->prev_ev) || 161 if (!is_transition(&ev, &dev->raw->prev_ev) ||
163 !geq_margin(ev.duration, RC6_TOGGLE_END, RC6_UNIT / 2)) 162 !geq_margin(ev.duration, RC6_TOGGLE_END, RC6_UNIT / 2))
164 break; 163 break;
165 164
@@ -204,7 +203,7 @@ again:
204 return 0; 203 return 0;
205 204
206 case STATE_BODY_BIT_END: 205 case STATE_BODY_BIT_END:
207 if (!is_transition(&ev, &ir_dev->raw->prev_ev)) 206 if (!is_transition(&ev, &dev->raw->prev_ev))
208 break; 207 break;
209 208
210 if (data->count == data->wanted_bits) 209 if (data->count == data->wanted_bits)
@@ -243,7 +242,7 @@ again:
243 goto out; 242 goto out;
244 } 243 }
245 244
246 ir_keydown(input_dev, scancode, toggle); 245 rc_keydown(dev, scancode, toggle);
247 data->state = STATE_INACTIVE; 246 data->state = STATE_INACTIVE;
248 return 0; 247 return 0;
249 } 248 }
@@ -256,7 +255,7 @@ out:
256} 255}
257 256
258static struct ir_raw_handler rc6_handler = { 257static struct ir_raw_handler rc6_handler = {
259 .protocols = IR_TYPE_RC6, 258 .protocols = RC_TYPE_RC6,
260 .decode = ir_rc6_decode, 259 .decode = ir_rc6_decode,
261}; 260};
262 261
diff --git a/drivers/media/IR/ir-sony-decoder.c b/drivers/media/rc/ir-sony-decoder.c
index 2d15730822bc..a92de80c48db 100644
--- a/drivers/media/IR/ir-sony-decoder.c
+++ b/drivers/media/rc/ir-sony-decoder.c
@@ -13,7 +13,7 @@
13 */ 13 */
14 14
15#include <linux/bitrev.h> 15#include <linux/bitrev.h>
16#include "ir-core-priv.h" 16#include "rc-core-priv.h"
17 17
18#define SONY_UNIT 600000 /* ns */ 18#define SONY_UNIT 600000 /* ns */
19#define SONY_HEADER_PULSE (4 * SONY_UNIT) 19#define SONY_HEADER_PULSE (4 * SONY_UNIT)
@@ -33,19 +33,18 @@ enum sony_state {
33 33
34/** 34/**
35 * ir_sony_decode() - Decode one Sony pulse or space 35 * ir_sony_decode() - Decode one Sony pulse or space
36 * @input_dev: the struct input_dev descriptor of the device 36 * @dev: the struct rc_dev descriptor of the device
37 * @ev: the struct ir_raw_event descriptor of the pulse/space 37 * @ev: the struct ir_raw_event descriptor of the pulse/space
38 * 38 *
39 * This function returns -EINVAL if the pulse violates the state machine 39 * This function returns -EINVAL if the pulse violates the state machine
40 */ 40 */
41static int ir_sony_decode(struct input_dev *input_dev, struct ir_raw_event ev) 41static int ir_sony_decode(struct rc_dev *dev, struct ir_raw_event ev)
42{ 42{
43 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); 43 struct sony_dec *data = &dev->raw->sony;
44 struct sony_dec *data = &ir_dev->raw->sony;
45 u32 scancode; 44 u32 scancode;
46 u8 device, subdevice, function; 45 u8 device, subdevice, function;
47 46
48 if (!(ir_dev->raw->enabled_protocols & IR_TYPE_SONY)) 47 if (!(dev->raw->enabled_protocols & RC_TYPE_SONY))
49 return 0; 48 return 0;
50 49
51 if (!is_timing_event(ev)) { 50 if (!is_timing_event(ev)) {
@@ -144,7 +143,7 @@ static int ir_sony_decode(struct input_dev *input_dev, struct ir_raw_event ev)
144 143
145 scancode = device << 16 | subdevice << 8 | function; 144 scancode = device << 16 | subdevice << 8 | function;
146 IR_dprintk(1, "Sony(%u) scancode 0x%05x\n", data->count, scancode); 145 IR_dprintk(1, "Sony(%u) scancode 0x%05x\n", data->count, scancode);
147 ir_keydown(input_dev, scancode, 0); 146 rc_keydown(dev, scancode, 0);
148 data->state = STATE_INACTIVE; 147 data->state = STATE_INACTIVE;
149 return 0; 148 return 0;
150 } 149 }
@@ -157,7 +156,7 @@ out:
157} 156}
158 157
159static struct ir_raw_handler sony_handler = { 158static struct ir_raw_handler sony_handler = {
160 .protocols = IR_TYPE_SONY, 159 .protocols = RC_TYPE_SONY,
161 .decode = ir_sony_decode, 160 .decode = ir_sony_decode,
162}; 161};
163 162
diff --git a/drivers/media/IR/keymaps/Kconfig b/drivers/media/rc/keymaps/Kconfig
index 14b22f58f823..8e615fd55852 100644
--- a/drivers/media/IR/keymaps/Kconfig
+++ b/drivers/media/rc/keymaps/Kconfig
@@ -1,6 +1,6 @@
1config RC_MAP 1config RC_MAP
2 tristate "Compile Remote Controller keymap modules" 2 tristate "Compile Remote Controller keymap modules"
3 depends on IR_CORE 3 depends on RC_CORE
4 default y 4 default y
5 5
6 ---help--- 6 ---help---
diff --git a/drivers/media/IR/keymaps/Makefile b/drivers/media/rc/keymaps/Makefile
index 3194d391bbd4..0659e9f50144 100644
--- a/drivers/media/IR/keymaps/Makefile
+++ b/drivers/media/rc/keymaps/Makefile
@@ -62,6 +62,7 @@ obj-$(CONFIG_RC_MAP) += rc-adstech-dvb-t-pci.o \
62 rc-pinnacle-pctv-hd.o \ 62 rc-pinnacle-pctv-hd.o \
63 rc-pixelview.o \ 63 rc-pixelview.o \
64 rc-pixelview-mk12.o \ 64 rc-pixelview-mk12.o \
65 rc-pixelview-002t.o \
65 rc-pixelview-new.o \ 66 rc-pixelview-new.o \
66 rc-powercolor-real-angel.o \ 67 rc-powercolor-real-angel.o \
67 rc-proteus-2309.o \ 68 rc-proteus-2309.o \
@@ -80,6 +81,7 @@ obj-$(CONFIG_RC_MAP) += rc-adstech-dvb-t-pci.o \
80 rc-trekstor.o \ 81 rc-trekstor.o \
81 rc-tt-1500.o \ 82 rc-tt-1500.o \
82 rc-twinhan1027.o \ 83 rc-twinhan1027.o \
84 rc-videomate-m1f.o \
83 rc-videomate-s350.o \ 85 rc-videomate-s350.o \
84 rc-videomate-tv-pvr.o \ 86 rc-videomate-tv-pvr.o \
85 rc-winfast.o \ 87 rc-winfast.o \
diff --git a/drivers/media/IR/keymaps/rc-adstech-dvb-t-pci.c b/drivers/media/rc/keymaps/rc-adstech-dvb-t-pci.c
index b17283176ecd..136d3952dedc 100644
--- a/drivers/media/IR/keymaps/rc-adstech-dvb-t-pci.c
+++ b/drivers/media/rc/keymaps/rc-adstech-dvb-t-pci.c
@@ -14,7 +14,7 @@
14 14
15/* ADS Tech Instant TV DVB-T PCI Remote */ 15/* ADS Tech Instant TV DVB-T PCI Remote */
16 16
17static struct ir_scancode adstech_dvb_t_pci[] = { 17static struct rc_map_table adstech_dvb_t_pci[] = {
18 /* Keys 0 to 9 */ 18 /* Keys 0 to 9 */
19 { 0x4d, KEY_0 }, 19 { 0x4d, KEY_0 },
20 { 0x57, KEY_1 }, 20 { 0x57, KEY_1 },
@@ -63,23 +63,23 @@ static struct ir_scancode adstech_dvb_t_pci[] = {
63 { 0x1c, KEY_VOLUMEDOWN }, 63 { 0x1c, KEY_VOLUMEDOWN },
64}; 64};
65 65
66static struct rc_keymap adstech_dvb_t_pci_map = { 66static struct rc_map_list adstech_dvb_t_pci_map = {
67 .map = { 67 .map = {
68 .scan = adstech_dvb_t_pci, 68 .scan = adstech_dvb_t_pci,
69 .size = ARRAY_SIZE(adstech_dvb_t_pci), 69 .size = ARRAY_SIZE(adstech_dvb_t_pci),
70 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 70 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
71 .name = RC_MAP_ADSTECH_DVB_T_PCI, 71 .name = RC_MAP_ADSTECH_DVB_T_PCI,
72 } 72 }
73}; 73};
74 74
75static int __init init_rc_map_adstech_dvb_t_pci(void) 75static int __init init_rc_map_adstech_dvb_t_pci(void)
76{ 76{
77 return ir_register_map(&adstech_dvb_t_pci_map); 77 return rc_map_register(&adstech_dvb_t_pci_map);
78} 78}
79 79
80static void __exit exit_rc_map_adstech_dvb_t_pci(void) 80static void __exit exit_rc_map_adstech_dvb_t_pci(void)
81{ 81{
82 ir_unregister_map(&adstech_dvb_t_pci_map); 82 rc_map_unregister(&adstech_dvb_t_pci_map);
83} 83}
84 84
85module_init(init_rc_map_adstech_dvb_t_pci) 85module_init(init_rc_map_adstech_dvb_t_pci)
diff --git a/drivers/media/IR/keymaps/rc-alink-dtu-m.c b/drivers/media/rc/keymaps/rc-alink-dtu-m.c
index ddfee7f8093d..fe652e928dc0 100644
--- a/drivers/media/IR/keymaps/rc-alink-dtu-m.c
+++ b/drivers/media/rc/keymaps/rc-alink-dtu-m.c
@@ -21,7 +21,7 @@
21#include <media/rc-map.h> 21#include <media/rc-map.h>
22 22
23/* A-Link DTU(m) slim remote, 6 rows, 3 columns. */ 23/* A-Link DTU(m) slim remote, 6 rows, 3 columns. */
24static struct ir_scancode alink_dtu_m[] = { 24static struct rc_map_table alink_dtu_m[] = {
25 { 0x0800, KEY_VOLUMEUP }, 25 { 0x0800, KEY_VOLUMEUP },
26 { 0x0801, KEY_1 }, 26 { 0x0801, KEY_1 },
27 { 0x0802, KEY_3 }, 27 { 0x0802, KEY_3 },
@@ -42,23 +42,23 @@ static struct ir_scancode alink_dtu_m[] = {
42 { 0x081d, KEY_CHANNELDOWN }, 42 { 0x081d, KEY_CHANNELDOWN },
43}; 43};
44 44
45static struct rc_keymap alink_dtu_m_map = { 45static struct rc_map_list alink_dtu_m_map = {
46 .map = { 46 .map = {
47 .scan = alink_dtu_m, 47 .scan = alink_dtu_m,
48 .size = ARRAY_SIZE(alink_dtu_m), 48 .size = ARRAY_SIZE(alink_dtu_m),
49 .ir_type = IR_TYPE_NEC, 49 .rc_type = RC_TYPE_NEC,
50 .name = RC_MAP_ALINK_DTU_M, 50 .name = RC_MAP_ALINK_DTU_M,
51 } 51 }
52}; 52};
53 53
54static int __init init_rc_map_alink_dtu_m(void) 54static int __init init_rc_map_alink_dtu_m(void)
55{ 55{
56 return ir_register_map(&alink_dtu_m_map); 56 return rc_map_register(&alink_dtu_m_map);
57} 57}
58 58
59static void __exit exit_rc_map_alink_dtu_m(void) 59static void __exit exit_rc_map_alink_dtu_m(void)
60{ 60{
61 ir_unregister_map(&alink_dtu_m_map); 61 rc_map_unregister(&alink_dtu_m_map);
62} 62}
63 63
64module_init(init_rc_map_alink_dtu_m) 64module_init(init_rc_map_alink_dtu_m)
diff --git a/drivers/media/IR/keymaps/rc-anysee.c b/drivers/media/rc/keymaps/rc-anysee.c
index 30d70498cfed..884f1b51a8ee 100644
--- a/drivers/media/IR/keymaps/rc-anysee.c
+++ b/drivers/media/rc/keymaps/rc-anysee.c
@@ -20,7 +20,7 @@
20 20
21#include <media/rc-map.h> 21#include <media/rc-map.h>
22 22
23static struct ir_scancode anysee[] = { 23static struct rc_map_table anysee[] = {
24 { 0x0800, KEY_0 }, 24 { 0x0800, KEY_0 },
25 { 0x0801, KEY_1 }, 25 { 0x0801, KEY_1 },
26 { 0x0802, KEY_2 }, 26 { 0x0802, KEY_2 },
@@ -67,23 +67,23 @@ static struct ir_scancode anysee[] = {
67 { 0x0851, KEY_PAUSE }, 67 { 0x0851, KEY_PAUSE },
68}; 68};
69 69
70static struct rc_keymap anysee_map = { 70static struct rc_map_list anysee_map = {
71 .map = { 71 .map = {
72 .scan = anysee, 72 .scan = anysee,
73 .size = ARRAY_SIZE(anysee), 73 .size = ARRAY_SIZE(anysee),
74 .ir_type = IR_TYPE_NEC, 74 .rc_type = RC_TYPE_NEC,
75 .name = RC_MAP_ANYSEE, 75 .name = RC_MAP_ANYSEE,
76 } 76 }
77}; 77};
78 78
79static int __init init_rc_map_anysee(void) 79static int __init init_rc_map_anysee(void)
80{ 80{
81 return ir_register_map(&anysee_map); 81 return rc_map_register(&anysee_map);
82} 82}
83 83
84static void __exit exit_rc_map_anysee(void) 84static void __exit exit_rc_map_anysee(void)
85{ 85{
86 ir_unregister_map(&anysee_map); 86 rc_map_unregister(&anysee_map);
87} 87}
88 88
89module_init(init_rc_map_anysee) 89module_init(init_rc_map_anysee)
diff --git a/drivers/media/IR/keymaps/rc-apac-viewcomp.c b/drivers/media/rc/keymaps/rc-apac-viewcomp.c
index 0ef2b562baf0..7af188209ff9 100644
--- a/drivers/media/IR/keymaps/rc-apac-viewcomp.c
+++ b/drivers/media/rc/keymaps/rc-apac-viewcomp.c
@@ -14,7 +14,7 @@
14 14
15/* Attila Kondoros <attila.kondoros@chello.hu> */ 15/* Attila Kondoros <attila.kondoros@chello.hu> */
16 16
17static struct ir_scancode apac_viewcomp[] = { 17static struct rc_map_table apac_viewcomp[] = {
18 18
19 { 0x01, KEY_1 }, 19 { 0x01, KEY_1 },
20 { 0x02, KEY_2 }, 20 { 0x02, KEY_2 },
@@ -54,23 +54,23 @@ static struct ir_scancode apac_viewcomp[] = {
54 { 0x18, KEY_KPMINUS }, /* fine tune <<<< */ 54 { 0x18, KEY_KPMINUS }, /* fine tune <<<< */
55}; 55};
56 56
57static struct rc_keymap apac_viewcomp_map = { 57static struct rc_map_list apac_viewcomp_map = {
58 .map = { 58 .map = {
59 .scan = apac_viewcomp, 59 .scan = apac_viewcomp,
60 .size = ARRAY_SIZE(apac_viewcomp), 60 .size = ARRAY_SIZE(apac_viewcomp),
61 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 61 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
62 .name = RC_MAP_APAC_VIEWCOMP, 62 .name = RC_MAP_APAC_VIEWCOMP,
63 } 63 }
64}; 64};
65 65
66static int __init init_rc_map_apac_viewcomp(void) 66static int __init init_rc_map_apac_viewcomp(void)
67{ 67{
68 return ir_register_map(&apac_viewcomp_map); 68 return rc_map_register(&apac_viewcomp_map);
69} 69}
70 70
71static void __exit exit_rc_map_apac_viewcomp(void) 71static void __exit exit_rc_map_apac_viewcomp(void)
72{ 72{
73 ir_unregister_map(&apac_viewcomp_map); 73 rc_map_unregister(&apac_viewcomp_map);
74} 74}
75 75
76module_init(init_rc_map_apac_viewcomp) 76module_init(init_rc_map_apac_viewcomp)
diff --git a/drivers/media/IR/keymaps/rc-asus-pc39.c b/drivers/media/rc/keymaps/rc-asus-pc39.c
index 2996e0a3b8d5..b2481154491b 100644
--- a/drivers/media/IR/keymaps/rc-asus-pc39.c
+++ b/drivers/media/rc/keymaps/rc-asus-pc39.c
@@ -18,7 +18,7 @@
18 * which has a label saying is "Model PC-39" 18 * which has a label saying is "Model PC-39"
19 */ 19 */
20 20
21static struct ir_scancode asus_pc39[] = { 21static struct rc_map_table asus_pc39[] = {
22 /* Keys 0 to 9 */ 22 /* Keys 0 to 9 */
23 { 0x082a, KEY_0 }, 23 { 0x082a, KEY_0 },
24 { 0x0816, KEY_1 }, 24 { 0x0816, KEY_1 },
@@ -65,23 +65,23 @@ static struct ir_scancode asus_pc39[] = {
65 { 0x083e, KEY_DVD }, /* dvd */ 65 { 0x083e, KEY_DVD }, /* dvd */
66}; 66};
67 67
68static struct rc_keymap asus_pc39_map = { 68static struct rc_map_list asus_pc39_map = {
69 .map = { 69 .map = {
70 .scan = asus_pc39, 70 .scan = asus_pc39,
71 .size = ARRAY_SIZE(asus_pc39), 71 .size = ARRAY_SIZE(asus_pc39),
72 .ir_type = IR_TYPE_RC5, 72 .rc_type = RC_TYPE_RC5,
73 .name = RC_MAP_ASUS_PC39, 73 .name = RC_MAP_ASUS_PC39,
74 } 74 }
75}; 75};
76 76
77static int __init init_rc_map_asus_pc39(void) 77static int __init init_rc_map_asus_pc39(void)
78{ 78{
79 return ir_register_map(&asus_pc39_map); 79 return rc_map_register(&asus_pc39_map);
80} 80}
81 81
82static void __exit exit_rc_map_asus_pc39(void) 82static void __exit exit_rc_map_asus_pc39(void)
83{ 83{
84 ir_unregister_map(&asus_pc39_map); 84 rc_map_unregister(&asus_pc39_map);
85} 85}
86 86
87module_init(init_rc_map_asus_pc39) 87module_init(init_rc_map_asus_pc39)
diff --git a/drivers/media/IR/keymaps/rc-ati-tv-wonder-hd-600.c b/drivers/media/rc/keymaps/rc-ati-tv-wonder-hd-600.c
index 8edfd293d010..f766b24b0158 100644
--- a/drivers/media/IR/keymaps/rc-ati-tv-wonder-hd-600.c
+++ b/drivers/media/rc/keymaps/rc-ati-tv-wonder-hd-600.c
@@ -16,7 +16,7 @@
16 Devin Heitmueller <devin.heitmueller@gmail.com> 16 Devin Heitmueller <devin.heitmueller@gmail.com>
17 */ 17 */
18 18
19static struct ir_scancode ati_tv_wonder_hd_600[] = { 19static struct rc_map_table ati_tv_wonder_hd_600[] = {
20 { 0x00, KEY_RECORD}, /* Row 1 */ 20 { 0x00, KEY_RECORD}, /* Row 1 */
21 { 0x01, KEY_PLAYPAUSE}, 21 { 0x01, KEY_PLAYPAUSE},
22 { 0x02, KEY_STOP}, 22 { 0x02, KEY_STOP},
@@ -43,23 +43,23 @@ static struct ir_scancode ati_tv_wonder_hd_600[] = {
43 { 0x17, KEY_VOLUMEDOWN}, 43 { 0x17, KEY_VOLUMEDOWN},
44}; 44};
45 45
46static struct rc_keymap ati_tv_wonder_hd_600_map = { 46static struct rc_map_list ati_tv_wonder_hd_600_map = {
47 .map = { 47 .map = {
48 .scan = ati_tv_wonder_hd_600, 48 .scan = ati_tv_wonder_hd_600,
49 .size = ARRAY_SIZE(ati_tv_wonder_hd_600), 49 .size = ARRAY_SIZE(ati_tv_wonder_hd_600),
50 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 50 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
51 .name = RC_MAP_ATI_TV_WONDER_HD_600, 51 .name = RC_MAP_ATI_TV_WONDER_HD_600,
52 } 52 }
53}; 53};
54 54
55static int __init init_rc_map_ati_tv_wonder_hd_600(void) 55static int __init init_rc_map_ati_tv_wonder_hd_600(void)
56{ 56{
57 return ir_register_map(&ati_tv_wonder_hd_600_map); 57 return rc_map_register(&ati_tv_wonder_hd_600_map);
58} 58}
59 59
60static void __exit exit_rc_map_ati_tv_wonder_hd_600(void) 60static void __exit exit_rc_map_ati_tv_wonder_hd_600(void)
61{ 61{
62 ir_unregister_map(&ati_tv_wonder_hd_600_map); 62 rc_map_unregister(&ati_tv_wonder_hd_600_map);
63} 63}
64 64
65module_init(init_rc_map_ati_tv_wonder_hd_600) 65module_init(init_rc_map_ati_tv_wonder_hd_600)
diff --git a/drivers/media/IR/keymaps/rc-avermedia-a16d.c b/drivers/media/rc/keymaps/rc-avermedia-a16d.c
index 12f043587f2e..ec9beeebd410 100644
--- a/drivers/media/IR/keymaps/rc-avermedia-a16d.c
+++ b/drivers/media/rc/keymaps/rc-avermedia-a16d.c
@@ -12,7 +12,7 @@
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14 14
15static struct ir_scancode avermedia_a16d[] = { 15static struct rc_map_table avermedia_a16d[] = {
16 { 0x20, KEY_LIST}, 16 { 0x20, KEY_LIST},
17 { 0x00, KEY_POWER}, 17 { 0x00, KEY_POWER},
18 { 0x28, KEY_1}, 18 { 0x28, KEY_1},
@@ -49,23 +49,23 @@ static struct ir_scancode avermedia_a16d[] = {
49 { 0x2a, KEY_MENU}, 49 { 0x2a, KEY_MENU},
50}; 50};
51 51
52static struct rc_keymap avermedia_a16d_map = { 52static struct rc_map_list avermedia_a16d_map = {
53 .map = { 53 .map = {
54 .scan = avermedia_a16d, 54 .scan = avermedia_a16d,
55 .size = ARRAY_SIZE(avermedia_a16d), 55 .size = ARRAY_SIZE(avermedia_a16d),
56 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 56 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
57 .name = RC_MAP_AVERMEDIA_A16D, 57 .name = RC_MAP_AVERMEDIA_A16D,
58 } 58 }
59}; 59};
60 60
61static int __init init_rc_map_avermedia_a16d(void) 61static int __init init_rc_map_avermedia_a16d(void)
62{ 62{
63 return ir_register_map(&avermedia_a16d_map); 63 return rc_map_register(&avermedia_a16d_map);
64} 64}
65 65
66static void __exit exit_rc_map_avermedia_a16d(void) 66static void __exit exit_rc_map_avermedia_a16d(void)
67{ 67{
68 ir_unregister_map(&avermedia_a16d_map); 68 rc_map_unregister(&avermedia_a16d_map);
69} 69}
70 70
71module_init(init_rc_map_avermedia_a16d) 71module_init(init_rc_map_avermedia_a16d)
diff --git a/drivers/media/IR/keymaps/rc-avermedia-cardbus.c b/drivers/media/rc/keymaps/rc-avermedia-cardbus.c
index 2a945b02e8ca..bdf97b74cf90 100644
--- a/drivers/media/IR/keymaps/rc-avermedia-cardbus.c
+++ b/drivers/media/rc/keymaps/rc-avermedia-cardbus.c
@@ -14,7 +14,7 @@
14 14
15/* Oldrich Jedlicka <oldium.pro@seznam.cz> */ 15/* Oldrich Jedlicka <oldium.pro@seznam.cz> */
16 16
17static struct ir_scancode avermedia_cardbus[] = { 17static struct rc_map_table avermedia_cardbus[] = {
18 { 0x00, KEY_POWER }, 18 { 0x00, KEY_POWER },
19 { 0x01, KEY_TUNER }, /* TV/FM */ 19 { 0x01, KEY_TUNER }, /* TV/FM */
20 { 0x03, KEY_TEXT }, /* Teletext */ 20 { 0x03, KEY_TEXT }, /* Teletext */
@@ -71,23 +71,23 @@ static struct ir_scancode avermedia_cardbus[] = {
71 { 0x43, KEY_CHANNELUP }, /* Channel up */ 71 { 0x43, KEY_CHANNELUP }, /* Channel up */
72}; 72};
73 73
74static struct rc_keymap avermedia_cardbus_map = { 74static struct rc_map_list avermedia_cardbus_map = {
75 .map = { 75 .map = {
76 .scan = avermedia_cardbus, 76 .scan = avermedia_cardbus,
77 .size = ARRAY_SIZE(avermedia_cardbus), 77 .size = ARRAY_SIZE(avermedia_cardbus),
78 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 78 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
79 .name = RC_MAP_AVERMEDIA_CARDBUS, 79 .name = RC_MAP_AVERMEDIA_CARDBUS,
80 } 80 }
81}; 81};
82 82
83static int __init init_rc_map_avermedia_cardbus(void) 83static int __init init_rc_map_avermedia_cardbus(void)
84{ 84{
85 return ir_register_map(&avermedia_cardbus_map); 85 return rc_map_register(&avermedia_cardbus_map);
86} 86}
87 87
88static void __exit exit_rc_map_avermedia_cardbus(void) 88static void __exit exit_rc_map_avermedia_cardbus(void)
89{ 89{
90 ir_unregister_map(&avermedia_cardbus_map); 90 rc_map_unregister(&avermedia_cardbus_map);
91} 91}
92 92
93module_init(init_rc_map_avermedia_cardbus) 93module_init(init_rc_map_avermedia_cardbus)
diff --git a/drivers/media/IR/keymaps/rc-avermedia-dvbt.c b/drivers/media/rc/keymaps/rc-avermedia-dvbt.c
index 39dde6222875..3ddb41bc075e 100644
--- a/drivers/media/IR/keymaps/rc-avermedia-dvbt.c
+++ b/drivers/media/rc/keymaps/rc-avermedia-dvbt.c
@@ -14,7 +14,7 @@
14 14
15/* Matt Jesson <dvb@jesson.eclipse.co.uk */ 15/* Matt Jesson <dvb@jesson.eclipse.co.uk */
16 16
17static struct ir_scancode avermedia_dvbt[] = { 17static struct rc_map_table avermedia_dvbt[] = {
18 { 0x28, KEY_0 }, /* '0' / 'enter' */ 18 { 0x28, KEY_0 }, /* '0' / 'enter' */
19 { 0x22, KEY_1 }, /* '1' */ 19 { 0x22, KEY_1 }, /* '1' */
20 { 0x12, KEY_2 }, /* '2' / 'up arrow' */ 20 { 0x12, KEY_2 }, /* '2' / 'up arrow' */
@@ -52,23 +52,23 @@ static struct ir_scancode avermedia_dvbt[] = {
52 { 0x3e, KEY_VOLUMEUP }, /* 'volume +' */ 52 { 0x3e, KEY_VOLUMEUP }, /* 'volume +' */
53}; 53};
54 54
55static struct rc_keymap avermedia_dvbt_map = { 55static struct rc_map_list avermedia_dvbt_map = {
56 .map = { 56 .map = {
57 .scan = avermedia_dvbt, 57 .scan = avermedia_dvbt,
58 .size = ARRAY_SIZE(avermedia_dvbt), 58 .size = ARRAY_SIZE(avermedia_dvbt),
59 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 59 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
60 .name = RC_MAP_AVERMEDIA_DVBT, 60 .name = RC_MAP_AVERMEDIA_DVBT,
61 } 61 }
62}; 62};
63 63
64static int __init init_rc_map_avermedia_dvbt(void) 64static int __init init_rc_map_avermedia_dvbt(void)
65{ 65{
66 return ir_register_map(&avermedia_dvbt_map); 66 return rc_map_register(&avermedia_dvbt_map);
67} 67}
68 68
69static void __exit exit_rc_map_avermedia_dvbt(void) 69static void __exit exit_rc_map_avermedia_dvbt(void)
70{ 70{
71 ir_unregister_map(&avermedia_dvbt_map); 71 rc_map_unregister(&avermedia_dvbt_map);
72} 72}
73 73
74module_init(init_rc_map_avermedia_dvbt) 74module_init(init_rc_map_avermedia_dvbt)
diff --git a/drivers/media/IR/keymaps/rc-avermedia-m135a.c b/drivers/media/rc/keymaps/rc-avermedia-m135a.c
index e4471fb2ad1e..357fea58a46e 100644
--- a/drivers/media/IR/keymaps/rc-avermedia-m135a.c
+++ b/drivers/media/rc/keymaps/rc-avermedia-m135a.c
@@ -22,7 +22,7 @@
22 * codes added by Herton Ronaldo Krzesinski <herton@mandriva.com.br> 22 * codes added by Herton Ronaldo Krzesinski <herton@mandriva.com.br>
23 */ 23 */
24 24
25static struct ir_scancode avermedia_m135a[] = { 25static struct rc_map_table avermedia_m135a[] = {
26 /* RM-JX */ 26 /* RM-JX */
27 { 0x0200, KEY_POWER2 }, 27 { 0x0200, KEY_POWER2 },
28 { 0x022e, KEY_DOT }, /* '.' */ 28 { 0x022e, KEY_DOT }, /* '.' */
@@ -121,23 +121,23 @@ static struct ir_scancode avermedia_m135a[] = {
121 { 0x041e, KEY_NEXT }, 121 { 0x041e, KEY_NEXT },
122}; 122};
123 123
124static struct rc_keymap avermedia_m135a_map = { 124static struct rc_map_list avermedia_m135a_map = {
125 .map = { 125 .map = {
126 .scan = avermedia_m135a, 126 .scan = avermedia_m135a,
127 .size = ARRAY_SIZE(avermedia_m135a), 127 .size = ARRAY_SIZE(avermedia_m135a),
128 .ir_type = IR_TYPE_NEC, 128 .rc_type = RC_TYPE_NEC,
129 .name = RC_MAP_AVERMEDIA_M135A, 129 .name = RC_MAP_AVERMEDIA_M135A,
130 } 130 }
131}; 131};
132 132
133static int __init init_rc_map_avermedia_m135a(void) 133static int __init init_rc_map_avermedia_m135a(void)
134{ 134{
135 return ir_register_map(&avermedia_m135a_map); 135 return rc_map_register(&avermedia_m135a_map);
136} 136}
137 137
138static void __exit exit_rc_map_avermedia_m135a(void) 138static void __exit exit_rc_map_avermedia_m135a(void)
139{ 139{
140 ir_unregister_map(&avermedia_m135a_map); 140 rc_map_unregister(&avermedia_m135a_map);
141} 141}
142 142
143module_init(init_rc_map_avermedia_m135a) 143module_init(init_rc_map_avermedia_m135a)
diff --git a/drivers/media/IR/keymaps/rc-avermedia-m733a-rm-k6.c b/drivers/media/rc/keymaps/rc-avermedia-m733a-rm-k6.c
index cf8d45717cb3..e694e6eac37e 100644
--- a/drivers/media/IR/keymaps/rc-avermedia-m733a-rm-k6.c
+++ b/drivers/media/rc/keymaps/rc-avermedia-m733a-rm-k6.c
@@ -16,7 +16,7 @@
16 * Herton Ronaldo Krzesinski <herton@mandriva.com.br> 16 * Herton Ronaldo Krzesinski <herton@mandriva.com.br>
17 */ 17 */
18 18
19static struct ir_scancode avermedia_m733a_rm_k6[] = { 19static struct rc_map_table avermedia_m733a_rm_k6[] = {
20 { 0x0401, KEY_POWER2 }, 20 { 0x0401, KEY_POWER2 },
21 { 0x0406, KEY_MUTE }, 21 { 0x0406, KEY_MUTE },
22 { 0x0408, KEY_MODE }, /* TV/FM */ 22 { 0x0408, KEY_MODE }, /* TV/FM */
@@ -69,23 +69,23 @@ static struct ir_scancode avermedia_m733a_rm_k6[] = {
69 { 0x041e, KEY_NEXT }, 69 { 0x041e, KEY_NEXT },
70}; 70};
71 71
72static struct rc_keymap avermedia_m733a_rm_k6_map = { 72static struct rc_map_list avermedia_m733a_rm_k6_map = {
73 .map = { 73 .map = {
74 .scan = avermedia_m733a_rm_k6, 74 .scan = avermedia_m733a_rm_k6,
75 .size = ARRAY_SIZE(avermedia_m733a_rm_k6), 75 .size = ARRAY_SIZE(avermedia_m733a_rm_k6),
76 .ir_type = IR_TYPE_NEC, 76 .rc_type = RC_TYPE_NEC,
77 .name = RC_MAP_AVERMEDIA_M733A_RM_K6, 77 .name = RC_MAP_AVERMEDIA_M733A_RM_K6,
78 } 78 }
79}; 79};
80 80
81static int __init init_rc_map_avermedia_m733a_rm_k6(void) 81static int __init init_rc_map_avermedia_m733a_rm_k6(void)
82{ 82{
83 return ir_register_map(&avermedia_m733a_rm_k6_map); 83 return rc_map_register(&avermedia_m733a_rm_k6_map);
84} 84}
85 85
86static void __exit exit_rc_map_avermedia_m733a_rm_k6(void) 86static void __exit exit_rc_map_avermedia_m733a_rm_k6(void)
87{ 87{
88 ir_unregister_map(&avermedia_m733a_rm_k6_map); 88 rc_map_unregister(&avermedia_m733a_rm_k6_map);
89} 89}
90 90
91module_init(init_rc_map_avermedia_m733a_rm_k6) 91module_init(init_rc_map_avermedia_m733a_rm_k6)
diff --git a/drivers/media/IR/keymaps/rc-avermedia-rm-ks.c b/drivers/media/rc/keymaps/rc-avermedia-rm-ks.c
index 9ee60906c861..f4ca1fff455d 100644
--- a/drivers/media/IR/keymaps/rc-avermedia-rm-ks.c
+++ b/drivers/media/rc/keymaps/rc-avermedia-rm-ks.c
@@ -23,7 +23,7 @@
23/* Initial keytable is from Jose Alberto Reguero <jareguero@telefonica.net> 23/* Initial keytable is from Jose Alberto Reguero <jareguero@telefonica.net>
24 and Felipe Morales Moreno <felipe.morales.moreno@gmail.com> */ 24 and Felipe Morales Moreno <felipe.morales.moreno@gmail.com> */
25/* FIXME: mappings are not 100% correct? */ 25/* FIXME: mappings are not 100% correct? */
26static struct ir_scancode avermedia_rm_ks[] = { 26static struct rc_map_table avermedia_rm_ks[] = {
27 { 0x0501, KEY_POWER2 }, 27 { 0x0501, KEY_POWER2 },
28 { 0x0502, KEY_CHANNELUP }, 28 { 0x0502, KEY_CHANNELUP },
29 { 0x0503, KEY_CHANNELDOWN }, 29 { 0x0503, KEY_CHANNELDOWN },
@@ -53,23 +53,23 @@ static struct ir_scancode avermedia_rm_ks[] = {
53 { 0x0556, KEY_ZOOM }, 53 { 0x0556, KEY_ZOOM },
54}; 54};
55 55
56static struct rc_keymap avermedia_rm_ks_map = { 56static struct rc_map_list avermedia_rm_ks_map = {
57 .map = { 57 .map = {
58 .scan = avermedia_rm_ks, 58 .scan = avermedia_rm_ks,
59 .size = ARRAY_SIZE(avermedia_rm_ks), 59 .size = ARRAY_SIZE(avermedia_rm_ks),
60 .ir_type = IR_TYPE_NEC, 60 .rc_type = RC_TYPE_NEC,
61 .name = RC_MAP_AVERMEDIA_RM_KS, 61 .name = RC_MAP_AVERMEDIA_RM_KS,
62 } 62 }
63}; 63};
64 64
65static int __init init_rc_map_avermedia_rm_ks(void) 65static int __init init_rc_map_avermedia_rm_ks(void)
66{ 66{
67 return ir_register_map(&avermedia_rm_ks_map); 67 return rc_map_register(&avermedia_rm_ks_map);
68} 68}
69 69
70static void __exit exit_rc_map_avermedia_rm_ks(void) 70static void __exit exit_rc_map_avermedia_rm_ks(void)
71{ 71{
72 ir_unregister_map(&avermedia_rm_ks_map); 72 rc_map_unregister(&avermedia_rm_ks_map);
73} 73}
74 74
75module_init(init_rc_map_avermedia_rm_ks) 75module_init(init_rc_map_avermedia_rm_ks)
diff --git a/drivers/media/IR/keymaps/rc-avermedia.c b/drivers/media/rc/keymaps/rc-avermedia.c
index 21effd5bfb0d..edfa71506d3e 100644
--- a/drivers/media/IR/keymaps/rc-avermedia.c
+++ b/drivers/media/rc/keymaps/rc-avermedia.c
@@ -14,7 +14,7 @@
14 14
15/* Alex Hermann <gaaf@gmx.net> */ 15/* Alex Hermann <gaaf@gmx.net> */
16 16
17static struct ir_scancode avermedia[] = { 17static struct rc_map_table avermedia[] = {
18 { 0x28, KEY_1 }, 18 { 0x28, KEY_1 },
19 { 0x18, KEY_2 }, 19 { 0x18, KEY_2 },
20 { 0x38, KEY_3 }, 20 { 0x38, KEY_3 },
@@ -60,23 +60,23 @@ static struct ir_scancode avermedia[] = {
60 { 0x31, KEY_CHANNELUP } /* CHANNEL/PAGE+ */ 60 { 0x31, KEY_CHANNELUP } /* CHANNEL/PAGE+ */
61}; 61};
62 62
63static struct rc_keymap avermedia_map = { 63static struct rc_map_list avermedia_map = {
64 .map = { 64 .map = {
65 .scan = avermedia, 65 .scan = avermedia,
66 .size = ARRAY_SIZE(avermedia), 66 .size = ARRAY_SIZE(avermedia),
67 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 67 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
68 .name = RC_MAP_AVERMEDIA, 68 .name = RC_MAP_AVERMEDIA,
69 } 69 }
70}; 70};
71 71
72static int __init init_rc_map_avermedia(void) 72static int __init init_rc_map_avermedia(void)
73{ 73{
74 return ir_register_map(&avermedia_map); 74 return rc_map_register(&avermedia_map);
75} 75}
76 76
77static void __exit exit_rc_map_avermedia(void) 77static void __exit exit_rc_map_avermedia(void)
78{ 78{
79 ir_unregister_map(&avermedia_map); 79 rc_map_unregister(&avermedia_map);
80} 80}
81 81
82module_init(init_rc_map_avermedia) 82module_init(init_rc_map_avermedia)
diff --git a/drivers/media/IR/keymaps/rc-avertv-303.c b/drivers/media/rc/keymaps/rc-avertv-303.c
index 971c59d6f9d6..32e94988dc94 100644
--- a/drivers/media/IR/keymaps/rc-avertv-303.c
+++ b/drivers/media/rc/keymaps/rc-avertv-303.c
@@ -14,7 +14,7 @@
14 14
15/* AVERTV STUDIO 303 Remote */ 15/* AVERTV STUDIO 303 Remote */
16 16
17static struct ir_scancode avertv_303[] = { 17static struct rc_map_table avertv_303[] = {
18 { 0x2a, KEY_1 }, 18 { 0x2a, KEY_1 },
19 { 0x32, KEY_2 }, 19 { 0x32, KEY_2 },
20 { 0x3a, KEY_3 }, 20 { 0x3a, KEY_3 },
@@ -59,23 +59,23 @@ static struct ir_scancode avertv_303[] = {
59 { 0x1b, KEY_UP }, 59 { 0x1b, KEY_UP },
60}; 60};
61 61
62static struct rc_keymap avertv_303_map = { 62static struct rc_map_list avertv_303_map = {
63 .map = { 63 .map = {
64 .scan = avertv_303, 64 .scan = avertv_303,
65 .size = ARRAY_SIZE(avertv_303), 65 .size = ARRAY_SIZE(avertv_303),
66 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 66 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
67 .name = RC_MAP_AVERTV_303, 67 .name = RC_MAP_AVERTV_303,
68 } 68 }
69}; 69};
70 70
71static int __init init_rc_map_avertv_303(void) 71static int __init init_rc_map_avertv_303(void)
72{ 72{
73 return ir_register_map(&avertv_303_map); 73 return rc_map_register(&avertv_303_map);
74} 74}
75 75
76static void __exit exit_rc_map_avertv_303(void) 76static void __exit exit_rc_map_avertv_303(void)
77{ 77{
78 ir_unregister_map(&avertv_303_map); 78 rc_map_unregister(&avertv_303_map);
79} 79}
80 80
81module_init(init_rc_map_avertv_303) 81module_init(init_rc_map_avertv_303)
diff --git a/drivers/media/IR/keymaps/rc-azurewave-ad-tu700.c b/drivers/media/rc/keymaps/rc-azurewave-ad-tu700.c
index e0876147d471..c3f6d62ac892 100644
--- a/drivers/media/IR/keymaps/rc-azurewave-ad-tu700.c
+++ b/drivers/media/rc/keymaps/rc-azurewave-ad-tu700.c
@@ -20,7 +20,7 @@
20 20
21#include <media/rc-map.h> 21#include <media/rc-map.h>
22 22
23static struct ir_scancode azurewave_ad_tu700[] = { 23static struct rc_map_table azurewave_ad_tu700[] = {
24 { 0x0000, KEY_TAB }, /* Tab */ 24 { 0x0000, KEY_TAB }, /* Tab */
25 { 0x0001, KEY_2 }, 25 { 0x0001, KEY_2 },
26 { 0x0002, KEY_CHANNELDOWN }, 26 { 0x0002, KEY_CHANNELDOWN },
@@ -76,23 +76,23 @@ static struct ir_scancode azurewave_ad_tu700[] = {
76 { 0x005f, KEY_BLUE }, 76 { 0x005f, KEY_BLUE },
77}; 77};
78 78
79static struct rc_keymap azurewave_ad_tu700_map = { 79static struct rc_map_list azurewave_ad_tu700_map = {
80 .map = { 80 .map = {
81 .scan = azurewave_ad_tu700, 81 .scan = azurewave_ad_tu700,
82 .size = ARRAY_SIZE(azurewave_ad_tu700), 82 .size = ARRAY_SIZE(azurewave_ad_tu700),
83 .ir_type = IR_TYPE_NEC, 83 .rc_type = RC_TYPE_NEC,
84 .name = RC_MAP_AZUREWAVE_AD_TU700, 84 .name = RC_MAP_AZUREWAVE_AD_TU700,
85 } 85 }
86}; 86};
87 87
88static int __init init_rc_map_azurewave_ad_tu700(void) 88static int __init init_rc_map_azurewave_ad_tu700(void)
89{ 89{
90 return ir_register_map(&azurewave_ad_tu700_map); 90 return rc_map_register(&azurewave_ad_tu700_map);
91} 91}
92 92
93static void __exit exit_rc_map_azurewave_ad_tu700(void) 93static void __exit exit_rc_map_azurewave_ad_tu700(void)
94{ 94{
95 ir_unregister_map(&azurewave_ad_tu700_map); 95 rc_map_unregister(&azurewave_ad_tu700_map);
96} 96}
97 97
98module_init(init_rc_map_azurewave_ad_tu700) 98module_init(init_rc_map_azurewave_ad_tu700)
diff --git a/drivers/media/IR/keymaps/rc-behold-columbus.c b/drivers/media/rc/keymaps/rc-behold-columbus.c
index 9f56c98fef5b..4b787fa94f08 100644
--- a/drivers/media/IR/keymaps/rc-behold-columbus.c
+++ b/drivers/media/rc/keymaps/rc-behold-columbus.c
@@ -21,7 +21,7 @@
21 * helps to descide which keycodes to assign to the buttons. 21 * helps to descide which keycodes to assign to the buttons.
22 */ 22 */
23 23
24static struct ir_scancode behold_columbus[] = { 24static struct rc_map_table behold_columbus[] = {
25 25
26 /* 0x13 0x11 0x1C 0x12 * 26 /* 0x13 0x11 0x1C 0x12 *
27 * Mute Source TV/FM Power * 27 * Mute Source TV/FM Power *
@@ -82,23 +82,23 @@ static struct ir_scancode behold_columbus[] = {
82 82
83}; 83};
84 84
85static struct rc_keymap behold_columbus_map = { 85static struct rc_map_list behold_columbus_map = {
86 .map = { 86 .map = {
87 .scan = behold_columbus, 87 .scan = behold_columbus,
88 .size = ARRAY_SIZE(behold_columbus), 88 .size = ARRAY_SIZE(behold_columbus),
89 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 89 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
90 .name = RC_MAP_BEHOLD_COLUMBUS, 90 .name = RC_MAP_BEHOLD_COLUMBUS,
91 } 91 }
92}; 92};
93 93
94static int __init init_rc_map_behold_columbus(void) 94static int __init init_rc_map_behold_columbus(void)
95{ 95{
96 return ir_register_map(&behold_columbus_map); 96 return rc_map_register(&behold_columbus_map);
97} 97}
98 98
99static void __exit exit_rc_map_behold_columbus(void) 99static void __exit exit_rc_map_behold_columbus(void)
100{ 100{
101 ir_unregister_map(&behold_columbus_map); 101 rc_map_unregister(&behold_columbus_map);
102} 102}
103 103
104module_init(init_rc_map_behold_columbus) 104module_init(init_rc_map_behold_columbus)
diff --git a/drivers/media/IR/keymaps/rc-behold.c b/drivers/media/rc/keymaps/rc-behold.c
index abc140b2098b..0ee1f149364c 100644
--- a/drivers/media/IR/keymaps/rc-behold.c
+++ b/drivers/media/rc/keymaps/rc-behold.c
@@ -24,13 +24,13 @@
24 * helps to descide which keycodes to assign to the buttons. 24 * helps to descide which keycodes to assign to the buttons.
25 */ 25 */
26 26
27static struct ir_scancode behold[] = { 27static struct rc_map_table behold[] = {
28 28
29 /* 0x1c 0x12 * 29 /* 0x1c 0x12 *
30 * TV/FM POWER * 30 * TV/FM POWER *
31 * */ 31 * */
32 { 0x1c, KEY_TUNER }, /* XXX KEY_TV / KEY_RADIO */ 32 { 0x6b861c, KEY_TUNER }, /* XXX KEY_TV / KEY_RADIO */
33 { 0x12, KEY_POWER }, 33 { 0x6b8612, KEY_POWER },
34 34
35 /* 0x01 0x02 0x03 * 35 /* 0x01 0x02 0x03 *
36 * 1 2 3 * 36 * 1 2 3 *
@@ -41,28 +41,28 @@ static struct ir_scancode behold[] = {
41 * 0x07 0x08 0x09 * 41 * 0x07 0x08 0x09 *
42 * 7 8 9 * 42 * 7 8 9 *
43 * */ 43 * */
44 { 0x01, KEY_1 }, 44 { 0x6b8601, KEY_1 },
45 { 0x02, KEY_2 }, 45 { 0x6b8602, KEY_2 },
46 { 0x03, KEY_3 }, 46 { 0x6b8603, KEY_3 },
47 { 0x04, KEY_4 }, 47 { 0x6b8604, KEY_4 },
48 { 0x05, KEY_5 }, 48 { 0x6b8605, KEY_5 },
49 { 0x06, KEY_6 }, 49 { 0x6b8606, KEY_6 },
50 { 0x07, KEY_7 }, 50 { 0x6b8607, KEY_7 },
51 { 0x08, KEY_8 }, 51 { 0x6b8608, KEY_8 },
52 { 0x09, KEY_9 }, 52 { 0x6b8609, KEY_9 },
53 53
54 /* 0x0a 0x00 0x17 * 54 /* 0x0a 0x00 0x17 *
55 * RECALL 0 MODE * 55 * RECALL 0 MODE *
56 * */ 56 * */
57 { 0x0a, KEY_AGAIN }, 57 { 0x6b860a, KEY_AGAIN },
58 { 0x00, KEY_0 }, 58 { 0x6b8600, KEY_0 },
59 { 0x17, KEY_MODE }, 59 { 0x6b8617, KEY_MODE },
60 60
61 /* 0x14 0x10 * 61 /* 0x14 0x10 *
62 * ASPECT FULLSCREEN * 62 * ASPECT FULLSCREEN *
63 * */ 63 * */
64 { 0x14, KEY_SCREEN }, 64 { 0x6b8614, KEY_SCREEN },
65 { 0x10, KEY_ZOOM }, 65 { 0x6b8610, KEY_ZOOM },
66 66
67 /* 0x0b * 67 /* 0x0b *
68 * Up * 68 * Up *
@@ -73,17 +73,17 @@ static struct ir_scancode behold[] = {
73 * 0x015 * 73 * 0x015 *
74 * Down * 74 * Down *
75 * */ 75 * */
76 { 0x0b, KEY_CHANNELUP }, 76 { 0x6b860b, KEY_CHANNELUP },
77 { 0x18, KEY_VOLUMEDOWN }, 77 { 0x6b8618, KEY_VOLUMEDOWN },
78 { 0x16, KEY_OK }, /* XXX KEY_ENTER */ 78 { 0x6b8616, KEY_OK }, /* XXX KEY_ENTER */
79 { 0x0c, KEY_VOLUMEUP }, 79 { 0x6b860c, KEY_VOLUMEUP },
80 { 0x15, KEY_CHANNELDOWN }, 80 { 0x6b8615, KEY_CHANNELDOWN },
81 81
82 /* 0x11 0x0d * 82 /* 0x11 0x0d *
83 * MUTE INFO * 83 * MUTE INFO *
84 * */ 84 * */
85 { 0x11, KEY_MUTE }, 85 { 0x6b8611, KEY_MUTE },
86 { 0x0d, KEY_INFO }, 86 { 0x6b860d, KEY_INFO },
87 87
88 /* 0x0f 0x1b 0x1a * 88 /* 0x0f 0x1b 0x1a *
89 * RECORD PLAY/PAUSE STOP * 89 * RECORD PLAY/PAUSE STOP *
@@ -92,46 +92,46 @@ static struct ir_scancode behold[] = {
92 *TELETEXT AUDIO SOURCE * 92 *TELETEXT AUDIO SOURCE *
93 * RED YELLOW * 93 * RED YELLOW *
94 * */ 94 * */
95 { 0x0f, KEY_RECORD }, 95 { 0x6b860f, KEY_RECORD },
96 { 0x1b, KEY_PLAYPAUSE }, 96 { 0x6b861b, KEY_PLAYPAUSE },
97 { 0x1a, KEY_STOP }, 97 { 0x6b861a, KEY_STOP },
98 { 0x0e, KEY_TEXT }, 98 { 0x6b860e, KEY_TEXT },
99 { 0x1f, KEY_RED }, /*XXX KEY_AUDIO */ 99 { 0x6b861f, KEY_RED }, /*XXX KEY_AUDIO */
100 { 0x1e, KEY_YELLOW }, /*XXX KEY_SOURCE */ 100 { 0x6b861e, KEY_YELLOW }, /*XXX KEY_SOURCE */
101 101
102 /* 0x1d 0x13 0x19 * 102 /* 0x1d 0x13 0x19 *
103 * SLEEP PREVIEW DVB * 103 * SLEEP PREVIEW DVB *
104 * GREEN BLUE * 104 * GREEN BLUE *
105 * */ 105 * */
106 { 0x1d, KEY_SLEEP }, 106 { 0x6b861d, KEY_SLEEP },
107 { 0x13, KEY_GREEN }, 107 { 0x6b8613, KEY_GREEN },
108 { 0x19, KEY_BLUE }, /* XXX KEY_SAT */ 108 { 0x6b8619, KEY_BLUE }, /* XXX KEY_SAT */
109 109
110 /* 0x58 0x5c * 110 /* 0x58 0x5c *
111 * FREEZE SNAPSHOT * 111 * FREEZE SNAPSHOT *
112 * */ 112 * */
113 { 0x58, KEY_SLOW }, 113 { 0x6b8658, KEY_SLOW },
114 { 0x5c, KEY_CAMERA }, 114 { 0x6b865c, KEY_CAMERA },
115 115
116}; 116};
117 117
118static struct rc_keymap behold_map = { 118static struct rc_map_list behold_map = {
119 .map = { 119 .map = {
120 .scan = behold, 120 .scan = behold,
121 .size = ARRAY_SIZE(behold), 121 .size = ARRAY_SIZE(behold),
122 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 122 .rc_type = RC_TYPE_NEC,
123 .name = RC_MAP_BEHOLD, 123 .name = RC_MAP_BEHOLD,
124 } 124 }
125}; 125};
126 126
127static int __init init_rc_map_behold(void) 127static int __init init_rc_map_behold(void)
128{ 128{
129 return ir_register_map(&behold_map); 129 return rc_map_register(&behold_map);
130} 130}
131 131
132static void __exit exit_rc_map_behold(void) 132static void __exit exit_rc_map_behold(void)
133{ 133{
134 ir_unregister_map(&behold_map); 134 rc_map_unregister(&behold_map);
135} 135}
136 136
137module_init(init_rc_map_behold) 137module_init(init_rc_map_behold)
diff --git a/drivers/media/IR/keymaps/rc-budget-ci-old.c b/drivers/media/rc/keymaps/rc-budget-ci-old.c
index 64c2ac913338..97fc3862f608 100644
--- a/drivers/media/IR/keymaps/rc-budget-ci-old.c
+++ b/drivers/media/rc/keymaps/rc-budget-ci-old.c
@@ -18,7 +18,7 @@
18 * This is a "middle of the road" approach, differences are noted 18 * This is a "middle of the road" approach, differences are noted
19 */ 19 */
20 20
21static struct ir_scancode budget_ci_old[] = { 21static struct rc_map_table budget_ci_old[] = {
22 { 0x00, KEY_0 }, 22 { 0x00, KEY_0 },
23 { 0x01, KEY_1 }, 23 { 0x01, KEY_1 },
24 { 0x02, KEY_2 }, 24 { 0x02, KEY_2 },
@@ -66,23 +66,23 @@ static struct ir_scancode budget_ci_old[] = {
66 { 0x3e, KEY_TUNER }, 66 { 0x3e, KEY_TUNER },
67}; 67};
68 68
69static struct rc_keymap budget_ci_old_map = { 69static struct rc_map_list budget_ci_old_map = {
70 .map = { 70 .map = {
71 .scan = budget_ci_old, 71 .scan = budget_ci_old,
72 .size = ARRAY_SIZE(budget_ci_old), 72 .size = ARRAY_SIZE(budget_ci_old),
73 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 73 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
74 .name = RC_MAP_BUDGET_CI_OLD, 74 .name = RC_MAP_BUDGET_CI_OLD,
75 } 75 }
76}; 76};
77 77
78static int __init init_rc_map_budget_ci_old(void) 78static int __init init_rc_map_budget_ci_old(void)
79{ 79{
80 return ir_register_map(&budget_ci_old_map); 80 return rc_map_register(&budget_ci_old_map);
81} 81}
82 82
83static void __exit exit_rc_map_budget_ci_old(void) 83static void __exit exit_rc_map_budget_ci_old(void)
84{ 84{
85 ir_unregister_map(&budget_ci_old_map); 85 rc_map_unregister(&budget_ci_old_map);
86} 86}
87 87
88module_init(init_rc_map_budget_ci_old) 88module_init(init_rc_map_budget_ci_old)
diff --git a/drivers/media/IR/keymaps/rc-cinergy-1400.c b/drivers/media/rc/keymaps/rc-cinergy-1400.c
index 074f2c2c2c61..284534b67e7d 100644
--- a/drivers/media/IR/keymaps/rc-cinergy-1400.c
+++ b/drivers/media/rc/keymaps/rc-cinergy-1400.c
@@ -14,7 +14,7 @@
14 14
15/* Cinergy 1400 DVB-T */ 15/* Cinergy 1400 DVB-T */
16 16
17static struct ir_scancode cinergy_1400[] = { 17static struct rc_map_table cinergy_1400[] = {
18 { 0x01, KEY_POWER }, 18 { 0x01, KEY_POWER },
19 { 0x02, KEY_1 }, 19 { 0x02, KEY_1 },
20 { 0x03, KEY_2 }, 20 { 0x03, KEY_2 },
@@ -58,23 +58,23 @@ static struct ir_scancode cinergy_1400[] = {
58 { 0x5c, KEY_NEXT }, 58 { 0x5c, KEY_NEXT },
59}; 59};
60 60
61static struct rc_keymap cinergy_1400_map = { 61static struct rc_map_list cinergy_1400_map = {
62 .map = { 62 .map = {
63 .scan = cinergy_1400, 63 .scan = cinergy_1400,
64 .size = ARRAY_SIZE(cinergy_1400), 64 .size = ARRAY_SIZE(cinergy_1400),
65 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 65 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
66 .name = RC_MAP_CINERGY_1400, 66 .name = RC_MAP_CINERGY_1400,
67 } 67 }
68}; 68};
69 69
70static int __init init_rc_map_cinergy_1400(void) 70static int __init init_rc_map_cinergy_1400(void)
71{ 71{
72 return ir_register_map(&cinergy_1400_map); 72 return rc_map_register(&cinergy_1400_map);
73} 73}
74 74
75static void __exit exit_rc_map_cinergy_1400(void) 75static void __exit exit_rc_map_cinergy_1400(void)
76{ 76{
77 ir_unregister_map(&cinergy_1400_map); 77 rc_map_unregister(&cinergy_1400_map);
78} 78}
79 79
80module_init(init_rc_map_cinergy_1400) 80module_init(init_rc_map_cinergy_1400)
diff --git a/drivers/media/IR/keymaps/rc-cinergy.c b/drivers/media/rc/keymaps/rc-cinergy.c
index cf84c3dba742..99520ff65b61 100644
--- a/drivers/media/IR/keymaps/rc-cinergy.c
+++ b/drivers/media/rc/keymaps/rc-cinergy.c
@@ -12,7 +12,7 @@
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14 14
15static struct ir_scancode cinergy[] = { 15static struct rc_map_table cinergy[] = {
16 { 0x00, KEY_0 }, 16 { 0x00, KEY_0 },
17 { 0x01, KEY_1 }, 17 { 0x01, KEY_1 },
18 { 0x02, KEY_2 }, 18 { 0x02, KEY_2 },
@@ -52,23 +52,23 @@ static struct ir_scancode cinergy[] = {
52 { 0x23, KEY_STOP }, 52 { 0x23, KEY_STOP },
53}; 53};
54 54
55static struct rc_keymap cinergy_map = { 55static struct rc_map_list cinergy_map = {
56 .map = { 56 .map = {
57 .scan = cinergy, 57 .scan = cinergy,
58 .size = ARRAY_SIZE(cinergy), 58 .size = ARRAY_SIZE(cinergy),
59 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 59 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
60 .name = RC_MAP_CINERGY, 60 .name = RC_MAP_CINERGY,
61 } 61 }
62}; 62};
63 63
64static int __init init_rc_map_cinergy(void) 64static int __init init_rc_map_cinergy(void)
65{ 65{
66 return ir_register_map(&cinergy_map); 66 return rc_map_register(&cinergy_map);
67} 67}
68 68
69static void __exit exit_rc_map_cinergy(void) 69static void __exit exit_rc_map_cinergy(void)
70{ 70{
71 ir_unregister_map(&cinergy_map); 71 rc_map_unregister(&cinergy_map);
72} 72}
73 73
74module_init(init_rc_map_cinergy) 74module_init(init_rc_map_cinergy)
diff --git a/drivers/media/IR/keymaps/rc-dib0700-nec.c b/drivers/media/rc/keymaps/rc-dib0700-nec.c
index ae1832038fbe..c59851b203da 100644
--- a/drivers/media/IR/keymaps/rc-dib0700-nec.c
+++ b/drivers/media/rc/keymaps/rc-dib0700-nec.c
@@ -17,7 +17,7 @@
17 17
18#include <media/rc-map.h> 18#include <media/rc-map.h>
19 19
20static struct ir_scancode dib0700_nec_table[] = { 20static struct rc_map_table dib0700_nec_table[] = {
21 /* Key codes for the Pixelview SBTVD remote */ 21 /* Key codes for the Pixelview SBTVD remote */
22 { 0x8613, KEY_MUTE }, 22 { 0x8613, KEY_MUTE },
23 { 0x8612, KEY_POWER }, 23 { 0x8612, KEY_POWER },
@@ -98,23 +98,23 @@ static struct ir_scancode dib0700_nec_table[] = {
98 { 0x4542, KEY_SELECT }, /* Select video input, 'Select' for Teletext */ 98 { 0x4542, KEY_SELECT }, /* Select video input, 'Select' for Teletext */
99}; 99};
100 100
101static struct rc_keymap dib0700_nec_map = { 101static struct rc_map_list dib0700_nec_map = {
102 .map = { 102 .map = {
103 .scan = dib0700_nec_table, 103 .scan = dib0700_nec_table,
104 .size = ARRAY_SIZE(dib0700_nec_table), 104 .size = ARRAY_SIZE(dib0700_nec_table),
105 .ir_type = IR_TYPE_NEC, 105 .rc_type = RC_TYPE_NEC,
106 .name = RC_MAP_DIB0700_NEC_TABLE, 106 .name = RC_MAP_DIB0700_NEC_TABLE,
107 } 107 }
108}; 108};
109 109
110static int __init init_rc_map(void) 110static int __init init_rc_map(void)
111{ 111{
112 return ir_register_map(&dib0700_nec_map); 112 return rc_map_register(&dib0700_nec_map);
113} 113}
114 114
115static void __exit exit_rc_map(void) 115static void __exit exit_rc_map(void)
116{ 116{
117 ir_unregister_map(&dib0700_nec_map); 117 rc_map_unregister(&dib0700_nec_map);
118} 118}
119 119
120module_init(init_rc_map) 120module_init(init_rc_map)
diff --git a/drivers/media/IR/keymaps/rc-dib0700-rc5.c b/drivers/media/rc/keymaps/rc-dib0700-rc5.c
index 4a4797cfd77d..4af12e45dfba 100644
--- a/drivers/media/IR/keymaps/rc-dib0700-rc5.c
+++ b/drivers/media/rc/keymaps/rc-dib0700-rc5.c
@@ -17,7 +17,7 @@
17 17
18#include <media/rc-map.h> 18#include <media/rc-map.h>
19 19
20static struct ir_scancode dib0700_rc5_table[] = { 20static struct rc_map_table dib0700_rc5_table[] = {
21 /* Key codes for the tiny Pinnacle remote*/ 21 /* Key codes for the tiny Pinnacle remote*/
22 { 0x0700, KEY_MUTE }, 22 { 0x0700, KEY_MUTE },
23 { 0x0701, KEY_MENU }, /* Pinnacle logo */ 23 { 0x0701, KEY_MENU }, /* Pinnacle logo */
@@ -209,23 +209,23 @@ static struct ir_scancode dib0700_rc5_table[] = {
209 { 0x1d3d, KEY_POWER }, 209 { 0x1d3d, KEY_POWER },
210}; 210};
211 211
212static struct rc_keymap dib0700_rc5_map = { 212static struct rc_map_list dib0700_rc5_map = {
213 .map = { 213 .map = {
214 .scan = dib0700_rc5_table, 214 .scan = dib0700_rc5_table,
215 .size = ARRAY_SIZE(dib0700_rc5_table), 215 .size = ARRAY_SIZE(dib0700_rc5_table),
216 .ir_type = IR_TYPE_RC5, 216 .rc_type = RC_TYPE_RC5,
217 .name = RC_MAP_DIB0700_RC5_TABLE, 217 .name = RC_MAP_DIB0700_RC5_TABLE,
218 } 218 }
219}; 219};
220 220
221static int __init init_rc_map(void) 221static int __init init_rc_map(void)
222{ 222{
223 return ir_register_map(&dib0700_rc5_map); 223 return rc_map_register(&dib0700_rc5_map);
224} 224}
225 225
226static void __exit exit_rc_map(void) 226static void __exit exit_rc_map(void)
227{ 227{
228 ir_unregister_map(&dib0700_rc5_map); 228 rc_map_unregister(&dib0700_rc5_map);
229} 229}
230 230
231module_init(init_rc_map) 231module_init(init_rc_map)
diff --git a/drivers/media/IR/keymaps/rc-digitalnow-tinytwin.c b/drivers/media/rc/keymaps/rc-digitalnow-tinytwin.c
index 63e469e2dd21..f68b450f5593 100644
--- a/drivers/media/IR/keymaps/rc-digitalnow-tinytwin.c
+++ b/drivers/media/rc/keymaps/rc-digitalnow-tinytwin.c
@@ -20,7 +20,7 @@
20 20
21#include <media/rc-map.h> 21#include <media/rc-map.h>
22 22
23static struct ir_scancode digitalnow_tinytwin[] = { 23static struct rc_map_table digitalnow_tinytwin[] = {
24 { 0x0000, KEY_MUTE }, /* [symbol speaker] */ 24 { 0x0000, KEY_MUTE }, /* [symbol speaker] */
25 { 0x0001, KEY_VOLUMEUP }, 25 { 0x0001, KEY_VOLUMEUP },
26 { 0x0002, KEY_POWER2 }, /* TV [power button] */ 26 { 0x0002, KEY_POWER2 }, /* TV [power button] */
@@ -72,23 +72,23 @@ static struct ir_scancode digitalnow_tinytwin[] = {
72 { 0x005a, KEY_PREVIOUS }, /* REPLAY */ 72 { 0x005a, KEY_PREVIOUS }, /* REPLAY */
73}; 73};
74 74
75static struct rc_keymap digitalnow_tinytwin_map = { 75static struct rc_map_list digitalnow_tinytwin_map = {
76 .map = { 76 .map = {
77 .scan = digitalnow_tinytwin, 77 .scan = digitalnow_tinytwin,
78 .size = ARRAY_SIZE(digitalnow_tinytwin), 78 .size = ARRAY_SIZE(digitalnow_tinytwin),
79 .ir_type = IR_TYPE_NEC, 79 .rc_type = RC_TYPE_NEC,
80 .name = RC_MAP_DIGITALNOW_TINYTWIN, 80 .name = RC_MAP_DIGITALNOW_TINYTWIN,
81 } 81 }
82}; 82};
83 83
84static int __init init_rc_map_digitalnow_tinytwin(void) 84static int __init init_rc_map_digitalnow_tinytwin(void)
85{ 85{
86 return ir_register_map(&digitalnow_tinytwin_map); 86 return rc_map_register(&digitalnow_tinytwin_map);
87} 87}
88 88
89static void __exit exit_rc_map_digitalnow_tinytwin(void) 89static void __exit exit_rc_map_digitalnow_tinytwin(void)
90{ 90{
91 ir_unregister_map(&digitalnow_tinytwin_map); 91 rc_map_unregister(&digitalnow_tinytwin_map);
92} 92}
93 93
94module_init(init_rc_map_digitalnow_tinytwin) 94module_init(init_rc_map_digitalnow_tinytwin)
diff --git a/drivers/media/IR/keymaps/rc-digittrade.c b/drivers/media/rc/keymaps/rc-digittrade.c
index 5dece78e19c5..21d49871f2a3 100644
--- a/drivers/media/IR/keymaps/rc-digittrade.c
+++ b/drivers/media/rc/keymaps/rc-digittrade.c
@@ -25,7 +25,7 @@
25 Initial keytable was from Alain Kalker <miki@dds.nl> */ 25 Initial keytable was from Alain Kalker <miki@dds.nl> */
26 26
27/* Digittrade DVB-T USB Stick */ 27/* Digittrade DVB-T USB Stick */
28static struct ir_scancode digittrade[] = { 28static struct rc_map_table digittrade[] = {
29 { 0x0000, KEY_9 }, 29 { 0x0000, KEY_9 },
30 { 0x0001, KEY_EPG }, /* EPG */ 30 { 0x0001, KEY_EPG }, /* EPG */
31 { 0x0002, KEY_VOLUMEDOWN }, /* Vol Dn */ 31 { 0x0002, KEY_VOLUMEDOWN }, /* Vol Dn */
@@ -56,23 +56,23 @@ static struct ir_scancode digittrade[] = {
56 { 0x0054, KEY_0 }, 56 { 0x0054, KEY_0 },
57}; 57};
58 58
59static struct rc_keymap digittrade_map = { 59static struct rc_map_list digittrade_map = {
60 .map = { 60 .map = {
61 .scan = digittrade, 61 .scan = digittrade,
62 .size = ARRAY_SIZE(digittrade), 62 .size = ARRAY_SIZE(digittrade),
63 .ir_type = IR_TYPE_NEC, 63 .rc_type = RC_TYPE_NEC,
64 .name = RC_MAP_DIGITTRADE, 64 .name = RC_MAP_DIGITTRADE,
65 } 65 }
66}; 66};
67 67
68static int __init init_rc_map_digittrade(void) 68static int __init init_rc_map_digittrade(void)
69{ 69{
70 return ir_register_map(&digittrade_map); 70 return rc_map_register(&digittrade_map);
71} 71}
72 72
73static void __exit exit_rc_map_digittrade(void) 73static void __exit exit_rc_map_digittrade(void)
74{ 74{
75 ir_unregister_map(&digittrade_map); 75 rc_map_unregister(&digittrade_map);
76} 76}
77 77
78module_init(init_rc_map_digittrade) 78module_init(init_rc_map_digittrade)
diff --git a/drivers/media/IR/keymaps/rc-dm1105-nec.c b/drivers/media/rc/keymaps/rc-dm1105-nec.c
index 90684d0efea3..d024fbf88bc4 100644
--- a/drivers/media/IR/keymaps/rc-dm1105-nec.c
+++ b/drivers/media/rc/keymaps/rc-dm1105-nec.c
@@ -16,7 +16,7 @@
16 Igor M. Liplianin <liplianin@me.by> 16 Igor M. Liplianin <liplianin@me.by>
17 */ 17 */
18 18
19static struct ir_scancode dm1105_nec[] = { 19static struct rc_map_table dm1105_nec[] = {
20 { 0x0a, KEY_POWER2}, /* power */ 20 { 0x0a, KEY_POWER2}, /* power */
21 { 0x0c, KEY_MUTE}, /* mute */ 21 { 0x0c, KEY_MUTE}, /* mute */
22 { 0x11, KEY_1}, 22 { 0x11, KEY_1},
@@ -50,23 +50,23 @@ static struct ir_scancode dm1105_nec[] = {
50 { 0x1b, KEY_B}, /* recall */ 50 { 0x1b, KEY_B}, /* recall */
51}; 51};
52 52
53static struct rc_keymap dm1105_nec_map = { 53static struct rc_map_list dm1105_nec_map = {
54 .map = { 54 .map = {
55 .scan = dm1105_nec, 55 .scan = dm1105_nec,
56 .size = ARRAY_SIZE(dm1105_nec), 56 .size = ARRAY_SIZE(dm1105_nec),
57 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 57 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
58 .name = RC_MAP_DM1105_NEC, 58 .name = RC_MAP_DM1105_NEC,
59 } 59 }
60}; 60};
61 61
62static int __init init_rc_map_dm1105_nec(void) 62static int __init init_rc_map_dm1105_nec(void)
63{ 63{
64 return ir_register_map(&dm1105_nec_map); 64 return rc_map_register(&dm1105_nec_map);
65} 65}
66 66
67static void __exit exit_rc_map_dm1105_nec(void) 67static void __exit exit_rc_map_dm1105_nec(void)
68{ 68{
69 ir_unregister_map(&dm1105_nec_map); 69 rc_map_unregister(&dm1105_nec_map);
70} 70}
71 71
72module_init(init_rc_map_dm1105_nec) 72module_init(init_rc_map_dm1105_nec)
diff --git a/drivers/media/IR/keymaps/rc-dntv-live-dvb-t.c b/drivers/media/rc/keymaps/rc-dntv-live-dvb-t.c
index 8a4027af964a..43912bd02a9e 100644
--- a/drivers/media/IR/keymaps/rc-dntv-live-dvb-t.c
+++ b/drivers/media/rc/keymaps/rc-dntv-live-dvb-t.c
@@ -14,7 +14,7 @@
14 14
15/* DigitalNow DNTV Live DVB-T Remote */ 15/* DigitalNow DNTV Live DVB-T Remote */
16 16
17static struct ir_scancode dntv_live_dvb_t[] = { 17static struct rc_map_table dntv_live_dvb_t[] = {
18 { 0x00, KEY_ESC }, /* 'go up a level?' */ 18 { 0x00, KEY_ESC }, /* 'go up a level?' */
19 /* Keys 0 to 9 */ 19 /* Keys 0 to 9 */
20 { 0x0a, KEY_0 }, 20 { 0x0a, KEY_0 },
@@ -52,23 +52,23 @@ static struct ir_scancode dntv_live_dvb_t[] = {
52 { 0x1f, KEY_VOLUMEDOWN }, 52 { 0x1f, KEY_VOLUMEDOWN },
53}; 53};
54 54
55static struct rc_keymap dntv_live_dvb_t_map = { 55static struct rc_map_list dntv_live_dvb_t_map = {
56 .map = { 56 .map = {
57 .scan = dntv_live_dvb_t, 57 .scan = dntv_live_dvb_t,
58 .size = ARRAY_SIZE(dntv_live_dvb_t), 58 .size = ARRAY_SIZE(dntv_live_dvb_t),
59 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 59 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
60 .name = RC_MAP_DNTV_LIVE_DVB_T, 60 .name = RC_MAP_DNTV_LIVE_DVB_T,
61 } 61 }
62}; 62};
63 63
64static int __init init_rc_map_dntv_live_dvb_t(void) 64static int __init init_rc_map_dntv_live_dvb_t(void)
65{ 65{
66 return ir_register_map(&dntv_live_dvb_t_map); 66 return rc_map_register(&dntv_live_dvb_t_map);
67} 67}
68 68
69static void __exit exit_rc_map_dntv_live_dvb_t(void) 69static void __exit exit_rc_map_dntv_live_dvb_t(void)
70{ 70{
71 ir_unregister_map(&dntv_live_dvb_t_map); 71 rc_map_unregister(&dntv_live_dvb_t_map);
72} 72}
73 73
74module_init(init_rc_map_dntv_live_dvb_t) 74module_init(init_rc_map_dntv_live_dvb_t)
diff --git a/drivers/media/IR/keymaps/rc-dntv-live-dvbt-pro.c b/drivers/media/rc/keymaps/rc-dntv-live-dvbt-pro.c
index 6f4d60764d59..015e99de06de 100644
--- a/drivers/media/IR/keymaps/rc-dntv-live-dvbt-pro.c
+++ b/drivers/media/rc/keymaps/rc-dntv-live-dvbt-pro.c
@@ -14,7 +14,7 @@
14 14
15/* DigitalNow DNTV Live! DVB-T Pro Remote */ 15/* DigitalNow DNTV Live! DVB-T Pro Remote */
16 16
17static struct ir_scancode dntv_live_dvbt_pro[] = { 17static struct rc_map_table dntv_live_dvbt_pro[] = {
18 { 0x16, KEY_POWER }, 18 { 0x16, KEY_POWER },
19 { 0x5b, KEY_HOME }, 19 { 0x5b, KEY_HOME },
20 20
@@ -71,23 +71,23 @@ static struct ir_scancode dntv_live_dvbt_pro[] = {
71 { 0x5d, KEY_BLUE }, 71 { 0x5d, KEY_BLUE },
72}; 72};
73 73
74static struct rc_keymap dntv_live_dvbt_pro_map = { 74static struct rc_map_list dntv_live_dvbt_pro_map = {
75 .map = { 75 .map = {
76 .scan = dntv_live_dvbt_pro, 76 .scan = dntv_live_dvbt_pro,
77 .size = ARRAY_SIZE(dntv_live_dvbt_pro), 77 .size = ARRAY_SIZE(dntv_live_dvbt_pro),
78 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 78 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
79 .name = RC_MAP_DNTV_LIVE_DVBT_PRO, 79 .name = RC_MAP_DNTV_LIVE_DVBT_PRO,
80 } 80 }
81}; 81};
82 82
83static int __init init_rc_map_dntv_live_dvbt_pro(void) 83static int __init init_rc_map_dntv_live_dvbt_pro(void)
84{ 84{
85 return ir_register_map(&dntv_live_dvbt_pro_map); 85 return rc_map_register(&dntv_live_dvbt_pro_map);
86} 86}
87 87
88static void __exit exit_rc_map_dntv_live_dvbt_pro(void) 88static void __exit exit_rc_map_dntv_live_dvbt_pro(void)
89{ 89{
90 ir_unregister_map(&dntv_live_dvbt_pro_map); 90 rc_map_unregister(&dntv_live_dvbt_pro_map);
91} 91}
92 92
93module_init(init_rc_map_dntv_live_dvbt_pro) 93module_init(init_rc_map_dntv_live_dvbt_pro)
diff --git a/drivers/media/IR/keymaps/rc-em-terratec.c b/drivers/media/rc/keymaps/rc-em-terratec.c
index 3130c9c29e6b..269d4299da34 100644
--- a/drivers/media/IR/keymaps/rc-em-terratec.c
+++ b/drivers/media/rc/keymaps/rc-em-terratec.c
@@ -12,7 +12,7 @@
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14 14
15static struct ir_scancode em_terratec[] = { 15static struct rc_map_table em_terratec[] = {
16 { 0x01, KEY_CHANNEL }, 16 { 0x01, KEY_CHANNEL },
17 { 0x02, KEY_SELECT }, 17 { 0x02, KEY_SELECT },
18 { 0x03, KEY_MUTE }, 18 { 0x03, KEY_MUTE },
@@ -43,23 +43,23 @@ static struct ir_scancode em_terratec[] = {
43 { 0x40, KEY_ZOOM }, 43 { 0x40, KEY_ZOOM },
44}; 44};
45 45
46static struct rc_keymap em_terratec_map = { 46static struct rc_map_list em_terratec_map = {
47 .map = { 47 .map = {
48 .scan = em_terratec, 48 .scan = em_terratec,
49 .size = ARRAY_SIZE(em_terratec), 49 .size = ARRAY_SIZE(em_terratec),
50 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 50 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
51 .name = RC_MAP_EM_TERRATEC, 51 .name = RC_MAP_EM_TERRATEC,
52 } 52 }
53}; 53};
54 54
55static int __init init_rc_map_em_terratec(void) 55static int __init init_rc_map_em_terratec(void)
56{ 56{
57 return ir_register_map(&em_terratec_map); 57 return rc_map_register(&em_terratec_map);
58} 58}
59 59
60static void __exit exit_rc_map_em_terratec(void) 60static void __exit exit_rc_map_em_terratec(void)
61{ 61{
62 ir_unregister_map(&em_terratec_map); 62 rc_map_unregister(&em_terratec_map);
63} 63}
64 64
65module_init(init_rc_map_em_terratec) 65module_init(init_rc_map_em_terratec)
diff --git a/drivers/media/IR/keymaps/rc-encore-enltv-fm53.c b/drivers/media/rc/keymaps/rc-encore-enltv-fm53.c
index 4b816967877e..e388698a0697 100644
--- a/drivers/media/IR/keymaps/rc-encore-enltv-fm53.c
+++ b/drivers/media/rc/keymaps/rc-encore-enltv-fm53.c
@@ -16,7 +16,7 @@
16 Mauro Carvalho Chehab <mchehab@infradead.org> 16 Mauro Carvalho Chehab <mchehab@infradead.org>
17 */ 17 */
18 18
19static struct ir_scancode encore_enltv_fm53[] = { 19static struct rc_map_table encore_enltv_fm53[] = {
20 { 0x10, KEY_POWER2}, 20 { 0x10, KEY_POWER2},
21 { 0x06, KEY_MUTE}, 21 { 0x06, KEY_MUTE},
22 22
@@ -55,23 +55,23 @@ static struct ir_scancode encore_enltv_fm53[] = {
55 { 0x47, KEY_SLEEP}, /* shutdown */ 55 { 0x47, KEY_SLEEP}, /* shutdown */
56}; 56};
57 57
58static struct rc_keymap encore_enltv_fm53_map = { 58static struct rc_map_list encore_enltv_fm53_map = {
59 .map = { 59 .map = {
60 .scan = encore_enltv_fm53, 60 .scan = encore_enltv_fm53,
61 .size = ARRAY_SIZE(encore_enltv_fm53), 61 .size = ARRAY_SIZE(encore_enltv_fm53),
62 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 62 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
63 .name = RC_MAP_ENCORE_ENLTV_FM53, 63 .name = RC_MAP_ENCORE_ENLTV_FM53,
64 } 64 }
65}; 65};
66 66
67static int __init init_rc_map_encore_enltv_fm53(void) 67static int __init init_rc_map_encore_enltv_fm53(void)
68{ 68{
69 return ir_register_map(&encore_enltv_fm53_map); 69 return rc_map_register(&encore_enltv_fm53_map);
70} 70}
71 71
72static void __exit exit_rc_map_encore_enltv_fm53(void) 72static void __exit exit_rc_map_encore_enltv_fm53(void)
73{ 73{
74 ir_unregister_map(&encore_enltv_fm53_map); 74 rc_map_unregister(&encore_enltv_fm53_map);
75} 75}
76 76
77module_init(init_rc_map_encore_enltv_fm53) 77module_init(init_rc_map_encore_enltv_fm53)
diff --git a/drivers/media/IR/keymaps/rc-encore-enltv.c b/drivers/media/rc/keymaps/rc-encore-enltv.c
index 9fabffd28cc9..afa4e92284ef 100644
--- a/drivers/media/IR/keymaps/rc-encore-enltv.c
+++ b/drivers/media/rc/keymaps/rc-encore-enltv.c
@@ -15,7 +15,7 @@
15/* Encore ENLTV-FM - black plastic, white front cover with white glowing buttons 15/* Encore ENLTV-FM - black plastic, white front cover with white glowing buttons
16 Juan Pablo Sormani <sorman@gmail.com> */ 16 Juan Pablo Sormani <sorman@gmail.com> */
17 17
18static struct ir_scancode encore_enltv[] = { 18static struct rc_map_table encore_enltv[] = {
19 19
20 /* Power button does nothing, neither in Windows app, 20 /* Power button does nothing, neither in Windows app,
21 although it sends data (used for BIOS wakeup?) */ 21 although it sends data (used for BIOS wakeup?) */
@@ -86,23 +86,23 @@ static struct ir_scancode encore_enltv[] = {
86 { 0x57, KEY_BLUE }, /* AP4 */ 86 { 0x57, KEY_BLUE }, /* AP4 */
87}; 87};
88 88
89static struct rc_keymap encore_enltv_map = { 89static struct rc_map_list encore_enltv_map = {
90 .map = { 90 .map = {
91 .scan = encore_enltv, 91 .scan = encore_enltv,
92 .size = ARRAY_SIZE(encore_enltv), 92 .size = ARRAY_SIZE(encore_enltv),
93 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 93 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
94 .name = RC_MAP_ENCORE_ENLTV, 94 .name = RC_MAP_ENCORE_ENLTV,
95 } 95 }
96}; 96};
97 97
98static int __init init_rc_map_encore_enltv(void) 98static int __init init_rc_map_encore_enltv(void)
99{ 99{
100 return ir_register_map(&encore_enltv_map); 100 return rc_map_register(&encore_enltv_map);
101} 101}
102 102
103static void __exit exit_rc_map_encore_enltv(void) 103static void __exit exit_rc_map_encore_enltv(void)
104{ 104{
105 ir_unregister_map(&encore_enltv_map); 105 rc_map_unregister(&encore_enltv_map);
106} 106}
107 107
108module_init(init_rc_map_encore_enltv) 108module_init(init_rc_map_encore_enltv)
diff --git a/drivers/media/IR/keymaps/rc-encore-enltv2.c b/drivers/media/rc/keymaps/rc-encore-enltv2.c
index efefd5166618..7d5b00ed4ff2 100644
--- a/drivers/media/IR/keymaps/rc-encore-enltv2.c
+++ b/drivers/media/rc/keymaps/rc-encore-enltv2.c
@@ -15,7 +15,7 @@
15/* Encore ENLTV2-FM - silver plastic - "Wand Media" written at the botton 15/* Encore ENLTV2-FM - silver plastic - "Wand Media" written at the botton
16 Mauro Carvalho Chehab <mchehab@infradead.org> */ 16 Mauro Carvalho Chehab <mchehab@infradead.org> */
17 17
18static struct ir_scancode encore_enltv2[] = { 18static struct rc_map_table encore_enltv2[] = {
19 { 0x4c, KEY_POWER2 }, 19 { 0x4c, KEY_POWER2 },
20 { 0x4a, KEY_TUNER }, 20 { 0x4a, KEY_TUNER },
21 { 0x40, KEY_1 }, 21 { 0x40, KEY_1 },
@@ -64,23 +64,23 @@ static struct ir_scancode encore_enltv2[] = {
64 { 0x79, KEY_STOP }, 64 { 0x79, KEY_STOP },
65}; 65};
66 66
67static struct rc_keymap encore_enltv2_map = { 67static struct rc_map_list encore_enltv2_map = {
68 .map = { 68 .map = {
69 .scan = encore_enltv2, 69 .scan = encore_enltv2,
70 .size = ARRAY_SIZE(encore_enltv2), 70 .size = ARRAY_SIZE(encore_enltv2),
71 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 71 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
72 .name = RC_MAP_ENCORE_ENLTV2, 72 .name = RC_MAP_ENCORE_ENLTV2,
73 } 73 }
74}; 74};
75 75
76static int __init init_rc_map_encore_enltv2(void) 76static int __init init_rc_map_encore_enltv2(void)
77{ 77{
78 return ir_register_map(&encore_enltv2_map); 78 return rc_map_register(&encore_enltv2_map);
79} 79}
80 80
81static void __exit exit_rc_map_encore_enltv2(void) 81static void __exit exit_rc_map_encore_enltv2(void)
82{ 82{
83 ir_unregister_map(&encore_enltv2_map); 83 rc_map_unregister(&encore_enltv2_map);
84} 84}
85 85
86module_init(init_rc_map_encore_enltv2) 86module_init(init_rc_map_encore_enltv2)
diff --git a/drivers/media/IR/keymaps/rc-evga-indtube.c b/drivers/media/rc/keymaps/rc-evga-indtube.c
index 3f3fb13813b3..a2bf24f6dfbb 100644
--- a/drivers/media/IR/keymaps/rc-evga-indtube.c
+++ b/drivers/media/rc/keymaps/rc-evga-indtube.c
@@ -16,7 +16,7 @@
16 Devin Heitmueller <devin.heitmueller@gmail.com> 16 Devin Heitmueller <devin.heitmueller@gmail.com>
17 */ 17 */
18 18
19static struct ir_scancode evga_indtube[] = { 19static struct rc_map_table evga_indtube[] = {
20 { 0x12, KEY_POWER}, 20 { 0x12, KEY_POWER},
21 { 0x02, KEY_MODE}, /* TV */ 21 { 0x02, KEY_MODE}, /* TV */
22 { 0x14, KEY_MUTE}, 22 { 0x14, KEY_MUTE},
@@ -35,23 +35,23 @@ static struct ir_scancode evga_indtube[] = {
35 { 0x13, KEY_CAMERA}, 35 { 0x13, KEY_CAMERA},
36}; 36};
37 37
38static struct rc_keymap evga_indtube_map = { 38static struct rc_map_list evga_indtube_map = {
39 .map = { 39 .map = {
40 .scan = evga_indtube, 40 .scan = evga_indtube,
41 .size = ARRAY_SIZE(evga_indtube), 41 .size = ARRAY_SIZE(evga_indtube),
42 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 42 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
43 .name = RC_MAP_EVGA_INDTUBE, 43 .name = RC_MAP_EVGA_INDTUBE,
44 } 44 }
45}; 45};
46 46
47static int __init init_rc_map_evga_indtube(void) 47static int __init init_rc_map_evga_indtube(void)
48{ 48{
49 return ir_register_map(&evga_indtube_map); 49 return rc_map_register(&evga_indtube_map);
50} 50}
51 51
52static void __exit exit_rc_map_evga_indtube(void) 52static void __exit exit_rc_map_evga_indtube(void)
53{ 53{
54 ir_unregister_map(&evga_indtube_map); 54 rc_map_unregister(&evga_indtube_map);
55} 55}
56 56
57module_init(init_rc_map_evga_indtube) 57module_init(init_rc_map_evga_indtube)
diff --git a/drivers/media/IR/keymaps/rc-eztv.c b/drivers/media/rc/keymaps/rc-eztv.c
index 660907a78db9..1e8e5b2d6e36 100644
--- a/drivers/media/IR/keymaps/rc-eztv.c
+++ b/drivers/media/rc/keymaps/rc-eztv.c
@@ -15,7 +15,7 @@
15/* Alfons Geser <a.geser@cox.net> 15/* Alfons Geser <a.geser@cox.net>
16 * updates from Job D. R. Borges <jobdrb@ig.com.br> */ 16 * updates from Job D. R. Borges <jobdrb@ig.com.br> */
17 17
18static struct ir_scancode eztv[] = { 18static struct rc_map_table eztv[] = {
19 { 0x12, KEY_POWER }, 19 { 0x12, KEY_POWER },
20 { 0x01, KEY_TV }, /* DVR */ 20 { 0x01, KEY_TV }, /* DVR */
21 { 0x15, KEY_DVD }, /* DVD */ 21 { 0x15, KEY_DVD }, /* DVD */
@@ -70,23 +70,23 @@ static struct ir_scancode eztv[] = {
70 { 0x21, KEY_DOT }, /* . (decimal dot) */ 70 { 0x21, KEY_DOT }, /* . (decimal dot) */
71}; 71};
72 72
73static struct rc_keymap eztv_map = { 73static struct rc_map_list eztv_map = {
74 .map = { 74 .map = {
75 .scan = eztv, 75 .scan = eztv,
76 .size = ARRAY_SIZE(eztv), 76 .size = ARRAY_SIZE(eztv),
77 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 77 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
78 .name = RC_MAP_EZTV, 78 .name = RC_MAP_EZTV,
79 } 79 }
80}; 80};
81 81
82static int __init init_rc_map_eztv(void) 82static int __init init_rc_map_eztv(void)
83{ 83{
84 return ir_register_map(&eztv_map); 84 return rc_map_register(&eztv_map);
85} 85}
86 86
87static void __exit exit_rc_map_eztv(void) 87static void __exit exit_rc_map_eztv(void)
88{ 88{
89 ir_unregister_map(&eztv_map); 89 rc_map_unregister(&eztv_map);
90} 90}
91 91
92module_init(init_rc_map_eztv) 92module_init(init_rc_map_eztv)
diff --git a/drivers/media/IR/keymaps/rc-flydvb.c b/drivers/media/rc/keymaps/rc-flydvb.c
index a173c81035f4..aea2f4acf7d8 100644
--- a/drivers/media/IR/keymaps/rc-flydvb.c
+++ b/drivers/media/rc/keymaps/rc-flydvb.c
@@ -12,7 +12,7 @@
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14 14
15static struct ir_scancode flydvb[] = { 15static struct rc_map_table flydvb[] = {
16 { 0x01, KEY_ZOOM }, /* Full Screen */ 16 { 0x01, KEY_ZOOM }, /* Full Screen */
17 { 0x00, KEY_POWER }, /* Power */ 17 { 0x00, KEY_POWER }, /* Power */
18 18
@@ -51,23 +51,23 @@ static struct ir_scancode flydvb[] = {
51 { 0x0e, KEY_NEXT }, /* End >>| */ 51 { 0x0e, KEY_NEXT }, /* End >>| */
52}; 52};
53 53
54static struct rc_keymap flydvb_map = { 54static struct rc_map_list flydvb_map = {
55 .map = { 55 .map = {
56 .scan = flydvb, 56 .scan = flydvb,
57 .size = ARRAY_SIZE(flydvb), 57 .size = ARRAY_SIZE(flydvb),
58 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 58 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
59 .name = RC_MAP_FLYDVB, 59 .name = RC_MAP_FLYDVB,
60 } 60 }
61}; 61};
62 62
63static int __init init_rc_map_flydvb(void) 63static int __init init_rc_map_flydvb(void)
64{ 64{
65 return ir_register_map(&flydvb_map); 65 return rc_map_register(&flydvb_map);
66} 66}
67 67
68static void __exit exit_rc_map_flydvb(void) 68static void __exit exit_rc_map_flydvb(void)
69{ 69{
70 ir_unregister_map(&flydvb_map); 70 rc_map_unregister(&flydvb_map);
71} 71}
72 72
73module_init(init_rc_map_flydvb) 73module_init(init_rc_map_flydvb)
diff --git a/drivers/media/IR/keymaps/rc-flyvideo.c b/drivers/media/rc/keymaps/rc-flyvideo.c
index 9c73043cbdba..5bbe68371756 100644
--- a/drivers/media/IR/keymaps/rc-flyvideo.c
+++ b/drivers/media/rc/keymaps/rc-flyvideo.c
@@ -12,7 +12,7 @@
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14 14
15static struct ir_scancode flyvideo[] = { 15static struct rc_map_table flyvideo[] = {
16 { 0x0f, KEY_0 }, 16 { 0x0f, KEY_0 },
17 { 0x03, KEY_1 }, 17 { 0x03, KEY_1 },
18 { 0x04, KEY_2 }, 18 { 0x04, KEY_2 },
@@ -44,23 +44,23 @@ static struct ir_scancode flyvideo[] = {
44 { 0x0a, KEY_ANGLE }, /* no label, may be used as the PAUSE button */ 44 { 0x0a, KEY_ANGLE }, /* no label, may be used as the PAUSE button */
45}; 45};
46 46
47static struct rc_keymap flyvideo_map = { 47static struct rc_map_list flyvideo_map = {
48 .map = { 48 .map = {
49 .scan = flyvideo, 49 .scan = flyvideo,
50 .size = ARRAY_SIZE(flyvideo), 50 .size = ARRAY_SIZE(flyvideo),
51 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 51 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
52 .name = RC_MAP_FLYVIDEO, 52 .name = RC_MAP_FLYVIDEO,
53 } 53 }
54}; 54};
55 55
56static int __init init_rc_map_flyvideo(void) 56static int __init init_rc_map_flyvideo(void)
57{ 57{
58 return ir_register_map(&flyvideo_map); 58 return rc_map_register(&flyvideo_map);
59} 59}
60 60
61static void __exit exit_rc_map_flyvideo(void) 61static void __exit exit_rc_map_flyvideo(void)
62{ 62{
63 ir_unregister_map(&flyvideo_map); 63 rc_map_unregister(&flyvideo_map);
64} 64}
65 65
66module_init(init_rc_map_flyvideo) 66module_init(init_rc_map_flyvideo)
diff --git a/drivers/media/IR/keymaps/rc-fusionhdtv-mce.c b/drivers/media/rc/keymaps/rc-fusionhdtv-mce.c
index cdb10389b10e..c80b25c65b57 100644
--- a/drivers/media/IR/keymaps/rc-fusionhdtv-mce.c
+++ b/drivers/media/rc/keymaps/rc-fusionhdtv-mce.c
@@ -14,7 +14,7 @@
14 14
15/* DViCO FUSION HDTV MCE remote */ 15/* DViCO FUSION HDTV MCE remote */
16 16
17static struct ir_scancode fusionhdtv_mce[] = { 17static struct rc_map_table fusionhdtv_mce[] = {
18 18
19 { 0x0b, KEY_1 }, 19 { 0x0b, KEY_1 },
20 { 0x17, KEY_2 }, 20 { 0x17, KEY_2 },
@@ -72,23 +72,23 @@ static struct ir_scancode fusionhdtv_mce[] = {
72 { 0x4e, KEY_POWER }, 72 { 0x4e, KEY_POWER },
73}; 73};
74 74
75static struct rc_keymap fusionhdtv_mce_map = { 75static struct rc_map_list fusionhdtv_mce_map = {
76 .map = { 76 .map = {
77 .scan = fusionhdtv_mce, 77 .scan = fusionhdtv_mce,
78 .size = ARRAY_SIZE(fusionhdtv_mce), 78 .size = ARRAY_SIZE(fusionhdtv_mce),
79 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 79 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
80 .name = RC_MAP_FUSIONHDTV_MCE, 80 .name = RC_MAP_FUSIONHDTV_MCE,
81 } 81 }
82}; 82};
83 83
84static int __init init_rc_map_fusionhdtv_mce(void) 84static int __init init_rc_map_fusionhdtv_mce(void)
85{ 85{
86 return ir_register_map(&fusionhdtv_mce_map); 86 return rc_map_register(&fusionhdtv_mce_map);
87} 87}
88 88
89static void __exit exit_rc_map_fusionhdtv_mce(void) 89static void __exit exit_rc_map_fusionhdtv_mce(void)
90{ 90{
91 ir_unregister_map(&fusionhdtv_mce_map); 91 rc_map_unregister(&fusionhdtv_mce_map);
92} 92}
93 93
94module_init(init_rc_map_fusionhdtv_mce) 94module_init(init_rc_map_fusionhdtv_mce)
diff --git a/drivers/media/IR/keymaps/rc-gadmei-rm008z.c b/drivers/media/rc/keymaps/rc-gadmei-rm008z.c
index c16c0d1263ac..068c9ead98dd 100644
--- a/drivers/media/IR/keymaps/rc-gadmei-rm008z.c
+++ b/drivers/media/rc/keymaps/rc-gadmei-rm008z.c
@@ -16,7 +16,7 @@
16 Shine Liu <shinel@foxmail.com> 16 Shine Liu <shinel@foxmail.com>
17 */ 17 */
18 18
19static struct ir_scancode gadmei_rm008z[] = { 19static struct rc_map_table gadmei_rm008z[] = {
20 { 0x14, KEY_POWER2}, /* POWER OFF */ 20 { 0x14, KEY_POWER2}, /* POWER OFF */
21 { 0x0c, KEY_MUTE}, /* MUTE */ 21 { 0x0c, KEY_MUTE}, /* MUTE */
22 22
@@ -55,23 +55,23 @@ static struct ir_scancode gadmei_rm008z[] = {
55 { 0x15, KEY_ENTER}, /* OK */ 55 { 0x15, KEY_ENTER}, /* OK */
56}; 56};
57 57
58static struct rc_keymap gadmei_rm008z_map = { 58static struct rc_map_list gadmei_rm008z_map = {
59 .map = { 59 .map = {
60 .scan = gadmei_rm008z, 60 .scan = gadmei_rm008z,
61 .size = ARRAY_SIZE(gadmei_rm008z), 61 .size = ARRAY_SIZE(gadmei_rm008z),
62 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 62 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
63 .name = RC_MAP_GADMEI_RM008Z, 63 .name = RC_MAP_GADMEI_RM008Z,
64 } 64 }
65}; 65};
66 66
67static int __init init_rc_map_gadmei_rm008z(void) 67static int __init init_rc_map_gadmei_rm008z(void)
68{ 68{
69 return ir_register_map(&gadmei_rm008z_map); 69 return rc_map_register(&gadmei_rm008z_map);
70} 70}
71 71
72static void __exit exit_rc_map_gadmei_rm008z(void) 72static void __exit exit_rc_map_gadmei_rm008z(void)
73{ 73{
74 ir_unregister_map(&gadmei_rm008z_map); 74 rc_map_unregister(&gadmei_rm008z_map);
75} 75}
76 76
77module_init(init_rc_map_gadmei_rm008z) 77module_init(init_rc_map_gadmei_rm008z)
diff --git a/drivers/media/IR/keymaps/rc-genius-tvgo-a11mce.c b/drivers/media/rc/keymaps/rc-genius-tvgo-a11mce.c
index 89f8e384e52a..cdbbed467926 100644
--- a/drivers/media/IR/keymaps/rc-genius-tvgo-a11mce.c
+++ b/drivers/media/rc/keymaps/rc-genius-tvgo-a11mce.c
@@ -17,7 +17,7 @@
17 * Adrian Pardini <pardo.bsso@gmail.com> 17 * Adrian Pardini <pardo.bsso@gmail.com>
18 */ 18 */
19 19
20static struct ir_scancode genius_tvgo_a11mce[] = { 20static struct rc_map_table genius_tvgo_a11mce[] = {
21 /* Keys 0 to 9 */ 21 /* Keys 0 to 9 */
22 { 0x48, KEY_0 }, 22 { 0x48, KEY_0 },
23 { 0x09, KEY_1 }, 23 { 0x09, KEY_1 },
@@ -58,23 +58,23 @@ static struct ir_scancode genius_tvgo_a11mce[] = {
58 { 0x50, KEY_BLUE }, 58 { 0x50, KEY_BLUE },
59}; 59};
60 60
61static struct rc_keymap genius_tvgo_a11mce_map = { 61static struct rc_map_list genius_tvgo_a11mce_map = {
62 .map = { 62 .map = {
63 .scan = genius_tvgo_a11mce, 63 .scan = genius_tvgo_a11mce,
64 .size = ARRAY_SIZE(genius_tvgo_a11mce), 64 .size = ARRAY_SIZE(genius_tvgo_a11mce),
65 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 65 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
66 .name = RC_MAP_GENIUS_TVGO_A11MCE, 66 .name = RC_MAP_GENIUS_TVGO_A11MCE,
67 } 67 }
68}; 68};
69 69
70static int __init init_rc_map_genius_tvgo_a11mce(void) 70static int __init init_rc_map_genius_tvgo_a11mce(void)
71{ 71{
72 return ir_register_map(&genius_tvgo_a11mce_map); 72 return rc_map_register(&genius_tvgo_a11mce_map);
73} 73}
74 74
75static void __exit exit_rc_map_genius_tvgo_a11mce(void) 75static void __exit exit_rc_map_genius_tvgo_a11mce(void)
76{ 76{
77 ir_unregister_map(&genius_tvgo_a11mce_map); 77 rc_map_unregister(&genius_tvgo_a11mce_map);
78} 78}
79 79
80module_init(init_rc_map_genius_tvgo_a11mce) 80module_init(init_rc_map_genius_tvgo_a11mce)
diff --git a/drivers/media/IR/keymaps/rc-gotview7135.c b/drivers/media/rc/keymaps/rc-gotview7135.c
index 52f025bb35f6..a38bdde8c140 100644
--- a/drivers/media/IR/keymaps/rc-gotview7135.c
+++ b/drivers/media/rc/keymaps/rc-gotview7135.c
@@ -14,7 +14,7 @@
14 14
15/* Mike Baikov <mike@baikov.com> */ 15/* Mike Baikov <mike@baikov.com> */
16 16
17static struct ir_scancode gotview7135[] = { 17static struct rc_map_table gotview7135[] = {
18 18
19 { 0x11, KEY_POWER }, 19 { 0x11, KEY_POWER },
20 { 0x35, KEY_TV }, 20 { 0x35, KEY_TV },
@@ -53,23 +53,23 @@ static struct ir_scancode gotview7135[] = {
53 { 0x38, KEY_F24 }, /* NORMAL TIMESHIFT */ 53 { 0x38, KEY_F24 }, /* NORMAL TIMESHIFT */
54}; 54};
55 55
56static struct rc_keymap gotview7135_map = { 56static struct rc_map_list gotview7135_map = {
57 .map = { 57 .map = {
58 .scan = gotview7135, 58 .scan = gotview7135,
59 .size = ARRAY_SIZE(gotview7135), 59 .size = ARRAY_SIZE(gotview7135),
60 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 60 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
61 .name = RC_MAP_GOTVIEW7135, 61 .name = RC_MAP_GOTVIEW7135,
62 } 62 }
63}; 63};
64 64
65static int __init init_rc_map_gotview7135(void) 65static int __init init_rc_map_gotview7135(void)
66{ 66{
67 return ir_register_map(&gotview7135_map); 67 return rc_map_register(&gotview7135_map);
68} 68}
69 69
70static void __exit exit_rc_map_gotview7135(void) 70static void __exit exit_rc_map_gotview7135(void)
71{ 71{
72 ir_unregister_map(&gotview7135_map); 72 rc_map_unregister(&gotview7135_map);
73} 73}
74 74
75module_init(init_rc_map_gotview7135) 75module_init(init_rc_map_gotview7135)
diff --git a/drivers/media/IR/keymaps/rc-hauppauge-new.c b/drivers/media/rc/keymaps/rc-hauppauge-new.c
index c6f8cd7c5186..bd11da46e56a 100644
--- a/drivers/media/IR/keymaps/rc-hauppauge-new.c
+++ b/drivers/media/rc/keymaps/rc-hauppauge-new.c
@@ -16,7 +16,7 @@
16 * slightly different versions), shipped with cx88+ivtv cards. 16 * slightly different versions), shipped with cx88+ivtv cards.
17 * almost rc5 coding, but some non-standard keys */ 17 * almost rc5 coding, but some non-standard keys */
18 18
19static struct ir_scancode hauppauge_new[] = { 19static struct rc_map_table hauppauge_new[] = {
20 /* Keys 0 to 9 */ 20 /* Keys 0 to 9 */
21 { 0x00, KEY_0 }, 21 { 0x00, KEY_0 },
22 { 0x01, KEY_1 }, 22 { 0x01, KEY_1 },
@@ -74,23 +74,23 @@ static struct ir_scancode hauppauge_new[] = {
74 { 0x3d, KEY_POWER }, /* system power (green button) */ 74 { 0x3d, KEY_POWER }, /* system power (green button) */
75}; 75};
76 76
77static struct rc_keymap hauppauge_new_map = { 77static struct rc_map_list hauppauge_new_map = {
78 .map = { 78 .map = {
79 .scan = hauppauge_new, 79 .scan = hauppauge_new,
80 .size = ARRAY_SIZE(hauppauge_new), 80 .size = ARRAY_SIZE(hauppauge_new),
81 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 81 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
82 .name = RC_MAP_HAUPPAUGE_NEW, 82 .name = RC_MAP_HAUPPAUGE_NEW,
83 } 83 }
84}; 84};
85 85
86static int __init init_rc_map_hauppauge_new(void) 86static int __init init_rc_map_hauppauge_new(void)
87{ 87{
88 return ir_register_map(&hauppauge_new_map); 88 return rc_map_register(&hauppauge_new_map);
89} 89}
90 90
91static void __exit exit_rc_map_hauppauge_new(void) 91static void __exit exit_rc_map_hauppauge_new(void)
92{ 92{
93 ir_unregister_map(&hauppauge_new_map); 93 rc_map_unregister(&hauppauge_new_map);
94} 94}
95 95
96module_init(init_rc_map_hauppauge_new) 96module_init(init_rc_map_hauppauge_new)
diff --git a/drivers/media/IR/keymaps/rc-imon-mce.c b/drivers/media/rc/keymaps/rc-imon-mce.c
index e49f350e3a0d..cb67184e015c 100644
--- a/drivers/media/IR/keymaps/rc-imon-mce.c
+++ b/drivers/media/rc/keymaps/rc-imon-mce.c
@@ -12,7 +12,7 @@
12#include <media/rc-map.h> 12#include <media/rc-map.h>
13 13
14/* mce-mode imon mce remote key table */ 14/* mce-mode imon mce remote key table */
15static struct ir_scancode imon_mce[] = { 15static struct rc_map_table imon_mce[] = {
16 /* keys sorted mostly by frequency of use to optimize lookups */ 16 /* keys sorted mostly by frequency of use to optimize lookups */
17 { 0x800ff415, KEY_REWIND }, 17 { 0x800ff415, KEY_REWIND },
18 { 0x800ff414, KEY_FASTFORWARD }, 18 { 0x800ff414, KEY_FASTFORWARD },
@@ -115,24 +115,24 @@ static struct ir_scancode imon_mce[] = {
115 115
116}; 116};
117 117
118static struct rc_keymap imon_mce_map = { 118static struct rc_map_list imon_mce_map = {
119 .map = { 119 .map = {
120 .scan = imon_mce, 120 .scan = imon_mce,
121 .size = ARRAY_SIZE(imon_mce), 121 .size = ARRAY_SIZE(imon_mce),
122 /* its RC6, but w/a hardware decoder */ 122 /* its RC6, but w/a hardware decoder */
123 .ir_type = IR_TYPE_RC6, 123 .rc_type = RC_TYPE_RC6,
124 .name = RC_MAP_IMON_MCE, 124 .name = RC_MAP_IMON_MCE,
125 } 125 }
126}; 126};
127 127
128static int __init init_rc_map_imon_mce(void) 128static int __init init_rc_map_imon_mce(void)
129{ 129{
130 return ir_register_map(&imon_mce_map); 130 return rc_map_register(&imon_mce_map);
131} 131}
132 132
133static void __exit exit_rc_map_imon_mce(void) 133static void __exit exit_rc_map_imon_mce(void)
134{ 134{
135 ir_unregister_map(&imon_mce_map); 135 rc_map_unregister(&imon_mce_map);
136} 136}
137 137
138module_init(init_rc_map_imon_mce) 138module_init(init_rc_map_imon_mce)
diff --git a/drivers/media/IR/keymaps/rc-imon-pad.c b/drivers/media/rc/keymaps/rc-imon-pad.c
index bc4db72f02e6..eef46b73ca7b 100644
--- a/drivers/media/IR/keymaps/rc-imon-pad.c
+++ b/drivers/media/rc/keymaps/rc-imon-pad.c
@@ -17,7 +17,7 @@
17 * same remote to different hex codes, and the silkscreened names 17 * same remote to different hex codes, and the silkscreened names
18 * vary a bit between the SoundGraph and Antec remotes... ugh. 18 * vary a bit between the SoundGraph and Antec remotes... ugh.
19 */ 19 */
20static struct ir_scancode imon_pad[] = { 20static struct rc_map_table imon_pad[] = {
21 /* keys sorted mostly by frequency of use to optimize lookups */ 21 /* keys sorted mostly by frequency of use to optimize lookups */
22 { 0x2a8195b7, KEY_REWIND }, 22 { 0x2a8195b7, KEY_REWIND },
23 { 0x298315b7, KEY_REWIND }, 23 { 0x298315b7, KEY_REWIND },
@@ -129,24 +129,24 @@ static struct ir_scancode imon_pad[] = {
129 { 0x29b715b7, KEY_DASHBOARD }, /* AppLauncher */ 129 { 0x29b715b7, KEY_DASHBOARD }, /* AppLauncher */
130}; 130};
131 131
132static struct rc_keymap imon_pad_map = { 132static struct rc_map_list imon_pad_map = {
133 .map = { 133 .map = {
134 .scan = imon_pad, 134 .scan = imon_pad,
135 .size = ARRAY_SIZE(imon_pad), 135 .size = ARRAY_SIZE(imon_pad),
136 /* actual protocol details unknown, hardware decoder */ 136 /* actual protocol details unknown, hardware decoder */
137 .ir_type = IR_TYPE_OTHER, 137 .rc_type = RC_TYPE_OTHER,
138 .name = RC_MAP_IMON_PAD, 138 .name = RC_MAP_IMON_PAD,
139 } 139 }
140}; 140};
141 141
142static int __init init_rc_map_imon_pad(void) 142static int __init init_rc_map_imon_pad(void)
143{ 143{
144 return ir_register_map(&imon_pad_map); 144 return rc_map_register(&imon_pad_map);
145} 145}
146 146
147static void __exit exit_rc_map_imon_pad(void) 147static void __exit exit_rc_map_imon_pad(void)
148{ 148{
149 ir_unregister_map(&imon_pad_map); 149 rc_map_unregister(&imon_pad_map);
150} 150}
151 151
152module_init(init_rc_map_imon_pad) 152module_init(init_rc_map_imon_pad)
diff --git a/drivers/media/IR/keymaps/rc-iodata-bctv7e.c b/drivers/media/rc/keymaps/rc-iodata-bctv7e.c
index ef6600259fc0..1f59e163f75d 100644
--- a/drivers/media/IR/keymaps/rc-iodata-bctv7e.c
+++ b/drivers/media/rc/keymaps/rc-iodata-bctv7e.c
@@ -14,7 +14,7 @@
14 14
15/* IO-DATA BCTV7E Remote */ 15/* IO-DATA BCTV7E Remote */
16 16
17static struct ir_scancode iodata_bctv7e[] = { 17static struct rc_map_table iodata_bctv7e[] = {
18 { 0x40, KEY_TV }, 18 { 0x40, KEY_TV },
19 { 0x20, KEY_RADIO }, /* FM */ 19 { 0x20, KEY_RADIO }, /* FM */
20 { 0x60, KEY_EPG }, 20 { 0x60, KEY_EPG },
@@ -62,23 +62,23 @@ static struct ir_scancode iodata_bctv7e[] = {
62 { 0x01, KEY_NEXT }, /* skip >| */ 62 { 0x01, KEY_NEXT }, /* skip >| */
63}; 63};
64 64
65static struct rc_keymap iodata_bctv7e_map = { 65static struct rc_map_list iodata_bctv7e_map = {
66 .map = { 66 .map = {
67 .scan = iodata_bctv7e, 67 .scan = iodata_bctv7e,
68 .size = ARRAY_SIZE(iodata_bctv7e), 68 .size = ARRAY_SIZE(iodata_bctv7e),
69 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 69 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
70 .name = RC_MAP_IODATA_BCTV7E, 70 .name = RC_MAP_IODATA_BCTV7E,
71 } 71 }
72}; 72};
73 73
74static int __init init_rc_map_iodata_bctv7e(void) 74static int __init init_rc_map_iodata_bctv7e(void)
75{ 75{
76 return ir_register_map(&iodata_bctv7e_map); 76 return rc_map_register(&iodata_bctv7e_map);
77} 77}
78 78
79static void __exit exit_rc_map_iodata_bctv7e(void) 79static void __exit exit_rc_map_iodata_bctv7e(void)
80{ 80{
81 ir_unregister_map(&iodata_bctv7e_map); 81 rc_map_unregister(&iodata_bctv7e_map);
82} 82}
83 83
84module_init(init_rc_map_iodata_bctv7e) 84module_init(init_rc_map_iodata_bctv7e)
diff --git a/drivers/media/IR/keymaps/rc-kaiomy.c b/drivers/media/rc/keymaps/rc-kaiomy.c
index 4c7883ba0f15..f31dc5c1ad9c 100644
--- a/drivers/media/IR/keymaps/rc-kaiomy.c
+++ b/drivers/media/rc/keymaps/rc-kaiomy.c
@@ -16,7 +16,7 @@
16 Mauro Carvalho Chehab <mchehab@infradead.org> 16 Mauro Carvalho Chehab <mchehab@infradead.org>
17 */ 17 */
18 18
19static struct ir_scancode kaiomy[] = { 19static struct rc_map_table kaiomy[] = {
20 { 0x43, KEY_POWER2}, 20 { 0x43, KEY_POWER2},
21 { 0x01, KEY_LIST}, 21 { 0x01, KEY_LIST},
22 { 0x0b, KEY_ZOOM}, 22 { 0x0b, KEY_ZOOM},
@@ -61,23 +61,23 @@ static struct ir_scancode kaiomy[] = {
61 { 0x1f, KEY_BLUE}, 61 { 0x1f, KEY_BLUE},
62}; 62};
63 63
64static struct rc_keymap kaiomy_map = { 64static struct rc_map_list kaiomy_map = {
65 .map = { 65 .map = {
66 .scan = kaiomy, 66 .scan = kaiomy,
67 .size = ARRAY_SIZE(kaiomy), 67 .size = ARRAY_SIZE(kaiomy),
68 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 68 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
69 .name = RC_MAP_KAIOMY, 69 .name = RC_MAP_KAIOMY,
70 } 70 }
71}; 71};
72 72
73static int __init init_rc_map_kaiomy(void) 73static int __init init_rc_map_kaiomy(void)
74{ 74{
75 return ir_register_map(&kaiomy_map); 75 return rc_map_register(&kaiomy_map);
76} 76}
77 77
78static void __exit exit_rc_map_kaiomy(void) 78static void __exit exit_rc_map_kaiomy(void)
79{ 79{
80 ir_unregister_map(&kaiomy_map); 80 rc_map_unregister(&kaiomy_map);
81} 81}
82 82
83module_init(init_rc_map_kaiomy) 83module_init(init_rc_map_kaiomy)
diff --git a/drivers/media/IR/keymaps/rc-kworld-315u.c b/drivers/media/rc/keymaps/rc-kworld-315u.c
index 618c817374e6..3ce6ef79fc34 100644
--- a/drivers/media/IR/keymaps/rc-kworld-315u.c
+++ b/drivers/media/rc/keymaps/rc-kworld-315u.c
@@ -15,7 +15,7 @@
15/* Kworld 315U 15/* Kworld 315U
16 */ 16 */
17 17
18static struct ir_scancode kworld_315u[] = { 18static struct rc_map_table kworld_315u[] = {
19 { 0x6143, KEY_POWER }, 19 { 0x6143, KEY_POWER },
20 { 0x6101, KEY_TUNER }, /* source */ 20 { 0x6101, KEY_TUNER }, /* source */
21 { 0x610b, KEY_ZOOM }, 21 { 0x610b, KEY_ZOOM },
@@ -57,23 +57,23 @@ static struct ir_scancode kworld_315u[] = {
57 { 0x611f, KEY_BLUE }, 57 { 0x611f, KEY_BLUE },
58}; 58};
59 59
60static struct rc_keymap kworld_315u_map = { 60static struct rc_map_list kworld_315u_map = {
61 .map = { 61 .map = {
62 .scan = kworld_315u, 62 .scan = kworld_315u,
63 .size = ARRAY_SIZE(kworld_315u), 63 .size = ARRAY_SIZE(kworld_315u),
64 .ir_type = IR_TYPE_NEC, 64 .rc_type = RC_TYPE_NEC,
65 .name = RC_MAP_KWORLD_315U, 65 .name = RC_MAP_KWORLD_315U,
66 } 66 }
67}; 67};
68 68
69static int __init init_rc_map_kworld_315u(void) 69static int __init init_rc_map_kworld_315u(void)
70{ 70{
71 return ir_register_map(&kworld_315u_map); 71 return rc_map_register(&kworld_315u_map);
72} 72}
73 73
74static void __exit exit_rc_map_kworld_315u(void) 74static void __exit exit_rc_map_kworld_315u(void)
75{ 75{
76 ir_unregister_map(&kworld_315u_map); 76 rc_map_unregister(&kworld_315u_map);
77} 77}
78 78
79module_init(init_rc_map_kworld_315u) 79module_init(init_rc_map_kworld_315u)
diff --git a/drivers/media/IR/keymaps/rc-kworld-plus-tv-analog.c b/drivers/media/rc/keymaps/rc-kworld-plus-tv-analog.c
index 366732f1f7b7..e45f0b8759d0 100644
--- a/drivers/media/IR/keymaps/rc-kworld-plus-tv-analog.c
+++ b/drivers/media/rc/keymaps/rc-kworld-plus-tv-analog.c
@@ -16,7 +16,7 @@
16 Mauro Carvalho Chehab <mchehab@infradead.org> 16 Mauro Carvalho Chehab <mchehab@infradead.org>
17 */ 17 */
18 18
19static struct ir_scancode kworld_plus_tv_analog[] = { 19static struct rc_map_table kworld_plus_tv_analog[] = {
20 { 0x0c, KEY_PROG1 }, /* Kworld key */ 20 { 0x0c, KEY_PROG1 }, /* Kworld key */
21 { 0x16, KEY_CLOSECD }, /* -> ) */ 21 { 0x16, KEY_CLOSECD }, /* -> ) */
22 { 0x1d, KEY_POWER2 }, 22 { 0x1d, KEY_POWER2 },
@@ -73,23 +73,23 @@ static struct ir_scancode kworld_plus_tv_analog[] = {
73 { 0x23, KEY_GREEN}, /* C */ 73 { 0x23, KEY_GREEN}, /* C */
74}; 74};
75 75
76static struct rc_keymap kworld_plus_tv_analog_map = { 76static struct rc_map_list kworld_plus_tv_analog_map = {
77 .map = { 77 .map = {
78 .scan = kworld_plus_tv_analog, 78 .scan = kworld_plus_tv_analog,
79 .size = ARRAY_SIZE(kworld_plus_tv_analog), 79 .size = ARRAY_SIZE(kworld_plus_tv_analog),
80 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 80 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
81 .name = RC_MAP_KWORLD_PLUS_TV_ANALOG, 81 .name = RC_MAP_KWORLD_PLUS_TV_ANALOG,
82 } 82 }
83}; 83};
84 84
85static int __init init_rc_map_kworld_plus_tv_analog(void) 85static int __init init_rc_map_kworld_plus_tv_analog(void)
86{ 86{
87 return ir_register_map(&kworld_plus_tv_analog_map); 87 return rc_map_register(&kworld_plus_tv_analog_map);
88} 88}
89 89
90static void __exit exit_rc_map_kworld_plus_tv_analog(void) 90static void __exit exit_rc_map_kworld_plus_tv_analog(void)
91{ 91{
92 ir_unregister_map(&kworld_plus_tv_analog_map); 92 rc_map_unregister(&kworld_plus_tv_analog_map);
93} 93}
94 94
95module_init(init_rc_map_kworld_plus_tv_analog) 95module_init(init_rc_map_kworld_plus_tv_analog)
diff --git a/drivers/media/IR/keymaps/rc-leadtek-y04g0051.c b/drivers/media/rc/keymaps/rc-leadtek-y04g0051.c
index 7521315fd876..8faa54ff16e6 100644
--- a/drivers/media/IR/keymaps/rc-leadtek-y04g0051.c
+++ b/drivers/media/rc/keymaps/rc-leadtek-y04g0051.c
@@ -20,7 +20,7 @@
20 20
21#include <media/rc-map.h> 21#include <media/rc-map.h>
22 22
23static struct ir_scancode leadtek_y04g0051[] = { 23static struct rc_map_table leadtek_y04g0051[] = {
24 { 0x0300, KEY_POWER2 }, 24 { 0x0300, KEY_POWER2 },
25 { 0x0303, KEY_SCREEN }, 25 { 0x0303, KEY_SCREEN },
26 { 0x0304, KEY_RIGHT }, 26 { 0x0304, KEY_RIGHT },
@@ -73,23 +73,23 @@ static struct ir_scancode leadtek_y04g0051[] = {
73 { 0x035f, KEY_CHANNELDOWN }, 73 { 0x035f, KEY_CHANNELDOWN },
74}; 74};
75 75
76static struct rc_keymap leadtek_y04g0051_map = { 76static struct rc_map_list leadtek_y04g0051_map = {
77 .map = { 77 .map = {
78 .scan = leadtek_y04g0051, 78 .scan = leadtek_y04g0051,
79 .size = ARRAY_SIZE(leadtek_y04g0051), 79 .size = ARRAY_SIZE(leadtek_y04g0051),
80 .ir_type = IR_TYPE_NEC, 80 .rc_type = RC_TYPE_NEC,
81 .name = RC_MAP_LEADTEK_Y04G0051, 81 .name = RC_MAP_LEADTEK_Y04G0051,
82 } 82 }
83}; 83};
84 84
85static int __init init_rc_map_leadtek_y04g0051(void) 85static int __init init_rc_map_leadtek_y04g0051(void)
86{ 86{
87 return ir_register_map(&leadtek_y04g0051_map); 87 return rc_map_register(&leadtek_y04g0051_map);
88} 88}
89 89
90static void __exit exit_rc_map_leadtek_y04g0051(void) 90static void __exit exit_rc_map_leadtek_y04g0051(void)
91{ 91{
92 ir_unregister_map(&leadtek_y04g0051_map); 92 rc_map_unregister(&leadtek_y04g0051_map);
93} 93}
94 94
95module_init(init_rc_map_leadtek_y04g0051) 95module_init(init_rc_map_leadtek_y04g0051)
diff --git a/drivers/media/IR/keymaps/rc-lirc.c b/drivers/media/rc/keymaps/rc-lirc.c
index 43fcf9035082..e8e23e233c39 100644
--- a/drivers/media/IR/keymaps/rc-lirc.c
+++ b/drivers/media/rc/keymaps/rc-lirc.c
@@ -9,29 +9,29 @@
9 * (at your option) any later version. 9 * (at your option) any later version.
10 */ 10 */
11 11
12#include <media/ir-core.h> 12#include <media/rc-core.h>
13 13
14static struct ir_scancode lirc[] = { 14static struct rc_map_table lirc[] = {
15 { }, 15 { },
16}; 16};
17 17
18static struct rc_keymap lirc_map = { 18static struct rc_map_list lirc_map = {
19 .map = { 19 .map = {
20 .scan = lirc, 20 .scan = lirc,
21 .size = ARRAY_SIZE(lirc), 21 .size = ARRAY_SIZE(lirc),
22 .ir_type = IR_TYPE_LIRC, 22 .rc_type = RC_TYPE_LIRC,
23 .name = RC_MAP_LIRC, 23 .name = RC_MAP_LIRC,
24 } 24 }
25}; 25};
26 26
27static int __init init_rc_map_lirc(void) 27static int __init init_rc_map_lirc(void)
28{ 28{
29 return ir_register_map(&lirc_map); 29 return rc_map_register(&lirc_map);
30} 30}
31 31
32static void __exit exit_rc_map_lirc(void) 32static void __exit exit_rc_map_lirc(void)
33{ 33{
34 ir_unregister_map(&lirc_map); 34 rc_map_unregister(&lirc_map);
35} 35}
36 36
37module_init(init_rc_map_lirc) 37module_init(init_rc_map_lirc)
diff --git a/drivers/media/IR/keymaps/rc-lme2510.c b/drivers/media/rc/keymaps/rc-lme2510.c
index 40dcf0b4e21a..875cd81477c7 100644
--- a/drivers/media/IR/keymaps/rc-lme2510.c
+++ b/drivers/media/rc/keymaps/rc-lme2510.c
@@ -12,7 +12,7 @@
12#include <media/rc-map.h> 12#include <media/rc-map.h>
13 13
14 14
15static struct ir_scancode lme2510_rc[] = { 15static struct rc_map_table lme2510_rc[] = {
16 { 0xba45, KEY_0 }, 16 { 0xba45, KEY_0 },
17 { 0xa05f, KEY_1 }, 17 { 0xa05f, KEY_1 },
18 { 0xaf50, KEY_2 }, 18 { 0xaf50, KEY_2 },
@@ -42,23 +42,23 @@ static struct ir_scancode lme2510_rc[] = {
42 42
43}; 43};
44 44
45static struct rc_keymap lme2510_map = { 45static struct rc_map_list lme2510_map = {
46 .map = { 46 .map = {
47 .scan = lme2510_rc, 47 .scan = lme2510_rc,
48 .size = ARRAY_SIZE(lme2510_rc), 48 .size = ARRAY_SIZE(lme2510_rc),
49 .ir_type = IR_TYPE_UNKNOWN, 49 .rc_type = RC_TYPE_UNKNOWN,
50 .name = RC_MAP_LME2510, 50 .name = RC_MAP_LME2510,
51 } 51 }
52}; 52};
53 53
54static int __init init_rc_lme2510_map(void) 54static int __init init_rc_lme2510_map(void)
55{ 55{
56 return ir_register_map(&lme2510_map); 56 return rc_map_register(&lme2510_map);
57} 57}
58 58
59static void __exit exit_rc_lme2510_map(void) 59static void __exit exit_rc_lme2510_map(void)
60{ 60{
61 ir_unregister_map(&lme2510_map); 61 rc_map_unregister(&lme2510_map);
62} 62}
63 63
64module_init(init_rc_lme2510_map) 64module_init(init_rc_lme2510_map)
diff --git a/drivers/media/IR/keymaps/rc-manli.c b/drivers/media/rc/keymaps/rc-manli.c
index 0f590b3d01c0..23b2d04e7a9f 100644
--- a/drivers/media/IR/keymaps/rc-manli.c
+++ b/drivers/media/rc/keymaps/rc-manli.c
@@ -21,7 +21,7 @@
21 helps to descide which keycodes to assign to the buttons. 21 helps to descide which keycodes to assign to the buttons.
22 */ 22 */
23 23
24static struct ir_scancode manli[] = { 24static struct rc_map_table manli[] = {
25 25
26 /* 0x1c 0x12 * 26 /* 0x1c 0x12 *
27 * FUNCTION POWER * 27 * FUNCTION POWER *
@@ -108,23 +108,23 @@ static struct ir_scancode manli[] = {
108 /* 0x1d unused ? */ 108 /* 0x1d unused ? */
109}; 109};
110 110
111static struct rc_keymap manli_map = { 111static struct rc_map_list manli_map = {
112 .map = { 112 .map = {
113 .scan = manli, 113 .scan = manli,
114 .size = ARRAY_SIZE(manli), 114 .size = ARRAY_SIZE(manli),
115 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 115 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
116 .name = RC_MAP_MANLI, 116 .name = RC_MAP_MANLI,
117 } 117 }
118}; 118};
119 119
120static int __init init_rc_map_manli(void) 120static int __init init_rc_map_manli(void)
121{ 121{
122 return ir_register_map(&manli_map); 122 return rc_map_register(&manli_map);
123} 123}
124 124
125static void __exit exit_rc_map_manli(void) 125static void __exit exit_rc_map_manli(void)
126{ 126{
127 ir_unregister_map(&manli_map); 127 rc_map_unregister(&manli_map);
128} 128}
129 129
130module_init(init_rc_map_manli) 130module_init(init_rc_map_manli)
diff --git a/drivers/media/IR/keymaps/rc-msi-digivox-ii.c b/drivers/media/rc/keymaps/rc-msi-digivox-ii.c
index 67237fbf9e4b..7b9a01b6e4cf 100644
--- a/drivers/media/IR/keymaps/rc-msi-digivox-ii.c
+++ b/drivers/media/rc/keymaps/rc-msi-digivox-ii.c
@@ -20,7 +20,7 @@
20 20
21#include <media/rc-map.h> 21#include <media/rc-map.h>
22 22
23static struct ir_scancode msi_digivox_ii[] = { 23static struct rc_map_table msi_digivox_ii[] = {
24 { 0x0002, KEY_2 }, 24 { 0x0002, KEY_2 },
25 { 0x0003, KEY_UP }, /* up */ 25 { 0x0003, KEY_UP }, /* up */
26 { 0x0004, KEY_3 }, 26 { 0x0004, KEY_3 },
@@ -41,23 +41,23 @@ static struct ir_scancode msi_digivox_ii[] = {
41 { 0x001f, KEY_VOLUMEDOWN }, 41 { 0x001f, KEY_VOLUMEDOWN },
42}; 42};
43 43
44static struct rc_keymap msi_digivox_ii_map = { 44static struct rc_map_list msi_digivox_ii_map = {
45 .map = { 45 .map = {
46 .scan = msi_digivox_ii, 46 .scan = msi_digivox_ii,
47 .size = ARRAY_SIZE(msi_digivox_ii), 47 .size = ARRAY_SIZE(msi_digivox_ii),
48 .ir_type = IR_TYPE_NEC, 48 .rc_type = RC_TYPE_NEC,
49 .name = RC_MAP_MSI_DIGIVOX_II, 49 .name = RC_MAP_MSI_DIGIVOX_II,
50 } 50 }
51}; 51};
52 52
53static int __init init_rc_map_msi_digivox_ii(void) 53static int __init init_rc_map_msi_digivox_ii(void)
54{ 54{
55 return ir_register_map(&msi_digivox_ii_map); 55 return rc_map_register(&msi_digivox_ii_map);
56} 56}
57 57
58static void __exit exit_rc_map_msi_digivox_ii(void) 58static void __exit exit_rc_map_msi_digivox_ii(void)
59{ 59{
60 ir_unregister_map(&msi_digivox_ii_map); 60 rc_map_unregister(&msi_digivox_ii_map);
61} 61}
62 62
63module_init(init_rc_map_msi_digivox_ii) 63module_init(init_rc_map_msi_digivox_ii)
diff --git a/drivers/media/IR/keymaps/rc-msi-digivox-iii.c b/drivers/media/rc/keymaps/rc-msi-digivox-iii.c
index 882056e52ef9..ae9d06b39157 100644
--- a/drivers/media/IR/keymaps/rc-msi-digivox-iii.c
+++ b/drivers/media/rc/keymaps/rc-msi-digivox-iii.c
@@ -24,7 +24,7 @@
24/* Uses NEC extended 0x61d6. */ 24/* Uses NEC extended 0x61d6. */
25/* This remote seems to be same as rc-kworld-315u.c. Anyhow, add new remote 25/* This remote seems to be same as rc-kworld-315u.c. Anyhow, add new remote
26 since rc-kworld-315u.c lacks NEC extended address byte. */ 26 since rc-kworld-315u.c lacks NEC extended address byte. */
27static struct ir_scancode msi_digivox_iii[] = { 27static struct rc_map_table msi_digivox_iii[] = {
28 { 0x61d601, KEY_VIDEO }, /* Source */ 28 { 0x61d601, KEY_VIDEO }, /* Source */
29 { 0x61d602, KEY_3 }, 29 { 0x61d602, KEY_3 },
30 { 0x61d603, KEY_POWER }, /* ShutDown */ 30 { 0x61d603, KEY_POWER }, /* ShutDown */
@@ -59,23 +59,23 @@ static struct ir_scancode msi_digivox_iii[] = {
59 { 0x61d643, KEY_POWER2 }, /* [red power button] */ 59 { 0x61d643, KEY_POWER2 }, /* [red power button] */
60}; 60};
61 61
62static struct rc_keymap msi_digivox_iii_map = { 62static struct rc_map_list msi_digivox_iii_map = {
63 .map = { 63 .map = {
64 .scan = msi_digivox_iii, 64 .scan = msi_digivox_iii,
65 .size = ARRAY_SIZE(msi_digivox_iii), 65 .size = ARRAY_SIZE(msi_digivox_iii),
66 .ir_type = IR_TYPE_NEC, 66 .rc_type = RC_TYPE_NEC,
67 .name = RC_MAP_MSI_DIGIVOX_III, 67 .name = RC_MAP_MSI_DIGIVOX_III,
68 } 68 }
69}; 69};
70 70
71static int __init init_rc_map_msi_digivox_iii(void) 71static int __init init_rc_map_msi_digivox_iii(void)
72{ 72{
73 return ir_register_map(&msi_digivox_iii_map); 73 return rc_map_register(&msi_digivox_iii_map);
74} 74}
75 75
76static void __exit exit_rc_map_msi_digivox_iii(void) 76static void __exit exit_rc_map_msi_digivox_iii(void)
77{ 77{
78 ir_unregister_map(&msi_digivox_iii_map); 78 rc_map_unregister(&msi_digivox_iii_map);
79} 79}
80 80
81module_init(init_rc_map_msi_digivox_iii) 81module_init(init_rc_map_msi_digivox_iii)
diff --git a/drivers/media/IR/keymaps/rc-msi-tvanywhere-plus.c b/drivers/media/rc/keymaps/rc-msi-tvanywhere-plus.c
index eb8e42c18ff9..fa8fd0ab94c7 100644
--- a/drivers/media/IR/keymaps/rc-msi-tvanywhere-plus.c
+++ b/drivers/media/rc/keymaps/rc-msi-tvanywhere-plus.c
@@ -26,7 +26,7 @@
26 Some changes to formatting and keycodes by Mark Schultz <n9xmj@yahoo.com> 26 Some changes to formatting and keycodes by Mark Schultz <n9xmj@yahoo.com>
27*/ 27*/
28 28
29static struct ir_scancode msi_tvanywhere_plus[] = { 29static struct rc_map_table msi_tvanywhere_plus[] = {
30 30
31/* ---- Remote Button Layout ---- 31/* ---- Remote Button Layout ----
32 32
@@ -97,23 +97,23 @@ static struct ir_scancode msi_tvanywhere_plus[] = {
97 { 0x1d, KEY_RESTART }, /* Reset */ 97 { 0x1d, KEY_RESTART }, /* Reset */
98}; 98};
99 99
100static struct rc_keymap msi_tvanywhere_plus_map = { 100static struct rc_map_list msi_tvanywhere_plus_map = {
101 .map = { 101 .map = {
102 .scan = msi_tvanywhere_plus, 102 .scan = msi_tvanywhere_plus,
103 .size = ARRAY_SIZE(msi_tvanywhere_plus), 103 .size = ARRAY_SIZE(msi_tvanywhere_plus),
104 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 104 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
105 .name = RC_MAP_MSI_TVANYWHERE_PLUS, 105 .name = RC_MAP_MSI_TVANYWHERE_PLUS,
106 } 106 }
107}; 107};
108 108
109static int __init init_rc_map_msi_tvanywhere_plus(void) 109static int __init init_rc_map_msi_tvanywhere_plus(void)
110{ 110{
111 return ir_register_map(&msi_tvanywhere_plus_map); 111 return rc_map_register(&msi_tvanywhere_plus_map);
112} 112}
113 113
114static void __exit exit_rc_map_msi_tvanywhere_plus(void) 114static void __exit exit_rc_map_msi_tvanywhere_plus(void)
115{ 115{
116 ir_unregister_map(&msi_tvanywhere_plus_map); 116 rc_map_unregister(&msi_tvanywhere_plus_map);
117} 117}
118 118
119module_init(init_rc_map_msi_tvanywhere_plus) 119module_init(init_rc_map_msi_tvanywhere_plus)
diff --git a/drivers/media/IR/keymaps/rc-msi-tvanywhere.c b/drivers/media/rc/keymaps/rc-msi-tvanywhere.c
index ef411854f067..18b37facb0dd 100644
--- a/drivers/media/IR/keymaps/rc-msi-tvanywhere.c
+++ b/drivers/media/rc/keymaps/rc-msi-tvanywhere.c
@@ -14,7 +14,7 @@
14 14
15/* MSI TV@nywhere MASTER remote */ 15/* MSI TV@nywhere MASTER remote */
16 16
17static struct ir_scancode msi_tvanywhere[] = { 17static struct rc_map_table msi_tvanywhere[] = {
18 /* Keys 0 to 9 */ 18 /* Keys 0 to 9 */
19 { 0x00, KEY_0 }, 19 { 0x00, KEY_0 },
20 { 0x01, KEY_1 }, 20 { 0x01, KEY_1 },
@@ -43,23 +43,23 @@ static struct ir_scancode msi_tvanywhere[] = {
43 { 0x1f, KEY_VOLUMEDOWN }, 43 { 0x1f, KEY_VOLUMEDOWN },
44}; 44};
45 45
46static struct rc_keymap msi_tvanywhere_map = { 46static struct rc_map_list msi_tvanywhere_map = {
47 .map = { 47 .map = {
48 .scan = msi_tvanywhere, 48 .scan = msi_tvanywhere,
49 .size = ARRAY_SIZE(msi_tvanywhere), 49 .size = ARRAY_SIZE(msi_tvanywhere),
50 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 50 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
51 .name = RC_MAP_MSI_TVANYWHERE, 51 .name = RC_MAP_MSI_TVANYWHERE,
52 } 52 }
53}; 53};
54 54
55static int __init init_rc_map_msi_tvanywhere(void) 55static int __init init_rc_map_msi_tvanywhere(void)
56{ 56{
57 return ir_register_map(&msi_tvanywhere_map); 57 return rc_map_register(&msi_tvanywhere_map);
58} 58}
59 59
60static void __exit exit_rc_map_msi_tvanywhere(void) 60static void __exit exit_rc_map_msi_tvanywhere(void)
61{ 61{
62 ir_unregister_map(&msi_tvanywhere_map); 62 rc_map_unregister(&msi_tvanywhere_map);
63} 63}
64 64
65module_init(init_rc_map_msi_tvanywhere) 65module_init(init_rc_map_msi_tvanywhere)
diff --git a/drivers/media/IR/keymaps/rc-nebula.c b/drivers/media/rc/keymaps/rc-nebula.c
index ccc50eb402ec..3e6f077eb700 100644
--- a/drivers/media/IR/keymaps/rc-nebula.c
+++ b/drivers/media/rc/keymaps/rc-nebula.c
@@ -12,7 +12,7 @@
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14 14
15static struct ir_scancode nebula[] = { 15static struct rc_map_table nebula[] = {
16 { 0x00, KEY_0 }, 16 { 0x00, KEY_0 },
17 { 0x01, KEY_1 }, 17 { 0x01, KEY_1 },
18 { 0x02, KEY_2 }, 18 { 0x02, KEY_2 },
@@ -70,23 +70,23 @@ static struct ir_scancode nebula[] = {
70 { 0x36, KEY_PC }, 70 { 0x36, KEY_PC },
71}; 71};
72 72
73static struct rc_keymap nebula_map = { 73static struct rc_map_list nebula_map = {
74 .map = { 74 .map = {
75 .scan = nebula, 75 .scan = nebula,
76 .size = ARRAY_SIZE(nebula), 76 .size = ARRAY_SIZE(nebula),
77 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 77 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
78 .name = RC_MAP_NEBULA, 78 .name = RC_MAP_NEBULA,
79 } 79 }
80}; 80};
81 81
82static int __init init_rc_map_nebula(void) 82static int __init init_rc_map_nebula(void)
83{ 83{
84 return ir_register_map(&nebula_map); 84 return rc_map_register(&nebula_map);
85} 85}
86 86
87static void __exit exit_rc_map_nebula(void) 87static void __exit exit_rc_map_nebula(void)
88{ 88{
89 ir_unregister_map(&nebula_map); 89 rc_map_unregister(&nebula_map);
90} 90}
91 91
92module_init(init_rc_map_nebula) 92module_init(init_rc_map_nebula)
diff --git a/drivers/media/IR/keymaps/rc-nec-terratec-cinergy-xs.c b/drivers/media/rc/keymaps/rc-nec-terratec-cinergy-xs.c
index e1b54d20db60..26f114c5c0de 100644
--- a/drivers/media/IR/keymaps/rc-nec-terratec-cinergy-xs.c
+++ b/drivers/media/rc/keymaps/rc-nec-terratec-cinergy-xs.c
@@ -16,7 +16,7 @@
16 Mauro Carvalho Chehab <mchehab@redhat.com> 16 Mauro Carvalho Chehab <mchehab@redhat.com>
17 */ 17 */
18 18
19static struct ir_scancode nec_terratec_cinergy_xs[] = { 19static struct rc_map_table nec_terratec_cinergy_xs[] = {
20 { 0x1441, KEY_HOME}, 20 { 0x1441, KEY_HOME},
21 { 0x1401, KEY_POWER2}, 21 { 0x1401, KEY_POWER2},
22 22
@@ -79,23 +79,23 @@ static struct ir_scancode nec_terratec_cinergy_xs[] = {
79 { 0x145c, KEY_NEXT}, 79 { 0x145c, KEY_NEXT},
80}; 80};
81 81
82static struct rc_keymap nec_terratec_cinergy_xs_map = { 82static struct rc_map_list nec_terratec_cinergy_xs_map = {
83 .map = { 83 .map = {
84 .scan = nec_terratec_cinergy_xs, 84 .scan = nec_terratec_cinergy_xs,
85 .size = ARRAY_SIZE(nec_terratec_cinergy_xs), 85 .size = ARRAY_SIZE(nec_terratec_cinergy_xs),
86 .ir_type = IR_TYPE_NEC, 86 .rc_type = RC_TYPE_NEC,
87 .name = RC_MAP_NEC_TERRATEC_CINERGY_XS, 87 .name = RC_MAP_NEC_TERRATEC_CINERGY_XS,
88 } 88 }
89}; 89};
90 90
91static int __init init_rc_map_nec_terratec_cinergy_xs(void) 91static int __init init_rc_map_nec_terratec_cinergy_xs(void)
92{ 92{
93 return ir_register_map(&nec_terratec_cinergy_xs_map); 93 return rc_map_register(&nec_terratec_cinergy_xs_map);
94} 94}
95 95
96static void __exit exit_rc_map_nec_terratec_cinergy_xs(void) 96static void __exit exit_rc_map_nec_terratec_cinergy_xs(void)
97{ 97{
98 ir_unregister_map(&nec_terratec_cinergy_xs_map); 98 rc_map_unregister(&nec_terratec_cinergy_xs_map);
99} 99}
100 100
101module_init(init_rc_map_nec_terratec_cinergy_xs) 101module_init(init_rc_map_nec_terratec_cinergy_xs)
diff --git a/drivers/media/IR/keymaps/rc-norwood.c b/drivers/media/rc/keymaps/rc-norwood.c
index e5849a6b3f05..629ee9d84537 100644
--- a/drivers/media/IR/keymaps/rc-norwood.c
+++ b/drivers/media/rc/keymaps/rc-norwood.c
@@ -16,7 +16,7 @@
16 By Peter Naulls <peter@chocky.org> 16 By Peter Naulls <peter@chocky.org>
17 Key comments are the functions given in the manual */ 17 Key comments are the functions given in the manual */
18 18
19static struct ir_scancode norwood[] = { 19static struct rc_map_table norwood[] = {
20 /* Keys 0 to 9 */ 20 /* Keys 0 to 9 */
21 { 0x20, KEY_0 }, 21 { 0x20, KEY_0 },
22 { 0x21, KEY_1 }, 22 { 0x21, KEY_1 },
@@ -59,23 +59,23 @@ static struct ir_scancode norwood[] = {
59 { 0x65, KEY_POWER }, /* Computer power */ 59 { 0x65, KEY_POWER }, /* Computer power */
60}; 60};
61 61
62static struct rc_keymap norwood_map = { 62static struct rc_map_list norwood_map = {
63 .map = { 63 .map = {
64 .scan = norwood, 64 .scan = norwood,
65 .size = ARRAY_SIZE(norwood), 65 .size = ARRAY_SIZE(norwood),
66 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 66 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
67 .name = RC_MAP_NORWOOD, 67 .name = RC_MAP_NORWOOD,
68 } 68 }
69}; 69};
70 70
71static int __init init_rc_map_norwood(void) 71static int __init init_rc_map_norwood(void)
72{ 72{
73 return ir_register_map(&norwood_map); 73 return rc_map_register(&norwood_map);
74} 74}
75 75
76static void __exit exit_rc_map_norwood(void) 76static void __exit exit_rc_map_norwood(void)
77{ 77{
78 ir_unregister_map(&norwood_map); 78 rc_map_unregister(&norwood_map);
79} 79}
80 80
81module_init(init_rc_map_norwood) 81module_init(init_rc_map_norwood)
diff --git a/drivers/media/IR/keymaps/rc-npgtech.c b/drivers/media/rc/keymaps/rc-npgtech.c
index b9ece1e90296..4aa588bf6d69 100644
--- a/drivers/media/IR/keymaps/rc-npgtech.c
+++ b/drivers/media/rc/keymaps/rc-npgtech.c
@@ -12,7 +12,7 @@
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14 14
15static struct ir_scancode npgtech[] = { 15static struct rc_map_table npgtech[] = {
16 { 0x1d, KEY_SWITCHVIDEOMODE }, /* switch inputs */ 16 { 0x1d, KEY_SWITCHVIDEOMODE }, /* switch inputs */
17 { 0x2a, KEY_FRONT }, 17 { 0x2a, KEY_FRONT },
18 18
@@ -54,23 +54,23 @@ static struct ir_scancode npgtech[] = {
54 54
55}; 55};
56 56
57static struct rc_keymap npgtech_map = { 57static struct rc_map_list npgtech_map = {
58 .map = { 58 .map = {
59 .scan = npgtech, 59 .scan = npgtech,
60 .size = ARRAY_SIZE(npgtech), 60 .size = ARRAY_SIZE(npgtech),
61 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 61 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
62 .name = RC_MAP_NPGTECH, 62 .name = RC_MAP_NPGTECH,
63 } 63 }
64}; 64};
65 65
66static int __init init_rc_map_npgtech(void) 66static int __init init_rc_map_npgtech(void)
67{ 67{
68 return ir_register_map(&npgtech_map); 68 return rc_map_register(&npgtech_map);
69} 69}
70 70
71static void __exit exit_rc_map_npgtech(void) 71static void __exit exit_rc_map_npgtech(void)
72{ 72{
73 ir_unregister_map(&npgtech_map); 73 rc_map_unregister(&npgtech_map);
74} 74}
75 75
76module_init(init_rc_map_npgtech) 76module_init(init_rc_map_npgtech)
diff --git a/drivers/media/IR/keymaps/rc-pctv-sedna.c b/drivers/media/rc/keymaps/rc-pctv-sedna.c
index 4129bb44a25b..fa5ae5981eb8 100644
--- a/drivers/media/IR/keymaps/rc-pctv-sedna.c
+++ b/drivers/media/rc/keymaps/rc-pctv-sedna.c
@@ -17,7 +17,7 @@
17 Pavel Mihaylov <bin@bash.info> 17 Pavel Mihaylov <bin@bash.info>
18 Also for the remote bundled with Kozumi KTV-01C card */ 18 Also for the remote bundled with Kozumi KTV-01C card */
19 19
20static struct ir_scancode pctv_sedna[] = { 20static struct rc_map_table pctv_sedna[] = {
21 { 0x00, KEY_0 }, 21 { 0x00, KEY_0 },
22 { 0x01, KEY_1 }, 22 { 0x01, KEY_1 },
23 { 0x02, KEY_2 }, 23 { 0x02, KEY_2 },
@@ -54,23 +54,23 @@ static struct ir_scancode pctv_sedna[] = {
54 { 0x1f, KEY_PLAY }, /* Play */ 54 { 0x1f, KEY_PLAY }, /* Play */
55}; 55};
56 56
57static struct rc_keymap pctv_sedna_map = { 57static struct rc_map_list pctv_sedna_map = {
58 .map = { 58 .map = {
59 .scan = pctv_sedna, 59 .scan = pctv_sedna,
60 .size = ARRAY_SIZE(pctv_sedna), 60 .size = ARRAY_SIZE(pctv_sedna),
61 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 61 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
62 .name = RC_MAP_PCTV_SEDNA, 62 .name = RC_MAP_PCTV_SEDNA,
63 } 63 }
64}; 64};
65 65
66static int __init init_rc_map_pctv_sedna(void) 66static int __init init_rc_map_pctv_sedna(void)
67{ 67{
68 return ir_register_map(&pctv_sedna_map); 68 return rc_map_register(&pctv_sedna_map);
69} 69}
70 70
71static void __exit exit_rc_map_pctv_sedna(void) 71static void __exit exit_rc_map_pctv_sedna(void)
72{ 72{
73 ir_unregister_map(&pctv_sedna_map); 73 rc_map_unregister(&pctv_sedna_map);
74} 74}
75 75
76module_init(init_rc_map_pctv_sedna) 76module_init(init_rc_map_pctv_sedna)
diff --git a/drivers/media/IR/keymaps/rc-pinnacle-color.c b/drivers/media/rc/keymaps/rc-pinnacle-color.c
index 326e023ce126..23b8c505c6aa 100644
--- a/drivers/media/IR/keymaps/rc-pinnacle-color.c
+++ b/drivers/media/rc/keymaps/rc-pinnacle-color.c
@@ -12,7 +12,7 @@
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14 14
15static struct ir_scancode pinnacle_color[] = { 15static struct rc_map_table pinnacle_color[] = {
16 { 0x59, KEY_MUTE }, 16 { 0x59, KEY_MUTE },
17 { 0x4a, KEY_POWER }, 17 { 0x4a, KEY_POWER },
18 18
@@ -68,23 +68,23 @@ static struct ir_scancode pinnacle_color[] = {
68 { 0x0a, KEY_BACKSPACE }, 68 { 0x0a, KEY_BACKSPACE },
69}; 69};
70 70
71static struct rc_keymap pinnacle_color_map = { 71static struct rc_map_list pinnacle_color_map = {
72 .map = { 72 .map = {
73 .scan = pinnacle_color, 73 .scan = pinnacle_color,
74 .size = ARRAY_SIZE(pinnacle_color), 74 .size = ARRAY_SIZE(pinnacle_color),
75 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 75 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
76 .name = RC_MAP_PINNACLE_COLOR, 76 .name = RC_MAP_PINNACLE_COLOR,
77 } 77 }
78}; 78};
79 79
80static int __init init_rc_map_pinnacle_color(void) 80static int __init init_rc_map_pinnacle_color(void)
81{ 81{
82 return ir_register_map(&pinnacle_color_map); 82 return rc_map_register(&pinnacle_color_map);
83} 83}
84 84
85static void __exit exit_rc_map_pinnacle_color(void) 85static void __exit exit_rc_map_pinnacle_color(void)
86{ 86{
87 ir_unregister_map(&pinnacle_color_map); 87 rc_map_unregister(&pinnacle_color_map);
88} 88}
89 89
90module_init(init_rc_map_pinnacle_color) 90module_init(init_rc_map_pinnacle_color)
diff --git a/drivers/media/IR/keymaps/rc-pinnacle-grey.c b/drivers/media/rc/keymaps/rc-pinnacle-grey.c
index 14cb772515c6..6ba8c368d10a 100644
--- a/drivers/media/IR/keymaps/rc-pinnacle-grey.c
+++ b/drivers/media/rc/keymaps/rc-pinnacle-grey.c
@@ -12,7 +12,7 @@
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14 14
15static struct ir_scancode pinnacle_grey[] = { 15static struct rc_map_table pinnacle_grey[] = {
16 { 0x3a, KEY_0 }, 16 { 0x3a, KEY_0 },
17 { 0x31, KEY_1 }, 17 { 0x31, KEY_1 },
18 { 0x32, KEY_2 }, 18 { 0x32, KEY_2 },
@@ -63,23 +63,23 @@ static struct ir_scancode pinnacle_grey[] = {
63 { 0x18, KEY_EPG }, 63 { 0x18, KEY_EPG },
64}; 64};
65 65
66static struct rc_keymap pinnacle_grey_map = { 66static struct rc_map_list pinnacle_grey_map = {
67 .map = { 67 .map = {
68 .scan = pinnacle_grey, 68 .scan = pinnacle_grey,
69 .size = ARRAY_SIZE(pinnacle_grey), 69 .size = ARRAY_SIZE(pinnacle_grey),
70 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 70 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
71 .name = RC_MAP_PINNACLE_GREY, 71 .name = RC_MAP_PINNACLE_GREY,
72 } 72 }
73}; 73};
74 74
75static int __init init_rc_map_pinnacle_grey(void) 75static int __init init_rc_map_pinnacle_grey(void)
76{ 76{
77 return ir_register_map(&pinnacle_grey_map); 77 return rc_map_register(&pinnacle_grey_map);
78} 78}
79 79
80static void __exit exit_rc_map_pinnacle_grey(void) 80static void __exit exit_rc_map_pinnacle_grey(void)
81{ 81{
82 ir_unregister_map(&pinnacle_grey_map); 82 rc_map_unregister(&pinnacle_grey_map);
83} 83}
84 84
85module_init(init_rc_map_pinnacle_grey) 85module_init(init_rc_map_pinnacle_grey)
diff --git a/drivers/media/IR/keymaps/rc-pinnacle-pctv-hd.c b/drivers/media/rc/keymaps/rc-pinnacle-pctv-hd.c
index 835bf4ef8de7..bb10ffe086b4 100644
--- a/drivers/media/IR/keymaps/rc-pinnacle-pctv-hd.c
+++ b/drivers/media/rc/keymaps/rc-pinnacle-pctv-hd.c
@@ -14,7 +14,7 @@
14 14
15/* Pinnacle PCTV HD 800i mini remote */ 15/* Pinnacle PCTV HD 800i mini remote */
16 16
17static struct ir_scancode pinnacle_pctv_hd[] = { 17static struct rc_map_table pinnacle_pctv_hd[] = {
18 18
19 { 0x0f, KEY_1 }, 19 { 0x0f, KEY_1 },
20 { 0x15, KEY_2 }, 20 { 0x15, KEY_2 },
@@ -47,23 +47,23 @@ static struct ir_scancode pinnacle_pctv_hd[] = {
47 { 0x3f, KEY_EPG }, /* Labeled "?" */ 47 { 0x3f, KEY_EPG }, /* Labeled "?" */
48}; 48};
49 49
50static struct rc_keymap pinnacle_pctv_hd_map = { 50static struct rc_map_list pinnacle_pctv_hd_map = {
51 .map = { 51 .map = {
52 .scan = pinnacle_pctv_hd, 52 .scan = pinnacle_pctv_hd,
53 .size = ARRAY_SIZE(pinnacle_pctv_hd), 53 .size = ARRAY_SIZE(pinnacle_pctv_hd),
54 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 54 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
55 .name = RC_MAP_PINNACLE_PCTV_HD, 55 .name = RC_MAP_PINNACLE_PCTV_HD,
56 } 56 }
57}; 57};
58 58
59static int __init init_rc_map_pinnacle_pctv_hd(void) 59static int __init init_rc_map_pinnacle_pctv_hd(void)
60{ 60{
61 return ir_register_map(&pinnacle_pctv_hd_map); 61 return rc_map_register(&pinnacle_pctv_hd_map);
62} 62}
63 63
64static void __exit exit_rc_map_pinnacle_pctv_hd(void) 64static void __exit exit_rc_map_pinnacle_pctv_hd(void)
65{ 65{
66 ir_unregister_map(&pinnacle_pctv_hd_map); 66 rc_map_unregister(&pinnacle_pctv_hd_map);
67} 67}
68 68
69module_init(init_rc_map_pinnacle_pctv_hd) 69module_init(init_rc_map_pinnacle_pctv_hd)
diff --git a/drivers/media/rc/keymaps/rc-pixelview-002t.c b/drivers/media/rc/keymaps/rc-pixelview-002t.c
new file mode 100644
index 000000000000..e5ab071f635a
--- /dev/null
+++ b/drivers/media/rc/keymaps/rc-pixelview-002t.c
@@ -0,0 +1,77 @@
1/* rc-pixelview-mk12.h - Keytable for pixelview Remote Controller
2 *
3 * keymap imported from ir-keymaps.c
4 *
5 * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
12
13#include <media/rc-map.h>
14
15/*
16 * Keytable for 002-T IR remote provided together with Pixelview
17 * SBTVD Hybrid Remote Controller. Uses NEC extended format.
18 */
19static struct rc_map_table pixelview_002t[] = {
20 { 0x866b13, KEY_MUTE },
21 { 0x866b12, KEY_POWER2 }, /* power */
22
23 { 0x866b01, KEY_1 },
24 { 0x866b02, KEY_2 },
25 { 0x866b03, KEY_3 },
26 { 0x866b04, KEY_4 },
27 { 0x866b05, KEY_5 },
28 { 0x866b06, KEY_6 },
29 { 0x866b07, KEY_7 },
30 { 0x866b08, KEY_8 },
31 { 0x866b09, KEY_9 },
32 { 0x866b00, KEY_0 },
33
34 { 0x866b0d, KEY_CHANNELUP },
35 { 0x866b19, KEY_CHANNELDOWN },
36 { 0x866b10, KEY_VOLUMEUP }, /* vol + */
37 { 0x866b0c, KEY_VOLUMEDOWN }, /* vol - */
38
39 { 0x866b0a, KEY_CAMERA }, /* snapshot */
40 { 0x866b0b, KEY_ZOOM }, /* zoom */
41
42 { 0x866b1b, KEY_BACKSPACE },
43 { 0x866b15, KEY_ENTER },
44
45 { 0x866b1d, KEY_UP },
46 { 0x866b1e, KEY_DOWN },
47 { 0x866b0e, KEY_LEFT },
48 { 0x866b0f, KEY_RIGHT },
49
50 { 0x866b18, KEY_RECORD },
51 { 0x866b1a, KEY_STOP },
52};
53
54static struct rc_map_list pixelview_map = {
55 .map = {
56 .scan = pixelview_002t,
57 .size = ARRAY_SIZE(pixelview_002t),
58 .rc_type = RC_TYPE_NEC,
59 .name = RC_MAP_PIXELVIEW_002T,
60 }
61};
62
63static int __init init_rc_map_pixelview(void)
64{
65 return rc_map_register(&pixelview_map);
66}
67
68static void __exit exit_rc_map_pixelview(void)
69{
70 rc_map_unregister(&pixelview_map);
71}
72
73module_init(init_rc_map_pixelview)
74module_exit(exit_rc_map_pixelview)
75
76MODULE_LICENSE("GPL");
77MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-pixelview-mk12.c b/drivers/media/rc/keymaps/rc-pixelview-mk12.c
index 5a735d569a8b..8d9f664e0a2d 100644
--- a/drivers/media/IR/keymaps/rc-pixelview-mk12.c
+++ b/drivers/media/rc/keymaps/rc-pixelview-mk12.c
@@ -16,7 +16,7 @@
16 * Keytable for MK-F12 IR remote provided together with Pixelview 16 * Keytable for MK-F12 IR remote provided together with Pixelview
17 * Ultra Pro Remote Controller. Uses NEC extended format. 17 * Ultra Pro Remote Controller. Uses NEC extended format.
18 */ 18 */
19static struct ir_scancode pixelview_mk12[] = { 19static struct rc_map_table pixelview_mk12[] = {
20 { 0x866b03, KEY_TUNER }, /* Timeshift */ 20 { 0x866b03, KEY_TUNER }, /* Timeshift */
21 { 0x866b1e, KEY_POWER2 }, /* power */ 21 { 0x866b1e, KEY_POWER2 }, /* power */
22 22
@@ -57,23 +57,23 @@ static struct ir_scancode pixelview_mk12[] = {
57 { 0x866b07, KEY_RADIO }, /* FM */ 57 { 0x866b07, KEY_RADIO }, /* FM */
58}; 58};
59 59
60static struct rc_keymap pixelview_map = { 60static struct rc_map_list pixelview_map = {
61 .map = { 61 .map = {
62 .scan = pixelview_mk12, 62 .scan = pixelview_mk12,
63 .size = ARRAY_SIZE(pixelview_mk12), 63 .size = ARRAY_SIZE(pixelview_mk12),
64 .ir_type = IR_TYPE_NEC, 64 .rc_type = RC_TYPE_NEC,
65 .name = RC_MAP_PIXELVIEW_MK12, 65 .name = RC_MAP_PIXELVIEW_MK12,
66 } 66 }
67}; 67};
68 68
69static int __init init_rc_map_pixelview(void) 69static int __init init_rc_map_pixelview(void)
70{ 70{
71 return ir_register_map(&pixelview_map); 71 return rc_map_register(&pixelview_map);
72} 72}
73 73
74static void __exit exit_rc_map_pixelview(void) 74static void __exit exit_rc_map_pixelview(void)
75{ 75{
76 ir_unregister_map(&pixelview_map); 76 rc_map_unregister(&pixelview_map);
77} 77}
78 78
79module_init(init_rc_map_pixelview) 79module_init(init_rc_map_pixelview)
diff --git a/drivers/media/IR/keymaps/rc-pixelview-new.c b/drivers/media/rc/keymaps/rc-pixelview-new.c
index 7bbbbf5735e6..777a70076be2 100644
--- a/drivers/media/IR/keymaps/rc-pixelview-new.c
+++ b/drivers/media/rc/keymaps/rc-pixelview-new.c
@@ -17,7 +17,7 @@
17 present on PV MPEG 8000GT 17 present on PV MPEG 8000GT
18 */ 18 */
19 19
20static struct ir_scancode pixelview_new[] = { 20static struct rc_map_table pixelview_new[] = {
21 { 0x3c, KEY_TIME }, /* Timeshift */ 21 { 0x3c, KEY_TIME }, /* Timeshift */
22 { 0x12, KEY_POWER }, 22 { 0x12, KEY_POWER },
23 23
@@ -57,23 +57,23 @@ static struct ir_scancode pixelview_new[] = {
57 { 0x34, KEY_RADIO }, 57 { 0x34, KEY_RADIO },
58}; 58};
59 59
60static struct rc_keymap pixelview_new_map = { 60static struct rc_map_list pixelview_new_map = {
61 .map = { 61 .map = {
62 .scan = pixelview_new, 62 .scan = pixelview_new,
63 .size = ARRAY_SIZE(pixelview_new), 63 .size = ARRAY_SIZE(pixelview_new),
64 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 64 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
65 .name = RC_MAP_PIXELVIEW_NEW, 65 .name = RC_MAP_PIXELVIEW_NEW,
66 } 66 }
67}; 67};
68 68
69static int __init init_rc_map_pixelview_new(void) 69static int __init init_rc_map_pixelview_new(void)
70{ 70{
71 return ir_register_map(&pixelview_new_map); 71 return rc_map_register(&pixelview_new_map);
72} 72}
73 73
74static void __exit exit_rc_map_pixelview_new(void) 74static void __exit exit_rc_map_pixelview_new(void)
75{ 75{
76 ir_unregister_map(&pixelview_new_map); 76 rc_map_unregister(&pixelview_new_map);
77} 77}
78 78
79module_init(init_rc_map_pixelview_new) 79module_init(init_rc_map_pixelview_new)
diff --git a/drivers/media/IR/keymaps/rc-pixelview.c b/drivers/media/rc/keymaps/rc-pixelview.c
index 82ff12e182a0..0ec5988916b9 100644
--- a/drivers/media/IR/keymaps/rc-pixelview.c
+++ b/drivers/media/rc/keymaps/rc-pixelview.c
@@ -12,7 +12,7 @@
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14 14
15static struct ir_scancode pixelview[] = { 15static struct rc_map_table pixelview[] = {
16 16
17 { 0x1e, KEY_POWER }, /* power */ 17 { 0x1e, KEY_POWER }, /* power */
18 { 0x07, KEY_MEDIA }, /* source */ 18 { 0x07, KEY_MEDIA }, /* source */
@@ -56,23 +56,23 @@ static struct ir_scancode pixelview[] = {
56 { 0x18, KEY_MUTE }, /* mute/unmute */ 56 { 0x18, KEY_MUTE }, /* mute/unmute */
57}; 57};
58 58
59static struct rc_keymap pixelview_map = { 59static struct rc_map_list pixelview_map = {
60 .map = { 60 .map = {
61 .scan = pixelview, 61 .scan = pixelview,
62 .size = ARRAY_SIZE(pixelview), 62 .size = ARRAY_SIZE(pixelview),
63 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 63 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
64 .name = RC_MAP_PIXELVIEW, 64 .name = RC_MAP_PIXELVIEW,
65 } 65 }
66}; 66};
67 67
68static int __init init_rc_map_pixelview(void) 68static int __init init_rc_map_pixelview(void)
69{ 69{
70 return ir_register_map(&pixelview_map); 70 return rc_map_register(&pixelview_map);
71} 71}
72 72
73static void __exit exit_rc_map_pixelview(void) 73static void __exit exit_rc_map_pixelview(void)
74{ 74{
75 ir_unregister_map(&pixelview_map); 75 rc_map_unregister(&pixelview_map);
76} 76}
77 77
78module_init(init_rc_map_pixelview) 78module_init(init_rc_map_pixelview)
diff --git a/drivers/media/IR/keymaps/rc-powercolor-real-angel.c b/drivers/media/rc/keymaps/rc-powercolor-real-angel.c
index 7cef8190a224..5f9d546a86c4 100644
--- a/drivers/media/IR/keymaps/rc-powercolor-real-angel.c
+++ b/drivers/media/rc/keymaps/rc-powercolor-real-angel.c
@@ -17,7 +17,7 @@
17 * Daniel Fraga <fragabr@gmail.com> 17 * Daniel Fraga <fragabr@gmail.com>
18 */ 18 */
19 19
20static struct ir_scancode powercolor_real_angel[] = { 20static struct rc_map_table powercolor_real_angel[] = {
21 { 0x38, KEY_SWITCHVIDEOMODE }, /* switch inputs */ 21 { 0x38, KEY_SWITCHVIDEOMODE }, /* switch inputs */
22 { 0x0c, KEY_MEDIA }, /* Turn ON/OFF App */ 22 { 0x0c, KEY_MEDIA }, /* Turn ON/OFF App */
23 { 0x00, KEY_0 }, 23 { 0x00, KEY_0 },
@@ -55,23 +55,23 @@ static struct ir_scancode powercolor_real_angel[] = {
55 { 0x25, KEY_POWER }, /* power */ 55 { 0x25, KEY_POWER }, /* power */
56}; 56};
57 57
58static struct rc_keymap powercolor_real_angel_map = { 58static struct rc_map_list powercolor_real_angel_map = {
59 .map = { 59 .map = {
60 .scan = powercolor_real_angel, 60 .scan = powercolor_real_angel,
61 .size = ARRAY_SIZE(powercolor_real_angel), 61 .size = ARRAY_SIZE(powercolor_real_angel),
62 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 62 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
63 .name = RC_MAP_POWERCOLOR_REAL_ANGEL, 63 .name = RC_MAP_POWERCOLOR_REAL_ANGEL,
64 } 64 }
65}; 65};
66 66
67static int __init init_rc_map_powercolor_real_angel(void) 67static int __init init_rc_map_powercolor_real_angel(void)
68{ 68{
69 return ir_register_map(&powercolor_real_angel_map); 69 return rc_map_register(&powercolor_real_angel_map);
70} 70}
71 71
72static void __exit exit_rc_map_powercolor_real_angel(void) 72static void __exit exit_rc_map_powercolor_real_angel(void)
73{ 73{
74 ir_unregister_map(&powercolor_real_angel_map); 74 rc_map_unregister(&powercolor_real_angel_map);
75} 75}
76 76
77module_init(init_rc_map_powercolor_real_angel) 77module_init(init_rc_map_powercolor_real_angel)
diff --git a/drivers/media/IR/keymaps/rc-proteus-2309.c b/drivers/media/rc/keymaps/rc-proteus-2309.c
index 22e92d39dee5..8a3a643879d4 100644
--- a/drivers/media/IR/keymaps/rc-proteus-2309.c
+++ b/drivers/media/rc/keymaps/rc-proteus-2309.c
@@ -14,7 +14,7 @@
14 14
15/* Michal Majchrowicz <mmajchrowicz@gmail.com> */ 15/* Michal Majchrowicz <mmajchrowicz@gmail.com> */
16 16
17static struct ir_scancode proteus_2309[] = { 17static struct rc_map_table proteus_2309[] = {
18 /* numeric */ 18 /* numeric */
19 { 0x00, KEY_0 }, 19 { 0x00, KEY_0 },
20 { 0x01, KEY_1 }, 20 { 0x01, KEY_1 },
@@ -43,23 +43,23 @@ static struct ir_scancode proteus_2309[] = {
43 { 0x14, KEY_F1 }, 43 { 0x14, KEY_F1 },
44}; 44};
45 45
46static struct rc_keymap proteus_2309_map = { 46static struct rc_map_list proteus_2309_map = {
47 .map = { 47 .map = {
48 .scan = proteus_2309, 48 .scan = proteus_2309,
49 .size = ARRAY_SIZE(proteus_2309), 49 .size = ARRAY_SIZE(proteus_2309),
50 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 50 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
51 .name = RC_MAP_PROTEUS_2309, 51 .name = RC_MAP_PROTEUS_2309,
52 } 52 }
53}; 53};
54 54
55static int __init init_rc_map_proteus_2309(void) 55static int __init init_rc_map_proteus_2309(void)
56{ 56{
57 return ir_register_map(&proteus_2309_map); 57 return rc_map_register(&proteus_2309_map);
58} 58}
59 59
60static void __exit exit_rc_map_proteus_2309(void) 60static void __exit exit_rc_map_proteus_2309(void)
61{ 61{
62 ir_unregister_map(&proteus_2309_map); 62 rc_map_unregister(&proteus_2309_map);
63} 63}
64 64
65module_init(init_rc_map_proteus_2309) 65module_init(init_rc_map_proteus_2309)
diff --git a/drivers/media/IR/keymaps/rc-purpletv.c b/drivers/media/rc/keymaps/rc-purpletv.c
index 4e20fc2269f7..ef90296bfd68 100644
--- a/drivers/media/IR/keymaps/rc-purpletv.c
+++ b/drivers/media/rc/keymaps/rc-purpletv.c
@@ -12,7 +12,7 @@
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14 14
15static struct ir_scancode purpletv[] = { 15static struct rc_map_table purpletv[] = {
16 { 0x03, KEY_POWER }, 16 { 0x03, KEY_POWER },
17 { 0x6f, KEY_MUTE }, 17 { 0x6f, KEY_MUTE },
18 { 0x10, KEY_BACKSPACE }, /* Recall */ 18 { 0x10, KEY_BACKSPACE }, /* Recall */
@@ -55,23 +55,23 @@ static struct ir_scancode purpletv[] = {
55 55
56}; 56};
57 57
58static struct rc_keymap purpletv_map = { 58static struct rc_map_list purpletv_map = {
59 .map = { 59 .map = {
60 .scan = purpletv, 60 .scan = purpletv,
61 .size = ARRAY_SIZE(purpletv), 61 .size = ARRAY_SIZE(purpletv),
62 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 62 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
63 .name = RC_MAP_PURPLETV, 63 .name = RC_MAP_PURPLETV,
64 } 64 }
65}; 65};
66 66
67static int __init init_rc_map_purpletv(void) 67static int __init init_rc_map_purpletv(void)
68{ 68{
69 return ir_register_map(&purpletv_map); 69 return rc_map_register(&purpletv_map);
70} 70}
71 71
72static void __exit exit_rc_map_purpletv(void) 72static void __exit exit_rc_map_purpletv(void)
73{ 73{
74 ir_unregister_map(&purpletv_map); 74 rc_map_unregister(&purpletv_map);
75} 75}
76 76
77module_init(init_rc_map_purpletv) 77module_init(init_rc_map_purpletv)
diff --git a/drivers/media/IR/keymaps/rc-pv951.c b/drivers/media/rc/keymaps/rc-pv951.c
index 36679e706cf3..83a418de12c6 100644
--- a/drivers/media/IR/keymaps/rc-pv951.c
+++ b/drivers/media/rc/keymaps/rc-pv951.c
@@ -14,7 +14,7 @@
14 14
15/* Mark Phalan <phalanm@o2.ie> */ 15/* Mark Phalan <phalanm@o2.ie> */
16 16
17static struct ir_scancode pv951[] = { 17static struct rc_map_table pv951[] = {
18 { 0x00, KEY_0 }, 18 { 0x00, KEY_0 },
19 { 0x01, KEY_1 }, 19 { 0x01, KEY_1 },
20 { 0x02, KEY_2 }, 20 { 0x02, KEY_2 },
@@ -52,23 +52,23 @@ static struct ir_scancode pv951[] = {
52 { 0x1c, KEY_MEDIA }, /* PC/TV */ 52 { 0x1c, KEY_MEDIA }, /* PC/TV */
53}; 53};
54 54
55static struct rc_keymap pv951_map = { 55static struct rc_map_list pv951_map = {
56 .map = { 56 .map = {
57 .scan = pv951, 57 .scan = pv951,
58 .size = ARRAY_SIZE(pv951), 58 .size = ARRAY_SIZE(pv951),
59 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 59 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
60 .name = RC_MAP_PV951, 60 .name = RC_MAP_PV951,
61 } 61 }
62}; 62};
63 63
64static int __init init_rc_map_pv951(void) 64static int __init init_rc_map_pv951(void)
65{ 65{
66 return ir_register_map(&pv951_map); 66 return rc_map_register(&pv951_map);
67} 67}
68 68
69static void __exit exit_rc_map_pv951(void) 69static void __exit exit_rc_map_pv951(void)
70{ 70{
71 ir_unregister_map(&pv951_map); 71 rc_map_unregister(&pv951_map);
72} 72}
73 73
74module_init(init_rc_map_pv951) 74module_init(init_rc_map_pv951)
diff --git a/drivers/media/IR/keymaps/rc-rc5-hauppauge-new.c b/drivers/media/rc/keymaps/rc-rc5-hauppauge-new.c
index cc6b8f548747..dfc9b15f43a9 100644
--- a/drivers/media/IR/keymaps/rc-rc5-hauppauge-new.c
+++ b/drivers/media/rc/keymaps/rc-rc5-hauppauge-new.c
@@ -19,7 +19,7 @@
19 * This table contains the complete RC5 code, instead of just the data part 19 * This table contains the complete RC5 code, instead of just the data part
20 */ 20 */
21 21
22static struct ir_scancode rc5_hauppauge_new[] = { 22static struct rc_map_table rc5_hauppauge_new[] = {
23 /* Keys 0 to 9 */ 23 /* Keys 0 to 9 */
24 { 0x1e00, KEY_0 }, 24 { 0x1e00, KEY_0 },
25 { 0x1e01, KEY_1 }, 25 { 0x1e01, KEY_1 },
@@ -75,25 +75,63 @@ static struct ir_scancode rc5_hauppauge_new[] = {
75 { 0x1e3b, KEY_SELECT }, /* top right button */ 75 { 0x1e3b, KEY_SELECT }, /* top right button */
76 { 0x1e3c, KEY_ZOOM }, /* full */ 76 { 0x1e3c, KEY_ZOOM }, /* full */
77 { 0x1e3d, KEY_POWER }, /* system power (green button) */ 77 { 0x1e3d, KEY_POWER }, /* system power (green button) */
78
79 /* Keycodes for DSR-0112 remote bundled with Haupauge MiniStick */
80 { 0x1d00, KEY_0 },
81 { 0x1d01, KEY_1 },
82 { 0x1d02, KEY_2 },
83 { 0x1d03, KEY_3 },
84 { 0x1d04, KEY_4 },
85 { 0x1d05, KEY_5 },
86 { 0x1d06, KEY_6 },
87 { 0x1d07, KEY_7 },
88 { 0x1d08, KEY_8 },
89 { 0x1d09, KEY_9 },
90 { 0x1d0a, KEY_TEXT },
91 { 0x1d0d, KEY_MENU },
92 { 0x1d0f, KEY_MUTE },
93 { 0x1d10, KEY_VOLUMEUP },
94 { 0x1d11, KEY_VOLUMEDOWN },
95 { 0x1d12, KEY_PREVIOUS }, /* Prev.Ch .. ??? */
96 { 0x1d14, KEY_UP },
97 { 0x1d15, KEY_DOWN },
98 { 0x1d16, KEY_LEFT },
99 { 0x1d17, KEY_RIGHT },
100 { 0x1d1c, KEY_TV },
101 { 0x1d1e, KEY_NEXT }, /* >| */
102 { 0x1d1f, KEY_EXIT },
103 { 0x1d20, KEY_CHANNELUP },
104 { 0x1d21, KEY_CHANNELDOWN },
105 { 0x1d24, KEY_LAST }, /* <| */
106 { 0x1d25, KEY_OK },
107 { 0x1d30, KEY_PAUSE },
108 { 0x1d32, KEY_REWIND },
109 { 0x1d34, KEY_FASTFORWARD },
110 { 0x1d35, KEY_PLAY },
111 { 0x1d36, KEY_STOP },
112 { 0x1d37, KEY_RECORD },
113 { 0x1d3b, KEY_GOTO },
114 { 0x1d3d, KEY_POWER },
115 { 0x1d3f, KEY_HOME },
78}; 116};
79 117
80static struct rc_keymap rc5_hauppauge_new_map = { 118static struct rc_map_list rc5_hauppauge_new_map = {
81 .map = { 119 .map = {
82 .scan = rc5_hauppauge_new, 120 .scan = rc5_hauppauge_new,
83 .size = ARRAY_SIZE(rc5_hauppauge_new), 121 .size = ARRAY_SIZE(rc5_hauppauge_new),
84 .ir_type = IR_TYPE_RC5, 122 .rc_type = RC_TYPE_RC5,
85 .name = RC_MAP_RC5_HAUPPAUGE_NEW, 123 .name = RC_MAP_RC5_HAUPPAUGE_NEW,
86 } 124 }
87}; 125};
88 126
89static int __init init_rc_map_rc5_hauppauge_new(void) 127static int __init init_rc_map_rc5_hauppauge_new(void)
90{ 128{
91 return ir_register_map(&rc5_hauppauge_new_map); 129 return rc_map_register(&rc5_hauppauge_new_map);
92} 130}
93 131
94static void __exit exit_rc_map_rc5_hauppauge_new(void) 132static void __exit exit_rc_map_rc5_hauppauge_new(void)
95{ 133{
96 ir_unregister_map(&rc5_hauppauge_new_map); 134 rc_map_unregister(&rc5_hauppauge_new_map);
97} 135}
98 136
99module_init(init_rc_map_rc5_hauppauge_new) 137module_init(init_rc_map_rc5_hauppauge_new)
diff --git a/drivers/media/IR/keymaps/rc-rc5-tv.c b/drivers/media/rc/keymaps/rc-rc5-tv.c
index 73cce2f8ddfb..4fcef9f1f721 100644
--- a/drivers/media/IR/keymaps/rc-rc5-tv.c
+++ b/drivers/media/rc/keymaps/rc-rc5-tv.c
@@ -16,7 +16,7 @@
16/* see http://users.pandora.be/nenya/electronics/rc5/codes00.htm */ 16/* see http://users.pandora.be/nenya/electronics/rc5/codes00.htm */
17/* used by old (black) Hauppauge remotes */ 17/* used by old (black) Hauppauge remotes */
18 18
19static struct ir_scancode rc5_tv[] = { 19static struct rc_map_table rc5_tv[] = {
20 /* Keys 0 to 9 */ 20 /* Keys 0 to 9 */
21 { 0x00, KEY_0 }, 21 { 0x00, KEY_0 },
22 { 0x01, KEY_1 }, 22 { 0x01, KEY_1 },
@@ -55,23 +55,23 @@ static struct ir_scancode rc5_tv[] = {
55 55
56}; 56};
57 57
58static struct rc_keymap rc5_tv_map = { 58static struct rc_map_list rc5_tv_map = {
59 .map = { 59 .map = {
60 .scan = rc5_tv, 60 .scan = rc5_tv,
61 .size = ARRAY_SIZE(rc5_tv), 61 .size = ARRAY_SIZE(rc5_tv),
62 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 62 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
63 .name = RC_MAP_RC5_TV, 63 .name = RC_MAP_RC5_TV,
64 } 64 }
65}; 65};
66 66
67static int __init init_rc_map_rc5_tv(void) 67static int __init init_rc_map_rc5_tv(void)
68{ 68{
69 return ir_register_map(&rc5_tv_map); 69 return rc_map_register(&rc5_tv_map);
70} 70}
71 71
72static void __exit exit_rc_map_rc5_tv(void) 72static void __exit exit_rc_map_rc5_tv(void)
73{ 73{
74 ir_unregister_map(&rc5_tv_map); 74 rc_map_unregister(&rc5_tv_map);
75} 75}
76 76
77module_init(init_rc_map_rc5_tv) 77module_init(init_rc_map_rc5_tv)
diff --git a/drivers/media/IR/keymaps/rc-rc6-mce.c b/drivers/media/rc/keymaps/rc-rc6-mce.c
index 6da955dfef48..3bf3337875d1 100644
--- a/drivers/media/IR/keymaps/rc-rc6-mce.c
+++ b/drivers/media/rc/keymaps/rc-rc6-mce.c
@@ -11,7 +11,7 @@
11 11
12#include <media/rc-map.h> 12#include <media/rc-map.h>
13 13
14static struct ir_scancode rc6_mce[] = { 14static struct rc_map_table rc6_mce[] = {
15 15
16 { 0x800f0400, KEY_NUMERIC_0 }, 16 { 0x800f0400, KEY_NUMERIC_0 },
17 { 0x800f0401, KEY_NUMERIC_1 }, 17 { 0x800f0401, KEY_NUMERIC_1 },
@@ -87,23 +87,23 @@ static struct ir_scancode rc6_mce[] = {
87 { 0x800f0481, KEY_PLAYPAUSE }, 87 { 0x800f0481, KEY_PLAYPAUSE },
88}; 88};
89 89
90static struct rc_keymap rc6_mce_map = { 90static struct rc_map_list rc6_mce_map = {
91 .map = { 91 .map = {
92 .scan = rc6_mce, 92 .scan = rc6_mce,
93 .size = ARRAY_SIZE(rc6_mce), 93 .size = ARRAY_SIZE(rc6_mce),
94 .ir_type = IR_TYPE_RC6, 94 .rc_type = RC_TYPE_RC6,
95 .name = RC_MAP_RC6_MCE, 95 .name = RC_MAP_RC6_MCE,
96 } 96 }
97}; 97};
98 98
99static int __init init_rc_map_rc6_mce(void) 99static int __init init_rc_map_rc6_mce(void)
100{ 100{
101 return ir_register_map(&rc6_mce_map); 101 return rc_map_register(&rc6_mce_map);
102} 102}
103 103
104static void __exit exit_rc_map_rc6_mce(void) 104static void __exit exit_rc_map_rc6_mce(void)
105{ 105{
106 ir_unregister_map(&rc6_mce_map); 106 rc_map_unregister(&rc6_mce_map);
107} 107}
108 108
109module_init(init_rc_map_rc6_mce) 109module_init(init_rc_map_rc6_mce)
diff --git a/drivers/media/IR/keymaps/rc-real-audio-220-32-keys.c b/drivers/media/rc/keymaps/rc-real-audio-220-32-keys.c
index ab1a6d2baf72..2d14598592d8 100644
--- a/drivers/media/IR/keymaps/rc-real-audio-220-32-keys.c
+++ b/drivers/media/rc/keymaps/rc-real-audio-220-32-keys.c
@@ -14,7 +14,7 @@
14 14
15/* Zogis Real Audio 220 - 32 keys IR */ 15/* Zogis Real Audio 220 - 32 keys IR */
16 16
17static struct ir_scancode real_audio_220_32_keys[] = { 17static struct rc_map_table real_audio_220_32_keys[] = {
18 { 0x1c, KEY_RADIO}, 18 { 0x1c, KEY_RADIO},
19 { 0x12, KEY_POWER2}, 19 { 0x12, KEY_POWER2},
20 20
@@ -52,23 +52,23 @@ static struct ir_scancode real_audio_220_32_keys[] = {
52 52
53}; 53};
54 54
55static struct rc_keymap real_audio_220_32_keys_map = { 55static struct rc_map_list real_audio_220_32_keys_map = {
56 .map = { 56 .map = {
57 .scan = real_audio_220_32_keys, 57 .scan = real_audio_220_32_keys,
58 .size = ARRAY_SIZE(real_audio_220_32_keys), 58 .size = ARRAY_SIZE(real_audio_220_32_keys),
59 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 59 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
60 .name = RC_MAP_REAL_AUDIO_220_32_KEYS, 60 .name = RC_MAP_REAL_AUDIO_220_32_KEYS,
61 } 61 }
62}; 62};
63 63
64static int __init init_rc_map_real_audio_220_32_keys(void) 64static int __init init_rc_map_real_audio_220_32_keys(void)
65{ 65{
66 return ir_register_map(&real_audio_220_32_keys_map); 66 return rc_map_register(&real_audio_220_32_keys_map);
67} 67}
68 68
69static void __exit exit_rc_map_real_audio_220_32_keys(void) 69static void __exit exit_rc_map_real_audio_220_32_keys(void)
70{ 70{
71 ir_unregister_map(&real_audio_220_32_keys_map); 71 rc_map_unregister(&real_audio_220_32_keys_map);
72} 72}
73 73
74module_init(init_rc_map_real_audio_220_32_keys) 74module_init(init_rc_map_real_audio_220_32_keys)
diff --git a/drivers/media/IR/keymaps/rc-streamzap.c b/drivers/media/rc/keymaps/rc-streamzap.c
index df32013a321c..92cc10d2f9cd 100644
--- a/drivers/media/IR/keymaps/rc-streamzap.c
+++ b/drivers/media/rc/keymaps/rc-streamzap.c
@@ -11,7 +11,7 @@
11 11
12#include <media/rc-map.h> 12#include <media/rc-map.h>
13 13
14static struct ir_scancode streamzap[] = { 14static struct rc_map_table streamzap[] = {
15/* 15/*
16 * The Streamzap remote is almost, but not quite, RC-5, as it has an extra 16 * The Streamzap remote is almost, but not quite, RC-5, as it has an extra
17 * bit in it, which throws the in-kernel RC-5 decoder for a loop. Currently, 17 * bit in it, which throws the in-kernel RC-5 decoder for a loop. Currently,
@@ -56,23 +56,23 @@ static struct ir_scancode streamzap[] = {
56 56
57}; 57};
58 58
59static struct rc_keymap streamzap_map = { 59static struct rc_map_list streamzap_map = {
60 .map = { 60 .map = {
61 .scan = streamzap, 61 .scan = streamzap,
62 .size = ARRAY_SIZE(streamzap), 62 .size = ARRAY_SIZE(streamzap),
63 .ir_type = IR_TYPE_RC5_SZ, 63 .rc_type = RC_TYPE_RC5_SZ,
64 .name = RC_MAP_STREAMZAP, 64 .name = RC_MAP_STREAMZAP,
65 } 65 }
66}; 66};
67 67
68static int __init init_rc_map_streamzap(void) 68static int __init init_rc_map_streamzap(void)
69{ 69{
70 return ir_register_map(&streamzap_map); 70 return rc_map_register(&streamzap_map);
71} 71}
72 72
73static void __exit exit_rc_map_streamzap(void) 73static void __exit exit_rc_map_streamzap(void)
74{ 74{
75 ir_unregister_map(&streamzap_map); 75 rc_map_unregister(&streamzap_map);
76} 76}
77 77
78module_init(init_rc_map_streamzap) 78module_init(init_rc_map_streamzap)
diff --git a/drivers/media/rc/keymaps/rc-tbs-nec.c b/drivers/media/rc/keymaps/rc-tbs-nec.c
new file mode 100644
index 000000000000..7242ee66f6e0
--- /dev/null
+++ b/drivers/media/rc/keymaps/rc-tbs-nec.c
@@ -0,0 +1,75 @@
1/* tbs-nec.h - Keytable for tbs_nec Remote Controller
2 *
3 * keymap imported from ir-keymaps.c
4 *
5 * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
12
13#include <media/rc-map.h>
14
15static struct rc_map_table tbs_nec[] = {
16 { 0x84, KEY_POWER2}, /* power */
17 { 0x94, KEY_MUTE}, /* mute */
18 { 0x87, KEY_1},
19 { 0x86, KEY_2},
20 { 0x85, KEY_3},
21 { 0x8b, KEY_4},
22 { 0x8a, KEY_5},
23 { 0x89, KEY_6},
24 { 0x8f, KEY_7},
25 { 0x8e, KEY_8},
26 { 0x8d, KEY_9},
27 { 0x92, KEY_0},
28 { 0xc0, KEY_10CHANNELSUP}, /* 10+ */
29 { 0xd0, KEY_10CHANNELSDOWN}, /* 10- */
30 { 0x96, KEY_CHANNELUP}, /* ch+ */
31 { 0x91, KEY_CHANNELDOWN}, /* ch- */
32 { 0x93, KEY_VOLUMEUP}, /* vol+ */
33 { 0x8c, KEY_VOLUMEDOWN}, /* vol- */
34 { 0x83, KEY_RECORD}, /* rec */
35 { 0x98, KEY_PAUSE}, /* pause, yellow */
36 { 0x99, KEY_OK}, /* ok */
37 { 0x9a, KEY_CAMERA}, /* snapshot */
38 { 0x81, KEY_UP},
39 { 0x90, KEY_LEFT},
40 { 0x82, KEY_RIGHT},
41 { 0x88, KEY_DOWN},
42 { 0x95, KEY_FAVORITES}, /* blue */
43 { 0x97, KEY_SUBTITLE}, /* green */
44 { 0x9d, KEY_ZOOM},
45 { 0x9f, KEY_EXIT},
46 { 0x9e, KEY_MENU},
47 { 0x9c, KEY_EPG},
48 { 0x80, KEY_PREVIOUS}, /* red */
49 { 0x9b, KEY_MODE},
50};
51
52static struct rc_map_list tbs_nec_map = {
53 .map = {
54 .scan = tbs_nec,
55 .size = ARRAY_SIZE(tbs_nec),
56 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
57 .name = RC_MAP_TBS_NEC,
58 }
59};
60
61static int __init init_rc_map_tbs_nec(void)
62{
63 return rc_map_register(&tbs_nec_map);
64}
65
66static void __exit exit_rc_map_tbs_nec(void)
67{
68 rc_map_unregister(&tbs_nec_map);
69}
70
71module_init(init_rc_map_tbs_nec)
72module_exit(exit_rc_map_tbs_nec)
73
74MODULE_LICENSE("GPL");
75MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-terratec-cinergy-xs.c b/drivers/media/rc/keymaps/rc-terratec-cinergy-xs.c
index 5326a0b444c1..bc38e34b9fda 100644
--- a/drivers/media/IR/keymaps/rc-terratec-cinergy-xs.c
+++ b/drivers/media/rc/keymaps/rc-terratec-cinergy-xs.c
@@ -16,7 +16,7 @@
16 Devin Heitmueller <dheitmueller@linuxtv.org> 16 Devin Heitmueller <dheitmueller@linuxtv.org>
17 */ 17 */
18 18
19static struct ir_scancode terratec_cinergy_xs[] = { 19static struct rc_map_table terratec_cinergy_xs[] = {
20 { 0x41, KEY_HOME}, 20 { 0x41, KEY_HOME},
21 { 0x01, KEY_POWER}, 21 { 0x01, KEY_POWER},
22 { 0x42, KEY_MENU}, 22 { 0x42, KEY_MENU},
@@ -66,23 +66,23 @@ static struct ir_scancode terratec_cinergy_xs[] = {
66 { 0x5c, KEY_NEXT}, 66 { 0x5c, KEY_NEXT},
67}; 67};
68 68
69static struct rc_keymap terratec_cinergy_xs_map = { 69static struct rc_map_list terratec_cinergy_xs_map = {
70 .map = { 70 .map = {
71 .scan = terratec_cinergy_xs, 71 .scan = terratec_cinergy_xs,
72 .size = ARRAY_SIZE(terratec_cinergy_xs), 72 .size = ARRAY_SIZE(terratec_cinergy_xs),
73 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 73 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
74 .name = RC_MAP_TERRATEC_CINERGY_XS, 74 .name = RC_MAP_TERRATEC_CINERGY_XS,
75 } 75 }
76}; 76};
77 77
78static int __init init_rc_map_terratec_cinergy_xs(void) 78static int __init init_rc_map_terratec_cinergy_xs(void)
79{ 79{
80 return ir_register_map(&terratec_cinergy_xs_map); 80 return rc_map_register(&terratec_cinergy_xs_map);
81} 81}
82 82
83static void __exit exit_rc_map_terratec_cinergy_xs(void) 83static void __exit exit_rc_map_terratec_cinergy_xs(void)
84{ 84{
85 ir_unregister_map(&terratec_cinergy_xs_map); 85 rc_map_unregister(&terratec_cinergy_xs_map);
86} 86}
87 87
88module_init(init_rc_map_terratec_cinergy_xs) 88module_init(init_rc_map_terratec_cinergy_xs)
diff --git a/drivers/media/IR/keymaps/rc-terratec-slim.c b/drivers/media/rc/keymaps/rc-terratec-slim.c
index 10dee4c1deff..1abafa5fd303 100644
--- a/drivers/media/IR/keymaps/rc-terratec-slim.c
+++ b/drivers/media/rc/keymaps/rc-terratec-slim.c
@@ -22,7 +22,7 @@
22 22
23/* TerraTec slim remote, 7 rows, 4 columns. */ 23/* TerraTec slim remote, 7 rows, 4 columns. */
24/* Uses NEC extended 0x02bd. */ 24/* Uses NEC extended 0x02bd. */
25static struct ir_scancode terratec_slim[] = { 25static struct rc_map_table terratec_slim[] = {
26 { 0x02bd00, KEY_1 }, 26 { 0x02bd00, KEY_1 },
27 { 0x02bd01, KEY_2 }, 27 { 0x02bd01, KEY_2 },
28 { 0x02bd02, KEY_3 }, 28 { 0x02bd02, KEY_3 },
@@ -53,23 +53,23 @@ static struct ir_scancode terratec_slim[] = {
53 { 0x02bd45, KEY_POWER2 }, /* [red power button] */ 53 { 0x02bd45, KEY_POWER2 }, /* [red power button] */
54}; 54};
55 55
56static struct rc_keymap terratec_slim_map = { 56static struct rc_map_list terratec_slim_map = {
57 .map = { 57 .map = {
58 .scan = terratec_slim, 58 .scan = terratec_slim,
59 .size = ARRAY_SIZE(terratec_slim), 59 .size = ARRAY_SIZE(terratec_slim),
60 .ir_type = IR_TYPE_NEC, 60 .rc_type = RC_TYPE_NEC,
61 .name = RC_MAP_TERRATEC_SLIM, 61 .name = RC_MAP_TERRATEC_SLIM,
62 } 62 }
63}; 63};
64 64
65static int __init init_rc_map_terratec_slim(void) 65static int __init init_rc_map_terratec_slim(void)
66{ 66{
67 return ir_register_map(&terratec_slim_map); 67 return rc_map_register(&terratec_slim_map);
68} 68}
69 69
70static void __exit exit_rc_map_terratec_slim(void) 70static void __exit exit_rc_map_terratec_slim(void)
71{ 71{
72 ir_unregister_map(&terratec_slim_map); 72 rc_map_unregister(&terratec_slim_map);
73} 73}
74 74
75module_init(init_rc_map_terratec_slim) 75module_init(init_rc_map_terratec_slim)
diff --git a/drivers/media/IR/keymaps/rc-tevii-nec.c b/drivers/media/rc/keymaps/rc-tevii-nec.c
index e30d411c07bb..ef5ba3f32735 100644
--- a/drivers/media/IR/keymaps/rc-tevii-nec.c
+++ b/drivers/media/rc/keymaps/rc-tevii-nec.c
@@ -12,7 +12,7 @@
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14 14
15static struct ir_scancode tevii_nec[] = { 15static struct rc_map_table tevii_nec[] = {
16 { 0x0a, KEY_POWER2}, 16 { 0x0a, KEY_POWER2},
17 { 0x0c, KEY_MUTE}, 17 { 0x0c, KEY_MUTE},
18 { 0x11, KEY_1}, 18 { 0x11, KEY_1},
@@ -62,23 +62,23 @@ static struct ir_scancode tevii_nec[] = {
62 { 0x58, KEY_SWITCHVIDEOMODE}, 62 { 0x58, KEY_SWITCHVIDEOMODE},
63}; 63};
64 64
65static struct rc_keymap tevii_nec_map = { 65static struct rc_map_list tevii_nec_map = {
66 .map = { 66 .map = {
67 .scan = tevii_nec, 67 .scan = tevii_nec,
68 .size = ARRAY_SIZE(tevii_nec), 68 .size = ARRAY_SIZE(tevii_nec),
69 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 69 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
70 .name = RC_MAP_TEVII_NEC, 70 .name = RC_MAP_TEVII_NEC,
71 } 71 }
72}; 72};
73 73
74static int __init init_rc_map_tevii_nec(void) 74static int __init init_rc_map_tevii_nec(void)
75{ 75{
76 return ir_register_map(&tevii_nec_map); 76 return rc_map_register(&tevii_nec_map);
77} 77}
78 78
79static void __exit exit_rc_map_tevii_nec(void) 79static void __exit exit_rc_map_tevii_nec(void)
80{ 80{
81 ir_unregister_map(&tevii_nec_map); 81 rc_map_unregister(&tevii_nec_map);
82} 82}
83 83
84module_init(init_rc_map_tevii_nec) 84module_init(init_rc_map_tevii_nec)
diff --git a/drivers/media/IR/keymaps/rc-total-media-in-hand.c b/drivers/media/rc/keymaps/rc-total-media-in-hand.c
index fd1985763781..20ac4e19fb3f 100644
--- a/drivers/media/IR/keymaps/rc-total-media-in-hand.c
+++ b/drivers/media/rc/keymaps/rc-total-media-in-hand.c
@@ -21,7 +21,7 @@
21#include <media/rc-map.h> 21#include <media/rc-map.h>
22 22
23/* Uses NEC extended 0x02bd */ 23/* Uses NEC extended 0x02bd */
24static struct ir_scancode total_media_in_hand[] = { 24static struct rc_map_table total_media_in_hand[] = {
25 { 0x02bd00, KEY_1 }, 25 { 0x02bd00, KEY_1 },
26 { 0x02bd01, KEY_2 }, 26 { 0x02bd01, KEY_2 },
27 { 0x02bd02, KEY_3 }, 27 { 0x02bd02, KEY_3 },
@@ -59,23 +59,23 @@ static struct ir_scancode total_media_in_hand[] = {
59 { 0x02bd45, KEY_INFO }, /* [red (I)] */ 59 { 0x02bd45, KEY_INFO }, /* [red (I)] */
60}; 60};
61 61
62static struct rc_keymap total_media_in_hand_map = { 62static struct rc_map_list total_media_in_hand_map = {
63 .map = { 63 .map = {
64 .scan = total_media_in_hand, 64 .scan = total_media_in_hand,
65 .size = ARRAY_SIZE(total_media_in_hand), 65 .size = ARRAY_SIZE(total_media_in_hand),
66 .ir_type = IR_TYPE_NEC, 66 .rc_type = RC_TYPE_NEC,
67 .name = RC_MAP_TOTAL_MEDIA_IN_HAND, 67 .name = RC_MAP_TOTAL_MEDIA_IN_HAND,
68 } 68 }
69}; 69};
70 70
71static int __init init_rc_map_total_media_in_hand(void) 71static int __init init_rc_map_total_media_in_hand(void)
72{ 72{
73 return ir_register_map(&total_media_in_hand_map); 73 return rc_map_register(&total_media_in_hand_map);
74} 74}
75 75
76static void __exit exit_rc_map_total_media_in_hand(void) 76static void __exit exit_rc_map_total_media_in_hand(void)
77{ 77{
78 ir_unregister_map(&total_media_in_hand_map); 78 rc_map_unregister(&total_media_in_hand_map);
79} 79}
80 80
81module_init(init_rc_map_total_media_in_hand) 81module_init(init_rc_map_total_media_in_hand)
diff --git a/drivers/media/IR/keymaps/rc-trekstor.c b/drivers/media/rc/keymaps/rc-trekstor.c
index 91092caca452..f8190ead2e32 100644
--- a/drivers/media/IR/keymaps/rc-trekstor.c
+++ b/drivers/media/rc/keymaps/rc-trekstor.c
@@ -23,7 +23,7 @@
23/* TrekStor DVB-T USB Stick remote controller. */ 23/* TrekStor DVB-T USB Stick remote controller. */
24/* Imported from af9015.h. 24/* Imported from af9015.h.
25 Initial keytable was from Marc Schneider <macke@macke.org> */ 25 Initial keytable was from Marc Schneider <macke@macke.org> */
26static struct ir_scancode trekstor[] = { 26static struct rc_map_table trekstor[] = {
27 { 0x0084, KEY_0 }, 27 { 0x0084, KEY_0 },
28 { 0x0085, KEY_MUTE }, /* Mute */ 28 { 0x0085, KEY_MUTE }, /* Mute */
29 { 0x0086, KEY_HOMEPAGE }, /* Home */ 29 { 0x0086, KEY_HOMEPAGE }, /* Home */
@@ -54,23 +54,23 @@ static struct ir_scancode trekstor[] = {
54 { 0x009f, KEY_LEFT }, /* Left */ 54 { 0x009f, KEY_LEFT }, /* Left */
55}; 55};
56 56
57static struct rc_keymap trekstor_map = { 57static struct rc_map_list trekstor_map = {
58 .map = { 58 .map = {
59 .scan = trekstor, 59 .scan = trekstor,
60 .size = ARRAY_SIZE(trekstor), 60 .size = ARRAY_SIZE(trekstor),
61 .ir_type = IR_TYPE_NEC, 61 .rc_type = RC_TYPE_NEC,
62 .name = RC_MAP_TREKSTOR, 62 .name = RC_MAP_TREKSTOR,
63 } 63 }
64}; 64};
65 65
66static int __init init_rc_map_trekstor(void) 66static int __init init_rc_map_trekstor(void)
67{ 67{
68 return ir_register_map(&trekstor_map); 68 return rc_map_register(&trekstor_map);
69} 69}
70 70
71static void __exit exit_rc_map_trekstor(void) 71static void __exit exit_rc_map_trekstor(void)
72{ 72{
73 ir_unregister_map(&trekstor_map); 73 rc_map_unregister(&trekstor_map);
74} 74}
75 75
76module_init(init_rc_map_trekstor) 76module_init(init_rc_map_trekstor)
diff --git a/drivers/media/rc/keymaps/rc-tt-1500.c b/drivers/media/rc/keymaps/rc-tt-1500.c
new file mode 100644
index 000000000000..295f3738e301
--- /dev/null
+++ b/drivers/media/rc/keymaps/rc-tt-1500.c
@@ -0,0 +1,82 @@
1/* tt-1500.h - Keytable for tt_1500 Remote Controller
2 *
3 * keymap imported from ir-keymaps.c
4 *
5 * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
12
13#include <media/rc-map.h>
14
15/* for the Technotrend 1500 bundled remotes (grey and black): */
16
17static struct rc_map_table tt_1500[] = {
18 { 0x1501, KEY_POWER },
19 { 0x1502, KEY_SHUFFLE }, /* ? double-arrow key */
20 { 0x1503, KEY_1 },
21 { 0x1504, KEY_2 },
22 { 0x1505, KEY_3 },
23 { 0x1506, KEY_4 },
24 { 0x1507, KEY_5 },
25 { 0x1508, KEY_6 },
26 { 0x1509, KEY_7 },
27 { 0x150a, KEY_8 },
28 { 0x150b, KEY_9 },
29 { 0x150c, KEY_0 },
30 { 0x150d, KEY_UP },
31 { 0x150e, KEY_LEFT },
32 { 0x150f, KEY_OK },
33 { 0x1510, KEY_RIGHT },
34 { 0x1511, KEY_DOWN },
35 { 0x1512, KEY_INFO },
36 { 0x1513, KEY_EXIT },
37 { 0x1514, KEY_RED },
38 { 0x1515, KEY_GREEN },
39 { 0x1516, KEY_YELLOW },
40 { 0x1517, KEY_BLUE },
41 { 0x1518, KEY_MUTE },
42 { 0x1519, KEY_TEXT },
43 { 0x151a, KEY_MODE }, /* ? TV/Radio */
44 { 0x1521, KEY_OPTION },
45 { 0x1522, KEY_EPG },
46 { 0x1523, KEY_CHANNELUP },
47 { 0x1524, KEY_CHANNELDOWN },
48 { 0x1525, KEY_VOLUMEUP },
49 { 0x1526, KEY_VOLUMEDOWN },
50 { 0x1527, KEY_SETUP },
51 { 0x153a, KEY_RECORD }, /* these keys are only in the black remote */
52 { 0x153b, KEY_PLAY },
53 { 0x153c, KEY_STOP },
54 { 0x153d, KEY_REWIND },
55 { 0x153e, KEY_PAUSE },
56 { 0x153f, KEY_FORWARD },
57};
58
59static struct rc_map_list tt_1500_map = {
60 .map = {
61 .scan = tt_1500,
62 .size = ARRAY_SIZE(tt_1500),
63 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
64 .name = RC_MAP_TT_1500,
65 }
66};
67
68static int __init init_rc_map_tt_1500(void)
69{
70 return rc_map_register(&tt_1500_map);
71}
72
73static void __exit exit_rc_map_tt_1500(void)
74{
75 rc_map_unregister(&tt_1500_map);
76}
77
78module_init(init_rc_map_tt_1500)
79module_exit(exit_rc_map_tt_1500)
80
81MODULE_LICENSE("GPL");
82MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-twinhan1027.c b/drivers/media/rc/keymaps/rc-twinhan1027.c
index 0b5d356c2d84..8bf8df64b081 100644
--- a/drivers/media/IR/keymaps/rc-twinhan1027.c
+++ b/drivers/media/rc/keymaps/rc-twinhan1027.c
@@ -1,6 +1,6 @@
1#include <media/rc-map.h> 1#include <media/rc-map.h>
2 2
3static struct ir_scancode twinhan_vp1027[] = { 3static struct rc_map_table twinhan_vp1027[] = {
4 { 0x16, KEY_POWER2 }, 4 { 0x16, KEY_POWER2 },
5 { 0x17, KEY_FAVORITES }, 5 { 0x17, KEY_FAVORITES },
6 { 0x0f, KEY_TEXT }, 6 { 0x0f, KEY_TEXT },
@@ -61,23 +61,23 @@ static struct ir_scancode twinhan_vp1027[] = {
61 { 0x5f, KEY_BLUE }, 61 { 0x5f, KEY_BLUE },
62}; 62};
63 63
64static struct rc_keymap twinhan_vp1027_map = { 64static struct rc_map_list twinhan_vp1027_map = {
65 .map = { 65 .map = {
66 .scan = twinhan_vp1027, 66 .scan = twinhan_vp1027,
67 .size = ARRAY_SIZE(twinhan_vp1027), 67 .size = ARRAY_SIZE(twinhan_vp1027),
68 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 68 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
69 .name = RC_MAP_TWINHAN_VP1027_DVBS, 69 .name = RC_MAP_TWINHAN_VP1027_DVBS,
70 } 70 }
71}; 71};
72 72
73static int __init init_rc_map_twinhan_vp1027(void) 73static int __init init_rc_map_twinhan_vp1027(void)
74{ 74{
75 return ir_register_map(&twinhan_vp1027_map); 75 return rc_map_register(&twinhan_vp1027_map);
76} 76}
77 77
78static void __exit exit_rc_map_twinhan_vp1027(void) 78static void __exit exit_rc_map_twinhan_vp1027(void)
79{ 79{
80 ir_unregister_map(&twinhan_vp1027_map); 80 rc_map_unregister(&twinhan_vp1027_map);
81} 81}
82 82
83module_init(init_rc_map_twinhan_vp1027) 83module_init(init_rc_map_twinhan_vp1027)
diff --git a/drivers/media/rc/keymaps/rc-videomate-m1f.c b/drivers/media/rc/keymaps/rc-videomate-m1f.c
new file mode 100644
index 000000000000..4994d405c0a1
--- /dev/null
+++ b/drivers/media/rc/keymaps/rc-videomate-m1f.c
@@ -0,0 +1,92 @@
1/* videomate-m1f.h - Keytable for videomate_m1f Remote Controller
2 *
3 * keymap imported from ir-keymaps.c
4 *
5 * Copyright (c) 2010 by Pavel Osnova <pvosnova@gmail.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
12
13#include <media/rc-map.h>
14
15static struct rc_map_table videomate_m1f[] = {
16 { 0x01, KEY_POWER },
17 { 0x31, KEY_TUNER },
18 { 0x33, KEY_VIDEO },
19 { 0x2f, KEY_RADIO },
20 { 0x30, KEY_CAMERA },
21 { 0x2d, KEY_NEW }, /* TV record button */
22 { 0x17, KEY_CYCLEWINDOWS },
23 { 0x2c, KEY_ANGLE },
24 { 0x2b, KEY_LANGUAGE },
25 { 0x32, KEY_SEARCH }, /* '...' button */
26 { 0x11, KEY_UP },
27 { 0x13, KEY_LEFT },
28 { 0x15, KEY_OK },
29 { 0x14, KEY_RIGHT },
30 { 0x12, KEY_DOWN },
31 { 0x16, KEY_BACKSPACE },
32 { 0x02, KEY_ZOOM }, /* WIN key */
33 { 0x04, KEY_INFO },
34 { 0x05, KEY_VOLUMEUP },
35 { 0x03, KEY_MUTE },
36 { 0x07, KEY_CHANNELUP },
37 { 0x06, KEY_VOLUMEDOWN },
38 { 0x08, KEY_CHANNELDOWN },
39 { 0x0c, KEY_RECORD },
40 { 0x0e, KEY_STOP },
41 { 0x0a, KEY_BACK },
42 { 0x0b, KEY_PLAY },
43 { 0x09, KEY_FORWARD },
44 { 0x10, KEY_PREVIOUS },
45 { 0x0d, KEY_PAUSE },
46 { 0x0f, KEY_NEXT },
47 { 0x1e, KEY_1 },
48 { 0x1f, KEY_2 },
49 { 0x20, KEY_3 },
50 { 0x21, KEY_4 },
51 { 0x22, KEY_5 },
52 { 0x23, KEY_6 },
53 { 0x24, KEY_7 },
54 { 0x25, KEY_8 },
55 { 0x26, KEY_9 },
56 { 0x2a, KEY_NUMERIC_STAR }, /* * key */
57 { 0x1d, KEY_0 },
58 { 0x29, KEY_SUBTITLE }, /* # key */
59 { 0x27, KEY_CLEAR },
60 { 0x34, KEY_SCREEN },
61 { 0x28, KEY_ENTER },
62 { 0x19, KEY_RED },
63 { 0x1a, KEY_GREEN },
64 { 0x1b, KEY_YELLOW },
65 { 0x1c, KEY_BLUE },
66 { 0x18, KEY_TEXT },
67};
68
69static struct rc_map_list videomate_m1f_map = {
70 .map = {
71 .scan = videomate_m1f,
72 .size = ARRAY_SIZE(videomate_m1f),
73 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
74 .name = RC_MAP_VIDEOMATE_M1F,
75 }
76};
77
78static int __init init_rc_map_videomate_m1f(void)
79{
80 return rc_map_register(&videomate_m1f_map);
81}
82
83static void __exit exit_rc_map_videomate_m1f(void)
84{
85 rc_map_unregister(&videomate_m1f_map);
86}
87
88module_init(init_rc_map_videomate_m1f)
89module_exit(exit_rc_map_videomate_m1f)
90
91MODULE_LICENSE("GPL");
92MODULE_AUTHOR("Pavel Osnova <pvosnova@gmail.com>");
diff --git a/drivers/media/IR/keymaps/rc-videomate-s350.c b/drivers/media/rc/keymaps/rc-videomate-s350.c
index 4df7fcd1d2fc..9e474a6024e5 100644
--- a/drivers/media/IR/keymaps/rc-videomate-s350.c
+++ b/drivers/media/rc/keymaps/rc-videomate-s350.c
@@ -12,7 +12,7 @@
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14 14
15static struct ir_scancode videomate_s350[] = { 15static struct rc_map_table videomate_s350[] = {
16 { 0x00, KEY_TV}, 16 { 0x00, KEY_TV},
17 { 0x01, KEY_DVD}, 17 { 0x01, KEY_DVD},
18 { 0x04, KEY_RECORD}, 18 { 0x04, KEY_RECORD},
@@ -59,23 +59,23 @@ static struct ir_scancode videomate_s350[] = {
59 { 0x20, KEY_TEXT}, 59 { 0x20, KEY_TEXT},
60}; 60};
61 61
62static struct rc_keymap videomate_s350_map = { 62static struct rc_map_list videomate_s350_map = {
63 .map = { 63 .map = {
64 .scan = videomate_s350, 64 .scan = videomate_s350,
65 .size = ARRAY_SIZE(videomate_s350), 65 .size = ARRAY_SIZE(videomate_s350),
66 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 66 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
67 .name = RC_MAP_VIDEOMATE_S350, 67 .name = RC_MAP_VIDEOMATE_S350,
68 } 68 }
69}; 69};
70 70
71static int __init init_rc_map_videomate_s350(void) 71static int __init init_rc_map_videomate_s350(void)
72{ 72{
73 return ir_register_map(&videomate_s350_map); 73 return rc_map_register(&videomate_s350_map);
74} 74}
75 75
76static void __exit exit_rc_map_videomate_s350(void) 76static void __exit exit_rc_map_videomate_s350(void)
77{ 77{
78 ir_unregister_map(&videomate_s350_map); 78 rc_map_unregister(&videomate_s350_map);
79} 79}
80 80
81module_init(init_rc_map_videomate_s350) 81module_init(init_rc_map_videomate_s350)
diff --git a/drivers/media/IR/keymaps/rc-videomate-tv-pvr.c b/drivers/media/rc/keymaps/rc-videomate-tv-pvr.c
index 776b0a638d87..5f2a46e1f8f6 100644
--- a/drivers/media/IR/keymaps/rc-videomate-tv-pvr.c
+++ b/drivers/media/rc/keymaps/rc-videomate-tv-pvr.c
@@ -12,7 +12,7 @@
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14 14
15static struct ir_scancode videomate_tv_pvr[] = { 15static struct rc_map_table videomate_tv_pvr[] = {
16 { 0x14, KEY_MUTE }, 16 { 0x14, KEY_MUTE },
17 { 0x24, KEY_ZOOM }, 17 { 0x24, KEY_ZOOM },
18 18
@@ -61,23 +61,23 @@ static struct ir_scancode videomate_tv_pvr[] = {
61 { 0x21, KEY_SLEEP }, 61 { 0x21, KEY_SLEEP },
62}; 62};
63 63
64static struct rc_keymap videomate_tv_pvr_map = { 64static struct rc_map_list videomate_tv_pvr_map = {
65 .map = { 65 .map = {
66 .scan = videomate_tv_pvr, 66 .scan = videomate_tv_pvr,
67 .size = ARRAY_SIZE(videomate_tv_pvr), 67 .size = ARRAY_SIZE(videomate_tv_pvr),
68 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 68 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
69 .name = RC_MAP_VIDEOMATE_TV_PVR, 69 .name = RC_MAP_VIDEOMATE_TV_PVR,
70 } 70 }
71}; 71};
72 72
73static int __init init_rc_map_videomate_tv_pvr(void) 73static int __init init_rc_map_videomate_tv_pvr(void)
74{ 74{
75 return ir_register_map(&videomate_tv_pvr_map); 75 return rc_map_register(&videomate_tv_pvr_map);
76} 76}
77 77
78static void __exit exit_rc_map_videomate_tv_pvr(void) 78static void __exit exit_rc_map_videomate_tv_pvr(void)
79{ 79{
80 ir_unregister_map(&videomate_tv_pvr_map); 80 rc_map_unregister(&videomate_tv_pvr_map);
81} 81}
82 82
83module_init(init_rc_map_videomate_tv_pvr) 83module_init(init_rc_map_videomate_tv_pvr)
diff --git a/drivers/media/IR/keymaps/rc-winfast-usbii-deluxe.c b/drivers/media/rc/keymaps/rc-winfast-usbii-deluxe.c
index 9d2d550aaa90..bd8d021f40aa 100644
--- a/drivers/media/IR/keymaps/rc-winfast-usbii-deluxe.c
+++ b/drivers/media/rc/keymaps/rc-winfast-usbii-deluxe.c
@@ -16,7 +16,7 @@
16 Magnus Alm <magnus.alm@gmail.com> 16 Magnus Alm <magnus.alm@gmail.com>
17 */ 17 */
18 18
19static struct ir_scancode winfast_usbii_deluxe[] = { 19static struct rc_map_table winfast_usbii_deluxe[] = {
20 { 0x62, KEY_0}, 20 { 0x62, KEY_0},
21 { 0x75, KEY_1}, 21 { 0x75, KEY_1},
22 { 0x76, KEY_2}, 22 { 0x76, KEY_2},
@@ -56,23 +56,23 @@ static struct ir_scancode winfast_usbii_deluxe[] = {
56 56
57}; 57};
58 58
59static struct rc_keymap winfast_usbii_deluxe_map = { 59static struct rc_map_list winfast_usbii_deluxe_map = {
60 .map = { 60 .map = {
61 .scan = winfast_usbii_deluxe, 61 .scan = winfast_usbii_deluxe,
62 .size = ARRAY_SIZE(winfast_usbii_deluxe), 62 .size = ARRAY_SIZE(winfast_usbii_deluxe),
63 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 63 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
64 .name = RC_MAP_WINFAST_USBII_DELUXE, 64 .name = RC_MAP_WINFAST_USBII_DELUXE,
65 } 65 }
66}; 66};
67 67
68static int __init init_rc_map_winfast_usbii_deluxe(void) 68static int __init init_rc_map_winfast_usbii_deluxe(void)
69{ 69{
70 return ir_register_map(&winfast_usbii_deluxe_map); 70 return rc_map_register(&winfast_usbii_deluxe_map);
71} 71}
72 72
73static void __exit exit_rc_map_winfast_usbii_deluxe(void) 73static void __exit exit_rc_map_winfast_usbii_deluxe(void)
74{ 74{
75 ir_unregister_map(&winfast_usbii_deluxe_map); 75 rc_map_unregister(&winfast_usbii_deluxe_map);
76} 76}
77 77
78module_init(init_rc_map_winfast_usbii_deluxe) 78module_init(init_rc_map_winfast_usbii_deluxe)
diff --git a/drivers/media/IR/keymaps/rc-winfast.c b/drivers/media/rc/keymaps/rc-winfast.c
index 0e90a3bd9499..2747db43b70c 100644
--- a/drivers/media/IR/keymaps/rc-winfast.c
+++ b/drivers/media/rc/keymaps/rc-winfast.c
@@ -14,7 +14,7 @@
14 14
15/* Table for Leadtek Winfast Remote Controls - used by both bttv and cx88 */ 15/* Table for Leadtek Winfast Remote Controls - used by both bttv and cx88 */
16 16
17static struct ir_scancode winfast[] = { 17static struct rc_map_table winfast[] = {
18 /* Keys 0 to 9 */ 18 /* Keys 0 to 9 */
19 { 0x12, KEY_0 }, 19 { 0x12, KEY_0 },
20 { 0x05, KEY_1 }, 20 { 0x05, KEY_1 },
@@ -76,23 +76,23 @@ static struct ir_scancode winfast[] = {
76 { 0x3f, KEY_F24 } /* MCE -CH, on Y04G0033 */ 76 { 0x3f, KEY_F24 } /* MCE -CH, on Y04G0033 */
77}; 77};
78 78
79static struct rc_keymap winfast_map = { 79static struct rc_map_list winfast_map = {
80 .map = { 80 .map = {
81 .scan = winfast, 81 .scan = winfast,
82 .size = ARRAY_SIZE(winfast), 82 .size = ARRAY_SIZE(winfast),
83 .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ 83 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
84 .name = RC_MAP_WINFAST, 84 .name = RC_MAP_WINFAST,
85 } 85 }
86}; 86};
87 87
88static int __init init_rc_map_winfast(void) 88static int __init init_rc_map_winfast(void)
89{ 89{
90 return ir_register_map(&winfast_map); 90 return rc_map_register(&winfast_map);
91} 91}
92 92
93static void __exit exit_rc_map_winfast(void) 93static void __exit exit_rc_map_winfast(void)
94{ 94{
95 ir_unregister_map(&winfast_map); 95 rc_map_unregister(&winfast_map);
96} 96}
97 97
98module_init(init_rc_map_winfast) 98module_init(init_rc_map_winfast)
diff --git a/drivers/media/IR/lirc_dev.c b/drivers/media/rc/lirc_dev.c
index 756656e17bdd..fd237ab120bb 100644
--- a/drivers/media/IR/lirc_dev.c
+++ b/drivers/media/rc/lirc_dev.c
@@ -178,7 +178,9 @@ static int lirc_cdev_add(struct irctl *ir)
178 cdev_init(cdev, &lirc_dev_fops); 178 cdev_init(cdev, &lirc_dev_fops);
179 cdev->owner = THIS_MODULE; 179 cdev->owner = THIS_MODULE;
180 } 180 }
181 kobject_set_name(&cdev->kobj, "lirc%d", d->minor); 181 retval = kobject_set_name(&cdev->kobj, "lirc%d", d->minor);
182 if (retval)
183 return retval;
182 184
183 retval = cdev_add(cdev, MKDEV(MAJOR(lirc_base_dev), d->minor), 1); 185 retval = cdev_add(cdev, MKDEV(MAJOR(lirc_base_dev), d->minor), 1);
184 if (retval) 186 if (retval)
@@ -627,7 +629,7 @@ long lirc_dev_fop_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
627EXPORT_SYMBOL(lirc_dev_fop_ioctl); 629EXPORT_SYMBOL(lirc_dev_fop_ioctl);
628 630
629ssize_t lirc_dev_fop_read(struct file *file, 631ssize_t lirc_dev_fop_read(struct file *file,
630 char *buffer, 632 char __user *buffer,
631 size_t length, 633 size_t length,
632 loff_t *ppos) 634 loff_t *ppos)
633{ 635{
@@ -747,7 +749,7 @@ void *lirc_get_pdata(struct file *file)
747EXPORT_SYMBOL(lirc_get_pdata); 749EXPORT_SYMBOL(lirc_get_pdata);
748 750
749 751
750ssize_t lirc_dev_fop_write(struct file *file, const char *buffer, 752ssize_t lirc_dev_fop_write(struct file *file, const char __user *buffer,
751 size_t length, loff_t *ppos) 753 size_t length, loff_t *ppos)
752{ 754{
753 struct irctl *ir = irctls[iminor(file->f_dentry->d_inode)]; 755 struct irctl *ir = irctls[iminor(file->f_dentry->d_inode)];
diff --git a/drivers/media/IR/mceusb.c b/drivers/media/rc/mceusb.c
index 392ca24132da..0fef6efad537 100644
--- a/drivers/media/IR/mceusb.c
+++ b/drivers/media/rc/mceusb.c
@@ -35,10 +35,9 @@
35#include <linux/device.h> 35#include <linux/device.h>
36#include <linux/module.h> 36#include <linux/module.h>
37#include <linux/slab.h> 37#include <linux/slab.h>
38#include <linux/input.h>
39#include <linux/usb.h> 38#include <linux/usb.h>
40#include <linux/usb/input.h> 39#include <linux/usb/input.h>
41#include <media/ir-core.h> 40#include <media/rc-core.h>
42 41
43#define DRIVER_VERSION "1.91" 42#define DRIVER_VERSION "1.91"
44#define DRIVER_AUTHOR "Jarod Wilson <jarod@wilsonet.com>" 43#define DRIVER_AUTHOR "Jarod Wilson <jarod@wilsonet.com>"
@@ -317,7 +316,7 @@ static struct usb_device_id mceusb_dev_table[] = {
317/* data structure for each usb transceiver */ 316/* data structure for each usb transceiver */
318struct mceusb_dev { 317struct mceusb_dev {
319 /* ir-core bits */ 318 /* ir-core bits */
320 struct ir_dev_props *props; 319 struct rc_dev *rc;
321 320
322 /* optional features we can enable */ 321 /* optional features we can enable */
323 bool carrier_report_enabled; 322 bool carrier_report_enabled;
@@ -325,7 +324,6 @@ struct mceusb_dev {
325 324
326 /* core device bits */ 325 /* core device bits */
327 struct device *dev; 326 struct device *dev;
328 struct input_dev *idev;
329 327
330 /* usb */ 328 /* usb */
331 struct usb_device *usbdev; 329 struct usb_device *usbdev;
@@ -663,9 +661,9 @@ static void mce_sync_in(struct mceusb_dev *ir, unsigned char *data, int size)
663} 661}
664 662
665/* Send data out the IR blaster port(s) */ 663/* Send data out the IR blaster port(s) */
666static int mceusb_tx_ir(void *priv, int *txbuf, u32 n) 664static int mceusb_tx_ir(struct rc_dev *dev, int *txbuf, u32 n)
667{ 665{
668 struct mceusb_dev *ir = priv; 666 struct mceusb_dev *ir = dev->priv;
669 int i, ret = 0; 667 int i, ret = 0;
670 int count, cmdcount = 0; 668 int count, cmdcount = 0;
671 unsigned char *cmdbuf; /* MCE command buffer */ 669 unsigned char *cmdbuf; /* MCE command buffer */
@@ -749,9 +747,9 @@ out:
749} 747}
750 748
751/* Sets active IR outputs -- mce devices typically have two */ 749/* Sets active IR outputs -- mce devices typically have two */
752static int mceusb_set_tx_mask(void *priv, u32 mask) 750static int mceusb_set_tx_mask(struct rc_dev *dev, u32 mask)
753{ 751{
754 struct mceusb_dev *ir = priv; 752 struct mceusb_dev *ir = dev->priv;
755 753
756 if (ir->flags.tx_mask_normal) 754 if (ir->flags.tx_mask_normal)
757 ir->tx_mask = mask; 755 ir->tx_mask = mask;
@@ -763,9 +761,9 @@ static int mceusb_set_tx_mask(void *priv, u32 mask)
763} 761}
764 762
765/* Sets the send carrier frequency and mode */ 763/* Sets the send carrier frequency and mode */
766static int mceusb_set_tx_carrier(void *priv, u32 carrier) 764static int mceusb_set_tx_carrier(struct rc_dev *dev, u32 carrier)
767{ 765{
768 struct mceusb_dev *ir = priv; 766 struct mceusb_dev *ir = dev->priv;
769 int clk = 10000000; 767 int clk = 10000000;
770 int prescaler = 0, divisor = 0; 768 int prescaler = 0, divisor = 0;
771 unsigned char cmdbuf[4] = { MCE_COMMAND_HEADER, 769 unsigned char cmdbuf[4] = { MCE_COMMAND_HEADER,
@@ -819,7 +817,7 @@ static void mceusb_handle_command(struct mceusb_dev *ir, int index)
819 switch (ir->buf_in[index]) { 817 switch (ir->buf_in[index]) {
820 /* 2-byte return value commands */ 818 /* 2-byte return value commands */
821 case MCE_CMD_S_TIMEOUT: 819 case MCE_CMD_S_TIMEOUT:
822 ir->props->timeout = MS_TO_NS((hi << 8 | lo) / 2); 820 ir->rc->timeout = MS_TO_NS((hi << 8 | lo) / 2);
823 break; 821 break;
824 822
825 /* 1-byte return value commands */ 823 /* 1-byte return value commands */
@@ -866,7 +864,7 @@ static void mceusb_process_ir_data(struct mceusb_dev *ir, int buf_len)
866 rawir.pulse ? "pulse" : "space", 864 rawir.pulse ? "pulse" : "space",
867 rawir.duration); 865 rawir.duration);
868 866
869 ir_raw_event_store_with_filter(ir->idev, &rawir); 867 ir_raw_event_store_with_filter(ir->rc, &rawir);
870 break; 868 break;
871 case CMD_DATA: 869 case CMD_DATA:
872 ir->rem--; 870 ir->rem--;
@@ -893,7 +891,7 @@ static void mceusb_process_ir_data(struct mceusb_dev *ir, int buf_len)
893 ir->parser_state = CMD_HEADER; 891 ir->parser_state = CMD_HEADER;
894 } 892 }
895 dev_dbg(ir->dev, "processed IR data, calling ir_raw_event_handle\n"); 893 dev_dbg(ir->dev, "processed IR data, calling ir_raw_event_handle\n");
896 ir_raw_event_handle(ir->idev); 894 ir_raw_event_handle(ir->rc);
897} 895}
898 896
899static void mceusb_dev_recv(struct urb *urb, struct pt_regs *regs) 897static void mceusb_dev_recv(struct urb *urb, struct pt_regs *regs)
@@ -1035,72 +1033,54 @@ static void mceusb_get_parameters(struct mceusb_dev *ir)
1035 mce_sync_in(ir, NULL, maxp); 1033 mce_sync_in(ir, NULL, maxp);
1036} 1034}
1037 1035
1038static struct input_dev *mceusb_init_input_dev(struct mceusb_dev *ir) 1036static struct rc_dev *mceusb_init_rc_dev(struct mceusb_dev *ir)
1039{ 1037{
1040 struct input_dev *idev;
1041 struct ir_dev_props *props;
1042 struct device *dev = ir->dev; 1038 struct device *dev = ir->dev;
1043 const char *rc_map = RC_MAP_RC6_MCE; 1039 struct rc_dev *rc;
1044 const char *name = "Media Center Ed. eHome Infrared Remote Transceiver"; 1040 int ret;
1045 int ret = -ENODEV;
1046
1047 idev = input_allocate_device();
1048 if (!idev) {
1049 dev_err(dev, "remote input dev allocation failed\n");
1050 goto idev_alloc_failed;
1051 }
1052 1041
1053 ret = -ENOMEM; 1042 rc = rc_allocate_device();
1054 props = kzalloc(sizeof(struct ir_dev_props), GFP_KERNEL); 1043 if (!rc) {
1055 if (!props) { 1044 dev_err(dev, "remote dev allocation failed\n");
1056 dev_err(dev, "remote ir dev props allocation failed\n"); 1045 goto out;
1057 goto props_alloc_failed;
1058 } 1046 }
1059 1047
1060 if (mceusb_model[ir->model].name)
1061 name = mceusb_model[ir->model].name;
1062
1063 snprintf(ir->name, sizeof(ir->name), "%s (%04x:%04x)", 1048 snprintf(ir->name, sizeof(ir->name), "%s (%04x:%04x)",
1064 name, 1049 mceusb_model[ir->model].name ?
1050 mceusb_model[ir->model].name :
1051 "Media Center Ed. eHome Infrared Remote Transceiver",
1065 le16_to_cpu(ir->usbdev->descriptor.idVendor), 1052 le16_to_cpu(ir->usbdev->descriptor.idVendor),
1066 le16_to_cpu(ir->usbdev->descriptor.idProduct)); 1053 le16_to_cpu(ir->usbdev->descriptor.idProduct));
1067 1054
1068 idev->name = ir->name;
1069 usb_make_path(ir->usbdev, ir->phys, sizeof(ir->phys)); 1055 usb_make_path(ir->usbdev, ir->phys, sizeof(ir->phys));
1070 strlcat(ir->phys, "/input0", sizeof(ir->phys));
1071 idev->phys = ir->phys;
1072 1056
1073 props->priv = ir; 1057 rc->input_name = ir->name;
1074 props->driver_type = RC_DRIVER_IR_RAW; 1058 rc->input_phys = ir->phys;
1075 props->allowed_protos = IR_TYPE_ALL; 1059 usb_to_input_id(ir->usbdev, &rc->input_id);
1076 props->timeout = MS_TO_NS(1000); 1060 rc->dev.parent = dev;
1061 rc->priv = ir;
1062 rc->driver_type = RC_DRIVER_IR_RAW;
1063 rc->allowed_protos = RC_TYPE_ALL;
1064 rc->timeout = MS_TO_NS(1000);
1077 if (!ir->flags.no_tx) { 1065 if (!ir->flags.no_tx) {
1078 props->s_tx_mask = mceusb_set_tx_mask; 1066 rc->s_tx_mask = mceusb_set_tx_mask;
1079 props->s_tx_carrier = mceusb_set_tx_carrier; 1067 rc->s_tx_carrier = mceusb_set_tx_carrier;
1080 props->tx_ir = mceusb_tx_ir; 1068 rc->tx_ir = mceusb_tx_ir;
1081 } 1069 }
1070 rc->driver_name = DRIVER_NAME;
1071 rc->map_name = mceusb_model[ir->model].rc_map ?
1072 mceusb_model[ir->model].rc_map : RC_MAP_RC6_MCE;
1082 1073
1083 ir->props = props; 1074 ret = rc_register_device(rc);
1084
1085 usb_to_input_id(ir->usbdev, &idev->id);
1086 idev->dev.parent = ir->dev;
1087
1088 if (mceusb_model[ir->model].rc_map)
1089 rc_map = mceusb_model[ir->model].rc_map;
1090
1091 ret = ir_input_register(idev, rc_map, props, DRIVER_NAME);
1092 if (ret < 0) { 1075 if (ret < 0) {
1093 dev_err(dev, "remote input device register failed\n"); 1076 dev_err(dev, "remote dev registration failed\n");
1094 goto irdev_failed; 1077 goto out;
1095 } 1078 }
1096 1079
1097 return idev; 1080 return rc;
1098 1081
1099irdev_failed: 1082out:
1100 kfree(props); 1083 rc_free_device(rc);
1101props_alloc_failed:
1102 input_free_device(idev);
1103idev_alloc_failed:
1104 return NULL; 1084 return NULL;
1105} 1085}
1106 1086
@@ -1212,9 +1192,9 @@ static int __devinit mceusb_dev_probe(struct usb_interface *intf,
1212 snprintf(name + strlen(name), sizeof(name) - strlen(name), 1192 snprintf(name + strlen(name), sizeof(name) - strlen(name),
1213 " %s", buf); 1193 " %s", buf);
1214 1194
1215 ir->idev = mceusb_init_input_dev(ir); 1195 ir->rc = mceusb_init_rc_dev(ir);
1216 if (!ir->idev) 1196 if (!ir->rc)
1217 goto input_dev_fail; 1197 goto rc_dev_fail;
1218 1198
1219 /* flush buffers on the device */ 1199 /* flush buffers on the device */
1220 mce_sync_in(ir, NULL, maxp); 1200 mce_sync_in(ir, NULL, maxp);
@@ -1235,7 +1215,7 @@ static int __devinit mceusb_dev_probe(struct usb_interface *intf,
1235 mceusb_get_parameters(ir); 1215 mceusb_get_parameters(ir);
1236 1216
1237 if (!ir->flags.no_tx) 1217 if (!ir->flags.no_tx)
1238 mceusb_set_tx_mask(ir, MCE_DEFAULT_TX_MASK); 1218 mceusb_set_tx_mask(ir->rc, MCE_DEFAULT_TX_MASK);
1239 1219
1240 usb_set_intfdata(intf, ir); 1220 usb_set_intfdata(intf, ir);
1241 1221
@@ -1245,7 +1225,7 @@ static int __devinit mceusb_dev_probe(struct usb_interface *intf,
1245 return 0; 1225 return 0;
1246 1226
1247 /* Error-handling path */ 1227 /* Error-handling path */
1248input_dev_fail: 1228rc_dev_fail:
1249 usb_free_urb(ir->urb_in); 1229 usb_free_urb(ir->urb_in);
1250urb_in_alloc_fail: 1230urb_in_alloc_fail:
1251 usb_free_coherent(dev, maxp, ir->buf_in, ir->dma_in); 1231 usb_free_coherent(dev, maxp, ir->buf_in, ir->dma_in);
@@ -1269,7 +1249,7 @@ static void __devexit mceusb_dev_disconnect(struct usb_interface *intf)
1269 return; 1249 return;
1270 1250
1271 ir->usbdev = NULL; 1251 ir->usbdev = NULL;
1272 ir_input_unregister(ir->idev); 1252 rc_unregister_device(ir->rc);
1273 usb_kill_urb(ir->urb_in); 1253 usb_kill_urb(ir->urb_in);
1274 usb_free_urb(ir->urb_in); 1254 usb_free_urb(ir->urb_in);
1275 usb_free_coherent(dev, ir->len_in, ir->buf_in, ir->dma_in); 1255 usb_free_coherent(dev, ir->len_in, ir->buf_in, ir->dma_in);
diff --git a/drivers/media/IR/nuvoton-cir.c b/drivers/media/rc/nuvoton-cir.c
index acc729c79cec..dd4caf8ef80b 100644
--- a/drivers/media/IR/nuvoton-cir.c
+++ b/drivers/media/rc/nuvoton-cir.c
@@ -32,8 +32,7 @@
32#include <linux/interrupt.h> 32#include <linux/interrupt.h>
33#include <linux/sched.h> 33#include <linux/sched.h>
34#include <linux/slab.h> 34#include <linux/slab.h>
35#include <linux/input.h> 35#include <media/rc-core.h>
36#include <media/ir-core.h>
37#include <linux/pci_ids.h> 36#include <linux/pci_ids.h>
38 37
39#include "nuvoton-cir.h" 38#include "nuvoton-cir.h"
@@ -249,9 +248,12 @@ static int nvt_hw_detect(struct nvt_dev *nvt)
249 chip_minor = nvt_cr_read(nvt, CR_CHIP_ID_LO); 248 chip_minor = nvt_cr_read(nvt, CR_CHIP_ID_LO);
250 nvt_dbg("%s: chip id: 0x%02x 0x%02x", chip_id, chip_major, chip_minor); 249 nvt_dbg("%s: chip id: 0x%02x 0x%02x", chip_id, chip_major, chip_minor);
251 250
252 if (chip_major != CHIP_ID_HIGH && 251 if (chip_major != CHIP_ID_HIGH ||
253 (chip_minor != CHIP_ID_LOW || chip_minor != CHIP_ID_LOW2)) 252 (chip_minor != CHIP_ID_LOW && chip_minor != CHIP_ID_LOW2)) {
253 nvt_pr(KERN_ERR, "%s: unsupported chip, id: 0x%02x 0x%02x",
254 chip_id, chip_major, chip_minor);
254 ret = -ENODEV; 255 ret = -ENODEV;
256 }
255 257
256 nvt_efm_disable(nvt); 258 nvt_efm_disable(nvt);
257 259
@@ -476,9 +478,9 @@ static u32 nvt_rx_carrier_detect(struct nvt_dev *nvt)
476 * always set CP as 0x81 478 * always set CP as 0x81
477 * set CC by SPEC, CC = 3MHz/carrier - 1 479 * set CC by SPEC, CC = 3MHz/carrier - 1
478 */ 480 */
479static int nvt_set_tx_carrier(void *data, u32 carrier) 481static int nvt_set_tx_carrier(struct rc_dev *dev, u32 carrier)
480{ 482{
481 struct nvt_dev *nvt = data; 483 struct nvt_dev *nvt = dev->priv;
482 u16 val; 484 u16 val;
483 485
484 nvt_cir_reg_write(nvt, 1, CIR_CP); 486 nvt_cir_reg_write(nvt, 1, CIR_CP);
@@ -509,9 +511,9 @@ static int nvt_set_tx_carrier(void *data, u32 carrier)
509 * number may larger than TXFCONT (0xff). So in interrupt_handler, it has to 511 * number may larger than TXFCONT (0xff). So in interrupt_handler, it has to
510 * set TXFCONT as 0xff, until buf_count less than 0xff. 512 * set TXFCONT as 0xff, until buf_count less than 0xff.
511 */ 513 */
512static int nvt_tx_ir(void *priv, int *txbuf, u32 n) 514static int nvt_tx_ir(struct rc_dev *dev, int *txbuf, u32 n)
513{ 515{
514 struct nvt_dev *nvt = priv; 516 struct nvt_dev *nvt = dev->priv;
515 unsigned long flags; 517 unsigned long flags;
516 size_t cur_count; 518 size_t cur_count;
517 unsigned int i; 519 unsigned int i;
@@ -948,9 +950,9 @@ static void nvt_disable_cir(struct nvt_dev *nvt)
948 nvt_efm_disable(nvt); 950 nvt_efm_disable(nvt);
949} 951}
950 952
951static int nvt_open(void *data) 953static int nvt_open(struct rc_dev *dev)
952{ 954{
953 struct nvt_dev *nvt = (struct nvt_dev *)data; 955 struct nvt_dev *nvt = dev->priv;
954 unsigned long flags; 956 unsigned long flags;
955 957
956 spin_lock_irqsave(&nvt->nvt_lock, flags); 958 spin_lock_irqsave(&nvt->nvt_lock, flags);
@@ -961,9 +963,9 @@ static int nvt_open(void *data)
961 return 0; 963 return 0;
962} 964}
963 965
964static void nvt_close(void *data) 966static void nvt_close(struct rc_dev *dev)
965{ 967{
966 struct nvt_dev *nvt = (struct nvt_dev *)data; 968 struct nvt_dev *nvt = dev->priv;
967 unsigned long flags; 969 unsigned long flags;
968 970
969 spin_lock_irqsave(&nvt->nvt_lock, flags); 971 spin_lock_irqsave(&nvt->nvt_lock, flags);
@@ -975,21 +977,16 @@ static void nvt_close(void *data)
975/* Allocate memory, probe hardware, and initialize everything */ 977/* Allocate memory, probe hardware, and initialize everything */
976static int nvt_probe(struct pnp_dev *pdev, const struct pnp_device_id *dev_id) 978static int nvt_probe(struct pnp_dev *pdev, const struct pnp_device_id *dev_id)
977{ 979{
978 struct nvt_dev *nvt = NULL; 980 struct nvt_dev *nvt;
979 struct input_dev *rdev = NULL; 981 struct rc_dev *rdev;
980 struct ir_dev_props *props = NULL;
981 int ret = -ENOMEM; 982 int ret = -ENOMEM;
982 983
983 nvt = kzalloc(sizeof(struct nvt_dev), GFP_KERNEL); 984 nvt = kzalloc(sizeof(struct nvt_dev), GFP_KERNEL);
984 if (!nvt) 985 if (!nvt)
985 return ret; 986 return ret;
986 987
987 props = kzalloc(sizeof(struct ir_dev_props), GFP_KERNEL);
988 if (!props)
989 goto failure;
990
991 /* input device for IR remote (and tx) */ 988 /* input device for IR remote (and tx) */
992 rdev = input_allocate_device(); 989 rdev = rc_allocate_device();
993 if (!rdev) 990 if (!rdev)
994 goto failure; 991 goto failure;
995 992
@@ -1063,41 +1060,38 @@ static int nvt_probe(struct pnp_dev *pdev, const struct pnp_device_id *dev_id)
1063 nvt_cir_regs_init(nvt); 1060 nvt_cir_regs_init(nvt);
1064 nvt_cir_wake_regs_init(nvt); 1061 nvt_cir_wake_regs_init(nvt);
1065 1062
1066 /* Set up ir-core props */ 1063 /* Set up the rc device */
1067 props->priv = nvt; 1064 rdev->priv = nvt;
1068 props->driver_type = RC_DRIVER_IR_RAW; 1065 rdev->driver_type = RC_DRIVER_IR_RAW;
1069 props->allowed_protos = IR_TYPE_ALL; 1066 rdev->allowed_protos = RC_TYPE_ALL;
1070 props->open = nvt_open; 1067 rdev->open = nvt_open;
1071 props->close = nvt_close; 1068 rdev->close = nvt_close;
1069 rdev->tx_ir = nvt_tx_ir;
1070 rdev->s_tx_carrier = nvt_set_tx_carrier;
1071 rdev->input_name = "Nuvoton w836x7hg Infrared Remote Transceiver";
1072 rdev->input_id.bustype = BUS_HOST;
1073 rdev->input_id.vendor = PCI_VENDOR_ID_WINBOND2;
1074 rdev->input_id.product = nvt->chip_major;
1075 rdev->input_id.version = nvt->chip_minor;
1076 rdev->driver_name = NVT_DRIVER_NAME;
1077 rdev->map_name = RC_MAP_RC6_MCE;
1072#if 0 1078#if 0
1073 props->min_timeout = XYZ; 1079 rdev->min_timeout = XYZ;
1074 props->max_timeout = XYZ; 1080 rdev->max_timeout = XYZ;
1075 props->timeout = XYZ; 1081 rdev->timeout = XYZ;
1076 /* rx resolution is hardwired to 50us atm, 1, 25, 100 also possible */ 1082 /* rx resolution is hardwired to 50us atm, 1, 25, 100 also possible */
1077 props->rx_resolution = XYZ; 1083 rdev->rx_resolution = XYZ;
1078
1079 /* tx bits */ 1084 /* tx bits */
1080 props->tx_resolution = XYZ; 1085 rdev->tx_resolution = XYZ;
1081#endif 1086#endif
1082 props->tx_ir = nvt_tx_ir;
1083 props->s_tx_carrier = nvt_set_tx_carrier;
1084
1085 rdev->name = "Nuvoton w836x7hg Infrared Remote Transceiver";
1086 rdev->id.bustype = BUS_HOST;
1087 rdev->id.vendor = PCI_VENDOR_ID_WINBOND2;
1088 rdev->id.product = nvt->chip_major;
1089 rdev->id.version = nvt->chip_minor;
1090
1091 nvt->props = props;
1092 nvt->rdev = rdev;
1093
1094 device_set_wakeup_capable(&pdev->dev, 1);
1095 device_set_wakeup_enable(&pdev->dev, 1);
1096 1087
1097 ret = ir_input_register(rdev, RC_MAP_RC6_MCE, props, NVT_DRIVER_NAME); 1088 ret = rc_register_device(rdev);
1098 if (ret) 1089 if (ret)
1099 goto failure; 1090 goto failure;
1100 1091
1092 device_set_wakeup_capable(&pdev->dev, 1);
1093 device_set_wakeup_enable(&pdev->dev, 1);
1094 nvt->rdev = rdev;
1101 nvt_pr(KERN_NOTICE, "driver has been successfully loaded\n"); 1095 nvt_pr(KERN_NOTICE, "driver has been successfully loaded\n");
1102 if (debug) { 1096 if (debug) {
1103 cir_dump_regs(nvt); 1097 cir_dump_regs(nvt);
@@ -1117,8 +1111,7 @@ failure:
1117 if (nvt->cir_wake_addr) 1111 if (nvt->cir_wake_addr)
1118 release_region(nvt->cir_wake_addr, CIR_IOREG_LENGTH); 1112 release_region(nvt->cir_wake_addr, CIR_IOREG_LENGTH);
1119 1113
1120 input_free_device(rdev); 1114 rc_free_device(rdev);
1121 kfree(props);
1122 kfree(nvt); 1115 kfree(nvt);
1123 1116
1124 return ret; 1117 return ret;
@@ -1143,9 +1136,8 @@ static void __devexit nvt_remove(struct pnp_dev *pdev)
1143 release_region(nvt->cir_addr, CIR_IOREG_LENGTH); 1136 release_region(nvt->cir_addr, CIR_IOREG_LENGTH);
1144 release_region(nvt->cir_wake_addr, CIR_IOREG_LENGTH); 1137 release_region(nvt->cir_wake_addr, CIR_IOREG_LENGTH);
1145 1138
1146 ir_input_unregister(nvt->rdev); 1139 rc_unregister_device(nvt->rdev);
1147 1140
1148 kfree(nvt->props);
1149 kfree(nvt); 1141 kfree(nvt);
1150} 1142}
1151 1143
diff --git a/drivers/media/IR/nuvoton-cir.h b/drivers/media/rc/nuvoton-cir.h
index 62dc53017c8e..1df82351cb03 100644
--- a/drivers/media/IR/nuvoton-cir.h
+++ b/drivers/media/rc/nuvoton-cir.h
@@ -66,8 +66,7 @@ static int debug;
66 66
67struct nvt_dev { 67struct nvt_dev {
68 struct pnp_dev *pdev; 68 struct pnp_dev *pdev;
69 struct input_dev *rdev; 69 struct rc_dev *rdev;
70 struct ir_dev_props *props;
71 struct ir_raw_event rawir; 70 struct ir_raw_event rawir;
72 71
73 spinlock_t nvt_lock; 72 spinlock_t nvt_lock;
diff --git a/drivers/media/IR/ir-core-priv.h b/drivers/media/rc/rc-core-priv.h
index 81c936bd793f..873b38789751 100644
--- a/drivers/media/IR/ir-core-priv.h
+++ b/drivers/media/rc/rc-core-priv.h
@@ -13,22 +13,22 @@
13 * GNU General Public License for more details. 13 * GNU General Public License for more details.
14 */ 14 */
15 15
16#ifndef _IR_RAW_EVENT 16#ifndef _RC_CORE_PRIV
17#define _IR_RAW_EVENT 17#define _RC_CORE_PRIV
18 18
19#include <linux/slab.h> 19#include <linux/slab.h>
20#include <linux/spinlock.h> 20#include <linux/spinlock.h>
21#include <media/ir-core.h> 21#include <media/rc-core.h>
22 22
23struct ir_raw_handler { 23struct ir_raw_handler {
24 struct list_head list; 24 struct list_head list;
25 25
26 u64 protocols; /* which are handled by this handler */ 26 u64 protocols; /* which are handled by this handler */
27 int (*decode)(struct input_dev *input_dev, struct ir_raw_event event); 27 int (*decode)(struct rc_dev *dev, struct ir_raw_event event);
28 28
29 /* These two should only be used by the lirc decoder */ 29 /* These two should only be used by the lirc decoder */
30 int (*raw_register)(struct input_dev *input_dev); 30 int (*raw_register)(struct rc_dev *dev);
31 int (*raw_unregister)(struct input_dev *input_dev); 31 int (*raw_unregister)(struct rc_dev *dev);
32}; 32};
33 33
34struct ir_raw_event_ctrl { 34struct ir_raw_event_ctrl {
@@ -38,7 +38,7 @@ struct ir_raw_event_ctrl {
38 struct kfifo kfifo; /* fifo for the pulse/space durations */ 38 struct kfifo kfifo; /* fifo for the pulse/space durations */
39 ktime_t last_event; /* when last event occurred */ 39 ktime_t last_event; /* when last event occurred */
40 enum raw_event_type last_type; /* last event type */ 40 enum raw_event_type last_type; /* last event type */
41 struct input_dev *input_dev; /* pointer to the parent input_dev */ 41 struct rc_dev *dev; /* pointer to the parent rc_dev */
42 u64 enabled_protocols; /* enabled raw protocol decoders */ 42 u64 enabled_protocols; /* enabled raw protocol decoders */
43 43
44 /* raw decoder state follows */ 44 /* raw decoder state follows */
@@ -85,7 +85,7 @@ struct ir_raw_event_ctrl {
85 unsigned wanted_bits; 85 unsigned wanted_bits;
86 } rc5_sz; 86 } rc5_sz;
87 struct lirc_codec { 87 struct lirc_codec {
88 struct ir_input_dev *ir_dev; 88 struct rc_dev *dev;
89 struct lirc_driver *drv; 89 struct lirc_driver *drv;
90 int carrier_low; 90 int carrier_low;
91 91
@@ -129,27 +129,17 @@ static inline bool is_timing_event(struct ir_raw_event ev)
129 129
130#define TO_US(duration) DIV_ROUND_CLOSEST((duration), 1000) 130#define TO_US(duration) DIV_ROUND_CLOSEST((duration), 1000)
131#define TO_STR(is_pulse) ((is_pulse) ? "pulse" : "space") 131#define TO_STR(is_pulse) ((is_pulse) ? "pulse" : "space")
132/*
133 * Routines from ir-sysfs.c - Meant to be called only internally inside
134 * ir-core
135 */
136int ir_register_input(struct input_dev *input_dev);
137
138int ir_register_class(struct input_dev *input_dev);
139void ir_unregister_class(struct input_dev *input_dev);
140 132
141/* 133/*
142 * Routines from ir-raw-event.c to be used internally and by decoders 134 * Routines from rc-raw.c to be used internally and by decoders
143 */ 135 */
144u64 ir_raw_get_allowed_protocols(void); 136u64 ir_raw_get_allowed_protocols(void);
145int ir_raw_event_register(struct input_dev *input_dev); 137int ir_raw_event_register(struct rc_dev *dev);
146void ir_raw_event_unregister(struct input_dev *input_dev); 138void ir_raw_event_unregister(struct rc_dev *dev);
147int ir_raw_handler_register(struct ir_raw_handler *ir_raw_handler); 139int ir_raw_handler_register(struct ir_raw_handler *ir_raw_handler);
148void ir_raw_handler_unregister(struct ir_raw_handler *ir_raw_handler); 140void ir_raw_handler_unregister(struct ir_raw_handler *ir_raw_handler);
149void ir_raw_init(void); 141void ir_raw_init(void);
150 142
151int ir_rcmap_init(void);
152void ir_rcmap_cleanup(void);
153/* 143/*
154 * Decoder initialization code 144 * Decoder initialization code
155 * 145 *
@@ -200,4 +190,4 @@ void ir_rcmap_cleanup(void);
200#endif 190#endif
201 191
202 192
203#endif /* _IR_RAW_EVENT */ 193#endif /* _RC_CORE_PRIV */
diff --git a/drivers/media/rc/rc-loopback.c b/drivers/media/rc/rc-loopback.c
new file mode 100644
index 000000000000..49cee61d79c6
--- /dev/null
+++ b/drivers/media/rc/rc-loopback.c
@@ -0,0 +1,260 @@
1/*
2 * Loopback driver for rc-core,
3 *
4 * Copyright (c) 2010 David Härdeman <david@hardeman.nu>
5 *
6 * This driver receives TX data and passes it back as RX data,
7 * which is useful for (scripted) debugging of rc-core without
8 * having to use actual hardware.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 *
24 */
25
26#include <linux/device.h>
27#include <linux/module.h>
28#include <linux/sched.h>
29#include <media/rc-core.h>
30
31#define DRIVER_NAME "rc-loopback"
32#define dprintk(x...) if (debug) printk(KERN_INFO DRIVER_NAME ": " x)
33#define RXMASK_REGULAR 0x1
34#define RXMASK_LEARNING 0x2
35
36static bool debug;
37
38struct loopback_dev {
39 struct rc_dev *dev;
40 u32 txmask;
41 u32 txcarrier;
42 u32 txduty;
43 bool idle;
44 bool learning;
45 bool carrierreport;
46 u32 rxcarriermin;
47 u32 rxcarriermax;
48};
49
50static struct loopback_dev loopdev;
51
52static int loop_set_tx_mask(struct rc_dev *dev, u32 mask)
53{
54 struct loopback_dev *lodev = dev->priv;
55
56 if ((mask & (RXMASK_REGULAR | RXMASK_LEARNING)) != mask) {
57 dprintk("invalid tx mask: %u\n", mask);
58 return -EINVAL;
59 }
60
61 dprintk("setting tx mask: %u\n", mask);
62 lodev->txmask = mask;
63 return 0;
64}
65
66static int loop_set_tx_carrier(struct rc_dev *dev, u32 carrier)
67{
68 struct loopback_dev *lodev = dev->priv;
69
70 dprintk("setting tx carrier: %u\n", carrier);
71 lodev->txcarrier = carrier;
72 return 0;
73}
74
75static int loop_set_tx_duty_cycle(struct rc_dev *dev, u32 duty_cycle)
76{
77 struct loopback_dev *lodev = dev->priv;
78
79 if (duty_cycle < 1 || duty_cycle > 99) {
80 dprintk("invalid duty cycle: %u\n", duty_cycle);
81 return -EINVAL;
82 }
83
84 dprintk("setting duty cycle: %u\n", duty_cycle);
85 lodev->txduty = duty_cycle;
86 return 0;
87}
88
89static int loop_set_rx_carrier_range(struct rc_dev *dev, u32 min, u32 max)
90{
91 struct loopback_dev *lodev = dev->priv;
92
93 if (min < 1 || min > max) {
94 dprintk("invalid rx carrier range %u to %u\n", min, max);
95 return -EINVAL;
96 }
97
98 dprintk("setting rx carrier range %u to %u\n", min, max);
99 lodev->rxcarriermin = min;
100 lodev->rxcarriermax = max;
101 return 0;
102}
103
104static int loop_tx_ir(struct rc_dev *dev, int *txbuf, u32 n)
105{
106 struct loopback_dev *lodev = dev->priv;
107 u32 rxmask;
108 unsigned count;
109 unsigned total_duration = 0;
110 unsigned i;
111 DEFINE_IR_RAW_EVENT(rawir);
112
113 if (n == 0 || n % sizeof(int)) {
114 dprintk("invalid tx buffer size\n");
115 return -EINVAL;
116 }
117
118 count = n / sizeof(int);
119 for (i = 0; i < count; i++)
120 total_duration += abs(txbuf[i]);
121
122 if (total_duration == 0) {
123 dprintk("invalid tx data, total duration zero\n");
124 return -EINVAL;
125 }
126
127 if (lodev->txcarrier < lodev->rxcarriermin ||
128 lodev->txcarrier > lodev->rxcarriermax) {
129 dprintk("ignoring tx, carrier out of range\n");
130 goto out;
131 }
132
133 if (lodev->learning)
134 rxmask = RXMASK_LEARNING;
135 else
136 rxmask = RXMASK_REGULAR;
137
138 if (!(rxmask & lodev->txmask)) {
139 dprintk("ignoring tx, rx mask mismatch\n");
140 goto out;
141 }
142
143 for (i = 0; i < count; i++) {
144 rawir.pulse = i % 2 ? false : true;
145 rawir.duration = abs(txbuf[i]) * 1000;
146 if (rawir.duration)
147 ir_raw_event_store_with_filter(dev, &rawir);
148 }
149 ir_raw_event_handle(dev);
150
151out:
152 /* Lirc expects this function to take as long as the total duration */
153 set_current_state(TASK_INTERRUPTIBLE);
154 schedule_timeout(usecs_to_jiffies(total_duration));
155 return n;
156}
157
158static void loop_set_idle(struct rc_dev *dev, bool enable)
159{
160 struct loopback_dev *lodev = dev->priv;
161
162 if (lodev->idle != enable) {
163 dprintk("%sing idle mode\n", enable ? "enter" : "exit");
164 lodev->idle = enable;
165 }
166}
167
168static int loop_set_learning_mode(struct rc_dev *dev, int enable)
169{
170 struct loopback_dev *lodev = dev->priv;
171
172 if (lodev->learning != enable) {
173 dprintk("%sing learning mode\n", enable ? "enter" : "exit");
174 lodev->learning = !!enable;
175 }
176
177 return 0;
178}
179
180static int loop_set_carrier_report(struct rc_dev *dev, int enable)
181{
182 struct loopback_dev *lodev = dev->priv;
183
184 if (lodev->carrierreport != enable) {
185 dprintk("%sabling carrier reports\n", enable ? "en" : "dis");
186 lodev->carrierreport = !!enable;
187 }
188
189 return 0;
190}
191
192static int __init loop_init(void)
193{
194 struct rc_dev *rc;
195 int ret;
196
197 rc = rc_allocate_device();
198 if (!rc) {
199 printk(KERN_ERR DRIVER_NAME ": rc_dev allocation failed\n");
200 return -ENOMEM;
201 }
202
203 rc->input_name = "rc-core loopback device";
204 rc->input_phys = "rc-core/virtual";
205 rc->input_id.bustype = BUS_VIRTUAL;
206 rc->input_id.version = 1;
207 rc->driver_name = DRIVER_NAME;
208 rc->map_name = RC_MAP_EMPTY;
209 rc->priv = &loopdev;
210 rc->driver_type = RC_DRIVER_IR_RAW;
211 rc->allowed_protos = RC_TYPE_ALL;
212 rc->timeout = 100 * 1000 * 1000; /* 100 ms */
213 rc->min_timeout = 1;
214 rc->max_timeout = UINT_MAX;
215 rc->rx_resolution = 1000;
216 rc->tx_resolution = 1000;
217 rc->s_tx_mask = loop_set_tx_mask;
218 rc->s_tx_carrier = loop_set_tx_carrier;
219 rc->s_tx_duty_cycle = loop_set_tx_duty_cycle;
220 rc->s_rx_carrier_range = loop_set_rx_carrier_range;
221 rc->tx_ir = loop_tx_ir;
222 rc->s_idle = loop_set_idle;
223 rc->s_learning_mode = loop_set_learning_mode;
224 rc->s_carrier_report = loop_set_carrier_report;
225 rc->priv = &loopdev;
226
227 loopdev.txmask = RXMASK_REGULAR;
228 loopdev.txcarrier = 36000;
229 loopdev.txduty = 50;
230 loopdev.rxcarriermin = 1;
231 loopdev.rxcarriermax = ~0;
232 loopdev.idle = true;
233 loopdev.learning = false;
234 loopdev.carrierreport = false;
235
236 ret = rc_register_device(rc);
237 if (ret < 0) {
238 printk(KERN_ERR DRIVER_NAME ": rc_dev registration failed\n");
239 rc_free_device(rc);
240 return ret;
241 }
242
243 loopdev.dev = rc;
244 return 0;
245}
246
247static void __exit loop_exit(void)
248{
249 rc_unregister_device(loopdev.dev);
250}
251
252module_init(loop_init);
253module_exit(loop_exit);
254
255module_param(debug, bool, S_IRUGO | S_IWUSR);
256MODULE_PARM_DESC(debug, "Enable debug messages");
257
258MODULE_DESCRIPTION("Loopback device for rc-core debugging");
259MODULE_AUTHOR("David Härdeman <david@hardeman.nu>");
260MODULE_LICENSE("GPL");
diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
new file mode 100644
index 000000000000..72be8a02118c
--- /dev/null
+++ b/drivers/media/rc/rc-main.c
@@ -0,0 +1,1135 @@
1/* rc-main.c - Remote Controller core module
2 *
3 * Copyright (C) 2009-2010 by Mauro Carvalho Chehab <mchehab@redhat.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation version 2 of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14
15#include <media/rc-core.h>
16#include <linux/spinlock.h>
17#include <linux/delay.h>
18#include <linux/input.h>
19#include <linux/slab.h>
20#include <linux/device.h>
21#include "rc-core-priv.h"
22
23/* Sizes are in bytes, 256 bytes allows for 32 entries on x64 */
24#define IR_TAB_MIN_SIZE 256
25#define IR_TAB_MAX_SIZE 8192
26
27/* FIXME: IR_KEYPRESS_TIMEOUT should be protocol specific */
28#define IR_KEYPRESS_TIMEOUT 250
29
30/* Used to keep track of known keymaps */
31static LIST_HEAD(rc_map_list);
32static DEFINE_SPINLOCK(rc_map_lock);
33
34static struct rc_map_list *seek_rc_map(const char *name)
35{
36 struct rc_map_list *map = NULL;
37
38 spin_lock(&rc_map_lock);
39 list_for_each_entry(map, &rc_map_list, list) {
40 if (!strcmp(name, map->map.name)) {
41 spin_unlock(&rc_map_lock);
42 return map;
43 }
44 }
45 spin_unlock(&rc_map_lock);
46
47 return NULL;
48}
49
50struct rc_map *rc_map_get(const char *name)
51{
52
53 struct rc_map_list *map;
54
55 map = seek_rc_map(name);
56#ifdef MODULE
57 if (!map) {
58 int rc = request_module(name);
59 if (rc < 0) {
60 printk(KERN_ERR "Couldn't load IR keymap %s\n", name);
61 return NULL;
62 }
63 msleep(20); /* Give some time for IR to register */
64
65 map = seek_rc_map(name);
66 }
67#endif
68 if (!map) {
69 printk(KERN_ERR "IR keymap %s not found\n", name);
70 return NULL;
71 }
72
73 printk(KERN_INFO "Registered IR keymap %s\n", map->map.name);
74
75 return &map->map;
76}
77EXPORT_SYMBOL_GPL(rc_map_get);
78
79int rc_map_register(struct rc_map_list *map)
80{
81 spin_lock(&rc_map_lock);
82 list_add_tail(&map->list, &rc_map_list);
83 spin_unlock(&rc_map_lock);
84 return 0;
85}
86EXPORT_SYMBOL_GPL(rc_map_register);
87
88void rc_map_unregister(struct rc_map_list *map)
89{
90 spin_lock(&rc_map_lock);
91 list_del(&map->list);
92 spin_unlock(&rc_map_lock);
93}
94EXPORT_SYMBOL_GPL(rc_map_unregister);
95
96
97static struct rc_map_table empty[] = {
98 { 0x2a, KEY_COFFEE },
99};
100
101static struct rc_map_list empty_map = {
102 .map = {
103 .scan = empty,
104 .size = ARRAY_SIZE(empty),
105 .rc_type = RC_TYPE_UNKNOWN, /* Legacy IR type */
106 .name = RC_MAP_EMPTY,
107 }
108};
109
110/**
111 * ir_create_table() - initializes a scancode table
112 * @rc_map: the rc_map to initialize
113 * @name: name to assign to the table
114 * @rc_type: ir type to assign to the new table
115 * @size: initial size of the table
116 * @return: zero on success or a negative error code
117 *
118 * This routine will initialize the rc_map and will allocate
119 * memory to hold at least the specified number of elements.
120 */
121static int ir_create_table(struct rc_map *rc_map,
122 const char *name, u64 rc_type, size_t size)
123{
124 rc_map->name = name;
125 rc_map->rc_type = rc_type;
126 rc_map->alloc = roundup_pow_of_two(size * sizeof(struct rc_map_table));
127 rc_map->size = rc_map->alloc / sizeof(struct rc_map_table);
128 rc_map->scan = kmalloc(rc_map->alloc, GFP_KERNEL);
129 if (!rc_map->scan)
130 return -ENOMEM;
131
132 IR_dprintk(1, "Allocated space for %u keycode entries (%u bytes)\n",
133 rc_map->size, rc_map->alloc);
134 return 0;
135}
136
137/**
138 * ir_free_table() - frees memory allocated by a scancode table
139 * @rc_map: the table whose mappings need to be freed
140 *
141 * This routine will free memory alloctaed for key mappings used by given
142 * scancode table.
143 */
144static void ir_free_table(struct rc_map *rc_map)
145{
146 rc_map->size = 0;
147 kfree(rc_map->scan);
148 rc_map->scan = NULL;
149}
150
151/**
152 * ir_resize_table() - resizes a scancode table if necessary
153 * @rc_map: the rc_map to resize
154 * @gfp_flags: gfp flags to use when allocating memory
155 * @return: zero on success or a negative error code
156 *
157 * This routine will shrink the rc_map if it has lots of
158 * unused entries and grow it if it is full.
159 */
160static int ir_resize_table(struct rc_map *rc_map, gfp_t gfp_flags)
161{
162 unsigned int oldalloc = rc_map->alloc;
163 unsigned int newalloc = oldalloc;
164 struct rc_map_table *oldscan = rc_map->scan;
165 struct rc_map_table *newscan;
166
167 if (rc_map->size == rc_map->len) {
168 /* All entries in use -> grow keytable */
169 if (rc_map->alloc >= IR_TAB_MAX_SIZE)
170 return -ENOMEM;
171
172 newalloc *= 2;
173 IR_dprintk(1, "Growing table to %u bytes\n", newalloc);
174 }
175
176 if ((rc_map->len * 3 < rc_map->size) && (oldalloc > IR_TAB_MIN_SIZE)) {
177 /* Less than 1/3 of entries in use -> shrink keytable */
178 newalloc /= 2;
179 IR_dprintk(1, "Shrinking table to %u bytes\n", newalloc);
180 }
181
182 if (newalloc == oldalloc)
183 return 0;
184
185 newscan = kmalloc(newalloc, gfp_flags);
186 if (!newscan) {
187 IR_dprintk(1, "Failed to kmalloc %u bytes\n", newalloc);
188 return -ENOMEM;
189 }
190
191 memcpy(newscan, rc_map->scan, rc_map->len * sizeof(struct rc_map_table));
192 rc_map->scan = newscan;
193 rc_map->alloc = newalloc;
194 rc_map->size = rc_map->alloc / sizeof(struct rc_map_table);
195 kfree(oldscan);
196 return 0;
197}
198
199/**
200 * ir_update_mapping() - set a keycode in the scancode->keycode table
201 * @dev: the struct rc_dev device descriptor
202 * @rc_map: scancode table to be adjusted
203 * @index: index of the mapping that needs to be updated
204 * @keycode: the desired keycode
205 * @return: previous keycode assigned to the mapping
206 *
207 * This routine is used to update scancode->keycode mapping at given
208 * position.
209 */
210static unsigned int ir_update_mapping(struct rc_dev *dev,
211 struct rc_map *rc_map,
212 unsigned int index,
213 unsigned int new_keycode)
214{
215 int old_keycode = rc_map->scan[index].keycode;
216 int i;
217
218 /* Did the user wish to remove the mapping? */
219 if (new_keycode == KEY_RESERVED || new_keycode == KEY_UNKNOWN) {
220 IR_dprintk(1, "#%d: Deleting scan 0x%04x\n",
221 index, rc_map->scan[index].scancode);
222 rc_map->len--;
223 memmove(&rc_map->scan[index], &rc_map->scan[index+ 1],
224 (rc_map->len - index) * sizeof(struct rc_map_table));
225 } else {
226 IR_dprintk(1, "#%d: %s scan 0x%04x with key 0x%04x\n",
227 index,
228 old_keycode == KEY_RESERVED ? "New" : "Replacing",
229 rc_map->scan[index].scancode, new_keycode);
230 rc_map->scan[index].keycode = new_keycode;
231 __set_bit(new_keycode, dev->input_dev->keybit);
232 }
233
234 if (old_keycode != KEY_RESERVED) {
235 /* A previous mapping was updated... */
236 __clear_bit(old_keycode, dev->input_dev->keybit);
237 /* ... but another scancode might use the same keycode */
238 for (i = 0; i < rc_map->len; i++) {
239 if (rc_map->scan[i].keycode == old_keycode) {
240 __set_bit(old_keycode, dev->input_dev->keybit);
241 break;
242 }
243 }
244
245 /* Possibly shrink the keytable, failure is not a problem */
246 ir_resize_table(rc_map, GFP_ATOMIC);
247 }
248
249 return old_keycode;
250}
251
252/**
253 * ir_establish_scancode() - set a keycode in the scancode->keycode table
254 * @dev: the struct rc_dev device descriptor
255 * @rc_map: scancode table to be searched
256 * @scancode: the desired scancode
257 * @resize: controls whether we allowed to resize the table to
258 * accomodate not yet present scancodes
259 * @return: index of the mapping containing scancode in question
260 * or -1U in case of failure.
261 *
262 * This routine is used to locate given scancode in rc_map.
263 * If scancode is not yet present the routine will allocate a new slot
264 * for it.
265 */
266static unsigned int ir_establish_scancode(struct rc_dev *dev,
267 struct rc_map *rc_map,
268 unsigned int scancode,
269 bool resize)
270{
271 unsigned int i;
272
273 /*
274 * Unfortunately, some hardware-based IR decoders don't provide
275 * all bits for the complete IR code. In general, they provide only
276 * the command part of the IR code. Yet, as it is possible to replace
277 * the provided IR with another one, it is needed to allow loading
278 * IR tables from other remotes. So, we support specifying a mask to
279 * indicate the valid bits of the scancodes.
280 */
281 if (dev->scanmask)
282 scancode &= dev->scanmask;
283
284 /* First check if we already have a mapping for this ir command */
285 for (i = 0; i < rc_map->len; i++) {
286 if (rc_map->scan[i].scancode == scancode)
287 return i;
288
289 /* Keytable is sorted from lowest to highest scancode */
290 if (rc_map->scan[i].scancode >= scancode)
291 break;
292 }
293
294 /* No previous mapping found, we might need to grow the table */
295 if (rc_map->size == rc_map->len) {
296 if (!resize || ir_resize_table(rc_map, GFP_ATOMIC))
297 return -1U;
298 }
299
300 /* i is the proper index to insert our new keycode */
301 if (i < rc_map->len)
302 memmove(&rc_map->scan[i + 1], &rc_map->scan[i],
303 (rc_map->len - i) * sizeof(struct rc_map_table));
304 rc_map->scan[i].scancode = scancode;
305 rc_map->scan[i].keycode = KEY_RESERVED;
306 rc_map->len++;
307
308 return i;
309}
310
311/**
312 * ir_setkeycode() - set a keycode in the scancode->keycode table
313 * @idev: the struct input_dev device descriptor
314 * @scancode: the desired scancode
315 * @keycode: result
316 * @return: -EINVAL if the keycode could not be inserted, otherwise zero.
317 *
318 * This routine is used to handle evdev EVIOCSKEY ioctl.
319 */
320static int ir_setkeycode(struct input_dev *idev,
321 const struct input_keymap_entry *ke,
322 unsigned int *old_keycode)
323{
324 struct rc_dev *rdev = input_get_drvdata(idev);
325 struct rc_map *rc_map = &rdev->rc_map;
326 unsigned int index;
327 unsigned int scancode;
328 int retval = 0;
329 unsigned long flags;
330
331 spin_lock_irqsave(&rc_map->lock, flags);
332
333 if (ke->flags & INPUT_KEYMAP_BY_INDEX) {
334 index = ke->index;
335 if (index >= rc_map->len) {
336 retval = -EINVAL;
337 goto out;
338 }
339 } else {
340 retval = input_scancode_to_scalar(ke, &scancode);
341 if (retval)
342 goto out;
343
344 index = ir_establish_scancode(rdev, rc_map, scancode, true);
345 if (index >= rc_map->len) {
346 retval = -ENOMEM;
347 goto out;
348 }
349 }
350
351 *old_keycode = ir_update_mapping(rdev, rc_map, index, ke->keycode);
352
353out:
354 spin_unlock_irqrestore(&rc_map->lock, flags);
355 return retval;
356}
357
358/**
359 * ir_setkeytable() - sets several entries in the scancode->keycode table
360 * @dev: the struct rc_dev device descriptor
361 * @to: the struct rc_map to copy entries to
362 * @from: the struct rc_map to copy entries from
363 * @return: -ENOMEM if all keycodes could not be inserted, otherwise zero.
364 *
365 * This routine is used to handle table initialization.
366 */
367static int ir_setkeytable(struct rc_dev *dev,
368 const struct rc_map *from)
369{
370 struct rc_map *rc_map = &dev->rc_map;
371 unsigned int i, index;
372 int rc;
373
374 rc = ir_create_table(rc_map, from->name,
375 from->rc_type, from->size);
376 if (rc)
377 return rc;
378
379 IR_dprintk(1, "Allocated space for %u keycode entries (%u bytes)\n",
380 rc_map->size, rc_map->alloc);
381
382 for (i = 0; i < from->size; i++) {
383 index = ir_establish_scancode(dev, rc_map,
384 from->scan[i].scancode, false);
385 if (index >= rc_map->len) {
386 rc = -ENOMEM;
387 break;
388 }
389
390 ir_update_mapping(dev, rc_map, index,
391 from->scan[i].keycode);
392 }
393
394 if (rc)
395 ir_free_table(rc_map);
396
397 return rc;
398}
399
400/**
401 * ir_lookup_by_scancode() - locate mapping by scancode
402 * @rc_map: the struct rc_map to search
403 * @scancode: scancode to look for in the table
404 * @return: index in the table, -1U if not found
405 *
406 * This routine performs binary search in RC keykeymap table for
407 * given scancode.
408 */
409static unsigned int ir_lookup_by_scancode(const struct rc_map *rc_map,
410 unsigned int scancode)
411{
412 int start = 0;
413 int end = rc_map->len - 1;
414 int mid;
415
416 while (start <= end) {
417 mid = (start + end) / 2;
418 if (rc_map->scan[mid].scancode < scancode)
419 start = mid + 1;
420 else if (rc_map->scan[mid].scancode > scancode)
421 end = mid - 1;
422 else
423 return mid;
424 }
425
426 return -1U;
427}
428
429/**
430 * ir_getkeycode() - get a keycode from the scancode->keycode table
431 * @idev: the struct input_dev device descriptor
432 * @scancode: the desired scancode
433 * @keycode: used to return the keycode, if found, or KEY_RESERVED
434 * @return: always returns zero.
435 *
436 * This routine is used to handle evdev EVIOCGKEY ioctl.
437 */
438static int ir_getkeycode(struct input_dev *idev,
439 struct input_keymap_entry *ke)
440{
441 struct rc_dev *rdev = input_get_drvdata(idev);
442 struct rc_map *rc_map = &rdev->rc_map;
443 struct rc_map_table *entry;
444 unsigned long flags;
445 unsigned int index;
446 unsigned int scancode;
447 int retval;
448
449 spin_lock_irqsave(&rc_map->lock, flags);
450
451 if (ke->flags & INPUT_KEYMAP_BY_INDEX) {
452 index = ke->index;
453 } else {
454 retval = input_scancode_to_scalar(ke, &scancode);
455 if (retval)
456 goto out;
457
458 index = ir_lookup_by_scancode(rc_map, scancode);
459 }
460
461 if (index >= rc_map->len) {
462 if (!(ke->flags & INPUT_KEYMAP_BY_INDEX))
463 IR_dprintk(1, "unknown key for scancode 0x%04x\n",
464 scancode);
465 retval = -EINVAL;
466 goto out;
467 }
468
469 entry = &rc_map->scan[index];
470
471 ke->index = index;
472 ke->keycode = entry->keycode;
473 ke->len = sizeof(entry->scancode);
474 memcpy(ke->scancode, &entry->scancode, sizeof(entry->scancode));
475
476 retval = 0;
477
478out:
479 spin_unlock_irqrestore(&rc_map->lock, flags);
480 return retval;
481}
482
483/**
484 * rc_g_keycode_from_table() - gets the keycode that corresponds to a scancode
485 * @dev: the struct rc_dev descriptor of the device
486 * @scancode: the scancode to look for
487 * @return: the corresponding keycode, or KEY_RESERVED
488 *
489 * This routine is used by drivers which need to convert a scancode to a
490 * keycode. Normally it should not be used since drivers should have no
491 * interest in keycodes.
492 */
493u32 rc_g_keycode_from_table(struct rc_dev *dev, u32 scancode)
494{
495 struct rc_map *rc_map = &dev->rc_map;
496 unsigned int keycode;
497 unsigned int index;
498 unsigned long flags;
499
500 spin_lock_irqsave(&rc_map->lock, flags);
501
502 index = ir_lookup_by_scancode(rc_map, scancode);
503 keycode = index < rc_map->len ?
504 rc_map->scan[index].keycode : KEY_RESERVED;
505
506 spin_unlock_irqrestore(&rc_map->lock, flags);
507
508 if (keycode != KEY_RESERVED)
509 IR_dprintk(1, "%s: scancode 0x%04x keycode 0x%02x\n",
510 dev->input_name, scancode, keycode);
511
512 return keycode;
513}
514EXPORT_SYMBOL_GPL(rc_g_keycode_from_table);
515
516/**
517 * ir_do_keyup() - internal function to signal the release of a keypress
518 * @dev: the struct rc_dev descriptor of the device
519 *
520 * This function is used internally to release a keypress, it must be
521 * called with keylock held.
522 */
523static void ir_do_keyup(struct rc_dev *dev)
524{
525 if (!dev->keypressed)
526 return;
527
528 IR_dprintk(1, "keyup key 0x%04x\n", dev->last_keycode);
529 input_report_key(dev->input_dev, dev->last_keycode, 0);
530 input_sync(dev->input_dev);
531 dev->keypressed = false;
532}
533
534/**
535 * rc_keyup() - signals the release of a keypress
536 * @dev: the struct rc_dev descriptor of the device
537 *
538 * This routine is used to signal that a key has been released on the
539 * remote control.
540 */
541void rc_keyup(struct rc_dev *dev)
542{
543 unsigned long flags;
544
545 spin_lock_irqsave(&dev->keylock, flags);
546 ir_do_keyup(dev);
547 spin_unlock_irqrestore(&dev->keylock, flags);
548}
549EXPORT_SYMBOL_GPL(rc_keyup);
550
551/**
552 * ir_timer_keyup() - generates a keyup event after a timeout
553 * @cookie: a pointer to the struct rc_dev for the device
554 *
555 * This routine will generate a keyup event some time after a keydown event
556 * is generated when no further activity has been detected.
557 */
558static void ir_timer_keyup(unsigned long cookie)
559{
560 struct rc_dev *dev = (struct rc_dev *)cookie;
561 unsigned long flags;
562
563 /*
564 * ir->keyup_jiffies is used to prevent a race condition if a
565 * hardware interrupt occurs at this point and the keyup timer
566 * event is moved further into the future as a result.
567 *
568 * The timer will then be reactivated and this function called
569 * again in the future. We need to exit gracefully in that case
570 * to allow the input subsystem to do its auto-repeat magic or
571 * a keyup event might follow immediately after the keydown.
572 */
573 spin_lock_irqsave(&dev->keylock, flags);
574 if (time_is_before_eq_jiffies(dev->keyup_jiffies))
575 ir_do_keyup(dev);
576 spin_unlock_irqrestore(&dev->keylock, flags);
577}
578
579/**
580 * rc_repeat() - signals that a key is still pressed
581 * @dev: the struct rc_dev descriptor of the device
582 *
583 * This routine is used by IR decoders when a repeat message which does
584 * not include the necessary bits to reproduce the scancode has been
585 * received.
586 */
587void rc_repeat(struct rc_dev *dev)
588{
589 unsigned long flags;
590
591 spin_lock_irqsave(&dev->keylock, flags);
592
593 input_event(dev->input_dev, EV_MSC, MSC_SCAN, dev->last_scancode);
594
595 if (!dev->keypressed)
596 goto out;
597
598 dev->keyup_jiffies = jiffies + msecs_to_jiffies(IR_KEYPRESS_TIMEOUT);
599 mod_timer(&dev->timer_keyup, dev->keyup_jiffies);
600
601out:
602 spin_unlock_irqrestore(&dev->keylock, flags);
603}
604EXPORT_SYMBOL_GPL(rc_repeat);
605
606/**
607 * ir_do_keydown() - internal function to process a keypress
608 * @dev: the struct rc_dev descriptor of the device
609 * @scancode: the scancode of the keypress
610 * @keycode: the keycode of the keypress
611 * @toggle: the toggle value of the keypress
612 *
613 * This function is used internally to register a keypress, it must be
614 * called with keylock held.
615 */
616static void ir_do_keydown(struct rc_dev *dev, int scancode,
617 u32 keycode, u8 toggle)
618{
619 input_event(dev->input_dev, EV_MSC, MSC_SCAN, scancode);
620
621 /* Repeat event? */
622 if (dev->keypressed &&
623 dev->last_scancode == scancode &&
624 dev->last_toggle == toggle)
625 return;
626
627 /* Release old keypress */
628 ir_do_keyup(dev);
629
630 dev->last_scancode = scancode;
631 dev->last_toggle = toggle;
632 dev->last_keycode = keycode;
633
634 if (keycode == KEY_RESERVED)
635 return;
636
637 /* Register a keypress */
638 dev->keypressed = true;
639 IR_dprintk(1, "%s: key down event, key 0x%04x, scancode 0x%04x\n",
640 dev->input_name, keycode, scancode);
641 input_report_key(dev->input_dev, dev->last_keycode, 1);
642 input_sync(dev->input_dev);
643}
644
645/**
646 * rc_keydown() - generates input event for a key press
647 * @dev: the struct rc_dev descriptor of the device
648 * @scancode: the scancode that we're seeking
649 * @toggle: the toggle value (protocol dependent, if the protocol doesn't
650 * support toggle values, this should be set to zero)
651 *
652 * This routine is used to signal that a key has been pressed on the
653 * remote control.
654 */
655void rc_keydown(struct rc_dev *dev, int scancode, u8 toggle)
656{
657 unsigned long flags;
658 u32 keycode = rc_g_keycode_from_table(dev, scancode);
659
660 spin_lock_irqsave(&dev->keylock, flags);
661 ir_do_keydown(dev, scancode, keycode, toggle);
662
663 if (dev->keypressed) {
664 dev->keyup_jiffies = jiffies + msecs_to_jiffies(IR_KEYPRESS_TIMEOUT);
665 mod_timer(&dev->timer_keyup, dev->keyup_jiffies);
666 }
667 spin_unlock_irqrestore(&dev->keylock, flags);
668}
669EXPORT_SYMBOL_GPL(rc_keydown);
670
671/**
672 * rc_keydown_notimeout() - generates input event for a key press without
673 * an automatic keyup event at a later time
674 * @dev: the struct rc_dev descriptor of the device
675 * @scancode: the scancode that we're seeking
676 * @toggle: the toggle value (protocol dependent, if the protocol doesn't
677 * support toggle values, this should be set to zero)
678 *
679 * This routine is used to signal that a key has been pressed on the
680 * remote control. The driver must manually call rc_keyup() at a later stage.
681 */
682void rc_keydown_notimeout(struct rc_dev *dev, int scancode, u8 toggle)
683{
684 unsigned long flags;
685 u32 keycode = rc_g_keycode_from_table(dev, scancode);
686
687 spin_lock_irqsave(&dev->keylock, flags);
688 ir_do_keydown(dev, scancode, keycode, toggle);
689 spin_unlock_irqrestore(&dev->keylock, flags);
690}
691EXPORT_SYMBOL_GPL(rc_keydown_notimeout);
692
693static int ir_open(struct input_dev *idev)
694{
695 struct rc_dev *rdev = input_get_drvdata(idev);
696
697 return rdev->open(rdev);
698}
699
700static void ir_close(struct input_dev *idev)
701{
702 struct rc_dev *rdev = input_get_drvdata(idev);
703
704 rdev->close(rdev);
705}
706
707/* class for /sys/class/rc */
708static char *ir_devnode(struct device *dev, mode_t *mode)
709{
710 return kasprintf(GFP_KERNEL, "rc/%s", dev_name(dev));
711}
712
713static struct class ir_input_class = {
714 .name = "rc",
715 .devnode = ir_devnode,
716};
717
718static struct {
719 u64 type;
720 char *name;
721} proto_names[] = {
722 { RC_TYPE_UNKNOWN, "unknown" },
723 { RC_TYPE_RC5, "rc-5" },
724 { RC_TYPE_NEC, "nec" },
725 { RC_TYPE_RC6, "rc-6" },
726 { RC_TYPE_JVC, "jvc" },
727 { RC_TYPE_SONY, "sony" },
728 { RC_TYPE_RC5_SZ, "rc-5-sz" },
729 { RC_TYPE_LIRC, "lirc" },
730};
731
732#define PROTO_NONE "none"
733
734/**
735 * show_protocols() - shows the current IR protocol(s)
736 * @device: the device descriptor
737 * @mattr: the device attribute struct (unused)
738 * @buf: a pointer to the output buffer
739 *
740 * This routine is a callback routine for input read the IR protocol type(s).
741 * it is trigged by reading /sys/class/rc/rc?/protocols.
742 * It returns the protocol names of supported protocols.
743 * Enabled protocols are printed in brackets.
744 */
745static ssize_t show_protocols(struct device *device,
746 struct device_attribute *mattr, char *buf)
747{
748 struct rc_dev *dev = to_rc_dev(device);
749 u64 allowed, enabled;
750 char *tmp = buf;
751 int i;
752
753 /* Device is being removed */
754 if (!dev)
755 return -EINVAL;
756
757 if (dev->driver_type == RC_DRIVER_SCANCODE) {
758 enabled = dev->rc_map.rc_type;
759 allowed = dev->allowed_protos;
760 } else {
761 enabled = dev->raw->enabled_protocols;
762 allowed = ir_raw_get_allowed_protocols();
763 }
764
765 IR_dprintk(1, "allowed - 0x%llx, enabled - 0x%llx\n",
766 (long long)allowed,
767 (long long)enabled);
768
769 for (i = 0; i < ARRAY_SIZE(proto_names); i++) {
770 if (allowed & enabled & proto_names[i].type)
771 tmp += sprintf(tmp, "[%s] ", proto_names[i].name);
772 else if (allowed & proto_names[i].type)
773 tmp += sprintf(tmp, "%s ", proto_names[i].name);
774 }
775
776 if (tmp != buf)
777 tmp--;
778 *tmp = '\n';
779 return tmp + 1 - buf;
780}
781
782/**
783 * store_protocols() - changes the current IR protocol(s)
784 * @device: the device descriptor
785 * @mattr: the device attribute struct (unused)
786 * @buf: a pointer to the input buffer
787 * @len: length of the input buffer
788 *
789 * This routine is for changing the IR protocol type.
790 * It is trigged by writing to /sys/class/rc/rc?/protocols.
791 * Writing "+proto" will add a protocol to the list of enabled protocols.
792 * Writing "-proto" will remove a protocol from the list of enabled protocols.
793 * Writing "proto" will enable only "proto".
794 * Writing "none" will disable all protocols.
795 * Returns -EINVAL if an invalid protocol combination or unknown protocol name
796 * is used, otherwise @len.
797 */
798static ssize_t store_protocols(struct device *device,
799 struct device_attribute *mattr,
800 const char *data,
801 size_t len)
802{
803 struct rc_dev *dev = to_rc_dev(device);
804 bool enable, disable;
805 const char *tmp;
806 u64 type;
807 u64 mask;
808 int rc, i, count = 0;
809 unsigned long flags;
810
811 /* Device is being removed */
812 if (!dev)
813 return -EINVAL;
814
815 if (dev->driver_type == RC_DRIVER_SCANCODE)
816 type = dev->rc_map.rc_type;
817 else if (dev->raw)
818 type = dev->raw->enabled_protocols;
819 else {
820 IR_dprintk(1, "Protocol switching not supported\n");
821 return -EINVAL;
822 }
823
824 while ((tmp = strsep((char **) &data, " \n")) != NULL) {
825 if (!*tmp)
826 break;
827
828 if (*tmp == '+') {
829 enable = true;
830 disable = false;
831 tmp++;
832 } else if (*tmp == '-') {
833 enable = false;
834 disable = true;
835 tmp++;
836 } else {
837 enable = false;
838 disable = false;
839 }
840
841 if (!enable && !disable && !strncasecmp(tmp, PROTO_NONE, sizeof(PROTO_NONE))) {
842 tmp += sizeof(PROTO_NONE);
843 mask = 0;
844 count++;
845 } else {
846 for (i = 0; i < ARRAY_SIZE(proto_names); i++) {
847 if (!strncasecmp(tmp, proto_names[i].name, strlen(proto_names[i].name))) {
848 tmp += strlen(proto_names[i].name);
849 mask = proto_names[i].type;
850 break;
851 }
852 }
853 if (i == ARRAY_SIZE(proto_names)) {
854 IR_dprintk(1, "Unknown protocol: '%s'\n", tmp);
855 return -EINVAL;
856 }
857 count++;
858 }
859
860 if (enable)
861 type |= mask;
862 else if (disable)
863 type &= ~mask;
864 else
865 type = mask;
866 }
867
868 if (!count) {
869 IR_dprintk(1, "Protocol not specified\n");
870 return -EINVAL;
871 }
872
873 if (dev->change_protocol) {
874 rc = dev->change_protocol(dev, type);
875 if (rc < 0) {
876 IR_dprintk(1, "Error setting protocols to 0x%llx\n",
877 (long long)type);
878 return -EINVAL;
879 }
880 }
881
882 if (dev->driver_type == RC_DRIVER_SCANCODE) {
883 spin_lock_irqsave(&dev->rc_map.lock, flags);
884 dev->rc_map.rc_type = type;
885 spin_unlock_irqrestore(&dev->rc_map.lock, flags);
886 } else {
887 dev->raw->enabled_protocols = type;
888 }
889
890 IR_dprintk(1, "Current protocol(s): 0x%llx\n",
891 (long long)type);
892
893 return len;
894}
895
896static void rc_dev_release(struct device *device)
897{
898 struct rc_dev *dev = to_rc_dev(device);
899
900 kfree(dev);
901 module_put(THIS_MODULE);
902}
903
904#define ADD_HOTPLUG_VAR(fmt, val...) \
905 do { \
906 int err = add_uevent_var(env, fmt, val); \
907 if (err) \
908 return err; \
909 } while (0)
910
911static int rc_dev_uevent(struct device *device, struct kobj_uevent_env *env)
912{
913 struct rc_dev *dev = to_rc_dev(device);
914
915 if (dev->rc_map.name)
916 ADD_HOTPLUG_VAR("NAME=%s", dev->rc_map.name);
917 if (dev->driver_name)
918 ADD_HOTPLUG_VAR("DRV_NAME=%s", dev->driver_name);
919
920 return 0;
921}
922
923/*
924 * Static device attribute struct with the sysfs attributes for IR's
925 */
926static DEVICE_ATTR(protocols, S_IRUGO | S_IWUSR,
927 show_protocols, store_protocols);
928
929static struct attribute *rc_dev_attrs[] = {
930 &dev_attr_protocols.attr,
931 NULL,
932};
933
934static struct attribute_group rc_dev_attr_grp = {
935 .attrs = rc_dev_attrs,
936};
937
938static const struct attribute_group *rc_dev_attr_groups[] = {
939 &rc_dev_attr_grp,
940 NULL
941};
942
943static struct device_type rc_dev_type = {
944 .groups = rc_dev_attr_groups,
945 .release = rc_dev_release,
946 .uevent = rc_dev_uevent,
947};
948
949struct rc_dev *rc_allocate_device(void)
950{
951 struct rc_dev *dev;
952
953 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
954 if (!dev)
955 return NULL;
956
957 dev->input_dev = input_allocate_device();
958 if (!dev->input_dev) {
959 kfree(dev);
960 return NULL;
961 }
962
963 dev->input_dev->getkeycode_new = ir_getkeycode;
964 dev->input_dev->setkeycode_new = ir_setkeycode;
965 input_set_drvdata(dev->input_dev, dev);
966
967 spin_lock_init(&dev->rc_map.lock);
968 spin_lock_init(&dev->keylock);
969 setup_timer(&dev->timer_keyup, ir_timer_keyup, (unsigned long)dev);
970
971 dev->dev.type = &rc_dev_type;
972 dev->dev.class = &ir_input_class;
973 device_initialize(&dev->dev);
974
975 __module_get(THIS_MODULE);
976 return dev;
977}
978EXPORT_SYMBOL_GPL(rc_allocate_device);
979
980void rc_free_device(struct rc_dev *dev)
981{
982 if (dev) {
983 input_free_device(dev->input_dev);
984 put_device(&dev->dev);
985 }
986}
987EXPORT_SYMBOL_GPL(rc_free_device);
988
989int rc_register_device(struct rc_dev *dev)
990{
991 static atomic_t devno = ATOMIC_INIT(0);
992 struct rc_map *rc_map;
993 const char *path;
994 int rc;
995
996 if (!dev || !dev->map_name)
997 return -EINVAL;
998
999 rc_map = rc_map_get(dev->map_name);
1000 if (!rc_map)
1001 rc_map = rc_map_get(RC_MAP_EMPTY);
1002 if (!rc_map || !rc_map->scan || rc_map->size == 0)
1003 return -EINVAL;
1004
1005 set_bit(EV_KEY, dev->input_dev->evbit);
1006 set_bit(EV_REP, dev->input_dev->evbit);
1007 set_bit(EV_MSC, dev->input_dev->evbit);
1008 set_bit(MSC_SCAN, dev->input_dev->mscbit);
1009 if (dev->open)
1010 dev->input_dev->open = ir_open;
1011 if (dev->close)
1012 dev->input_dev->close = ir_close;
1013
1014 dev->devno = (unsigned long)(atomic_inc_return(&devno) - 1);
1015 dev_set_name(&dev->dev, "rc%ld", dev->devno);
1016 dev_set_drvdata(&dev->dev, dev);
1017 rc = device_add(&dev->dev);
1018 if (rc)
1019 return rc;
1020
1021 rc = ir_setkeytable(dev, rc_map);
1022 if (rc)
1023 goto out_dev;
1024
1025 dev->input_dev->dev.parent = &dev->dev;
1026 memcpy(&dev->input_dev->id, &dev->input_id, sizeof(dev->input_id));
1027 dev->input_dev->phys = dev->input_phys;
1028 dev->input_dev->name = dev->input_name;
1029 rc = input_register_device(dev->input_dev);
1030 if (rc)
1031 goto out_table;
1032
1033 /*
1034 * Default delay of 250ms is too short for some protocols, expecially
1035 * since the timeout is currently set to 250ms. Increase it to 500ms,
1036 * to avoid wrong repetition of the keycodes. Note that this must be
1037 * set after the call to input_register_device().
1038 */
1039 dev->input_dev->rep[REP_DELAY] = 500;
1040
1041 path = kobject_get_path(&dev->dev.kobj, GFP_KERNEL);
1042 printk(KERN_INFO "%s: %s as %s\n",
1043 dev_name(&dev->dev),
1044 dev->input_name ? dev->input_name : "Unspecified device",
1045 path ? path : "N/A");
1046 kfree(path);
1047
1048 if (dev->driver_type == RC_DRIVER_IR_RAW) {
1049 rc = ir_raw_event_register(dev);
1050 if (rc < 0)
1051 goto out_input;
1052 }
1053
1054 if (dev->change_protocol) {
1055 rc = dev->change_protocol(dev, rc_map->rc_type);
1056 if (rc < 0)
1057 goto out_raw;
1058 }
1059
1060 IR_dprintk(1, "Registered rc%ld (driver: %s, remote: %s, mode %s)\n",
1061 dev->devno,
1062 dev->driver_name ? dev->driver_name : "unknown",
1063 rc_map->name ? rc_map->name : "unknown",
1064 dev->driver_type == RC_DRIVER_IR_RAW ? "raw" : "cooked");
1065
1066 return 0;
1067
1068out_raw:
1069 if (dev->driver_type == RC_DRIVER_IR_RAW)
1070 ir_raw_event_unregister(dev);
1071out_input:
1072 input_unregister_device(dev->input_dev);
1073 dev->input_dev = NULL;
1074out_table:
1075 ir_free_table(&dev->rc_map);
1076out_dev:
1077 device_del(&dev->dev);
1078 return rc;
1079}
1080EXPORT_SYMBOL_GPL(rc_register_device);
1081
1082void rc_unregister_device(struct rc_dev *dev)
1083{
1084 if (!dev)
1085 return;
1086
1087 del_timer_sync(&dev->timer_keyup);
1088
1089 if (dev->driver_type == RC_DRIVER_IR_RAW)
1090 ir_raw_event_unregister(dev);
1091
1092 input_unregister_device(dev->input_dev);
1093 dev->input_dev = NULL;
1094
1095 ir_free_table(&dev->rc_map);
1096 IR_dprintk(1, "Freed keycode table\n");
1097
1098 device_unregister(&dev->dev);
1099}
1100EXPORT_SYMBOL_GPL(rc_unregister_device);
1101
1102/*
1103 * Init/exit code for the module. Basically, creates/removes /sys/class/rc
1104 */
1105
1106static int __init rc_core_init(void)
1107{
1108 int rc = class_register(&ir_input_class);
1109 if (rc) {
1110 printk(KERN_ERR "rc_core: unable to register rc class\n");
1111 return rc;
1112 }
1113
1114 /* Initialize/load the decoders/keymap code that will be used */
1115 ir_raw_init();
1116 rc_map_register(&empty_map);
1117
1118 return 0;
1119}
1120
1121static void __exit rc_core_exit(void)
1122{
1123 class_unregister(&ir_input_class);
1124 rc_map_unregister(&empty_map);
1125}
1126
1127module_init(rc_core_init);
1128module_exit(rc_core_exit);
1129
1130int rc_core_debug; /* ir_debug level (0,1,2) */
1131EXPORT_SYMBOL_GPL(rc_core_debug);
1132module_param_named(debug, rc_core_debug, int, 0644);
1133
1134MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
1135MODULE_LICENSE("GPL");
diff --git a/drivers/media/IR/streamzap.c b/drivers/media/rc/streamzap.c
index 3a20aef67d08..6e2911c2abfb 100644
--- a/drivers/media/IR/streamzap.c
+++ b/drivers/media/rc/streamzap.c
@@ -34,10 +34,9 @@
34#include <linux/device.h> 34#include <linux/device.h>
35#include <linux/module.h> 35#include <linux/module.h>
36#include <linux/slab.h> 36#include <linux/slab.h>
37#include <linux/input.h>
38#include <linux/usb.h> 37#include <linux/usb.h>
39#include <linux/usb/input.h> 38#include <linux/usb/input.h>
40#include <media/ir-core.h> 39#include <media/rc-core.h>
41 40
42#define DRIVER_VERSION "1.61" 41#define DRIVER_VERSION "1.61"
43#define DRIVER_NAME "streamzap" 42#define DRIVER_NAME "streamzap"
@@ -74,7 +73,7 @@ MODULE_DEVICE_TABLE(usb, streamzap_table);
74#ifdef CONFIG_IR_RC5_SZ_DECODER_MODULE 73#ifdef CONFIG_IR_RC5_SZ_DECODER_MODULE
75#define load_rc5_sz_decode() request_module("ir-rc5-sz-decoder") 74#define load_rc5_sz_decode() request_module("ir-rc5-sz-decoder")
76#else 75#else
77#define load_rc5_sz_decode() 0 76#define load_rc5_sz_decode() {}
78#endif 77#endif
79 78
80enum StreamzapDecoderState { 79enum StreamzapDecoderState {
@@ -86,13 +85,11 @@ enum StreamzapDecoderState {
86 85
87/* structure to hold our device specific stuff */ 86/* structure to hold our device specific stuff */
88struct streamzap_ir { 87struct streamzap_ir {
89
90 /* ir-core */ 88 /* ir-core */
91 struct ir_dev_props *props; 89 struct rc_dev *rdev;
92 90
93 /* core device info */ 91 /* core device info */
94 struct device *dev; 92 struct device *dev;
95 struct input_dev *idev;
96 93
97 /* usb */ 94 /* usb */
98 struct usb_device *usbdev; 95 struct usb_device *usbdev;
@@ -143,7 +140,7 @@ static void sz_push(struct streamzap_ir *sz, struct ir_raw_event rawir)
143{ 140{
144 dev_dbg(sz->dev, "Storing %s with duration %u us\n", 141 dev_dbg(sz->dev, "Storing %s with duration %u us\n",
145 (rawir.pulse ? "pulse" : "space"), rawir.duration); 142 (rawir.pulse ? "pulse" : "space"), rawir.duration);
146 ir_raw_event_store_with_filter(sz->idev, &rawir); 143 ir_raw_event_store_with_filter(sz->rdev, &rawir);
147} 144}
148 145
149static void sz_push_full_pulse(struct streamzap_ir *sz, 146static void sz_push_full_pulse(struct streamzap_ir *sz,
@@ -271,11 +268,11 @@ static void streamzap_callback(struct urb *urb)
271 DEFINE_IR_RAW_EVENT(rawir); 268 DEFINE_IR_RAW_EVENT(rawir);
272 269
273 rawir.pulse = false; 270 rawir.pulse = false;
274 rawir.duration = sz->props->timeout; 271 rawir.duration = sz->rdev->timeout;
275 sz->idle = true; 272 sz->idle = true;
276 if (sz->timeout_enabled) 273 if (sz->timeout_enabled)
277 sz_push(sz, rawir); 274 sz_push(sz, rawir);
278 ir_raw_event_handle(sz->idev); 275 ir_raw_event_handle(sz->rdev);
279 } else { 276 } else {
280 sz_push_full_space(sz, sz->buf_in[i]); 277 sz_push_full_space(sz, sz->buf_in[i]);
281 } 278 }
@@ -298,57 +295,45 @@ static void streamzap_callback(struct urb *urb)
298 return; 295 return;
299} 296}
300 297
301static struct input_dev *streamzap_init_input_dev(struct streamzap_ir *sz) 298static struct rc_dev *streamzap_init_rc_dev(struct streamzap_ir *sz)
302{ 299{
303 struct input_dev *idev; 300 struct rc_dev *rdev;
304 struct ir_dev_props *props;
305 struct device *dev = sz->dev; 301 struct device *dev = sz->dev;
306 int ret; 302 int ret;
307 303
308 idev = input_allocate_device(); 304 rdev = rc_allocate_device();
309 if (!idev) { 305 if (!rdev) {
310 dev_err(dev, "remote input dev allocation failed\n"); 306 dev_err(dev, "remote dev allocation failed\n");
311 goto idev_alloc_failed; 307 goto out;
312 }
313
314 props = kzalloc(sizeof(struct ir_dev_props), GFP_KERNEL);
315 if (!props) {
316 dev_err(dev, "remote ir dev props allocation failed\n");
317 goto props_alloc_failed;
318 } 308 }
319 309
320 snprintf(sz->name, sizeof(sz->name), "Streamzap PC Remote Infrared " 310 snprintf(sz->name, sizeof(sz->name), "Streamzap PC Remote Infrared "
321 "Receiver (%04x:%04x)", 311 "Receiver (%04x:%04x)",
322 le16_to_cpu(sz->usbdev->descriptor.idVendor), 312 le16_to_cpu(sz->usbdev->descriptor.idVendor),
323 le16_to_cpu(sz->usbdev->descriptor.idProduct)); 313 le16_to_cpu(sz->usbdev->descriptor.idProduct));
324
325 idev->name = sz->name;
326 usb_make_path(sz->usbdev, sz->phys, sizeof(sz->phys)); 314 usb_make_path(sz->usbdev, sz->phys, sizeof(sz->phys));
327 strlcat(sz->phys, "/input0", sizeof(sz->phys)); 315 strlcat(sz->phys, "/input0", sizeof(sz->phys));
328 idev->phys = sz->phys;
329
330 props->priv = sz;
331 props->driver_type = RC_DRIVER_IR_RAW;
332 props->allowed_protos = IR_TYPE_ALL;
333
334 sz->props = props;
335
336 usb_to_input_id(sz->usbdev, &idev->id);
337 idev->dev.parent = sz->dev;
338 316
339 ret = ir_input_register(idev, RC_MAP_STREAMZAP, props, DRIVER_NAME); 317 rdev->input_name = sz->name;
318 rdev->input_phys = sz->phys;
319 usb_to_input_id(sz->usbdev, &rdev->input_id);
320 rdev->dev.parent = dev;
321 rdev->priv = sz;
322 rdev->driver_type = RC_DRIVER_IR_RAW;
323 rdev->allowed_protos = RC_TYPE_ALL;
324 rdev->driver_name = DRIVER_NAME;
325 rdev->map_name = RC_MAP_STREAMZAP;
326
327 ret = rc_register_device(rdev);
340 if (ret < 0) { 328 if (ret < 0) {
341 dev_err(dev, "remote input device register failed\n"); 329 dev_err(dev, "remote input device register failed\n");
342 goto irdev_failed; 330 goto out;
343 } 331 }
344 332
345 return idev; 333 return rdev;
346 334
347irdev_failed: 335out:
348 kfree(props); 336 rc_free_device(rdev);
349props_alloc_failed:
350 input_free_device(idev);
351idev_alloc_failed:
352 return NULL; 337 return NULL;
353} 338}
354 339
@@ -437,15 +422,15 @@ static int __devinit streamzap_probe(struct usb_interface *intf,
437 snprintf(name + strlen(name), sizeof(name) - strlen(name), 422 snprintf(name + strlen(name), sizeof(name) - strlen(name),
438 " %s", buf); 423 " %s", buf);
439 424
440 sz->idev = streamzap_init_input_dev(sz); 425 sz->rdev = streamzap_init_rc_dev(sz);
441 if (!sz->idev) 426 if (!sz->rdev)
442 goto input_dev_fail; 427 goto rc_dev_fail;
443 428
444 sz->idle = true; 429 sz->idle = true;
445 sz->decoder_state = PulseSpace; 430 sz->decoder_state = PulseSpace;
446 /* FIXME: don't yet have a way to set this */ 431 /* FIXME: don't yet have a way to set this */
447 sz->timeout_enabled = true; 432 sz->timeout_enabled = true;
448 sz->props->timeout = (((SZ_TIMEOUT * SZ_RESOLUTION * 1000) & 433 sz->rdev->timeout = (((SZ_TIMEOUT * SZ_RESOLUTION * 1000) &
449 IR_MAX_DURATION) | 0x03000000); 434 IR_MAX_DURATION) | 0x03000000);
450 #if 0 435 #if 0
451 /* not yet supported, depends on patches from maxim */ 436 /* not yet supported, depends on patches from maxim */
@@ -476,7 +461,7 @@ static int __devinit streamzap_probe(struct usb_interface *intf,
476 461
477 return 0; 462 return 0;
478 463
479input_dev_fail: 464rc_dev_fail:
480 usb_free_urb(sz->urb_in); 465 usb_free_urb(sz->urb_in);
481free_buf_in: 466free_buf_in:
482 usb_free_coherent(usbdev, maxp, sz->buf_in, sz->dma_in); 467 usb_free_coherent(usbdev, maxp, sz->buf_in, sz->dma_in);
@@ -507,7 +492,7 @@ static void streamzap_disconnect(struct usb_interface *interface)
507 return; 492 return;
508 493
509 sz->usbdev = NULL; 494 sz->usbdev = NULL;
510 ir_input_unregister(sz->idev); 495 rc_unregister_device(sz->rdev);
511 usb_kill_urb(sz->urb_in); 496 usb_kill_urb(sz->urb_in);
512 usb_free_urb(sz->urb_in); 497 usb_free_urb(sz->urb_in);
513 usb_free_coherent(usbdev, sz->buf_in_len, sz->buf_in, sz->dma_in); 498 usb_free_coherent(usbdev, sz->buf_in_len, sz->buf_in, sz->dma_in);
diff --git a/drivers/input/misc/winbond-cir.c b/drivers/media/rc/winbond-cir.c
index 64f1de7960c6..186de5522001 100644
--- a/drivers/input/misc/winbond-cir.c
+++ b/drivers/media/rc/winbond-cir.c
@@ -7,10 +7,10 @@
7 * with minor modifications. 7 * with minor modifications.
8 * 8 *
9 * Original Author: David Härdeman <david@hardeman.nu> 9 * Original Author: David Härdeman <david@hardeman.nu>
10 * Copyright (C) 2009 David Härdeman <david@hardeman.nu> 10 * Copyright (C) 2009 - 2010 David Härdeman <david@hardeman.nu>
11 * 11 *
12 * Dedicated to Matilda, my newborn daughter, without whose loving attention 12 * Dedicated to my daughter Matilda, without whose loving attention this
13 * this driver would have been finished in half the time and with a fraction 13 * driver would have been finished in half the time and with a fraction
14 * of the bugs. 14 * of the bugs.
15 * 15 *
16 * Written using: 16 * Written using:
@@ -19,15 +19,11 @@
19 * o DSDT dumps 19 * o DSDT dumps
20 * 20 *
21 * Supported features: 21 * Supported features:
22 * o RC6
23 * o Wake-On-CIR functionality 22 * o Wake-On-CIR functionality
24 * 23 *
25 * To do: 24 * To do:
26 * o Test NEC and RC5 25 * o Learning
27 * 26 * o IR Transmit
28 * Left as an exercise for the reader:
29 * o Learning (I have neither the hardware, nor the need)
30 * o IR Transmit (ibid)
31 * 27 *
32 * This program is free software; you can redistribute it and/or modify 28 * This program is free software; you can redistribute it and/or modify
33 * it under the terms of the GNU General Public License as published by 29 * it under the terms of the GNU General Public License as published by
@@ -48,15 +44,13 @@
48#include <linux/pnp.h> 44#include <linux/pnp.h>
49#include <linux/interrupt.h> 45#include <linux/interrupt.h>
50#include <linux/timer.h> 46#include <linux/timer.h>
51#include <linux/input.h>
52#include <linux/leds.h> 47#include <linux/leds.h>
53#include <linux/list.h>
54#include <linux/spinlock.h> 48#include <linux/spinlock.h>
55#include <linux/pci_ids.h> 49#include <linux/pci_ids.h>
56#include <linux/io.h> 50#include <linux/io.h>
57#include <linux/bitrev.h> 51#include <linux/bitrev.h>
58#include <linux/bitops.h>
59#include <linux/slab.h> 52#include <linux/slab.h>
53#include <media/rc-core.h>
60 54
61#define DRVNAME "winbond-cir" 55#define DRVNAME "winbond-cir"
62 56
@@ -108,7 +102,7 @@
108#define WBCIR_REG_SP3_IRCR2 0x04 /* Infrared Control 2 */ 102#define WBCIR_REG_SP3_IRCR2 0x04 /* Infrared Control 2 */
109 /* Bank 6 */ 103 /* Bank 6 */
110#define WBCIR_REG_SP3_IRCR3 0x00 /* Infrared Control 3 */ 104#define WBCIR_REG_SP3_IRCR3 0x00 /* Infrared Control 3 */
111#define WBCIR_REG_SP3_SIR_PW 0x02 /* SIR Pulse Width */ 105#define WBCIR_REG_SP3_SIR_PW 0x02 /* SIR Pulse Width */
112 /* Bank 7 */ 106 /* Bank 7 */
113#define WBCIR_REG_SP3_IRRXDC 0x00 /* IR RX Demod Control */ 107#define WBCIR_REG_SP3_IRRXDC 0x00 /* IR RX Demod Control */
114#define WBCIR_REG_SP3_IRTXMC 0x01 /* IR TX Mod Control */ 108#define WBCIR_REG_SP3_IRTXMC 0x01 /* IR TX Mod Control */
@@ -153,7 +147,7 @@ enum wbcir_bank {
153 WBCIR_BANK_7 = 0xF4, 147 WBCIR_BANK_7 = 0xF4,
154}; 148};
155 149
156/* Supported IR Protocols */ 150/* Supported power-on IR Protocols */
157enum wbcir_protocol { 151enum wbcir_protocol {
158 IR_PROTOCOL_RC5 = 0x0, 152 IR_PROTOCOL_RC5 = 0x0,
159 IR_PROTOCOL_NEC = 0x1, 153 IR_PROTOCOL_NEC = 0x1,
@@ -164,113 +158,35 @@ enum wbcir_protocol {
164#define WBCIR_NAME "Winbond CIR" 158#define WBCIR_NAME "Winbond CIR"
165#define WBCIR_ID_FAMILY 0xF1 /* Family ID for the WPCD376I */ 159#define WBCIR_ID_FAMILY 0xF1 /* Family ID for the WPCD376I */
166#define WBCIR_ID_CHIP 0x04 /* Chip ID for the WPCD376I */ 160#define WBCIR_ID_CHIP 0x04 /* Chip ID for the WPCD376I */
167#define IR_KEYPRESS_TIMEOUT 250 /* FIXME: should be per-protocol? */
168#define INVALID_SCANCODE 0x7FFFFFFF /* Invalid with all protos */ 161#define INVALID_SCANCODE 0x7FFFFFFF /* Invalid with all protos */
169#define WAKEUP_IOMEM_LEN 0x10 /* Wake-Up I/O Reg Len */ 162#define WAKEUP_IOMEM_LEN 0x10 /* Wake-Up I/O Reg Len */
170#define EHFUNC_IOMEM_LEN 0x10 /* Enhanced Func I/O Reg Len */ 163#define EHFUNC_IOMEM_LEN 0x10 /* Enhanced Func I/O Reg Len */
171#define SP_IOMEM_LEN 0x08 /* Serial Port 3 (IR) Reg Len */ 164#define SP_IOMEM_LEN 0x08 /* Serial Port 3 (IR) Reg Len */
172#define WBCIR_MAX_IDLE_BYTES 10
173
174static DEFINE_SPINLOCK(wbcir_lock);
175static DEFINE_RWLOCK(keytable_lock);
176 165
177struct wbcir_key { 166/* Per-device data */
178 u32 scancode;
179 unsigned int keycode;
180};
181
182struct wbcir_keyentry {
183 struct wbcir_key key;
184 struct list_head list;
185};
186
187static struct wbcir_key rc6_def_keymap[] = {
188 { 0x800F0400, KEY_NUMERIC_0 },
189 { 0x800F0401, KEY_NUMERIC_1 },
190 { 0x800F0402, KEY_NUMERIC_2 },
191 { 0x800F0403, KEY_NUMERIC_3 },
192 { 0x800F0404, KEY_NUMERIC_4 },
193 { 0x800F0405, KEY_NUMERIC_5 },
194 { 0x800F0406, KEY_NUMERIC_6 },
195 { 0x800F0407, KEY_NUMERIC_7 },
196 { 0x800F0408, KEY_NUMERIC_8 },
197 { 0x800F0409, KEY_NUMERIC_9 },
198 { 0x800F041D, KEY_NUMERIC_STAR },
199 { 0x800F041C, KEY_NUMERIC_POUND },
200 { 0x800F0410, KEY_VOLUMEUP },
201 { 0x800F0411, KEY_VOLUMEDOWN },
202 { 0x800F0412, KEY_CHANNELUP },
203 { 0x800F0413, KEY_CHANNELDOWN },
204 { 0x800F040E, KEY_MUTE },
205 { 0x800F040D, KEY_VENDOR }, /* Vista Logo Key */
206 { 0x800F041E, KEY_UP },
207 { 0x800F041F, KEY_DOWN },
208 { 0x800F0420, KEY_LEFT },
209 { 0x800F0421, KEY_RIGHT },
210 { 0x800F0422, KEY_OK },
211 { 0x800F0423, KEY_ESC },
212 { 0x800F040F, KEY_INFO },
213 { 0x800F040A, KEY_CLEAR },
214 { 0x800F040B, KEY_ENTER },
215 { 0x800F045B, KEY_RED },
216 { 0x800F045C, KEY_GREEN },
217 { 0x800F045D, KEY_YELLOW },
218 { 0x800F045E, KEY_BLUE },
219 { 0x800F045A, KEY_TEXT },
220 { 0x800F0427, KEY_SWITCHVIDEOMODE },
221 { 0x800F040C, KEY_POWER },
222 { 0x800F0450, KEY_RADIO },
223 { 0x800F0448, KEY_PVR },
224 { 0x800F0447, KEY_AUDIO },
225 { 0x800F0426, KEY_EPG },
226 { 0x800F0449, KEY_CAMERA },
227 { 0x800F0425, KEY_TV },
228 { 0x800F044A, KEY_VIDEO },
229 { 0x800F0424, KEY_DVD },
230 { 0x800F0416, KEY_PLAY },
231 { 0x800F0418, KEY_PAUSE },
232 { 0x800F0419, KEY_STOP },
233 { 0x800F0414, KEY_FASTFORWARD },
234 { 0x800F041A, KEY_NEXT },
235 { 0x800F041B, KEY_PREVIOUS },
236 { 0x800F0415, KEY_REWIND },
237 { 0x800F0417, KEY_RECORD },
238};
239
240/* Registers and other state is protected by wbcir_lock */
241struct wbcir_data { 167struct wbcir_data {
168 spinlock_t spinlock;
169
242 unsigned long wbase; /* Wake-Up Baseaddr */ 170 unsigned long wbase; /* Wake-Up Baseaddr */
243 unsigned long ebase; /* Enhanced Func. Baseaddr */ 171 unsigned long ebase; /* Enhanced Func. Baseaddr */
244 unsigned long sbase; /* Serial Port Baseaddr */ 172 unsigned long sbase; /* Serial Port Baseaddr */
245 unsigned int irq; /* Serial Port IRQ */ 173 unsigned int irq; /* Serial Port IRQ */
246 174
247 struct input_dev *input_dev; 175 struct rc_dev *dev;
248 struct timer_list timer_keyup; 176
249 struct led_trigger *rxtrigger; 177 struct led_trigger *rxtrigger;
250 struct led_trigger *txtrigger; 178 struct led_trigger *txtrigger;
251 struct led_classdev led; 179 struct led_classdev led;
252 180
253 u32 last_scancode; 181 /* RX irdata state */
254 unsigned int last_keycode; 182 bool irdata_active;
255 u8 last_toggle; 183 bool irdata_error;
256 u8 keypressed; 184 struct ir_raw_event ev;
257 unsigned long keyup_jiffies;
258 unsigned int idle_count;
259
260 /* RX irdata and parsing state */
261 unsigned long irdata[30];
262 unsigned int irdata_count;
263 unsigned int irdata_idle;
264 unsigned int irdata_off;
265 unsigned int irdata_error;
266
267 /* Protected by keytable_lock */
268 struct list_head keytable;
269}; 185};
270 186
271static enum wbcir_protocol protocol = IR_PROTOCOL_RC6; 187static enum wbcir_protocol protocol = IR_PROTOCOL_RC6;
272module_param(protocol, uint, 0444); 188module_param(protocol, uint, 0444);
273MODULE_PARM_DESC(protocol, "IR protocol to use " 189MODULE_PARM_DESC(protocol, "IR protocol to use for the power-on command "
274 "(0 = RC5, 1 = NEC, 2 = RC6A, default)"); 190 "(0 = RC5, 1 = NEC, 2 = RC6A, default)");
275 191
276static int invert; /* default = 0 */ 192static int invert; /* default = 0 */
@@ -327,7 +243,7 @@ wbcir_led_brightness_get(struct led_classdev *led_cdev)
327 243
328static void 244static void
329wbcir_led_brightness_set(struct led_classdev *led_cdev, 245wbcir_led_brightness_set(struct led_classdev *led_cdev,
330 enum led_brightness brightness) 246 enum led_brightness brightness)
331{ 247{
332 struct wbcir_data *data = container_of(led_cdev, 248 struct wbcir_data *data = container_of(led_cdev,
333 struct wbcir_data, 249 struct wbcir_data,
@@ -338,7 +254,7 @@ wbcir_led_brightness_set(struct led_classdev *led_cdev,
338 WBCIR_LED_ENABLE); 254 WBCIR_LED_ENABLE);
339} 255}
340 256
341/* Manchester encodes bits to RC6 message cells (see wbcir_parse_rc6) */ 257/* Manchester encodes bits to RC6 message cells (see wbcir_shutdown) */
342static u8 258static u8
343wbcir_to_rc6cells(u8 val) 259wbcir_to_rc6cells(u8 val)
344{ 260{
@@ -357,579 +273,6 @@ wbcir_to_rc6cells(u8 val)
357 return coded; 273 return coded;
358} 274}
359 275
360
361
362/*****************************************************************************
363 *
364 * INPUT FUNCTIONS
365 *
366 *****************************************************************************/
367
368static unsigned int
369wbcir_do_getkeycode(struct wbcir_data *data, u32 scancode)
370{
371 struct wbcir_keyentry *keyentry;
372 unsigned int keycode = KEY_RESERVED;
373 unsigned long flags;
374
375 read_lock_irqsave(&keytable_lock, flags);
376
377 list_for_each_entry(keyentry, &data->keytable, list) {
378 if (keyentry->key.scancode == scancode) {
379 keycode = keyentry->key.keycode;
380 break;
381 }
382 }
383
384 read_unlock_irqrestore(&keytable_lock, flags);
385 return keycode;
386}
387
388static int
389wbcir_getkeycode(struct input_dev *dev,
390 unsigned int scancode, unsigned int *keycode)
391{
392 struct wbcir_data *data = input_get_drvdata(dev);
393
394 *keycode = wbcir_do_getkeycode(data, scancode);
395 return 0;
396}
397
398static int
399wbcir_setkeycode(struct input_dev *dev,
400 unsigned int scancode, unsigned int keycode)
401{
402 struct wbcir_data *data = input_get_drvdata(dev);
403 struct wbcir_keyentry *keyentry;
404 struct wbcir_keyentry *new_keyentry;
405 unsigned long flags;
406 unsigned int old_keycode = KEY_RESERVED;
407
408 new_keyentry = kmalloc(sizeof(*new_keyentry), GFP_KERNEL);
409 if (!new_keyentry)
410 return -ENOMEM;
411
412 write_lock_irqsave(&keytable_lock, flags);
413
414 list_for_each_entry(keyentry, &data->keytable, list) {
415 if (keyentry->key.scancode != scancode)
416 continue;
417
418 old_keycode = keyentry->key.keycode;
419 keyentry->key.keycode = keycode;
420
421 if (keyentry->key.keycode == KEY_RESERVED) {
422 list_del(&keyentry->list);
423 kfree(keyentry);
424 }
425
426 break;
427 }
428
429 set_bit(keycode, dev->keybit);
430
431 if (old_keycode == KEY_RESERVED) {
432 new_keyentry->key.scancode = scancode;
433 new_keyentry->key.keycode = keycode;
434 list_add(&new_keyentry->list, &data->keytable);
435 } else {
436 kfree(new_keyentry);
437 clear_bit(old_keycode, dev->keybit);
438 list_for_each_entry(keyentry, &data->keytable, list) {
439 if (keyentry->key.keycode == old_keycode) {
440 set_bit(old_keycode, dev->keybit);
441 break;
442 }
443 }
444 }
445
446 write_unlock_irqrestore(&keytable_lock, flags);
447 return 0;
448}
449
450/*
451 * Timer function to report keyup event some time after keydown is
452 * reported by the ISR.
453 */
454static void
455wbcir_keyup(unsigned long cookie)
456{
457 struct wbcir_data *data = (struct wbcir_data *)cookie;
458 unsigned long flags;
459
460 /*
461 * data->keyup_jiffies is used to prevent a race condition if a
462 * hardware interrupt occurs at this point and the keyup timer
463 * event is moved further into the future as a result.
464 *
465 * The timer will then be reactivated and this function called
466 * again in the future. We need to exit gracefully in that case
467 * to allow the input subsystem to do its auto-repeat magic or
468 * a keyup event might follow immediately after the keydown.
469 */
470
471 spin_lock_irqsave(&wbcir_lock, flags);
472
473 if (time_is_after_eq_jiffies(data->keyup_jiffies) && data->keypressed) {
474 data->keypressed = 0;
475 led_trigger_event(data->rxtrigger, LED_OFF);
476 input_report_key(data->input_dev, data->last_keycode, 0);
477 input_sync(data->input_dev);
478 }
479
480 spin_unlock_irqrestore(&wbcir_lock, flags);
481}
482
483static void
484wbcir_keydown(struct wbcir_data *data, u32 scancode, u8 toggle)
485{
486 unsigned int keycode;
487
488 /* Repeat? */
489 if (data->last_scancode == scancode &&
490 data->last_toggle == toggle &&
491 data->keypressed)
492 goto set_timer;
493 data->last_scancode = scancode;
494
495 /* Do we need to release an old keypress? */
496 if (data->keypressed) {
497 input_report_key(data->input_dev, data->last_keycode, 0);
498 input_sync(data->input_dev);
499 data->keypressed = 0;
500 }
501
502 /* Report scancode */
503 input_event(data->input_dev, EV_MSC, MSC_SCAN, (int)scancode);
504
505 /* Do we know this scancode? */
506 keycode = wbcir_do_getkeycode(data, scancode);
507 if (keycode == KEY_RESERVED)
508 goto set_timer;
509
510 /* Register a keypress */
511 input_report_key(data->input_dev, keycode, 1);
512 data->keypressed = 1;
513 data->last_keycode = keycode;
514 data->last_toggle = toggle;
515
516set_timer:
517 input_sync(data->input_dev);
518 led_trigger_event(data->rxtrigger,
519 data->keypressed ? LED_FULL : LED_OFF);
520 data->keyup_jiffies = jiffies + msecs_to_jiffies(IR_KEYPRESS_TIMEOUT);
521 mod_timer(&data->timer_keyup, data->keyup_jiffies);
522}
523
524
525
526/*****************************************************************************
527 *
528 * IR PARSING FUNCTIONS
529 *
530 *****************************************************************************/
531
532/* Resets all irdata */
533static void
534wbcir_reset_irdata(struct wbcir_data *data)
535{
536 memset(data->irdata, 0, sizeof(data->irdata));
537 data->irdata_count = 0;
538 data->irdata_off = 0;
539 data->irdata_error = 0;
540 data->idle_count = 0;
541}
542
543/* Adds one bit of irdata */
544static void
545add_irdata_bit(struct wbcir_data *data, int set)
546{
547 if (data->irdata_count >= sizeof(data->irdata) * 8) {
548 data->irdata_error = 1;
549 return;
550 }
551
552 if (set)
553 __set_bit(data->irdata_count, data->irdata);
554 data->irdata_count++;
555}
556
557/* Gets count bits of irdata */
558static u16
559get_bits(struct wbcir_data *data, int count)
560{
561 u16 val = 0x0;
562
563 if (data->irdata_count - data->irdata_off < count) {
564 data->irdata_error = 1;
565 return 0x0;
566 }
567
568 while (count > 0) {
569 val <<= 1;
570 if (test_bit(data->irdata_off, data->irdata))
571 val |= 0x1;
572 count--;
573 data->irdata_off++;
574 }
575
576 return val;
577}
578
579/* Reads 16 cells and converts them to a byte */
580static u8
581wbcir_rc6cells_to_byte(struct wbcir_data *data)
582{
583 u16 raw = get_bits(data, 16);
584 u8 val = 0x00;
585 int bit;
586
587 for (bit = 0; bit < 8; bit++) {
588 switch (raw & 0x03) {
589 case 0x01:
590 break;
591 case 0x02:
592 val |= (0x01 << bit);
593 break;
594 default:
595 data->irdata_error = 1;
596 break;
597 }
598 raw >>= 2;
599 }
600
601 return val;
602}
603
604/* Decodes a number of bits from raw RC5 data */
605static u8
606wbcir_get_rc5bits(struct wbcir_data *data, unsigned int count)
607{
608 u16 raw = get_bits(data, count * 2);
609 u8 val = 0x00;
610 int bit;
611
612 for (bit = 0; bit < count; bit++) {
613 switch (raw & 0x03) {
614 case 0x01:
615 val |= (0x01 << bit);
616 break;
617 case 0x02:
618 break;
619 default:
620 data->irdata_error = 1;
621 break;
622 }
623 raw >>= 2;
624 }
625
626 return val;
627}
628
629static void
630wbcir_parse_rc6(struct device *dev, struct wbcir_data *data)
631{
632 /*
633 * Normal bits are manchester coded as follows:
634 * cell0 + cell1 = logic "0"
635 * cell1 + cell0 = logic "1"
636 *
637 * The IR pulse has the following components:
638 *
639 * Leader - 6 * cell1 - discarded
640 * Gap - 2 * cell0 - discarded
641 * Start bit - Normal Coding - always "1"
642 * Mode Bit 2 - 0 - Normal Coding
643 * Toggle bit - Normal Coding with double bit time,
644 * e.g. cell0 + cell0 + cell1 + cell1
645 * means logic "0".
646 *
647 * The rest depends on the mode, the following modes are known:
648 *
649 * MODE 0:
650 * Address Bit 7 - 0 - Normal Coding
651 * Command Bit 7 - 0 - Normal Coding
652 *
653 * MODE 6:
654 * The above Toggle Bit is used as a submode bit, 0 = A, 1 = B.
655 * Submode B is for pointing devices, only remotes using submode A
656 * are supported.
657 *
658 * Customer range bit - 0 => Customer = 7 bits, 0...127
659 * 1 => Customer = 15 bits, 32768...65535
660 * Customer Bits - Normal Coding
661 *
662 * Customer codes are allocated by Philips. The rest of the bits
663 * are customer dependent. The following is commonly used (and the
664 * only supported config):
665 *
666 * Toggle Bit - Normal Coding
667 * Address Bit 6 - 0 - Normal Coding
668 * Command Bit 7 - 0 - Normal Coding
669 *
670 * All modes are followed by at least 6 * cell0.
671 *
672 * MODE 0 msglen:
673 * 1 * 2 (start bit) + 3 * 2 (mode) + 2 * 2 (toggle) +
674 * 8 * 2 (address) + 8 * 2 (command) =
675 * 44 cells
676 *
677 * MODE 6A msglen:
678 * 1 * 2 (start bit) + 3 * 2 (mode) + 2 * 2 (submode) +
679 * 1 * 2 (customer range bit) + 7/15 * 2 (customer bits) +
680 * 1 * 2 (toggle bit) + 7 * 2 (address) + 8 * 2 (command) =
681 * 60 - 76 cells
682 */
683 u8 mode;
684 u8 toggle;
685 u16 customer = 0x0;
686 u8 address;
687 u8 command;
688 u32 scancode;
689
690 /* Leader mark */
691 while (get_bits(data, 1) && !data->irdata_error)
692 /* Do nothing */;
693
694 /* Leader space */
695 if (get_bits(data, 1)) {
696 dev_dbg(dev, "RC6 - Invalid leader space\n");
697 return;
698 }
699
700 /* Start bit */
701 if (get_bits(data, 2) != 0x02) {
702 dev_dbg(dev, "RC6 - Invalid start bit\n");
703 return;
704 }
705
706 /* Mode */
707 mode = get_bits(data, 6);
708 switch (mode) {
709 case 0x15: /* 010101 = b000 */
710 mode = 0;
711 break;
712 case 0x29: /* 101001 = b110 */
713 mode = 6;
714 break;
715 default:
716 dev_dbg(dev, "RC6 - Invalid mode\n");
717 return;
718 }
719
720 /* Toggle bit / Submode bit */
721 toggle = get_bits(data, 4);
722 switch (toggle) {
723 case 0x03:
724 toggle = 0;
725 break;
726 case 0x0C:
727 toggle = 1;
728 break;
729 default:
730 dev_dbg(dev, "RC6 - Toggle bit error\n");
731 break;
732 }
733
734 /* Customer */
735 if (mode == 6) {
736 if (toggle != 0) {
737 dev_dbg(dev, "RC6B - Not Supported\n");
738 return;
739 }
740
741 customer = wbcir_rc6cells_to_byte(data);
742
743 if (customer & 0x80) {
744 /* 15 bit customer value */
745 customer <<= 8;
746 customer |= wbcir_rc6cells_to_byte(data);
747 }
748 }
749
750 /* Address */
751 address = wbcir_rc6cells_to_byte(data);
752 if (mode == 6) {
753 toggle = address >> 7;
754 address &= 0x7F;
755 }
756
757 /* Command */
758 command = wbcir_rc6cells_to_byte(data);
759
760 /* Create scancode */
761 scancode = command;
762 scancode |= address << 8;
763 scancode |= customer << 16;
764
765 /* Last sanity check */
766 if (data->irdata_error) {
767 dev_dbg(dev, "RC6 - Cell error(s)\n");
768 return;
769 }
770
771 dev_dbg(dev, "IR-RC6 ad 0x%02X cm 0x%02X cu 0x%04X "
772 "toggle %u mode %u scan 0x%08X\n",
773 address,
774 command,
775 customer,
776 (unsigned int)toggle,
777 (unsigned int)mode,
778 scancode);
779
780 wbcir_keydown(data, scancode, toggle);
781}
782
783static void
784wbcir_parse_rc5(struct device *dev, struct wbcir_data *data)
785{
786 /*
787 * Bits are manchester coded as follows:
788 * cell1 + cell0 = logic "0"
789 * cell0 + cell1 = logic "1"
790 * (i.e. the reverse of RC6)
791 *
792 * Start bit 1 - "1" - discarded
793 * Start bit 2 - Must be inverted to get command bit 6
794 * Toggle bit
795 * Address Bit 4 - 0
796 * Command Bit 5 - 0
797 */
798 u8 toggle;
799 u8 address;
800 u8 command;
801 u32 scancode;
802
803 /* Start bit 1 */
804 if (!get_bits(data, 1)) {
805 dev_dbg(dev, "RC5 - Invalid start bit\n");
806 return;
807 }
808
809 /* Start bit 2 */
810 if (!wbcir_get_rc5bits(data, 1))
811 command = 0x40;
812 else
813 command = 0x00;
814
815 toggle = wbcir_get_rc5bits(data, 1);
816 address = wbcir_get_rc5bits(data, 5);
817 command |= wbcir_get_rc5bits(data, 6);
818 scancode = address << 7 | command;
819
820 /* Last sanity check */
821 if (data->irdata_error) {
822 dev_dbg(dev, "RC5 - Invalid message\n");
823 return;
824 }
825
826 dev_dbg(dev, "IR-RC5 ad %u cm %u t %u s %u\n",
827 (unsigned int)address,
828 (unsigned int)command,
829 (unsigned int)toggle,
830 (unsigned int)scancode);
831
832 wbcir_keydown(data, scancode, toggle);
833}
834
835static void
836wbcir_parse_nec(struct device *dev, struct wbcir_data *data)
837{
838 /*
839 * Each bit represents 560 us.
840 *
841 * Leader - 9 ms burst
842 * Gap - 4.5 ms silence
843 * Address1 bit 0 - 7 - Address 1
844 * Address2 bit 0 - 7 - Address 2
845 * Command1 bit 0 - 7 - Command 1
846 * Command2 bit 0 - 7 - Command 2
847 *
848 * Note the bit order!
849 *
850 * With the old NEC protocol, Address2 was the inverse of Address1
851 * and Command2 was the inverse of Command1 and were used as
852 * an error check.
853 *
854 * With NEC extended, Address1 is the LSB of the Address and
855 * Address2 is the MSB, Command parsing remains unchanged.
856 *
857 * A repeat message is coded as:
858 * Leader - 9 ms burst
859 * Gap - 2.25 ms silence
860 * Repeat - 560 us active
861 */
862 u8 address1;
863 u8 address2;
864 u8 command1;
865 u8 command2;
866 u16 address;
867 u32 scancode;
868
869 /* Leader mark */
870 while (get_bits(data, 1) && !data->irdata_error)
871 /* Do nothing */;
872
873 /* Leader space */
874 if (get_bits(data, 4)) {
875 dev_dbg(dev, "NEC - Invalid leader space\n");
876 return;
877 }
878
879 /* Repeat? */
880 if (get_bits(data, 1)) {
881 if (!data->keypressed) {
882 dev_dbg(dev, "NEC - Stray repeat message\n");
883 return;
884 }
885
886 dev_dbg(dev, "IR-NEC repeat s %u\n",
887 (unsigned int)data->last_scancode);
888
889 wbcir_keydown(data, data->last_scancode, data->last_toggle);
890 return;
891 }
892
893 /* Remaining leader space */
894 if (get_bits(data, 3)) {
895 dev_dbg(dev, "NEC - Invalid leader space\n");
896 return;
897 }
898
899 address1 = bitrev8(get_bits(data, 8));
900 address2 = bitrev8(get_bits(data, 8));
901 command1 = bitrev8(get_bits(data, 8));
902 command2 = bitrev8(get_bits(data, 8));
903
904 /* Sanity check */
905 if (data->irdata_error) {
906 dev_dbg(dev, "NEC - Invalid message\n");
907 return;
908 }
909
910 /* Check command validity */
911 if (command1 != ~command2) {
912 dev_dbg(dev, "NEC - Command bytes mismatch\n");
913 return;
914 }
915
916 /* Check for extended NEC protocol */
917 address = address1;
918 if (address1 != ~address2)
919 address |= address2 << 8;
920
921 scancode = address << 8 | command1;
922
923 dev_dbg(dev, "IR-NEC ad %u cm %u s %u\n",
924 (unsigned int)address,
925 (unsigned int)command1,
926 (unsigned int)scancode);
927
928 wbcir_keydown(data, scancode, !data->last_toggle);
929}
930
931
932
933/***************************************************************************** 276/*****************************************************************************
934 * 277 *
935 * INTERRUPT FUNCTIONS 278 * INTERRUPT FUNCTIONS
@@ -941,75 +284,88 @@ wbcir_irq_handler(int irqno, void *cookie)
941{ 284{
942 struct pnp_dev *device = cookie; 285 struct pnp_dev *device = cookie;
943 struct wbcir_data *data = pnp_get_drvdata(device); 286 struct wbcir_data *data = pnp_get_drvdata(device);
944 struct device *dev = &device->dev;
945 u8 status;
946 unsigned long flags; 287 unsigned long flags;
947 u8 irdata[8]; 288 u8 irdata[8];
289 u8 disable = true;
290 u8 status;
948 int i; 291 int i;
949 unsigned int hw;
950 292
951 spin_lock_irqsave(&wbcir_lock, flags); 293 spin_lock_irqsave(&data->spinlock, flags);
952 294
953 wbcir_select_bank(data, WBCIR_BANK_0); 295 wbcir_select_bank(data, WBCIR_BANK_0);
954 296
955 status = inb(data->sbase + WBCIR_REG_SP3_EIR); 297 status = inb(data->sbase + WBCIR_REG_SP3_EIR);
956 298
957 if (!(status & (WBCIR_IRQ_RX | WBCIR_IRQ_ERR))) { 299 if (!(status & (WBCIR_IRQ_RX | WBCIR_IRQ_ERR))) {
958 spin_unlock_irqrestore(&wbcir_lock, flags); 300 spin_unlock_irqrestore(&data->spinlock, flags);
959 return IRQ_NONE; 301 return IRQ_NONE;
960 } 302 }
961 303
962 if (status & WBCIR_IRQ_ERR) 304 /* Check for e.g. buffer overflow */
963 data->irdata_error = 1; 305 if (status & WBCIR_IRQ_ERR) {
306 data->irdata_error = true;
307 ir_raw_event_reset(data->dev);
308 }
964 309
965 if (!(status & WBCIR_IRQ_RX)) 310 if (!(status & WBCIR_IRQ_RX))
966 goto out; 311 goto out;
967 312
313 if (!data->irdata_active) {
314 data->irdata_active = true;
315 led_trigger_event(data->rxtrigger, LED_FULL);
316 }
317
968 /* Since RXHDLEV is set, at least 8 bytes are in the FIFO */ 318 /* Since RXHDLEV is set, at least 8 bytes are in the FIFO */
969 insb(data->sbase + WBCIR_REG_SP3_RXDATA, &irdata[0], 8); 319 insb(data->sbase + WBCIR_REG_SP3_RXDATA, &irdata[0], 8);
970 320
971 for (i = 0; i < sizeof(irdata); i++) { 321 for (i = 0; i < 8; i++) {
972 hw = hweight8(irdata[i]); 322 u8 pulse;
973 if (hw > 4) 323 u32 duration;
974 add_irdata_bit(data, 0);
975 else
976 add_irdata_bit(data, 1);
977 324
978 if (hw == 8) 325 if (irdata[i] != 0xFF && irdata[i] != 0x00)
979 data->idle_count++; 326 disable = false;
980 else 327
981 data->idle_count = 0; 328 if (data->irdata_error)
329 continue;
330
331 pulse = irdata[i] & 0x80 ? false : true;
332 duration = (irdata[i] & 0x7F) * 10000; /* ns */
333
334 if (data->ev.pulse != pulse) {
335 if (data->ev.duration != 0) {
336 ir_raw_event_store(data->dev, &data->ev);
337 data->ev.duration = 0;
338 }
339
340 data->ev.pulse = pulse;
341 }
342
343 data->ev.duration += duration;
982 } 344 }
983 345
984 if (data->idle_count > WBCIR_MAX_IDLE_BYTES) { 346 if (disable) {
985 /* Set RXINACTIVE... */ 347 if (data->ev.duration != 0 && !data->irdata_error) {
348 ir_raw_event_store(data->dev, &data->ev);
349 data->ev.duration = 0;
350 }
351
352 /* Set RXINACTIVE */
986 outb(WBCIR_RX_DISABLE, data->sbase + WBCIR_REG_SP3_ASCR); 353 outb(WBCIR_RX_DISABLE, data->sbase + WBCIR_REG_SP3_ASCR);
987 354
988 /* ...and drain the FIFO */ 355 /* Drain the FIFO */
989 while (inb(data->sbase + WBCIR_REG_SP3_LSR) & WBCIR_RX_AVAIL) 356 while (inb(data->sbase + WBCIR_REG_SP3_LSR) & WBCIR_RX_AVAIL)
990 inb(data->sbase + WBCIR_REG_SP3_RXDATA); 357 inb(data->sbase + WBCIR_REG_SP3_RXDATA);
991 358
992 dev_dbg(dev, "IRDATA:\n"); 359 ir_raw_event_reset(data->dev);
993 for (i = 0; i < data->irdata_count; i += BITS_PER_LONG) 360 data->irdata_error = false;
994 dev_dbg(dev, "0x%08lX\n", data->irdata[i/BITS_PER_LONG]); 361 data->irdata_active = false;
995 362 led_trigger_event(data->rxtrigger, LED_OFF);
996 switch (protocol) {
997 case IR_PROTOCOL_RC5:
998 wbcir_parse_rc5(dev, data);
999 break;
1000 case IR_PROTOCOL_RC6:
1001 wbcir_parse_rc6(dev, data);
1002 break;
1003 case IR_PROTOCOL_NEC:
1004 wbcir_parse_nec(dev, data);
1005 break;
1006 }
1007
1008 wbcir_reset_irdata(data);
1009 } 363 }
1010 364
365 ir_raw_event_handle(data->dev);
366
1011out: 367out:
1012 spin_unlock_irqrestore(&wbcir_lock, flags); 368 spin_unlock_irqrestore(&data->spinlock, flags);
1013 return IRQ_HANDLED; 369 return IRQ_HANDLED;
1014} 370}
1015 371
@@ -1199,6 +555,10 @@ finish:
1199 wbcir_select_bank(data, WBCIR_BANK_0); 555 wbcir_select_bank(data, WBCIR_BANK_0);
1200 outb(WBCIR_IRQ_NONE, data->sbase + WBCIR_REG_SP3_IER); 556 outb(WBCIR_IRQ_NONE, data->sbase + WBCIR_REG_SP3_IER);
1201 557
558 /* Disable LED */
559 data->irdata_active = false;
560 led_trigger_event(data->rxtrigger, LED_OFF);
561
1202 /* 562 /*
1203 * ACPI will set the HW disable bit for SP3 which means that the 563 * ACPI will set the HW disable bit for SP3 which means that the
1204 * output signals are left in an undefined state which may cause 564 * output signals are left in an undefined state which may cause
@@ -1323,8 +683,15 @@ wbcir_init_hw(struct wbcir_data *data)
1323 /* Clear AUX status bits */ 683 /* Clear AUX status bits */
1324 outb(0xE0, data->sbase + WBCIR_REG_SP3_ASCR); 684 outb(0xE0, data->sbase + WBCIR_REG_SP3_ASCR);
1325 685
686 /* Clear IR decoding state */
687 data->irdata_active = false;
688 led_trigger_event(data->rxtrigger, LED_OFF);
689 data->irdata_error = false;
690 data->ev.duration = 0;
691 ir_raw_event_reset(data->dev);
692 ir_raw_event_handle(data->dev);
693
1326 /* Enable interrupts */ 694 /* Enable interrupts */
1327 wbcir_reset_irdata(data);
1328 outb(WBCIR_IRQ_RX | WBCIR_IRQ_ERR, data->sbase + WBCIR_REG_SP3_IER); 695 outb(WBCIR_IRQ_RX | WBCIR_IRQ_ERR, data->sbase + WBCIR_REG_SP3_IER);
1329} 696}
1330 697
@@ -1361,6 +728,7 @@ wbcir_probe(struct pnp_dev *device, const struct pnp_device_id *dev_id)
1361 728
1362 pnp_set_drvdata(device, data); 729 pnp_set_drvdata(device, data);
1363 730
731 spin_lock_init(&data->spinlock);
1364 data->ebase = pnp_port_start(device, 0); 732 data->ebase = pnp_port_start(device, 0);
1365 data->wbase = pnp_port_start(device, 1); 733 data->wbase = pnp_port_start(device, 1);
1366 data->sbase = pnp_port_start(device, 2); 734 data->sbase = pnp_port_start(device, 2);
@@ -1426,43 +794,25 @@ wbcir_probe(struct pnp_dev *device, const struct pnp_device_id *dev_id)
1426 if (err) 794 if (err)
1427 goto exit_unregister_rxtrigger; 795 goto exit_unregister_rxtrigger;
1428 796
1429 data->input_dev = input_allocate_device(); 797 data->dev = rc_allocate_device();
1430 if (!data->input_dev) { 798 if (!data->dev) {
1431 err = -ENOMEM; 799 err = -ENOMEM;
1432 goto exit_unregister_led; 800 goto exit_unregister_led;
1433 } 801 }
1434 802
1435 data->input_dev->evbit[0] = BIT(EV_KEY); 803 data->dev->driver_name = WBCIR_NAME;
1436 data->input_dev->name = WBCIR_NAME; 804 data->dev->input_name = WBCIR_NAME;
1437 data->input_dev->phys = "wbcir/cir0"; 805 data->dev->input_phys = "wbcir/cir0";
1438 data->input_dev->id.bustype = BUS_HOST; 806 data->dev->input_id.bustype = BUS_HOST;
1439 data->input_dev->id.vendor = PCI_VENDOR_ID_WINBOND; 807 data->dev->input_id.vendor = PCI_VENDOR_ID_WINBOND;
1440 data->input_dev->id.product = WBCIR_ID_FAMILY; 808 data->dev->input_id.product = WBCIR_ID_FAMILY;
1441 data->input_dev->id.version = WBCIR_ID_CHIP; 809 data->dev->input_id.version = WBCIR_ID_CHIP;
1442 data->input_dev->getkeycode = wbcir_getkeycode; 810 data->dev->priv = data;
1443 data->input_dev->setkeycode = wbcir_setkeycode; 811 data->dev->dev.parent = &device->dev;
1444 input_set_capability(data->input_dev, EV_MSC, MSC_SCAN); 812
1445 input_set_drvdata(data->input_dev, data); 813 err = rc_register_device(data->dev);
1446
1447 err = input_register_device(data->input_dev);
1448 if (err) 814 if (err)
1449 goto exit_free_input; 815 goto exit_free_rc;
1450
1451 data->last_scancode = INVALID_SCANCODE;
1452 INIT_LIST_HEAD(&data->keytable);
1453 setup_timer(&data->timer_keyup, wbcir_keyup, (unsigned long)data);
1454
1455 /* Load default keymaps */
1456 if (protocol == IR_PROTOCOL_RC6) {
1457 int i;
1458 for (i = 0; i < ARRAY_SIZE(rc6_def_keymap); i++) {
1459 err = wbcir_setkeycode(data->input_dev,
1460 (int)rc6_def_keymap[i].scancode,
1461 (int)rc6_def_keymap[i].keycode);
1462 if (err)
1463 goto exit_unregister_keys;
1464 }
1465 }
1466 816
1467 device_init_wakeup(&device->dev, 1); 817 device_init_wakeup(&device->dev, 1);
1468 818
@@ -1470,21 +820,8 @@ wbcir_probe(struct pnp_dev *device, const struct pnp_device_id *dev_id)
1470 820
1471 return 0; 821 return 0;
1472 822
1473exit_unregister_keys: 823exit_free_rc:
1474 if (!list_empty(&data->keytable)) { 824 rc_free_device(data->dev);
1475 struct wbcir_keyentry *key;
1476 struct wbcir_keyentry *keytmp;
1477
1478 list_for_each_entry_safe(key, keytmp, &data->keytable, list) {
1479 list_del(&key->list);
1480 kfree(key);
1481 }
1482 }
1483 input_unregister_device(data->input_dev);
1484 /* Can't call input_free_device on an unregistered device */
1485 data->input_dev = NULL;
1486exit_free_input:
1487 input_free_device(data->input_dev);
1488exit_unregister_led: 825exit_unregister_led:
1489 led_classdev_unregister(&data->led); 826 led_classdev_unregister(&data->led);
1490exit_unregister_rxtrigger: 827exit_unregister_rxtrigger:
@@ -1510,15 +847,11 @@ static void __devexit
1510wbcir_remove(struct pnp_dev *device) 847wbcir_remove(struct pnp_dev *device)
1511{ 848{
1512 struct wbcir_data *data = pnp_get_drvdata(device); 849 struct wbcir_data *data = pnp_get_drvdata(device);
1513 struct wbcir_keyentry *key;
1514 struct wbcir_keyentry *keytmp;
1515 850
1516 /* Disable interrupts */ 851 /* Disable interrupts */
1517 wbcir_select_bank(data, WBCIR_BANK_0); 852 wbcir_select_bank(data, WBCIR_BANK_0);
1518 outb(WBCIR_IRQ_NONE, data->sbase + WBCIR_REG_SP3_IER); 853 outb(WBCIR_IRQ_NONE, data->sbase + WBCIR_REG_SP3_IER);
1519 854
1520 del_timer_sync(&data->timer_keyup);
1521
1522 free_irq(data->irq, device); 855 free_irq(data->irq, device);
1523 856
1524 /* Clear status bits NEC_REP, BUFF, MSG_END, MATCH */ 857 /* Clear status bits NEC_REP, BUFF, MSG_END, MATCH */
@@ -1530,8 +863,7 @@ wbcir_remove(struct pnp_dev *device)
1530 /* Clear BUFF_EN, END_EN, MATCH_EN */ 863 /* Clear BUFF_EN, END_EN, MATCH_EN */
1531 wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x00, 0x07); 864 wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x00, 0x07);
1532 865
1533 /* This will generate a keyup event if necessary */ 866 rc_unregister_device(data->dev);
1534 input_unregister_device(data->input_dev);
1535 867
1536 led_trigger_unregister_simple(data->rxtrigger); 868 led_trigger_unregister_simple(data->rxtrigger);
1537 led_trigger_unregister_simple(data->txtrigger); 869 led_trigger_unregister_simple(data->txtrigger);
@@ -1544,11 +876,6 @@ wbcir_remove(struct pnp_dev *device)
1544 release_region(data->ebase, EHFUNC_IOMEM_LEN); 876 release_region(data->ebase, EHFUNC_IOMEM_LEN);
1545 release_region(data->sbase, SP_IOMEM_LEN); 877 release_region(data->sbase, SP_IOMEM_LEN);
1546 878
1547 list_for_each_entry_safe(key, keytmp, &data->keytable, list) {
1548 list_del(&key->list);
1549 kfree(key);
1550 }
1551
1552 kfree(data); 879 kfree(data);
1553 880
1554 pnp_set_drvdata(device, NULL); 881 pnp_set_drvdata(device, NULL);
@@ -1581,8 +908,7 @@ wbcir_init(void)
1581 case IR_PROTOCOL_RC6: 908 case IR_PROTOCOL_RC6:
1582 break; 909 break;
1583 default: 910 default:
1584 printk(KERN_ERR DRVNAME ": Invalid protocol argument\n"); 911 printk(KERN_ERR DRVNAME ": Invalid power-on protocol\n");
1585 return -EINVAL;
1586 } 912 }
1587 913
1588 ret = pnp_register_driver(&wbcir_driver); 914 ret = pnp_register_driver(&wbcir_driver);
@@ -1598,11 +924,9 @@ wbcir_exit(void)
1598 pnp_unregister_driver(&wbcir_driver); 924 pnp_unregister_driver(&wbcir_driver);
1599} 925}
1600 926
1601MODULE_AUTHOR("David Härdeman <david@hardeman.nu>");
1602MODULE_DESCRIPTION("Winbond SuperI/O Consumer IR Driver");
1603MODULE_LICENSE("GPL");
1604
1605module_init(wbcir_init); 927module_init(wbcir_init);
1606module_exit(wbcir_exit); 928module_exit(wbcir_exit);
1607 929
1608 930MODULE_AUTHOR("David Härdeman <david@hardeman.nu>");
931MODULE_DESCRIPTION("Winbond SuperI/O Consumer IR Driver");
932MODULE_LICENSE("GPL");
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index 6830d2848bd7..eb875af05e79 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -7,11 +7,6 @@ config VIDEO_V4L2
7 depends on VIDEO_DEV && VIDEO_V4L2_COMMON 7 depends on VIDEO_DEV && VIDEO_V4L2_COMMON
8 default VIDEO_DEV && VIDEO_V4L2_COMMON 8 default VIDEO_DEV && VIDEO_V4L2_COMMON
9 9
10config VIDEO_V4L1
11 tristate
12 depends on VIDEO_DEV && VIDEO_V4L2_COMMON && VIDEO_ALLOW_V4L1
13 default VIDEO_DEV && VIDEO_V4L2_COMMON && VIDEO_ALLOW_V4L1
14
15config VIDEOBUF_GEN 10config VIDEOBUF_GEN
16 tristate 11 tristate
17 12
@@ -96,7 +91,7 @@ config VIDEO_HELPER_CHIPS_AUTO
96 91
97config VIDEO_IR_I2C 92config VIDEO_IR_I2C
98 tristate "I2C module for IR" if !VIDEO_HELPER_CHIPS_AUTO 93 tristate "I2C module for IR" if !VIDEO_HELPER_CHIPS_AUTO
99 depends on I2C && VIDEO_IR 94 depends on I2C && RC_CORE
100 default y 95 default y
101 ---help--- 96 ---help---
102 Most boards have an IR chip directly connected via GPIO. However, 97 Most boards have an IR chip directly connected via GPIO. However,
@@ -666,6 +661,16 @@ config VIDEO_HEXIUM_GEMINI
666 To compile this driver as a module, choose M here: the 661 To compile this driver as a module, choose M here: the
667 module will be called hexium_gemini. 662 module will be called hexium_gemini.
668 663
664config VIDEO_TIMBERDALE
665 tristate "Support for timberdale Video In/LogiWIN"
666 depends on VIDEO_V4L2 && I2C
667 select DMA_ENGINE
668 select TIMB_DMA
669 select VIDEO_ADV7180
670 select VIDEOBUF_DMA_CONTIG
671 ---help---
672 Add support for the Video In peripherial of the timberdale FPGA.
673
669source "drivers/media/video/cx88/Kconfig" 674source "drivers/media/video/cx88/Kconfig"
670 675
671source "drivers/media/video/cx23885/Kconfig" 676source "drivers/media/video/cx23885/Kconfig"
@@ -789,6 +794,12 @@ config SOC_CAMERA_PLATFORM
789 help 794 help
790 This is a generic SoC camera platform driver, useful for testing 795 This is a generic SoC camera platform driver, useful for testing
791 796
797config SOC_CAMERA_OV2640
798 tristate "ov2640 camera support"
799 depends on SOC_CAMERA && I2C
800 help
801 This is a ov2640 camera driver
802
792config SOC_CAMERA_OV6650 803config SOC_CAMERA_OV6650
793 tristate "ov6650 sensor support" 804 tristate "ov6650 sensor support"
794 depends on SOC_CAMERA && I2C 805 depends on SOC_CAMERA && I2C
@@ -905,21 +916,8 @@ source "drivers/media/video/cx231xx/Kconfig"
905 916
906source "drivers/media/video/usbvision/Kconfig" 917source "drivers/media/video/usbvision/Kconfig"
907 918
908source "drivers/media/video/usbvideo/Kconfig"
909
910source "drivers/media/video/et61x251/Kconfig" 919source "drivers/media/video/et61x251/Kconfig"
911 920
912config USB_SE401
913 tristate "USB SE401 Camera support"
914 depends on VIDEO_V4L1
915 ---help---
916 Say Y here if you want to connect this type of camera to your
917 computer's USB port. See <file:Documentation/video4linux/se401.txt>
918 for more information and for a list of supported cameras.
919
920 To compile this driver as a module, choose M here: the
921 module will be called se401.
922
923source "drivers/media/video/sn9c102/Kconfig" 921source "drivers/media/video/sn9c102/Kconfig"
924 922
925source "drivers/media/video/pwc/Kconfig" 923source "drivers/media/video/pwc/Kconfig"
diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile
index af79d476a4c8..81e38cb0b846 100644
--- a/drivers/media/video/Makefile
+++ b/drivers/media/video/Makefile
@@ -22,10 +22,6 @@ endif
22 22
23obj-$(CONFIG_VIDEO_V4L2_COMMON) += v4l2-common.o 23obj-$(CONFIG_VIDEO_V4L2_COMMON) += v4l2-common.o
24 24
25ifeq ($(CONFIG_VIDEO_V4L1_COMPAT),y)
26 obj-$(CONFIG_VIDEO_DEV) += v4l1-compat.o
27endif
28
29# All i2c modules must come first: 25# All i2c modules must come first:
30 26
31obj-$(CONFIG_VIDEO_TUNER) += tuner.o 27obj-$(CONFIG_VIDEO_TUNER) += tuner.o
@@ -79,6 +75,7 @@ obj-$(CONFIG_SOC_CAMERA_MT9M111) += mt9m111.o
79obj-$(CONFIG_SOC_CAMERA_MT9T031) += mt9t031.o 75obj-$(CONFIG_SOC_CAMERA_MT9T031) += mt9t031.o
80obj-$(CONFIG_SOC_CAMERA_MT9T112) += mt9t112.o 76obj-$(CONFIG_SOC_CAMERA_MT9T112) += mt9t112.o
81obj-$(CONFIG_SOC_CAMERA_MT9V022) += mt9v022.o 77obj-$(CONFIG_SOC_CAMERA_MT9V022) += mt9v022.o
78obj-$(CONFIG_SOC_CAMERA_OV2640) += ov2640.o
82obj-$(CONFIG_SOC_CAMERA_OV6650) += ov6650.o 79obj-$(CONFIG_SOC_CAMERA_OV6650) += ov6650.o
83obj-$(CONFIG_SOC_CAMERA_OV772X) += ov772x.o 80obj-$(CONFIG_SOC_CAMERA_OV772X) += ov772x.o
84obj-$(CONFIG_SOC_CAMERA_OV9640) += ov9640.o 81obj-$(CONFIG_SOC_CAMERA_OV9640) += ov9640.o
@@ -106,6 +103,7 @@ obj-$(CONFIG_VIDEO_CPIA2) += cpia2/
106obj-$(CONFIG_VIDEO_MXB) += mxb.o 103obj-$(CONFIG_VIDEO_MXB) += mxb.o
107obj-$(CONFIG_VIDEO_HEXIUM_ORION) += hexium_orion.o 104obj-$(CONFIG_VIDEO_HEXIUM_ORION) += hexium_orion.o
108obj-$(CONFIG_VIDEO_HEXIUM_GEMINI) += hexium_gemini.o 105obj-$(CONFIG_VIDEO_HEXIUM_GEMINI) += hexium_gemini.o
106obj-$(CONFIG_VIDEO_TIMBERDALE) += timblogiw.o
109 107
110obj-$(CONFIG_VIDEOBUF_GEN) += videobuf-core.o 108obj-$(CONFIG_VIDEOBUF_GEN) += videobuf-core.o
111obj-$(CONFIG_VIDEOBUF_DMA_SG) += videobuf-dma-sg.o 109obj-$(CONFIG_VIDEOBUF_DMA_SG) += videobuf-dma-sg.o
@@ -124,8 +122,6 @@ obj-$(CONFIG_VIDEO_CAFE_CCIC) += cafe_ccic.o
124 122
125obj-$(CONFIG_VIDEO_VIA_CAMERA) += via-camera.o 123obj-$(CONFIG_VIDEO_VIA_CAMERA) += via-camera.o
126 124
127obj-$(CONFIG_USB_DABUSB) += dabusb.o
128obj-$(CONFIG_USB_SE401) += se401.o
129obj-$(CONFIG_USB_ZR364XX) += zr364xx.o 125obj-$(CONFIG_USB_ZR364XX) += zr364xx.o
130obj-$(CONFIG_USB_STKWEBCAM) += stkwebcam.o 126obj-$(CONFIG_USB_STKWEBCAM) += stkwebcam.o
131 127
@@ -136,10 +132,6 @@ obj-$(CONFIG_USB_GSPCA) += gspca/
136 132
137obj-$(CONFIG_VIDEO_HDPVR) += hdpvr/ 133obj-$(CONFIG_VIDEO_HDPVR) += hdpvr/
138 134
139obj-$(CONFIG_USB_IBMCAM) += usbvideo/
140obj-$(CONFIG_USB_KONICAWC) += usbvideo/
141obj-$(CONFIG_USB_VICAM) += usbvideo/
142obj-$(CONFIG_USB_QUICKCAM_MESSENGER) += usbvideo/
143obj-$(CONFIG_USB_S2255) += s2255drv.o 135obj-$(CONFIG_USB_S2255) += s2255drv.o
144 136
145obj-$(CONFIG_VIDEO_IVTV) += ivtv/ 137obj-$(CONFIG_VIDEO_IVTV) += ivtv/
diff --git a/drivers/media/video/au0828/au0828-video.c b/drivers/media/video/au0828/au0828-video.c
index 162fd5f9d448..e41e4ad5cc40 100644
--- a/drivers/media/video/au0828/au0828-video.c
+++ b/drivers/media/video/au0828/au0828-video.c
@@ -122,6 +122,7 @@ static void au0828_irq_callback(struct urb *urb)
122{ 122{
123 struct au0828_dmaqueue *dma_q = urb->context; 123 struct au0828_dmaqueue *dma_q = urb->context;
124 struct au0828_dev *dev = container_of(dma_q, struct au0828_dev, vidq); 124 struct au0828_dev *dev = container_of(dma_q, struct au0828_dev, vidq);
125 unsigned long flags = 0;
125 int rc, i; 126 int rc, i;
126 127
127 switch (urb->status) { 128 switch (urb->status) {
@@ -139,9 +140,9 @@ static void au0828_irq_callback(struct urb *urb)
139 } 140 }
140 141
141 /* Copy data from URB */ 142 /* Copy data from URB */
142 spin_lock(&dev->slock); 143 spin_lock_irqsave(&dev->slock, flags);
143 rc = dev->isoc_ctl.isoc_copy(dev, urb); 144 rc = dev->isoc_ctl.isoc_copy(dev, urb);
144 spin_unlock(&dev->slock); 145 spin_unlock_irqrestore(&dev->slock, flags);
145 146
146 /* Reset urb buffers */ 147 /* Reset urb buffers */
147 for (i = 0; i < urb->number_of_packets; i++) { 148 for (i = 0; i < urb->number_of_packets; i++) {
@@ -576,7 +577,7 @@ static inline int au0828_isoc_copy(struct au0828_dev *dev, struct urb *urb)
576 p += 4; 577 p += 4;
577 au0828_isocdbg("Video frame %s\n", 578 au0828_isocdbg("Video frame %s\n",
578 (fbyte & 0x40) ? "odd" : "even"); 579 (fbyte & 0x40) ? "odd" : "even");
579 if (!(fbyte & 0x40)) { 580 if (fbyte & 0x40) {
580 /* VBI */ 581 /* VBI */
581 if (vbi_buf != NULL) 582 if (vbi_buf != NULL)
582 vbi_buffer_filled(dev, 583 vbi_buffer_filled(dev,
@@ -597,6 +598,15 @@ static inline int au0828_isoc_copy(struct au0828_dev *dev, struct urb *urb)
597 outp = NULL; 598 outp = NULL;
598 else 599 else
599 outp = videobuf_to_vmalloc(&buf->vb); 600 outp = videobuf_to_vmalloc(&buf->vb);
601
602 /* As long as isoc traffic is arriving, keep
603 resetting the timer */
604 if (dev->vid_timeout_running)
605 mod_timer(&dev->vid_timeout,
606 jiffies + (HZ / 10));
607 if (dev->vbi_timeout_running)
608 mod_timer(&dev->vbi_timeout,
609 jiffies + (HZ / 10));
600 } 610 }
601 611
602 if (buf != NULL) { 612 if (buf != NULL) {
@@ -907,6 +917,57 @@ static int get_ressource(struct au0828_fh *fh)
907 } 917 }
908} 918}
909 919
920/* This function ensures that video frames continue to be delivered even if
921 the ITU-656 input isn't receiving any data (thereby preventing applications
922 such as tvtime from hanging) */
923void au0828_vid_buffer_timeout(unsigned long data)
924{
925 struct au0828_dev *dev = (struct au0828_dev *) data;
926 struct au0828_dmaqueue *dma_q = &dev->vidq;
927 struct au0828_buffer *buf;
928 unsigned char *vid_data;
929 unsigned long flags = 0;
930
931 spin_lock_irqsave(&dev->slock, flags);
932
933 buf = dev->isoc_ctl.buf;
934 if (buf != NULL) {
935 vid_data = videobuf_to_vmalloc(&buf->vb);
936 memset(vid_data, 0x00, buf->vb.size); /* Blank green frame */
937 buffer_filled(dev, dma_q, buf);
938 }
939 get_next_buf(dma_q, &buf);
940
941 if (dev->vid_timeout_running == 1)
942 mod_timer(&dev->vid_timeout, jiffies + (HZ / 10));
943
944 spin_unlock_irqrestore(&dev->slock, flags);
945}
946
947void au0828_vbi_buffer_timeout(unsigned long data)
948{
949 struct au0828_dev *dev = (struct au0828_dev *) data;
950 struct au0828_dmaqueue *dma_q = &dev->vbiq;
951 struct au0828_buffer *buf;
952 unsigned char *vbi_data;
953 unsigned long flags = 0;
954
955 spin_lock_irqsave(&dev->slock, flags);
956
957 buf = dev->isoc_ctl.vbi_buf;
958 if (buf != NULL) {
959 vbi_data = videobuf_to_vmalloc(&buf->vb);
960 memset(vbi_data, 0x00, buf->vb.size);
961 vbi_buffer_filled(dev, dma_q, buf);
962 }
963 vbi_get_next_buf(dma_q, &buf);
964
965 if (dev->vbi_timeout_running == 1)
966 mod_timer(&dev->vbi_timeout, jiffies + (HZ / 10));
967 spin_unlock_irqrestore(&dev->slock, flags);
968}
969
970
910static int au0828_v4l2_open(struct file *filp) 971static int au0828_v4l2_open(struct file *filp)
911{ 972{
912 int ret = 0; 973 int ret = 0;
@@ -976,7 +1037,6 @@ static int au0828_v4l2_open(struct file *filp)
976 V4L2_FIELD_SEQ_TB, 1037 V4L2_FIELD_SEQ_TB,
977 sizeof(struct au0828_buffer), fh, NULL); 1038 sizeof(struct au0828_buffer), fh, NULL);
978 1039
979
980 return ret; 1040 return ret;
981} 1041}
982 1042
@@ -987,11 +1047,19 @@ static int au0828_v4l2_close(struct file *filp)
987 struct au0828_dev *dev = fh->dev; 1047 struct au0828_dev *dev = fh->dev;
988 1048
989 if (res_check(fh, AU0828_RESOURCE_VIDEO)) { 1049 if (res_check(fh, AU0828_RESOURCE_VIDEO)) {
1050 /* Cancel timeout thread in case they didn't call streamoff */
1051 dev->vid_timeout_running = 0;
1052 del_timer_sync(&dev->vid_timeout);
1053
990 videobuf_stop(&fh->vb_vidq); 1054 videobuf_stop(&fh->vb_vidq);
991 res_free(fh, AU0828_RESOURCE_VIDEO); 1055 res_free(fh, AU0828_RESOURCE_VIDEO);
992 } 1056 }
993 1057
994 if (res_check(fh, AU0828_RESOURCE_VBI)) { 1058 if (res_check(fh, AU0828_RESOURCE_VBI)) {
1059 /* Cancel timeout thread in case they didn't call streamoff */
1060 dev->vbi_timeout_running = 0;
1061 del_timer_sync(&dev->vbi_timeout);
1062
995 videobuf_stop(&fh->vb_vbiq); 1063 videobuf_stop(&fh->vb_vbiq);
996 res_free(fh, AU0828_RESOURCE_VBI); 1064 res_free(fh, AU0828_RESOURCE_VBI);
997 } 1065 }
@@ -1048,6 +1116,13 @@ static ssize_t au0828_v4l2_read(struct file *filp, char __user *buf,
1048 if (!res_get(fh, AU0828_RESOURCE_VBI)) 1116 if (!res_get(fh, AU0828_RESOURCE_VBI))
1049 return -EBUSY; 1117 return -EBUSY;
1050 1118
1119 if (dev->vbi_timeout_running == 0) {
1120 /* Handle case where caller tries to read without
1121 calling streamon first */
1122 dev->vbi_timeout_running = 1;
1123 mod_timer(&dev->vbi_timeout, jiffies + (HZ / 10));
1124 }
1125
1051 return videobuf_read_stream(&fh->vb_vbiq, buf, count, pos, 0, 1126 return videobuf_read_stream(&fh->vb_vbiq, buf, count, pos, 0,
1052 filp->f_flags & O_NONBLOCK); 1127 filp->f_flags & O_NONBLOCK);
1053 } 1128 }
@@ -1577,10 +1652,15 @@ static int vidioc_streamon(struct file *file, void *priv,
1577 v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_stream, 1); 1652 v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_stream, 1);
1578 } 1653 }
1579 1654
1580 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) 1655 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1581 rc = videobuf_streamon(&fh->vb_vidq); 1656 rc = videobuf_streamon(&fh->vb_vidq);
1582 else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) 1657 dev->vid_timeout_running = 1;
1658 mod_timer(&dev->vid_timeout, jiffies + (HZ / 10));
1659 } else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
1583 rc = videobuf_streamon(&fh->vb_vbiq); 1660 rc = videobuf_streamon(&fh->vb_vbiq);
1661 dev->vbi_timeout_running = 1;
1662 mod_timer(&dev->vbi_timeout, jiffies + (HZ / 10));
1663 }
1584 1664
1585 return rc; 1665 return rc;
1586} 1666}
@@ -1607,6 +1687,9 @@ static int vidioc_streamoff(struct file *file, void *priv,
1607 fh, type, fh->resources, dev->resources); 1687 fh, type, fh->resources, dev->resources);
1608 1688
1609 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { 1689 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1690 dev->vid_timeout_running = 0;
1691 del_timer_sync(&dev->vid_timeout);
1692
1610 v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_stream, 0); 1693 v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_stream, 0);
1611 rc = au0828_stream_interrupt(dev); 1694 rc = au0828_stream_interrupt(dev);
1612 if (rc != 0) 1695 if (rc != 0)
@@ -1621,6 +1704,9 @@ static int vidioc_streamoff(struct file *file, void *priv,
1621 videobuf_streamoff(&fh->vb_vidq); 1704 videobuf_streamoff(&fh->vb_vidq);
1622 res_free(fh, AU0828_RESOURCE_VIDEO); 1705 res_free(fh, AU0828_RESOURCE_VIDEO);
1623 } else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) { 1706 } else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
1707 dev->vbi_timeout_running = 0;
1708 del_timer_sync(&dev->vbi_timeout);
1709
1624 videobuf_streamoff(&fh->vb_vbiq); 1710 videobuf_streamoff(&fh->vb_vbiq);
1625 res_free(fh, AU0828_RESOURCE_VBI); 1711 res_free(fh, AU0828_RESOURCE_VBI);
1626 } 1712 }
@@ -1723,15 +1809,6 @@ static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b)
1723 return videobuf_dqbuf(&fh->vb_vidq, b, file->f_flags & O_NONBLOCK); 1809 return videobuf_dqbuf(&fh->vb_vidq, b, file->f_flags & O_NONBLOCK);
1724} 1810}
1725 1811
1726#ifdef CONFIG_VIDEO_V4L1_COMPAT
1727static int vidiocgmbuf(struct file *file, void *priv, struct video_mbuf *mbuf)
1728{
1729 struct au0828_fh *fh = priv;
1730
1731 return videobuf_cgmbuf(&fh->vb_vidq, mbuf, 8);
1732}
1733#endif
1734
1735static struct v4l2_file_operations au0828_v4l_fops = { 1812static struct v4l2_file_operations au0828_v4l_fops = {
1736 .owner = THIS_MODULE, 1813 .owner = THIS_MODULE,
1737 .open = au0828_v4l2_open, 1814 .open = au0828_v4l2_open,
@@ -1775,9 +1852,6 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
1775 .vidioc_s_register = vidioc_s_register, 1852 .vidioc_s_register = vidioc_s_register,
1776#endif 1853#endif
1777 .vidioc_g_chip_ident = vidioc_g_chip_ident, 1854 .vidioc_g_chip_ident = vidioc_g_chip_ident,
1778#ifdef CONFIG_VIDEO_V4L1_COMPAT
1779 .vidiocgmbuf = vidiocgmbuf,
1780#endif
1781}; 1855};
1782 1856
1783static const struct video_device au0828_video_template = { 1857static const struct video_device au0828_video_template = {
@@ -1840,6 +1914,14 @@ int au0828_analog_register(struct au0828_dev *dev,
1840 INIT_LIST_HEAD(&dev->vbiq.active); 1914 INIT_LIST_HEAD(&dev->vbiq.active);
1841 INIT_LIST_HEAD(&dev->vbiq.queued); 1915 INIT_LIST_HEAD(&dev->vbiq.queued);
1842 1916
1917 dev->vid_timeout.function = au0828_vid_buffer_timeout;
1918 dev->vid_timeout.data = (unsigned long) dev;
1919 init_timer(&dev->vid_timeout);
1920
1921 dev->vbi_timeout.function = au0828_vbi_buffer_timeout;
1922 dev->vbi_timeout.data = (unsigned long) dev;
1923 init_timer(&dev->vbi_timeout);
1924
1843 dev->width = NTSC_STD_W; 1925 dev->width = NTSC_STD_W;
1844 dev->height = NTSC_STD_H; 1926 dev->height = NTSC_STD_H;
1845 dev->field_size = dev->width * dev->height; 1927 dev->field_size = dev->width * dev->height;
diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
index 9905bc4f5f59..9cde35321824 100644
--- a/drivers/media/video/au0828/au0828.h
+++ b/drivers/media/video/au0828/au0828.h
@@ -53,7 +53,7 @@
53 53
54/* Defination for AU0828 USB transfer */ 54/* Defination for AU0828 USB transfer */
55#define AU0828_MAX_ISO_BUFS 12 /* maybe resize this value in the future */ 55#define AU0828_MAX_ISO_BUFS 12 /* maybe resize this value in the future */
56#define AU0828_ISO_PACKETS_PER_URB 10 56#define AU0828_ISO_PACKETS_PER_URB 128
57 57
58#define AU0828_MIN_BUF 4 58#define AU0828_MIN_BUF 4
59#define AU0828_DEF_BUF 8 59#define AU0828_DEF_BUF 8
@@ -204,6 +204,10 @@ struct au0828_dev {
204 unsigned int resources; /* resources in use */ 204 unsigned int resources; /* resources in use */
205 struct video_device *vdev; 205 struct video_device *vdev;
206 struct video_device *vbi_dev; 206 struct video_device *vbi_dev;
207 struct timer_list vid_timeout;
208 int vid_timeout_running;
209 struct timer_list vbi_timeout;
210 int vbi_timeout_running;
207 int width; 211 int width;
208 int height; 212 int height;
209 int vbi_width; 213 int vbi_width;
diff --git a/drivers/media/video/bt8xx/Kconfig b/drivers/media/video/bt8xx/Kconfig
index 1a4a89fdf767..7da5c2e1fc12 100644
--- a/drivers/media/video/bt8xx/Kconfig
+++ b/drivers/media/video/bt8xx/Kconfig
@@ -1,10 +1,10 @@
1config VIDEO_BT848 1config VIDEO_BT848
2 tristate "BT848 Video For Linux" 2 tristate "BT848 Video For Linux"
3 depends on VIDEO_DEV && PCI && I2C && VIDEO_V4L2 && INPUT 3 depends on VIDEO_DEV && PCI && I2C && VIDEO_V4L2
4 select I2C_ALGOBIT 4 select I2C_ALGOBIT
5 select VIDEO_BTCX 5 select VIDEO_BTCX
6 select VIDEOBUF_DMA_SG 6 select VIDEOBUF_DMA_SG
7 depends on VIDEO_IR 7 depends on RC_CORE
8 select VIDEO_TUNER 8 select VIDEO_TUNER
9 select VIDEO_TVEEPROM 9 select VIDEO_TVEEPROM
10 select VIDEO_MSP3400 if VIDEO_HELPER_CHIPS_AUTO 10 select VIDEO_MSP3400 if VIDEO_HELPER_CHIPS_AUTO
diff --git a/drivers/media/video/bt8xx/bttv-driver.c b/drivers/media/video/bt8xx/bttv-driver.c
index 0902ec041c7a..849cd170b821 100644
--- a/drivers/media/video/bt8xx/bttv-driver.c
+++ b/drivers/media/video/bt8xx/bttv-driver.c
@@ -55,7 +55,7 @@
55#include <asm/io.h> 55#include <asm/io.h>
56#include <asm/byteorder.h> 56#include <asm/byteorder.h>
57 57
58#include <media/rds.h> 58#include <media/saa6588.h>
59 59
60 60
61unsigned int bttv_num; /* number of Bt848s in use */ 61unsigned int bttv_num; /* number of Bt848s in use */
@@ -2597,31 +2597,6 @@ static int bttv_s_fmt_vid_overlay(struct file *file, void *priv,
2597 return setup_window_lock(fh, btv, &f->fmt.win, 1); 2597 return setup_window_lock(fh, btv, &f->fmt.win, 1);
2598} 2598}
2599 2599
2600#ifdef CONFIG_VIDEO_V4L1_COMPAT
2601static int vidiocgmbuf(struct file *file, void *priv, struct video_mbuf *mbuf)
2602{
2603 int retval;
2604 unsigned int i;
2605 struct bttv_fh *fh = priv;
2606
2607 retval = __videobuf_mmap_setup(&fh->cap, gbuffers, gbufsize,
2608 V4L2_MEMORY_MMAP);
2609 if (retval < 0) {
2610 return retval;
2611 }
2612
2613 gbuffers = retval;
2614 memset(mbuf, 0, sizeof(*mbuf));
2615 mbuf->frames = gbuffers;
2616 mbuf->size = gbuffers * gbufsize;
2617
2618 for (i = 0; i < gbuffers; i++)
2619 mbuf->offsets[i] = i * gbufsize;
2620
2621 return 0;
2622}
2623#endif
2624
2625static int bttv_querycap(struct file *file, void *priv, 2600static int bttv_querycap(struct file *file, void *priv,
2626 struct v4l2_capability *cap) 2601 struct v4l2_capability *cap)
2627{ 2602{
@@ -3354,9 +3329,6 @@ static const struct v4l2_ioctl_ops bttv_ioctl_ops = {
3354 .vidioc_streamoff = bttv_streamoff, 3329 .vidioc_streamoff = bttv_streamoff,
3355 .vidioc_g_tuner = bttv_g_tuner, 3330 .vidioc_g_tuner = bttv_g_tuner,
3356 .vidioc_s_tuner = bttv_s_tuner, 3331 .vidioc_s_tuner = bttv_s_tuner,
3357#ifdef CONFIG_VIDEO_V4L1_COMPAT
3358 .vidiocgmbuf = vidiocgmbuf,
3359#endif
3360 .vidioc_g_crop = bttv_g_crop, 3332 .vidioc_g_crop = bttv_g_crop,
3361 .vidioc_s_crop = bttv_s_crop, 3333 .vidioc_s_crop = bttv_s_crop,
3362 .vidioc_g_fbuf = bttv_g_fbuf, 3334 .vidioc_g_fbuf = bttv_g_fbuf,
@@ -3416,7 +3388,7 @@ static int radio_release(struct file *file)
3416{ 3388{
3417 struct bttv_fh *fh = file->private_data; 3389 struct bttv_fh *fh = file->private_data;
3418 struct bttv *btv = fh->btv; 3390 struct bttv *btv = fh->btv;
3419 struct rds_command cmd; 3391 struct saa6588_command cmd;
3420 3392
3421 v4l2_prio_close(&btv->prio, fh->prio); 3393 v4l2_prio_close(&btv->prio, fh->prio);
3422 file->private_data = NULL; 3394 file->private_data = NULL;
@@ -3424,7 +3396,7 @@ static int radio_release(struct file *file)
3424 3396
3425 btv->radio_user--; 3397 btv->radio_user--;
3426 3398
3427 bttv_call_all(btv, core, ioctl, RDS_CMD_CLOSE, &cmd); 3399 bttv_call_all(btv, core, ioctl, SAA6588_CMD_CLOSE, &cmd);
3428 3400
3429 return 0; 3401 return 0;
3430} 3402}
@@ -3551,13 +3523,13 @@ static ssize_t radio_read(struct file *file, char __user *data,
3551{ 3523{
3552 struct bttv_fh *fh = file->private_data; 3524 struct bttv_fh *fh = file->private_data;
3553 struct bttv *btv = fh->btv; 3525 struct bttv *btv = fh->btv;
3554 struct rds_command cmd; 3526 struct saa6588_command cmd;
3555 cmd.block_count = count/3; 3527 cmd.block_count = count/3;
3556 cmd.buffer = data; 3528 cmd.buffer = data;
3557 cmd.instance = file; 3529 cmd.instance = file;
3558 cmd.result = -ENODEV; 3530 cmd.result = -ENODEV;
3559 3531
3560 bttv_call_all(btv, core, ioctl, RDS_CMD_READ, &cmd); 3532 bttv_call_all(btv, core, ioctl, SAA6588_CMD_READ, &cmd);
3561 3533
3562 return cmd.result; 3534 return cmd.result;
3563} 3535}
@@ -3566,11 +3538,11 @@ static unsigned int radio_poll(struct file *file, poll_table *wait)
3566{ 3538{
3567 struct bttv_fh *fh = file->private_data; 3539 struct bttv_fh *fh = file->private_data;
3568 struct bttv *btv = fh->btv; 3540 struct bttv *btv = fh->btv;
3569 struct rds_command cmd; 3541 struct saa6588_command cmd;
3570 cmd.instance = file; 3542 cmd.instance = file;
3571 cmd.event_list = wait; 3543 cmd.event_list = wait;
3572 cmd.result = -ENODEV; 3544 cmd.result = -ENODEV;
3573 bttv_call_all(btv, core, ioctl, RDS_CMD_POLL, &cmd); 3545 bttv_call_all(btv, core, ioctl, SAA6588_CMD_POLL, &cmd);
3574 3546
3575 return cmd.result; 3547 return cmd.result;
3576} 3548}
@@ -4041,9 +4013,6 @@ static irqreturn_t bttv_irq(int irq, void *dev_id)
4041 4013
4042 btv=(struct bttv *)dev_id; 4014 btv=(struct bttv *)dev_id;
4043 4015
4044 if (btv->custom_irq)
4045 handled = btv->custom_irq(btv);
4046
4047 count=0; 4016 count=0;
4048 while (1) { 4017 while (1) {
4049 /* get/clear interrupt status bits */ 4018 /* get/clear interrupt status bits */
@@ -4079,7 +4048,6 @@ static irqreturn_t bttv_irq(int irq, void *dev_id)
4079 btv->field_count++; 4048 btv->field_count++;
4080 4049
4081 if ((astat & BT848_INT_GPINT) && btv->remote) { 4050 if ((astat & BT848_INT_GPINT) && btv->remote) {
4082 wake_up(&btv->gpioq);
4083 bttv_input_irq(btv); 4051 bttv_input_irq(btv);
4084 } 4052 }
4085 4053
@@ -4284,7 +4252,6 @@ static int __devinit bttv_probe(struct pci_dev *dev,
4284 mutex_init(&btv->lock); 4252 mutex_init(&btv->lock);
4285 spin_lock_init(&btv->s_lock); 4253 spin_lock_init(&btv->s_lock);
4286 spin_lock_init(&btv->gpio_lock); 4254 spin_lock_init(&btv->gpio_lock);
4287 init_waitqueue_head(&btv->gpioq);
4288 init_waitqueue_head(&btv->i2c_queue); 4255 init_waitqueue_head(&btv->i2c_queue);
4289 INIT_LIST_HEAD(&btv->c.subs); 4256 INIT_LIST_HEAD(&btv->c.subs);
4290 INIT_LIST_HEAD(&btv->capture); 4257 INIT_LIST_HEAD(&btv->capture);
@@ -4472,7 +4439,6 @@ static void __devexit bttv_remove(struct pci_dev *pci_dev)
4472 4439
4473 /* tell gpio modules we are leaving ... */ 4440 /* tell gpio modules we are leaving ... */
4474 btv->shutdown=1; 4441 btv->shutdown=1;
4475 wake_up(&btv->gpioq);
4476 bttv_input_fini(btv); 4442 bttv_input_fini(btv);
4477 bttv_sub_del_devices(&btv->c); 4443 bttv_sub_del_devices(&btv->c);
4478 4444
diff --git a/drivers/media/video/bt8xx/bttv-input.c b/drivers/media/video/bt8xx/bttv-input.c
index 6bf05a7dc5f9..97793b960600 100644
--- a/drivers/media/video/bt8xx/bttv-input.c
+++ b/drivers/media/video/bt8xx/bttv-input.c
@@ -31,15 +31,9 @@
31 31
32static int ir_debug; 32static int ir_debug;
33module_param(ir_debug, int, 0644); 33module_param(ir_debug, int, 0644);
34static int repeat_delay = 500;
35module_param(repeat_delay, int, 0644);
36static int repeat_period = 33;
37module_param(repeat_period, int, 0644);
38 34
39static int ir_rc5_remote_gap = 885; 35static int ir_rc5_remote_gap = 885;
40module_param(ir_rc5_remote_gap, int, 0644); 36module_param(ir_rc5_remote_gap, int, 0644);
41static int ir_rc5_key_timeout = 200;
42module_param(ir_rc5_key_timeout, int, 0644);
43 37
44#undef dprintk 38#undef dprintk
45#define dprintk(arg...) do { \ 39#define dprintk(arg...) do { \
@@ -55,7 +49,7 @@ module_param(ir_rc5_key_timeout, int, 0644);
55 49
56static void ir_handle_key(struct bttv *btv) 50static void ir_handle_key(struct bttv *btv)
57{ 51{
58 struct card_ir *ir = btv->remote; 52 struct bttv_ir *ir = btv->remote;
59 u32 gpio,data; 53 u32 gpio,data;
60 54
61 /* read gpio value */ 55 /* read gpio value */
@@ -74,23 +68,22 @@ static void ir_handle_key(struct bttv *btv)
74 (gpio & ir->mask_keydown) ? " down" : "", 68 (gpio & ir->mask_keydown) ? " down" : "",
75 (gpio & ir->mask_keyup) ? " up" : ""); 69 (gpio & ir->mask_keyup) ? " up" : "");
76 70
77 if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) || 71 if ((ir->mask_keydown && (gpio & ir->mask_keydown)) ||
78 (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) { 72 (ir->mask_keyup && !(gpio & ir->mask_keyup))) {
79 ir_input_keydown(ir->dev, &ir->ir, data); 73 rc_keydown_notimeout(ir->dev, data, 0);
80 } else { 74 } else {
81 /* HACK: Probably, ir->mask_keydown is missing 75 /* HACK: Probably, ir->mask_keydown is missing
82 for this board */ 76 for this board */
83 if (btv->c.type == BTTV_BOARD_WINFAST2000) 77 if (btv->c.type == BTTV_BOARD_WINFAST2000)
84 ir_input_keydown(ir->dev, &ir->ir, data); 78 rc_keydown_notimeout(ir->dev, data, 0);
85 79
86 ir_input_nokey(ir->dev,&ir->ir); 80 rc_keyup(ir->dev);
87 } 81 }
88
89} 82}
90 83
91static void ir_enltv_handle_key(struct bttv *btv) 84static void ir_enltv_handle_key(struct bttv *btv)
92{ 85{
93 struct card_ir *ir = btv->remote; 86 struct bttv_ir *ir = btv->remote;
94 u32 gpio, data, keyup; 87 u32 gpio, data, keyup;
95 88
96 /* read gpio value */ 89 /* read gpio value */
@@ -107,9 +100,9 @@ static void ir_enltv_handle_key(struct bttv *btv)
107 gpio, data, 100 gpio, data,
108 (gpio & ir->mask_keyup) ? " up" : "up/down"); 101 (gpio & ir->mask_keyup) ? " up" : "up/down");
109 102
110 ir_input_keydown(ir->dev, &ir->ir, data); 103 rc_keydown_notimeout(ir->dev, data, 0);
111 if (keyup) 104 if (keyup)
112 ir_input_nokey(ir->dev, &ir->ir); 105 rc_keyup(ir->dev);
113 } else { 106 } else {
114 if ((ir->last_gpio & 1 << 31) == keyup) 107 if ((ir->last_gpio & 1 << 31) == keyup)
115 return; 108 return;
@@ -119,26 +112,30 @@ static void ir_enltv_handle_key(struct bttv *btv)
119 (gpio & ir->mask_keyup) ? " up" : "down"); 112 (gpio & ir->mask_keyup) ? " up" : "down");
120 113
121 if (keyup) 114 if (keyup)
122 ir_input_nokey(ir->dev, &ir->ir); 115 rc_keyup(ir->dev);
123 else 116 else
124 ir_input_keydown(ir->dev, &ir->ir, data); 117 rc_keydown_notimeout(ir->dev, data, 0);
125 } 118 }
126 119
127 ir->last_gpio = data | keyup; 120 ir->last_gpio = data | keyup;
128} 121}
129 122
123static int bttv_rc5_irq(struct bttv *btv);
124
130void bttv_input_irq(struct bttv *btv) 125void bttv_input_irq(struct bttv *btv)
131{ 126{
132 struct card_ir *ir = btv->remote; 127 struct bttv_ir *ir = btv->remote;
133 128
134 if (!ir->polling) 129 if (ir->rc5_gpio)
130 bttv_rc5_irq(btv);
131 else if (!ir->polling)
135 ir_handle_key(btv); 132 ir_handle_key(btv);
136} 133}
137 134
138static void bttv_input_timer(unsigned long data) 135static void bttv_input_timer(unsigned long data)
139{ 136{
140 struct bttv *btv = (struct bttv*)data; 137 struct bttv *btv = (struct bttv*)data;
141 struct card_ir *ir = btv->remote; 138 struct bttv_ir *ir = btv->remote;
142 139
143 if (btv->c.type == BTTV_BOARD_ENLTV_FM_2) 140 if (btv->c.type == BTTV_BOARD_ENLTV_FM_2)
144 ir_enltv_handle_key(btv); 141 ir_enltv_handle_key(btv);
@@ -147,11 +144,109 @@ static void bttv_input_timer(unsigned long data)
147 mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling)); 144 mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling));
148} 145}
149 146
150/* ---------------------------------------------------------------*/ 147/*
148 * FIXME: Nebula digi uses the legacy way to decode RC5, instead of relying
149 * on the rc-core way. As we need to be sure that both IRQ transitions are
150 * properly triggered, Better to touch it only with this hardware for
151 * testing.
152 */
153
154#define RC5_START(x) (((x) >> 12) & 3)
155#define RC5_TOGGLE(x) (((x) >> 11) & 1)
156#define RC5_ADDR(x) (((x) >> 6) & 31)
157#define RC5_INSTR(x) ((x) & 63)
158
159/* decode raw bit pattern to RC5 code */
160static u32 bttv_rc5_decode(unsigned int code)
161{
162 unsigned int org_code = code;
163 unsigned int pair;
164 unsigned int rc5 = 0;
165 int i;
166
167 for (i = 0; i < 14; ++i) {
168 pair = code & 0x3;
169 code >>= 2;
170
171 rc5 <<= 1;
172 switch (pair) {
173 case 0:
174 case 2:
175 break;
176 case 1:
177 rc5 |= 1;
178 break;
179 case 3:
180 dprintk(KERN_INFO DEVNAME ":rc5_decode(%x) bad code\n",
181 org_code);
182 return 0;
183 }
184 }
185 dprintk(KERN_INFO DEVNAME ":"
186 "code=%x, rc5=%x, start=%x, toggle=%x, address=%x, "
187 "instr=%x\n", rc5, org_code, RC5_START(rc5),
188 RC5_TOGGLE(rc5), RC5_ADDR(rc5), RC5_INSTR(rc5));
189 return rc5;
190}
191
192static void bttv_rc5_timer_end(unsigned long data)
193{
194 struct bttv_ir *ir = (struct bttv_ir *)data;
195 struct timeval tv;
196 unsigned long current_jiffies;
197 u32 gap;
198 u32 rc5 = 0;
199
200 /* get time */
201 current_jiffies = jiffies;
202 do_gettimeofday(&tv);
203
204 /* avoid overflow with gap >1s */
205 if (tv.tv_sec - ir->base_time.tv_sec > 1) {
206 gap = 200000;
207 } else {
208 gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
209 tv.tv_usec - ir->base_time.tv_usec;
210 }
211
212 /* signal we're ready to start a new code */
213 ir->active = false;
214
215 /* Allow some timer jitter (RC5 is ~24ms anyway so this is ok) */
216 if (gap < 28000) {
217 dprintk(KERN_INFO DEVNAME ": spurious timer_end\n");
218 return;
219 }
220
221 if (ir->last_bit < 20) {
222 /* ignore spurious codes (caused by light/other remotes) */
223 dprintk(KERN_INFO DEVNAME ": short code: %x\n", ir->code);
224 } else {
225 ir->code = (ir->code << ir->shift_by) | 1;
226 rc5 = bttv_rc5_decode(ir->code);
227
228 /* two start bits? */
229 if (RC5_START(rc5) != ir->start) {
230 printk(KERN_INFO DEVNAME ":"
231 " rc5 start bits invalid: %u\n", RC5_START(rc5));
232
233 /* right address? */
234 } else if (RC5_ADDR(rc5) == ir->addr) {
235 u32 toggle = RC5_TOGGLE(rc5);
236 u32 instr = RC5_INSTR(rc5);
237
238 /* Good code */
239 rc_keydown(ir->dev, instr, toggle);
240 dprintk(KERN_INFO DEVNAME ":"
241 " instruction %x, toggle %x\n",
242 instr, toggle);
243 }
244 }
245}
151 246
152static int bttv_rc5_irq(struct bttv *btv) 247static int bttv_rc5_irq(struct bttv *btv)
153{ 248{
154 struct card_ir *ir = btv->remote; 249 struct bttv_ir *ir = btv->remote;
155 struct timeval tv; 250 struct timeval tv;
156 u32 gpio; 251 u32 gpio;
157 u32 gap; 252 u32 gap;
@@ -160,10 +255,6 @@ static int bttv_rc5_irq(struct bttv *btv)
160 /* read gpio port */ 255 /* read gpio port */
161 gpio = bttv_gpio_read(&btv->c); 256 gpio = bttv_gpio_read(&btv->c);
162 257
163 /* remote IRQ? */
164 if (!(gpio & 0x20))
165 return 0;
166
167 /* get time of bit */ 258 /* get time of bit */
168 current_jiffies = jiffies; 259 current_jiffies = jiffies;
169 do_gettimeofday(&tv); 260 do_gettimeofday(&tv);
@@ -176,6 +267,13 @@ static int bttv_rc5_irq(struct bttv *btv)
176 tv.tv_usec - ir->base_time.tv_usec; 267 tv.tv_usec - ir->base_time.tv_usec;
177 } 268 }
178 269
270 dprintk(KERN_INFO DEVNAME ": RC5 IRQ: gap %d us for %s\n",
271 gap, (gpio & 0x20) ? "mark" : "space");
272
273 /* remote IRQ? */
274 if (!(gpio & 0x20))
275 return 0;
276
179 /* active code => add bit */ 277 /* active code => add bit */
180 if (ir->active) { 278 if (ir->active) {
181 /* only if in the code (otherwise spurious IRQ or timer 279 /* only if in the code (otherwise spurious IRQ or timer
@@ -187,13 +285,12 @@ static int bttv_rc5_irq(struct bttv *btv)
187 } 285 }
188 /* starting new code */ 286 /* starting new code */
189 } else { 287 } else {
190 ir->active = 1; 288 ir->active = true;
191 ir->code = 0; 289 ir->code = 0;
192 ir->base_time = tv; 290 ir->base_time = tv;
193 ir->last_bit = 0; 291 ir->last_bit = 0;
194 292
195 mod_timer(&ir->timer_end, 293 mod_timer(&ir->timer, current_jiffies + msecs_to_jiffies(30));
196 current_jiffies + msecs_to_jiffies(30));
197 } 294 }
198 295
199 /* toggle GPIO pin 4 to reset the irq */ 296 /* toggle GPIO pin 4 to reset the irq */
@@ -204,7 +301,7 @@ static int bttv_rc5_irq(struct bttv *btv)
204 301
205/* ---------------------------------------------------------------------- */ 302/* ---------------------------------------------------------------------- */
206 303
207static void bttv_ir_start(struct bttv *btv, struct card_ir *ir) 304static void bttv_ir_start(struct bttv *btv, struct bttv_ir *ir)
208{ 305{
209 if (ir->polling) { 306 if (ir->polling) {
210 setup_timer(&ir->timer, bttv_input_timer, (unsigned long)btv); 307 setup_timer(&ir->timer, bttv_input_timer, (unsigned long)btv);
@@ -212,17 +309,10 @@ static void bttv_ir_start(struct bttv *btv, struct card_ir *ir)
212 add_timer(&ir->timer); 309 add_timer(&ir->timer);
213 } else if (ir->rc5_gpio) { 310 } else if (ir->rc5_gpio) {
214 /* set timer_end for code completion */ 311 /* set timer_end for code completion */
215 init_timer(&ir->timer_end); 312 setup_timer(&ir->timer, bttv_rc5_timer_end, (unsigned long)ir);
216 ir->timer_end.function = ir_rc5_timer_end;
217 ir->timer_end.data = (unsigned long)ir;
218
219 init_timer(&ir->timer_keyup);
220 ir->timer_keyup.function = ir_rc5_timer_keyup;
221 ir->timer_keyup.data = (unsigned long)ir;
222 ir->shift_by = 1; 313 ir->shift_by = 1;
223 ir->start = 3; 314 ir->start = 3;
224 ir->addr = 0x0; 315 ir->addr = 0x0;
225 ir->rc5_key_timeout = ir_rc5_key_timeout;
226 ir->rc5_remote_gap = ir_rc5_remote_gap; 316 ir->rc5_remote_gap = ir_rc5_remote_gap;
227 } 317 }
228} 318}
@@ -237,7 +327,7 @@ static void bttv_ir_stop(struct bttv *btv)
237 if (btv->remote->rc5_gpio) { 327 if (btv->remote->rc5_gpio) {
238 u32 gpio; 328 u32 gpio;
239 329
240 del_timer_sync(&btv->remote->timer_end); 330 del_timer_sync(&btv->remote->timer);
241 flush_scheduled_work(); 331 flush_scheduled_work();
242 332
243 gpio = bttv_gpio_read(&btv->c); 333 gpio = bttv_gpio_read(&btv->c);
@@ -264,6 +354,18 @@ static int get_key_pv951(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
264 return 0; 354 return 0;
265 dprintk(KERN_INFO DEVNAME ": key %02x\n", b); 355 dprintk(KERN_INFO DEVNAME ": key %02x\n", b);
266 356
357 /*
358 * NOTE:
359 * lirc_i2c maps the pv951 code as:
360 * addr = 0x61D6
361 * cmd = bit_reverse (b)
362 * So, it seems that this device uses NEC extended
363 * I decided to not fix the table, due to two reasons:
364 * 1) Without the actual device, this is only a guess;
365 * 2) As the addr is not reported via I2C, nor can be changed,
366 * the device is bound to the vendor-provided RC.
367 */
368
267 *ir_key = b; 369 *ir_key = b;
268 *ir_raw = b; 370 *ir_raw = b;
269 return 1; 371 return 1;
@@ -290,16 +392,15 @@ void __devinit init_bttv_i2c_ir(struct bttv *btv)
290 btv->init_data.name = "PV951"; 392 btv->init_data.name = "PV951";
291 btv->init_data.get_key = get_key_pv951; 393 btv->init_data.get_key = get_key_pv951;
292 btv->init_data.ir_codes = RC_MAP_PV951; 394 btv->init_data.ir_codes = RC_MAP_PV951;
293 btv->init_data.type = IR_TYPE_OTHER;
294 info.addr = 0x4b; 395 info.addr = 0x4b;
295 break; 396 break;
296 default: 397 default:
297 /* 398 /*
298 * The external IR receiver is at i2c address 0x34 (0x35 for 399 * The external IR receiver is at i2c address 0x34 (0x35 for
299 * reads). Future Hauppauge cards will have an internal 400 * reads). Future Hauppauge cards will have an internal
300 * receiver at 0x30 (0x31 for reads). In theory, both can be 401 * receiver at 0x30 (0x31 for reads). In theory, both can be
301 * fitted, and Hauppauge suggest an external overrides an 402 * fitted, and Hauppauge suggest an external overrides an
302 * internal. 403 * internal.
303 * That's why we probe 0x1a (~0x34) first. CB 404 * That's why we probe 0x1a (~0x34) first. CB
304 */ 405 */
305 406
@@ -324,18 +425,17 @@ int __devexit fini_bttv_i2c(struct bttv *btv)
324 425
325int bttv_input_init(struct bttv *btv) 426int bttv_input_init(struct bttv *btv)
326{ 427{
327 struct card_ir *ir; 428 struct bttv_ir *ir;
328 char *ir_codes = NULL; 429 char *ir_codes = NULL;
329 struct input_dev *input_dev; 430 struct rc_dev *rc;
330 u64 ir_type = IR_TYPE_OTHER;
331 int err = -ENOMEM; 431 int err = -ENOMEM;
332 432
333 if (!btv->has_remote) 433 if (!btv->has_remote)
334 return -ENODEV; 434 return -ENODEV;
335 435
336 ir = kzalloc(sizeof(*ir),GFP_KERNEL); 436 ir = kzalloc(sizeof(*ir),GFP_KERNEL);
337 input_dev = input_allocate_device(); 437 rc = rc_allocate_device();
338 if (!ir || !input_dev) 438 if (!ir || !rc)
339 goto err_out_free; 439 goto err_out_free;
340 440
341 /* detect & configure */ 441 /* detect & configure */
@@ -398,8 +498,7 @@ int bttv_input_init(struct bttv *btv)
398 break; 498 break;
399 case BTTV_BOARD_NEBULA_DIGITV: 499 case BTTV_BOARD_NEBULA_DIGITV:
400 ir_codes = RC_MAP_NEBULA; 500 ir_codes = RC_MAP_NEBULA;
401 btv->custom_irq = bttv_rc5_irq; 501 ir->rc5_gpio = true;
402 ir->rc5_gpio = 1;
403 break; 502 break;
404 case BTTV_BOARD_MACHTV_MAGICTV: 503 case BTTV_BOARD_MACHTV_MAGICTV:
405 ir_codes = RC_MAP_APAC_VIEWCOMP; 504 ir_codes = RC_MAP_APAC_VIEWCOMP;
@@ -441,48 +540,43 @@ int bttv_input_init(struct bttv *btv)
441 } 540 }
442 541
443 /* init input device */ 542 /* init input device */
444 ir->dev = input_dev; 543 ir->dev = rc;
445 544
446 snprintf(ir->name, sizeof(ir->name), "bttv IR (card=%d)", 545 snprintf(ir->name, sizeof(ir->name), "bttv IR (card=%d)",
447 btv->c.type); 546 btv->c.type);
448 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0", 547 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0",
449 pci_name(btv->c.pci)); 548 pci_name(btv->c.pci));
450 549
451 err = ir_input_init(input_dev, &ir->ir, ir_type); 550 rc->input_name = ir->name;
452 if (err < 0) 551 rc->input_phys = ir->phys;
453 goto err_out_free; 552 rc->input_id.bustype = BUS_PCI;
454 553 rc->input_id.version = 1;
455 input_dev->name = ir->name;
456 input_dev->phys = ir->phys;
457 input_dev->id.bustype = BUS_PCI;
458 input_dev->id.version = 1;
459 if (btv->c.pci->subsystem_vendor) { 554 if (btv->c.pci->subsystem_vendor) {
460 input_dev->id.vendor = btv->c.pci->subsystem_vendor; 555 rc->input_id.vendor = btv->c.pci->subsystem_vendor;
461 input_dev->id.product = btv->c.pci->subsystem_device; 556 rc->input_id.product = btv->c.pci->subsystem_device;
462 } else { 557 } else {
463 input_dev->id.vendor = btv->c.pci->vendor; 558 rc->input_id.vendor = btv->c.pci->vendor;
464 input_dev->id.product = btv->c.pci->device; 559 rc->input_id.product = btv->c.pci->device;
465 } 560 }
466 input_dev->dev.parent = &btv->c.pci->dev; 561 rc->dev.parent = &btv->c.pci->dev;
562 rc->map_name = ir_codes;
563 rc->driver_name = MODULE_NAME;
467 564
468 btv->remote = ir; 565 btv->remote = ir;
469 bttv_ir_start(btv, ir); 566 bttv_ir_start(btv, ir);
470 567
471 /* all done */ 568 /* all done */
472 err = ir_input_register(btv->remote->dev, ir_codes, NULL, MODULE_NAME); 569 err = rc_register_device(rc);
473 if (err) 570 if (err)
474 goto err_out_stop; 571 goto err_out_stop;
475 572
476 /* the remote isn't as bouncy as a keyboard */
477 ir->dev->rep[REP_DELAY] = repeat_delay;
478 ir->dev->rep[REP_PERIOD] = repeat_period;
479
480 return 0; 573 return 0;
481 574
482 err_out_stop: 575 err_out_stop:
483 bttv_ir_stop(btv); 576 bttv_ir_stop(btv);
484 btv->remote = NULL; 577 btv->remote = NULL;
485 err_out_free: 578 err_out_free:
579 rc_free_device(rc);
486 kfree(ir); 580 kfree(ir);
487 return err; 581 return err;
488} 582}
@@ -493,7 +587,7 @@ void bttv_input_fini(struct bttv *btv)
493 return; 587 return;
494 588
495 bttv_ir_stop(btv); 589 bttv_ir_stop(btv);
496 ir_input_unregister(btv->remote->dev); 590 rc_unregister_device(btv->remote->dev);
497 kfree(btv->remote); 591 kfree(btv->remote);
498 btv->remote = NULL; 592 btv->remote = NULL;
499} 593}
diff --git a/drivers/media/video/bt8xx/bttv.h b/drivers/media/video/bt8xx/bttv.h
index 6fd2a8ebda1e..fd62bf15d779 100644
--- a/drivers/media/video/bt8xx/bttv.h
+++ b/drivers/media/video/bt8xx/bttv.h
@@ -17,7 +17,6 @@
17#include <linux/videodev2.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/v4l2-device.h>
20#include <media/ir-common.h>
21#include <media/i2c-addr.h> 20#include <media/i2c-addr.h>
22#include <media/tuner.h> 21#include <media/tuner.h>
23 22
diff --git a/drivers/media/video/bt8xx/bttvp.h b/drivers/media/video/bt8xx/bttvp.h
index d1e26a448ed2..9b776faf0741 100644
--- a/drivers/media/video/bt8xx/bttvp.h
+++ b/drivers/media/video/bt8xx/bttvp.h
@@ -41,7 +41,7 @@
41#include <linux/device.h> 41#include <linux/device.h>
42#include <media/videobuf-dma-sg.h> 42#include <media/videobuf-dma-sg.h>
43#include <media/tveeprom.h> 43#include <media/tveeprom.h>
44#include <media/ir-common.h> 44#include <media/rc-core.h>
45#include <media/ir-kbd-i2c.h> 45#include <media/ir-kbd-i2c.h>
46 46
47#include "bt848.h" 47#include "bt848.h"
@@ -120,6 +120,33 @@ struct bttv_format {
120 int hshift,vshift; /* for planar modes */ 120 int hshift,vshift; /* for planar modes */
121}; 121};
122 122
123struct bttv_ir {
124 struct rc_dev *dev;
125 struct timer_list timer;
126
127 char name[32];
128 char phys[32];
129
130 /* Usual gpio signalling */
131 u32 mask_keycode;
132 u32 mask_keydown;
133 u32 mask_keyup;
134 u32 polling;
135 u32 last_gpio;
136 int shift_by;
137 int start; // What should RC5_START() be
138 int addr; // What RC5_ADDR() should be.
139 int rc5_remote_gap;
140
141 /* RC5 gpio */
142 bool rc5_gpio; /* Is RC5 legacy GPIO enabled? */
143 u32 last_bit; /* last raw bit seen */
144 u32 code; /* raw code under construction */
145 struct timeval base_time; /* time of last seen code */
146 bool active; /* building raw code */
147};
148
149
123/* ---------------------------------------------------------- */ 150/* ---------------------------------------------------------- */
124 151
125struct bttv_geometry { 152struct bttv_geometry {
@@ -305,7 +332,6 @@ struct bttv_pll_info {
305/* for gpio-connected remote control */ 332/* for gpio-connected remote control */
306struct bttv_input { 333struct bttv_input {
307 struct input_dev *dev; 334 struct input_dev *dev;
308 struct ir_input_state ir;
309 char name[32]; 335 char name[32];
310 char phys[32]; 336 char phys[32];
311 u32 mask_keycode; 337 u32 mask_keycode;
@@ -338,12 +364,10 @@ struct bttv {
338 struct bttv_pll_info pll; 364 struct bttv_pll_info pll;
339 int triton1; 365 int triton1;
340 int gpioirq; 366 int gpioirq;
341 int (*custom_irq)(struct bttv *btv);
342 367
343 int use_i2c_hw; 368 int use_i2c_hw;
344 369
345 /* old gpio interface */ 370 /* old gpio interface */
346 wait_queue_head_t gpioq;
347 int shutdown; 371 int shutdown;
348 372
349 void (*volume_gpio)(struct bttv *btv, __u16 volume); 373 void (*volume_gpio)(struct bttv *btv, __u16 volume);
@@ -368,7 +392,7 @@ struct bttv {
368 392
369 /* infrared remote */ 393 /* infrared remote */
370 int has_remote; 394 int has_remote;
371 struct card_ir *remote; 395 struct bttv_ir *remote;
372 396
373 /* I2C remote data */ 397 /* I2C remote data */
374 struct IR_i2c_init_data init_data; 398 struct IR_i2c_init_data init_data;
diff --git a/drivers/media/video/cafe_ccic.c b/drivers/media/video/cafe_ccic.c
index 0dfff50891e4..789087cd6a9c 100644
--- a/drivers/media/video/cafe_ccic.c
+++ b/drivers/media/video/cafe_ccic.c
@@ -859,8 +859,6 @@ static int cafe_cam_configure(struct cafe_camera *cam)
859 struct v4l2_mbus_framefmt mbus_fmt; 859 struct v4l2_mbus_framefmt mbus_fmt;
860 int ret; 860 int ret;
861 861
862 if (cam->state != S_IDLE)
863 return -EINVAL;
864 v4l2_fill_mbus_format(&mbus_fmt, &cam->pix_format, cam->mbus_code); 862 v4l2_fill_mbus_format(&mbus_fmt, &cam->pix_format, cam->mbus_code);
865 ret = sensor_call(cam, core, init, 0); 863 ret = sensor_call(cam, core, init, 0);
866 if (ret == 0) 864 if (ret == 0)
@@ -2196,12 +2194,13 @@ static int cafe_pci_resume(struct pci_dev *pdev)
2196 return ret; 2194 return ret;
2197 } 2195 }
2198 cafe_ctlr_init(cam); 2196 cafe_ctlr_init(cam);
2199 cafe_ctlr_power_down(cam);
2200 2197
2201 mutex_lock(&cam->s_mutex); 2198 mutex_lock(&cam->s_mutex);
2202 if (cam->users > 0) { 2199 if (cam->users > 0) {
2203 cafe_ctlr_power_up(cam); 2200 cafe_ctlr_power_up(cam);
2204 __cafe_cam_reset(cam); 2201 __cafe_cam_reset(cam);
2202 } else {
2203 cafe_ctlr_power_down(cam);
2205 } 2204 }
2206 mutex_unlock(&cam->s_mutex); 2205 mutex_unlock(&cam->s_mutex);
2207 2206
diff --git a/drivers/media/video/cpia2/cpia2_v4l.c b/drivers/media/video/cpia2/cpia2_v4l.c
index 46b433bbf2c1..7edf80b0d01a 100644
--- a/drivers/media/video/cpia2/cpia2_v4l.c
+++ b/drivers/media/video/cpia2/cpia2_v4l.c
@@ -419,28 +419,6 @@ static int sync(struct camera_data *cam, int frame_nr)
419 419
420/****************************************************************************** 420/******************************************************************************
421 * 421 *
422 * ioctl_get_mbuf
423 *
424 *****************************************************************************/
425#ifdef CONFIG_VIDEO_V4L1_COMPAT
426static int ioctl_get_mbuf(void *arg, struct camera_data *cam)
427{
428 struct video_mbuf *vm;
429 int i;
430 vm = arg;
431
432 memset(vm, 0, sizeof(*vm));
433 vm->size = cam->frame_size*cam->num_frames;
434 vm->frames = cam->num_frames;
435 for (i = 0; i < cam->num_frames; i++)
436 vm->offsets[i] = cam->frame_size * i;
437
438 return 0;
439}
440#endif
441
442/******************************************************************************
443 *
444 * ioctl_set_gpio 422 * ioctl_set_gpio
445 * 423 *
446 *****************************************************************************/ 424 *****************************************************************************/
@@ -1380,17 +1358,6 @@ static long cpia2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
1380 } 1358 }
1381 break; 1359 break;
1382 } 1360 }
1383#ifdef CONFIG_VIDEO_V4L1_COMPAT
1384 case VIDIOCGMBUF:
1385 {
1386 struct cpia2_fh *fh = file->private_data;
1387 if(fh->prio != V4L2_PRIORITY_RECORD) {
1388 mutex_unlock(&cam->busy_lock);
1389 return -EBUSY;
1390 }
1391 break;
1392 }
1393#endif
1394 default: 1361 default:
1395 break; 1362 break;
1396 } 1363 }
@@ -1400,11 +1367,6 @@ static long cpia2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
1400 case CPIA2_IOC_SET_GPIO: 1367 case CPIA2_IOC_SET_GPIO:
1401 retval = ioctl_set_gpio(arg, cam); 1368 retval = ioctl_set_gpio(arg, cam);
1402 break; 1369 break;
1403#ifdef CONFIG_VIDEO_V4L1_COMPAT
1404 case VIDIOCGMBUF: /* mmap interface */
1405 retval = ioctl_get_mbuf(arg, cam);
1406 break;
1407#endif
1408 case VIDIOC_QUERYCAP: 1370 case VIDIOC_QUERYCAP:
1409 retval = ioctl_querycap(arg,cam); 1371 retval = ioctl_querycap(arg,cam);
1410 break; 1372 break;
diff --git a/drivers/media/video/cx18/Kconfig b/drivers/media/video/cx18/Kconfig
index 76c054d1eef9..d9d2f6ad6ffb 100644
--- a/drivers/media/video/cx18/Kconfig
+++ b/drivers/media/video/cx18/Kconfig
@@ -1,9 +1,8 @@
1config VIDEO_CX18 1config VIDEO_CX18
2 tristate "Conexant cx23418 MPEG encoder support" 2 tristate "Conexant cx23418 MPEG encoder support"
3 depends on VIDEO_V4L2 && DVB_CORE && PCI && I2C && EXPERIMENTAL 3 depends on VIDEO_V4L2 && DVB_CORE && PCI && I2C && EXPERIMENTAL
4 depends on INPUT # due to VIDEO_IR
5 select I2C_ALGOBIT 4 select I2C_ALGOBIT
6 depends on VIDEO_IR 5 depends on RC_CORE
7 select VIDEO_TUNER 6 select VIDEO_TUNER
8 select VIDEO_TVEEPROM 7 select VIDEO_TVEEPROM
9 select VIDEO_CX2341X 8 select VIDEO_CX2341X
diff --git a/drivers/media/video/cx18/cx18-cards.c b/drivers/media/video/cx18/cx18-cards.c
index fe1090940b01..87177733cf92 100644
--- a/drivers/media/video/cx18/cx18-cards.c
+++ b/drivers/media/video/cx18/cx18-cards.c
@@ -39,7 +39,7 @@ static struct cx18_card_tuner_i2c cx18_i2c_std = {
39 .tv = { 0x61, 0x60, I2C_CLIENT_END }, 39 .tv = { 0x61, 0x60, I2C_CLIENT_END },
40}; 40};
41 41
42/* Please add new PCI IDs to: http://pci-ids.ucw.cz/ 42/* Please add new PCI IDs to: http://pci-ids.ucw.cz/
43 This keeps the PCI ID database up to date. Note that the entries 43 This keeps the PCI ID database up to date. Note that the entries
44 must be added under vendor 0x4444 (Conexant) as subsystem IDs. 44 must be added under vendor 0x4444 (Conexant) as subsystem IDs.
45 New vendor IDs should still be added to the vendor ID list. */ 45 New vendor IDs should still be added to the vendor ID list. */
@@ -251,6 +251,66 @@ static const struct cx18_card cx18_card_mpc718 = {
251 251
252/* ------------------------------------------------------------------------- */ 252/* ------------------------------------------------------------------------- */
253 253
254/* GoTView PCI */
255
256static const struct cx18_card_pci_info cx18_pci_gotview_dvd3[] = {
257 { PCI_DEVICE_ID_CX23418, CX18_PCI_ID_GOTVIEW, 0x3343 },
258 { 0, 0, 0 }
259};
260
261static const struct cx18_card cx18_card_gotview_dvd3 = {
262 .type = CX18_CARD_GOTVIEW_PCI_DVD3,
263 .name = "GoTView PCI DVD3 Hybrid",
264 .comment = "Experimenters needed for device to work well.\n"
265 "\tTo help, mail the ivtv-devel list (www.ivtvdriver.org).\n",
266 .v4l2_capabilities = CX18_CAP_ENCODER,
267 .hw_audio_ctrl = CX18_HW_418_AV,
268 .hw_muxer = CX18_HW_GPIO_MUX,
269 .hw_all = CX18_HW_TVEEPROM | CX18_HW_418_AV | CX18_HW_TUNER |
270 CX18_HW_GPIO_MUX | CX18_HW_DVB | CX18_HW_GPIO_RESET_CTRL,
271 .video_inputs = {
272 { CX18_CARD_INPUT_VID_TUNER, 0, CX18_AV_COMPOSITE2 },
273 { CX18_CARD_INPUT_SVIDEO1, 1,
274 CX18_AV_SVIDEO_LUMA3 | CX18_AV_SVIDEO_CHROMA4 },
275 { CX18_CARD_INPUT_COMPOSITE1, 1, CX18_AV_COMPOSITE1 },
276 { CX18_CARD_INPUT_SVIDEO2, 2,
277 CX18_AV_SVIDEO_LUMA7 | CX18_AV_SVIDEO_CHROMA8 },
278 { CX18_CARD_INPUT_COMPOSITE2, 2, CX18_AV_COMPOSITE6 },
279 },
280 .audio_inputs = {
281 { CX18_CARD_INPUT_AUD_TUNER, CX18_AV_AUDIO5, 0 },
282 { CX18_CARD_INPUT_LINE_IN1, CX18_AV_AUDIO_SERIAL1, 1 },
283 { CX18_CARD_INPUT_LINE_IN2, CX18_AV_AUDIO_SERIAL2, 1 },
284 },
285 .tuners = {
286 /* XC3028 tuner */
287 { .std = V4L2_STD_ALL, .tuner = TUNER_XC2028 },
288 },
289 /* FIXME - the FM radio is just a guess and driver doesn't use SIF */
290 .radio_input = { CX18_CARD_INPUT_AUD_TUNER, CX18_AV_AUDIO5, 2 },
291 .ddr = {
292 /* Hynix HY5DU283222B DDR RAM */
293 .chip_config = 0x303,
294 .refresh = 0x3bd,
295 .timing1 = 0x36320966,
296 .timing2 = 0x1f,
297 .tune_lane = 0,
298 .initial_emrs = 2,
299 },
300 .gpio_init.initial_value = 0x1,
301 .gpio_init.direction = 0x3,
302
303 .gpio_audio_input = { .mask = 0x3,
304 .tuner = 0x1,
305 .linein = 0x2,
306 .radio = 0x1 },
307 .xceive_pin = 0,
308 .pci_list = cx18_pci_gotview_dvd3,
309 .i2c = &cx18_i2c_std,
310};
311
312/* ------------------------------------------------------------------------- */
313
254/* Conexant Raptor PAL/SECAM: note that this card is analog only! */ 314/* Conexant Raptor PAL/SECAM: note that this card is analog only! */
255 315
256static const struct cx18_card_pci_info cx18_pci_cnxt_raptor_pal[] = { 316static const struct cx18_card_pci_info cx18_pci_cnxt_raptor_pal[] = {
@@ -463,6 +523,7 @@ static const struct cx18_card *cx18_card_list[] = {
463 &cx18_card_toshiba_qosmio_dvbt, 523 &cx18_card_toshiba_qosmio_dvbt,
464 &cx18_card_leadtek_pvr2100, 524 &cx18_card_leadtek_pvr2100,
465 &cx18_card_leadtek_dvr3100h, 525 &cx18_card_leadtek_dvr3100h,
526 &cx18_card_gotview_dvd3
466}; 527};
467 528
468const struct cx18_card *cx18_get_card(u16 index) 529const struct cx18_card *cx18_get_card(u16 index)
@@ -485,7 +546,6 @@ int cx18_get_input(struct cx18 *cx, u16 index, struct v4l2_input *input)
485 "Component 1" 546 "Component 1"
486 }; 547 };
487 548
488 memset(input, 0, sizeof(*input));
489 if (index >= cx->nof_inputs) 549 if (index >= cx->nof_inputs)
490 return -EINVAL; 550 return -EINVAL;
491 input->index = index; 551 input->index = index;
diff --git a/drivers/media/video/cx18/cx18-controls.c b/drivers/media/video/cx18/cx18-controls.c
index 67043c7b452b..97d7b7e100a3 100644
--- a/drivers/media/video/cx18/cx18-controls.c
+++ b/drivers/media/video/cx18/cx18-controls.c
@@ -108,7 +108,7 @@ static int cx18_try_ctrl(struct file *file, void *fh,
108 struct v4l2_ext_control *vctrl) 108 struct v4l2_ext_control *vctrl)
109{ 109{
110 struct v4l2_queryctrl qctrl; 110 struct v4l2_queryctrl qctrl;
111 const char **menu_items = NULL; 111 const char * const *menu_items = NULL;
112 int err; 112 int err;
113 113
114 qctrl.id = vctrl->id; 114 qctrl.id = vctrl->id;
diff --git a/drivers/media/video/cx18/cx18-driver.c b/drivers/media/video/cx18/cx18-driver.c
index df60f27337cf..676e5bef89eb 100644
--- a/drivers/media/video/cx18/cx18-driver.c
+++ b/drivers/media/video/cx18/cx18-driver.c
@@ -156,6 +156,7 @@ MODULE_PARM_DESC(cardtype,
156 "\t\t\t 6 = Toshiba Qosmio DVB-T/Analog\n" 156 "\t\t\t 6 = Toshiba Qosmio DVB-T/Analog\n"
157 "\t\t\t 7 = Leadtek WinFast PVR2100\n" 157 "\t\t\t 7 = Leadtek WinFast PVR2100\n"
158 "\t\t\t 8 = Leadtek WinFast DVR3100 H\n" 158 "\t\t\t 8 = Leadtek WinFast DVR3100 H\n"
159 "\t\t\t 9 = GoTView PCI DVD3 Hybrid\n"
159 "\t\t\t 0 = Autodetect (default)\n" 160 "\t\t\t 0 = Autodetect (default)\n"
160 "\t\t\t-1 = Ignore this card\n\t\t"); 161 "\t\t\t-1 = Ignore this card\n\t\t");
161MODULE_PARM_DESC(pal, "Set PAL standard: B, G, H, D, K, I, M, N, Nc, 60"); 162MODULE_PARM_DESC(pal, "Set PAL standard: B, G, H, D, K, I, M, N, Nc, 60");
@@ -333,6 +334,7 @@ void cx18_read_eeprom(struct cx18 *cx, struct tveeprom *tv)
333 tveeprom_hauppauge_analog(&c, tv, eedata); 334 tveeprom_hauppauge_analog(&c, tv, eedata);
334 break; 335 break;
335 case CX18_CARD_YUAN_MPC718: 336 case CX18_CARD_YUAN_MPC718:
337 case CX18_CARD_GOTVIEW_PCI_DVD3:
336 tv->model = 0x718; 338 tv->model = 0x718;
337 cx18_eeprom_dump(cx, eedata, sizeof(eedata)); 339 cx18_eeprom_dump(cx, eedata, sizeof(eedata));
338 CX18_INFO("eeprom PCI ID: %02x%02x:%02x%02x\n", 340 CX18_INFO("eeprom PCI ID: %02x%02x:%02x%02x\n",
@@ -923,8 +925,13 @@ static int __devinit cx18_probe(struct pci_dev *pci_dev,
923 cx->enc_mem = ioremap_nocache(cx->base_addr + CX18_MEM_OFFSET, 925 cx->enc_mem = ioremap_nocache(cx->base_addr + CX18_MEM_OFFSET,
924 CX18_MEM_SIZE); 926 CX18_MEM_SIZE);
925 if (!cx->enc_mem) { 927 if (!cx->enc_mem) {
926 CX18_ERR("ioremap failed, perhaps increasing __VMALLOC_RESERVE in page.h\n"); 928 CX18_ERR("ioremap failed. Can't get a window into CX23418 "
927 CX18_ERR("or disabling CONFIG_HIGHMEM4G into the kernel would help\n"); 929 "memory and register space\n");
930 CX18_ERR("Each capture card with a CX23418 needs 64 MB of "
931 "vmalloc address space for the window\n");
932 CX18_ERR("Check the output of 'grep Vmalloc /proc/meminfo'\n");
933 CX18_ERR("Use the vmalloc= kernel command line option to set "
934 "VmallocTotal to a larger value\n");
928 retval = -ENOMEM; 935 retval = -ENOMEM;
929 goto free_mem; 936 goto free_mem;
930 } 937 }
diff --git a/drivers/media/video/cx18/cx18-driver.h b/drivers/media/video/cx18/cx18-driver.h
index 77be58c1096b..f6f3e50d4bdf 100644
--- a/drivers/media/video/cx18/cx18-driver.h
+++ b/drivers/media/video/cx18/cx18-driver.h
@@ -84,7 +84,8 @@
84#define CX18_CARD_TOSHIBA_QOSMIO_DVBT 5 /* Toshiba Qosmio Interal DVB-T/Analog*/ 84#define CX18_CARD_TOSHIBA_QOSMIO_DVBT 5 /* Toshiba Qosmio Interal DVB-T/Analog*/
85#define CX18_CARD_LEADTEK_PVR2100 6 /* Leadtek WinFast PVR2100 */ 85#define CX18_CARD_LEADTEK_PVR2100 6 /* Leadtek WinFast PVR2100 */
86#define CX18_CARD_LEADTEK_DVR3100H 7 /* Leadtek WinFast DVR3100 H */ 86#define CX18_CARD_LEADTEK_DVR3100H 7 /* Leadtek WinFast DVR3100 H */
87#define CX18_CARD_LAST 7 87#define CX18_CARD_GOTVIEW_PCI_DVD3 8 /* GoTView PCI DVD3 Hybrid */
88#define CX18_CARD_LAST 8
88 89
89#define CX18_ENC_STREAM_TYPE_MPG 0 90#define CX18_ENC_STREAM_TYPE_MPG 0
90#define CX18_ENC_STREAM_TYPE_TS 1 91#define CX18_ENC_STREAM_TYPE_TS 1
@@ -106,6 +107,7 @@
106#define CX18_PCI_ID_CONEXANT 0x14f1 107#define CX18_PCI_ID_CONEXANT 0x14f1
107#define CX18_PCI_ID_TOSHIBA 0x1179 108#define CX18_PCI_ID_TOSHIBA 0x1179
108#define CX18_PCI_ID_LEADTEK 0x107D 109#define CX18_PCI_ID_LEADTEK 0x107D
110#define CX18_PCI_ID_GOTVIEW 0x5854
109 111
110/* ======================================================================== */ 112/* ======================================================================== */
111/* ========================== START USER SETTABLE DMA VARIABLES =========== */ 113/* ========================== START USER SETTABLE DMA VARIABLES =========== */
@@ -323,7 +325,10 @@ struct cx18_queue {
323 spinlock_t lock; 325 spinlock_t lock;
324}; 326};
325 327
328struct cx18_stream; /* forward reference */
329
326struct cx18_dvb { 330struct cx18_dvb {
331 struct cx18_stream *stream;
327 struct dmx_frontend hw_frontend; 332 struct dmx_frontend hw_frontend;
328 struct dmx_frontend mem_frontend; 333 struct dmx_frontend mem_frontend;
329 struct dmxdev dmxdev; 334 struct dmxdev dmxdev;
@@ -363,9 +368,10 @@ struct cx18_in_work_order {
363#define CX18_INVALID_TASK_HANDLE 0xffffffff 368#define CX18_INVALID_TASK_HANDLE 0xffffffff
364 369
365struct cx18_stream { 370struct cx18_stream {
366 /* These first four fields are always set, even if the stream 371 /* These first five fields are always set, even if the stream
367 is not actually created. */ 372 is not actually created. */
368 struct video_device *video_dev; /* NULL when stream not created */ 373 struct video_device *video_dev; /* NULL when stream not created */
374 struct cx18_dvb *dvb; /* DVB / Digital Transport */
369 struct cx18 *cx; /* for ease of use */ 375 struct cx18 *cx; /* for ease of use */
370 const char *name; /* name of the stream */ 376 const char *name; /* name of the stream */
371 int type; /* stream type */ 377 int type; /* stream type */
@@ -395,9 +401,6 @@ struct cx18_stream {
395 struct cx18_queue q_idle; /* idle - not in rotation */ 401 struct cx18_queue q_idle; /* idle - not in rotation */
396 402
397 struct work_struct out_work_order; 403 struct work_struct out_work_order;
398
399 /* DVB / Digital Transport */
400 struct cx18_dvb dvb;
401}; 404};
402 405
403struct cx18_open_id { 406struct cx18_open_id {
diff --git a/drivers/media/video/cx18/cx18-dvb.c b/drivers/media/video/cx18/cx18-dvb.c
index 6d19f040d70f..f0381d62518d 100644
--- a/drivers/media/video/cx18/cx18-dvb.c
+++ b/drivers/media/video/cx18/cx18-dvb.c
@@ -137,7 +137,7 @@ static int yuan_mpc718_mt352_init(struct dvb_frontend *fe)
137{ 137{
138 struct cx18_dvb *dvb = container_of(fe->dvb, 138 struct cx18_dvb *dvb = container_of(fe->dvb,
139 struct cx18_dvb, dvb_adapter); 139 struct cx18_dvb, dvb_adapter);
140 struct cx18_stream *stream = container_of(dvb, struct cx18_stream, dvb); 140 struct cx18_stream *stream = dvb->stream;
141 const struct firmware *fw = NULL; 141 const struct firmware *fw = NULL;
142 int ret; 142 int ret;
143 int i; 143 int i;
@@ -203,6 +203,14 @@ static struct zl10353_config yuan_mpc718_zl10353_demod = {
203 .disable_i2c_gate_ctrl = 1, /* Disable the I2C gate */ 203 .disable_i2c_gate_ctrl = 1, /* Disable the I2C gate */
204}; 204};
205 205
206static struct zl10353_config gotview_dvd3_zl10353_demod = {
207 .demod_address = 0x1e >> 1, /* Datasheet suggested straps */
208 .if2 = 45600, /* 4.560 MHz IF from the XC3028 */
209 .parallel_ts = 1, /* Not a serial TS */
210 .no_tuner = 1, /* XC3028 is not behind the gate */
211 .disable_i2c_gate_ctrl = 1, /* Disable the I2C gate */
212};
213
206static int dvb_register(struct cx18_stream *stream); 214static int dvb_register(struct cx18_stream *stream);
207 215
208/* Kernel DVB framework calls this when the feed needs to start. 216/* Kernel DVB framework calls this when the feed needs to start.
@@ -247,6 +255,7 @@ static int cx18_dvb_start_feed(struct dvb_demux_feed *feed)
247 255
248 case CX18_CARD_LEADTEK_DVR3100H: 256 case CX18_CARD_LEADTEK_DVR3100H:
249 case CX18_CARD_YUAN_MPC718: 257 case CX18_CARD_YUAN_MPC718:
258 case CX18_CARD_GOTVIEW_PCI_DVD3:
250 default: 259 default:
251 /* Assumption - Parallel transport - Signalling 260 /* Assumption - Parallel transport - Signalling
252 * undefined or default. 261 * undefined or default.
@@ -257,22 +266,22 @@ static int cx18_dvb_start_feed(struct dvb_demux_feed *feed)
257 if (!demux->dmx.frontend) 266 if (!demux->dmx.frontend)
258 return -EINVAL; 267 return -EINVAL;
259 268
260 mutex_lock(&stream->dvb.feedlock); 269 mutex_lock(&stream->dvb->feedlock);
261 if (stream->dvb.feeding++ == 0) { 270 if (stream->dvb->feeding++ == 0) {
262 CX18_DEBUG_INFO("Starting Transport DMA\n"); 271 CX18_DEBUG_INFO("Starting Transport DMA\n");
263 mutex_lock(&cx->serialize_lock); 272 mutex_lock(&cx->serialize_lock);
264 set_bit(CX18_F_S_STREAMING, &stream->s_flags); 273 set_bit(CX18_F_S_STREAMING, &stream->s_flags);
265 ret = cx18_start_v4l2_encode_stream(stream); 274 ret = cx18_start_v4l2_encode_stream(stream);
266 if (ret < 0) { 275 if (ret < 0) {
267 CX18_DEBUG_INFO("Failed to start Transport DMA\n"); 276 CX18_DEBUG_INFO("Failed to start Transport DMA\n");
268 stream->dvb.feeding--; 277 stream->dvb->feeding--;
269 if (stream->dvb.feeding == 0) 278 if (stream->dvb->feeding == 0)
270 clear_bit(CX18_F_S_STREAMING, &stream->s_flags); 279 clear_bit(CX18_F_S_STREAMING, &stream->s_flags);
271 } 280 }
272 mutex_unlock(&cx->serialize_lock); 281 mutex_unlock(&cx->serialize_lock);
273 } else 282 } else
274 ret = 0; 283 ret = 0;
275 mutex_unlock(&stream->dvb.feedlock); 284 mutex_unlock(&stream->dvb->feedlock);
276 285
277 return ret; 286 return ret;
278} 287}
@@ -290,15 +299,15 @@ static int cx18_dvb_stop_feed(struct dvb_demux_feed *feed)
290 CX18_DEBUG_INFO("Stop feed: pid = 0x%x index = %d\n", 299 CX18_DEBUG_INFO("Stop feed: pid = 0x%x index = %d\n",
291 feed->pid, feed->index); 300 feed->pid, feed->index);
292 301
293 mutex_lock(&stream->dvb.feedlock); 302 mutex_lock(&stream->dvb->feedlock);
294 if (--stream->dvb.feeding == 0) { 303 if (--stream->dvb->feeding == 0) {
295 CX18_DEBUG_INFO("Stopping Transport DMA\n"); 304 CX18_DEBUG_INFO("Stopping Transport DMA\n");
296 mutex_lock(&cx->serialize_lock); 305 mutex_lock(&cx->serialize_lock);
297 ret = cx18_stop_v4l2_encode_stream(stream, 0); 306 ret = cx18_stop_v4l2_encode_stream(stream, 0);
298 mutex_unlock(&cx->serialize_lock); 307 mutex_unlock(&cx->serialize_lock);
299 } else 308 } else
300 ret = 0; 309 ret = 0;
301 mutex_unlock(&stream->dvb.feedlock); 310 mutex_unlock(&stream->dvb->feedlock);
302 } 311 }
303 312
304 return ret; 313 return ret;
@@ -307,7 +316,7 @@ static int cx18_dvb_stop_feed(struct dvb_demux_feed *feed)
307int cx18_dvb_register(struct cx18_stream *stream) 316int cx18_dvb_register(struct cx18_stream *stream)
308{ 317{
309 struct cx18 *cx = stream->cx; 318 struct cx18 *cx = stream->cx;
310 struct cx18_dvb *dvb = &stream->dvb; 319 struct cx18_dvb *dvb = stream->dvb;
311 struct dvb_adapter *dvb_adapter; 320 struct dvb_adapter *dvb_adapter;
312 struct dvb_demux *dvbdemux; 321 struct dvb_demux *dvbdemux;
313 struct dmx_demux *dmx; 322 struct dmx_demux *dmx;
@@ -316,6 +325,9 @@ int cx18_dvb_register(struct cx18_stream *stream)
316 if (!dvb) 325 if (!dvb)
317 return -EINVAL; 326 return -EINVAL;
318 327
328 dvb->enabled = 0;
329 dvb->stream = stream;
330
319 ret = dvb_register_adapter(&dvb->dvb_adapter, 331 ret = dvb_register_adapter(&dvb->dvb_adapter,
320 CX18_DRIVER_NAME, 332 CX18_DRIVER_NAME,
321 THIS_MODULE, &cx->pci_dev->dev, adapter_nr); 333 THIS_MODULE, &cx->pci_dev->dev, adapter_nr);
@@ -369,7 +381,7 @@ int cx18_dvb_register(struct cx18_stream *stream)
369 381
370 CX18_INFO("DVB Frontend registered\n"); 382 CX18_INFO("DVB Frontend registered\n");
371 CX18_INFO("Registered DVB adapter%d for %s (%d x %d.%02d kB)\n", 383 CX18_INFO("Registered DVB adapter%d for %s (%d x %d.%02d kB)\n",
372 stream->dvb.dvb_adapter.num, stream->name, 384 stream->dvb->dvb_adapter.num, stream->name,
373 stream->buffers, stream->buf_size/1024, 385 stream->buffers, stream->buf_size/1024,
374 (stream->buf_size * 100 / 1024) % 100); 386 (stream->buf_size * 100 / 1024) % 100);
375 387
@@ -396,13 +408,16 @@ err_out:
396void cx18_dvb_unregister(struct cx18_stream *stream) 408void cx18_dvb_unregister(struct cx18_stream *stream)
397{ 409{
398 struct cx18 *cx = stream->cx; 410 struct cx18 *cx = stream->cx;
399 struct cx18_dvb *dvb = &stream->dvb; 411 struct cx18_dvb *dvb = stream->dvb;
400 struct dvb_adapter *dvb_adapter; 412 struct dvb_adapter *dvb_adapter;
401 struct dvb_demux *dvbdemux; 413 struct dvb_demux *dvbdemux;
402 struct dmx_demux *dmx; 414 struct dmx_demux *dmx;
403 415
404 CX18_INFO("unregister DVB\n"); 416 CX18_INFO("unregister DVB\n");
405 417
418 if (dvb == NULL || !dvb->enabled)
419 return;
420
406 dvb_adapter = &dvb->dvb_adapter; 421 dvb_adapter = &dvb->dvb_adapter;
407 dvbdemux = &dvb->demux; 422 dvbdemux = &dvb->demux;
408 dmx = &dvbdemux->dmx; 423 dmx = &dvbdemux->dmx;
@@ -423,7 +438,7 @@ void cx18_dvb_unregister(struct cx18_stream *stream)
423 */ 438 */
424static int dvb_register(struct cx18_stream *stream) 439static int dvb_register(struct cx18_stream *stream)
425{ 440{
426 struct cx18_dvb *dvb = &stream->dvb; 441 struct cx18_dvb *dvb = stream->dvb;
427 struct cx18 *cx = stream->cx; 442 struct cx18 *cx = stream->cx;
428 int ret = 0; 443 int ret = 0;
429 444
@@ -495,6 +510,29 @@ static int dvb_register(struct cx18_stream *stream)
495 fe->ops.tuner_ops.set_config(fe, &ctrl); 510 fe->ops.tuner_ops.set_config(fe, &ctrl);
496 } 511 }
497 break; 512 break;
513 case CX18_CARD_GOTVIEW_PCI_DVD3:
514 dvb->fe = dvb_attach(zl10353_attach,
515 &gotview_dvd3_zl10353_demod,
516 &cx->i2c_adap[1]);
517 if (dvb->fe != NULL) {
518 struct dvb_frontend *fe;
519 struct xc2028_config cfg = {
520 .i2c_adap = &cx->i2c_adap[1],
521 .i2c_addr = 0xc2 >> 1,
522 .ctrl = NULL,
523 };
524 static struct xc2028_ctrl ctrl = {
525 .fname = XC2028_DEFAULT_FIRMWARE,
526 .max_len = 64,
527 .demod = XC3028_FE_ZARLINK456,
528 .type = XC2028_AUTO,
529 };
530
531 fe = dvb_attach(xc2028_attach, dvb->fe, &cfg);
532 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
533 fe->ops.tuner_ops.set_config(fe, &ctrl);
534 }
535 break;
498 default: 536 default:
499 /* No Digital Tv Support */ 537 /* No Digital Tv Support */
500 break; 538 break;
diff --git a/drivers/media/video/cx18/cx18-i2c.c b/drivers/media/video/cx18/cx18-i2c.c
index e71a026f3419..c330fb917b50 100644
--- a/drivers/media/video/cx18/cx18-i2c.c
+++ b/drivers/media/video/cx18/cx18-i2c.c
@@ -98,7 +98,7 @@ static int cx18_i2c_new_ir(struct cx18 *cx, struct i2c_adapter *adap, u32 hw,
98 case CX18_HW_Z8F0811_IR_RX_HAUP: 98 case CX18_HW_Z8F0811_IR_RX_HAUP:
99 init_data->ir_codes = RC_MAP_HAUPPAUGE_NEW; 99 init_data->ir_codes = RC_MAP_HAUPPAUGE_NEW;
100 init_data->internal_get_key_func = IR_KBD_GET_KEY_HAUP_XVR; 100 init_data->internal_get_key_func = IR_KBD_GET_KEY_HAUP_XVR;
101 init_data->type = IR_TYPE_RC5; 101 init_data->type = RC_TYPE_RC5;
102 init_data->name = cx->card_name; 102 init_data->name = cx->card_name;
103 info.platform_data = init_data; 103 info.platform_data = init_data;
104 break; 104 break;
diff --git a/drivers/media/video/cx18/cx18-mailbox.c b/drivers/media/video/cx18/cx18-mailbox.c
index 956aa190ecca..c545f3beef78 100644
--- a/drivers/media/video/cx18/cx18-mailbox.c
+++ b/drivers/media/video/cx18/cx18-mailbox.c
@@ -136,7 +136,7 @@ static void cx18_mdl_send_to_dvb(struct cx18_stream *s, struct cx18_mdl *mdl)
136{ 136{
137 struct cx18_buffer *buf; 137 struct cx18_buffer *buf;
138 138
139 if (!s->dvb.enabled || mdl->bytesused == 0) 139 if (s->dvb == NULL || !s->dvb->enabled || mdl->bytesused == 0)
140 return; 140 return;
141 141
142 /* We ignore mdl and buf readpos accounting here - it doesn't matter */ 142 /* We ignore mdl and buf readpos accounting here - it doesn't matter */
@@ -146,7 +146,7 @@ static void cx18_mdl_send_to_dvb(struct cx18_stream *s, struct cx18_mdl *mdl)
146 buf = list_first_entry(&mdl->buf_list, struct cx18_buffer, 146 buf = list_first_entry(&mdl->buf_list, struct cx18_buffer,
147 list); 147 list);
148 if (buf->bytesused) 148 if (buf->bytesused)
149 dvb_dmx_swfilter(&s->dvb.demux, 149 dvb_dmx_swfilter(&s->dvb->demux,
150 buf->buf, buf->bytesused); 150 buf->buf, buf->bytesused);
151 return; 151 return;
152 } 152 }
@@ -154,7 +154,7 @@ static void cx18_mdl_send_to_dvb(struct cx18_stream *s, struct cx18_mdl *mdl)
154 list_for_each_entry(buf, &mdl->buf_list, list) { 154 list_for_each_entry(buf, &mdl->buf_list, list) {
155 if (buf->bytesused == 0) 155 if (buf->bytesused == 0)
156 break; 156 break;
157 dvb_dmx_swfilter(&s->dvb.demux, buf->buf, buf->bytesused); 157 dvb_dmx_swfilter(&s->dvb->demux, buf->buf, buf->bytesused);
158 } 158 }
159} 159}
160 160
diff --git a/drivers/media/video/cx18/cx18-streams.c b/drivers/media/video/cx18/cx18-streams.c
index ab461e27d9dd..94f5d7967c5c 100644
--- a/drivers/media/video/cx18/cx18-streams.c
+++ b/drivers/media/video/cx18/cx18-streams.c
@@ -107,6 +107,7 @@ static void cx18_stream_init(struct cx18 *cx, int type)
107 s->video_dev = video_dev; 107 s->video_dev = video_dev;
108 108
109 /* initialize cx18_stream fields */ 109 /* initialize cx18_stream fields */
110 s->dvb = NULL;
110 s->cx = cx; 111 s->cx = cx;
111 s->type = type; 112 s->type = type;
112 s->name = cx18_stream_info[type].name; 113 s->name = cx18_stream_info[type].name;
@@ -140,10 +141,15 @@ static int cx18_prep_dev(struct cx18 *cx, int type)
140 int num_offset = cx18_stream_info[type].num_offset; 141 int num_offset = cx18_stream_info[type].num_offset;
141 int num = cx->instance + cx18_first_minor + num_offset; 142 int num = cx->instance + cx18_first_minor + num_offset;
142 143
143 /* These four fields are always initialized. If video_dev == NULL, then 144 /*
144 this stream is not in use. In that case no other fields but these 145 * These five fields are always initialized.
145 four can be used. */ 146 * For analog capture related streams, if video_dev == NULL then the
147 * stream is not in use.
148 * For the TS stream, if dvb == NULL then the stream is not in use.
149 * In those cases no other fields but these four can be used.
150 */
146 s->video_dev = NULL; 151 s->video_dev = NULL;
152 s->dvb = NULL;
147 s->cx = cx; 153 s->cx = cx;
148 s->type = type; 154 s->type = type;
149 s->name = cx18_stream_info[type].name; 155 s->name = cx18_stream_info[type].name;
@@ -167,6 +173,21 @@ static int cx18_prep_dev(struct cx18 *cx, int type)
167 173
168 cx18_stream_init(cx, type); 174 cx18_stream_init(cx, type);
169 175
176 /* Allocate the cx18_dvb struct only for the TS on cards with DTV */
177 if (type == CX18_ENC_STREAM_TYPE_TS) {
178 if (cx->card->hw_all & CX18_HW_DVB) {
179 s->dvb = kzalloc(sizeof(struct cx18_dvb), GFP_KERNEL);
180 if (s->dvb == NULL) {
181 CX18_ERR("Couldn't allocate cx18_dvb structure"
182 " for %s\n", s->name);
183 return -ENOMEM;
184 }
185 } else {
186 /* Don't need buffers for the TS, if there is no DVB */
187 s->buffers = 0;
188 }
189 }
190
170 if (num_offset == -1) 191 if (num_offset == -1)
171 return 0; 192 return 0;
172 193
@@ -222,13 +243,7 @@ static int cx18_reg_dev(struct cx18 *cx, int type)
222 const char *name; 243 const char *name;
223 int num, ret; 244 int num, ret;
224 245
225 /* TODO: Shouldn't this be a VFL_TYPE_TRANSPORT or something? 246 if (type == CX18_ENC_STREAM_TYPE_TS && s->dvb != NULL) {
226 * We need a VFL_TYPE_TS defined.
227 */
228 if (strcmp("TS", s->name) == 0) {
229 /* just return if no DVB is supported */
230 if ((cx->card->hw_all & CX18_HW_DVB) == 0)
231 return 0;
232 ret = cx18_dvb_register(s); 247 ret = cx18_dvb_register(s);
233 if (ret < 0) { 248 if (ret < 0) {
234 CX18_ERR("DVB failed to register\n"); 249 CX18_ERR("DVB failed to register\n");
@@ -320,11 +335,13 @@ void cx18_streams_cleanup(struct cx18 *cx, int unregister)
320 /* Teardown all streams */ 335 /* Teardown all streams */
321 for (type = 0; type < CX18_MAX_STREAMS; type++) { 336 for (type = 0; type < CX18_MAX_STREAMS; type++) {
322 337
323 /* No struct video_device, but can have buffers allocated */ 338 /* The TS has a cx18_dvb structure, not a video_device */
324 if (type == CX18_ENC_STREAM_TYPE_TS) { 339 if (type == CX18_ENC_STREAM_TYPE_TS) {
325 if (cx->streams[type].dvb.enabled) { 340 if (cx->streams[type].dvb != NULL) {
326 cx18_dvb_unregister(&cx->streams[type]); 341 if (unregister)
327 cx->streams[type].dvb.enabled = false; 342 cx18_dvb_unregister(&cx->streams[type]);
343 kfree(cx->streams[type].dvb);
344 cx->streams[type].dvb = NULL;
328 cx18_stream_free(&cx->streams[type]); 345 cx18_stream_free(&cx->streams[type]);
329 } 346 }
330 continue; 347 continue;
diff --git a/drivers/media/video/cx18/cx18-streams.h b/drivers/media/video/cx18/cx18-streams.h
index 77412bee5963..51765eb12d39 100644
--- a/drivers/media/video/cx18/cx18-streams.h
+++ b/drivers/media/video/cx18/cx18-streams.h
@@ -33,7 +33,8 @@ void cx18_stream_rotate_idx_mdls(struct cx18 *cx);
33 33
34static inline bool cx18_stream_enabled(struct cx18_stream *s) 34static inline bool cx18_stream_enabled(struct cx18_stream *s)
35{ 35{
36 return s->video_dev || s->dvb.enabled || 36 return s->video_dev ||
37 (s->dvb && s->dvb->enabled) ||
37 (s->type == CX18_ENC_STREAM_TYPE_IDX && 38 (s->type == CX18_ENC_STREAM_TYPE_IDX &&
38 s->cx->stream_buffers[CX18_ENC_STREAM_TYPE_IDX] != 0); 39 s->cx->stream_buffers[CX18_ENC_STREAM_TYPE_IDX] != 0);
39} 40}
diff --git a/drivers/media/video/cx231xx/Kconfig b/drivers/media/video/cx231xx/Kconfig
index bb04914983fd..ae85a7a7bd73 100644
--- a/drivers/media/video/cx231xx/Kconfig
+++ b/drivers/media/video/cx231xx/Kconfig
@@ -1,9 +1,9 @@
1config VIDEO_CX231XX 1config VIDEO_CX231XX
2 tristate "Conexant cx231xx USB video capture support" 2 tristate "Conexant cx231xx USB video capture support"
3 depends on VIDEO_DEV && I2C && INPUT 3 depends on VIDEO_DEV && I2C
4 select VIDEO_TUNER 4 select VIDEO_TUNER
5 select VIDEO_TVEEPROM 5 select VIDEO_TVEEPROM
6 depends on VIDEO_IR 6 depends on RC_CORE
7 select VIDEOBUF_VMALLOC 7 select VIDEOBUF_VMALLOC
8 select VIDEO_CX25840 8 select VIDEO_CX25840
9 select VIDEO_CX2341X 9 select VIDEO_CX2341X
@@ -14,6 +14,19 @@ config VIDEO_CX231XX
14 To compile this driver as a module, choose M here: the 14 To compile this driver as a module, choose M here: the
15 module will be called cx231xx 15 module will be called cx231xx
16 16
17config VIDEO_CX231XX_RC
18 bool "Conexant cx231xx Remote Controller additional support"
19 depends on RC_CORE
20 depends on VIDEO_CX231XX
21 default y
22 ---help---
23 cx231xx hardware has a builtin RX/TX support. However, a few
24 designs opted to not use it, but, instead, some other hardware.
25 This module enables the usage of those other hardware, like the
26 ones used with ISDB-T boards.
27
28 On most cases, all you need for IR is mceusb module.
29
17config VIDEO_CX231XX_ALSA 30config VIDEO_CX231XX_ALSA
18 tristate "Conexant Cx231xx ALSA audio module" 31 tristate "Conexant Cx231xx ALSA audio module"
19 depends on VIDEO_CX231XX && SND 32 depends on VIDEO_CX231XX && SND
@@ -30,6 +43,8 @@ config VIDEO_CX231XX_DVB
30 depends on VIDEO_CX231XX && DVB_CORE 43 depends on VIDEO_CX231XX && DVB_CORE
31 select VIDEOBUF_DVB 44 select VIDEOBUF_DVB
32 select MEDIA_TUNER_XC5000 if !DVB_FE_CUSTOMISE 45 select MEDIA_TUNER_XC5000 if !DVB_FE_CUSTOMISE
46 select MEDIA_TUNER_NXP18271 if !DVB_FE_CUSTOMISE
47 select DVB_MB86A20S if !DVB_FE_CUSTOMISE
33 48
34 ---help--- 49 ---help---
35 This adds support for DVB cards based on the 50 This adds support for DVB cards based on the
diff --git a/drivers/media/video/cx231xx/Makefile b/drivers/media/video/cx231xx/Makefile
index a6bc4cc54677..2c2484355449 100644
--- a/drivers/media/video/cx231xx/Makefile
+++ b/drivers/media/video/cx231xx/Makefile
@@ -1,5 +1,6 @@
1cx231xx-objs := cx231xx-video.o cx231xx-i2c.o cx231xx-cards.o cx231xx-core.o \ 1cx231xx-y += cx231xx-video.o cx231xx-i2c.o cx231xx-cards.o cx231xx-core.o
2 cx231xx-avcore.o cx231xx-417.o cx231xx-pcb-cfg.o cx231xx-vbi.o 2cx231xx-y += cx231xx-avcore.o cx231xx-417.o cx231xx-pcb-cfg.o cx231xx-vbi.o
3cx231xx-$(CONFIG_VIDEO_CX231XX_RC) += cx231xx-input.o
3 4
4cx231xx-alsa-objs := cx231xx-audio.o 5cx231xx-alsa-objs := cx231xx-audio.o
5 6
diff --git a/drivers/media/video/cx231xx/cx231xx-417.c b/drivers/media/video/cx231xx/cx231xx-417.c
index 4c7cac3b6254..fc9526a5b746 100644
--- a/drivers/media/video/cx231xx/cx231xx-417.c
+++ b/drivers/media/video/cx231xx/cx231xx-417.c
@@ -940,14 +940,14 @@ static int cx231xx_load_firmware(struct cx231xx *dev)
940 u16 _buffer_size = 4096; 940 u16 _buffer_size = 4096;
941 u8 *p_buffer; 941 u8 *p_buffer;
942 942
943 p_current_fw = (u32 *)vmalloc(1884180*4); 943 p_current_fw = vmalloc(1884180 * 4);
944 p_fw = p_current_fw; 944 p_fw = p_current_fw;
945 if (p_current_fw == 0) { 945 if (p_current_fw == 0) {
946 dprintk(2, "FAIL!!!\n"); 946 dprintk(2, "FAIL!!!\n");
947 return -1; 947 return -1;
948 } 948 }
949 949
950 p_buffer = (u8 *)vmalloc(4096); 950 p_buffer = vmalloc(4096);
951 if (p_buffer == 0) { 951 if (p_buffer == 0) {
952 dprintk(2, "FAIL!!!\n"); 952 dprintk(2, "FAIL!!!\n");
953 return -1; 953 return -1;
diff --git a/drivers/media/video/cx231xx/cx231xx-avcore.c b/drivers/media/video/cx231xx/cx231xx-avcore.c
index cf50fafa8abb..c53e97295a0d 100644
--- a/drivers/media/video/cx231xx/cx231xx-avcore.c
+++ b/drivers/media/video/cx231xx/cx231xx-avcore.c
@@ -274,7 +274,7 @@ int cx231xx_afe_set_input_mux(struct cx231xx *dev, u32 input_mux)
274 274
275 if (ch1_setting != 0) { 275 if (ch1_setting != 0) {
276 status = afe_read_byte(dev, ADC_INPUT_CH1, &value); 276 status = afe_read_byte(dev, ADC_INPUT_CH1, &value);
277 value &= (!INPUT_SEL_MASK); 277 value &= ~INPUT_SEL_MASK;
278 value |= (ch1_setting - 1) << 4; 278 value |= (ch1_setting - 1) << 4;
279 value &= 0xff; 279 value &= 0xff;
280 status = afe_write_byte(dev, ADC_INPUT_CH1, value); 280 status = afe_write_byte(dev, ADC_INPUT_CH1, value);
@@ -282,7 +282,7 @@ int cx231xx_afe_set_input_mux(struct cx231xx *dev, u32 input_mux)
282 282
283 if (ch2_setting != 0) { 283 if (ch2_setting != 0) {
284 status = afe_read_byte(dev, ADC_INPUT_CH2, &value); 284 status = afe_read_byte(dev, ADC_INPUT_CH2, &value);
285 value &= (!INPUT_SEL_MASK); 285 value &= ~INPUT_SEL_MASK;
286 value |= (ch2_setting - 1) << 4; 286 value |= (ch2_setting - 1) << 4;
287 value &= 0xff; 287 value &= 0xff;
288 status = afe_write_byte(dev, ADC_INPUT_CH2, value); 288 status = afe_write_byte(dev, ADC_INPUT_CH2, value);
@@ -292,7 +292,7 @@ int cx231xx_afe_set_input_mux(struct cx231xx *dev, u32 input_mux)
292 7 less than the input number */ 292 7 less than the input number */
293 if (ch3_setting != 0) { 293 if (ch3_setting != 0) {
294 status = afe_read_byte(dev, ADC_INPUT_CH3, &value); 294 status = afe_read_byte(dev, ADC_INPUT_CH3, &value);
295 value &= (!INPUT_SEL_MASK); 295 value &= ~INPUT_SEL_MASK;
296 value |= (ch3_setting - 1) << 4; 296 value |= (ch3_setting - 1) << 4;
297 value &= 0xff; 297 value &= 0xff;
298 status = afe_write_byte(dev, ADC_INPUT_CH3, value); 298 status = afe_write_byte(dev, ADC_INPUT_CH3, value);
@@ -354,6 +354,7 @@ int cx231xx_afe_update_power_control(struct cx231xx *dev,
354 case CX231XX_BOARD_CNXT_VIDEO_GRABBER: 354 case CX231XX_BOARD_CNXT_VIDEO_GRABBER:
355 case CX231XX_BOARD_HAUPPAUGE_EXETER: 355 case CX231XX_BOARD_HAUPPAUGE_EXETER:
356 case CX231XX_BOARD_HAUPPAUGE_USBLIVE2: 356 case CX231XX_BOARD_HAUPPAUGE_USBLIVE2:
357 case CX231XX_BOARD_PV_PLAYTV_USB_HYBRID:
357 if (avmode == POLARIS_AVMODE_ANALOGT_TV) { 358 if (avmode == POLARIS_AVMODE_ANALOGT_TV) {
358 while (afe_power_status != (FLD_PWRDN_TUNING_BIAS | 359 while (afe_power_status != (FLD_PWRDN_TUNING_BIAS |
359 FLD_PWRDN_ENABLE_PLL)) { 360 FLD_PWRDN_ENABLE_PLL)) {
diff --git a/drivers/media/video/cx231xx/cx231xx-cards.c b/drivers/media/video/cx231xx/cx231xx-cards.c
index 2c78d188bb06..6905607ffca3 100644
--- a/drivers/media/video/cx231xx/cx231xx-cards.c
+++ b/drivers/media/video/cx231xx/cx231xx-cards.c
@@ -34,6 +34,7 @@
34#include <media/cx25840.h> 34#include <media/cx25840.h>
35#include "dvb-usb-ids.h" 35#include "dvb-usb-ids.h"
36#include "xc5000.h" 36#include "xc5000.h"
37#include "tda18271.h"
37 38
38#include "cx231xx.h" 39#include "cx231xx.h"
39 40
@@ -395,6 +396,45 @@ struct cx231xx_board cx231xx_boards[] = {
395 .gpio = 0, 396 .gpio = 0,
396 } }, 397 } },
397 }, 398 },
399 [CX231XX_BOARD_PV_PLAYTV_USB_HYBRID] = {
400 .name = "Pixelview PlayTV USB Hybrid",
401 .tuner_type = TUNER_NXP_TDA18271,
402 .tuner_addr = 0x60,
403 .decoder = CX231XX_AVDECODER,
404 .output_mode = OUT_MODE_VIP11,
405 .demod_xfer_mode = 0,
406 .ctl_pin_status_mask = 0xFFFFFFC4,
407 .agc_analog_digital_select_gpio = 0x00, /* According with PV cxPolaris.inf file */
408 .tuner_sif_gpio = -1,
409 .tuner_scl_gpio = -1,
410 .tuner_sda_gpio = -1,
411 .gpio_pin_status_mask = 0x4001000,
412 .tuner_i2c_master = 2,
413 .demod_i2c_master = 1,
414 .ir_i2c_master = 2,
415 .rc_map_name = RC_MAP_PIXELVIEW_002T,
416 .has_dvb = 1,
417 .demod_addr = 0x10,
418 .norm = V4L2_STD_PAL_M,
419 .input = {{
420 .type = CX231XX_VMUX_TELEVISION,
421 .vmux = CX231XX_VIN_3_1,
422 .amux = CX231XX_AMUX_VIDEO,
423 .gpio = 0,
424 }, {
425 .type = CX231XX_VMUX_COMPOSITE1,
426 .vmux = CX231XX_VIN_2_1,
427 .amux = CX231XX_AMUX_LINE_IN,
428 .gpio = 0,
429 }, {
430 .type = CX231XX_VMUX_SVIDEO,
431 .vmux = CX231XX_VIN_1_1 |
432 (CX231XX_VIN_1_2 << 8) |
433 CX25840_SVIDEO_ON,
434 .amux = CX231XX_AMUX_LINE_IN,
435 .gpio = 0,
436 } },
437 },
398}; 438};
399const unsigned int cx231xx_bcount = ARRAY_SIZE(cx231xx_boards); 439const unsigned int cx231xx_bcount = ARRAY_SIZE(cx231xx_boards);
400 440
@@ -402,8 +442,6 @@ const unsigned int cx231xx_bcount = ARRAY_SIZE(cx231xx_boards);
402struct usb_device_id cx231xx_id_table[] = { 442struct usb_device_id cx231xx_id_table[] = {
403 {USB_DEVICE(0x0572, 0x5A3C), 443 {USB_DEVICE(0x0572, 0x5A3C),
404 .driver_info = CX231XX_BOARD_UNKNOWN}, 444 .driver_info = CX231XX_BOARD_UNKNOWN},
405 {USB_DEVICE_VER(USB_VID_PIXELVIEW, USB_PID_PIXELVIEW_SBTVD, 0x4000,0x4fff),
406 .driver_info = CX231XX_BOARD_UNKNOWN},
407 {USB_DEVICE(0x0572, 0x58A2), 445 {USB_DEVICE(0x0572, 0x58A2),
408 .driver_info = CX231XX_BOARD_CNXT_CARRAERA}, 446 .driver_info = CX231XX_BOARD_CNXT_CARRAERA},
409 {USB_DEVICE(0x0572, 0x58A1), 447 {USB_DEVICE(0x0572, 0x58A1),
@@ -424,6 +462,8 @@ struct usb_device_id cx231xx_id_table[] = {
424 .driver_info = CX231XX_BOARD_HAUPPAUGE_EXETER}, 462 .driver_info = CX231XX_BOARD_HAUPPAUGE_EXETER},
425 {USB_DEVICE(0x2040, 0xc200), 463 {USB_DEVICE(0x2040, 0xc200),
426 .driver_info = CX231XX_BOARD_HAUPPAUGE_USBLIVE2}, 464 .driver_info = CX231XX_BOARD_HAUPPAUGE_USBLIVE2},
465 {USB_DEVICE_VER(USB_VID_PIXELVIEW, USB_PID_PIXELVIEW_SBTVD, 0x4000, 0x4001),
466 .driver_info = CX231XX_BOARD_PV_PLAYTV_USB_HYBRID},
427 {}, 467 {},
428}; 468};
429 469
@@ -453,6 +493,16 @@ int cx231xx_tuner_callback(void *ptr, int component, int command, int arg)
453 1); 493 1);
454 msleep(10); 494 msleep(10);
455 } 495 }
496 } else if (dev->tuner_type == TUNER_NXP_TDA18271) {
497 switch (command) {
498 case TDA18271_CALLBACK_CMD_AGC_ENABLE:
499 if (dev->model == CX231XX_BOARD_PV_PLAYTV_USB_HYBRID)
500 rc = cx231xx_set_agc_analog_digital_mux_select(dev, arg);
501 break;
502 default:
503 rc = -EINVAL;
504 break;
505 }
456 } 506 }
457 return rc; 507 return rc;
458} 508}
@@ -615,8 +665,11 @@ void cx231xx_release_resources(struct cx231xx *dev)
615 665
616 cx231xx_remove_from_devlist(dev); 666 cx231xx_remove_from_devlist(dev);
617 667
668 /* Release I2C buses */
618 cx231xx_dev_uninit(dev); 669 cx231xx_dev_uninit(dev);
619 670
671 cx231xx_ir_exit(dev);
672
620 usb_put_dev(dev->udev); 673 usb_put_dev(dev->udev);
621 674
622 /* Mark device as unused */ 675 /* Mark device as unused */
@@ -731,16 +784,14 @@ static int cx231xx_init_dev(struct cx231xx **devhandle, struct usb_device *udev,
731 retval = cx231xx_register_analog_devices(dev); 784 retval = cx231xx_register_analog_devices(dev);
732 if (retval < 0) { 785 if (retval < 0) {
733 cx231xx_release_resources(dev); 786 cx231xx_release_resources(dev);
734 goto fail_reg_devices; 787 return retval;
735 } 788 }
736 789
790 cx231xx_ir_init(dev);
791
737 cx231xx_init_extension(dev); 792 cx231xx_init_extension(dev);
738 793
739 return 0; 794 return 0;
740
741fail_reg_devices:
742 mutex_unlock(&dev->lock);
743 return retval;
744} 795}
745 796
746#if defined(CONFIG_MODULES) && defined(MODULE) 797#if defined(CONFIG_MODULES) && defined(MODULE)
diff --git a/drivers/media/video/cx231xx/cx231xx-core.c b/drivers/media/video/cx231xx/cx231xx-core.c
index 4af46fca9b0a..7d62d58617f5 100644
--- a/drivers/media/video/cx231xx/cx231xx-core.c
+++ b/drivers/media/video/cx231xx/cx231xx-core.c
@@ -740,6 +740,7 @@ int cx231xx_set_mode(struct cx231xx *dev, enum cx231xx_mode set_mode)
740 case CX231XX_BOARD_CNXT_RDE_253S: 740 case CX231XX_BOARD_CNXT_RDE_253S:
741 case CX231XX_BOARD_CNXT_RDU_253S: 741 case CX231XX_BOARD_CNXT_RDU_253S:
742 case CX231XX_BOARD_HAUPPAUGE_EXETER: 742 case CX231XX_BOARD_HAUPPAUGE_EXETER:
743 case CX231XX_BOARD_PV_PLAYTV_USB_HYBRID:
743 errCode = cx231xx_set_agc_analog_digital_mux_select(dev, 0); 744 errCode = cx231xx_set_agc_analog_digital_mux_select(dev, 0);
744 break; 745 break;
745 default: 746 default:
@@ -1288,7 +1289,7 @@ int cx231xx_dev_init(struct cx231xx *dev)
1288 /* Internal Master 3 Bus */ 1289 /* Internal Master 3 Bus */
1289 dev->i2c_bus[2].nr = 2; 1290 dev->i2c_bus[2].nr = 2;
1290 dev->i2c_bus[2].dev = dev; 1291 dev->i2c_bus[2].dev = dev;
1291 dev->i2c_bus[2].i2c_period = I2C_SPEED_400K; /* 400kHz */ 1292 dev->i2c_bus[2].i2c_period = I2C_SPEED_100K; /* 100kHz */
1292 dev->i2c_bus[2].i2c_nostop = 0; 1293 dev->i2c_bus[2].i2c_nostop = 0;
1293 dev->i2c_bus[2].i2c_reserve = 0; 1294 dev->i2c_bus[2].i2c_reserve = 0;
1294 1295
@@ -1381,6 +1382,7 @@ int cx231xx_dev_init(struct cx231xx *dev)
1381 case CX231XX_BOARD_CNXT_RDE_253S: 1382 case CX231XX_BOARD_CNXT_RDE_253S:
1382 case CX231XX_BOARD_CNXT_RDU_253S: 1383 case CX231XX_BOARD_CNXT_RDU_253S:
1383 case CX231XX_BOARD_HAUPPAUGE_EXETER: 1384 case CX231XX_BOARD_HAUPPAUGE_EXETER:
1385 case CX231XX_BOARD_PV_PLAYTV_USB_HYBRID:
1384 errCode = cx231xx_set_agc_analog_digital_mux_select(dev, 0); 1386 errCode = cx231xx_set_agc_analog_digital_mux_select(dev, 0);
1385 break; 1387 break;
1386 default: 1388 default:
@@ -1513,7 +1515,7 @@ int cx231xx_read_i2c_master(struct cx231xx *dev, u8 dev_addr, u16 saddr,
1513 1515
1514 if (saddr_len == 0) 1516 if (saddr_len == 0)
1515 saddr = 0; 1517 saddr = 0;
1516 else if (saddr_len == 0) 1518 else if (saddr_len == 1)
1517 saddr &= 0xff; 1519 saddr &= 0xff;
1518 1520
1519 /* prepare xfer_data struct */ 1521 /* prepare xfer_data struct */
@@ -1564,7 +1566,7 @@ int cx231xx_write_i2c_master(struct cx231xx *dev, u8 dev_addr, u16 saddr,
1564 1566
1565 if (saddr_len == 0) 1567 if (saddr_len == 0)
1566 saddr = 0; 1568 saddr = 0;
1567 else if (saddr_len == 0) 1569 else if (saddr_len == 1)
1568 saddr &= 0xff; 1570 saddr &= 0xff;
1569 1571
1570 /* prepare xfer_data struct */ 1572 /* prepare xfer_data struct */
@@ -1598,7 +1600,7 @@ int cx231xx_read_i2c_data(struct cx231xx *dev, u8 dev_addr, u16 saddr,
1598 1600
1599 if (saddr_len == 0) 1601 if (saddr_len == 0)
1600 saddr = 0; 1602 saddr = 0;
1601 else if (saddr_len == 0) 1603 else if (saddr_len == 1)
1602 saddr &= 0xff; 1604 saddr &= 0xff;
1603 1605
1604 /* prepare xfer_data struct */ 1606 /* prepare xfer_data struct */
@@ -1639,7 +1641,7 @@ int cx231xx_write_i2c_data(struct cx231xx *dev, u8 dev_addr, u16 saddr,
1639 1641
1640 if (saddr_len == 0) 1642 if (saddr_len == 0)
1641 saddr = 0; 1643 saddr = 0;
1642 else if (saddr_len == 0) 1644 else if (saddr_len == 1)
1643 saddr &= 0xff; 1645 saddr &= 0xff;
1644 1646
1645 /* prepare xfer_data struct */ 1647 /* prepare xfer_data struct */
diff --git a/drivers/media/video/cx231xx/cx231xx-dvb.c b/drivers/media/video/cx231xx/cx231xx-dvb.c
index 5feb3ee640d9..fe59a1c3f064 100644
--- a/drivers/media/video/cx231xx/cx231xx-dvb.c
+++ b/drivers/media/video/cx231xx/cx231xx-dvb.c
@@ -33,6 +33,7 @@
33#include "tda18271.h" 33#include "tda18271.h"
34#include "s5h1411.h" 34#include "s5h1411.h"
35#include "lgdt3305.h" 35#include "lgdt3305.h"
36#include "mb86a20s.h"
36 37
37MODULE_DESCRIPTION("driver for cx231xx based DVB cards"); 38MODULE_DESCRIPTION("driver for cx231xx based DVB cards");
38MODULE_AUTHOR("Srinivasa Deevi <srinivasa.deevi@conexant.com>"); 39MODULE_AUTHOR("Srinivasa Deevi <srinivasa.deevi@conexant.com>");
@@ -88,6 +89,11 @@ static struct tda18271_std_map cnxt_rde253s_tda18271_std_map = {
88 .if_lvl = 1, .rfagc_top = 0x37, }, 89 .if_lvl = 1, .rfagc_top = 0x37, },
89}; 90};
90 91
92static struct tda18271_std_map mb86a20s_tda18271_config = {
93 .dvbt_6 = { .if_freq = 3300, .agc_mode = 3, .std = 4,
94 .if_lvl = 7, .rfagc_top = 0x37, },
95};
96
91static struct tda18271_config cnxt_rde253s_tunerconfig = { 97static struct tda18271_config cnxt_rde253s_tunerconfig = {
92 .std_map = &cnxt_rde253s_tda18271_std_map, 98 .std_map = &cnxt_rde253s_tda18271_std_map,
93 .gate = TDA18271_GATE_ANALOG, 99 .gate = TDA18271_GATE_ANALOG,
@@ -135,6 +141,17 @@ static struct tda18271_config hcw_tda18271_config = {
135 .gate = TDA18271_GATE_DIGITAL, 141 .gate = TDA18271_GATE_DIGITAL,
136}; 142};
137 143
144static const struct mb86a20s_config pv_mb86a20s_config = {
145 .demod_address = 0x10,
146 .is_serial = true,
147};
148
149static struct tda18271_config pv_tda18271_config = {
150 .std_map = &mb86a20s_tda18271_config,
151 .gate = TDA18271_GATE_DIGITAL,
152 .small_i2c = TDA18271_03_BYTE_CHUNK_INIT,
153};
154
138static inline void print_err_status(struct cx231xx *dev, int packet, int status) 155static inline void print_err_status(struct cx231xx *dev, int packet, int status)
139{ 156{
140 char *errmsg = "Unknown"; 157 char *errmsg = "Unknown";
@@ -687,6 +704,29 @@ static int dvb_init(struct cx231xx *dev)
687 &hcw_tda18271_config); 704 &hcw_tda18271_config);
688 break; 705 break;
689 706
707 case CX231XX_BOARD_PV_PLAYTV_USB_HYBRID:
708
709 printk(KERN_INFO "%s: looking for demod on i2c bus: %d\n",
710 __func__, i2c_adapter_id(&dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap));
711
712 dev->dvb->frontend = dvb_attach(mb86a20s_attach,
713 &pv_mb86a20s_config,
714 &dev->i2c_bus[dev->board.demod_i2c_master].i2c_adap);
715
716 if (dev->dvb->frontend == NULL) {
717 printk(DRIVER_NAME
718 ": Failed to attach mb86a20s demod\n");
719 result = -EINVAL;
720 goto out_free;
721 }
722
723 /* define general-purpose callback pointer */
724 dvb->frontend->callback = cx231xx_tuner_callback;
725
726 dvb_attach(tda18271_attach, dev->dvb->frontend,
727 0x60, &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap,
728 &pv_tda18271_config);
729 break;
690 730
691 default: 731 default:
692 printk(KERN_ERR "%s/2: The frontend of your DVB/ATSC card" 732 printk(KERN_ERR "%s/2: The frontend of your DVB/ATSC card"
diff --git a/drivers/media/video/cx231xx/cx231xx-input.c b/drivers/media/video/cx231xx/cx231xx-input.c
new file mode 100644
index 000000000000..45e14cac4622
--- /dev/null
+++ b/drivers/media/video/cx231xx/cx231xx-input.c
@@ -0,0 +1,112 @@
1/*
2 * cx231xx IR glue driver
3 *
4 * Copyright (C) 2010 Mauro Carvalho Chehab <mchehab@redhat.com>
5 *
6 * Polaris (cx231xx) has its support for IR's with a design close to MCE.
7 * however, a few designs are using an external I2C chip for IR, instead
8 * of using the one provided by the chip.
9 * This driver provides support for those extra devices
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation version 2.
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 GNU
18 * General Public License for more details.
19 */
20
21#include "cx231xx.h"
22#include <linux/usb.h>
23#include <linux/slab.h>
24
25#define MODULE_NAME "cx231xx-input"
26
27static int get_key_isdbt(struct IR_i2c *ir, u32 *ir_key,
28 u32 *ir_raw)
29{
30 u8 cmd, scancode;
31
32 dev_dbg(&ir->rc->input_dev->dev, "%s\n", __func__);
33
34 /* poll IR chip */
35 if (1 != i2c_master_recv(ir->c, &cmd, 1))
36 return -EIO;
37
38 /* it seems that 0xFE indicates that a button is still hold
39 down, while 0xff indicates that no button is hold
40 down. 0xfe sequences are sometimes interrupted by 0xFF */
41
42 if (cmd == 0xff)
43 return 0;
44
45 scancode =
46 ((cmd & 0x01) ? 0x80 : 0) |
47 ((cmd & 0x02) ? 0x40 : 0) |
48 ((cmd & 0x04) ? 0x20 : 0) |
49 ((cmd & 0x08) ? 0x10 : 0) |
50 ((cmd & 0x10) ? 0x08 : 0) |
51 ((cmd & 0x20) ? 0x04 : 0) |
52 ((cmd & 0x40) ? 0x02 : 0) |
53 ((cmd & 0x80) ? 0x01 : 0);
54
55 dev_dbg(&ir->rc->input_dev->dev, "cmd %02x, scan = %02x\n",
56 cmd, scancode);
57
58 *ir_key = scancode;
59 *ir_raw = scancode;
60 return 1;
61}
62
63int cx231xx_ir_init(struct cx231xx *dev)
64{
65 struct i2c_board_info info;
66 u8 ir_i2c_bus;
67
68 dev_dbg(&dev->udev->dev, "%s\n", __func__);
69
70 /* Only initialize if a rc keycode map is defined */
71 if (!cx231xx_boards[dev->model].rc_map_name)
72 return -ENODEV;
73
74 request_module("ir-kbd-i2c");
75
76 memset(&info, 0, sizeof(struct i2c_board_info));
77 memset(&dev->init_data, 0, sizeof(dev->init_data));
78 dev->init_data.rc_dev = rc_allocate_device();
79 if (!dev->init_data.rc_dev)
80 return -ENOMEM;
81
82 dev->init_data.name = cx231xx_boards[dev->model].name;
83
84 strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
85 info.platform_data = &dev->init_data;
86
87 /*
88 * Board-dependent values
89 *
90 * For now, there's just one type of hardware design using
91 * an i2c device.
92 */
93 dev->init_data.get_key = get_key_isdbt;
94 dev->init_data.ir_codes = cx231xx_boards[dev->model].rc_map_name;
95 /* The i2c micro-controller only outputs the cmd part of NEC protocol */
96 dev->init_data.rc_dev->scanmask = 0xff;
97 dev->init_data.rc_dev->driver_name = "cx231xx";
98 dev->init_data.type = RC_TYPE_NEC;
99 info.addr = 0x30;
100
101 /* Load and bind ir-kbd-i2c */
102 ir_i2c_bus = cx231xx_boards[dev->model].ir_i2c_master;
103 dev_dbg(&dev->udev->dev, "Trying to bind ir at bus %d, addr 0x%02x\n",
104 ir_i2c_bus, info.addr);
105 i2c_new_device(&dev->i2c_bus[ir_i2c_bus].i2c_adap, &info);
106
107 return 0;
108}
109
110void cx231xx_ir_exit(struct cx231xx *dev)
111{
112}
diff --git a/drivers/media/video/cx231xx/cx231xx-video.c b/drivers/media/video/cx231xx/cx231xx-video.c
index b13b69fb2af6..7e3e8c4f19b7 100644
--- a/drivers/media/video/cx231xx/cx231xx-video.c
+++ b/drivers/media/video/cx231xx/cx231xx-video.c
@@ -2044,15 +2044,6 @@ static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b)
2044 return videobuf_dqbuf(&fh->vb_vidq, b, file->f_flags & O_NONBLOCK); 2044 return videobuf_dqbuf(&fh->vb_vidq, b, file->f_flags & O_NONBLOCK);
2045} 2045}
2046 2046
2047#ifdef CONFIG_VIDEO_V4L1_COMPAT
2048static int vidiocgmbuf(struct file *file, void *priv, struct video_mbuf *mbuf)
2049{
2050 struct cx231xx_fh *fh = priv;
2051
2052 return videobuf_cgmbuf(&fh->vb_vidq, mbuf, 8);
2053}
2054#endif
2055
2056/* ----------------------------------------------------------- */ 2047/* ----------------------------------------------------------- */
2057/* RADIO ESPECIFIC IOCTLS */ 2048/* RADIO ESPECIFIC IOCTLS */
2058/* ----------------------------------------------------------- */ 2049/* ----------------------------------------------------------- */
@@ -2507,9 +2498,6 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
2507 .vidioc_g_register = vidioc_g_register, 2498 .vidioc_g_register = vidioc_g_register,
2508 .vidioc_s_register = vidioc_s_register, 2499 .vidioc_s_register = vidioc_s_register,
2509#endif 2500#endif
2510#ifdef CONFIG_VIDEO_V4L1_COMPAT
2511 .vidiocgmbuf = vidiocgmbuf,
2512#endif
2513}; 2501};
2514 2502
2515static struct video_device cx231xx_vbi_template; 2503static struct video_device cx231xx_vbi_template;
diff --git a/drivers/media/video/cx231xx/cx231xx.h b/drivers/media/video/cx231xx/cx231xx.h
index d067df9b81e7..72bbea2bcd56 100644
--- a/drivers/media/video/cx231xx/cx231xx.h
+++ b/drivers/media/video/cx231xx/cx231xx.h
@@ -34,7 +34,8 @@
34 34
35#include <media/videobuf-vmalloc.h> 35#include <media/videobuf-vmalloc.h>
36#include <media/v4l2-device.h> 36#include <media/v4l2-device.h>
37#include <media/ir-core.h> 37#include <media/rc-core.h>
38#include <media/ir-kbd-i2c.h>
38#include <media/videobuf-dvb.h> 39#include <media/videobuf-dvb.h>
39 40
40#include "cx231xx-reg.h" 41#include "cx231xx-reg.h"
@@ -62,6 +63,7 @@
62#define CX231XX_BOARD_CNXT_RDU_250 7 63#define CX231XX_BOARD_CNXT_RDU_250 7
63#define CX231XX_BOARD_HAUPPAUGE_EXETER 8 64#define CX231XX_BOARD_HAUPPAUGE_EXETER 8
64#define CX231XX_BOARD_HAUPPAUGE_USBLIVE2 9 65#define CX231XX_BOARD_HAUPPAUGE_USBLIVE2 9
66#define CX231XX_BOARD_PV_PLAYTV_USB_HYBRID 10
65 67
66/* Limits minimum and default number of buffers */ 68/* Limits minimum and default number of buffers */
67#define CX231XX_MIN_BUF 4 69#define CX231XX_MIN_BUF 4
@@ -344,6 +346,10 @@ struct cx231xx_board {
344 /* i2c masters */ 346 /* i2c masters */
345 u8 tuner_i2c_master; 347 u8 tuner_i2c_master;
346 u8 demod_i2c_master; 348 u8 demod_i2c_master;
349 u8 ir_i2c_master;
350
351 /* for devices with I2C chips for IR */
352 char *rc_map_name;
347 353
348 unsigned int max_range_640_480:1; 354 unsigned int max_range_640_480:1;
349 unsigned int has_dvb:1; 355 unsigned int has_dvb:1;
@@ -356,7 +362,7 @@ struct cx231xx_board {
356 362
357 struct cx231xx_input input[MAX_CX231XX_INPUT]; 363 struct cx231xx_input input[MAX_CX231XX_INPUT];
358 struct cx231xx_input radio; 364 struct cx231xx_input radio;
359 struct ir_scancode_table *ir_codes; 365 struct rc_map *ir_codes;
360}; 366};
361 367
362/* device states */ 368/* device states */
@@ -605,6 +611,9 @@ struct cx231xx {
605 611
606 struct cx231xx_board board; 612 struct cx231xx_board board;
607 613
614 /* For I2C IR support */
615 struct IR_i2c_init_data init_data;
616
608 unsigned int stream_on:1; /* Locks streams */ 617 unsigned int stream_on:1; /* Locks streams */
609 unsigned int vbi_stream_on:1; /* Locks streams for VBI */ 618 unsigned int vbi_stream_on:1; /* Locks streams for VBI */
610 unsigned int has_audio_class:1; 619 unsigned int has_audio_class:1;
@@ -616,8 +625,6 @@ struct cx231xx {
616 struct v4l2_subdev *sd_cx25840; 625 struct v4l2_subdev *sd_cx25840;
617 struct v4l2_subdev *sd_tuner; 626 struct v4l2_subdev *sd_tuner;
618 627
619 struct cx231xx_IR *ir;
620
621 struct work_struct wq_trigger; /* Trigger to start/stop audio for alsa module */ 628 struct work_struct wq_trigger; /* Trigger to start/stop audio for alsa module */
622 atomic_t stream_started; /* stream should be running if true */ 629 atomic_t stream_started; /* stream should be running if true */
623 630
@@ -954,6 +961,17 @@ int cx231xx_tuner_callback(void *ptr, int component, int command, int arg);
954extern int cx231xx_417_register(struct cx231xx *dev); 961extern int cx231xx_417_register(struct cx231xx *dev);
955extern void cx231xx_417_unregister(struct cx231xx *dev); 962extern void cx231xx_417_unregister(struct cx231xx *dev);
956 963
964/* cx23885-input.c */
965
966#if defined(CONFIG_VIDEO_CX231XX_RC)
967int cx231xx_ir_init(struct cx231xx *dev);
968void cx231xx_ir_exit(struct cx231xx *dev);
969#else
970#define cx231xx_ir_init(dev) (0)
971#define cx231xx_ir_exit(dev) (0)
972#endif
973
974
957/* printk macros */ 975/* printk macros */
958 976
959#define cx231xx_err(fmt, arg...) do {\ 977#define cx231xx_err(fmt, arg...) do {\
diff --git a/drivers/media/video/cx2341x.c b/drivers/media/video/cx2341x.c
index e5c3c8da4be3..103ef6bad2e2 100644
--- a/drivers/media/video/cx2341x.c
+++ b/drivers/media/video/cx2341x.c
@@ -853,9 +853,9 @@ int cx2341x_ctrl_query(const struct cx2341x_mpeg_params *params,
853} 853}
854EXPORT_SYMBOL(cx2341x_ctrl_query); 854EXPORT_SYMBOL(cx2341x_ctrl_query);
855 855
856const char **cx2341x_ctrl_get_menu(const struct cx2341x_mpeg_params *p, u32 id) 856const char * const *cx2341x_ctrl_get_menu(const struct cx2341x_mpeg_params *p, u32 id)
857{ 857{
858 static const char *mpeg_stream_type_without_ts[] = { 858 static const char * const mpeg_stream_type_without_ts[] = {
859 "MPEG-2 Program Stream", 859 "MPEG-2 Program Stream",
860 "", 860 "",
861 "MPEG-1 System Stream", 861 "MPEG-1 System Stream",
@@ -952,7 +952,7 @@ int cx2341x_ext_ctrls(struct cx2341x_mpeg_params *params, int busy,
952 for (i = 0; i < ctrls->count; i++) { 952 for (i = 0; i < ctrls->count; i++) {
953 struct v4l2_ext_control *ctrl = ctrls->controls + i; 953 struct v4l2_ext_control *ctrl = ctrls->controls + i;
954 struct v4l2_queryctrl qctrl; 954 struct v4l2_queryctrl qctrl;
955 const char **menu_items = NULL; 955 const char * const *menu_items = NULL;
956 956
957 qctrl.id = ctrl->id; 957 qctrl.id = ctrl->id;
958 err = cx2341x_ctrl_query(params, &qctrl); 958 err = cx2341x_ctrl_query(params, &qctrl);
@@ -1135,7 +1135,7 @@ EXPORT_SYMBOL(cx2341x_update);
1135 1135
1136static const char *cx2341x_menu_item(const struct cx2341x_mpeg_params *p, u32 id) 1136static const char *cx2341x_menu_item(const struct cx2341x_mpeg_params *p, u32 id)
1137{ 1137{
1138 const char **menu = cx2341x_ctrl_get_menu(p, id); 1138 const char * const *menu = cx2341x_ctrl_get_menu(p, id);
1139 struct v4l2_ext_control ctrl; 1139 struct v4l2_ext_control ctrl;
1140 1140
1141 if (menu == NULL) 1141 if (menu == NULL)
diff --git a/drivers/media/video/cx23885/Kconfig b/drivers/media/video/cx23885/Kconfig
index e1367b35647a..6b4a516addfe 100644
--- a/drivers/media/video/cx23885/Kconfig
+++ b/drivers/media/video/cx23885/Kconfig
@@ -5,7 +5,7 @@ config VIDEO_CX23885
5 select VIDEO_BTCX 5 select VIDEO_BTCX
6 select VIDEO_TUNER 6 select VIDEO_TUNER
7 select VIDEO_TVEEPROM 7 select VIDEO_TVEEPROM
8 depends on IR_CORE 8 depends on RC_CORE
9 select VIDEOBUF_DVB 9 select VIDEOBUF_DVB
10 select VIDEOBUF_DMA_SG 10 select VIDEOBUF_DMA_SG
11 select VIDEO_CX25840 11 select VIDEO_CX25840
diff --git a/drivers/media/video/cx23885/cimax2.c b/drivers/media/video/cx23885/cimax2.c
index c95e7bc14745..209b971bd267 100644
--- a/drivers/media/video/cx23885/cimax2.c
+++ b/drivers/media/video/cx23885/cimax2.c
@@ -368,7 +368,7 @@ static void netup_read_ci_status(struct work_struct *work)
368 DVB_CA_EN50221_POLL_CAM_READY; 368 DVB_CA_EN50221_POLL_CAM_READY;
369 else 369 else
370 state->status = 0; 370 state->status = 0;
371 }; 371 }
372} 372}
373 373
374/* CI irq handler */ 374/* CI irq handler */
@@ -377,16 +377,24 @@ int netup_ci_slot_status(struct cx23885_dev *dev, u32 pci_status)
377 struct cx23885_tsport *port = NULL; 377 struct cx23885_tsport *port = NULL;
378 struct netup_ci_state *state = NULL; 378 struct netup_ci_state *state = NULL;
379 379
380 if (pci_status & PCI_MSK_GPIO0) 380 ci_dbg_print("%s:\n", __func__);
381 port = &dev->ts1; 381
382 else if (pci_status & PCI_MSK_GPIO1) 382 if (0 == (pci_status & (PCI_MSK_GPIO0 | PCI_MSK_GPIO1)))
383 port = &dev->ts2;
384 else /* who calls ? */
385 return 0; 383 return 0;
386 384
387 state = port->port_priv; 385 if (pci_status & PCI_MSK_GPIO0) {
386 port = &dev->ts1;
387 state = port->port_priv;
388 schedule_work(&state->work);
389 ci_dbg_print("%s: Wakeup CI0\n", __func__);
390 }
388 391
389 schedule_work(&state->work); 392 if (pci_status & PCI_MSK_GPIO1) {
393 port = &dev->ts2;
394 state = port->port_priv;
395 schedule_work(&state->work);
396 ci_dbg_print("%s: Wakeup CI1\n", __func__);
397 }
390 398
391 return 1; 399 return 1;
392} 400}
diff --git a/drivers/media/video/cx23885/cx23885-cards.c b/drivers/media/video/cx23885/cx23885-cards.c
index 8861309268b1..b298b730943c 100644
--- a/drivers/media/video/cx23885/cx23885-cards.c
+++ b/drivers/media/video/cx23885/cx23885-cards.c
@@ -309,6 +309,26 @@ struct cx23885_board cx23885_boards[] = {
309 CX25840_COMPONENT_ON, 309 CX25840_COMPONENT_ON,
310 } }, 310 } },
311 }, 311 },
312 [CX23885_BOARD_GOTVIEW_X5_3D_HYBRID] = {
313 .name = "GoTView X5 3D Hybrid",
314 .tuner_type = TUNER_XC5000,
315 .tuner_addr = 0x64,
316 .porta = CX23885_ANALOG_VIDEO,
317 .portb = CX23885_MPEG_DVB,
318 .input = {{
319 .type = CX23885_VMUX_TELEVISION,
320 .vmux = CX25840_VIN2_CH1 |
321 CX25840_VIN5_CH2,
322 .gpio0 = 0x02,
323 }, {
324 .type = CX23885_VMUX_COMPOSITE1,
325 .vmux = CX23885_VMUX_COMPOSITE1,
326 }, {
327 .type = CX23885_VMUX_SVIDEO,
328 .vmux = CX25840_SVIDEO_LUMA3 |
329 CX25840_SVIDEO_CHROMA4,
330 } },
331 },
312}; 332};
313const unsigned int cx23885_bcount = ARRAY_SIZE(cx23885_boards); 333const unsigned int cx23885_bcount = ARRAY_SIZE(cx23885_boards);
314 334
@@ -496,6 +516,10 @@ struct cx23885_subid cx23885_subids[] = {
496 .subvendor = 0x107d, 516 .subvendor = 0x107d,
497 .subdevice = 0x6f22, 517 .subdevice = 0x6f22,
498 .card = CX23885_BOARD_LEADTEK_WINFAST_PXTV1200, 518 .card = CX23885_BOARD_LEADTEK_WINFAST_PXTV1200,
519 }, {
520 .subvendor = 0x5654,
521 .subdevice = 0x2390,
522 .card = CX23885_BOARD_GOTVIEW_X5_3D_HYBRID,
499 }, 523 },
500}; 524};
501const unsigned int cx23885_idcount = ARRAY_SIZE(cx23885_subids); 525const unsigned int cx23885_idcount = ARRAY_SIZE(cx23885_subids);
@@ -712,6 +736,10 @@ int cx23885_tuner_callback(void *priv, int component, int command, int arg)
712 else if (port->nr == 2) 736 else if (port->nr == 2)
713 bitmask = 0x04; 737 bitmask = 0x04;
714 break; 738 break;
739 case CX23885_BOARD_GOTVIEW_X5_3D_HYBRID:
740 /* Tuner Reset Command */
741 bitmask = 0x02;
742 break;
715 } 743 }
716 744
717 if (bitmask) { 745 if (bitmask) {
@@ -967,6 +995,9 @@ void cx23885_gpio_setup(struct cx23885_dev *dev)
967 /* CX24228 GPIO */ 995 /* CX24228 GPIO */
968 /* Connected to IF / Mux */ 996 /* Connected to IF / Mux */
969 break; 997 break;
998 case CX23885_BOARD_GOTVIEW_X5_3D_HYBRID:
999 cx_set(GP0_IO, 0x00010001); /* Bring the part out of reset */
1000 break;
970 } 1001 }
971} 1002}
972 1003
@@ -1218,6 +1249,7 @@ void cx23885_card_setup(struct cx23885_dev *dev)
1218 case CX23885_BOARD_HAUPPAUGE_HVR1850: 1249 case CX23885_BOARD_HAUPPAUGE_HVR1850:
1219 case CX23885_BOARD_COMPRO_VIDEOMATE_E800: 1250 case CX23885_BOARD_COMPRO_VIDEOMATE_E800:
1220 case CX23885_BOARD_HAUPPAUGE_HVR1290: 1251 case CX23885_BOARD_HAUPPAUGE_HVR1290:
1252 case CX23885_BOARD_GOTVIEW_X5_3D_HYBRID:
1221 default: 1253 default:
1222 ts2->gen_ctrl_val = 0xc; /* Serial bus + punctured clock */ 1254 ts2->gen_ctrl_val = 0xc; /* Serial bus + punctured clock */
1223 ts2->ts_clk_en_val = 0x1; /* Enable TS_CLK */ 1255 ts2->ts_clk_en_val = 0x1; /* Enable TS_CLK */
@@ -1245,6 +1277,7 @@ void cx23885_card_setup(struct cx23885_dev *dev)
1245 case CX23885_BOARD_MAGICPRO_PROHDTVE2: 1277 case CX23885_BOARD_MAGICPRO_PROHDTVE2:
1246 case CX23885_BOARD_HAUPPAUGE_HVR1290: 1278 case CX23885_BOARD_HAUPPAUGE_HVR1290:
1247 case CX23885_BOARD_LEADTEK_WINFAST_PXTV1200: 1279 case CX23885_BOARD_LEADTEK_WINFAST_PXTV1200:
1280 case CX23885_BOARD_GOTVIEW_X5_3D_HYBRID:
1248 dev->sd_cx25840 = v4l2_i2c_new_subdev(&dev->v4l2_dev, 1281 dev->sd_cx25840 = v4l2_i2c_new_subdev(&dev->v4l2_dev,
1249 &dev->i2c_bus[2].i2c_adap, 1282 &dev->i2c_bus[2].i2c_adap,
1250 "cx25840", 0x88 >> 1, NULL); 1283 "cx25840", 0x88 >> 1, NULL);
diff --git a/drivers/media/video/cx23885/cx23885-input.c b/drivers/media/video/cx23885/cx23885-input.c
index bb61870b8d6e..0b0d0664382a 100644
--- a/drivers/media/video/cx23885/cx23885-input.c
+++ b/drivers/media/video/cx23885/cx23885-input.c
@@ -35,9 +35,8 @@
35 * 02110-1301, USA. 35 * 02110-1301, USA.
36 */ 36 */
37 37
38#include <linux/input.h>
39#include <linux/slab.h> 38#include <linux/slab.h>
40#include <media/ir-core.h> 39#include <media/rc-core.h>
41#include <media/v4l2-subdev.h> 40#include <media/v4l2-subdev.h>
42 41
43#include "cx23885.h" 42#include "cx23885.h"
@@ -62,16 +61,16 @@ static void cx23885_input_process_measurements(struct cx23885_dev *dev,
62 count = num / sizeof(struct ir_raw_event); 61 count = num / sizeof(struct ir_raw_event);
63 62
64 for (i = 0; i < count; i++) { 63 for (i = 0; i < count; i++) {
65 ir_raw_event_store(kernel_ir->inp_dev, 64 ir_raw_event_store(kernel_ir->rc,
66 &ir_core_event[i]); 65 &ir_core_event[i]);
67 handle = true; 66 handle = true;
68 } 67 }
69 } while (num != 0); 68 } while (num != 0);
70 69
71 if (overrun) 70 if (overrun)
72 ir_raw_event_reset(kernel_ir->inp_dev); 71 ir_raw_event_reset(kernel_ir->rc);
73 else if (handle) 72 else if (handle)
74 ir_raw_event_handle(kernel_ir->inp_dev); 73 ir_raw_event_handle(kernel_ir->rc);
75} 74}
76 75
77void cx23885_input_rx_work_handler(struct cx23885_dev *dev, u32 events) 76void cx23885_input_rx_work_handler(struct cx23885_dev *dev, u32 events)
@@ -197,9 +196,9 @@ static int cx23885_input_ir_start(struct cx23885_dev *dev)
197 return 0; 196 return 0;
198} 197}
199 198
200static int cx23885_input_ir_open(void *priv) 199static int cx23885_input_ir_open(struct rc_dev *rc)
201{ 200{
202 struct cx23885_kernel_ir *kernel_ir = priv; 201 struct cx23885_kernel_ir *kernel_ir = rc->priv;
203 202
204 if (kernel_ir->cx == NULL) 203 if (kernel_ir->cx == NULL)
205 return -ENODEV; 204 return -ENODEV;
@@ -234,9 +233,9 @@ static void cx23885_input_ir_stop(struct cx23885_dev *dev)
234 flush_scheduled_work(); 233 flush_scheduled_work();
235} 234}
236 235
237static void cx23885_input_ir_close(void *priv) 236static void cx23885_input_ir_close(struct rc_dev *rc)
238{ 237{
239 struct cx23885_kernel_ir *kernel_ir = priv; 238 struct cx23885_kernel_ir *kernel_ir = rc->priv;
240 239
241 if (kernel_ir->cx != NULL) 240 if (kernel_ir->cx != NULL)
242 cx23885_input_ir_stop(kernel_ir->cx); 241 cx23885_input_ir_stop(kernel_ir->cx);
@@ -245,9 +244,7 @@ static void cx23885_input_ir_close(void *priv)
245int cx23885_input_init(struct cx23885_dev *dev) 244int cx23885_input_init(struct cx23885_dev *dev)
246{ 245{
247 struct cx23885_kernel_ir *kernel_ir; 246 struct cx23885_kernel_ir *kernel_ir;
248 struct input_dev *inp_dev; 247 struct rc_dev *rc;
249 struct ir_dev_props *props;
250
251 char *rc_map; 248 char *rc_map;
252 enum rc_driver_type driver_type; 249 enum rc_driver_type driver_type;
253 unsigned long allowed_protos; 250 unsigned long allowed_protos;
@@ -267,14 +264,14 @@ int cx23885_input_init(struct cx23885_dev *dev)
267 case CX23885_BOARD_HAUPPAUGE_HVR1250: 264 case CX23885_BOARD_HAUPPAUGE_HVR1250:
268 /* Integrated CX2388[58] IR controller */ 265 /* Integrated CX2388[58] IR controller */
269 driver_type = RC_DRIVER_IR_RAW; 266 driver_type = RC_DRIVER_IR_RAW;
270 allowed_protos = IR_TYPE_ALL; 267 allowed_protos = RC_TYPE_ALL;
271 /* The grey Hauppauge RC-5 remote */ 268 /* The grey Hauppauge RC-5 remote */
272 rc_map = RC_MAP_RC5_HAUPPAUGE_NEW; 269 rc_map = RC_MAP_RC5_HAUPPAUGE_NEW;
273 break; 270 break;
274 case CX23885_BOARD_TEVII_S470: 271 case CX23885_BOARD_TEVII_S470:
275 /* Integrated CX23885 IR controller */ 272 /* Integrated CX23885 IR controller */
276 driver_type = RC_DRIVER_IR_RAW; 273 driver_type = RC_DRIVER_IR_RAW;
277 allowed_protos = IR_TYPE_ALL; 274 allowed_protos = RC_TYPE_ALL;
278 /* A guess at the remote */ 275 /* A guess at the remote */
279 rc_map = RC_MAP_TEVII_NEC; 276 rc_map = RC_MAP_TEVII_NEC;
280 break; 277 break;
@@ -294,37 +291,36 @@ int cx23885_input_init(struct cx23885_dev *dev)
294 pci_name(dev->pci)); 291 pci_name(dev->pci));
295 292
296 /* input device */ 293 /* input device */
297 inp_dev = input_allocate_device(); 294 rc = rc_allocate_device();
298 if (inp_dev == NULL) { 295 if (!rc) {
299 ret = -ENOMEM; 296 ret = -ENOMEM;
300 goto err_out_free; 297 goto err_out_free;
301 } 298 }
302 299
303 kernel_ir->inp_dev = inp_dev; 300 kernel_ir->rc = rc;
304 inp_dev->name = kernel_ir->name; 301 rc->input_name = kernel_ir->name;
305 inp_dev->phys = kernel_ir->phys; 302 rc->input_phys = kernel_ir->phys;
306 inp_dev->id.bustype = BUS_PCI; 303 rc->input_id.bustype = BUS_PCI;
307 inp_dev->id.version = 1; 304 rc->input_id.version = 1;
308 if (dev->pci->subsystem_vendor) { 305 if (dev->pci->subsystem_vendor) {
309 inp_dev->id.vendor = dev->pci->subsystem_vendor; 306 rc->input_id.vendor = dev->pci->subsystem_vendor;
310 inp_dev->id.product = dev->pci->subsystem_device; 307 rc->input_id.product = dev->pci->subsystem_device;
311 } else { 308 } else {
312 inp_dev->id.vendor = dev->pci->vendor; 309 rc->input_id.vendor = dev->pci->vendor;
313 inp_dev->id.product = dev->pci->device; 310 rc->input_id.product = dev->pci->device;
314 } 311 }
315 inp_dev->dev.parent = &dev->pci->dev; 312 rc->dev.parent = &dev->pci->dev;
316 313 rc->driver_type = driver_type;
317 /* kernel ir device properties */ 314 rc->allowed_protos = allowed_protos;
318 props = &kernel_ir->props; 315 rc->priv = kernel_ir;
319 props->driver_type = driver_type; 316 rc->open = cx23885_input_ir_open;
320 props->allowed_protos = allowed_protos; 317 rc->close = cx23885_input_ir_close;
321 props->priv = kernel_ir; 318 rc->map_name = rc_map;
322 props->open = cx23885_input_ir_open; 319 rc->driver_name = MODULE_NAME;
323 props->close = cx23885_input_ir_close;
324 320
325 /* Go */ 321 /* Go */
326 dev->kernel_ir = kernel_ir; 322 dev->kernel_ir = kernel_ir;
327 ret = ir_input_register(inp_dev, rc_map, props, MODULE_NAME); 323 ret = rc_register_device(rc);
328 if (ret) 324 if (ret)
329 goto err_out_stop; 325 goto err_out_stop;
330 326
@@ -333,7 +329,7 @@ int cx23885_input_init(struct cx23885_dev *dev)
333err_out_stop: 329err_out_stop:
334 cx23885_input_ir_stop(dev); 330 cx23885_input_ir_stop(dev);
335 dev->kernel_ir = NULL; 331 dev->kernel_ir = NULL;
336 /* TODO: double check clean-up of kernel_ir->inp_dev */ 332 rc_free_device(rc);
337err_out_free: 333err_out_free:
338 kfree(kernel_ir->phys); 334 kfree(kernel_ir->phys);
339 kfree(kernel_ir->name); 335 kfree(kernel_ir->name);
@@ -348,7 +344,7 @@ void cx23885_input_fini(struct cx23885_dev *dev)
348 344
349 if (dev->kernel_ir == NULL) 345 if (dev->kernel_ir == NULL)
350 return; 346 return;
351 ir_input_unregister(dev->kernel_ir->inp_dev); 347 rc_unregister_device(dev->kernel_ir->rc);
352 kfree(dev->kernel_ir->phys); 348 kfree(dev->kernel_ir->phys);
353 kfree(dev->kernel_ir->name); 349 kfree(dev->kernel_ir->name);
354 kfree(dev->kernel_ir); 350 kfree(dev->kernel_ir);
diff --git a/drivers/media/video/cx23885/cx23885-video.c b/drivers/media/video/cx23885/cx23885-video.c
index 8b2fb8a4375c..644fcb808c0b 100644
--- a/drivers/media/video/cx23885/cx23885-video.c
+++ b/drivers/media/video/cx23885/cx23885-video.c
@@ -1024,35 +1024,6 @@ static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
1024 return 0; 1024 return 0;
1025} 1025}
1026 1026
1027#ifdef CONFIG_VIDEO_V4L1_COMPAT
1028static int vidiocgmbuf(struct file *file, void *priv,
1029 struct video_mbuf *mbuf)
1030{
1031 struct cx23885_fh *fh = priv;
1032 struct videobuf_queue *q;
1033 struct v4l2_requestbuffers req;
1034 unsigned int i;
1035 int err;
1036
1037 q = get_queue(fh);
1038 memset(&req, 0, sizeof(req));
1039 req.type = q->type;
1040 req.count = 8;
1041 req.memory = V4L2_MEMORY_MMAP;
1042 err = videobuf_reqbufs(q, &req);
1043 if (err < 0)
1044 return err;
1045
1046 mbuf->frames = req.count;
1047 mbuf->size = 0;
1048 for (i = 0; i < mbuf->frames; i++) {
1049 mbuf->offsets[i] = q->bufs[i]->boff;
1050 mbuf->size += q->bufs[i]->bsize;
1051 }
1052 return 0;
1053}
1054#endif
1055
1056static int vidioc_reqbufs(struct file *file, void *priv, 1027static int vidioc_reqbufs(struct file *file, void *priv,
1057 struct v4l2_requestbuffers *p) 1028 struct v4l2_requestbuffers *p)
1058{ 1029{
@@ -1155,7 +1126,6 @@ static int cx23885_enum_input(struct cx23885_dev *dev, struct v4l2_input *i)
1155 if (0 == INPUT(n)->type) 1126 if (0 == INPUT(n)->type)
1156 return -EINVAL; 1127 return -EINVAL;
1157 1128
1158 memset(i, 0, sizeof(*i));
1159 i->index = n; 1129 i->index = n;
1160 i->type = V4L2_INPUT_TYPE_CAMERA; 1130 i->type = V4L2_INPUT_TYPE_CAMERA;
1161 strcpy(i->name, iname[INPUT(n)->type]); 1131 strcpy(i->name, iname[INPUT(n)->type]);
@@ -1427,9 +1397,6 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
1427 .vidioc_s_ctrl = vidioc_s_ctrl, 1397 .vidioc_s_ctrl = vidioc_s_ctrl,
1428 .vidioc_streamon = vidioc_streamon, 1398 .vidioc_streamon = vidioc_streamon,
1429 .vidioc_streamoff = vidioc_streamoff, 1399 .vidioc_streamoff = vidioc_streamoff,
1430#ifdef CONFIG_VIDEO_V4L1_COMPAT
1431 .vidiocgmbuf = vidiocgmbuf,
1432#endif
1433 .vidioc_g_tuner = vidioc_g_tuner, 1400 .vidioc_g_tuner = vidioc_g_tuner,
1434 .vidioc_s_tuner = vidioc_s_tuner, 1401 .vidioc_s_tuner = vidioc_s_tuner,
1435 .vidioc_g_frequency = vidioc_g_frequency, 1402 .vidioc_g_frequency = vidioc_g_frequency,
diff --git a/drivers/media/video/cx23885/cx23885.h b/drivers/media/video/cx23885/cx23885.h
index ed94b17dd8a5..62e41ab65810 100644
--- a/drivers/media/video/cx23885/cx23885.h
+++ b/drivers/media/video/cx23885/cx23885.h
@@ -30,7 +30,7 @@
30#include <media/tveeprom.h> 30#include <media/tveeprom.h>
31#include <media/videobuf-dma-sg.h> 31#include <media/videobuf-dma-sg.h>
32#include <media/videobuf-dvb.h> 32#include <media/videobuf-dvb.h>
33#include <media/ir-core.h> 33#include <media/rc-core.h>
34 34
35#include "btcx-risc.h" 35#include "btcx-risc.h"
36#include "cx23885-reg.h" 36#include "cx23885-reg.h"
@@ -84,6 +84,7 @@
84#define CX23885_BOARD_HAUPPAUGE_HVR1290 26 84#define CX23885_BOARD_HAUPPAUGE_HVR1290 26
85#define CX23885_BOARD_MYGICA_X8558PRO 27 85#define CX23885_BOARD_MYGICA_X8558PRO 27
86#define CX23885_BOARD_LEADTEK_WINFAST_PXTV1200 28 86#define CX23885_BOARD_LEADTEK_WINFAST_PXTV1200 28
87#define CX23885_BOARD_GOTVIEW_X5_3D_HYBRID 29
87 88
88#define GPIO_0 0x00000001 89#define GPIO_0 0x00000001
89#define GPIO_1 0x00000002 90#define GPIO_1 0x00000002
@@ -310,8 +311,7 @@ struct cx23885_kernel_ir {
310 char *name; 311 char *name;
311 char *phys; 312 char *phys;
312 313
313 struct input_dev *inp_dev; 314 struct rc_dev *rc;
314 struct ir_dev_props props;
315}; 315};
316 316
317struct cx23885_dev { 317struct cx23885_dev {
diff --git a/drivers/media/video/cx23885/cx23888-ir.c b/drivers/media/video/cx23885/cx23888-ir.c
index e78e3e4c8112..e37be6fcf67d 100644
--- a/drivers/media/video/cx23885/cx23888-ir.c
+++ b/drivers/media/video/cx23885/cx23888-ir.c
@@ -26,7 +26,7 @@
26 26
27#include <media/v4l2-device.h> 27#include <media/v4l2-device.h>
28#include <media/v4l2-chip-ident.h> 28#include <media/v4l2-chip-ident.h>
29#include <media/ir-core.h> 29#include <media/rc-core.h>
30 30
31#include "cx23885.h" 31#include "cx23885.h"
32 32
diff --git a/drivers/media/video/cx25840/cx25840-ir.c b/drivers/media/video/cx25840/cx25840-ir.c
index 97a4e9b25fe4..627926f6bde8 100644
--- a/drivers/media/video/cx25840/cx25840-ir.c
+++ b/drivers/media/video/cx25840/cx25840-ir.c
@@ -24,7 +24,7 @@
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/kfifo.h> 25#include <linux/kfifo.h>
26#include <media/cx25840.h> 26#include <media/cx25840.h>
27#include <media/ir-core.h> 27#include <media/rc-core.h>
28 28
29#include "cx25840-core.h" 29#include "cx25840-core.h"
30 30
diff --git a/drivers/media/video/cx88/Kconfig b/drivers/media/video/cx88/Kconfig
index 0fa85cbefbb1..5c42abdf422f 100644
--- a/drivers/media/video/cx88/Kconfig
+++ b/drivers/media/video/cx88/Kconfig
@@ -1,12 +1,11 @@
1config VIDEO_CX88 1config VIDEO_CX88
2 tristate "Conexant 2388x (bt878 successor) support" 2 tristate "Conexant 2388x (bt878 successor) support"
3 depends on VIDEO_DEV && PCI && I2C && INPUT 3 depends on VIDEO_DEV && PCI && I2C && RC_CORE
4 select I2C_ALGOBIT 4 select I2C_ALGOBIT
5 select VIDEO_BTCX 5 select VIDEO_BTCX
6 select VIDEOBUF_DMA_SG 6 select VIDEOBUF_DMA_SG
7 select VIDEO_TUNER 7 select VIDEO_TUNER
8 select VIDEO_TVEEPROM 8 select VIDEO_TVEEPROM
9 depends on VIDEO_IR
10 select VIDEO_WM8775 if VIDEO_HELPER_CHIPS_AUTO 9 select VIDEO_WM8775 if VIDEO_HELPER_CHIPS_AUTO
11 ---help--- 10 ---help---
12 This is a video4linux driver for Conexant 2388x based 11 This is a video4linux driver for Conexant 2388x based
diff --git a/drivers/media/video/cx88/cx88-blackbird.c b/drivers/media/video/cx88/cx88-blackbird.c
index d7c94848249e..bca307eb1e24 100644
--- a/drivers/media/video/cx88/cx88-blackbird.c
+++ b/drivers/media/video/cx88/cx88-blackbird.c
@@ -1064,7 +1064,7 @@ static int mpeg_open(struct file *file)
1064 err = drv->request_acquire(drv); 1064 err = drv->request_acquire(drv);
1065 if(err != 0) { 1065 if(err != 0) {
1066 dprintk(1,"%s: Unable to acquire hardware, %d\n", __func__, err); 1066 dprintk(1,"%s: Unable to acquire hardware, %d\n", __func__, err);
1067 mutex_unlock(&dev->core->lock);; 1067 mutex_unlock(&dev->core->lock);
1068 return err; 1068 return err;
1069 } 1069 }
1070 } 1070 }
diff --git a/drivers/media/video/cx88/cx88-cards.c b/drivers/media/video/cx88/cx88-cards.c
index 0ccc2afd7266..4e6ee5584cb3 100644
--- a/drivers/media/video/cx88/cx88-cards.c
+++ b/drivers/media/video/cx88/cx88-cards.c
@@ -47,7 +47,7 @@ MODULE_PARM_DESC(latency,"pci latency timer");
47 47
48static int disable_ir; 48static int disable_ir;
49module_param(disable_ir, int, 0444); 49module_param(disable_ir, int, 0444);
50MODULE_PARM_DESC(latency, "Disable IR support"); 50MODULE_PARM_DESC(disable_ir, "Disable IR support");
51 51
52#define info_printk(core, fmt, arg...) \ 52#define info_printk(core, fmt, arg...) \
53 printk(KERN_INFO "%s: " fmt, core->name , ## arg) 53 printk(KERN_INFO "%s: " fmt, core->name , ## arg)
diff --git a/drivers/media/video/cx88/cx88-dvb.c b/drivers/media/video/cx88/cx88-dvb.c
index 367a653f4c95..90717ee944ec 100644
--- a/drivers/media/video/cx88/cx88-dvb.c
+++ b/drivers/media/video/cx88/cx88-dvb.c
@@ -67,6 +67,10 @@ static unsigned int debug;
67module_param(debug, int, 0644); 67module_param(debug, int, 0644);
68MODULE_PARM_DESC(debug,"enable debug messages [dvb]"); 68MODULE_PARM_DESC(debug,"enable debug messages [dvb]");
69 69
70static unsigned int dvb_buf_tscnt = 32;
71module_param(dvb_buf_tscnt, int, 0644);
72MODULE_PARM_DESC(dvb_buf_tscnt, "DVB Buffer TS count [dvb]");
73
70DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); 74DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
71 75
72#define dprintk(level,fmt, arg...) if (debug >= level) \ 76#define dprintk(level,fmt, arg...) if (debug >= level) \
@@ -80,10 +84,10 @@ static int dvb_buf_setup(struct videobuf_queue *q,
80 struct cx8802_dev *dev = q->priv_data; 84 struct cx8802_dev *dev = q->priv_data;
81 85
82 dev->ts_packet_size = 188 * 4; 86 dev->ts_packet_size = 188 * 4;
83 dev->ts_packet_count = 32; 87 dev->ts_packet_count = dvb_buf_tscnt;
84 88
85 *size = dev->ts_packet_size * dev->ts_packet_count; 89 *size = dev->ts_packet_size * dev->ts_packet_count;
86 *count = 32; 90 *count = dvb_buf_tscnt;
87 return 0; 91 return 0;
88} 92}
89 93
diff --git a/drivers/media/video/cx88/cx88-i2c.c b/drivers/media/video/cx88/cx88-i2c.c
index f53836bb6a5a..a1fe0abb6e43 100644
--- a/drivers/media/video/cx88/cx88-i2c.c
+++ b/drivers/media/video/cx88/cx88-i2c.c
@@ -146,7 +146,6 @@ int cx88_i2c_init(struct cx88_core *core, struct pci_dev *pci)
146 core->i2c_adap.dev.parent = &pci->dev; 146 core->i2c_adap.dev.parent = &pci->dev;
147 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));
148 core->i2c_adap.owner = THIS_MODULE; 148 core->i2c_adap.owner = THIS_MODULE;
149 core->i2c_adap.id = I2C_HW_B_CX2388x;
150 core->i2c_algo.udelay = i2c_udelay; 149 core->i2c_algo.udelay = i2c_udelay;
151 core->i2c_algo.data = core; 150 core->i2c_algo.data = core;
152 i2c_set_adapdata(&core->i2c_adap, &core->v4l2_dev); 151 i2c_set_adapdata(&core->i2c_adap, &core->v4l2_dev);
diff --git a/drivers/media/video/cx88/cx88-input.c b/drivers/media/video/cx88/cx88-input.c
index fc777bc6e716..06f7d1d00944 100644
--- a/drivers/media/video/cx88/cx88-input.c
+++ b/drivers/media/video/cx88/cx88-input.c
@@ -24,14 +24,12 @@
24 24
25#include <linux/init.h> 25#include <linux/init.h>
26#include <linux/hrtimer.h> 26#include <linux/hrtimer.h>
27#include <linux/input.h>
28#include <linux/pci.h> 27#include <linux/pci.h>
29#include <linux/slab.h> 28#include <linux/slab.h>
30#include <linux/module.h> 29#include <linux/module.h>
31 30
32#include "cx88.h" 31#include "cx88.h"
33#include <media/ir-core.h> 32#include <media/rc-core.h>
34#include <media/ir-common.h>
35 33
36#define MODULE_NAME "cx88xx" 34#define MODULE_NAME "cx88xx"
37 35
@@ -39,9 +37,7 @@
39 37
40struct cx88_IR { 38struct cx88_IR {
41 struct cx88_core *core; 39 struct cx88_core *core;
42 struct input_dev *input; 40 struct rc_dev *dev;
43 struct ir_dev_props props;
44 u64 ir_type;
45 41
46 int users; 42 int users;
47 43
@@ -50,8 +46,6 @@ struct cx88_IR {
50 46
51 /* sample from gpio pin 16 */ 47 /* sample from gpio pin 16 */
52 u32 sampling; 48 u32 sampling;
53 u32 samples[16];
54 int scount;
55 49
56 /* poll external decoder */ 50 /* poll external decoder */
57 int polling; 51 int polling;
@@ -63,6 +57,10 @@ struct cx88_IR {
63 u32 mask_keyup; 57 u32 mask_keyup;
64}; 58};
65 59
60static unsigned ir_samplerate = 4;
61module_param(ir_samplerate, uint, 0444);
62MODULE_PARM_DESC(ir_samplerate, "IR samplerate in kHz, 1 - 20, default 4");
63
66static int ir_debug; 64static int ir_debug;
67module_param(ir_debug, int, 0644); /* debug level [IR] */ 65module_param(ir_debug, int, 0644); /* debug level [IR] */
68MODULE_PARM_DESC(ir_debug, "enable debug messages [IR]"); 66MODULE_PARM_DESC(ir_debug, "enable debug messages [IR]");
@@ -70,6 +68,9 @@ MODULE_PARM_DESC(ir_debug, "enable debug messages [IR]");
70#define ir_dprintk(fmt, arg...) if (ir_debug) \ 68#define ir_dprintk(fmt, arg...) if (ir_debug) \
71 printk(KERN_DEBUG "%s IR: " fmt , ir->core->name , ##arg) 69 printk(KERN_DEBUG "%s IR: " fmt , ir->core->name , ##arg)
72 70
71#define dprintk(fmt, arg...) if (ir_debug) \
72 printk(KERN_DEBUG "cx88 IR: " fmt , ##arg)
73
73/* ---------------------------------------------------------------------- */ 74/* ---------------------------------------------------------------------- */
74 75
75static void cx88_ir_handle_key(struct cx88_IR *ir) 76static void cx88_ir_handle_key(struct cx88_IR *ir)
@@ -125,21 +126,26 @@ static void cx88_ir_handle_key(struct cx88_IR *ir)
125 126
126 data = (data << 4) | ((gpio_key & 0xf0) >> 4); 127 data = (data << 4) | ((gpio_key & 0xf0) >> 4);
127 128
128 ir_keydown(ir->input, data, 0); 129 rc_keydown(ir->dev, data, 0);
129 130
130 } else if (ir->mask_keydown) { 131 } else if (ir->mask_keydown) {
131 /* bit set on keydown */ 132 /* bit set on keydown */
132 if (gpio & ir->mask_keydown) 133 if (gpio & ir->mask_keydown)
133 ir_keydown(ir->input, data, 0); 134 rc_keydown_notimeout(ir->dev, data, 0);
135 else
136 rc_keyup(ir->dev);
134 137
135 } else if (ir->mask_keyup) { 138 } else if (ir->mask_keyup) {
136 /* bit cleared on keydown */ 139 /* bit cleared on keydown */
137 if (0 == (gpio & ir->mask_keyup)) 140 if (0 == (gpio & ir->mask_keyup))
138 ir_keydown(ir->input, data, 0); 141 rc_keydown_notimeout(ir->dev, data, 0);
142 else
143 rc_keyup(ir->dev);
139 144
140 } else { 145 } else {
141 /* can't distinguish keydown/up :-/ */ 146 /* can't distinguish keydown/up :-/ */
142 ir_keydown(ir->input, data, 0); 147 rc_keydown_notimeout(ir->dev, data, 0);
148 rc_keyup(ir->dev);
143 } 149 }
144} 150}
145 151
@@ -176,8 +182,8 @@ static int __cx88_ir_start(void *priv)
176 } 182 }
177 if (ir->sampling) { 183 if (ir->sampling) {
178 core->pci_irqmask |= PCI_INT_IR_SMPINT; 184 core->pci_irqmask |= PCI_INT_IR_SMPINT;
179 cx_write(MO_DDS_IO, 0xa80a80); /* 4 kHz sample rate */ 185 cx_write(MO_DDS_IO, 0x33F286 * ir_samplerate); /* samplerate */
180 cx_write(MO_DDSCFG_IO, 0x5); /* enable */ 186 cx_write(MO_DDSCFG_IO, 0x5); /* enable */
181 } 187 }
182 return 0; 188 return 0;
183} 189}
@@ -214,17 +220,17 @@ void cx88_ir_stop(struct cx88_core *core)
214 __cx88_ir_stop(core); 220 __cx88_ir_stop(core);
215} 221}
216 222
217static int cx88_ir_open(void *priv) 223static int cx88_ir_open(struct rc_dev *rc)
218{ 224{
219 struct cx88_core *core = priv; 225 struct cx88_core *core = rc->priv;
220 226
221 core->ir->users++; 227 core->ir->users++;
222 return __cx88_ir_start(core); 228 return __cx88_ir_start(core);
223} 229}
224 230
225static void cx88_ir_close(void *priv) 231static void cx88_ir_close(struct rc_dev *rc)
226{ 232{
227 struct cx88_core *core = priv; 233 struct cx88_core *core = rc->priv;
228 234
229 core->ir->users--; 235 core->ir->users--;
230 if (!core->ir->users) 236 if (!core->ir->users)
@@ -236,20 +242,20 @@ static void cx88_ir_close(void *priv)
236int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci) 242int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
237{ 243{
238 struct cx88_IR *ir; 244 struct cx88_IR *ir;
239 struct input_dev *input_dev; 245 struct rc_dev *dev;
240 char *ir_codes = NULL; 246 char *ir_codes = NULL;
241 u64 ir_type = IR_TYPE_OTHER; 247 u64 rc_type = RC_TYPE_OTHER;
242 int err = -ENOMEM; 248 int err = -ENOMEM;
243 u32 hardware_mask = 0; /* For devices with a hardware mask, when 249 u32 hardware_mask = 0; /* For devices with a hardware mask, when
244 * used with a full-code IR table 250 * used with a full-code IR table
245 */ 251 */
246 252
247 ir = kzalloc(sizeof(*ir), GFP_KERNEL); 253 ir = kzalloc(sizeof(*ir), GFP_KERNEL);
248 input_dev = input_allocate_device(); 254 dev = rc_allocate_device();
249 if (!ir || !input_dev) 255 if (!ir || !dev)
250 goto err_out_free; 256 goto err_out_free;
251 257
252 ir->input = input_dev; 258 ir->dev = dev;
253 259
254 /* detect & configure */ 260 /* detect & configure */
255 switch (core->boardnr) { 261 switch (core->boardnr) {
@@ -264,7 +270,6 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
264 break; 270 break;
265 case CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1: 271 case CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1:
266 ir_codes = RC_MAP_CINERGY_1400; 272 ir_codes = RC_MAP_CINERGY_1400;
267 ir_type = IR_TYPE_NEC;
268 ir->sampling = 0xeb04; /* address */ 273 ir->sampling = 0xeb04; /* address */
269 break; 274 break;
270 case CX88_BOARD_HAUPPAUGE: 275 case CX88_BOARD_HAUPPAUGE:
@@ -279,7 +284,6 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
279 case CX88_BOARD_PCHDTV_HD5500: 284 case CX88_BOARD_PCHDTV_HD5500:
280 case CX88_BOARD_HAUPPAUGE_IRONLY: 285 case CX88_BOARD_HAUPPAUGE_IRONLY:
281 ir_codes = RC_MAP_HAUPPAUGE_NEW; 286 ir_codes = RC_MAP_HAUPPAUGE_NEW;
282 ir_type = IR_TYPE_RC5;
283 ir->sampling = 1; 287 ir->sampling = 1;
284 break; 288 break;
285 case CX88_BOARD_WINFAST_DTV2000H: 289 case CX88_BOARD_WINFAST_DTV2000H:
@@ -367,18 +371,15 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
367 case CX88_BOARD_PROF_7301: 371 case CX88_BOARD_PROF_7301:
368 case CX88_BOARD_PROF_6200: 372 case CX88_BOARD_PROF_6200:
369 ir_codes = RC_MAP_TBS_NEC; 373 ir_codes = RC_MAP_TBS_NEC;
370 ir_type = IR_TYPE_NEC;
371 ir->sampling = 0xff00; /* address */ 374 ir->sampling = 0xff00; /* address */
372 break; 375 break;
373 case CX88_BOARD_TEVII_S460: 376 case CX88_BOARD_TEVII_S460:
374 case CX88_BOARD_TEVII_S420: 377 case CX88_BOARD_TEVII_S420:
375 ir_codes = RC_MAP_TEVII_NEC; 378 ir_codes = RC_MAP_TEVII_NEC;
376 ir_type = IR_TYPE_NEC;
377 ir->sampling = 0xff00; /* address */ 379 ir->sampling = 0xff00; /* address */
378 break; 380 break;
379 case CX88_BOARD_DNTV_LIVE_DVB_T_PRO: 381 case CX88_BOARD_DNTV_LIVE_DVB_T_PRO:
380 ir_codes = RC_MAP_DNTV_LIVE_DVBT_PRO; 382 ir_codes = RC_MAP_DNTV_LIVE_DVBT_PRO;
381 ir_type = IR_TYPE_NEC;
382 ir->sampling = 0xff00; /* address */ 383 ir->sampling = 0xff00; /* address */
383 break; 384 break;
384 case CX88_BOARD_NORWOOD_MICRO: 385 case CX88_BOARD_NORWOOD_MICRO:
@@ -396,7 +397,6 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
396 break; 397 break;
397 case CX88_BOARD_PINNACLE_PCTV_HD_800i: 398 case CX88_BOARD_PINNACLE_PCTV_HD_800i:
398 ir_codes = RC_MAP_PINNACLE_PCTV_HD; 399 ir_codes = RC_MAP_PINNACLE_PCTV_HD;
399 ir_type = IR_TYPE_RC5;
400 ir->sampling = 1; 400 ir->sampling = 1;
401 break; 401 break;
402 case CX88_BOARD_POWERCOLOR_REAL_ANGEL: 402 case CX88_BOARD_POWERCOLOR_REAL_ANGEL:
@@ -407,12 +407,12 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
407 break; 407 break;
408 case CX88_BOARD_TWINHAN_VP1027_DVBS: 408 case CX88_BOARD_TWINHAN_VP1027_DVBS:
409 ir_codes = RC_MAP_TWINHAN_VP1027_DVBS; 409 ir_codes = RC_MAP_TWINHAN_VP1027_DVBS;
410 ir_type = IR_TYPE_NEC; 410 rc_type = RC_TYPE_NEC;
411 ir->sampling = 0xff00; /* address */ 411 ir->sampling = 0xff00; /* address */
412 break; 412 break;
413 } 413 }
414 414
415 if (NULL == ir_codes) { 415 if (!ir_codes) {
416 err = -ENODEV; 416 err = -ENODEV;
417 goto err_out_free; 417 goto err_out_free;
418 } 418 }
@@ -436,37 +436,45 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
436 snprintf(ir->name, sizeof(ir->name), "cx88 IR (%s)", core->board.name); 436 snprintf(ir->name, sizeof(ir->name), "cx88 IR (%s)", core->board.name);
437 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0", pci_name(pci)); 437 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0", pci_name(pci));
438 438
439 ir->ir_type = ir_type; 439 dev->input_name = ir->name;
440 440 dev->input_phys = ir->phys;
441 input_dev->name = ir->name; 441 dev->input_id.bustype = BUS_PCI;
442 input_dev->phys = ir->phys; 442 dev->input_id.version = 1;
443 input_dev->id.bustype = BUS_PCI;
444 input_dev->id.version = 1;
445 if (pci->subsystem_vendor) { 443 if (pci->subsystem_vendor) {
446 input_dev->id.vendor = pci->subsystem_vendor; 444 dev->input_id.vendor = pci->subsystem_vendor;
447 input_dev->id.product = pci->subsystem_device; 445 dev->input_id.product = pci->subsystem_device;
448 } else { 446 } else {
449 input_dev->id.vendor = pci->vendor; 447 dev->input_id.vendor = pci->vendor;
450 input_dev->id.product = pci->device; 448 dev->input_id.product = pci->device;
451 } 449 }
452 input_dev->dev.parent = &pci->dev; 450 dev->dev.parent = &pci->dev;
453 /* record handles to ourself */ 451 dev->map_name = ir_codes;
452 dev->driver_name = MODULE_NAME;
453 dev->priv = core;
454 dev->open = cx88_ir_open;
455 dev->close = cx88_ir_close;
456 dev->scanmask = hardware_mask;
457
458 if (ir->sampling) {
459 dev->driver_type = RC_DRIVER_IR_RAW;
460 dev->timeout = 10 * 1000 * 1000; /* 10 ms */
461 } else {
462 dev->driver_type = RC_DRIVER_SCANCODE;
463 dev->allowed_protos = rc_type;
464 }
465
454 ir->core = core; 466 ir->core = core;
455 core->ir = ir; 467 core->ir = ir;
456 468
457 ir->props.priv = core;
458 ir->props.open = cx88_ir_open;
459 ir->props.close = cx88_ir_close;
460 ir->props.scanmask = hardware_mask;
461
462 /* all done */ 469 /* all done */
463 err = ir_input_register(ir->input, ir_codes, &ir->props, MODULE_NAME); 470 err = rc_register_device(dev);
464 if (err) 471 if (err)
465 goto err_out_free; 472 goto err_out_free;
466 473
467 return 0; 474 return 0;
468 475
469 err_out_free: 476err_out_free:
477 rc_free_device(dev);
470 core->ir = NULL; 478 core->ir = NULL;
471 kfree(ir); 479 kfree(ir);
472 return err; 480 return err;
@@ -481,7 +489,7 @@ int cx88_ir_fini(struct cx88_core *core)
481 return 0; 489 return 0;
482 490
483 cx88_ir_stop(core); 491 cx88_ir_stop(core);
484 ir_input_unregister(ir->input); 492 rc_unregister_device(ir->dev);
485 kfree(ir); 493 kfree(ir);
486 494
487 /* done */ 495 /* done */
@@ -494,135 +502,75 @@ int cx88_ir_fini(struct cx88_core *core)
494void cx88_ir_irq(struct cx88_core *core) 502void cx88_ir_irq(struct cx88_core *core)
495{ 503{
496 struct cx88_IR *ir = core->ir; 504 struct cx88_IR *ir = core->ir;
497 u32 samples, ircode; 505 u32 samples;
498 int i, start, range, toggle, dev, code; 506 unsigned todo, bits;
507 struct ir_raw_event ev;
499 508
500 if (NULL == ir) 509 if (!ir || !ir->sampling)
501 return;
502 if (!ir->sampling)
503 return; 510 return;
504 511
512 /*
513 * Samples are stored in a 32 bit register, oldest sample in
514 * the msb. A set bit represents space and an unset bit
515 * represents a pulse.
516 */
505 samples = cx_read(MO_SAMPLE_IO); 517 samples = cx_read(MO_SAMPLE_IO);
506 if (0 != samples && 0xffffffff != samples) {
507 /* record sample data */
508 if (ir->scount < ARRAY_SIZE(ir->samples))
509 ir->samples[ir->scount++] = samples;
510 return;
511 }
512 if (!ir->scount) {
513 /* nothing to sample */
514 return;
515 }
516
517 /* have a complete sample */
518 if (ir->scount < ARRAY_SIZE(ir->samples))
519 ir->samples[ir->scount++] = samples;
520 for (i = 0; i < ir->scount; i++)
521 ir->samples[i] = ~ir->samples[i];
522 if (ir_debug)
523 ir_dump_samples(ir->samples, ir->scount);
524 518
525 /* decode it */ 519 if (samples == 0xff && ir->dev->idle)
526 switch (core->boardnr) { 520 return;
527 case CX88_BOARD_TEVII_S460:
528 case CX88_BOARD_TEVII_S420:
529 case CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1:
530 case CX88_BOARD_DNTV_LIVE_DVB_T_PRO:
531 case CX88_BOARD_OMICOM_SS4_PCI:
532 case CX88_BOARD_SATTRADE_ST4200:
533 case CX88_BOARD_TBS_8920:
534 case CX88_BOARD_TBS_8910:
535 case CX88_BOARD_PROF_7300:
536 case CX88_BOARD_PROF_7301:
537 case CX88_BOARD_PROF_6200:
538 case CX88_BOARD_TWINHAN_VP1027_DVBS:
539 ircode = ir_decode_pulsedistance(ir->samples, ir->scount, 1, 4);
540
541 if (ircode == 0xffffffff) { /* decoding error */
542 ir_dprintk("pulse distance decoding error\n");
543 break;
544 }
545
546 ir_dprintk("pulse distance decoded: %x\n", ircode);
547 521
548 if (ircode == 0) { /* key still pressed */ 522 init_ir_raw_event(&ev);
549 ir_dprintk("pulse distance decoded repeat code\n"); 523 for (todo = 32; todo > 0; todo -= bits) {
550 ir_repeat(ir->input); 524 ev.pulse = samples & 0x80000000 ? false : true;
551 break; 525 bits = min(todo, 32U - fls(ev.pulse ? samples : ~samples));
552 } 526 ev.duration = (bits * NSEC_PER_SEC) / (1000 * ir_samplerate);
527 ir_raw_event_store_with_filter(ir->dev, &ev);
528 samples <<= bits;
529 }
530 ir_raw_event_handle(ir->dev);
531}
553 532
554 if ((ircode & 0xffff) != (ir->sampling & 0xffff)) { /* wrong address */ 533static int get_key_pvr2000(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
555 ir_dprintk("pulse distance decoded wrong address\n"); 534{
556 break; 535 int flags, code;
557 }
558 536
559 if (((~ircode >> 24) & 0xff) != ((ircode >> 16) & 0xff)) { /* wrong checksum */ 537 /* poll IR chip */
560 ir_dprintk("pulse distance decoded wrong check sum\n"); 538 flags = i2c_smbus_read_byte_data(ir->c, 0x10);
561 break; 539 if (flags < 0) {
562 } 540 dprintk("read error\n");
541 return 0;
542 }
543 /* key pressed ? */
544 if (0 == (flags & 0x80))
545 return 0;
563 546
564 ir_dprintk("Key Code: %x\n", (ircode >> 16) & 0xff); 547 /* read actual key code */
565 ir_keydown(ir->input, (ircode >> 16) & 0xff, 0); 548 code = i2c_smbus_read_byte_data(ir->c, 0x00);
566 break; 549 if (code < 0) {
567 case CX88_BOARD_HAUPPAUGE: 550 dprintk("read error\n");
568 case CX88_BOARD_HAUPPAUGE_DVB_T1: 551 return 0;
569 case CX88_BOARD_HAUPPAUGE_NOVASE2_S1:
570 case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1:
571 case CX88_BOARD_HAUPPAUGE_HVR1100:
572 case CX88_BOARD_HAUPPAUGE_HVR3000:
573 case CX88_BOARD_HAUPPAUGE_HVR4000:
574 case CX88_BOARD_HAUPPAUGE_HVR4000LITE:
575 case CX88_BOARD_PCHDTV_HD3000:
576 case CX88_BOARD_PCHDTV_HD5500:
577 case CX88_BOARD_HAUPPAUGE_IRONLY:
578 ircode = ir_decode_biphase(ir->samples, ir->scount, 5, 7);
579 ir_dprintk("biphase decoded: %x\n", ircode);
580 /*
581 * RC5 has an extension bit which adds a new range
582 * of available codes, this is detected here. Also
583 * hauppauge remotes (black/silver) always use
584 * specific device ids. If we do not filter the
585 * device ids then messages destined for devices
586 * such as TVs (id=0) will get through to the
587 * device causing mis-fired events.
588 */
589 /* split rc5 data block ... */
590 start = (ircode & 0x2000) >> 13;
591 range = (ircode & 0x1000) >> 12;
592 toggle= (ircode & 0x0800) >> 11;
593 dev = (ircode & 0x07c0) >> 6;
594 code = (ircode & 0x003f) | ((range << 6) ^ 0x0040);
595 if( start != 1)
596 /* no key pressed */
597 break;
598 if ( dev != 0x1e && dev != 0x1f )
599 /* not a hauppauge remote */
600 break;
601 ir_keydown(ir->input, code, toggle);
602 break;
603 case CX88_BOARD_PINNACLE_PCTV_HD_800i:
604 ircode = ir_decode_biphase(ir->samples, ir->scount, 5, 7);
605 ir_dprintk("biphase decoded: %x\n", ircode);
606 if ((ircode & 0xfffff000) != 0x3000)
607 break;
608 /* Note: bit 0x800 being the toggle is assumed, not checked
609 with real hardware */
610 ir_keydown(ir->input, ircode & 0x3f, ircode & 0x0800 ? 1 : 0);
611 break;
612 } 552 }
613 553
614 ir->scount = 0; 554 dprintk("IR Key/Flags: (0x%02x/0x%02x)\n",
615 return; 555 code & 0xff, flags & 0xff);
616}
617 556
557 *ir_key = code & 0xff;
558 *ir_raw = code;
559 return 1;
560}
618 561
619void cx88_i2c_init_ir(struct cx88_core *core) 562void cx88_i2c_init_ir(struct cx88_core *core)
620{ 563{
621 struct i2c_board_info info; 564 struct i2c_board_info info;
622 const unsigned short addr_list[] = { 565 const unsigned short default_addr_list[] = {
623 0x18, 0x6b, 0x71, 566 0x18, 0x6b, 0x71,
624 I2C_CLIENT_END 567 I2C_CLIENT_END
625 }; 568 };
569 const unsigned short pvr2000_addr_list[] = {
570 0x18, 0x1a,
571 I2C_CLIENT_END
572 };
573 const unsigned short *addr_list = default_addr_list;
626 const unsigned short *addrp; 574 const unsigned short *addrp;
627 /* Instantiate the IR receiver device, if present */ 575 /* Instantiate the IR receiver device, if present */
628 if (0 != core->i2c_rc) 576 if (0 != core->i2c_rc)
@@ -631,6 +579,16 @@ void cx88_i2c_init_ir(struct cx88_core *core)
631 memset(&info, 0, sizeof(struct i2c_board_info)); 579 memset(&info, 0, sizeof(struct i2c_board_info));
632 strlcpy(info.type, "ir_video", I2C_NAME_SIZE); 580 strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
633 581
582 switch (core->boardnr) {
583 case CX88_BOARD_LEADTEK_PVR2000:
584 addr_list = pvr2000_addr_list;
585 core->init_data.name = "cx88 Leadtek PVR 2000 remote";
586 core->init_data.type = RC_TYPE_UNKNOWN;
587 core->init_data.get_key = get_key_pvr2000;
588 core->init_data.ir_codes = RC_MAP_EMPTY;
589 break;
590 }
591
634 /* 592 /*
635 * We can't call i2c_new_probed_device() because it uses 593 * We can't call i2c_new_probed_device() because it uses
636 * quick writes for probing and at least some RC receiver 594 * quick writes for probing and at least some RC receiver
@@ -646,7 +604,7 @@ void cx88_i2c_init_ir(struct cx88_core *core)
646 /* Hauppauge XVR */ 604 /* Hauppauge XVR */
647 core->init_data.name = "cx88 Hauppauge XVR remote"; 605 core->init_data.name = "cx88 Hauppauge XVR remote";
648 core->init_data.ir_codes = RC_MAP_HAUPPAUGE_NEW; 606 core->init_data.ir_codes = RC_MAP_HAUPPAUGE_NEW;
649 core->init_data.type = IR_TYPE_RC5; 607 core->init_data.type = RC_TYPE_RC5;
650 core->init_data.internal_get_key_func = IR_KBD_GET_KEY_HAUP_XVR; 608 core->init_data.internal_get_key_func = IR_KBD_GET_KEY_HAUP_XVR;
651 609
652 info.platform_data = &core->init_data; 610 info.platform_data = &core->init_data;
diff --git a/drivers/media/video/cx88/cx88-video.c b/drivers/media/video/cx88/cx88-video.c
index d9249e5a04c9..508dabbed986 100644
--- a/drivers/media/video/cx88/cx88-video.c
+++ b/drivers/media/video/cx88/cx88-video.c
@@ -1156,15 +1156,6 @@ static int vidioc_enum_fmt_vid_cap (struct file *file, void *priv,
1156 return 0; 1156 return 0;
1157} 1157}
1158 1158
1159#ifdef CONFIG_VIDEO_V4L1_COMPAT
1160static int vidiocgmbuf (struct file *file, void *priv, struct video_mbuf *mbuf)
1161{
1162 struct cx8800_fh *fh = priv;
1163
1164 return videobuf_cgmbuf (get_queue(fh), mbuf, 8);
1165}
1166#endif
1167
1168static int vidioc_reqbufs (struct file *file, void *priv, struct v4l2_requestbuffers *p) 1159static int vidioc_reqbufs (struct file *file, void *priv, struct v4l2_requestbuffers *p)
1169{ 1160{
1170 struct cx8800_fh *fh = priv; 1161 struct cx8800_fh *fh = priv;
@@ -1706,9 +1697,6 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
1706 .vidioc_s_ctrl = vidioc_s_ctrl, 1697 .vidioc_s_ctrl = vidioc_s_ctrl,
1707 .vidioc_streamon = vidioc_streamon, 1698 .vidioc_streamon = vidioc_streamon,
1708 .vidioc_streamoff = vidioc_streamoff, 1699 .vidioc_streamoff = vidioc_streamoff,
1709#ifdef CONFIG_VIDEO_V4L1_COMPAT
1710 .vidiocgmbuf = vidiocgmbuf,
1711#endif
1712 .vidioc_g_tuner = vidioc_g_tuner, 1700 .vidioc_g_tuner = vidioc_g_tuner,
1713 .vidioc_s_tuner = vidioc_s_tuner, 1701 .vidioc_s_tuner = vidioc_s_tuner,
1714 .vidioc_g_frequency = vidioc_g_frequency, 1702 .vidioc_g_frequency = vidioc_g_frequency,
diff --git a/drivers/media/video/cx88/cx88-vp3054-i2c.c b/drivers/media/video/cx88/cx88-vp3054-i2c.c
index ec5476d8b10b..d77f8ecab9d7 100644
--- a/drivers/media/video/cx88/cx88-vp3054-i2c.c
+++ b/drivers/media/video/cx88/cx88-vp3054-i2c.c
@@ -125,7 +125,6 @@ int vp3054_i2c_probe(struct cx8802_dev *dev)
125 strlcpy(vp3054_i2c->adap.name, core->name, 125 strlcpy(vp3054_i2c->adap.name, core->name,
126 sizeof(vp3054_i2c->adap.name)); 126 sizeof(vp3054_i2c->adap.name));
127 vp3054_i2c->adap.owner = THIS_MODULE; 127 vp3054_i2c->adap.owner = THIS_MODULE;
128 vp3054_i2c->adap.id = I2C_HW_B_CX2388x;
129 vp3054_i2c->algo.data = dev; 128 vp3054_i2c->algo.data = dev;
130 i2c_set_adapdata(&vp3054_i2c->adap, dev); 129 i2c_set_adapdata(&vp3054_i2c->adap, dev);
131 vp3054_i2c->adap.algo_data = &vp3054_i2c->algo; 130 vp3054_i2c->adap.algo_data = &vp3054_i2c->algo;
diff --git a/drivers/media/video/davinci/vpfe_capture.c b/drivers/media/video/davinci/vpfe_capture.c
index 7333a9bb2549..353eadaa823e 100644
--- a/drivers/media/video/davinci/vpfe_capture.c
+++ b/drivers/media/video/davinci/vpfe_capture.c
@@ -1276,7 +1276,7 @@ static int vpfe_videobuf_prepare(struct videobuf_queue *vq,
1276 vb->size = vpfe_dev->fmt.fmt.pix.sizeimage; 1276 vb->size = vpfe_dev->fmt.fmt.pix.sizeimage;
1277 vb->field = field; 1277 vb->field = field;
1278 1278
1279 ret = videobuf_iolock(vq, vb, NULL);; 1279 ret = videobuf_iolock(vq, vb, NULL);
1280 if (ret < 0) 1280 if (ret < 0)
1281 return ret; 1281 return ret;
1282 1282
diff --git a/drivers/media/video/em28xx/Kconfig b/drivers/media/video/em28xx/Kconfig
index 66aefd6eef55..985100ea17a4 100644
--- a/drivers/media/video/em28xx/Kconfig
+++ b/drivers/media/video/em28xx/Kconfig
@@ -1,9 +1,9 @@
1config VIDEO_EM28XX 1config VIDEO_EM28XX
2 tristate "Empia EM28xx USB video capture support" 2 tristate "Empia EM28xx USB video capture support"
3 depends on VIDEO_DEV && I2C && INPUT 3 depends on VIDEO_DEV && I2C
4 select VIDEO_TUNER 4 select VIDEO_TUNER
5 select VIDEO_TVEEPROM 5 select VIDEO_TVEEPROM
6 depends on VIDEO_IR 6 depends on RC_CORE
7 select VIDEOBUF_VMALLOC 7 select VIDEOBUF_VMALLOC
8 select VIDEO_SAA711X if VIDEO_HELPER_CHIPS_AUTO 8 select VIDEO_SAA711X if VIDEO_HELPER_CHIPS_AUTO
9 select VIDEO_TVP5150 if VIDEO_HELPER_CHIPS_AUTO 9 select VIDEO_TVP5150 if VIDEO_HELPER_CHIPS_AUTO
@@ -37,6 +37,7 @@ config VIDEO_EM28XX_DVB
37 select DVB_LGDT330X if !DVB_FE_CUSTOMISE 37 select DVB_LGDT330X if !DVB_FE_CUSTOMISE
38 select DVB_ZL10353 if !DVB_FE_CUSTOMISE 38 select DVB_ZL10353 if !DVB_FE_CUSTOMISE
39 select DVB_TDA10023 if !DVB_FE_CUSTOMISE 39 select DVB_TDA10023 if !DVB_FE_CUSTOMISE
40 select DVB_S921 if !DVB_FE_CUSTOMISE
40 select VIDEOBUF_DVB 41 select VIDEOBUF_DVB
41 ---help--- 42 ---help---
42 This adds support for DVB cards based on the 43 This adds support for DVB cards based on the
diff --git a/drivers/media/video/em28xx/em28xx-cards.c b/drivers/media/video/em28xx/em28xx-cards.c
index f7e9168157a5..8af302b425b3 100644
--- a/drivers/media/video/em28xx/em28xx-cards.c
+++ b/drivers/media/video/em28xx/em28xx-cards.c
@@ -268,6 +268,20 @@ static struct em28xx_reg_seq dikom_dk300_digital[] = {
268}; 268};
269 269
270 270
271/* Reset for the most [digital] boards */
272static struct em28xx_reg_seq leadership_digital[] = {
273 {EM2874_R80_GPIO, 0x70, 0xff, 10},
274 { -1, -1, -1, -1},
275};
276
277static struct em28xx_reg_seq leadership_reset[] = {
278 {EM2874_R80_GPIO, 0xf0, 0xff, 10},
279 {EM2874_R80_GPIO, 0xb0, 0xff, 10},
280 {EM2874_R80_GPIO, 0xf0, 0xff, 10},
281 { -1, -1, -1, -1},
282};
283
284
271/* 285/*
272 * Board definitions 286 * Board definitions
273 */ 287 */
@@ -1224,6 +1238,19 @@ struct em28xx_board em28xx_boards[] = {
1224 .vmux = SAA7115_COMPOSITE0, 1238 .vmux = SAA7115_COMPOSITE0,
1225 } }, 1239 } },
1226 }, 1240 },
1241
1242 [EM2874_LEADERSHIP_ISDBT] = {
1243 .i2c_speed = EM2874_I2C_SECONDARY_BUS_SELECT |
1244 EM28XX_I2C_CLK_WAIT_ENABLE |
1245 EM28XX_I2C_FREQ_100_KHZ,
1246 .xclk = EM28XX_XCLK_FREQUENCY_10MHZ,
1247 .name = "EM2874 Leadership ISDBT",
1248 .tuner_type = TUNER_ABSENT,
1249 .tuner_gpio = leadership_reset,
1250 .dvb_gpio = leadership_digital,
1251 .has_dvb = 1,
1252 },
1253
1227 [EM2880_BOARD_MSI_DIGIVOX_AD] = { 1254 [EM2880_BOARD_MSI_DIGIVOX_AD] = {
1228 .name = "MSI DigiVox A/D", 1255 .name = "MSI DigiVox A/D",
1229 .valid = EM28XX_BOARD_NOT_VALIDATED, 1256 .valid = EM28XX_BOARD_NOT_VALIDATED,
@@ -1469,7 +1496,7 @@ struct em28xx_board em28xx_boards[] = {
1469 } }, 1496 } },
1470 }, 1497 },
1471 [EM2882_BOARD_TERRATEC_HYBRID_XS] = { 1498 [EM2882_BOARD_TERRATEC_HYBRID_XS] = {
1472 .name = "Terratec Hybrid XS (em2882)", 1499 .name = "Terratec Cinnergy Hybrid T USB XS (em2882)",
1473 .tuner_type = TUNER_XC2028, 1500 .tuner_type = TUNER_XC2028,
1474 .tuner_gpio = default_tuner_gpio, 1501 .tuner_gpio = default_tuner_gpio,
1475 .mts_firmware = 1, 1502 .mts_firmware = 1,
@@ -1633,11 +1660,11 @@ struct em28xx_board em28xx_boards[] = {
1633 .input = { { 1660 .input = { {
1634 .type = EM28XX_VMUX_COMPOSITE1, 1661 .type = EM28XX_VMUX_COMPOSITE1,
1635 .vmux = SAA7115_COMPOSITE0, 1662 .vmux = SAA7115_COMPOSITE0,
1636 .amux = EM28XX_AMUX_VIDEO2, 1663 .amux = EM28XX_AMUX_LINE_IN,
1637 }, { 1664 }, {
1638 .type = EM28XX_VMUX_SVIDEO, 1665 .type = EM28XX_VMUX_SVIDEO,
1639 .vmux = SAA7115_SVIDEO3, 1666 .vmux = SAA7115_SVIDEO3,
1640 .amux = EM28XX_AMUX_VIDEO2, 1667 .amux = EM28XX_AMUX_LINE_IN,
1641 } }, 1668 } },
1642 }, 1669 },
1643 [EM2860_BOARD_TERRATEC_AV350] = { 1670 [EM2860_BOARD_TERRATEC_AV350] = {
@@ -1754,6 +1781,8 @@ struct usb_device_id em28xx_id_table[] = {
1754 .driver_info = EM2820_BOARD_UNKNOWN }, 1781 .driver_info = EM2820_BOARD_UNKNOWN },
1755 { USB_DEVICE(0xeb1a, 0x2868), 1782 { USB_DEVICE(0xeb1a, 0x2868),
1756 .driver_info = EM2820_BOARD_UNKNOWN }, 1783 .driver_info = EM2820_BOARD_UNKNOWN },
1784 { USB_DEVICE(0xeb1a, 0x2875),
1785 .driver_info = EM2820_BOARD_UNKNOWN },
1757 { USB_DEVICE(0xeb1a, 0xe300), 1786 { USB_DEVICE(0xeb1a, 0xe300),
1758 .driver_info = EM2861_BOARD_KWORLD_PVRTV_300U }, 1787 .driver_info = EM2861_BOARD_KWORLD_PVRTV_300U },
1759 { USB_DEVICE(0xeb1a, 0xe303), 1788 { USB_DEVICE(0xeb1a, 0xe303),
@@ -1791,7 +1820,7 @@ struct usb_device_id em28xx_id_table[] = {
1791 { USB_DEVICE(0x0ccd, 0x005e), 1820 { USB_DEVICE(0x0ccd, 0x005e),
1792 .driver_info = EM2882_BOARD_TERRATEC_HYBRID_XS }, 1821 .driver_info = EM2882_BOARD_TERRATEC_HYBRID_XS },
1793 { USB_DEVICE(0x0ccd, 0x0042), 1822 { USB_DEVICE(0x0ccd, 0x0042),
1794 .driver_info = EM2880_BOARD_TERRATEC_HYBRID_XS }, 1823 .driver_info = EM2882_BOARD_TERRATEC_HYBRID_XS },
1795 { USB_DEVICE(0x0ccd, 0x0043), 1824 { USB_DEVICE(0x0ccd, 0x0043),
1796 .driver_info = EM2870_BOARD_TERRATEC_XS }, 1825 .driver_info = EM2870_BOARD_TERRATEC_XS },
1797 { USB_DEVICE(0x0ccd, 0x0047), 1826 { USB_DEVICE(0x0ccd, 0x0047),
@@ -1873,6 +1902,7 @@ static struct em28xx_hash_table em28xx_i2c_hash[] = {
1873 {0x77800080, EM2860_BOARD_TVP5150_REFERENCE_DESIGN, TUNER_ABSENT}, 1902 {0x77800080, EM2860_BOARD_TVP5150_REFERENCE_DESIGN, TUNER_ABSENT},
1874 {0xc51200e3, EM2820_BOARD_GADMEI_TVR200, TUNER_LG_PAL_NEW_TAPC}, 1903 {0xc51200e3, EM2820_BOARD_GADMEI_TVR200, TUNER_LG_PAL_NEW_TAPC},
1875 {0x4ba50080, EM2861_BOARD_GADMEI_UTV330PLUS, TUNER_TNF_5335MF}, 1904 {0x4ba50080, EM2861_BOARD_GADMEI_UTV330PLUS, TUNER_TNF_5335MF},
1905 {0x6b800080, EM2874_LEADERSHIP_ISDBT, TUNER_ABSENT},
1876}; 1906};
1877 1907
1878/* I2C possible address to saa7115, tvp5150, msp3400, tvaudio */ 1908/* I2C possible address to saa7115, tvp5150, msp3400, tvaudio */
@@ -2408,7 +2438,7 @@ void em28xx_register_i2c_ir(struct em28xx *dev)
2408 dev->init_data.get_key = em28xx_get_key_em_haup; 2438 dev->init_data.get_key = em28xx_get_key_em_haup;
2409 dev->init_data.name = "i2c IR (EM2840 Hauppauge)"; 2439 dev->init_data.name = "i2c IR (EM2840 Hauppauge)";
2410 case EM2820_BOARD_LEADTEK_WINFAST_USBII_DELUXE: 2440 case EM2820_BOARD_LEADTEK_WINFAST_USBII_DELUXE:
2411 dev->init_data.ir_codes = RC_MAP_WINFAST_USBII_DELUXE;; 2441 dev->init_data.ir_codes = RC_MAP_WINFAST_USBII_DELUXE;
2412 dev->init_data.get_key = em28xx_get_key_winfast_usbii_deluxe; 2442 dev->init_data.get_key = em28xx_get_key_winfast_usbii_deluxe;
2413 dev->init_data.name = "i2c IR (EM2820 Winfast TV USBII Deluxe)"; 2443 dev->init_data.name = "i2c IR (EM2820 Winfast TV USBII Deluxe)";
2414 break; 2444 break;
@@ -2430,8 +2460,36 @@ void em28xx_card_setup(struct em28xx *dev)
2430 dev->board.is_webcam = 0; 2460 dev->board.is_webcam = 0;
2431 else 2461 else
2432 dev->progressive = 1; 2462 dev->progressive = 1;
2433 } else 2463 }
2434 em28xx_set_model(dev); 2464
2465 if (!dev->board.is_webcam) {
2466 switch (dev->model) {
2467 case EM2820_BOARD_UNKNOWN:
2468 case EM2800_BOARD_UNKNOWN:
2469 /*
2470 * The K-WORLD DVB-T 310U is detected as an MSI Digivox AD.
2471 *
2472 * This occurs because they share identical USB vendor and
2473 * product IDs.
2474 *
2475 * What we do here is look up the EEPROM hash of the K-WORLD
2476 * and if it is found then we decide that we do not have
2477 * a DIGIVOX and reset the device to the K-WORLD instead.
2478 *
2479 * This solution is only valid if they do not share eeprom
2480 * hash identities which has not been determined as yet.
2481 */
2482 if (em28xx_hint_board(dev) < 0)
2483 em28xx_errdev("Board not discovered\n");
2484 else {
2485 em28xx_set_model(dev);
2486 em28xx_pre_card_setup(dev);
2487 }
2488 break;
2489 default:
2490 em28xx_set_model(dev);
2491 }
2492 }
2435 2493
2436 em28xx_info("Identified as %s (card=%d)\n", 2494 em28xx_info("Identified as %s (card=%d)\n",
2437 dev->board.name, dev->model); 2495 dev->board.name, dev->model);
@@ -2749,8 +2807,8 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
2749 em28xx_pre_card_setup(dev); 2807 em28xx_pre_card_setup(dev);
2750 2808
2751 if (!dev->board.is_em2800) { 2809 if (!dev->board.is_em2800) {
2752 /* Sets I2C speed to 100 KHz */ 2810 /* Resets I2C speed */
2753 retval = em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40); 2811 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, dev->board.i2c_speed);
2754 if (retval < 0) { 2812 if (retval < 0) {
2755 em28xx_errdev("%s: em28xx_write_regs_req failed!" 2813 em28xx_errdev("%s: em28xx_write_regs_req failed!"
2756 " retval [%d]\n", 2814 " retval [%d]\n",
diff --git a/drivers/media/video/em28xx/em28xx-dvb.c b/drivers/media/video/em28xx/em28xx-dvb.c
index 3ac8d3025fea..c7c04bf712aa 100644
--- a/drivers/media/video/em28xx/em28xx-dvb.c
+++ b/drivers/media/video/em28xx/em28xx-dvb.c
@@ -37,6 +37,7 @@
37#include "mt352_priv.h" /* FIXME */ 37#include "mt352_priv.h" /* FIXME */
38#include "tda1002x.h" 38#include "tda1002x.h"
39#include "tda18271.h" 39#include "tda18271.h"
40#include "s921.h"
40 41
41MODULE_DESCRIPTION("driver for em28xx based DVB cards"); 42MODULE_DESCRIPTION("driver for em28xx based DVB cards");
42MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>"); 43MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
@@ -245,6 +246,10 @@ static struct lgdt3305_config em2870_lgdt3304_dev = {
245 .qam_if_khz = 4000, 246 .qam_if_khz = 4000,
246}; 247};
247 248
249static struct s921_config sharp_isdbt = {
250 .demod_address = 0x30 >> 1
251};
252
248static struct zl10353_config em28xx_zl10353_with_xc3028 = { 253static struct zl10353_config em28xx_zl10353_with_xc3028 = {
249 .demod_address = (0x1e >> 1), 254 .demod_address = (0x1e >> 1),
250 .no_tuner = 1, 255 .no_tuner = 1,
@@ -481,6 +486,7 @@ static int dvb_init(struct em28xx *dev)
481 486
482 if (!dev->board.has_dvb) { 487 if (!dev->board.has_dvb) {
483 /* This device does not support the extension */ 488 /* This device does not support the extension */
489 printk(KERN_INFO "em28xx_dvb: This device does not support the extension\n");
484 return 0; 490 return 0;
485 } 491 }
486 492
@@ -496,6 +502,16 @@ static int dvb_init(struct em28xx *dev)
496 em28xx_set_mode(dev, EM28XX_DIGITAL_MODE); 502 em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
497 /* init frontend */ 503 /* init frontend */
498 switch (dev->model) { 504 switch (dev->model) {
505 case EM2874_LEADERSHIP_ISDBT:
506 dvb->frontend = dvb_attach(s921_attach,
507 &sharp_isdbt, &dev->i2c_adap);
508
509 if (!dvb->frontend) {
510 result = -EINVAL;
511 goto out_free;
512 }
513
514 break;
499 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850: 515 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850:
500 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950: 516 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950:
501 case EM2880_BOARD_PINNACLE_PCTV_HD_PRO: 517 case EM2880_BOARD_PINNACLE_PCTV_HD_PRO:
diff --git a/drivers/media/video/em28xx/em28xx-input.c b/drivers/media/video/em28xx/em28xx-input.c
index 6759cd5570dd..29cc74441a7d 100644
--- a/drivers/media/video/em28xx/em28xx-input.c
+++ b/drivers/media/video/em28xx/em28xx-input.c
@@ -25,7 +25,6 @@
25#include <linux/init.h> 25#include <linux/init.h>
26#include <linux/delay.h> 26#include <linux/delay.h>
27#include <linux/interrupt.h> 27#include <linux/interrupt.h>
28#include <linux/input.h>
29#include <linux/usb.h> 28#include <linux/usb.h>
30#include <linux/slab.h> 29#include <linux/slab.h>
31 30
@@ -64,7 +63,7 @@ struct em28xx_ir_poll_result {
64 63
65struct em28xx_IR { 64struct em28xx_IR {
66 struct em28xx *dev; 65 struct em28xx *dev;
67 struct input_dev *input; 66 struct rc_dev *rc;
68 char name[32]; 67 char name[32];
69 char phys[32]; 68 char phys[32];
70 69
@@ -75,10 +74,6 @@ struct em28xx_IR {
75 unsigned int last_readcount; 74 unsigned int last_readcount;
76 75
77 int (*get_key)(struct em28xx_IR *, struct em28xx_ir_poll_result *); 76 int (*get_key)(struct em28xx_IR *, struct em28xx_ir_poll_result *);
78
79 /* IR device properties */
80
81 struct ir_dev_props props;
82}; 77};
83 78
84/********************************************************** 79/**********************************************************
@@ -302,12 +297,12 @@ static void em28xx_ir_handle_key(struct em28xx_IR *ir)
302 poll_result.toggle_bit, poll_result.read_count, 297 poll_result.toggle_bit, poll_result.read_count,
303 poll_result.rc_address, poll_result.rc_data[0]); 298 poll_result.rc_address, poll_result.rc_data[0]);
304 if (ir->full_code) 299 if (ir->full_code)
305 ir_keydown(ir->input, 300 rc_keydown(ir->rc,
306 poll_result.rc_address << 8 | 301 poll_result.rc_address << 8 |
307 poll_result.rc_data[0], 302 poll_result.rc_data[0],
308 poll_result.toggle_bit); 303 poll_result.toggle_bit);
309 else 304 else
310 ir_keydown(ir->input, 305 rc_keydown(ir->rc,
311 poll_result.rc_data[0], 306 poll_result.rc_data[0],
312 poll_result.toggle_bit); 307 poll_result.toggle_bit);
313 308
@@ -331,9 +326,9 @@ static void em28xx_ir_work(struct work_struct *work)
331 schedule_delayed_work(&ir->work, msecs_to_jiffies(ir->polling)); 326 schedule_delayed_work(&ir->work, msecs_to_jiffies(ir->polling));
332} 327}
333 328
334static int em28xx_ir_start(void *priv) 329static int em28xx_ir_start(struct rc_dev *rc)
335{ 330{
336 struct em28xx_IR *ir = priv; 331 struct em28xx_IR *ir = rc->priv;
337 332
338 INIT_DELAYED_WORK(&ir->work, em28xx_ir_work); 333 INIT_DELAYED_WORK(&ir->work, em28xx_ir_work);
339 schedule_delayed_work(&ir->work, 0); 334 schedule_delayed_work(&ir->work, 0);
@@ -341,30 +336,30 @@ static int em28xx_ir_start(void *priv)
341 return 0; 336 return 0;
342} 337}
343 338
344static void em28xx_ir_stop(void *priv) 339static void em28xx_ir_stop(struct rc_dev *rc)
345{ 340{
346 struct em28xx_IR *ir = priv; 341 struct em28xx_IR *ir = rc->priv;
347 342
348 cancel_delayed_work_sync(&ir->work); 343 cancel_delayed_work_sync(&ir->work);
349} 344}
350 345
351int em28xx_ir_change_protocol(void *priv, u64 ir_type) 346int em28xx_ir_change_protocol(struct rc_dev *rc_dev, u64 rc_type)
352{ 347{
353 int rc = 0; 348 int rc = 0;
354 struct em28xx_IR *ir = priv; 349 struct em28xx_IR *ir = rc_dev->priv;
355 struct em28xx *dev = ir->dev; 350 struct em28xx *dev = ir->dev;
356 u8 ir_config = EM2874_IR_RC5; 351 u8 ir_config = EM2874_IR_RC5;
357 352
358 /* Adjust xclk based o IR table for RC5/NEC tables */ 353 /* Adjust xclk based o IR table for RC5/NEC tables */
359 354
360 if (ir_type == IR_TYPE_RC5) { 355 if (rc_type == RC_TYPE_RC5) {
361 dev->board.xclk |= EM28XX_XCLK_IR_RC5_MODE; 356 dev->board.xclk |= EM28XX_XCLK_IR_RC5_MODE;
362 ir->full_code = 1; 357 ir->full_code = 1;
363 } else if (ir_type == IR_TYPE_NEC) { 358 } else if (rc_type == RC_TYPE_NEC) {
364 dev->board.xclk &= ~EM28XX_XCLK_IR_RC5_MODE; 359 dev->board.xclk &= ~EM28XX_XCLK_IR_RC5_MODE;
365 ir_config = EM2874_IR_NEC; 360 ir_config = EM2874_IR_NEC;
366 ir->full_code = 1; 361 ir->full_code = 1;
367 } else if (ir_type != IR_TYPE_UNKNOWN) 362 } else if (rc_type != RC_TYPE_UNKNOWN)
368 rc = -EINVAL; 363 rc = -EINVAL;
369 364
370 em28xx_write_reg_bits(dev, EM28XX_R0F_XCLK, dev->board.xclk, 365 em28xx_write_reg_bits(dev, EM28XX_R0F_XCLK, dev->board.xclk,
@@ -391,7 +386,7 @@ int em28xx_ir_change_protocol(void *priv, u64 ir_type)
391int em28xx_ir_init(struct em28xx *dev) 386int em28xx_ir_init(struct em28xx *dev)
392{ 387{
393 struct em28xx_IR *ir; 388 struct em28xx_IR *ir;
394 struct input_dev *input_dev; 389 struct rc_dev *rc;
395 int err = -ENOMEM; 390 int err = -ENOMEM;
396 391
397 if (dev->board.ir_codes == NULL) { 392 if (dev->board.ir_codes == NULL) {
@@ -400,28 +395,27 @@ int em28xx_ir_init(struct em28xx *dev)
400 } 395 }
401 396
402 ir = kzalloc(sizeof(*ir), GFP_KERNEL); 397 ir = kzalloc(sizeof(*ir), GFP_KERNEL);
403 input_dev = input_allocate_device(); 398 rc = rc_allocate_device();
404 if (!ir || !input_dev) 399 if (!ir || !rc)
405 goto err_out_free; 400 goto err_out_free;
406 401
407 /* record handles to ourself */ 402 /* record handles to ourself */
408 ir->dev = dev; 403 ir->dev = dev;
409 dev->ir = ir; 404 dev->ir = ir;
410 405 ir->rc = rc;
411 ir->input = input_dev;
412 406
413 /* 407 /*
414 * em2874 supports more protocols. For now, let's just announce 408 * em2874 supports more protocols. For now, let's just announce
415 * the two protocols that were already tested 409 * the two protocols that were already tested
416 */ 410 */
417 ir->props.allowed_protos = IR_TYPE_RC5 | IR_TYPE_NEC; 411 rc->allowed_protos = RC_TYPE_RC5 | RC_TYPE_NEC;
418 ir->props.priv = ir; 412 rc->priv = ir;
419 ir->props.change_protocol = em28xx_ir_change_protocol; 413 rc->change_protocol = em28xx_ir_change_protocol;
420 ir->props.open = em28xx_ir_start; 414 rc->open = em28xx_ir_start;
421 ir->props.close = em28xx_ir_stop; 415 rc->close = em28xx_ir_stop;
422 416
423 /* By default, keep protocol field untouched */ 417 /* By default, keep protocol field untouched */
424 err = em28xx_ir_change_protocol(ir, IR_TYPE_UNKNOWN); 418 err = em28xx_ir_change_protocol(rc, RC_TYPE_UNKNOWN);
425 if (err) 419 if (err)
426 goto err_out_free; 420 goto err_out_free;
427 421
@@ -435,27 +429,27 @@ int em28xx_ir_init(struct em28xx *dev)
435 usb_make_path(dev->udev, ir->phys, sizeof(ir->phys)); 429 usb_make_path(dev->udev, ir->phys, sizeof(ir->phys));
436 strlcat(ir->phys, "/input0", sizeof(ir->phys)); 430 strlcat(ir->phys, "/input0", sizeof(ir->phys));
437 431
438 input_dev->name = ir->name; 432 rc->input_name = ir->name;
439 input_dev->phys = ir->phys; 433 rc->input_phys = ir->phys;
440 input_dev->id.bustype = BUS_USB; 434 rc->input_id.bustype = BUS_USB;
441 input_dev->id.version = 1; 435 rc->input_id.version = 1;
442 input_dev->id.vendor = le16_to_cpu(dev->udev->descriptor.idVendor); 436 rc->input_id.vendor = le16_to_cpu(dev->udev->descriptor.idVendor);
443 input_dev->id.product = le16_to_cpu(dev->udev->descriptor.idProduct); 437 rc->input_id.product = le16_to_cpu(dev->udev->descriptor.idProduct);
444 438 rc->dev.parent = &dev->udev->dev;
445 input_dev->dev.parent = &dev->udev->dev; 439 rc->map_name = dev->board.ir_codes;
446 440 rc->driver_name = MODULE_NAME;
447
448 441
449 /* all done */ 442 /* all done */
450 err = ir_input_register(ir->input, dev->board.ir_codes, 443 err = rc_register_device(rc);
451 &ir->props, MODULE_NAME);
452 if (err) 444 if (err)
453 goto err_out_stop; 445 goto err_out_stop;
454 446
455 return 0; 447 return 0;
448
456 err_out_stop: 449 err_out_stop:
457 dev->ir = NULL; 450 dev->ir = NULL;
458 err_out_free: 451 err_out_free:
452 rc_free_device(rc);
459 kfree(ir); 453 kfree(ir);
460 return err; 454 return err;
461} 455}
@@ -468,8 +462,8 @@ int em28xx_ir_fini(struct em28xx *dev)
468 if (!ir) 462 if (!ir)
469 return 0; 463 return 0;
470 464
471 em28xx_ir_stop(ir); 465 em28xx_ir_stop(ir->rc);
472 ir_input_unregister(ir->input); 466 rc_unregister_device(ir->rc);
473 kfree(ir); 467 kfree(ir);
474 468
475 /* done */ 469 /* done */
diff --git a/drivers/media/video/em28xx/em28xx-vbi.c b/drivers/media/video/em28xx/em28xx-vbi.c
index 7f1c4a2173b6..2b4c9cba2d67 100644
--- a/drivers/media/video/em28xx/em28xx-vbi.c
+++ b/drivers/media/video/em28xx/em28xx-vbi.c
@@ -23,6 +23,7 @@
23 23
24#include <linux/kernel.h> 24#include <linux/kernel.h>
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/hardirq.h>
26#include <linux/init.h> 27#include <linux/init.h>
27 28
28#include "em28xx.h" 29#include "em28xx.h"
diff --git a/drivers/media/video/em28xx/em28xx-video.c b/drivers/media/video/em28xx/em28xx-video.c
index 2c3007280032..f34d524ccb09 100644
--- a/drivers/media/video/em28xx/em28xx-video.c
+++ b/drivers/media/video/em28xx/em28xx-video.c
@@ -1434,7 +1434,7 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
1434 1434
1435 /* It isn't an AC97 control. Sends it to the v4l2 dev interface */ 1435 /* It isn't an AC97 control. Sends it to the v4l2 dev interface */
1436 if (rc == 1) { 1436 if (rc == 1) {
1437 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_ctrl, ctrl); 1437 rc = v4l2_device_call_until_err(&dev->v4l2_dev, 0, core, s_ctrl, ctrl);
1438 1438
1439 /* 1439 /*
1440 * In the case of non-AC97 volume controls, we still need 1440 * In the case of non-AC97 volume controls, we still need
@@ -1708,11 +1708,15 @@ static int vidioc_streamoff(struct file *file, void *priv,
1708 fh, type, fh->resources, dev->resources); 1708 fh, type, fh->resources, dev->resources);
1709 1709
1710 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { 1710 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1711 videobuf_streamoff(&fh->vb_vidq); 1711 if (res_check(fh, EM28XX_RESOURCE_VIDEO)) {
1712 res_free(fh, EM28XX_RESOURCE_VIDEO); 1712 videobuf_streamoff(&fh->vb_vidq);
1713 res_free(fh, EM28XX_RESOURCE_VIDEO);
1714 }
1713 } else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) { 1715 } else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
1714 videobuf_streamoff(&fh->vb_vbiq); 1716 if (res_check(fh, EM28XX_RESOURCE_VBI)) {
1715 res_free(fh, EM28XX_RESOURCE_VBI); 1717 videobuf_streamoff(&fh->vb_vbiq);
1718 res_free(fh, EM28XX_RESOURCE_VBI);
1719 }
1716 } 1720 }
1717 1721
1718 return 0; 1722 return 0;
@@ -1934,19 +1938,6 @@ static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b)
1934 O_NONBLOCK); 1938 O_NONBLOCK);
1935} 1939}
1936 1940
1937#ifdef CONFIG_VIDEO_V4L1_COMPAT
1938static int vidiocgmbuf(struct file *file, void *priv, struct video_mbuf *mbuf)
1939{
1940 struct em28xx_fh *fh = priv;
1941
1942 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1943 return videobuf_cgmbuf(&fh->vb_vidq, mbuf, 8);
1944 else
1945 return videobuf_cgmbuf(&fh->vb_vbiq, mbuf, 8);
1946}
1947#endif
1948
1949
1950/* ----------------------------------------------------------- */ 1941/* ----------------------------------------------------------- */
1951/* RADIO ESPECIFIC IOCTLS */ 1942/* RADIO ESPECIFIC IOCTLS */
1952/* ----------------------------------------------------------- */ 1943/* ----------------------------------------------------------- */
@@ -2359,9 +2350,6 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
2359 .vidioc_s_register = vidioc_s_register, 2350 .vidioc_s_register = vidioc_s_register,
2360 .vidioc_g_chip_ident = vidioc_g_chip_ident, 2351 .vidioc_g_chip_ident = vidioc_g_chip_ident,
2361#endif 2352#endif
2362#ifdef CONFIG_VIDEO_V4L1_COMPAT
2363 .vidiocgmbuf = vidiocgmbuf,
2364#endif
2365}; 2353};
2366 2354
2367static const struct video_device em28xx_video_template = { 2355static const struct video_device em28xx_video_template = {
diff --git a/drivers/media/video/em28xx/em28xx.h b/drivers/media/video/em28xx/em28xx.h
index 6a75e6a4fc21..6f2795a3d4b7 100644
--- a/drivers/media/video/em28xx/em28xx.h
+++ b/drivers/media/video/em28xx/em28xx.h
@@ -33,7 +33,7 @@
33#include <media/videobuf-vmalloc.h> 33#include <media/videobuf-vmalloc.h>
34#include <media/v4l2-device.h> 34#include <media/v4l2-device.h>
35#include <media/ir-kbd-i2c.h> 35#include <media/ir-kbd-i2c.h>
36#include <media/ir-core.h> 36#include <media/rc-core.h>
37#if defined(CONFIG_VIDEO_EM28XX_DVB) || defined(CONFIG_VIDEO_EM28XX_DVB_MODULE) 37#if defined(CONFIG_VIDEO_EM28XX_DVB) || defined(CONFIG_VIDEO_EM28XX_DVB_MODULE)
38#include <media/videobuf-dvb.h> 38#include <media/videobuf-dvb.h>
39#endif 39#endif
@@ -117,6 +117,8 @@
117#define EM2800_BOARD_VC211A 74 117#define EM2800_BOARD_VC211A 74
118#define EM2882_BOARD_DIKOM_DK300 75 118#define EM2882_BOARD_DIKOM_DK300 75
119#define EM2870_BOARD_KWORLD_A340 76 119#define EM2870_BOARD_KWORLD_A340 76
120#define EM2874_LEADERSHIP_ISDBT 77
121
120 122
121/* Limits minimum and default number of buffers */ 123/* Limits minimum and default number of buffers */
122#define EM28XX_MIN_BUF 4 124#define EM28XX_MIN_BUF 4
diff --git a/drivers/media/video/et61x251/et61x251_core.c b/drivers/media/video/et61x251/et61x251_core.c
index bb164099ea2c..a982750dcef1 100644
--- a/drivers/media/video/et61x251/et61x251_core.c
+++ b/drivers/media/video/et61x251/et61x251_core.c
@@ -1610,6 +1610,7 @@ et61x251_vidioc_enuminput(struct et61x251_device* cam, void __user * arg)
1610 memset(&i, 0, sizeof(i)); 1610 memset(&i, 0, sizeof(i));
1611 strcpy(i.name, "Camera"); 1611 strcpy(i.name, "Camera");
1612 i.type = V4L2_INPUT_TYPE_CAMERA; 1612 i.type = V4L2_INPUT_TYPE_CAMERA;
1613 i.capabilities = V4L2_IN_CAP_STD;
1613 1614
1614 if (copy_to_user(arg, &i, sizeof(i))) 1615 if (copy_to_user(arg, &i, sizeof(i)))
1615 return -EFAULT; 1616 return -EFAULT;
diff --git a/drivers/media/video/fsl-viu.c b/drivers/media/video/fsl-viu.c
index b8faff2dd711..e4bba88254c7 100644
--- a/drivers/media/video/fsl-viu.c
+++ b/drivers/media/video/fsl-viu.c
@@ -194,6 +194,8 @@ struct viu_dev {
194 194
195 /* decoder */ 195 /* decoder */
196 struct v4l2_subdev *decoder; 196 struct v4l2_subdev *decoder;
197
198 v4l2_std_id std;
197}; 199};
198 200
199struct viu_fh { 201struct viu_fh {
@@ -915,6 +917,8 @@ static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
915 if (fh->type != i) 917 if (fh->type != i)
916 return -EINVAL; 918 return -EINVAL;
917 919
920 viu_start_dma(fh->dev);
921
918 return videobuf_streamon(&fh->vb_vidq); 922 return videobuf_streamon(&fh->vb_vidq);
919} 923}
920 924
@@ -927,20 +931,39 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
927 if (fh->type != i) 931 if (fh->type != i)
928 return -EINVAL; 932 return -EINVAL;
929 933
934 viu_stop_dma(fh->dev);
935
930 return videobuf_streamoff(&fh->vb_vidq); 936 return videobuf_streamoff(&fh->vb_vidq);
931} 937}
932 938
933#define decoder_call(viu, o, f, args...) \ 939#define decoder_call(viu, o, f, args...) \
934 v4l2_subdev_call(viu->decoder, o, f, ##args) 940 v4l2_subdev_call(viu->decoder, o, f, ##args)
935 941
942static int vidioc_querystd(struct file *file, void *priv, v4l2_std_id *std_id)
943{
944 struct viu_fh *fh = priv;
945
946 decoder_call(fh->dev, video, querystd, std_id);
947 return 0;
948}
949
936static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *id) 950static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *id)
937{ 951{
938 struct viu_fh *fh = priv; 952 struct viu_fh *fh = priv;
939 953
954 fh->dev->std = *id;
940 decoder_call(fh->dev, core, s_std, *id); 955 decoder_call(fh->dev, core, s_std, *id);
941 return 0; 956 return 0;
942} 957}
943 958
959static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *std_id)
960{
961 struct viu_fh *fh = priv;
962
963 *std_id = fh->dev->std;
964 return 0;
965}
966
944/* only one input in this driver */ 967/* only one input in this driver */
945static int vidioc_enum_input(struct file *file, void *priv, 968static int vidioc_enum_input(struct file *file, void *priv,
946 struct v4l2_input *inp) 969 struct v4l2_input *inp)
@@ -1331,6 +1354,7 @@ static int viu_release(struct file *file)
1331 1354
1332 viu_stop_dma(dev); 1355 viu_stop_dma(dev);
1333 videobuf_stop(&fh->vb_vidq); 1356 videobuf_stop(&fh->vb_vidq);
1357 videobuf_mmap_free(&fh->vb_vidq);
1334 1358
1335 kfree(fh); 1359 kfree(fh);
1336 1360
@@ -1397,7 +1421,9 @@ static const struct v4l2_ioctl_ops viu_ioctl_ops = {
1397 .vidioc_querybuf = vidioc_querybuf, 1421 .vidioc_querybuf = vidioc_querybuf,
1398 .vidioc_qbuf = vidioc_qbuf, 1422 .vidioc_qbuf = vidioc_qbuf,
1399 .vidioc_dqbuf = vidioc_dqbuf, 1423 .vidioc_dqbuf = vidioc_dqbuf,
1424 .vidioc_g_std = vidioc_g_std,
1400 .vidioc_s_std = vidioc_s_std, 1425 .vidioc_s_std = vidioc_s_std,
1426 .vidioc_querystd = vidioc_querystd,
1401 .vidioc_enum_input = vidioc_enum_input, 1427 .vidioc_enum_input = vidioc_enum_input,
1402 .vidioc_g_input = vidioc_g_input, 1428 .vidioc_g_input = vidioc_g_input,
1403 .vidioc_s_input = vidioc_s_input, 1429 .vidioc_s_input = vidioc_s_input,
diff --git a/drivers/media/video/gspca/cpia1.c b/drivers/media/video/gspca/cpia1.c
index 9b121681d135..c1ae05f4661f 100644
--- a/drivers/media/video/gspca/cpia1.c
+++ b/drivers/media/video/gspca/cpia1.c
@@ -37,7 +37,7 @@ MODULE_LICENSE("GPL");
37/* constant value's */ 37/* constant value's */
38#define MAGIC_0 0x19 38#define MAGIC_0 0x19
39#define MAGIC_1 0x68 39#define MAGIC_1 0x68
40#define DATA_IN 0xC0 40#define DATA_IN 0xc0
41#define DATA_OUT 0x40 41#define DATA_OUT 0x40
42#define VIDEOSIZE_QCIF 0 /* 176x144 */ 42#define VIDEOSIZE_QCIF 0 /* 176x144 */
43#define VIDEOSIZE_CIF 1 /* 352x288 */ 43#define VIDEOSIZE_CIF 1 /* 352x288 */
@@ -660,9 +660,9 @@ static int do_command(struct gspca_dev *gspca_dev, u16 command,
660 if (sd->params.qx3.button) { 660 if (sd->params.qx3.button) {
661 /* button pressed - unlock the latch */ 661 /* button pressed - unlock the latch */
662 do_command(gspca_dev, CPIA_COMMAND_WriteMCPort, 662 do_command(gspca_dev, CPIA_COMMAND_WriteMCPort,
663 3, 0xDF, 0xDF, 0); 663 3, 0xdf, 0xdf, 0);
664 do_command(gspca_dev, CPIA_COMMAND_WriteMCPort, 664 do_command(gspca_dev, CPIA_COMMAND_WriteMCPort,
665 3, 0xFF, 0xFF, 0); 665 3, 0xff, 0xff, 0);
666 } 666 }
667 667
668 /* test whether microscope is cradled */ 668 /* test whether microscope is cradled */
@@ -829,7 +829,7 @@ static int goto_low_power(struct gspca_dev *gspca_dev)
829 if (ret) 829 if (ret)
830 return ret; 830 return ret;
831 831
832 do_command(gspca_dev, CPIA_COMMAND_GetCameraStatus, 0, 0, 0, 0); 832 ret = do_command(gspca_dev, CPIA_COMMAND_GetCameraStatus, 0, 0, 0, 0);
833 if (ret) 833 if (ret)
834 return ret; 834 return ret;
835 835
@@ -1110,12 +1110,12 @@ static int command_setlights(struct gspca_dev *gspca_dev)
1110 p2 = (sd->params.qx3.toplight == 0) << 3; 1110 p2 = (sd->params.qx3.toplight == 0) << 3;
1111 1111
1112 ret = do_command(gspca_dev, CPIA_COMMAND_WriteVCReg, 1112 ret = do_command(gspca_dev, CPIA_COMMAND_WriteVCReg,
1113 0x90, 0x8F, 0x50, 0); 1113 0x90, 0x8f, 0x50, 0);
1114 if (ret) 1114 if (ret)
1115 return ret; 1115 return ret;
1116 1116
1117 return do_command(gspca_dev, CPIA_COMMAND_WriteMCPort, 2, 0, 1117 return do_command(gspca_dev, CPIA_COMMAND_WriteMCPort, 2, 0,
1118 p1 | p2 | 0xE0, 0); 1118 p1 | p2 | 0xe0, 0);
1119} 1119}
1120 1120
1121static int set_flicker(struct gspca_dev *gspca_dev, int on, int apply) 1121static int set_flicker(struct gspca_dev *gspca_dev, int on, int apply)
diff --git a/drivers/media/video/gspca/gspca.c b/drivers/media/video/gspca/gspca.c
index 8fe8fb486d62..442970073e8a 100644
--- a/drivers/media/video/gspca/gspca.c
+++ b/drivers/media/video/gspca/gspca.c
@@ -55,7 +55,7 @@ MODULE_AUTHOR("Jean-François Moine <http://moinejf.free.fr>");
55MODULE_DESCRIPTION("GSPCA USB Camera Driver"); 55MODULE_DESCRIPTION("GSPCA USB Camera Driver");
56MODULE_LICENSE("GPL"); 56MODULE_LICENSE("GPL");
57 57
58#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 10, 0) 58#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 11, 0)
59 59
60#ifdef GSPCA_DEBUG 60#ifdef GSPCA_DEBUG
61int gspca_debug = D_ERR | D_PROBE; 61int gspca_debug = D_ERR | D_PROBE;
@@ -224,12 +224,12 @@ static int alloc_and_submit_int_urb(struct gspca_dev *gspca_dev,
224 buffer, buffer_len, 224 buffer, buffer_len,
225 int_irq, (void *)gspca_dev, interval); 225 int_irq, (void *)gspca_dev, interval);
226 urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 226 urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
227 gspca_dev->int_urb = urb;
228 ret = usb_submit_urb(urb, GFP_KERNEL); 227 ret = usb_submit_urb(urb, GFP_KERNEL);
229 if (ret < 0) { 228 if (ret < 0) {
230 PDEBUG(D_ERR, "submit int URB failed with error %i", ret); 229 PDEBUG(D_ERR, "submit int URB failed with error %i", ret);
231 goto error_submit; 230 goto error_submit;
232 } 231 }
232 gspca_dev->int_urb = urb;
233 return ret; 233 return ret;
234 234
235error_submit: 235error_submit:
@@ -318,14 +318,9 @@ static void fill_frame(struct gspca_dev *gspca_dev,
318 } 318 }
319 pkt_scan = gspca_dev->sd_desc->pkt_scan; 319 pkt_scan = gspca_dev->sd_desc->pkt_scan;
320 for (i = 0; i < urb->number_of_packets; i++) { 320 for (i = 0; i < urb->number_of_packets; i++) {
321 len = urb->iso_frame_desc[i].actual_length;
321 322
322 /* check the packet status and length */ 323 /* check the packet status and length */
323 len = urb->iso_frame_desc[i].actual_length;
324 if (len == 0) {
325 if (gspca_dev->empty_packet == 0)
326 gspca_dev->empty_packet = 1;
327 continue;
328 }
329 st = urb->iso_frame_desc[i].status; 324 st = urb->iso_frame_desc[i].status;
330 if (st) { 325 if (st) {
331 err("ISOC data error: [%d] len=%d, status=%d", 326 err("ISOC data error: [%d] len=%d, status=%d",
@@ -333,6 +328,11 @@ static void fill_frame(struct gspca_dev *gspca_dev,
333 gspca_dev->last_packet_type = DISCARD_PACKET; 328 gspca_dev->last_packet_type = DISCARD_PACKET;
334 continue; 329 continue;
335 } 330 }
331 if (len == 0) {
332 if (gspca_dev->empty_packet == 0)
333 gspca_dev->empty_packet = 1;
334 continue;
335 }
336 336
337 /* let the packet be analyzed by the subdriver */ 337 /* let the packet be analyzed by the subdriver */
338 PDEBUG(D_PACK, "packet [%d] o:%d l:%d", 338 PDEBUG(D_PACK, "packet [%d] o:%d l:%d",
@@ -652,16 +652,12 @@ static struct usb_host_endpoint *get_ep(struct gspca_dev *gspca_dev)
652 : USB_ENDPOINT_XFER_ISOC; 652 : USB_ENDPOINT_XFER_ISOC;
653 i = gspca_dev->alt; /* previous alt setting */ 653 i = gspca_dev->alt; /* previous alt setting */
654 if (gspca_dev->cam.reverse_alts) { 654 if (gspca_dev->cam.reverse_alts) {
655 if (gspca_dev->audio && i < gspca_dev->nbalt - 2)
656 i++;
657 while (++i < gspca_dev->nbalt) { 655 while (++i < gspca_dev->nbalt) {
658 ep = alt_xfer(&intf->altsetting[i], xfer); 656 ep = alt_xfer(&intf->altsetting[i], xfer);
659 if (ep) 657 if (ep)
660 break; 658 break;
661 } 659 }
662 } else { 660 } else {
663 if (gspca_dev->audio && i > 1)
664 i--;
665 while (--i >= 0) { 661 while (--i >= 0) {
666 ep = alt_xfer(&intf->altsetting[i], xfer); 662 ep = alt_xfer(&intf->altsetting[i], xfer);
667 if (ep) 663 if (ep)
@@ -676,13 +672,11 @@ static struct usb_host_endpoint *get_ep(struct gspca_dev *gspca_dev)
676 i, ep->desc.bEndpointAddress); 672 i, ep->desc.bEndpointAddress);
677 gspca_dev->alt = i; /* memorize the current alt setting */ 673 gspca_dev->alt = i; /* memorize the current alt setting */
678 if (gspca_dev->nbalt > 1) { 674 if (gspca_dev->nbalt > 1) {
679 gspca_input_destroy_urb(gspca_dev);
680 ret = usb_set_interface(gspca_dev->dev, gspca_dev->iface, i); 675 ret = usb_set_interface(gspca_dev->dev, gspca_dev->iface, i);
681 if (ret < 0) { 676 if (ret < 0) {
682 err("set alt %d err %d", i, ret); 677 err("set alt %d err %d", i, ret);
683 ep = NULL; 678 ep = NULL;
684 } 679 }
685 gspca_input_create_urb(gspca_dev);
686 } 680 }
687 return ep; 681 return ep;
688} 682}
@@ -759,7 +753,7 @@ static int create_urbs(struct gspca_dev *gspca_dev,
759 } 753 }
760 } else { /* bulk */ 754 } else { /* bulk */
761 urb->pipe = usb_rcvbulkpipe(gspca_dev->dev, 755 urb->pipe = usb_rcvbulkpipe(gspca_dev->dev,
762 ep->desc.bEndpointAddress), 756 ep->desc.bEndpointAddress);
763 urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP; 757 urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
764 urb->complete = bulk_irq; 758 urb->complete = bulk_irq;
765 } 759 }
@@ -781,7 +775,7 @@ static int gspca_init_transfer(struct gspca_dev *gspca_dev)
781 775
782 if (!gspca_dev->present) { 776 if (!gspca_dev->present) {
783 ret = -ENODEV; 777 ret = -ENODEV;
784 goto out; 778 goto unlock;
785 } 779 }
786 780
787 /* reset the streaming variables */ 781 /* reset the streaming variables */
@@ -802,8 +796,10 @@ static int gspca_init_transfer(struct gspca_dev *gspca_dev)
802 if (gspca_dev->sd_desc->isoc_init) { 796 if (gspca_dev->sd_desc->isoc_init) {
803 ret = gspca_dev->sd_desc->isoc_init(gspca_dev); 797 ret = gspca_dev->sd_desc->isoc_init(gspca_dev);
804 if (ret < 0) 798 if (ret < 0)
805 goto out; 799 goto unlock;
806 } 800 }
801
802 gspca_input_destroy_urb(gspca_dev);
807 ep = get_ep(gspca_dev); 803 ep = get_ep(gspca_dev);
808 if (ep == NULL) { 804 if (ep == NULL) {
809 ret = -EIO; 805 ret = -EIO;
@@ -873,6 +869,8 @@ static int gspca_init_transfer(struct gspca_dev *gspca_dev)
873 } 869 }
874 } 870 }
875out: 871out:
872 gspca_input_create_urb(gspca_dev);
873unlock:
876 mutex_unlock(&gspca_dev->usb_lock); 874 mutex_unlock(&gspca_dev->usb_lock);
877 return ret; 875 return ret;
878} 876}
@@ -1299,17 +1297,19 @@ static int vidioc_querycap(struct file *file, void *priv,
1299 ret = -ENODEV; 1297 ret = -ENODEV;
1300 goto out; 1298 goto out;
1301 } 1299 }
1302 strncpy(cap->driver, gspca_dev->sd_desc->name, sizeof cap->driver); 1300 strncpy((char *) cap->driver, gspca_dev->sd_desc->name,
1301 sizeof cap->driver);
1303 if (gspca_dev->dev->product != NULL) { 1302 if (gspca_dev->dev->product != NULL) {
1304 strncpy(cap->card, gspca_dev->dev->product, 1303 strncpy((char *) cap->card, gspca_dev->dev->product,
1305 sizeof cap->card); 1304 sizeof cap->card);
1306 } else { 1305 } else {
1307 snprintf(cap->card, sizeof cap->card, 1306 snprintf((char *) cap->card, sizeof cap->card,
1308 "USB Camera (%04x:%04x)", 1307 "USB Camera (%04x:%04x)",
1309 le16_to_cpu(gspca_dev->dev->descriptor.idVendor), 1308 le16_to_cpu(gspca_dev->dev->descriptor.idVendor),
1310 le16_to_cpu(gspca_dev->dev->descriptor.idProduct)); 1309 le16_to_cpu(gspca_dev->dev->descriptor.idProduct));
1311 } 1310 }
1312 usb_make_path(gspca_dev->dev, cap->bus_info, sizeof(cap->bus_info)); 1311 usb_make_path(gspca_dev->dev, (char *) cap->bus_info,
1312 sizeof(cap->bus_info));
1313 cap->version = DRIVER_VERSION_NUMBER; 1313 cap->version = DRIVER_VERSION_NUMBER;
1314 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE 1314 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE
1315 | V4L2_CAP_STREAMING 1315 | V4L2_CAP_STREAMING
@@ -1710,12 +1710,13 @@ static int vidioc_g_parm(struct file *filp, void *priv,
1710 1710
1711 if (mutex_lock_interruptible(&gspca_dev->usb_lock)) 1711 if (mutex_lock_interruptible(&gspca_dev->usb_lock))
1712 return -ERESTARTSYS; 1712 return -ERESTARTSYS;
1713 gspca_dev->usb_err = 0; 1713 if (gspca_dev->present) {
1714 if (gspca_dev->present) 1714 gspca_dev->usb_err = 0;
1715 ret = gspca_dev->sd_desc->get_streamparm(gspca_dev, 1715 gspca_dev->sd_desc->get_streamparm(gspca_dev, parm);
1716 parm); 1716 ret = gspca_dev->usb_err;
1717 else 1717 } else {
1718 ret = -ENODEV; 1718 ret = -ENODEV;
1719 }
1719 mutex_unlock(&gspca_dev->usb_lock); 1720 mutex_unlock(&gspca_dev->usb_lock);
1720 return ret; 1721 return ret;
1721 } 1722 }
@@ -1740,12 +1741,13 @@ static int vidioc_s_parm(struct file *filp, void *priv,
1740 1741
1741 if (mutex_lock_interruptible(&gspca_dev->usb_lock)) 1742 if (mutex_lock_interruptible(&gspca_dev->usb_lock))
1742 return -ERESTARTSYS; 1743 return -ERESTARTSYS;
1743 gspca_dev->usb_err = 0; 1744 if (gspca_dev->present) {
1744 if (gspca_dev->present) 1745 gspca_dev->usb_err = 0;
1745 ret = gspca_dev->sd_desc->set_streamparm(gspca_dev, 1746 gspca_dev->sd_desc->set_streamparm(gspca_dev, parm);
1746 parm); 1747 ret = gspca_dev->usb_err;
1747 else 1748 } else {
1748 ret = -ENODEV; 1749 ret = -ENODEV;
1750 }
1749 mutex_unlock(&gspca_dev->usb_lock); 1751 mutex_unlock(&gspca_dev->usb_lock);
1750 return ret; 1752 return ret;
1751 } 1753 }
diff --git a/drivers/media/video/gspca/gspca.h b/drivers/media/video/gspca/gspca.h
index d4d210b56b49..97b77a26a2eb 100644
--- a/drivers/media/video/gspca/gspca.h
+++ b/drivers/media/video/gspca/gspca.h
@@ -62,7 +62,7 @@ struct gspca_ctrl {
62/* device information - set at probe time */ 62/* device information - set at probe time */
63struct cam { 63struct cam {
64 const struct v4l2_pix_format *cam_mode; /* size nmodes */ 64 const struct v4l2_pix_format *cam_mode; /* size nmodes */
65 const struct framerates *mode_framerates; /* must have size nmode, 65 const struct framerates *mode_framerates; /* must have size nmodes,
66 * just like cam_mode */ 66 * just like cam_mode */
67 struct gspca_ctrl *ctrls; /* control table - size nctrls */ 67 struct gspca_ctrl *ctrls; /* control table - size nctrls */
68 /* may be NULL */ 68 /* may be NULL */
@@ -93,7 +93,7 @@ typedef int (*cam_reg_op) (struct gspca_dev *,
93 struct v4l2_dbg_register *); 93 struct v4l2_dbg_register *);
94typedef int (*cam_ident_op) (struct gspca_dev *, 94typedef int (*cam_ident_op) (struct gspca_dev *,
95 struct v4l2_dbg_chip_ident *); 95 struct v4l2_dbg_chip_ident *);
96typedef int (*cam_streamparm_op) (struct gspca_dev *, 96typedef void (*cam_streamparm_op) (struct gspca_dev *,
97 struct v4l2_streamparm *); 97 struct v4l2_streamparm *);
98typedef int (*cam_qmnu_op) (struct gspca_dev *, 98typedef int (*cam_qmnu_op) (struct gspca_dev *,
99 struct v4l2_querymenu *); 99 struct v4l2_querymenu *);
diff --git a/drivers/media/video/gspca/m5602/m5602_ov9650.c b/drivers/media/video/gspca/m5602/m5602_ov9650.c
index 8ded8b100576..703d48670a24 100644
--- a/drivers/media/video/gspca/m5602/m5602_ov9650.c
+++ b/drivers/media/video/gspca/m5602/m5602_ov9650.c
@@ -624,7 +624,7 @@ static int ov9650_set_gain(struct gspca_dev *gspca_dev, __s32 val)
624 624
625 /* Mask away all uninteresting bits */ 625 /* Mask away all uninteresting bits */
626 i2c_data = ((val & 0x0300) >> 2) | 626 i2c_data = ((val & 0x0300) >> 2) |
627 (i2c_data & 0x3F); 627 (i2c_data & 0x3f);
628 err = m5602_write_sensor(sd, OV9650_VREF, &i2c_data, 1); 628 err = m5602_write_sensor(sd, OV9650_VREF, &i2c_data, 1);
629 if (err < 0) 629 if (err < 0)
630 return err; 630 return err;
diff --git a/drivers/media/video/gspca/ov519.c b/drivers/media/video/gspca/ov519.c
index 6cf6855aa506..e1c3b9328ace 100644
--- a/drivers/media/video/gspca/ov519.c
+++ b/drivers/media/video/gspca/ov519.c
@@ -75,14 +75,14 @@ struct sd {
75 75
76 struct gspca_ctrl ctrls[NCTRL]; 76 struct gspca_ctrl ctrls[NCTRL];
77 77
78 __u8 packet_nr; 78 u8 packet_nr;
79 79
80 char bridge; 80 char bridge;
81#define BRIDGE_OV511 0 81#define BRIDGE_OV511 0
82#define BRIDGE_OV511PLUS 1 82#define BRIDGE_OV511PLUS 1
83#define BRIDGE_OV518 2 83#define BRIDGE_OV518 2
84#define BRIDGE_OV518PLUS 3 84#define BRIDGE_OV518PLUS 3
85#define BRIDGE_OV519 4 85#define BRIDGE_OV519 4 /* = ov530 */
86#define BRIDGE_OVFX2 5 86#define BRIDGE_OVFX2 5
87#define BRIDGE_W9968CF 6 87#define BRIDGE_W9968CF 6
88#define BRIDGE_MASK 7 88#define BRIDGE_MASK 7
@@ -94,42 +94,44 @@ struct sd {
94 char snapshot_needs_reset; 94 char snapshot_needs_reset;
95 95
96 /* Determined by sensor type */ 96 /* Determined by sensor type */
97 __u8 sif; 97 u8 sif;
98 98
99 __u8 quality; 99 u8 quality;
100#define QUALITY_MIN 50 100#define QUALITY_MIN 50
101#define QUALITY_MAX 70 101#define QUALITY_MAX 70
102#define QUALITY_DEF 50 102#define QUALITY_DEF 50
103 103
104 __u8 stopped; /* Streaming is temporarily paused */ 104 u8 stopped; /* Streaming is temporarily paused */
105 __u8 first_frame; 105 u8 first_frame;
106 106
107 __u8 frame_rate; /* current Framerate */ 107 u8 frame_rate; /* current Framerate */
108 __u8 clockdiv; /* clockdiv override */ 108 u8 clockdiv; /* clockdiv override */
109 109
110 char sensor; /* Type of image sensor chip (SEN_*) */ 110 s8 sensor; /* Type of image sensor chip (SEN_*) */
111#define SEN_UNKNOWN 0
112#define SEN_OV2610 1
113#define SEN_OV3610 2
114#define SEN_OV6620 3
115#define SEN_OV6630 4
116#define SEN_OV66308AF 5
117#define SEN_OV7610 6
118#define SEN_OV7620 7
119#define SEN_OV7620AE 8
120#define SEN_OV7640 9
121#define SEN_OV7648 10
122#define SEN_OV7670 11
123#define SEN_OV76BE 12
124#define SEN_OV8610 13
125 111
126 u8 sensor_addr; 112 u8 sensor_addr;
127 int sensor_width; 113 u16 sensor_width;
128 int sensor_height; 114 u16 sensor_height;
129 int sensor_reg_cache[256]; 115 s16 sensor_reg_cache[256];
130 116
131 u8 jpeg_hdr[JPEG_HDR_SZ]; 117 u8 jpeg_hdr[JPEG_HDR_SZ];
132}; 118};
119enum sensors {
120 SEN_OV2610,
121 SEN_OV3610,
122 SEN_OV6620,
123 SEN_OV6630,
124 SEN_OV66308AF,
125 SEN_OV7610,
126 SEN_OV7620,
127 SEN_OV7620AE,
128 SEN_OV7640,
129 SEN_OV7648,
130 SEN_OV7660,
131 SEN_OV7670,
132 SEN_OV76BE,
133 SEN_OV8610,
134};
133 135
134/* Note this is a bit of a hack, but the w9968cf driver needs the code for all 136/* Note this is a bit of a hack, but the w9968cf driver needs the code for all
135 the ov sensors which is already present here. When we have the time we 137 the ov sensors which is already present here. When we have the time we
@@ -182,7 +184,7 @@ static const struct ctrl sd_ctrls[] = {
182 }, 184 },
183 .set_control = setcolors, 185 .set_control = setcolors,
184 }, 186 },
185/* The flip controls work with ov7670 only */ 187/* The flip controls work for sensors ov7660 and ov7670 only */
186[HFLIP] = { 188[HFLIP] = {
187 { 189 {
188 .id = V4L2_CID_HFLIP, 190 .id = V4L2_CID_HFLIP,
@@ -225,7 +227,7 @@ static const struct ctrl sd_ctrls[] = {
225 .type = V4L2_CTRL_TYPE_MENU, 227 .type = V4L2_CTRL_TYPE_MENU,
226 .name = "Light frequency filter", 228 .name = "Light frequency filter",
227 .minimum = 0, 229 .minimum = 0,
228 .maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */ 230 .maximum = 2, /* 0: no flicker, 1: 50Hz, 2:60Hz, 3: auto */
229 .step = 1, 231 .step = 1,
230 .default_value = 0, 232 .default_value = 0,
231 }, 233 },
@@ -233,6 +235,53 @@ static const struct ctrl sd_ctrls[] = {
233 }, 235 },
234}; 236};
235 237
238/* table of the disabled controls */
239static const unsigned ctrl_dis[] = {
240[SEN_OV2610] = (1 << NCTRL) - 1, /* no control */
241
242[SEN_OV3610] = (1 << NCTRL) - 1, /* no control */
243
244[SEN_OV6620] = (1 << HFLIP) |
245 (1 << VFLIP),
246
247[SEN_OV6630] = (1 << HFLIP) |
248 (1 << VFLIP),
249
250[SEN_OV66308AF] = (1 << HFLIP) |
251 (1 << VFLIP),
252
253[SEN_OV7610] = (1 << HFLIP) |
254 (1 << VFLIP),
255
256[SEN_OV7620] = (1 << HFLIP) |
257 (1 << VFLIP),
258
259[SEN_OV7620AE] = (1 << HFLIP) |
260 (1 << VFLIP),
261
262[SEN_OV7640] = (1 << HFLIP) |
263 (1 << VFLIP) |
264 (1 << AUTOBRIGHT) |
265 (1 << CONTRAST),
266
267[SEN_OV7648] = (1 << HFLIP) |
268 (1 << VFLIP) |
269 (1 << AUTOBRIGHT) |
270 (1 << CONTRAST),
271
272[SEN_OV7660] = (1 << AUTOBRIGHT),
273
274[SEN_OV7670] = (1 << COLORS) |
275 (1 << AUTOBRIGHT),
276
277[SEN_OV76BE] = (1 << HFLIP) |
278 (1 << VFLIP),
279
280[SEN_OV8610] = (1 << HFLIP) |
281 (1 << VFLIP) |
282 (1 << FREQ),
283};
284
236static const struct v4l2_pix_format ov519_vga_mode[] = { 285static const struct v4l2_pix_format ov519_vga_mode[] = {
237 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, 286 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
238 .bytesperline = 320, 287 .bytesperline = 320,
@@ -412,7 +461,6 @@ static const struct v4l2_pix_format ovfx2_ov3610_mode[] = {
412 .priv = 0}, 461 .priv = 0},
413}; 462};
414 463
415
416/* Registers common to OV511 / OV518 */ 464/* Registers common to OV511 / OV518 */
417#define R51x_FIFO_PSIZE 0x30 /* 2 bytes wide w/ OV518(+) */ 465#define R51x_FIFO_PSIZE 0x30 /* 2 bytes wide w/ OV518(+) */
418#define R51x_SYS_RESET 0x50 466#define R51x_SYS_RESET 0x50
@@ -420,7 +468,7 @@ static const struct v4l2_pix_format ovfx2_ov3610_mode[] = {
420 #define OV511_RESET_OMNICE 0x08 468 #define OV511_RESET_OMNICE 0x08
421#define R51x_SYS_INIT 0x53 469#define R51x_SYS_INIT 0x53
422#define R51x_SYS_SNAP 0x52 470#define R51x_SYS_SNAP 0x52
423#define R51x_SYS_CUST_ID 0x5F 471#define R51x_SYS_CUST_ID 0x5f
424#define R51x_COMP_LUT_BEGIN 0x80 472#define R51x_COMP_LUT_BEGIN 0x80
425 473
426/* OV511 Camera interface register numbers */ 474/* OV511 Camera interface register numbers */
@@ -435,13 +483,13 @@ static const struct v4l2_pix_format ovfx2_ov3610_mode[] = {
435#define R511_CAM_OPTS 0x18 483#define R511_CAM_OPTS 0x18
436 484
437#define R511_SNAP_FRAME 0x19 485#define R511_SNAP_FRAME 0x19
438#define R511_SNAP_PXCNT 0x1A 486#define R511_SNAP_PXCNT 0x1a
439#define R511_SNAP_LNCNT 0x1B 487#define R511_SNAP_LNCNT 0x1b
440#define R511_SNAP_PXDIV 0x1C 488#define R511_SNAP_PXDIV 0x1c
441#define R511_SNAP_LNDIV 0x1D 489#define R511_SNAP_LNDIV 0x1d
442#define R511_SNAP_UV_EN 0x1E 490#define R511_SNAP_UV_EN 0x1e
443#define R511_SNAP_UV_EN 0x1E 491#define R511_SNAP_UV_EN 0x1e
444#define R511_SNAP_OPTS 0x1F 492#define R511_SNAP_OPTS 0x1f
445 493
446#define R511_DRAM_FLOW_CTL 0x20 494#define R511_DRAM_FLOW_CTL 0x20
447#define R511_FIFO_OPTS 0x31 495#define R511_FIFO_OPTS 0x31
@@ -466,13 +514,14 @@ static const struct v4l2_pix_format ovfx2_ov3610_mode[] = {
466#define OV519_R25_FORMAT 0x25 514#define OV519_R25_FORMAT 0x25
467 515
468/* OV519 System Controller register numbers */ 516/* OV519 System Controller register numbers */
469#define OV519_SYS_RESET1 0x51 517#define OV519_R51_RESET1 0x51
470#define OV519_SYS_EN_CLK1 0x54 518#define OV519_R54_EN_CLK1 0x54
519#define OV519_R57_SNAPSHOT 0x57
471 520
472#define OV519_GPIO_DATA_OUT0 0x71 521#define OV519_GPIO_DATA_OUT0 0x71
473#define OV519_GPIO_IO_CTRL0 0x72 522#define OV519_GPIO_IO_CTRL0 0x72
474 523
475#define OV511_ENDPOINT_ADDRESS 1 /* Isoc endpoint number */ 524/*#define OV511_ENDPOINT_ADDRESS 1 * Isoc endpoint number */
476 525
477/* 526/*
478 * The FX2 chip does not give us a zero length read at end of frame. 527 * The FX2 chip does not give us a zero length read at end of frame.
@@ -526,80 +575,81 @@ static const struct v4l2_pix_format ovfx2_ov3610_mode[] = {
526#define OV7610_REG_ID_LOW 0x1d /* manufacturer ID LSB */ 575#define OV7610_REG_ID_LOW 0x1d /* manufacturer ID LSB */
527#define OV7610_REG_COM_I 0x29 /* misc settings */ 576#define OV7610_REG_COM_I 0x29 /* misc settings */
528 577
529/* OV7670 registers */ 578/* OV7660 and OV7670 registers */
530#define OV7670_REG_GAIN 0x00 /* Gain lower 8 bits (rest in vref) */ 579#define OV7670_R00_GAIN 0x00 /* Gain lower 8 bits (rest in vref) */
531#define OV7670_REG_BLUE 0x01 /* blue gain */ 580#define OV7670_R01_BLUE 0x01 /* blue gain */
532#define OV7670_REG_RED 0x02 /* red gain */ 581#define OV7670_R02_RED 0x02 /* red gain */
533#define OV7670_REG_VREF 0x03 /* Pieces of GAIN, VSTART, VSTOP */ 582#define OV7670_R03_VREF 0x03 /* Pieces of GAIN, VSTART, VSTOP */
534#define OV7670_REG_COM1 0x04 /* Control 1 */ 583#define OV7670_R04_COM1 0x04 /* Control 1 */
535#define OV7670_REG_AECHH 0x07 /* AEC MS 5 bits */ 584/*#define OV7670_R07_AECHH 0x07 * AEC MS 5 bits */
536#define OV7670_REG_COM3 0x0c /* Control 3 */ 585#define OV7670_R0C_COM3 0x0c /* Control 3 */
537#define OV7670_REG_COM4 0x0d /* Control 4 */ 586#define OV7670_R0D_COM4 0x0d /* Control 4 */
538#define OV7670_REG_COM5 0x0e /* All "reserved" */ 587#define OV7670_R0E_COM5 0x0e /* All "reserved" */
539#define OV7670_REG_COM6 0x0f /* Control 6 */ 588#define OV7670_R0F_COM6 0x0f /* Control 6 */
540#define OV7670_REG_AECH 0x10 /* More bits of AEC value */ 589#define OV7670_R10_AECH 0x10 /* More bits of AEC value */
541#define OV7670_REG_CLKRC 0x11 /* Clock control */ 590#define OV7670_R11_CLKRC 0x11 /* Clock control */
542#define OV7670_REG_COM7 0x12 /* Control 7 */ 591#define OV7670_R12_COM7 0x12 /* Control 7 */
543#define OV7670_COM7_FMT_VGA 0x00 592#define OV7670_COM7_FMT_VGA 0x00
544#define OV7670_COM7_YUV 0x00 /* YUV */ 593/*#define OV7670_COM7_YUV 0x00 * YUV */
545#define OV7670_COM7_FMT_QVGA 0x10 /* QVGA format */ 594#define OV7670_COM7_FMT_QVGA 0x10 /* QVGA format */
546#define OV7670_COM7_FMT_MASK 0x38 595#define OV7670_COM7_FMT_MASK 0x38
547#define OV7670_COM7_RESET 0x80 /* Register reset */ 596#define OV7670_COM7_RESET 0x80 /* Register reset */
548#define OV7670_REG_COM8 0x13 /* Control 8 */ 597#define OV7670_R13_COM8 0x13 /* Control 8 */
549#define OV7670_COM8_AEC 0x01 /* Auto exposure enable */ 598#define OV7670_COM8_AEC 0x01 /* Auto exposure enable */
550#define OV7670_COM8_AWB 0x02 /* White balance enable */ 599#define OV7670_COM8_AWB 0x02 /* White balance enable */
551#define OV7670_COM8_AGC 0x04 /* Auto gain enable */ 600#define OV7670_COM8_AGC 0x04 /* Auto gain enable */
552#define OV7670_COM8_BFILT 0x20 /* Band filter enable */ 601#define OV7670_COM8_BFILT 0x20 /* Band filter enable */
553#define OV7670_COM8_AECSTEP 0x40 /* Unlimited AEC step size */ 602#define OV7670_COM8_AECSTEP 0x40 /* Unlimited AEC step size */
554#define OV7670_COM8_FASTAEC 0x80 /* Enable fast AGC/AEC */ 603#define OV7670_COM8_FASTAEC 0x80 /* Enable fast AGC/AEC */
555#define OV7670_REG_COM9 0x14 /* Control 9 - gain ceiling */ 604#define OV7670_R14_COM9 0x14 /* Control 9 - gain ceiling */
556#define OV7670_REG_COM10 0x15 /* Control 10 */ 605#define OV7670_R15_COM10 0x15 /* Control 10 */
557#define OV7670_REG_HSTART 0x17 /* Horiz start high bits */ 606#define OV7670_R17_HSTART 0x17 /* Horiz start high bits */
558#define OV7670_REG_HSTOP 0x18 /* Horiz stop high bits */ 607#define OV7670_R18_HSTOP 0x18 /* Horiz stop high bits */
559#define OV7670_REG_VSTART 0x19 /* Vert start high bits */ 608#define OV7670_R19_VSTART 0x19 /* Vert start high bits */
560#define OV7670_REG_VSTOP 0x1a /* Vert stop high bits */ 609#define OV7670_R1A_VSTOP 0x1a /* Vert stop high bits */
561#define OV7670_REG_MVFP 0x1e /* Mirror / vflip */ 610#define OV7670_R1E_MVFP 0x1e /* Mirror / vflip */
562#define OV7670_MVFP_VFLIP 0x10 /* vertical flip */ 611#define OV7670_MVFP_VFLIP 0x10 /* vertical flip */
563#define OV7670_MVFP_MIRROR 0x20 /* Mirror image */ 612#define OV7670_MVFP_MIRROR 0x20 /* Mirror image */
564#define OV7670_REG_AEW 0x24 /* AGC upper limit */ 613#define OV7670_R24_AEW 0x24 /* AGC upper limit */
565#define OV7670_REG_AEB 0x25 /* AGC lower limit */ 614#define OV7670_R25_AEB 0x25 /* AGC lower limit */
566#define OV7670_REG_VPT 0x26 /* AGC/AEC fast mode op region */ 615#define OV7670_R26_VPT 0x26 /* AGC/AEC fast mode op region */
567#define OV7670_REG_HREF 0x32 /* HREF pieces */ 616#define OV7670_R32_HREF 0x32 /* HREF pieces */
568#define OV7670_REG_TSLB 0x3a /* lots of stuff */ 617#define OV7670_R3A_TSLB 0x3a /* lots of stuff */
569#define OV7670_REG_COM11 0x3b /* Control 11 */ 618#define OV7670_R3B_COM11 0x3b /* Control 11 */
570#define OV7670_COM11_EXP 0x02 619#define OV7670_COM11_EXP 0x02
571#define OV7670_COM11_HZAUTO 0x10 /* Auto detect 50/60 Hz */ 620#define OV7670_COM11_HZAUTO 0x10 /* Auto detect 50/60 Hz */
572#define OV7670_REG_COM12 0x3c /* Control 12 */ 621#define OV7670_R3C_COM12 0x3c /* Control 12 */
573#define OV7670_REG_COM13 0x3d /* Control 13 */ 622#define OV7670_R3D_COM13 0x3d /* Control 13 */
574#define OV7670_COM13_GAMMA 0x80 /* Gamma enable */ 623#define OV7670_COM13_GAMMA 0x80 /* Gamma enable */
575#define OV7670_COM13_UVSAT 0x40 /* UV saturation auto adjustment */ 624#define OV7670_COM13_UVSAT 0x40 /* UV saturation auto adjustment */
576#define OV7670_REG_COM14 0x3e /* Control 14 */ 625#define OV7670_R3E_COM14 0x3e /* Control 14 */
577#define OV7670_REG_EDGE 0x3f /* Edge enhancement factor */ 626#define OV7670_R3F_EDGE 0x3f /* Edge enhancement factor */
578#define OV7670_REG_COM15 0x40 /* Control 15 */ 627#define OV7670_R40_COM15 0x40 /* Control 15 */
579#define OV7670_COM15_R00FF 0xc0 /* 00 to FF */ 628/*#define OV7670_COM15_R00FF 0xc0 * 00 to FF */
580#define OV7670_REG_COM16 0x41 /* Control 16 */ 629#define OV7670_R41_COM16 0x41 /* Control 16 */
581#define OV7670_COM16_AWBGAIN 0x08 /* AWB gain enable */ 630#define OV7670_COM16_AWBGAIN 0x08 /* AWB gain enable */
582#define OV7670_REG_BRIGHT 0x55 /* Brightness */ 631/* end of ov7660 common registers */
583#define OV7670_REG_CONTRAS 0x56 /* Contrast control */ 632#define OV7670_R55_BRIGHT 0x55 /* Brightness */
584#define OV7670_REG_GFIX 0x69 /* Fix gain control */ 633#define OV7670_R56_CONTRAS 0x56 /* Contrast control */
585#define OV7670_REG_RGB444 0x8c /* RGB 444 control */ 634#define OV7670_R69_GFIX 0x69 /* Fix gain control */
586#define OV7670_REG_HAECC1 0x9f /* Hist AEC/AGC control 1 */ 635/*#define OV7670_R8C_RGB444 0x8c * RGB 444 control */
587#define OV7670_REG_HAECC2 0xa0 /* Hist AEC/AGC control 2 */ 636#define OV7670_R9F_HAECC1 0x9f /* Hist AEC/AGC control 1 */
588#define OV7670_REG_BD50MAX 0xa5 /* 50hz banding step limit */ 637#define OV7670_RA0_HAECC2 0xa0 /* Hist AEC/AGC control 2 */
589#define OV7670_REG_HAECC3 0xa6 /* Hist AEC/AGC control 3 */ 638#define OV7670_RA5_BD50MAX 0xa5 /* 50hz banding step limit */
590#define OV7670_REG_HAECC4 0xa7 /* Hist AEC/AGC control 4 */ 639#define OV7670_RA6_HAECC3 0xa6 /* Hist AEC/AGC control 3 */
591#define OV7670_REG_HAECC5 0xa8 /* Hist AEC/AGC control 5 */ 640#define OV7670_RA7_HAECC4 0xa7 /* Hist AEC/AGC control 4 */
592#define OV7670_REG_HAECC6 0xa9 /* Hist AEC/AGC control 6 */ 641#define OV7670_RA8_HAECC5 0xa8 /* Hist AEC/AGC control 5 */
593#define OV7670_REG_HAECC7 0xaa /* Hist AEC/AGC control 7 */ 642#define OV7670_RA9_HAECC6 0xa9 /* Hist AEC/AGC control 6 */
594#define OV7670_REG_BD60MAX 0xab /* 60hz banding step limit */ 643#define OV7670_RAA_HAECC7 0xaa /* Hist AEC/AGC control 7 */
644#define OV7670_RAB_BD60MAX 0xab /* 60hz banding step limit */
595 645
596struct ov_regvals { 646struct ov_regvals {
597 __u8 reg; 647 u8 reg;
598 __u8 val; 648 u8 val;
599}; 649};
600struct ov_i2c_regvals { 650struct ov_i2c_regvals {
601 __u8 reg; 651 u8 reg;
602 __u8 val; 652 u8 val;
603}; 653};
604 654
605/* Settings for OV2610 camera chip */ 655/* Settings for OV2610 camera chip */
@@ -617,7 +667,6 @@ static const struct ov_i2c_regvals norm_3620b[] = {
617 * "wait 4096 external clock ... to make sure the sensor is 667 * "wait 4096 external clock ... to make sure the sensor is
618 * stable and ready to access registers" i.e. 160us at 24MHz 668 * stable and ready to access registers" i.e. 160us at 24MHz
619 */ 669 */
620
621 { 0x12, 0x80 }, /* COMH reset */ 670 { 0x12, 0x80 }, /* COMH reset */
622 { 0x12, 0x00 }, /* QXGA, master */ 671 { 0x12, 0x00 }, /* QXGA, master */
623 672
@@ -650,7 +699,7 @@ static const struct ov_i2c_regvals norm_3620b[] = {
650 * COMI[0] "Exposure control" 699 * COMI[0] "Exposure control"
651 * = 0 (0x00) .......0 "Manual" 700 * = 0 (0x00) .......0 "Manual"
652 */ 701 */
653 { 0x13, 0xC0 }, 702 { 0x13, 0xc0 },
654 703
655 /* 704 /*
656 * 09 COMC "Common Control C" 705 * 09 COMC "Common Control C"
@@ -706,7 +755,7 @@ static const struct ov_i2c_regvals norm_3620b[] = {
706 * COME[0] "Auto zero circuit select" 755 * COME[0] "Auto zero circuit select"
707 * = 1 (0x01) .......1 "On" 756 * = 1 (0x01) .......1 "On"
708 */ 757 */
709 { 0x0d, 0xA1 }, 758 { 0x0d, 0xa1 },
710 759
711 /* 760 /*
712 * 0E COMF "Common Control F" 761 * 0E COMF "Common Control F"
@@ -770,7 +819,7 @@ static const struct ov_i2c_regvals norm_3620b[] = {
770 * COMJ[0] "Reserved" 819 * COMJ[0] "Reserved"
771 * = 0 (0x00) .......0 820 * = 0 (0x00) .......0
772 */ 821 */
773 { 0x14, 0xC6 }, 822 { 0x14, 0xc6 },
774 823
775 /* 824 /*
776 * 15 COMK "Common Control K" 825 * 15 COMK "Common Control K"
@@ -876,7 +925,7 @@ static const struct ov_i2c_regvals norm_3620b[] = {
876 * FVOPT[7:0] "Range" 925 * FVOPT[7:0] "Range"
877 * = 31 (0x1F) 00011111 926 * = 31 (0x1F) 00011111
878 */ 927 */
879 { 0x3c, 0x1F }, 928 { 0x3c, 0x1f },
880 929
881 /* 930 /*
882 * 44 Undocumented = 0 (0x00) 00000000 931 * 44 Undocumented = 0 (0x00) 00000000
@@ -925,7 +974,7 @@ static const struct ov_i2c_regvals norm_3620b[] = {
925 * 48[7:0] "It's a secret" 974 * 48[7:0] "It's a secret"
926 * = 192 (0xC0) 11000000 975 * = 192 (0xC0) 11000000
927 */ 976 */
928 { 0x48, 0xC0 }, 977 { 0x48, 0xc0 },
929 978
930 /* 979 /*
931 * 49 Undocumented = 25 (0x19) 00011001 980 * 49 Undocumented = 25 (0x19) 00011001
@@ -939,18 +988,18 @@ static const struct ov_i2c_regvals norm_3620b[] = {
939 * 4B[7:0] "It's a secret" 988 * 4B[7:0] "It's a secret"
940 * = 128 (0x80) 10000000 989 * = 128 (0x80) 10000000
941 */ 990 */
942 { 0x4B, 0x80 }, 991 { 0x4b, 0x80 },
943 992
944 /* 993 /*
945 * 4D Undocumented = 196 (0xC4) 11000100 994 * 4D Undocumented = 196 (0xC4) 11000100
946 * 4D[7:0] "It's a secret" 995 * 4D[7:0] "It's a secret"
947 * = 196 (0xC4) 11000100 996 * = 196 (0xC4) 11000100
948 */ 997 */
949 { 0x4D, 0xC4 }, 998 { 0x4d, 0xc4 },
950 999
951 /* 1000 /*
952 * 35 VREF "Reference Voltage Control" 1001 * 35 VREF "Reference Voltage Control"
953 * = 76 (0x4C) 01001100 1002 * = 76 (0x4c) 01001100
954 * VREF[7:5] "Column high reference control" 1003 * VREF[7:5] "Column high reference control"
955 * = 2 (0x02) 010..... "higher voltage" 1004 * = 2 (0x02) 010..... "higher voltage"
956 * VREF[4:2] "Column low reference control" 1005 * VREF[4:2] "Column low reference control"
@@ -958,21 +1007,21 @@ static const struct ov_i2c_regvals norm_3620b[] = {
958 * VREF[1:0] "Reserved" 1007 * VREF[1:0] "Reserved"
959 * = 0 (0x00) ......00 1008 * = 0 (0x00) ......00
960 */ 1009 */
961 { 0x35, 0x4C }, 1010 { 0x35, 0x4c },
962 1011
963 /* 1012 /*
964 * 3D Undocumented = 0 (0x00) 00000000 1013 * 3D Undocumented = 0 (0x00) 00000000
965 * 3D[7:0] "It's a secret" 1014 * 3D[7:0] "It's a secret"
966 * = 0 (0x00) 00000000 1015 * = 0 (0x00) 00000000
967 */ 1016 */
968 { 0x3D, 0x00 }, 1017 { 0x3d, 0x00 },
969 1018
970 /* 1019 /*
971 * 3E Undocumented = 0 (0x00) 00000000 1020 * 3E Undocumented = 0 (0x00) 00000000
972 * 3E[7:0] "It's a secret" 1021 * 3E[7:0] "It's a secret"
973 * = 0 (0x00) 00000000 1022 * = 0 (0x00) 00000000
974 */ 1023 */
975 { 0x3E, 0x00 }, 1024 { 0x3e, 0x00 },
976 1025
977 /* 1026 /*
978 * 3B FREFB "Internal Reference Adjustment" 1027 * 3B FREFB "Internal Reference Adjustment"
@@ -1012,7 +1061,7 @@ static const struct ov_i2c_regvals norm_3620b[] = {
1012 * VBLM[3:0] "Sensor current control" 1061 * VBLM[3:0] "Sensor current control"
1013 * = 10 (0x0A) ....1010 1062 * = 10 (0x0A) ....1010
1014 */ 1063 */
1015 { 0x34, 0x5A }, 1064 { 0x34, 0x5a },
1016 1065
1017 /* 1066 /*
1018 * 3B FREFB "Internal Reference Adjustment" 1067 * 3B FREFB "Internal Reference Adjustment"
@@ -1078,7 +1127,7 @@ static const struct ov_i2c_regvals norm_3620b[] = {
1078 * HREFST[7:0] "Horizontal window start, 8 MSBs" 1127 * HREFST[7:0] "Horizontal window start, 8 MSBs"
1079 * = 31 (0x1F) 00011111 1128 * = 31 (0x1F) 00011111
1080 */ 1129 */
1081 { 0x17, 0x1F }, 1130 { 0x17, 0x1f },
1082 1131
1083 /* 1132 /*
1084 * 18 HREFEND "Horizontal window end" 1133 * 18 HREFEND "Horizontal window end"
@@ -1086,7 +1135,7 @@ static const struct ov_i2c_regvals norm_3620b[] = {
1086 * HREFEND[7:0] "Horizontal Window End, 8 MSBs" 1135 * HREFEND[7:0] "Horizontal Window End, 8 MSBs"
1087 * = 95 (0x5F) 01011111 1136 * = 95 (0x5F) 01011111
1088 */ 1137 */
1089 { 0x18, 0x5F }, 1138 { 0x18, 0x5f },
1090 1139
1091 /* 1140 /*
1092 * 19 VSTRT "Vertical window start" 1141 * 19 VSTRT "Vertical window start"
@@ -1126,7 +1175,7 @@ static const struct ov_i2c_regvals norm_3620b[] = {
1126 * COMA[1:0] "Vertical window start line control 2 LSBs" 1175 * COMA[1:0] "Vertical window start line control 2 LSBs"
1127 * = 2 (0x02) ......10 1176 * = 2 (0x02) ......10
1128 */ 1177 */
1129 { 0x03, 0x4A }, 1178 { 0x03, 0x4a },
1130 1179
1131 /* 1180 /*
1132 * 11 CLKRC "Clock Rate Control" 1181 * 11 CLKRC "Clock Rate Control"
@@ -1183,7 +1232,7 @@ static const struct ov_i2c_regvals norm_3620b[] = {
1183 * HREFST[7:0] "Horizontal window start, 8 MSBs" 1232 * HREFST[7:0] "Horizontal window start, 8 MSBs"
1184 * = 31 (0x1F) 00011111 1233 * = 31 (0x1F) 00011111
1185 */ 1234 */
1186 { 0x17, 0x1F }, 1235 { 0x17, 0x1f },
1187 1236
1188 /* 1237 /*
1189 * 18 HREFEND "Horizontal window end" 1238 * 18 HREFEND "Horizontal window end"
@@ -1191,7 +1240,7 @@ static const struct ov_i2c_regvals norm_3620b[] = {
1191 * HREFEND[7:0] "Horizontal Window End, 8 MSBs" 1240 * HREFEND[7:0] "Horizontal Window End, 8 MSBs"
1192 * = 95 (0x5F) 01011111 1241 * = 95 (0x5F) 01011111
1193 */ 1242 */
1194 { 0x18, 0x5F }, 1243 { 0x18, 0x5f },
1195 1244
1196 /* 1245 /*
1197 * 19 VSTRT "Vertical window start" 1246 * 19 VSTRT "Vertical window start"
@@ -1231,7 +1280,7 @@ static const struct ov_i2c_regvals norm_3620b[] = {
1231 * COMA[1:0] "Vertical window start line control 2 LSBs" 1280 * COMA[1:0] "Vertical window start line control 2 LSBs"
1232 * = 2 (0x02) ......10 1281 * = 2 (0x02) ......10
1233 */ 1282 */
1234 { 0x03, 0x4A }, 1283 { 0x03, 0x4a },
1235 1284
1236 /* 1285 /*
1237 * 02 RED "Red Gain Control" 1286 * 02 RED "Red Gain Control"
@@ -1241,7 +1290,7 @@ static const struct ov_i2c_regvals norm_3620b[] = {
1241 * RED[6:0] "Value" 1290 * RED[6:0] "Value"
1242 * = 47 (0x2F) .0101111 1291 * = 47 (0x2F) .0101111
1243 */ 1292 */
1244 { 0x02, 0xAF }, 1293 { 0x02, 0xaf },
1245 1294
1246 /* 1295 /*
1247 * 2D ADDVSL "VSYNC Pulse Width" 1296 * 2D ADDVSL "VSYNC Pulse Width"
@@ -1249,7 +1298,7 @@ static const struct ov_i2c_regvals norm_3620b[] = {
1249 * ADDVSL[7:0] "VSYNC pulse width, LSB" 1298 * ADDVSL[7:0] "VSYNC pulse width, LSB"
1250 * = 210 (0xD2) 11010010 1299 * = 210 (0xD2) 11010010
1251 */ 1300 */
1252 { 0x2d, 0xD2 }, 1301 { 0x2d, 0xd2 },
1253 1302
1254 /* 1303 /*
1255 * 00 GAIN = 24 (0x18) 00011000 1304 * 00 GAIN = 24 (0x18) 00011000
@@ -1272,7 +1321,7 @@ static const struct ov_i2c_regvals norm_3620b[] = {
1272 * BLUE[6:0] "Value" 1321 * BLUE[6:0] "Value"
1273 * = 112 (0x70) .1110000 1322 * = 112 (0x70) .1110000
1274 */ 1323 */
1275 { 0x01, 0xF0 }, 1324 { 0x01, 0xf0 },
1276 1325
1277 /* 1326 /*
1278 * 10 AEC "Automatic Exposure Control" 1327 * 10 AEC "Automatic Exposure Control"
@@ -1280,14 +1329,14 @@ static const struct ov_i2c_regvals norm_3620b[] = {
1280 * AEC[7:0] "Automatic Exposure Control, 8 MSBs" 1329 * AEC[7:0] "Automatic Exposure Control, 8 MSBs"
1281 * = 10 (0x0A) 00001010 1330 * = 10 (0x0A) 00001010
1282 */ 1331 */
1283 { 0x10, 0x0A }, 1332 { 0x10, 0x0a },
1284 1333
1285 { 0xE1, 0x67 }, 1334 { 0xe1, 0x67 },
1286 { 0xE3, 0x03 }, 1335 { 0xe3, 0x03 },
1287 { 0xE4, 0x26 }, 1336 { 0xe4, 0x26 },
1288 { 0xE5, 0x3E }, 1337 { 0xe5, 0x3e },
1289 { 0xF8, 0x01 }, 1338 { 0xf8, 0x01 },
1290 { 0xFF, 0x01 }, 1339 { 0xff, 0x01 },
1291}; 1340};
1292 1341
1293static const struct ov_i2c_regvals norm_6x20[] = { 1342static const struct ov_i2c_regvals norm_6x20[] = {
@@ -1296,7 +1345,7 @@ static const struct ov_i2c_regvals norm_6x20[] = {
1296 { 0x03, 0x60 }, 1345 { 0x03, 0x60 },
1297 { 0x05, 0x7f }, /* For when autoadjust is off */ 1346 { 0x05, 0x7f }, /* For when autoadjust is off */
1298 { 0x07, 0xa8 }, 1347 { 0x07, 0xa8 },
1299 /* The ratio of 0x0c and 0x0d controls the white point */ 1348 /* The ratio of 0x0c and 0x0d controls the white point */
1300 { 0x0c, 0x24 }, 1349 { 0x0c, 0x24 },
1301 { 0x0d, 0x24 }, 1350 { 0x0d, 0x24 },
1302 { 0x0f, 0x15 }, /* COMS */ 1351 { 0x0f, 0x15 }, /* COMS */
@@ -1464,7 +1513,7 @@ static const struct ov_i2c_regvals norm_7620[] = {
1464 { 0x00, 0x00 }, /* gain */ 1513 { 0x00, 0x00 }, /* gain */
1465 { 0x01, 0x80 }, /* blue gain */ 1514 { 0x01, 0x80 }, /* blue gain */
1466 { 0x02, 0x80 }, /* red gain */ 1515 { 0x02, 0x80 }, /* red gain */
1467 { 0x03, 0xc0 }, /* OV7670_REG_VREF */ 1516 { 0x03, 0xc0 }, /* OV7670_R03_VREF */
1468 { 0x06, 0x60 }, 1517 { 0x06, 0x60 },
1469 { 0x07, 0x00 }, 1518 { 0x07, 0x00 },
1470 { 0x0c, 0x24 }, 1519 { 0x0c, 0x24 },
@@ -1532,33 +1581,177 @@ static const struct ov_i2c_regvals norm_7640[] = {
1532 { 0x12, 0x14 }, 1581 { 0x12, 0x14 },
1533}; 1582};
1534 1583
1584static const struct ov_regvals init_519_ov7660[] = {
1585 { 0x5d, 0x03 }, /* Turn off suspend mode */
1586 { 0x53, 0x9b }, /* 0x9f enables the (unused) microcontroller */
1587 { 0x54, 0x0f }, /* bit2 (jpeg enable) */
1588 { 0xa2, 0x20 }, /* a2-a5 are undocumented */
1589 { 0xa3, 0x18 },
1590 { 0xa4, 0x04 },
1591 { 0xa5, 0x28 },
1592 { 0x37, 0x00 }, /* SetUsbInit */
1593 { 0x55, 0x02 }, /* 4.096 Mhz audio clock */
1594 /* Enable both fields, YUV Input, disable defect comp (why?) */
1595 { 0x20, 0x0c }, /* 0x0d does U <-> V swap */
1596 { 0x21, 0x38 },
1597 { 0x22, 0x1d },
1598 { 0x17, 0x50 }, /* undocumented */
1599 { 0x37, 0x00 }, /* undocumented */
1600 { 0x40, 0xff }, /* I2C timeout counter */
1601 { 0x46, 0x00 }, /* I2C clock prescaler */
1602};
1603static const struct ov_i2c_regvals norm_7660[] = {
1604 {OV7670_R12_COM7, OV7670_COM7_RESET},
1605 {OV7670_R11_CLKRC, 0x81},
1606 {0x92, 0x00}, /* DM_LNL */
1607 {0x93, 0x00}, /* DM_LNH */
1608 {0x9d, 0x4c}, /* BD50ST */
1609 {0x9e, 0x3f}, /* BD60ST */
1610 {OV7670_R3B_COM11, 0x02},
1611 {OV7670_R13_COM8, 0xf5},
1612 {OV7670_R10_AECH, 0x00},
1613 {OV7670_R00_GAIN, 0x00},
1614 {OV7670_R01_BLUE, 0x7c},
1615 {OV7670_R02_RED, 0x9d},
1616 {OV7670_R12_COM7, 0x00},
1617 {OV7670_R04_COM1, 00},
1618 {OV7670_R18_HSTOP, 0x01},
1619 {OV7670_R17_HSTART, 0x13},
1620 {OV7670_R32_HREF, 0x92},
1621 {OV7670_R19_VSTART, 0x02},
1622 {OV7670_R1A_VSTOP, 0x7a},
1623 {OV7670_R03_VREF, 0x00},
1624 {OV7670_R0E_COM5, 0x04},
1625 {OV7670_R0F_COM6, 0x62},
1626 {OV7670_R15_COM10, 0x00},
1627 {0x16, 0x02}, /* RSVD */
1628 {0x1b, 0x00}, /* PSHFT */
1629 {OV7670_R1E_MVFP, 0x01},
1630 {0x29, 0x3c}, /* RSVD */
1631 {0x33, 0x00}, /* CHLF */
1632 {0x34, 0x07}, /* ARBLM */
1633 {0x35, 0x84}, /* RSVD */
1634 {0x36, 0x00}, /* RSVD */
1635 {0x37, 0x04}, /* ADC */
1636 {0x39, 0x43}, /* OFON */
1637 {OV7670_R3A_TSLB, 0x00},
1638 {OV7670_R3C_COM12, 0x6c},
1639 {OV7670_R3D_COM13, 0x98},
1640 {OV7670_R3F_EDGE, 0x23},
1641 {OV7670_R40_COM15, 0xc1},
1642 {OV7670_R41_COM16, 0x22},
1643 {0x6b, 0x0a}, /* DBLV */
1644 {0xa1, 0x08}, /* RSVD */
1645 {0x69, 0x80}, /* HV */
1646 {0x43, 0xf0}, /* RSVD.. */
1647 {0x44, 0x10},
1648 {0x45, 0x78},
1649 {0x46, 0xa8},
1650 {0x47, 0x60},
1651 {0x48, 0x80},
1652 {0x59, 0xba},
1653 {0x5a, 0x9a},
1654 {0x5b, 0x22},
1655 {0x5c, 0xb9},
1656 {0x5d, 0x9b},
1657 {0x5e, 0x10},
1658 {0x5f, 0xe0},
1659 {0x60, 0x85},
1660 {0x61, 0x60},
1661 {0x9f, 0x9d}, /* RSVD */
1662 {0xa0, 0xa0}, /* DSPC2 */
1663 {0x4f, 0x60}, /* matrix */
1664 {0x50, 0x64},
1665 {0x51, 0x04},
1666 {0x52, 0x18},
1667 {0x53, 0x3c},
1668 {0x54, 0x54},
1669 {0x55, 0x40},
1670 {0x56, 0x40},
1671 {0x57, 0x40},
1672 {0x58, 0x0d}, /* matrix sign */
1673 {0x8b, 0xcc}, /* RSVD */
1674 {0x8c, 0xcc},
1675 {0x8d, 0xcf},
1676 {0x6c, 0x40}, /* gamma curve */
1677 {0x6d, 0xe0},
1678 {0x6e, 0xa0},
1679 {0x6f, 0x80},
1680 {0x70, 0x70},
1681 {0x71, 0x80},
1682 {0x72, 0x60},
1683 {0x73, 0x60},
1684 {0x74, 0x50},
1685 {0x75, 0x40},
1686 {0x76, 0x38},
1687 {0x77, 0x3c},
1688 {0x78, 0x32},
1689 {0x79, 0x1a},
1690 {0x7a, 0x28},
1691 {0x7b, 0x24},
1692 {0x7c, 0x04}, /* gamma curve */
1693 {0x7d, 0x12},
1694 {0x7e, 0x26},
1695 {0x7f, 0x46},
1696 {0x80, 0x54},
1697 {0x81, 0x64},
1698 {0x82, 0x70},
1699 {0x83, 0x7c},
1700 {0x84, 0x86},
1701 {0x85, 0x8e},
1702 {0x86, 0x9c},
1703 {0x87, 0xab},
1704 {0x88, 0xc4},
1705 {0x89, 0xd1},
1706 {0x8a, 0xe5},
1707 {OV7670_R14_COM9, 0x1e},
1708 {OV7670_R24_AEW, 0x80},
1709 {OV7670_R25_AEB, 0x72},
1710 {OV7670_R26_VPT, 0xb3},
1711 {0x62, 0x80}, /* LCC1 */
1712 {0x63, 0x80}, /* LCC2 */
1713 {0x64, 0x06}, /* LCC3 */
1714 {0x65, 0x00}, /* LCC4 */
1715 {0x66, 0x01}, /* LCC5 */
1716 {0x94, 0x0e}, /* RSVD.. */
1717 {0x95, 0x14},
1718 {OV7670_R13_COM8, OV7670_COM8_FASTAEC
1719 | OV7670_COM8_AECSTEP
1720 | OV7670_COM8_BFILT
1721 | 0x10
1722 | OV7670_COM8_AGC
1723 | OV7670_COM8_AWB
1724 | OV7670_COM8_AEC},
1725 {0xa1, 0xc8}
1726};
1727
1535/* 7670. Defaults taken from OmniVision provided data, 1728/* 7670. Defaults taken from OmniVision provided data,
1536* as provided by Jonathan Corbet of OLPC */ 1729* as provided by Jonathan Corbet of OLPC */
1537static const struct ov_i2c_regvals norm_7670[] = { 1730static const struct ov_i2c_regvals norm_7670[] = {
1538 { OV7670_REG_COM7, OV7670_COM7_RESET }, 1731 { OV7670_R12_COM7, OV7670_COM7_RESET },
1539 { OV7670_REG_TSLB, 0x04 }, /* OV */ 1732 { OV7670_R3A_TSLB, 0x04 }, /* OV */
1540 { OV7670_REG_COM7, OV7670_COM7_FMT_VGA }, /* VGA */ 1733 { OV7670_R12_COM7, OV7670_COM7_FMT_VGA }, /* VGA */
1541 { OV7670_REG_CLKRC, 0x01 }, 1734 { OV7670_R11_CLKRC, 0x01 },
1542/* 1735/*
1543 * Set the hardware window. These values from OV don't entirely 1736 * Set the hardware window. These values from OV don't entirely
1544 * make sense - hstop is less than hstart. But they work... 1737 * make sense - hstop is less than hstart. But they work...
1545 */ 1738 */
1546 { OV7670_REG_HSTART, 0x13 }, 1739 { OV7670_R17_HSTART, 0x13 },
1547 { OV7670_REG_HSTOP, 0x01 }, 1740 { OV7670_R18_HSTOP, 0x01 },
1548 { OV7670_REG_HREF, 0xb6 }, 1741 { OV7670_R32_HREF, 0xb6 },
1549 { OV7670_REG_VSTART, 0x02 }, 1742 { OV7670_R19_VSTART, 0x02 },
1550 { OV7670_REG_VSTOP, 0x7a }, 1743 { OV7670_R1A_VSTOP, 0x7a },
1551 { OV7670_REG_VREF, 0x0a }, 1744 { OV7670_R03_VREF, 0x0a },
1552 1745
1553 { OV7670_REG_COM3, 0x00 }, 1746 { OV7670_R0C_COM3, 0x00 },
1554 { OV7670_REG_COM14, 0x00 }, 1747 { OV7670_R3E_COM14, 0x00 },
1555/* Mystery scaling numbers */ 1748/* Mystery scaling numbers */
1556 { 0x70, 0x3a }, 1749 { 0x70, 0x3a },
1557 { 0x71, 0x35 }, 1750 { 0x71, 0x35 },
1558 { 0x72, 0x11 }, 1751 { 0x72, 0x11 },
1559 { 0x73, 0xf0 }, 1752 { 0x73, 0xf0 },
1560 { 0xa2, 0x02 }, 1753 { 0xa2, 0x02 },
1561/* { OV7670_REG_COM10, 0x0 }, */ 1754/* { OV7670_R15_COM10, 0x0 }, */
1562 1755
1563/* Gamma curve values */ 1756/* Gamma curve values */
1564 { 0x7a, 0x20 }, 1757 { 0x7a, 0x20 },
@@ -1580,37 +1773,37 @@ static const struct ov_i2c_regvals norm_7670[] = {
1580 1773
1581/* AGC and AEC parameters. Note we start by disabling those features, 1774/* AGC and AEC parameters. Note we start by disabling those features,
1582 then turn them only after tweaking the values. */ 1775 then turn them only after tweaking the values. */
1583 { OV7670_REG_COM8, OV7670_COM8_FASTAEC 1776 { OV7670_R13_COM8, OV7670_COM8_FASTAEC
1584 | OV7670_COM8_AECSTEP 1777 | OV7670_COM8_AECSTEP
1585 | OV7670_COM8_BFILT }, 1778 | OV7670_COM8_BFILT },
1586 { OV7670_REG_GAIN, 0x00 }, 1779 { OV7670_R00_GAIN, 0x00 },
1587 { OV7670_REG_AECH, 0x00 }, 1780 { OV7670_R10_AECH, 0x00 },
1588 { OV7670_REG_COM4, 0x40 }, /* magic reserved bit */ 1781 { OV7670_R0D_COM4, 0x40 }, /* magic reserved bit */
1589 { OV7670_REG_COM9, 0x18 }, /* 4x gain + magic rsvd bit */ 1782 { OV7670_R14_COM9, 0x18 }, /* 4x gain + magic rsvd bit */
1590 { OV7670_REG_BD50MAX, 0x05 }, 1783 { OV7670_RA5_BD50MAX, 0x05 },
1591 { OV7670_REG_BD60MAX, 0x07 }, 1784 { OV7670_RAB_BD60MAX, 0x07 },
1592 { OV7670_REG_AEW, 0x95 }, 1785 { OV7670_R24_AEW, 0x95 },
1593 { OV7670_REG_AEB, 0x33 }, 1786 { OV7670_R25_AEB, 0x33 },
1594 { OV7670_REG_VPT, 0xe3 }, 1787 { OV7670_R26_VPT, 0xe3 },
1595 { OV7670_REG_HAECC1, 0x78 }, 1788 { OV7670_R9F_HAECC1, 0x78 },
1596 { OV7670_REG_HAECC2, 0x68 }, 1789 { OV7670_RA0_HAECC2, 0x68 },
1597 { 0xa1, 0x03 }, /* magic */ 1790 { 0xa1, 0x03 }, /* magic */
1598 { OV7670_REG_HAECC3, 0xd8 }, 1791 { OV7670_RA6_HAECC3, 0xd8 },
1599 { OV7670_REG_HAECC4, 0xd8 }, 1792 { OV7670_RA7_HAECC4, 0xd8 },
1600 { OV7670_REG_HAECC5, 0xf0 }, 1793 { OV7670_RA8_HAECC5, 0xf0 },
1601 { OV7670_REG_HAECC6, 0x90 }, 1794 { OV7670_RA9_HAECC6, 0x90 },
1602 { OV7670_REG_HAECC7, 0x94 }, 1795 { OV7670_RAA_HAECC7, 0x94 },
1603 { OV7670_REG_COM8, OV7670_COM8_FASTAEC 1796 { OV7670_R13_COM8, OV7670_COM8_FASTAEC
1604 | OV7670_COM8_AECSTEP 1797 | OV7670_COM8_AECSTEP
1605 | OV7670_COM8_BFILT 1798 | OV7670_COM8_BFILT
1606 | OV7670_COM8_AGC 1799 | OV7670_COM8_AGC
1607 | OV7670_COM8_AEC }, 1800 | OV7670_COM8_AEC },
1608 1801
1609/* Almost all of these are magic "reserved" values. */ 1802/* Almost all of these are magic "reserved" values. */
1610 { OV7670_REG_COM5, 0x61 }, 1803 { OV7670_R0E_COM5, 0x61 },
1611 { OV7670_REG_COM6, 0x4b }, 1804 { OV7670_R0F_COM6, 0x4b },
1612 { 0x16, 0x02 }, 1805 { 0x16, 0x02 },
1613 { OV7670_REG_MVFP, 0x07 }, 1806 { OV7670_R1E_MVFP, 0x07 },
1614 { 0x21, 0x02 }, 1807 { 0x21, 0x02 },
1615 { 0x22, 0x91 }, 1808 { 0x22, 0x91 },
1616 { 0x29, 0x07 }, 1809 { 0x29, 0x07 },
@@ -1619,10 +1812,10 @@ static const struct ov_i2c_regvals norm_7670[] = {
1619 { 0x37, 0x1d }, 1812 { 0x37, 0x1d },
1620 { 0x38, 0x71 }, 1813 { 0x38, 0x71 },
1621 { 0x39, 0x2a }, 1814 { 0x39, 0x2a },
1622 { OV7670_REG_COM12, 0x78 }, 1815 { OV7670_R3C_COM12, 0x78 },
1623 { 0x4d, 0x40 }, 1816 { 0x4d, 0x40 },
1624 { 0x4e, 0x20 }, 1817 { 0x4e, 0x20 },
1625 { OV7670_REG_GFIX, 0x00 }, 1818 { OV7670_R69_GFIX, 0x00 },
1626 { 0x6b, 0x4a }, 1819 { 0x6b, 0x4a },
1627 { 0x74, 0x10 }, 1820 { 0x74, 0x10 },
1628 { 0x8d, 0x4f }, 1821 { 0x8d, 0x4f },
@@ -1657,9 +1850,9 @@ static const struct ov_i2c_regvals norm_7670[] = {
1657 { 0x6f, 0x9f }, 1850 { 0x6f, 0x9f },
1658 /* "9e for advance AWB" */ 1851 /* "9e for advance AWB" */
1659 { 0x6a, 0x40 }, 1852 { 0x6a, 0x40 },
1660 { OV7670_REG_BLUE, 0x40 }, 1853 { OV7670_R01_BLUE, 0x40 },
1661 { OV7670_REG_RED, 0x60 }, 1854 { OV7670_R02_RED, 0x60 },
1662 { OV7670_REG_COM8, OV7670_COM8_FASTAEC 1855 { OV7670_R13_COM8, OV7670_COM8_FASTAEC
1663 | OV7670_COM8_AECSTEP 1856 | OV7670_COM8_AECSTEP
1664 | OV7670_COM8_BFILT 1857 | OV7670_COM8_BFILT
1665 | OV7670_COM8_AGC 1858 | OV7670_COM8_AGC
@@ -1675,22 +1868,22 @@ static const struct ov_i2c_regvals norm_7670[] = {
1675 { 0x54, 0x80 }, 1868 { 0x54, 0x80 },
1676 { 0x58, 0x9e }, 1869 { 0x58, 0x9e },
1677 1870
1678 { OV7670_REG_COM16, OV7670_COM16_AWBGAIN }, 1871 { OV7670_R41_COM16, OV7670_COM16_AWBGAIN },
1679 { OV7670_REG_EDGE, 0x00 }, 1872 { OV7670_R3F_EDGE, 0x00 },
1680 { 0x75, 0x05 }, 1873 { 0x75, 0x05 },
1681 { 0x76, 0xe1 }, 1874 { 0x76, 0xe1 },
1682 { 0x4c, 0x00 }, 1875 { 0x4c, 0x00 },
1683 { 0x77, 0x01 }, 1876 { 0x77, 0x01 },
1684 { OV7670_REG_COM13, OV7670_COM13_GAMMA 1877 { OV7670_R3D_COM13, OV7670_COM13_GAMMA
1685 | OV7670_COM13_UVSAT 1878 | OV7670_COM13_UVSAT
1686 | 2}, /* was 3 */ 1879 | 2}, /* was 3 */
1687 { 0x4b, 0x09 }, 1880 { 0x4b, 0x09 },
1688 { 0xc9, 0x60 }, 1881 { 0xc9, 0x60 },
1689 { OV7670_REG_COM16, 0x38 }, 1882 { OV7670_R41_COM16, 0x38 },
1690 { 0x56, 0x40 }, 1883 { 0x56, 0x40 },
1691 1884
1692 { 0x34, 0x11 }, 1885 { 0x34, 0x11 },
1693 { OV7670_REG_COM11, OV7670_COM11_EXP|OV7670_COM11_HZAUTO }, 1886 { OV7670_R3B_COM11, OV7670_COM11_EXP|OV7670_COM11_HZAUTO },
1694 { 0xa4, 0x88 }, 1887 { 0xa4, 0x88 },
1695 { 0x96, 0x00 }, 1888 { 0x96, 0x00 },
1696 { 0x97, 0x30 }, 1889 { 0x97, 0x30 },
@@ -1825,10 +2018,13 @@ static unsigned char ov7670_abs_to_sm(unsigned char v)
1825} 2018}
1826 2019
1827/* Write a OV519 register */ 2020/* Write a OV519 register */
1828static int reg_w(struct sd *sd, __u16 index, __u16 value) 2021static void reg_w(struct sd *sd, u16 index, u16 value)
1829{ 2022{
1830 int ret, req = 0; 2023 int ret, req = 0;
1831 2024
2025 if (sd->gspca_dev.usb_err < 0)
2026 return;
2027
1832 switch (sd->bridge) { 2028 switch (sd->bridge) {
1833 case BRIDGE_OV511: 2029 case BRIDGE_OV511:
1834 case BRIDGE_OV511PLUS: 2030 case BRIDGE_OV511PLUS:
@@ -1838,6 +2034,8 @@ static int reg_w(struct sd *sd, __u16 index, __u16 value)
1838 req = 0x0a; 2034 req = 0x0a;
1839 /* fall through */ 2035 /* fall through */
1840 case BRIDGE_W9968CF: 2036 case BRIDGE_W9968CF:
2037 PDEBUG(D_USBO, "SET %02x %04x %04x",
2038 req, value, index);
1841 ret = usb_control_msg(sd->gspca_dev.dev, 2039 ret = usb_control_msg(sd->gspca_dev.dev,
1842 usb_sndctrlpipe(sd->gspca_dev.dev, 0), 2040 usb_sndctrlpipe(sd->gspca_dev.dev, 0),
1843 req, 2041 req,
@@ -1848,6 +2046,8 @@ static int reg_w(struct sd *sd, __u16 index, __u16 value)
1848 req = 1; 2046 req = 1;
1849 } 2047 }
1850 2048
2049 PDEBUG(D_USBO, "SET %02x 0000 %04x %02x",
2050 req, index, value);
1851 sd->gspca_dev.usb_buf[0] = value; 2051 sd->gspca_dev.usb_buf[0] = value;
1852 ret = usb_control_msg(sd->gspca_dev.dev, 2052 ret = usb_control_msg(sd->gspca_dev.dev,
1853 usb_sndctrlpipe(sd->gspca_dev.dev, 0), 2053 usb_sndctrlpipe(sd->gspca_dev.dev, 0),
@@ -1857,22 +2057,22 @@ static int reg_w(struct sd *sd, __u16 index, __u16 value)
1857 sd->gspca_dev.usb_buf, 1, 500); 2057 sd->gspca_dev.usb_buf, 1, 500);
1858leave: 2058leave:
1859 if (ret < 0) { 2059 if (ret < 0) {
1860 err("Write reg 0x%04x -> [0x%02x] failed", 2060 err("reg_w %02x failed %d", index, ret);
1861 value, index); 2061 sd->gspca_dev.usb_err = ret;
1862 return ret; 2062 return;
1863 } 2063 }
1864
1865 PDEBUG(D_USBO, "Write reg 0x%04x -> [0x%02x]", value, index);
1866 return 0;
1867} 2064}
1868 2065
1869/* Read from a OV519 register, note not valid for the w9968cf!! */ 2066/* Read from a OV519 register, note not valid for the w9968cf!! */
1870/* returns: negative is error, pos or zero is data */ 2067/* returns: negative is error, pos or zero is data */
1871static int reg_r(struct sd *sd, __u16 index) 2068static int reg_r(struct sd *sd, u16 index)
1872{ 2069{
1873 int ret; 2070 int ret;
1874 int req; 2071 int req;
1875 2072
2073 if (sd->gspca_dev.usb_err < 0)
2074 return -1;
2075
1876 switch (sd->bridge) { 2076 switch (sd->bridge) {
1877 case BRIDGE_OV511: 2077 case BRIDGE_OV511:
1878 case BRIDGE_OV511PLUS: 2078 case BRIDGE_OV511PLUS:
@@ -1893,29 +2093,37 @@ static int reg_r(struct sd *sd, __u16 index)
1893 2093
1894 if (ret >= 0) { 2094 if (ret >= 0) {
1895 ret = sd->gspca_dev.usb_buf[0]; 2095 ret = sd->gspca_dev.usb_buf[0];
1896 PDEBUG(D_USBI, "Read reg [0x%02X] -> 0x%04X", index, ret); 2096 PDEBUG(D_USBI, "GET %02x 0000 %04x %02x",
1897 } else 2097 req, index, ret);
1898 err("Read reg [0x%02x] failed", index); 2098 } else {
2099 err("reg_r %02x failed %d", index, ret);
2100 sd->gspca_dev.usb_err = ret;
2101 }
1899 2102
1900 return ret; 2103 return ret;
1901} 2104}
1902 2105
1903/* Read 8 values from a OV519 register */ 2106/* Read 8 values from a OV519 register */
1904static int reg_r8(struct sd *sd, 2107static int reg_r8(struct sd *sd,
1905 __u16 index) 2108 u16 index)
1906{ 2109{
1907 int ret; 2110 int ret;
1908 2111
2112 if (sd->gspca_dev.usb_err < 0)
2113 return -1;
2114
1909 ret = usb_control_msg(sd->gspca_dev.dev, 2115 ret = usb_control_msg(sd->gspca_dev.dev,
1910 usb_rcvctrlpipe(sd->gspca_dev.dev, 0), 2116 usb_rcvctrlpipe(sd->gspca_dev.dev, 0),
1911 1, /* REQ_IO */ 2117 1, /* REQ_IO */
1912 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 2118 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1913 0, index, sd->gspca_dev.usb_buf, 8, 500); 2119 0, index, sd->gspca_dev.usb_buf, 8, 500);
1914 2120
1915 if (ret >= 0) 2121 if (ret >= 0) {
1916 ret = sd->gspca_dev.usb_buf[0]; 2122 ret = sd->gspca_dev.usb_buf[0];
1917 else 2123 } else {
1918 err("Read reg 8 [0x%02x] failed", index); 2124 err("reg_r8 %02x failed %d", index, ret);
2125 sd->gspca_dev.usb_err = ret;
2126 }
1919 2127
1920 return ret; 2128 return ret;
1921} 2129}
@@ -1926,34 +2134,37 @@ static int reg_r8(struct sd *sd,
1926 * that are in the same position as 0's in "mask" are preserved, regardless 2134 * that are in the same position as 0's in "mask" are preserved, regardless
1927 * of their respective state in "value". 2135 * of their respective state in "value".
1928 */ 2136 */
1929static int reg_w_mask(struct sd *sd, 2137static void reg_w_mask(struct sd *sd,
1930 __u16 index, 2138 u16 index,
1931 __u8 value, 2139 u8 value,
1932 __u8 mask) 2140 u8 mask)
1933{ 2141{
1934 int ret; 2142 int ret;
1935 __u8 oldval; 2143 u8 oldval;
1936 2144
1937 if (mask != 0xff) { 2145 if (mask != 0xff) {
1938 value &= mask; /* Enforce mask on value */ 2146 value &= mask; /* Enforce mask on value */
1939 ret = reg_r(sd, index); 2147 ret = reg_r(sd, index);
1940 if (ret < 0) 2148 if (ret < 0)
1941 return ret; 2149 return;
1942 2150
1943 oldval = ret & ~mask; /* Clear the masked bits */ 2151 oldval = ret & ~mask; /* Clear the masked bits */
1944 value |= oldval; /* Set the desired bits */ 2152 value |= oldval; /* Set the desired bits */
1945 } 2153 }
1946 return reg_w(sd, index, value); 2154 reg_w(sd, index, value);
1947} 2155}
1948 2156
1949/* 2157/*
1950 * Writes multiple (n) byte value to a single register. Only valid with certain 2158 * Writes multiple (n) byte value to a single register. Only valid with certain
1951 * registers (0x30 and 0xc4 - 0xce). 2159 * registers (0x30 and 0xc4 - 0xce).
1952 */ 2160 */
1953static int ov518_reg_w32(struct sd *sd, __u16 index, u32 value, int n) 2161static void ov518_reg_w32(struct sd *sd, u16 index, u32 value, int n)
1954{ 2162{
1955 int ret; 2163 int ret;
1956 2164
2165 if (sd->gspca_dev.usb_err < 0)
2166 return;
2167
1957 *((__le32 *) sd->gspca_dev.usb_buf) = __cpu_to_le32(value); 2168 *((__le32 *) sd->gspca_dev.usb_buf) = __cpu_to_le32(value);
1958 2169
1959 ret = usb_control_msg(sd->gspca_dev.dev, 2170 ret = usb_control_msg(sd->gspca_dev.dev,
@@ -1963,69 +2174,55 @@ static int ov518_reg_w32(struct sd *sd, __u16 index, u32 value, int n)
1963 0, index, 2174 0, index,
1964 sd->gspca_dev.usb_buf, n, 500); 2175 sd->gspca_dev.usb_buf, n, 500);
1965 if (ret < 0) { 2176 if (ret < 0) {
1966 err("Write reg32 [%02x] %08x failed", index, value); 2177 err("reg_w32 %02x failed %d", index, ret);
1967 return ret; 2178 sd->gspca_dev.usb_err = ret;
1968 } 2179 }
1969
1970 return 0;
1971} 2180}
1972 2181
1973static int ov511_i2c_w(struct sd *sd, __u8 reg, __u8 value) 2182static void ov511_i2c_w(struct sd *sd, u8 reg, u8 value)
1974{ 2183{
1975 int rc, retries; 2184 int rc, retries;
1976 2185
1977 PDEBUG(D_USBO, "i2c 0x%02x -> [0x%02x]", value, reg); 2186 PDEBUG(D_USBO, "ov511_i2c_w %02x %02x", reg, value);
1978 2187
1979 /* Three byte write cycle */ 2188 /* Three byte write cycle */
1980 for (retries = 6; ; ) { 2189 for (retries = 6; ; ) {
1981 /* Select camera register */ 2190 /* Select camera register */
1982 rc = reg_w(sd, R51x_I2C_SADDR_3, reg); 2191 reg_w(sd, R51x_I2C_SADDR_3, reg);
1983 if (rc < 0)
1984 return rc;
1985 2192
1986 /* Write "value" to I2C data port of OV511 */ 2193 /* Write "value" to I2C data port of OV511 */
1987 rc = reg_w(sd, R51x_I2C_DATA, value); 2194 reg_w(sd, R51x_I2C_DATA, value);
1988 if (rc < 0)
1989 return rc;
1990 2195
1991 /* Initiate 3-byte write cycle */ 2196 /* Initiate 3-byte write cycle */
1992 rc = reg_w(sd, R511_I2C_CTL, 0x01); 2197 reg_w(sd, R511_I2C_CTL, 0x01);
1993 if (rc < 0)
1994 return rc;
1995 2198
1996 do { 2199 do {
1997 rc = reg_r(sd, R511_I2C_CTL); 2200 rc = reg_r(sd, R511_I2C_CTL);
1998 } while (rc > 0 && ((rc & 1) == 0)); /* Retry until idle */ 2201 } while (rc > 0 && ((rc & 1) == 0)); /* Retry until idle */
1999 2202
2000 if (rc < 0) 2203 if (rc < 0)
2001 return rc; 2204 return;
2002 2205
2003 if ((rc & 2) == 0) /* Ack? */ 2206 if ((rc & 2) == 0) /* Ack? */
2004 break; 2207 break;
2005 if (--retries < 0) { 2208 if (--retries < 0) {
2006 PDEBUG(D_USBO, "i2c write retries exhausted"); 2209 PDEBUG(D_USBO, "i2c write retries exhausted");
2007 return -1; 2210 return;
2008 } 2211 }
2009 } 2212 }
2010
2011 return 0;
2012} 2213}
2013 2214
2014static int ov511_i2c_r(struct sd *sd, __u8 reg) 2215static int ov511_i2c_r(struct sd *sd, u8 reg)
2015{ 2216{
2016 int rc, value, retries; 2217 int rc, value, retries;
2017 2218
2018 /* Two byte write cycle */ 2219 /* Two byte write cycle */
2019 for (retries = 6; ; ) { 2220 for (retries = 6; ; ) {
2020 /* Select camera register */ 2221 /* Select camera register */
2021 rc = reg_w(sd, R51x_I2C_SADDR_2, reg); 2222 reg_w(sd, R51x_I2C_SADDR_2, reg);
2022 if (rc < 0)
2023 return rc;
2024 2223
2025 /* Initiate 2-byte write cycle */ 2224 /* Initiate 2-byte write cycle */
2026 rc = reg_w(sd, R511_I2C_CTL, 0x03); 2225 reg_w(sd, R511_I2C_CTL, 0x03);
2027 if (rc < 0)
2028 return rc;
2029 2226
2030 do { 2227 do {
2031 rc = reg_r(sd, R511_I2C_CTL); 2228 rc = reg_r(sd, R511_I2C_CTL);
@@ -2049,9 +2246,7 @@ static int ov511_i2c_r(struct sd *sd, __u8 reg)
2049 /* Two byte read cycle */ 2246 /* Two byte read cycle */
2050 for (retries = 6; ; ) { 2247 for (retries = 6; ; ) {
2051 /* Initiate 2-byte read cycle */ 2248 /* Initiate 2-byte read cycle */
2052 rc = reg_w(sd, R511_I2C_CTL, 0x05); 2249 reg_w(sd, R511_I2C_CTL, 0x05);
2053 if (rc < 0)
2054 return rc;
2055 2250
2056 do { 2251 do {
2057 rc = reg_r(sd, R511_I2C_CTL); 2252 rc = reg_r(sd, R511_I2C_CTL);
@@ -2064,9 +2259,7 @@ static int ov511_i2c_r(struct sd *sd, __u8 reg)
2064 break; 2259 break;
2065 2260
2066 /* I2C abort */ 2261 /* I2C abort */
2067 rc = reg_w(sd, R511_I2C_CTL, 0x10); 2262 reg_w(sd, R511_I2C_CTL, 0x10);
2068 if (rc < 0)
2069 return rc;
2070 2263
2071 if (--retries < 0) { 2264 if (--retries < 0) {
2072 PDEBUG(D_USBI, "i2c read retries exhausted"); 2265 PDEBUG(D_USBI, "i2c read retries exhausted");
@@ -2076,12 +2269,10 @@ static int ov511_i2c_r(struct sd *sd, __u8 reg)
2076 2269
2077 value = reg_r(sd, R51x_I2C_DATA); 2270 value = reg_r(sd, R51x_I2C_DATA);
2078 2271
2079 PDEBUG(D_USBI, "i2c [0x%02X] -> 0x%02X", reg, value); 2272 PDEBUG(D_USBI, "ov511_i2c_r %02x %02x", reg, value);
2080 2273
2081 /* This is needed to make i2c_w() work */ 2274 /* This is needed to make i2c_w() work */
2082 rc = reg_w(sd, R511_I2C_CTL, 0x05); 2275 reg_w(sd, R511_I2C_CTL, 0x05);
2083 if (rc < 0)
2084 return rc;
2085 2276
2086 return value; 2277 return value;
2087} 2278}
@@ -2091,32 +2282,24 @@ static int ov511_i2c_r(struct sd *sd, __u8 reg)
2091 * This is normally only called from i2c_w(). Note that this function 2282 * This is normally only called from i2c_w(). Note that this function
2092 * always succeeds regardless of whether the sensor is present and working. 2283 * always succeeds regardless of whether the sensor is present and working.
2093 */ 2284 */
2094static int ov518_i2c_w(struct sd *sd, 2285static void ov518_i2c_w(struct sd *sd,
2095 __u8 reg, 2286 u8 reg,
2096 __u8 value) 2287 u8 value)
2097{ 2288{
2098 int rc; 2289 PDEBUG(D_USBO, "ov518_i2c_w %02x %02x", reg, value);
2099
2100 PDEBUG(D_USBO, "i2c 0x%02x -> [0x%02x]", value, reg);
2101 2290
2102 /* Select camera register */ 2291 /* Select camera register */
2103 rc = reg_w(sd, R51x_I2C_SADDR_3, reg); 2292 reg_w(sd, R51x_I2C_SADDR_3, reg);
2104 if (rc < 0)
2105 return rc;
2106 2293
2107 /* Write "value" to I2C data port of OV511 */ 2294 /* Write "value" to I2C data port of OV511 */
2108 rc = reg_w(sd, R51x_I2C_DATA, value); 2295 reg_w(sd, R51x_I2C_DATA, value);
2109 if (rc < 0)
2110 return rc;
2111 2296
2112 /* Initiate 3-byte write cycle */ 2297 /* Initiate 3-byte write cycle */
2113 rc = reg_w(sd, R518_I2C_CTL, 0x01); 2298 reg_w(sd, R518_I2C_CTL, 0x01);
2114 if (rc < 0)
2115 return rc;
2116 2299
2117 /* wait for write complete */ 2300 /* wait for write complete */
2118 msleep(4); 2301 msleep(4);
2119 return reg_r8(sd, R518_I2C_CTL); 2302 reg_r8(sd, R518_I2C_CTL);
2120} 2303}
2121 2304
2122/* 2305/*
@@ -2126,105 +2309,102 @@ static int ov518_i2c_w(struct sd *sd,
2126 * This is normally only called from i2c_r(). Note that this function 2309 * This is normally only called from i2c_r(). Note that this function
2127 * always succeeds regardless of whether the sensor is present and working. 2310 * always succeeds regardless of whether the sensor is present and working.
2128 */ 2311 */
2129static int ov518_i2c_r(struct sd *sd, __u8 reg) 2312static int ov518_i2c_r(struct sd *sd, u8 reg)
2130{ 2313{
2131 int rc, value; 2314 int value;
2132 2315
2133 /* Select camera register */ 2316 /* Select camera register */
2134 rc = reg_w(sd, R51x_I2C_SADDR_2, reg); 2317 reg_w(sd, R51x_I2C_SADDR_2, reg);
2135 if (rc < 0)
2136 return rc;
2137 2318
2138 /* Initiate 2-byte write cycle */ 2319 /* Initiate 2-byte write cycle */
2139 rc = reg_w(sd, R518_I2C_CTL, 0x03); 2320 reg_w(sd, R518_I2C_CTL, 0x03);
2140 if (rc < 0)
2141 return rc;
2142 2321
2143 /* Initiate 2-byte read cycle */ 2322 /* Initiate 2-byte read cycle */
2144 rc = reg_w(sd, R518_I2C_CTL, 0x05); 2323 reg_w(sd, R518_I2C_CTL, 0x05);
2145 if (rc < 0)
2146 return rc;
2147 value = reg_r(sd, R51x_I2C_DATA); 2324 value = reg_r(sd, R51x_I2C_DATA);
2148 PDEBUG(D_USBI, "i2c [0x%02X] -> 0x%02X", reg, value); 2325 PDEBUG(D_USBI, "ov518_i2c_r %02x %02x", reg, value);
2149 return value; 2326 return value;
2150} 2327}
2151 2328
2152static int ovfx2_i2c_w(struct sd *sd, __u8 reg, __u8 value) 2329static void ovfx2_i2c_w(struct sd *sd, u8 reg, u8 value)
2153{ 2330{
2154 int ret; 2331 int ret;
2155 2332
2333 if (sd->gspca_dev.usb_err < 0)
2334 return;
2335
2156 ret = usb_control_msg(sd->gspca_dev.dev, 2336 ret = usb_control_msg(sd->gspca_dev.dev,
2157 usb_sndctrlpipe(sd->gspca_dev.dev, 0), 2337 usb_sndctrlpipe(sd->gspca_dev.dev, 0),
2158 0x02, 2338 0x02,
2159 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 2339 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
2160 (__u16)value, (__u16)reg, NULL, 0, 500); 2340 (u16) value, (u16) reg, NULL, 0, 500);
2161 2341
2162 if (ret < 0) { 2342 if (ret < 0) {
2163 err("i2c 0x%02x -> [0x%02x] failed", value, reg); 2343 err("ovfx2_i2c_w %02x failed %d", reg, ret);
2164 return ret; 2344 sd->gspca_dev.usb_err = ret;
2165 } 2345 }
2166 2346
2167 PDEBUG(D_USBO, "i2c 0x%02x -> [0x%02x]", value, reg); 2347 PDEBUG(D_USBO, "ovfx2_i2c_w %02x %02x", reg, value);
2168 return 0;
2169} 2348}
2170 2349
2171static int ovfx2_i2c_r(struct sd *sd, __u8 reg) 2350static int ovfx2_i2c_r(struct sd *sd, u8 reg)
2172{ 2351{
2173 int ret; 2352 int ret;
2174 2353
2354 if (sd->gspca_dev.usb_err < 0)
2355 return -1;
2356
2175 ret = usb_control_msg(sd->gspca_dev.dev, 2357 ret = usb_control_msg(sd->gspca_dev.dev,
2176 usb_rcvctrlpipe(sd->gspca_dev.dev, 0), 2358 usb_rcvctrlpipe(sd->gspca_dev.dev, 0),
2177 0x03, 2359 0x03,
2178 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 2360 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
2179 0, (__u16)reg, sd->gspca_dev.usb_buf, 1, 500); 2361 0, (u16) reg, sd->gspca_dev.usb_buf, 1, 500);
2180 2362
2181 if (ret >= 0) { 2363 if (ret >= 0) {
2182 ret = sd->gspca_dev.usb_buf[0]; 2364 ret = sd->gspca_dev.usb_buf[0];
2183 PDEBUG(D_USBI, "i2c [0x%02X] -> 0x%02X", reg, ret); 2365 PDEBUG(D_USBI, "ovfx2_i2c_r %02x %02x", reg, ret);
2184 } else 2366 } else {
2185 err("i2c read [0x%02x] failed", reg); 2367 err("ovfx2_i2c_r %02x failed %d", reg, ret);
2368 sd->gspca_dev.usb_err = ret;
2369 }
2186 2370
2187 return ret; 2371 return ret;
2188} 2372}
2189 2373
2190static int i2c_w(struct sd *sd, __u8 reg, __u8 value) 2374static void i2c_w(struct sd *sd, u8 reg, u8 value)
2191{ 2375{
2192 int ret = -1;
2193
2194 if (sd->sensor_reg_cache[reg] == value) 2376 if (sd->sensor_reg_cache[reg] == value)
2195 return 0; 2377 return;
2196 2378
2197 switch (sd->bridge) { 2379 switch (sd->bridge) {
2198 case BRIDGE_OV511: 2380 case BRIDGE_OV511:
2199 case BRIDGE_OV511PLUS: 2381 case BRIDGE_OV511PLUS:
2200 ret = ov511_i2c_w(sd, reg, value); 2382 ov511_i2c_w(sd, reg, value);
2201 break; 2383 break;
2202 case BRIDGE_OV518: 2384 case BRIDGE_OV518:
2203 case BRIDGE_OV518PLUS: 2385 case BRIDGE_OV518PLUS:
2204 case BRIDGE_OV519: 2386 case BRIDGE_OV519:
2205 ret = ov518_i2c_w(sd, reg, value); 2387 ov518_i2c_w(sd, reg, value);
2206 break; 2388 break;
2207 case BRIDGE_OVFX2: 2389 case BRIDGE_OVFX2:
2208 ret = ovfx2_i2c_w(sd, reg, value); 2390 ovfx2_i2c_w(sd, reg, value);
2209 break; 2391 break;
2210 case BRIDGE_W9968CF: 2392 case BRIDGE_W9968CF:
2211 ret = w9968cf_i2c_w(sd, reg, value); 2393 w9968cf_i2c_w(sd, reg, value);
2212 break; 2394 break;
2213 } 2395 }
2214 2396
2215 if (ret >= 0) { 2397 if (sd->gspca_dev.usb_err >= 0) {
2216 /* Up on sensor reset empty the register cache */ 2398 /* Up on sensor reset empty the register cache */
2217 if (reg == 0x12 && (value & 0x80)) 2399 if (reg == 0x12 && (value & 0x80))
2218 memset(sd->sensor_reg_cache, -1, 2400 memset(sd->sensor_reg_cache, -1,
2219 sizeof(sd->sensor_reg_cache)); 2401 sizeof(sd->sensor_reg_cache));
2220 else 2402 else
2221 sd->sensor_reg_cache[reg] = value; 2403 sd->sensor_reg_cache[reg] = value;
2222 } 2404 }
2223
2224 return ret;
2225} 2405}
2226 2406
2227static int i2c_r(struct sd *sd, __u8 reg) 2407static int i2c_r(struct sd *sd, u8 reg)
2228{ 2408{
2229 int ret = -1; 2409 int ret = -1;
2230 2410
@@ -2260,95 +2440,99 @@ static int i2c_r(struct sd *sd, __u8 reg)
2260 * that are in the same position as 0's in "mask" are preserved, regardless 2440 * that are in the same position as 0's in "mask" are preserved, regardless
2261 * of their respective state in "value". 2441 * of their respective state in "value".
2262 */ 2442 */
2263static int i2c_w_mask(struct sd *sd, 2443static void i2c_w_mask(struct sd *sd,
2264 __u8 reg, 2444 u8 reg,
2265 __u8 value, 2445 u8 value,
2266 __u8 mask) 2446 u8 mask)
2267{ 2447{
2268 int rc; 2448 int rc;
2269 __u8 oldval; 2449 u8 oldval;
2270 2450
2271 value &= mask; /* Enforce mask on value */ 2451 value &= mask; /* Enforce mask on value */
2272 rc = i2c_r(sd, reg); 2452 rc = i2c_r(sd, reg);
2273 if (rc < 0) 2453 if (rc < 0)
2274 return rc; 2454 return;
2275 oldval = rc & ~mask; /* Clear the masked bits */ 2455 oldval = rc & ~mask; /* Clear the masked bits */
2276 value |= oldval; /* Set the desired bits */ 2456 value |= oldval; /* Set the desired bits */
2277 return i2c_w(sd, reg, value); 2457 i2c_w(sd, reg, value);
2278} 2458}
2279 2459
2280/* Temporarily stops OV511 from functioning. Must do this before changing 2460/* Temporarily stops OV511 from functioning. Must do this before changing
2281 * registers while the camera is streaming */ 2461 * registers while the camera is streaming */
2282static inline int ov51x_stop(struct sd *sd) 2462static inline void ov51x_stop(struct sd *sd)
2283{ 2463{
2284 PDEBUG(D_STREAM, "stopping"); 2464 PDEBUG(D_STREAM, "stopping");
2285 sd->stopped = 1; 2465 sd->stopped = 1;
2286 switch (sd->bridge) { 2466 switch (sd->bridge) {
2287 case BRIDGE_OV511: 2467 case BRIDGE_OV511:
2288 case BRIDGE_OV511PLUS: 2468 case BRIDGE_OV511PLUS:
2289 return reg_w(sd, R51x_SYS_RESET, 0x3d); 2469 reg_w(sd, R51x_SYS_RESET, 0x3d);
2470 break;
2290 case BRIDGE_OV518: 2471 case BRIDGE_OV518:
2291 case BRIDGE_OV518PLUS: 2472 case BRIDGE_OV518PLUS:
2292 return reg_w_mask(sd, R51x_SYS_RESET, 0x3a, 0x3a); 2473 reg_w_mask(sd, R51x_SYS_RESET, 0x3a, 0x3a);
2474 break;
2293 case BRIDGE_OV519: 2475 case BRIDGE_OV519:
2294 return reg_w(sd, OV519_SYS_RESET1, 0x0f); 2476 reg_w(sd, OV519_R51_RESET1, 0x0f);
2477 reg_w(sd, OV519_R51_RESET1, 0x00);
2478 reg_w(sd, 0x22, 0x00); /* FRAR */
2479 break;
2295 case BRIDGE_OVFX2: 2480 case BRIDGE_OVFX2:
2296 return reg_w_mask(sd, 0x0f, 0x00, 0x02); 2481 reg_w_mask(sd, 0x0f, 0x00, 0x02);
2482 break;
2297 case BRIDGE_W9968CF: 2483 case BRIDGE_W9968CF:
2298 return reg_w(sd, 0x3c, 0x0a05); /* stop USB transfer */ 2484 reg_w(sd, 0x3c, 0x0a05); /* stop USB transfer */
2485 break;
2299 } 2486 }
2300
2301 return 0;
2302} 2487}
2303 2488
2304/* Restarts OV511 after ov511_stop() is called. Has no effect if it is not 2489/* Restarts OV511 after ov511_stop() is called. Has no effect if it is not
2305 * actually stopped (for performance). */ 2490 * actually stopped (for performance). */
2306static inline int ov51x_restart(struct sd *sd) 2491static inline void ov51x_restart(struct sd *sd)
2307{ 2492{
2308 int rc;
2309
2310 PDEBUG(D_STREAM, "restarting"); 2493 PDEBUG(D_STREAM, "restarting");
2311 if (!sd->stopped) 2494 if (!sd->stopped)
2312 return 0; 2495 return;
2313 sd->stopped = 0; 2496 sd->stopped = 0;
2314 2497
2315 /* Reinitialize the stream */ 2498 /* Reinitialize the stream */
2316 switch (sd->bridge) { 2499 switch (sd->bridge) {
2317 case BRIDGE_OV511: 2500 case BRIDGE_OV511:
2318 case BRIDGE_OV511PLUS: 2501 case BRIDGE_OV511PLUS:
2319 return reg_w(sd, R51x_SYS_RESET, 0x00); 2502 reg_w(sd, R51x_SYS_RESET, 0x00);
2503 break;
2320 case BRIDGE_OV518: 2504 case BRIDGE_OV518:
2321 case BRIDGE_OV518PLUS: 2505 case BRIDGE_OV518PLUS:
2322 rc = reg_w(sd, 0x2f, 0x80); 2506 reg_w(sd, 0x2f, 0x80);
2323 if (rc < 0) 2507 reg_w(sd, R51x_SYS_RESET, 0x00);
2324 return rc; 2508 break;
2325 return reg_w(sd, R51x_SYS_RESET, 0x00);
2326 case BRIDGE_OV519: 2509 case BRIDGE_OV519:
2327 return reg_w(sd, OV519_SYS_RESET1, 0x00); 2510 reg_w(sd, OV519_R51_RESET1, 0x0f);
2511 reg_w(sd, OV519_R51_RESET1, 0x00);
2512 reg_w(sd, 0x22, 0x1d); /* FRAR */
2513 break;
2328 case BRIDGE_OVFX2: 2514 case BRIDGE_OVFX2:
2329 return reg_w_mask(sd, 0x0f, 0x02, 0x02); 2515 reg_w_mask(sd, 0x0f, 0x02, 0x02);
2516 break;
2330 case BRIDGE_W9968CF: 2517 case BRIDGE_W9968CF:
2331 return reg_w(sd, 0x3c, 0x8a05); /* USB FIFO enable */ 2518 reg_w(sd, 0x3c, 0x8a05); /* USB FIFO enable */
2519 break;
2332 } 2520 }
2333
2334 return 0;
2335} 2521}
2336 2522
2337static int ov51x_set_slave_ids(struct sd *sd, __u8 slave); 2523static void ov51x_set_slave_ids(struct sd *sd, u8 slave);
2338 2524
2339/* This does an initial reset of an OmniVision sensor and ensures that I2C 2525/* This does an initial reset of an OmniVision sensor and ensures that I2C
2340 * is synchronized. Returns <0 on failure. 2526 * is synchronized. Returns <0 on failure.
2341 */ 2527 */
2342static int init_ov_sensor(struct sd *sd, __u8 slave) 2528static int init_ov_sensor(struct sd *sd, u8 slave)
2343{ 2529{
2344 int i; 2530 int i;
2345 2531
2346 if (ov51x_set_slave_ids(sd, slave) < 0) 2532 ov51x_set_slave_ids(sd, slave);
2347 return -EIO;
2348 2533
2349 /* Reset the sensor */ 2534 /* Reset the sensor */
2350 if (i2c_w(sd, 0x12, 0x80) < 0) 2535 i2c_w(sd, 0x12, 0x80);
2351 return -EIO;
2352 2536
2353 /* Wait for it to initialize */ 2537 /* Wait for it to initialize */
2354 msleep(150); 2538 msleep(150);
@@ -2361,15 +2545,16 @@ static int init_ov_sensor(struct sd *sd, __u8 slave)
2361 } 2545 }
2362 2546
2363 /* Reset the sensor */ 2547 /* Reset the sensor */
2364 if (i2c_w(sd, 0x12, 0x80) < 0) 2548 i2c_w(sd, 0x12, 0x80);
2365 return -EIO; 2549
2366 /* Wait for it to initialize */ 2550 /* Wait for it to initialize */
2367 msleep(150); 2551 msleep(150);
2552
2368 /* Dummy read to sync I2C */ 2553 /* Dummy read to sync I2C */
2369 if (i2c_r(sd, 0x00) < 0) 2554 if (i2c_r(sd, 0x00) < 0)
2370 return -EIO; 2555 return -1;
2371 } 2556 }
2372 return -EIO; 2557 return -1;
2373} 2558}
2374 2559
2375/* Set the read and write slave IDs. The "slave" argument is the write slave, 2560/* Set the read and write slave IDs. The "slave" argument is the write slave,
@@ -2377,53 +2562,40 @@ static int init_ov_sensor(struct sd *sd, __u8 slave)
2377 * This should not be called from outside the i2c I/O functions. 2562 * This should not be called from outside the i2c I/O functions.
2378 * Sets I2C read and write slave IDs. Returns <0 for error 2563 * Sets I2C read and write slave IDs. Returns <0 for error
2379 */ 2564 */
2380static int ov51x_set_slave_ids(struct sd *sd, 2565static void ov51x_set_slave_ids(struct sd *sd,
2381 __u8 slave) 2566 u8 slave)
2382{ 2567{
2383 int rc;
2384
2385 switch (sd->bridge) { 2568 switch (sd->bridge) {
2386 case BRIDGE_OVFX2: 2569 case BRIDGE_OVFX2:
2387 return reg_w(sd, OVFX2_I2C_ADDR, slave); 2570 reg_w(sd, OVFX2_I2C_ADDR, slave);
2571 return;
2388 case BRIDGE_W9968CF: 2572 case BRIDGE_W9968CF:
2389 sd->sensor_addr = slave; 2573 sd->sensor_addr = slave;
2390 return 0; 2574 return;
2391 } 2575 }
2392 2576
2393 rc = reg_w(sd, R51x_I2C_W_SID, slave); 2577 reg_w(sd, R51x_I2C_W_SID, slave);
2394 if (rc < 0) 2578 reg_w(sd, R51x_I2C_R_SID, slave + 1);
2395 return rc;
2396 return reg_w(sd, R51x_I2C_R_SID, slave + 1);
2397} 2579}
2398 2580
2399static int write_regvals(struct sd *sd, 2581static void write_regvals(struct sd *sd,
2400 const struct ov_regvals *regvals, 2582 const struct ov_regvals *regvals,
2401 int n) 2583 int n)
2402{ 2584{
2403 int rc;
2404
2405 while (--n >= 0) { 2585 while (--n >= 0) {
2406 rc = reg_w(sd, regvals->reg, regvals->val); 2586 reg_w(sd, regvals->reg, regvals->val);
2407 if (rc < 0)
2408 return rc;
2409 regvals++; 2587 regvals++;
2410 } 2588 }
2411 return 0;
2412} 2589}
2413 2590
2414static int write_i2c_regvals(struct sd *sd, 2591static void write_i2c_regvals(struct sd *sd,
2415 const struct ov_i2c_regvals *regvals, 2592 const struct ov_i2c_regvals *regvals,
2416 int n) 2593 int n)
2417{ 2594{
2418 int rc;
2419
2420 while (--n >= 0) { 2595 while (--n >= 0) {
2421 rc = i2c_w(sd, regvals->reg, regvals->val); 2596 i2c_w(sd, regvals->reg, regvals->val);
2422 if (rc < 0)
2423 return rc;
2424 regvals++; 2597 regvals++;
2425 } 2598 }
2426 return 0;
2427} 2599}
2428 2600
2429/**************************************************************************** 2601/****************************************************************************
@@ -2433,13 +2605,13 @@ static int write_i2c_regvals(struct sd *sd,
2433 ***************************************************************************/ 2605 ***************************************************************************/
2434 2606
2435/* This initializes the OV2x10 / OV3610 / OV3620 */ 2607/* This initializes the OV2x10 / OV3610 / OV3620 */
2436static int ov_hires_configure(struct sd *sd) 2608static void ov_hires_configure(struct sd *sd)
2437{ 2609{
2438 int high, low; 2610 int high, low;
2439 2611
2440 if (sd->bridge != BRIDGE_OVFX2) { 2612 if (sd->bridge != BRIDGE_OVFX2) {
2441 err("error hires sensors only supported with ovfx2"); 2613 err("error hires sensors only supported with ovfx2");
2442 return -1; 2614 return;
2443 } 2615 }
2444 2616
2445 PDEBUG(D_PROBE, "starting ov hires configuration"); 2617 PDEBUG(D_PROBE, "starting ov hires configuration");
@@ -2455,20 +2627,15 @@ static int ov_hires_configure(struct sd *sd)
2455 PDEBUG(D_PROBE, "Sensor is an OV3610"); 2627 PDEBUG(D_PROBE, "Sensor is an OV3610");
2456 sd->sensor = SEN_OV3610; 2628 sd->sensor = SEN_OV3610;
2457 } else { 2629 } else {
2458 err("Error unknown sensor type: 0x%02x%02x", 2630 err("Error unknown sensor type: %02x%02x",
2459 high, low); 2631 high, low);
2460 return -1;
2461 } 2632 }
2462
2463 /* Set sensor-specific vars */
2464 return 0;
2465} 2633}
2466 2634
2467
2468/* This initializes the OV8110, OV8610 sensor. The OV8110 uses 2635/* This initializes the OV8110, OV8610 sensor. The OV8110 uses
2469 * the same register settings as the OV8610, since they are very similar. 2636 * the same register settings as the OV8610, since they are very similar.
2470 */ 2637 */
2471static int ov8xx0_configure(struct sd *sd) 2638static void ov8xx0_configure(struct sd *sd)
2472{ 2639{
2473 int rc; 2640 int rc;
2474 2641
@@ -2478,27 +2645,21 @@ static int ov8xx0_configure(struct sd *sd)
2478 rc = i2c_r(sd, OV7610_REG_COM_I); 2645 rc = i2c_r(sd, OV7610_REG_COM_I);
2479 if (rc < 0) { 2646 if (rc < 0) {
2480 PDEBUG(D_ERR, "Error detecting sensor type"); 2647 PDEBUG(D_ERR, "Error detecting sensor type");
2481 return -1; 2648 return;
2482 } 2649 }
2483 if ((rc & 3) == 1) { 2650 if ((rc & 3) == 1)
2484 sd->sensor = SEN_OV8610; 2651 sd->sensor = SEN_OV8610;
2485 } else { 2652 else
2486 err("Unknown image sensor version: %d", rc & 3); 2653 err("Unknown image sensor version: %d", rc & 3);
2487 return -1;
2488 }
2489
2490 /* Set sensor-specific vars */
2491 return 0;
2492} 2654}
2493 2655
2494/* This initializes the OV7610, OV7620, or OV76BE sensor. The OV76BE uses 2656/* This initializes the OV7610, OV7620, or OV76BE sensor. The OV76BE uses
2495 * the same register settings as the OV7610, since they are very similar. 2657 * the same register settings as the OV7610, since they are very similar.
2496 */ 2658 */
2497static int ov7xx0_configure(struct sd *sd) 2659static void ov7xx0_configure(struct sd *sd)
2498{ 2660{
2499 int rc, high, low; 2661 int rc, high, low;
2500 2662
2501
2502 PDEBUG(D_PROBE, "starting OV7xx0 configuration"); 2663 PDEBUG(D_PROBE, "starting OV7xx0 configuration");
2503 2664
2504 /* Detect sensor (sub)type */ 2665 /* Detect sensor (sub)type */
@@ -2508,15 +2669,15 @@ static int ov7xx0_configure(struct sd *sd)
2508 * it appears to be wrongly detected as a 7610 by default */ 2669 * it appears to be wrongly detected as a 7610 by default */
2509 if (rc < 0) { 2670 if (rc < 0) {
2510 PDEBUG(D_ERR, "Error detecting sensor type"); 2671 PDEBUG(D_ERR, "Error detecting sensor type");
2511 return -1; 2672 return;
2512 } 2673 }
2513 if ((rc & 3) == 3) { 2674 if ((rc & 3) == 3) {
2514 /* quick hack to make OV7670s work */ 2675 /* quick hack to make OV7670s work */
2515 high = i2c_r(sd, 0x0a); 2676 high = i2c_r(sd, 0x0a);
2516 low = i2c_r(sd, 0x0b); 2677 low = i2c_r(sd, 0x0b);
2517 /* info("%x, %x", high, low); */ 2678 /* info("%x, %x", high, low); */
2518 if (high == 0x76 && low == 0x73) { 2679 if (high == 0x76 && (low & 0xf0) == 0x70) {
2519 PDEBUG(D_PROBE, "Sensor is an OV7670"); 2680 PDEBUG(D_PROBE, "Sensor is an OV76%02x", low);
2520 sd->sensor = SEN_OV7670; 2681 sd->sensor = SEN_OV7670;
2521 } else { 2682 } else {
2522 PDEBUG(D_PROBE, "Sensor is an OV7610"); 2683 PDEBUG(D_PROBE, "Sensor is an OV7610");
@@ -2536,19 +2697,19 @@ static int ov7xx0_configure(struct sd *sd)
2536 high = i2c_r(sd, 0x0a); 2697 high = i2c_r(sd, 0x0a);
2537 if (high < 0) { 2698 if (high < 0) {
2538 PDEBUG(D_ERR, "Error detecting camera chip PID"); 2699 PDEBUG(D_ERR, "Error detecting camera chip PID");
2539 return high; 2700 return;
2540 } 2701 }
2541 low = i2c_r(sd, 0x0b); 2702 low = i2c_r(sd, 0x0b);
2542 if (low < 0) { 2703 if (low < 0) {
2543 PDEBUG(D_ERR, "Error detecting camera chip VER"); 2704 PDEBUG(D_ERR, "Error detecting camera chip VER");
2544 return low; 2705 return;
2545 } 2706 }
2546 if (high == 0x76) { 2707 if (high == 0x76) {
2547 switch (low) { 2708 switch (low) {
2548 case 0x30: 2709 case 0x30:
2549 err("Sensor is an OV7630/OV7635"); 2710 err("Sensor is an OV7630/OV7635");
2550 err("7630 is not supported by this driver"); 2711 err("7630 is not supported by this driver");
2551 return -1; 2712 return;
2552 case 0x40: 2713 case 0x40:
2553 PDEBUG(D_PROBE, "Sensor is an OV7645"); 2714 PDEBUG(D_PROBE, "Sensor is an OV7645");
2554 sd->sensor = SEN_OV7640; /* FIXME */ 2715 sd->sensor = SEN_OV7640; /* FIXME */
@@ -2561,9 +2722,14 @@ static int ov7xx0_configure(struct sd *sd)
2561 PDEBUG(D_PROBE, "Sensor is an OV7648"); 2722 PDEBUG(D_PROBE, "Sensor is an OV7648");
2562 sd->sensor = SEN_OV7648; 2723 sd->sensor = SEN_OV7648;
2563 break; 2724 break;
2725 case 0x60:
2726 PDEBUG(D_PROBE, "Sensor is a OV7660");
2727 sd->sensor = SEN_OV7660;
2728 sd->invert_led = 0;
2729 break;
2564 default: 2730 default:
2565 PDEBUG(D_PROBE, "Unknown sensor: 0x76%x", low); 2731 PDEBUG(D_PROBE, "Unknown sensor: 0x76%x", low);
2566 return -1; 2732 return;
2567 } 2733 }
2568 } else { 2734 } else {
2569 PDEBUG(D_PROBE, "Sensor is an OV7620"); 2735 PDEBUG(D_PROBE, "Sensor is an OV7620");
@@ -2571,15 +2737,11 @@ static int ov7xx0_configure(struct sd *sd)
2571 } 2737 }
2572 } else { 2738 } else {
2573 err("Unknown image sensor version: %d", rc & 3); 2739 err("Unknown image sensor version: %d", rc & 3);
2574 return -1;
2575 } 2740 }
2576
2577 /* Set sensor-specific vars */
2578 return 0;
2579} 2741}
2580 2742
2581/* This initializes the OV6620, OV6630, OV6630AE, or OV6630AF sensor. */ 2743/* This initializes the OV6620, OV6630, OV6630AE, or OV6630AF sensor. */
2582static int ov6xx0_configure(struct sd *sd) 2744static void ov6xx0_configure(struct sd *sd)
2583{ 2745{
2584 int rc; 2746 int rc;
2585 PDEBUG(D_PROBE, "starting OV6xx0 configuration"); 2747 PDEBUG(D_PROBE, "starting OV6xx0 configuration");
@@ -2588,7 +2750,7 @@ static int ov6xx0_configure(struct sd *sd)
2588 rc = i2c_r(sd, OV7610_REG_COM_I); 2750 rc = i2c_r(sd, OV7610_REG_COM_I);
2589 if (rc < 0) { 2751 if (rc < 0) {
2590 PDEBUG(D_ERR, "Error detecting sensor type"); 2752 PDEBUG(D_ERR, "Error detecting sensor type");
2591 return -1; 2753 return;
2592 } 2754 }
2593 2755
2594 /* Ugh. The first two bits are the version bits, but 2756 /* Ugh. The first two bits are the version bits, but
@@ -2619,13 +2781,11 @@ static int ov6xx0_configure(struct sd *sd)
2619 break; 2781 break;
2620 default: 2782 default:
2621 err("FATAL: Unknown sensor version: 0x%02x", rc); 2783 err("FATAL: Unknown sensor version: 0x%02x", rc);
2622 return -1; 2784 return;
2623 } 2785 }
2624 2786
2625 /* Set sensor-specific vars */ 2787 /* Set sensor-specific vars */
2626 sd->sif = 1; 2788 sd->sif = 1;
2627
2628 return 0;
2629} 2789}
2630 2790
2631/* Turns on or off the LED. Only has an effect with OV511+/OV518(+)/OV519 */ 2791/* Turns on or off the LED. Only has an effect with OV511+/OV518(+)/OV519 */
@@ -2637,14 +2797,14 @@ static void ov51x_led_control(struct sd *sd, int on)
2637 switch (sd->bridge) { 2797 switch (sd->bridge) {
2638 /* OV511 has no LED control */ 2798 /* OV511 has no LED control */
2639 case BRIDGE_OV511PLUS: 2799 case BRIDGE_OV511PLUS:
2640 reg_w(sd, R511_SYS_LED_CTL, on ? 1 : 0); 2800 reg_w(sd, R511_SYS_LED_CTL, on);
2641 break; 2801 break;
2642 case BRIDGE_OV518: 2802 case BRIDGE_OV518:
2643 case BRIDGE_OV518PLUS: 2803 case BRIDGE_OV518PLUS:
2644 reg_w_mask(sd, R518_GPIO_OUT, on ? 0x02 : 0x00, 0x02); 2804 reg_w_mask(sd, R518_GPIO_OUT, 0x02 * on, 0x02);
2645 break; 2805 break;
2646 case BRIDGE_OV519: 2806 case BRIDGE_OV519:
2647 reg_w_mask(sd, OV519_GPIO_DATA_OUT0, !on, 1); /* 0 / 1 */ 2807 reg_w_mask(sd, OV519_GPIO_DATA_OUT0, on, 1);
2648 break; 2808 break;
2649 } 2809 }
2650} 2810}
@@ -2679,7 +2839,7 @@ static void sd_reset_snapshot(struct gspca_dev *gspca_dev)
2679 } 2839 }
2680} 2840}
2681 2841
2682static int ov51x_upload_quan_tables(struct sd *sd) 2842static void ov51x_upload_quan_tables(struct sd *sd)
2683{ 2843{
2684 const unsigned char yQuanTable511[] = { 2844 const unsigned char yQuanTable511[] = {
2685 0, 1, 1, 2, 2, 3, 3, 4, 2845 0, 1, 1, 2, 2, 3, 3, 4,
@@ -2710,7 +2870,6 @@ static int ov51x_upload_quan_tables(struct sd *sd)
2710 6, 6, 6, 6, 7, 7, 7, 8, 2870 6, 6, 6, 6, 7, 7, 7, 8,
2711 7, 7, 6, 7, 7, 7, 8, 8 2871 7, 7, 6, 7, 7, 7, 8, 8
2712 }; 2872 };
2713
2714 const unsigned char uvQuanTable518[] = { 2873 const unsigned char uvQuanTable518[] = {
2715 6, 6, 6, 7, 7, 7, 7, 7, 2874 6, 6, 6, 7, 7, 7, 7, 7,
2716 6, 6, 6, 7, 7, 7, 7, 7, 2875 6, 6, 6, 7, 7, 7, 7, 7,
@@ -2720,18 +2879,18 @@ static int ov51x_upload_quan_tables(struct sd *sd)
2720 2879
2721 const unsigned char *pYTable, *pUVTable; 2880 const unsigned char *pYTable, *pUVTable;
2722 unsigned char val0, val1; 2881 unsigned char val0, val1;
2723 int i, size, rc, reg = R51x_COMP_LUT_BEGIN; 2882 int i, size, reg = R51x_COMP_LUT_BEGIN;
2724 2883
2725 PDEBUG(D_PROBE, "Uploading quantization tables"); 2884 PDEBUG(D_PROBE, "Uploading quantization tables");
2726 2885
2727 if (sd->bridge == BRIDGE_OV511 || sd->bridge == BRIDGE_OV511PLUS) { 2886 if (sd->bridge == BRIDGE_OV511 || sd->bridge == BRIDGE_OV511PLUS) {
2728 pYTable = yQuanTable511; 2887 pYTable = yQuanTable511;
2729 pUVTable = uvQuanTable511; 2888 pUVTable = uvQuanTable511;
2730 size = 32; 2889 size = 32;
2731 } else { 2890 } else {
2732 pYTable = yQuanTable518; 2891 pYTable = yQuanTable518;
2733 pUVTable = uvQuanTable518; 2892 pUVTable = uvQuanTable518;
2734 size = 16; 2893 size = 16;
2735 } 2894 }
2736 2895
2737 for (i = 0; i < size; i++) { 2896 for (i = 0; i < size; i++) {
@@ -2740,30 +2899,23 @@ static int ov51x_upload_quan_tables(struct sd *sd)
2740 val0 &= 0x0f; 2899 val0 &= 0x0f;
2741 val1 &= 0x0f; 2900 val1 &= 0x0f;
2742 val0 |= val1 << 4; 2901 val0 |= val1 << 4;
2743 rc = reg_w(sd, reg, val0); 2902 reg_w(sd, reg, val0);
2744 if (rc < 0)
2745 return rc;
2746 2903
2747 val0 = *pUVTable++; 2904 val0 = *pUVTable++;
2748 val1 = *pUVTable++; 2905 val1 = *pUVTable++;
2749 val0 &= 0x0f; 2906 val0 &= 0x0f;
2750 val1 &= 0x0f; 2907 val1 &= 0x0f;
2751 val0 |= val1 << 4; 2908 val0 |= val1 << 4;
2752 rc = reg_w(sd, reg + size, val0); 2909 reg_w(sd, reg + size, val0);
2753 if (rc < 0)
2754 return rc;
2755 2910
2756 reg++; 2911 reg++;
2757 } 2912 }
2758
2759 return 0;
2760} 2913}
2761 2914
2762/* This initializes the OV511/OV511+ and the sensor */ 2915/* This initializes the OV511/OV511+ and the sensor */
2763static int ov511_configure(struct gspca_dev *gspca_dev) 2916static void ov511_configure(struct gspca_dev *gspca_dev)
2764{ 2917{
2765 struct sd *sd = (struct sd *) gspca_dev; 2918 struct sd *sd = (struct sd *) gspca_dev;
2766 int rc;
2767 2919
2768 /* For 511 and 511+ */ 2920 /* For 511 and 511+ */
2769 const struct ov_regvals init_511[] = { 2921 const struct ov_regvals init_511[] = {
@@ -2809,42 +2961,27 @@ static int ov511_configure(struct gspca_dev *gspca_dev)
2809 2961
2810 PDEBUG(D_PROBE, "Device custom id %x", reg_r(sd, R51x_SYS_CUST_ID)); 2962 PDEBUG(D_PROBE, "Device custom id %x", reg_r(sd, R51x_SYS_CUST_ID));
2811 2963
2812 rc = write_regvals(sd, init_511, ARRAY_SIZE(init_511)); 2964 write_regvals(sd, init_511, ARRAY_SIZE(init_511));
2813 if (rc < 0)
2814 return rc;
2815 2965
2816 switch (sd->bridge) { 2966 switch (sd->bridge) {
2817 case BRIDGE_OV511: 2967 case BRIDGE_OV511:
2818 rc = write_regvals(sd, norm_511, ARRAY_SIZE(norm_511)); 2968 write_regvals(sd, norm_511, ARRAY_SIZE(norm_511));
2819 if (rc < 0)
2820 return rc;
2821 break; 2969 break;
2822 case BRIDGE_OV511PLUS: 2970 case BRIDGE_OV511PLUS:
2823 rc = write_regvals(sd, norm_511_p, ARRAY_SIZE(norm_511_p)); 2971 write_regvals(sd, norm_511_p, ARRAY_SIZE(norm_511_p));
2824 if (rc < 0)
2825 return rc;
2826 break; 2972 break;
2827 } 2973 }
2828 2974
2829 /* Init compression */ 2975 /* Init compression */
2830 rc = write_regvals(sd, compress_511, ARRAY_SIZE(compress_511)); 2976 write_regvals(sd, compress_511, ARRAY_SIZE(compress_511));
2831 if (rc < 0)
2832 return rc;
2833
2834 rc = ov51x_upload_quan_tables(sd);
2835 if (rc < 0) {
2836 PDEBUG(D_ERR, "Error uploading quantization tables");
2837 return rc;
2838 }
2839 2977
2840 return 0; 2978 ov51x_upload_quan_tables(sd);
2841} 2979}
2842 2980
2843/* This initializes the OV518/OV518+ and the sensor */ 2981/* This initializes the OV518/OV518+ and the sensor */
2844static int ov518_configure(struct gspca_dev *gspca_dev) 2982static void ov518_configure(struct gspca_dev *gspca_dev)
2845{ 2983{
2846 struct sd *sd = (struct sd *) gspca_dev; 2984 struct sd *sd = (struct sd *) gspca_dev;
2847 int rc;
2848 2985
2849 /* For 518 and 518+ */ 2986 /* For 518 and 518+ */
2850 const struct ov_regvals init_518[] = { 2987 const struct ov_regvals init_518[] = {
@@ -2892,65 +3029,49 @@ static int ov518_configure(struct gspca_dev *gspca_dev)
2892 3029
2893 /* First 5 bits of custom ID reg are a revision ID on OV518 */ 3030 /* First 5 bits of custom ID reg are a revision ID on OV518 */
2894 PDEBUG(D_PROBE, "Device revision %d", 3031 PDEBUG(D_PROBE, "Device revision %d",
2895 0x1F & reg_r(sd, R51x_SYS_CUST_ID)); 3032 0x1f & reg_r(sd, R51x_SYS_CUST_ID));
2896 3033
2897 rc = write_regvals(sd, init_518, ARRAY_SIZE(init_518)); 3034 write_regvals(sd, init_518, ARRAY_SIZE(init_518));
2898 if (rc < 0)
2899 return rc;
2900 3035
2901 /* Set LED GPIO pin to output mode */ 3036 /* Set LED GPIO pin to output mode */
2902 rc = reg_w_mask(sd, R518_GPIO_CTL, 0x00, 0x02); 3037 reg_w_mask(sd, R518_GPIO_CTL, 0x00, 0x02);
2903 if (rc < 0)
2904 return rc;
2905 3038
2906 switch (sd->bridge) { 3039 switch (sd->bridge) {
2907 case BRIDGE_OV518: 3040 case BRIDGE_OV518:
2908 rc = write_regvals(sd, norm_518, ARRAY_SIZE(norm_518)); 3041 write_regvals(sd, norm_518, ARRAY_SIZE(norm_518));
2909 if (rc < 0)
2910 return rc;
2911 break; 3042 break;
2912 case BRIDGE_OV518PLUS: 3043 case BRIDGE_OV518PLUS:
2913 rc = write_regvals(sd, norm_518_p, ARRAY_SIZE(norm_518_p)); 3044 write_regvals(sd, norm_518_p, ARRAY_SIZE(norm_518_p));
2914 if (rc < 0)
2915 return rc;
2916 break; 3045 break;
2917 } 3046 }
2918 3047
2919 rc = ov51x_upload_quan_tables(sd); 3048 ov51x_upload_quan_tables(sd);
2920 if (rc < 0) {
2921 PDEBUG(D_ERR, "Error uploading quantization tables");
2922 return rc;
2923 }
2924 3049
2925 rc = reg_w(sd, 0x2f, 0x80); 3050 reg_w(sd, 0x2f, 0x80);
2926 if (rc < 0)
2927 return rc;
2928
2929 return 0;
2930} 3051}
2931 3052
2932static int ov519_configure(struct sd *sd) 3053static void ov519_configure(struct sd *sd)
2933{ 3054{
2934 static const struct ov_regvals init_519[] = { 3055 static const struct ov_regvals init_519[] = {
2935 { 0x5a, 0x6d }, /* EnableSystem */ 3056 { 0x5a, 0x6d }, /* EnableSystem */
2936 { 0x53, 0x9b }, 3057 { 0x53, 0x9b },
2937 { 0x54, 0xff }, /* set bit2 to enable jpeg */ 3058 { OV519_R54_EN_CLK1, 0xff }, /* set bit2 to enable jpeg */
2938 { 0x5d, 0x03 }, 3059 { 0x5d, 0x03 },
2939 { 0x49, 0x01 }, 3060 { 0x49, 0x01 },
2940 { 0x48, 0x00 }, 3061 { 0x48, 0x00 },
2941 /* Set LED pin to output mode. Bit 4 must be cleared or sensor 3062 /* Set LED pin to output mode. Bit 4 must be cleared or sensor
2942 * detection will fail. This deserves further investigation. */ 3063 * detection will fail. This deserves further investigation. */
2943 { OV519_GPIO_IO_CTRL0, 0xee }, 3064 { OV519_GPIO_IO_CTRL0, 0xee },
2944 { 0x51, 0x0f }, /* SetUsbInit */ 3065 { OV519_R51_RESET1, 0x0f },
2945 { 0x51, 0x00 }, 3066 { OV519_R51_RESET1, 0x00 },
2946 { 0x22, 0x00 }, 3067 { 0x22, 0x00 },
2947 /* windows reads 0x55 at this point*/ 3068 /* windows reads 0x55 at this point*/
2948 }; 3069 };
2949 3070
2950 return write_regvals(sd, init_519, ARRAY_SIZE(init_519)); 3071 write_regvals(sd, init_519, ARRAY_SIZE(init_519));
2951} 3072}
2952 3073
2953static int ovfx2_configure(struct sd *sd) 3074static void ovfx2_configure(struct sd *sd)
2954{ 3075{
2955 static const struct ov_regvals init_fx2[] = { 3076 static const struct ov_regvals init_fx2[] = {
2956 { 0x00, 0x60 }, 3077 { 0x00, 0x60 },
@@ -2964,7 +3085,92 @@ static int ovfx2_configure(struct sd *sd)
2964 3085
2965 sd->stopped = 1; 3086 sd->stopped = 1;
2966 3087
2967 return write_regvals(sd, init_fx2, ARRAY_SIZE(init_fx2)); 3088 write_regvals(sd, init_fx2, ARRAY_SIZE(init_fx2));
3089}
3090
3091/* set the mode */
3092/* This function works for ov7660 only */
3093static void ov519_set_mode(struct sd *sd)
3094{
3095 static const struct ov_regvals bridge_ov7660[2][10] = {
3096 {{0x10, 0x14}, {0x11, 0x1e}, {0x12, 0x00}, {0x13, 0x00},
3097 {0x14, 0x00}, {0x15, 0x00}, {0x16, 0x00}, {0x20, 0x0c},
3098 {0x25, 0x01}, {0x26, 0x00}},
3099 {{0x10, 0x28}, {0x11, 0x3c}, {0x12, 0x00}, {0x13, 0x00},
3100 {0x14, 0x00}, {0x15, 0x00}, {0x16, 0x00}, {0x20, 0x0c},
3101 {0x25, 0x03}, {0x26, 0x00}}
3102 };
3103 static const struct ov_i2c_regvals sensor_ov7660[2][3] = {
3104 {{0x12, 0x00}, {0x24, 0x00}, {0x0c, 0x0c}},
3105 {{0x12, 0x00}, {0x04, 0x00}, {0x0c, 0x00}}
3106 };
3107 static const struct ov_i2c_regvals sensor_ov7660_2[] = {
3108 {OV7670_R17_HSTART, 0x13},
3109 {OV7670_R18_HSTOP, 0x01},
3110 {OV7670_R32_HREF, 0x92},
3111 {OV7670_R19_VSTART, 0x02},
3112 {OV7670_R1A_VSTOP, 0x7a},
3113 {OV7670_R03_VREF, 0x00},
3114/* {0x33, 0x00}, */
3115/* {0x34, 0x07}, */
3116/* {0x36, 0x00}, */
3117/* {0x6b, 0x0a}, */
3118 };
3119
3120 write_regvals(sd, bridge_ov7660[sd->gspca_dev.curr_mode],
3121 ARRAY_SIZE(bridge_ov7660[0]));
3122 write_i2c_regvals(sd, sensor_ov7660[sd->gspca_dev.curr_mode],
3123 ARRAY_SIZE(sensor_ov7660[0]));
3124 write_i2c_regvals(sd, sensor_ov7660_2,
3125 ARRAY_SIZE(sensor_ov7660_2));
3126}
3127
3128/* set the frame rate */
3129/* This function works for sensors ov7640, ov7648 ov7660 and ov7670 only */
3130static void ov519_set_fr(struct sd *sd)
3131{
3132 int fr;
3133 u8 clock;
3134 /* frame rate table with indices:
3135 * - mode = 0: 320x240, 1: 640x480
3136 * - fr rate = 0: 30, 1: 25, 2: 20, 3: 15, 4: 10, 5: 5
3137 * - reg = 0: bridge a4, 1: bridge 23, 2: sensor 11 (clock)
3138 */
3139 static const u8 fr_tb[2][6][3] = {
3140 {{0x04, 0xff, 0x00},
3141 {0x04, 0x1f, 0x00},
3142 {0x04, 0x1b, 0x00},
3143 {0x04, 0x15, 0x00},
3144 {0x04, 0x09, 0x00},
3145 {0x04, 0x01, 0x00}},
3146 {{0x0c, 0xff, 0x00},
3147 {0x0c, 0x1f, 0x00},
3148 {0x0c, 0x1b, 0x00},
3149 {0x04, 0xff, 0x01},
3150 {0x04, 0x1f, 0x01},
3151 {0x04, 0x1b, 0x01}},
3152 };
3153
3154 if (frame_rate > 0)
3155 sd->frame_rate = frame_rate;
3156 if (sd->frame_rate >= 30)
3157 fr = 0;
3158 else if (sd->frame_rate >= 25)
3159 fr = 1;
3160 else if (sd->frame_rate >= 20)
3161 fr = 2;
3162 else if (sd->frame_rate >= 15)
3163 fr = 3;
3164 else if (sd->frame_rate >= 10)
3165 fr = 4;
3166 else
3167 fr = 5;
3168 reg_w(sd, 0xa4, fr_tb[sd->gspca_dev.curr_mode][fr][0]);
3169 reg_w(sd, 0x23, fr_tb[sd->gspca_dev.curr_mode][fr][1]);
3170 clock = fr_tb[sd->gspca_dev.curr_mode][fr][2];
3171 if (sd->sensor == SEN_OV7660)
3172 clock |= 0x80; /* enable double clock */
3173 ov518_i2c_w(sd, OV7670_R11_CLKRC, clock);
2968} 3174}
2969 3175
2970/* this function is called at probe time */ 3176/* this function is called at probe time */
@@ -2973,99 +3179,119 @@ static int sd_config(struct gspca_dev *gspca_dev,
2973{ 3179{
2974 struct sd *sd = (struct sd *) gspca_dev; 3180 struct sd *sd = (struct sd *) gspca_dev;
2975 struct cam *cam = &gspca_dev->cam; 3181 struct cam *cam = &gspca_dev->cam;
2976 int ret = 0;
2977 3182
2978 sd->bridge = id->driver_info & BRIDGE_MASK; 3183 sd->bridge = id->driver_info & BRIDGE_MASK;
2979 sd->invert_led = id->driver_info & BRIDGE_INVERT_LED; 3184 sd->invert_led = (id->driver_info & BRIDGE_INVERT_LED) != 0;
2980 3185
2981 switch (sd->bridge) { 3186 switch (sd->bridge) {
2982 case BRIDGE_OV511: 3187 case BRIDGE_OV511:
2983 case BRIDGE_OV511PLUS: 3188 case BRIDGE_OV511PLUS:
2984 ret = ov511_configure(gspca_dev); 3189 cam->cam_mode = ov511_vga_mode;
3190 cam->nmodes = ARRAY_SIZE(ov511_vga_mode);
2985 break; 3191 break;
2986 case BRIDGE_OV518: 3192 case BRIDGE_OV518:
2987 case BRIDGE_OV518PLUS: 3193 case BRIDGE_OV518PLUS:
2988 ret = ov518_configure(gspca_dev); 3194 cam->cam_mode = ov518_vga_mode;
3195 cam->nmodes = ARRAY_SIZE(ov518_vga_mode);
2989 break; 3196 break;
2990 case BRIDGE_OV519: 3197 case BRIDGE_OV519:
2991 ret = ov519_configure(sd); 3198 cam->cam_mode = ov519_vga_mode;
3199 cam->nmodes = ARRAY_SIZE(ov519_vga_mode);
3200 sd->invert_led = !sd->invert_led;
2992 break; 3201 break;
2993 case BRIDGE_OVFX2: 3202 case BRIDGE_OVFX2:
2994 ret = ovfx2_configure(sd); 3203 cam->cam_mode = ov519_vga_mode;
3204 cam->nmodes = ARRAY_SIZE(ov519_vga_mode);
2995 cam->bulk_size = OVFX2_BULK_SIZE; 3205 cam->bulk_size = OVFX2_BULK_SIZE;
2996 cam->bulk_nurbs = MAX_NURBS; 3206 cam->bulk_nurbs = MAX_NURBS;
2997 cam->bulk = 1; 3207 cam->bulk = 1;
2998 break; 3208 break;
2999 case BRIDGE_W9968CF: 3209 case BRIDGE_W9968CF:
3000 ret = w9968cf_configure(sd); 3210 cam->cam_mode = w9968cf_vga_mode;
3211 cam->nmodes = ARRAY_SIZE(w9968cf_vga_mode);
3001 cam->reverse_alts = 1; 3212 cam->reverse_alts = 1;
3002 break; 3213 break;
3003 } 3214 }
3004 3215
3005 if (ret) 3216 gspca_dev->cam.ctrls = sd->ctrls;
3006 goto error; 3217 sd->quality = QUALITY_DEF;
3007 3218
3008 ov51x_led_control(sd, 0); /* turn LED off */ 3219 return 0;
3220}
3221
3222/* this function is called at probe and resume time */
3223static int sd_init(struct gspca_dev *gspca_dev)
3224{
3225 struct sd *sd = (struct sd *) gspca_dev;
3226 struct cam *cam = &gspca_dev->cam;
3227
3228 switch (sd->bridge) {
3229 case BRIDGE_OV511:
3230 case BRIDGE_OV511PLUS:
3231 ov511_configure(gspca_dev);
3232 break;
3233 case BRIDGE_OV518:
3234 case BRIDGE_OV518PLUS:
3235 ov518_configure(gspca_dev);
3236 break;
3237 case BRIDGE_OV519:
3238 ov519_configure(sd);
3239 break;
3240 case BRIDGE_OVFX2:
3241 ovfx2_configure(sd);
3242 break;
3243 case BRIDGE_W9968CF:
3244 w9968cf_configure(sd);
3245 break;
3246 }
3009 3247
3010 /* The OV519 must be more aggressive about sensor detection since 3248 /* The OV519 must be more aggressive about sensor detection since
3011 * I2C write will never fail if the sensor is not present. We have 3249 * I2C write will never fail if the sensor is not present. We have
3012 * to try to initialize the sensor to detect its presence */ 3250 * to try to initialize the sensor to detect its presence */
3251 sd->sensor = -1;
3013 3252
3014 /* Test for 76xx */ 3253 /* Test for 76xx */
3015 if (init_ov_sensor(sd, OV7xx0_SID) >= 0) { 3254 if (init_ov_sensor(sd, OV7xx0_SID) >= 0) {
3016 if (ov7xx0_configure(sd) < 0) { 3255 ov7xx0_configure(sd);
3017 PDEBUG(D_ERR, "Failed to configure OV7xx0"); 3256
3018 goto error;
3019 }
3020 /* Test for 6xx0 */ 3257 /* Test for 6xx0 */
3021 } else if (init_ov_sensor(sd, OV6xx0_SID) >= 0) { 3258 } else if (init_ov_sensor(sd, OV6xx0_SID) >= 0) {
3022 if (ov6xx0_configure(sd) < 0) { 3259 ov6xx0_configure(sd);
3023 PDEBUG(D_ERR, "Failed to configure OV6xx0"); 3260
3024 goto error;
3025 }
3026 /* Test for 8xx0 */ 3261 /* Test for 8xx0 */
3027 } else if (init_ov_sensor(sd, OV8xx0_SID) >= 0) { 3262 } else if (init_ov_sensor(sd, OV8xx0_SID) >= 0) {
3028 if (ov8xx0_configure(sd) < 0) { 3263 ov8xx0_configure(sd);
3029 PDEBUG(D_ERR, "Failed to configure OV8xx0"); 3264
3030 goto error;
3031 }
3032 /* Test for 3xxx / 2xxx */ 3265 /* Test for 3xxx / 2xxx */
3033 } else if (init_ov_sensor(sd, OV_HIRES_SID) >= 0) { 3266 } else if (init_ov_sensor(sd, OV_HIRES_SID) >= 0) {
3034 if (ov_hires_configure(sd) < 0) { 3267 ov_hires_configure(sd);
3035 PDEBUG(D_ERR, "Failed to configure high res OV");
3036 goto error;
3037 }
3038 } else { 3268 } else {
3039 err("Can't determine sensor slave IDs"); 3269 err("Can't determine sensor slave IDs");
3040 goto error; 3270 goto error;
3041 } 3271 }
3042 3272
3273 if (sd->sensor < 0)
3274 goto error;
3275
3276 ov51x_led_control(sd, 0); /* turn LED off */
3277
3043 switch (sd->bridge) { 3278 switch (sd->bridge) {
3044 case BRIDGE_OV511: 3279 case BRIDGE_OV511:
3045 case BRIDGE_OV511PLUS: 3280 case BRIDGE_OV511PLUS:
3046 if (!sd->sif) { 3281 if (sd->sif) {
3047 cam->cam_mode = ov511_vga_mode;
3048 cam->nmodes = ARRAY_SIZE(ov511_vga_mode);
3049 } else {
3050 cam->cam_mode = ov511_sif_mode; 3282 cam->cam_mode = ov511_sif_mode;
3051 cam->nmodes = ARRAY_SIZE(ov511_sif_mode); 3283 cam->nmodes = ARRAY_SIZE(ov511_sif_mode);
3052 } 3284 }
3053 break; 3285 break;
3054 case BRIDGE_OV518: 3286 case BRIDGE_OV518:
3055 case BRIDGE_OV518PLUS: 3287 case BRIDGE_OV518PLUS:
3056 if (!sd->sif) { 3288 if (sd->sif) {
3057 cam->cam_mode = ov518_vga_mode;
3058 cam->nmodes = ARRAY_SIZE(ov518_vga_mode);
3059 } else {
3060 cam->cam_mode = ov518_sif_mode; 3289 cam->cam_mode = ov518_sif_mode;
3061 cam->nmodes = ARRAY_SIZE(ov518_sif_mode); 3290 cam->nmodes = ARRAY_SIZE(ov518_sif_mode);
3062 } 3291 }
3063 break; 3292 break;
3064 case BRIDGE_OV519: 3293 case BRIDGE_OV519:
3065 if (!sd->sif) { 3294 if (sd->sif) {
3066 cam->cam_mode = ov519_vga_mode;
3067 cam->nmodes = ARRAY_SIZE(ov519_vga_mode);
3068 } else {
3069 cam->cam_mode = ov519_sif_mode; 3295 cam->cam_mode = ov519_sif_mode;
3070 cam->nmodes = ARRAY_SIZE(ov519_sif_mode); 3296 cam->nmodes = ARRAY_SIZE(ov519_sif_mode);
3071 } 3297 }
@@ -3077,118 +3303,107 @@ static int sd_config(struct gspca_dev *gspca_dev,
3077 } else if (sd->sensor == SEN_OV3610) { 3303 } else if (sd->sensor == SEN_OV3610) {
3078 cam->cam_mode = ovfx2_ov3610_mode; 3304 cam->cam_mode = ovfx2_ov3610_mode;
3079 cam->nmodes = ARRAY_SIZE(ovfx2_ov3610_mode); 3305 cam->nmodes = ARRAY_SIZE(ovfx2_ov3610_mode);
3080 } else if (!sd->sif) { 3306 } else if (sd->sif) {
3081 cam->cam_mode = ov519_vga_mode;
3082 cam->nmodes = ARRAY_SIZE(ov519_vga_mode);
3083 } else {
3084 cam->cam_mode = ov519_sif_mode; 3307 cam->cam_mode = ov519_sif_mode;
3085 cam->nmodes = ARRAY_SIZE(ov519_sif_mode); 3308 cam->nmodes = ARRAY_SIZE(ov519_sif_mode);
3086 } 3309 }
3087 break; 3310 break;
3088 case BRIDGE_W9968CF: 3311 case BRIDGE_W9968CF:
3089 cam->cam_mode = w9968cf_vga_mode;
3090 cam->nmodes = ARRAY_SIZE(w9968cf_vga_mode);
3091 if (sd->sif) 3312 if (sd->sif)
3092 cam->nmodes--; 3313 cam->nmodes = ARRAY_SIZE(w9968cf_vga_mode) - 1;
3093 3314
3094 /* w9968cf needs initialisation once the sensor is known */ 3315 /* w9968cf needs initialisation once the sensor is known */
3095 if (w9968cf_init(sd) < 0) 3316 w9968cf_init(sd);
3096 goto error;
3097 break; 3317 break;
3098 } 3318 }
3099 gspca_dev->cam.ctrls = sd->ctrls;
3100 if (sd->sensor == SEN_OV7670)
3101 gspca_dev->ctrl_dis = 1 << COLORS;
3102 else
3103 gspca_dev->ctrl_dis = (1 << HFLIP) | (1 << VFLIP);
3104 sd->quality = QUALITY_DEF;
3105 if (sd->sensor == SEN_OV7640 ||
3106 sd->sensor == SEN_OV7648)
3107 gspca_dev->ctrl_dis |= (1 << AUTOBRIGHT) | (1 << CONTRAST);
3108 if (sd->sensor == SEN_OV7670)
3109 gspca_dev->ctrl_dis |= 1 << AUTOBRIGHT;
3110 /* OV8610 Frequency filter control should work but needs testing */
3111 if (sd->sensor == SEN_OV8610)
3112 gspca_dev->ctrl_dis |= 1 << FREQ;
3113 /* No controls for the OV2610/OV3610 */
3114 if (sd->sensor == SEN_OV2610 || sd->sensor == SEN_OV3610)
3115 gspca_dev->ctrl_dis |= (1 << NCTRL) - 1;
3116 3319
3117 return 0; 3320 gspca_dev->ctrl_dis = ctrl_dis[sd->sensor];
3118error:
3119 PDEBUG(D_ERR, "OV519 Config failed");
3120 return -EBUSY;
3121}
3122
3123/* this function is called at probe and resume time */
3124static int sd_init(struct gspca_dev *gspca_dev)
3125{
3126 struct sd *sd = (struct sd *) gspca_dev;
3127 3321
3128 /* initialize the sensor */ 3322 /* initialize the sensor */
3129 switch (sd->sensor) { 3323 switch (sd->sensor) {
3130 case SEN_OV2610: 3324 case SEN_OV2610:
3131 if (write_i2c_regvals(sd, norm_2610, ARRAY_SIZE(norm_2610))) 3325 write_i2c_regvals(sd, norm_2610, ARRAY_SIZE(norm_2610));
3132 return -EIO; 3326
3133 /* Enable autogain, autoexpo, awb, bandfilter */ 3327 /* Enable autogain, autoexpo, awb, bandfilter */
3134 if (i2c_w_mask(sd, 0x13, 0x27, 0x27) < 0) 3328 i2c_w_mask(sd, 0x13, 0x27, 0x27);
3135 return -EIO;
3136 break; 3329 break;
3137 case SEN_OV3610: 3330 case SEN_OV3610:
3138 if (write_i2c_regvals(sd, norm_3620b, ARRAY_SIZE(norm_3620b))) 3331 write_i2c_regvals(sd, norm_3620b, ARRAY_SIZE(norm_3620b));
3139 return -EIO; 3332
3140 /* Enable autogain, autoexpo, awb, bandfilter */ 3333 /* Enable autogain, autoexpo, awb, bandfilter */
3141 if (i2c_w_mask(sd, 0x13, 0x27, 0x27) < 0) 3334 i2c_w_mask(sd, 0x13, 0x27, 0x27);
3142 return -EIO;
3143 break; 3335 break;
3144 case SEN_OV6620: 3336 case SEN_OV6620:
3145 if (write_i2c_regvals(sd, norm_6x20, ARRAY_SIZE(norm_6x20))) 3337 write_i2c_regvals(sd, norm_6x20, ARRAY_SIZE(norm_6x20));
3146 return -EIO;
3147 break; 3338 break;
3148 case SEN_OV6630: 3339 case SEN_OV6630:
3149 case SEN_OV66308AF: 3340 case SEN_OV66308AF:
3150 sd->ctrls[CONTRAST].def = 200; 3341 sd->ctrls[CONTRAST].def = 200;
3151 /* The default is too low for the ov6630 */ 3342 /* The default is too low for the ov6630 */
3152 if (write_i2c_regvals(sd, norm_6x30, ARRAY_SIZE(norm_6x30))) 3343 write_i2c_regvals(sd, norm_6x30, ARRAY_SIZE(norm_6x30));
3153 return -EIO;
3154 break; 3344 break;
3155 default: 3345 default:
3156/* case SEN_OV7610: */ 3346/* case SEN_OV7610: */
3157/* case SEN_OV76BE: */ 3347/* case SEN_OV76BE: */
3158 if (write_i2c_regvals(sd, norm_7610, ARRAY_SIZE(norm_7610))) 3348 write_i2c_regvals(sd, norm_7610, ARRAY_SIZE(norm_7610));
3159 return -EIO; 3349 i2c_w_mask(sd, 0x0e, 0x00, 0x40);
3160 if (i2c_w_mask(sd, 0x0e, 0x00, 0x40))
3161 return -EIO;
3162 break; 3350 break;
3163 case SEN_OV7620: 3351 case SEN_OV7620:
3164 case SEN_OV7620AE: 3352 case SEN_OV7620AE:
3165 if (write_i2c_regvals(sd, norm_7620, ARRAY_SIZE(norm_7620))) 3353 write_i2c_regvals(sd, norm_7620, ARRAY_SIZE(norm_7620));
3166 return -EIO;
3167 break; 3354 break;
3168 case SEN_OV7640: 3355 case SEN_OV7640:
3169 case SEN_OV7648: 3356 case SEN_OV7648:
3170 if (write_i2c_regvals(sd, norm_7640, ARRAY_SIZE(norm_7640))) 3357 write_i2c_regvals(sd, norm_7640, ARRAY_SIZE(norm_7640));
3171 return -EIO; 3358 break;
3359 case SEN_OV7660:
3360 i2c_w(sd, OV7670_R12_COM7, OV7670_COM7_RESET);
3361 msleep(14);
3362 reg_w(sd, OV519_R57_SNAPSHOT, 0x23);
3363 write_regvals(sd, init_519_ov7660,
3364 ARRAY_SIZE(init_519_ov7660));
3365 write_i2c_regvals(sd, norm_7660, ARRAY_SIZE(norm_7660));
3366 sd->gspca_dev.curr_mode = 1; /* 640x480 */
3367 sd->frame_rate = 15;
3368 ov519_set_mode(sd);
3369 ov519_set_fr(sd);
3370 sd->ctrls[COLORS].max = 4; /* 0..4 */
3371 sd->ctrls[COLORS].val =
3372 sd->ctrls[COLORS].def = 2;
3373 setcolors(gspca_dev);
3374 sd->ctrls[CONTRAST].max = 6; /* 0..6 */
3375 sd->ctrls[CONTRAST].val =
3376 sd->ctrls[CONTRAST].def = 3;
3377 setcontrast(gspca_dev);
3378 sd->ctrls[BRIGHTNESS].max = 6; /* 0..6 */
3379 sd->ctrls[BRIGHTNESS].val =
3380 sd->ctrls[BRIGHTNESS].def = 3;
3381 setbrightness(gspca_dev);
3382 sd_reset_snapshot(gspca_dev);
3383 ov51x_restart(sd);
3384 ov51x_stop(sd); /* not in win traces */
3385 ov51x_led_control(sd, 0);
3172 break; 3386 break;
3173 case SEN_OV7670: 3387 case SEN_OV7670:
3174 sd->ctrls[FREQ].max = 3; /* auto */ 3388 sd->ctrls[FREQ].max = 3; /* auto */
3175 sd->ctrls[FREQ].def = 3; 3389 sd->ctrls[FREQ].def = 3;
3176 if (write_i2c_regvals(sd, norm_7670, ARRAY_SIZE(norm_7670))) 3390 write_i2c_regvals(sd, norm_7670, ARRAY_SIZE(norm_7670));
3177 return -EIO;
3178 break; 3391 break;
3179 case SEN_OV8610: 3392 case SEN_OV8610:
3180 if (write_i2c_regvals(sd, norm_8610, ARRAY_SIZE(norm_8610))) 3393 write_i2c_regvals(sd, norm_8610, ARRAY_SIZE(norm_8610));
3181 return -EIO;
3182 break; 3394 break;
3183 } 3395 }
3184 return 0; 3396 return gspca_dev->usb_err;
3397error:
3398 PDEBUG(D_ERR, "OV519 Config failed");
3399 return -EINVAL;
3185} 3400}
3186 3401
3187/* Set up the OV511/OV511+ with the given image parameters. 3402/* Set up the OV511/OV511+ with the given image parameters.
3188 * 3403 *
3189 * Do not put any sensor-specific code in here (including I2C I/O functions) 3404 * Do not put any sensor-specific code in here (including I2C I/O functions)
3190 */ 3405 */
3191static int ov511_mode_init_regs(struct sd *sd) 3406static void ov511_mode_init_regs(struct sd *sd)
3192{ 3407{
3193 int hsegs, vsegs, packet_size, fps, needed; 3408 int hsegs, vsegs, packet_size, fps, needed;
3194 int interlaced = 0; 3409 int interlaced = 0;
@@ -3199,7 +3414,8 @@ static int ov511_mode_init_regs(struct sd *sd)
3199 alt = usb_altnum_to_altsetting(intf, sd->gspca_dev.alt); 3414 alt = usb_altnum_to_altsetting(intf, sd->gspca_dev.alt);
3200 if (!alt) { 3415 if (!alt) {
3201 err("Couldn't get altsetting"); 3416 err("Couldn't get altsetting");
3202 return -EIO; 3417 sd->gspca_dev.usb_err = -EIO;
3418 return;
3203 } 3419 }
3204 3420
3205 packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize); 3421 packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize);
@@ -3302,8 +3518,6 @@ static int ov511_mode_init_regs(struct sd *sd)
3302 3518
3303 reg_w(sd, R51x_SYS_RESET, OV511_RESET_OMNICE); 3519 reg_w(sd, R51x_SYS_RESET, OV511_RESET_OMNICE);
3304 reg_w(sd, R51x_SYS_RESET, 0); 3520 reg_w(sd, R51x_SYS_RESET, 0);
3305
3306 return 0;
3307} 3521}
3308 3522
3309/* Sets up the OV518/OV518+ with the given image parameters 3523/* Sets up the OV518/OV518+ with the given image parameters
@@ -3313,7 +3527,7 @@ static int ov511_mode_init_regs(struct sd *sd)
3313 * 3527 *
3314 * Do not put any sensor-specific code in here (including I2C I/O functions) 3528 * Do not put any sensor-specific code in here (including I2C I/O functions)
3315 */ 3529 */
3316static int ov518_mode_init_regs(struct sd *sd) 3530static void ov518_mode_init_regs(struct sd *sd)
3317{ 3531{
3318 int hsegs, vsegs, packet_size; 3532 int hsegs, vsegs, packet_size;
3319 struct usb_host_interface *alt; 3533 struct usb_host_interface *alt;
@@ -3323,14 +3537,14 @@ static int ov518_mode_init_regs(struct sd *sd)
3323 alt = usb_altnum_to_altsetting(intf, sd->gspca_dev.alt); 3537 alt = usb_altnum_to_altsetting(intf, sd->gspca_dev.alt);
3324 if (!alt) { 3538 if (!alt) {
3325 err("Couldn't get altsetting"); 3539 err("Couldn't get altsetting");
3326 return -EIO; 3540 sd->gspca_dev.usb_err = -EIO;
3541 return;
3327 } 3542 }
3328 3543
3329 packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize); 3544 packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize);
3330 ov518_reg_w32(sd, R51x_FIFO_PSIZE, packet_size & ~7, 2); 3545 ov518_reg_w32(sd, R51x_FIFO_PSIZE, packet_size & ~7, 2);
3331 3546
3332 /******** Set the mode ********/ 3547 /******** Set the mode ********/
3333
3334 reg_w(sd, 0x2b, 0); 3548 reg_w(sd, 0x2b, 0);
3335 reg_w(sd, 0x2c, 0); 3549 reg_w(sd, 0x2c, 0);
3336 reg_w(sd, 0x2d, 0); 3550 reg_w(sd, 0x2d, 0);
@@ -3364,7 +3578,7 @@ static int ov518_mode_init_regs(struct sd *sd)
3364 /* Windows driver does this here; who knows why */ 3578 /* Windows driver does this here; who knows why */
3365 reg_w(sd, 0x2f, 0x80); 3579 reg_w(sd, 0x2f, 0x80);
3366 3580
3367 /******** Set the framerate ********/ 3581 /******** Set the framerate ********/
3368 sd->clockdiv = 1; 3582 sd->clockdiv = 1;
3369 3583
3370 /* Mode independent, but framerate dependent, regs */ 3584 /* Mode independent, but framerate dependent, regs */
@@ -3427,11 +3641,8 @@ static int ov518_mode_init_regs(struct sd *sd)
3427 } 3641 }
3428 3642
3429 reg_w(sd, 0x2f, 0x80); 3643 reg_w(sd, 0x2f, 0x80);
3430
3431 return 0;
3432} 3644}
3433 3645
3434
3435/* Sets up the OV519 with the given image parameters 3646/* Sets up the OV519 with the given image parameters
3436 * 3647 *
3437 * OV519 needs a completely different approach, until we can figure out what 3648 * OV519 needs a completely different approach, until we can figure out what
@@ -3439,12 +3650,12 @@ static int ov518_mode_init_regs(struct sd *sd)
3439 * 3650 *
3440 * Do not put any sensor-specific code in here (including I2C I/O functions) 3651 * Do not put any sensor-specific code in here (including I2C I/O functions)
3441 */ 3652 */
3442static int ov519_mode_init_regs(struct sd *sd) 3653static void ov519_mode_init_regs(struct sd *sd)
3443{ 3654{
3444 static const struct ov_regvals mode_init_519_ov7670[] = { 3655 static const struct ov_regvals mode_init_519_ov7670[] = {
3445 { 0x5d, 0x03 }, /* Turn off suspend mode */ 3656 { 0x5d, 0x03 }, /* Turn off suspend mode */
3446 { 0x53, 0x9f }, /* was 9b in 1.65-1.08 */ 3657 { 0x53, 0x9f }, /* was 9b in 1.65-1.08 */
3447 { 0x54, 0x0f }, /* bit2 (jpeg enable) */ 3658 { OV519_R54_EN_CLK1, 0x0f }, /* bit2 (jpeg enable) */
3448 { 0xa2, 0x20 }, /* a2-a5 are undocumented */ 3659 { 0xa2, 0x20 }, /* a2-a5 are undocumented */
3449 { 0xa3, 0x18 }, 3660 { 0xa3, 0x18 },
3450 { 0xa4, 0x04 }, 3661 { 0xa4, 0x04 },
@@ -3467,7 +3678,7 @@ static int ov519_mode_init_regs(struct sd *sd)
3467 static const struct ov_regvals mode_init_519[] = { 3678 static const struct ov_regvals mode_init_519[] = {
3468 { 0x5d, 0x03 }, /* Turn off suspend mode */ 3679 { 0x5d, 0x03 }, /* Turn off suspend mode */
3469 { 0x53, 0x9f }, /* was 9b in 1.65-1.08 */ 3680 { 0x53, 0x9f }, /* was 9b in 1.65-1.08 */
3470 { 0x54, 0x0f }, /* bit2 (jpeg enable) */ 3681 { OV519_R54_EN_CLK1, 0x0f }, /* bit2 (jpeg enable) */
3471 { 0xa2, 0x20 }, /* a2-a5 are undocumented */ 3682 { 0xa2, 0x20 }, /* a2-a5 are undocumented */
3472 { 0xa3, 0x18 }, 3683 { 0xa3, 0x18 },
3473 { 0xa4, 0x04 }, 3684 { 0xa4, 0x04 },
@@ -3486,19 +3697,21 @@ static int ov519_mode_init_regs(struct sd *sd)
3486 }; 3697 };
3487 3698
3488 /******** Set the mode ********/ 3699 /******** Set the mode ********/
3489 if (sd->sensor != SEN_OV7670) { 3700 switch (sd->sensor) {
3490 if (write_regvals(sd, mode_init_519, 3701 default:
3491 ARRAY_SIZE(mode_init_519))) 3702 write_regvals(sd, mode_init_519, ARRAY_SIZE(mode_init_519));
3492 return -EIO;
3493 if (sd->sensor == SEN_OV7640 || 3703 if (sd->sensor == SEN_OV7640 ||
3494 sd->sensor == SEN_OV7648) { 3704 sd->sensor == SEN_OV7648) {
3495 /* Select 8-bit input mode */ 3705 /* Select 8-bit input mode */
3496 reg_w_mask(sd, OV519_R20_DFR, 0x10, 0x10); 3706 reg_w_mask(sd, OV519_R20_DFR, 0x10, 0x10);
3497 } 3707 }
3498 } else { 3708 break;
3499 if (write_regvals(sd, mode_init_519_ov7670, 3709 case SEN_OV7660:
3500 ARRAY_SIZE(mode_init_519_ov7670))) 3710 return; /* done by ov519_set_mode/fr() */
3501 return -EIO; 3711 case SEN_OV7670:
3712 write_regvals(sd, mode_init_519_ov7670,
3713 ARRAY_SIZE(mode_init_519_ov7670));
3714 break;
3502 } 3715 }
3503 3716
3504 reg_w(sd, OV519_R10_H_SIZE, sd->gspca_dev.width >> 4); 3717 reg_w(sd, OV519_R10_H_SIZE, sd->gspca_dev.width >> 4);
@@ -3594,17 +3807,16 @@ static int ov519_mode_init_regs(struct sd *sd)
3594 } 3807 }
3595 break; 3808 break;
3596 } 3809 }
3597 return 0;
3598} 3810}
3599 3811
3600static int mode_init_ov_sensor_regs(struct sd *sd) 3812static void mode_init_ov_sensor_regs(struct sd *sd)
3601{ 3813{
3602 struct gspca_dev *gspca_dev; 3814 struct gspca_dev *gspca_dev;
3603 int qvga, xstart, xend, ystart, yend; 3815 int qvga, xstart, xend, ystart, yend;
3604 __u8 v; 3816 u8 v;
3605 3817
3606 gspca_dev = &sd->gspca_dev; 3818 gspca_dev = &sd->gspca_dev;
3607 qvga = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv & 1; 3819 qvga = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv & 1;
3608 3820
3609 /******** Mode (VGA/QVGA) and sensor specific regs ********/ 3821 /******** Mode (VGA/QVGA) and sensor specific regs ********/
3610 switch (sd->sensor) { 3822 switch (sd->sensor) {
@@ -3616,7 +3828,7 @@ static int mode_init_ov_sensor_regs(struct sd *sd)
3616 i2c_w_mask(sd, 0x2d, qvga ? 0x40 : 0x00, 0x40); 3828 i2c_w_mask(sd, 0x2d, qvga ? 0x40 : 0x00, 0x40);
3617 i2c_w_mask(sd, 0x67, qvga ? 0xf0 : 0x90, 0xf0); 3829 i2c_w_mask(sd, 0x67, qvga ? 0xf0 : 0x90, 0xf0);
3618 i2c_w_mask(sd, 0x74, qvga ? 0x20 : 0x00, 0x20); 3830 i2c_w_mask(sd, 0x74, qvga ? 0x20 : 0x00, 0x20);
3619 return 0; 3831 return;
3620 case SEN_OV3610: 3832 case SEN_OV3610:
3621 if (qvga) { 3833 if (qvga) {
3622 xstart = (1040 - gspca_dev->width) / 2 + (0x1f << 4); 3834 xstart = (1040 - gspca_dev->width) / 2 + (0x1f << 4);
@@ -3640,7 +3852,7 @@ static int mode_init_ov_sensor_regs(struct sd *sd)
3640 i2c_w(sd, 0x18, xend >> 4); 3852 i2c_w(sd, 0x18, xend >> 4);
3641 i2c_w(sd, 0x19, ystart >> 3); 3853 i2c_w(sd, 0x19, ystart >> 3);
3642 i2c_w(sd, 0x1a, yend >> 3); 3854 i2c_w(sd, 0x1a, yend >> 3);
3643 return 0; 3855 return;
3644 case SEN_OV8610: 3856 case SEN_OV8610:
3645 /* For OV8610 qvga means qsvga */ 3857 /* For OV8610 qvga means qsvga */
3646 i2c_w_mask(sd, OV7610_REG_COM_C, qvga ? (1 << 5) : 0, 1 << 5); 3858 i2c_w_mask(sd, OV7610_REG_COM_C, qvga ? (1 << 5) : 0, 1 << 5);
@@ -3687,11 +3899,11 @@ static int mode_init_ov_sensor_regs(struct sd *sd)
3687 /* set COM7_FMT_VGA or COM7_FMT_QVGA 3899 /* set COM7_FMT_VGA or COM7_FMT_QVGA
3688 * do we need to set anything else? 3900 * do we need to set anything else?
3689 * HSTART etc are set in set_ov_sensor_window itself */ 3901 * HSTART etc are set in set_ov_sensor_window itself */
3690 i2c_w_mask(sd, OV7670_REG_COM7, 3902 i2c_w_mask(sd, OV7670_R12_COM7,
3691 qvga ? OV7670_COM7_FMT_QVGA : OV7670_COM7_FMT_VGA, 3903 qvga ? OV7670_COM7_FMT_QVGA : OV7670_COM7_FMT_VGA,
3692 OV7670_COM7_FMT_MASK); 3904 OV7670_COM7_FMT_MASK);
3693 i2c_w_mask(sd, 0x13, 0x00, 0x20); /* Select 16 bit data bus */ 3905 i2c_w_mask(sd, 0x13, 0x00, 0x20); /* Select 16 bit data bus */
3694 i2c_w_mask(sd, OV7670_REG_COM8, OV7670_COM8_AWB, 3906 i2c_w_mask(sd, OV7670_R13_COM8, OV7670_COM8_AWB,
3695 OV7670_COM8_AWB); 3907 OV7670_COM8_AWB);
3696 if (qvga) { /* QVGA from ov7670.c by 3908 if (qvga) { /* QVGA from ov7670.c by
3697 * Jonathan Corbet */ 3909 * Jonathan Corbet */
@@ -3707,21 +3919,21 @@ static int mode_init_ov_sensor_regs(struct sd *sd)
3707 } 3919 }
3708 /* OV7670 hardware window registers are split across 3920 /* OV7670 hardware window registers are split across
3709 * multiple locations */ 3921 * multiple locations */
3710 i2c_w(sd, OV7670_REG_HSTART, xstart >> 3); 3922 i2c_w(sd, OV7670_R17_HSTART, xstart >> 3);
3711 i2c_w(sd, OV7670_REG_HSTOP, xend >> 3); 3923 i2c_w(sd, OV7670_R18_HSTOP, xend >> 3);
3712 v = i2c_r(sd, OV7670_REG_HREF); 3924 v = i2c_r(sd, OV7670_R32_HREF);
3713 v = (v & 0xc0) | ((xend & 0x7) << 3) | (xstart & 0x07); 3925 v = (v & 0xc0) | ((xend & 0x7) << 3) | (xstart & 0x07);
3714 msleep(10); /* need to sleep between read and write to 3926 msleep(10); /* need to sleep between read and write to
3715 * same reg! */ 3927 * same reg! */
3716 i2c_w(sd, OV7670_REG_HREF, v); 3928 i2c_w(sd, OV7670_R32_HREF, v);
3717 3929
3718 i2c_w(sd, OV7670_REG_VSTART, ystart >> 2); 3930 i2c_w(sd, OV7670_R19_VSTART, ystart >> 2);
3719 i2c_w(sd, OV7670_REG_VSTOP, yend >> 2); 3931 i2c_w(sd, OV7670_R1A_VSTOP, yend >> 2);
3720 v = i2c_r(sd, OV7670_REG_VREF); 3932 v = i2c_r(sd, OV7670_R03_VREF);
3721 v = (v & 0xc0) | ((yend & 0x3) << 2) | (ystart & 0x03); 3933 v = (v & 0xc0) | ((yend & 0x3) << 2) | (ystart & 0x03);
3722 msleep(10); /* need to sleep between read and write to 3934 msleep(10); /* need to sleep between read and write to
3723 * same reg! */ 3935 * same reg! */
3724 i2c_w(sd, OV7670_REG_VREF, v); 3936 i2c_w(sd, OV7670_R03_VREF, v);
3725 break; 3937 break;
3726 case SEN_OV6620: 3938 case SEN_OV6620:
3727 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20); 3939 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
@@ -3734,46 +3946,50 @@ static int mode_init_ov_sensor_regs(struct sd *sd)
3734 i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */ 3946 i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */
3735 break; 3947 break;
3736 default: 3948 default:
3737 return -EINVAL; 3949 return;
3738 } 3950 }
3739 3951
3740 /******** Clock programming ********/ 3952 /******** Clock programming ********/
3741 i2c_w(sd, 0x11, sd->clockdiv); 3953 i2c_w(sd, 0x11, sd->clockdiv);
3742
3743 return 0;
3744} 3954}
3745 3955
3956/* this function works for bridge ov519 and sensors ov7660 and ov7670 only */
3746static void sethvflip(struct gspca_dev *gspca_dev) 3957static void sethvflip(struct gspca_dev *gspca_dev)
3747{ 3958{
3748 struct sd *sd = (struct sd *) gspca_dev; 3959 struct sd *sd = (struct sd *) gspca_dev;
3749 3960
3750 if (sd->sensor != SEN_OV7670)
3751 return;
3752 if (sd->gspca_dev.streaming) 3961 if (sd->gspca_dev.streaming)
3753 ov51x_stop(sd); 3962 reg_w(sd, OV519_R51_RESET1, 0x0f); /* block stream */
3754 i2c_w_mask(sd, OV7670_REG_MVFP, 3963 i2c_w_mask(sd, OV7670_R1E_MVFP,
3755 OV7670_MVFP_MIRROR * sd->ctrls[HFLIP].val 3964 OV7670_MVFP_MIRROR * sd->ctrls[HFLIP].val
3756 | OV7670_MVFP_VFLIP * sd->ctrls[VFLIP].val, 3965 | OV7670_MVFP_VFLIP * sd->ctrls[VFLIP].val,
3757 OV7670_MVFP_MIRROR | OV7670_MVFP_VFLIP); 3966 OV7670_MVFP_MIRROR | OV7670_MVFP_VFLIP);
3758 if (sd->gspca_dev.streaming) 3967 if (sd->gspca_dev.streaming)
3759 ov51x_restart(sd); 3968 reg_w(sd, OV519_R51_RESET1, 0x00); /* restart stream */
3760} 3969}
3761 3970
3762static int set_ov_sensor_window(struct sd *sd) 3971static void set_ov_sensor_window(struct sd *sd)
3763{ 3972{
3764 struct gspca_dev *gspca_dev; 3973 struct gspca_dev *gspca_dev;
3765 int qvga, crop; 3974 int qvga, crop;
3766 int hwsbase, hwebase, vwsbase, vwebase, hwscale, vwscale; 3975 int hwsbase, hwebase, vwsbase, vwebase, hwscale, vwscale;
3767 int ret;
3768 3976
3769 /* mode setup is fully handled in mode_init_ov_sensor_regs for these */ 3977 /* mode setup is fully handled in mode_init_ov_sensor_regs for these */
3770 if (sd->sensor == SEN_OV2610 || sd->sensor == SEN_OV3610 || 3978 switch (sd->sensor) {
3771 sd->sensor == SEN_OV7670) 3979 case SEN_OV2610:
3772 return mode_init_ov_sensor_regs(sd); 3980 case SEN_OV3610:
3981 case SEN_OV7670:
3982 mode_init_ov_sensor_regs(sd);
3983 return;
3984 case SEN_OV7660:
3985 ov519_set_mode(sd);
3986 ov519_set_fr(sd);
3987 return;
3988 }
3773 3989
3774 gspca_dev = &sd->gspca_dev; 3990 gspca_dev = &sd->gspca_dev;
3775 qvga = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv & 1; 3991 qvga = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv & 1;
3776 crop = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv & 2; 3992 crop = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv & 2;
3777 3993
3778 /* The different sensor ICs handle setting up of window differently. 3994 /* The different sensor ICs handle setting up of window differently.
3779 * IF YOU SET IT WRONG, YOU WILL GET ALL ZERO ISOC DATA FROM OV51x!! */ 3995 * IF YOU SET IT WRONG, YOU WILL GET ALL ZERO ISOC DATA FROM OV51x!! */
@@ -3820,7 +4036,7 @@ static int set_ov_sensor_window(struct sd *sd)
3820 vwsbase = vwebase = 0x03; 4036 vwsbase = vwebase = 0x03;
3821 break; 4037 break;
3822 default: 4038 default:
3823 return -EINVAL; 4039 return;
3824 } 4040 }
3825 4041
3826 switch (sd->sensor) { 4042 switch (sd->sensor) {
@@ -3855,23 +4071,18 @@ static int set_ov_sensor_window(struct sd *sd)
3855 } 4071 }
3856 } 4072 }
3857 4073
3858 ret = mode_init_ov_sensor_regs(sd); 4074 mode_init_ov_sensor_regs(sd);
3859 if (ret < 0)
3860 return ret;
3861 4075
3862 i2c_w(sd, 0x17, hwsbase); 4076 i2c_w(sd, 0x17, hwsbase);
3863 i2c_w(sd, 0x18, hwebase + (sd->sensor_width >> hwscale)); 4077 i2c_w(sd, 0x18, hwebase + (sd->sensor_width >> hwscale));
3864 i2c_w(sd, 0x19, vwsbase); 4078 i2c_w(sd, 0x19, vwsbase);
3865 i2c_w(sd, 0x1a, vwebase + (sd->sensor_height >> vwscale)); 4079 i2c_w(sd, 0x1a, vwebase + (sd->sensor_height >> vwscale));
3866
3867 return 0;
3868} 4080}
3869 4081
3870/* -- start the camera -- */ 4082/* -- start the camera -- */
3871static int sd_start(struct gspca_dev *gspca_dev) 4083static int sd_start(struct gspca_dev *gspca_dev)
3872{ 4084{
3873 struct sd *sd = (struct sd *) gspca_dev; 4085 struct sd *sd = (struct sd *) gspca_dev;
3874 int ret = 0;
3875 4086
3876 /* Default for most bridges, allow bridge_mode_init_regs to override */ 4087 /* Default for most bridges, allow bridge_mode_init_regs to override */
3877 sd->sensor_width = sd->gspca_dev.width; 4088 sd->sensor_width = sd->gspca_dev.width;
@@ -3880,50 +4091,46 @@ static int sd_start(struct gspca_dev *gspca_dev)
3880 switch (sd->bridge) { 4091 switch (sd->bridge) {
3881 case BRIDGE_OV511: 4092 case BRIDGE_OV511:
3882 case BRIDGE_OV511PLUS: 4093 case BRIDGE_OV511PLUS:
3883 ret = ov511_mode_init_regs(sd); 4094 ov511_mode_init_regs(sd);
3884 break; 4095 break;
3885 case BRIDGE_OV518: 4096 case BRIDGE_OV518:
3886 case BRIDGE_OV518PLUS: 4097 case BRIDGE_OV518PLUS:
3887 ret = ov518_mode_init_regs(sd); 4098 ov518_mode_init_regs(sd);
3888 break; 4099 break;
3889 case BRIDGE_OV519: 4100 case BRIDGE_OV519:
3890 ret = ov519_mode_init_regs(sd); 4101 ov519_mode_init_regs(sd);
3891 break; 4102 break;
3892 /* case BRIDGE_OVFX2: nothing to do */ 4103 /* case BRIDGE_OVFX2: nothing to do */
3893 case BRIDGE_W9968CF: 4104 case BRIDGE_W9968CF:
3894 ret = w9968cf_mode_init_regs(sd); 4105 w9968cf_mode_init_regs(sd);
3895 break; 4106 break;
3896 } 4107 }
3897 if (ret < 0) 4108
3898 goto out; 4109 set_ov_sensor_window(sd);
3899 4110
3900 ret = set_ov_sensor_window(sd); 4111 if (!(sd->gspca_dev.ctrl_dis & (1 << CONTRAST)))
3901 if (ret < 0) 4112 setcontrast(gspca_dev);
3902 goto out; 4113 if (!(sd->gspca_dev.ctrl_dis & (1 << BRIGHTNESS)))
3903 4114 setbrightness(gspca_dev);
3904 setcontrast(gspca_dev); 4115 if (!(sd->gspca_dev.ctrl_dis & (1 << COLORS)))
3905 setbrightness(gspca_dev); 4116 setcolors(gspca_dev);
3906 setcolors(gspca_dev); 4117 if (!(sd->gspca_dev.ctrl_dis & ((1 << HFLIP) | (1 << VFLIP))))
3907 sethvflip(gspca_dev); 4118 sethvflip(gspca_dev);
3908 setautobright(gspca_dev); 4119 if (!(sd->gspca_dev.ctrl_dis & (1 << AUTOBRIGHT)))
3909 setfreq_i(sd); 4120 setautobright(gspca_dev);
4121 if (!(sd->gspca_dev.ctrl_dis & (1 << FREQ)))
4122 setfreq_i(sd);
3910 4123
3911 /* Force clear snapshot state in case the snapshot button was 4124 /* Force clear snapshot state in case the snapshot button was
3912 pressed while we weren't streaming */ 4125 pressed while we weren't streaming */
3913 sd->snapshot_needs_reset = 1; 4126 sd->snapshot_needs_reset = 1;
3914 sd_reset_snapshot(gspca_dev); 4127 sd_reset_snapshot(gspca_dev);
3915 sd->snapshot_pressed = 0;
3916 4128
3917 sd->first_frame = 3; 4129 sd->first_frame = 3;
3918 4130
3919 ret = ov51x_restart(sd); 4131 ov51x_restart(sd);
3920 if (ret < 0)
3921 goto out;
3922 ov51x_led_control(sd, 1); 4132 ov51x_led_control(sd, 1);
3923 return 0; 4133 return gspca_dev->usb_err;
3924out:
3925 PDEBUG(D_ERR, "camera start error:%d", ret);
3926 return ret;
3927} 4134}
3928 4135
3929static void sd_stopN(struct gspca_dev *gspca_dev) 4136static void sd_stopN(struct gspca_dev *gspca_dev)
@@ -3938,8 +4145,21 @@ static void sd_stop0(struct gspca_dev *gspca_dev)
3938{ 4145{
3939 struct sd *sd = (struct sd *) gspca_dev; 4146 struct sd *sd = (struct sd *) gspca_dev;
3940 4147
4148 if (!sd->gspca_dev.present)
4149 return;
3941 if (sd->bridge == BRIDGE_W9968CF) 4150 if (sd->bridge == BRIDGE_W9968CF)
3942 w9968cf_stop0(sd); 4151 w9968cf_stop0(sd);
4152
4153#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
4154 /* If the last button state is pressed, release it now! */
4155 if (sd->snapshot_pressed) {
4156 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0);
4157 input_sync(gspca_dev->input_dev);
4158 sd->snapshot_pressed = 0;
4159 }
4160#endif
4161 if (sd->bridge == BRIDGE_OV519)
4162 reg_w(sd, OV519_R57_SNAPSHOT, 0x23);
3943} 4163}
3944 4164
3945static void ov51x_handle_button(struct gspca_dev *gspca_dev, u8 state) 4165static void ov51x_handle_button(struct gspca_dev *gspca_dev, u8 state)
@@ -4160,6 +4380,22 @@ static void setbrightness(struct gspca_dev *gspca_dev)
4160{ 4380{
4161 struct sd *sd = (struct sd *) gspca_dev; 4381 struct sd *sd = (struct sd *) gspca_dev;
4162 int val; 4382 int val;
4383 static const struct ov_i2c_regvals brit_7660[][7] = {
4384 {{0x0f, 0x6a}, {0x24, 0x40}, {0x25, 0x2b}, {0x26, 0x90},
4385 {0x27, 0xe0}, {0x28, 0xe0}, {0x2c, 0xe0}},
4386 {{0x0f, 0x6a}, {0x24, 0x50}, {0x25, 0x40}, {0x26, 0xa1},
4387 {0x27, 0xc0}, {0x28, 0xc0}, {0x2c, 0xc0}},
4388 {{0x0f, 0x6a}, {0x24, 0x68}, {0x25, 0x58}, {0x26, 0xc2},
4389 {0x27, 0xa0}, {0x28, 0xa0}, {0x2c, 0xa0}},
4390 {{0x0f, 0x6a}, {0x24, 0x70}, {0x25, 0x68}, {0x26, 0xd3},
4391 {0x27, 0x80}, {0x28, 0x80}, {0x2c, 0x80}},
4392 {{0x0f, 0x6a}, {0x24, 0x80}, {0x25, 0x70}, {0x26, 0xd3},
4393 {0x27, 0x20}, {0x28, 0x20}, {0x2c, 0x20}},
4394 {{0x0f, 0x6a}, {0x24, 0x88}, {0x25, 0x78}, {0x26, 0xd3},
4395 {0x27, 0x40}, {0x28, 0x40}, {0x2c, 0x40}},
4396 {{0x0f, 0x6a}, {0x24, 0x90}, {0x25, 0x80}, {0x26, 0xd4},
4397 {0x27, 0x60}, {0x28, 0x60}, {0x2c, 0x60}}
4398 };
4163 4399
4164 val = sd->ctrls[BRIGHTNESS].val; 4400 val = sd->ctrls[BRIGHTNESS].val;
4165 switch (sd->sensor) { 4401 switch (sd->sensor) {
@@ -4179,10 +4415,14 @@ static void setbrightness(struct gspca_dev *gspca_dev)
4179 if (!sd->ctrls[AUTOBRIGHT].val) 4415 if (!sd->ctrls[AUTOBRIGHT].val)
4180 i2c_w(sd, OV7610_REG_BRT, val); 4416 i2c_w(sd, OV7610_REG_BRT, val);
4181 break; 4417 break;
4418 case SEN_OV7660:
4419 write_i2c_regvals(sd, brit_7660[val],
4420 ARRAY_SIZE(brit_7660[0]));
4421 break;
4182 case SEN_OV7670: 4422 case SEN_OV7670:
4183/*win trace 4423/*win trace
4184 * i2c_w_mask(sd, OV7670_REG_COM8, 0, OV7670_COM8_AEC); */ 4424 * i2c_w_mask(sd, OV7670_R13_COM8, 0, OV7670_COM8_AEC); */
4185 i2c_w(sd, OV7670_REG_BRIGHT, ov7670_abs_to_sm(val)); 4425 i2c_w(sd, OV7670_R55_BRIGHT, ov7670_abs_to_sm(val));
4186 break; 4426 break;
4187 } 4427 }
4188} 4428}
@@ -4191,6 +4431,64 @@ static void setcontrast(struct gspca_dev *gspca_dev)
4191{ 4431{
4192 struct sd *sd = (struct sd *) gspca_dev; 4432 struct sd *sd = (struct sd *) gspca_dev;
4193 int val; 4433 int val;
4434 static const struct ov_i2c_regvals contrast_7660[][31] = {
4435 {{0x6c, 0xf0}, {0x6d, 0xf0}, {0x6e, 0xf8}, {0x6f, 0xa0},
4436 {0x70, 0x58}, {0x71, 0x38}, {0x72, 0x30}, {0x73, 0x30},
4437 {0x74, 0x28}, {0x75, 0x28}, {0x76, 0x24}, {0x77, 0x24},
4438 {0x78, 0x22}, {0x79, 0x28}, {0x7a, 0x2a}, {0x7b, 0x34},
4439 {0x7c, 0x0f}, {0x7d, 0x1e}, {0x7e, 0x3d}, {0x7f, 0x65},
4440 {0x80, 0x70}, {0x81, 0x77}, {0x82, 0x7d}, {0x83, 0x83},
4441 {0x84, 0x88}, {0x85, 0x8d}, {0x86, 0x96}, {0x87, 0x9f},
4442 {0x88, 0xb0}, {0x89, 0xc4}, {0x8a, 0xd9}},
4443 {{0x6c, 0xf0}, {0x6d, 0xf0}, {0x6e, 0xf8}, {0x6f, 0x94},
4444 {0x70, 0x58}, {0x71, 0x40}, {0x72, 0x30}, {0x73, 0x30},
4445 {0x74, 0x30}, {0x75, 0x30}, {0x76, 0x2c}, {0x77, 0x24},
4446 {0x78, 0x22}, {0x79, 0x28}, {0x7a, 0x2a}, {0x7b, 0x31},
4447 {0x7c, 0x0f}, {0x7d, 0x1e}, {0x7e, 0x3d}, {0x7f, 0x62},
4448 {0x80, 0x6d}, {0x81, 0x75}, {0x82, 0x7b}, {0x83, 0x81},
4449 {0x84, 0x87}, {0x85, 0x8d}, {0x86, 0x98}, {0x87, 0xa1},
4450 {0x88, 0xb2}, {0x89, 0xc6}, {0x8a, 0xdb}},
4451 {{0x6c, 0xf0}, {0x6d, 0xf0}, {0x6e, 0xf0}, {0x6f, 0x84},
4452 {0x70, 0x58}, {0x71, 0x48}, {0x72, 0x40}, {0x73, 0x40},
4453 {0x74, 0x28}, {0x75, 0x28}, {0x76, 0x28}, {0x77, 0x24},
4454 {0x78, 0x26}, {0x79, 0x28}, {0x7a, 0x28}, {0x7b, 0x34},
4455 {0x7c, 0x0f}, {0x7d, 0x1e}, {0x7e, 0x3c}, {0x7f, 0x5d},
4456 {0x80, 0x68}, {0x81, 0x71}, {0x82, 0x79}, {0x83, 0x81},
4457 {0x84, 0x86}, {0x85, 0x8b}, {0x86, 0x95}, {0x87, 0x9e},
4458 {0x88, 0xb1}, {0x89, 0xc5}, {0x8a, 0xd9}},
4459 {{0x6c, 0xf0}, {0x6d, 0xf0}, {0x6e, 0xf0}, {0x6f, 0x70},
4460 {0x70, 0x58}, {0x71, 0x58}, {0x72, 0x48}, {0x73, 0x48},
4461 {0x74, 0x38}, {0x75, 0x40}, {0x76, 0x34}, {0x77, 0x34},
4462 {0x78, 0x2e}, {0x79, 0x28}, {0x7a, 0x24}, {0x7b, 0x22},
4463 {0x7c, 0x0f}, {0x7d, 0x1e}, {0x7e, 0x3c}, {0x7f, 0x58},
4464 {0x80, 0x63}, {0x81, 0x6e}, {0x82, 0x77}, {0x83, 0x80},
4465 {0x84, 0x87}, {0x85, 0x8f}, {0x86, 0x9c}, {0x87, 0xa9},
4466 {0x88, 0xc0}, {0x89, 0xd4}, {0x8a, 0xe6}},
4467 {{0x6c, 0xa0}, {0x6d, 0xf0}, {0x6e, 0x90}, {0x6f, 0x80},
4468 {0x70, 0x70}, {0x71, 0x80}, {0x72, 0x60}, {0x73, 0x60},
4469 {0x74, 0x58}, {0x75, 0x60}, {0x76, 0x4c}, {0x77, 0x38},
4470 {0x78, 0x38}, {0x79, 0x2a}, {0x7a, 0x20}, {0x7b, 0x0e},
4471 {0x7c, 0x0a}, {0x7d, 0x14}, {0x7e, 0x26}, {0x7f, 0x46},
4472 {0x80, 0x54}, {0x81, 0x64}, {0x82, 0x70}, {0x83, 0x7c},
4473 {0x84, 0x87}, {0x85, 0x93}, {0x86, 0xa6}, {0x87, 0xb4},
4474 {0x88, 0xd0}, {0x89, 0xe5}, {0x8a, 0xf5}},
4475 {{0x6c, 0x60}, {0x6d, 0x80}, {0x6e, 0x60}, {0x6f, 0x80},
4476 {0x70, 0x80}, {0x71, 0x80}, {0x72, 0x88}, {0x73, 0x30},
4477 {0x74, 0x70}, {0x75, 0x68}, {0x76, 0x64}, {0x77, 0x50},
4478 {0x78, 0x3c}, {0x79, 0x22}, {0x7a, 0x10}, {0x7b, 0x08},
4479 {0x7c, 0x06}, {0x7d, 0x0e}, {0x7e, 0x1a}, {0x7f, 0x3a},
4480 {0x80, 0x4a}, {0x81, 0x5a}, {0x82, 0x6b}, {0x83, 0x7b},
4481 {0x84, 0x89}, {0x85, 0x96}, {0x86, 0xaf}, {0x87, 0xc3},
4482 {0x88, 0xe1}, {0x89, 0xf2}, {0x8a, 0xfa}},
4483 {{0x6c, 0x20}, {0x6d, 0x40}, {0x6e, 0x20}, {0x6f, 0x60},
4484 {0x70, 0x88}, {0x71, 0xc8}, {0x72, 0xc0}, {0x73, 0xb8},
4485 {0x74, 0xa8}, {0x75, 0xb8}, {0x76, 0x80}, {0x77, 0x5c},
4486 {0x78, 0x26}, {0x79, 0x10}, {0x7a, 0x08}, {0x7b, 0x04},
4487 {0x7c, 0x02}, {0x7d, 0x06}, {0x7e, 0x0a}, {0x7f, 0x22},
4488 {0x80, 0x33}, {0x81, 0x4c}, {0x82, 0x64}, {0x83, 0x7b},
4489 {0x84, 0x90}, {0x85, 0xa7}, {0x86, 0xc7}, {0x87, 0xde},
4490 {0x88, 0xf1}, {0x89, 0xf9}, {0x8a, 0xfd}},
4491 };
4194 4492
4195 val = sd->ctrls[CONTRAST].val; 4493 val = sd->ctrls[CONTRAST].val;
4196 switch (sd->sensor) { 4494 switch (sd->sensor) {
@@ -4203,7 +4501,7 @@ static void setcontrast(struct gspca_dev *gspca_dev)
4203 i2c_w_mask(sd, OV7610_REG_CNT, val >> 4, 0x0f); 4501 i2c_w_mask(sd, OV7610_REG_CNT, val >> 4, 0x0f);
4204 break; 4502 break;
4205 case SEN_OV8610: { 4503 case SEN_OV8610: {
4206 static const __u8 ctab[] = { 4504 static const u8 ctab[] = {
4207 0x03, 0x09, 0x0b, 0x0f, 0x53, 0x6f, 0x35, 0x7f 4505 0x03, 0x09, 0x0b, 0x0f, 0x53, 0x6f, 0x35, 0x7f
4208 }; 4506 };
4209 4507
@@ -4213,7 +4511,7 @@ static void setcontrast(struct gspca_dev *gspca_dev)
4213 } 4511 }
4214 case SEN_OV7620: 4512 case SEN_OV7620:
4215 case SEN_OV7620AE: { 4513 case SEN_OV7620AE: {
4216 static const __u8 ctab[] = { 4514 static const u8 ctab[] = {
4217 0x01, 0x05, 0x09, 0x11, 0x15, 0x35, 0x37, 0x57, 4515 0x01, 0x05, 0x09, 0x11, 0x15, 0x35, 0x37, 0x57,
4218 0x5b, 0xa5, 0xa7, 0xc7, 0xc9, 0xcf, 0xef, 0xff 4516 0x5b, 0xa5, 0xa7, 0xc7, 0xc9, 0xcf, 0xef, 0xff
4219 }; 4517 };
@@ -4222,9 +4520,13 @@ static void setcontrast(struct gspca_dev *gspca_dev)
4222 i2c_w(sd, 0x64, ctab[val >> 4]); 4520 i2c_w(sd, 0x64, ctab[val >> 4]);
4223 break; 4521 break;
4224 } 4522 }
4523 case SEN_OV7660:
4524 write_i2c_regvals(sd, contrast_7660[val],
4525 ARRAY_SIZE(contrast_7660[0]));
4526 break;
4225 case SEN_OV7670: 4527 case SEN_OV7670:
4226 /* check that this isn't just the same as ov7610 */ 4528 /* check that this isn't just the same as ov7610 */
4227 i2c_w(sd, OV7670_REG_CONTRAS, val >> 1); 4529 i2c_w(sd, OV7670_R56_CONTRAS, val >> 1);
4228 break; 4530 break;
4229 } 4531 }
4230} 4532}
@@ -4233,6 +4535,18 @@ static void setcolors(struct gspca_dev *gspca_dev)
4233{ 4535{
4234 struct sd *sd = (struct sd *) gspca_dev; 4536 struct sd *sd = (struct sd *) gspca_dev;
4235 int val; 4537 int val;
4538 static const struct ov_i2c_regvals colors_7660[][6] = {
4539 {{0x4f, 0x28}, {0x50, 0x2a}, {0x51, 0x02}, {0x52, 0x0a},
4540 {0x53, 0x19}, {0x54, 0x23}},
4541 {{0x4f, 0x47}, {0x50, 0x4a}, {0x51, 0x03}, {0x52, 0x11},
4542 {0x53, 0x2c}, {0x54, 0x3e}},
4543 {{0x4f, 0x66}, {0x50, 0x6b}, {0x51, 0x05}, {0x52, 0x19},
4544 {0x53, 0x40}, {0x54, 0x59}},
4545 {{0x4f, 0x84}, {0x50, 0x8b}, {0x51, 0x06}, {0x52, 0x20},
4546 {0x53, 0x53}, {0x54, 0x73}},
4547 {{0x4f, 0xa3}, {0x50, 0xab}, {0x51, 0x08}, {0x52, 0x28},
4548 {0x53, 0x66}, {0x54, 0x8e}},
4549 };
4236 4550
4237 val = sd->ctrls[COLORS].val; 4551 val = sd->ctrls[COLORS].val;
4238 switch (sd->sensor) { 4552 switch (sd->sensor) {
@@ -4256,6 +4570,10 @@ static void setcolors(struct gspca_dev *gspca_dev)
4256 case SEN_OV7648: 4570 case SEN_OV7648:
4257 i2c_w(sd, OV7610_REG_SAT, val & 0xf0); 4571 i2c_w(sd, OV7610_REG_SAT, val & 0xf0);
4258 break; 4572 break;
4573 case SEN_OV7660:
4574 write_i2c_regvals(sd, colors_7660[val],
4575 ARRAY_SIZE(colors_7660[0]));
4576 break;
4259 case SEN_OV7670: 4577 case SEN_OV7670:
4260 /* supported later once I work out how to do it 4578 /* supported later once I work out how to do it
4261 * transparently fail now! */ 4579 * transparently fail now! */
@@ -4268,38 +4586,31 @@ static void setautobright(struct gspca_dev *gspca_dev)
4268{ 4586{
4269 struct sd *sd = (struct sd *) gspca_dev; 4587 struct sd *sd = (struct sd *) gspca_dev;
4270 4588
4271 if (sd->sensor == SEN_OV7640 || sd->sensor == SEN_OV7648 ||
4272 sd->sensor == SEN_OV7670 ||
4273 sd->sensor == SEN_OV2610 || sd->sensor == SEN_OV3610)
4274 return;
4275
4276 i2c_w_mask(sd, 0x2d, sd->ctrls[AUTOBRIGHT].val ? 0x10 : 0x00, 0x10); 4589 i2c_w_mask(sd, 0x2d, sd->ctrls[AUTOBRIGHT].val ? 0x10 : 0x00, 0x10);
4277} 4590}
4278 4591
4279static void setfreq_i(struct sd *sd) 4592static void setfreq_i(struct sd *sd)
4280{ 4593{
4281 if (sd->sensor == SEN_OV2610 || sd->sensor == SEN_OV3610) 4594 if (sd->sensor == SEN_OV7660
4282 return; 4595 || sd->sensor == SEN_OV7670) {
4283
4284 if (sd->sensor == SEN_OV7670) {
4285 switch (sd->ctrls[FREQ].val) { 4596 switch (sd->ctrls[FREQ].val) {
4286 case 0: /* Banding filter disabled */ 4597 case 0: /* Banding filter disabled */
4287 i2c_w_mask(sd, OV7670_REG_COM8, 0, OV7670_COM8_BFILT); 4598 i2c_w_mask(sd, OV7670_R13_COM8, 0, OV7670_COM8_BFILT);
4288 break; 4599 break;
4289 case 1: /* 50 hz */ 4600 case 1: /* 50 hz */
4290 i2c_w_mask(sd, OV7670_REG_COM8, OV7670_COM8_BFILT, 4601 i2c_w_mask(sd, OV7670_R13_COM8, OV7670_COM8_BFILT,
4291 OV7670_COM8_BFILT); 4602 OV7670_COM8_BFILT);
4292 i2c_w_mask(sd, OV7670_REG_COM11, 0x08, 0x18); 4603 i2c_w_mask(sd, OV7670_R3B_COM11, 0x08, 0x18);
4293 break; 4604 break;
4294 case 2: /* 60 hz */ 4605 case 2: /* 60 hz */
4295 i2c_w_mask(sd, OV7670_REG_COM8, OV7670_COM8_BFILT, 4606 i2c_w_mask(sd, OV7670_R13_COM8, OV7670_COM8_BFILT,
4296 OV7670_COM8_BFILT); 4607 OV7670_COM8_BFILT);
4297 i2c_w_mask(sd, OV7670_REG_COM11, 0x00, 0x18); 4608 i2c_w_mask(sd, OV7670_R3B_COM11, 0x00, 0x18);
4298 break; 4609 break;
4299 case 3: /* Auto hz */ 4610 case 3: /* Auto hz - ov7670 only */
4300 i2c_w_mask(sd, OV7670_REG_COM8, OV7670_COM8_BFILT, 4611 i2c_w_mask(sd, OV7670_R13_COM8, OV7670_COM8_BFILT,
4301 OV7670_COM8_BFILT); 4612 OV7670_COM8_BFILT);
4302 i2c_w_mask(sd, OV7670_REG_COM11, OV7670_COM11_HZAUTO, 4613 i2c_w_mask(sd, OV7670_R3B_COM11, OV7670_COM11_HZAUTO,
4303 0x18); 4614 0x18);
4304 break; 4615 break;
4305 } 4616 }
@@ -4443,14 +4754,14 @@ static const __devinitdata struct usb_device_id device_table[] = {
4443 {USB_DEVICE(0x041e, 0x4060), .driver_info = BRIDGE_OV519 }, 4754 {USB_DEVICE(0x041e, 0x4060), .driver_info = BRIDGE_OV519 },
4444 {USB_DEVICE(0x041e, 0x4061), .driver_info = BRIDGE_OV519 }, 4755 {USB_DEVICE(0x041e, 0x4061), .driver_info = BRIDGE_OV519 },
4445 {USB_DEVICE(0x041e, 0x4064), 4756 {USB_DEVICE(0x041e, 0x4064),
4446 .driver_info = BRIDGE_OV519 | BRIDGE_INVERT_LED }, 4757 .driver_info = BRIDGE_OV519 | BRIDGE_INVERT_LED },
4447 {USB_DEVICE(0x041e, 0x4067), .driver_info = BRIDGE_OV519 }, 4758 {USB_DEVICE(0x041e, 0x4067), .driver_info = BRIDGE_OV519 },
4448 {USB_DEVICE(0x041e, 0x4068), 4759 {USB_DEVICE(0x041e, 0x4068),
4449 .driver_info = BRIDGE_OV519 | BRIDGE_INVERT_LED }, 4760 .driver_info = BRIDGE_OV519 | BRIDGE_INVERT_LED },
4450 {USB_DEVICE(0x045e, 0x028c), .driver_info = BRIDGE_OV519 }, 4761 {USB_DEVICE(0x045e, 0x028c), .driver_info = BRIDGE_OV519 },
4451 {USB_DEVICE(0x054c, 0x0154), .driver_info = BRIDGE_OV519 }, 4762 {USB_DEVICE(0x054c, 0x0154), .driver_info = BRIDGE_OV519 },
4452 {USB_DEVICE(0x054c, 0x0155), 4763 {USB_DEVICE(0x054c, 0x0155),
4453 .driver_info = BRIDGE_OV519 | BRIDGE_INVERT_LED }, 4764 .driver_info = BRIDGE_OV519 | BRIDGE_INVERT_LED },
4454 {USB_DEVICE(0x05a9, 0x0511), .driver_info = BRIDGE_OV511 }, 4765 {USB_DEVICE(0x05a9, 0x0511), .driver_info = BRIDGE_OV511 },
4455 {USB_DEVICE(0x05a9, 0x0518), .driver_info = BRIDGE_OV518 }, 4766 {USB_DEVICE(0x05a9, 0x0518), .driver_info = BRIDGE_OV518 },
4456 {USB_DEVICE(0x05a9, 0x0519), .driver_info = BRIDGE_OV519 }, 4767 {USB_DEVICE(0x05a9, 0x0519), .driver_info = BRIDGE_OV519 },
@@ -4464,7 +4775,7 @@ static const __devinitdata struct usb_device_id device_table[] = {
4464 {USB_DEVICE(0x0b62, 0x0059), .driver_info = BRIDGE_OVFX2 }, 4775 {USB_DEVICE(0x0b62, 0x0059), .driver_info = BRIDGE_OVFX2 },
4465 {USB_DEVICE(0x0e96, 0xc001), .driver_info = BRIDGE_OVFX2 }, 4776 {USB_DEVICE(0x0e96, 0xc001), .driver_info = BRIDGE_OVFX2 },
4466 {USB_DEVICE(0x1046, 0x9967), .driver_info = BRIDGE_W9968CF }, 4777 {USB_DEVICE(0x1046, 0x9967), .driver_info = BRIDGE_W9968CF },
4467 {USB_DEVICE(0x8020, 0xEF04), .driver_info = BRIDGE_OVFX2 }, 4778 {USB_DEVICE(0x8020, 0xef04), .driver_info = BRIDGE_OVFX2 },
4468 {} 4779 {}
4469}; 4780};
4470 4781
diff --git a/drivers/media/video/gspca/ov534.c b/drivers/media/video/gspca/ov534.c
index 88ef03f6235b..0edf93973b1c 100644
--- a/drivers/media/video/gspca/ov534.c
+++ b/drivers/media/video/gspca/ov534.c
@@ -1243,34 +1243,26 @@ static int sd_querymenu(struct gspca_dev *gspca_dev,
1243} 1243}
1244 1244
1245/* get stream parameters (framerate) */ 1245/* get stream parameters (framerate) */
1246static int sd_get_streamparm(struct gspca_dev *gspca_dev, 1246static void sd_get_streamparm(struct gspca_dev *gspca_dev,
1247 struct v4l2_streamparm *parm) 1247 struct v4l2_streamparm *parm)
1248{ 1248{
1249 struct v4l2_captureparm *cp = &parm->parm.capture; 1249 struct v4l2_captureparm *cp = &parm->parm.capture;
1250 struct v4l2_fract *tpf = &cp->timeperframe; 1250 struct v4l2_fract *tpf = &cp->timeperframe;
1251 struct sd *sd = (struct sd *) gspca_dev; 1251 struct sd *sd = (struct sd *) gspca_dev;
1252 1252
1253 if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1254 return -EINVAL;
1255
1256 cp->capability |= V4L2_CAP_TIMEPERFRAME; 1253 cp->capability |= V4L2_CAP_TIMEPERFRAME;
1257 tpf->numerator = 1; 1254 tpf->numerator = 1;
1258 tpf->denominator = sd->frame_rate; 1255 tpf->denominator = sd->frame_rate;
1259
1260 return 0;
1261} 1256}
1262 1257
1263/* set stream parameters (framerate) */ 1258/* set stream parameters (framerate) */
1264static int sd_set_streamparm(struct gspca_dev *gspca_dev, 1259static void sd_set_streamparm(struct gspca_dev *gspca_dev,
1265 struct v4l2_streamparm *parm) 1260 struct v4l2_streamparm *parm)
1266{ 1261{
1267 struct v4l2_captureparm *cp = &parm->parm.capture; 1262 struct v4l2_captureparm *cp = &parm->parm.capture;
1268 struct v4l2_fract *tpf = &cp->timeperframe; 1263 struct v4l2_fract *tpf = &cp->timeperframe;
1269 struct sd *sd = (struct sd *) gspca_dev; 1264 struct sd *sd = (struct sd *) gspca_dev;
1270 1265
1271 if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1272 return -EINVAL;
1273
1274 /* Set requested framerate */ 1266 /* Set requested framerate */
1275 sd->frame_rate = tpf->denominator / tpf->numerator; 1267 sd->frame_rate = tpf->denominator / tpf->numerator;
1276 if (gspca_dev->streaming) 1268 if (gspca_dev->streaming)
@@ -1279,8 +1271,6 @@ static int sd_set_streamparm(struct gspca_dev *gspca_dev,
1279 /* Return the actual framerate */ 1271 /* Return the actual framerate */
1280 tpf->numerator = 1; 1272 tpf->numerator = 1;
1281 tpf->denominator = sd->frame_rate; 1273 tpf->denominator = sd->frame_rate;
1282
1283 return 0;
1284} 1274}
1285 1275
1286/* sub-driver description */ 1276/* sub-driver description */
diff --git a/drivers/media/video/gspca/ov534_9.c b/drivers/media/video/gspca/ov534_9.c
index e831f0d280ea..c5244b4b4777 100644
--- a/drivers/media/video/gspca/ov534_9.c
+++ b/drivers/media/video/gspca/ov534_9.c
@@ -945,7 +945,6 @@ static void setautogain(struct gspca_dev *gspca_dev)
945 u8 val; 945 u8 val;
946 946
947/*fixme: should adjust agc/awb/aec by different controls */ 947/*fixme: should adjust agc/awb/aec by different controls */
948 val = sd->autogain;
949 val = sccb_read(gspca_dev, 0x13); /* com8 */ 948 val = sccb_read(gspca_dev, 0x13); /* com8 */
950 sccb_write(gspca_dev, 0xff, 0x00); 949 sccb_write(gspca_dev, 0xff, 0x00);
951 if (sd->autogain) 950 if (sd->autogain)
diff --git a/drivers/media/video/gspca/pac207.c b/drivers/media/video/gspca/pac207.c
index 15e97fa4c337..96f9986305b4 100644
--- a/drivers/media/video/gspca/pac207.c
+++ b/drivers/media/video/gspca/pac207.c
@@ -162,7 +162,7 @@ static const __u8 pac207_sensor_init[][8] = {
162 {0x10, 0x12, 0x0d, 0x12, 0x0c, 0x01, 0x29, 0x84}, 162 {0x10, 0x12, 0x0d, 0x12, 0x0c, 0x01, 0x29, 0x84},
163 {0x49, 0x64, 0x64, 0x64, 0x04, 0x10, 0xf0, 0x30}, 163 {0x49, 0x64, 0x64, 0x64, 0x04, 0x10, 0xf0, 0x30},
164 {0x00, 0x00, 0x00, 0x70, 0xa0, 0xf8, 0x00, 0x00}, 164 {0x00, 0x00, 0x00, 0x70, 0xa0, 0xf8, 0x00, 0x00},
165 {0x32, 0x00, 0x96, 0x00, 0xA2, 0x02, 0xaf, 0x00}, 165 {0x32, 0x00, 0x96, 0x00, 0xa2, 0x02, 0xaf, 0x00},
166}; 166};
167 167
168static int pac207_write_regs(struct gspca_dev *gspca_dev, u16 index, 168static int pac207_write_regs(struct gspca_dev *gspca_dev, u16 index,
@@ -228,7 +228,7 @@ static int sd_config(struct gspca_dev *gspca_dev,
228 228
229 idreg[0] = pac207_read_reg(gspca_dev, 0x0000); 229 idreg[0] = pac207_read_reg(gspca_dev, 0x0000);
230 idreg[1] = pac207_read_reg(gspca_dev, 0x0001); 230 idreg[1] = pac207_read_reg(gspca_dev, 0x0001);
231 idreg[0] = ((idreg[0] & 0x0F) << 4) | ((idreg[1] & 0xf0) >> 4); 231 idreg[0] = ((idreg[0] & 0x0f) << 4) | ((idreg[1] & 0xf0) >> 4);
232 idreg[1] = idreg[1] & 0x0f; 232 idreg[1] = idreg[1] & 0x0f;
233 PDEBUG(D_PROBE, "Pixart Sensor ID 0x%02X Chips ID 0x%02X", 233 PDEBUG(D_PROBE, "Pixart Sensor ID 0x%02X Chips ID 0x%02X",
234 idreg[0], idreg[1]); 234 idreg[0], idreg[1]);
diff --git a/drivers/media/video/gspca/pac7302.c b/drivers/media/video/gspca/pac7302.c
index 55fbea7381b0..2700975abce5 100644
--- a/drivers/media/video/gspca/pac7302.c
+++ b/drivers/media/video/gspca/pac7302.c
@@ -393,7 +393,7 @@ static const __u8 page3_7302[] = {
393 393
394static void reg_w_buf(struct gspca_dev *gspca_dev, 394static void reg_w_buf(struct gspca_dev *gspca_dev,
395 __u8 index, 395 __u8 index,
396 const char *buffer, int len) 396 const u8 *buffer, int len)
397{ 397{
398 int ret; 398 int ret;
399 399
diff --git a/drivers/media/video/gspca/pac7311.c b/drivers/media/video/gspca/pac7311.c
index 7657b43b3203..6820f5d58b19 100644
--- a/drivers/media/video/gspca/pac7311.c
+++ b/drivers/media/video/gspca/pac7311.c
@@ -261,7 +261,7 @@ static const __u8 page4_7311[] = {
261 261
262static void reg_w_buf(struct gspca_dev *gspca_dev, 262static void reg_w_buf(struct gspca_dev *gspca_dev,
263 __u8 index, 263 __u8 index,
264 const char *buffer, int len) 264 const u8 *buffer, int len)
265{ 265{
266 int ret; 266 int ret;
267 267
diff --git a/drivers/media/video/gspca/sn9c20x.c b/drivers/media/video/gspca/sn9c20x.c
index 6b155ae3a746..cb08d00d0a31 100644
--- a/drivers/media/video/gspca/sn9c20x.c
+++ b/drivers/media/video/gspca/sn9c20x.c
@@ -33,6 +33,14 @@ MODULE_LICENSE("GPL");
33 33
34#define MODULE_NAME "sn9c20x" 34#define MODULE_NAME "sn9c20x"
35 35
36/*
37 * Pixel format private data
38 */
39#define SCALE_MASK 0x0f
40#define SCALE_160x120 0
41#define SCALE_320x240 1
42#define SCALE_640x480 2
43#define SCALE_1280x1024 3
36#define MODE_RAW 0x10 44#define MODE_RAW 0x10
37#define MODE_JPEG 0x20 45#define MODE_JPEG 0x20
38#define MODE_SXGA 0x80 46#define MODE_SXGA 0x80
@@ -348,47 +356,47 @@ static const struct v4l2_pix_format vga_mode[] = {
348 .bytesperline = 160, 356 .bytesperline = 160,
349 .sizeimage = 160 * 120 * 4 / 8 + 590, 357 .sizeimage = 160 * 120 * 4 / 8 + 590,
350 .colorspace = V4L2_COLORSPACE_JPEG, 358 .colorspace = V4L2_COLORSPACE_JPEG,
351 .priv = 0 | MODE_JPEG}, 359 .priv = SCALE_160x120 | MODE_JPEG},
352 {160, 120, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE, 360 {160, 120, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
353 .bytesperline = 160, 361 .bytesperline = 160,
354 .sizeimage = 160 * 120, 362 .sizeimage = 160 * 120,
355 .colorspace = V4L2_COLORSPACE_SRGB, 363 .colorspace = V4L2_COLORSPACE_SRGB,
356 .priv = 0 | MODE_RAW}, 364 .priv = SCALE_160x120 | MODE_RAW},
357 {160, 120, V4L2_PIX_FMT_SN9C20X_I420, V4L2_FIELD_NONE, 365 {160, 120, V4L2_PIX_FMT_SN9C20X_I420, V4L2_FIELD_NONE,
358 .bytesperline = 160, 366 .bytesperline = 160,
359 .sizeimage = 240 * 120, 367 .sizeimage = 240 * 120,
360 .colorspace = V4L2_COLORSPACE_SRGB, 368 .colorspace = V4L2_COLORSPACE_SRGB,
361 .priv = 0}, 369 .priv = SCALE_160x120},
362 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, 370 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
363 .bytesperline = 320, 371 .bytesperline = 320,
364 .sizeimage = 320 * 240 * 3 / 8 + 590, 372 .sizeimage = 320 * 240 * 3 / 8 + 590,
365 .colorspace = V4L2_COLORSPACE_JPEG, 373 .colorspace = V4L2_COLORSPACE_JPEG,
366 .priv = 1 | MODE_JPEG}, 374 .priv = SCALE_320x240 | MODE_JPEG},
367 {320, 240, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE, 375 {320, 240, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
368 .bytesperline = 320, 376 .bytesperline = 320,
369 .sizeimage = 320 * 240 , 377 .sizeimage = 320 * 240 ,
370 .colorspace = V4L2_COLORSPACE_SRGB, 378 .colorspace = V4L2_COLORSPACE_SRGB,
371 .priv = 1 | MODE_RAW}, 379 .priv = SCALE_320x240 | MODE_RAW},
372 {320, 240, V4L2_PIX_FMT_SN9C20X_I420, V4L2_FIELD_NONE, 380 {320, 240, V4L2_PIX_FMT_SN9C20X_I420, V4L2_FIELD_NONE,
373 .bytesperline = 320, 381 .bytesperline = 320,
374 .sizeimage = 480 * 240 , 382 .sizeimage = 480 * 240 ,
375 .colorspace = V4L2_COLORSPACE_SRGB, 383 .colorspace = V4L2_COLORSPACE_SRGB,
376 .priv = 1}, 384 .priv = SCALE_320x240},
377 {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, 385 {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
378 .bytesperline = 640, 386 .bytesperline = 640,
379 .sizeimage = 640 * 480 * 3 / 8 + 590, 387 .sizeimage = 640 * 480 * 3 / 8 + 590,
380 .colorspace = V4L2_COLORSPACE_JPEG, 388 .colorspace = V4L2_COLORSPACE_JPEG,
381 .priv = 2 | MODE_JPEG}, 389 .priv = SCALE_640x480 | MODE_JPEG},
382 {640, 480, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE, 390 {640, 480, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
383 .bytesperline = 640, 391 .bytesperline = 640,
384 .sizeimage = 640 * 480, 392 .sizeimage = 640 * 480,
385 .colorspace = V4L2_COLORSPACE_SRGB, 393 .colorspace = V4L2_COLORSPACE_SRGB,
386 .priv = 2 | MODE_RAW}, 394 .priv = SCALE_640x480 | MODE_RAW},
387 {640, 480, V4L2_PIX_FMT_SN9C20X_I420, V4L2_FIELD_NONE, 395 {640, 480, V4L2_PIX_FMT_SN9C20X_I420, V4L2_FIELD_NONE,
388 .bytesperline = 640, 396 .bytesperline = 640,
389 .sizeimage = 960 * 480, 397 .sizeimage = 960 * 480,
390 .colorspace = V4L2_COLORSPACE_SRGB, 398 .colorspace = V4L2_COLORSPACE_SRGB,
391 .priv = 2}, 399 .priv = SCALE_640x480},
392}; 400};
393 401
394static const struct v4l2_pix_format sxga_mode[] = { 402static const struct v4l2_pix_format sxga_mode[] = {
@@ -396,52 +404,75 @@ static const struct v4l2_pix_format sxga_mode[] = {
396 .bytesperline = 160, 404 .bytesperline = 160,
397 .sizeimage = 160 * 120 * 4 / 8 + 590, 405 .sizeimage = 160 * 120 * 4 / 8 + 590,
398 .colorspace = V4L2_COLORSPACE_JPEG, 406 .colorspace = V4L2_COLORSPACE_JPEG,
399 .priv = 0 | MODE_JPEG}, 407 .priv = SCALE_160x120 | MODE_JPEG},
400 {160, 120, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE, 408 {160, 120, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
401 .bytesperline = 160, 409 .bytesperline = 160,
402 .sizeimage = 160 * 120, 410 .sizeimage = 160 * 120,
403 .colorspace = V4L2_COLORSPACE_SRGB, 411 .colorspace = V4L2_COLORSPACE_SRGB,
404 .priv = 0 | MODE_RAW}, 412 .priv = SCALE_160x120 | MODE_RAW},
405 {160, 120, V4L2_PIX_FMT_SN9C20X_I420, V4L2_FIELD_NONE, 413 {160, 120, V4L2_PIX_FMT_SN9C20X_I420, V4L2_FIELD_NONE,
406 .bytesperline = 160, 414 .bytesperline = 160,
407 .sizeimage = 240 * 120, 415 .sizeimage = 240 * 120,
408 .colorspace = V4L2_COLORSPACE_SRGB, 416 .colorspace = V4L2_COLORSPACE_SRGB,
409 .priv = 0}, 417 .priv = SCALE_160x120},
410 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, 418 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
411 .bytesperline = 320, 419 .bytesperline = 320,
412 .sizeimage = 320 * 240 * 3 / 8 + 590, 420 .sizeimage = 320 * 240 * 3 / 8 + 590,
413 .colorspace = V4L2_COLORSPACE_JPEG, 421 .colorspace = V4L2_COLORSPACE_JPEG,
414 .priv = 1 | MODE_JPEG}, 422 .priv = SCALE_320x240 | MODE_JPEG},
415 {320, 240, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE, 423 {320, 240, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
416 .bytesperline = 320, 424 .bytesperline = 320,
417 .sizeimage = 320 * 240 , 425 .sizeimage = 320 * 240 ,
418 .colorspace = V4L2_COLORSPACE_SRGB, 426 .colorspace = V4L2_COLORSPACE_SRGB,
419 .priv = 1 | MODE_RAW}, 427 .priv = SCALE_320x240 | MODE_RAW},
420 {320, 240, V4L2_PIX_FMT_SN9C20X_I420, V4L2_FIELD_NONE, 428 {320, 240, V4L2_PIX_FMT_SN9C20X_I420, V4L2_FIELD_NONE,
421 .bytesperline = 320, 429 .bytesperline = 320,
422 .sizeimage = 480 * 240 , 430 .sizeimage = 480 * 240 ,
423 .colorspace = V4L2_COLORSPACE_SRGB, 431 .colorspace = V4L2_COLORSPACE_SRGB,
424 .priv = 1}, 432 .priv = SCALE_320x240},
425 {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, 433 {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
426 .bytesperline = 640, 434 .bytesperline = 640,
427 .sizeimage = 640 * 480 * 3 / 8 + 590, 435 .sizeimage = 640 * 480 * 3 / 8 + 590,
428 .colorspace = V4L2_COLORSPACE_JPEG, 436 .colorspace = V4L2_COLORSPACE_JPEG,
429 .priv = 2 | MODE_JPEG}, 437 .priv = SCALE_640x480 | MODE_JPEG},
430 {640, 480, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE, 438 {640, 480, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
431 .bytesperline = 640, 439 .bytesperline = 640,
432 .sizeimage = 640 * 480, 440 .sizeimage = 640 * 480,
433 .colorspace = V4L2_COLORSPACE_SRGB, 441 .colorspace = V4L2_COLORSPACE_SRGB,
434 .priv = 2 | MODE_RAW}, 442 .priv = SCALE_640x480 | MODE_RAW},
435 {640, 480, V4L2_PIX_FMT_SN9C20X_I420, V4L2_FIELD_NONE, 443 {640, 480, V4L2_PIX_FMT_SN9C20X_I420, V4L2_FIELD_NONE,
436 .bytesperline = 640, 444 .bytesperline = 640,
437 .sizeimage = 960 * 480, 445 .sizeimage = 960 * 480,
438 .colorspace = V4L2_COLORSPACE_SRGB, 446 .colorspace = V4L2_COLORSPACE_SRGB,
439 .priv = 2}, 447 .priv = SCALE_640x480},
440 {1280, 1024, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE, 448 {1280, 1024, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
441 .bytesperline = 1280, 449 .bytesperline = 1280,
442 .sizeimage = 1280 * 1024, 450 .sizeimage = 1280 * 1024,
443 .colorspace = V4L2_COLORSPACE_SRGB, 451 .colorspace = V4L2_COLORSPACE_SRGB,
444 .priv = 3 | MODE_RAW | MODE_SXGA}, 452 .priv = SCALE_1280x1024 | MODE_RAW | MODE_SXGA},
453};
454
455static const struct v4l2_pix_format mono_mode[] = {
456 {160, 120, V4L2_PIX_FMT_GREY, V4L2_FIELD_NONE,
457 .bytesperline = 160,
458 .sizeimage = 160 * 120,
459 .colorspace = V4L2_COLORSPACE_SRGB,
460 .priv = SCALE_160x120 | MODE_RAW},
461 {320, 240, V4L2_PIX_FMT_GREY, V4L2_FIELD_NONE,
462 .bytesperline = 320,
463 .sizeimage = 320 * 240 ,
464 .colorspace = V4L2_COLORSPACE_SRGB,
465 .priv = SCALE_320x240 | MODE_RAW},
466 {640, 480, V4L2_PIX_FMT_GREY, V4L2_FIELD_NONE,
467 .bytesperline = 640,
468 .sizeimage = 640 * 480,
469 .colorspace = V4L2_COLORSPACE_SRGB,
470 .priv = SCALE_640x480 | MODE_RAW},
471 {1280, 1024, V4L2_PIX_FMT_GREY, V4L2_FIELD_NONE,
472 .bytesperline = 1280,
473 .sizeimage = 1280 * 1024,
474 .colorspace = V4L2_COLORSPACE_SRGB,
475 .priv = SCALE_1280x1024 | MODE_RAW | MODE_SXGA},
445}; 476};
446 477
447static const s16 hsv_red_x[] = { 478static const s16 hsv_red_x[] = {
@@ -1029,16 +1060,19 @@ static struct i2c_reg_u16 mt9v011_init[] = {
1029}; 1060};
1030 1061
1031static struct i2c_reg_u16 mt9m001_init[] = { 1062static struct i2c_reg_u16 mt9m001_init[] = {
1032 {0x0d, 0x0001}, {0x0d, 0x0000}, {0x01, 0x000e}, 1063 {0x0d, 0x0001},
1033 {0x02, 0x0014}, {0x03, 0x03c1}, {0x04, 0x0501}, 1064 {0x0d, 0x0000},
1034 {0x05, 0x0083}, {0x06, 0x0006}, {0x0d, 0x0002}, 1065 {0x04, 0x0500}, /* hres = 1280 */
1035 {0x0a, 0x0000}, {0x0c, 0x0000}, {0x11, 0x0000}, 1066 {0x03, 0x0400}, /* vres = 1024 */
1036 {0x1e, 0x8000}, {0x5f, 0x8904}, {0x60, 0x0000}, 1067 {0x20, 0x1100},
1037 {0x61, 0x0000}, {0x62, 0x0498}, {0x63, 0x0000}, 1068 {0x06, 0x0010},
1038 {0x64, 0x0000}, {0x20, 0x111d}, {0x06, 0x00f2}, 1069 {0x2b, 0x0024},
1039 {0x05, 0x0013}, {0x09, 0x10f2}, {0x07, 0x0003}, 1070 {0x2e, 0x0024},
1040 {0x2b, 0x002a}, {0x2d, 0x002a}, {0x2c, 0x002a}, 1071 {0x35, 0x0024},
1041 {0x2e, 0x0029}, {0x07, 0x0002}, 1072 {0x2d, 0x0020},
1073 {0x2c, 0x0020},
1074 {0x09, 0x0ad4},
1075 {0x35, 0x0057},
1042}; 1076};
1043 1077
1044static struct i2c_reg_u16 mt9m111_init[] = { 1078static struct i2c_reg_u16 mt9m111_init[] = {
@@ -1224,8 +1258,17 @@ static int i2c_r2(struct gspca_dev *gspca_dev, u8 reg, u16 *val)
1224static int ov9650_init_sensor(struct gspca_dev *gspca_dev) 1258static int ov9650_init_sensor(struct gspca_dev *gspca_dev)
1225{ 1259{
1226 int i; 1260 int i;
1261 u16 id;
1227 struct sd *sd = (struct sd *) gspca_dev; 1262 struct sd *sd = (struct sd *) gspca_dev;
1228 1263
1264 if (i2c_r2(gspca_dev, 0x1c, &id) < 0)
1265 return -EINVAL;
1266
1267 if (id != 0x7fa2) {
1268 err("sensor id for ov9650 doesn't match (0x%04x)", id);
1269 return -ENODEV;
1270 }
1271
1229 for (i = 0; i < ARRAY_SIZE(ov9650_init); i++) { 1272 for (i = 0; i < ARRAY_SIZE(ov9650_init); i++) {
1230 if (i2c_w1(gspca_dev, ov9650_init[i].reg, 1273 if (i2c_w1(gspca_dev, ov9650_init[i].reg,
1231 ov9650_init[i].val) < 0) { 1274 ov9650_init[i].val) < 0) {
@@ -1425,6 +1468,25 @@ static int mt9m001_init_sensor(struct gspca_dev *gspca_dev)
1425{ 1468{
1426 struct sd *sd = (struct sd *) gspca_dev; 1469 struct sd *sd = (struct sd *) gspca_dev;
1427 int i; 1470 int i;
1471 u16 id;
1472
1473 if (i2c_r2(gspca_dev, 0x00, &id) < 0)
1474 return -EINVAL;
1475
1476 /* must be 0x8411 or 0x8421 for colour sensor and 8431 for bw */
1477 switch (id) {
1478 case 0x8411:
1479 case 0x8421:
1480 info("MT9M001 color sensor detected");
1481 break;
1482 case 0x8431:
1483 info("MT9M001 mono sensor detected");
1484 break;
1485 default:
1486 err("No MT9M001 chip detected, ID = %x\n", id);
1487 return -ENODEV;
1488 }
1489
1428 for (i = 0; i < ARRAY_SIZE(mt9m001_init); i++) { 1490 for (i = 0; i < ARRAY_SIZE(mt9m001_init); i++) {
1429 if (i2c_w2(gspca_dev, mt9m001_init[i].reg, 1491 if (i2c_w2(gspca_dev, mt9m001_init[i].reg,
1430 mt9m001_init[i].val) < 0) { 1492 mt9m001_init[i].val) < 0) {
@@ -1434,8 +1496,8 @@ static int mt9m001_init_sensor(struct gspca_dev *gspca_dev)
1434 } 1496 }
1435 /* disable hflip and vflip */ 1497 /* disable hflip and vflip */
1436 gspca_dev->ctrl_dis = (1 << HFLIP_IDX) | (1 << VFLIP_IDX); 1498 gspca_dev->ctrl_dis = (1 << HFLIP_IDX) | (1 << VFLIP_IDX);
1437 sd->hstart = 2; 1499 sd->hstart = 1;
1438 sd->vstart = 2; 1500 sd->vstart = 1;
1439 return 0; 1501 return 0;
1440} 1502}
1441 1503
@@ -1977,6 +2039,10 @@ static int sd_config(struct gspca_dev *gspca_dev,
1977 cam->cam_mode = sxga_mode; 2039 cam->cam_mode = sxga_mode;
1978 cam->nmodes = ARRAY_SIZE(sxga_mode); 2040 cam->nmodes = ARRAY_SIZE(sxga_mode);
1979 break; 2041 break;
2042 case SENSOR_MT9M001:
2043 cam->cam_mode = mono_mode;
2044 cam->nmodes = ARRAY_SIZE(mono_mode);
2045 break;
1980 default: 2046 default:
1981 cam->cam_mode = vga_mode; 2047 cam->cam_mode = vga_mode;
1982 cam->nmodes = ARRAY_SIZE(vga_mode); 2048 cam->nmodes = ARRAY_SIZE(vga_mode);
@@ -2075,7 +2141,6 @@ static int sd_init(struct gspca_dev *gspca_dev)
2075 case SENSOR_MT9M001: 2141 case SENSOR_MT9M001:
2076 if (mt9m001_init_sensor(gspca_dev) < 0) 2142 if (mt9m001_init_sensor(gspca_dev) < 0)
2077 return -ENODEV; 2143 return -ENODEV;
2078 info("MT9M001 sensor detected");
2079 break; 2144 break;
2080 case SENSOR_HV7131R: 2145 case SENSOR_HV7131R:
2081 if (hv7131r_init_sensor(gspca_dev) < 0) 2146 if (hv7131r_init_sensor(gspca_dev) < 0)
@@ -2173,22 +2238,22 @@ static int sd_start(struct gspca_dev *gspca_dev)
2173 else if (mode & MODE_JPEG) 2238 else if (mode & MODE_JPEG)
2174 fmt = 0x2c; 2239 fmt = 0x2c;
2175 else 2240 else
2176 fmt = 0x2f; 2241 fmt = 0x2f; /* YUV 420 */
2177 2242
2178 switch (mode & 0x0f) { 2243 switch (mode & SCALE_MASK) {
2179 case 3: 2244 case SCALE_1280x1024:
2180 scale = 0xc0; 2245 scale = 0xc0;
2181 info("Set 1280x1024"); 2246 info("Set 1280x1024");
2182 break; 2247 break;
2183 case 2: 2248 case SCALE_640x480:
2184 scale = 0x80; 2249 scale = 0x80;
2185 info("Set 640x480"); 2250 info("Set 640x480");
2186 break; 2251 break;
2187 case 1: 2252 case SCALE_320x240:
2188 scale = 0x90; 2253 scale = 0x90;
2189 info("Set 320x240"); 2254 info("Set 320x240");
2190 break; 2255 break;
2191 case 0: 2256 case SCALE_160x120:
2192 scale = 0xa0; 2257 scale = 0xa0;
2193 info("Set 160x120"); 2258 info("Set 160x120");
2194 break; 2259 break;
diff --git a/drivers/media/video/gspca/sonixb.c b/drivers/media/video/gspca/sonixb.c
index 706f96f92654..73504a3f87b7 100644
--- a/drivers/media/video/gspca/sonixb.c
+++ b/drivers/media/video/gspca/sonixb.c
@@ -56,6 +56,8 @@ struct sd {
56 int prev_avg_lum; 56 int prev_avg_lum;
57 int exp_too_low_cnt; 57 int exp_too_low_cnt;
58 int exp_too_high_cnt; 58 int exp_too_high_cnt;
59 int header_read;
60 u8 header[12]; /* Header without sof marker */
59 61
60 unsigned short exposure; 62 unsigned short exposure;
61 unsigned char gain; 63 unsigned char gain;
@@ -71,14 +73,15 @@ struct sd {
71#define BRIDGE_103 1 73#define BRIDGE_103 1
72 74
73 __u8 sensor; /* Type of image sensor chip */ 75 __u8 sensor; /* Type of image sensor chip */
74#define SENSOR_HV7131R 0 76#define SENSOR_HV7131D 0
75#define SENSOR_OV6650 1 77#define SENSOR_HV7131R 1
76#define SENSOR_OV7630 2 78#define SENSOR_OV6650 2
77#define SENSOR_PAS106 3 79#define SENSOR_OV7630 3
78#define SENSOR_PAS202 4 80#define SENSOR_PAS106 4
79#define SENSOR_TAS5110C 5 81#define SENSOR_PAS202 5
80#define SENSOR_TAS5110D 6 82#define SENSOR_TAS5110C 6
81#define SENSOR_TAS5130CXX 7 83#define SENSOR_TAS5110D 7
84#define SENSOR_TAS5130CXX 8
82 __u8 reg11; 85 __u8 reg11;
83}; 86};
84 87
@@ -303,14 +306,29 @@ static const struct v4l2_pix_format sif_mode[] = {
303 .priv = 0}, 306 .priv = 0},
304}; 307};
305 308
306static const __u8 initHv7131[] = { 309static const __u8 initHv7131d[] = {
310 0x04, 0x03, 0x00, 0x04, 0x00, 0x00, 0x00, 0x80, 0x11, 0x00, 0x00, 0x00,
311 0x00, 0x00,
312 0x00, 0x00, 0x00, 0x02, 0x02, 0x00,
313 0x28, 0x1e, 0x60, 0x8e, 0x42,
314 0x1d, 0x10, 0x02, 0x03, 0x0f, 0x0c
315};
316static const __u8 hv7131d_sensor_init[][8] = {
317 {0xa0, 0x11, 0x01, 0x04, 0x00, 0x00, 0x00, 0x17},
318 {0xa0, 0x11, 0x02, 0x00, 0x00, 0x00, 0x00, 0x17},
319 {0xa0, 0x11, 0x28, 0x00, 0x00, 0x00, 0x00, 0x17},
320 {0xa0, 0x11, 0x30, 0x30, 0x00, 0x00, 0x00, 0x17}, /* reset level */
321 {0xa0, 0x11, 0x34, 0x02, 0x00, 0x00, 0x00, 0x17}, /* pixel bias volt */
322};
323
324static const __u8 initHv7131r[] = {
307 0x46, 0x77, 0x00, 0x04, 0x00, 0x00, 0x00, 0x80, 0x11, 0x00, 0x00, 0x00, 325 0x46, 0x77, 0x00, 0x04, 0x00, 0x00, 0x00, 0x80, 0x11, 0x00, 0x00, 0x00,
308 0x00, 0x00, 326 0x00, 0x00,
309 0x00, 0x00, 0x00, 0x02, 0x01, 0x00, 327 0x00, 0x00, 0x00, 0x02, 0x01, 0x00,
310 0x28, 0x1e, 0x60, 0x8a, 0x20, 328 0x28, 0x1e, 0x60, 0x8a, 0x20,
311 0x1d, 0x10, 0x02, 0x03, 0x0f, 0x0c 329 0x1d, 0x10, 0x02, 0x03, 0x0f, 0x0c
312}; 330};
313static const __u8 hv7131_sensor_init[][8] = { 331static const __u8 hv7131r_sensor_init[][8] = {
314 {0xc0, 0x11, 0x31, 0x38, 0x2a, 0x2e, 0x00, 0x10}, 332 {0xc0, 0x11, 0x31, 0x38, 0x2a, 0x2e, 0x00, 0x10},
315 {0xa0, 0x11, 0x01, 0x08, 0x2a, 0x2e, 0x00, 0x10}, 333 {0xa0, 0x11, 0x01, 0x08, 0x2a, 0x2e, 0x00, 0x10},
316 {0xb0, 0x11, 0x20, 0x00, 0xd0, 0x2e, 0x00, 0x10}, 334 {0xb0, 0x11, 0x20, 0x00, 0xd0, 0x2e, 0x00, 0x10},
@@ -340,7 +358,7 @@ static const __u8 ov6650_sensor_init[][8] = {
340 * but blue wont be there. Avoid this data ... */ 358 * but blue wont be there. Avoid this data ... */
341 {0xd0, 0x60, 0x26, 0x01, 0x14, 0xd8, 0xa4, 0x10}, /* format out? */ 359 {0xd0, 0x60, 0x26, 0x01, 0x14, 0xd8, 0xa4, 0x10}, /* format out? */
342 {0xd0, 0x60, 0x26, 0x01, 0x14, 0xd8, 0xa4, 0x10}, 360 {0xd0, 0x60, 0x26, 0x01, 0x14, 0xd8, 0xa4, 0x10},
343 {0xa0, 0x60, 0x30, 0x3d, 0x0A, 0xd8, 0xa4, 0x10}, 361 {0xa0, 0x60, 0x30, 0x3d, 0x0a, 0xd8, 0xa4, 0x10},
344 /* Enable rgb brightness control */ 362 /* Enable rgb brightness control */
345 {0xa0, 0x60, 0x61, 0x08, 0x00, 0x00, 0x00, 0x10}, 363 {0xa0, 0x60, 0x61, 0x08, 0x00, 0x00, 0x00, 0x10},
346 /* HDG: Note windows uses the line below, which sets both register 0x60 364 /* HDG: Note windows uses the line below, which sets both register 0x60
@@ -505,7 +523,7 @@ static const __u8 pas202_sensor_init[][8] = {
505 {0xa0, 0x40, 0x02, 0x04, 0x00, 0x00, 0x00, 0x10}, 523 {0xa0, 0x40, 0x02, 0x04, 0x00, 0x00, 0x00, 0x10},
506 {0xd0, 0x40, 0x04, 0x07, 0x34, 0x00, 0x09, 0x10}, 524 {0xd0, 0x40, 0x04, 0x07, 0x34, 0x00, 0x09, 0x10},
507 {0xd0, 0x40, 0x08, 0x01, 0x00, 0x00, 0x01, 0x10}, 525 {0xd0, 0x40, 0x08, 0x01, 0x00, 0x00, 0x01, 0x10},
508 {0xd0, 0x40, 0x0C, 0x00, 0x0C, 0x01, 0x32, 0x10}, 526 {0xd0, 0x40, 0x0c, 0x00, 0x0c, 0x01, 0x32, 0x10},
509 {0xd0, 0x40, 0x10, 0x00, 0x01, 0x00, 0x63, 0x10}, 527 {0xd0, 0x40, 0x10, 0x00, 0x01, 0x00, 0x63, 0x10},
510 {0xa0, 0x40, 0x15, 0x70, 0x01, 0x00, 0x63, 0x10}, 528 {0xa0, 0x40, 0x15, 0x70, 0x01, 0x00, 0x63, 0x10},
511 {0xa0, 0x40, 0x18, 0x00, 0x01, 0x00, 0x63, 0x10}, 529 {0xa0, 0x40, 0x18, 0x00, 0x01, 0x00, 0x63, 0x10},
@@ -551,7 +569,8 @@ static const __u8 tas5130_sensor_init[][8] = {
551}; 569};
552 570
553static struct sensor_data sensor_data[] = { 571static struct sensor_data sensor_data[] = {
554SENS(initHv7131, NULL, hv7131_sensor_init, NULL, NULL, 0, NO_EXPO|NO_FREQ, 0), 572SENS(initHv7131d, NULL, hv7131d_sensor_init, NULL, NULL, F_GAIN, NO_BRIGHTNESS|NO_FREQ, 0),
573SENS(initHv7131r, NULL, hv7131r_sensor_init, NULL, NULL, 0, NO_BRIGHTNESS|NO_EXPO|NO_FREQ, 0),
555SENS(initOv6650, NULL, ov6650_sensor_init, NULL, NULL, F_GAIN|F_SIF, 0, 0x60), 574SENS(initOv6650, NULL, ov6650_sensor_init, NULL, NULL, F_GAIN|F_SIF, 0, 0x60),
556SENS(initOv7630, initOv7630_3, ov7630_sensor_init, NULL, ov7630_sensor_init_3, 575SENS(initOv7630, initOv7630_3, ov7630_sensor_init, NULL, ov7630_sensor_init_3,
557 F_GAIN, 0, 0x21), 576 F_GAIN, 0, 0x21),
@@ -701,7 +720,18 @@ static void setsensorgain(struct gspca_dev *gspca_dev)
701 unsigned char gain = sd->gain; 720 unsigned char gain = sd->gain;
702 721
703 switch (sd->sensor) { 722 switch (sd->sensor) {
723 case SENSOR_HV7131D: {
724 __u8 i2c[] =
725 {0xc0, 0x11, 0x31, 0x00, 0x00, 0x00, 0x00, 0x17};
704 726
727 i2c[3] = 0x3f - (sd->gain / 4);
728 i2c[4] = 0x3f - (sd->gain / 4);
729 i2c[5] = 0x3f - (sd->gain / 4);
730
731 if (i2c_w(gspca_dev, i2c) < 0)
732 goto err;
733 break;
734 }
705 case SENSOR_TAS5110C: 735 case SENSOR_TAS5110C:
706 case SENSOR_TAS5110D: { 736 case SENSOR_TAS5110D: {
707 __u8 i2c[] = 737 __u8 i2c[] =
@@ -788,6 +818,23 @@ static void setexposure(struct gspca_dev *gspca_dev)
788 struct sd *sd = (struct sd *) gspca_dev; 818 struct sd *sd = (struct sd *) gspca_dev;
789 819
790 switch (sd->sensor) { 820 switch (sd->sensor) {
821 case SENSOR_HV7131D: {
822 /* Note the datasheet wrongly says line mode exposure uses reg
823 0x26 and 0x27, testing has shown 0x25 + 0x26 */
824 __u8 i2c[] = {0xc0, 0x11, 0x25, 0x00, 0x00, 0x00, 0x00, 0x17};
825 /* The HV7131D's exposure goes from 0 - 65535, we scale our
826 exposure of 0-1023 to 0-6138. There are 2 reasons for this:
827 1) This puts our exposure knee of 200 at approx the point
828 where the framerate starts dropping
829 2) At 6138 the framerate has already dropped to 2 fps,
830 going any lower makes little sense */
831 __u16 reg = sd->exposure * 6;
832 i2c[3] = reg >> 8;
833 i2c[4] = reg & 0xff;
834 if (i2c_w(gspca_dev, i2c) != 0)
835 goto err;
836 break;
837 }
791 case SENSOR_TAS5110C: 838 case SENSOR_TAS5110C:
792 case SENSOR_TAS5110D: { 839 case SENSOR_TAS5110D: {
793 /* register 19's high nibble contains the sn9c10x clock divider 840 /* register 19's high nibble contains the sn9c10x clock divider
@@ -1177,13 +1224,10 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
1177 sd_init(gspca_dev); 1224 sd_init(gspca_dev);
1178} 1225}
1179 1226
1180static void sd_pkt_scan(struct gspca_dev *gspca_dev, 1227static u8* find_sof(struct gspca_dev *gspca_dev, u8 *data, int len)
1181 u8 *data, /* isoc packet */
1182 int len) /* iso packet length */
1183{ 1228{
1184 int i;
1185 struct sd *sd = (struct sd *) gspca_dev; 1229 struct sd *sd = (struct sd *) gspca_dev;
1186 struct cam *cam = &gspca_dev->cam; 1230 int i, header_size = (sd->bridge == BRIDGE_103) ? 18 : 12;
1187 1231
1188 /* frames start with: 1232 /* frames start with:
1189 * ff ff 00 c4 c4 96 synchro 1233 * ff ff 00 c4 c4 96 synchro
@@ -1194,58 +1238,84 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
1194 * ll mm brightness sum outside auto exposure 1238 * ll mm brightness sum outside auto exposure
1195 * (xx xx xx xx xx) audio values for snc103 1239 * (xx xx xx xx xx) audio values for snc103
1196 */ 1240 */
1197 if (len > 6 && len < 24) { 1241 for (i = 0; i < len; i++) {
1198 for (i = 0; i < len - 6; i++) { 1242 switch (sd->header_read) {
1199 if (data[0 + i] == 0xff 1243 case 0:
1200 && data[1 + i] == 0xff 1244 if (data[i] == 0xff)
1201 && data[2 + i] == 0x00 1245 sd->header_read++;
1202 && data[3 + i] == 0xc4 1246 break;
1203 && data[4 + i] == 0xc4 1247 case 1:
1204 && data[5 + i] == 0x96) { /* start of frame */ 1248 if (data[i] == 0xff)
1205 int lum = -1; 1249 sd->header_read++;
1206 int pkt_type = LAST_PACKET; 1250 else
1207 int fr_h_sz = (sd->bridge == BRIDGE_103) ? 1251 sd->header_read = 0;
1208 18 : 12; 1252 break;
1209 1253 case 2:
1210 if (len - i < fr_h_sz) { 1254 if (data[i] == 0x00)
1211 PDEBUG(D_STREAM, "packet too short to" 1255 sd->header_read++;
1212 " get avg brightness"); 1256 else if (data[i] != 0xff)
1213 } else if (sd->bridge == BRIDGE_103) { 1257 sd->header_read = 0;
1214 lum = data[i + 9] + 1258 break;
1215 (data[i + 10] << 8); 1259 case 3:
1216 } else { 1260 if (data[i] == 0xc4)
1217 lum = data[i + 8] + (data[i + 9] << 8); 1261 sd->header_read++;
1218 } 1262 else if (data[i] == 0xff)
1219 /* When exposure changes midway a frame we 1263 sd->header_read = 1;
1220 get a lum of 0 in this case drop 2 frames 1264 else
1221 as the frames directly after an exposure 1265 sd->header_read = 0;
1222 change have an unstable image. Sometimes lum 1266 break;
1223 *really* is 0 (cam used in low light with 1267 case 4:
1224 low exposure setting), so do not drop frames 1268 if (data[i] == 0xc4)
1225 if the previous lum was 0 too. */ 1269 sd->header_read++;
1226 if (lum == 0 && sd->prev_avg_lum != 0) { 1270 else if (data[i] == 0xff)
1227 lum = -1; 1271 sd->header_read = 1;
1228 sd->frames_to_drop = 2; 1272 else
1229 sd->prev_avg_lum = 0; 1273 sd->header_read = 0;
1230 } else 1274 break;
1231 sd->prev_avg_lum = lum; 1275 case 5:
1232 atomic_set(&sd->avg_lum, lum); 1276 if (data[i] == 0x96)
1233 1277 sd->header_read++;
1234 if (sd->frames_to_drop) { 1278 else if (data[i] == 0xff)
1235 sd->frames_to_drop--; 1279 sd->header_read = 1;
1236 pkt_type = DISCARD_PACKET; 1280 else
1237 } 1281 sd->header_read = 0;
1238 1282 break;
1239 gspca_frame_add(gspca_dev, pkt_type, 1283 default:
1240 NULL, 0); 1284 sd->header[sd->header_read - 6] = data[i];
1241 data += i + fr_h_sz; 1285 sd->header_read++;
1242 len -= i + fr_h_sz; 1286 if (sd->header_read == header_size) {
1243 gspca_frame_add(gspca_dev, FIRST_PACKET, 1287 sd->header_read = 0;
1244 data, len); 1288 return data + i + 1;
1245 return;
1246 } 1289 }
1247 } 1290 }
1248 } 1291 }
1292 return NULL;
1293}
1294
1295static void sd_pkt_scan(struct gspca_dev *gspca_dev,
1296 u8 *data, /* isoc packet */
1297 int len) /* iso packet length */
1298{
1299 int fr_h_sz = 0, lum_offset = 0, len_after_sof = 0;
1300 struct sd *sd = (struct sd *) gspca_dev;
1301 struct cam *cam = &gspca_dev->cam;
1302 u8 *sof;
1303
1304 sof = find_sof(gspca_dev, data, len);
1305 if (sof) {
1306 if (sd->bridge == BRIDGE_103) {
1307 fr_h_sz = 18;
1308 lum_offset = 3;
1309 } else {
1310 fr_h_sz = 12;
1311 lum_offset = 2;
1312 }
1313
1314 len_after_sof = len - (sof - data);
1315 len = (sof - data) - fr_h_sz;
1316 if (len < 0)
1317 len = 0;
1318 }
1249 1319
1250 if (cam->cam_mode[gspca_dev->curr_mode].priv & MODE_RAW) { 1320 if (cam->cam_mode[gspca_dev->curr_mode].priv & MODE_RAW) {
1251 /* In raw mode we sometimes get some garbage after the frame 1321 /* In raw mode we sometimes get some garbage after the frame
@@ -1259,6 +1329,33 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
1259 } 1329 }
1260 1330
1261 gspca_frame_add(gspca_dev, INTER_PACKET, data, len); 1331 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
1332
1333 if (sof) {
1334 int lum = sd->header[lum_offset] +
1335 (sd->header[lum_offset + 1] << 8);
1336
1337 /* When exposure changes midway a frame we
1338 get a lum of 0 in this case drop 2 frames
1339 as the frames directly after an exposure
1340 change have an unstable image. Sometimes lum
1341 *really* is 0 (cam used in low light with
1342 low exposure setting), so do not drop frames
1343 if the previous lum was 0 too. */
1344 if (lum == 0 && sd->prev_avg_lum != 0) {
1345 lum = -1;
1346 sd->frames_to_drop = 2;
1347 sd->prev_avg_lum = 0;
1348 } else
1349 sd->prev_avg_lum = lum;
1350 atomic_set(&sd->avg_lum, lum);
1351
1352 if (sd->frames_to_drop)
1353 sd->frames_to_drop--;
1354 else
1355 gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
1356
1357 gspca_frame_add(gspca_dev, FIRST_PACKET, sof, len_after_sof);
1358 }
1262} 1359}
1263 1360
1264static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val) 1361static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
@@ -1431,9 +1528,7 @@ static const struct sd_desc sd_desc = {
1431static const struct usb_device_id device_table[] __devinitconst = { 1528static const struct usb_device_id device_table[] __devinitconst = {
1432 {USB_DEVICE(0x0c45, 0x6001), SB(TAS5110C, 102)}, /* TAS5110C1B */ 1529 {USB_DEVICE(0x0c45, 0x6001), SB(TAS5110C, 102)}, /* TAS5110C1B */
1433 {USB_DEVICE(0x0c45, 0x6005), SB(TAS5110C, 101)}, /* TAS5110C1B */ 1530 {USB_DEVICE(0x0c45, 0x6005), SB(TAS5110C, 101)}, /* TAS5110C1B */
1434#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
1435 {USB_DEVICE(0x0c45, 0x6007), SB(TAS5110D, 101)}, /* TAS5110D */ 1531 {USB_DEVICE(0x0c45, 0x6007), SB(TAS5110D, 101)}, /* TAS5110D */
1436#endif
1437 {USB_DEVICE(0x0c45, 0x6009), SB(PAS106, 101)}, 1532 {USB_DEVICE(0x0c45, 0x6009), SB(PAS106, 101)},
1438 {USB_DEVICE(0x0c45, 0x600d), SB(PAS106, 101)}, 1533 {USB_DEVICE(0x0c45, 0x600d), SB(PAS106, 101)},
1439 {USB_DEVICE(0x0c45, 0x6011), SB(OV6650, 101)}, 1534 {USB_DEVICE(0x0c45, 0x6011), SB(OV6650, 101)},
@@ -1444,9 +1539,12 @@ static const struct usb_device_id device_table[] __devinitconst = {
1444#endif 1539#endif
1445 {USB_DEVICE(0x0c45, 0x6028), SB(PAS202, 102)}, 1540 {USB_DEVICE(0x0c45, 0x6028), SB(PAS202, 102)},
1446 {USB_DEVICE(0x0c45, 0x6029), SB(PAS106, 102)}, 1541 {USB_DEVICE(0x0c45, 0x6029), SB(PAS106, 102)},
1542 {USB_DEVICE(0x0c45, 0x602a), SB(HV7131D, 102)},
1543 /* {USB_DEVICE(0x0c45, 0x602b), SB(MI0343, 102)}, */
1447 {USB_DEVICE(0x0c45, 0x602c), SB(OV7630, 102)}, 1544 {USB_DEVICE(0x0c45, 0x602c), SB(OV7630, 102)},
1448 {USB_DEVICE(0x0c45, 0x602d), SB(HV7131R, 102)}, 1545 {USB_DEVICE(0x0c45, 0x602d), SB(HV7131R, 102)},
1449 {USB_DEVICE(0x0c45, 0x602e), SB(OV7630, 102)}, 1546 {USB_DEVICE(0x0c45, 0x602e), SB(OV7630, 102)},
1547 /* {USB_DEVICE(0x0c45, 0x602b), SB(MI03XX, 102)}, */ /* MI0343 MI0360 MI0330 */
1450 {USB_DEVICE(0x0c45, 0x608f), SB(OV7630, 103)}, 1548 {USB_DEVICE(0x0c45, 0x608f), SB(OV7630, 103)},
1451#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE 1549#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
1452 {USB_DEVICE(0x0c45, 0x60af), SB(PAS202, 103)}, 1550 {USB_DEVICE(0x0c45, 0x60af), SB(PAS202, 103)},
diff --git a/drivers/media/video/gspca/sonixj.c b/drivers/media/video/gspca/sonixj.c
index e23de57e2c73..2d0bb17a30a2 100644
--- a/drivers/media/video/gspca/sonixj.c
+++ b/drivers/media/video/gspca/sonixj.c
@@ -1598,22 +1598,22 @@ static void i2c_w_seq(struct gspca_dev *gspca_dev,
1598 } 1598 }
1599} 1599}
1600 1600
1601/* check the ID of the hv7131 sensor */
1602/* this sequence is needed because it activates the sensor */
1601static void hv7131r_probe(struct gspca_dev *gspca_dev) 1603static void hv7131r_probe(struct gspca_dev *gspca_dev)
1602{ 1604{
1603 i2c_w1(gspca_dev, 0x02, 0); /* sensor wakeup */ 1605 i2c_w1(gspca_dev, 0x02, 0); /* sensor wakeup */
1604 msleep(10); 1606 msleep(10);
1605 reg_w1(gspca_dev, 0x02, 0x66); /* Gpio on */ 1607 reg_w1(gspca_dev, 0x02, 0x66); /* Gpio on */
1606 msleep(10); 1608 msleep(10);
1607 i2c_r(gspca_dev, 0, 5); /* read sensor id */ 1609 i2c_r(gspca_dev, 0, 5); /* read sensor id */
1608 if (gspca_dev->usb_buf[0] == 0x02 1610 if (gspca_dev->usb_buf[0] == 0x02 /* chip ID (02 is R) */
1609 && gspca_dev->usb_buf[1] == 0x09 1611 && gspca_dev->usb_buf[1] == 0x09
1610 && gspca_dev->usb_buf[2] == 0x01 1612 && gspca_dev->usb_buf[2] == 0x01) {
1611 && gspca_dev->usb_buf[3] == 0x00 1613 PDEBUG(D_PROBE, "Sensor HV7131R found");
1612 && gspca_dev->usb_buf[4] == 0x00) {
1613 PDEBUG(D_PROBE, "Sensor sn9c102P HV7131R found");
1614 return; 1614 return;
1615 } 1615 }
1616 PDEBUG(D_PROBE, "Sensor 0x%02x 0x%02x 0x%02x - sn9c102P not found", 1616 warn("Erroneous HV7131R ID 0x%02x 0x%02x 0x%02x",
1617 gspca_dev->usb_buf[0], gspca_dev->usb_buf[1], 1617 gspca_dev->usb_buf[0], gspca_dev->usb_buf[1],
1618 gspca_dev->usb_buf[2]); 1618 gspca_dev->usb_buf[2]);
1619} 1619}
@@ -2533,7 +2533,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
2533 init = om6802_sensor_param1; 2533 init = om6802_sensor_param1;
2534 if (!mode) { /* if 640x480 */ 2534 if (!mode) { /* if 640x480 */
2535 reg17 &= ~MCK_SIZE_MASK; 2535 reg17 &= ~MCK_SIZE_MASK;
2536 reg17 |= 0x01; /* clock / 4 */ 2536 reg17 |= 0x04; /* clock / 4 */
2537 } 2537 }
2538 break; 2538 break;
2539 case SENSOR_OV7630: 2539 case SENSOR_OV7630:
diff --git a/drivers/media/video/gspca/spca561.c b/drivers/media/video/gspca/spca561.c
index ad73f4812c05..3a162c6d5466 100644
--- a/drivers/media/video/gspca/spca561.c
+++ b/drivers/media/video/gspca/spca561.c
@@ -597,7 +597,7 @@ static void setgain(struct gspca_dev *gspca_dev)
597 else if (sd->gain < 128) 597 else if (sd->gain < 128)
598 gspca_dev->usb_buf[0] = (sd->gain / 2) | 0x40; 598 gspca_dev->usb_buf[0] = (sd->gain / 2) | 0x40;
599 else 599 else
600 gspca_dev->usb_buf[0] = (sd->gain / 4) | 0xC0; 600 gspca_dev->usb_buf[0] = (sd->gain / 4) | 0xc0;
601 601
602 gspca_dev->usb_buf[1] = 0; 602 gspca_dev->usb_buf[1] = 0;
603 reg_w_buf(gspca_dev, 0x8335, 2); 603 reg_w_buf(gspca_dev, 0x8335, 2);
diff --git a/drivers/media/video/gspca/sq905c.c b/drivers/media/video/gspca/sq905c.c
index c2e88b5303cb..8ba199543856 100644
--- a/drivers/media/video/gspca/sq905c.c
+++ b/drivers/media/video/gspca/sq905c.c
@@ -301,6 +301,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
301static const __devinitdata struct usb_device_id device_table[] = { 301static const __devinitdata struct usb_device_id device_table[] = {
302 {USB_DEVICE(0x2770, 0x905c)}, 302 {USB_DEVICE(0x2770, 0x905c)},
303 {USB_DEVICE(0x2770, 0x9050)}, 303 {USB_DEVICE(0x2770, 0x9050)},
304 {USB_DEVICE(0x2770, 0x9051)},
304 {USB_DEVICE(0x2770, 0x9052)}, 305 {USB_DEVICE(0x2770, 0x9052)},
305 {USB_DEVICE(0x2770, 0x913d)}, 306 {USB_DEVICE(0x2770, 0x913d)},
306 {} 307 {}
diff --git a/drivers/media/video/gspca/sq930x.c b/drivers/media/video/gspca/sq930x.c
index 3e4b0b94c700..a4a98811b9e3 100644
--- a/drivers/media/video/gspca/sq930x.c
+++ b/drivers/media/video/gspca/sq930x.c
@@ -687,10 +687,19 @@ static void cmos_probe(struct gspca_dev *gspca_dev)
687 if (gspca_dev->usb_buf[0] != 0) 687 if (gspca_dev->usb_buf[0] != 0)
688 break; 688 break;
689 } 689 }
690 if (i >= ARRAY_SIZE(probe_order)) 690 if (i >= ARRAY_SIZE(probe_order)) {
691 err("Unknown sensor"); 691 err("Unknown sensor");
692 else 692 gspca_dev->usb_err = -EINVAL;
693 sd->sensor = probe_order[i]; 693 return;
694 }
695 sd->sensor = probe_order[i];
696 switch (sd->sensor) {
697 case SENSOR_OV7660:
698 case SENSOR_OV9630:
699 err("Sensor %s not yet treated", sensor_tb[sd->sensor].name);
700 gspca_dev->usb_err = -EINVAL;
701 break;
702 }
694} 703}
695 704
696static void mt9v111_init(struct gspca_dev *gspca_dev) 705static void mt9v111_init(struct gspca_dev *gspca_dev)
@@ -867,6 +876,9 @@ static int sd_init(struct gspca_dev *gspca_dev)
867 */ 876 */
868 877
869 reg_r(gspca_dev, SQ930_CTRL_GET_DEV_INFO, 8); 878 reg_r(gspca_dev, SQ930_CTRL_GET_DEV_INFO, 8);
879 if (gspca_dev->usb_err < 0)
880 return gspca_dev->usb_err;
881
870/* it returns: 882/* it returns:
871 * 03 00 12 93 0b f6 c9 00 live! ultra 883 * 03 00 12 93 0b f6 c9 00 live! ultra
872 * 03 00 07 93 0b f6 ca 00 live! ultra for notebook 884 * 03 00 07 93 0b f6 ca 00 live! ultra for notebook
@@ -900,15 +912,15 @@ static int sd_init(struct gspca_dev *gspca_dev)
900 if (sd->sensor == SENSOR_MI0360) { 912 if (sd->sensor == SENSOR_MI0360) {
901 913
902 /* no sensor probe for icam tracer */ 914 /* no sensor probe for icam tracer */
903 if (gspca_dev->usb_buf[5] == 0xf6) /* if CMOS */ 915 if (gspca_dev->usb_buf[5] == 0xf6) /* if ccd */
904 sd->sensor = SENSOR_ICX098BQ; 916 sd->sensor = SENSOR_ICX098BQ;
905 else 917 else
906 cmos_probe(gspca_dev); 918 cmos_probe(gspca_dev);
907 } 919 }
908 920 if (gspca_dev->usb_err >= 0) {
909 PDEBUG(D_PROBE, "Sensor %s", sensor_tb[sd->sensor].name); 921 PDEBUG(D_PROBE, "Sensor %s", sensor_tb[sd->sensor].name);
910 922 global_init(sd, 1);
911 global_init(sd, 1); 923 }
912 return gspca_dev->usb_err; 924 return gspca_dev->usb_err;
913} 925}
914 926
diff --git a/drivers/media/video/gspca/stv06xx/stv06xx.c b/drivers/media/video/gspca/stv06xx/stv06xx.c
index 086de44a6e57..28ea4175b80e 100644
--- a/drivers/media/video/gspca/stv06xx/stv06xx.c
+++ b/drivers/media/video/gspca/stv06xx/stv06xx.c
@@ -263,7 +263,21 @@ static int stv06xx_init(struct gspca_dev *gspca_dev)
263static int stv06xx_start(struct gspca_dev *gspca_dev) 263static int stv06xx_start(struct gspca_dev *gspca_dev)
264{ 264{
265 struct sd *sd = (struct sd *) gspca_dev; 265 struct sd *sd = (struct sd *) gspca_dev;
266 int err; 266 struct usb_host_interface *alt;
267 struct usb_interface *intf;
268 int err, packet_size;
269
270 intf = usb_ifnum_to_if(sd->gspca_dev.dev, sd->gspca_dev.iface);
271 alt = usb_altnum_to_altsetting(intf, sd->gspca_dev.alt);
272 if (!alt) {
273 PDEBUG(D_ERR, "Couldn't get altsetting");
274 return -EIO;
275 }
276
277 packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize);
278 err = stv06xx_write_bridge(sd, STV_ISO_SIZE_L, packet_size);
279 if (err < 0)
280 return err;
267 281
268 /* Prepare the sensor for start */ 282 /* Prepare the sensor for start */
269 err = sd->sensor->start(sd); 283 err = sd->sensor->start(sd);
@@ -282,6 +296,43 @@ out:
282 return (err < 0) ? err : 0; 296 return (err < 0) ? err : 0;
283} 297}
284 298
299static int stv06xx_isoc_init(struct gspca_dev *gspca_dev)
300{
301 struct usb_host_interface *alt;
302 struct sd *sd = (struct sd *) gspca_dev;
303
304 /* Start isoc bandwidth "negotiation" at max isoc bandwidth */
305 alt = &gspca_dev->dev->config->intf_cache[0]->altsetting[1];
306 alt->endpoint[0].desc.wMaxPacketSize =
307 cpu_to_le16(sd->sensor->max_packet_size[gspca_dev->curr_mode]);
308
309 return 0;
310}
311
312static int stv06xx_isoc_nego(struct gspca_dev *gspca_dev)
313{
314 int ret, packet_size, min_packet_size;
315 struct usb_host_interface *alt;
316 struct sd *sd = (struct sd *) gspca_dev;
317
318 alt = &gspca_dev->dev->config->intf_cache[0]->altsetting[1];
319 packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize);
320 min_packet_size = sd->sensor->min_packet_size[gspca_dev->curr_mode];
321 if (packet_size <= min_packet_size)
322 return -EIO;
323
324 packet_size -= 100;
325 if (packet_size < min_packet_size)
326 packet_size = min_packet_size;
327 alt->endpoint[0].desc.wMaxPacketSize = cpu_to_le16(packet_size);
328
329 ret = usb_set_interface(gspca_dev->dev, gspca_dev->iface, 1);
330 if (ret < 0)
331 PDEBUG(D_ERR|D_STREAM, "set alt 1 err %d", ret);
332
333 return ret;
334}
335
285static void stv06xx_stopN(struct gspca_dev *gspca_dev) 336static void stv06xx_stopN(struct gspca_dev *gspca_dev)
286{ 337{
287 int err; 338 int err;
@@ -349,7 +400,7 @@ static void stv06xx_pkt_scan(struct gspca_dev *gspca_dev,
349 } 400 }
350 401
351 /* First byte seem to be 02=data 2nd byte is unknown??? */ 402 /* First byte seem to be 02=data 2nd byte is unknown??? */
352 if (sd->bridge == BRIDGE_ST6422 && (id & 0xFF00) == 0x0200) 403 if (sd->bridge == BRIDGE_ST6422 && (id & 0xff00) == 0x0200)
353 goto frame_data; 404 goto frame_data;
354 405
355 switch (id) { 406 switch (id) {
@@ -462,6 +513,8 @@ static const struct sd_desc sd_desc = {
462 .start = stv06xx_start, 513 .start = stv06xx_start,
463 .stopN = stv06xx_stopN, 514 .stopN = stv06xx_stopN,
464 .pkt_scan = stv06xx_pkt_scan, 515 .pkt_scan = stv06xx_pkt_scan,
516 .isoc_init = stv06xx_isoc_init,
517 .isoc_nego = stv06xx_isoc_nego,
465#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) 518#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
466 .int_pkt_scan = sd_int_pkt_scan, 519 .int_pkt_scan = sd_int_pkt_scan,
467#endif 520#endif
diff --git a/drivers/media/video/gspca/stv06xx/stv06xx_hdcs.h b/drivers/media/video/gspca/stv06xx/stv06xx_hdcs.h
index cf3d0ccc1121..b538dce96f78 100644
--- a/drivers/media/video/gspca/stv06xx/stv06xx_hdcs.h
+++ b/drivers/media/video/gspca/stv06xx/stv06xx_hdcs.h
@@ -146,6 +146,11 @@ const struct stv06xx_sensor stv06xx_sensor_hdcs1x00 = {
146 .i2c_addr = (0x55 << 1), 146 .i2c_addr = (0x55 << 1),
147 .i2c_len = 1, 147 .i2c_len = 1,
148 148
149 /* FIXME (see if we can lower min_packet_size, needs testing, and also
150 adjusting framerate when the bandwidth gets lower) */
151 .min_packet_size = { 847 },
152 .max_packet_size = { 847 },
153
149 .init = hdcs_init, 154 .init = hdcs_init,
150 .probe = hdcs_probe_1x00, 155 .probe = hdcs_probe_1x00,
151 .start = hdcs_start, 156 .start = hdcs_start,
@@ -160,6 +165,11 @@ const struct stv06xx_sensor stv06xx_sensor_hdcs1020 = {
160 .i2c_addr = (0x55 << 1), 165 .i2c_addr = (0x55 << 1),
161 .i2c_len = 1, 166 .i2c_len = 1,
162 167
168 /* FIXME (see if we can lower min_packet_size, needs testing, and also
169 adjusting framerate when the bandwidthm gets lower) */
170 .min_packet_size = { 847 },
171 .max_packet_size = { 847 },
172
163 .init = hdcs_init, 173 .init = hdcs_init,
164 .probe = hdcs_probe_1020, 174 .probe = hdcs_probe_1020,
165 .start = hdcs_start, 175 .start = hdcs_start,
@@ -177,7 +187,6 @@ static const u16 stv_bridge_init[][2] = {
177 {STV_REG04, 0x07}, 187 {STV_REG04, 0x07},
178 188
179 {STV_SCAN_RATE, 0x20}, 189 {STV_SCAN_RATE, 0x20},
180 {STV_ISO_SIZE_L, 847},
181 {STV_Y_CTRL, 0x01}, 190 {STV_Y_CTRL, 0x01},
182 {STV_X_CTRL, 0x0a} 191 {STV_X_CTRL, 0x0a}
183}; 192};
diff --git a/drivers/media/video/gspca/stv06xx/stv06xx_pb0100.c b/drivers/media/video/gspca/stv06xx/stv06xx_pb0100.c
index 285221e6b390..ac47b4c94388 100644
--- a/drivers/media/video/gspca/stv06xx/stv06xx_pb0100.c
+++ b/drivers/media/video/gspca/stv06xx/stv06xx_pb0100.c
@@ -208,11 +208,24 @@ static int pb0100_probe(struct sd *sd)
208 208
209static int pb0100_start(struct sd *sd) 209static int pb0100_start(struct sd *sd)
210{ 210{
211 int err; 211 int err, packet_size, max_packet_size;
212 struct usb_host_interface *alt;
213 struct usb_interface *intf;
212 struct cam *cam = &sd->gspca_dev.cam; 214 struct cam *cam = &sd->gspca_dev.cam;
213 s32 *sensor_settings = sd->sensor_priv; 215 s32 *sensor_settings = sd->sensor_priv;
214 u32 mode = cam->cam_mode[sd->gspca_dev.curr_mode].priv; 216 u32 mode = cam->cam_mode[sd->gspca_dev.curr_mode].priv;
215 217
218 intf = usb_ifnum_to_if(sd->gspca_dev.dev, sd->gspca_dev.iface);
219 alt = usb_altnum_to_altsetting(intf, sd->gspca_dev.alt);
220 packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize);
221
222 /* If we don't have enough bandwidth use a lower framerate */
223 max_packet_size = sd->sensor->max_packet_size[sd->gspca_dev.curr_mode];
224 if (packet_size < max_packet_size)
225 stv06xx_write_sensor(sd, PB_ROWSPEED, BIT(4)|BIT(3)|BIT(1));
226 else
227 stv06xx_write_sensor(sd, PB_ROWSPEED, BIT(5)|BIT(3)|BIT(1));
228
216 /* Setup sensor window */ 229 /* Setup sensor window */
217 if (mode & PB0100_CROP_TO_VGA) { 230 if (mode & PB0100_CROP_TO_VGA) {
218 stv06xx_write_sensor(sd, PB_RSTART, 30); 231 stv06xx_write_sensor(sd, PB_RSTART, 30);
@@ -328,9 +341,6 @@ static int pb0100_init(struct sd *sd)
328 stv06xx_write_bridge(sd, STV_REG03, 0x45); 341 stv06xx_write_bridge(sd, STV_REG03, 0x45);
329 stv06xx_write_bridge(sd, STV_REG04, 0x07); 342 stv06xx_write_bridge(sd, STV_REG04, 0x07);
330 343
331 /* ISO-Size (0x27b: 635... why? - HDCS uses 847) */
332 stv06xx_write_bridge(sd, STV_ISO_SIZE_L, 847);
333
334 /* Scan/timing for the sensor */ 344 /* Scan/timing for the sensor */
335 stv06xx_write_sensor(sd, PB_ROWSPEED, BIT(4)|BIT(3)|BIT(1)); 345 stv06xx_write_sensor(sd, PB_ROWSPEED, BIT(4)|BIT(3)|BIT(1));
336 stv06xx_write_sensor(sd, PB_CFILLIN, 14); 346 stv06xx_write_sensor(sd, PB_CFILLIN, 14);
diff --git a/drivers/media/video/gspca/stv06xx/stv06xx_pb0100.h b/drivers/media/video/gspca/stv06xx/stv06xx_pb0100.h
index 4de4fa5ebc57..757de246dc75 100644
--- a/drivers/media/video/gspca/stv06xx/stv06xx_pb0100.h
+++ b/drivers/media/video/gspca/stv06xx/stv06xx_pb0100.h
@@ -138,6 +138,9 @@ const struct stv06xx_sensor stv06xx_sensor_pb0100 = {
138 .i2c_addr = 0xba, 138 .i2c_addr = 0xba,
139 .i2c_len = 2, 139 .i2c_len = 2,
140 140
141 .min_packet_size = { 635, 847 },
142 .max_packet_size = { 847, 923 },
143
141 .init = pb0100_init, 144 .init = pb0100_init,
142 .probe = pb0100_probe, 145 .probe = pb0100_probe,
143 .start = pb0100_start, 146 .start = pb0100_start,
diff --git a/drivers/media/video/gspca/stv06xx/stv06xx_sensor.h b/drivers/media/video/gspca/stv06xx/stv06xx_sensor.h
index 934b9cebc1ab..fb229d8ded58 100644
--- a/drivers/media/video/gspca/stv06xx/stv06xx_sensor.h
+++ b/drivers/media/video/gspca/stv06xx/stv06xx_sensor.h
@@ -53,6 +53,10 @@ struct stv06xx_sensor {
53 /* length of an i2c word */ 53 /* length of an i2c word */
54 u8 i2c_len; 54 u8 i2c_len;
55 55
56 /* Isoc packet size (per mode) */
57 int min_packet_size[4];
58 int max_packet_size[4];
59
56 /* Probes if the sensor is connected */ 60 /* Probes if the sensor is connected */
57 int (*probe)(struct sd *sd); 61 int (*probe)(struct sd *sd);
58 62
diff --git a/drivers/media/video/gspca/stv06xx/stv06xx_st6422.c b/drivers/media/video/gspca/stv06xx/stv06xx_st6422.c
index 3af53264a364..8a456de4970a 100644
--- a/drivers/media/video/gspca/stv06xx/stv06xx_st6422.c
+++ b/drivers/media/video/gspca/stv06xx/stv06xx_st6422.c
@@ -28,6 +28,20 @@
28 28
29#include "stv06xx_st6422.h" 29#include "stv06xx_st6422.h"
30 30
31/* controls */
32enum e_ctrl {
33 BRIGHTNESS,
34 CONTRAST,
35 GAIN,
36 EXPOSURE,
37 NCTRLS /* number of controls */
38};
39
40/* sensor settings */
41struct st6422_settings {
42 struct gspca_ctrl ctrls[NCTRLS];
43};
44
31static struct v4l2_pix_format st6422_mode[] = { 45static struct v4l2_pix_format st6422_mode[] = {
32 /* Note we actually get 124 lines of data, of which we skip the 4st 46 /* Note we actually get 124 lines of data, of which we skip the 4st
33 4 as they are garbage */ 47 4 as they are garbage */
@@ -57,9 +71,14 @@ static struct v4l2_pix_format st6422_mode[] = {
57 }, 71 },
58}; 72};
59 73
60static const struct ctrl st6422_ctrl[] = { 74/* V4L2 controls supported by the driver */
61#define BRIGHTNESS_IDX 0 75static void st6422_set_brightness(struct gspca_dev *gspca_dev);
62 { 76static void st6422_set_contrast(struct gspca_dev *gspca_dev);
77static void st6422_set_gain(struct gspca_dev *gspca_dev);
78static void st6422_set_exposure(struct gspca_dev *gspca_dev);
79
80static const struct ctrl st6422_ctrl[NCTRLS] = {
81[BRIGHTNESS] = {
63 { 82 {
64 .id = V4L2_CID_BRIGHTNESS, 83 .id = V4L2_CID_BRIGHTNESS,
65 .type = V4L2_CTRL_TYPE_INTEGER, 84 .type = V4L2_CTRL_TYPE_INTEGER,
@@ -69,11 +88,9 @@ static const struct ctrl st6422_ctrl[] = {
69 .step = 1, 88 .step = 1,
70 .default_value = 3 89 .default_value = 3
71 }, 90 },
72 .set = st6422_set_brightness, 91 .set_control = st6422_set_brightness
73 .get = st6422_get_brightness
74 }, 92 },
75#define CONTRAST_IDX 1 93[CONTRAST] = {
76 {
77 { 94 {
78 .id = V4L2_CID_CONTRAST, 95 .id = V4L2_CID_CONTRAST,
79 .type = V4L2_CTRL_TYPE_INTEGER, 96 .type = V4L2_CTRL_TYPE_INTEGER,
@@ -83,11 +100,9 @@ static const struct ctrl st6422_ctrl[] = {
83 .step = 1, 100 .step = 1,
84 .default_value = 11 101 .default_value = 11
85 }, 102 },
86 .set = st6422_set_contrast, 103 .set_control = st6422_set_contrast
87 .get = st6422_get_contrast
88 }, 104 },
89#define GAIN_IDX 2 105[GAIN] = {
90 {
91 { 106 {
92 .id = V4L2_CID_GAIN, 107 .id = V4L2_CID_GAIN,
93 .type = V4L2_CTRL_TYPE_INTEGER, 108 .type = V4L2_CTRL_TYPE_INTEGER,
@@ -97,49 +112,43 @@ static const struct ctrl st6422_ctrl[] = {
97 .step = 1, 112 .step = 1,
98 .default_value = 64 113 .default_value = 64
99 }, 114 },
100 .set = st6422_set_gain, 115 .set_control = st6422_set_gain
101 .get = st6422_get_gain
102 }, 116 },
103#define EXPOSURE_IDX 3 117[EXPOSURE] = {
104 {
105 { 118 {
106 .id = V4L2_CID_EXPOSURE, 119 .id = V4L2_CID_EXPOSURE,
107 .type = V4L2_CTRL_TYPE_INTEGER, 120 .type = V4L2_CTRL_TYPE_INTEGER,
108 .name = "Exposure", 121 .name = "Exposure",
109 .minimum = 0, 122 .minimum = 0,
110 .maximum = 1023, 123#define EXPOSURE_MAX 1023
124 .maximum = EXPOSURE_MAX,
111 .step = 1, 125 .step = 1,
112 .default_value = 256 126 .default_value = 256
113 }, 127 },
114 .set = st6422_set_exposure, 128 .set_control = st6422_set_exposure
115 .get = st6422_get_exposure
116 }, 129 },
117}; 130};
118 131
119static int st6422_probe(struct sd *sd) 132static int st6422_probe(struct sd *sd)
120{ 133{
121 int i; 134 struct st6422_settings *sensor_settings;
122 s32 *sensor_settings;
123 135
124 if (sd->bridge != BRIDGE_ST6422) 136 if (sd->bridge != BRIDGE_ST6422)
125 return -ENODEV; 137 return -ENODEV;
126 138
127 info("st6422 sensor detected"); 139 info("st6422 sensor detected");
128 140
129 sensor_settings = kmalloc(ARRAY_SIZE(st6422_ctrl) * sizeof(s32), 141 sensor_settings = kmalloc(sizeof *sensor_settings, GFP_KERNEL);
130 GFP_KERNEL);
131 if (!sensor_settings) 142 if (!sensor_settings)
132 return -ENOMEM; 143 return -ENOMEM;
133 144
134 sd->gspca_dev.cam.cam_mode = st6422_mode; 145 sd->gspca_dev.cam.cam_mode = st6422_mode;
135 sd->gspca_dev.cam.nmodes = ARRAY_SIZE(st6422_mode); 146 sd->gspca_dev.cam.nmodes = ARRAY_SIZE(st6422_mode);
147 sd->gspca_dev.cam.ctrls = sensor_settings->ctrls;
136 sd->desc.ctrls = st6422_ctrl; 148 sd->desc.ctrls = st6422_ctrl;
137 sd->desc.nctrls = ARRAY_SIZE(st6422_ctrl); 149 sd->desc.nctrls = ARRAY_SIZE(st6422_ctrl);
138 sd->sensor_priv = sensor_settings; 150 sd->sensor_priv = sensor_settings;
139 151
140 for (i = 0; i < sd->desc.nctrls; i++)
141 sensor_settings[i] = st6422_ctrl[i].qctrl.default_value;
142
143 return 0; 152 return 0;
144} 153}
145 154
@@ -151,11 +160,11 @@ static int st6422_init(struct sd *sd)
151 { STV_ISO_ENABLE, 0x00 }, /* disable capture */ 160 { STV_ISO_ENABLE, 0x00 }, /* disable capture */
152 { 0x1436, 0x00 }, 161 { 0x1436, 0x00 },
153 { 0x1432, 0x03 }, /* 0x00-0x1F brightness */ 162 { 0x1432, 0x03 }, /* 0x00-0x1F brightness */
154 { 0x143a, 0xF9 }, /* 0x00-0x0F contrast */ 163 { 0x143a, 0xf9 }, /* 0x00-0x0F contrast */
155 { 0x0509, 0x38 }, /* R */ 164 { 0x0509, 0x38 }, /* R */
156 { 0x050a, 0x38 }, /* G */ 165 { 0x050a, 0x38 }, /* G */
157 { 0x050b, 0x38 }, /* B */ 166 { 0x050b, 0x38 }, /* B */
158 { 0x050c, 0x2A }, 167 { 0x050c, 0x2a },
159 { 0x050d, 0x01 }, 168 { 0x050d, 0x01 },
160 169
161 170
@@ -213,7 +222,6 @@ static int st6422_init(struct sd *sd)
213 { 0x150e, 0x8e }, 222 { 0x150e, 0x8e },
214 { 0x150f, 0x37 }, 223 { 0x150f, 0x37 },
215 { 0x15c0, 0x00 }, 224 { 0x15c0, 0x00 },
216 { 0x15c1, 1023 }, /* 160x120, ISOC_PACKET_SIZE */
217 { 0x15c3, 0x08 }, /* 0x04/0x14 ... test pictures ??? */ 225 { 0x15c3, 0x08 }, /* 0x04/0x14 ... test pictures ??? */
218 226
219 227
@@ -235,91 +243,92 @@ static void st6422_disconnect(struct sd *sd)
235 kfree(sd->sensor_priv); 243 kfree(sd->sensor_priv);
236} 244}
237 245
238static int st6422_start(struct sd *sd) 246static int setbrightness(struct sd *sd)
239{ 247{
240 int err, packet_size; 248 struct st6422_settings *sensor_settings = sd->sensor_priv;
241 struct cam *cam = &sd->gspca_dev.cam;
242 s32 *sensor_settings = sd->sensor_priv;
243 struct usb_host_interface *alt;
244 struct usb_interface *intf;
245
246 intf = usb_ifnum_to_if(sd->gspca_dev.dev, sd->gspca_dev.iface);
247 alt = usb_altnum_to_altsetting(intf, sd->gspca_dev.alt);
248 if (!alt) {
249 err("Couldn't get altsetting");
250 return -EIO;
251 }
252 249
253 packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize); 250 /* val goes from 0 -> 31 */
254 err = stv06xx_write_bridge(sd, 0x15c1, packet_size); 251 return stv06xx_write_bridge(sd, 0x1432,
255 if (err < 0) 252 sensor_settings->ctrls[BRIGHTNESS].val);
256 return err; 253}
257 254
258 if (cam->cam_mode[sd->gspca_dev.curr_mode].priv) 255static int setcontrast(struct sd *sd)
259 err = stv06xx_write_bridge(sd, 0x1505, 0x0f); 256{
260 else 257 struct st6422_settings *sensor_settings = sd->sensor_priv;
261 err = stv06xx_write_bridge(sd, 0x1505, 0x02); 258
262 if (err < 0) 259 /* Val goes from 0 -> 15 */
263 return err; 260 return stv06xx_write_bridge(sd, 0x143a,
261 sensor_settings->ctrls[CONTRAST].val | 0xf0);
262}
263
264static int setgain(struct sd *sd)
265{
266 struct st6422_settings *sensor_settings = sd->sensor_priv;
267 u8 gain;
268 int err;
269
270 gain = sensor_settings->ctrls[GAIN].val;
264 271
265 err = st6422_set_brightness(&sd->gspca_dev, 272 /* Set red, green, blue, gain */
266 sensor_settings[BRIGHTNESS_IDX]); 273 err = stv06xx_write_bridge(sd, 0x0509, gain);
267 if (err < 0) 274 if (err < 0)
268 return err; 275 return err;
269 276
270 err = st6422_set_contrast(&sd->gspca_dev, 277 err = stv06xx_write_bridge(sd, 0x050a, gain);
271 sensor_settings[CONTRAST_IDX]);
272 if (err < 0) 278 if (err < 0)
273 return err; 279 return err;
274 280
275 err = st6422_set_exposure(&sd->gspca_dev, 281 err = stv06xx_write_bridge(sd, 0x050b, gain);
276 sensor_settings[EXPOSURE_IDX]);
277 if (err < 0) 282 if (err < 0)
278 return err; 283 return err;
279 284
280 err = st6422_set_gain(&sd->gspca_dev, 285 /* 2 mystery writes */
281 sensor_settings[GAIN_IDX]); 286 err = stv06xx_write_bridge(sd, 0x050c, 0x2a);
282 if (err < 0) 287 if (err < 0)
283 return err; 288 return err;
284 289
285 PDEBUG(D_STREAM, "Starting stream"); 290 return stv06xx_write_bridge(sd, 0x050d, 0x01);
286
287 return 0;
288} 291}
289 292
290static int st6422_stop(struct sd *sd) 293static int setexposure(struct sd *sd)
291{ 294{
292 PDEBUG(D_STREAM, "Halting stream"); 295 struct st6422_settings *sensor_settings = sd->sensor_priv;
293 296 u16 expo;
294 return 0; 297 int err;
295}
296
297static int st6422_get_brightness(struct gspca_dev *gspca_dev, __s32 *val)
298{
299 struct sd *sd = (struct sd *) gspca_dev;
300 s32 *sensor_settings = sd->sensor_priv;
301
302 *val = sensor_settings[BRIGHTNESS_IDX];
303 298
304 PDEBUG(D_V4L2, "Read brightness %d", *val); 299 expo = sensor_settings->ctrls[EXPOSURE].val;
300 err = stv06xx_write_bridge(sd, 0x143d, expo & 0xff);
301 if (err < 0)
302 return err;
305 303
306 return 0; 304 return stv06xx_write_bridge(sd, 0x143e, expo >> 8);
307} 305}
308 306
309static int st6422_set_brightness(struct gspca_dev *gspca_dev, __s32 val) 307static int st6422_start(struct sd *sd)
310{ 308{
311 int err; 309 int err;
312 struct sd *sd = (struct sd *) gspca_dev; 310 struct cam *cam = &sd->gspca_dev.cam;
313 s32 *sensor_settings = sd->sensor_priv;
314 311
315 sensor_settings[BRIGHTNESS_IDX] = val; 312 if (cam->cam_mode[sd->gspca_dev.curr_mode].priv)
313 err = stv06xx_write_bridge(sd, 0x1505, 0x0f);
314 else
315 err = stv06xx_write_bridge(sd, 0x1505, 0x02);
316 if (err < 0)
317 return err;
316 318
317 if (!gspca_dev->streaming) 319 err = setbrightness(sd);
318 return 0; 320 if (err < 0)
321 return err;
319 322
320 /* val goes from 0 -> 31 */ 323 err = setcontrast(sd);
321 PDEBUG(D_V4L2, "Set brightness to %d", val); 324 if (err < 0)
322 err = stv06xx_write_bridge(sd, 0x1432, val); 325 return err;
326
327 err = setexposure(sd);
328 if (err < 0)
329 return err;
330
331 err = setgain(sd);
323 if (err < 0) 332 if (err < 0)
324 return err; 333 return err;
325 334
@@ -328,125 +337,65 @@ static int st6422_set_brightness(struct gspca_dev *gspca_dev, __s32 val)
328 return (err < 0) ? err : 0; 337 return (err < 0) ? err : 0;
329} 338}
330 339
331static int st6422_get_contrast(struct gspca_dev *gspca_dev, __s32 *val) 340static int st6422_stop(struct sd *sd)
332{ 341{
333 struct sd *sd = (struct sd *) gspca_dev; 342 PDEBUG(D_STREAM, "Halting stream");
334 s32 *sensor_settings = sd->sensor_priv;
335
336 *val = sensor_settings[CONTRAST_IDX];
337
338 PDEBUG(D_V4L2, "Read contrast %d", *val);
339 343
340 return 0; 344 return 0;
341} 345}
342 346
343static int st6422_set_contrast(struct gspca_dev *gspca_dev, __s32 val) 347static void st6422_set_brightness(struct gspca_dev *gspca_dev)
344{ 348{
345 int err; 349 int err;
346 struct sd *sd = (struct sd *) gspca_dev; 350 struct sd *sd = (struct sd *) gspca_dev;
347 s32 *sensor_settings = sd->sensor_priv;
348
349 sensor_settings[CONTRAST_IDX] = val;
350 351
351 if (!gspca_dev->streaming) 352 err = setbrightness(sd);
352 return 0;
353
354 /* Val goes from 0 -> 15 */
355 PDEBUG(D_V4L2, "Set contrast to %d\n", val);
356 err = stv06xx_write_bridge(sd, 0x143a, 0xf0 | val);
357 if (err < 0)
358 return err;
359 353
360 /* commit settings */ 354 /* commit settings */
361 err = stv06xx_write_bridge(sd, 0x143f, 0x01); 355 if (err >= 0)
362 return (err < 0) ? err : 0; 356 err = stv06xx_write_bridge(sd, 0x143f, 0x01);
363}
364
365static int st6422_get_gain(struct gspca_dev *gspca_dev, __s32 *val)
366{
367 struct sd *sd = (struct sd *) gspca_dev;
368 s32 *sensor_settings = sd->sensor_priv;
369
370 *val = sensor_settings[GAIN_IDX];
371
372 PDEBUG(D_V4L2, "Read gain %d", *val);
373 357
374 return 0; 358 gspca_dev->usb_err = err;
375} 359}
376 360
377static int st6422_set_gain(struct gspca_dev *gspca_dev, __s32 val) 361static void st6422_set_contrast(struct gspca_dev *gspca_dev)
378{ 362{
379 int err; 363 int err;
380 struct sd *sd = (struct sd *) gspca_dev; 364 struct sd *sd = (struct sd *) gspca_dev;
381 s32 *sensor_settings = sd->sensor_priv;
382
383 sensor_settings[GAIN_IDX] = val;
384
385 if (!gspca_dev->streaming)
386 return 0;
387
388 PDEBUG(D_V4L2, "Set gain to %d", val);
389 365
390 /* Set red, green, blue, gain */ 366 err = setcontrast(sd);
391 err = stv06xx_write_bridge(sd, 0x0509, val);
392 if (err < 0)
393 return err;
394
395 err = stv06xx_write_bridge(sd, 0x050a, val);
396 if (err < 0)
397 return err;
398
399 err = stv06xx_write_bridge(sd, 0x050b, val);
400 if (err < 0)
401 return err;
402
403 /* 2 mystery writes */
404 err = stv06xx_write_bridge(sd, 0x050c, 0x2a);
405 if (err < 0)
406 return err;
407
408 err = stv06xx_write_bridge(sd, 0x050d, 0x01);
409 if (err < 0)
410 return err;
411 367
412 /* commit settings */ 368 /* commit settings */
413 err = stv06xx_write_bridge(sd, 0x143f, 0x01); 369 if (err >= 0)
414 return (err < 0) ? err : 0; 370 err = stv06xx_write_bridge(sd, 0x143f, 0x01);
371
372 gspca_dev->usb_err = err;
415} 373}
416 374
417static int st6422_get_exposure(struct gspca_dev *gspca_dev, __s32 *val) 375static void st6422_set_gain(struct gspca_dev *gspca_dev)
418{ 376{
377 int err;
419 struct sd *sd = (struct sd *) gspca_dev; 378 struct sd *sd = (struct sd *) gspca_dev;
420 s32 *sensor_settings = sd->sensor_priv;
421 379
422 *val = sensor_settings[EXPOSURE_IDX]; 380 err = setgain(sd);
423 381
424 PDEBUG(D_V4L2, "Read exposure %d", *val); 382 /* commit settings */
383 if (err >= 0)
384 err = stv06xx_write_bridge(sd, 0x143f, 0x01);
425 385
426 return 0; 386 gspca_dev->usb_err = err;
427} 387}
428 388
429static int st6422_set_exposure(struct gspca_dev *gspca_dev, __s32 val) 389static void st6422_set_exposure(struct gspca_dev *gspca_dev)
430{ 390{
431 int err; 391 int err;
432 struct sd *sd = (struct sd *) gspca_dev; 392 struct sd *sd = (struct sd *) gspca_dev;
433 s32 *sensor_settings = sd->sensor_priv;
434
435 sensor_settings[EXPOSURE_IDX] = val;
436 393
437 if (!gspca_dev->streaming) 394 err = setexposure(sd);
438 return 0;
439
440 PDEBUG(D_V4L2, "Set exposure to %d\n", val);
441 err = stv06xx_write_bridge(sd, 0x143d, val & 0xff);
442 if (err < 0)
443 return err;
444
445 err = stv06xx_write_bridge(sd, 0x143e, val >> 8);
446 if (err < 0)
447 return err;
448 395
449 /* commit settings */ 396 /* commit settings */
450 err = stv06xx_write_bridge(sd, 0x143f, 0x01); 397 if (err >= 0)
451 return (err < 0) ? err : 0; 398 err = stv06xx_write_bridge(sd, 0x143f, 0x01);
399
400 gspca_dev->usb_err = err;
452} 401}
diff --git a/drivers/media/video/gspca/stv06xx/stv06xx_st6422.h b/drivers/media/video/gspca/stv06xx/stv06xx_st6422.h
index b2d45fe50522..d7498e06432b 100644
--- a/drivers/media/video/gspca/stv06xx/stv06xx_st6422.h
+++ b/drivers/media/video/gspca/stv06xx/stv06xx_st6422.h
@@ -37,18 +37,11 @@ static int st6422_init(struct sd *sd);
37static int st6422_stop(struct sd *sd); 37static int st6422_stop(struct sd *sd);
38static void st6422_disconnect(struct sd *sd); 38static void st6422_disconnect(struct sd *sd);
39 39
40/* V4L2 controls supported by the driver */
41static int st6422_get_brightness(struct gspca_dev *gspca_dev, __s32 *val);
42static int st6422_set_brightness(struct gspca_dev *gspca_dev, __s32 val);
43static int st6422_get_contrast(struct gspca_dev *gspca_dev, __s32 *val);
44static int st6422_set_contrast(struct gspca_dev *gspca_dev, __s32 val);
45static int st6422_get_gain(struct gspca_dev *gspca_dev, __s32 *val);
46static int st6422_set_gain(struct gspca_dev *gspca_dev, __s32 val);
47static int st6422_get_exposure(struct gspca_dev *gspca_dev, __s32 *val);
48static int st6422_set_exposure(struct gspca_dev *gspca_dev, __s32 val);
49
50const struct stv06xx_sensor stv06xx_sensor_st6422 = { 40const struct stv06xx_sensor stv06xx_sensor_st6422 = {
51 .name = "ST6422", 41 .name = "ST6422",
42 /* No known way to lower framerate in case of less bandwidth */
43 .min_packet_size = { 300, 847 },
44 .max_packet_size = { 300, 847 },
52 .init = st6422_init, 45 .init = st6422_init,
53 .probe = st6422_probe, 46 .probe = st6422_probe,
54 .start = st6422_start, 47 .start = st6422_start,
diff --git a/drivers/media/video/gspca/stv06xx/stv06xx_vv6410.h b/drivers/media/video/gspca/stv06xx/stv06xx_vv6410.h
index b3b5508473bc..7fe3587f5f71 100644
--- a/drivers/media/video/gspca/stv06xx/stv06xx_vv6410.h
+++ b/drivers/media/video/gspca/stv06xx/stv06xx_vv6410.h
@@ -197,6 +197,10 @@ const struct stv06xx_sensor stv06xx_sensor_vv6410 = {
197 .i2c_flush = 5, 197 .i2c_flush = 5,
198 .i2c_addr = 0x20, 198 .i2c_addr = 0x20,
199 .i2c_len = 1, 199 .i2c_len = 1,
200 /* FIXME (see if we can lower packet_size-s, needs testing, and also
201 adjusting framerate when the bandwidth gets lower) */
202 .min_packet_size = { 1023 },
203 .max_packet_size = { 1023 },
200 .init = vv6410_init, 204 .init = vv6410_init,
201 .probe = vv6410_probe, 205 .probe = vv6410_probe,
202 .start = vv6410_start, 206 .start = vv6410_start,
@@ -220,10 +224,6 @@ static const u8 x1536[] = { /* 0x1536 - 0x153b */
220 0x02, 0x00, 0x60, 0x01, 0x20, 0x01 224 0x02, 0x00, 0x60, 0x01, 0x20, 0x01
221}; 225};
222 226
223static const u8 x15c1[] = { /* 0x15c1 - 0x15c2 */
224 0xff, 0x03 /* Output word 0x03ff = 1023 (ISO size) */
225};
226
227static const struct stv_init stv_bridge_init[] = { 227static const struct stv_init stv_bridge_init[] = {
228 /* This reg is written twice. Some kind of reset? */ 228 /* This reg is written twice. Some kind of reset? */
229 {NULL, 0x1620, 0x80}, 229 {NULL, 0x1620, 0x80},
@@ -232,7 +232,6 @@ static const struct stv_init stv_bridge_init[] = {
232 {NULL, 0x1423, 0x04}, 232 {NULL, 0x1423, 0x04},
233 {x1500, 0x1500, ARRAY_SIZE(x1500)}, 233 {x1500, 0x1500, ARRAY_SIZE(x1500)},
234 {x1536, 0x1536, ARRAY_SIZE(x1536)}, 234 {x1536, 0x1536, ARRAY_SIZE(x1536)},
235 {x15c1, 0x15c1, ARRAY_SIZE(x15c1)}
236}; 235};
237 236
238static const u8 vv6410_sensor_init[][2] = { 237static const u8 vv6410_sensor_init[][2] = {
diff --git a/drivers/media/video/gspca/t613.c b/drivers/media/video/gspca/t613.c
index b45f4d0f3997..8f0c33116e0d 100644
--- a/drivers/media/video/gspca/t613.c
+++ b/drivers/media/video/gspca/t613.c
@@ -487,7 +487,7 @@ static const u8 gamma_table[GAMMA_MAX][17] = {
487 {0x00, 0x02, 0x07, 0x0f, 0x18, 0x24, 0x30, 0x3f, /* 3 */ 487 {0x00, 0x02, 0x07, 0x0f, 0x18, 0x24, 0x30, 0x3f, /* 3 */
488 0x4f, 0x61, 0x73, 0x88, 0x9d, 0xb4, 0xcd, 0xe6, 488 0x4f, 0x61, 0x73, 0x88, 0x9d, 0xb4, 0xcd, 0xe6,
489 0xff}, 489 0xff},
490 {0x00, 0x04, 0x0B, 0x15, 0x20, 0x2d, 0x3b, 0x4a, /* 4 */ 490 {0x00, 0x04, 0x0b, 0x15, 0x20, 0x2d, 0x3b, 0x4a, /* 4 */
491 0x5b, 0x6c, 0x7f, 0x92, 0xa7, 0xbc, 0xd2, 0xe9, 491 0x5b, 0x6c, 0x7f, 0x92, 0xa7, 0xbc, 0xd2, 0xe9,
492 0xff}, 492 0xff},
493 {0x00, 0x07, 0x11, 0x15, 0x20, 0x2d, 0x48, 0x58, /* 5 */ 493 {0x00, 0x07, 0x11, 0x15, 0x20, 0x2d, 0x48, 0x58, /* 5 */
diff --git a/drivers/media/video/gspca/tv8532.c b/drivers/media/video/gspca/tv8532.c
index d9e3c6050781..38c22f0a4263 100644
--- a/drivers/media/video/gspca/tv8532.c
+++ b/drivers/media/video/gspca/tv8532.c
@@ -132,7 +132,7 @@ static const struct v4l2_pix_format sif_mode[] = {
132#define R36_PID 0x36 132#define R36_PID 0x36
133#define R37_PIDH 0x37 133#define R37_PIDH 0x37
134#define R39_Test1 0x39 /* GPIO */ 134#define R39_Test1 0x39 /* GPIO */
135#define R3B_Test3 0x3B /* GPIO */ 135#define R3B_Test3 0x3b /* GPIO */
136#define R83_AD_IDH 0x83 136#define R83_AD_IDH 0x83
137#define R91_AD_SLOPEREG 0x91 137#define R91_AD_SLOPEREG 0x91
138#define R94_AD_BITCONTROL 0x94 138#define R94_AD_BITCONTROL 0x94
diff --git a/drivers/media/video/gspca/vc032x.c b/drivers/media/video/gspca/vc032x.c
index 38a6efe1a5f9..9b2ae1b6cc75 100644
--- a/drivers/media/video/gspca/vc032x.c
+++ b/drivers/media/video/gspca/vc032x.c
@@ -47,24 +47,29 @@ struct sd {
47 u8 image_offset; 47 u8 image_offset;
48 48
49 u8 bridge; 49 u8 bridge;
50#define BRIDGE_VC0321 0
51#define BRIDGE_VC0323 1
52 u8 sensor; 50 u8 sensor;
53#define SENSOR_HV7131R 0
54#define SENSOR_MI0360 1
55#define SENSOR_MI1310_SOC 2
56#define SENSOR_MI1320 3
57#define SENSOR_MI1320_SOC 4
58#define SENSOR_OV7660 5
59#define SENSOR_OV7670 6
60#define SENSOR_PO1200 7
61#define SENSOR_PO3130NC 8
62#define SENSOR_POxxxx 9
63 u8 flags; 51 u8 flags;
64#define FL_SAMSUNG 0x01 /* SamsungQ1 (2 sensors) */ 52#define FL_SAMSUNG 0x01 /* SamsungQ1 (2 sensors) */
65#define FL_HFLIP 0x02 /* mirrored by default */ 53#define FL_HFLIP 0x02 /* mirrored by default */
66#define FL_VFLIP 0x04 /* vertical flipped by default */ 54#define FL_VFLIP 0x04 /* vertical flipped by default */
67}; 55};
56enum bridges {
57 BRIDGE_VC0321,
58 BRIDGE_VC0323,
59};
60enum sensors {
61 SENSOR_HV7131R,
62 SENSOR_MI0360,
63 SENSOR_MI1310_SOC,
64 SENSOR_MI1320,
65 SENSOR_MI1320_SOC,
66 SENSOR_OV7660,
67 SENSOR_OV7670,
68 SENSOR_PO1200,
69 SENSOR_PO3130NC,
70 SENSOR_POxxxx,
71 NSENSORS
72};
68 73
69/* V4L2 controls supported by the driver */ 74/* V4L2 controls supported by the driver */
70static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val); 75static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
@@ -260,56 +265,56 @@ static const struct ctrl sd_ctrls[] = {
260}; 265};
261 266
262/* table of the disabled controls */ 267/* table of the disabled controls */
263static u32 ctrl_dis[] = { 268static u32 ctrl_dis[NSENSORS] = {
264/* SENSOR_HV7131R 0 */ 269 [SENSOR_HV7131R] =
265 (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX) 270 (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX)
266 | (1 << HFLIP_IDX) | (1 << VFLIP_IDX) | (1 << LIGHTFREQ_IDX) 271 | (1 << HFLIP_IDX) | (1 << VFLIP_IDX) | (1 << LIGHTFREQ_IDX)
267 | (1 << SHARPNESS_IDX) 272 | (1 << SHARPNESS_IDX)
268 | (1 << GAIN_IDX) | (1 << EXPOSURE_IDX) 273 | (1 << GAIN_IDX) | (1 << EXPOSURE_IDX)
269 | (1 << AUTOGAIN_IDX) | (1 << BACKLIGHT_IDX), 274 | (1 << AUTOGAIN_IDX) | (1 << BACKLIGHT_IDX),
270/* SENSOR_MI0360 1 */ 275 [SENSOR_MI0360] =
271 (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX) 276 (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX)
272 | (1 << HFLIP_IDX) | (1 << VFLIP_IDX) | (1 << LIGHTFREQ_IDX) 277 | (1 << HFLIP_IDX) | (1 << VFLIP_IDX) | (1 << LIGHTFREQ_IDX)
273 | (1 << SHARPNESS_IDX) 278 | (1 << SHARPNESS_IDX)
274 | (1 << GAIN_IDX) | (1 << EXPOSURE_IDX) 279 | (1 << GAIN_IDX) | (1 << EXPOSURE_IDX)
275 | (1 << AUTOGAIN_IDX) | (1 << BACKLIGHT_IDX), 280 | (1 << AUTOGAIN_IDX) | (1 << BACKLIGHT_IDX),
276/* SENSOR_MI1310_SOC 2 */ 281 [SENSOR_MI1310_SOC] =
277 (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX) 282 (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX)
278 | (1 << LIGHTFREQ_IDX) | (1 << SHARPNESS_IDX) 283 | (1 << LIGHTFREQ_IDX) | (1 << SHARPNESS_IDX)
279 | (1 << GAIN_IDX) | (1 << EXPOSURE_IDX) 284 | (1 << GAIN_IDX) | (1 << EXPOSURE_IDX)
280 | (1 << AUTOGAIN_IDX) | (1 << BACKLIGHT_IDX), 285 | (1 << AUTOGAIN_IDX) | (1 << BACKLIGHT_IDX),
281/* SENSOR_MI1320 3 */ 286 [SENSOR_MI1320] =
282 (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX) 287 (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX)
283 | (1 << LIGHTFREQ_IDX) | (1 << SHARPNESS_IDX) 288 | (1 << LIGHTFREQ_IDX) | (1 << SHARPNESS_IDX)
284 | (1 << GAIN_IDX) | (1 << EXPOSURE_IDX) 289 | (1 << GAIN_IDX) | (1 << EXPOSURE_IDX)
285 | (1 << AUTOGAIN_IDX) | (1 << BACKLIGHT_IDX), 290 | (1 << AUTOGAIN_IDX) | (1 << BACKLIGHT_IDX),
286/* SENSOR_MI1320_SOC 4 */ 291 [SENSOR_MI1320_SOC] =
287 (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX) 292 (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX)
288 | (1 << LIGHTFREQ_IDX) | (1 << SHARPNESS_IDX) 293 | (1 << LIGHTFREQ_IDX) | (1 << SHARPNESS_IDX)
289 | (1 << GAIN_IDX) | (1 << EXPOSURE_IDX) 294 | (1 << GAIN_IDX) | (1 << EXPOSURE_IDX)
290 | (1 << AUTOGAIN_IDX) | (1 << BACKLIGHT_IDX), 295 | (1 << AUTOGAIN_IDX) | (1 << BACKLIGHT_IDX),
291/* SENSOR_OV7660 5 */ 296 [SENSOR_OV7660] =
292 (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX) 297 (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX)
293 | (1 << LIGHTFREQ_IDX) | (1 << SHARPNESS_IDX) 298 | (1 << LIGHTFREQ_IDX) | (1 << SHARPNESS_IDX)
294 | (1 << GAIN_IDX) | (1 << EXPOSURE_IDX) 299 | (1 << GAIN_IDX) | (1 << EXPOSURE_IDX)
295 | (1 << AUTOGAIN_IDX) | (1 << BACKLIGHT_IDX), 300 | (1 << AUTOGAIN_IDX) | (1 << BACKLIGHT_IDX),
296/* SENSOR_OV7670 6 */ 301 [SENSOR_OV7670] =
297 (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX) 302 (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX)
298 | (1 << SHARPNESS_IDX) 303 | (1 << SHARPNESS_IDX)
299 | (1 << GAIN_IDX) | (1 << EXPOSURE_IDX) 304 | (1 << GAIN_IDX) | (1 << EXPOSURE_IDX)
300 | (1 << AUTOGAIN_IDX) | (1 << BACKLIGHT_IDX), 305 | (1 << AUTOGAIN_IDX) | (1 << BACKLIGHT_IDX),
301/* SENSOR_PO1200 7 */ 306 [SENSOR_PO1200] =
302 (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX) 307 (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX)
303 | (1 << LIGHTFREQ_IDX) 308 | (1 << LIGHTFREQ_IDX)
304 | (1 << GAIN_IDX) | (1 << EXPOSURE_IDX) 309 | (1 << GAIN_IDX) | (1 << EXPOSURE_IDX)
305 | (1 << AUTOGAIN_IDX) | (1 << BACKLIGHT_IDX), 310 | (1 << AUTOGAIN_IDX) | (1 << BACKLIGHT_IDX),
306/* SENSOR_PO3130NC 8 */ 311 [SENSOR_PO3130NC] =
307 (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX) 312 (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX)
308 | (1 << HFLIP_IDX) | (1 << VFLIP_IDX) | (1 << LIGHTFREQ_IDX) 313 | (1 << HFLIP_IDX) | (1 << VFLIP_IDX) | (1 << LIGHTFREQ_IDX)
309 | (1 << SHARPNESS_IDX) 314 | (1 << SHARPNESS_IDX)
310 | (1 << GAIN_IDX) | (1 << EXPOSURE_IDX) 315 | (1 << GAIN_IDX) | (1 << EXPOSURE_IDX)
311 | (1 << AUTOGAIN_IDX) | (1 << BACKLIGHT_IDX), 316 | (1 << AUTOGAIN_IDX) | (1 << BACKLIGHT_IDX),
312/* SENSOR_POxxxx 9 */ 317 [SENSOR_POxxxx] =
313 (1 << HFLIP_IDX) | (1 << VFLIP_IDX) | (1 << LIGHTFREQ_IDX), 318 (1 << HFLIP_IDX) | (1 << VFLIP_IDX) | (1 << LIGHTFREQ_IDX),
314}; 319};
315 320
@@ -3420,17 +3425,18 @@ static int sd_init(struct gspca_dev *gspca_dev)
3420 struct sd *sd = (struct sd *) gspca_dev; 3425 struct sd *sd = (struct sd *) gspca_dev;
3421 struct cam *cam; 3426 struct cam *cam;
3422 int sensor; 3427 int sensor;
3423 static u8 npkt[] = { /* number of packets per ISOC message */ 3428 /* number of packets per ISOC message */
3424 64, /* HV7131R 0 */ 3429 static u8 npkt[NSENSORS] = {
3425 32, /* MI0360 1 */ 3430 [SENSOR_HV7131R] = 64,
3426 32, /* MI1310_SOC 2 */ 3431 [SENSOR_MI0360] = 32,
3427 64, /* MI1320 3 */ 3432 [SENSOR_MI1310_SOC] = 32,
3428 128, /* MI1320_SOC 4 */ 3433 [SENSOR_MI1320] = 64,
3429 32, /* OV7660 5 */ 3434 [SENSOR_MI1320_SOC] = 128,
3430 64, /* OV7670 6 */ 3435 [SENSOR_OV7660] = 32,
3431 128, /* PO1200 7 */ 3436 [SENSOR_OV7670] = 64,
3432 128, /* PO3130NC 8 */ 3437 [SENSOR_PO1200] = 128,
3433 128, /* POxxxx 9 */ 3438 [SENSOR_PO3130NC] = 128,
3439 [SENSOR_POxxxx] = 128,
3434 }; 3440 };
3435 3441
3436 if (sd->sensor != SENSOR_POxxxx) 3442 if (sd->sensor != SENSOR_POxxxx)
diff --git a/drivers/media/video/gspca/w996Xcf.c b/drivers/media/video/gspca/w996Xcf.c
index 4066ac8c45a0..4a9e622e5e1b 100644
--- a/drivers/media/video/gspca/w996Xcf.c
+++ b/drivers/media/video/gspca/w996Xcf.c
@@ -59,18 +59,21 @@ static const struct v4l2_pix_format w9968cf_vga_mode[] = {
59 .colorspace = V4L2_COLORSPACE_JPEG}, 59 .colorspace = V4L2_COLORSPACE_JPEG},
60}; 60};
61 61
62static int reg_w(struct sd *sd, __u16 index, __u16 value); 62static void reg_w(struct sd *sd, u16 index, u16 value);
63 63
64/*-------------------------------------------------------------------------- 64/*--------------------------------------------------------------------------
65 Write 64-bit data to the fast serial bus registers. 65 Write 64-bit data to the fast serial bus registers.
66 Return 0 on success, -1 otherwise. 66 Return 0 on success, -1 otherwise.
67 --------------------------------------------------------------------------*/ 67 --------------------------------------------------------------------------*/
68static int w9968cf_write_fsb(struct sd *sd, u16* data) 68static void w9968cf_write_fsb(struct sd *sd, u16* data)
69{ 69{
70 struct usb_device *udev = sd->gspca_dev.dev; 70 struct usb_device *udev = sd->gspca_dev.dev;
71 u16 value; 71 u16 value;
72 int ret; 72 int ret;
73 73
74 if (sd->gspca_dev.usb_err < 0)
75 return;
76
74 value = *data++; 77 value = *data++;
75 memcpy(sd->gspca_dev.usb_buf, data, 6); 78 memcpy(sd->gspca_dev.usb_buf, data, 6);
76 79
@@ -79,20 +82,21 @@ static int w9968cf_write_fsb(struct sd *sd, u16* data)
79 value, 0x06, sd->gspca_dev.usb_buf, 6, 500); 82 value, 0x06, sd->gspca_dev.usb_buf, 6, 500);
80 if (ret < 0) { 83 if (ret < 0) {
81 err("Write FSB registers failed (%d)", ret); 84 err("Write FSB registers failed (%d)", ret);
82 return ret; 85 sd->gspca_dev.usb_err = ret;
83 } 86 }
84
85 return 0;
86} 87}
87 88
88/*-------------------------------------------------------------------------- 89/*--------------------------------------------------------------------------
89 Write data to the serial bus control register. 90 Write data to the serial bus control register.
90 Return 0 on success, a negative number otherwise. 91 Return 0 on success, a negative number otherwise.
91 --------------------------------------------------------------------------*/ 92 --------------------------------------------------------------------------*/
92static int w9968cf_write_sb(struct sd *sd, u16 value) 93static void w9968cf_write_sb(struct sd *sd, u16 value)
93{ 94{
94 int ret; 95 int ret;
95 96
97 if (sd->gspca_dev.usb_err < 0)
98 return;
99
96 /* We don't use reg_w here, as that would cause all writes when 100 /* We don't use reg_w here, as that would cause all writes when
97 bitbanging i2c to be logged, making the logs impossible to read */ 101 bitbanging i2c to be logged, making the logs impossible to read */
98 ret = usb_control_msg(sd->gspca_dev.dev, 102 ret = usb_control_msg(sd->gspca_dev.dev,
@@ -105,10 +109,8 @@ static int w9968cf_write_sb(struct sd *sd, u16 value)
105 109
106 if (ret < 0) { 110 if (ret < 0) {
107 err("Write SB reg [01] %04x failed", value); 111 err("Write SB reg [01] %04x failed", value);
108 return ret; 112 sd->gspca_dev.usb_err = ret;
109 } 113 }
110
111 return 0;
112} 114}
113 115
114/*-------------------------------------------------------------------------- 116/*--------------------------------------------------------------------------
@@ -119,6 +121,9 @@ static int w9968cf_read_sb(struct sd *sd)
119{ 121{
120 int ret; 122 int ret;
121 123
124 if (sd->gspca_dev.usb_err < 0)
125 return -1;
126
122 /* We don't use reg_r here, as the w9968cf is special and has 16 127 /* We don't use reg_r here, as the w9968cf is special and has 16
123 bit registers instead of 8 bit */ 128 bit registers instead of 8 bit */
124 ret = usb_control_msg(sd->gspca_dev.dev, 129 ret = usb_control_msg(sd->gspca_dev.dev,
@@ -126,11 +131,13 @@ static int w9968cf_read_sb(struct sd *sd)
126 1, 131 1,
127 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 132 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
128 0, 0x01, sd->gspca_dev.usb_buf, 2, 500); 133 0, 0x01, sd->gspca_dev.usb_buf, 2, 500);
129 if (ret >= 0) 134 if (ret >= 0) {
130 ret = sd->gspca_dev.usb_buf[0] | 135 ret = sd->gspca_dev.usb_buf[0] |
131 (sd->gspca_dev.usb_buf[1] << 8); 136 (sd->gspca_dev.usb_buf[1] << 8);
132 else 137 } else {
133 err("Read SB reg [01] failed"); 138 err("Read SB reg [01] failed");
139 sd->gspca_dev.usb_err = ret;
140 }
134 141
135 udelay(W9968CF_I2C_BUS_DELAY); 142 udelay(W9968CF_I2C_BUS_DELAY);
136 143
@@ -142,22 +149,20 @@ static int w9968cf_read_sb(struct sd *sd)
142 This function is called by w9968cf_start_transfer(). 149 This function is called by w9968cf_start_transfer().
143 Return 0 on success, a negative number otherwise. 150 Return 0 on success, a negative number otherwise.
144 --------------------------------------------------------------------------*/ 151 --------------------------------------------------------------------------*/
145static int w9968cf_upload_quantizationtables(struct sd *sd) 152static void w9968cf_upload_quantizationtables(struct sd *sd)
146{ 153{
147 u16 a, b; 154 u16 a, b;
148 int ret = 0, i, j; 155 int i, j;
149 156
150 ret += reg_w(sd, 0x39, 0x0010); /* JPEG clock enable */ 157 reg_w(sd, 0x39, 0x0010); /* JPEG clock enable */
151 158
152 for (i = 0, j = 0; i < 32; i++, j += 2) { 159 for (i = 0, j = 0; i < 32; i++, j += 2) {
153 a = Y_QUANTABLE[j] | ((unsigned)(Y_QUANTABLE[j+1]) << 8); 160 a = Y_QUANTABLE[j] | ((unsigned)(Y_QUANTABLE[j + 1]) << 8);
154 b = UV_QUANTABLE[j] | ((unsigned)(UV_QUANTABLE[j+1]) << 8); 161 b = UV_QUANTABLE[j] | ((unsigned)(UV_QUANTABLE[j + 1]) << 8);
155 ret += reg_w(sd, 0x40+i, a); 162 reg_w(sd, 0x40 + i, a);
156 ret += reg_w(sd, 0x60+i, b); 163 reg_w(sd, 0x60 + i, b);
157 } 164 }
158 ret += reg_w(sd, 0x39, 0x0012); /* JPEG encoder enable */ 165 reg_w(sd, 0x39, 0x0012); /* JPEG encoder enable */
159
160 return ret;
161} 166}
162 167
163/**************************************************************************** 168/****************************************************************************
@@ -168,50 +173,39 @@ static int w9968cf_upload_quantizationtables(struct sd *sd)
168 * i2c_adap_read_byte() * 173 * i2c_adap_read_byte() *
169 ****************************************************************************/ 174 ****************************************************************************/
170 175
171static int w9968cf_smbus_start(struct sd *sd) 176static void w9968cf_smbus_start(struct sd *sd)
172{ 177{
173 int ret = 0; 178 w9968cf_write_sb(sd, 0x0011); /* SDE=1, SDA=0, SCL=1 */
174 179 w9968cf_write_sb(sd, 0x0010); /* SDE=1, SDA=0, SCL=0 */
175 ret += w9968cf_write_sb(sd, 0x0011); /* SDE=1, SDA=0, SCL=1 */
176 ret += w9968cf_write_sb(sd, 0x0010); /* SDE=1, SDA=0, SCL=0 */
177
178 return ret;
179} 180}
180 181
181static int w9968cf_smbus_stop(struct sd *sd) 182static void w9968cf_smbus_stop(struct sd *sd)
182{ 183{
183 int ret = 0; 184 w9968cf_write_sb(sd, 0x0010); /* SDE=1, SDA=0, SCL=0 */
184 185 w9968cf_write_sb(sd, 0x0011); /* SDE=1, SDA=0, SCL=1 */
185 ret += w9968cf_write_sb(sd, 0x0010); /* SDE=1, SDA=0, SCL=0 */ 186 w9968cf_write_sb(sd, 0x0013); /* SDE=1, SDA=1, SCL=1 */
186 ret += w9968cf_write_sb(sd, 0x0011); /* SDE=1, SDA=0, SCL=1 */
187 ret += w9968cf_write_sb(sd, 0x0013); /* SDE=1, SDA=1, SCL=1 */
188
189 return ret;
190} 187}
191 188
192static int w9968cf_smbus_write_byte(struct sd *sd, u8 v) 189static void w9968cf_smbus_write_byte(struct sd *sd, u8 v)
193{ 190{
194 u8 bit; 191 u8 bit;
195 int ret = 0, sda; 192 int sda;
196 193
197 for (bit = 0 ; bit < 8 ; bit++) { 194 for (bit = 0 ; bit < 8 ; bit++) {
198 sda = (v & 0x80) ? 2 : 0; 195 sda = (v & 0x80) ? 2 : 0;
199 v <<= 1; 196 v <<= 1;
200 /* SDE=1, SDA=sda, SCL=0 */ 197 /* SDE=1, SDA=sda, SCL=0 */
201 ret += w9968cf_write_sb(sd, 0x10 | sda); 198 w9968cf_write_sb(sd, 0x10 | sda);
202 /* SDE=1, SDA=sda, SCL=1 */ 199 /* SDE=1, SDA=sda, SCL=1 */
203 ret += w9968cf_write_sb(sd, 0x11 | sda); 200 w9968cf_write_sb(sd, 0x11 | sda);
204 /* SDE=1, SDA=sda, SCL=0 */ 201 /* SDE=1, SDA=sda, SCL=0 */
205 ret += w9968cf_write_sb(sd, 0x10 | sda); 202 w9968cf_write_sb(sd, 0x10 | sda);
206 } 203 }
207
208 return ret;
209} 204}
210 205
211static int w9968cf_smbus_read_byte(struct sd *sd, u8* v) 206static void w9968cf_smbus_read_byte(struct sd *sd, u8 *v)
212{ 207{
213 u8 bit; 208 u8 bit;
214 int ret = 0;
215 209
216 /* No need to ensure SDA is high as we are always called after 210 /* No need to ensure SDA is high as we are always called after
217 read_ack which ends with SDA high */ 211 read_ack which ends with SDA high */
@@ -219,51 +213,40 @@ static int w9968cf_smbus_read_byte(struct sd *sd, u8* v)
219 for (bit = 0 ; bit < 8 ; bit++) { 213 for (bit = 0 ; bit < 8 ; bit++) {
220 *v <<= 1; 214 *v <<= 1;
221 /* SDE=1, SDA=1, SCL=1 */ 215 /* SDE=1, SDA=1, SCL=1 */
222 ret += w9968cf_write_sb(sd, 0x0013); 216 w9968cf_write_sb(sd, 0x0013);
223 *v |= (w9968cf_read_sb(sd) & 0x0008) ? 1 : 0; 217 *v |= (w9968cf_read_sb(sd) & 0x0008) ? 1 : 0;
224 /* SDE=1, SDA=1, SCL=0 */ 218 /* SDE=1, SDA=1, SCL=0 */
225 ret += w9968cf_write_sb(sd, 0x0012); 219 w9968cf_write_sb(sd, 0x0012);
226 } 220 }
227
228 return ret;
229} 221}
230 222
231static int w9968cf_smbus_write_nack(struct sd *sd) 223static void w9968cf_smbus_write_nack(struct sd *sd)
232{ 224{
233 int ret = 0;
234
235 /* No need to ensure SDA is high as we are always called after 225 /* No need to ensure SDA is high as we are always called after
236 read_byte which ends with SDA high */ 226 read_byte which ends with SDA high */
237 ret += w9968cf_write_sb(sd, 0x0013); /* SDE=1, SDA=1, SCL=1 */ 227 w9968cf_write_sb(sd, 0x0013); /* SDE=1, SDA=1, SCL=1 */
238 ret += w9968cf_write_sb(sd, 0x0012); /* SDE=1, SDA=1, SCL=0 */ 228 w9968cf_write_sb(sd, 0x0012); /* SDE=1, SDA=1, SCL=0 */
239
240 return ret;
241} 229}
242 230
243static int w9968cf_smbus_read_ack(struct sd *sd) 231static void w9968cf_smbus_read_ack(struct sd *sd)
244{ 232{
245 int ret = 0, sda; 233 int sda;
246 234
247 /* Ensure SDA is high before raising clock to avoid a spurious stop */ 235 /* Ensure SDA is high before raising clock to avoid a spurious stop */
248 ret += w9968cf_write_sb(sd, 0x0012); /* SDE=1, SDA=1, SCL=0 */ 236 w9968cf_write_sb(sd, 0x0012); /* SDE=1, SDA=1, SCL=0 */
249 ret += w9968cf_write_sb(sd, 0x0013); /* SDE=1, SDA=1, SCL=1 */ 237 w9968cf_write_sb(sd, 0x0013); /* SDE=1, SDA=1, SCL=1 */
250 sda = w9968cf_read_sb(sd); 238 sda = w9968cf_read_sb(sd);
251 ret += w9968cf_write_sb(sd, 0x0012); /* SDE=1, SDA=1, SCL=0 */ 239 w9968cf_write_sb(sd, 0x0012); /* SDE=1, SDA=1, SCL=0 */
252 if (sda < 0) 240 if (sda >= 0 && (sda & 0x08)) {
253 ret += sda;
254 else if (sda & 0x08) {
255 PDEBUG(D_USBI, "Did not receive i2c ACK"); 241 PDEBUG(D_USBI, "Did not receive i2c ACK");
256 ret += -1; 242 sd->gspca_dev.usb_err = -EIO;
257 } 243 }
258
259 return ret;
260} 244}
261 245
262/* SMBus protocol: S Addr Wr [A] Subaddr [A] Value [A] P */ 246/* SMBus protocol: S Addr Wr [A] Subaddr [A] Value [A] P */
263static int w9968cf_i2c_w(struct sd *sd, u8 reg, u8 value) 247static void w9968cf_i2c_w(struct sd *sd, u8 reg, u8 value)
264{ 248{
265 u16* data = (u16 *)sd->gspca_dev.usb_buf; 249 u16* data = (u16 *)sd->gspca_dev.usb_buf;
266 int ret = 0;
267 250
268 data[0] = 0x082f | ((sd->sensor_addr & 0x80) ? 0x1500 : 0x0); 251 data[0] = 0x082f | ((sd->sensor_addr & 0x80) ? 0x1500 : 0x0);
269 data[0] |= (sd->sensor_addr & 0x40) ? 0x4000 : 0x0; 252 data[0] |= (sd->sensor_addr & 0x40) ? 0x4000 : 0x0;
@@ -276,7 +259,7 @@ static int w9968cf_i2c_w(struct sd *sd, u8 reg, u8 value)
276 data[3] = 0x1d20 | ((sd->sensor_addr & 0x02) ? 0x0001 : 0x0); 259 data[3] = 0x1d20 | ((sd->sensor_addr & 0x02) ? 0x0001 : 0x0);
277 data[3] |= (sd->sensor_addr & 0x01) ? 0x0054 : 0x0; 260 data[3] |= (sd->sensor_addr & 0x01) ? 0x0054 : 0x0;
278 261
279 ret += w9968cf_write_fsb(sd, data); 262 w9968cf_write_fsb(sd, data);
280 263
281 data[0] = 0x8208 | ((reg & 0x80) ? 0x0015 : 0x0); 264 data[0] = 0x8208 | ((reg & 0x80) ? 0x0015 : 0x0);
282 data[0] |= (reg & 0x40) ? 0x0540 : 0x0; 265 data[0] |= (reg & 0x40) ? 0x0540 : 0x0;
@@ -290,7 +273,7 @@ static int w9968cf_i2c_w(struct sd *sd, u8 reg, u8 value)
290 data[2] |= (reg & 0x01) ? 0x5400 : 0x0; 273 data[2] |= (reg & 0x01) ? 0x5400 : 0x0;
291 data[3] = 0x001d; 274 data[3] = 0x001d;
292 275
293 ret += w9968cf_write_fsb(sd, data); 276 w9968cf_write_fsb(sd, data);
294 277
295 data[0] = 0x8208 | ((value & 0x80) ? 0x0015 : 0x0); 278 data[0] = 0x8208 | ((value & 0x80) ? 0x0015 : 0x0);
296 data[0] |= (value & 0x40) ? 0x0540 : 0x0; 279 data[0] |= (value & 0x40) ? 0x0540 : 0x0;
@@ -304,14 +287,9 @@ static int w9968cf_i2c_w(struct sd *sd, u8 reg, u8 value)
304 data[2] |= (value & 0x01) ? 0x5400 : 0x0; 287 data[2] |= (value & 0x01) ? 0x5400 : 0x0;
305 data[3] = 0xfe1d; 288 data[3] = 0xfe1d;
306 289
307 ret += w9968cf_write_fsb(sd, data); 290 w9968cf_write_fsb(sd, data);
308 291
309 if (!ret) 292 PDEBUG(D_USBO, "i2c 0x%02x -> [0x%02x]", value, reg);
310 PDEBUG(D_USBO, "i2c 0x%02x -> [0x%02x]", value, reg);
311 else
312 PDEBUG(D_ERR, "i2c 0x%02x -> [0x%02x] failed", value, reg);
313
314 return ret;
315} 293}
316 294
317/* SMBus protocol: S Addr Wr [A] Subaddr [A] P S Addr+1 Rd [A] [Value] NA P */ 295/* SMBus protocol: S Addr Wr [A] Subaddr [A] P S Addr+1 Rd [A] [Value] NA P */
@@ -321,28 +299,28 @@ static int w9968cf_i2c_r(struct sd *sd, u8 reg)
321 u8 value; 299 u8 value;
322 300
323 /* Fast serial bus data control disable */ 301 /* Fast serial bus data control disable */
324 ret += w9968cf_write_sb(sd, 0x0013); /* don't change ! */ 302 w9968cf_write_sb(sd, 0x0013); /* don't change ! */
325 303
326 ret += w9968cf_smbus_start(sd); 304 w9968cf_smbus_start(sd);
327 ret += w9968cf_smbus_write_byte(sd, sd->sensor_addr); 305 w9968cf_smbus_write_byte(sd, sd->sensor_addr);
328 ret += w9968cf_smbus_read_ack(sd); 306 w9968cf_smbus_read_ack(sd);
329 ret += w9968cf_smbus_write_byte(sd, reg); 307 w9968cf_smbus_write_byte(sd, reg);
330 ret += w9968cf_smbus_read_ack(sd); 308 w9968cf_smbus_read_ack(sd);
331 ret += w9968cf_smbus_stop(sd); 309 w9968cf_smbus_stop(sd);
332 ret += w9968cf_smbus_start(sd); 310 w9968cf_smbus_start(sd);
333 ret += w9968cf_smbus_write_byte(sd, sd->sensor_addr + 1); 311 w9968cf_smbus_write_byte(sd, sd->sensor_addr + 1);
334 ret += w9968cf_smbus_read_ack(sd); 312 w9968cf_smbus_read_ack(sd);
335 ret += w9968cf_smbus_read_byte(sd, &value); 313 w9968cf_smbus_read_byte(sd, &value);
336 /* signal we don't want to read anymore, the v4l1 driver used to 314 /* signal we don't want to read anymore, the v4l1 driver used to
337 send an ack here which is very wrong! (and then fixed 315 send an ack here which is very wrong! (and then fixed
338 the issues this gave by retrying reads) */ 316 the issues this gave by retrying reads) */
339 ret += w9968cf_smbus_write_nack(sd); 317 w9968cf_smbus_write_nack(sd);
340 ret += w9968cf_smbus_stop(sd); 318 w9968cf_smbus_stop(sd);
341 319
342 /* Fast serial bus data control re-enable */ 320 /* Fast serial bus data control re-enable */
343 ret += w9968cf_write_sb(sd, 0x0030); 321 w9968cf_write_sb(sd, 0x0030);
344 322
345 if (!ret) { 323 if (sd->gspca_dev.usb_err >= 0) {
346 ret = value; 324 ret = value;
347 PDEBUG(D_USBI, "i2c [0x%02X] -> 0x%02X", reg, value); 325 PDEBUG(D_USBI, "i2c [0x%02X] -> 0x%02X", reg, value);
348 } else 326 } else
@@ -351,79 +329,68 @@ static int w9968cf_i2c_r(struct sd *sd, u8 reg)
351 return ret; 329 return ret;
352} 330}
353 331
354
355/*-------------------------------------------------------------------------- 332/*--------------------------------------------------------------------------
356 Turn on the LED on some webcams. A beep should be heard too. 333 Turn on the LED on some webcams. A beep should be heard too.
357 Return 0 on success, a negative number otherwise. 334 Return 0 on success, a negative number otherwise.
358 --------------------------------------------------------------------------*/ 335 --------------------------------------------------------------------------*/
359static int w9968cf_configure(struct sd *sd) 336static void w9968cf_configure(struct sd *sd)
360{ 337{
361 int ret = 0; 338 reg_w(sd, 0x00, 0xff00); /* power-down */
362 339 reg_w(sd, 0x00, 0xbf17); /* reset everything */
363 ret += reg_w(sd, 0x00, 0xff00); /* power-down */ 340 reg_w(sd, 0x00, 0xbf10); /* normal operation */
364 ret += reg_w(sd, 0x00, 0xbf17); /* reset everything */ 341 reg_w(sd, 0x01, 0x0010); /* serial bus, SDS high */
365 ret += reg_w(sd, 0x00, 0xbf10); /* normal operation */ 342 reg_w(sd, 0x01, 0x0000); /* serial bus, SDS low */
366 ret += reg_w(sd, 0x01, 0x0010); /* serial bus, SDS high */ 343 reg_w(sd, 0x01, 0x0010); /* ..high 'beep-beep' */
367 ret += reg_w(sd, 0x01, 0x0000); /* serial bus, SDS low */ 344 reg_w(sd, 0x01, 0x0030); /* Set sda scl to FSB mode */
368 ret += reg_w(sd, 0x01, 0x0010); /* ..high 'beep-beep' */
369 ret += reg_w(sd, 0x01, 0x0030); /* Set sda scl to FSB mode */
370
371 if (ret)
372 PDEBUG(D_ERR, "Couldn't turn on the LED");
373 345
374 sd->stopped = 1; 346 sd->stopped = 1;
375
376 return ret;
377} 347}
378 348
379static int w9968cf_init(struct sd *sd) 349static void w9968cf_init(struct sd *sd)
380{ 350{
381 int ret = 0;
382 unsigned long hw_bufsize = sd->sif ? (352 * 288 * 2) : (640 * 480 * 2), 351 unsigned long hw_bufsize = sd->sif ? (352 * 288 * 2) : (640 * 480 * 2),
383 y0 = 0x0000, 352 y0 = 0x0000,
384 u0 = y0 + hw_bufsize/2, 353 u0 = y0 + hw_bufsize / 2,
385 v0 = u0 + hw_bufsize/4, 354 v0 = u0 + hw_bufsize / 4,
386 y1 = v0 + hw_bufsize/4, 355 y1 = v0 + hw_bufsize / 4,
387 u1 = y1 + hw_bufsize/2, 356 u1 = y1 + hw_bufsize / 2,
388 v1 = u1 + hw_bufsize/4; 357 v1 = u1 + hw_bufsize / 4;
389 358
390 ret += reg_w(sd, 0x00, 0xff00); /* power off */ 359 reg_w(sd, 0x00, 0xff00); /* power off */
391 ret += reg_w(sd, 0x00, 0xbf10); /* power on */ 360 reg_w(sd, 0x00, 0xbf10); /* power on */
392 361
393 ret += reg_w(sd, 0x03, 0x405d); /* DRAM timings */ 362 reg_w(sd, 0x03, 0x405d); /* DRAM timings */
394 ret += reg_w(sd, 0x04, 0x0030); /* SDRAM timings */ 363 reg_w(sd, 0x04, 0x0030); /* SDRAM timings */
395 364
396 ret += reg_w(sd, 0x20, y0 & 0xffff); /* Y buf.0, low */ 365 reg_w(sd, 0x20, y0 & 0xffff); /* Y buf.0, low */
397 ret += reg_w(sd, 0x21, y0 >> 16); /* Y buf.0, high */ 366 reg_w(sd, 0x21, y0 >> 16); /* Y buf.0, high */
398 ret += reg_w(sd, 0x24, u0 & 0xffff); /* U buf.0, low */ 367 reg_w(sd, 0x24, u0 & 0xffff); /* U buf.0, low */
399 ret += reg_w(sd, 0x25, u0 >> 16); /* U buf.0, high */ 368 reg_w(sd, 0x25, u0 >> 16); /* U buf.0, high */
400 ret += reg_w(sd, 0x28, v0 & 0xffff); /* V buf.0, low */ 369 reg_w(sd, 0x28, v0 & 0xffff); /* V buf.0, low */
401 ret += reg_w(sd, 0x29, v0 >> 16); /* V buf.0, high */ 370 reg_w(sd, 0x29, v0 >> 16); /* V buf.0, high */
402 371
403 ret += reg_w(sd, 0x22, y1 & 0xffff); /* Y buf.1, low */ 372 reg_w(sd, 0x22, y1 & 0xffff); /* Y buf.1, low */
404 ret += reg_w(sd, 0x23, y1 >> 16); /* Y buf.1, high */ 373 reg_w(sd, 0x23, y1 >> 16); /* Y buf.1, high */
405 ret += reg_w(sd, 0x26, u1 & 0xffff); /* U buf.1, low */ 374 reg_w(sd, 0x26, u1 & 0xffff); /* U buf.1, low */
406 ret += reg_w(sd, 0x27, u1 >> 16); /* U buf.1, high */ 375 reg_w(sd, 0x27, u1 >> 16); /* U buf.1, high */
407 ret += reg_w(sd, 0x2a, v1 & 0xffff); /* V buf.1, low */ 376 reg_w(sd, 0x2a, v1 & 0xffff); /* V buf.1, low */
408 ret += reg_w(sd, 0x2b, v1 >> 16); /* V buf.1, high */ 377 reg_w(sd, 0x2b, v1 >> 16); /* V buf.1, high */
409 378
410 ret += reg_w(sd, 0x32, y1 & 0xffff); /* JPEG buf 0 low */ 379 reg_w(sd, 0x32, y1 & 0xffff); /* JPEG buf 0 low */
411 ret += reg_w(sd, 0x33, y1 >> 16); /* JPEG buf 0 high */ 380 reg_w(sd, 0x33, y1 >> 16); /* JPEG buf 0 high */
412 381
413 ret += reg_w(sd, 0x34, y1 & 0xffff); /* JPEG buf 1 low */ 382 reg_w(sd, 0x34, y1 & 0xffff); /* JPEG buf 1 low */
414 ret += reg_w(sd, 0x35, y1 >> 16); /* JPEG bug 1 high */ 383 reg_w(sd, 0x35, y1 >> 16); /* JPEG bug 1 high */
415 384
416 ret += reg_w(sd, 0x36, 0x0000);/* JPEG restart interval */ 385 reg_w(sd, 0x36, 0x0000);/* JPEG restart interval */
417 ret += reg_w(sd, 0x37, 0x0804);/*JPEG VLE FIFO threshold*/ 386 reg_w(sd, 0x37, 0x0804);/*JPEG VLE FIFO threshold*/
418 ret += reg_w(sd, 0x38, 0x0000);/* disable hw up-scaling */ 387 reg_w(sd, 0x38, 0x0000);/* disable hw up-scaling */
419 ret += reg_w(sd, 0x3f, 0x0000); /* JPEG/MCTL test data */ 388 reg_w(sd, 0x3f, 0x0000); /* JPEG/MCTL test data */
420
421 return ret;
422} 389}
423 390
424static int w9968cf_set_crop_window(struct sd *sd) 391static void w9968cf_set_crop_window(struct sd *sd)
425{ 392{
426 int ret = 0, start_cropx, start_cropy, x, y, fw, fh, cw, ch, 393 int start_cropx, start_cropy, x, y, fw, fh, cw, ch,
427 max_width, max_height; 394 max_width, max_height;
428 395
429 if (sd->sif) { 396 if (sd->sif) {
@@ -456,8 +423,8 @@ static int w9968cf_set_crop_window(struct sd *sd)
456 fw = SC(sd->gspca_dev.width) / max_width; 423 fw = SC(sd->gspca_dev.width) / max_width;
457 fh = SC(sd->gspca_dev.height) / max_height; 424 fh = SC(sd->gspca_dev.height) / max_height;
458 425
459 cw = (fw >= fh) ? max_width : SC(sd->gspca_dev.width)/fh; 426 cw = (fw >= fh) ? max_width : SC(sd->gspca_dev.width) / fh;
460 ch = (fw >= fh) ? SC(sd->gspca_dev.height)/fw : max_height; 427 ch = (fw >= fh) ? SC(sd->gspca_dev.height) / fw : max_height;
461 428
462 sd->sensor_width = max_width; 429 sd->sensor_width = max_width;
463 sd->sensor_height = max_height; 430 sd->sensor_height = max_height;
@@ -465,42 +432,40 @@ static int w9968cf_set_crop_window(struct sd *sd)
465 x = (max_width - cw) / 2; 432 x = (max_width - cw) / 2;
466 y = (max_height - ch) / 2; 433 y = (max_height - ch) / 2;
467 434
468 ret += reg_w(sd, 0x10, start_cropx + x); 435 reg_w(sd, 0x10, start_cropx + x);
469 ret += reg_w(sd, 0x11, start_cropy + y); 436 reg_w(sd, 0x11, start_cropy + y);
470 ret += reg_w(sd, 0x12, start_cropx + x + cw); 437 reg_w(sd, 0x12, start_cropx + x + cw);
471 ret += reg_w(sd, 0x13, start_cropy + y + ch); 438 reg_w(sd, 0x13, start_cropy + y + ch);
472
473 return ret;
474} 439}
475 440
476static int w9968cf_mode_init_regs(struct sd *sd) 441static void w9968cf_mode_init_regs(struct sd *sd)
477{ 442{
478 int ret = 0, val, vs_polarity, hs_polarity; 443 int val, vs_polarity, hs_polarity;
479 444
480 ret += w9968cf_set_crop_window(sd); 445 w9968cf_set_crop_window(sd);
481 446
482 ret += reg_w(sd, 0x14, sd->gspca_dev.width); 447 reg_w(sd, 0x14, sd->gspca_dev.width);
483 ret += reg_w(sd, 0x15, sd->gspca_dev.height); 448 reg_w(sd, 0x15, sd->gspca_dev.height);
484 449
485 /* JPEG width & height */ 450 /* JPEG width & height */
486 ret += reg_w(sd, 0x30, sd->gspca_dev.width); 451 reg_w(sd, 0x30, sd->gspca_dev.width);
487 ret += reg_w(sd, 0x31, sd->gspca_dev.height); 452 reg_w(sd, 0x31, sd->gspca_dev.height);
488 453
489 /* Y & UV frame buffer strides (in WORD) */ 454 /* Y & UV frame buffer strides (in WORD) */
490 if (w9968cf_vga_mode[sd->gspca_dev.curr_mode].pixelformat == 455 if (w9968cf_vga_mode[sd->gspca_dev.curr_mode].pixelformat ==
491 V4L2_PIX_FMT_JPEG) { 456 V4L2_PIX_FMT_JPEG) {
492 ret += reg_w(sd, 0x2c, sd->gspca_dev.width/2); 457 reg_w(sd, 0x2c, sd->gspca_dev.width / 2);
493 ret += reg_w(sd, 0x2d, sd->gspca_dev.width/4); 458 reg_w(sd, 0x2d, sd->gspca_dev.width / 4);
494 } else 459 } else
495 ret += reg_w(sd, 0x2c, sd->gspca_dev.width); 460 reg_w(sd, 0x2c, sd->gspca_dev.width);
496 461
497 ret += reg_w(sd, 0x00, 0xbf17); /* reset everything */ 462 reg_w(sd, 0x00, 0xbf17); /* reset everything */
498 ret += reg_w(sd, 0x00, 0xbf10); /* normal operation */ 463 reg_w(sd, 0x00, 0xbf10); /* normal operation */
499 464
500 /* Transfer size in WORDS (for UYVY format only) */ 465 /* Transfer size in WORDS (for UYVY format only) */
501 val = sd->gspca_dev.width * sd->gspca_dev.height; 466 val = sd->gspca_dev.width * sd->gspca_dev.height;
502 ret += reg_w(sd, 0x3d, val & 0xffff); /* low bits */ 467 reg_w(sd, 0x3d, val & 0xffff); /* low bits */
503 ret += reg_w(sd, 0x3e, val >> 16); /* high bits */ 468 reg_w(sd, 0x3e, val >> 16); /* high bits */
504 469
505 if (w9968cf_vga_mode[sd->gspca_dev.curr_mode].pixelformat == 470 if (w9968cf_vga_mode[sd->gspca_dev.curr_mode].pixelformat ==
506 V4L2_PIX_FMT_JPEG) { 471 V4L2_PIX_FMT_JPEG) {
@@ -508,7 +473,7 @@ static int w9968cf_mode_init_regs(struct sd *sd)
508 jpeg_define(sd->jpeg_hdr, sd->gspca_dev.height, 473 jpeg_define(sd->jpeg_hdr, sd->gspca_dev.height,
509 sd->gspca_dev.width, 0x22); /* JPEG 420 */ 474 sd->gspca_dev.width, 0x22); /* JPEG 420 */
510 jpeg_set_qual(sd->jpeg_hdr, sd->quality); 475 jpeg_set_qual(sd->jpeg_hdr, sd->quality);
511 ret += w9968cf_upload_quantizationtables(sd); 476 w9968cf_upload_quantizationtables(sd);
512 } 477 }
513 478
514 /* Video Capture Control Register */ 479 /* Video Capture Control Register */
@@ -540,19 +505,15 @@ static int w9968cf_mode_init_regs(struct sd *sd)
540 505
541 val |= 0x8000; /* capt. enable */ 506 val |= 0x8000; /* capt. enable */
542 507
543 ret += reg_w(sd, 0x16, val); 508 reg_w(sd, 0x16, val);
544 509
545 sd->gspca_dev.empty_packet = 0; 510 sd->gspca_dev.empty_packet = 0;
546
547 return ret;
548} 511}
549 512
550static void w9968cf_stop0(struct sd *sd) 513static void w9968cf_stop0(struct sd *sd)
551{ 514{
552 if (sd->gspca_dev.present) { 515 reg_w(sd, 0x39, 0x0000); /* disable JPEG encoder */
553 reg_w(sd, 0x39, 0x0000); /* disable JPEG encoder */ 516 reg_w(sd, 0x16, 0x0000); /* stop video capture */
554 reg_w(sd, 0x16, 0x0000); /* stop video capture */
555 }
556} 517}
557 518
558/* The w9968cf docs say that a 0 sized packet means EOF (and also SOF 519/* The w9968cf docs say that a 0 sized packet means EOF (and also SOF
diff --git a/drivers/media/video/gspca/xirlink_cit.c b/drivers/media/video/gspca/xirlink_cit.c
index 8715577bc2d8..5b5039a02031 100644
--- a/drivers/media/video/gspca/xirlink_cit.c
+++ b/drivers/media/video/gspca/xirlink_cit.c
@@ -29,6 +29,7 @@
29 29
30#define MODULE_NAME "xirlink-cit" 30#define MODULE_NAME "xirlink-cit"
31 31
32#include <linux/input.h>
32#include "gspca.h" 33#include "gspca.h"
33 34
34MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>"); 35MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>");
@@ -58,6 +59,7 @@ struct sd {
58#define CIT_MODEL4 4 59#define CIT_MODEL4 4
59#define CIT_IBM_NETCAM_PRO 5 60#define CIT_IBM_NETCAM_PRO 5
60 u8 input_index; 61 u8 input_index;
62 u8 button_state;
61 u8 stop_on_control_change; 63 u8 stop_on_control_change;
62 u8 sof_read; 64 u8 sof_read;
63 u8 sof_len; 65 u8 sof_len;
@@ -185,60 +187,60 @@ static const struct ctrl sd_ctrls[] = {
185static const struct v4l2_pix_format cif_yuv_mode[] = { 187static const struct v4l2_pix_format cif_yuv_mode[] = {
186 {176, 144, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE, 188 {176, 144, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
187 .bytesperline = 176, 189 .bytesperline = 176,
188 .sizeimage = 176 * 144 * 3 / 2, 190 .sizeimage = 176 * 144 * 3 / 2 + 4,
189 .colorspace = V4L2_COLORSPACE_SRGB}, 191 .colorspace = V4L2_COLORSPACE_SRGB},
190 {352, 288, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE, 192 {352, 288, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
191 .bytesperline = 352, 193 .bytesperline = 352,
192 .sizeimage = 352 * 288 * 3 / 2, 194 .sizeimage = 352 * 288 * 3 / 2 + 4,
193 .colorspace = V4L2_COLORSPACE_SRGB}, 195 .colorspace = V4L2_COLORSPACE_SRGB},
194}; 196};
195 197
196static const struct v4l2_pix_format vga_yuv_mode[] = { 198static const struct v4l2_pix_format vga_yuv_mode[] = {
197 {160, 120, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE, 199 {160, 120, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
198 .bytesperline = 160, 200 .bytesperline = 160,
199 .sizeimage = 160 * 120 * 3 / 2, 201 .sizeimage = 160 * 120 * 3 / 2 + 4,
200 .colorspace = V4L2_COLORSPACE_SRGB}, 202 .colorspace = V4L2_COLORSPACE_SRGB},
201 {320, 240, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE, 203 {320, 240, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
202 .bytesperline = 320, 204 .bytesperline = 320,
203 .sizeimage = 320 * 240 * 3 / 2, 205 .sizeimage = 320 * 240 * 3 / 2 + 4,
204 .colorspace = V4L2_COLORSPACE_SRGB}, 206 .colorspace = V4L2_COLORSPACE_SRGB},
205 {640, 480, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE, 207 {640, 480, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
206 .bytesperline = 640, 208 .bytesperline = 640,
207 .sizeimage = 640 * 480 * 3 / 2, 209 .sizeimage = 640 * 480 * 3 / 2 + 4,
208 .colorspace = V4L2_COLORSPACE_SRGB}, 210 .colorspace = V4L2_COLORSPACE_SRGB},
209}; 211};
210 212
211static const struct v4l2_pix_format model0_mode[] = { 213static const struct v4l2_pix_format model0_mode[] = {
212 {160, 120, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE, 214 {160, 120, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
213 .bytesperline = 160, 215 .bytesperline = 160,
214 .sizeimage = 160 * 120 * 3 / 2, 216 .sizeimage = 160 * 120 * 3 / 2 + 4,
215 .colorspace = V4L2_COLORSPACE_SRGB}, 217 .colorspace = V4L2_COLORSPACE_SRGB},
216 {176, 144, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE, 218 {176, 144, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
217 .bytesperline = 176, 219 .bytesperline = 176,
218 .sizeimage = 176 * 144 * 3 / 2, 220 .sizeimage = 176 * 144 * 3 / 2 + 4,
219 .colorspace = V4L2_COLORSPACE_SRGB}, 221 .colorspace = V4L2_COLORSPACE_SRGB},
220 {320, 240, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE, 222 {320, 240, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
221 .bytesperline = 320, 223 .bytesperline = 320,
222 .sizeimage = 320 * 240 * 3 / 2, 224 .sizeimage = 320 * 240 * 3 / 2 + 4,
223 .colorspace = V4L2_COLORSPACE_SRGB}, 225 .colorspace = V4L2_COLORSPACE_SRGB},
224}; 226};
225 227
226static const struct v4l2_pix_format model2_mode[] = { 228static const struct v4l2_pix_format model2_mode[] = {
227 {160, 120, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE, 229 {160, 120, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
228 .bytesperline = 160, 230 .bytesperline = 160,
229 .sizeimage = 160 * 120 * 3 / 2, 231 .sizeimage = 160 * 120 * 3 / 2 + 4,
230 .colorspace = V4L2_COLORSPACE_SRGB}, 232 .colorspace = V4L2_COLORSPACE_SRGB},
231 {176, 144, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE, 233 {176, 144, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE,
232 .bytesperline = 176, 234 .bytesperline = 176,
233 .sizeimage = 176 * 144 * 3 / 2, 235 .sizeimage = 176 * 144 * 3 / 2 + 4,
234 .colorspace = V4L2_COLORSPACE_SRGB}, 236 .colorspace = V4L2_COLORSPACE_SRGB},
235 {320, 240, V4L2_PIX_FMT_SGRBG8, V4L2_FIELD_NONE, 237 {320, 240, V4L2_PIX_FMT_SGRBG8, V4L2_FIELD_NONE,
236 .bytesperline = 320, 238 .bytesperline = 320,
237 .sizeimage = 320 * 240, 239 .sizeimage = 320 * 240 + 4,
238 .colorspace = V4L2_COLORSPACE_SRGB}, 240 .colorspace = V4L2_COLORSPACE_SRGB},
239 {352, 288, V4L2_PIX_FMT_SGRBG8, V4L2_FIELD_NONE, 241 {352, 288, V4L2_PIX_FMT_SGRBG8, V4L2_FIELD_NONE,
240 .bytesperline = 352, 242 .bytesperline = 352,
241 .sizeimage = 352 * 288, 243 .sizeimage = 352 * 288 + 4,
242 .colorspace = V4L2_COLORSPACE_SRGB}, 244 .colorspace = V4L2_COLORSPACE_SRGB},
243}; 245};
244 246
@@ -804,7 +806,7 @@ static int cit_write_reg(struct gspca_dev *gspca_dev, u16 value, u16 index)
804 return 0; 806 return 0;
805} 807}
806 808
807static int cit_read_reg(struct gspca_dev *gspca_dev, u16 index) 809static int cit_read_reg(struct gspca_dev *gspca_dev, u16 index, int verbose)
808{ 810{
809 struct usb_device *udev = gspca_dev->dev; 811 struct usb_device *udev = gspca_dev->dev;
810 __u8 *buf = gspca_dev->usb_buf; 812 __u8 *buf = gspca_dev->usb_buf;
@@ -819,10 +821,8 @@ static int cit_read_reg(struct gspca_dev *gspca_dev, u16 index)
819 return res; 821 return res;
820 } 822 }
821 823
822 PDEBUG(D_PROBE, 824 if (verbose)
823 "Register %04x value: %02x %02x %02x %02x %02x %02x %02x %02x", 825 PDEBUG(D_PROBE, "Register %04x value: %02x", index, buf[0]);
824 index,
825 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]);
826 826
827 return 0; 827 return 0;
828} 828}
@@ -907,7 +907,7 @@ static void cit_Packet_Format1(struct gspca_dev *gspca_dev, u16 fkey, u16 val)
907 cit_send_x_00_05(gspca_dev, 0x0089); 907 cit_send_x_00_05(gspca_dev, 0x0089);
908 cit_send_x_00(gspca_dev, fkey); 908 cit_send_x_00(gspca_dev, fkey);
909 cit_send_00_04_06(gspca_dev); 909 cit_send_00_04_06(gspca_dev);
910 cit_read_reg(gspca_dev, 0x0126); 910 cit_read_reg(gspca_dev, 0x0126, 0);
911 cit_send_FF_04_02(gspca_dev); 911 cit_send_FF_04_02(gspca_dev);
912} 912}
913 913
@@ -1074,12 +1074,12 @@ static int cit_init_model0(struct gspca_dev *gspca_dev)
1074 1074
1075static int cit_init_ibm_netcam_pro(struct gspca_dev *gspca_dev) 1075static int cit_init_ibm_netcam_pro(struct gspca_dev *gspca_dev)
1076{ 1076{
1077 cit_read_reg(gspca_dev, 0x128); 1077 cit_read_reg(gspca_dev, 0x128, 1);
1078 cit_write_reg(gspca_dev, 0x0003, 0x0133); 1078 cit_write_reg(gspca_dev, 0x0003, 0x0133);
1079 cit_write_reg(gspca_dev, 0x0000, 0x0117); 1079 cit_write_reg(gspca_dev, 0x0000, 0x0117);
1080 cit_write_reg(gspca_dev, 0x0008, 0x0123); 1080 cit_write_reg(gspca_dev, 0x0008, 0x0123);
1081 cit_write_reg(gspca_dev, 0x0000, 0x0100); 1081 cit_write_reg(gspca_dev, 0x0000, 0x0100);
1082 cit_read_reg(gspca_dev, 0x0116); 1082 cit_read_reg(gspca_dev, 0x0116, 0);
1083 cit_write_reg(gspca_dev, 0x0060, 0x0116); 1083 cit_write_reg(gspca_dev, 0x0060, 0x0116);
1084 cit_write_reg(gspca_dev, 0x0002, 0x0112); 1084 cit_write_reg(gspca_dev, 0x0002, 0x0112);
1085 cit_write_reg(gspca_dev, 0x0000, 0x0133); 1085 cit_write_reg(gspca_dev, 0x0000, 0x0133);
@@ -1098,7 +1098,7 @@ static int cit_init_ibm_netcam_pro(struct gspca_dev *gspca_dev)
1098 cit_write_reg(gspca_dev, 0x00ff, 0x0130); 1098 cit_write_reg(gspca_dev, 0x00ff, 0x0130);
1099 cit_write_reg(gspca_dev, 0xcd41, 0x0124); 1099 cit_write_reg(gspca_dev, 0xcd41, 0x0124);
1100 cit_write_reg(gspca_dev, 0xfffa, 0x0124); 1100 cit_write_reg(gspca_dev, 0xfffa, 0x0124);
1101 cit_read_reg(gspca_dev, 0x0126); 1101 cit_read_reg(gspca_dev, 0x0126, 1);
1102 1102
1103 cit_model3_Packet1(gspca_dev, 0x0000, 0x0000); 1103 cit_model3_Packet1(gspca_dev, 0x0000, 0x0000);
1104 cit_model3_Packet1(gspca_dev, 0x0000, 0x0001); 1104 cit_model3_Packet1(gspca_dev, 0x0000, 0x0001);
@@ -1557,18 +1557,20 @@ static int cit_restart_stream(struct gspca_dev *gspca_dev)
1557 switch (sd->model) { 1557 switch (sd->model) {
1558 case CIT_MODEL0: 1558 case CIT_MODEL0:
1559 case CIT_MODEL1: 1559 case CIT_MODEL1:
1560 case CIT_MODEL3:
1561 case CIT_IBM_NETCAM_PRO:
1562 cit_write_reg(gspca_dev, 0x0001, 0x0114); 1560 cit_write_reg(gspca_dev, 0x0001, 0x0114);
1563 /* Fall through */ 1561 /* Fall through */
1564 case CIT_MODEL2: 1562 case CIT_MODEL2:
1565 case CIT_MODEL4: 1563 case CIT_MODEL4:
1566 cit_write_reg(gspca_dev, 0x00c0, 0x010c); /* Go! */ 1564 cit_write_reg(gspca_dev, 0x00c0, 0x010c); /* Go! */
1567 usb_clear_halt(gspca_dev->dev, gspca_dev->urb[0]->pipe); 1565 usb_clear_halt(gspca_dev->dev, gspca_dev->urb[0]->pipe);
1568 /* This happens repeatedly while streaming with the ibm netcam 1566 break;
1569 pro and the ibmcam driver did it for model3 after changing 1567 case CIT_MODEL3:
1570 settings, but it does not seem to have any effect. */ 1568 case CIT_IBM_NETCAM_PRO:
1571 /* cit_write_reg(gspca_dev, 0x0001, 0x0113); */ 1569 cit_write_reg(gspca_dev, 0x0001, 0x0114);
1570 cit_write_reg(gspca_dev, 0x00c0, 0x010c); /* Go! */
1571 usb_clear_halt(gspca_dev->dev, gspca_dev->urb[0]->pipe);
1572 /* Clear button events from while we were not streaming */
1573 cit_write_reg(gspca_dev, 0x0001, 0x0113);
1572 break; 1574 break;
1573 } 1575 }
1574 1576
@@ -1680,23 +1682,23 @@ static int cit_start_model1(struct gspca_dev *gspca_dev)
1680 if (clock_div < 0) 1682 if (clock_div < 0)
1681 return clock_div; 1683 return clock_div;
1682 1684
1683 cit_read_reg(gspca_dev, 0x0128); 1685 cit_read_reg(gspca_dev, 0x0128, 1);
1684 cit_read_reg(gspca_dev, 0x0100); 1686 cit_read_reg(gspca_dev, 0x0100, 0);
1685 cit_write_reg(gspca_dev, 0x01, 0x0100); /* LED On */ 1687 cit_write_reg(gspca_dev, 0x01, 0x0100); /* LED On */
1686 cit_read_reg(gspca_dev, 0x0100); 1688 cit_read_reg(gspca_dev, 0x0100, 0);
1687 cit_write_reg(gspca_dev, 0x81, 0x0100); /* LED Off */ 1689 cit_write_reg(gspca_dev, 0x81, 0x0100); /* LED Off */
1688 cit_read_reg(gspca_dev, 0x0100); 1690 cit_read_reg(gspca_dev, 0x0100, 0);
1689 cit_write_reg(gspca_dev, 0x01, 0x0100); /* LED On */ 1691 cit_write_reg(gspca_dev, 0x01, 0x0100); /* LED On */
1690 cit_write_reg(gspca_dev, 0x01, 0x0108); 1692 cit_write_reg(gspca_dev, 0x01, 0x0108);
1691 1693
1692 cit_write_reg(gspca_dev, 0x03, 0x0112); 1694 cit_write_reg(gspca_dev, 0x03, 0x0112);
1693 cit_read_reg(gspca_dev, 0x0115); 1695 cit_read_reg(gspca_dev, 0x0115, 0);
1694 cit_write_reg(gspca_dev, 0x06, 0x0115); 1696 cit_write_reg(gspca_dev, 0x06, 0x0115);
1695 cit_read_reg(gspca_dev, 0x0116); 1697 cit_read_reg(gspca_dev, 0x0116, 0);
1696 cit_write_reg(gspca_dev, 0x44, 0x0116); 1698 cit_write_reg(gspca_dev, 0x44, 0x0116);
1697 cit_read_reg(gspca_dev, 0x0116); 1699 cit_read_reg(gspca_dev, 0x0116, 0);
1698 cit_write_reg(gspca_dev, 0x40, 0x0116); 1700 cit_write_reg(gspca_dev, 0x40, 0x0116);
1699 cit_read_reg(gspca_dev, 0x0115); 1701 cit_read_reg(gspca_dev, 0x0115, 0);
1700 cit_write_reg(gspca_dev, 0x0e, 0x0115); 1702 cit_write_reg(gspca_dev, 0x0e, 0x0115);
1701 cit_write_reg(gspca_dev, 0x19, 0x012c); 1703 cit_write_reg(gspca_dev, 0x19, 0x012c);
1702 1704
@@ -1878,7 +1880,7 @@ static int cit_start_model2(struct gspca_dev *gspca_dev)
1878 int clock_div = 0; 1880 int clock_div = 0;
1879 1881
1880 cit_write_reg(gspca_dev, 0x0000, 0x0100); /* LED on */ 1882 cit_write_reg(gspca_dev, 0x0000, 0x0100); /* LED on */
1881 cit_read_reg(gspca_dev, 0x0116); 1883 cit_read_reg(gspca_dev, 0x0116, 0);
1882 cit_write_reg(gspca_dev, 0x0060, 0x0116); 1884 cit_write_reg(gspca_dev, 0x0060, 0x0116);
1883 cit_write_reg(gspca_dev, 0x0002, 0x0112); 1885 cit_write_reg(gspca_dev, 0x0002, 0x0112);
1884 cit_write_reg(gspca_dev, 0x00bc, 0x012c); 1886 cit_write_reg(gspca_dev, 0x00bc, 0x012c);
@@ -2070,10 +2072,10 @@ static int cit_start_model3(struct gspca_dev *gspca_dev)
2070 2072
2071 /* HDG not in ibmcam driver, added to see if it helps with 2073 /* HDG not in ibmcam driver, added to see if it helps with
2072 auto-detecting between model3 and ibm netcamera pro */ 2074 auto-detecting between model3 and ibm netcamera pro */
2073 cit_read_reg(gspca_dev, 0x128); 2075 cit_read_reg(gspca_dev, 0x128, 1);
2074 2076
2075 cit_write_reg(gspca_dev, 0x0000, 0x0100); 2077 cit_write_reg(gspca_dev, 0x0000, 0x0100);
2076 cit_read_reg(gspca_dev, 0x0116); 2078 cit_read_reg(gspca_dev, 0x0116, 0);
2077 cit_write_reg(gspca_dev, 0x0060, 0x0116); 2079 cit_write_reg(gspca_dev, 0x0060, 0x0116);
2078 cit_write_reg(gspca_dev, 0x0002, 0x0112); 2080 cit_write_reg(gspca_dev, 0x0002, 0x0112);
2079 cit_write_reg(gspca_dev, 0x0000, 0x0123); 2081 cit_write_reg(gspca_dev, 0x0000, 0x0123);
@@ -2083,7 +2085,7 @@ static int cit_start_model3(struct gspca_dev *gspca_dev)
2083 cit_write_reg(gspca_dev, 0x0060, 0x0116); 2085 cit_write_reg(gspca_dev, 0x0060, 0x0116);
2084 cit_write_reg(gspca_dev, 0x0002, 0x0115); 2086 cit_write_reg(gspca_dev, 0x0002, 0x0115);
2085 cit_write_reg(gspca_dev, 0x0003, 0x0115); 2087 cit_write_reg(gspca_dev, 0x0003, 0x0115);
2086 cit_read_reg(gspca_dev, 0x0115); 2088 cit_read_reg(gspca_dev, 0x0115, 0);
2087 cit_write_reg(gspca_dev, 0x000b, 0x0115); 2089 cit_write_reg(gspca_dev, 0x000b, 0x0115);
2088 2090
2089 /* TESTME HDG not in ibmcam driver, added to see if it helps with 2091 /* TESTME HDG not in ibmcam driver, added to see if it helps with
@@ -2096,7 +2098,7 @@ static int cit_start_model3(struct gspca_dev *gspca_dev)
2096 cit_write_reg(gspca_dev, 0x00ff, 0x0130); 2098 cit_write_reg(gspca_dev, 0x00ff, 0x0130);
2097 cit_write_reg(gspca_dev, 0xcd41, 0x0124); 2099 cit_write_reg(gspca_dev, 0xcd41, 0x0124);
2098 cit_write_reg(gspca_dev, 0xfffa, 0x0124); 2100 cit_write_reg(gspca_dev, 0xfffa, 0x0124);
2099 cit_read_reg(gspca_dev, 0x0126); 2101 cit_read_reg(gspca_dev, 0x0126, 1);
2100 } 2102 }
2101 2103
2102 cit_model3_Packet1(gspca_dev, 0x000a, 0x0040); 2104 cit_model3_Packet1(gspca_dev, 0x000a, 0x0040);
@@ -2293,7 +2295,7 @@ static int cit_start_model3(struct gspca_dev *gspca_dev)
2293 if (rca_input) { 2295 if (rca_input) {
2294 for (i = 0; i < ARRAY_SIZE(rca_initdata); i++) { 2296 for (i = 0; i < ARRAY_SIZE(rca_initdata); i++) {
2295 if (rca_initdata[i][0]) 2297 if (rca_initdata[i][0])
2296 cit_read_reg(gspca_dev, rca_initdata[i][2]); 2298 cit_read_reg(gspca_dev, rca_initdata[i][2], 0);
2297 else 2299 else
2298 cit_write_reg(gspca_dev, rca_initdata[i][1], 2300 cit_write_reg(gspca_dev, rca_initdata[i][1],
2299 rca_initdata[i][2]); 2301 rca_initdata[i][2]);
@@ -2712,7 +2714,7 @@ static int cit_start_ibm_netcam_pro(struct gspca_dev *gspca_dev)
2712 if (rca_input) { 2714 if (rca_input) {
2713 for (i = 0; i < ARRAY_SIZE(rca_initdata); i++) { 2715 for (i = 0; i < ARRAY_SIZE(rca_initdata); i++) {
2714 if (rca_initdata[i][0]) 2716 if (rca_initdata[i][0])
2715 cit_read_reg(gspca_dev, rca_initdata[i][2]); 2717 cit_read_reg(gspca_dev, rca_initdata[i][2], 0);
2716 else 2718 else
2717 cit_write_reg(gspca_dev, rca_initdata[i][1], 2719 cit_write_reg(gspca_dev, rca_initdata[i][1],
2718 rca_initdata[i][2]); 2720 rca_initdata[i][2]);
@@ -2769,16 +2771,55 @@ static int sd_start(struct gspca_dev *gspca_dev)
2769 return 0; 2771 return 0;
2770} 2772}
2771 2773
2774static int sd_isoc_init(struct gspca_dev *gspca_dev)
2775{
2776 struct usb_host_interface *alt;
2777 int max_packet_size;
2778
2779 switch (gspca_dev->width) {
2780 case 160:
2781 max_packet_size = 450;
2782 break;
2783 case 176:
2784 max_packet_size = 600;
2785 break;
2786 default:
2787 max_packet_size = 1022;
2788 break;
2789 }
2790
2791 /* Start isoc bandwidth "negotiation" at max isoc bandwidth */
2792 alt = &gspca_dev->dev->config->intf_cache[0]->altsetting[1];
2793 alt->endpoint[0].desc.wMaxPacketSize = cpu_to_le16(max_packet_size);
2794
2795 return 0;
2796}
2797
2772static int sd_isoc_nego(struct gspca_dev *gspca_dev) 2798static int sd_isoc_nego(struct gspca_dev *gspca_dev)
2773{ 2799{
2774 int ret, packet_size; 2800 int ret, packet_size, min_packet_size;
2775 struct usb_host_interface *alt; 2801 struct usb_host_interface *alt;
2776 2802
2803 switch (gspca_dev->width) {
2804 case 160:
2805 min_packet_size = 200;
2806 break;
2807 case 176:
2808 min_packet_size = 266;
2809 break;
2810 default:
2811 min_packet_size = 400;
2812 break;
2813 }
2814
2777 alt = &gspca_dev->dev->config->intf_cache[0]->altsetting[1]; 2815 alt = &gspca_dev->dev->config->intf_cache[0]->altsetting[1];
2778 packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize); 2816 packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize);
2779 packet_size -= 100; 2817 if (packet_size <= min_packet_size)
2780 if (packet_size < 300)
2781 return -EIO; 2818 return -EIO;
2819
2820 packet_size -= 100;
2821 if (packet_size < min_packet_size)
2822 packet_size = min_packet_size;
2782 alt->endpoint[0].desc.wMaxPacketSize = cpu_to_le16(packet_size); 2823 alt->endpoint[0].desc.wMaxPacketSize = cpu_to_le16(packet_size);
2783 2824
2784 ret = usb_set_interface(gspca_dev->dev, gspca_dev->iface, 1); 2825 ret = usb_set_interface(gspca_dev->dev, gspca_dev->iface, 1);
@@ -2796,15 +2837,12 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
2796static void sd_stop0(struct gspca_dev *gspca_dev) 2837static void sd_stop0(struct gspca_dev *gspca_dev)
2797{ 2838{
2798 struct sd *sd = (struct sd *) gspca_dev; 2839 struct sd *sd = (struct sd *) gspca_dev;
2799 struct usb_host_interface *alt;
2800 2840
2801 /* We cannot use gspca_dev->present here as that is not set when 2841 /* We cannot use gspca_dev->present here as that is not set when
2802 sd_init gets called and we get called from sd_init */ 2842 sd_init gets called and we get called from sd_init */
2803 if (!gspca_dev->dev) 2843 if (!gspca_dev->dev)
2804 return; 2844 return;
2805 2845
2806 alt = &gspca_dev->dev->config->intf_cache[0]->altsetting[1];
2807
2808 switch (sd->model) { 2846 switch (sd->model) {
2809 case CIT_MODEL0: 2847 case CIT_MODEL0:
2810 /* HDG windows does this, but it causes the cams autogain to 2848 /* HDG windows does this, but it causes the cams autogain to
@@ -2815,7 +2853,7 @@ static void sd_stop0(struct gspca_dev *gspca_dev)
2815 break; 2853 break;
2816 case CIT_MODEL1: 2854 case CIT_MODEL1:
2817 cit_send_FF_04_02(gspca_dev); 2855 cit_send_FF_04_02(gspca_dev);
2818 cit_read_reg(gspca_dev, 0x0100); 2856 cit_read_reg(gspca_dev, 0x0100, 0);
2819 cit_write_reg(gspca_dev, 0x81, 0x0100); /* LED Off */ 2857 cit_write_reg(gspca_dev, 0x81, 0x0100); /* LED Off */
2820 break; 2858 break;
2821 case CIT_MODEL2: 2859 case CIT_MODEL2:
@@ -2834,9 +2872,9 @@ static void sd_stop0(struct gspca_dev *gspca_dev)
2834 case CIT_MODEL3: 2872 case CIT_MODEL3:
2835 cit_write_reg(gspca_dev, 0x0006, 0x012c); 2873 cit_write_reg(gspca_dev, 0x0006, 0x012c);
2836 cit_model3_Packet1(gspca_dev, 0x0046, 0x0000); 2874 cit_model3_Packet1(gspca_dev, 0x0046, 0x0000);
2837 cit_read_reg(gspca_dev, 0x0116); 2875 cit_read_reg(gspca_dev, 0x0116, 0);
2838 cit_write_reg(gspca_dev, 0x0064, 0x0116); 2876 cit_write_reg(gspca_dev, 0x0064, 0x0116);
2839 cit_read_reg(gspca_dev, 0x0115); 2877 cit_read_reg(gspca_dev, 0x0115, 0);
2840 cit_write_reg(gspca_dev, 0x0003, 0x0115); 2878 cit_write_reg(gspca_dev, 0x0003, 0x0115);
2841 cit_write_reg(gspca_dev, 0x0008, 0x0123); 2879 cit_write_reg(gspca_dev, 0x0008, 0x0123);
2842 cit_write_reg(gspca_dev, 0x0000, 0x0117); 2880 cit_write_reg(gspca_dev, 0x0000, 0x0117);
@@ -2859,12 +2897,17 @@ static void sd_stop0(struct gspca_dev *gspca_dev)
2859 restarting the stream after this */ 2897 restarting the stream after this */
2860 /* cit_write_reg(gspca_dev, 0x0000, 0x0112); */ 2898 /* cit_write_reg(gspca_dev, 0x0000, 0x0112); */
2861 cit_write_reg(gspca_dev, 0x00c0, 0x0100); 2899 cit_write_reg(gspca_dev, 0x00c0, 0x0100);
2862
2863 /* Start isoc bandwidth "negotiation" at max isoc bandwith
2864 next stream start */
2865 alt->endpoint[0].desc.wMaxPacketSize = cpu_to_le16(1022);
2866 break; 2900 break;
2867 } 2901 }
2902
2903#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
2904 /* If the last button state is pressed, release it now! */
2905 if (sd->button_state) {
2906 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0);
2907 input_sync(gspca_dev->input_dev);
2908 sd->button_state = 0;
2909 }
2910#endif
2868} 2911}
2869 2912
2870static u8 *cit_find_sof(struct gspca_dev *gspca_dev, u8 *data, int len) 2913static u8 *cit_find_sof(struct gspca_dev *gspca_dev, u8 *data, int len)
@@ -3158,6 +3201,38 @@ static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val)
3158 return 0; 3201 return 0;
3159} 3202}
3160 3203
3204#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
3205static void cit_check_button(struct gspca_dev *gspca_dev)
3206{
3207 int new_button_state;
3208 struct sd *sd = (struct sd *)gspca_dev;
3209
3210 switch (sd->model) {
3211 case CIT_MODEL3:
3212 case CIT_IBM_NETCAM_PRO:
3213 break;
3214 default: /* TEST ME unknown if this works on other models too */
3215 return;
3216 }
3217
3218 /* Read the button state */
3219 cit_read_reg(gspca_dev, 0x0113, 0);
3220 new_button_state = !gspca_dev->usb_buf[0];
3221
3222 /* Tell the cam we've seen the button press, notice that this
3223 is a nop (iow the cam keeps reporting pressed) until the
3224 button is actually released. */
3225 if (new_button_state)
3226 cit_write_reg(gspca_dev, 0x01, 0x0113);
3227
3228 if (sd->button_state != new_button_state) {
3229 input_report_key(gspca_dev->input_dev, KEY_CAMERA,
3230 new_button_state);
3231 input_sync(gspca_dev->input_dev);
3232 sd->button_state = new_button_state;
3233 }
3234}
3235#endif
3161 3236
3162/* sub-driver description */ 3237/* sub-driver description */
3163static const struct sd_desc sd_desc = { 3238static const struct sd_desc sd_desc = {
@@ -3170,6 +3245,10 @@ static const struct sd_desc sd_desc = {
3170 .stopN = sd_stopN, 3245 .stopN = sd_stopN,
3171 .stop0 = sd_stop0, 3246 .stop0 = sd_stop0,
3172 .pkt_scan = sd_pkt_scan, 3247 .pkt_scan = sd_pkt_scan,
3248#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
3249 .dq_callback = cit_check_button,
3250 .other_input = 1,
3251#endif
3173}; 3252};
3174 3253
3175static const struct sd_desc sd_desc_isoc_nego = { 3254static const struct sd_desc sd_desc_isoc_nego = {
@@ -3179,10 +3258,15 @@ static const struct sd_desc sd_desc_isoc_nego = {
3179 .config = sd_config, 3258 .config = sd_config,
3180 .init = sd_init, 3259 .init = sd_init,
3181 .start = sd_start, 3260 .start = sd_start,
3261 .isoc_init = sd_isoc_init,
3182 .isoc_nego = sd_isoc_nego, 3262 .isoc_nego = sd_isoc_nego,
3183 .stopN = sd_stopN, 3263 .stopN = sd_stopN,
3184 .stop0 = sd_stop0, 3264 .stop0 = sd_stop0,
3185 .pkt_scan = sd_pkt_scan, 3265 .pkt_scan = sd_pkt_scan,
3266#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
3267 .dq_callback = cit_check_button,
3268 .other_input = 1,
3269#endif
3186}; 3270};
3187 3271
3188/* -- module initialisation -- */ 3272/* -- module initialisation -- */
diff --git a/drivers/media/video/gspca/zc3xx.c b/drivers/media/video/gspca/zc3xx.c
index c7e1970ca284..14b85d483163 100644
--- a/drivers/media/video/gspca/zc3xx.c
+++ b/drivers/media/video/gspca/zc3xx.c
@@ -35,16 +35,23 @@ static int force_sensor = -1;
35#define QUANT_VAL 1 /* quantization table */ 35#define QUANT_VAL 1 /* quantization table */
36#include "zc3xx-reg.h" 36#include "zc3xx-reg.h"
37 37
38/* controls */
39enum e_ctrl {
40 BRIGHTNESS,
41 CONTRAST,
42 GAMMA,
43 AUTOGAIN,
44 LIGHTFREQ,
45 SHARPNESS,
46 NCTRLS /* number of controls */
47};
48
38/* specific webcam descriptor */ 49/* specific webcam descriptor */
39struct sd { 50struct sd {
40 struct gspca_dev gspca_dev; /* !! must be the first item */ 51 struct gspca_dev gspca_dev; /* !! must be the first item */
41 52
42 u8 brightness; 53 struct gspca_ctrl ctrls[NCTRLS];
43 u8 contrast; 54
44 u8 gamma;
45 u8 autogain;
46 u8 lightfreq;
47 u8 sharpness;
48 u8 quality; /* image quality */ 55 u8 quality; /* image quality */
49#define QUALITY_MIN 50 56#define QUALITY_MIN 50
50#define QUALITY_MAX 80 57#define QUALITY_MAX 80
@@ -64,6 +71,7 @@ enum sensors {
64 SENSOR_ADCM2700, 71 SENSOR_ADCM2700,
65 SENSOR_CS2102, 72 SENSOR_CS2102,
66 SENSOR_CS2102K, 73 SENSOR_CS2102K,
74 SENSOR_GC0303,
67 SENSOR_GC0305, 75 SENSOR_GC0305,
68 SENSOR_HDCS2020b, 76 SENSOR_HDCS2020b,
69 SENSOR_HV7131B, 77 SENSOR_HV7131B,
@@ -79,26 +87,17 @@ enum sensors {
79 SENSOR_PB0330, 87 SENSOR_PB0330,
80 SENSOR_PO2030, 88 SENSOR_PO2030,
81 SENSOR_TAS5130C, 89 SENSOR_TAS5130C,
82 SENSOR_TAS5130C_VF0250,
83 SENSOR_MAX 90 SENSOR_MAX
84}; 91};
85 92
86/* V4L2 controls supported by the driver */ 93/* V4L2 controls supported by the driver */
87static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val); 94static void setcontrast(struct gspca_dev *gspca_dev);
88static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val); 95static void setautogain(struct gspca_dev *gspca_dev);
89static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val); 96static void setlightfreq(struct gspca_dev *gspca_dev);
90static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val); 97static void setsharpness(struct gspca_dev *gspca_dev);
91static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val); 98
92static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val); 99static const struct ctrl sd_ctrls[NCTRLS] = {
93static int sd_setgamma(struct gspca_dev *gspca_dev, __s32 val); 100[BRIGHTNESS] = {
94static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val);
95static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val);
96static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val);
97static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val);
98static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val);
99
100static const struct ctrl sd_ctrls[] = {
101 {
102 { 101 {
103 .id = V4L2_CID_BRIGHTNESS, 102 .id = V4L2_CID_BRIGHTNESS,
104 .type = V4L2_CTRL_TYPE_INTEGER, 103 .type = V4L2_CTRL_TYPE_INTEGER,
@@ -106,13 +105,11 @@ static const struct ctrl sd_ctrls[] = {
106 .minimum = 0, 105 .minimum = 0,
107 .maximum = 255, 106 .maximum = 255,
108 .step = 1, 107 .step = 1,
109#define BRIGHTNESS_DEF 128 108 .default_value = 128,
110 .default_value = BRIGHTNESS_DEF,
111 }, 109 },
112 .set = sd_setbrightness, 110 .set_control = setcontrast
113 .get = sd_getbrightness,
114 }, 111 },
115 { 112[CONTRAST] = {
116 { 113 {
117 .id = V4L2_CID_CONTRAST, 114 .id = V4L2_CID_CONTRAST,
118 .type = V4L2_CTRL_TYPE_INTEGER, 115 .type = V4L2_CTRL_TYPE_INTEGER,
@@ -120,13 +117,11 @@ static const struct ctrl sd_ctrls[] = {
120 .minimum = 0, 117 .minimum = 0,
121 .maximum = 255, 118 .maximum = 255,
122 .step = 1, 119 .step = 1,
123#define CONTRAST_DEF 128 120 .default_value = 128,
124 .default_value = CONTRAST_DEF,
125 }, 121 },
126 .set = sd_setcontrast, 122 .set_control = setcontrast
127 .get = sd_getcontrast,
128 }, 123 },
129 { 124[GAMMA] = {
130 { 125 {
131 .id = V4L2_CID_GAMMA, 126 .id = V4L2_CID_GAMMA,
132 .type = V4L2_CTRL_TYPE_INTEGER, 127 .type = V4L2_CTRL_TYPE_INTEGER,
@@ -136,10 +131,9 @@ static const struct ctrl sd_ctrls[] = {
136 .step = 1, 131 .step = 1,
137 .default_value = 4, 132 .default_value = 4,
138 }, 133 },
139 .set = sd_setgamma, 134 .set_control = setcontrast
140 .get = sd_getgamma,
141 }, 135 },
142 { 136[AUTOGAIN] = {
143 { 137 {
144 .id = V4L2_CID_AUTOGAIN, 138 .id = V4L2_CID_AUTOGAIN,
145 .type = V4L2_CTRL_TYPE_BOOLEAN, 139 .type = V4L2_CTRL_TYPE_BOOLEAN,
@@ -147,14 +141,11 @@ static const struct ctrl sd_ctrls[] = {
147 .minimum = 0, 141 .minimum = 0,
148 .maximum = 1, 142 .maximum = 1,
149 .step = 1, 143 .step = 1,
150#define AUTOGAIN_DEF 1 144 .default_value = 1,
151 .default_value = AUTOGAIN_DEF,
152 }, 145 },
153 .set = sd_setautogain, 146 .set_control = setautogain
154 .get = sd_getautogain,
155 }, 147 },
156#define LIGHTFREQ_IDX 4 148[LIGHTFREQ] = {
157 {
158 { 149 {
159 .id = V4L2_CID_POWER_LINE_FREQUENCY, 150 .id = V4L2_CID_POWER_LINE_FREQUENCY,
160 .type = V4L2_CTRL_TYPE_MENU, 151 .type = V4L2_CTRL_TYPE_MENU,
@@ -162,13 +153,11 @@ static const struct ctrl sd_ctrls[] = {
162 .minimum = 0, 153 .minimum = 0,
163 .maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */ 154 .maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */
164 .step = 1, 155 .step = 1,
165#define FREQ_DEF 0 156 .default_value = 0,
166 .default_value = FREQ_DEF,
167 }, 157 },
168 .set = sd_setfreq, 158 .set_control = setlightfreq
169 .get = sd_getfreq,
170 }, 159 },
171 { 160[SHARPNESS] = {
172 { 161 {
173 .id = V4L2_CID_SHARPNESS, 162 .id = V4L2_CID_SHARPNESS,
174 .type = V4L2_CTRL_TYPE_INTEGER, 163 .type = V4L2_CTRL_TYPE_INTEGER,
@@ -176,11 +165,9 @@ static const struct ctrl sd_ctrls[] = {
176 .minimum = 0, 165 .minimum = 0,
177 .maximum = 3, 166 .maximum = 3,
178 .step = 1, 167 .step = 1,
179#define SHARPNESS_DEF 2 168 .default_value = 2,
180 .default_value = SHARPNESS_DEF,
181 }, 169 },
182 .set = sd_setsharpness, 170 .set_control = setsharpness
183 .get = sd_getsharpness,
184 }, 171 },
185}; 172};
186 173
@@ -4499,7 +4486,7 @@ static const struct usb_action mt9v111_3_Initial[] = {
4499 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, 4486 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL},
4500 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, 4487 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING},
4501 {0xa0, 0x0a, ZC3XX_R010_CMOSSENSORSELECT}, 4488 {0xa0, 0x0a, ZC3XX_R010_CMOSSENSORSELECT},
4502 {0xa0, 0x04, ZC3XX_R002_CLOCKSELECT}, 4489 {0xa0, 0x00, ZC3XX_R002_CLOCKSELECT},
4503 {0xa0, 0x02, ZC3XX_R003_FRAMEWIDTHHIGH}, 4490 {0xa0, 0x02, ZC3XX_R003_FRAMEWIDTHHIGH},
4504 {0xa0, 0x80, ZC3XX_R004_FRAMEWIDTHLOW}, 4491 {0xa0, 0x80, ZC3XX_R004_FRAMEWIDTHLOW},
4505 {0xa0, 0x01, ZC3XX_R005_FRAMEHEIGHTHIGH}, 4492 {0xa0, 0x01, ZC3XX_R005_FRAMEHEIGHTHIGH},
@@ -5406,7 +5393,7 @@ static const struct usb_action tas5130c_NoFlikerScale[] = {
5406 {} 5393 {}
5407}; 5394};
5408 5395
5409static const struct usb_action tas5130c_vf0250_InitialScale[] = { 5396static const struct usb_action gc0303_InitialScale[] = {
5410 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, /* 00,00,01,cc, */ 5397 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, /* 00,00,01,cc, */
5411 {0xa0, 0x02, ZC3XX_R008_CLOCKSETTING}, /* 00,08,02,cc, */ 5398 {0xa0, 0x02, ZC3XX_R008_CLOCKSETTING}, /* 00,08,02,cc, */
5412 {0xa0, 0x01, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,01,cc, */ 5399 {0xa0, 0x01, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,01,cc, */
@@ -5473,7 +5460,7 @@ static const struct usb_action tas5130c_vf0250_InitialScale[] = {
5473 {} 5460 {}
5474}; 5461};
5475 5462
5476static const struct usb_action tas5130c_vf0250_Initial[] = { 5463static const struct usb_action gc0303_Initial[] = {
5477 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, /* 00,00,01,cc, */ 5464 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, /* 00,00,01,cc, */
5478 {0xa0, 0x02, ZC3XX_R008_CLOCKSETTING}, /* 00,08,02,cc, */ 5465 {0xa0, 0x02, ZC3XX_R008_CLOCKSETTING}, /* 00,08,02,cc, */
5479 {0xa0, 0x01, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,01,cc, */ 5466 {0xa0, 0x01, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,01,cc, */
@@ -5538,7 +5525,7 @@ static const struct usb_action tas5130c_vf0250_Initial[] = {
5538 {0xa0, 0x65, ZC3XX_R118_BGAIN}, /* 01,18,65,cc */ 5525 {0xa0, 0x65, ZC3XX_R118_BGAIN}, /* 01,18,65,cc */
5539 {} 5526 {}
5540}; 5527};
5541static const struct usb_action tas5130c_vf0250_50HZScale[] = { 5528static const struct usb_action gc0303_50HZScale[] = {
5542 {0xaa, 0x82, 0x0000}, /* 00,82,00,aa */ 5529 {0xaa, 0x82, 0x0000}, /* 00,82,00,aa */
5543 {0xaa, 0x83, 0x0001}, /* 00,83,01,aa */ 5530 {0xaa, 0x83, 0x0001}, /* 00,83,01,aa */
5544 {0xaa, 0x84, 0x00aa}, /* 00,84,aa,aa */ 5531 {0xaa, 0x84, 0x00aa}, /* 00,84,aa,aa */
@@ -5562,7 +5549,7 @@ static const struct usb_action tas5130c_vf0250_50HZScale[] = {
5562 {} 5549 {}
5563}; 5550};
5564 5551
5565static const struct usb_action tas5130c_vf0250_50HZ[] = { 5552static const struct usb_action gc0303_50HZ[] = {
5566 {0xaa, 0x82, 0x0000}, /* 00,82,00,aa */ 5553 {0xaa, 0x82, 0x0000}, /* 00,82,00,aa */
5567 {0xaa, 0x83, 0x0003}, /* 00,83,03,aa */ 5554 {0xaa, 0x83, 0x0003}, /* 00,83,03,aa */
5568 {0xaa, 0x84, 0x0054}, /* 00,84,54,aa */ 5555 {0xaa, 0x84, 0x0054}, /* 00,84,54,aa */
@@ -5586,7 +5573,7 @@ static const struct usb_action tas5130c_vf0250_50HZ[] = {
5586 {} 5573 {}
5587}; 5574};
5588 5575
5589static const struct usb_action tas5130c_vf0250_60HZScale[] = { 5576static const struct usb_action gc0303_60HZScale[] = {
5590 {0xaa, 0x82, 0x0000}, /* 00,82,00,aa */ 5577 {0xaa, 0x82, 0x0000}, /* 00,82,00,aa */
5591 {0xaa, 0x83, 0x0001}, /* 00,83,01,aa */ 5578 {0xaa, 0x83, 0x0001}, /* 00,83,01,aa */
5592 {0xaa, 0x84, 0x0062}, /* 00,84,62,aa */ 5579 {0xaa, 0x84, 0x0062}, /* 00,84,62,aa */
@@ -5610,7 +5597,7 @@ static const struct usb_action tas5130c_vf0250_60HZScale[] = {
5610 {} 5597 {}
5611}; 5598};
5612 5599
5613static const struct usb_action tas5130c_vf0250_60HZ[] = { 5600static const struct usb_action gc0303_60HZ[] = {
5614 {0xaa, 0x82, 0x0000}, /* 00,82,00,aa */ 5601 {0xaa, 0x82, 0x0000}, /* 00,82,00,aa */
5615 {0xaa, 0x83, 0x0002}, /* 00,83,02,aa */ 5602 {0xaa, 0x83, 0x0002}, /* 00,83,02,aa */
5616 {0xaa, 0x84, 0x00c4}, /* 00,84,c4,aa */ 5603 {0xaa, 0x84, 0x00c4}, /* 00,84,c4,aa */
@@ -5634,7 +5621,7 @@ static const struct usb_action tas5130c_vf0250_60HZ[] = {
5634 {} 5621 {}
5635}; 5622};
5636 5623
5637static const struct usb_action tas5130c_vf0250_NoFlikerScale[] = { 5624static const struct usb_action gc0303_NoFlikerScale[] = {
5638 {0xa0, 0x0c, ZC3XX_R100_OPERATIONMODE}, /* 01,00,0c,cc, */ 5625 {0xa0, 0x0c, ZC3XX_R100_OPERATIONMODE}, /* 01,00,0c,cc, */
5639 {0xaa, 0x82, 0x0000}, /* 00,82,00,aa */ 5626 {0xaa, 0x82, 0x0000}, /* 00,82,00,aa */
5640 {0xaa, 0x83, 0x0000}, /* 00,83,00,aa */ 5627 {0xaa, 0x83, 0x0000}, /* 00,83,00,aa */
@@ -5656,7 +5643,7 @@ static const struct usb_action tas5130c_vf0250_NoFlikerScale[] = {
5656 {} 5643 {}
5657}; 5644};
5658 5645
5659static const struct usb_action tas5130c_vf0250_NoFliker[] = { 5646static const struct usb_action gc0303_NoFliker[] = {
5660 {0xa0, 0x0c, ZC3XX_R100_OPERATIONMODE}, /* 01,00,0c,cc, */ 5647 {0xa0, 0x0c, ZC3XX_R100_OPERATIONMODE}, /* 01,00,0c,cc, */
5661 {0xaa, 0x82, 0x0000}, /* 00,82,00,aa */ 5648 {0xaa, 0x82, 0x0000}, /* 00,82,00,aa */
5662 {0xaa, 0x83, 0x0000}, /* 00,83,00,aa */ 5649 {0xaa, 0x83, 0x0000}, /* 00,83,00,aa */
@@ -5833,12 +5820,13 @@ static void setmatrix(struct gspca_dev *gspca_dev)
5833 {0x60, 0xf0, 0xf0, 0xf0, 0x60, 0xf0, 0xf0, 0xf0, 0x60}; 5820 {0x60, 0xf0, 0xf0, 0xf0, 0x60, 0xf0, 0xf0, 0xf0, 0x60};
5834 static const u8 tas5130c_matrix[9] = 5821 static const u8 tas5130c_matrix[9] =
5835 {0x68, 0xec, 0xec, 0xec, 0x68, 0xec, 0xec, 0xec, 0x68}; 5822 {0x68, 0xec, 0xec, 0xec, 0x68, 0xec, 0xec, 0xec, 0x68};
5836 static const u8 vf0250_matrix[9] = 5823 static const u8 gc0303_matrix[9] =
5837 {0x7b, 0xea, 0xea, 0xea, 0x7b, 0xea, 0xea, 0xea, 0x7b}; 5824 {0x7b, 0xea, 0xea, 0xea, 0x7b, 0xea, 0xea, 0xea, 0x7b};
5838 static const u8 *matrix_tb[SENSOR_MAX] = { 5825 static const u8 *matrix_tb[SENSOR_MAX] = {
5839 [SENSOR_ADCM2700] = adcm2700_matrix, 5826 [SENSOR_ADCM2700] = adcm2700_matrix,
5840 [SENSOR_CS2102] = ov7620_matrix, 5827 [SENSOR_CS2102] = ov7620_matrix,
5841 [SENSOR_CS2102K] = NULL, 5828 [SENSOR_CS2102K] = NULL,
5829 [SENSOR_GC0303] = gc0303_matrix,
5842 [SENSOR_GC0305] = gc0305_matrix, 5830 [SENSOR_GC0305] = gc0305_matrix,
5843 [SENSOR_HDCS2020b] = NULL, 5831 [SENSOR_HDCS2020b] = NULL,
5844 [SENSOR_HV7131B] = NULL, 5832 [SENSOR_HV7131B] = NULL,
@@ -5854,7 +5842,6 @@ static void setmatrix(struct gspca_dev *gspca_dev)
5854 [SENSOR_PB0330] = gc0305_matrix, 5842 [SENSOR_PB0330] = gc0305_matrix,
5855 [SENSOR_PO2030] = po2030_matrix, 5843 [SENSOR_PO2030] = po2030_matrix,
5856 [SENSOR_TAS5130C] = tas5130c_matrix, 5844 [SENSOR_TAS5130C] = tas5130c_matrix,
5857 [SENSOR_TAS5130C_VF0250] = vf0250_matrix,
5858 }; 5845 };
5859 5846
5860 matrix = matrix_tb[sd->sensor]; 5847 matrix = matrix_tb[sd->sensor];
@@ -5875,7 +5862,7 @@ static void setsharpness(struct gspca_dev *gspca_dev)
5875 {0x10, 0x1e} 5862 {0x10, 0x1e}
5876 }; 5863 };
5877 5864
5878 sharpness = sd->sharpness; 5865 sharpness = sd->ctrls[SHARPNESS].val;
5879 reg_w(gspca_dev, sharpness_tb[sharpness][0], 0x01c6); 5866 reg_w(gspca_dev, sharpness_tb[sharpness][0], 0x01c6);
5880 reg_r(gspca_dev, 0x01c8); 5867 reg_r(gspca_dev, 0x01c8);
5881 reg_r(gspca_dev, 0x01c9); 5868 reg_r(gspca_dev, 0x01c9);
@@ -5910,10 +5897,10 @@ static void setcontrast(struct gspca_dev *gspca_dev)
5910 0xe0, 0xeb, 0xf4, 0xff, 0xff, 0xff, 0xff, 0xff}, 5897 0xe0, 0xeb, 0xf4, 0xff, 0xff, 0xff, 0xff, 0xff},
5911 }; 5898 };
5912 5899
5913 Tgamma = gamma_tb[sd->gamma - 1]; 5900 Tgamma = gamma_tb[sd->ctrls[GAMMA].val - 1];
5914 5901
5915 contrast = ((int) sd->contrast - 128); /* -128 / 127 */ 5902 contrast = ((int) sd->ctrls[CONTRAST].val - 128); /* -128 / 127 */
5916 brightness = ((int) sd->brightness - 128); /* -128 / 92 */ 5903 brightness = ((int) sd->ctrls[BRIGHTNESS].val - 128); /* -128 / 92 */
5917 adj = 0; 5904 adj = 0;
5918 gp1 = gp2 = 0; 5905 gp1 = gp2 = 0;
5919 for (i = 0; i < 16; i++) { 5906 for (i = 0; i < 16; i++) {
@@ -5994,6 +5981,10 @@ static void setlightfreq(struct gspca_dev *gspca_dev)
5994 {cs2102_NoFliker, cs2102_NoFlikerScale, 5981 {cs2102_NoFliker, cs2102_NoFlikerScale,
5995 NULL, NULL, /* currently disabled */ 5982 NULL, NULL, /* currently disabled */
5996 NULL, NULL}, 5983 NULL, NULL},
5984 [SENSOR_GC0303] =
5985 {gc0303_NoFliker, gc0303_NoFlikerScale,
5986 gc0303_50HZ, gc0303_50HZScale,
5987 gc0303_60HZ, gc0303_60HZScale},
5997 [SENSOR_GC0305] = 5988 [SENSOR_GC0305] =
5998 {gc0305_NoFliker, gc0305_NoFliker, 5989 {gc0305_NoFliker, gc0305_NoFliker,
5999 gc0305_50HZ, gc0305_50HZ, 5990 gc0305_50HZ, gc0305_50HZ,
@@ -6054,14 +6045,10 @@ static void setlightfreq(struct gspca_dev *gspca_dev)
6054 {tas5130c_NoFliker, tas5130c_NoFlikerScale, 6045 {tas5130c_NoFliker, tas5130c_NoFlikerScale,
6055 tas5130c_50HZ, tas5130c_50HZScale, 6046 tas5130c_50HZ, tas5130c_50HZScale,
6056 tas5130c_60HZ, tas5130c_60HZScale}, 6047 tas5130c_60HZ, tas5130c_60HZScale},
6057 [SENSOR_TAS5130C_VF0250] =
6058 {tas5130c_vf0250_NoFliker, tas5130c_vf0250_NoFlikerScale,
6059 tas5130c_vf0250_50HZ, tas5130c_vf0250_50HZScale,
6060 tas5130c_vf0250_60HZ, tas5130c_vf0250_60HZScale},
6061 }; 6048 };
6062 6049
6063 i = sd->lightfreq * 2; 6050 i = sd->ctrls[LIGHTFREQ].val * 2;
6064 mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv; 6051 mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
6065 if (mode) 6052 if (mode)
6066 i++; /* 320x240 */ 6053 i++; /* 320x240 */
6067 zc3_freq = freq_tb[sd->sensor][i]; 6054 zc3_freq = freq_tb[sd->sensor][i];
@@ -6070,14 +6057,14 @@ static void setlightfreq(struct gspca_dev *gspca_dev)
6070 usb_exchange(gspca_dev, zc3_freq); 6057 usb_exchange(gspca_dev, zc3_freq);
6071 switch (sd->sensor) { 6058 switch (sd->sensor) {
6072 case SENSOR_GC0305: 6059 case SENSOR_GC0305:
6073 if (mode /* if 320x240 */ 6060 if (mode /* if 320x240 */
6074 && sd->lightfreq == 1) /* and 50Hz */ 6061 && sd->ctrls[LIGHTFREQ].val == 1) /* and 50Hz */
6075 reg_w(gspca_dev, 0x85, 0x018d); 6062 reg_w(gspca_dev, 0x85, 0x018d);
6076 /* win: 0x80, 0x018d */ 6063 /* win: 0x80, 0x018d */
6077 break; 6064 break;
6078 case SENSOR_OV7620: 6065 case SENSOR_OV7620:
6079 if (!mode) { /* if 640x480 */ 6066 if (!mode) { /* if 640x480 */
6080 if (sd->lightfreq != 0) /* and 50 or 60 Hz */ 6067 if (sd->ctrls[LIGHTFREQ].val != 0) /* and filter */
6081 reg_w(gspca_dev, 0x40, 0x0002); 6068 reg_w(gspca_dev, 0x40, 0x0002);
6082 else 6069 else
6083 reg_w(gspca_dev, 0x44, 0x0002); 6070 reg_w(gspca_dev, 0x44, 0x0002);
@@ -6094,7 +6081,7 @@ static void setautogain(struct gspca_dev *gspca_dev)
6094 struct sd *sd = (struct sd *) gspca_dev; 6081 struct sd *sd = (struct sd *) gspca_dev;
6095 u8 autoval; 6082 u8 autoval;
6096 6083
6097 if (sd->autogain) 6084 if (sd->ctrls[AUTOGAIN].val)
6098 autoval = 0x42; 6085 autoval = 0x42;
6099 else 6086 else
6100 autoval = 0x02; 6087 autoval = 0x02;
@@ -6330,8 +6317,8 @@ static int vga_3wr_probe(struct gspca_dev *gspca_dev)
6330 retword = i2c_read(gspca_dev, 0x00); 6317 retword = i2c_read(gspca_dev, 0x00);
6331 if (retword != 0) { 6318 if (retword != 0) {
6332 PDEBUG(D_PROBE, "probe 3wr vga type %02x", retword); 6319 PDEBUG(D_PROBE, "probe 3wr vga type %02x", retword);
6333 if (retword == 0x0011) /* VF0250 */ 6320 if (retword == 0x0011) /* gc0303 */
6334 return 0x0250; 6321 return 0x0303;
6335 if (retword == 0x0029) /* gc0305 */ 6322 if (retword == 0x0029) /* gc0305 */
6336 send_unknown(gspca_dev, SENSOR_GC0305); 6323 send_unknown(gspca_dev, SENSOR_GC0305);
6337 return retword; 6324 return retword;
@@ -6392,7 +6379,7 @@ static int zcxx_probeSensor(struct gspca_dev *gspca_dev)
6392 switch (sd->sensor) { 6379 switch (sd->sensor) {
6393 case SENSOR_MC501CB: 6380 case SENSOR_MC501CB:
6394 return -1; /* don't probe */ 6381 return -1; /* don't probe */
6395 case SENSOR_TAS5130C_VF0250: 6382 case SENSOR_GC0303:
6396 /* may probe but with no write in reg 0x0010 */ 6383 /* may probe but with no write in reg 0x0010 */
6397 return -1; /* don't probe */ 6384 return -1; /* don't probe */
6398 case SENSOR_PAS106: 6385 case SENSOR_PAS106:
@@ -6421,11 +6408,7 @@ static int sd_config(struct gspca_dev *gspca_dev,
6421 /* define some sensors from the vendor/product */ 6408 /* define some sensors from the vendor/product */
6422 sd->sensor = id->driver_info; 6409 sd->sensor = id->driver_info;
6423 6410
6424 sd->sharpness = SHARPNESS_DEF; 6411 gspca_dev->cam.ctrls = sd->ctrls;
6425 sd->brightness = BRIGHTNESS_DEF;
6426 sd->contrast = CONTRAST_DEF;
6427 sd->autogain = AUTOGAIN_DEF;
6428 sd->lightfreq = FREQ_DEF;
6429 sd->quality = QUALITY_DEF; 6412 sd->quality = QUALITY_DEF;
6430 6413
6431 return 0; 6414 return 0;
@@ -6441,6 +6424,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
6441 [SENSOR_ADCM2700] = 4, 6424 [SENSOR_ADCM2700] = 4,
6442 [SENSOR_CS2102] = 4, 6425 [SENSOR_CS2102] = 4,
6443 [SENSOR_CS2102K] = 5, 6426 [SENSOR_CS2102K] = 5,
6427 [SENSOR_GC0303] = 3,
6444 [SENSOR_GC0305] = 4, 6428 [SENSOR_GC0305] = 4,
6445 [SENSOR_HDCS2020b] = 4, 6429 [SENSOR_HDCS2020b] = 4,
6446 [SENSOR_HV7131B] = 4, 6430 [SENSOR_HV7131B] = 4,
@@ -6456,12 +6440,12 @@ static int sd_init(struct gspca_dev *gspca_dev)
6456 [SENSOR_PB0330] = 4, 6440 [SENSOR_PB0330] = 4,
6457 [SENSOR_PO2030] = 4, 6441 [SENSOR_PO2030] = 4,
6458 [SENSOR_TAS5130C] = 3, 6442 [SENSOR_TAS5130C] = 3,
6459 [SENSOR_TAS5130C_VF0250] = 3,
6460 }; 6443 };
6461 static const u8 mode_tb[SENSOR_MAX] = { 6444 static const u8 mode_tb[SENSOR_MAX] = {
6462 [SENSOR_ADCM2700] = 2, 6445 [SENSOR_ADCM2700] = 2,
6463 [SENSOR_CS2102] = 1, 6446 [SENSOR_CS2102] = 1,
6464 [SENSOR_CS2102K] = 1, 6447 [SENSOR_CS2102K] = 1,
6448 [SENSOR_GC0303] = 1,
6465 [SENSOR_GC0305] = 1, 6449 [SENSOR_GC0305] = 1,
6466 [SENSOR_HDCS2020b] = 1, 6450 [SENSOR_HDCS2020b] = 1,
6467 [SENSOR_HV7131B] = 1, 6451 [SENSOR_HV7131B] = 1,
@@ -6477,7 +6461,6 @@ static int sd_init(struct gspca_dev *gspca_dev)
6477 [SENSOR_PB0330] = 1, 6461 [SENSOR_PB0330] = 1,
6478 [SENSOR_PO2030] = 1, 6462 [SENSOR_PO2030] = 1,
6479 [SENSOR_TAS5130C] = 1, 6463 [SENSOR_TAS5130C] = 1,
6480 [SENSOR_TAS5130C_VF0250] = 1,
6481 }; 6464 };
6482 6465
6483 sensor = zcxx_probeSensor(gspca_dev); 6466 sensor = zcxx_probeSensor(gspca_dev);
@@ -6493,8 +6476,8 @@ static int sd_init(struct gspca_dev *gspca_dev)
6493 case SENSOR_MC501CB: 6476 case SENSOR_MC501CB:
6494 PDEBUG(D_PROBE, "Sensor MC501CB"); 6477 PDEBUG(D_PROBE, "Sensor MC501CB");
6495 break; 6478 break;
6496 case SENSOR_TAS5130C_VF0250: 6479 case SENSOR_GC0303:
6497 PDEBUG(D_PROBE, "Sensor Tas5130 (VF0250)"); 6480 PDEBUG(D_PROBE, "Sensor GC0303");
6498 break; 6481 break;
6499 default: 6482 default:
6500 warn("Unknown sensor - set to TAS5130C"); 6483 warn("Unknown sensor - set to TAS5130C");
@@ -6581,14 +6564,14 @@ static int sd_init(struct gspca_dev *gspca_dev)
6581 PDEBUG(D_PROBE, "Find Sensor GC0305"); 6564 PDEBUG(D_PROBE, "Find Sensor GC0305");
6582 sd->sensor = SENSOR_GC0305; 6565 sd->sensor = SENSOR_GC0305;
6583 break; 6566 break;
6584 case 0x0250: 6567 case 0x0303:
6585 PDEBUG(D_PROBE, "Sensor Tas5130 (VF0250)"); 6568 PDEBUG(D_PROBE, "Sensor GC0303");
6586 sd->sensor = SENSOR_TAS5130C_VF0250; 6569 sd->sensor = SENSOR_GC0303;
6587 break; 6570 break;
6588 case 0x2030: 6571 case 0x2030:
6589 PDEBUG(D_PROBE, "Find Sensor PO2030"); 6572 PDEBUG(D_PROBE, "Find Sensor PO2030");
6590 sd->sensor = SENSOR_PO2030; 6573 sd->sensor = SENSOR_PO2030;
6591 sd->sharpness = 0; /* from win traces */ 6574 sd->ctrls[SHARPNESS].def = 0; /* from win traces */
6592 break; 6575 break;
6593 case 0x7620: 6576 case 0x7620:
6594 PDEBUG(D_PROBE, "Find Sensor OV7620"); 6577 PDEBUG(D_PROBE, "Find Sensor OV7620");
@@ -6629,11 +6612,12 @@ static int sd_init(struct gspca_dev *gspca_dev)
6629 cam->nmodes = ARRAY_SIZE(broken_vga_mode); 6612 cam->nmodes = ARRAY_SIZE(broken_vga_mode);
6630 break; 6613 break;
6631 } 6614 }
6632 sd->gamma = gamma[sd->sensor]; 6615
6616 sd->ctrls[GAMMA].def = gamma[sd->sensor];
6633 6617
6634 switch (sd->sensor) { 6618 switch (sd->sensor) {
6635 case SENSOR_OV7630C: 6619 case SENSOR_OV7630C:
6636 gspca_dev->ctrl_dis = (1 << LIGHTFREQ_IDX); 6620 gspca_dev->ctrl_dis = (1 << LIGHTFREQ);
6637 break; 6621 break;
6638 } 6622 }
6639 6623
@@ -6653,6 +6637,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
6653 {cs2102_Initial, cs2102_InitialScale}, 6637 {cs2102_Initial, cs2102_InitialScale},
6654 [SENSOR_CS2102K] = 6638 [SENSOR_CS2102K] =
6655 {cs2102K_Initial, cs2102K_InitialScale}, 6639 {cs2102K_Initial, cs2102K_InitialScale},
6640 [SENSOR_GC0303] =
6641 {gc0303_Initial, gc0303_InitialScale},
6656 [SENSOR_GC0305] = 6642 [SENSOR_GC0305] =
6657 {gc0305_Initial, gc0305_InitialScale}, 6643 {gc0305_Initial, gc0305_InitialScale},
6658 [SENSOR_HDCS2020b] = 6644 [SENSOR_HDCS2020b] =
@@ -6683,8 +6669,6 @@ static int sd_start(struct gspca_dev *gspca_dev)
6683 {po2030_Initial, po2030_InitialScale}, 6669 {po2030_Initial, po2030_InitialScale},
6684 [SENSOR_TAS5130C] = 6670 [SENSOR_TAS5130C] =
6685 {tas5130c_Initial, tas5130c_InitialScale}, 6671 {tas5130c_Initial, tas5130c_InitialScale},
6686 [SENSOR_TAS5130C_VF0250] =
6687 {tas5130c_vf0250_Initial, tas5130c_vf0250_InitialScale},
6688 }; 6672 };
6689 6673
6690 /* create the JPEG header */ 6674 /* create the JPEG header */
@@ -6709,7 +6693,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
6709 case SENSOR_OV7620: 6693 case SENSOR_OV7620:
6710 case SENSOR_PO2030: 6694 case SENSOR_PO2030:
6711 case SENSOR_TAS5130C: 6695 case SENSOR_TAS5130C:
6712 case SENSOR_TAS5130C_VF0250: 6696 case SENSOR_GC0303:
6713/* msleep(100); * ?? */ 6697/* msleep(100); * ?? */
6714 reg_r(gspca_dev, 0x0002); /* --> 0x40 */ 6698 reg_r(gspca_dev, 0x0002); /* --> 0x40 */
6715 reg_w(gspca_dev, 0x09, 0x01ad); /* (from win traces) */ 6699 reg_w(gspca_dev, 0x09, 0x01ad); /* (from win traces) */
@@ -6843,114 +6827,6 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
6843 gspca_frame_add(gspca_dev, INTER_PACKET, data, len); 6827 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
6844} 6828}
6845 6829
6846static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
6847{
6848 struct sd *sd = (struct sd *) gspca_dev;
6849
6850 sd->brightness = val;
6851 if (gspca_dev->streaming)
6852 setcontrast(gspca_dev);
6853 return gspca_dev->usb_err;
6854}
6855
6856static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
6857{
6858 struct sd *sd = (struct sd *) gspca_dev;
6859
6860 *val = sd->brightness;
6861 return 0;
6862}
6863
6864static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
6865{
6866 struct sd *sd = (struct sd *) gspca_dev;
6867
6868 sd->contrast = val;
6869 if (gspca_dev->streaming)
6870 setcontrast(gspca_dev);
6871 return gspca_dev->usb_err;
6872}
6873
6874static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
6875{
6876 struct sd *sd = (struct sd *) gspca_dev;
6877
6878 *val = sd->contrast;
6879 return 0;
6880}
6881
6882static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
6883{
6884 struct sd *sd = (struct sd *) gspca_dev;
6885
6886 sd->autogain = val;
6887 if (gspca_dev->streaming)
6888 setautogain(gspca_dev);
6889 return gspca_dev->usb_err;
6890}
6891
6892static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
6893{
6894 struct sd *sd = (struct sd *) gspca_dev;
6895
6896 *val = sd->autogain;
6897 return 0;
6898}
6899
6900static int sd_setgamma(struct gspca_dev *gspca_dev, __s32 val)
6901{
6902 struct sd *sd = (struct sd *) gspca_dev;
6903
6904 sd->gamma = val;
6905 if (gspca_dev->streaming)
6906 setcontrast(gspca_dev);
6907 return gspca_dev->usb_err;
6908}
6909
6910static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val)
6911{
6912 struct sd *sd = (struct sd *) gspca_dev;
6913
6914 *val = sd->gamma;
6915 return 0;
6916}
6917
6918static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val)
6919{
6920 struct sd *sd = (struct sd *) gspca_dev;
6921
6922 sd->lightfreq = val;
6923 if (gspca_dev->streaming)
6924 setlightfreq(gspca_dev);
6925 return gspca_dev->usb_err;
6926}
6927
6928static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val)
6929{
6930 struct sd *sd = (struct sd *) gspca_dev;
6931
6932 *val = sd->lightfreq;
6933 return 0;
6934}
6935
6936static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val)
6937{
6938 struct sd *sd = (struct sd *) gspca_dev;
6939
6940 sd->sharpness = val;
6941 if (gspca_dev->streaming)
6942 setsharpness(gspca_dev);
6943 return gspca_dev->usb_err;
6944}
6945
6946static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val)
6947{
6948 struct sd *sd = (struct sd *) gspca_dev;
6949
6950 *val = sd->sharpness;
6951 return 0;
6952}
6953
6954static int sd_querymenu(struct gspca_dev *gspca_dev, 6830static int sd_querymenu(struct gspca_dev *gspca_dev,
6955 struct v4l2_querymenu *menu) 6831 struct v4l2_querymenu *menu)
6956{ 6832{
@@ -7045,8 +6921,8 @@ static const __devinitdata struct usb_device_id device_table[] = {
7045 {USB_DEVICE(0x041e, 0x4035), .driver_info = SENSOR_PAS106}, 6921 {USB_DEVICE(0x041e, 0x4035), .driver_info = SENSOR_PAS106},
7046 {USB_DEVICE(0x041e, 0x4036)}, 6922 {USB_DEVICE(0x041e, 0x4036)},
7047 {USB_DEVICE(0x041e, 0x403a)}, 6923 {USB_DEVICE(0x041e, 0x403a)},
7048 {USB_DEVICE(0x041e, 0x4051), .driver_info = SENSOR_TAS5130C_VF0250}, 6924 {USB_DEVICE(0x041e, 0x4051), .driver_info = SENSOR_GC0303},
7049 {USB_DEVICE(0x041e, 0x4053), .driver_info = SENSOR_TAS5130C_VF0250}, 6925 {USB_DEVICE(0x041e, 0x4053), .driver_info = SENSOR_GC0303},
7050 {USB_DEVICE(0x0458, 0x7007)}, 6926 {USB_DEVICE(0x0458, 0x7007)},
7051 {USB_DEVICE(0x0458, 0x700c)}, 6927 {USB_DEVICE(0x0458, 0x700c)},
7052 {USB_DEVICE(0x0458, 0x700f)}, 6928 {USB_DEVICE(0x0458, 0x700f)},
@@ -7066,8 +6942,8 @@ static const __devinitdata struct usb_device_id device_table[] = {
7066 {USB_DEVICE(0x046d, 0x08af)}, 6942 {USB_DEVICE(0x046d, 0x08af)},
7067 {USB_DEVICE(0x046d, 0x08b9)}, 6943 {USB_DEVICE(0x046d, 0x08b9)},
7068 {USB_DEVICE(0x046d, 0x08d7)}, 6944 {USB_DEVICE(0x046d, 0x08d7)},
7069 {USB_DEVICE(0x046d, 0x08d9)},
7070 {USB_DEVICE(0x046d, 0x08d8)}, 6945 {USB_DEVICE(0x046d, 0x08d8)},
6946 {USB_DEVICE(0x046d, 0x08d9)},
7071 {USB_DEVICE(0x046d, 0x08da)}, 6947 {USB_DEVICE(0x046d, 0x08da)},
7072 {USB_DEVICE(0x046d, 0x08dd), .driver_info = SENSOR_MC501CB}, 6948 {USB_DEVICE(0x046d, 0x08dd), .driver_info = SENSOR_MC501CB},
7073 {USB_DEVICE(0x0471, 0x0325), .driver_info = SENSOR_PAS106}, 6949 {USB_DEVICE(0x0471, 0x0325), .driver_info = SENSOR_PAS106},
diff --git a/drivers/media/video/hdpvr/hdpvr-core.c b/drivers/media/video/hdpvr/hdpvr-core.c
index b70d6afc9fec..f7d1ee55185a 100644
--- a/drivers/media/video/hdpvr/hdpvr-core.c
+++ b/drivers/media/video/hdpvr/hdpvr-core.c
@@ -385,6 +385,11 @@ static int hdpvr_probe(struct usb_interface *interface,
385 v4l2_err(&dev->v4l2_dev, "registering i2c adapter failed\n"); 385 v4l2_err(&dev->v4l2_dev, "registering i2c adapter failed\n");
386 goto error; 386 goto error;
387 } 387 }
388
389 /* until i2c is working properly */
390 retval = 0; /* hdpvr_register_i2c_ir(dev); */
391 if (retval < 0)
392 v4l2_err(&dev->v4l2_dev, "registering i2c IR devices failed\n");
388#endif /* CONFIG_I2C */ 393#endif /* CONFIG_I2C */
389 394
390 /* let the user know what node this device is now attached to */ 395 /* let the user know what node this device is now attached to */
diff --git a/drivers/media/video/hdpvr/hdpvr-i2c.c b/drivers/media/video/hdpvr/hdpvr-i2c.c
index 409de11096d4..24966aa02a70 100644
--- a/drivers/media/video/hdpvr/hdpvr-i2c.c
+++ b/drivers/media/video/hdpvr/hdpvr-i2c.c
@@ -4,6 +4,9 @@
4 * 4 *
5 * Copyright (C) 2008 Janne Grunau (j@jannau.net) 5 * Copyright (C) 2008 Janne Grunau (j@jannau.net)
6 * 6 *
7 * IR device registration code is
8 * Copyright (C) 2010 Andy Walls <awalls@md.metrocast.net>
9 *
7 * This program is free software; you can redistribute it and/or 10 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as 11 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation, version 2. 12 * published by the Free Software Foundation, version 2.
@@ -22,6 +25,56 @@
22#define REQTYPE_I2C_WRITE 0xb0 25#define REQTYPE_I2C_WRITE 0xb0
23#define REQTYPE_I2C_WRITE_STATT 0xd0 26#define REQTYPE_I2C_WRITE_STATT 0xd0
24 27
28#define Z8F0811_IR_TX_I2C_ADDR 0x70
29#define Z8F0811_IR_RX_I2C_ADDR 0x71
30
31static const u8 ir_i2c_addrs[] = {
32 Z8F0811_IR_TX_I2C_ADDR,
33 Z8F0811_IR_RX_I2C_ADDR,
34};
35
36static const char * const ir_devicenames[] = {
37 "ir_tx_z8f0811_hdpvr",
38 "ir_rx_z8f0811_hdpvr",
39};
40
41static int hdpvr_new_i2c_ir(struct hdpvr_device *dev, struct i2c_adapter *adap,
42 const char *type, u8 addr)
43{
44 struct i2c_board_info info;
45 struct IR_i2c_init_data *init_data = &dev->ir_i2c_init_data;
46 unsigned short addr_list[2] = { addr, I2C_CLIENT_END };
47
48 memset(&info, 0, sizeof(struct i2c_board_info));
49 strlcpy(info.type, type, I2C_NAME_SIZE);
50
51 /* Our default information for ir-kbd-i2c.c to use */
52 switch (addr) {
53 case Z8F0811_IR_RX_I2C_ADDR:
54 init_data->ir_codes = RC_MAP_HAUPPAUGE_NEW;
55 init_data->internal_get_key_func = IR_KBD_GET_KEY_HAUP_XVR;
56 init_data->type = RC_TYPE_RC5;
57 init_data->name = "HD PVR";
58 info.platform_data = init_data;
59 break;
60 }
61
62 return i2c_new_probed_device(adap, &info, addr_list, NULL) == NULL ?
63 -1 : 0;
64}
65
66int hdpvr_register_i2c_ir(struct hdpvr_device *dev)
67{
68 int i;
69 int ret = 0;
70
71 for (i = 0; i < ARRAY_SIZE(ir_i2c_addrs); i++)
72 ret += hdpvr_new_i2c_ir(dev, dev->i2c_adapter,
73 ir_devicenames[i], ir_i2c_addrs[i]);
74
75 return ret;
76}
77
25static int hdpvr_i2c_read(struct hdpvr_device *dev, unsigned char addr, 78static int hdpvr_i2c_read(struct hdpvr_device *dev, unsigned char addr,
26 char *data, int len) 79 char *data, int len)
27{ 80{
diff --git a/drivers/media/video/hdpvr/hdpvr.h b/drivers/media/video/hdpvr/hdpvr.h
index 5efc963f9164..37f1e4c7675d 100644
--- a/drivers/media/video/hdpvr/hdpvr.h
+++ b/drivers/media/video/hdpvr/hdpvr.h
@@ -16,6 +16,7 @@
16#include <linux/videodev2.h> 16#include <linux/videodev2.h>
17 17
18#include <media/v4l2-device.h> 18#include <media/v4l2-device.h>
19#include <media/ir-kbd-i2c.h>
19 20
20#define HDPVR_MAJOR_VERSION 0 21#define HDPVR_MAJOR_VERSION 0
21#define HDPVR_MINOR_VERSION 2 22#define HDPVR_MINOR_VERSION 2
@@ -109,6 +110,9 @@ struct hdpvr_device {
109 /* I2C lock */ 110 /* I2C lock */
110 struct mutex i2c_mutex; 111 struct mutex i2c_mutex;
111 112
113 /* For passing data to ir-kbd-i2c */
114 struct IR_i2c_init_data ir_i2c_init_data;
115
112 /* usb control transfer buffer and lock */ 116 /* usb control transfer buffer and lock */
113 struct mutex usbc_mutex; 117 struct mutex usbc_mutex;
114 u8 *usbc_buf; 118 u8 *usbc_buf;
@@ -306,6 +310,8 @@ int hdpvr_cancel_queue(struct hdpvr_device *dev);
306/* i2c adapter registration */ 310/* i2c adapter registration */
307int hdpvr_register_i2c_adapter(struct hdpvr_device *dev); 311int hdpvr_register_i2c_adapter(struct hdpvr_device *dev);
308 312
313int hdpvr_register_i2c_ir(struct hdpvr_device *dev);
314
309/*========================================================================*/ 315/*========================================================================*/
310/* buffer management */ 316/* buffer management */
311int hdpvr_free_buffers(struct hdpvr_device *dev); 317int hdpvr_free_buffers(struct hdpvr_device *dev);
diff --git a/drivers/media/video/hexium_gemini.c b/drivers/media/video/hexium_gemini.c
index 7ae96367b3ab..cdf8b191f710 100644
--- a/drivers/media/video/hexium_gemini.c
+++ b/drivers/media/video/hexium_gemini.c
@@ -37,15 +37,15 @@ static int hexium_num;
37 37
38#define HEXIUM_INPUTS 9 38#define HEXIUM_INPUTS 9
39static struct v4l2_input hexium_inputs[HEXIUM_INPUTS] = { 39static struct v4l2_input hexium_inputs[HEXIUM_INPUTS] = {
40 { 0, "CVBS 1", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0 }, 40 { 0, "CVBS 1", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0, V4L2_IN_CAP_STD },
41 { 1, "CVBS 2", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0 }, 41 { 1, "CVBS 2", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0, V4L2_IN_CAP_STD },
42 { 2, "CVBS 3", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0 }, 42 { 2, "CVBS 3", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0, V4L2_IN_CAP_STD },
43 { 3, "CVBS 4", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0 }, 43 { 3, "CVBS 4", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0, V4L2_IN_CAP_STD },
44 { 4, "CVBS 5", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0 }, 44 { 4, "CVBS 5", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0, V4L2_IN_CAP_STD },
45 { 5, "CVBS 6", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0 }, 45 { 5, "CVBS 6", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0, V4L2_IN_CAP_STD },
46 { 6, "Y/C 1", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0 }, 46 { 6, "Y/C 1", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0, V4L2_IN_CAP_STD },
47 { 7, "Y/C 2", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0 }, 47 { 7, "Y/C 2", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0, V4L2_IN_CAP_STD },
48 { 8, "Y/C 3", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0 }, 48 { 8, "Y/C 3", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0, V4L2_IN_CAP_STD },
49}; 49};
50 50
51#define HEXIUM_AUDIOS 0 51#define HEXIUM_AUDIOS 0
diff --git a/drivers/media/video/hexium_orion.c b/drivers/media/video/hexium_orion.c
index b72d0f0b8310..6ad7e1c8b922 100644
--- a/drivers/media/video/hexium_orion.c
+++ b/drivers/media/video/hexium_orion.c
@@ -38,15 +38,15 @@ static int hexium_num;
38 38
39#define HEXIUM_INPUTS 9 39#define HEXIUM_INPUTS 9
40static struct v4l2_input hexium_inputs[HEXIUM_INPUTS] = { 40static struct v4l2_input hexium_inputs[HEXIUM_INPUTS] = {
41 { 0, "CVBS 1", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0 }, 41 { 0, "CVBS 1", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0, V4L2_IN_CAP_STD },
42 { 1, "CVBS 2", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0 }, 42 { 1, "CVBS 2", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0, V4L2_IN_CAP_STD },
43 { 2, "CVBS 3", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0 }, 43 { 2, "CVBS 3", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0, V4L2_IN_CAP_STD },
44 { 3, "CVBS 4", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0 }, 44 { 3, "CVBS 4", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0, V4L2_IN_CAP_STD },
45 { 4, "CVBS 5", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0 }, 45 { 4, "CVBS 5", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0, V4L2_IN_CAP_STD },
46 { 5, "CVBS 6", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0 }, 46 { 5, "CVBS 6", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0, V4L2_IN_CAP_STD },
47 { 6, "Y/C 1", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0 }, 47 { 6, "Y/C 1", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0, V4L2_IN_CAP_STD },
48 { 7, "Y/C 2", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0 }, 48 { 7, "Y/C 2", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0, V4L2_IN_CAP_STD },
49 { 8, "Y/C 3", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0 }, 49 { 8, "Y/C 3", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0, V4L2_IN_CAP_STD },
50}; 50};
51 51
52#define HEXIUM_AUDIOS 0 52#define HEXIUM_AUDIOS 0
diff --git a/drivers/media/video/imx074.c b/drivers/media/video/imx074.c
index 27b5dfdfbb93..1a1169115716 100644
--- a/drivers/media/video/imx074.c
+++ b/drivers/media/video/imx074.c
@@ -467,7 +467,6 @@ static int imx074_remove(struct i2c_client *client)
467 icd->ops = NULL; 467 icd->ops = NULL;
468 if (icl->free_bus) 468 if (icl->free_bus)
469 icl->free_bus(icl); 469 icl->free_bus(icl);
470 client->driver = NULL;
471 kfree(priv); 470 kfree(priv);
472 471
473 return 0; 472 return 0;
diff --git a/drivers/media/video/ir-kbd-i2c.c b/drivers/media/video/ir-kbd-i2c.c
index ce4a75375909..c87b6bc45555 100644
--- a/drivers/media/video/ir-kbd-i2c.c
+++ b/drivers/media/video/ir-kbd-i2c.c
@@ -46,7 +46,7 @@
46#include <linux/i2c.h> 46#include <linux/i2c.h>
47#include <linux/workqueue.h> 47#include <linux/workqueue.h>
48 48
49#include <media/ir-core.h> 49#include <media/rc-core.h>
50#include <media/ir-kbd-i2c.h> 50#include <media/ir-kbd-i2c.h>
51 51
52/* ----------------------------------------------------------------------- */ 52/* ----------------------------------------------------------------------- */
@@ -252,7 +252,7 @@ static void ir_key_poll(struct IR_i2c *ir)
252 } 252 }
253 253
254 if (rc) 254 if (rc)
255 ir_keydown(ir->input, ir_key, 0); 255 rc_keydown(ir->rc, ir_key, 0);
256} 256}
257 257
258static void ir_work(struct work_struct *work) 258static void ir_work(struct work_struct *work)
@@ -269,22 +269,18 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
269{ 269{
270 char *ir_codes = NULL; 270 char *ir_codes = NULL;
271 const char *name = NULL; 271 const char *name = NULL;
272 u64 ir_type = 0; 272 u64 rc_type = RC_TYPE_UNKNOWN;
273 struct IR_i2c *ir; 273 struct IR_i2c *ir;
274 struct input_dev *input_dev; 274 struct rc_dev *rc = NULL;
275 struct i2c_adapter *adap = client->adapter; 275 struct i2c_adapter *adap = client->adapter;
276 unsigned short addr = client->addr; 276 unsigned short addr = client->addr;
277 int err; 277 int err;
278 278
279 ir = kzalloc(sizeof(struct IR_i2c),GFP_KERNEL); 279 ir = kzalloc(sizeof(struct IR_i2c), GFP_KERNEL);
280 input_dev = input_allocate_device(); 280 if (!ir)
281 if (!ir || !input_dev) { 281 return -ENOMEM;
282 err = -ENOMEM;
283 goto err_out_free;
284 }
285 282
286 ir->c = client; 283 ir->c = client;
287 ir->input = input_dev;
288 ir->polling_interval = DEFAULT_POLLING_INTERVAL; 284 ir->polling_interval = DEFAULT_POLLING_INTERVAL;
289 i2c_set_clientdata(client, ir); 285 i2c_set_clientdata(client, ir);
290 286
@@ -292,7 +288,7 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
292 case 0x64: 288 case 0x64:
293 name = "Pixelview"; 289 name = "Pixelview";
294 ir->get_key = get_key_pixelview; 290 ir->get_key = get_key_pixelview;
295 ir_type = IR_TYPE_OTHER; 291 rc_type = RC_TYPE_OTHER;
296 ir_codes = RC_MAP_EMPTY; 292 ir_codes = RC_MAP_EMPTY;
297 break; 293 break;
298 case 0x18: 294 case 0x18:
@@ -300,7 +296,7 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
300 case 0x1a: 296 case 0x1a:
301 name = "Hauppauge"; 297 name = "Hauppauge";
302 ir->get_key = get_key_haup; 298 ir->get_key = get_key_haup;
303 ir_type = IR_TYPE_RC5; 299 rc_type = RC_TYPE_RC5;
304 if (hauppauge == 1) { 300 if (hauppauge == 1) {
305 ir_codes = RC_MAP_HAUPPAUGE_NEW; 301 ir_codes = RC_MAP_HAUPPAUGE_NEW;
306 } else { 302 } else {
@@ -310,19 +306,19 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
310 case 0x30: 306 case 0x30:
311 name = "KNC One"; 307 name = "KNC One";
312 ir->get_key = get_key_knc1; 308 ir->get_key = get_key_knc1;
313 ir_type = IR_TYPE_OTHER; 309 rc_type = RC_TYPE_OTHER;
314 ir_codes = RC_MAP_EMPTY; 310 ir_codes = RC_MAP_EMPTY;
315 break; 311 break;
316 case 0x6b: 312 case 0x6b:
317 name = "FusionHDTV"; 313 name = "FusionHDTV";
318 ir->get_key = get_key_fusionhdtv; 314 ir->get_key = get_key_fusionhdtv;
319 ir_type = IR_TYPE_RC5; 315 rc_type = RC_TYPE_RC5;
320 ir_codes = RC_MAP_FUSIONHDTV_MCE; 316 ir_codes = RC_MAP_FUSIONHDTV_MCE;
321 break; 317 break;
322 case 0x40: 318 case 0x40:
323 name = "AVerMedia Cardbus remote"; 319 name = "AVerMedia Cardbus remote";
324 ir->get_key = get_key_avermedia_cardbus; 320 ir->get_key = get_key_avermedia_cardbus;
325 ir_type = IR_TYPE_OTHER; 321 rc_type = RC_TYPE_OTHER;
326 ir_codes = RC_MAP_AVERMEDIA_CARDBUS; 322 ir_codes = RC_MAP_AVERMEDIA_CARDBUS;
327 break; 323 break;
328 } 324 }
@@ -333,9 +329,11 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
333 client->dev.platform_data; 329 client->dev.platform_data;
334 330
335 ir_codes = init_data->ir_codes; 331 ir_codes = init_data->ir_codes;
332 rc = init_data->rc_dev;
333
336 name = init_data->name; 334 name = init_data->name;
337 if (init_data->type) 335 if (init_data->type)
338 ir_type = init_data->type; 336 rc_type = init_data->type;
339 337
340 if (init_data->polling_interval) 338 if (init_data->polling_interval)
341 ir->polling_interval = init_data->polling_interval; 339 ir->polling_interval = init_data->polling_interval;
@@ -366,8 +364,21 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
366 } 364 }
367 } 365 }
368 366
367 if (!rc) {
368 /*
369 * If platform_data doesn't specify rc_dev, initilize it
370 * internally
371 */
372 rc = rc_allocate_device();
373 if (!rc) {
374 err = -ENOMEM;
375 goto err_out_free;
376 }
377 }
378 ir->rc = rc;
379
369 /* Make sure we are all setup before going on */ 380 /* Make sure we are all setup before going on */
370 if (!name || !ir->get_key || !ir_type || !ir_codes) { 381 if (!name || !ir->get_key || !rc_type || !ir_codes) {
371 dprintk(1, ": Unsupported device at address 0x%02x\n", 382 dprintk(1, ": Unsupported device at address 0x%02x\n",
372 addr); 383 addr);
373 err = -ENODEV; 384 err = -ENODEV;
@@ -382,18 +393,28 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
382 dev_name(&adap->dev), 393 dev_name(&adap->dev),
383 dev_name(&client->dev)); 394 dev_name(&client->dev));
384 395
385 /* init + register input device */ 396 /*
386 ir->ir_type = ir_type; 397 * Initialize input_dev fields
387 input_dev->id.bustype = BUS_I2C; 398 * It doesn't make sense to allow overriding them via platform_data
388 input_dev->name = ir->name; 399 */
389 input_dev->phys = ir->phys; 400 rc->input_id.bustype = BUS_I2C;
401 rc->input_phys = ir->phys;
402 rc->input_name = ir->name;
403
404 /*
405 * Initialize the other fields of rc_dev
406 */
407 rc->map_name = ir->ir_codes;
408 rc->allowed_protos = rc_type;
409 if (!rc->driver_name)
410 rc->driver_name = MODULE_NAME;
390 411
391 err = ir_input_register(ir->input, ir->ir_codes, NULL, MODULE_NAME); 412 err = rc_register_device(rc);
392 if (err) 413 if (err)
393 goto err_out_free; 414 goto err_out_free;
394 415
395 printk(MODULE_NAME ": %s detected at %s [%s]\n", 416 printk(MODULE_NAME ": %s detected at %s [%s]\n",
396 ir->input->name, ir->input->phys, adap->name); 417 ir->name, ir->phys, adap->name);
397 418
398 /* start polling via eventd */ 419 /* start polling via eventd */
399 INIT_DELAYED_WORK(&ir->work, ir_work); 420 INIT_DELAYED_WORK(&ir->work, ir_work);
@@ -402,6 +423,8 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
402 return 0; 423 return 0;
403 424
404 err_out_free: 425 err_out_free:
426 /* Only frees rc if it were allocated internally */
427 rc_free_device(rc);
405 kfree(ir); 428 kfree(ir);
406 return err; 429 return err;
407} 430}
@@ -414,7 +437,7 @@ static int ir_remove(struct i2c_client *client)
414 cancel_delayed_work_sync(&ir->work); 437 cancel_delayed_work_sync(&ir->work);
415 438
416 /* unregister device */ 439 /* unregister device */
417 ir_input_unregister(ir->input); 440 rc_unregister_device(ir->rc);
418 441
419 /* free memory */ 442 /* free memory */
420 kfree(ir); 443 kfree(ir);
@@ -426,6 +449,7 @@ static const struct i2c_device_id ir_kbd_id[] = {
426 { "ir_video", 0 }, 449 { "ir_video", 0 },
427 /* IR device specific entries should be added here */ 450 /* IR device specific entries should be added here */
428 { "ir_rx_z8f0811_haup", 0 }, 451 { "ir_rx_z8f0811_haup", 0 },
452 { "ir_rx_z8f0811_hdpvr", 0 },
429 { } 453 { }
430}; 454};
431 455
diff --git a/drivers/media/video/ivtv/Kconfig b/drivers/media/video/ivtv/Kconfig
index be4af1fa557e..89f65914cc8e 100644
--- a/drivers/media/video/ivtv/Kconfig
+++ b/drivers/media/video/ivtv/Kconfig
@@ -1,9 +1,8 @@
1config VIDEO_IVTV 1config VIDEO_IVTV
2 tristate "Conexant cx23416/cx23415 MPEG encoder/decoder support" 2 tristate "Conexant cx23416/cx23415 MPEG encoder/decoder support"
3 depends on VIDEO_V4L2 && PCI && I2C 3 depends on VIDEO_V4L2 && PCI && I2C
4 depends on INPUT # due to VIDEO_IR
5 select I2C_ALGOBIT 4 select I2C_ALGOBIT
6 depends on VIDEO_IR 5 depends on RC_CORE
7 select VIDEO_TUNER 6 select VIDEO_TUNER
8 select VIDEO_TVEEPROM 7 select VIDEO_TVEEPROM
9 select VIDEO_CX2341X 8 select VIDEO_CX2341X
diff --git a/drivers/media/video/ivtv/ivtv-cards.c b/drivers/media/video/ivtv/ivtv-cards.c
index 87afbbee2063..145e4749a69d 100644
--- a/drivers/media/video/ivtv/ivtv-cards.c
+++ b/drivers/media/video/ivtv/ivtv-cards.c
@@ -405,7 +405,8 @@ static const struct ivtv_card ivtv_card_avc2410 = {
405 .hw_audio_ctrl = IVTV_HW_MSP34XX, 405 .hw_audio_ctrl = IVTV_HW_MSP34XX,
406 .hw_muxer = IVTV_HW_CS53L32A, 406 .hw_muxer = IVTV_HW_CS53L32A,
407 .hw_all = IVTV_HW_MSP34XX | IVTV_HW_CS53L32A | 407 .hw_all = IVTV_HW_MSP34XX | IVTV_HW_CS53L32A |
408 IVTV_HW_SAA7115 | IVTV_HW_TUNER, 408 IVTV_HW_SAA7115 | IVTV_HW_TUNER |
409 IVTV_HW_I2C_IR_RX_ADAPTEC,
409 .video_inputs = { 410 .video_inputs = {
410 { IVTV_CARD_INPUT_VID_TUNER, 0, IVTV_SAA71XX_COMPOSITE4 }, 411 { IVTV_CARD_INPUT_VID_TUNER, 0, IVTV_SAA71XX_COMPOSITE4 },
411 { IVTV_CARD_INPUT_SVIDEO1, 1, IVTV_SAA71XX_SVIDEO0 }, 412 { IVTV_CARD_INPUT_SVIDEO1, 1, IVTV_SAA71XX_SVIDEO0 },
@@ -1313,7 +1314,6 @@ int ivtv_get_input(struct ivtv *itv, u16 index, struct v4l2_input *input)
1313 "Composite 3" 1314 "Composite 3"
1314 }; 1315 };
1315 1316
1316 memset(input, 0, sizeof(*input));
1317 if (index >= itv->nof_inputs) 1317 if (index >= itv->nof_inputs)
1318 return -EINVAL; 1318 return -EINVAL;
1319 input->index = index; 1319 input->index = index;
@@ -1331,7 +1331,6 @@ int ivtv_get_output(struct ivtv *itv, u16 index, struct v4l2_output *output)
1331{ 1331{
1332 const struct ivtv_card_output *card_output = itv->card->video_outputs + index; 1332 const struct ivtv_card_output *card_output = itv->card->video_outputs + index;
1333 1333
1334 memset(output, 0, sizeof(*output));
1335 if (index >= itv->card->nof_outputs) 1334 if (index >= itv->card->nof_outputs)
1336 return -EINVAL; 1335 return -EINVAL;
1337 output->index = index; 1336 output->index = index;
diff --git a/drivers/media/video/ivtv/ivtv-cards.h b/drivers/media/video/ivtv/ivtv-cards.h
index 78eca992e1fd..e6f5c02981f1 100644
--- a/drivers/media/video/ivtv/ivtv-cards.h
+++ b/drivers/media/video/ivtv/ivtv-cards.h
@@ -111,6 +111,7 @@
111#define IVTV_HW_I2C_IR_RX_HAUP_INT (1 << 18) 111#define IVTV_HW_I2C_IR_RX_HAUP_INT (1 << 18)
112#define IVTV_HW_Z8F0811_IR_TX_HAUP (1 << 19) 112#define IVTV_HW_Z8F0811_IR_TX_HAUP (1 << 19)
113#define IVTV_HW_Z8F0811_IR_RX_HAUP (1 << 20) 113#define IVTV_HW_Z8F0811_IR_RX_HAUP (1 << 20)
114#define IVTV_HW_I2C_IR_RX_ADAPTEC (1 << 21)
114 115
115#define IVTV_HW_Z8F0811_IR_HAUP (IVTV_HW_Z8F0811_IR_RX_HAUP | \ 116#define IVTV_HW_Z8F0811_IR_HAUP (IVTV_HW_Z8F0811_IR_RX_HAUP | \
116 IVTV_HW_Z8F0811_IR_TX_HAUP) 117 IVTV_HW_Z8F0811_IR_TX_HAUP)
@@ -120,7 +121,8 @@
120#define IVTV_HW_IR_RX_ANY (IVTV_HW_I2C_IR_RX_AVER | \ 121#define IVTV_HW_IR_RX_ANY (IVTV_HW_I2C_IR_RX_AVER | \
121 IVTV_HW_I2C_IR_RX_HAUP_EXT | \ 122 IVTV_HW_I2C_IR_RX_HAUP_EXT | \
122 IVTV_HW_I2C_IR_RX_HAUP_INT | \ 123 IVTV_HW_I2C_IR_RX_HAUP_INT | \
123 IVTV_HW_Z8F0811_IR_RX_HAUP) 124 IVTV_HW_Z8F0811_IR_RX_HAUP | \
125 IVTV_HW_I2C_IR_RX_ADAPTEC)
124 126
125#define IVTV_HW_IR_TX_ANY (IVTV_HW_Z8F0811_IR_TX_HAUP) 127#define IVTV_HW_IR_TX_ANY (IVTV_HW_Z8F0811_IR_TX_HAUP)
126 128
diff --git a/drivers/media/video/ivtv/ivtv-driver.c b/drivers/media/video/ivtv/ivtv-driver.c
index e421d15b0f5c..39946420b301 100644
--- a/drivers/media/video/ivtv/ivtv-driver.c
+++ b/drivers/media/video/ivtv/ivtv-driver.c
@@ -1029,8 +1029,13 @@ static int __devinit ivtv_probe(struct pci_dev *pdev,
1029 itv->enc_mem = ioremap_nocache(itv->base_addr + IVTV_ENCODER_OFFSET, 1029 itv->enc_mem = ioremap_nocache(itv->base_addr + IVTV_ENCODER_OFFSET,
1030 IVTV_ENCODER_SIZE); 1030 IVTV_ENCODER_SIZE);
1031 if (!itv->enc_mem) { 1031 if (!itv->enc_mem) {
1032 IVTV_ERR("ioremap failed, perhaps increasing __VMALLOC_RESERVE in page.h\n"); 1032 IVTV_ERR("ioremap failed. Can't get a window into CX23415/6 "
1033 IVTV_ERR("or disabling CONFIG_HIGHMEM4G into the kernel would help\n"); 1033 "encoder memory\n");
1034 IVTV_ERR("Each capture card with a CX23415/6 needs 8 MB of "
1035 "vmalloc address space for this window\n");
1036 IVTV_ERR("Check the output of 'grep Vmalloc /proc/meminfo'\n");
1037 IVTV_ERR("Use the vmalloc= kernel command line option to set "
1038 "VmallocTotal to a larger value\n");
1034 retval = -ENOMEM; 1039 retval = -ENOMEM;
1035 goto free_mem; 1040 goto free_mem;
1036 } 1041 }
@@ -1041,8 +1046,14 @@ static int __devinit ivtv_probe(struct pci_dev *pdev,
1041 itv->dec_mem = ioremap_nocache(itv->base_addr + IVTV_DECODER_OFFSET, 1046 itv->dec_mem = ioremap_nocache(itv->base_addr + IVTV_DECODER_OFFSET,
1042 IVTV_DECODER_SIZE); 1047 IVTV_DECODER_SIZE);
1043 if (!itv->dec_mem) { 1048 if (!itv->dec_mem) {
1044 IVTV_ERR("ioremap failed, perhaps increasing __VMALLOC_RESERVE in page.h\n"); 1049 IVTV_ERR("ioremap failed. Can't get a window into "
1045 IVTV_ERR("or disabling CONFIG_HIGHMEM4G into the kernel would help\n"); 1050 "CX23415 decoder memory\n");
1051 IVTV_ERR("Each capture card with a CX23415 needs 8 MB "
1052 "of vmalloc address space for this window\n");
1053 IVTV_ERR("Check the output of 'grep Vmalloc "
1054 "/proc/meminfo'\n");
1055 IVTV_ERR("Use the vmalloc= kernel command line option "
1056 "to set VmallocTotal to a larger value\n");
1046 retval = -ENOMEM; 1057 retval = -ENOMEM;
1047 goto free_mem; 1058 goto free_mem;
1048 } 1059 }
@@ -1057,8 +1068,13 @@ static int __devinit ivtv_probe(struct pci_dev *pdev,
1057 itv->reg_mem = 1068 itv->reg_mem =
1058 ioremap_nocache(itv->base_addr + IVTV_REG_OFFSET, IVTV_REG_SIZE); 1069 ioremap_nocache(itv->base_addr + IVTV_REG_OFFSET, IVTV_REG_SIZE);
1059 if (!itv->reg_mem) { 1070 if (!itv->reg_mem) {
1060 IVTV_ERR("ioremap failed, perhaps increasing __VMALLOC_RESERVE in page.h\n"); 1071 IVTV_ERR("ioremap failed. Can't get a window into CX23415/6 "
1061 IVTV_ERR("or disabling CONFIG_HIGHMEM4G into the kernel would help\n"); 1072 "register space\n");
1073 IVTV_ERR("Each capture card with a CX23415/6 needs 64 kB of "
1074 "vmalloc address space for this window\n");
1075 IVTV_ERR("Check the output of 'grep Vmalloc /proc/meminfo'\n");
1076 IVTV_ERR("Use the vmalloc= kernel command line option to set "
1077 "VmallocTotal to a larger value\n");
1062 retval = -ENOMEM; 1078 retval = -ENOMEM;
1063 goto free_io; 1079 goto free_io;
1064 } 1080 }
diff --git a/drivers/media/video/ivtv/ivtv-fileops.c b/drivers/media/video/ivtv/ivtv-fileops.c
index d727485da886..c57a58523ca8 100644
--- a/drivers/media/video/ivtv/ivtv-fileops.c
+++ b/drivers/media/video/ivtv/ivtv-fileops.c
@@ -570,8 +570,8 @@ ssize_t ivtv_v4l2_write(struct file *filp, const char __user *user_buf, size_t c
570 int elems = count / sizeof(struct v4l2_sliced_vbi_data); 570 int elems = count / sizeof(struct v4l2_sliced_vbi_data);
571 571
572 set_bit(IVTV_F_S_APPL_IO, &s->s_flags); 572 set_bit(IVTV_F_S_APPL_IO, &s->s_flags);
573 ivtv_write_vbi(itv, (const struct v4l2_sliced_vbi_data *)user_buf, elems); 573 return ivtv_write_vbi_from_user(itv,
574 return elems * sizeof(struct v4l2_sliced_vbi_data); 574 (const struct v4l2_sliced_vbi_data __user *)user_buf, elems);
575 } 575 }
576 576
577 mode = s->type == IVTV_DEC_STREAM_TYPE_MPG ? OUT_MPG : OUT_YUV; 577 mode = s->type == IVTV_DEC_STREAM_TYPE_MPG ? OUT_MPG : OUT_YUV;
diff --git a/drivers/media/video/ivtv/ivtv-i2c.c b/drivers/media/video/ivtv/ivtv-i2c.c
index 665191c9b407..e103b8fc7452 100644
--- a/drivers/media/video/ivtv/ivtv-i2c.c
+++ b/drivers/media/video/ivtv/ivtv-i2c.c
@@ -94,6 +94,7 @@
94#define IVTV_HAUP_INT_IR_RX_I2C_ADDR 0x18 94#define IVTV_HAUP_INT_IR_RX_I2C_ADDR 0x18
95#define IVTV_Z8F0811_IR_TX_I2C_ADDR 0x70 95#define IVTV_Z8F0811_IR_TX_I2C_ADDR 0x70
96#define IVTV_Z8F0811_IR_RX_I2C_ADDR 0x71 96#define IVTV_Z8F0811_IR_RX_I2C_ADDR 0x71
97#define IVTV_ADAPTEC_IR_ADDR 0x6b
97 98
98/* This array should match the IVTV_HW_ defines */ 99/* This array should match the IVTV_HW_ defines */
99static const u8 hw_addrs[] = { 100static const u8 hw_addrs[] = {
@@ -118,6 +119,7 @@ static const u8 hw_addrs[] = {
118 IVTV_HAUP_INT_IR_RX_I2C_ADDR, /* IVTV_HW_I2C_IR_RX_HAUP_INT */ 119 IVTV_HAUP_INT_IR_RX_I2C_ADDR, /* IVTV_HW_I2C_IR_RX_HAUP_INT */
119 IVTV_Z8F0811_IR_TX_I2C_ADDR, /* IVTV_HW_Z8F0811_IR_TX_HAUP */ 120 IVTV_Z8F0811_IR_TX_I2C_ADDR, /* IVTV_HW_Z8F0811_IR_TX_HAUP */
120 IVTV_Z8F0811_IR_RX_I2C_ADDR, /* IVTV_HW_Z8F0811_IR_RX_HAUP */ 121 IVTV_Z8F0811_IR_RX_I2C_ADDR, /* IVTV_HW_Z8F0811_IR_RX_HAUP */
122 IVTV_ADAPTEC_IR_ADDR, /* IVTV_HW_I2C_IR_RX_ADAPTEC */
121}; 123};
122 124
123/* This array should match the IVTV_HW_ defines */ 125/* This array should match the IVTV_HW_ defines */
@@ -143,8 +145,34 @@ static const char * const hw_devicenames[] = {
143 "ir_video", /* IVTV_HW_I2C_IR_RX_HAUP_INT */ 145 "ir_video", /* IVTV_HW_I2C_IR_RX_HAUP_INT */
144 "ir_tx_z8f0811_haup", /* IVTV_HW_Z8F0811_IR_TX_HAUP */ 146 "ir_tx_z8f0811_haup", /* IVTV_HW_Z8F0811_IR_TX_HAUP */
145 "ir_rx_z8f0811_haup", /* IVTV_HW_Z8F0811_IR_RX_HAUP */ 147 "ir_rx_z8f0811_haup", /* IVTV_HW_Z8F0811_IR_RX_HAUP */
148 "ir_video", /* IVTV_HW_I2C_IR_RX_ADAPTEC */
146}; 149};
147 150
151static int get_key_adaptec(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
152{
153 unsigned char keybuf[4];
154
155 keybuf[0] = 0x00;
156 i2c_master_send(ir->c, keybuf, 1);
157 /* poll IR chip */
158 if (i2c_master_recv(ir->c, keybuf, sizeof(keybuf)) != sizeof(keybuf)) {
159 return 0;
160 }
161
162 /* key pressed ? */
163 if (keybuf[2] == 0xff)
164 return 0;
165
166 /* remove repeat bit */
167 keybuf[2] &= 0x7f;
168 keybuf[3] |= 0x80;
169
170 *ir_key = keybuf[3] | keybuf[2] << 8 | keybuf[1] << 16 |keybuf[0] << 24;
171 *ir_raw = *ir_key;
172
173 return 1;
174}
175
148static int ivtv_i2c_new_ir(struct ivtv *itv, u32 hw, const char *type, u8 addr) 176static int ivtv_i2c_new_ir(struct ivtv *itv, u32 hw, const char *type, u8 addr)
149{ 177{
150 struct i2c_board_info info; 178 struct i2c_board_info info;
@@ -172,7 +200,7 @@ static int ivtv_i2c_new_ir(struct ivtv *itv, u32 hw, const char *type, u8 addr)
172 init_data->ir_codes = RC_MAP_AVERMEDIA_CARDBUS; 200 init_data->ir_codes = RC_MAP_AVERMEDIA_CARDBUS;
173 init_data->internal_get_key_func = 201 init_data->internal_get_key_func =
174 IR_KBD_GET_KEY_AVERMEDIA_CARDBUS; 202 IR_KBD_GET_KEY_AVERMEDIA_CARDBUS;
175 init_data->type = IR_TYPE_OTHER; 203 init_data->type = RC_TYPE_OTHER;
176 init_data->name = "AVerMedia AVerTV card"; 204 init_data->name = "AVerMedia AVerTV card";
177 break; 205 break;
178 case IVTV_HW_I2C_IR_RX_HAUP_EXT: 206 case IVTV_HW_I2C_IR_RX_HAUP_EXT:
@@ -180,15 +208,22 @@ static int ivtv_i2c_new_ir(struct ivtv *itv, u32 hw, const char *type, u8 addr)
180 /* Default to old black remote */ 208 /* Default to old black remote */
181 init_data->ir_codes = RC_MAP_RC5_TV; 209 init_data->ir_codes = RC_MAP_RC5_TV;
182 init_data->internal_get_key_func = IR_KBD_GET_KEY_HAUP; 210 init_data->internal_get_key_func = IR_KBD_GET_KEY_HAUP;
183 init_data->type = IR_TYPE_RC5; 211 init_data->type = RC_TYPE_RC5;
184 init_data->name = itv->card_name; 212 init_data->name = itv->card_name;
185 break; 213 break;
186 case IVTV_HW_Z8F0811_IR_RX_HAUP: 214 case IVTV_HW_Z8F0811_IR_RX_HAUP:
187 /* Default to grey remote */ 215 /* Default to grey remote */
188 init_data->ir_codes = RC_MAP_HAUPPAUGE_NEW; 216 init_data->ir_codes = RC_MAP_HAUPPAUGE_NEW;
189 init_data->internal_get_key_func = IR_KBD_GET_KEY_HAUP_XVR; 217 init_data->internal_get_key_func = IR_KBD_GET_KEY_HAUP_XVR;
190 init_data->type = IR_TYPE_RC5; 218 init_data->type = RC_TYPE_RC5;
219 init_data->name = itv->card_name;
220 break;
221 case IVTV_HW_I2C_IR_RX_ADAPTEC:
222 init_data->get_key = get_key_adaptec;
191 init_data->name = itv->card_name; 223 init_data->name = itv->card_name;
224 /* FIXME: The protocol and RC_MAP needs to be corrected */
225 init_data->ir_codes = RC_MAP_EMPTY;
226 init_data->type = RC_TYPE_UNKNOWN;
192 break; 227 break;
193 } 228 }
194 229
@@ -218,8 +253,6 @@ struct i2c_client *ivtv_i2c_new_ir_legacy(struct ivtv *itv)
218 const unsigned short addr_list[] = { 253 const unsigned short addr_list[] = {
219 0x1a, /* Hauppauge IR external - collides with WM8739 */ 254 0x1a, /* Hauppauge IR external - collides with WM8739 */
220 0x18, /* Hauppauge IR internal */ 255 0x18, /* Hauppauge IR internal */
221 0x71, /* Hauppauge IR (PVR150) */
222 0x6b, /* Adaptec IR */
223 I2C_CLIENT_END 256 I2C_CLIENT_END
224 }; 257 };
225 258
diff --git a/drivers/media/video/ivtv/ivtv-vbi.c b/drivers/media/video/ivtv/ivtv-vbi.c
index e1c347e5ebd8..2dfa957b0fd5 100644
--- a/drivers/media/video/ivtv/ivtv-vbi.c
+++ b/drivers/media/video/ivtv/ivtv-vbi.c
@@ -92,54 +92,97 @@ static int odd_parity(u8 c)
92 return c & 1; 92 return c & 1;
93} 93}
94 94
95void ivtv_write_vbi(struct ivtv *itv, const struct v4l2_sliced_vbi_data *sliced, size_t cnt) 95static void ivtv_write_vbi_line(struct ivtv *itv,
96 const struct v4l2_sliced_vbi_data *d,
97 struct vbi_cc *cc, int *found_cc)
96{ 98{
97 struct vbi_info *vi = &itv->vbi; 99 struct vbi_info *vi = &itv->vbi;
98 struct vbi_cc cc = { .odd = { 0x80, 0x80 }, .even = { 0x80, 0x80 } };
99 int found_cc = 0;
100 size_t i;
101
102 for (i = 0; i < cnt; i++) {
103 const struct v4l2_sliced_vbi_data *d = sliced + i;
104 100
105 if (d->id == V4L2_SLICED_CAPTION_525 && d->line == 21) { 101 if (d->id == V4L2_SLICED_CAPTION_525 && d->line == 21) {
106 if (d->field) { 102 if (d->field) {
107 cc.even[0] = d->data[0]; 103 cc->even[0] = d->data[0];
108 cc.even[1] = d->data[1]; 104 cc->even[1] = d->data[1];
109 } else { 105 } else {
110 cc.odd[0] = d->data[0]; 106 cc->odd[0] = d->data[0];
111 cc.odd[1] = d->data[1]; 107 cc->odd[1] = d->data[1];
112 }
113 found_cc = 1;
114 } 108 }
115 else if (d->id == V4L2_SLICED_VPS && d->line == 16 && d->field == 0) { 109 *found_cc = 1;
116 struct vbi_vps vps; 110 } else if (d->id == V4L2_SLICED_VPS && d->line == 16 && d->field == 0) {
117 111 struct vbi_vps vps;
118 vps.data[0] = d->data[2]; 112
119 vps.data[1] = d->data[8]; 113 vps.data[0] = d->data[2];
120 vps.data[2] = d->data[9]; 114 vps.data[1] = d->data[8];
121 vps.data[3] = d->data[10]; 115 vps.data[2] = d->data[9];
122 vps.data[4] = d->data[11]; 116 vps.data[3] = d->data[10];
123 if (memcmp(&vps, &vi->vps_payload, sizeof(vps))) { 117 vps.data[4] = d->data[11];
124 vi->vps_payload = vps; 118 if (memcmp(&vps, &vi->vps_payload, sizeof(vps))) {
125 set_bit(IVTV_F_I_UPDATE_VPS, &itv->i_flags); 119 vi->vps_payload = vps;
126 } 120 set_bit(IVTV_F_I_UPDATE_VPS, &itv->i_flags);
127 } 121 }
128 else if (d->id == V4L2_SLICED_WSS_625 && d->line == 23 && d->field == 0) { 122 } else if (d->id == V4L2_SLICED_WSS_625 &&
129 int wss = d->data[0] | d->data[1] << 8; 123 d->line == 23 && d->field == 0) {
124 int wss = d->data[0] | d->data[1] << 8;
130 125
131 if (vi->wss_payload != wss) { 126 if (vi->wss_payload != wss) {
132 vi->wss_payload = wss; 127 vi->wss_payload = wss;
133 set_bit(IVTV_F_I_UPDATE_WSS, &itv->i_flags); 128 set_bit(IVTV_F_I_UPDATE_WSS, &itv->i_flags);
134 }
135 } 129 }
136 } 130 }
137 if (found_cc && vi->cc_payload_idx < ARRAY_SIZE(vi->cc_payload)) { 131}
138 vi->cc_payload[vi->cc_payload_idx++] = cc; 132
133static void ivtv_write_vbi_cc_lines(struct ivtv *itv, const struct vbi_cc *cc)
134{
135 struct vbi_info *vi = &itv->vbi;
136
137 if (vi->cc_payload_idx < ARRAY_SIZE(vi->cc_payload)) {
138 memcpy(&vi->cc_payload[vi->cc_payload_idx], cc,
139 sizeof(struct vbi_cc));
140 vi->cc_payload_idx++;
139 set_bit(IVTV_F_I_UPDATE_CC, &itv->i_flags); 141 set_bit(IVTV_F_I_UPDATE_CC, &itv->i_flags);
140 } 142 }
141} 143}
142 144
145static void ivtv_write_vbi(struct ivtv *itv,
146 const struct v4l2_sliced_vbi_data *sliced,
147 size_t cnt)
148{
149 struct vbi_cc cc = { .odd = { 0x80, 0x80 }, .even = { 0x80, 0x80 } };
150 int found_cc = 0;
151 size_t i;
152
153 for (i = 0; i < cnt; i++)
154 ivtv_write_vbi_line(itv, sliced + i, &cc, &found_cc);
155
156 if (found_cc)
157 ivtv_write_vbi_cc_lines(itv, &cc);
158}
159
160ssize_t
161ivtv_write_vbi_from_user(struct ivtv *itv,
162 const struct v4l2_sliced_vbi_data __user *sliced,
163 size_t cnt)
164{
165 struct vbi_cc cc = { .odd = { 0x80, 0x80 }, .even = { 0x80, 0x80 } };
166 int found_cc = 0;
167 size_t i;
168 struct v4l2_sliced_vbi_data d;
169 ssize_t ret = cnt * sizeof(struct v4l2_sliced_vbi_data);
170
171 for (i = 0; i < cnt; i++) {
172 if (copy_from_user(&d, sliced + i,
173 sizeof(struct v4l2_sliced_vbi_data))) {
174 ret = -EFAULT;
175 break;
176 }
177 ivtv_write_vbi_line(itv, sliced + i, &cc, &found_cc);
178 }
179
180 if (found_cc)
181 ivtv_write_vbi_cc_lines(itv, &cc);
182
183 return ret;
184}
185
143static void copy_vbi_data(struct ivtv *itv, int lines, u32 pts_stamp) 186static void copy_vbi_data(struct ivtv *itv, int lines, u32 pts_stamp)
144{ 187{
145 int line = 0; 188 int line = 0;
diff --git a/drivers/media/video/ivtv/ivtv-vbi.h b/drivers/media/video/ivtv/ivtv-vbi.h
index 970567b9194d..166dd0b75d0f 100644
--- a/drivers/media/video/ivtv/ivtv-vbi.h
+++ b/drivers/media/video/ivtv/ivtv-vbi.h
@@ -20,7 +20,10 @@
20#ifndef IVTV_VBI_H 20#ifndef IVTV_VBI_H
21#define IVTV_VBI_H 21#define IVTV_VBI_H
22 22
23void ivtv_write_vbi(struct ivtv *itv, const struct v4l2_sliced_vbi_data *sliced, size_t count); 23ssize_t
24ivtv_write_vbi_from_user(struct ivtv *itv,
25 const struct v4l2_sliced_vbi_data __user *sliced,
26 size_t count);
24void ivtv_process_vbi_data(struct ivtv *itv, struct ivtv_buffer *buf, 27void ivtv_process_vbi_data(struct ivtv *itv, struct ivtv_buffer *buf,
25 u64 pts_stamp, int streamtype); 28 u64 pts_stamp, int streamtype);
26int ivtv_used_line(struct ivtv *itv, int line, int field); 29int ivtv_used_line(struct ivtv *itv, int line, int field);
diff --git a/drivers/media/video/mem2mem_testdev.c b/drivers/media/video/mem2mem_testdev.c
index 3b19f5b25a72..c179041d91f8 100644
--- a/drivers/media/video/mem2mem_testdev.c
+++ b/drivers/media/video/mem2mem_testdev.c
@@ -524,7 +524,6 @@ static int vidioc_s_fmt(struct m2mtest_ctx *ctx, struct v4l2_format *f)
524{ 524{
525 struct m2mtest_q_data *q_data; 525 struct m2mtest_q_data *q_data;
526 struct videobuf_queue *vq; 526 struct videobuf_queue *vq;
527 int ret = 0;
528 527
529 vq = v4l2_m2m_get_vq(ctx->m2m_ctx, f->type); 528 vq = v4l2_m2m_get_vq(ctx->m2m_ctx, f->type);
530 if (!vq) 529 if (!vq)
@@ -534,12 +533,9 @@ static int vidioc_s_fmt(struct m2mtest_ctx *ctx, struct v4l2_format *f)
534 if (!q_data) 533 if (!q_data)
535 return -EINVAL; 534 return -EINVAL;
536 535
537 mutex_lock(&vq->vb_lock);
538
539 if (videobuf_queue_is_busy(vq)) { 536 if (videobuf_queue_is_busy(vq)) {
540 v4l2_err(&ctx->dev->v4l2_dev, "%s queue busy\n", __func__); 537 v4l2_err(&ctx->dev->v4l2_dev, "%s queue busy\n", __func__);
541 ret = -EBUSY; 538 return -EBUSY;
542 goto out;
543 } 539 }
544 540
545 q_data->fmt = find_format(f); 541 q_data->fmt = find_format(f);
@@ -553,9 +549,7 @@ static int vidioc_s_fmt(struct m2mtest_ctx *ctx, struct v4l2_format *f)
553 "Setting format for type %d, wxh: %dx%d, fmt: %d\n", 549 "Setting format for type %d, wxh: %dx%d, fmt: %d\n",
554 f->type, q_data->width, q_data->height, q_data->fmt->fourcc); 550 f->type, q_data->width, q_data->height, q_data->fmt->fourcc);
555 551
556out: 552 return 0;
557 mutex_unlock(&vq->vb_lock);
558 return ret;
559} 553}
560 554
561static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, 555static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
@@ -845,10 +839,12 @@ static void queue_init(void *priv, struct videobuf_queue *vq,
845 enum v4l2_buf_type type) 839 enum v4l2_buf_type type)
846{ 840{
847 struct m2mtest_ctx *ctx = priv; 841 struct m2mtest_ctx *ctx = priv;
842 struct m2mtest_dev *dev = ctx->dev;
848 843
849 videobuf_queue_vmalloc_init(vq, &m2mtest_qops, ctx->dev->v4l2_dev.dev, 844 videobuf_queue_vmalloc_init(vq, &m2mtest_qops, dev->v4l2_dev.dev,
850 &ctx->dev->irqlock, type, V4L2_FIELD_NONE, 845 &dev->irqlock, type, V4L2_FIELD_NONE,
851 sizeof(struct m2mtest_buffer), priv, NULL); 846 sizeof(struct m2mtest_buffer), priv,
847 &dev->dev_mutex);
852} 848}
853 849
854 850
@@ -920,7 +916,7 @@ static const struct v4l2_file_operations m2mtest_fops = {
920 .open = m2mtest_open, 916 .open = m2mtest_open,
921 .release = m2mtest_release, 917 .release = m2mtest_release,
922 .poll = m2mtest_poll, 918 .poll = m2mtest_poll,
923 .ioctl = video_ioctl2, 919 .unlocked_ioctl = video_ioctl2,
924 .mmap = m2mtest_mmap, 920 .mmap = m2mtest_mmap,
925}; 921};
926 922
@@ -965,6 +961,7 @@ static int m2mtest_probe(struct platform_device *pdev)
965 } 961 }
966 962
967 *vfd = m2mtest_videodev; 963 *vfd = m2mtest_videodev;
964 vfd->lock = &dev->dev_mutex;
968 965
969 ret = video_register_device(vfd, VFL_TYPE_GRABBER, 0); 966 ret = video_register_device(vfd, VFL_TYPE_GRABBER, 0);
970 if (ret) { 967 if (ret) {
diff --git a/drivers/media/video/mt9m001.c b/drivers/media/video/mt9m001.c
index fcb4cd941853..f7fc88d240e6 100644
--- a/drivers/media/video/mt9m001.c
+++ b/drivers/media/video/mt9m001.c
@@ -798,7 +798,6 @@ static int mt9m001_remove(struct i2c_client *client)
798 798
799 icd->ops = NULL; 799 icd->ops = NULL;
800 mt9m001_video_remove(icd); 800 mt9m001_video_remove(icd);
801 client->driver = NULL;
802 kfree(mt9m001); 801 kfree(mt9m001);
803 802
804 return 0; 803 return 0;
diff --git a/drivers/media/video/mt9m111.c b/drivers/media/video/mt9m111.c
index 525a16e73285..53fa2a7bf156 100644
--- a/drivers/media/video/mt9m111.c
+++ b/drivers/media/video/mt9m111.c
@@ -1092,7 +1092,6 @@ static int mt9m111_remove(struct i2c_client *client)
1092 struct soc_camera_device *icd = client->dev.platform_data; 1092 struct soc_camera_device *icd = client->dev.platform_data;
1093 1093
1094 icd->ops = NULL; 1094 icd->ops = NULL;
1095 client->driver = NULL;
1096 kfree(mt9m111); 1095 kfree(mt9m111);
1097 1096
1098 return 0; 1097 return 0;
diff --git a/drivers/media/video/mt9t031.c b/drivers/media/video/mt9t031.c
index 9bd44a816ea1..7ce279c3751d 100644
--- a/drivers/media/video/mt9t031.c
+++ b/drivers/media/video/mt9t031.c
@@ -896,7 +896,6 @@ static int mt9t031_remove(struct i2c_client *client)
896 896
897 if (icd) 897 if (icd)
898 icd->ops = NULL; 898 icd->ops = NULL;
899 client->driver = NULL;
900 kfree(mt9t031); 899 kfree(mt9t031);
901 900
902 return 0; 901 return 0;
diff --git a/drivers/media/video/mt9v022.c b/drivers/media/video/mt9v022.c
index b96171cc79f9..6a784c87e5ff 100644
--- a/drivers/media/video/mt9v022.c
+++ b/drivers/media/video/mt9v022.c
@@ -930,7 +930,6 @@ static int mt9v022_remove(struct i2c_client *client)
930 930
931 icd->ops = NULL; 931 icd->ops = NULL;
932 mt9v022_video_remove(icd); 932 mt9v022_video_remove(icd);
933 client->driver = NULL;
934 kfree(mt9v022); 933 kfree(mt9v022);
935 934
936 return 0; 935 return 0;
diff --git a/drivers/media/video/mx1_camera.c b/drivers/media/video/mx1_camera.c
index 5e486a88ad7c..bc0c23a1009c 100644
--- a/drivers/media/video/mx1_camera.c
+++ b/drivers/media/video/mx1_camera.c
@@ -382,10 +382,9 @@ static void mx1_camera_init_videobuf(struct videobuf_queue *q,
382 struct mx1_camera_dev *pcdev = ici->priv; 382 struct mx1_camera_dev *pcdev = ici->priv;
383 383
384 videobuf_queue_dma_contig_init(q, &mx1_videobuf_ops, icd->dev.parent, 384 videobuf_queue_dma_contig_init(q, &mx1_videobuf_ops, icd->dev.parent,
385 &pcdev->lock, 385 &pcdev->lock, V4L2_BUF_TYPE_VIDEO_CAPTURE,
386 V4L2_BUF_TYPE_VIDEO_CAPTURE, 386 V4L2_FIELD_NONE,
387 V4L2_FIELD_NONE, 387 sizeof(struct mx1_buffer), icd, &icd->video_lock);
388 sizeof(struct mx1_buffer), icd, NULL);
389} 388}
390 389
391static int mclk_get_divisor(struct mx1_camera_dev *pcdev) 390static int mclk_get_divisor(struct mx1_camera_dev *pcdev)
diff --git a/drivers/media/video/mx2_camera.c b/drivers/media/video/mx2_camera.c
index 13565cba237d..4eab1c620318 100644
--- a/drivers/media/video/mx2_camera.c
+++ b/drivers/media/video/mx2_camera.c
@@ -683,7 +683,8 @@ static void mx2_camera_init_videobuf(struct videobuf_queue *q,
683 683
684 videobuf_queue_dma_contig_init(q, &mx2_videobuf_ops, pcdev->dev, 684 videobuf_queue_dma_contig_init(q, &mx2_videobuf_ops, pcdev->dev,
685 &pcdev->lock, V4L2_BUF_TYPE_VIDEO_CAPTURE, 685 &pcdev->lock, V4L2_BUF_TYPE_VIDEO_CAPTURE,
686 V4L2_FIELD_NONE, sizeof(struct mx2_buffer), icd, NULL); 686 V4L2_FIELD_NONE, sizeof(struct mx2_buffer),
687 icd, &icd->video_lock);
687} 688}
688 689
689#define MX2_BUS_FLAGS (SOCAM_DATAWIDTH_8 | \ 690#define MX2_BUS_FLAGS (SOCAM_DATAWIDTH_8 | \
diff --git a/drivers/media/video/mx3_camera.c b/drivers/media/video/mx3_camera.c
index aa871c2936b3..b9cb4a436959 100644
--- a/drivers/media/video/mx3_camera.c
+++ b/drivers/media/video/mx3_camera.c
@@ -443,7 +443,7 @@ static void mx3_camera_init_videobuf(struct videobuf_queue *q,
443 V4L2_BUF_TYPE_VIDEO_CAPTURE, 443 V4L2_BUF_TYPE_VIDEO_CAPTURE,
444 V4L2_FIELD_NONE, 444 V4L2_FIELD_NONE,
445 sizeof(struct mx3_camera_buffer), icd, 445 sizeof(struct mx3_camera_buffer), icd,
446 NULL); 446 &icd->video_lock);
447} 447}
448 448
449/* First part of ipu_csi_init_interface() */ 449/* First part of ipu_csi_init_interface() */
@@ -1186,13 +1186,12 @@ static int __devinit mx3_camera_probe(struct platform_device *pdev)
1186 goto egetres; 1186 goto egetres;
1187 } 1187 }
1188 1188
1189 mx3_cam = vmalloc(sizeof(*mx3_cam)); 1189 mx3_cam = vzalloc(sizeof(*mx3_cam));
1190 if (!mx3_cam) { 1190 if (!mx3_cam) {
1191 dev_err(&pdev->dev, "Could not allocate mx3 camera object\n"); 1191 dev_err(&pdev->dev, "Could not allocate mx3 camera object\n");
1192 err = -ENOMEM; 1192 err = -ENOMEM;
1193 goto ealloc; 1193 goto ealloc;
1194 } 1194 }
1195 memset(mx3_cam, 0, sizeof(*mx3_cam));
1196 1195
1197 mx3_cam->clk = clk_get(&pdev->dev, NULL); 1196 mx3_cam->clk = clk_get(&pdev->dev, NULL);
1198 if (IS_ERR(mx3_cam->clk)) { 1197 if (IS_ERR(mx3_cam->clk)) {
diff --git a/drivers/media/video/mxb.c b/drivers/media/video/mxb.c
index 4e8fd965f151..e8846a09b026 100644
--- a/drivers/media/video/mxb.c
+++ b/drivers/media/video/mxb.c
@@ -59,10 +59,10 @@ MODULE_PARM_DESC(debug, "Turn on/off device debugging (default:off).");
59enum { TUNER, AUX1, AUX3, AUX3_YC }; 59enum { TUNER, AUX1, AUX3, AUX3_YC };
60 60
61static struct v4l2_input mxb_inputs[MXB_INPUTS] = { 61static struct v4l2_input mxb_inputs[MXB_INPUTS] = {
62 { TUNER, "Tuner", V4L2_INPUT_TYPE_TUNER, 1, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0 }, 62 { TUNER, "Tuner", V4L2_INPUT_TYPE_TUNER, 1, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0, V4L2_IN_CAP_STD },
63 { AUX1, "AUX1", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0 }, 63 { AUX1, "AUX1", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0, V4L2_IN_CAP_STD },
64 { AUX3, "AUX3 Composite", V4L2_INPUT_TYPE_CAMERA, 4, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0 }, 64 { AUX3, "AUX3 Composite", V4L2_INPUT_TYPE_CAMERA, 4, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0, V4L2_IN_CAP_STD },
65 { AUX3_YC, "AUX3 S-Video", V4L2_INPUT_TYPE_CAMERA, 4, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0 }, 65 { AUX3_YC, "AUX3 S-Video", V4L2_INPUT_TYPE_CAMERA, 4, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0, V4L2_IN_CAP_STD },
66}; 66};
67 67
68/* this array holds the information, which port of the saa7146 each 68/* this array holds the information, which port of the saa7146 each
diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
index 15f8793e325b..83de97ad971e 100644
--- a/drivers/media/video/omap/omap_vout.c
+++ b/drivers/media/video/omap/omap_vout.c
@@ -2230,7 +2230,6 @@ static int __init omap_vout_setup_video_data(struct omap_vout_device *vout)
2230 2230
2231 strlcpy(vfd->name, VOUT_NAME, sizeof(vfd->name)); 2231 strlcpy(vfd->name, VOUT_NAME, sizeof(vfd->name));
2232 2232
2233 /* need to register for a VID_HARDWARE_* ID in videodev.h */
2234 vfd->fops = &omap_vout_fops; 2233 vfd->fops = &omap_vout_fops;
2235 vfd->v4l2_dev = &vout->vid_dev->v4l2_dev; 2234 vfd->v4l2_dev = &vout->vid_dev->v4l2_dev;
2236 mutex_init(&vout->lock); 2235 mutex_init(&vout->lock);
diff --git a/drivers/media/video/omap1_camera.c b/drivers/media/video/omap1_camera.c
index cbfd07f2d9da..0a2fb2bfdbfb 100644
--- a/drivers/media/video/omap1_camera.c
+++ b/drivers/media/video/omap1_camera.c
@@ -1365,12 +1365,12 @@ static void omap1_cam_init_videobuf(struct videobuf_queue *q,
1365 videobuf_queue_dma_contig_init(q, &omap1_videobuf_ops, 1365 videobuf_queue_dma_contig_init(q, &omap1_videobuf_ops,
1366 icd->dev.parent, &pcdev->lock, 1366 icd->dev.parent, &pcdev->lock,
1367 V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_NONE, 1367 V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_NONE,
1368 sizeof(struct omap1_cam_buf), icd, NULL); 1368 sizeof(struct omap1_cam_buf), icd, &icd->video_lock);
1369 else 1369 else
1370 videobuf_queue_sg_init(q, &omap1_videobuf_ops, 1370 videobuf_queue_sg_init(q, &omap1_videobuf_ops,
1371 icd->dev.parent, &pcdev->lock, 1371 icd->dev.parent, &pcdev->lock,
1372 V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_NONE, 1372 V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_NONE,
1373 sizeof(struct omap1_cam_buf), icd, NULL); 1373 sizeof(struct omap1_cam_buf), icd, &icd->video_lock);
1374 1374
1375 /* use videobuf mode (auto)selected with the module parameter */ 1375 /* use videobuf mode (auto)selected with the module parameter */
1376 pcdev->vb_mode = sg_mode ? OMAP1_CAM_DMA_SG : OMAP1_CAM_DMA_CONTIG; 1376 pcdev->vb_mode = sg_mode ? OMAP1_CAM_DMA_SG : OMAP1_CAM_DMA_CONTIG;
diff --git a/drivers/media/video/ov2640.c b/drivers/media/video/ov2640.c
new file mode 100644
index 000000000000..0cea0cf36679
--- /dev/null
+++ b/drivers/media/video/ov2640.c
@@ -0,0 +1,1205 @@
1/*
2 * ov2640 Camera Driver
3 *
4 * Copyright (C) 2010 Alberto Panizzo <maramaopercheseimorto@gmail.com>
5 *
6 * Based on ov772x, ov9640 drivers and previous non merged implementations.
7 *
8 * Copyright 2005-2009 Freescale Semiconductor, Inc. All Rights Reserved.
9 * Copyright (C) 2006, OmniVision
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14 */
15
16#include <linux/init.h>
17#include <linux/module.h>
18#include <linux/i2c.h>
19#include <linux/slab.h>
20#include <linux/delay.h>
21#include <linux/videodev2.h>
22#include <media/v4l2-chip-ident.h>
23#include <media/v4l2-subdev.h>
24#include <media/soc_camera.h>
25#include <media/soc_mediabus.h>
26
27#define VAL_SET(x, mask, rshift, lshift) \
28 ((((x) >> rshift) & mask) << lshift)
29/*
30 * DSP registers
31 * register offset for BANK_SEL == BANK_SEL_DSP
32 */
33#define R_BYPASS 0x05 /* Bypass DSP */
34#define R_BYPASS_DSP_BYPAS 0x01 /* Bypass DSP, sensor out directly */
35#define R_BYPASS_USE_DSP 0x00 /* Use the internal DSP */
36#define QS 0x44 /* Quantization Scale Factor */
37#define CTRLI 0x50
38#define CTRLI_LP_DP 0x80
39#define CTRLI_ROUND 0x40
40#define CTRLI_V_DIV_SET(x) VAL_SET(x, 0x3, 0, 3)
41#define CTRLI_H_DIV_SET(x) VAL_SET(x, 0x3, 0, 0)
42#define HSIZE 0x51 /* H_SIZE[7:0] (real/4) */
43#define HSIZE_SET(x) VAL_SET(x, 0xFF, 2, 0)
44#define VSIZE 0x52 /* V_SIZE[7:0] (real/4) */
45#define VSIZE_SET(x) VAL_SET(x, 0xFF, 2, 0)
46#define XOFFL 0x53 /* OFFSET_X[7:0] */
47#define XOFFL_SET(x) VAL_SET(x, 0xFF, 0, 0)
48#define YOFFL 0x54 /* OFFSET_Y[7:0] */
49#define YOFFL_SET(x) VAL_SET(x, 0xFF, 0, 0)
50#define VHYX 0x55 /* Offset and size completion */
51#define VHYX_VSIZE_SET(x) VAL_SET(x, 0x1, (8+2), 7)
52#define VHYX_HSIZE_SET(x) VAL_SET(x, 0x1, (8+2), 3)
53#define VHYX_YOFF_SET(x) VAL_SET(x, 0x3, 8, 4)
54#define VHYX_XOFF_SET(x) VAL_SET(x, 0x3, 8, 0)
55#define DPRP 0x56
56#define TEST 0x57 /* Horizontal size completion */
57#define TEST_HSIZE_SET(x) VAL_SET(x, 0x1, (9+2), 7)
58#define ZMOW 0x5A /* Zoom: Out Width OUTW[7:0] (real/4) */
59#define ZMOW_OUTW_SET(x) VAL_SET(x, 0xFF, 2, 0)
60#define ZMOH 0x5B /* Zoom: Out Height OUTH[7:0] (real/4) */
61#define ZMOH_OUTH_SET(x) VAL_SET(x, 0xFF, 2, 0)
62#define ZMHH 0x5C /* Zoom: Speed and H&W completion */
63#define ZMHH_ZSPEED_SET(x) VAL_SET(x, 0x0F, 0, 4)
64#define ZMHH_OUTH_SET(x) VAL_SET(x, 0x1, (8+2), 2)
65#define ZMHH_OUTW_SET(x) VAL_SET(x, 0x3, (8+2), 0)
66#define BPADDR 0x7C /* SDE Indirect Register Access: Address */
67#define BPDATA 0x7D /* SDE Indirect Register Access: Data */
68#define CTRL2 0x86 /* DSP Module enable 2 */
69#define CTRL2_DCW_EN 0x20
70#define CTRL2_SDE_EN 0x10
71#define CTRL2_UV_ADJ_EN 0x08
72#define CTRL2_UV_AVG_EN 0x04
73#define CTRL2_CMX_EN 0x01
74#define CTRL3 0x87 /* DSP Module enable 3 */
75#define CTRL3_BPC_EN 0x80
76#define CTRL3_WPC_EN 0x40
77#define SIZEL 0x8C /* Image Size Completion */
78#define SIZEL_HSIZE8_11_SET(x) VAL_SET(x, 0x1, 11, 6)
79#define SIZEL_HSIZE8_SET(x) VAL_SET(x, 0x7, 0, 3)
80#define SIZEL_VSIZE8_SET(x) VAL_SET(x, 0x7, 0, 0)
81#define HSIZE8 0xC0 /* Image Horizontal Size HSIZE[10:3] */
82#define HSIZE8_SET(x) VAL_SET(x, 0xFF, 3, 0)
83#define VSIZE8 0xC1 /* Image Vertical Size VSIZE[10:3] */
84#define VSIZE8_SET(x) VAL_SET(x, 0xFF, 3, 0)
85#define CTRL0 0xC2 /* DSP Module enable 0 */
86#define CTRL0_AEC_EN 0x80
87#define CTRL0_AEC_SEL 0x40
88#define CTRL0_STAT_SEL 0x20
89#define CTRL0_VFIRST 0x10
90#define CTRL0_YUV422 0x08
91#define CTRL0_YUV_EN 0x04
92#define CTRL0_RGB_EN 0x02
93#define CTRL0_RAW_EN 0x01
94#define CTRL1 0xC3 /* DSP Module enable 1 */
95#define CTRL1_CIP 0x80
96#define CTRL1_DMY 0x40
97#define CTRL1_RAW_GMA 0x20
98#define CTRL1_DG 0x10
99#define CTRL1_AWB 0x08
100#define CTRL1_AWB_GAIN 0x04
101#define CTRL1_LENC 0x02
102#define CTRL1_PRE 0x01
103#define R_DVP_SP 0xD3 /* DVP output speed control */
104#define R_DVP_SP_AUTO_MODE 0x80
105#define R_DVP_SP_DVP_MASK 0x3F /* DVP PCLK = sysclk (48)/[6:0] (YUV0);
106 * = sysclk (48)/(2*[6:0]) (RAW);*/
107#define IMAGE_MODE 0xDA /* Image Output Format Select */
108#define IMAGE_MODE_Y8_DVP_EN 0x40
109#define IMAGE_MODE_JPEG_EN 0x10
110#define IMAGE_MODE_YUV422 0x00
111#define IMAGE_MODE_RAW10 0x04 /* (DVP) */
112#define IMAGE_MODE_RGB565 0x08
113#define IMAGE_MODE_HREF_VSYNC 0x02 /* HREF timing select in DVP JPEG output
114 * mode (0 for HREF is same as sensor) */
115#define IMAGE_MODE_LBYTE_FIRST 0x01 /* Byte swap enable for DVP
116 * 1: Low byte first UYVY (C2[4] =0)
117 * VYUY (C2[4] =1)
118 * 0: High byte first YUYV (C2[4]=0)
119 * YVYU (C2[4] = 1) */
120#define RESET 0xE0 /* Reset */
121#define RESET_MICROC 0x40
122#define RESET_SCCB 0x20
123#define RESET_JPEG 0x10
124#define RESET_DVP 0x04
125#define RESET_IPU 0x02
126#define RESET_CIF 0x01
127#define REGED 0xED /* Register ED */
128#define REGED_CLK_OUT_DIS 0x10
129#define MS_SP 0xF0 /* SCCB Master Speed */
130#define SS_ID 0xF7 /* SCCB Slave ID */
131#define SS_CTRL 0xF8 /* SCCB Slave Control */
132#define SS_CTRL_ADD_AUTO_INC 0x20
133#define SS_CTRL_EN 0x08
134#define SS_CTRL_DELAY_CLK 0x04
135#define SS_CTRL_ACC_EN 0x02
136#define SS_CTRL_SEN_PASS_THR 0x01
137#define MC_BIST 0xF9 /* Microcontroller misc register */
138#define MC_BIST_RESET 0x80 /* Microcontroller Reset */
139#define MC_BIST_BOOT_ROM_SEL 0x40
140#define MC_BIST_12KB_SEL 0x20
141#define MC_BIST_12KB_MASK 0x30
142#define MC_BIST_512KB_SEL 0x08
143#define MC_BIST_512KB_MASK 0x0C
144#define MC_BIST_BUSY_BIT_R 0x02
145#define MC_BIST_MC_RES_ONE_SH_W 0x02
146#define MC_BIST_LAUNCH 0x01
147#define BANK_SEL 0xFF /* Register Bank Select */
148#define BANK_SEL_DSP 0x00
149#define BANK_SEL_SENS 0x01
150
151/*
152 * Sensor registers
153 * register offset for BANK_SEL == BANK_SEL_SENS
154 */
155#define GAIN 0x00 /* AGC - Gain control gain setting */
156#define COM1 0x03 /* Common control 1 */
157#define COM1_1_DUMMY_FR 0x40
158#define COM1_3_DUMMY_FR 0x80
159#define COM1_7_DUMMY_FR 0xC0
160#define COM1_VWIN_LSB_UXGA 0x0F
161#define COM1_VWIN_LSB_SVGA 0x0A
162#define COM1_VWIN_LSB_CIF 0x06
163#define REG04 0x04 /* Register 04 */
164#define REG04_DEF 0x20 /* Always set */
165#define REG04_HFLIP_IMG 0x80 /* Horizontal mirror image ON/OFF */
166#define REG04_VFLIP_IMG 0x40 /* Vertical flip image ON/OFF */
167#define REG04_VREF_EN 0x10
168#define REG04_HREF_EN 0x08
169#define REG04_AEC_SET(x) VAL_SET(x, 0x3, 0, 0)
170#define REG08 0x08 /* Frame Exposure One-pin Control Pre-charge Row Num */
171#define COM2 0x09 /* Common control 2 */
172#define COM2_SOFT_SLEEP_MODE 0x10 /* Soft sleep mode */
173 /* Output drive capability */
174#define COM2_OCAP_Nx_SET(N) (((N) - 1) & 0x03) /* N = [1x .. 4x] */
175#define PID 0x0A /* Product ID Number MSB */
176#define VER 0x0B /* Product ID Number LSB */
177#define COM3 0x0C /* Common control 3 */
178#define COM3_BAND_50H 0x04 /* 0 For Banding at 60H */
179#define COM3_BAND_AUTO 0x02 /* Auto Banding */
180#define COM3_SING_FR_SNAPSH 0x01 /* 0 For enable live video output after the
181 * snapshot sequence*/
182#define AEC 0x10 /* AEC[9:2] Exposure Value */
183#define CLKRC 0x11 /* Internal clock */
184#define CLKRC_EN 0x80
185#define CLKRC_DIV_SET(x) (((x) - 1) & 0x1F) /* CLK = XVCLK/(x) */
186#define COM7 0x12 /* Common control 7 */
187#define COM7_SRST 0x80 /* Initiates system reset. All registers are
188 * set to factory default values after which
189 * the chip resumes normal operation */
190#define COM7_RES_UXGA 0x00 /* Resolution selectors for UXGA */
191#define COM7_RES_SVGA 0x40 /* SVGA */
192#define COM7_RES_CIF 0x20 /* CIF */
193#define COM7_ZOOM_EN 0x04 /* Enable Zoom mode */
194#define COM7_COLOR_BAR_TEST 0x02 /* Enable Color Bar Test Pattern */
195#define COM8 0x13 /* Common control 8 */
196#define COM8_DEF 0xC0 /* Banding filter ON/OFF */
197#define COM8_BNDF_EN 0x20 /* Banding filter ON/OFF */
198#define COM8_AGC_EN 0x04 /* AGC Auto/Manual control selection */
199#define COM8_AEC_EN 0x01 /* Auto/Manual Exposure control */
200#define COM9 0x14 /* Common control 9
201 * Automatic gain ceiling - maximum AGC value [7:5]*/
202#define COM9_AGC_GAIN_2x 0x00 /* 000 : 2x */
203#define COM9_AGC_GAIN_4x 0x20 /* 001 : 4x */
204#define COM9_AGC_GAIN_8x 0x40 /* 010 : 8x */
205#define COM9_AGC_GAIN_16x 0x60 /* 011 : 16x */
206#define COM9_AGC_GAIN_32x 0x80 /* 100 : 32x */
207#define COM9_AGC_GAIN_64x 0xA0 /* 101 : 64x */
208#define COM9_AGC_GAIN_128x 0xC0 /* 110 : 128x */
209#define COM10 0x15 /* Common control 10 */
210#define COM10_PCLK_HREF 0x20 /* PCLK output qualified by HREF */
211#define COM10_PCLK_RISE 0x10 /* Data is updated at the rising edge of
212 * PCLK (user can latch data at the next
213 * falling edge of PCLK).
214 * 0 otherwise. */
215#define COM10_HREF_INV 0x08 /* Invert HREF polarity:
216 * HREF negative for valid data*/
217#define COM10_VSINC_INV 0x02 /* Invert VSYNC polarity */
218#define HSTART 0x17 /* Horizontal Window start MSB 8 bit */
219#define HEND 0x18 /* Horizontal Window end MSB 8 bit */
220#define VSTART 0x19 /* Vertical Window start MSB 8 bit */
221#define VEND 0x1A /* Vertical Window end MSB 8 bit */
222#define MIDH 0x1C /* Manufacturer ID byte - high */
223#define MIDL 0x1D /* Manufacturer ID byte - low */
224#define AEW 0x24 /* AGC/AEC - Stable operating region (upper limit) */
225#define AEB 0x25 /* AGC/AEC - Stable operating region (lower limit) */
226#define VV 0x26 /* AGC/AEC Fast mode operating region */
227#define VV_HIGH_TH_SET(x) VAL_SET(x, 0xF, 0, 4)
228#define VV_LOW_TH_SET(x) VAL_SET(x, 0xF, 0, 0)
229#define REG2A 0x2A /* Dummy pixel insert MSB */
230#define FRARL 0x2B /* Dummy pixel insert LSB */
231#define ADDVFL 0x2D /* LSB of insert dummy lines in Vertical direction */
232#define ADDVFH 0x2E /* MSB of insert dummy lines in Vertical direction */
233#define YAVG 0x2F /* Y/G Channel Average value */
234#define REG32 0x32 /* Common Control 32 */
235#define REG32_PCLK_DIV_2 0x80 /* PCLK freq divided by 2 */
236#define REG32_PCLK_DIV_4 0xC0 /* PCLK freq divided by 4 */
237#define ARCOM2 0x34 /* Zoom: Horizontal start point */
238#define REG45 0x45 /* Register 45 */
239#define FLL 0x46 /* Frame Length Adjustment LSBs */
240#define FLH 0x47 /* Frame Length Adjustment MSBs */
241#define COM19 0x48 /* Zoom: Vertical start point */
242#define ZOOMS 0x49 /* Zoom: Vertical start point */
243#define COM22 0x4B /* Flash light control */
244#define COM25 0x4E /* For Banding operations */
245#define BD50 0x4F /* 50Hz Banding AEC 8 LSBs */
246#define BD60 0x50 /* 60Hz Banding AEC 8 LSBs */
247#define REG5D 0x5D /* AVGsel[7:0], 16-zone average weight option */
248#define REG5E 0x5E /* AVGsel[15:8], 16-zone average weight option */
249#define REG5F 0x5F /* AVGsel[23:16], 16-zone average weight option */
250#define REG60 0x60 /* AVGsel[31:24], 16-zone average weight option */
251#define HISTO_LOW 0x61 /* Histogram Algorithm Low Level */
252#define HISTO_HIGH 0x62 /* Histogram Algorithm High Level */
253
254/*
255 * ID
256 */
257#define MANUFACTURER_ID 0x7FA2
258#define PID_OV2640 0x2642
259#define VERSION(pid, ver) ((pid << 8) | (ver & 0xFF))
260
261/*
262 * Struct
263 */
264struct regval_list {
265 u8 reg_num;
266 u8 value;
267};
268
269/* Supported resolutions */
270enum ov2640_width {
271 W_QCIF = 176,
272 W_QVGA = 320,
273 W_CIF = 352,
274 W_VGA = 640,
275 W_SVGA = 800,
276 W_XGA = 1024,
277 W_SXGA = 1280,
278 W_UXGA = 1600,
279};
280
281enum ov2640_height {
282 H_QCIF = 144,
283 H_QVGA = 240,
284 H_CIF = 288,
285 H_VGA = 480,
286 H_SVGA = 600,
287 H_XGA = 768,
288 H_SXGA = 1024,
289 H_UXGA = 1200,
290};
291
292struct ov2640_win_size {
293 char *name;
294 enum ov2640_width width;
295 enum ov2640_height height;
296 const struct regval_list *regs;
297};
298
299
300struct ov2640_priv {
301 struct v4l2_subdev subdev;
302 struct ov2640_camera_info *info;
303 enum v4l2_mbus_pixelcode cfmt_code;
304 const struct ov2640_win_size *win;
305 int model;
306 u16 flag_vflip:1;
307 u16 flag_hflip:1;
308};
309
310/*
311 * Registers settings
312 */
313
314#define ENDMARKER { 0xff, 0xff }
315
316static const struct regval_list ov2640_init_regs[] = {
317 { BANK_SEL, BANK_SEL_DSP },
318 { 0x2c, 0xff },
319 { 0x2e, 0xdf },
320 { BANK_SEL, BANK_SEL_SENS },
321 { 0x3c, 0x32 },
322 { CLKRC, CLKRC_DIV_SET(1) },
323 { COM2, COM2_OCAP_Nx_SET(3) },
324 { REG04, REG04_DEF | REG04_HREF_EN },
325 { COM8, COM8_DEF | COM8_BNDF_EN | COM8_AGC_EN | COM8_AEC_EN },
326 { COM9, COM9_AGC_GAIN_8x | 0x08},
327 { 0x2c, 0x0c },
328 { 0x33, 0x78 },
329 { 0x3a, 0x33 },
330 { 0x3b, 0xfb },
331 { 0x3e, 0x00 },
332 { 0x43, 0x11 },
333 { 0x16, 0x10 },
334 { 0x39, 0x02 },
335 { 0x35, 0x88 },
336 { 0x22, 0x0a },
337 { 0x37, 0x40 },
338 { 0x23, 0x00 },
339 { ARCOM2, 0xa0 },
340 { 0x06, 0x02 },
341 { 0x06, 0x88 },
342 { 0x07, 0xc0 },
343 { 0x0d, 0xb7 },
344 { 0x0e, 0x01 },
345 { 0x4c, 0x00 },
346 { 0x4a, 0x81 },
347 { 0x21, 0x99 },
348 { AEW, 0x40 },
349 { AEB, 0x38 },
350 { VV, VV_HIGH_TH_SET(0x08) | VV_LOW_TH_SET(0x02) },
351 { 0x5c, 0x00 },
352 { 0x63, 0x00 },
353 { FLL, 0x22 },
354 { COM3, 0x38 | COM3_BAND_AUTO },
355 { REG5D, 0x55 },
356 { REG5E, 0x7d },
357 { REG5F, 0x7d },
358 { REG60, 0x55 },
359 { HISTO_LOW, 0x70 },
360 { HISTO_HIGH, 0x80 },
361 { 0x7c, 0x05 },
362 { 0x20, 0x80 },
363 { 0x28, 0x30 },
364 { 0x6c, 0x00 },
365 { 0x6d, 0x80 },
366 { 0x6e, 0x00 },
367 { 0x70, 0x02 },
368 { 0x71, 0x94 },
369 { 0x73, 0xc1 },
370 { 0x3d, 0x34 },
371 { COM7, COM7_RES_UXGA | COM7_ZOOM_EN },
372 { 0x5a, 0x57 },
373 { BD50, 0xbb },
374 { BD60, 0x9c },
375 { BANK_SEL, BANK_SEL_DSP },
376 { 0xe5, 0x7f },
377 { MC_BIST, MC_BIST_RESET | MC_BIST_BOOT_ROM_SEL },
378 { 0x41, 0x24 },
379 { RESET, RESET_JPEG | RESET_DVP },
380 { 0x76, 0xff },
381 { 0x33, 0xa0 },
382 { 0x42, 0x20 },
383 { 0x43, 0x18 },
384 { 0x4c, 0x00 },
385 { CTRL3, CTRL3_BPC_EN | CTRL3_WPC_EN | 0x10 },
386 { 0x88, 0x3f },
387 { 0xd7, 0x03 },
388 { 0xd9, 0x10 },
389 { R_DVP_SP , R_DVP_SP_AUTO_MODE | 0x2 },
390 { 0xc8, 0x08 },
391 { 0xc9, 0x80 },
392 { BPADDR, 0x00 },
393 { BPDATA, 0x00 },
394 { BPADDR, 0x03 },
395 { BPDATA, 0x48 },
396 { BPDATA, 0x48 },
397 { BPADDR, 0x08 },
398 { BPDATA, 0x20 },
399 { BPDATA, 0x10 },
400 { BPDATA, 0x0e },
401 { 0x90, 0x00 },
402 { 0x91, 0x0e },
403 { 0x91, 0x1a },
404 { 0x91, 0x31 },
405 { 0x91, 0x5a },
406 { 0x91, 0x69 },
407 { 0x91, 0x75 },
408 { 0x91, 0x7e },
409 { 0x91, 0x88 },
410 { 0x91, 0x8f },
411 { 0x91, 0x96 },
412 { 0x91, 0xa3 },
413 { 0x91, 0xaf },
414 { 0x91, 0xc4 },
415 { 0x91, 0xd7 },
416 { 0x91, 0xe8 },
417 { 0x91, 0x20 },
418 { 0x92, 0x00 },
419 { 0x93, 0x06 },
420 { 0x93, 0xe3 },
421 { 0x93, 0x03 },
422 { 0x93, 0x03 },
423 { 0x93, 0x00 },
424 { 0x93, 0x02 },
425 { 0x93, 0x00 },
426 { 0x93, 0x00 },
427 { 0x93, 0x00 },
428 { 0x93, 0x00 },
429 { 0x93, 0x00 },
430 { 0x93, 0x00 },
431 { 0x93, 0x00 },
432 { 0x96, 0x00 },
433 { 0x97, 0x08 },
434 { 0x97, 0x19 },
435 { 0x97, 0x02 },
436 { 0x97, 0x0c },
437 { 0x97, 0x24 },
438 { 0x97, 0x30 },
439 { 0x97, 0x28 },
440 { 0x97, 0x26 },
441 { 0x97, 0x02 },
442 { 0x97, 0x98 },
443 { 0x97, 0x80 },
444 { 0x97, 0x00 },
445 { 0x97, 0x00 },
446 { 0xa4, 0x00 },
447 { 0xa8, 0x00 },
448 { 0xc5, 0x11 },
449 { 0xc6, 0x51 },
450 { 0xbf, 0x80 },
451 { 0xc7, 0x10 },
452 { 0xb6, 0x66 },
453 { 0xb8, 0xA5 },
454 { 0xb7, 0x64 },
455 { 0xb9, 0x7C },
456 { 0xb3, 0xaf },
457 { 0xb4, 0x97 },
458 { 0xb5, 0xFF },
459 { 0xb0, 0xC5 },
460 { 0xb1, 0x94 },
461 { 0xb2, 0x0f },
462 { 0xc4, 0x5c },
463 { 0xa6, 0x00 },
464 { 0xa7, 0x20 },
465 { 0xa7, 0xd8 },
466 { 0xa7, 0x1b },
467 { 0xa7, 0x31 },
468 { 0xa7, 0x00 },
469 { 0xa7, 0x18 },
470 { 0xa7, 0x20 },
471 { 0xa7, 0xd8 },
472 { 0xa7, 0x19 },
473 { 0xa7, 0x31 },
474 { 0xa7, 0x00 },
475 { 0xa7, 0x18 },
476 { 0xa7, 0x20 },
477 { 0xa7, 0xd8 },
478 { 0xa7, 0x19 },
479 { 0xa7, 0x31 },
480 { 0xa7, 0x00 },
481 { 0xa7, 0x18 },
482 { 0x7f, 0x00 },
483 { 0xe5, 0x1f },
484 { 0xe1, 0x77 },
485 { 0xdd, 0x7f },
486 { CTRL0, CTRL0_YUV422 | CTRL0_YUV_EN | CTRL0_RGB_EN },
487 ENDMARKER,
488};
489
490/*
491 * Register settings for window size
492 * The preamble, setup the internal DSP to input an UXGA (1600x1200) image.
493 * Then the different zooming configurations will setup the output image size.
494 */
495static const struct regval_list ov2640_size_change_preamble_regs[] = {
496 { BANK_SEL, BANK_SEL_DSP },
497 { RESET, RESET_DVP },
498 { HSIZE8, HSIZE8_SET(W_UXGA) },
499 { VSIZE8, VSIZE8_SET(H_UXGA) },
500 { CTRL2, CTRL2_DCW_EN | CTRL2_SDE_EN |
501 CTRL2_UV_AVG_EN | CTRL2_CMX_EN | CTRL2_UV_ADJ_EN },
502 { HSIZE, HSIZE_SET(W_UXGA) },
503 { VSIZE, VSIZE_SET(H_UXGA) },
504 { XOFFL, XOFFL_SET(0) },
505 { YOFFL, YOFFL_SET(0) },
506 { VHYX, VHYX_HSIZE_SET(W_UXGA) | VHYX_VSIZE_SET(H_UXGA) |
507 VHYX_XOFF_SET(0) | VHYX_YOFF_SET(0)},
508 { TEST, TEST_HSIZE_SET(W_UXGA) },
509 ENDMARKER,
510};
511
512#define PER_SIZE_REG_SEQ(x, y, v_div, h_div, pclk_div) \
513 { CTRLI, CTRLI_LP_DP | CTRLI_V_DIV_SET(v_div) | \
514 CTRLI_H_DIV_SET(h_div)}, \
515 { ZMOW, ZMOW_OUTW_SET(x) }, \
516 { ZMOH, ZMOH_OUTH_SET(y) }, \
517 { ZMHH, ZMHH_OUTW_SET(x) | ZMHH_OUTH_SET(y) }, \
518 { R_DVP_SP, pclk_div }, \
519 { RESET, 0x00}
520
521static const struct regval_list ov2640_qcif_regs[] = {
522 PER_SIZE_REG_SEQ(W_QCIF, H_QCIF, 3, 3, 4),
523 ENDMARKER,
524};
525
526static const struct regval_list ov2640_qvga_regs[] = {
527 PER_SIZE_REG_SEQ(W_QVGA, H_QVGA, 2, 2, 4),
528 ENDMARKER,
529};
530
531static const struct regval_list ov2640_cif_regs[] = {
532 PER_SIZE_REG_SEQ(W_CIF, H_CIF, 2, 2, 8),
533 ENDMARKER,
534};
535
536static const struct regval_list ov2640_vga_regs[] = {
537 PER_SIZE_REG_SEQ(W_VGA, H_VGA, 0, 0, 2),
538 ENDMARKER,
539};
540
541static const struct regval_list ov2640_svga_regs[] = {
542 PER_SIZE_REG_SEQ(W_SVGA, H_SVGA, 1, 1, 2),
543 ENDMARKER,
544};
545
546static const struct regval_list ov2640_xga_regs[] = {
547 PER_SIZE_REG_SEQ(W_XGA, H_XGA, 0, 0, 2),
548 { CTRLI, 0x00},
549 ENDMARKER,
550};
551
552static const struct regval_list ov2640_sxga_regs[] = {
553 PER_SIZE_REG_SEQ(W_SXGA, H_SXGA, 0, 0, 2),
554 { CTRLI, 0x00},
555 { R_DVP_SP, 2 | R_DVP_SP_AUTO_MODE },
556 ENDMARKER,
557};
558
559static const struct regval_list ov2640_uxga_regs[] = {
560 PER_SIZE_REG_SEQ(W_UXGA, H_UXGA, 0, 0, 0),
561 { CTRLI, 0x00},
562 { R_DVP_SP, 0 | R_DVP_SP_AUTO_MODE },
563 ENDMARKER,
564};
565
566#define OV2640_SIZE(n, w, h, r) \
567 {.name = n, .width = w , .height = h, .regs = r }
568
569static const struct ov2640_win_size ov2640_supported_win_sizes[] = {
570 OV2640_SIZE("QCIF", W_QCIF, H_QCIF, ov2640_qcif_regs),
571 OV2640_SIZE("QVGA", W_QVGA, H_QVGA, ov2640_qvga_regs),
572 OV2640_SIZE("CIF", W_CIF, H_CIF, ov2640_cif_regs),
573 OV2640_SIZE("VGA", W_VGA, H_VGA, ov2640_vga_regs),
574 OV2640_SIZE("SVGA", W_SVGA, H_SVGA, ov2640_svga_regs),
575 OV2640_SIZE("XGA", W_XGA, H_XGA, ov2640_xga_regs),
576 OV2640_SIZE("SXGA", W_SXGA, H_SXGA, ov2640_sxga_regs),
577 OV2640_SIZE("UXGA", W_UXGA, H_UXGA, ov2640_uxga_regs),
578};
579
580/*
581 * Register settings for pixel formats
582 */
583static const struct regval_list ov2640_format_change_preamble_regs[] = {
584 { BANK_SEL, BANK_SEL_DSP },
585 { R_BYPASS, R_BYPASS_USE_DSP },
586 ENDMARKER,
587};
588
589static const struct regval_list ov2640_yuv422_regs[] = {
590 { IMAGE_MODE, IMAGE_MODE_LBYTE_FIRST | IMAGE_MODE_YUV422 },
591 { 0xD7, 0x01 },
592 { 0x33, 0xa0 },
593 { 0xe1, 0x67 },
594 { RESET, 0x00 },
595 { R_BYPASS, R_BYPASS_USE_DSP },
596 ENDMARKER,
597};
598
599static const struct regval_list ov2640_rgb565_regs[] = {
600 { IMAGE_MODE, IMAGE_MODE_LBYTE_FIRST | IMAGE_MODE_RGB565 },
601 { 0xd7, 0x03 },
602 { RESET, 0x00 },
603 { R_BYPASS, R_BYPASS_USE_DSP },
604 ENDMARKER,
605};
606
607static enum v4l2_mbus_pixelcode ov2640_codes[] = {
608 V4L2_MBUS_FMT_UYVY8_2X8,
609 V4L2_MBUS_FMT_RGB565_2X8_LE,
610};
611
612/*
613 * Supported controls
614 */
615static const struct v4l2_queryctrl ov2640_controls[] = {
616 {
617 .id = V4L2_CID_VFLIP,
618 .type = V4L2_CTRL_TYPE_BOOLEAN,
619 .name = "Flip Vertically",
620 .minimum = 0,
621 .maximum = 1,
622 .step = 1,
623 .default_value = 0,
624 }, {
625 .id = V4L2_CID_HFLIP,
626 .type = V4L2_CTRL_TYPE_BOOLEAN,
627 .name = "Flip Horizontally",
628 .minimum = 0,
629 .maximum = 1,
630 .step = 1,
631 .default_value = 0,
632 },
633};
634
635/*
636 * General functions
637 */
638static struct ov2640_priv *to_ov2640(const struct i2c_client *client)
639{
640 return container_of(i2c_get_clientdata(client), struct ov2640_priv,
641 subdev);
642}
643
644static int ov2640_write_array(struct i2c_client *client,
645 const struct regval_list *vals)
646{
647 int ret;
648
649 while ((vals->reg_num != 0xff) || (vals->value != 0xff)) {
650 ret = i2c_smbus_write_byte_data(client,
651 vals->reg_num, vals->value);
652 dev_vdbg(&client->dev, "array: 0x%02x, 0x%02x",
653 vals->reg_num, vals->value);
654
655 if (ret < 0)
656 return ret;
657 vals++;
658 }
659 return 0;
660}
661
662static int ov2640_mask_set(struct i2c_client *client,
663 u8 reg, u8 mask, u8 set)
664{
665 s32 val = i2c_smbus_read_byte_data(client, reg);
666 if (val < 0)
667 return val;
668
669 val &= ~mask;
670 val |= set & mask;
671
672 dev_vdbg(&client->dev, "masks: 0x%02x, 0x%02x", reg, val);
673
674 return i2c_smbus_write_byte_data(client, reg, val);
675}
676
677static int ov2640_reset(struct i2c_client *client)
678{
679 int ret;
680 const struct regval_list reset_seq[] = {
681 {BANK_SEL, BANK_SEL_SENS},
682 {COM7, COM7_SRST},
683 ENDMARKER,
684 };
685
686 ret = ov2640_write_array(client, reset_seq);
687 if (ret)
688 goto err;
689
690 msleep(5);
691err:
692 dev_dbg(&client->dev, "%s: (ret %d)", __func__, ret);
693 return ret;
694}
695
696/*
697 * soc_camera_ops functions
698 */
699static int ov2640_s_stream(struct v4l2_subdev *sd, int enable)
700{
701 return 0;
702}
703
704static int ov2640_set_bus_param(struct soc_camera_device *icd,
705 unsigned long flags)
706{
707 struct soc_camera_link *icl = to_soc_camera_link(icd);
708 unsigned long width_flag = flags & SOCAM_DATAWIDTH_MASK;
709
710 /* Only one width bit may be set */
711 if (!is_power_of_2(width_flag))
712 return -EINVAL;
713
714 if (icl->set_bus_param)
715 return icl->set_bus_param(icl, width_flag);
716
717 /*
718 * Without board specific bus width settings we support only the
719 * sensors native bus width witch are tested working
720 */
721 if (width_flag & (SOCAM_DATAWIDTH_10 | SOCAM_DATAWIDTH_8))
722 return 0;
723
724 return 0;
725}
726
727static unsigned long ov2640_query_bus_param(struct soc_camera_device *icd)
728{
729 struct soc_camera_link *icl = to_soc_camera_link(icd);
730 unsigned long flags = SOCAM_PCLK_SAMPLE_RISING | SOCAM_MASTER |
731 SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_HIGH |
732 SOCAM_DATA_ACTIVE_HIGH;
733
734 if (icl->query_bus_param)
735 flags |= icl->query_bus_param(icl) & SOCAM_DATAWIDTH_MASK;
736 else
737 flags |= SOCAM_DATAWIDTH_10;
738
739 return soc_camera_apply_sensor_flags(icl, flags);
740}
741
742static int ov2640_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
743{
744 struct i2c_client *client = v4l2_get_subdevdata(sd);
745 struct ov2640_priv *priv = to_ov2640(client);
746
747 switch (ctrl->id) {
748 case V4L2_CID_VFLIP:
749 ctrl->value = priv->flag_vflip;
750 break;
751 case V4L2_CID_HFLIP:
752 ctrl->value = priv->flag_hflip;
753 break;
754 }
755 return 0;
756}
757
758static int ov2640_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
759{
760 struct i2c_client *client = v4l2_get_subdevdata(sd);
761 struct ov2640_priv *priv = to_ov2640(client);
762 int ret = 0;
763 u8 val;
764
765 switch (ctrl->id) {
766 case V4L2_CID_VFLIP:
767 val = ctrl->value ? REG04_VFLIP_IMG : 0x00;
768 priv->flag_vflip = ctrl->value ? 1 : 0;
769 ret = ov2640_mask_set(client, REG04, REG04_VFLIP_IMG, val);
770 break;
771 case V4L2_CID_HFLIP:
772 val = ctrl->value ? REG04_HFLIP_IMG : 0x00;
773 priv->flag_hflip = ctrl->value ? 1 : 0;
774 ret = ov2640_mask_set(client, REG04, REG04_HFLIP_IMG, val);
775 break;
776 }
777
778 return ret;
779}
780
781static int ov2640_g_chip_ident(struct v4l2_subdev *sd,
782 struct v4l2_dbg_chip_ident *id)
783{
784 struct i2c_client *client = v4l2_get_subdevdata(sd);
785 struct ov2640_priv *priv = to_ov2640(client);
786
787 id->ident = priv->model;
788 id->revision = 0;
789
790 return 0;
791}
792
793#ifdef CONFIG_VIDEO_ADV_DEBUG
794static int ov2640_g_register(struct v4l2_subdev *sd,
795 struct v4l2_dbg_register *reg)
796{
797 struct i2c_client *client = v4l2_get_subdevdata(sd);
798 int ret;
799
800 reg->size = 1;
801 if (reg->reg > 0xff)
802 return -EINVAL;
803
804 ret = i2c_smbus_read_byte_data(client, reg->reg);
805 if (ret < 0)
806 return ret;
807
808 reg->val = ret;
809
810 return 0;
811}
812
813static int ov2640_s_register(struct v4l2_subdev *sd,
814 struct v4l2_dbg_register *reg)
815{
816 struct i2c_client *client = v4l2_get_subdevdata(sd);
817
818 if (reg->reg > 0xff ||
819 reg->val > 0xff)
820 return -EINVAL;
821
822 return i2c_smbus_write_byte_data(client, reg->reg, reg->val);
823}
824#endif
825
826/* Select the nearest higher resolution for capture */
827static const struct ov2640_win_size *ov2640_select_win(u32 *width, u32 *height)
828{
829 int i, default_size = ARRAY_SIZE(ov2640_supported_win_sizes) - 1;
830
831 for (i = 0; i < ARRAY_SIZE(ov2640_supported_win_sizes); i++) {
832 if (ov2640_supported_win_sizes[i].width >= *width &&
833 ov2640_supported_win_sizes[i].height >= *height) {
834 *width = ov2640_supported_win_sizes[i].width;
835 *height = ov2640_supported_win_sizes[i].height;
836 return &ov2640_supported_win_sizes[i];
837 }
838 }
839
840 *width = ov2640_supported_win_sizes[default_size].width;
841 *height = ov2640_supported_win_sizes[default_size].height;
842 return &ov2640_supported_win_sizes[default_size];
843}
844
845static int ov2640_set_params(struct i2c_client *client, u32 *width, u32 *height,
846 enum v4l2_mbus_pixelcode code)
847{
848 struct ov2640_priv *priv = to_ov2640(client);
849 const struct regval_list *selected_cfmt_regs;
850 int ret;
851
852 /* select win */
853 priv->win = ov2640_select_win(width, height);
854
855 /* select format */
856 priv->cfmt_code = 0;
857 switch (code) {
858 case V4L2_MBUS_FMT_RGB565_2X8_LE:
859 dev_dbg(&client->dev, "%s: Selected cfmt RGB565", __func__);
860 selected_cfmt_regs = ov2640_rgb565_regs;
861 break;
862 default:
863 case V4L2_MBUS_FMT_UYVY8_2X8:
864 dev_dbg(&client->dev, "%s: Selected cfmt YUV422", __func__);
865 selected_cfmt_regs = ov2640_yuv422_regs;
866 }
867
868 /* reset hardware */
869 ov2640_reset(client);
870
871 /* initialize the sensor with default data */
872 dev_dbg(&client->dev, "%s: Init default", __func__);
873 ret = ov2640_write_array(client, ov2640_init_regs);
874 if (ret < 0)
875 goto err;
876
877 /* select preamble */
878 dev_dbg(&client->dev, "%s: Set size to %s", __func__, priv->win->name);
879 ret = ov2640_write_array(client, ov2640_size_change_preamble_regs);
880 if (ret < 0)
881 goto err;
882
883 /* set size win */
884 ret = ov2640_write_array(client, priv->win->regs);
885 if (ret < 0)
886 goto err;
887
888 /* cfmt preamble */
889 dev_dbg(&client->dev, "%s: Set cfmt", __func__);
890 ret = ov2640_write_array(client, ov2640_format_change_preamble_regs);
891 if (ret < 0)
892 goto err;
893
894 /* set cfmt */
895 ret = ov2640_write_array(client, selected_cfmt_regs);
896 if (ret < 0)
897 goto err;
898
899 priv->cfmt_code = code;
900 *width = priv->win->width;
901 *height = priv->win->height;
902
903 return 0;
904
905err:
906 dev_err(&client->dev, "%s: Error %d", __func__, ret);
907 ov2640_reset(client);
908 priv->win = NULL;
909
910 return ret;
911}
912
913static int ov2640_g_fmt(struct v4l2_subdev *sd,
914 struct v4l2_mbus_framefmt *mf)
915{
916 struct i2c_client *client = v4l2_get_subdevdata(sd);
917 struct ov2640_priv *priv = to_ov2640(client);
918
919 if (!priv->win) {
920 u32 width = W_SVGA, height = H_SVGA;
921 int ret = ov2640_set_params(client, &width, &height,
922 V4L2_MBUS_FMT_UYVY8_2X8);
923 if (ret < 0)
924 return ret;
925 }
926
927 mf->width = priv->win->width;
928 mf->height = priv->win->height;
929 mf->code = priv->cfmt_code;
930
931 switch (mf->code) {
932 case V4L2_MBUS_FMT_RGB565_2X8_LE:
933 mf->colorspace = V4L2_COLORSPACE_SRGB;
934 break;
935 default:
936 case V4L2_MBUS_FMT_UYVY8_2X8:
937 mf->colorspace = V4L2_COLORSPACE_JPEG;
938 }
939 mf->field = V4L2_FIELD_NONE;
940
941 return 0;
942}
943
944static int ov2640_s_fmt(struct v4l2_subdev *sd,
945 struct v4l2_mbus_framefmt *mf)
946{
947 struct i2c_client *client = v4l2_get_subdevdata(sd);
948 int ret;
949
950
951 switch (mf->code) {
952 case V4L2_MBUS_FMT_RGB565_2X8_LE:
953 mf->colorspace = V4L2_COLORSPACE_SRGB;
954 break;
955 default:
956 mf->code = V4L2_MBUS_FMT_UYVY8_2X8;
957 case V4L2_MBUS_FMT_UYVY8_2X8:
958 mf->colorspace = V4L2_COLORSPACE_JPEG;
959 }
960
961 ret = ov2640_set_params(client, &mf->width, &mf->height, mf->code);
962
963 return ret;
964}
965
966static int ov2640_try_fmt(struct v4l2_subdev *sd,
967 struct v4l2_mbus_framefmt *mf)
968{
969 const struct ov2640_win_size *win;
970
971 /*
972 * select suitable win
973 */
974 win = ov2640_select_win(&mf->width, &mf->height);
975
976 mf->field = V4L2_FIELD_NONE;
977
978 switch (mf->code) {
979 case V4L2_MBUS_FMT_RGB565_2X8_LE:
980 mf->colorspace = V4L2_COLORSPACE_SRGB;
981 break;
982 default:
983 mf->code = V4L2_MBUS_FMT_UYVY8_2X8;
984 case V4L2_MBUS_FMT_UYVY8_2X8:
985 mf->colorspace = V4L2_COLORSPACE_JPEG;
986 }
987
988 return 0;
989}
990
991static int ov2640_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
992 enum v4l2_mbus_pixelcode *code)
993{
994 if (index >= ARRAY_SIZE(ov2640_codes))
995 return -EINVAL;
996
997 *code = ov2640_codes[index];
998 return 0;
999}
1000
1001static int ov2640_g_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
1002{
1003 a->c.left = 0;
1004 a->c.top = 0;
1005 a->c.width = W_UXGA;
1006 a->c.height = H_UXGA;
1007 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1008
1009 return 0;
1010}
1011
1012static int ov2640_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap *a)
1013{
1014 a->bounds.left = 0;
1015 a->bounds.top = 0;
1016 a->bounds.width = W_UXGA;
1017 a->bounds.height = H_UXGA;
1018 a->defrect = a->bounds;
1019 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1020 a->pixelaspect.numerator = 1;
1021 a->pixelaspect.denominator = 1;
1022
1023 return 0;
1024}
1025
1026static int ov2640_video_probe(struct soc_camera_device *icd,
1027 struct i2c_client *client)
1028{
1029 struct ov2640_priv *priv = to_ov2640(client);
1030 u8 pid, ver, midh, midl;
1031 const char *devname;
1032 int ret;
1033
1034 /*
1035 * we must have a parent by now. And it cannot be a wrong one.
1036 * So this entire test is completely redundant.
1037 */
1038 if (!icd->dev.parent ||
1039 to_soc_camera_host(icd->dev.parent)->nr != icd->iface) {
1040 dev_err(&client->dev, "Parent missing or invalid!\n");
1041 ret = -ENODEV;
1042 goto err;
1043 }
1044
1045 /*
1046 * check and show product ID and manufacturer ID
1047 */
1048 i2c_smbus_write_byte_data(client, BANK_SEL, BANK_SEL_SENS);
1049 pid = i2c_smbus_read_byte_data(client, PID);
1050 ver = i2c_smbus_read_byte_data(client, VER);
1051 midh = i2c_smbus_read_byte_data(client, MIDH);
1052 midl = i2c_smbus_read_byte_data(client, MIDL);
1053
1054 switch (VERSION(pid, ver)) {
1055 case PID_OV2640:
1056 devname = "ov2640";
1057 priv->model = V4L2_IDENT_OV2640;
1058 break;
1059 default:
1060 dev_err(&client->dev,
1061 "Product ID error %x:%x\n", pid, ver);
1062 ret = -ENODEV;
1063 goto err;
1064 }
1065
1066 dev_info(&client->dev,
1067 "%s Product ID %0x:%0x Manufacturer ID %x:%x\n",
1068 devname, pid, ver, midh, midl);
1069
1070 return 0;
1071
1072err:
1073 return ret;
1074}
1075
1076static struct soc_camera_ops ov2640_ops = {
1077 .set_bus_param = ov2640_set_bus_param,
1078 .query_bus_param = ov2640_query_bus_param,
1079 .controls = ov2640_controls,
1080 .num_controls = ARRAY_SIZE(ov2640_controls),
1081};
1082
1083static struct v4l2_subdev_core_ops ov2640_subdev_core_ops = {
1084 .g_ctrl = ov2640_g_ctrl,
1085 .s_ctrl = ov2640_s_ctrl,
1086 .g_chip_ident = ov2640_g_chip_ident,
1087#ifdef CONFIG_VIDEO_ADV_DEBUG
1088 .g_register = ov2640_g_register,
1089 .s_register = ov2640_s_register,
1090#endif
1091};
1092
1093static struct v4l2_subdev_video_ops ov2640_subdev_video_ops = {
1094 .s_stream = ov2640_s_stream,
1095 .g_mbus_fmt = ov2640_g_fmt,
1096 .s_mbus_fmt = ov2640_s_fmt,
1097 .try_mbus_fmt = ov2640_try_fmt,
1098 .cropcap = ov2640_cropcap,
1099 .g_crop = ov2640_g_crop,
1100 .enum_mbus_fmt = ov2640_enum_fmt,
1101};
1102
1103static struct v4l2_subdev_ops ov2640_subdev_ops = {
1104 .core = &ov2640_subdev_core_ops,
1105 .video = &ov2640_subdev_video_ops,
1106};
1107
1108/*
1109 * i2c_driver functions
1110 */
1111static int ov2640_probe(struct i2c_client *client,
1112 const struct i2c_device_id *did)
1113{
1114 struct ov2640_priv *priv;
1115 struct soc_camera_device *icd = client->dev.platform_data;
1116 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
1117 struct soc_camera_link *icl;
1118 int ret;
1119
1120 if (!icd) {
1121 dev_err(&adapter->dev, "OV2640: missing soc-camera data!\n");
1122 return -EINVAL;
1123 }
1124
1125 icl = to_soc_camera_link(icd);
1126 if (!icl) {
1127 dev_err(&adapter->dev,
1128 "OV2640: Missing platform_data for driver\n");
1129 return -EINVAL;
1130 }
1131
1132 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
1133 dev_err(&adapter->dev,
1134 "OV2640: I2C-Adapter doesn't support SMBUS\n");
1135 return -EIO;
1136 }
1137
1138 priv = kzalloc(sizeof(struct ov2640_priv), GFP_KERNEL);
1139 if (!priv) {
1140 dev_err(&adapter->dev,
1141 "Failed to allocate memory for private data!\n");
1142 return -ENOMEM;
1143 }
1144
1145 priv->info = icl->priv;
1146
1147 v4l2_i2c_subdev_init(&priv->subdev, client, &ov2640_subdev_ops);
1148
1149 icd->ops = &ov2640_ops;
1150
1151 ret = ov2640_video_probe(icd, client);
1152 if (ret) {
1153 icd->ops = NULL;
1154 kfree(priv);
1155 } else {
1156 dev_info(&adapter->dev, "OV2640 Probed\n");
1157 }
1158
1159 return ret;
1160}
1161
1162static int ov2640_remove(struct i2c_client *client)
1163{
1164 struct ov2640_priv *priv = to_ov2640(client);
1165 struct soc_camera_device *icd = client->dev.platform_data;
1166
1167 icd->ops = NULL;
1168 kfree(priv);
1169 return 0;
1170}
1171
1172static const struct i2c_device_id ov2640_id[] = {
1173 { "ov2640", 0 },
1174 { }
1175};
1176MODULE_DEVICE_TABLE(i2c, ov2640_id);
1177
1178static struct i2c_driver ov2640_i2c_driver = {
1179 .driver = {
1180 .name = "ov2640",
1181 },
1182 .probe = ov2640_probe,
1183 .remove = ov2640_remove,
1184 .id_table = ov2640_id,
1185};
1186
1187/*
1188 * Module functions
1189 */
1190static int __init ov2640_module_init(void)
1191{
1192 return i2c_add_driver(&ov2640_i2c_driver);
1193}
1194
1195static void __exit ov2640_module_exit(void)
1196{
1197 i2c_del_driver(&ov2640_i2c_driver);
1198}
1199
1200module_init(ov2640_module_init);
1201module_exit(ov2640_module_exit);
1202
1203MODULE_DESCRIPTION("SoC Camera driver for Omni Vision 2640 sensor");
1204MODULE_AUTHOR("Alberto Panizzo");
1205MODULE_LICENSE("GPL v2");
diff --git a/drivers/media/video/ov772x.c b/drivers/media/video/ov772x.c
index a84b770352f9..48895ef863ff 100644
--- a/drivers/media/video/ov772x.c
+++ b/drivers/media/video/ov772x.c
@@ -600,7 +600,7 @@ static int ov772x_reset(struct i2c_client *client)
600static int ov772x_s_stream(struct v4l2_subdev *sd, int enable) 600static int ov772x_s_stream(struct v4l2_subdev *sd, int enable)
601{ 601{
602 struct i2c_client *client = v4l2_get_subdevdata(sd); 602 struct i2c_client *client = v4l2_get_subdevdata(sd);
603 struct ov772x_priv *priv = to_ov772x(client); 603 struct ov772x_priv *priv = container_of(sd, struct ov772x_priv, subdev);
604 604
605 if (!enable) { 605 if (!enable) {
606 ov772x_mask_set(client, COM2, SOFT_SLEEP_MODE, SOFT_SLEEP_MODE); 606 ov772x_mask_set(client, COM2, SOFT_SLEEP_MODE, SOFT_SLEEP_MODE);
@@ -645,8 +645,7 @@ static unsigned long ov772x_query_bus_param(struct soc_camera_device *icd)
645 645
646static int ov772x_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 646static int ov772x_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
647{ 647{
648 struct i2c_client *client = v4l2_get_subdevdata(sd); 648 struct ov772x_priv *priv = container_of(sd, struct ov772x_priv, subdev);
649 struct ov772x_priv *priv = to_ov772x(client);
650 649
651 switch (ctrl->id) { 650 switch (ctrl->id) {
652 case V4L2_CID_VFLIP: 651 case V4L2_CID_VFLIP:
@@ -665,7 +664,7 @@ static int ov772x_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
665static int ov772x_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 664static int ov772x_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
666{ 665{
667 struct i2c_client *client = v4l2_get_subdevdata(sd); 666 struct i2c_client *client = v4l2_get_subdevdata(sd);
668 struct ov772x_priv *priv = to_ov772x(client); 667 struct ov772x_priv *priv = container_of(sd, struct ov772x_priv, subdev);
669 int ret = 0; 668 int ret = 0;
670 u8 val; 669 u8 val;
671 670
@@ -715,8 +714,7 @@ static int ov772x_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
715static int ov772x_g_chip_ident(struct v4l2_subdev *sd, 714static int ov772x_g_chip_ident(struct v4l2_subdev *sd,
716 struct v4l2_dbg_chip_ident *id) 715 struct v4l2_dbg_chip_ident *id)
717{ 716{
718 struct i2c_client *client = v4l2_get_subdevdata(sd); 717 struct ov772x_priv *priv = container_of(sd, struct ov772x_priv, subdev);
719 struct ov772x_priv *priv = to_ov772x(client);
720 718
721 id->ident = priv->model; 719 id->ident = priv->model;
722 id->revision = 0; 720 id->revision = 0;
@@ -955,7 +953,7 @@ static int ov772x_g_fmt(struct v4l2_subdev *sd,
955 struct v4l2_mbus_framefmt *mf) 953 struct v4l2_mbus_framefmt *mf)
956{ 954{
957 struct i2c_client *client = v4l2_get_subdevdata(sd); 955 struct i2c_client *client = v4l2_get_subdevdata(sd);
958 struct ov772x_priv *priv = to_ov772x(client); 956 struct ov772x_priv *priv = container_of(sd, struct ov772x_priv, subdev);
959 957
960 if (!priv->win || !priv->cfmt) { 958 if (!priv->win || !priv->cfmt) {
961 u32 width = VGA_WIDTH, height = VGA_HEIGHT; 959 u32 width = VGA_WIDTH, height = VGA_HEIGHT;
@@ -978,7 +976,7 @@ static int ov772x_s_fmt(struct v4l2_subdev *sd,
978 struct v4l2_mbus_framefmt *mf) 976 struct v4l2_mbus_framefmt *mf)
979{ 977{
980 struct i2c_client *client = v4l2_get_subdevdata(sd); 978 struct i2c_client *client = v4l2_get_subdevdata(sd);
981 struct ov772x_priv *priv = to_ov772x(client); 979 struct ov772x_priv *priv = container_of(sd, struct ov772x_priv, subdev);
982 int ret = ov772x_set_params(client, &mf->width, &mf->height, 980 int ret = ov772x_set_params(client, &mf->width, &mf->height,
983 mf->code); 981 mf->code);
984 982
@@ -991,8 +989,7 @@ static int ov772x_s_fmt(struct v4l2_subdev *sd,
991static int ov772x_try_fmt(struct v4l2_subdev *sd, 989static int ov772x_try_fmt(struct v4l2_subdev *sd,
992 struct v4l2_mbus_framefmt *mf) 990 struct v4l2_mbus_framefmt *mf)
993{ 991{
994 struct i2c_client *client = v4l2_get_subdevdata(sd); 992 struct ov772x_priv *priv = container_of(sd, struct ov772x_priv, subdev);
995 struct ov772x_priv *priv = to_ov772x(client);
996 const struct ov772x_win_size *win; 993 const struct ov772x_win_size *win;
997 int i; 994 int i;
998 995
diff --git a/drivers/media/video/ov9640.c b/drivers/media/video/ov9640.c
index 99e9e1d3c83b..53d88a2ab920 100644
--- a/drivers/media/video/ov9640.c
+++ b/drivers/media/video/ov9640.c
@@ -31,6 +31,8 @@
31 31
32#include "ov9640.h" 32#include "ov9640.h"
33 33
34#define to_ov9640_sensor(sd) container_of(sd, struct ov9640_priv, subdev)
35
34/* default register setup */ 36/* default register setup */
35static const struct ov9640_reg ov9640_regs_dflt[] = { 37static const struct ov9640_reg ov9640_regs_dflt[] = {
36 { OV9640_COM5, OV9640_COM5_SYSCLK | OV9640_COM5_LONGEXP }, 38 { OV9640_COM5, OV9640_COM5_SYSCLK | OV9640_COM5_LONGEXP },
@@ -308,9 +310,7 @@ static unsigned long ov9640_query_bus_param(struct soc_camera_device *icd)
308/* Get status of additional camera capabilities */ 310/* Get status of additional camera capabilities */
309static int ov9640_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 311static int ov9640_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
310{ 312{
311 struct i2c_client *client = v4l2_get_subdevdata(sd); 313 struct ov9640_priv *priv = to_ov9640_sensor(sd);
312 struct ov9640_priv *priv = container_of(i2c_get_clientdata(client),
313 struct ov9640_priv, subdev);
314 314
315 switch (ctrl->id) { 315 switch (ctrl->id) {
316 case V4L2_CID_VFLIP: 316 case V4L2_CID_VFLIP:
@@ -327,8 +327,7 @@ static int ov9640_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
327static int ov9640_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 327static int ov9640_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
328{ 328{
329 struct i2c_client *client = v4l2_get_subdevdata(sd); 329 struct i2c_client *client = v4l2_get_subdevdata(sd);
330 struct ov9640_priv *priv = container_of(i2c_get_clientdata(client), 330 struct ov9640_priv *priv = to_ov9640_sensor(sd);
331 struct ov9640_priv, subdev);
332 331
333 int ret = 0; 332 int ret = 0;
334 333
@@ -360,9 +359,7 @@ static int ov9640_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
360static int ov9640_g_chip_ident(struct v4l2_subdev *sd, 359static int ov9640_g_chip_ident(struct v4l2_subdev *sd,
361 struct v4l2_dbg_chip_ident *id) 360 struct v4l2_dbg_chip_ident *id)
362{ 361{
363 struct i2c_client *client = v4l2_get_subdevdata(sd); 362 struct ov9640_priv *priv = to_ov9640_sensor(sd);
364 struct ov9640_priv *priv = container_of(i2c_get_clientdata(client),
365 struct ov9640_priv, subdev);
366 363
367 id->ident = priv->model; 364 id->ident = priv->model;
368 id->revision = priv->revision; 365 id->revision = priv->revision;
@@ -654,7 +651,8 @@ static int ov9640_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap *a)
654static int ov9640_video_probe(struct soc_camera_device *icd, 651static int ov9640_video_probe(struct soc_camera_device *icd,
655 struct i2c_client *client) 652 struct i2c_client *client)
656{ 653{
657 struct ov9640_priv *priv = i2c_get_clientdata(client); 654 struct v4l2_subdev *sd = i2c_get_clientdata(client);
655 struct ov9640_priv *priv = to_ov9640_sensor(sd);
658 u8 pid, ver, midh, midl; 656 u8 pid, ver, midh, midl;
659 const char *devname; 657 const char *devname;
660 int ret = 0; 658 int ret = 0;
@@ -791,7 +789,8 @@ static int ov9640_probe(struct i2c_client *client,
791 789
792static int ov9640_remove(struct i2c_client *client) 790static int ov9640_remove(struct i2c_client *client)
793{ 791{
794 struct ov9640_priv *priv = i2c_get_clientdata(client); 792 struct v4l2_subdev *sd = i2c_get_clientdata(client);
793 struct ov9640_priv *priv = to_ov9640_sensor(sd);
795 794
796 kfree(priv); 795 kfree(priv);
797 return 0; 796 return 0;
diff --git a/drivers/media/video/pvrusb2/pvrusb2-ctrl.c b/drivers/media/video/pvrusb2/pvrusb2-ctrl.c
index 55ea914c7fcd..7d5a7139a45a 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-ctrl.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-ctrl.c
@@ -203,7 +203,7 @@ int pvr2_ctrl_get_valname(struct pvr2_ctrl *cptr,int val,
203 *blen = 0; 203 *blen = 0;
204 LOCK_TAKE(cptr->hdw->big_lock); do { 204 LOCK_TAKE(cptr->hdw->big_lock); do {
205 if (cptr->info->type == pvr2_ctl_enum) { 205 if (cptr->info->type == pvr2_ctl_enum) {
206 const char **names; 206 const char * const *names;
207 names = cptr->info->def.type_enum.value_names; 207 names = cptr->info->def.type_enum.value_names;
208 if (pvr2_ctrl_range_check(cptr,val) == 0) { 208 if (pvr2_ctrl_range_check(cptr,val) == 0) {
209 if (names[val]) { 209 if (names[val]) {
@@ -367,7 +367,7 @@ static const char *boolNames[] = {
367 367
368static int parse_token(const char *ptr,unsigned int len, 368static int parse_token(const char *ptr,unsigned int len,
369 int *valptr, 369 int *valptr,
370 const char **names,unsigned int namecnt) 370 const char * const *names, unsigned int namecnt)
371{ 371{
372 char buf[33]; 372 char buf[33];
373 unsigned int slen; 373 unsigned int slen;
@@ -559,7 +559,7 @@ int pvr2_ctrl_value_to_sym_internal(struct pvr2_ctrl *cptr,
559 *len = scnprintf(buf,maxlen,"%s",val ? "true" : "false"); 559 *len = scnprintf(buf,maxlen,"%s",val ? "true" : "false");
560 ret = 0; 560 ret = 0;
561 } else if (cptr->info->type == pvr2_ctl_enum) { 561 } else if (cptr->info->type == pvr2_ctl_enum) {
562 const char **names; 562 const char * const *names;
563 names = cptr->info->def.type_enum.value_names; 563 names = cptr->info->def.type_enum.value_names;
564 if ((val >= 0) && 564 if ((val >= 0) &&
565 (val < cptr->info->def.type_enum.count)) { 565 (val < cptr->info->def.type_enum.count)) {
diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
index cb4057bb07a0..ac94a8bf883e 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
@@ -115,7 +115,7 @@ struct pvr2_ctl_info {
115 } type_int; 115 } type_int;
116 struct { /* enumerated control */ 116 struct { /* enumerated control */
117 unsigned int count; /* enum value count */ 117 unsigned int count; /* enum value count */
118 const char **value_names; /* symbol names */ 118 const char * const *value_names; /* symbol names */
119 } type_enum; 119 } type_enum;
120 struct { /* bitmask control */ 120 struct { /* bitmask control */
121 unsigned int valid_bits; /* bits in use */ 121 unsigned int valid_bits; /* bits in use */
diff --git a/drivers/media/video/pvrusb2/pvrusb2-sysfs.c b/drivers/media/video/pvrusb2/pvrusb2-sysfs.c
index 3d7e5aab547f..281806b2df62 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-sysfs.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-sysfs.c
@@ -647,7 +647,7 @@ static void class_dev_create(struct pvr2_sysfs *sfp,
647 if (ret) { 647 if (ret) {
648 pvr2_trace(PVR2_TRACE_ERROR_LEGS, 648 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
649 "device_register failed"); 649 "device_register failed");
650 kfree(class_dev); 650 put_device(class_dev);
651 return; 651 return;
652 } 652 }
653 653
diff --git a/drivers/media/video/pvrusb2/pvrusb2-v4l2.c b/drivers/media/video/pvrusb2/pvrusb2-v4l2.c
index aaafa0398fd5..58617fc656c2 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-v4l2.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-v4l2.c
@@ -852,8 +852,8 @@ static long pvr2_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
852#endif 852#endif
853 853
854 default : 854 default :
855 ret = v4l_compat_translate_ioctl(file, cmd, 855 ret = -EINVAL;
856 arg, pvr2_v4l2_do_ioctl); 856 break;
857 } 857 }
858 858
859 pvr2_hdw_commit_ctl(hdw); 859 pvr2_hdw_commit_ctl(hdw);
diff --git a/drivers/media/video/pwc/pwc-ctrl.c b/drivers/media/video/pwc/pwc-ctrl.c
index 6b8fbddc0747..1593f8deb810 100644
--- a/drivers/media/video/pwc/pwc-ctrl.c
+++ b/drivers/media/video/pwc/pwc-ctrl.c
@@ -1386,11 +1386,16 @@ long pwc_ioctl(struct pwc_device *pdev, unsigned int cmd, void *arg)
1386 { 1386 {
1387 ARG_DEF(int, qual) 1387 ARG_DEF(int, qual)
1388 1388
1389 if (pdev->iso_init) {
1390 ret = -EBUSY;
1391 break;
1392 }
1393
1389 ARG_IN(qual) 1394 ARG_IN(qual)
1390 if (ARGR(qual) < 0 || ARGR(qual) > 3) 1395 if (ARGR(qual) < 0 || ARGR(qual) > 3)
1391 ret = -EINVAL; 1396 ret = -EINVAL;
1392 else 1397 else
1393 ret = pwc_try_video_mode(pdev, pdev->view.x, pdev->view.y, pdev->vframes, ARGR(qual), pdev->vsnapshot); 1398 ret = pwc_set_video_mode(pdev, pdev->view.x, pdev->view.y, pdev->vframes, ARGR(qual), pdev->vsnapshot);
1394 if (ret >= 0) 1399 if (ret >= 0)
1395 pdev->vcompression = ARGR(qual); 1400 pdev->vcompression = ARGR(qual);
1396 break; 1401 break;
diff --git a/drivers/media/video/pwc/pwc-if.c b/drivers/media/video/pwc/pwc-if.c
index f3dc89da4c4e..bd1519a4ecb4 100644
--- a/drivers/media/video/pwc/pwc-if.c
+++ b/drivers/media/video/pwc/pwc-if.c
@@ -287,14 +287,13 @@ static int pwc_allocate_buffers(struct pwc_device *pdev)
287 /* create frame buffers, and make circular ring */ 287 /* create frame buffers, and make circular ring */
288 for (i = 0; i < default_fbufs; i++) { 288 for (i = 0; i < default_fbufs; i++) {
289 if (pdev->fbuf[i].data == NULL) { 289 if (pdev->fbuf[i].data == NULL) {
290 kbuf = vmalloc(PWC_FRAME_SIZE); /* need vmalloc since frame buffer > 128K */ 290 kbuf = vzalloc(PWC_FRAME_SIZE); /* need vmalloc since frame buffer > 128K */
291 if (kbuf == NULL) { 291 if (kbuf == NULL) {
292 PWC_ERROR("Failed to allocate frame buffer %d.\n", i); 292 PWC_ERROR("Failed to allocate frame buffer %d.\n", i);
293 return -ENOMEM; 293 return -ENOMEM;
294 } 294 }
295 PWC_DEBUG_MEMORY("Allocated frame buffer %d at %p.\n", i, kbuf); 295 PWC_DEBUG_MEMORY("Allocated frame buffer %d at %p.\n", i, kbuf);
296 pdev->fbuf[i].data = kbuf; 296 pdev->fbuf[i].data = kbuf;
297 memset(kbuf, 0, PWC_FRAME_SIZE);
298 } 297 }
299 } 298 }
300 299
@@ -899,10 +898,13 @@ int pwc_isoc_init(struct pwc_device *pdev)
899 /* link */ 898 /* link */
900 for (i = 0; i < MAX_ISO_BUFS; i++) { 899 for (i = 0; i < MAX_ISO_BUFS; i++) {
901 ret = usb_submit_urb(pdev->sbuf[i].urb, GFP_KERNEL); 900 ret = usb_submit_urb(pdev->sbuf[i].urb, GFP_KERNEL);
902 if (ret) 901 if (ret) {
903 PWC_ERROR("isoc_init() submit_urb %d failed with error %d\n", i, ret); 902 PWC_ERROR("isoc_init() submit_urb %d failed with error %d\n", i, ret);
904 else 903 pdev->iso_init = 1;
905 PWC_DEBUG_MEMORY("URB 0x%p submitted.\n", pdev->sbuf[i].urb); 904 pwc_isoc_cleanup(pdev);
905 return ret;
906 }
907 PWC_DEBUG_MEMORY("URB 0x%p submitted.\n", pdev->sbuf[i].urb);
906 } 908 }
907 909
908 /* All is done... */ 910 /* All is done... */
@@ -958,7 +960,7 @@ void pwc_isoc_cleanup(struct pwc_device *pdev)
958 /* Stop camera, but only if we are sure the camera is still there (unplug 960 /* Stop camera, but only if we are sure the camera is still there (unplug
959 is signalled by EPIPE) 961 is signalled by EPIPE)
960 */ 962 */
961 if (pdev->error_status && pdev->error_status != EPIPE) { 963 if (pdev->error_status != EPIPE) {
962 PWC_DEBUG_OPEN("Setting alternate interface 0.\n"); 964 PWC_DEBUG_OPEN("Setting alternate interface 0.\n");
963 usb_set_interface(pdev->udev, 0, 0); 965 usb_set_interface(pdev->udev, 0, 0);
964 } 966 }
@@ -967,36 +969,6 @@ void pwc_isoc_cleanup(struct pwc_device *pdev)
967 PWC_DEBUG_OPEN("<< pwc_isoc_cleanup()\n"); 969 PWC_DEBUG_OPEN("<< pwc_isoc_cleanup()\n");
968} 970}
969 971
970int pwc_try_video_mode(struct pwc_device *pdev, int width, int height, int new_fps, int new_compression, int new_snapshot)
971{
972 int ret, start;
973
974 /* Stop isoc stuff */
975 pwc_isoc_cleanup(pdev);
976 /* Reset parameters */
977 pwc_reset_buffers(pdev);
978 /* Try to set video mode... */
979 start = ret = pwc_set_video_mode(pdev, width, height, new_fps, new_compression, new_snapshot);
980 if (ret) {
981 PWC_DEBUG_FLOW("pwc_set_video_mode attempt 1 failed.\n");
982 /* That failed... restore old mode (we know that worked) */
983 start = pwc_set_video_mode(pdev, pdev->view.x, pdev->view.y, pdev->vframes, pdev->vcompression, pdev->vsnapshot);
984 if (start) {
985 PWC_DEBUG_FLOW("pwc_set_video_mode attempt 2 failed.\n");
986 }
987 }
988 if (start == 0)
989 {
990 if (pwc_isoc_init(pdev) < 0)
991 {
992 PWC_WARNING("Failed to restart ISOC transfers in pwc_try_video_mode.\n");
993 ret = -EAGAIN; /* let's try again, who knows if it works a second time */
994 }
995 }
996 pdev->drop_frames++; /* try to avoid garbage during switch */
997 return ret; /* Return original error code */
998}
999
1000/********* 972/*********
1001 * sysfs 973 * sysfs
1002 *********/ 974 *********/
@@ -1176,7 +1148,7 @@ static int pwc_video_open(struct file *file)
1176 /* Set some defaults */ 1148 /* Set some defaults */
1177 pdev->vsnapshot = 0; 1149 pdev->vsnapshot = 0;
1178 1150
1179 /* Start iso pipe for video; first try the last used video size 1151 /* Set video size, first try the last used video size
1180 (or the default one); if that fails try QCIF/10 or QSIF/10; 1152 (or the default one); if that fails try QCIF/10 or QSIF/10;
1181 it that fails too, give up. 1153 it that fails too, give up.
1182 */ 1154 */
@@ -1203,15 +1175,6 @@ static int pwc_video_open(struct file *file)
1203 return i; 1175 return i;
1204 } 1176 }
1205 1177
1206 i = pwc_isoc_init(pdev);
1207 if (i) {
1208 PWC_DEBUG_OPEN("Failed to init ISOC stuff = %d.\n", i);
1209 pwc_isoc_cleanup(pdev);
1210 pwc_free_buffers(pdev);
1211 mutex_unlock(&pdev->modlock);
1212 return i;
1213 }
1214
1215 /* Initialize the webcam to sane value */ 1178 /* Initialize the webcam to sane value */
1216 pwc_set_brightness(pdev, 0x7fff); 1179 pwc_set_brightness(pdev, 0x7fff);
1217 pwc_set_agc(pdev, 1, 0); 1180 pwc_set_agc(pdev, 1, 0);
@@ -1326,6 +1289,11 @@ static ssize_t pwc_video_read(struct file *file, char __user *buf,
1326 goto err_out; 1289 goto err_out;
1327 } 1290 }
1328 1291
1292 /* Start the stream (if not already started) */
1293 rv = pwc_isoc_init(pdev);
1294 if (rv)
1295 goto err_out;
1296
1329 /* In case we're doing partial reads, we don't have to wait for a frame */ 1297 /* In case we're doing partial reads, we don't have to wait for a frame */
1330 if (pdev->image_read_pos == 0) { 1298 if (pdev->image_read_pos == 0) {
1331 /* Do wait queueing according to the (doc)book */ 1299 /* Do wait queueing according to the (doc)book */
@@ -1395,6 +1363,7 @@ static unsigned int pwc_video_poll(struct file *file, poll_table *wait)
1395{ 1363{
1396 struct video_device *vdev = file->private_data; 1364 struct video_device *vdev = file->private_data;
1397 struct pwc_device *pdev; 1365 struct pwc_device *pdev;
1366 int ret;
1398 1367
1399 if (vdev == NULL) 1368 if (vdev == NULL)
1400 return -EFAULT; 1369 return -EFAULT;
@@ -1402,6 +1371,13 @@ static unsigned int pwc_video_poll(struct file *file, poll_table *wait)
1402 if (pdev == NULL) 1371 if (pdev == NULL)
1403 return -EFAULT; 1372 return -EFAULT;
1404 1373
1374 /* Start the stream (if not already started) */
1375 mutex_lock(&pdev->modlock);
1376 ret = pwc_isoc_init(pdev);
1377 mutex_unlock(&pdev->modlock);
1378 if (ret)
1379 return ret;
1380
1405 poll_wait(file, &pdev->frameq, wait); 1381 poll_wait(file, &pdev->frameq, wait);
1406 if (pdev->error_status) 1382 if (pdev->error_status)
1407 return POLLERR; 1383 return POLLERR;
diff --git a/drivers/media/video/pwc/pwc-v4l.c b/drivers/media/video/pwc/pwc-v4l.c
index 7061a03f5cf1..8ca4d22b4384 100644
--- a/drivers/media/video/pwc/pwc-v4l.c
+++ b/drivers/media/video/pwc/pwc-v4l.c
@@ -309,7 +309,10 @@ static int pwc_vidioc_set_fmt(struct pwc_device *pdev, struct v4l2_format *f)
309 pixelformat != V4L2_PIX_FMT_PWC2) 309 pixelformat != V4L2_PIX_FMT_PWC2)
310 return -EINVAL; 310 return -EINVAL;
311 311
312 PWC_DEBUG_IOCTL("Try to change format to: width=%d height=%d fps=%d " 312 if (pdev->iso_init)
313 return -EBUSY;
314
315 PWC_DEBUG_IOCTL("Trying to set format to: width=%d height=%d fps=%d "
313 "compression=%d snapshot=%d format=%c%c%c%c\n", 316 "compression=%d snapshot=%d format=%c%c%c%c\n",
314 f->fmt.pix.width, f->fmt.pix.height, fps, 317 f->fmt.pix.width, f->fmt.pix.height, fps,
315 compression, snapshot, 318 compression, snapshot,
@@ -318,14 +321,14 @@ static int pwc_vidioc_set_fmt(struct pwc_device *pdev, struct v4l2_format *f)
318 (pixelformat>>16)&255, 321 (pixelformat>>16)&255,
319 (pixelformat>>24)&255); 322 (pixelformat>>24)&255);
320 323
321 ret = pwc_try_video_mode(pdev, 324 ret = pwc_set_video_mode(pdev,
322 f->fmt.pix.width, 325 f->fmt.pix.width,
323 f->fmt.pix.height, 326 f->fmt.pix.height,
324 fps, 327 fps,
325 compression, 328 compression,
326 snapshot); 329 snapshot);
327 330
328 PWC_DEBUG_IOCTL("pwc_try_video_mode(), return=%d\n", ret); 331 PWC_DEBUG_IOCTL("pwc_set_video_mode(), return=%d\n", ret);
329 332
330 if (ret) 333 if (ret)
331 return ret; 334 return ret;
@@ -359,23 +362,6 @@ long pwc_video_do_ioctl(struct file *file, unsigned int cmd, void *arg)
359 362
360 363
361 switch (cmd) { 364 switch (cmd) {
362#ifdef CONFIG_VIDEO_V4L1_COMPAT
363 /* mmap() functions */
364 case VIDIOCGMBUF:
365 {
366 /* Tell the user program how much memory is needed for a mmap() */
367 struct video_mbuf *vm = arg;
368 int i;
369
370 memset(vm, 0, sizeof(*vm));
371 vm->size = pwc_mbufs * pdev->len_per_image;
372 vm->frames = pwc_mbufs; /* double buffering should be enough for most applications */
373 for (i = 0; i < pwc_mbufs; i++)
374 vm->offsets[i] = i * pdev->len_per_image;
375 break;
376 }
377#endif
378
379 /* V4L2 Layer */ 365 /* V4L2 Layer */
380 case VIDIOC_QUERYCAP: 366 case VIDIOC_QUERYCAP:
381 { 367 {
@@ -882,9 +868,7 @@ long pwc_video_do_ioctl(struct file *file, unsigned int cmd, void *arg)
882 868
883 case VIDIOC_STREAMON: 869 case VIDIOC_STREAMON:
884 { 870 {
885 /* WARNING: pwc_try_video_mode() called pwc_isoc_init */ 871 return pwc_isoc_init(pdev);
886 pwc_isoc_init(pdev);
887 return 0;
888 } 872 }
889 873
890 case VIDIOC_STREAMOFF: 874 case VIDIOC_STREAMOFF:
diff --git a/drivers/media/video/pwc/pwc.h b/drivers/media/video/pwc/pwc.h
index 36a9c83b5f5d..16bbc6df9b07 100644
--- a/drivers/media/video/pwc/pwc.h
+++ b/drivers/media/video/pwc/pwc.h
@@ -275,7 +275,6 @@ extern int pwc_trace;
275extern int pwc_mbufs; 275extern int pwc_mbufs;
276 276
277/** functions in pwc-if.c */ 277/** functions in pwc-if.c */
278int pwc_try_video_mode(struct pwc_device *pdev, int width, int height, int new_fps, int new_compression, int new_snapshot);
279int pwc_handle_frame(struct pwc_device *pdev); 278int pwc_handle_frame(struct pwc_device *pdev);
280void pwc_next_image(struct pwc_device *pdev); 279void pwc_next_image(struct pwc_device *pdev);
281int pwc_isoc_init(struct pwc_device *pdev); 280int pwc_isoc_init(struct pwc_device *pdev);
diff --git a/drivers/media/video/pxa_camera.c b/drivers/media/video/pxa_camera.c
index c143ed0a5270..02686771740d 100644
--- a/drivers/media/video/pxa_camera.c
+++ b/drivers/media/video/pxa_camera.c
@@ -852,7 +852,7 @@ static void pxa_camera_init_videobuf(struct videobuf_queue *q,
852 */ 852 */
853 videobuf_queue_sg_init(q, &pxa_videobuf_ops, NULL, &pcdev->lock, 853 videobuf_queue_sg_init(q, &pxa_videobuf_ops, NULL, &pcdev->lock,
854 V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_NONE, 854 V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_NONE,
855 sizeof(struct pxa_buffer), icd, NULL); 855 sizeof(struct pxa_buffer), icd, &icd->video_lock);
856} 856}
857 857
858static u32 mclk_get_divisor(struct platform_device *pdev, 858static u32 mclk_get_divisor(struct platform_device *pdev,
diff --git a/drivers/media/video/rj54n1cb0c.c b/drivers/media/video/rj54n1cb0c.c
index d2fa2d43ff19..57e11b6f19fb 100644
--- a/drivers/media/video/rj54n1cb0c.c
+++ b/drivers/media/video/rj54n1cb0c.c
@@ -1460,7 +1460,6 @@ static int rj54n1_remove(struct i2c_client *client)
1460 icd->ops = NULL; 1460 icd->ops = NULL;
1461 if (icl->free_bus) 1461 if (icl->free_bus)
1462 icl->free_bus(icl); 1462 icl->free_bus(icl);
1463 client->driver = NULL;
1464 kfree(rj54n1); 1463 kfree(rj54n1);
1465 1464
1466 return 0; 1465 return 0;
diff --git a/drivers/media/video/s2255drv.c b/drivers/media/video/s2255drv.c
index a845753665c1..b63f8cafa671 100644
--- a/drivers/media/video/s2255drv.c
+++ b/drivers/media/video/s2255drv.c
@@ -268,7 +268,7 @@ struct s2255_dev {
268 struct v4l2_device v4l2_dev; 268 struct v4l2_device v4l2_dev;
269 atomic_t num_channels; 269 atomic_t num_channels;
270 int frames; 270 int frames;
271 struct mutex lock; 271 struct mutex lock; /* channels[].vdev.lock */
272 struct mutex open_lock; 272 struct mutex open_lock;
273 struct usb_device *udev; 273 struct usb_device *udev;
274 struct usb_interface *interface; 274 struct usb_interface *interface;
@@ -780,20 +780,14 @@ static struct videobuf_queue_ops s2255_video_qops = {
780 780
781static int res_get(struct s2255_fh *fh) 781static int res_get(struct s2255_fh *fh)
782{ 782{
783 struct s2255_dev *dev = fh->dev;
784 /* is it free? */
785 struct s2255_channel *channel = fh->channel; 783 struct s2255_channel *channel = fh->channel;
786 mutex_lock(&dev->lock); 784 /* is it free? */
787 if (channel->resources) { 785 if (channel->resources)
788 /* no, someone else uses it */ 786 return 0; /* no, someone else uses it */
789 mutex_unlock(&dev->lock);
790 return 0;
791 }
792 /* it's free, grab it */ 787 /* it's free, grab it */
793 channel->resources = 1; 788 channel->resources = 1;
794 fh->resources = 1; 789 fh->resources = 1;
795 dprintk(1, "s2255: res: get\n"); 790 dprintk(1, "s2255: res: get\n");
796 mutex_unlock(&dev->lock);
797 return 1; 791 return 1;
798} 792}
799 793
@@ -811,11 +805,8 @@ static int res_check(struct s2255_fh *fh)
811static void res_free(struct s2255_fh *fh) 805static void res_free(struct s2255_fh *fh)
812{ 806{
813 struct s2255_channel *channel = fh->channel; 807 struct s2255_channel *channel = fh->channel;
814 struct s2255_dev *dev = fh->dev;
815 mutex_lock(&dev->lock);
816 channel->resources = 0; 808 channel->resources = 0;
817 fh->resources = 0; 809 fh->resources = 0;
818 mutex_unlock(&dev->lock);
819 dprintk(1, "res: put\n"); 810 dprintk(1, "res: put\n");
820} 811}
821 812
@@ -1106,15 +1097,6 @@ static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
1106 return rc; 1097 return rc;
1107} 1098}
1108 1099
1109#ifdef CONFIG_VIDEO_V4L1_COMPAT
1110static int vidioc_cgmbuf(struct file *file, void *priv, struct video_mbuf *mbuf)
1111{
1112 struct s2255_fh *fh = priv;
1113
1114 return videobuf_cgmbuf(&fh->vb_vidq, mbuf, 8);
1115}
1116#endif
1117
1118/* write to the configuration pipe, synchronously */ 1100/* write to the configuration pipe, synchronously */
1119static int s2255_write_config(struct usb_device *udev, unsigned char *pbuf, 1101static int s2255_write_config(struct usb_device *udev, unsigned char *pbuf,
1120 int size) 1102 int size)
@@ -1218,7 +1200,6 @@ static int s2255_set_mode(struct s2255_channel *channel,
1218 __le32 *buffer; 1200 __le32 *buffer;
1219 unsigned long chn_rev; 1201 unsigned long chn_rev;
1220 struct s2255_dev *dev = to_s2255_dev(channel->vdev.v4l2_dev); 1202 struct s2255_dev *dev = to_s2255_dev(channel->vdev.v4l2_dev);
1221 mutex_lock(&dev->lock);
1222 chn_rev = G_chnmap[channel->idx]; 1203 chn_rev = G_chnmap[channel->idx];
1223 dprintk(3, "%s channel: %d\n", __func__, channel->idx); 1204 dprintk(3, "%s channel: %d\n", __func__, channel->idx);
1224 /* if JPEG, set the quality */ 1205 /* if JPEG, set the quality */
@@ -1235,7 +1216,6 @@ static int s2255_set_mode(struct s2255_channel *channel,
1235 buffer = kzalloc(512, GFP_KERNEL); 1216 buffer = kzalloc(512, GFP_KERNEL);
1236 if (buffer == NULL) { 1217 if (buffer == NULL) {
1237 dev_err(&dev->udev->dev, "out of mem\n"); 1218 dev_err(&dev->udev->dev, "out of mem\n");
1238 mutex_unlock(&dev->lock);
1239 return -ENOMEM; 1219 return -ENOMEM;
1240 } 1220 }
1241 /* set the mode */ 1221 /* set the mode */
@@ -1260,7 +1240,6 @@ static int s2255_set_mode(struct s2255_channel *channel,
1260 } 1240 }
1261 /* clear the restart flag */ 1241 /* clear the restart flag */
1262 channel->mode.restart = 0; 1242 channel->mode.restart = 0;
1263 mutex_unlock(&dev->lock);
1264 dprintk(1, "%s chn %d, result: %d\n", __func__, channel->idx, res); 1243 dprintk(1, "%s chn %d, result: %d\n", __func__, channel->idx, res);
1265 return res; 1244 return res;
1266} 1245}
@@ -1271,13 +1250,11 @@ static int s2255_cmd_status(struct s2255_channel *channel, u32 *pstatus)
1271 __le32 *buffer; 1250 __le32 *buffer;
1272 u32 chn_rev; 1251 u32 chn_rev;
1273 struct s2255_dev *dev = to_s2255_dev(channel->vdev.v4l2_dev); 1252 struct s2255_dev *dev = to_s2255_dev(channel->vdev.v4l2_dev);
1274 mutex_lock(&dev->lock);
1275 chn_rev = G_chnmap[channel->idx]; 1253 chn_rev = G_chnmap[channel->idx];
1276 dprintk(4, "%s chan %d\n", __func__, channel->idx); 1254 dprintk(4, "%s chan %d\n", __func__, channel->idx);
1277 buffer = kzalloc(512, GFP_KERNEL); 1255 buffer = kzalloc(512, GFP_KERNEL);
1278 if (buffer == NULL) { 1256 if (buffer == NULL) {
1279 dev_err(&dev->udev->dev, "out of mem\n"); 1257 dev_err(&dev->udev->dev, "out of mem\n");
1280 mutex_unlock(&dev->lock);
1281 return -ENOMEM; 1258 return -ENOMEM;
1282 } 1259 }
1283 /* form the get vid status command */ 1260 /* form the get vid status command */
@@ -1297,7 +1274,6 @@ static int s2255_cmd_status(struct s2255_channel *channel, u32 *pstatus)
1297 } 1274 }
1298 *pstatus = channel->vidstatus; 1275 *pstatus = channel->vidstatus;
1299 dprintk(4, "%s, vid status %d\n", __func__, *pstatus); 1276 dprintk(4, "%s, vid status %d\n", __func__, *pstatus);
1300 mutex_unlock(&dev->lock);
1301 return res; 1277 return res;
1302} 1278}
1303 1279
@@ -1816,7 +1792,8 @@ static int s2255_open(struct file *file)
1816 NULL, &dev->slock, 1792 NULL, &dev->slock,
1817 fh->type, 1793 fh->type,
1818 V4L2_FIELD_INTERLACED, 1794 V4L2_FIELD_INTERLACED,
1819 sizeof(struct s2255_buffer), fh, NULL); 1795 sizeof(struct s2255_buffer),
1796 fh, vdev->lock);
1820 return 0; 1797 return 0;
1821} 1798}
1822 1799
@@ -1899,7 +1876,7 @@ static const struct v4l2_file_operations s2255_fops_v4l = {
1899 .open = s2255_open, 1876 .open = s2255_open,
1900 .release = s2255_release, 1877 .release = s2255_release,
1901 .poll = s2255_poll, 1878 .poll = s2255_poll,
1902 .ioctl = video_ioctl2, /* V4L2 ioctl handler */ 1879 .unlocked_ioctl = video_ioctl2, /* V4L2 ioctl handler */
1903 .mmap = s2255_mmap_v4l, 1880 .mmap = s2255_mmap_v4l,
1904}; 1881};
1905 1882
@@ -1923,9 +1900,6 @@ static const struct v4l2_ioctl_ops s2255_ioctl_ops = {
1923 .vidioc_s_ctrl = vidioc_s_ctrl, 1900 .vidioc_s_ctrl = vidioc_s_ctrl,
1924 .vidioc_streamon = vidioc_streamon, 1901 .vidioc_streamon = vidioc_streamon,
1925 .vidioc_streamoff = vidioc_streamoff, 1902 .vidioc_streamoff = vidioc_streamoff,
1926#ifdef CONFIG_VIDEO_V4L1_COMPAT
1927 .vidiocgmbuf = vidioc_cgmbuf,
1928#endif
1929 .vidioc_s_jpegcomp = vidioc_s_jpegcomp, 1903 .vidioc_s_jpegcomp = vidioc_s_jpegcomp,
1930 .vidioc_g_jpegcomp = vidioc_g_jpegcomp, 1904 .vidioc_g_jpegcomp = vidioc_g_jpegcomp,
1931 .vidioc_s_parm = vidioc_s_parm, 1905 .vidioc_s_parm = vidioc_s_parm,
@@ -1969,6 +1943,7 @@ static int s2255_probe_v4l(struct s2255_dev *dev)
1969 channel->vidq.dev = dev; 1943 channel->vidq.dev = dev;
1970 /* register 4 video devices */ 1944 /* register 4 video devices */
1971 channel->vdev = template; 1945 channel->vdev = template;
1946 channel->vdev.lock = &dev->lock;
1972 channel->vdev.v4l2_dev = &dev->v4l2_dev; 1947 channel->vdev.v4l2_dev = &dev->v4l2_dev;
1973 video_set_drvdata(&channel->vdev, channel); 1948 video_set_drvdata(&channel->vdev, channel);
1974 if (video_nr == -1) 1949 if (video_nr == -1)
@@ -2675,7 +2650,9 @@ static void s2255_disconnect(struct usb_interface *interface)
2675 struct s2255_dev *dev = to_s2255_dev(usb_get_intfdata(interface)); 2650 struct s2255_dev *dev = to_s2255_dev(usb_get_intfdata(interface));
2676 int i; 2651 int i;
2677 int channels = atomic_read(&dev->num_channels); 2652 int channels = atomic_read(&dev->num_channels);
2653 mutex_lock(&dev->lock);
2678 v4l2_device_disconnect(&dev->v4l2_dev); 2654 v4l2_device_disconnect(&dev->v4l2_dev);
2655 mutex_unlock(&dev->lock);
2679 /*see comments in the uvc_driver.c usb disconnect function */ 2656 /*see comments in the uvc_driver.c usb disconnect function */
2680 atomic_inc(&dev->num_channels); 2657 atomic_inc(&dev->num_channels);
2681 /* unregister each video device. */ 2658 /* unregister each video device. */
diff --git a/drivers/media/video/s5p-fimc/fimc-core.c b/drivers/media/video/s5p-fimc/fimc-core.c
index bb99f2d805d3..817aa66627f6 100644
--- a/drivers/media/video/s5p-fimc/fimc-core.c
+++ b/drivers/media/video/s5p-fimc/fimc-core.c
@@ -543,7 +543,7 @@ static void fimc_dma_run(void *priv)
543 unsigned long flags; 543 unsigned long flags;
544 u32 ret; 544 u32 ret;
545 545
546 if (WARN(!ctx, "null hardware context")) 546 if (WARN(!ctx, "null hardware context\n"))
547 return; 547 return;
548 548
549 fimc = ctx->fimc_dev; 549 fimc = ctx->fimc_dev;
diff --git a/drivers/media/video/saa6588.c b/drivers/media/video/saa6588.c
index 984c0feb2a4e..99a2ac16f9e5 100644
--- a/drivers/media/video/saa6588.c
+++ b/drivers/media/video/saa6588.c
@@ -31,7 +31,7 @@
31#include <linux/wait.h> 31#include <linux/wait.h>
32#include <asm/uaccess.h> 32#include <asm/uaccess.h>
33 33
34#include <media/rds.h> 34#include <media/saa6588.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 37
@@ -181,7 +181,7 @@ static int block_to_user_buf(struct saa6588 *s, unsigned char __user *user_buf)
181 return 1; 181 return 1;
182} 182}
183 183
184static void read_from_buf(struct saa6588 *s, struct rds_command *a) 184static void read_from_buf(struct saa6588 *s, struct saa6588_command *a)
185{ 185{
186 unsigned long flags; 186 unsigned long flags;
187 187
@@ -392,25 +392,25 @@ static void saa6588_configure(struct saa6588 *s)
392static long saa6588_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg) 392static long saa6588_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
393{ 393{
394 struct saa6588 *s = to_saa6588(sd); 394 struct saa6588 *s = to_saa6588(sd);
395 struct rds_command *a = arg; 395 struct saa6588_command *a = arg;
396 396
397 switch (cmd) { 397 switch (cmd) {
398 /* --- open() for /dev/radio --- */ 398 /* --- open() for /dev/radio --- */
399 case RDS_CMD_OPEN: 399 case SAA6588_CMD_OPEN:
400 a->result = 0; /* return error if chip doesn't work ??? */ 400 a->result = 0; /* return error if chip doesn't work ??? */
401 break; 401 break;
402 /* --- close() for /dev/radio --- */ 402 /* --- close() for /dev/radio --- */
403 case RDS_CMD_CLOSE: 403 case SAA6588_CMD_CLOSE:
404 s->data_available_for_read = 1; 404 s->data_available_for_read = 1;
405 wake_up_interruptible(&s->read_queue); 405 wake_up_interruptible(&s->read_queue);
406 a->result = 0; 406 a->result = 0;
407 break; 407 break;
408 /* --- read() for /dev/radio --- */ 408 /* --- read() for /dev/radio --- */
409 case RDS_CMD_READ: 409 case SAA6588_CMD_READ:
410 read_from_buf(s, a); 410 read_from_buf(s, a);
411 break; 411 break;
412 /* --- poll() for /dev/radio --- */ 412 /* --- poll() for /dev/radio --- */
413 case RDS_CMD_POLL: 413 case SAA6588_CMD_POLL:
414 a->result = 0; 414 a->result = 0;
415 if (s->data_available_for_read) { 415 if (s->data_available_for_read) {
416 a->result |= POLLIN | POLLRDNORM; 416 a->result |= POLLIN | POLLRDNORM;
diff --git a/drivers/media/video/saa7115.c b/drivers/media/video/saa7115.c
index 301c62b88cad..f35459d1f42f 100644
--- a/drivers/media/video/saa7115.c
+++ b/drivers/media/video/saa7115.c
@@ -1348,8 +1348,17 @@ static int saa711x_querystd(struct v4l2_subdev *sd, v4l2_std_id *std)
1348 int reg1e; 1348 int reg1e;
1349 1349
1350 *std = V4L2_STD_ALL; 1350 *std = V4L2_STD_ALL;
1351 if (state->ident != V4L2_IDENT_SAA7115) 1351 if (state->ident != V4L2_IDENT_SAA7115) {
1352 int reg1f = saa711x_read(sd, R_1F_STATUS_BYTE_2_VD_DEC);
1353
1354 if (reg1f & 0x20)
1355 *std = V4L2_STD_525_60;
1356 else
1357 *std = V4L2_STD_625_50;
1358
1352 return 0; 1359 return 0;
1360 }
1361
1353 reg1e = saa711x_read(sd, R_1E_STATUS_BYTE_1_VD_DEC); 1362 reg1e = saa711x_read(sd, R_1E_STATUS_BYTE_1_VD_DEC);
1354 1363
1355 switch (reg1e & 0x03) { 1364 switch (reg1e & 0x03) {
diff --git a/drivers/media/video/saa7134/Kconfig b/drivers/media/video/saa7134/Kconfig
index 3fe71be41a1f..380f1b28cfcc 100644
--- a/drivers/media/video/saa7134/Kconfig
+++ b/drivers/media/video/saa7134/Kconfig
@@ -26,7 +26,7 @@ config VIDEO_SAA7134_ALSA
26 26
27config VIDEO_SAA7134_RC 27config VIDEO_SAA7134_RC
28 bool "Philips SAA7134 Remote Controller support" 28 bool "Philips SAA7134 Remote Controller support"
29 depends on VIDEO_IR 29 depends on RC_CORE
30 depends on VIDEO_SAA7134 30 depends on VIDEO_SAA7134
31 default y 31 default y
32 ---help--- 32 ---help---
diff --git a/drivers/media/video/saa7134/saa7134-cards.c b/drivers/media/video/saa7134/saa7134-cards.c
index 1d4d0a49ea52..e7aa588c6c5a 100644
--- a/drivers/media/video/saa7134/saa7134-cards.c
+++ b/drivers/media/video/saa7134/saa7134-cards.c
@@ -5176,6 +5176,58 @@ struct saa7134_board saa7134_boards[] = {
5176 .amux = 2, 5176 .amux = 2,
5177 }, 5177 },
5178 }, 5178 },
5179 [SAA7134_BOARD_KWORLD_PCI_SBTVD_FULLSEG] = {
5180 .name = "Kworld PCI SBTVD/ISDB-T Full-Seg Hybrid",
5181 .audio_clock = 0x00187de7,
5182#if 0
5183 /*
5184 * FIXME: Analog mode doesn't work, if digital is enabled. The proper
5185 * fix is to use tda8290 driver, but Kworld seems to use an
5186 * unsupported version of tda8295.
5187 */
5188 .tuner_type = TUNER_NXP_TDA18271, /* TUNER_PHILIPS_TDA8290 */
5189 .tuner_addr = 0x60,
5190#else
5191 .tuner_type = UNSET,
5192 .tuner_addr = ADDR_UNSET,
5193#endif
5194 .radio_type = UNSET,
5195 .radio_addr = ADDR_UNSET,
5196 .gpiomask = 0x8e054000,
5197 .mpeg = SAA7134_MPEG_DVB,
5198 .ts_type = SAA7134_MPEG_TS_PARALLEL,
5199 .inputs = { {
5200 .name = name_tv,
5201 .vmux = 1,
5202 .amux = TV,
5203 .tv = 1,
5204#if 0 /* FIXME */
5205 }, {
5206 .name = name_comp1,
5207 .vmux = 3,
5208 .amux = LINE1,
5209 .gpio = 0x200,
5210 }, {
5211 .name = name_svideo,
5212 .vmux = 8,
5213 .amux = LINE1,
5214 .gpio = 0x200,
5215#endif
5216 } },
5217#if 0
5218 .radio = {
5219 .name = name_radio,
5220 .vmux = 1,
5221 .amux = LINE1,
5222 .gpio = 0x100,
5223 },
5224#endif
5225 .mute = {
5226 .name = name_mute,
5227 .vmux = 0,
5228 .amux = TV,
5229 },
5230 },
5179 [SAA7134_BOARD_AVERMEDIA_GO_007_FM_PLUS] = { 5231 [SAA7134_BOARD_AVERMEDIA_GO_007_FM_PLUS] = {
5180 .name = "Avermedia AVerTV GO 007 FM Plus", 5232 .name = "Avermedia AVerTV GO 007 FM Plus",
5181 .audio_clock = 0x00187de7, 5233 .audio_clock = 0x00187de7,
@@ -5486,6 +5538,37 @@ struct saa7134_board saa7134_boards[] = {
5486 .amux = LINE2, 5538 .amux = LINE2,
5487 } }, 5539 } },
5488 }, 5540 },
5541 [SAA7134_BOARD_VIDEOMATE_M1F] = {
5542 /* Pavel Osnova <pvosnova@gmail.com> */
5543 .name = "Compro VideoMate Vista M1F",
5544 .audio_clock = 0x00187de7,
5545 .tuner_type = TUNER_LG_PAL_NEW_TAPC,
5546 .radio_type = TUNER_TEA5767,
5547 .tuner_addr = ADDR_UNSET,
5548 .radio_addr = 0x60,
5549 .inputs = { {
5550 .name = name_tv,
5551 .vmux = 1,
5552 .amux = TV,
5553 .tv = 1,
5554 }, {
5555 .name = name_comp1,
5556 .vmux = 3,
5557 .amux = LINE2,
5558 }, {
5559 .name = name_svideo,
5560 .vmux = 8,
5561 .amux = LINE2,
5562 } },
5563 .radio = {
5564 .name = name_radio,
5565 .amux = LINE1,
5566 },
5567 .mute = {
5568 .name = name_mute,
5569 .amux = TV,
5570 },
5571 },
5489 5572
5490}; 5573};
5491 5574
@@ -6615,6 +6698,12 @@ struct pci_device_id saa7134_pci_tbl[] = {
6615 }, { 6698 }, {
6616 .vendor = PCI_VENDOR_ID_PHILIPS, 6699 .vendor = PCI_VENDOR_ID_PHILIPS,
6617 .device = PCI_DEVICE_ID_PHILIPS_SAA7133, 6700 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
6701 .subvendor = 0x17de,
6702 .subdevice = 0xb136,
6703 .driver_data = SAA7134_BOARD_KWORLD_PCI_SBTVD_FULLSEG,
6704 }, {
6705 .vendor = PCI_VENDOR_ID_PHILIPS,
6706 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
6618 .subvendor = 0x1461, /* Avermedia Technologies Inc */ 6707 .subvendor = 0x1461, /* Avermedia Technologies Inc */
6619 .subdevice = 0xf31d, 6708 .subdevice = 0xf31d,
6620 .driver_data = SAA7134_BOARD_AVERMEDIA_GO_007_FM_PLUS, 6709 .driver_data = SAA7134_BOARD_AVERMEDIA_GO_007_FM_PLUS,
@@ -6673,6 +6762,12 @@ struct pci_device_id saa7134_pci_tbl[] = {
6673 .subdevice = 0x7090, 6762 .subdevice = 0x7090,
6674 .driver_data = SAA7134_BOARD_BEHOLD_A7, 6763 .driver_data = SAA7134_BOARD_BEHOLD_A7,
6675 }, { 6764 }, {
6765 .vendor = PCI_VENDOR_ID_PHILIPS,
6766 .device = PCI_DEVICE_ID_PHILIPS_SAA7135,
6767 .subvendor = 0x185b,
6768 .subdevice = 0xc900,
6769 .driver_data = SAA7134_BOARD_VIDEOMATE_M1F,
6770 }, {
6676 /* --- boards without eeprom + subsystem ID --- */ 6771 /* --- boards without eeprom + subsystem ID --- */
6677 .vendor = PCI_VENDOR_ID_PHILIPS, 6772 .vendor = PCI_VENDOR_ID_PHILIPS,
6678 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 6773 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
@@ -6831,6 +6926,23 @@ static inline int saa7134_tda18271_hvr11x0_toggle_agc(struct saa7134_dev *dev,
6831 return 0; 6926 return 0;
6832} 6927}
6833 6928
6929static inline int saa7134_kworld_sbtvd_toggle_agc(struct saa7134_dev *dev,
6930 enum tda18271_mode mode)
6931{
6932 /* toggle AGC switch through GPIO 27 */
6933 switch (mode) {
6934 case TDA18271_ANALOG:
6935 saa7134_set_gpio(dev, 27, 0);
6936 break;
6937 case TDA18271_DIGITAL:
6938 saa7134_set_gpio(dev, 27, 1);
6939 break;
6940 default:
6941 return -EINVAL;
6942 }
6943 return 0;
6944}
6945
6834static int saa7134_tda8290_18271_callback(struct saa7134_dev *dev, 6946static int saa7134_tda8290_18271_callback(struct saa7134_dev *dev,
6835 int command, int arg) 6947 int command, int arg)
6836{ 6948{
@@ -6843,6 +6955,9 @@ static int saa7134_tda8290_18271_callback(struct saa7134_dev *dev,
6843 case SAA7134_BOARD_HAUPPAUGE_HVR1120: 6955 case SAA7134_BOARD_HAUPPAUGE_HVR1120:
6844 ret = saa7134_tda18271_hvr11x0_toggle_agc(dev, arg); 6956 ret = saa7134_tda18271_hvr11x0_toggle_agc(dev, arg);
6845 break; 6957 break;
6958 case SAA7134_BOARD_KWORLD_PCI_SBTVD_FULLSEG:
6959 ret = saa7134_kworld_sbtvd_toggle_agc(dev, arg);
6960 break;
6846 default: 6961 default:
6847 break; 6962 break;
6848 } 6963 }
@@ -6863,6 +6978,7 @@ static int saa7134_tda8290_callback(struct saa7134_dev *dev,
6863 case SAA7134_BOARD_HAUPPAUGE_HVR1150: 6978 case SAA7134_BOARD_HAUPPAUGE_HVR1150:
6864 case SAA7134_BOARD_HAUPPAUGE_HVR1120: 6979 case SAA7134_BOARD_HAUPPAUGE_HVR1120:
6865 case SAA7134_BOARD_AVERMEDIA_M733A: 6980 case SAA7134_BOARD_AVERMEDIA_M733A:
6981 case SAA7134_BOARD_KWORLD_PCI_SBTVD_FULLSEG:
6866 /* tda8290 + tda18271 */ 6982 /* tda8290 + tda18271 */
6867 ret = saa7134_tda8290_18271_callback(dev, command, arg); 6983 ret = saa7134_tda8290_18271_callback(dev, command, arg);
6868 break; 6984 break;
@@ -6967,6 +7083,7 @@ int saa7134_board_init1(struct saa7134_dev *dev)
6967 case SAA7134_BOARD_VIDEOMATE_TV_PVR: 7083 case SAA7134_BOARD_VIDEOMATE_TV_PVR:
6968 case SAA7134_BOARD_VIDEOMATE_GOLD_PLUS: 7084 case SAA7134_BOARD_VIDEOMATE_GOLD_PLUS:
6969 case SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII: 7085 case SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII:
7086 case SAA7134_BOARD_VIDEOMATE_M1F:
6970 case SAA7134_BOARD_VIDEOMATE_DVBT_300: 7087 case SAA7134_BOARD_VIDEOMATE_DVBT_300:
6971 case SAA7134_BOARD_VIDEOMATE_DVBT_200: 7088 case SAA7134_BOARD_VIDEOMATE_DVBT_200:
6972 case SAA7134_BOARD_VIDEOMATE_DVBT_200A: 7089 case SAA7134_BOARD_VIDEOMATE_DVBT_200A:
@@ -7541,6 +7658,37 @@ int saa7134_board_init2(struct saa7134_dev *dev)
7541 dev->name); 7658 dev->name);
7542 break; 7659 break;
7543 } 7660 }
7661 case SAA7134_BOARD_KWORLD_PCI_SBTVD_FULLSEG:
7662 {
7663 struct i2c_msg msg = { .addr = 0x4b, .flags = 0 };
7664 int i;
7665 static u8 buffer[][2] = {
7666 {0x30, 0x31},
7667 {0xff, 0x00},
7668 {0x41, 0x03},
7669 {0x41, 0x1a},
7670 {0xff, 0x02},
7671 {0x34, 0x00},
7672 {0x45, 0x97},
7673 {0x45, 0xc1},
7674 };
7675 saa_writel(SAA7134_GPIO_GPMODE0 >> 2, 0x4000);
7676 saa_writel(SAA7134_GPIO_GPSTATUS0 >> 2, 0x4000);
7677
7678 /*
7679 * FIXME: identify what device is at addr 0x4b and what means
7680 * this initialization
7681 */
7682 for (i = 0; i < ARRAY_SIZE(buffer); i++) {
7683 msg.buf = &buffer[i][0];
7684 msg.len = ARRAY_SIZE(buffer[0]);
7685 if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1)
7686 printk(KERN_WARNING
7687 "%s: Unable to enable tuner(%i).\n",
7688 dev->name, i);
7689 }
7690 break;
7691 }
7544 } /* switch() */ 7692 } /* switch() */
7545 7693
7546 /* initialize tuner */ 7694 /* initialize tuner */
diff --git a/drivers/media/video/saa7134/saa7134-dvb.c b/drivers/media/video/saa7134/saa7134-dvb.c
index beb95e21d109..3315a48a848b 100644
--- a/drivers/media/video/saa7134/saa7134-dvb.c
+++ b/drivers/media/video/saa7134/saa7134-dvb.c
@@ -52,6 +52,7 @@
52#include "tda18271.h" 52#include "tda18271.h"
53#include "lgdt3305.h" 53#include "lgdt3305.h"
54#include "tda8290.h" 54#include "tda8290.h"
55#include "mb86a20s.h"
55 56
56#include "zl10353.h" 57#include "zl10353.h"
57 58
@@ -228,6 +229,20 @@ static struct mt352_config avermedia_xc3028_mt352_dev = {
228 .demod_init = mt352_avermedia_xc3028_init, 229 .demod_init = mt352_avermedia_xc3028_init,
229}; 230};
230 231
232static struct tda18271_std_map mb86a20s_tda18271_std_map = {
233 .dvbt_6 = { .if_freq = 3300, .agc_mode = 3, .std = 4,
234 .if_lvl = 7, .rfagc_top = 0x37, },
235};
236
237static struct tda18271_config kworld_tda18271_config = {
238 .std_map = &mb86a20s_tda18271_std_map,
239 .gate = TDA18271_GATE_DIGITAL,
240};
241
242static const struct mb86a20s_config kworld_mb86a20s_config = {
243 .demod_address = 0x10,
244};
245
231/* ================================================================== 246/* ==================================================================
232 * tda1004x based DVB-T cards, helper functions 247 * tda1004x based DVB-T cards, helper functions
233 */ 248 */
@@ -608,6 +623,37 @@ static struct tda827x_config tda827x_cfg_2_sw42 = {
608 623
609/* ------------------------------------------------------------------ */ 624/* ------------------------------------------------------------------ */
610 625
626static int __kworld_sbtvd_i2c_gate_ctrl(struct saa7134_dev *dev, int enable)
627{
628 unsigned char initmsg[] = {0x45, 0x97};
629 unsigned char msg_enable[] = {0x45, 0xc1};
630 unsigned char msg_disable[] = {0x45, 0x81};
631 struct i2c_msg msg = {.addr = 0x4b, .flags = 0, .buf = initmsg, .len = 2};
632
633 if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1) {
634 wprintk("could not access the I2C gate\n");
635 return -EIO;
636 }
637 if (enable)
638 msg.buf = msg_enable;
639 else
640 msg.buf = msg_disable;
641 if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1) {
642 wprintk("could not access the I2C gate\n");
643 return -EIO;
644 }
645 msleep(20);
646 return 0;
647}
648static int kworld_sbtvd_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
649{
650 struct saa7134_dev *dev = fe->dvb->priv;
651
652 return __kworld_sbtvd_i2c_gate_ctrl(dev, enable);
653}
654
655/* ------------------------------------------------------------------ */
656
611static struct tda1004x_config tda827x_lifeview_config = { 657static struct tda1004x_config tda827x_lifeview_config = {
612 .demod_address = 0x08, 658 .demod_address = 0x08,
613 .invert = 1, 659 .invert = 1,
@@ -1613,6 +1659,29 @@ static int dvb_init(struct saa7134_dev *dev)
1613 &dtv1000s_tda18271_config); 1659 &dtv1000s_tda18271_config);
1614 } 1660 }
1615 break; 1661 break;
1662 case SAA7134_BOARD_KWORLD_PCI_SBTVD_FULLSEG:
1663 __kworld_sbtvd_i2c_gate_ctrl(dev, 0);
1664 saa_writel(SAA7134_GPIO_GPMODE0 >> 2, 0x14000);
1665 saa_writel(SAA7134_GPIO_GPSTATUS0 >> 2, 0x14000);
1666 msleep(20);
1667 saa_writel(SAA7134_GPIO_GPMODE0 >> 2, 0x54000);
1668 saa_writel(SAA7134_GPIO_GPSTATUS0 >> 2, 0x54000);
1669 msleep(20);
1670 fe0->dvb.frontend = dvb_attach(mb86a20s_attach,
1671 &kworld_mb86a20s_config,
1672 &dev->i2c_adap);
1673 __kworld_sbtvd_i2c_gate_ctrl(dev, 1);
1674 if (fe0->dvb.frontend != NULL) {
1675 dvb_attach(tda18271_attach, fe0->dvb.frontend,
1676 0x60, &dev->i2c_adap,
1677 &kworld_tda18271_config);
1678 /*
1679 * Only after success, it can initialize the gate, otherwise
1680 * an OOPS will hit, due to kfree(fe0->dvb.frontend)
1681 */
1682 fe0->dvb.frontend->ops.i2c_gate_ctrl = kworld_sbtvd_i2c_gate_ctrl;
1683 }
1684 break;
1616 default: 1685 default:
1617 wprintk("Huh? unknown DVB card?\n"); 1686 wprintk("Huh? unknown DVB card?\n");
1618 break; 1687 break;
diff --git a/drivers/media/video/saa7134/saa7134-input.c b/drivers/media/video/saa7134/saa7134-input.c
index 46d31dfca7a3..dc646e65edb7 100644
--- a/drivers/media/video/saa7134/saa7134-input.c
+++ b/drivers/media/video/saa7134/saa7134-input.c
@@ -22,7 +22,6 @@
22#include <linux/init.h> 22#include <linux/init.h>
23#include <linux/delay.h> 23#include <linux/delay.h>
24#include <linux/interrupt.h> 24#include <linux/interrupt.h>
25#include <linux/input.h>
26#include <linux/slab.h> 25#include <linux/slab.h>
27 26
28#include "saa7134-reg.h" 27#include "saa7134-reg.h"
@@ -42,41 +41,19 @@ static int pinnacle_remote;
42module_param(pinnacle_remote, int, 0644); /* Choose Pinnacle PCTV remote */ 41module_param(pinnacle_remote, int, 0644); /* Choose Pinnacle PCTV remote */
43MODULE_PARM_DESC(pinnacle_remote, "Specify Pinnacle PCTV remote: 0=coloured, 1=grey (defaults to 0)"); 42MODULE_PARM_DESC(pinnacle_remote, "Specify Pinnacle PCTV remote: 0=coloured, 1=grey (defaults to 0)");
44 43
45static int ir_rc5_remote_gap = 885;
46module_param(ir_rc5_remote_gap, int, 0644);
47static int ir_rc5_key_timeout = 115;
48module_param(ir_rc5_key_timeout, int, 0644);
49
50static int repeat_delay = 500;
51module_param(repeat_delay, int, 0644);
52MODULE_PARM_DESC(repeat_delay, "delay before key repeat started");
53static int repeat_period = 33;
54module_param(repeat_period, int, 0644);
55MODULE_PARM_DESC(repeat_period, "repeat period between "
56 "keypresses when key is down");
57
58static unsigned int disable_other_ir;
59module_param(disable_other_ir, int, 0644);
60MODULE_PARM_DESC(disable_other_ir, "disable full codes of "
61 "alternative remotes from other manufacturers");
62
63#define dprintk(fmt, arg...) if (ir_debug) \ 44#define dprintk(fmt, arg...) if (ir_debug) \
64 printk(KERN_DEBUG "%s/ir: " fmt, dev->name , ## arg) 45 printk(KERN_DEBUG "%s/ir: " fmt, dev->name , ## arg)
65#define i2cdprintk(fmt, arg...) if (ir_debug) \ 46#define i2cdprintk(fmt, arg...) if (ir_debug) \
66 printk(KERN_DEBUG "%s/ir: " fmt, ir->name , ## arg) 47 printk(KERN_DEBUG "%s/ir: " fmt, ir->name , ## arg)
67 48
68/* Helper functions for RC5 and NEC decoding at GPIO16 or GPIO18 */ 49/* Helper function for raw decoding at GPIO16 or GPIO18 */
69static int saa7134_rc5_irq(struct saa7134_dev *dev);
70static int saa7134_nec_irq(struct saa7134_dev *dev);
71static int saa7134_raw_decode_irq(struct saa7134_dev *dev); 50static int saa7134_raw_decode_irq(struct saa7134_dev *dev);
72static void nec_task(unsigned long data);
73static void saa7134_nec_timer(unsigned long data);
74 51
75/* -------------------- GPIO generic keycode builder -------------------- */ 52/* -------------------- GPIO generic keycode builder -------------------- */
76 53
77static int build_key(struct saa7134_dev *dev) 54static int build_key(struct saa7134_dev *dev)
78{ 55{
79 struct card_ir *ir = dev->remote; 56 struct saa7134_card_ir *ir = dev->remote;
80 u32 gpio, data; 57 u32 gpio, data;
81 58
82 /* here comes the additional handshake steps for some cards */ 59 /* here comes the additional handshake steps for some cards */
@@ -104,25 +81,25 @@ static int build_key(struct saa7134_dev *dev)
104 switch (dev->board) { 81 switch (dev->board) {
105 case SAA7134_BOARD_KWORLD_PLUS_TV_ANALOG: 82 case SAA7134_BOARD_KWORLD_PLUS_TV_ANALOG:
106 if (data == ir->mask_keycode) 83 if (data == ir->mask_keycode)
107 ir_input_nokey(ir->dev, &ir->ir); 84 rc_keyup(ir->dev);
108 else 85 else
109 ir_input_keydown(ir->dev, &ir->ir, data); 86 rc_keydown_notimeout(ir->dev, data, 0);
110 return 0; 87 return 0;
111 } 88 }
112 89
113 if (ir->polling) { 90 if (ir->polling) {
114 if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) || 91 if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) ||
115 (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) { 92 (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) {
116 ir_input_keydown(ir->dev, &ir->ir, data); 93 rc_keydown_notimeout(ir->dev, data, 0);
117 } else { 94 } else {
118 ir_input_nokey(ir->dev, &ir->ir); 95 rc_keyup(ir->dev);
119 } 96 }
120 } 97 }
121 else { /* IRQ driven mode - handle key press and release in one go */ 98 else { /* IRQ driven mode - handle key press and release in one go */
122 if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) || 99 if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) ||
123 (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) { 100 (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) {
124 ir_input_keydown(ir->dev, &ir->ir, data); 101 rc_keydown_notimeout(ir->dev, data, 0);
125 ir_input_nokey(ir->dev, &ir->ir); 102 rc_keyup(ir->dev);
126 } 103 }
127 } 104 }
128 105
@@ -300,22 +277,12 @@ static int get_key_beholdm6xx(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
300 i2cdprintk("read error\n"); 277 i2cdprintk("read error\n");
301 return -EIO; 278 return -EIO;
302 } 279 }
303 /* IR of this card normally decode signals NEC-standard from
304 * - Sven IHOO MT 5.1R remote. xxyye718
305 * - Sven DVD HD-10xx remote. xxyyf708
306 * - BBK ...
307 * - mayby others
308 * So, skip not our, if disable full codes mode.
309 */
310 if (data[10] != 0x6b && data[11] != 0x86 && disable_other_ir)
311 return 0;
312 280
313 /* Wrong data decode fix */
314 if (data[9] != (unsigned char)(~data[8])) 281 if (data[9] != (unsigned char)(~data[8]))
315 return 0; 282 return 0;
316 283
317 *ir_key = data[9]; 284 *ir_raw = ((data[10] << 16) | (data[11] << 8) | (data[9] << 0));
318 *ir_raw = data[9]; 285 *ir_key = *ir_raw;
319 286
320 return 1; 287 return 1;
321} 288}
@@ -400,7 +367,7 @@ static int get_key_pinnacle_color(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
400 367
401void saa7134_input_irq(struct saa7134_dev *dev) 368void saa7134_input_irq(struct saa7134_dev *dev)
402{ 369{
403 struct card_ir *ir; 370 struct saa7134_card_ir *ir;
404 371
405 if (!dev || !dev->remote) 372 if (!dev || !dev->remote)
406 return; 373 return;
@@ -409,12 +376,8 @@ void saa7134_input_irq(struct saa7134_dev *dev)
409 if (!ir->running) 376 if (!ir->running)
410 return; 377 return;
411 378
412 if (ir->nec_gpio) { 379 if (!ir->polling && !ir->raw_decode) {
413 saa7134_nec_irq(dev);
414 } else if (!ir->polling && !ir->rc5_gpio && !ir->raw_decode) {
415 build_key(dev); 380 build_key(dev);
416 } else if (ir->rc5_gpio) {
417 saa7134_rc5_irq(dev);
418 } else if (ir->raw_decode) { 381 } else if (ir->raw_decode) {
419 saa7134_raw_decode_irq(dev); 382 saa7134_raw_decode_irq(dev);
420 } 383 }
@@ -423,7 +386,7 @@ void saa7134_input_irq(struct saa7134_dev *dev)
423static void saa7134_input_timer(unsigned long data) 386static void saa7134_input_timer(unsigned long data)
424{ 387{
425 struct saa7134_dev *dev = (struct saa7134_dev *)data; 388 struct saa7134_dev *dev = (struct saa7134_dev *)data;
426 struct card_ir *ir = dev->remote; 389 struct saa7134_card_ir *ir = dev->remote;
427 390
428 build_key(dev); 391 build_key(dev);
429 mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling)); 392 mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling));
@@ -432,57 +395,37 @@ static void saa7134_input_timer(unsigned long data)
432static void ir_raw_decode_timer_end(unsigned long data) 395static void ir_raw_decode_timer_end(unsigned long data)
433{ 396{
434 struct saa7134_dev *dev = (struct saa7134_dev *)data; 397 struct saa7134_dev *dev = (struct saa7134_dev *)data;
435 struct card_ir *ir = dev->remote; 398 struct saa7134_card_ir *ir = dev->remote;
436 399
437 ir_raw_event_handle(dev->remote->dev); 400 ir_raw_event_handle(dev->remote->dev);
438 401
439 ir->active = 0; 402 ir->active = false;
440} 403}
441 404
442static int __saa7134_ir_start(void *priv) 405static int __saa7134_ir_start(void *priv)
443{ 406{
444 struct saa7134_dev *dev = priv; 407 struct saa7134_dev *dev = priv;
445 struct card_ir *ir; 408 struct saa7134_card_ir *ir;
446 409
447 if (!dev) 410 if (!dev || !dev->remote)
448 return -EINVAL; 411 return -EINVAL;
449 412
450 ir = dev->remote; 413 ir = dev->remote;
451 if (!ir)
452 return -EINVAL;
453
454 if (ir->running) 414 if (ir->running)
455 return 0; 415 return 0;
456 416
457 ir->running = 1; 417 ir->running = true;
418 ir->active = false;
419
458 if (ir->polling) { 420 if (ir->polling) {
459 setup_timer(&ir->timer, saa7134_input_timer, 421 setup_timer(&ir->timer, saa7134_input_timer,
460 (unsigned long)dev); 422 (unsigned long)dev);
461 ir->timer.expires = jiffies + HZ; 423 ir->timer.expires = jiffies + HZ;
462 add_timer(&ir->timer); 424 add_timer(&ir->timer);
463 } else if (ir->rc5_gpio) {
464 /* set timer_end for code completion */
465 init_timer(&ir->timer_end);
466 ir->timer_end.function = ir_rc5_timer_end;
467 ir->timer_end.data = (unsigned long)ir;
468 init_timer(&ir->timer_keyup);
469 ir->timer_keyup.function = ir_rc5_timer_keyup;
470 ir->timer_keyup.data = (unsigned long)ir;
471 ir->shift_by = 2;
472 ir->start = 0x2;
473 ir->addr = 0x17;
474 ir->rc5_key_timeout = ir_rc5_key_timeout;
475 ir->rc5_remote_gap = ir_rc5_remote_gap;
476 } else if (ir->nec_gpio) {
477 setup_timer(&ir->timer_keyup, saa7134_nec_timer,
478 (unsigned long)dev);
479 tasklet_init(&ir->tlet, nec_task, (unsigned long)dev);
480 } else if (ir->raw_decode) { 425 } else if (ir->raw_decode) {
481 /* set timer_end for code completion */ 426 /* set timer_end for code completion */
482 init_timer(&ir->timer_end); 427 setup_timer(&ir->timer, ir_raw_decode_timer_end,
483 ir->timer_end.function = ir_raw_decode_timer_end; 428 (unsigned long)dev);
484 ir->timer_end.data = (unsigned long)dev;
485 ir->active = 0;
486 } 429 }
487 430
488 return 0; 431 return 0;
@@ -491,29 +434,20 @@ static int __saa7134_ir_start(void *priv)
491static void __saa7134_ir_stop(void *priv) 434static void __saa7134_ir_stop(void *priv)
492{ 435{
493 struct saa7134_dev *dev = priv; 436 struct saa7134_dev *dev = priv;
494 struct card_ir *ir; 437 struct saa7134_card_ir *ir;
495 438
496 if (!dev) 439 if (!dev || !dev->remote)
497 return; 440 return;
498 441
499 ir = dev->remote; 442 ir = dev->remote;
500 if (!ir)
501 return;
502
503 if (!ir->running) 443 if (!ir->running)
504 return; 444 return;
505 if (dev->remote->polling)
506 del_timer_sync(&dev->remote->timer);
507 else if (ir->rc5_gpio)
508 del_timer_sync(&ir->timer_end);
509 else if (ir->nec_gpio)
510 tasklet_kill(&ir->tlet);
511 else if (ir->raw_decode) {
512 del_timer_sync(&ir->timer_end);
513 ir->active = 0;
514 }
515 445
516 ir->running = 0; 446 if (ir->polling || ir->raw_decode)
447 del_timer_sync(&ir->timer);
448
449 ir->active = false;
450 ir->running = false;
517 451
518 return; 452 return;
519} 453}
@@ -532,71 +466,33 @@ void saa7134_ir_stop(struct saa7134_dev *dev)
532 __saa7134_ir_stop(dev); 466 __saa7134_ir_stop(dev);
533} 467}
534 468
535static int saa7134_ir_open(void *priv) 469static int saa7134_ir_open(struct rc_dev *rc)
536{ 470{
537 struct saa7134_dev *dev = priv; 471 struct saa7134_dev *dev = rc->priv;
538 472
539 dev->remote->users++; 473 dev->remote->users++;
540 return __saa7134_ir_start(dev); 474 return __saa7134_ir_start(dev);
541} 475}
542 476
543static void saa7134_ir_close(void *priv) 477static void saa7134_ir_close(struct rc_dev *rc)
544{ 478{
545 struct saa7134_dev *dev = priv; 479 struct saa7134_dev *dev = rc->priv;
546 480
547 dev->remote->users--; 481 dev->remote->users--;
548 if (!dev->remote->users) 482 if (!dev->remote->users)
549 __saa7134_ir_stop(dev); 483 __saa7134_ir_stop(dev);
550} 484}
551 485
552
553static int saa7134_ir_change_protocol(void *priv, u64 ir_type)
554{
555 struct saa7134_dev *dev = priv;
556 struct card_ir *ir = dev->remote;
557 u32 nec_gpio, rc5_gpio;
558
559 if (ir_type == IR_TYPE_RC5) {
560 dprintk("Changing protocol to RC5\n");
561 nec_gpio = 0;
562 rc5_gpio = 1;
563 } else if (ir_type == IR_TYPE_NEC) {
564 dprintk("Changing protocol to NEC\n");
565 nec_gpio = 1;
566 rc5_gpio = 0;
567 } else {
568 dprintk("IR protocol type %ud is not supported\n",
569 (unsigned)ir_type);
570 return -EINVAL;
571 }
572
573 if (ir->running) {
574 saa7134_ir_stop(dev);
575 ir->nec_gpio = nec_gpio;
576 ir->rc5_gpio = rc5_gpio;
577 saa7134_ir_start(dev);
578 } else {
579 ir->nec_gpio = nec_gpio;
580 ir->rc5_gpio = rc5_gpio;
581 }
582
583 return 0;
584}
585
586int saa7134_input_init1(struct saa7134_dev *dev) 486int saa7134_input_init1(struct saa7134_dev *dev)
587{ 487{
588 struct card_ir *ir; 488 struct saa7134_card_ir *ir;
589 struct input_dev *input_dev; 489 struct rc_dev *rc;
590 char *ir_codes = NULL; 490 char *ir_codes = NULL;
591 u32 mask_keycode = 0; 491 u32 mask_keycode = 0;
592 u32 mask_keydown = 0; 492 u32 mask_keydown = 0;
593 u32 mask_keyup = 0; 493 u32 mask_keyup = 0;
594 int polling = 0; 494 unsigned polling = 0;
595 int rc5_gpio = 0; 495 bool raw_decode = false;
596 int nec_gpio = 0;
597 int raw_decode = 0;
598 int allow_protocol_change = 0;
599 u64 ir_type = IR_TYPE_OTHER;
600 int err; 496 int err;
601 497
602 if (dev->has_remote != SAA7134_REMOTE_GPIO) 498 if (dev->has_remote != SAA7134_REMOTE_GPIO)
@@ -661,14 +557,14 @@ int saa7134_input_init1(struct saa7134_dev *dev)
661 mask_keydown = 0x0040000; /* Enable GPIO18 line on both edges */ 557 mask_keydown = 0x0040000; /* Enable GPIO18 line on both edges */
662 mask_keyup = 0x0040000; 558 mask_keyup = 0x0040000;
663 mask_keycode = 0xffff; 559 mask_keycode = 0xffff;
664 raw_decode = 1; 560 raw_decode = true;
665 break; 561 break;
666 case SAA7134_BOARD_AVERMEDIA_M733A: 562 case SAA7134_BOARD_AVERMEDIA_M733A:
667 ir_codes = RC_MAP_AVERMEDIA_M733A_RM_K6; 563 ir_codes = RC_MAP_AVERMEDIA_M733A_RM_K6;
668 mask_keydown = 0x0040000; 564 mask_keydown = 0x0040000;
669 mask_keyup = 0x0040000; 565 mask_keyup = 0x0040000;
670 mask_keycode = 0xffff; 566 mask_keycode = 0xffff;
671 raw_decode = 1; 567 raw_decode = true;
672 break; 568 break;
673 case SAA7134_BOARD_AVERMEDIA_777: 569 case SAA7134_BOARD_AVERMEDIA_777:
674 case SAA7134_BOARD_AVERMEDIA_A16AR: 570 case SAA7134_BOARD_AVERMEDIA_A16AR:
@@ -775,7 +671,7 @@ int saa7134_input_init1(struct saa7134_dev *dev)
775 mask_keydown = 0x0040000; /* Enable GPIO18 line on both edges */ 671 mask_keydown = 0x0040000; /* Enable GPIO18 line on both edges */
776 mask_keyup = 0x0040000; 672 mask_keyup = 0x0040000;
777 mask_keycode = 0xffff; 673 mask_keycode = 0xffff;
778 raw_decode = 1; 674 raw_decode = true;
779 break; 675 break;
780 case SAA7134_BOARD_ENCORE_ENLTV: 676 case SAA7134_BOARD_ENCORE_ENLTV:
781 case SAA7134_BOARD_ENCORE_ENLTV_FM: 677 case SAA7134_BOARD_ENCORE_ENLTV_FM:
@@ -786,9 +682,10 @@ int saa7134_input_init1(struct saa7134_dev *dev)
786 break; 682 break;
787 case SAA7134_BOARD_ENCORE_ENLTV_FM53: 683 case SAA7134_BOARD_ENCORE_ENLTV_FM53:
788 ir_codes = RC_MAP_ENCORE_ENLTV_FM53; 684 ir_codes = RC_MAP_ENCORE_ENLTV_FM53;
789 mask_keydown = 0x0040000; 685 mask_keydown = 0x0040000; /* Enable GPIO18 line on both edges */
790 mask_keycode = 0x00007f; 686 mask_keyup = 0x0040000;
791 nec_gpio = 1; 687 mask_keycode = 0xffff;
688 raw_decode = true;
792 break; 689 break;
793 case SAA7134_BOARD_10MOONSTVMASTER3: 690 case SAA7134_BOARD_10MOONSTVMASTER3:
794 ir_codes = RC_MAP_ENCORE_ENLTV; 691 ir_codes = RC_MAP_ENCORE_ENLTV;
@@ -824,6 +721,11 @@ int saa7134_input_init1(struct saa7134_dev *dev)
824 mask_keyup = 0x020000; 721 mask_keyup = 0x020000;
825 polling = 50; /* ms */ 722 polling = 50; /* ms */
826 break; 723 break;
724 case SAA7134_BOARD_VIDEOMATE_M1F:
725 ir_codes = RC_MAP_VIDEOMATE_M1F;
726 mask_keycode = 0x0ff00;
727 mask_keyup = 0x040000;
728 break;
827 } 729 }
828 if (NULL == ir_codes) { 730 if (NULL == ir_codes) {
829 printk("%s: Oops: IR config error [card=%d]\n", 731 printk("%s: Oops: IR config error [card=%d]\n",
@@ -832,24 +734,20 @@ int saa7134_input_init1(struct saa7134_dev *dev)
832 } 734 }
833 735
834 ir = kzalloc(sizeof(*ir), GFP_KERNEL); 736 ir = kzalloc(sizeof(*ir), GFP_KERNEL);
835 input_dev = input_allocate_device(); 737 rc = rc_allocate_device();
836 if (!ir || !input_dev) { 738 if (!ir || !rc) {
837 err = -ENOMEM; 739 err = -ENOMEM;
838 goto err_out_free; 740 goto err_out_free;
839 } 741 }
840 742
841 ir->dev = input_dev; 743 ir->dev = rc;
842 dev->remote = ir; 744 dev->remote = ir;
843 745
844 ir->running = 0;
845
846 /* init hardware-specific stuff */ 746 /* init hardware-specific stuff */
847 ir->mask_keycode = mask_keycode; 747 ir->mask_keycode = mask_keycode;
848 ir->mask_keydown = mask_keydown; 748 ir->mask_keydown = mask_keydown;
849 ir->mask_keyup = mask_keyup; 749 ir->mask_keyup = mask_keyup;
850 ir->polling = polling; 750 ir->polling = polling;
851 ir->rc5_gpio = rc5_gpio;
852 ir->nec_gpio = nec_gpio;
853 ir->raw_decode = raw_decode; 751 ir->raw_decode = raw_decode;
854 752
855 /* init input device */ 753 /* init input device */
@@ -858,47 +756,35 @@ int saa7134_input_init1(struct saa7134_dev *dev)
858 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0", 756 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0",
859 pci_name(dev->pci)); 757 pci_name(dev->pci));
860 758
861 759 rc->priv = dev;
862 ir->props.priv = dev; 760 rc->open = saa7134_ir_open;
863 ir->props.open = saa7134_ir_open; 761 rc->close = saa7134_ir_close;
864 ir->props.close = saa7134_ir_close;
865
866 if (raw_decode) 762 if (raw_decode)
867 ir->props.driver_type = RC_DRIVER_IR_RAW; 763 rc->driver_type = RC_DRIVER_IR_RAW;
868
869 if (!raw_decode && allow_protocol_change) {
870 ir->props.allowed_protos = IR_TYPE_RC5 | IR_TYPE_NEC;
871 ir->props.change_protocol = saa7134_ir_change_protocol;
872 }
873
874 err = ir_input_init(input_dev, &ir->ir, ir_type);
875 if (err < 0)
876 goto err_out_free;
877 764
878 input_dev->name = ir->name; 765 rc->input_name = ir->name;
879 input_dev->phys = ir->phys; 766 rc->input_phys = ir->phys;
880 input_dev->id.bustype = BUS_PCI; 767 rc->input_id.bustype = BUS_PCI;
881 input_dev->id.version = 1; 768 rc->input_id.version = 1;
882 if (dev->pci->subsystem_vendor) { 769 if (dev->pci->subsystem_vendor) {
883 input_dev->id.vendor = dev->pci->subsystem_vendor; 770 rc->input_id.vendor = dev->pci->subsystem_vendor;
884 input_dev->id.product = dev->pci->subsystem_device; 771 rc->input_id.product = dev->pci->subsystem_device;
885 } else { 772 } else {
886 input_dev->id.vendor = dev->pci->vendor; 773 rc->input_id.vendor = dev->pci->vendor;
887 input_dev->id.product = dev->pci->device; 774 rc->input_id.product = dev->pci->device;
888 } 775 }
889 input_dev->dev.parent = &dev->pci->dev; 776 rc->dev.parent = &dev->pci->dev;
777 rc->map_name = ir_codes;
778 rc->driver_name = MODULE_NAME;
890 779
891 err = ir_input_register(ir->dev, ir_codes, &ir->props, MODULE_NAME); 780 err = rc_register_device(rc);
892 if (err) 781 if (err)
893 goto err_out_free; 782 goto err_out_free;
894 783
895 /* the remote isn't as bouncy as a keyboard */
896 ir->dev->rep[REP_DELAY] = repeat_delay;
897 ir->dev->rep[REP_PERIOD] = repeat_period;
898
899 return 0; 784 return 0;
900 785
901err_out_free: 786err_out_free:
787 rc_free_device(rc);
902 dev->remote = NULL; 788 dev->remote = NULL;
903 kfree(ir); 789 kfree(ir);
904 return err; 790 return err;
@@ -910,7 +796,7 @@ void saa7134_input_fini(struct saa7134_dev *dev)
910 return; 796 return;
911 797
912 saa7134_ir_stop(dev); 798 saa7134_ir_stop(dev);
913 ir_input_unregister(dev->remote->dev); 799 rc_unregister_device(dev->remote->dev);
914 kfree(dev->remote); 800 kfree(dev->remote);
915 dev->remote = NULL; 801 dev->remote = NULL;
916} 802}
@@ -918,14 +804,12 @@ void saa7134_input_fini(struct saa7134_dev *dev)
918void saa7134_probe_i2c_ir(struct saa7134_dev *dev) 804void saa7134_probe_i2c_ir(struct saa7134_dev *dev)
919{ 805{
920 struct i2c_board_info info; 806 struct i2c_board_info info;
921
922 struct i2c_msg msg_msi = { 807 struct i2c_msg msg_msi = {
923 .addr = 0x50, 808 .addr = 0x50,
924 .flags = I2C_M_RD, 809 .flags = I2C_M_RD,
925 .len = 0, 810 .len = 0,
926 .buf = NULL, 811 .buf = NULL,
927 }; 812 };
928
929 int rc; 813 int rc;
930 814
931 if (disable_ir) { 815 if (disable_ir) {
@@ -972,7 +856,7 @@ void saa7134_probe_i2c_ir(struct saa7134_dev *dev)
972 an existing device. Weird... 856 an existing device. Weird...
973 REVISIT: might no longer be needed */ 857 REVISIT: might no longer be needed */
974 rc = i2c_transfer(&dev->i2c_adap, &msg_msi, 1); 858 rc = i2c_transfer(&dev->i2c_adap, &msg_msi, 1);
975 dprintk(KERN_DEBUG "probe 0x%02x @ %s: %s\n", 859 dprintk("probe 0x%02x @ %s: %s\n",
976 msg_msi.addr, dev->i2c_adap.name, 860 msg_msi.addr, dev->i2c_adap.name,
977 (1 == rc) ? "yes" : "no"); 861 (1 == rc) ? "yes" : "no");
978 break; 862 break;
@@ -1000,7 +884,7 @@ void saa7134_probe_i2c_ir(struct saa7134_dev *dev)
1000 dev->init_data.name = "BeholdTV"; 884 dev->init_data.name = "BeholdTV";
1001 dev->init_data.get_key = get_key_beholdm6xx; 885 dev->init_data.get_key = get_key_beholdm6xx;
1002 dev->init_data.ir_codes = RC_MAP_BEHOLD; 886 dev->init_data.ir_codes = RC_MAP_BEHOLD;
1003 dev->init_data.type = IR_TYPE_NEC; 887 dev->init_data.type = RC_TYPE_NEC;
1004 info.addr = 0x2d; 888 info.addr = 0x2d;
1005 break; 889 break;
1006 case SAA7134_BOARD_AVERMEDIA_CARDBUS_501: 890 case SAA7134_BOARD_AVERMEDIA_CARDBUS_501:
@@ -1025,8 +909,8 @@ void saa7134_probe_i2c_ir(struct saa7134_dev *dev)
1025 909
1026static int saa7134_raw_decode_irq(struct saa7134_dev *dev) 910static int saa7134_raw_decode_irq(struct saa7134_dev *dev)
1027{ 911{
1028 struct card_ir *ir = dev->remote; 912 struct saa7134_card_ir *ir = dev->remote;
1029 unsigned long timeout; 913 unsigned long timeout;
1030 int space; 914 int space;
1031 915
1032 /* Generate initial event */ 916 /* Generate initial event */
@@ -1035,7 +919,6 @@ static int saa7134_raw_decode_irq(struct saa7134_dev *dev)
1035 space = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2) & ir->mask_keydown; 919 space = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2) & ir->mask_keydown;
1036 ir_raw_event_store_edge(dev->remote->dev, space ? IR_SPACE : IR_PULSE); 920 ir_raw_event_store_edge(dev->remote->dev, space ? IR_SPACE : IR_PULSE);
1037 921
1038
1039 /* 922 /*
1040 * Wait 15 ms from the start of the first IR event before processing 923 * Wait 15 ms from the start of the first IR event before processing
1041 * the event. This time is enough for NEC protocol. May need adjustments 924 * the event. This time is enough for NEC protocol. May need adjustments
@@ -1043,173 +926,9 @@ static int saa7134_raw_decode_irq(struct saa7134_dev *dev)
1043 */ 926 */
1044 if (!ir->active) { 927 if (!ir->active) {
1045 timeout = jiffies + jiffies_to_msecs(15); 928 timeout = jiffies + jiffies_to_msecs(15);
1046 mod_timer(&ir->timer_end, timeout); 929 mod_timer(&ir->timer, timeout);
1047 ir->active = 1; 930 ir->active = true;
1048 } 931 }
1049 932
1050 return 1; 933 return 1;
1051} 934}
1052
1053static int saa7134_rc5_irq(struct saa7134_dev *dev)
1054{
1055 struct card_ir *ir = dev->remote;
1056 struct timeval tv;
1057 u32 gap;
1058 unsigned long current_jiffies, timeout;
1059
1060 /* get time of bit */
1061 current_jiffies = jiffies;
1062 do_gettimeofday(&tv);
1063
1064 /* avoid overflow with gap >1s */
1065 if (tv.tv_sec - ir->base_time.tv_sec > 1) {
1066 gap = 200000;
1067 } else {
1068 gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
1069 tv.tv_usec - ir->base_time.tv_usec;
1070 }
1071
1072 /* active code => add bit */
1073 if (ir->active) {
1074 /* only if in the code (otherwise spurious IRQ or timer
1075 late) */
1076 if (ir->last_bit < 28) {
1077 ir->last_bit = (gap - ir_rc5_remote_gap / 2) /
1078 ir_rc5_remote_gap;
1079 ir->code |= 1 << ir->last_bit;
1080 }
1081 /* starting new code */
1082 } else {
1083 ir->active = 1;
1084 ir->code = 0;
1085 ir->base_time = tv;
1086 ir->last_bit = 0;
1087
1088 timeout = current_jiffies + (500 + 30 * HZ) / 1000;
1089 mod_timer(&ir->timer_end, timeout);
1090 }
1091
1092 return 1;
1093}
1094
1095/* On NEC protocol, One has 2.25 ms, and zero has 1.125 ms
1096 The first pulse (start) has 9 + 4.5 ms
1097 */
1098
1099static void saa7134_nec_timer(unsigned long data)
1100{
1101 struct saa7134_dev *dev = (struct saa7134_dev *) data;
1102 struct card_ir *ir = dev->remote;
1103
1104 dprintk("Cancel key repeat\n");
1105
1106 ir_input_nokey(ir->dev, &ir->ir);
1107}
1108
1109static void nec_task(unsigned long data)
1110{
1111 struct saa7134_dev *dev = (struct saa7134_dev *) data;
1112 struct card_ir *ir;
1113 struct timeval tv;
1114 int count, pulse, oldpulse, gap;
1115 u32 ircode = 0, not_code = 0;
1116 int ngap = 0;
1117
1118 if (!data) {
1119 printk(KERN_ERR "saa713x/ir: Can't recover dev struct\n");
1120 /* GPIO will be kept disabled */
1121 return;
1122 }
1123
1124 ir = dev->remote;
1125
1126 /* rising SAA7134_GPIO_GPRESCAN reads the status */
1127 saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
1128 saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
1129
1130 oldpulse = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2) & ir->mask_keydown;
1131 pulse = oldpulse;
1132
1133 do_gettimeofday(&tv);
1134 ir->base_time = tv;
1135
1136 /* Decode NEC pulsecode. This code can take up to 76.5 ms to run.
1137 Unfortunately, using IRQ to decode pulse didn't work, since it uses
1138 a pulse train of 38KHz. This means one pulse on each 52 us
1139 */
1140 do {
1141 /* Wait until the end of pulse/space or 5 ms */
1142 for (count = 0; count < 500; count++) {
1143 udelay(10);
1144 /* rising SAA7134_GPIO_GPRESCAN reads the status */
1145 saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
1146 saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
1147 pulse = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2)
1148 & ir->mask_keydown;
1149 if (pulse != oldpulse)
1150 break;
1151 }
1152
1153 do_gettimeofday(&tv);
1154 gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
1155 tv.tv_usec - ir->base_time.tv_usec;
1156
1157 if (!pulse) {
1158 /* Bit 0 has 560 us, while bit 1 has 1120 us.
1159 Do something only if bit == 1
1160 */
1161 if (ngap && (gap > 560 + 280)) {
1162 unsigned int shift = ngap - 1;
1163
1164 /* Address first, then command */
1165 if (shift < 8) {
1166 shift += 8;
1167 ircode |= 1 << shift;
1168 } else if (shift < 16) {
1169 not_code |= 1 << shift;
1170 } else if (shift < 24) {
1171 shift -= 16;
1172 ircode |= 1 << shift;
1173 } else {
1174 shift -= 24;
1175 not_code |= 1 << shift;
1176 }
1177 }
1178 ngap++;
1179 }
1180
1181
1182 ir->base_time = tv;
1183
1184 /* TIMEOUT - Long pulse */
1185 if (gap >= 5000)
1186 break;
1187 oldpulse = pulse;
1188 } while (ngap < 32);
1189
1190 if (ngap == 32) {
1191 /* FIXME: should check if not_code == ~ircode */
1192 ir->code = ir_extract_bits(ircode, ir->mask_keycode);
1193
1194 dprintk("scancode = 0x%02x (code = 0x%02x, notcode= 0x%02x)\n",
1195 ir->code, ircode, not_code);
1196
1197 ir_input_keydown(ir->dev, &ir->ir, ir->code);
1198 } else
1199 dprintk("Repeat last key\n");
1200
1201 /* Keep repeating the last key */
1202 mod_timer(&ir->timer_keyup, jiffies + msecs_to_jiffies(150));
1203
1204 saa_setl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18_P);
1205}
1206
1207static int saa7134_nec_irq(struct saa7134_dev *dev)
1208{
1209 struct card_ir *ir = dev->remote;
1210
1211 saa_clearl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18_P);
1212 tasklet_schedule(&ir->tlet);
1213
1214 return 1;
1215}
diff --git a/drivers/media/video/saa7134/saa7134-tvaudio.c b/drivers/media/video/saa7134/saa7134-tvaudio.c
index 3e7d2fd1688f..57e646bb48b3 100644
--- a/drivers/media/video/saa7134/saa7134-tvaudio.c
+++ b/drivers/media/video/saa7134/saa7134-tvaudio.c
@@ -550,16 +550,16 @@ static int tvaudio_thread(void *data)
550 } else if (0 != dev->last_carrier) { 550 } else if (0 != dev->last_carrier) {
551 /* no carrier -- try last detected one as fallback */ 551 /* no carrier -- try last detected one as fallback */
552 carrier = dev->last_carrier; 552 carrier = dev->last_carrier;
553 dprintk(KERN_WARNING "%s/audio: audio carrier scan failed, " 553 dprintk("audio carrier scan failed, "
554 "using %d.%03d MHz [last detected]\n", 554 "using %d.%03d MHz [last detected]\n",
555 dev->name, carrier/1000, carrier%1000); 555 carrier/1000, carrier%1000);
556 556
557 } else { 557 } else {
558 /* no carrier + no fallback -- use default */ 558 /* no carrier + no fallback -- use default */
559 carrier = default_carrier; 559 carrier = default_carrier;
560 dprintk(KERN_WARNING "%s/audio: audio carrier scan failed, " 560 dprintk("audio carrier scan failed, "
561 "using %d.%03d MHz [default]\n", 561 "using %d.%03d MHz [default]\n",
562 dev->name, carrier/1000, carrier%1000); 562 carrier/1000, carrier%1000);
563 } 563 }
564 tvaudio_setcarrier(dev,carrier,carrier); 564 tvaudio_setcarrier(dev,carrier,carrier);
565 dev->automute = 0; 565 dev->automute = 0;
diff --git a/drivers/media/video/saa7134/saa7134-video.c b/drivers/media/video/saa7134/saa7134-video.c
index f0b1573137f4..776ba2dd7f9f 100644
--- a/drivers/media/video/saa7134/saa7134-video.c
+++ b/drivers/media/video/saa7134/saa7134-video.c
@@ -30,7 +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#include <media/rds.h> 33#include <media/saa6588.h>
34 34
35/* ------------------------------------------------------------------ */ 35/* ------------------------------------------------------------------ */
36 36
@@ -1459,7 +1459,7 @@ static int video_release(struct file *file)
1459{ 1459{
1460 struct saa7134_fh *fh = file->private_data; 1460 struct saa7134_fh *fh = file->private_data;
1461 struct saa7134_dev *dev = fh->dev; 1461 struct saa7134_dev *dev = fh->dev;
1462 struct rds_command cmd; 1462 struct saa6588_command cmd;
1463 unsigned long flags; 1463 unsigned long flags;
1464 1464
1465 /* turn off overlay */ 1465 /* turn off overlay */
@@ -1494,7 +1494,7 @@ static int video_release(struct file *file)
1494 1494
1495 saa_call_all(dev, core, s_power, 0); 1495 saa_call_all(dev, core, s_power, 0);
1496 if (fh->radio) 1496 if (fh->radio)
1497 saa_call_all(dev, core, ioctl, RDS_CMD_CLOSE, &cmd); 1497 saa_call_all(dev, core, ioctl, SAA6588_CMD_CLOSE, &cmd);
1498 1498
1499 /* free stuff */ 1499 /* free stuff */
1500 videobuf_mmap_free(&fh->cap); 1500 videobuf_mmap_free(&fh->cap);
@@ -1520,14 +1520,14 @@ static ssize_t radio_read(struct file *file, char __user *data,
1520{ 1520{
1521 struct saa7134_fh *fh = file->private_data; 1521 struct saa7134_fh *fh = file->private_data;
1522 struct saa7134_dev *dev = fh->dev; 1522 struct saa7134_dev *dev = fh->dev;
1523 struct rds_command cmd; 1523 struct saa6588_command cmd;
1524 1524
1525 cmd.block_count = count/3; 1525 cmd.block_count = count/3;
1526 cmd.buffer = data; 1526 cmd.buffer = data;
1527 cmd.instance = file; 1527 cmd.instance = file;
1528 cmd.result = -ENODEV; 1528 cmd.result = -ENODEV;
1529 1529
1530 saa_call_all(dev, core, ioctl, RDS_CMD_READ, &cmd); 1530 saa_call_all(dev, core, ioctl, SAA6588_CMD_READ, &cmd);
1531 1531
1532 return cmd.result; 1532 return cmd.result;
1533} 1533}
@@ -1536,12 +1536,12 @@ static unsigned int radio_poll(struct file *file, poll_table *wait)
1536{ 1536{
1537 struct saa7134_fh *fh = file->private_data; 1537 struct saa7134_fh *fh = file->private_data;
1538 struct saa7134_dev *dev = fh->dev; 1538 struct saa7134_dev *dev = fh->dev;
1539 struct rds_command cmd; 1539 struct saa6588_command cmd;
1540 1540
1541 cmd.instance = file; 1541 cmd.instance = file;
1542 cmd.event_list = wait; 1542 cmd.event_list = wait;
1543 cmd.result = -ENODEV; 1543 cmd.result = -ENODEV;
1544 saa_call_all(dev, core, ioctl, RDS_CMD_POLL, &cmd); 1544 saa_call_all(dev, core, ioctl, SAA6588_CMD_POLL, &cmd);
1545 1545
1546 return cmd.result; 1546 return cmd.result;
1547} 1547}
@@ -1748,7 +1748,6 @@ static int saa7134_enum_input(struct file *file, void *priv,
1748 return -EINVAL; 1748 return -EINVAL;
1749 if (NULL == card_in(dev, i->index).name) 1749 if (NULL == card_in(dev, i->index).name)
1750 return -EINVAL; 1750 return -EINVAL;
1751 memset(i, 0, sizeof(*i));
1752 i->index = n; 1751 i->index = n;
1753 i->type = V4L2_INPUT_TYPE_CAMERA; 1752 i->type = V4L2_INPUT_TYPE_CAMERA;
1754 strcpy(i->name, card_in(dev, n).name); 1753 strcpy(i->name, card_in(dev, n).name);
@@ -2211,14 +2210,6 @@ static int saa7134_overlay(struct file *file, void *f, unsigned int on)
2211 return 0; 2210 return 0;
2212} 2211}
2213 2212
2214#ifdef CONFIG_VIDEO_V4L1_COMPAT
2215static int vidiocgmbuf(struct file *file, void *priv, struct video_mbuf *mbuf)
2216{
2217 struct saa7134_fh *fh = file->private_data;
2218 return videobuf_cgmbuf(saa7134_queue(fh), mbuf, 8);
2219}
2220#endif
2221
2222static int saa7134_reqbufs(struct file *file, void *priv, 2213static int saa7134_reqbufs(struct file *file, void *priv,
2223 struct v4l2_requestbuffers *p) 2214 struct v4l2_requestbuffers *p)
2224{ 2215{
@@ -2456,9 +2447,6 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
2456 .vidioc_streamoff = saa7134_streamoff, 2447 .vidioc_streamoff = saa7134_streamoff,
2457 .vidioc_g_tuner = saa7134_g_tuner, 2448 .vidioc_g_tuner = saa7134_g_tuner,
2458 .vidioc_s_tuner = saa7134_s_tuner, 2449 .vidioc_s_tuner = saa7134_s_tuner,
2459#ifdef CONFIG_VIDEO_V4L1_COMPAT
2460 .vidiocgmbuf = vidiocgmbuf,
2461#endif
2462 .vidioc_g_crop = saa7134_g_crop, 2450 .vidioc_g_crop = saa7134_g_crop,
2463 .vidioc_s_crop = saa7134_s_crop, 2451 .vidioc_s_crop = saa7134_s_crop,
2464 .vidioc_g_fbuf = saa7134_g_fbuf, 2452 .vidioc_g_fbuf = saa7134_g_fbuf,
diff --git a/drivers/media/video/saa7134/saa7134.h b/drivers/media/video/saa7134/saa7134.h
index d3b6a196e5dc..5b0a347b0b8f 100644
--- a/drivers/media/video/saa7134/saa7134.h
+++ b/drivers/media/video/saa7134/saa7134.h
@@ -37,7 +37,7 @@
37#include <media/v4l2-ioctl.h> 37#include <media/v4l2-ioctl.h>
38#include <media/v4l2-device.h> 38#include <media/v4l2-device.h>
39#include <media/tuner.h> 39#include <media/tuner.h>
40#include <media/ir-common.h> 40#include <media/rc-core.h>
41#include <media/ir-kbd-i2c.h> 41#include <media/ir-kbd-i2c.h>
42#include <media/videobuf-dma-sg.h> 42#include <media/videobuf-dma-sg.h>
43#include <sound/core.h> 43#include <sound/core.h>
@@ -119,6 +119,26 @@ struct saa7134_format {
119 unsigned int uvswap:1; 119 unsigned int uvswap:1;
120}; 120};
121 121
122struct saa7134_card_ir {
123 struct rc_dev *dev;
124
125 char name[32];
126 char phys[32];
127 unsigned users;
128
129 u32 polling;
130 u32 last_gpio;
131 u32 mask_keycode, mask_keydown, mask_keyup;
132
133 bool running;
134 bool active;
135
136 struct timer_list timer;
137
138 /* IR core raw decoding */
139 u32 raw_decode;
140};
141
122/* ----------------------------------------------------------- */ 142/* ----------------------------------------------------------- */
123/* card configuration */ 143/* card configuration */
124 144
@@ -305,6 +325,8 @@ struct saa7134_format {
305#define SAA7134_BOARD_BEHOLD_A7 179 325#define SAA7134_BOARD_BEHOLD_A7 179
306#define SAA7134_BOARD_AVERMEDIA_M733A 180 326#define SAA7134_BOARD_AVERMEDIA_M733A 180
307#define SAA7134_BOARD_TECHNOTREND_BUDGET_T3000 181 327#define SAA7134_BOARD_TECHNOTREND_BUDGET_T3000 181
328#define SAA7134_BOARD_KWORLD_PCI_SBTVD_FULLSEG 182
329#define SAA7134_BOARD_VIDEOMATE_M1F 183
308 330
309#define SAA7134_MAXBOARDS 32 331#define SAA7134_MAXBOARDS 32
310#define SAA7134_INPUT_MAX 8 332#define SAA7134_INPUT_MAX 8
@@ -529,7 +551,7 @@ struct saa7134_dev {
529 551
530 /* infrared remote */ 552 /* infrared remote */
531 int has_remote; 553 int has_remote;
532 struct card_ir *remote; 554 struct saa7134_card_ir *remote;
533 555
534 /* pci i/o */ 556 /* pci i/o */
535 char name[32]; 557 char name[32];
diff --git a/drivers/media/video/saa7164/saa7164-api.c b/drivers/media/video/saa7164/saa7164-api.c
index ad3bc4154176..bd86d970f4c2 100644
--- a/drivers/media/video/saa7164/saa7164-api.c
+++ b/drivers/media/video/saa7164/saa7164-api.c
@@ -40,9 +40,8 @@ int saa7164_api_get_load_info(struct saa7164_dev *dev, struct tmFwInfoStruct *i)
40 40
41 ret = saa7164_cmd_send(dev, 0, GET_CUR, 41 ret = saa7164_cmd_send(dev, 0, GET_CUR,
42 GET_FW_STATUS_CONTROL, sizeof(struct tmFwInfoStruct), i); 42 GET_FW_STATUS_CONTROL, sizeof(struct tmFwInfoStruct), i);
43 if (ret != SAA_OK) { 43 if (ret != SAA_OK)
44 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); 44 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
45 }
46 45
47 printk(KERN_INFO "saa7164[%d]-CPU: %d percent", dev->nr, i->CPULoad); 46 printk(KERN_INFO "saa7164[%d]-CPU: %d percent", dev->nr, i->CPULoad);
48 47
@@ -63,14 +62,15 @@ int saa7164_api_collect_debug(struct saa7164_dev *dev)
63 62
64 ret = saa7164_cmd_send(dev, 0, GET_CUR, 63 ret = saa7164_cmd_send(dev, 0, GET_CUR,
65 GET_DEBUG_DATA_CONTROL, sizeof(d), &d); 64 GET_DEBUG_DATA_CONTROL, sizeof(d), &d);
66 if (ret != SAA_OK) { 65 if (ret != SAA_OK)
67 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); 66 printk(KERN_ERR "%s() error, ret = 0x%x\n",
68 } 67 __func__, ret);
69 68
70 if (d.dwResult != SAA_OK) 69 if (d.dwResult != SAA_OK)
71 break; 70 break;
72 71
73 printk(KERN_INFO "saa7164[%d]-FWMSG: %s", dev->nr, d.ucDebugData); 72 printk(KERN_INFO "saa7164[%d]-FWMSG: %s", dev->nr,
73 d.ucDebugData);
74 } 74 }
75 75
76 return 0; 76 return 0;
@@ -86,9 +86,9 @@ int saa7164_api_set_debug(struct saa7164_dev *dev, u8 level)
86 /* Retrieve current state */ 86 /* Retrieve current state */
87 ret = saa7164_cmd_send(dev, 0, GET_CUR, 87 ret = saa7164_cmd_send(dev, 0, GET_CUR,
88 SET_DEBUG_LEVEL_CONTROL, sizeof(lvl), &lvl); 88 SET_DEBUG_LEVEL_CONTROL, sizeof(lvl), &lvl);
89 if (ret != SAA_OK) { 89 if (ret != SAA_OK)
90 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); 90 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
91 } 91
92 dprintk(DBGLVL_API, "%s() Was %d\n", __func__, lvl.dwDebugLevel); 92 dprintk(DBGLVL_API, "%s() Was %d\n", __func__, lvl.dwDebugLevel);
93 93
94 lvl.dwDebugLevel = level; 94 lvl.dwDebugLevel = level;
@@ -96,9 +96,8 @@ int saa7164_api_set_debug(struct saa7164_dev *dev, u8 level)
96 /* set new state */ 96 /* set new state */
97 ret = saa7164_cmd_send(dev, 0, SET_CUR, 97 ret = saa7164_cmd_send(dev, 0, SET_CUR,
98 SET_DEBUG_LEVEL_CONTROL, sizeof(lvl), &lvl); 98 SET_DEBUG_LEVEL_CONTROL, sizeof(lvl), &lvl);
99 if (ret != SAA_OK) { 99 if (ret != SAA_OK)
100 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); 100 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
101 }
102 101
103 return ret; 102 return ret;
104} 103}
@@ -152,8 +151,10 @@ int saa7164_api_set_vbi_format(struct saa7164_port *port)
152 dprintk(DBGLVL_API, "SET/COMMIT Verified\n"); 151 dprintk(DBGLVL_API, "SET/COMMIT Verified\n");
153 152
154 dprintk(DBGLVL_API, "rsp.bmHint = 0x%x\n", rsp.bmHint); 153 dprintk(DBGLVL_API, "rsp.bmHint = 0x%x\n", rsp.bmHint);
155 dprintk(DBGLVL_API, "rsp.bFormatIndex = 0x%x\n", rsp.bFormatIndex); 154 dprintk(DBGLVL_API, "rsp.bFormatIndex = 0x%x\n",
156 dprintk(DBGLVL_API, "rsp.bFrameIndex = 0x%x\n", rsp.bFrameIndex); 155 rsp.bFormatIndex);
156 dprintk(DBGLVL_API, "rsp.bFrameIndex = 0x%x\n",
157 rsp.bFrameIndex);
157 } else 158 } else
158 printk(KERN_ERR "%s() compare failed\n", __func__); 159 printk(KERN_ERR "%s() compare failed\n", __func__);
159 } 160 }
@@ -210,14 +211,17 @@ int saa7164_api_set_encoder(struct saa7164_port *port)
210 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); 211 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
211 212
212 /* Establish video bitrates */ 213 /* Establish video bitrates */
213 if (port->encoder_params.bitrate_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_CBR) 214 if (port->encoder_params.bitrate_mode ==
215 V4L2_MPEG_VIDEO_BITRATE_MODE_CBR)
214 vb.ucVideoBitRateMode = EU_VIDEO_BIT_RATE_MODE_CONSTANT; 216 vb.ucVideoBitRateMode = EU_VIDEO_BIT_RATE_MODE_CONSTANT;
215 else 217 else
216 vb.ucVideoBitRateMode = EU_VIDEO_BIT_RATE_MODE_VARIABLE_PEAK; 218 vb.ucVideoBitRateMode = EU_VIDEO_BIT_RATE_MODE_VARIABLE_PEAK;
217 vb.dwVideoBitRate = port->encoder_params.bitrate; 219 vb.dwVideoBitRate = port->encoder_params.bitrate;
218 vb.dwVideoBitRatePeak = port->encoder_params.bitrate_peak; 220 vb.dwVideoBitRatePeak = port->encoder_params.bitrate_peak;
219 ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, SET_CUR, 221 ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, SET_CUR,
220 EU_VIDEO_BIT_RATE_CONTROL, sizeof(struct tmComResEncVideoBitRate), &vb); 222 EU_VIDEO_BIT_RATE_CONTROL,
223 sizeof(struct tmComResEncVideoBitRate),
224 &vb);
221 if (ret != SAA_OK) 225 if (ret != SAA_OK)
222 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); 226 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
223 227
@@ -226,9 +230,12 @@ int saa7164_api_set_encoder(struct saa7164_port *port)
226 ab.dwAudioBitRate = 384000; 230 ab.dwAudioBitRate = 384000;
227 ab.dwAudioBitRatePeak = ab.dwAudioBitRate; 231 ab.dwAudioBitRatePeak = ab.dwAudioBitRate;
228 ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, SET_CUR, 232 ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, SET_CUR,
229 EU_AUDIO_BIT_RATE_CONTROL, sizeof(struct tmComResEncAudioBitRate), &ab); 233 EU_AUDIO_BIT_RATE_CONTROL,
234 sizeof(struct tmComResEncAudioBitRate),
235 &ab);
230 if (ret != SAA_OK) 236 if (ret != SAA_OK)
231 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); 237 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__,
238 ret);
232 239
233 saa7164_api_set_aspect_ratio(port); 240 saa7164_api_set_aspect_ratio(port);
234 saa7164_api_set_gop_size(port); 241 saa7164_api_set_gop_size(port);
@@ -244,7 +251,8 @@ int saa7164_api_get_encoder(struct saa7164_port *port)
244 struct tmComResEncVideoInputAspectRatio ar; 251 struct tmComResEncVideoInputAspectRatio ar;
245 int ret; 252 int ret;
246 253
247 dprintk(DBGLVL_ENC, "%s() unitid=0x%x\n", __func__, port->hwcfg.sourceid); 254 dprintk(DBGLVL_ENC, "%s() unitid=0x%x\n", __func__,
255 port->hwcfg.sourceid);
248 256
249 port->encoder_profile = 0; 257 port->encoder_profile = 0;
250 port->video_format = 0; 258 port->video_format = 0;
@@ -257,7 +265,8 @@ int saa7164_api_get_encoder(struct saa7164_port *port)
257 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); 265 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
258 266
259 ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, GET_CUR, 267 ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, GET_CUR,
260 EU_VIDEO_RESOLUTION_CONTROL, sizeof(u8), &port->video_resolution); 268 EU_VIDEO_RESOLUTION_CONTROL, sizeof(u8),
269 &port->video_resolution);
261 if (ret != SAA_OK) 270 if (ret != SAA_OK)
262 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); 271 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
263 272
@@ -294,13 +303,20 @@ int saa7164_api_get_encoder(struct saa7164_port *port)
294 dprintk(DBGLVL_ENC, "video_format = %d\n", port->video_format); 303 dprintk(DBGLVL_ENC, "video_format = %d\n", port->video_format);
295 dprintk(DBGLVL_ENC, "audio_format = %d\n", port->audio_format); 304 dprintk(DBGLVL_ENC, "audio_format = %d\n", port->audio_format);
296 dprintk(DBGLVL_ENC, "video_resolution= %d\n", port->video_resolution); 305 dprintk(DBGLVL_ENC, "video_resolution= %d\n", port->video_resolution);
297 dprintk(DBGLVL_ENC, "v.ucVideoBitRateMode = %d\n", v.ucVideoBitRateMode); 306 dprintk(DBGLVL_ENC, "v.ucVideoBitRateMode = %d\n",
298 dprintk(DBGLVL_ENC, "v.dwVideoBitRate = %d\n", v.dwVideoBitRate); 307 v.ucVideoBitRateMode);
299 dprintk(DBGLVL_ENC, "v.dwVideoBitRatePeak = %d\n", v.dwVideoBitRatePeak); 308 dprintk(DBGLVL_ENC, "v.dwVideoBitRate = %d\n",
300 dprintk(DBGLVL_ENC, "a.ucVideoBitRateMode = %d\n", a.ucAudioBitRateMode); 309 v.dwVideoBitRate);
301 dprintk(DBGLVL_ENC, "a.dwVideoBitRate = %d\n", a.dwAudioBitRate); 310 dprintk(DBGLVL_ENC, "v.dwVideoBitRatePeak = %d\n",
302 dprintk(DBGLVL_ENC, "a.dwVideoBitRatePeak = %d\n", a.dwAudioBitRatePeak); 311 v.dwVideoBitRatePeak);
303 dprintk(DBGLVL_ENC, "aspect.width / height = %d:%d\n", ar.width, ar.height); 312 dprintk(DBGLVL_ENC, "a.ucVideoBitRateMode = %d\n",
313 a.ucAudioBitRateMode);
314 dprintk(DBGLVL_ENC, "a.dwVideoBitRate = %d\n",
315 a.dwAudioBitRate);
316 dprintk(DBGLVL_ENC, "a.dwVideoBitRatePeak = %d\n",
317 a.dwAudioBitRatePeak);
318 dprintk(DBGLVL_ENC, "aspect.width / height = %d:%d\n",
319 ar.width, ar.height);
304 320
305 return ret; 321 return ret;
306} 322}
@@ -439,7 +455,8 @@ int saa7164_api_set_videomux(struct saa7164_port *port)
439 455
440 /* Audio Mux */ 456 /* Audio Mux */
441 ret = saa7164_cmd_send(port->dev, port->audfeat.sourceid, SET_CUR, 457 ret = saa7164_cmd_send(port->dev, port->audfeat.sourceid, SET_CUR,
442 SU_INPUT_SELECT_CONTROL, sizeof(u8), &inputs[port->mux_input - 1]); 458 SU_INPUT_SELECT_CONTROL, sizeof(u8),
459 &inputs[port->mux_input - 1]);
443 if (ret != SAA_OK) 460 if (ret != SAA_OK)
444 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); 461 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
445 462
@@ -492,7 +509,8 @@ int saa7164_api_set_audio_volume(struct saa7164_port *port, s8 level)
492 if (ret != SAA_OK) 509 if (ret != SAA_OK)
493 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); 510 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
494 511
495 dprintk(DBGLVL_API, "%s(%d) min=%d max=%d cur=%d\n", __func__, level, min, max, v); 512 dprintk(DBGLVL_API, "%s(%d) min=%d max=%d cur=%d\n", __func__,
513 level, min, max, v);
496 514
497 v = level; 515 v = level;
498 if (v < min) 516 if (v < min)
@@ -517,7 +535,8 @@ int saa7164_api_set_audio_volume(struct saa7164_port *port, s8 level)
517 if (ret != SAA_OK) 535 if (ret != SAA_OK)
518 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); 536 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
519 537
520 dprintk(DBGLVL_API, "%s(%d) min=%d max=%d cur=%d\n", __func__, level, min, max, v); 538 dprintk(DBGLVL_API, "%s(%d) min=%d max=%d cur=%d\n", __func__,
539 level, min, max, v);
521 540
522 return ret; 541 return ret;
523} 542}
@@ -539,7 +558,8 @@ int saa7164_api_set_audio_std(struct saa7164_port *port)
539 lvl.ucSAP_Level = TMHW_LEV_ADJ_SAPLEV_DEFAULT; 558 lvl.ucSAP_Level = TMHW_LEV_ADJ_SAPLEV_DEFAULT;
540 lvl.ucADC_Level = TMHW_LEV_ADJ_ADCLEV_DEFAULT; 559 lvl.ucADC_Level = TMHW_LEV_ADJ_ADCLEV_DEFAULT;
541 ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, SET_CUR, 560 ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, SET_CUR,
542 AUDIO_DEFAULT_CONTROL, sizeof(struct tmComResAudioDefaults), &lvl); 561 AUDIO_DEFAULT_CONTROL, sizeof(struct tmComResAudioDefaults),
562 &lvl);
543 if (ret != SAA_OK) 563 if (ret != SAA_OK)
544 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret); 564 printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
545 565
@@ -555,7 +575,8 @@ int saa7164_api_set_audio_std(struct saa7164_port *port)
555 ret = saa7164_cmd_send(port->dev, port->tunerunit.unitid, SET_CUR, 575 ret = saa7164_cmd_send(port->dev, port->tunerunit.unitid, SET_CUR,
556 TU_STANDARD_CONTROL, sizeof(tvaudio), &tvaudio); 576 TU_STANDARD_CONTROL, sizeof(tvaudio), &tvaudio);
557 if (ret != SAA_OK) 577 if (ret != SAA_OK)
558 printk(KERN_ERR "%s() TU_STANDARD_CONTROL error, ret = 0x%x\n", __func__, ret); 578 printk(KERN_ERR "%s() TU_STANDARD_CONTROL error, ret = 0x%x\n",
579 __func__, ret);
559 return ret; 580 return ret;
560} 581}
561 582
@@ -575,7 +596,9 @@ int saa7164_api_set_audio_detection(struct saa7164_port *port, int autodetect)
575 ret = saa7164_cmd_send(port->dev, port->tunerunit.unitid, SET_CUR, 596 ret = saa7164_cmd_send(port->dev, port->tunerunit.unitid, SET_CUR,
576 TU_STANDARD_AUTO_CONTROL, sizeof(p), &p); 597 TU_STANDARD_AUTO_CONTROL, sizeof(p), &p);
577 if (ret != SAA_OK) 598 if (ret != SAA_OK)
578 printk(KERN_ERR "%s() TU_STANDARD_AUTO_CONTROL error, ret = 0x%x\n", __func__, ret); 599 printk(KERN_ERR
600 "%s() TU_STANDARD_AUTO_CONTROL error, ret = 0x%x\n",
601 __func__, ret);
579 602
580 return ret; 603 return ret;
581} 604}
@@ -646,9 +669,9 @@ int saa7164_api_set_dif(struct saa7164_port *port, u8 reg, u8 val)
646 EXU_REGISTER_ACCESS_CONTROL, len, &buf); 669 EXU_REGISTER_ACCESS_CONTROL, len, &buf);
647 if (ret != SAA_OK) 670 if (ret != SAA_OK)
648 printk(KERN_ERR "%s() error, ret(2) = 0x%x\n", __func__, ret); 671 printk(KERN_ERR "%s() error, ret(2) = 0x%x\n", __func__, ret);
649 672#if 0
650 //saa7164_dumphex16(dev, buf, 16); 673 saa7164_dumphex16(dev, buf, 16);
651 674#endif
652 return ret == SAA_OK ? 0 : -EIO; 675 return ret == SAA_OK ? 0 : -EIO;
653} 676}
654 677
@@ -696,7 +719,8 @@ int saa7164_api_configure_dif(struct saa7164_port *port, u32 std)
696 } else { 719 } else {
697 /* Unknown standard, assume DTV */ 720 /* Unknown standard, assume DTV */
698 dprintk(DBGLVL_API, " Unknown (assuming DTV)\n"); 721 dprintk(DBGLVL_API, " Unknown (assuming DTV)\n");
699 saa7164_api_set_dif(port, 0x00, 0x80); /* Undefined Video Standard */ 722 /* Undefinded Video Standard */
723 saa7164_api_set_dif(port, 0x00, 0x80);
700 agc_disable = 1; 724 agc_disable = 1;
701 } 725 }
702 726
@@ -933,7 +957,7 @@ int saa7164_api_dump_subdevs(struct saa7164_dev *dev, u8 *buf, int len)
933 if (hdr->type != CS_INTERFACE) 957 if (hdr->type != CS_INTERFACE)
934 return SAA_ERR_NOT_SUPPORTED; 958 return SAA_ERR_NOT_SUPPORTED;
935 959
936 dprintk(DBGLVL_API, "@ 0x%x = \n", idx); 960 dprintk(DBGLVL_API, "@ 0x%x =\n", idx);
937 switch (hdr->subtype) { 961 switch (hdr->subtype) {
938 case GENERAL_REQUEST: 962 case GENERAL_REQUEST:
939 dprintk(DBGLVL_API, " GENERAL_REQUEST\n"); 963 dprintk(DBGLVL_API, " GENERAL_REQUEST\n");
@@ -1085,7 +1109,8 @@ int saa7164_api_dump_subdevs(struct saa7164_dev *dev, u8 *buf, int len)
1085 vbiport = &dev->ports[SAA7164_PORT_VBI2]; 1109 vbiport = &dev->ports[SAA7164_PORT_VBI2];
1086 memcpy(&vbiport->hwcfg, vcoutputtermhdr, 1110 memcpy(&vbiport->hwcfg, vcoutputtermhdr,
1087 sizeof(*vcoutputtermhdr)); 1111 sizeof(*vcoutputtermhdr));
1088 memcpy(&vbiport->vbi_fmt_ntsc, vbifmt, sizeof(*vbifmt)); 1112 memcpy(&vbiport->vbi_fmt_ntsc, vbifmt,
1113 sizeof(*vbifmt));
1089 saa7164_api_configure_port_vbi(dev, 1114 saa7164_api_configure_port_vbi(dev,
1090 vbiport); 1115 vbiport);
1091 break; 1116 break;
@@ -1134,7 +1159,9 @@ int saa7164_api_dump_subdevs(struct saa7164_dev *dev, u8 *buf, int len)
1134 encport = &dev->ports[SAA7164_PORT_ENC2]; 1159 encport = &dev->ports[SAA7164_PORT_ENC2];
1135 memcpy(&encport->tunerunit, tunerunithdr, 1160 memcpy(&encport->tunerunit, tunerunithdr,
1136 sizeof(struct tmComResTunerDescrHeader)); 1161 sizeof(struct tmComResTunerDescrHeader));
1137 dprintk(DBGLVL_API, " (becomes dev->enc[%d] tuner)\n", encport->nr); 1162 dprintk(DBGLVL_API,
1163 " (becomes dev->enc[%d] tuner)\n",
1164 encport->nr);
1138 } 1165 }
1139 break; 1166 break;
1140 case VC_SELECTOR_UNIT: 1167 case VC_SELECTOR_UNIT:
@@ -1163,7 +1190,8 @@ int saa7164_api_dump_subdevs(struct saa7164_dev *dev, u8 *buf, int len)
1163 encport = &dev->ports[SAA7164_PORT_ENC2]; 1190 encport = &dev->ports[SAA7164_PORT_ENC2];
1164 memcpy(&encport->vidproc, pdh, 1191 memcpy(&encport->vidproc, pdh,
1165 sizeof(struct tmComResProcDescrHeader)); 1192 sizeof(struct tmComResProcDescrHeader));
1166 dprintk(DBGLVL_API, " (becomes dev->enc[%d])\n", encport->nr); 1193 dprintk(DBGLVL_API, " (becomes dev->enc[%d])\n",
1194 encport->nr);
1167 } 1195 }
1168 break; 1196 break;
1169 case FEATURE_UNIT: 1197 case FEATURE_UNIT:
@@ -1181,15 +1209,18 @@ int saa7164_api_dump_subdevs(struct saa7164_dev *dev, u8 *buf, int len)
1181 encport = &dev->ports[SAA7164_PORT_ENC2]; 1209 encport = &dev->ports[SAA7164_PORT_ENC2];
1182 memcpy(&encport->audfeat, afd, 1210 memcpy(&encport->audfeat, afd,
1183 sizeof(struct tmComResAFeatureDescrHeader)); 1211 sizeof(struct tmComResAFeatureDescrHeader));
1184 dprintk(DBGLVL_API, " (becomes dev->enc[%d])\n", encport->nr); 1212 dprintk(DBGLVL_API, " (becomes dev->enc[%d])\n",
1213 encport->nr);
1185 break; 1214 break;
1186 case ENCODER_UNIT: 1215 case ENCODER_UNIT:
1187 edh = (struct tmComResEncoderDescrHeader *)(buf + idx); 1216 edh = (struct tmComResEncoderDescrHeader *)(buf + idx);
1188 dprintk(DBGLVL_API, " ENCODER_UNIT\n"); 1217 dprintk(DBGLVL_API, " ENCODER_UNIT\n");
1189 dprintk(DBGLVL_API, " subtype = 0x%x\n", edh->subtype); 1218 dprintk(DBGLVL_API, " subtype = 0x%x\n", edh->subtype);
1190 dprintk(DBGLVL_API, " unitid = 0x%x\n", edh->unitid); 1219 dprintk(DBGLVL_API, " unitid = 0x%x\n", edh->unitid);
1191 dprintk(DBGLVL_API, " vsourceid = 0x%x\n", edh->vsourceid); 1220 dprintk(DBGLVL_API, " vsourceid = 0x%x\n",
1192 dprintk(DBGLVL_API, " asourceid = 0x%x\n", edh->asourceid); 1221 edh->vsourceid);
1222 dprintk(DBGLVL_API, " asourceid = 0x%x\n",
1223 edh->asourceid);
1193 dprintk(DBGLVL_API, " iunit = 0x%x\n", edh->iunit); 1224 dprintk(DBGLVL_API, " iunit = 0x%x\n", edh->iunit);
1194 if (edh->iunit == edh->unitid) { 1225 if (edh->iunit == edh->unitid) {
1195 if (currpath == 1) 1226 if (currpath == 1)
@@ -1198,7 +1229,9 @@ int saa7164_api_dump_subdevs(struct saa7164_dev *dev, u8 *buf, int len)
1198 encport = &dev->ports[SAA7164_PORT_ENC2]; 1229 encport = &dev->ports[SAA7164_PORT_ENC2];
1199 memcpy(&encport->encunit, edh, 1230 memcpy(&encport->encunit, edh,
1200 sizeof(struct tmComResEncoderDescrHeader)); 1231 sizeof(struct tmComResEncoderDescrHeader));
1201 dprintk(DBGLVL_API, " (becomes dev->enc[%d])\n", encport->nr); 1232 dprintk(DBGLVL_API,
1233 " (becomes dev->enc[%d])\n",
1234 encport->nr);
1202 } 1235 }
1203 break; 1236 break;
1204 case EXTENSION_UNIT: 1237 case EXTENSION_UNIT:
@@ -1262,7 +1295,9 @@ int saa7164_api_dump_subdevs(struct saa7164_dev *dev, u8 *buf, int len)
1262 encport = &dev->ports[SAA7164_PORT_ENC2]; 1295 encport = &dev->ports[SAA7164_PORT_ENC2];
1263 memcpy(&encport->ifunit, exthdr, 1296 memcpy(&encport->ifunit, exthdr,
1264 sizeof(struct tmComResExtDevDescrHeader)); 1297 sizeof(struct tmComResExtDevDescrHeader));
1265 dprintk(DBGLVL_API, " (becomes dev->enc[%d])\n", encport->nr); 1298 dprintk(DBGLVL_API,
1299 " (becomes dev->enc[%d])\n",
1300 encport->nr);
1266 } 1301 }
1267 break; 1302 break;
1268 case PVC_INFRARED_UNIT: 1303 case PVC_INFRARED_UNIT:
diff --git a/drivers/media/video/saa7164/saa7164-buffer.c b/drivers/media/video/saa7164/saa7164-buffer.c
index 7230912acc7d..ddd25211c9e8 100644
--- a/drivers/media/video/saa7164/saa7164-buffer.c
+++ b/drivers/media/video/saa7164/saa7164-buffer.c
@@ -24,46 +24,46 @@
24#include "saa7164.h" 24#include "saa7164.h"
25 25
26/* The PCI address space for buffer handling looks like this: 26/* The PCI address space for buffer handling looks like this:
27 27 *
28 +-u32 wide-------------+ 28 * +-u32 wide-------------+
29 | + 29 * | +
30 +-u64 wide------------------------------------+ 30 * +-u64 wide------------------------------------+
31 + + 31 * + +
32 +----------------------+ 32 * +----------------------+
33 | CurrentBufferPtr + Pointer to current PCI buffer >-+ 33 * | CurrentBufferPtr + Pointer to current PCI buffer >-+
34 +----------------------+ | 34 * +----------------------+ |
35 | Unused + | 35 * | Unused + |
36 +----------------------+ | 36 * +----------------------+ |
37 | Pitch + = 188 (bytes) | 37 * | Pitch + = 188 (bytes) |
38 +----------------------+ | 38 * +----------------------+ |
39 | PCI buffer size + = pitch * number of lines (312) | 39 * | PCI buffer size + = pitch * number of lines (312) |
40 +----------------------+ | 40 * +----------------------+ |
41 |0| Buf0 Write Offset + | 41 * |0| Buf0 Write Offset + |
42 +----------------------+ v 42 * +----------------------+ v
43 |1| Buf1 Write Offset + | 43 * |1| Buf1 Write Offset + |
44 +----------------------+ | 44 * +----------------------+ |
45 |2| Buf2 Write Offset + | 45 * |2| Buf2 Write Offset + |
46 +----------------------+ | 46 * +----------------------+ |
47 |3| Buf3 Write Offset + | 47 * |3| Buf3 Write Offset + |
48 +----------------------+ | 48 * +----------------------+ |
49 ... More write offsets | 49 * ... More write offsets |
50 +---------------------------------------------+ | 50 * +---------------------------------------------+ |
51 +0| set of ptrs to PCI pagetables + | 51 * +0| set of ptrs to PCI pagetables + |
52 +---------------------------------------------+ | 52 * +---------------------------------------------+ |
53 +1| set of ptrs to PCI pagetables + <--------+ 53 * +1| set of ptrs to PCI pagetables + <--------+
54 +---------------------------------------------+ 54 * +---------------------------------------------+
55 +2| set of ptrs to PCI pagetables + 55 * +2| set of ptrs to PCI pagetables +
56 +---------------------------------------------+ 56 * +---------------------------------------------+
57 +3| set of ptrs to PCI pagetables + >--+ 57 * +3| set of ptrs to PCI pagetables + >--+
58 +---------------------------------------------+ | 58 * +---------------------------------------------+ |
59 ... More buffer pointers | +----------------+ 59 * ... More buffer pointers | +----------------+
60 +->| pt[0] TS data | 60 * +->| pt[0] TS data |
61 | +----------------+ 61 * | +----------------+
62 | 62 * |
63 | +----------------+ 63 * | +----------------+
64 +->| pt[1] TS data | 64 * +->| pt[1] TS data |
65 | +----------------+ 65 * | +----------------+
66 | etc 66 * | etc
67 */ 67 */
68 68
69void saa7164_buffer_display(struct saa7164_buffer *buf) 69void saa7164_buffer_display(struct saa7164_buffer *buf)
@@ -283,7 +283,8 @@ int saa7164_buffer_cfg_port(struct saa7164_port *port)
283 return 0; 283 return 0;
284} 284}
285 285
286struct saa7164_user_buffer *saa7164_buffer_alloc_user(struct saa7164_dev *dev, u32 len) 286struct saa7164_user_buffer *saa7164_buffer_alloc_user(struct saa7164_dev *dev,
287 u32 len)
287{ 288{
288 struct saa7164_user_buffer *buf; 289 struct saa7164_user_buffer *buf;
289 290
@@ -313,12 +314,9 @@ void saa7164_buffer_dealloc_user(struct saa7164_user_buffer *buf)
313 if (!buf) 314 if (!buf)
314 return; 315 return;
315 316
316 if (buf->data) { 317 kfree(buf->data);
317 kfree(buf->data); 318 buf->data = 0;
318 buf->data = 0;
319 }
320 319
321 if (buf) 320 kfree(buf);
322 kfree(buf);
323} 321}
324 322
diff --git a/drivers/media/video/saa7164/saa7164-bus.c b/drivers/media/video/saa7164/saa7164-bus.c
index 30d5283da41e..b2b0d97101d0 100644
--- a/drivers/media/video/saa7164/saa7164-bus.c
+++ b/drivers/media/video/saa7164/saa7164-bus.c
@@ -43,7 +43,8 @@ int saa7164_bus_setup(struct saa7164_dev *dev)
43 43
44 b->m_dwSizeGetRing = SAA_DEVICE_BUFFERBLOCKSIZE; 44 b->m_dwSizeGetRing = SAA_DEVICE_BUFFERBLOCKSIZE;
45 45
46 b->m_dwSetWritePos = ((u32)dev->intfdesc.BARLocation) + (2 * sizeof(u64)); 46 b->m_dwSetWritePos = ((u32)dev->intfdesc.BARLocation) +
47 (2 * sizeof(u64));
47 b->m_dwSetReadPos = b->m_dwSetWritePos + (1 * sizeof(u32)); 48 b->m_dwSetReadPos = b->m_dwSetWritePos + (1 * sizeof(u32));
48 49
49 b->m_dwGetWritePos = b->m_dwSetWritePos + (2 * sizeof(u32)); 50 b->m_dwGetWritePos = b->m_dwSetWritePos + (2 * sizeof(u32));
@@ -105,7 +106,8 @@ void saa7164_bus_verify(struct saa7164_dev *dev)
105 } 106 }
106} 107}
107 108
108void saa7164_bus_dumpmsg(struct saa7164_dev *dev, struct tmComResInfo* m, void *buf) 109void saa7164_bus_dumpmsg(struct saa7164_dev *dev, struct tmComResInfo* m,
110 void *buf)
109{ 111{
110 dprintk(DBGLVL_BUS, "Dumping msg structure:\n"); 112 dprintk(DBGLVL_BUS, "Dumping msg structure:\n");
111 dprintk(DBGLVL_BUS, " .id = %d\n", m->id); 113 dprintk(DBGLVL_BUS, " .id = %d\n", m->id);
@@ -129,7 +131,8 @@ void saa7164_bus_dumpmsg(struct saa7164_dev *dev, struct tmComResInfo* m, void *
129 * SAA_OK The function executed successfully. 131 * SAA_OK The function executed successfully.
130 * < 0 One or more members are not initialized. 132 * < 0 One or more members are not initialized.
131 */ 133 */
132int saa7164_bus_set(struct saa7164_dev *dev, struct tmComResInfo* msg, void *buf) 134int saa7164_bus_set(struct saa7164_dev *dev, struct tmComResInfo* msg,
135 void *buf)
133{ 136{
134 struct tmComResBusInfo *bus = &dev->bus; 137 struct tmComResBusInfo *bus = &dev->bus;
135 u32 bytes_to_write, free_write_space, timeout, curr_srp, curr_swp; 138 u32 bytes_to_write, free_write_space, timeout, curr_srp, curr_swp;
@@ -294,14 +297,15 @@ out:
294/* 297/*
295 * Receive a command or a response from the bus. The implementation does not 298 * Receive a command or a response from the bus. The implementation does not
296 * know if it is a command or a response it simply dequeues the data, 299 * know if it is a command or a response it simply dequeues the data,
297 * depending on the bus information given in the struct tmComResBusInfo structure. 300 * depending on the bus information given in the struct tmComResBusInfo
301 * structure.
298 * 302 *
299 * Return Value: 303 * Return Value:
300 * 0 The function executed successfully. 304 * 0 The function executed successfully.
301 * < 0 One or more members are not initialized. 305 * < 0 One or more members are not initialized.
302 */ 306 */
303int saa7164_bus_get(struct saa7164_dev *dev, struct tmComResInfo* msg, void *buf, 307int saa7164_bus_get(struct saa7164_dev *dev, struct tmComResInfo* msg,
304 int peekonly) 308 void *buf, int peekonly)
305{ 309{
306 struct tmComResBusInfo *bus = &dev->bus; 310 struct tmComResBusInfo *bus = &dev->bus;
307 u32 bytes_to_read, write_distance, curr_grp, curr_gwp, 311 u32 bytes_to_read, write_distance, curr_grp, curr_gwp,
diff --git a/drivers/media/video/saa7164/saa7164-cards.c b/drivers/media/video/saa7164/saa7164-cards.c
index 4cb634e952a6..69822a4e7275 100644
--- a/drivers/media/video/saa7164/saa7164-cards.c
+++ b/drivers/media/video/saa7164/saa7164-cards.c
@@ -482,7 +482,7 @@ void saa7164_gpio_setup(struct saa7164_dev *dev)
482 saa7164_api_clear_gpiobit(dev, PCIEBRIDGE_UNITID, 2); 482 saa7164_api_clear_gpiobit(dev, PCIEBRIDGE_UNITID, 2);
483 saa7164_api_clear_gpiobit(dev, PCIEBRIDGE_UNITID, 3); 483 saa7164_api_clear_gpiobit(dev, PCIEBRIDGE_UNITID, 3);
484 484
485 msleep(10); 485 msleep(20);
486 486
487 saa7164_api_set_gpiobit(dev, PCIEBRIDGE_UNITID, 2); 487 saa7164_api_set_gpiobit(dev, PCIEBRIDGE_UNITID, 2);
488 saa7164_api_set_gpiobit(dev, PCIEBRIDGE_UNITID, 3); 488 saa7164_api_set_gpiobit(dev, PCIEBRIDGE_UNITID, 3);
diff --git a/drivers/media/video/saa7164/saa7164-cmd.c b/drivers/media/video/saa7164/saa7164-cmd.c
index 301a9e302f45..a97ae17b36c2 100644
--- a/drivers/media/video/saa7164/saa7164-cmd.c
+++ b/drivers/media/video/saa7164/saa7164-cmd.c
@@ -122,8 +122,8 @@ int saa7164_irq_dequeue(struct saa7164_dev *dev)
122 return ret; 122 return ret;
123 } 123 }
124 124
125 /* It's unlikely to have more than 4 or 5 pending messages, ensure we exit 125 /* It's unlikely to have more than 4 or 5 pending messages,
126 * at some point regardles. 126 * ensure we exit at some point regardless.
127 */ 127 */
128 } while (i++ < 32); 128 } while (i++ < 32);
129 129
@@ -186,7 +186,8 @@ int saa7164_cmd_dequeue(struct saa7164_dev *dev)
186 return SAA_OK; 186 return SAA_OK;
187} 187}
188 188
189int saa7164_cmd_set(struct saa7164_dev *dev, struct tmComResInfo* msg, void *buf) 189int saa7164_cmd_set(struct saa7164_dev *dev, struct tmComResInfo *msg,
190 void *buf)
190{ 191{
191 struct tmComResBusInfo *bus = &dev->bus; 192 struct tmComResBusInfo *bus = &dev->bus;
192 u8 cmd_sent; 193 u8 cmd_sent;
@@ -292,7 +293,8 @@ int saa7164_cmd_wait(struct saa7164_dev *dev, u8 seqno)
292 * We typically are signalled in < 50ms but it can 293 * We typically are signalled in < 50ms but it can
293 * take MUCH longer. 294 * take MUCH longer.
294 */ 295 */
295 wait_event_timeout(*q, dev->cmds[seqno].signalled, (HZ * waitsecs)); 296 wait_event_timeout(*q, dev->cmds[seqno].signalled,
297 (HZ * waitsecs));
296 r = time_before(jiffies, stamp + (HZ * waitsecs)); 298 r = time_before(jiffies, stamp + (HZ * waitsecs));
297 if (r) 299 if (r)
298 ret = SAA_OK; 300 ret = SAA_OK;
diff --git a/drivers/media/video/saa7164/saa7164-core.c b/drivers/media/video/saa7164/saa7164-core.c
index e1bac5051460..d6bf3f82cc34 100644
--- a/drivers/media/video/saa7164/saa7164-core.c
+++ b/drivers/media/video/saa7164/saa7164-core.c
@@ -40,12 +40,12 @@ MODULE_AUTHOR("Steven Toth <stoth@kernellabs.com>");
40MODULE_LICENSE("GPL"); 40MODULE_LICENSE("GPL");
41 41
42/* 42/*
43 1 Basic 43 * 1 Basic
44 2 44 * 2
45 4 i2c 45 * 4 i2c
46 8 api 46 * 8 api
47 16 cmd 47 * 16 cmd
48 32 bus 48 * 32 bus
49 */ 49 */
50 50
51unsigned int saa_debug; 51unsigned int saa_debug;
@@ -82,7 +82,8 @@ MODULE_PARM_DESC(crc_checking, "enable crc sanity checking on buffers");
82 82
83unsigned int guard_checking = 1; 83unsigned int guard_checking = 1;
84module_param(guard_checking, int, 0644); 84module_param(guard_checking, int, 0644);
85MODULE_PARM_DESC(guard_checking, "enable dma sanity checking for buffer overruns"); 85MODULE_PARM_DESC(guard_checking,
86 "enable dma sanity checking for buffer overruns");
86 87
87static unsigned int saa7164_devcount; 88static unsigned int saa7164_devcount;
88 89
@@ -123,7 +124,9 @@ static void saa7164_pack_verifier(struct saa7164_buffer *buf)
123 if ((*(p + i + 0) != 0x00) || (*(p + i + 1) != 0x00) || 124 if ((*(p + i + 0) != 0x00) || (*(p + i + 1) != 0x00) ||
124 (*(p + i + 2) != 0x01) || (*(p + i + 3) != 0xBA)) { 125 (*(p + i + 2) != 0x01) || (*(p + i + 3) != 0xBA)) {
125 printk(KERN_ERR "No pack at 0x%x\n", i); 126 printk(KERN_ERR "No pack at 0x%x\n", i);
126// saa7164_dumphex16FF(buf->port->dev, (p + i), 32); 127#if 0
128 saa7164_dumphex16FF(buf->port->dev, (p + i), 32);
129#endif
127 } 130 }
128 } 131 }
129} 132}
@@ -199,19 +202,16 @@ static void saa7164_histogram_reset(struct saa7164_histogram *hg, char *name)
199 strcpy(hg->name, name); 202 strcpy(hg->name, name);
200 203
201 /* First 30ms x 1ms */ 204 /* First 30ms x 1ms */
202 for (i = 0; i < 30; i++) { 205 for (i = 0; i < 30; i++)
203 hg->counter1[0 + i].val = i; 206 hg->counter1[0 + i].val = i;
204 }
205 207
206 /* 30 - 200ms x 10ms */ 208 /* 30 - 200ms x 10ms */
207 for (i = 0; i < 18; i++) { 209 for (i = 0; i < 18; i++)
208 hg->counter1[30 + i].val = 30 + (i * 10); 210 hg->counter1[30 + i].val = 30 + (i * 10);
209 }
210 211
211 /* 200 - 2000ms x 100ms */ 212 /* 200 - 2000ms x 100ms */
212 for (i = 0; i < 15; i++) { 213 for (i = 0; i < 15; i++)
213 hg->counter1[48 + i].val = 200 + (i * 200); 214 hg->counter1[48 + i].val = 200 + (i * 200);
214 }
215 215
216 /* Catch all massive value (2secs) */ 216 /* Catch all massive value (2secs) */
217 hg->counter1[55].val = 2000; 217 hg->counter1[55].val = 2000;
@@ -315,7 +315,9 @@ static void saa7164_work_enchandler_helper(struct saa7164_port *port, int bufnr)
315 (*(p + buf->actual_size + 0x13) != 0xff)) { 315 (*(p + buf->actual_size + 0x13) != 0xff)) {
316 printk(KERN_ERR "%s() buf %p guard buffer breach\n", 316 printk(KERN_ERR "%s() buf %p guard buffer breach\n",
317 __func__, buf); 317 __func__, buf);
318// saa7164_dumphex16FF(dev, (p + buf->actual_size) - 32 , 64); 318#if 0
319 saa7164_dumphex16FF(dev, (p + buf->actual_size) - 32 , 64);
320#endif
319 } 321 }
320 } 322 }
321 323
@@ -961,9 +963,7 @@ static int saa7164_port_init(struct saa7164_dev *dev, int portnr)
961 963
962 /* We need a deferred interrupt handler for cmd handling */ 964 /* We need a deferred interrupt handler for cmd handling */
963 INIT_WORK(&port->workenc, saa7164_work_enchandler); 965 INIT_WORK(&port->workenc, saa7164_work_enchandler);
964 } 966 } else if ((portnr == SAA7164_PORT_VBI1) || (portnr == SAA7164_PORT_VBI2)) {
965 else
966 if ((portnr == SAA7164_PORT_VBI1) || (portnr == SAA7164_PORT_VBI2)) {
967 port->type = SAA7164_MPEG_VBI; 967 port->type = SAA7164_MPEG_VBI;
968 968
969 /* We need a deferred interrupt handler for cmd handling */ 969 /* We need a deferred interrupt handler for cmd handling */
@@ -1001,7 +1001,7 @@ static int saa7164_dev_setup(struct saa7164_dev *dev)
1001 atomic_inc(&dev->refcount); 1001 atomic_inc(&dev->refcount);
1002 dev->nr = saa7164_devcount++; 1002 dev->nr = saa7164_devcount++;
1003 1003
1004 sprintf(dev->name, "saa7164[%d]", dev->nr); 1004 snprintf(dev->name, sizeof(dev->name), "saa7164[%d]", dev->nr);
1005 1005
1006 mutex_lock(&devlist); 1006 mutex_lock(&devlist);
1007 list_add_tail(&dev->devlist, &saa7164_devlist); 1007 list_add_tail(&dev->devlist, &saa7164_devlist);
@@ -1169,7 +1169,7 @@ static int saa7164_proc_open(struct inode *inode, struct file *filp)
1169 return single_open(filp, saa7164_proc_show, NULL); 1169 return single_open(filp, saa7164_proc_show, NULL);
1170} 1170}
1171 1171
1172static struct file_operations saa7164_proc_fops = { 1172static const struct file_operations saa7164_proc_fops = {
1173 .open = saa7164_proc_open, 1173 .open = saa7164_proc_open,
1174 .read = seq_read, 1174 .read = seq_read,
1175 .llseek = seq_lseek, 1175 .llseek = seq_lseek,
diff --git a/drivers/media/video/saa7164/saa7164-encoder.c b/drivers/media/video/saa7164/saa7164-encoder.c
index cbb53d0ee979..1838408cd5cb 100644
--- a/drivers/media/video/saa7164/saa7164-encoder.c
+++ b/drivers/media/video/saa7164/saa7164-encoder.c
@@ -125,16 +125,22 @@ static int saa7164_encoder_buffers_alloc(struct saa7164_port *port)
125 125
126 dprintk(DBGLVL_ENC, "%s()\n", __func__); 126 dprintk(DBGLVL_ENC, "%s()\n", __func__);
127 127
128 if (port->encoder_params.stream_type == V4L2_MPEG_STREAM_TYPE_MPEG2_PS) { 128 if (port->encoder_params.stream_type ==
129 dprintk(DBGLVL_ENC, "%s() type=V4L2_MPEG_STREAM_TYPE_MPEG2_PS\n", __func__); 129 V4L2_MPEG_STREAM_TYPE_MPEG2_PS) {
130 dprintk(DBGLVL_ENC,
131 "%s() type=V4L2_MPEG_STREAM_TYPE_MPEG2_PS\n",
132 __func__);
130 params->samplesperline = 128; 133 params->samplesperline = 128;
131 params->numberoflines = 256; 134 params->numberoflines = 256;
132 params->pitch = 128; 135 params->pitch = 128;
133 params->numpagetables = 2 + 136 params->numpagetables = 2 +
134 ((SAA7164_PS_NUMBER_OF_LINES * 128) / PAGE_SIZE); 137 ((SAA7164_PS_NUMBER_OF_LINES * 128) / PAGE_SIZE);
135 } else 138 } else
136 if (port->encoder_params.stream_type == V4L2_MPEG_STREAM_TYPE_MPEG2_TS) { 139 if (port->encoder_params.stream_type ==
137 dprintk(DBGLVL_ENC, "%s() type=V4L2_MPEG_STREAM_TYPE_MPEG2_TS\n", __func__); 140 V4L2_MPEG_STREAM_TYPE_MPEG2_TS) {
141 dprintk(DBGLVL_ENC,
142 "%s() type=V4L2_MPEG_STREAM_TYPE_MPEG2_TS\n",
143 __func__);
138 params->samplesperline = 188; 144 params->samplesperline = 188;
139 params->numberoflines = 312; 145 params->numberoflines = 312;
140 params->pitch = 188; 146 params->pitch = 188;
@@ -826,7 +832,8 @@ static int fill_queryctrl(struct saa7164_encoder_params *params,
826 return v4l2_ctrl_query_fill(c, 1, 255, 1, 15); 832 return v4l2_ctrl_query_fill(c, 1, 255, 1, 15);
827 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: 833 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
828 return v4l2_ctrl_query_fill(c, 834 return v4l2_ctrl_query_fill(c,
829 V4L2_MPEG_VIDEO_BITRATE_MODE_VBR, V4L2_MPEG_VIDEO_BITRATE_MODE_CBR, 835 V4L2_MPEG_VIDEO_BITRATE_MODE_VBR,
836 V4L2_MPEG_VIDEO_BITRATE_MODE_CBR,
830 1, V4L2_MPEG_VIDEO_BITRATE_MODE_VBR); 837 1, V4L2_MPEG_VIDEO_BITRATE_MODE_VBR);
831 case V4L2_CID_MPEG_VIDEO_B_FRAMES: 838 case V4L2_CID_MPEG_VIDEO_B_FRAMES:
832 return v4l2_ctrl_query_fill(c, 839 return v4l2_ctrl_query_fill(c,
@@ -1113,7 +1120,9 @@ struct saa7164_user_buffer *saa7164_enc_next_buf(struct saa7164_port *port)
1113 if (crc_checking) { 1120 if (crc_checking) {
1114 crc = crc32(0, ubuf->data, ubuf->actual_size); 1121 crc = crc32(0, ubuf->data, ubuf->actual_size);
1115 if (crc != ubuf->crc) { 1122 if (crc != ubuf->crc) {
1116 printk(KERN_ERR "%s() ubuf %p crc became invalid, was 0x%x became 0x%x\n", __func__, 1123 printk(KERN_ERR
1124 "%s() ubuf %p crc became invalid, was 0x%x became 0x%x\n",
1125 __func__,
1117 ubuf, ubuf->crc, crc); 1126 ubuf, ubuf->crc, crc);
1118 } 1127 }
1119 } 1128 }
@@ -1201,9 +1210,8 @@ static ssize_t fops_read(struct file *file, char __user *buffer,
1201 buffer += cnt; 1210 buffer += cnt;
1202 ret += cnt; 1211 ret += cnt;
1203 1212
1204 if (ubuf->pos > ubuf->actual_size) { 1213 if (ubuf->pos > ubuf->actual_size)
1205 printk(KERN_ERR "read() pos > actual, huh?\n"); 1214 printk(KERN_ERR "read() pos > actual, huh?\n");
1206 }
1207 1215
1208 if (ubuf->pos == ubuf->actual_size) { 1216 if (ubuf->pos == ubuf->actual_size) {
1209 1217
@@ -1227,16 +1235,16 @@ static ssize_t fops_read(struct file *file, char __user *buffer,
1227 } 1235 }
1228 } 1236 }
1229err: 1237err:
1230 if (!ret && !ubuf) { 1238 if (!ret && !ubuf)
1231 ret = -EAGAIN; 1239 ret = -EAGAIN;
1232 }
1233 1240
1234 return ret; 1241 return ret;
1235} 1242}
1236 1243
1237static unsigned int fops_poll(struct file *file, poll_table *wait) 1244static unsigned int fops_poll(struct file *file, poll_table *wait)
1238{ 1245{
1239 struct saa7164_encoder_fh *fh = (struct saa7164_encoder_fh *)file->private_data; 1246 struct saa7164_encoder_fh *fh =
1247 (struct saa7164_encoder_fh *)file->private_data;
1240 struct saa7164_port *port = fh->port; 1248 struct saa7164_port *port = fh->port;
1241 struct saa7164_user_buffer *ubuf; 1249 struct saa7164_user_buffer *ubuf;
1242 unsigned int mask = 0; 1250 unsigned int mask = 0;
@@ -1249,9 +1257,8 @@ static unsigned int fops_poll(struct file *file, poll_table *wait)
1249 saa7164_histogram_update(&port->poll_interval, 1257 saa7164_histogram_update(&port->poll_interval,
1250 port->last_poll_msecs_diff); 1258 port->last_poll_msecs_diff);
1251 1259
1252 if (!video_is_registered(port->v4l_device)) { 1260 if (!video_is_registered(port->v4l_device))
1253 return -EIO; 1261 return -EIO;
1254 }
1255 1262
1256 if (atomic_cmpxchg(&fh->v4l_reading, 0, 1) == 0) { 1263 if (atomic_cmpxchg(&fh->v4l_reading, 0, 1) == 0) {
1257 if (atomic_inc_return(&port->v4l_reader_count) == 1) { 1264 if (atomic_inc_return(&port->v4l_reader_count) == 1) {
diff --git a/drivers/media/video/saa7164/saa7164-fw.c b/drivers/media/video/saa7164/saa7164-fw.c
index 484533c32bb1..ebed6f786a23 100644
--- a/drivers/media/video/saa7164/saa7164-fw.c
+++ b/drivers/media/video/saa7164/saa7164-fw.c
@@ -178,7 +178,7 @@ int saa7164_downloadimage(struct saa7164_dev *dev, u8 *src, u32 srcsize,
178 goto out; 178 goto out;
179 } 179 }
180 180
181 msleep(10); 181 msleep(10); /* Checkpatch throws a < 20ms warning */
182 if (timeout++ > 60) 182 if (timeout++ > 60)
183 break; 183 break;
184 } 184 }
@@ -235,7 +235,7 @@ int saa7164_downloadfirmware(struct saa7164_dev *dev)
235 while (err_flags != SAA_DEVICE_IMAGE_BOOTING) { 235 while (err_flags != SAA_DEVICE_IMAGE_BOOTING) {
236 dprintk(DBGLVL_FW, "%s() err_flags = %x\n", 236 dprintk(DBGLVL_FW, "%s() err_flags = %x\n",
237 __func__, err_flags); 237 __func__, err_flags);
238 msleep(10); 238 msleep(10); /* Checkpatch throws a < 20ms warning */
239 239
240 if (err_flags & SAA_DEVICE_IMAGE_CORRUPT) { 240 if (err_flags & SAA_DEVICE_IMAGE_CORRUPT) {
241 printk(KERN_ERR "%s() firmware corrupt\n", 241 printk(KERN_ERR "%s() firmware corrupt\n",
@@ -294,7 +294,7 @@ int saa7164_downloadfirmware(struct saa7164_dev *dev)
294 while (err_flags != SAA_DEVICE_IMAGE_BOOTING) { 294 while (err_flags != SAA_DEVICE_IMAGE_BOOTING) {
295 dprintk(DBGLVL_FW, "%s() err_flags2 = %x\n", 295 dprintk(DBGLVL_FW, "%s() err_flags2 = %x\n",
296 __func__, err_flags); 296 __func__, err_flags);
297 msleep(10); 297 msleep(10); /* Checkpatch throws a < 20ms warning */
298 298
299 if (err_flags & SAA_DEVICE_IMAGE_CORRUPT) { 299 if (err_flags & SAA_DEVICE_IMAGE_CORRUPT) {
300 printk(KERN_ERR 300 printk(KERN_ERR
@@ -365,7 +365,7 @@ int saa7164_downloadfirmware(struct saa7164_dev *dev)
365 365
366 first_timeout = SAA_DEVICE_TIMEOUT; 366 first_timeout = SAA_DEVICE_TIMEOUT;
367 while (first_timeout) { 367 while (first_timeout) {
368 msleep(10); 368 msleep(10); /* Checkpatch throws a < 20ms warning */
369 369
370 version = 370 version =
371 saa7164_getcurrentfirmwareversion(dev); 371 saa7164_getcurrentfirmwareversion(dev);
@@ -608,8 +608,6 @@ int saa7164_downloadfirmware(struct saa7164_dev *dev)
608 ret = 0; 608 ret = 0;
609 609
610out: 610out:
611 if (fw) 611 release_firmware(fw);
612 release_firmware(fw);
613
614 return ret; 612 return ret;
615} 613}
diff --git a/drivers/media/video/saa7164/saa7164-i2c.c b/drivers/media/video/saa7164/saa7164-i2c.c
index b5167d33650a..26148f76cba2 100644
--- a/drivers/media/video/saa7164/saa7164-i2c.c
+++ b/drivers/media/video/saa7164/saa7164-i2c.c
@@ -23,7 +23,7 @@
23#include <linux/moduleparam.h> 23#include <linux/moduleparam.h>
24#include <linux/init.h> 24#include <linux/init.h>
25#include <linux/delay.h> 25#include <linux/delay.h>
26#include <asm/io.h> 26#include <linux/io.h>
27 27
28#include "saa7164.h" 28#include "saa7164.h"
29 29
@@ -65,7 +65,7 @@ static int i2c_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs, int num)
65 } 65 }
66 return num; 66 return num;
67 67
68 err: 68err:
69 return retval; 69 return retval;
70} 70}
71 71
diff --git a/drivers/media/video/saa7164/saa7164-vbi.c b/drivers/media/video/saa7164/saa7164-vbi.c
index 323c7cdca37b..8abbe6d661e4 100644
--- a/drivers/media/video/saa7164/saa7164-vbi.c
+++ b/drivers/media/video/saa7164/saa7164-vbi.c
@@ -51,11 +51,15 @@ static void saa7164_vbi_configure(struct saa7164_port *port)
51 /* Set up the DIF (enable it) for analog mode by default */ 51 /* Set up the DIF (enable it) for analog mode by default */
52 saa7164_api_initialize_dif(port); 52 saa7164_api_initialize_dif(port);
53 53
54// /* Configure the correct video standard */ 54 /* Configure the correct video standard */
55// saa7164_api_configure_dif(port, port->encodernorm.id); 55#if 0
56 saa7164_api_configure_dif(port, port->encodernorm.id);
57#endif
56 58
57// /* Ensure the audio decoder is correct configured */ 59#if 0
58// saa7164_api_set_audio_std(port); 60 /* Ensure the audio decoder is correct configured */
61 saa7164_api_set_audio_std(port);
62#endif
59 dprintk(DBGLVL_VBI, "%s() ends\n", __func__); 63 dprintk(DBGLVL_VBI, "%s() ends\n", __func__);
60} 64}
61 65
@@ -919,8 +923,10 @@ static int saa7164_vbi_start_streaming(struct saa7164_port *port)
919 saa7164_vbi_buffers_alloc(port); 923 saa7164_vbi_buffers_alloc(port);
920 924
921 /* Configure the encoder with any cache values */ 925 /* Configure the encoder with any cache values */
922// saa7164_api_set_encoder(port); 926#if 0
923// saa7164_api_get_encoder(port); 927 saa7164_api_set_encoder(port);
928 saa7164_api_get_encoder(port);
929#endif
924 930
925 /* Place the empty buffers on the hardware */ 931 /* Place the empty buffers on the hardware */
926 saa7164_buffer_cfg_port(port); 932 saa7164_buffer_cfg_port(port);
@@ -1060,7 +1066,8 @@ struct saa7164_user_buffer *saa7164_vbi_next_buf(struct saa7164_port *port)
1060 if (crc_checking) { 1066 if (crc_checking) {
1061 crc = crc32(0, ubuf->data, ubuf->actual_size); 1067 crc = crc32(0, ubuf->data, ubuf->actual_size);
1062 if (crc != ubuf->crc) { 1068 if (crc != ubuf->crc) {
1063 printk(KERN_ERR "%s() ubuf %p crc became invalid, was 0x%x became 0x%x\n", __func__, 1069 printk(KERN_ERR "%s() ubuf %p crc became invalid, was 0x%x became 0x%x\n",
1070 __func__,
1064 ubuf, ubuf->crc, crc); 1071 ubuf, ubuf->crc, crc);
1065 } 1072 }
1066 } 1073 }
@@ -1148,9 +1155,8 @@ static ssize_t fops_read(struct file *file, char __user *buffer,
1148 buffer += cnt; 1155 buffer += cnt;
1149 ret += cnt; 1156 ret += cnt;
1150 1157
1151 if (ubuf->pos > ubuf->actual_size) { 1158 if (ubuf->pos > ubuf->actual_size)
1152 printk(KERN_ERR "read() pos > actual, huh?\n"); 1159 printk(KERN_ERR "read() pos > actual, huh?\n");
1153 }
1154 1160
1155 if (ubuf->pos == ubuf->actual_size) { 1161 if (ubuf->pos == ubuf->actual_size) {
1156 1162
@@ -1197,9 +1203,8 @@ static unsigned int fops_poll(struct file *file, poll_table *wait)
1197 saa7164_histogram_update(&port->poll_interval, 1203 saa7164_histogram_update(&port->poll_interval,
1198 port->last_poll_msecs_diff); 1204 port->last_poll_msecs_diff);
1199 1205
1200 if (!video_is_registered(port->v4l_device)) { 1206 if (!video_is_registered(port->v4l_device))
1201 return -EIO; 1207 return -EIO;
1202 }
1203 1208
1204 if (atomic_cmpxchg(&fh->v4l_reading, 0, 1) == 0) { 1209 if (atomic_cmpxchg(&fh->v4l_reading, 0, 1) == 0) {
1205 if (atomic_inc_return(&port->v4l_reader_count) == 1) { 1210 if (atomic_inc_return(&port->v4l_reader_count) == 1) {
@@ -1257,10 +1262,14 @@ static const struct v4l2_ioctl_ops vbi_ioctl_ops = {
1257 .vidioc_try_ext_ctrls = vidioc_try_ext_ctrls, 1262 .vidioc_try_ext_ctrls = vidioc_try_ext_ctrls,
1258 .vidioc_log_status = vidioc_log_status, 1263 .vidioc_log_status = vidioc_log_status,
1259 .vidioc_queryctrl = vidioc_queryctrl, 1264 .vidioc_queryctrl = vidioc_queryctrl,
1260// .vidioc_g_chip_ident = saa7164_g_chip_ident, 1265#if 0
1266 .vidioc_g_chip_ident = saa7164_g_chip_ident,
1267#endif
1261#ifdef CONFIG_VIDEO_ADV_DEBUG 1268#ifdef CONFIG_VIDEO_ADV_DEBUG
1262// .vidioc_g_register = saa7164_g_register, 1269#if 0
1263// .vidioc_s_register = saa7164_s_register, 1270 .vidioc_g_register = saa7164_g_register,
1271 .vidioc_s_register = saa7164_s_register,
1272#endif
1264#endif 1273#endif
1265 .vidioc_g_fmt_vbi_cap = saa7164_vbi_fmt, 1274 .vidioc_g_fmt_vbi_cap = saa7164_vbi_fmt,
1266 .vidioc_try_fmt_vbi_cap = saa7164_vbi_fmt, 1275 .vidioc_try_fmt_vbi_cap = saa7164_vbi_fmt,
diff --git a/drivers/media/video/saa7164/saa7164.h b/drivers/media/video/saa7164/saa7164.h
index 041ae8e20f68..16745d2fb349 100644
--- a/drivers/media/video/saa7164/saa7164.h
+++ b/drivers/media/video/saa7164/saa7164.h
@@ -113,7 +113,8 @@
113#define DBGLVL_THR 4096 113#define DBGLVL_THR 4096
114#define DBGLVL_CPU 8192 114#define DBGLVL_CPU 8192
115 115
116#define SAA7164_NORMS (V4L2_STD_NTSC_M | V4L2_STD_NTSC_M_JP | V4L2_STD_NTSC_443) 116#define SAA7164_NORMS \
117 (V4L2_STD_NTSC_M | V4L2_STD_NTSC_M_JP | V4L2_STD_NTSC_443)
117 118
118enum port_t { 119enum port_t {
119 SAA7164_MPEG_UNDEFINED = 0, 120 SAA7164_MPEG_UNDEFINED = 0,
@@ -182,15 +183,11 @@ struct saa7164_subid {
182 183
183struct saa7164_encoder_fh { 184struct saa7164_encoder_fh {
184 struct saa7164_port *port; 185 struct saa7164_port *port;
185// u32 freq;
186// u32 tuner_type;
187 atomic_t v4l_reading; 186 atomic_t v4l_reading;
188}; 187};
189 188
190struct saa7164_vbi_fh { 189struct saa7164_vbi_fh {
191 struct saa7164_port *port; 190 struct saa7164_port *port;
192// u32 freq;
193// u32 tuner_type;
194 atomic_t v4l_reading; 191 atomic_t v4l_reading;
195}; 192};
196 193
@@ -265,8 +262,6 @@ struct saa7164_ctrl {
265struct saa7164_tvnorm { 262struct saa7164_tvnorm {
266 char *name; 263 char *name;
267 v4l2_std_id id; 264 v4l2_std_id id;
268// u32 cxiformat;
269// u32 cxoformat;
270}; 265};
271 266
272struct saa7164_encoder_params { 267struct saa7164_encoder_params {
@@ -447,7 +442,7 @@ struct saa7164_dev {
447 int nr; 442 int nr;
448 int hwrevision; 443 int hwrevision;
449 u32 board; 444 u32 board;
450 char name[32]; 445 char name[16];
451 446
452 /* firmware status */ 447 /* firmware status */
453 struct saa7164_fw_status fw_status; 448 struct saa7164_fw_status fw_status;
@@ -510,7 +505,8 @@ extern void saa7164_call_i2c_clients(struct saa7164_i2c *bus,
510/* saa7164-bus.c */ 505/* saa7164-bus.c */
511int saa7164_bus_setup(struct saa7164_dev *dev); 506int saa7164_bus_setup(struct saa7164_dev *dev);
512void saa7164_bus_dump(struct saa7164_dev *dev); 507void saa7164_bus_dump(struct saa7164_dev *dev);
513int saa7164_bus_set(struct saa7164_dev *dev, struct tmComResInfo* msg, void *buf); 508int saa7164_bus_set(struct saa7164_dev *dev, struct tmComResInfo* msg,
509 void *buf);
514int saa7164_bus_get(struct saa7164_dev *dev, struct tmComResInfo* msg, 510int saa7164_bus_get(struct saa7164_dev *dev, struct tmComResInfo* msg,
515 void *buf, int peekonly); 511 void *buf, int peekonly);
516 512
@@ -552,7 +548,8 @@ int saa7164_api_get_videomux(struct saa7164_port *port);
552int saa7164_api_set_vbi_format(struct saa7164_port *port); 548int saa7164_api_set_vbi_format(struct saa7164_port *port);
553int saa7164_api_set_debug(struct saa7164_dev *dev, u8 level); 549int saa7164_api_set_debug(struct saa7164_dev *dev, u8 level);
554int saa7164_api_collect_debug(struct saa7164_dev *dev); 550int saa7164_api_collect_debug(struct saa7164_dev *dev);
555int saa7164_api_get_load_info(struct saa7164_dev *dev, struct tmFwInfoStruct *i); 551int saa7164_api_get_load_info(struct saa7164_dev *dev,
552 struct tmFwInfoStruct *i);
556 553
557/* ----------------------------------------------------------- */ 554/* ----------------------------------------------------------- */
558/* saa7164-cards.c */ 555/* saa7164-cards.c */
diff --git a/drivers/media/video/sh_mobile_ceu_camera.c b/drivers/media/video/sh_mobile_ceu_camera.c
index 2486520582f2..954222bc3458 100644
--- a/drivers/media/video/sh_mobile_ceu_camera.c
+++ b/drivers/media/video/sh_mobile_ceu_camera.c
@@ -1786,7 +1786,7 @@ static void sh_mobile_ceu_init_videobuf(struct videobuf_queue *q,
1786 V4L2_BUF_TYPE_VIDEO_CAPTURE, 1786 V4L2_BUF_TYPE_VIDEO_CAPTURE,
1787 pcdev->field, 1787 pcdev->field,
1788 sizeof(struct sh_mobile_ceu_buffer), 1788 sizeof(struct sh_mobile_ceu_buffer),
1789 icd, NULL); 1789 icd, &icd->video_lock);
1790} 1790}
1791 1791
1792static int sh_mobile_ceu_get_ctrl(struct soc_camera_device *icd, 1792static int sh_mobile_ceu_get_ctrl(struct soc_camera_device *icd,
diff --git a/drivers/media/video/sn9c102/sn9c102_core.c b/drivers/media/video/sn9c102/sn9c102_core.c
index f49fbfb7dc13..84984f64b234 100644
--- a/drivers/media/video/sn9c102/sn9c102_core.c
+++ b/drivers/media/video/sn9c102/sn9c102_core.c
@@ -2189,6 +2189,7 @@ sn9c102_vidioc_enuminput(struct sn9c102_device* cam, void __user * arg)
2189 memset(&i, 0, sizeof(i)); 2189 memset(&i, 0, sizeof(i));
2190 strcpy(i.name, "Camera"); 2190 strcpy(i.name, "Camera");
2191 i.type = V4L2_INPUT_TYPE_CAMERA; 2191 i.type = V4L2_INPUT_TYPE_CAMERA;
2192 i.capabilities = V4L2_IN_CAP_STD;
2192 2193
2193 if (copy_to_user(arg, &i, sizeof(i))) 2194 if (copy_to_user(arg, &i, sizeof(i)))
2194 return -EFAULT; 2195 return -EFAULT;
diff --git a/drivers/media/video/sn9c102/sn9c102_devtable.h b/drivers/media/video/sn9c102/sn9c102_devtable.h
index ccfa59c54552..41064c7b5ef8 100644
--- a/drivers/media/video/sn9c102/sn9c102_devtable.h
+++ b/drivers/media/video/sn9c102/sn9c102_devtable.h
@@ -43,9 +43,7 @@ static const struct usb_device_id sn9c102_id_table[] = {
43#if !defined CONFIG_USB_GSPCA_SONIXB && !defined CONFIG_USB_GSPCA_SONIXB_MODULE 43#if !defined CONFIG_USB_GSPCA_SONIXB && !defined CONFIG_USB_GSPCA_SONIXB_MODULE
44 { SN9C102_USB_DEVICE(0x0c45, 0x6001, BRIDGE_SN9C102), }, 44 { SN9C102_USB_DEVICE(0x0c45, 0x6001, BRIDGE_SN9C102), },
45 { SN9C102_USB_DEVICE(0x0c45, 0x6005, BRIDGE_SN9C102), }, 45 { SN9C102_USB_DEVICE(0x0c45, 0x6005, BRIDGE_SN9C102), },
46#endif
47 { SN9C102_USB_DEVICE(0x0c45, 0x6007, BRIDGE_SN9C102), }, 46 { SN9C102_USB_DEVICE(0x0c45, 0x6007, BRIDGE_SN9C102), },
48#if !defined CONFIG_USB_GSPCA_SONIXB && !defined CONFIG_USB_GSPCA_SONIXB_MODULE
49 { SN9C102_USB_DEVICE(0x0c45, 0x6009, BRIDGE_SN9C102), }, 47 { SN9C102_USB_DEVICE(0x0c45, 0x6009, BRIDGE_SN9C102), },
50 { SN9C102_USB_DEVICE(0x0c45, 0x600d, BRIDGE_SN9C102), }, 48 { SN9C102_USB_DEVICE(0x0c45, 0x600d, BRIDGE_SN9C102), },
51/* { SN9C102_USB_DEVICE(0x0c45, 0x6011, BRIDGE_SN9C102), }, OV6650 */ 49/* { SN9C102_USB_DEVICE(0x0c45, 0x6011, BRIDGE_SN9C102), }, OV6650 */
@@ -56,8 +54,8 @@ static const struct usb_device_id sn9c102_id_table[] = {
56#if !defined CONFIG_USB_GSPCA_SONIXB && !defined CONFIG_USB_GSPCA_SONIXB_MODULE 54#if !defined CONFIG_USB_GSPCA_SONIXB && !defined CONFIG_USB_GSPCA_SONIXB_MODULE
57 { SN9C102_USB_DEVICE(0x0c45, 0x6028, BRIDGE_SN9C102), }, 55 { SN9C102_USB_DEVICE(0x0c45, 0x6028, BRIDGE_SN9C102), },
58 { SN9C102_USB_DEVICE(0x0c45, 0x6029, BRIDGE_SN9C102), }, 56 { SN9C102_USB_DEVICE(0x0c45, 0x6029, BRIDGE_SN9C102), },
59#endif
60 { SN9C102_USB_DEVICE(0x0c45, 0x602a, BRIDGE_SN9C102), }, 57 { SN9C102_USB_DEVICE(0x0c45, 0x602a, BRIDGE_SN9C102), },
58#endif
61 { SN9C102_USB_DEVICE(0x0c45, 0x602b, BRIDGE_SN9C102), }, 59 { SN9C102_USB_DEVICE(0x0c45, 0x602b, BRIDGE_SN9C102), },
62#if !defined CONFIG_USB_GSPCA_SONIXB && !defined CONFIG_USB_GSPCA_SONIXB_MODULE 60#if !defined CONFIG_USB_GSPCA_SONIXB && !defined CONFIG_USB_GSPCA_SONIXB_MODULE
63 { SN9C102_USB_DEVICE(0x0c45, 0x602c, BRIDGE_SN9C102), }, 61 { SN9C102_USB_DEVICE(0x0c45, 0x602c, BRIDGE_SN9C102), },
diff --git a/drivers/media/video/soc_camera.c b/drivers/media/video/soc_camera.c
index 052bd6dfa5a7..a66811b43710 100644
--- a/drivers/media/video/soc_camera.c
+++ b/drivers/media/video/soc_camera.c
@@ -24,6 +24,7 @@
24#include <linux/mutex.h> 24#include <linux/mutex.h>
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/platform_device.h> 26#include <linux/platform_device.h>
27#include <linux/regulator/consumer.h>
27#include <linux/slab.h> 28#include <linux/slab.h>
28#include <linux/pm_runtime.h> 29#include <linux/pm_runtime.h>
29#include <linux/vmalloc.h> 30#include <linux/vmalloc.h>
@@ -43,6 +44,51 @@ static LIST_HEAD(hosts);
43static LIST_HEAD(devices); 44static LIST_HEAD(devices);
44static DEFINE_MUTEX(list_lock); /* Protects the list of hosts */ 45static DEFINE_MUTEX(list_lock); /* Protects the list of hosts */
45 46
47static int soc_camera_power_set(struct soc_camera_device *icd,
48 struct soc_camera_link *icl,
49 int power_on)
50{
51 int ret;
52
53 if (power_on) {
54 ret = regulator_bulk_enable(icl->num_regulators,
55 icl->regulators);
56 if (ret < 0) {
57 dev_err(&icd->dev, "Cannot enable regulators\n");
58 return ret;
59 }
60
61 if (icl->power)
62 ret = icl->power(icd->pdev, power_on);
63 if (ret < 0) {
64 dev_err(&icd->dev,
65 "Platform failed to power-on the camera.\n");
66
67 regulator_bulk_disable(icl->num_regulators,
68 icl->regulators);
69 return ret;
70 }
71 } else {
72 ret = 0;
73 if (icl->power)
74 ret = icl->power(icd->pdev, 0);
75 if (ret < 0) {
76 dev_err(&icd->dev,
77 "Platform failed to power-off the camera.\n");
78 return ret;
79 }
80
81 ret = regulator_bulk_disable(icl->num_regulators,
82 icl->regulators);
83 if (ret < 0) {
84 dev_err(&icd->dev, "Cannot disable regulators\n");
85 return ret;
86 }
87 }
88
89 return 0;
90}
91
46const struct soc_camera_format_xlate *soc_camera_xlate_by_fourcc( 92const struct soc_camera_format_xlate *soc_camera_xlate_by_fourcc(
47 struct soc_camera_device *icd, unsigned int fourcc) 93 struct soc_camera_device *icd, unsigned int fourcc)
48{ 94{
@@ -352,12 +398,6 @@ static int soc_camera_open(struct file *file)
352 return -EINVAL; 398 return -EINVAL;
353 } 399 }
354 400
355 /*
356 * Protect against icd->ops->remove() until we module_get() both
357 * drivers.
358 */
359 mutex_lock(&icd->video_lock);
360
361 icd->use_count++; 401 icd->use_count++;
362 402
363 /* Now we really have to activate the camera */ 403 /* Now we really have to activate the camera */
@@ -375,11 +415,9 @@ static int soc_camera_open(struct file *file)
375 }, 415 },
376 }; 416 };
377 417
378 if (icl->power) { 418 ret = soc_camera_power_set(icd, icl, 1);
379 ret = icl->power(icd->pdev, 1); 419 if (ret < 0)
380 if (ret < 0) 420 goto epower;
381 goto epower;
382 }
383 421
384 /* The camera could have been already on, try to reset */ 422 /* The camera could have been already on, try to reset */
385 if (icl->reset) 423 if (icl->reset)
@@ -412,8 +450,6 @@ static int soc_camera_open(struct file *file)
412 file->private_data = icd; 450 file->private_data = icd;
413 dev_dbg(&icd->dev, "camera device open\n"); 451 dev_dbg(&icd->dev, "camera device open\n");
414 452
415 mutex_unlock(&icd->video_lock);
416
417 return 0; 453 return 0;
418 454
419 /* 455 /*
@@ -425,11 +461,9 @@ esfmt:
425eresume: 461eresume:
426 ici->ops->remove(icd); 462 ici->ops->remove(icd);
427eiciadd: 463eiciadd:
428 if (icl->power) 464 soc_camera_power_set(icd, icl, 0);
429 icl->power(icd->pdev, 0);
430epower: 465epower:
431 icd->use_count--; 466 icd->use_count--;
432 mutex_unlock(&icd->video_lock);
433 module_put(ici->ops->owner); 467 module_put(ici->ops->owner);
434 468
435 return ret; 469 return ret;
@@ -440,7 +474,6 @@ static int soc_camera_close(struct file *file)
440 struct soc_camera_device *icd = file->private_data; 474 struct soc_camera_device *icd = file->private_data;
441 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); 475 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
442 476
443 mutex_lock(&icd->video_lock);
444 icd->use_count--; 477 icd->use_count--;
445 if (!icd->use_count) { 478 if (!icd->use_count) {
446 struct soc_camera_link *icl = to_soc_camera_link(icd); 479 struct soc_camera_link *icl = to_soc_camera_link(icd);
@@ -450,15 +483,12 @@ static int soc_camera_close(struct file *file)
450 483
451 ici->ops->remove(icd); 484 ici->ops->remove(icd);
452 485
453 if (icl->power) 486 soc_camera_power_set(icd, icl, 0);
454 icl->power(icd->pdev, 0);
455 } 487 }
456 488
457 if (icd->streamer == file) 489 if (icd->streamer == file)
458 icd->streamer = NULL; 490 icd->streamer = NULL;
459 491
460 mutex_unlock(&icd->video_lock);
461
462 module_put(ici->ops->owner); 492 module_put(ici->ops->owner);
463 493
464 dev_dbg(&icd->dev, "camera device close\n"); 494 dev_dbg(&icd->dev, "camera device close\n");
@@ -517,7 +547,7 @@ static struct v4l2_file_operations soc_camera_fops = {
517 .owner = THIS_MODULE, 547 .owner = THIS_MODULE,
518 .open = soc_camera_open, 548 .open = soc_camera_open,
519 .release = soc_camera_close, 549 .release = soc_camera_close,
520 .ioctl = video_ioctl2, 550 .unlocked_ioctl = video_ioctl2,
521 .read = soc_camera_read, 551 .read = soc_camera_read,
522 .mmap = soc_camera_mmap, 552 .mmap = soc_camera_mmap,
523 .poll = soc_camera_poll, 553 .poll = soc_camera_poll,
@@ -534,12 +564,9 @@ static int soc_camera_s_fmt_vid_cap(struct file *file, void *priv,
534 if (icd->streamer && icd->streamer != file) 564 if (icd->streamer && icd->streamer != file)
535 return -EBUSY; 565 return -EBUSY;
536 566
537 mutex_lock(&icd->vb_vidq.vb_lock);
538
539 if (icd->vb_vidq.bufs[0]) { 567 if (icd->vb_vidq.bufs[0]) {
540 dev_err(&icd->dev, "S_FMT denied: queue initialised\n"); 568 dev_err(&icd->dev, "S_FMT denied: queue initialised\n");
541 ret = -EBUSY; 569 return -EBUSY;
542 goto unlock;
543 } 570 }
544 571
545 ret = soc_camera_set_fmt(icd, f); 572 ret = soc_camera_set_fmt(icd, f);
@@ -547,9 +574,6 @@ static int soc_camera_s_fmt_vid_cap(struct file *file, void *priv,
547 if (!ret && !icd->streamer) 574 if (!ret && !icd->streamer)
548 icd->streamer = file; 575 icd->streamer = file;
549 576
550unlock:
551 mutex_unlock(&icd->vb_vidq.vb_lock);
552
553 return ret; 577 return ret;
554} 578}
555 579
@@ -622,15 +646,11 @@ static int soc_camera_streamon(struct file *file, void *priv,
622 if (icd->streamer != file) 646 if (icd->streamer != file)
623 return -EBUSY; 647 return -EBUSY;
624 648
625 mutex_lock(&icd->video_lock);
626
627 v4l2_subdev_call(sd, video, s_stream, 1); 649 v4l2_subdev_call(sd, video, s_stream, 1);
628 650
629 /* This calls buf_queue from host driver's videobuf_queue_ops */ 651 /* This calls buf_queue from host driver's videobuf_queue_ops */
630 ret = videobuf_streamon(&icd->vb_vidq); 652 ret = videobuf_streamon(&icd->vb_vidq);
631 653
632 mutex_unlock(&icd->video_lock);
633
634 return ret; 654 return ret;
635} 655}
636 656
@@ -648,8 +668,6 @@ static int soc_camera_streamoff(struct file *file, void *priv,
648 if (icd->streamer != file) 668 if (icd->streamer != file)
649 return -EBUSY; 669 return -EBUSY;
650 670
651 mutex_lock(&icd->video_lock);
652
653 /* 671 /*
654 * This calls buf_release from host driver's videobuf_queue_ops for all 672 * This calls buf_release from host driver's videobuf_queue_ops for all
655 * remaining buffers. When the last buffer is freed, stop capture 673 * remaining buffers. When the last buffer is freed, stop capture
@@ -658,8 +676,6 @@ static int soc_camera_streamoff(struct file *file, void *priv,
658 676
659 v4l2_subdev_call(sd, video, s_stream, 0); 677 v4l2_subdev_call(sd, video, s_stream, 0);
660 678
661 mutex_unlock(&icd->video_lock);
662
663 return 0; 679 return 0;
664} 680}
665 681
@@ -748,9 +764,7 @@ static int soc_camera_g_crop(struct file *file, void *fh,
748 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); 764 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
749 int ret; 765 int ret;
750 766
751 mutex_lock(&icd->vb_vidq.vb_lock);
752 ret = ici->ops->get_crop(icd, a); 767 ret = ici->ops->get_crop(icd, a);
753 mutex_unlock(&icd->vb_vidq.vb_lock);
754 768
755 return ret; 769 return ret;
756} 770}
@@ -775,9 +789,6 @@ static int soc_camera_s_crop(struct file *file, void *fh,
775 dev_dbg(&icd->dev, "S_CROP(%ux%u@%u:%u)\n", 789 dev_dbg(&icd->dev, "S_CROP(%ux%u@%u:%u)\n",
776 rect->width, rect->height, rect->left, rect->top); 790 rect->width, rect->height, rect->left, rect->top);
777 791
778 /* Cropping is allowed during a running capture, guard consistency */
779 mutex_lock(&icd->vb_vidq.vb_lock);
780
781 /* If get_crop fails, we'll let host and / or client drivers decide */ 792 /* If get_crop fails, we'll let host and / or client drivers decide */
782 ret = ici->ops->get_crop(icd, &current_crop); 793 ret = ici->ops->get_crop(icd, &current_crop);
783 794
@@ -795,8 +806,6 @@ static int soc_camera_s_crop(struct file *file, void *fh,
795 ret = ici->ops->set_crop(icd, a); 806 ret = ici->ops->set_crop(icd, a);
796 } 807 }
797 808
798 mutex_unlock(&icd->vb_vidq.vb_lock);
799
800 return ret; 809 return ret;
801} 810}
802 811
@@ -941,14 +950,14 @@ static int soc_camera_probe(struct device *dev)
941 950
942 dev_info(dev, "Probing %s\n", dev_name(dev)); 951 dev_info(dev, "Probing %s\n", dev_name(dev));
943 952
944 if (icl->power) { 953 ret = regulator_bulk_get(icd->pdev, icl->num_regulators,
945 ret = icl->power(icd->pdev, 1); 954 icl->regulators);
946 if (ret < 0) { 955 if (ret < 0)
947 dev_err(dev, 956 goto ereg;
948 "Platform failed to power-on the camera.\n"); 957
949 goto epower; 958 ret = soc_camera_power_set(icd, icl, 1);
950 } 959 if (ret < 0)
951 } 960 goto epower;
952 961
953 /* The camera could have been already on, try to reset */ 962 /* The camera could have been already on, try to reset */
954 if (icl->reset) 963 if (icl->reset)
@@ -998,7 +1007,13 @@ static int soc_camera_probe(struct device *dev)
998 1007
999 icd->field = V4L2_FIELD_ANY; 1008 icd->field = V4L2_FIELD_ANY;
1000 1009
1001 /* ..._video_start() will create a device node, so we have to protect */ 1010 icd->vdev->lock = &icd->video_lock;
1011
1012 /*
1013 * ..._video_start() will create a device node, video_register_device()
1014 * itself is protected against concurrent open() calls, but we also have
1015 * to protect our data.
1016 */
1002 mutex_lock(&icd->video_lock); 1017 mutex_lock(&icd->video_lock);
1003 1018
1004 ret = soc_camera_video_start(icd); 1019 ret = soc_camera_video_start(icd);
@@ -1021,8 +1036,7 @@ static int soc_camera_probe(struct device *dev)
1021 1036
1022 ici->ops->remove(icd); 1037 ici->ops->remove(icd);
1023 1038
1024 if (icl->power) 1039 soc_camera_power_set(icd, icl, 0);
1025 icl->power(icd->pdev, 0);
1026 1040
1027 mutex_unlock(&icd->video_lock); 1041 mutex_unlock(&icd->video_lock);
1028 1042
@@ -1044,9 +1058,10 @@ eadddev:
1044evdc: 1058evdc:
1045 ici->ops->remove(icd); 1059 ici->ops->remove(icd);
1046eadd: 1060eadd:
1047 if (icl->power) 1061 soc_camera_power_set(icd, icl, 0);
1048 icl->power(icd->pdev, 0);
1049epower: 1062epower:
1063 regulator_bulk_free(icl->num_regulators, icl->regulators);
1064ereg:
1050 return ret; 1065 return ret;
1051} 1066}
1052 1067
@@ -1063,10 +1078,8 @@ static int soc_camera_remove(struct device *dev)
1063 BUG_ON(!dev->parent); 1078 BUG_ON(!dev->parent);
1064 1079
1065 if (vdev) { 1080 if (vdev) {
1066 mutex_lock(&icd->video_lock);
1067 video_unregister_device(vdev); 1081 video_unregister_device(vdev);
1068 icd->vdev = NULL; 1082 icd->vdev = NULL;
1069 mutex_unlock(&icd->video_lock);
1070 } 1083 }
1071 1084
1072 if (icl->board_info) { 1085 if (icl->board_info) {
@@ -1081,6 +1094,8 @@ static int soc_camera_remove(struct device *dev)
1081 } 1094 }
1082 soc_camera_free_user_formats(icd); 1095 soc_camera_free_user_formats(icd);
1083 1096
1097 regulator_bulk_free(icl->num_regulators, icl->regulators);
1098
1084 return 0; 1099 return 0;
1085} 1100}
1086 1101
diff --git a/drivers/media/video/sr030pc30.c b/drivers/media/video/sr030pc30.c
index c9dc67aba980..864696b7a006 100644
--- a/drivers/media/video/sr030pc30.c
+++ b/drivers/media/video/sr030pc30.c
@@ -735,7 +735,7 @@ static int sr030pc30_s_power(struct v4l2_subdev *sd, int on)
735 const struct sr030pc30_platform_data *pdata = info->pdata; 735 const struct sr030pc30_platform_data *pdata = info->pdata;
736 int ret; 736 int ret;
737 737
738 if (WARN(pdata == NULL, "No platform data!")) 738 if (WARN(pdata == NULL, "No platform data!\n"))
739 return -ENOMEM; 739 return -ENOMEM;
740 740
741 /* 741 /*
diff --git a/drivers/media/video/stk-webcam.c b/drivers/media/video/stk-webcam.c
index b5afe5f841ce..d1a2cefbf55b 100644
--- a/drivers/media/video/stk-webcam.c
+++ b/drivers/media/video/stk-webcam.c
@@ -230,120 +230,6 @@ static int stk_initialise(struct stk_camera *dev)
230 return -1; 230 return -1;
231} 231}
232 232
233#ifdef CONFIG_VIDEO_V4L1_COMPAT
234
235/* sysfs functions */
236/*FIXME cleanup this */
237
238static ssize_t show_brightness(struct device *class,
239 struct device_attribute *attr, char *buf)
240{
241 struct video_device *vdev = to_video_device(class);
242 struct stk_camera *dev = vdev_to_camera(vdev);
243
244 return sprintf(buf, "%X\n", dev->vsettings.brightness);
245}
246
247static ssize_t store_brightness(struct device *class,
248 struct device_attribute *attr, const char *buf, size_t count)
249{
250 char *endp;
251 unsigned long value;
252 int ret;
253
254 struct video_device *vdev = to_video_device(class);
255 struct stk_camera *dev = vdev_to_camera(vdev);
256
257 value = simple_strtoul(buf, &endp, 16);
258
259 dev->vsettings.brightness = (int) value;
260
261 ret = stk_sensor_set_brightness(dev, value >> 8);
262 if (ret)
263 return ret;
264 else
265 return count;
266}
267
268static ssize_t show_hflip(struct device *class,
269 struct device_attribute *attr, char *buf)
270{
271 struct video_device *vdev = to_video_device(class);
272 struct stk_camera *dev = vdev_to_camera(vdev);
273
274 return sprintf(buf, "%d\n", dev->vsettings.hflip);
275}
276
277static ssize_t store_hflip(struct device *class,
278 struct device_attribute *attr, const char *buf, size_t count)
279{
280 struct video_device *vdev = to_video_device(class);
281 struct stk_camera *dev = vdev_to_camera(vdev);
282
283 if (strncmp(buf, "1", 1) == 0)
284 dev->vsettings.hflip = 1;
285 else if (strncmp(buf, "0", 1) == 0)
286 dev->vsettings.hflip = 0;
287 else
288 return -EINVAL;
289
290 return strlen(buf);
291}
292
293static ssize_t show_vflip(struct device *class,
294 struct device_attribute *attr, char *buf)
295{
296 struct video_device *vdev = to_video_device(class);
297 struct stk_camera *dev = vdev_to_camera(vdev);
298
299 return sprintf(buf, "%d\n", dev->vsettings.vflip);
300}
301
302static ssize_t store_vflip(struct device *class,
303 struct device_attribute *attr, const char *buf, size_t count)
304{
305 struct video_device *vdev = to_video_device(class);
306 struct stk_camera *dev = vdev_to_camera(vdev);
307
308 if (strncmp(buf, "1", 1) == 0)
309 dev->vsettings.vflip = 1;
310 else if (strncmp(buf, "0", 1) == 0)
311 dev->vsettings.vflip = 0;
312 else
313 return -EINVAL;
314
315 return strlen(buf);
316}
317
318static DEVICE_ATTR(brightness, S_IRUGO | S_IWUGO,
319 show_brightness, store_brightness);
320static DEVICE_ATTR(hflip, S_IRUGO | S_IWUGO, show_hflip, store_hflip);
321static DEVICE_ATTR(vflip, S_IRUGO | S_IWUGO, show_vflip, store_vflip);
322
323static int stk_create_sysfs_files(struct video_device *vdev)
324{
325 int ret;
326
327 ret = device_create_file(&vdev->dev, &dev_attr_brightness);
328 ret += device_create_file(&vdev->dev, &dev_attr_hflip);
329 ret += device_create_file(&vdev->dev, &dev_attr_vflip);
330 if (ret)
331 STK_WARNING("Could not create sysfs files\n");
332 return ret;
333}
334
335static void stk_remove_sysfs_files(struct video_device *vdev)
336{
337 device_remove_file(&vdev->dev, &dev_attr_brightness);
338 device_remove_file(&vdev->dev, &dev_attr_hflip);
339 device_remove_file(&vdev->dev, &dev_attr_vflip);
340}
341
342#else
343#define stk_create_sysfs_files(a)
344#define stk_remove_sysfs_files(a)
345#endif
346
347/* *********************************************** */ 233/* *********************************************** */
348/* 234/*
349 * This function is called as an URB transfert is complete (Isochronous pipe). 235 * This function is called as an URB transfert is complete (Isochronous pipe).
@@ -878,7 +764,24 @@ static struct v4l2_queryctrl stk_controls[] = {
878 .step = 0x0100, 764 .step = 0x0100,
879 .default_value = 0x6000, 765 .default_value = 0x6000,
880 }, 766 },
881 /*TODO: get more controls to work */ 767 {
768 .id = V4L2_CID_HFLIP,
769 .type = V4L2_CTRL_TYPE_BOOLEAN,
770 .name = "Horizontal Flip",
771 .minimum = 0,
772 .maximum = 1,
773 .step = 1,
774 .default_value = 1,
775 },
776 {
777 .id = V4L2_CID_VFLIP,
778 .type = V4L2_CTRL_TYPE_BOOLEAN,
779 .name = "Vertical Flip",
780 .minimum = 0,
781 .maximum = 1,
782 .step = 1,
783 .default_value = 1,
784 },
882}; 785};
883 786
884static int stk_vidioc_queryctrl(struct file *filp, 787static int stk_vidioc_queryctrl(struct file *filp,
@@ -906,6 +809,12 @@ static int stk_vidioc_g_ctrl(struct file *filp,
906 case V4L2_CID_BRIGHTNESS: 809 case V4L2_CID_BRIGHTNESS:
907 c->value = dev->vsettings.brightness; 810 c->value = dev->vsettings.brightness;
908 break; 811 break;
812 case V4L2_CID_HFLIP:
813 c->value = dev->vsettings.hflip;
814 break;
815 case V4L2_CID_VFLIP:
816 c->value = dev->vsettings.vflip;
817 break;
909 default: 818 default:
910 return -EINVAL; 819 return -EINVAL;
911 } 820 }
@@ -920,6 +829,12 @@ static int stk_vidioc_s_ctrl(struct file *filp,
920 case V4L2_CID_BRIGHTNESS: 829 case V4L2_CID_BRIGHTNESS:
921 dev->vsettings.brightness = c->value; 830 dev->vsettings.brightness = c->value;
922 return stk_sensor_set_brightness(dev, c->value >> 8); 831 return stk_sensor_set_brightness(dev, c->value >> 8);
832 case V4L2_CID_HFLIP:
833 dev->vsettings.hflip = c->value;
834 return 0;
835 case V4L2_CID_VFLIP:
836 dev->vsettings.vflip = c->value;
837 return 0;
923 default: 838 default:
924 return -EINVAL; 839 return -EINVAL;
925 } 840 }
@@ -1394,8 +1309,6 @@ static int stk_camera_probe(struct usb_interface *interface,
1394 goto error; 1309 goto error;
1395 } 1310 }
1396 1311
1397 stk_create_sysfs_files(&dev->vdev);
1398
1399 return 0; 1312 return 0;
1400 1313
1401error: 1314error:
@@ -1411,7 +1324,6 @@ static void stk_camera_disconnect(struct usb_interface *interface)
1411 unset_present(dev); 1324 unset_present(dev);
1412 1325
1413 wake_up_interruptible(&dev->wait_frame); 1326 wake_up_interruptible(&dev->wait_frame);
1414 stk_remove_sysfs_files(&dev->vdev);
1415 1327
1416 STK_INFO("Syntek USB2.0 Camera release resources device %s\n", 1328 STK_INFO("Syntek USB2.0 Camera release resources device %s\n",
1417 video_device_node_name(&dev->vdev)); 1329 video_device_node_name(&dev->vdev));
diff --git a/drivers/media/video/tea6415c.c b/drivers/media/video/tea6415c.c
index 3e99cea8e4dc..19621ed523ec 100644
--- a/drivers/media/video/tea6415c.c
+++ b/drivers/media/video/tea6415c.c
@@ -148,7 +148,7 @@ static int tea6415c_probe(struct i2c_client *client,
148 148
149 /* let's see whether this adapter can support what we need */ 149 /* let's see whether this adapter can support what we need */
150 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WRITE_BYTE)) 150 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WRITE_BYTE))
151 return 0; 151 return -EIO;
152 152
153 v4l_info(client, "chip found @ 0x%x (%s)\n", 153 v4l_info(client, "chip found @ 0x%x (%s)\n",
154 client->addr << 1, client->adapter->name); 154 client->addr << 1, client->adapter->name);
diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
new file mode 100644
index 000000000000..fc611ebeb82c
--- /dev/null
+++ b/drivers/media/video/timblogiw.c
@@ -0,0 +1,893 @@
1/*
2 * timblogiw.c timberdale FPGA LogiWin Video In driver
3 * Copyright (c) 2009-2010 Intel Corporation
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19/* Supports:
20 * Timberdale FPGA LogiWin Video In
21 */
22
23#include <linux/version.h>
24#include <linux/platform_device.h>
25#include <linux/slab.h>
26#include <linux/dmaengine.h>
27#include <linux/scatterlist.h>
28#include <linux/interrupt.h>
29#include <linux/list.h>
30#include <linux/i2c.h>
31#include <media/v4l2-ioctl.h>
32#include <media/v4l2-device.h>
33#include <media/videobuf-dma-contig.h>
34#include <media/timb_video.h>
35
36#define DRIVER_NAME "timb-video"
37
38#define TIMBLOGIWIN_NAME "Timberdale Video-In"
39#define TIMBLOGIW_VERSION_CODE 0x04
40
41#define TIMBLOGIW_LINES_PER_DESC 44
42#define TIMBLOGIW_MAX_VIDEO_MEM 16
43
44#define TIMBLOGIW_HAS_DECODER(lw) (lw->pdata.encoder.module_name)
45
46
47struct timblogiw {
48 struct video_device video_dev;
49 struct v4l2_device v4l2_dev; /* mutual exclusion */
50 struct mutex lock;
51 struct device *dev;
52 struct timb_video_platform_data pdata;
53 struct v4l2_subdev *sd_enc; /* encoder */
54 bool opened;
55};
56
57struct timblogiw_tvnorm {
58 v4l2_std_id std;
59 u16 width;
60 u16 height;
61 u8 fps;
62};
63
64struct timblogiw_fh {
65 struct videobuf_queue vb_vidq;
66 struct timblogiw_tvnorm const *cur_norm;
67 struct list_head capture;
68 struct dma_chan *chan;
69 spinlock_t queue_lock; /* mutual exclusion */
70 unsigned int frame_count;
71};
72
73struct timblogiw_buffer {
74 /* common v4l buffer stuff -- must be first */
75 struct videobuf_buffer vb;
76 struct scatterlist sg[16];
77 dma_cookie_t cookie;
78 struct timblogiw_fh *fh;
79};
80
81const struct timblogiw_tvnorm timblogiw_tvnorms[] = {
82 {
83 .std = V4L2_STD_PAL,
84 .width = 720,
85 .height = 576,
86 .fps = 25
87 },
88 {
89 .std = V4L2_STD_NTSC,
90 .width = 720,
91 .height = 480,
92 .fps = 30
93 }
94};
95
96static int timblogiw_bytes_per_line(const struct timblogiw_tvnorm *norm)
97{
98 return norm->width * 2;
99}
100
101
102static int timblogiw_frame_size(const struct timblogiw_tvnorm *norm)
103{
104 return norm->height * timblogiw_bytes_per_line(norm);
105}
106
107static const struct timblogiw_tvnorm *timblogiw_get_norm(const v4l2_std_id std)
108{
109 int i;
110 for (i = 0; i < ARRAY_SIZE(timblogiw_tvnorms); i++)
111 if (timblogiw_tvnorms[i].std & std)
112 return timblogiw_tvnorms + i;
113
114 /* default to first element */
115 return timblogiw_tvnorms;
116}
117
118static void timblogiw_dma_cb(void *data)
119{
120 struct timblogiw_buffer *buf = data;
121 struct timblogiw_fh *fh = buf->fh;
122 struct videobuf_buffer *vb = &buf->vb;
123
124 spin_lock(&fh->queue_lock);
125
126 /* mark the transfer done */
127 buf->cookie = -1;
128
129 fh->frame_count++;
130
131 if (vb->state != VIDEOBUF_ERROR) {
132 list_del(&vb->queue);
133 do_gettimeofday(&vb->ts);
134 vb->field_count = fh->frame_count * 2;
135 vb->state = VIDEOBUF_DONE;
136
137 wake_up(&vb->done);
138 }
139
140 if (!list_empty(&fh->capture)) {
141 vb = list_entry(fh->capture.next, struct videobuf_buffer,
142 queue);
143 vb->state = VIDEOBUF_ACTIVE;
144 }
145
146 spin_unlock(&fh->queue_lock);
147}
148
149static bool timblogiw_dma_filter_fn(struct dma_chan *chan, void *filter_param)
150{
151 return chan->chan_id == (uintptr_t)filter_param;
152}
153
154/* IOCTL functions */
155
156static int timblogiw_g_fmt(struct file *file, void *priv,
157 struct v4l2_format *format)
158{
159 struct video_device *vdev = video_devdata(file);
160 struct timblogiw *lw = video_get_drvdata(vdev);
161 struct timblogiw_fh *fh = priv;
162
163 dev_dbg(&vdev->dev, "%s entry\n", __func__);
164
165 if (format->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
166 return -EINVAL;
167
168 mutex_lock(&lw->lock);
169
170 format->fmt.pix.width = fh->cur_norm->width;
171 format->fmt.pix.height = fh->cur_norm->height;
172 format->fmt.pix.pixelformat = V4L2_PIX_FMT_UYVY;
173 format->fmt.pix.bytesperline = timblogiw_bytes_per_line(fh->cur_norm);
174 format->fmt.pix.sizeimage = timblogiw_frame_size(fh->cur_norm);
175 format->fmt.pix.field = V4L2_FIELD_NONE;
176
177 mutex_unlock(&lw->lock);
178
179 return 0;
180}
181
182static int timblogiw_try_fmt(struct file *file, void *priv,
183 struct v4l2_format *format)
184{
185 struct video_device *vdev = video_devdata(file);
186 struct v4l2_pix_format *pix = &format->fmt.pix;
187
188 dev_dbg(&vdev->dev,
189 "%s - width=%d, height=%d, pixelformat=%d, field=%d\n"
190 "bytes per line %d, size image: %d, colorspace: %d\n",
191 __func__,
192 pix->width, pix->height, pix->pixelformat, pix->field,
193 pix->bytesperline, pix->sizeimage, pix->colorspace);
194
195 if (format->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
196 return -EINVAL;
197
198 if (pix->field != V4L2_FIELD_NONE)
199 return -EINVAL;
200
201 if (pix->pixelformat != V4L2_PIX_FMT_UYVY)
202 return -EINVAL;
203
204 return 0;
205}
206
207static int timblogiw_s_fmt(struct file *file, void *priv,
208 struct v4l2_format *format)
209{
210 struct video_device *vdev = video_devdata(file);
211 struct timblogiw *lw = video_get_drvdata(vdev);
212 struct timblogiw_fh *fh = priv;
213 struct v4l2_pix_format *pix = &format->fmt.pix;
214 int err;
215
216 mutex_lock(&lw->lock);
217
218 err = timblogiw_try_fmt(file, priv, format);
219 if (err)
220 goto out;
221
222 if (videobuf_queue_is_busy(&fh->vb_vidq)) {
223 dev_err(&vdev->dev, "%s queue busy\n", __func__);
224 err = -EBUSY;
225 goto out;
226 }
227
228 pix->width = fh->cur_norm->width;
229 pix->height = fh->cur_norm->height;
230
231out:
232 mutex_unlock(&lw->lock);
233 return err;
234}
235
236static int timblogiw_querycap(struct file *file, void *priv,
237 struct v4l2_capability *cap)
238{
239 struct video_device *vdev = video_devdata(file);
240
241 dev_dbg(&vdev->dev, "%s: Entry\n", __func__);
242 memset(cap, 0, sizeof(*cap));
243 strncpy(cap->card, TIMBLOGIWIN_NAME, sizeof(cap->card)-1);
244 strncpy(cap->driver, DRIVER_NAME, sizeof(cap->driver) - 1);
245 strlcpy(cap->bus_info, vdev->name, sizeof(cap->bus_info));
246 cap->version = TIMBLOGIW_VERSION_CODE;
247 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING |
248 V4L2_CAP_READWRITE;
249
250 return 0;
251}
252
253static int timblogiw_enum_fmt(struct file *file, void *priv,
254 struct v4l2_fmtdesc *fmt)
255{
256 struct video_device *vdev = video_devdata(file);
257
258 dev_dbg(&vdev->dev, "%s, index: %d\n", __func__, fmt->index);
259
260 if (fmt->index != 0)
261 return -EINVAL;
262 memset(fmt, 0, sizeof(*fmt));
263 fmt->index = 0;
264 fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
265 strncpy(fmt->description, "4:2:2, packed, YUYV",
266 sizeof(fmt->description)-1);
267 fmt->pixelformat = V4L2_PIX_FMT_UYVY;
268
269 return 0;
270}
271
272static int timblogiw_g_parm(struct file *file, void *priv,
273 struct v4l2_streamparm *sp)
274{
275 struct timblogiw_fh *fh = priv;
276 struct v4l2_captureparm *cp = &sp->parm.capture;
277
278 cp->capability = V4L2_CAP_TIMEPERFRAME;
279 cp->timeperframe.numerator = 1;
280 cp->timeperframe.denominator = fh->cur_norm->fps;
281
282 return 0;
283}
284
285static int timblogiw_reqbufs(struct file *file, void *priv,
286 struct v4l2_requestbuffers *rb)
287{
288 struct video_device *vdev = video_devdata(file);
289 struct timblogiw_fh *fh = priv;
290
291 dev_dbg(&vdev->dev, "%s: entry\n", __func__);
292
293 return videobuf_reqbufs(&fh->vb_vidq, rb);
294}
295
296static int timblogiw_querybuf(struct file *file, void *priv,
297 struct v4l2_buffer *b)
298{
299 struct video_device *vdev = video_devdata(file);
300 struct timblogiw_fh *fh = priv;
301
302 dev_dbg(&vdev->dev, "%s: entry\n", __func__);
303
304 return videobuf_querybuf(&fh->vb_vidq, b);
305}
306
307static int timblogiw_qbuf(struct file *file, void *priv, struct v4l2_buffer *b)
308{
309 struct video_device *vdev = video_devdata(file);
310 struct timblogiw_fh *fh = priv;
311
312 dev_dbg(&vdev->dev, "%s: entry\n", __func__);
313
314 return videobuf_qbuf(&fh->vb_vidq, b);
315}
316
317static int timblogiw_dqbuf(struct file *file, void *priv,
318 struct v4l2_buffer *b)
319{
320 struct video_device *vdev = video_devdata(file);
321 struct timblogiw_fh *fh = priv;
322
323 dev_dbg(&vdev->dev, "%s: entry\n", __func__);
324
325 return videobuf_dqbuf(&fh->vb_vidq, b, file->f_flags & O_NONBLOCK);
326}
327
328static int timblogiw_g_std(struct file *file, void *priv, v4l2_std_id *std)
329{
330 struct video_device *vdev = video_devdata(file);
331 struct timblogiw_fh *fh = priv;
332
333 dev_dbg(&vdev->dev, "%s: entry\n", __func__);
334
335 *std = fh->cur_norm->std;
336 return 0;
337}
338
339static int timblogiw_s_std(struct file *file, void *priv, v4l2_std_id *std)
340{
341 struct video_device *vdev = video_devdata(file);
342 struct timblogiw *lw = video_get_drvdata(vdev);
343 struct timblogiw_fh *fh = priv;
344 int err = 0;
345
346 dev_dbg(&vdev->dev, "%s: entry\n", __func__);
347
348 mutex_lock(&lw->lock);
349
350 if (TIMBLOGIW_HAS_DECODER(lw))
351 err = v4l2_subdev_call(lw->sd_enc, core, s_std, *std);
352
353 if (!err)
354 fh->cur_norm = timblogiw_get_norm(*std);
355
356 mutex_unlock(&lw->lock);
357
358 return err;
359}
360
361static int timblogiw_enuminput(struct file *file, void *priv,
362 struct v4l2_input *inp)
363{
364 struct video_device *vdev = video_devdata(file);
365 int i;
366
367 dev_dbg(&vdev->dev, "%s: Entry\n", __func__);
368
369 if (inp->index != 0)
370 return -EINVAL;
371
372 inp->index = 0;
373
374 strncpy(inp->name, "Timb input 1", sizeof(inp->name) - 1);
375 inp->type = V4L2_INPUT_TYPE_CAMERA;
376
377 inp->std = 0;
378 for (i = 0; i < ARRAY_SIZE(timblogiw_tvnorms); i++)
379 inp->std |= timblogiw_tvnorms[i].std;
380
381 return 0;
382}
383
384static int timblogiw_g_input(struct file *file, void *priv,
385 unsigned int *input)
386{
387 struct video_device *vdev = video_devdata(file);
388
389 dev_dbg(&vdev->dev, "%s: Entry\n", __func__);
390
391 *input = 0;
392
393 return 0;
394}
395
396static int timblogiw_s_input(struct file *file, void *priv, unsigned int input)
397{
398 struct video_device *vdev = video_devdata(file);
399
400 dev_dbg(&vdev->dev, "%s: Entry\n", __func__);
401
402 if (input != 0)
403 return -EINVAL;
404 return 0;
405}
406
407static int timblogiw_streamon(struct file *file, void *priv, unsigned int type)
408{
409 struct video_device *vdev = video_devdata(file);
410 struct timblogiw_fh *fh = priv;
411
412 dev_dbg(&vdev->dev, "%s: entry\n", __func__);
413
414 if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
415 dev_dbg(&vdev->dev, "%s - No capture device\n", __func__);
416 return -EINVAL;
417 }
418
419 fh->frame_count = 0;
420 return videobuf_streamon(&fh->vb_vidq);
421}
422
423static int timblogiw_streamoff(struct file *file, void *priv,
424 unsigned int type)
425{
426 struct video_device *vdev = video_devdata(file);
427 struct timblogiw_fh *fh = priv;
428
429 dev_dbg(&vdev->dev, "%s entry\n", __func__);
430
431 if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
432 return -EINVAL;
433
434 return videobuf_streamoff(&fh->vb_vidq);
435}
436
437static int timblogiw_querystd(struct file *file, void *priv, v4l2_std_id *std)
438{
439 struct video_device *vdev = video_devdata(file);
440 struct timblogiw *lw = video_get_drvdata(vdev);
441 struct timblogiw_fh *fh = priv;
442
443 dev_dbg(&vdev->dev, "%s entry\n", __func__);
444
445 if (TIMBLOGIW_HAS_DECODER(lw))
446 return v4l2_subdev_call(lw->sd_enc, video, querystd, std);
447 else {
448 *std = fh->cur_norm->std;
449 return 0;
450 }
451}
452
453static int timblogiw_enum_framesizes(struct file *file, void *priv,
454 struct v4l2_frmsizeenum *fsize)
455{
456 struct video_device *vdev = video_devdata(file);
457 struct timblogiw_fh *fh = priv;
458
459 dev_dbg(&vdev->dev, "%s - index: %d, format: %d\n", __func__,
460 fsize->index, fsize->pixel_format);
461
462 if ((fsize->index != 0) ||
463 (fsize->pixel_format != V4L2_PIX_FMT_UYVY))
464 return -EINVAL;
465
466 fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE;
467 fsize->discrete.width = fh->cur_norm->width;
468 fsize->discrete.height = fh->cur_norm->height;
469
470 return 0;
471}
472
473/* Video buffer functions */
474
475static int buffer_setup(struct videobuf_queue *vq, unsigned int *count,
476 unsigned int *size)
477{
478 struct timblogiw_fh *fh = vq->priv_data;
479
480 *size = timblogiw_frame_size(fh->cur_norm);
481
482 if (!*count)
483 *count = 32;
484
485 while (*size * *count > TIMBLOGIW_MAX_VIDEO_MEM * 1024 * 1024)
486 (*count)--;
487
488 return 0;
489}
490
491static int buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
492 enum v4l2_field field)
493{
494 struct timblogiw_fh *fh = vq->priv_data;
495 struct timblogiw_buffer *buf = container_of(vb, struct timblogiw_buffer,
496 vb);
497 unsigned int data_size = timblogiw_frame_size(fh->cur_norm);
498 int err = 0;
499
500 if (vb->baddr && vb->bsize < data_size)
501 /* User provided buffer, but it is too small */
502 return -ENOMEM;
503
504 vb->size = data_size;
505 vb->width = fh->cur_norm->width;
506 vb->height = fh->cur_norm->height;
507 vb->field = field;
508
509 if (vb->state == VIDEOBUF_NEEDS_INIT) {
510 int i;
511 unsigned int size;
512 unsigned int bytes_per_desc = TIMBLOGIW_LINES_PER_DESC *
513 timblogiw_bytes_per_line(fh->cur_norm);
514 dma_addr_t addr;
515
516 sg_init_table(buf->sg, ARRAY_SIZE(buf->sg));
517
518 err = videobuf_iolock(vq, vb, NULL);
519 if (err)
520 goto err;
521
522 addr = videobuf_to_dma_contig(vb);
523 for (i = 0, size = 0; size < data_size; i++) {
524 sg_dma_address(buf->sg + i) = addr + size;
525 size += bytes_per_desc;
526 sg_dma_len(buf->sg + i) = (size > data_size) ?
527 (bytes_per_desc - (size - data_size)) :
528 bytes_per_desc;
529 }
530
531 vb->state = VIDEOBUF_PREPARED;
532 buf->cookie = -1;
533 buf->fh = fh;
534 }
535
536 return 0;
537
538err:
539 videobuf_dma_contig_free(vq, vb);
540 vb->state = VIDEOBUF_NEEDS_INIT;
541 return err;
542}
543
544static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
545{
546 struct timblogiw_fh *fh = vq->priv_data;
547 struct timblogiw_buffer *buf = container_of(vb, struct timblogiw_buffer,
548 vb);
549 struct dma_async_tx_descriptor *desc;
550 int sg_elems;
551 int bytes_per_desc = TIMBLOGIW_LINES_PER_DESC *
552 timblogiw_bytes_per_line(fh->cur_norm);
553
554 sg_elems = timblogiw_frame_size(fh->cur_norm) / bytes_per_desc;
555 sg_elems +=
556 (timblogiw_frame_size(fh->cur_norm) % bytes_per_desc) ? 1 : 0;
557
558 if (list_empty(&fh->capture))
559 vb->state = VIDEOBUF_ACTIVE;
560 else
561 vb->state = VIDEOBUF_QUEUED;
562
563 list_add_tail(&vb->queue, &fh->capture);
564
565 spin_unlock_irq(&fh->queue_lock);
566
567 desc = fh->chan->device->device_prep_slave_sg(fh->chan,
568 buf->sg, sg_elems, DMA_FROM_DEVICE,
569 DMA_PREP_INTERRUPT | DMA_COMPL_SKIP_SRC_UNMAP);
570 if (!desc) {
571 spin_lock_irq(&fh->queue_lock);
572 list_del_init(&vb->queue);
573 vb->state = VIDEOBUF_PREPARED;
574 return;
575 }
576
577 desc->callback_param = buf;
578 desc->callback = timblogiw_dma_cb;
579
580 buf->cookie = desc->tx_submit(desc);
581
582 spin_lock_irq(&fh->queue_lock);
583}
584
585static void buffer_release(struct videobuf_queue *vq,
586 struct videobuf_buffer *vb)
587{
588 struct timblogiw_fh *fh = vq->priv_data;
589 struct timblogiw_buffer *buf = container_of(vb, struct timblogiw_buffer,
590 vb);
591
592 videobuf_waiton(vq, vb, 0, 0);
593 if (buf->cookie >= 0)
594 dma_sync_wait(fh->chan, buf->cookie);
595
596 videobuf_dma_contig_free(vq, vb);
597 vb->state = VIDEOBUF_NEEDS_INIT;
598}
599
600static struct videobuf_queue_ops timblogiw_video_qops = {
601 .buf_setup = buffer_setup,
602 .buf_prepare = buffer_prepare,
603 .buf_queue = buffer_queue,
604 .buf_release = buffer_release,
605};
606
607/* Device Operations functions */
608
609static int timblogiw_open(struct file *file)
610{
611 struct video_device *vdev = video_devdata(file);
612 struct timblogiw *lw = video_get_drvdata(vdev);
613 struct timblogiw_fh *fh;
614 v4l2_std_id std;
615 dma_cap_mask_t mask;
616 int err = 0;
617
618 dev_dbg(&vdev->dev, "%s: entry\n", __func__);
619
620 mutex_lock(&lw->lock);
621 if (lw->opened) {
622 err = -EBUSY;
623 goto out;
624 }
625
626 if (TIMBLOGIW_HAS_DECODER(lw) && !lw->sd_enc) {
627 struct i2c_adapter *adapt;
628
629 /* find the video decoder */
630 adapt = i2c_get_adapter(lw->pdata.i2c_adapter);
631 if (!adapt) {
632 dev_err(&vdev->dev, "No I2C bus #%d\n",
633 lw->pdata.i2c_adapter);
634 err = -ENODEV;
635 goto out;
636 }
637
638 /* now find the encoder */
639 lw->sd_enc = v4l2_i2c_new_subdev_board(&lw->v4l2_dev, adapt,
640 lw->pdata.encoder.info, NULL);
641
642 i2c_put_adapter(adapt);
643
644 if (!lw->sd_enc) {
645 dev_err(&vdev->dev, "Failed to get encoder: %s\n",
646 lw->pdata.encoder.module_name);
647 err = -ENODEV;
648 goto out;
649 }
650 }
651
652 fh = kzalloc(sizeof(*fh), GFP_KERNEL);
653 if (!fh) {
654 err = -ENOMEM;
655 goto out;
656 }
657
658 fh->cur_norm = timblogiw_tvnorms;
659 timblogiw_querystd(file, fh, &std);
660 fh->cur_norm = timblogiw_get_norm(std);
661
662 INIT_LIST_HEAD(&fh->capture);
663 spin_lock_init(&fh->queue_lock);
664
665 dma_cap_zero(mask);
666 dma_cap_set(DMA_SLAVE, mask);
667 dma_cap_set(DMA_PRIVATE, mask);
668
669 /* find the DMA channel */
670 fh->chan = dma_request_channel(mask, timblogiw_dma_filter_fn,
671 (void *)(uintptr_t)lw->pdata.dma_channel);
672 if (!fh->chan) {
673 dev_err(&vdev->dev, "Failed to get DMA channel\n");
674 kfree(fh);
675 err = -ENODEV;
676 goto out;
677 }
678
679 file->private_data = fh;
680 videobuf_queue_dma_contig_init(&fh->vb_vidq,
681 &timblogiw_video_qops, lw->dev, &fh->queue_lock,
682 V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_NONE,
683 sizeof(struct timblogiw_buffer), fh, NULL);
684
685 lw->opened = true;
686out:
687 mutex_unlock(&lw->lock);
688
689 return err;
690}
691
692static int timblogiw_close(struct file *file)
693{
694 struct video_device *vdev = video_devdata(file);
695 struct timblogiw *lw = video_get_drvdata(vdev);
696 struct timblogiw_fh *fh = file->private_data;
697
698 dev_dbg(&vdev->dev, "%s: Entry\n", __func__);
699
700 videobuf_stop(&fh->vb_vidq);
701 videobuf_mmap_free(&fh->vb_vidq);
702
703 dma_release_channel(fh->chan);
704
705 kfree(fh);
706
707 mutex_lock(&lw->lock);
708 lw->opened = false;
709 mutex_unlock(&lw->lock);
710 return 0;
711}
712
713static ssize_t timblogiw_read(struct file *file, char __user *data,
714 size_t count, loff_t *ppos)
715{
716 struct video_device *vdev = video_devdata(file);
717 struct timblogiw_fh *fh = file->private_data;
718
719 dev_dbg(&vdev->dev, "%s: entry\n", __func__);
720
721 return videobuf_read_stream(&fh->vb_vidq, data, count, ppos, 0,
722 file->f_flags & O_NONBLOCK);
723}
724
725static unsigned int timblogiw_poll(struct file *file,
726 struct poll_table_struct *wait)
727{
728 struct video_device *vdev = video_devdata(file);
729 struct timblogiw_fh *fh = file->private_data;
730
731 dev_dbg(&vdev->dev, "%s: entry\n", __func__);
732
733 return videobuf_poll_stream(file, &fh->vb_vidq, wait);
734}
735
736static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
737{
738 struct video_device *vdev = video_devdata(file);
739 struct timblogiw_fh *fh = file->private_data;
740
741 dev_dbg(&vdev->dev, "%s: entry\n", __func__);
742
743 return videobuf_mmap_mapper(&fh->vb_vidq, vma);
744}
745
746/* Platform device functions */
747
748static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
749 .vidioc_querycap = timblogiw_querycap,
750 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
751 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
752 .vidioc_try_fmt_vid_cap = timblogiw_try_fmt,
753 .vidioc_s_fmt_vid_cap = timblogiw_s_fmt,
754 .vidioc_g_parm = timblogiw_g_parm,
755 .vidioc_reqbufs = timblogiw_reqbufs,
756 .vidioc_querybuf = timblogiw_querybuf,
757 .vidioc_qbuf = timblogiw_qbuf,
758 .vidioc_dqbuf = timblogiw_dqbuf,
759 .vidioc_g_std = timblogiw_g_std,
760 .vidioc_s_std = timblogiw_s_std,
761 .vidioc_enum_input = timblogiw_enuminput,
762 .vidioc_g_input = timblogiw_g_input,
763 .vidioc_s_input = timblogiw_s_input,
764 .vidioc_streamon = timblogiw_streamon,
765 .vidioc_streamoff = timblogiw_streamoff,
766 .vidioc_querystd = timblogiw_querystd,
767 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
768};
769
770static __devinitconst struct v4l2_file_operations timblogiw_fops = {
771 .owner = THIS_MODULE,
772 .open = timblogiw_open,
773 .release = timblogiw_close,
774 .unlocked_ioctl = video_ioctl2, /* V4L2 ioctl handler */
775 .mmap = timblogiw_mmap,
776 .read = timblogiw_read,
777 .poll = timblogiw_poll,
778};
779
780static __devinitconst struct video_device timblogiw_template = {
781 .name = TIMBLOGIWIN_NAME,
782 .fops = &timblogiw_fops,
783 .ioctl_ops = &timblogiw_ioctl_ops,
784 .release = video_device_release_empty,
785 .minor = -1,
786 .tvnorms = V4L2_STD_PAL | V4L2_STD_NTSC
787};
788
789static int __devinit timblogiw_probe(struct platform_device *pdev)
790{
791 int err;
792 struct timblogiw *lw = NULL;
793 struct timb_video_platform_data *pdata = pdev->dev.platform_data;
794
795 if (!pdata) {
796 dev_err(&pdev->dev, "No platform data\n");
797 err = -EINVAL;
798 goto err;
799 }
800
801 if (!pdata->encoder.module_name)
802 dev_info(&pdev->dev, "Running without decoder\n");
803
804 lw = kzalloc(sizeof(*lw), GFP_KERNEL);
805 if (!lw) {
806 err = -ENOMEM;
807 goto err;
808 }
809
810 if (pdev->dev.parent)
811 lw->dev = pdev->dev.parent;
812 else
813 lw->dev = &pdev->dev;
814
815 memcpy(&lw->pdata, pdata, sizeof(lw->pdata));
816
817 mutex_init(&lw->lock);
818
819 lw->video_dev = timblogiw_template;
820
821 strlcpy(lw->v4l2_dev.name, DRIVER_NAME, sizeof(lw->v4l2_dev.name));
822 err = v4l2_device_register(NULL, &lw->v4l2_dev);
823 if (err)
824 goto err_register;
825
826 lw->video_dev.v4l2_dev = &lw->v4l2_dev;
827
828 platform_set_drvdata(pdev, lw);
829 video_set_drvdata(&lw->video_dev, lw);
830
831 err = video_register_device(&lw->video_dev, VFL_TYPE_GRABBER, 0);
832 if (err) {
833 dev_err(&pdev->dev, "Error reg video: %d\n", err);
834 goto err_request;
835 }
836
837
838 return 0;
839
840err_request:
841 platform_set_drvdata(pdev, NULL);
842 v4l2_device_unregister(&lw->v4l2_dev);
843err_register:
844 kfree(lw);
845err:
846 dev_err(&pdev->dev, "Failed to register: %d\n", err);
847
848 return err;
849}
850
851static int __devexit timblogiw_remove(struct platform_device *pdev)
852{
853 struct timblogiw *lw = platform_get_drvdata(pdev);
854
855 video_unregister_device(&lw->video_dev);
856
857 v4l2_device_unregister(&lw->v4l2_dev);
858
859 kfree(lw);
860
861 platform_set_drvdata(pdev, NULL);
862
863 return 0;
864}
865
866static struct platform_driver timblogiw_platform_driver = {
867 .driver = {
868 .name = DRIVER_NAME,
869 .owner = THIS_MODULE,
870 },
871 .probe = timblogiw_probe,
872 .remove = __devexit_p(timblogiw_remove),
873};
874
875/* Module functions */
876
877static int __init timblogiw_init(void)
878{
879 return platform_driver_register(&timblogiw_platform_driver);
880}
881
882static void __exit timblogiw_exit(void)
883{
884 platform_driver_unregister(&timblogiw_platform_driver);
885}
886
887module_init(timblogiw_init);
888module_exit(timblogiw_exit);
889
890MODULE_DESCRIPTION(TIMBLOGIWIN_NAME);
891MODULE_AUTHOR("Pelagicore AB <info@pelagicore.com>");
892MODULE_LICENSE("GPL v2");
893MODULE_ALIAS("platform:"DRIVER_NAME);
diff --git a/drivers/media/video/tlg2300/Kconfig b/drivers/media/video/tlg2300/Kconfig
index 1686ebfa6951..645d915267e6 100644
--- a/drivers/media/video/tlg2300/Kconfig
+++ b/drivers/media/video/tlg2300/Kconfig
@@ -1,9 +1,9 @@
1config VIDEO_TLG2300 1config VIDEO_TLG2300
2 tristate "Telegent TLG2300 USB video capture support" 2 tristate "Telegent TLG2300 USB video capture support"
3 depends on VIDEO_DEV && I2C && INPUT && SND && DVB_CORE 3 depends on VIDEO_DEV && I2C && SND && DVB_CORE
4 select VIDEO_TUNER 4 select VIDEO_TUNER
5 select VIDEO_TVEEPROM 5 select VIDEO_TVEEPROM
6 depends on VIDEO_IR 6 depends on RC_CORE
7 select VIDEOBUF_VMALLOC 7 select VIDEOBUF_VMALLOC
8 select SND_PCM 8 select SND_PCM
9 select VIDEOBUF_DVB 9 select VIDEOBUF_DVB
diff --git a/drivers/media/video/usbvideo/Kconfig b/drivers/media/video/usbvideo/Kconfig
deleted file mode 100644
index dfa7fc68a657..000000000000
--- a/drivers/media/video/usbvideo/Kconfig
+++ /dev/null
@@ -1,45 +0,0 @@
1config VIDEO_USBVIDEO
2 tristate
3
4config USB_VICAM
5 tristate "USB 3com HomeConnect (aka vicam) support (EXPERIMENTAL)"
6 depends on VIDEO_V4L1 && EXPERIMENTAL
7 select VIDEO_USBVIDEO
8 ---help---
9 Say Y here if you have 3com homeconnect camera (vicam).
10
11 To compile this driver as a module, choose M here: the
12 module will be called vicam.
13
14config USB_IBMCAM
15 tristate "USB IBM (Xirlink) C-it Camera support (DEPRECATED)"
16 depends on VIDEO_V4L1
17 select VIDEO_USBVIDEO
18 ---help---
19 This driver is DEPRECATED please use the gspca xirlink_cit module
20 instead.
21
22 Say Y here if you want to connect a IBM "C-It" camera, also known as
23 "Xirlink PC Camera" to your computer's USB port.
24
25 To compile this driver as a module, choose M here: the
26 module will be called ibmcam.
27
28 This camera has several configuration options which
29 can be specified when you load the module. Read
30 <file:Documentation/video4linux/ibmcam.txt> to learn more.
31
32config USB_KONICAWC
33 tristate "USB Konica Webcam support (DEPRECATED)"
34 depends on VIDEO_V4L1
35 select VIDEO_USBVIDEO
36 ---help---
37 This driver is DEPRECATED (and known to crash) please use the
38 gspca konica module instead.
39
40 Say Y here if you want support for webcams based on a Konica
41 chipset. This is known to work with the Intel YC76 webcam.
42
43 To compile this driver as a module, choose M here: the
44 module will be called konicawc.
45
diff --git a/drivers/media/video/usbvideo/Makefile b/drivers/media/video/usbvideo/Makefile
deleted file mode 100644
index bb52eb8dc2f9..000000000000
--- a/drivers/media/video/usbvideo/Makefile
+++ /dev/null
@@ -1,4 +0,0 @@
1obj-$(CONFIG_VIDEO_USBVIDEO) += usbvideo.o
2obj-$(CONFIG_USB_IBMCAM) += ibmcam.o ultracam.o
3obj-$(CONFIG_USB_KONICAWC) += konicawc.o
4obj-$(CONFIG_USB_VICAM) += vicam.o
diff --git a/drivers/media/video/usbvideo/ibmcam.c b/drivers/media/video/usbvideo/ibmcam.c
deleted file mode 100644
index b08549661781..000000000000
--- a/drivers/media/video/usbvideo/ibmcam.c
+++ /dev/null
@@ -1,3977 +0,0 @@
1/*
2 * USB IBM C-It Video Camera driver
3 *
4 * Supports Xirlink C-It Video Camera, IBM PC Camera,
5 * IBM NetCamera and Veo Stingray.
6 *
7 * This driver is based on earlier work of:
8 *
9 * (C) Copyright 1999 Johannes Erdfelt
10 * (C) Copyright 1999 Randy Dunlap
11 *
12 * 5/24/00 Removed optional (and unnecessary) locking of the driver while
13 * the device remains plugged in. Corrected race conditions in ibmcam_open
14 * and ibmcam_probe() routines using this as a guideline:
15 */
16
17#include <linux/kernel.h>
18#include <linux/module.h>
19#include <linux/init.h>
20
21#include "usbvideo.h"
22
23#define IBMCAM_VENDOR_ID 0x0545
24#define IBMCAM_PRODUCT_ID 0x8080
25#define NETCAM_PRODUCT_ID 0x8002 /* IBM NetCamera, close to model 2 */
26#define VEO_800C_PRODUCT_ID 0x800C /* Veo Stingray, repackaged Model 2 */
27#define VEO_800D_PRODUCT_ID 0x800D /* Veo Stingray, repackaged Model 4 */
28
29#define MAX_IBMCAM 4 /* How many devices we allow to connect */
30#define USES_IBMCAM_PUTPIXEL 0 /* 0=Fast/oops 1=Slow/secure */
31
32/* Header signatures */
33
34/* Model 1 header: 00 FF 00 xx */
35#define HDRSIG_MODEL1_128x96 0x06 /* U Y V Y ... */
36#define HDRSIG_MODEL1_176x144 0x0e /* U Y V Y ... */
37#define HDRSIG_MODEL1_352x288 0x00 /* V Y U Y ... */
38
39#define IBMCAM_MODEL_1 1 /* XVP-501, 3 interfaces, rev. 0.02 */
40#define IBMCAM_MODEL_2 2 /* KSX-X9903, 2 interfaces, rev. 3.0a */
41#define IBMCAM_MODEL_3 3 /* KSX-X9902, 2 interfaces, rev. 3.01 */
42#define IBMCAM_MODEL_4 4 /* IBM NetCamera, 0545/8002/3.0a */
43
44/* Video sizes supported */
45#define VIDEOSIZE_128x96 VIDEOSIZE(128, 96)
46#define VIDEOSIZE_176x144 VIDEOSIZE(176,144)
47#define VIDEOSIZE_352x288 VIDEOSIZE(352,288)
48#define VIDEOSIZE_320x240 VIDEOSIZE(320,240)
49#define VIDEOSIZE_352x240 VIDEOSIZE(352,240)
50#define VIDEOSIZE_640x480 VIDEOSIZE(640,480)
51#define VIDEOSIZE_160x120 VIDEOSIZE(160,120)
52
53/* Video sizes supported */
54enum {
55 SIZE_128x96 = 0,
56 SIZE_160x120,
57 SIZE_176x144,
58 SIZE_320x240,
59 SIZE_352x240,
60 SIZE_352x288,
61 SIZE_640x480,
62 /* Add/remove/rearrange items before this line */
63 SIZE_LastItem
64};
65
66/*
67 * This structure lives in uvd->user field.
68 */
69typedef struct {
70 int initialized; /* Had we already sent init sequence? */
71 int camera_model; /* What type of IBM camera we got? */
72 int has_hdr;
73} ibmcam_t;
74#define IBMCAM_T(uvd) ((ibmcam_t *)((uvd)->user_data))
75
76static struct usbvideo *cams;
77
78static int debug;
79
80static int flags; /* = FLAGS_DISPLAY_HINTS | FLAGS_OVERLAY_STATS; */
81
82static const int min_canvasWidth = 8;
83static const int min_canvasHeight = 4;
84
85static int lighting = 1; /* Medium */
86
87#define SHARPNESS_MIN 0
88#define SHARPNESS_MAX 6
89static int sharpness = 4; /* Low noise, good details */
90
91#define FRAMERATE_MIN 0
92#define FRAMERATE_MAX 6
93static int framerate = -1;
94
95static int size = SIZE_352x288;
96
97/*
98 * Here we define several initialization variables. They may
99 * be used to automatically set color, hue, brightness and
100 * contrast to desired values. This is particularly useful in
101 * case of webcams (which have no controls and no on-screen
102 * output) and also when a client V4L software is used that
103 * does not have some of those controls. In any case it's
104 * good to have startup values as options.
105 *
106 * These values are all in [0..255] range. This simplifies
107 * operation. Note that actual values of V4L variables may
108 * be scaled up (as much as << 8). User can see that only
109 * on overlay output, however, or through a V4L client.
110 */
111static int init_brightness = 128;
112static int init_contrast = 192;
113static int init_color = 128;
114static int init_hue = 128;
115static int hue_correction = 128;
116
117/* Settings for camera model 2 */
118static int init_model2_rg2 = -1;
119static int init_model2_sat = -1;
120static int init_model2_yb = -1;
121
122/* 01.01.08 - Added for RCA video in support -LO */
123/* Settings for camera model 3 */
124static int init_model3_input;
125
126module_param(debug, int, 0);
127MODULE_PARM_DESC(debug, "Debug level: 0-9 (default=0)");
128module_param(flags, int, 0);
129MODULE_PARM_DESC(flags, "Bitfield: 0=VIDIOCSYNC, 1=B/W, 2=show hints, 3=show stats, 4=test pattern, 5=separate frames, 6=clean frames");
130module_param(framerate, int, 0);
131MODULE_PARM_DESC(framerate, "Framerate setting: 0=slowest, 6=fastest (default=2)");
132module_param(lighting, int, 0);
133MODULE_PARM_DESC(lighting, "Photosensitivity: 0=bright, 1=medium (default), 2=low light");
134module_param(sharpness, int, 0);
135MODULE_PARM_DESC(sharpness, "Model1 noise reduction: 0=smooth, 6=sharp (default=4)");
136module_param(size, int, 0);
137MODULE_PARM_DESC(size, "Image size: 0=128x96 1=160x120 2=176x144 3=320x240 4=352x240 5=352x288 6=640x480 (default=5)");
138module_param(init_brightness, int, 0);
139MODULE_PARM_DESC(init_brightness, "Brightness preconfiguration: 0-255 (default=128)");
140module_param(init_contrast, int, 0);
141MODULE_PARM_DESC(init_contrast, "Contrast preconfiguration: 0-255 (default=192)");
142module_param(init_color, int, 0);
143MODULE_PARM_DESC(init_color, "Color preconfiguration: 0-255 (default=128)");
144module_param(init_hue, int, 0);
145MODULE_PARM_DESC(init_hue, "Hue preconfiguration: 0-255 (default=128)");
146module_param(hue_correction, int, 0);
147MODULE_PARM_DESC(hue_correction, "YUV colorspace regulation: 0-255 (default=128)");
148
149module_param(init_model2_rg2, int, 0);
150MODULE_PARM_DESC(init_model2_rg2, "Model2 preconfiguration: 0-255 (default=47)");
151module_param(init_model2_sat, int, 0);
152MODULE_PARM_DESC(init_model2_sat, "Model2 preconfiguration: 0-255 (default=52)");
153module_param(init_model2_yb, int, 0);
154MODULE_PARM_DESC(init_model2_yb, "Model2 preconfiguration: 0-255 (default=160)");
155
156/* 01.01.08 - Added for RCA video in support -LO */
157module_param(init_model3_input, int, 0);
158MODULE_PARM_DESC(init_model3_input, "Model3 input: 0=CCD 1=RCA");
159
160MODULE_AUTHOR ("Dmitri");
161MODULE_DESCRIPTION ("IBM/Xirlink C-it USB Camera Driver for Linux (c) 2000");
162MODULE_LICENSE("GPL");
163
164/* Still mysterious i2c commands */
165static const unsigned short unknown_88 = 0x0088;
166static const unsigned short unknown_89 = 0x0089;
167static const unsigned short bright_3x[3] = { 0x0031, 0x0032, 0x0033 };
168static const unsigned short contrast_14 = 0x0014;
169static const unsigned short light_27 = 0x0027;
170static const unsigned short sharp_13 = 0x0013;
171
172/* i2c commands for Model 2 cameras */
173static const unsigned short mod2_brightness = 0x001a; /* $5b .. $ee; default=$5a */
174static const unsigned short mod2_set_framerate = 0x001c; /* 0 (fast).. $1F (slow) */
175static const unsigned short mod2_color_balance_rg2 = 0x001e; /* 0 (red) .. $7F (green) */
176static const unsigned short mod2_saturation = 0x0020; /* 0 (b/w) - $7F (full color) */
177static const unsigned short mod2_color_balance_yb = 0x0022; /* 0..$7F, $50 is about right */
178static const unsigned short mod2_hue = 0x0024; /* 0..$7F, $70 is about right */
179static const unsigned short mod2_sensitivity = 0x0028; /* 0 (min) .. $1F (max) */
180
181struct struct_initData {
182 unsigned char req;
183 unsigned short value;
184 unsigned short index;
185};
186
187/*
188 * ibmcam_size_to_videosize()
189 *
190 * This procedure converts module option 'size' into the actual
191 * videosize_t that defines the image size in pixels. We need
192 * simplified 'size' because user wants a simple enumerated list
193 * of choices, not an infinite set of possibilities.
194 */
195static videosize_t ibmcam_size_to_videosize(int size)
196{
197 videosize_t vs = VIDEOSIZE_352x288;
198 RESTRICT_TO_RANGE(size, 0, (SIZE_LastItem-1));
199 switch (size) {
200 case SIZE_128x96:
201 vs = VIDEOSIZE_128x96;
202 break;
203 case SIZE_160x120:
204 vs = VIDEOSIZE_160x120;
205 break;
206 case SIZE_176x144:
207 vs = VIDEOSIZE_176x144;
208 break;
209 case SIZE_320x240:
210 vs = VIDEOSIZE_320x240;
211 break;
212 case SIZE_352x240:
213 vs = VIDEOSIZE_352x240;
214 break;
215 case SIZE_352x288:
216 vs = VIDEOSIZE_352x288;
217 break;
218 case SIZE_640x480:
219 vs = VIDEOSIZE_640x480;
220 break;
221 default:
222 err("size=%d. is not valid", size);
223 break;
224 }
225 return vs;
226}
227
228/*
229 * ibmcam_find_header()
230 *
231 * Locate one of supported header markers in the queue.
232 * Once found, remove all preceding bytes AND the marker (4 bytes)
233 * from the data pump queue. Whatever follows must be video lines.
234 *
235 * History:
236 * 1/21/00 Created.
237 */
238static enum ParseState ibmcam_find_header(struct uvd *uvd) /* FIXME: Add frame here */
239{
240 struct usbvideo_frame *frame;
241 ibmcam_t *icam;
242
243 if ((uvd->curframe) < 0 || (uvd->curframe >= USBVIDEO_NUMFRAMES)) {
244 err("ibmcam_find_header: Illegal frame %d.", uvd->curframe);
245 return scan_EndParse;
246 }
247 icam = IBMCAM_T(uvd);
248 assert(icam != NULL);
249 frame = &uvd->frame[uvd->curframe];
250 icam->has_hdr = 0;
251 switch (icam->camera_model) {
252 case IBMCAM_MODEL_1:
253 {
254 const int marker_len = 4;
255 while (RingQueue_GetLength(&uvd->dp) >= marker_len) {
256 if ((RING_QUEUE_PEEK(&uvd->dp, 0) == 0x00) &&
257 (RING_QUEUE_PEEK(&uvd->dp, 1) == 0xFF) &&
258 (RING_QUEUE_PEEK(&uvd->dp, 2) == 0x00))
259 {
260#if 0 /* This code helps to detect new frame markers */
261 dev_info(&uvd->dev->dev,
262 "Header sig: 00 FF 00 %02X\n",
263 RING_QUEUE_PEEK(&uvd->dp, 3));
264#endif
265 frame->header = RING_QUEUE_PEEK(&uvd->dp, 3);
266 if ((frame->header == HDRSIG_MODEL1_128x96) ||
267 (frame->header == HDRSIG_MODEL1_176x144) ||
268 (frame->header == HDRSIG_MODEL1_352x288))
269 {
270#if 0
271 dev_info(&uvd->dev->dev,
272 "Header found.\n");
273#endif
274 RING_QUEUE_DEQUEUE_BYTES(&uvd->dp, marker_len);
275 icam->has_hdr = 1;
276 break;
277 }
278 }
279 /* If we are still here then this doesn't look like a header */
280 RING_QUEUE_DEQUEUE_BYTES(&uvd->dp, 1);
281 }
282 break;
283 }
284 case IBMCAM_MODEL_2:
285case IBMCAM_MODEL_4:
286 {
287 int marker_len = 0;
288 switch (uvd->videosize) {
289 case VIDEOSIZE_176x144:
290 marker_len = 10;
291 break;
292 default:
293 marker_len = 2;
294 break;
295 }
296 while (RingQueue_GetLength(&uvd->dp) >= marker_len) {
297 if ((RING_QUEUE_PEEK(&uvd->dp, 0) == 0x00) &&
298 (RING_QUEUE_PEEK(&uvd->dp, 1) == 0xFF))
299 {
300#if 0
301 dev_info(&uvd->dev->dev, "Header found.\n");
302#endif
303 RING_QUEUE_DEQUEUE_BYTES(&uvd->dp, marker_len);
304 icam->has_hdr = 1;
305 frame->header = HDRSIG_MODEL1_176x144;
306 break;
307 }
308 /* If we are still here then this doesn't look like a header */
309 RING_QUEUE_DEQUEUE_BYTES(&uvd->dp, 1);
310 }
311 break;
312 }
313 case IBMCAM_MODEL_3:
314 { /*
315 * Headers: (one precedes every frame). nc=no compression,
316 * bq=best quality bf=best frame rate.
317 *
318 * 176x144: 00 FF 02 { 0A=nc CA=bq EA=bf }
319 * 320x240: 00 FF 02 { 08=nc 28=bq 68=bf }
320 * 640x480: 00 FF 03 { 08=nc 28=bq 68=bf }
321 *
322 * Bytes '00 FF' seem to indicate header. Other two bytes
323 * encode the frame type. This is a set of bit fields that
324 * encode image size, compression type etc. These fields
325 * do NOT contain frame number because all frames carry
326 * the same header.
327 */
328 const int marker_len = 4;
329 while (RingQueue_GetLength(&uvd->dp) >= marker_len) {
330 if ((RING_QUEUE_PEEK(&uvd->dp, 0) == 0x00) &&
331 (RING_QUEUE_PEEK(&uvd->dp, 1) == 0xFF) &&
332 (RING_QUEUE_PEEK(&uvd->dp, 2) != 0xFF))
333 {
334 /*
335 * Combine 2 bytes of frame type into one
336 * easy to use value
337 */
338 unsigned long byte3, byte4;
339
340 byte3 = RING_QUEUE_PEEK(&uvd->dp, 2);
341 byte4 = RING_QUEUE_PEEK(&uvd->dp, 3);
342 frame->header = (byte3 << 8) | byte4;
343#if 0
344 dev_info(&uvd->dev->dev, "Header found.\n");
345#endif
346 RING_QUEUE_DEQUEUE_BYTES(&uvd->dp, marker_len);
347 icam->has_hdr = 1;
348 break;
349 }
350 /* If we are still here then this doesn't look like a header */
351 RING_QUEUE_DEQUEUE_BYTES(&uvd->dp, 1);
352 }
353 break;
354 }
355 default:
356 break;
357 }
358 if (!icam->has_hdr) {
359 if (uvd->debug > 2)
360 dev_info(&uvd->dev->dev,
361 "Skipping frame, no header\n");
362 return scan_EndParse;
363 }
364
365 /* Header found */
366 icam->has_hdr = 1;
367 uvd->stats.header_count++;
368 frame->scanstate = ScanState_Lines;
369 frame->curline = 0;
370
371 if (flags & FLAGS_FORCE_TESTPATTERN) {
372 usbvideo_TestPattern(uvd, 1, 1);
373 return scan_NextFrame;
374 }
375 return scan_Continue;
376}
377
378/*
379 * ibmcam_parse_lines()
380 *
381 * Parse one line (interlaced) from the buffer, put
382 * decoded RGB value into the current frame buffer
383 * and add the written number of bytes (RGB) to
384 * the *pcopylen.
385 *
386 * History:
387 * 21-Jan-2000 Created.
388 * 12-Oct-2000 Reworked to reflect interlaced nature of the data.
389 */
390static enum ParseState ibmcam_parse_lines(
391 struct uvd *uvd,
392 struct usbvideo_frame *frame,
393 long *pcopylen)
394{
395 unsigned char *f;
396 ibmcam_t *icam;
397 unsigned int len, scanLength, scanHeight, order_uv, order_yc;
398 int v4l_linesize; /* V4L line offset */
399 const int hue_corr = (uvd->vpic.hue - 0x8000) >> 10; /* -32..+31 */
400 const int hue2_corr = (hue_correction - 128) / 4; /* -32..+31 */
401 const int ccm = 128; /* Color correction median - see below */
402 int y, u, v, i, frame_done=0, color_corr;
403 static unsigned char lineBuffer[640*3];
404 unsigned const char *chromaLine, *lumaLine;
405
406 assert(uvd != NULL);
407 assert(frame != NULL);
408 icam = IBMCAM_T(uvd);
409 assert(icam != NULL);
410 color_corr = (uvd->vpic.colour - 0x8000) >> 8; /* -128..+127 = -ccm..+(ccm-1)*/
411 RESTRICT_TO_RANGE(color_corr, -ccm, ccm+1);
412
413 v4l_linesize = VIDEOSIZE_X(frame->request) * V4L_BYTES_PER_PIXEL;
414
415 if (IBMCAM_T(uvd)->camera_model == IBMCAM_MODEL_4) {
416 /* Model 4 frame markers do not carry image size identification */
417 switch (uvd->videosize) {
418 case VIDEOSIZE_128x96:
419 case VIDEOSIZE_160x120:
420 case VIDEOSIZE_176x144:
421 scanLength = VIDEOSIZE_X(uvd->videosize);
422 scanHeight = VIDEOSIZE_Y(uvd->videosize);
423 break;
424 default:
425 err("ibmcam_parse_lines: Wrong mode.");
426 return scan_Out;
427 }
428 order_yc = 1; /* order_yc: true=Yc false=cY ('c'=either U or V) */
429 order_uv = 1; /* Always true in this algorithm */
430 } else {
431 switch (frame->header) {
432 case HDRSIG_MODEL1_128x96:
433 scanLength = 128;
434 scanHeight = 96;
435 order_uv = 1; /* U Y V Y ... */
436 break;
437 case HDRSIG_MODEL1_176x144:
438 scanLength = 176;
439 scanHeight = 144;
440 order_uv = 1; /* U Y V Y ... */
441 break;
442 case HDRSIG_MODEL1_352x288:
443 scanLength = 352;
444 scanHeight = 288;
445 order_uv = 0; /* Y V Y V ... */
446 break;
447 default:
448 err("Unknown header signature 00 FF 00 %02lX", frame->header);
449 return scan_NextFrame;
450 }
451 /* order_yc: true=Yc false=cY ('c'=either U or V) */
452 order_yc = (IBMCAM_T(uvd)->camera_model == IBMCAM_MODEL_2);
453 }
454
455 len = scanLength * 3;
456 assert(len <= sizeof(lineBuffer));
457
458 /*
459 * Lines are organized this way:
460 *
461 * I420:
462 * ~~~~
463 * <scanLength->
464 * ___________________________________
465 * |-----Y-----|---UVUVUV...UVUV-----| \
466 * |-----------+---------------------| \
467 * |<-- 176 -->|<------ 176*2 ------>| Total 72. lines (interlaced)
468 * |... ... | ... | /
469 * |<-- 352 -->|<------ 352*2 ------>| Total 144. lines (interlaced)
470 * |___________|_____________________| /
471 * \ \
472 * lumaLine chromaLine
473 */
474
475 /* Make sure there's enough data for the entire line */
476 if (RingQueue_GetLength(&uvd->dp) < len)
477 return scan_Out;
478
479 /* Suck one line out of the ring queue */
480 RingQueue_Dequeue(&uvd->dp, lineBuffer, len);
481
482 /*
483 * Make sure that our writing into output buffer
484 * will not exceed the buffer. Mind that we may write
485 * not into current output scanline but in several after
486 * it as well (if we enlarge image vertically.)
487 */
488 if ((frame->curline + 2) >= VIDEOSIZE_Y(frame->request))
489 return scan_NextFrame;
490
491 /*
492 * Now we are sure that entire line (representing all 'scanLength'
493 * pixels from the camera) is available in the buffer. We
494 * start copying the line left-aligned to the V4L buffer.
495 * If the camera line is shorter then we should pad the V4L
496 * buffer with something (black) to complete the line.
497 */
498 assert(frame->data != NULL);
499 f = frame->data + (v4l_linesize * frame->curline);
500
501 /*
502 * To obtain chrominance data from the 'chromaLine' use this:
503 * v = chromaLine[0]; // 0-1:[0], 2-3:[4], 4-5:[8]...
504 * u = chromaLine[2]; // 0-1:[2], 2-3:[6], 4-5:[10]...
505 *
506 * Indices must be calculated this way:
507 * v_index = (i >> 1) << 2;
508 * u_index = (i >> 1) << 2 + 2;
509 *
510 * where 'i' is the column number [0..VIDEOSIZE_X(frame->request)-1]
511 */
512 lumaLine = lineBuffer;
513 chromaLine = lineBuffer + scanLength;
514 for (i = 0; i < VIDEOSIZE_X(frame->request); i++)
515 {
516 unsigned char rv, gv, bv; /* RGB components */
517
518 /* Check for various visual debugging hints (colorized pixels) */
519 if ((flags & FLAGS_DISPLAY_HINTS) && (icam->has_hdr)) {
520 /*
521 * This is bad and should not happen. This means that
522 * we somehow overshoot the line and encountered new
523 * frame! Obviously our camera/V4L frame size is out
524 * of whack. This cyan dot will help you to figure
525 * out where exactly the new frame arrived.
526 */
527 if (icam->has_hdr == 1) {
528 bv = 0; /* Yellow marker */
529 gv = 0xFF;
530 rv = 0xFF;
531 } else {
532 bv = 0xFF; /* Cyan marker */
533 gv = 0xFF;
534 rv = 0;
535 }
536 icam->has_hdr = 0;
537 goto make_pixel;
538 }
539
540 /*
541 * Check if we are still in range. We may be out of range if our
542 * V4L canvas is wider or taller than the camera "native" image.
543 * Then we quickly fill the remainder of the line with zeros to
544 * make black color and quit the horizontal scanning loop.
545 */
546 if (((frame->curline + 2) >= scanHeight) || (i >= scanLength)) {
547 const int j = i * V4L_BYTES_PER_PIXEL;
548#if USES_IBMCAM_PUTPIXEL
549 /* Refresh 'f' because we don't use it much with PUTPIXEL */
550 f = frame->data + (v4l_linesize * frame->curline) + j;
551#endif
552 memset(f, 0, v4l_linesize - j);
553 break;
554 }
555
556 y = lumaLine[i];
557 if (flags & FLAGS_MONOCHROME) /* Use monochrome for debugging */
558 rv = gv = bv = y;
559 else {
560 int off_0, off_2;
561
562 off_0 = (i >> 1) << 2;
563 off_2 = off_0 + 2;
564
565 if (order_yc) {
566 off_0++;
567 off_2++;
568 }
569 if (!order_uv) {
570 off_0 += 2;
571 off_2 -= 2;
572 }
573 u = chromaLine[off_0] + hue_corr;
574 v = chromaLine[off_2] + hue2_corr;
575
576 /* Apply color correction */
577 if (color_corr != 0) {
578 /* Magnify up to 2 times, reduce down to zero saturation */
579 u = 128 + ((ccm + color_corr) * (u - 128)) / ccm;
580 v = 128 + ((ccm + color_corr) * (v - 128)) / ccm;
581 }
582 YUV_TO_RGB_BY_THE_BOOK(y, u, v, rv, gv, bv);
583 }
584
585 make_pixel:
586 /*
587 * The purpose of creating the pixel here, in one,
588 * dedicated place is that we may need to make the
589 * pixel wider and taller than it actually is. This
590 * may be used if camera generates small frames for
591 * sake of frame rate (or any other reason.)
592 *
593 * The output data consists of B, G, R bytes
594 * (in this order).
595 */
596#if USES_IBMCAM_PUTPIXEL
597 RGB24_PUTPIXEL(frame, i, frame->curline, rv, gv, bv);
598#else
599 *f++ = bv;
600 *f++ = gv;
601 *f++ = rv;
602#endif
603 /*
604 * Typically we do not decide within a legitimate frame
605 * that we want to end the frame. However debugging code
606 * may detect marker of new frame within the data. Then
607 * this condition activates. The 'data' pointer is already
608 * pointing at the new marker, so we'd better leave it as is.
609 */
610 if (frame_done)
611 break; /* End scanning of lines */
612 }
613 /*
614 * Account for number of bytes that we wrote into output V4L frame.
615 * We do it here, after we are done with the scanline, because we
616 * may fill more than one output scanline if we do vertical
617 * enlargement.
618 */
619 frame->curline += 2;
620 if (pcopylen != NULL)
621 *pcopylen += 2 * v4l_linesize;
622 frame->deinterlace = Deinterlace_FillOddLines;
623
624 if (frame_done || (frame->curline >= VIDEOSIZE_Y(frame->request)))
625 return scan_NextFrame;
626 else
627 return scan_Continue;
628}
629
630/*
631 * ibmcam_model2_320x240_parse_lines()
632 *
633 * This procedure deals with a weird RGB format that is produced by IBM
634 * camera model 2 in modes 320x240 and above; 'x' below is 159 or 175,
635 * depending on horizontal size of the picture:
636 *
637 * <--- 160 or 176 pairs of RA,RB bytes ----->
638 * *-----------------------------------------* \
639 * | RA0 | RB0 | RA1 | RB1 | ... | RAx | RBx | \ This is pair of horizontal lines,
640 * |-----+-----+-----+-----+ ... +-----+-----| *- or one interlaced line, total
641 * | B0 | G0 | B1 | G1 | ... | Bx | Gx | / 120 or 144 such pairs which yield
642 * |=====+=====+=====+=====+ ... +=====+=====| / 240 or 288 lines after deinterlacing.
643 *
644 * Each group of FOUR bytes (RAi, RBi, Bi, Gi) where i=0..frame_width/2-1
645 * defines ONE pixel. Therefore this format yields 176x144 "decoded"
646 * resolution at best. I do not know why camera sends such format - the
647 * previous model (1) just used interlaced I420 and everyone was happy.
648 *
649 * I do not know what is the difference between RAi and RBi bytes. Both
650 * seemingly represent R component, but slightly vary in value (so that
651 * the picture looks a bit colored if one or another is used). I use
652 * them both as R component in attempt to at least partially recover the
653 * lost resolution.
654 */
655static enum ParseState ibmcam_model2_320x240_parse_lines(
656 struct uvd *uvd,
657 struct usbvideo_frame *frame,
658 long *pcopylen)
659{
660 unsigned char *f, *la, *lb;
661 unsigned int len;
662 int v4l_linesize; /* V4L line offset */
663 int i, j, frame_done=0, color_corr;
664 int scanLength, scanHeight;
665 static unsigned char lineBuffer[352*2];
666
667 switch (uvd->videosize) {
668 case VIDEOSIZE_320x240:
669 case VIDEOSIZE_352x240:
670 case VIDEOSIZE_352x288:
671 scanLength = VIDEOSIZE_X(uvd->videosize);
672 scanHeight = VIDEOSIZE_Y(uvd->videosize);
673 break;
674 default:
675 err("ibmcam_model2_320x240_parse_lines: Wrong mode.");
676 return scan_Out;
677 }
678
679 color_corr = (uvd->vpic.colour) >> 8; /* 0..+255 */
680 v4l_linesize = VIDEOSIZE_X(frame->request) * V4L_BYTES_PER_PIXEL;
681
682 len = scanLength * 2; /* See explanation above */
683 assert(len <= sizeof(lineBuffer));
684
685 /* Make sure there's enough data for the entire line */
686 if (RingQueue_GetLength(&uvd->dp) < len)
687 return scan_Out;
688
689 /* Suck one line out of the ring queue */
690 RingQueue_Dequeue(&uvd->dp, lineBuffer, len);
691
692 /*
693 * Make sure that our writing into output buffer
694 * will not exceed the buffer. Mind that we may write
695 * not into current output scanline but in several after
696 * it as well (if we enlarge image vertically.)
697 */
698 if ((frame->curline + 2) >= VIDEOSIZE_Y(frame->request))
699 return scan_NextFrame;
700
701 la = lineBuffer;
702 lb = lineBuffer + scanLength;
703
704 /*
705 * Now we are sure that entire line (representing all
706 * VIDEOSIZE_X(frame->request)
707 * pixels from the camera) is available in the scratch buffer. We
708 * start copying the line left-aligned to the V4L buffer (which
709 * might be larger - not smaller, hopefully). If the camera
710 * line is shorter then we should pad the V4L buffer with something
711 * (black in this case) to complete the line.
712 */
713 f = frame->data + (v4l_linesize * frame->curline);
714
715 /* Fill the 2-line strip */
716 for (i = 0; i < VIDEOSIZE_X(frame->request); i++) {
717 int y, rv, gv, bv; /* RGB components */
718
719 j = i & (~1);
720
721 /* Check for various visual debugging hints (colorized pixels) */
722 if ((flags & FLAGS_DISPLAY_HINTS) && (IBMCAM_T(uvd)->has_hdr)) {
723 if (IBMCAM_T(uvd)->has_hdr == 1) {
724 bv = 0; /* Yellow marker */
725 gv = 0xFF;
726 rv = 0xFF;
727 } else {
728 bv = 0xFF; /* Cyan marker */
729 gv = 0xFF;
730 rv = 0;
731 }
732 IBMCAM_T(uvd)->has_hdr = 0;
733 goto make_pixel;
734 }
735
736 /*
737 * Check if we are still in range. We may be out of range if our
738 * V4L canvas is wider or taller than the camera "native" image.
739 * Then we quickly fill the remainder of the line with zeros to
740 * make black color and quit the horizontal scanning loop.
741 */
742 if (((frame->curline + 2) >= scanHeight) || (i >= scanLength)) {
743 const int offset = i * V4L_BYTES_PER_PIXEL;
744#if USES_IBMCAM_PUTPIXEL
745 /* Refresh 'f' because we don't use it much with PUTPIXEL */
746 f = frame->data + (v4l_linesize * frame->curline) + offset;
747#endif
748 memset(f, 0, v4l_linesize - offset);
749 break;
750 }
751
752 /*
753 * Here I use RA and RB components, one per physical pixel.
754 * This causes fine vertical grid on the picture but may improve
755 * horizontal resolution. If you prefer replicating, use this:
756 * rv = la[j + 0]; ... or ... rv = la[j + 1];
757 * then the pixel will be replicated.
758 */
759 rv = la[i];
760 gv = lb[j + 1];
761 bv = lb[j + 0];
762
763 y = (rv + gv + bv) / 3; /* Brightness (badly calculated) */
764
765 if (flags & FLAGS_MONOCHROME) /* Use monochrome for debugging */
766 rv = gv = bv = y;
767 else if (color_corr != 128) {
768
769 /* Calculate difference between color and brightness */
770 rv -= y;
771 gv -= y;
772 bv -= y;
773
774 /* Scale differences */
775 rv = (rv * color_corr) / 128;
776 gv = (gv * color_corr) / 128;
777 bv = (bv * color_corr) / 128;
778
779 /* Reapply brightness */
780 rv += y;
781 gv += y;
782 bv += y;
783
784 /* Watch for overflows */
785 RESTRICT_TO_RANGE(rv, 0, 255);
786 RESTRICT_TO_RANGE(gv, 0, 255);
787 RESTRICT_TO_RANGE(bv, 0, 255);
788 }
789
790 make_pixel:
791 RGB24_PUTPIXEL(frame, i, frame->curline, rv, gv, bv);
792 }
793 /*
794 * Account for number of bytes that we wrote into output V4L frame.
795 * We do it here, after we are done with the scanline, because we
796 * may fill more than one output scanline if we do vertical
797 * enlargement.
798 */
799 frame->curline += 2;
800 *pcopylen += v4l_linesize * 2;
801 frame->deinterlace = Deinterlace_FillOddLines;
802
803 if (frame_done || (frame->curline >= VIDEOSIZE_Y(frame->request)))
804 return scan_NextFrame;
805 else
806 return scan_Continue;
807}
808
809/*
810 * ibmcam_model3_parse_lines()
811 *
812 * | Even lines | Odd Lines |
813 * -----------------------------------|
814 * |YYY........Y|UYVYUYVY.........UYVY|
815 * |YYY........Y|UYVYUYVY.........UYVY|
816 * |............|.....................|
817 * |YYY........Y|UYVYUYVY.........UYVY|
818 * |------------+---------------------|
819 *
820 * There is one (U, V) chroma pair for every four luma (Y) values. This
821 * function reads a pair of lines at a time and obtains missing chroma values
822 * from adjacent pixels.
823 */
824static enum ParseState ibmcam_model3_parse_lines(
825 struct uvd *uvd,
826 struct usbvideo_frame *frame,
827 long *pcopylen)
828{
829 unsigned char *data;
830 const unsigned char *color;
831 unsigned int len;
832 int v4l_linesize; /* V4L line offset */
833 const int hue_corr = (uvd->vpic.hue - 0x8000) >> 10; /* -32..+31 */
834 const int hue2_corr = (hue_correction - 128) / 4; /* -32..+31 */
835 const int ccm = 128; /* Color correction median - see below */
836 int i, u, v, rw, data_w=0, data_h=0, color_corr;
837 static unsigned char lineBuffer[640*3];
838 int line;
839
840 color_corr = (uvd->vpic.colour - 0x8000) >> 8; /* -128..+127 = -ccm..+(ccm-1)*/
841 RESTRICT_TO_RANGE(color_corr, -ccm, ccm+1);
842
843 v4l_linesize = VIDEOSIZE_X(frame->request) * V4L_BYTES_PER_PIXEL;
844
845 /* The header tells us what sort of data is in this frame */
846 switch (frame->header) {
847 /*
848 * Uncompressed modes (that are easy to decode).
849 */
850 case 0x0308:
851 data_w = 640;
852 data_h = 480;
853 break;
854 case 0x0208:
855 data_w = 320;
856 data_h = 240;
857 break;
858 case 0x020A:
859 data_w = 160;
860 data_h = 120;
861 break;
862 /*
863 * Compressed modes (ViCE - that I don't know how to decode).
864 */
865 case 0x0328: /* 640x480, best quality compression */
866 case 0x0368: /* 640x480, best frame rate compression */
867 case 0x0228: /* 320x240, best quality compression */
868 case 0x0268: /* 320x240, best frame rate compression */
869 case 0x02CA: /* 160x120, best quality compression */
870 case 0x02EA: /* 160x120, best frame rate compression */
871 /* Do nothing with this - not supported */
872 err("Unsupported mode $%04lx", frame->header);
873 return scan_NextFrame;
874 default:
875 /* Catch unknown headers, may help in learning new headers */
876 err("Strange frame->header=$%08lx", frame->header);
877 return scan_NextFrame;
878 }
879
880 /*
881 * Make sure that our writing into output buffer
882 * will not exceed the buffer. Note that we may write
883 * not into current output scanline but in several after
884 * it as well (if we enlarge image vertically.)
885 */
886 if ((frame->curline + 1) >= data_h) {
887 if (uvd->debug >= 3)
888 dev_info(&uvd->dev->dev,
889 "Reached line %d. (frame is done)\n",
890 frame->curline);
891 return scan_NextFrame;
892 }
893
894 /* Make sure that lineBuffer can store two lines of data */
895 len = 3 * data_w; /* <y-data> <uyvy-data> */
896 assert(len <= sizeof(lineBuffer));
897
898 /* Make sure there's enough data for two lines */
899 if (RingQueue_GetLength(&uvd->dp) < len)
900 return scan_Out;
901
902 /* Suck two lines of data out of the ring queue */
903 RingQueue_Dequeue(&uvd->dp, lineBuffer, len);
904
905 data = lineBuffer;
906 color = data + data_w; /* Point to where color planes begin */
907
908 /* Bottom-to-top scanning */
909 rw = (int)VIDEOSIZE_Y(frame->request) - (int)(frame->curline) - 1;
910 RESTRICT_TO_RANGE(rw, 0, VIDEOSIZE_Y(frame->request)-1);
911
912 /* Iterate over two lines. */
913 for (line = 0; line < 2; line++) {
914 for (i = 0; i < VIDEOSIZE_X(frame->request); i++) {
915 int y;
916 int rv, gv, bv; /* RGB components */
917
918 if (i >= data_w) {
919 RGB24_PUTPIXEL(frame, i, rw, 0, 0, 0);
920 continue;
921 }
922
923 /* first line is YYY...Y; second is UYVY...UYVY */
924 y = data[(line == 0) ? i : (i*2 + 1)];
925
926 /* Apply static color correction */
927 u = color[(i/2)*4] + hue_corr;
928 v = color[(i/2)*4 + 2] + hue2_corr;
929
930 /* Apply color correction */
931 if (color_corr != 0) {
932 /* Magnify up to 2 times, reduce down to zero saturation */
933 u = 128 + ((ccm + color_corr) * (u - 128)) / ccm;
934 v = 128 + ((ccm + color_corr) * (v - 128)) / ccm;
935 }
936
937
938 YUV_TO_RGB_BY_THE_BOOK(y, u, v, rv, gv, bv);
939 RGB24_PUTPIXEL(frame, i, rw, rv, gv, bv); /* No deinterlacing */
940 }
941
942 /* Check for the end of requested data */
943 if (rw == 0)
944 break;
945
946 /* Prepare for the second line */
947 rw--;
948 data = lineBuffer + data_w;
949 }
950 frame->deinterlace = Deinterlace_None;
951
952 /*
953 * Account for number of bytes that we wrote into output V4L frame.
954 * We do it here, after we are done with the scanline, because we
955 * may fill more than one output scanline if we do vertical
956 * enlargement.
957 */
958 frame->curline += 2;
959 *pcopylen += 2 * v4l_linesize;
960
961 if (frame->curline >= VIDEOSIZE_Y(frame->request)) {
962 if (uvd->debug >= 3) {
963 dev_info(&uvd->dev->dev,
964 "All requested lines (%ld.) done.\n",
965 VIDEOSIZE_Y(frame->request));
966 }
967 return scan_NextFrame;
968 } else
969 return scan_Continue;
970}
971
972/*
973 * ibmcam_model4_128x96_parse_lines()
974 *
975 * This decoder is for one strange data format that is produced by Model 4
976 * camera only in 128x96 mode. This is RGB format and here is its description.
977 * First of all, this is non-interlaced stream, meaning that all scan lines
978 * are present in the datastream. There are 96 consecutive blocks of data
979 * that describe all 96 lines of the image. Each block is 5*128 bytes long
980 * and carries R, G, B components. The format of the block is shown in the
981 * code below. First 128*2 bytes are interleaved R and G components. Then
982 * we have a gap (junk data) 64 bytes long. Then follow B and something
983 * else, also interleaved (this makes another 128*2 bytes). After that
984 * probably another 64 bytes of junk follow.
985 *
986 * History:
987 * 10-Feb-2001 Created.
988 */
989static enum ParseState ibmcam_model4_128x96_parse_lines(
990 struct uvd *uvd,
991 struct usbvideo_frame *frame,
992 long *pcopylen)
993{
994 const unsigned char *data_rv, *data_gv, *data_bv;
995 unsigned int len;
996 int i, v4l_linesize; /* V4L line offset */
997 const int data_w=128, data_h=96;
998 static unsigned char lineBuffer[128*5];
999
1000 v4l_linesize = VIDEOSIZE_X(frame->request) * V4L_BYTES_PER_PIXEL;
1001
1002 /*
1003 * Make sure that our writing into output buffer
1004 * will not exceed the buffer. Note that we may write
1005 * not into current output scanline but in several after
1006 * it as well (if we enlarge image vertically.)
1007 */
1008 if ((frame->curline + 1) >= data_h) {
1009 if (uvd->debug >= 3)
1010 dev_info(&uvd->dev->dev,
1011 "Reached line %d. (frame is done)\n",
1012 frame->curline);
1013 return scan_NextFrame;
1014 }
1015
1016 /*
1017 * RGRGRG .... RGRG_____________B?B?B? ... B?B?____________
1018 * <---- 128*2 ---><---- 64 ---><--- 128*2 ---><--- 64 --->
1019 */
1020
1021 /* Make sure there's enough data for the entire line */
1022 len = 5 * data_w;
1023 assert(len <= sizeof(lineBuffer));
1024
1025 /* Make sure there's enough data for the entire line */
1026 if (RingQueue_GetLength(&uvd->dp) < len)
1027 return scan_Out;
1028
1029 /* Suck one line out of the ring queue */
1030 RingQueue_Dequeue(&uvd->dp, lineBuffer, len);
1031
1032 data_rv = lineBuffer;
1033 data_gv = lineBuffer + 1;
1034 data_bv = lineBuffer + data_w*2 + data_w/2;
1035 for (i = 0; i < VIDEOSIZE_X(frame->request); i++) {
1036 int rv, gv, bv; /* RGB components */
1037 if (i < data_w) {
1038 const int j = i * 2;
1039 gv = data_rv[j];
1040 rv = data_gv[j];
1041 bv = data_bv[j];
1042 if (flags & FLAGS_MONOCHROME) {
1043 unsigned long y;
1044 y = rv + gv + bv;
1045 y /= 3;
1046 if (y > 0xFF)
1047 y = 0xFF;
1048 rv = gv = bv = (unsigned char) y;
1049 }
1050 } else {
1051 rv = gv = bv = 0;
1052 }
1053 RGB24_PUTPIXEL(frame, i, frame->curline, rv, gv, bv);
1054 }
1055 frame->deinterlace = Deinterlace_None;
1056 frame->curline++;
1057 *pcopylen += v4l_linesize;
1058
1059 if (frame->curline >= VIDEOSIZE_Y(frame->request)) {
1060 if (uvd->debug >= 3) {
1061 dev_info(&uvd->dev->dev,
1062 "All requested lines (%ld.) done.\n",
1063 VIDEOSIZE_Y(frame->request));
1064 }
1065 return scan_NextFrame;
1066 } else
1067 return scan_Continue;
1068}
1069
1070/*
1071 * ibmcam_ProcessIsocData()
1072 *
1073 * Generic routine to parse the ring queue data. It employs either
1074 * ibmcam_find_header() or ibmcam_parse_lines() to do most
1075 * of work.
1076 *
1077 * History:
1078 * 1/21/00 Created.
1079 */
1080static void ibmcam_ProcessIsocData(struct uvd *uvd,
1081 struct usbvideo_frame *frame)
1082{
1083 enum ParseState newstate;
1084 long copylen = 0;
1085 int mod = IBMCAM_T(uvd)->camera_model;
1086
1087 while (1) {
1088 newstate = scan_Out;
1089 if (RingQueue_GetLength(&uvd->dp) > 0) {
1090 if (frame->scanstate == ScanState_Scanning) {
1091 newstate = ibmcam_find_header(uvd);
1092 } else if (frame->scanstate == ScanState_Lines) {
1093 if ((mod == IBMCAM_MODEL_2) &&
1094 ((uvd->videosize == VIDEOSIZE_352x288) ||
1095 (uvd->videosize == VIDEOSIZE_320x240) ||
1096 (uvd->videosize == VIDEOSIZE_352x240)))
1097 {
1098 newstate = ibmcam_model2_320x240_parse_lines(
1099 uvd, frame, &copylen);
1100 } else if (mod == IBMCAM_MODEL_4) {
1101 /*
1102 * Model 4 cameras (IBM NetCamera) use Model 2 decoder (RGB)
1103 * for 320x240 and above; 160x120 and 176x144 uses Model 1
1104 * decoder (YUV), and 128x96 mode uses ???
1105 */
1106 if ((uvd->videosize == VIDEOSIZE_352x288) ||
1107 (uvd->videosize == VIDEOSIZE_320x240) ||
1108 (uvd->videosize == VIDEOSIZE_352x240))
1109 {
1110 newstate = ibmcam_model2_320x240_parse_lines(uvd, frame, &copylen);
1111 } else if (uvd->videosize == VIDEOSIZE_128x96) {
1112 newstate = ibmcam_model4_128x96_parse_lines(uvd, frame, &copylen);
1113 } else {
1114 newstate = ibmcam_parse_lines(uvd, frame, &copylen);
1115 }
1116 } else if (mod == IBMCAM_MODEL_3) {
1117 newstate = ibmcam_model3_parse_lines(uvd, frame, &copylen);
1118 } else {
1119 newstate = ibmcam_parse_lines(uvd, frame, &copylen);
1120 }
1121 }
1122 }
1123 if (newstate == scan_Continue)
1124 continue;
1125 else if ((newstate == scan_NextFrame) || (newstate == scan_Out))
1126 break;
1127 else
1128 return; /* scan_EndParse */
1129 }
1130
1131 if (newstate == scan_NextFrame) {
1132 frame->frameState = FrameState_Done;
1133 uvd->curframe = -1;
1134 uvd->stats.frame_num++;
1135 if ((mod == IBMCAM_MODEL_2) || (mod == IBMCAM_MODEL_4)) {
1136 /* Need software contrast adjustment for those cameras */
1137 frame->flags |= USBVIDEO_FRAME_FLAG_SOFTWARE_CONTRAST;
1138 }
1139 }
1140
1141 /* Update the frame's uncompressed length. */
1142 frame->seqRead_Length += copylen;
1143
1144#if 0
1145 {
1146 static unsigned char j=0;
1147 memset(frame->data, j++, uvd->max_frame_size);
1148 frame->frameState = FrameState_Ready;
1149 }
1150#endif
1151}
1152
1153/*
1154 * ibmcam_veio()
1155 *
1156 * History:
1157 * 1/27/00 Added check for dev == NULL; this happens if camera is unplugged.
1158 */
1159static int ibmcam_veio(
1160 struct uvd *uvd,
1161 unsigned char req,
1162 unsigned short value,
1163 unsigned short index)
1164{
1165 static const char proc[] = "ibmcam_veio";
1166 unsigned char cp[8] /* = { 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef } */;
1167 int i;
1168
1169 if (!CAMERA_IS_OPERATIONAL(uvd))
1170 return 0;
1171
1172 if (req == 1) {
1173 i = usb_control_msg(
1174 uvd->dev,
1175 usb_rcvctrlpipe(uvd->dev, 0),
1176 req,
1177 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT,
1178 value,
1179 index,
1180 cp,
1181 sizeof(cp),
1182 1000);
1183#if 0
1184 dev_info(&uvd->dev->dev,
1185 "USB => %02x%02x%02x%02x%02x%02x%02x%02x "
1186 "(req=$%02x val=$%04x ind=$%04x)\n",
1187 cp[0],cp[1],cp[2],cp[3],cp[4],cp[5],cp[6],cp[7],
1188 req, value, index);
1189#endif
1190 } else {
1191 i = usb_control_msg(
1192 uvd->dev,
1193 usb_sndctrlpipe(uvd->dev, 0),
1194 req,
1195 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT,
1196 value,
1197 index,
1198 NULL,
1199 0,
1200 1000);
1201 }
1202 if (i < 0) {
1203 err("%s: ERROR=%d. Camera stopped; Reconnect or reload driver.",
1204 proc, i);
1205 uvd->last_error = i;
1206 }
1207 return i;
1208}
1209
1210/*
1211 * ibmcam_calculate_fps()
1212 *
1213 * This procedure roughly calculates the real frame rate based
1214 * on FPS code (framerate=NNN option). Actual FPS differs
1215 * slightly depending on lighting conditions, so that actual frame
1216 * rate is determined by the camera. Since I don't know how to ask
1217 * the camera what FPS is now I have to use the FPS code instead.
1218 *
1219 * The FPS code is in range [0..6], 0 is slowest, 6 is fastest.
1220 * Corresponding real FPS should be in range [3..30] frames per second.
1221 * The conversion formula is obvious:
1222 *
1223 * real_fps = 3 + (fps_code * 4.5)
1224 *
1225 * History:
1226 * 1/18/00 Created.
1227 */
1228static int ibmcam_calculate_fps(struct uvd *uvd)
1229{
1230 return 3 + framerate*4 + framerate/2;
1231}
1232
1233/*
1234 * ibmcam_send_FF_04_02()
1235 *
1236 * This procedure sends magic 3-command prefix to the camera.
1237 * The purpose of this prefix is not known.
1238 *
1239 * History:
1240 * 1/2/00 Created.
1241 */
1242static void ibmcam_send_FF_04_02(struct uvd *uvd)
1243{
1244 ibmcam_veio(uvd, 0, 0x00FF, 0x0127);
1245 ibmcam_veio(uvd, 0, 0x0004, 0x0124);
1246 ibmcam_veio(uvd, 0, 0x0002, 0x0124);
1247}
1248
1249static void ibmcam_send_00_04_06(struct uvd *uvd)
1250{
1251 ibmcam_veio(uvd, 0, 0x0000, 0x0127);
1252 ibmcam_veio(uvd, 0, 0x0004, 0x0124);
1253 ibmcam_veio(uvd, 0, 0x0006, 0x0124);
1254}
1255
1256static void ibmcam_send_x_00(struct uvd *uvd, unsigned short x)
1257{
1258 ibmcam_veio(uvd, 0, x, 0x0127);
1259 ibmcam_veio(uvd, 0, 0x0000, 0x0124);
1260}
1261
1262static void ibmcam_send_x_00_05(struct uvd *uvd, unsigned short x)
1263{
1264 ibmcam_send_x_00(uvd, x);
1265 ibmcam_veio(uvd, 0, 0x0005, 0x0124);
1266}
1267
1268static void ibmcam_send_x_00_05_02(struct uvd *uvd, unsigned short x)
1269{
1270 ibmcam_veio(uvd, 0, x, 0x0127);
1271 ibmcam_veio(uvd, 0, 0x0000, 0x0124);
1272 ibmcam_veio(uvd, 0, 0x0005, 0x0124);
1273 ibmcam_veio(uvd, 0, 0x0002, 0x0124);
1274}
1275
1276static void ibmcam_send_x_01_00_05(struct uvd *uvd, unsigned short x)
1277{
1278 ibmcam_veio(uvd, 0, x, 0x0127);
1279 ibmcam_veio(uvd, 0, 0x0001, 0x0124);
1280 ibmcam_veio(uvd, 0, 0x0000, 0x0124);
1281 ibmcam_veio(uvd, 0, 0x0005, 0x0124);
1282}
1283
1284static void ibmcam_send_x_00_05_02_01(struct uvd *uvd, unsigned short x)
1285{
1286 ibmcam_veio(uvd, 0, x, 0x0127);
1287 ibmcam_veio(uvd, 0, 0x0000, 0x0124);
1288 ibmcam_veio(uvd, 0, 0x0005, 0x0124);
1289 ibmcam_veio(uvd, 0, 0x0002, 0x0124);
1290 ibmcam_veio(uvd, 0, 0x0001, 0x0124);
1291}
1292
1293static void ibmcam_send_x_00_05_02_08_01(struct uvd *uvd, unsigned short x)
1294{
1295 ibmcam_veio(uvd, 0, x, 0x0127);
1296 ibmcam_veio(uvd, 0, 0x0000, 0x0124);
1297 ibmcam_veio(uvd, 0, 0x0005, 0x0124);
1298 ibmcam_veio(uvd, 0, 0x0002, 0x0124);
1299 ibmcam_veio(uvd, 0, 0x0008, 0x0124);
1300 ibmcam_veio(uvd, 0, 0x0001, 0x0124);
1301}
1302
1303static void ibmcam_Packet_Format1(struct uvd *uvd, unsigned char fkey, unsigned char val)
1304{
1305 ibmcam_send_x_01_00_05(uvd, unknown_88);
1306 ibmcam_send_x_00_05(uvd, fkey);
1307 ibmcam_send_x_00_05_02_08_01(uvd, val);
1308 ibmcam_send_x_00_05(uvd, unknown_88);
1309 ibmcam_send_x_00_05_02_01(uvd, fkey);
1310 ibmcam_send_x_00_05(uvd, unknown_89);
1311 ibmcam_send_x_00(uvd, fkey);
1312 ibmcam_send_00_04_06(uvd);
1313 ibmcam_veio(uvd, 1, 0x0000, 0x0126);
1314 ibmcam_send_FF_04_02(uvd);
1315}
1316
1317static void ibmcam_PacketFormat2(struct uvd *uvd, unsigned char fkey, unsigned char val)
1318{
1319 ibmcam_send_x_01_00_05 (uvd, unknown_88);
1320 ibmcam_send_x_00_05 (uvd, fkey);
1321 ibmcam_send_x_00_05_02 (uvd, val);
1322}
1323
1324static void ibmcam_model2_Packet2(struct uvd *uvd)
1325{
1326 ibmcam_veio(uvd, 0, 0x00ff, 0x012d);
1327 ibmcam_veio(uvd, 0, 0xfea3, 0x0124);
1328}
1329
1330static void ibmcam_model2_Packet1(struct uvd *uvd, unsigned short v1, unsigned short v2)
1331{
1332 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
1333 ibmcam_veio(uvd, 0, 0x00ff, 0x012e);
1334 ibmcam_veio(uvd, 0, v1, 0x012f);
1335 ibmcam_veio(uvd, 0, 0x00ff, 0x0130);
1336 ibmcam_veio(uvd, 0, 0xc719, 0x0124);
1337 ibmcam_veio(uvd, 0, v2, 0x0127);
1338
1339 ibmcam_model2_Packet2(uvd);
1340}
1341
1342/*
1343 * ibmcam_model3_Packet1()
1344 *
1345 * 00_0078_012d
1346 * 00_0097_012f
1347 * 00_d141_0124
1348 * 00_0096_0127
1349 * 00_fea8_0124
1350*/
1351static void ibmcam_model3_Packet1(struct uvd *uvd, unsigned short v1, unsigned short v2)
1352{
1353 ibmcam_veio(uvd, 0, 0x0078, 0x012d);
1354 ibmcam_veio(uvd, 0, v1, 0x012f);
1355 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
1356 ibmcam_veio(uvd, 0, v2, 0x0127);
1357 ibmcam_veio(uvd, 0, 0xfea8, 0x0124);
1358}
1359
1360static void ibmcam_model4_BrightnessPacket(struct uvd *uvd, int i)
1361{
1362 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
1363 ibmcam_veio(uvd, 0, 0x0026, 0x012f);
1364 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
1365 ibmcam_veio(uvd, 0, i, 0x0127);
1366 ibmcam_veio(uvd, 0, 0x00aa, 0x0130);
1367 ibmcam_veio(uvd, 0, 0x82a8, 0x0124);
1368 ibmcam_veio(uvd, 0, 0x0038, 0x012d);
1369 ibmcam_veio(uvd, 0, 0x0004, 0x012f);
1370 ibmcam_veio(uvd, 0, 0xd145, 0x0124);
1371 ibmcam_veio(uvd, 0, 0xfffa, 0x0124);
1372}
1373
1374/*
1375 * ibmcam_adjust_contrast()
1376 *
1377 * The contrast value changes from 0 (high contrast) to 15 (low contrast).
1378 * This is in reverse to usual order of things (such as TV controls), so
1379 * we reverse it again here.
1380 *
1381 * TODO: we probably don't need to send the setup 5 times...
1382 *
1383 * History:
1384 * 1/2/00 Created.
1385 */
1386static void ibmcam_adjust_contrast(struct uvd *uvd)
1387{
1388 unsigned char a_contrast = uvd->vpic.contrast >> 12;
1389 unsigned char new_contrast;
1390
1391 if (a_contrast >= 16)
1392 a_contrast = 15;
1393 new_contrast = 15 - a_contrast;
1394 if (new_contrast == uvd->vpic_old.contrast)
1395 return;
1396 uvd->vpic_old.contrast = new_contrast;
1397 switch (IBMCAM_T(uvd)->camera_model) {
1398 case IBMCAM_MODEL_1:
1399 {
1400 const int ntries = 5;
1401 int i;
1402 for (i=0; i < ntries; i++) {
1403 ibmcam_Packet_Format1(uvd, contrast_14, new_contrast);
1404 ibmcam_send_FF_04_02(uvd);
1405 }
1406 break;
1407 }
1408 case IBMCAM_MODEL_2:
1409 case IBMCAM_MODEL_4:
1410 /* Models 2, 4 do not have this control; implemented in software. */
1411 break;
1412 case IBMCAM_MODEL_3:
1413 { /* Preset hardware values */
1414 static const struct {
1415 unsigned short cv1;
1416 unsigned short cv2;
1417 unsigned short cv3;
1418 } cv[7] = {
1419 { 0x05, 0x05, 0x0f }, /* Minimum */
1420 { 0x04, 0x04, 0x16 },
1421 { 0x02, 0x03, 0x16 },
1422 { 0x02, 0x08, 0x16 },
1423 { 0x01, 0x0c, 0x16 },
1424 { 0x01, 0x0e, 0x16 },
1425 { 0x01, 0x10, 0x16 } /* Maximum */
1426 };
1427 int i = a_contrast / 2;
1428 RESTRICT_TO_RANGE(i, 0, 6);
1429 ibmcam_veio(uvd, 0, 0x0000, 0x010c); /* Stop */
1430 ibmcam_model3_Packet1(uvd, 0x0067, cv[i].cv1);
1431 ibmcam_model3_Packet1(uvd, 0x005b, cv[i].cv2);
1432 ibmcam_model3_Packet1(uvd, 0x005c, cv[i].cv3);
1433 ibmcam_veio(uvd, 0, 0x0001, 0x0114);
1434 ibmcam_veio(uvd, 0, 0x00c0, 0x010c); /* Go! */
1435 usb_clear_halt(uvd->dev, usb_rcvisocpipe(uvd->dev, uvd->video_endp));
1436 break;
1437 }
1438 default:
1439 break;
1440 }
1441}
1442
1443/*
1444 * ibmcam_change_lighting_conditions()
1445 *
1446 * Camera model 1:
1447 * We have 3 levels of lighting conditions: 0=Bright, 1=Medium, 2=Low.
1448 *
1449 * Camera model 2:
1450 * We have 16 levels of lighting, 0 for bright light and up to 15 for
1451 * low light. But values above 5 or so are useless because camera is
1452 * not really capable to produce anything worth viewing at such light.
1453 * This setting may be altered only in certain camera state.
1454 *
1455 * Low lighting forces slower FPS. Lighting is set as a module parameter.
1456 *
1457 * History:
1458 * 1/5/00 Created.
1459 * 2/20/00 Added support for Model 2 cameras.
1460 */
1461static void ibmcam_change_lighting_conditions(struct uvd *uvd)
1462{
1463 if (debug > 0)
1464 dev_info(&uvd->dev->dev,
1465 "%s: Set lighting to %hu.\n", __func__, lighting);
1466
1467 switch (IBMCAM_T(uvd)->camera_model) {
1468 case IBMCAM_MODEL_1:
1469 {
1470 const int ntries = 5;
1471 int i;
1472 for (i=0; i < ntries; i++)
1473 ibmcam_Packet_Format1(uvd, light_27, (unsigned short) lighting);
1474 break;
1475 }
1476 case IBMCAM_MODEL_2:
1477#if 0
1478 /*
1479 * This command apparently requires camera to be stopped. My
1480 * experiments showed that it -is- possible to alter the lighting
1481 * conditions setting "on the fly", but why bother? This setting does
1482 * not work reliably in all cases, so I decided simply to leave the
1483 * setting where Xirlink put it - in the camera setup phase. This code
1484 * is commented out because it does not work at -any- moment, so its
1485 * presence makes no sense. You may use it for experiments.
1486 */
1487 ibmcam_veio(uvd, 0, 0x0000, 0x010c); /* Stop camera */
1488 ibmcam_model2_Packet1(uvd, mod2_sensitivity, lighting);
1489 ibmcam_veio(uvd, 0, 0x00c0, 0x010c); /* Start camera */
1490#endif
1491 break;
1492 case IBMCAM_MODEL_3:
1493 case IBMCAM_MODEL_4:
1494 default:
1495 break;
1496 }
1497}
1498
1499/*
1500 * ibmcam_set_sharpness()
1501 *
1502 * Cameras model 1 have internal smoothing feature. It is controlled by value in
1503 * range [0..6], where 0 is most smooth and 6 is most sharp (raw image, I guess).
1504 * Recommended value is 4. Cameras model 2 do not have this feature at all.
1505 */
1506static void ibmcam_set_sharpness(struct uvd *uvd)
1507{
1508 switch (IBMCAM_T(uvd)->camera_model) {
1509 case IBMCAM_MODEL_1:
1510 {
1511 static const unsigned short sa[] = { 0x11, 0x13, 0x16, 0x18, 0x1a, 0x8, 0x0a };
1512 unsigned short i, sv;
1513
1514 RESTRICT_TO_RANGE(sharpness, SHARPNESS_MIN, SHARPNESS_MAX);
1515 if (debug > 0)
1516 dev_info(&uvd->dev->dev, "%s: Set sharpness to %hu.\n",
1517 __func__, sharpness);
1518
1519 sv = sa[sharpness - SHARPNESS_MIN];
1520 for (i=0; i < 2; i++) {
1521 ibmcam_send_x_01_00_05 (uvd, unknown_88);
1522 ibmcam_send_x_00_05 (uvd, sharp_13);
1523 ibmcam_send_x_00_05_02 (uvd, sv);
1524 }
1525 break;
1526 }
1527 case IBMCAM_MODEL_2:
1528 case IBMCAM_MODEL_4:
1529 /* Models 2, 4 do not have this control */
1530 break;
1531 case IBMCAM_MODEL_3:
1532 { /*
1533 * "Use a table of magic numbers.
1534 * This setting doesn't really change much.
1535 * But that's how Windows does it."
1536 */
1537 static const struct {
1538 unsigned short sv1;
1539 unsigned short sv2;
1540 unsigned short sv3;
1541 unsigned short sv4;
1542 } sv[7] = {
1543 { 0x00, 0x00, 0x05, 0x14 }, /* Smoothest */
1544 { 0x01, 0x04, 0x05, 0x14 },
1545 { 0x02, 0x04, 0x05, 0x14 },
1546 { 0x03, 0x04, 0x05, 0x14 },
1547 { 0x03, 0x05, 0x05, 0x14 },
1548 { 0x03, 0x06, 0x05, 0x14 },
1549 { 0x03, 0x07, 0x05, 0x14 } /* Sharpest */
1550 };
1551 RESTRICT_TO_RANGE(sharpness, SHARPNESS_MIN, SHARPNESS_MAX);
1552 RESTRICT_TO_RANGE(sharpness, 0, 6);
1553 ibmcam_veio(uvd, 0, 0x0000, 0x010c); /* Stop */
1554 ibmcam_model3_Packet1(uvd, 0x0060, sv[sharpness].sv1);
1555 ibmcam_model3_Packet1(uvd, 0x0061, sv[sharpness].sv2);
1556 ibmcam_model3_Packet1(uvd, 0x0062, sv[sharpness].sv3);
1557 ibmcam_model3_Packet1(uvd, 0x0063, sv[sharpness].sv4);
1558 ibmcam_veio(uvd, 0, 0x0001, 0x0114);
1559 ibmcam_veio(uvd, 0, 0x00c0, 0x010c); /* Go! */
1560 usb_clear_halt(uvd->dev, usb_rcvisocpipe(uvd->dev, uvd->video_endp));
1561 ibmcam_veio(uvd, 0, 0x0001, 0x0113);
1562 break;
1563 }
1564 default:
1565 break;
1566 }
1567}
1568
1569/*
1570 * ibmcam_set_brightness()
1571 *
1572 * This procedure changes brightness of the picture.
1573 */
1574static void ibmcam_set_brightness(struct uvd *uvd)
1575{
1576 static const unsigned short n = 1;
1577
1578 if (debug > 0)
1579 dev_info(&uvd->dev->dev, "%s: Set brightness to %hu.\n",
1580 __func__, uvd->vpic.brightness);
1581
1582 switch (IBMCAM_T(uvd)->camera_model) {
1583 case IBMCAM_MODEL_1:
1584 {
1585 unsigned short i, j, bv[3];
1586 bv[0] = bv[1] = bv[2] = uvd->vpic.brightness >> 10;
1587 if (bv[0] == (uvd->vpic_old.brightness >> 10))
1588 return;
1589 uvd->vpic_old.brightness = bv[0];
1590 for (j=0; j < 3; j++)
1591 for (i=0; i < n; i++)
1592 ibmcam_Packet_Format1(uvd, bright_3x[j], bv[j]);
1593 break;
1594 }
1595 case IBMCAM_MODEL_2:
1596 {
1597 unsigned short i, j;
1598 i = uvd->vpic.brightness >> 12; /* 0 .. 15 */
1599 j = 0x60 + i * ((0xee - 0x60) / 16); /* 0x60 .. 0xee or so */
1600 if (uvd->vpic_old.brightness == j)
1601 break;
1602 uvd->vpic_old.brightness = j;
1603 ibmcam_model2_Packet1(uvd, mod2_brightness, j);
1604 break;
1605 }
1606 case IBMCAM_MODEL_3:
1607 {
1608 /* Model 3: Brightness range 'i' in [0x0C..0x3F] */
1609 unsigned short i =
1610 0x0C + (uvd->vpic.brightness / (0xFFFF / (0x3F - 0x0C + 1)));
1611 RESTRICT_TO_RANGE(i, 0x0C, 0x3F);
1612 if (uvd->vpic_old.brightness == i)
1613 break;
1614 uvd->vpic_old.brightness = i;
1615 ibmcam_veio(uvd, 0, 0x0000, 0x010c); /* Stop */
1616 ibmcam_model3_Packet1(uvd, 0x0036, i);
1617 ibmcam_veio(uvd, 0, 0x0001, 0x0114);
1618 ibmcam_veio(uvd, 0, 0x00c0, 0x010c); /* Go! */
1619 usb_clear_halt(uvd->dev, usb_rcvisocpipe(uvd->dev, uvd->video_endp));
1620 ibmcam_veio(uvd, 0, 0x0001, 0x0113);
1621 break;
1622 }
1623 case IBMCAM_MODEL_4:
1624 {
1625 /* Model 4: Brightness range 'i' in [0x04..0xb4] */
1626 unsigned short i = 0x04 + (uvd->vpic.brightness / (0xFFFF / (0xb4 - 0x04 + 1)));
1627 RESTRICT_TO_RANGE(i, 0x04, 0xb4);
1628 if (uvd->vpic_old.brightness == i)
1629 break;
1630 uvd->vpic_old.brightness = i;
1631 ibmcam_model4_BrightnessPacket(uvd, i);
1632 break;
1633 }
1634 default:
1635 break;
1636 }
1637}
1638
1639static void ibmcam_set_hue(struct uvd *uvd)
1640{
1641 switch (IBMCAM_T(uvd)->camera_model) {
1642 case IBMCAM_MODEL_2:
1643 {
1644 unsigned short hue = uvd->vpic.hue >> 9; /* 0 .. 7F */
1645 if (uvd->vpic_old.hue == hue)
1646 return;
1647 uvd->vpic_old.hue = hue;
1648 ibmcam_model2_Packet1(uvd, mod2_hue, hue);
1649 /* ibmcam_model2_Packet1(uvd, mod2_saturation, sat); */
1650 break;
1651 }
1652 case IBMCAM_MODEL_3:
1653 {
1654#if 0 /* This seems not to work. No problem, will fix programmatically */
1655 unsigned short hue = 0x05 + (uvd->vpic.hue / (0xFFFF / (0x37 - 0x05 + 1)));
1656 RESTRICT_TO_RANGE(hue, 0x05, 0x37);
1657 if (uvd->vpic_old.hue == hue)
1658 return;
1659 uvd->vpic_old.hue = hue;
1660 ibmcam_veio(uvd, 0, 0x0000, 0x010c); /* Stop */
1661 ibmcam_model3_Packet1(uvd, 0x007e, hue);
1662 ibmcam_veio(uvd, 0, 0x0001, 0x0114);
1663 ibmcam_veio(uvd, 0, 0x00c0, 0x010c); /* Go! */
1664 usb_clear_halt(uvd->dev, usb_rcvisocpipe(uvd->dev, uvd->video_endp));
1665 ibmcam_veio(uvd, 0, 0x0001, 0x0113);
1666#endif
1667 break;
1668 }
1669 case IBMCAM_MODEL_4:
1670 {
1671 unsigned short r_gain, g_gain, b_gain, hue;
1672
1673 /*
1674 * I am not sure r/g/b_gain variables exactly control gain
1675 * of those channels. Most likely they subtly change some
1676 * very internal image processing settings in the camera.
1677 * In any case, here is what they do, and feel free to tweak:
1678 *
1679 * r_gain: seriously affects red gain
1680 * g_gain: seriously affects green gain
1681 * b_gain: seriously affects blue gain
1682 * hue: changes average color from violet (0) to red (0xFF)
1683 *
1684 * These settings are preset for a decent white balance in
1685 * 320x240, 352x288 modes. Low-res modes exhibit higher contrast
1686 * and therefore may need different values here.
1687 */
1688 hue = 20 + (uvd->vpic.hue >> 9);
1689 switch (uvd->videosize) {
1690 case VIDEOSIZE_128x96:
1691 r_gain = 90;
1692 g_gain = 166;
1693 b_gain = 175;
1694 break;
1695 case VIDEOSIZE_160x120:
1696 r_gain = 70;
1697 g_gain = 166;
1698 b_gain = 185;
1699 break;
1700 case VIDEOSIZE_176x144:
1701 r_gain = 160;
1702 g_gain = 175;
1703 b_gain = 185;
1704 break;
1705 default:
1706 r_gain = 120;
1707 g_gain = 166;
1708 b_gain = 175;
1709 break;
1710 }
1711 RESTRICT_TO_RANGE(hue, 1, 0x7f);
1712
1713 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
1714 ibmcam_veio(uvd, 0, 0x001e, 0x012f);
1715 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
1716 ibmcam_veio(uvd, 0, g_gain, 0x0127); /* Green gain */
1717 ibmcam_veio(uvd, 0, r_gain, 0x012e); /* Red gain */
1718 ibmcam_veio(uvd, 0, b_gain, 0x0130); /* Blue gain */
1719 ibmcam_veio(uvd, 0, 0x8a28, 0x0124);
1720 ibmcam_veio(uvd, 0, hue, 0x012d); /* Hue */
1721 ibmcam_veio(uvd, 0, 0xf545, 0x0124);
1722 break;
1723 }
1724 default:
1725 break;
1726 }
1727}
1728
1729/*
1730 * ibmcam_adjust_picture()
1731 *
1732 * This procedure gets called from V4L interface to update picture settings.
1733 * Here we change brightness and contrast.
1734 */
1735static void ibmcam_adjust_picture(struct uvd *uvd)
1736{
1737 ibmcam_adjust_contrast(uvd);
1738 ibmcam_set_brightness(uvd);
1739 ibmcam_set_hue(uvd);
1740}
1741
1742static int ibmcam_model1_setup(struct uvd *uvd)
1743{
1744 const int ntries = 5;
1745 int i;
1746
1747 ibmcam_veio(uvd, 1, 0x00, 0x0128);
1748 ibmcam_veio(uvd, 1, 0x00, 0x0100);
1749 ibmcam_veio(uvd, 0, 0x01, 0x0100); /* LED On */
1750 ibmcam_veio(uvd, 1, 0x00, 0x0100);
1751 ibmcam_veio(uvd, 0, 0x81, 0x0100); /* LED Off */
1752 ibmcam_veio(uvd, 1, 0x00, 0x0100);
1753 ibmcam_veio(uvd, 0, 0x01, 0x0100); /* LED On */
1754 ibmcam_veio(uvd, 0, 0x01, 0x0108);
1755
1756 ibmcam_veio(uvd, 0, 0x03, 0x0112);
1757 ibmcam_veio(uvd, 1, 0x00, 0x0115);
1758 ibmcam_veio(uvd, 0, 0x06, 0x0115);
1759 ibmcam_veio(uvd, 1, 0x00, 0x0116);
1760 ibmcam_veio(uvd, 0, 0x44, 0x0116);
1761 ibmcam_veio(uvd, 1, 0x00, 0x0116);
1762 ibmcam_veio(uvd, 0, 0x40, 0x0116);
1763 ibmcam_veio(uvd, 1, 0x00, 0x0115);
1764 ibmcam_veio(uvd, 0, 0x0e, 0x0115);
1765 ibmcam_veio(uvd, 0, 0x19, 0x012c);
1766
1767 ibmcam_Packet_Format1(uvd, 0x00, 0x1e);
1768 ibmcam_Packet_Format1(uvd, 0x39, 0x0d);
1769 ibmcam_Packet_Format1(uvd, 0x39, 0x09);
1770 ibmcam_Packet_Format1(uvd, 0x3b, 0x00);
1771 ibmcam_Packet_Format1(uvd, 0x28, 0x22);
1772 ibmcam_Packet_Format1(uvd, light_27, 0);
1773 ibmcam_Packet_Format1(uvd, 0x2b, 0x1f);
1774 ibmcam_Packet_Format1(uvd, 0x39, 0x08);
1775
1776 for (i=0; i < ntries; i++)
1777 ibmcam_Packet_Format1(uvd, 0x2c, 0x00);
1778
1779 for (i=0; i < ntries; i++)
1780 ibmcam_Packet_Format1(uvd, 0x30, 0x14);
1781
1782 ibmcam_PacketFormat2(uvd, 0x39, 0x02);
1783 ibmcam_PacketFormat2(uvd, 0x01, 0xe1);
1784 ibmcam_PacketFormat2(uvd, 0x02, 0xcd);
1785 ibmcam_PacketFormat2(uvd, 0x03, 0xcd);
1786 ibmcam_PacketFormat2(uvd, 0x04, 0xfa);
1787 ibmcam_PacketFormat2(uvd, 0x3f, 0xff);
1788 ibmcam_PacketFormat2(uvd, 0x39, 0x00);
1789
1790 ibmcam_PacketFormat2(uvd, 0x39, 0x02);
1791 ibmcam_PacketFormat2(uvd, 0x0a, 0x37);
1792 ibmcam_PacketFormat2(uvd, 0x0b, 0xb8);
1793 ibmcam_PacketFormat2(uvd, 0x0c, 0xf3);
1794 ibmcam_PacketFormat2(uvd, 0x0d, 0xe3);
1795 ibmcam_PacketFormat2(uvd, 0x0e, 0x0d);
1796 ibmcam_PacketFormat2(uvd, 0x0f, 0xf2);
1797 ibmcam_PacketFormat2(uvd, 0x10, 0xd5);
1798 ibmcam_PacketFormat2(uvd, 0x11, 0xba);
1799 ibmcam_PacketFormat2(uvd, 0x12, 0x53);
1800 ibmcam_PacketFormat2(uvd, 0x3f, 0xff);
1801 ibmcam_PacketFormat2(uvd, 0x39, 0x00);
1802
1803 ibmcam_PacketFormat2(uvd, 0x39, 0x02);
1804 ibmcam_PacketFormat2(uvd, 0x16, 0x00);
1805 ibmcam_PacketFormat2(uvd, 0x17, 0x28);
1806 ibmcam_PacketFormat2(uvd, 0x18, 0x7d);
1807 ibmcam_PacketFormat2(uvd, 0x19, 0xbe);
1808 ibmcam_PacketFormat2(uvd, 0x3f, 0xff);
1809 ibmcam_PacketFormat2(uvd, 0x39, 0x00);
1810
1811 for (i=0; i < ntries; i++)
1812 ibmcam_Packet_Format1(uvd, 0x00, 0x18);
1813 for (i=0; i < ntries; i++)
1814 ibmcam_Packet_Format1(uvd, 0x13, 0x18);
1815 for (i=0; i < ntries; i++)
1816 ibmcam_Packet_Format1(uvd, 0x14, 0x06);
1817
1818 /* This is default brightness */
1819 for (i=0; i < ntries; i++)
1820 ibmcam_Packet_Format1(uvd, 0x31, 0x37);
1821 for (i=0; i < ntries; i++)
1822 ibmcam_Packet_Format1(uvd, 0x32, 0x46);
1823 for (i=0; i < ntries; i++)
1824 ibmcam_Packet_Format1(uvd, 0x33, 0x55);
1825
1826 ibmcam_Packet_Format1(uvd, 0x2e, 0x04);
1827 for (i=0; i < ntries; i++)
1828 ibmcam_Packet_Format1(uvd, 0x2d, 0x04);
1829 for (i=0; i < ntries; i++)
1830 ibmcam_Packet_Format1(uvd, 0x29, 0x80);
1831 ibmcam_Packet_Format1(uvd, 0x2c, 0x01);
1832 ibmcam_Packet_Format1(uvd, 0x30, 0x17);
1833 ibmcam_Packet_Format1(uvd, 0x39, 0x08);
1834 for (i=0; i < ntries; i++)
1835 ibmcam_Packet_Format1(uvd, 0x34, 0x00);
1836
1837 ibmcam_veio(uvd, 0, 0x00, 0x0101);
1838 ibmcam_veio(uvd, 0, 0x00, 0x010a);
1839
1840 switch (uvd->videosize) {
1841 case VIDEOSIZE_128x96:
1842 ibmcam_veio(uvd, 0, 0x80, 0x0103);
1843 ibmcam_veio(uvd, 0, 0x60, 0x0105);
1844 ibmcam_veio(uvd, 0, 0x0c, 0x010b);
1845 ibmcam_veio(uvd, 0, 0x04, 0x011b); /* Same everywhere */
1846 ibmcam_veio(uvd, 0, 0x0b, 0x011d);
1847 ibmcam_veio(uvd, 0, 0x00, 0x011e); /* Same everywhere */
1848 ibmcam_veio(uvd, 0, 0x00, 0x0129);
1849 break;
1850 case VIDEOSIZE_176x144:
1851 ibmcam_veio(uvd, 0, 0xb0, 0x0103);
1852 ibmcam_veio(uvd, 0, 0x8f, 0x0105);
1853 ibmcam_veio(uvd, 0, 0x06, 0x010b);
1854 ibmcam_veio(uvd, 0, 0x04, 0x011b); /* Same everywhere */
1855 ibmcam_veio(uvd, 0, 0x0d, 0x011d);
1856 ibmcam_veio(uvd, 0, 0x00, 0x011e); /* Same everywhere */
1857 ibmcam_veio(uvd, 0, 0x03, 0x0129);
1858 break;
1859 case VIDEOSIZE_352x288:
1860 ibmcam_veio(uvd, 0, 0xb0, 0x0103);
1861 ibmcam_veio(uvd, 0, 0x90, 0x0105);
1862 ibmcam_veio(uvd, 0, 0x02, 0x010b);
1863 ibmcam_veio(uvd, 0, 0x04, 0x011b); /* Same everywhere */
1864 ibmcam_veio(uvd, 0, 0x05, 0x011d);
1865 ibmcam_veio(uvd, 0, 0x00, 0x011e); /* Same everywhere */
1866 ibmcam_veio(uvd, 0, 0x00, 0x0129);
1867 break;
1868 }
1869
1870 ibmcam_veio(uvd, 0, 0xff, 0x012b);
1871
1872 /* This is another brightness - don't know why */
1873 for (i=0; i < ntries; i++)
1874 ibmcam_Packet_Format1(uvd, 0x31, 0xc3);
1875 for (i=0; i < ntries; i++)
1876 ibmcam_Packet_Format1(uvd, 0x32, 0xd2);
1877 for (i=0; i < ntries; i++)
1878 ibmcam_Packet_Format1(uvd, 0x33, 0xe1);
1879
1880 /* Default contrast */
1881 for (i=0; i < ntries; i++)
1882 ibmcam_Packet_Format1(uvd, contrast_14, 0x0a);
1883
1884 /* Default sharpness */
1885 for (i=0; i < 2; i++)
1886 ibmcam_PacketFormat2(uvd, sharp_13, 0x1a); /* Level 4 FIXME */
1887
1888 /* Default lighting conditions */
1889 ibmcam_Packet_Format1(uvd, light_27, lighting); /* 0=Bright 2=Low */
1890
1891 /* Assorted init */
1892
1893 switch (uvd->videosize) {
1894 case VIDEOSIZE_128x96:
1895 ibmcam_Packet_Format1(uvd, 0x2b, 0x1e);
1896 ibmcam_veio(uvd, 0, 0xc9, 0x0119); /* Same everywhere */
1897 ibmcam_veio(uvd, 0, 0x80, 0x0109); /* Same everywhere */
1898 ibmcam_veio(uvd, 0, 0x36, 0x0102);
1899 ibmcam_veio(uvd, 0, 0x1a, 0x0104);
1900 ibmcam_veio(uvd, 0, 0x04, 0x011a); /* Same everywhere */
1901 ibmcam_veio(uvd, 0, 0x2b, 0x011c);
1902 ibmcam_veio(uvd, 0, 0x23, 0x012a); /* Same everywhere */
1903#if 0
1904 ibmcam_veio(uvd, 0, 0x00, 0x0106);
1905 ibmcam_veio(uvd, 0, 0x38, 0x0107);
1906#else
1907 ibmcam_veio(uvd, 0, 0x02, 0x0106);
1908 ibmcam_veio(uvd, 0, 0x2a, 0x0107);
1909#endif
1910 break;
1911 case VIDEOSIZE_176x144:
1912 ibmcam_Packet_Format1(uvd, 0x2b, 0x1e);
1913 ibmcam_veio(uvd, 0, 0xc9, 0x0119); /* Same everywhere */
1914 ibmcam_veio(uvd, 0, 0x80, 0x0109); /* Same everywhere */
1915 ibmcam_veio(uvd, 0, 0x04, 0x0102);
1916 ibmcam_veio(uvd, 0, 0x02, 0x0104);
1917 ibmcam_veio(uvd, 0, 0x04, 0x011a); /* Same everywhere */
1918 ibmcam_veio(uvd, 0, 0x2b, 0x011c);
1919 ibmcam_veio(uvd, 0, 0x23, 0x012a); /* Same everywhere */
1920 ibmcam_veio(uvd, 0, 0x01, 0x0106);
1921 ibmcam_veio(uvd, 0, 0xca, 0x0107);
1922 break;
1923 case VIDEOSIZE_352x288:
1924 ibmcam_Packet_Format1(uvd, 0x2b, 0x1f);
1925 ibmcam_veio(uvd, 0, 0xc9, 0x0119); /* Same everywhere */
1926 ibmcam_veio(uvd, 0, 0x80, 0x0109); /* Same everywhere */
1927 ibmcam_veio(uvd, 0, 0x08, 0x0102);
1928 ibmcam_veio(uvd, 0, 0x01, 0x0104);
1929 ibmcam_veio(uvd, 0, 0x04, 0x011a); /* Same everywhere */
1930 ibmcam_veio(uvd, 0, 0x2f, 0x011c);
1931 ibmcam_veio(uvd, 0, 0x23, 0x012a); /* Same everywhere */
1932 ibmcam_veio(uvd, 0, 0x03, 0x0106);
1933 ibmcam_veio(uvd, 0, 0xf6, 0x0107);
1934 break;
1935 }
1936 return (CAMERA_IS_OPERATIONAL(uvd) ? 0 : -EFAULT);
1937}
1938
1939static int ibmcam_model2_setup(struct uvd *uvd)
1940{
1941 ibmcam_veio(uvd, 0, 0x0000, 0x0100); /* LED on */
1942 ibmcam_veio(uvd, 1, 0x0000, 0x0116);
1943 ibmcam_veio(uvd, 0, 0x0060, 0x0116);
1944 ibmcam_veio(uvd, 0, 0x0002, 0x0112);
1945 ibmcam_veio(uvd, 0, 0x00bc, 0x012c);
1946 ibmcam_veio(uvd, 0, 0x0008, 0x012b);
1947 ibmcam_veio(uvd, 0, 0x0000, 0x0108);
1948 ibmcam_veio(uvd, 0, 0x0001, 0x0133);
1949 ibmcam_veio(uvd, 0, 0x0001, 0x0102);
1950 switch (uvd->videosize) {
1951 case VIDEOSIZE_176x144:
1952 ibmcam_veio(uvd, 0, 0x002c, 0x0103); /* All except 320x240 */
1953 ibmcam_veio(uvd, 0, 0x0000, 0x0104); /* Same */
1954 ibmcam_veio(uvd, 0, 0x0024, 0x0105); /* 176x144, 352x288 */
1955 ibmcam_veio(uvd, 0, 0x00b9, 0x010a); /* Unique to this mode */
1956 ibmcam_veio(uvd, 0, 0x0038, 0x0119); /* Unique to this mode */
1957 ibmcam_veio(uvd, 0, 0x0003, 0x0106); /* Same */
1958 ibmcam_veio(uvd, 0, 0x0090, 0x0107); /* Unique to every mode*/
1959 break;
1960 case VIDEOSIZE_320x240:
1961 ibmcam_veio(uvd, 0, 0x0028, 0x0103); /* Unique to this mode */
1962 ibmcam_veio(uvd, 0, 0x0000, 0x0104); /* Same */
1963 ibmcam_veio(uvd, 0, 0x001e, 0x0105); /* 320x240, 352x240 */
1964 ibmcam_veio(uvd, 0, 0x0039, 0x010a); /* All except 176x144 */
1965 ibmcam_veio(uvd, 0, 0x0070, 0x0119); /* All except 176x144 */
1966 ibmcam_veio(uvd, 0, 0x0003, 0x0106); /* Same */
1967 ibmcam_veio(uvd, 0, 0x0098, 0x0107); /* Unique to every mode*/
1968 break;
1969 case VIDEOSIZE_352x240:
1970 ibmcam_veio(uvd, 0, 0x002c, 0x0103); /* All except 320x240 */
1971 ibmcam_veio(uvd, 0, 0x0000, 0x0104); /* Same */
1972 ibmcam_veio(uvd, 0, 0x001e, 0x0105); /* 320x240, 352x240 */
1973 ibmcam_veio(uvd, 0, 0x0039, 0x010a); /* All except 176x144 */
1974 ibmcam_veio(uvd, 0, 0x0070, 0x0119); /* All except 176x144 */
1975 ibmcam_veio(uvd, 0, 0x0003, 0x0106); /* Same */
1976 ibmcam_veio(uvd, 0, 0x00da, 0x0107); /* Unique to every mode*/
1977 break;
1978 case VIDEOSIZE_352x288:
1979 ibmcam_veio(uvd, 0, 0x002c, 0x0103); /* All except 320x240 */
1980 ibmcam_veio(uvd, 0, 0x0000, 0x0104); /* Same */
1981 ibmcam_veio(uvd, 0, 0x0024, 0x0105); /* 176x144, 352x288 */
1982 ibmcam_veio(uvd, 0, 0x0039, 0x010a); /* All except 176x144 */
1983 ibmcam_veio(uvd, 0, 0x0070, 0x0119); /* All except 176x144 */
1984 ibmcam_veio(uvd, 0, 0x0003, 0x0106); /* Same */
1985 ibmcam_veio(uvd, 0, 0x00fe, 0x0107); /* Unique to every mode*/
1986 break;
1987 }
1988 return (CAMERA_IS_OPERATIONAL(uvd) ? 0 : -EFAULT);
1989}
1990
1991/*
1992 * ibmcam_model1_setup_after_video_if()
1993 *
1994 * This code adds finishing touches to the video data interface.
1995 * Here we configure the frame rate and turn on the LED.
1996 */
1997static void ibmcam_model1_setup_after_video_if(struct uvd *uvd)
1998{
1999 unsigned short internal_frame_rate;
2000
2001 RESTRICT_TO_RANGE(framerate, FRAMERATE_MIN, FRAMERATE_MAX);
2002 internal_frame_rate = FRAMERATE_MAX - framerate; /* 0=Fast 6=Slow */
2003 ibmcam_veio(uvd, 0, 0x01, 0x0100); /* LED On */
2004 ibmcam_veio(uvd, 0, internal_frame_rate, 0x0111);
2005 ibmcam_veio(uvd, 0, 0x01, 0x0114);
2006 ibmcam_veio(uvd, 0, 0xc0, 0x010c);
2007}
2008
2009static void ibmcam_model2_setup_after_video_if(struct uvd *uvd)
2010{
2011 unsigned short setup_model2_rg2, setup_model2_sat, setup_model2_yb;
2012
2013 ibmcam_veio(uvd, 0, 0x0000, 0x0100); /* LED on */
2014
2015 switch (uvd->videosize) {
2016 case VIDEOSIZE_176x144:
2017 ibmcam_veio(uvd, 0, 0x0050, 0x0111);
2018 ibmcam_veio(uvd, 0, 0x00d0, 0x0111);
2019 break;
2020 case VIDEOSIZE_320x240:
2021 case VIDEOSIZE_352x240:
2022 case VIDEOSIZE_352x288:
2023 ibmcam_veio(uvd, 0, 0x0040, 0x0111);
2024 ibmcam_veio(uvd, 0, 0x00c0, 0x0111);
2025 break;
2026 }
2027 ibmcam_veio(uvd, 0, 0x009b, 0x010f);
2028 ibmcam_veio(uvd, 0, 0x00bb, 0x010f);
2029
2030 /*
2031 * Hardware settings, may affect CMOS sensor; not user controls!
2032 * -------------------------------------------------------------
2033 * 0x0004: no effect
2034 * 0x0006: hardware effect
2035 * 0x0008: no effect
2036 * 0x000a: stops video stream, probably important h/w setting
2037 * 0x000c: changes color in hardware manner (not user setting)
2038 * 0x0012: changes number of colors (does not affect speed)
2039 * 0x002a: no effect
2040 * 0x002c: hardware setting (related to scan lines)
2041 * 0x002e: stops video stream, probably important h/w setting
2042 */
2043 ibmcam_model2_Packet1(uvd, 0x000a, 0x005c);
2044 ibmcam_model2_Packet1(uvd, 0x0004, 0x0000);
2045 ibmcam_model2_Packet1(uvd, 0x0006, 0x00fb);
2046 ibmcam_model2_Packet1(uvd, 0x0008, 0x0000);
2047 ibmcam_model2_Packet1(uvd, 0x000c, 0x0009);
2048 ibmcam_model2_Packet1(uvd, 0x0012, 0x000a);
2049 ibmcam_model2_Packet1(uvd, 0x002a, 0x0000);
2050 ibmcam_model2_Packet1(uvd, 0x002c, 0x0000);
2051 ibmcam_model2_Packet1(uvd, 0x002e, 0x0008);
2052
2053 /*
2054 * Function 0x0030 pops up all over the place. Apparently
2055 * it is a hardware control register, with every bit assigned to
2056 * do something.
2057 */
2058 ibmcam_model2_Packet1(uvd, 0x0030, 0x0000);
2059
2060 /*
2061 * Magic control of CMOS sensor. Only lower values like
2062 * 0-3 work, and picture shifts left or right. Don't change.
2063 */
2064 switch (uvd->videosize) {
2065 case VIDEOSIZE_176x144:
2066 ibmcam_model2_Packet1(uvd, 0x0014, 0x0002);
2067 ibmcam_model2_Packet1(uvd, 0x0016, 0x0002); /* Horizontal shift */
2068 ibmcam_model2_Packet1(uvd, 0x0018, 0x004a); /* Another hardware setting */
2069 break;
2070 case VIDEOSIZE_320x240:
2071 ibmcam_model2_Packet1(uvd, 0x0014, 0x0009);
2072 ibmcam_model2_Packet1(uvd, 0x0016, 0x0005); /* Horizontal shift */
2073 ibmcam_model2_Packet1(uvd, 0x0018, 0x0044); /* Another hardware setting */
2074 break;
2075 case VIDEOSIZE_352x240:
2076 /* This mode doesn't work as Windows programs it; changed to work */
2077 ibmcam_model2_Packet1(uvd, 0x0014, 0x0009); /* Windows sets this to 8 */
2078 ibmcam_model2_Packet1(uvd, 0x0016, 0x0003); /* Horizontal shift */
2079 ibmcam_model2_Packet1(uvd, 0x0018, 0x0044); /* Windows sets this to 0x0045 */
2080 break;
2081 case VIDEOSIZE_352x288:
2082 ibmcam_model2_Packet1(uvd, 0x0014, 0x0003);
2083 ibmcam_model2_Packet1(uvd, 0x0016, 0x0002); /* Horizontal shift */
2084 ibmcam_model2_Packet1(uvd, 0x0018, 0x004a); /* Another hardware setting */
2085 break;
2086 }
2087
2088 ibmcam_model2_Packet1(uvd, mod2_brightness, 0x005a);
2089
2090 /*
2091 * We have our own frame rate setting varying from 0 (slowest) to 6 (fastest).
2092 * The camera model 2 allows frame rate in range [0..0x1F] where 0 is also the
2093 * slowest setting. However for all practical reasons high settings make no
2094 * sense because USB is not fast enough to support high FPS. Be aware that
2095 * the picture datastream will be severely disrupted if you ask for
2096 * frame rate faster than allowed for the video size - see below:
2097 *
2098 * Allowable ranges (obtained experimentally on OHCI, K6-3, 450 MHz):
2099 * -----------------------------------------------------------------
2100 * 176x144: [6..31]
2101 * 320x240: [8..31]
2102 * 352x240: [10..31]
2103 * 352x288: [16..31] I have to raise lower threshold for stability...
2104 *
2105 * As usual, slower FPS provides better sensitivity.
2106 */
2107 {
2108 short hw_fps=31, i_framerate;
2109
2110 RESTRICT_TO_RANGE(framerate, FRAMERATE_MIN, FRAMERATE_MAX);
2111 i_framerate = FRAMERATE_MAX - framerate + FRAMERATE_MIN;
2112 switch (uvd->videosize) {
2113 case VIDEOSIZE_176x144:
2114 hw_fps = 6 + i_framerate*4;
2115 break;
2116 case VIDEOSIZE_320x240:
2117 hw_fps = 8 + i_framerate*3;
2118 break;
2119 case VIDEOSIZE_352x240:
2120 hw_fps = 10 + i_framerate*2;
2121 break;
2122 case VIDEOSIZE_352x288:
2123 hw_fps = 28 + i_framerate/2;
2124 break;
2125 }
2126 if (uvd->debug > 0)
2127 dev_info(&uvd->dev->dev, "Framerate (hardware): %hd.\n",
2128 hw_fps);
2129 RESTRICT_TO_RANGE(hw_fps, 0, 31);
2130 ibmcam_model2_Packet1(uvd, mod2_set_framerate, hw_fps);
2131 }
2132
2133 /*
2134 * This setting does not visibly affect pictures; left it here
2135 * because it was present in Windows USB data stream. This function
2136 * does not allow arbitrary values and apparently is a bit mask, to
2137 * be activated only at appropriate time. Don't change it randomly!
2138 */
2139 switch (uvd->videosize) {
2140 case VIDEOSIZE_176x144:
2141 ibmcam_model2_Packet1(uvd, 0x0026, 0x00c2);
2142 break;
2143 case VIDEOSIZE_320x240:
2144 ibmcam_model2_Packet1(uvd, 0x0026, 0x0044);
2145 break;
2146 case VIDEOSIZE_352x240:
2147 ibmcam_model2_Packet1(uvd, 0x0026, 0x0046);
2148 break;
2149 case VIDEOSIZE_352x288:
2150 ibmcam_model2_Packet1(uvd, 0x0026, 0x0048);
2151 break;
2152 }
2153
2154 ibmcam_model2_Packet1(uvd, mod2_sensitivity, lighting);
2155
2156 if (init_model2_rg2 >= 0) {
2157 RESTRICT_TO_RANGE(init_model2_rg2, 0, 255);
2158 setup_model2_rg2 = init_model2_rg2;
2159 } else
2160 setup_model2_rg2 = 0x002f;
2161
2162 if (init_model2_sat >= 0) {
2163 RESTRICT_TO_RANGE(init_model2_sat, 0, 255);
2164 setup_model2_sat = init_model2_sat;
2165 } else
2166 setup_model2_sat = 0x0034;
2167
2168 if (init_model2_yb >= 0) {
2169 RESTRICT_TO_RANGE(init_model2_yb, 0, 255);
2170 setup_model2_yb = init_model2_yb;
2171 } else
2172 setup_model2_yb = 0x00a0;
2173
2174 ibmcam_model2_Packet1(uvd, mod2_color_balance_rg2, setup_model2_rg2);
2175 ibmcam_model2_Packet1(uvd, mod2_saturation, setup_model2_sat);
2176 ibmcam_model2_Packet1(uvd, mod2_color_balance_yb, setup_model2_yb);
2177 ibmcam_model2_Packet1(uvd, mod2_hue, uvd->vpic.hue >> 9); /* 0 .. 7F */;
2178
2179 /* Hardware control command */
2180 ibmcam_model2_Packet1(uvd, 0x0030, 0x0004);
2181
2182 ibmcam_veio(uvd, 0, 0x00c0, 0x010c); /* Go camera, go! */
2183 usb_clear_halt(uvd->dev, usb_rcvisocpipe(uvd->dev, uvd->video_endp));
2184}
2185
2186static void ibmcam_model4_setup_after_video_if(struct uvd *uvd)
2187{
2188 switch (uvd->videosize) {
2189 case VIDEOSIZE_128x96:
2190 ibmcam_veio(uvd, 0, 0x0000, 0x0100);
2191 ibmcam_veio(uvd, 0, 0x00c0, 0x0111);
2192 ibmcam_veio(uvd, 0, 0x00bc, 0x012c);
2193 ibmcam_veio(uvd, 0, 0x0080, 0x012b);
2194 ibmcam_veio(uvd, 0, 0x0000, 0x0108);
2195 ibmcam_veio(uvd, 0, 0x0001, 0x0133);
2196 ibmcam_veio(uvd, 0, 0x009b, 0x010f);
2197 ibmcam_veio(uvd, 0, 0x00bb, 0x010f);
2198 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
2199 ibmcam_veio(uvd, 0, 0x0038, 0x012f);
2200 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
2201 ibmcam_veio(uvd, 0, 0x0000, 0x0127);
2202 ibmcam_veio(uvd, 0, 0xfea8, 0x0124);
2203 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
2204 ibmcam_veio(uvd, 0, 0x000a, 0x012f);
2205 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
2206 ibmcam_veio(uvd, 0, 0x005c, 0x0127);
2207 ibmcam_veio(uvd, 0, 0xfea8, 0x0124);
2208 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
2209 ibmcam_veio(uvd, 0, 0x0004, 0x012f);
2210 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
2211 ibmcam_veio(uvd, 0, 0x0000, 0x0127);
2212 ibmcam_veio(uvd, 0, 0x00fb, 0x012e);
2213 ibmcam_veio(uvd, 0, 0x0000, 0x0130);
2214 ibmcam_veio(uvd, 0, 0x8a28, 0x0124);
2215 ibmcam_veio(uvd, 0, 0x00aa, 0x012f);
2216 ibmcam_veio(uvd, 0, 0xd055, 0x0124);
2217 ibmcam_veio(uvd, 0, 0x000c, 0x0127);
2218 ibmcam_veio(uvd, 0, 0x0009, 0x012e);
2219 ibmcam_veio(uvd, 0, 0xaa28, 0x0124);
2220 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
2221 ibmcam_veio(uvd, 0, 0x0012, 0x012f);
2222 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
2223 ibmcam_veio(uvd, 0, 0x0008, 0x0127);
2224 ibmcam_veio(uvd, 0, 0x00aa, 0x0130);
2225 ibmcam_veio(uvd, 0, 0x82a8, 0x0124);
2226 ibmcam_veio(uvd, 0, 0x002a, 0x012d);
2227 ibmcam_veio(uvd, 0, 0x0000, 0x012f);
2228 ibmcam_veio(uvd, 0, 0xd145, 0x0124);
2229 ibmcam_veio(uvd, 0, 0xfffa, 0x0124);
2230 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
2231 ibmcam_veio(uvd, 0, 0x0034, 0x012f);
2232 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
2233 ibmcam_veio(uvd, 0, 0x0000, 0x0127);
2234 ibmcam_veio(uvd, 0, 0xfea8, 0x0124);
2235 ibmcam_veio(uvd, 0, 0x0070, 0x0119);
2236 ibmcam_veio(uvd, 0, 0x00d2, 0x0107);
2237 ibmcam_veio(uvd, 0, 0x0003, 0x0106);
2238 ibmcam_veio(uvd, 0, 0x005e, 0x0107);
2239 ibmcam_veio(uvd, 0, 0x0003, 0x0106);
2240 ibmcam_veio(uvd, 0, 0x00d0, 0x0111);
2241 ibmcam_veio(uvd, 0, 0x0039, 0x010a);
2242 ibmcam_veio(uvd, 0, 0x0001, 0x0102);
2243 ibmcam_veio(uvd, 0, 0x0028, 0x0103);
2244 ibmcam_veio(uvd, 0, 0x0000, 0x0104);
2245 ibmcam_veio(uvd, 0, 0x001e, 0x0105);
2246 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
2247 ibmcam_veio(uvd, 0, 0x0016, 0x012f);
2248 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
2249 ibmcam_veio(uvd, 0, 0x000a, 0x0127);
2250 ibmcam_veio(uvd, 0, 0x00aa, 0x0130);
2251 ibmcam_veio(uvd, 0, 0x82a8, 0x0124);
2252 ibmcam_veio(uvd, 0, 0x0014, 0x012d);
2253 ibmcam_veio(uvd, 0, 0x0008, 0x012f);
2254 ibmcam_veio(uvd, 0, 0xd145, 0x0124);
2255 ibmcam_veio(uvd, 0, 0x00aa, 0x012e);
2256 ibmcam_veio(uvd, 0, 0x001a, 0x0130);
2257 ibmcam_veio(uvd, 0, 0x8a0a, 0x0124);
2258 ibmcam_veio(uvd, 0, 0x005a, 0x012d);
2259 ibmcam_veio(uvd, 0, 0x9545, 0x0124);
2260 ibmcam_veio(uvd, 0, 0x00aa, 0x0127);
2261 ibmcam_veio(uvd, 0, 0x0018, 0x012e);
2262 ibmcam_veio(uvd, 0, 0x0043, 0x0130);
2263 ibmcam_veio(uvd, 0, 0x8a28, 0x0124);
2264 ibmcam_veio(uvd, 0, 0x00aa, 0x012f);
2265 ibmcam_veio(uvd, 0, 0xd055, 0x0124);
2266 ibmcam_veio(uvd, 0, 0x001c, 0x0127);
2267 ibmcam_veio(uvd, 0, 0x00eb, 0x012e);
2268 ibmcam_veio(uvd, 0, 0xaa28, 0x0124);
2269 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
2270 ibmcam_veio(uvd, 0, 0x0032, 0x012f);
2271 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
2272 ibmcam_veio(uvd, 0, 0x0000, 0x0127);
2273 ibmcam_veio(uvd, 0, 0x00aa, 0x0130);
2274 ibmcam_veio(uvd, 0, 0x82a8, 0x0124);
2275 ibmcam_veio(uvd, 0, 0x0036, 0x012d);
2276 ibmcam_veio(uvd, 0, 0x0008, 0x012f);
2277 ibmcam_veio(uvd, 0, 0xd145, 0x0124);
2278 ibmcam_veio(uvd, 0, 0xfffa, 0x0124);
2279 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
2280 ibmcam_veio(uvd, 0, 0x001e, 0x012f);
2281 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
2282 ibmcam_veio(uvd, 0, 0x0017, 0x0127);
2283 ibmcam_veio(uvd, 0, 0x0013, 0x012e);
2284 ibmcam_veio(uvd, 0, 0x0031, 0x0130);
2285 ibmcam_veio(uvd, 0, 0x8a28, 0x0124);
2286 ibmcam_veio(uvd, 0, 0x0017, 0x012d);
2287 ibmcam_veio(uvd, 0, 0x0078, 0x012f);
2288 ibmcam_veio(uvd, 0, 0xd145, 0x0124);
2289 ibmcam_veio(uvd, 0, 0x0000, 0x0127);
2290 ibmcam_veio(uvd, 0, 0xfea8, 0x0124);
2291 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
2292 ibmcam_veio(uvd, 0, 0x0038, 0x012f);
2293 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
2294 ibmcam_veio(uvd, 0, 0x0004, 0x0127);
2295 ibmcam_veio(uvd, 0, 0xfea8, 0x0124);
2296 ibmcam_veio(uvd, 0, 0x00c0, 0x010c);
2297 break;
2298 case VIDEOSIZE_160x120:
2299 ibmcam_veio(uvd, 0, 0x0000, 0x0100);
2300 ibmcam_veio(uvd, 0, 0x00c0, 0x0111);
2301 ibmcam_veio(uvd, 0, 0x00bc, 0x012c);
2302 ibmcam_veio(uvd, 0, 0x0080, 0x012b);
2303 ibmcam_veio(uvd, 0, 0x0000, 0x0108);
2304 ibmcam_veio(uvd, 0, 0x0001, 0x0133);
2305 ibmcam_veio(uvd, 0, 0x009b, 0x010f);
2306 ibmcam_veio(uvd, 0, 0x00bb, 0x010f);
2307 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
2308 ibmcam_veio(uvd, 0, 0x0038, 0x012f);
2309 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
2310 ibmcam_veio(uvd, 0, 0x0000, 0x0127);
2311 ibmcam_veio(uvd, 0, 0xfea8, 0x0124);
2312 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
2313 ibmcam_veio(uvd, 0, 0x000a, 0x012f);
2314 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
2315 ibmcam_veio(uvd, 0, 0x005c, 0x0127);
2316 ibmcam_veio(uvd, 0, 0xfea8, 0x0124);
2317 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
2318 ibmcam_veio(uvd, 0, 0x0004, 0x012f);
2319 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
2320 ibmcam_veio(uvd, 0, 0x0000, 0x0127);
2321 ibmcam_veio(uvd, 0, 0x00fb, 0x012e);
2322 ibmcam_veio(uvd, 0, 0x0000, 0x0130);
2323 ibmcam_veio(uvd, 0, 0x8a28, 0x0124);
2324 ibmcam_veio(uvd, 0, 0x00aa, 0x012f);
2325 ibmcam_veio(uvd, 0, 0xd055, 0x0124);
2326 ibmcam_veio(uvd, 0, 0x000c, 0x0127);
2327 ibmcam_veio(uvd, 0, 0x0009, 0x012e);
2328 ibmcam_veio(uvd, 0, 0xaa28, 0x0124);
2329 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
2330 ibmcam_veio(uvd, 0, 0x0012, 0x012f);
2331 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
2332 ibmcam_veio(uvd, 0, 0x0008, 0x0127);
2333 ibmcam_veio(uvd, 0, 0x00aa, 0x0130);
2334 ibmcam_veio(uvd, 0, 0x82a8, 0x0124);
2335 ibmcam_veio(uvd, 0, 0x002a, 0x012d);
2336 ibmcam_veio(uvd, 0, 0x0000, 0x012f);
2337 ibmcam_veio(uvd, 0, 0xd145, 0x0124);
2338 ibmcam_veio(uvd, 0, 0xfffa, 0x0124);
2339 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
2340 ibmcam_veio(uvd, 0, 0x0034, 0x012f);
2341 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
2342 ibmcam_veio(uvd, 0, 0x0000, 0x0127);
2343 ibmcam_veio(uvd, 0, 0xfea8, 0x0124);
2344 ibmcam_veio(uvd, 0, 0x0038, 0x0119);
2345 ibmcam_veio(uvd, 0, 0x00d8, 0x0107);
2346 ibmcam_veio(uvd, 0, 0x0002, 0x0106);
2347 ibmcam_veio(uvd, 0, 0x00d0, 0x0111);
2348 ibmcam_veio(uvd, 0, 0x00b9, 0x010a);
2349 ibmcam_veio(uvd, 0, 0x0001, 0x0102);
2350 ibmcam_veio(uvd, 0, 0x0028, 0x0103);
2351 ibmcam_veio(uvd, 0, 0x0000, 0x0104);
2352 ibmcam_veio(uvd, 0, 0x001e, 0x0105);
2353 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
2354 ibmcam_veio(uvd, 0, 0x0016, 0x012f);
2355 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
2356 ibmcam_veio(uvd, 0, 0x000b, 0x0127);
2357 ibmcam_veio(uvd, 0, 0x00aa, 0x0130);
2358 ibmcam_veio(uvd, 0, 0x82a8, 0x0124);
2359 ibmcam_veio(uvd, 0, 0x0014, 0x012d);
2360 ibmcam_veio(uvd, 0, 0x0008, 0x012f);
2361 ibmcam_veio(uvd, 0, 0xd145, 0x0124);
2362 ibmcam_veio(uvd, 0, 0x00aa, 0x012e);
2363 ibmcam_veio(uvd, 0, 0x001a, 0x0130);
2364 ibmcam_veio(uvd, 0, 0x8a0a, 0x0124);
2365 ibmcam_veio(uvd, 0, 0x005a, 0x012d);
2366 ibmcam_veio(uvd, 0, 0x9545, 0x0124);
2367 ibmcam_veio(uvd, 0, 0x00aa, 0x0127);
2368 ibmcam_veio(uvd, 0, 0x0018, 0x012e);
2369 ibmcam_veio(uvd, 0, 0x0043, 0x0130);
2370 ibmcam_veio(uvd, 0, 0x8a28, 0x0124);
2371 ibmcam_veio(uvd, 0, 0x00aa, 0x012f);
2372 ibmcam_veio(uvd, 0, 0xd055, 0x0124);
2373 ibmcam_veio(uvd, 0, 0x001c, 0x0127);
2374 ibmcam_veio(uvd, 0, 0x00c7, 0x012e);
2375 ibmcam_veio(uvd, 0, 0xaa28, 0x0124);
2376 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
2377 ibmcam_veio(uvd, 0, 0x0032, 0x012f);
2378 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
2379 ibmcam_veio(uvd, 0, 0x0025, 0x0127);
2380 ibmcam_veio(uvd, 0, 0x00aa, 0x0130);
2381 ibmcam_veio(uvd, 0, 0x82a8, 0x0124);
2382 ibmcam_veio(uvd, 0, 0x0036, 0x012d);
2383 ibmcam_veio(uvd, 0, 0x0008, 0x012f);
2384 ibmcam_veio(uvd, 0, 0xd145, 0x0124);
2385 ibmcam_veio(uvd, 0, 0xfffa, 0x0124);
2386 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
2387 ibmcam_veio(uvd, 0, 0x001e, 0x012f);
2388 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
2389 ibmcam_veio(uvd, 0, 0x0048, 0x0127);
2390 ibmcam_veio(uvd, 0, 0x0035, 0x012e);
2391 ibmcam_veio(uvd, 0, 0x00d0, 0x0130);
2392 ibmcam_veio(uvd, 0, 0x8a28, 0x0124);
2393 ibmcam_veio(uvd, 0, 0x0048, 0x012d);
2394 ibmcam_veio(uvd, 0, 0x0090, 0x012f);
2395 ibmcam_veio(uvd, 0, 0xd145, 0x0124);
2396 ibmcam_veio(uvd, 0, 0x0001, 0x0127);
2397 ibmcam_veio(uvd, 0, 0xfea8, 0x0124);
2398 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
2399 ibmcam_veio(uvd, 0, 0x0038, 0x012f);
2400 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
2401 ibmcam_veio(uvd, 0, 0x0004, 0x0127);
2402 ibmcam_veio(uvd, 0, 0xfea8, 0x0124);
2403 ibmcam_veio(uvd, 0, 0x00c0, 0x010c);
2404 break;
2405 case VIDEOSIZE_176x144:
2406 ibmcam_veio(uvd, 0, 0x0000, 0x0100);
2407 ibmcam_veio(uvd, 0, 0x00c0, 0x0111);
2408 ibmcam_veio(uvd, 0, 0x00bc, 0x012c);
2409 ibmcam_veio(uvd, 0, 0x0080, 0x012b);
2410 ibmcam_veio(uvd, 0, 0x0000, 0x0108);
2411 ibmcam_veio(uvd, 0, 0x0001, 0x0133);
2412 ibmcam_veio(uvd, 0, 0x009b, 0x010f);
2413 ibmcam_veio(uvd, 0, 0x00bb, 0x010f);
2414 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
2415 ibmcam_veio(uvd, 0, 0x0038, 0x012f);
2416 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
2417 ibmcam_veio(uvd, 0, 0x0000, 0x0127);
2418 ibmcam_veio(uvd, 0, 0xfea8, 0x0124);
2419 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
2420 ibmcam_veio(uvd, 0, 0x000a, 0x012f);
2421 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
2422 ibmcam_veio(uvd, 0, 0x005c, 0x0127);
2423 ibmcam_veio(uvd, 0, 0xfea8, 0x0124);
2424 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
2425 ibmcam_veio(uvd, 0, 0x0004, 0x012f);
2426 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
2427 ibmcam_veio(uvd, 0, 0x0000, 0x0127);
2428 ibmcam_veio(uvd, 0, 0x00fb, 0x012e);
2429 ibmcam_veio(uvd, 0, 0x0000, 0x0130);
2430 ibmcam_veio(uvd, 0, 0x8a28, 0x0124);
2431 ibmcam_veio(uvd, 0, 0x00aa, 0x012f);
2432 ibmcam_veio(uvd, 0, 0xd055, 0x0124);
2433 ibmcam_veio(uvd, 0, 0x000c, 0x0127);
2434 ibmcam_veio(uvd, 0, 0x0009, 0x012e);
2435 ibmcam_veio(uvd, 0, 0xaa28, 0x0124);
2436 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
2437 ibmcam_veio(uvd, 0, 0x0012, 0x012f);
2438 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
2439 ibmcam_veio(uvd, 0, 0x0008, 0x0127);
2440 ibmcam_veio(uvd, 0, 0x00aa, 0x0130);
2441 ibmcam_veio(uvd, 0, 0x82a8, 0x0124);
2442 ibmcam_veio(uvd, 0, 0x002a, 0x012d);
2443 ibmcam_veio(uvd, 0, 0x0000, 0x012f);
2444 ibmcam_veio(uvd, 0, 0xd145, 0x0124);
2445 ibmcam_veio(uvd, 0, 0xfffa, 0x0124);
2446 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
2447 ibmcam_veio(uvd, 0, 0x0034, 0x012f);
2448 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
2449 ibmcam_veio(uvd, 0, 0x0000, 0x0127);
2450 ibmcam_veio(uvd, 0, 0xfea8, 0x0124);
2451 ibmcam_veio(uvd, 0, 0x0038, 0x0119);
2452 ibmcam_veio(uvd, 0, 0x00d6, 0x0107);
2453 ibmcam_veio(uvd, 0, 0x0003, 0x0106);
2454 ibmcam_veio(uvd, 0, 0x0018, 0x0107);
2455 ibmcam_veio(uvd, 0, 0x0003, 0x0106);
2456 ibmcam_veio(uvd, 0, 0x00d0, 0x0111);
2457 ibmcam_veio(uvd, 0, 0x00b9, 0x010a);
2458 ibmcam_veio(uvd, 0, 0x0001, 0x0102);
2459 ibmcam_veio(uvd, 0, 0x002c, 0x0103);
2460 ibmcam_veio(uvd, 0, 0x0000, 0x0104);
2461 ibmcam_veio(uvd, 0, 0x0024, 0x0105);
2462 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
2463 ibmcam_veio(uvd, 0, 0x0016, 0x012f);
2464 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
2465 ibmcam_veio(uvd, 0, 0x0007, 0x0127);
2466 ibmcam_veio(uvd, 0, 0x00aa, 0x0130);
2467 ibmcam_veio(uvd, 0, 0x82a8, 0x0124);
2468 ibmcam_veio(uvd, 0, 0x0014, 0x012d);
2469 ibmcam_veio(uvd, 0, 0x0001, 0x012f);
2470 ibmcam_veio(uvd, 0, 0xd145, 0x0124);
2471 ibmcam_veio(uvd, 0, 0x00aa, 0x012e);
2472 ibmcam_veio(uvd, 0, 0x001a, 0x0130);
2473 ibmcam_veio(uvd, 0, 0x8a0a, 0x0124);
2474 ibmcam_veio(uvd, 0, 0x005e, 0x012d);
2475 ibmcam_veio(uvd, 0, 0x9545, 0x0124);
2476 ibmcam_veio(uvd, 0, 0x00aa, 0x0127);
2477 ibmcam_veio(uvd, 0, 0x0018, 0x012e);
2478 ibmcam_veio(uvd, 0, 0x0049, 0x0130);
2479 ibmcam_veio(uvd, 0, 0x8a28, 0x0124);
2480 ibmcam_veio(uvd, 0, 0x00aa, 0x012f);
2481 ibmcam_veio(uvd, 0, 0xd055, 0x0124);
2482 ibmcam_veio(uvd, 0, 0x001c, 0x0127);
2483 ibmcam_veio(uvd, 0, 0x00c7, 0x012e);
2484 ibmcam_veio(uvd, 0, 0xaa28, 0x0124);
2485 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
2486 ibmcam_veio(uvd, 0, 0x0032, 0x012f);
2487 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
2488 ibmcam_veio(uvd, 0, 0x0028, 0x0127);
2489 ibmcam_veio(uvd, 0, 0x00aa, 0x0130);
2490 ibmcam_veio(uvd, 0, 0x82a8, 0x0124);
2491 ibmcam_veio(uvd, 0, 0x0036, 0x012d);
2492 ibmcam_veio(uvd, 0, 0x0008, 0x012f);
2493 ibmcam_veio(uvd, 0, 0xd145, 0x0124);
2494 ibmcam_veio(uvd, 0, 0xfffa, 0x0124);
2495 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
2496 ibmcam_veio(uvd, 0, 0x001e, 0x012f);
2497 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
2498 ibmcam_veio(uvd, 0, 0x0010, 0x0127);
2499 ibmcam_veio(uvd, 0, 0x0013, 0x012e);
2500 ibmcam_veio(uvd, 0, 0x002a, 0x0130);
2501 ibmcam_veio(uvd, 0, 0x8a28, 0x0124);
2502 ibmcam_veio(uvd, 0, 0x0010, 0x012d);
2503 ibmcam_veio(uvd, 0, 0x006d, 0x012f);
2504 ibmcam_veio(uvd, 0, 0xd145, 0x0124);
2505 ibmcam_veio(uvd, 0, 0x0001, 0x0127);
2506 ibmcam_veio(uvd, 0, 0xfea8, 0x0124);
2507 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
2508 ibmcam_veio(uvd, 0, 0x0038, 0x012f);
2509 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
2510 ibmcam_veio(uvd, 0, 0x0004, 0x0127);
2511 ibmcam_veio(uvd, 0, 0xfea8, 0x0124);
2512 ibmcam_veio(uvd, 0, 0x00c0, 0x010c);
2513 break;
2514 case VIDEOSIZE_320x240:
2515 ibmcam_veio(uvd, 0, 0x0000, 0x0100);
2516 ibmcam_veio(uvd, 0, 0x00c0, 0x0111);
2517 ibmcam_veio(uvd, 0, 0x00bc, 0x012c);
2518 ibmcam_veio(uvd, 0, 0x0080, 0x012b);
2519 ibmcam_veio(uvd, 0, 0x0000, 0x0108);
2520 ibmcam_veio(uvd, 0, 0x0001, 0x0133);
2521 ibmcam_veio(uvd, 0, 0x009b, 0x010f);
2522 ibmcam_veio(uvd, 0, 0x00bb, 0x010f);
2523 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
2524 ibmcam_veio(uvd, 0, 0x0038, 0x012f);
2525 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
2526 ibmcam_veio(uvd, 0, 0x0000, 0x0127);
2527 ibmcam_veio(uvd, 0, 0xfea8, 0x0124);
2528 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
2529 ibmcam_veio(uvd, 0, 0x000a, 0x012f);
2530 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
2531 ibmcam_veio(uvd, 0, 0x005c, 0x0127);
2532 ibmcam_veio(uvd, 0, 0xfea8, 0x0124);
2533 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
2534 ibmcam_veio(uvd, 0, 0x0004, 0x012f);
2535 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
2536 ibmcam_veio(uvd, 0, 0x0000, 0x0127);
2537 ibmcam_veio(uvd, 0, 0x00fb, 0x012e);
2538 ibmcam_veio(uvd, 0, 0x0000, 0x0130);
2539 ibmcam_veio(uvd, 0, 0x8a28, 0x0124);
2540 ibmcam_veio(uvd, 0, 0x00aa, 0x012f);
2541 ibmcam_veio(uvd, 0, 0xd055, 0x0124);
2542 ibmcam_veio(uvd, 0, 0x000c, 0x0127);
2543 ibmcam_veio(uvd, 0, 0x0009, 0x012e);
2544 ibmcam_veio(uvd, 0, 0xaa28, 0x0124);
2545 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
2546 ibmcam_veio(uvd, 0, 0x0012, 0x012f);
2547 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
2548 ibmcam_veio(uvd, 0, 0x0008, 0x0127);
2549 ibmcam_veio(uvd, 0, 0x00aa, 0x0130);
2550 ibmcam_veio(uvd, 0, 0x82a8, 0x0124);
2551 ibmcam_veio(uvd, 0, 0x002a, 0x012d);
2552 ibmcam_veio(uvd, 0, 0x0000, 0x012f);
2553 ibmcam_veio(uvd, 0, 0xd145, 0x0124);
2554 ibmcam_veio(uvd, 0, 0xfffa, 0x0124);
2555 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
2556 ibmcam_veio(uvd, 0, 0x0034, 0x012f);
2557 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
2558 ibmcam_veio(uvd, 0, 0x0000, 0x0127);
2559 ibmcam_veio(uvd, 0, 0xfea8, 0x0124);
2560 ibmcam_veio(uvd, 0, 0x0070, 0x0119);
2561 ibmcam_veio(uvd, 0, 0x00d2, 0x0107);
2562 ibmcam_veio(uvd, 0, 0x0003, 0x0106);
2563 ibmcam_veio(uvd, 0, 0x005e, 0x0107);
2564 ibmcam_veio(uvd, 0, 0x0003, 0x0106);
2565 ibmcam_veio(uvd, 0, 0x00d0, 0x0111);
2566 ibmcam_veio(uvd, 0, 0x0039, 0x010a);
2567 ibmcam_veio(uvd, 0, 0x0001, 0x0102);
2568 ibmcam_veio(uvd, 0, 0x0028, 0x0103);
2569 ibmcam_veio(uvd, 0, 0x0000, 0x0104);
2570 ibmcam_veio(uvd, 0, 0x001e, 0x0105);
2571 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
2572 ibmcam_veio(uvd, 0, 0x0016, 0x012f);
2573 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
2574 ibmcam_veio(uvd, 0, 0x000a, 0x0127);
2575 ibmcam_veio(uvd, 0, 0x00aa, 0x0130);
2576 ibmcam_veio(uvd, 0, 0x82a8, 0x0124);
2577 ibmcam_veio(uvd, 0, 0x0014, 0x012d);
2578 ibmcam_veio(uvd, 0, 0x0008, 0x012f);
2579 ibmcam_veio(uvd, 0, 0xd145, 0x0124);
2580 ibmcam_veio(uvd, 0, 0x00aa, 0x012e);
2581 ibmcam_veio(uvd, 0, 0x001a, 0x0130);
2582 ibmcam_veio(uvd, 0, 0x8a0a, 0x0124);
2583 ibmcam_veio(uvd, 0, 0x005a, 0x012d);
2584 ibmcam_veio(uvd, 0, 0x9545, 0x0124);
2585 ibmcam_veio(uvd, 0, 0x00aa, 0x0127);
2586 ibmcam_veio(uvd, 0, 0x0018, 0x012e);
2587 ibmcam_veio(uvd, 0, 0x0043, 0x0130);
2588 ibmcam_veio(uvd, 0, 0x8a28, 0x0124);
2589 ibmcam_veio(uvd, 0, 0x00aa, 0x012f);
2590 ibmcam_veio(uvd, 0, 0xd055, 0x0124);
2591 ibmcam_veio(uvd, 0, 0x001c, 0x0127);
2592 ibmcam_veio(uvd, 0, 0x00eb, 0x012e);
2593 ibmcam_veio(uvd, 0, 0xaa28, 0x0124);
2594 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
2595 ibmcam_veio(uvd, 0, 0x0032, 0x012f);
2596 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
2597 ibmcam_veio(uvd, 0, 0x0000, 0x0127);
2598 ibmcam_veio(uvd, 0, 0x00aa, 0x0130);
2599 ibmcam_veio(uvd, 0, 0x82a8, 0x0124);
2600 ibmcam_veio(uvd, 0, 0x0036, 0x012d);
2601 ibmcam_veio(uvd, 0, 0x0008, 0x012f);
2602 ibmcam_veio(uvd, 0, 0xd145, 0x0124);
2603 ibmcam_veio(uvd, 0, 0xfffa, 0x0124);
2604 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
2605 ibmcam_veio(uvd, 0, 0x001e, 0x012f);
2606 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
2607 ibmcam_veio(uvd, 0, 0x0017, 0x0127);
2608 ibmcam_veio(uvd, 0, 0x0013, 0x012e);
2609 ibmcam_veio(uvd, 0, 0x0031, 0x0130);
2610 ibmcam_veio(uvd, 0, 0x8a28, 0x0124);
2611 ibmcam_veio(uvd, 0, 0x0017, 0x012d);
2612 ibmcam_veio(uvd, 0, 0x0078, 0x012f);
2613 ibmcam_veio(uvd, 0, 0xd145, 0x0124);
2614 ibmcam_veio(uvd, 0, 0x0000, 0x0127);
2615 ibmcam_veio(uvd, 0, 0xfea8, 0x0124);
2616 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
2617 ibmcam_veio(uvd, 0, 0x0038, 0x012f);
2618 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
2619 ibmcam_veio(uvd, 0, 0x0004, 0x0127);
2620 ibmcam_veio(uvd, 0, 0xfea8, 0x0124);
2621 ibmcam_veio(uvd, 0, 0x00c0, 0x010c);
2622 break;
2623 case VIDEOSIZE_352x288:
2624 ibmcam_veio(uvd, 0, 0x0000, 0x0100);
2625 ibmcam_veio(uvd, 0, 0x00c0, 0x0111);
2626 ibmcam_veio(uvd, 0, 0x00bc, 0x012c);
2627 ibmcam_veio(uvd, 0, 0x0080, 0x012b);
2628 ibmcam_veio(uvd, 0, 0x0000, 0x0108);
2629 ibmcam_veio(uvd, 0, 0x0001, 0x0133);
2630 ibmcam_veio(uvd, 0, 0x009b, 0x010f);
2631 ibmcam_veio(uvd, 0, 0x00bb, 0x010f);
2632 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
2633 ibmcam_veio(uvd, 0, 0x0038, 0x012f);
2634 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
2635 ibmcam_veio(uvd, 0, 0x0000, 0x0127);
2636 ibmcam_veio(uvd, 0, 0xfea8, 0x0124);
2637 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
2638 ibmcam_veio(uvd, 0, 0x000a, 0x012f);
2639 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
2640 ibmcam_veio(uvd, 0, 0x005c, 0x0127);
2641 ibmcam_veio(uvd, 0, 0xfea8, 0x0124);
2642 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
2643 ibmcam_veio(uvd, 0, 0x0004, 0x012f);
2644 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
2645 ibmcam_veio(uvd, 0, 0x0000, 0x0127);
2646 ibmcam_veio(uvd, 0, 0x00fb, 0x012e);
2647 ibmcam_veio(uvd, 0, 0x0000, 0x0130);
2648 ibmcam_veio(uvd, 0, 0x8a28, 0x0124);
2649 ibmcam_veio(uvd, 0, 0x00aa, 0x012f);
2650 ibmcam_veio(uvd, 0, 0xd055, 0x0124);
2651 ibmcam_veio(uvd, 0, 0x000c, 0x0127);
2652 ibmcam_veio(uvd, 0, 0x0009, 0x012e);
2653 ibmcam_veio(uvd, 0, 0xaa28, 0x0124);
2654 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
2655 ibmcam_veio(uvd, 0, 0x0012, 0x012f);
2656 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
2657 ibmcam_veio(uvd, 0, 0x0008, 0x0127);
2658 ibmcam_veio(uvd, 0, 0x00aa, 0x0130);
2659 ibmcam_veio(uvd, 0, 0x82a8, 0x0124);
2660 ibmcam_veio(uvd, 0, 0x002a, 0x012d);
2661 ibmcam_veio(uvd, 0, 0x0000, 0x012f);
2662 ibmcam_veio(uvd, 0, 0xd145, 0x0124);
2663 ibmcam_veio(uvd, 0, 0xfffa, 0x0124);
2664 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
2665 ibmcam_veio(uvd, 0, 0x0034, 0x012f);
2666 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
2667 ibmcam_veio(uvd, 0, 0x0000, 0x0127);
2668 ibmcam_veio(uvd, 0, 0xfea8, 0x0124);
2669 ibmcam_veio(uvd, 0, 0x0070, 0x0119);
2670 ibmcam_veio(uvd, 0, 0x00f2, 0x0107);
2671 ibmcam_veio(uvd, 0, 0x0003, 0x0106);
2672 ibmcam_veio(uvd, 0, 0x008c, 0x0107);
2673 ibmcam_veio(uvd, 0, 0x0003, 0x0106);
2674 ibmcam_veio(uvd, 0, 0x00c0, 0x0111);
2675 ibmcam_veio(uvd, 0, 0x0039, 0x010a);
2676 ibmcam_veio(uvd, 0, 0x0001, 0x0102);
2677 ibmcam_veio(uvd, 0, 0x002c, 0x0103);
2678 ibmcam_veio(uvd, 0, 0x0000, 0x0104);
2679 ibmcam_veio(uvd, 0, 0x0024, 0x0105);
2680 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
2681 ibmcam_veio(uvd, 0, 0x0016, 0x012f);
2682 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
2683 ibmcam_veio(uvd, 0, 0x0006, 0x0127);
2684 ibmcam_veio(uvd, 0, 0x00aa, 0x0130);
2685 ibmcam_veio(uvd, 0, 0x82a8, 0x0124);
2686 ibmcam_veio(uvd, 0, 0x0014, 0x012d);
2687 ibmcam_veio(uvd, 0, 0x0002, 0x012f);
2688 ibmcam_veio(uvd, 0, 0xd145, 0x0124);
2689 ibmcam_veio(uvd, 0, 0x00aa, 0x012e);
2690 ibmcam_veio(uvd, 0, 0x001a, 0x0130);
2691 ibmcam_veio(uvd, 0, 0x8a0a, 0x0124);
2692 ibmcam_veio(uvd, 0, 0x005e, 0x012d);
2693 ibmcam_veio(uvd, 0, 0x9545, 0x0124);
2694 ibmcam_veio(uvd, 0, 0x00aa, 0x0127);
2695 ibmcam_veio(uvd, 0, 0x0018, 0x012e);
2696 ibmcam_veio(uvd, 0, 0x0049, 0x0130);
2697 ibmcam_veio(uvd, 0, 0x8a28, 0x0124);
2698 ibmcam_veio(uvd, 0, 0x00aa, 0x012f);
2699 ibmcam_veio(uvd, 0, 0xd055, 0x0124);
2700 ibmcam_veio(uvd, 0, 0x001c, 0x0127);
2701 ibmcam_veio(uvd, 0, 0x00cf, 0x012e);
2702 ibmcam_veio(uvd, 0, 0xaa28, 0x0124);
2703 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
2704 ibmcam_veio(uvd, 0, 0x0032, 0x012f);
2705 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
2706 ibmcam_veio(uvd, 0, 0x0000, 0x0127);
2707 ibmcam_veio(uvd, 0, 0x00aa, 0x0130);
2708 ibmcam_veio(uvd, 0, 0x82a8, 0x0124);
2709 ibmcam_veio(uvd, 0, 0x0036, 0x012d);
2710 ibmcam_veio(uvd, 0, 0x0008, 0x012f);
2711 ibmcam_veio(uvd, 0, 0xd145, 0x0124);
2712 ibmcam_veio(uvd, 0, 0xfffa, 0x0124);
2713 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
2714 ibmcam_veio(uvd, 0, 0x001e, 0x012f);
2715 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
2716 ibmcam_veio(uvd, 0, 0x0010, 0x0127);
2717 ibmcam_veio(uvd, 0, 0x0013, 0x012e);
2718 ibmcam_veio(uvd, 0, 0x0025, 0x0130);
2719 ibmcam_veio(uvd, 0, 0x8a28, 0x0124);
2720 ibmcam_veio(uvd, 0, 0x0010, 0x012d);
2721 ibmcam_veio(uvd, 0, 0x0048, 0x012f);
2722 ibmcam_veio(uvd, 0, 0xd145, 0x0124);
2723 ibmcam_veio(uvd, 0, 0x0000, 0x0127);
2724 ibmcam_veio(uvd, 0, 0xfea8, 0x0124);
2725 ibmcam_veio(uvd, 0, 0x00aa, 0x012d);
2726 ibmcam_veio(uvd, 0, 0x0038, 0x012f);
2727 ibmcam_veio(uvd, 0, 0xd141, 0x0124);
2728 ibmcam_veio(uvd, 0, 0x0004, 0x0127);
2729 ibmcam_veio(uvd, 0, 0xfea8, 0x0124);
2730 ibmcam_veio(uvd, 0, 0x00c0, 0x010c);
2731 break;
2732 }
2733 usb_clear_halt(uvd->dev, usb_rcvisocpipe(uvd->dev, uvd->video_endp));
2734}
2735
2736static void ibmcam_model3_setup_after_video_if(struct uvd *uvd)
2737{
2738 int i;
2739 /*
2740 * 01.01.08 - Added for RCA video in support -LO
2741 * This struct is used to init the Model3 cam to use the RCA video in port
2742 * instead of the CCD sensor.
2743 */
2744 static const struct struct_initData initData[] = {
2745 {0, 0x0000, 0x010c},
2746 {0, 0x0006, 0x012c},
2747 {0, 0x0078, 0x012d},
2748 {0, 0x0046, 0x012f},
2749 {0, 0xd141, 0x0124},
2750 {0, 0x0000, 0x0127},
2751 {0, 0xfea8, 0x0124},
2752 {1, 0x0000, 0x0116},
2753 {0, 0x0064, 0x0116},
2754 {1, 0x0000, 0x0115},
2755 {0, 0x0003, 0x0115},
2756 {0, 0x0008, 0x0123},
2757 {0, 0x0000, 0x0117},
2758 {0, 0x0000, 0x0112},
2759 {0, 0x0080, 0x0100},
2760 {0, 0x0000, 0x0100},
2761 {1, 0x0000, 0x0116},
2762 {0, 0x0060, 0x0116},
2763 {0, 0x0002, 0x0112},
2764 {0, 0x0000, 0x0123},
2765 {0, 0x0001, 0x0117},
2766 {0, 0x0040, 0x0108},
2767 {0, 0x0019, 0x012c},
2768 {0, 0x0040, 0x0116},
2769 {0, 0x000a, 0x0115},
2770 {0, 0x000b, 0x0115},
2771 {0, 0x0078, 0x012d},
2772 {0, 0x0046, 0x012f},
2773 {0, 0xd141, 0x0124},
2774 {0, 0x0000, 0x0127},
2775 {0, 0xfea8, 0x0124},
2776 {0, 0x0064, 0x0116},
2777 {0, 0x0000, 0x0115},
2778 {0, 0x0001, 0x0115},
2779 {0, 0xffff, 0x0124},
2780 {0, 0xfff9, 0x0124},
2781 {0, 0x0086, 0x0127},
2782 {0, 0xfff8, 0x0124},
2783 {0, 0xfffd, 0x0124},
2784 {0, 0x00aa, 0x0127},
2785 {0, 0xfff8, 0x0124},
2786 {0, 0xfffd, 0x0124},
2787 {0, 0x0000, 0x0127},
2788 {0, 0xfff8, 0x0124},
2789 {0, 0xfffd, 0x0124},
2790 {0, 0xfffa, 0x0124},
2791 {0, 0xffff, 0x0124},
2792 {0, 0xfff9, 0x0124},
2793 {0, 0x0086, 0x0127},
2794 {0, 0xfff8, 0x0124},
2795 {0, 0xfffd, 0x0124},
2796 {0, 0x00f2, 0x0127},
2797 {0, 0xfff8, 0x0124},
2798 {0, 0xfffd, 0x0124},
2799 {0, 0x000f, 0x0127},
2800 {0, 0xfff8, 0x0124},
2801 {0, 0xfffd, 0x0124},
2802 {0, 0xfffa, 0x0124},
2803 {0, 0xffff, 0x0124},
2804 {0, 0xfff9, 0x0124},
2805 {0, 0x0086, 0x0127},
2806 {0, 0xfff8, 0x0124},
2807 {0, 0xfffd, 0x0124},
2808 {0, 0x00f8, 0x0127},
2809 {0, 0xfff8, 0x0124},
2810 {0, 0xfffd, 0x0124},
2811 {0, 0x00fc, 0x0127},
2812 {0, 0xfff8, 0x0124},
2813 {0, 0xfffd, 0x0124},
2814 {0, 0xfffa, 0x0124},
2815 {0, 0xffff, 0x0124},
2816 {0, 0xfff9, 0x0124},
2817 {0, 0x0086, 0x0127},
2818 {0, 0xfff8, 0x0124},
2819 {0, 0xfffd, 0x0124},
2820 {0, 0x00f9, 0x0127},
2821 {0, 0xfff8, 0x0124},
2822 {0, 0xfffd, 0x0124},
2823 {0, 0x003c, 0x0127},
2824 {0, 0xfff8, 0x0124},
2825 {0, 0xfffd, 0x0124},
2826 {0, 0xfffa, 0x0124},
2827 {0, 0xffff, 0x0124},
2828 {0, 0xfff9, 0x0124},
2829 {0, 0x0086, 0x0127},
2830 {0, 0xfff8, 0x0124},
2831 {0, 0xfffd, 0x0124},
2832 {0, 0x0027, 0x0127},
2833 {0, 0xfff8, 0x0124},
2834 {0, 0xfffd, 0x0124},
2835 {0, 0x0019, 0x0127},
2836 {0, 0xfff8, 0x0124},
2837 {0, 0xfffd, 0x0124},
2838 {0, 0xfffa, 0x0124},
2839 {0, 0xfff9, 0x0124},
2840 {0, 0x0086, 0x0127},
2841 {0, 0xfff8, 0x0124},
2842 {0, 0xfffd, 0x0124},
2843 {0, 0x0037, 0x0127},
2844 {0, 0xfff8, 0x0124},
2845 {0, 0xfffd, 0x0124},
2846 {0, 0x0000, 0x0127},
2847 {0, 0xfff8, 0x0124},
2848 {0, 0xfffd, 0x0124},
2849 {0, 0x0021, 0x0127},
2850 {0, 0xfff8, 0x0124},
2851 {0, 0xfffd, 0x0124},
2852 {0, 0xfffa, 0x0124},
2853 {0, 0xfff9, 0x0124},
2854 {0, 0x0086, 0x0127},
2855 {0, 0xfff8, 0x0124},
2856 {0, 0xfffd, 0x0124},
2857 {0, 0x0038, 0x0127},
2858 {0, 0xfff8, 0x0124},
2859 {0, 0xfffd, 0x0124},
2860 {0, 0x0006, 0x0127},
2861 {0, 0xfff8, 0x0124},
2862 {0, 0xfffd, 0x0124},
2863 {0, 0x0045, 0x0127},
2864 {0, 0xfff8, 0x0124},
2865 {0, 0xfffd, 0x0124},
2866 {0, 0xfffa, 0x0124},
2867 {0, 0xfff9, 0x0124},
2868 {0, 0x0086, 0x0127},
2869 {0, 0xfff8, 0x0124},
2870 {0, 0xfffd, 0x0124},
2871 {0, 0x0037, 0x0127},
2872 {0, 0xfff8, 0x0124},
2873 {0, 0xfffd, 0x0124},
2874 {0, 0x0001, 0x0127},
2875 {0, 0xfff8, 0x0124},
2876 {0, 0xfffd, 0x0124},
2877 {0, 0x002a, 0x0127},
2878 {0, 0xfff8, 0x0124},
2879 {0, 0xfffd, 0x0124},
2880 {0, 0xfffa, 0x0124},
2881 {0, 0xfff9, 0x0124},
2882 {0, 0x0086, 0x0127},
2883 {0, 0xfff8, 0x0124},
2884 {0, 0xfffd, 0x0124},
2885 {0, 0x0038, 0x0127},
2886 {0, 0xfff8, 0x0124},
2887 {0, 0xfffd, 0x0124},
2888 {0, 0x0000, 0x0127},
2889 {0, 0xfff8, 0x0124},
2890 {0, 0xfffd, 0x0124},
2891 {0, 0x000e, 0x0127},
2892 {0, 0xfff8, 0x0124},
2893 {0, 0xfffd, 0x0124},
2894 {0, 0xfffa, 0x0124},
2895 {0, 0xfff9, 0x0124},
2896 {0, 0x0086, 0x0127},
2897 {0, 0xfff8, 0x0124},
2898 {0, 0xfffd, 0x0124},
2899 {0, 0x0037, 0x0127},
2900 {0, 0xfff8, 0x0124},
2901 {0, 0xfffd, 0x0124},
2902 {0, 0x0001, 0x0127},
2903 {0, 0xfff8, 0x0124},
2904 {0, 0xfffd, 0x0124},
2905 {0, 0x002b, 0x0127},
2906 {0, 0xfff8, 0x0124},
2907 {0, 0xfffd, 0x0124},
2908 {0, 0xfffa, 0x0124},
2909 {0, 0xfff9, 0x0124},
2910 {0, 0x0086, 0x0127},
2911 {0, 0xfff8, 0x0124},
2912 {0, 0xfffd, 0x0124},
2913 {0, 0x0038, 0x0127},
2914 {0, 0xfff8, 0x0124},
2915 {0, 0xfffd, 0x0124},
2916 {0, 0x0001, 0x0127},
2917 {0, 0xfff8, 0x0124},
2918 {0, 0xfffd, 0x0124},
2919 {0, 0x00f4, 0x0127},
2920 {0, 0xfff8, 0x0124},
2921 {0, 0xfffd, 0x0124},
2922 {0, 0xfffa, 0x0124},
2923 {0, 0xfff9, 0x0124},
2924 {0, 0x0086, 0x0127},
2925 {0, 0xfff8, 0x0124},
2926 {0, 0xfffd, 0x0124},
2927 {0, 0x0037, 0x0127},
2928 {0, 0xfff8, 0x0124},
2929 {0, 0xfffd, 0x0124},
2930 {0, 0x0001, 0x0127},
2931 {0, 0xfff8, 0x0124},
2932 {0, 0xfffd, 0x0124},
2933 {0, 0x002c, 0x0127},
2934 {0, 0xfff8, 0x0124},
2935 {0, 0xfffd, 0x0124},
2936 {0, 0xfffa, 0x0124},
2937 {0, 0xfff9, 0x0124},
2938 {0, 0x0086, 0x0127},
2939 {0, 0xfff8, 0x0124},
2940 {0, 0xfffd, 0x0124},
2941 {0, 0x0038, 0x0127},
2942 {0, 0xfff8, 0x0124},
2943 {0, 0xfffd, 0x0124},
2944 {0, 0x0001, 0x0127},
2945 {0, 0xfff8, 0x0124},
2946 {0, 0xfffd, 0x0124},
2947 {0, 0x0004, 0x0127},
2948 {0, 0xfff8, 0x0124},
2949 {0, 0xfffd, 0x0124},
2950 {0, 0xfffa, 0x0124},
2951 {0, 0xfff9, 0x0124},
2952 {0, 0x0086, 0x0127},
2953 {0, 0xfff8, 0x0124},
2954 {0, 0xfffd, 0x0124},
2955 {0, 0x0037, 0x0127},
2956 {0, 0xfff8, 0x0124},
2957 {0, 0xfffd, 0x0124},
2958 {0, 0x0001, 0x0127},
2959 {0, 0xfff8, 0x0124},
2960 {0, 0xfffd, 0x0124},
2961 {0, 0x002d, 0x0127},
2962 {0, 0xfff8, 0x0124},
2963 {0, 0xfffd, 0x0124},
2964 {0, 0xfffa, 0x0124},
2965 {0, 0xfff9, 0x0124},
2966 {0, 0x0086, 0x0127},
2967 {0, 0xfff8, 0x0124},
2968 {0, 0xfffd, 0x0124},
2969 {0, 0x0038, 0x0127},
2970 {0, 0xfff8, 0x0124},
2971 {0, 0xfffd, 0x0124},
2972 {0, 0x0000, 0x0127},
2973 {0, 0xfff8, 0x0124},
2974 {0, 0xfffd, 0x0124},
2975 {0, 0x0014, 0x0127},
2976 {0, 0xfff8, 0x0124},
2977 {0, 0xfffd, 0x0124},
2978 {0, 0xfffa, 0x0124},
2979 {0, 0xfff9, 0x0124},
2980 {0, 0x0086, 0x0127},
2981 {0, 0xfff8, 0x0124},
2982 {0, 0xfffd, 0x0124},
2983 {0, 0x0037, 0x0127},
2984 {0, 0xfff8, 0x0124},
2985 {0, 0xfffd, 0x0124},
2986 {0, 0x0001, 0x0127},
2987 {0, 0xfff8, 0x0124},
2988 {0, 0xfffd, 0x0124},
2989 {0, 0x002e, 0x0127},
2990 {0, 0xfff8, 0x0124},
2991 {0, 0xfffd, 0x0124},
2992 {0, 0xfffa, 0x0124},
2993 {0, 0xfff9, 0x0124},
2994 {0, 0x0086, 0x0127},
2995 {0, 0xfff8, 0x0124},
2996 {0, 0xfffd, 0x0124},
2997 {0, 0x0038, 0x0127},
2998 {0, 0xfff8, 0x0124},
2999 {0, 0xfffd, 0x0124},
3000 {0, 0x0003, 0x0127},
3001 {0, 0xfff8, 0x0124},
3002 {0, 0xfffd, 0x0124},
3003 {0, 0x0000, 0x0127},
3004 {0, 0xfff8, 0x0124},
3005 {0, 0xfffd, 0x0124},
3006 {0, 0xfffa, 0x0124},
3007 {0, 0xfff9, 0x0124},
3008 {0, 0x0086, 0x0127},
3009 {0, 0xfff8, 0x0124},
3010 {0, 0xfffd, 0x0124},
3011 {0, 0x0037, 0x0127},
3012 {0, 0xfff8, 0x0124},
3013 {0, 0xfffd, 0x0124},
3014 {0, 0x0001, 0x0127},
3015 {0, 0xfff8, 0x0124},
3016 {0, 0xfffd, 0x0124},
3017 {0, 0x002f, 0x0127},
3018 {0, 0xfff8, 0x0124},
3019 {0, 0xfffd, 0x0124},
3020 {0, 0xfffa, 0x0124},
3021 {0, 0xfff9, 0x0124},
3022 {0, 0x0086, 0x0127},
3023 {0, 0xfff8, 0x0124},
3024 {0, 0xfffd, 0x0124},
3025 {0, 0x0038, 0x0127},
3026 {0, 0xfff8, 0x0124},
3027 {0, 0xfffd, 0x0124},
3028 {0, 0x0003, 0x0127},
3029 {0, 0xfff8, 0x0124},
3030 {0, 0xfffd, 0x0124},
3031 {0, 0x0014, 0x0127},
3032 {0, 0xfff8, 0x0124},
3033 {0, 0xfffd, 0x0124},
3034 {0, 0xfffa, 0x0124},
3035 {0, 0xfff9, 0x0124},
3036 {0, 0x0086, 0x0127},
3037 {0, 0xfff8, 0x0124},
3038 {0, 0xfffd, 0x0124},
3039 {0, 0x0037, 0x0127},
3040 {0, 0xfff8, 0x0124},
3041 {0, 0xfffd, 0x0124},
3042 {0, 0x0001, 0x0127},
3043 {0, 0xfff8, 0x0124},
3044 {0, 0xfffd, 0x0124},
3045 {0, 0x0040, 0x0127},
3046 {0, 0xfff8, 0x0124},
3047 {0, 0xfffd, 0x0124},
3048 {0, 0xfffa, 0x0124},
3049 {0, 0xfff9, 0x0124},
3050 {0, 0x0086, 0x0127},
3051 {0, 0xfff8, 0x0124},
3052 {0, 0xfffd, 0x0124},
3053 {0, 0x0038, 0x0127},
3054 {0, 0xfff8, 0x0124},
3055 {0, 0xfffd, 0x0124},
3056 {0, 0x0000, 0x0127},
3057 {0, 0xfff8, 0x0124},
3058 {0, 0xfffd, 0x0124},
3059 {0, 0x0040, 0x0127},
3060 {0, 0xfff8, 0x0124},
3061 {0, 0xfffd, 0x0124},
3062 {0, 0xfffa, 0x0124},
3063 {0, 0xfff9, 0x0124},
3064 {0, 0x0086, 0x0127},
3065 {0, 0xfff8, 0x0124},
3066 {0, 0xfffd, 0x0124},
3067 {0, 0x0037, 0x0127},
3068 {0, 0xfff8, 0x0124},
3069 {0, 0xfffd, 0x0124},
3070 {0, 0x0001, 0x0127},
3071 {0, 0xfff8, 0x0124},
3072 {0, 0xfffd, 0x0124},
3073 {0, 0x0053, 0x0127},
3074 {0, 0xfff8, 0x0124},
3075 {0, 0xfffd, 0x0124},
3076 {0, 0xfffa, 0x0124},
3077 {0, 0xfff9, 0x0124},
3078 {0, 0x0086, 0x0127},
3079 {0, 0xfff8, 0x0124},
3080 {0, 0xfffd, 0x0124},
3081 {0, 0x0038, 0x0127},
3082 {0, 0xfff8, 0x0124},
3083 {0, 0xfffd, 0x0124},
3084 {0, 0x0000, 0x0127},
3085 {0, 0xfff8, 0x0124},
3086 {0, 0xfffd, 0x0124},
3087 {0, 0x0038, 0x0127},
3088 {0, 0xfff8, 0x0124},
3089 {0, 0xfffd, 0x0124},
3090 {0, 0xfffa, 0x0124},
3091 {0, 0x0000, 0x0101},
3092 {0, 0x00a0, 0x0103},
3093 {0, 0x0078, 0x0105},
3094 {0, 0x0000, 0x010a},
3095 {0, 0x0024, 0x010b},
3096 {0, 0x0028, 0x0119},
3097 {0, 0x0088, 0x011b},
3098 {0, 0x0002, 0x011d},
3099 {0, 0x0003, 0x011e},
3100 {0, 0x0000, 0x0129},
3101 {0, 0x00fc, 0x012b},
3102 {0, 0x0008, 0x0102},
3103 {0, 0x0000, 0x0104},
3104 {0, 0x0008, 0x011a},
3105 {0, 0x0028, 0x011c},
3106 {0, 0x0021, 0x012a},
3107 {0, 0x0000, 0x0118},
3108 {0, 0x0000, 0x0132},
3109 {0, 0x0000, 0x0109},
3110 {0, 0xfff9, 0x0124},
3111 {0, 0x0086, 0x0127},
3112 {0, 0xfff8, 0x0124},
3113 {0, 0xfffd, 0x0124},
3114 {0, 0x0037, 0x0127},
3115 {0, 0xfff8, 0x0124},
3116 {0, 0xfffd, 0x0124},
3117 {0, 0x0001, 0x0127},
3118 {0, 0xfff8, 0x0124},
3119 {0, 0xfffd, 0x0124},
3120 {0, 0x0031, 0x0127},
3121 {0, 0xfff8, 0x0124},
3122 {0, 0xfffd, 0x0124},
3123 {0, 0xfffa, 0x0124},
3124 {0, 0xfff9, 0x0124},
3125 {0, 0x0086, 0x0127},
3126 {0, 0xfff8, 0x0124},
3127 {0, 0xfffd, 0x0124},
3128 {0, 0x0038, 0x0127},
3129 {0, 0xfff8, 0x0124},
3130 {0, 0xfffd, 0x0124},
3131 {0, 0x0000, 0x0127},
3132 {0, 0xfff8, 0x0124},
3133 {0, 0xfffd, 0x0124},
3134 {0, 0x0000, 0x0127},
3135 {0, 0xfff8, 0x0124},
3136 {0, 0xfffd, 0x0124},
3137 {0, 0xfffa, 0x0124},
3138 {0, 0xfff9, 0x0124},
3139 {0, 0x0086, 0x0127},
3140 {0, 0xfff8, 0x0124},
3141 {0, 0xfffd, 0x0124},
3142 {0, 0x0037, 0x0127},
3143 {0, 0xfff8, 0x0124},
3144 {0, 0xfffd, 0x0124},
3145 {0, 0x0001, 0x0127},
3146 {0, 0xfff8, 0x0124},
3147 {0, 0xfffd, 0x0124},
3148 {0, 0x0040, 0x0127},
3149 {0, 0xfff8, 0x0124},
3150 {0, 0xfffd, 0x0124},
3151 {0, 0xfffa, 0x0124},
3152 {0, 0xfff9, 0x0124},
3153 {0, 0x0086, 0x0127},
3154 {0, 0xfff8, 0x0124},
3155 {0, 0xfffd, 0x0124},
3156 {0, 0x0038, 0x0127},
3157 {0, 0xfff8, 0x0124},
3158 {0, 0xfffd, 0x0124},
3159 {0, 0x0000, 0x0127},
3160 {0, 0xfff8, 0x0124},
3161 {0, 0xfffd, 0x0124},
3162 {0, 0x0040, 0x0127},
3163 {0, 0xfff8, 0x0124},
3164 {0, 0xfffd, 0x0124},
3165 {0, 0xfffa, 0x0124},
3166 {0, 0xfff9, 0x0124},
3167 {0, 0x0086, 0x0127},
3168 {0, 0xfff8, 0x0124},
3169 {0, 0xfffd, 0x0124},
3170 {0, 0x0037, 0x0127},
3171 {0, 0xfff8, 0x0124},
3172 {0, 0xfffd, 0x0124},
3173 {0, 0x0000, 0x0127},
3174 {0, 0xfff8, 0x0124},
3175 {0, 0xfffd, 0x0124},
3176 {0, 0x00dc, 0x0127},
3177 {0, 0xfff8, 0x0124},
3178 {0, 0xfffd, 0x0124},
3179 {0, 0xfffa, 0x0124},
3180 {0, 0xfff9, 0x0124},
3181 {0, 0x0086, 0x0127},
3182 {0, 0xfff8, 0x0124},
3183 {0, 0xfffd, 0x0124},
3184 {0, 0x0038, 0x0127},
3185 {0, 0xfff8, 0x0124},
3186 {0, 0xfffd, 0x0124},
3187 {0, 0x0000, 0x0127},
3188 {0, 0xfff8, 0x0124},
3189 {0, 0xfffd, 0x0124},
3190 {0, 0x0000, 0x0127},
3191 {0, 0xfff8, 0x0124},
3192 {0, 0xfffd, 0x0124},
3193 {0, 0xfffa, 0x0124},
3194 {0, 0xfff9, 0x0124},
3195 {0, 0x0086, 0x0127},
3196 {0, 0xfff8, 0x0124},
3197 {0, 0xfffd, 0x0124},
3198 {0, 0x0037, 0x0127},
3199 {0, 0xfff8, 0x0124},
3200 {0, 0xfffd, 0x0124},
3201 {0, 0x0001, 0x0127},
3202 {0, 0xfff8, 0x0124},
3203 {0, 0xfffd, 0x0124},
3204 {0, 0x0032, 0x0127},
3205 {0, 0xfff8, 0x0124},
3206 {0, 0xfffd, 0x0124},
3207 {0, 0xfffa, 0x0124},
3208 {0, 0xfff9, 0x0124},
3209 {0, 0x0086, 0x0127},
3210 {0, 0xfff8, 0x0124},
3211 {0, 0xfffd, 0x0124},
3212 {0, 0x0038, 0x0127},
3213 {0, 0xfff8, 0x0124},
3214 {0, 0xfffd, 0x0124},
3215 {0, 0x0001, 0x0127},
3216 {0, 0xfff8, 0x0124},
3217 {0, 0xfffd, 0x0124},
3218 {0, 0x0020, 0x0127},
3219 {0, 0xfff8, 0x0124},
3220 {0, 0xfffd, 0x0124},
3221 {0, 0xfffa, 0x0124},
3222 {0, 0xfff9, 0x0124},
3223 {0, 0x0086, 0x0127},
3224 {0, 0xfff8, 0x0124},
3225 {0, 0xfffd, 0x0124},
3226 {0, 0x0037, 0x0127},
3227 {0, 0xfff8, 0x0124},
3228 {0, 0xfffd, 0x0124},
3229 {0, 0x0001, 0x0127},
3230 {0, 0xfff8, 0x0124},
3231 {0, 0xfffd, 0x0124},
3232 {0, 0x0040, 0x0127},
3233 {0, 0xfff8, 0x0124},
3234 {0, 0xfffd, 0x0124},
3235 {0, 0xfffa, 0x0124},
3236 {0, 0xfff9, 0x0124},
3237 {0, 0x0086, 0x0127},
3238 {0, 0xfff8, 0x0124},
3239 {0, 0xfffd, 0x0124},
3240 {0, 0x0038, 0x0127},
3241 {0, 0xfff8, 0x0124},
3242 {0, 0xfffd, 0x0124},
3243 {0, 0x0000, 0x0127},
3244 {0, 0xfff8, 0x0124},
3245 {0, 0xfffd, 0x0124},
3246 {0, 0x0040, 0x0127},
3247 {0, 0xfff8, 0x0124},
3248 {0, 0xfffd, 0x0124},
3249 {0, 0xfffa, 0x0124},
3250 {0, 0xfff9, 0x0124},
3251 {0, 0x0086, 0x0127},
3252 {0, 0xfff8, 0x0124},
3253 {0, 0xfffd, 0x0124},
3254 {0, 0x0037, 0x0127},
3255 {0, 0xfff8, 0x0124},
3256 {0, 0xfffd, 0x0124},
3257 {0, 0x0000, 0x0127},
3258 {0, 0xfff8, 0x0124},
3259 {0, 0xfffd, 0x0124},
3260 {0, 0x0030, 0x0127},
3261 {0, 0xfff8, 0x0124},
3262 {0, 0xfffd, 0x0124},
3263 {0, 0xfffa, 0x0124},
3264 {0, 0xfff9, 0x0124},
3265 {0, 0x0086, 0x0127},
3266 {0, 0xfff8, 0x0124},
3267 {0, 0xfffd, 0x0124},
3268 {0, 0x0038, 0x0127},
3269 {0, 0xfff8, 0x0124},
3270 {0, 0xfffd, 0x0124},
3271 {0, 0x0008, 0x0127},
3272 {0, 0xfff8, 0x0124},
3273 {0, 0xfffd, 0x0124},
3274 {0, 0x0000, 0x0127},
3275 {0, 0xfff8, 0x0124},
3276 {0, 0xfffd, 0x0124},
3277 {0, 0xfffa, 0x0124},
3278 {0, 0x0003, 0x0106},
3279 {0, 0x0062, 0x0107},
3280 {0, 0x0003, 0x0111},
3281 };
3282#define NUM_INIT_DATA
3283
3284 unsigned short compression = 0; /* 0=none, 7=best frame rate */
3285 int f_rate; /* 0=Fastest 7=slowest */
3286
3287 if (IBMCAM_T(uvd)->initialized)
3288 return;
3289
3290 /* Internal frame rate is controlled by f_rate value */
3291 f_rate = 7 - framerate;
3292 RESTRICT_TO_RANGE(f_rate, 0, 7);
3293
3294 ibmcam_veio(uvd, 0, 0x0000, 0x0100);
3295 ibmcam_veio(uvd, 1, 0x0000, 0x0116);
3296 ibmcam_veio(uvd, 0, 0x0060, 0x0116);
3297 ibmcam_veio(uvd, 0, 0x0002, 0x0112);
3298 ibmcam_veio(uvd, 0, 0x0000, 0x0123);
3299 ibmcam_veio(uvd, 0, 0x0001, 0x0117);
3300 ibmcam_veio(uvd, 0, 0x0040, 0x0108);
3301 ibmcam_veio(uvd, 0, 0x0019, 0x012c);
3302 ibmcam_veio(uvd, 0, 0x0060, 0x0116);
3303 ibmcam_veio(uvd, 0, 0x0002, 0x0115);
3304 ibmcam_veio(uvd, 0, 0x0003, 0x0115);
3305 ibmcam_veio(uvd, 1, 0x0000, 0x0115);
3306 ibmcam_veio(uvd, 0, 0x000b, 0x0115);
3307 ibmcam_model3_Packet1(uvd, 0x000a, 0x0040);
3308 ibmcam_model3_Packet1(uvd, 0x000b, 0x00f6);
3309 ibmcam_model3_Packet1(uvd, 0x000c, 0x0002);
3310 ibmcam_model3_Packet1(uvd, 0x000d, 0x0020);
3311 ibmcam_model3_Packet1(uvd, 0x000e, 0x0033);
3312 ibmcam_model3_Packet1(uvd, 0x000f, 0x0007);
3313 ibmcam_model3_Packet1(uvd, 0x0010, 0x0000);
3314 ibmcam_model3_Packet1(uvd, 0x0011, 0x0070);
3315 ibmcam_model3_Packet1(uvd, 0x0012, 0x0030);
3316 ibmcam_model3_Packet1(uvd, 0x0013, 0x0000);
3317 ibmcam_model3_Packet1(uvd, 0x0014, 0x0001);
3318 ibmcam_model3_Packet1(uvd, 0x0015, 0x0001);
3319 ibmcam_model3_Packet1(uvd, 0x0016, 0x0001);
3320 ibmcam_model3_Packet1(uvd, 0x0017, 0x0001);
3321 ibmcam_model3_Packet1(uvd, 0x0018, 0x0000);
3322 ibmcam_model3_Packet1(uvd, 0x001e, 0x00c3);
3323 ibmcam_model3_Packet1(uvd, 0x0020, 0x0000);
3324 ibmcam_model3_Packet1(uvd, 0x0028, 0x0010);
3325 ibmcam_model3_Packet1(uvd, 0x0029, 0x0054);
3326 ibmcam_model3_Packet1(uvd, 0x002a, 0x0013);
3327 ibmcam_model3_Packet1(uvd, 0x002b, 0x0007);
3328 ibmcam_model3_Packet1(uvd, 0x002d, 0x0028);
3329 ibmcam_model3_Packet1(uvd, 0x002e, 0x0000);
3330 ibmcam_model3_Packet1(uvd, 0x0031, 0x0000);
3331 ibmcam_model3_Packet1(uvd, 0x0032, 0x0000);
3332 ibmcam_model3_Packet1(uvd, 0x0033, 0x0000);
3333 ibmcam_model3_Packet1(uvd, 0x0034, 0x0000);
3334 ibmcam_model3_Packet1(uvd, 0x0035, 0x0038);
3335 ibmcam_model3_Packet1(uvd, 0x003a, 0x0001);
3336 ibmcam_model3_Packet1(uvd, 0x003c, 0x001e);
3337 ibmcam_model3_Packet1(uvd, 0x003f, 0x000a);
3338 ibmcam_model3_Packet1(uvd, 0x0041, 0x0000);
3339 ibmcam_model3_Packet1(uvd, 0x0046, 0x003f);
3340 ibmcam_model3_Packet1(uvd, 0x0047, 0x0000);
3341 ibmcam_model3_Packet1(uvd, 0x0050, 0x0005);
3342 ibmcam_model3_Packet1(uvd, 0x0052, 0x001a);
3343 ibmcam_model3_Packet1(uvd, 0x0053, 0x0003);
3344 ibmcam_model3_Packet1(uvd, 0x005a, 0x006b);
3345 ibmcam_model3_Packet1(uvd, 0x005d, 0x001e);
3346 ibmcam_model3_Packet1(uvd, 0x005e, 0x0030);
3347 ibmcam_model3_Packet1(uvd, 0x005f, 0x0041);
3348 ibmcam_model3_Packet1(uvd, 0x0064, 0x0008);
3349 ibmcam_model3_Packet1(uvd, 0x0065, 0x0015);
3350 ibmcam_model3_Packet1(uvd, 0x0068, 0x000f);
3351 ibmcam_model3_Packet1(uvd, 0x0079, 0x0000);
3352 ibmcam_model3_Packet1(uvd, 0x007a, 0x0000);
3353 ibmcam_model3_Packet1(uvd, 0x007c, 0x003f);
3354 ibmcam_model3_Packet1(uvd, 0x0082, 0x000f);
3355 ibmcam_model3_Packet1(uvd, 0x0085, 0x0000);
3356 ibmcam_model3_Packet1(uvd, 0x0099, 0x0000);
3357 ibmcam_model3_Packet1(uvd, 0x009b, 0x0023);
3358 ibmcam_model3_Packet1(uvd, 0x009c, 0x0022);
3359 ibmcam_model3_Packet1(uvd, 0x009d, 0x0096);
3360 ibmcam_model3_Packet1(uvd, 0x009e, 0x0096);
3361 ibmcam_model3_Packet1(uvd, 0x009f, 0x000a);
3362
3363 switch (uvd->videosize) {
3364 case VIDEOSIZE_160x120:
3365 ibmcam_veio(uvd, 0, 0x0000, 0x0101); /* Same on 176x144, 320x240 */
3366 ibmcam_veio(uvd, 0, 0x00a0, 0x0103); /* Same on 176x144, 320x240 */
3367 ibmcam_veio(uvd, 0, 0x0078, 0x0105); /* Same on 176x144, 320x240 */
3368 ibmcam_veio(uvd, 0, 0x0000, 0x010a); /* Same */
3369 ibmcam_veio(uvd, 0, 0x0024, 0x010b); /* Differs everywhere */
3370 ibmcam_veio(uvd, 0, 0x00a9, 0x0119);
3371 ibmcam_veio(uvd, 0, 0x0016, 0x011b);
3372 ibmcam_veio(uvd, 0, 0x0002, 0x011d); /* Same on 176x144, 320x240 */
3373 ibmcam_veio(uvd, 0, 0x0003, 0x011e); /* Same on 176x144, 640x480 */
3374 ibmcam_veio(uvd, 0, 0x0000, 0x0129); /* Same */
3375 ibmcam_veio(uvd, 0, 0x00fc, 0x012b); /* Same */
3376 ibmcam_veio(uvd, 0, 0x0018, 0x0102);
3377 ibmcam_veio(uvd, 0, 0x0004, 0x0104);
3378 ibmcam_veio(uvd, 0, 0x0004, 0x011a);
3379 ibmcam_veio(uvd, 0, 0x0028, 0x011c);
3380 ibmcam_veio(uvd, 0, 0x0022, 0x012a); /* Same */
3381 ibmcam_veio(uvd, 0, 0x0000, 0x0118);
3382 ibmcam_veio(uvd, 0, 0x0000, 0x0132);
3383 ibmcam_model3_Packet1(uvd, 0x0021, 0x0001); /* Same */
3384 ibmcam_veio(uvd, 0, compression, 0x0109);
3385 break;
3386 case VIDEOSIZE_320x240:
3387 ibmcam_veio(uvd, 0, 0x0000, 0x0101); /* Same on 176x144, 320x240 */
3388 ibmcam_veio(uvd, 0, 0x00a0, 0x0103); /* Same on 176x144, 320x240 */
3389 ibmcam_veio(uvd, 0, 0x0078, 0x0105); /* Same on 176x144, 320x240 */
3390 ibmcam_veio(uvd, 0, 0x0000, 0x010a); /* Same */
3391 ibmcam_veio(uvd, 0, 0x0028, 0x010b); /* Differs everywhere */
3392 ibmcam_veio(uvd, 0, 0x0002, 0x011d); /* Same */
3393 ibmcam_veio(uvd, 0, 0x0000, 0x011e);
3394 ibmcam_veio(uvd, 0, 0x0000, 0x0129); /* Same */
3395 ibmcam_veio(uvd, 0, 0x00fc, 0x012b); /* Same */
3396 /* 4 commands from 160x120 skipped */
3397 ibmcam_veio(uvd, 0, 0x0022, 0x012a); /* Same */
3398 ibmcam_model3_Packet1(uvd, 0x0021, 0x0001); /* Same */
3399 ibmcam_veio(uvd, 0, compression, 0x0109);
3400 ibmcam_veio(uvd, 0, 0x00d9, 0x0119);
3401 ibmcam_veio(uvd, 0, 0x0006, 0x011b);
3402 ibmcam_veio(uvd, 0, 0x0021, 0x0102); /* Same on 320x240, 640x480 */
3403 ibmcam_veio(uvd, 0, 0x0010, 0x0104);
3404 ibmcam_veio(uvd, 0, 0x0004, 0x011a);
3405 ibmcam_veio(uvd, 0, 0x003f, 0x011c);
3406 ibmcam_veio(uvd, 0, 0x001c, 0x0118);
3407 ibmcam_veio(uvd, 0, 0x0000, 0x0132);
3408 break;
3409 case VIDEOSIZE_640x480:
3410 ibmcam_veio(uvd, 0, 0x00f0, 0x0105);
3411 ibmcam_veio(uvd, 0, 0x0000, 0x010a); /* Same */
3412 ibmcam_veio(uvd, 0, 0x0038, 0x010b); /* Differs everywhere */
3413 ibmcam_veio(uvd, 0, 0x00d9, 0x0119); /* Same on 320x240, 640x480 */
3414 ibmcam_veio(uvd, 0, 0x0006, 0x011b); /* Same on 320x240, 640x480 */
3415 ibmcam_veio(uvd, 0, 0x0004, 0x011d); /* NC */
3416 ibmcam_veio(uvd, 0, 0x0003, 0x011e); /* Same on 176x144, 640x480 */
3417 ibmcam_veio(uvd, 0, 0x0000, 0x0129); /* Same */
3418 ibmcam_veio(uvd, 0, 0x00fc, 0x012b); /* Same */
3419 ibmcam_veio(uvd, 0, 0x0021, 0x0102); /* Same on 320x240, 640x480 */
3420 ibmcam_veio(uvd, 0, 0x0016, 0x0104); /* NC */
3421 ibmcam_veio(uvd, 0, 0x0004, 0x011a); /* Same on 320x240, 640x480 */
3422 ibmcam_veio(uvd, 0, 0x003f, 0x011c); /* Same on 320x240, 640x480 */
3423 ibmcam_veio(uvd, 0, 0x0022, 0x012a); /* Same */
3424 ibmcam_veio(uvd, 0, 0x001c, 0x0118); /* Same on 320x240, 640x480 */
3425 ibmcam_model3_Packet1(uvd, 0x0021, 0x0001); /* Same */
3426 ibmcam_veio(uvd, 0, compression, 0x0109);
3427 ibmcam_veio(uvd, 0, 0x0040, 0x0101);
3428 ibmcam_veio(uvd, 0, 0x0040, 0x0103);
3429 ibmcam_veio(uvd, 0, 0x0000, 0x0132); /* Same on 320x240, 640x480 */
3430 break;
3431 }
3432 ibmcam_model3_Packet1(uvd, 0x007e, 0x000e); /* Hue */
3433 ibmcam_model3_Packet1(uvd, 0x0036, 0x0011); /* Brightness */
3434 ibmcam_model3_Packet1(uvd, 0x0060, 0x0002); /* Sharpness */
3435 ibmcam_model3_Packet1(uvd, 0x0061, 0x0004); /* Sharpness */
3436 ibmcam_model3_Packet1(uvd, 0x0062, 0x0005); /* Sharpness */
3437 ibmcam_model3_Packet1(uvd, 0x0063, 0x0014); /* Sharpness */
3438 ibmcam_model3_Packet1(uvd, 0x0096, 0x00a0); /* Red gain */
3439 ibmcam_model3_Packet1(uvd, 0x0097, 0x0096); /* Blue gain */
3440 ibmcam_model3_Packet1(uvd, 0x0067, 0x0001); /* Contrast */
3441 ibmcam_model3_Packet1(uvd, 0x005b, 0x000c); /* Contrast */
3442 ibmcam_model3_Packet1(uvd, 0x005c, 0x0016); /* Contrast */
3443 ibmcam_model3_Packet1(uvd, 0x0098, 0x000b);
3444 ibmcam_model3_Packet1(uvd, 0x002c, 0x0003); /* Was 1, broke 640x480 */
3445 ibmcam_model3_Packet1(uvd, 0x002f, 0x002a);
3446 ibmcam_model3_Packet1(uvd, 0x0030, 0x0029);
3447 ibmcam_model3_Packet1(uvd, 0x0037, 0x0002);
3448 ibmcam_model3_Packet1(uvd, 0x0038, 0x0059);
3449 ibmcam_model3_Packet1(uvd, 0x003d, 0x002e);
3450 ibmcam_model3_Packet1(uvd, 0x003e, 0x0028);
3451 ibmcam_model3_Packet1(uvd, 0x0078, 0x0005);
3452 ibmcam_model3_Packet1(uvd, 0x007b, 0x0011);
3453 ibmcam_model3_Packet1(uvd, 0x007d, 0x004b);
3454 ibmcam_model3_Packet1(uvd, 0x007f, 0x0022);
3455 ibmcam_model3_Packet1(uvd, 0x0080, 0x000c);
3456 ibmcam_model3_Packet1(uvd, 0x0081, 0x000b);
3457 ibmcam_model3_Packet1(uvd, 0x0083, 0x00fd);
3458 ibmcam_model3_Packet1(uvd, 0x0086, 0x000b);
3459 ibmcam_model3_Packet1(uvd, 0x0087, 0x000b);
3460 ibmcam_model3_Packet1(uvd, 0x007e, 0x000e);
3461 ibmcam_model3_Packet1(uvd, 0x0096, 0x00a0); /* Red gain */
3462 ibmcam_model3_Packet1(uvd, 0x0097, 0x0096); /* Blue gain */
3463 ibmcam_model3_Packet1(uvd, 0x0098, 0x000b);
3464
3465 switch (uvd->videosize) {
3466 case VIDEOSIZE_160x120:
3467 ibmcam_veio(uvd, 0, 0x0002, 0x0106);
3468 ibmcam_veio(uvd, 0, 0x0008, 0x0107);
3469 ibmcam_veio(uvd, 0, f_rate, 0x0111); /* Frame rate */
3470 ibmcam_model3_Packet1(uvd, 0x001f, 0x0000); /* Same */
3471 ibmcam_model3_Packet1(uvd, 0x0039, 0x001f); /* Same */
3472 ibmcam_model3_Packet1(uvd, 0x003b, 0x003c); /* Same */
3473 ibmcam_model3_Packet1(uvd, 0x0040, 0x000a);
3474 ibmcam_model3_Packet1(uvd, 0x0051, 0x000a);
3475 break;
3476 case VIDEOSIZE_320x240:
3477 ibmcam_veio(uvd, 0, 0x0003, 0x0106);
3478 ibmcam_veio(uvd, 0, 0x0062, 0x0107);
3479 ibmcam_veio(uvd, 0, f_rate, 0x0111); /* Frame rate */
3480 ibmcam_model3_Packet1(uvd, 0x001f, 0x0000); /* Same */
3481 ibmcam_model3_Packet1(uvd, 0x0039, 0x001f); /* Same */
3482 ibmcam_model3_Packet1(uvd, 0x003b, 0x003c); /* Same */
3483 ibmcam_model3_Packet1(uvd, 0x0040, 0x0008);
3484 ibmcam_model3_Packet1(uvd, 0x0051, 0x000b);
3485 break;
3486 case VIDEOSIZE_640x480:
3487 ibmcam_veio(uvd, 0, 0x0002, 0x0106); /* Adjustments */
3488 ibmcam_veio(uvd, 0, 0x00b4, 0x0107); /* Adjustments */
3489 ibmcam_veio(uvd, 0, f_rate, 0x0111); /* Frame rate */
3490 ibmcam_model3_Packet1(uvd, 0x001f, 0x0002); /* !Same */
3491 ibmcam_model3_Packet1(uvd, 0x0039, 0x003e); /* !Same */
3492 ibmcam_model3_Packet1(uvd, 0x0040, 0x0008);
3493 ibmcam_model3_Packet1(uvd, 0x0051, 0x000a);
3494 break;
3495 }
3496
3497 /* 01.01.08 - Added for RCA video in support -LO */
3498 if(init_model3_input) {
3499 if (debug > 0)
3500 dev_info(&uvd->dev->dev, "Setting input to RCA.\n");
3501 for (i=0; i < ARRAY_SIZE(initData); i++) {
3502 ibmcam_veio(uvd, initData[i].req, initData[i].value, initData[i].index);
3503 }
3504 }
3505
3506 ibmcam_veio(uvd, 0, 0x0001, 0x0114);
3507 ibmcam_veio(uvd, 0, 0x00c0, 0x010c);
3508 usb_clear_halt(uvd->dev, usb_rcvisocpipe(uvd->dev, uvd->video_endp));
3509}
3510
3511/*
3512 * ibmcam_video_stop()
3513 *
3514 * This code tells camera to stop streaming. The interface remains
3515 * configured and bandwidth - claimed.
3516 */
3517static void ibmcam_video_stop(struct uvd *uvd)
3518{
3519 switch (IBMCAM_T(uvd)->camera_model) {
3520 case IBMCAM_MODEL_1:
3521 ibmcam_veio(uvd, 0, 0x00, 0x010c);
3522 ibmcam_veio(uvd, 0, 0x00, 0x010c);
3523 ibmcam_veio(uvd, 0, 0x01, 0x0114);
3524 ibmcam_veio(uvd, 0, 0xc0, 0x010c);
3525 ibmcam_veio(uvd, 0, 0x00, 0x010c);
3526 ibmcam_send_FF_04_02(uvd);
3527 ibmcam_veio(uvd, 1, 0x00, 0x0100);
3528 ibmcam_veio(uvd, 0, 0x81, 0x0100); /* LED Off */
3529 break;
3530 case IBMCAM_MODEL_2:
3531case IBMCAM_MODEL_4:
3532 ibmcam_veio(uvd, 0, 0x0000, 0x010c); /* Stop the camera */
3533
3534 ibmcam_model2_Packet1(uvd, 0x0030, 0x0004);
3535
3536 ibmcam_veio(uvd, 0, 0x0080, 0x0100); /* LED Off */
3537 ibmcam_veio(uvd, 0, 0x0020, 0x0111);
3538 ibmcam_veio(uvd, 0, 0x00a0, 0x0111);
3539
3540 ibmcam_model2_Packet1(uvd, 0x0030, 0x0002);
3541
3542 ibmcam_veio(uvd, 0, 0x0020, 0x0111);
3543 ibmcam_veio(uvd, 0, 0x0000, 0x0112);
3544 break;
3545 case IBMCAM_MODEL_3:
3546#if 1
3547 ibmcam_veio(uvd, 0, 0x0000, 0x010c);
3548
3549 /* Here we are supposed to select video interface alt. setting 0 */
3550 ibmcam_veio(uvd, 0, 0x0006, 0x012c);
3551
3552 ibmcam_model3_Packet1(uvd, 0x0046, 0x0000);
3553
3554 ibmcam_veio(uvd, 1, 0x0000, 0x0116);
3555 ibmcam_veio(uvd, 0, 0x0064, 0x0116);
3556 ibmcam_veio(uvd, 1, 0x0000, 0x0115);
3557 ibmcam_veio(uvd, 0, 0x0003, 0x0115);
3558 ibmcam_veio(uvd, 0, 0x0008, 0x0123);
3559 ibmcam_veio(uvd, 0, 0x0000, 0x0117);
3560 ibmcam_veio(uvd, 0, 0x0000, 0x0112);
3561 ibmcam_veio(uvd, 0, 0x0080, 0x0100);
3562 IBMCAM_T(uvd)->initialized = 0;
3563#endif
3564 break;
3565 } /* switch */
3566}
3567
3568/*
3569 * ibmcam_reinit_iso()
3570 *
3571 * This procedure sends couple of commands to the camera and then
3572 * resets the video pipe. This sequence was observed to reinit the
3573 * camera or, at least, to initiate ISO data stream.
3574 *
3575 * History:
3576 * 1/2/00 Created.
3577 */
3578static void ibmcam_reinit_iso(struct uvd *uvd, int do_stop)
3579{
3580 switch (IBMCAM_T(uvd)->camera_model) {
3581 case IBMCAM_MODEL_1:
3582 if (do_stop)
3583 ibmcam_video_stop(uvd);
3584 ibmcam_veio(uvd, 0, 0x0001, 0x0114);
3585 ibmcam_veio(uvd, 0, 0x00c0, 0x010c);
3586 usb_clear_halt(uvd->dev, usb_rcvisocpipe(uvd->dev, uvd->video_endp));
3587 ibmcam_model1_setup_after_video_if(uvd);
3588 break;
3589 case IBMCAM_MODEL_2:
3590 ibmcam_model2_setup_after_video_if(uvd);
3591 break;
3592 case IBMCAM_MODEL_3:
3593 ibmcam_video_stop(uvd);
3594 ibmcam_model3_setup_after_video_if(uvd);
3595 break;
3596 case IBMCAM_MODEL_4:
3597 ibmcam_model4_setup_after_video_if(uvd);
3598 break;
3599 }
3600}
3601
3602static void ibmcam_video_start(struct uvd *uvd)
3603{
3604 ibmcam_change_lighting_conditions(uvd);
3605 ibmcam_set_sharpness(uvd);
3606 ibmcam_reinit_iso(uvd, 0);
3607}
3608
3609/*
3610 * Return negative code on failure, 0 on success.
3611 */
3612static int ibmcam_setup_on_open(struct uvd *uvd)
3613{
3614 int setup_ok = 0; /* Success by default */
3615 /* Send init sequence only once, it's large! */
3616 if (!IBMCAM_T(uvd)->initialized) { /* FIXME rename */
3617 switch (IBMCAM_T(uvd)->camera_model) {
3618 case IBMCAM_MODEL_1:
3619 setup_ok = ibmcam_model1_setup(uvd);
3620 break;
3621 case IBMCAM_MODEL_2:
3622 setup_ok = ibmcam_model2_setup(uvd);
3623 break;
3624 case IBMCAM_MODEL_3:
3625 case IBMCAM_MODEL_4:
3626 /* We do all setup when Isoc stream is requested */
3627 break;
3628 }
3629 IBMCAM_T(uvd)->initialized = (setup_ok != 0);
3630 }
3631 return setup_ok;
3632}
3633
3634static void ibmcam_configure_video(struct uvd *uvd)
3635{
3636 if (uvd == NULL)
3637 return;
3638
3639 RESTRICT_TO_RANGE(init_brightness, 0, 255);
3640 RESTRICT_TO_RANGE(init_contrast, 0, 255);
3641 RESTRICT_TO_RANGE(init_color, 0, 255);
3642 RESTRICT_TO_RANGE(init_hue, 0, 255);
3643 RESTRICT_TO_RANGE(hue_correction, 0, 255);
3644
3645 memset(&uvd->vpic, 0, sizeof(uvd->vpic));
3646 memset(&uvd->vpic_old, 0x55, sizeof(uvd->vpic_old));
3647
3648 uvd->vpic.colour = init_color << 8;
3649 uvd->vpic.hue = init_hue << 8;
3650 uvd->vpic.brightness = init_brightness << 8;
3651 uvd->vpic.contrast = init_contrast << 8;
3652 uvd->vpic.whiteness = 105 << 8; /* This one isn't used */
3653 uvd->vpic.depth = 24;
3654 uvd->vpic.palette = VIDEO_PALETTE_RGB24;
3655
3656 memset(&uvd->vcap, 0, sizeof(uvd->vcap));
3657 strcpy(uvd->vcap.name, "IBM USB Camera");
3658 uvd->vcap.type = VID_TYPE_CAPTURE;
3659 uvd->vcap.channels = 1;
3660 uvd->vcap.audios = 0;
3661 uvd->vcap.maxwidth = VIDEOSIZE_X(uvd->canvas);
3662 uvd->vcap.maxheight = VIDEOSIZE_Y(uvd->canvas);
3663 uvd->vcap.minwidth = min_canvasWidth;
3664 uvd->vcap.minheight = min_canvasHeight;
3665
3666 memset(&uvd->vchan, 0, sizeof(uvd->vchan));
3667 uvd->vchan.flags = 0;
3668 uvd->vchan.tuners = 0;
3669 uvd->vchan.channel = 0;
3670 uvd->vchan.type = VIDEO_TYPE_CAMERA;
3671 strcpy(uvd->vchan.name, "Camera");
3672}
3673
3674/*
3675 * ibmcam_probe()
3676 *
3677 * This procedure queries device descriptor and accepts the interface
3678 * if it looks like IBM C-it camera.
3679 *
3680 * History:
3681 * 22-Jan-2000 Moved camera init code to ibmcam_open()
3682 * 27=Jan-2000 Changed to use static structures, added locking.
3683 * 24-May-2000 Corrected to prevent race condition (MOD_xxx_USE_COUNT).
3684 * 03-Jul-2000 Fixed endianness bug.
3685 * 12-Nov-2000 Reworked to comply with new probe() signature.
3686 * 23-Jan-2001 Added compatibility with 2.2.x kernels.
3687 */
3688static int ibmcam_probe(struct usb_interface *intf, const struct usb_device_id *devid)
3689{
3690 struct usb_device *dev = interface_to_usbdev(intf);
3691 struct uvd *uvd = NULL;
3692 int ix, i, nas, model=0, canvasX=0, canvasY=0;
3693 int actInterface=-1, inactInterface=-1, maxPS=0;
3694 __u8 ifnum = intf->altsetting->desc.bInterfaceNumber;
3695 unsigned char video_ep = 0;
3696
3697 if (debug >= 1)
3698 dev_info(&dev->dev, "ibmcam_probe(%p,%u.)\n", intf, ifnum);
3699
3700 /* We don't handle multi-config cameras */
3701 if (dev->descriptor.bNumConfigurations != 1)
3702 return -ENODEV;
3703
3704 /* Check the version/revision */
3705 switch (le16_to_cpu(dev->descriptor.bcdDevice)) {
3706 case 0x0002:
3707 if (ifnum != 2)
3708 return -ENODEV;
3709 model = IBMCAM_MODEL_1;
3710 break;
3711 case 0x030A:
3712 if (ifnum != 0)
3713 return -ENODEV;
3714 if ((le16_to_cpu(dev->descriptor.idProduct) == NETCAM_PRODUCT_ID) ||
3715 (le16_to_cpu(dev->descriptor.idProduct) == VEO_800D_PRODUCT_ID))
3716 model = IBMCAM_MODEL_4;
3717 else
3718 model = IBMCAM_MODEL_2;
3719 break;
3720 case 0x0301:
3721 if (ifnum != 0)
3722 return -ENODEV;
3723 model = IBMCAM_MODEL_3;
3724 break;
3725 default:
3726 err("IBM camera with revision 0x%04x is not supported.",
3727 le16_to_cpu(dev->descriptor.bcdDevice));
3728 return -ENODEV;
3729 }
3730
3731 /* Print detailed info on what we found so far */
3732 do {
3733 char *brand = NULL;
3734 switch (le16_to_cpu(dev->descriptor.idProduct)) {
3735 case NETCAM_PRODUCT_ID:
3736 brand = "IBM NetCamera";
3737 break;
3738 case VEO_800C_PRODUCT_ID:
3739 brand = "Veo Stingray [800C]";
3740 break;
3741 case VEO_800D_PRODUCT_ID:
3742 brand = "Veo Stingray [800D]";
3743 break;
3744 case IBMCAM_PRODUCT_ID:
3745 default:
3746 brand = "IBM PC Camera"; /* a.k.a. Xirlink C-It */
3747 break;
3748 }
3749 dev_info(&dev->dev,
3750 "%s USB camera found (model %d, rev. 0x%04x)\n",
3751 brand, model, le16_to_cpu(dev->descriptor.bcdDevice));
3752 } while (0);
3753
3754 /* Validate found interface: must have one ISO endpoint */
3755 nas = intf->num_altsetting;
3756 if (debug > 0)
3757 dev_info(&dev->dev, "Number of alternate settings=%d.\n",
3758 nas);
3759 if (nas < 2) {
3760 err("Too few alternate settings for this camera!");
3761 return -ENODEV;
3762 }
3763 /* Validate all alternate settings */
3764 for (ix=0; ix < nas; ix++) {
3765 const struct usb_host_interface *interface;
3766 const struct usb_endpoint_descriptor *endpoint;
3767
3768 interface = &intf->altsetting[ix];
3769 i = interface->desc.bAlternateSetting;
3770 if (interface->desc.bNumEndpoints != 1) {
3771 err("Interface %d. has %u. endpoints!",
3772 ifnum, (unsigned)(interface->desc.bNumEndpoints));
3773 return -ENODEV;
3774 }
3775 endpoint = &interface->endpoint[0].desc;
3776 if (video_ep == 0)
3777 video_ep = endpoint->bEndpointAddress;
3778 else if (video_ep != endpoint->bEndpointAddress) {
3779 err("Alternate settings have different endpoint addresses!");
3780 return -ENODEV;
3781 }
3782 if (!usb_endpoint_xfer_isoc(endpoint)) {
3783 err("Interface %d. has non-ISO endpoint!", ifnum);
3784 return -ENODEV;
3785 }
3786 if (usb_endpoint_dir_out(endpoint)) {
3787 err("Interface %d. has ISO OUT endpoint!", ifnum);
3788 return -ENODEV;
3789 }
3790 if (le16_to_cpu(endpoint->wMaxPacketSize) == 0) {
3791 if (inactInterface < 0)
3792 inactInterface = i;
3793 else {
3794 err("More than one inactive alt. setting!");
3795 return -ENODEV;
3796 }
3797 } else {
3798 if (actInterface < 0) {
3799 actInterface = i;
3800 maxPS = le16_to_cpu(endpoint->wMaxPacketSize);
3801 if (debug > 0)
3802 dev_info(&dev->dev,
3803 "Active setting=%d. "
3804 "maxPS=%d.\n", i, maxPS);
3805 } else
3806 err("More than one active alt. setting! Ignoring #%d.", i);
3807 }
3808 }
3809 if ((maxPS <= 0) || (actInterface < 0) || (inactInterface < 0)) {
3810 err("Failed to recognize the camera!");
3811 return -ENODEV;
3812 }
3813
3814 /* Validate options */
3815 switch (model) {
3816 case IBMCAM_MODEL_1:
3817 RESTRICT_TO_RANGE(lighting, 0, 2);
3818 RESTRICT_TO_RANGE(size, SIZE_128x96, SIZE_352x288);
3819 if (framerate < 0)
3820 framerate = 2;
3821 canvasX = 352;
3822 canvasY = 288;
3823 break;
3824 case IBMCAM_MODEL_2:
3825 RESTRICT_TO_RANGE(lighting, 0, 15);
3826 RESTRICT_TO_RANGE(size, SIZE_176x144, SIZE_352x240);
3827 if (framerate < 0)
3828 framerate = 2;
3829 canvasX = 352;
3830 canvasY = 240;
3831 break;
3832 case IBMCAM_MODEL_3:
3833 RESTRICT_TO_RANGE(lighting, 0, 15); /* FIXME */
3834 switch (size) {
3835 case SIZE_160x120:
3836 canvasX = 160;
3837 canvasY = 120;
3838 if (framerate < 0)
3839 framerate = 2;
3840 RESTRICT_TO_RANGE(framerate, 0, 5);
3841 break;
3842 default:
3843 dev_info(&dev->dev, "IBM camera: using 320x240\n");
3844 size = SIZE_320x240;
3845 /* No break here */
3846 case SIZE_320x240:
3847 canvasX = 320;
3848 canvasY = 240;
3849 if (framerate < 0)
3850 framerate = 3;
3851 RESTRICT_TO_RANGE(framerate, 0, 5);
3852 break;
3853 case SIZE_640x480:
3854 canvasX = 640;
3855 canvasY = 480;
3856 framerate = 0; /* Slowest, and maybe even that is too fast */
3857 break;
3858 }
3859 break;
3860 case IBMCAM_MODEL_4:
3861 RESTRICT_TO_RANGE(lighting, 0, 2);
3862 switch (size) {
3863 case SIZE_128x96:
3864 canvasX = 128;
3865 canvasY = 96;
3866 break;
3867 case SIZE_160x120:
3868 canvasX = 160;
3869 canvasY = 120;
3870 break;
3871 default:
3872 dev_info(&dev->dev, "IBM NetCamera: using 176x144\n");
3873 size = SIZE_176x144;
3874 /* No break here */
3875 case SIZE_176x144:
3876 canvasX = 176;
3877 canvasY = 144;
3878 break;
3879 case SIZE_320x240:
3880 canvasX = 320;
3881 canvasY = 240;
3882 break;
3883 case SIZE_352x288:
3884 canvasX = 352;
3885 canvasY = 288;
3886 break;
3887 }
3888 break;
3889 default:
3890 err("IBM camera: Model %d. not supported!", model);
3891 return -ENODEV;
3892 }
3893
3894 uvd = usbvideo_AllocateDevice(cams);
3895 if (uvd != NULL) {
3896 /* Here uvd is a fully allocated uvd object */
3897 uvd->flags = flags;
3898 uvd->debug = debug;
3899 uvd->dev = dev;
3900 uvd->iface = ifnum;
3901 uvd->ifaceAltInactive = inactInterface;
3902 uvd->ifaceAltActive = actInterface;
3903 uvd->video_endp = video_ep;
3904 uvd->iso_packet_len = maxPS;
3905 uvd->paletteBits = 1L << VIDEO_PALETTE_RGB24;
3906 uvd->defaultPalette = VIDEO_PALETTE_RGB24;
3907 uvd->canvas = VIDEOSIZE(canvasX, canvasY);
3908 uvd->videosize = ibmcam_size_to_videosize(size);
3909
3910 /* Initialize ibmcam-specific data */
3911 assert(IBMCAM_T(uvd) != NULL);
3912 IBMCAM_T(uvd)->camera_model = model;
3913 IBMCAM_T(uvd)->initialized = 0;
3914
3915 ibmcam_configure_video(uvd);
3916
3917 i = usbvideo_RegisterVideoDevice(uvd);
3918 if (i != 0) {
3919 err("usbvideo_RegisterVideoDevice() failed.");
3920 uvd = NULL;
3921 }
3922 }
3923 usb_set_intfdata (intf, uvd);
3924 return 0;
3925}
3926
3927
3928static struct usb_device_id id_table[] = {
3929 { USB_DEVICE_VER(IBMCAM_VENDOR_ID, IBMCAM_PRODUCT_ID, 0x0002, 0x0002) }, /* Model 1 */
3930 { USB_DEVICE_VER(IBMCAM_VENDOR_ID, IBMCAM_PRODUCT_ID, 0x030a, 0x030a) }, /* Model 2 */
3931 { USB_DEVICE_VER(IBMCAM_VENDOR_ID, IBMCAM_PRODUCT_ID, 0x0301, 0x0301) }, /* Model 3 */
3932 { USB_DEVICE_VER(IBMCAM_VENDOR_ID, NETCAM_PRODUCT_ID, 0x030a, 0x030a) }, /* Model 4 */
3933 { USB_DEVICE_VER(IBMCAM_VENDOR_ID, VEO_800C_PRODUCT_ID, 0x030a, 0x030a) }, /* Model 2 */
3934 { USB_DEVICE_VER(IBMCAM_VENDOR_ID, VEO_800D_PRODUCT_ID, 0x030a, 0x030a) }, /* Model 4 */
3935 { } /* Terminating entry */
3936};
3937
3938/*
3939 * ibmcam_init()
3940 *
3941 * This code is run to initialize the driver.
3942 *
3943 * History:
3944 * 1/27/00 Reworked to use statically allocated ibmcam structures.
3945 * 21/10/00 Completely redesigned to use usbvideo services.
3946 */
3947static int __init ibmcam_init(void)
3948{
3949 struct usbvideo_cb cbTbl;
3950 memset(&cbTbl, 0, sizeof(cbTbl));
3951 cbTbl.probe = ibmcam_probe;
3952 cbTbl.setupOnOpen = ibmcam_setup_on_open;
3953 cbTbl.videoStart = ibmcam_video_start;
3954 cbTbl.videoStop = ibmcam_video_stop;
3955 cbTbl.processData = ibmcam_ProcessIsocData;
3956 cbTbl.postProcess = usbvideo_DeinterlaceFrame;
3957 cbTbl.adjustPicture = ibmcam_adjust_picture;
3958 cbTbl.getFPS = ibmcam_calculate_fps;
3959 return usbvideo_register(
3960 &cams,
3961 MAX_IBMCAM,
3962 sizeof(ibmcam_t),
3963 "ibmcam",
3964 &cbTbl,
3965 THIS_MODULE,
3966 id_table);
3967}
3968
3969static void __exit ibmcam_cleanup(void)
3970{
3971 usbvideo_Deregister(&cams);
3972}
3973
3974MODULE_DEVICE_TABLE(usb, id_table);
3975
3976module_init(ibmcam_init);
3977module_exit(ibmcam_cleanup);
diff --git a/drivers/media/video/usbvideo/konicawc.c b/drivers/media/video/usbvideo/konicawc.c
deleted file mode 100644
index 562e1d170be0..000000000000
--- a/drivers/media/video/usbvideo/konicawc.c
+++ /dev/null
@@ -1,992 +0,0 @@
1/*
2 * konicawc.c - konica webcam driver
3 *
4 * Author: Simon Evans <spse@secret.org.uk>
5 *
6 * Copyright (C) 2002 Simon Evans
7 *
8 * Licence: GPL
9 *
10 * Driver for USB webcams based on Konica chipset. This
11 * chipset is used in Intel YC76 camera.
12 *
13 */
14
15#include <linux/kernel.h>
16#include <linux/module.h>
17#include <linux/init.h>
18#include <linux/usb/input.h>
19#include <linux/gfp.h>
20
21#include "usbvideo.h"
22
23#define MAX_BRIGHTNESS 108
24#define MAX_CONTRAST 108
25#define MAX_SATURATION 108
26#define MAX_SHARPNESS 108
27#define MAX_WHITEBAL 372
28#define MAX_SPEED 6
29
30
31#define MAX_CAMERAS 1
32
33#define DRIVER_VERSION "v1.4"
34#define DRIVER_DESC "Konica Webcam driver"
35
36enum ctrl_req {
37 SetWhitebal = 0x01,
38 SetBrightness = 0x02,
39 SetSharpness = 0x03,
40 SetContrast = 0x04,
41 SetSaturation = 0x05,
42};
43
44
45enum frame_sizes {
46 SIZE_160X120 = 0,
47 SIZE_160X136 = 1,
48 SIZE_176X144 = 2,
49 SIZE_320X240 = 3,
50
51};
52
53#define MAX_FRAME_SIZE SIZE_320X240
54
55static struct usbvideo *cams;
56
57#ifdef CONFIG_USB_DEBUG
58static int debug;
59#define DEBUG(n, format, arg...) \
60 if (n <= debug) { \
61 printk(KERN_DEBUG __FILE__ ":%s(): " format "\n", __func__ , ## arg); \
62 }
63#else
64#define DEBUG(n, arg...)
65static const int debug;
66#endif
67
68
69/* Some default values for initial camera settings,
70 can be set by modprobe */
71
72static int size;
73static int speed = 6; /* Speed (fps) 0 (slowest) to 6 (fastest) */
74static int brightness = MAX_BRIGHTNESS/2;
75static int contrast = MAX_CONTRAST/2;
76static int saturation = MAX_SATURATION/2;
77static int sharpness = MAX_SHARPNESS/2;
78static int whitebal = 3*(MAX_WHITEBAL/4);
79
80static const int spd_to_iface[] = { 1, 0, 3, 2, 4, 5, 6 };
81
82/* These FPS speeds are from the windows config box. They are
83 * indexed on size (0-2) and speed (0-6). Divide by 3 to get the
84 * real fps.
85 */
86
87static const int spd_to_fps[][7] = { { 24, 40, 48, 60, 72, 80, 100 },
88 { 24, 40, 48, 60, 72, 80, 100 },
89 { 18, 30, 36, 45, 54, 60, 75 },
90 { 6, 10, 12, 15, 18, 21, 25 } };
91
92struct cam_size {
93 u16 width;
94 u16 height;
95 u8 cmd;
96};
97
98static const struct cam_size camera_sizes[] = { { 160, 120, 0x7 },
99 { 160, 136, 0xa },
100 { 176, 144, 0x4 },
101 { 320, 240, 0x5 } };
102
103struct konicawc {
104 u8 brightness; /* camera uses 0 - 9, x11 for real value */
105 u8 contrast; /* as above */
106 u8 saturation; /* as above */
107 u8 sharpness; /* as above */
108 u8 white_bal; /* 0 - 33, x11 for real value */
109 u8 speed; /* Stored as 0 - 6, used as index in spd_to_* (above) */
110 u8 size; /* Frame Size */
111 int height;
112 int width;
113 struct urb *sts_urb[USBVIDEO_NUMSBUF];
114 u8 sts_buf[USBVIDEO_NUMSBUF][FRAMES_PER_DESC];
115 struct urb *last_data_urb;
116 int lastframe;
117 int cur_frame_size; /* number of bytes in current frame size */
118 int maxline; /* number of lines per frame */
119 int yplanesz; /* Number of bytes in the Y plane */
120 unsigned int buttonsts:1;
121#ifdef CONFIG_INPUT
122 struct input_dev *input;
123 char input_physname[64];
124#endif
125};
126
127
128#define konicawc_set_misc(uvd, req, value, index) konicawc_ctrl_msg(uvd, USB_DIR_OUT, req, value, index, NULL, 0)
129#define konicawc_get_misc(uvd, req, value, index, buf, sz) konicawc_ctrl_msg(uvd, USB_DIR_IN, req, value, index, buf, sz)
130#define konicawc_set_value(uvd, value, index) konicawc_ctrl_msg(uvd, USB_DIR_OUT, 2, value, index, NULL, 0)
131
132
133static int konicawc_ctrl_msg(struct uvd *uvd, u8 dir, u8 request, u16 value, u16 index, void *buf, int len)
134{
135 int retval = usb_control_msg(uvd->dev,
136 dir ? usb_rcvctrlpipe(uvd->dev, 0) : usb_sndctrlpipe(uvd->dev, 0),
137 request, 0x40 | dir, value, index, buf, len, 1000);
138 return retval < 0 ? retval : 0;
139}
140
141
142static inline void konicawc_camera_on(struct uvd *uvd)
143{
144 DEBUG(0, "camera on");
145 konicawc_set_misc(uvd, 0x2, 1, 0x0b);
146}
147
148
149static inline void konicawc_camera_off(struct uvd *uvd)
150{
151 DEBUG(0, "camera off");
152 konicawc_set_misc(uvd, 0x2, 0, 0x0b);
153}
154
155
156static void konicawc_set_camera_size(struct uvd *uvd)
157{
158 struct konicawc *cam = (struct konicawc *)uvd->user_data;
159
160 konicawc_set_misc(uvd, 0x2, camera_sizes[cam->size].cmd, 0x08);
161 cam->width = camera_sizes[cam->size].width;
162 cam->height = camera_sizes[cam->size].height;
163 cam->yplanesz = cam->height * cam->width;
164 cam->cur_frame_size = (cam->yplanesz * 3) / 2;
165 cam->maxline = cam->yplanesz / 256;
166 uvd->videosize = VIDEOSIZE(cam->width, cam->height);
167}
168
169
170static int konicawc_setup_on_open(struct uvd *uvd)
171{
172 struct konicawc *cam = (struct konicawc *)uvd->user_data;
173
174 DEBUG(1, "setting brightness to %d (%d)", cam->brightness,
175 cam->brightness * 11);
176 konicawc_set_value(uvd, cam->brightness, SetBrightness);
177 DEBUG(1, "setting white balance to %d (%d)", cam->white_bal,
178 cam->white_bal * 11);
179 konicawc_set_value(uvd, cam->white_bal, SetWhitebal);
180 DEBUG(1, "setting contrast to %d (%d)", cam->contrast,
181 cam->contrast * 11);
182 konicawc_set_value(uvd, cam->contrast, SetContrast);
183 DEBUG(1, "setting saturation to %d (%d)", cam->saturation,
184 cam->saturation * 11);
185 konicawc_set_value(uvd, cam->saturation, SetSaturation);
186 DEBUG(1, "setting sharpness to %d (%d)", cam->sharpness,
187 cam->sharpness * 11);
188 konicawc_set_value(uvd, cam->sharpness, SetSharpness);
189 konicawc_set_camera_size(uvd);
190 cam->lastframe = -2;
191 cam->buttonsts = 0;
192 return 0;
193}
194
195
196static void konicawc_adjust_picture(struct uvd *uvd)
197{
198 struct konicawc *cam = (struct konicawc *)uvd->user_data;
199
200 konicawc_camera_off(uvd);
201 DEBUG(1, "new brightness: %d", uvd->vpic.brightness);
202 uvd->vpic.brightness = (uvd->vpic.brightness > MAX_BRIGHTNESS) ? MAX_BRIGHTNESS : uvd->vpic.brightness;
203 if(cam->brightness != uvd->vpic.brightness / 11) {
204 cam->brightness = uvd->vpic.brightness / 11;
205 DEBUG(1, "setting brightness to %d (%d)", cam->brightness,
206 cam->brightness * 11);
207 konicawc_set_value(uvd, cam->brightness, SetBrightness);
208 }
209
210 DEBUG(1, "new contrast: %d", uvd->vpic.contrast);
211 uvd->vpic.contrast = (uvd->vpic.contrast > MAX_CONTRAST) ? MAX_CONTRAST : uvd->vpic.contrast;
212 if(cam->contrast != uvd->vpic.contrast / 11) {
213 cam->contrast = uvd->vpic.contrast / 11;
214 DEBUG(1, "setting contrast to %d (%d)", cam->contrast,
215 cam->contrast * 11);
216 konicawc_set_value(uvd, cam->contrast, SetContrast);
217 }
218 konicawc_camera_on(uvd);
219}
220
221#ifdef CONFIG_INPUT
222
223static void konicawc_register_input(struct konicawc *cam, struct usb_device *dev)
224{
225 struct input_dev *input_dev;
226 int error;
227
228 usb_make_path(dev, cam->input_physname, sizeof(cam->input_physname));
229 strlcat(cam->input_physname, "/input0", sizeof(cam->input_physname));
230
231 cam->input = input_dev = input_allocate_device();
232 if (!input_dev) {
233 dev_warn(&dev->dev,
234 "Not enough memory for camera's input device\n");
235 return;
236 }
237
238 input_dev->name = "Konicawc snapshot button";
239 input_dev->phys = cam->input_physname;
240 usb_to_input_id(dev, &input_dev->id);
241 input_dev->dev.parent = &dev->dev;
242
243 input_dev->evbit[0] = BIT_MASK(EV_KEY);
244 input_dev->keybit[BIT_WORD(KEY_CAMERA)] = BIT_MASK(KEY_CAMERA);
245
246 error = input_register_device(cam->input);
247 if (error) {
248 dev_warn(&dev->dev,
249 "Failed to register camera's input device, err: %d\n",
250 error);
251 input_free_device(cam->input);
252 cam->input = NULL;
253 }
254}
255
256static void konicawc_unregister_input(struct konicawc *cam)
257{
258 if (cam->input) {
259 input_unregister_device(cam->input);
260 cam->input = NULL;
261 }
262}
263
264static void konicawc_report_buttonstat(struct konicawc *cam)
265{
266 if (cam->input) {
267 input_report_key(cam->input, KEY_CAMERA, cam->buttonsts);
268 input_sync(cam->input);
269 }
270}
271
272#else
273
274static inline void konicawc_register_input(struct konicawc *cam, struct usb_device *dev) { }
275static inline void konicawc_unregister_input(struct konicawc *cam) { }
276static inline void konicawc_report_buttonstat(struct konicawc *cam) { }
277
278#endif /* CONFIG_INPUT */
279
280static int konicawc_compress_iso(struct uvd *uvd, struct urb *dataurb, struct urb *stsurb)
281{
282 char *cdata;
283 int i, totlen = 0;
284 unsigned char *status = stsurb->transfer_buffer;
285 int keep = 0, discard = 0, bad = 0;
286 struct konicawc *cam = (struct konicawc *)uvd->user_data;
287
288 for (i = 0; i < dataurb->number_of_packets; i++) {
289 int button = cam->buttonsts;
290 unsigned char sts;
291 int n = dataurb->iso_frame_desc[i].actual_length;
292 int st = dataurb->iso_frame_desc[i].status;
293 cdata = dataurb->transfer_buffer +
294 dataurb->iso_frame_desc[i].offset;
295
296 /* Detect and ignore errored packets */
297 if (st < 0) {
298 DEBUG(1, "Data error: packet=%d. len=%d. status=%d.",
299 i, n, st);
300 uvd->stats.iso_err_count++;
301 continue;
302 }
303
304 /* Detect and ignore empty packets */
305 if (n <= 0) {
306 uvd->stats.iso_skip_count++;
307 continue;
308 }
309
310 /* See what the status data said about the packet */
311 sts = *(status+stsurb->iso_frame_desc[i].offset);
312
313 /* sts: 0x80-0xff: frame start with frame number (ie 0-7f)
314 * otherwise:
315 * bit 0 0: keep packet
316 * 1: drop packet (padding data)
317 *
318 * bit 4 0 button not clicked
319 * 1 button clicked
320 * button is used to `take a picture' (in software)
321 */
322
323 if(sts < 0x80) {
324 button = !!(sts & 0x40);
325 sts &= ~0x40;
326 }
327
328 /* work out the button status, but don't do
329 anything with it for now */
330
331 if(button != cam->buttonsts) {
332 DEBUG(2, "button: %sclicked", button ? "" : "un");
333 cam->buttonsts = button;
334 konicawc_report_buttonstat(cam);
335 }
336
337 if(sts == 0x01) { /* drop frame */
338 discard++;
339 continue;
340 }
341
342 if((sts > 0x01) && (sts < 0x80)) {
343 dev_info(&uvd->dev->dev, "unknown status %2.2x\n",
344 sts);
345 bad++;
346 continue;
347 }
348 if(!sts && cam->lastframe == -2) {
349 DEBUG(2, "dropping frame looking for image start");
350 continue;
351 }
352
353 keep++;
354 if(sts & 0x80) { /* frame start */
355 unsigned char marker[] = { 0, 0xff, 0, 0x00 };
356
357 if(cam->lastframe == -2) {
358 DEBUG(2, "found initial image");
359 cam->lastframe = -1;
360 }
361
362 marker[3] = sts & 0x7F;
363 RingQueue_Enqueue(&uvd->dp, marker, 4);
364 totlen += 4;
365 }
366
367 totlen += n; /* Little local accounting */
368 RingQueue_Enqueue(&uvd->dp, cdata, n);
369 }
370 DEBUG(8, "finished: keep = %d discard = %d bad = %d added %d bytes",
371 keep, discard, bad, totlen);
372 return totlen;
373}
374
375
376static void resubmit_urb(struct uvd *uvd, struct urb *urb)
377{
378 int i, ret;
379 for (i = 0; i < FRAMES_PER_DESC; i++) {
380 urb->iso_frame_desc[i].status = 0;
381 }
382 urb->dev = uvd->dev;
383 urb->status = 0;
384 ret = usb_submit_urb(urb, GFP_ATOMIC);
385 DEBUG(3, "submitting urb of length %d", urb->transfer_buffer_length);
386 if(ret)
387 err("usb_submit_urb error (%d)", ret);
388
389}
390
391
392static void konicawc_isoc_irq(struct urb *urb)
393{
394 struct uvd *uvd = urb->context;
395 struct konicawc *cam = (struct konicawc *)uvd->user_data;
396
397 /* We don't want to do anything if we are about to be removed! */
398 if (!CAMERA_IS_OPERATIONAL(uvd))
399 return;
400
401 if (!uvd->streaming) {
402 DEBUG(1, "Not streaming, but interrupt!");
403 return;
404 }
405
406 DEBUG(3, "got frame %d len = %d buflen =%d", urb->start_frame, urb->actual_length, urb->transfer_buffer_length);
407
408 uvd->stats.urb_count++;
409
410 if (urb->transfer_buffer_length > 32) {
411 cam->last_data_urb = urb;
412 return;
413 }
414 /* Copy the data received into ring queue */
415 if(cam->last_data_urb) {
416 int len = 0;
417 if(urb->start_frame != cam->last_data_urb->start_frame)
418 err("Lost sync on frames");
419 else if (!urb->status && !cam->last_data_urb->status)
420 len = konicawc_compress_iso(uvd, cam->last_data_urb, urb);
421
422 resubmit_urb(uvd, cam->last_data_urb);
423 resubmit_urb(uvd, urb);
424 cam->last_data_urb = NULL;
425 uvd->stats.urb_length = len;
426 uvd->stats.data_count += len;
427 if(len)
428 RingQueue_WakeUpInterruptible(&uvd->dp);
429 return;
430 }
431 return;
432}
433
434
435static int konicawc_start_data(struct uvd *uvd)
436{
437 struct usb_device *dev = uvd->dev;
438 int i, errFlag;
439 struct konicawc *cam = (struct konicawc *)uvd->user_data;
440 int pktsz;
441 struct usb_interface *intf;
442 struct usb_host_interface *interface = NULL;
443
444 intf = usb_ifnum_to_if(dev, uvd->iface);
445 if (intf)
446 interface = usb_altnum_to_altsetting(intf,
447 spd_to_iface[cam->speed]);
448 if (!interface)
449 return -ENXIO;
450 pktsz = le16_to_cpu(interface->endpoint[1].desc.wMaxPacketSize);
451 DEBUG(1, "pktsz = %d", pktsz);
452 if (!CAMERA_IS_OPERATIONAL(uvd)) {
453 err("Camera is not operational");
454 return -EFAULT;
455 }
456 uvd->curframe = -1;
457 konicawc_camera_on(uvd);
458 /* Alternate interface 1 is is the biggest frame size */
459 i = usb_set_interface(dev, uvd->iface, uvd->ifaceAltActive);
460 if (i < 0) {
461 err("usb_set_interface error");
462 uvd->last_error = i;
463 return -EBUSY;
464 }
465
466 /* We double buffer the Iso lists */
467 for (i=0; i < USBVIDEO_NUMSBUF; i++) {
468 int j, k;
469 struct urb *urb = uvd->sbuf[i].urb;
470 urb->dev = dev;
471 urb->context = uvd;
472 urb->pipe = usb_rcvisocpipe(dev, uvd->video_endp);
473 urb->interval = 1;
474 urb->transfer_flags = URB_ISO_ASAP;
475 urb->transfer_buffer = uvd->sbuf[i].data;
476 urb->complete = konicawc_isoc_irq;
477 urb->number_of_packets = FRAMES_PER_DESC;
478 urb->transfer_buffer_length = pktsz * FRAMES_PER_DESC;
479 for (j=k=0; j < FRAMES_PER_DESC; j++, k += pktsz) {
480 urb->iso_frame_desc[j].offset = k;
481 urb->iso_frame_desc[j].length = pktsz;
482 }
483
484 urb = cam->sts_urb[i];
485 urb->dev = dev;
486 urb->context = uvd;
487 urb->pipe = usb_rcvisocpipe(dev, uvd->video_endp-1);
488 urb->interval = 1;
489 urb->transfer_flags = URB_ISO_ASAP;
490 urb->transfer_buffer = cam->sts_buf[i];
491 urb->complete = konicawc_isoc_irq;
492 urb->number_of_packets = FRAMES_PER_DESC;
493 urb->transfer_buffer_length = FRAMES_PER_DESC;
494 for (j=0; j < FRAMES_PER_DESC; j++) {
495 urb->iso_frame_desc[j].offset = j;
496 urb->iso_frame_desc[j].length = 1;
497 }
498 }
499
500 cam->last_data_urb = NULL;
501
502 /* Submit all URBs */
503 for (i=0; i < USBVIDEO_NUMSBUF; i++) {
504 errFlag = usb_submit_urb(cam->sts_urb[i], GFP_KERNEL);
505 if (errFlag)
506 err("usb_submit_isoc(%d) ret %d", i, errFlag);
507
508 errFlag = usb_submit_urb(uvd->sbuf[i].urb, GFP_KERNEL);
509 if (errFlag)
510 err ("usb_submit_isoc(%d) ret %d", i, errFlag);
511 }
512
513 uvd->streaming = 1;
514 DEBUG(1, "streaming=1 video_endp=$%02x", uvd->video_endp);
515 return 0;
516}
517
518
519static void konicawc_stop_data(struct uvd *uvd)
520{
521 int i, j;
522 struct konicawc *cam;
523
524 if ((uvd == NULL) || (!uvd->streaming) || (uvd->dev == NULL))
525 return;
526
527 konicawc_camera_off(uvd);
528 uvd->streaming = 0;
529 cam = (struct konicawc *)uvd->user_data;
530 cam->last_data_urb = NULL;
531
532 /* Unschedule all of the iso td's */
533 for (i=0; i < USBVIDEO_NUMSBUF; i++) {
534 usb_kill_urb(uvd->sbuf[i].urb);
535 usb_kill_urb(cam->sts_urb[i]);
536 }
537
538 if (!uvd->remove_pending) {
539 /* Set packet size to 0 */
540 j = usb_set_interface(uvd->dev, uvd->iface, uvd->ifaceAltInactive);
541 if (j < 0) {
542 err("usb_set_interface() error %d.", j);
543 uvd->last_error = j;
544 }
545 }
546}
547
548
549static void konicawc_process_isoc(struct uvd *uvd, struct usbvideo_frame *frame)
550{
551 struct konicawc *cam = (struct konicawc *)uvd->user_data;
552 int maxline = cam->maxline;
553 int yplanesz = cam->yplanesz;
554
555 assert(frame != NULL);
556
557 DEBUG(5, "maxline = %d yplanesz = %d", maxline, yplanesz);
558 DEBUG(3, "Frame state = %d", frame->scanstate);
559
560 if(frame->scanstate == ScanState_Scanning) {
561 int drop = 0;
562 int curframe;
563 int fdrops = 0;
564 DEBUG(3, "Searching for marker, queue len = %d", RingQueue_GetLength(&uvd->dp));
565 while(RingQueue_GetLength(&uvd->dp) >= 4) {
566 if ((RING_QUEUE_PEEK(&uvd->dp, 0) == 0x00) &&
567 (RING_QUEUE_PEEK(&uvd->dp, 1) == 0xff) &&
568 (RING_QUEUE_PEEK(&uvd->dp, 2) == 0x00) &&
569 (RING_QUEUE_PEEK(&uvd->dp, 3) < 0x80)) {
570 curframe = RING_QUEUE_PEEK(&uvd->dp, 3);
571 if(cam->lastframe >= 0) {
572 fdrops = (0x80 + curframe - cam->lastframe) & 0x7F;
573 fdrops--;
574 if(fdrops) {
575 dev_info(&uvd->dev->dev,
576 "Dropped %d frames "
577 "(%d -> %d)\n",
578 fdrops,
579 cam->lastframe,
580 curframe);
581 }
582 }
583 cam->lastframe = curframe;
584 frame->curline = 0;
585 frame->scanstate = ScanState_Lines;
586 RING_QUEUE_DEQUEUE_BYTES(&uvd->dp, 4);
587 break;
588 }
589 RING_QUEUE_DEQUEUE_BYTES(&uvd->dp, 1);
590 drop++;
591 }
592 if(drop)
593 DEBUG(2, "dropped %d bytes looking for new frame", drop);
594 }
595
596 if(frame->scanstate == ScanState_Scanning)
597 return;
598
599 /* Try to move data from queue into frame buffer
600 * We get data in blocks of 384 bytes made up of:
601 * 256 Y, 64 U, 64 V.
602 * This needs to be written out as a Y plane, a U plane and a V plane.
603 */
604
605 while ( frame->curline < maxline && (RingQueue_GetLength(&uvd->dp) >= 384)) {
606 /* Y */
607 RingQueue_Dequeue(&uvd->dp, frame->data + (frame->curline * 256), 256);
608 /* U */
609 RingQueue_Dequeue(&uvd->dp, frame->data + yplanesz + (frame->curline * 64), 64);
610 /* V */
611 RingQueue_Dequeue(&uvd->dp, frame->data + (5 * yplanesz)/4 + (frame->curline * 64), 64);
612 frame->seqRead_Length += 384;
613 frame->curline++;
614 }
615 /* See if we filled the frame */
616 if (frame->curline == maxline) {
617 DEBUG(5, "got whole frame");
618
619 frame->frameState = FrameState_Done_Hold;
620 frame->curline = 0;
621 uvd->curframe = -1;
622 uvd->stats.frame_num++;
623 }
624}
625
626
627static int konicawc_find_fps(int size, int fps)
628{
629 int i;
630
631 fps *= 3;
632 DEBUG(1, "konica_find_fps: size = %d fps = %d", size, fps);
633 if(fps <= spd_to_fps[size][0])
634 return 0;
635
636 if(fps >= spd_to_fps[size][MAX_SPEED])
637 return MAX_SPEED;
638
639 for(i = 0; i < MAX_SPEED; i++) {
640 if((fps >= spd_to_fps[size][i]) && (fps <= spd_to_fps[size][i+1])) {
641 DEBUG(2, "fps %d between %d and %d", fps, i, i+1);
642 if( (fps - spd_to_fps[size][i]) < (spd_to_fps[size][i+1] - fps))
643 return i;
644 else
645 return i+1;
646 }
647 }
648 return MAX_SPEED+1;
649}
650
651
652static int konicawc_set_video_mode(struct uvd *uvd, struct video_window *vw)
653{
654 struct konicawc *cam = (struct konicawc *)uvd->user_data;
655 int newspeed = cam->speed;
656 int newsize;
657 int x = vw->width;
658 int y = vw->height;
659 int fps = vw->flags;
660
661 if(x > 0 && y > 0) {
662 DEBUG(2, "trying to find size %d,%d", x, y);
663 for(newsize = 0; newsize <= MAX_FRAME_SIZE; newsize++) {
664 if((camera_sizes[newsize].width == x) && (camera_sizes[newsize].height == y))
665 break;
666 }
667 } else {
668 newsize = cam->size;
669 }
670
671 if(newsize > MAX_FRAME_SIZE) {
672 DEBUG(1, "couldn't find size %d,%d", x, y);
673 return -EINVAL;
674 }
675
676 if(fps > 0) {
677 DEBUG(1, "trying to set fps to %d", fps);
678 newspeed = konicawc_find_fps(newsize, fps);
679 DEBUG(1, "find_fps returned %d (%d)", newspeed, spd_to_fps[newsize][newspeed]);
680 }
681
682 if(newspeed > MAX_SPEED)
683 return -EINVAL;
684
685 DEBUG(1, "setting size to %d speed to %d", newsize, newspeed);
686 if((newsize == cam->size) && (newspeed == cam->speed)) {
687 DEBUG(1, "Nothing to do");
688 return 0;
689 }
690 DEBUG(0, "setting to %dx%d @ %d fps", camera_sizes[newsize].width,
691 camera_sizes[newsize].height, spd_to_fps[newsize][newspeed]/3);
692
693 konicawc_stop_data(uvd);
694 uvd->ifaceAltActive = spd_to_iface[newspeed];
695 DEBUG(1, "new interface = %d", uvd->ifaceAltActive);
696 cam->speed = newspeed;
697
698 if(cam->size != newsize) {
699 cam->size = newsize;
700 konicawc_set_camera_size(uvd);
701 }
702
703 /* Flush the input queue and clear any current frame in progress */
704
705 RingQueue_Flush(&uvd->dp);
706 cam->lastframe = -2;
707 if(uvd->curframe != -1) {
708 uvd->frame[uvd->curframe].curline = 0;
709 uvd->frame[uvd->curframe].seqRead_Length = 0;
710 uvd->frame[uvd->curframe].seqRead_Index = 0;
711 }
712
713 konicawc_start_data(uvd);
714 return 0;
715}
716
717
718static int konicawc_calculate_fps(struct uvd *uvd)
719{
720 struct konicawc *cam = uvd->user_data;
721 return spd_to_fps[cam->size][cam->speed]/3;
722}
723
724
725static void konicawc_configure_video(struct uvd *uvd)
726{
727 struct konicawc *cam = (struct konicawc *)uvd->user_data;
728 u8 buf[2];
729
730 memset(&uvd->vpic, 0, sizeof(uvd->vpic));
731 memset(&uvd->vpic_old, 0x55, sizeof(uvd->vpic_old));
732
733 RESTRICT_TO_RANGE(brightness, 0, MAX_BRIGHTNESS);
734 RESTRICT_TO_RANGE(contrast, 0, MAX_CONTRAST);
735 RESTRICT_TO_RANGE(saturation, 0, MAX_SATURATION);
736 RESTRICT_TO_RANGE(sharpness, 0, MAX_SHARPNESS);
737 RESTRICT_TO_RANGE(whitebal, 0, MAX_WHITEBAL);
738
739 cam->brightness = brightness / 11;
740 cam->contrast = contrast / 11;
741 cam->saturation = saturation / 11;
742 cam->sharpness = sharpness / 11;
743 cam->white_bal = whitebal / 11;
744
745 uvd->vpic.colour = 108;
746 uvd->vpic.hue = 108;
747 uvd->vpic.brightness = brightness;
748 uvd->vpic.contrast = contrast;
749 uvd->vpic.whiteness = whitebal;
750 uvd->vpic.depth = 6;
751 uvd->vpic.palette = VIDEO_PALETTE_YUV420P;
752
753 memset(&uvd->vcap, 0, sizeof(uvd->vcap));
754 strcpy(uvd->vcap.name, "Konica Webcam");
755 uvd->vcap.type = VID_TYPE_CAPTURE;
756 uvd->vcap.channels = 1;
757 uvd->vcap.audios = 0;
758 uvd->vcap.minwidth = camera_sizes[SIZE_160X120].width;
759 uvd->vcap.minheight = camera_sizes[SIZE_160X120].height;
760 uvd->vcap.maxwidth = camera_sizes[SIZE_320X240].width;
761 uvd->vcap.maxheight = camera_sizes[SIZE_320X240].height;
762
763 memset(&uvd->vchan, 0, sizeof(uvd->vchan));
764 uvd->vchan.flags = 0 ;
765 uvd->vchan.tuners = 0;
766 uvd->vchan.channel = 0;
767 uvd->vchan.type = VIDEO_TYPE_CAMERA;
768 strcpy(uvd->vchan.name, "Camera");
769
770 /* Talk to device */
771 DEBUG(1, "device init");
772 if(!konicawc_get_misc(uvd, 0x3, 0, 0x10, buf, 2))
773 DEBUG(2, "3,10 -> %2.2x %2.2x", buf[0], buf[1]);
774 if(!konicawc_get_misc(uvd, 0x3, 0, 0x10, buf, 2))
775 DEBUG(2, "3,10 -> %2.2x %2.2x", buf[0], buf[1]);
776 if(konicawc_set_misc(uvd, 0x2, 0, 0xd))
777 DEBUG(2, "2,0,d failed");
778 DEBUG(1, "setting initial values");
779}
780
781static int konicawc_probe(struct usb_interface *intf, const struct usb_device_id *devid)
782{
783 struct usb_device *dev = interface_to_usbdev(intf);
784 struct uvd *uvd = NULL;
785 int ix, i, nas;
786 int actInterface=-1, inactInterface=-1, maxPS=0;
787 unsigned char video_ep = 0;
788
789 DEBUG(1, "konicawc_probe(%p)", intf);
790
791 /* We don't handle multi-config cameras */
792 if (dev->descriptor.bNumConfigurations != 1)
793 return -ENODEV;
794
795 dev_info(&intf->dev, "Konica Webcam (rev. 0x%04x)\n",
796 le16_to_cpu(dev->descriptor.bcdDevice));
797 RESTRICT_TO_RANGE(speed, 0, MAX_SPEED);
798
799 /* Validate found interface: must have one ISO endpoint */
800 nas = intf->num_altsetting;
801 if (nas != 8) {
802 err("Incorrect number of alternate settings (%d) for this camera!", nas);
803 return -ENODEV;
804 }
805 /* Validate all alternate settings */
806 for (ix=0; ix < nas; ix++) {
807 const struct usb_host_interface *interface;
808 const struct usb_endpoint_descriptor *endpoint;
809
810 interface = &intf->altsetting[ix];
811 i = interface->desc.bAlternateSetting;
812 if (interface->desc.bNumEndpoints != 2) {
813 err("Interface %d. has %u. endpoints!",
814 interface->desc.bInterfaceNumber,
815 (unsigned)(interface->desc.bNumEndpoints));
816 return -ENODEV;
817 }
818 endpoint = &interface->endpoint[1].desc;
819 DEBUG(1, "found endpoint: addr: 0x%2.2x maxps = 0x%4.4x",
820 endpoint->bEndpointAddress, le16_to_cpu(endpoint->wMaxPacketSize));
821 if (video_ep == 0)
822 video_ep = endpoint->bEndpointAddress;
823 else if (video_ep != endpoint->bEndpointAddress) {
824 err("Alternate settings have different endpoint addresses!");
825 return -ENODEV;
826 }
827 if (!usb_endpoint_xfer_isoc(endpoint)) {
828 err("Interface %d. has non-ISO endpoint!",
829 interface->desc.bInterfaceNumber);
830 return -ENODEV;
831 }
832 if (usb_endpoint_dir_out(endpoint)) {
833 err("Interface %d. has ISO OUT endpoint!",
834 interface->desc.bInterfaceNumber);
835 return -ENODEV;
836 }
837 if (le16_to_cpu(endpoint->wMaxPacketSize) == 0) {
838 if (inactInterface < 0)
839 inactInterface = i;
840 else {
841 err("More than one inactive alt. setting!");
842 return -ENODEV;
843 }
844 } else {
845 if (i == spd_to_iface[speed]) {
846 /* This one is the requested one */
847 actInterface = i;
848 }
849 }
850 if (le16_to_cpu(endpoint->wMaxPacketSize) > maxPS)
851 maxPS = le16_to_cpu(endpoint->wMaxPacketSize);
852 }
853 if(actInterface == -1) {
854 err("Cant find required endpoint");
855 return -ENODEV;
856 }
857
858 DEBUG(1, "Selecting requested active setting=%d. maxPS=%d.", actInterface, maxPS);
859
860 uvd = usbvideo_AllocateDevice(cams);
861 if (uvd != NULL) {
862 struct konicawc *cam = (struct konicawc *)(uvd->user_data);
863 /* Here uvd is a fully allocated uvd object */
864 for(i = 0; i < USBVIDEO_NUMSBUF; i++) {
865 cam->sts_urb[i] = usb_alloc_urb(FRAMES_PER_DESC, GFP_KERNEL);
866 if(cam->sts_urb[i] == NULL) {
867 while(i--) {
868 usb_free_urb(cam->sts_urb[i]);
869 }
870 err("can't allocate urbs");
871 return -ENOMEM;
872 }
873 }
874 cam->speed = speed;
875 RESTRICT_TO_RANGE(size, SIZE_160X120, SIZE_320X240);
876 cam->width = camera_sizes[size].width;
877 cam->height = camera_sizes[size].height;
878 cam->size = size;
879
880 uvd->flags = 0;
881 uvd->debug = debug;
882 uvd->dev = dev;
883 uvd->iface = intf->altsetting->desc.bInterfaceNumber;
884 uvd->ifaceAltInactive = inactInterface;
885 uvd->ifaceAltActive = actInterface;
886 uvd->video_endp = video_ep;
887 uvd->iso_packet_len = maxPS;
888 uvd->paletteBits = 1L << VIDEO_PALETTE_YUV420P;
889 uvd->defaultPalette = VIDEO_PALETTE_YUV420P;
890 uvd->canvas = VIDEOSIZE(320, 240);
891 uvd->videosize = VIDEOSIZE(cam->width, cam->height);
892
893 /* Initialize konicawc specific data */
894 konicawc_configure_video(uvd);
895
896 i = usbvideo_RegisterVideoDevice(uvd);
897 uvd->max_frame_size = (320 * 240 * 3)/2;
898 if (i != 0) {
899 err("usbvideo_RegisterVideoDevice() failed.");
900 uvd = NULL;
901 }
902
903 konicawc_register_input(cam, dev);
904 }
905
906 if (uvd) {
907 usb_set_intfdata (intf, uvd);
908 return 0;
909 }
910 return -EIO;
911}
912
913
914static void konicawc_free_uvd(struct uvd *uvd)
915{
916 int i;
917 struct konicawc *cam = (struct konicawc *)uvd->user_data;
918
919 konicawc_unregister_input(cam);
920
921 for (i = 0; i < USBVIDEO_NUMSBUF; i++) {
922 usb_free_urb(cam->sts_urb[i]);
923 cam->sts_urb[i] = NULL;
924 }
925}
926
927
928static struct usb_device_id id_table[] = {
929 { USB_DEVICE(0x04c8, 0x0720) }, /* Intel YC 76 */
930 { } /* Terminating entry */
931};
932
933
934static int __init konicawc_init(void)
935{
936 struct usbvideo_cb cbTbl;
937 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
938 DRIVER_DESC "\n");
939 memset(&cbTbl, 0, sizeof(cbTbl));
940 cbTbl.probe = konicawc_probe;
941 cbTbl.setupOnOpen = konicawc_setup_on_open;
942 cbTbl.processData = konicawc_process_isoc;
943 cbTbl.getFPS = konicawc_calculate_fps;
944 cbTbl.setVideoMode = konicawc_set_video_mode;
945 cbTbl.startDataPump = konicawc_start_data;
946 cbTbl.stopDataPump = konicawc_stop_data;
947 cbTbl.adjustPicture = konicawc_adjust_picture;
948 cbTbl.userFree = konicawc_free_uvd;
949 return usbvideo_register(
950 &cams,
951 MAX_CAMERAS,
952 sizeof(struct konicawc),
953 "konicawc",
954 &cbTbl,
955 THIS_MODULE,
956 id_table);
957}
958
959
960static void __exit konicawc_cleanup(void)
961{
962 usbvideo_Deregister(&cams);
963}
964
965
966MODULE_DEVICE_TABLE(usb, id_table);
967
968MODULE_LICENSE("GPL");
969MODULE_AUTHOR("Simon Evans <spse@secret.org.uk>");
970MODULE_DESCRIPTION(DRIVER_DESC);
971module_param(speed, int, 0);
972MODULE_PARM_DESC(speed, "Initial speed: 0 (slowest) - 6 (fastest)");
973module_param(size, int, 0);
974MODULE_PARM_DESC(size, "Initial Size 0: 160x120 1: 160x136 2: 176x144 3: 320x240");
975module_param(brightness, int, 0);
976MODULE_PARM_DESC(brightness, "Initial brightness 0 - 108");
977module_param(contrast, int, 0);
978MODULE_PARM_DESC(contrast, "Initial contrast 0 - 108");
979module_param(saturation, int, 0);
980MODULE_PARM_DESC(saturation, "Initial saturation 0 - 108");
981module_param(sharpness, int, 0);
982MODULE_PARM_DESC(sharpness, "Initial brightness 0 - 108");
983module_param(whitebal, int, 0);
984MODULE_PARM_DESC(whitebal, "Initial white balance 0 - 363");
985
986#ifdef CONFIG_USB_DEBUG
987module_param(debug, int, S_IRUGO | S_IWUSR);
988MODULE_PARM_DESC(debug, "Debug level: 0-9 (default=0)");
989#endif
990
991module_init(konicawc_init);
992module_exit(konicawc_cleanup);
diff --git a/drivers/media/video/usbvideo/ultracam.c b/drivers/media/video/usbvideo/ultracam.c
deleted file mode 100644
index fbd1b6392290..000000000000
--- a/drivers/media/video/usbvideo/ultracam.c
+++ /dev/null
@@ -1,685 +0,0 @@
1/*
2 * USB NB Camera driver
3 *
4 * HISTORY:
5 * 25-Dec-2002 Dmitri Removed lighting, sharpness parameters, methods.
6 */
7
8#include <linux/kernel.h>
9#include <linux/module.h>
10#include <linux/init.h>
11
12#include "usbvideo.h"
13
14#define ULTRACAM_VENDOR_ID 0x0461
15#define ULTRACAM_PRODUCT_ID 0x0813
16
17#define MAX_CAMERAS 4 /* How many devices we allow to connect */
18
19/*
20 * This structure lives in uvd_t->user field.
21 */
22typedef struct {
23 int initialized; /* Had we already sent init sequence? */
24 int camera_model; /* What type of IBM camera we got? */
25 int has_hdr;
26} ultracam_t;
27#define ULTRACAM_T(uvd) ((ultracam_t *)((uvd)->user_data))
28
29static struct usbvideo *cams = NULL;
30
31static int debug;
32
33static int flags; /* FLAGS_DISPLAY_HINTS | FLAGS_OVERLAY_STATS; */
34
35static const int min_canvasWidth = 8;
36static const int min_canvasHeight = 4;
37
38#define FRAMERATE_MIN 0
39#define FRAMERATE_MAX 6
40static int framerate = -1;
41
42/*
43 * Here we define several initialization variables. They may
44 * be used to automatically set color, hue, brightness and
45 * contrast to desired values. This is particularly useful in
46 * case of webcams (which have no controls and no on-screen
47 * output) and also when a client V4L software is used that
48 * does not have some of those controls. In any case it's
49 * good to have startup values as options.
50 *
51 * These values are all in [0..255] range. This simplifies
52 * operation. Note that actual values of V4L variables may
53 * be scaled up (as much as << 8). User can see that only
54 * on overlay output, however, or through a V4L client.
55 */
56static int init_brightness = 128;
57static int init_contrast = 192;
58static int init_color = 128;
59static int init_hue = 128;
60static int hue_correction = 128;
61
62module_param(debug, int, S_IRUGO | S_IWUSR);
63MODULE_PARM_DESC(debug, "Debug level: 0-9 (default=0)");
64module_param(flags, int, 0);
65MODULE_PARM_DESC(flags,
66 "Bitfield: 0=VIDIOCSYNC, "
67 "1=B/W, "
68 "2=show hints, "
69 "3=show stats, "
70 "4=test pattern, "
71 "5=separate frames, "
72 "6=clean frames");
73module_param(framerate, int, 0);
74MODULE_PARM_DESC(framerate, "Framerate setting: 0=slowest, 6=fastest (default=2)");
75
76module_param(init_brightness, int, 0);
77MODULE_PARM_DESC(init_brightness, "Brightness preconfiguration: 0-255 (default=128)");
78module_param(init_contrast, int, 0);
79MODULE_PARM_DESC(init_contrast, "Contrast preconfiguration: 0-255 (default=192)");
80module_param(init_color, int, 0);
81MODULE_PARM_DESC(init_color, "Color preconfiguration: 0-255 (default=128)");
82module_param(init_hue, int, 0);
83MODULE_PARM_DESC(init_hue, "Hue preconfiguration: 0-255 (default=128)");
84module_param(hue_correction, int, 0);
85MODULE_PARM_DESC(hue_correction, "YUV colorspace regulation: 0-255 (default=128)");
86
87/*
88 * ultracam_ProcessIsocData()
89 *
90 * Generic routine to parse the ring queue data. It employs either
91 * ultracam_find_header() or ultracam_parse_lines() to do most
92 * of work.
93 *
94 * 02-Nov-2000 First (mostly dummy) version.
95 * 06-Nov-2000 Rewrote to dump all data into frame.
96 */
97static void ultracam_ProcessIsocData(struct uvd *uvd, struct usbvideo_frame *frame)
98{
99 int n;
100
101 assert(uvd != NULL);
102 assert(frame != NULL);
103
104 /* Try to move data from queue into frame buffer */
105 n = RingQueue_GetLength(&uvd->dp);
106 if (n > 0) {
107 int m;
108 /* See how much spare we have left */
109 m = uvd->max_frame_size - frame->seqRead_Length;
110 if (n > m)
111 n = m;
112 /* Now move that much data into frame buffer */
113 RingQueue_Dequeue(
114 &uvd->dp,
115 frame->data + frame->seqRead_Length,
116 m);
117 frame->seqRead_Length += m;
118 }
119 /* See if we filled the frame */
120 if (frame->seqRead_Length >= uvd->max_frame_size) {
121 frame->frameState = FrameState_Done;
122 uvd->curframe = -1;
123 uvd->stats.frame_num++;
124 }
125}
126
127/*
128 * ultracam_veio()
129 *
130 * History:
131 * 1/27/00 Added check for dev == NULL; this happens if camera is unplugged.
132 */
133static int ultracam_veio(
134 struct uvd *uvd,
135 unsigned char req,
136 unsigned short value,
137 unsigned short index,
138 int is_out)
139{
140 static const char proc[] = "ultracam_veio";
141 unsigned char cp[8] /* = { 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef } */;
142 int i;
143
144 if (!CAMERA_IS_OPERATIONAL(uvd))
145 return 0;
146
147 if (!is_out) {
148 i = usb_control_msg(
149 uvd->dev,
150 usb_rcvctrlpipe(uvd->dev, 0),
151 req,
152 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
153 value,
154 index,
155 cp,
156 sizeof(cp),
157 1000);
158#if 1
159 dev_info(&uvd->dev->dev,
160 "USB => %02x%02x%02x%02x%02x%02x%02x%02x "
161 "(req=$%02x val=$%04x ind=$%04x)\n",
162 cp[0],cp[1],cp[2],cp[3],cp[4],cp[5],cp[6],cp[7],
163 req, value, index);
164#endif
165 } else {
166 i = usb_control_msg(
167 uvd->dev,
168 usb_sndctrlpipe(uvd->dev, 0),
169 req,
170 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
171 value,
172 index,
173 NULL,
174 0,
175 1000);
176 }
177 if (i < 0) {
178 err("%s: ERROR=%d. Camera stopped; Reconnect or reload driver.",
179 proc, i);
180 uvd->last_error = i;
181 }
182 return i;
183}
184
185/*
186 * ultracam_calculate_fps()
187 */
188static int ultracam_calculate_fps(struct uvd *uvd)
189{
190 return 3 + framerate*4 + framerate/2;
191}
192
193/*
194 * ultracam_adjust_contrast()
195 */
196static void ultracam_adjust_contrast(struct uvd *uvd)
197{
198}
199
200/*
201 * ultracam_set_brightness()
202 *
203 * This procedure changes brightness of the picture.
204 */
205static void ultracam_set_brightness(struct uvd *uvd)
206{
207}
208
209static void ultracam_set_hue(struct uvd *uvd)
210{
211}
212
213/*
214 * ultracam_adjust_picture()
215 *
216 * This procedure gets called from V4L interface to update picture settings.
217 * Here we change brightness and contrast.
218 */
219static void ultracam_adjust_picture(struct uvd *uvd)
220{
221 ultracam_adjust_contrast(uvd);
222 ultracam_set_brightness(uvd);
223 ultracam_set_hue(uvd);
224}
225
226/*
227 * ultracam_video_stop()
228 *
229 * This code tells camera to stop streaming. The interface remains
230 * configured and bandwidth - claimed.
231 */
232static void ultracam_video_stop(struct uvd *uvd)
233{
234}
235
236/*
237 * ultracam_reinit_iso()
238 *
239 * This procedure sends couple of commands to the camera and then
240 * resets the video pipe. This sequence was observed to reinit the
241 * camera or, at least, to initiate ISO data stream.
242 */
243static void ultracam_reinit_iso(struct uvd *uvd, int do_stop)
244{
245}
246
247static void ultracam_video_start(struct uvd *uvd)
248{
249 ultracam_reinit_iso(uvd, 0);
250}
251
252static int ultracam_resetPipe(struct uvd *uvd)
253{
254 usb_clear_halt(uvd->dev, uvd->video_endp);
255 return 0;
256}
257
258static int ultracam_alternateSetting(struct uvd *uvd, int setting)
259{
260 static const char proc[] = "ultracam_alternateSetting";
261 int i;
262 i = usb_set_interface(uvd->dev, uvd->iface, setting);
263 if (i < 0) {
264 err("%s: usb_set_interface error", proc);
265 uvd->last_error = i;
266 return -EBUSY;
267 }
268 return 0;
269}
270
271/*
272 * Return negative code on failure, 0 on success.
273 */
274static int ultracam_setup_on_open(struct uvd *uvd)
275{
276 int setup_ok = 0; /* Success by default */
277 /* Send init sequence only once, it's large! */
278 if (!ULTRACAM_T(uvd)->initialized) {
279 ultracam_alternateSetting(uvd, 0x04);
280 ultracam_alternateSetting(uvd, 0x00);
281 ultracam_veio(uvd, 0x02, 0x0004, 0x000b, 1);
282 ultracam_veio(uvd, 0x02, 0x0001, 0x0005, 1);
283 ultracam_veio(uvd, 0x02, 0x8000, 0x0000, 1);
284 ultracam_veio(uvd, 0x00, 0x0000, 0x0000, 1);
285 ultracam_veio(uvd, 0x00, 0x00b0, 0x0001, 1);
286 ultracam_veio(uvd, 0x00, 0x0000, 0x0002, 1);
287 ultracam_veio(uvd, 0x00, 0x000c, 0x0003, 1);
288 ultracam_veio(uvd, 0x00, 0x000b, 0x0004, 1);
289 ultracam_veio(uvd, 0x00, 0x0000, 0x0005, 1);
290 ultracam_veio(uvd, 0x00, 0x0000, 0x0006, 1);
291 ultracam_veio(uvd, 0x00, 0x0079, 0x0007, 1);
292 ultracam_veio(uvd, 0x00, 0x003b, 0x0008, 1);
293 ultracam_veio(uvd, 0x00, 0x0002, 0x000f, 1);
294 ultracam_veio(uvd, 0x00, 0x0001, 0x0010, 1);
295 ultracam_veio(uvd, 0x00, 0x0000, 0x0011, 1);
296 ultracam_veio(uvd, 0x00, 0x0000, 0x00bf, 1);
297 ultracam_veio(uvd, 0x00, 0x0001, 0x00c0, 1);
298 ultracam_veio(uvd, 0x00, 0x0010, 0x00cb, 1);
299 ultracam_veio(uvd, 0x01, 0x00a4, 0x0001, 1);
300 ultracam_veio(uvd, 0x01, 0x0010, 0x0002, 1);
301 ultracam_veio(uvd, 0x01, 0x0066, 0x0007, 1);
302 ultracam_veio(uvd, 0x01, 0x000b, 0x0008, 1);
303 ultracam_veio(uvd, 0x01, 0x0034, 0x0009, 1);
304 ultracam_veio(uvd, 0x01, 0x0000, 0x000a, 1);
305 ultracam_veio(uvd, 0x01, 0x002e, 0x000b, 1);
306 ultracam_veio(uvd, 0x01, 0x00d6, 0x000c, 1);
307 ultracam_veio(uvd, 0x01, 0x00fc, 0x000d, 1);
308 ultracam_veio(uvd, 0x01, 0x00f1, 0x000e, 1);
309 ultracam_veio(uvd, 0x01, 0x00da, 0x000f, 1);
310 ultracam_veio(uvd, 0x01, 0x0036, 0x0010, 1);
311 ultracam_veio(uvd, 0x01, 0x000b, 0x0011, 1);
312 ultracam_veio(uvd, 0x01, 0x0001, 0x0012, 1);
313 ultracam_veio(uvd, 0x01, 0x0000, 0x0013, 1);
314 ultracam_veio(uvd, 0x01, 0x0000, 0x0014, 1);
315 ultracam_veio(uvd, 0x01, 0x0087, 0x0051, 1);
316 ultracam_veio(uvd, 0x01, 0x0040, 0x0052, 1);
317 ultracam_veio(uvd, 0x01, 0x0058, 0x0053, 1);
318 ultracam_veio(uvd, 0x01, 0x0040, 0x0054, 1);
319 ultracam_veio(uvd, 0x01, 0x0000, 0x0040, 1);
320 ultracam_veio(uvd, 0x01, 0x0010, 0x0041, 1);
321 ultracam_veio(uvd, 0x01, 0x0020, 0x0042, 1);
322 ultracam_veio(uvd, 0x01, 0x0030, 0x0043, 1);
323 ultracam_veio(uvd, 0x01, 0x0040, 0x0044, 1);
324 ultracam_veio(uvd, 0x01, 0x0050, 0x0045, 1);
325 ultracam_veio(uvd, 0x01, 0x0060, 0x0046, 1);
326 ultracam_veio(uvd, 0x01, 0x0070, 0x0047, 1);
327 ultracam_veio(uvd, 0x01, 0x0080, 0x0048, 1);
328 ultracam_veio(uvd, 0x01, 0x0090, 0x0049, 1);
329 ultracam_veio(uvd, 0x01, 0x00a0, 0x004a, 1);
330 ultracam_veio(uvd, 0x01, 0x00b0, 0x004b, 1);
331 ultracam_veio(uvd, 0x01, 0x00c0, 0x004c, 1);
332 ultracam_veio(uvd, 0x01, 0x00d0, 0x004d, 1);
333 ultracam_veio(uvd, 0x01, 0x00e0, 0x004e, 1);
334 ultracam_veio(uvd, 0x01, 0x00f0, 0x004f, 1);
335 ultracam_veio(uvd, 0x01, 0x00ff, 0x0050, 1);
336 ultracam_veio(uvd, 0x01, 0x0000, 0x0056, 1);
337 ultracam_veio(uvd, 0x00, 0x0080, 0x00c1, 1);
338 ultracam_veio(uvd, 0x00, 0x0000, 0x00c2, 1);
339 ultracam_veio(uvd, 0x00, 0x0000, 0x00ca, 1);
340 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
341 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
342 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
343 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
344 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
345 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
346 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
347 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
348 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
349 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
350 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
351 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
352 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
353 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
354 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
355 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
356 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
357 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
358 ultracam_veio(uvd, 0x00, 0x0080, 0x00c1, 1);
359 ultracam_veio(uvd, 0x00, 0x0004, 0x00c2, 1);
360 ultracam_veio(uvd, 0x00, 0x0000, 0x00ca, 1);
361 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
362 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
363 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
364 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
365 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
366 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
367 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
368 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
369 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
370 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
371 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
372 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
373 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
374 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
375 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
376 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
377 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
378 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
379 ultracam_veio(uvd, 0x00, 0x0002, 0x00c1, 1);
380 ultracam_veio(uvd, 0x00, 0x0020, 0x00c2, 1);
381 ultracam_veio(uvd, 0x00, 0x0000, 0x00ca, 1);
382 ultracam_veio(uvd, 0x00, 0x0000, 0x00c3, 1);
383 ultracam_veio(uvd, 0x00, 0x0000, 0x00c4, 1);
384 ultracam_veio(uvd, 0x00, 0x0000, 0x00c5, 1);
385 ultracam_veio(uvd, 0x00, 0x0000, 0x00c6, 1);
386 ultracam_veio(uvd, 0x00, 0x0000, 0x00c7, 1);
387 ultracam_veio(uvd, 0x00, 0x0000, 0x00c8, 1);
388 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
389 ultracam_veio(uvd, 0x00, 0x0000, 0x00c3, 1);
390 ultracam_veio(uvd, 0x00, 0x0000, 0x00c4, 1);
391 ultracam_veio(uvd, 0x00, 0x0000, 0x00c5, 1);
392 ultracam_veio(uvd, 0x00, 0x0000, 0x00c6, 1);
393 ultracam_veio(uvd, 0x00, 0x0000, 0x00c7, 1);
394 ultracam_veio(uvd, 0x00, 0x0000, 0x00c8, 1);
395 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
396 ultracam_veio(uvd, 0x00, 0x0040, 0x00c1, 1);
397 ultracam_veio(uvd, 0x00, 0x0017, 0x00c2, 1);
398 ultracam_veio(uvd, 0x00, 0x0000, 0x00ca, 1);
399 ultracam_veio(uvd, 0x00, 0x0000, 0x00c3, 1);
400 ultracam_veio(uvd, 0x00, 0x0000, 0x00c4, 1);
401 ultracam_veio(uvd, 0x00, 0x0000, 0x00c5, 1);
402 ultracam_veio(uvd, 0x00, 0x0000, 0x00c6, 1);
403 ultracam_veio(uvd, 0x00, 0x0000, 0x00c7, 1);
404 ultracam_veio(uvd, 0x00, 0x0000, 0x00c8, 1);
405 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
406 ultracam_veio(uvd, 0x00, 0x0000, 0x00c3, 1);
407 ultracam_veio(uvd, 0x00, 0x0000, 0x00c4, 1);
408 ultracam_veio(uvd, 0x00, 0x0000, 0x00c5, 1);
409 ultracam_veio(uvd, 0x00, 0x0000, 0x00c6, 1);
410 ultracam_veio(uvd, 0x00, 0x0000, 0x00c7, 1);
411 ultracam_veio(uvd, 0x00, 0x0000, 0x00c8, 1);
412 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
413 ultracam_veio(uvd, 0x00, 0x00c0, 0x00c1, 1);
414 ultracam_veio(uvd, 0x00, 0x0000, 0x00c2, 1);
415 ultracam_veio(uvd, 0x00, 0x0000, 0x00ca, 1);
416 ultracam_veio(uvd, 0x02, 0xc040, 0x0001, 1);
417 ultracam_veio(uvd, 0x01, 0x0000, 0x0008, 0);
418 ultracam_veio(uvd, 0x01, 0x0000, 0x0009, 0);
419 ultracam_veio(uvd, 0x01, 0x0000, 0x000a, 0);
420 ultracam_veio(uvd, 0x01, 0x0000, 0x000b, 0);
421 ultracam_veio(uvd, 0x01, 0x0000, 0x000c, 0);
422 ultracam_veio(uvd, 0x01, 0x0000, 0x000d, 0);
423 ultracam_veio(uvd, 0x01, 0x0000, 0x000e, 0);
424 ultracam_veio(uvd, 0x01, 0x0000, 0x000f, 0);
425 ultracam_veio(uvd, 0x01, 0x0000, 0x0010, 0);
426 ultracam_veio(uvd, 0x01, 0x000b, 0x0008, 1);
427 ultracam_veio(uvd, 0x01, 0x0034, 0x0009, 1);
428 ultracam_veio(uvd, 0x01, 0x0000, 0x000a, 1);
429 ultracam_veio(uvd, 0x01, 0x002e, 0x000b, 1);
430 ultracam_veio(uvd, 0x01, 0x00d6, 0x000c, 1);
431 ultracam_veio(uvd, 0x01, 0x00fc, 0x000d, 1);
432 ultracam_veio(uvd, 0x01, 0x00f1, 0x000e, 1);
433 ultracam_veio(uvd, 0x01, 0x00da, 0x000f, 1);
434 ultracam_veio(uvd, 0x01, 0x0036, 0x0010, 1);
435 ultracam_veio(uvd, 0x01, 0x0000, 0x0001, 0);
436 ultracam_veio(uvd, 0x01, 0x0064, 0x0001, 1);
437 ultracam_veio(uvd, 0x01, 0x0059, 0x0051, 1);
438 ultracam_veio(uvd, 0x01, 0x003f, 0x0052, 1);
439 ultracam_veio(uvd, 0x01, 0x0094, 0x0053, 1);
440 ultracam_veio(uvd, 0x01, 0x00ff, 0x0011, 1);
441 ultracam_veio(uvd, 0x01, 0x0003, 0x0012, 1);
442 ultracam_veio(uvd, 0x01, 0x00f7, 0x0013, 1);
443 ultracam_veio(uvd, 0x00, 0x0009, 0x0011, 1);
444 ultracam_veio(uvd, 0x00, 0x0000, 0x0001, 1);
445 ultracam_veio(uvd, 0x00, 0x0000, 0x0000, 1);
446 ultracam_veio(uvd, 0x00, 0x0020, 0x00c1, 1);
447 ultracam_veio(uvd, 0x00, 0x0010, 0x00c2, 1);
448 ultracam_veio(uvd, 0x00, 0x0000, 0x00ca, 1);
449 ultracam_alternateSetting(uvd, 0x04);
450 ultracam_veio(uvd, 0x02, 0x0000, 0x0001, 1);
451 ultracam_veio(uvd, 0x02, 0x0000, 0x0001, 1);
452 ultracam_veio(uvd, 0x02, 0x0000, 0x0006, 1);
453 ultracam_veio(uvd, 0x02, 0x9000, 0x0007, 1);
454 ultracam_veio(uvd, 0x02, 0x0042, 0x0001, 1);
455 ultracam_veio(uvd, 0x02, 0x0000, 0x000b, 0);
456 ultracam_resetPipe(uvd);
457 ULTRACAM_T(uvd)->initialized = (setup_ok != 0);
458 }
459 return setup_ok;
460}
461
462static void ultracam_configure_video(struct uvd *uvd)
463{
464 if (uvd == NULL)
465 return;
466
467 RESTRICT_TO_RANGE(init_brightness, 0, 255);
468 RESTRICT_TO_RANGE(init_contrast, 0, 255);
469 RESTRICT_TO_RANGE(init_color, 0, 255);
470 RESTRICT_TO_RANGE(init_hue, 0, 255);
471 RESTRICT_TO_RANGE(hue_correction, 0, 255);
472
473 memset(&uvd->vpic, 0, sizeof(uvd->vpic));
474 memset(&uvd->vpic_old, 0x55, sizeof(uvd->vpic_old));
475
476 uvd->vpic.colour = init_color << 8;
477 uvd->vpic.hue = init_hue << 8;
478 uvd->vpic.brightness = init_brightness << 8;
479 uvd->vpic.contrast = init_contrast << 8;
480 uvd->vpic.whiteness = 105 << 8; /* This one isn't used */
481 uvd->vpic.depth = 24;
482 uvd->vpic.palette = VIDEO_PALETTE_RGB24;
483
484 memset(&uvd->vcap, 0, sizeof(uvd->vcap));
485 strcpy(uvd->vcap.name, "IBM Ultra Camera");
486 uvd->vcap.type = VID_TYPE_CAPTURE;
487 uvd->vcap.channels = 1;
488 uvd->vcap.audios = 0;
489 uvd->vcap.maxwidth = VIDEOSIZE_X(uvd->canvas);
490 uvd->vcap.maxheight = VIDEOSIZE_Y(uvd->canvas);
491 uvd->vcap.minwidth = min_canvasWidth;
492 uvd->vcap.minheight = min_canvasHeight;
493
494 memset(&uvd->vchan, 0, sizeof(uvd->vchan));
495 uvd->vchan.flags = 0;
496 uvd->vchan.tuners = 0;
497 uvd->vchan.channel = 0;
498 uvd->vchan.type = VIDEO_TYPE_CAMERA;
499 strcpy(uvd->vchan.name, "Camera");
500}
501
502/*
503 * ultracam_probe()
504 *
505 * This procedure queries device descriptor and accepts the interface
506 * if it looks like our camera.
507 *
508 * History:
509 * 12-Nov-2000 Reworked to comply with new probe() signature.
510 * 23-Jan-2001 Added compatibility with 2.2.x kernels.
511 */
512static int ultracam_probe(struct usb_interface *intf, const struct usb_device_id *devid)
513{
514 struct usb_device *dev = interface_to_usbdev(intf);
515 struct uvd *uvd = NULL;
516 int ix, i, nas;
517 int actInterface=-1, inactInterface=-1, maxPS=0;
518 unsigned char video_ep = 0;
519
520 if (debug >= 1)
521 dev_info(&intf->dev, "ultracam_probe\n");
522
523 /* We don't handle multi-config cameras */
524 if (dev->descriptor.bNumConfigurations != 1)
525 return -ENODEV;
526
527 dev_info(&intf->dev, "IBM Ultra camera found (rev. 0x%04x)\n",
528 le16_to_cpu(dev->descriptor.bcdDevice));
529
530 /* Validate found interface: must have one ISO endpoint */
531 nas = intf->num_altsetting;
532 if (debug > 0)
533 dev_info(&intf->dev, "Number of alternate settings=%d.\n",
534 nas);
535 if (nas < 8) {
536 err("Too few alternate settings for this camera!");
537 return -ENODEV;
538 }
539 /* Validate all alternate settings */
540 for (ix=0; ix < nas; ix++) {
541 const struct usb_host_interface *interface;
542 const struct usb_endpoint_descriptor *endpoint;
543
544 interface = &intf->altsetting[ix];
545 i = interface->desc.bAlternateSetting;
546 if (interface->desc.bNumEndpoints != 1) {
547 err("Interface %d. has %u. endpoints!",
548 interface->desc.bInterfaceNumber,
549 (unsigned)(interface->desc.bNumEndpoints));
550 return -ENODEV;
551 }
552 endpoint = &interface->endpoint[0].desc;
553 if (video_ep == 0)
554 video_ep = endpoint->bEndpointAddress;
555 else if (video_ep != endpoint->bEndpointAddress) {
556 err("Alternate settings have different endpoint addresses!");
557 return -ENODEV;
558 }
559 if (!usb_endpoint_xfer_isoc(endpoint)) {
560 err("Interface %d. has non-ISO endpoint!",
561 interface->desc.bInterfaceNumber);
562 return -ENODEV;
563 }
564 if (usb_endpoint_dir_out(endpoint)) {
565 err("Interface %d. has ISO OUT endpoint!",
566 interface->desc.bInterfaceNumber);
567 return -ENODEV;
568 }
569 if (le16_to_cpu(endpoint->wMaxPacketSize) == 0) {
570 if (inactInterface < 0)
571 inactInterface = i;
572 else {
573 err("More than one inactive alt. setting!");
574 return -ENODEV;
575 }
576 } else {
577 if (actInterface < 0) {
578 actInterface = i;
579 maxPS = le16_to_cpu(endpoint->wMaxPacketSize);
580 if (debug > 0)
581 dev_info(&intf->dev,
582 "Active setting=%d. "
583 "maxPS=%d.\n", i, maxPS);
584 } else {
585 /* Got another active alt. setting */
586 if (maxPS < le16_to_cpu(endpoint->wMaxPacketSize)) {
587 /* This one is better! */
588 actInterface = i;
589 maxPS = le16_to_cpu(endpoint->wMaxPacketSize);
590 if (debug > 0) {
591 dev_info(&intf->dev,
592 "Even better ctive "
593 "setting=%d. "
594 "maxPS=%d.\n",
595 i, maxPS);
596 }
597 }
598 }
599 }
600 }
601 if ((maxPS <= 0) || (actInterface < 0) || (inactInterface < 0)) {
602 err("Failed to recognize the camera!");
603 return -ENODEV;
604 }
605
606 uvd = usbvideo_AllocateDevice(cams);
607 if (uvd != NULL) {
608 /* Here uvd is a fully allocated uvd object */
609 uvd->flags = flags;
610 uvd->debug = debug;
611 uvd->dev = dev;
612 uvd->iface = intf->altsetting->desc.bInterfaceNumber;
613 uvd->ifaceAltInactive = inactInterface;
614 uvd->ifaceAltActive = actInterface;
615 uvd->video_endp = video_ep;
616 uvd->iso_packet_len = maxPS;
617 uvd->paletteBits = 1L << VIDEO_PALETTE_RGB24;
618 uvd->defaultPalette = VIDEO_PALETTE_RGB24;
619 uvd->canvas = VIDEOSIZE(640, 480); /* FIXME */
620 uvd->videosize = uvd->canvas; /* ultracam_size_to_videosize(size);*/
621
622 /* Initialize ibmcam-specific data */
623 assert(ULTRACAM_T(uvd) != NULL);
624 ULTRACAM_T(uvd)->camera_model = 0; /* Not used yet */
625 ULTRACAM_T(uvd)->initialized = 0;
626
627 ultracam_configure_video(uvd);
628
629 i = usbvideo_RegisterVideoDevice(uvd);
630 if (i != 0) {
631 err("usbvideo_RegisterVideoDevice() failed.");
632 uvd = NULL;
633 }
634 }
635
636 if (uvd) {
637 usb_set_intfdata (intf, uvd);
638 return 0;
639 }
640 return -EIO;
641}
642
643
644static struct usb_device_id id_table[] = {
645 { USB_DEVICE(ULTRACAM_VENDOR_ID, ULTRACAM_PRODUCT_ID) },
646 { } /* Terminating entry */
647};
648
649/*
650 * ultracam_init()
651 *
652 * This code is run to initialize the driver.
653 */
654static int __init ultracam_init(void)
655{
656 struct usbvideo_cb cbTbl;
657 memset(&cbTbl, 0, sizeof(cbTbl));
658 cbTbl.probe = ultracam_probe;
659 cbTbl.setupOnOpen = ultracam_setup_on_open;
660 cbTbl.videoStart = ultracam_video_start;
661 cbTbl.videoStop = ultracam_video_stop;
662 cbTbl.processData = ultracam_ProcessIsocData;
663 cbTbl.postProcess = usbvideo_DeinterlaceFrame;
664 cbTbl.adjustPicture = ultracam_adjust_picture;
665 cbTbl.getFPS = ultracam_calculate_fps;
666 return usbvideo_register(
667 &cams,
668 MAX_CAMERAS,
669 sizeof(ultracam_t),
670 "ultracam",
671 &cbTbl,
672 THIS_MODULE,
673 id_table);
674}
675
676static void __exit ultracam_cleanup(void)
677{
678 usbvideo_Deregister(&cams);
679}
680
681MODULE_DEVICE_TABLE(usb, id_table);
682MODULE_LICENSE("GPL");
683
684module_init(ultracam_init);
685module_exit(ultracam_cleanup);
diff --git a/drivers/media/video/usbvision/usbvision-cards.c b/drivers/media/video/usbvision/usbvision-cards.c
index 503b13beb922..68b998bd203f 100644
--- a/drivers/media/video/usbvision/usbvision-cards.c
+++ b/drivers/media/video/usbvision/usbvision-cards.c
@@ -32,1072 +32,1072 @@
32/* Supported Devices: A table for usbvision.c*/ 32/* Supported Devices: A table for usbvision.c*/
33struct usbvision_device_data_st usbvision_device_data[] = { 33struct usbvision_device_data_st usbvision_device_data[] = {
34 [XANBOO] = { 34 [XANBOO] = {
35 .Interface = -1, 35 .interface = -1,
36 .Codec = CODEC_SAA7113, 36 .codec = CODEC_SAA7113,
37 .VideoChannels = 4, 37 .video_channels = 4,
38 .VideoNorm = V4L2_STD_NTSC, 38 .video_norm = V4L2_STD_NTSC,
39 .AudioChannels = 1, 39 .audio_channels = 1,
40 .Radio = 0, 40 .radio = 0,
41 .vbi = 1, 41 .vbi = 1,
42 .Tuner = 0, 42 .tuner = 0,
43 .TunerType = 0, 43 .tuner_type = 0,
44 .X_Offset = -1, 44 .x_offset = -1,
45 .Y_Offset = -1, 45 .y_offset = -1,
46 .ModelString = "Xanboo", 46 .model_string = "Xanboo",
47 }, 47 },
48 [BELKIN_VIDEOBUS_II] = { 48 [BELKIN_VIDEOBUS_II] = {
49 .Interface = -1, 49 .interface = -1,
50 .Codec = CODEC_SAA7113, 50 .codec = CODEC_SAA7113,
51 .VideoChannels = 2, 51 .video_channels = 2,
52 .VideoNorm = V4L2_STD_PAL, 52 .video_norm = V4L2_STD_PAL,
53 .AudioChannels = 1, 53 .audio_channels = 1,
54 .Radio = 0, 54 .radio = 0,
55 .vbi = 1, 55 .vbi = 1,
56 .Tuner = 0, 56 .tuner = 0,
57 .TunerType = 0, 57 .tuner_type = 0,
58 .X_Offset = 0, 58 .x_offset = 0,
59 .Y_Offset = 3, 59 .y_offset = 3,
60 .Dvi_yuv_override = 1, 60 .dvi_yuv_override = 1,
61 .Dvi_yuv = 7, 61 .dvi_yuv = 7,
62 .ModelString = "Belkin USB VideoBus II Adapter", 62 .model_string = "Belkin USB VideoBus II Adapter",
63 }, 63 },
64 [BELKIN_VIDEOBUS] = { 64 [BELKIN_VIDEOBUS] = {
65 .Interface = -1, 65 .interface = -1,
66 .Codec = CODEC_SAA7111, 66 .codec = CODEC_SAA7111,
67 .VideoChannels = 2, 67 .video_channels = 2,
68 .VideoNorm = V4L2_STD_NTSC, 68 .video_norm = V4L2_STD_NTSC,
69 .AudioChannels = 1, 69 .audio_channels = 1,
70 .Radio = 0, 70 .radio = 0,
71 .vbi = 1, 71 .vbi = 1,
72 .Tuner = 0, 72 .tuner = 0,
73 .TunerType = 0, 73 .tuner_type = 0,
74 .X_Offset = -1, 74 .x_offset = -1,
75 .Y_Offset = -1, 75 .y_offset = -1,
76 .ModelString = "Belkin Components USB VideoBus", 76 .model_string = "Belkin Components USB VideoBus",
77 }, 77 },
78 [BELKIN_USB_VIDEOBUS_II] = { 78 [BELKIN_USB_VIDEOBUS_II] = {
79 .Interface = -1, 79 .interface = -1,
80 .Codec = CODEC_SAA7113, 80 .codec = CODEC_SAA7113,
81 .VideoChannels = 2, 81 .video_channels = 2,
82 .VideoNorm = V4L2_STD_NTSC, 82 .video_norm = V4L2_STD_NTSC,
83 .AudioChannels = 1, 83 .audio_channels = 1,
84 .Radio = 0, 84 .radio = 0,
85 .vbi = 1, 85 .vbi = 1,
86 .Tuner = 0, 86 .tuner = 0,
87 .TunerType = 0, 87 .tuner_type = 0,
88 .X_Offset = 0, 88 .x_offset = 0,
89 .Y_Offset = 3, 89 .y_offset = 3,
90 .Dvi_yuv_override = 1, 90 .dvi_yuv_override = 1,
91 .Dvi_yuv = 7, 91 .dvi_yuv = 7,
92 .ModelString = "Belkin USB VideoBus II", 92 .model_string = "Belkin USB VideoBus II",
93 }, 93 },
94 [ECHOFX_INTERVIEW_LITE] = { 94 [ECHOFX_INTERVIEW_LITE] = {
95 .Interface = 0, 95 .interface = 0,
96 .Codec = CODEC_SAA7111, 96 .codec = CODEC_SAA7111,
97 .VideoChannels = 2, 97 .video_channels = 2,
98 .VideoNorm = V4L2_STD_PAL, 98 .video_norm = V4L2_STD_PAL,
99 .AudioChannels = 0, 99 .audio_channels = 0,
100 .Radio = 0, 100 .radio = 0,
101 .vbi = 1, 101 .vbi = 1,
102 .Tuner = 0, 102 .tuner = 0,
103 .TunerType = 0, 103 .tuner_type = 0,
104 .X_Offset = -1, 104 .x_offset = -1,
105 .Y_Offset = -1, 105 .y_offset = -1,
106 .Dvi_yuv_override = 1, 106 .dvi_yuv_override = 1,
107 .Dvi_yuv = 7, 107 .dvi_yuv = 7,
108 .ModelString = "echoFX InterView Lite", 108 .model_string = "echoFX InterView Lite",
109 }, 109 },
110 [USBGEAR_USBG_V1] = { 110 [USBGEAR_USBG_V1] = {
111 .Interface = -1, 111 .interface = -1,
112 .Codec = CODEC_SAA7111, 112 .codec = CODEC_SAA7111,
113 .VideoChannels = 2, 113 .video_channels = 2,
114 .VideoNorm = V4L2_STD_NTSC, 114 .video_norm = V4L2_STD_NTSC,
115 .AudioChannels = 1, 115 .audio_channels = 1,
116 .Radio = 0, 116 .radio = 0,
117 .vbi = 1, 117 .vbi = 1,
118 .Tuner = 0, 118 .tuner = 0,
119 .TunerType = 0, 119 .tuner_type = 0,
120 .X_Offset = -1, 120 .x_offset = -1,
121 .Y_Offset = -1, 121 .y_offset = -1,
122 .ModelString = "USBGear USBG-V1 resp. HAMA USB", 122 .model_string = "USBGear USBG-V1 resp. HAMA USB",
123 }, 123 },
124 [D_LINK_V100] = { 124 [D_LINK_V100] = {
125 .Interface = -1, 125 .interface = -1,
126 .Codec = CODEC_SAA7113, 126 .codec = CODEC_SAA7113,
127 .VideoChannels = 4, 127 .video_channels = 4,
128 .VideoNorm = V4L2_STD_NTSC, 128 .video_norm = V4L2_STD_NTSC,
129 .AudioChannels = 0, 129 .audio_channels = 0,
130 .Radio = 0, 130 .radio = 0,
131 .vbi = 1, 131 .vbi = 1,
132 .Tuner = 0, 132 .tuner = 0,
133 .TunerType = 0, 133 .tuner_type = 0,
134 .X_Offset = 0, 134 .x_offset = 0,
135 .Y_Offset = 3, 135 .y_offset = 3,
136 .Dvi_yuv_override = 1, 136 .dvi_yuv_override = 1,
137 .Dvi_yuv = 7, 137 .dvi_yuv = 7,
138 .ModelString = "D-Link V100", 138 .model_string = "D-Link V100",
139 }, 139 },
140 [X10_USB_CAMERA] = { 140 [X10_USB_CAMERA] = {
141 .Interface = -1, 141 .interface = -1,
142 .Codec = CODEC_SAA7111, 142 .codec = CODEC_SAA7111,
143 .VideoChannels = 2, 143 .video_channels = 2,
144 .VideoNorm = V4L2_STD_NTSC, 144 .video_norm = V4L2_STD_NTSC,
145 .AudioChannels = 1, 145 .audio_channels = 1,
146 .Radio = 0, 146 .radio = 0,
147 .vbi = 1, 147 .vbi = 1,
148 .Tuner = 0, 148 .tuner = 0,
149 .TunerType = 0, 149 .tuner_type = 0,
150 .X_Offset = -1, 150 .x_offset = -1,
151 .Y_Offset = -1, 151 .y_offset = -1,
152 .ModelString = "X10 USB Camera", 152 .model_string = "X10 USB Camera",
153 }, 153 },
154 [HPG_WINTV_LIVE_PAL_BG] = { 154 [HPG_WINTV_LIVE_PAL_BG] = {
155 .Interface = -1, 155 .interface = -1,
156 .Codec = CODEC_SAA7111, 156 .codec = CODEC_SAA7111,
157 .VideoChannels = 2, 157 .video_channels = 2,
158 .VideoNorm = V4L2_STD_PAL, 158 .video_norm = V4L2_STD_PAL,
159 .AudioChannels = 1, 159 .audio_channels = 1,
160 .Radio = 0, 160 .radio = 0,
161 .vbi = 1, 161 .vbi = 1,
162 .Tuner = 0, 162 .tuner = 0,
163 .TunerType = 0, 163 .tuner_type = 0,
164 .X_Offset = -1, 164 .x_offset = -1,
165 .Y_Offset = 3, 165 .y_offset = 3,
166 .Dvi_yuv_override = 1, 166 .dvi_yuv_override = 1,
167 .Dvi_yuv = 7, 167 .dvi_yuv = 7,
168 .ModelString = "Hauppauge WinTV USB Live (PAL B/G)", 168 .model_string = "Hauppauge WinTV USB Live (PAL B/G)",
169 }, 169 },
170 [HPG_WINTV_LIVE_PRO_NTSC_MN] = { 170 [HPG_WINTV_LIVE_PRO_NTSC_MN] = {
171 .Interface = -1, 171 .interface = -1,
172 .Codec = CODEC_SAA7113, 172 .codec = CODEC_SAA7113,
173 .VideoChannels = 2, 173 .video_channels = 2,
174 .VideoNorm = V4L2_STD_NTSC, 174 .video_norm = V4L2_STD_NTSC,
175 .AudioChannels = 0, 175 .audio_channels = 0,
176 .Radio = 0, 176 .radio = 0,
177 .vbi = 1, 177 .vbi = 1,
178 .Tuner = 0, 178 .tuner = 0,
179 .TunerType = 0, 179 .tuner_type = 0,
180 .X_Offset = 0, 180 .x_offset = 0,
181 .Y_Offset = 3, 181 .y_offset = 3,
182 .Dvi_yuv_override = 1, 182 .dvi_yuv_override = 1,
183 .Dvi_yuv = 7, 183 .dvi_yuv = 7,
184 .ModelString = "Hauppauge WinTV USB Live Pro (NTSC M/N)", 184 .model_string = "Hauppauge WinTV USB Live Pro (NTSC M/N)",
185 }, 185 },
186 [ZORAN_PMD_NOGATECH] = { 186 [ZORAN_PMD_NOGATECH] = {
187 .Interface = -1, 187 .interface = -1,
188 .Codec = CODEC_SAA7113, 188 .codec = CODEC_SAA7113,
189 .VideoChannels = 2, 189 .video_channels = 2,
190 .VideoNorm = V4L2_STD_PAL, 190 .video_norm = V4L2_STD_PAL,
191 .AudioChannels = 2, 191 .audio_channels = 2,
192 .Radio = 0, 192 .radio = 0,
193 .vbi = 1, 193 .vbi = 1,
194 .Tuner = 0, 194 .tuner = 0,
195 .TunerType = 0, 195 .tuner_type = 0,
196 .X_Offset = 0, 196 .x_offset = 0,
197 .Y_Offset = 3, 197 .y_offset = 3,
198 .Dvi_yuv_override = 1, 198 .dvi_yuv_override = 1,
199 .Dvi_yuv = 7, 199 .dvi_yuv = 7,
200 .ModelString = "Zoran Co. PMD (Nogatech) AV-grabber Manhattan", 200 .model_string = "Zoran Co. PMD (Nogatech) AV-grabber Manhattan",
201 }, 201 },
202 [NOGATECH_USB_TV_NTSC_FM] = { 202 [NOGATECH_USB_TV_NTSC_FM] = {
203 .Interface = -1, 203 .interface = -1,
204 .Codec = CODEC_SAA7111, 204 .codec = CODEC_SAA7111,
205 .VideoChannels = 3, 205 .video_channels = 3,
206 .VideoNorm = V4L2_STD_NTSC, 206 .video_norm = V4L2_STD_NTSC,
207 .AudioChannels = 1, 207 .audio_channels = 1,
208 .Radio = 1, 208 .radio = 1,
209 .vbi = 1, 209 .vbi = 1,
210 .Tuner = 1, 210 .tuner = 1,
211 .TunerType = TUNER_PHILIPS_NTSC_M, 211 .tuner_type = TUNER_PHILIPS_NTSC_M,
212 .X_Offset = -1, 212 .x_offset = -1,
213 .Y_Offset = 20, 213 .y_offset = 20,
214 .ModelString = "Nogatech USB-TV (NTSC) FM", 214 .model_string = "Nogatech USB-TV (NTSC) FM",
215 }, 215 },
216 [PNY_USB_TV_NTSC_FM] = { 216 [PNY_USB_TV_NTSC_FM] = {
217 .Interface = -1, 217 .interface = -1,
218 .Codec = CODEC_SAA7111, 218 .codec = CODEC_SAA7111,
219 .VideoChannels = 3, 219 .video_channels = 3,
220 .VideoNorm = V4L2_STD_NTSC, 220 .video_norm = V4L2_STD_NTSC,
221 .AudioChannels = 1, 221 .audio_channels = 1,
222 .Radio = 1, 222 .radio = 1,
223 .vbi = 1, 223 .vbi = 1,
224 .Tuner = 1, 224 .tuner = 1,
225 .TunerType = TUNER_PHILIPS_NTSC_M, 225 .tuner_type = TUNER_PHILIPS_NTSC_M,
226 .X_Offset = -1, 226 .x_offset = -1,
227 .Y_Offset = 20, 227 .y_offset = 20,
228 .ModelString = "PNY USB-TV (NTSC) FM", 228 .model_string = "PNY USB-TV (NTSC) FM",
229 }, 229 },
230 [PV_PLAYTV_USB_PRO_PAL_FM] = { 230 [PV_PLAYTV_USB_PRO_PAL_FM] = {
231 .Interface = 0, 231 .interface = 0,
232 .Codec = CODEC_SAA7113, 232 .codec = CODEC_SAA7113,
233 .VideoChannels = 3, 233 .video_channels = 3,
234 .VideoNorm = V4L2_STD_PAL, 234 .video_norm = V4L2_STD_PAL,
235 .AudioChannels = 1, 235 .audio_channels = 1,
236 .Radio = 1, 236 .radio = 1,
237 .vbi = 1, 237 .vbi = 1,
238 .Tuner = 1, 238 .tuner = 1,
239 .TunerType = TUNER_PHILIPS_PAL, 239 .tuner_type = TUNER_PHILIPS_PAL,
240 .X_Offset = 0, 240 .x_offset = 0,
241 .Y_Offset = 3, 241 .y_offset = 3,
242 .Dvi_yuv_override = 1, 242 .dvi_yuv_override = 1,
243 .Dvi_yuv = 7, 243 .dvi_yuv = 7,
244 .ModelString = "PixelView PlayTv-USB PRO (PAL) FM", 244 .model_string = "PixelView PlayTv-USB PRO (PAL) FM",
245 }, 245 },
246 [ZT_721] = { 246 [ZT_721] = {
247 .Interface = 0, 247 .interface = 0,
248 .Codec = CODEC_SAA7113, 248 .codec = CODEC_SAA7113,
249 .VideoChannels = 3, 249 .video_channels = 3,
250 .VideoNorm = V4L2_STD_PAL, 250 .video_norm = V4L2_STD_PAL,
251 .AudioChannels = 1, 251 .audio_channels = 1,
252 .Radio = 1, 252 .radio = 1,
253 .vbi = 1, 253 .vbi = 1,
254 .Tuner = 1, 254 .tuner = 1,
255 .TunerType = TUNER_PHILIPS_PAL, 255 .tuner_type = TUNER_PHILIPS_PAL,
256 .X_Offset = 0, 256 .x_offset = 0,
257 .Y_Offset = 3, 257 .y_offset = 3,
258 .Dvi_yuv_override = 1, 258 .dvi_yuv_override = 1,
259 .Dvi_yuv = 7, 259 .dvi_yuv = 7,
260 .ModelString = "ZTV ZT-721 2.4GHz USB A/V Receiver", 260 .model_string = "ZTV ZT-721 2.4GHz USB A/V Receiver",
261 }, 261 },
262 [HPG_WINTV_NTSC_MN] = { 262 [HPG_WINTV_NTSC_MN] = {
263 .Interface = -1, 263 .interface = -1,
264 .Codec = CODEC_SAA7111, 264 .codec = CODEC_SAA7111,
265 .VideoChannels = 3, 265 .video_channels = 3,
266 .VideoNorm = V4L2_STD_NTSC, 266 .video_norm = V4L2_STD_NTSC,
267 .AudioChannels = 1, 267 .audio_channels = 1,
268 .Radio = 0, 268 .radio = 0,
269 .vbi = 1, 269 .vbi = 1,
270 .Tuner = 1, 270 .tuner = 1,
271 .TunerType = TUNER_PHILIPS_NTSC_M, 271 .tuner_type = TUNER_PHILIPS_NTSC_M,
272 .X_Offset = -1, 272 .x_offset = -1,
273 .Y_Offset = 20, 273 .y_offset = 20,
274 .ModelString = "Hauppauge WinTV USB (NTSC M/N)", 274 .model_string = "Hauppauge WinTV USB (NTSC M/N)",
275 }, 275 },
276 [HPG_WINTV_PAL_BG] = { 276 [HPG_WINTV_PAL_BG] = {
277 .Interface = -1, 277 .interface = -1,
278 .Codec = CODEC_SAA7111, 278 .codec = CODEC_SAA7111,
279 .VideoChannels = 3, 279 .video_channels = 3,
280 .VideoNorm = V4L2_STD_PAL, 280 .video_norm = V4L2_STD_PAL,
281 .AudioChannels = 1, 281 .audio_channels = 1,
282 .Radio = 0, 282 .radio = 0,
283 .vbi = 1, 283 .vbi = 1,
284 .Tuner = 1, 284 .tuner = 1,
285 .TunerType = TUNER_PHILIPS_PAL, 285 .tuner_type = TUNER_PHILIPS_PAL,
286 .X_Offset = -1, 286 .x_offset = -1,
287 .Y_Offset = -1, 287 .y_offset = -1,
288 .ModelString = "Hauppauge WinTV USB (PAL B/G)", 288 .model_string = "Hauppauge WinTV USB (PAL B/G)",
289 }, 289 },
290 [HPG_WINTV_PAL_I] = { 290 [HPG_WINTV_PAL_I] = {
291 .Interface = -1, 291 .interface = -1,
292 .Codec = CODEC_SAA7111, 292 .codec = CODEC_SAA7111,
293 .VideoChannels = 3, 293 .video_channels = 3,
294 .VideoNorm = V4L2_STD_PAL, 294 .video_norm = V4L2_STD_PAL,
295 .AudioChannels = 1, 295 .audio_channels = 1,
296 .Radio = 0, 296 .radio = 0,
297 .vbi = 1, 297 .vbi = 1,
298 .Tuner = 1, 298 .tuner = 1,
299 .TunerType = TUNER_PHILIPS_PAL, 299 .tuner_type = TUNER_PHILIPS_PAL,
300 .X_Offset = -1, 300 .x_offset = -1,
301 .Y_Offset = -1, 301 .y_offset = -1,
302 .ModelString = "Hauppauge WinTV USB (PAL I)", 302 .model_string = "Hauppauge WinTV USB (PAL I)",
303 }, 303 },
304 [HPG_WINTV_PAL_SECAM_L] = { 304 [HPG_WINTV_PAL_SECAM_L] = {
305 .Interface = -1, 305 .interface = -1,
306 .Codec = CODEC_SAA7111, 306 .codec = CODEC_SAA7111,
307 .VideoChannels = 3, 307 .video_channels = 3,
308 .VideoNorm = V4L2_STD_SECAM, 308 .video_norm = V4L2_STD_SECAM,
309 .AudioChannels = 1, 309 .audio_channels = 1,
310 .Radio = 0, 310 .radio = 0,
311 .vbi = 1, 311 .vbi = 1,
312 .Tuner = 1, 312 .tuner = 1,
313 .TunerType = TUNER_PHILIPS_SECAM, 313 .tuner_type = TUNER_PHILIPS_SECAM,
314 .X_Offset = 0x80, 314 .x_offset = 0x80,
315 .Y_Offset = 0x16, 315 .y_offset = 0x16,
316 .ModelString = "Hauppauge WinTV USB (PAL/SECAM L)", 316 .model_string = "Hauppauge WinTV USB (PAL/SECAM L)",
317 }, 317 },
318 [HPG_WINTV_PAL_D_K] = { 318 [HPG_WINTV_PAL_D_K] = {
319 .Interface = -1, 319 .interface = -1,
320 .Codec = CODEC_SAA7111, 320 .codec = CODEC_SAA7111,
321 .VideoChannels = 3, 321 .video_channels = 3,
322 .VideoNorm = V4L2_STD_PAL, 322 .video_norm = V4L2_STD_PAL,
323 .AudioChannels = 1, 323 .audio_channels = 1,
324 .Radio = 0, 324 .radio = 0,
325 .vbi = 1, 325 .vbi = 1,
326 .Tuner = 1, 326 .tuner = 1,
327 .TunerType = TUNER_PHILIPS_PAL, 327 .tuner_type = TUNER_PHILIPS_PAL,
328 .X_Offset = -1, 328 .x_offset = -1,
329 .Y_Offset = -1, 329 .y_offset = -1,
330 .ModelString = "Hauppauge WinTV USB (PAL D/K)", 330 .model_string = "Hauppauge WinTV USB (PAL D/K)",
331 }, 331 },
332 [HPG_WINTV_NTSC_FM] = { 332 [HPG_WINTV_NTSC_FM] = {
333 .Interface = -1, 333 .interface = -1,
334 .Codec = CODEC_SAA7111, 334 .codec = CODEC_SAA7111,
335 .VideoChannels = 3, 335 .video_channels = 3,
336 .VideoNorm = V4L2_STD_NTSC, 336 .video_norm = V4L2_STD_NTSC,
337 .AudioChannels = 1, 337 .audio_channels = 1,
338 .Radio = 1, 338 .radio = 1,
339 .vbi = 1, 339 .vbi = 1,
340 .Tuner = 1, 340 .tuner = 1,
341 .TunerType = TUNER_PHILIPS_NTSC_M, 341 .tuner_type = TUNER_PHILIPS_NTSC_M,
342 .X_Offset = -1, 342 .x_offset = -1,
343 .Y_Offset = -1, 343 .y_offset = -1,
344 .ModelString = "Hauppauge WinTV USB (NTSC FM)", 344 .model_string = "Hauppauge WinTV USB (NTSC FM)",
345 }, 345 },
346 [HPG_WINTV_PAL_BG_FM] = { 346 [HPG_WINTV_PAL_BG_FM] = {
347 .Interface = -1, 347 .interface = -1,
348 .Codec = CODEC_SAA7111, 348 .codec = CODEC_SAA7111,
349 .VideoChannels = 3, 349 .video_channels = 3,
350 .VideoNorm = V4L2_STD_PAL, 350 .video_norm = V4L2_STD_PAL,
351 .AudioChannels = 1, 351 .audio_channels = 1,
352 .Radio = 1, 352 .radio = 1,
353 .vbi = 1, 353 .vbi = 1,
354 .Tuner = 1, 354 .tuner = 1,
355 .TunerType = TUNER_PHILIPS_PAL, 355 .tuner_type = TUNER_PHILIPS_PAL,
356 .X_Offset = -1, 356 .x_offset = -1,
357 .Y_Offset = -1, 357 .y_offset = -1,
358 .ModelString = "Hauppauge WinTV USB (PAL B/G FM)", 358 .model_string = "Hauppauge WinTV USB (PAL B/G FM)",
359 }, 359 },
360 [HPG_WINTV_PAL_I_FM] = { 360 [HPG_WINTV_PAL_I_FM] = {
361 .Interface = -1, 361 .interface = -1,
362 .Codec = CODEC_SAA7111, 362 .codec = CODEC_SAA7111,
363 .VideoChannels = 3, 363 .video_channels = 3,
364 .VideoNorm = V4L2_STD_PAL, 364 .video_norm = V4L2_STD_PAL,
365 .AudioChannels = 1, 365 .audio_channels = 1,
366 .Radio = 1, 366 .radio = 1,
367 .vbi = 1, 367 .vbi = 1,
368 .Tuner = 1, 368 .tuner = 1,
369 .TunerType = TUNER_PHILIPS_PAL, 369 .tuner_type = TUNER_PHILIPS_PAL,
370 .X_Offset = -1, 370 .x_offset = -1,
371 .Y_Offset = -1, 371 .y_offset = -1,
372 .ModelString = "Hauppauge WinTV USB (PAL I FM)", 372 .model_string = "Hauppauge WinTV USB (PAL I FM)",
373 }, 373 },
374 [HPG_WINTV_PAL_D_K_FM] = { 374 [HPG_WINTV_PAL_D_K_FM] = {
375 .Interface = -1, 375 .interface = -1,
376 .Codec = CODEC_SAA7111, 376 .codec = CODEC_SAA7111,
377 .VideoChannels = 3, 377 .video_channels = 3,
378 .VideoNorm = V4L2_STD_PAL, 378 .video_norm = V4L2_STD_PAL,
379 .AudioChannels = 1, 379 .audio_channels = 1,
380 .Radio = 1, 380 .radio = 1,
381 .vbi = 1, 381 .vbi = 1,
382 .Tuner = 1, 382 .tuner = 1,
383 .TunerType = TUNER_PHILIPS_PAL, 383 .tuner_type = TUNER_PHILIPS_PAL,
384 .X_Offset = -1, 384 .x_offset = -1,
385 .Y_Offset = -1, 385 .y_offset = -1,
386 .ModelString = "Hauppauge WinTV USB (PAL D/K FM)", 386 .model_string = "Hauppauge WinTV USB (PAL D/K FM)",
387 }, 387 },
388 [HPG_WINTV_PRO_NTSC_MN] = { 388 [HPG_WINTV_PRO_NTSC_MN] = {
389 .Interface = 0, 389 .interface = 0,
390 .Codec = CODEC_SAA7113, 390 .codec = CODEC_SAA7113,
391 .VideoChannels = 3, 391 .video_channels = 3,
392 .VideoNorm = V4L2_STD_NTSC, 392 .video_norm = V4L2_STD_NTSC,
393 .AudioChannels = 1, 393 .audio_channels = 1,
394 .Radio = 1, 394 .radio = 1,
395 .vbi = 1, 395 .vbi = 1,
396 .Tuner = 1, 396 .tuner = 1,
397 .TunerType = TUNER_MICROTUNE_4049FM5, 397 .tuner_type = TUNER_MICROTUNE_4049FM5,
398 .X_Offset = 0, 398 .x_offset = 0,
399 .Y_Offset = 3, 399 .y_offset = 3,
400 .Dvi_yuv_override = 1, 400 .dvi_yuv_override = 1,
401 .Dvi_yuv = 7, 401 .dvi_yuv = 7,
402 .ModelString = "Hauppauge WinTV USB Pro (NTSC M/N)", 402 .model_string = "Hauppauge WinTV USB Pro (NTSC M/N)",
403 }, 403 },
404 [HPG_WINTV_PRO_NTSC_MN_V2] = { 404 [HPG_WINTV_PRO_NTSC_MN_V2] = {
405 .Interface = 0, 405 .interface = 0,
406 .Codec = CODEC_SAA7113, 406 .codec = CODEC_SAA7113,
407 .VideoChannels = 3, 407 .video_channels = 3,
408 .VideoNorm = V4L2_STD_NTSC, 408 .video_norm = V4L2_STD_NTSC,
409 .AudioChannels = 1, 409 .audio_channels = 1,
410 .Radio = 1, 410 .radio = 1,
411 .vbi = 1, 411 .vbi = 1,
412 .Tuner = 1, 412 .tuner = 1,
413 .TunerType = TUNER_MICROTUNE_4049FM5, 413 .tuner_type = TUNER_MICROTUNE_4049FM5,
414 .X_Offset = 0, 414 .x_offset = 0,
415 .Y_Offset = 3, 415 .y_offset = 3,
416 .Dvi_yuv_override = 1, 416 .dvi_yuv_override = 1,
417 .Dvi_yuv = 7, 417 .dvi_yuv = 7,
418 .ModelString = "Hauppauge WinTV USB Pro (NTSC M/N) V2", 418 .model_string = "Hauppauge WinTV USB Pro (NTSC M/N) V2",
419 }, 419 },
420 [HPG_WINTV_PRO_PAL] = { 420 [HPG_WINTV_PRO_PAL] = {
421 .Interface = 0, 421 .interface = 0,
422 .Codec = CODEC_SAA7113, 422 .codec = CODEC_SAA7113,
423 .VideoChannels = 3, 423 .video_channels = 3,
424 .VideoNorm = V4L2_STD_PAL, 424 .video_norm = V4L2_STD_PAL,
425 .AudioChannels = 1, 425 .audio_channels = 1,
426 .Radio = 0, 426 .radio = 0,
427 .vbi = 1, 427 .vbi = 1,
428 .Tuner = 1, 428 .tuner = 1,
429 .TunerType = TUNER_PHILIPS_FM1216ME_MK3, 429 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
430 .X_Offset = 0, 430 .x_offset = 0,
431 .Y_Offset = 3, 431 .y_offset = 3,
432 .Dvi_yuv_override = 1, 432 .dvi_yuv_override = 1,
433 .Dvi_yuv = 7, 433 .dvi_yuv = 7,
434 .ModelString = "Hauppauge WinTV USB Pro (PAL/SECAM B/G/I/D/K/L)", 434 .model_string = "Hauppauge WinTV USB Pro (PAL/SECAM B/G/I/D/K/L)",
435 }, 435 },
436 [HPG_WINTV_PRO_NTSC_MN_V3] = { 436 [HPG_WINTV_PRO_NTSC_MN_V3] = {
437 .Interface = 0, 437 .interface = 0,
438 .Codec = CODEC_SAA7113, 438 .codec = CODEC_SAA7113,
439 .VideoChannels = 3, 439 .video_channels = 3,
440 .VideoNorm = V4L2_STD_NTSC, 440 .video_norm = V4L2_STD_NTSC,
441 .AudioChannels = 1, 441 .audio_channels = 1,
442 .Radio = 1, 442 .radio = 1,
443 .vbi = 1, 443 .vbi = 1,
444 .Tuner = 1, 444 .tuner = 1,
445 .TunerType = TUNER_PHILIPS_NTSC_M, 445 .tuner_type = TUNER_PHILIPS_NTSC_M,
446 .X_Offset = 0, 446 .x_offset = 0,
447 .Y_Offset = 3, 447 .y_offset = 3,
448 .Dvi_yuv_override = 1, 448 .dvi_yuv_override = 1,
449 .Dvi_yuv = 7, 449 .dvi_yuv = 7,
450 .ModelString = "Hauppauge WinTV USB Pro (NTSC M/N) V3", 450 .model_string = "Hauppauge WinTV USB Pro (NTSC M/N) V3",
451 }, 451 },
452 [HPG_WINTV_PRO_PAL_BG] = { 452 [HPG_WINTV_PRO_PAL_BG] = {
453 .Interface = 0, 453 .interface = 0,
454 .Codec = CODEC_SAA7113, 454 .codec = CODEC_SAA7113,
455 .VideoChannels = 3, 455 .video_channels = 3,
456 .VideoNorm = V4L2_STD_PAL, 456 .video_norm = V4L2_STD_PAL,
457 .AudioChannels = 1, 457 .audio_channels = 1,
458 .Radio = 0, 458 .radio = 0,
459 .vbi = 1, 459 .vbi = 1,
460 .Tuner = 1, 460 .tuner = 1,
461 .TunerType = TUNER_PHILIPS_PAL, 461 .tuner_type = TUNER_PHILIPS_PAL,
462 .X_Offset = 0, 462 .x_offset = 0,
463 .Y_Offset = 3, 463 .y_offset = 3,
464 .Dvi_yuv_override = 1, 464 .dvi_yuv_override = 1,
465 .Dvi_yuv = 7, 465 .dvi_yuv = 7,
466 .ModelString = "Hauppauge WinTV USB Pro (PAL B/G)", 466 .model_string = "Hauppauge WinTV USB Pro (PAL B/G)",
467 }, 467 },
468 [HPG_WINTV_PRO_PAL_I] = { 468 [HPG_WINTV_PRO_PAL_I] = {
469 .Interface = 0, 469 .interface = 0,
470 .Codec = CODEC_SAA7113, 470 .codec = CODEC_SAA7113,
471 .VideoChannels = 3, 471 .video_channels = 3,
472 .VideoNorm = V4L2_STD_PAL, 472 .video_norm = V4L2_STD_PAL,
473 .AudioChannels = 1, 473 .audio_channels = 1,
474 .Radio = 0, 474 .radio = 0,
475 .vbi = 1, 475 .vbi = 1,
476 .Tuner = 1, 476 .tuner = 1,
477 .TunerType = TUNER_PHILIPS_PAL, 477 .tuner_type = TUNER_PHILIPS_PAL,
478 .X_Offset = 0, 478 .x_offset = 0,
479 .Y_Offset = 3, 479 .y_offset = 3,
480 .Dvi_yuv_override = 1, 480 .dvi_yuv_override = 1,
481 .Dvi_yuv = 7, 481 .dvi_yuv = 7,
482 .ModelString = "Hauppauge WinTV USB Pro (PAL I)", 482 .model_string = "Hauppauge WinTV USB Pro (PAL I)",
483 }, 483 },
484 [HPG_WINTV_PRO_PAL_SECAM_L] = { 484 [HPG_WINTV_PRO_PAL_SECAM_L] = {
485 .Interface = -1, 485 .interface = -1,
486 .Codec = CODEC_SAA7113, 486 .codec = CODEC_SAA7113,
487 .VideoChannels = 3, 487 .video_channels = 3,
488 .VideoNorm = V4L2_STD_SECAM, 488 .video_norm = V4L2_STD_SECAM,
489 .AudioChannels = 1, 489 .audio_channels = 1,
490 .Radio = 0, 490 .radio = 0,
491 .vbi = 1, 491 .vbi = 1,
492 .Tuner = 1, 492 .tuner = 1,
493 .TunerType = TUNER_PHILIPS_SECAM, 493 .tuner_type = TUNER_PHILIPS_SECAM,
494 .X_Offset = 0, 494 .x_offset = 0,
495 .Y_Offset = 3, 495 .y_offset = 3,
496 .Dvi_yuv_override = 1, 496 .dvi_yuv_override = 1,
497 .Dvi_yuv = 7, 497 .dvi_yuv = 7,
498 .ModelString = "Hauppauge WinTV USB Pro (PAL/SECAM L)", 498 .model_string = "Hauppauge WinTV USB Pro (PAL/SECAM L)",
499 }, 499 },
500 [HPG_WINTV_PRO_PAL_D_K] = { 500 [HPG_WINTV_PRO_PAL_D_K] = {
501 .Interface = -1, 501 .interface = -1,
502 .Codec = CODEC_SAA7113, 502 .codec = CODEC_SAA7113,
503 .VideoChannels = 3, 503 .video_channels = 3,
504 .VideoNorm = V4L2_STD_PAL, 504 .video_norm = V4L2_STD_PAL,
505 .AudioChannels = 1, 505 .audio_channels = 1,
506 .Radio = 0, 506 .radio = 0,
507 .vbi = 1, 507 .vbi = 1,
508 .Tuner = 1, 508 .tuner = 1,
509 .TunerType = TUNER_PHILIPS_PAL, 509 .tuner_type = TUNER_PHILIPS_PAL,
510 .X_Offset = 0, 510 .x_offset = 0,
511 .Y_Offset = 3, 511 .y_offset = 3,
512 .Dvi_yuv_override = 1, 512 .dvi_yuv_override = 1,
513 .Dvi_yuv = 7, 513 .dvi_yuv = 7,
514 .ModelString = "Hauppauge WinTV USB Pro (PAL D/K)", 514 .model_string = "Hauppauge WinTV USB Pro (PAL D/K)",
515 }, 515 },
516 [HPG_WINTV_PRO_PAL_SECAM] = { 516 [HPG_WINTV_PRO_PAL_SECAM] = {
517 .Interface = -1, 517 .interface = -1,
518 .Codec = CODEC_SAA7113, 518 .codec = CODEC_SAA7113,
519 .VideoChannels = 3, 519 .video_channels = 3,
520 .VideoNorm = V4L2_STD_SECAM, 520 .video_norm = V4L2_STD_SECAM,
521 .AudioChannels = 1, 521 .audio_channels = 1,
522 .Radio = 0, 522 .radio = 0,
523 .vbi = 1, 523 .vbi = 1,
524 .Tuner = 1, 524 .tuner = 1,
525 .TunerType = TUNER_PHILIPS_SECAM, 525 .tuner_type = TUNER_PHILIPS_SECAM,
526 .X_Offset = 0, 526 .x_offset = 0,
527 .Y_Offset = 3, 527 .y_offset = 3,
528 .Dvi_yuv_override = 1, 528 .dvi_yuv_override = 1,
529 .Dvi_yuv = 7, 529 .dvi_yuv = 7,
530 .ModelString = "Hauppauge WinTV USB Pro (PAL/SECAM BGDK/I/L)", 530 .model_string = "Hauppauge WinTV USB Pro (PAL/SECAM BGDK/I/L)",
531 }, 531 },
532 [HPG_WINTV_PRO_PAL_SECAM_V2] = { 532 [HPG_WINTV_PRO_PAL_SECAM_V2] = {
533 .Interface = -1, 533 .interface = -1,
534 .Codec = CODEC_SAA7113, 534 .codec = CODEC_SAA7113,
535 .VideoChannels = 3, 535 .video_channels = 3,
536 .VideoNorm = V4L2_STD_SECAM, 536 .video_norm = V4L2_STD_SECAM,
537 .AudioChannels = 1, 537 .audio_channels = 1,
538 .Radio = 0, 538 .radio = 0,
539 .vbi = 1, 539 .vbi = 1,
540 .Tuner = 1, 540 .tuner = 1,
541 .TunerType = TUNER_PHILIPS_SECAM, 541 .tuner_type = TUNER_PHILIPS_SECAM,
542 .X_Offset = 0, 542 .x_offset = 0,
543 .Y_Offset = 3, 543 .y_offset = 3,
544 .Dvi_yuv_override = 1, 544 .dvi_yuv_override = 1,
545 .Dvi_yuv = 7, 545 .dvi_yuv = 7,
546 .ModelString = "Hauppauge WinTV USB Pro (PAL/SECAM BGDK/I/L) V2", 546 .model_string = "Hauppauge WinTV USB Pro (PAL/SECAM BGDK/I/L) V2",
547 }, 547 },
548 [HPG_WINTV_PRO_PAL_BG_V2] = { 548 [HPG_WINTV_PRO_PAL_BG_V2] = {
549 .Interface = -1, 549 .interface = -1,
550 .Codec = CODEC_SAA7113, 550 .codec = CODEC_SAA7113,
551 .VideoChannels = 3, 551 .video_channels = 3,
552 .VideoNorm = V4L2_STD_PAL, 552 .video_norm = V4L2_STD_PAL,
553 .AudioChannels = 1, 553 .audio_channels = 1,
554 .Radio = 0, 554 .radio = 0,
555 .vbi = 1, 555 .vbi = 1,
556 .Tuner = 1, 556 .tuner = 1,
557 .TunerType = TUNER_ALPS_TSBE1_PAL, 557 .tuner_type = TUNER_ALPS_TSBE1_PAL,
558 .X_Offset = 0, 558 .x_offset = 0,
559 .Y_Offset = 3, 559 .y_offset = 3,
560 .Dvi_yuv_override = 1, 560 .dvi_yuv_override = 1,
561 .Dvi_yuv = 7, 561 .dvi_yuv = 7,
562 .ModelString = "Hauppauge WinTV USB Pro (PAL B/G) V2", 562 .model_string = "Hauppauge WinTV USB Pro (PAL B/G) V2",
563 }, 563 },
564 [HPG_WINTV_PRO_PAL_BG_D_K] = { 564 [HPG_WINTV_PRO_PAL_BG_D_K] = {
565 .Interface = -1, 565 .interface = -1,
566 .Codec = CODEC_SAA7113, 566 .codec = CODEC_SAA7113,
567 .VideoChannels = 3, 567 .video_channels = 3,
568 .VideoNorm = V4L2_STD_PAL, 568 .video_norm = V4L2_STD_PAL,
569 .AudioChannels = 1, 569 .audio_channels = 1,
570 .Radio = 0, 570 .radio = 0,
571 .vbi = 1, 571 .vbi = 1,
572 .Tuner = 1, 572 .tuner = 1,
573 .TunerType = TUNER_ALPS_TSBE1_PAL, 573 .tuner_type = TUNER_ALPS_TSBE1_PAL,
574 .X_Offset = 0, 574 .x_offset = 0,
575 .Y_Offset = 3, 575 .y_offset = 3,
576 .Dvi_yuv_override = 1, 576 .dvi_yuv_override = 1,
577 .Dvi_yuv = 7, 577 .dvi_yuv = 7,
578 .ModelString = "Hauppauge WinTV USB Pro (PAL B/G,D/K)", 578 .model_string = "Hauppauge WinTV USB Pro (PAL B/G,D/K)",
579 }, 579 },
580 [HPG_WINTV_PRO_PAL_I_D_K] = { 580 [HPG_WINTV_PRO_PAL_I_D_K] = {
581 .Interface = -1, 581 .interface = -1,
582 .Codec = CODEC_SAA7113, 582 .codec = CODEC_SAA7113,
583 .VideoChannels = 3, 583 .video_channels = 3,
584 .VideoNorm = V4L2_STD_PAL, 584 .video_norm = V4L2_STD_PAL,
585 .AudioChannels = 1, 585 .audio_channels = 1,
586 .Radio = 0, 586 .radio = 0,
587 .vbi = 1, 587 .vbi = 1,
588 .Tuner = 1, 588 .tuner = 1,
589 .TunerType = TUNER_LG_PAL_NEW_TAPC, 589 .tuner_type = TUNER_LG_PAL_NEW_TAPC,
590 .X_Offset = 0, 590 .x_offset = 0,
591 .Y_Offset = 3, 591 .y_offset = 3,
592 .Dvi_yuv_override = 1, 592 .dvi_yuv_override = 1,
593 .Dvi_yuv = 7, 593 .dvi_yuv = 7,
594 .ModelString = "Hauppauge WinTV USB Pro (PAL I,D/K)", 594 .model_string = "Hauppauge WinTV USB Pro (PAL I,D/K)",
595 }, 595 },
596 [HPG_WINTV_PRO_NTSC_MN_FM] = { 596 [HPG_WINTV_PRO_NTSC_MN_FM] = {
597 .Interface = -1, 597 .interface = -1,
598 .Codec = CODEC_SAA7113, 598 .codec = CODEC_SAA7113,
599 .VideoChannels = 3, 599 .video_channels = 3,
600 .VideoNorm = V4L2_STD_NTSC, 600 .video_norm = V4L2_STD_NTSC,
601 .AudioChannels = 1, 601 .audio_channels = 1,
602 .Radio = 1, 602 .radio = 1,
603 .vbi = 1, 603 .vbi = 1,
604 .Tuner = 1, 604 .tuner = 1,
605 .TunerType = TUNER_PHILIPS_NTSC_M, 605 .tuner_type = TUNER_PHILIPS_NTSC_M,
606 .X_Offset = 0, 606 .x_offset = 0,
607 .Y_Offset = 3, 607 .y_offset = 3,
608 .Dvi_yuv_override = 1, 608 .dvi_yuv_override = 1,
609 .Dvi_yuv = 7, 609 .dvi_yuv = 7,
610 .ModelString = "Hauppauge WinTV USB Pro (NTSC M/N FM)", 610 .model_string = "Hauppauge WinTV USB Pro (NTSC M/N FM)",
611 }, 611 },
612 [HPG_WINTV_PRO_PAL_BG_FM] = { 612 [HPG_WINTV_PRO_PAL_BG_FM] = {
613 .Interface = 0, 613 .interface = 0,
614 .Codec = CODEC_SAA7113, 614 .codec = CODEC_SAA7113,
615 .VideoChannels = 3, 615 .video_channels = 3,
616 .VideoNorm = V4L2_STD_PAL, 616 .video_norm = V4L2_STD_PAL,
617 .AudioChannels = 1, 617 .audio_channels = 1,
618 .Radio = 1, 618 .radio = 1,
619 .vbi = 1, 619 .vbi = 1,
620 .Tuner = 1, 620 .tuner = 1,
621 .TunerType = TUNER_PHILIPS_PAL, 621 .tuner_type = TUNER_PHILIPS_PAL,
622 .X_Offset = 0, 622 .x_offset = 0,
623 .Y_Offset = 3, 623 .y_offset = 3,
624 .Dvi_yuv_override = 1, 624 .dvi_yuv_override = 1,
625 .Dvi_yuv = 7, 625 .dvi_yuv = 7,
626 .ModelString = "Hauppauge WinTV USB Pro (PAL B/G FM)", 626 .model_string = "Hauppauge WinTV USB Pro (PAL B/G FM)",
627 }, 627 },
628 [HPG_WINTV_PRO_PAL_I_FM] = { 628 [HPG_WINTV_PRO_PAL_I_FM] = {
629 .Interface = 0, 629 .interface = 0,
630 .Codec = CODEC_SAA7113, 630 .codec = CODEC_SAA7113,
631 .VideoChannels = 3, 631 .video_channels = 3,
632 .VideoNorm = V4L2_STD_PAL, 632 .video_norm = V4L2_STD_PAL,
633 .AudioChannels = 1, 633 .audio_channels = 1,
634 .Radio = 1, 634 .radio = 1,
635 .vbi = 1, 635 .vbi = 1,
636 .Tuner = 1, 636 .tuner = 1,
637 .TunerType = TUNER_PHILIPS_PAL, 637 .tuner_type = TUNER_PHILIPS_PAL,
638 .X_Offset = 0, 638 .x_offset = 0,
639 .Y_Offset = 3, 639 .y_offset = 3,
640 .Dvi_yuv_override = 1, 640 .dvi_yuv_override = 1,
641 .Dvi_yuv = 7, 641 .dvi_yuv = 7,
642 .ModelString = "Hauppauge WinTV USB Pro (PAL I FM)", 642 .model_string = "Hauppauge WinTV USB Pro (PAL I FM)",
643 }, 643 },
644 [HPG_WINTV_PRO_PAL_D_K_FM] = { 644 [HPG_WINTV_PRO_PAL_D_K_FM] = {
645 .Interface = 0, 645 .interface = 0,
646 .Codec = CODEC_SAA7113, 646 .codec = CODEC_SAA7113,
647 .VideoChannels = 3, 647 .video_channels = 3,
648 .VideoNorm = V4L2_STD_PAL, 648 .video_norm = V4L2_STD_PAL,
649 .AudioChannels = 1, 649 .audio_channels = 1,
650 .Radio = 1, 650 .radio = 1,
651 .vbi = 1, 651 .vbi = 1,
652 .Tuner = 1, 652 .tuner = 1,
653 .TunerType = TUNER_PHILIPS_PAL, 653 .tuner_type = TUNER_PHILIPS_PAL,
654 .X_Offset = 0, 654 .x_offset = 0,
655 .Y_Offset = 3, 655 .y_offset = 3,
656 .Dvi_yuv_override = 1, 656 .dvi_yuv_override = 1,
657 .Dvi_yuv = 7, 657 .dvi_yuv = 7,
658 .ModelString = "Hauppauge WinTV USB Pro (PAL D/K FM)", 658 .model_string = "Hauppauge WinTV USB Pro (PAL D/K FM)",
659 }, 659 },
660 [HPG_WINTV_PRO_TEMIC_PAL_FM] = { 660 [HPG_WINTV_PRO_TEMIC_PAL_FM] = {
661 .Interface = 0, 661 .interface = 0,
662 .Codec = CODEC_SAA7113, 662 .codec = CODEC_SAA7113,
663 .VideoChannels = 3, 663 .video_channels = 3,
664 .VideoNorm = V4L2_STD_PAL, 664 .video_norm = V4L2_STD_PAL,
665 .AudioChannels = 1, 665 .audio_channels = 1,
666 .Radio = 1, 666 .radio = 1,
667 .vbi = 1, 667 .vbi = 1,
668 .Tuner = 1, 668 .tuner = 1,
669 .TunerType = TUNER_MICROTUNE_4049FM5, 669 .tuner_type = TUNER_MICROTUNE_4049FM5,
670 .X_Offset = 0, 670 .x_offset = 0,
671 .Y_Offset = 3, 671 .y_offset = 3,
672 .Dvi_yuv_override = 1, 672 .dvi_yuv_override = 1,
673 .Dvi_yuv = 7, 673 .dvi_yuv = 7,
674 .ModelString = "Hauppauge WinTV USB Pro (Temic PAL/SECAM B/G/I/D/K/L FM)", 674 .model_string = "Hauppauge WinTV USB Pro (Temic PAL/SECAM B/G/I/D/K/L FM)",
675 }, 675 },
676 [HPG_WINTV_PRO_TEMIC_PAL_BG_FM] = { 676 [HPG_WINTV_PRO_TEMIC_PAL_BG_FM] = {
677 .Interface = 0, 677 .interface = 0,
678 .Codec = CODEC_SAA7113, 678 .codec = CODEC_SAA7113,
679 .VideoChannels = 3, 679 .video_channels = 3,
680 .VideoNorm = V4L2_STD_PAL, 680 .video_norm = V4L2_STD_PAL,
681 .AudioChannels = 1, 681 .audio_channels = 1,
682 .Radio = 1, 682 .radio = 1,
683 .vbi = 1, 683 .vbi = 1,
684 .Tuner = 1, 684 .tuner = 1,
685 .TunerType = TUNER_MICROTUNE_4049FM5, 685 .tuner_type = TUNER_MICROTUNE_4049FM5,
686 .X_Offset = 0, 686 .x_offset = 0,
687 .Y_Offset = 3, 687 .y_offset = 3,
688 .Dvi_yuv_override = 1, 688 .dvi_yuv_override = 1,
689 .Dvi_yuv = 7, 689 .dvi_yuv = 7,
690 .ModelString = "Hauppauge WinTV USB Pro (Temic PAL B/G FM)", 690 .model_string = "Hauppauge WinTV USB Pro (Temic PAL B/G FM)",
691 }, 691 },
692 [HPG_WINTV_PRO_PAL_FM] = { 692 [HPG_WINTV_PRO_PAL_FM] = {
693 .Interface = 0, 693 .interface = 0,
694 .Codec = CODEC_SAA7113, 694 .codec = CODEC_SAA7113,
695 .VideoChannels = 3, 695 .video_channels = 3,
696 .VideoNorm = V4L2_STD_PAL, 696 .video_norm = V4L2_STD_PAL,
697 .AudioChannels = 1, 697 .audio_channels = 1,
698 .Radio = 1, 698 .radio = 1,
699 .vbi = 1, 699 .vbi = 1,
700 .Tuner = 1, 700 .tuner = 1,
701 .TunerType = TUNER_PHILIPS_FM1216ME_MK3, 701 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
702 .X_Offset = 0, 702 .x_offset = 0,
703 .Y_Offset = 3, 703 .y_offset = 3,
704 .Dvi_yuv_override = 1, 704 .dvi_yuv_override = 1,
705 .Dvi_yuv = 7, 705 .dvi_yuv = 7,
706 .ModelString = "Hauppauge WinTV USB Pro (PAL/SECAM B/G/I/D/K/L FM)", 706 .model_string = "Hauppauge WinTV USB Pro (PAL/SECAM B/G/I/D/K/L FM)",
707 }, 707 },
708 [HPG_WINTV_PRO_NTSC_MN_FM_V2] = { 708 [HPG_WINTV_PRO_NTSC_MN_FM_V2] = {
709 .Interface = 0, 709 .interface = 0,
710 .Codec = CODEC_SAA7113, 710 .codec = CODEC_SAA7113,
711 .VideoChannels = 3, 711 .video_channels = 3,
712 .VideoNorm = V4L2_STD_NTSC, 712 .video_norm = V4L2_STD_NTSC,
713 .AudioChannels = 1, 713 .audio_channels = 1,
714 .Radio = 1, 714 .radio = 1,
715 .vbi = 1, 715 .vbi = 1,
716 .Tuner = 1, 716 .tuner = 1,
717 .TunerType = TUNER_PHILIPS_NTSC_M, 717 .tuner_type = TUNER_PHILIPS_NTSC_M,
718 .X_Offset = 0, 718 .x_offset = 0,
719 .Y_Offset = 3, 719 .y_offset = 3,
720 .Dvi_yuv_override = 1, 720 .dvi_yuv_override = 1,
721 .Dvi_yuv = 7, 721 .dvi_yuv = 7,
722 .ModelString = "Hauppauge WinTV USB Pro (NTSC M/N FM) V2", 722 .model_string = "Hauppauge WinTV USB Pro (NTSC M/N FM) V2",
723 }, 723 },
724 [CAMTEL_TVB330] = { 724 [CAMTEL_TVB330] = {
725 .Interface = -1, 725 .interface = -1,
726 .Codec = CODEC_SAA7113, 726 .codec = CODEC_SAA7113,
727 .VideoChannels = 3, 727 .video_channels = 3,
728 .VideoNorm = V4L2_STD_NTSC, 728 .video_norm = V4L2_STD_NTSC,
729 .AudioChannels = 1, 729 .audio_channels = 1,
730 .Radio = 1, 730 .radio = 1,
731 .vbi = 1, 731 .vbi = 1,
732 .Tuner = 1, 732 .tuner = 1,
733 .TunerType = TUNER_PHILIPS_NTSC_M, 733 .tuner_type = TUNER_PHILIPS_NTSC_M,
734 .X_Offset = 5, 734 .x_offset = 5,
735 .Y_Offset = 5, 735 .y_offset = 5,
736 .ModelString = "Camtel Technology USB TV Genie Pro FM Model TVB330", 736 .model_string = "Camtel Technology USB TV Genie Pro FM Model TVB330",
737 }, 737 },
738 [DIGITAL_VIDEO_CREATOR_I] = { 738 [DIGITAL_VIDEO_CREATOR_I] = {
739 .Interface = -1, 739 .interface = -1,
740 .Codec = CODEC_SAA7113, 740 .codec = CODEC_SAA7113,
741 .VideoChannels = 2, 741 .video_channels = 2,
742 .VideoNorm = V4L2_STD_PAL, 742 .video_norm = V4L2_STD_PAL,
743 .AudioChannels = 0, 743 .audio_channels = 0,
744 .Radio = 0, 744 .radio = 0,
745 .vbi = 1, 745 .vbi = 1,
746 .Tuner = 0, 746 .tuner = 0,
747 .TunerType = 0, 747 .tuner_type = 0,
748 .X_Offset = 0, 748 .x_offset = 0,
749 .Y_Offset = 3, 749 .y_offset = 3,
750 .Dvi_yuv_override = 1, 750 .dvi_yuv_override = 1,
751 .Dvi_yuv = 7, 751 .dvi_yuv = 7,
752 .ModelString = "Digital Video Creator I", 752 .model_string = "Digital Video Creator I",
753 }, 753 },
754 [GLOBAL_VILLAGE_GV_007_NTSC] = { 754 [GLOBAL_VILLAGE_GV_007_NTSC] = {
755 .Interface = -1, 755 .interface = -1,
756 .Codec = CODEC_SAA7111, 756 .codec = CODEC_SAA7111,
757 .VideoChannels = 2, 757 .video_channels = 2,
758 .VideoNorm = V4L2_STD_NTSC, 758 .video_norm = V4L2_STD_NTSC,
759 .AudioChannels = 0, 759 .audio_channels = 0,
760 .Radio = 0, 760 .radio = 0,
761 .vbi = 1, 761 .vbi = 1,
762 .Tuner = 0, 762 .tuner = 0,
763 .TunerType = 0, 763 .tuner_type = 0,
764 .X_Offset = 82, 764 .x_offset = 82,
765 .Y_Offset = 20, 765 .y_offset = 20,
766 .Dvi_yuv_override = 1, 766 .dvi_yuv_override = 1,
767 .Dvi_yuv = 7, 767 .dvi_yuv = 7,
768 .ModelString = "Global Village GV-007 (NTSC)", 768 .model_string = "Global Village GV-007 (NTSC)",
769 }, 769 },
770 [DAZZLE_DVC_50_REV_1_NTSC] = { 770 [DAZZLE_DVC_50_REV_1_NTSC] = {
771 .Interface = 0, 771 .interface = 0,
772 .Codec = CODEC_SAA7113, 772 .codec = CODEC_SAA7113,
773 .VideoChannels = 2, 773 .video_channels = 2,
774 .VideoNorm = V4L2_STD_NTSC, 774 .video_norm = V4L2_STD_NTSC,
775 .AudioChannels = 0, 775 .audio_channels = 0,
776 .Radio = 0, 776 .radio = 0,
777 .vbi = 1, 777 .vbi = 1,
778 .Tuner = 0, 778 .tuner = 0,
779 .TunerType = 0, 779 .tuner_type = 0,
780 .X_Offset = 0, 780 .x_offset = 0,
781 .Y_Offset = 3, 781 .y_offset = 3,
782 .Dvi_yuv_override = 1, 782 .dvi_yuv_override = 1,
783 .Dvi_yuv = 7, 783 .dvi_yuv = 7,
784 .ModelString = "Dazzle Fusion Model DVC-50 Rev 1 (NTSC)", 784 .model_string = "Dazzle Fusion Model DVC-50 Rev 1 (NTSC)",
785 }, 785 },
786 [DAZZLE_DVC_80_REV_1_PAL] = { 786 [DAZZLE_DVC_80_REV_1_PAL] = {
787 .Interface = 0, 787 .interface = 0,
788 .Codec = CODEC_SAA7113, 788 .codec = CODEC_SAA7113,
789 .VideoChannels = 2, 789 .video_channels = 2,
790 .VideoNorm = V4L2_STD_PAL, 790 .video_norm = V4L2_STD_PAL,
791 .AudioChannels = 0, 791 .audio_channels = 0,
792 .Radio = 0, 792 .radio = 0,
793 .vbi = 1, 793 .vbi = 1,
794 .Tuner = 0, 794 .tuner = 0,
795 .TunerType = 0, 795 .tuner_type = 0,
796 .X_Offset = 0, 796 .x_offset = 0,
797 .Y_Offset = 3, 797 .y_offset = 3,
798 .Dvi_yuv_override = 1, 798 .dvi_yuv_override = 1,
799 .Dvi_yuv = 7, 799 .dvi_yuv = 7,
800 .ModelString = "Dazzle Fusion Model DVC-80 Rev 1 (PAL)", 800 .model_string = "Dazzle Fusion Model DVC-80 Rev 1 (PAL)",
801 }, 801 },
802 [DAZZLE_DVC_90_REV_1_SECAM] = { 802 [DAZZLE_DVC_90_REV_1_SECAM] = {
803 .Interface = 0, 803 .interface = 0,
804 .Codec = CODEC_SAA7113, 804 .codec = CODEC_SAA7113,
805 .VideoChannels = 2, 805 .video_channels = 2,
806 .VideoNorm = V4L2_STD_SECAM, 806 .video_norm = V4L2_STD_SECAM,
807 .AudioChannels = 0, 807 .audio_channels = 0,
808 .Radio = 0, 808 .radio = 0,
809 .vbi = 1, 809 .vbi = 1,
810 .Tuner = 0, 810 .tuner = 0,
811 .TunerType = 0, 811 .tuner_type = 0,
812 .X_Offset = 0, 812 .x_offset = 0,
813 .Y_Offset = 3, 813 .y_offset = 3,
814 .Dvi_yuv_override = 1, 814 .dvi_yuv_override = 1,
815 .Dvi_yuv = 7, 815 .dvi_yuv = 7,
816 .ModelString = "Dazzle Fusion Model DVC-90 Rev 1 (SECAM)", 816 .model_string = "Dazzle Fusion Model DVC-90 Rev 1 (SECAM)",
817 }, 817 },
818 [ESKAPE_LABS_MYTV2GO] = { 818 [ESKAPE_LABS_MYTV2GO] = {
819 .Interface = 0, 819 .interface = 0,
820 .Codec = CODEC_SAA7113, 820 .codec = CODEC_SAA7113,
821 .VideoChannels = 2, 821 .video_channels = 2,
822 .VideoNorm = V4L2_STD_PAL, 822 .video_norm = V4L2_STD_PAL,
823 .AudioChannels = 1, 823 .audio_channels = 1,
824 .Radio = 1, 824 .radio = 1,
825 .vbi = 1, 825 .vbi = 1,
826 .Tuner = 1, 826 .tuner = 1,
827 .TunerType = TUNER_PHILIPS_FM1216ME_MK3, 827 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
828 .X_Offset = 0, 828 .x_offset = 0,
829 .Y_Offset = 3, 829 .y_offset = 3,
830 .Dvi_yuv_override = 1, 830 .dvi_yuv_override = 1,
831 .Dvi_yuv = 7, 831 .dvi_yuv = 7,
832 .ModelString = "Eskape Labs MyTV2Go", 832 .model_string = "Eskape Labs MyTV2Go",
833 }, 833 },
834 [PINNA_PCTV_USB_PAL] = { 834 [PINNA_PCTV_USB_PAL] = {
835 .Interface = -1, 835 .interface = -1,
836 .Codec = CODEC_SAA7111, 836 .codec = CODEC_SAA7111,
837 .VideoChannels = 3, 837 .video_channels = 3,
838 .VideoNorm = V4L2_STD_PAL, 838 .video_norm = V4L2_STD_PAL,
839 .AudioChannels = 1, 839 .audio_channels = 1,
840 .Radio = 0, 840 .radio = 0,
841 .vbi = 0, 841 .vbi = 0,
842 .Tuner = 1, 842 .tuner = 1,
843 .TunerType = TUNER_TEMIC_4066FY5_PAL_I, 843 .tuner_type = TUNER_TEMIC_4066FY5_PAL_I,
844 .X_Offset = -1, 844 .x_offset = -1,
845 .Y_Offset = -1, 845 .y_offset = -1,
846 .ModelString = "Pinnacle Studio PCTV USB (PAL)", 846 .model_string = "Pinnacle Studio PCTV USB (PAL)",
847 }, 847 },
848 [PINNA_PCTV_USB_SECAM] = { 848 [PINNA_PCTV_USB_SECAM] = {
849 .Interface = -1, 849 .interface = -1,
850 .Codec = CODEC_SAA7111, 850 .codec = CODEC_SAA7111,
851 .VideoChannels = 3, 851 .video_channels = 3,
852 .VideoNorm = V4L2_STD_SECAM, 852 .video_norm = V4L2_STD_SECAM,
853 .AudioChannels = 1, 853 .audio_channels = 1,
854 .Radio = 0, 854 .radio = 0,
855 .vbi = 1, 855 .vbi = 1,
856 .Tuner = 1, 856 .tuner = 1,
857 .TunerType = TUNER_PHILIPS_SECAM, 857 .tuner_type = TUNER_PHILIPS_SECAM,
858 .X_Offset = -1, 858 .x_offset = -1,
859 .Y_Offset = -1, 859 .y_offset = -1,
860 .ModelString = "Pinnacle Studio PCTV USB (SECAM)", 860 .model_string = "Pinnacle Studio PCTV USB (SECAM)",
861 }, 861 },
862 [PINNA_PCTV_USB_PAL_FM] = { 862 [PINNA_PCTV_USB_PAL_FM] = {
863 .Interface = -1, 863 .interface = -1,
864 .Codec = CODEC_SAA7111, 864 .codec = CODEC_SAA7111,
865 .VideoChannels = 3, 865 .video_channels = 3,
866 .VideoNorm = V4L2_STD_PAL, 866 .video_norm = V4L2_STD_PAL,
867 .AudioChannels = 1, 867 .audio_channels = 1,
868 .Radio = 1, 868 .radio = 1,
869 .vbi = 1, 869 .vbi = 1,
870 .Tuner = 1, 870 .tuner = 1,
871 .TunerType = TUNER_PHILIPS_PAL, 871 .tuner_type = TUNER_PHILIPS_PAL,
872 .X_Offset = 128, 872 .x_offset = 128,
873 .Y_Offset = 23, 873 .y_offset = 23,
874 .ModelString = "Pinnacle Studio PCTV USB (PAL) FM", 874 .model_string = "Pinnacle Studio PCTV USB (PAL) FM",
875 }, 875 },
876 [MIRO_PCTV_USB] = { 876 [MIRO_PCTV_USB] = {
877 .Interface = -1, 877 .interface = -1,
878 .Codec = CODEC_SAA7111, 878 .codec = CODEC_SAA7111,
879 .VideoChannels = 3, 879 .video_channels = 3,
880 .VideoNorm = V4L2_STD_PAL, 880 .video_norm = V4L2_STD_PAL,
881 .AudioChannels = 1, 881 .audio_channels = 1,
882 .Radio = 0, 882 .radio = 0,
883 .vbi = 1, 883 .vbi = 1,
884 .Tuner = 1, 884 .tuner = 1,
885 .TunerType = TUNER_PHILIPS_PAL, 885 .tuner_type = TUNER_PHILIPS_PAL,
886 .X_Offset = -1, 886 .x_offset = -1,
887 .Y_Offset = -1, 887 .y_offset = -1,
888 .ModelString = "Miro PCTV USB", 888 .model_string = "Miro PCTV USB",
889 }, 889 },
890 [PINNA_PCTV_USB_NTSC_FM] = { 890 [PINNA_PCTV_USB_NTSC_FM] = {
891 .Interface = -1, 891 .interface = -1,
892 .Codec = CODEC_SAA7111, 892 .codec = CODEC_SAA7111,
893 .VideoChannels = 3, 893 .video_channels = 3,
894 .VideoNorm = V4L2_STD_NTSC, 894 .video_norm = V4L2_STD_NTSC,
895 .AudioChannels = 1, 895 .audio_channels = 1,
896 .Radio = 1, 896 .radio = 1,
897 .vbi = 1, 897 .vbi = 1,
898 .Tuner = 1, 898 .tuner = 1,
899 .TunerType = TUNER_PHILIPS_NTSC_M, 899 .tuner_type = TUNER_PHILIPS_NTSC_M,
900 .X_Offset = -1, 900 .x_offset = -1,
901 .Y_Offset = -1, 901 .y_offset = -1,
902 .ModelString = "Pinnacle Studio PCTV USB (NTSC) FM", 902 .model_string = "Pinnacle Studio PCTV USB (NTSC) FM",
903 }, 903 },
904 [PINNA_PCTV_USB_NTSC_FM_V3] = { 904 [PINNA_PCTV_USB_NTSC_FM_V3] = {
905 .Interface = -1, 905 .interface = -1,
906 .Codec = CODEC_SAA7111, 906 .codec = CODEC_SAA7111,
907 .VideoChannels = 3, 907 .video_channels = 3,
908 .VideoNorm = V4L2_STD_NTSC, 908 .video_norm = V4L2_STD_NTSC,
909 .AudioChannels = 1, 909 .audio_channels = 1,
910 .Radio = 1, 910 .radio = 1,
911 .vbi = 1, 911 .vbi = 1,
912 .Tuner = 1, 912 .tuner = 1,
913 .TunerType = TUNER_PHILIPS_NTSC_M, 913 .tuner_type = TUNER_PHILIPS_NTSC_M,
914 .X_Offset = -1, 914 .x_offset = -1,
915 .Y_Offset = -1, 915 .y_offset = -1,
916 .ModelString = "Pinnacle Studio PCTV USB (NTSC) FM V3", 916 .model_string = "Pinnacle Studio PCTV USB (NTSC) FM V3",
917 }, 917 },
918 [PINNA_PCTV_USB_PAL_FM_V2] = { 918 [PINNA_PCTV_USB_PAL_FM_V2] = {
919 .Interface = -1, 919 .interface = -1,
920 .Codec = CODEC_SAA7113, 920 .codec = CODEC_SAA7113,
921 .VideoChannels = 3, 921 .video_channels = 3,
922 .VideoNorm = V4L2_STD_PAL, 922 .video_norm = V4L2_STD_PAL,
923 .AudioChannels = 1, 923 .audio_channels = 1,
924 .Radio = 1, 924 .radio = 1,
925 .vbi = 1, 925 .vbi = 1,
926 .Tuner = 1, 926 .tuner = 1,
927 .TunerType = TUNER_TEMIC_4009FR5_PAL, 927 .tuner_type = TUNER_TEMIC_4009FR5_PAL,
928 .X_Offset = 0, 928 .x_offset = 0,
929 .Y_Offset = 3, 929 .y_offset = 3,
930 .Dvi_yuv_override = 1, 930 .dvi_yuv_override = 1,
931 .Dvi_yuv = 7, 931 .dvi_yuv = 7,
932 .ModelString = "Pinnacle Studio PCTV USB (PAL) FM V2", 932 .model_string = "Pinnacle Studio PCTV USB (PAL) FM V2",
933 }, 933 },
934 [PINNA_PCTV_USB_NTSC_FM_V2] = { 934 [PINNA_PCTV_USB_NTSC_FM_V2] = {
935 .Interface = -1, 935 .interface = -1,
936 .Codec = CODEC_SAA7111, 936 .codec = CODEC_SAA7111,
937 .VideoChannels = 3, 937 .video_channels = 3,
938 .VideoNorm = V4L2_STD_NTSC, 938 .video_norm = V4L2_STD_NTSC,
939 .AudioChannels = 1, 939 .audio_channels = 1,
940 .Radio = 1, 940 .radio = 1,
941 .vbi = 1, 941 .vbi = 1,
942 .Tuner = 1, 942 .tuner = 1,
943 .TunerType = TUNER_TEMIC_4039FR5_NTSC, 943 .tuner_type = TUNER_TEMIC_4039FR5_NTSC,
944 .X_Offset = 0, 944 .x_offset = 0,
945 .Y_Offset = 3, 945 .y_offset = 3,
946 .Dvi_yuv_override = 1, 946 .dvi_yuv_override = 1,
947 .Dvi_yuv = 7, 947 .dvi_yuv = 7,
948 .ModelString = "Pinnacle Studio PCTV USB (NTSC) FM V2", 948 .model_string = "Pinnacle Studio PCTV USB (NTSC) FM V2",
949 }, 949 },
950 [PINNA_PCTV_USB_PAL_FM_V3] = { 950 [PINNA_PCTV_USB_PAL_FM_V3] = {
951 .Interface = -1, 951 .interface = -1,
952 .Codec = CODEC_SAA7113, 952 .codec = CODEC_SAA7113,
953 .VideoChannels = 3, 953 .video_channels = 3,
954 .VideoNorm = V4L2_STD_PAL, 954 .video_norm = V4L2_STD_PAL,
955 .AudioChannels = 1, 955 .audio_channels = 1,
956 .Radio = 1, 956 .radio = 1,
957 .vbi = 1, 957 .vbi = 1,
958 .Tuner = 1, 958 .tuner = 1,
959 .TunerType = TUNER_TEMIC_4009FR5_PAL, 959 .tuner_type = TUNER_TEMIC_4009FR5_PAL,
960 .X_Offset = 0, 960 .x_offset = 0,
961 .Y_Offset = 3, 961 .y_offset = 3,
962 .Dvi_yuv_override = 1, 962 .dvi_yuv_override = 1,
963 .Dvi_yuv = 7, 963 .dvi_yuv = 7,
964 .ModelString = "Pinnacle Studio PCTV USB (PAL) FM V3", 964 .model_string = "Pinnacle Studio PCTV USB (PAL) FM V3",
965 }, 965 },
966 [PINNA_LINX_VD_IN_CAB_NTSC] = { 966 [PINNA_LINX_VD_IN_CAB_NTSC] = {
967 .Interface = -1, 967 .interface = -1,
968 .Codec = CODEC_SAA7113, 968 .codec = CODEC_SAA7113,
969 .VideoChannels = 2, 969 .video_channels = 2,
970 .VideoNorm = V4L2_STD_NTSC, 970 .video_norm = V4L2_STD_NTSC,
971 .AudioChannels = 1, 971 .audio_channels = 1,
972 .Radio = 0, 972 .radio = 0,
973 .vbi = 1, 973 .vbi = 1,
974 .Tuner = 0, 974 .tuner = 0,
975 .TunerType = 0, 975 .tuner_type = 0,
976 .X_Offset = 0, 976 .x_offset = 0,
977 .Y_Offset = 3, 977 .y_offset = 3,
978 .Dvi_yuv_override = 1, 978 .dvi_yuv_override = 1,
979 .Dvi_yuv = 7, 979 .dvi_yuv = 7,
980 .ModelString = "Pinnacle Studio Linx Video input cable (NTSC)", 980 .model_string = "Pinnacle Studio Linx Video input cable (NTSC)",
981 }, 981 },
982 [PINNA_LINX_VD_IN_CAB_PAL] = { 982 [PINNA_LINX_VD_IN_CAB_PAL] = {
983 .Interface = -1, 983 .interface = -1,
984 .Codec = CODEC_SAA7113, 984 .codec = CODEC_SAA7113,
985 .VideoChannels = 2, 985 .video_channels = 2,
986 .VideoNorm = V4L2_STD_PAL, 986 .video_norm = V4L2_STD_PAL,
987 .AudioChannels = 1, 987 .audio_channels = 1,
988 .Radio = 0, 988 .radio = 0,
989 .vbi = 1, 989 .vbi = 1,
990 .Tuner = 0, 990 .tuner = 0,
991 .TunerType = 0, 991 .tuner_type = 0,
992 .X_Offset = 0, 992 .x_offset = 0,
993 .Y_Offset = 3, 993 .y_offset = 3,
994 .Dvi_yuv_override = 1, 994 .dvi_yuv_override = 1,
995 .Dvi_yuv = 7, 995 .dvi_yuv = 7,
996 .ModelString = "Pinnacle Studio Linx Video input cable (PAL)", 996 .model_string = "Pinnacle Studio Linx Video input cable (PAL)",
997 }, 997 },
998 [PINNA_PCTV_BUNGEE_PAL_FM] = { 998 [PINNA_PCTV_BUNGEE_PAL_FM] = {
999 .Interface = -1, 999 .interface = -1,
1000 .Codec = CODEC_SAA7113, 1000 .codec = CODEC_SAA7113,
1001 .VideoChannels = 3, 1001 .video_channels = 3,
1002 .VideoNorm = V4L2_STD_PAL, 1002 .video_norm = V4L2_STD_PAL,
1003 .AudioChannels = 1, 1003 .audio_channels = 1,
1004 .Radio = 1, 1004 .radio = 1,
1005 .vbi = 1, 1005 .vbi = 1,
1006 .Tuner = 1, 1006 .tuner = 1,
1007 .TunerType = TUNER_TEMIC_4009FR5_PAL, 1007 .tuner_type = TUNER_TEMIC_4009FR5_PAL,
1008 .X_Offset = 0, 1008 .x_offset = 0,
1009 .Y_Offset = 3, 1009 .y_offset = 3,
1010 .Dvi_yuv_override = 1, 1010 .dvi_yuv_override = 1,
1011 .Dvi_yuv = 7, 1011 .dvi_yuv = 7,
1012 .ModelString = "Pinnacle PCTV Bungee USB (PAL) FM", 1012 .model_string = "Pinnacle PCTV Bungee USB (PAL) FM",
1013 }, 1013 },
1014 [HPG_WINTV] = { 1014 [HPG_WINTV] = {
1015 .Interface = -1, 1015 .interface = -1,
1016 .Codec = CODEC_SAA7111, 1016 .codec = CODEC_SAA7111,
1017 .VideoChannels = 3, 1017 .video_channels = 3,
1018 .VideoNorm = V4L2_STD_NTSC, 1018 .video_norm = V4L2_STD_NTSC,
1019 .AudioChannels = 1, 1019 .audio_channels = 1,
1020 .Radio = 0, 1020 .radio = 0,
1021 .vbi = 1, 1021 .vbi = 1,
1022 .Tuner = 1, 1022 .tuner = 1,
1023 .TunerType = TUNER_PHILIPS_NTSC_M, 1023 .tuner_type = TUNER_PHILIPS_NTSC_M,
1024 .X_Offset = -1, 1024 .x_offset = -1,
1025 .Y_Offset = -1, 1025 .y_offset = -1,
1026 .ModelString = "Hauppauge WinTv-USB", 1026 .model_string = "Hauppauge WinTv-USB",
1027 }, 1027 },
1028}; 1028};
1029const int usbvision_device_data_size=ARRAY_SIZE(usbvision_device_data); 1029const int usbvision_device_data_size = ARRAY_SIZE(usbvision_device_data);
1030 1030
1031/* Supported Devices */ 1031/* Supported Devices */
1032 1032
1033struct usb_device_id usbvision_table [] = { 1033struct usb_device_id usbvision_table[] = {
1034 { USB_DEVICE(0x0a6f, 0x0400), .driver_info=XANBOO }, 1034 { USB_DEVICE(0x0a6f, 0x0400), .driver_info = XANBOO },
1035 { USB_DEVICE(0x050d, 0x0106), .driver_info=BELKIN_VIDEOBUS_II }, 1035 { USB_DEVICE(0x050d, 0x0106), .driver_info = BELKIN_VIDEOBUS_II },
1036 { USB_DEVICE(0x050d, 0x0207), .driver_info=BELKIN_VIDEOBUS }, 1036 { USB_DEVICE(0x050d, 0x0207), .driver_info = BELKIN_VIDEOBUS },
1037 { USB_DEVICE(0x050d, 0x0208), .driver_info=BELKIN_USB_VIDEOBUS_II }, 1037 { USB_DEVICE(0x050d, 0x0208), .driver_info = BELKIN_USB_VIDEOBUS_II },
1038 { USB_DEVICE(0x0571, 0x0002), .driver_info=ECHOFX_INTERVIEW_LITE }, 1038 { USB_DEVICE(0x0571, 0x0002), .driver_info = ECHOFX_INTERVIEW_LITE },
1039 { USB_DEVICE(0x0573, 0x0003), .driver_info=USBGEAR_USBG_V1 }, 1039 { USB_DEVICE(0x0573, 0x0003), .driver_info = USBGEAR_USBG_V1 },
1040 { USB_DEVICE(0x0573, 0x0400), .driver_info=D_LINK_V100 }, 1040 { USB_DEVICE(0x0573, 0x0400), .driver_info = D_LINK_V100 },
1041 { USB_DEVICE(0x0573, 0x2000), .driver_info=X10_USB_CAMERA }, 1041 { USB_DEVICE(0x0573, 0x2000), .driver_info = X10_USB_CAMERA },
1042 { USB_DEVICE(0x0573, 0x2d00), .driver_info=HPG_WINTV_LIVE_PAL_BG }, 1042 { USB_DEVICE(0x0573, 0x2d00), .driver_info = HPG_WINTV_LIVE_PAL_BG },
1043 { USB_DEVICE(0x0573, 0x2d01), .driver_info=HPG_WINTV_LIVE_PRO_NTSC_MN }, 1043 { USB_DEVICE(0x0573, 0x2d01), .driver_info = HPG_WINTV_LIVE_PRO_NTSC_MN },
1044 { USB_DEVICE(0x0573, 0x2101), .driver_info=ZORAN_PMD_NOGATECH }, 1044 { USB_DEVICE(0x0573, 0x2101), .driver_info = ZORAN_PMD_NOGATECH },
1045 { USB_DEVICE(0x0573, 0x4100), .driver_info=NOGATECH_USB_TV_NTSC_FM }, 1045 { USB_DEVICE(0x0573, 0x4100), .driver_info = NOGATECH_USB_TV_NTSC_FM },
1046 { USB_DEVICE(0x0573, 0x4110), .driver_info=PNY_USB_TV_NTSC_FM }, 1046 { USB_DEVICE(0x0573, 0x4110), .driver_info = PNY_USB_TV_NTSC_FM },
1047 { USB_DEVICE(0x0573, 0x4450), .driver_info=PV_PLAYTV_USB_PRO_PAL_FM }, 1047 { USB_DEVICE(0x0573, 0x4450), .driver_info = PV_PLAYTV_USB_PRO_PAL_FM },
1048 { USB_DEVICE(0x0573, 0x4550), .driver_info=ZT_721 }, 1048 { USB_DEVICE(0x0573, 0x4550), .driver_info = ZT_721 },
1049 { USB_DEVICE(0x0573, 0x4d00), .driver_info=HPG_WINTV_NTSC_MN }, 1049 { USB_DEVICE(0x0573, 0x4d00), .driver_info = HPG_WINTV_NTSC_MN },
1050 { USB_DEVICE(0x0573, 0x4d01), .driver_info=HPG_WINTV_PAL_BG }, 1050 { USB_DEVICE(0x0573, 0x4d01), .driver_info = HPG_WINTV_PAL_BG },
1051 { USB_DEVICE(0x0573, 0x4d02), .driver_info=HPG_WINTV_PAL_I }, 1051 { USB_DEVICE(0x0573, 0x4d02), .driver_info = HPG_WINTV_PAL_I },
1052 { USB_DEVICE(0x0573, 0x4d03), .driver_info=HPG_WINTV_PAL_SECAM_L }, 1052 { USB_DEVICE(0x0573, 0x4d03), .driver_info = HPG_WINTV_PAL_SECAM_L },
1053 { USB_DEVICE(0x0573, 0x4d04), .driver_info=HPG_WINTV_PAL_D_K }, 1053 { USB_DEVICE(0x0573, 0x4d04), .driver_info = HPG_WINTV_PAL_D_K },
1054 { USB_DEVICE(0x0573, 0x4d10), .driver_info=HPG_WINTV_NTSC_FM }, 1054 { USB_DEVICE(0x0573, 0x4d10), .driver_info = HPG_WINTV_NTSC_FM },
1055 { USB_DEVICE(0x0573, 0x4d11), .driver_info=HPG_WINTV_PAL_BG_FM }, 1055 { USB_DEVICE(0x0573, 0x4d11), .driver_info = HPG_WINTV_PAL_BG_FM },
1056 { USB_DEVICE(0x0573, 0x4d12), .driver_info=HPG_WINTV_PAL_I_FM }, 1056 { USB_DEVICE(0x0573, 0x4d12), .driver_info = HPG_WINTV_PAL_I_FM },
1057 { USB_DEVICE(0x0573, 0x4d14), .driver_info=HPG_WINTV_PAL_D_K_FM }, 1057 { USB_DEVICE(0x0573, 0x4d14), .driver_info = HPG_WINTV_PAL_D_K_FM },
1058 { USB_DEVICE(0x0573, 0x4d2a), .driver_info=HPG_WINTV_PRO_NTSC_MN }, 1058 { USB_DEVICE(0x0573, 0x4d2a), .driver_info = HPG_WINTV_PRO_NTSC_MN },
1059 { USB_DEVICE(0x0573, 0x4d2b), .driver_info=HPG_WINTV_PRO_NTSC_MN_V2 }, 1059 { USB_DEVICE(0x0573, 0x4d2b), .driver_info = HPG_WINTV_PRO_NTSC_MN_V2 },
1060 { USB_DEVICE(0x0573, 0x4d2c), .driver_info=HPG_WINTV_PRO_PAL }, 1060 { USB_DEVICE(0x0573, 0x4d2c), .driver_info = HPG_WINTV_PRO_PAL },
1061 { USB_DEVICE(0x0573, 0x4d20), .driver_info = HPG_WINTV_PRO_NTSC_MN_V3 }, 1061 { USB_DEVICE(0x0573, 0x4d20), .driver_info = HPG_WINTV_PRO_NTSC_MN_V3 },
1062 { USB_DEVICE(0x0573, 0x4d21), .driver_info=HPG_WINTV_PRO_PAL_BG }, 1062 { USB_DEVICE(0x0573, 0x4d21), .driver_info = HPG_WINTV_PRO_PAL_BG },
1063 { USB_DEVICE(0x0573, 0x4d22), .driver_info=HPG_WINTV_PRO_PAL_I }, 1063 { USB_DEVICE(0x0573, 0x4d22), .driver_info = HPG_WINTV_PRO_PAL_I },
1064 { USB_DEVICE(0x0573, 0x4d23), .driver_info=HPG_WINTV_PRO_PAL_SECAM_L }, 1064 { USB_DEVICE(0x0573, 0x4d23), .driver_info = HPG_WINTV_PRO_PAL_SECAM_L },
1065 { USB_DEVICE(0x0573, 0x4d24), .driver_info=HPG_WINTV_PRO_PAL_D_K }, 1065 { USB_DEVICE(0x0573, 0x4d24), .driver_info = HPG_WINTV_PRO_PAL_D_K },
1066 { USB_DEVICE(0x0573, 0x4d25), .driver_info=HPG_WINTV_PRO_PAL_SECAM }, 1066 { USB_DEVICE(0x0573, 0x4d25), .driver_info = HPG_WINTV_PRO_PAL_SECAM },
1067 { USB_DEVICE(0x0573, 0x4d26), .driver_info=HPG_WINTV_PRO_PAL_SECAM_V2 }, 1067 { USB_DEVICE(0x0573, 0x4d26), .driver_info = HPG_WINTV_PRO_PAL_SECAM_V2 },
1068 { USB_DEVICE(0x0573, 0x4d27), .driver_info=HPG_WINTV_PRO_PAL_BG_V2 }, 1068 { USB_DEVICE(0x0573, 0x4d27), .driver_info = HPG_WINTV_PRO_PAL_BG_V2 },
1069 { USB_DEVICE(0x0573, 0x4d28), .driver_info=HPG_WINTV_PRO_PAL_BG_D_K }, 1069 { USB_DEVICE(0x0573, 0x4d28), .driver_info = HPG_WINTV_PRO_PAL_BG_D_K },
1070 { USB_DEVICE(0x0573, 0x4d29), .driver_info=HPG_WINTV_PRO_PAL_I_D_K }, 1070 { USB_DEVICE(0x0573, 0x4d29), .driver_info = HPG_WINTV_PRO_PAL_I_D_K },
1071 { USB_DEVICE(0x0573, 0x4d30), .driver_info=HPG_WINTV_PRO_NTSC_MN_FM }, 1071 { USB_DEVICE(0x0573, 0x4d30), .driver_info = HPG_WINTV_PRO_NTSC_MN_FM },
1072 { USB_DEVICE(0x0573, 0x4d31), .driver_info=HPG_WINTV_PRO_PAL_BG_FM }, 1072 { USB_DEVICE(0x0573, 0x4d31), .driver_info = HPG_WINTV_PRO_PAL_BG_FM },
1073 { USB_DEVICE(0x0573, 0x4d32), .driver_info=HPG_WINTV_PRO_PAL_I_FM }, 1073 { USB_DEVICE(0x0573, 0x4d32), .driver_info = HPG_WINTV_PRO_PAL_I_FM },
1074 { USB_DEVICE(0x0573, 0x4d34), .driver_info=HPG_WINTV_PRO_PAL_D_K_FM }, 1074 { USB_DEVICE(0x0573, 0x4d34), .driver_info = HPG_WINTV_PRO_PAL_D_K_FM },
1075 { USB_DEVICE(0x0573, 0x4d35), .driver_info=HPG_WINTV_PRO_TEMIC_PAL_FM }, 1075 { USB_DEVICE(0x0573, 0x4d35), .driver_info = HPG_WINTV_PRO_TEMIC_PAL_FM },
1076 { USB_DEVICE(0x0573, 0x4d36), .driver_info=HPG_WINTV_PRO_TEMIC_PAL_BG_FM }, 1076 { USB_DEVICE(0x0573, 0x4d36), .driver_info = HPG_WINTV_PRO_TEMIC_PAL_BG_FM },
1077 { USB_DEVICE(0x0573, 0x4d37), .driver_info=HPG_WINTV_PRO_PAL_FM }, 1077 { USB_DEVICE(0x0573, 0x4d37), .driver_info = HPG_WINTV_PRO_PAL_FM },
1078 { USB_DEVICE(0x0573, 0x4d38), .driver_info=HPG_WINTV_PRO_NTSC_MN_FM_V2 }, 1078 { USB_DEVICE(0x0573, 0x4d38), .driver_info = HPG_WINTV_PRO_NTSC_MN_FM_V2 },
1079 { USB_DEVICE(0x0768, 0x0006), .driver_info=CAMTEL_TVB330 }, 1079 { USB_DEVICE(0x0768, 0x0006), .driver_info = CAMTEL_TVB330 },
1080 { USB_DEVICE(0x07d0, 0x0001), .driver_info=DIGITAL_VIDEO_CREATOR_I }, 1080 { USB_DEVICE(0x07d0, 0x0001), .driver_info = DIGITAL_VIDEO_CREATOR_I },
1081 { USB_DEVICE(0x07d0, 0x0002), .driver_info=GLOBAL_VILLAGE_GV_007_NTSC }, 1081 { USB_DEVICE(0x07d0, 0x0002), .driver_info = GLOBAL_VILLAGE_GV_007_NTSC },
1082 { USB_DEVICE(0x07d0, 0x0003), .driver_info=DAZZLE_DVC_50_REV_1_NTSC }, 1082 { USB_DEVICE(0x07d0, 0x0003), .driver_info = DAZZLE_DVC_50_REV_1_NTSC },
1083 { USB_DEVICE(0x07d0, 0x0004), .driver_info=DAZZLE_DVC_80_REV_1_PAL }, 1083 { USB_DEVICE(0x07d0, 0x0004), .driver_info = DAZZLE_DVC_80_REV_1_PAL },
1084 { USB_DEVICE(0x07d0, 0x0005), .driver_info=DAZZLE_DVC_90_REV_1_SECAM }, 1084 { USB_DEVICE(0x07d0, 0x0005), .driver_info = DAZZLE_DVC_90_REV_1_SECAM },
1085 { USB_DEVICE(0x07f8, 0x9104), .driver_info=ESKAPE_LABS_MYTV2GO }, 1085 { USB_DEVICE(0x07f8, 0x9104), .driver_info = ESKAPE_LABS_MYTV2GO },
1086 { USB_DEVICE(0x2304, 0x010d), .driver_info=PINNA_PCTV_USB_PAL }, 1086 { USB_DEVICE(0x2304, 0x010d), .driver_info = PINNA_PCTV_USB_PAL },
1087 { USB_DEVICE(0x2304, 0x0109), .driver_info=PINNA_PCTV_USB_SECAM }, 1087 { USB_DEVICE(0x2304, 0x0109), .driver_info = PINNA_PCTV_USB_SECAM },
1088 { USB_DEVICE(0x2304, 0x0110), .driver_info=PINNA_PCTV_USB_PAL_FM }, 1088 { USB_DEVICE(0x2304, 0x0110), .driver_info = PINNA_PCTV_USB_PAL_FM },
1089 { USB_DEVICE(0x2304, 0x0111), .driver_info=MIRO_PCTV_USB }, 1089 { USB_DEVICE(0x2304, 0x0111), .driver_info = MIRO_PCTV_USB },
1090 { USB_DEVICE(0x2304, 0x0112), .driver_info=PINNA_PCTV_USB_NTSC_FM }, 1090 { USB_DEVICE(0x2304, 0x0112), .driver_info = PINNA_PCTV_USB_NTSC_FM },
1091 { USB_DEVICE(0x2304, 0x0113), 1091 { USB_DEVICE(0x2304, 0x0113),
1092 .driver_info = PINNA_PCTV_USB_NTSC_FM_V3 }, 1092 .driver_info = PINNA_PCTV_USB_NTSC_FM_V3 },
1093 { USB_DEVICE(0x2304, 0x0210), .driver_info=PINNA_PCTV_USB_PAL_FM_V2 }, 1093 { USB_DEVICE(0x2304, 0x0210), .driver_info = PINNA_PCTV_USB_PAL_FM_V2 },
1094 { USB_DEVICE(0x2304, 0x0212), .driver_info=PINNA_PCTV_USB_NTSC_FM_V2 }, 1094 { USB_DEVICE(0x2304, 0x0212), .driver_info = PINNA_PCTV_USB_NTSC_FM_V2 },
1095 { USB_DEVICE(0x2304, 0x0214), .driver_info=PINNA_PCTV_USB_PAL_FM_V3 }, 1095 { USB_DEVICE(0x2304, 0x0214), .driver_info = PINNA_PCTV_USB_PAL_FM_V3 },
1096 { USB_DEVICE(0x2304, 0x0300), .driver_info=PINNA_LINX_VD_IN_CAB_NTSC }, 1096 { USB_DEVICE(0x2304, 0x0300), .driver_info = PINNA_LINX_VD_IN_CAB_NTSC },
1097 { USB_DEVICE(0x2304, 0x0301), .driver_info=PINNA_LINX_VD_IN_CAB_PAL }, 1097 { USB_DEVICE(0x2304, 0x0301), .driver_info = PINNA_LINX_VD_IN_CAB_PAL },
1098 { USB_DEVICE(0x2304, 0x0419), .driver_info=PINNA_PCTV_BUNGEE_PAL_FM }, 1098 { USB_DEVICE(0x2304, 0x0419), .driver_info = PINNA_PCTV_BUNGEE_PAL_FM },
1099 { USB_DEVICE(0x2400, 0x4200), .driver_info=HPG_WINTV }, 1099 { USB_DEVICE(0x2400, 0x4200), .driver_info = HPG_WINTV },
1100 { }, /* terminate list */ 1100 { }, /* terminate list */
1101}; 1101};
1102 1102
1103MODULE_DEVICE_TABLE (usb, usbvision_table); 1103MODULE_DEVICE_TABLE(usb, usbvision_table);
diff --git a/drivers/media/video/usbvision/usbvision-core.c b/drivers/media/video/usbvision/usbvision-core.c
index b9dd74fde212..c8feb0d6fccf 100644
--- a/drivers/media/video/usbvision/usbvision-core.c
+++ b/drivers/media/video/usbvision/usbvision-core.c
@@ -33,7 +33,7 @@
33#include <linux/module.h> 33#include <linux/module.h>
34#include <linux/init.h> 34#include <linux/init.h>
35#include <linux/spinlock.h> 35#include <linux/spinlock.h>
36#include <asm/io.h> 36#include <linux/io.h>
37#include <linux/videodev2.h> 37#include <linux/videodev2.h>
38#include <linux/i2c.h> 38#include <linux/i2c.h>
39 39
@@ -46,30 +46,30 @@
46#include "usbvision.h" 46#include "usbvision.h"
47 47
48static unsigned int core_debug; 48static unsigned int core_debug;
49module_param(core_debug,int,0644); 49module_param(core_debug, int, 0644);
50MODULE_PARM_DESC(core_debug,"enable debug messages [core]"); 50MODULE_PARM_DESC(core_debug, "enable debug messages [core]");
51 51
52static unsigned int force_testpattern; 52static unsigned int force_testpattern;
53module_param(force_testpattern,int,0644); 53module_param(force_testpattern, int, 0644);
54MODULE_PARM_DESC(force_testpattern,"enable test pattern display [core]"); 54MODULE_PARM_DESC(force_testpattern, "enable test pattern display [core]");
55 55
56static int adjustCompression = 1; /* Set the compression to be adaptive */ 56static int adjust_compression = 1; /* Set the compression to be adaptive */
57module_param(adjustCompression, int, 0444); 57module_param(adjust_compression, int, 0444);
58MODULE_PARM_DESC(adjustCompression, " Set the ADPCM compression for the device. Default: 1 (On)"); 58MODULE_PARM_DESC(adjust_compression, " Set the ADPCM compression for the device. Default: 1 (On)");
59 59
60/* To help people with Black and White output with using s-video input. 60/* To help people with Black and White output with using s-video input.
61 * Some cables and input device are wired differently. */ 61 * Some cables and input device are wired differently. */
62static int SwitchSVideoInput; 62static int switch_svideo_input;
63module_param(SwitchSVideoInput, int, 0444); 63module_param(switch_svideo_input, int, 0444);
64MODULE_PARM_DESC(SwitchSVideoInput, " Set the S-Video input. Some cables and input device are wired differently. Default: 0 (Off)"); 64MODULE_PARM_DESC(switch_svideo_input, " Set the S-Video input. Some cables and input device are wired differently. Default: 0 (Off)");
65 65
66static unsigned int adjust_X_Offset = -1; 66static unsigned int adjust_x_offset = -1;
67module_param(adjust_X_Offset, int, 0644); 67module_param(adjust_x_offset, int, 0644);
68MODULE_PARM_DESC(adjust_X_Offset, "adjust X offset display [core]"); 68MODULE_PARM_DESC(adjust_x_offset, "adjust X offset display [core]");
69 69
70static unsigned int adjust_Y_Offset = -1; 70static unsigned int adjust_y_offset = -1;
71module_param(adjust_Y_Offset, int, 0644); 71module_param(adjust_y_offset, int, 0644);
72MODULE_PARM_DESC(adjust_Y_Offset, "adjust Y offset display [core]"); 72MODULE_PARM_DESC(adjust_y_offset, "adjust Y offset display [core]");
73 73
74 74
75#define ENABLE_HEXDUMP 0 /* Enable if you need it */ 75#define ENABLE_HEXDUMP 0 /* Enable if you need it */
@@ -82,15 +82,15 @@ MODULE_PARM_DESC(adjust_Y_Offset, "adjust Y offset display [core]");
82 __func__, __LINE__ , ## args); \ 82 __func__, __LINE__ , ## args); \
83 } 83 }
84#else 84#else
85 #define PDEBUG(level, fmt, args...) do {} while(0) 85 #define PDEBUG(level, fmt, args...) do {} while (0)
86#endif 86#endif
87 87
88#define DBG_HEADER 1<<0 88#define DBG_HEADER (1 << 0)
89#define DBG_IRQ 1<<1 89#define DBG_IRQ (1 << 1)
90#define DBG_ISOC 1<<2 90#define DBG_ISOC (1 << 2)
91#define DBG_PARSE 1<<3 91#define DBG_PARSE (1 << 3)
92#define DBG_SCRATCH 1<<4 92#define DBG_SCRATCH (1 << 4)
93#define DBG_FUNC 1<<5 93#define DBG_FUNC (1 << 5)
94 94
95static const int max_imgwidth = MAX_FRAME_WIDTH; 95static const int max_imgwidth = MAX_FRAME_WIDTH;
96static const int max_imgheight = MAX_FRAME_HEIGHT; 96static const int max_imgheight = MAX_FRAME_HEIGHT;
@@ -103,14 +103,14 @@ static const int min_imgheight = MIN_FRAME_HEIGHT;
103 * to work with. This setting can be adjusted, but the default value 103 * to work with. This setting can be adjusted, but the default value
104 * should be OK for most desktop users. 104 * should be OK for most desktop users.
105 */ 105 */
106#define DEFAULT_SCRATCH_BUF_SIZE (0x20000) // 128kB memory scratch buffer 106#define DEFAULT_SCRATCH_BUF_SIZE (0x20000) /* 128kB memory scratch buffer */
107static const int scratch_buf_size = DEFAULT_SCRATCH_BUF_SIZE; 107static const int scratch_buf_size = DEFAULT_SCRATCH_BUF_SIZE;
108 108
109// Function prototypes 109/* Function prototypes */
110static int usbvision_request_intra (struct usb_usbvision *usbvision); 110static int usbvision_request_intra(struct usb_usbvision *usbvision);
111static int usbvision_unrequest_intra (struct usb_usbvision *usbvision); 111static int usbvision_unrequest_intra(struct usb_usbvision *usbvision);
112static int usbvision_adjust_compression (struct usb_usbvision *usbvision); 112static int usbvision_adjust_compression(struct usb_usbvision *usbvision);
113static int usbvision_measure_bandwidth (struct usb_usbvision *usbvision); 113static int usbvision_measure_bandwidth(struct usb_usbvision *usbvision);
114 114
115/*******************************/ 115/*******************************/
116/* Memory management functions */ 116/* Memory management functions */
@@ -176,19 +176,19 @@ static void usbvision_hexdump(const unsigned char *data, int len)
176 k += sprintf(&tmp[k], "%02x ", data[i]); 176 k += sprintf(&tmp[k], "%02x ", data[i]);
177 } 177 }
178 if (k > 0) 178 if (k > 0)
179 printk("%s\n", tmp); 179 printk(KERN_CONT "%s\n", tmp);
180} 180}
181#endif 181#endif
182 182
183/******************************** 183/********************************
184 * scratch ring buffer handling 184 * scratch ring buffer handling
185 ********************************/ 185 ********************************/
186static int scratch_len(struct usb_usbvision *usbvision) /*This returns the amount of data actually in the buffer */ 186static int scratch_len(struct usb_usbvision *usbvision) /* This returns the amount of data actually in the buffer */
187{ 187{
188 int len = usbvision->scratch_write_ptr - usbvision->scratch_read_ptr; 188 int len = usbvision->scratch_write_ptr - usbvision->scratch_read_ptr;
189 if (len < 0) { 189
190 if (len < 0)
190 len += scratch_buf_size; 191 len += scratch_buf_size;
191 }
192 PDEBUG(DBG_SCRATCH, "scratch_len() = %d\n", len); 192 PDEBUG(DBG_SCRATCH, "scratch_len() = %d\n", len);
193 193
194 return len; 194 return len;
@@ -199,9 +199,8 @@ static int scratch_len(struct usb_usbvision *usbvision) /*This returns the am
199static int scratch_free(struct usb_usbvision *usbvision) 199static int scratch_free(struct usb_usbvision *usbvision)
200{ 200{
201 int free = usbvision->scratch_read_ptr - usbvision->scratch_write_ptr; 201 int free = usbvision->scratch_read_ptr - usbvision->scratch_write_ptr;
202 if (free <= 0) { 202 if (free <= 0)
203 free += scratch_buf_size; 203 free += scratch_buf_size;
204 }
205 if (free) { 204 if (free) {
206 free -= 1; /* at least one byte in the buffer must */ 205 free -= 1; /* at least one byte in the buffer must */
207 /* left blank, otherwise there is no chance to differ between full and empty */ 206 /* left blank, otherwise there is no chance to differ between full and empty */
@@ -221,14 +220,12 @@ static int scratch_put(struct usb_usbvision *usbvision, unsigned char *data,
221 if (usbvision->scratch_write_ptr + len < scratch_buf_size) { 220 if (usbvision->scratch_write_ptr + len < scratch_buf_size) {
222 memcpy(usbvision->scratch + usbvision->scratch_write_ptr, data, len); 221 memcpy(usbvision->scratch + usbvision->scratch_write_ptr, data, len);
223 usbvision->scratch_write_ptr += len; 222 usbvision->scratch_write_ptr += len;
224 } 223 } else {
225 else {
226 len_part = scratch_buf_size - usbvision->scratch_write_ptr; 224 len_part = scratch_buf_size - usbvision->scratch_write_ptr;
227 memcpy(usbvision->scratch + usbvision->scratch_write_ptr, data, len_part); 225 memcpy(usbvision->scratch + usbvision->scratch_write_ptr, data, len_part);
228 if (len == len_part) { 226 if (len == len_part) {
229 usbvision->scratch_write_ptr = 0; /* just set write_ptr to zero */ 227 usbvision->scratch_write_ptr = 0; /* just set write_ptr to zero */
230 } 228 } else {
231 else {
232 memcpy(usbvision->scratch, data + len_part, len - len_part); 229 memcpy(usbvision->scratch, data + len_part, len - len_part);
233 usbvision->scratch_write_ptr = len - len_part; 230 usbvision->scratch_write_ptr = len - len_part;
234 } 231 }
@@ -255,17 +252,16 @@ static int scratch_get_extra(struct usb_usbvision *usbvision,
255 unsigned char *data, int *ptr, int len) 252 unsigned char *data, int *ptr, int len)
256{ 253{
257 int len_part; 254 int len_part;
255
258 if (*ptr + len < scratch_buf_size) { 256 if (*ptr + len < scratch_buf_size) {
259 memcpy(data, usbvision->scratch + *ptr, len); 257 memcpy(data, usbvision->scratch + *ptr, len);
260 *ptr += len; 258 *ptr += len;
261 } 259 } else {
262 else {
263 len_part = scratch_buf_size - *ptr; 260 len_part = scratch_buf_size - *ptr;
264 memcpy(data, usbvision->scratch + *ptr, len_part); 261 memcpy(data, usbvision->scratch + *ptr, len_part);
265 if (len == len_part) { 262 if (len == len_part) {
266 *ptr = 0; /* just set the y_ptr to zero */ 263 *ptr = 0; /* just set the y_ptr to zero */
267 } 264 } else {
268 else {
269 memcpy(data + len_part, usbvision->scratch, len - len_part); 265 memcpy(data + len_part, usbvision->scratch, len - len_part);
270 *ptr = len - len_part; 266 *ptr = len - len_part;
271 } 267 }
@@ -281,13 +277,13 @@ static int scratch_get_extra(struct usb_usbvision *usbvision,
281static void scratch_set_extra_ptr(struct usb_usbvision *usbvision, int *ptr, 277static void scratch_set_extra_ptr(struct usb_usbvision *usbvision, int *ptr,
282 int len) 278 int len)
283{ 279{
284 *ptr = (usbvision->scratch_read_ptr + len)%scratch_buf_size; 280 *ptr = (usbvision->scratch_read_ptr + len) % scratch_buf_size;
285 281
286 PDEBUG(DBG_SCRATCH, "ptr=%d\n", *ptr); 282 PDEBUG(DBG_SCRATCH, "ptr=%d\n", *ptr);
287} 283}
288 284
289 285
290/*This increments the scratch extra read pointer */ 286/* This increments the scratch extra read pointer */
291static void scratch_inc_extra_ptr(int *ptr, int len) 287static void scratch_inc_extra_ptr(int *ptr, int len)
292{ 288{
293 *ptr = (*ptr + len) % scratch_buf_size; 289 *ptr = (*ptr + len) % scratch_buf_size;
@@ -301,17 +297,16 @@ static int scratch_get(struct usb_usbvision *usbvision, unsigned char *data,
301 int len) 297 int len)
302{ 298{
303 int len_part; 299 int len_part;
300
304 if (usbvision->scratch_read_ptr + len < scratch_buf_size) { 301 if (usbvision->scratch_read_ptr + len < scratch_buf_size) {
305 memcpy(data, usbvision->scratch + usbvision->scratch_read_ptr, len); 302 memcpy(data, usbvision->scratch + usbvision->scratch_read_ptr, len);
306 usbvision->scratch_read_ptr += len; 303 usbvision->scratch_read_ptr += len;
307 } 304 } else {
308 else {
309 len_part = scratch_buf_size - usbvision->scratch_read_ptr; 305 len_part = scratch_buf_size - usbvision->scratch_read_ptr;
310 memcpy(data, usbvision->scratch + usbvision->scratch_read_ptr, len_part); 306 memcpy(data, usbvision->scratch + usbvision->scratch_read_ptr, len_part);
311 if (len == len_part) { 307 if (len == len_part) {
312 usbvision->scratch_read_ptr = 0; /* just set the read_ptr to zero */ 308 usbvision->scratch_read_ptr = 0; /* just set the read_ptr to zero */
313 } 309 } else {
314 else {
315 memcpy(data + len_part, usbvision->scratch, len - len_part); 310 memcpy(data + len_part, usbvision->scratch, len - len_part);
316 usbvision->scratch_read_ptr = len - len_part; 311 usbvision->scratch_read_ptr = len - len_part;
317 } 312 }
@@ -327,7 +322,7 @@ static int scratch_get(struct usb_usbvision *usbvision, unsigned char *data,
327static int scratch_get_header(struct usb_usbvision *usbvision, 322static int scratch_get_header(struct usb_usbvision *usbvision,
328 struct usbvision_frame_header *header) 323 struct usbvision_frame_header *header)
329{ 324{
330 int errCode = 0; 325 int err_code = 0;
331 326
332 PDEBUG(DBG_SCRATCH, "from read_ptr=%d", usbvision->scratch_headermarker_read_ptr); 327 PDEBUG(DBG_SCRATCH, "from read_ptr=%d", usbvision->scratch_headermarker_read_ptr);
333 328
@@ -340,29 +335,28 @@ static int scratch_get_header(struct usb_usbvision *usbvision,
340 scratch_get(usbvision, (unsigned char *)header, USBVISION_HEADER_LENGTH); 335 scratch_get(usbvision, (unsigned char *)header, USBVISION_HEADER_LENGTH);
341 if ((header->magic_1 == USBVISION_MAGIC_1) 336 if ((header->magic_1 == USBVISION_MAGIC_1)
342 && (header->magic_2 == USBVISION_MAGIC_2) 337 && (header->magic_2 == USBVISION_MAGIC_2)
343 && (header->headerLength == USBVISION_HEADER_LENGTH)) { 338 && (header->header_length == USBVISION_HEADER_LENGTH)) {
344 errCode = USBVISION_HEADER_LENGTH; 339 err_code = USBVISION_HEADER_LENGTH;
345 header->frameWidth = header->frameWidthLo + (header->frameWidthHi << 8); 340 header->frame_width = header->frame_width_lo + (header->frame_width_hi << 8);
346 header->frameHeight = header->frameHeightLo + (header->frameHeightHi << 8); 341 header->frame_height = header->frame_height_lo + (header->frame_height_hi << 8);
347 break; 342 break;
348 } 343 }
349 } 344 }
350 345
351 return errCode; 346 return err_code;
352} 347}
353 348
354 349
355/*This removes len bytes of old data from the buffer */ 350/* This removes len bytes of old data from the buffer */
356static void scratch_rm_old(struct usb_usbvision *usbvision, int len) 351static void scratch_rm_old(struct usb_usbvision *usbvision, int len)
357{ 352{
358
359 usbvision->scratch_read_ptr += len; 353 usbvision->scratch_read_ptr += len;
360 usbvision->scratch_read_ptr %= scratch_buf_size; 354 usbvision->scratch_read_ptr %= scratch_buf_size;
361 PDEBUG(DBG_SCRATCH, "read_ptr is now %d\n", usbvision->scratch_read_ptr); 355 PDEBUG(DBG_SCRATCH, "read_ptr is now %d\n", usbvision->scratch_read_ptr);
362} 356}
363 357
364 358
365/*This resets the buffer - kills all data in it too */ 359/* This resets the buffer - kills all data in it too */
366static void scratch_reset(struct usb_usbvision *usbvision) 360static void scratch_reset(struct usb_usbvision *usbvision)
367{ 361{
368 PDEBUG(DBG_SCRATCH, "\n"); 362 PDEBUG(DBG_SCRATCH, "\n");
@@ -371,14 +365,14 @@ static void scratch_reset(struct usb_usbvision *usbvision)
371 usbvision->scratch_write_ptr = 0; 365 usbvision->scratch_write_ptr = 0;
372 usbvision->scratch_headermarker_read_ptr = 0; 366 usbvision->scratch_headermarker_read_ptr = 0;
373 usbvision->scratch_headermarker_write_ptr = 0; 367 usbvision->scratch_headermarker_write_ptr = 0;
374 usbvision->isocstate = IsocState_NoFrame; 368 usbvision->isocstate = isoc_state_no_frame;
375} 369}
376 370
377int usbvision_scratch_alloc(struct usb_usbvision *usbvision) 371int usbvision_scratch_alloc(struct usb_usbvision *usbvision)
378{ 372{
379 usbvision->scratch = vmalloc_32(scratch_buf_size); 373 usbvision->scratch = vmalloc_32(scratch_buf_size);
380 scratch_reset(usbvision); 374 scratch_reset(usbvision);
381 if(usbvision->scratch == NULL) { 375 if (usbvision->scratch == NULL) {
382 dev_err(&usbvision->dev->dev, 376 dev_err(&usbvision->dev->dev,
383 "%s: unable to allocate %d bytes for scratch\n", 377 "%s: unable to allocate %d bytes for scratch\n",
384 __func__, scratch_buf_size); 378 __func__, scratch_buf_size);
@@ -391,7 +385,6 @@ void usbvision_scratch_free(struct usb_usbvision *usbvision)
391{ 385{
392 vfree(usbvision->scratch); 386 vfree(usbvision->scratch);
393 usbvision->scratch = NULL; 387 usbvision->scratch = NULL;
394
395} 388}
396 389
397/* 390/*
@@ -420,13 +413,13 @@ static void usbvision_testpattern(struct usb_usbvision *usbvision,
420 printk(KERN_ERR "%s: usbvision == NULL\n", proc); 413 printk(KERN_ERR "%s: usbvision == NULL\n", proc);
421 return; 414 return;
422 } 415 }
423 if (usbvision->curFrame == NULL) { 416 if (usbvision->cur_frame == NULL) {
424 printk(KERN_ERR "%s: usbvision->curFrame is NULL.\n", proc); 417 printk(KERN_ERR "%s: usbvision->cur_frame is NULL.\n", proc);
425 return; 418 return;
426 } 419 }
427 420
428 /* Grab the current frame */ 421 /* Grab the current frame */
429 frame = usbvision->curFrame; 422 frame = usbvision->cur_frame;
430 423
431 /* Optionally start at the beginning */ 424 /* Optionally start at the beginning */
432 if (fullframe) { 425 if (fullframe) {
@@ -473,10 +466,9 @@ static void usbvision_testpattern(struct usb_usbvision *usbvision,
473 } 466 }
474 } 467 }
475 468
476 frame->grabstate = FrameState_Done; 469 frame->grabstate = frame_state_done;
477 frame->scanlength += scan_length; 470 frame->scanlength += scan_length;
478 ++num_pass; 471 ++num_pass;
479
480} 472}
481 473
482/* 474/*
@@ -487,8 +479,9 @@ static void usbvision_testpattern(struct usb_usbvision *usbvision,
487int usbvision_decompress_alloc(struct usb_usbvision *usbvision) 479int usbvision_decompress_alloc(struct usb_usbvision *usbvision)
488{ 480{
489 int IFB_size = MAX_FRAME_WIDTH * MAX_FRAME_HEIGHT * 3 / 2; 481 int IFB_size = MAX_FRAME_WIDTH * MAX_FRAME_HEIGHT * 3 / 2;
490 usbvision->IntraFrameBuffer = vmalloc_32(IFB_size); 482
491 if (usbvision->IntraFrameBuffer == NULL) { 483 usbvision->intra_frame_buffer = vmalloc_32(IFB_size);
484 if (usbvision->intra_frame_buffer == NULL) {
492 dev_err(&usbvision->dev->dev, 485 dev_err(&usbvision->dev->dev,
493 "%s: unable to allocate %d for compr. frame buffer\n", 486 "%s: unable to allocate %d for compr. frame buffer\n",
494 __func__, IFB_size); 487 __func__, IFB_size);
@@ -504,8 +497,8 @@ int usbvision_decompress_alloc(struct usb_usbvision *usbvision)
504 */ 497 */
505void usbvision_decompress_free(struct usb_usbvision *usbvision) 498void usbvision_decompress_free(struct usb_usbvision *usbvision)
506{ 499{
507 vfree(usbvision->IntraFrameBuffer); 500 vfree(usbvision->intra_frame_buffer);
508 usbvision->IntraFrameBuffer = NULL; 501 usbvision->intra_frame_buffer = NULL;
509 502
510} 503}
511 504
@@ -517,117 +510,111 @@ void usbvision_decompress_free(struct usb_usbvision *usbvision)
517 * 510 *
518 * Locate one of supported header markers in the scratch buffer. 511 * Locate one of supported header markers in the scratch buffer.
519 */ 512 */
520static enum ParseState usbvision_find_header(struct usb_usbvision *usbvision) 513static enum parse_state usbvision_find_header(struct usb_usbvision *usbvision)
521{ 514{
522 struct usbvision_frame *frame; 515 struct usbvision_frame *frame;
523 int foundHeader = 0; 516 int found_header = 0;
524 517
525 frame = usbvision->curFrame; 518 frame = usbvision->cur_frame;
526 519
527 while (scratch_get_header(usbvision, &frame->isocHeader) == USBVISION_HEADER_LENGTH) { 520 while (scratch_get_header(usbvision, &frame->isoc_header) == USBVISION_HEADER_LENGTH) {
528 // found header in scratch 521 /* found header in scratch */
529 PDEBUG(DBG_HEADER, "found header: 0x%02x%02x %d %d %d %d %#x 0x%02x %u %u", 522 PDEBUG(DBG_HEADER, "found header: 0x%02x%02x %d %d %d %d %#x 0x%02x %u %u",
530 frame->isocHeader.magic_2, 523 frame->isoc_header.magic_2,
531 frame->isocHeader.magic_1, 524 frame->isoc_header.magic_1,
532 frame->isocHeader.headerLength, 525 frame->isoc_header.header_length,
533 frame->isocHeader.frameNum, 526 frame->isoc_header.frame_num,
534 frame->isocHeader.framePhase, 527 frame->isoc_header.frame_phase,
535 frame->isocHeader.frameLatency, 528 frame->isoc_header.frame_latency,
536 frame->isocHeader.dataFormat, 529 frame->isoc_header.data_format,
537 frame->isocHeader.formatParam, 530 frame->isoc_header.format_param,
538 frame->isocHeader.frameWidth, 531 frame->isoc_header.frame_width,
539 frame->isocHeader.frameHeight); 532 frame->isoc_header.frame_height);
540 533
541 if (usbvision->requestIntra) { 534 if (usbvision->request_intra) {
542 if (frame->isocHeader.formatParam & 0x80) { 535 if (frame->isoc_header.format_param & 0x80) {
543 foundHeader = 1; 536 found_header = 1;
544 usbvision->lastIsocFrameNum = -1; // do not check for lost frames this time 537 usbvision->last_isoc_frame_num = -1; /* do not check for lost frames this time */
545 usbvision_unrequest_intra(usbvision); 538 usbvision_unrequest_intra(usbvision);
546 break; 539 break;
547 } 540 }
548 } 541 } else {
549 else { 542 found_header = 1;
550 foundHeader = 1;
551 break; 543 break;
552 } 544 }
553 } 545 }
554 546
555 if (foundHeader) { 547 if (found_header) {
556 frame->frmwidth = frame->isocHeader.frameWidth * usbvision->stretch_width; 548 frame->frmwidth = frame->isoc_header.frame_width * usbvision->stretch_width;
557 frame->frmheight = frame->isocHeader.frameHeight * usbvision->stretch_height; 549 frame->frmheight = frame->isoc_header.frame_height * usbvision->stretch_height;
558 frame->v4l2_linesize = (frame->frmwidth * frame->v4l2_format.depth)>> 3; 550 frame->v4l2_linesize = (frame->frmwidth * frame->v4l2_format.depth) >> 3;
559 } 551 } else { /* no header found */
560 else { // no header found
561 PDEBUG(DBG_HEADER, "skipping scratch data, no header"); 552 PDEBUG(DBG_HEADER, "skipping scratch data, no header");
562 scratch_reset(usbvision); 553 scratch_reset(usbvision);
563 return ParseState_EndParse; 554 return parse_state_end_parse;
564 } 555 }
565 556
566 // found header 557 /* found header */
567 if (frame->isocHeader.dataFormat==ISOC_MODE_COMPRESS) { 558 if (frame->isoc_header.data_format == ISOC_MODE_COMPRESS) {
568 //check isocHeader.frameNum for lost frames 559 /* check isoc_header.frame_num for lost frames */
569 if (usbvision->lastIsocFrameNum >= 0) { 560 if (usbvision->last_isoc_frame_num >= 0) {
570 if (((usbvision->lastIsocFrameNum + 1) % 32) != frame->isocHeader.frameNum) { 561 if (((usbvision->last_isoc_frame_num + 1) % 32) != frame->isoc_header.frame_num) {
571 // unexpected frame drop: need to request new intra frame 562 /* unexpected frame drop: need to request new intra frame */
572 PDEBUG(DBG_HEADER, "Lost frame before %d on USB", frame->isocHeader.frameNum); 563 PDEBUG(DBG_HEADER, "Lost frame before %d on USB", frame->isoc_header.frame_num);
573 usbvision_request_intra(usbvision); 564 usbvision_request_intra(usbvision);
574 return ParseState_NextFrame; 565 return parse_state_next_frame;
575 } 566 }
576 } 567 }
577 usbvision->lastIsocFrameNum = frame->isocHeader.frameNum; 568 usbvision->last_isoc_frame_num = frame->isoc_header.frame_num;
578 } 569 }
579 usbvision->header_count++; 570 usbvision->header_count++;
580 frame->scanstate = ScanState_Lines; 571 frame->scanstate = scan_state_lines;
581 frame->curline = 0; 572 frame->curline = 0;
582 573
583 if (force_testpattern) { 574 if (force_testpattern) {
584 usbvision_testpattern(usbvision, 1, 1); 575 usbvision_testpattern(usbvision, 1, 1);
585 return ParseState_NextFrame; 576 return parse_state_next_frame;
586 } 577 }
587 return ParseState_Continue; 578 return parse_state_continue;
588} 579}
589 580
590static enum ParseState usbvision_parse_lines_422(struct usb_usbvision *usbvision, 581static enum parse_state usbvision_parse_lines_422(struct usb_usbvision *usbvision,
591 long *pcopylen) 582 long *pcopylen)
592{ 583{
593 volatile struct usbvision_frame *frame; 584 volatile struct usbvision_frame *frame;
594 unsigned char *f; 585 unsigned char *f;
595 int len; 586 int len;
596 int i; 587 int i;
597 unsigned char yuyv[4]={180, 128, 10, 128}; // YUV components 588 unsigned char yuyv[4] = { 180, 128, 10, 128 }; /* YUV components */
598 unsigned char rv, gv, bv; // RGB components 589 unsigned char rv, gv, bv; /* RGB components */
599 int clipmask_index, bytes_per_pixel; 590 int clipmask_index, bytes_per_pixel;
600 int stretch_bytes, clipmask_add; 591 int stretch_bytes, clipmask_add;
601 592
602 frame = usbvision->curFrame; 593 frame = usbvision->cur_frame;
603 f = frame->data + (frame->v4l2_linesize * frame->curline); 594 f = frame->data + (frame->v4l2_linesize * frame->curline);
604 595
605 /* Make sure there's enough data for the entire line */ 596 /* Make sure there's enough data for the entire line */
606 len = (frame->isocHeader.frameWidth * 2)+5; 597 len = (frame->isoc_header.frame_width * 2) + 5;
607 if (scratch_len(usbvision) < len) { 598 if (scratch_len(usbvision) < len) {
608 PDEBUG(DBG_PARSE, "out of data in line %d, need %u.\n", frame->curline, len); 599 PDEBUG(DBG_PARSE, "out of data in line %d, need %u.\n", frame->curline, len);
609 return ParseState_Out; 600 return parse_state_out;
610 } 601 }
611 602
612 if ((frame->curline + 1) >= frame->frmheight) { 603 if ((frame->curline + 1) >= frame->frmheight)
613 return ParseState_NextFrame; 604 return parse_state_next_frame;
614 }
615 605
616 bytes_per_pixel = frame->v4l2_format.bytes_per_pixel; 606 bytes_per_pixel = frame->v4l2_format.bytes_per_pixel;
617 stretch_bytes = (usbvision->stretch_width - 1) * bytes_per_pixel; 607 stretch_bytes = (usbvision->stretch_width - 1) * bytes_per_pixel;
618 clipmask_index = frame->curline * MAX_FRAME_WIDTH; 608 clipmask_index = frame->curline * MAX_FRAME_WIDTH;
619 clipmask_add = usbvision->stretch_width; 609 clipmask_add = usbvision->stretch_width;
620 610
621 for (i = 0; i < frame->frmwidth; i+=(2 * usbvision->stretch_width)) { 611 for (i = 0; i < frame->frmwidth; i += (2 * usbvision->stretch_width)) {
622
623 scratch_get(usbvision, &yuyv[0], 4); 612 scratch_get(usbvision, &yuyv[0], 4);
624 613
625 if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) { 614 if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
626 *f++ = yuyv[0]; // Y 615 *f++ = yuyv[0]; /* Y */
627 *f++ = yuyv[3]; // U 616 *f++ = yuyv[3]; /* U */
628 } 617 } else {
629 else {
630
631 YUV_TO_RGB_BY_THE_BOOK(yuyv[0], yuyv[1], yuyv[3], rv, gv, bv); 618 YUV_TO_RGB_BY_THE_BOOK(yuyv[0], yuyv[1], yuyv[3], rv, gv, bv);
632 switch (frame->v4l2_format.format) { 619 switch (frame->v4l2_format.format) {
633 case V4L2_PIX_FMT_RGB565: 620 case V4L2_PIX_FMT_RGB565:
@@ -659,11 +646,9 @@ static enum ParseState usbvision_parse_lines_422(struct usb_usbvision *usbvision
659 f += stretch_bytes; 646 f += stretch_bytes;
660 647
661 if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) { 648 if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
662 *f++ = yuyv[2]; // Y 649 *f++ = yuyv[2]; /* Y */
663 *f++ = yuyv[1]; // V 650 *f++ = yuyv[1]; /* V */
664 } 651 } else {
665 else {
666
667 YUV_TO_RGB_BY_THE_BOOK(yuyv[2], yuyv[1], yuyv[3], rv, gv, bv); 652 YUV_TO_RGB_BY_THE_BOOK(yuyv[2], yuyv[1], yuyv[3], rv, gv, bv);
668 switch (frame->v4l2_format.format) { 653 switch (frame->v4l2_format.format) {
669 case V4L2_PIX_FMT_RGB565: 654 case V4L2_PIX_FMT_RGB565:
@@ -698,100 +683,94 @@ static enum ParseState usbvision_parse_lines_422(struct usb_usbvision *usbvision
698 frame->curline += usbvision->stretch_height; 683 frame->curline += usbvision->stretch_height;
699 *pcopylen += frame->v4l2_linesize * usbvision->stretch_height; 684 *pcopylen += frame->v4l2_linesize * usbvision->stretch_height;
700 685
701 if (frame->curline >= frame->frmheight) { 686 if (frame->curline >= frame->frmheight)
702 return ParseState_NextFrame; 687 return parse_state_next_frame;
703 } 688 return parse_state_continue;
704 else {
705 return ParseState_Continue;
706 }
707} 689}
708 690
709/* The decompression routine */ 691/* The decompression routine */
710static int usbvision_decompress(struct usb_usbvision *usbvision,unsigned char *Compressed, 692static int usbvision_decompress(struct usb_usbvision *usbvision, unsigned char *compressed,
711 unsigned char *Decompressed, int *StartPos, 693 unsigned char *decompressed, int *start_pos,
712 int *BlockTypeStartPos, int Len) 694 int *block_typestart_pos, int len)
713{ 695{
714 int RestPixel, Idx, MaxPos, Pos, ExtraPos, BlockLen, BlockTypePos, BlockTypeLen; 696 int rest_pixel, idx, max_pos, pos, extra_pos, block_len, block_type_pos, block_type_len;
715 unsigned char BlockByte, BlockCode, BlockType, BlockTypeByte, Integrator; 697 unsigned char block_byte, block_code, block_type, block_type_byte, integrator;
716 698
717 Integrator = 0; 699 integrator = 0;
718 Pos = *StartPos; 700 pos = *start_pos;
719 BlockTypePos = *BlockTypeStartPos; 701 block_type_pos = *block_typestart_pos;
720 MaxPos = 396; //Pos + Len; 702 max_pos = 396; /* pos + len; */
721 ExtraPos = Pos; 703 extra_pos = pos;
722 BlockLen = 0; 704 block_len = 0;
723 BlockByte = 0; 705 block_byte = 0;
724 BlockCode = 0; 706 block_code = 0;
725 BlockType = 0; 707 block_type = 0;
726 BlockTypeByte = 0; 708 block_type_byte = 0;
727 BlockTypeLen = 0; 709 block_type_len = 0;
728 RestPixel = Len; 710 rest_pixel = len;
729 711
730 for (Idx = 0; Idx < Len; Idx++) { 712 for (idx = 0; idx < len; idx++) {
731 713 if (block_len == 0) {
732 if (BlockLen == 0) { 714 if (block_type_len == 0) {
733 if (BlockTypeLen==0) { 715 block_type_byte = compressed[block_type_pos];
734 BlockTypeByte = Compressed[BlockTypePos]; 716 block_type_pos++;
735 BlockTypePos++; 717 block_type_len = 4;
736 BlockTypeLen = 4;
737 } 718 }
738 BlockType = (BlockTypeByte & 0xC0) >> 6; 719 block_type = (block_type_byte & 0xC0) >> 6;
739 720
740 //statistic: 721 /* statistic: */
741 usbvision->ComprBlockTypes[BlockType]++; 722 usbvision->compr_block_types[block_type]++;
742 723
743 Pos = ExtraPos; 724 pos = extra_pos;
744 if (BlockType == 0) { 725 if (block_type == 0) {
745 if(RestPixel >= 24) { 726 if (rest_pixel >= 24) {
746 Idx += 23; 727 idx += 23;
747 RestPixel -= 24; 728 rest_pixel -= 24;
748 Integrator = Decompressed[Idx]; 729 integrator = decompressed[idx];
749 } else { 730 } else {
750 Idx += RestPixel - 1; 731 idx += rest_pixel - 1;
751 RestPixel = 0; 732 rest_pixel = 0;
752 } 733 }
753 } else { 734 } else {
754 BlockCode = Compressed[Pos]; 735 block_code = compressed[pos];
755 Pos++; 736 pos++;
756 if (RestPixel >= 24) { 737 if (rest_pixel >= 24)
757 BlockLen = 24; 738 block_len = 24;
758 } else { 739 else
759 BlockLen = RestPixel; 740 block_len = rest_pixel;
760 } 741 rest_pixel -= block_len;
761 RestPixel -= BlockLen; 742 extra_pos = pos + (block_len / 4);
762 ExtraPos = Pos + (BlockLen / 4);
763 } 743 }
764 BlockTypeByte <<= 2; 744 block_type_byte <<= 2;
765 BlockTypeLen -= 1; 745 block_type_len -= 1;
766 } 746 }
767 if (BlockLen > 0) { 747 if (block_len > 0) {
768 if ((BlockLen%4) == 0) { 748 if ((block_len % 4) == 0) {
769 BlockByte = Compressed[Pos]; 749 block_byte = compressed[pos];
770 Pos++; 750 pos++;
771 } 751 }
772 if (BlockType == 1) { //inter Block 752 if (block_type == 1) /* inter Block */
773 Integrator = Decompressed[Idx]; 753 integrator = decompressed[idx];
774 } 754 switch (block_byte & 0xC0) {
775 switch (BlockByte & 0xC0) { 755 case 0x03 << 6:
776 case 0x03<<6: 756 integrator += compressed[extra_pos];
777 Integrator += Compressed[ExtraPos]; 757 extra_pos++;
778 ExtraPos++; 758 break;
779 break; 759 case 0x02 << 6:
780 case 0x02<<6: 760 integrator += block_code;
781 Integrator += BlockCode; 761 break;
782 break; 762 case 0x00:
783 case 0x00: 763 integrator -= block_code;
784 Integrator -= BlockCode; 764 break;
785 break;
786 } 765 }
787 Decompressed[Idx] = Integrator; 766 decompressed[idx] = integrator;
788 BlockByte <<= 2; 767 block_byte <<= 2;
789 BlockLen -= 1; 768 block_len -= 1;
790 } 769 }
791 } 770 }
792 *StartPos = ExtraPos; 771 *start_pos = extra_pos;
793 *BlockTypeStartPos = BlockTypePos; 772 *block_typestart_pos = block_type_pos;
794 return Idx; 773 return idx;
795} 774}
796 775
797 776
@@ -803,7 +782,7 @@ static int usbvision_decompress(struct usb_usbvision *usbvision,unsigned char *C
803 * number of bytes (RGB) to the *pcopylen. 782 * number of bytes (RGB) to the *pcopylen.
804 * 783 *
805 */ 784 */
806static enum ParseState usbvision_parse_compress(struct usb_usbvision *usbvision, 785static enum parse_state usbvision_parse_compress(struct usb_usbvision *usbvision,
807 long *pcopylen) 786 long *pcopylen)
808{ 787{
809#define USBVISION_STRIP_MAGIC 0x5A 788#define USBVISION_STRIP_MAGIC 0x5A
@@ -811,191 +790,165 @@ static enum ParseState usbvision_parse_compress(struct usb_usbvision *usbvision,
811#define USBVISION_STRIP_HEADER_LEN 3 790#define USBVISION_STRIP_HEADER_LEN 3
812 791
813 struct usbvision_frame *frame; 792 struct usbvision_frame *frame;
814 unsigned char *f,*u = NULL ,*v = NULL; 793 unsigned char *f, *u = NULL, *v = NULL;
815 unsigned char StripData[USBVISION_STRIP_LEN_MAX]; 794 unsigned char strip_data[USBVISION_STRIP_LEN_MAX];
816 unsigned char StripHeader[USBVISION_STRIP_HEADER_LEN]; 795 unsigned char strip_header[USBVISION_STRIP_HEADER_LEN];
817 int Idx, IdxEnd, StripLen, StripPtr, StartBlockPos, BlockPos, BlockTypePos; 796 int idx, idx_end, strip_len, strip_ptr, startblock_pos, block_pos, block_type_pos;
818 int clipmask_index, bytes_per_pixel, rc; 797 int clipmask_index, bytes_per_pixel, rc;
819 int imageSize; 798 int image_size;
820 unsigned char rv, gv, bv; 799 unsigned char rv, gv, bv;
821 static unsigned char *Y, *U, *V; 800 static unsigned char *Y, *U, *V;
822 801
823 frame = usbvision->curFrame; 802 frame = usbvision->cur_frame;
824 imageSize = frame->frmwidth * frame->frmheight; 803 image_size = frame->frmwidth * frame->frmheight;
825 if ( (frame->v4l2_format.format == V4L2_PIX_FMT_YUV422P) || 804 if ((frame->v4l2_format.format == V4L2_PIX_FMT_YUV422P) ||
826 (frame->v4l2_format.format == V4L2_PIX_FMT_YVU420) ) { // this is a planar format 805 (frame->v4l2_format.format == V4L2_PIX_FMT_YVU420)) { /* this is a planar format */
827 //... v4l2_linesize not used here. 806 /* ... v4l2_linesize not used here. */
828 f = frame->data + (frame->width * frame->curline); 807 f = frame->data + (frame->width * frame->curline);
829 } else 808 } else
830 f = frame->data + (frame->v4l2_linesize * frame->curline); 809 f = frame->data + (frame->v4l2_linesize * frame->curline);
831 810
832 if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV){ //initialise u and v pointers 811 if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) { /* initialise u and v pointers */
833 // get base of u and b planes add halfoffset 812 /* get base of u and b planes add halfoffset */
834
835 u = frame->data 813 u = frame->data
836 + imageSize 814 + image_size
837 + (frame->frmwidth >>1) * frame->curline ; 815 + (frame->frmwidth >> 1) * frame->curline;
838 v = u + (imageSize >>1 ); 816 v = u + (image_size >> 1);
839 817 } else if (frame->v4l2_format.format == V4L2_PIX_FMT_YVU420) {
840 } else if (frame->v4l2_format.format == V4L2_PIX_FMT_YVU420){ 818 v = frame->data + image_size + ((frame->curline * (frame->width)) >> 2);
841 819 u = v + (image_size >> 2);
842 v = frame->data + imageSize + ((frame->curline* (frame->width))>>2) ;
843 u = v + (imageSize >>2) ;
844 } 820 }
845 821
846 if (frame->curline == 0) { 822 if (frame->curline == 0)
847 usbvision_adjust_compression(usbvision); 823 usbvision_adjust_compression(usbvision);
848 }
849 824
850 if (scratch_len(usbvision) < USBVISION_STRIP_HEADER_LEN) { 825 if (scratch_len(usbvision) < USBVISION_STRIP_HEADER_LEN)
851 return ParseState_Out; 826 return parse_state_out;
852 }
853 827
854 //get strip header without changing the scratch_read_ptr 828 /* get strip header without changing the scratch_read_ptr */
855 scratch_set_extra_ptr(usbvision, &StripPtr, 0); 829 scratch_set_extra_ptr(usbvision, &strip_ptr, 0);
856 scratch_get_extra(usbvision, &StripHeader[0], &StripPtr, 830 scratch_get_extra(usbvision, &strip_header[0], &strip_ptr,
857 USBVISION_STRIP_HEADER_LEN); 831 USBVISION_STRIP_HEADER_LEN);
858 832
859 if (StripHeader[0] != USBVISION_STRIP_MAGIC) { 833 if (strip_header[0] != USBVISION_STRIP_MAGIC) {
860 // wrong strip magic 834 /* wrong strip magic */
861 usbvision->stripMagicErrors++; 835 usbvision->strip_magic_errors++;
862 return ParseState_NextFrame; 836 return parse_state_next_frame;
863 } 837 }
864 838
865 if (frame->curline != (int)StripHeader[2]) { 839 if (frame->curline != (int)strip_header[2]) {
866 //line number missmatch error 840 /* line number mismatch error */
867 usbvision->stripLineNumberErrors++; 841 usbvision->strip_line_number_errors++;
868 } 842 }
869 843
870 StripLen = 2 * (unsigned int)StripHeader[1]; 844 strip_len = 2 * (unsigned int)strip_header[1];
871 if (StripLen > USBVISION_STRIP_LEN_MAX) { 845 if (strip_len > USBVISION_STRIP_LEN_MAX) {
872 // strip overrun 846 /* strip overrun */
873 // I think this never happens 847 /* I think this never happens */
874 usbvision_request_intra(usbvision); 848 usbvision_request_intra(usbvision);
875 } 849 }
876 850
877 if (scratch_len(usbvision) < StripLen) { 851 if (scratch_len(usbvision) < strip_len) {
878 //there is not enough data for the strip 852 /* there is not enough data for the strip */
879 return ParseState_Out; 853 return parse_state_out;
880 } 854 }
881 855
882 if (usbvision->IntraFrameBuffer) { 856 if (usbvision->intra_frame_buffer) {
883 Y = usbvision->IntraFrameBuffer + frame->frmwidth * frame->curline; 857 Y = usbvision->intra_frame_buffer + frame->frmwidth * frame->curline;
884 U = usbvision->IntraFrameBuffer + imageSize + (frame->frmwidth / 2) * (frame->curline / 2); 858 U = usbvision->intra_frame_buffer + image_size + (frame->frmwidth / 2) * (frame->curline / 2);
885 V = usbvision->IntraFrameBuffer + imageSize / 4 * 5 + (frame->frmwidth / 2) * (frame->curline / 2); 859 V = usbvision->intra_frame_buffer + image_size / 4 * 5 + (frame->frmwidth / 2) * (frame->curline / 2);
886 } 860 } else {
887 else { 861 return parse_state_next_frame;
888 return ParseState_NextFrame;
889 } 862 }
890 863
891 bytes_per_pixel = frame->v4l2_format.bytes_per_pixel; 864 bytes_per_pixel = frame->v4l2_format.bytes_per_pixel;
892 clipmask_index = frame->curline * MAX_FRAME_WIDTH; 865 clipmask_index = frame->curline * MAX_FRAME_WIDTH;
893 866
894 scratch_get(usbvision, StripData, StripLen); 867 scratch_get(usbvision, strip_data, strip_len);
895 868
896 IdxEnd = frame->frmwidth; 869 idx_end = frame->frmwidth;
897 BlockTypePos = USBVISION_STRIP_HEADER_LEN; 870 block_type_pos = USBVISION_STRIP_HEADER_LEN;
898 StartBlockPos = BlockTypePos + (IdxEnd - 1) / 96 + (IdxEnd / 2 - 1) / 96 + 2; 871 startblock_pos = block_type_pos + (idx_end - 1) / 96 + (idx_end / 2 - 1) / 96 + 2;
899 BlockPos = StartBlockPos; 872 block_pos = startblock_pos;
900 873
901 usbvision->BlockPos = BlockPos; 874 usbvision->block_pos = block_pos;
902 875
903 if ((rc = usbvision_decompress(usbvision, StripData, Y, &BlockPos, &BlockTypePos, IdxEnd)) != IdxEnd) { 876 rc = usbvision_decompress(usbvision, strip_data, Y, &block_pos, &block_type_pos, idx_end);
904 //return ParseState_Continue; 877 if (strip_len > usbvision->max_strip_len)
905 } 878 usbvision->max_strip_len = strip_len;
906 if (StripLen > usbvision->maxStripLen) {
907 usbvision->maxStripLen = StripLen;
908 }
909 879
910 if (frame->curline%2) { 880 if (frame->curline % 2)
911 if ((rc = usbvision_decompress(usbvision, StripData, V, &BlockPos, &BlockTypePos, IdxEnd/2)) != IdxEnd/2) { 881 rc = usbvision_decompress(usbvision, strip_data, V, &block_pos, &block_type_pos, idx_end / 2);
912 //return ParseState_Continue; 882 else
913 } 883 rc = usbvision_decompress(usbvision, strip_data, U, &block_pos, &block_type_pos, idx_end / 2);
914 }
915 else {
916 if ((rc = usbvision_decompress(usbvision, StripData, U, &BlockPos, &BlockTypePos, IdxEnd/2)) != IdxEnd/2) {
917 //return ParseState_Continue;
918 }
919 }
920 884
921 if (BlockPos > usbvision->comprBlockPos) { 885 if (block_pos > usbvision->comprblock_pos)
922 usbvision->comprBlockPos = BlockPos; 886 usbvision->comprblock_pos = block_pos;
923 } 887 if (block_pos > strip_len)
924 if (BlockPos > StripLen) { 888 usbvision->strip_len_errors++;
925 usbvision->stripLenErrors++;
926 }
927 889
928 for (Idx = 0; Idx < IdxEnd; Idx++) { 890 for (idx = 0; idx < idx_end; idx++) {
929 if(frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) { 891 if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
930 *f++ = Y[Idx]; 892 *f++ = Y[idx];
931 *f++ = Idx & 0x01 ? U[Idx/2] : V[Idx/2]; 893 *f++ = idx & 0x01 ? U[idx / 2] : V[idx / 2];
932 } 894 } else if (frame->v4l2_format.format == V4L2_PIX_FMT_YUV422P) {
933 else if(frame->v4l2_format.format == V4L2_PIX_FMT_YUV422P) { 895 *f++ = Y[idx];
934 *f++ = Y[Idx]; 896 if (idx & 0x01)
935 if ( Idx & 0x01) 897 *u++ = U[idx >> 1];
936 *u++ = U[Idx>>1] ;
937 else 898 else
938 *v++ = V[Idx>>1]; 899 *v++ = V[idx >> 1];
939 } 900 } else if (frame->v4l2_format.format == V4L2_PIX_FMT_YVU420) {
940 else if (frame->v4l2_format.format == V4L2_PIX_FMT_YVU420) { 901 *f++ = Y[idx];
941 *f++ = Y [Idx]; 902 if (!((idx & 0x01) | (frame->curline & 0x01))) {
942 if ( !(( Idx & 0x01 ) | ( frame->curline & 0x01 )) ){ 903 /* only need do this for 1 in 4 pixels */
943 904 /* intraframe buffer is YUV420 format */
944/* only need do this for 1 in 4 pixels */ 905 *u++ = U[idx >> 1];
945/* intraframe buffer is YUV420 format */ 906 *v++ = V[idx >> 1];
946
947 *u++ = U[Idx >>1];
948 *v++ = V[Idx >>1];
949 } 907 }
950 908 } else {
951 } 909 YUV_TO_RGB_BY_THE_BOOK(Y[idx], U[idx / 2], V[idx / 2], rv, gv, bv);
952 else {
953 YUV_TO_RGB_BY_THE_BOOK(Y[Idx], U[Idx/2], V[Idx/2], rv, gv, bv);
954 switch (frame->v4l2_format.format) { 910 switch (frame->v4l2_format.format) {
955 case V4L2_PIX_FMT_GREY: 911 case V4L2_PIX_FMT_GREY:
956 *f++ = Y[Idx]; 912 *f++ = Y[idx];
957 break; 913 break;
958 case V4L2_PIX_FMT_RGB555: 914 case V4L2_PIX_FMT_RGB555:
959 *f++ = (0x1F & rv) | 915 *f++ = (0x1F & rv) |
960 (0xE0 & (gv << 5)); 916 (0xE0 & (gv << 5));
961 *f++ = (0x03 & (gv >> 3)) | 917 *f++ = (0x03 & (gv >> 3)) |
962 (0x7C & (bv << 2)); 918 (0x7C & (bv << 2));
963 break; 919 break;
964 case V4L2_PIX_FMT_RGB565: 920 case V4L2_PIX_FMT_RGB565:
965 *f++ = (0x1F & rv) | 921 *f++ = (0x1F & rv) |
966 (0xE0 & (gv << 5)); 922 (0xE0 & (gv << 5));
967 *f++ = (0x07 & (gv >> 3)) | 923 *f++ = (0x07 & (gv >> 3)) |
968 (0xF8 & bv); 924 (0xF8 & bv);
969 break; 925 break;
970 case V4L2_PIX_FMT_RGB24: 926 case V4L2_PIX_FMT_RGB24:
971 *f++ = rv; 927 *f++ = rv;
972 *f++ = gv; 928 *f++ = gv;
973 *f++ = bv; 929 *f++ = bv;
974 break; 930 break;
975 case V4L2_PIX_FMT_RGB32: 931 case V4L2_PIX_FMT_RGB32:
976 *f++ = rv; 932 *f++ = rv;
977 *f++ = gv; 933 *f++ = gv;
978 *f++ = bv; 934 *f++ = bv;
979 f++; 935 f++;
980 break; 936 break;
981 } 937 }
982 } 938 }
983 clipmask_index++; 939 clipmask_index++;
984 } 940 }
985 /* Deal with non-integer no. of bytes for YUV420P */ 941 /* Deal with non-integer no. of bytes for YUV420P */
986 if (frame->v4l2_format.format != V4L2_PIX_FMT_YVU420 ) 942 if (frame->v4l2_format.format != V4L2_PIX_FMT_YVU420)
987 *pcopylen += frame->v4l2_linesize; 943 *pcopylen += frame->v4l2_linesize;
988 else 944 else
989 *pcopylen += frame->curline & 0x01 ? frame->v4l2_linesize : frame->v4l2_linesize << 1; 945 *pcopylen += frame->curline & 0x01 ? frame->v4l2_linesize : frame->v4l2_linesize << 1;
990 946
991 frame->curline += 1; 947 frame->curline += 1;
992 948
993 if (frame->curline >= frame->frmheight) { 949 if (frame->curline >= frame->frmheight)
994 return ParseState_NextFrame; 950 return parse_state_next_frame;
995 } 951 return parse_state_continue;
996 else {
997 return ParseState_Continue;
998 }
999 952
1000} 953}
1001 954
@@ -1008,7 +961,7 @@ static enum ParseState usbvision_parse_compress(struct usb_usbvision *usbvision,
1008 * number of bytes (RGB) to the *pcopylen. 961 * number of bytes (RGB) to the *pcopylen.
1009 * 962 *
1010 */ 963 */
1011static enum ParseState usbvision_parse_lines_420(struct usb_usbvision *usbvision, 964static enum parse_state usbvision_parse_lines_420(struct usb_usbvision *usbvision,
1012 long *pcopylen) 965 long *pcopylen)
1013{ 966{
1014 struct usbvision_frame *frame; 967 struct usbvision_frame *frame;
@@ -1016,11 +969,11 @@ static enum ParseState usbvision_parse_lines_420(struct usb_usbvision *usbvision
1016 unsigned int pixel_per_line, block; 969 unsigned int pixel_per_line, block;
1017 int pixel, block_split; 970 int pixel, block_split;
1018 int y_ptr, u_ptr, v_ptr, y_odd_offset; 971 int y_ptr, u_ptr, v_ptr, y_odd_offset;
1019 const int y_block_size = 128; 972 const int y_block_size = 128;
1020 const int uv_block_size = 64; 973 const int uv_block_size = 64;
1021 const int sub_block_size = 32; 974 const int sub_block_size = 32;
1022 const int y_step[] = { 0, 0, 0, 2 }, y_step_size = 4; 975 const int y_step[] = { 0, 0, 0, 2 }, y_step_size = 4;
1023 const int uv_step[]= { 0, 0, 0, 4 }, uv_step_size = 4; 976 const int uv_step[] = { 0, 0, 0, 4 }, uv_step_size = 4;
1024 unsigned char y[2], u, v; /* YUV components */ 977 unsigned char y[2], u, v; /* YUV components */
1025 int y_, u_, v_, vb, uvg, ur; 978 int y_, u_, v_, vb, uvg, ur;
1026 int r_, g_, b_; /* RGB components */ 979 int r_, g_, b_; /* RGB components */
@@ -1028,7 +981,7 @@ static enum ParseState usbvision_parse_lines_420(struct usb_usbvision *usbvision
1028 int clipmask_even_index, clipmask_odd_index, bytes_per_pixel; 981 int clipmask_even_index, clipmask_odd_index, bytes_per_pixel;
1029 int clipmask_add, stretch_bytes; 982 int clipmask_add, stretch_bytes;
1030 983
1031 frame = usbvision->curFrame; 984 frame = usbvision->cur_frame;
1032 f_even = frame->data + (frame->v4l2_linesize * frame->curline); 985 f_even = frame->data + (frame->v4l2_linesize * frame->curline);
1033 f_odd = f_even + frame->v4l2_linesize * usbvision->stretch_height; 986 f_odd = f_even + frame->v4l2_linesize * usbvision->stretch_height;
1034 987
@@ -1040,18 +993,17 @@ static enum ParseState usbvision_parse_lines_420(struct usb_usbvision *usbvision
1040 clipmask_even_index = frame->curline * MAX_FRAME_WIDTH; 993 clipmask_even_index = frame->curline * MAX_FRAME_WIDTH;
1041 clipmask_odd_index = clipmask_even_index + MAX_FRAME_WIDTH; 994 clipmask_odd_index = clipmask_even_index + MAX_FRAME_WIDTH;
1042 clipmask_add = usbvision->stretch_width; 995 clipmask_add = usbvision->stretch_width;
1043 pixel_per_line = frame->isocHeader.frameWidth; 996 pixel_per_line = frame->isoc_header.frame_width;
1044 997
1045 if (scratch_len(usbvision) < (int)pixel_per_line * 3) { 998 if (scratch_len(usbvision) < (int)pixel_per_line * 3) {
1046 //printk(KERN_DEBUG "out of data, need %d\n", len); 999 /* printk(KERN_DEBUG "out of data, need %d\n", len); */
1047 return ParseState_Out; 1000 return parse_state_out;
1048 } 1001 }
1049 1002
1050 if ((frame->curline + 1) >= frame->frmheight) { 1003 if ((frame->curline + 1) >= frame->frmheight)
1051 return ParseState_NextFrame; 1004 return parse_state_next_frame;
1052 }
1053 1005
1054 block_split = (pixel_per_line%y_block_size) ? 1 : 0; //are some blocks splitted into different lines? 1006 block_split = (pixel_per_line%y_block_size) ? 1 : 0; /* are some blocks splitted into different lines? */
1055 1007
1056 y_odd_offset = (pixel_per_line / y_block_size) * (y_block_size + uv_block_size) 1008 y_odd_offset = (pixel_per_line / y_block_size) * (y_block_size + uv_block_size)
1057 + block_split * uv_block_size; 1009 + block_split * uv_block_size;
@@ -1061,31 +1013,27 @@ static enum ParseState usbvision_parse_lines_420(struct usb_usbvision *usbvision
1061 scratch_set_extra_ptr(usbvision, &v_ptr, y_odd_offset 1013 scratch_set_extra_ptr(usbvision, &v_ptr, y_odd_offset
1062 + (4 - block_split) * sub_block_size); 1014 + (4 - block_split) * sub_block_size);
1063 1015
1064 for (block = 0; block < (pixel_per_line / sub_block_size); 1016 for (block = 0; block < (pixel_per_line / sub_block_size); block++) {
1065 block++) { 1017 for (pixel = 0; pixel < sub_block_size; pixel += 2) {
1066
1067
1068 for (pixel = 0; pixel < sub_block_size; pixel +=2) {
1069 scratch_get(usbvision, &y[0], 2); 1018 scratch_get(usbvision, &y[0], 2);
1070 scratch_get_extra(usbvision, &u, &u_ptr, 1); 1019 scratch_get_extra(usbvision, &u, &u_ptr, 1);
1071 scratch_get_extra(usbvision, &v, &v_ptr, 1); 1020 scratch_get_extra(usbvision, &v, &v_ptr, 1);
1072 1021
1073 //I don't use the YUV_TO_RGB macro for better performance 1022 /* I don't use the YUV_TO_RGB macro for better performance */
1074 v_ = v - 128; 1023 v_ = v - 128;
1075 u_ = u - 128; 1024 u_ = u - 128;
1076 vb = 132252 * v_; 1025 vb = 132252 * v_;
1077 uvg= -53281 * u_ - 25625 * v_; 1026 uvg = -53281 * u_ - 25625 * v_;
1078 ur = 104595 * u_; 1027 ur = 104595 * u_;
1079 1028
1080 if(frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) { 1029 if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
1081 *f_even++ = y[0]; 1030 *f_even++ = y[0];
1082 *f_even++ = v; 1031 *f_even++ = v;
1083 } 1032 } else {
1084 else {
1085 y_ = 76284 * (y[0] - 16); 1033 y_ = 76284 * (y[0] - 16);
1086 1034
1087 b_ = (y_ + vb) >> 16; 1035 b_ = (y_ + vb) >> 16;
1088 g_ = (y_ + uvg)>> 16; 1036 g_ = (y_ + uvg) >> 16;
1089 r_ = (y_ + ur) >> 16; 1037 r_ = (y_ + ur) >> 16;
1090 1038
1091 switch (frame->v4l2_format.format) { 1039 switch (frame->v4l2_format.format) {
@@ -1121,15 +1069,14 @@ static enum ParseState usbvision_parse_lines_420(struct usb_usbvision *usbvision
1121 clipmask_even_index += clipmask_add; 1069 clipmask_even_index += clipmask_add;
1122 f_even += stretch_bytes; 1070 f_even += stretch_bytes;
1123 1071
1124 if(frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) { 1072 if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
1125 *f_even++ = y[1]; 1073 *f_even++ = y[1];
1126 *f_even++ = u; 1074 *f_even++ = u;
1127 } 1075 } else {
1128 else {
1129 y_ = 76284 * (y[1] - 16); 1076 y_ = 76284 * (y[1] - 16);
1130 1077
1131 b_ = (y_ + vb) >> 16; 1078 b_ = (y_ + vb) >> 16;
1132 g_ = (y_ + uvg)>> 16; 1079 g_ = (y_ + uvg) >> 16;
1133 r_ = (y_ + ur) >> 16; 1080 r_ = (y_ + ur) >> 16;
1134 1081
1135 switch (frame->v4l2_format.format) { 1082 switch (frame->v4l2_format.format) {
@@ -1167,15 +1114,14 @@ static enum ParseState usbvision_parse_lines_420(struct usb_usbvision *usbvision
1167 1114
1168 scratch_get_extra(usbvision, &y[0], &y_ptr, 2); 1115 scratch_get_extra(usbvision, &y[0], &y_ptr, 2);
1169 1116
1170 if(frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) { 1117 if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
1171 *f_odd++ = y[0]; 1118 *f_odd++ = y[0];
1172 *f_odd++ = v; 1119 *f_odd++ = v;
1173 } 1120 } else {
1174 else {
1175 y_ = 76284 * (y[0] - 16); 1121 y_ = 76284 * (y[0] - 16);
1176 1122
1177 b_ = (y_ + vb) >> 16; 1123 b_ = (y_ + vb) >> 16;
1178 g_ = (y_ + uvg)>> 16; 1124 g_ = (y_ + uvg) >> 16;
1179 r_ = (y_ + ur) >> 16; 1125 r_ = (y_ + ur) >> 16;
1180 1126
1181 switch (frame->v4l2_format.format) { 1127 switch (frame->v4l2_format.format) {
@@ -1211,15 +1157,14 @@ static enum ParseState usbvision_parse_lines_420(struct usb_usbvision *usbvision
1211 clipmask_odd_index += clipmask_add; 1157 clipmask_odd_index += clipmask_add;
1212 f_odd += stretch_bytes; 1158 f_odd += stretch_bytes;
1213 1159
1214 if(frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) { 1160 if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
1215 *f_odd++ = y[1]; 1161 *f_odd++ = y[1];
1216 *f_odd++ = u; 1162 *f_odd++ = u;
1217 } 1163 } else {
1218 else {
1219 y_ = 76284 * (y[1] - 16); 1164 y_ = 76284 * (y[1] - 16);
1220 1165
1221 b_ = (y_ + vb) >> 16; 1166 b_ = (y_ + vb) >> 16;
1222 g_ = (y_ + uvg)>> 16; 1167 g_ = (y_ + uvg) >> 16;
1223 r_ = (y_ + ur) >> 16; 1168 r_ = (y_ + ur) >> 16;
1224 1169
1225 switch (frame->v4l2_format.format) { 1170 switch (frame->v4l2_format.format) {
@@ -1256,7 +1201,7 @@ static enum ParseState usbvision_parse_lines_420(struct usb_usbvision *usbvision
1256 f_odd += stretch_bytes; 1201 f_odd += stretch_bytes;
1257 } 1202 }
1258 1203
1259 scratch_rm_old(usbvision,y_step[block % y_step_size] * sub_block_size); 1204 scratch_rm_old(usbvision, y_step[block % y_step_size] * sub_block_size);
1260 scratch_inc_extra_ptr(&y_ptr, y_step[(block + 2 * block_split) % y_step_size] 1205 scratch_inc_extra_ptr(&y_ptr, y_step[(block + 2 * block_split) % y_step_size]
1261 * sub_block_size); 1206 * sub_block_size);
1262 scratch_inc_extra_ptr(&u_ptr, uv_step[block % uv_step_size] 1207 scratch_inc_extra_ptr(&u_ptr, uv_step[block % uv_step_size]
@@ -1272,9 +1217,8 @@ static enum ParseState usbvision_parse_lines_420(struct usb_usbvision *usbvision
1272 *pcopylen += frame->v4l2_linesize * 2 * usbvision->stretch_height; 1217 *pcopylen += frame->v4l2_linesize * 2 * usbvision->stretch_height;
1273 1218
1274 if (frame->curline >= frame->frmheight) 1219 if (frame->curline >= frame->frmheight)
1275 return ParseState_NextFrame; 1220 return parse_state_next_frame;
1276 else 1221 return parse_state_continue;
1277 return ParseState_Continue;
1278} 1222}
1279 1223
1280/* 1224/*
@@ -1288,53 +1232,43 @@ static enum ParseState usbvision_parse_lines_420(struct usb_usbvision *usbvision
1288static void usbvision_parse_data(struct usb_usbvision *usbvision) 1232static void usbvision_parse_data(struct usb_usbvision *usbvision)
1289{ 1233{
1290 struct usbvision_frame *frame; 1234 struct usbvision_frame *frame;
1291 enum ParseState newstate; 1235 enum parse_state newstate;
1292 long copylen = 0; 1236 long copylen = 0;
1293 unsigned long lock_flags; 1237 unsigned long lock_flags;
1294 1238
1295 frame = usbvision->curFrame; 1239 frame = usbvision->cur_frame;
1296 1240
1297 PDEBUG(DBG_PARSE, "parsing len=%d\n", scratch_len(usbvision)); 1241 PDEBUG(DBG_PARSE, "parsing len=%d\n", scratch_len(usbvision));
1298 1242
1299 while (1) { 1243 while (1) {
1300 1244 newstate = parse_state_out;
1301 newstate = ParseState_Out;
1302 if (scratch_len(usbvision)) { 1245 if (scratch_len(usbvision)) {
1303 if (frame->scanstate == ScanState_Scanning) { 1246 if (frame->scanstate == scan_state_scanning) {
1304 newstate = usbvision_find_header(usbvision); 1247 newstate = usbvision_find_header(usbvision);
1305 } 1248 } else if (frame->scanstate == scan_state_lines) {
1306 else if (frame->scanstate == ScanState_Lines) { 1249 if (usbvision->isoc_mode == ISOC_MODE_YUV420)
1307 if (usbvision->isocMode == ISOC_MODE_YUV420) {
1308 newstate = usbvision_parse_lines_420(usbvision, &copylen); 1250 newstate = usbvision_parse_lines_420(usbvision, &copylen);
1309 } 1251 else if (usbvision->isoc_mode == ISOC_MODE_YUV422)
1310 else if (usbvision->isocMode == ISOC_MODE_YUV422) {
1311 newstate = usbvision_parse_lines_422(usbvision, &copylen); 1252 newstate = usbvision_parse_lines_422(usbvision, &copylen);
1312 } 1253 else if (usbvision->isoc_mode == ISOC_MODE_COMPRESS)
1313 else if (usbvision->isocMode == ISOC_MODE_COMPRESS) {
1314 newstate = usbvision_parse_compress(usbvision, &copylen); 1254 newstate = usbvision_parse_compress(usbvision, &copylen);
1315 }
1316
1317 } 1255 }
1318 } 1256 }
1319 if (newstate == ParseState_Continue) { 1257 if (newstate == parse_state_continue)
1320 continue; 1258 continue;
1321 } 1259 if ((newstate == parse_state_next_frame) || (newstate == parse_state_out))
1322 else if ((newstate == ParseState_NextFrame) || (newstate == ParseState_Out)) {
1323 break; 1260 break;
1324 } 1261 return; /* parse_state_end_parse */
1325 else {
1326 return; /* ParseState_EndParse */
1327 }
1328 } 1262 }
1329 1263
1330 if (newstate == ParseState_NextFrame) { 1264 if (newstate == parse_state_next_frame) {
1331 frame->grabstate = FrameState_Done; 1265 frame->grabstate = frame_state_done;
1332 do_gettimeofday(&(frame->timestamp)); 1266 do_gettimeofday(&(frame->timestamp));
1333 frame->sequence = usbvision->frame_num; 1267 frame->sequence = usbvision->frame_num;
1334 1268
1335 spin_lock_irqsave(&usbvision->queue_lock, lock_flags); 1269 spin_lock_irqsave(&usbvision->queue_lock, lock_flags);
1336 list_move_tail(&(frame->frame), &usbvision->outqueue); 1270 list_move_tail(&(frame->frame), &usbvision->outqueue);
1337 usbvision->curFrame = NULL; 1271 usbvision->cur_frame = NULL;
1338 spin_unlock_irqrestore(&usbvision->queue_lock, lock_flags); 1272 spin_unlock_irqrestore(&usbvision->queue_lock, lock_flags);
1339 1273
1340 usbvision->frame_num++; 1274 usbvision->frame_num++;
@@ -1344,10 +1278,9 @@ static void usbvision_parse_data(struct usb_usbvision *usbvision)
1344 PDEBUG(DBG_PARSE, "Wake up !"); 1278 PDEBUG(DBG_PARSE, "Wake up !");
1345 wake_up_interruptible(&usbvision->wait_frame); 1279 wake_up_interruptible(&usbvision->wait_frame);
1346 } 1280 }
1281 } else {
1282 frame->grabstate = frame_state_grabbing;
1347 } 1283 }
1348 else
1349 frame->grabstate = FrameState_Grabbing;
1350
1351 1284
1352 /* Update the frame's uncompressed length. */ 1285 /* Update the frame's uncompressed length. */
1353 frame->scanlength += copylen; 1286 frame->scanlength += copylen;
@@ -1370,34 +1303,32 @@ static int usbvision_compress_isochronous(struct usb_usbvision *usbvision,
1370 packet_data = urb->transfer_buffer + urb->iso_frame_desc[i].offset; 1303 packet_data = urb->transfer_buffer + urb->iso_frame_desc[i].offset;
1371 1304
1372 /* Detect and ignore errored packets */ 1305 /* Detect and ignore errored packets */
1373 if (packet_stat) { // packet_stat != 0 ????????????? 1306 if (packet_stat) { /* packet_stat != 0 ????????????? */
1374 PDEBUG(DBG_ISOC, "data error: [%d] len=%d, status=%X", i, packet_len, packet_stat); 1307 PDEBUG(DBG_ISOC, "data error: [%d] len=%d, status=%X", i, packet_len, packet_stat);
1375 usbvision->isocErrCount++; 1308 usbvision->isoc_err_count++;
1376 continue; 1309 continue;
1377 } 1310 }
1378 1311
1379 /* Detect and ignore empty packets */ 1312 /* Detect and ignore empty packets */
1380 if (packet_len < 0) { 1313 if (packet_len < 0) {
1381 PDEBUG(DBG_ISOC, "error packet [%d]", i); 1314 PDEBUG(DBG_ISOC, "error packet [%d]", i);
1382 usbvision->isocSkipCount++; 1315 usbvision->isoc_skip_count++;
1383 continue; 1316 continue;
1384 } 1317 } else if (packet_len == 0) { /* Frame end ????? */
1385 else if (packet_len == 0) { /* Frame end ????? */
1386 PDEBUG(DBG_ISOC, "null packet [%d]", i); 1318 PDEBUG(DBG_ISOC, "null packet [%d]", i);
1387 usbvision->isocstate=IsocState_NoFrame; 1319 usbvision->isocstate = isoc_state_no_frame;
1388 usbvision->isocSkipCount++; 1320 usbvision->isoc_skip_count++;
1389 continue; 1321 continue;
1390 } 1322 } else if (packet_len > usbvision->isoc_packet_size) {
1391 else if (packet_len > usbvision->isocPacketSize) { 1323 PDEBUG(DBG_ISOC, "packet[%d] > isoc_packet_size", i);
1392 PDEBUG(DBG_ISOC, "packet[%d] > isocPacketSize", i); 1324 usbvision->isoc_skip_count++;
1393 usbvision->isocSkipCount++;
1394 continue; 1325 continue;
1395 } 1326 }
1396 1327
1397 PDEBUG(DBG_ISOC, "packet ok [%d] len=%d", i, packet_len); 1328 PDEBUG(DBG_ISOC, "packet ok [%d] len=%d", i, packet_len);
1398 1329
1399 if (usbvision->isocstate==IsocState_NoFrame) { //new frame begins 1330 if (usbvision->isocstate == isoc_state_no_frame) { /* new frame begins */
1400 usbvision->isocstate=IsocState_InFrame; 1331 usbvision->isocstate = isoc_state_in_frame;
1401 scratch_mark_header(usbvision); 1332 scratch_mark_header(usbvision);
1402 usbvision_measure_bandwidth(usbvision); 1333 usbvision_measure_bandwidth(usbvision);
1403 PDEBUG(DBG_ISOC, "packet with header"); 1334 PDEBUG(DBG_ISOC, "packet with header");
@@ -1412,7 +1343,6 @@ static int usbvision_compress_isochronous(struct usb_usbvision *usbvision,
1412 * your favorite evil here. 1343 * your favorite evil here.
1413 */ 1344 */
1414 if (scratch_free(usbvision) < packet_len) { 1345 if (scratch_free(usbvision) < packet_len) {
1415
1416 usbvision->scratch_ovf_count++; 1346 usbvision->scratch_ovf_count++;
1417 PDEBUG(DBG_ISOC, "scratch buf overflow! scr_len: %d, n: %d", 1347 PDEBUG(DBG_ISOC, "scratch buf overflow! scr_len: %d, n: %d",
1418 scratch_len(usbvision), packet_len); 1348 scratch_len(usbvision), packet_len);
@@ -1422,12 +1352,13 @@ static int usbvision_compress_isochronous(struct usb_usbvision *usbvision,
1422 /* Now we know that there is enough room in scratch buffer */ 1352 /* Now we know that there is enough room in scratch buffer */
1423 scratch_put(usbvision, packet_data, packet_len); 1353 scratch_put(usbvision, packet_data, packet_len);
1424 totlen += packet_len; 1354 totlen += packet_len;
1425 usbvision->isocDataCount += packet_len; 1355 usbvision->isoc_data_count += packet_len;
1426 usbvision->isocPacketCount++; 1356 usbvision->isoc_packet_count++;
1427 } 1357 }
1428#if ENABLE_HEXDUMP 1358#if ENABLE_HEXDUMP
1429 if (totlen > 0) { 1359 if (totlen > 0) {
1430 static int foo; 1360 static int foo;
1361
1431 if (foo < 1) { 1362 if (foo < 1) {
1432 printk(KERN_DEBUG "+%d.\n", usbvision->scratchlen); 1363 printk(KERN_DEBUG "+%d.\n", usbvision->scratchlen);
1433 usbvision_hexdump(data0, (totlen > 64) ? 64 : totlen); 1364 usbvision_hexdump(data0, (totlen > 64) ? 64 : totlen);
@@ -1435,16 +1366,16 @@ static int usbvision_compress_isochronous(struct usb_usbvision *usbvision,
1435 } 1366 }
1436 } 1367 }
1437#endif 1368#endif
1438 return totlen; 1369 return totlen;
1439} 1370}
1440 1371
1441static void usbvision_isocIrq(struct urb *urb) 1372static void usbvision_isoc_irq(struct urb *urb)
1442{ 1373{
1443 int errCode = 0; 1374 int err_code = 0;
1444 int len; 1375 int len;
1445 struct usb_usbvision *usbvision = urb->context; 1376 struct usb_usbvision *usbvision = urb->context;
1446 int i; 1377 int i;
1447 unsigned long startTime = jiffies; 1378 unsigned long start_time = jiffies;
1448 struct usbvision_frame **f; 1379 struct usbvision_frame **f;
1449 1380
1450 /* We don't want to do anything if we are about to be removed! */ 1381 /* We don't want to do anything if we are about to be removed! */
@@ -1452,18 +1383,17 @@ static void usbvision_isocIrq(struct urb *urb)
1452 return; 1383 return;
1453 1384
1454 /* any urb with wrong status is ignored without acknowledgement */ 1385 /* any urb with wrong status is ignored without acknowledgement */
1455 if (urb->status == -ENOENT) { 1386 if (urb->status == -ENOENT)
1456 return; 1387 return;
1457 }
1458 1388
1459 f = &usbvision->curFrame; 1389 f = &usbvision->cur_frame;
1460 1390
1461 /* Manage streaming interruption */ 1391 /* Manage streaming interruption */
1462 if (usbvision->streaming == Stream_Interrupt) { 1392 if (usbvision->streaming == stream_interrupt) {
1463 usbvision->streaming = Stream_Idle; 1393 usbvision->streaming = stream_idle;
1464 if ((*f)) { 1394 if ((*f)) {
1465 (*f)->grabstate = FrameState_Ready; 1395 (*f)->grabstate = frame_state_ready;
1466 (*f)->scanstate = ScanState_Scanning; 1396 (*f)->scanstate = scan_state_scanning;
1467 } 1397 }
1468 PDEBUG(DBG_IRQ, "stream interrupted"); 1398 PDEBUG(DBG_IRQ, "stream interrupted");
1469 wake_up_interruptible(&usbvision->wait_stream); 1399 wake_up_interruptible(&usbvision->wait_stream);
@@ -1472,35 +1402,32 @@ static void usbvision_isocIrq(struct urb *urb)
1472 /* Copy the data received into our scratch buffer */ 1402 /* Copy the data received into our scratch buffer */
1473 len = usbvision_compress_isochronous(usbvision, urb); 1403 len = usbvision_compress_isochronous(usbvision, urb);
1474 1404
1475 usbvision->isocUrbCount++; 1405 usbvision->isoc_urb_count++;
1476 usbvision->urb_length = len; 1406 usbvision->urb_length = len;
1477 1407
1478 if (usbvision->streaming == Stream_On) { 1408 if (usbvision->streaming == stream_on) {
1479
1480 /* If we collected enough data let's parse! */ 1409 /* If we collected enough data let's parse! */
1481 if ((scratch_len(usbvision) > USBVISION_HEADER_LENGTH) && 1410 if (scratch_len(usbvision) > USBVISION_HEADER_LENGTH &&
1482 (!list_empty(&(usbvision->inqueue))) ) { 1411 !list_empty(&(usbvision->inqueue))) {
1483 if (!(*f)) { 1412 if (!(*f)) {
1484 (*f) = list_entry(usbvision->inqueue.next, 1413 (*f) = list_entry(usbvision->inqueue.next,
1485 struct usbvision_frame, 1414 struct usbvision_frame,
1486 frame); 1415 frame);
1487 } 1416 }
1488 usbvision_parse_data(usbvision); 1417 usbvision_parse_data(usbvision);
1489 } 1418 } else {
1490 else { 1419 /* If we don't have a frame
1491 /*If we don't have a frame
1492 we're current working on, complain */ 1420 we're current working on, complain */
1493 PDEBUG(DBG_IRQ, 1421 PDEBUG(DBG_IRQ,
1494 "received data, but no one needs it"); 1422 "received data, but no one needs it");
1495 scratch_reset(usbvision); 1423 scratch_reset(usbvision);
1496 } 1424 }
1497 } 1425 } else {
1498 else {
1499 PDEBUG(DBG_IRQ, "received data, but no one needs it"); 1426 PDEBUG(DBG_IRQ, "received data, but no one needs it");
1500 scratch_reset(usbvision); 1427 scratch_reset(usbvision);
1501 } 1428 }
1502 1429
1503 usbvision->timeInIrq += jiffies - startTime; 1430 usbvision->time_in_irq += jiffies - start_time;
1504 1431
1505 for (i = 0; i < USBVISION_URB_FRAMES; i++) { 1432 for (i = 0; i < USBVISION_URB_FRAMES; i++) {
1506 urb->iso_frame_desc[i].status = 0; 1433 urb->iso_frame_desc[i].status = 0;
@@ -1509,12 +1436,12 @@ static void usbvision_isocIrq(struct urb *urb)
1509 1436
1510 urb->status = 0; 1437 urb->status = 0;
1511 urb->dev = usbvision->dev; 1438 urb->dev = usbvision->dev;
1512 errCode = usb_submit_urb (urb, GFP_ATOMIC); 1439 err_code = usb_submit_urb(urb, GFP_ATOMIC);
1513 1440
1514 if(errCode) { 1441 if (err_code) {
1515 dev_err(&usbvision->dev->dev, 1442 dev_err(&usbvision->dev->dev,
1516 "%s: usb_submit_urb failed: error %d\n", 1443 "%s: usb_submit_urb failed: error %d\n",
1517 __func__, errCode); 1444 __func__, err_code);
1518 } 1445 }
1519 1446
1520 return; 1447 return;
@@ -1533,21 +1460,21 @@ static void usbvision_isocIrq(struct urb *urb)
1533 1460
1534int usbvision_read_reg(struct usb_usbvision *usbvision, unsigned char reg) 1461int usbvision_read_reg(struct usb_usbvision *usbvision, unsigned char reg)
1535{ 1462{
1536 int errCode = 0; 1463 int err_code = 0;
1537 unsigned char buffer[1]; 1464 unsigned char buffer[1];
1538 1465
1539 if (!USBVISION_IS_OPERATIONAL(usbvision)) 1466 if (!USBVISION_IS_OPERATIONAL(usbvision))
1540 return -1; 1467 return -1;
1541 1468
1542 errCode = usb_control_msg(usbvision->dev, usb_rcvctrlpipe(usbvision->dev, 1), 1469 err_code = usb_control_msg(usbvision->dev, usb_rcvctrlpipe(usbvision->dev, 1),
1543 USBVISION_OP_CODE, 1470 USBVISION_OP_CODE,
1544 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT, 1471 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT,
1545 0, (__u16) reg, buffer, 1, HZ); 1472 0, (__u16) reg, buffer, 1, HZ);
1546 1473
1547 if (errCode < 0) { 1474 if (err_code < 0) {
1548 dev_err(&usbvision->dev->dev, 1475 dev_err(&usbvision->dev->dev,
1549 "%s: failed: error %d\n", __func__, errCode); 1476 "%s: failed: error %d\n", __func__, err_code);
1550 return errCode; 1477 return err_code;
1551 } 1478 }
1552 return buffer[0]; 1479 return buffer[0];
1553} 1480}
@@ -1563,179 +1490,176 @@ int usbvision_read_reg(struct usb_usbvision *usbvision, unsigned char reg)
1563int usbvision_write_reg(struct usb_usbvision *usbvision, unsigned char reg, 1490int usbvision_write_reg(struct usb_usbvision *usbvision, unsigned char reg,
1564 unsigned char value) 1491 unsigned char value)
1565{ 1492{
1566 int errCode = 0; 1493 int err_code = 0;
1567 1494
1568 if (!USBVISION_IS_OPERATIONAL(usbvision)) 1495 if (!USBVISION_IS_OPERATIONAL(usbvision))
1569 return 0; 1496 return 0;
1570 1497
1571 errCode = usb_control_msg(usbvision->dev, usb_sndctrlpipe(usbvision->dev, 1), 1498 err_code = usb_control_msg(usbvision->dev, usb_sndctrlpipe(usbvision->dev, 1),
1572 USBVISION_OP_CODE, 1499 USBVISION_OP_CODE,
1573 USB_DIR_OUT | USB_TYPE_VENDOR | 1500 USB_DIR_OUT | USB_TYPE_VENDOR |
1574 USB_RECIP_ENDPOINT, 0, (__u16) reg, &value, 1, HZ); 1501 USB_RECIP_ENDPOINT, 0, (__u16) reg, &value, 1, HZ);
1575 1502
1576 if (errCode < 0) { 1503 if (err_code < 0) {
1577 dev_err(&usbvision->dev->dev, 1504 dev_err(&usbvision->dev->dev,
1578 "%s: failed: error %d\n", __func__, errCode); 1505 "%s: failed: error %d\n", __func__, err_code);
1579 } 1506 }
1580 return errCode; 1507 return err_code;
1581} 1508}
1582 1509
1583 1510
1584static void usbvision_ctrlUrb_complete(struct urb *urb) 1511static void usbvision_ctrl_urb_complete(struct urb *urb)
1585{ 1512{
1586 struct usb_usbvision *usbvision = (struct usb_usbvision *)urb->context; 1513 struct usb_usbvision *usbvision = (struct usb_usbvision *)urb->context;
1587 1514
1588 PDEBUG(DBG_IRQ, ""); 1515 PDEBUG(DBG_IRQ, "");
1589 usbvision->ctrlUrbBusy = 0; 1516 usbvision->ctrl_urb_busy = 0;
1590 if (waitqueue_active(&usbvision->ctrlUrb_wq)) { 1517 if (waitqueue_active(&usbvision->ctrl_urb_wq))
1591 wake_up_interruptible(&usbvision->ctrlUrb_wq); 1518 wake_up_interruptible(&usbvision->ctrl_urb_wq);
1592 }
1593} 1519}
1594 1520
1595 1521
1596static int usbvision_write_reg_irq(struct usb_usbvision *usbvision,int address, 1522static int usbvision_write_reg_irq(struct usb_usbvision *usbvision, int address,
1597 unsigned char *data, int len) 1523 unsigned char *data, int len)
1598{ 1524{
1599 int errCode = 0; 1525 int err_code = 0;
1600 1526
1601 PDEBUG(DBG_IRQ, ""); 1527 PDEBUG(DBG_IRQ, "");
1602 if (len > 8) { 1528 if (len > 8)
1603 return -EFAULT; 1529 return -EFAULT;
1604 } 1530 if (usbvision->ctrl_urb_busy)
1605 if (usbvision->ctrlUrbBusy) {
1606 return -EBUSY; 1531 return -EBUSY;
1607 } 1532 usbvision->ctrl_urb_busy = 1;
1608 usbvision->ctrlUrbBusy = 1; 1533
1609 1534 usbvision->ctrl_urb_setup.bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT;
1610 usbvision->ctrlUrbSetup.bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT; 1535 usbvision->ctrl_urb_setup.bRequest = USBVISION_OP_CODE;
1611 usbvision->ctrlUrbSetup.bRequest = USBVISION_OP_CODE; 1536 usbvision->ctrl_urb_setup.wValue = 0;
1612 usbvision->ctrlUrbSetup.wValue = 0; 1537 usbvision->ctrl_urb_setup.wIndex = cpu_to_le16(address);
1613 usbvision->ctrlUrbSetup.wIndex = cpu_to_le16(address); 1538 usbvision->ctrl_urb_setup.wLength = cpu_to_le16(len);
1614 usbvision->ctrlUrbSetup.wLength = cpu_to_le16(len); 1539 usb_fill_control_urb(usbvision->ctrl_urb, usbvision->dev,
1615 usb_fill_control_urb (usbvision->ctrlUrb, usbvision->dev,
1616 usb_sndctrlpipe(usbvision->dev, 1), 1540 usb_sndctrlpipe(usbvision->dev, 1),
1617 (unsigned char *)&usbvision->ctrlUrbSetup, 1541 (unsigned char *)&usbvision->ctrl_urb_setup,
1618 (void *)usbvision->ctrlUrbBuffer, len, 1542 (void *)usbvision->ctrl_urb_buffer, len,
1619 usbvision_ctrlUrb_complete, 1543 usbvision_ctrl_urb_complete,
1620 (void *)usbvision); 1544 (void *)usbvision);
1621 1545
1622 memcpy(usbvision->ctrlUrbBuffer, data, len); 1546 memcpy(usbvision->ctrl_urb_buffer, data, len);
1623 1547
1624 errCode = usb_submit_urb(usbvision->ctrlUrb, GFP_ATOMIC); 1548 err_code = usb_submit_urb(usbvision->ctrl_urb, GFP_ATOMIC);
1625 if (errCode < 0) { 1549 if (err_code < 0) {
1626 // error in usb_submit_urb() 1550 /* error in usb_submit_urb() */
1627 usbvision->ctrlUrbBusy = 0; 1551 usbvision->ctrl_urb_busy = 0;
1628 } 1552 }
1629 PDEBUG(DBG_IRQ, "submit %d byte: error %d", len, errCode); 1553 PDEBUG(DBG_IRQ, "submit %d byte: error %d", len, err_code);
1630 return errCode; 1554 return err_code;
1631} 1555}
1632 1556
1633 1557
1634static int usbvision_init_compression(struct usb_usbvision *usbvision) 1558static int usbvision_init_compression(struct usb_usbvision *usbvision)
1635{ 1559{
1636 int errCode = 0; 1560 int err_code = 0;
1637 1561
1638 usbvision->lastIsocFrameNum = -1; 1562 usbvision->last_isoc_frame_num = -1;
1639 usbvision->isocDataCount = 0; 1563 usbvision->isoc_data_count = 0;
1640 usbvision->isocPacketCount = 0; 1564 usbvision->isoc_packet_count = 0;
1641 usbvision->isocSkipCount = 0; 1565 usbvision->isoc_skip_count = 0;
1642 usbvision->comprLevel = 50; 1566 usbvision->compr_level = 50;
1643 usbvision->lastComprLevel = -1; 1567 usbvision->last_compr_level = -1;
1644 usbvision->isocUrbCount = 0; 1568 usbvision->isoc_urb_count = 0;
1645 usbvision->requestIntra = 1; 1569 usbvision->request_intra = 1;
1646 usbvision->isocMeasureBandwidthCount = 0; 1570 usbvision->isoc_measure_bandwidth_count = 0;
1647 1571
1648 return errCode; 1572 return err_code;
1649} 1573}
1650 1574
1651/* this function measures the used bandwidth since last call 1575/* this function measures the used bandwidth since last call
1652 * return: 0 : no error 1576 * return: 0 : no error
1653 * sets usedBandwidth to 1-100 : 1-100% of full bandwidth resp. to isocPacketSize 1577 * sets used_bandwidth to 1-100 : 1-100% of full bandwidth resp. to isoc_packet_size
1654 */ 1578 */
1655static int usbvision_measure_bandwidth (struct usb_usbvision *usbvision) 1579static int usbvision_measure_bandwidth(struct usb_usbvision *usbvision)
1656{ 1580{
1657 int errCode = 0; 1581 int err_code = 0;
1658 1582
1659 if (usbvision->isocMeasureBandwidthCount < 2) { // this gives an average bandwidth of 3 frames 1583 if (usbvision->isoc_measure_bandwidth_count < 2) { /* this gives an average bandwidth of 3 frames */
1660 usbvision->isocMeasureBandwidthCount++; 1584 usbvision->isoc_measure_bandwidth_count++;
1661 return errCode; 1585 return err_code;
1662 } 1586 }
1663 if ((usbvision->isocPacketSize > 0) && (usbvision->isocPacketCount > 0)) { 1587 if ((usbvision->isoc_packet_size > 0) && (usbvision->isoc_packet_count > 0)) {
1664 usbvision->usedBandwidth = usbvision->isocDataCount / 1588 usbvision->used_bandwidth = usbvision->isoc_data_count /
1665 (usbvision->isocPacketCount + usbvision->isocSkipCount) * 1589 (usbvision->isoc_packet_count + usbvision->isoc_skip_count) *
1666 100 / usbvision->isocPacketSize; 1590 100 / usbvision->isoc_packet_size;
1667 } 1591 }
1668 usbvision->isocMeasureBandwidthCount = 0; 1592 usbvision->isoc_measure_bandwidth_count = 0;
1669 usbvision->isocDataCount = 0; 1593 usbvision->isoc_data_count = 0;
1670 usbvision->isocPacketCount = 0; 1594 usbvision->isoc_packet_count = 0;
1671 usbvision->isocSkipCount = 0; 1595 usbvision->isoc_skip_count = 0;
1672 return errCode; 1596 return err_code;
1673} 1597}
1674 1598
1675static int usbvision_adjust_compression (struct usb_usbvision *usbvision) 1599static int usbvision_adjust_compression(struct usb_usbvision *usbvision)
1676{ 1600{
1677 int errCode = 0; 1601 int err_code = 0;
1678 unsigned char buffer[6]; 1602 unsigned char buffer[6];
1679 1603
1680 PDEBUG(DBG_IRQ, ""); 1604 PDEBUG(DBG_IRQ, "");
1681 if ((adjustCompression) && (usbvision->usedBandwidth > 0)) { 1605 if ((adjust_compression) && (usbvision->used_bandwidth > 0)) {
1682 usbvision->comprLevel += (usbvision->usedBandwidth - 90) / 2; 1606 usbvision->compr_level += (usbvision->used_bandwidth - 90) / 2;
1683 RESTRICT_TO_RANGE(usbvision->comprLevel, 0, 100); 1607 RESTRICT_TO_RANGE(usbvision->compr_level, 0, 100);
1684 if (usbvision->comprLevel != usbvision->lastComprLevel) { 1608 if (usbvision->compr_level != usbvision->last_compr_level) {
1685 int distorsion; 1609 int distortion;
1686 if (usbvision->bridgeType == BRIDGE_NT1004 || usbvision->bridgeType == BRIDGE_NT1005) { 1610
1687 buffer[0] = (unsigned char)(4 + 16 * usbvision->comprLevel / 100); // PCM Threshold 1 1611 if (usbvision->bridge_type == BRIDGE_NT1004 || usbvision->bridge_type == BRIDGE_NT1005) {
1688 buffer[1] = (unsigned char)(4 + 8 * usbvision->comprLevel / 100); // PCM Threshold 2 1612 buffer[0] = (unsigned char)(4 + 16 * usbvision->compr_level / 100); /* PCM Threshold 1 */
1689 distorsion = 7 + 248 * usbvision->comprLevel / 100; 1613 buffer[1] = (unsigned char)(4 + 8 * usbvision->compr_level / 100); /* PCM Threshold 2 */
1690 buffer[2] = (unsigned char)(distorsion & 0xFF); // Average distorsion Threshold (inter) 1614 distortion = 7 + 248 * usbvision->compr_level / 100;
1691 buffer[3] = (unsigned char)(distorsion & 0xFF); // Average distorsion Threshold (intra) 1615 buffer[2] = (unsigned char)(distortion & 0xFF); /* Average distortion Threshold (inter) */
1692 distorsion = 1 + 42 * usbvision->comprLevel / 100; 1616 buffer[3] = (unsigned char)(distortion & 0xFF); /* Average distortion Threshold (intra) */
1693 buffer[4] = (unsigned char)(distorsion & 0xFF); // Maximum distorsion Threshold (inter) 1617 distortion = 1 + 42 * usbvision->compr_level / 100;
1694 buffer[5] = (unsigned char)(distorsion & 0xFF); // Maximum distorsion Threshold (intra) 1618 buffer[4] = (unsigned char)(distortion & 0xFF); /* Maximum distortion Threshold (inter) */
1695 } 1619 buffer[5] = (unsigned char)(distortion & 0xFF); /* Maximum distortion Threshold (intra) */
1696 else { //BRIDGE_NT1003 1620 } else { /* BRIDGE_NT1003 */
1697 buffer[0] = (unsigned char)(4 + 16 * usbvision->comprLevel / 100); // PCM threshold 1 1621 buffer[0] = (unsigned char)(4 + 16 * usbvision->compr_level / 100); /* PCM threshold 1 */
1698 buffer[1] = (unsigned char)(4 + 8 * usbvision->comprLevel / 100); // PCM threshold 2 1622 buffer[1] = (unsigned char)(4 + 8 * usbvision->compr_level / 100); /* PCM threshold 2 */
1699 distorsion = 2 + 253 * usbvision->comprLevel / 100; 1623 distortion = 2 + 253 * usbvision->compr_level / 100;
1700 buffer[2] = (unsigned char)(distorsion & 0xFF); // distorsion threshold bit0-7 1624 buffer[2] = (unsigned char)(distortion & 0xFF); /* distortion threshold bit0-7 */
1701 buffer[3] = 0; //(unsigned char)((distorsion >> 8) & 0x0F); // distorsion threshold bit 8-11 1625 buffer[3] = 0; /* (unsigned char)((distortion >> 8) & 0x0F); distortion threshold bit 8-11 */
1702 distorsion = 0 + 43 * usbvision->comprLevel / 100; 1626 distortion = 0 + 43 * usbvision->compr_level / 100;
1703 buffer[4] = (unsigned char)(distorsion & 0xFF); // maximum distorsion bit0-7 1627 buffer[4] = (unsigned char)(distortion & 0xFF); /* maximum distortion bit0-7 */
1704 buffer[5] = 0; //(unsigned char)((distorsion >> 8) & 0x01); // maximum distorsion bit 8 1628 buffer[5] = 0; /* (unsigned char)((distortion >> 8) & 0x01); maximum distortion bit 8 */
1705 } 1629 }
1706 errCode = usbvision_write_reg_irq(usbvision, USBVISION_PCM_THR1, buffer, 6); 1630 err_code = usbvision_write_reg_irq(usbvision, USBVISION_PCM_THR1, buffer, 6);
1707 if (errCode == 0){ 1631 if (err_code == 0) {
1708 PDEBUG(DBG_IRQ, "new compr params %#02x %#02x %#02x %#02x %#02x %#02x", buffer[0], 1632 PDEBUG(DBG_IRQ, "new compr params %#02x %#02x %#02x %#02x %#02x %#02x", buffer[0],
1709 buffer[1], buffer[2], buffer[3], buffer[4], buffer[5]); 1633 buffer[1], buffer[2], buffer[3], buffer[4], buffer[5]);
1710 usbvision->lastComprLevel = usbvision->comprLevel; 1634 usbvision->last_compr_level = usbvision->compr_level;
1711 } 1635 }
1712 } 1636 }
1713 } 1637 }
1714 return errCode; 1638 return err_code;
1715} 1639}
1716 1640
1717static int usbvision_request_intra (struct usb_usbvision *usbvision) 1641static int usbvision_request_intra(struct usb_usbvision *usbvision)
1718{ 1642{
1719 int errCode = 0; 1643 int err_code = 0;
1720 unsigned char buffer[1]; 1644 unsigned char buffer[1];
1721 1645
1722 PDEBUG(DBG_IRQ, ""); 1646 PDEBUG(DBG_IRQ, "");
1723 usbvision->requestIntra = 1; 1647 usbvision->request_intra = 1;
1724 buffer[0] = 1; 1648 buffer[0] = 1;
1725 usbvision_write_reg_irq(usbvision, USBVISION_FORCE_INTRA, buffer, 1); 1649 usbvision_write_reg_irq(usbvision, USBVISION_FORCE_INTRA, buffer, 1);
1726 return errCode; 1650 return err_code;
1727} 1651}
1728 1652
1729static int usbvision_unrequest_intra (struct usb_usbvision *usbvision) 1653static int usbvision_unrequest_intra(struct usb_usbvision *usbvision)
1730{ 1654{
1731 int errCode = 0; 1655 int err_code = 0;
1732 unsigned char buffer[1]; 1656 unsigned char buffer[1];
1733 1657
1734 PDEBUG(DBG_IRQ, ""); 1658 PDEBUG(DBG_IRQ, "");
1735 usbvision->requestIntra = 0; 1659 usbvision->request_intra = 0;
1736 buffer[0] = 0; 1660 buffer[0] = 0;
1737 usbvision_write_reg_irq(usbvision, USBVISION_FORCE_INTRA, buffer, 1); 1661 usbvision_write_reg_irq(usbvision, USBVISION_FORCE_INTRA, buffer, 1);
1738 return errCode; 1662 return err_code;
1739} 1663}
1740 1664
1741/******************************* 1665/*******************************
@@ -1744,16 +1668,15 @@ static int usbvision_unrequest_intra (struct usb_usbvision *usbvision)
1744 1668
1745int usbvision_power_off(struct usb_usbvision *usbvision) 1669int usbvision_power_off(struct usb_usbvision *usbvision)
1746{ 1670{
1747 int errCode = 0; 1671 int err_code = 0;
1748 1672
1749 PDEBUG(DBG_FUNC, ""); 1673 PDEBUG(DBG_FUNC, "");
1750 1674
1751 errCode = usbvision_write_reg(usbvision, USBVISION_PWR_REG, USBVISION_SSPND_EN); 1675 err_code = usbvision_write_reg(usbvision, USBVISION_PWR_REG, USBVISION_SSPND_EN);
1752 if (errCode == 1) { 1676 if (err_code == 1)
1753 usbvision->power = 0; 1677 usbvision->power = 0;
1754 } 1678 PDEBUG(DBG_FUNC, "%s: err_code %d", (err_code != 1) ? "ERROR" : "power is off", err_code);
1755 PDEBUG(DBG_FUNC, "%s: errCode %d", (errCode!=1)?"ERROR":"power is off", errCode); 1679 return err_code;
1756 return errCode;
1757} 1680}
1758 1681
1759/* 1682/*
@@ -1769,7 +1692,7 @@ static int usbvision_set_video_format(struct usb_usbvision *usbvision, int forma
1769 if (!USBVISION_IS_OPERATIONAL(usbvision)) 1692 if (!USBVISION_IS_OPERATIONAL(usbvision))
1770 return 0; 1693 return 0;
1771 1694
1772 PDEBUG(DBG_FUNC, "isocMode %#02x", format); 1695 PDEBUG(DBG_FUNC, "isoc_mode %#02x", format);
1773 1696
1774 if ((format != ISOC_MODE_YUV422) 1697 if ((format != ISOC_MODE_YUV422)
1775 && (format != ISOC_MODE_YUV420) 1698 && (format != ISOC_MODE_YUV420)
@@ -1778,8 +1701,8 @@ static int usbvision_set_video_format(struct usb_usbvision *usbvision, int forma
1778 format); 1701 format);
1779 format = ISOC_MODE_YUV420; 1702 format = ISOC_MODE_YUV420;
1780 } 1703 }
1781 value[0] = 0x0A; //TODO: See the effect of the filter 1704 value[0] = 0x0A; /* TODO: See the effect of the filter */
1782 value[1] = format; // Sets the VO_MODE register which follows FILT_CONT 1705 value[1] = format; /* Sets the VO_MODE register which follows FILT_CONT */
1783 rc = usb_control_msg(usbvision->dev, usb_sndctrlpipe(usbvision->dev, 1), 1706 rc = usb_control_msg(usbvision->dev, usb_sndctrlpipe(usbvision->dev, 1),
1784 USBVISION_OP_CODE, 1707 USBVISION_OP_CODE,
1785 USB_DIR_OUT | USB_TYPE_VENDOR | 1708 USB_DIR_OUT | USB_TYPE_VENDOR |
@@ -1790,7 +1713,7 @@ static int usbvision_set_video_format(struct usb_usbvision *usbvision, int forma
1790 printk(KERN_ERR "%s: ERROR=%d. USBVISION stopped - " 1713 printk(KERN_ERR "%s: ERROR=%d. USBVISION stopped - "
1791 "reconnect or reload driver.\n", proc, rc); 1714 "reconnect or reload driver.\n", proc, rc);
1792 } 1715 }
1793 usbvision->isocMode = format; 1716 usbvision->isoc_mode = format;
1794 return rc; 1717 return rc;
1795} 1718}
1796 1719
@@ -1802,96 +1725,88 @@ static int usbvision_set_video_format(struct usb_usbvision *usbvision, int forma
1802int usbvision_set_output(struct usb_usbvision *usbvision, int width, 1725int usbvision_set_output(struct usb_usbvision *usbvision, int width,
1803 int height) 1726 int height)
1804{ 1727{
1805 int errCode = 0; 1728 int err_code = 0;
1806 int UsbWidth, UsbHeight; 1729 int usb_width, usb_height;
1807 unsigned int frameRate=0, frameDrop=0; 1730 unsigned int frame_rate = 0, frame_drop = 0;
1808 unsigned char value[4]; 1731 unsigned char value[4];
1809 1732
1810 if (!USBVISION_IS_OPERATIONAL(usbvision)) { 1733 if (!USBVISION_IS_OPERATIONAL(usbvision))
1811 return 0; 1734 return 0;
1812 }
1813 1735
1814 if (width > MAX_USB_WIDTH) { 1736 if (width > MAX_USB_WIDTH) {
1815 UsbWidth = width / 2; 1737 usb_width = width / 2;
1816 usbvision->stretch_width = 2; 1738 usbvision->stretch_width = 2;
1817 } 1739 } else {
1818 else { 1740 usb_width = width;
1819 UsbWidth = width;
1820 usbvision->stretch_width = 1; 1741 usbvision->stretch_width = 1;
1821 } 1742 }
1822 1743
1823 if (height > MAX_USB_HEIGHT) { 1744 if (height > MAX_USB_HEIGHT) {
1824 UsbHeight = height / 2; 1745 usb_height = height / 2;
1825 usbvision->stretch_height = 2; 1746 usbvision->stretch_height = 2;
1826 } 1747 } else {
1827 else { 1748 usb_height = height;
1828 UsbHeight = height;
1829 usbvision->stretch_height = 1; 1749 usbvision->stretch_height = 1;
1830 } 1750 }
1831 1751
1832 RESTRICT_TO_RANGE(UsbWidth, MIN_FRAME_WIDTH, MAX_USB_WIDTH); 1752 RESTRICT_TO_RANGE(usb_width, MIN_FRAME_WIDTH, MAX_USB_WIDTH);
1833 UsbWidth &= ~(MIN_FRAME_WIDTH-1); 1753 usb_width &= ~(MIN_FRAME_WIDTH-1);
1834 RESTRICT_TO_RANGE(UsbHeight, MIN_FRAME_HEIGHT, MAX_USB_HEIGHT); 1754 RESTRICT_TO_RANGE(usb_height, MIN_FRAME_HEIGHT, MAX_USB_HEIGHT);
1835 UsbHeight &= ~(1); 1755 usb_height &= ~(1);
1836 1756
1837 PDEBUG(DBG_FUNC, "usb %dx%d; screen %dx%d; stretch %dx%d", 1757 PDEBUG(DBG_FUNC, "usb %dx%d; screen %dx%d; stretch %dx%d",
1838 UsbWidth, UsbHeight, width, height, 1758 usb_width, usb_height, width, height,
1839 usbvision->stretch_width, usbvision->stretch_height); 1759 usbvision->stretch_width, usbvision->stretch_height);
1840 1760
1841 /* I'll not rewrite the same values */ 1761 /* I'll not rewrite the same values */
1842 if ((UsbWidth != usbvision->curwidth) || (UsbHeight != usbvision->curheight)) { 1762 if ((usb_width != usbvision->curwidth) || (usb_height != usbvision->curheight)) {
1843 value[0] = UsbWidth & 0xff; //LSB 1763 value[0] = usb_width & 0xff; /* LSB */
1844 value[1] = (UsbWidth >> 8) & 0x03; //MSB 1764 value[1] = (usb_width >> 8) & 0x03; /* MSB */
1845 value[2] = UsbHeight & 0xff; //LSB 1765 value[2] = usb_height & 0xff; /* LSB */
1846 value[3] = (UsbHeight >> 8) & 0x03; //MSB 1766 value[3] = (usb_height >> 8) & 0x03; /* MSB */
1847 1767
1848 errCode = usb_control_msg(usbvision->dev, usb_sndctrlpipe(usbvision->dev, 1), 1768 err_code = usb_control_msg(usbvision->dev, usb_sndctrlpipe(usbvision->dev, 1),
1849 USBVISION_OP_CODE, 1769 USBVISION_OP_CODE,
1850 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT, 1770 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT,
1851 0, (__u16) USBVISION_LXSIZE_O, value, 4, HZ); 1771 0, (__u16) USBVISION_LXSIZE_O, value, 4, HZ);
1852 1772
1853 if (errCode < 0) { 1773 if (err_code < 0) {
1854 dev_err(&usbvision->dev->dev, 1774 dev_err(&usbvision->dev->dev,
1855 "%s failed: error %d\n", __func__, errCode); 1775 "%s failed: error %d\n", __func__, err_code);
1856 return errCode; 1776 return err_code;
1857 } 1777 }
1858 usbvision->curwidth = usbvision->stretch_width * UsbWidth; 1778 usbvision->curwidth = usbvision->stretch_width * usb_width;
1859 usbvision->curheight = usbvision->stretch_height * UsbHeight; 1779 usbvision->curheight = usbvision->stretch_height * usb_height;
1860 } 1780 }
1861 1781
1862 if (usbvision->isocMode == ISOC_MODE_YUV422) { 1782 if (usbvision->isoc_mode == ISOC_MODE_YUV422)
1863 frameRate = (usbvision->isocPacketSize * 1000) / (UsbWidth * UsbHeight * 2); 1783 frame_rate = (usbvision->isoc_packet_size * 1000) / (usb_width * usb_height * 2);
1864 } 1784 else if (usbvision->isoc_mode == ISOC_MODE_YUV420)
1865 else if (usbvision->isocMode == ISOC_MODE_YUV420) { 1785 frame_rate = (usbvision->isoc_packet_size * 1000) / ((usb_width * usb_height * 12) / 8);
1866 frameRate = (usbvision->isocPacketSize * 1000) / ((UsbWidth * UsbHeight * 12) / 8); 1786 else
1867 } 1787 frame_rate = FRAMERATE_MAX;
1868 else {
1869 frameRate = FRAMERATE_MAX;
1870 }
1871 1788
1872 if (usbvision->tvnormId & V4L2_STD_625_50) { 1789 if (usbvision->tvnorm_id & V4L2_STD_625_50)
1873 frameDrop = frameRate * 32 / 25 - 1; 1790 frame_drop = frame_rate * 32 / 25 - 1;
1874 } 1791 else if (usbvision->tvnorm_id & V4L2_STD_525_60)
1875 else if (usbvision->tvnormId & V4L2_STD_525_60) { 1792 frame_drop = frame_rate * 32 / 30 - 1;
1876 frameDrop = frameRate * 32 / 30 - 1;
1877 }
1878 1793
1879 RESTRICT_TO_RANGE(frameDrop, FRAMERATE_MIN, FRAMERATE_MAX); 1794 RESTRICT_TO_RANGE(frame_drop, FRAMERATE_MIN, FRAMERATE_MAX);
1880 1795
1881 PDEBUG(DBG_FUNC, "frameRate %d fps, frameDrop %d", frameRate, frameDrop); 1796 PDEBUG(DBG_FUNC, "frame_rate %d fps, frame_drop %d", frame_rate, frame_drop);
1882 1797
1883 frameDrop = FRAMERATE_MAX; // We can allow the maximum here, because dropping is controlled 1798 frame_drop = FRAMERATE_MAX; /* We can allow the maximum here, because dropping is controlled */
1884 1799
1885 /* frameDrop = 7; => framePhase = 1, 5, 9, 13, 17, 21, 25, 0, 4, 8, ... 1800 /* frame_drop = 7; => frame_phase = 1, 5, 9, 13, 17, 21, 25, 0, 4, 8, ...
1886 => frameSkip = 4; 1801 => frame_skip = 4;
1887 => frameRate = (7 + 1) * 25 / 32 = 200 / 32 = 6.25; 1802 => frame_rate = (7 + 1) * 25 / 32 = 200 / 32 = 6.25;
1888 1803
1889 frameDrop = 9; => framePhase = 1, 5, 8, 11, 14, 17, 21, 24, 27, 1, 4, 8, ... 1804 frame_drop = 9; => frame_phase = 1, 5, 8, 11, 14, 17, 21, 24, 27, 1, 4, 8, ...
1890 => frameSkip = 4, 3, 3, 3, 3, 4, 3, 3, 3, 3, 4, ... 1805 => frame_skip = 4, 3, 3, 3, 3, 4, 3, 3, 3, 3, 4, ...
1891 => frameRate = (9 + 1) * 25 / 32 = 250 / 32 = 7.8125; 1806 => frame_rate = (9 + 1) * 25 / 32 = 250 / 32 = 7.8125;
1892 */ 1807 */
1893 errCode = usbvision_write_reg(usbvision, USBVISION_FRM_RATE, frameDrop); 1808 err_code = usbvision_write_reg(usbvision, USBVISION_FRM_RATE, frame_drop);
1894 return errCode; 1809 return err_code;
1895} 1810}
1896 1811
1897 1812
@@ -1903,8 +1818,8 @@ int usbvision_frames_alloc(struct usb_usbvision *usbvision, int number_of_frames
1903{ 1818{
1904 int i; 1819 int i;
1905 1820
1906 /*needs to be page aligned cause the buffers can be mapped individually! */ 1821 /* needs to be page aligned cause the buffers can be mapped individually! */
1907 usbvision->max_frame_size = PAGE_ALIGN(usbvision->curwidth * 1822 usbvision->max_frame_size = PAGE_ALIGN(usbvision->curwidth *
1908 usbvision->curheight * 1823 usbvision->curheight *
1909 usbvision->palette.bytes_per_pixel); 1824 usbvision->palette.bytes_per_pixel);
1910 1825
@@ -1912,9 +1827,9 @@ int usbvision_frames_alloc(struct usb_usbvision *usbvision, int number_of_frames
1912 usbvision->num_frames = number_of_frames; 1827 usbvision->num_frames = number_of_frames;
1913 while (usbvision->num_frames > 0) { 1828 while (usbvision->num_frames > 0) {
1914 usbvision->fbuf_size = usbvision->num_frames * usbvision->max_frame_size; 1829 usbvision->fbuf_size = usbvision->num_frames * usbvision->max_frame_size;
1915 if((usbvision->fbuf = usbvision_rvmalloc(usbvision->fbuf_size))) { 1830 usbvision->fbuf = usbvision_rvmalloc(usbvision->fbuf_size);
1831 if (usbvision->fbuf)
1916 break; 1832 break;
1917 }
1918 usbvision->num_frames--; 1833 usbvision->num_frames--;
1919 } 1834 }
1920 1835
@@ -1925,7 +1840,7 @@ int usbvision_frames_alloc(struct usb_usbvision *usbvision, int number_of_frames
1925 /* Allocate all buffers */ 1840 /* Allocate all buffers */
1926 for (i = 0; i < usbvision->num_frames; i++) { 1841 for (i = 0; i < usbvision->num_frames; i++) {
1927 usbvision->frame[i].index = i; 1842 usbvision->frame[i].index = i;
1928 usbvision->frame[i].grabstate = FrameState_Unused; 1843 usbvision->frame[i].grabstate = frame_state_unused;
1929 usbvision->frame[i].data = usbvision->fbuf + 1844 usbvision->frame[i].data = usbvision->fbuf +
1930 i * usbvision->max_frame_size; 1845 i * usbvision->max_frame_size;
1931 /* 1846 /*
@@ -1937,7 +1852,8 @@ int usbvision_frames_alloc(struct usb_usbvision *usbvision, int number_of_frames
1937 usbvision->frame[i].height = usbvision->curheight; 1852 usbvision->frame[i].height = usbvision->curheight;
1938 usbvision->frame[i].bytes_read = 0; 1853 usbvision->frame[i].bytes_read = 0;
1939 } 1854 }
1940 PDEBUG(DBG_FUNC, "allocated %d frames (%d bytes per frame)",usbvision->num_frames,usbvision->max_frame_size); 1855 PDEBUG(DBG_FUNC, "allocated %d frames (%d bytes per frame)",
1856 usbvision->num_frames, usbvision->max_frame_size);
1941 return usbvision->num_frames; 1857 return usbvision->num_frames;
1942} 1858}
1943 1859
@@ -1948,7 +1864,7 @@ int usbvision_frames_alloc(struct usb_usbvision *usbvision, int number_of_frames
1948void usbvision_frames_free(struct usb_usbvision *usbvision) 1864void usbvision_frames_free(struct usb_usbvision *usbvision)
1949{ 1865{
1950 /* Have to free all that memory */ 1866 /* Have to free all that memory */
1951 PDEBUG(DBG_FUNC, "free %d frames",usbvision->num_frames); 1867 PDEBUG(DBG_FUNC, "free %d frames", usbvision->num_frames);
1952 1868
1953 if (usbvision->fbuf != NULL) { 1869 if (usbvision->fbuf != NULL) {
1954 usbvision_rvfree(usbvision->fbuf, usbvision->fbuf_size); 1870 usbvision_rvfree(usbvision->fbuf, usbvision->fbuf_size);
@@ -1969,7 +1885,7 @@ void usbvision_empty_framequeues(struct usb_usbvision *usbvision)
1969 INIT_LIST_HEAD(&(usbvision->outqueue)); 1885 INIT_LIST_HEAD(&(usbvision->outqueue));
1970 1886
1971 for (i = 0; i < USBVISION_NUMFRAMES; i++) { 1887 for (i = 0; i < USBVISION_NUMFRAMES; i++) {
1972 usbvision->frame[i].grabstate = FrameState_Unused; 1888 usbvision->frame[i].grabstate = frame_state_unused;
1973 usbvision->frame[i].bytes_read = 0; 1889 usbvision->frame[i].bytes_read = 0;
1974 } 1890 }
1975} 1891}
@@ -1984,9 +1900,9 @@ int usbvision_stream_interrupt(struct usb_usbvision *usbvision)
1984 1900
1985 /* stop reading from the device */ 1901 /* stop reading from the device */
1986 1902
1987 usbvision->streaming = Stream_Interrupt; 1903 usbvision->streaming = stream_interrupt;
1988 ret = wait_event_timeout(usbvision->wait_stream, 1904 ret = wait_event_timeout(usbvision->wait_stream,
1989 (usbvision->streaming == Stream_Idle), 1905 (usbvision->streaming == stream_idle),
1990 msecs_to_jiffies(USBVISION_NUMSBUF*USBVISION_URB_FRAMES)); 1906 msecs_to_jiffies(USBVISION_NUMSBUF*USBVISION_URB_FRAMES));
1991 return ret; 1907 return ret;
1992} 1908}
@@ -2002,19 +1918,19 @@ static int usbvision_set_compress_params(struct usb_usbvision *usbvision)
2002 int rc; 1918 int rc;
2003 unsigned char value[6]; 1919 unsigned char value[6];
2004 1920
2005 value[0] = 0x0F; // Intra-Compression cycle 1921 value[0] = 0x0F; /* Intra-Compression cycle */
2006 value[1] = 0x01; // Reg.45 one line per strip 1922 value[1] = 0x01; /* Reg.45 one line per strip */
2007 value[2] = 0x00; // Reg.46 Force intra mode on all new frames 1923 value[2] = 0x00; /* Reg.46 Force intra mode on all new frames */
2008 value[3] = 0x00; // Reg.47 FORCE_UP <- 0 normal operation (not force) 1924 value[3] = 0x00; /* Reg.47 FORCE_UP <- 0 normal operation (not force) */
2009 value[4] = 0xA2; // Reg.48 BUF_THR I'm not sure if this does something in not compressed mode. 1925 value[4] = 0xA2; /* Reg.48 BUF_THR I'm not sure if this does something in not compressed mode. */
2010 value[5] = 0x00; // Reg.49 DVI_YUV This has nothing to do with compression 1926 value[5] = 0x00; /* Reg.49 DVI_YUV This has nothing to do with compression */
2011 1927
2012 //catched values for NT1004 1928 /* catched values for NT1004 */
2013 // value[0] = 0xFF; // Never apply intra mode automatically 1929 /* value[0] = 0xFF; Never apply intra mode automatically */
2014 // value[1] = 0xF1; // Use full frame height for virtual strip width; One line per strip 1930 /* value[1] = 0xF1; Use full frame height for virtual strip width; One line per strip */
2015 // value[2] = 0x01; // Force intra mode on all new frames 1931 /* value[2] = 0x01; Force intra mode on all new frames */
2016 // value[3] = 0x00; // Strip size 400 Bytes; do not force up 1932 /* value[3] = 0x00; Strip size 400 Bytes; do not force up */
2017 // value[4] = 0xA2; // 1933 /* value[4] = 0xA2; */
2018 if (!USBVISION_IS_OPERATIONAL(usbvision)) 1934 if (!USBVISION_IS_OPERATIONAL(usbvision))
2019 return 0; 1935 return 0;
2020 1936
@@ -2030,21 +1946,20 @@ static int usbvision_set_compress_params(struct usb_usbvision *usbvision)
2030 return rc; 1946 return rc;
2031 } 1947 }
2032 1948
2033 if (usbvision->bridgeType == BRIDGE_NT1004) { 1949 if (usbvision->bridge_type == BRIDGE_NT1004) {
2034 value[0] = 20; // PCM Threshold 1 1950 value[0] = 20; /* PCM Threshold 1 */
2035 value[1] = 12; // PCM Threshold 2 1951 value[1] = 12; /* PCM Threshold 2 */
2036 value[2] = 255; // Distorsion Threshold inter 1952 value[2] = 255; /* Distortion Threshold inter */
2037 value[3] = 255; // Distorsion Threshold intra 1953 value[3] = 255; /* Distortion Threshold intra */
2038 value[4] = 43; // Max Distorsion inter 1954 value[4] = 43; /* Max Distortion inter */
2039 value[5] = 43; // Max Distorsion intra 1955 value[5] = 43; /* Max Distortion intra */
2040 } 1956 } else {
2041 else { 1957 value[0] = 20; /* PCM Threshold 1 */
2042 value[0] = 20; // PCM Threshold 1 1958 value[1] = 12; /* PCM Threshold 2 */
2043 value[1] = 12; // PCM Threshold 2 1959 value[2] = 255; /* Distortion Threshold d7-d0 */
2044 value[2] = 255; // Distorsion Threshold d7-d0 1960 value[3] = 0; /* Distortion Threshold d11-d8 */
2045 value[3] = 0; // Distorsion Threshold d11-d8 1961 value[4] = 43; /* Max Distortion d7-d0 */
2046 value[4] = 43; // Max Distorsion d7-d0 1962 value[5] = 0; /* Max Distortion d8 */
2047 value[5] = 0; // Max Distorsion d8
2048 } 1963 }
2049 1964
2050 if (!USBVISION_IS_OPERATIONAL(usbvision)) 1965 if (!USBVISION_IS_OPERATIONAL(usbvision))
@@ -2059,10 +1974,7 @@ static int usbvision_set_compress_params(struct usb_usbvision *usbvision)
2059 if (rc < 0) { 1974 if (rc < 0) {
2060 printk(KERN_ERR "%sERROR=%d. USBVISION stopped - " 1975 printk(KERN_ERR "%sERROR=%d. USBVISION stopped - "
2061 "reconnect or reload driver.\n", proc, rc); 1976 "reconnect or reload driver.\n", proc, rc);
2062 return rc;
2063 } 1977 }
2064
2065
2066 return rc; 1978 return rc;
2067} 1979}
2068 1980
@@ -2085,9 +1997,9 @@ int usbvision_set_input(struct usb_usbvision *usbvision)
2085 return 0; 1997 return 0;
2086 1998
2087 /* Set input format expected from decoder*/ 1999 /* Set input format expected from decoder*/
2088 if (usbvision_device_data[usbvision->DevModel].Vin_Reg1_override) { 2000 if (usbvision_device_data[usbvision->dev_model].vin_reg1_override) {
2089 value[0] = usbvision_device_data[usbvision->DevModel].Vin_Reg1; 2001 value[0] = usbvision_device_data[usbvision->dev_model].vin_reg1;
2090 } else if(usbvision_device_data[usbvision->DevModel].Codec == CODEC_SAA7113) { 2002 } else if (usbvision_device_data[usbvision->dev_model].codec == CODEC_SAA7113) {
2091 /* SAA7113 uses 8 bit output */ 2003 /* SAA7113 uses 8 bit output */
2092 value[0] = USBVISION_8_422_SYNC; 2004 value[0] = USBVISION_8_422_SYNC;
2093 } else { 2005 } else {
@@ -2105,53 +2017,53 @@ int usbvision_set_input(struct usb_usbvision *usbvision)
2105 } 2017 }
2106 2018
2107 2019
2108 if (usbvision->tvnormId & V4L2_STD_PAL) { 2020 if (usbvision->tvnorm_id & V4L2_STD_PAL) {
2109 value[0] = 0xC0; 2021 value[0] = 0xC0;
2110 value[1] = 0x02; //0x02C0 -> 704 Input video line length 2022 value[1] = 0x02; /* 0x02C0 -> 704 Input video line length */
2111 value[2] = 0x20; 2023 value[2] = 0x20;
2112 value[3] = 0x01; //0x0120 -> 288 Input video n. of lines 2024 value[3] = 0x01; /* 0x0120 -> 288 Input video n. of lines */
2113 value[4] = 0x60; 2025 value[4] = 0x60;
2114 value[5] = 0x00; //0x0060 -> 96 Input video h offset 2026 value[5] = 0x00; /* 0x0060 -> 96 Input video h offset */
2115 value[6] = 0x16; 2027 value[6] = 0x16;
2116 value[7] = 0x00; //0x0016 -> 22 Input video v offset 2028 value[7] = 0x00; /* 0x0016 -> 22 Input video v offset */
2117 } else if (usbvision->tvnormId & V4L2_STD_SECAM) { 2029 } else if (usbvision->tvnorm_id & V4L2_STD_SECAM) {
2118 value[0] = 0xC0; 2030 value[0] = 0xC0;
2119 value[1] = 0x02; //0x02C0 -> 704 Input video line length 2031 value[1] = 0x02; /* 0x02C0 -> 704 Input video line length */
2120 value[2] = 0x20; 2032 value[2] = 0x20;
2121 value[3] = 0x01; //0x0120 -> 288 Input video n. of lines 2033 value[3] = 0x01; /* 0x0120 -> 288 Input video n. of lines */
2122 value[4] = 0x01; 2034 value[4] = 0x01;
2123 value[5] = 0x00; //0x0001 -> 01 Input video h offset 2035 value[5] = 0x00; /* 0x0001 -> 01 Input video h offset */
2124 value[6] = 0x01; 2036 value[6] = 0x01;
2125 value[7] = 0x00; //0x0001 -> 01 Input video v offset 2037 value[7] = 0x00; /* 0x0001 -> 01 Input video v offset */
2126 } else { /* V4L2_STD_NTSC */ 2038 } else { /* V4L2_STD_NTSC */
2127 value[0] = 0xD0; 2039 value[0] = 0xD0;
2128 value[1] = 0x02; //0x02D0 -> 720 Input video line length 2040 value[1] = 0x02; /* 0x02D0 -> 720 Input video line length */
2129 value[2] = 0xF0; 2041 value[2] = 0xF0;
2130 value[3] = 0x00; //0x00F0 -> 240 Input video number of lines 2042 value[3] = 0x00; /* 0x00F0 -> 240 Input video number of lines */
2131 value[4] = 0x50; 2043 value[4] = 0x50;
2132 value[5] = 0x00; //0x0050 -> 80 Input video h offset 2044 value[5] = 0x00; /* 0x0050 -> 80 Input video h offset */
2133 value[6] = 0x10; 2045 value[6] = 0x10;
2134 value[7] = 0x00; //0x0010 -> 16 Input video v offset 2046 value[7] = 0x00; /* 0x0010 -> 16 Input video v offset */
2135 } 2047 }
2136 2048
2137 if (usbvision_device_data[usbvision->DevModel].X_Offset >= 0) { 2049 if (usbvision_device_data[usbvision->dev_model].x_offset >= 0) {
2138 value[4]=usbvision_device_data[usbvision->DevModel].X_Offset & 0xff; 2050 value[4] = usbvision_device_data[usbvision->dev_model].x_offset & 0xff;
2139 value[5]=(usbvision_device_data[usbvision->DevModel].X_Offset & 0x0300) >> 8; 2051 value[5] = (usbvision_device_data[usbvision->dev_model].x_offset & 0x0300) >> 8;
2140 } 2052 }
2141 2053
2142 if (adjust_X_Offset != -1) { 2054 if (adjust_x_offset != -1) {
2143 value[4] = adjust_X_Offset & 0xff; 2055 value[4] = adjust_x_offset & 0xff;
2144 value[5] = (adjust_X_Offset & 0x0300) >> 8; 2056 value[5] = (adjust_x_offset & 0x0300) >> 8;
2145 } 2057 }
2146 2058
2147 if (usbvision_device_data[usbvision->DevModel].Y_Offset >= 0) { 2059 if (usbvision_device_data[usbvision->dev_model].y_offset >= 0) {
2148 value[6]=usbvision_device_data[usbvision->DevModel].Y_Offset & 0xff; 2060 value[6] = usbvision_device_data[usbvision->dev_model].y_offset & 0xff;
2149 value[7]=(usbvision_device_data[usbvision->DevModel].Y_Offset & 0x0300) >> 8; 2061 value[7] = (usbvision_device_data[usbvision->dev_model].y_offset & 0x0300) >> 8;
2150 } 2062 }
2151 2063
2152 if (adjust_Y_Offset != -1) { 2064 if (adjust_y_offset != -1) {
2153 value[6] = adjust_Y_Offset & 0xff; 2065 value[6] = adjust_y_offset & 0xff;
2154 value[7] = (adjust_Y_Offset & 0x0300) >> 8; 2066 value[7] = (adjust_y_offset & 0x0300) >> 8;
2155 } 2067 }
2156 2068
2157 rc = usb_control_msg(usbvision->dev, usb_sndctrlpipe(usbvision->dev, 1), 2069 rc = usb_control_msg(usbvision->dev, usb_sndctrlpipe(usbvision->dev, 1),
@@ -2167,15 +2079,14 @@ int usbvision_set_input(struct usb_usbvision *usbvision)
2167 2079
2168 dvi_yuv_value = 0x00; /* U comes after V, Ya comes after U/V, Yb comes after Yb */ 2080 dvi_yuv_value = 0x00; /* U comes after V, Ya comes after U/V, Yb comes after Yb */
2169 2081
2170 if(usbvision_device_data[usbvision->DevModel].Dvi_yuv_override){ 2082 if (usbvision_device_data[usbvision->dev_model].dvi_yuv_override) {
2171 dvi_yuv_value = usbvision_device_data[usbvision->DevModel].Dvi_yuv; 2083 dvi_yuv_value = usbvision_device_data[usbvision->dev_model].dvi_yuv;
2172 } 2084 } else if (usbvision_device_data[usbvision->dev_model].codec == CODEC_SAA7113) {
2173 else if(usbvision_device_data[usbvision->DevModel].Codec == CODEC_SAA7113) { 2085 /* This changes as the fine sync control changes. Further investigation necessary */
2174 /* This changes as the fine sync control changes. Further investigation necessary */
2175 dvi_yuv_value = 0x06; 2086 dvi_yuv_value = 0x06;
2176 } 2087 }
2177 2088
2178 return (usbvision_write_reg(usbvision, USBVISION_DVI_YUV, dvi_yuv_value)); 2089 return usbvision_write_reg(usbvision, USBVISION_DVI_YUV, dvi_yuv_value);
2179} 2090}
2180 2091
2181 2092
@@ -2192,7 +2103,7 @@ static int usbvision_set_dram_settings(struct usb_usbvision *usbvision)
2192 int rc; 2103 int rc;
2193 unsigned char value[8]; 2104 unsigned char value[8];
2194 2105
2195 if (usbvision->isocMode == ISOC_MODE_COMPRESS) { 2106 if (usbvision->isoc_mode == ISOC_MODE_COMPRESS) {
2196 value[0] = 0x42; 2107 value[0] = 0x42;
2197 value[1] = 0x71; 2108 value[1] = 0x71;
2198 value[2] = 0xff; 2109 value[2] = 0xff;
@@ -2201,11 +2112,10 @@ static int usbvision_set_dram_settings(struct usb_usbvision *usbvision)
2201 value[5] = 0xe0; 2112 value[5] = 0xe0;
2202 value[6] = 0x71; 2113 value[6] = 0x71;
2203 value[7] = 0xff; 2114 value[7] = 0xff;
2204 // UR: 0x0E200-0x3FFFF = 204288 Words (1 Word = 2 Byte) 2115 /* UR: 0x0E200-0x3FFFF = 204288 Words (1 Word = 2 Byte) */
2205 // FDL: 0x00000-0x0E099 = 57498 Words 2116 /* FDL: 0x00000-0x0E099 = 57498 Words */
2206 // VDW: 0x0E3FF-0x3FFFF 2117 /* VDW: 0x0E3FF-0x3FFFF */
2207 } 2118 } else {
2208 else {
2209 value[0] = 0x42; 2119 value[0] = 0x42;
2210 value[1] = 0x00; 2120 value[1] = 0x00;
2211 value[2] = 0xff; 2121 value[2] = 0xff;
@@ -2218,14 +2128,14 @@ static int usbvision_set_dram_settings(struct usb_usbvision *usbvision)
2218 /* These are the values of the address of the video buffer, 2128 /* These are the values of the address of the video buffer,
2219 * they have to be loaded into the USBVISION_DRM_PRM1-8 2129 * they have to be loaded into the USBVISION_DRM_PRM1-8
2220 * 2130 *
2221 * Start address of video output buffer for read: drm_prm1-2 -> 0x00000 2131 * Start address of video output buffer for read: drm_prm1-2 -> 0x00000
2222 * End address of video output buffer for read: drm_prm1-3 -> 0x1ffff 2132 * End address of video output buffer for read: drm_prm1-3 -> 0x1ffff
2223 * Start address of video frame delay buffer: drm_prm1-4 -> 0x20000 2133 * Start address of video frame delay buffer: drm_prm1-4 -> 0x20000
2224 * Only used in compressed mode 2134 * Only used in compressed mode
2225 * End address of video frame delay buffer: drm_prm1-5-6 -> 0x3ffff 2135 * End address of video frame delay buffer: drm_prm1-5-6 -> 0x3ffff
2226 * Only used in compressed mode 2136 * Only used in compressed mode
2227 * Start address of video output buffer for write: drm_prm1-7 -> 0x00000 2137 * Start address of video output buffer for write: drm_prm1-7 -> 0x00000
2228 * End address of video output buffer for write: drm_prm1-8 -> 0x1ffff 2138 * End address of video output buffer for write: drm_prm1-8 -> 0x1ffff
2229 */ 2139 */
2230 2140
2231 if (!USBVISION_IS_OPERATIONAL(usbvision)) 2141 if (!USBVISION_IS_OPERATIONAL(usbvision))
@@ -2243,8 +2153,9 @@ static int usbvision_set_dram_settings(struct usb_usbvision *usbvision)
2243 } 2153 }
2244 2154
2245 /* Restart the video buffer logic */ 2155 /* Restart the video buffer logic */
2246 if ((rc = usbvision_write_reg(usbvision, USBVISION_DRM_CONT, USBVISION_RES_UR | 2156 rc = usbvision_write_reg(usbvision, USBVISION_DRM_CONT, USBVISION_RES_UR |
2247 USBVISION_RES_FDL | USBVISION_RES_VDW)) < 0) 2157 USBVISION_RES_FDL | USBVISION_RES_VDW);
2158 if (rc < 0)
2248 return rc; 2159 return rc;
2249 rc = usbvision_write_reg(usbvision, USBVISION_DRM_CONT, 0x00); 2160 rc = usbvision_write_reg(usbvision, USBVISION_DRM_CONT, 0x00);
2250 2161
@@ -2261,23 +2172,22 @@ static int usbvision_set_dram_settings(struct usb_usbvision *usbvision)
2261 2172
2262int usbvision_power_on(struct usb_usbvision *usbvision) 2173int usbvision_power_on(struct usb_usbvision *usbvision)
2263{ 2174{
2264 int errCode = 0; 2175 int err_code = 0;
2265 2176
2266 PDEBUG(DBG_FUNC, ""); 2177 PDEBUG(DBG_FUNC, "");
2267 2178
2268 usbvision_write_reg(usbvision, USBVISION_PWR_REG, USBVISION_SSPND_EN); 2179 usbvision_write_reg(usbvision, USBVISION_PWR_REG, USBVISION_SSPND_EN);
2269 usbvision_write_reg(usbvision, USBVISION_PWR_REG, 2180 usbvision_write_reg(usbvision, USBVISION_PWR_REG,
2270 USBVISION_SSPND_EN | USBVISION_RES2); 2181 USBVISION_SSPND_EN | USBVISION_RES2);
2271 2182
2272 usbvision_write_reg(usbvision, USBVISION_PWR_REG, 2183 usbvision_write_reg(usbvision, USBVISION_PWR_REG,
2273 USBVISION_SSPND_EN | USBVISION_PWR_VID); 2184 USBVISION_SSPND_EN | USBVISION_PWR_VID);
2274 errCode = usbvision_write_reg(usbvision, USBVISION_PWR_REG, 2185 err_code = usbvision_write_reg(usbvision, USBVISION_PWR_REG,
2275 USBVISION_SSPND_EN | USBVISION_PWR_VID | USBVISION_RES2); 2186 USBVISION_SSPND_EN | USBVISION_PWR_VID | USBVISION_RES2);
2276 if (errCode == 1) { 2187 if (err_code == 1)
2277 usbvision->power = 1; 2188 usbvision->power = 1;
2278 } 2189 PDEBUG(DBG_FUNC, "%s: err_code %d", (err_code < 0) ? "ERROR" : "power is on", err_code);
2279 PDEBUG(DBG_FUNC, "%s: errCode %d", (errCode<0)?"ERROR":"power is on", errCode); 2190 return err_code;
2280 return errCode;
2281} 2191}
2282 2192
2283 2193
@@ -2285,53 +2195,50 @@ int usbvision_power_on(struct usb_usbvision *usbvision)
2285 * usbvision timer stuff 2195 * usbvision timer stuff
2286 */ 2196 */
2287 2197
2288// to call usbvision_power_off from task queue 2198/* to call usbvision_power_off from task queue */
2289static void call_usbvision_power_off(struct work_struct *work) 2199static void call_usbvision_power_off(struct work_struct *work)
2290{ 2200{
2291 struct usb_usbvision *usbvision = container_of(work, struct usb_usbvision, powerOffWork); 2201 struct usb_usbvision *usbvision = container_of(work, struct usb_usbvision, power_off_work);
2292 2202
2293 PDEBUG(DBG_FUNC, ""); 2203 PDEBUG(DBG_FUNC, "");
2294 if(mutex_lock_interruptible(&usbvision->lock)) { 2204 if (mutex_lock_interruptible(&usbvision->v4l2_lock))
2295 return; 2205 return;
2296 }
2297 2206
2298 2207 if (usbvision->user == 0) {
2299 if(usbvision->user == 0) {
2300 usbvision_i2c_unregister(usbvision); 2208 usbvision_i2c_unregister(usbvision);
2301 2209
2302 usbvision_power_off(usbvision); 2210 usbvision_power_off(usbvision);
2303 usbvision->initialized = 0; 2211 usbvision->initialized = 0;
2304 } 2212 }
2305 mutex_unlock(&usbvision->lock); 2213 mutex_unlock(&usbvision->v4l2_lock);
2306} 2214}
2307 2215
2308static void usbvision_powerOffTimer(unsigned long data) 2216static void usbvision_power_off_timer(unsigned long data)
2309{ 2217{
2310 struct usb_usbvision *usbvision = (void *) data; 2218 struct usb_usbvision *usbvision = (void *)data;
2311 2219
2312 PDEBUG(DBG_FUNC, ""); 2220 PDEBUG(DBG_FUNC, "");
2313 del_timer(&usbvision->powerOffTimer); 2221 del_timer(&usbvision->power_off_timer);
2314 INIT_WORK(&usbvision->powerOffWork, call_usbvision_power_off); 2222 INIT_WORK(&usbvision->power_off_work, call_usbvision_power_off);
2315 (void) schedule_work(&usbvision->powerOffWork); 2223 (void) schedule_work(&usbvision->power_off_work);
2316} 2224}
2317 2225
2318void usbvision_init_powerOffTimer(struct usb_usbvision *usbvision) 2226void usbvision_init_power_off_timer(struct usb_usbvision *usbvision)
2319{ 2227{
2320 init_timer(&usbvision->powerOffTimer); 2228 init_timer(&usbvision->power_off_timer);
2321 usbvision->powerOffTimer.data = (long) usbvision; 2229 usbvision->power_off_timer.data = (long)usbvision;
2322 usbvision->powerOffTimer.function = usbvision_powerOffTimer; 2230 usbvision->power_off_timer.function = usbvision_power_off_timer;
2323} 2231}
2324 2232
2325void usbvision_set_powerOffTimer(struct usb_usbvision *usbvision) 2233void usbvision_set_power_off_timer(struct usb_usbvision *usbvision)
2326{ 2234{
2327 mod_timer(&usbvision->powerOffTimer, jiffies + USBVISION_POWEROFF_TIME); 2235 mod_timer(&usbvision->power_off_timer, jiffies + USBVISION_POWEROFF_TIME);
2328} 2236}
2329 2237
2330void usbvision_reset_powerOffTimer(struct usb_usbvision *usbvision) 2238void usbvision_reset_power_off_timer(struct usb_usbvision *usbvision)
2331{ 2239{
2332 if (timer_pending(&usbvision->powerOffTimer)) { 2240 if (timer_pending(&usbvision->power_off_timer))
2333 del_timer(&usbvision->powerOffTimer); 2241 del_timer(&usbvision->power_off_timer);
2334 }
2335} 2242}
2336 2243
2337/* 2244/*
@@ -2341,14 +2248,10 @@ void usbvision_reset_powerOffTimer(struct usb_usbvision *usbvision)
2341 */ 2248 */
2342int usbvision_begin_streaming(struct usb_usbvision *usbvision) 2249int usbvision_begin_streaming(struct usb_usbvision *usbvision)
2343{ 2250{
2344 int errCode = 0; 2251 if (usbvision->isoc_mode == ISOC_MODE_COMPRESS)
2345
2346 if (usbvision->isocMode == ISOC_MODE_COMPRESS) {
2347 usbvision_init_compression(usbvision); 2252 usbvision_init_compression(usbvision);
2348 } 2253 return usbvision_write_reg(usbvision, USBVISION_VIN_REG2,
2349 errCode = usbvision_write_reg(usbvision, USBVISION_VIN_REG2, USBVISION_NOHVALID | 2254 USBVISION_NOHVALID | usbvision->vin_reg2_preset);
2350 usbvision->Vin_Reg2_Preset);
2351 return errCode;
2352} 2255}
2353 2256
2354/* 2257/*
@@ -2360,25 +2263,24 @@ int usbvision_restart_isoc(struct usb_usbvision *usbvision)
2360{ 2263{
2361 int ret; 2264 int ret;
2362 2265
2363 if ( 2266 ret = usbvision_write_reg(usbvision, USBVISION_PWR_REG,
2364 (ret = 2267 USBVISION_SSPND_EN | USBVISION_PWR_VID);
2365 usbvision_write_reg(usbvision, USBVISION_PWR_REG, 2268 if (ret < 0)
2366 USBVISION_SSPND_EN | USBVISION_PWR_VID)) < 0)
2367 return ret; 2269 return ret;
2368 if ( 2270 ret = usbvision_write_reg(usbvision, USBVISION_PWR_REG,
2369 (ret =
2370 usbvision_write_reg(usbvision, USBVISION_PWR_REG,
2371 USBVISION_SSPND_EN | USBVISION_PWR_VID | 2271 USBVISION_SSPND_EN | USBVISION_PWR_VID |
2372 USBVISION_RES2)) < 0) 2272 USBVISION_RES2);
2273 if (ret < 0)
2373 return ret; 2274 return ret;
2374 if ( 2275 ret = usbvision_write_reg(usbvision, USBVISION_VIN_REG2,
2375 (ret =
2376 usbvision_write_reg(usbvision, USBVISION_VIN_REG2,
2377 USBVISION_KEEP_BLANK | USBVISION_NOHVALID | 2276 USBVISION_KEEP_BLANK | USBVISION_NOHVALID |
2378 usbvision->Vin_Reg2_Preset)) < 0) return ret; 2277 usbvision->vin_reg2_preset);
2278 if (ret < 0)
2279 return ret;
2379 2280
2380 /* TODO: schedule timeout */ 2281 /* TODO: schedule timeout */
2381 while ((usbvision_read_reg(usbvision, USBVISION_STATUS_REG) & 0x01) != 1); 2282 while ((usbvision_read_reg(usbvision, USBVISION_STATUS_REG) & 0x01) != 1)
2283 ;
2382 2284
2383 return 0; 2285 return 0;
2384} 2286}
@@ -2386,27 +2288,27 @@ int usbvision_restart_isoc(struct usb_usbvision *usbvision)
2386int usbvision_audio_off(struct usb_usbvision *usbvision) 2288int usbvision_audio_off(struct usb_usbvision *usbvision)
2387{ 2289{
2388 if (usbvision_write_reg(usbvision, USBVISION_IOPIN_REG, USBVISION_AUDIO_MUTE) < 0) { 2290 if (usbvision_write_reg(usbvision, USBVISION_IOPIN_REG, USBVISION_AUDIO_MUTE) < 0) {
2389 printk(KERN_ERR "usbvision_audio_off: can't wirte reg\n"); 2291 printk(KERN_ERR "usbvision_audio_off: can't write reg\n");
2390 return -1; 2292 return -1;
2391 } 2293 }
2392 usbvision->AudioMute = 0; 2294 usbvision->audio_mute = 0;
2393 usbvision->AudioChannel = USBVISION_AUDIO_MUTE; 2295 usbvision->audio_channel = USBVISION_AUDIO_MUTE;
2394 return 0; 2296 return 0;
2395} 2297}
2396 2298
2397int usbvision_set_audio(struct usb_usbvision *usbvision, int AudioChannel) 2299int usbvision_set_audio(struct usb_usbvision *usbvision, int audio_channel)
2398{ 2300{
2399 if (!usbvision->AudioMute) { 2301 if (!usbvision->audio_mute) {
2400 if (usbvision_write_reg(usbvision, USBVISION_IOPIN_REG, AudioChannel) < 0) { 2302 if (usbvision_write_reg(usbvision, USBVISION_IOPIN_REG, audio_channel) < 0) {
2401 printk(KERN_ERR "usbvision_set_audio: can't write iopin register for audio switching\n"); 2303 printk(KERN_ERR "usbvision_set_audio: can't write iopin register for audio switching\n");
2402 return -1; 2304 return -1;
2403 } 2305 }
2404 } 2306 }
2405 usbvision->AudioChannel = AudioChannel; 2307 usbvision->audio_channel = audio_channel;
2406 return 0; 2308 return 0;
2407} 2309}
2408 2310
2409int usbvision_setup(struct usb_usbvision *usbvision,int format) 2311int usbvision_setup(struct usb_usbvision *usbvision, int format)
2410{ 2312{
2411 usbvision_set_video_format(usbvision, format); 2313 usbvision_set_video_format(usbvision, format);
2412 usbvision_set_dram_settings(usbvision); 2314 usbvision_set_dram_settings(usbvision);
@@ -2421,27 +2323,28 @@ int usbvision_setup(struct usb_usbvision *usbvision,int format)
2421 2323
2422int usbvision_set_alternate(struct usb_usbvision *dev) 2324int usbvision_set_alternate(struct usb_usbvision *dev)
2423{ 2325{
2424 int errCode, prev_alt = dev->ifaceAlt; 2326 int err_code, prev_alt = dev->iface_alt;
2425 int i; 2327 int i;
2426 2328
2427 dev->ifaceAlt=0; 2329 dev->iface_alt = 0;
2428 for(i=0;i< dev->num_alt; i++) 2330 for (i = 0; i < dev->num_alt; i++)
2429 if(dev->alt_max_pkt_size[i]>dev->alt_max_pkt_size[dev->ifaceAlt]) 2331 if (dev->alt_max_pkt_size[i] > dev->alt_max_pkt_size[dev->iface_alt])
2430 dev->ifaceAlt=i; 2332 dev->iface_alt = i;
2431 2333
2432 if (dev->ifaceAlt != prev_alt) { 2334 if (dev->iface_alt != prev_alt) {
2433 dev->isocPacketSize = dev->alt_max_pkt_size[dev->ifaceAlt]; 2335 dev->isoc_packet_size = dev->alt_max_pkt_size[dev->iface_alt];
2434 PDEBUG(DBG_FUNC,"setting alternate %d with wMaxPacketSize=%u", dev->ifaceAlt,dev->isocPacketSize); 2336 PDEBUG(DBG_FUNC, "setting alternate %d with max_packet_size=%u",
2435 errCode = usb_set_interface(dev->dev, dev->iface, dev->ifaceAlt); 2337 dev->iface_alt, dev->isoc_packet_size);
2436 if (errCode < 0) { 2338 err_code = usb_set_interface(dev->dev, dev->iface, dev->iface_alt);
2339 if (err_code < 0) {
2437 dev_err(&dev->dev->dev, 2340 dev_err(&dev->dev->dev,
2438 "cannot change alternate number to %d (error=%i)\n", 2341 "cannot change alternate number to %d (error=%i)\n",
2439 dev->ifaceAlt, errCode); 2342 dev->iface_alt, err_code);
2440 return errCode; 2343 return err_code;
2441 } 2344 }
2442 } 2345 }
2443 2346
2444 PDEBUG(DBG_ISOC, "ISO Packet Length:%d", dev->isocPacketSize); 2347 PDEBUG(DBG_ISOC, "ISO Packet Length:%d", dev->isoc_packet_size);
2445 2348
2446 return 0; 2349 return 0;
2447} 2350}
@@ -2453,27 +2356,27 @@ int usbvision_set_alternate(struct usb_usbvision *dev)
2453int usbvision_init_isoc(struct usb_usbvision *usbvision) 2356int usbvision_init_isoc(struct usb_usbvision *usbvision)
2454{ 2357{
2455 struct usb_device *dev = usbvision->dev; 2358 struct usb_device *dev = usbvision->dev;
2456 int bufIdx, errCode, regValue; 2359 int buf_idx, err_code, reg_value;
2457 int sb_size; 2360 int sb_size;
2458 2361
2459 if (!USBVISION_IS_OPERATIONAL(usbvision)) 2362 if (!USBVISION_IS_OPERATIONAL(usbvision))
2460 return -EFAULT; 2363 return -EFAULT;
2461 2364
2462 usbvision->curFrame = NULL; 2365 usbvision->cur_frame = NULL;
2463 scratch_reset(usbvision); 2366 scratch_reset(usbvision);
2464 2367
2465 /* Alternate interface 1 is is the biggest frame size */ 2368 /* Alternate interface 1 is is the biggest frame size */
2466 errCode = usbvision_set_alternate(usbvision); 2369 err_code = usbvision_set_alternate(usbvision);
2467 if (errCode < 0) { 2370 if (err_code < 0) {
2468 usbvision->last_error = errCode; 2371 usbvision->last_error = err_code;
2469 return -EBUSY; 2372 return -EBUSY;
2470 } 2373 }
2471 sb_size = USBVISION_URB_FRAMES * usbvision->isocPacketSize; 2374 sb_size = USBVISION_URB_FRAMES * usbvision->isoc_packet_size;
2472 2375
2473 regValue = (16 - usbvision_read_reg(usbvision, 2376 reg_value = (16 - usbvision_read_reg(usbvision,
2474 USBVISION_ALTER_REG)) & 0x0F; 2377 USBVISION_ALTER_REG)) & 0x0F;
2475 2378
2476 usbvision->usb_bandwidth = regValue >> 1; 2379 usbvision->usb_bandwidth = reg_value >> 1;
2477 PDEBUG(DBG_ISOC, "USB Bandwidth Usage: %dMbit/Sec", 2380 PDEBUG(DBG_ISOC, "USB Bandwidth Usage: %dMbit/Sec",
2478 usbvision->usb_bandwidth); 2381 usbvision->usb_bandwidth);
2479 2382
@@ -2481,7 +2384,7 @@ int usbvision_init_isoc(struct usb_usbvision *usbvision)
2481 2384
2482 /* We double buffer the Iso lists */ 2385 /* We double buffer the Iso lists */
2483 2386
2484 for (bufIdx = 0; bufIdx < USBVISION_NUMSBUF; bufIdx++) { 2387 for (buf_idx = 0; buf_idx < USBVISION_NUMSBUF; buf_idx++) {
2485 int j, k; 2388 int j, k;
2486 struct urb *urb; 2389 struct urb *urb;
2487 2390
@@ -2491,8 +2394,8 @@ int usbvision_init_isoc(struct usb_usbvision *usbvision)
2491 "%s: usb_alloc_urb() failed\n", __func__); 2394 "%s: usb_alloc_urb() failed\n", __func__);
2492 return -ENOMEM; 2395 return -ENOMEM;
2493 } 2396 }
2494 usbvision->sbuf[bufIdx].urb = urb; 2397 usbvision->sbuf[buf_idx].urb = urb;
2495 usbvision->sbuf[bufIdx].data = 2398 usbvision->sbuf[buf_idx].data =
2496 usb_alloc_coherent(usbvision->dev, 2399 usb_alloc_coherent(usbvision->dev,
2497 sb_size, 2400 sb_size,
2498 GFP_KERNEL, 2401 GFP_KERNEL,
@@ -2502,31 +2405,31 @@ int usbvision_init_isoc(struct usb_usbvision *usbvision)
2502 urb->pipe = usb_rcvisocpipe(dev, usbvision->video_endp); 2405 urb->pipe = usb_rcvisocpipe(dev, usbvision->video_endp);
2503 urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP; 2406 urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
2504 urb->interval = 1; 2407 urb->interval = 1;
2505 urb->transfer_buffer = usbvision->sbuf[bufIdx].data; 2408 urb->transfer_buffer = usbvision->sbuf[buf_idx].data;
2506 urb->complete = usbvision_isocIrq; 2409 urb->complete = usbvision_isoc_irq;
2507 urb->number_of_packets = USBVISION_URB_FRAMES; 2410 urb->number_of_packets = USBVISION_URB_FRAMES;
2508 urb->transfer_buffer_length = 2411 urb->transfer_buffer_length =
2509 usbvision->isocPacketSize * USBVISION_URB_FRAMES; 2412 usbvision->isoc_packet_size * USBVISION_URB_FRAMES;
2510 for (j = k = 0; j < USBVISION_URB_FRAMES; j++, 2413 for (j = k = 0; j < USBVISION_URB_FRAMES; j++,
2511 k += usbvision->isocPacketSize) { 2414 k += usbvision->isoc_packet_size) {
2512 urb->iso_frame_desc[j].offset = k; 2415 urb->iso_frame_desc[j].offset = k;
2513 urb->iso_frame_desc[j].length = 2416 urb->iso_frame_desc[j].length =
2514 usbvision->isocPacketSize; 2417 usbvision->isoc_packet_size;
2515 } 2418 }
2516 } 2419 }
2517 2420
2518 /* Submit all URBs */ 2421 /* Submit all URBs */
2519 for (bufIdx = 0; bufIdx < USBVISION_NUMSBUF; bufIdx++) { 2422 for (buf_idx = 0; buf_idx < USBVISION_NUMSBUF; buf_idx++) {
2520 errCode = usb_submit_urb(usbvision->sbuf[bufIdx].urb, 2423 err_code = usb_submit_urb(usbvision->sbuf[buf_idx].urb,
2521 GFP_KERNEL); 2424 GFP_KERNEL);
2522 if (errCode) { 2425 if (err_code) {
2523 dev_err(&usbvision->dev->dev, 2426 dev_err(&usbvision->dev->dev,
2524 "%s: usb_submit_urb(%d) failed: error %d\n", 2427 "%s: usb_submit_urb(%d) failed: error %d\n",
2525 __func__, bufIdx, errCode); 2428 __func__, buf_idx, err_code);
2526 } 2429 }
2527 } 2430 }
2528 2431
2529 usbvision->streaming = Stream_Idle; 2432 usbvision->streaming = stream_idle;
2530 PDEBUG(DBG_ISOC, "%s: streaming=1 usbvision->video_endp=$%02x", 2433 PDEBUG(DBG_ISOC, "%s: streaming=1 usbvision->video_endp=$%02x",
2531 __func__, 2434 __func__,
2532 usbvision->video_endp); 2435 usbvision->video_endp);
@@ -2542,47 +2445,46 @@ int usbvision_init_isoc(struct usb_usbvision *usbvision)
2542 */ 2445 */
2543void usbvision_stop_isoc(struct usb_usbvision *usbvision) 2446void usbvision_stop_isoc(struct usb_usbvision *usbvision)
2544{ 2447{
2545 int bufIdx, errCode, regValue; 2448 int buf_idx, err_code, reg_value;
2546 int sb_size = USBVISION_URB_FRAMES * usbvision->isocPacketSize; 2449 int sb_size = USBVISION_URB_FRAMES * usbvision->isoc_packet_size;
2547 2450
2548 if ((usbvision->streaming == Stream_Off) || (usbvision->dev == NULL)) 2451 if ((usbvision->streaming == stream_off) || (usbvision->dev == NULL))
2549 return; 2452 return;
2550 2453
2551 /* Unschedule all of the iso td's */ 2454 /* Unschedule all of the iso td's */
2552 for (bufIdx = 0; bufIdx < USBVISION_NUMSBUF; bufIdx++) { 2455 for (buf_idx = 0; buf_idx < USBVISION_NUMSBUF; buf_idx++) {
2553 usb_kill_urb(usbvision->sbuf[bufIdx].urb); 2456 usb_kill_urb(usbvision->sbuf[buf_idx].urb);
2554 if (usbvision->sbuf[bufIdx].data){ 2457 if (usbvision->sbuf[buf_idx].data) {
2555 usb_free_coherent(usbvision->dev, 2458 usb_free_coherent(usbvision->dev,
2556 sb_size, 2459 sb_size,
2557 usbvision->sbuf[bufIdx].data, 2460 usbvision->sbuf[buf_idx].data,
2558 usbvision->sbuf[bufIdx].urb->transfer_dma); 2461 usbvision->sbuf[buf_idx].urb->transfer_dma);
2559 } 2462 }
2560 usb_free_urb(usbvision->sbuf[bufIdx].urb); 2463 usb_free_urb(usbvision->sbuf[buf_idx].urb);
2561 usbvision->sbuf[bufIdx].urb = NULL; 2464 usbvision->sbuf[buf_idx].urb = NULL;
2562 } 2465 }
2563 2466
2564 PDEBUG(DBG_ISOC, "%s: streaming=Stream_Off\n", __func__); 2467 PDEBUG(DBG_ISOC, "%s: streaming=stream_off\n", __func__);
2565 usbvision->streaming = Stream_Off; 2468 usbvision->streaming = stream_off;
2566 2469
2567 if (!usbvision->remove_pending) { 2470 if (!usbvision->remove_pending) {
2568
2569 /* Set packet size to 0 */ 2471 /* Set packet size to 0 */
2570 usbvision->ifaceAlt=0; 2472 usbvision->iface_alt = 0;
2571 errCode = usb_set_interface(usbvision->dev, usbvision->iface, 2473 err_code = usb_set_interface(usbvision->dev, usbvision->iface,
2572 usbvision->ifaceAlt); 2474 usbvision->iface_alt);
2573 if (errCode < 0) { 2475 if (err_code < 0) {
2574 dev_err(&usbvision->dev->dev, 2476 dev_err(&usbvision->dev->dev,
2575 "%s: usb_set_interface() failed: error %d\n", 2477 "%s: usb_set_interface() failed: error %d\n",
2576 __func__, errCode); 2478 __func__, err_code);
2577 usbvision->last_error = errCode; 2479 usbvision->last_error = err_code;
2578 } 2480 }
2579 regValue = (16-usbvision_read_reg(usbvision, USBVISION_ALTER_REG)) & 0x0F; 2481 reg_value = (16-usbvision_read_reg(usbvision, USBVISION_ALTER_REG)) & 0x0F;
2580 usbvision->isocPacketSize = 2482 usbvision->isoc_packet_size =
2581 (regValue == 0) ? 0 : (regValue * 64) - 1; 2483 (reg_value == 0) ? 0 : (reg_value * 64) - 1;
2582 PDEBUG(DBG_ISOC, "ISO Packet Length:%d", 2484 PDEBUG(DBG_ISOC, "ISO Packet Length:%d",
2583 usbvision->isocPacketSize); 2485 usbvision->isoc_packet_size);
2584 2486
2585 usbvision->usb_bandwidth = regValue >> 1; 2487 usbvision->usb_bandwidth = reg_value >> 1;
2586 PDEBUG(DBG_ISOC, "USB Bandwidth Usage: %dMbit/Sec", 2488 PDEBUG(DBG_ISOC, "USB Bandwidth Usage: %dMbit/Sec",
2587 usbvision->usb_bandwidth); 2489 usbvision->usb_bandwidth);
2588 } 2490 }
@@ -2592,39 +2494,38 @@ int usbvision_muxsel(struct usb_usbvision *usbvision, int channel)
2592{ 2494{
2593 /* inputs #0 and #3 are constant for every SAA711x. */ 2495 /* inputs #0 and #3 are constant for every SAA711x. */
2594 /* inputs #1 and #2 are variable for SAA7111 and SAA7113 */ 2496 /* inputs #1 and #2 are variable for SAA7111 and SAA7113 */
2595 int mode[4]= {SAA7115_COMPOSITE0, 0, 0, SAA7115_COMPOSITE3}; 2497 int mode[4] = { SAA7115_COMPOSITE0, 0, 0, SAA7115_COMPOSITE3 };
2596 int audio[]= {1, 0, 0, 0}; 2498 int audio[] = { 1, 0, 0, 0 };
2597 //channel 0 is TV with audiochannel 1 (tuner mono) 2499 /* channel 0 is TV with audiochannel 1 (tuner mono) */
2598 //channel 1 is Composite with audio channel 0 (line in) 2500 /* channel 1 is Composite with audio channel 0 (line in) */
2599 //channel 2 is S-Video with audio channel 0 (line in) 2501 /* channel 2 is S-Video with audio channel 0 (line in) */
2600 //channel 3 is additional video inputs to the device with audio channel 0 (line in) 2502 /* channel 3 is additional video inputs to the device with audio channel 0 (line in) */
2601 2503
2602 RESTRICT_TO_RANGE(channel, 0, usbvision->video_inputs); 2504 RESTRICT_TO_RANGE(channel, 0, usbvision->video_inputs);
2603 usbvision->ctl_input = channel; 2505 usbvision->ctl_input = channel;
2604 2506
2605 // set the new channel 2507 /* set the new channel */
2606 // Regular USB TV Tuners -> channel: 0 = Television, 1 = Composite, 2 = S-Video 2508 /* Regular USB TV Tuners -> channel: 0 = Television, 1 = Composite, 2 = S-Video */
2607 // Four video input devices -> channel: 0 = Chan White, 1 = Chan Green, 2 = Chan Yellow, 3 = Chan Red 2509 /* Four video input devices -> channel: 0 = Chan White, 1 = Chan Green, 2 = Chan Yellow, 3 = Chan Red */
2608 2510
2609 switch (usbvision_device_data[usbvision->DevModel].Codec) { 2511 switch (usbvision_device_data[usbvision->dev_model].codec) {
2610 case CODEC_SAA7113: 2512 case CODEC_SAA7113:
2611 mode[1] = SAA7115_COMPOSITE2; 2513 mode[1] = SAA7115_COMPOSITE2;
2612 if (SwitchSVideoInput) { 2514 if (switch_svideo_input) {
2613 /* To handle problems with S-Video Input for 2515 /* To handle problems with S-Video Input for
2614 * some devices. Use SwitchSVideoInput 2516 * some devices. Use switch_svideo_input
2615 * parameter when loading the module.*/ 2517 * parameter when loading the module.*/
2616 mode[2] = SAA7115_COMPOSITE1; 2518 mode[2] = SAA7115_COMPOSITE1;
2617 } 2519 } else {
2618 else {
2619 mode[2] = SAA7115_SVIDEO1;
2620 }
2621 break;
2622 case CODEC_SAA7111:
2623 default:
2624 /* modes for saa7111 */
2625 mode[1] = SAA7115_COMPOSITE1;
2626 mode[2] = SAA7115_SVIDEO1; 2520 mode[2] = SAA7115_SVIDEO1;
2627 break; 2521 }
2522 break;
2523 case CODEC_SAA7111:
2524 default:
2525 /* modes for saa7111 */
2526 mode[1] = SAA7115_COMPOSITE1;
2527 mode[2] = SAA7115_SVIDEO1;
2528 break;
2628 } 2529 }
2629 call_all(usbvision, video, s_routing, mode[channel], 0, 0); 2530 call_all(usbvision, video, s_routing, mode[channel], 0, 0);
2630 usbvision_set_audio(usbvision, audio[channel]); 2531 usbvision_set_audio(usbvision, audio[channel]);
diff --git a/drivers/media/video/usbvision/usbvision-i2c.c b/drivers/media/video/usbvision/usbvision-i2c.c
index 81dd53bb5267..05b1344181cd 100644
--- a/drivers/media/video/usbvision/usbvision-i2c.c
+++ b/drivers/media/video/usbvision/usbvision-i2c.c
@@ -28,18 +28,18 @@
28#include <linux/module.h> 28#include <linux/module.h>
29#include <linux/delay.h> 29#include <linux/delay.h>
30#include <linux/init.h> 30#include <linux/init.h>
31#include <asm/uaccess.h> 31#include <linux/uaccess.h>
32#include <linux/ioport.h> 32#include <linux/ioport.h>
33#include <linux/errno.h> 33#include <linux/errno.h>
34#include <linux/usb.h> 34#include <linux/usb.h>
35#include <linux/i2c.h> 35#include <linux/i2c.h>
36#include "usbvision.h" 36#include "usbvision.h"
37 37
38#define DBG_I2C 1<<0 38#define DBG_I2C (1 << 0)
39 39
40static int i2c_debug; 40static int i2c_debug;
41 41
42module_param (i2c_debug, int, 0644); // debug_i2c_usb mode of the device driver 42module_param(i2c_debug, int, 0644); /* debug_i2c_usb mode of the device driver */
43MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]"); 43MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]");
44 44
45#define PDEBUG(level, fmt, args...) { \ 45#define PDEBUG(level, fmt, args...) { \
@@ -72,8 +72,8 @@ static inline int try_write_address(struct i2c_adapter *i2c_adap,
72 udelay(10); 72 udelay(10);
73 } 73 }
74 if (i) { 74 if (i) {
75 PDEBUG(DBG_I2C,"Needed %d retries for address %#2x", i, addr); 75 PDEBUG(DBG_I2C, "Needed %d retries for address %#2x", i, addr);
76 PDEBUG(DBG_I2C,"Maybe there's no device at this address"); 76 PDEBUG(DBG_I2C, "Maybe there's no device at this address");
77 } 77 }
78 return ret; 78 return ret;
79} 79}
@@ -96,8 +96,8 @@ static inline int try_read_address(struct i2c_adapter *i2c_adap,
96 udelay(10); 96 udelay(10);
97 } 97 }
98 if (i) { 98 if (i) {
99 PDEBUG(DBG_I2C,"Needed %d retries for address %#2x", i, addr); 99 PDEBUG(DBG_I2C, "Needed %d retries for address %#2x", i, addr);
100 PDEBUG(DBG_I2C,"Maybe there's no device at this address"); 100 PDEBUG(DBG_I2C, "Maybe there's no device at this address");
101 } 101 }
102 return ret; 102 return ret;
103} 103}
@@ -143,9 +143,8 @@ static inline int usb_find_address(struct i2c_adapter *i2c_adap,
143 else 143 else
144 ret = try_write_address(i2c_adap, addr, retries); 144 ret = try_write_address(i2c_adap, addr, retries);
145 145
146 if (ret != 1) { 146 if (ret != 1)
147 return -EREMOTEIO; 147 return -EREMOTEIO;
148 }
149 } 148 }
150 return 0; 149 return 0;
151} 150}
@@ -164,22 +163,20 @@ usbvision_i2c_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg msgs[], int num)
164 pmsg = &msgs[i]; 163 pmsg = &msgs[i];
165 ret = usb_find_address(i2c_adap, pmsg, i2c_adap->retries, &addr); 164 ret = usb_find_address(i2c_adap, pmsg, i2c_adap->retries, &addr);
166 if (ret != 0) { 165 if (ret != 0) {
167 PDEBUG(DBG_I2C,"got NAK from device, message #%d", i); 166 PDEBUG(DBG_I2C, "got NAK from device, message #%d", i);
168 return (ret < 0) ? ret : -EREMOTEIO; 167 return (ret < 0) ? ret : -EREMOTEIO;
169 } 168 }
170 169
171 if (pmsg->flags & I2C_M_RD) { 170 if (pmsg->flags & I2C_M_RD) {
172 /* read bytes into buffer */ 171 /* read bytes into buffer */
173 ret = (usbvision_i2c_read(usbvision, addr, pmsg->buf, pmsg->len)); 172 ret = (usbvision_i2c_read(usbvision, addr, pmsg->buf, pmsg->len));
174 if (ret < pmsg->len) { 173 if (ret < pmsg->len)
175 return (ret < 0) ? ret : -EREMOTEIO; 174 return (ret < 0) ? ret : -EREMOTEIO;
176 }
177 } else { 175 } else {
178 /* write bytes from buffer */ 176 /* write bytes from buffer */
179 ret = (usbvision_i2c_write(usbvision, addr, pmsg->buf, pmsg->len)); 177 ret = (usbvision_i2c_write(usbvision, addr, pmsg->buf, pmsg->len));
180 if (ret < pmsg->len) { 178 if (ret < pmsg->len)
181 return (ret < 0) ? ret : -EREMOTEIO; 179 return (ret < 0) ? ret : -EREMOTEIO;
182 }
183 } 180 }
184 } 181 }
185 return num; 182 return num;
@@ -219,7 +216,7 @@ int usbvision_i2c_register(struct usb_usbvision *usbvision)
219 216
220 sprintf(usbvision->i2c_adap.name, "%s-%d-%s", i2c_adap_template.name, 217 sprintf(usbvision->i2c_adap.name, "%s-%d-%s", i2c_adap_template.name,
221 usbvision->dev->bus->busnum, usbvision->dev->devpath); 218 usbvision->dev->bus->busnum, usbvision->dev->devpath);
222 PDEBUG(DBG_I2C,"Adaptername: %s", usbvision->i2c_adap.name); 219 PDEBUG(DBG_I2C, "Adaptername: %s", usbvision->i2c_adap.name);
223 usbvision->i2c_adap.dev.parent = &usbvision->dev->dev; 220 usbvision->i2c_adap.dev.parent = &usbvision->dev->dev;
224 221
225 i2c_set_adapdata(&usbvision->i2c_adap, &usbvision->v4l2_dev); 222 i2c_set_adapdata(&usbvision->i2c_adap, &usbvision->v4l2_dev);
@@ -244,7 +241,7 @@ int usbvision_i2c_register(struct usb_usbvision *usbvision)
244 PDEBUG(DBG_I2C, "i2c bus for %s registered", usbvision->i2c_adap.name); 241 PDEBUG(DBG_I2C, "i2c bus for %s registered", usbvision->i2c_adap.name);
245 242
246 /* Request the load of the i2c modules we need */ 243 /* Request the load of the i2c modules we need */
247 switch (usbvision_device_data[usbvision->DevModel].Codec) { 244 switch (usbvision_device_data[usbvision->dev_model].codec) {
248 case CODEC_SAA7113: 245 case CODEC_SAA7113:
249 case CODEC_SAA7111: 246 case CODEC_SAA7111:
250 /* Without this delay the detection of the saa711x is 247 /* Without this delay the detection of the saa711x is
@@ -255,7 +252,7 @@ int usbvision_i2c_register(struct usb_usbvision *usbvision)
255 "saa7115_auto", 0, saa711x_addrs); 252 "saa7115_auto", 0, saa711x_addrs);
256 break; 253 break;
257 } 254 }
258 if (usbvision_device_data[usbvision->DevModel].Tuner == 1) { 255 if (usbvision_device_data[usbvision->dev_model].tuner == 1) {
259 struct v4l2_subdev *sd; 256 struct v4l2_subdev *sd;
260 enum v4l2_i2c_tuner_type type; 257 enum v4l2_i2c_tuner_type type;
261 struct tuner_setup tun_setup; 258 struct tuner_setup tun_setup;
@@ -293,7 +290,7 @@ int usbvision_i2c_unregister(struct usb_usbvision *usbvision)
293 i2c_del_adapter(&(usbvision->i2c_adap)); 290 i2c_del_adapter(&(usbvision->i2c_adap));
294 usbvision->registered_i2c = 0; 291 usbvision->registered_i2c = 0;
295 292
296 PDEBUG(DBG_I2C,"i2c bus for %s unregistered", usbvision->i2c_adap.name); 293 PDEBUG(DBG_I2C, "i2c bus for %s unregistered", usbvision->i2c_adap.name);
297 294
298 return 0; 295 return 0;
299} 296}
@@ -355,9 +352,9 @@ usbvision_i2c_read_max4(struct usb_usbvision *usbvision, unsigned char addr,
355 352
356 if (i2c_debug & DBG_I2C) { 353 if (i2c_debug & DBG_I2C) {
357 int idx; 354 int idx;
358 for (idx = 0; idx < len; idx++) { 355
359 PDEBUG(DBG_I2C,"read %x from address %x", (unsigned char)buf[idx], addr); 356 for (idx = 0; idx < len; idx++)
360 } 357 PDEBUG(DBG_I2C, "read %x from address %x", (unsigned char)buf[idx], addr);
361 } 358 }
362 return len; 359 return len;
363} 360}
@@ -416,9 +413,9 @@ static int usbvision_i2c_write_max4(struct usb_usbvision *usbvision,
416 413
417 if (i2c_debug & DBG_I2C) { 414 if (i2c_debug & DBG_I2C) {
418 int idx; 415 int idx;
419 for (idx = 0; idx < len; idx++) { 416
420 PDEBUG(DBG_I2C,"wrote %x at address %x", (unsigned char)buf[idx], addr); 417 for (idx = 0; idx < len; idx++)
421 } 418 PDEBUG(DBG_I2C, "wrote %x at address %x", (unsigned char)buf[idx], addr);
422 } 419 }
423 return len; 420 return len;
424} 421}
@@ -426,18 +423,18 @@ static int usbvision_i2c_write_max4(struct usb_usbvision *usbvision,
426static int usbvision_i2c_write(struct usb_usbvision *usbvision, unsigned char addr, char *buf, 423static int usbvision_i2c_write(struct usb_usbvision *usbvision, unsigned char addr, char *buf,
427 short len) 424 short len)
428{ 425{
429 char *bufPtr = buf; 426 char *buf_ptr = buf;
430 int retval; 427 int retval;
431 int wrcount = 0; 428 int wrcount = 0;
432 int count; 429 int count;
433 int maxLen = 4; 430 int max_len = 4;
434 431
435 while (len > 0) { 432 while (len > 0) {
436 count = (len > maxLen) ? maxLen : len; 433 count = (len > max_len) ? max_len : len;
437 retval = usbvision_i2c_write_max4(usbvision, addr, bufPtr, count); 434 retval = usbvision_i2c_write_max4(usbvision, addr, buf_ptr, count);
438 if (retval > 0) { 435 if (retval > 0) {
439 len -= count; 436 len -= count;
440 bufPtr += count; 437 buf_ptr += count;
441 wrcount += count; 438 wrcount += count;
442 } else 439 } else
443 return (retval < 0) ? retval : -EFAULT; 440 return (retval < 0) ? retval : -EFAULT;
diff --git a/drivers/media/video/usbvision/usbvision-video.c b/drivers/media/video/usbvision/usbvision-video.c
index 011c0c386995..6083137f0bf8 100644
--- a/drivers/media/video/usbvision/usbvision-video.c
+++ b/drivers/media/video/usbvision/usbvision-video.c
@@ -56,7 +56,7 @@
56#include <linux/module.h> 56#include <linux/module.h>
57#include <linux/init.h> 57#include <linux/init.h>
58#include <linux/spinlock.h> 58#include <linux/spinlock.h>
59#include <asm/io.h> 59#include <linux/io.h>
60#include <linux/videodev2.h> 60#include <linux/videodev2.h>
61#include <linux/i2c.h> 61#include <linux/i2c.h>
62 62
@@ -70,8 +70,8 @@
70#include "usbvision.h" 70#include "usbvision.h"
71#include "usbvision-cards.h" 71#include "usbvision-cards.h"
72 72
73#define DRIVER_AUTHOR "Joerg Heckenbach <joerg@heckenbach-aw.de>,\ 73#define DRIVER_AUTHOR "Joerg Heckenbach <joerg@heckenbach-aw.de>, \
74 Dwaine Garden <DwaineGarden@rogers.com>" 74Dwaine Garden <DwaineGarden@rogers.com>"
75#define DRIVER_NAME "usbvision" 75#define DRIVER_NAME "usbvision"
76#define DRIVER_ALIAS "USBVision" 76#define DRIVER_ALIAS "USBVision"
77#define DRIVER_DESC "USBVision USB Video Device Driver for Linux" 77#define DRIVER_DESC "USBVision USB Video Device Driver for Linux"
@@ -82,9 +82,9 @@
82#define USBVISION_DRIVER_VERSION KERNEL_VERSION(USBVISION_DRIVER_VERSION_MAJOR,\ 82#define USBVISION_DRIVER_VERSION KERNEL_VERSION(USBVISION_DRIVER_VERSION_MAJOR,\
83USBVISION_DRIVER_VERSION_MINOR,\ 83USBVISION_DRIVER_VERSION_MINOR,\
84USBVISION_DRIVER_VERSION_PATCHLEVEL) 84USBVISION_DRIVER_VERSION_PATCHLEVEL)
85#define USBVISION_VERSION_STRING __stringify(USBVISION_DRIVER_VERSION_MAJOR)\ 85#define USBVISION_VERSION_STRING __stringify(USBVISION_DRIVER_VERSION_MAJOR) \
86 "." __stringify(USBVISION_DRIVER_VERSION_MINOR)\ 86"." __stringify(USBVISION_DRIVER_VERSION_MINOR) \
87 "." __stringify(USBVISION_DRIVER_VERSION_PATCHLEVEL) 87"." __stringify(USBVISION_DRIVER_VERSION_PATCHLEVEL)
88 88
89#define ENABLE_HEXDUMP 0 /* Enable if you need it */ 89#define ENABLE_HEXDUMP 0 /* Enable if you need it */
90 90
@@ -96,16 +96,16 @@ USBVISION_DRIVER_VERSION_PATCHLEVEL)
96 __func__, __LINE__ , ## args); \ 96 __func__, __LINE__ , ## args); \
97 } 97 }
98#else 98#else
99 #define PDEBUG(level, fmt, args...) do {} while(0) 99 #define PDEBUG(level, fmt, args...) do {} while (0)
100#endif 100#endif
101 101
102#define DBG_IO 1<<1 102#define DBG_IO (1 << 1)
103#define DBG_PROBE 1<<2 103#define DBG_PROBE (1 << 2)
104#define DBG_MMAP 1<<3 104#define DBG_MMAP (1 << 3)
105 105
106//String operations 106/* String operations */
107#define rmspace(str) while(*str==' ') str++; 107#define rmspace(str) while (*str == ' ') str++;
108#define goto2next(str) while(*str!=' ') str++; while(*str==' ') str++; 108#define goto2next(str) while (*str != ' ') str++; while (*str == ' ') str++;
109 109
110 110
111/* sequential number of usbvision device */ 111/* sequential number of usbvision device */
@@ -118,7 +118,7 @@ static struct usbvision_v4l2_format_st usbvision_v4l2_format[] = {
118 { 1, 4, 32, V4L2_PIX_FMT_RGB32 , "RGB32" }, 118 { 1, 4, 32, V4L2_PIX_FMT_RGB32 , "RGB32" },
119 { 1, 2, 16, V4L2_PIX_FMT_RGB555 , "RGB555" }, 119 { 1, 2, 16, V4L2_PIX_FMT_RGB555 , "RGB555" },
120 { 1, 2, 16, V4L2_PIX_FMT_YUYV , "YUV422" }, 120 { 1, 2, 16, V4L2_PIX_FMT_YUYV , "YUV422" },
121 { 1, 2, 12, V4L2_PIX_FMT_YVU420 , "YUV420P" }, // 1.5 ! 121 { 1, 2, 12, V4L2_PIX_FMT_YVU420 , "YUV420P" }, /* 1.5 ! */
122 { 1, 2, 16, V4L2_PIX_FMT_YUV422P , "YUV422P" } 122 { 1, 2, 16, V4L2_PIX_FMT_YUV422P , "YUV422P" }
123}; 123};
124 124
@@ -127,11 +127,11 @@ static void usbvision_release(struct usb_usbvision *usbvision);
127 127
128/* Default initialization of device driver parameters */ 128/* Default initialization of device driver parameters */
129/* Set the default format for ISOC endpoint */ 129/* Set the default format for ISOC endpoint */
130static int isocMode = ISOC_MODE_COMPRESS; 130static int isoc_mode = ISOC_MODE_COMPRESS;
131/* Set the default Debug Mode of the device driver */ 131/* Set the default Debug Mode of the device driver */
132static int video_debug; 132static int video_debug;
133/* Set the default device to power on at startup */ 133/* Set the default device to power on at startup */
134static int PowerOnAtOpen = 1; 134static int power_on_at_open = 1;
135/* Sequential Number of Video Device */ 135/* Sequential Number of Video Device */
136static int video_nr = -1; 136static int video_nr = -1;
137/* Sequential Number of Radio Device */ 137/* Sequential Number of Radio Device */
@@ -140,20 +140,20 @@ static int radio_nr = -1;
140/* Grab parameters for the device driver */ 140/* Grab parameters for the device driver */
141 141
142/* Showing parameters under SYSFS */ 142/* Showing parameters under SYSFS */
143module_param(isocMode, int, 0444); 143module_param(isoc_mode, int, 0444);
144module_param(video_debug, int, 0444); 144module_param(video_debug, int, 0444);
145module_param(PowerOnAtOpen, int, 0444); 145module_param(power_on_at_open, int, 0444);
146module_param(video_nr, int, 0444); 146module_param(video_nr, int, 0444);
147module_param(radio_nr, int, 0444); 147module_param(radio_nr, int, 0444);
148 148
149MODULE_PARM_DESC(isocMode, " Set the default format for ISOC endpoint. Default: 0x60 (Compression On)"); 149MODULE_PARM_DESC(isoc_mode, " Set the default format for ISOC endpoint. Default: 0x60 (Compression On)");
150MODULE_PARM_DESC(video_debug, " Set the default Debug Mode of the device driver. Default: 0 (Off)"); 150MODULE_PARM_DESC(video_debug, " Set the default Debug Mode of the device driver. Default: 0 (Off)");
151MODULE_PARM_DESC(PowerOnAtOpen, " Set the default device to power on when device is opened. Default: 1 (On)"); 151MODULE_PARM_DESC(power_on_at_open, " Set the default device to power on when device is opened. Default: 1 (On)");
152MODULE_PARM_DESC(video_nr, "Set video device number (/dev/videoX). Default: -1 (autodetect)"); 152MODULE_PARM_DESC(video_nr, "Set video device number (/dev/videoX). Default: -1 (autodetect)");
153MODULE_PARM_DESC(radio_nr, "Set radio device number (/dev/radioX). Default: -1 (autodetect)"); 153MODULE_PARM_DESC(radio_nr, "Set radio device number (/dev/radioX). Default: -1 (autodetect)");
154 154
155 155
156// Misc stuff 156/* Misc stuff */
157MODULE_AUTHOR(DRIVER_AUTHOR); 157MODULE_AUTHOR(DRIVER_AUTHOR);
158MODULE_DESCRIPTION(DRIVER_DESC); 158MODULE_DESCRIPTION(DRIVER_DESC);
159MODULE_LICENSE(DRIVER_LICENSE); 159MODULE_LICENSE(DRIVER_LICENSE);
@@ -192,7 +192,7 @@ static ssize_t show_model(struct device *cd,
192 container_of(cd, struct video_device, dev); 192 container_of(cd, struct video_device, dev);
193 struct usb_usbvision *usbvision = video_get_drvdata(vdev); 193 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
194 return sprintf(buf, "%s\n", 194 return sprintf(buf, "%s\n",
195 usbvision_device_data[usbvision->DevModel].ModelString); 195 usbvision_device_data[usbvision->dev_model].model_string);
196} 196}
197static DEVICE_ATTR(model, S_IRUGO, show_model, NULL); 197static DEVICE_ATTR(model, S_IRUGO, show_model, NULL);
198 198
@@ -205,7 +205,7 @@ static ssize_t show_hue(struct device *cd,
205 struct v4l2_control ctrl; 205 struct v4l2_control ctrl;
206 ctrl.id = V4L2_CID_HUE; 206 ctrl.id = V4L2_CID_HUE;
207 ctrl.value = 0; 207 ctrl.value = 0;
208 if(usbvision->user) 208 if (usbvision->user)
209 call_all(usbvision, core, g_ctrl, &ctrl); 209 call_all(usbvision, core, g_ctrl, &ctrl);
210 return sprintf(buf, "%d\n", ctrl.value); 210 return sprintf(buf, "%d\n", ctrl.value);
211} 211}
@@ -220,7 +220,7 @@ static ssize_t show_contrast(struct device *cd,
220 struct v4l2_control ctrl; 220 struct v4l2_control ctrl;
221 ctrl.id = V4L2_CID_CONTRAST; 221 ctrl.id = V4L2_CID_CONTRAST;
222 ctrl.value = 0; 222 ctrl.value = 0;
223 if(usbvision->user) 223 if (usbvision->user)
224 call_all(usbvision, core, g_ctrl, &ctrl); 224 call_all(usbvision, core, g_ctrl, &ctrl);
225 return sprintf(buf, "%d\n", ctrl.value); 225 return sprintf(buf, "%d\n", ctrl.value);
226} 226}
@@ -235,7 +235,7 @@ static ssize_t show_brightness(struct device *cd,
235 struct v4l2_control ctrl; 235 struct v4l2_control ctrl;
236 ctrl.id = V4L2_CID_BRIGHTNESS; 236 ctrl.id = V4L2_CID_BRIGHTNESS;
237 ctrl.value = 0; 237 ctrl.value = 0;
238 if(usbvision->user) 238 if (usbvision->user)
239 call_all(usbvision, core, g_ctrl, &ctrl); 239 call_all(usbvision, core, g_ctrl, &ctrl);
240 return sprintf(buf, "%d\n", ctrl.value); 240 return sprintf(buf, "%d\n", ctrl.value);
241} 241}
@@ -250,7 +250,7 @@ static ssize_t show_saturation(struct device *cd,
250 struct v4l2_control ctrl; 250 struct v4l2_control ctrl;
251 ctrl.id = V4L2_CID_SATURATION; 251 ctrl.id = V4L2_CID_SATURATION;
252 ctrl.value = 0; 252 ctrl.value = 0;
253 if(usbvision->user) 253 if (usbvision->user)
254 call_all(usbvision, core, g_ctrl, &ctrl); 254 call_all(usbvision, core, g_ctrl, &ctrl);
255 return sprintf(buf, "%d\n", ctrl.value); 255 return sprintf(buf, "%d\n", ctrl.value);
256} 256}
@@ -263,7 +263,7 @@ static ssize_t show_streaming(struct device *cd,
263 container_of(cd, struct video_device, dev); 263 container_of(cd, struct video_device, dev);
264 struct usb_usbvision *usbvision = video_get_drvdata(vdev); 264 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
265 return sprintf(buf, "%s\n", 265 return sprintf(buf, "%s\n",
266 YES_NO(usbvision->streaming==Stream_On?1:0)); 266 YES_NO(usbvision->streaming == stream_on ? 1 : 0));
267} 267}
268static DEVICE_ATTR(streaming, S_IRUGO, show_streaming, NULL); 268static DEVICE_ATTR(streaming, S_IRUGO, show_streaming, NULL);
269 269
@@ -274,7 +274,7 @@ static ssize_t show_compression(struct device *cd,
274 container_of(cd, struct video_device, dev); 274 container_of(cd, struct video_device, dev);
275 struct usb_usbvision *usbvision = video_get_drvdata(vdev); 275 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
276 return sprintf(buf, "%s\n", 276 return sprintf(buf, "%s\n",
277 YES_NO(usbvision->isocMode==ISOC_MODE_COMPRESS)); 277 YES_NO(usbvision->isoc_mode == ISOC_MODE_COMPRESS));
278} 278}
279static DEVICE_ATTR(compression, S_IRUGO, show_compression, NULL); 279static DEVICE_ATTR(compression, S_IRUGO, show_compression, NULL);
280 280
@@ -284,42 +284,43 @@ static ssize_t show_device_bridge(struct device *cd,
284 struct video_device *vdev = 284 struct video_device *vdev =
285 container_of(cd, struct video_device, dev); 285 container_of(cd, struct video_device, dev);
286 struct usb_usbvision *usbvision = video_get_drvdata(vdev); 286 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
287 return sprintf(buf, "%d\n", usbvision->bridgeType); 287 return sprintf(buf, "%d\n", usbvision->bridge_type);
288} 288}
289static DEVICE_ATTR(bridge, S_IRUGO, show_device_bridge, NULL); 289static DEVICE_ATTR(bridge, S_IRUGO, show_device_bridge, NULL);
290 290
291static void usbvision_create_sysfs(struct video_device *vdev) 291static void usbvision_create_sysfs(struct video_device *vdev)
292{ 292{
293 int res; 293 int res;
294
294 if (!vdev) 295 if (!vdev)
295 return; 296 return;
296 do { 297 do {
297 res = device_create_file(&vdev->dev, &dev_attr_version); 298 res = device_create_file(&vdev->dev, &dev_attr_version);
298 if (res<0) 299 if (res < 0)
299 break; 300 break;
300 res = device_create_file(&vdev->dev, &dev_attr_model); 301 res = device_create_file(&vdev->dev, &dev_attr_model);
301 if (res<0) 302 if (res < 0)
302 break; 303 break;
303 res = device_create_file(&vdev->dev, &dev_attr_hue); 304 res = device_create_file(&vdev->dev, &dev_attr_hue);
304 if (res<0) 305 if (res < 0)
305 break; 306 break;
306 res = device_create_file(&vdev->dev, &dev_attr_contrast); 307 res = device_create_file(&vdev->dev, &dev_attr_contrast);
307 if (res<0) 308 if (res < 0)
308 break; 309 break;
309 res = device_create_file(&vdev->dev, &dev_attr_brightness); 310 res = device_create_file(&vdev->dev, &dev_attr_brightness);
310 if (res<0) 311 if (res < 0)
311 break; 312 break;
312 res = device_create_file(&vdev->dev, &dev_attr_saturation); 313 res = device_create_file(&vdev->dev, &dev_attr_saturation);
313 if (res<0) 314 if (res < 0)
314 break; 315 break;
315 res = device_create_file(&vdev->dev, &dev_attr_streaming); 316 res = device_create_file(&vdev->dev, &dev_attr_streaming);
316 if (res<0) 317 if (res < 0)
317 break; 318 break;
318 res = device_create_file(&vdev->dev, &dev_attr_compression); 319 res = device_create_file(&vdev->dev, &dev_attr_compression);
319 if (res<0) 320 if (res < 0)
320 break; 321 break;
321 res = device_create_file(&vdev->dev, &dev_attr_bridge); 322 res = device_create_file(&vdev->dev, &dev_attr_bridge);
322 if (res>=0) 323 if (res >= 0)
323 return; 324 return;
324 } while (0); 325 } while (0);
325 326
@@ -352,24 +353,23 @@ static void usbvision_remove_sysfs(struct video_device *vdev)
352static int usbvision_v4l2_open(struct file *file) 353static int usbvision_v4l2_open(struct file *file)
353{ 354{
354 struct usb_usbvision *usbvision = video_drvdata(file); 355 struct usb_usbvision *usbvision = video_drvdata(file);
355 int errCode = 0; 356 int err_code = 0;
356 357
357 PDEBUG(DBG_IO, "open"); 358 PDEBUG(DBG_IO, "open");
358 359
359 mutex_lock(&usbvision->lock); 360 usbvision_reset_power_off_timer(usbvision);
360 usbvision_reset_powerOffTimer(usbvision);
361 361
362 if (usbvision->user) 362 if (usbvision->user)
363 errCode = -EBUSY; 363 err_code = -EBUSY;
364 else { 364 else {
365 /* Allocate memory for the scratch ring buffer */ 365 /* Allocate memory for the scratch ring buffer */
366 errCode = usbvision_scratch_alloc(usbvision); 366 err_code = usbvision_scratch_alloc(usbvision);
367 if (isocMode==ISOC_MODE_COMPRESS) { 367 if (isoc_mode == ISOC_MODE_COMPRESS) {
368 /* Allocate intermediate decompression buffers 368 /* Allocate intermediate decompression buffers
369 only if needed */ 369 only if needed */
370 errCode = usbvision_decompress_alloc(usbvision); 370 err_code = usbvision_decompress_alloc(usbvision);
371 } 371 }
372 if (errCode) { 372 if (err_code) {
373 /* Deallocate all buffers if trouble */ 373 /* Deallocate all buffers if trouble */
374 usbvision_scratch_free(usbvision); 374 usbvision_scratch_free(usbvision);
375 usbvision_decompress_free(usbvision); 375 usbvision_decompress_free(usbvision);
@@ -377,7 +377,7 @@ static int usbvision_v4l2_open(struct file *file)
377 } 377 }
378 378
379 /* If so far no errors then we shall start the camera */ 379 /* If so far no errors then we shall start the camera */
380 if (!errCode) { 380 if (!err_code) {
381 if (usbvision->power == 0) { 381 if (usbvision->power == 0) {
382 usbvision_power_on(usbvision); 382 usbvision_power_on(usbvision);
383 usbvision_i2c_register(usbvision); 383 usbvision_i2c_register(usbvision);
@@ -386,21 +386,21 @@ static int usbvision_v4l2_open(struct file *file)
386 /* Send init sequence only once, it's large! */ 386 /* Send init sequence only once, it's large! */
387 if (!usbvision->initialized) { 387 if (!usbvision->initialized) {
388 int setup_ok = 0; 388 int setup_ok = 0;
389 setup_ok = usbvision_setup(usbvision,isocMode); 389 setup_ok = usbvision_setup(usbvision, isoc_mode);
390 if (setup_ok) 390 if (setup_ok)
391 usbvision->initialized = 1; 391 usbvision->initialized = 1;
392 else 392 else
393 errCode = -EBUSY; 393 err_code = -EBUSY;
394 } 394 }
395 395
396 if (!errCode) { 396 if (!err_code) {
397 usbvision_begin_streaming(usbvision); 397 usbvision_begin_streaming(usbvision);
398 errCode = usbvision_init_isoc(usbvision); 398 err_code = usbvision_init_isoc(usbvision);
399 /* device must be initialized before isoc transfer */ 399 /* device must be initialized before isoc transfer */
400 usbvision_muxsel(usbvision,0); 400 usbvision_muxsel(usbvision, 0);
401 usbvision->user++; 401 usbvision->user++;
402 } else { 402 } else {
403 if (PowerOnAtOpen) { 403 if (power_on_at_open) {
404 usbvision_i2c_unregister(usbvision); 404 usbvision_i2c_unregister(usbvision);
405 usbvision_power_off(usbvision); 405 usbvision_power_off(usbvision);
406 usbvision->initialized = 0; 406 usbvision->initialized = 0;
@@ -412,8 +412,7 @@ static int usbvision_v4l2_open(struct file *file)
412 usbvision_empty_framequeues(usbvision); 412 usbvision_empty_framequeues(usbvision);
413 413
414 PDEBUG(DBG_IO, "success"); 414 PDEBUG(DBG_IO, "success");
415 mutex_unlock(&usbvision->lock); 415 return err_code;
416 return errCode;
417} 416}
418 417
419/* 418/*
@@ -429,7 +428,6 @@ static int usbvision_v4l2_close(struct file *file)
429 struct usb_usbvision *usbvision = video_drvdata(file); 428 struct usb_usbvision *usbvision = video_drvdata(file);
430 429
431 PDEBUG(DBG_IO, "close"); 430 PDEBUG(DBG_IO, "close");
432 mutex_lock(&usbvision->lock);
433 431
434 usbvision_audio_off(usbvision); 432 usbvision_audio_off(usbvision);
435 usbvision_restart_isoc(usbvision); 433 usbvision_restart_isoc(usbvision);
@@ -442,15 +440,13 @@ static int usbvision_v4l2_close(struct file *file)
442 440
443 usbvision->user--; 441 usbvision->user--;
444 442
445 if (PowerOnAtOpen) { 443 if (power_on_at_open) {
446 /* power off in a little while 444 /* power off in a little while
447 to avoid off/on every close/open short sequences */ 445 to avoid off/on every close/open short sequences */
448 usbvision_set_powerOffTimer(usbvision); 446 usbvision_set_power_off_timer(usbvision);
449 usbvision->initialized = 0; 447 usbvision->initialized = 0;
450 } 448 }
451 449
452 mutex_unlock(&usbvision->lock);
453
454 if (usbvision->remove_pending) { 450 if (usbvision->remove_pending) {
455 printk(KERN_INFO "%s: Final disconnect\n", __func__); 451 printk(KERN_INFO "%s: Final disconnect\n", __func__);
456 usbvision_release(usbvision); 452 usbvision_release(usbvision);
@@ -468,55 +464,55 @@ static int usbvision_v4l2_close(struct file *file)
468 * 464 *
469 */ 465 */
470#ifdef CONFIG_VIDEO_ADV_DEBUG 466#ifdef CONFIG_VIDEO_ADV_DEBUG
471static int vidioc_g_register (struct file *file, void *priv, 467static int vidioc_g_register(struct file *file, void *priv,
472 struct v4l2_dbg_register *reg) 468 struct v4l2_dbg_register *reg)
473{ 469{
474 struct usb_usbvision *usbvision = video_drvdata(file); 470 struct usb_usbvision *usbvision = video_drvdata(file);
475 int errCode; 471 int err_code;
476 472
477 if (!v4l2_chip_match_host(&reg->match)) 473 if (!v4l2_chip_match_host(&reg->match))
478 return -EINVAL; 474 return -EINVAL;
479 /* NT100x has a 8-bit register space */ 475 /* NT100x has a 8-bit register space */
480 errCode = usbvision_read_reg(usbvision, reg->reg&0xff); 476 err_code = usbvision_read_reg(usbvision, reg->reg&0xff);
481 if (errCode < 0) { 477 if (err_code < 0) {
482 dev_err(&usbvision->vdev->dev, 478 dev_err(&usbvision->vdev->dev,
483 "%s: VIDIOC_DBG_G_REGISTER failed: error %d\n", 479 "%s: VIDIOC_DBG_G_REGISTER failed: error %d\n",
484 __func__, errCode); 480 __func__, err_code);
485 return errCode; 481 return err_code;
486 } 482 }
487 reg->val = errCode; 483 reg->val = err_code;
488 reg->size = 1; 484 reg->size = 1;
489 return 0; 485 return 0;
490} 486}
491 487
492static int vidioc_s_register (struct file *file, void *priv, 488static int vidioc_s_register(struct file *file, void *priv,
493 struct v4l2_dbg_register *reg) 489 struct v4l2_dbg_register *reg)
494{ 490{
495 struct usb_usbvision *usbvision = video_drvdata(file); 491 struct usb_usbvision *usbvision = video_drvdata(file);
496 int errCode; 492 int err_code;
497 493
498 if (!v4l2_chip_match_host(&reg->match)) 494 if (!v4l2_chip_match_host(&reg->match))
499 return -EINVAL; 495 return -EINVAL;
500 /* NT100x has a 8-bit register space */ 496 /* NT100x has a 8-bit register space */
501 errCode = usbvision_write_reg(usbvision, reg->reg&0xff, reg->val); 497 err_code = usbvision_write_reg(usbvision, reg->reg & 0xff, reg->val);
502 if (errCode < 0) { 498 if (err_code < 0) {
503 dev_err(&usbvision->vdev->dev, 499 dev_err(&usbvision->vdev->dev,
504 "%s: VIDIOC_DBG_S_REGISTER failed: error %d\n", 500 "%s: VIDIOC_DBG_S_REGISTER failed: error %d\n",
505 __func__, errCode); 501 __func__, err_code);
506 return errCode; 502 return err_code;
507 } 503 }
508 return 0; 504 return 0;
509} 505}
510#endif 506#endif
511 507
512static int vidioc_querycap (struct file *file, void *priv, 508static int vidioc_querycap(struct file *file, void *priv,
513 struct v4l2_capability *vc) 509 struct v4l2_capability *vc)
514{ 510{
515 struct usb_usbvision *usbvision = video_drvdata(file); 511 struct usb_usbvision *usbvision = video_drvdata(file);
516 512
517 strlcpy(vc->driver, "USBVision", sizeof(vc->driver)); 513 strlcpy(vc->driver, "USBVision", sizeof(vc->driver));
518 strlcpy(vc->card, 514 strlcpy(vc->card,
519 usbvision_device_data[usbvision->DevModel].ModelString, 515 usbvision_device_data[usbvision->dev_model].model_string,
520 sizeof(vc->card)); 516 sizeof(vc->card));
521 usb_make_path(usbvision->dev, vc->bus_info, sizeof(vc->bus_info)); 517 usb_make_path(usbvision->dev, vc->bus_info, sizeof(vc->bus_info));
522 vc->version = USBVISION_DRIVER_VERSION; 518 vc->version = USBVISION_DRIVER_VERSION;
@@ -528,7 +524,7 @@ static int vidioc_querycap (struct file *file, void *priv,
528 return 0; 524 return 0;
529} 525}
530 526
531static int vidioc_enum_input (struct file *file, void *priv, 527static int vidioc_enum_input(struct file *file, void *priv,
532 struct v4l2_input *vi) 528 struct v4l2_input *vi)
533{ 529{
534 struct usb_usbvision *usbvision = video_drvdata(file); 530 struct usb_usbvision *usbvision = video_drvdata(file);
@@ -536,16 +532,16 @@ static int vidioc_enum_input (struct file *file, void *priv,
536 532
537 if (vi->index >= usbvision->video_inputs) 533 if (vi->index >= usbvision->video_inputs)
538 return -EINVAL; 534 return -EINVAL;
539 if (usbvision->have_tuner) { 535 if (usbvision->have_tuner)
540 chan = vi->index; 536 chan = vi->index;
541 } else { 537 else
542 chan = vi->index + 1; /*skip Television string*/ 538 chan = vi->index + 1; /* skip Television string*/
543 } 539
544 /* Determine the requested input characteristics 540 /* Determine the requested input characteristics
545 specific for each usbvision card model */ 541 specific for each usbvision card model */
546 switch(chan) { 542 switch (chan) {
547 case 0: 543 case 0:
548 if (usbvision_device_data[usbvision->DevModel].VideoChannels == 4) { 544 if (usbvision_device_data[usbvision->dev_model].video_channels == 4) {
549 strcpy(vi->name, "White Video Input"); 545 strcpy(vi->name, "White Video Input");
550 } else { 546 } else {
551 strcpy(vi->name, "Television"); 547 strcpy(vi->name, "Television");
@@ -557,20 +553,18 @@ static int vidioc_enum_input (struct file *file, void *priv,
557 break; 553 break;
558 case 1: 554 case 1:
559 vi->type = V4L2_INPUT_TYPE_CAMERA; 555 vi->type = V4L2_INPUT_TYPE_CAMERA;
560 if (usbvision_device_data[usbvision->DevModel].VideoChannels == 4) { 556 if (usbvision_device_data[usbvision->dev_model].video_channels == 4)
561 strcpy(vi->name, "Green Video Input"); 557 strcpy(vi->name, "Green Video Input");
562 } else { 558 else
563 strcpy(vi->name, "Composite Video Input"); 559 strcpy(vi->name, "Composite Video Input");
564 }
565 vi->std = V4L2_STD_PAL; 560 vi->std = V4L2_STD_PAL;
566 break; 561 break;
567 case 2: 562 case 2:
568 vi->type = V4L2_INPUT_TYPE_CAMERA; 563 vi->type = V4L2_INPUT_TYPE_CAMERA;
569 if (usbvision_device_data[usbvision->DevModel].VideoChannels == 4) { 564 if (usbvision_device_data[usbvision->dev_model].video_channels == 4)
570 strcpy(vi->name, "Yellow Video Input"); 565 strcpy(vi->name, "Yellow Video Input");
571 } else { 566 else
572 strcpy(vi->name, "S-Video Input"); 567 strcpy(vi->name, "S-Video Input");
573 }
574 vi->std = V4L2_STD_PAL; 568 vi->std = V4L2_STD_PAL;
575 break; 569 break;
576 case 3: 570 case 3:
@@ -582,7 +576,7 @@ static int vidioc_enum_input (struct file *file, void *priv,
582 return 0; 576 return 0;
583} 577}
584 578
585static int vidioc_g_input (struct file *file, void *priv, unsigned int *input) 579static int vidioc_g_input(struct file *file, void *priv, unsigned int *input)
586{ 580{
587 struct usb_usbvision *usbvision = video_drvdata(file); 581 struct usb_usbvision *usbvision = video_drvdata(file);
588 582
@@ -590,46 +584,42 @@ static int vidioc_g_input (struct file *file, void *priv, unsigned int *input)
590 return 0; 584 return 0;
591} 585}
592 586
593static int vidioc_s_input (struct file *file, void *priv, unsigned int input) 587static int vidioc_s_input(struct file *file, void *priv, unsigned int input)
594{ 588{
595 struct usb_usbvision *usbvision = video_drvdata(file); 589 struct usb_usbvision *usbvision = video_drvdata(file);
596 590
597 if (input >= usbvision->video_inputs) 591 if (input >= usbvision->video_inputs)
598 return -EINVAL; 592 return -EINVAL;
599 593
600 mutex_lock(&usbvision->lock);
601 usbvision_muxsel(usbvision, input); 594 usbvision_muxsel(usbvision, input);
602 usbvision_set_input(usbvision); 595 usbvision_set_input(usbvision);
603 usbvision_set_output(usbvision, 596 usbvision_set_output(usbvision,
604 usbvision->curwidth, 597 usbvision->curwidth,
605 usbvision->curheight); 598 usbvision->curheight);
606 mutex_unlock(&usbvision->lock);
607 return 0; 599 return 0;
608} 600}
609 601
610static int vidioc_s_std (struct file *file, void *priv, v4l2_std_id *id) 602static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *id)
611{ 603{
612 struct usb_usbvision *usbvision = video_drvdata(file); 604 struct usb_usbvision *usbvision = video_drvdata(file);
613 605
614 usbvision->tvnormId=*id; 606 usbvision->tvnorm_id = *id;
615 607
616 mutex_lock(&usbvision->lock); 608 call_all(usbvision, core, s_std, usbvision->tvnorm_id);
617 call_all(usbvision, core, s_std, usbvision->tvnormId);
618 mutex_unlock(&usbvision->lock);
619 /* propagate the change to the decoder */ 609 /* propagate the change to the decoder */
620 usbvision_muxsel(usbvision, usbvision->ctl_input); 610 usbvision_muxsel(usbvision, usbvision->ctl_input);
621 611
622 return 0; 612 return 0;
623} 613}
624 614
625static int vidioc_g_tuner (struct file *file, void *priv, 615static int vidioc_g_tuner(struct file *file, void *priv,
626 struct v4l2_tuner *vt) 616 struct v4l2_tuner *vt)
627{ 617{
628 struct usb_usbvision *usbvision = video_drvdata(file); 618 struct usb_usbvision *usbvision = video_drvdata(file);
629 619
630 if (!usbvision->have_tuner || vt->index) // Only tuner 0 620 if (!usbvision->have_tuner || vt->index) /* Only tuner 0 */
631 return -EINVAL; 621 return -EINVAL;
632 if(usbvision->radio) { 622 if (usbvision->radio) {
633 strcpy(vt->name, "Radio"); 623 strcpy(vt->name, "Radio");
634 vt->type = V4L2_TUNER_RADIO; 624 vt->type = V4L2_TUNER_RADIO;
635 } else { 625 } else {
@@ -641,12 +631,12 @@ static int vidioc_g_tuner (struct file *file, void *priv,
641 return 0; 631 return 0;
642} 632}
643 633
644static int vidioc_s_tuner (struct file *file, void *priv, 634static int vidioc_s_tuner(struct file *file, void *priv,
645 struct v4l2_tuner *vt) 635 struct v4l2_tuner *vt)
646{ 636{
647 struct usb_usbvision *usbvision = video_drvdata(file); 637 struct usb_usbvision *usbvision = video_drvdata(file);
648 638
649 // Only no or one tuner for now 639 /* Only no or one tuner for now */
650 if (!usbvision->have_tuner || vt->index) 640 if (!usbvision->have_tuner || vt->index)
651 return -EINVAL; 641 return -EINVAL;
652 /* let clients handle this */ 642 /* let clients handle this */
@@ -655,28 +645,27 @@ static int vidioc_s_tuner (struct file *file, void *priv,
655 return 0; 645 return 0;
656} 646}
657 647
658static int vidioc_g_frequency (struct file *file, void *priv, 648static int vidioc_g_frequency(struct file *file, void *priv,
659 struct v4l2_frequency *freq) 649 struct v4l2_frequency *freq)
660{ 650{
661 struct usb_usbvision *usbvision = video_drvdata(file); 651 struct usb_usbvision *usbvision = video_drvdata(file);
662 652
663 freq->tuner = 0; // Only one tuner 653 freq->tuner = 0; /* Only one tuner */
664 if(usbvision->radio) { 654 if (usbvision->radio)
665 freq->type = V4L2_TUNER_RADIO; 655 freq->type = V4L2_TUNER_RADIO;
666 } else { 656 else
667 freq->type = V4L2_TUNER_ANALOG_TV; 657 freq->type = V4L2_TUNER_ANALOG_TV;
668 }
669 freq->frequency = usbvision->freq; 658 freq->frequency = usbvision->freq;
670 659
671 return 0; 660 return 0;
672} 661}
673 662
674static int vidioc_s_frequency (struct file *file, void *priv, 663static int vidioc_s_frequency(struct file *file, void *priv,
675 struct v4l2_frequency *freq) 664 struct v4l2_frequency *freq)
676{ 665{
677 struct usb_usbvision *usbvision = video_drvdata(file); 666 struct usb_usbvision *usbvision = video_drvdata(file);
678 667
679 // Only no or one tuner for now 668 /* Only no or one tuner for now */
680 if (!usbvision->have_tuner || freq->tuner) 669 if (!usbvision->have_tuner || freq->tuner)
681 return -EINVAL; 670 return -EINVAL;
682 671
@@ -686,30 +675,27 @@ static int vidioc_s_frequency (struct file *file, void *priv,
686 return 0; 675 return 0;
687} 676}
688 677
689static int vidioc_g_audio (struct file *file, void *priv, struct v4l2_audio *a) 678static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a)
690{ 679{
691 struct usb_usbvision *usbvision = video_drvdata(file); 680 struct usb_usbvision *usbvision = video_drvdata(file);
692 681
693 if(usbvision->radio) { 682 if (usbvision->radio)
694 strcpy(a->name,"Radio"); 683 strcpy(a->name, "Radio");
695 } else { 684 else
696 strcpy(a->name, "TV"); 685 strcpy(a->name, "TV");
697 }
698 686
699 return 0; 687 return 0;
700} 688}
701 689
702static int vidioc_s_audio (struct file *file, void *fh, 690static int vidioc_s_audio(struct file *file, void *fh,
703 struct v4l2_audio *a) 691 struct v4l2_audio *a)
704{ 692{
705 if(a->index) { 693 if (a->index)
706 return -EINVAL; 694 return -EINVAL;
707 }
708
709 return 0; 695 return 0;
710} 696}
711 697
712static int vidioc_queryctrl (struct file *file, void *priv, 698static int vidioc_queryctrl(struct file *file, void *priv,
713 struct v4l2_queryctrl *ctrl) 699 struct v4l2_queryctrl *ctrl)
714{ 700{
715 struct usb_usbvision *usbvision = video_drvdata(file); 701 struct usb_usbvision *usbvision = video_drvdata(file);
@@ -722,52 +708,53 @@ static int vidioc_queryctrl (struct file *file, void *priv,
722 return 0; 708 return 0;
723} 709}
724 710
725static int vidioc_g_ctrl (struct file *file, void *priv, 711static int vidioc_g_ctrl(struct file *file, void *priv,
726 struct v4l2_control *ctrl) 712 struct v4l2_control *ctrl)
727{ 713{
728 struct usb_usbvision *usbvision = video_drvdata(file); 714 struct usb_usbvision *usbvision = video_drvdata(file);
729 call_all(usbvision, core, g_ctrl, ctrl);
730 715
716 call_all(usbvision, core, g_ctrl, ctrl);
731 return 0; 717 return 0;
732} 718}
733 719
734static int vidioc_s_ctrl (struct file *file, void *priv, 720static int vidioc_s_ctrl(struct file *file, void *priv,
735 struct v4l2_control *ctrl) 721 struct v4l2_control *ctrl)
736{ 722{
737 struct usb_usbvision *usbvision = video_drvdata(file); 723 struct usb_usbvision *usbvision = video_drvdata(file);
738 call_all(usbvision, core, s_ctrl, ctrl);
739 724
725 call_all(usbvision, core, s_ctrl, ctrl);
740 return 0; 726 return 0;
741} 727}
742 728
743static int vidioc_reqbufs (struct file *file, 729static int vidioc_reqbufs(struct file *file,
744 void *priv, struct v4l2_requestbuffers *vr) 730 void *priv, struct v4l2_requestbuffers *vr)
745{ 731{
746 struct usb_usbvision *usbvision = video_drvdata(file); 732 struct usb_usbvision *usbvision = video_drvdata(file);
747 int ret; 733 int ret;
748 734
749 RESTRICT_TO_RANGE(vr->count,1,USBVISION_NUMFRAMES); 735 RESTRICT_TO_RANGE(vr->count, 1, USBVISION_NUMFRAMES);
750 736
751 /* Check input validity: 737 /* Check input validity:
752 the user must do a VIDEO CAPTURE and MMAP method. */ 738 the user must do a VIDEO CAPTURE and MMAP method. */
753 if (vr->memory != V4L2_MEMORY_MMAP) 739 if (vr->memory != V4L2_MEMORY_MMAP)
754 return -EINVAL; 740 return -EINVAL;
755 741
756 if(usbvision->streaming == Stream_On) { 742 if (usbvision->streaming == stream_on) {
757 if ((ret = usbvision_stream_interrupt(usbvision))) 743 ret = usbvision_stream_interrupt(usbvision);
744 if (ret)
758 return ret; 745 return ret;
759 } 746 }
760 747
761 usbvision_frames_free(usbvision); 748 usbvision_frames_free(usbvision);
762 usbvision_empty_framequeues(usbvision); 749 usbvision_empty_framequeues(usbvision);
763 vr->count = usbvision_frames_alloc(usbvision,vr->count); 750 vr->count = usbvision_frames_alloc(usbvision, vr->count);
764 751
765 usbvision->curFrame = NULL; 752 usbvision->cur_frame = NULL;
766 753
767 return 0; 754 return 0;
768} 755}
769 756
770static int vidioc_querybuf (struct file *file, 757static int vidioc_querybuf(struct file *file,
771 void *priv, struct v4l2_buffer *vb) 758 void *priv, struct v4l2_buffer *vb)
772{ 759{
773 struct usb_usbvision *usbvision = video_drvdata(file); 760 struct usb_usbvision *usbvision = video_drvdata(file);
@@ -775,52 +762,49 @@ static int vidioc_querybuf (struct file *file,
775 762
776 /* FIXME : must control 763 /* FIXME : must control
777 that buffers are mapped (VIDIOC_REQBUFS has been called) */ 764 that buffers are mapped (VIDIOC_REQBUFS has been called) */
778 if(vb->index>=usbvision->num_frames) { 765 if (vb->index >= usbvision->num_frames)
779 return -EINVAL; 766 return -EINVAL;
780 }
781 /* Updating the corresponding frame state */ 767 /* Updating the corresponding frame state */
782 vb->flags = 0; 768 vb->flags = 0;
783 frame = &usbvision->frame[vb->index]; 769 frame = &usbvision->frame[vb->index];
784 if(frame->grabstate >= FrameState_Ready) 770 if (frame->grabstate >= frame_state_ready)
785 vb->flags |= V4L2_BUF_FLAG_QUEUED; 771 vb->flags |= V4L2_BUF_FLAG_QUEUED;
786 if(frame->grabstate >= FrameState_Done) 772 if (frame->grabstate >= frame_state_done)
787 vb->flags |= V4L2_BUF_FLAG_DONE; 773 vb->flags |= V4L2_BUF_FLAG_DONE;
788 if(frame->grabstate == FrameState_Unused) 774 if (frame->grabstate == frame_state_unused)
789 vb->flags |= V4L2_BUF_FLAG_MAPPED; 775 vb->flags |= V4L2_BUF_FLAG_MAPPED;
790 vb->memory = V4L2_MEMORY_MMAP; 776 vb->memory = V4L2_MEMORY_MMAP;
791 777
792 vb->m.offset = vb->index*PAGE_ALIGN(usbvision->max_frame_size); 778 vb->m.offset = vb->index * PAGE_ALIGN(usbvision->max_frame_size);
793 779
794 vb->memory = V4L2_MEMORY_MMAP; 780 vb->memory = V4L2_MEMORY_MMAP;
795 vb->field = V4L2_FIELD_NONE; 781 vb->field = V4L2_FIELD_NONE;
796 vb->length = usbvision->curwidth* 782 vb->length = usbvision->curwidth *
797 usbvision->curheight* 783 usbvision->curheight *
798 usbvision->palette.bytes_per_pixel; 784 usbvision->palette.bytes_per_pixel;
799 vb->timestamp = usbvision->frame[vb->index].timestamp; 785 vb->timestamp = usbvision->frame[vb->index].timestamp;
800 vb->sequence = usbvision->frame[vb->index].sequence; 786 vb->sequence = usbvision->frame[vb->index].sequence;
801 return 0; 787 return 0;
802} 788}
803 789
804static int vidioc_qbuf (struct file *file, void *priv, struct v4l2_buffer *vb) 790static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *vb)
805{ 791{
806 struct usb_usbvision *usbvision = video_drvdata(file); 792 struct usb_usbvision *usbvision = video_drvdata(file);
807 struct usbvision_frame *frame; 793 struct usbvision_frame *frame;
808 unsigned long lock_flags; 794 unsigned long lock_flags;
809 795
810 /* FIXME : works only on VIDEO_CAPTURE MODE, MMAP. */ 796 /* FIXME : works only on VIDEO_CAPTURE MODE, MMAP. */
811 if(vb->index>=usbvision->num_frames) { 797 if (vb->index >= usbvision->num_frames)
812 return -EINVAL; 798 return -EINVAL;
813 }
814 799
815 frame = &usbvision->frame[vb->index]; 800 frame = &usbvision->frame[vb->index];
816 801
817 if (frame->grabstate != FrameState_Unused) { 802 if (frame->grabstate != frame_state_unused)
818 return -EAGAIN; 803 return -EAGAIN;
819 }
820 804
821 /* Mark it as ready and enqueue frame */ 805 /* Mark it as ready and enqueue frame */
822 frame->grabstate = FrameState_Ready; 806 frame->grabstate = frame_state_ready;
823 frame->scanstate = ScanState_Scanning; 807 frame->scanstate = scan_state_scanning;
824 frame->scanlength = 0; /* Accumulated in usbvision_parse_data() */ 808 frame->scanlength = 0; /* Accumulated in usbvision_parse_data() */
825 809
826 vb->flags &= ~V4L2_BUF_FLAG_DONE; 810 vb->flags &= ~V4L2_BUF_FLAG_DONE;
@@ -835,7 +819,7 @@ static int vidioc_qbuf (struct file *file, void *priv, struct v4l2_buffer *vb)
835 return 0; 819 return 0;
836} 820}
837 821
838static int vidioc_dqbuf (struct file *file, void *priv, struct v4l2_buffer *vb) 822static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *vb)
839{ 823{
840 struct usb_usbvision *usbvision = video_drvdata(file); 824 struct usb_usbvision *usbvision = video_drvdata(file);
841 int ret; 825 int ret;
@@ -843,7 +827,7 @@ static int vidioc_dqbuf (struct file *file, void *priv, struct v4l2_buffer *vb)
843 unsigned long lock_flags; 827 unsigned long lock_flags;
844 828
845 if (list_empty(&(usbvision->outqueue))) { 829 if (list_empty(&(usbvision->outqueue))) {
846 if (usbvision->streaming == Stream_Idle) 830 if (usbvision->streaming == stream_idle)
847 return -EINVAL; 831 return -EINVAL;
848 ret = wait_event_interruptible 832 ret = wait_event_interruptible
849 (usbvision->wait_frame, 833 (usbvision->wait_frame,
@@ -858,7 +842,7 @@ static int vidioc_dqbuf (struct file *file, void *priv, struct v4l2_buffer *vb)
858 list_del(usbvision->outqueue.next); 842 list_del(usbvision->outqueue.next);
859 spin_unlock_irqrestore(&usbvision->queue_lock, lock_flags); 843 spin_unlock_irqrestore(&usbvision->queue_lock, lock_flags);
860 844
861 f->grabstate = FrameState_Unused; 845 f->grabstate = frame_state_unused;
862 846
863 vb->memory = V4L2_MEMORY_MMAP; 847 vb->memory = V4L2_MEMORY_MMAP;
864 vb->flags = V4L2_BUF_FLAG_MAPPED | 848 vb->flags = V4L2_BUF_FLAG_MAPPED |
@@ -877,7 +861,7 @@ static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
877{ 861{
878 struct usb_usbvision *usbvision = video_drvdata(file); 862 struct usb_usbvision *usbvision = video_drvdata(file);
879 863
880 usbvision->streaming = Stream_On; 864 usbvision->streaming = stream_on;
881 call_all(usbvision, video, s_stream, 1); 865 call_all(usbvision, video, s_stream, 1);
882 866
883 return 0; 867 return 0;
@@ -891,7 +875,7 @@ static int vidioc_streamoff(struct file *file,
891 if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 875 if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
892 return -EINVAL; 876 return -EINVAL;
893 877
894 if(usbvision->streaming == Stream_On) { 878 if (usbvision->streaming == stream_on) {
895 usbvision_stream_interrupt(usbvision); 879 usbvision_stream_interrupt(usbvision);
896 /* Stop all video streamings */ 880 /* Stop all video streamings */
897 call_all(usbvision, video, s_stream, 0); 881 call_all(usbvision, video, s_stream, 0);
@@ -901,18 +885,17 @@ static int vidioc_streamoff(struct file *file,
901 return 0; 885 return 0;
902} 886}
903 887
904static int vidioc_enum_fmt_vid_cap (struct file *file, void *priv, 888static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
905 struct v4l2_fmtdesc *vfd) 889 struct v4l2_fmtdesc *vfd)
906{ 890{
907 if(vfd->index>=USBVISION_SUPPORTED_PALETTES-1) { 891 if (vfd->index >= USBVISION_SUPPORTED_PALETTES - 1)
908 return -EINVAL; 892 return -EINVAL;
909 } 893 strcpy(vfd->description, usbvision_v4l2_format[vfd->index].desc);
910 strcpy(vfd->description,usbvision_v4l2_format[vfd->index].desc);
911 vfd->pixelformat = usbvision_v4l2_format[vfd->index].format; 894 vfd->pixelformat = usbvision_v4l2_format[vfd->index].format;
912 return 0; 895 return 0;
913} 896}
914 897
915static int vidioc_g_fmt_vid_cap (struct file *file, void *priv, 898static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
916 struct v4l2_format *vf) 899 struct v4l2_format *vf)
917{ 900{
918 struct usb_usbvision *usbvision = video_drvdata(file); 901 struct usb_usbvision *usbvision = video_drvdata(file);
@@ -920,32 +903,31 @@ static int vidioc_g_fmt_vid_cap (struct file *file, void *priv,
920 vf->fmt.pix.height = usbvision->curheight; 903 vf->fmt.pix.height = usbvision->curheight;
921 vf->fmt.pix.pixelformat = usbvision->palette.format; 904 vf->fmt.pix.pixelformat = usbvision->palette.format;
922 vf->fmt.pix.bytesperline = 905 vf->fmt.pix.bytesperline =
923 usbvision->curwidth*usbvision->palette.bytes_per_pixel; 906 usbvision->curwidth * usbvision->palette.bytes_per_pixel;
924 vf->fmt.pix.sizeimage = vf->fmt.pix.bytesperline*usbvision->curheight; 907 vf->fmt.pix.sizeimage = vf->fmt.pix.bytesperline * usbvision->curheight;
925 vf->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; 908 vf->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
926 vf->fmt.pix.field = V4L2_FIELD_NONE; /* Always progressive image */ 909 vf->fmt.pix.field = V4L2_FIELD_NONE; /* Always progressive image */
927 910
928 return 0; 911 return 0;
929} 912}
930 913
931static int vidioc_try_fmt_vid_cap (struct file *file, void *priv, 914static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
932 struct v4l2_format *vf) 915 struct v4l2_format *vf)
933{ 916{
934 struct usb_usbvision *usbvision = video_drvdata(file); 917 struct usb_usbvision *usbvision = video_drvdata(file);
935 int formatIdx; 918 int format_idx;
936 919
937 /* Find requested format in available ones */ 920 /* Find requested format in available ones */
938 for(formatIdx=0;formatIdx<USBVISION_SUPPORTED_PALETTES;formatIdx++) { 921 for (format_idx = 0; format_idx < USBVISION_SUPPORTED_PALETTES; format_idx++) {
939 if(vf->fmt.pix.pixelformat == 922 if (vf->fmt.pix.pixelformat ==
940 usbvision_v4l2_format[formatIdx].format) { 923 usbvision_v4l2_format[format_idx].format) {
941 usbvision->palette = usbvision_v4l2_format[formatIdx]; 924 usbvision->palette = usbvision_v4l2_format[format_idx];
942 break; 925 break;
943 } 926 }
944 } 927 }
945 /* robustness */ 928 /* robustness */
946 if(formatIdx == USBVISION_SUPPORTED_PALETTES) { 929 if (format_idx == USBVISION_SUPPORTED_PALETTES)
947 return -EINVAL; 930 return -EINVAL;
948 }
949 RESTRICT_TO_RANGE(vf->fmt.pix.width, MIN_FRAME_WIDTH, MAX_FRAME_WIDTH); 931 RESTRICT_TO_RANGE(vf->fmt.pix.width, MIN_FRAME_WIDTH, MAX_FRAME_WIDTH);
950 RESTRICT_TO_RANGE(vf->fmt.pix.height, MIN_FRAME_HEIGHT, MAX_FRAME_HEIGHT); 932 RESTRICT_TO_RANGE(vf->fmt.pix.height, MIN_FRAME_HEIGHT, MAX_FRAME_HEIGHT);
951 933
@@ -962,24 +944,23 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
962 struct usb_usbvision *usbvision = video_drvdata(file); 944 struct usb_usbvision *usbvision = video_drvdata(file);
963 int ret; 945 int ret;
964 946
965 if( 0 != (ret=vidioc_try_fmt_vid_cap (file, priv, vf)) ) { 947 ret = vidioc_try_fmt_vid_cap(file, priv, vf);
948 if (ret)
966 return ret; 949 return ret;
967 }
968 950
969 /* stop io in case it is already in progress */ 951 /* stop io in case it is already in progress */
970 if(usbvision->streaming == Stream_On) { 952 if (usbvision->streaming == stream_on) {
971 if ((ret = usbvision_stream_interrupt(usbvision))) 953 ret = usbvision_stream_interrupt(usbvision);
954 if (ret)
972 return ret; 955 return ret;
973 } 956 }
974 usbvision_frames_free(usbvision); 957 usbvision_frames_free(usbvision);
975 usbvision_empty_framequeues(usbvision); 958 usbvision_empty_framequeues(usbvision);
976 959
977 usbvision->curFrame = NULL; 960 usbvision->cur_frame = NULL;
978 961
979 /* by now we are committed to the new data... */ 962 /* by now we are committed to the new data... */
980 mutex_lock(&usbvision->lock);
981 usbvision_set_output(usbvision, vf->fmt.pix.width, vf->fmt.pix.height); 963 usbvision_set_output(usbvision, vf->fmt.pix.width, vf->fmt.pix.height);
982 mutex_unlock(&usbvision->lock);
983 964
984 return 0; 965 return 0;
985} 966}
@@ -990,8 +971,7 @@ static ssize_t usbvision_v4l2_read(struct file *file, char __user *buf,
990 struct usb_usbvision *usbvision = video_drvdata(file); 971 struct usb_usbvision *usbvision = video_drvdata(file);
991 int noblock = file->f_flags & O_NONBLOCK; 972 int noblock = file->f_flags & O_NONBLOCK;
992 unsigned long lock_flags; 973 unsigned long lock_flags;
993 974 int ret, i;
994 int ret,i;
995 struct usbvision_frame *frame; 975 struct usbvision_frame *frame;
996 976
997 PDEBUG(DBG_IO, "%s: %ld bytes, noblock=%d", __func__, 977 PDEBUG(DBG_IO, "%s: %ld bytes, noblock=%d", __func__,
@@ -1003,28 +983,28 @@ static ssize_t usbvision_v4l2_read(struct file *file, char __user *buf,
1003 /* This entry point is compatible with the mmap routines 983 /* This entry point is compatible with the mmap routines
1004 so that a user can do either VIDIOC_QBUF/VIDIOC_DQBUF 984 so that a user can do either VIDIOC_QBUF/VIDIOC_DQBUF
1005 to get frames or call read on the device. */ 985 to get frames or call read on the device. */
1006 if(!usbvision->num_frames) { 986 if (!usbvision->num_frames) {
1007 /* First, allocate some frames to work with 987 /* First, allocate some frames to work with
1008 if this has not been done with VIDIOC_REQBUF */ 988 if this has not been done with VIDIOC_REQBUF */
1009 usbvision_frames_free(usbvision); 989 usbvision_frames_free(usbvision);
1010 usbvision_empty_framequeues(usbvision); 990 usbvision_empty_framequeues(usbvision);
1011 usbvision_frames_alloc(usbvision,USBVISION_NUMFRAMES); 991 usbvision_frames_alloc(usbvision, USBVISION_NUMFRAMES);
1012 } 992 }
1013 993
1014 if(usbvision->streaming != Stream_On) { 994 if (usbvision->streaming != stream_on) {
1015 /* no stream is running, make it running ! */ 995 /* no stream is running, make it running ! */
1016 usbvision->streaming = Stream_On; 996 usbvision->streaming = stream_on;
1017 call_all(usbvision, video, s_stream, 1); 997 call_all(usbvision, video, s_stream, 1);
1018 } 998 }
1019 999
1020 /* Then, enqueue as many frames as possible 1000 /* Then, enqueue as many frames as possible
1021 (like a user of VIDIOC_QBUF would do) */ 1001 (like a user of VIDIOC_QBUF would do) */
1022 for(i=0;i<usbvision->num_frames;i++) { 1002 for (i = 0; i < usbvision->num_frames; i++) {
1023 frame = &usbvision->frame[i]; 1003 frame = &usbvision->frame[i];
1024 if(frame->grabstate == FrameState_Unused) { 1004 if (frame->grabstate == frame_state_unused) {
1025 /* Mark it as ready and enqueue frame */ 1005 /* Mark it as ready and enqueue frame */
1026 frame->grabstate = FrameState_Ready; 1006 frame->grabstate = frame_state_ready;
1027 frame->scanstate = ScanState_Scanning; 1007 frame->scanstate = scan_state_scanning;
1028 /* Accumulated in usbvision_parse_data() */ 1008 /* Accumulated in usbvision_parse_data() */
1029 frame->scanlength = 0; 1009 frame->scanlength = 0;
1030 1010
@@ -1040,7 +1020,7 @@ static ssize_t usbvision_v4l2_read(struct file *file, char __user *buf,
1040 1020
1041 /* Then try to steal a frame (like a VIDIOC_DQBUF would do) */ 1021 /* Then try to steal a frame (like a VIDIOC_DQBUF would do) */
1042 if (list_empty(&(usbvision->outqueue))) { 1022 if (list_empty(&(usbvision->outqueue))) {
1043 if(noblock) 1023 if (noblock)
1044 return -EAGAIN; 1024 return -EAGAIN;
1045 1025
1046 ret = wait_event_interruptible 1026 ret = wait_event_interruptible
@@ -1057,7 +1037,7 @@ static ssize_t usbvision_v4l2_read(struct file *file, char __user *buf,
1057 spin_unlock_irqrestore(&usbvision->queue_lock, lock_flags); 1037 spin_unlock_irqrestore(&usbvision->queue_lock, lock_flags);
1058 1038
1059 /* An error returns an empty frame */ 1039 /* An error returns an empty frame */
1060 if (frame->grabstate == FrameState_Error) { 1040 if (frame->grabstate == frame_state_error) {
1061 frame->bytes_read = 0; 1041 frame->bytes_read = 0;
1062 return 0; 1042 return 0;
1063 } 1043 }
@@ -1070,9 +1050,8 @@ static ssize_t usbvision_v4l2_read(struct file *file, char __user *buf,
1070 if ((count + frame->bytes_read) > (unsigned long)frame->scanlength) 1050 if ((count + frame->bytes_read) > (unsigned long)frame->scanlength)
1071 count = frame->scanlength - frame->bytes_read; 1051 count = frame->scanlength - frame->bytes_read;
1072 1052
1073 if (copy_to_user(buf, frame->data + frame->bytes_read, count)) { 1053 if (copy_to_user(buf, frame->data + frame->bytes_read, count))
1074 return -EFAULT; 1054 return -EFAULT;
1075 }
1076 1055
1077 frame->bytes_read += count; 1056 frame->bytes_read += count;
1078 PDEBUG(DBG_IO, "%s: {copy} count used=%ld, new bytes_read=%ld", 1057 PDEBUG(DBG_IO, "%s: {copy} count used=%ld, new bytes_read=%ld",
@@ -1080,12 +1059,12 @@ static ssize_t usbvision_v4l2_read(struct file *file, char __user *buf,
1080 (unsigned long)count, frame->bytes_read); 1059 (unsigned long)count, frame->bytes_read);
1081 1060
1082 /* For now, forget the frame if it has not been read in one shot. */ 1061 /* For now, forget the frame if it has not been read in one shot. */
1083/* if (frame->bytes_read >= frame->scanlength) {// All data has been read */ 1062/* if (frame->bytes_read >= frame->scanlength) {*/ /* All data has been read */
1084 frame->bytes_read = 0; 1063 frame->bytes_read = 0;
1085 1064
1086 /* Mark it as available to be used again. */ 1065 /* Mark it as available to be used again. */
1087 frame->grabstate = FrameState_Unused; 1066 frame->grabstate = frame_state_unused;
1088/* } */ 1067/* } */
1089 1068
1090 return count; 1069 return count;
1091} 1070}
@@ -1100,16 +1079,11 @@ static int usbvision_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
1100 1079
1101 PDEBUG(DBG_MMAP, "mmap"); 1080 PDEBUG(DBG_MMAP, "mmap");
1102 1081
1103 mutex_lock(&usbvision->lock); 1082 if (!USBVISION_IS_OPERATIONAL(usbvision))
1104
1105 if (!USBVISION_IS_OPERATIONAL(usbvision)) {
1106 mutex_unlock(&usbvision->lock);
1107 return -EFAULT; 1083 return -EFAULT;
1108 }
1109 1084
1110 if (!(vma->vm_flags & VM_WRITE) || 1085 if (!(vma->vm_flags & VM_WRITE) ||
1111 size != PAGE_ALIGN(usbvision->max_frame_size)) { 1086 size != PAGE_ALIGN(usbvision->max_frame_size)) {
1112 mutex_unlock(&usbvision->lock);
1113 return -EINVAL; 1087 return -EINVAL;
1114 } 1088 }
1115 1089
@@ -1121,7 +1095,6 @@ static int usbvision_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
1121 if (i == usbvision->num_frames) { 1095 if (i == usbvision->num_frames) {
1122 PDEBUG(DBG_MMAP, 1096 PDEBUG(DBG_MMAP,
1123 "mmap: user supplied mapping address is out of range"); 1097 "mmap: user supplied mapping address is out of range");
1124 mutex_unlock(&usbvision->lock);
1125 return -EINVAL; 1098 return -EINVAL;
1126 } 1099 }
1127 1100
@@ -1131,10 +1104,8 @@ static int usbvision_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
1131 1104
1132 pos = usbvision->frame[i].data; 1105 pos = usbvision->frame[i].data;
1133 while (size > 0) { 1106 while (size > 0) {
1134
1135 if (vm_insert_page(vma, start, vmalloc_to_page(pos))) { 1107 if (vm_insert_page(vma, start, vmalloc_to_page(pos))) {
1136 PDEBUG(DBG_MMAP, "mmap: vm_insert_page failed"); 1108 PDEBUG(DBG_MMAP, "mmap: vm_insert_page failed");
1137 mutex_unlock(&usbvision->lock);
1138 return -EAGAIN; 1109 return -EAGAIN;
1139 } 1110 }
1140 start += PAGE_SIZE; 1111 start += PAGE_SIZE;
@@ -1142,7 +1113,6 @@ static int usbvision_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
1142 size -= PAGE_SIZE; 1113 size -= PAGE_SIZE;
1143 } 1114 }
1144 1115
1145 mutex_unlock(&usbvision->lock);
1146 return 0; 1116 return 0;
1147} 1117}
1148 1118
@@ -1154,21 +1124,18 @@ static int usbvision_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
1154static int usbvision_radio_open(struct file *file) 1124static int usbvision_radio_open(struct file *file)
1155{ 1125{
1156 struct usb_usbvision *usbvision = video_drvdata(file); 1126 struct usb_usbvision *usbvision = video_drvdata(file);
1157 int errCode = 0; 1127 int err_code = 0;
1158 1128
1159 PDEBUG(DBG_IO, "%s:", __func__); 1129 PDEBUG(DBG_IO, "%s:", __func__);
1160 1130
1161 mutex_lock(&usbvision->lock);
1162
1163 if (usbvision->user) { 1131 if (usbvision->user) {
1164 dev_err(&usbvision->rdev->dev, 1132 dev_err(&usbvision->rdev->dev,
1165 "%s: Someone tried to open an already opened USBVision Radio!\n", 1133 "%s: Someone tried to open an already opened USBVision Radio!\n",
1166 __func__); 1134 __func__);
1167 errCode = -EBUSY; 1135 err_code = -EBUSY;
1168 } 1136 } else {
1169 else { 1137 if (power_on_at_open) {
1170 if(PowerOnAtOpen) { 1138 usbvision_reset_power_off_timer(usbvision);
1171 usbvision_reset_powerOffTimer(usbvision);
1172 if (usbvision->power == 0) { 1139 if (usbvision->power == 0) {
1173 usbvision_power_on(usbvision); 1140 usbvision_power_on(usbvision);
1174 usbvision_i2c_register(usbvision); 1141 usbvision_i2c_register(usbvision);
@@ -1176,80 +1143,73 @@ static int usbvision_radio_open(struct file *file)
1176 } 1143 }
1177 1144
1178 /* Alternate interface 1 is is the biggest frame size */ 1145 /* Alternate interface 1 is is the biggest frame size */
1179 errCode = usbvision_set_alternate(usbvision); 1146 err_code = usbvision_set_alternate(usbvision);
1180 if (errCode < 0) { 1147 if (err_code < 0) {
1181 usbvision->last_error = errCode; 1148 usbvision->last_error = err_code;
1182 errCode = -EBUSY; 1149 err_code = -EBUSY;
1183 goto out; 1150 goto out;
1184 } 1151 }
1185 1152
1186 // If so far no errors then we shall start the radio 1153 /* If so far no errors then we shall start the radio */
1187 usbvision->radio = 1; 1154 usbvision->radio = 1;
1188 call_all(usbvision, tuner, s_radio); 1155 call_all(usbvision, tuner, s_radio);
1189 usbvision_set_audio(usbvision, USBVISION_AUDIO_RADIO); 1156 usbvision_set_audio(usbvision, USBVISION_AUDIO_RADIO);
1190 usbvision->user++; 1157 usbvision->user++;
1191 } 1158 }
1192 1159
1193 if (errCode) { 1160 if (err_code) {
1194 if (PowerOnAtOpen) { 1161 if (power_on_at_open) {
1195 usbvision_i2c_unregister(usbvision); 1162 usbvision_i2c_unregister(usbvision);
1196 usbvision_power_off(usbvision); 1163 usbvision_power_off(usbvision);
1197 usbvision->initialized = 0; 1164 usbvision->initialized = 0;
1198 } 1165 }
1199 } 1166 }
1200out: 1167out:
1201 mutex_unlock(&usbvision->lock); 1168 return err_code;
1202 return errCode;
1203} 1169}
1204 1170
1205 1171
1206static int usbvision_radio_close(struct file *file) 1172static int usbvision_radio_close(struct file *file)
1207{ 1173{
1208 struct usb_usbvision *usbvision = video_drvdata(file); 1174 struct usb_usbvision *usbvision = video_drvdata(file);
1209 int errCode = 0; 1175 int err_code = 0;
1210 1176
1211 PDEBUG(DBG_IO, ""); 1177 PDEBUG(DBG_IO, "");
1212 1178
1213 mutex_lock(&usbvision->lock);
1214
1215 /* Set packet size to 0 */ 1179 /* Set packet size to 0 */
1216 usbvision->ifaceAlt=0; 1180 usbvision->iface_alt = 0;
1217 errCode = usb_set_interface(usbvision->dev, usbvision->iface, 1181 err_code = usb_set_interface(usbvision->dev, usbvision->iface,
1218 usbvision->ifaceAlt); 1182 usbvision->iface_alt);
1219 1183
1220 usbvision_audio_off(usbvision); 1184 usbvision_audio_off(usbvision);
1221 usbvision->radio=0; 1185 usbvision->radio = 0;
1222 usbvision->user--; 1186 usbvision->user--;
1223 1187
1224 if (PowerOnAtOpen) { 1188 if (power_on_at_open) {
1225 usbvision_set_powerOffTimer(usbvision); 1189 usbvision_set_power_off_timer(usbvision);
1226 usbvision->initialized = 0; 1190 usbvision->initialized = 0;
1227 } 1191 }
1228 1192
1229 mutex_unlock(&usbvision->lock);
1230
1231 if (usbvision->remove_pending) { 1193 if (usbvision->remove_pending) {
1232 printk(KERN_INFO "%s: Final disconnect\n", __func__); 1194 printk(KERN_INFO "%s: Final disconnect\n", __func__);
1233 usbvision_release(usbvision); 1195 usbvision_release(usbvision);
1234 } 1196 }
1235 1197
1236 PDEBUG(DBG_IO, "success"); 1198 PDEBUG(DBG_IO, "success");
1237 return errCode; 1199 return err_code;
1238} 1200}
1239 1201
1240// 1202/* Video registration stuff */
1241// Video registration stuff
1242//
1243 1203
1244// Video template 1204/* Video template */
1245static const struct v4l2_file_operations usbvision_fops = { 1205static const struct v4l2_file_operations usbvision_fops = {
1246 .owner = THIS_MODULE, 1206 .owner = THIS_MODULE,
1247 .open = usbvision_v4l2_open, 1207 .open = usbvision_v4l2_open,
1248 .release = usbvision_v4l2_close, 1208 .release = usbvision_v4l2_close,
1249 .read = usbvision_v4l2_read, 1209 .read = usbvision_v4l2_read,
1250 .mmap = usbvision_v4l2_mmap, 1210 .mmap = usbvision_v4l2_mmap,
1251 .ioctl = video_ioctl2, 1211 .unlocked_ioctl = video_ioctl2,
1252/* .poll = video_poll, */ 1212/* .poll = video_poll, */
1253}; 1213};
1254 1214
1255static const struct v4l2_ioctl_ops usbvision_ioctl_ops = { 1215static const struct v4l2_ioctl_ops usbvision_ioctl_ops = {
@@ -1273,9 +1233,6 @@ static const struct v4l2_ioctl_ops usbvision_ioctl_ops = {
1273 .vidioc_s_ctrl = vidioc_s_ctrl, 1233 .vidioc_s_ctrl = vidioc_s_ctrl,
1274 .vidioc_streamon = vidioc_streamon, 1234 .vidioc_streamon = vidioc_streamon,
1275 .vidioc_streamoff = vidioc_streamoff, 1235 .vidioc_streamoff = vidioc_streamoff,
1276#ifdef CONFIG_VIDEO_V4L1_COMPAT
1277/* .vidiocgmbuf = vidiocgmbuf, */
1278#endif
1279 .vidioc_g_tuner = vidioc_g_tuner, 1236 .vidioc_g_tuner = vidioc_g_tuner,
1280 .vidioc_s_tuner = vidioc_s_tuner, 1237 .vidioc_s_tuner = vidioc_s_tuner,
1281 .vidioc_g_frequency = vidioc_g_frequency, 1238 .vidioc_g_frequency = vidioc_g_frequency,
@@ -1288,20 +1245,20 @@ static const struct v4l2_ioctl_ops usbvision_ioctl_ops = {
1288 1245
1289static struct video_device usbvision_video_template = { 1246static struct video_device usbvision_video_template = {
1290 .fops = &usbvision_fops, 1247 .fops = &usbvision_fops,
1291 .ioctl_ops = &usbvision_ioctl_ops, 1248 .ioctl_ops = &usbvision_ioctl_ops,
1292 .name = "usbvision-video", 1249 .name = "usbvision-video",
1293 .release = video_device_release, 1250 .release = video_device_release,
1294 .tvnorms = USBVISION_NORMS, 1251 .tvnorms = USBVISION_NORMS,
1295 .current_norm = V4L2_STD_PAL 1252 .current_norm = V4L2_STD_PAL
1296}; 1253};
1297 1254
1298 1255
1299// Radio template 1256/* Radio template */
1300static const struct v4l2_file_operations usbvision_radio_fops = { 1257static const struct v4l2_file_operations usbvision_radio_fops = {
1301 .owner = THIS_MODULE, 1258 .owner = THIS_MODULE,
1302 .open = usbvision_radio_open, 1259 .open = usbvision_radio_open,
1303 .release = usbvision_radio_close, 1260 .release = usbvision_radio_close,
1304 .ioctl = video_ioctl2, 1261 .unlocked_ioctl = video_ioctl2,
1305}; 1262};
1306 1263
1307static const struct v4l2_ioctl_ops usbvision_radio_ioctl_ops = { 1264static const struct v4l2_ioctl_ops usbvision_radio_ioctl_ops = {
@@ -1322,9 +1279,9 @@ static const struct v4l2_ioctl_ops usbvision_radio_ioctl_ops = {
1322 1279
1323static struct video_device usbvision_radio_template = { 1280static struct video_device usbvision_radio_template = {
1324 .fops = &usbvision_radio_fops, 1281 .fops = &usbvision_radio_fops,
1325 .name = "usbvision-radio", 1282 .name = "usbvision-radio",
1326 .release = video_device_release, 1283 .release = video_device_release,
1327 .ioctl_ops = &usbvision_radio_ioctl_ops, 1284 .ioctl_ops = &usbvision_radio_ioctl_ops,
1328 1285
1329 .tvnorms = USBVISION_NORMS, 1286 .tvnorms = USBVISION_NORMS,
1330 .current_norm = V4L2_STD_PAL 1287 .current_norm = V4L2_STD_PAL
@@ -1345,80 +1302,70 @@ static struct video_device *usbvision_vdev_init(struct usb_usbvision *usbvision,
1345 } 1302 }
1346 1303
1347 vdev = video_device_alloc(); 1304 vdev = video_device_alloc();
1348 if (NULL == vdev) { 1305 if (NULL == vdev)
1349 return NULL; 1306 return NULL;
1350 }
1351 *vdev = *vdev_template; 1307 *vdev = *vdev_template;
1308 vdev->lock = &usbvision->v4l2_lock;
1352 vdev->v4l2_dev = &usbvision->v4l2_dev; 1309 vdev->v4l2_dev = &usbvision->v4l2_dev;
1353 snprintf(vdev->name, sizeof(vdev->name), "%s", name); 1310 snprintf(vdev->name, sizeof(vdev->name), "%s", name);
1354 video_set_drvdata(vdev, usbvision); 1311 video_set_drvdata(vdev, usbvision);
1355 return vdev; 1312 return vdev;
1356} 1313}
1357 1314
1358// unregister video4linux devices 1315/* unregister video4linux devices */
1359static void usbvision_unregister_video(struct usb_usbvision *usbvision) 1316static void usbvision_unregister_video(struct usb_usbvision *usbvision)
1360{ 1317{
1361 // Radio Device: 1318 /* Radio Device: */
1362 if (usbvision->rdev) { 1319 if (usbvision->rdev) {
1363 PDEBUG(DBG_PROBE, "unregister %s [v4l2]", 1320 PDEBUG(DBG_PROBE, "unregister %s [v4l2]",
1364 video_device_node_name(usbvision->rdev)); 1321 video_device_node_name(usbvision->rdev));
1365 if (video_is_registered(usbvision->rdev)) { 1322 if (video_is_registered(usbvision->rdev))
1366 video_unregister_device(usbvision->rdev); 1323 video_unregister_device(usbvision->rdev);
1367 } else { 1324 else
1368 video_device_release(usbvision->rdev); 1325 video_device_release(usbvision->rdev);
1369 }
1370 usbvision->rdev = NULL; 1326 usbvision->rdev = NULL;
1371 } 1327 }
1372 1328
1373 // Video Device: 1329 /* Video Device: */
1374 if (usbvision->vdev) { 1330 if (usbvision->vdev) {
1375 PDEBUG(DBG_PROBE, "unregister %s [v4l2]", 1331 PDEBUG(DBG_PROBE, "unregister %s [v4l2]",
1376 video_device_node_name(usbvision->vdev)); 1332 video_device_node_name(usbvision->vdev));
1377 if (video_is_registered(usbvision->vdev)) { 1333 if (video_is_registered(usbvision->vdev))
1378 video_unregister_device(usbvision->vdev); 1334 video_unregister_device(usbvision->vdev);
1379 } else { 1335 else
1380 video_device_release(usbvision->vdev); 1336 video_device_release(usbvision->vdev);
1381 }
1382 usbvision->vdev = NULL; 1337 usbvision->vdev = NULL;
1383 } 1338 }
1384} 1339}
1385 1340
1386// register video4linux devices 1341/* register video4linux devices */
1387static int __devinit usbvision_register_video(struct usb_usbvision *usbvision) 1342static int __devinit usbvision_register_video(struct usb_usbvision *usbvision)
1388{ 1343{
1389 // Video Device: 1344 /* Video Device: */
1390 usbvision->vdev = usbvision_vdev_init(usbvision, 1345 usbvision->vdev = usbvision_vdev_init(usbvision,
1391 &usbvision_video_template, 1346 &usbvision_video_template,
1392 "USBVision Video"); 1347 "USBVision Video");
1393 if (usbvision->vdev == NULL) { 1348 if (usbvision->vdev == NULL)
1394 goto err_exit; 1349 goto err_exit;
1395 } 1350 if (video_register_device(usbvision->vdev, VFL_TYPE_GRABBER, video_nr) < 0)
1396 if (video_register_device(usbvision->vdev,
1397 VFL_TYPE_GRABBER,
1398 video_nr)<0) {
1399 goto err_exit; 1351 goto err_exit;
1400 }
1401 printk(KERN_INFO "USBVision[%d]: registered USBVision Video device %s [v4l2]\n", 1352 printk(KERN_INFO "USBVision[%d]: registered USBVision Video device %s [v4l2]\n",
1402 usbvision->nr, video_device_node_name(usbvision->vdev)); 1353 usbvision->nr, video_device_node_name(usbvision->vdev));
1403 1354
1404 // Radio Device: 1355 /* Radio Device: */
1405 if (usbvision_device_data[usbvision->DevModel].Radio) { 1356 if (usbvision_device_data[usbvision->dev_model].radio) {
1406 // usbvision has radio 1357 /* usbvision has radio */
1407 usbvision->rdev = usbvision_vdev_init(usbvision, 1358 usbvision->rdev = usbvision_vdev_init(usbvision,
1408 &usbvision_radio_template, 1359 &usbvision_radio_template,
1409 "USBVision Radio"); 1360 "USBVision Radio");
1410 if (usbvision->rdev == NULL) { 1361 if (usbvision->rdev == NULL)
1411 goto err_exit; 1362 goto err_exit;
1412 } 1363 if (video_register_device(usbvision->rdev, VFL_TYPE_RADIO, radio_nr) < 0)
1413 if (video_register_device(usbvision->rdev,
1414 VFL_TYPE_RADIO,
1415 radio_nr)<0) {
1416 goto err_exit; 1364 goto err_exit;
1417 }
1418 printk(KERN_INFO "USBVision[%d]: registered USBVision Radio device %s [v4l2]\n", 1365 printk(KERN_INFO "USBVision[%d]: registered USBVision Radio device %s [v4l2]\n",
1419 usbvision->nr, video_device_node_name(usbvision->rdev)); 1366 usbvision->nr, video_device_node_name(usbvision->rdev));
1420 } 1367 }
1421 // all done 1368 /* all done */
1422 return 0; 1369 return 0;
1423 1370
1424 err_exit: 1371 err_exit:
@@ -1451,15 +1398,15 @@ static struct usb_usbvision *usbvision_alloc(struct usb_device *dev,
1451 if (v4l2_device_register(&intf->dev, &usbvision->v4l2_dev)) 1398 if (v4l2_device_register(&intf->dev, &usbvision->v4l2_dev))
1452 goto err_free; 1399 goto err_free;
1453 1400
1454 mutex_init(&usbvision->lock); /* available */ 1401 mutex_init(&usbvision->v4l2_lock);
1455 1402
1456 // prepare control urb for control messages during interrupts 1403 /* prepare control urb for control messages during interrupts */
1457 usbvision->ctrlUrb = usb_alloc_urb(USBVISION_URB_FRAMES, GFP_KERNEL); 1404 usbvision->ctrl_urb = usb_alloc_urb(USBVISION_URB_FRAMES, GFP_KERNEL);
1458 if (usbvision->ctrlUrb == NULL) 1405 if (usbvision->ctrl_urb == NULL)
1459 goto err_unreg; 1406 goto err_unreg;
1460 init_waitqueue_head(&usbvision->ctrlUrb_wq); 1407 init_waitqueue_head(&usbvision->ctrl_urb_wq);
1461 1408
1462 usbvision_init_powerOffTimer(usbvision); 1409 usbvision_init_power_off_timer(usbvision);
1463 1410
1464 return usbvision; 1411 return usbvision;
1465 1412
@@ -1481,20 +1428,14 @@ static void usbvision_release(struct usb_usbvision *usbvision)
1481{ 1428{
1482 PDEBUG(DBG_PROBE, ""); 1429 PDEBUG(DBG_PROBE, "");
1483 1430
1484 mutex_lock(&usbvision->lock); 1431 usbvision_reset_power_off_timer(usbvision);
1485
1486 usbvision_reset_powerOffTimer(usbvision);
1487 1432
1488 usbvision->initialized = 0; 1433 usbvision->initialized = 0;
1489 1434
1490 mutex_unlock(&usbvision->lock);
1491
1492 usbvision_remove_sysfs(usbvision->vdev); 1435 usbvision_remove_sysfs(usbvision->vdev);
1493 usbvision_unregister_video(usbvision); 1436 usbvision_unregister_video(usbvision);
1494 1437
1495 if (usbvision->ctrlUrb) { 1438 usb_free_urb(usbvision->ctrl_urb);
1496 usb_free_urb(usbvision->ctrlUrb);
1497 }
1498 1439
1499 v4l2_device_unregister(&usbvision->v4l2_dev); 1440 v4l2_device_unregister(&usbvision->v4l2_dev);
1500 kfree(usbvision); 1441 kfree(usbvision);
@@ -1512,25 +1453,25 @@ static void usbvision_configure_video(struct usb_usbvision *usbvision)
1512 if (usbvision == NULL) 1453 if (usbvision == NULL)
1513 return; 1454 return;
1514 1455
1515 model = usbvision->DevModel; 1456 model = usbvision->dev_model;
1516 usbvision->palette = usbvision_v4l2_format[2]; // V4L2_PIX_FMT_RGB24; 1457 usbvision->palette = usbvision_v4l2_format[2]; /* V4L2_PIX_FMT_RGB24; */
1517 1458
1518 if (usbvision_device_data[usbvision->DevModel].Vin_Reg2_override) { 1459 if (usbvision_device_data[usbvision->dev_model].vin_reg2_override) {
1519 usbvision->Vin_Reg2_Preset = 1460 usbvision->vin_reg2_preset =
1520 usbvision_device_data[usbvision->DevModel].Vin_Reg2; 1461 usbvision_device_data[usbvision->dev_model].vin_reg2;
1521 } else { 1462 } else {
1522 usbvision->Vin_Reg2_Preset = 0; 1463 usbvision->vin_reg2_preset = 0;
1523 } 1464 }
1524 1465
1525 usbvision->tvnormId = usbvision_device_data[model].VideoNorm; 1466 usbvision->tvnorm_id = usbvision_device_data[model].video_norm;
1526 1467
1527 usbvision->video_inputs = usbvision_device_data[model].VideoChannels; 1468 usbvision->video_inputs = usbvision_device_data[model].video_channels;
1528 usbvision->ctl_input = 0; 1469 usbvision->ctl_input = 0;
1529 1470
1530 /* This should be here to make i2c clients to be able to register */ 1471 /* This should be here to make i2c clients to be able to register */
1531 /* first switch off audio */ 1472 /* first switch off audio */
1532 usbvision_audio_off(usbvision); 1473 usbvision_audio_off(usbvision);
1533 if (!PowerOnAtOpen) { 1474 if (!power_on_at_open) {
1534 /* and then power up the noisy tuner */ 1475 /* and then power up the noisy tuner */
1535 usbvision_power_on(usbvision); 1476 usbvision_power_on(usbvision);
1536 usbvision_i2c_register(usbvision); 1477 usbvision_i2c_register(usbvision);
@@ -1553,25 +1494,24 @@ static int __devinit usbvision_probe(struct usb_interface *intf,
1553 const struct usb_host_interface *interface; 1494 const struct usb_host_interface *interface;
1554 struct usb_usbvision *usbvision = NULL; 1495 struct usb_usbvision *usbvision = NULL;
1555 const struct usb_endpoint_descriptor *endpoint; 1496 const struct usb_endpoint_descriptor *endpoint;
1556 int model,i; 1497 int model, i;
1557 1498
1558 PDEBUG(DBG_PROBE, "VID=%#04x, PID=%#04x, ifnum=%u", 1499 PDEBUG(DBG_PROBE, "VID=%#04x, PID=%#04x, ifnum=%u",
1559 dev->descriptor.idVendor, 1500 dev->descriptor.idVendor,
1560 dev->descriptor.idProduct, ifnum); 1501 dev->descriptor.idProduct, ifnum);
1561 1502
1562 model = devid->driver_info; 1503 model = devid->driver_info;
1563 if ( (model<0) || (model>=usbvision_device_data_size) ) { 1504 if (model < 0 || model >= usbvision_device_data_size) {
1564 PDEBUG(DBG_PROBE, "model out of bounds %d",model); 1505 PDEBUG(DBG_PROBE, "model out of bounds %d", model);
1565 return -ENODEV; 1506 return -ENODEV;
1566 } 1507 }
1567 printk(KERN_INFO "%s: %s found\n", __func__, 1508 printk(KERN_INFO "%s: %s found\n", __func__,
1568 usbvision_device_data[model].ModelString); 1509 usbvision_device_data[model].model_string);
1569 1510
1570 if (usbvision_device_data[model].Interface >= 0) { 1511 if (usbvision_device_data[model].interface >= 0)
1571 interface = &dev->actconfig->interface[usbvision_device_data[model].Interface]->altsetting[0]; 1512 interface = &dev->actconfig->interface[usbvision_device_data[model].interface]->altsetting[0];
1572 } else { 1513 else
1573 interface = &dev->actconfig->interface[ifnum]->altsetting[0]; 1514 interface = &dev->actconfig->interface[ifnum]->altsetting[0];
1574 }
1575 endpoint = &interface->endpoint[1].desc; 1515 endpoint = &interface->endpoint[1].desc;
1576 if (!usb_endpoint_xfer_isoc(endpoint)) { 1516 if (!usb_endpoint_xfer_isoc(endpoint)) {
1577 dev_err(&intf->dev, "%s: interface %d. has non-ISO endpoint!\n", 1517 dev_err(&intf->dev, "%s: interface %d. has non-ISO endpoint!\n",
@@ -1592,59 +1532,52 @@ static int __devinit usbvision_probe(struct usb_interface *intf,
1592 return -ENOMEM; 1532 return -ENOMEM;
1593 } 1533 }
1594 1534
1595 if (dev->descriptor.bNumConfigurations > 1) { 1535 if (dev->descriptor.bNumConfigurations > 1)
1596 usbvision->bridgeType = BRIDGE_NT1004; 1536 usbvision->bridge_type = BRIDGE_NT1004;
1597 } else if (model == DAZZLE_DVC_90_REV_1_SECAM) { 1537 else if (model == DAZZLE_DVC_90_REV_1_SECAM)
1598 usbvision->bridgeType = BRIDGE_NT1005; 1538 usbvision->bridge_type = BRIDGE_NT1005;
1599 } else { 1539 else
1600 usbvision->bridgeType = BRIDGE_NT1003; 1540 usbvision->bridge_type = BRIDGE_NT1003;
1601 } 1541 PDEBUG(DBG_PROBE, "bridge_type %d", usbvision->bridge_type);
1602 PDEBUG(DBG_PROBE, "bridgeType %d", usbvision->bridgeType);
1603
1604 mutex_lock(&usbvision->lock);
1605 1542
1606 /* compute alternate max packet sizes */ 1543 /* compute alternate max packet sizes */
1607 uif = dev->actconfig->interface[0]; 1544 uif = dev->actconfig->interface[0];
1608 1545
1609 usbvision->num_alt=uif->num_altsetting; 1546 usbvision->num_alt = uif->num_altsetting;
1610 PDEBUG(DBG_PROBE, "Alternate settings: %i",usbvision->num_alt); 1547 PDEBUG(DBG_PROBE, "Alternate settings: %i", usbvision->num_alt);
1611 usbvision->alt_max_pkt_size = kmalloc(32* 1548 usbvision->alt_max_pkt_size = kmalloc(32 * usbvision->num_alt, GFP_KERNEL);
1612 usbvision->num_alt,GFP_KERNEL);
1613 if (usbvision->alt_max_pkt_size == NULL) { 1549 if (usbvision->alt_max_pkt_size == NULL) {
1614 dev_err(&intf->dev, "usbvision: out of memory!\n"); 1550 dev_err(&intf->dev, "usbvision: out of memory!\n");
1615 mutex_unlock(&usbvision->lock);
1616 return -ENOMEM; 1551 return -ENOMEM;
1617 } 1552 }
1618 1553
1619 for (i = 0; i < usbvision->num_alt ; i++) { 1554 for (i = 0; i < usbvision->num_alt; i++) {
1620 u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[1].desc. 1555 u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[1].desc.
1621 wMaxPacketSize); 1556 wMaxPacketSize);
1622 usbvision->alt_max_pkt_size[i] = 1557 usbvision->alt_max_pkt_size[i] =
1623 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1); 1558 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
1624 PDEBUG(DBG_PROBE, "Alternate setting %i, max size= %i",i, 1559 PDEBUG(DBG_PROBE, "Alternate setting %i, max size= %i", i,
1625 usbvision->alt_max_pkt_size[i]); 1560 usbvision->alt_max_pkt_size[i]);
1626 } 1561 }
1627 1562
1628 1563
1629 usbvision->nr = usbvision_nr++; 1564 usbvision->nr = usbvision_nr++;
1630 1565
1631 usbvision->have_tuner = usbvision_device_data[model].Tuner; 1566 usbvision->have_tuner = usbvision_device_data[model].tuner;
1632 if (usbvision->have_tuner) { 1567 if (usbvision->have_tuner)
1633 usbvision->tuner_type = usbvision_device_data[model].TunerType; 1568 usbvision->tuner_type = usbvision_device_data[model].tuner_type;
1634 }
1635 1569
1636 usbvision->DevModel = model; 1570 usbvision->dev_model = model;
1637 usbvision->remove_pending = 0; 1571 usbvision->remove_pending = 0;
1638 usbvision->iface = ifnum; 1572 usbvision->iface = ifnum;
1639 usbvision->ifaceAlt = 0; 1573 usbvision->iface_alt = 0;
1640 usbvision->video_endp = endpoint->bEndpointAddress; 1574 usbvision->video_endp = endpoint->bEndpointAddress;
1641 usbvision->isocPacketSize = 0; 1575 usbvision->isoc_packet_size = 0;
1642 usbvision->usb_bandwidth = 0; 1576 usbvision->usb_bandwidth = 0;
1643 usbvision->user = 0; 1577 usbvision->user = 0;
1644 usbvision->streaming = Stream_Off; 1578 usbvision->streaming = stream_off;
1645 usbvision_configure_video(usbvision); 1579 usbvision_configure_video(usbvision);
1646 usbvision_register_video(usbvision); 1580 usbvision_register_video(usbvision);
1647 mutex_unlock(&usbvision->lock);
1648 1581
1649 usbvision_create_sysfs(usbvision->vdev); 1582 usbvision_create_sysfs(usbvision->vdev);
1650 1583
@@ -1672,9 +1605,9 @@ static void __devexit usbvision_disconnect(struct usb_interface *intf)
1672 return; 1605 return;
1673 } 1606 }
1674 1607
1675 mutex_lock(&usbvision->lock); 1608 mutex_lock(&usbvision->v4l2_lock);
1676 1609
1677 // At this time we ask to cancel outstanding URBs 1610 /* At this time we ask to cancel outstanding URBs */
1678 usbvision_stop_isoc(usbvision); 1611 usbvision_stop_isoc(usbvision);
1679 1612
1680 v4l2_device_disconnect(&usbvision->v4l2_dev); 1613 v4l2_device_disconnect(&usbvision->v4l2_dev);
@@ -1683,12 +1616,12 @@ static void __devexit usbvision_disconnect(struct usb_interface *intf)
1683 usbvision_i2c_unregister(usbvision); 1616 usbvision_i2c_unregister(usbvision);
1684 usbvision_power_off(usbvision); 1617 usbvision_power_off(usbvision);
1685 } 1618 }
1686 usbvision->remove_pending = 1; // Now all ISO data will be ignored 1619 usbvision->remove_pending = 1; /* Now all ISO data will be ignored */
1687 1620
1688 usb_put_dev(usbvision->dev); 1621 usb_put_dev(usbvision->dev);
1689 usbvision->dev = NULL; // USB device is no more 1622 usbvision->dev = NULL; /* USB device is no more */
1690 1623
1691 mutex_unlock(&usbvision->lock); 1624 mutex_unlock(&usbvision->v4l2_lock);
1692 1625
1693 if (usbvision->user) { 1626 if (usbvision->user) {
1694 printk(KERN_INFO "%s: In use, disconnect pending\n", 1627 printk(KERN_INFO "%s: In use, disconnect pending\n",
@@ -1717,7 +1650,7 @@ static struct usb_driver usbvision_driver = {
1717 */ 1650 */
1718static int __init usbvision_init(void) 1651static int __init usbvision_init(void)
1719{ 1652{
1720 int errCode; 1653 int err_code;
1721 1654
1722 PDEBUG(DBG_PROBE, ""); 1655 PDEBUG(DBG_PROBE, "");
1723 1656
@@ -1726,27 +1659,27 @@ static int __init usbvision_init(void)
1726 PDEBUG(DBG_MMAP, "MMAP debugging is enabled [video]"); 1659 PDEBUG(DBG_MMAP, "MMAP debugging is enabled [video]");
1727 1660
1728 /* disable planar mode support unless compression enabled */ 1661 /* disable planar mode support unless compression enabled */
1729 if (isocMode != ISOC_MODE_COMPRESS ) { 1662 if (isoc_mode != ISOC_MODE_COMPRESS) {
1730 // FIXME : not the right way to set supported flag 1663 /* FIXME : not the right way to set supported flag */
1731 usbvision_v4l2_format[6].supported = 0; // V4L2_PIX_FMT_YVU420 1664 usbvision_v4l2_format[6].supported = 0; /* V4L2_PIX_FMT_YVU420 */
1732 usbvision_v4l2_format[7].supported = 0; // V4L2_PIX_FMT_YUV422P 1665 usbvision_v4l2_format[7].supported = 0; /* V4L2_PIX_FMT_YUV422P */
1733 } 1666 }
1734 1667
1735 errCode = usb_register(&usbvision_driver); 1668 err_code = usb_register(&usbvision_driver);
1736 1669
1737 if (errCode == 0) { 1670 if (err_code == 0) {
1738 printk(KERN_INFO DRIVER_DESC " : " USBVISION_VERSION_STRING "\n"); 1671 printk(KERN_INFO DRIVER_DESC " : " USBVISION_VERSION_STRING "\n");
1739 PDEBUG(DBG_PROBE, "success"); 1672 PDEBUG(DBG_PROBE, "success");
1740 } 1673 }
1741 return errCode; 1674 return err_code;
1742} 1675}
1743 1676
1744static void __exit usbvision_exit(void) 1677static void __exit usbvision_exit(void)
1745{ 1678{
1746 PDEBUG(DBG_PROBE, ""); 1679 PDEBUG(DBG_PROBE, "");
1747 1680
1748 usb_deregister(&usbvision_driver); 1681 usb_deregister(&usbvision_driver);
1749 PDEBUG(DBG_PROBE, "success"); 1682 PDEBUG(DBG_PROBE, "success");
1750} 1683}
1751 1684
1752module_init(usbvision_init); 1685module_init(usbvision_init);
diff --git a/drivers/media/video/usbvision/usbvision.h b/drivers/media/video/usbvision/usbvision.h
index cc4e96c8cd6c..8074787fd1ac 100644
--- a/drivers/media/video/usbvision/usbvision.h
+++ b/drivers/media/video/usbvision/usbvision.h
@@ -132,15 +132,15 @@
132#define MAX_BYTES_PER_PIXEL 4 132#define MAX_BYTES_PER_PIXEL 4
133 133
134#define MIN_FRAME_WIDTH 64 134#define MIN_FRAME_WIDTH 64
135#define MAX_USB_WIDTH 320 //384 135#define MAX_USB_WIDTH 320 /* 384 */
136#define MAX_FRAME_WIDTH 320 //384 /*streching sometimes causes crashes*/ 136#define MAX_FRAME_WIDTH 320 /* 384 */ /* streching sometimes causes crashes*/
137 137
138#define MIN_FRAME_HEIGHT 48 138#define MIN_FRAME_HEIGHT 48
139#define MAX_USB_HEIGHT 240 //288 139#define MAX_USB_HEIGHT 240 /* 288 */
140#define MAX_FRAME_HEIGHT 240 //288 /*Streching sometimes causes crashes*/ 140#define MAX_FRAME_HEIGHT 240 /* 288 */ /* Streching sometimes causes crashes*/
141 141
142#define MAX_FRAME_SIZE (MAX_FRAME_WIDTH * MAX_FRAME_HEIGHT * MAX_BYTES_PER_PIXEL) 142#define MAX_FRAME_SIZE (MAX_FRAME_WIDTH * MAX_FRAME_HEIGHT * MAX_BYTES_PER_PIXEL)
143#define USBVISION_CLIPMASK_SIZE (MAX_FRAME_WIDTH * MAX_FRAME_HEIGHT / 8) //bytesize of clipmask 143#define USBVISION_CLIPMASK_SIZE (MAX_FRAME_WIDTH * MAX_FRAME_HEIGHT / 8) /* bytesize of clipmask */
144 144
145#define USBVISION_URB_FRAMES 32 145#define USBVISION_URB_FRAMES 32
146 146
@@ -148,7 +148,7 @@
148#define USBVISION_NUMFRAMES 3 /* Maximum number of frames an application can get */ 148#define USBVISION_NUMFRAMES 3 /* Maximum number of frames an application can get */
149#define USBVISION_NUMSBUF 2 /* Dimensioning the USB S buffering */ 149#define USBVISION_NUMSBUF 2 /* Dimensioning the USB S buffering */
150 150
151#define USBVISION_POWEROFF_TIME 3 * (HZ) // 3 seconds 151#define USBVISION_POWEROFF_TIME (3 * HZ) /* 3 seconds */
152 152
153 153
154#define FRAMERATE_MIN 0 154#define FRAMERATE_MIN 0
@@ -161,7 +161,8 @@ enum {
161}; 161};
162 162
163/* This macro restricts an int variable to an inclusive range */ 163/* This macro restricts an int variable to an inclusive range */
164#define RESTRICT_TO_RANGE(v,mi,ma) { if ((v) < (mi)) (v) = (mi); else if ((v) > (ma)) (v) = (ma); } 164#define RESTRICT_TO_RANGE(v, mi, ma) \
165 { if ((v) < (mi)) (v) = (mi); else if ((v) > (ma)) (v) = (ma); }
165 166
166/* 167/*
167 * We use macros to do YUV -> RGB conversion because this is 168 * We use macros to do YUV -> RGB conversion because this is
@@ -183,18 +184,18 @@ enum {
183 * Make sure the output values are within [0..255] range. 184 * Make sure the output values are within [0..255] range.
184 */ 185 */
185#define LIMIT_RGB(x) (((x) < 0) ? 0 : (((x) > 255) ? 255 : (x))) 186#define LIMIT_RGB(x) (((x) < 0) ? 0 : (((x) > 255) ? 255 : (x)))
186#define YUV_TO_RGB_BY_THE_BOOK(my,mu,mv,mr,mg,mb) { \ 187#define YUV_TO_RGB_BY_THE_BOOK(my, mu, mv, mr, mg, mb) { \
187 int mm_y, mm_yc, mm_u, mm_v, mm_r, mm_g, mm_b; \ 188 int mm_y, mm_yc, mm_u, mm_v, mm_r, mm_g, mm_b; \
188 mm_y = (my) - 16; \ 189 mm_y = (my) - 16; \
189 mm_u = (mu) - 128; \ 190 mm_u = (mu) - 128; \
190 mm_v = (mv) - 128; \ 191 mm_v = (mv) - 128; \
191 mm_yc= mm_y * 76284; \ 192 mm_yc = mm_y * 76284; \
192 mm_b = (mm_yc + 132252*mm_v ) >> 16; \ 193 mm_b = (mm_yc + 132252 * mm_v) >> 16; \
193 mm_g = (mm_yc - 53281*mm_u - 25625*mm_v ) >> 16; \ 194 mm_g = (mm_yc - 53281 * mm_u - 25625 * mm_v) >> 16; \
194 mm_r = (mm_yc + 104595*mm_u ) >> 16; \ 195 mm_r = (mm_yc + 104595 * mm_u) >> 16; \
195 mb = LIMIT_RGB(mm_b); \ 196 mb = LIMIT_RGB(mm_b); \
196 mg = LIMIT_RGB(mm_g); \ 197 mg = LIMIT_RGB(mm_g); \
197 mr = LIMIT_RGB(mm_r); \ 198 mr = LIMIT_RGB(mm_r); \
198} 199}
199 200
200/* Debugging aid */ 201/* Debugging aid */
@@ -202,7 +203,7 @@ enum {
202 wait_queue_head_t wq; \ 203 wait_queue_head_t wq; \
203 init_waitqueue_head(&wq); \ 204 init_waitqueue_head(&wq); \
204 printk(KERN_INFO "Say: %s\n", what); \ 205 printk(KERN_INFO "Say: %s\n", what); \
205 interruptible_sleep_on_timeout (&wq, HZ*3); \ 206 interruptible_sleep_on_timeout(&wq, HZ * 3); \
206} 207}
207 208
208/* 209/*
@@ -223,39 +224,39 @@ enum {
223/* ----------------------------------------------------------------- */ 224/* ----------------------------------------------------------------- */
224/* usbvision video structures */ 225/* usbvision video structures */
225/* ----------------------------------------------------------------- */ 226/* ----------------------------------------------------------------- */
226enum ScanState { 227enum scan_state {
227 ScanState_Scanning, /* Scanning for header */ 228 scan_state_scanning, /* Scanning for header */
228 ScanState_Lines /* Parsing lines */ 229 scan_state_lines /* Parsing lines */
229}; 230};
230 231
231/* Completion states of the data parser */ 232/* Completion states of the data parser */
232enum ParseState { 233enum parse_state {
233 ParseState_Continue, /* Just parse next item */ 234 parse_state_continue, /* Just parse next item */
234 ParseState_NextFrame, /* Frame done, send it to V4L */ 235 parse_state_next_frame, /* Frame done, send it to V4L */
235 ParseState_Out, /* Not enough data for frame */ 236 parse_state_out, /* Not enough data for frame */
236 ParseState_EndParse /* End parsing */ 237 parse_state_end_parse /* End parsing */
237}; 238};
238 239
239enum FrameState { 240enum frame_state {
240 FrameState_Unused, /* Unused (no MCAPTURE) */ 241 frame_state_unused, /* Unused (no MCAPTURE) */
241 FrameState_Ready, /* Ready to start grabbing */ 242 frame_state_ready, /* Ready to start grabbing */
242 FrameState_Grabbing, /* In the process of being grabbed into */ 243 frame_state_grabbing, /* In the process of being grabbed into */
243 FrameState_Done, /* Finished grabbing, but not been synced yet */ 244 frame_state_done, /* Finished grabbing, but not been synced yet */
244 FrameState_DoneHold, /* Are syncing or reading */ 245 frame_state_done_hold, /* Are syncing or reading */
245 FrameState_Error, /* Something bad happened while processing */ 246 frame_state_error, /* Something bad happened while processing */
246}; 247};
247 248
248/* stream states */ 249/* stream states */
249enum StreamState { 250enum stream_state {
250 Stream_Off, /* Driver streaming is completely OFF */ 251 stream_off, /* Driver streaming is completely OFF */
251 Stream_Idle, /* Driver streaming is ready to be put ON by the application */ 252 stream_idle, /* Driver streaming is ready to be put ON by the application */
252 Stream_Interrupt, /* Driver streaming must be interrupted */ 253 stream_interrupt, /* Driver streaming must be interrupted */
253 Stream_On, /* Driver streaming is put ON by the application */ 254 stream_on, /* Driver streaming is put ON by the application */
254}; 255};
255 256
256enum IsocState { 257enum isoc_state {
257 IsocState_InFrame, /* Isoc packet is member of frame */ 258 isoc_state_in_frame, /* Isoc packet is member of frame */
258 IsocState_NoFrame, /* Isoc packet is not member of any frame */ 259 isoc_state_no_frame, /* Isoc packet is not member of any frame */
259}; 260};
260 261
261struct usb_device; 262struct usb_device;
@@ -265,8 +266,8 @@ struct usbvision_sbuf {
265 struct urb *urb; 266 struct urb *urb;
266}; 267};
267 268
268#define USBVISION_MAGIC_1 0x55 269#define USBVISION_MAGIC_1 0x55
269#define USBVISION_MAGIC_2 0xAA 270#define USBVISION_MAGIC_2 0xAA
270#define USBVISION_HEADER_LENGTH 0x0c 271#define USBVISION_HEADER_LENGTH 0x0c
271#define USBVISION_SAA7111_ADDR 0x48 272#define USBVISION_SAA7111_ADDR 0x48
272#define USBVISION_SAA7113_ADDR 0x4a 273#define USBVISION_SAA7113_ADDR 0x4a
@@ -286,23 +287,23 @@ struct usbvision_v4l2_format_st {
286struct usbvision_frame_header { 287struct usbvision_frame_header {
287 unsigned char magic_1; /* 0 magic */ 288 unsigned char magic_1; /* 0 magic */
288 unsigned char magic_2; /* 1 magic */ 289 unsigned char magic_2; /* 1 magic */
289 unsigned char headerLength; /* 2 */ 290 unsigned char header_length; /* 2 */
290 unsigned char frameNum; /* 3 */ 291 unsigned char frame_num; /* 3 */
291 unsigned char framePhase; /* 4 */ 292 unsigned char frame_phase; /* 4 */
292 unsigned char frameLatency; /* 5 */ 293 unsigned char frame_latency; /* 5 */
293 unsigned char dataFormat; /* 6 */ 294 unsigned char data_format; /* 6 */
294 unsigned char formatParam; /* 7 */ 295 unsigned char format_param; /* 7 */
295 unsigned char frameWidthLo; /* 8 */ 296 unsigned char frame_width_lo; /* 8 */
296 unsigned char frameWidthHi; /* 9 */ 297 unsigned char frame_width_hi; /* 9 */
297 unsigned char frameHeightLo; /* 10 */ 298 unsigned char frame_height_lo; /* 10 */
298 unsigned char frameHeightHi; /* 11 */ 299 unsigned char frame_height_hi; /* 11 */
299 __u16 frameWidth; /* 8 - 9 after endian correction*/ 300 __u16 frame_width; /* 8 - 9 after endian correction*/
300 __u16 frameHeight; /* 10 - 11 after endian correction*/ 301 __u16 frame_height; /* 10 - 11 after endian correction*/
301}; 302};
302 303
303struct usbvision_frame { 304struct usbvision_frame {
304 char *data; /* Frame buffer */ 305 char *data; /* Frame buffer */
305 struct usbvision_frame_header isocHeader; /* Header from stream */ 306 struct usbvision_frame_header isoc_header; /* Header from stream */
306 307
307 int width; /* Width application is expecting */ 308 int width; /* Width application is expecting */
308 int height; /* Height */ 309 int height; /* Height */
@@ -322,7 +323,7 @@ struct usbvision_frame {
322 struct usbvision_v4l2_format_st v4l2_format; /* format the user needs*/ 323 struct usbvision_v4l2_format_st v4l2_format; /* format the user needs*/
323 int v4l2_linesize; /* bytes for one videoline*/ 324 int v4l2_linesize; /* bytes for one videoline*/
324 struct timeval timestamp; 325 struct timeval timestamp;
325 int sequence; // How many video frames we send to user 326 int sequence; /* How many video frames we send to user */
326}; 327};
327 328
328#define CODEC_SAA7113 7113 329#define CODEC_SAA7113 7113
@@ -332,24 +333,24 @@ struct usbvision_frame {
332#define BRIDGE_NT1005 1005 333#define BRIDGE_NT1005 1005
333 334
334struct usbvision_device_data_st { 335struct usbvision_device_data_st {
335 __u64 VideoNorm; 336 __u64 video_norm;
336 const char *ModelString; 337 const char *model_string;
337 int Interface; /* to handle special interface number like BELKIN and Hauppauge WinTV-USB II */ 338 int interface; /* to handle special interface number like BELKIN and Hauppauge WinTV-USB II */
338 __u16 Codec; 339 __u16 codec;
339 unsigned VideoChannels:3; 340 unsigned video_channels:3;
340 unsigned AudioChannels:2; 341 unsigned audio_channels:2;
341 unsigned Radio:1; 342 unsigned radio:1;
342 unsigned vbi:1; 343 unsigned vbi:1;
343 unsigned Tuner:1; 344 unsigned tuner:1;
344 unsigned Vin_Reg1_override:1; /* Override default value with */ 345 unsigned vin_reg1_override:1; /* Override default value with */
345 unsigned Vin_Reg2_override:1; /* Vin_Reg1, Vin_Reg2, etc. */ 346 unsigned vin_reg2_override:1; /* vin_reg1, vin_reg2, etc. */
346 unsigned Dvi_yuv_override:1; 347 unsigned dvi_yuv_override:1;
347 __u8 Vin_Reg1; 348 __u8 vin_reg1;
348 __u8 Vin_Reg2; 349 __u8 vin_reg2;
349 __u8 Dvi_yuv; 350 __u8 dvi_yuv;
350 __u8 TunerType; 351 __u8 tuner_type;
351 __s16 X_Offset; 352 __s16 x_offset;
352 __s16 Y_Offset; 353 __s16 y_offset;
353}; 354};
354 355
355/* Declared on usbvision-cards.c */ 356/* Declared on usbvision-cards.c */
@@ -358,50 +359,50 @@ extern struct usb_device_id usbvision_table[];
358 359
359struct usb_usbvision { 360struct usb_usbvision {
360 struct v4l2_device v4l2_dev; 361 struct v4l2_device v4l2_dev;
361 struct video_device *vdev; /* Video Device */ 362 struct video_device *vdev; /* Video Device */
362 struct video_device *rdev; /* Radio Device */ 363 struct video_device *rdev; /* Radio Device */
363 364
364 /* i2c Declaration Section*/ 365 /* i2c Declaration Section*/
365 struct i2c_adapter i2c_adap; 366 struct i2c_adapter i2c_adap;
366 int registered_i2c; 367 int registered_i2c;
367 368
368 struct urb *ctrlUrb; 369 struct urb *ctrl_urb;
369 unsigned char ctrlUrbBuffer[8]; 370 unsigned char ctrl_urb_buffer[8];
370 int ctrlUrbBusy; 371 int ctrl_urb_busy;
371 struct usb_ctrlrequest ctrlUrbSetup; 372 struct usb_ctrlrequest ctrl_urb_setup;
372 wait_queue_head_t ctrlUrb_wq; // Processes waiting 373 wait_queue_head_t ctrl_urb_wq; /* Processes waiting */
373 374
374 /* configuration part */ 375 /* configuration part */
375 int have_tuner; 376 int have_tuner;
376 int tuner_type; 377 int tuner_type;
377 int bridgeType; // NT1003, NT1004, NT1005 378 int bridge_type; /* NT1003, NT1004, NT1005 */
378 int radio; 379 int radio;
379 int video_inputs; // # of inputs 380 int video_inputs; /* # of inputs */
380 unsigned long freq; 381 unsigned long freq;
381 int AudioMute; 382 int audio_mute;
382 int AudioChannel; 383 int audio_channel;
383 int isocMode; // format of video data for the usb isoc-transfer 384 int isoc_mode; /* format of video data for the usb isoc-transfer */
384 unsigned int nr; // Number of the device 385 unsigned int nr; /* Number of the device */
385 386
386 /* Device structure */ 387 /* Device structure */
387 struct usb_device *dev; 388 struct usb_device *dev;
388 /* usb transfer */ 389 /* usb transfer */
389 int num_alt; /* Number of alternative settings */ 390 int num_alt; /* Number of alternative settings */
390 unsigned int *alt_max_pkt_size; /* array of wMaxPacketSize */ 391 unsigned int *alt_max_pkt_size; /* array of max_packet_size */
391 unsigned char iface; /* Video interface number */ 392 unsigned char iface; /* Video interface number */
392 unsigned char ifaceAlt; /* Alt settings */ 393 unsigned char iface_alt; /* Alt settings */
393 unsigned char Vin_Reg2_Preset; 394 unsigned char vin_reg2_preset;
394 struct mutex lock; 395 struct mutex v4l2_lock;
395 struct timer_list powerOffTimer; 396 struct timer_list power_off_timer;
396 struct work_struct powerOffWork; 397 struct work_struct power_off_work;
397 int power; /* is the device powered on? */ 398 int power; /* is the device powered on? */
398 int user; /* user count for exclusive use */ 399 int user; /* user count for exclusive use */
399 int initialized; /* Had we already sent init sequence? */ 400 int initialized; /* Had we already sent init sequence? */
400 int DevModel; /* What type of USBVISION device we got? */ 401 int dev_model; /* What type of USBVISION device we got? */
401 enum StreamState streaming; /* Are we streaming Isochronous? */ 402 enum stream_state streaming; /* Are we streaming Isochronous? */
402 int last_error; /* What calamity struck us? */ 403 int last_error; /* What calamity struck us? */
403 int curwidth; /* width of the frame the device is currently set to*/ 404 int curwidth; /* width of the frame the device is currently set to*/
404 int curheight; /* height of the frame the device is currently set to*/ 405 int curheight; /* height of the frame the device is currently set to*/
405 int stretch_width; /* stretch-factor for frame width (from usb to screen)*/ 406 int stretch_width; /* stretch-factor for frame width (from usb to screen)*/
406 int stretch_height; /* stretch-factor for frame height (from usb to screen)*/ 407 int stretch_height; /* stretch-factor for frame height (from usb to screen)*/
407 char *fbuf; /* Videodev buffer area for mmap*/ 408 char *fbuf; /* Videodev buffer area for mmap*/
@@ -411,10 +412,10 @@ struct usb_usbvision {
411 struct list_head inqueue, outqueue; /* queued frame list and ready to dequeue frame list */ 412 struct list_head inqueue, outqueue; /* queued frame list and ready to dequeue frame list */
412 wait_queue_head_t wait_frame; /* Processes waiting */ 413 wait_queue_head_t wait_frame; /* Processes waiting */
413 wait_queue_head_t wait_stream; /* Processes waiting */ 414 wait_queue_head_t wait_stream; /* Processes waiting */
414 struct usbvision_frame *curFrame; // pointer to current frame, set by usbvision_find_header 415 struct usbvision_frame *cur_frame; /* pointer to current frame, set by usbvision_find_header */
415 struct usbvision_frame frame[USBVISION_NUMFRAMES]; // frame buffer 416 struct usbvision_frame frame[USBVISION_NUMFRAMES]; /* frame buffer */
416 int num_frames; // number of frames allocated 417 int num_frames; /* number of frames allocated */
417 struct usbvision_sbuf sbuf[USBVISION_NUMSBUF]; // S buffering 418 struct usbvision_sbuf sbuf[USBVISION_NUMSBUF]; /* S buffering */
418 volatile int remove_pending; /* If set then about to exit */ 419 volatile int remove_pending; /* If set then about to exit */
419 420
420 /* Scratch space from the Isochronous Pipe.*/ 421 /* Scratch space from the Isochronous Pipe.*/
@@ -424,43 +425,43 @@ struct usb_usbvision {
424 int scratch_headermarker[USBVISION_NUM_HEADERMARKER]; 425 int scratch_headermarker[USBVISION_NUM_HEADERMARKER];
425 int scratch_headermarker_read_ptr; 426 int scratch_headermarker_read_ptr;
426 int scratch_headermarker_write_ptr; 427 int scratch_headermarker_write_ptr;
427 enum IsocState isocstate; 428 enum isoc_state isocstate;
428 struct usbvision_v4l2_format_st palette; 429 struct usbvision_v4l2_format_st palette;
429 430
430 struct v4l2_capability vcap; /* Video capabilities */ 431 struct v4l2_capability vcap; /* Video capabilities */
431 unsigned int ctl_input; /* selected input */ 432 unsigned int ctl_input; /* selected input */
432 v4l2_std_id tvnormId; /* selected tv norm */ 433 v4l2_std_id tvnorm_id; /* selected tv norm */
433 unsigned char video_endp; /* 0x82 for USBVISION devices based */ 434 unsigned char video_endp; /* 0x82 for USBVISION devices based */
434 435
435 // Decompression stuff: 436 /* Decompression stuff: */
436 unsigned char *IntraFrameBuffer; /* Buffer for reference frame */ 437 unsigned char *intra_frame_buffer; /* Buffer for reference frame */
437 int BlockPos; //for test only 438 int block_pos; /* for test only */
438 int requestIntra; // 0 = normal; 1 = intra frame is requested; 439 int request_intra; /* 0 = normal; 1 = intra frame is requested; */
439 int lastIsocFrameNum; // check for lost isoc frames 440 int last_isoc_frame_num; /* check for lost isoc frames */
440 int isocPacketSize; // need to calculate usedBandwidth 441 int isoc_packet_size; /* need to calculate used_bandwidth */
441 int usedBandwidth; // used bandwidth 0-100%, need to set comprLevel 442 int used_bandwidth; /* used bandwidth 0-100%, need to set compr_level */
442 int comprLevel; // How strong (100) or weak (0) is compression 443 int compr_level; /* How strong (100) or weak (0) is compression */
443 int lastComprLevel; // How strong (100) or weak (0) was compression 444 int last_compr_level; /* How strong (100) or weak (0) was compression */
444 int usb_bandwidth; /* Mbit/s */ 445 int usb_bandwidth; /* Mbit/s */
445 446
446 /* Statistics that can be overlayed on the screen */ 447 /* Statistics that can be overlayed on the screen */
447 unsigned long isocUrbCount; // How many URBs we received so far 448 unsigned long isoc_urb_count; /* How many URBs we received so far */
448 unsigned long urb_length; /* Length of last URB */ 449 unsigned long urb_length; /* Length of last URB */
449 unsigned long isocDataCount; /* How many bytes we received */ 450 unsigned long isoc_data_count; /* How many bytes we received */
450 unsigned long header_count; /* How many frame headers we found */ 451 unsigned long header_count; /* How many frame headers we found */
451 unsigned long scratch_ovf_count; /* How many times we overflowed scratch */ 452 unsigned long scratch_ovf_count; /* How many times we overflowed scratch */
452 unsigned long isocSkipCount; /* How many empty ISO packets received */ 453 unsigned long isoc_skip_count; /* How many empty ISO packets received */
453 unsigned long isocErrCount; /* How many bad ISO packets received */ 454 unsigned long isoc_err_count; /* How many bad ISO packets received */
454 unsigned long isocPacketCount; // How many packets we totally got 455 unsigned long isoc_packet_count; /* How many packets we totally got */
455 unsigned long timeInIrq; // How long do we need for interrupt 456 unsigned long time_in_irq; /* How long do we need for interrupt */
456 int isocMeasureBandwidthCount; 457 int isoc_measure_bandwidth_count;
457 int frame_num; // How many video frames we send to user 458 int frame_num; /* How many video frames we send to user */
458 int maxStripLen; // How big is the biggest strip 459 int max_strip_len; /* How big is the biggest strip */
459 int comprBlockPos; 460 int comprblock_pos;
460 int stripLenErrors; // How many times was BlockPos greater than StripLen 461 int strip_len_errors; /* How many times was block_pos greater than strip_len */
461 int stripMagicErrors; 462 int strip_magic_errors;
462 int stripLineNumberErrors; 463 int strip_line_number_errors;
463 int ComprBlockTypes[4]; 464 int compr_block_types[4];
464}; 465};
465 466
466static inline struct usb_usbvision *to_usbvision(struct v4l2_device *v4l2_dev) 467static inline struct usb_usbvision *to_usbvision(struct v4l2_device *v4l2_dev)
@@ -494,13 +495,13 @@ void usbvision_scratch_free(struct usb_usbvision *usbvision);
494int usbvision_decompress_alloc(struct usb_usbvision *usbvision); 495int usbvision_decompress_alloc(struct usb_usbvision *usbvision);
495void usbvision_decompress_free(struct usb_usbvision *usbvision); 496void usbvision_decompress_free(struct usb_usbvision *usbvision);
496 497
497int usbvision_setup(struct usb_usbvision *usbvision,int format); 498int usbvision_setup(struct usb_usbvision *usbvision, int format);
498int usbvision_init_isoc(struct usb_usbvision *usbvision); 499int usbvision_init_isoc(struct usb_usbvision *usbvision);
499int usbvision_restart_isoc(struct usb_usbvision *usbvision); 500int usbvision_restart_isoc(struct usb_usbvision *usbvision);
500void usbvision_stop_isoc(struct usb_usbvision *usbvision); 501void usbvision_stop_isoc(struct usb_usbvision *usbvision);
501int usbvision_set_alternate(struct usb_usbvision *dev); 502int usbvision_set_alternate(struct usb_usbvision *dev);
502 503
503int usbvision_set_audio(struct usb_usbvision *usbvision, int AudioChannel); 504int usbvision_set_audio(struct usb_usbvision *usbvision, int audio_channel);
504int usbvision_audio_off(struct usb_usbvision *usbvision); 505int usbvision_audio_off(struct usb_usbvision *usbvision);
505 506
506int usbvision_begin_streaming(struct usb_usbvision *usbvision); 507int usbvision_begin_streaming(struct usb_usbvision *usbvision);
@@ -511,9 +512,9 @@ int usbvision_muxsel(struct usb_usbvision *usbvision, int channel);
511int usbvision_set_input(struct usb_usbvision *usbvision); 512int usbvision_set_input(struct usb_usbvision *usbvision);
512int usbvision_set_output(struct usb_usbvision *usbvision, int width, int height); 513int usbvision_set_output(struct usb_usbvision *usbvision, int width, int height);
513 514
514void usbvision_init_powerOffTimer(struct usb_usbvision *usbvision); 515void usbvision_init_power_off_timer(struct usb_usbvision *usbvision);
515void usbvision_set_powerOffTimer(struct usb_usbvision *usbvision); 516void usbvision_set_power_off_timer(struct usb_usbvision *usbvision);
516void usbvision_reset_powerOffTimer(struct usb_usbvision *usbvision); 517void usbvision_reset_power_off_timer(struct usb_usbvision *usbvision);
517int usbvision_power_off(struct usb_usbvision *usbvision); 518int usbvision_power_off(struct usb_usbvision *usbvision);
518int usbvision_power_on(struct usb_usbvision *usbvision); 519int usbvision_power_on(struct usb_usbvision *usbvision);
519 520
diff --git a/drivers/media/video/uvc/uvc_v4l2.c b/drivers/media/video/uvc/uvc_v4l2.c
index 8cf61e8a634f..9005a8d9d5f8 100644
--- a/drivers/media/video/uvc/uvc_v4l2.c
+++ b/drivers/media/video/uvc/uvc_v4l2.c
@@ -1035,11 +1035,8 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
1035 return uvc_xu_ctrl_query(chain, arg, 1); 1035 return uvc_xu_ctrl_query(chain, arg, 1);
1036 1036
1037 default: 1037 default:
1038 if ((ret = v4l_compat_translate_ioctl(file, cmd, arg, 1038 uvc_trace(UVC_TRACE_IOCTL, "Unknown ioctl 0x%08x\n", cmd);
1039 uvc_v4l2_do_ioctl)) == -ENOIOCTLCMD) 1039 return -EINVAL;
1040 uvc_trace(UVC_TRACE_IOCTL, "Unknown ioctl 0x%08x\n",
1041 cmd);
1042 return ret;
1043 } 1040 }
1044 1041
1045 return ret; 1042 return ret;
diff --git a/drivers/media/video/v4l1-compat.c b/drivers/media/video/v4l1-compat.c
deleted file mode 100644
index d4ac751036a2..000000000000
--- a/drivers/media/video/v4l1-compat.c
+++ /dev/null
@@ -1,1277 +0,0 @@
1/*
2 *
3 * Video for Linux Two
4 * Backward Compatibility Layer
5 *
6 * Support subroutines for providing V4L2 drivers with backward
7 * compatibility with applications using the old API.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version
12 * 2 of the License, or (at your option) any later version.
13 *
14 * Author: Bill Dirks <bill@thedirks.org>
15 * et al.
16 *
17 */
18
19
20#include <linux/init.h>
21#include <linux/module.h>
22#include <linux/types.h>
23#include <linux/kernel.h>
24#include <linux/sched.h>
25#include <linux/mm.h>
26#include <linux/fs.h>
27#include <linux/file.h>
28#include <linux/string.h>
29#include <linux/errno.h>
30#include <linux/slab.h>
31#include <linux/videodev.h>
32#include <media/v4l2-common.h>
33#include <media/v4l2-ioctl.h>
34
35#include <asm/uaccess.h>
36#include <asm/system.h>
37#include <asm/pgtable.h>
38
39static unsigned int debug;
40module_param(debug, int, 0644);
41MODULE_PARM_DESC(debug, "enable debug messages");
42MODULE_AUTHOR("Bill Dirks");
43MODULE_DESCRIPTION("v4l(1) compatibility layer for v4l2 drivers.");
44MODULE_LICENSE("GPL");
45
46#define dprintk(fmt, arg...) \
47 do { \
48 if (debug) \
49 printk(KERN_DEBUG "v4l1-compat: " fmt , ## arg);\
50 } while (0)
51
52/*
53 * I O C T L T R A N S L A T I O N
54 *
55 * From here on down is the code for translating the numerous
56 * ioctl commands from the old API to the new API.
57 */
58
59static int
60get_v4l_control(struct file *file,
61 int cid,
62 v4l2_kioctl drv)
63{
64 struct v4l2_queryctrl qctrl2;
65 struct v4l2_control ctrl2;
66 int err;
67
68 qctrl2.id = cid;
69 err = drv(file, VIDIOC_QUERYCTRL, &qctrl2);
70 if (err < 0)
71 dprintk("VIDIOC_QUERYCTRL: %d\n", err);
72 if (err == 0 && !(qctrl2.flags & V4L2_CTRL_FLAG_DISABLED)) {
73 ctrl2.id = qctrl2.id;
74 err = drv(file, VIDIOC_G_CTRL, &ctrl2);
75 if (err < 0) {
76 dprintk("VIDIOC_G_CTRL: %d\n", err);
77 return 0;
78 }
79 return DIV_ROUND_CLOSEST((ctrl2.value-qctrl2.minimum) * 65535,
80 qctrl2.maximum - qctrl2.minimum);
81 }
82 return 0;
83}
84
85static int
86set_v4l_control(struct file *file,
87 int cid,
88 int value,
89 v4l2_kioctl drv)
90{
91 struct v4l2_queryctrl qctrl2;
92 struct v4l2_control ctrl2;
93 int err;
94
95 qctrl2.id = cid;
96 err = drv(file, VIDIOC_QUERYCTRL, &qctrl2);
97 if (err < 0)
98 dprintk("VIDIOC_QUERYCTRL: %d\n", err);
99 if (err == 0 &&
100 !(qctrl2.flags & V4L2_CTRL_FLAG_DISABLED) &&
101 !(qctrl2.flags & V4L2_CTRL_FLAG_GRABBED)) {
102 if (value < 0)
103 value = 0;
104 if (value > 65535)
105 value = 65535;
106 if (value && qctrl2.type == V4L2_CTRL_TYPE_BOOLEAN)
107 value = 65535;
108 ctrl2.id = qctrl2.id;
109 ctrl2.value =
110 (value * (qctrl2.maximum - qctrl2.minimum)
111 + 32767)
112 / 65535;
113 ctrl2.value += qctrl2.minimum;
114 err = drv(file, VIDIOC_S_CTRL, &ctrl2);
115 if (err < 0)
116 dprintk("VIDIOC_S_CTRL: %d\n", err);
117 }
118 return 0;
119}
120
121/* ----------------------------------------------------------------- */
122
123static const unsigned int palette2pixelformat[] = {
124 [VIDEO_PALETTE_GREY] = V4L2_PIX_FMT_GREY,
125 [VIDEO_PALETTE_RGB555] = V4L2_PIX_FMT_RGB555,
126 [VIDEO_PALETTE_RGB565] = V4L2_PIX_FMT_RGB565,
127 [VIDEO_PALETTE_RGB24] = V4L2_PIX_FMT_BGR24,
128 [VIDEO_PALETTE_RGB32] = V4L2_PIX_FMT_BGR32,
129 /* yuv packed pixel */
130 [VIDEO_PALETTE_YUYV] = V4L2_PIX_FMT_YUYV,
131 [VIDEO_PALETTE_YUV422] = V4L2_PIX_FMT_YUYV,
132 [VIDEO_PALETTE_UYVY] = V4L2_PIX_FMT_UYVY,
133 /* yuv planar */
134 [VIDEO_PALETTE_YUV410P] = V4L2_PIX_FMT_YUV410,
135 [VIDEO_PALETTE_YUV420] = V4L2_PIX_FMT_YUV420,
136 [VIDEO_PALETTE_YUV420P] = V4L2_PIX_FMT_YUV420,
137 [VIDEO_PALETTE_YUV411P] = V4L2_PIX_FMT_YUV411P,
138 [VIDEO_PALETTE_YUV422P] = V4L2_PIX_FMT_YUV422P,
139};
140
141static unsigned int __pure
142palette_to_pixelformat(unsigned int palette)
143{
144 if (palette < ARRAY_SIZE(palette2pixelformat))
145 return palette2pixelformat[palette];
146 else
147 return 0;
148}
149
150static unsigned int __attribute_const__
151pixelformat_to_palette(unsigned int pixelformat)
152{
153 int palette = 0;
154 switch (pixelformat) {
155 case V4L2_PIX_FMT_GREY:
156 palette = VIDEO_PALETTE_GREY;
157 break;
158 case V4L2_PIX_FMT_RGB555:
159 palette = VIDEO_PALETTE_RGB555;
160 break;
161 case V4L2_PIX_FMT_RGB565:
162 palette = VIDEO_PALETTE_RGB565;
163 break;
164 case V4L2_PIX_FMT_BGR24:
165 palette = VIDEO_PALETTE_RGB24;
166 break;
167 case V4L2_PIX_FMT_BGR32:
168 palette = VIDEO_PALETTE_RGB32;
169 break;
170 /* yuv packed pixel */
171 case V4L2_PIX_FMT_YUYV:
172 palette = VIDEO_PALETTE_YUYV;
173 break;
174 case V4L2_PIX_FMT_UYVY:
175 palette = VIDEO_PALETTE_UYVY;
176 break;
177 /* yuv planar */
178 case V4L2_PIX_FMT_YUV410:
179 palette = VIDEO_PALETTE_YUV420;
180 break;
181 case V4L2_PIX_FMT_YUV420:
182 palette = VIDEO_PALETTE_YUV420;
183 break;
184 case V4L2_PIX_FMT_YUV411P:
185 palette = VIDEO_PALETTE_YUV411P;
186 break;
187 case V4L2_PIX_FMT_YUV422P:
188 palette = VIDEO_PALETTE_YUV422P;
189 break;
190 }
191 return palette;
192}
193
194/* ----------------------------------------------------------------- */
195
196static int poll_one(struct file *file, struct poll_wqueues *pwq)
197{
198 int retval = 1;
199 poll_table *table;
200
201 poll_initwait(pwq);
202 table = &pwq->pt;
203 for (;;) {
204 int mask;
205 mask = file->f_op->poll(file, table);
206 if (mask & POLLIN)
207 break;
208 table = NULL;
209 if (signal_pending(current)) {
210 retval = -ERESTARTSYS;
211 break;
212 }
213 poll_schedule(pwq, TASK_INTERRUPTIBLE);
214 }
215 poll_freewait(pwq);
216 return retval;
217}
218
219static int count_inputs(
220 struct file *file,
221 v4l2_kioctl drv)
222{
223 struct v4l2_input input2;
224 int i;
225
226 for (i = 0;; i++) {
227 memset(&input2, 0, sizeof(input2));
228 input2.index = i;
229 if (0 != drv(file, VIDIOC_ENUMINPUT, &input2))
230 break;
231 }
232 return i;
233}
234
235static int check_size(
236 struct file *file,
237 v4l2_kioctl drv,
238 int *maxw,
239 int *maxh)
240{
241 struct v4l2_fmtdesc desc2;
242 struct v4l2_format fmt2;
243
244 memset(&desc2, 0, sizeof(desc2));
245 memset(&fmt2, 0, sizeof(fmt2));
246
247 desc2.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
248 if (0 != drv(file, VIDIOC_ENUM_FMT, &desc2))
249 goto done;
250
251 fmt2.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
252 fmt2.fmt.pix.width = 10000;
253 fmt2.fmt.pix.height = 10000;
254 fmt2.fmt.pix.pixelformat = desc2.pixelformat;
255 if (0 != drv(file, VIDIOC_TRY_FMT, &fmt2))
256 goto done;
257
258 *maxw = fmt2.fmt.pix.width;
259 *maxh = fmt2.fmt.pix.height;
260
261done:
262 return 0;
263}
264
265/* ----------------------------------------------------------------- */
266
267static noinline long v4l1_compat_get_capabilities(
268 struct video_capability *cap,
269 struct file *file,
270 v4l2_kioctl drv)
271{
272 long err;
273 struct v4l2_framebuffer fbuf;
274 struct v4l2_capability *cap2;
275
276 cap2 = kzalloc(sizeof(*cap2), GFP_KERNEL);
277 if (!cap2) {
278 err = -ENOMEM;
279 return err;
280 }
281 memset(cap, 0, sizeof(*cap));
282 memset(&fbuf, 0, sizeof(fbuf));
283
284 err = drv(file, VIDIOC_QUERYCAP, cap2);
285 if (err < 0) {
286 dprintk("VIDIOCGCAP / VIDIOC_QUERYCAP: %ld\n", err);
287 goto done;
288 }
289 if (cap2->capabilities & V4L2_CAP_VIDEO_OVERLAY) {
290 err = drv(file, VIDIOC_G_FBUF, &fbuf);
291 if (err < 0) {
292 dprintk("VIDIOCGCAP / VIDIOC_G_FBUF: %ld\n", err);
293 memset(&fbuf, 0, sizeof(fbuf));
294 }
295 err = 0;
296 }
297
298 memcpy(cap->name, cap2->card,
299 min(sizeof(cap->name), sizeof(cap2->card)));
300 cap->name[sizeof(cap->name) - 1] = 0;
301 if (cap2->capabilities & V4L2_CAP_VIDEO_CAPTURE)
302 cap->type |= VID_TYPE_CAPTURE;
303 if (cap2->capabilities & V4L2_CAP_TUNER)
304 cap->type |= VID_TYPE_TUNER;
305 if (cap2->capabilities & V4L2_CAP_VBI_CAPTURE)
306 cap->type |= VID_TYPE_TELETEXT;
307 if (cap2->capabilities & V4L2_CAP_VIDEO_OVERLAY)
308 cap->type |= VID_TYPE_OVERLAY;
309 if (fbuf.capability & V4L2_FBUF_CAP_LIST_CLIPPING)
310 cap->type |= VID_TYPE_CLIPPING;
311
312 cap->channels = count_inputs(file, drv);
313 check_size(file, drv,
314 &cap->maxwidth, &cap->maxheight);
315 cap->audios = 0; /* FIXME */
316 cap->minwidth = 48; /* FIXME */
317 cap->minheight = 32; /* FIXME */
318
319done:
320 kfree(cap2);
321 return err;
322}
323
324static noinline long v4l1_compat_get_frame_buffer(
325 struct video_buffer *buffer,
326 struct file *file,
327 v4l2_kioctl drv)
328{
329 long err;
330 struct v4l2_framebuffer fbuf;
331
332 memset(buffer, 0, sizeof(*buffer));
333 memset(&fbuf, 0, sizeof(fbuf));
334
335 err = drv(file, VIDIOC_G_FBUF, &fbuf);
336 if (err < 0) {
337 dprintk("VIDIOCGFBUF / VIDIOC_G_FBUF: %ld\n", err);
338 goto done;
339 }
340 buffer->base = fbuf.base;
341 buffer->height = fbuf.fmt.height;
342 buffer->width = fbuf.fmt.width;
343
344 switch (fbuf.fmt.pixelformat) {
345 case V4L2_PIX_FMT_RGB332:
346 buffer->depth = 8;
347 break;
348 case V4L2_PIX_FMT_RGB555:
349 buffer->depth = 15;
350 break;
351 case V4L2_PIX_FMT_RGB565:
352 buffer->depth = 16;
353 break;
354 case V4L2_PIX_FMT_BGR24:
355 buffer->depth = 24;
356 break;
357 case V4L2_PIX_FMT_BGR32:
358 buffer->depth = 32;
359 break;
360 default:
361 buffer->depth = 0;
362 }
363 if (fbuf.fmt.bytesperline) {
364 buffer->bytesperline = fbuf.fmt.bytesperline;
365 if (!buffer->depth && buffer->width)
366 buffer->depth = ((fbuf.fmt.bytesperline<<3)
367 + (buffer->width-1))
368 / buffer->width;
369 } else {
370 buffer->bytesperline =
371 (buffer->width * buffer->depth + 7) & 7;
372 buffer->bytesperline >>= 3;
373 }
374done:
375 return err;
376}
377
378static noinline long v4l1_compat_set_frame_buffer(
379 struct video_buffer *buffer,
380 struct file *file,
381 v4l2_kioctl drv)
382{
383 long err;
384 struct v4l2_framebuffer fbuf;
385
386 memset(&fbuf, 0, sizeof(fbuf));
387 fbuf.base = buffer->base;
388 fbuf.fmt.height = buffer->height;
389 fbuf.fmt.width = buffer->width;
390 switch (buffer->depth) {
391 case 8:
392 fbuf.fmt.pixelformat = V4L2_PIX_FMT_RGB332;
393 break;
394 case 15:
395 fbuf.fmt.pixelformat = V4L2_PIX_FMT_RGB555;
396 break;
397 case 16:
398 fbuf.fmt.pixelformat = V4L2_PIX_FMT_RGB565;
399 break;
400 case 24:
401 fbuf.fmt.pixelformat = V4L2_PIX_FMT_BGR24;
402 break;
403 case 32:
404 fbuf.fmt.pixelformat = V4L2_PIX_FMT_BGR32;
405 break;
406 }
407 fbuf.fmt.bytesperline = buffer->bytesperline;
408 err = drv(file, VIDIOC_S_FBUF, &fbuf);
409 if (err < 0)
410 dprintk("VIDIOCSFBUF / VIDIOC_S_FBUF: %ld\n", err);
411 return err;
412}
413
414static noinline long v4l1_compat_get_win_cap_dimensions(
415 struct video_window *win,
416 struct file *file,
417 v4l2_kioctl drv)
418{
419 long err;
420 struct v4l2_format *fmt;
421
422 fmt = kzalloc(sizeof(*fmt), GFP_KERNEL);
423 if (!fmt) {
424 err = -ENOMEM;
425 return err;
426 }
427 memset(win, 0, sizeof(*win));
428
429 fmt->type = V4L2_BUF_TYPE_VIDEO_OVERLAY;
430 err = drv(file, VIDIOC_G_FMT, fmt);
431 if (err < 0)
432 dprintk("VIDIOCGWIN / VIDIOC_G_WIN: %ld\n", err);
433 if (err == 0) {
434 win->x = fmt->fmt.win.w.left;
435 win->y = fmt->fmt.win.w.top;
436 win->width = fmt->fmt.win.w.width;
437 win->height = fmt->fmt.win.w.height;
438 win->chromakey = fmt->fmt.win.chromakey;
439 win->clips = NULL;
440 win->clipcount = 0;
441 goto done;
442 }
443
444 fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
445 err = drv(file, VIDIOC_G_FMT, fmt);
446 if (err < 0) {
447 dprintk("VIDIOCGWIN / VIDIOC_G_FMT: %ld\n", err);
448 goto done;
449 }
450 win->x = 0;
451 win->y = 0;
452 win->width = fmt->fmt.pix.width;
453 win->height = fmt->fmt.pix.height;
454 win->chromakey = 0;
455 win->clips = NULL;
456 win->clipcount = 0;
457done:
458 kfree(fmt);
459 return err;
460}
461
462static noinline long v4l1_compat_set_win_cap_dimensions(
463 struct video_window *win,
464 struct file *file,
465 v4l2_kioctl drv)
466{
467 long err, err1, err2;
468 struct v4l2_format *fmt;
469
470 fmt = kzalloc(sizeof(*fmt), GFP_KERNEL);
471 if (!fmt) {
472 err = -ENOMEM;
473 return err;
474 }
475 fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
476 drv(file, VIDIOC_STREAMOFF, &fmt->type);
477 err1 = drv(file, VIDIOC_G_FMT, fmt);
478 if (err1 < 0)
479 dprintk("VIDIOCSWIN / VIDIOC_G_FMT: %ld\n", err1);
480 if (err1 == 0) {
481 fmt->fmt.pix.width = win->width;
482 fmt->fmt.pix.height = win->height;
483 fmt->fmt.pix.field = V4L2_FIELD_ANY;
484 fmt->fmt.pix.bytesperline = 0;
485 err = drv(file, VIDIOC_S_FMT, fmt);
486 if (err < 0)
487 dprintk("VIDIOCSWIN / VIDIOC_S_FMT #1: %ld\n",
488 err);
489 win->width = fmt->fmt.pix.width;
490 win->height = fmt->fmt.pix.height;
491 }
492
493 memset(fmt, 0, sizeof(*fmt));
494 fmt->type = V4L2_BUF_TYPE_VIDEO_OVERLAY;
495 fmt->fmt.win.w.left = win->x;
496 fmt->fmt.win.w.top = win->y;
497 fmt->fmt.win.w.width = win->width;
498 fmt->fmt.win.w.height = win->height;
499 fmt->fmt.win.chromakey = win->chromakey;
500 fmt->fmt.win.clips = (void __user *)win->clips;
501 fmt->fmt.win.clipcount = win->clipcount;
502 err2 = drv(file, VIDIOC_S_FMT, fmt);
503 if (err2 < 0)
504 dprintk("VIDIOCSWIN / VIDIOC_S_FMT #2: %ld\n", err2);
505
506 if (err1 != 0 && err2 != 0)
507 err = err1;
508 else
509 err = 0;
510 kfree(fmt);
511 return err;
512}
513
514static noinline long v4l1_compat_turn_preview_on_off(
515 int *on,
516 struct file *file,
517 v4l2_kioctl drv)
518{
519 long err;
520 enum v4l2_buf_type captype = V4L2_BUF_TYPE_VIDEO_CAPTURE;
521
522 if (0 == *on) {
523 /* dirty hack time. But v4l1 has no STREAMOFF
524 * equivalent in the API, and this one at
525 * least comes close ... */
526 drv(file, VIDIOC_STREAMOFF, &captype);
527 }
528 err = drv(file, VIDIOC_OVERLAY, on);
529 if (err < 0)
530 dprintk("VIDIOCCAPTURE / VIDIOC_PREVIEW: %ld\n", err);
531 return err;
532}
533
534static noinline long v4l1_compat_get_input_info(
535 struct video_channel *chan,
536 struct file *file,
537 v4l2_kioctl drv)
538{
539 long err;
540 struct v4l2_input input2;
541 v4l2_std_id sid;
542
543 memset(&input2, 0, sizeof(input2));
544 input2.index = chan->channel;
545 err = drv(file, VIDIOC_ENUMINPUT, &input2);
546 if (err < 0) {
547 dprintk("VIDIOCGCHAN / VIDIOC_ENUMINPUT: "
548 "channel=%d err=%ld\n", chan->channel, err);
549 goto done;
550 }
551 chan->channel = input2.index;
552 memcpy(chan->name, input2.name,
553 min(sizeof(chan->name), sizeof(input2.name)));
554 chan->name[sizeof(chan->name) - 1] = 0;
555 chan->tuners = (input2.type == V4L2_INPUT_TYPE_TUNER) ? 1 : 0;
556 chan->flags = (chan->tuners) ? VIDEO_VC_TUNER : 0;
557 switch (input2.type) {
558 case V4L2_INPUT_TYPE_TUNER:
559 chan->type = VIDEO_TYPE_TV;
560 break;
561 default:
562 case V4L2_INPUT_TYPE_CAMERA:
563 chan->type = VIDEO_TYPE_CAMERA;
564 break;
565 }
566 chan->norm = 0;
567 /* Note: G_STD might not be present for radio receivers,
568 * so we should ignore any errors. */
569 if (drv(file, VIDIOC_G_STD, &sid) == 0) {
570 if (sid & V4L2_STD_PAL)
571 chan->norm = VIDEO_MODE_PAL;
572 if (sid & V4L2_STD_NTSC)
573 chan->norm = VIDEO_MODE_NTSC;
574 if (sid & V4L2_STD_SECAM)
575 chan->norm = VIDEO_MODE_SECAM;
576 if (sid == V4L2_STD_ALL)
577 chan->norm = VIDEO_MODE_AUTO;
578 }
579done:
580 return err;
581}
582
583static noinline long v4l1_compat_set_input(
584 struct video_channel *chan,
585 struct file *file,
586 v4l2_kioctl drv)
587{
588 long err;
589 v4l2_std_id sid = 0;
590
591 err = drv(file, VIDIOC_S_INPUT, &chan->channel);
592 if (err < 0)
593 dprintk("VIDIOCSCHAN / VIDIOC_S_INPUT: %ld\n", err);
594 switch (chan->norm) {
595 case VIDEO_MODE_PAL:
596 sid = V4L2_STD_PAL;
597 break;
598 case VIDEO_MODE_NTSC:
599 sid = V4L2_STD_NTSC;
600 break;
601 case VIDEO_MODE_SECAM:
602 sid = V4L2_STD_SECAM;
603 break;
604 case VIDEO_MODE_AUTO:
605 sid = V4L2_STD_ALL;
606 break;
607 }
608 if (0 != sid) {
609 err = drv(file, VIDIOC_S_STD, &sid);
610 if (err < 0)
611 dprintk("VIDIOCSCHAN / VIDIOC_S_STD: %ld\n", err);
612 }
613 return err;
614}
615
616static noinline long v4l1_compat_get_picture(
617 struct video_picture *pict,
618 struct file *file,
619 v4l2_kioctl drv)
620{
621 long err;
622 struct v4l2_format *fmt;
623
624 fmt = kzalloc(sizeof(*fmt), GFP_KERNEL);
625 if (!fmt) {
626 err = -ENOMEM;
627 return err;
628 }
629
630 pict->brightness = get_v4l_control(file,
631 V4L2_CID_BRIGHTNESS, drv);
632 pict->hue = get_v4l_control(file,
633 V4L2_CID_HUE, drv);
634 pict->contrast = get_v4l_control(file,
635 V4L2_CID_CONTRAST, drv);
636 pict->colour = get_v4l_control(file,
637 V4L2_CID_SATURATION, drv);
638 pict->whiteness = get_v4l_control(file,
639 V4L2_CID_WHITENESS, drv);
640
641 fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
642 err = drv(file, VIDIOC_G_FMT, fmt);
643 if (err < 0) {
644 dprintk("VIDIOCGPICT / VIDIOC_G_FMT: %ld\n", err);
645 goto done;
646 }
647
648 if (fmt->fmt.pix.width)
649 {
650 pict->depth = ((fmt->fmt.pix.bytesperline << 3)
651 + (fmt->fmt.pix.width - 1))
652 / fmt->fmt.pix.width;
653 } else {
654 err = -EINVAL;
655 goto done;
656 }
657
658 pict->palette = pixelformat_to_palette(
659 fmt->fmt.pix.pixelformat);
660done:
661 kfree(fmt);
662 return err;
663}
664
665static noinline long v4l1_compat_set_picture(
666 struct video_picture *pict,
667 struct file *file,
668 v4l2_kioctl drv)
669{
670 long err;
671 struct v4l2_framebuffer fbuf;
672 int mem_err = 0, ovl_err = 0;
673 struct v4l2_format *fmt;
674
675 fmt = kzalloc(sizeof(*fmt), GFP_KERNEL);
676 if (!fmt) {
677 err = -ENOMEM;
678 return err;
679 }
680 memset(&fbuf, 0, sizeof(fbuf));
681
682 set_v4l_control(file,
683 V4L2_CID_BRIGHTNESS, pict->brightness, drv);
684 set_v4l_control(file,
685 V4L2_CID_HUE, pict->hue, drv);
686 set_v4l_control(file,
687 V4L2_CID_CONTRAST, pict->contrast, drv);
688 set_v4l_control(file,
689 V4L2_CID_SATURATION, pict->colour, drv);
690 set_v4l_control(file,
691 V4L2_CID_WHITENESS, pict->whiteness, drv);
692 /*
693 * V4L1 uses this ioctl to set both memory capture and overlay
694 * pixel format, while V4L2 has two different ioctls for this.
695 * Some cards may not support one or the other, and may support
696 * different pixel formats for memory vs overlay.
697 */
698
699 fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
700 err = drv(file, VIDIOC_G_FMT, fmt);
701 /* If VIDIOC_G_FMT failed, then the driver likely doesn't
702 support memory capture. Trying to set the memory capture
703 parameters would be pointless. */
704 if (err < 0) {
705 dprintk("VIDIOCSPICT / VIDIOC_G_FMT: %ld\n", err);
706 mem_err = -1000; /* didn't even try */
707 } else if (fmt->fmt.pix.pixelformat !=
708 palette_to_pixelformat(pict->palette)) {
709 fmt->fmt.pix.pixelformat = palette_to_pixelformat(
710 pict->palette);
711 mem_err = drv(file, VIDIOC_S_FMT, fmt);
712 if (mem_err < 0)
713 dprintk("VIDIOCSPICT / VIDIOC_S_FMT: %d\n",
714 mem_err);
715 }
716
717 err = drv(file, VIDIOC_G_FBUF, &fbuf);
718 /* If VIDIOC_G_FBUF failed, then the driver likely doesn't
719 support overlay. Trying to set the overlay parameters
720 would be quite pointless. */
721 if (err < 0) {
722 dprintk("VIDIOCSPICT / VIDIOC_G_FBUF: %ld\n", err);
723 ovl_err = -1000; /* didn't even try */
724 } else if (fbuf.fmt.pixelformat !=
725 palette_to_pixelformat(pict->palette)) {
726 fbuf.fmt.pixelformat = palette_to_pixelformat(
727 pict->palette);
728 ovl_err = drv(file, VIDIOC_S_FBUF, &fbuf);
729 if (ovl_err < 0)
730 dprintk("VIDIOCSPICT / VIDIOC_S_FBUF: %d\n",
731 ovl_err);
732 }
733 if (ovl_err < 0 && mem_err < 0) {
734 /* ioctl failed, couldn't set either parameter */
735 if (mem_err != -1000)
736 err = mem_err;
737 else if (ovl_err == -EPERM)
738 err = 0;
739 else
740 err = ovl_err;
741 } else
742 err = 0;
743 kfree(fmt);
744 return err;
745}
746
747static noinline long v4l1_compat_get_tuner(
748 struct video_tuner *tun,
749 struct file *file,
750 v4l2_kioctl drv)
751{
752 long err;
753 int i;
754 struct v4l2_tuner tun2;
755 struct v4l2_standard std2;
756 v4l2_std_id sid;
757
758 memset(&tun2, 0, sizeof(tun2));
759 err = drv(file, VIDIOC_G_TUNER, &tun2);
760 if (err < 0) {
761 dprintk("VIDIOCGTUNER / VIDIOC_G_TUNER: %ld\n", err);
762 goto done;
763 }
764 memcpy(tun->name, tun2.name,
765 min(sizeof(tun->name), sizeof(tun2.name)));
766 tun->name[sizeof(tun->name) - 1] = 0;
767 tun->rangelow = tun2.rangelow;
768 tun->rangehigh = tun2.rangehigh;
769 tun->flags = 0;
770 tun->mode = VIDEO_MODE_AUTO;
771
772 for (i = 0; i < 64; i++) {
773 memset(&std2, 0, sizeof(std2));
774 std2.index = i;
775 if (0 != drv(file, VIDIOC_ENUMSTD, &std2))
776 break;
777 if (std2.id & V4L2_STD_PAL)
778 tun->flags |= VIDEO_TUNER_PAL;
779 if (std2.id & V4L2_STD_NTSC)
780 tun->flags |= VIDEO_TUNER_NTSC;
781 if (std2.id & V4L2_STD_SECAM)
782 tun->flags |= VIDEO_TUNER_SECAM;
783 }
784
785 /* Note: G_STD might not be present for radio receivers,
786 * so we should ignore any errors. */
787 if (drv(file, VIDIOC_G_STD, &sid) == 0) {
788 if (sid & V4L2_STD_PAL)
789 tun->mode = VIDEO_MODE_PAL;
790 if (sid & V4L2_STD_NTSC)
791 tun->mode = VIDEO_MODE_NTSC;
792 if (sid & V4L2_STD_SECAM)
793 tun->mode = VIDEO_MODE_SECAM;
794 }
795
796 if (tun2.capability & V4L2_TUNER_CAP_LOW)
797 tun->flags |= VIDEO_TUNER_LOW;
798 if (tun2.rxsubchans & V4L2_TUNER_SUB_STEREO)
799 tun->flags |= VIDEO_TUNER_STEREO_ON;
800 tun->signal = tun2.signal;
801done:
802 return err;
803}
804
805static noinline long v4l1_compat_select_tuner(
806 struct video_tuner *tun,
807 struct file *file,
808 v4l2_kioctl drv)
809{
810 long err;
811 struct v4l2_tuner t;/*84 bytes on x86_64*/
812 memset(&t, 0, sizeof(t));
813
814 t.index = tun->tuner;
815
816 err = drv(file, VIDIOC_S_TUNER, &t);
817 if (err < 0)
818 dprintk("VIDIOCSTUNER / VIDIOC_S_TUNER: %ld\n", err);
819 return err;
820}
821
822static noinline long v4l1_compat_get_frequency(
823 unsigned long *freq,
824 struct file *file,
825 v4l2_kioctl drv)
826{
827 long err;
828 struct v4l2_frequency freq2;
829 memset(&freq2, 0, sizeof(freq2));
830
831 freq2.tuner = 0;
832 err = drv(file, VIDIOC_G_FREQUENCY, &freq2);
833 if (err < 0)
834 dprintk("VIDIOCGFREQ / VIDIOC_G_FREQUENCY: %ld\n", err);
835 if (0 == err)
836 *freq = freq2.frequency;
837 return err;
838}
839
840static noinline long v4l1_compat_set_frequency(
841 unsigned long *freq,
842 struct file *file,
843 v4l2_kioctl drv)
844{
845 long err;
846 struct v4l2_frequency freq2;
847 memset(&freq2, 0, sizeof(freq2));
848
849 drv(file, VIDIOC_G_FREQUENCY, &freq2);
850 freq2.frequency = *freq;
851 err = drv(file, VIDIOC_S_FREQUENCY, &freq2);
852 if (err < 0)
853 dprintk("VIDIOCSFREQ / VIDIOC_S_FREQUENCY: %ld\n", err);
854 return err;
855}
856
857static noinline long v4l1_compat_get_audio(
858 struct video_audio *aud,
859 struct file *file,
860 v4l2_kioctl drv)
861{
862 long err;
863 int i;
864 struct v4l2_queryctrl qctrl2;
865 struct v4l2_audio aud2;
866 struct v4l2_tuner tun2;
867 memset(&aud2, 0, sizeof(aud2));
868
869 err = drv(file, VIDIOC_G_AUDIO, &aud2);
870 if (err < 0) {
871 dprintk("VIDIOCGAUDIO / VIDIOC_G_AUDIO: %ld\n", err);
872 goto done;
873 }
874 memcpy(aud->name, aud2.name,
875 min(sizeof(aud->name), sizeof(aud2.name)));
876 aud->name[sizeof(aud->name) - 1] = 0;
877 aud->audio = aud2.index;
878 aud->flags = 0;
879 i = get_v4l_control(file, V4L2_CID_AUDIO_VOLUME, drv);
880 if (i >= 0) {
881 aud->volume = i;
882 aud->flags |= VIDEO_AUDIO_VOLUME;
883 }
884 i = get_v4l_control(file, V4L2_CID_AUDIO_BASS, drv);
885 if (i >= 0) {
886 aud->bass = i;
887 aud->flags |= VIDEO_AUDIO_BASS;
888 }
889 i = get_v4l_control(file, V4L2_CID_AUDIO_TREBLE, drv);
890 if (i >= 0) {
891 aud->treble = i;
892 aud->flags |= VIDEO_AUDIO_TREBLE;
893 }
894 i = get_v4l_control(file, V4L2_CID_AUDIO_BALANCE, drv);
895 if (i >= 0) {
896 aud->balance = i;
897 aud->flags |= VIDEO_AUDIO_BALANCE;
898 }
899 i = get_v4l_control(file, V4L2_CID_AUDIO_MUTE, drv);
900 if (i >= 0) {
901 if (i)
902 aud->flags |= VIDEO_AUDIO_MUTE;
903 aud->flags |= VIDEO_AUDIO_MUTABLE;
904 }
905 aud->step = 1;
906 qctrl2.id = V4L2_CID_AUDIO_VOLUME;
907 if (drv(file, VIDIOC_QUERYCTRL, &qctrl2) == 0 &&
908 !(qctrl2.flags & V4L2_CTRL_FLAG_DISABLED))
909 aud->step = qctrl2.step;
910 aud->mode = 0;
911
912 memset(&tun2, 0, sizeof(tun2));
913 err = drv(file, VIDIOC_G_TUNER, &tun2);
914 if (err < 0) {
915 dprintk("VIDIOCGAUDIO / VIDIOC_G_TUNER: %ld\n", err);
916 err = 0;
917 goto done;
918 }
919
920 if (tun2.rxsubchans & V4L2_TUNER_SUB_LANG2)
921 aud->mode = VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2;
922 else if (tun2.rxsubchans & V4L2_TUNER_SUB_STEREO)
923 aud->mode = VIDEO_SOUND_STEREO;
924 else if (tun2.rxsubchans & V4L2_TUNER_SUB_MONO)
925 aud->mode = VIDEO_SOUND_MONO;
926done:
927 return err;
928}
929
930static noinline long v4l1_compat_set_audio(
931 struct video_audio *aud,
932 struct file *file,
933 v4l2_kioctl drv)
934{
935 long err;
936 struct v4l2_audio aud2;
937 struct v4l2_tuner tun2;
938
939 memset(&aud2, 0, sizeof(aud2));
940 memset(&tun2, 0, sizeof(tun2));
941
942 aud2.index = aud->audio;
943 err = drv(file, VIDIOC_S_AUDIO, &aud2);
944 if (err < 0) {
945 dprintk("VIDIOCSAUDIO / VIDIOC_S_AUDIO: %ld\n", err);
946 goto done;
947 }
948
949 set_v4l_control(file, V4L2_CID_AUDIO_VOLUME,
950 aud->volume, drv);
951 set_v4l_control(file, V4L2_CID_AUDIO_BASS,
952 aud->bass, drv);
953 set_v4l_control(file, V4L2_CID_AUDIO_TREBLE,
954 aud->treble, drv);
955 set_v4l_control(file, V4L2_CID_AUDIO_BALANCE,
956 aud->balance, drv);
957 set_v4l_control(file, V4L2_CID_AUDIO_MUTE,
958 !!(aud->flags & VIDEO_AUDIO_MUTE), drv);
959
960 err = drv(file, VIDIOC_G_TUNER, &tun2);
961 if (err < 0)
962 dprintk("VIDIOCSAUDIO / VIDIOC_G_TUNER: %ld\n", err);
963 if (err == 0) {
964 switch (aud->mode) {
965 default:
966 case VIDEO_SOUND_MONO:
967 case VIDEO_SOUND_LANG1:
968 tun2.audmode = V4L2_TUNER_MODE_MONO;
969 break;
970 case VIDEO_SOUND_STEREO:
971 tun2.audmode = V4L2_TUNER_MODE_STEREO;
972 break;
973 case VIDEO_SOUND_LANG2:
974 tun2.audmode = V4L2_TUNER_MODE_LANG2;
975 break;
976 }
977 err = drv(file, VIDIOC_S_TUNER, &tun2);
978 if (err < 0)
979 dprintk("VIDIOCSAUDIO / VIDIOC_S_TUNER: %ld\n", err);
980 }
981 err = 0;
982done:
983 return err;
984}
985
986static noinline long v4l1_compat_capture_frame(
987 struct video_mmap *mm,
988 struct file *file,
989 v4l2_kioctl drv)
990{
991 long err;
992 enum v4l2_buf_type captype = V4L2_BUF_TYPE_VIDEO_CAPTURE;
993 struct v4l2_buffer buf;
994 struct v4l2_format *fmt;
995
996 fmt = kzalloc(sizeof(*fmt), GFP_KERNEL);
997 if (!fmt) {
998 err = -ENOMEM;
999 return err;
1000 }
1001 memset(&buf, 0, sizeof(buf));
1002
1003 fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1004 err = drv(file, VIDIOC_G_FMT, fmt);
1005 if (err < 0) {
1006 dprintk("VIDIOCMCAPTURE / VIDIOC_G_FMT: %ld\n", err);
1007 goto done;
1008 }
1009 if (mm->width != fmt->fmt.pix.width ||
1010 mm->height != fmt->fmt.pix.height ||
1011 palette_to_pixelformat(mm->format) !=
1012 fmt->fmt.pix.pixelformat) {
1013 /* New capture format... */
1014 fmt->fmt.pix.width = mm->width;
1015 fmt->fmt.pix.height = mm->height;
1016 fmt->fmt.pix.pixelformat =
1017 palette_to_pixelformat(mm->format);
1018 fmt->fmt.pix.field = V4L2_FIELD_ANY;
1019 fmt->fmt.pix.bytesperline = 0;
1020 err = drv(file, VIDIOC_S_FMT, fmt);
1021 if (err < 0) {
1022 dprintk("VIDIOCMCAPTURE / VIDIOC_S_FMT: %ld\n", err);
1023 goto done;
1024 }
1025 }
1026 buf.index = mm->frame;
1027 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1028 err = drv(file, VIDIOC_QUERYBUF, &buf);
1029 if (err < 0) {
1030 dprintk("VIDIOCMCAPTURE / VIDIOC_QUERYBUF: %ld\n", err);
1031 goto done;
1032 }
1033 err = drv(file, VIDIOC_QBUF, &buf);
1034 if (err < 0) {
1035 dprintk("VIDIOCMCAPTURE / VIDIOC_QBUF: %ld\n", err);
1036 goto done;
1037 }
1038 err = drv(file, VIDIOC_STREAMON, &captype);
1039 if (err < 0)
1040 dprintk("VIDIOCMCAPTURE / VIDIOC_STREAMON: %ld\n", err);
1041done:
1042 kfree(fmt);
1043 return err;
1044}
1045
1046static noinline long v4l1_compat_sync(
1047 int *i,
1048 struct file *file,
1049 v4l2_kioctl drv)
1050{
1051 long err;
1052 enum v4l2_buf_type captype = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1053 struct v4l2_buffer buf;
1054 struct poll_wqueues *pwq;
1055
1056 memset(&buf, 0, sizeof(buf));
1057 buf.index = *i;
1058 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1059 err = drv(file, VIDIOC_QUERYBUF, &buf);
1060 if (err < 0) {
1061 /* No such buffer */
1062 dprintk("VIDIOCSYNC / VIDIOC_QUERYBUF: %ld\n", err);
1063 goto done;
1064 }
1065 if (!(buf.flags & V4L2_BUF_FLAG_MAPPED)) {
1066 /* Buffer is not mapped */
1067 err = -EINVAL;
1068 goto done;
1069 }
1070
1071 /* make sure capture actually runs so we don't block forever */
1072 err = drv(file, VIDIOC_STREAMON, &captype);
1073 if (err < 0) {
1074 dprintk("VIDIOCSYNC / VIDIOC_STREAMON: %ld\n", err);
1075 goto done;
1076 }
1077
1078 pwq = kmalloc(sizeof(*pwq), GFP_KERNEL);
1079 /* Loop as long as the buffer is queued, but not done */
1080 while ((buf.flags & (V4L2_BUF_FLAG_QUEUED | V4L2_BUF_FLAG_DONE))
1081 == V4L2_BUF_FLAG_QUEUED) {
1082 err = poll_one(file, pwq);
1083 if (err < 0 || /* error or sleep was interrupted */
1084 err == 0) /* timeout? Shouldn't occur. */
1085 break;
1086 err = drv(file, VIDIOC_QUERYBUF, &buf);
1087 if (err < 0)
1088 dprintk("VIDIOCSYNC / VIDIOC_QUERYBUF: %ld\n", err);
1089 }
1090 kfree(pwq);
1091 if (!(buf.flags & V4L2_BUF_FLAG_DONE)) /* not done */
1092 goto done;
1093 do {
1094 err = drv(file, VIDIOC_DQBUF, &buf);
1095 if (err < 0)
1096 dprintk("VIDIOCSYNC / VIDIOC_DQBUF: %ld\n", err);
1097 } while (err == 0 && buf.index != *i);
1098done:
1099 return err;
1100}
1101
1102static noinline long v4l1_compat_get_vbi_format(
1103 struct vbi_format *fmt,
1104 struct file *file,
1105 v4l2_kioctl drv)
1106{
1107 long err;
1108 struct v4l2_format *fmt2;
1109
1110 fmt2 = kzalloc(sizeof(*fmt2), GFP_KERNEL);
1111 if (!fmt2) {
1112 err = -ENOMEM;
1113 return err;
1114 }
1115 fmt2->type = V4L2_BUF_TYPE_VBI_CAPTURE;
1116
1117 err = drv(file, VIDIOC_G_FMT, fmt2);
1118 if (err < 0) {
1119 dprintk("VIDIOCGVBIFMT / VIDIOC_G_FMT: %ld\n", err);
1120 goto done;
1121 }
1122 if (fmt2->fmt.vbi.sample_format != V4L2_PIX_FMT_GREY) {
1123 err = -EINVAL;
1124 goto done;
1125 }
1126 memset(fmt, 0, sizeof(*fmt));
1127 fmt->samples_per_line = fmt2->fmt.vbi.samples_per_line;
1128 fmt->sampling_rate = fmt2->fmt.vbi.sampling_rate;
1129 fmt->sample_format = VIDEO_PALETTE_RAW;
1130 fmt->start[0] = fmt2->fmt.vbi.start[0];
1131 fmt->count[0] = fmt2->fmt.vbi.count[0];
1132 fmt->start[1] = fmt2->fmt.vbi.start[1];
1133 fmt->count[1] = fmt2->fmt.vbi.count[1];
1134 fmt->flags = fmt2->fmt.vbi.flags & 0x03;
1135done:
1136 kfree(fmt2);
1137 return err;
1138}
1139
1140static noinline long v4l1_compat_set_vbi_format(
1141 struct vbi_format *fmt,
1142 struct file *file,
1143 v4l2_kioctl drv)
1144{
1145 long err;
1146 struct v4l2_format *fmt2 = NULL;
1147
1148 if (VIDEO_PALETTE_RAW != fmt->sample_format) {
1149 err = -EINVAL;
1150 return err;
1151 }
1152
1153 fmt2 = kzalloc(sizeof(*fmt2), GFP_KERNEL);
1154 if (!fmt2) {
1155 err = -ENOMEM;
1156 return err;
1157 }
1158 fmt2->type = V4L2_BUF_TYPE_VBI_CAPTURE;
1159 fmt2->fmt.vbi.samples_per_line = fmt->samples_per_line;
1160 fmt2->fmt.vbi.sampling_rate = fmt->sampling_rate;
1161 fmt2->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
1162 fmt2->fmt.vbi.start[0] = fmt->start[0];
1163 fmt2->fmt.vbi.count[0] = fmt->count[0];
1164 fmt2->fmt.vbi.start[1] = fmt->start[1];
1165 fmt2->fmt.vbi.count[1] = fmt->count[1];
1166 fmt2->fmt.vbi.flags = fmt->flags;
1167 err = drv(file, VIDIOC_TRY_FMT, fmt2);
1168 if (err < 0) {
1169 dprintk("VIDIOCSVBIFMT / VIDIOC_TRY_FMT: %ld\n", err);
1170 goto done;
1171 }
1172
1173 if (fmt2->fmt.vbi.samples_per_line != fmt->samples_per_line ||
1174 fmt2->fmt.vbi.sampling_rate != fmt->sampling_rate ||
1175 fmt2->fmt.vbi.sample_format != V4L2_PIX_FMT_GREY ||
1176 fmt2->fmt.vbi.start[0] != fmt->start[0] ||
1177 fmt2->fmt.vbi.count[0] != fmt->count[0] ||
1178 fmt2->fmt.vbi.start[1] != fmt->start[1] ||
1179 fmt2->fmt.vbi.count[1] != fmt->count[1] ||
1180 fmt2->fmt.vbi.flags != fmt->flags) {
1181 err = -EINVAL;
1182 goto done;
1183 }
1184 err = drv(file, VIDIOC_S_FMT, fmt2);
1185 if (err < 0)
1186 dprintk("VIDIOCSVBIFMT / VIDIOC_S_FMT: %ld\n", err);
1187done:
1188 kfree(fmt2);
1189 return err;
1190}
1191
1192/*
1193 * This function is exported.
1194 */
1195long
1196v4l_compat_translate_ioctl(struct file *file,
1197 int cmd,
1198 void *arg,
1199 v4l2_kioctl drv)
1200{
1201 long err;
1202
1203 switch (cmd) {
1204 case VIDIOCGCAP: /* capability */
1205 err = v4l1_compat_get_capabilities(arg, file, drv);
1206 break;
1207 case VIDIOCGFBUF: /* get frame buffer */
1208 err = v4l1_compat_get_frame_buffer(arg, file, drv);
1209 break;
1210 case VIDIOCSFBUF: /* set frame buffer */
1211 err = v4l1_compat_set_frame_buffer(arg, file, drv);
1212 break;
1213 case VIDIOCGWIN: /* get window or capture dimensions */
1214 err = v4l1_compat_get_win_cap_dimensions(arg, file, drv);
1215 break;
1216 case VIDIOCSWIN: /* set window and/or capture dimensions */
1217 err = v4l1_compat_set_win_cap_dimensions(arg, file, drv);
1218 break;
1219 case VIDIOCCAPTURE: /* turn on/off preview */
1220 err = v4l1_compat_turn_preview_on_off(arg, file, drv);
1221 break;
1222 case VIDIOCGCHAN: /* get input information */
1223 err = v4l1_compat_get_input_info(arg, file, drv);
1224 break;
1225 case VIDIOCSCHAN: /* set input */
1226 err = v4l1_compat_set_input(arg, file, drv);
1227 break;
1228 case VIDIOCGPICT: /* get tone controls & partial capture format */
1229 err = v4l1_compat_get_picture(arg, file, drv);
1230 break;
1231 case VIDIOCSPICT: /* set tone controls & partial capture format */
1232 err = v4l1_compat_set_picture(arg, file, drv);
1233 break;
1234 case VIDIOCGTUNER: /* get tuner information */
1235 err = v4l1_compat_get_tuner(arg, file, drv);
1236 break;
1237 case VIDIOCSTUNER: /* select a tuner input */
1238 err = v4l1_compat_select_tuner(arg, file, drv);
1239 break;
1240 case VIDIOCGFREQ: /* get frequency */
1241 err = v4l1_compat_get_frequency(arg, file, drv);
1242 break;
1243 case VIDIOCSFREQ: /* set frequency */
1244 err = v4l1_compat_set_frequency(arg, file, drv);
1245 break;
1246 case VIDIOCGAUDIO: /* get audio properties/controls */
1247 err = v4l1_compat_get_audio(arg, file, drv);
1248 break;
1249 case VIDIOCSAUDIO: /* set audio controls */
1250 err = v4l1_compat_set_audio(arg, file, drv);
1251 break;
1252 case VIDIOCMCAPTURE: /* capture a frame */
1253 err = v4l1_compat_capture_frame(arg, file, drv);
1254 break;
1255 case VIDIOCSYNC: /* wait for a frame */
1256 err = v4l1_compat_sync(arg, file, drv);
1257 break;
1258 case VIDIOCGVBIFMT: /* query VBI data capture format */
1259 err = v4l1_compat_get_vbi_format(arg, file, drv);
1260 break;
1261 case VIDIOCSVBIFMT:
1262 err = v4l1_compat_set_vbi_format(arg, file, drv);
1263 break;
1264 default:
1265 err = -ENOIOCTLCMD;
1266 break;
1267 }
1268
1269 return err;
1270}
1271EXPORT_SYMBOL(v4l_compat_translate_ioctl);
1272
1273/*
1274 * Local variables:
1275 * c-basic-offset: 8
1276 * End:
1277 */
diff --git a/drivers/media/video/v4l2-common.c b/drivers/media/video/v4l2-common.c
index b5eb1f3950b1..3f0871b550ad 100644
--- a/drivers/media/video/v4l2-common.c
+++ b/drivers/media/video/v4l2-common.c
@@ -150,7 +150,7 @@ EXPORT_SYMBOL(v4l2_prio_check);
150 struct v4l2_queryctrl and the available menu items. Note that 150 struct v4l2_queryctrl and the available menu items. Note that
151 menu_items may be NULL, in that case it is ignored. */ 151 menu_items may be NULL, in that case it is ignored. */
152int v4l2_ctrl_check(struct v4l2_ext_control *ctrl, struct v4l2_queryctrl *qctrl, 152int v4l2_ctrl_check(struct v4l2_ext_control *ctrl, struct v4l2_queryctrl *qctrl,
153 const char **menu_items) 153 const char * const *menu_items)
154{ 154{
155 if (qctrl->flags & V4L2_CTRL_FLAG_DISABLED) 155 if (qctrl->flags & V4L2_CTRL_FLAG_DISABLED)
156 return -EINVAL; 156 return -EINVAL;
@@ -199,7 +199,7 @@ EXPORT_SYMBOL(v4l2_ctrl_query_fill);
199 If menu_items is NULL, then the menu items are retrieved using 199 If menu_items is NULL, then the menu items are retrieved using
200 v4l2_ctrl_get_menu. */ 200 v4l2_ctrl_get_menu. */
201int v4l2_ctrl_query_menu(struct v4l2_querymenu *qmenu, struct v4l2_queryctrl *qctrl, 201int v4l2_ctrl_query_menu(struct v4l2_querymenu *qmenu, struct v4l2_queryctrl *qctrl,
202 const char **menu_items) 202 const char * const *menu_items)
203{ 203{
204 int i; 204 int i;
205 205
@@ -222,7 +222,7 @@ EXPORT_SYMBOL(v4l2_ctrl_query_menu);
222 Use this if there are 'holes' in the list of valid menu items. */ 222 Use this if there are 'holes' in the list of valid menu items. */
223int v4l2_ctrl_query_menu_valid_items(struct v4l2_querymenu *qmenu, const u32 *ids) 223int v4l2_ctrl_query_menu_valid_items(struct v4l2_querymenu *qmenu, const u32 *ids)
224{ 224{
225 const char **menu_items = v4l2_ctrl_get_menu(qmenu->id); 225 const char * const *menu_items = v4l2_ctrl_get_menu(qmenu->id);
226 226
227 qmenu->reserved = 0; 227 qmenu->reserved = 0;
228 if (menu_items == NULL || ids == NULL) 228 if (menu_items == NULL || ids == NULL)
diff --git a/drivers/media/video/v4l2-compat-ioctl32.c b/drivers/media/video/v4l2-compat-ioctl32.c
index e30e8dfb6205..dc82eb83c1d4 100644
--- a/drivers/media/video/v4l2-compat-ioctl32.c
+++ b/drivers/media/video/v4l2-compat-ioctl32.c
@@ -15,219 +15,12 @@
15 15
16#include <linux/compat.h> 16#include <linux/compat.h>
17#define __OLD_VIDIOC_ /* To allow fixing old calls*/ 17#define __OLD_VIDIOC_ /* To allow fixing old calls*/
18#include <linux/videodev.h>
19#include <linux/videodev2.h> 18#include <linux/videodev2.h>
20#include <linux/module.h> 19#include <linux/module.h>
21#include <media/v4l2-ioctl.h> 20#include <media/v4l2-ioctl.h>
22 21
23#ifdef CONFIG_COMPAT 22#ifdef CONFIG_COMPAT
24 23
25#ifdef CONFIG_VIDEO_V4L1_COMPAT
26struct video_tuner32 {
27 compat_int_t tuner;
28 char name[32];
29 compat_ulong_t rangelow, rangehigh;
30 u32 flags; /* It is really u32 in videodev.h */
31 u16 mode, signal;
32};
33
34static int get_video_tuner32(struct video_tuner *kp, struct video_tuner32 __user *up)
35{
36 if (!access_ok(VERIFY_READ, up, sizeof(struct video_tuner32)) ||
37 get_user(kp->tuner, &up->tuner) ||
38 copy_from_user(kp->name, up->name, 32) ||
39 get_user(kp->rangelow, &up->rangelow) ||
40 get_user(kp->rangehigh, &up->rangehigh) ||
41 get_user(kp->flags, &up->flags) ||
42 get_user(kp->mode, &up->mode) ||
43 get_user(kp->signal, &up->signal))
44 return -EFAULT;
45 return 0;
46}
47
48static int put_video_tuner32(struct video_tuner *kp, struct video_tuner32 __user *up)
49{
50 if (!access_ok(VERIFY_WRITE, up, sizeof(struct video_tuner32)) ||
51 put_user(kp->tuner, &up->tuner) ||
52 copy_to_user(up->name, kp->name, 32) ||
53 put_user(kp->rangelow, &up->rangelow) ||
54 put_user(kp->rangehigh, &up->rangehigh) ||
55 put_user(kp->flags, &up->flags) ||
56 put_user(kp->mode, &up->mode) ||
57 put_user(kp->signal, &up->signal))
58 return -EFAULT;
59 return 0;
60}
61
62struct video_buffer32 {
63 compat_caddr_t base;
64 compat_int_t height, width, depth, bytesperline;
65};
66
67static int get_video_buffer32(struct video_buffer *kp, struct video_buffer32 __user *up)
68{
69 u32 tmp;
70
71 if (!access_ok(VERIFY_READ, up, sizeof(struct video_buffer32)) ||
72 get_user(tmp, &up->base) ||
73 get_user(kp->height, &up->height) ||
74 get_user(kp->width, &up->width) ||
75 get_user(kp->depth, &up->depth) ||
76 get_user(kp->bytesperline, &up->bytesperline))
77 return -EFAULT;
78
79 /* This is actually a physical address stored
80 * as a void pointer.
81 */
82 kp->base = (void *)(unsigned long) tmp;
83
84 return 0;
85}
86
87static int put_video_buffer32(struct video_buffer *kp, struct video_buffer32 __user *up)
88{
89 u32 tmp = (u32)((unsigned long)kp->base);
90
91 if (!access_ok(VERIFY_WRITE, up, sizeof(struct video_buffer32)) ||
92 put_user(tmp, &up->base) ||
93 put_user(kp->height, &up->height) ||
94 put_user(kp->width, &up->width) ||
95 put_user(kp->depth, &up->depth) ||
96 put_user(kp->bytesperline, &up->bytesperline))
97 return -EFAULT;
98 return 0;
99}
100
101struct video_clip32 {
102 s32 x, y, width, height; /* It's really s32 in videodev.h */
103 compat_caddr_t next;
104};
105
106struct video_window32 {
107 u32 x, y, width, height, chromakey, flags;
108 compat_caddr_t clips;
109 compat_int_t clipcount;
110};
111
112static int get_video_window32(struct video_window *kp, struct video_window32 __user *up)
113{
114 struct video_clip __user *uclips;
115 struct video_clip __user *kclips;
116 compat_caddr_t p;
117 int nclips;
118
119 if (!access_ok(VERIFY_READ, up, sizeof(struct video_window32)))
120 return -EFAULT;
121
122 if (get_user(nclips, &up->clipcount))
123 return -EFAULT;
124
125 if (!access_ok(VERIFY_READ, up, sizeof(struct video_window32)) ||
126 get_user(kp->x, &up->x) ||
127 get_user(kp->y, &up->y) ||
128 get_user(kp->width, &up->width) ||
129 get_user(kp->height, &up->height) ||
130 get_user(kp->chromakey, &up->chromakey) ||
131 get_user(kp->flags, &up->flags) ||
132 get_user(kp->clipcount, &up->clipcount))
133 return -EFAULT;
134
135 nclips = kp->clipcount;
136 kp->clips = NULL;
137
138 if (nclips == 0)
139 return 0;
140 if (get_user(p, &up->clips))
141 return -EFAULT;
142 uclips = compat_ptr(p);
143
144 /* If nclips < 0, then it is a clipping bitmap of size
145 VIDEO_CLIPMAP_SIZE */
146 if (nclips < 0) {
147 if (!access_ok(VERIFY_READ, uclips, VIDEO_CLIPMAP_SIZE))
148 return -EFAULT;
149 kp->clips = compat_alloc_user_space(VIDEO_CLIPMAP_SIZE);
150 if (copy_in_user(kp->clips, uclips, VIDEO_CLIPMAP_SIZE))
151 return -EFAULT;
152 return 0;
153 }
154
155 /* Otherwise it is an array of video_clip structs. */
156 if (!access_ok(VERIFY_READ, uclips, nclips * sizeof(struct video_clip)))
157 return -EFAULT;
158
159 kp->clips = compat_alloc_user_space(nclips * sizeof(struct video_clip));
160 kclips = kp->clips;
161 while (nclips--) {
162 int err;
163
164 err = copy_in_user(&kclips->x, &uclips->x, sizeof(kclips->x));
165 err |= copy_in_user(&kclips->y, &uclips->y, sizeof(kclips->y));
166 err |= copy_in_user(&kclips->width, &uclips->width, sizeof(kclips->width));
167 err |= copy_in_user(&kclips->height, &uclips->height, sizeof(kclips->height));
168 kclips->next = NULL;
169 if (err)
170 return -EFAULT;
171 kclips++;
172 uclips++;
173 }
174 return 0;
175}
176
177/* You get back everything except the clips... */
178static int put_video_window32(struct video_window *kp, struct video_window32 __user *up)
179{
180 if (!access_ok(VERIFY_WRITE, up, sizeof(struct video_window32)) ||
181 put_user(kp->x, &up->x) ||
182 put_user(kp->y, &up->y) ||
183 put_user(kp->width, &up->width) ||
184 put_user(kp->height, &up->height) ||
185 put_user(kp->chromakey, &up->chromakey) ||
186 put_user(kp->flags, &up->flags) ||
187 put_user(kp->clipcount, &up->clipcount))
188 return -EFAULT;
189 return 0;
190}
191
192struct video_code32 {
193 char loadwhat[16]; /* name or tag of file being passed */
194 compat_int_t datasize;
195 compat_uptr_t data;
196};
197
198static struct video_code __user *get_microcode32(struct video_code32 *kp)
199{
200 struct video_code __user *up;
201
202 up = compat_alloc_user_space(sizeof(*up));
203
204 /*
205 * NOTE! We don't actually care if these fail. If the
206 * user address is invalid, the native ioctl will do
207 * the error handling for us
208 */
209 (void) copy_to_user(up->loadwhat, kp->loadwhat, sizeof(up->loadwhat));
210 (void) put_user(kp->datasize, &up->datasize);
211 (void) put_user(compat_ptr(kp->data), &up->data);
212 return up;
213}
214
215#define VIDIOCGTUNER32 _IOWR('v', 4, struct video_tuner32)
216#define VIDIOCSTUNER32 _IOW('v', 5, struct video_tuner32)
217#define VIDIOCGWIN32 _IOR('v', 9, struct video_window32)
218#define VIDIOCSWIN32 _IOW('v', 10, struct video_window32)
219#define VIDIOCGFBUF32 _IOR('v', 11, struct video_buffer32)
220#define VIDIOCSFBUF32 _IOW('v', 12, struct video_buffer32)
221#define VIDIOCGFREQ32 _IOR('v', 14, u32)
222#define VIDIOCSFREQ32 _IOW('v', 15, u32)
223#define VIDIOCSMICROCODE32 _IOW('v', 27, struct video_code32)
224
225#define VIDIOCCAPTURE32 _IOW('v', 8, s32)
226#define VIDIOCSYNC32 _IOW('v', 18, s32)
227#define VIDIOCSWRITEMODE32 _IOW('v', 25, s32)
228
229#endif
230
231static long native_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 24static long native_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
232{ 25{
233 long ret = -ENOIOCTLCMD; 26 long ret = -ENOIOCTLCMD;
@@ -372,8 +165,6 @@ static int get_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 __user
372 if (copy_from_user(kp, up, sizeof(kp->fmt.raw_data))) 165 if (copy_from_user(kp, up, sizeof(kp->fmt.raw_data)))
373 return -EFAULT; 166 return -EFAULT;
374 return 0; 167 return 0;
375 case 0:
376 return -EINVAL;
377 default: 168 default:
378 printk(KERN_INFO "compat_ioctl32: unexpected VIDIOC_FMT type %d\n", 169 printk(KERN_INFO "compat_ioctl32: unexpected VIDIOC_FMT type %d\n",
379 kp->type); 170 kp->type);
@@ -403,8 +194,6 @@ static int put_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 __user
403 if (copy_to_user(up, kp, sizeof(up->fmt.raw_data))) 194 if (copy_to_user(up, kp, sizeof(up->fmt.raw_data)))
404 return -EFAULT; 195 return -EFAULT;
405 return 0; 196 return 0;
406 case 0:
407 return -EINVAL;
408 default: 197 default:
409 printk(KERN_INFO "compat_ioctl32: unexpected VIDIOC_FMT type %d\n", 198 printk(KERN_INFO "compat_ioctl32: unexpected VIDIOC_FMT type %d\n",
410 kp->type); 199 kp->type);
@@ -741,13 +530,6 @@ static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
741static long do_video_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 530static long do_video_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
742{ 531{
743 union { 532 union {
744#ifdef CONFIG_VIDEO_V4L1_COMPAT
745 struct video_tuner vt;
746 struct video_buffer vb;
747 struct video_window vw;
748 struct video_code32 vc;
749 struct video_audio va;
750#endif
751 struct v4l2_format v2f; 533 struct v4l2_format v2f;
752 struct v4l2_buffer v2b; 534 struct v4l2_buffer v2b;
753 struct v4l2_framebuffer v2fb; 535 struct v4l2_framebuffer v2fb;
@@ -763,17 +545,6 @@ static long do_video_ioctl(struct file *file, unsigned int cmd, unsigned long ar
763 545
764 /* First, convert the command. */ 546 /* First, convert the command. */
765 switch (cmd) { 547 switch (cmd) {
766#ifdef CONFIG_VIDEO_V4L1_COMPAT
767 case VIDIOCGTUNER32: cmd = VIDIOCGTUNER; break;
768 case VIDIOCSTUNER32: cmd = VIDIOCSTUNER; break;
769 case VIDIOCGWIN32: cmd = VIDIOCGWIN; break;
770 case VIDIOCSWIN32: cmd = VIDIOCSWIN; break;
771 case VIDIOCGFBUF32: cmd = VIDIOCGFBUF; break;
772 case VIDIOCSFBUF32: cmd = VIDIOCSFBUF; break;
773 case VIDIOCGFREQ32: cmd = VIDIOCGFREQ; break;
774 case VIDIOCSFREQ32: cmd = VIDIOCSFREQ; break;
775 case VIDIOCSMICROCODE32: cmd = VIDIOCSMICROCODE; break;
776#endif
777 case VIDIOC_G_FMT32: cmd = VIDIOC_G_FMT; break; 548 case VIDIOC_G_FMT32: cmd = VIDIOC_G_FMT; break;
778 case VIDIOC_S_FMT32: cmd = VIDIOC_S_FMT; break; 549 case VIDIOC_S_FMT32: cmd = VIDIOC_S_FMT; break;
779 case VIDIOC_QUERYBUF32: cmd = VIDIOC_QUERYBUF; break; 550 case VIDIOC_QUERYBUF32: cmd = VIDIOC_QUERYBUF; break;
@@ -800,46 +571,6 @@ static long do_video_ioctl(struct file *file, unsigned int cmd, unsigned long ar
800 } 571 }
801 572
802 switch (cmd) { 573 switch (cmd) {
803#ifdef CONFIG_VIDEO_V4L1_COMPAT
804 case VIDIOCSTUNER:
805 case VIDIOCGTUNER:
806 err = get_video_tuner32(&karg.vt, up);
807 compatible_arg = 0;
808 break;
809
810 case VIDIOCSFBUF:
811 err = get_video_buffer32(&karg.vb, up);
812 compatible_arg = 0;
813 break;
814
815 case VIDIOCSWIN:
816 err = get_video_window32(&karg.vw, up);
817 compatible_arg = 0;
818 break;
819
820 case VIDIOCGWIN:
821 case VIDIOCGFBUF:
822 case VIDIOCGFREQ:
823 compatible_arg = 0;
824 break;
825
826 case VIDIOCSMICROCODE:
827 /* Copy the 32-bit "video_code32" to kernel space */
828 if (copy_from_user(&karg.vc, up, sizeof(karg.vc)))
829 return -EFAULT;
830 /* Convert the 32-bit version to a 64-bit version in user space */
831 up = get_microcode32(&karg.vc);
832 break;
833
834 case VIDIOCSFREQ:
835 err = get_user(karg.vx, (u32 __user *)up);
836 compatible_arg = 0;
837 break;
838
839 case VIDIOCCAPTURE:
840 case VIDIOCSYNC:
841 case VIDIOCSWRITEMODE:
842#endif
843 case VIDIOC_OVERLAY: 574 case VIDIOC_OVERLAY:
844 case VIDIOC_STREAMON: 575 case VIDIOC_STREAMON:
845 case VIDIOC_STREAMOFF: 576 case VIDIOC_STREAMOFF:
@@ -922,23 +653,6 @@ static long do_video_ioctl(struct file *file, unsigned int cmd, unsigned long ar
922 return err; 653 return err;
923 654
924 switch (cmd) { 655 switch (cmd) {
925#ifdef CONFIG_VIDEO_V4L1_COMPAT
926 case VIDIOCGTUNER:
927 err = put_video_tuner32(&karg.vt, up);
928 break;
929
930 case VIDIOCGWIN:
931 err = put_video_window32(&karg.vw, up);
932 break;
933
934 case VIDIOCGFBUF:
935 err = put_video_buffer32(&karg.vb, up);
936 break;
937
938 case VIDIOCGFREQ:
939 err = put_user(((u32)karg.vx), (u32 __user *)up);
940 break;
941#endif
942 case VIDIOC_S_INPUT: 656 case VIDIOC_S_INPUT:
943 case VIDIOC_S_OUTPUT: 657 case VIDIOC_S_OUTPUT:
944 case VIDIOC_G_INPUT: 658 case VIDIOC_G_INPUT:
@@ -981,37 +695,6 @@ long v4l2_compat_ioctl32(struct file *file, unsigned int cmd, unsigned long arg)
981 return ret; 695 return ret;
982 696
983 switch (cmd) { 697 switch (cmd) {
984#ifdef CONFIG_VIDEO_V4L1_COMPAT
985 case VIDIOCGCAP:
986 case VIDIOCGCHAN:
987 case VIDIOCSCHAN:
988 case VIDIOCGTUNER32:
989 case VIDIOCSTUNER32:
990 case VIDIOCGPICT:
991 case VIDIOCSPICT:
992 case VIDIOCCAPTURE32:
993 case VIDIOCGWIN32:
994 case VIDIOCSWIN32:
995 case VIDIOCGFBUF32:
996 case VIDIOCSFBUF32:
997 case VIDIOCKEY:
998 case VIDIOCGFREQ32:
999 case VIDIOCSFREQ32:
1000 case VIDIOCGAUDIO:
1001 case VIDIOCSAUDIO:
1002 case VIDIOCSYNC32:
1003 case VIDIOCMCAPTURE:
1004 case VIDIOCGMBUF:
1005 case VIDIOCGUNIT:
1006 case VIDIOCGCAPTURE:
1007 case VIDIOCSCAPTURE:
1008 case VIDIOCSPLAYMODE:
1009 case VIDIOCSWRITEMODE32:
1010 case VIDIOCGPLAYINFO:
1011 case VIDIOCSMICROCODE32:
1012 case VIDIOCGVBIFMT:
1013 case VIDIOCSVBIFMT:
1014#endif
1015#ifdef __OLD_VIDIOC_ 698#ifdef __OLD_VIDIOC_
1016 case VIDIOC_OVERLAY32_OLD: 699 case VIDIOC_OVERLAY32_OLD:
1017 case VIDIOC_S_PARM_OLD: 700 case VIDIOC_S_PARM_OLD:
@@ -1096,19 +779,6 @@ long v4l2_compat_ioctl32(struct file *file, unsigned int cmd, unsigned long arg)
1096 ret = do_video_ioctl(file, cmd, arg); 779 ret = do_video_ioctl(file, cmd, arg);
1097 break; 780 break;
1098 781
1099#ifdef CONFIG_VIDEO_V4L1_COMPAT
1100 /* BTTV specific... */
1101 case _IOW('v', BASE_VIDIOCPRIVATE+0, char [256]):
1102 case _IOR('v', BASE_VIDIOCPRIVATE+1, char [256]):
1103 case _IOR('v' , BASE_VIDIOCPRIVATE+2, unsigned int):
1104 case _IOW('v' , BASE_VIDIOCPRIVATE+3, char [16]): /* struct bttv_pll_info */
1105 case _IOR('v' , BASE_VIDIOCPRIVATE+4, int):
1106 case _IOR('v' , BASE_VIDIOCPRIVATE+5, int):
1107 case _IOR('v' , BASE_VIDIOCPRIVATE+6, int):
1108 case _IOR('v' , BASE_VIDIOCPRIVATE+7, int):
1109 ret = native_ioctl(file, cmd, (unsigned long)compat_ptr(arg));
1110 break;
1111#endif
1112 default: 782 default:
1113 printk(KERN_WARNING "compat_ioctl32: " 783 printk(KERN_WARNING "compat_ioctl32: "
1114 "unknown ioctl '%c', dir=%d, #%d (0x%08x)\n", 784 "unknown ioctl '%c', dir=%d, #%d (0x%08x)\n",
diff --git a/drivers/media/video/v4l2-ctrls.c b/drivers/media/video/v4l2-ctrls.c
index 9d2502cd03ff..8f81efcfcf56 100644
--- a/drivers/media/video/v4l2-ctrls.c
+++ b/drivers/media/video/v4l2-ctrls.c
@@ -38,15 +38,15 @@ struct ctrl_helper {
38 the given control ID. The pointer array ends with a NULL pointer. 38 the given control ID. The pointer array ends with a NULL pointer.
39 An empty string signifies a menu entry that is invalid. This allows 39 An empty string signifies a menu entry that is invalid. This allows
40 drivers to disable certain options if it is not supported. */ 40 drivers to disable certain options if it is not supported. */
41const char **v4l2_ctrl_get_menu(u32 id) 41const char * const *v4l2_ctrl_get_menu(u32 id)
42{ 42{
43 static const char *mpeg_audio_sampling_freq[] = { 43 static const char * const mpeg_audio_sampling_freq[] = {
44 "44.1 kHz", 44 "44.1 kHz",
45 "48 kHz", 45 "48 kHz",
46 "32 kHz", 46 "32 kHz",
47 NULL 47 NULL
48 }; 48 };
49 static const char *mpeg_audio_encoding[] = { 49 static const char * const mpeg_audio_encoding[] = {
50 "MPEG-1/2 Layer I", 50 "MPEG-1/2 Layer I",
51 "MPEG-1/2 Layer II", 51 "MPEG-1/2 Layer II",
52 "MPEG-1/2 Layer III", 52 "MPEG-1/2 Layer III",
@@ -54,7 +54,7 @@ const char **v4l2_ctrl_get_menu(u32 id)
54 "AC-3", 54 "AC-3",
55 NULL 55 NULL
56 }; 56 };
57 static const char *mpeg_audio_l1_bitrate[] = { 57 static const char * const mpeg_audio_l1_bitrate[] = {
58 "32 kbps", 58 "32 kbps",
59 "64 kbps", 59 "64 kbps",
60 "96 kbps", 60 "96 kbps",
@@ -71,7 +71,7 @@ const char **v4l2_ctrl_get_menu(u32 id)
71 "448 kbps", 71 "448 kbps",
72 NULL 72 NULL
73 }; 73 };
74 static const char *mpeg_audio_l2_bitrate[] = { 74 static const char * const mpeg_audio_l2_bitrate[] = {
75 "32 kbps", 75 "32 kbps",
76 "48 kbps", 76 "48 kbps",
77 "56 kbps", 77 "56 kbps",
@@ -88,7 +88,7 @@ const char **v4l2_ctrl_get_menu(u32 id)
88 "384 kbps", 88 "384 kbps",
89 NULL 89 NULL
90 }; 90 };
91 static const char *mpeg_audio_l3_bitrate[] = { 91 static const char * const mpeg_audio_l3_bitrate[] = {
92 "32 kbps", 92 "32 kbps",
93 "40 kbps", 93 "40 kbps",
94 "48 kbps", 94 "48 kbps",
@@ -105,7 +105,7 @@ const char **v4l2_ctrl_get_menu(u32 id)
105 "320 kbps", 105 "320 kbps",
106 NULL 106 NULL
107 }; 107 };
108 static const char *mpeg_audio_ac3_bitrate[] = { 108 static const char * const mpeg_audio_ac3_bitrate[] = {
109 "32 kbps", 109 "32 kbps",
110 "40 kbps", 110 "40 kbps",
111 "48 kbps", 111 "48 kbps",
@@ -127,50 +127,50 @@ const char **v4l2_ctrl_get_menu(u32 id)
127 "640 kbps", 127 "640 kbps",
128 NULL 128 NULL
129 }; 129 };
130 static const char *mpeg_audio_mode[] = { 130 static const char * const mpeg_audio_mode[] = {
131 "Stereo", 131 "Stereo",
132 "Joint Stereo", 132 "Joint Stereo",
133 "Dual", 133 "Dual",
134 "Mono", 134 "Mono",
135 NULL 135 NULL
136 }; 136 };
137 static const char *mpeg_audio_mode_extension[] = { 137 static const char * const mpeg_audio_mode_extension[] = {
138 "Bound 4", 138 "Bound 4",
139 "Bound 8", 139 "Bound 8",
140 "Bound 12", 140 "Bound 12",
141 "Bound 16", 141 "Bound 16",
142 NULL 142 NULL
143 }; 143 };
144 static const char *mpeg_audio_emphasis[] = { 144 static const char * const mpeg_audio_emphasis[] = {
145 "No Emphasis", 145 "No Emphasis",
146 "50/15 us", 146 "50/15 us",
147 "CCITT J17", 147 "CCITT J17",
148 NULL 148 NULL
149 }; 149 };
150 static const char *mpeg_audio_crc[] = { 150 static const char * const mpeg_audio_crc[] = {
151 "No CRC", 151 "No CRC",
152 "16-bit CRC", 152 "16-bit CRC",
153 NULL 153 NULL
154 }; 154 };
155 static const char *mpeg_video_encoding[] = { 155 static const char * const mpeg_video_encoding[] = {
156 "MPEG-1", 156 "MPEG-1",
157 "MPEG-2", 157 "MPEG-2",
158 "MPEG-4 AVC", 158 "MPEG-4 AVC",
159 NULL 159 NULL
160 }; 160 };
161 static const char *mpeg_video_aspect[] = { 161 static const char * const mpeg_video_aspect[] = {
162 "1x1", 162 "1x1",
163 "4x3", 163 "4x3",
164 "16x9", 164 "16x9",
165 "2.21x1", 165 "2.21x1",
166 NULL 166 NULL
167 }; 167 };
168 static const char *mpeg_video_bitrate_mode[] = { 168 static const char * const mpeg_video_bitrate_mode[] = {
169 "Variable Bitrate", 169 "Variable Bitrate",
170 "Constant Bitrate", 170 "Constant Bitrate",
171 NULL 171 NULL
172 }; 172 };
173 static const char *mpeg_stream_type[] = { 173 static const char * const mpeg_stream_type[] = {
174 "MPEG-2 Program Stream", 174 "MPEG-2 Program Stream",
175 "MPEG-2 Transport Stream", 175 "MPEG-2 Transport Stream",
176 "MPEG-1 System Stream", 176 "MPEG-1 System Stream",
@@ -179,25 +179,25 @@ const char **v4l2_ctrl_get_menu(u32 id)
179 "MPEG-2 SVCD-compatible Stream", 179 "MPEG-2 SVCD-compatible Stream",
180 NULL 180 NULL
181 }; 181 };
182 static const char *mpeg_stream_vbi_fmt[] = { 182 static const char * const mpeg_stream_vbi_fmt[] = {
183 "No VBI", 183 "No VBI",
184 "Private packet, IVTV format", 184 "Private packet, IVTV format",
185 NULL 185 NULL
186 }; 186 };
187 static const char *camera_power_line_frequency[] = { 187 static const char * const camera_power_line_frequency[] = {
188 "Disabled", 188 "Disabled",
189 "50 Hz", 189 "50 Hz",
190 "60 Hz", 190 "60 Hz",
191 NULL 191 NULL
192 }; 192 };
193 static const char *camera_exposure_auto[] = { 193 static const char * const camera_exposure_auto[] = {
194 "Auto Mode", 194 "Auto Mode",
195 "Manual Mode", 195 "Manual Mode",
196 "Shutter Priority Mode", 196 "Shutter Priority Mode",
197 "Aperture Priority Mode", 197 "Aperture Priority Mode",
198 NULL 198 NULL
199 }; 199 };
200 static const char *colorfx[] = { 200 static const char * const colorfx[] = {
201 "None", 201 "None",
202 "Black & White", 202 "Black & White",
203 "Sepia", 203 "Sepia",
@@ -210,7 +210,7 @@ const char **v4l2_ctrl_get_menu(u32 id)
210 "Vivid", 210 "Vivid",
211 NULL 211 NULL
212 }; 212 };
213 static const char *tune_preemphasis[] = { 213 static const char * const tune_preemphasis[] = {
214 "No preemphasis", 214 "No preemphasis",
215 "50 useconds", 215 "50 useconds",
216 "75 useconds", 216 "75 useconds",
@@ -952,7 +952,7 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,
952 const struct v4l2_ctrl_ops *ops, 952 const struct v4l2_ctrl_ops *ops,
953 u32 id, const char *name, enum v4l2_ctrl_type type, 953 u32 id, const char *name, enum v4l2_ctrl_type type,
954 s32 min, s32 max, u32 step, s32 def, 954 s32 min, s32 max, u32 step, s32 def,
955 u32 flags, const char **qmenu, void *priv) 955 u32 flags, const char * const *qmenu, void *priv)
956{ 956{
957 struct v4l2_ctrl *ctrl; 957 struct v4l2_ctrl *ctrl;
958 unsigned sz_extra = 0; 958 unsigned sz_extra = 0;
@@ -962,13 +962,20 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,
962 962
963 /* Sanity checks */ 963 /* Sanity checks */
964 if (id == 0 || name == NULL || id >= V4L2_CID_PRIVATE_BASE || 964 if (id == 0 || name == NULL || id >= V4L2_CID_PRIVATE_BASE ||
965 def < min || def > max || max < min || 965 max < min ||
966 (type == V4L2_CTRL_TYPE_INTEGER && step == 0) || 966 (type == V4L2_CTRL_TYPE_INTEGER && step == 0) ||
967 (type == V4L2_CTRL_TYPE_MENU && qmenu == NULL) || 967 (type == V4L2_CTRL_TYPE_MENU && qmenu == NULL) ||
968 (type == V4L2_CTRL_TYPE_STRING && max == 0)) { 968 (type == V4L2_CTRL_TYPE_STRING && max == 0)) {
969 handler_set_err(hdl, -ERANGE); 969 handler_set_err(hdl, -ERANGE);
970 return NULL; 970 return NULL;
971 } 971 }
972 if ((type == V4L2_CTRL_TYPE_INTEGER ||
973 type == V4L2_CTRL_TYPE_MENU ||
974 type == V4L2_CTRL_TYPE_BOOLEAN) &&
975 (def < min || def > max)) {
976 handler_set_err(hdl, -ERANGE);
977 return NULL;
978 }
972 979
973 if (type == V4L2_CTRL_TYPE_BUTTON) 980 if (type == V4L2_CTRL_TYPE_BUTTON)
974 flags |= V4L2_CTRL_FLAG_WRITE_ONLY; 981 flags |= V4L2_CTRL_FLAG_WRITE_ONLY;
@@ -1019,7 +1026,7 @@ struct v4l2_ctrl *v4l2_ctrl_new_custom(struct v4l2_ctrl_handler *hdl,
1019 bool is_menu; 1026 bool is_menu;
1020 struct v4l2_ctrl *ctrl; 1027 struct v4l2_ctrl *ctrl;
1021 const char *name = cfg->name; 1028 const char *name = cfg->name;
1022 const char **qmenu = cfg->qmenu; 1029 const char * const *qmenu = cfg->qmenu;
1023 enum v4l2_ctrl_type type = cfg->type; 1030 enum v4l2_ctrl_type type = cfg->type;
1024 u32 flags = cfg->flags; 1031 u32 flags = cfg->flags;
1025 s32 min = cfg->min; 1032 s32 min = cfg->min;
@@ -1075,7 +1082,7 @@ struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl,
1075 const struct v4l2_ctrl_ops *ops, 1082 const struct v4l2_ctrl_ops *ops,
1076 u32 id, s32 max, s32 mask, s32 def) 1083 u32 id, s32 max, s32 mask, s32 def)
1077{ 1084{
1078 const char **qmenu = v4l2_ctrl_get_menu(id); 1085 const char * const *qmenu = v4l2_ctrl_get_menu(id);
1079 const char *name; 1086 const char *name;
1080 enum v4l2_ctrl_type type; 1087 enum v4l2_ctrl_type type;
1081 s32 min; 1088 s32 min;
diff --git a/drivers/media/video/v4l2-ioctl.c b/drivers/media/video/v4l2-ioctl.c
index dd9283fcb564..7e47f15f350d 100644
--- a/drivers/media/video/v4l2-ioctl.c
+++ b/drivers/media/video/v4l2-ioctl.c
@@ -18,12 +18,8 @@
18#include <linux/kernel.h> 18#include <linux/kernel.h>
19 19
20#define __OLD_VIDIOC_ /* To allow fixing old calls */ 20#define __OLD_VIDIOC_ /* To allow fixing old calls */
21#include <linux/videodev.h>
22#include <linux/videodev2.h> 21#include <linux/videodev2.h>
23 22
24#ifdef CONFIG_VIDEO_V4L1
25#include <linux/videodev.h>
26#endif
27#include <media/v4l2-common.h> 23#include <media/v4l2-common.h>
28#include <media/v4l2-ioctl.h> 24#include <media/v4l2-ioctl.h>
29#include <media/v4l2-ctrls.h> 25#include <media/v4l2-ctrls.h>
@@ -183,42 +179,6 @@ static const char *v4l2_memory_names[] = {
183 179
184/* ------------------------------------------------------------------ */ 180/* ------------------------------------------------------------------ */
185/* debug help functions */ 181/* debug help functions */
186
187#ifdef CONFIG_VIDEO_V4L1_COMPAT
188static const char *v4l1_ioctls[] = {
189 [_IOC_NR(VIDIOCGCAP)] = "VIDIOCGCAP",
190 [_IOC_NR(VIDIOCGCHAN)] = "VIDIOCGCHAN",
191 [_IOC_NR(VIDIOCSCHAN)] = "VIDIOCSCHAN",
192 [_IOC_NR(VIDIOCGTUNER)] = "VIDIOCGTUNER",
193 [_IOC_NR(VIDIOCSTUNER)] = "VIDIOCSTUNER",
194 [_IOC_NR(VIDIOCGPICT)] = "VIDIOCGPICT",
195 [_IOC_NR(VIDIOCSPICT)] = "VIDIOCSPICT",
196 [_IOC_NR(VIDIOCCAPTURE)] = "VIDIOCCAPTURE",
197 [_IOC_NR(VIDIOCGWIN)] = "VIDIOCGWIN",
198 [_IOC_NR(VIDIOCSWIN)] = "VIDIOCSWIN",
199 [_IOC_NR(VIDIOCGFBUF)] = "VIDIOCGFBUF",
200 [_IOC_NR(VIDIOCSFBUF)] = "VIDIOCSFBUF",
201 [_IOC_NR(VIDIOCKEY)] = "VIDIOCKEY",
202 [_IOC_NR(VIDIOCGFREQ)] = "VIDIOCGFREQ",
203 [_IOC_NR(VIDIOCSFREQ)] = "VIDIOCSFREQ",
204 [_IOC_NR(VIDIOCGAUDIO)] = "VIDIOCGAUDIO",
205 [_IOC_NR(VIDIOCSAUDIO)] = "VIDIOCSAUDIO",
206 [_IOC_NR(VIDIOCSYNC)] = "VIDIOCSYNC",
207 [_IOC_NR(VIDIOCMCAPTURE)] = "VIDIOCMCAPTURE",
208 [_IOC_NR(VIDIOCGMBUF)] = "VIDIOCGMBUF",
209 [_IOC_NR(VIDIOCGUNIT)] = "VIDIOCGUNIT",
210 [_IOC_NR(VIDIOCGCAPTURE)] = "VIDIOCGCAPTURE",
211 [_IOC_NR(VIDIOCSCAPTURE)] = "VIDIOCSCAPTURE",
212 [_IOC_NR(VIDIOCSPLAYMODE)] = "VIDIOCSPLAYMODE",
213 [_IOC_NR(VIDIOCSWRITEMODE)] = "VIDIOCSWRITEMODE",
214 [_IOC_NR(VIDIOCGPLAYINFO)] = "VIDIOCGPLAYINFO",
215 [_IOC_NR(VIDIOCSMICROCODE)] = "VIDIOCSMICROCODE",
216 [_IOC_NR(VIDIOCGVBIFMT)] = "VIDIOCGVBIFMT",
217 [_IOC_NR(VIDIOCSVBIFMT)] = "VIDIOCSVBIFMT"
218};
219#define V4L1_IOCTLS ARRAY_SIZE(v4l1_ioctls)
220#endif
221
222static const char *v4l2_ioctls[] = { 182static const char *v4l2_ioctls[] = {
223 [_IOC_NR(VIDIOC_QUERYCAP)] = "VIDIOC_QUERYCAP", 183 [_IOC_NR(VIDIOC_QUERYCAP)] = "VIDIOC_QUERYCAP",
224 [_IOC_NR(VIDIOC_RESERVED)] = "VIDIOC_RESERVED", 184 [_IOC_NR(VIDIOC_RESERVED)] = "VIDIOC_RESERVED",
@@ -310,15 +270,6 @@ void v4l_printk_ioctl(unsigned int cmd)
310 case 'd': 270 case 'd':
311 type = "v4l2_int"; 271 type = "v4l2_int";
312 break; 272 break;
313#ifdef CONFIG_VIDEO_V4L1_COMPAT
314 case 'v':
315 if (_IOC_NR(cmd) >= V4L1_IOCTLS) {
316 type = "v4l1";
317 break;
318 }
319 printk("%s", v4l1_ioctls[_IOC_NR(cmd)]);
320 return;
321#endif
322 case 'V': 273 case 'V':
323 if (_IOC_NR(cmd) >= V4L2_IOCTLS) { 274 if (_IOC_NR(cmd) >= V4L2_IOCTLS) {
324 type = "v4l2"; 275 type = "v4l2";
@@ -622,20 +573,6 @@ static long __video_do_ioctl(struct file *file,
622 return -EINVAL; 573 return -EINVAL;
623 } 574 }
624 575
625#ifdef CONFIG_VIDEO_V4L1_COMPAT
626 /********************************************************
627 All other V4L1 calls are handled by v4l1_compat module.
628 Those calls will be translated into V4L2 calls, and
629 __video_do_ioctl will be called again, with one or more
630 V4L2 ioctls.
631 ********************************************************/
632 if (_IOC_TYPE(cmd) == 'v' && cmd != VIDIOCGMBUF &&
633 _IOC_NR(cmd) < BASE_VIDIOCPRIVATE) {
634 return v4l_compat_translate_ioctl(file, cmd, arg,
635 __video_do_ioctl);
636 }
637#endif
638
639 if ((vfd->debug & V4L2_DEBUG_IOCTL) && 576 if ((vfd->debug & V4L2_DEBUG_IOCTL) &&
640 !(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) { 577 !(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) {
641 v4l_print_ioctl(vfd->name, cmd); 578 v4l_print_ioctl(vfd->name, cmd);
@@ -644,29 +581,6 @@ static long __video_do_ioctl(struct file *file,
644 581
645 switch (cmd) { 582 switch (cmd) {
646 583
647#ifdef CONFIG_VIDEO_V4L1_COMPAT
648 /***********************************************************
649 Handles calls to the obsoleted V4L1 API
650 Due to the nature of VIDIOCGMBUF, each driver that supports
651 V4L1 should implement its own handler for this ioctl.
652 ***********************************************************/
653
654 /* --- streaming capture ------------------------------------- */
655 case VIDIOCGMBUF:
656 {
657 struct video_mbuf *p = arg;
658
659 if (!ops->vidiocgmbuf)
660 break;
661 ret = ops->vidiocgmbuf(file, fh, p);
662 if (!ret)
663 dbgarg(cmd, "size=%d, frames=%d, offsets=0x%08lx\n",
664 p->size, p->frames,
665 (unsigned long)p->offsets);
666 break;
667 }
668#endif
669
670 /* --- capabilities ------------------------------------------ */ 584 /* --- capabilities ------------------------------------------ */
671 case VIDIOC_QUERYCAP: 585 case VIDIOC_QUERYCAP:
672 { 586 {
diff --git a/drivers/media/video/via-camera.c b/drivers/media/video/via-camera.c
index 9eda7cc03121..e25aca5759fb 100644
--- a/drivers/media/video/via-camera.c
+++ b/drivers/media/video/via-camera.c
@@ -1161,16 +1161,6 @@ out:
1161 return ret; 1161 return ret;
1162} 1162}
1163 1163
1164#ifdef CONFIG_VIDEO_V4L1_COMPAT
1165static int viacam_vidiocgmbuf(struct file *filp, void *priv,
1166 struct video_mbuf *mbuf)
1167{
1168 struct via_camera *cam = priv;
1169
1170 return videobuf_cgmbuf(&cam->vb_queue, mbuf, 6);
1171}
1172#endif
1173
1174/* G/S_PARM */ 1164/* G/S_PARM */
1175 1165
1176static int viacam_g_parm(struct file *filp, void *priv, 1166static int viacam_g_parm(struct file *filp, void *priv,
@@ -1251,9 +1241,6 @@ static const struct v4l2_ioctl_ops viacam_ioctl_ops = {
1251 .vidioc_s_parm = viacam_s_parm, 1241 .vidioc_s_parm = viacam_s_parm,
1252 .vidioc_enum_framesizes = viacam_enum_framesizes, 1242 .vidioc_enum_framesizes = viacam_enum_framesizes,
1253 .vidioc_enum_frameintervals = viacam_enum_frameintervals, 1243 .vidioc_enum_frameintervals = viacam_enum_frameintervals,
1254#ifdef CONFIG_VIDEO_V4L1_COMPAT
1255 .vidiocgmbuf = viacam_vidiocgmbuf,
1256#endif
1257}; 1244};
1258 1245
1259/*----------------------------------------------------------------------------*/ 1246/*----------------------------------------------------------------------------*/
diff --git a/drivers/media/video/videobuf-core.c b/drivers/media/video/videobuf-core.c
index 8979f91fa8e5..de4fa4eb8844 100644
--- a/drivers/media/video/videobuf-core.c
+++ b/drivers/media/video/videobuf-core.c
@@ -1202,33 +1202,3 @@ int videobuf_mmap_mapper(struct videobuf_queue *q, struct vm_area_struct *vma)
1202 return rc; 1202 return rc;
1203} 1203}
1204EXPORT_SYMBOL_GPL(videobuf_mmap_mapper); 1204EXPORT_SYMBOL_GPL(videobuf_mmap_mapper);
1205
1206#ifdef CONFIG_VIDEO_V4L1_COMPAT
1207int videobuf_cgmbuf(struct videobuf_queue *q,
1208 struct video_mbuf *mbuf, int count)
1209{
1210 struct v4l2_requestbuffers req;
1211 int rc, i;
1212
1213 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
1214
1215 memset(&req, 0, sizeof(req));
1216 req.type = q->type;
1217 req.count = count;
1218 req.memory = V4L2_MEMORY_MMAP;
1219 rc = videobuf_reqbufs(q, &req);
1220 if (rc < 0)
1221 return rc;
1222
1223 mbuf->frames = req.count;
1224 mbuf->size = 0;
1225 for (i = 0; i < mbuf->frames; i++) {
1226 mbuf->offsets[i] = q->bufs[i]->boff;
1227 mbuf->size += PAGE_ALIGN(q->bufs[i]->bsize);
1228 }
1229
1230 return 0;
1231}
1232EXPORT_SYMBOL_GPL(videobuf_cgmbuf);
1233#endif
1234
diff --git a/drivers/media/video/videobuf-dma-sg.c b/drivers/media/video/videobuf-dma-sg.c
index 20f227ee2b3e..ddb8f4b46c03 100644
--- a/drivers/media/video/videobuf-dma-sg.c
+++ b/drivers/media/video/videobuf-dma-sg.c
@@ -69,10 +69,9 @@ static struct scatterlist *videobuf_vmalloc_to_sg(unsigned char *virt,
69 struct page *pg; 69 struct page *pg;
70 int i; 70 int i;
71 71
72 sglist = vmalloc(nr_pages * sizeof(*sglist)); 72 sglist = vzalloc(nr_pages * sizeof(*sglist));
73 if (NULL == sglist) 73 if (NULL == sglist)
74 return NULL; 74 return NULL;
75 memset(sglist, 0, nr_pages * sizeof(*sglist));
76 sg_init_table(sglist, nr_pages); 75 sg_init_table(sglist, nr_pages);
77 for (i = 0; i < nr_pages; i++, virt += PAGE_SIZE) { 76 for (i = 0; i < nr_pages; i++, virt += PAGE_SIZE) {
78 pg = vmalloc_to_page(virt); 77 pg = vmalloc_to_page(virt);
@@ -544,14 +543,6 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
544 543
545 retval = -EINVAL; 544 retval = -EINVAL;
546 545
547 /* This function maintains backwards compatibility with V4L1 and will
548 * map more than one buffer if the vma length is equal to the combined
549 * size of multiple buffers than it will map them together. See
550 * VIDIOCGMBUF in the v4l spec
551 *
552 * TODO: Allow drivers to specify if they support this mode
553 */
554
555 BUG_ON(!mem); 546 BUG_ON(!mem);
556 MAGIC_CHECK(mem->magic, MAGIC_SG_MEM); 547 MAGIC_CHECK(mem->magic, MAGIC_SG_MEM);
557 548
@@ -571,29 +562,6 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
571 } 562 }
572 563
573 last = first; 564 last = first;
574#ifdef CONFIG_VIDEO_V4L1_COMPAT
575 if (size != (vma->vm_end - vma->vm_start)) {
576 /* look for last buffer to map */
577 for (last = first + 1; last < VIDEO_MAX_FRAME; last++) {
578 if (NULL == q->bufs[last])
579 continue;
580 if (V4L2_MEMORY_MMAP != q->bufs[last]->memory)
581 continue;
582 if (q->bufs[last]->map) {
583 retval = -EBUSY;
584 goto done;
585 }
586 size += PAGE_ALIGN(q->bufs[last]->bsize);
587 if (size == (vma->vm_end - vma->vm_start))
588 break;
589 }
590 if (VIDEO_MAX_FRAME == last) {
591 dprintk(1, "mmap app bug: size invalid [size=0x%lx]\n",
592 (vma->vm_end - vma->vm_start));
593 goto done;
594 }
595 }
596#endif
597 565
598 /* create mapping + update buffer list */ 566 /* create mapping + update buffer list */
599 retval = -ENOMEM; 567 retval = -ENOMEM;
diff --git a/drivers/media/video/vino.c b/drivers/media/video/vino.c
index 7e7eec48f8b1..d63e9d978493 100644
--- a/drivers/media/video/vino.c
+++ b/drivers/media/video/vino.c
@@ -2954,9 +2954,6 @@ static int vino_enum_input(struct file *file, void *__fh,
2954 if (input == VINO_INPUT_NONE) 2954 if (input == VINO_INPUT_NONE)
2955 return -EINVAL; 2955 return -EINVAL;
2956 2956
2957 memset(i, 0, sizeof(struct v4l2_input));
2958
2959 i->index = index;
2960 i->type = V4L2_INPUT_TYPE_CAMERA; 2957 i->type = V4L2_INPUT_TYPE_CAMERA;
2961 i->std = vino_inputs[input].std; 2958 i->std = vino_inputs[input].std;
2962 strcpy(i->name, vino_inputs[input].name); 2959 strcpy(i->name, vino_inputs[input].name);
diff --git a/drivers/media/video/vivi.c b/drivers/media/video/vivi.c
index 9797e5a69265..c49c39386bd0 100644
--- a/drivers/media/video/vivi.c
+++ b/drivers/media/video/vivi.c
@@ -870,15 +870,6 @@ static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
870 file->f_flags & O_NONBLOCK); 870 file->f_flags & O_NONBLOCK);
871} 871}
872 872
873#ifdef CONFIG_VIDEO_V4L1_COMPAT
874static int vidiocgmbuf(struct file *file, void *priv, struct video_mbuf *mbuf)
875{
876 struct vivi_dev *dev = video_drvdata(file);
877
878 return videobuf_cgmbuf(&dev->vb_vidq, mbuf, 8);
879}
880#endif
881
882static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i) 873static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
883{ 874{
884 struct vivi_dev *dev = video_drvdata(file); 875 struct vivi_dev *dev = video_drvdata(file);
@@ -1105,9 +1096,6 @@ static const struct v4l2_ioctl_ops vivi_ioctl_ops = {
1105 .vidioc_queryctrl = vidioc_queryctrl, 1096 .vidioc_queryctrl = vidioc_queryctrl,
1106 .vidioc_g_ctrl = vidioc_g_ctrl, 1097 .vidioc_g_ctrl = vidioc_g_ctrl,
1107 .vidioc_s_ctrl = vidioc_s_ctrl, 1098 .vidioc_s_ctrl = vidioc_s_ctrl,
1108#ifdef CONFIG_VIDEO_V4L1_COMPAT
1109 .vidiocgmbuf = vidiocgmbuf,
1110#endif
1111}; 1099};
1112 1100
1113static struct video_device vivi_template = { 1101static struct video_device vivi_template = {
diff --git a/drivers/media/video/zoran/zoran.h b/drivers/media/video/zoran/zoran.h
index 27f05551183f..4bb368e6fd47 100644
--- a/drivers/media/video/zoran/zoran.h
+++ b/drivers/media/video/zoran/zoran.h
@@ -33,15 +33,6 @@
33 33
34#include <media/v4l2-device.h> 34#include <media/v4l2-device.h>
35 35
36#define ZORAN_VIDMODE_PAL 0
37#define ZORAN_VIDMODE_NTSC 1
38#define ZORAN_VIDMODE_SECAM 2
39
40struct zoran_requestbuffers {
41 unsigned long count; /* Number of buffers for MJPEG grabbing */
42 unsigned long size; /* Size PER BUFFER in bytes */
43};
44
45struct zoran_sync { 36struct zoran_sync {
46 unsigned long frame; /* number of buffer that has been free'd */ 37 unsigned long frame; /* number of buffer that has been free'd */
47 unsigned long length; /* number of code bytes in buffer (capture only) */ 38 unsigned long length; /* number of code bytes in buffer (capture only) */
@@ -49,102 +40,6 @@ struct zoran_sync {
49 struct timeval timestamp; /* timestamp */ 40 struct timeval timestamp; /* timestamp */
50}; 41};
51 42
52struct zoran_status {
53 int input; /* Input channel, has to be set prior to BUZIOC_G_STATUS */
54 int signal; /* Returned: 1 if valid video signal detected */
55 int norm; /* Returned: ZORAN_VIDMODE_PAL or ZORAN_VIDMODE_NTSC */
56 int color; /* Returned: 1 if color signal detected */
57};
58
59struct zoran_params {
60
61 /* The following parameters can only be queried */
62
63 int major_version; /* Major version number of driver */
64 int minor_version; /* Minor version number of driver */
65
66 /* Main control parameters */
67
68 int input; /* Input channel: 0 = Composite, 1 = S-VHS */
69 int norm; /* Norm: ZORAN_VIDMODE_PAL or ZORAN_VIDMODE_NTSC */
70 int decimation; /* decimation of captured video,
71 * enlargement of video played back.
72 * Valid values are 1, 2, 4 or 0.
73 * 0 is a special value where the user
74 * has full control over video scaling */
75
76 /* The following parameters only have to be set if decimation==0,
77 * for other values of decimation they provide the data how the image is captured */
78
79 int HorDcm; /* Horizontal decimation: 1, 2 or 4 */
80 int VerDcm; /* Vertical decimation: 1 or 2 */
81 int TmpDcm; /* Temporal decimation: 1 or 2,
82 * if TmpDcm==2 in capture every second frame is dropped,
83 * in playback every frame is played twice */
84 int field_per_buff; /* Number of fields per buffer: 1 or 2 */
85 int img_x; /* start of image in x direction */
86 int img_y; /* start of image in y direction */
87 int img_width; /* image width BEFORE decimation,
88 * must be a multiple of HorDcm*16 */
89 int img_height; /* image height BEFORE decimation,
90 * must be a multiple of VerDcm*8 */
91
92 /* --- End of parameters for decimation==0 only --- */
93
94 /* JPEG control parameters */
95
96 int quality; /* Measure for quality of compressed images.
97 * Scales linearly with the size of the compressed images.
98 * Must be beetween 0 and 100, 100 is a compression
99 * ratio of 1:4 */
100
101 int odd_even; /* Which field should come first ??? */
102
103 int APPn; /* Number of APP segment to be written, must be 0..15 */
104 int APP_len; /* Length of data in JPEG APPn segment */
105 char APP_data[60]; /* Data in the JPEG APPn segment. */
106
107 int COM_len; /* Length of data in JPEG COM segment */
108 char COM_data[60]; /* Data in JPEG COM segment */
109
110 unsigned long jpeg_markers; /* Which markers should go into the JPEG output.
111 * Unless you exactly know what you do, leave them untouched.
112 * Inluding less markers will make the resulting code
113 * smaller, but there will be fewer applications
114 * which can read it.
115 * The presence of the APP and COM marker is
116 * influenced by APP0_len and COM_len ONLY! */
117#define JPEG_MARKER_DHT (1<<3) /* Define Huffman Tables */
118#define JPEG_MARKER_DQT (1<<4) /* Define Quantization Tables */
119#define JPEG_MARKER_DRI (1<<5) /* Define Restart Interval */
120#define JPEG_MARKER_COM (1<<6) /* Comment segment */
121#define JPEG_MARKER_APP (1<<7) /* App segment, driver will allways use APP0 */
122
123 int VFIFO_FB; /* Flag for enabling Video Fifo Feedback.
124 * If this flag is turned on and JPEG decompressing
125 * is going to the screen, the decompress process
126 * is stopped every time the Video Fifo is full.
127 * This enables a smooth decompress to the screen
128 * but the video output signal will get scrambled */
129
130 /* Misc */
131
132 char reserved[312]; /* Makes 512 bytes for this structure */
133};
134
135/*
136Private IOCTL to set up for displaying MJPEG
137*/
138#define BUZIOC_G_PARAMS _IOR ('v', BASE_VIDIOC_PRIVATE+0, struct zoran_params)
139#define BUZIOC_S_PARAMS _IOWR('v', BASE_VIDIOC_PRIVATE+1, struct zoran_params)
140#define BUZIOC_REQBUFS _IOWR('v', BASE_VIDIOC_PRIVATE+2, struct zoran_requestbuffers)
141#define BUZIOC_QBUF_CAPT _IOW ('v', BASE_VIDIOC_PRIVATE+3, int)
142#define BUZIOC_QBUF_PLAY _IOW ('v', BASE_VIDIOC_PRIVATE+4, int)
143#define BUZIOC_SYNC _IOR ('v', BASE_VIDIOC_PRIVATE+5, struct zoran_sync)
144#define BUZIOC_G_STATUS _IOWR('v', BASE_VIDIOC_PRIVATE+6, struct zoran_status)
145
146
147#ifdef __KERNEL__
148 43
149#define MAJOR_VERSION 0 /* driver major version */ 44#define MAJOR_VERSION 0 /* driver major version */
150#define MINOR_VERSION 10 /* driver minor version */ 45#define MINOR_VERSION 10 /* driver minor version */
@@ -507,6 +402,4 @@ static inline struct zoran *to_zoran(struct v4l2_device *v4l2_dev)
507#define btor(dat,adr) btwrite((dat) | btread(adr), adr) 402#define btor(dat,adr) btwrite((dat) | btread(adr), adr)
508#define btaor(dat,mask,adr) btwrite((dat) | ((mask) & btread(adr)), adr) 403#define btaor(dat,mask,adr) btwrite((dat) | ((mask) & btread(adr)), adr)
509 404
510#endif /* __kernel__ */
511
512#endif 405#endif
diff --git a/drivers/media/video/zoran/zoran_card.c b/drivers/media/video/zoran/zoran_card.c
index e520abf9f4c3..9cdc3bb15b15 100644
--- a/drivers/media/video/zoran/zoran_card.c
+++ b/drivers/media/video/zoran/zoran_card.c
@@ -943,7 +943,7 @@ zoran_open_init_params (struct zoran *zr)
943 memset(zr->jpg_settings.jpg_comp.COM_data, 0, 943 memset(zr->jpg_settings.jpg_comp.COM_data, 0,
944 sizeof(zr->jpg_settings.jpg_comp.COM_data)); 944 sizeof(zr->jpg_settings.jpg_comp.COM_data));
945 zr->jpg_settings.jpg_comp.jpeg_markers = 945 zr->jpg_settings.jpg_comp.jpeg_markers =
946 JPEG_MARKER_DHT | JPEG_MARKER_DQT; 946 V4L2_JPEG_MARKER_DHT | V4L2_JPEG_MARKER_DQT;
947 i = zoran_check_jpg_settings(zr, &zr->jpg_settings, 0); 947 i = zoran_check_jpg_settings(zr, &zr->jpg_settings, 0);
948 if (i) 948 if (i)
949 dprintk(1, KERN_ERR "%s: %s internal error\n", 949 dprintk(1, KERN_ERR "%s: %s internal error\n",
diff --git a/drivers/media/video/zoran/zoran_device.c b/drivers/media/video/zoran/zoran_device.c
index b02007e42150..e8a27844bf39 100644
--- a/drivers/media/video/zoran/zoran_device.c
+++ b/drivers/media/video/zoran/zoran_device.c
@@ -1523,7 +1523,7 @@ zoran_irq (int irq,
1523 zr->JPEG_missed > 25 || 1523 zr->JPEG_missed > 25 ||
1524 zr->JPEG_error == 1 || 1524 zr->JPEG_error == 1 ||
1525 ((zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS) && 1525 ((zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS) &&
1526 (zr->frame_num & (zr->JPEG_missed > zr->jpg_settings.field_per_buff)))) { 1526 (zr->frame_num && (zr->JPEG_missed > zr->jpg_settings.field_per_buff)))) {
1527 error_handler(zr, astat, stat); 1527 error_handler(zr, astat, stat);
1528 } 1528 }
1529 1529
diff --git a/drivers/media/video/zoran/zoran_driver.c b/drivers/media/video/zoran/zoran_driver.c
index 67a52e844ae6..7c3921de9589 100644
--- a/drivers/media/video/zoran/zoran_driver.c
+++ b/drivers/media/video/zoran/zoran_driver.c
@@ -1528,323 +1528,6 @@ zoran_set_input (struct zoran *zr,
1528 * ioctl routine 1528 * ioctl routine
1529 */ 1529 */
1530 1530
1531#ifdef CONFIG_VIDEO_V4L1_COMPAT
1532static long zoran_default(struct file *file, void *__fh, int cmd, void *arg)
1533{
1534 struct zoran_fh *fh = __fh;
1535 struct zoran *zr = fh->zr;
1536 struct zoran_jpg_settings settings;
1537
1538 switch (cmd) {
1539 case BUZIOC_G_PARAMS:
1540 {
1541 struct zoran_params *bparams = arg;
1542
1543 dprintk(3, KERN_DEBUG "%s: BUZIOC_G_PARAMS\n", ZR_DEVNAME(zr));
1544
1545 memset(bparams, 0, sizeof(struct zoran_params));
1546 bparams->major_version = MAJOR_VERSION;
1547 bparams->minor_version = MINOR_VERSION;
1548
1549 mutex_lock(&zr->resource_lock);
1550
1551 if (zr->norm & V4L2_STD_NTSC)
1552 bparams->norm = ZORAN_VIDMODE_NTSC;
1553 else if (zr->norm & V4L2_STD_SECAM)
1554 bparams->norm = ZORAN_VIDMODE_SECAM;
1555 else
1556 bparams->norm = ZORAN_VIDMODE_PAL;
1557
1558 bparams->input = zr->input;
1559
1560 bparams->decimation = fh->jpg_settings.decimation;
1561 bparams->HorDcm = fh->jpg_settings.HorDcm;
1562 bparams->VerDcm = fh->jpg_settings.VerDcm;
1563 bparams->TmpDcm = fh->jpg_settings.TmpDcm;
1564 bparams->field_per_buff = fh->jpg_settings.field_per_buff;
1565 bparams->img_x = fh->jpg_settings.img_x;
1566 bparams->img_y = fh->jpg_settings.img_y;
1567 bparams->img_width = fh->jpg_settings.img_width;
1568 bparams->img_height = fh->jpg_settings.img_height;
1569 bparams->odd_even = fh->jpg_settings.odd_even;
1570
1571 bparams->quality = fh->jpg_settings.jpg_comp.quality;
1572 bparams->APPn = fh->jpg_settings.jpg_comp.APPn;
1573 bparams->APP_len = fh->jpg_settings.jpg_comp.APP_len;
1574 memcpy(bparams->APP_data,
1575 fh->jpg_settings.jpg_comp.APP_data,
1576 sizeof(bparams->APP_data));
1577 bparams->COM_len = zr->jpg_settings.jpg_comp.COM_len;
1578 memcpy(bparams->COM_data,
1579 fh->jpg_settings.jpg_comp.COM_data,
1580 sizeof(bparams->COM_data));
1581 bparams->jpeg_markers =
1582 fh->jpg_settings.jpg_comp.jpeg_markers;
1583
1584 mutex_unlock(&zr->resource_lock);
1585
1586 bparams->VFIFO_FB = 0;
1587
1588 return 0;
1589 }
1590
1591 case BUZIOC_S_PARAMS:
1592 {
1593 struct zoran_params *bparams = arg;
1594 int res = 0;
1595
1596 dprintk(3, KERN_DEBUG "%s: BUZIOC_S_PARAMS\n", ZR_DEVNAME(zr));
1597
1598 settings.decimation = bparams->decimation;
1599 settings.HorDcm = bparams->HorDcm;
1600 settings.VerDcm = bparams->VerDcm;
1601 settings.TmpDcm = bparams->TmpDcm;
1602 settings.field_per_buff = bparams->field_per_buff;
1603 settings.img_x = bparams->img_x;
1604 settings.img_y = bparams->img_y;
1605 settings.img_width = bparams->img_width;
1606 settings.img_height = bparams->img_height;
1607 settings.odd_even = bparams->odd_even;
1608
1609 settings.jpg_comp.quality = bparams->quality;
1610 settings.jpg_comp.APPn = bparams->APPn;
1611 settings.jpg_comp.APP_len = bparams->APP_len;
1612 memcpy(settings.jpg_comp.APP_data, bparams->APP_data,
1613 sizeof(bparams->APP_data));
1614 settings.jpg_comp.COM_len = bparams->COM_len;
1615 memcpy(settings.jpg_comp.COM_data, bparams->COM_data,
1616 sizeof(bparams->COM_data));
1617 settings.jpg_comp.jpeg_markers = bparams->jpeg_markers;
1618
1619 mutex_lock(&zr->resource_lock);
1620
1621 if (zr->codec_mode != BUZ_MODE_IDLE) {
1622 dprintk(1,
1623 KERN_ERR
1624 "%s: BUZIOC_S_PARAMS called, but Buz in capture/playback mode\n",
1625 ZR_DEVNAME(zr));
1626 res = -EINVAL;
1627 goto sparams_unlock_and_return;
1628 }
1629
1630 /* Check the params first before overwriting our
1631 * nternal values */
1632 if (zoran_check_jpg_settings(zr, &settings, 0)) {
1633 res = -EINVAL;
1634 goto sparams_unlock_and_return;
1635 }
1636
1637 fh->jpg_settings = settings;
1638sparams_unlock_and_return:
1639 mutex_unlock(&zr->resource_lock);
1640
1641 return res;
1642 }
1643
1644 case BUZIOC_REQBUFS:
1645 {
1646 struct zoran_requestbuffers *breq = arg;
1647 int res = 0;
1648
1649 dprintk(3,
1650 KERN_DEBUG
1651 "%s: BUZIOC_REQBUFS - count=%lu, size=%lu\n",
1652 ZR_DEVNAME(zr), breq->count, breq->size);
1653
1654 /* Enforce reasonable lower and upper limits */
1655 if (breq->count < 4)
1656 breq->count = 4; /* Could be choosen smaller */
1657 if (breq->count > jpg_nbufs)
1658 breq->count = jpg_nbufs;
1659 breq->size = PAGE_ALIGN(breq->size);
1660 if (breq->size < 8192)
1661 breq->size = 8192; /* Arbitrary */
1662 /* breq->size is limited by 1 page for the stat_com
1663 * tables to a Maximum of 2 MB */
1664 if (breq->size > jpg_bufsize)
1665 breq->size = jpg_bufsize;
1666
1667 mutex_lock(&zr->resource_lock);
1668
1669 if (fh->buffers.allocated) {
1670 dprintk(1,
1671 KERN_ERR
1672 "%s: BUZIOC_REQBUFS - buffers already allocated\n",
1673 ZR_DEVNAME(zr));
1674 res = -EBUSY;
1675 goto jpgreqbuf_unlock_and_return;
1676 }
1677
1678 /* The next mmap will map the MJPEG buffers - could
1679 * also be *_PLAY, but it doesn't matter here */
1680 map_mode_jpg(fh, 0);
1681 fh->buffers.num_buffers = breq->count;
1682 fh->buffers.buffer_size = breq->size;
1683
1684 if (jpg_fbuffer_alloc(fh)) {
1685 res = -ENOMEM;
1686 goto jpgreqbuf_unlock_and_return;
1687 }
1688
1689jpgreqbuf_unlock_and_return:
1690 mutex_unlock(&zr->resource_lock);
1691
1692 return res;
1693 }
1694
1695 case BUZIOC_QBUF_CAPT:
1696 {
1697 int *frame = arg, res;
1698
1699 dprintk(3, KERN_DEBUG "%s: BUZIOC_QBUF_CAPT - frame=%d\n",
1700 ZR_DEVNAME(zr), *frame);
1701
1702 mutex_lock(&zr->resource_lock);
1703 res = jpg_qbuf(fh, *frame, BUZ_MODE_MOTION_COMPRESS);
1704 mutex_unlock(&zr->resource_lock);
1705
1706 return res;
1707 }
1708
1709 case BUZIOC_QBUF_PLAY:
1710 {
1711 int *frame = arg, res;
1712
1713 dprintk(3, KERN_DEBUG "%s: BUZIOC_QBUF_PLAY - frame=%d\n",
1714 ZR_DEVNAME(zr), *frame);
1715
1716 mutex_lock(&zr->resource_lock);
1717 res = jpg_qbuf(fh, *frame, BUZ_MODE_MOTION_DECOMPRESS);
1718 mutex_unlock(&zr->resource_lock);
1719
1720 return res;
1721 }
1722
1723 case BUZIOC_SYNC:
1724 {
1725 struct zoran_sync *bsync = arg;
1726 int res;
1727
1728 dprintk(3, KERN_DEBUG "%s: BUZIOC_SYNC\n", ZR_DEVNAME(zr));
1729
1730 mutex_lock(&zr->resource_lock);
1731
1732 if (fh->map_mode == ZORAN_MAP_MODE_RAW) {
1733 dprintk(2, KERN_WARNING
1734 "%s: %s - not in jpg capture mode\n",
1735 ZR_DEVNAME(zr), __func__);
1736 res = -EINVAL;
1737 } else {
1738 res = jpg_sync(fh, bsync);
1739 }
1740 mutex_unlock(&zr->resource_lock);
1741
1742 return res;
1743 }
1744
1745 case BUZIOC_G_STATUS:
1746 {
1747 struct zoran_status *bstat = arg;
1748 int status = 0, res = 0;
1749 v4l2_std_id norm;
1750
1751 dprintk(3, KERN_DEBUG "%s: BUZIOC_G_STATUS\n", ZR_DEVNAME(zr));
1752
1753 if (zr->codec_mode != BUZ_MODE_IDLE) {
1754 dprintk(1,
1755 KERN_ERR
1756 "%s: BUZIOC_G_STATUS called but Buz in capture/playback mode\n",
1757 ZR_DEVNAME(zr));
1758 return -EINVAL;
1759 }
1760
1761 mutex_lock(&zr->resource_lock);
1762
1763 if (zr->codec_mode != BUZ_MODE_IDLE) {
1764 dprintk(1,
1765 KERN_ERR
1766 "%s: BUZIOC_G_STATUS called, but Buz in capture/playback mode\n",
1767 ZR_DEVNAME(zr));
1768 res = -EINVAL;
1769 goto gstat_unlock_and_return;
1770 }
1771
1772 decoder_call(zr, video, s_routing,
1773 zr->card.input[bstat->input].muxsel, 0, 0);
1774
1775 /* sleep 1 second */
1776 ssleep(1);
1777
1778 /* Get status of video decoder */
1779 decoder_call(zr, video, querystd, &norm);
1780 decoder_call(zr, video, g_input_status, &status);
1781
1782 /* restore previous input and norm */
1783 decoder_call(zr, video, s_routing,
1784 zr->card.input[zr->input].muxsel, 0, 0);
1785gstat_unlock_and_return:
1786 mutex_unlock(&zr->resource_lock);
1787
1788 if (!res) {
1789 bstat->signal =
1790 (status & V4L2_IN_ST_NO_SIGNAL) ? 0 : 1;
1791 if (norm & V4L2_STD_NTSC)
1792 bstat->norm = ZORAN_VIDMODE_NTSC;
1793 else if (norm & V4L2_STD_SECAM)
1794 bstat->norm = ZORAN_VIDMODE_SECAM;
1795 else
1796 bstat->norm = ZORAN_VIDMODE_PAL;
1797
1798 bstat->color =
1799 (status & V4L2_IN_ST_NO_COLOR) ? 0 : 1;
1800 }
1801
1802 return res;
1803 }
1804
1805 default:
1806 return -EINVAL;
1807 }
1808}
1809
1810static int zoran_vidiocgmbuf(struct file *file, void *__fh, struct video_mbuf *vmbuf)
1811{
1812 struct zoran_fh *fh = __fh;
1813 struct zoran *zr = fh->zr;
1814 int i, res = 0;
1815
1816
1817 mutex_lock(&zr->resource_lock);
1818
1819 if (fh->buffers.allocated) {
1820 dprintk(1,
1821 KERN_ERR
1822 "%s: VIDIOCGMBUF - buffers already allocated\n",
1823 ZR_DEVNAME(zr));
1824 res = -EINVAL;
1825 goto v4l1reqbuf_unlock_and_return;
1826 }
1827
1828 /* The next mmap will map the V4L buffers */
1829 map_mode_raw(fh);
1830
1831 if (v4l_fbuffer_alloc(fh)) {
1832 res = -ENOMEM;
1833 goto v4l1reqbuf_unlock_and_return;
1834 }
1835
1836 vmbuf->size = fh->buffers.num_buffers * fh->buffers.buffer_size;
1837 vmbuf->frames = fh->buffers.num_buffers;
1838 for (i = 0; i < vmbuf->frames; i++)
1839 vmbuf->offsets[i] = i * fh->buffers.buffer_size;
1840
1841v4l1reqbuf_unlock_and_return:
1842 mutex_unlock(&zr->resource_lock);
1843
1844 return res;
1845}
1846#endif
1847
1848static int zoran_querycap(struct file *file, void *__fh, struct v4l2_capability *cap) 1531static int zoran_querycap(struct file *file, void *__fh, struct v4l2_capability *cap)
1849{ 1532{
1850 struct zoran_fh *fh = __fh; 1533 struct zoran_fh *fh = __fh;
@@ -2533,6 +2216,7 @@ static int zoran_dqbuf(struct file *file, void *__fh, struct v4l2_buffer *buf)
2533 res = -EAGAIN; 2216 res = -EAGAIN;
2534 goto dqbuf_unlock_and_return; 2217 goto dqbuf_unlock_and_return;
2535 } 2218 }
2219 bs.frame = 0; /* suppress compiler warning */
2536 res = jpg_sync(fh, &bs); 2220 res = jpg_sync(fh, &bs);
2537 if (res) 2221 if (res)
2538 goto dqbuf_unlock_and_return; 2222 goto dqbuf_unlock_and_return;
@@ -2766,11 +2450,6 @@ static int zoran_enum_input(struct file *file, void *__fh,
2766 2450
2767 if (inp->index >= zr->card.inputs) 2451 if (inp->index >= zr->card.inputs)
2768 return -EINVAL; 2452 return -EINVAL;
2769 else {
2770 int id = inp->index;
2771 memset(inp, 0, sizeof(*inp));
2772 inp->index = id;
2773 }
2774 2453
2775 strncpy(inp->name, zr->card.input[inp->index].name, 2454 strncpy(inp->name, zr->card.input[inp->index].name,
2776 sizeof(inp->name) - 1); 2455 sizeof(inp->name) - 1);
@@ -2820,7 +2499,6 @@ static int zoran_enum_output(struct file *file, void *__fh,
2820 if (outp->index != 0) 2499 if (outp->index != 0)
2821 return -EINVAL; 2500 return -EINVAL;
2822 2501
2823 memset(outp, 0, sizeof(*outp));
2824 outp->index = 0; 2502 outp->index = 0;
2825 outp->type = V4L2_OUTPUT_TYPE_ANALOGVGAOVERLAY; 2503 outp->type = V4L2_OUTPUT_TYPE_ANALOGVGAOVERLAY;
2826 strncpy(outp->name, "Autodetect", sizeof(outp->name)-1); 2504 strncpy(outp->name, "Autodetect", sizeof(outp->name)-1);
@@ -3364,10 +3042,6 @@ static const struct v4l2_ioctl_ops zoran_ioctl_ops = {
3364 .vidioc_queryctrl = zoran_queryctrl, 3042 .vidioc_queryctrl = zoran_queryctrl,
3365 .vidioc_s_ctrl = zoran_s_ctrl, 3043 .vidioc_s_ctrl = zoran_s_ctrl,
3366 .vidioc_g_ctrl = zoran_g_ctrl, 3044 .vidioc_g_ctrl = zoran_g_ctrl,
3367#ifdef CONFIG_VIDEO_V4L1_COMPAT
3368 .vidioc_default = zoran_default,
3369 .vidiocgmbuf = zoran_vidiocgmbuf,
3370#endif
3371}; 3045};
3372 3046
3373/* please use zr->resource_lock consistently and kill this wrapper */ 3047/* please use zr->resource_lock consistently and kill this wrapper */
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index e8e704f52746..da9d2971102e 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -606,6 +606,16 @@ config MFD_VX855
606 VIA VX855/VX875 south bridge. You will need to enable the vx855_spi 606 VIA VX855/VX875 south bridge. You will need to enable the vx855_spi
607 and/or vx855_gpio drivers for this to do anything useful. 607 and/or vx855_gpio drivers for this to do anything useful.
608 608
609config MFD_WL1273_CORE
610 tristate
611 depends on I2C
612 select MFD_CORE
613 default n
614 help
615 This is the core driver for the TI WL1273 FM radio. This MFD
616 driver connects the radio-wl1273 V4L2 module and the wl1273
617 audio codec.
618
609endif # MFD_SUPPORT 619endif # MFD_SUPPORT
610 620
611menu "Multimedia Capabilities Port drivers" 621menu "Multimedia Capabilities Port drivers"
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index e590d1e44cf0..848e7eac75aa 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -81,3 +81,4 @@ obj-$(CONFIG_MFD_JANZ_CMODIO) += janz-cmodio.o
81obj-$(CONFIG_MFD_JZ4740_ADC) += jz4740-adc.o 81obj-$(CONFIG_MFD_JZ4740_ADC) += jz4740-adc.o
82obj-$(CONFIG_MFD_TPS6586X) += tps6586x.o 82obj-$(CONFIG_MFD_TPS6586X) += tps6586x.o
83obj-$(CONFIG_MFD_VX855) += vx855.o 83obj-$(CONFIG_MFD_VX855) += vx855.o
84obj-$(CONFIG_MFD_WL1273_CORE) += wl1273-core.o
diff --git a/drivers/mfd/timberdale.c b/drivers/mfd/timberdale.c
index 727f62c15a60..6ad8a7f8d390 100644
--- a/drivers/mfd/timberdale.c
+++ b/drivers/mfd/timberdale.c
@@ -40,6 +40,7 @@
40#include <linux/spi/mc33880.h> 40#include <linux/spi/mc33880.h>
41 41
42#include <media/timb_radio.h> 42#include <media/timb_radio.h>
43#include <media/timb_video.h>
43 44
44#include <linux/timb_dma.h> 45#include <linux/timb_dma.h>
45 46
@@ -246,7 +247,23 @@ static const __devinitconst struct resource timberdale_uartlite_resources[] = {
246 }, 247 },
247}; 248};
248 249
249static const __devinitconst struct resource timberdale_radio_resources[] = { 250static __devinitdata struct i2c_board_info timberdale_adv7180_i2c_board_info = {
251 /* Requires jumper JP9 to be off */
252 I2C_BOARD_INFO("adv7180", 0x42 >> 1),
253 .irq = IRQ_TIMBERDALE_ADV7180
254};
255
256static __devinitdata struct timb_video_platform_data
257 timberdale_video_platform_data = {
258 .dma_channel = DMA_VIDEO_RX,
259 .i2c_adapter = 0,
260 .encoder = {
261 .info = &timberdale_adv7180_i2c_board_info
262 }
263};
264
265static const __devinitconst struct resource
266timberdale_radio_resources[] = {
250 { 267 {
251 .start = RDSOFFSET, 268 .start = RDSOFFSET,
252 .end = RDSEND, 269 .end = RDSEND,
@@ -271,15 +288,25 @@ static __devinitdata struct timb_radio_platform_data
271 timberdale_radio_platform_data = { 288 timberdale_radio_platform_data = {
272 .i2c_adapter = 0, 289 .i2c_adapter = 0,
273 .tuner = { 290 .tuner = {
274 .module_name = "tef6862",
275 .info = &timberdale_tef6868_i2c_board_info 291 .info = &timberdale_tef6868_i2c_board_info
276 }, 292 },
277 .dsp = { 293 .dsp = {
278 .module_name = "saa7706h",
279 .info = &timberdale_saa7706_i2c_board_info 294 .info = &timberdale_saa7706_i2c_board_info
280 } 295 }
281}; 296};
282 297
298static const __devinitconst struct resource timberdale_video_resources[] = {
299 {
300 .start = LOGIWOFFSET,
301 .end = LOGIWEND,
302 .flags = IORESOURCE_MEM,
303 },
304 /*
305 note that the "frame buffer" is located in DMA area
306 starting at 0x1200000
307 */
308};
309
283static __devinitdata struct timb_dma_platform_data timb_dma_platform_data = { 310static __devinitdata struct timb_dma_platform_data timb_dma_platform_data = {
284 .nr_channels = 10, 311 .nr_channels = 10,
285 .channels = { 312 .channels = {
@@ -380,6 +407,13 @@ static __devinitdata struct mfd_cell timberdale_cells_bar0_cfg0[] = {
380 .data_size = sizeof(timberdale_gpio_platform_data), 407 .data_size = sizeof(timberdale_gpio_platform_data),
381 }, 408 },
382 { 409 {
410 .name = "timb-video",
411 .num_resources = ARRAY_SIZE(timberdale_video_resources),
412 .resources = timberdale_video_resources,
413 .platform_data = &timberdale_video_platform_data,
414 .data_size = sizeof(timberdale_video_platform_data),
415 },
416 {
383 .name = "timb-radio", 417 .name = "timb-radio",
384 .num_resources = ARRAY_SIZE(timberdale_radio_resources), 418 .num_resources = ARRAY_SIZE(timberdale_radio_resources),
385 .resources = timberdale_radio_resources, 419 .resources = timberdale_radio_resources,
@@ -440,6 +474,13 @@ static __devinitdata struct mfd_cell timberdale_cells_bar0_cfg1[] = {
440 .resources = timberdale_mlogicore_resources, 474 .resources = timberdale_mlogicore_resources,
441 }, 475 },
442 { 476 {
477 .name = "timb-video",
478 .num_resources = ARRAY_SIZE(timberdale_video_resources),
479 .resources = timberdale_video_resources,
480 .platform_data = &timberdale_video_platform_data,
481 .data_size = sizeof(timberdale_video_platform_data),
482 },
483 {
443 .name = "timb-radio", 484 .name = "timb-radio",
444 .num_resources = ARRAY_SIZE(timberdale_radio_resources), 485 .num_resources = ARRAY_SIZE(timberdale_radio_resources),
445 .resources = timberdale_radio_resources, 486 .resources = timberdale_radio_resources,
@@ -490,6 +531,13 @@ static __devinitdata struct mfd_cell timberdale_cells_bar0_cfg2[] = {
490 .data_size = sizeof(timberdale_gpio_platform_data), 531 .data_size = sizeof(timberdale_gpio_platform_data),
491 }, 532 },
492 { 533 {
534 .name = "timb-video",
535 .num_resources = ARRAY_SIZE(timberdale_video_resources),
536 .resources = timberdale_video_resources,
537 .platform_data = &timberdale_video_platform_data,
538 .data_size = sizeof(timberdale_video_platform_data),
539 },
540 {
493 .name = "timb-radio", 541 .name = "timb-radio",
494 .num_resources = ARRAY_SIZE(timberdale_radio_resources), 542 .num_resources = ARRAY_SIZE(timberdale_radio_resources),
495 .resources = timberdale_radio_resources, 543 .resources = timberdale_radio_resources,
@@ -533,6 +581,13 @@ static __devinitdata struct mfd_cell timberdale_cells_bar0_cfg3[] = {
533 .data_size = sizeof(timberdale_gpio_platform_data), 581 .data_size = sizeof(timberdale_gpio_platform_data),
534 }, 582 },
535 { 583 {
584 .name = "timb-video",
585 .num_resources = ARRAY_SIZE(timberdale_video_resources),
586 .resources = timberdale_video_resources,
587 .platform_data = &timberdale_video_platform_data,
588 .data_size = sizeof(timberdale_video_platform_data),
589 },
590 {
536 .name = "timb-radio", 591 .name = "timb-radio",
537 .num_resources = ARRAY_SIZE(timberdale_radio_resources), 592 .num_resources = ARRAY_SIZE(timberdale_radio_resources),
538 .resources = timberdale_radio_resources, 593 .resources = timberdale_radio_resources,
diff --git a/drivers/mfd/timberdale.h b/drivers/mfd/timberdale.h
index c11bf6ebfe00..4412acd826fa 100644
--- a/drivers/mfd/timberdale.h
+++ b/drivers/mfd/timberdale.h
@@ -23,7 +23,7 @@
23#ifndef MFD_TIMBERDALE_H 23#ifndef MFD_TIMBERDALE_H
24#define MFD_TIMBERDALE_H 24#define MFD_TIMBERDALE_H
25 25
26#define DRV_VERSION "0.2" 26#define DRV_VERSION "0.3"
27 27
28/* This driver only support versions >= 3.8 and < 4.0 */ 28/* This driver only support versions >= 3.8 and < 4.0 */
29#define TIMB_SUPPORTED_MAJOR 3 29#define TIMB_SUPPORTED_MAJOR 3
diff --git a/drivers/mfd/wl1273-core.c b/drivers/mfd/wl1273-core.c
new file mode 100644
index 000000000000..d2ecc2435736
--- /dev/null
+++ b/drivers/mfd/wl1273-core.c
@@ -0,0 +1,148 @@
1/*
2 * MFD driver for wl1273 FM radio and audio codec submodules.
3 *
4 * Copyright (C) 2010 Nokia Corporation
5 * Author: Matti Aaltonen <matti.j.aaltonen@nokia.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * 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., 51 Franklin St, Fifth Floor, Boston, MA
19 * 02110-1301 USA
20 *
21 */
22
23#include <linux/mfd/wl1273-core.h>
24#include <linux/slab.h>
25
26#define DRIVER_DESC "WL1273 FM Radio Core"
27
28static struct i2c_device_id wl1273_driver_id_table[] = {
29 { WL1273_FM_DRIVER_NAME, 0 },
30 { }
31};
32MODULE_DEVICE_TABLE(i2c, wl1273_driver_id_table);
33
34static int wl1273_core_remove(struct i2c_client *client)
35{
36 struct wl1273_core *core = i2c_get_clientdata(client);
37
38 dev_dbg(&client->dev, "%s\n", __func__);
39
40 mfd_remove_devices(&client->dev);
41 i2c_set_clientdata(client, NULL);
42 kfree(core);
43
44 return 0;
45}
46
47static int __devinit wl1273_core_probe(struct i2c_client *client,
48 const struct i2c_device_id *id)
49{
50 struct wl1273_fm_platform_data *pdata = client->dev.platform_data;
51 struct wl1273_core *core;
52 struct mfd_cell *cell;
53 int children = 0;
54 int r = 0;
55
56 dev_dbg(&client->dev, "%s\n", __func__);
57
58 if (!pdata) {
59 dev_err(&client->dev, "No platform data.\n");
60 return -EINVAL;
61 }
62
63 if (!(pdata->children & WL1273_RADIO_CHILD)) {
64 dev_err(&client->dev, "Cannot function without radio child.\n");
65 return -EINVAL;
66 }
67
68 core = kzalloc(sizeof(*core), GFP_KERNEL);
69 if (!core)
70 return -ENOMEM;
71
72 core->pdata = pdata;
73 core->client = client;
74 mutex_init(&core->lock);
75
76 i2c_set_clientdata(client, core);
77
78 dev_dbg(&client->dev, "%s: Have V4L2.\n", __func__);
79
80 cell = &core->cells[children];
81 cell->name = "wl1273_fm_radio";
82 cell->platform_data = &core;
83 cell->data_size = sizeof(core);
84 children++;
85
86 if (pdata->children & WL1273_CODEC_CHILD) {
87 cell = &core->cells[children];
88
89 dev_dbg(&client->dev, "%s: Have codec.\n", __func__);
90 cell->name = "wl1273-codec";
91 cell->platform_data = &core;
92 cell->data_size = sizeof(core);
93 children++;
94 }
95
96 dev_dbg(&client->dev, "%s: number of children: %d.\n",
97 __func__, children);
98
99 r = mfd_add_devices(&client->dev, -1, core->cells,
100 children, NULL, 0);
101 if (r)
102 goto err;
103
104 return 0;
105
106err:
107 i2c_set_clientdata(client, NULL);
108 pdata->free_resources();
109 kfree(core);
110
111 dev_dbg(&client->dev, "%s\n", __func__);
112
113 return r;
114}
115
116static struct i2c_driver wl1273_core_driver = {
117 .driver = {
118 .name = WL1273_FM_DRIVER_NAME,
119 },
120 .probe = wl1273_core_probe,
121 .id_table = wl1273_driver_id_table,
122 .remove = __devexit_p(wl1273_core_remove),
123};
124
125static int __init wl1273_core_init(void)
126{
127 int r;
128
129 r = i2c_add_driver(&wl1273_core_driver);
130 if (r) {
131 pr_err(WL1273_FM_DRIVER_NAME
132 ": driver registration failed\n");
133 return r;
134 }
135
136 return r;
137}
138
139static void __exit wl1273_core_exit(void)
140{
141 i2c_del_driver(&wl1273_core_driver);
142}
143late_initcall(wl1273_core_init);
144module_exit(wl1273_core_exit);
145
146MODULE_AUTHOR("Matti Aaltonen <matti.j.aaltonen@nokia.com>");
147MODULE_DESCRIPTION(DRIVER_DESC);
148MODULE_LICENSE("GPL");
diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig
index df31a7228079..bdc632b6b586 100644
--- a/drivers/staging/Kconfig
+++ b/drivers/staging/Kconfig
@@ -51,9 +51,11 @@ source "drivers/staging/cx25821/Kconfig"
51 51
52source "drivers/staging/tm6000/Kconfig" 52source "drivers/staging/tm6000/Kconfig"
53 53
54source "drivers/staging/cpia/Kconfig" 54source "drivers/staging/dabusb/Kconfig"
55 55
56source "drivers/staging/stradis/Kconfig" 56source "drivers/staging/se401/Kconfig"
57
58source "drivers/staging/usbvideo/Kconfig"
57 59
58source "drivers/staging/usbip/Kconfig" 60source "drivers/staging/usbip/Kconfig"
59 61
diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile
index 7a15c0c82b69..3eda5c73a50a 100644
--- a/drivers/staging/Makefile
+++ b/drivers/staging/Makefile
@@ -8,8 +8,9 @@ obj-$(CONFIG_SLICOSS) += slicoss/
8obj-$(CONFIG_VIDEO_GO7007) += go7007/ 8obj-$(CONFIG_VIDEO_GO7007) += go7007/
9obj-$(CONFIG_VIDEO_CX25821) += cx25821/ 9obj-$(CONFIG_VIDEO_CX25821) += cx25821/
10obj-$(CONFIG_VIDEO_TM6000) += tm6000/ 10obj-$(CONFIG_VIDEO_TM6000) += tm6000/
11obj-$(CONFIG_VIDEO_CPIA) += cpia/ 11obj-$(CONFIG_USB_DABUSB) += dabusb/
12obj-$(CONFIG_VIDEO_STRADIS) += stradis/ 12obj-$(CONFIG_USB_VICAM) += usbvideo/
13obj-$(CONFIG_USB_SE401) += se401/
13obj-$(CONFIG_LIRC_STAGING) += lirc/ 14obj-$(CONFIG_LIRC_STAGING) += lirc/
14obj-$(CONFIG_USB_IP_COMMON) += usbip/ 15obj-$(CONFIG_USB_IP_COMMON) += usbip/
15obj-$(CONFIG_W35UND) += winbond/ 16obj-$(CONFIG_W35UND) += winbond/
diff --git a/drivers/staging/cpia/Kconfig b/drivers/staging/cpia/Kconfig
deleted file mode 100644
index 205d247ad373..000000000000
--- a/drivers/staging/cpia/Kconfig
+++ /dev/null
@@ -1,39 +0,0 @@
1config VIDEO_CPIA
2 tristate "CPiA Video For Linux (DEPRECATED)"
3 depends on VIDEO_V4L1
4 default n
5 ---help---
6 This driver is DEPRECATED please use the gspca cpia1 module
7 instead. Note that you need atleast version 0.6.4 of libv4l for
8 the cpia1 gspca module.
9
10 This is the video4linux driver for cameras based on Vision's CPiA
11 (Colour Processor Interface ASIC), such as the Creative Labs Video
12 Blaster Webcam II. If you have one of these cameras, say Y here
13 and select parallel port and/or USB lowlevel support below,
14 otherwise say N. This will not work with the Creative Webcam III.
15
16 Please read <file:Documentation/video4linux/README.cpia> for more
17 information.
18
19 This driver is also available as a module (cpia).
20
21config VIDEO_CPIA_PP
22 tristate "CPiA Parallel Port Lowlevel Support"
23 depends on PARPORT_1284 && VIDEO_CPIA && PARPORT
24 help
25 This is the lowlevel parallel port support for cameras based on
26 Vision's CPiA (Colour Processor Interface ASIC), such as the
27 Creative Webcam II. If you have the parallel port version of one
28 of these cameras, say Y here, otherwise say N. It is also available
29 as a module (cpia_pp).
30
31config VIDEO_CPIA_USB
32 tristate "CPiA USB Lowlevel Support"
33 depends on VIDEO_CPIA && USB
34 help
35 This is the lowlevel USB support for cameras based on Vision's CPiA
36 (Colour Processor Interface ASIC), such as the Creative Webcam II.
37 If you have the USB version of one of these cameras, say Y here,
38 otherwise say N. This will not work with the Creative Webcam III.
39 It is also available as a module (cpia_usb).
diff --git a/drivers/staging/cpia/Makefile b/drivers/staging/cpia/Makefile
deleted file mode 100644
index 89e52f10d739..000000000000
--- a/drivers/staging/cpia/Makefile
+++ /dev/null
@@ -1,5 +0,0 @@
1obj-$(CONFIG_VIDEO_CPIA) += cpia.o
2obj-$(CONFIG_VIDEO_CPIA_PP) += cpia_pp.o
3obj-$(CONFIG_VIDEO_CPIA_USB) += cpia_usb.o
4
5EXTRA_CFLAGS += -Idrivers/media/video
diff --git a/drivers/staging/cpia/TODO b/drivers/staging/cpia/TODO
deleted file mode 100644
index ccb1c0775eec..000000000000
--- a/drivers/staging/cpia/TODO
+++ /dev/null
@@ -1,8 +0,0 @@
1This is an obsolete driver for some cpia-based webcams that use the parallel port.
2We couldn't find anyone with this hardware in order to port it to use V4L2.
3
4Also, parallel-port webcams are obsolete nowadays.
5
6If nobody take care on it, the driver will be removed for 2.6.38.
7
8Please send patches to linux-media@vger.kernel.org
diff --git a/drivers/staging/cpia/cpia.c b/drivers/staging/cpia/cpia.c
deleted file mode 100644
index 0e740b8dafc3..000000000000
--- a/drivers/staging/cpia/cpia.c
+++ /dev/null
@@ -1,4028 +0,0 @@
1/*
2 * cpia CPiA driver
3 *
4 * Supports CPiA based Video Camera's.
5 *
6 * (C) Copyright 1999-2000 Peter Pregler
7 * (C) Copyright 1999-2000 Scott J. Bertin
8 * (C) Copyright 1999-2000 Johannes Erdfelt <johannes@erdfelt.com>
9 * (C) Copyright 2000 STMicroelectronics
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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/* define _CPIA_DEBUG_ for verbose debug output (see cpia.h) */
27/* #define _CPIA_DEBUG_ 1 */
28
29
30#include <linux/module.h>
31#include <linux/init.h>
32#include <linux/fs.h>
33#include <linux/vmalloc.h>
34#include <linux/sched.h>
35#include <linux/seq_file.h>
36#include <linux/slab.h>
37#include <linux/proc_fs.h>
38#include <linux/ctype.h>
39#include <linux/pagemap.h>
40#include <linux/delay.h>
41#include <asm/io.h>
42#include <linux/mutex.h>
43
44#include "cpia.h"
45
46static int video_nr = -1;
47
48#ifdef MODULE
49module_param(video_nr, int, 0);
50MODULE_AUTHOR("Scott J. Bertin <sbertin@securenym.net> & Peter Pregler <Peter_Pregler@email.com> & Johannes Erdfelt <johannes@erdfelt.com>");
51MODULE_DESCRIPTION("V4L-driver for Vision CPiA based cameras");
52MODULE_LICENSE("GPL");
53MODULE_SUPPORTED_DEVICE("video");
54#endif
55
56static unsigned short colorspace_conv;
57module_param(colorspace_conv, ushort, 0444);
58MODULE_PARM_DESC(colorspace_conv,
59 " Colorspace conversion:"
60 "\n 0 = disable, 1 = enable"
61 "\n Default value is 0"
62 );
63
64#define ABOUT "V4L-Driver for Vision CPiA based cameras"
65
66#define CPIA_MODULE_CPIA (0<<5)
67#define CPIA_MODULE_SYSTEM (1<<5)
68#define CPIA_MODULE_VP_CTRL (5<<5)
69#define CPIA_MODULE_CAPTURE (6<<5)
70#define CPIA_MODULE_DEBUG (7<<5)
71
72#define INPUT (DATA_IN << 8)
73#define OUTPUT (DATA_OUT << 8)
74
75#define CPIA_COMMAND_GetCPIAVersion (INPUT | CPIA_MODULE_CPIA | 1)
76#define CPIA_COMMAND_GetPnPID (INPUT | CPIA_MODULE_CPIA | 2)
77#define CPIA_COMMAND_GetCameraStatus (INPUT | CPIA_MODULE_CPIA | 3)
78#define CPIA_COMMAND_GotoHiPower (OUTPUT | CPIA_MODULE_CPIA | 4)
79#define CPIA_COMMAND_GotoLoPower (OUTPUT | CPIA_MODULE_CPIA | 5)
80#define CPIA_COMMAND_GotoSuspend (OUTPUT | CPIA_MODULE_CPIA | 7)
81#define CPIA_COMMAND_GotoPassThrough (OUTPUT | CPIA_MODULE_CPIA | 8)
82#define CPIA_COMMAND_ModifyCameraStatus (OUTPUT | CPIA_MODULE_CPIA | 10)
83
84#define CPIA_COMMAND_ReadVCRegs (INPUT | CPIA_MODULE_SYSTEM | 1)
85#define CPIA_COMMAND_WriteVCReg (OUTPUT | CPIA_MODULE_SYSTEM | 2)
86#define CPIA_COMMAND_ReadMCPorts (INPUT | CPIA_MODULE_SYSTEM | 3)
87#define CPIA_COMMAND_WriteMCPort (OUTPUT | CPIA_MODULE_SYSTEM | 4)
88#define CPIA_COMMAND_SetBaudRate (OUTPUT | CPIA_MODULE_SYSTEM | 5)
89#define CPIA_COMMAND_SetECPTiming (OUTPUT | CPIA_MODULE_SYSTEM | 6)
90#define CPIA_COMMAND_ReadIDATA (INPUT | CPIA_MODULE_SYSTEM | 7)
91#define CPIA_COMMAND_WriteIDATA (OUTPUT | CPIA_MODULE_SYSTEM | 8)
92#define CPIA_COMMAND_GenericCall (OUTPUT | CPIA_MODULE_SYSTEM | 9)
93#define CPIA_COMMAND_I2CStart (OUTPUT | CPIA_MODULE_SYSTEM | 10)
94#define CPIA_COMMAND_I2CStop (OUTPUT | CPIA_MODULE_SYSTEM | 11)
95#define CPIA_COMMAND_I2CWrite (OUTPUT | CPIA_MODULE_SYSTEM | 12)
96#define CPIA_COMMAND_I2CRead (INPUT | CPIA_MODULE_SYSTEM | 13)
97
98#define CPIA_COMMAND_GetVPVersion (INPUT | CPIA_MODULE_VP_CTRL | 1)
99#define CPIA_COMMAND_ResetFrameCounter (INPUT | CPIA_MODULE_VP_CTRL | 2)
100#define CPIA_COMMAND_SetColourParams (OUTPUT | CPIA_MODULE_VP_CTRL | 3)
101#define CPIA_COMMAND_SetExposure (OUTPUT | CPIA_MODULE_VP_CTRL | 4)
102#define CPIA_COMMAND_SetColourBalance (OUTPUT | CPIA_MODULE_VP_CTRL | 6)
103#define CPIA_COMMAND_SetSensorFPS (OUTPUT | CPIA_MODULE_VP_CTRL | 7)
104#define CPIA_COMMAND_SetVPDefaults (OUTPUT | CPIA_MODULE_VP_CTRL | 8)
105#define CPIA_COMMAND_SetApcor (OUTPUT | CPIA_MODULE_VP_CTRL | 9)
106#define CPIA_COMMAND_SetFlickerCtrl (OUTPUT | CPIA_MODULE_VP_CTRL | 10)
107#define CPIA_COMMAND_SetVLOffset (OUTPUT | CPIA_MODULE_VP_CTRL | 11)
108#define CPIA_COMMAND_GetColourParams (INPUT | CPIA_MODULE_VP_CTRL | 16)
109#define CPIA_COMMAND_GetColourBalance (INPUT | CPIA_MODULE_VP_CTRL | 17)
110#define CPIA_COMMAND_GetExposure (INPUT | CPIA_MODULE_VP_CTRL | 18)
111#define CPIA_COMMAND_SetSensorMatrix (OUTPUT | CPIA_MODULE_VP_CTRL | 19)
112#define CPIA_COMMAND_ColourBars (OUTPUT | CPIA_MODULE_VP_CTRL | 25)
113#define CPIA_COMMAND_ReadVPRegs (INPUT | CPIA_MODULE_VP_CTRL | 30)
114#define CPIA_COMMAND_WriteVPReg (OUTPUT | CPIA_MODULE_VP_CTRL | 31)
115
116#define CPIA_COMMAND_GrabFrame (OUTPUT | CPIA_MODULE_CAPTURE | 1)
117#define CPIA_COMMAND_UploadFrame (OUTPUT | CPIA_MODULE_CAPTURE | 2)
118#define CPIA_COMMAND_SetGrabMode (OUTPUT | CPIA_MODULE_CAPTURE | 3)
119#define CPIA_COMMAND_InitStreamCap (OUTPUT | CPIA_MODULE_CAPTURE | 4)
120#define CPIA_COMMAND_FiniStreamCap (OUTPUT | CPIA_MODULE_CAPTURE | 5)
121#define CPIA_COMMAND_StartStreamCap (OUTPUT | CPIA_MODULE_CAPTURE | 6)
122#define CPIA_COMMAND_EndStreamCap (OUTPUT | CPIA_MODULE_CAPTURE | 7)
123#define CPIA_COMMAND_SetFormat (OUTPUT | CPIA_MODULE_CAPTURE | 8)
124#define CPIA_COMMAND_SetROI (OUTPUT | CPIA_MODULE_CAPTURE | 9)
125#define CPIA_COMMAND_SetCompression (OUTPUT | CPIA_MODULE_CAPTURE | 10)
126#define CPIA_COMMAND_SetCompressionTarget (OUTPUT | CPIA_MODULE_CAPTURE | 11)
127#define CPIA_COMMAND_SetYUVThresh (OUTPUT | CPIA_MODULE_CAPTURE | 12)
128#define CPIA_COMMAND_SetCompressionParams (OUTPUT | CPIA_MODULE_CAPTURE | 13)
129#define CPIA_COMMAND_DiscardFrame (OUTPUT | CPIA_MODULE_CAPTURE | 14)
130#define CPIA_COMMAND_GrabReset (OUTPUT | CPIA_MODULE_CAPTURE | 15)
131
132#define CPIA_COMMAND_OutputRS232 (OUTPUT | CPIA_MODULE_DEBUG | 1)
133#define CPIA_COMMAND_AbortProcess (OUTPUT | CPIA_MODULE_DEBUG | 4)
134#define CPIA_COMMAND_SetDramPage (OUTPUT | CPIA_MODULE_DEBUG | 5)
135#define CPIA_COMMAND_StartDramUpload (OUTPUT | CPIA_MODULE_DEBUG | 6)
136#define CPIA_COMMAND_StartDummyDtream (OUTPUT | CPIA_MODULE_DEBUG | 8)
137#define CPIA_COMMAND_AbortStream (OUTPUT | CPIA_MODULE_DEBUG | 9)
138#define CPIA_COMMAND_DownloadDRAM (OUTPUT | CPIA_MODULE_DEBUG | 10)
139#define CPIA_COMMAND_Null (OUTPUT | CPIA_MODULE_DEBUG | 11)
140
141enum {
142 FRAME_READY, /* Ready to grab into */
143 FRAME_GRABBING, /* In the process of being grabbed into */
144 FRAME_DONE, /* Finished grabbing, but not been synced yet */
145 FRAME_UNUSED, /* Unused (no MCAPTURE) */
146};
147
148#define COMMAND_NONE 0x0000
149#define COMMAND_SETCOMPRESSION 0x0001
150#define COMMAND_SETCOMPRESSIONTARGET 0x0002
151#define COMMAND_SETCOLOURPARAMS 0x0004
152#define COMMAND_SETFORMAT 0x0008
153#define COMMAND_PAUSE 0x0010
154#define COMMAND_RESUME 0x0020
155#define COMMAND_SETYUVTHRESH 0x0040
156#define COMMAND_SETECPTIMING 0x0080
157#define COMMAND_SETCOMPRESSIONPARAMS 0x0100
158#define COMMAND_SETEXPOSURE 0x0200
159#define COMMAND_SETCOLOURBALANCE 0x0400
160#define COMMAND_SETSENSORFPS 0x0800
161#define COMMAND_SETAPCOR 0x1000
162#define COMMAND_SETFLICKERCTRL 0x2000
163#define COMMAND_SETVLOFFSET 0x4000
164#define COMMAND_SETLIGHTS 0x8000
165
166#define ROUND_UP_EXP_FOR_FLICKER 15
167
168/* Constants for automatic frame rate adjustment */
169#define MAX_EXP 302
170#define MAX_EXP_102 255
171#define LOW_EXP 140
172#define VERY_LOW_EXP 70
173#define TC 94
174#define EXP_ACC_DARK 50
175#define EXP_ACC_LIGHT 90
176#define HIGH_COMP_102 160
177#define MAX_COMP 239
178#define DARK_TIME 3
179#define LIGHT_TIME 3
180
181/* Maximum number of 10ms loops to wait for the stream to become ready */
182#define READY_TIMEOUT 100
183
184/* Developer's Guide Table 5 p 3-34
185 * indexed by [mains][sensorFps.baserate][sensorFps.divisor]*/
186static u8 flicker_jumps[2][2][4] =
187{ { { 76, 38, 19, 9 }, { 92, 46, 23, 11 } },
188 { { 64, 32, 16, 8 }, { 76, 38, 19, 9} }
189};
190
191/* forward declaration of local function */
192static void reset_camera_struct(struct cam_data *cam);
193static int find_over_exposure(int brightness);
194static void set_flicker(struct cam_params *params, volatile u32 *command_flags,
195 int on);
196
197
198/**********************************************************************
199 *
200 * Memory management
201 *
202 **********************************************************************/
203static void *rvmalloc(unsigned long size)
204{
205 void *mem;
206 unsigned long adr;
207
208 size = PAGE_ALIGN(size);
209 mem = vmalloc_32(size);
210 if (!mem)
211 return NULL;
212
213 memset(mem, 0, size); /* Clear the ram out, no junk to the user */
214 adr = (unsigned long) mem;
215 while (size > 0) {
216 SetPageReserved(vmalloc_to_page((void *)adr));
217 adr += PAGE_SIZE;
218 size -= PAGE_SIZE;
219 }
220
221 return mem;
222}
223
224static void rvfree(void *mem, unsigned long size)
225{
226 unsigned long adr;
227
228 if (!mem)
229 return;
230
231 adr = (unsigned long) mem;
232 while ((long) size > 0) {
233 ClearPageReserved(vmalloc_to_page((void *)adr));
234 adr += PAGE_SIZE;
235 size -= PAGE_SIZE;
236 }
237 vfree(mem);
238}
239
240/**********************************************************************
241 *
242 * /proc interface
243 *
244 **********************************************************************/
245#ifdef CONFIG_PROC_FS
246static struct proc_dir_entry *cpia_proc_root=NULL;
247
248static int cpia_proc_show(struct seq_file *m, void *v)
249{
250 struct cam_data *cam = m->private;
251 int tmp;
252 char tmpstr[29];
253
254 seq_printf(m, "read-only\n-----------------------\n");
255 seq_printf(m, "V4L Driver version: %d.%d.%d\n",
256 CPIA_MAJ_VER, CPIA_MIN_VER, CPIA_PATCH_VER);
257 seq_printf(m, "CPIA Version: %d.%02d (%d.%d)\n",
258 cam->params.version.firmwareVersion,
259 cam->params.version.firmwareRevision,
260 cam->params.version.vcVersion,
261 cam->params.version.vcRevision);
262 seq_printf(m, "CPIA PnP-ID: %04x:%04x:%04x\n",
263 cam->params.pnpID.vendor, cam->params.pnpID.product,
264 cam->params.pnpID.deviceRevision);
265 seq_printf(m, "VP-Version: %d.%d %04x\n",
266 cam->params.vpVersion.vpVersion,
267 cam->params.vpVersion.vpRevision,
268 cam->params.vpVersion.cameraHeadID);
269
270 seq_printf(m, "system_state: %#04x\n",
271 cam->params.status.systemState);
272 seq_printf(m, "grab_state: %#04x\n",
273 cam->params.status.grabState);
274 seq_printf(m, "stream_state: %#04x\n",
275 cam->params.status.streamState);
276 seq_printf(m, "fatal_error: %#04x\n",
277 cam->params.status.fatalError);
278 seq_printf(m, "cmd_error: %#04x\n",
279 cam->params.status.cmdError);
280 seq_printf(m, "debug_flags: %#04x\n",
281 cam->params.status.debugFlags);
282 seq_printf(m, "vp_status: %#04x\n",
283 cam->params.status.vpStatus);
284 seq_printf(m, "error_code: %#04x\n",
285 cam->params.status.errorCode);
286 /* QX3 specific entries */
287 if (cam->params.qx3.qx3_detected) {
288 seq_printf(m, "button: %4d\n",
289 cam->params.qx3.button);
290 seq_printf(m, "cradled: %4d\n",
291 cam->params.qx3.cradled);
292 }
293 seq_printf(m, "video_size: %s\n",
294 cam->params.format.videoSize == VIDEOSIZE_CIF ?
295 "CIF " : "QCIF");
296 seq_printf(m, "roi: (%3d, %3d) to (%3d, %3d)\n",
297 cam->params.roi.colStart*8,
298 cam->params.roi.rowStart*4,
299 cam->params.roi.colEnd*8,
300 cam->params.roi.rowEnd*4);
301 seq_printf(m, "actual_fps: %3d\n", cam->fps);
302 seq_printf(m, "transfer_rate: %4dkB/s\n",
303 cam->transfer_rate);
304
305 seq_printf(m, "\nread-write\n");
306 seq_printf(m, "----------------------- current min"
307 " max default comment\n");
308 seq_printf(m, "brightness: %8d %8d %8d %8d\n",
309 cam->params.colourParams.brightness, 0, 100, 50);
310 if (cam->params.version.firmwareVersion == 1 &&
311 cam->params.version.firmwareRevision == 2)
312 /* 1-02 firmware limits contrast to 80 */
313 tmp = 80;
314 else
315 tmp = 96;
316
317 seq_printf(m, "contrast: %8d %8d %8d %8d"
318 " steps of 8\n",
319 cam->params.colourParams.contrast, 0, tmp, 48);
320 seq_printf(m, "saturation: %8d %8d %8d %8d\n",
321 cam->params.colourParams.saturation, 0, 100, 50);
322 tmp = (25000+5000*cam->params.sensorFps.baserate)/
323 (1<<cam->params.sensorFps.divisor);
324 seq_printf(m, "sensor_fps: %4d.%03d %8d %8d %8d\n",
325 tmp/1000, tmp%1000, 3, 30, 15);
326 seq_printf(m, "stream_start_line: %8d %8d %8d %8d\n",
327 2*cam->params.streamStartLine, 0,
328 cam->params.format.videoSize == VIDEOSIZE_CIF ? 288:144,
329 cam->params.format.videoSize == VIDEOSIZE_CIF ? 240:120);
330 seq_printf(m, "sub_sample: %8s %8s %8s %8s\n",
331 cam->params.format.subSample == SUBSAMPLE_420 ?
332 "420" : "422", "420", "422", "422");
333 seq_printf(m, "yuv_order: %8s %8s %8s %8s\n",
334 cam->params.format.yuvOrder == YUVORDER_YUYV ?
335 "YUYV" : "UYVY", "YUYV" , "UYVY", "YUYV");
336 seq_printf(m, "ecp_timing: %8s %8s %8s %8s\n",
337 cam->params.ecpTiming ? "slow" : "normal", "slow",
338 "normal", "normal");
339
340 if (cam->params.colourBalance.balanceMode == 2) {
341 sprintf(tmpstr, "auto");
342 } else {
343 sprintf(tmpstr, "manual");
344 }
345 seq_printf(m, "color_balance_mode: %8s %8s %8s"
346 " %8s\n", tmpstr, "manual", "auto", "auto");
347 seq_printf(m, "red_gain: %8d %8d %8d %8d\n",
348 cam->params.colourBalance.redGain, 0, 212, 32);
349 seq_printf(m, "green_gain: %8d %8d %8d %8d\n",
350 cam->params.colourBalance.greenGain, 0, 212, 6);
351 seq_printf(m, "blue_gain: %8d %8d %8d %8d\n",
352 cam->params.colourBalance.blueGain, 0, 212, 92);
353
354 if (cam->params.version.firmwareVersion == 1 &&
355 cam->params.version.firmwareRevision == 2)
356 /* 1-02 firmware limits gain to 2 */
357 sprintf(tmpstr, "%8d %8d %8d", 1, 2, 2);
358 else
359 sprintf(tmpstr, "%8d %8d %8d", 1, 8, 2);
360
361 if (cam->params.exposure.gainMode == 0)
362 seq_printf(m, "max_gain: unknown %28s"
363 " powers of 2\n", tmpstr);
364 else
365 seq_printf(m, "max_gain: %8d %28s"
366 " 1,2,4 or 8 \n",
367 1<<(cam->params.exposure.gainMode-1), tmpstr);
368
369 switch(cam->params.exposure.expMode) {
370 case 1:
371 case 3:
372 sprintf(tmpstr, "manual");
373 break;
374 case 2:
375 sprintf(tmpstr, "auto");
376 break;
377 default:
378 sprintf(tmpstr, "unknown");
379 break;
380 }
381 seq_printf(m, "exposure_mode: %8s %8s %8s"
382 " %8s\n", tmpstr, "manual", "auto", "auto");
383 seq_printf(m, "centre_weight: %8s %8s %8s %8s\n",
384 (2-cam->params.exposure.centreWeight) ? "on" : "off",
385 "off", "on", "on");
386 seq_printf(m, "gain: %8d %8d max_gain %8d 1,2,4,8 possible\n",
387 1<<cam->params.exposure.gain, 1, 1);
388 if (cam->params.version.firmwareVersion == 1 &&
389 cam->params.version.firmwareRevision == 2)
390 /* 1-02 firmware limits fineExp/2 to 127 */
391 tmp = 254;
392 else
393 tmp = 510;
394
395 seq_printf(m, "fine_exp: %8d %8d %8d %8d\n",
396 cam->params.exposure.fineExp*2, 0, tmp, 0);
397 if (cam->params.version.firmwareVersion == 1 &&
398 cam->params.version.firmwareRevision == 2)
399 /* 1-02 firmware limits coarseExpHi to 0 */
400 tmp = MAX_EXP_102;
401 else
402 tmp = MAX_EXP;
403
404 seq_printf(m, "coarse_exp: %8d %8d %8d"
405 " %8d\n", cam->params.exposure.coarseExpLo+
406 256*cam->params.exposure.coarseExpHi, 0, tmp, 185);
407 seq_printf(m, "red_comp: %8d %8d %8d %8d\n",
408 cam->params.exposure.redComp, COMP_RED, 255, COMP_RED);
409 seq_printf(m, "green1_comp: %8d %8d %8d %8d\n",
410 cam->params.exposure.green1Comp, COMP_GREEN1, 255,
411 COMP_GREEN1);
412 seq_printf(m, "green2_comp: %8d %8d %8d %8d\n",
413 cam->params.exposure.green2Comp, COMP_GREEN2, 255,
414 COMP_GREEN2);
415 seq_printf(m, "blue_comp: %8d %8d %8d %8d\n",
416 cam->params.exposure.blueComp, COMP_BLUE, 255, COMP_BLUE);
417
418 seq_printf(m, "apcor_gain1: %#8x %#8x %#8x %#8x\n",
419 cam->params.apcor.gain1, 0, 0xff, 0x1c);
420 seq_printf(m, "apcor_gain2: %#8x %#8x %#8x %#8x\n",
421 cam->params.apcor.gain2, 0, 0xff, 0x1a);
422 seq_printf(m, "apcor_gain4: %#8x %#8x %#8x %#8x\n",
423 cam->params.apcor.gain4, 0, 0xff, 0x2d);
424 seq_printf(m, "apcor_gain8: %#8x %#8x %#8x %#8x\n",
425 cam->params.apcor.gain8, 0, 0xff, 0x2a);
426 seq_printf(m, "vl_offset_gain1: %8d %8d %8d %8d\n",
427 cam->params.vlOffset.gain1, 0, 255, 24);
428 seq_printf(m, "vl_offset_gain2: %8d %8d %8d %8d\n",
429 cam->params.vlOffset.gain2, 0, 255, 28);
430 seq_printf(m, "vl_offset_gain4: %8d %8d %8d %8d\n",
431 cam->params.vlOffset.gain4, 0, 255, 30);
432 seq_printf(m, "vl_offset_gain8: %8d %8d %8d %8d\n",
433 cam->params.vlOffset.gain8, 0, 255, 30);
434 seq_printf(m, "flicker_control: %8s %8s %8s %8s\n",
435 cam->params.flickerControl.flickerMode ? "on" : "off",
436 "off", "on", "off");
437 seq_printf(m, "mains_frequency: %8d %8d %8d %8d"
438 " only 50/60\n",
439 cam->mainsFreq ? 60 : 50, 50, 60, 50);
440 if(cam->params.flickerControl.allowableOverExposure < 0)
441 seq_printf(m, "allowable_overexposure: %4dauto auto %8d auto\n",
442 -cam->params.flickerControl.allowableOverExposure,
443 255);
444 else
445 seq_printf(m, "allowable_overexposure: %8d auto %8d auto\n",
446 cam->params.flickerControl.allowableOverExposure,
447 255);
448 seq_printf(m, "compression_mode: ");
449 switch(cam->params.compression.mode) {
450 case CPIA_COMPRESSION_NONE:
451 seq_printf(m, "%8s", "none");
452 break;
453 case CPIA_COMPRESSION_AUTO:
454 seq_printf(m, "%8s", "auto");
455 break;
456 case CPIA_COMPRESSION_MANUAL:
457 seq_printf(m, "%8s", "manual");
458 break;
459 default:
460 seq_printf(m, "%8s", "unknown");
461 break;
462 }
463 seq_printf(m, " none,auto,manual auto\n");
464 seq_printf(m, "decimation_enable: %8s %8s %8s %8s\n",
465 cam->params.compression.decimation ==
466 DECIMATION_ENAB ? "on":"off", "off", "on",
467 "off");
468 seq_printf(m, "compression_target: %9s %9s %9s %9s\n",
469 cam->params.compressionTarget.frTargeting ==
470 CPIA_COMPRESSION_TARGET_FRAMERATE ?
471 "framerate":"quality",
472 "framerate", "quality", "quality");
473 seq_printf(m, "target_framerate: %8d %8d %8d %8d\n",
474 cam->params.compressionTarget.targetFR, 1, 30, 15);
475 seq_printf(m, "target_quality: %8d %8d %8d %8d\n",
476 cam->params.compressionTarget.targetQ, 1, 64, 5);
477 seq_printf(m, "y_threshold: %8d %8d %8d %8d\n",
478 cam->params.yuvThreshold.yThreshold, 0, 31, 6);
479 seq_printf(m, "uv_threshold: %8d %8d %8d %8d\n",
480 cam->params.yuvThreshold.uvThreshold, 0, 31, 6);
481 seq_printf(m, "hysteresis: %8d %8d %8d %8d\n",
482 cam->params.compressionParams.hysteresis, 0, 255, 3);
483 seq_printf(m, "threshold_max: %8d %8d %8d %8d\n",
484 cam->params.compressionParams.threshMax, 0, 255, 11);
485 seq_printf(m, "small_step: %8d %8d %8d %8d\n",
486 cam->params.compressionParams.smallStep, 0, 255, 1);
487 seq_printf(m, "large_step: %8d %8d %8d %8d\n",
488 cam->params.compressionParams.largeStep, 0, 255, 3);
489 seq_printf(m, "decimation_hysteresis: %8d %8d %8d %8d\n",
490 cam->params.compressionParams.decimationHysteresis,
491 0, 255, 2);
492 seq_printf(m, "fr_diff_step_thresh: %8d %8d %8d %8d\n",
493 cam->params.compressionParams.frDiffStepThresh,
494 0, 255, 5);
495 seq_printf(m, "q_diff_step_thresh: %8d %8d %8d %8d\n",
496 cam->params.compressionParams.qDiffStepThresh,
497 0, 255, 3);
498 seq_printf(m, "decimation_thresh_mod: %8d %8d %8d %8d\n",
499 cam->params.compressionParams.decimationThreshMod,
500 0, 255, 2);
501 /* QX3 specific entries */
502 if (cam->params.qx3.qx3_detected) {
503 seq_printf(m, "toplight: %8s %8s %8s %8s\n",
504 cam->params.qx3.toplight ? "on" : "off",
505 "off", "on", "off");
506 seq_printf(m, "bottomlight: %8s %8s %8s %8s\n",
507 cam->params.qx3.bottomlight ? "on" : "off",
508 "off", "on", "off");
509 }
510
511 return 0;
512}
513
514static int cpia_proc_open(struct inode *inode, struct file *file)
515{
516 return single_open(file, cpia_proc_show, PDE(inode)->data);
517}
518
519static int match(char *checkstr, char **buffer, size_t *count,
520 int *find_colon, int *err)
521{
522 int ret, colon_found = 1;
523 int len = strlen(checkstr);
524 ret = (len <= *count && strncmp(*buffer, checkstr, len) == 0);
525 if (ret) {
526 *buffer += len;
527 *count -= len;
528 if (*find_colon) {
529 colon_found = 0;
530 while (*count && (**buffer == ' ' || **buffer == '\t' ||
531 (!colon_found && **buffer == ':'))) {
532 if (**buffer == ':')
533 colon_found = 1;
534 --*count;
535 ++*buffer;
536 }
537 if (!*count || !colon_found)
538 *err = -EINVAL;
539 *find_colon = 0;
540 }
541 }
542 return ret;
543}
544
545static unsigned long int value(char **buffer, size_t *count, int *err)
546{
547 char *p;
548 unsigned long int ret;
549 ret = simple_strtoul(*buffer, &p, 0);
550 if (p == *buffer)
551 *err = -EINVAL;
552 else {
553 *count -= p - *buffer;
554 *buffer = p;
555 }
556 return ret;
557}
558
559static ssize_t cpia_proc_write(struct file *file, const char __user *buf,
560 size_t count, loff_t *pos)
561{
562 struct cam_data *cam = PDE(file->f_path.dentry->d_inode)->data;
563 struct cam_params new_params;
564 char *page, *buffer;
565 int retval, find_colon;
566 int size = count;
567 unsigned long val = 0;
568 u32 command_flags = 0;
569 u8 new_mains;
570
571 /*
572 * This code to copy from buf to page is shamelessly copied
573 * from the comx driver
574 */
575 if (count > PAGE_SIZE) {
576 printk(KERN_ERR "count is %zu > %d!!!\n", count, (int)PAGE_SIZE);
577 return -ENOSPC;
578 }
579
580 if (!(page = (char *)__get_free_page(GFP_KERNEL))) return -ENOMEM;
581
582 if(copy_from_user(page, buf, count))
583 {
584 retval = -EFAULT;
585 goto out;
586 }
587
588 if (page[count-1] == '\n')
589 page[count-1] = '\0';
590 else if (count < PAGE_SIZE)
591 page[count] = '\0';
592 else if (page[count]) {
593 retval = -EINVAL;
594 goto out;
595 }
596
597 buffer = page;
598
599 if (mutex_lock_interruptible(&cam->param_lock))
600 return -ERESTARTSYS;
601
602 /*
603 * Skip over leading whitespace
604 */
605 while (count && isspace(*buffer)) {
606 --count;
607 ++buffer;
608 }
609
610 memcpy(&new_params, &cam->params, sizeof(struct cam_params));
611 new_mains = cam->mainsFreq;
612
613#define MATCH(x) (match(x, &buffer, &count, &find_colon, &retval))
614#define VALUE (value(&buffer,&count, &retval))
615#define FIRMWARE_VERSION(x,y) (new_params.version.firmwareVersion == (x) && \
616 new_params.version.firmwareRevision == (y))
617
618 retval = 0;
619 while (count && !retval) {
620 find_colon = 1;
621 if (MATCH("brightness")) {
622 if (!retval)
623 val = VALUE;
624
625 if (!retval) {
626 if (val <= 100)
627 new_params.colourParams.brightness = val;
628 else
629 retval = -EINVAL;
630 }
631 command_flags |= COMMAND_SETCOLOURPARAMS;
632 if(new_params.flickerControl.allowableOverExposure < 0)
633 new_params.flickerControl.allowableOverExposure =
634 -find_over_exposure(new_params.colourParams.brightness);
635 if(new_params.flickerControl.flickerMode != 0)
636 command_flags |= COMMAND_SETFLICKERCTRL;
637
638 } else if (MATCH("contrast")) {
639 if (!retval)
640 val = VALUE;
641
642 if (!retval) {
643 if (val <= 100) {
644 /* contrast is in steps of 8, so round*/
645 val = ((val + 3) / 8) * 8;
646 /* 1-02 firmware limits contrast to 80*/
647 if (FIRMWARE_VERSION(1,2) && val > 80)
648 val = 80;
649
650 new_params.colourParams.contrast = val;
651 } else
652 retval = -EINVAL;
653 }
654 command_flags |= COMMAND_SETCOLOURPARAMS;
655 } else if (MATCH("saturation")) {
656 if (!retval)
657 val = VALUE;
658
659 if (!retval) {
660 if (val <= 100)
661 new_params.colourParams.saturation = val;
662 else
663 retval = -EINVAL;
664 }
665 command_flags |= COMMAND_SETCOLOURPARAMS;
666 } else if (MATCH("sensor_fps")) {
667 if (!retval)
668 val = VALUE;
669
670 if (!retval) {
671 /* find values so that sensorFPS is minimized,
672 * but >= val */
673 if (val > 30)
674 retval = -EINVAL;
675 else if (val > 25) {
676 new_params.sensorFps.divisor = 0;
677 new_params.sensorFps.baserate = 1;
678 } else if (val > 15) {
679 new_params.sensorFps.divisor = 0;
680 new_params.sensorFps.baserate = 0;
681 } else if (val > 12) {
682 new_params.sensorFps.divisor = 1;
683 new_params.sensorFps.baserate = 1;
684 } else if (val > 7) {
685 new_params.sensorFps.divisor = 1;
686 new_params.sensorFps.baserate = 0;
687 } else if (val > 6) {
688 new_params.sensorFps.divisor = 2;
689 new_params.sensorFps.baserate = 1;
690 } else if (val > 3) {
691 new_params.sensorFps.divisor = 2;
692 new_params.sensorFps.baserate = 0;
693 } else {
694 new_params.sensorFps.divisor = 3;
695 /* Either base rate would work here */
696 new_params.sensorFps.baserate = 1;
697 }
698 new_params.flickerControl.coarseJump =
699 flicker_jumps[new_mains]
700 [new_params.sensorFps.baserate]
701 [new_params.sensorFps.divisor];
702 if (new_params.flickerControl.flickerMode)
703 command_flags |= COMMAND_SETFLICKERCTRL;
704 }
705 command_flags |= COMMAND_SETSENSORFPS;
706 cam->exposure_status = EXPOSURE_NORMAL;
707 } else if (MATCH("stream_start_line")) {
708 if (!retval)
709 val = VALUE;
710
711 if (!retval) {
712 int max_line = 288;
713
714 if (new_params.format.videoSize == VIDEOSIZE_QCIF)
715 max_line = 144;
716 if (val <= max_line)
717 new_params.streamStartLine = val/2;
718 else
719 retval = -EINVAL;
720 }
721 } else if (MATCH("sub_sample")) {
722 if (!retval && MATCH("420"))
723 new_params.format.subSample = SUBSAMPLE_420;
724 else if (!retval && MATCH("422"))
725 new_params.format.subSample = SUBSAMPLE_422;
726 else
727 retval = -EINVAL;
728
729 command_flags |= COMMAND_SETFORMAT;
730 } else if (MATCH("yuv_order")) {
731 if (!retval && MATCH("YUYV"))
732 new_params.format.yuvOrder = YUVORDER_YUYV;
733 else if (!retval && MATCH("UYVY"))
734 new_params.format.yuvOrder = YUVORDER_UYVY;
735 else
736 retval = -EINVAL;
737
738 command_flags |= COMMAND_SETFORMAT;
739 } else if (MATCH("ecp_timing")) {
740 if (!retval && MATCH("normal"))
741 new_params.ecpTiming = 0;
742 else if (!retval && MATCH("slow"))
743 new_params.ecpTiming = 1;
744 else
745 retval = -EINVAL;
746
747 command_flags |= COMMAND_SETECPTIMING;
748 } else if (MATCH("color_balance_mode")) {
749 if (!retval && MATCH("manual"))
750 new_params.colourBalance.balanceMode = 3;
751 else if (!retval && MATCH("auto"))
752 new_params.colourBalance.balanceMode = 2;
753 else
754 retval = -EINVAL;
755
756 command_flags |= COMMAND_SETCOLOURBALANCE;
757 } else if (MATCH("red_gain")) {
758 if (!retval)
759 val = VALUE;
760
761 if (!retval) {
762 if (val <= 212) {
763 new_params.colourBalance.redGain = val;
764 new_params.colourBalance.balanceMode = 1;
765 } else
766 retval = -EINVAL;
767 }
768 command_flags |= COMMAND_SETCOLOURBALANCE;
769 } else if (MATCH("green_gain")) {
770 if (!retval)
771 val = VALUE;
772
773 if (!retval) {
774 if (val <= 212) {
775 new_params.colourBalance.greenGain = val;
776 new_params.colourBalance.balanceMode = 1;
777 } else
778 retval = -EINVAL;
779 }
780 command_flags |= COMMAND_SETCOLOURBALANCE;
781 } else if (MATCH("blue_gain")) {
782 if (!retval)
783 val = VALUE;
784
785 if (!retval) {
786 if (val <= 212) {
787 new_params.colourBalance.blueGain = val;
788 new_params.colourBalance.balanceMode = 1;
789 } else
790 retval = -EINVAL;
791 }
792 command_flags |= COMMAND_SETCOLOURBALANCE;
793 } else if (MATCH("max_gain")) {
794 if (!retval)
795 val = VALUE;
796
797 if (!retval) {
798 /* 1-02 firmware limits gain to 2 */
799 if (FIRMWARE_VERSION(1,2) && val > 2)
800 val = 2;
801 switch(val) {
802 case 1:
803 new_params.exposure.gainMode = 1;
804 break;
805 case 2:
806 new_params.exposure.gainMode = 2;
807 break;
808 case 4:
809 new_params.exposure.gainMode = 3;
810 break;
811 case 8:
812 new_params.exposure.gainMode = 4;
813 break;
814 default:
815 retval = -EINVAL;
816 break;
817 }
818 }
819 command_flags |= COMMAND_SETEXPOSURE;
820 } else if (MATCH("exposure_mode")) {
821 if (!retval && MATCH("auto"))
822 new_params.exposure.expMode = 2;
823 else if (!retval && MATCH("manual")) {
824 if (new_params.exposure.expMode == 2)
825 new_params.exposure.expMode = 3;
826 if(new_params.flickerControl.flickerMode != 0)
827 command_flags |= COMMAND_SETFLICKERCTRL;
828 new_params.flickerControl.flickerMode = 0;
829 } else
830 retval = -EINVAL;
831
832 command_flags |= COMMAND_SETEXPOSURE;
833 } else if (MATCH("centre_weight")) {
834 if (!retval && MATCH("on"))
835 new_params.exposure.centreWeight = 1;
836 else if (!retval && MATCH("off"))
837 new_params.exposure.centreWeight = 2;
838 else
839 retval = -EINVAL;
840
841 command_flags |= COMMAND_SETEXPOSURE;
842 } else if (MATCH("gain")) {
843 if (!retval)
844 val = VALUE;
845
846 if (!retval) {
847 switch(val) {
848 case 1:
849 new_params.exposure.gain = 0;
850 break;
851 case 2:
852 new_params.exposure.gain = 1;
853 break;
854 case 4:
855 new_params.exposure.gain = 2;
856 break;
857 case 8:
858 new_params.exposure.gain = 3;
859 break;
860 default:
861 retval = -EINVAL;
862 break;
863 }
864 new_params.exposure.expMode = 1;
865 if(new_params.flickerControl.flickerMode != 0)
866 command_flags |= COMMAND_SETFLICKERCTRL;
867 new_params.flickerControl.flickerMode = 0;
868 command_flags |= COMMAND_SETEXPOSURE;
869 if (new_params.exposure.gain >
870 new_params.exposure.gainMode-1)
871 retval = -EINVAL;
872 }
873 } else if (MATCH("fine_exp")) {
874 if (!retval)
875 val = VALUE/2;
876
877 if (!retval) {
878 if (val < 256) {
879 /* 1-02 firmware limits fineExp/2 to 127*/
880 if (FIRMWARE_VERSION(1,2) && val > 127)
881 val = 127;
882 new_params.exposure.fineExp = val;
883 new_params.exposure.expMode = 1;
884 command_flags |= COMMAND_SETEXPOSURE;
885 if(new_params.flickerControl.flickerMode != 0)
886 command_flags |= COMMAND_SETFLICKERCTRL;
887 new_params.flickerControl.flickerMode = 0;
888 command_flags |= COMMAND_SETFLICKERCTRL;
889 } else
890 retval = -EINVAL;
891 }
892 } else if (MATCH("coarse_exp")) {
893 if (!retval)
894 val = VALUE;
895
896 if (!retval) {
897 if (val <= MAX_EXP) {
898 if (FIRMWARE_VERSION(1,2) &&
899 val > MAX_EXP_102)
900 val = MAX_EXP_102;
901 new_params.exposure.coarseExpLo =
902 val & 0xff;
903 new_params.exposure.coarseExpHi =
904 val >> 8;
905 new_params.exposure.expMode = 1;
906 command_flags |= COMMAND_SETEXPOSURE;
907 if(new_params.flickerControl.flickerMode != 0)
908 command_flags |= COMMAND_SETFLICKERCTRL;
909 new_params.flickerControl.flickerMode = 0;
910 command_flags |= COMMAND_SETFLICKERCTRL;
911 } else
912 retval = -EINVAL;
913 }
914 } else if (MATCH("red_comp")) {
915 if (!retval)
916 val = VALUE;
917
918 if (!retval) {
919 if (val >= COMP_RED && val <= 255) {
920 new_params.exposure.redComp = val;
921 new_params.exposure.compMode = 1;
922 command_flags |= COMMAND_SETEXPOSURE;
923 } else
924 retval = -EINVAL;
925 }
926 } else if (MATCH("green1_comp")) {
927 if (!retval)
928 val = VALUE;
929
930 if (!retval) {
931 if (val >= COMP_GREEN1 && val <= 255) {
932 new_params.exposure.green1Comp = val;
933 new_params.exposure.compMode = 1;
934 command_flags |= COMMAND_SETEXPOSURE;
935 } else
936 retval = -EINVAL;
937 }
938 } else if (MATCH("green2_comp")) {
939 if (!retval)
940 val = VALUE;
941
942 if (!retval) {
943 if (val >= COMP_GREEN2 && val <= 255) {
944 new_params.exposure.green2Comp = val;
945 new_params.exposure.compMode = 1;
946 command_flags |= COMMAND_SETEXPOSURE;
947 } else
948 retval = -EINVAL;
949 }
950 } else if (MATCH("blue_comp")) {
951 if (!retval)
952 val = VALUE;
953
954 if (!retval) {
955 if (val >= COMP_BLUE && val <= 255) {
956 new_params.exposure.blueComp = val;
957 new_params.exposure.compMode = 1;
958 command_flags |= COMMAND_SETEXPOSURE;
959 } else
960 retval = -EINVAL;
961 }
962 } else if (MATCH("apcor_gain1")) {
963 if (!retval)
964 val = VALUE;
965
966 if (!retval) {
967 command_flags |= COMMAND_SETAPCOR;
968 if (val <= 0xff)
969 new_params.apcor.gain1 = val;
970 else
971 retval = -EINVAL;
972 }
973 } else if (MATCH("apcor_gain2")) {
974 if (!retval)
975 val = VALUE;
976
977 if (!retval) {
978 command_flags |= COMMAND_SETAPCOR;
979 if (val <= 0xff)
980 new_params.apcor.gain2 = val;
981 else
982 retval = -EINVAL;
983 }
984 } else if (MATCH("apcor_gain4")) {
985 if (!retval)
986 val = VALUE;
987
988 if (!retval) {
989 command_flags |= COMMAND_SETAPCOR;
990 if (val <= 0xff)
991 new_params.apcor.gain4 = val;
992 else
993 retval = -EINVAL;
994 }
995 } else if (MATCH("apcor_gain8")) {
996 if (!retval)
997 val = VALUE;
998
999 if (!retval) {
1000 command_flags |= COMMAND_SETAPCOR;
1001 if (val <= 0xff)
1002 new_params.apcor.gain8 = val;
1003 else
1004 retval = -EINVAL;
1005 }
1006 } else if (MATCH("vl_offset_gain1")) {
1007 if (!retval)
1008 val = VALUE;
1009
1010 if (!retval) {
1011 if (val <= 0xff)
1012 new_params.vlOffset.gain1 = val;
1013 else
1014 retval = -EINVAL;
1015 }
1016 command_flags |= COMMAND_SETVLOFFSET;
1017 } else if (MATCH("vl_offset_gain2")) {
1018 if (!retval)
1019 val = VALUE;
1020
1021 if (!retval) {
1022 if (val <= 0xff)
1023 new_params.vlOffset.gain2 = val;
1024 else
1025 retval = -EINVAL;
1026 }
1027 command_flags |= COMMAND_SETVLOFFSET;
1028 } else if (MATCH("vl_offset_gain4")) {
1029 if (!retval)
1030 val = VALUE;
1031
1032 if (!retval) {
1033 if (val <= 0xff)
1034 new_params.vlOffset.gain4 = val;
1035 else
1036 retval = -EINVAL;
1037 }
1038 command_flags |= COMMAND_SETVLOFFSET;
1039 } else if (MATCH("vl_offset_gain8")) {
1040 if (!retval)
1041 val = VALUE;
1042
1043 if (!retval) {
1044 if (val <= 0xff)
1045 new_params.vlOffset.gain8 = val;
1046 else
1047 retval = -EINVAL;
1048 }
1049 command_flags |= COMMAND_SETVLOFFSET;
1050 } else if (MATCH("flicker_control")) {
1051 if (!retval && MATCH("on")) {
1052 set_flicker(&new_params, &command_flags, 1);
1053 } else if (!retval && MATCH("off")) {
1054 set_flicker(&new_params, &command_flags, 0);
1055 } else
1056 retval = -EINVAL;
1057
1058 command_flags |= COMMAND_SETFLICKERCTRL;
1059 } else if (MATCH("mains_frequency")) {
1060 if (!retval && MATCH("50")) {
1061 new_mains = 0;
1062 new_params.flickerControl.coarseJump =
1063 flicker_jumps[new_mains]
1064 [new_params.sensorFps.baserate]
1065 [new_params.sensorFps.divisor];
1066 if (new_params.flickerControl.flickerMode)
1067 command_flags |= COMMAND_SETFLICKERCTRL;
1068 } else if (!retval && MATCH("60")) {
1069 new_mains = 1;
1070 new_params.flickerControl.coarseJump =
1071 flicker_jumps[new_mains]
1072 [new_params.sensorFps.baserate]
1073 [new_params.sensorFps.divisor];
1074 if (new_params.flickerControl.flickerMode)
1075 command_flags |= COMMAND_SETFLICKERCTRL;
1076 } else
1077 retval = -EINVAL;
1078 } else if (MATCH("allowable_overexposure")) {
1079 if (!retval && MATCH("auto")) {
1080 new_params.flickerControl.allowableOverExposure =
1081 -find_over_exposure(new_params.colourParams.brightness);
1082 if(new_params.flickerControl.flickerMode != 0)
1083 command_flags |= COMMAND_SETFLICKERCTRL;
1084 } else {
1085 if (!retval)
1086 val = VALUE;
1087
1088 if (!retval) {
1089 if (val <= 0xff) {
1090 new_params.flickerControl.
1091 allowableOverExposure = val;
1092 if(new_params.flickerControl.flickerMode != 0)
1093 command_flags |= COMMAND_SETFLICKERCTRL;
1094 } else
1095 retval = -EINVAL;
1096 }
1097 }
1098 } else if (MATCH("compression_mode")) {
1099 if (!retval && MATCH("none"))
1100 new_params.compression.mode =
1101 CPIA_COMPRESSION_NONE;
1102 else if (!retval && MATCH("auto"))
1103 new_params.compression.mode =
1104 CPIA_COMPRESSION_AUTO;
1105 else if (!retval && MATCH("manual"))
1106 new_params.compression.mode =
1107 CPIA_COMPRESSION_MANUAL;
1108 else
1109 retval = -EINVAL;
1110
1111 command_flags |= COMMAND_SETCOMPRESSION;
1112 } else if (MATCH("decimation_enable")) {
1113 if (!retval && MATCH("off"))
1114 new_params.compression.decimation = 0;
1115 else if (!retval && MATCH("on"))
1116 new_params.compression.decimation = 1;
1117 else
1118 retval = -EINVAL;
1119
1120 command_flags |= COMMAND_SETCOMPRESSION;
1121 } else if (MATCH("compression_target")) {
1122 if (!retval && MATCH("quality"))
1123 new_params.compressionTarget.frTargeting =
1124 CPIA_COMPRESSION_TARGET_QUALITY;
1125 else if (!retval && MATCH("framerate"))
1126 new_params.compressionTarget.frTargeting =
1127 CPIA_COMPRESSION_TARGET_FRAMERATE;
1128 else
1129 retval = -EINVAL;
1130
1131 command_flags |= COMMAND_SETCOMPRESSIONTARGET;
1132 } else if (MATCH("target_framerate")) {
1133 if (!retval)
1134 val = VALUE;
1135
1136 if (!retval) {
1137 if(val > 0 && val <= 30)
1138 new_params.compressionTarget.targetFR = val;
1139 else
1140 retval = -EINVAL;
1141 }
1142 command_flags |= COMMAND_SETCOMPRESSIONTARGET;
1143 } else if (MATCH("target_quality")) {
1144 if (!retval)
1145 val = VALUE;
1146
1147 if (!retval) {
1148 if(val > 0 && val <= 64)
1149 new_params.compressionTarget.targetQ = val;
1150 else
1151 retval = -EINVAL;
1152 }
1153 command_flags |= COMMAND_SETCOMPRESSIONTARGET;
1154 } else if (MATCH("y_threshold")) {
1155 if (!retval)
1156 val = VALUE;
1157
1158 if (!retval) {
1159 if (val < 32)
1160 new_params.yuvThreshold.yThreshold = val;
1161 else
1162 retval = -EINVAL;
1163 }
1164 command_flags |= COMMAND_SETYUVTHRESH;
1165 } else if (MATCH("uv_threshold")) {
1166 if (!retval)
1167 val = VALUE;
1168
1169 if (!retval) {
1170 if (val < 32)
1171 new_params.yuvThreshold.uvThreshold = val;
1172 else
1173 retval = -EINVAL;
1174 }
1175 command_flags |= COMMAND_SETYUVTHRESH;
1176 } else if (MATCH("hysteresis")) {
1177 if (!retval)
1178 val = VALUE;
1179
1180 if (!retval) {
1181 if (val <= 0xff)
1182 new_params.compressionParams.hysteresis = val;
1183 else
1184 retval = -EINVAL;
1185 }
1186 command_flags |= COMMAND_SETCOMPRESSIONPARAMS;
1187 } else if (MATCH("threshold_max")) {
1188 if (!retval)
1189 val = VALUE;
1190
1191 if (!retval) {
1192 if (val <= 0xff)
1193 new_params.compressionParams.threshMax = val;
1194 else
1195 retval = -EINVAL;
1196 }
1197 command_flags |= COMMAND_SETCOMPRESSIONPARAMS;
1198 } else if (MATCH("small_step")) {
1199 if (!retval)
1200 val = VALUE;
1201
1202 if (!retval) {
1203 if (val <= 0xff)
1204 new_params.compressionParams.smallStep = val;
1205 else
1206 retval = -EINVAL;
1207 }
1208 command_flags |= COMMAND_SETCOMPRESSIONPARAMS;
1209 } else if (MATCH("large_step")) {
1210 if (!retval)
1211 val = VALUE;
1212
1213 if (!retval) {
1214 if (val <= 0xff)
1215 new_params.compressionParams.largeStep = val;
1216 else
1217 retval = -EINVAL;
1218 }
1219 command_flags |= COMMAND_SETCOMPRESSIONPARAMS;
1220 } else if (MATCH("decimation_hysteresis")) {
1221 if (!retval)
1222 val = VALUE;
1223
1224 if (!retval) {
1225 if (val <= 0xff)
1226 new_params.compressionParams.decimationHysteresis = val;
1227 else
1228 retval = -EINVAL;
1229 }
1230 command_flags |= COMMAND_SETCOMPRESSIONPARAMS;
1231 } else if (MATCH("fr_diff_step_thresh")) {
1232 if (!retval)
1233 val = VALUE;
1234
1235 if (!retval) {
1236 if (val <= 0xff)
1237 new_params.compressionParams.frDiffStepThresh = val;
1238 else
1239 retval = -EINVAL;
1240 }
1241 command_flags |= COMMAND_SETCOMPRESSIONPARAMS;
1242 } else if (MATCH("q_diff_step_thresh")) {
1243 if (!retval)
1244 val = VALUE;
1245
1246 if (!retval) {
1247 if (val <= 0xff)
1248 new_params.compressionParams.qDiffStepThresh = val;
1249 else
1250 retval = -EINVAL;
1251 }
1252 command_flags |= COMMAND_SETCOMPRESSIONPARAMS;
1253 } else if (MATCH("decimation_thresh_mod")) {
1254 if (!retval)
1255 val = VALUE;
1256
1257 if (!retval) {
1258 if (val <= 0xff)
1259 new_params.compressionParams.decimationThreshMod = val;
1260 else
1261 retval = -EINVAL;
1262 }
1263 command_flags |= COMMAND_SETCOMPRESSIONPARAMS;
1264 } else if (MATCH("toplight")) {
1265 if (!retval && MATCH("on"))
1266 new_params.qx3.toplight = 1;
1267 else if (!retval && MATCH("off"))
1268 new_params.qx3.toplight = 0;
1269 else
1270 retval = -EINVAL;
1271 command_flags |= COMMAND_SETLIGHTS;
1272 } else if (MATCH("bottomlight")) {
1273 if (!retval && MATCH("on"))
1274 new_params.qx3.bottomlight = 1;
1275 else if (!retval && MATCH("off"))
1276 new_params.qx3.bottomlight = 0;
1277 else
1278 retval = -EINVAL;
1279 command_flags |= COMMAND_SETLIGHTS;
1280 } else {
1281 DBG("No match found\n");
1282 retval = -EINVAL;
1283 }
1284
1285 if (!retval) {
1286 while (count && isspace(*buffer) && *buffer != '\n') {
1287 --count;
1288 ++buffer;
1289 }
1290 if (count) {
1291 if (*buffer == '\0' && count != 1)
1292 retval = -EINVAL;
1293 else if (*buffer != '\n' && *buffer != ';' &&
1294 *buffer != '\0')
1295 retval = -EINVAL;
1296 else {
1297 --count;
1298 ++buffer;
1299 }
1300 }
1301 }
1302 }
1303#undef MATCH
1304#undef VALUE
1305#undef FIRMWARE_VERSION
1306 if (!retval) {
1307 if (command_flags & COMMAND_SETCOLOURPARAMS) {
1308 /* Adjust cam->vp to reflect these changes */
1309 cam->vp.brightness =
1310 new_params.colourParams.brightness*65535/100;
1311 cam->vp.contrast =
1312 new_params.colourParams.contrast*65535/100;
1313 cam->vp.colour =
1314 new_params.colourParams.saturation*65535/100;
1315 }
1316 if((command_flags & COMMAND_SETEXPOSURE) &&
1317 new_params.exposure.expMode == 2)
1318 cam->exposure_status = EXPOSURE_NORMAL;
1319
1320 memcpy(&cam->params, &new_params, sizeof(struct cam_params));
1321 cam->mainsFreq = new_mains;
1322 cam->cmd_queue |= command_flags;
1323 retval = size;
1324 } else
1325 DBG("error: %d\n", retval);
1326
1327 mutex_unlock(&cam->param_lock);
1328
1329out:
1330 free_page((unsigned long)page);
1331 return retval;
1332}
1333
1334static const struct file_operations cpia_proc_fops = {
1335 .owner = THIS_MODULE,
1336 .open = cpia_proc_open,
1337 .read = seq_read,
1338 .llseek = seq_lseek,
1339 .release = single_release,
1340 .write = cpia_proc_write,
1341};
1342
1343static void create_proc_cpia_cam(struct cam_data *cam)
1344{
1345 struct proc_dir_entry *ent;
1346
1347 if (!cpia_proc_root || !cam)
1348 return;
1349
1350 ent = proc_create_data(video_device_node_name(&cam->vdev),
1351 S_IRUGO|S_IWUSR, cpia_proc_root,
1352 &cpia_proc_fops, cam);
1353 if (!ent)
1354 return;
1355
1356 /*
1357 size of the proc entry is 3736 bytes for the standard webcam;
1358 the extra features of the QX3 microscope add 189 bytes.
1359 (we have not yet probed the camera to see which type it is).
1360 */
1361 ent->size = 3736 + 189;
1362 cam->proc_entry = ent;
1363}
1364
1365static void destroy_proc_cpia_cam(struct cam_data *cam)
1366{
1367 if (!cam || !cam->proc_entry)
1368 return;
1369
1370 remove_proc_entry(video_device_node_name(&cam->vdev), cpia_proc_root);
1371 cam->proc_entry = NULL;
1372}
1373
1374static void proc_cpia_create(void)
1375{
1376 cpia_proc_root = proc_mkdir("cpia", NULL);
1377
1378 if (!cpia_proc_root)
1379 LOG("Unable to initialise /proc/cpia\n");
1380}
1381
1382static void __exit proc_cpia_destroy(void)
1383{
1384 remove_proc_entry("cpia", NULL);
1385}
1386#endif /* CONFIG_PROC_FS */
1387
1388/* ----------------------- debug functions ---------------------- */
1389
1390#define printstatus(cam) \
1391 DBG("%02x %02x %02x %02x %02x %02x %02x %02x\n",\
1392 cam->params.status.systemState, cam->params.status.grabState, \
1393 cam->params.status.streamState, cam->params.status.fatalError, \
1394 cam->params.status.cmdError, cam->params.status.debugFlags, \
1395 cam->params.status.vpStatus, cam->params.status.errorCode);
1396
1397/* ----------------------- v4l helpers -------------------------- */
1398
1399/* supported frame palettes and depths */
1400static inline int valid_mode(u16 palette, u16 depth)
1401{
1402 if ((palette == VIDEO_PALETTE_YUV422 && depth == 16) ||
1403 (palette == VIDEO_PALETTE_YUYV && depth == 16))
1404 return 1;
1405
1406 if (colorspace_conv)
1407 return (palette == VIDEO_PALETTE_GREY && depth == 8) ||
1408 (palette == VIDEO_PALETTE_RGB555 && depth == 16) ||
1409 (palette == VIDEO_PALETTE_RGB565 && depth == 16) ||
1410 (palette == VIDEO_PALETTE_RGB24 && depth == 24) ||
1411 (palette == VIDEO_PALETTE_RGB32 && depth == 32) ||
1412 (palette == VIDEO_PALETTE_UYVY && depth == 16);
1413
1414 return 0;
1415}
1416
1417static int match_videosize( int width, int height )
1418{
1419 /* return the best match, where 'best' is as always
1420 * the largest that is not bigger than what is requested. */
1421 if (width>=352 && height>=288)
1422 return VIDEOSIZE_352_288; /* CIF */
1423
1424 if (width>=320 && height>=240)
1425 return VIDEOSIZE_320_240; /* SIF */
1426
1427 if (width>=288 && height>=216)
1428 return VIDEOSIZE_288_216;
1429
1430 if (width>=256 && height>=192)
1431 return VIDEOSIZE_256_192;
1432
1433 if (width>=224 && height>=168)
1434 return VIDEOSIZE_224_168;
1435
1436 if (width>=192 && height>=144)
1437 return VIDEOSIZE_192_144;
1438
1439 if (width>=176 && height>=144)
1440 return VIDEOSIZE_176_144; /* QCIF */
1441
1442 if (width>=160 && height>=120)
1443 return VIDEOSIZE_160_120; /* QSIF */
1444
1445 if (width>=128 && height>=96)
1446 return VIDEOSIZE_128_96;
1447
1448 if (width>=88 && height>=72)
1449 return VIDEOSIZE_88_72;
1450
1451 if (width>=64 && height>=48)
1452 return VIDEOSIZE_64_48;
1453
1454 if (width>=48 && height>=48)
1455 return VIDEOSIZE_48_48;
1456
1457 return -1;
1458}
1459
1460/* these are the capture sizes we support */
1461static void set_vw_size(struct cam_data *cam)
1462{
1463 /* the col/row/start/end values are the result of simple math */
1464 /* study the SetROI-command in cpia developers guide p 2-22 */
1465 /* streamStartLine is set to the recommended value in the cpia */
1466 /* developers guide p 3-37 */
1467 switch(cam->video_size) {
1468 case VIDEOSIZE_CIF:
1469 cam->vw.width = 352;
1470 cam->vw.height = 288;
1471 cam->params.format.videoSize=VIDEOSIZE_CIF;
1472 cam->params.roi.colStart=0;
1473 cam->params.roi.rowStart=0;
1474 cam->params.streamStartLine = 120;
1475 break;
1476 case VIDEOSIZE_SIF:
1477 cam->vw.width = 320;
1478 cam->vw.height = 240;
1479 cam->params.format.videoSize=VIDEOSIZE_CIF;
1480 cam->params.roi.colStart=2;
1481 cam->params.roi.rowStart=6;
1482 cam->params.streamStartLine = 120;
1483 break;
1484 case VIDEOSIZE_288_216:
1485 cam->vw.width = 288;
1486 cam->vw.height = 216;
1487 cam->params.format.videoSize=VIDEOSIZE_CIF;
1488 cam->params.roi.colStart=4;
1489 cam->params.roi.rowStart=9;
1490 cam->params.streamStartLine = 120;
1491 break;
1492 case VIDEOSIZE_256_192:
1493 cam->vw.width = 256;
1494 cam->vw.height = 192;
1495 cam->params.format.videoSize=VIDEOSIZE_CIF;
1496 cam->params.roi.colStart=6;
1497 cam->params.roi.rowStart=12;
1498 cam->params.streamStartLine = 120;
1499 break;
1500 case VIDEOSIZE_224_168:
1501 cam->vw.width = 224;
1502 cam->vw.height = 168;
1503 cam->params.format.videoSize=VIDEOSIZE_CIF;
1504 cam->params.roi.colStart=8;
1505 cam->params.roi.rowStart=15;
1506 cam->params.streamStartLine = 120;
1507 break;
1508 case VIDEOSIZE_192_144:
1509 cam->vw.width = 192;
1510 cam->vw.height = 144;
1511 cam->params.format.videoSize=VIDEOSIZE_CIF;
1512 cam->params.roi.colStart=10;
1513 cam->params.roi.rowStart=18;
1514 cam->params.streamStartLine = 120;
1515 break;
1516 case VIDEOSIZE_QCIF:
1517 cam->vw.width = 176;
1518 cam->vw.height = 144;
1519 cam->params.format.videoSize=VIDEOSIZE_QCIF;
1520 cam->params.roi.colStart=0;
1521 cam->params.roi.rowStart=0;
1522 cam->params.streamStartLine = 60;
1523 break;
1524 case VIDEOSIZE_QSIF:
1525 cam->vw.width = 160;
1526 cam->vw.height = 120;
1527 cam->params.format.videoSize=VIDEOSIZE_QCIF;
1528 cam->params.roi.colStart=1;
1529 cam->params.roi.rowStart=3;
1530 cam->params.streamStartLine = 60;
1531 break;
1532 case VIDEOSIZE_128_96:
1533 cam->vw.width = 128;
1534 cam->vw.height = 96;
1535 cam->params.format.videoSize=VIDEOSIZE_QCIF;
1536 cam->params.roi.colStart=3;
1537 cam->params.roi.rowStart=6;
1538 cam->params.streamStartLine = 60;
1539 break;
1540 case VIDEOSIZE_88_72:
1541 cam->vw.width = 88;
1542 cam->vw.height = 72;
1543 cam->params.format.videoSize=VIDEOSIZE_QCIF;
1544 cam->params.roi.colStart=5;
1545 cam->params.roi.rowStart=9;
1546 cam->params.streamStartLine = 60;
1547 break;
1548 case VIDEOSIZE_64_48:
1549 cam->vw.width = 64;
1550 cam->vw.height = 48;
1551 cam->params.format.videoSize=VIDEOSIZE_QCIF;
1552 cam->params.roi.colStart=7;
1553 cam->params.roi.rowStart=12;
1554 cam->params.streamStartLine = 60;
1555 break;
1556 case VIDEOSIZE_48_48:
1557 cam->vw.width = 48;
1558 cam->vw.height = 48;
1559 cam->params.format.videoSize=VIDEOSIZE_QCIF;
1560 cam->params.roi.colStart=8;
1561 cam->params.roi.rowStart=6;
1562 cam->params.streamStartLine = 60;
1563 break;
1564 default:
1565 LOG("bad videosize value: %d\n", cam->video_size);
1566 return;
1567 }
1568
1569 if(cam->vc.width == 0)
1570 cam->vc.width = cam->vw.width;
1571 if(cam->vc.height == 0)
1572 cam->vc.height = cam->vw.height;
1573
1574 cam->params.roi.colStart += cam->vc.x >> 3;
1575 cam->params.roi.colEnd = cam->params.roi.colStart +
1576 (cam->vc.width >> 3);
1577 cam->params.roi.rowStart += cam->vc.y >> 2;
1578 cam->params.roi.rowEnd = cam->params.roi.rowStart +
1579 (cam->vc.height >> 2);
1580
1581 return;
1582}
1583
1584static int allocate_frame_buf(struct cam_data *cam)
1585{
1586 int i;
1587
1588 cam->frame_buf = rvmalloc(FRAME_NUM * CPIA_MAX_FRAME_SIZE);
1589 if (!cam->frame_buf)
1590 return -ENOBUFS;
1591
1592 for (i = 0; i < FRAME_NUM; i++)
1593 cam->frame[i].data = cam->frame_buf + i * CPIA_MAX_FRAME_SIZE;
1594
1595 return 0;
1596}
1597
1598static int free_frame_buf(struct cam_data *cam)
1599{
1600 int i;
1601
1602 rvfree(cam->frame_buf, FRAME_NUM*CPIA_MAX_FRAME_SIZE);
1603 cam->frame_buf = NULL;
1604 for (i=0; i < FRAME_NUM; i++)
1605 cam->frame[i].data = NULL;
1606
1607 return 0;
1608}
1609
1610
1611static inline void free_frames(struct cpia_frame frame[FRAME_NUM])
1612{
1613 int i;
1614
1615 for (i=0; i < FRAME_NUM; i++)
1616 frame[i].state = FRAME_UNUSED;
1617 return;
1618}
1619
1620/**********************************************************************
1621 *
1622 * General functions
1623 *
1624 **********************************************************************/
1625/* send an arbitrary command to the camera */
1626static int do_command(struct cam_data *cam, u16 command, u8 a, u8 b, u8 c, u8 d)
1627{
1628 int retval, datasize;
1629 u8 cmd[8], data[8];
1630
1631 switch(command) {
1632 case CPIA_COMMAND_GetCPIAVersion:
1633 case CPIA_COMMAND_GetPnPID:
1634 case CPIA_COMMAND_GetCameraStatus:
1635 case CPIA_COMMAND_GetVPVersion:
1636 datasize=8;
1637 break;
1638 case CPIA_COMMAND_GetColourParams:
1639 case CPIA_COMMAND_GetColourBalance:
1640 case CPIA_COMMAND_GetExposure:
1641 mutex_lock(&cam->param_lock);
1642 datasize=8;
1643 break;
1644 case CPIA_COMMAND_ReadMCPorts:
1645 case CPIA_COMMAND_ReadVCRegs:
1646 datasize = 4;
1647 break;
1648 default:
1649 datasize=0;
1650 break;
1651 }
1652
1653 cmd[0] = command>>8;
1654 cmd[1] = command&0xff;
1655 cmd[2] = a;
1656 cmd[3] = b;
1657 cmd[4] = c;
1658 cmd[5] = d;
1659 cmd[6] = datasize;
1660 cmd[7] = 0;
1661
1662 retval = cam->ops->transferCmd(cam->lowlevel_data, cmd, data);
1663 if (retval) {
1664 DBG("%x - failed, retval=%d\n", command, retval);
1665 if (command == CPIA_COMMAND_GetColourParams ||
1666 command == CPIA_COMMAND_GetColourBalance ||
1667 command == CPIA_COMMAND_GetExposure)
1668 mutex_unlock(&cam->param_lock);
1669 } else {
1670 switch(command) {
1671 case CPIA_COMMAND_GetCPIAVersion:
1672 cam->params.version.firmwareVersion = data[0];
1673 cam->params.version.firmwareRevision = data[1];
1674 cam->params.version.vcVersion = data[2];
1675 cam->params.version.vcRevision = data[3];
1676 break;
1677 case CPIA_COMMAND_GetPnPID:
1678 cam->params.pnpID.vendor = data[0]+(((u16)data[1])<<8);
1679 cam->params.pnpID.product = data[2]+(((u16)data[3])<<8);
1680 cam->params.pnpID.deviceRevision =
1681 data[4]+(((u16)data[5])<<8);
1682 break;
1683 case CPIA_COMMAND_GetCameraStatus:
1684 cam->params.status.systemState = data[0];
1685 cam->params.status.grabState = data[1];
1686 cam->params.status.streamState = data[2];
1687 cam->params.status.fatalError = data[3];
1688 cam->params.status.cmdError = data[4];
1689 cam->params.status.debugFlags = data[5];
1690 cam->params.status.vpStatus = data[6];
1691 cam->params.status.errorCode = data[7];
1692 break;
1693 case CPIA_COMMAND_GetVPVersion:
1694 cam->params.vpVersion.vpVersion = data[0];
1695 cam->params.vpVersion.vpRevision = data[1];
1696 cam->params.vpVersion.cameraHeadID =
1697 data[2]+(((u16)data[3])<<8);
1698 break;
1699 case CPIA_COMMAND_GetColourParams:
1700 cam->params.colourParams.brightness = data[0];
1701 cam->params.colourParams.contrast = data[1];
1702 cam->params.colourParams.saturation = data[2];
1703 mutex_unlock(&cam->param_lock);
1704 break;
1705 case CPIA_COMMAND_GetColourBalance:
1706 cam->params.colourBalance.redGain = data[0];
1707 cam->params.colourBalance.greenGain = data[1];
1708 cam->params.colourBalance.blueGain = data[2];
1709 mutex_unlock(&cam->param_lock);
1710 break;
1711 case CPIA_COMMAND_GetExposure:
1712 cam->params.exposure.gain = data[0];
1713 cam->params.exposure.fineExp = data[1];
1714 cam->params.exposure.coarseExpLo = data[2];
1715 cam->params.exposure.coarseExpHi = data[3];
1716 cam->params.exposure.redComp = data[4];
1717 cam->params.exposure.green1Comp = data[5];
1718 cam->params.exposure.green2Comp = data[6];
1719 cam->params.exposure.blueComp = data[7];
1720 mutex_unlock(&cam->param_lock);
1721 break;
1722
1723 case CPIA_COMMAND_ReadMCPorts:
1724 if (!cam->params.qx3.qx3_detected)
1725 break;
1726 /* test button press */
1727 cam->params.qx3.button = ((data[1] & 0x02) == 0);
1728 if (cam->params.qx3.button) {
1729 /* button pressed - unlock the latch */
1730 do_command(cam,CPIA_COMMAND_WriteMCPort,3,0xDF,0xDF,0);
1731 do_command(cam,CPIA_COMMAND_WriteMCPort,3,0xFF,0xFF,0);
1732 }
1733
1734 /* test whether microscope is cradled */
1735 cam->params.qx3.cradled = ((data[2] & 0x40) == 0);
1736 break;
1737
1738 default:
1739 break;
1740 }
1741 }
1742 return retval;
1743}
1744
1745/* send a command to the camera with an additional data transaction */
1746static int do_command_extended(struct cam_data *cam, u16 command,
1747 u8 a, u8 b, u8 c, u8 d,
1748 u8 e, u8 f, u8 g, u8 h,
1749 u8 i, u8 j, u8 k, u8 l)
1750{
1751 int retval;
1752 u8 cmd[8], data[8];
1753
1754 cmd[0] = command>>8;
1755 cmd[1] = command&0xff;
1756 cmd[2] = a;
1757 cmd[3] = b;
1758 cmd[4] = c;
1759 cmd[5] = d;
1760 cmd[6] = 8;
1761 cmd[7] = 0;
1762 data[0] = e;
1763 data[1] = f;
1764 data[2] = g;
1765 data[3] = h;
1766 data[4] = i;
1767 data[5] = j;
1768 data[6] = k;
1769 data[7] = l;
1770
1771 retval = cam->ops->transferCmd(cam->lowlevel_data, cmd, data);
1772 if (retval)
1773 DBG("%x - failed\n", command);
1774
1775 return retval;
1776}
1777
1778/**********************************************************************
1779 *
1780 * Colorspace conversion
1781 *
1782 **********************************************************************/
1783#define LIMIT(x) ((((x)>0xffffff)?0xff0000:(((x)<=0xffff)?0:(x)&0xff0000))>>16)
1784
1785static int convert420(unsigned char *yuv, unsigned char *rgb, int out_fmt,
1786 int linesize, int mmap_kludge)
1787{
1788 int y, u, v, r, g, b, y1;
1789
1790 /* Odd lines use the same u and v as the previous line.
1791 * Because of compression, it is necessary to get this
1792 * information from the decoded image. */
1793 switch(out_fmt) {
1794 case VIDEO_PALETTE_RGB555:
1795 y = (*yuv++ - 16) * 76310;
1796 y1 = (*yuv - 16) * 76310;
1797 r = ((*(rgb+1-linesize)) & 0x7c) << 1;
1798 g = ((*(rgb-linesize)) & 0xe0) >> 4 |
1799 ((*(rgb+1-linesize)) & 0x03) << 6;
1800 b = ((*(rgb-linesize)) & 0x1f) << 3;
1801 u = (-53294 * r - 104635 * g + 157929 * b) / 5756495;
1802 v = (157968 * r - 132278 * g - 25690 * b) / 5366159;
1803 r = 104635 * v;
1804 g = -25690 * u - 53294 * v;
1805 b = 132278 * u;
1806 *rgb++ = ((LIMIT(g+y) & 0xf8) << 2) | (LIMIT(b+y) >> 3);
1807 *rgb++ = ((LIMIT(r+y) & 0xf8) >> 1) | (LIMIT(g+y) >> 6);
1808 *rgb++ = ((LIMIT(g+y1) & 0xf8) << 2) | (LIMIT(b+y1) >> 3);
1809 *rgb = ((LIMIT(r+y1) & 0xf8) >> 1) | (LIMIT(g+y1) >> 6);
1810 return 4;
1811 case VIDEO_PALETTE_RGB565:
1812 y = (*yuv++ - 16) * 76310;
1813 y1 = (*yuv - 16) * 76310;
1814 r = (*(rgb+1-linesize)) & 0xf8;
1815 g = ((*(rgb-linesize)) & 0xe0) >> 3 |
1816 ((*(rgb+1-linesize)) & 0x07) << 5;
1817 b = ((*(rgb-linesize)) & 0x1f) << 3;
1818 u = (-53294 * r - 104635 * g + 157929 * b) / 5756495;
1819 v = (157968 * r - 132278 * g - 25690 * b) / 5366159;
1820 r = 104635 * v;
1821 g = -25690 * u - 53294 * v;
1822 b = 132278 * u;
1823 *rgb++ = ((LIMIT(g+y) & 0xfc) << 3) | (LIMIT(b+y) >> 3);
1824 *rgb++ = (LIMIT(r+y) & 0xf8) | (LIMIT(g+y) >> 5);
1825 *rgb++ = ((LIMIT(g+y1) & 0xfc) << 3) | (LIMIT(b+y1) >> 3);
1826 *rgb = (LIMIT(r+y1) & 0xf8) | (LIMIT(g+y1) >> 5);
1827 return 4;
1828 break;
1829 case VIDEO_PALETTE_RGB24:
1830 case VIDEO_PALETTE_RGB32:
1831 y = (*yuv++ - 16) * 76310;
1832 y1 = (*yuv - 16) * 76310;
1833 if (mmap_kludge) {
1834 r = *(rgb+2-linesize);
1835 g = *(rgb+1-linesize);
1836 b = *(rgb-linesize);
1837 } else {
1838 r = *(rgb-linesize);
1839 g = *(rgb+1-linesize);
1840 b = *(rgb+2-linesize);
1841 }
1842 u = (-53294 * r - 104635 * g + 157929 * b) / 5756495;
1843 v = (157968 * r - 132278 * g - 25690 * b) / 5366159;
1844 r = 104635 * v;
1845 g = -25690 * u + -53294 * v;
1846 b = 132278 * u;
1847 if (mmap_kludge) {
1848 *rgb++ = LIMIT(b+y);
1849 *rgb++ = LIMIT(g+y);
1850 *rgb++ = LIMIT(r+y);
1851 if(out_fmt == VIDEO_PALETTE_RGB32)
1852 rgb++;
1853 *rgb++ = LIMIT(b+y1);
1854 *rgb++ = LIMIT(g+y1);
1855 *rgb = LIMIT(r+y1);
1856 } else {
1857 *rgb++ = LIMIT(r+y);
1858 *rgb++ = LIMIT(g+y);
1859 *rgb++ = LIMIT(b+y);
1860 if(out_fmt == VIDEO_PALETTE_RGB32)
1861 rgb++;
1862 *rgb++ = LIMIT(r+y1);
1863 *rgb++ = LIMIT(g+y1);
1864 *rgb = LIMIT(b+y1);
1865 }
1866 if(out_fmt == VIDEO_PALETTE_RGB32)
1867 return 8;
1868 return 6;
1869 case VIDEO_PALETTE_YUV422:
1870 case VIDEO_PALETTE_YUYV:
1871 y = *yuv++;
1872 u = *(rgb+1-linesize);
1873 y1 = *yuv;
1874 v = *(rgb+3-linesize);
1875 *rgb++ = y;
1876 *rgb++ = u;
1877 *rgb++ = y1;
1878 *rgb = v;
1879 return 4;
1880 case VIDEO_PALETTE_UYVY:
1881 u = *(rgb-linesize);
1882 y = *yuv++;
1883 v = *(rgb+2-linesize);
1884 y1 = *yuv;
1885 *rgb++ = u;
1886 *rgb++ = y;
1887 *rgb++ = v;
1888 *rgb = y1;
1889 return 4;
1890 case VIDEO_PALETTE_GREY:
1891 *rgb++ = *yuv++;
1892 *rgb = *yuv;
1893 return 2;
1894 default:
1895 DBG("Empty: %d\n", out_fmt);
1896 return 0;
1897 }
1898}
1899
1900
1901static int yuvconvert(unsigned char *yuv, unsigned char *rgb, int out_fmt,
1902 int in_uyvy, int mmap_kludge)
1903{
1904 int y, u, v, r, g, b, y1;
1905
1906 switch(out_fmt) {
1907 case VIDEO_PALETTE_RGB555:
1908 case VIDEO_PALETTE_RGB565:
1909 case VIDEO_PALETTE_RGB24:
1910 case VIDEO_PALETTE_RGB32:
1911 if (in_uyvy) {
1912 u = *yuv++ - 128;
1913 y = (*yuv++ - 16) * 76310;
1914 v = *yuv++ - 128;
1915 y1 = (*yuv - 16) * 76310;
1916 } else {
1917 y = (*yuv++ - 16) * 76310;
1918 u = *yuv++ - 128;
1919 y1 = (*yuv++ - 16) * 76310;
1920 v = *yuv - 128;
1921 }
1922 r = 104635 * v;
1923 g = -25690 * u + -53294 * v;
1924 b = 132278 * u;
1925 break;
1926 default:
1927 y = *yuv++;
1928 u = *yuv++;
1929 y1 = *yuv++;
1930 v = *yuv;
1931 /* Just to avoid compiler warnings */
1932 r = 0;
1933 g = 0;
1934 b = 0;
1935 break;
1936 }
1937 switch(out_fmt) {
1938 case VIDEO_PALETTE_RGB555:
1939 *rgb++ = ((LIMIT(g+y) & 0xf8) << 2) | (LIMIT(b+y) >> 3);
1940 *rgb++ = ((LIMIT(r+y) & 0xf8) >> 1) | (LIMIT(g+y) >> 6);
1941 *rgb++ = ((LIMIT(g+y1) & 0xf8) << 2) | (LIMIT(b+y1) >> 3);
1942 *rgb = ((LIMIT(r+y1) & 0xf8) >> 1) | (LIMIT(g+y1) >> 6);
1943 return 4;
1944 case VIDEO_PALETTE_RGB565:
1945 *rgb++ = ((LIMIT(g+y) & 0xfc) << 3) | (LIMIT(b+y) >> 3);
1946 *rgb++ = (LIMIT(r+y) & 0xf8) | (LIMIT(g+y) >> 5);
1947 *rgb++ = ((LIMIT(g+y1) & 0xfc) << 3) | (LIMIT(b+y1) >> 3);
1948 *rgb = (LIMIT(r+y1) & 0xf8) | (LIMIT(g+y1) >> 5);
1949 return 4;
1950 case VIDEO_PALETTE_RGB24:
1951 if (mmap_kludge) {
1952 *rgb++ = LIMIT(b+y);
1953 *rgb++ = LIMIT(g+y);
1954 *rgb++ = LIMIT(r+y);
1955 *rgb++ = LIMIT(b+y1);
1956 *rgb++ = LIMIT(g+y1);
1957 *rgb = LIMIT(r+y1);
1958 } else {
1959 *rgb++ = LIMIT(r+y);
1960 *rgb++ = LIMIT(g+y);
1961 *rgb++ = LIMIT(b+y);
1962 *rgb++ = LIMIT(r+y1);
1963 *rgb++ = LIMIT(g+y1);
1964 *rgb = LIMIT(b+y1);
1965 }
1966 return 6;
1967 case VIDEO_PALETTE_RGB32:
1968 if (mmap_kludge) {
1969 *rgb++ = LIMIT(b+y);
1970 *rgb++ = LIMIT(g+y);
1971 *rgb++ = LIMIT(r+y);
1972 rgb++;
1973 *rgb++ = LIMIT(b+y1);
1974 *rgb++ = LIMIT(g+y1);
1975 *rgb = LIMIT(r+y1);
1976 } else {
1977 *rgb++ = LIMIT(r+y);
1978 *rgb++ = LIMIT(g+y);
1979 *rgb++ = LIMIT(b+y);
1980 rgb++;
1981 *rgb++ = LIMIT(r+y1);
1982 *rgb++ = LIMIT(g+y1);
1983 *rgb = LIMIT(b+y1);
1984 }
1985 return 8;
1986 case VIDEO_PALETTE_GREY:
1987 *rgb++ = y;
1988 *rgb = y1;
1989 return 2;
1990 case VIDEO_PALETTE_YUV422:
1991 case VIDEO_PALETTE_YUYV:
1992 *rgb++ = y;
1993 *rgb++ = u;
1994 *rgb++ = y1;
1995 *rgb = v;
1996 return 4;
1997 case VIDEO_PALETTE_UYVY:
1998 *rgb++ = u;
1999 *rgb++ = y;
2000 *rgb++ = v;
2001 *rgb = y1;
2002 return 4;
2003 default:
2004 DBG("Empty: %d\n", out_fmt);
2005 return 0;
2006 }
2007}
2008
2009static int skipcount(int count, int fmt)
2010{
2011 switch(fmt) {
2012 case VIDEO_PALETTE_GREY:
2013 return count;
2014 case VIDEO_PALETTE_RGB555:
2015 case VIDEO_PALETTE_RGB565:
2016 case VIDEO_PALETTE_YUV422:
2017 case VIDEO_PALETTE_YUYV:
2018 case VIDEO_PALETTE_UYVY:
2019 return 2*count;
2020 case VIDEO_PALETTE_RGB24:
2021 return 3*count;
2022 case VIDEO_PALETTE_RGB32:
2023 return 4*count;
2024 default:
2025 return 0;
2026 }
2027}
2028
2029static int parse_picture(struct cam_data *cam, int size)
2030{
2031 u8 *obuf, *ibuf, *end_obuf;
2032 int ll, in_uyvy, compressed, decimation, even_line, origsize, out_fmt;
2033 int rows, cols, linesize, subsample_422;
2034
2035 /* make sure params don't change while we are decoding */
2036 mutex_lock(&cam->param_lock);
2037
2038 obuf = cam->decompressed_frame.data;
2039 end_obuf = obuf+CPIA_MAX_FRAME_SIZE;
2040 ibuf = cam->raw_image;
2041 origsize = size;
2042 out_fmt = cam->vp.palette;
2043
2044 if ((ibuf[0] != MAGIC_0) || (ibuf[1] != MAGIC_1)) {
2045 LOG("header not found\n");
2046 mutex_unlock(&cam->param_lock);
2047 return -1;
2048 }
2049
2050 if ((ibuf[16] != VIDEOSIZE_QCIF) && (ibuf[16] != VIDEOSIZE_CIF)) {
2051 LOG("wrong video size\n");
2052 mutex_unlock(&cam->param_lock);
2053 return -1;
2054 }
2055
2056 if (ibuf[17] != SUBSAMPLE_420 && ibuf[17] != SUBSAMPLE_422) {
2057 LOG("illegal subtype %d\n",ibuf[17]);
2058 mutex_unlock(&cam->param_lock);
2059 return -1;
2060 }
2061 subsample_422 = ibuf[17] == SUBSAMPLE_422;
2062
2063 if (ibuf[18] != YUVORDER_YUYV && ibuf[18] != YUVORDER_UYVY) {
2064 LOG("illegal yuvorder %d\n",ibuf[18]);
2065 mutex_unlock(&cam->param_lock);
2066 return -1;
2067 }
2068 in_uyvy = ibuf[18] == YUVORDER_UYVY;
2069
2070 if ((ibuf[24] != cam->params.roi.colStart) ||
2071 (ibuf[25] != cam->params.roi.colEnd) ||
2072 (ibuf[26] != cam->params.roi.rowStart) ||
2073 (ibuf[27] != cam->params.roi.rowEnd)) {
2074 LOG("ROI mismatch\n");
2075 mutex_unlock(&cam->param_lock);
2076 return -1;
2077 }
2078 cols = 8*(ibuf[25] - ibuf[24]);
2079 rows = 4*(ibuf[27] - ibuf[26]);
2080
2081
2082 if ((ibuf[28] != NOT_COMPRESSED) && (ibuf[28] != COMPRESSED)) {
2083 LOG("illegal compression %d\n",ibuf[28]);
2084 mutex_unlock(&cam->param_lock);
2085 return -1;
2086 }
2087 compressed = (ibuf[28] == COMPRESSED);
2088
2089 if (ibuf[29] != NO_DECIMATION && ibuf[29] != DECIMATION_ENAB) {
2090 LOG("illegal decimation %d\n",ibuf[29]);
2091 mutex_unlock(&cam->param_lock);
2092 return -1;
2093 }
2094 decimation = (ibuf[29] == DECIMATION_ENAB);
2095
2096 cam->params.yuvThreshold.yThreshold = ibuf[30];
2097 cam->params.yuvThreshold.uvThreshold = ibuf[31];
2098 cam->params.status.systemState = ibuf[32];
2099 cam->params.status.grabState = ibuf[33];
2100 cam->params.status.streamState = ibuf[34];
2101 cam->params.status.fatalError = ibuf[35];
2102 cam->params.status.cmdError = ibuf[36];
2103 cam->params.status.debugFlags = ibuf[37];
2104 cam->params.status.vpStatus = ibuf[38];
2105 cam->params.status.errorCode = ibuf[39];
2106 cam->fps = ibuf[41];
2107 mutex_unlock(&cam->param_lock);
2108
2109 linesize = skipcount(cols, out_fmt);
2110 ibuf += FRAME_HEADER_SIZE;
2111 size -= FRAME_HEADER_SIZE;
2112 ll = ibuf[0] | (ibuf[1] << 8);
2113 ibuf += 2;
2114 even_line = 1;
2115
2116 while (size > 0) {
2117 size -= (ll+2);
2118 if (size < 0) {
2119 LOG("Insufficient data in buffer\n");
2120 return -1;
2121 }
2122
2123 while (ll > 1) {
2124 if (!compressed || (compressed && !(*ibuf & 1))) {
2125 if(subsample_422 || even_line) {
2126 obuf += yuvconvert(ibuf, obuf, out_fmt,
2127 in_uyvy, cam->mmap_kludge);
2128 ibuf += 4;
2129 ll -= 4;
2130 } else {
2131 /* SUBSAMPLE_420 on an odd line */
2132 obuf += convert420(ibuf, obuf,
2133 out_fmt, linesize,
2134 cam->mmap_kludge);
2135 ibuf += 2;
2136 ll -= 2;
2137 }
2138 } else {
2139 /*skip compressed interval from previous frame*/
2140 obuf += skipcount(*ibuf >> 1, out_fmt);
2141 if (obuf > end_obuf) {
2142 LOG("Insufficient buffer size\n");
2143 return -1;
2144 }
2145 ++ibuf;
2146 ll--;
2147 }
2148 }
2149 if (ll == 1) {
2150 if (*ibuf != EOL) {
2151 DBG("EOL not found giving up after %d/%d"
2152 " bytes\n", origsize-size, origsize);
2153 return -1;
2154 }
2155
2156 ++ibuf; /* skip over EOL */
2157
2158 if ((size > 3) && (ibuf[0] == EOI) && (ibuf[1] == EOI) &&
2159 (ibuf[2] == EOI) && (ibuf[3] == EOI)) {
2160 size -= 4;
2161 break;
2162 }
2163
2164 if(decimation) {
2165 /* skip the odd lines for now */
2166 obuf += linesize;
2167 }
2168
2169 if (size > 1) {
2170 ll = ibuf[0] | (ibuf[1] << 8);
2171 ibuf += 2; /* skip over line length */
2172 }
2173 if(!decimation)
2174 even_line = !even_line;
2175 } else {
2176 LOG("line length was not 1 but %d after %d/%d bytes\n",
2177 ll, origsize-size, origsize);
2178 return -1;
2179 }
2180 }
2181
2182 if(decimation) {
2183 /* interpolate odd rows */
2184 int i, j;
2185 u8 *prev, *next;
2186 prev = cam->decompressed_frame.data;
2187 obuf = prev+linesize;
2188 next = obuf+linesize;
2189 for(i=1; i<rows-1; i+=2) {
2190 for(j=0; j<linesize; ++j) {
2191 *obuf++ = ((int)*prev++ + *next++) / 2;
2192 }
2193 prev += linesize;
2194 obuf += linesize;
2195 next += linesize;
2196 }
2197 /* last row is odd, just copy previous row */
2198 memcpy(obuf, prev, linesize);
2199 }
2200
2201 cam->decompressed_frame.count = obuf-cam->decompressed_frame.data;
2202
2203 return cam->decompressed_frame.count;
2204}
2205
2206/* InitStreamCap wrapper to select correct start line */
2207static inline int init_stream_cap(struct cam_data *cam)
2208{
2209 return do_command(cam, CPIA_COMMAND_InitStreamCap,
2210 0, cam->params.streamStartLine, 0, 0);
2211}
2212
2213
2214/* find_over_exposure
2215 * Finds a suitable value of OverExposure for use with SetFlickerCtrl
2216 * Some calculation is required because this value changes with the brightness
2217 * set with SetColourParameters
2218 *
2219 * Parameters: Brightness - last brightness value set with SetColourParameters
2220 *
2221 * Returns: OverExposure value to use with SetFlickerCtrl
2222 */
2223#define FLICKER_MAX_EXPOSURE 250
2224#define FLICKER_ALLOWABLE_OVER_EXPOSURE 146
2225#define FLICKER_BRIGHTNESS_CONSTANT 59
2226static int find_over_exposure(int brightness)
2227{
2228 int MaxAllowableOverExposure, OverExposure;
2229
2230 MaxAllowableOverExposure = FLICKER_MAX_EXPOSURE - brightness -
2231 FLICKER_BRIGHTNESS_CONSTANT;
2232
2233 if (MaxAllowableOverExposure < FLICKER_ALLOWABLE_OVER_EXPOSURE) {
2234 OverExposure = MaxAllowableOverExposure;
2235 } else {
2236 OverExposure = FLICKER_ALLOWABLE_OVER_EXPOSURE;
2237 }
2238
2239 return OverExposure;
2240}
2241#undef FLICKER_MAX_EXPOSURE
2242#undef FLICKER_ALLOWABLE_OVER_EXPOSURE
2243#undef FLICKER_BRIGHTNESS_CONSTANT
2244
2245/* update various camera modes and settings */
2246static void dispatch_commands(struct cam_data *cam)
2247{
2248 mutex_lock(&cam->param_lock);
2249 if (cam->cmd_queue==COMMAND_NONE) {
2250 mutex_unlock(&cam->param_lock);
2251 return;
2252 }
2253 DEB_BYTE(cam->cmd_queue);
2254 DEB_BYTE(cam->cmd_queue>>8);
2255 if (cam->cmd_queue & COMMAND_SETFORMAT) {
2256 do_command(cam, CPIA_COMMAND_SetFormat,
2257 cam->params.format.videoSize,
2258 cam->params.format.subSample,
2259 cam->params.format.yuvOrder, 0);
2260 do_command(cam, CPIA_COMMAND_SetROI,
2261 cam->params.roi.colStart, cam->params.roi.colEnd,
2262 cam->params.roi.rowStart, cam->params.roi.rowEnd);
2263 cam->first_frame = 1;
2264 }
2265
2266 if (cam->cmd_queue & COMMAND_SETCOLOURPARAMS)
2267 do_command(cam, CPIA_COMMAND_SetColourParams,
2268 cam->params.colourParams.brightness,
2269 cam->params.colourParams.contrast,
2270 cam->params.colourParams.saturation, 0);
2271
2272 if (cam->cmd_queue & COMMAND_SETAPCOR)
2273 do_command(cam, CPIA_COMMAND_SetApcor,
2274 cam->params.apcor.gain1,
2275 cam->params.apcor.gain2,
2276 cam->params.apcor.gain4,
2277 cam->params.apcor.gain8);
2278
2279 if (cam->cmd_queue & COMMAND_SETVLOFFSET)
2280 do_command(cam, CPIA_COMMAND_SetVLOffset,
2281 cam->params.vlOffset.gain1,
2282 cam->params.vlOffset.gain2,
2283 cam->params.vlOffset.gain4,
2284 cam->params.vlOffset.gain8);
2285
2286 if (cam->cmd_queue & COMMAND_SETEXPOSURE) {
2287 do_command_extended(cam, CPIA_COMMAND_SetExposure,
2288 cam->params.exposure.gainMode,
2289 1,
2290 cam->params.exposure.compMode,
2291 cam->params.exposure.centreWeight,
2292 cam->params.exposure.gain,
2293 cam->params.exposure.fineExp,
2294 cam->params.exposure.coarseExpLo,
2295 cam->params.exposure.coarseExpHi,
2296 cam->params.exposure.redComp,
2297 cam->params.exposure.green1Comp,
2298 cam->params.exposure.green2Comp,
2299 cam->params.exposure.blueComp);
2300 if(cam->params.exposure.expMode != 1) {
2301 do_command_extended(cam, CPIA_COMMAND_SetExposure,
2302 0,
2303 cam->params.exposure.expMode,
2304 0, 0,
2305 cam->params.exposure.gain,
2306 cam->params.exposure.fineExp,
2307 cam->params.exposure.coarseExpLo,
2308 cam->params.exposure.coarseExpHi,
2309 0, 0, 0, 0);
2310 }
2311 }
2312
2313 if (cam->cmd_queue & COMMAND_SETCOLOURBALANCE) {
2314 if (cam->params.colourBalance.balanceMode == 1) {
2315 do_command(cam, CPIA_COMMAND_SetColourBalance,
2316 1,
2317 cam->params.colourBalance.redGain,
2318 cam->params.colourBalance.greenGain,
2319 cam->params.colourBalance.blueGain);
2320 do_command(cam, CPIA_COMMAND_SetColourBalance,
2321 3, 0, 0, 0);
2322 }
2323 if (cam->params.colourBalance.balanceMode == 2) {
2324 do_command(cam, CPIA_COMMAND_SetColourBalance,
2325 2, 0, 0, 0);
2326 }
2327 if (cam->params.colourBalance.balanceMode == 3) {
2328 do_command(cam, CPIA_COMMAND_SetColourBalance,
2329 3, 0, 0, 0);
2330 }
2331 }
2332
2333 if (cam->cmd_queue & COMMAND_SETCOMPRESSIONTARGET)
2334 do_command(cam, CPIA_COMMAND_SetCompressionTarget,
2335 cam->params.compressionTarget.frTargeting,
2336 cam->params.compressionTarget.targetFR,
2337 cam->params.compressionTarget.targetQ, 0);
2338
2339 if (cam->cmd_queue & COMMAND_SETYUVTHRESH)
2340 do_command(cam, CPIA_COMMAND_SetYUVThresh,
2341 cam->params.yuvThreshold.yThreshold,
2342 cam->params.yuvThreshold.uvThreshold, 0, 0);
2343
2344 if (cam->cmd_queue & COMMAND_SETCOMPRESSIONPARAMS)
2345 do_command_extended(cam, CPIA_COMMAND_SetCompressionParams,
2346 0, 0, 0, 0,
2347 cam->params.compressionParams.hysteresis,
2348 cam->params.compressionParams.threshMax,
2349 cam->params.compressionParams.smallStep,
2350 cam->params.compressionParams.largeStep,
2351 cam->params.compressionParams.decimationHysteresis,
2352 cam->params.compressionParams.frDiffStepThresh,
2353 cam->params.compressionParams.qDiffStepThresh,
2354 cam->params.compressionParams.decimationThreshMod);
2355
2356 if (cam->cmd_queue & COMMAND_SETCOMPRESSION)
2357 do_command(cam, CPIA_COMMAND_SetCompression,
2358 cam->params.compression.mode,
2359 cam->params.compression.decimation, 0, 0);
2360
2361 if (cam->cmd_queue & COMMAND_SETSENSORFPS)
2362 do_command(cam, CPIA_COMMAND_SetSensorFPS,
2363 cam->params.sensorFps.divisor,
2364 cam->params.sensorFps.baserate, 0, 0);
2365
2366 if (cam->cmd_queue & COMMAND_SETFLICKERCTRL)
2367 do_command(cam, CPIA_COMMAND_SetFlickerCtrl,
2368 cam->params.flickerControl.flickerMode,
2369 cam->params.flickerControl.coarseJump,
2370 abs(cam->params.flickerControl.allowableOverExposure),
2371 0);
2372
2373 if (cam->cmd_queue & COMMAND_SETECPTIMING)
2374 do_command(cam, CPIA_COMMAND_SetECPTiming,
2375 cam->params.ecpTiming, 0, 0, 0);
2376
2377 if (cam->cmd_queue & COMMAND_PAUSE)
2378 do_command(cam, CPIA_COMMAND_EndStreamCap, 0, 0, 0, 0);
2379
2380 if (cam->cmd_queue & COMMAND_RESUME)
2381 init_stream_cap(cam);
2382
2383 if (cam->cmd_queue & COMMAND_SETLIGHTS && cam->params.qx3.qx3_detected)
2384 {
2385 int p1 = (cam->params.qx3.bottomlight == 0) << 1;
2386 int p2 = (cam->params.qx3.toplight == 0) << 3;
2387 do_command(cam, CPIA_COMMAND_WriteVCReg, 0x90, 0x8F, 0x50, 0);
2388 do_command(cam, CPIA_COMMAND_WriteMCPort, 2, 0, (p1|p2|0xE0), 0);
2389 }
2390
2391 cam->cmd_queue = COMMAND_NONE;
2392 mutex_unlock(&cam->param_lock);
2393 return;
2394}
2395
2396
2397
2398static void set_flicker(struct cam_params *params, volatile u32 *command_flags,
2399 int on)
2400{
2401 /* Everything in here is from the Windows driver */
2402#define FIRMWARE_VERSION(x,y) (params->version.firmwareVersion == (x) && \
2403 params->version.firmwareRevision == (y))
2404/* define for compgain calculation */
2405#if 0
2406#define COMPGAIN(base, curexp, newexp) \
2407 (u8) ((((float) base - 128.0) * ((float) curexp / (float) newexp)) + 128.5)
2408#define EXP_FROM_COMP(basecomp, curcomp, curexp) \
2409 (u16)((float)curexp * (float)(u8)(curcomp + 128) / (float)(u8)(basecomp - 128))
2410#else
2411 /* equivalent functions without floating point math */
2412#define COMPGAIN(base, curexp, newexp) \
2413 (u8)(128 + (((u32)(2*(base-128)*curexp + newexp)) / (2* newexp)) )
2414#define EXP_FROM_COMP(basecomp, curcomp, curexp) \
2415 (u16)(((u32)(curexp * (u8)(curcomp + 128)) / (u8)(basecomp - 128)))
2416#endif
2417
2418
2419 int currentexp = params->exposure.coarseExpLo +
2420 params->exposure.coarseExpHi*256;
2421 int startexp;
2422 if (on) {
2423 int cj = params->flickerControl.coarseJump;
2424 params->flickerControl.flickerMode = 1;
2425 params->flickerControl.disabled = 0;
2426 if(params->exposure.expMode != 2)
2427 *command_flags |= COMMAND_SETEXPOSURE;
2428 params->exposure.expMode = 2;
2429 currentexp = currentexp << params->exposure.gain;
2430 params->exposure.gain = 0;
2431 /* round down current exposure to nearest value */
2432 startexp = (currentexp + ROUND_UP_EXP_FOR_FLICKER) / cj;
2433 if(startexp < 1)
2434 startexp = 1;
2435 startexp = (startexp * cj) - 1;
2436 if(FIRMWARE_VERSION(1,2))
2437 while(startexp > MAX_EXP_102)
2438 startexp -= cj;
2439 else
2440 while(startexp > MAX_EXP)
2441 startexp -= cj;
2442 params->exposure.coarseExpLo = startexp & 0xff;
2443 params->exposure.coarseExpHi = startexp >> 8;
2444 if (currentexp > startexp) {
2445 if (currentexp > (2 * startexp))
2446 currentexp = 2 * startexp;
2447 params->exposure.redComp = COMPGAIN (COMP_RED, currentexp, startexp);
2448 params->exposure.green1Comp = COMPGAIN (COMP_GREEN1, currentexp, startexp);
2449 params->exposure.green2Comp = COMPGAIN (COMP_GREEN2, currentexp, startexp);
2450 params->exposure.blueComp = COMPGAIN (COMP_BLUE, currentexp, startexp);
2451 } else {
2452 params->exposure.redComp = COMP_RED;
2453 params->exposure.green1Comp = COMP_GREEN1;
2454 params->exposure.green2Comp = COMP_GREEN2;
2455 params->exposure.blueComp = COMP_BLUE;
2456 }
2457 if(FIRMWARE_VERSION(1,2))
2458 params->exposure.compMode = 0;
2459 else
2460 params->exposure.compMode = 1;
2461
2462 params->apcor.gain1 = 0x18;
2463 params->apcor.gain2 = 0x18;
2464 params->apcor.gain4 = 0x16;
2465 params->apcor.gain8 = 0x14;
2466 *command_flags |= COMMAND_SETAPCOR;
2467 } else {
2468 params->flickerControl.flickerMode = 0;
2469 params->flickerControl.disabled = 1;
2470 /* Coarse = average of equivalent coarse for each comp channel */
2471 startexp = EXP_FROM_COMP(COMP_RED, params->exposure.redComp, currentexp);
2472 startexp += EXP_FROM_COMP(COMP_GREEN1, params->exposure.green1Comp, currentexp);
2473 startexp += EXP_FROM_COMP(COMP_GREEN2, params->exposure.green2Comp, currentexp);
2474 startexp += EXP_FROM_COMP(COMP_BLUE, params->exposure.blueComp, currentexp);
2475 startexp = startexp >> 2;
2476 while(startexp > MAX_EXP &&
2477 params->exposure.gain < params->exposure.gainMode-1) {
2478 startexp = startexp >> 1;
2479 ++params->exposure.gain;
2480 }
2481 if(FIRMWARE_VERSION(1,2) && startexp > MAX_EXP_102)
2482 startexp = MAX_EXP_102;
2483 if(startexp > MAX_EXP)
2484 startexp = MAX_EXP;
2485 params->exposure.coarseExpLo = startexp&0xff;
2486 params->exposure.coarseExpHi = startexp >> 8;
2487 params->exposure.redComp = COMP_RED;
2488 params->exposure.green1Comp = COMP_GREEN1;
2489 params->exposure.green2Comp = COMP_GREEN2;
2490 params->exposure.blueComp = COMP_BLUE;
2491 params->exposure.compMode = 1;
2492 *command_flags |= COMMAND_SETEXPOSURE;
2493 params->apcor.gain1 = 0x18;
2494 params->apcor.gain2 = 0x16;
2495 params->apcor.gain4 = 0x24;
2496 params->apcor.gain8 = 0x34;
2497 *command_flags |= COMMAND_SETAPCOR;
2498 }
2499 params->vlOffset.gain1 = 20;
2500 params->vlOffset.gain2 = 24;
2501 params->vlOffset.gain4 = 26;
2502 params->vlOffset.gain8 = 26;
2503 *command_flags |= COMMAND_SETVLOFFSET;
2504#undef FIRMWARE_VERSION
2505#undef EXP_FROM_COMP
2506#undef COMPGAIN
2507}
2508
2509#define FIRMWARE_VERSION(x,y) (cam->params.version.firmwareVersion == (x) && \
2510 cam->params.version.firmwareRevision == (y))
2511/* monitor the exposure and adjust the sensor frame rate if needed */
2512static void monitor_exposure(struct cam_data *cam)
2513{
2514 u8 exp_acc, bcomp, gain, coarseL, cmd[8], data[8];
2515 int retval, light_exp, dark_exp, very_dark_exp;
2516 int old_exposure, new_exposure, framerate;
2517
2518 /* get necessary stats and register settings from camera */
2519 /* do_command can't handle this, so do it ourselves */
2520 cmd[0] = CPIA_COMMAND_ReadVPRegs>>8;
2521 cmd[1] = CPIA_COMMAND_ReadVPRegs&0xff;
2522 cmd[2] = 30;
2523 cmd[3] = 4;
2524 cmd[4] = 9;
2525 cmd[5] = 8;
2526 cmd[6] = 8;
2527 cmd[7] = 0;
2528 retval = cam->ops->transferCmd(cam->lowlevel_data, cmd, data);
2529 if (retval) {
2530 LOG("ReadVPRegs(30,4,9,8) - failed, retval=%d\n",
2531 retval);
2532 return;
2533 }
2534 exp_acc = data[0];
2535 bcomp = data[1];
2536 gain = data[2];
2537 coarseL = data[3];
2538
2539 mutex_lock(&cam->param_lock);
2540 light_exp = cam->params.colourParams.brightness +
2541 TC - 50 + EXP_ACC_LIGHT;
2542 if(light_exp > 255)
2543 light_exp = 255;
2544 dark_exp = cam->params.colourParams.brightness +
2545 TC - 50 - EXP_ACC_DARK;
2546 if(dark_exp < 0)
2547 dark_exp = 0;
2548 very_dark_exp = dark_exp/2;
2549
2550 old_exposure = cam->params.exposure.coarseExpHi * 256 +
2551 cam->params.exposure.coarseExpLo;
2552
2553 if(!cam->params.flickerControl.disabled) {
2554 /* Flicker control on */
2555 int max_comp = FIRMWARE_VERSION(1,2) ? MAX_COMP : HIGH_COMP_102;
2556 bcomp += 128; /* decode */
2557 if(bcomp >= max_comp && exp_acc < dark_exp) {
2558 /* dark */
2559 if(exp_acc < very_dark_exp) {
2560 /* very dark */
2561 if(cam->exposure_status == EXPOSURE_VERY_DARK)
2562 ++cam->exposure_count;
2563 else {
2564 cam->exposure_status = EXPOSURE_VERY_DARK;
2565 cam->exposure_count = 1;
2566 }
2567 } else {
2568 /* just dark */
2569 if(cam->exposure_status == EXPOSURE_DARK)
2570 ++cam->exposure_count;
2571 else {
2572 cam->exposure_status = EXPOSURE_DARK;
2573 cam->exposure_count = 1;
2574 }
2575 }
2576 } else if(old_exposure <= LOW_EXP || exp_acc > light_exp) {
2577 /* light */
2578 if(old_exposure <= VERY_LOW_EXP) {
2579 /* very light */
2580 if(cam->exposure_status == EXPOSURE_VERY_LIGHT)
2581 ++cam->exposure_count;
2582 else {
2583 cam->exposure_status = EXPOSURE_VERY_LIGHT;
2584 cam->exposure_count = 1;
2585 }
2586 } else {
2587 /* just light */
2588 if(cam->exposure_status == EXPOSURE_LIGHT)
2589 ++cam->exposure_count;
2590 else {
2591 cam->exposure_status = EXPOSURE_LIGHT;
2592 cam->exposure_count = 1;
2593 }
2594 }
2595 } else {
2596 /* not dark or light */
2597 cam->exposure_status = EXPOSURE_NORMAL;
2598 }
2599 } else {
2600 /* Flicker control off */
2601 if(old_exposure >= MAX_EXP && exp_acc < dark_exp) {
2602 /* dark */
2603 if(exp_acc < very_dark_exp) {
2604 /* very dark */
2605 if(cam->exposure_status == EXPOSURE_VERY_DARK)
2606 ++cam->exposure_count;
2607 else {
2608 cam->exposure_status = EXPOSURE_VERY_DARK;
2609 cam->exposure_count = 1;
2610 }
2611 } else {
2612 /* just dark */
2613 if(cam->exposure_status == EXPOSURE_DARK)
2614 ++cam->exposure_count;
2615 else {
2616 cam->exposure_status = EXPOSURE_DARK;
2617 cam->exposure_count = 1;
2618 }
2619 }
2620 } else if(old_exposure <= LOW_EXP || exp_acc > light_exp) {
2621 /* light */
2622 if(old_exposure <= VERY_LOW_EXP) {
2623 /* very light */
2624 if(cam->exposure_status == EXPOSURE_VERY_LIGHT)
2625 ++cam->exposure_count;
2626 else {
2627 cam->exposure_status = EXPOSURE_VERY_LIGHT;
2628 cam->exposure_count = 1;
2629 }
2630 } else {
2631 /* just light */
2632 if(cam->exposure_status == EXPOSURE_LIGHT)
2633 ++cam->exposure_count;
2634 else {
2635 cam->exposure_status = EXPOSURE_LIGHT;
2636 cam->exposure_count = 1;
2637 }
2638 }
2639 } else {
2640 /* not dark or light */
2641 cam->exposure_status = EXPOSURE_NORMAL;
2642 }
2643 }
2644
2645 framerate = cam->fps;
2646 if(framerate > 30 || framerate < 1)
2647 framerate = 1;
2648
2649 if(!cam->params.flickerControl.disabled) {
2650 /* Flicker control on */
2651 if((cam->exposure_status == EXPOSURE_VERY_DARK ||
2652 cam->exposure_status == EXPOSURE_DARK) &&
2653 cam->exposure_count >= DARK_TIME*framerate &&
2654 cam->params.sensorFps.divisor < 3) {
2655
2656 /* dark for too long */
2657 ++cam->params.sensorFps.divisor;
2658 cam->cmd_queue |= COMMAND_SETSENSORFPS;
2659
2660 cam->params.flickerControl.coarseJump =
2661 flicker_jumps[cam->mainsFreq]
2662 [cam->params.sensorFps.baserate]
2663 [cam->params.sensorFps.divisor];
2664 cam->cmd_queue |= COMMAND_SETFLICKERCTRL;
2665
2666 new_exposure = cam->params.flickerControl.coarseJump-1;
2667 while(new_exposure < old_exposure/2)
2668 new_exposure += cam->params.flickerControl.coarseJump;
2669 cam->params.exposure.coarseExpLo = new_exposure & 0xff;
2670 cam->params.exposure.coarseExpHi = new_exposure >> 8;
2671 cam->cmd_queue |= COMMAND_SETEXPOSURE;
2672 cam->exposure_status = EXPOSURE_NORMAL;
2673 LOG("Automatically decreasing sensor_fps\n");
2674
2675 } else if((cam->exposure_status == EXPOSURE_VERY_LIGHT ||
2676 cam->exposure_status == EXPOSURE_LIGHT) &&
2677 cam->exposure_count >= LIGHT_TIME*framerate &&
2678 cam->params.sensorFps.divisor > 0) {
2679
2680 /* light for too long */
2681 int max_exp = FIRMWARE_VERSION(1,2) ? MAX_EXP_102 : MAX_EXP ;
2682
2683 --cam->params.sensorFps.divisor;
2684 cam->cmd_queue |= COMMAND_SETSENSORFPS;
2685
2686 cam->params.flickerControl.coarseJump =
2687 flicker_jumps[cam->mainsFreq]
2688 [cam->params.sensorFps.baserate]
2689 [cam->params.sensorFps.divisor];
2690 cam->cmd_queue |= COMMAND_SETFLICKERCTRL;
2691
2692 new_exposure = cam->params.flickerControl.coarseJump-1;
2693 while(new_exposure < 2*old_exposure &&
2694 new_exposure+
2695 cam->params.flickerControl.coarseJump < max_exp)
2696 new_exposure += cam->params.flickerControl.coarseJump;
2697 cam->params.exposure.coarseExpLo = new_exposure & 0xff;
2698 cam->params.exposure.coarseExpHi = new_exposure >> 8;
2699 cam->cmd_queue |= COMMAND_SETEXPOSURE;
2700 cam->exposure_status = EXPOSURE_NORMAL;
2701 LOG("Automatically increasing sensor_fps\n");
2702 }
2703 } else {
2704 /* Flicker control off */
2705 if((cam->exposure_status == EXPOSURE_VERY_DARK ||
2706 cam->exposure_status == EXPOSURE_DARK) &&
2707 cam->exposure_count >= DARK_TIME*framerate &&
2708 cam->params.sensorFps.divisor < 3) {
2709
2710 /* dark for too long */
2711 ++cam->params.sensorFps.divisor;
2712 cam->cmd_queue |= COMMAND_SETSENSORFPS;
2713
2714 if(cam->params.exposure.gain > 0) {
2715 --cam->params.exposure.gain;
2716 cam->cmd_queue |= COMMAND_SETEXPOSURE;
2717 }
2718 cam->exposure_status = EXPOSURE_NORMAL;
2719 LOG("Automatically decreasing sensor_fps\n");
2720
2721 } else if((cam->exposure_status == EXPOSURE_VERY_LIGHT ||
2722 cam->exposure_status == EXPOSURE_LIGHT) &&
2723 cam->exposure_count >= LIGHT_TIME*framerate &&
2724 cam->params.sensorFps.divisor > 0) {
2725
2726 /* light for too long */
2727 --cam->params.sensorFps.divisor;
2728 cam->cmd_queue |= COMMAND_SETSENSORFPS;
2729
2730 if(cam->params.exposure.gain <
2731 cam->params.exposure.gainMode-1) {
2732 ++cam->params.exposure.gain;
2733 cam->cmd_queue |= COMMAND_SETEXPOSURE;
2734 }
2735 cam->exposure_status = EXPOSURE_NORMAL;
2736 LOG("Automatically increasing sensor_fps\n");
2737 }
2738 }
2739 mutex_unlock(&cam->param_lock);
2740}
2741
2742/*-----------------------------------------------------------------*/
2743/* if flicker is switched off, this function switches it back on.It checks,
2744 however, that conditions are suitable before restarting it.
2745 This should only be called for firmware version 1.2.
2746
2747 It also adjust the colour balance when an exposure step is detected - as
2748 long as flicker is running
2749*/
2750static void restart_flicker(struct cam_data *cam)
2751{
2752 int cam_exposure, old_exp;
2753 if(!FIRMWARE_VERSION(1,2))
2754 return;
2755 mutex_lock(&cam->param_lock);
2756 if(cam->params.flickerControl.flickerMode == 0 ||
2757 cam->raw_image[39] == 0) {
2758 mutex_unlock(&cam->param_lock);
2759 return;
2760 }
2761 cam_exposure = cam->raw_image[39]*2;
2762 old_exp = cam->params.exposure.coarseExpLo +
2763 cam->params.exposure.coarseExpHi*256;
2764 /*
2765 see how far away camera exposure is from a valid
2766 flicker exposure value
2767 */
2768 cam_exposure %= cam->params.flickerControl.coarseJump;
2769 if(!cam->params.flickerControl.disabled &&
2770 cam_exposure <= cam->params.flickerControl.coarseJump - 3) {
2771 /* Flicker control auto-disabled */
2772 cam->params.flickerControl.disabled = 1;
2773 }
2774
2775 if(cam->params.flickerControl.disabled &&
2776 cam->params.flickerControl.flickerMode &&
2777 old_exp > cam->params.flickerControl.coarseJump +
2778 ROUND_UP_EXP_FOR_FLICKER) {
2779 /* exposure is now high enough to switch
2780 flicker control back on */
2781 set_flicker(&cam->params, &cam->cmd_queue, 1);
2782 if((cam->cmd_queue & COMMAND_SETEXPOSURE) &&
2783 cam->params.exposure.expMode == 2)
2784 cam->exposure_status = EXPOSURE_NORMAL;
2785
2786 }
2787 mutex_unlock(&cam->param_lock);
2788}
2789#undef FIRMWARE_VERSION
2790
2791static int clear_stall(struct cam_data *cam)
2792{
2793 /* FIXME: Does this actually work? */
2794 LOG("Clearing stall\n");
2795
2796 cam->ops->streamRead(cam->lowlevel_data, cam->raw_image, 0);
2797 do_command(cam, CPIA_COMMAND_GetCameraStatus,0,0,0,0);
2798 return cam->params.status.streamState != STREAM_PAUSED;
2799}
2800
2801/* kernel thread function to read image from camera */
2802static int fetch_frame(void *data)
2803{
2804 int image_size, retry;
2805 struct cam_data *cam = (struct cam_data *)data;
2806 unsigned long oldjif, rate, diff;
2807
2808 /* Allow up to two bad images in a row to be read and
2809 * ignored before an error is reported */
2810 for (retry = 0; retry < 3; ++retry) {
2811 if (retry)
2812 DBG("retry=%d\n", retry);
2813
2814 if (!cam->ops)
2815 continue;
2816
2817 /* load first frame always uncompressed */
2818 if (cam->first_frame &&
2819 cam->params.compression.mode != CPIA_COMPRESSION_NONE) {
2820 do_command(cam, CPIA_COMMAND_SetCompression,
2821 CPIA_COMPRESSION_NONE,
2822 NO_DECIMATION, 0, 0);
2823 /* Trial & error - Discarding a frame prevents the
2824 first frame from having an error in the data. */
2825 do_command(cam, CPIA_COMMAND_DiscardFrame, 0, 0, 0, 0);
2826 }
2827
2828 /* init camera upload */
2829 if (do_command(cam, CPIA_COMMAND_GrabFrame, 0,
2830 cam->params.streamStartLine, 0, 0))
2831 continue;
2832
2833 if (cam->ops->wait_for_stream_ready) {
2834 /* loop until image ready */
2835 int count = 0;
2836 do_command(cam, CPIA_COMMAND_GetCameraStatus,0,0,0,0);
2837 while (cam->params.status.streamState != STREAM_READY) {
2838 if(++count > READY_TIMEOUT)
2839 break;
2840 if(cam->params.status.streamState ==
2841 STREAM_PAUSED) {
2842 /* Bad news */
2843 if(!clear_stall(cam))
2844 return -EIO;
2845 }
2846
2847 cond_resched();
2848
2849 /* sleep for 10 ms, hopefully ;) */
2850 msleep_interruptible(10);
2851 if (signal_pending(current))
2852 return -EINTR;
2853
2854 do_command(cam, CPIA_COMMAND_GetCameraStatus,
2855 0, 0, 0, 0);
2856 }
2857 if(cam->params.status.streamState != STREAM_READY) {
2858 continue;
2859 }
2860 }
2861
2862 cond_resched();
2863
2864 /* grab image from camera */
2865 oldjif = jiffies;
2866 image_size = cam->ops->streamRead(cam->lowlevel_data,
2867 cam->raw_image, 0);
2868 if (image_size <= 0) {
2869 DBG("streamRead failed: %d\n", image_size);
2870 continue;
2871 }
2872
2873 rate = image_size * HZ / 1024;
2874 diff = jiffies-oldjif;
2875 cam->transfer_rate = diff==0 ? rate : rate/diff;
2876 /* diff==0 ? unlikely but possible */
2877
2878 /* Switch flicker control back on if it got turned off */
2879 restart_flicker(cam);
2880
2881 /* If AEC is enabled, monitor the exposure and
2882 adjust the sensor frame rate if needed */
2883 if(cam->params.exposure.expMode == 2)
2884 monitor_exposure(cam);
2885
2886 /* camera idle now so dispatch queued commands */
2887 dispatch_commands(cam);
2888
2889 /* Update our knowledge of the camera state */
2890 do_command(cam, CPIA_COMMAND_GetColourBalance, 0, 0, 0, 0);
2891 do_command(cam, CPIA_COMMAND_GetExposure, 0, 0, 0, 0);
2892 do_command(cam, CPIA_COMMAND_ReadMCPorts, 0, 0, 0, 0);
2893
2894 /* decompress and convert image to by copying it from
2895 * raw_image to decompressed_frame
2896 */
2897
2898 cond_resched();
2899
2900 cam->image_size = parse_picture(cam, image_size);
2901 if (cam->image_size <= 0) {
2902 DBG("parse_picture failed %d\n", cam->image_size);
2903 if(cam->params.compression.mode !=
2904 CPIA_COMPRESSION_NONE) {
2905 /* Compression may not work right if we
2906 had a bad frame, get the next one
2907 uncompressed. */
2908 cam->first_frame = 1;
2909 do_command(cam, CPIA_COMMAND_SetGrabMode,
2910 CPIA_GRAB_SINGLE, 0, 0, 0);
2911 /* FIXME: Trial & error - need up to 70ms for
2912 the grab mode change to complete ? */
2913 msleep_interruptible(70);
2914 if (signal_pending(current))
2915 return -EINTR;
2916 }
2917 } else
2918 break;
2919 }
2920
2921 if (retry < 3) {
2922 /* FIXME: this only works for double buffering */
2923 if (cam->frame[cam->curframe].state == FRAME_READY) {
2924 memcpy(cam->frame[cam->curframe].data,
2925 cam->decompressed_frame.data,
2926 cam->decompressed_frame.count);
2927 cam->frame[cam->curframe].state = FRAME_DONE;
2928 } else
2929 cam->decompressed_frame.state = FRAME_DONE;
2930
2931 if (cam->first_frame) {
2932 cam->first_frame = 0;
2933 do_command(cam, CPIA_COMMAND_SetCompression,
2934 cam->params.compression.mode,
2935 cam->params.compression.decimation, 0, 0);
2936
2937 /* Switch from single-grab to continuous grab */
2938 do_command(cam, CPIA_COMMAND_SetGrabMode,
2939 CPIA_GRAB_CONTINUOUS, 0, 0, 0);
2940 }
2941 return 0;
2942 }
2943 return -EIO;
2944}
2945
2946static int capture_frame(struct cam_data *cam, struct video_mmap *vm)
2947{
2948 if (!cam->frame_buf) {
2949 /* we do lazy allocation */
2950 int err;
2951 if ((err = allocate_frame_buf(cam)))
2952 return err;
2953 }
2954
2955 cam->curframe = vm->frame;
2956 cam->frame[cam->curframe].state = FRAME_READY;
2957 return fetch_frame(cam);
2958}
2959
2960static int goto_high_power(struct cam_data *cam)
2961{
2962 if (do_command(cam, CPIA_COMMAND_GotoHiPower, 0, 0, 0, 0))
2963 return -EIO;
2964 msleep_interruptible(40); /* windows driver does it too */
2965 if(signal_pending(current))
2966 return -EINTR;
2967 if (do_command(cam, CPIA_COMMAND_GetCameraStatus, 0, 0, 0, 0))
2968 return -EIO;
2969 if (cam->params.status.systemState == HI_POWER_STATE) {
2970 DBG("camera now in HIGH power state\n");
2971 return 0;
2972 }
2973 printstatus(cam);
2974 return -EIO;
2975}
2976
2977static int goto_low_power(struct cam_data *cam)
2978{
2979 if (do_command(cam, CPIA_COMMAND_GotoLoPower, 0, 0, 0, 0))
2980 return -1;
2981 if (do_command(cam, CPIA_COMMAND_GetCameraStatus, 0, 0, 0, 0))
2982 return -1;
2983 if (cam->params.status.systemState == LO_POWER_STATE) {
2984 DBG("camera now in LOW power state\n");
2985 return 0;
2986 }
2987 printstatus(cam);
2988 return -1;
2989}
2990
2991static void save_camera_state(struct cam_data *cam)
2992{
2993 if(!(cam->cmd_queue & COMMAND_SETCOLOURBALANCE))
2994 do_command(cam, CPIA_COMMAND_GetColourBalance, 0, 0, 0, 0);
2995 if(!(cam->cmd_queue & COMMAND_SETEXPOSURE))
2996 do_command(cam, CPIA_COMMAND_GetExposure, 0, 0, 0, 0);
2997
2998 DBG("%d/%d/%d/%d/%d/%d/%d/%d\n",
2999 cam->params.exposure.gain,
3000 cam->params.exposure.fineExp,
3001 cam->params.exposure.coarseExpLo,
3002 cam->params.exposure.coarseExpHi,
3003 cam->params.exposure.redComp,
3004 cam->params.exposure.green1Comp,
3005 cam->params.exposure.green2Comp,
3006 cam->params.exposure.blueComp);
3007 DBG("%d/%d/%d\n",
3008 cam->params.colourBalance.redGain,
3009 cam->params.colourBalance.greenGain,
3010 cam->params.colourBalance.blueGain);
3011}
3012
3013static int set_camera_state(struct cam_data *cam)
3014{
3015 cam->cmd_queue = COMMAND_SETCOMPRESSION |
3016 COMMAND_SETCOMPRESSIONTARGET |
3017 COMMAND_SETCOLOURPARAMS |
3018 COMMAND_SETFORMAT |
3019 COMMAND_SETYUVTHRESH |
3020 COMMAND_SETECPTIMING |
3021 COMMAND_SETCOMPRESSIONPARAMS |
3022 COMMAND_SETEXPOSURE |
3023 COMMAND_SETCOLOURBALANCE |
3024 COMMAND_SETSENSORFPS |
3025 COMMAND_SETAPCOR |
3026 COMMAND_SETFLICKERCTRL |
3027 COMMAND_SETVLOFFSET;
3028
3029 do_command(cam, CPIA_COMMAND_SetGrabMode, CPIA_GRAB_SINGLE,0,0,0);
3030 dispatch_commands(cam);
3031
3032 /* Wait 6 frames for the sensor to get all settings and
3033 AEC/ACB to settle */
3034 msleep_interruptible(6*(cam->params.sensorFps.baserate ? 33 : 40) *
3035 (1 << cam->params.sensorFps.divisor) + 10);
3036
3037 if(signal_pending(current))
3038 return -EINTR;
3039
3040 save_camera_state(cam);
3041
3042 return 0;
3043}
3044
3045static void get_version_information(struct cam_data *cam)
3046{
3047 /* GetCPIAVersion */
3048 do_command(cam, CPIA_COMMAND_GetCPIAVersion, 0, 0, 0, 0);
3049
3050 /* GetPnPID */
3051 do_command(cam, CPIA_COMMAND_GetPnPID, 0, 0, 0, 0);
3052}
3053
3054/* initialize camera */
3055static int reset_camera(struct cam_data *cam)
3056{
3057 int err;
3058 /* Start the camera in low power mode */
3059 if (goto_low_power(cam)) {
3060 if (cam->params.status.systemState != WARM_BOOT_STATE)
3061 return -ENODEV;
3062
3063 /* FIXME: this is just dirty trial and error */
3064 err = goto_high_power(cam);
3065 if(err)
3066 return err;
3067 do_command(cam, CPIA_COMMAND_DiscardFrame, 0, 0, 0, 0);
3068 if (goto_low_power(cam))
3069 return -ENODEV;
3070 }
3071
3072 /* procedure described in developer's guide p3-28 */
3073
3074 /* Check the firmware version. */
3075 cam->params.version.firmwareVersion = 0;
3076 get_version_information(cam);
3077 if (cam->params.version.firmwareVersion != 1)
3078 return -ENODEV;
3079
3080 /* A bug in firmware 1-02 limits gainMode to 2 */
3081 if(cam->params.version.firmwareRevision <= 2 &&
3082 cam->params.exposure.gainMode > 2) {
3083 cam->params.exposure.gainMode = 2;
3084 }
3085
3086 /* set QX3 detected flag */
3087 cam->params.qx3.qx3_detected = (cam->params.pnpID.vendor == 0x0813 &&
3088 cam->params.pnpID.product == 0x0001);
3089
3090 /* The fatal error checking should be done after
3091 * the camera powers up (developer's guide p 3-38) */
3092
3093 /* Set streamState before transition to high power to avoid bug
3094 * in firmware 1-02 */
3095 do_command(cam, CPIA_COMMAND_ModifyCameraStatus, STREAMSTATE, 0,
3096 STREAM_NOT_READY, 0);
3097
3098 /* GotoHiPower */
3099 err = goto_high_power(cam);
3100 if (err)
3101 return err;
3102
3103 /* Check the camera status */
3104 if (do_command(cam, CPIA_COMMAND_GetCameraStatus, 0, 0, 0, 0))
3105 return -EIO;
3106
3107 if (cam->params.status.fatalError) {
3108 DBG("fatal_error: %#04x\n",
3109 cam->params.status.fatalError);
3110 DBG("vp_status: %#04x\n",
3111 cam->params.status.vpStatus);
3112 if (cam->params.status.fatalError & ~(COM_FLAG|CPIA_FLAG)) {
3113 /* Fatal error in camera */
3114 return -EIO;
3115 } else if (cam->params.status.fatalError & (COM_FLAG|CPIA_FLAG)) {
3116 /* Firmware 1-02 may do this for parallel port cameras,
3117 * just clear the flags (developer's guide p 3-38) */
3118 do_command(cam, CPIA_COMMAND_ModifyCameraStatus,
3119 FATALERROR, ~(COM_FLAG|CPIA_FLAG), 0, 0);
3120 }
3121 }
3122
3123 /* Check the camera status again */
3124 if (cam->params.status.fatalError) {
3125 if (cam->params.status.fatalError)
3126 return -EIO;
3127 }
3128
3129 /* VPVersion can't be retrieved before the camera is in HiPower,
3130 * so get it here instead of in get_version_information. */
3131 do_command(cam, CPIA_COMMAND_GetVPVersion, 0, 0, 0, 0);
3132
3133 /* set camera to a known state */
3134 return set_camera_state(cam);
3135}
3136
3137static void put_cam(struct cpia_camera_ops* ops)
3138{
3139 module_put(ops->owner);
3140}
3141
3142/* ------------------------- V4L interface --------------------- */
3143static int cpia_open(struct file *file)
3144{
3145 struct video_device *dev = video_devdata(file);
3146 struct cam_data *cam = video_get_drvdata(dev);
3147 int err;
3148
3149 if (!cam) {
3150 DBG("Internal error, cam_data not found!\n");
3151 return -ENODEV;
3152 }
3153
3154 if (cam->open_count > 0) {
3155 DBG("Camera already open\n");
3156 return -EBUSY;
3157 }
3158
3159 if (!try_module_get(cam->ops->owner))
3160 return -ENODEV;
3161
3162 mutex_lock(&cam->busy_lock);
3163 err = -ENOMEM;
3164 if (!cam->raw_image) {
3165 cam->raw_image = rvmalloc(CPIA_MAX_IMAGE_SIZE);
3166 if (!cam->raw_image)
3167 goto oops;
3168 }
3169
3170 if (!cam->decompressed_frame.data) {
3171 cam->decompressed_frame.data = rvmalloc(CPIA_MAX_FRAME_SIZE);
3172 if (!cam->decompressed_frame.data)
3173 goto oops;
3174 }
3175
3176 /* open cpia */
3177 err = -ENODEV;
3178 if (cam->ops->open(cam->lowlevel_data))
3179 goto oops;
3180
3181 /* reset the camera */
3182 if ((err = reset_camera(cam)) != 0) {
3183 cam->ops->close(cam->lowlevel_data);
3184 goto oops;
3185 }
3186
3187 /* Set ownership of /proc/cpia/videoX to current user */
3188 if(cam->proc_entry)
3189 cam->proc_entry->uid = current_euid();
3190
3191 /* set mark for loading first frame uncompressed */
3192 cam->first_frame = 1;
3193
3194 /* init it to something */
3195 cam->mmap_kludge = 0;
3196
3197 ++cam->open_count;
3198 file->private_data = dev;
3199 mutex_unlock(&cam->busy_lock);
3200 return 0;
3201
3202 oops:
3203 if (cam->decompressed_frame.data) {
3204 rvfree(cam->decompressed_frame.data, CPIA_MAX_FRAME_SIZE);
3205 cam->decompressed_frame.data = NULL;
3206 }
3207 if (cam->raw_image) {
3208 rvfree(cam->raw_image, CPIA_MAX_IMAGE_SIZE);
3209 cam->raw_image = NULL;
3210 }
3211 mutex_unlock(&cam->busy_lock);
3212 put_cam(cam->ops);
3213 return err;
3214}
3215
3216static int cpia_close(struct file *file)
3217{
3218 struct video_device *dev = file->private_data;
3219 struct cam_data *cam = video_get_drvdata(dev);
3220
3221 if (cam->ops) {
3222 /* Return ownership of /proc/cpia/videoX to root */
3223 if(cam->proc_entry)
3224 cam->proc_entry->uid = 0;
3225
3226 /* save camera state for later open (developers guide ch 3.5.3) */
3227 save_camera_state(cam);
3228
3229 /* GotoLoPower */
3230 goto_low_power(cam);
3231
3232 /* Update the camera status */
3233 do_command(cam, CPIA_COMMAND_GetCameraStatus, 0, 0, 0, 0);
3234
3235 /* cleanup internal state stuff */
3236 free_frames(cam->frame);
3237
3238 /* close cpia */
3239 cam->ops->close(cam->lowlevel_data);
3240
3241 put_cam(cam->ops);
3242 }
3243
3244 if (--cam->open_count == 0) {
3245 /* clean up capture-buffers */
3246 if (cam->raw_image) {
3247 rvfree(cam->raw_image, CPIA_MAX_IMAGE_SIZE);
3248 cam->raw_image = NULL;
3249 }
3250
3251 if (cam->decompressed_frame.data) {
3252 rvfree(cam->decompressed_frame.data, CPIA_MAX_FRAME_SIZE);
3253 cam->decompressed_frame.data = NULL;
3254 }
3255
3256 if (cam->frame_buf)
3257 free_frame_buf(cam);
3258
3259 if (!cam->ops)
3260 kfree(cam);
3261 }
3262 file->private_data = NULL;
3263
3264 return 0;
3265}
3266
3267static ssize_t cpia_read(struct file *file, char __user *buf,
3268 size_t count, loff_t *ppos)
3269{
3270 struct video_device *dev = file->private_data;
3271 struct cam_data *cam = video_get_drvdata(dev);
3272 int err;
3273
3274 /* make this _really_ smp and multithread-safe */
3275 if (mutex_lock_interruptible(&cam->busy_lock))
3276 return -EINTR;
3277
3278 if (!buf) {
3279 DBG("buf NULL\n");
3280 mutex_unlock(&cam->busy_lock);
3281 return -EINVAL;
3282 }
3283
3284 if (!count) {
3285 DBG("count 0\n");
3286 mutex_unlock(&cam->busy_lock);
3287 return 0;
3288 }
3289
3290 if (!cam->ops) {
3291 DBG("ops NULL\n");
3292 mutex_unlock(&cam->busy_lock);
3293 return -ENODEV;
3294 }
3295
3296 /* upload frame */
3297 cam->decompressed_frame.state = FRAME_READY;
3298 cam->mmap_kludge=0;
3299 if((err = fetch_frame(cam)) != 0) {
3300 DBG("ERROR from fetch_frame: %d\n", err);
3301 mutex_unlock(&cam->busy_lock);
3302 return err;
3303 }
3304 cam->decompressed_frame.state = FRAME_UNUSED;
3305
3306 /* copy data to user space */
3307 if (cam->decompressed_frame.count > count) {
3308 DBG("count wrong: %d, %lu\n", cam->decompressed_frame.count,
3309 (unsigned long) count);
3310 mutex_unlock(&cam->busy_lock);
3311 return -EFAULT;
3312 }
3313 if (copy_to_user(buf, cam->decompressed_frame.data,
3314 cam->decompressed_frame.count)) {
3315 DBG("copy_to_user failed\n");
3316 mutex_unlock(&cam->busy_lock);
3317 return -EFAULT;
3318 }
3319
3320 mutex_unlock(&cam->busy_lock);
3321 return cam->decompressed_frame.count;
3322}
3323
3324static long cpia_do_ioctl(struct file *file, unsigned int cmd, void *arg)
3325{
3326 struct video_device *dev = file->private_data;
3327 struct cam_data *cam = video_get_drvdata(dev);
3328 int retval = 0;
3329
3330 if (!cam || !cam->ops)
3331 return -ENODEV;
3332
3333 /* make this _really_ smp-safe */
3334 if (mutex_lock_interruptible(&cam->busy_lock))
3335 return -EINTR;
3336
3337 /* DBG("cpia_ioctl: %u\n", cmd); */
3338
3339 switch (cmd) {
3340 /* query capabilities */
3341 case VIDIOCGCAP:
3342 {
3343 struct video_capability *b = arg;
3344
3345 DBG("VIDIOCGCAP\n");
3346 strcpy(b->name, "CPiA Camera");
3347 b->type = VID_TYPE_CAPTURE | VID_TYPE_SUBCAPTURE;
3348 b->channels = 1;
3349 b->audios = 0;
3350 b->maxwidth = 352; /* VIDEOSIZE_CIF */
3351 b->maxheight = 288;
3352 b->minwidth = 48; /* VIDEOSIZE_48_48 */
3353 b->minheight = 48;
3354 break;
3355 }
3356
3357 /* get/set video source - we are a camera and nothing else */
3358 case VIDIOCGCHAN:
3359 {
3360 struct video_channel *v = arg;
3361
3362 DBG("VIDIOCGCHAN\n");
3363 if (v->channel != 0) {
3364 retval = -EINVAL;
3365 break;
3366 }
3367
3368 v->channel = 0;
3369 strcpy(v->name, "Camera");
3370 v->tuners = 0;
3371 v->flags = 0;
3372 v->type = VIDEO_TYPE_CAMERA;
3373 v->norm = 0;
3374 break;
3375 }
3376
3377 case VIDIOCSCHAN:
3378 {
3379 struct video_channel *v = arg;
3380
3381 DBG("VIDIOCSCHAN\n");
3382 if (v->channel != 0)
3383 retval = -EINVAL;
3384 break;
3385 }
3386
3387 /* image properties */
3388 case VIDIOCGPICT:
3389 {
3390 struct video_picture *pic = arg;
3391 DBG("VIDIOCGPICT\n");
3392 *pic = cam->vp;
3393 break;
3394 }
3395
3396 case VIDIOCSPICT:
3397 {
3398 struct video_picture *vp = arg;
3399
3400 DBG("VIDIOCSPICT\n");
3401
3402 /* check validity */
3403 DBG("palette: %d\n", vp->palette);
3404 DBG("depth: %d\n", vp->depth);
3405 if (!valid_mode(vp->palette, vp->depth)) {
3406 retval = -EINVAL;
3407 break;
3408 }
3409
3410 mutex_lock(&cam->param_lock);
3411 /* brightness, colour, contrast need no check 0-65535 */
3412 cam->vp = *vp;
3413 /* update cam->params.colourParams */
3414 cam->params.colourParams.brightness = vp->brightness*100/65535;
3415 cam->params.colourParams.contrast = vp->contrast*100/65535;
3416 cam->params.colourParams.saturation = vp->colour*100/65535;
3417 /* contrast is in steps of 8, so round */
3418 cam->params.colourParams.contrast =
3419 ((cam->params.colourParams.contrast + 3) / 8) * 8;
3420 if (cam->params.version.firmwareVersion == 1 &&
3421 cam->params.version.firmwareRevision == 2 &&
3422 cam->params.colourParams.contrast > 80) {
3423 /* 1-02 firmware limits contrast to 80 */
3424 cam->params.colourParams.contrast = 80;
3425 }
3426
3427 /* Adjust flicker control if necessary */
3428 if(cam->params.flickerControl.allowableOverExposure < 0)
3429 cam->params.flickerControl.allowableOverExposure =
3430 -find_over_exposure(cam->params.colourParams.brightness);
3431 if(cam->params.flickerControl.flickerMode != 0)
3432 cam->cmd_queue |= COMMAND_SETFLICKERCTRL;
3433
3434
3435 /* queue command to update camera */
3436 cam->cmd_queue |= COMMAND_SETCOLOURPARAMS;
3437 mutex_unlock(&cam->param_lock);
3438 DBG("VIDIOCSPICT: %d / %d // %d / %d / %d / %d\n",
3439 vp->depth, vp->palette, vp->brightness, vp->hue, vp->colour,
3440 vp->contrast);
3441 break;
3442 }
3443
3444 /* get/set capture window */
3445 case VIDIOCGWIN:
3446 {
3447 struct video_window *vw = arg;
3448 DBG("VIDIOCGWIN\n");
3449
3450 *vw = cam->vw;
3451 break;
3452 }
3453
3454 case VIDIOCSWIN:
3455 {
3456 /* copy_from_user, check validity, copy to internal structure */
3457 struct video_window *vw = arg;
3458 DBG("VIDIOCSWIN\n");
3459
3460 if (vw->clipcount != 0) { /* clipping not supported */
3461 retval = -EINVAL;
3462 break;
3463 }
3464 if (vw->clips != NULL) { /* clipping not supported */
3465 retval = -EINVAL;
3466 break;
3467 }
3468
3469 /* we set the video window to something smaller or equal to what
3470 * is requested by the user???
3471 */
3472 mutex_lock(&cam->param_lock);
3473 if (vw->width != cam->vw.width || vw->height != cam->vw.height) {
3474 int video_size = match_videosize(vw->width, vw->height);
3475
3476 if (video_size < 0) {
3477 retval = -EINVAL;
3478 mutex_unlock(&cam->param_lock);
3479 break;
3480 }
3481 cam->video_size = video_size;
3482
3483 /* video size is changing, reset the subcapture area */
3484 memset(&cam->vc, 0, sizeof(cam->vc));
3485
3486 set_vw_size(cam);
3487 DBG("%d / %d\n", cam->vw.width, cam->vw.height);
3488 cam->cmd_queue |= COMMAND_SETFORMAT;
3489 }
3490
3491 mutex_unlock(&cam->param_lock);
3492
3493 /* setformat ignored by camera during streaming,
3494 * so stop/dispatch/start */
3495 if (cam->cmd_queue & COMMAND_SETFORMAT) {
3496 DBG("\n");
3497 dispatch_commands(cam);
3498 }
3499 DBG("%d/%d:%d\n", cam->video_size,
3500 cam->vw.width, cam->vw.height);
3501 break;
3502 }
3503
3504 /* mmap interface */
3505 case VIDIOCGMBUF:
3506 {
3507 struct video_mbuf *vm = arg;
3508 int i;
3509
3510 DBG("VIDIOCGMBUF\n");
3511 memset(vm, 0, sizeof(*vm));
3512 vm->size = CPIA_MAX_FRAME_SIZE*FRAME_NUM;
3513 vm->frames = FRAME_NUM;
3514 for (i = 0; i < FRAME_NUM; i++)
3515 vm->offsets[i] = CPIA_MAX_FRAME_SIZE * i;
3516 break;
3517 }
3518
3519 case VIDIOCMCAPTURE:
3520 {
3521 struct video_mmap *vm = arg;
3522 int video_size;
3523
3524 DBG("VIDIOCMCAPTURE: %d / %d / %dx%d\n", vm->format, vm->frame,
3525 vm->width, vm->height);
3526 if (vm->frame<0||vm->frame>=FRAME_NUM) {
3527 retval = -EINVAL;
3528 break;
3529 }
3530
3531 /* set video format */
3532 cam->vp.palette = vm->format;
3533 switch(vm->format) {
3534 case VIDEO_PALETTE_GREY:
3535 cam->vp.depth=8;
3536 break;
3537 case VIDEO_PALETTE_RGB555:
3538 case VIDEO_PALETTE_RGB565:
3539 case VIDEO_PALETTE_YUV422:
3540 case VIDEO_PALETTE_YUYV:
3541 case VIDEO_PALETTE_UYVY:
3542 cam->vp.depth = 16;
3543 break;
3544 case VIDEO_PALETTE_RGB24:
3545 cam->vp.depth = 24;
3546 break;
3547 case VIDEO_PALETTE_RGB32:
3548 cam->vp.depth = 32;
3549 break;
3550 default:
3551 retval = -EINVAL;
3552 break;
3553 }
3554 if (retval)
3555 break;
3556
3557 /* set video size */
3558 video_size = match_videosize(vm->width, vm->height);
3559 if (video_size < 0) {
3560 retval = -EINVAL;
3561 break;
3562 }
3563 if (video_size != cam->video_size) {
3564 cam->video_size = video_size;
3565
3566 /* video size is changing, reset the subcapture area */
3567 memset(&cam->vc, 0, sizeof(cam->vc));
3568
3569 set_vw_size(cam);
3570 cam->cmd_queue |= COMMAND_SETFORMAT;
3571 dispatch_commands(cam);
3572 }
3573 /* according to v4l-spec we must start streaming here */
3574 cam->mmap_kludge = 1;
3575 retval = capture_frame(cam, vm);
3576
3577 break;
3578 }
3579
3580 case VIDIOCSYNC:
3581 {
3582 int *frame = arg;
3583
3584 //DBG("VIDIOCSYNC: %d\n", *frame);
3585
3586 if (*frame<0 || *frame >= FRAME_NUM) {
3587 retval = -EINVAL;
3588 break;
3589 }
3590
3591 switch (cam->frame[*frame].state) {
3592 case FRAME_UNUSED:
3593 case FRAME_READY:
3594 case FRAME_GRABBING:
3595 DBG("sync to unused frame %d\n", *frame);
3596 retval = -EINVAL;
3597 break;
3598
3599 case FRAME_DONE:
3600 cam->frame[*frame].state = FRAME_UNUSED;
3601 //DBG("VIDIOCSYNC: %d synced\n", *frame);
3602 break;
3603 }
3604 if (retval == -EINTR) {
3605 /* FIXME - xawtv does not handle this nice */
3606 retval = 0;
3607 }
3608 break;
3609 }
3610
3611 case VIDIOCGCAPTURE:
3612 {
3613 struct video_capture *vc = arg;
3614
3615 DBG("VIDIOCGCAPTURE\n");
3616
3617 *vc = cam->vc;
3618
3619 break;
3620 }
3621
3622 case VIDIOCSCAPTURE:
3623 {
3624 struct video_capture *vc = arg;
3625
3626 DBG("VIDIOCSCAPTURE\n");
3627
3628 if (vc->decimation != 0) { /* How should this be used? */
3629 retval = -EINVAL;
3630 break;
3631 }
3632 if (vc->flags != 0) { /* Even/odd grab not supported */
3633 retval = -EINVAL;
3634 break;
3635 }
3636
3637 /* Clip to the resolution we can set for the ROI
3638 (every 8 columns and 4 rows) */
3639 vc->x = vc->x & ~(__u32)7;
3640 vc->y = vc->y & ~(__u32)3;
3641 vc->width = vc->width & ~(__u32)7;
3642 vc->height = vc->height & ~(__u32)3;
3643
3644 if(vc->width == 0 || vc->height == 0 ||
3645 vc->x + vc->width > cam->vw.width ||
3646 vc->y + vc->height > cam->vw.height) {
3647 retval = -EINVAL;
3648 break;
3649 }
3650
3651 DBG("%d,%d/%dx%d\n", vc->x,vc->y,vc->width, vc->height);
3652
3653 mutex_lock(&cam->param_lock);
3654
3655 cam->vc.x = vc->x;
3656 cam->vc.y = vc->y;
3657 cam->vc.width = vc->width;
3658 cam->vc.height = vc->height;
3659
3660 set_vw_size(cam);
3661 cam->cmd_queue |= COMMAND_SETFORMAT;
3662
3663 mutex_unlock(&cam->param_lock);
3664
3665 /* setformat ignored by camera during streaming,
3666 * so stop/dispatch/start */
3667 dispatch_commands(cam);
3668 break;
3669 }
3670
3671 case VIDIOCGUNIT:
3672 {
3673 struct video_unit *vu = arg;
3674
3675 DBG("VIDIOCGUNIT\n");
3676
3677 vu->video = cam->vdev.minor;
3678 vu->vbi = VIDEO_NO_UNIT;
3679 vu->radio = VIDEO_NO_UNIT;
3680 vu->audio = VIDEO_NO_UNIT;
3681 vu->teletext = VIDEO_NO_UNIT;
3682
3683 break;
3684 }
3685
3686
3687 /* pointless to implement overlay with this camera */
3688 case VIDIOCCAPTURE:
3689 case VIDIOCGFBUF:
3690 case VIDIOCSFBUF:
3691 case VIDIOCKEY:
3692 /* tuner interface - we have none */
3693 case VIDIOCGTUNER:
3694 case VIDIOCSTUNER:
3695 case VIDIOCGFREQ:
3696 case VIDIOCSFREQ:
3697 /* audio interface - we have none */
3698 case VIDIOCGAUDIO:
3699 case VIDIOCSAUDIO:
3700 retval = -EINVAL;
3701 break;
3702 default:
3703 retval = -ENOIOCTLCMD;
3704 break;
3705 }
3706
3707 mutex_unlock(&cam->busy_lock);
3708 return retval;
3709}
3710
3711static long cpia_ioctl(struct file *file,
3712 unsigned int cmd, unsigned long arg)
3713{
3714 return video_usercopy(file, cmd, arg, cpia_do_ioctl);
3715}
3716
3717
3718/* FIXME */
3719static int cpia_mmap(struct file *file, struct vm_area_struct *vma)
3720{
3721 struct video_device *dev = file->private_data;
3722 unsigned long start = vma->vm_start;
3723 unsigned long size = vma->vm_end - vma->vm_start;
3724 unsigned long page, pos;
3725 struct cam_data *cam = video_get_drvdata(dev);
3726 int retval;
3727
3728 if (!cam || !cam->ops)
3729 return -ENODEV;
3730
3731 DBG("cpia_mmap: %ld\n", size);
3732
3733 if (size > FRAME_NUM*CPIA_MAX_FRAME_SIZE)
3734 return -EINVAL;
3735
3736 /* make this _really_ smp-safe */
3737 if (mutex_lock_interruptible(&cam->busy_lock))
3738 return -EINTR;
3739
3740 if (!cam->frame_buf) { /* we do lazy allocation */
3741 if ((retval = allocate_frame_buf(cam))) {
3742 mutex_unlock(&cam->busy_lock);
3743 return retval;
3744 }
3745 }
3746
3747 pos = (unsigned long)(cam->frame_buf);
3748 while (size > 0) {
3749 page = vmalloc_to_pfn((void *)pos);
3750 if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED)) {
3751 mutex_unlock(&cam->busy_lock);
3752 return -EAGAIN;
3753 }
3754 start += PAGE_SIZE;
3755 pos += PAGE_SIZE;
3756 if (size > PAGE_SIZE)
3757 size -= PAGE_SIZE;
3758 else
3759 size = 0;
3760 }
3761
3762 DBG("cpia_mmap: %ld\n", size);
3763 mutex_unlock(&cam->busy_lock);
3764
3765 return 0;
3766}
3767
3768static const struct v4l2_file_operations cpia_fops = {
3769 .owner = THIS_MODULE,
3770 .open = cpia_open,
3771 .release = cpia_close,
3772 .read = cpia_read,
3773 .mmap = cpia_mmap,
3774 .ioctl = cpia_ioctl,
3775};
3776
3777static struct video_device cpia_template = {
3778 .name = "CPiA Camera",
3779 .fops = &cpia_fops,
3780 .release = video_device_release_empty,
3781};
3782
3783/* initialise cam_data structure */
3784static void reset_camera_struct(struct cam_data *cam)
3785{
3786 /* The following parameter values are the defaults from
3787 * "Software Developer's Guide for CPiA Cameras". Any changes
3788 * to the defaults are noted in comments. */
3789 cam->params.colourParams.brightness = 50;
3790 cam->params.colourParams.contrast = 48;
3791 cam->params.colourParams.saturation = 50;
3792 cam->params.exposure.gainMode = 4;
3793 cam->params.exposure.expMode = 2; /* AEC */
3794 cam->params.exposure.compMode = 1;
3795 cam->params.exposure.centreWeight = 1;
3796 cam->params.exposure.gain = 0;
3797 cam->params.exposure.fineExp = 0;
3798 cam->params.exposure.coarseExpLo = 185;
3799 cam->params.exposure.coarseExpHi = 0;
3800 cam->params.exposure.redComp = COMP_RED;
3801 cam->params.exposure.green1Comp = COMP_GREEN1;
3802 cam->params.exposure.green2Comp = COMP_GREEN2;
3803 cam->params.exposure.blueComp = COMP_BLUE;
3804 cam->params.colourBalance.balanceMode = 2; /* ACB */
3805 cam->params.colourBalance.redGain = 32;
3806 cam->params.colourBalance.greenGain = 6;
3807 cam->params.colourBalance.blueGain = 92;
3808 cam->params.apcor.gain1 = 0x18;
3809 cam->params.apcor.gain2 = 0x16;
3810 cam->params.apcor.gain4 = 0x24;
3811 cam->params.apcor.gain8 = 0x34;
3812 cam->params.flickerControl.flickerMode = 0;
3813 cam->params.flickerControl.disabled = 1;
3814
3815 cam->params.flickerControl.coarseJump =
3816 flicker_jumps[cam->mainsFreq]
3817 [cam->params.sensorFps.baserate]
3818 [cam->params.sensorFps.divisor];
3819 cam->params.flickerControl.allowableOverExposure =
3820 -find_over_exposure(cam->params.colourParams.brightness);
3821 cam->params.vlOffset.gain1 = 20;
3822 cam->params.vlOffset.gain2 = 24;
3823 cam->params.vlOffset.gain4 = 26;
3824 cam->params.vlOffset.gain8 = 26;
3825 cam->params.compressionParams.hysteresis = 3;
3826 cam->params.compressionParams.threshMax = 11;
3827 cam->params.compressionParams.smallStep = 1;
3828 cam->params.compressionParams.largeStep = 3;
3829 cam->params.compressionParams.decimationHysteresis = 2;
3830 cam->params.compressionParams.frDiffStepThresh = 5;
3831 cam->params.compressionParams.qDiffStepThresh = 3;
3832 cam->params.compressionParams.decimationThreshMod = 2;
3833 /* End of default values from Software Developer's Guide */
3834
3835 cam->transfer_rate = 0;
3836 cam->exposure_status = EXPOSURE_NORMAL;
3837
3838 /* Set Sensor FPS to 15fps. This seems better than 30fps
3839 * for indoor lighting. */
3840 cam->params.sensorFps.divisor = 1;
3841 cam->params.sensorFps.baserate = 1;
3842
3843 cam->params.yuvThreshold.yThreshold = 6; /* From windows driver */
3844 cam->params.yuvThreshold.uvThreshold = 6; /* From windows driver */
3845
3846 cam->params.format.subSample = SUBSAMPLE_422;
3847 cam->params.format.yuvOrder = YUVORDER_YUYV;
3848
3849 cam->params.compression.mode = CPIA_COMPRESSION_AUTO;
3850 cam->params.compressionTarget.frTargeting =
3851 CPIA_COMPRESSION_TARGET_QUALITY;
3852 cam->params.compressionTarget.targetFR = 15; /* From windows driver */
3853 cam->params.compressionTarget.targetQ = 5; /* From windows driver */
3854
3855 cam->params.qx3.qx3_detected = 0;
3856 cam->params.qx3.toplight = 0;
3857 cam->params.qx3.bottomlight = 0;
3858 cam->params.qx3.button = 0;
3859 cam->params.qx3.cradled = 0;
3860
3861 cam->video_size = VIDEOSIZE_CIF;
3862
3863 cam->vp.colour = 32768; /* 50% */
3864 cam->vp.hue = 32768; /* 50% */
3865 cam->vp.brightness = 32768; /* 50% */
3866 cam->vp.contrast = 32768; /* 50% */
3867 cam->vp.whiteness = 0; /* not used -> grayscale only */
3868 cam->vp.depth = 24; /* to be set by user */
3869 cam->vp.palette = VIDEO_PALETTE_RGB24; /* to be set by user */
3870
3871 cam->vc.x = 0;
3872 cam->vc.y = 0;
3873 cam->vc.width = 0;
3874 cam->vc.height = 0;
3875
3876 cam->vw.x = 0;
3877 cam->vw.y = 0;
3878 set_vw_size(cam);
3879 cam->vw.chromakey = 0;
3880 cam->vw.flags = 0;
3881 cam->vw.clipcount = 0;
3882 cam->vw.clips = NULL;
3883
3884 cam->cmd_queue = COMMAND_NONE;
3885 cam->first_frame = 1;
3886
3887 return;
3888}
3889
3890/* initialize cam_data structure */
3891static void init_camera_struct(struct cam_data *cam,
3892 struct cpia_camera_ops *ops )
3893{
3894 int i;
3895
3896 /* Default everything to 0 */
3897 memset(cam, 0, sizeof(struct cam_data));
3898
3899 cam->ops = ops;
3900 mutex_init(&cam->param_lock);
3901 mutex_init(&cam->busy_lock);
3902
3903 reset_camera_struct(cam);
3904
3905 cam->proc_entry = NULL;
3906
3907 memcpy(&cam->vdev, &cpia_template, sizeof(cpia_template));
3908 video_set_drvdata(&cam->vdev, cam);
3909
3910 cam->curframe = 0;
3911 for (i = 0; i < FRAME_NUM; i++) {
3912 cam->frame[i].width = 0;
3913 cam->frame[i].height = 0;
3914 cam->frame[i].state = FRAME_UNUSED;
3915 cam->frame[i].data = NULL;
3916 }
3917 cam->decompressed_frame.width = 0;
3918 cam->decompressed_frame.height = 0;
3919 cam->decompressed_frame.state = FRAME_UNUSED;
3920 cam->decompressed_frame.data = NULL;
3921}
3922
3923struct cam_data *cpia_register_camera(struct cpia_camera_ops *ops, void *lowlevel)
3924{
3925 struct cam_data *camera;
3926
3927 if ((camera = kmalloc(sizeof(struct cam_data), GFP_KERNEL)) == NULL)
3928 return NULL;
3929
3930
3931 init_camera_struct( camera, ops );
3932 camera->lowlevel_data = lowlevel;
3933
3934 /* register v4l device */
3935 if (video_register_device(&camera->vdev, VFL_TYPE_GRABBER, video_nr) < 0) {
3936 kfree(camera);
3937 printk(KERN_DEBUG "video_register_device failed\n");
3938 return NULL;
3939 }
3940
3941 /* get version information from camera: open/reset/close */
3942
3943 /* open cpia */
3944 if (camera->ops->open(camera->lowlevel_data))
3945 return camera;
3946
3947 /* reset the camera */
3948 if (reset_camera(camera) != 0) {
3949 camera->ops->close(camera->lowlevel_data);
3950 return camera;
3951 }
3952
3953 /* close cpia */
3954 camera->ops->close(camera->lowlevel_data);
3955
3956#ifdef CONFIG_PROC_FS
3957 create_proc_cpia_cam(camera);
3958#endif
3959
3960 printk(KERN_INFO " CPiA Version: %d.%02d (%d.%d)\n",
3961 camera->params.version.firmwareVersion,
3962 camera->params.version.firmwareRevision,
3963 camera->params.version.vcVersion,
3964 camera->params.version.vcRevision);
3965 printk(KERN_INFO " CPiA PnP-ID: %04x:%04x:%04x\n",
3966 camera->params.pnpID.vendor,
3967 camera->params.pnpID.product,
3968 camera->params.pnpID.deviceRevision);
3969 printk(KERN_INFO " VP-Version: %d.%d %04x\n",
3970 camera->params.vpVersion.vpVersion,
3971 camera->params.vpVersion.vpRevision,
3972 camera->params.vpVersion.cameraHeadID);
3973
3974 return camera;
3975}
3976
3977void cpia_unregister_camera(struct cam_data *cam)
3978{
3979 DBG("unregistering video\n");
3980 video_unregister_device(&cam->vdev);
3981 if (cam->open_count) {
3982 put_cam(cam->ops);
3983 DBG("camera open -- setting ops to NULL\n");
3984 cam->ops = NULL;
3985 }
3986
3987#ifdef CONFIG_PROC_FS
3988 DBG("destroying /proc/cpia/%s\n", video_device_node_name(&cam->vdev));
3989 destroy_proc_cpia_cam(cam);
3990#endif
3991 if (!cam->open_count) {
3992 DBG("freeing camera\n");
3993 kfree(cam);
3994 }
3995}
3996
3997static int __init cpia_init(void)
3998{
3999 printk(KERN_INFO "%s v%d.%d.%d\n", ABOUT,
4000 CPIA_MAJ_VER, CPIA_MIN_VER, CPIA_PATCH_VER);
4001
4002 printk(KERN_WARNING "Since in-kernel colorspace conversion is not "
4003 "allowed, it is disabled by default now. Users should fix the "
4004 "applications in case they don't work without conversion "
4005 "reenabled by setting the 'colorspace_conv' module "
4006 "parameter to 1\n");
4007
4008#ifdef CONFIG_PROC_FS
4009 proc_cpia_create();
4010#endif
4011
4012 return 0;
4013}
4014
4015static void __exit cpia_exit(void)
4016{
4017#ifdef CONFIG_PROC_FS
4018 proc_cpia_destroy();
4019#endif
4020}
4021
4022module_init(cpia_init);
4023module_exit(cpia_exit);
4024
4025/* Exported symbols for modules. */
4026
4027EXPORT_SYMBOL(cpia_register_camera);
4028EXPORT_SYMBOL(cpia_unregister_camera);
diff --git a/drivers/staging/cpia/cpia.h b/drivers/staging/cpia/cpia.h
deleted file mode 100644
index 8f0cfee4b8a1..000000000000
--- a/drivers/staging/cpia/cpia.h
+++ /dev/null
@@ -1,432 +0,0 @@
1#ifndef cpia_h
2#define cpia_h
3
4/*
5 * CPiA Parallel Port Video4Linux driver
6 *
7 * Supports CPiA based parallel port Video Camera's.
8 *
9 * (C) Copyright 1999 Bas Huisman,
10 * Peter Pregler,
11 * Scott J. Bertin,
12 * VLSI Vision Ltd.
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 */
28
29#define CPIA_MAJ_VER 1
30#define CPIA_MIN_VER 2
31#define CPIA_PATCH_VER 3
32
33#define CPIA_PP_MAJ_VER CPIA_MAJ_VER
34#define CPIA_PP_MIN_VER CPIA_MIN_VER
35#define CPIA_PP_PATCH_VER CPIA_PATCH_VER
36
37#define CPIA_USB_MAJ_VER CPIA_MAJ_VER
38#define CPIA_USB_MIN_VER CPIA_MIN_VER
39#define CPIA_USB_PATCH_VER CPIA_PATCH_VER
40
41#define CPIA_MAX_FRAME_SIZE_UNALIGNED (352 * 288 * 4) /* CIF at RGB32 */
42#define CPIA_MAX_FRAME_SIZE ((CPIA_MAX_FRAME_SIZE_UNALIGNED + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1)) /* align above to PAGE_SIZE */
43
44#ifdef __KERNEL__
45
46#include <asm/uaccess.h>
47#include <linux/videodev.h>
48#include <media/v4l2-common.h>
49#include <media/v4l2-ioctl.h>
50#include <linux/list.h>
51#include <linux/mutex.h>
52
53struct cpia_camera_ops
54{
55 /* open sets privdata to point to structure for this camera.
56 * Returns negative value on error, otherwise 0.
57 */
58 int (*open)(void *privdata);
59
60 /* Registers callback function cb to be called with cbdata
61 * when an image is ready. If cb is NULL, only single image grabs
62 * should be used. cb should immediately call streamRead to read
63 * the data or data may be lost. Returns negative value on error,
64 * otherwise 0.
65 */
66 int (*registerCallback)(void *privdata, void (*cb)(void *cbdata),
67 void *cbdata);
68
69 /* transferCmd sends commands to the camera. command MUST point to
70 * an 8 byte buffer in kernel space. data can be NULL if no extra
71 * data is needed. The size of the data is given by the last 2
72 * bytes of command. data must also point to memory in kernel space.
73 * Returns negative value on error, otherwise 0.
74 */
75 int (*transferCmd)(void *privdata, u8 *command, u8 *data);
76
77 /* streamStart initiates stream capture mode.
78 * Returns negative value on error, otherwise 0.
79 */
80 int (*streamStart)(void *privdata);
81
82 /* streamStop terminates stream capture mode.
83 * Returns negative value on error, otherwise 0.
84 */
85 int (*streamStop)(void *privdata);
86
87 /* streamRead reads a frame from the camera. buffer points to a
88 * buffer large enough to hold a complete frame in kernel space.
89 * noblock indicates if this should be a non blocking read.
90 * Returns the number of bytes read, or negative value on error.
91 */
92 int (*streamRead)(void *privdata, u8 *buffer, int noblock);
93
94 /* close disables the device until open() is called again.
95 * Returns negative value on error, otherwise 0.
96 */
97 int (*close)(void *privdata);
98
99 /* If wait_for_stream_ready is non-zero, wait until the streamState
100 * is STREAM_READY before calling streamRead.
101 */
102 int wait_for_stream_ready;
103
104 /*
105 * Used to maintain lowlevel module usage counts
106 */
107 struct module *owner;
108};
109
110struct cpia_frame {
111 u8 *data;
112 int count;
113 int width;
114 int height;
115 volatile int state;
116};
117
118struct cam_params {
119 struct {
120 u8 firmwareVersion;
121 u8 firmwareRevision;
122 u8 vcVersion;
123 u8 vcRevision;
124 } version;
125 struct {
126 u16 vendor;
127 u16 product;
128 u16 deviceRevision;
129 } pnpID;
130 struct {
131 u8 vpVersion;
132 u8 vpRevision;
133 u16 cameraHeadID;
134 } vpVersion;
135 struct {
136 u8 systemState;
137 u8 grabState;
138 u8 streamState;
139 u8 fatalError;
140 u8 cmdError;
141 u8 debugFlags;
142 u8 vpStatus;
143 u8 errorCode;
144 } status;
145 struct {
146 u8 brightness;
147 u8 contrast;
148 u8 saturation;
149 } colourParams;
150 struct {
151 u8 gainMode;
152 u8 expMode;
153 u8 compMode;
154 u8 centreWeight;
155 u8 gain;
156 u8 fineExp;
157 u8 coarseExpLo;
158 u8 coarseExpHi;
159 u8 redComp;
160 u8 green1Comp;
161 u8 green2Comp;
162 u8 blueComp;
163 } exposure;
164 struct {
165 u8 balanceMode;
166 u8 redGain;
167 u8 greenGain;
168 u8 blueGain;
169 } colourBalance;
170 struct {
171 u8 divisor;
172 u8 baserate;
173 } sensorFps;
174 struct {
175 u8 gain1;
176 u8 gain2;
177 u8 gain4;
178 u8 gain8;
179 } apcor;
180 struct {
181 u8 disabled;
182 u8 flickerMode;
183 u8 coarseJump;
184 int allowableOverExposure;
185 } flickerControl;
186 struct {
187 u8 gain1;
188 u8 gain2;
189 u8 gain4;
190 u8 gain8;
191 } vlOffset;
192 struct {
193 u8 mode;
194 u8 decimation;
195 } compression;
196 struct {
197 u8 frTargeting;
198 u8 targetFR;
199 u8 targetQ;
200 } compressionTarget;
201 struct {
202 u8 yThreshold;
203 u8 uvThreshold;
204 } yuvThreshold;
205 struct {
206 u8 hysteresis;
207 u8 threshMax;
208 u8 smallStep;
209 u8 largeStep;
210 u8 decimationHysteresis;
211 u8 frDiffStepThresh;
212 u8 qDiffStepThresh;
213 u8 decimationThreshMod;
214 } compressionParams;
215 struct {
216 u8 videoSize; /* CIF/QCIF */
217 u8 subSample;
218 u8 yuvOrder;
219 } format;
220 struct { /* Intel QX3 specific data */
221 u8 qx3_detected; /* a QX3 is present */
222 u8 toplight; /* top light lit , R/W */
223 u8 bottomlight; /* bottom light lit, R/W */
224 u8 button; /* snapshot button pressed (R/O) */
225 u8 cradled; /* microscope is in cradle (R/O) */
226 } qx3;
227 struct {
228 u8 colStart; /* skip first 8*colStart pixels */
229 u8 colEnd; /* finish at 8*colEnd pixels */
230 u8 rowStart; /* skip first 4*rowStart lines */
231 u8 rowEnd; /* finish at 4*rowEnd lines */
232 } roi;
233 u8 ecpTiming;
234 u8 streamStartLine;
235};
236
237enum v4l_camstates {
238 CPIA_V4L_IDLE = 0,
239 CPIA_V4L_ERROR,
240 CPIA_V4L_COMMAND,
241 CPIA_V4L_GRABBING,
242 CPIA_V4L_STREAMING,
243 CPIA_V4L_STREAMING_PAUSED,
244};
245
246#define FRAME_NUM 2 /* double buffering for now */
247
248struct cam_data {
249 struct list_head cam_data_list;
250
251 struct mutex busy_lock; /* guard against SMP multithreading */
252 struct cpia_camera_ops *ops; /* lowlevel driver operations */
253 void *lowlevel_data; /* private data for lowlevel driver */
254 u8 *raw_image; /* buffer for raw image data */
255 struct cpia_frame decompressed_frame;
256 /* buffer to hold decompressed frame */
257 int image_size; /* sizeof last decompressed image */
258 int open_count; /* # of process that have camera open */
259
260 /* camera status */
261 int fps; /* actual fps reported by the camera */
262 int transfer_rate; /* transfer rate from camera in kB/s */
263 u8 mainsFreq; /* for flicker control */
264
265 /* proc interface */
266 struct mutex param_lock; /* params lock for this camera */
267 struct cam_params params; /* camera settings */
268 struct proc_dir_entry *proc_entry; /* /proc/cpia/videoX */
269
270 /* v4l */
271 int video_size; /* VIDEO_SIZE_ */
272 volatile enum v4l_camstates camstate; /* v4l layer status */
273 struct video_device vdev; /* v4l videodev */
274 struct video_picture vp; /* v4l camera settings */
275 struct video_window vw; /* v4l capture area */
276 struct video_capture vc; /* v4l subcapture area */
277
278 /* mmap interface */
279 int curframe; /* the current frame to grab into */
280 u8 *frame_buf; /* frame buffer data */
281 struct cpia_frame frame[FRAME_NUM];
282 /* FRAME_NUM-buffering, so we need a array */
283
284 int first_frame;
285 int mmap_kludge; /* 'wrong' byte order for mmap */
286 volatile u32 cmd_queue; /* queued commands */
287 int exposure_status; /* EXPOSURE_* */
288 int exposure_count; /* number of frames at this status */
289};
290
291/* cpia_register_camera is called by low level driver for each camera.
292 * A unique camera number is returned, or a negative value on error */
293struct cam_data *cpia_register_camera(struct cpia_camera_ops *ops, void *lowlevel);
294
295/* cpia_unregister_camera is called by low level driver when a camera
296 * is removed. This must not fail. */
297void cpia_unregister_camera(struct cam_data *cam);
298
299/* raw CIF + 64 byte header + (2 bytes line_length + EOL) per line + 4*EOI +
300 * one byte 16bit DMA alignment
301 */
302#define CPIA_MAX_IMAGE_SIZE ((352*288*2)+64+(288*3)+5)
303
304/* constant value's */
305#define MAGIC_0 0x19
306#define MAGIC_1 0x68
307#define DATA_IN 0xC0
308#define DATA_OUT 0x40
309#define VIDEOSIZE_QCIF 0 /* 176x144 */
310#define VIDEOSIZE_CIF 1 /* 352x288 */
311#define VIDEOSIZE_SIF 2 /* 320x240 */
312#define VIDEOSIZE_QSIF 3 /* 160x120 */
313#define VIDEOSIZE_48_48 4 /* where no one has gone before, iconsize! */
314#define VIDEOSIZE_64_48 5
315#define VIDEOSIZE_128_96 6
316#define VIDEOSIZE_160_120 VIDEOSIZE_QSIF
317#define VIDEOSIZE_176_144 VIDEOSIZE_QCIF
318#define VIDEOSIZE_192_144 7
319#define VIDEOSIZE_224_168 8
320#define VIDEOSIZE_256_192 9
321#define VIDEOSIZE_288_216 10
322#define VIDEOSIZE_320_240 VIDEOSIZE_SIF
323#define VIDEOSIZE_352_288 VIDEOSIZE_CIF
324#define VIDEOSIZE_88_72 11 /* quarter CIF */
325#define SUBSAMPLE_420 0
326#define SUBSAMPLE_422 1
327#define YUVORDER_YUYV 0
328#define YUVORDER_UYVY 1
329#define NOT_COMPRESSED 0
330#define COMPRESSED 1
331#define NO_DECIMATION 0
332#define DECIMATION_ENAB 1
333#define EOI 0xff /* End Of Image */
334#define EOL 0xfd /* End Of Line */
335#define FRAME_HEADER_SIZE 64
336
337/* Image grab modes */
338#define CPIA_GRAB_SINGLE 0
339#define CPIA_GRAB_CONTINUOUS 1
340
341/* Compression parameters */
342#define CPIA_COMPRESSION_NONE 0
343#define CPIA_COMPRESSION_AUTO 1
344#define CPIA_COMPRESSION_MANUAL 2
345#define CPIA_COMPRESSION_TARGET_QUALITY 0
346#define CPIA_COMPRESSION_TARGET_FRAMERATE 1
347
348/* Return offsets for GetCameraState */
349#define SYSTEMSTATE 0
350#define GRABSTATE 1
351#define STREAMSTATE 2
352#define FATALERROR 3
353#define CMDERROR 4
354#define DEBUGFLAGS 5
355#define VPSTATUS 6
356#define ERRORCODE 7
357
358/* SystemState */
359#define UNINITIALISED_STATE 0
360#define PASS_THROUGH_STATE 1
361#define LO_POWER_STATE 2
362#define HI_POWER_STATE 3
363#define WARM_BOOT_STATE 4
364
365/* GrabState */
366#define GRAB_IDLE 0
367#define GRAB_ACTIVE 1
368#define GRAB_DONE 2
369
370/* StreamState */
371#define STREAM_NOT_READY 0
372#define STREAM_READY 1
373#define STREAM_OPEN 2
374#define STREAM_PAUSED 3
375#define STREAM_FINISHED 4
376
377/* Fatal Error, CmdError, and DebugFlags */
378#define CPIA_FLAG 1
379#define SYSTEM_FLAG 2
380#define INT_CTRL_FLAG 4
381#define PROCESS_FLAG 8
382#define COM_FLAG 16
383#define VP_CTRL_FLAG 32
384#define CAPTURE_FLAG 64
385#define DEBUG_FLAG 128
386
387/* VPStatus */
388#define VP_STATE_OK 0x00
389
390#define VP_STATE_FAILED_VIDEOINIT 0x01
391#define VP_STATE_FAILED_AECACBINIT 0x02
392#define VP_STATE_AEC_MAX 0x04
393#define VP_STATE_ACB_BMAX 0x08
394
395#define VP_STATE_ACB_RMIN 0x10
396#define VP_STATE_ACB_GMIN 0x20
397#define VP_STATE_ACB_RMAX 0x40
398#define VP_STATE_ACB_GMAX 0x80
399
400/* default (minimum) compensation values */
401#define COMP_RED 220
402#define COMP_GREEN1 214
403#define COMP_GREEN2 COMP_GREEN1
404#define COMP_BLUE 230
405
406/* exposure status */
407#define EXPOSURE_VERY_LIGHT 0
408#define EXPOSURE_LIGHT 1
409#define EXPOSURE_NORMAL 2
410#define EXPOSURE_DARK 3
411#define EXPOSURE_VERY_DARK 4
412
413/* ErrorCode */
414#define ERROR_FLICKER_BELOW_MIN_EXP 0x01 /*flicker exposure got below minimum exposure */
415#define ALOG(fmt,args...) printk(fmt, ##args)
416#define LOG(fmt,args...) ALOG(KERN_INFO __FILE__ ":%s(%d):" fmt, __func__ , __LINE__ , ##args)
417
418#ifdef _CPIA_DEBUG_
419#define ADBG(fmt,args...) printk(fmt, jiffies, ##args)
420#define DBG(fmt,args...) ADBG(KERN_DEBUG __FILE__" (%ld):%s(%d):" fmt, __func__, __LINE__ , ##args)
421#else
422#define DBG(fmn,args...) do {} while(0)
423#endif
424
425#define DEB_BYTE(p)\
426 DBG("%1d %1d %1d %1d %1d %1d %1d %1d \n",\
427 (p)&0x80?1:0, (p)&0x40?1:0, (p)&0x20?1:0, (p)&0x10?1:0,\
428 (p)&0x08?1:0, (p)&0x04?1:0, (p)&0x02?1:0, (p)&0x01?1:0);
429
430#endif /* __KERNEL__ */
431
432#endif /* cpia_h */
diff --git a/drivers/staging/cpia/cpia_pp.c b/drivers/staging/cpia/cpia_pp.c
deleted file mode 100644
index f5604c16a092..000000000000
--- a/drivers/staging/cpia/cpia_pp.c
+++ /dev/null
@@ -1,869 +0,0 @@
1/*
2 * cpia_pp CPiA Parallel Port driver
3 *
4 * Supports CPiA based parallel port Video Camera's.
5 *
6 * (C) Copyright 1999 Bas Huisman <bhuism@cs.utwente.nl>
7 * (C) Copyright 1999-2000 Scott J. Bertin <sbertin@securenym.net>,
8 * (C) Copyright 1999-2000 Peter Pregler <Peter_Pregler@email.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24
25/* define _CPIA_DEBUG_ for verbose debug output (see cpia.h) */
26/* #define _CPIA_DEBUG_ 1 */
27
28
29#include <linux/module.h>
30#include <linux/init.h>
31
32#include <linux/kernel.h>
33#include <linux/parport.h>
34#include <linux/interrupt.h>
35#include <linux/delay.h>
36#include <linux/workqueue.h>
37#include <linux/sched.h>
38#include <linux/slab.h>
39
40#include <linux/kmod.h>
41
42/* #define _CPIA_DEBUG_ define for verbose debug output */
43#include "cpia.h"
44
45static int cpia_pp_open(void *privdata);
46static int cpia_pp_registerCallback(void *privdata, void (*cb) (void *cbdata),
47 void *cbdata);
48static int cpia_pp_transferCmd(void *privdata, u8 *command, u8 *data);
49static int cpia_pp_streamStart(void *privdata);
50static int cpia_pp_streamStop(void *privdata);
51static int cpia_pp_streamRead(void *privdata, u8 *buffer, int noblock);
52static int cpia_pp_close(void *privdata);
53
54
55#define ABOUT "Parallel port driver for Vision CPiA based cameras"
56
57#define PACKET_LENGTH 8
58
59/* Magic numbers for defining port-device mappings */
60#define PPCPIA_PARPORT_UNSPEC -4
61#define PPCPIA_PARPORT_AUTO -3
62#define PPCPIA_PARPORT_OFF -2
63#define PPCPIA_PARPORT_NONE -1
64
65static int parport_nr[PARPORT_MAX] = {[0 ... PARPORT_MAX - 1] = PPCPIA_PARPORT_UNSPEC};
66static char *parport[PARPORT_MAX] = {NULL,};
67
68MODULE_AUTHOR("B. Huisman <bhuism@cs.utwente.nl> & Peter Pregler <Peter_Pregler@email.com>");
69MODULE_DESCRIPTION("Parallel port driver for Vision CPiA based cameras");
70MODULE_LICENSE("GPL");
71
72module_param_array(parport, charp, NULL, 0);
73MODULE_PARM_DESC(parport, "'auto' or a list of parallel port numbers. Just like lp.");
74
75struct pp_cam_entry {
76 struct pardevice *pdev;
77 struct parport *port;
78 struct work_struct cb_task;
79 void (*cb_func)(void *cbdata);
80 void *cb_data;
81 int open_count;
82 wait_queue_head_t wq_stream;
83 /* image state flags */
84 int image_ready; /* we got an interrupt */
85 int image_complete; /* we have seen 4 EOI */
86
87 int streaming; /* we are in streaming mode */
88 int stream_irq;
89};
90
91static struct cpia_camera_ops cpia_pp_ops =
92{
93 cpia_pp_open,
94 cpia_pp_registerCallback,
95 cpia_pp_transferCmd,
96 cpia_pp_streamStart,
97 cpia_pp_streamStop,
98 cpia_pp_streamRead,
99 cpia_pp_close,
100 1,
101 THIS_MODULE
102};
103
104static LIST_HEAD(cam_list);
105static spinlock_t cam_list_lock_pp;
106
107/* FIXME */
108static void cpia_parport_enable_irq( struct parport *port ) {
109 parport_enable_irq(port);
110 mdelay(10);
111 return;
112}
113
114static void cpia_parport_disable_irq( struct parport *port ) {
115 parport_disable_irq(port);
116 mdelay(10);
117 return;
118}
119
120/* Special CPiA PPC modes: These are invoked by using the 1284 Extensibility
121 * Link Flag during negotiation */
122#define UPLOAD_FLAG 0x08
123#define NIBBLE_TRANSFER 0x01
124#define ECP_TRANSFER 0x03
125
126#define PARPORT_CHUNK_SIZE PAGE_SIZE
127
128
129static void cpia_pp_run_callback(struct work_struct *work)
130{
131 void (*cb_func)(void *cbdata);
132 void *cb_data;
133 struct pp_cam_entry *cam;
134
135 cam = container_of(work, struct pp_cam_entry, cb_task);
136 cb_func = cam->cb_func;
137 cb_data = cam->cb_data;
138
139 cb_func(cb_data);
140}
141
142/****************************************************************************
143 *
144 * CPiA-specific low-level parport functions for nibble uploads
145 *
146 ***************************************************************************/
147/* CPiA nonstandard "Nibble" mode (no nDataAvail signal after each byte). */
148/* The standard kernel parport_ieee1284_read_nibble() fails with the CPiA... */
149
150static size_t cpia_read_nibble (struct parport *port,
151 void *buffer, size_t len,
152 int flags)
153{
154 /* adapted verbatim, with one change, from
155 parport_ieee1284_read_nibble() in drivers/parport/ieee1284-ops.c */
156
157 unsigned char *buf = buffer;
158 int i;
159 unsigned char byte = 0;
160
161 len *= 2; /* in nibbles */
162 for (i=0; i < len; i++) {
163 unsigned char nibble;
164
165 /* The CPiA firmware suppresses the use of nDataAvail (nFault LO)
166 * after every second nibble to signal that more
167 * data is available. (the total number of Bytes that
168 * should be sent is known; if too few are received, an error
169 * will be recorded after a timeout).
170 * This is incompatible with parport_ieee1284_read_nibble(),
171 * which expects to find nFault LO after every second nibble.
172 */
173
174 /* Solution: modify cpia_read_nibble to only check for
175 * nDataAvail before the first nibble is sent.
176 */
177
178 /* Does the error line indicate end of data? */
179 if (((i /*& 1*/) == 0) &&
180 (parport_read_status(port) & PARPORT_STATUS_ERROR)) {
181 DBG("%s: No more nibble data (%d bytes)\n",
182 port->name, i/2);
183 goto end_of_data;
184 }
185
186 /* Event 7: Set nAutoFd low. */
187 parport_frob_control (port,
188 PARPORT_CONTROL_AUTOFD,
189 PARPORT_CONTROL_AUTOFD);
190
191 /* Event 9: nAck goes low. */
192 port->ieee1284.phase = IEEE1284_PH_REV_DATA;
193 if (parport_wait_peripheral (port,
194 PARPORT_STATUS_ACK, 0)) {
195 /* Timeout -- no more data? */
196 DBG("%s: Nibble timeout at event 9 (%d bytes)\n",
197 port->name, i/2);
198 parport_frob_control (port, PARPORT_CONTROL_AUTOFD, 0);
199 break;
200 }
201
202
203 /* Read a nibble. */
204 nibble = parport_read_status (port) >> 3;
205 nibble &= ~8;
206 if ((nibble & 0x10) == 0)
207 nibble |= 8;
208 nibble &= 0xf;
209
210 /* Event 10: Set nAutoFd high. */
211 parport_frob_control (port, PARPORT_CONTROL_AUTOFD, 0);
212
213 /* Event 11: nAck goes high. */
214 if (parport_wait_peripheral (port,
215 PARPORT_STATUS_ACK,
216 PARPORT_STATUS_ACK)) {
217 /* Timeout -- no more data? */
218 DBG("%s: Nibble timeout at event 11\n",
219 port->name);
220 break;
221 }
222
223 if (i & 1) {
224 /* Second nibble */
225 byte |= nibble << 4;
226 *buf++ = byte;
227 } else
228 byte = nibble;
229 }
230
231 if (i == len) {
232 /* Read the last nibble without checking data avail. */
233 if (parport_read_status (port) & PARPORT_STATUS_ERROR) {
234 end_of_data:
235 /* Go to reverse idle phase. */
236 parport_frob_control (port,
237 PARPORT_CONTROL_AUTOFD,
238 PARPORT_CONTROL_AUTOFD);
239 port->physport->ieee1284.phase = IEEE1284_PH_REV_IDLE;
240 }
241 else
242 port->physport->ieee1284.phase = IEEE1284_PH_HBUSY_DAVAIL;
243 }
244
245 return i/2;
246}
247
248/* CPiA nonstandard "Nibble Stream" mode (2 nibbles per cycle, instead of 1)
249 * (See CPiA Data sheet p. 31)
250 *
251 * "Nibble Stream" mode used by CPiA for uploads to non-ECP ports is a
252 * nonstandard variant of nibble mode which allows the same (mediocre)
253 * data flow of 8 bits per cycle as software-enabled ECP by TRISTATE-capable
254 * parallel ports, but works also for non-TRISTATE-capable ports.
255 * (Standard nibble mode only send 4 bits per cycle)
256 *
257 */
258
259static size_t cpia_read_nibble_stream(struct parport *port,
260 void *buffer, size_t len,
261 int flags)
262{
263 int i;
264 unsigned char *buf = buffer;
265 int endseen = 0;
266
267 for (i=0; i < len; i++) {
268 unsigned char nibble[2], byte = 0;
269 int j;
270
271 /* Image Data is complete when 4 consecutive EOI bytes (0xff) are seen */
272 if (endseen > 3 )
273 break;
274
275 /* Event 7: Set nAutoFd low. */
276 parport_frob_control (port,
277 PARPORT_CONTROL_AUTOFD,
278 PARPORT_CONTROL_AUTOFD);
279
280 /* Event 9: nAck goes low. */
281 port->ieee1284.phase = IEEE1284_PH_REV_DATA;
282 if (parport_wait_peripheral (port,
283 PARPORT_STATUS_ACK, 0)) {
284 /* Timeout -- no more data? */
285 DBG("%s: Nibble timeout at event 9 (%d bytes)\n",
286 port->name, i/2);
287 parport_frob_control (port, PARPORT_CONTROL_AUTOFD, 0);
288 break;
289 }
290
291 /* Read lower nibble */
292 nibble[0] = parport_read_status (port) >>3;
293
294 /* Event 10: Set nAutoFd high. */
295 parport_frob_control (port, PARPORT_CONTROL_AUTOFD, 0);
296
297 /* Event 11: nAck goes high. */
298 if (parport_wait_peripheral (port,
299 PARPORT_STATUS_ACK,
300 PARPORT_STATUS_ACK)) {
301 /* Timeout -- no more data? */
302 DBG("%s: Nibble timeout at event 11\n",
303 port->name);
304 break;
305 }
306
307 /* Read upper nibble */
308 nibble[1] = parport_read_status (port) >>3;
309
310 /* reassemble the byte */
311 for (j = 0; j < 2 ; j++ ) {
312 nibble[j] &= ~8;
313 if ((nibble[j] & 0x10) == 0)
314 nibble[j] |= 8;
315 nibble[j] &= 0xf;
316 }
317 byte = (nibble[0] |(nibble[1] << 4));
318 *buf++ = byte;
319
320 if(byte == EOI)
321 endseen++;
322 else
323 endseen = 0;
324 }
325 return i;
326}
327
328/****************************************************************************
329 *
330 * EndTransferMode
331 *
332 ***************************************************************************/
333static void EndTransferMode(struct pp_cam_entry *cam)
334{
335 parport_negotiate(cam->port, IEEE1284_MODE_COMPAT);
336}
337
338/****************************************************************************
339 *
340 * ForwardSetup
341 *
342 ***************************************************************************/
343static int ForwardSetup(struct pp_cam_entry *cam)
344{
345 int retry;
346
347 /* The CPiA uses ECP protocol for Downloads from the Host to the camera.
348 * This will be software-emulated if ECP hardware is not present
349 */
350
351 /* the usual camera maximum response time is 10ms, but after receiving
352 * some commands, it needs up to 40ms. (Data Sheet p. 32)*/
353
354 for(retry = 0; retry < 4; ++retry) {
355 if(!parport_negotiate(cam->port, IEEE1284_MODE_ECP)) {
356 break;
357 }
358 mdelay(10);
359 }
360 if(retry == 4) {
361 DBG("Unable to negotiate IEEE1284 ECP Download mode\n");
362 return -1;
363 }
364 return 0;
365}
366/****************************************************************************
367 *
368 * ReverseSetup
369 *
370 ***************************************************************************/
371static int ReverseSetup(struct pp_cam_entry *cam, int extensibility)
372{
373 int retry;
374 int upload_mode, mode = IEEE1284_MODE_ECP;
375 int transfer_mode = ECP_TRANSFER;
376
377 if (!(cam->port->modes & PARPORT_MODE_ECP) &&
378 !(cam->port->modes & PARPORT_MODE_TRISTATE)) {
379 mode = IEEE1284_MODE_NIBBLE;
380 transfer_mode = NIBBLE_TRANSFER;
381 }
382
383 upload_mode = mode;
384 if(extensibility) mode = UPLOAD_FLAG|transfer_mode|IEEE1284_EXT_LINK;
385
386 /* the usual camera maximum response time is 10ms, but after
387 * receiving some commands, it needs up to 40ms. */
388
389 for(retry = 0; retry < 4; ++retry) {
390 if(!parport_negotiate(cam->port, mode)) {
391 break;
392 }
393 mdelay(10);
394 }
395 if(retry == 4) {
396 if(extensibility)
397 DBG("Unable to negotiate upload extensibility mode\n");
398 else
399 DBG("Unable to negotiate upload mode\n");
400 return -1;
401 }
402 if(extensibility) cam->port->ieee1284.mode = upload_mode;
403 return 0;
404}
405
406/****************************************************************************
407 *
408 * WritePacket
409 *
410 ***************************************************************************/
411static int WritePacket(struct pp_cam_entry *cam, const u8 *packet, size_t size)
412{
413 int retval=0;
414 int size_written;
415
416 if (packet == NULL) {
417 return -EINVAL;
418 }
419 if (ForwardSetup(cam)) {
420 DBG("Write failed in setup\n");
421 return -EIO;
422 }
423 size_written = parport_write(cam->port, packet, size);
424 if(size_written != size) {
425 DBG("Write failed, wrote %d/%d\n", size_written, size);
426 retval = -EIO;
427 }
428 EndTransferMode(cam);
429 return retval;
430}
431
432/****************************************************************************
433 *
434 * ReadPacket
435 *
436 ***************************************************************************/
437static int ReadPacket(struct pp_cam_entry *cam, u8 *packet, size_t size)
438{
439 int retval=0;
440
441 if (packet == NULL) {
442 return -EINVAL;
443 }
444 if (ReverseSetup(cam, 0)) {
445 return -EIO;
446 }
447
448 /* support for CPiA variant nibble reads */
449 if(cam->port->ieee1284.mode == IEEE1284_MODE_NIBBLE) {
450 if(cpia_read_nibble(cam->port, packet, size, 0) != size)
451 retval = -EIO;
452 } else {
453 if(parport_read(cam->port, packet, size) != size)
454 retval = -EIO;
455 }
456 EndTransferMode(cam);
457 return retval;
458}
459
460/****************************************************************************
461 *
462 * cpia_pp_streamStart
463 *
464 ***************************************************************************/
465static int cpia_pp_streamStart(void *privdata)
466{
467 struct pp_cam_entry *cam = privdata;
468 DBG("\n");
469 cam->streaming=1;
470 cam->image_ready=0;
471 //if (ReverseSetup(cam,1)) return -EIO;
472 if(cam->stream_irq) cpia_parport_enable_irq(cam->port);
473 return 0;
474}
475
476/****************************************************************************
477 *
478 * cpia_pp_streamStop
479 *
480 ***************************************************************************/
481static int cpia_pp_streamStop(void *privdata)
482{
483 struct pp_cam_entry *cam = privdata;
484
485 DBG("\n");
486 cam->streaming=0;
487 cpia_parport_disable_irq(cam->port);
488 //EndTransferMode(cam);
489
490 return 0;
491}
492
493/****************************************************************************
494 *
495 * cpia_pp_streamRead
496 *
497 ***************************************************************************/
498static int cpia_pp_read(struct parport *port, u8 *buffer, int len)
499{
500 int bytes_read;
501
502 /* support for CPiA variant "nibble stream" reads */
503 if(port->ieee1284.mode == IEEE1284_MODE_NIBBLE)
504 bytes_read = cpia_read_nibble_stream(port,buffer,len,0);
505 else {
506 int new_bytes;
507 for(bytes_read=0; bytes_read<len; bytes_read += new_bytes) {
508 new_bytes = parport_read(port, buffer+bytes_read,
509 len-bytes_read);
510 if(new_bytes < 0) break;
511 }
512 }
513 return bytes_read;
514}
515
516static int cpia_pp_streamRead(void *privdata, u8 *buffer, int noblock)
517{
518 struct pp_cam_entry *cam = privdata;
519 int read_bytes = 0;
520 int i, endseen, block_size, new_bytes;
521
522 if(cam == NULL) {
523 DBG("Internal driver error: cam is NULL\n");
524 return -EINVAL;
525 }
526 if(buffer == NULL) {
527 DBG("Internal driver error: buffer is NULL\n");
528 return -EINVAL;
529 }
530 //if(cam->streaming) DBG("%d / %d\n", cam->image_ready, noblock);
531 if( cam->stream_irq ) {
532 DBG("%d\n", cam->image_ready);
533 cam->image_ready--;
534 }
535 cam->image_complete=0;
536 if (0/*cam->streaming*/) {
537 if(!cam->image_ready) {
538 if(noblock) return -EWOULDBLOCK;
539 interruptible_sleep_on(&cam->wq_stream);
540 if( signal_pending(current) ) return -EINTR;
541 DBG("%d\n", cam->image_ready);
542 }
543 } else {
544 if (ReverseSetup(cam, 1)) {
545 DBG("unable to ReverseSetup\n");
546 return -EIO;
547 }
548 }
549 endseen = 0;
550 block_size = PARPORT_CHUNK_SIZE;
551 while( !cam->image_complete ) {
552 cond_resched();
553
554 new_bytes = cpia_pp_read(cam->port, buffer, block_size );
555 if( new_bytes <= 0 ) {
556 break;
557 }
558 i=-1;
559 while(++i<new_bytes && endseen<4) {
560 if(*buffer==EOI) {
561 endseen++;
562 } else {
563 endseen=0;
564 }
565 buffer++;
566 }
567 read_bytes += i;
568 if( endseen==4 ) {
569 cam->image_complete=1;
570 break;
571 }
572 if( CPIA_MAX_IMAGE_SIZE-read_bytes <= PARPORT_CHUNK_SIZE ) {
573 block_size=CPIA_MAX_IMAGE_SIZE-read_bytes;
574 }
575 }
576 EndTransferMode(cam);
577 return cam->image_complete ? read_bytes : -EIO;
578}
579/****************************************************************************
580 *
581 * cpia_pp_transferCmd
582 *
583 ***************************************************************************/
584static int cpia_pp_transferCmd(void *privdata, u8 *command, u8 *data)
585{
586 int err;
587 int retval=0;
588 int databytes;
589 struct pp_cam_entry *cam = privdata;
590
591 if(cam == NULL) {
592 DBG("Internal driver error: cam is NULL\n");
593 return -EINVAL;
594 }
595 if(command == NULL) {
596 DBG("Internal driver error: command is NULL\n");
597 return -EINVAL;
598 }
599 databytes = (((int)command[7])<<8) | command[6];
600 if ((err = WritePacket(cam, command, PACKET_LENGTH)) < 0) {
601 DBG("Error writing command\n");
602 return err;
603 }
604 if(command[0] == DATA_IN) {
605 u8 buffer[8];
606 if(data == NULL) {
607 DBG("Internal driver error: data is NULL\n");
608 return -EINVAL;
609 }
610 if((err = ReadPacket(cam, buffer, 8)) < 0) {
611 DBG("Error reading command result\n");
612 return err;
613 }
614 memcpy(data, buffer, databytes);
615 } else if(command[0] == DATA_OUT) {
616 if(databytes > 0) {
617 if(data == NULL) {
618 DBG("Internal driver error: data is NULL\n");
619 retval = -EINVAL;
620 } else {
621 if((err=WritePacket(cam, data, databytes)) < 0){
622 DBG("Error writing command data\n");
623 return err;
624 }
625 }
626 }
627 } else {
628 DBG("Unexpected first byte of command: %x\n", command[0]);
629 retval = -EINVAL;
630 }
631 return retval;
632}
633
634/****************************************************************************
635 *
636 * cpia_pp_open
637 *
638 ***************************************************************************/
639static int cpia_pp_open(void *privdata)
640{
641 struct pp_cam_entry *cam = (struct pp_cam_entry *)privdata;
642
643 if (cam == NULL)
644 return -EINVAL;
645
646 if(cam->open_count == 0) {
647 if (parport_claim(cam->pdev)) {
648 DBG("failed to claim the port\n");
649 return -EBUSY;
650 }
651 parport_negotiate(cam->port, IEEE1284_MODE_COMPAT);
652 parport_data_forward(cam->port);
653 parport_write_control(cam->port, PARPORT_CONTROL_SELECT);
654 udelay(50);
655 parport_write_control(cam->port,
656 PARPORT_CONTROL_SELECT
657 | PARPORT_CONTROL_INIT);
658 }
659
660 ++cam->open_count;
661
662 return 0;
663}
664
665/****************************************************************************
666 *
667 * cpia_pp_registerCallback
668 *
669 ***************************************************************************/
670static int cpia_pp_registerCallback(void *privdata, void (*cb)(void *cbdata), void *cbdata)
671{
672 struct pp_cam_entry *cam = privdata;
673 int retval = 0;
674
675 if(cam->port->irq != PARPORT_IRQ_NONE) {
676 cam->cb_func = cb;
677 cam->cb_data = cbdata;
678 INIT_WORK(&cam->cb_task, cpia_pp_run_callback);
679 } else {
680 retval = -1;
681 }
682 return retval;
683}
684
685/****************************************************************************
686 *
687 * cpia_pp_close
688 *
689 ***************************************************************************/
690static int cpia_pp_close(void *privdata)
691{
692 struct pp_cam_entry *cam = privdata;
693 if (--cam->open_count == 0) {
694 parport_release(cam->pdev);
695 }
696 return 0;
697}
698
699/****************************************************************************
700 *
701 * cpia_pp_register
702 *
703 ***************************************************************************/
704static int cpia_pp_register(struct parport *port)
705{
706 struct pardevice *pdev = NULL;
707 struct pp_cam_entry *cam;
708 struct cam_data *cpia;
709
710 if (!(port->modes & PARPORT_MODE_PCSPP)) {
711 LOG("port is not supported by CPiA driver\n");
712 return -ENXIO;
713 }
714
715 cam = kzalloc(sizeof(struct pp_cam_entry), GFP_KERNEL);
716 if (cam == NULL) {
717 LOG("failed to allocate camera structure\n");
718 return -ENOMEM;
719 }
720
721 pdev = parport_register_device(port, "cpia_pp", NULL, NULL,
722 NULL, 0, cam);
723
724 if (!pdev) {
725 LOG("failed to parport_register_device\n");
726 kfree(cam);
727 return -ENXIO;
728 }
729
730 cam->pdev = pdev;
731 cam->port = port;
732 init_waitqueue_head(&cam->wq_stream);
733
734 cam->streaming = 0;
735 cam->stream_irq = 0;
736
737 if((cpia = cpia_register_camera(&cpia_pp_ops, cam)) == NULL) {
738 LOG("failed to cpia_register_camera\n");
739 parport_unregister_device(pdev);
740 kfree(cam);
741 return -ENXIO;
742 }
743 spin_lock( &cam_list_lock_pp );
744 list_add( &cpia->cam_data_list, &cam_list );
745 spin_unlock( &cam_list_lock_pp );
746
747 return 0;
748}
749
750static void cpia_pp_detach (struct parport *port)
751{
752 struct list_head *tmp;
753 struct cam_data *cpia = NULL;
754 struct pp_cam_entry *cam;
755
756 spin_lock( &cam_list_lock_pp );
757 list_for_each (tmp, &cam_list) {
758 cpia = list_entry(tmp, struct cam_data, cam_data_list);
759 cam = (struct pp_cam_entry *) cpia->lowlevel_data;
760 if (cam && cam->port->number == port->number) {
761 list_del(&cpia->cam_data_list);
762 break;
763 }
764 cpia = NULL;
765 }
766 spin_unlock( &cam_list_lock_pp );
767
768 if (!cpia) {
769 DBG("cpia_pp_detach failed to find cam_data in cam_list\n");
770 return;
771 }
772
773 cam = (struct pp_cam_entry *) cpia->lowlevel_data;
774 cpia_unregister_camera(cpia);
775 if(cam->open_count > 0)
776 cpia_pp_close(cam);
777 parport_unregister_device(cam->pdev);
778 cpia->lowlevel_data = NULL;
779 kfree(cam);
780}
781
782static void cpia_pp_attach (struct parport *port)
783{
784 unsigned int i;
785
786 switch (parport_nr[0])
787 {
788 case PPCPIA_PARPORT_UNSPEC:
789 case PPCPIA_PARPORT_AUTO:
790 if (port->probe_info[0].class != PARPORT_CLASS_MEDIA ||
791 port->probe_info[0].cmdset == NULL ||
792 strncmp(port->probe_info[0].cmdset, "CPIA_1", 6) != 0)
793 return;
794
795 cpia_pp_register(port);
796
797 break;
798
799 default:
800 for (i = 0; i < PARPORT_MAX; ++i) {
801 if (port->number == parport_nr[i]) {
802 cpia_pp_register(port);
803 break;
804 }
805 }
806 break;
807 }
808}
809
810static struct parport_driver cpia_pp_driver = {
811 .name = "cpia_pp",
812 .attach = cpia_pp_attach,
813 .detach = cpia_pp_detach,
814};
815
816static int __init cpia_pp_init(void)
817{
818 printk(KERN_INFO "%s v%d.%d.%d\n",ABOUT,
819 CPIA_PP_MAJ_VER,CPIA_PP_MIN_VER,CPIA_PP_PATCH_VER);
820
821 if(parport_nr[0] == PPCPIA_PARPORT_OFF) {
822 printk(" disabled\n");
823 return 0;
824 }
825
826 spin_lock_init( &cam_list_lock_pp );
827
828 if (parport_register_driver (&cpia_pp_driver)) {
829 LOG ("unable to register with parport\n");
830 return -EIO;
831 }
832 return 0;
833}
834
835static int __init cpia_init(void)
836{
837 if (parport[0]) {
838 /* The user gave some parameters. Let's see what they were. */
839 if (!strncmp(parport[0], "auto", 4)) {
840 parport_nr[0] = PPCPIA_PARPORT_AUTO;
841 } else {
842 int n;
843 for (n = 0; n < PARPORT_MAX && parport[n]; n++) {
844 if (!strncmp(parport[n], "none", 4)) {
845 parport_nr[n] = PPCPIA_PARPORT_NONE;
846 } else {
847 char *ep;
848 unsigned long r = simple_strtoul(parport[n], &ep, 0);
849 if (ep != parport[n]) {
850 parport_nr[n] = r;
851 } else {
852 LOG("bad port specifier `%s'\n", parport[n]);
853 return -ENODEV;
854 }
855 }
856 }
857 }
858 }
859 return cpia_pp_init();
860}
861
862static void __exit cpia_cleanup(void)
863{
864 parport_unregister_driver(&cpia_pp_driver);
865 return;
866}
867
868module_init(cpia_init);
869module_exit(cpia_cleanup);
diff --git a/drivers/staging/cpia/cpia_usb.c b/drivers/staging/cpia/cpia_usb.c
deleted file mode 100644
index 58d193ff591c..000000000000
--- a/drivers/staging/cpia/cpia_usb.c
+++ /dev/null
@@ -1,640 +0,0 @@
1/*
2 * cpia_usb CPiA USB driver
3 *
4 * Supports CPiA based parallel port Video Camera's.
5 *
6 * Copyright (C) 1999 Jochen Scharrlach <Jochen.Scharrlach@schwaben.de>
7 * Copyright (C) 1999, 2000 Johannes Erdfelt <johannes@erdfelt.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24/* define _CPIA_DEBUG_ for verbose debug output (see cpia.h) */
25/* #define _CPIA_DEBUG_ 1 */
26
27#include <linux/module.h>
28#include <linux/kernel.h>
29#include <linux/init.h>
30#include <linux/wait.h>
31#include <linux/list.h>
32#include <linux/slab.h>
33#include <linux/vmalloc.h>
34#include <linux/usb.h>
35
36#include "cpia.h"
37
38#define USB_REQ_CPIA_GRAB_FRAME 0xC1
39#define USB_REQ_CPIA_UPLOAD_FRAME 0xC2
40#define WAIT_FOR_NEXT_FRAME 0
41#define FORCE_FRAME_UPLOAD 1
42
43#define FRAMES_PER_DESC 10
44#define FRAME_SIZE_PER_DESC 960 /* Shouldn't be hardcoded */
45#define CPIA_NUMSBUF 2
46#define STREAM_BUF_SIZE (PAGE_SIZE * 4)
47#define SCRATCH_BUF_SIZE (STREAM_BUF_SIZE * 2)
48
49struct cpia_sbuf {
50 char *data;
51 struct urb *urb;
52};
53
54#define FRAMEBUF_LEN (CPIA_MAX_FRAME_SIZE+100)
55enum framebuf_status {
56 FRAME_EMPTY,
57 FRAME_READING,
58 FRAME_READY,
59 FRAME_ERROR,
60};
61
62struct framebuf {
63 int length;
64 enum framebuf_status status;
65 u8 data[FRAMEBUF_LEN];
66 struct framebuf *next;
67};
68
69struct usb_cpia {
70 /* Device structure */
71 struct usb_device *dev;
72
73 unsigned char iface;
74 wait_queue_head_t wq_stream;
75
76 int cursbuf; /* Current receiving sbuf */
77 struct cpia_sbuf sbuf[CPIA_NUMSBUF]; /* Double buffering */
78
79 int streaming;
80 int open;
81 int present;
82 struct framebuf *buffers[3];
83 struct framebuf *curbuff, *workbuff;
84};
85
86static int cpia_usb_open(void *privdata);
87static int cpia_usb_registerCallback(void *privdata, void (*cb) (void *cbdata),
88 void *cbdata);
89static int cpia_usb_transferCmd(void *privdata, u8 *command, u8 *data);
90static int cpia_usb_streamStart(void *privdata);
91static int cpia_usb_streamStop(void *privdata);
92static int cpia_usb_streamRead(void *privdata, u8 *frame, int noblock);
93static int cpia_usb_close(void *privdata);
94
95#define ABOUT "USB driver for Vision CPiA based cameras"
96
97static struct cpia_camera_ops cpia_usb_ops = {
98 cpia_usb_open,
99 cpia_usb_registerCallback,
100 cpia_usb_transferCmd,
101 cpia_usb_streamStart,
102 cpia_usb_streamStop,
103 cpia_usb_streamRead,
104 cpia_usb_close,
105 0,
106 THIS_MODULE
107};
108
109static LIST_HEAD(cam_list);
110static spinlock_t cam_list_lock_usb;
111
112static void cpia_usb_complete(struct urb *urb)
113{
114 int i;
115 char *cdata;
116 struct usb_cpia *ucpia;
117
118 if (!urb || !urb->context)
119 return;
120
121 ucpia = (struct usb_cpia *) urb->context;
122
123 if (!ucpia->dev || !ucpia->streaming || !ucpia->present || !ucpia->open)
124 return;
125
126 if (ucpia->workbuff->status == FRAME_EMPTY) {
127 ucpia->workbuff->status = FRAME_READING;
128 ucpia->workbuff->length = 0;
129 }
130
131 for (i = 0; i < urb->number_of_packets; i++) {
132 int n = urb->iso_frame_desc[i].actual_length;
133 int st = urb->iso_frame_desc[i].status;
134
135 cdata = urb->transfer_buffer + urb->iso_frame_desc[i].offset;
136
137 if (st)
138 printk(KERN_DEBUG "cpia data error: [%d] len=%d, status=%X\n", i, n, st);
139
140 if (FRAMEBUF_LEN < ucpia->workbuff->length + n) {
141 printk(KERN_DEBUG "cpia: scratch buf overflow!scr_len: %d, n: %d\n", ucpia->workbuff->length, n);
142 return;
143 }
144
145 if (n) {
146 if ((ucpia->workbuff->length > 0) ||
147 (0x19 == cdata[0] && 0x68 == cdata[1])) {
148 memcpy(ucpia->workbuff->data + ucpia->workbuff->length, cdata, n);
149 ucpia->workbuff->length += n;
150 } else
151 DBG("Ignoring packet!\n");
152 } else {
153 if (ucpia->workbuff->length > 4 &&
154 0xff == ucpia->workbuff->data[ucpia->workbuff->length-1] &&
155 0xff == ucpia->workbuff->data[ucpia->workbuff->length-2] &&
156 0xff == ucpia->workbuff->data[ucpia->workbuff->length-3] &&
157 0xff == ucpia->workbuff->data[ucpia->workbuff->length-4]) {
158 ucpia->workbuff->status = FRAME_READY;
159 ucpia->curbuff = ucpia->workbuff;
160 ucpia->workbuff = ucpia->workbuff->next;
161 ucpia->workbuff->status = FRAME_EMPTY;
162 ucpia->workbuff->length = 0;
163
164 if (waitqueue_active(&ucpia->wq_stream))
165 wake_up_interruptible(&ucpia->wq_stream);
166 }
167 }
168 }
169
170 /* resubmit */
171 urb->dev = ucpia->dev;
172 if ((i = usb_submit_urb(urb, GFP_ATOMIC)) != 0)
173 printk(KERN_ERR "%s: usb_submit_urb ret %d\n", __func__, i);
174}
175
176static int cpia_usb_open(void *privdata)
177{
178 struct usb_cpia *ucpia = (struct usb_cpia *) privdata;
179 struct urb *urb;
180 int ret, retval = 0, fx, err;
181
182 if (!ucpia)
183 return -EINVAL;
184
185 ucpia->sbuf[0].data = kmalloc(FRAMES_PER_DESC * FRAME_SIZE_PER_DESC, GFP_KERNEL);
186 if (!ucpia->sbuf[0].data)
187 return -EINVAL;
188
189 ucpia->sbuf[1].data = kmalloc(FRAMES_PER_DESC * FRAME_SIZE_PER_DESC, GFP_KERNEL);
190 if (!ucpia->sbuf[1].data) {
191 retval = -EINVAL;
192 goto error_0;
193 }
194
195 ret = usb_set_interface(ucpia->dev, ucpia->iface, 3);
196 if (ret < 0) {
197 printk(KERN_ERR "cpia_usb_open: usb_set_interface error (ret = %d)\n", ret);
198 retval = -EBUSY;
199 goto error_1;
200 }
201
202 ucpia->buffers[0]->status = FRAME_EMPTY;
203 ucpia->buffers[0]->length = 0;
204 ucpia->buffers[1]->status = FRAME_EMPTY;
205 ucpia->buffers[1]->length = 0;
206 ucpia->buffers[2]->status = FRAME_EMPTY;
207 ucpia->buffers[2]->length = 0;
208 ucpia->curbuff = ucpia->buffers[0];
209 ucpia->workbuff = ucpia->buffers[1];
210
211 /* We double buffer the Iso lists, and also know the polling
212 * interval is every frame (1 == (1 << (bInterval -1))).
213 */
214 urb = usb_alloc_urb(FRAMES_PER_DESC, GFP_KERNEL);
215 if (!urb) {
216 printk(KERN_ERR "cpia_init_isoc: usb_alloc_urb 0\n");
217 retval = -ENOMEM;
218 goto error_1;
219 }
220
221 ucpia->sbuf[0].urb = urb;
222 urb->dev = ucpia->dev;
223 urb->context = ucpia;
224 urb->pipe = usb_rcvisocpipe(ucpia->dev, 1);
225 urb->transfer_flags = URB_ISO_ASAP;
226 urb->transfer_buffer = ucpia->sbuf[0].data;
227 urb->complete = cpia_usb_complete;
228 urb->number_of_packets = FRAMES_PER_DESC;
229 urb->interval = 1;
230 urb->transfer_buffer_length = FRAME_SIZE_PER_DESC * FRAMES_PER_DESC;
231 for (fx = 0; fx < FRAMES_PER_DESC; fx++) {
232 urb->iso_frame_desc[fx].offset = FRAME_SIZE_PER_DESC * fx;
233 urb->iso_frame_desc[fx].length = FRAME_SIZE_PER_DESC;
234 }
235
236 urb = usb_alloc_urb(FRAMES_PER_DESC, GFP_KERNEL);
237 if (!urb) {
238 printk(KERN_ERR "cpia_init_isoc: usb_alloc_urb 1\n");
239 retval = -ENOMEM;
240 goto error_urb0;
241 }
242
243 ucpia->sbuf[1].urb = urb;
244 urb->dev = ucpia->dev;
245 urb->context = ucpia;
246 urb->pipe = usb_rcvisocpipe(ucpia->dev, 1);
247 urb->transfer_flags = URB_ISO_ASAP;
248 urb->transfer_buffer = ucpia->sbuf[1].data;
249 urb->complete = cpia_usb_complete;
250 urb->number_of_packets = FRAMES_PER_DESC;
251 urb->interval = 1;
252 urb->transfer_buffer_length = FRAME_SIZE_PER_DESC * FRAMES_PER_DESC;
253 for (fx = 0; fx < FRAMES_PER_DESC; fx++) {
254 urb->iso_frame_desc[fx].offset = FRAME_SIZE_PER_DESC * fx;
255 urb->iso_frame_desc[fx].length = FRAME_SIZE_PER_DESC;
256 }
257
258 /* queue the ISO urbs, and resubmit in the completion handler */
259 err = usb_submit_urb(ucpia->sbuf[0].urb, GFP_KERNEL);
260 if (err) {
261 printk(KERN_ERR "cpia_init_isoc: usb_submit_urb 0 ret %d\n",
262 err);
263 goto error_urb1;
264 }
265 err = usb_submit_urb(ucpia->sbuf[1].urb, GFP_KERNEL);
266 if (err) {
267 printk(KERN_ERR "cpia_init_isoc: usb_submit_urb 1 ret %d\n",
268 err);
269 goto error_urb1;
270 }
271
272 ucpia->streaming = 1;
273 ucpia->open = 1;
274
275 return 0;
276
277error_urb1: /* free urb 1 */
278 usb_free_urb(ucpia->sbuf[1].urb);
279 ucpia->sbuf[1].urb = NULL;
280error_urb0: /* free urb 0 */
281 usb_free_urb(ucpia->sbuf[0].urb);
282 ucpia->sbuf[0].urb = NULL;
283error_1:
284 kfree (ucpia->sbuf[1].data);
285 ucpia->sbuf[1].data = NULL;
286error_0:
287 kfree (ucpia->sbuf[0].data);
288 ucpia->sbuf[0].data = NULL;
289
290 return retval;
291}
292
293//
294// convenience functions
295//
296
297/****************************************************************************
298 *
299 * WritePacket
300 *
301 ***************************************************************************/
302static int WritePacket(struct usb_device *udev, const u8 *packet, u8 *buf, size_t size)
303{
304 if (!packet)
305 return -EINVAL;
306
307 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
308 packet[1] + (packet[0] << 8),
309 USB_TYPE_VENDOR | USB_RECIP_DEVICE,
310 packet[2] + (packet[3] << 8),
311 packet[4] + (packet[5] << 8), buf, size, 1000);
312}
313
314/****************************************************************************
315 *
316 * ReadPacket
317 *
318 ***************************************************************************/
319static int ReadPacket(struct usb_device *udev, u8 *packet, u8 *buf, size_t size)
320{
321 if (!packet || size <= 0)
322 return -EINVAL;
323
324 return usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
325 packet[1] + (packet[0] << 8),
326 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
327 packet[2] + (packet[3] << 8),
328 packet[4] + (packet[5] << 8), buf, size, 1000);
329}
330
331static int cpia_usb_transferCmd(void *privdata, u8 *command, u8 *data)
332{
333 int err = 0;
334 int databytes;
335 struct usb_cpia *ucpia = (struct usb_cpia *)privdata;
336 struct usb_device *udev = ucpia->dev;
337
338 if (!udev) {
339 DBG("Internal driver error: udev is NULL\n");
340 return -EINVAL;
341 }
342
343 if (!command) {
344 DBG("Internal driver error: command is NULL\n");
345 return -EINVAL;
346 }
347
348 databytes = (((int)command[7])<<8) | command[6];
349
350 if (command[0] == DATA_IN) {
351 u8 buffer[8];
352
353 if (!data) {
354 DBG("Internal driver error: data is NULL\n");
355 return -EINVAL;
356 }
357
358 err = ReadPacket(udev, command, buffer, 8);
359 if (err < 0)
360 return err;
361
362 memcpy(data, buffer, databytes);
363 } else if(command[0] == DATA_OUT)
364 WritePacket(udev, command, data, databytes);
365 else {
366 DBG("Unexpected first byte of command: %x\n", command[0]);
367 err = -EINVAL;
368 }
369
370 return 0;
371}
372
373static int cpia_usb_registerCallback(void *privdata, void (*cb) (void *cbdata),
374 void *cbdata)
375{
376 return -ENODEV;
377}
378
379static int cpia_usb_streamStart(void *privdata)
380{
381 return -ENODEV;
382}
383
384static int cpia_usb_streamStop(void *privdata)
385{
386 return -ENODEV;
387}
388
389static int cpia_usb_streamRead(void *privdata, u8 *frame, int noblock)
390{
391 struct usb_cpia *ucpia = (struct usb_cpia *) privdata;
392 struct framebuf *mybuff;
393
394 if (!ucpia || !ucpia->present)
395 return -1;
396
397 if (ucpia->curbuff->status != FRAME_READY)
398 interruptible_sleep_on(&ucpia->wq_stream);
399 else
400 DBG("Frame already waiting!\n");
401
402 mybuff = ucpia->curbuff;
403
404 if (!mybuff)
405 return -1;
406
407 if (mybuff->status != FRAME_READY || mybuff->length < 4) {
408 DBG("Something went wrong!\n");
409 return -1;
410 }
411
412 memcpy(frame, mybuff->data, mybuff->length);
413 mybuff->status = FRAME_EMPTY;
414
415/* DBG("read done, %d bytes, Header: %x/%x, Footer: %x%x%x%x\n", */
416/* mybuff->length, frame[0], frame[1], */
417/* frame[mybuff->length-4], frame[mybuff->length-3], */
418/* frame[mybuff->length-2], frame[mybuff->length-1]); */
419
420 return mybuff->length;
421}
422
423static void cpia_usb_free_resources(struct usb_cpia *ucpia, int try)
424{
425 if (!ucpia->streaming)
426 return;
427
428 ucpia->streaming = 0;
429
430 /* Set packet size to 0 */
431 if (try) {
432 int ret;
433
434 ret = usb_set_interface(ucpia->dev, ucpia->iface, 0);
435 if (ret < 0) {
436 printk(KERN_ERR "usb_set_interface error (ret = %d)\n", ret);
437 return;
438 }
439 }
440
441 /* Unschedule all of the iso td's */
442 if (ucpia->sbuf[1].urb) {
443 usb_kill_urb(ucpia->sbuf[1].urb);
444 usb_free_urb(ucpia->sbuf[1].urb);
445 ucpia->sbuf[1].urb = NULL;
446 }
447
448 kfree(ucpia->sbuf[1].data);
449 ucpia->sbuf[1].data = NULL;
450
451 if (ucpia->sbuf[0].urb) {
452 usb_kill_urb(ucpia->sbuf[0].urb);
453 usb_free_urb(ucpia->sbuf[0].urb);
454 ucpia->sbuf[0].urb = NULL;
455 }
456
457 kfree(ucpia->sbuf[0].data);
458 ucpia->sbuf[0].data = NULL;
459}
460
461static int cpia_usb_close(void *privdata)
462{
463 struct usb_cpia *ucpia = (struct usb_cpia *) privdata;
464
465 if(!ucpia)
466 return -ENODEV;
467
468 ucpia->open = 0;
469
470 /* ucpia->present = 0 protects against trying to reset the
471 * alt setting if camera is physically disconnected while open */
472 cpia_usb_free_resources(ucpia, ucpia->present);
473
474 return 0;
475}
476
477/* Probing and initializing */
478
479static int cpia_probe(struct usb_interface *intf,
480 const struct usb_device_id *id)
481{
482 struct usb_device *udev = interface_to_usbdev(intf);
483 struct usb_host_interface *interface;
484 struct usb_cpia *ucpia;
485 struct cam_data *cam;
486 int ret;
487
488 /* A multi-config CPiA camera? */
489 if (udev->descriptor.bNumConfigurations != 1)
490 return -ENODEV;
491
492 interface = intf->cur_altsetting;
493
494 printk(KERN_INFO "USB CPiA camera found\n");
495
496 ucpia = kzalloc(sizeof(*ucpia), GFP_KERNEL);
497 if (!ucpia) {
498 printk(KERN_ERR "couldn't kmalloc cpia struct\n");
499 return -ENOMEM;
500 }
501
502 ucpia->dev = udev;
503 ucpia->iface = interface->desc.bInterfaceNumber;
504 init_waitqueue_head(&ucpia->wq_stream);
505
506 ucpia->buffers[0] = vmalloc(sizeof(*ucpia->buffers[0]));
507 if (!ucpia->buffers[0]) {
508 printk(KERN_ERR "couldn't vmalloc frame buffer 0\n");
509 goto fail_alloc_0;
510 }
511
512 ucpia->buffers[1] = vmalloc(sizeof(*ucpia->buffers[1]));
513 if (!ucpia->buffers[1]) {
514 printk(KERN_ERR "couldn't vmalloc frame buffer 1\n");
515 goto fail_alloc_1;
516 }
517
518 ucpia->buffers[2] = vmalloc(sizeof(*ucpia->buffers[2]));
519 if (!ucpia->buffers[2]) {
520 printk(KERN_ERR "couldn't vmalloc frame buffer 2\n");
521 goto fail_alloc_2;
522 }
523
524 ucpia->buffers[0]->next = ucpia->buffers[1];
525 ucpia->buffers[1]->next = ucpia->buffers[2];
526 ucpia->buffers[2]->next = ucpia->buffers[0];
527
528 ret = usb_set_interface(udev, ucpia->iface, 0);
529 if (ret < 0) {
530 printk(KERN_ERR "cpia_probe: usb_set_interface error (ret = %d)\n", ret);
531 /* goto fail_all; */
532 }
533
534 /* Before register_camera, important */
535 ucpia->present = 1;
536
537 cam = cpia_register_camera(&cpia_usb_ops, ucpia);
538 if (!cam) {
539 LOG("failed to cpia_register_camera\n");
540 goto fail_all;
541 }
542
543 spin_lock( &cam_list_lock_usb );
544 list_add( &cam->cam_data_list, &cam_list );
545 spin_unlock( &cam_list_lock_usb );
546
547 usb_set_intfdata(intf, cam);
548 return 0;
549
550fail_all:
551 vfree(ucpia->buffers[2]);
552 ucpia->buffers[2] = NULL;
553fail_alloc_2:
554 vfree(ucpia->buffers[1]);
555 ucpia->buffers[1] = NULL;
556fail_alloc_1:
557 vfree(ucpia->buffers[0]);
558 ucpia->buffers[0] = NULL;
559fail_alloc_0:
560 kfree(ucpia);
561 return -EIO;
562}
563
564static void cpia_disconnect(struct usb_interface *intf);
565
566static struct usb_device_id cpia_id_table [] = {
567 { USB_DEVICE(0x0553, 0x0002) },
568 { USB_DEVICE(0x0813, 0x0001) },
569 { } /* Terminating entry */
570};
571
572MODULE_DEVICE_TABLE (usb, cpia_id_table);
573MODULE_LICENSE("GPL");
574
575
576static struct usb_driver cpia_driver = {
577 .name = "cpia",
578 .probe = cpia_probe,
579 .disconnect = cpia_disconnect,
580 .id_table = cpia_id_table,
581};
582
583static void cpia_disconnect(struct usb_interface *intf)
584{
585 struct cam_data *cam = usb_get_intfdata(intf);
586 struct usb_cpia *ucpia;
587
588 usb_set_intfdata(intf, NULL);
589 if (!cam)
590 return;
591
592 ucpia = (struct usb_cpia *) cam->lowlevel_data;
593 spin_lock( &cam_list_lock_usb );
594 list_del(&cam->cam_data_list);
595 spin_unlock( &cam_list_lock_usb );
596
597 ucpia->present = 0;
598
599 cpia_unregister_camera(cam);
600 if(ucpia->open)
601 cpia_usb_close(cam->lowlevel_data);
602
603 ucpia->curbuff->status = FRAME_ERROR;
604
605 if (waitqueue_active(&ucpia->wq_stream))
606 wake_up_interruptible(&ucpia->wq_stream);
607
608 ucpia->curbuff = ucpia->workbuff = NULL;
609
610 vfree(ucpia->buffers[2]);
611 ucpia->buffers[2] = NULL;
612
613 vfree(ucpia->buffers[1]);
614 ucpia->buffers[1] = NULL;
615
616 vfree(ucpia->buffers[0]);
617 ucpia->buffers[0] = NULL;
618
619 cam->lowlevel_data = NULL;
620 kfree(ucpia);
621}
622
623static int __init usb_cpia_init(void)
624{
625 printk(KERN_INFO "%s v%d.%d.%d\n",ABOUT,
626 CPIA_USB_MAJ_VER,CPIA_USB_MIN_VER,CPIA_USB_PATCH_VER);
627
628 spin_lock_init(&cam_list_lock_usb);
629 return usb_register(&cpia_driver);
630}
631
632static void __exit usb_cpia_cleanup(void)
633{
634 usb_deregister(&cpia_driver);
635}
636
637
638module_init (usb_cpia_init);
639module_exit (usb_cpia_cleanup);
640
diff --git a/drivers/staging/cx25821/Kconfig b/drivers/staging/cx25821/Kconfig
index 1d73334d2a44..b2656957aa8f 100644
--- a/drivers/staging/cx25821/Kconfig
+++ b/drivers/staging/cx25821/Kconfig
@@ -1,11 +1,11 @@
1config VIDEO_CX25821 1config VIDEO_CX25821
2 tristate "Conexant cx25821 support" 2 tristate "Conexant cx25821 support"
3 depends on DVB_CORE && VIDEO_DEV && PCI && I2C && INPUT 3 depends on DVB_CORE && VIDEO_DEV && PCI && I2C
4 depends on BKL # please fix 4 depends on BKL # please fix
5 select I2C_ALGOBIT 5 select I2C_ALGOBIT
6 select VIDEO_BTCX 6 select VIDEO_BTCX
7 select VIDEO_TVEEPROM 7 select VIDEO_TVEEPROM
8 depends on VIDEO_IR 8 depends on RC_CORE
9 select VIDEOBUF_DVB 9 select VIDEOBUF_DVB
10 select VIDEOBUF_DMA_SG 10 select VIDEOBUF_DMA_SG
11 select VIDEO_CX25840 11 select VIDEO_CX25840
diff --git a/drivers/staging/cx25821/cx25821-alsa.c b/drivers/staging/cx25821/cx25821-alsa.c
index 2a01dc057b2c..9a205a342c55 100644
--- a/drivers/staging/cx25821/cx25821-alsa.c
+++ b/drivers/staging/cx25821/cx25821-alsa.c
@@ -20,6 +20,8 @@
20 * 20 *
21 */ 21 */
22 22
23#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
24
23#include <linux/module.h> 25#include <linux/module.h>
24#include <linux/init.h> 26#include <linux/init.h>
25#include <linux/device.h> 27#include <linux/device.h>
@@ -42,11 +44,16 @@
42 44
43#define AUDIO_SRAM_CHANNEL SRAM_CH08 45#define AUDIO_SRAM_CHANNEL SRAM_CH08
44 46
45#define dprintk(level, fmt, arg...) if (debug >= level) \ 47#define dprintk(level, fmt, arg...) \
46 printk(KERN_INFO "%s/1: " fmt, chip->dev->name , ## arg) 48do { \
47 49 if (debug >= level) \
48#define dprintk_core(level, fmt, arg...) if (debug >= level) \ 50 pr_info("%s/1: " fmt, chip->dev->name, ##arg); \
49 printk(KERN_DEBUG "%s/1: " fmt, chip->dev->name , ## arg) 51} while (0)
52#define dprintk_core(level, fmt, arg...) \
53do { \
54 if (debug >= level) \
55 printk(KERN_DEBUG "%s/1: " fmt, chip->dev->name, ##arg); \
56} while (0)
50 57
51/**************************************************************************** 58/****************************************************************************
52 Data type declarations - Can be moded to a header file later 59 Data type declarations - Can be moded to a header file later
@@ -173,12 +180,11 @@ static int _cx25821_start_audio_dma(struct cx25821_audio_dev *chip)
173 tmp | FLD_AUD_DST_PK_MODE | FLD_AUD_DST_ENABLE | 180 tmp | FLD_AUD_DST_PK_MODE | FLD_AUD_DST_ENABLE |
174 FLD_AUD_CLK_ENABLE); 181 FLD_AUD_CLK_ENABLE);
175 182
176 /* printk(KERN_INFO "DEBUG: Start audio DMA, %d B/line," 183 /*
177 "cmds_start(0x%x)= %d lines/FIFO, %d periods, " 184 pr_info("DEBUG: Start audio DMA, %d B/line, cmds_start(0x%x)= %d lines/FIFO, %d periods, %d byte buffer\n",
178 "%d byte buffer\n", buf->bpl, 185 buf->bpl, audio_ch->cmds_start,
179 audio_ch->cmds_start, 186 cx_read(audio_ch->cmds_start + 12)>>1,
180 cx_read(audio_ch->cmds_start + 12)>>1, 187 chip->num_periods, buf->bpl * chip->num_periods);
181 chip->num_periods, buf->bpl *chip->num_periods);
182 */ 188 */
183 189
184 /* Enables corresponding bits at AUD_INT_STAT */ 190 /* Enables corresponding bits at AUD_INT_STAT */
@@ -259,8 +265,7 @@ static void cx25821_aud_irq(struct cx25821_audio_dev *chip, u32 status,
259 265
260 /* risc op code error */ 266 /* risc op code error */
261 if (status & AUD_INT_OPC_ERR) { 267 if (status & AUD_INT_OPC_ERR) {
262 printk(KERN_WARNING "WARNING %s/1: Audio risc op code error\n", 268 pr_warn("WARNING %s/1: Audio risc op code error\n", dev->name);
263 dev->name);
264 269
265 cx_clear(AUD_INT_DMA_CTL, 270 cx_clear(AUD_INT_DMA_CTL,
266 FLD_AUD_DST_A_RISC_EN | FLD_AUD_DST_A_FIFO_EN); 271 FLD_AUD_DST_A_RISC_EN | FLD_AUD_DST_A_FIFO_EN);
@@ -269,8 +274,7 @@ static void cx25821_aud_irq(struct cx25821_audio_dev *chip, u32 status,
269 [AUDIO_SRAM_CHANNEL]); 274 [AUDIO_SRAM_CHANNEL]);
270 } 275 }
271 if (status & AUD_INT_DN_SYNC) { 276 if (status & AUD_INT_DN_SYNC) {
272 printk(KERN_WARNING "WARNING %s: Downstream sync error!\n", 277 pr_warn("WARNING %s: Downstream sync error!\n", dev->name);
273 dev->name);
274 cx_write(AUD_A_GPCNT_CTL, GP_COUNT_CONTROL_RESET); 278 cx_write(AUD_A_GPCNT_CTL, GP_COUNT_CONTROL_RESET);
275 return; 279 return;
276 } 280 }
@@ -388,8 +392,7 @@ static int snd_cx25821_pcm_open(struct snd_pcm_substream *substream)
388 unsigned int bpl = 0; 392 unsigned int bpl = 0;
389 393
390 if (!chip) { 394 if (!chip) {
391 printk(KERN_ERR "DEBUG: cx25821 can't find device struct." 395 pr_err("DEBUG: cx25821 can't find device struct. Can't proceed with open\n");
392 " Can't proceed with open\n");
393 return -ENODEV; 396 return -ENODEV;
394 } 397 }
395 398
@@ -479,8 +482,7 @@ static int snd_cx25821_hw_params(struct snd_pcm_substream *substream,
479 chip->period_size, chip->num_periods, 482 chip->period_size, chip->num_periods,
480 1); 483 1);
481 if (ret < 0) { 484 if (ret < 0) {
482 printk(KERN_INFO 485 pr_info("DEBUG: ERROR after cx25821_risc_databuffer_audio()\n");
483 "DEBUG: ERROR after cx25821_risc_databuffer_audio()\n");
484 goto error; 486 goto error;
485 } 487 }
486 488
@@ -608,8 +610,7 @@ static int snd_cx25821_pcm(struct cx25821_audio_dev *chip, int device,
608 610
609 err = snd_pcm_new(chip->card, name, device, 0, 1, &pcm); 611 err = snd_pcm_new(chip->card, name, device, 0, 1, &pcm);
610 if (err < 0) { 612 if (err < 0) {
611 printk(KERN_INFO "ERROR: FAILED snd_pcm_new() in %s\n", 613 pr_info("ERROR: FAILED snd_pcm_new() in %s\n", __func__);
612 __func__);
613 return err; 614 return err;
614 } 615 }
615 pcm->private_data = chip; 616 pcm->private_data = chip;
@@ -674,23 +675,21 @@ static int cx25821_audio_initdev(struct cx25821_dev *dev)
674 int err; 675 int err;
675 676
676 if (devno >= SNDRV_CARDS) { 677 if (devno >= SNDRV_CARDS) {
677 printk(KERN_INFO "DEBUG ERROR: devno >= SNDRV_CARDS %s\n", 678 pr_info("DEBUG ERROR: devno >= SNDRV_CARDS %s\n", __func__);
678 __func__);
679 return -ENODEV; 679 return -ENODEV;
680 } 680 }
681 681
682 if (!enable[devno]) { 682 if (!enable[devno]) {
683 ++devno; 683 ++devno;
684 printk(KERN_INFO "DEBUG ERROR: !enable[devno] %s\n", __func__); 684 pr_info("DEBUG ERROR: !enable[devno] %s\n", __func__);
685 return -ENOENT; 685 return -ENOENT;
686 } 686 }
687 687
688 err = snd_card_create(index[devno], id[devno], THIS_MODULE, 688 err = snd_card_create(index[devno], id[devno], THIS_MODULE,
689 sizeof(struct cx25821_audio_dev), &card); 689 sizeof(struct cx25821_audio_dev), &card);
690 if (err < 0) { 690 if (err < 0) {
691 printk(KERN_INFO 691 pr_info("DEBUG ERROR: cannot create snd_card_new in %s\n",
692 "DEBUG ERROR: cannot create snd_card_new in %s\n", 692 __func__);
693 __func__);
694 return err; 693 return err;
695 } 694 }
696 695
@@ -712,16 +711,15 @@ static int cx25821_audio_initdev(struct cx25821_dev *dev)
712 IRQF_SHARED | IRQF_DISABLED, chip->dev->name, chip); 711 IRQF_SHARED | IRQF_DISABLED, chip->dev->name, chip);
713 712
714 if (err < 0) { 713 if (err < 0) {
715 printk(KERN_ERR "ERROR %s: can't get IRQ %d for ALSA\n", 714 pr_err("ERROR %s: can't get IRQ %d for ALSA\n",
716 chip->dev->name, dev->pci->irq); 715 chip->dev->name, dev->pci->irq);
717 goto error; 716 goto error;
718 } 717 }
719 718
720 err = snd_cx25821_pcm(chip, 0, "cx25821 Digital"); 719 err = snd_cx25821_pcm(chip, 0, "cx25821 Digital");
721 if (err < 0) { 720 if (err < 0) {
722 printk(KERN_INFO 721 pr_info("DEBUG ERROR: cannot create snd_cx25821_pcm %s\n",
723 "DEBUG ERROR: cannot create snd_cx25821_pcm %s\n", 722 __func__);
724 __func__);
725 goto error; 723 goto error;
726 } 724 }
727 725
@@ -732,13 +730,13 @@ static int cx25821_audio_initdev(struct cx25821_dev *dev)
732 chip->iobase, chip->irq); 730 chip->iobase, chip->irq);
733 strcpy(card->mixername, "CX25821"); 731 strcpy(card->mixername, "CX25821");
734 732
735 printk(KERN_INFO "%s/%i: ALSA support for cx25821 boards\n", 733 pr_info("%s/%i: ALSA support for cx25821 boards\n",
736 card->driver, devno); 734 card->driver, devno);
737 735
738 err = snd_card_register(card); 736 err = snd_card_register(card);
739 if (err < 0) { 737 if (err < 0) {
740 printk(KERN_INFO "DEBUG ERROR: cannot register sound card %s\n", 738 pr_info("DEBUG ERROR: cannot register sound card %s\n",
741 __func__); 739 __func__);
742 goto error; 740 goto error;
743 } 741 }
744 742
@@ -778,8 +776,7 @@ static int cx25821_alsa_init(void)
778 } 776 }
779 777
780 if (dev == NULL) 778 if (dev == NULL)
781 printk(KERN_INFO 779 pr_info("ERROR ALSA: no cx25821 cards found\n");
782 "cx25821 ERROR ALSA: no cx25821 cards found\n");
783 780
784 return 0; 781 return 0;
785 782
diff --git a/drivers/staging/cx25821/cx25821-audio-upstream.c b/drivers/staging/cx25821/cx25821-audio-upstream.c
index 1607b0d86e6f..7992a3ba526f 100644
--- a/drivers/staging/cx25821/cx25821-audio-upstream.c
+++ b/drivers/staging/cx25821/cx25821-audio-upstream.c
@@ -20,6 +20,8 @@
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */ 21 */
22 22
23#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
24
23#include "cx25821-video.h" 25#include "cx25821-video.h"
24#include "cx25821-audio-upstream.h" 26#include "cx25821-audio-upstream.h"
25 27
@@ -221,7 +223,7 @@ void cx25821_stop_upstream_audio(struct cx25821_dev *dev)
221 223
222 if (!dev->_audio_is_running) { 224 if (!dev->_audio_is_running) {
223 printk(KERN_DEBUG 225 printk(KERN_DEBUG
224 "cx25821: No audio file is currently running so return!\n"); 226 pr_fmt("No audio file is currently running so return!\n"));
225 return; 227 return;
226 } 228 }
227 /* Disable RISC interrupts */ 229 /* Disable RISC interrupts */
@@ -281,19 +283,19 @@ int cx25821_get_audio_data(struct cx25821_dev *dev,
281 283
282 if (IS_ERR(myfile)) { 284 if (IS_ERR(myfile)) {
283 const int open_errno = -PTR_ERR(myfile); 285 const int open_errno = -PTR_ERR(myfile);
284 printk(KERN_ERR "%s(): ERROR opening file(%s) with errno = %d!\n", 286 pr_err("%s(): ERROR opening file(%s) with errno = %d!\n",
285 __func__, dev->_audiofilename, open_errno); 287 __func__, dev->_audiofilename, open_errno);
286 return PTR_ERR(myfile); 288 return PTR_ERR(myfile);
287 } else { 289 } else {
288 if (!(myfile->f_op)) { 290 if (!(myfile->f_op)) {
289 printk(KERN_ERR "%s: File has no file operations registered!\n", 291 pr_err("%s(): File has no file operations registered!\n",
290 __func__); 292 __func__);
291 filp_close(myfile, NULL); 293 filp_close(myfile, NULL);
292 return -EIO; 294 return -EIO;
293 } 295 }
294 296
295 if (!myfile->f_op->read) { 297 if (!myfile->f_op->read) {
296 printk(KERN_ERR "%s: File has no READ operations registered!\n", 298 pr_err("%s(): File has no READ operations registered!\n",
297 __func__); 299 __func__);
298 filp_close(myfile, NULL); 300 filp_close(myfile, NULL);
299 return -EIO; 301 return -EIO;
@@ -320,9 +322,8 @@ int cx25821_get_audio_data(struct cx25821_dev *dev,
320 frame_offset += vfs_read_retval; 322 frame_offset += vfs_read_retval;
321 323
322 if (vfs_read_retval < line_size) { 324 if (vfs_read_retval < line_size) {
323 printk(KERN_INFO 325 pr_info("Done: exit %s() since no more bytes to read from Audio file\n",
324 "Done: exit %s() since no more bytes to read from Audio file.\n", 326 __func__);
325 __func__);
326 break; 327 break;
327 } 328 }
328 } 329 }
@@ -346,7 +347,7 @@ static void cx25821_audioups_handler(struct work_struct *work)
346 container_of(work, struct cx25821_dev, _audio_work_entry); 347 container_of(work, struct cx25821_dev, _audio_work_entry);
347 348
348 if (!dev) { 349 if (!dev) {
349 printk(KERN_ERR "ERROR %s(): since container_of(work_struct) FAILED!\n", 350 pr_err("ERROR %s(): since container_of(work_struct) FAILED!\n",
350 __func__); 351 __func__);
351 return; 352 return;
352 } 353 }
@@ -373,19 +374,19 @@ int cx25821_openfile_audio(struct cx25821_dev *dev,
373 374
374 if (IS_ERR(myfile)) { 375 if (IS_ERR(myfile)) {
375 const int open_errno = -PTR_ERR(myfile); 376 const int open_errno = -PTR_ERR(myfile);
376 printk(KERN_ERR "%s(): ERROR opening file(%s) with errno = %d!\n", 377 pr_err("%s(): ERROR opening file(%s) with errno = %d!\n",
377 __func__, dev->_audiofilename, open_errno); 378 __func__, dev->_audiofilename, open_errno);
378 return PTR_ERR(myfile); 379 return PTR_ERR(myfile);
379 } else { 380 } else {
380 if (!(myfile->f_op)) { 381 if (!(myfile->f_op)) {
381 printk(KERN_ERR "%s: File has no file operations registered!\n", 382 pr_err("%s(): File has no file operations registered!\n",
382 __func__); 383 __func__);
383 filp_close(myfile, NULL); 384 filp_close(myfile, NULL);
384 return -EIO; 385 return -EIO;
385 } 386 }
386 387
387 if (!myfile->f_op->read) { 388 if (!myfile->f_op->read) {
388 printk(KERN_ERR "%s: File has no READ operations registered!\n", 389 pr_err("%s(): File has no READ operations registered!\n",
389 __func__); 390 __func__);
390 filp_close(myfile, NULL); 391 filp_close(myfile, NULL);
391 return -EIO; 392 return -EIO;
@@ -414,9 +415,8 @@ int cx25821_openfile_audio(struct cx25821_dev *dev,
414 offset += vfs_read_retval; 415 offset += vfs_read_retval;
415 416
416 if (vfs_read_retval < line_size) { 417 if (vfs_read_retval < line_size) {
417 printk(KERN_INFO 418 pr_info("Done: exit %s() since no more bytes to read from Audio file\n",
418 "Done: exit %s() since no more bytes to read from Audio file.\n", 419 __func__);
419 __func__);
420 break; 420 break;
421 } 421 }
422 } 422 }
@@ -459,7 +459,7 @@ static int cx25821_audio_upstream_buffer_prepare(struct cx25821_dev *dev,
459 459
460 if (!dev->_risc_virt_addr) { 460 if (!dev->_risc_virt_addr) {
461 printk(KERN_DEBUG 461 printk(KERN_DEBUG
462 "cx25821 ERROR: pci_alloc_consistent() FAILED to allocate memory for RISC program! Returning.\n"); 462 pr_fmt("ERROR: pci_alloc_consistent() FAILED to allocate memory for RISC program! Returning\n"));
463 return -ENOMEM; 463 return -ENOMEM;
464 } 464 }
465 /* Clear out memory at address */ 465 /* Clear out memory at address */
@@ -474,7 +474,7 @@ static int cx25821_audio_upstream_buffer_prepare(struct cx25821_dev *dev,
474 474
475 if (!dev->_audiodata_buf_virt_addr) { 475 if (!dev->_audiodata_buf_virt_addr) {
476 printk(KERN_DEBUG 476 printk(KERN_DEBUG
477 "cx25821 ERROR: pci_alloc_consistent() FAILED to allocate memory for data buffer! Returning.\n"); 477 pr_fmt("ERROR: pci_alloc_consistent() FAILED to allocate memory for data buffer! Returning\n"));
478 return -ENOMEM; 478 return -ENOMEM;
479 } 479 }
480 /* Clear out memory at address */ 480 /* Clear out memory at address */
@@ -490,7 +490,7 @@ static int cx25821_audio_upstream_buffer_prepare(struct cx25821_dev *dev,
490 dev->_audio_lines_count); 490 dev->_audio_lines_count);
491 if (ret < 0) { 491 if (ret < 0) {
492 printk(KERN_DEBUG 492 printk(KERN_DEBUG
493 "cx25821 ERROR creating audio upstream RISC programs!\n"); 493 pr_fmt("ERROR creating audio upstream RISC programs!\n"));
494 goto error; 494 goto error;
495 } 495 }
496 496
@@ -569,16 +569,16 @@ int cx25821_audio_upstream_irq(struct cx25821_dev *dev, int chan_num,
569 spin_unlock(&dev->slock); 569 spin_unlock(&dev->slock);
570 } else { 570 } else {
571 if (status & FLD_AUD_SRC_OF) 571 if (status & FLD_AUD_SRC_OF)
572 printk(KERN_WARNING "%s: Audio Received Overflow Error Interrupt!\n", 572 pr_warn("%s(): Audio Received Overflow Error Interrupt!\n",
573 __func__); 573 __func__);
574 574
575 if (status & FLD_AUD_SRC_SYNC) 575 if (status & FLD_AUD_SRC_SYNC)
576 printk(KERN_WARNING "%s: Audio Received Sync Error Interrupt!\n", 576 pr_warn("%s(): Audio Received Sync Error Interrupt!\n",
577 __func__); 577 __func__);
578 578
579 if (status & FLD_AUD_SRC_OPC_ERR) 579 if (status & FLD_AUD_SRC_OPC_ERR)
580 printk(KERN_WARNING "%s: Audio Received OpCode Error Interrupt!\n", 580 pr_warn("%s(): Audio Received OpCode Error Interrupt!\n",
581 __func__); 581 __func__);
582 582
583 /* Read and write back the interrupt status register to clear 583 /* Read and write back the interrupt status register to clear
584 * our bits */ 584 * our bits */
@@ -586,8 +586,8 @@ int cx25821_audio_upstream_irq(struct cx25821_dev *dev, int chan_num,
586 } 586 }
587 587
588 if (dev->_audiofile_status == END_OF_FILE) { 588 if (dev->_audiofile_status == END_OF_FILE) {
589 printk(KERN_WARNING "cx25821: EOF Channel Audio Framecount = %d\n", 589 pr_warn("EOF Channel Audio Framecount = %d\n",
590 dev->_audioframe_count); 590 dev->_audioframe_count);
591 return -1; 591 return -1;
592 } 592 }
593 /* ElSE, set the interrupt mask register, re-enable irq. */ 593 /* ElSE, set the interrupt mask register, re-enable irq. */
@@ -644,9 +644,8 @@ static void cx25821_wait_fifo_enable(struct cx25821_dev *dev,
644 644
645 /* 10 millisecond timeout */ 645 /* 10 millisecond timeout */
646 if (count++ > 1000) { 646 if (count++ > 1000) {
647 printk(KERN_ERR 647 pr_err("ERROR: %s() fifo is NOT turned on. Timeout!\n",
648 "cx25821 ERROR: %s() fifo is NOT turned on. Timeout!\n", 648 __func__);
649 __func__);
650 return; 649 return;
651 } 650 }
652 651
@@ -696,8 +695,8 @@ int cx25821_start_audio_dma_upstream(struct cx25821_dev *dev,
696 request_irq(dev->pci->irq, cx25821_upstream_irq_audio, 695 request_irq(dev->pci->irq, cx25821_upstream_irq_audio,
697 IRQF_SHARED | IRQF_DISABLED, dev->name, dev); 696 IRQF_SHARED | IRQF_DISABLED, dev->name, dev);
698 if (err < 0) { 697 if (err < 0) {
699 printk(KERN_ERR "%s: can't get upstream IRQ %d\n", dev->name, 698 pr_err("%s: can't get upstream IRQ %d\n",
700 dev->pci->irq); 699 dev->name, dev->pci->irq);
701 goto fail_irq; 700 goto fail_irq;
702 } 701 }
703 702
@@ -726,7 +725,7 @@ int cx25821_audio_upstream_init(struct cx25821_dev *dev, int channel_select)
726 int str_length = 0; 725 int str_length = 0;
727 726
728 if (dev->_audio_is_running) { 727 if (dev->_audio_is_running) {
729 printk(KERN_WARNING "Audio Channel is still running so return!\n"); 728 pr_warn("Audio Channel is still running so return!\n");
730 return 0; 729 return 0;
731 } 730 }
732 731
@@ -740,7 +739,7 @@ int cx25821_audio_upstream_init(struct cx25821_dev *dev, int channel_select)
740 739
741 if (!dev->_irq_audio_queues) { 740 if (!dev->_irq_audio_queues) {
742 printk(KERN_DEBUG 741 printk(KERN_DEBUG
743 "cx25821 ERROR: create_singlethread_workqueue() for Audio FAILED!\n"); 742 pr_fmt("ERROR: create_singlethread_workqueue() for Audio FAILED!\n"));
744 return -ENOMEM; 743 return -ENOMEM;
745 } 744 }
746 745
@@ -787,8 +786,7 @@ int cx25821_audio_upstream_init(struct cx25821_dev *dev, int channel_select)
787 retval = 786 retval =
788 cx25821_audio_upstream_buffer_prepare(dev, sram_ch, _line_size); 787 cx25821_audio_upstream_buffer_prepare(dev, sram_ch, _line_size);
789 if (retval < 0) { 788 if (retval < 0) {
790 printk(KERN_ERR 789 pr_err("%s: Failed to set up Audio upstream buffers!\n",
791 "%s: Failed to set up Audio upstream buffers!\n",
792 dev->name); 790 dev->name);
793 goto error; 791 goto error;
794 } 792 }
diff --git a/drivers/staging/cx25821/cx25821-cards.c b/drivers/staging/cx25821/cx25821-cards.c
index da0f56d50e27..94e8d685c889 100644
--- a/drivers/staging/cx25821/cx25821-cards.c
+++ b/drivers/staging/cx25821/cx25821-cards.c
@@ -21,6 +21,8 @@
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */ 22 */
23 23
24#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
25
24#include <linux/init.h> 26#include <linux/init.h>
25#include <linux/module.h> 27#include <linux/module.h>
26#include <linux/pci.h> 28#include <linux/pci.h>
diff --git a/drivers/staging/cx25821/cx25821-core.c b/drivers/staging/cx25821/cx25821-core.c
index 300da319b065..a216b620b718 100644
--- a/drivers/staging/cx25821/cx25821-core.c
+++ b/drivers/staging/cx25821/cx25821-core.c
@@ -21,6 +21,8 @@
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */ 22 */
23 23
24#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
25
24#include <linux/i2c.h> 26#include <linux/i2c.h>
25#include <linux/slab.h> 27#include <linux/slab.h>
26#include "cx25821.h" 28#include "cx25821.h"
@@ -332,7 +334,7 @@ struct cx25821_dmaqueue mpegq;
332 334
333static int cx25821_risc_decode(u32 risc) 335static int cx25821_risc_decode(u32 risc)
334{ 336{
335 static char *instr[16] = { 337 static const char * const instr[16] = {
336 [RISC_SYNC >> 28] = "sync", 338 [RISC_SYNC >> 28] = "sync",
337 [RISC_WRITE >> 28] = "write", 339 [RISC_WRITE >> 28] = "write",
338 [RISC_WRITEC >> 28] = "writec", 340 [RISC_WRITEC >> 28] = "writec",
@@ -344,7 +346,7 @@ static int cx25821_risc_decode(u32 risc)
344 [RISC_WRITECM >> 28] = "writecm", 346 [RISC_WRITECM >> 28] = "writecm",
345 [RISC_WRITECR >> 28] = "writecr", 347 [RISC_WRITECR >> 28] = "writecr",
346 }; 348 };
347 static int incr[16] = { 349 static const int incr[16] = {
348 [RISC_WRITE >> 28] = 3, 350 [RISC_WRITE >> 28] = 3,
349 [RISC_JUMP >> 28] = 3, 351 [RISC_JUMP >> 28] = 3,
350 [RISC_SKIP >> 28] = 1, 352 [RISC_SKIP >> 28] = 1,
@@ -353,7 +355,7 @@ static int cx25821_risc_decode(u32 risc)
353 [RISC_WRITECM >> 28] = 3, 355 [RISC_WRITECM >> 28] = 3,
354 [RISC_WRITECR >> 28] = 4, 356 [RISC_WRITECR >> 28] = 4,
355 }; 357 };
356 static char *bits[] = { 358 static const char * const bits[] = {
357 "12", "13", "14", "resync", 359 "12", "13", "14", "resync",
358 "cnt0", "cnt1", "18", "19", 360 "cnt0", "cnt1", "18", "19",
359 "20", "21", "22", "23", 361 "20", "21", "22", "23",
@@ -361,13 +363,13 @@ static int cx25821_risc_decode(u32 risc)
361 }; 363 };
362 int i; 364 int i;
363 365
364 printk("0x%08x [ %s", risc, 366 pr_cont("0x%08x [ %s",
365 instr[risc >> 28] ? instr[risc >> 28] : "INVALID"); 367 risc, instr[risc >> 28] ? instr[risc >> 28] : "INVALID");
366 for (i = ARRAY_SIZE(bits) - 1; i >= 0; i--) { 368 for (i = ARRAY_SIZE(bits) - 1; i >= 0; i--) {
367 if (risc & (1 << (i + 12))) 369 if (risc & (1 << (i + 12)))
368 printk(" %s", bits[i]); 370 pr_cont(" %s", bits[i]);
369 } 371 }
370 printk(" count=%d ]\n", risc & 0xfff); 372 pr_cont(" count=%d ]\n", risc & 0xfff);
371 return incr[risc >> 28] ? incr[risc >> 28] : 1; 373 return incr[risc >> 28] ? incr[risc >> 28] : 1;
372} 374}
373 375
@@ -620,16 +622,15 @@ void cx25821_sram_channel_dump(struct cx25821_dev *dev, struct sram_channel *ch)
620 u32 risc; 622 u32 risc;
621 unsigned int i, j, n; 623 unsigned int i, j, n;
622 624
623 printk(KERN_WARNING "%s: %s - dma channel status dump\n", dev->name, 625 pr_warn("%s: %s - dma channel status dump\n", dev->name, ch->name);
624 ch->name);
625 for (i = 0; i < ARRAY_SIZE(name); i++) 626 for (i = 0; i < ARRAY_SIZE(name); i++)
626 printk(KERN_WARNING "cmds + 0x%2x: %-15s: 0x%08x\n", i * 4, 627 pr_warn("cmds + 0x%2x: %-15s: 0x%08x\n",
627 name[i], cx_read(ch->cmds_start + 4 * i)); 628 i * 4, name[i], cx_read(ch->cmds_start + 4 * i));
628 629
629 j = i * 4; 630 j = i * 4;
630 for (i = 0; i < 4;) { 631 for (i = 0; i < 4;) {
631 risc = cx_read(ch->cmds_start + 4 * (i + 14)); 632 risc = cx_read(ch->cmds_start + 4 * (i + 14));
632 printk(KERN_WARNING "cmds + 0x%2x: risc%d: ", j + i * 4, i); 633 pr_warn("cmds + 0x%2x: risc%d: ", j + i * 4, i);
633 i += cx25821_risc_decode(risc); 634 i += cx25821_risc_decode(risc);
634 } 635 }
635 636
@@ -637,36 +638,35 @@ void cx25821_sram_channel_dump(struct cx25821_dev *dev, struct sram_channel *ch)
637 risc = cx_read(ch->ctrl_start + 4 * i); 638 risc = cx_read(ch->ctrl_start + 4 * i);
638 /* No consideration for bits 63-32 */ 639 /* No consideration for bits 63-32 */
639 640
640 printk(KERN_WARNING "ctrl + 0x%2x (0x%08x): iq %x: ", i * 4, 641 pr_warn("ctrl + 0x%2x (0x%08x): iq %x: ",
641 ch->ctrl_start + 4 * i, i); 642 i * 4, ch->ctrl_start + 4 * i, i);
642 n = cx25821_risc_decode(risc); 643 n = cx25821_risc_decode(risc);
643 for (j = 1; j < n; j++) { 644 for (j = 1; j < n; j++) {
644 risc = cx_read(ch->ctrl_start + 4 * (i + j)); 645 risc = cx_read(ch->ctrl_start + 4 * (i + j));
645 printk(KERN_WARNING 646 pr_warn("ctrl + 0x%2x : iq %x: 0x%08x [ arg #%d ]\n",
646 "ctrl + 0x%2x : iq %x: 0x%08x [ arg #%d ]\n", 647 4 * (i + j), i + j, risc, j);
647 4 * (i + j), i + j, risc, j);
648 } 648 }
649 } 649 }
650 650
651 printk(KERN_WARNING " : fifo: 0x%08x -> 0x%x\n", 651 pr_warn(" : fifo: 0x%08x -> 0x%x\n",
652 ch->fifo_start, ch->fifo_start + ch->fifo_size); 652 ch->fifo_start, ch->fifo_start + ch->fifo_size);
653 printk(KERN_WARNING " : ctrl: 0x%08x -> 0x%x\n", 653 pr_warn(" : ctrl: 0x%08x -> 0x%x\n",
654 ch->ctrl_start, ch->ctrl_start + 6 * 16); 654 ch->ctrl_start, ch->ctrl_start + 6 * 16);
655 printk(KERN_WARNING " : ptr1_reg: 0x%08x\n", 655 pr_warn(" : ptr1_reg: 0x%08x\n",
656 cx_read(ch->ptr1_reg)); 656 cx_read(ch->ptr1_reg));
657 printk(KERN_WARNING " : ptr2_reg: 0x%08x\n", 657 pr_warn(" : ptr2_reg: 0x%08x\n",
658 cx_read(ch->ptr2_reg)); 658 cx_read(ch->ptr2_reg));
659 printk(KERN_WARNING " : cnt1_reg: 0x%08x\n", 659 pr_warn(" : cnt1_reg: 0x%08x\n",
660 cx_read(ch->cnt1_reg)); 660 cx_read(ch->cnt1_reg));
661 printk(KERN_WARNING " : cnt2_reg: 0x%08x\n", 661 pr_warn(" : cnt2_reg: 0x%08x\n",
662 cx_read(ch->cnt2_reg)); 662 cx_read(ch->cnt2_reg));
663} 663}
664EXPORT_SYMBOL(cx25821_sram_channel_dump); 664EXPORT_SYMBOL(cx25821_sram_channel_dump);
665 665
666void cx25821_sram_channel_dump_audio(struct cx25821_dev *dev, 666void cx25821_sram_channel_dump_audio(struct cx25821_dev *dev,
667 struct sram_channel *ch) 667 struct sram_channel *ch)
668{ 668{
669 static char *name[] = { 669 static const char * const name[] = {
670 "init risc lo", 670 "init risc lo",
671 "init risc hi", 671 "init risc hi",
672 "cdt base", 672 "cdt base",
@@ -686,18 +686,18 @@ void cx25821_sram_channel_dump_audio(struct cx25821_dev *dev,
686 u32 risc, value, tmp; 686 u32 risc, value, tmp;
687 unsigned int i, j, n; 687 unsigned int i, j, n;
688 688
689 printk(KERN_INFO "\n%s: %s - dma Audio channel status dump\n", 689 pr_info("\n%s: %s - dma Audio channel status dump\n",
690 dev->name, ch->name); 690 dev->name, ch->name);
691 691
692 for (i = 0; i < ARRAY_SIZE(name); i++) 692 for (i = 0; i < ARRAY_SIZE(name); i++)
693 printk(KERN_INFO "%s: cmds + 0x%2x: %-15s: 0x%08x\n", 693 pr_info("%s: cmds + 0x%2x: %-15s: 0x%08x\n",
694 dev->name, i * 4, name[i], 694 dev->name, i * 4, name[i],
695 cx_read(ch->cmds_start + 4 * i)); 695 cx_read(ch->cmds_start + 4 * i));
696 696
697 j = i * 4; 697 j = i * 4;
698 for (i = 0; i < 4;) { 698 for (i = 0; i < 4;) {
699 risc = cx_read(ch->cmds_start + 4 * (i + 14)); 699 risc = cx_read(ch->cmds_start + 4 * (i + 14));
700 printk(KERN_WARNING "cmds + 0x%2x: risc%d: ", j + i * 4, i); 700 pr_warn("cmds + 0x%2x: risc%d: ", j + i * 4, i);
701 i += cx25821_risc_decode(risc); 701 i += cx25821_risc_decode(risc);
702 } 702 }
703 703
@@ -705,44 +705,43 @@ void cx25821_sram_channel_dump_audio(struct cx25821_dev *dev,
705 risc = cx_read(ch->ctrl_start + 4 * i); 705 risc = cx_read(ch->ctrl_start + 4 * i);
706 /* No consideration for bits 63-32 */ 706 /* No consideration for bits 63-32 */
707 707
708 printk(KERN_WARNING "ctrl + 0x%2x (0x%08x): iq %x: ", i * 4, 708 pr_warn("ctrl + 0x%2x (0x%08x): iq %x: ",
709 ch->ctrl_start + 4 * i, i); 709 i * 4, ch->ctrl_start + 4 * i, i);
710 n = cx25821_risc_decode(risc); 710 n = cx25821_risc_decode(risc);
711 711
712 for (j = 1; j < n; j++) { 712 for (j = 1; j < n; j++) {
713 risc = cx_read(ch->ctrl_start + 4 * (i + j)); 713 risc = cx_read(ch->ctrl_start + 4 * (i + j));
714 printk(KERN_WARNING 714 pr_warn("ctrl + 0x%2x : iq %x: 0x%08x [ arg #%d ]\n",
715 "ctrl + 0x%2x : iq %x: 0x%08x [ arg #%d ]\n", 715 4 * (i + j), i + j, risc, j);
716 4 * (i + j), i + j, risc, j);
717 } 716 }
718 } 717 }
719 718
720 printk(KERN_WARNING " : fifo: 0x%08x -> 0x%x\n", 719 pr_warn(" : fifo: 0x%08x -> 0x%x\n",
721 ch->fifo_start, ch->fifo_start + ch->fifo_size); 720 ch->fifo_start, ch->fifo_start + ch->fifo_size);
722 printk(KERN_WARNING " : ctrl: 0x%08x -> 0x%x\n", 721 pr_warn(" : ctrl: 0x%08x -> 0x%x\n",
723 ch->ctrl_start, ch->ctrl_start + 6 * 16); 722 ch->ctrl_start, ch->ctrl_start + 6 * 16);
724 printk(KERN_WARNING " : ptr1_reg: 0x%08x\n", 723 pr_warn(" : ptr1_reg: 0x%08x\n",
725 cx_read(ch->ptr1_reg)); 724 cx_read(ch->ptr1_reg));
726 printk(KERN_WARNING " : ptr2_reg: 0x%08x\n", 725 pr_warn(" : ptr2_reg: 0x%08x\n",
727 cx_read(ch->ptr2_reg)); 726 cx_read(ch->ptr2_reg));
728 printk(KERN_WARNING " : cnt1_reg: 0x%08x\n", 727 pr_warn(" : cnt1_reg: 0x%08x\n",
729 cx_read(ch->cnt1_reg)); 728 cx_read(ch->cnt1_reg));
730 printk(KERN_WARNING " : cnt2_reg: 0x%08x\n", 729 pr_warn(" : cnt2_reg: 0x%08x\n",
731 cx_read(ch->cnt2_reg)); 730 cx_read(ch->cnt2_reg));
732 731
733 for (i = 0; i < 4; i++) { 732 for (i = 0; i < 4; i++) {
734 risc = cx_read(ch->cmds_start + 56 + (i * 4)); 733 risc = cx_read(ch->cmds_start + 56 + (i * 4));
735 printk(KERN_WARNING "instruction %d = 0x%x\n", i, risc); 734 pr_warn("instruction %d = 0x%x\n", i, risc);
736 } 735 }
737 736
738 /* read data from the first cdt buffer */ 737 /* read data from the first cdt buffer */
739 risc = cx_read(AUD_A_CDT); 738 risc = cx_read(AUD_A_CDT);
740 printk(KERN_WARNING "\nread cdt loc=0x%x\n", risc); 739 pr_warn("\nread cdt loc=0x%x\n", risc);
741 for (i = 0; i < 8; i++) { 740 for (i = 0; i < 8; i++) {
742 n = cx_read(risc + i * 4); 741 n = cx_read(risc + i * 4);
743 printk(KERN_WARNING "0x%x ", n); 742 pr_cont("0x%x ", n);
744 } 743 }
745 printk(KERN_WARNING "\n\n"); 744 pr_cont("\n\n");
746 745
747 value = cx_read(CLK_RST); 746 value = cx_read(CLK_RST);
748 CX25821_INFO(" CLK_RST = 0x%x\n\n", value); 747 CX25821_INFO(" CLK_RST = 0x%x\n\n", value);
@@ -870,7 +869,7 @@ static int cx25821_get_resources(struct cx25821_dev *dev)
870 dev->name)) 869 dev->name))
871 return 0; 870 return 0;
872 871
873 printk(KERN_ERR "%s: can't get MMIO memory @ 0x%llx\n", 872 pr_err("%s: can't get MMIO memory @ 0x%llx\n",
874 dev->name, (unsigned long long)pci_resource_start(dev->pci, 0)); 873 dev->name, (unsigned long long)pci_resource_start(dev->pci, 0));
875 874
876 return -EBUSY; 875 return -EBUSY;
@@ -880,8 +879,8 @@ static void cx25821_dev_checkrevision(struct cx25821_dev *dev)
880{ 879{
881 dev->hwrevision = cx_read(RDR_CFG2) & 0xff; 880 dev->hwrevision = cx_read(RDR_CFG2) & 0xff;
882 881
883 printk(KERN_INFO "%s() Hardware revision = 0x%02x\n", __func__, 882 pr_info("%s(): Hardware revision = 0x%02x\n",
884 dev->hwrevision); 883 __func__, dev->hwrevision);
885} 884}
886 885
887static void cx25821_iounmap(struct cx25821_dev *dev) 886static void cx25821_iounmap(struct cx25821_dev *dev)
@@ -901,9 +900,9 @@ static int cx25821_dev_setup(struct cx25821_dev *dev)
901{ 900{
902 int io_size = 0, i; 901 int io_size = 0, i;
903 902
904 printk(KERN_INFO "\n***********************************\n"); 903 pr_info("\n***********************************\n");
905 printk(KERN_INFO "cx25821 set up\n"); 904 pr_info("cx25821 set up\n");
906 printk(KERN_INFO "***********************************\n\n"); 905 pr_info("***********************************\n\n");
907 906
908 mutex_init(&dev->lock); 907 mutex_init(&dev->lock);
909 908
@@ -920,13 +919,11 @@ static int cx25821_dev_setup(struct cx25821_dev *dev)
920 strcpy(cx25821_boards[CX25821_BOARD].name, "cx25821"); 919 strcpy(cx25821_boards[CX25821_BOARD].name, "cx25821");
921 920
922 if (dev->pci->device != 0x8210) { 921 if (dev->pci->device != 0x8210) {
923 printk(KERN_INFO 922 pr_info("%s(): Exiting. Incorrect Hardware device = 0x%02x\n",
924 "%s() Exiting. Incorrect Hardware device = 0x%02x\n", 923 __func__, dev->pci->device);
925 __func__, dev->pci->device);
926 return -1; 924 return -1;
927 } else { 925 } else {
928 printk(KERN_INFO "Athena Hardware device = 0x%02x\n", 926 pr_info("Athena Hardware device = 0x%02x\n", dev->pci->device);
929 dev->pci->device);
930 } 927 }
931 928
932 /* Apply a sensible clock frequency for the PCIe bridge */ 929 /* Apply a sensible clock frequency for the PCIe bridge */
@@ -956,8 +953,7 @@ static int cx25821_dev_setup(struct cx25821_dev *dev)
956 dev->i2c_bus[0].i2c_period = (0x07 << 24); /* 1.95MHz */ 953 dev->i2c_bus[0].i2c_period = (0x07 << 24); /* 1.95MHz */
957 954
958 if (cx25821_get_resources(dev) < 0) { 955 if (cx25821_get_resources(dev) < 0) {
959 printk(KERN_ERR "%s No more PCIe resources for " 956 pr_err("%s: No more PCIe resources for subsystem: %04x:%04x\n",
960 "subsystem: %04x:%04x\n",
961 dev->name, dev->pci->subsystem_vendor, 957 dev->name, dev->pci->subsystem_vendor,
962 dev->pci->subsystem_device); 958 dev->pci->subsystem_device);
963 959
@@ -985,11 +981,11 @@ static int cx25821_dev_setup(struct cx25821_dev *dev)
985 981
986 dev->bmmio = (u8 __iomem *) dev->lmmio; 982 dev->bmmio = (u8 __iomem *) dev->lmmio;
987 983
988 printk(KERN_INFO "%s: subsystem: %04x:%04x, board: %s [card=%d,%s]\n", 984 pr_info("%s: subsystem: %04x:%04x, board: %s [card=%d,%s]\n",
989 dev->name, dev->pci->subsystem_vendor, 985 dev->name, dev->pci->subsystem_vendor,
990 dev->pci->subsystem_device, cx25821_boards[dev->board].name, 986 dev->pci->subsystem_device, cx25821_boards[dev->board].name,
991 dev->board, card[dev->nr] == dev->board ? 987 dev->board, card[dev->nr] == dev->board ?
992 "insmod option" : "autodetected"); 988 "insmod option" : "autodetected");
993 989
994 /* init hardware */ 990 /* init hardware */
995 cx25821_initialize(dev); 991 cx25821_initialize(dev);
@@ -1004,8 +1000,7 @@ static int cx25821_dev_setup(struct cx25821_dev *dev)
1004 cx25821_card_setup(dev); 1000 cx25821_card_setup(dev);
1005 1001
1006 if (medusa_video_init(dev) < 0) 1002 if (medusa_video_init(dev) < 0)
1007 CX25821_ERR("%s() Failed to initialize medusa!\n" 1003 CX25821_ERR("%s(): Failed to initialize medusa!\n", __func__);
1008 , __func__);
1009 1004
1010 cx25821_video_register(dev); 1005 cx25821_video_register(dev);
1011 1006
@@ -1017,13 +1012,12 @@ static int cx25821_dev_setup(struct cx25821_dev *dev)
1017 if (video_register_device 1012 if (video_register_device
1018 (dev->ioctl_dev, VFL_TYPE_GRABBER, VIDEO_IOCTL_CH) < 0) { 1013 (dev->ioctl_dev, VFL_TYPE_GRABBER, VIDEO_IOCTL_CH) < 0) {
1019 cx25821_videoioctl_unregister(dev); 1014 cx25821_videoioctl_unregister(dev);
1020 printk(KERN_ERR 1015 pr_err("%s(): Failed to register video adapter for IOCTL, so unregistering videoioctl device\n",
1021 "%s() Failed to register video adapter for IOCTL, so \ 1016 __func__);
1022 unregistering videoioctl device.\n", __func__);
1023 } 1017 }
1024 1018
1025 cx25821_dev_checkrevision(dev); 1019 cx25821_dev_checkrevision(dev);
1026 CX25821_INFO("cx25821 setup done!\n"); 1020 CX25821_INFO("setup done!\n");
1027 1021
1028 return 0; 1022 return 0;
1029} 1023}
@@ -1362,20 +1356,20 @@ void cx25821_print_irqbits(char *name, char *tag, char **strings,
1362{ 1356{
1363 unsigned int i; 1357 unsigned int i;
1364 1358
1365 printk(KERN_DEBUG "%s: %s [0x%x]", name, tag, bits); 1359 printk(KERN_DEBUG pr_fmt("%s: %s [0x%x]"), name, tag, bits);
1366 1360
1367 for (i = 0; i < len; i++) { 1361 for (i = 0; i < len; i++) {
1368 if (!(bits & (1 << i))) 1362 if (!(bits & (1 << i)))
1369 continue; 1363 continue;
1370 if (strings[i]) 1364 if (strings[i])
1371 printk(" %s", strings[i]); 1365 pr_cont(" %s", strings[i]);
1372 else 1366 else
1373 printk(" %d", i); 1367 pr_cont(" %d", i);
1374 if (!(mask & (1 << i))) 1368 if (!(mask & (1 << i)))
1375 continue; 1369 continue;
1376 printk("*"); 1370 pr_cont("*");
1377 } 1371 }
1378 printk("\n"); 1372 pr_cont("\n");
1379} 1373}
1380EXPORT_SYMBOL(cx25821_print_irqbits); 1374EXPORT_SYMBOL(cx25821_print_irqbits);
1381 1375
@@ -1405,12 +1399,12 @@ static int __devinit cx25821_initdev(struct pci_dev *pci_dev,
1405 if (pci_enable_device(pci_dev)) { 1399 if (pci_enable_device(pci_dev)) {
1406 err = -EIO; 1400 err = -EIO;
1407 1401
1408 printk(KERN_INFO "pci enable failed! "); 1402 pr_info("pci enable failed!\n");
1409 1403
1410 goto fail_unregister_device; 1404 goto fail_unregister_device;
1411 } 1405 }
1412 1406
1413 printk(KERN_INFO "cx25821 Athena pci enable !\n"); 1407 pr_info("Athena pci enable !\n");
1414 1408
1415 err = cx25821_dev_setup(dev); 1409 err = cx25821_dev_setup(dev);
1416 if (err) { 1410 if (err) {
@@ -1423,14 +1417,13 @@ static int __devinit cx25821_initdev(struct pci_dev *pci_dev,
1423 /* print pci info */ 1417 /* print pci info */
1424 pci_read_config_byte(pci_dev, PCI_CLASS_REVISION, &dev->pci_rev); 1418 pci_read_config_byte(pci_dev, PCI_CLASS_REVISION, &dev->pci_rev);
1425 pci_read_config_byte(pci_dev, PCI_LATENCY_TIMER, &dev->pci_lat); 1419 pci_read_config_byte(pci_dev, PCI_LATENCY_TIMER, &dev->pci_lat);
1426 printk(KERN_INFO "%s/0: found at %s, rev: %d, irq: %d, " 1420 pr_info("%s/0: found at %s, rev: %d, irq: %d, latency: %d, mmio: 0x%llx\n",
1427 "latency: %d, mmio: 0x%llx\n", dev->name, 1421 dev->name, pci_name(pci_dev), dev->pci_rev, pci_dev->irq,
1428 pci_name(pci_dev), dev->pci_rev, pci_dev->irq, 1422 dev->pci_lat, (unsigned long long)dev->base_io_addr);
1429 dev->pci_lat, (unsigned long long)dev->base_io_addr);
1430 1423
1431 pci_set_master(pci_dev); 1424 pci_set_master(pci_dev);
1432 if (!pci_dma_supported(pci_dev, 0xffffffff)) { 1425 if (!pci_dma_supported(pci_dev, 0xffffffff)) {
1433 printk("%s/0: Oops: no 32bit PCI DMA ???\n", dev->name); 1426 pr_err("%s/0: Oops: no 32bit PCI DMA ???\n", dev->name);
1434 err = -EIO; 1427 err = -EIO;
1435 goto fail_irq; 1428 goto fail_irq;
1436 } 1429 }
@@ -1440,15 +1433,14 @@ static int __devinit cx25821_initdev(struct pci_dev *pci_dev,
1440 dev->name, dev); 1433 dev->name, dev);
1441 1434
1442 if (err < 0) { 1435 if (err < 0) {
1443 printk(KERN_ERR "%s: can't get IRQ %d\n", dev->name, 1436 pr_err("%s: can't get IRQ %d\n", dev->name, pci_dev->irq);
1444 pci_dev->irq);
1445 goto fail_irq; 1437 goto fail_irq;
1446 } 1438 }
1447 1439
1448 return 0; 1440 return 0;
1449 1441
1450fail_irq: 1442fail_irq:
1451 printk(KERN_INFO "cx25821 cx25821_initdev() can't get IRQ !\n"); 1443 pr_info("cx25821_initdev() can't get IRQ !\n");
1452 cx25821_dev_unregister(dev); 1444 cx25821_dev_unregister(dev);
1453 1445
1454fail_unregister_pci: 1446fail_unregister_pci:
@@ -1510,9 +1502,10 @@ static struct pci_driver cx25821_pci_driver = {
1510static int __init cx25821_init(void) 1502static int __init cx25821_init(void)
1511{ 1503{
1512 INIT_LIST_HEAD(&cx25821_devlist); 1504 INIT_LIST_HEAD(&cx25821_devlist);
1513 printk(KERN_INFO "cx25821 driver version %d.%d.%d loaded\n", 1505 pr_info("driver version %d.%d.%d loaded\n",
1514 (CX25821_VERSION_CODE >> 16) & 0xff, 1506 (CX25821_VERSION_CODE >> 16) & 0xff,
1515 (CX25821_VERSION_CODE >> 8) & 0xff, CX25821_VERSION_CODE & 0xff); 1507 (CX25821_VERSION_CODE >> 8) & 0xff,
1508 CX25821_VERSION_CODE & 0xff);
1516 return pci_register_driver(&cx25821_pci_driver); 1509 return pci_register_driver(&cx25821_pci_driver);
1517} 1510}
1518 1511
diff --git a/drivers/staging/cx25821/cx25821-i2c.c b/drivers/staging/cx25821/cx25821-i2c.c
index 2b14bcca6897..130dfebebe20 100644
--- a/drivers/staging/cx25821/cx25821-i2c.c
+++ b/drivers/staging/cx25821/cx25821-i2c.c
@@ -21,6 +21,8 @@
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */ 22 */
23 23
24#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
25
24#include "cx25821.h" 26#include "cx25821.h"
25#include <linux/i2c.h> 27#include <linux/i2c.h>
26 28
@@ -32,10 +34,11 @@ static unsigned int i2c_scan;
32module_param(i2c_scan, int, 0444); 34module_param(i2c_scan, int, 0444);
33MODULE_PARM_DESC(i2c_scan, "scan i2c bus at insmod time"); 35MODULE_PARM_DESC(i2c_scan, "scan i2c bus at insmod time");
34 36
35#define dprintk(level, fmt, arg...)\ 37#define dprintk(level, fmt, arg...) \
36 do { if (i2c_debug >= level)\ 38do { \
37 printk(KERN_DEBUG "%s/0: " fmt, dev->name, ## arg);\ 39 if (i2c_debug >= level) \
38 } while (0) 40 printk(KERN_DEBUG "%s/0: " fmt, dev->name, ##arg); \
41} while (0)
39 42
40#define I2C_WAIT_DELAY 32 43#define I2C_WAIT_DELAY 32
41#define I2C_WAIT_RETRY 64 44#define I2C_WAIT_RETRY 64
@@ -98,7 +101,7 @@ static int i2c_sendbytes(struct i2c_adapter *i2c_adap,
98 if (!i2c_slave_did_ack(i2c_adap)) 101 if (!i2c_slave_did_ack(i2c_adap))
99 return -EIO; 102 return -EIO;
100 103
101 dprintk(1, "%s() returns 0\n", __func__); 104 dprintk(1, "%s(): returns 0\n", __func__);
102 return 0; 105 return 0;
103 } 106 }
104 107
@@ -163,7 +166,7 @@ eio:
163 retval = -EIO; 166 retval = -EIO;
164err: 167err:
165 if (i2c_debug) 168 if (i2c_debug)
166 printk(KERN_ERR " ERR: %d\n", retval); 169 pr_err(" ERR: %d\n", retval);
167 return retval; 170 return retval;
168} 171}
169 172
@@ -187,7 +190,7 @@ static int i2c_readbytes(struct i2c_adapter *i2c_adap,
187 if (!i2c_slave_did_ack(i2c_adap)) 190 if (!i2c_slave_did_ack(i2c_adap))
188 return -EIO; 191 return -EIO;
189 192
190 dprintk(1, "%s() returns 0\n", __func__); 193 dprintk(1, "%s(): returns 0\n", __func__);
191 return 0; 194 return 0;
192 } 195 }
193 196
@@ -227,7 +230,7 @@ eio:
227 retval = -EIO; 230 retval = -EIO;
228err: 231err:
229 if (i2c_debug) 232 if (i2c_debug)
230 printk(KERN_ERR " ERR: %d\n", retval); 233 pr_err(" ERR: %d\n", retval);
231 return retval; 234 return retval;
232} 235}
233 236
diff --git a/drivers/staging/cx25821/cx25821-medusa-video.c b/drivers/staging/cx25821/cx25821-medusa-video.c
index 1e11e0ce2d0a..fc780d0908dc 100644
--- a/drivers/staging/cx25821/cx25821-medusa-video.c
+++ b/drivers/staging/cx25821/cx25821-medusa-video.c
@@ -20,6 +20,8 @@
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */ 21 */
22 22
23#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
24
23#include "cx25821.h" 25#include "cx25821.h"
24#include "cx25821-medusa-video.h" 26#include "cx25821-medusa-video.h"
25#include "cx25821-biffuncs.h" 27#include "cx25821-biffuncs.h"
@@ -499,9 +501,8 @@ void medusa_set_resolution(struct cx25821_dev *dev, int width,
499 501
500 /* validate the width - cannot be negative */ 502 /* validate the width - cannot be negative */
501 if (width > MAX_WIDTH) { 503 if (width > MAX_WIDTH) {
502 printk 504 pr_info("%s(): width %d > MAX_WIDTH %d ! resetting to MAX_WIDTH\n",
503 ("cx25821 %s() : width %d > MAX_WIDTH %d ! resetting to MAX_WIDTH\n", 505 __func__, width, MAX_WIDTH);
504 __func__, width, MAX_WIDTH);
505 width = MAX_WIDTH; 506 width = MAX_WIDTH;
506 } 507 }
507 508
diff --git a/drivers/staging/cx25821/cx25821-video-upstream-ch2.c b/drivers/staging/cx25821/cx25821-video-upstream-ch2.c
index 405e2db72b0f..e2efacdfb874 100644
--- a/drivers/staging/cx25821/cx25821-video-upstream-ch2.c
+++ b/drivers/staging/cx25821/cx25821-video-upstream-ch2.c
@@ -20,6 +20,8 @@
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */ 21 */
22 22
23#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
24
23#include "cx25821-video.h" 25#include "cx25821-video.h"
24#include "cx25821-video-upstream-ch2.h" 26#include "cx25821-video-upstream-ch2.h"
25 27
@@ -211,8 +213,7 @@ void cx25821_stop_upstream_video_ch2(struct cx25821_dev *dev)
211 u32 tmp = 0; 213 u32 tmp = 0;
212 214
213 if (!dev->_is_running_ch2) { 215 if (!dev->_is_running_ch2) {
214 printk 216 pr_info("No video file is currently running so return!\n");
215 ("cx25821: No video file is currently running so return!\n");
216 return; 217 return;
217 } 218 }
218 /* Disable RISC interrupts */ 219 /* Disable RISC interrupts */
@@ -301,19 +302,19 @@ int cx25821_get_frame_ch2(struct cx25821_dev *dev, struct sram_channel *sram_ch)
301 myfile = filp_open(dev->_filename_ch2, O_RDONLY | O_LARGEFILE, 0); 302 myfile = filp_open(dev->_filename_ch2, O_RDONLY | O_LARGEFILE, 0);
302 if (IS_ERR(myfile)) { 303 if (IS_ERR(myfile)) {
303 const int open_errno = -PTR_ERR(myfile); 304 const int open_errno = -PTR_ERR(myfile);
304 printk("%s(): ERROR opening file(%s) with errno = %d!\n", 305 pr_err("%s(): ERROR opening file(%s) with errno = %d!\n",
305 __func__, dev->_filename_ch2, open_errno); 306 __func__, dev->_filename_ch2, open_errno);
306 return PTR_ERR(myfile); 307 return PTR_ERR(myfile);
307 } else { 308 } else {
308 if (!(myfile->f_op)) { 309 if (!(myfile->f_op)) {
309 printk("%s: File has no file operations registered!", 310 pr_err("%s(): File has no file operations registered!\n",
310 __func__); 311 __func__);
311 filp_close(myfile, NULL); 312 filp_close(myfile, NULL);
312 return -EIO; 313 return -EIO;
313 } 314 }
314 315
315 if (!myfile->f_op->read) { 316 if (!myfile->f_op->read) {
316 printk("%s: File has no READ operations registered!", 317 pr_err("%s(): File has no READ operations registered!\n",
317 __func__); 318 __func__);
318 filp_close(myfile, NULL); 319 filp_close(myfile, NULL);
319 return -EIO; 320 return -EIO;
@@ -340,9 +341,8 @@ int cx25821_get_frame_ch2(struct cx25821_dev *dev, struct sram_channel *sram_ch)
340 frame_offset += vfs_read_retval; 341 frame_offset += vfs_read_retval;
341 342
342 if (vfs_read_retval < line_size) { 343 if (vfs_read_retval < line_size) {
343 printk(KERN_INFO 344 pr_info("Done: exit %s() since no more bytes to read from Video file\n",
344 "Done: exit %s() since no more bytes to read from Video file.\n", 345 __func__);
345 __func__);
346 break; 346 break;
347 } 347 }
348 } 348 }
@@ -366,8 +366,8 @@ static void cx25821_vidups_handler_ch2(struct work_struct *work)
366 container_of(work, struct cx25821_dev, _irq_work_entry_ch2); 366 container_of(work, struct cx25821_dev, _irq_work_entry_ch2);
367 367
368 if (!dev) { 368 if (!dev) {
369 printk("ERROR %s(): since container_of(work_struct) FAILED!\n", 369 pr_err("ERROR %s(): since container_of(work_struct) FAILED!\n",
370 __func__); 370 __func__);
371 return; 371 return;
372 } 372 }
373 373
@@ -393,21 +393,20 @@ int cx25821_openfile_ch2(struct cx25821_dev *dev, struct sram_channel *sram_ch)
393 393
394 if (IS_ERR(myfile)) { 394 if (IS_ERR(myfile)) {
395 const int open_errno = -PTR_ERR(myfile); 395 const int open_errno = -PTR_ERR(myfile);
396 printk("%s(): ERROR opening file(%s) with errno = %d!\n", 396 pr_err("%s(): ERROR opening file(%s) with errno = %d!\n",
397 __func__, dev->_filename_ch2, open_errno); 397 __func__, dev->_filename_ch2, open_errno);
398 return PTR_ERR(myfile); 398 return PTR_ERR(myfile);
399 } else { 399 } else {
400 if (!(myfile->f_op)) { 400 if (!(myfile->f_op)) {
401 printk("%s: File has no file operations registered!", 401 pr_err("%s(): File has no file operations registered!\n",
402 __func__); 402 __func__);
403 filp_close(myfile, NULL); 403 filp_close(myfile, NULL);
404 return -EIO; 404 return -EIO;
405 } 405 }
406 406
407 if (!myfile->f_op->read) { 407 if (!myfile->f_op->read) {
408 printk 408 pr_err("%s(): File has no READ operations registered! Returning\n",
409 ("%s: File has no READ operations registered! Returning.", 409 __func__);
410 __func__);
411 filp_close(myfile, NULL); 410 filp_close(myfile, NULL);
412 return -EIO; 411 return -EIO;
413 } 412 }
@@ -435,9 +434,8 @@ int cx25821_openfile_ch2(struct cx25821_dev *dev, struct sram_channel *sram_ch)
435 offset += vfs_read_retval; 434 offset += vfs_read_retval;
436 435
437 if (vfs_read_retval < line_size) { 436 if (vfs_read_retval < line_size) {
438 printk(KERN_INFO 437 pr_info("Done: exit %s() since no more bytes to read from Video file\n",
439 "Done: exit %s() since no more bytes to read from Video file.\n", 438 __func__);
440 __func__);
441 break; 439 break;
442 } 440 }
443 } 441 }
@@ -483,8 +481,7 @@ static int cx25821_upstream_buffer_prepare_ch2(struct cx25821_dev *dev,
483 dev->_risc_size_ch2 = dev->upstream_riscbuf_size_ch2; 481 dev->_risc_size_ch2 = dev->upstream_riscbuf_size_ch2;
484 482
485 if (!dev->_dma_virt_addr_ch2) { 483 if (!dev->_dma_virt_addr_ch2) {
486 printk 484 pr_err("FAILED to allocate memory for Risc buffer! Returning\n");
487 ("cx25821: FAILED to allocate memory for Risc buffer! Returning.\n");
488 return -ENOMEM; 485 return -ENOMEM;
489 } 486 }
490 487
@@ -504,8 +501,7 @@ static int cx25821_upstream_buffer_prepare_ch2(struct cx25821_dev *dev,
504 dev->_data_buf_size_ch2 = dev->upstream_databuf_size_ch2; 501 dev->_data_buf_size_ch2 = dev->upstream_databuf_size_ch2;
505 502
506 if (!dev->_data_buf_virt_addr_ch2) { 503 if (!dev->_data_buf_virt_addr_ch2) {
507 printk 504 pr_err("FAILED to allocate memory for data buffer! Returning\n");
508 ("cx25821: FAILED to allocate memory for data buffer! Returning.\n");
509 return -ENOMEM; 505 return -ENOMEM;
510 } 506 }
511 507
@@ -521,8 +517,7 @@ static int cx25821_upstream_buffer_prepare_ch2(struct cx25821_dev *dev,
521 cx25821_risc_buffer_upstream_ch2(dev, dev->pci, 0, bpl, 517 cx25821_risc_buffer_upstream_ch2(dev, dev->pci, 0, bpl,
522 dev->_lines_count_ch2); 518 dev->_lines_count_ch2);
523 if (ret < 0) { 519 if (ret < 0) {
524 printk(KERN_INFO 520 pr_info("Failed creating Video Upstream Risc programs!\n");
525 "cx25821: Failed creating Video Upstream Risc programs!\n");
526 goto error; 521 goto error;
527 } 522 }
528 523
@@ -602,8 +597,8 @@ int cx25821_video_upstream_irq_ch2(struct cx25821_dev *dev, int chan_num,
602 } 597 }
603 598
604 if (dev->_file_status_ch2 == END_OF_FILE) { 599 if (dev->_file_status_ch2 == END_OF_FILE) {
605 printk("cx25821: EOF Channel 2 Framecount = %d\n", 600 pr_info("EOF Channel 2 Framecount = %d\n",
606 dev->_frame_count_ch2); 601 dev->_frame_count_ch2);
607 return -1; 602 return -1;
608 } 603 }
609 /* ElSE, set the interrupt mask register, re-enable irq. */ 604 /* ElSE, set the interrupt mask register, re-enable irq. */
@@ -714,8 +709,8 @@ int cx25821_start_video_dma_upstream_ch2(struct cx25821_dev *dev,
714 request_irq(dev->pci->irq, cx25821_upstream_irq_ch2, 709 request_irq(dev->pci->irq, cx25821_upstream_irq_ch2,
715 IRQF_SHARED | IRQF_DISABLED, dev->name, dev); 710 IRQF_SHARED | IRQF_DISABLED, dev->name, dev);
716 if (err < 0) { 711 if (err < 0) {
717 printk(KERN_ERR "%s: can't get upstream IRQ %d\n", dev->name, 712 pr_err("%s: can't get upstream IRQ %d\n",
718 dev->pci->irq); 713 dev->name, dev->pci->irq);
719 goto fail_irq; 714 goto fail_irq;
720 } 715 }
721 /* Start the DMA engine */ 716 /* Start the DMA engine */
@@ -744,7 +739,7 @@ int cx25821_vidupstream_init_ch2(struct cx25821_dev *dev, int channel_select,
744 int str_length = 0; 739 int str_length = 0;
745 740
746 if (dev->_is_running_ch2) { 741 if (dev->_is_running_ch2) {
747 printk("Video Channel is still running so return!\n"); 742 pr_info("Video Channel is still running so return!\n");
748 return 0; 743 return 0;
749 } 744 }
750 745
@@ -756,8 +751,7 @@ int cx25821_vidupstream_init_ch2(struct cx25821_dev *dev, int channel_select,
756 create_singlethread_workqueue("cx25821_workqueue2"); 751 create_singlethread_workqueue("cx25821_workqueue2");
757 752
758 if (!dev->_irq_queues_ch2) { 753 if (!dev->_irq_queues_ch2) {
759 printk 754 pr_err("create_singlethread_workqueue() for Video FAILED!\n");
760 ("cx25821: create_singlethread_workqueue() for Video FAILED!\n");
761 return -ENOMEM; 755 return -ENOMEM;
762 } 756 }
763 /* 757 /*
@@ -829,8 +823,7 @@ int cx25821_vidupstream_init_ch2(struct cx25821_dev *dev, int channel_select,
829 cx25821_upstream_buffer_prepare_ch2(dev, sram_ch, 823 cx25821_upstream_buffer_prepare_ch2(dev, sram_ch,
830 dev->_line_size_ch2); 824 dev->_line_size_ch2);
831 if (retval < 0) { 825 if (retval < 0) {
832 printk(KERN_ERR 826 pr_err("%s: Failed to set up Video upstream buffers!\n",
833 "%s: Failed to set up Video upstream buffers!\n",
834 dev->name); 827 dev->name);
835 goto error; 828 goto error;
836 } 829 }
diff --git a/drivers/staging/cx25821/cx25821-video-upstream.c b/drivers/staging/cx25821/cx25821-video-upstream.c
index 16bf74d65912..31b4e3c74c8d 100644
--- a/drivers/staging/cx25821/cx25821-video-upstream.c
+++ b/drivers/staging/cx25821/cx25821-video-upstream.c
@@ -20,6 +20,8 @@
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */ 21 */
22 22
23#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
24
23#include "cx25821-video.h" 25#include "cx25821-video.h"
24#include "cx25821-video-upstream.h" 26#include "cx25821-video-upstream.h"
25 27
@@ -257,8 +259,7 @@ void cx25821_stop_upstream_video_ch1(struct cx25821_dev *dev)
257 u32 tmp = 0; 259 u32 tmp = 0;
258 260
259 if (!dev->_is_running) { 261 if (!dev->_is_running) {
260 printk 262 pr_info("No video file is currently running so return!\n");
261 (KERN_INFO "cx25821: No video file is currently running so return!\n");
262 return; 263 return;
263 } 264 }
264 /* Disable RISC interrupts */ 265 /* Disable RISC interrupts */
@@ -346,23 +347,20 @@ int cx25821_get_frame(struct cx25821_dev *dev, struct sram_channel *sram_ch)
346 347
347 if (IS_ERR(myfile)) { 348 if (IS_ERR(myfile)) {
348 const int open_errno = -PTR_ERR(myfile); 349 const int open_errno = -PTR_ERR(myfile);
349 printk(KERN_ERR 350 pr_err("%s(): ERROR opening file(%s) with errno = %d!\n",
350 "%s(): ERROR opening file(%s) with errno = %d!\n", 351 __func__, dev->_filename, open_errno);
351 __func__, dev->_filename, open_errno);
352 return PTR_ERR(myfile); 352 return PTR_ERR(myfile);
353 } else { 353 } else {
354 if (!(myfile->f_op)) { 354 if (!(myfile->f_op)) {
355 printk(KERN_ERR 355 pr_err("%s(): File has no file operations registered!\n",
356 "%s: File has no file operations registered!", 356 __func__);
357 __func__);
358 filp_close(myfile, NULL); 357 filp_close(myfile, NULL);
359 return -EIO; 358 return -EIO;
360 } 359 }
361 360
362 if (!myfile->f_op->read) { 361 if (!myfile->f_op->read) {
363 printk(KERN_ERR 362 pr_err("%s(): File has no READ operations registered!\n",
364 "%s: File has no READ operations registered!", 363 __func__);
365 __func__);
366 filp_close(myfile, NULL); 364 filp_close(myfile, NULL);
367 return -EIO; 365 return -EIO;
368 } 366 }
@@ -388,10 +386,8 @@ int cx25821_get_frame(struct cx25821_dev *dev, struct sram_channel *sram_ch)
388 frame_offset += vfs_read_retval; 386 frame_offset += vfs_read_retval;
389 387
390 if (vfs_read_retval < line_size) { 388 if (vfs_read_retval < line_size) {
391 printk(KERN_INFO 389 pr_info("Done: exit %s() since no more bytes to read from Video file\n",
392 "Done: exit %s() since no more bytes to \ 390 __func__);
393 read from Video file.\n",
394 __func__);
395 break; 391 break;
396 } 392 }
397 } 393 }
@@ -415,9 +411,8 @@ static void cx25821_vidups_handler(struct work_struct *work)
415 container_of(work, struct cx25821_dev, _irq_work_entry); 411 container_of(work, struct cx25821_dev, _irq_work_entry);
416 412
417 if (!dev) { 413 if (!dev) {
418 printk(KERN_ERR 414 pr_err("ERROR %s(): since container_of(work_struct) FAILED!\n",
419 "ERROR %s(): since container_of(work_struct) FAILED!\n", 415 __func__);
420 __func__);
421 return; 416 return;
422 } 417 }
423 418
@@ -443,23 +438,20 @@ int cx25821_openfile(struct cx25821_dev *dev, struct sram_channel *sram_ch)
443 438
444 if (IS_ERR(myfile)) { 439 if (IS_ERR(myfile)) {
445 const int open_errno = -PTR_ERR(myfile); 440 const int open_errno = -PTR_ERR(myfile);
446 printk(KERN_ERR "%s(): ERROR opening file(%s) with errno = %d!\n", 441 pr_err("%s(): ERROR opening file(%s) with errno = %d!\n",
447 __func__, dev->_filename, open_errno); 442 __func__, dev->_filename, open_errno);
448 return PTR_ERR(myfile); 443 return PTR_ERR(myfile);
449 } else { 444 } else {
450 if (!(myfile->f_op)) { 445 if (!(myfile->f_op)) {
451 printk(KERN_ERR 446 pr_err("%s(): File has no file operations registered!\n",
452 "%s: File has no file operations registered!", 447 __func__);
453 __func__);
454 filp_close(myfile, NULL); 448 filp_close(myfile, NULL);
455 return -EIO; 449 return -EIO;
456 } 450 }
457 451
458 if (!myfile->f_op->read) { 452 if (!myfile->f_op->read) {
459 printk(KERN_ERR 453 pr_err("%s(): File has no READ operations registered! Returning\n",
460 "%s: File has no READ operations registered! \ 454 __func__);
461 Returning.",
462 __func__);
463 filp_close(myfile, NULL); 455 filp_close(myfile, NULL);
464 return -EIO; 456 return -EIO;
465 } 457 }
@@ -487,10 +479,8 @@ int cx25821_openfile(struct cx25821_dev *dev, struct sram_channel *sram_ch)
487 offset += vfs_read_retval; 479 offset += vfs_read_retval;
488 480
489 if (vfs_read_retval < line_size) { 481 if (vfs_read_retval < line_size) {
490 printk(KERN_INFO 482 pr_info("Done: exit %s() since no more bytes to read from Video file\n",
491 "Done: exit %s() since no more \ 483 __func__);
492 bytes to read from Video file.\n",
493 __func__);
494 break; 484 break;
495 } 485 }
496 } 486 }
@@ -534,9 +524,7 @@ int cx25821_upstream_buffer_prepare(struct cx25821_dev *dev,
534 dev->_risc_size = dev->upstream_riscbuf_size; 524 dev->_risc_size = dev->upstream_riscbuf_size;
535 525
536 if (!dev->_dma_virt_addr) { 526 if (!dev->_dma_virt_addr) {
537 printk 527 pr_err("FAILED to allocate memory for Risc buffer! Returning\n");
538 (KERN_ERR "cx25821: FAILED to allocate memory for Risc \
539 buffer! Returning.\n");
540 return -ENOMEM; 528 return -ENOMEM;
541 } 529 }
542 530
@@ -556,9 +544,7 @@ int cx25821_upstream_buffer_prepare(struct cx25821_dev *dev,
556 dev->_data_buf_size = dev->upstream_databuf_size; 544 dev->_data_buf_size = dev->upstream_databuf_size;
557 545
558 if (!dev->_data_buf_virt_addr) { 546 if (!dev->_data_buf_virt_addr) {
559 printk 547 pr_err("FAILED to allocate memory for data buffer! Returning\n");
560 (KERN_ERR "cx25821: FAILED to allocate memory for data \
561 buffer! Returning.\n");
562 return -ENOMEM; 548 return -ENOMEM;
563 } 549 }
564 550
@@ -574,8 +560,7 @@ int cx25821_upstream_buffer_prepare(struct cx25821_dev *dev,
574 cx25821_risc_buffer_upstream(dev, dev->pci, 0, bpl, 560 cx25821_risc_buffer_upstream(dev, dev->pci, 0, bpl,
575 dev->_lines_count); 561 dev->_lines_count);
576 if (ret < 0) { 562 if (ret < 0) {
577 printk(KERN_INFO 563 pr_info("Failed creating Video Upstream Risc programs!\n");
578 "cx25821: Failed creating Video Upstream Risc programs!\n");
579 goto error; 564 goto error;
580 } 565 }
581 566
@@ -652,22 +637,20 @@ int cx25821_video_upstream_irq(struct cx25821_dev *dev, int chan_num,
652 spin_unlock(&dev->slock); 637 spin_unlock(&dev->slock);
653 } else { 638 } else {
654 if (status & FLD_VID_SRC_UF) 639 if (status & FLD_VID_SRC_UF)
655 printk 640 pr_err("%s(): Video Received Underflow Error Interrupt!\n",
656 (KERN_ERR "%s: Video Received Underflow Error \ 641 __func__);
657 Interrupt!\n", __func__);
658 642
659 if (status & FLD_VID_SRC_SYNC) 643 if (status & FLD_VID_SRC_SYNC)
660 printk(KERN_ERR "%s: Video Received Sync Error \ 644 pr_err("%s(): Video Received Sync Error Interrupt!\n",
661 Interrupt!\n", __func__); 645 __func__);
662 646
663 if (status & FLD_VID_SRC_OPC_ERR) 647 if (status & FLD_VID_SRC_OPC_ERR)
664 printk(KERN_ERR "%s: Video Received OpCode Error \ 648 pr_err("%s(): Video Received OpCode Error Interrupt!\n",
665 Interrupt!\n", __func__); 649 __func__);
666 } 650 }
667 651
668 if (dev->_file_status == END_OF_FILE) { 652 if (dev->_file_status == END_OF_FILE) {
669 printk(KERN_ERR "cx25821: EOF Channel 1 Framecount = %d\n", 653 pr_err("EOF Channel 1 Framecount = %d\n", dev->_frame_count);
670 dev->_frame_count);
671 return -1; 654 return -1;
672 } 655 }
673 /* ElSE, set the interrupt mask register, re-enable irq. */ 656 /* ElSE, set the interrupt mask register, re-enable irq. */
@@ -775,8 +758,8 @@ int cx25821_start_video_dma_upstream(struct cx25821_dev *dev,
775 request_irq(dev->pci->irq, cx25821_upstream_irq, 758 request_irq(dev->pci->irq, cx25821_upstream_irq,
776 IRQF_SHARED | IRQF_DISABLED, dev->name, dev); 759 IRQF_SHARED | IRQF_DISABLED, dev->name, dev);
777 if (err < 0) { 760 if (err < 0) {
778 printk(KERN_ERR "%s: can't get upstream IRQ %d\n", dev->name, 761 pr_err("%s: can't get upstream IRQ %d\n",
779 dev->pci->irq); 762 dev->name, dev->pci->irq);
780 goto fail_irq; 763 goto fail_irq;
781 } 764 }
782 765
@@ -806,7 +789,7 @@ int cx25821_vidupstream_init_ch1(struct cx25821_dev *dev, int channel_select,
806 int str_length = 0; 789 int str_length = 0;
807 790
808 if (dev->_is_running) { 791 if (dev->_is_running) {
809 printk(KERN_INFO "Video Channel is still running so return!\n"); 792 pr_info("Video Channel is still running so return!\n");
810 return 0; 793 return 0;
811 } 794 }
812 795
@@ -817,9 +800,7 @@ int cx25821_vidupstream_init_ch1(struct cx25821_dev *dev, int channel_select,
817 dev->_irq_queues = create_singlethread_workqueue("cx25821_workqueue"); 800 dev->_irq_queues = create_singlethread_workqueue("cx25821_workqueue");
818 801
819 if (!dev->_irq_queues) { 802 if (!dev->_irq_queues) {
820 printk 803 pr_err("create_singlethread_workqueue() for Video FAILED!\n");
821 (KERN_ERR "cx25821: create_singlethread_workqueue() for \
822 Video FAILED!\n");
823 return -ENOMEM; 804 return -ENOMEM;
824 } 805 }
825 /* 656/VIP SRC Upstream Channel I & J and 7 - Host Bus Interface for 806 /* 656/VIP SRC Upstream Channel I & J and 7 - Host Bus Interface for
@@ -895,8 +876,7 @@ int cx25821_vidupstream_init_ch1(struct cx25821_dev *dev, int channel_select,
895 /* Allocating buffers and prepare RISC program */ 876 /* Allocating buffers and prepare RISC program */
896 retval = cx25821_upstream_buffer_prepare(dev, sram_ch, dev->_line_size); 877 retval = cx25821_upstream_buffer_prepare(dev, sram_ch, dev->_line_size);
897 if (retval < 0) { 878 if (retval < 0) {
898 printk(KERN_ERR 879 pr_err("%s: Failed to set up Video upstream buffers!\n",
899 "%s: Failed to set up Video upstream buffers!\n",
900 dev->name); 880 dev->name);
901 goto error; 881 goto error;
902 } 882 }
diff --git a/drivers/staging/cx25821/cx25821-video.c b/drivers/staging/cx25821/cx25821-video.c
index 52389308f333..0d8d75670516 100644
--- a/drivers/staging/cx25821/cx25821-video.c
+++ b/drivers/staging/cx25821/cx25821-video.c
@@ -24,7 +24,10 @@
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 */ 25 */
26 26
27#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
28
27#include "cx25821-video.h" 29#include "cx25821-video.h"
30#include <linux/smp_lock.h>
28 31
29MODULE_DESCRIPTION("v4l2 driver module for cx25821 based TV cards"); 32MODULE_DESCRIPTION("v4l2 driver module for cx25821 based TV cards");
30MODULE_AUTHOR("Hiep Huynh <hiep.huynh@conexant.com>"); 33MODULE_AUTHOR("Hiep Huynh <hiep.huynh@conexant.com>");
@@ -104,7 +107,7 @@ struct cx25821_fmt *cx25821_format_by_fourcc(unsigned int fourcc)
104 if (formats[i].fourcc == fourcc) 107 if (formats[i].fourcc == fourcc)
105 return formats + i; 108 return formats + i;
106 109
107 printk(KERN_ERR "%s(0x%08x) NOT FOUND\n", __func__, fourcc); 110 pr_err("%s(0x%08x) NOT FOUND\n", __func__, fourcc);
108 return NULL; 111 return NULL;
109} 112}
110 113
@@ -159,15 +162,15 @@ void cx25821_video_wakeup(struct cx25821_dev *dev, struct cx25821_dmaqueue *q,
159 else 162 else
160 mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT); 163 mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
161 if (bc != 1) 164 if (bc != 1)
162 printk(KERN_ERR "%s: %d buffers handled (should be 1)\n", 165 pr_err("%s: %d buffers handled (should be 1)\n",
163 __func__, bc); 166 __func__, bc);
164} 167}
165 168
166#ifdef TUNER_FLAG 169#ifdef TUNER_FLAG
167int cx25821_set_tvnorm(struct cx25821_dev *dev, v4l2_std_id norm) 170int cx25821_set_tvnorm(struct cx25821_dev *dev, v4l2_std_id norm)
168{ 171{
169 dprintk(1, "%s(norm = 0x%08x) name: [%s]\n", __func__, 172 dprintk(1, "%s(norm = 0x%08x) name: [%s]\n",
170 (unsigned int)norm, v4l2_norm_to_name(norm)); 173 __func__, (unsigned int)norm, v4l2_norm_to_name(norm));
171 174
172 dev->tvnorm = norm; 175 dev->tvnorm = norm;
173 176
@@ -267,7 +270,7 @@ int cx25821_video_mux(struct cx25821_dev *dev, unsigned int input)
267 struct v4l2_routing route; 270 struct v4l2_routing route;
268 memset(&route, 0, sizeof(route)); 271 memset(&route, 0, sizeof(route));
269 272
270 dprintk(1, "%s() video_mux: %d [vmux=%d, gpio=0x%x,0x%x,0x%x,0x%x]\n", 273 dprintk(1, "%s(): video_mux: %d [vmux=%d, gpio=0x%x,0x%x,0x%x,0x%x]\n",
271 __func__, input, INPUT(input)->vmux, INPUT(input)->gpio0, 274 __func__, input, INPUT(input)->vmux, INPUT(input)->gpio0,
272 INPUT(input)->gpio1, INPUT(input)->gpio2, INPUT(input)->gpio3); 275 INPUT(input)->gpio1, INPUT(input)->gpio2, INPUT(input)->gpio3);
273 dev->input = input; 276 dev->input = input;
@@ -400,8 +403,8 @@ int cx25821_video_irq(struct cx25821_dev *dev, int chan_num, u32 status)
400 403
401 /* risc op code error */ 404 /* risc op code error */
402 if (status & (1 << 16)) { 405 if (status & (1 << 16)) {
403 printk(KERN_WARNING "%s, %s: video risc op code error\n", 406 pr_warn("%s, %s: video risc op code error\n",
404 dev->name, channel->name); 407 dev->name, channel->name);
405 cx_clear(channel->dma_ctl, 0x11); 408 cx_clear(channel->dma_ctl, 0x11);
406 cx25821_sram_channel_dump(dev, channel); 409 cx25821_sram_channel_dump(dev, channel);
407 } 410 }
@@ -458,7 +461,7 @@ void cx25821_video_unregister(struct cx25821_dev *dev, int chan_num)
458 btcx_riscmem_free(dev->pci, 461 btcx_riscmem_free(dev->pci,
459 &dev->channels[chan_num].vidq.stopper); 462 &dev->channels[chan_num].vidq.stopper);
460 463
461 printk(KERN_WARNING "device %d released!\n", chan_num); 464 pr_warn("device %d released!\n", chan_num);
462 } 465 }
463 466
464} 467}
@@ -590,7 +593,7 @@ int cx25821_buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
590 init_buffer = 1; 593 init_buffer = 1;
591 rc = videobuf_iolock(q, &buf->vb, NULL); 594 rc = videobuf_iolock(q, &buf->vb, NULL);
592 if (0 != rc) { 595 if (0 != rc) {
593 printk(KERN_DEBUG "videobuf_iolock failed!\n"); 596 printk(KERN_DEBUG pr_fmt("videobuf_iolock failed!\n"));
594 goto fail; 597 goto fail;
595 } 598 }
596 } 599 }
@@ -1038,8 +1041,8 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
1038 dev->channels[fh->channel_id].cif_width = fh->width; 1041 dev->channels[fh->channel_id].cif_width = fh->width;
1039 medusa_set_resolution(dev, fh->width, SRAM_CH00); 1042 medusa_set_resolution(dev, fh->width, SRAM_CH00);
1040 1043
1041 dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width, 1044 dprintk(2, "%s(): width=%d height=%d field=%d\n", __func__, fh->width,
1042 fh->height, fh->vidq.field); 1045 fh->height, fh->vidq.field);
1043 v4l2_fill_mbus_format(&mbus_fmt, &f->fmt.pix, V4L2_MBUS_FMT_FIXED); 1046 v4l2_fill_mbus_format(&mbus_fmt, &f->fmt.pix, V4L2_MBUS_FMT_FIXED);
1044 cx25821_call_all(dev, video, s_mbus_fmt, &mbus_fmt); 1047 cx25821_call_all(dev, video, s_mbus_fmt, &mbus_fmt);
1045 1048
@@ -1070,14 +1073,14 @@ static int vidioc_log_status(struct file *file, void *priv)
1070 u32 tmp = 0; 1073 u32 tmp = 0;
1071 1074
1072 snprintf(name, sizeof(name), "%s/2", dev->name); 1075 snprintf(name, sizeof(name), "%s/2", dev->name);
1073 printk(KERN_INFO "%s/2: ============ START LOG STATUS ============\n", 1076 pr_info("%s/2: ============ START LOG STATUS ============\n",
1074 dev->name); 1077 dev->name);
1075 cx25821_call_all(dev, core, log_status); 1078 cx25821_call_all(dev, core, log_status);
1076 tmp = cx_read(sram_ch->dma_ctl); 1079 tmp = cx_read(sram_ch->dma_ctl);
1077 printk(KERN_INFO "Video input 0 is %s\n", 1080 pr_info("Video input 0 is %s\n",
1078 (tmp & 0x11) ? "streaming" : "stopped"); 1081 (tmp & 0x11) ? "streaming" : "stopped");
1079 printk(KERN_INFO "%s/2: ============= END LOG STATUS =============\n", 1082 pr_info("%s/2: ============= END LOG STATUS =============\n",
1080 dev->name); 1083 dev->name);
1081 return 0; 1084 return 0;
1082} 1085}
1083 1086
@@ -1186,34 +1189,6 @@ int cx25821_vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
1186 return 0; 1189 return 0;
1187} 1190}
1188 1191
1189#ifdef CONFIG_VIDEO_V4L1_COMPAT
1190int cx25821_vidiocgmbuf(struct file *file, void *priv, struct video_mbuf *mbuf)
1191{
1192 struct cx25821_fh *fh = priv;
1193 struct videobuf_queue *q;
1194 struct v4l2_requestbuffers req;
1195 unsigned int i;
1196 int err;
1197
1198 q = get_queue(fh);
1199 memset(&req, 0, sizeof(req));
1200 req.type = q->type;
1201 req.count = 8;
1202 req.memory = V4L2_MEMORY_MMAP;
1203 err = videobuf_reqbufs(q, &req);
1204 if (err < 0)
1205 return err;
1206
1207 mbuf->frames = req.count;
1208 mbuf->size = 0;
1209 for (i = 0; i < mbuf->frames; i++) {
1210 mbuf->offsets[i] = q->bufs[i]->boff;
1211 mbuf->size += q->bufs[i]->bsize;
1212 }
1213 return 0;
1214}
1215#endif
1216
1217int cx25821_vidioc_reqbufs(struct file *file, void *priv, struct v4l2_requestbuffers *p) 1192int cx25821_vidioc_reqbufs(struct file *file, void *priv, struct v4l2_requestbuffers *p)
1218{ 1193{
1219 struct cx25821_fh *fh = priv; 1194 struct cx25821_fh *fh = priv;
@@ -1298,8 +1273,6 @@ int cx25821_enum_input(struct cx25821_dev *dev, struct v4l2_input *i)
1298 if (0 == INPUT(n)->type) 1273 if (0 == INPUT(n)->type)
1299 return -EINVAL; 1274 return -EINVAL;
1300 1275
1301 memset(i, 0, sizeof(*i));
1302 i->index = n;
1303 i->type = V4L2_INPUT_TYPE_CAMERA; 1276 i->type = V4L2_INPUT_TYPE_CAMERA;
1304 strcpy(i->name, iname[INPUT(n)->type]); 1277 strcpy(i->name, iname[INPUT(n)->type]);
1305 1278
@@ -1319,7 +1292,7 @@ int cx25821_vidioc_g_input(struct file *file, void *priv, unsigned int *i)
1319 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; 1292 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
1320 1293
1321 *i = dev->input; 1294 *i = dev->input;
1322 dprintk(1, "%s() returns %d\n", __func__, *i); 1295 dprintk(1, "%s(): returns %d\n", __func__, *i);
1323 return 0; 1296 return 0;
1324} 1297}
1325 1298
@@ -1339,7 +1312,7 @@ int cx25821_vidioc_s_input(struct file *file, void *priv, unsigned int i)
1339 } 1312 }
1340 1313
1341 if (i > 2) { 1314 if (i > 2) {
1342 dprintk(1, "%s() -EINVAL\n", __func__); 1315 dprintk(1, "%s(): -EINVAL\n", __func__);
1343 return -EINVAL; 1316 return -EINVAL;
1344 } 1317 }
1345 1318
@@ -1390,7 +1363,7 @@ int cx25821_vidioc_s_frequency(struct file *file, void *priv, struct v4l2_freque
1390 if (0 != err) 1363 if (0 != err)
1391 return err; 1364 return err;
1392 } else { 1365 } else {
1393 printk(KERN_ERR "Invalid fh pointer!\n"); 1366 pr_err("Invalid fh pointer!\n");
1394 return -EINVAL; 1367 return -EINVAL;
1395 } 1368 }
1396 1369
@@ -1733,12 +1706,10 @@ static long video_ioctl_upstream9(struct file *file, unsigned int cmd,
1733 1706
1734 data_from_user = (struct upstream_user_struct *)arg; 1707 data_from_user = (struct upstream_user_struct *)arg;
1735 1708
1736 if (!data_from_user) { 1709 if (!data_from_user) {
1737 printk 1710 pr_err("%s(): Upstream data is INVALID. Returning\n", __func__);
1738 ("cx25821 in %s(): Upstream data is INVALID. Returning.\n", 1711 return 0;
1739 __func__); 1712 }
1740 return 0;
1741 }
1742 1713
1743 command = data_from_user->command; 1714 command = data_from_user->command;
1744 1715
@@ -1776,12 +1747,10 @@ static long video_ioctl_upstream10(struct file *file, unsigned int cmd,
1776 1747
1777 data_from_user = (struct upstream_user_struct *)arg; 1748 data_from_user = (struct upstream_user_struct *)arg;
1778 1749
1779 if (!data_from_user) { 1750 if (!data_from_user) {
1780 printk 1751 pr_err("%s(): Upstream data is INVALID. Returning\n", __func__);
1781 ("cx25821 in %s(): Upstream data is INVALID. Returning.\n", 1752 return 0;
1782 __func__); 1753 }
1783 return 0;
1784 }
1785 1754
1786 command = data_from_user->command; 1755 command = data_from_user->command;
1787 1756
@@ -1819,12 +1788,10 @@ static long video_ioctl_upstream11(struct file *file, unsigned int cmd,
1819 1788
1820 data_from_user = (struct upstream_user_struct *)arg; 1789 data_from_user = (struct upstream_user_struct *)arg;
1821 1790
1822 if (!data_from_user) { 1791 if (!data_from_user) {
1823 printk 1792 pr_err("%s(): Upstream data is INVALID. Returning\n", __func__);
1824 ("cx25821 in %s(): Upstream data is INVALID. Returning.\n", 1793 return 0;
1825 __func__); 1794 }
1826 return 0;
1827 }
1828 1795
1829 command = data_from_user->command; 1796 command = data_from_user->command;
1830 1797
@@ -1866,12 +1833,10 @@ static long video_ioctl_set(struct file *file, unsigned int cmd,
1866 1833
1867 data_from_user = (struct downstream_user_struct *)arg; 1834 data_from_user = (struct downstream_user_struct *)arg;
1868 1835
1869 if (!data_from_user) { 1836 if (!data_from_user) {
1870 printk( 1837 pr_err("%s(): User data is INVALID. Returning\n", __func__);
1871 "cx25821 in %s(): User data is INVALID. Returning.\n", 1838 return 0;
1872 __func__); 1839 }
1873 return 0;
1874 }
1875 1840
1876 command = data_from_user->command; 1841 command = data_from_user->command;
1877 1842
@@ -2022,9 +1987,6 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
2022 .vidioc_log_status = vidioc_log_status, 1987 .vidioc_log_status = vidioc_log_status,
2023 .vidioc_g_priority = cx25821_vidioc_g_priority, 1988 .vidioc_g_priority = cx25821_vidioc_g_priority,
2024 .vidioc_s_priority = cx25821_vidioc_s_priority, 1989 .vidioc_s_priority = cx25821_vidioc_s_priority,
2025#ifdef CONFIG_VIDEO_V4L1_COMPAT
2026 .vidiocgmbuf = cx25821_vidiocgmbuf,
2027#endif
2028#ifdef TUNER_FLAG 1990#ifdef TUNER_FLAG
2029 .vidioc_g_tuner = cx25821_vidioc_g_tuner, 1991 .vidioc_g_tuner = cx25821_vidioc_g_tuner,
2030 .vidioc_s_tuner = cx25821_vidioc_s_tuner, 1992 .vidioc_s_tuner = cx25821_vidioc_s_tuner,
diff --git a/drivers/staging/cx25821/cx25821-video.h b/drivers/staging/cx25821/cx25821-video.h
index a2415d33235b..f4ee8051b8b3 100644
--- a/drivers/staging/cx25821/cx25821-video.h
+++ b/drivers/staging/cx25821/cx25821-video.h
@@ -40,19 +40,15 @@
40#include <media/v4l2-common.h> 40#include <media/v4l2-common.h>
41#include <media/v4l2-ioctl.h> 41#include <media/v4l2-ioctl.h>
42 42
43#ifdef CONFIG_VIDEO_V4L1_COMPAT
44/* Include V4L1 specific functions. Should be removed soon */
45#include <linux/videodev.h>
46#endif
47
48#define TUNER_FLAG 43#define TUNER_FLAG
49 44
50#define VIDEO_DEBUG 0 45#define VIDEO_DEBUG 0
51 46
52#define dprintk(level, fmt, arg...)\ 47#define dprintk(level, fmt, arg...) \
53 do { if (VIDEO_DEBUG >= level)\ 48do { \
54 printk(KERN_DEBUG "%s/0: " fmt, dev->name, ## arg);\ 49 if (VIDEO_DEBUG >= level) \
55 } while (0) 50 printk(KERN_DEBUG "%s/0: " fmt, dev->name, ##arg); \
51} while (0)
56 52
57/* For IOCTL to identify running upstream */ 53/* For IOCTL to identify running upstream */
58#define UPSTREAM_START_VIDEO 700 54#define UPSTREAM_START_VIDEO 700
@@ -133,7 +129,6 @@ extern int cx25821_vidioc_querycap(struct file *file, void *priv,
133 struct v4l2_capability *cap); 129 struct v4l2_capability *cap);
134extern int cx25821_vidioc_enum_fmt_vid_cap(struct file *file, void *priv, 130extern int cx25821_vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
135 struct v4l2_fmtdesc *f); 131 struct v4l2_fmtdesc *f);
136extern int cx25821_vidiocgmbuf(struct file *file, void *priv, struct video_mbuf *mbuf);
137extern int cx25821_vidioc_reqbufs(struct file *file, void *priv, 132extern int cx25821_vidioc_reqbufs(struct file *file, void *priv,
138 struct v4l2_requestbuffers *p); 133 struct v4l2_requestbuffers *p);
139extern int cx25821_vidioc_querybuf(struct file *file, void *priv, 134extern int cx25821_vidioc_querybuf(struct file *file, void *priv,
diff --git a/drivers/staging/cx25821/cx25821.h b/drivers/staging/cx25821/cx25821.h
index c94000125782..55115235f7f6 100644
--- a/drivers/staging/cx25821/cx25821.h
+++ b/drivers/staging/cx25821/cx25821.h
@@ -519,9 +519,12 @@ extern struct sram_channel cx25821_sram_channels[];
519#define Set_GPIO_Bit(Bit) (1 << Bit) 519#define Set_GPIO_Bit(Bit) (1 << Bit)
520#define Clear_GPIO_Bit(Bit) (~(1 << Bit)) 520#define Clear_GPIO_Bit(Bit) (~(1 << Bit))
521 521
522#define CX25821_ERR(fmt, args...) printk(KERN_ERR "cx25821(%d): " fmt, dev->board, ## args) 522#define CX25821_ERR(fmt, args...) \
523#define CX25821_WARN(fmt, args...) printk(KERN_WARNING "cx25821(%d): " fmt, dev->board , ## args) 523 pr_err("(%d): " fmt, dev->board, ##args)
524#define CX25821_INFO(fmt, args...) printk(KERN_INFO "cx25821(%d): " fmt, dev->board , ## args) 524#define CX25821_WARN(fmt, args...) \
525 pr_warn("(%d): " fmt, dev->board, ##args)
526#define CX25821_INFO(fmt, args...) \
527 pr_info("(%d): " fmt, dev->board, ##args)
525 528
526extern int cx25821_i2c_register(struct cx25821_i2c *bus); 529extern int cx25821_i2c_register(struct cx25821_i2c *bus);
527extern void cx25821_card_setup(struct cx25821_dev *dev); 530extern void cx25821_card_setup(struct cx25821_dev *dev);
diff --git a/drivers/staging/dabusb/Kconfig b/drivers/staging/dabusb/Kconfig
new file mode 100644
index 000000000000..87bdc425d3c5
--- /dev/null
+++ b/drivers/staging/dabusb/Kconfig
@@ -0,0 +1,14 @@
1config USB_DABUSB
2 tristate "DABUSB driver"
3 depends on USB
4 ---help---
5 A Digital Audio Broadcasting (DAB) Receiver for USB and Linux
6 brought to you by the DAB-Team
7 <http://wwwbode.cs.tum.edu/Par/arch/dab/>. This driver can be taken
8 as an example for URB-based bulk, control, and isochronous
9 transactions. URB's are explained in
10 <Documentation/usb/URB.txt>.
11
12 To compile this driver as a module, choose M here: the
13 module will be called dabusb.
14
diff --git a/drivers/staging/dabusb/Makefile b/drivers/staging/dabusb/Makefile
new file mode 100644
index 000000000000..2ff2f228e5f9
--- /dev/null
+++ b/drivers/staging/dabusb/Makefile
@@ -0,0 +1,2 @@
1obj-$(CONFIG_USB_DABUSB) += dabusb.o
2
diff --git a/drivers/staging/dabusb/TODO b/drivers/staging/dabusb/TODO
new file mode 100644
index 000000000000..f9c0314ea0c1
--- /dev/null
+++ b/drivers/staging/dabusb/TODO
@@ -0,0 +1,5 @@
1This is a driver for an experimental sample developed in 2003. The driver
2never supported any commercial product, nor had any known user.
3If nobody takes care on it, the driver will be removed for 2.6.39.
4
5Please send patches to linux-media@vger.kernel.org
diff --git a/drivers/media/video/dabusb.c b/drivers/staging/dabusb/dabusb.c
index f3e25e91366d..f3e25e91366d 100644
--- a/drivers/media/video/dabusb.c
+++ b/drivers/staging/dabusb/dabusb.c
diff --git a/drivers/media/video/dabusb.h b/drivers/staging/dabusb/dabusb.h
index 00eb34c863eb..00eb34c863eb 100644
--- a/drivers/media/video/dabusb.h
+++ b/drivers/staging/dabusb/dabusb.h
diff --git a/drivers/staging/dt3155v4l/dt3155v4l.c b/drivers/staging/dt3155v4l/dt3155v4l.c
index b996697e7eb2..15d7efeed292 100644
--- a/drivers/staging/dt3155v4l/dt3155v4l.c
+++ b/drivers/staging/dt3155v4l/dt3155v4l.c
@@ -876,9 +876,6 @@ static const struct v4l2_ioctl_ops dt3155_ioctl_ops = {
876 .vidioc_s_crop = dt3155_ioc_s_crop, 876 .vidioc_s_crop = dt3155_ioc_s_crop,
877 .vidioc_enum_framesizes = dt3155_ioc_enum_framesizes, 877 .vidioc_enum_framesizes = dt3155_ioc_enum_framesizes,
878 .vidioc_enum_frameintervals = dt3155_ioc_enum_frameintervals, 878 .vidioc_enum_frameintervals = dt3155_ioc_enum_frameintervals,
879#ifdef CONFIG_VIDEO_V4L1_COMPAT
880 .vidiocgmbuf = iocgmbuf,
881#endif
882*/ 879*/
883}; 880};
884 881
diff --git a/drivers/staging/go7007/Kconfig b/drivers/staging/go7007/Kconfig
index 3aecd30f0d1e..1da57df5cbcb 100644
--- a/drivers/staging/go7007/Kconfig
+++ b/drivers/staging/go7007/Kconfig
@@ -1,10 +1,10 @@
1config VIDEO_GO7007 1config VIDEO_GO7007
2 tristate "WIS GO7007 MPEG encoder support" 2 tristate "WIS GO7007 MPEG encoder support"
3 depends on VIDEO_DEV && PCI && I2C && INPUT 3 depends on VIDEO_DEV && PCI && I2C
4 depends on BKL # please fix 4 depends on BKL # please fix
5 depends on SND 5 depends on SND
6 select VIDEOBUF_DMA_SG 6 select VIDEOBUF_DMA_SG
7 depends on VIDEO_IR 7 depends on RC_CORE
8 select VIDEO_TUNER 8 select VIDEO_TUNER
9 select VIDEO_TVEEPROM 9 select VIDEO_TVEEPROM
10 select SND_PCM 10 select SND_PCM
diff --git a/drivers/staging/lirc/Kconfig b/drivers/staging/lirc/Kconfig
index fa790db75d7e..cdaff5903a8f 100644
--- a/drivers/staging/lirc/Kconfig
+++ b/drivers/staging/lirc/Kconfig
@@ -14,26 +14,19 @@ if LIRC_STAGING
14 14
15config LIRC_BT829 15config LIRC_BT829
16 tristate "BT829 based hardware" 16 tristate "BT829 based hardware"
17 depends on LIRC_STAGING && PCI 17 depends on LIRC && PCI
18 help 18 help
19 Driver for the IR interface on BT829-based hardware 19 Driver for the IR interface on BT829-based hardware
20 20
21config LIRC_I2C
22 tristate "I2C Based IR Receivers"
23 depends on LIRC_STAGING && I2C
24 help
25 Driver for I2C-based IR receivers, such as those commonly
26 found onboard Hauppauge PVR-150/250/350 video capture cards
27
28config LIRC_IGORPLUGUSB 21config LIRC_IGORPLUGUSB
29 tristate "Igor Cesko's USB IR Receiver" 22 tristate "Igor Cesko's USB IR Receiver"
30 depends on LIRC_STAGING && USB 23 depends on LIRC && USB
31 help 24 help
32 Driver for Igor Cesko's USB IR Receiver 25 Driver for Igor Cesko's USB IR Receiver
33 26
34config LIRC_IMON 27config LIRC_IMON
35 tristate "Legacy SoundGraph iMON Receiver and Display" 28 tristate "Legacy SoundGraph iMON Receiver and Display"
36 depends on LIRC_STAGING && USB 29 depends on LIRC && USB
37 help 30 help
38 Driver for the original SoundGraph iMON IR Receiver and Display 31 Driver for the original SoundGraph iMON IR Receiver and Display
39 32
@@ -41,31 +34,31 @@ config LIRC_IMON
41 34
42config LIRC_IT87 35config LIRC_IT87
43 tristate "ITE IT87XX CIR Port Receiver" 36 tristate "ITE IT87XX CIR Port Receiver"
44 depends on LIRC_STAGING && PNP 37 depends on LIRC && PNP
45 help 38 help
46 Driver for the ITE IT87xx IR Receiver 39 Driver for the ITE IT87xx IR Receiver
47 40
48config LIRC_ITE8709 41config LIRC_ITE8709
49 tristate "ITE8709 CIR Port Receiver" 42 tristate "ITE8709 CIR Port Receiver"
50 depends on LIRC_STAGING && PNP 43 depends on LIRC && PNP
51 help 44 help
52 Driver for the ITE8709 IR Receiver 45 Driver for the ITE8709 IR Receiver
53 46
54config LIRC_PARALLEL 47config LIRC_PARALLEL
55 tristate "Homebrew Parallel Port Receiver" 48 tristate "Homebrew Parallel Port Receiver"
56 depends on LIRC_STAGING && PARPORT 49 depends on LIRC && PARPORT
57 help 50 help
58 Driver for Homebrew Parallel Port Receivers 51 Driver for Homebrew Parallel Port Receivers
59 52
60config LIRC_SASEM 53config LIRC_SASEM
61 tristate "Sasem USB IR Remote" 54 tristate "Sasem USB IR Remote"
62 depends on LIRC_STAGING && USB 55 depends on LIRC && USB
63 help 56 help
64 Driver for the Sasem OnAir Remocon-V or Dign HV5 HTPC IR/VFD Module 57 Driver for the Sasem OnAir Remocon-V or Dign HV5 HTPC IR/VFD Module
65 58
66config LIRC_SERIAL 59config LIRC_SERIAL
67 tristate "Homebrew Serial Port Receiver" 60 tristate "Homebrew Serial Port Receiver"
68 depends on LIRC_STAGING 61 depends on LIRC
69 help 62 help
70 Driver for Homebrew Serial Port Receivers 63 Driver for Homebrew Serial Port Receivers
71 64
@@ -78,19 +71,19 @@ config LIRC_SERIAL_TRANSMITTER
78 71
79config LIRC_SIR 72config LIRC_SIR
80 tristate "Built-in SIR IrDA port" 73 tristate "Built-in SIR IrDA port"
81 depends on LIRC_STAGING 74 depends on LIRC
82 help 75 help
83 Driver for the SIR IrDA port 76 Driver for the SIR IrDA port
84 77
85config LIRC_TTUSBIR 78config LIRC_TTUSBIR
86 tristate "Technotrend USB IR Receiver" 79 tristate "Technotrend USB IR Receiver"
87 depends on LIRC_STAGING && USB 80 depends on LIRC && USB
88 help 81 help
89 Driver for the Technotrend USB IR Receiver 82 Driver for the Technotrend USB IR Receiver
90 83
91config LIRC_ZILOG 84config LIRC_ZILOG
92 tristate "Zilog/Hauppauge IR Transmitter" 85 tristate "Zilog/Hauppauge IR Transmitter"
93 depends on LIRC_STAGING && I2C 86 depends on LIRC && I2C
94 help 87 help
95 Driver for the Zilog/Hauppauge IR Transmitter, found on 88 Driver for the Zilog/Hauppauge IR Transmitter, found on
96 PVR-150/500, HVR-1200/1250/1700/1800, HD-PVR and other cards 89 PVR-150/500, HVR-1200/1250/1700/1800, HD-PVR and other cards
diff --git a/drivers/staging/lirc/Makefile b/drivers/staging/lirc/Makefile
index 4da1f3397a16..94af218d8373 100644
--- a/drivers/staging/lirc/Makefile
+++ b/drivers/staging/lirc/Makefile
@@ -4,7 +4,6 @@
4# Each configuration option enables a list of files. 4# Each configuration option enables a list of files.
5 5
6obj-$(CONFIG_LIRC_BT829) += lirc_bt829.o 6obj-$(CONFIG_LIRC_BT829) += lirc_bt829.o
7obj-$(CONFIG_LIRC_I2C) += lirc_i2c.o
8obj-$(CONFIG_LIRC_IGORPLUGUSB) += lirc_igorplugusb.o 7obj-$(CONFIG_LIRC_IGORPLUGUSB) += lirc_igorplugusb.o
9obj-$(CONFIG_LIRC_IMON) += lirc_imon.o 8obj-$(CONFIG_LIRC_IMON) += lirc_imon.o
10obj-$(CONFIG_LIRC_IT87) += lirc_it87.o 9obj-$(CONFIG_LIRC_IT87) += lirc_it87.o
diff --git a/drivers/staging/lirc/TODO.lirc_i2c b/drivers/staging/lirc/TODO.lirc_i2c
deleted file mode 100644
index 1f0a6ff65439..000000000000
--- a/drivers/staging/lirc/TODO.lirc_i2c
+++ /dev/null
@@ -1,3 +0,0 @@
1lirc_i2c provides support for some drivers that have already a RC
2driver under drivers/media/video. It should be integrated into those
3drivers, in special with drivers/media/video/ir-kbd-i2c.c.
diff --git a/drivers/staging/lirc/TODO.lirc_zilog b/drivers/staging/lirc/TODO.lirc_zilog
new file mode 100644
index 000000000000..6aa312df4018
--- /dev/null
+++ b/drivers/staging/lirc/TODO.lirc_zilog
@@ -0,0 +1,13 @@
1The binding between hdpvr and lirc_zilog is currently disabled,
2due to an OOPS reported a few years ago when both the hdpvr and cx18
3drivers were loaded in his system. More details can be seen at:
4 http://www.mail-archive.com/linux-media@vger.kernel.org/msg09163.html
5More tests need to be done, in order to fix the reported issue.
6
7There's a conflict between ir-kbd-i2c: Both provide support for RX events.
8Such conflict needs to be fixed, before moving it out of staging.
9
10The way I2C probe works, it will try to register the driver twice, one
11for RX and another for TX. The logic needs to be fixed to avoid such
12issue.
13
diff --git a/drivers/staging/lirc/lirc_i2c.c b/drivers/staging/lirc/lirc_i2c.c
deleted file mode 100644
index 6df2c0e8d721..000000000000
--- a/drivers/staging/lirc/lirc_i2c.c
+++ /dev/null
@@ -1,536 +0,0 @@
1/*
2 * lirc_i2c.c
3 *
4 * i2c IR driver for the onboard IR port on many TV tuner cards, including:
5 * -Flavors of the Hauppauge PVR-150/250/350
6 * -Hauppauge HVR-1300
7 * -PixelView (BT878P+W/FM)
8 * -KNC ONE TV Station/Anubis Typhoon TView Tuner
9 * -Asus TV-Box and Creative/VisionTek BreakOut-Box
10 * -Leadtek Winfast PVR2000
11 *
12 * Copyright (c) 2000 Gerd Knorr <kraxel@goldbach.in-berlin.de>
13 * modified for PixelView (BT878P+W/FM) by
14 * Michal Kochanowicz <mkochano@pld.org.pl>
15 * Christoph Bartelmus <lirc@bartelmus.de>
16 * modified for KNC ONE TV Station/Anubis Typhoon TView Tuner by
17 * Ulrich Mueller <ulrich.mueller42@web.de>
18 * modified for Asus TV-Box and Creative/VisionTek BreakOut-Box by
19 * Stefan Jahn <stefan@lkcc.org>
20 * modified for inclusion into kernel sources by
21 * Jerome Brock <jbrock@users.sourceforge.net>
22 * modified for Leadtek Winfast PVR2000 by
23 * Thomas Reitmayr (treitmayr@yahoo.com)
24 * modified for Hauppauge HVR-1300 by
25 * Jan Frey (jfrey@gmx.de)
26 *
27 * parts are cut&pasted from the old lirc_haup.c driver
28 *
29 * This program is free software; you can redistribute it and/or modify
30 * it under the terms of the GNU General Public License as published by
31 * the Free Software Foundation; either version 2 of the License, or
32 * (at your option) any later version.
33 *
34 * This program is distributed in the hope that it will be useful,
35 * but WITHOUT ANY WARRANTY; without even the implied warranty of
36 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37 * GNU General Public License for more details.
38 *
39 * You should have received a copy of the GNU General Public License
40 * along with this program; if not, write to the Free Software
41 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
42 */
43
44
45#include <linux/version.h>
46#include <linux/module.h>
47#include <linux/kmod.h>
48#include <linux/kernel.h>
49#include <linux/sched.h>
50#include <linux/string.h>
51#include <linux/timer.h>
52#include <linux/delay.h>
53#include <linux/errno.h>
54#include <linux/slab.h>
55#include <linux/i2c.h>
56#include <linux/i2c-algo-bit.h>
57
58#include <media/lirc_dev.h>
59
60struct IR {
61 struct lirc_driver l;
62 struct i2c_client c;
63 int nextkey;
64 unsigned char b[3];
65 unsigned char bits;
66 unsigned char flag;
67};
68
69#define DEVICE_NAME "lirc_i2c"
70
71/* module parameters */
72static int debug; /* debug output */
73static int minor = -1; /* minor number */
74
75#define dprintk(fmt, args...) \
76 do { \
77 if (debug) \
78 printk(KERN_DEBUG DEVICE_NAME ": " fmt, \
79 ## args); \
80 } while (0)
81
82static int reverse(int data, int bits)
83{
84 int i;
85 int c;
86
87 for (c = 0, i = 0; i < bits; i++)
88 c |= ((data & (1<<i)) ? 1 : 0) << (bits-1-i);
89
90 return c;
91}
92
93static int add_to_buf_adap(void *data, struct lirc_buffer *buf)
94{
95 struct IR *ir = data;
96 unsigned char keybuf[4];
97
98 keybuf[0] = 0x00;
99 i2c_master_send(&ir->c, keybuf, 1);
100 /* poll IR chip */
101 if (i2c_master_recv(&ir->c, keybuf, sizeof(keybuf)) != sizeof(keybuf)) {
102 dprintk("read error\n");
103 return -EIO;
104 }
105
106 dprintk("key (0x%02x%02x%02x%02x)\n",
107 keybuf[0], keybuf[1], keybuf[2], keybuf[3]);
108
109 /* key pressed ? */
110 if (keybuf[2] == 0xff)
111 return -ENODATA;
112
113 /* remove repeat bit */
114 keybuf[2] &= 0x7f;
115 keybuf[3] |= 0x80;
116
117 lirc_buffer_write(buf, keybuf);
118 return 0;
119}
120
121static int add_to_buf_pcf8574(void *data, struct lirc_buffer *buf)
122{
123 struct IR *ir = data;
124 int rc;
125 unsigned char all, mask;
126 unsigned char key;
127
128 /* compute all valid bits (key code + pressed/release flag) */
129 all = ir->bits | ir->flag;
130
131 /* save IR writable mask bits */
132 mask = i2c_smbus_read_byte(&ir->c) & ~all;
133
134 /* send bit mask */
135 rc = i2c_smbus_write_byte(&ir->c, (0xff & all) | mask);
136
137 /* receive scan code */
138 rc = i2c_smbus_read_byte(&ir->c);
139
140 if (rc == -1) {
141 dprintk("%s read error\n", ir->c.name);
142 return -EIO;
143 }
144
145 /* drop duplicate polls */
146 if (ir->b[0] == (rc & all))
147 return -ENODATA;
148
149 ir->b[0] = rc & all;
150
151 dprintk("%s key 0x%02X %s\n", ir->c.name, rc & ir->bits,
152 (rc & ir->flag) ? "released" : "pressed");
153
154 /* ignore released buttons */
155 if (rc & ir->flag)
156 return -ENODATA;
157
158 /* set valid key code */
159 key = rc & ir->bits;
160 lirc_buffer_write(buf, &key);
161 return 0;
162}
163
164/* common for Hauppauge IR receivers */
165static int add_to_buf_haup_common(void *data, struct lirc_buffer *buf,
166 unsigned char *keybuf, int size, int offset)
167{
168 struct IR *ir = data;
169 __u16 code;
170 unsigned char codes[2];
171 int ret;
172
173 /* poll IR chip */
174 ret = i2c_master_recv(&ir->c, keybuf, size);
175 if (ret == size) {
176 ir->b[0] = keybuf[offset];
177 ir->b[1] = keybuf[offset+1];
178 ir->b[2] = keybuf[offset+2];
179 if (ir->b[0] != 0x00 && ir->b[1] != 0x00)
180 dprintk("key (0x%02x/0x%02x)\n", ir->b[0], ir->b[1]);
181 } else {
182 dprintk("read error (ret=%d)\n", ret);
183 /* keep last successful read buffer */
184 }
185
186 /* key pressed ? */
187 if ((ir->b[0] & 0x80) == 0)
188 return -ENODATA;
189
190 /* look what we have */
191 code = (((__u16)ir->b[0]&0x7f)<<6) | (ir->b[1]>>2);
192
193 codes[0] = (code >> 8) & 0xff;
194 codes[1] = code & 0xff;
195
196 /* return it */
197 dprintk("sending code 0x%02x%02x to lirc\n", codes[0], codes[1]);
198 lirc_buffer_write(buf, codes);
199 return 0;
200}
201
202/* specific for the Hauppauge PVR150 IR receiver */
203static int add_to_buf_haup_pvr150(void *data, struct lirc_buffer *buf)
204{
205 unsigned char keybuf[6];
206 /* fetch 6 bytes, first relevant is at offset 3 */
207 return add_to_buf_haup_common(data, buf, keybuf, 6, 3);
208}
209
210/* used for all Hauppauge IR receivers but the PVR150 */
211static int add_to_buf_haup(void *data, struct lirc_buffer *buf)
212{
213 unsigned char keybuf[3];
214 /* fetch 3 bytes, first relevant is at offset 0 */
215 return add_to_buf_haup_common(data, buf, keybuf, 3, 0);
216}
217
218
219static int add_to_buf_pvr2000(void *data, struct lirc_buffer *buf)
220{
221 struct IR *ir = data;
222 unsigned char key;
223 s32 flags;
224 s32 code;
225
226 /* poll IR chip */
227 flags = i2c_smbus_read_byte_data(&ir->c, 0x10);
228 if (-1 == flags) {
229 dprintk("read error\n");
230 return -ENODATA;
231 }
232 /* key pressed ? */
233 if (0 == (flags & 0x80))
234 return -ENODATA;
235
236 /* read actual key code */
237 code = i2c_smbus_read_byte_data(&ir->c, 0x00);
238 if (-1 == code) {
239 dprintk("read error\n");
240 return -ENODATA;
241 }
242
243 key = code & 0xFF;
244
245 dprintk("IR Key/Flags: (0x%02x/0x%02x)\n", key, flags & 0xFF);
246
247 /* return it */
248 lirc_buffer_write(buf, &key);
249 return 0;
250}
251
252static int add_to_buf_pixelview(void *data, struct lirc_buffer *buf)
253{
254 struct IR *ir = data;
255 unsigned char key;
256
257 /* poll IR chip */
258 if (1 != i2c_master_recv(&ir->c, &key, 1)) {
259 dprintk("read error\n");
260 return -1;
261 }
262 dprintk("key %02x\n", key);
263
264 /* return it */
265 lirc_buffer_write(buf, &key);
266 return 0;
267}
268
269static int add_to_buf_pv951(void *data, struct lirc_buffer *buf)
270{
271 struct IR *ir = data;
272 unsigned char key;
273 unsigned char codes[4];
274
275 /* poll IR chip */
276 if (1 != i2c_master_recv(&ir->c, &key, 1)) {
277 dprintk("read error\n");
278 return -ENODATA;
279 }
280 /* ignore 0xaa */
281 if (key == 0xaa)
282 return -ENODATA;
283 dprintk("key %02x\n", key);
284
285 codes[0] = 0x61;
286 codes[1] = 0xD6;
287 codes[2] = reverse(key, 8);
288 codes[3] = (~codes[2])&0xff;
289
290 lirc_buffer_write(buf, codes);
291 return 0;
292}
293
294static int add_to_buf_knc1(void *data, struct lirc_buffer *buf)
295{
296 static unsigned char last_key = 0xFF;
297 struct IR *ir = data;
298 unsigned char key;
299
300 /* poll IR chip */
301 if (1 != i2c_master_recv(&ir->c, &key, 1)) {
302 dprintk("read error\n");
303 return -ENODATA;
304 }
305
306 /*
307 * it seems that 0xFE indicates that a button is still held
308 * down, while 0xFF indicates that no button is held
309 * down. 0xFE sequences are sometimes interrupted by 0xFF
310 */
311
312 dprintk("key %02x\n", key);
313
314 if (key == 0xFF)
315 return -ENODATA;
316
317 if (key == 0xFE)
318 key = last_key;
319
320 last_key = key;
321 lirc_buffer_write(buf, &key);
322
323 return 0;
324}
325
326static int set_use_inc(void *data)
327{
328 struct IR *ir = data;
329
330 dprintk("%s called\n", __func__);
331
332 /* lock bttv in memory while /dev/lirc is in use */
333 i2c_use_client(&ir->c);
334
335 return 0;
336}
337
338static void set_use_dec(void *data)
339{
340 struct IR *ir = data;
341
342 dprintk("%s called\n", __func__);
343
344 i2c_release_client(&ir->c);
345}
346
347static struct lirc_driver lirc_template = {
348 .name = "lirc_i2c",
349 .set_use_inc = set_use_inc,
350 .set_use_dec = set_use_dec,
351 .dev = NULL,
352 .owner = THIS_MODULE,
353};
354
355static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id);
356static int ir_remove(struct i2c_client *client);
357static int ir_command(struct i2c_client *client, unsigned int cmd, void *arg);
358
359static const struct i2c_device_id ir_receiver_id[] = {
360 /* Generic entry for any IR receiver */
361 { "ir_video", 0 },
362 /* IR device specific entries could be added here */
363 { }
364};
365
366static struct i2c_driver driver = {
367 .driver = {
368 .owner = THIS_MODULE,
369 .name = "i2c ir driver",
370 },
371 .probe = ir_probe,
372 .remove = ir_remove,
373 .id_table = ir_receiver_id,
374 .command = ir_command,
375};
376
377static void pcf_probe(struct i2c_client *client, struct IR *ir)
378{
379 int ret1, ret2, ret3, ret4;
380
381 ret1 = i2c_smbus_write_byte(client, 0xff);
382 ret2 = i2c_smbus_read_byte(client);
383 ret3 = i2c_smbus_write_byte(client, 0x00);
384 ret4 = i2c_smbus_read_byte(client);
385
386 /* in the Asus TV-Box: bit 1-0 */
387 if (((ret2 & 0x03) == 0x03) && ((ret4 & 0x03) == 0x00)) {
388 ir->bits = (unsigned char) ~0x07;
389 ir->flag = 0x04;
390 /* in the Creative/VisionTek BreakOut-Box: bit 7-6 */
391 } else if (((ret2 & 0xc0) == 0xc0) && ((ret4 & 0xc0) == 0x00)) {
392 ir->bits = (unsigned char) ~0xe0;
393 ir->flag = 0x20;
394 }
395
396 return;
397}
398
399static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
400{
401 struct IR *ir;
402 struct i2c_adapter *adap = client->adapter;
403 unsigned short addr = client->addr;
404 int retval;
405
406 ir = kzalloc(sizeof(struct IR), GFP_KERNEL);
407 if (!ir)
408 return -ENOMEM;
409 memcpy(&ir->l, &lirc_template, sizeof(struct lirc_driver));
410 memcpy(&ir->c, client, sizeof(struct i2c_client));
411
412 i2c_set_clientdata(client, ir);
413 ir->l.data = ir;
414 ir->l.minor = minor;
415 ir->l.sample_rate = 10;
416 ir->l.dev = &ir->c.dev;
417 ir->nextkey = -1;
418
419 switch (addr) {
420 case 0x64:
421 strlcpy(ir->c.name, "Pixelview IR", I2C_NAME_SIZE);
422 ir->l.code_length = 8;
423 ir->l.add_to_buf = add_to_buf_pixelview;
424 break;
425 case 0x4b:
426 strlcpy(ir->c.name, "PV951 IR", I2C_NAME_SIZE);
427 ir->l.code_length = 32;
428 ir->l.add_to_buf = add_to_buf_pv951;
429 break;
430 case 0x71:
431 if (adap->id == I2C_HW_B_CX2388x)
432 strlcpy(ir->c.name, "Hauppauge HVR1300", I2C_NAME_SIZE);
433 else /* bt8xx or cx2341x */
434 /*
435 * The PVR150 IR receiver uses the same protocol as
436 * other Hauppauge cards, but the data flow is
437 * different, so we need to deal with it by its own.
438 */
439 strlcpy(ir->c.name, "Hauppauge PVR150", I2C_NAME_SIZE);
440 ir->l.code_length = 13;
441 ir->l.add_to_buf = add_to_buf_haup_pvr150;
442 break;
443 case 0x6b:
444 strlcpy(ir->c.name, "Adaptec IR", I2C_NAME_SIZE);
445 ir->l.code_length = 32;
446 ir->l.add_to_buf = add_to_buf_adap;
447 break;
448 case 0x18:
449 case 0x1a:
450 if (adap->id == I2C_HW_B_CX2388x) {
451 strlcpy(ir->c.name, "Leadtek IR", I2C_NAME_SIZE);
452 ir->l.code_length = 8;
453 ir->l.add_to_buf = add_to_buf_pvr2000;
454 } else { /* bt8xx or cx2341x */
455 strlcpy(ir->c.name, "Hauppauge IR", I2C_NAME_SIZE);
456 ir->l.code_length = 13;
457 ir->l.add_to_buf = add_to_buf_haup;
458 }
459 break;
460 case 0x30:
461 strlcpy(ir->c.name, "KNC ONE IR", I2C_NAME_SIZE);
462 ir->l.code_length = 8;
463 ir->l.add_to_buf = add_to_buf_knc1;
464 break;
465 case 0x21:
466 case 0x23:
467 pcf_probe(client, ir);
468 strlcpy(ir->c.name, "TV-Box IR", I2C_NAME_SIZE);
469 ir->l.code_length = 8;
470 ir->l.add_to_buf = add_to_buf_pcf8574;
471 break;
472 default:
473 /* shouldn't happen */
474 printk("lirc_i2c: Huh? unknown i2c address (0x%02x)?\n", addr);
475 kfree(ir);
476 return -EINVAL;
477 }
478 printk(KERN_INFO "lirc_i2c: chip 0x%x found @ 0x%02x (%s)\n",
479 adap->id, addr, ir->c.name);
480
481 retval = lirc_register_driver(&ir->l);
482
483 if (retval < 0) {
484 printk(KERN_ERR "lirc_i2c: failed to register driver!\n");
485 kfree(ir);
486 return retval;
487 }
488
489 ir->l.minor = retval;
490
491 return 0;
492}
493
494static int ir_remove(struct i2c_client *client)
495{
496 struct IR *ir = i2c_get_clientdata(client);
497
498 /* unregister device */
499 lirc_unregister_driver(ir->l.minor);
500
501 /* free memory */
502 kfree(ir);
503 return 0;
504}
505
506static int ir_command(struct i2c_client *client, unsigned int cmd, void *arg)
507{
508 /* nothing */
509 return 0;
510}
511
512static int __init lirc_i2c_init(void)
513{
514 i2c_add_driver(&driver);
515 return 0;
516}
517
518static void __exit lirc_i2c_exit(void)
519{
520 i2c_del_driver(&driver);
521}
522
523MODULE_DESCRIPTION("Infrared receiver driver for Hauppauge and "
524 "Pixelview cards (i2c stack)");
525MODULE_AUTHOR("Gerd Knorr, Michal Kochanowicz, Christoph Bartelmus, "
526 "Ulrich Mueller, Stefan Jahn, Jerome Brock");
527MODULE_LICENSE("GPL");
528
529module_param(minor, int, S_IRUGO);
530MODULE_PARM_DESC(minor, "Preferred minor device number");
531
532module_param(debug, bool, S_IRUGO | S_IWUSR);
533MODULE_PARM_DESC(debug, "Enable debugging messages");
534
535module_init(lirc_i2c_init);
536module_exit(lirc_i2c_exit);
diff --git a/drivers/staging/lirc/lirc_zilog.c b/drivers/staging/lirc/lirc_zilog.c
index f0076eb025f1..ad29bb1275ab 100644
--- a/drivers/staging/lirc/lirc_zilog.c
+++ b/drivers/staging/lirc/lirc_zilog.c
@@ -66,6 +66,7 @@ struct IR {
66 /* Device info */ 66 /* Device info */
67 struct mutex ir_lock; 67 struct mutex ir_lock;
68 int open; 68 int open;
69 bool is_hdpvr;
69 70
70 /* RX device */ 71 /* RX device */
71 struct i2c_client c_rx; 72 struct i2c_client c_rx;
@@ -206,16 +207,12 @@ static int add_to_buf(struct IR *ir)
206 } 207 }
207 208
208 /* key pressed ? */ 209 /* key pressed ? */
209#ifdef I2C_HW_B_HDPVR 210 if (ir->is_hdpvr) {
210 if (ir->c_rx.adapter->id == I2C_HW_B_HDPVR) {
211 if (got_data && (keybuf[0] == 0x80)) 211 if (got_data && (keybuf[0] == 0x80))
212 return 0; 212 return 0;
213 else if (got_data && (keybuf[0] == 0x00)) 213 else if (got_data && (keybuf[0] == 0x00))
214 return -ENODATA; 214 return -ENODATA;
215 } else if ((ir->b[0] & 0x80) == 0) 215 } else if ((ir->b[0] & 0x80) == 0)
216#else
217 if ((ir->b[0] & 0x80) == 0)
218#endif
219 return got_data ? 0 : -ENODATA; 216 return got_data ? 0 : -ENODATA;
220 217
221 /* look what we have */ 218 /* look what we have */
@@ -841,15 +838,15 @@ static int send_code(struct IR *ir, unsigned int code, unsigned int key)
841 return ret < 0 ? ret : -EFAULT; 838 return ret < 0 ? ret : -EFAULT;
842 } 839 }
843 840
844#ifdef I2C_HW_B_HDPVR
845 /* 841 /*
846 * The sleep bits aren't necessary on the HD PVR, and in fact, the 842 * The sleep bits aren't necessary on the HD PVR, and in fact, the
847 * last i2c_master_recv always fails with a -5, so for now, we're 843 * last i2c_master_recv always fails with a -5, so for now, we're
848 * going to skip this whole mess and say we're done on the HD PVR 844 * going to skip this whole mess and say we're done on the HD PVR
849 */ 845 */
850 if (ir->c_rx.adapter->id == I2C_HW_B_HDPVR) 846 if (ir->is_hdpvr) {
851 goto done; 847 dprintk("sent code %u, key %u\n", code, key);
852#endif 848 return 0;
849 }
853 850
854 /* 851 /*
855 * This bit NAKs until the device is ready, so we retry it 852 * This bit NAKs until the device is ready, so we retry it
@@ -883,7 +880,6 @@ static int send_code(struct IR *ir, unsigned int code, unsigned int key)
883 return -EFAULT; 880 return -EFAULT;
884 } 881 }
885 882
886done:
887 /* Oh good, it worked */ 883 /* Oh good, it worked */
888 dprintk("sent code %u, key %u\n", code, key); 884 dprintk("sent code %u, key %u\n", code, key);
889 return 0; 885 return 0;
@@ -1112,12 +1108,14 @@ static int ir_remove(struct i2c_client *client);
1112static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id); 1108static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id);
1113static int ir_command(struct i2c_client *client, unsigned int cmd, void *arg); 1109static int ir_command(struct i2c_client *client, unsigned int cmd, void *arg);
1114 1110
1111#define ID_FLAG_TX 0x01
1112#define ID_FLAG_HDPVR 0x02
1113
1115static const struct i2c_device_id ir_transceiver_id[] = { 1114static const struct i2c_device_id ir_transceiver_id[] = {
1116 /* Generic entry for any IR transceiver */ 1115 { "ir_tx_z8f0811_haup", ID_FLAG_TX },
1117 { "ir_video", 0 }, 1116 { "ir_rx_z8f0811_haup", 0 },
1118 /* IR device specific entries should be added here */ 1117 { "ir_tx_z8f0811_hdpvr", ID_FLAG_HDPVR | ID_FLAG_TX },
1119 { "ir_tx_z8f0811_haup", 0 }, 1118 { "ir_rx_z8f0811_hdpvr", ID_FLAG_HDPVR },
1120 { "ir_rx_z8f0811_haup", 0 },
1121 { } 1119 { }
1122}; 1120};
1123 1121
@@ -1197,10 +1195,25 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
1197 int ret; 1195 int ret;
1198 int have_rx = 0, have_tx = 0; 1196 int have_rx = 0, have_tx = 0;
1199 1197
1200 dprintk("%s: adapter id=0x%x, client addr=0x%02x\n", 1198 dprintk("%s: adapter name (%s) nr %d, i2c_device_id name (%s), "
1201 __func__, adap->id, client->addr); 1199 "client addr=0x%02x\n",
1200 __func__, adap->name, adap->nr, id->name, client->addr);
1202 1201
1203 /* 1202 /*
1203 * FIXME - This probe function probes both the Tx and Rx
1204 * addresses of the IR microcontroller.
1205 *
1206 * However, the I2C subsystem is passing along one I2C client at a
1207 * time, based on matches to the ir_transceiver_id[] table above.
1208 * The expectation is that each i2c_client address will be probed
1209 * individually by drivers so the I2C subsystem can mark all client
1210 * addresses as claimed or not.
1211 *
1212 * This probe routine causes only one of the client addresses, TX or RX,
1213 * to be claimed. This will cause a problem if the I2C subsystem is
1214 * subsequently triggered to probe unclaimed clients again.
1215 */
1216 /*
1204 * The external IR receiver is at i2c address 0x71. 1217 * The external IR receiver is at i2c address 0x71.
1205 * The IR transmitter is at 0x70. 1218 * The IR transmitter is at 0x70.
1206 */ 1219 */
@@ -1242,6 +1255,7 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
1242 mutex_init(&ir->ir_lock); 1255 mutex_init(&ir->ir_lock);
1243 mutex_init(&ir->buf_lock); 1256 mutex_init(&ir->buf_lock);
1244 ir->need_boot = 1; 1257 ir->need_boot = 1;
1258 ir->is_hdpvr = (id->driver_data & ID_FLAG_HDPVR) ? true : false;
1245 1259
1246 memcpy(&ir->l, &lirc_template, sizeof(struct lirc_driver)); 1260 memcpy(&ir->l, &lirc_template, sizeof(struct lirc_driver));
1247 ir->l.minor = -1; 1261 ir->l.minor = -1;
diff --git a/drivers/staging/se401/Kconfig b/drivers/staging/se401/Kconfig
new file mode 100644
index 000000000000..b7f8222ad21b
--- /dev/null
+++ b/drivers/staging/se401/Kconfig
@@ -0,0 +1,13 @@
1config USB_SE401
2 tristate "USB SE401 Camera support (DEPRECATED)"
3 depends on VIDEO_DEV && VIDEO_V4L2_COMMON && USB
4 ---help---
5 Say Y here if you want to connect this type of camera to your
6 computer's USB port. See <file:Documentation/video4linux/se401.txt>
7 for more information and for a list of supported cameras.
8
9 This driver uses the deprecated V4L1 API and will be removed in
10 2.6.39, unless someone converts it to the V4L2 API.
11
12 To compile this driver as a module, choose M here: the
13 module will be called se401.
diff --git a/drivers/staging/se401/Makefile b/drivers/staging/se401/Makefile
new file mode 100644
index 000000000000..b465d49783af
--- /dev/null
+++ b/drivers/staging/se401/Makefile
@@ -0,0 +1 @@
obj-$(CONFIG_USB_SE401) += se401.o
diff --git a/drivers/staging/se401/TODO b/drivers/staging/se401/TODO
new file mode 100644
index 000000000000..3b2c03836286
--- /dev/null
+++ b/drivers/staging/se401/TODO
@@ -0,0 +1,5 @@
1This is an obsolete driver for some old webcams that still use V4L1 API.
2As V4L1 support is being removed from kernel, if nobody take care on it,
3the driver will be removed for 2.6.39.
4
5Please send patches to linux-media@vger.kernel.org
diff --git a/drivers/media/video/se401.c b/drivers/staging/se401/se401.c
index 41360d7c3e96..41360d7c3e96 100644
--- a/drivers/media/video/se401.c
+++ b/drivers/staging/se401/se401.c
diff --git a/drivers/media/video/se401.h b/drivers/staging/se401/se401.h
index bf7d2e9765b0..2758f4716c3d 100644
--- a/drivers/media/video/se401.h
+++ b/drivers/staging/se401/se401.h
@@ -3,7 +3,7 @@
3#define __LINUX_se401_H 3#define __LINUX_se401_H
4 4
5#include <linux/uaccess.h> 5#include <linux/uaccess.h>
6#include <linux/videodev.h> 6#include "videodev.h"
7#include <media/v4l2-common.h> 7#include <media/v4l2-common.h>
8#include <media/v4l2-ioctl.h> 8#include <media/v4l2-ioctl.h>
9#include <linux/mutex.h> 9#include <linux/mutex.h>
diff --git a/drivers/staging/se401/videodev.h b/drivers/staging/se401/videodev.h
new file mode 100644
index 000000000000..f11efbef1c05
--- /dev/null
+++ b/drivers/staging/se401/videodev.h
@@ -0,0 +1,318 @@
1/*
2 * Video for Linux version 1 - OBSOLETE
3 *
4 * Header file for v4l1 drivers and applications, for
5 * Linux kernels 2.2.x or 2.4.x.
6 *
7 * Provides header for legacy drivers and applications
8 *
9 * See http://linuxtv.org for more info
10 *
11 */
12#ifndef __LINUX_VIDEODEV_H
13#define __LINUX_VIDEODEV_H
14
15#include <linux/types.h>
16#include <linux/ioctl.h>
17#include <linux/videodev2.h>
18
19#define VID_TYPE_CAPTURE 1 /* Can capture */
20#define VID_TYPE_TUNER 2 /* Can tune */
21#define VID_TYPE_TELETEXT 4 /* Does teletext */
22#define VID_TYPE_OVERLAY 8 /* Overlay onto frame buffer */
23#define VID_TYPE_CHROMAKEY 16 /* Overlay by chromakey */
24#define VID_TYPE_CLIPPING 32 /* Can clip */
25#define VID_TYPE_FRAMERAM 64 /* Uses the frame buffer memory */
26#define VID_TYPE_SCALES 128 /* Scalable */
27#define VID_TYPE_MONOCHROME 256 /* Monochrome only */
28#define VID_TYPE_SUBCAPTURE 512 /* Can capture subareas of the image */
29#define VID_TYPE_MPEG_DECODER 1024 /* Can decode MPEG streams */
30#define VID_TYPE_MPEG_ENCODER 2048 /* Can encode MPEG streams */
31#define VID_TYPE_MJPEG_DECODER 4096 /* Can decode MJPEG streams */
32#define VID_TYPE_MJPEG_ENCODER 8192 /* Can encode MJPEG streams */
33
34struct video_capability
35{
36 char name[32];
37 int type;
38 int channels; /* Num channels */
39 int audios; /* Num audio devices */
40 int maxwidth; /* Supported width */
41 int maxheight; /* And height */
42 int minwidth; /* Supported width */
43 int minheight; /* And height */
44};
45
46
47struct video_channel
48{
49 int channel;
50 char name[32];
51 int tuners;
52 __u32 flags;
53#define VIDEO_VC_TUNER 1 /* Channel has a tuner */
54#define VIDEO_VC_AUDIO 2 /* Channel has audio */
55 __u16 type;
56#define VIDEO_TYPE_TV 1
57#define VIDEO_TYPE_CAMERA 2
58 __u16 norm; /* Norm set by channel */
59};
60
61struct video_tuner
62{
63 int tuner;
64 char name[32];
65 unsigned long rangelow, rangehigh; /* Tuner range */
66 __u32 flags;
67#define VIDEO_TUNER_PAL 1
68#define VIDEO_TUNER_NTSC 2
69#define VIDEO_TUNER_SECAM 4
70#define VIDEO_TUNER_LOW 8 /* Uses KHz not MHz */
71#define VIDEO_TUNER_NORM 16 /* Tuner can set norm */
72#define VIDEO_TUNER_STEREO_ON 128 /* Tuner is seeing stereo */
73#define VIDEO_TUNER_RDS_ON 256 /* Tuner is seeing an RDS datastream */
74#define VIDEO_TUNER_MBS_ON 512 /* Tuner is seeing an MBS datastream */
75 __u16 mode; /* PAL/NTSC/SECAM/OTHER */
76#define VIDEO_MODE_PAL 0
77#define VIDEO_MODE_NTSC 1
78#define VIDEO_MODE_SECAM 2
79#define VIDEO_MODE_AUTO 3
80 __u16 signal; /* Signal strength 16bit scale */
81};
82
83struct video_picture
84{
85 __u16 brightness;
86 __u16 hue;
87 __u16 colour;
88 __u16 contrast;
89 __u16 whiteness; /* Black and white only */
90 __u16 depth; /* Capture depth */
91 __u16 palette; /* Palette in use */
92#define VIDEO_PALETTE_GREY 1 /* Linear greyscale */
93#define VIDEO_PALETTE_HI240 2 /* High 240 cube (BT848) */
94#define VIDEO_PALETTE_RGB565 3 /* 565 16 bit RGB */
95#define VIDEO_PALETTE_RGB24 4 /* 24bit RGB */
96#define VIDEO_PALETTE_RGB32 5 /* 32bit RGB */
97#define VIDEO_PALETTE_RGB555 6 /* 555 15bit RGB */
98#define VIDEO_PALETTE_YUV422 7 /* YUV422 capture */
99#define VIDEO_PALETTE_YUYV 8
100#define VIDEO_PALETTE_UYVY 9 /* The great thing about standards is ... */
101#define VIDEO_PALETTE_YUV420 10
102#define VIDEO_PALETTE_YUV411 11 /* YUV411 capture */
103#define VIDEO_PALETTE_RAW 12 /* RAW capture (BT848) */
104#define VIDEO_PALETTE_YUV422P 13 /* YUV 4:2:2 Planar */
105#define VIDEO_PALETTE_YUV411P 14 /* YUV 4:1:1 Planar */
106#define VIDEO_PALETTE_YUV420P 15 /* YUV 4:2:0 Planar */
107#define VIDEO_PALETTE_YUV410P 16 /* YUV 4:1:0 Planar */
108#define VIDEO_PALETTE_PLANAR 13 /* start of planar entries */
109#define VIDEO_PALETTE_COMPONENT 7 /* start of component entries */
110};
111
112struct video_audio
113{
114 int audio; /* Audio channel */
115 __u16 volume; /* If settable */
116 __u16 bass, treble;
117 __u32 flags;
118#define VIDEO_AUDIO_MUTE 1
119#define VIDEO_AUDIO_MUTABLE 2
120#define VIDEO_AUDIO_VOLUME 4
121#define VIDEO_AUDIO_BASS 8
122#define VIDEO_AUDIO_TREBLE 16
123#define VIDEO_AUDIO_BALANCE 32
124 char name[16];
125#define VIDEO_SOUND_MONO 1
126#define VIDEO_SOUND_STEREO 2
127#define VIDEO_SOUND_LANG1 4
128#define VIDEO_SOUND_LANG2 8
129 __u16 mode;
130 __u16 balance; /* Stereo balance */
131 __u16 step; /* Step actual volume uses */
132};
133
134struct video_clip
135{
136 __s32 x,y;
137 __s32 width, height;
138 struct video_clip *next; /* For user use/driver use only */
139};
140
141struct video_window
142{
143 __u32 x,y; /* Position of window */
144 __u32 width,height; /* Its size */
145 __u32 chromakey;
146 __u32 flags;
147 struct video_clip __user *clips; /* Set only */
148 int clipcount;
149#define VIDEO_WINDOW_INTERLACE 1
150#define VIDEO_WINDOW_CHROMAKEY 16 /* Overlay by chromakey */
151#define VIDEO_CLIP_BITMAP -1
152/* bitmap is 1024x625, a '1' bit represents a clipped pixel */
153#define VIDEO_CLIPMAP_SIZE (128 * 625)
154};
155
156struct video_capture
157{
158 __u32 x,y; /* Offsets into image */
159 __u32 width, height; /* Area to capture */
160 __u16 decimation; /* Decimation divider */
161 __u16 flags; /* Flags for capture */
162#define VIDEO_CAPTURE_ODD 0 /* Temporal */
163#define VIDEO_CAPTURE_EVEN 1
164};
165
166struct video_buffer
167{
168 void *base;
169 int height,width;
170 int depth;
171 int bytesperline;
172};
173
174struct video_mmap
175{
176 unsigned int frame; /* Frame (0 - n) for double buffer */
177 int height,width;
178 unsigned int format; /* should be VIDEO_PALETTE_* */
179};
180
181struct video_key
182{
183 __u8 key[8];
184 __u32 flags;
185};
186
187struct video_mbuf
188{
189 int size; /* Total memory to map */
190 int frames; /* Frames */
191 int offsets[VIDEO_MAX_FRAME];
192};
193
194#define VIDEO_NO_UNIT (-1)
195
196struct video_unit
197{
198 int video; /* Video minor */
199 int vbi; /* VBI minor */
200 int radio; /* Radio minor */
201 int audio; /* Audio minor */
202 int teletext; /* Teletext minor */
203};
204
205struct vbi_format {
206 __u32 sampling_rate; /* in Hz */
207 __u32 samples_per_line;
208 __u32 sample_format; /* VIDEO_PALETTE_RAW only (1 byte) */
209 __s32 start[2]; /* starting line for each frame */
210 __u32 count[2]; /* count of lines for each frame */
211 __u32 flags;
212#define VBI_UNSYNC 1 /* can distingues between top/bottom field */
213#define VBI_INTERLACED 2 /* lines are interlaced */
214};
215
216/* video_info is biased towards hardware mpeg encode/decode */
217/* but it could apply generically to any hardware compressor/decompressor */
218struct video_info
219{
220 __u32 frame_count; /* frames output since decode/encode began */
221 __u32 h_size; /* current unscaled horizontal size */
222 __u32 v_size; /* current unscaled veritcal size */
223 __u32 smpte_timecode; /* current SMPTE timecode (for current GOP) */
224 __u32 picture_type; /* current picture type */
225 __u32 temporal_reference; /* current temporal reference */
226 __u8 user_data[256]; /* user data last found in compressed stream */
227 /* user_data[0] contains user data flags, user_data[1] has count */
228};
229
230/* generic structure for setting playback modes */
231struct video_play_mode
232{
233 int mode;
234 int p1;
235 int p2;
236};
237
238/* for loading microcode / fpga programming */
239struct video_code
240{
241 char loadwhat[16]; /* name or tag of file being passed */
242 int datasize;
243 __u8 *data;
244};
245
246#define VIDIOCGCAP _IOR('v',1,struct video_capability) /* Get capabilities */
247#define VIDIOCGCHAN _IOWR('v',2,struct video_channel) /* Get channel info (sources) */
248#define VIDIOCSCHAN _IOW('v',3,struct video_channel) /* Set channel */
249#define VIDIOCGTUNER _IOWR('v',4,struct video_tuner) /* Get tuner abilities */
250#define VIDIOCSTUNER _IOW('v',5,struct video_tuner) /* Tune the tuner for the current channel */
251#define VIDIOCGPICT _IOR('v',6,struct video_picture) /* Get picture properties */
252#define VIDIOCSPICT _IOW('v',7,struct video_picture) /* Set picture properties */
253#define VIDIOCCAPTURE _IOW('v',8,int) /* Start, end capture */
254#define VIDIOCGWIN _IOR('v',9, struct video_window) /* Get the video overlay window */
255#define VIDIOCSWIN _IOW('v',10, struct video_window) /* Set the video overlay window - passes clip list for hardware smarts , chromakey etc */
256#define VIDIOCGFBUF _IOR('v',11, struct video_buffer) /* Get frame buffer */
257#define VIDIOCSFBUF _IOW('v',12, struct video_buffer) /* Set frame buffer - root only */
258#define VIDIOCKEY _IOR('v',13, struct video_key) /* Video key event - to dev 255 is to all - cuts capture on all DMA windows with this key (0xFFFFFFFF == all) */
259#define VIDIOCGFREQ _IOR('v',14, unsigned long) /* Set tuner */
260#define VIDIOCSFREQ _IOW('v',15, unsigned long) /* Set tuner */
261#define VIDIOCGAUDIO _IOR('v',16, struct video_audio) /* Get audio info */
262#define VIDIOCSAUDIO _IOW('v',17, struct video_audio) /* Audio source, mute etc */
263#define VIDIOCSYNC _IOW('v',18, int) /* Sync with mmap grabbing */
264#define VIDIOCMCAPTURE _IOW('v',19, struct video_mmap) /* Grab frames */
265#define VIDIOCGMBUF _IOR('v',20, struct video_mbuf) /* Memory map buffer info */
266#define VIDIOCGUNIT _IOR('v',21, struct video_unit) /* Get attached units */
267#define VIDIOCGCAPTURE _IOR('v',22, struct video_capture) /* Get subcapture */
268#define VIDIOCSCAPTURE _IOW('v',23, struct video_capture) /* Set subcapture */
269#define VIDIOCSPLAYMODE _IOW('v',24, struct video_play_mode) /* Set output video mode/feature */
270#define VIDIOCSWRITEMODE _IOW('v',25, int) /* Set write mode */
271#define VIDIOCGPLAYINFO _IOR('v',26, struct video_info) /* Get current playback info from hardware */
272#define VIDIOCSMICROCODE _IOW('v',27, struct video_code) /* Load microcode into hardware */
273#define VIDIOCGVBIFMT _IOR('v',28, struct vbi_format) /* Get VBI information */
274#define VIDIOCSVBIFMT _IOW('v',29, struct vbi_format) /* Set VBI information */
275
276
277#define BASE_VIDIOCPRIVATE 192 /* 192-255 are private */
278
279/* VIDIOCSWRITEMODE */
280#define VID_WRITE_MPEG_AUD 0
281#define VID_WRITE_MPEG_VID 1
282#define VID_WRITE_OSD 2
283#define VID_WRITE_TTX 3
284#define VID_WRITE_CC 4
285#define VID_WRITE_MJPEG 5
286
287/* VIDIOCSPLAYMODE */
288#define VID_PLAY_VID_OUT_MODE 0
289 /* p1: = VIDEO_MODE_PAL, VIDEO_MODE_NTSC, etc ... */
290#define VID_PLAY_GENLOCK 1
291 /* p1: 0 = OFF, 1 = ON */
292 /* p2: GENLOCK FINE DELAY value */
293#define VID_PLAY_NORMAL 2
294#define VID_PLAY_PAUSE 3
295#define VID_PLAY_SINGLE_FRAME 4
296#define VID_PLAY_FAST_FORWARD 5
297#define VID_PLAY_SLOW_MOTION 6
298#define VID_PLAY_IMMEDIATE_NORMAL 7
299#define VID_PLAY_SWITCH_CHANNELS 8
300#define VID_PLAY_FREEZE_FRAME 9
301#define VID_PLAY_STILL_MODE 10
302#define VID_PLAY_MASTER_MODE 11
303 /* p1: see below */
304#define VID_PLAY_MASTER_NONE 1
305#define VID_PLAY_MASTER_VIDEO 2
306#define VID_PLAY_MASTER_AUDIO 3
307#define VID_PLAY_ACTIVE_SCANLINES 12
308 /* p1 = first active; p2 = last active */
309#define VID_PLAY_RESET 13
310#define VID_PLAY_END_MARK 14
311
312#endif /* __LINUX_VIDEODEV_H */
313
314/*
315 * Local variables:
316 * c-basic-offset: 8
317 * End:
318 */
diff --git a/drivers/staging/stradis/Kconfig b/drivers/staging/stradis/Kconfig
deleted file mode 100644
index 02f0fc504cf5..000000000000
--- a/drivers/staging/stradis/Kconfig
+++ /dev/null
@@ -1,7 +0,0 @@
1config VIDEO_STRADIS
2 tristate "Stradis 4:2:2 MPEG-2 video driver (DEPRECATED)"
3 depends on EXPERIMENTAL && PCI && VIDEO_V4L1 && VIRT_TO_BUS && BKL
4 help
5 Say Y here to enable support for the Stradis 4:2:2 MPEG-2 video
6 driver for PCI. There is a product page at
7 <http://www.stradis.com/>.
diff --git a/drivers/staging/stradis/Makefile b/drivers/staging/stradis/Makefile
deleted file mode 100644
index 0f1feab59e39..000000000000
--- a/drivers/staging/stradis/Makefile
+++ /dev/null
@@ -1,3 +0,0 @@
1obj-$(CONFIG_VIDEO_STRADIS) += stradis.o
2
3EXTRA_CFLAGS += -Idrivers/media/video
diff --git a/drivers/staging/stradis/TODO b/drivers/staging/stradis/TODO
deleted file mode 100644
index f48150fe2fa9..000000000000
--- a/drivers/staging/stradis/TODO
+++ /dev/null
@@ -1,6 +0,0 @@
1This is an obsolete driver for ancient stradis hardware.
2We couldn't find anyone with this hardware in order to port it to use V4L2.
3
4If nobody take care on it, the driver will be removed for 2.6.38.
5
6Please send patches to linux-media@vger.kernel.org
diff --git a/drivers/staging/stradis/stradis.c b/drivers/staging/stradis/stradis.c
deleted file mode 100644
index 807dd7eb748f..000000000000
--- a/drivers/staging/stradis/stradis.c
+++ /dev/null
@@ -1,2222 +0,0 @@
1/*
2 * stradis.c - stradis 4:2:2 mpeg decoder driver
3 *
4 * Stradis 4:2:2 MPEG-2 Decoder Driver
5 * Copyright (C) 1999 Nathan Laredo <laredo@gnu.org>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22#include <linux/module.h>
23#include <linux/delay.h>
24#include <linux/errno.h>
25#include <linux/fs.h>
26#include <linux/kernel.h>
27#include <linux/major.h>
28#include <linux/slab.h>
29#include <linux/smp_lock.h>
30#include <linux/mm.h>
31#include <linux/init.h>
32#include <linux/poll.h>
33#include <linux/pci.h>
34#include <linux/signal.h>
35#include <asm/io.h>
36#include <linux/ioport.h>
37#include <asm/pgtable.h>
38#include <asm/page.h>
39#include <linux/sched.h>
40#include <asm/types.h>
41#include <linux/types.h>
42#include <linux/interrupt.h>
43#include <asm/uaccess.h>
44#include <linux/vmalloc.h>
45#include <linux/videodev.h>
46#include <media/v4l2-common.h>
47#include <media/v4l2-ioctl.h>
48
49#include "saa7146.h"
50#include "saa7146reg.h"
51#include "ibmmpeg2.h"
52#include "saa7121.h"
53#include "cs8420.h"
54
55#define DEBUG(x) /* debug driver */
56#undef IDEBUG /* debug irq handler */
57#undef MDEBUG /* debug memory management */
58
59#define SAA7146_MAX 6
60
61static struct saa7146 saa7146s[SAA7146_MAX];
62
63static int saa_num; /* number of SAA7146s in use */
64
65static int video_nr = -1;
66module_param(video_nr, int, 0);
67MODULE_LICENSE("GPL");
68
69#define nDebNormal 0x00480000
70#define nDebNoInc 0x00480000
71#define nDebVideo 0xd0480000
72#define nDebAudio 0xd0400000
73#define nDebDMA 0x02c80000
74
75#define oDebNormal 0x13c80000
76#define oDebNoInc 0x13c80000
77#define oDebVideo 0xd1080000
78#define oDebAudio 0xd1080000
79#define oDebDMA 0x03080000
80
81#define NewCard (saa->boardcfg[3])
82#define ChipControl (saa->boardcfg[1])
83#define NTSCFirstActive (saa->boardcfg[4])
84#define PALFirstActive (saa->boardcfg[5])
85#define NTSCLastActive (saa->boardcfg[54])
86#define PALLastActive (saa->boardcfg[55])
87#define Have2MB (saa->boardcfg[18] & 0x40)
88#define HaveCS8420 (saa->boardcfg[18] & 0x04)
89#define IBMMPEGCD20 (saa->boardcfg[18] & 0x20)
90#define HaveCS3310 (saa->boardcfg[18] & 0x01)
91#define CS3310MaxLvl ((saa->boardcfg[30] << 8) | saa->boardcfg[31])
92#define HaveCS4341 (saa->boardcfg[40] == 2)
93#define SDIType (saa->boardcfg[27])
94#define CurrentMode (saa->boardcfg[2])
95
96#define debNormal (NewCard ? nDebNormal : oDebNormal)
97#define debNoInc (NewCard ? nDebNoInc : oDebNoInc)
98#define debVideo (NewCard ? nDebVideo : oDebVideo)
99#define debAudio (NewCard ? nDebAudio : oDebAudio)
100#define debDMA (NewCard ? nDebDMA : oDebDMA)
101
102#ifdef USE_RESCUE_EEPROM_SDM275
103static unsigned char rescue_eeprom[64] = {
104 0x00, 0x01, 0x04, 0x13, 0x26, 0x0f, 0x10, 0x00, 0x00, 0x00, 0x43, 0x63,
105 0x22, 0x01, 0x29, 0x15, 0x73, 0x00, 0x1f, 'd', 'e', 'c', 'x', 'l',
106 'd', 'v', 'a', 0x02, 0x00, 0x01, 0x00, 0xcc, 0xa4, 0x63, 0x09, 0xe2,
107 0x10, 0x00, 0x0a, 0x00, 0x02, 0x02, 'd', 'e', 'c', 'x', 'l', 'a',
108 0x00, 0x00, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
109 0x00, 0x00, 0x00, 0x00,
110};
111#endif
112
113/* ----------------------------------------------------------------------- */
114/* Hardware I2C functions */
115static void I2CWipe(struct saa7146 *saa)
116{
117 int i;
118 /* set i2c to ~=100kHz, abort transfer, clear busy */
119 saawrite(0x600 | SAA7146_I2C_ABORT, SAA7146_I2C_STATUS);
120 saawrite((SAA7146_MC2_UPLD_I2C << 16) |
121 SAA7146_MC2_UPLD_I2C, SAA7146_MC2);
122 /* wait for i2c registers to be programmed */
123 for (i = 0; i < 1000 &&
124 !(saaread(SAA7146_MC2) & SAA7146_MC2_UPLD_I2C); i++)
125 schedule();
126 saawrite(0x600, SAA7146_I2C_STATUS);
127 saawrite((SAA7146_MC2_UPLD_I2C << 16) |
128 SAA7146_MC2_UPLD_I2C, SAA7146_MC2);
129 /* wait for i2c registers to be programmed */
130 for (i = 0; i < 1000 &&
131 !(saaread(SAA7146_MC2) & SAA7146_MC2_UPLD_I2C); i++)
132 schedule();
133 saawrite(0x600, SAA7146_I2C_STATUS);
134 saawrite((SAA7146_MC2_UPLD_I2C << 16) |
135 SAA7146_MC2_UPLD_I2C, SAA7146_MC2);
136 /* wait for i2c registers to be programmed */
137 for (i = 0; i < 1000 &&
138 !(saaread(SAA7146_MC2) & SAA7146_MC2_UPLD_I2C); i++)
139 schedule();
140}
141
142/* read I2C */
143static int I2CRead(struct saa7146 *saa, unsigned char addr,
144 unsigned char subaddr, int dosub)
145{
146 int i;
147
148 if (saaread(SAA7146_I2C_STATUS) & 0x3c)
149 I2CWipe(saa);
150 for (i = 0;
151 i < 1000 && (saaread(SAA7146_I2C_STATUS) & SAA7146_I2C_BUSY);
152 i++)
153 schedule();
154 if (i == 1000)
155 I2CWipe(saa);
156 if (dosub)
157 saawrite(((addr & 0xfe) << 24) | (((addr | 1) & 0xff) << 8) |
158 ((subaddr & 0xff) << 16) | 0xed, SAA7146_I2C_TRANSFER);
159 else
160 saawrite(((addr & 0xfe) << 24) | (((addr | 1) & 0xff) << 16) |
161 0xf1, SAA7146_I2C_TRANSFER);
162 saawrite((SAA7146_MC2_UPLD_I2C << 16) |
163 SAA7146_MC2_UPLD_I2C, SAA7146_MC2);
164 /* wait for i2c registers to be programmed */
165 for (i = 0; i < 1000 &&
166 !(saaread(SAA7146_MC2) & SAA7146_MC2_UPLD_I2C); i++)
167 schedule();
168 /* wait for valid data */
169 for (i = 0; i < 1000 &&
170 (saaread(SAA7146_I2C_STATUS) & SAA7146_I2C_BUSY); i++)
171 schedule();
172 if (saaread(SAA7146_I2C_STATUS) & SAA7146_I2C_ERR)
173 return -1;
174 if (i == 1000)
175 printk("i2c setup read timeout\n");
176 saawrite(0x41, SAA7146_I2C_TRANSFER);
177 saawrite((SAA7146_MC2_UPLD_I2C << 16) |
178 SAA7146_MC2_UPLD_I2C, SAA7146_MC2);
179 /* wait for i2c registers to be programmed */
180 for (i = 0; i < 1000 &&
181 !(saaread(SAA7146_MC2) & SAA7146_MC2_UPLD_I2C); i++)
182 schedule();
183 /* wait for valid data */
184 for (i = 0; i < 1000 &&
185 (saaread(SAA7146_I2C_TRANSFER) & SAA7146_I2C_BUSY); i++)
186 schedule();
187 if (saaread(SAA7146_I2C_TRANSFER) & SAA7146_I2C_ERR)
188 return -1;
189 if (i == 1000)
190 printk("i2c read timeout\n");
191 return ((saaread(SAA7146_I2C_TRANSFER) >> 24) & 0xff);
192}
193
194/* set both to write both bytes, reset it to write only b1 */
195
196static int I2CWrite(struct saa7146 *saa, unsigned char addr, unsigned char b1,
197 unsigned char b2, int both)
198{
199 int i;
200 u32 data;
201
202 if (saaread(SAA7146_I2C_STATUS) & 0x3c)
203 I2CWipe(saa);
204 for (i = 0; i < 1000 &&
205 (saaread(SAA7146_I2C_STATUS) & SAA7146_I2C_BUSY); i++)
206 schedule();
207 if (i == 1000)
208 I2CWipe(saa);
209 data = ((addr & 0xfe) << 24) | ((b1 & 0xff) << 16);
210 if (both)
211 data |= ((b2 & 0xff) << 8) | 0xe5;
212 else
213 data |= 0xd1;
214 saawrite(data, SAA7146_I2C_TRANSFER);
215 saawrite((SAA7146_MC2_UPLD_I2C << 16) | SAA7146_MC2_UPLD_I2C,
216 SAA7146_MC2);
217 return 0;
218}
219
220static void attach_inform(struct saa7146 *saa, int id)
221{
222 int i;
223
224 DEBUG(printk(KERN_DEBUG "stradis%d: i2c: device found=%02x\n", saa->nr,
225 id));
226 if (id == 0xa0) { /* we have rev2 or later board, fill in info */
227 for (i = 0; i < 64; i++)
228 saa->boardcfg[i] = I2CRead(saa, 0xa0, i, 1);
229#ifdef USE_RESCUE_EEPROM_SDM275
230 if (saa->boardcfg[0] != 0) {
231 printk("stradis%d: WARNING: EEPROM STORED VALUES HAVE "
232 "BEEN IGNORED\n", saa->nr);
233 for (i = 0; i < 64; i++)
234 saa->boardcfg[i] = rescue_eeprom[i];
235 }
236#endif
237 printk("stradis%d: config =", saa->nr);
238 for (i = 0; i < 51; i++) {
239 printk(" %02x", saa->boardcfg[i]);
240 }
241 printk("\n");
242 }
243}
244
245static void I2CBusScan(struct saa7146 *saa)
246{
247 int i;
248 for (i = 0; i < 0xff; i += 2)
249 if ((I2CRead(saa, i, 0, 0)) >= 0)
250 attach_inform(saa, i);
251}
252
253static int debiwait_maxwait;
254
255static int wait_for_debi_done(struct saa7146 *saa)
256{
257 int i;
258
259 /* wait for registers to be programmed */
260 for (i = 0; i < 100000 &&
261 !(saaread(SAA7146_MC2) & SAA7146_MC2_UPLD_DEBI); i++)
262 saaread(SAA7146_MC2);
263 /* wait for transfer to complete */
264 for (i = 0; i < 500000 &&
265 (saaread(SAA7146_PSR) & SAA7146_PSR_DEBI_S); i++)
266 saaread(SAA7146_MC2);
267
268 if (i > debiwait_maxwait)
269 printk("wait-for-debi-done maxwait: %d\n",
270 debiwait_maxwait = i);
271
272 if (i == 500000)
273 return -1;
274
275 return 0;
276}
277
278static int debiwrite(struct saa7146 *saa, u32 config, int addr,
279 u32 val, int count)
280{
281 u32 cmd;
282 if (count <= 0 || count > 32764)
283 return -1;
284 if (wait_for_debi_done(saa) < 0)
285 return -1;
286 saawrite(config, SAA7146_DEBI_CONFIG);
287 if (count <= 4) /* immediate transfer */
288 saawrite(val, SAA7146_DEBI_AD);
289 else /* block transfer */
290 saawrite(virt_to_bus(saa->dmadebi), SAA7146_DEBI_AD);
291 saawrite((cmd = (count << 17) | (addr & 0xffff)), SAA7146_DEBI_COMMAND);
292 saawrite((SAA7146_MC2_UPLD_DEBI << 16) | SAA7146_MC2_UPLD_DEBI,
293 SAA7146_MC2);
294 return 0;
295}
296
297static u32 debiread(struct saa7146 *saa, u32 config, int addr, int count)
298{
299 u32 result = 0;
300
301 if (count > 32764 || count <= 0)
302 return 0;
303 if (wait_for_debi_done(saa) < 0)
304 return 0;
305 saawrite(virt_to_bus(saa->dmadebi), SAA7146_DEBI_AD);
306 saawrite((count << 17) | 0x10000 | (addr & 0xffff),
307 SAA7146_DEBI_COMMAND);
308 saawrite(config, SAA7146_DEBI_CONFIG);
309 saawrite((SAA7146_MC2_UPLD_DEBI << 16) | SAA7146_MC2_UPLD_DEBI,
310 SAA7146_MC2);
311 if (count > 4) /* not an immediate transfer */
312 return count;
313 wait_for_debi_done(saa);
314 result = saaread(SAA7146_DEBI_AD);
315 if (count == 1)
316 result &= 0xff;
317 if (count == 2)
318 result &= 0xffff;
319 if (count == 3)
320 result &= 0xffffff;
321 return result;
322}
323
324static void do_irq_send_data(struct saa7146 *saa)
325{
326 int split, audbytes, vidbytes;
327
328 saawrite(SAA7146_PSR_PIN1, SAA7146_IER);
329 /* if special feature mode in effect, disable audio sending */
330 if (saa->playmode != VID_PLAY_NORMAL)
331 saa->audtail = saa->audhead = 0;
332 if (saa->audhead <= saa->audtail)
333 audbytes = saa->audtail - saa->audhead;
334 else
335 audbytes = 65536 - (saa->audhead - saa->audtail);
336 if (saa->vidhead <= saa->vidtail)
337 vidbytes = saa->vidtail - saa->vidhead;
338 else
339 vidbytes = 524288 - (saa->vidhead - saa->vidtail);
340 if (audbytes == 0 && vidbytes == 0 && saa->osdtail == saa->osdhead) {
341 saawrite(0, SAA7146_IER);
342 return;
343 }
344 /* if at least 1 block audio waiting and audio fifo isn't full */
345 if (audbytes >= 2048 && (debiread(saa, debNormal, IBM_MP2_AUD_FIFO, 2)
346 & 0xff) < 60) {
347 if (saa->audhead > saa->audtail)
348 split = 65536 - saa->audhead;
349 else
350 split = 0;
351 audbytes = 2048;
352 if (split > 0 && split < 2048) {
353 memcpy(saa->dmadebi, saa->audbuf + saa->audhead, split);
354 saa->audhead = 0;
355 audbytes -= split;
356 } else
357 split = 0;
358 memcpy(saa->dmadebi + split, saa->audbuf + saa->audhead,
359 audbytes);
360 saa->audhead += audbytes;
361 saa->audhead &= 0xffff;
362 debiwrite(saa, debAudio, (NewCard ? IBM_MP2_AUD_FIFO :
363 IBM_MP2_AUD_FIFOW), 0, 2048);
364 wake_up_interruptible(&saa->audq);
365 /* if at least 1 block video waiting and video fifo isn't full */
366 } else if (vidbytes >= 30720 && (debiread(saa, debNormal,
367 IBM_MP2_FIFO, 2)) < 16384) {
368 if (saa->vidhead > saa->vidtail)
369 split = 524288 - saa->vidhead;
370 else
371 split = 0;
372 vidbytes = 30720;
373 if (split > 0 && split < 30720) {
374 memcpy(saa->dmadebi, saa->vidbuf + saa->vidhead, split);
375 saa->vidhead = 0;
376 vidbytes -= split;
377 } else
378 split = 0;
379 memcpy(saa->dmadebi + split, saa->vidbuf + saa->vidhead,
380 vidbytes);
381 saa->vidhead += vidbytes;
382 saa->vidhead &= 0x7ffff;
383 debiwrite(saa, debVideo, (NewCard ? IBM_MP2_FIFO :
384 IBM_MP2_FIFOW), 0, 30720);
385 wake_up_interruptible(&saa->vidq);
386 }
387 saawrite(SAA7146_PSR_DEBI_S | SAA7146_PSR_PIN1, SAA7146_IER);
388}
389
390static void send_osd_data(struct saa7146 *saa)
391{
392 int size = saa->osdtail - saa->osdhead;
393 if (size > 30720)
394 size = 30720;
395 /* ensure some multiple of 8 bytes is transferred */
396 size = 8 * ((size + 8) >> 3);
397 if (size) {
398 debiwrite(saa, debNormal, IBM_MP2_OSD_ADDR,
399 (saa->osdhead >> 3), 2);
400 memcpy(saa->dmadebi, &saa->osdbuf[saa->osdhead], size);
401 saa->osdhead += size;
402 /* block transfer of next 8 bytes to ~32k bytes */
403 debiwrite(saa, debNormal, IBM_MP2_OSD_DATA, 0, size);
404 }
405 if (saa->osdhead >= saa->osdtail) {
406 saa->osdhead = saa->osdtail = 0;
407 debiwrite(saa, debNormal, IBM_MP2_MASK0, 0xc00c, 2);
408 }
409}
410
411static irqreturn_t saa7146_irq(int irq, void *dev_id)
412{
413 struct saa7146 *saa = dev_id;
414 u32 stat, astat;
415 int count;
416 int handled = 0;
417
418 count = 0;
419 while (1) {
420 /* get/clear interrupt status bits */
421 stat = saaread(SAA7146_ISR);
422 astat = stat & saaread(SAA7146_IER);
423 if (!astat)
424 break;
425 handled = 1;
426 saawrite(astat, SAA7146_ISR);
427 if (astat & SAA7146_PSR_DEBI_S) {
428 do_irq_send_data(saa);
429 }
430 if (astat & SAA7146_PSR_PIN1) {
431 int istat;
432 /* the following read will trigger DEBI_S */
433 istat = debiread(saa, debNormal, IBM_MP2_HOST_INT, 2);
434 if (istat & 1) {
435 saawrite(0, SAA7146_IER);
436 send_osd_data(saa);
437 saawrite(SAA7146_PSR_DEBI_S |
438 SAA7146_PSR_PIN1, SAA7146_IER);
439 }
440 if (istat & 0x20) { /* Video Start */
441 saa->vidinfo.frame_count++;
442 }
443 if (istat & 0x400) { /* Picture Start */
444 /* update temporal reference */
445 }
446 if (istat & 0x200) { /* Picture Resolution Change */
447 /* read new resolution */
448 }
449 if (istat & 0x100) { /* New User Data found */
450 /* read new user data */
451 }
452 if (istat & 0x1000) { /* new GOP/SMPTE */
453 /* read new SMPTE */
454 }
455 if (istat & 0x8000) { /* Sequence Start Code */
456 /* reset frame counter, load sizes */
457 saa->vidinfo.frame_count = 0;
458 saa->vidinfo.h_size = 704;
459 saa->vidinfo.v_size = 480;
460#if 0
461 if (saa->endmarkhead != saa->endmarktail) {
462 saa->audhead =
463 saa->endmark[saa->endmarkhead];
464 saa->endmarkhead++;
465 if (saa->endmarkhead >= MAX_MARKS)
466 saa->endmarkhead = 0;
467 }
468#endif
469 }
470 if (istat & 0x4000) { /* Sequence Error Code */
471 if (saa->endmarkhead != saa->endmarktail) {
472 saa->audhead =
473 saa->endmark[saa->endmarkhead];
474 saa->endmarkhead++;
475 if (saa->endmarkhead >= MAX_MARKS)
476 saa->endmarkhead = 0;
477 }
478 }
479 }
480#ifdef IDEBUG
481 if (astat & SAA7146_PSR_PPEF) {
482 IDEBUG(printk("stradis%d irq: PPEF\n", saa->nr));
483 }
484 if (astat & SAA7146_PSR_PABO) {
485 IDEBUG(printk("stradis%d irq: PABO\n", saa->nr));
486 }
487 if (astat & SAA7146_PSR_PPED) {
488 IDEBUG(printk("stradis%d irq: PPED\n", saa->nr));
489 }
490 if (astat & SAA7146_PSR_RPS_I1) {
491 IDEBUG(printk("stradis%d irq: RPS_I1\n", saa->nr));
492 }
493 if (astat & SAA7146_PSR_RPS_I0) {
494 IDEBUG(printk("stradis%d irq: RPS_I0\n", saa->nr));
495 }
496 if (astat & SAA7146_PSR_RPS_LATE1) {
497 IDEBUG(printk("stradis%d irq: RPS_LATE1\n", saa->nr));
498 }
499 if (astat & SAA7146_PSR_RPS_LATE0) {
500 IDEBUG(printk("stradis%d irq: RPS_LATE0\n", saa->nr));
501 }
502 if (astat & SAA7146_PSR_RPS_E1) {
503 IDEBUG(printk("stradis%d irq: RPS_E1\n", saa->nr));
504 }
505 if (astat & SAA7146_PSR_RPS_E0) {
506 IDEBUG(printk("stradis%d irq: RPS_E0\n", saa->nr));
507 }
508 if (astat & SAA7146_PSR_RPS_TO1) {
509 IDEBUG(printk("stradis%d irq: RPS_TO1\n", saa->nr));
510 }
511 if (astat & SAA7146_PSR_RPS_TO0) {
512 IDEBUG(printk("stradis%d irq: RPS_TO0\n", saa->nr));
513 }
514 if (astat & SAA7146_PSR_UPLD) {
515 IDEBUG(printk("stradis%d irq: UPLD\n", saa->nr));
516 }
517 if (astat & SAA7146_PSR_DEBI_E) {
518 IDEBUG(printk("stradis%d irq: DEBI_E\n", saa->nr));
519 }
520 if (astat & SAA7146_PSR_I2C_S) {
521 IDEBUG(printk("stradis%d irq: I2C_S\n", saa->nr));
522 }
523 if (astat & SAA7146_PSR_I2C_E) {
524 IDEBUG(printk("stradis%d irq: I2C_E\n", saa->nr));
525 }
526 if (astat & SAA7146_PSR_A2_IN) {
527 IDEBUG(printk("stradis%d irq: A2_IN\n", saa->nr));
528 }
529 if (astat & SAA7146_PSR_A2_OUT) {
530 IDEBUG(printk("stradis%d irq: A2_OUT\n", saa->nr));
531 }
532 if (astat & SAA7146_PSR_A1_IN) {
533 IDEBUG(printk("stradis%d irq: A1_IN\n", saa->nr));
534 }
535 if (astat & SAA7146_PSR_A1_OUT) {
536 IDEBUG(printk("stradis%d irq: A1_OUT\n", saa->nr));
537 }
538 if (astat & SAA7146_PSR_AFOU) {
539 IDEBUG(printk("stradis%d irq: AFOU\n", saa->nr));
540 }
541 if (astat & SAA7146_PSR_V_PE) {
542 IDEBUG(printk("stradis%d irq: V_PE\n", saa->nr));
543 }
544 if (astat & SAA7146_PSR_VFOU) {
545 IDEBUG(printk("stradis%d irq: VFOU\n", saa->nr));
546 }
547 if (astat & SAA7146_PSR_FIDA) {
548 IDEBUG(printk("stradis%d irq: FIDA\n", saa->nr));
549 }
550 if (astat & SAA7146_PSR_FIDB) {
551 IDEBUG(printk("stradis%d irq: FIDB\n", saa->nr));
552 }
553 if (astat & SAA7146_PSR_PIN3) {
554 IDEBUG(printk("stradis%d irq: PIN3\n", saa->nr));
555 }
556 if (astat & SAA7146_PSR_PIN2) {
557 IDEBUG(printk("stradis%d irq: PIN2\n", saa->nr));
558 }
559 if (astat & SAA7146_PSR_PIN0) {
560 IDEBUG(printk("stradis%d irq: PIN0\n", saa->nr));
561 }
562 if (astat & SAA7146_PSR_ECS) {
563 IDEBUG(printk("stradis%d irq: ECS\n", saa->nr));
564 }
565 if (astat & SAA7146_PSR_EC3S) {
566 IDEBUG(printk("stradis%d irq: EC3S\n", saa->nr));
567 }
568 if (astat & SAA7146_PSR_EC0S) {
569 IDEBUG(printk("stradis%d irq: EC0S\n", saa->nr));
570 }
571#endif
572 count++;
573 if (count > 15)
574 printk(KERN_WARNING "stradis%d: irq loop %d\n",
575 saa->nr, count);
576 if (count > 20) {
577 saawrite(0, SAA7146_IER);
578 printk(KERN_ERR
579 "stradis%d: IRQ loop cleared\n", saa->nr);
580 }
581 }
582 return IRQ_RETVAL(handled);
583}
584
585static int ibm_send_command(struct saa7146 *saa,
586 int command, int data, int chain)
587{
588 int i;
589
590 if (chain)
591 debiwrite(saa, debNormal, IBM_MP2_COMMAND, (command << 1)| 1,2);
592 else
593 debiwrite(saa, debNormal, IBM_MP2_COMMAND, command << 1, 2);
594 debiwrite(saa, debNormal, IBM_MP2_CMD_DATA, data, 2);
595 debiwrite(saa, debNormal, IBM_MP2_CMD_STAT, 1, 2);
596 for (i = 0; i < 100 &&
597 (debiread(saa, debNormal, IBM_MP2_CMD_STAT, 2) & 1); i++)
598 schedule();
599 if (i == 100)
600 return -1;
601 return 0;
602}
603
604static void cs4341_setlevel(struct saa7146 *saa, int left, int right)
605{
606 I2CWrite(saa, 0x22, 0x03, left > 94 ? 94 : left, 2);
607 I2CWrite(saa, 0x22, 0x04, right > 94 ? 94 : right, 2);
608}
609
610static void initialize_cs4341(struct saa7146 *saa)
611{
612 int i;
613 for (i = 0; i < 200; i++) {
614 /* auto mute off, power on, no de-emphasis */
615 /* I2S data up to 24-bit 64xFs internal SCLK */
616 I2CWrite(saa, 0x22, 0x01, 0x11, 2);
617 /* ATAPI mixer settings */
618 I2CWrite(saa, 0x22, 0x02, 0x49, 2);
619 /* attenuation left 3db */
620 I2CWrite(saa, 0x22, 0x03, 0x00, 2);
621 /* attenuation right 3db */
622 I2CWrite(saa, 0x22, 0x04, 0x00, 2);
623 I2CWrite(saa, 0x22, 0x01, 0x10, 2);
624 if (I2CRead(saa, 0x22, 0x02, 1) == 0x49)
625 break;
626 schedule();
627 }
628 printk("stradis%d: CS4341 initialized (%d)\n", saa->nr, i);
629 return;
630}
631
632static void initialize_cs8420(struct saa7146 *saa, int pro)
633{
634 int i;
635 u8 *sequence;
636 if (pro)
637 sequence = mode8420pro;
638 else
639 sequence = mode8420con;
640 for (i = 0; i < INIT8420LEN; i++)
641 I2CWrite(saa, 0x20, init8420[i * 2], init8420[i * 2 + 1], 2);
642 for (i = 0; i < MODE8420LEN; i++)
643 I2CWrite(saa, 0x20, sequence[i * 2], sequence[i * 2 + 1], 2);
644 printk("stradis%d: CS8420 initialized\n", saa->nr);
645}
646
647static void initialize_saa7121(struct saa7146 *saa, int dopal)
648{
649 int i, mod;
650 u8 *sequence;
651 if (dopal)
652 sequence = init7121pal;
653 else
654 sequence = init7121ntsc;
655 mod = saaread(SAA7146_PSR) & 0x08;
656 /* initialize PAL/NTSC video encoder */
657 for (i = 0; i < INIT7121LEN; i++) {
658 if (NewCard) { /* handle new card encoder differences */
659 if (sequence[i * 2] == 0x3a)
660 I2CWrite(saa, 0x88, 0x3a, 0x13, 2);
661 else if (sequence[i * 2] == 0x6b)
662 I2CWrite(saa, 0x88, 0x6b, 0x20, 2);
663 else if (sequence[i * 2] == 0x6c)
664 I2CWrite(saa, 0x88, 0x6c,
665 dopal ? 0x09 : 0xf5, 2);
666 else if (sequence[i * 2] == 0x6d)
667 I2CWrite(saa, 0x88, 0x6d,
668 dopal ? 0x20 : 0x00, 2);
669 else if (sequence[i * 2] == 0x7a)
670 I2CWrite(saa, 0x88, 0x7a,
671 dopal ? (PALFirstActive - 1) :
672 (NTSCFirstActive - 4), 2);
673 else if (sequence[i * 2] == 0x7b)
674 I2CWrite(saa, 0x88, 0x7b,
675 dopal ? PALLastActive :
676 NTSCLastActive, 2);
677 else
678 I2CWrite(saa, 0x88, sequence[i * 2],
679 sequence[i * 2 + 1], 2);
680 } else {
681 if (sequence[i * 2] == 0x6b && mod)
682 I2CWrite(saa, 0x88, 0x6b,
683 (sequence[i * 2 + 1] ^ 0x09), 2);
684 else if (sequence[i * 2] == 0x7a)
685 I2CWrite(saa, 0x88, 0x7a,
686 dopal ? (PALFirstActive - 1) :
687 (NTSCFirstActive - 4), 2);
688 else if (sequence[i * 2] == 0x7b)
689 I2CWrite(saa, 0x88, 0x7b,
690 dopal ? PALLastActive :
691 NTSCLastActive, 2);
692 else
693 I2CWrite(saa, 0x88, sequence[i * 2],
694 sequence[i * 2 + 1], 2);
695 }
696 }
697}
698
699static void set_genlock_offset(struct saa7146 *saa, int noffset)
700{
701 int nCode;
702 int PixelsPerLine = 858;
703 if (CurrentMode == VIDEO_MODE_PAL)
704 PixelsPerLine = 864;
705 if (noffset > 500)
706 noffset = 500;
707 else if (noffset < -500)
708 noffset = -500;
709 nCode = noffset + 0x100;
710 if (nCode == 1)
711 nCode = 0x401;
712 else if (nCode < 1)
713 nCode = 0x400 + PixelsPerLine + nCode;
714 debiwrite(saa, debNormal, XILINX_GLDELAY, nCode, 2);
715}
716
717static void set_out_format(struct saa7146 *saa, int mode)
718{
719 initialize_saa7121(saa, (mode == VIDEO_MODE_NTSC ? 0 : 1));
720 saa->boardcfg[2] = mode;
721 /* do not adjust analog video parameters here, use saa7121 init */
722 /* you will affect the SDI output on the new card */
723 if (mode == VIDEO_MODE_PAL) { /* PAL */
724 debiwrite(saa, debNormal, XILINX_CTL0, 0x0808, 2);
725 mdelay(50);
726 saawrite(0x012002c0, SAA7146_NUM_LINE_BYTE1);
727 if (NewCard) {
728 debiwrite(saa, debNormal, IBM_MP2_DISP_MODE, 0xe100, 2);
729 mdelay(50);
730 }
731 debiwrite(saa, debNormal, IBM_MP2_DISP_MODE,
732 NewCard ? 0xe500 : 0x6500, 2);
733 debiwrite(saa, debNormal, IBM_MP2_DISP_DLY,
734 (1 << 8) |
735 (NewCard ? PALFirstActive : PALFirstActive - 6), 2);
736 } else { /* NTSC */
737 debiwrite(saa, debNormal, XILINX_CTL0, 0x0800, 2);
738 mdelay(50);
739 saawrite(0x00f002c0, SAA7146_NUM_LINE_BYTE1);
740 debiwrite(saa, debNormal, IBM_MP2_DISP_MODE,
741 NewCard ? 0xe100 : 0x6100, 2);
742 debiwrite(saa, debNormal, IBM_MP2_DISP_DLY,
743 (1 << 8) |
744 (NewCard ? NTSCFirstActive : NTSCFirstActive - 6), 2);
745 }
746}
747
748/* Intialize bitmangler to map from a byte value to the mangled word that
749 * must be output to program the Xilinx part through the DEBI port.
750 * Xilinx Data Bit->DEBI Bit: 0->15 1->7 2->6 3->12 4->11 5->2 6->1 7->0
751 * transfer FPGA code, init IBM chip, transfer IBM microcode
752 * rev2 card mangles: 0->7 1->6 2->5 3->4 4->3 5->2 6->1 7->0
753 */
754static u16 bitmangler[256];
755
756static int initialize_fpga(struct video_code *bitdata)
757{
758 int i, num, startindex, failure = 0, loadtwo, loadfile = 0;
759 u16 *dmabuf;
760 u8 *newdma;
761 struct saa7146 *saa;
762
763 /* verify fpga code */
764 for (startindex = 0; startindex < bitdata->datasize; startindex++)
765 if (bitdata->data[startindex] == 255)
766 break;
767 if (startindex == bitdata->datasize) {
768 printk(KERN_INFO "stradis: bad fpga code\n");
769 return -1;
770 }
771 /* initialize all detected cards */
772 for (num = 0; num < saa_num; num++) {
773 saa = &saa7146s[num];
774 if (saa->boardcfg[0] > 20)
775 continue; /* card was programmed */
776 loadtwo = (saa->boardcfg[18] & 0x10);
777 if (!NewCard) /* we have an old board */
778 for (i = 0; i < 256; i++)
779 bitmangler[i] = ((i & 0x01) << 15) |
780 ((i & 0x02) << 6) | ((i & 0x04) << 4) |
781 ((i & 0x08) << 9) | ((i & 0x10) << 7) |
782 ((i & 0x20) >> 3) | ((i & 0x40) >> 5) |
783 ((i & 0x80) >> 7);
784 else /* else we have a new board */
785 for (i = 0; i < 256; i++)
786 bitmangler[i] = ((i & 0x01) << 7) |
787 ((i & 0x02) << 5) | ((i & 0x04) << 3) |
788 ((i & 0x08) << 1) | ((i & 0x10) >> 1) |
789 ((i & 0x20) >> 3) | ((i & 0x40) >> 5) |
790 ((i & 0x80) >> 7);
791
792 dmabuf = (u16 *) saa->dmadebi;
793 newdma = (u8 *) saa->dmadebi;
794 if (NewCard) { /* SDM2xxx */
795 if (!strncmp(bitdata->loadwhat, "decoder2", 8))
796 continue; /* fpga not for this card */
797 if (!strncmp(&saa->boardcfg[42], bitdata->loadwhat, 8))
798 loadfile = 1;
799 else if (loadtwo && !strncmp(&saa->boardcfg[19],
800 bitdata->loadwhat, 8))
801 loadfile = 2;
802 else if (!saa->boardcfg[42] && !strncmp("decxl",
803 bitdata->loadwhat, 8))
804 loadfile = 1; /* special */
805 else
806 continue; /* fpga not for this card */
807 if (loadfile != 1 && loadfile != 2)
808 continue; /* skip to next card */
809 if (saa->boardcfg[0] && loadfile == 1)
810 continue; /* skip to next card */
811 if (saa->boardcfg[0] != 1 && loadfile == 2)
812 continue; /* skip to next card */
813 saa->boardcfg[0]++; /* mark fpga handled */
814 printk("stradis%d: loading %s\n", saa->nr,
815 bitdata->loadwhat);
816 if (loadtwo && loadfile == 2)
817 goto send_fpga_stuff;
818 /* turn on the Audio interface to set PROG low */
819 saawrite(0x00400040, SAA7146_GPIO_CTRL);
820 saaread(SAA7146_PSR); /* ensure posted write */
821 /* wait for everyone to reset */
822 mdelay(10);
823 saawrite(0x00400000, SAA7146_GPIO_CTRL);
824 } else { /* original card */
825 if (strncmp(bitdata->loadwhat, "decoder2", 8))
826 continue; /* fpga not for this card */
827 /* Pull the Xilinx PROG signal WS3 low */
828 saawrite(0x02000200, SAA7146_MC1);
829 /* Turn on the Audio interface so can set PROG low */
830 saawrite(0x000000c0, SAA7146_ACON1);
831 /* Pull the Xilinx INIT signal (GPIO2) low */
832 saawrite(0x00400000, SAA7146_GPIO_CTRL);
833 /* Make sure everybody resets */
834 saaread(SAA7146_PSR); /* ensure posted write */
835 mdelay(10);
836 /* Release the Xilinx PROG signal */
837 saawrite(0x00000000, SAA7146_ACON1);
838 /* Turn off the Audio interface */
839 saawrite(0x02000000, SAA7146_MC1);
840 }
841 /* Release Xilinx INIT signal (WS2) */
842 saawrite(0x00000000, SAA7146_GPIO_CTRL);
843 /* Wait for the INIT to go High */
844 for (i = 0;
845 i < 10000 && !(saaread(SAA7146_PSR) & SAA7146_PSR_PIN2);
846 i++)
847 schedule();
848 if (i == 1000) {
849 printk(KERN_INFO "stradis%d: no fpga INIT\n", saa->nr);
850 return -1;
851 }
852send_fpga_stuff:
853 if (NewCard) {
854 for (i = startindex; i < bitdata->datasize; i++)
855 newdma[i - startindex] =
856 bitmangler[bitdata->data[i]];
857 debiwrite(saa, 0x01420000, 0, 0,
858 ((bitdata->datasize - startindex) + 5));
859 if (loadtwo && loadfile == 1) {
860 printk("stradis%d: awaiting 2nd FPGA bitfile\n",
861 saa->nr);
862 continue; /* skip to next card */
863 }
864 } else {
865 for (i = startindex; i < bitdata->datasize; i++)
866 dmabuf[i - startindex] =
867 bitmangler[bitdata->data[i]];
868 debiwrite(saa, 0x014a0000, 0, 0,
869 ((bitdata->datasize - startindex) + 5) * 2);
870 }
871 for (i = 0;
872 i < 1000 && !(saaread(SAA7146_PSR) & SAA7146_PSR_PIN2);
873 i++)
874 schedule();
875 if (i == 1000) {
876 printk(KERN_INFO "stradis%d: FPGA load failed\n",
877 saa->nr);
878 failure++;
879 continue;
880 }
881 if (!NewCard) {
882 /* Pull the Xilinx INIT signal (GPIO2) low */
883 saawrite(0x00400000, SAA7146_GPIO_CTRL);
884 saaread(SAA7146_PSR); /* ensure posted write */
885 mdelay(2);
886 saawrite(0x00000000, SAA7146_GPIO_CTRL);
887 mdelay(2);
888 }
889 printk(KERN_INFO "stradis%d: FPGA Loaded\n", saa->nr);
890 saa->boardcfg[0] = 26; /* mark fpga programmed */
891 /* set VXCO to its lowest frequency */
892 debiwrite(saa, debNormal, XILINX_PWM, 0, 2);
893 if (NewCard) {
894 /* mute CS3310 */
895 if (HaveCS3310)
896 debiwrite(saa, debNormal, XILINX_CS3310_CMPLT,
897 0, 2);
898 /* set VXCO to PWM mode, release reset, blank on */
899 debiwrite(saa, debNormal, XILINX_CTL0, 0xffc4, 2);
900 mdelay(10);
901 /* unmute CS3310 */
902 if (HaveCS3310)
903 debiwrite(saa, debNormal, XILINX_CTL0,
904 0x2020, 2);
905 }
906 /* set source Black */
907 debiwrite(saa, debNormal, XILINX_CTL0, 0x1707, 2);
908 saa->boardcfg[4] = 22; /* set NTSC First Active Line */
909 saa->boardcfg[5] = 23; /* set PAL First Active Line */
910 saa->boardcfg[54] = 2; /* set NTSC Last Active Line - 256 */
911 saa->boardcfg[55] = 54; /* set PAL Last Active Line - 256 */
912 set_out_format(saa, VIDEO_MODE_NTSC);
913 mdelay(50);
914 /* begin IBM chip init */
915 debiwrite(saa, debNormal, IBM_MP2_CHIP_CONTROL, 4, 2);
916 saaread(SAA7146_PSR); /* wait for reset */
917 mdelay(5);
918 debiwrite(saa, debNormal, IBM_MP2_CHIP_CONTROL, 0, 2);
919 debiread(saa, debNormal, IBM_MP2_CHIP_CONTROL, 2);
920 debiwrite(saa, debNormal, IBM_MP2_CHIP_CONTROL, 0x10, 2);
921 debiwrite(saa, debNormal, IBM_MP2_CMD_ADDR, 0, 2);
922 debiwrite(saa, debNormal, IBM_MP2_CHIP_MODE, 0x2e, 2);
923 if (NewCard) {
924 mdelay(5);
925 /* set i2s rate converter to 48KHz */
926 debiwrite(saa, debNormal, 0x80c0, 6, 2);
927 /* we must init CS8420 first since rev b pulls i2s */
928 /* master clock low and CS4341 needs i2s master to */
929 /* run the i2c port. */
930 if (HaveCS8420)
931 /* 0=consumer, 1=pro */
932 initialize_cs8420(saa, 0);
933
934 mdelay(5);
935 if (HaveCS4341)
936 initialize_cs4341(saa);
937 }
938 debiwrite(saa, debNormal, IBM_MP2_INFC_CTL, 0x48, 2);
939 debiwrite(saa, debNormal, IBM_MP2_BEEP_CTL, 0xa000, 2);
940 debiwrite(saa, debNormal, IBM_MP2_DISP_LBOR, 0, 2);
941 debiwrite(saa, debNormal, IBM_MP2_DISP_TBOR, 0, 2);
942 if (NewCard)
943 set_genlock_offset(saa, 0);
944 debiwrite(saa, debNormal, IBM_MP2_FRNT_ATTEN, 0, 2);
945#if 0
946 /* enable genlock */
947 debiwrite(saa, debNormal, XILINX_CTL0, 0x8000, 2);
948#else
949 /* disable genlock */
950 debiwrite(saa, debNormal, XILINX_CTL0, 0x8080, 2);
951#endif
952 }
953
954 return failure;
955}
956
957static int do_ibm_reset(struct saa7146 *saa)
958{
959 /* failure if decoder not previously programmed */
960 if (saa->boardcfg[0] < 37)
961 return -EIO;
962 /* mute CS3310 */
963 if (HaveCS3310)
964 debiwrite(saa, debNormal, XILINX_CS3310_CMPLT, 0, 2);
965 /* disable interrupts */
966 saawrite(0, SAA7146_IER);
967 saa->audhead = saa->audtail = 0;
968 saa->vidhead = saa->vidtail = 0;
969 /* tristate debi bus, disable debi transfers */
970 saawrite(0x00880000, SAA7146_MC1);
971 /* ensure posted write */
972 saaread(SAA7146_MC1);
973 mdelay(50);
974 /* re-enable debi transfers */
975 saawrite(0x00880088, SAA7146_MC1);
976 /* set source Black */
977 debiwrite(saa, debNormal, XILINX_CTL0, 0x1707, 2);
978 /* begin IBM chip init */
979 set_out_format(saa, CurrentMode);
980 debiwrite(saa, debNormal, IBM_MP2_CHIP_CONTROL, 4, 2);
981 saaread(SAA7146_PSR); /* wait for reset */
982 mdelay(5);
983 debiwrite(saa, debNormal, IBM_MP2_CHIP_CONTROL, 0, 2);
984 debiread(saa, debNormal, IBM_MP2_CHIP_CONTROL, 2);
985 debiwrite(saa, debNormal, IBM_MP2_CHIP_CONTROL, ChipControl, 2);
986 debiwrite(saa, debNormal, IBM_MP2_CHIP_MODE, 0x2e, 2);
987 if (NewCard) {
988 mdelay(5);
989 /* set i2s rate converter to 48KHz */
990 debiwrite(saa, debNormal, 0x80c0, 6, 2);
991 /* we must init CS8420 first since rev b pulls i2s */
992 /* master clock low and CS4341 needs i2s master to */
993 /* run the i2c port. */
994 if (HaveCS8420)
995 /* 0=consumer, 1=pro */
996 initialize_cs8420(saa, 1);
997
998 mdelay(5);
999 if (HaveCS4341)
1000 initialize_cs4341(saa);
1001 }
1002 debiwrite(saa, debNormal, IBM_MP2_INFC_CTL, 0x48, 2);
1003 debiwrite(saa, debNormal, IBM_MP2_BEEP_CTL, 0xa000, 2);
1004 debiwrite(saa, debNormal, IBM_MP2_DISP_LBOR, 0, 2);
1005 debiwrite(saa, debNormal, IBM_MP2_DISP_TBOR, 0, 2);
1006 if (NewCard)
1007 set_genlock_offset(saa, 0);
1008 debiwrite(saa, debNormal, IBM_MP2_FRNT_ATTEN, 0, 2);
1009 debiwrite(saa, debNormal, IBM_MP2_OSD_SIZE, 0x2000, 2);
1010 debiwrite(saa, debNormal, IBM_MP2_AUD_CTL, 0x4552, 2);
1011 if (ibm_send_command(saa, IBM_MP2_CONFIG_DECODER,
1012 (ChipControl == 0x43 ? 0xe800 : 0xe000), 1)) {
1013 printk(KERN_ERR "stradis%d: IBM config failed\n", saa->nr);
1014 }
1015 if (HaveCS3310) {
1016 int i = CS3310MaxLvl;
1017 debiwrite(saa, debNormal, XILINX_CS3310_CMPLT, ((i << 8)| i),2);
1018 }
1019 /* start video decoder */
1020 debiwrite(saa, debNormal, IBM_MP2_CHIP_CONTROL, ChipControl, 2);
1021 /* 256k vid, 3520 bytes aud */
1022 debiwrite(saa, debNormal, IBM_MP2_RB_THRESHOLD, 0x4037, 2);
1023 debiwrite(saa, debNormal, IBM_MP2_AUD_CTL, 0x4573, 2);
1024 ibm_send_command(saa, IBM_MP2_PLAY, 0, 0);
1025 /* enable buffer threshold irq */
1026 debiwrite(saa, debNormal, IBM_MP2_MASK0, 0xc00c, 2);
1027 /* clear pending interrupts */
1028 debiread(saa, debNormal, IBM_MP2_HOST_INT, 2);
1029 debiwrite(saa, debNormal, XILINX_CTL0, 0x1711, 2);
1030
1031 return 0;
1032}
1033
1034/* load the decoder microcode */
1035static int initialize_ibmmpeg2(struct video_code *microcode)
1036{
1037 int i, num;
1038 struct saa7146 *saa;
1039
1040 for (num = 0; num < saa_num; num++) {
1041 saa = &saa7146s[num];
1042 /* check that FPGA is loaded */
1043 debiwrite(saa, debNormal, IBM_MP2_OSD_SIZE, 0xa55a, 2);
1044 i = debiread(saa, debNormal, IBM_MP2_OSD_SIZE, 2);
1045 if (i != 0xa55a) {
1046 printk(KERN_INFO "stradis%d: %04x != 0xa55a\n",
1047 saa->nr, i);
1048#if 0
1049 return -1;
1050#endif
1051 }
1052 if (!strncmp(microcode->loadwhat, "decoder.vid", 11)) {
1053 if (saa->boardcfg[0] > 27)
1054 continue; /* skip to next card */
1055 /* load video control store */
1056 saa->boardcfg[1] = 0x13; /* no-sync default */
1057 debiwrite(saa, debNormal, IBM_MP2_WR_PROT, 1, 2);
1058 debiwrite(saa, debNormal, IBM_MP2_PROC_IADDR, 0, 2);
1059 for (i = 0; i < microcode->datasize / 2; i++)
1060 debiwrite(saa, debNormal, IBM_MP2_PROC_IDATA,
1061 (microcode->data[i * 2] << 8) |
1062 microcode->data[i * 2 + 1], 2);
1063 debiwrite(saa, debNormal, IBM_MP2_PROC_IADDR, 0, 2);
1064 debiwrite(saa, debNormal, IBM_MP2_WR_PROT, 0, 2);
1065 debiwrite(saa, debNormal, IBM_MP2_CHIP_CONTROL,
1066 ChipControl, 2);
1067 saa->boardcfg[0] = 28;
1068 }
1069 if (!strncmp(microcode->loadwhat, "decoder.aud", 11)) {
1070 if (saa->boardcfg[0] > 35)
1071 continue; /* skip to next card */
1072 /* load audio control store */
1073 debiwrite(saa, debNormal, IBM_MP2_WR_PROT, 1, 2);
1074 debiwrite(saa, debNormal, IBM_MP2_AUD_IADDR, 0, 2);
1075 for (i = 0; i < microcode->datasize; i++)
1076 debiwrite(saa, debNormal, IBM_MP2_AUD_IDATA,
1077 microcode->data[i], 1);
1078 debiwrite(saa, debNormal, IBM_MP2_AUD_IADDR, 0, 2);
1079 debiwrite(saa, debNormal, IBM_MP2_WR_PROT, 0, 2);
1080 debiwrite(saa, debNormal, IBM_MP2_OSD_SIZE, 0x2000, 2);
1081 debiwrite(saa, debNormal, IBM_MP2_AUD_CTL, 0x4552, 2);
1082 if (ibm_send_command(saa, IBM_MP2_CONFIG_DECODER,
1083 0xe000, 1)) {
1084 printk(KERN_ERR "stradis%d: IBM config "
1085 "failed\n", saa->nr);
1086 return -1;
1087 }
1088 /* set PWM to center value */
1089 if (NewCard) {
1090 debiwrite(saa, debNormal, XILINX_PWM,
1091 saa->boardcfg[14] +
1092 (saa->boardcfg[13] << 8), 2);
1093 } else
1094 debiwrite(saa, debNormal, XILINX_PWM, 0x46, 2);
1095
1096 if (HaveCS3310) {
1097 i = CS3310MaxLvl;
1098 debiwrite(saa, debNormal, XILINX_CS3310_CMPLT,
1099 (i << 8) | i, 2);
1100 }
1101 printk(KERN_INFO "stradis%d: IBM MPEGCD%d Inited\n",
1102 saa->nr, 18 + (debiread(saa, debNormal,
1103 IBM_MP2_CHIP_CONTROL, 2) >> 12));
1104 /* start video decoder */
1105 debiwrite(saa, debNormal, IBM_MP2_CHIP_CONTROL,
1106 ChipControl, 2);
1107 debiwrite(saa, debNormal, IBM_MP2_RB_THRESHOLD, 0x4037,
1108 2); /* 256k vid, 3520 bytes aud */
1109 debiwrite(saa, debNormal, IBM_MP2_AUD_CTL, 0x4573, 2);
1110 ibm_send_command(saa, IBM_MP2_PLAY, 0, 0);
1111 /* enable buffer threshold irq */
1112 debiwrite(saa, debNormal, IBM_MP2_MASK0, 0xc00c, 2);
1113 debiread(saa, debNormal, IBM_MP2_HOST_INT, 2);
1114 /* enable gpio irq */
1115 saawrite(0x00002000, SAA7146_GPIO_CTRL);
1116 /* enable decoder output to HPS */
1117 debiwrite(saa, debNormal, XILINX_CTL0, 0x1711, 2);
1118 saa->boardcfg[0] = 37;
1119 }
1120 }
1121
1122 return 0;
1123}
1124
1125static u32 palette2fmt[] = { /* some of these YUV translations are wrong */
1126 0xffffffff, 0x86000000, 0x87000000, 0x80000000, 0x8100000, 0x82000000,
1127 0x83000000, 0x00000000, 0x03000000, 0x03000000, 0x0a00000, 0x03000000,
1128 0x06000000, 0x00000000, 0x03000000, 0x0a000000, 0x0300000
1129};
1130static int bpp2fmt[4] = {
1131 VIDEO_PALETTE_HI240, VIDEO_PALETTE_RGB565, VIDEO_PALETTE_RGB24,
1132 VIDEO_PALETTE_RGB32
1133};
1134
1135/* I wish I could find a formula to calculate these... */
1136static u32 h_prescale[64] = {
1137 0x10000000, 0x18040202, 0x18080000, 0x380c0606, 0x38100204, 0x38140808,
1138 0x38180000, 0x381c0000, 0x3820161c, 0x38242a3b, 0x38281230, 0x382c4460,
1139 0x38301040, 0x38340080, 0x38380000, 0x383c0000, 0x3840fefe, 0x3844ee9f,
1140 0x3848ee9f, 0x384cee9f, 0x3850ee9f, 0x38542a3b, 0x38581230, 0x385c0000,
1141 0x38600000, 0x38640000, 0x38680000, 0x386c0000, 0x38700000, 0x38740000,
1142 0x38780000, 0x387c0000, 0x30800000, 0x38840000, 0x38880000, 0x388c0000,
1143 0x38900000, 0x38940000, 0x38980000, 0x389c0000, 0x38a00000, 0x38a40000,
1144 0x38a80000, 0x38ac0000, 0x38b00000, 0x38b40000, 0x38b80000, 0x38bc0000,
1145 0x38c00000, 0x38c40000, 0x38c80000, 0x38cc0000, 0x38d00000, 0x38d40000,
1146 0x38d80000, 0x38dc0000, 0x38e00000, 0x38e40000, 0x38e80000, 0x38ec0000,
1147 0x38f00000, 0x38f40000, 0x38f80000, 0x38fc0000,
1148};
1149static u32 v_gain[64] = {
1150 0x016000ff, 0x016100ff, 0x016100ff, 0x016200ff, 0x016200ff, 0x016200ff,
1151 0x016200ff, 0x016300ff, 0x016300ff, 0x016300ff, 0x016300ff, 0x016300ff,
1152 0x016300ff, 0x016300ff, 0x016300ff, 0x016400ff, 0x016400ff, 0x016400ff,
1153 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff,
1154 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff,
1155 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff,
1156 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff,
1157 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff,
1158 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff,
1159 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff,
1160 0x016400ff, 0x016400ff, 0x016400ff, 0x016400ff,
1161};
1162
1163static void saa7146_set_winsize(struct saa7146 *saa)
1164{
1165 u32 format;
1166 int offset, yacl, ysci;
1167 saa->win.color_fmt = format =
1168 (saa->win.depth == 15) ? palette2fmt[VIDEO_PALETTE_RGB555] :
1169 palette2fmt[bpp2fmt[(saa->win.bpp - 1) & 3]];
1170 offset = saa->win.x * saa->win.bpp + saa->win.y * saa->win.bpl;
1171 saawrite(saa->win.vidadr + offset, SAA7146_BASE_EVEN1);
1172 saawrite(saa->win.vidadr + offset + saa->win.bpl, SAA7146_BASE_ODD1);
1173 saawrite(saa->win.bpl * 2, SAA7146_PITCH1);
1174 saawrite(saa->win.vidadr + saa->win.bpl * saa->win.sheight,
1175 SAA7146_PROT_ADDR1);
1176 saawrite(0, SAA7146_PAGE1);
1177 saawrite(format | 0x60, SAA7146_CLIP_FORMAT_CTRL);
1178 offset = (704 / (saa->win.width - 1)) & 0x3f;
1179 saawrite(h_prescale[offset], SAA7146_HPS_H_PRESCALE);
1180 offset = (720896 / saa->win.width) / (offset + 1);
1181 saawrite((offset << 12) | 0x0c, SAA7146_HPS_H_SCALE);
1182 if (CurrentMode == VIDEO_MODE_NTSC) {
1183 yacl = /*(480 / saa->win.height - 1) & 0x3f */ 0;
1184 ysci = 1024 - (saa->win.height * 1024 / 480);
1185 } else {
1186 yacl = /*(576 / saa->win.height - 1) & 0x3f */ 0;
1187 ysci = 1024 - (saa->win.height * 1024 / 576);
1188 }
1189 saawrite((1 << 31) | (ysci << 21) | (yacl << 15), SAA7146_HPS_V_SCALE);
1190 saawrite(v_gain[yacl], SAA7146_HPS_V_GAIN);
1191 saawrite(((SAA7146_MC2_UPLD_DMA1 | SAA7146_MC2_UPLD_HPS_V |
1192 SAA7146_MC2_UPLD_HPS_H) << 16) | (SAA7146_MC2_UPLD_DMA1 |
1193 SAA7146_MC2_UPLD_HPS_V | SAA7146_MC2_UPLD_HPS_H), SAA7146_MC2);
1194}
1195
1196/* clip_draw_rectangle(cm,x,y,w,h) -- handle clipping an area
1197 * bitmap is fixed width, 128 bytes (1024 pixels represented)
1198 * arranged most-sigificant-bit-left in 32-bit words
1199 * based on saa7146 clipping hardware, it swaps bytes if LE
1200 * much of this makes up for egcs brain damage -- so if you
1201 * are wondering "why did he do this?" it is because the C
1202 * was adjusted to generate the optimal asm output without
1203 * writing non-portable __asm__ directives.
1204 */
1205
1206static void clip_draw_rectangle(u32 *clipmap, int x, int y, int w, int h)
1207{
1208 register int startword, endword;
1209 register u32 bitsleft, bitsright;
1210 u32 *temp;
1211 if (x < 0) {
1212 w += x;
1213 x = 0;
1214 }
1215 if (y < 0) {
1216 h += y;
1217 y = 0;
1218 }
1219 if (w <= 0 || h <= 0 || x > 1023 || y > 639)
1220 return; /* throw away bad clips */
1221 if (x + w > 1024)
1222 w = 1024 - x;
1223 if (y + h > 640)
1224 h = 640 - y;
1225 startword = (x >> 5);
1226 endword = ((x + w) >> 5);
1227 bitsleft = (0xffffffff >> (x & 31));
1228 bitsright = (0xffffffff << (~((x + w) - (endword << 5))));
1229 temp = &clipmap[(y << 5) + startword];
1230 w = endword - startword;
1231 if (!w) {
1232 bitsleft |= bitsright;
1233 for (y = 0; y < h; y++) {
1234 *temp |= bitsleft;
1235 temp += 32;
1236 }
1237 } else {
1238 for (y = 0; y < h; y++) {
1239 *temp++ |= bitsleft;
1240 for (x = 1; x < w; x++)
1241 *temp++ = 0xffffffff;
1242 *temp |= bitsright;
1243 temp += (32 - w);
1244 }
1245 }
1246}
1247
1248static void make_clip_tab(struct saa7146 *saa, struct video_clip *cr, int ncr)
1249{
1250 int i, width, height;
1251 u32 *clipmap;
1252
1253 clipmap = saa->dmavid2;
1254 if ((width = saa->win.width) > 1023)
1255 width = 1023; /* sanity check */
1256 if ((height = saa->win.height) > 640)
1257 height = 639; /* sanity check */
1258 if (ncr > 0) { /* rectangles pased */
1259 /* convert rectangular clips to a bitmap */
1260 memset(clipmap, 0, VIDEO_CLIPMAP_SIZE); /* clear map */
1261 for (i = 0; i < ncr; i++)
1262 clip_draw_rectangle(clipmap, cr[i].x, cr[i].y,
1263 cr[i].width, cr[i].height);
1264 }
1265 /* clip against viewing window AND screen
1266 so we do not have to rely on the user program
1267 */
1268 clip_draw_rectangle(clipmap, (saa->win.x + width > saa->win.swidth) ?
1269 (saa->win.swidth - saa->win.x) : width, 0, 1024, 768);
1270 clip_draw_rectangle(clipmap, 0,
1271 (saa->win.y + height > saa->win.sheight) ?
1272 (saa->win.sheight - saa->win.y) : height, 1024, 768);
1273 if (saa->win.x < 0)
1274 clip_draw_rectangle(clipmap, 0, 0, -saa->win.x, 768);
1275 if (saa->win.y < 0)
1276 clip_draw_rectangle(clipmap, 0, 0, 1024, -saa->win.y);
1277}
1278
1279static long saa_ioctl(struct file *file,
1280 unsigned int cmd, unsigned long argl)
1281{
1282 struct saa7146 *saa = file->private_data;
1283 void __user *arg = (void __user *)argl;
1284
1285 switch (cmd) {
1286 case VIDIOCGCAP:
1287 {
1288 struct video_capability b;
1289 memset(&b, 0, sizeof(b));
1290 strcpy(b.name, saa->video_dev.name);
1291 b.type = VID_TYPE_CAPTURE | VID_TYPE_OVERLAY |
1292 VID_TYPE_CLIPPING | VID_TYPE_FRAMERAM |
1293 VID_TYPE_SCALES;
1294 b.channels = 1;
1295 b.audios = 1;
1296 b.maxwidth = 768;
1297 b.maxheight = 576;
1298 b.minwidth = 32;
1299 b.minheight = 32;
1300 if (copy_to_user(arg, &b, sizeof(b)))
1301 return -EFAULT;
1302 return 0;
1303 }
1304 case VIDIOCGPICT:
1305 {
1306 struct video_picture p = saa->picture;
1307 if (saa->win.depth == 8)
1308 p.palette = VIDEO_PALETTE_HI240;
1309 if (saa->win.depth == 15)
1310 p.palette = VIDEO_PALETTE_RGB555;
1311 if (saa->win.depth == 16)
1312 p.palette = VIDEO_PALETTE_RGB565;
1313 if (saa->win.depth == 24)
1314 p.palette = VIDEO_PALETTE_RGB24;
1315 if (saa->win.depth == 32)
1316 p.palette = VIDEO_PALETTE_RGB32;
1317 if (copy_to_user(arg, &p, sizeof(p)))
1318 return -EFAULT;
1319 return 0;
1320 }
1321 case VIDIOCSPICT:
1322 {
1323 struct video_picture p;
1324 u32 format;
1325 if (copy_from_user(&p, arg, sizeof(p)))
1326 return -EFAULT;
1327 if (p.palette < ARRAY_SIZE(palette2fmt)) {
1328 format = palette2fmt[p.palette];
1329 saa->win.color_fmt = format;
1330 saawrite(format | 0x60,
1331 SAA7146_CLIP_FORMAT_CTRL);
1332 }
1333 saawrite(((p.brightness & 0xff00) << 16) |
1334 ((p.contrast & 0xfe00) << 7) |
1335 ((p.colour & 0xfe00) >> 9), SAA7146_BCS_CTRL);
1336 saa->picture = p;
1337 /* upload changed registers */
1338 saawrite(((SAA7146_MC2_UPLD_HPS_H |
1339 SAA7146_MC2_UPLD_HPS_V) << 16) |
1340 SAA7146_MC2_UPLD_HPS_H |
1341 SAA7146_MC2_UPLD_HPS_V, SAA7146_MC2);
1342 return 0;
1343 }
1344 case VIDIOCSWIN:
1345 {
1346 struct video_window vw;
1347 struct video_clip *vcp = NULL;
1348
1349 if (copy_from_user(&vw, arg, sizeof(vw)))
1350 return -EFAULT;
1351
1352 /* stop capture */
1353 if (vw.flags || vw.width < 16 || vw.height < 16) {
1354 saawrite((SAA7146_MC1_TR_E_1 << 16),
1355 SAA7146_MC1);
1356 return -EINVAL;
1357 }
1358 /* 32-bit align start and adjust width */
1359 if (saa->win.bpp < 4) {
1360 int i = vw.x;
1361 vw.x = (vw.x + 3) & ~3;
1362 i = vw.x - i;
1363 vw.width -= i;
1364 }
1365 saa->win.x = vw.x;
1366 saa->win.y = vw.y;
1367 saa->win.width = vw.width;
1368 if (saa->win.width > 768)
1369 saa->win.width = 768;
1370 saa->win.height = vw.height;
1371 if (CurrentMode == VIDEO_MODE_NTSC) {
1372 if (saa->win.height > 480)
1373 saa->win.height = 480;
1374 } else {
1375 if (saa->win.height > 576)
1376 saa->win.height = 576;
1377 }
1378
1379 /* stop capture */
1380 saawrite((SAA7146_MC1_TR_E_1 << 16), SAA7146_MC1);
1381 saa7146_set_winsize(saa);
1382
1383 /*
1384 * Do any clips.
1385 */
1386 if (vw.clipcount < 0) {
1387 if (copy_from_user(saa->dmavid2, vw.clips,
1388 VIDEO_CLIPMAP_SIZE))
1389 return -EFAULT;
1390 } else if (vw.clipcount > 16384) {
1391 return -EINVAL;
1392 } else if (vw.clipcount > 0) {
1393 vcp = vmalloc(sizeof(struct video_clip) *
1394 vw.clipcount);
1395 if (vcp == NULL)
1396 return -ENOMEM;
1397 if (copy_from_user(vcp, vw.clips,
1398 sizeof(struct video_clip) *
1399 vw.clipcount)) {
1400 vfree(vcp);
1401 return -EFAULT;
1402 }
1403 } else /* nothing clipped */
1404 memset(saa->dmavid2, 0, VIDEO_CLIPMAP_SIZE);
1405
1406 make_clip_tab(saa, vcp, vw.clipcount);
1407 if (vw.clipcount > 0)
1408 vfree(vcp);
1409
1410 /* start capture & clip dma if we have an address */
1411 if ((saa->cap & 3) && saa->win.vidadr != 0)
1412 saawrite(((SAA7146_MC1_TR_E_1 |
1413 SAA7146_MC1_TR_E_2) << 16) | 0xffff,
1414 SAA7146_MC1);
1415 return 0;
1416 }
1417 case VIDIOCGWIN:
1418 {
1419 struct video_window vw;
1420 memset(&vw, 0, sizeof(vw));
1421 vw.x = saa->win.x;
1422 vw.y = saa->win.y;
1423 vw.width = saa->win.width;
1424 vw.height = saa->win.height;
1425 vw.chromakey = 0;
1426 vw.flags = 0;
1427 if (copy_to_user(arg, &vw, sizeof(vw)))
1428 return -EFAULT;
1429 return 0;
1430 }
1431 case VIDIOCCAPTURE:
1432 {
1433 int v;
1434 if (copy_from_user(&v, arg, sizeof(v)))
1435 return -EFAULT;
1436 if (v == 0) {
1437 saa->cap &= ~1;
1438 saawrite((SAA7146_MC1_TR_E_1 << 16),
1439 SAA7146_MC1);
1440 } else {
1441 if (saa->win.vidadr == 0 || saa->win.width == 0
1442 || saa->win.height == 0)
1443 return -EINVAL;
1444 saa->cap |= 1;
1445 saawrite((SAA7146_MC1_TR_E_1 << 16) | 0xffff,
1446 SAA7146_MC1);
1447 }
1448 return 0;
1449 }
1450 case VIDIOCGFBUF:
1451 {
1452 struct video_buffer v;
1453 memset(&v, 0, sizeof(v));
1454 v.base = (void *)saa->win.vidadr;
1455 v.height = saa->win.sheight;
1456 v.width = saa->win.swidth;
1457 v.depth = saa->win.depth;
1458 v.bytesperline = saa->win.bpl;
1459 if (copy_to_user(arg, &v, sizeof(v)))
1460 return -EFAULT;
1461 return 0;
1462
1463 }
1464 case VIDIOCSFBUF:
1465 {
1466 struct video_buffer v;
1467 if (!capable(CAP_SYS_ADMIN))
1468 return -EPERM;
1469 if (copy_from_user(&v, arg, sizeof(v)))
1470 return -EFAULT;
1471 if (v.depth != 8 && v.depth != 15 && v.depth != 16 &&
1472 v.depth != 24 && v.depth != 32 && v.width > 16 &&
1473 v.height > 16 && v.bytesperline > 16)
1474 return -EINVAL;
1475 if (v.base)
1476 saa->win.vidadr = (unsigned long)v.base;
1477 saa->win.sheight = v.height;
1478 saa->win.swidth = v.width;
1479 saa->win.bpp = ((v.depth + 7) & 0x38) / 8;
1480 saa->win.depth = v.depth;
1481 saa->win.bpl = v.bytesperline;
1482
1483 DEBUG(printk("Display at %p is %d by %d, bytedepth %d, "
1484 "bpl %d\n", v.base, v.width, v.height,
1485 saa->win.bpp, saa->win.bpl));
1486 saa7146_set_winsize(saa);
1487 return 0;
1488 }
1489 case VIDIOCKEY:
1490 {
1491 /* Will be handled higher up .. */
1492 return 0;
1493 }
1494
1495 case VIDIOCGAUDIO:
1496 {
1497 struct video_audio v;
1498 memset(&v, 0, sizeof(v));
1499 v = saa->audio_dev;
1500 v.flags &= ~(VIDEO_AUDIO_MUTE | VIDEO_AUDIO_MUTABLE);
1501 v.flags |= VIDEO_AUDIO_MUTABLE | VIDEO_AUDIO_VOLUME;
1502 strcpy(v.name, "MPEG");
1503 v.mode = VIDEO_SOUND_STEREO;
1504 if (copy_to_user(arg, &v, sizeof(v)))
1505 return -EFAULT;
1506 return 0;
1507 }
1508 case VIDIOCSAUDIO:
1509 {
1510 struct video_audio v;
1511 int i;
1512 if (copy_from_user(&v, arg, sizeof(v)))
1513 return -EFAULT;
1514 i = (~(v.volume >> 8)) & 0xff;
1515 if (!HaveCS4341) {
1516 if (v.flags & VIDEO_AUDIO_MUTE)
1517 debiwrite(saa, debNormal,
1518 IBM_MP2_FRNT_ATTEN, 0xffff, 2);
1519 if (!(v.flags & VIDEO_AUDIO_MUTE))
1520 debiwrite(saa, debNormal,
1521 IBM_MP2_FRNT_ATTEN, 0x0000, 2);
1522 if (v.flags & VIDEO_AUDIO_VOLUME)
1523 debiwrite(saa, debNormal,
1524 IBM_MP2_FRNT_ATTEN,
1525 (i << 8) | i, 2);
1526 } else {
1527 if (v.flags & VIDEO_AUDIO_MUTE)
1528 cs4341_setlevel(saa, 0xff, 0xff);
1529 if (!(v.flags & VIDEO_AUDIO_MUTE))
1530 cs4341_setlevel(saa, 0, 0);
1531 if (v.flags & VIDEO_AUDIO_VOLUME)
1532 cs4341_setlevel(saa, i, i);
1533 }
1534 saa->audio_dev = v;
1535 return 0;
1536 }
1537
1538 case VIDIOCGUNIT:
1539 {
1540 struct video_unit vu;
1541 memset(&vu, 0, sizeof(vu));
1542 vu.video = saa->video_dev.minor;
1543 vu.vbi = VIDEO_NO_UNIT;
1544 vu.radio = VIDEO_NO_UNIT;
1545 vu.audio = VIDEO_NO_UNIT;
1546 vu.teletext = VIDEO_NO_UNIT;
1547 if (copy_to_user(arg, &vu, sizeof(vu)))
1548 return -EFAULT;
1549 return 0;
1550 }
1551 case VIDIOCSPLAYMODE:
1552 {
1553 struct video_play_mode pmode;
1554 if (copy_from_user((void *)&pmode, arg,
1555 sizeof(struct video_play_mode)))
1556 return -EFAULT;
1557 switch (pmode.mode) {
1558 case VID_PLAY_VID_OUT_MODE:
1559 if (pmode.p1 != VIDEO_MODE_NTSC &&
1560 pmode.p1 != VIDEO_MODE_PAL)
1561 return -EINVAL;
1562 set_out_format(saa, pmode.p1);
1563 return 0;
1564 case VID_PLAY_GENLOCK:
1565 debiwrite(saa, debNormal, XILINX_CTL0,
1566 pmode.p1 ? 0x8000 : 0x8080, 2);
1567 if (NewCard)
1568 set_genlock_offset(saa, pmode.p2);
1569 return 0;
1570 case VID_PLAY_NORMAL:
1571 debiwrite(saa, debNormal,
1572 IBM_MP2_CHIP_CONTROL, ChipControl, 2);
1573 ibm_send_command(saa, IBM_MP2_PLAY, 0, 0);
1574 saa->playmode = pmode.mode;
1575 return 0;
1576 case VID_PLAY_PAUSE:
1577 /* IBM removed the PAUSE command */
1578 /* they say use SINGLE_FRAME now */
1579 case VID_PLAY_SINGLE_FRAME:
1580 ibm_send_command(saa, IBM_MP2_SINGLE_FRAME,0,0);
1581 if (saa->playmode == pmode.mode) {
1582 debiwrite(saa, debNormal,
1583 IBM_MP2_CHIP_CONTROL,
1584 ChipControl, 2);
1585 }
1586 saa->playmode = pmode.mode;
1587 return 0;
1588 case VID_PLAY_FAST_FORWARD:
1589 ibm_send_command(saa, IBM_MP2_FAST_FORWARD,0,0);
1590 saa->playmode = pmode.mode;
1591 return 0;
1592 case VID_PLAY_SLOW_MOTION:
1593 ibm_send_command(saa, IBM_MP2_SLOW_MOTION,
1594 pmode.p1, 0);
1595 saa->playmode = pmode.mode;
1596 return 0;
1597 case VID_PLAY_IMMEDIATE_NORMAL:
1598 /* ensure transfers resume */
1599 debiwrite(saa, debNormal,
1600 IBM_MP2_CHIP_CONTROL, ChipControl, 2);
1601 ibm_send_command(saa, IBM_MP2_IMED_NORM_PLAY,
1602 0, 0);
1603 saa->playmode = VID_PLAY_NORMAL;
1604 return 0;
1605 case VID_PLAY_SWITCH_CHANNELS:
1606 saa->audhead = saa->audtail = 0;
1607 saa->vidhead = saa->vidtail = 0;
1608 ibm_send_command(saa, IBM_MP2_FREEZE_FRAME,0,1);
1609 ibm_send_command(saa, IBM_MP2_RESET_AUD_RATE,
1610 0, 1);
1611 debiwrite(saa, debNormal, IBM_MP2_CHIP_CONTROL,
1612 0, 2);
1613 ibm_send_command(saa, IBM_MP2_CHANNEL_SWITCH,
1614 0, 1);
1615 debiwrite(saa, debNormal, IBM_MP2_CHIP_CONTROL,
1616 ChipControl, 2);
1617 ibm_send_command(saa, IBM_MP2_PLAY, 0, 0);
1618 saa->playmode = VID_PLAY_NORMAL;
1619 return 0;
1620 case VID_PLAY_FREEZE_FRAME:
1621 ibm_send_command(saa, IBM_MP2_FREEZE_FRAME,0,0);
1622 saa->playmode = pmode.mode;
1623 return 0;
1624 case VID_PLAY_STILL_MODE:
1625 ibm_send_command(saa, IBM_MP2_SET_STILL_MODE,
1626 0, 0);
1627 saa->playmode = pmode.mode;
1628 return 0;
1629 case VID_PLAY_MASTER_MODE:
1630 if (pmode.p1 == VID_PLAY_MASTER_NONE)
1631 saa->boardcfg[1] = 0x13;
1632 else if (pmode.p1 == VID_PLAY_MASTER_VIDEO)
1633 saa->boardcfg[1] = 0x23;
1634 else if (pmode.p1 == VID_PLAY_MASTER_AUDIO)
1635 saa->boardcfg[1] = 0x43;
1636 else
1637 return -EINVAL;
1638 debiwrite(saa, debNormal,
1639 IBM_MP2_CHIP_CONTROL, ChipControl, 2);
1640 return 0;
1641 case VID_PLAY_ACTIVE_SCANLINES:
1642 if (CurrentMode == VIDEO_MODE_PAL) {
1643 if (pmode.p1 < 1 || pmode.p2 > 625)
1644 return -EINVAL;
1645 saa->boardcfg[5] = pmode.p1;
1646 saa->boardcfg[55] = (pmode.p1 +
1647 (pmode.p2 / 2) - 1) & 0xff;
1648 } else {
1649 if (pmode.p1 < 4 || pmode.p2 > 525)
1650 return -EINVAL;
1651 saa->boardcfg[4] = pmode.p1;
1652 saa->boardcfg[54] = (pmode.p1 +
1653 (pmode.p2 / 2) - 4) & 0xff;
1654 }
1655 set_out_format(saa, CurrentMode);
1656 case VID_PLAY_RESET:
1657 return do_ibm_reset(saa);
1658 case VID_PLAY_END_MARK:
1659 if (saa->endmarktail < saa->endmarkhead) {
1660 if (saa->endmarkhead -
1661 saa->endmarktail < 2)
1662 return -ENOSPC;
1663 } else if (saa->endmarkhead <=saa->endmarktail){
1664 if (saa->endmarktail - saa->endmarkhead
1665 > (MAX_MARKS - 2))
1666 return -ENOSPC;
1667 } else
1668 return -ENOSPC;
1669 saa->endmark[saa->endmarktail] = saa->audtail;
1670 saa->endmarktail++;
1671 if (saa->endmarktail >= MAX_MARKS)
1672 saa->endmarktail = 0;
1673 }
1674 return -EINVAL;
1675 }
1676 case VIDIOCSWRITEMODE:
1677 {
1678 int mode;
1679 if (copy_from_user((void *)&mode, arg, sizeof(int)))
1680 return -EFAULT;
1681 if (mode == VID_WRITE_MPEG_AUD ||
1682 mode == VID_WRITE_MPEG_VID ||
1683 mode == VID_WRITE_CC ||
1684 mode == VID_WRITE_TTX ||
1685 mode == VID_WRITE_OSD) {
1686 saa->writemode = mode;
1687 return 0;
1688 }
1689 return -EINVAL;
1690 }
1691 case VIDIOCSMICROCODE:
1692 {
1693 struct video_code ucode;
1694 __u8 *udata;
1695 int i;
1696 if (copy_from_user(&ucode, arg, sizeof(ucode)))
1697 return -EFAULT;
1698 if (ucode.datasize > 65536 || ucode.datasize < 1024 ||
1699 strncmp(ucode.loadwhat, "dec", 3))
1700 return -EINVAL;
1701 if ((udata = vmalloc(ucode.datasize)) == NULL)
1702 return -ENOMEM;
1703 if (copy_from_user(udata, ucode.data, ucode.datasize)) {
1704 vfree(udata);
1705 return -EFAULT;
1706 }
1707 ucode.data = udata;
1708 if (!strncmp(ucode.loadwhat, "decoder.aud", 11) ||
1709 !strncmp(ucode.loadwhat, "decoder.vid", 11))
1710 i = initialize_ibmmpeg2(&ucode);
1711 else
1712 i = initialize_fpga(&ucode);
1713 vfree(udata);
1714 if (i)
1715 return -EINVAL;
1716 return 0;
1717
1718 }
1719 case VIDIOCGCHAN: /* this makes xawtv happy */
1720 {
1721 struct video_channel v;
1722 if (copy_from_user(&v, arg, sizeof(v)))
1723 return -EFAULT;
1724 v.flags = VIDEO_VC_AUDIO;
1725 v.tuners = 0;
1726 v.type = VID_TYPE_MPEG_DECODER;
1727 v.norm = CurrentMode;
1728 strcpy(v.name, "MPEG2");
1729 if (copy_to_user(arg, &v, sizeof(v)))
1730 return -EFAULT;
1731 return 0;
1732 }
1733 case VIDIOCSCHAN: /* this makes xawtv happy */
1734 {
1735 struct video_channel v;
1736 if (copy_from_user(&v, arg, sizeof(v)))
1737 return -EFAULT;
1738 /* do nothing */
1739 return 0;
1740 }
1741 default:
1742 return -ENOIOCTLCMD;
1743 }
1744 return 0;
1745}
1746
1747static int saa_mmap(struct file *file, struct vm_area_struct *vma)
1748{
1749 struct saa7146 *saa = file->private_data;
1750 printk(KERN_DEBUG "stradis%d: saa_mmap called\n", saa->nr);
1751 return -EINVAL;
1752}
1753
1754static ssize_t saa_read(struct file *file, char __user * buf,
1755 size_t count, loff_t * ppos)
1756{
1757 return -EINVAL;
1758}
1759
1760static ssize_t saa_write(struct file *file, const char __user * buf,
1761 size_t count, loff_t * ppos)
1762{
1763 struct saa7146 *saa = file->private_data;
1764 unsigned long todo = count;
1765 int blocksize, split;
1766 unsigned long flags;
1767
1768 while (todo > 0) {
1769 if (saa->writemode == VID_WRITE_MPEG_AUD) {
1770 spin_lock_irqsave(&saa->lock, flags);
1771 if (saa->audhead <= saa->audtail)
1772 blocksize = 65536 -
1773 (saa->audtail - saa->audhead);
1774 else
1775 blocksize = saa->audhead - saa->audtail;
1776 spin_unlock_irqrestore(&saa->lock, flags);
1777 if (blocksize < 16384) {
1778 saawrite(SAA7146_PSR_DEBI_S |
1779 SAA7146_PSR_PIN1, SAA7146_IER);
1780 saawrite(SAA7146_PSR_PIN1, SAA7146_PSR);
1781 /* wait for buffer space to open */
1782 interruptible_sleep_on(&saa->audq);
1783 }
1784 spin_lock_irqsave(&saa->lock, flags);
1785 if (saa->audhead <= saa->audtail) {
1786 blocksize = 65536 -
1787 (saa->audtail - saa->audhead);
1788 split = 65536 - saa->audtail;
1789 } else {
1790 blocksize = saa->audhead - saa->audtail;
1791 split = 65536;
1792 }
1793 spin_unlock_irqrestore(&saa->lock, flags);
1794 blocksize--;
1795 if (blocksize > todo)
1796 blocksize = todo;
1797 /* double check that we really have space */
1798 if (!blocksize)
1799 return -ENOSPC;
1800 if (split < blocksize) {
1801 if (copy_from_user(saa->audbuf +
1802 saa->audtail, buf, split))
1803 return -EFAULT;
1804 buf += split;
1805 todo -= split;
1806 blocksize -= split;
1807 saa->audtail = 0;
1808 }
1809 if (copy_from_user(saa->audbuf + saa->audtail, buf,
1810 blocksize))
1811 return -EFAULT;
1812 saa->audtail += blocksize;
1813 todo -= blocksize;
1814 buf += blocksize;
1815 saa->audtail &= 0xffff;
1816 } else if (saa->writemode == VID_WRITE_MPEG_VID) {
1817 spin_lock_irqsave(&saa->lock, flags);
1818 if (saa->vidhead <= saa->vidtail)
1819 blocksize = 524288 -
1820 (saa->vidtail - saa->vidhead);
1821 else
1822 blocksize = saa->vidhead - saa->vidtail;
1823 spin_unlock_irqrestore(&saa->lock, flags);
1824 if (blocksize < 65536) {
1825 saawrite(SAA7146_PSR_DEBI_S |
1826 SAA7146_PSR_PIN1, SAA7146_IER);
1827 saawrite(SAA7146_PSR_PIN1, SAA7146_PSR);
1828 /* wait for buffer space to open */
1829 interruptible_sleep_on(&saa->vidq);
1830 }
1831 spin_lock_irqsave(&saa->lock, flags);
1832 if (saa->vidhead <= saa->vidtail) {
1833 blocksize = 524288 -
1834 (saa->vidtail - saa->vidhead);
1835 split = 524288 - saa->vidtail;
1836 } else {
1837 blocksize = saa->vidhead - saa->vidtail;
1838 split = 524288;
1839 }
1840 spin_unlock_irqrestore(&saa->lock, flags);
1841 blocksize--;
1842 if (blocksize > todo)
1843 blocksize = todo;
1844 /* double check that we really have space */
1845 if (!blocksize)
1846 return -ENOSPC;
1847 if (split < blocksize) {
1848 if (copy_from_user(saa->vidbuf +
1849 saa->vidtail, buf, split))
1850 return -EFAULT;
1851 buf += split;
1852 todo -= split;
1853 blocksize -= split;
1854 saa->vidtail = 0;
1855 }
1856 if (copy_from_user(saa->vidbuf + saa->vidtail, buf,
1857 blocksize))
1858 return -EFAULT;
1859 saa->vidtail += blocksize;
1860 todo -= blocksize;
1861 buf += blocksize;
1862 saa->vidtail &= 0x7ffff;
1863 } else if (saa->writemode == VID_WRITE_OSD) {
1864 if (count > 131072)
1865 return -ENOSPC;
1866 if (copy_from_user(saa->osdbuf, buf, count))
1867 return -EFAULT;
1868 buf += count;
1869 saa->osdhead = 0;
1870 saa->osdtail = count;
1871 debiwrite(saa, debNormal, IBM_MP2_OSD_ADDR, 0, 2);
1872 debiwrite(saa, debNormal, IBM_MP2_OSD_LINK_ADDR, 0, 2);
1873 debiwrite(saa, debNormal, IBM_MP2_MASK0, 0xc00d, 2);
1874 debiwrite(saa, debNormal, IBM_MP2_DISP_MODE,
1875 debiread(saa, debNormal,
1876 IBM_MP2_DISP_MODE, 2) | 1, 2);
1877 /* trigger osd data transfer */
1878 saawrite(SAA7146_PSR_DEBI_S |
1879 SAA7146_PSR_PIN1, SAA7146_IER);
1880 saawrite(SAA7146_PSR_PIN1, SAA7146_PSR);
1881 }
1882 }
1883 return count;
1884}
1885
1886static int saa_open(struct file *file)
1887{
1888 struct video_device *vdev = video_devdata(file);
1889 struct saa7146 *saa = container_of(vdev, struct saa7146, video_dev);
1890
1891 lock_kernel();
1892 file->private_data = saa;
1893
1894 saa->user++;
1895 if (saa->user > 1) {
1896 saa->user--;
1897 unlock_kernel();
1898 return 0; /* device open already, don't reset */
1899 }
1900 saa->writemode = VID_WRITE_MPEG_VID; /* default to video */
1901 unlock_kernel();
1902 return 0;
1903}
1904
1905static int saa_release(struct file *file)
1906{
1907 struct saa7146 *saa = file->private_data;
1908 saa->user--;
1909
1910 if (saa->user > 0) /* still someone using device */
1911 return 0;
1912 saawrite(0x007f0000, SAA7146_MC1); /* stop all overlay dma */
1913 return 0;
1914}
1915
1916static const struct v4l2_file_operations saa_fops = {
1917 .owner = THIS_MODULE,
1918 .open = saa_open,
1919 .release = saa_release,
1920 .ioctl = saa_ioctl,
1921 .read = saa_read,
1922 .write = saa_write,
1923 .mmap = saa_mmap,
1924};
1925
1926/* template for video_device-structure */
1927static struct video_device saa_template = {
1928 .name = "SAA7146A",
1929 .fops = &saa_fops,
1930 .release = video_device_release_empty,
1931};
1932
1933static int __devinit configure_saa7146(struct pci_dev *pdev, int num)
1934{
1935 int retval;
1936 struct saa7146 *saa = pci_get_drvdata(pdev);
1937
1938 saa->endmarkhead = saa->endmarktail = 0;
1939 saa->win.x = saa->win.y = 0;
1940 saa->win.width = saa->win.cropwidth = 720;
1941 saa->win.height = saa->win.cropheight = 480;
1942 saa->win.cropx = saa->win.cropy = 0;
1943 saa->win.bpp = 2;
1944 saa->win.depth = 16;
1945 saa->win.color_fmt = palette2fmt[VIDEO_PALETTE_RGB565];
1946 saa->win.bpl = 1024 * saa->win.bpp;
1947 saa->win.swidth = 1024;
1948 saa->win.sheight = 768;
1949 saa->picture.brightness = 32768;
1950 saa->picture.contrast = 38768;
1951 saa->picture.colour = 32768;
1952 saa->cap = 0;
1953 saa->nr = num;
1954 saa->playmode = VID_PLAY_NORMAL;
1955 memset(saa->boardcfg, 0, 64); /* clear board config area */
1956 saa->saa7146_mem = NULL;
1957 saa->dmavid1 = saa->dmavid2 = saa->dmavid3 = saa->dmaa1in =
1958 saa->dmaa1out = saa->dmaa2in = saa->dmaa2out =
1959 saa->pagevid1 = saa->pagevid2 = saa->pagevid3 = saa->pagea1in =
1960 saa->pagea1out = saa->pagea2in = saa->pagea2out =
1961 saa->pagedebi = saa->dmaRPS1 = saa->dmaRPS2 = saa->pageRPS1 =
1962 saa->pageRPS2 = NULL;
1963 saa->audbuf = saa->vidbuf = saa->osdbuf = saa->dmadebi = NULL;
1964 saa->audhead = saa->vidtail = 0;
1965
1966 init_waitqueue_head(&saa->i2cq);
1967 init_waitqueue_head(&saa->audq);
1968 init_waitqueue_head(&saa->debiq);
1969 init_waitqueue_head(&saa->vidq);
1970 spin_lock_init(&saa->lock);
1971
1972 retval = pci_enable_device(pdev);
1973 if (retval) {
1974 dev_err(&pdev->dev, "%d: pci_enable_device failed!\n", num);
1975 goto err;
1976 }
1977
1978 saa->id = pdev->device;
1979 saa->irq = pdev->irq;
1980 saa->saa7146_adr = pci_resource_start(pdev, 0);
1981 pci_read_config_byte(pdev, PCI_CLASS_REVISION, &saa->revision);
1982
1983 saa->saa7146_mem = ioremap(saa->saa7146_adr, 0x200);
1984 if (saa->saa7146_mem == NULL) {
1985 dev_err(&pdev->dev, "%d: ioremap failed!\n", num);
1986 retval = -EIO;
1987 goto err;
1988 }
1989
1990 memcpy(&saa->video_dev, &saa_template, sizeof(saa_template));
1991 saawrite(0, SAA7146_IER); /* turn off all interrupts */
1992
1993 retval = request_irq(saa->irq, saa7146_irq, IRQF_SHARED | IRQF_DISABLED,
1994 "stradis", saa);
1995 if (retval == -EINVAL)
1996 dev_err(&pdev->dev, "%d: Bad irq number or handler\n", num);
1997 else if (retval == -EBUSY)
1998 dev_err(&pdev->dev, "%d: IRQ %ld busy, change your PnP config "
1999 "in BIOS\n", num, saa->irq);
2000 if (retval < 0)
2001 goto errio;
2002
2003 pci_set_master(pdev);
2004 retval = video_register_device(&saa->video_dev, VFL_TYPE_GRABBER,
2005 video_nr);
2006 if (retval < 0) {
2007 dev_err(&pdev->dev, "%d: error in registering video device!\n",
2008 num);
2009 goto errirq;
2010 }
2011
2012 return 0;
2013
2014errirq:
2015 free_irq(saa->irq, saa);
2016errio:
2017 iounmap(saa->saa7146_mem);
2018err:
2019 return retval;
2020}
2021
2022static int __devinit init_saa7146(struct pci_dev *pdev)
2023{
2024 struct saa7146 *saa = pci_get_drvdata(pdev);
2025
2026 saa->user = 0;
2027 /* reset the saa7146 */
2028 saawrite(0xffff0000, SAA7146_MC1);
2029 mdelay(5);
2030 /* enable debi and i2c transfers and pins */
2031 saawrite(((SAA7146_MC1_EDP | SAA7146_MC1_EI2C |
2032 SAA7146_MC1_TR_E_DEBI) << 16) | 0xffff, SAA7146_MC1);
2033 /* ensure proper state of chip */
2034 saawrite(0x00000000, SAA7146_PAGE1);
2035 saawrite(0x00f302c0, SAA7146_NUM_LINE_BYTE1);
2036 saawrite(0x00000000, SAA7146_PAGE2);
2037 saawrite(0x01400080, SAA7146_NUM_LINE_BYTE2);
2038 saawrite(0x00000000, SAA7146_DD1_INIT);
2039 saawrite(0x00000000, SAA7146_DD1_STREAM_B);
2040 saawrite(0x00000000, SAA7146_DD1_STREAM_A);
2041 saawrite(0x00000000, SAA7146_BRS_CTRL);
2042 saawrite(0x80400040, SAA7146_BCS_CTRL);
2043 saawrite(0x0000e000 /*| (1<<29) */ , SAA7146_HPS_CTRL);
2044 saawrite(0x00000060, SAA7146_CLIP_FORMAT_CTRL);
2045 saawrite(0x00000000, SAA7146_ACON1);
2046 saawrite(0x00000000, SAA7146_ACON2);
2047 saawrite(0x00000600, SAA7146_I2C_STATUS);
2048 saawrite(((SAA7146_MC2_UPLD_D1_B | SAA7146_MC2_UPLD_D1_A |
2049 SAA7146_MC2_UPLD_BRS | SAA7146_MC2_UPLD_HPS_H |
2050 SAA7146_MC2_UPLD_HPS_V | SAA7146_MC2_UPLD_DMA2 |
2051 SAA7146_MC2_UPLD_DMA1 | SAA7146_MC2_UPLD_I2C) << 16) | 0xffff,
2052 SAA7146_MC2);
2053 /* setup arbitration control registers */
2054 saawrite(0x1412121a, SAA7146_PCI_BT_V1);
2055
2056 /* allocate 32k dma buffer + 4k for page table */
2057 if ((saa->dmadebi = kmalloc(32768 + 4096, GFP_KERNEL)) == NULL) {
2058 dev_err(&pdev->dev, "%d: debi kmalloc failed\n", saa->nr);
2059 goto err;
2060 }
2061#if 0
2062 saa->pagedebi = saa->dmadebi + 32768; /* top 4k is for mmu */
2063 saawrite(virt_to_bus(saa->pagedebi) /*|0x800 */ , SAA7146_DEBI_PAGE);
2064 for (i = 0; i < 12; i++) /* setup mmu page table */
2065 saa->pagedebi[i] = virt_to_bus((saa->dmadebi + i * 4096));
2066#endif
2067 saa->audhead = saa->vidhead = saa->osdhead = 0;
2068 saa->audtail = saa->vidtail = saa->osdtail = 0;
2069 if (saa->vidbuf == NULL && (saa->vidbuf = vmalloc(524288)) == NULL) {
2070 dev_err(&pdev->dev, "%d: malloc failed\n", saa->nr);
2071 goto err;
2072 }
2073 if (saa->audbuf == NULL && (saa->audbuf = vmalloc(65536)) == NULL) {
2074 dev_err(&pdev->dev, "%d: malloc failed\n", saa->nr);
2075 goto errfree;
2076 }
2077 if (saa->osdbuf == NULL && (saa->osdbuf = vmalloc(131072)) == NULL) {
2078 dev_err(&pdev->dev, "%d: malloc failed\n", saa->nr);
2079 goto errfree;
2080 }
2081 /* allocate 81920 byte buffer for clipping */
2082 if ((saa->dmavid2 = kzalloc(VIDEO_CLIPMAP_SIZE, GFP_KERNEL)) == NULL) {
2083 dev_err(&pdev->dev, "%d: clip kmalloc failed\n", saa->nr);
2084 goto errfree;
2085 }
2086 /* setup clipping registers */
2087 saawrite(virt_to_bus(saa->dmavid2), SAA7146_BASE_EVEN2);
2088 saawrite(virt_to_bus(saa->dmavid2) + 128, SAA7146_BASE_ODD2);
2089 saawrite(virt_to_bus(saa->dmavid2) + VIDEO_CLIPMAP_SIZE,
2090 SAA7146_PROT_ADDR2);
2091 saawrite(256, SAA7146_PITCH2);
2092 saawrite(4, SAA7146_PAGE2); /* dma direction: read, no byteswap */
2093 saawrite(((SAA7146_MC2_UPLD_DMA2) << 16) | SAA7146_MC2_UPLD_DMA2,
2094 SAA7146_MC2);
2095 I2CBusScan(saa);
2096
2097 return 0;
2098errfree:
2099 vfree(saa->osdbuf);
2100 vfree(saa->audbuf);
2101 vfree(saa->vidbuf);
2102 saa->audbuf = saa->osdbuf = saa->vidbuf = NULL;
2103err:
2104 return -ENOMEM;
2105}
2106
2107static void stradis_release_saa(struct pci_dev *pdev)
2108{
2109 u8 command;
2110 struct saa7146 *saa = pci_get_drvdata(pdev);
2111
2112 /* turn off all capturing, DMA and IRQs */
2113 saawrite(0xffff0000, SAA7146_MC1); /* reset chip */
2114 saawrite(0, SAA7146_MC2);
2115 saawrite(0, SAA7146_IER);
2116 saawrite(0xffffffffUL, SAA7146_ISR);
2117
2118 /* disable PCI bus-mastering */
2119 pci_read_config_byte(pdev, PCI_COMMAND, &command);
2120 command &= ~PCI_COMMAND_MASTER;
2121 pci_write_config_byte(pdev, PCI_COMMAND, command);
2122
2123 /* unmap and free memory */
2124 saa->audhead = saa->audtail = saa->osdhead = 0;
2125 saa->vidhead = saa->vidtail = saa->osdtail = 0;
2126 vfree(saa->vidbuf);
2127 vfree(saa->audbuf);
2128 vfree(saa->osdbuf);
2129 kfree(saa->dmavid2);
2130 saa->audbuf = saa->vidbuf = saa->osdbuf = NULL;
2131 saa->dmavid2 = NULL;
2132 kfree(saa->dmadebi);
2133 kfree(saa->dmavid1);
2134 kfree(saa->dmavid3);
2135 kfree(saa->dmaa1in);
2136 kfree(saa->dmaa1out);
2137 kfree(saa->dmaa2in);
2138 kfree(saa->dmaa2out);
2139 kfree(saa->dmaRPS1);
2140 kfree(saa->dmaRPS2);
2141 free_irq(saa->irq, saa);
2142 if (saa->saa7146_mem)
2143 iounmap(saa->saa7146_mem);
2144 if (video_is_registered(&saa->video_dev))
2145 video_unregister_device(&saa->video_dev);
2146}
2147
2148static int __devinit stradis_probe(struct pci_dev *pdev,
2149 const struct pci_device_id *ent)
2150{
2151 int retval = -EINVAL;
2152
2153 if (saa_num >= SAA7146_MAX)
2154 goto err;
2155
2156 if (!pdev->subsystem_vendor)
2157 dev_info(&pdev->dev, "%d: rev1 decoder\n", saa_num);
2158 else
2159 dev_info(&pdev->dev, "%d: SDM2xx found\n", saa_num);
2160
2161 pci_set_drvdata(pdev, &saa7146s[saa_num]);
2162
2163 retval = configure_saa7146(pdev, saa_num);
2164 if (retval) {
2165 dev_err(&pdev->dev, "%d: error in configuring\n", saa_num);
2166 goto err;
2167 }
2168
2169 if (init_saa7146(pdev) < 0) {
2170 dev_err(&pdev->dev, "%d: error in initialization\n", saa_num);
2171 retval = -EIO;
2172 goto errrel;
2173 }
2174
2175 saa_num++;
2176
2177 return 0;
2178errrel:
2179 stradis_release_saa(pdev);
2180err:
2181 return retval;
2182}
2183
2184static void __devexit stradis_remove(struct pci_dev *pdev)
2185{
2186 stradis_release_saa(pdev);
2187}
2188
2189static struct pci_device_id stradis_pci_tbl[] = {
2190 { PCI_DEVICE(PCI_VENDOR_ID_PHILIPS, PCI_DEVICE_ID_PHILIPS_SAA7146) },
2191 { 0 }
2192};
2193
2194
2195static struct pci_driver stradis_driver = {
2196 .name = "stradis",
2197 .id_table = stradis_pci_tbl,
2198 .probe = stradis_probe,
2199 .remove = __devexit_p(stradis_remove)
2200};
2201
2202static int __init stradis_init(void)
2203{
2204 int retval;
2205
2206 saa_num = 0;
2207
2208 retval = pci_register_driver(&stradis_driver);
2209 if (retval)
2210 printk(KERN_ERR "stradis: Unable to register pci driver.\n");
2211
2212 return retval;
2213}
2214
2215static void __exit stradis_exit(void)
2216{
2217 pci_unregister_driver(&stradis_driver);
2218 printk(KERN_INFO "stradis: module cleanup complete\n");
2219}
2220
2221module_init(stradis_init);
2222module_exit(stradis_exit);
diff --git a/drivers/staging/tm6000/Kconfig b/drivers/staging/tm6000/Kconfig
index de7ebb99d8f6..114eec8a630a 100644
--- a/drivers/staging/tm6000/Kconfig
+++ b/drivers/staging/tm6000/Kconfig
@@ -1,6 +1,6 @@
1config VIDEO_TM6000 1config VIDEO_TM6000
2 tristate "TV Master TM5600/6000/6010 driver" 2 tristate "TV Master TM5600/6000/6010 driver"
3 depends on VIDEO_DEV && I2C && INPUT && IR_CORE && USB && EXPERIMENTAL 3 depends on VIDEO_DEV && I2C && INPUT && RC_CORE && USB && EXPERIMENTAL
4 select VIDEO_TUNER 4 select VIDEO_TUNER
5 select MEDIA_TUNER_XC2028 5 select MEDIA_TUNER_XC2028
6 select MEDIA_TUNER_XC5000 6 select MEDIA_TUNER_XC5000
diff --git a/drivers/staging/tm6000/TODO b/drivers/staging/tm6000/TODO
index 34780fc17b16..135d0ea3ad70 100644
--- a/drivers/staging/tm6000/TODO
+++ b/drivers/staging/tm6000/TODO
@@ -1,4 +1,6 @@
1There a few things to do before putting this driver in production: 1There a few things to do before putting this driver in production:
2 - IR NEC with tm5600/6000 TV cards
3 - IR RC5 with tm5600/6000/6010 TV cards
2 - CodingStyle; 4 - CodingStyle;
3 - Fix audio; 5 - Fix audio;
4 - Fix some panic/OOPS conditions. 6 - Fix some panic/OOPS conditions.
diff --git a/drivers/staging/tm6000/tm6000-cards.c b/drivers/staging/tm6000/tm6000-cards.c
index b143258f094a..455038bdfc9f 100644
--- a/drivers/staging/tm6000/tm6000-cards.c
+++ b/drivers/staging/tm6000/tm6000-cards.c
@@ -328,6 +328,47 @@ struct usb_device_id tm6000_id_table[] = {
328 { }, 328 { },
329}; 329};
330 330
331/* Control power led for show some activity */
332void tm6000_flash_led(struct tm6000_core *dev, u8 state)
333{
334 /* Power LED unconfigured */
335 if (!dev->gpio.power_led)
336 return;
337
338 /* ON Power LED */
339 if (state) {
340 switch (dev->model) {
341 case TM6010_BOARD_HAUPPAUGE_900H:
342 case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE:
343 case TM6010_BOARD_TWINHAN_TU501:
344 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
345 dev->gpio.power_led, 0x00);
346 break;
347 case TM6010_BOARD_BEHOLD_WANDER:
348 case TM6010_BOARD_BEHOLD_VOYAGER:
349 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
350 dev->gpio.power_led, 0x01);
351 break;
352 }
353 }
354 /* OFF Power LED */
355 else {
356 switch (dev->model) {
357 case TM6010_BOARD_HAUPPAUGE_900H:
358 case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE:
359 case TM6010_BOARD_TWINHAN_TU501:
360 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
361 dev->gpio.power_led, 0x01);
362 break;
363 case TM6010_BOARD_BEHOLD_WANDER:
364 case TM6010_BOARD_BEHOLD_VOYAGER:
365 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
366 dev->gpio.power_led, 0x00);
367 break;
368 }
369 }
370}
371
331/* Tuner callback to provide the proper gpio changes needed for xc5000 */ 372/* Tuner callback to provide the proper gpio changes needed for xc5000 */
332int tm6000_xc5000_callback(void *ptr, int component, int command, int arg) 373int tm6000_xc5000_callback(void *ptr, int component, int command, int arg)
333{ 374{
@@ -521,13 +562,6 @@ int tm6000_cards_setup(struct tm6000_core *dev)
521 printk(KERN_ERR "Error %i doing tuner reset\n", rc); 562 printk(KERN_ERR "Error %i doing tuner reset\n", rc);
522 return rc; 563 return rc;
523 } 564 }
524 msleep(10);
525
526 if (!i) {
527 rc = tm6000_get_reg32(dev, REQ_40_GET_VERSION, 0, 0);
528 if (rc >= 0)
529 printk(KERN_DEBUG "board=0x%08x\n", rc);
530 }
531 } 565 }
532 } else { 566 } else {
533 printk(KERN_ERR "Tuner reset is not configured\n"); 567 printk(KERN_ERR "Tuner reset is not configured\n");
diff --git a/drivers/staging/tm6000/tm6000-core.c b/drivers/staging/tm6000/tm6000-core.c
index 40a0206e2432..96aed4ace467 100644
--- a/drivers/staging/tm6000/tm6000-core.c
+++ b/drivers/staging/tm6000/tm6000-core.c
@@ -542,6 +542,26 @@ int tm6000_init(struct tm6000_core *dev)
542 int board, rc = 0, i, size; 542 int board, rc = 0, i, size;
543 struct reg_init *tab; 543 struct reg_init *tab;
544 544
545 /* Check board revision */
546 board = tm6000_get_reg32(dev, REQ_40_GET_VERSION, 0, 0);
547 if (board >= 0) {
548 switch (board & 0xff) {
549 case 0xf3:
550 printk(KERN_INFO "Found tm6000\n");
551 if (dev->dev_type != TM6000)
552 dev->dev_type = TM6000;
553 break;
554 case 0xf4:
555 printk(KERN_INFO "Found tm6010\n");
556 if (dev->dev_type != TM6010)
557 dev->dev_type = TM6010;
558 break;
559 default:
560 printk(KERN_INFO "Unknown board version = 0x%08x\n", board);
561 }
562 } else
563 printk(KERN_ERR "Error %i while retrieving board version\n", board);
564
545 if (dev->dev_type == TM6010) { 565 if (dev->dev_type == TM6010) {
546 tab = tm6010_init_tab; 566 tab = tm6010_init_tab;
547 size = ARRAY_SIZE(tm6010_init_tab); 567 size = ARRAY_SIZE(tm6010_init_tab);
@@ -563,13 +583,6 @@ int tm6000_init(struct tm6000_core *dev)
563 583
564 msleep(5); /* Just to be conservative */ 584 msleep(5); /* Just to be conservative */
565 585
566 /* Check board version - maybe 10Moons specific */
567 board = tm6000_get_reg32(dev, REQ_40_GET_VERSION, 0, 0);
568 if (board >= 0)
569 printk(KERN_INFO "Board version = 0x%08x\n", board);
570 else
571 printk(KERN_ERR "Error %i while retrieving board version\n", board);
572
573 rc = tm6000_cards_setup(dev); 586 rc = tm6000_cards_setup(dev);
574 587
575 return rc; 588 return rc;
@@ -709,5 +722,5 @@ void tm6000_close_extension(struct tm6000_core *dev)
709 ops->fini(dev); 722 ops->fini(dev);
710 } 723 }
711 } 724 }
712 mutex_lock(&tm6000_devlist_mutex); 725 mutex_unlock(&tm6000_devlist_mutex);
713} 726}
diff --git a/drivers/staging/tm6000/tm6000-i2c.c b/drivers/staging/tm6000/tm6000-i2c.c
index 93f625fc852b..18de4748f27e 100644
--- a/drivers/staging/tm6000/tm6000-i2c.c
+++ b/drivers/staging/tm6000/tm6000-i2c.c
@@ -301,33 +301,11 @@ static u32 functionality(struct i2c_adapter *adap)
301 return I2C_FUNC_SMBUS_EMUL; 301 return I2C_FUNC_SMBUS_EMUL;
302} 302}
303 303
304#define mass_write(addr, reg, data...) \ 304static const struct i2c_algorithm tm6000_algo = {
305 { static const u8 _val[] = data; \
306 rc = tm6000_read_write_usb(dev, USB_DIR_OUT | USB_TYPE_VENDOR, \
307 REQ_16_SET_GET_I2C_WR1_RDN, (reg<<8)+addr, 0x00, (u8 *) _val, \
308 ARRAY_SIZE(_val)); \
309 if (rc < 0) { \
310 printk(KERN_ERR "Error on line %d: %d\n", __LINE__, rc); \
311 return rc; \
312 } \
313 msleep(10); \
314 }
315
316static struct i2c_algorithm tm6000_algo = {
317 .master_xfer = tm6000_i2c_xfer, 305 .master_xfer = tm6000_i2c_xfer,
318 .functionality = functionality, 306 .functionality = functionality,
319}; 307};
320 308
321static struct i2c_adapter tm6000_adap_template = {
322 .owner = THIS_MODULE,
323 .name = "tm6000",
324 .algo = &tm6000_algo,
325};
326
327static struct i2c_client tm6000_client_template = {
328 .name = "tm6000 internal",
329};
330
331/* ----------------------------------------------------------- */ 309/* ----------------------------------------------------------- */
332 310
333/* 311/*
@@ -337,17 +315,20 @@ static struct i2c_client tm6000_client_template = {
337int tm6000_i2c_register(struct tm6000_core *dev) 315int tm6000_i2c_register(struct tm6000_core *dev)
338{ 316{
339 unsigned char eedata[256]; 317 unsigned char eedata[256];
318 int rc;
340 319
341 dev->i2c_adap = tm6000_adap_template; 320 dev->i2c_adap.owner = THIS_MODULE;
321 dev->i2c_adap.algo = &tm6000_algo;
342 dev->i2c_adap.dev.parent = &dev->udev->dev; 322 dev->i2c_adap.dev.parent = &dev->udev->dev;
343 strcpy(dev->i2c_adap.name, dev->name); 323 strlcpy(dev->i2c_adap.name, dev->name, sizeof(dev->i2c_adap.name));
344 dev->i2c_adap.algo_data = dev; 324 dev->i2c_adap.algo_data = dev;
345 i2c_add_adapter(&dev->i2c_adap); 325 i2c_set_adapdata(&dev->i2c_adap, &dev->v4l2_dev);
326 rc = i2c_add_adapter(&dev->i2c_adap);
327 if (rc)
328 return rc;
346 329
347 dev->i2c_client = tm6000_client_template;
348 dev->i2c_client.adapter = &dev->i2c_adap; 330 dev->i2c_client.adapter = &dev->i2c_adap;
349 331 strlcpy(dev->i2c_client.name, "tm6000 internal", I2C_NAME_SIZE);
350 i2c_set_adapdata(&dev->i2c_adap, &dev->v4l2_dev);
351 332
352 tm6000_i2c_eeprom(dev, eedata, sizeof(eedata)); 333 tm6000_i2c_eeprom(dev, eedata, sizeof(eedata));
353 334
diff --git a/drivers/staging/tm6000/tm6000-input.c b/drivers/staging/tm6000/tm6000-input.c
index 6022caaa739b..21e7da40f049 100644
--- a/drivers/staging/tm6000/tm6000-input.c
+++ b/drivers/staging/tm6000/tm6000-input.c
@@ -24,8 +24,7 @@
24#include <linux/input.h> 24#include <linux/input.h>
25#include <linux/usb.h> 25#include <linux/usb.h>
26 26
27#include <media/ir-core.h> 27#include <media/rc-core.h>
28#include <media/ir-common.h>
29 28
30#include "tm6000.h" 29#include "tm6000.h"
31#include "tm6000-regs.h" 30#include "tm6000-regs.h"
@@ -38,6 +37,10 @@ static unsigned int enable_ir = 1;
38module_param(enable_ir, int, 0644); 37module_param(enable_ir, int, 0644);
39MODULE_PARM_DESC(enable_ir, "enable ir (default is enable)"); 38MODULE_PARM_DESC(enable_ir, "enable ir (default is enable)");
40 39
40/* number of 50ms for ON-OFF-ON power led */
41/* show IR activity */
42#define PWLED_OFF 2
43
41#undef dprintk 44#undef dprintk
42 45
43#define dprintk(fmt, arg...) \ 46#define dprintk(fmt, arg...) \
@@ -51,8 +54,7 @@ struct tm6000_ir_poll_result {
51 54
52struct tm6000_IR { 55struct tm6000_IR {
53 struct tm6000_core *dev; 56 struct tm6000_core *dev;
54 struct ir_input_dev *input; 57 struct rc_dev *rc;
55 struct ir_input_state ir;
56 char name[32]; 58 char name[32];
57 char phys[32]; 59 char phys[32];
58 60
@@ -61,13 +63,16 @@ struct tm6000_IR {
61 struct delayed_work work; 63 struct delayed_work work;
62 u8 wait:1; 64 u8 wait:1;
63 u8 key:1; 65 u8 key:1;
66 u8 pwled:1;
67 u8 pwledcnt;
68 u16 key_addr;
64 struct urb *int_urb; 69 struct urb *int_urb;
65 u8 *urb_data; 70 u8 *urb_data;
66 71
67 int (*get_key) (struct tm6000_IR *, struct tm6000_ir_poll_result *); 72 int (*get_key) (struct tm6000_IR *, struct tm6000_ir_poll_result *);
68 73
69 /* IR device properties */ 74 /* IR device properties */
70 struct ir_dev_props props; 75 u64 rc_type;
71}; 76};
72 77
73 78
@@ -91,26 +96,49 @@ static int tm6000_ir_config(struct tm6000_IR *ir)
91 u8 buf[10]; 96 u8 buf[10];
92 int rc; 97 int rc;
93 98
94 /* hack */ 99 switch (ir->rc_type) {
95 buf[0] = 0xff; 100 case RC_TYPE_NEC:
96 buf[1] = 0xff; 101 /* Setup IR decoder for NEC standard 12MHz system clock */
97 buf[2] = 0xf2; 102 /* IR_LEADER_CNT = 0.9ms */
98 buf[3] = 0x2b; 103 tm6000_set_reg(dev, TM6010_REQ07_RD8_IR_LEADER1, 0xaa);
99 buf[4] = 0x20; 104 tm6000_set_reg(dev, TM6010_REQ07_RD8_IR_LEADER0, 0x30);
100 buf[5] = 0x35; 105 /* IR_PULSE_CNT = 0.7ms */
101 buf[6] = 0x60; 106 tm6000_set_reg(dev, TM6010_REQ07_RD8_IR_PULSE_CNT1, 0x20);
102 buf[7] = 0x04; 107 tm6000_set_reg(dev, TM6010_REQ07_RD8_IR_PULSE_CNT0, 0xd0);
103 buf[8] = 0xc0; 108 /* Remote WAKEUP = enable */
104 buf[9] = 0x08; 109 tm6000_set_reg(dev, TM6010_REQ07_RE5_REMOTE_WAKEUP, 0xfe);
105 110 /* IR_WKUP_SEL = Low byte in decoded IR data */
106 rc = tm6000_read_write_usb(dev, USB_DIR_OUT | USB_TYPE_VENDOR | 111 tm6000_set_reg(dev, TM6010_REQ07_RD8_IR_WAKEUP_SEL, 0xff);
107 USB_RECIP_DEVICE, REQ_00_SET_IR_VALUE, 0, 0, buf, 0x0a); 112 /* IR_WKU_ADD code */
108 msleep(100); 113 tm6000_set_reg(dev, TM6010_REQ07_RD8_IR_WAKEUP_ADD, 0xff);
109 114 tm6000_flash_led(dev, 0);
110 if (rc < 0) { 115 msleep(100);
111 printk(KERN_INFO "IR configuration failed"); 116 tm6000_flash_led(dev, 1);
112 return rc; 117 break;
118 default:
119 /* hack */
120 buf[0] = 0xff;
121 buf[1] = 0xff;
122 buf[2] = 0xf2;
123 buf[3] = 0x2b;
124 buf[4] = 0x20;
125 buf[5] = 0x35;
126 buf[6] = 0x60;
127 buf[7] = 0x04;
128 buf[8] = 0xc0;
129 buf[9] = 0x08;
130
131 rc = tm6000_read_write_usb(dev, USB_DIR_OUT | USB_TYPE_VENDOR |
132 USB_RECIP_DEVICE, REQ_00_SET_IR_VALUE, 0, 0, buf, 0x0a);
133 msleep(100);
134
135 if (rc < 0) {
136 printk(KERN_INFO "IR configuration failed");
137 return rc;
138 }
139 break;
113 } 140 }
141
114 return 0; 142 return 0;
115} 143}
116 144
@@ -145,17 +173,28 @@ static int default_polling_getkey(struct tm6000_IR *ir,
145 return 0; 173 return 0;
146 174
147 if (&dev->int_in) { 175 if (&dev->int_in) {
148 if (ir->ir.ir_type == IR_TYPE_RC5) 176 switch (ir->rc_type) {
177 case RC_TYPE_RC5:
149 poll_result->rc_data = ir->urb_data[0]; 178 poll_result->rc_data = ir->urb_data[0];
150 else 179 break;
151 poll_result->rc_data = ir->urb_data[0] | ir->urb_data[1] << 8; 180 case RC_TYPE_NEC:
181 if (ir->urb_data[1] == ((ir->key_addr >> 8) & 0xff)) {
182 poll_result->rc_data = ir->urb_data[0]
183 | ir->urb_data[1] << 8;
184 }
185 break;
186 default:
187 poll_result->rc_data = ir->urb_data[0]
188 | ir->urb_data[1] << 8;
189 break;
190 }
152 } else { 191 } else {
153 tm6000_set_reg(dev, REQ_04_EN_DISABLE_MCU_INT, 2, 0); 192 tm6000_set_reg(dev, REQ_04_EN_DISABLE_MCU_INT, 2, 0);
154 msleep(10); 193 msleep(10);
155 tm6000_set_reg(dev, REQ_04_EN_DISABLE_MCU_INT, 2, 1); 194 tm6000_set_reg(dev, REQ_04_EN_DISABLE_MCU_INT, 2, 1);
156 msleep(10); 195 msleep(10);
157 196
158 if (ir->ir.ir_type == IR_TYPE_RC5) { 197 if (ir->rc_type == RC_TYPE_RC5) {
159 rc = tm6000_read_write_usb(dev, USB_DIR_IN | 198 rc = tm6000_read_write_usb(dev, USB_DIR_IN |
160 USB_TYPE_VENDOR | USB_RECIP_DEVICE, 199 USB_TYPE_VENDOR | USB_RECIP_DEVICE,
161 REQ_02_GET_IR_CODE, 0, 0, buf, 1); 200 REQ_02_GET_IR_CODE, 0, 0, buf, 1);
@@ -188,6 +227,7 @@ static int default_polling_getkey(struct tm6000_IR *ir,
188 227
189static void tm6000_ir_handle_key(struct tm6000_IR *ir) 228static void tm6000_ir_handle_key(struct tm6000_IR *ir)
190{ 229{
230 struct tm6000_core *dev = ir->dev;
191 int result; 231 int result;
192 struct tm6000_ir_poll_result poll_result; 232 struct tm6000_ir_poll_result poll_result;
193 233
@@ -200,12 +240,21 @@ static void tm6000_ir_handle_key(struct tm6000_IR *ir)
200 240
201 dprintk("ir->get_key result data=%04x\n", poll_result.rc_data); 241 dprintk("ir->get_key result data=%04x\n", poll_result.rc_data);
202 242
203 if (ir->key) { 243 if (ir->pwled) {
204 ir_input_keydown(ir->input->input_dev, &ir->ir, 244 if (ir->pwledcnt >= PWLED_OFF) {
205 (u32)poll_result.rc_data); 245 ir->pwled = 0;
246 ir->pwledcnt = 0;
247 tm6000_flash_led(dev, 1);
248 } else
249 ir->pwledcnt += 1;
250 }
206 251
207 ir_input_nokey(ir->input->input_dev, &ir->ir); 252 if (ir->key) {
253 rc_keydown(ir->rc, poll_result.rc_data, 0);
208 ir->key = 0; 254 ir->key = 0;
255 ir->pwled = 1;
256 ir->pwledcnt = 0;
257 tm6000_flash_led(dev, 0);
209 } 258 }
210 return; 259 return;
211} 260}
@@ -218,9 +267,9 @@ static void tm6000_ir_work(struct work_struct *work)
218 schedule_delayed_work(&ir->work, msecs_to_jiffies(ir->polling)); 267 schedule_delayed_work(&ir->work, msecs_to_jiffies(ir->polling));
219} 268}
220 269
221static int tm6000_ir_start(void *priv) 270static int tm6000_ir_start(struct rc_dev *rc)
222{ 271{
223 struct tm6000_IR *ir = priv; 272 struct tm6000_IR *ir = rc->priv;
224 273
225 INIT_DELAYED_WORK(&ir->work, tm6000_ir_work); 274 INIT_DELAYED_WORK(&ir->work, tm6000_ir_work);
226 schedule_delayed_work(&ir->work, 0); 275 schedule_delayed_work(&ir->work, 0);
@@ -228,30 +277,91 @@ static int tm6000_ir_start(void *priv)
228 return 0; 277 return 0;
229} 278}
230 279
231static void tm6000_ir_stop(void *priv) 280static void tm6000_ir_stop(struct rc_dev *rc)
232{ 281{
233 struct tm6000_IR *ir = priv; 282 struct tm6000_IR *ir = rc->priv;
234 283
235 cancel_delayed_work_sync(&ir->work); 284 cancel_delayed_work_sync(&ir->work);
236} 285}
237 286
238int tm6000_ir_change_protocol(void *priv, u64 ir_type) 287int tm6000_ir_change_protocol(struct rc_dev *rc, u64 rc_type)
239{ 288{
240 struct tm6000_IR *ir = priv; 289 struct tm6000_IR *ir = rc->priv;
290
291 if (!ir)
292 return 0;
293
294 if ((rc->rc_map.scan) && (rc_type == RC_TYPE_NEC))
295 ir->key_addr = ((rc->rc_map.scan[0].scancode >> 8) & 0xffff);
241 296
242 ir->get_key = default_polling_getkey; 297 ir->get_key = default_polling_getkey;
298 ir->rc_type = rc_type;
243 299
244 tm6000_ir_config(ir); 300 tm6000_ir_config(ir);
245 /* TODO */ 301 /* TODO */
246 return 0; 302 return 0;
247} 303}
248 304
305int tm6000_ir_int_start(struct tm6000_core *dev)
306{
307 struct tm6000_IR *ir = dev->ir;
308 int pipe, size;
309 int err = -ENOMEM;
310
311
312 if (!ir)
313 return -ENODEV;
314
315 ir->int_urb = usb_alloc_urb(0, GFP_KERNEL);
316
317 pipe = usb_rcvintpipe(dev->udev,
318 dev->int_in.endp->desc.bEndpointAddress
319 & USB_ENDPOINT_NUMBER_MASK);
320
321 size = usb_maxpacket(dev->udev, pipe, usb_pipeout(pipe));
322 dprintk("IR max size: %d\n", size);
323
324 ir->int_urb->transfer_buffer = kzalloc(size, GFP_KERNEL);
325 if (ir->int_urb->transfer_buffer == NULL) {
326 usb_free_urb(ir->int_urb);
327 return err;
328 }
329 dprintk("int interval: %d\n", dev->int_in.endp->desc.bInterval);
330 usb_fill_int_urb(ir->int_urb, dev->udev, pipe,
331 ir->int_urb->transfer_buffer, size,
332 tm6000_ir_urb_received, dev,
333 dev->int_in.endp->desc.bInterval);
334 err = usb_submit_urb(ir->int_urb, GFP_KERNEL);
335 if (err) {
336 kfree(ir->int_urb->transfer_buffer);
337 usb_free_urb(ir->int_urb);
338 return err;
339 }
340 ir->urb_data = kzalloc(size, GFP_KERNEL);
341
342 return 0;
343}
344
345void tm6000_ir_int_stop(struct tm6000_core *dev)
346{
347 struct tm6000_IR *ir = dev->ir;
348
349 if (!ir)
350 return;
351
352 usb_kill_urb(ir->int_urb);
353 kfree(ir->int_urb->transfer_buffer);
354 usb_free_urb(ir->int_urb);
355 ir->int_urb = NULL;
356 kfree(ir->urb_data);
357 ir->urb_data = NULL;
358}
359
249int tm6000_ir_init(struct tm6000_core *dev) 360int tm6000_ir_init(struct tm6000_core *dev)
250{ 361{
251 struct tm6000_IR *ir; 362 struct tm6000_IR *ir;
252 struct ir_input_dev *ir_input_dev; 363 struct rc_dev *rc;
253 int err = -ENOMEM; 364 int err = -ENOMEM;
254 int pipe, size, rc;
255 365
256 if (!enable_ir) 366 if (!enable_ir)
257 return -ENODEV; 367 return -ENODEV;
@@ -263,26 +373,27 @@ int tm6000_ir_init(struct tm6000_core *dev)
263 return 0; 373 return 0;
264 374
265 ir = kzalloc(sizeof(*ir), GFP_KERNEL); 375 ir = kzalloc(sizeof(*ir), GFP_KERNEL);
266 ir_input_dev = kzalloc(sizeof(*ir_input_dev), GFP_KERNEL); 376 rc = rc_allocate_device();
267 ir_input_dev->input_dev = input_allocate_device(); 377 if (!ir | !rc)
268 if (!ir || !ir_input_dev || !ir_input_dev->input_dev) 378 goto out;
269 goto err_out_free;
270 379
271 /* record handles to ourself */ 380 /* record handles to ourself */
272 ir->dev = dev; 381 ir->dev = dev;
273 dev->ir = ir; 382 dev->ir = ir;
274 383 ir->rc = rc;
275 ir->input = ir_input_dev;
276 384
277 /* input einrichten */ 385 /* input einrichten */
278 ir->props.allowed_protos = IR_TYPE_RC5 | IR_TYPE_NEC; 386 rc->allowed_protos = RC_TYPE_RC5 | RC_TYPE_NEC;
279 ir->props.priv = ir; 387 rc->priv = ir;
280 ir->props.change_protocol = tm6000_ir_change_protocol; 388 rc->change_protocol = tm6000_ir_change_protocol;
281 ir->props.open = tm6000_ir_start; 389 rc->open = tm6000_ir_start;
282 ir->props.close = tm6000_ir_stop; 390 rc->close = tm6000_ir_stop;
283 ir->props.driver_type = RC_DRIVER_SCANCODE; 391 rc->driver_type = RC_DRIVER_SCANCODE;
284 392
285 ir->polling = 50; 393 ir->polling = 50;
394 ir->pwled = 0;
395 ir->pwledcnt = 0;
396
286 397
287 snprintf(ir->name, sizeof(ir->name), "tm5600/60x0 IR (%s)", 398 snprintf(ir->name, sizeof(ir->name), "tm5600/60x0 IR (%s)",
288 dev->name); 399 dev->name);
@@ -290,64 +401,37 @@ int tm6000_ir_init(struct tm6000_core *dev)
290 usb_make_path(dev->udev, ir->phys, sizeof(ir->phys)); 401 usb_make_path(dev->udev, ir->phys, sizeof(ir->phys));
291 strlcat(ir->phys, "/input0", sizeof(ir->phys)); 402 strlcat(ir->phys, "/input0", sizeof(ir->phys));
292 403
293 tm6000_ir_change_protocol(ir, IR_TYPE_UNKNOWN); 404 tm6000_ir_change_protocol(rc, RC_TYPE_UNKNOWN);
294 err = ir_input_init(ir_input_dev->input_dev, &ir->ir, IR_TYPE_OTHER);
295 if (err < 0)
296 goto err_out_free;
297
298 ir_input_dev->input_dev->name = ir->name;
299 ir_input_dev->input_dev->phys = ir->phys;
300 ir_input_dev->input_dev->id.bustype = BUS_USB;
301 ir_input_dev->input_dev->id.version = 1;
302 ir_input_dev->input_dev->id.vendor = le16_to_cpu(dev->udev->descriptor.idVendor);
303 ir_input_dev->input_dev->id.product = le16_to_cpu(dev->udev->descriptor.idProduct);
304 405
305 ir_input_dev->input_dev->dev.parent = &dev->udev->dev; 406 rc->input_name = ir->name;
407 rc->input_phys = ir->phys;
408 rc->input_id.bustype = BUS_USB;
409 rc->input_id.version = 1;
410 rc->input_id.vendor = le16_to_cpu(dev->udev->descriptor.idVendor);
411 rc->input_id.product = le16_to_cpu(dev->udev->descriptor.idProduct);
412 rc->map_name = dev->ir_codes;
413 rc->driver_name = "tm6000";
414 rc->dev.parent = &dev->udev->dev;
306 415
307 if (&dev->int_in) { 416 if (&dev->int_in) {
308 dprintk("IR over int\n"); 417 dprintk("IR over int\n");
309 418
310 ir->int_urb = usb_alloc_urb(0, GFP_KERNEL); 419 err = tm6000_ir_int_start(dev);
311 420
312 pipe = usb_rcvintpipe(dev->udev, 421 if (err)
313 dev->int_in.endp->desc.bEndpointAddress 422 goto out;
314 & USB_ENDPOINT_NUMBER_MASK);
315
316 size = usb_maxpacket(dev->udev, pipe, usb_pipeout(pipe));
317 dprintk("IR max size: %d\n", size);
318
319 ir->int_urb->transfer_buffer = kzalloc(size, GFP_KERNEL);
320 if (ir->int_urb->transfer_buffer == NULL) {
321 usb_free_urb(ir->int_urb);
322 goto err_out_stop;
323 }
324 dprintk("int interval: %d\n", dev->int_in.endp->desc.bInterval);
325 usb_fill_int_urb(ir->int_urb, dev->udev, pipe,
326 ir->int_urb->transfer_buffer, size,
327 tm6000_ir_urb_received, dev,
328 dev->int_in.endp->desc.bInterval);
329 rc = usb_submit_urb(ir->int_urb, GFP_KERNEL);
330 if (rc) {
331 kfree(ir->int_urb->transfer_buffer);
332 usb_free_urb(ir->int_urb);
333 err = rc;
334 goto err_out_stop;
335 }
336 ir->urb_data = kzalloc(size, GFP_KERNEL);
337 } 423 }
338 424
339 /* ir register */ 425 /* ir register */
340 err = ir_input_register(ir->input->input_dev, dev->ir_codes, 426 err = rc_register_device(rc);
341 &ir->props, "tm6000");
342 if (err) 427 if (err)
343 goto err_out_stop; 428 goto out;
344 429
345 return 0; 430 return 0;
346 431
347err_out_stop: 432out:
348 dev->ir = NULL; 433 dev->ir = NULL;
349err_out_free: 434 rc_free_device(rc);
350 kfree(ir_input_dev);
351 kfree(ir); 435 kfree(ir);
352 return err; 436 return err;
353} 437}
@@ -361,19 +445,12 @@ int tm6000_ir_fini(struct tm6000_core *dev)
361 if (!ir) 445 if (!ir)
362 return 0; 446 return 0;
363 447
364 ir_input_unregister(ir->input->input_dev); 448 rc_unregister_device(ir->rc);
365 449
366 if (ir->int_urb) { 450 if (ir->int_urb) {
367 usb_kill_urb(ir->int_urb); 451 tm6000_ir_int_stop(dev);
368 kfree(ir->int_urb->transfer_buffer);
369 usb_free_urb(ir->int_urb);
370 ir->int_urb = NULL;
371 kfree(ir->urb_data);
372 ir->urb_data = NULL;
373 } 452 }
374 453
375 kfree(ir->input);
376 ir->input = NULL;
377 kfree(ir); 454 kfree(ir);
378 dev->ir = NULL; 455 dev->ir = NULL;
379 456
diff --git a/drivers/staging/tm6000/tm6000-video.c b/drivers/staging/tm6000/tm6000-video.c
index c5690b2a8924..8fe017c3721f 100644
--- a/drivers/staging/tm6000/tm6000-video.c
+++ b/drivers/staging/tm6000/tm6000-video.c
@@ -545,11 +545,16 @@ static int tm6000_prepare_isoc(struct tm6000_core *dev, unsigned int framesize)
545 545
546 /* De-allocates all pending stuff */ 546 /* De-allocates all pending stuff */
547 tm6000_uninit_isoc(dev); 547 tm6000_uninit_isoc(dev);
548 /* Stop interrupt USB pipe */
549 tm6000_ir_int_stop(dev);
548 550
549 usb_set_interface(dev->udev, 551 usb_set_interface(dev->udev,
550 dev->isoc_in.bInterfaceNumber, 552 dev->isoc_in.bInterfaceNumber,
551 dev->isoc_in.bAlternateSetting); 553 dev->isoc_in.bAlternateSetting);
552 554
555 /* Start interrupt USB pipe */
556 tm6000_ir_int_start(dev);
557
553 pipe = usb_rcvisocpipe(dev->udev, 558 pipe = usb_rcvisocpipe(dev->udev,
554 dev->isoc_in.endp->desc.bEndpointAddress & 559 dev->isoc_in.endp->desc.bEndpointAddress &
555 USB_ENDPOINT_NUMBER_MASK); 560 USB_ENDPOINT_NUMBER_MASK);
@@ -986,15 +991,6 @@ static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
986 file->f_flags & O_NONBLOCK); 991 file->f_flags & O_NONBLOCK);
987} 992}
988 993
989#ifdef CONFIG_VIDEO_V4L1_COMPAT
990static int vidiocgmbuf(struct file *file, void *priv, struct video_mbuf *mbuf)
991{
992 struct tm6000_fh *fh = priv;
993
994 return videobuf_cgmbuf(&fh->vb_vidq, mbuf, 8);
995}
996#endif
997
998static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i) 994static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
999{ 995{
1000 struct tm6000_fh *fh = priv; 996 struct tm6000_fh *fh = priv;
@@ -1438,9 +1434,6 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
1438 .vidioc_querybuf = vidioc_querybuf, 1434 .vidioc_querybuf = vidioc_querybuf,
1439 .vidioc_qbuf = vidioc_qbuf, 1435 .vidioc_qbuf = vidioc_qbuf,
1440 .vidioc_dqbuf = vidioc_dqbuf, 1436 .vidioc_dqbuf = vidioc_dqbuf,
1441#ifdef CONFIG_VIDEO_V4L1_COMPAT
1442 .vidiocgmbuf = vidiocgmbuf,
1443#endif
1444}; 1437};
1445 1438
1446static struct video_device tm6000_template = { 1439static struct video_device tm6000_template = {
diff --git a/drivers/staging/tm6000/tm6000.h b/drivers/staging/tm6000/tm6000.h
index 46017b603190..bf11eeec92c7 100644
--- a/drivers/staging/tm6000/tm6000.h
+++ b/drivers/staging/tm6000/tm6000.h
@@ -266,6 +266,7 @@ struct tm6000_fh {
266int tm6000_tuner_callback(void *ptr, int component, int command, int arg); 266int tm6000_tuner_callback(void *ptr, int component, int command, int arg);
267int tm6000_xc5000_callback(void *ptr, int component, int command, int arg); 267int tm6000_xc5000_callback(void *ptr, int component, int command, int arg);
268int tm6000_cards_setup(struct tm6000_core *dev); 268int tm6000_cards_setup(struct tm6000_core *dev);
269void tm6000_flash_led(struct tm6000_core *dev, u8 state);
269 270
270/* In tm6000-core.c */ 271/* In tm6000-core.c */
271 272
@@ -332,6 +333,8 @@ int tm6000_queue_init(struct tm6000_core *dev);
332int tm6000_ir_init(struct tm6000_core *dev); 333int tm6000_ir_init(struct tm6000_core *dev);
333int tm6000_ir_fini(struct tm6000_core *dev); 334int tm6000_ir_fini(struct tm6000_core *dev);
334void tm6000_ir_wait(struct tm6000_core *dev, u8 state); 335void tm6000_ir_wait(struct tm6000_core *dev, u8 state);
336int tm6000_ir_int_start(struct tm6000_core *dev);
337void tm6000_ir_int_stop(struct tm6000_core *dev);
335 338
336/* Debug stuff */ 339/* Debug stuff */
337 340
diff --git a/drivers/staging/usbvideo/Kconfig b/drivers/staging/usbvideo/Kconfig
new file mode 100644
index 000000000000..566d659e6ff3
--- /dev/null
+++ b/drivers/staging/usbvideo/Kconfig
@@ -0,0 +1,15 @@
1config VIDEO_USBVIDEO
2 tristate
3
4config USB_VICAM
5 tristate "USB 3com HomeConnect (aka vicam) support (DEPRECATED)"
6 depends on VIDEO_DEV && VIDEO_V4L2_COMMON && USB
7 select VIDEO_USBVIDEO
8 ---help---
9 Say Y here if you have 3com homeconnect camera (vicam).
10
11 This driver uses the deprecated V4L1 API and will be removed in
12 2.6.39, unless someone converts it to the V4L2 API.
13
14 To compile this driver as a module, choose M here: the
15 module will be called vicam.
diff --git a/drivers/staging/usbvideo/Makefile b/drivers/staging/usbvideo/Makefile
new file mode 100644
index 000000000000..3c99a9a2d8d3
--- /dev/null
+++ b/drivers/staging/usbvideo/Makefile
@@ -0,0 +1,2 @@
1obj-$(CONFIG_VIDEO_USBVIDEO) += usbvideo.o
2obj-$(CONFIG_USB_VICAM) += vicam.o
diff --git a/drivers/staging/usbvideo/TODO b/drivers/staging/usbvideo/TODO
new file mode 100644
index 000000000000..3b2c03836286
--- /dev/null
+++ b/drivers/staging/usbvideo/TODO
@@ -0,0 +1,5 @@
1This is an obsolete driver for some old webcams that still use V4L1 API.
2As V4L1 support is being removed from kernel, if nobody take care on it,
3the driver will be removed for 2.6.39.
4
5Please send patches to linux-media@vger.kernel.org
diff --git a/drivers/media/video/usbvideo/usbvideo.c b/drivers/staging/usbvideo/usbvideo.c
index f1fcf9744961..f1fcf9744961 100644
--- a/drivers/media/video/usbvideo/usbvideo.c
+++ b/drivers/staging/usbvideo/usbvideo.c
diff --git a/drivers/media/video/usbvideo/usbvideo.h b/drivers/staging/usbvideo/usbvideo.h
index c66985beb8c9..95638a072b19 100644
--- a/drivers/media/video/usbvideo/usbvideo.h
+++ b/drivers/staging/usbvideo/usbvideo.h
@@ -16,7 +16,7 @@
16#ifndef usbvideo_h 16#ifndef usbvideo_h
17#define usbvideo_h 17#define usbvideo_h
18 18
19#include <linux/videodev.h> 19#include "videodev.h"
20#include <media/v4l2-common.h> 20#include <media/v4l2-common.h>
21#include <media/v4l2-ioctl.h> 21#include <media/v4l2-ioctl.h>
22#include <linux/usb.h> 22#include <linux/usb.h>
diff --git a/drivers/media/video/usbvideo/vicam.c b/drivers/staging/usbvideo/vicam.c
index dc17cce2fbb6..ecdb121297c9 100644
--- a/drivers/media/video/usbvideo/vicam.c
+++ b/drivers/staging/usbvideo/vicam.c
@@ -38,7 +38,7 @@
38#include <linux/kernel.h> 38#include <linux/kernel.h>
39#include <linux/module.h> 39#include <linux/module.h>
40#include <linux/init.h> 40#include <linux/init.h>
41#include <linux/videodev.h> 41#include "videodev.h"
42#include <linux/usb.h> 42#include <linux/usb.h>
43#include <linux/vmalloc.h> 43#include <linux/vmalloc.h>
44#include <linux/mm.h> 44#include <linux/mm.h>
diff --git a/drivers/staging/usbvideo/videodev.h b/drivers/staging/usbvideo/videodev.h
new file mode 100644
index 000000000000..f11efbef1c05
--- /dev/null
+++ b/drivers/staging/usbvideo/videodev.h
@@ -0,0 +1,318 @@
1/*
2 * Video for Linux version 1 - OBSOLETE
3 *
4 * Header file for v4l1 drivers and applications, for
5 * Linux kernels 2.2.x or 2.4.x.
6 *
7 * Provides header for legacy drivers and applications
8 *
9 * See http://linuxtv.org for more info
10 *
11 */
12#ifndef __LINUX_VIDEODEV_H
13#define __LINUX_VIDEODEV_H
14
15#include <linux/types.h>
16#include <linux/ioctl.h>
17#include <linux/videodev2.h>
18
19#define VID_TYPE_CAPTURE 1 /* Can capture */
20#define VID_TYPE_TUNER 2 /* Can tune */
21#define VID_TYPE_TELETEXT 4 /* Does teletext */
22#define VID_TYPE_OVERLAY 8 /* Overlay onto frame buffer */
23#define VID_TYPE_CHROMAKEY 16 /* Overlay by chromakey */
24#define VID_TYPE_CLIPPING 32 /* Can clip */
25#define VID_TYPE_FRAMERAM 64 /* Uses the frame buffer memory */
26#define VID_TYPE_SCALES 128 /* Scalable */
27#define VID_TYPE_MONOCHROME 256 /* Monochrome only */
28#define VID_TYPE_SUBCAPTURE 512 /* Can capture subareas of the image */
29#define VID_TYPE_MPEG_DECODER 1024 /* Can decode MPEG streams */
30#define VID_TYPE_MPEG_ENCODER 2048 /* Can encode MPEG streams */
31#define VID_TYPE_MJPEG_DECODER 4096 /* Can decode MJPEG streams */
32#define VID_TYPE_MJPEG_ENCODER 8192 /* Can encode MJPEG streams */
33
34struct video_capability
35{
36 char name[32];
37 int type;
38 int channels; /* Num channels */
39 int audios; /* Num audio devices */
40 int maxwidth; /* Supported width */
41 int maxheight; /* And height */
42 int minwidth; /* Supported width */
43 int minheight; /* And height */
44};
45
46
47struct video_channel
48{
49 int channel;
50 char name[32];
51 int tuners;
52 __u32 flags;
53#define VIDEO_VC_TUNER 1 /* Channel has a tuner */
54#define VIDEO_VC_AUDIO 2 /* Channel has audio */
55 __u16 type;
56#define VIDEO_TYPE_TV 1
57#define VIDEO_TYPE_CAMERA 2
58 __u16 norm; /* Norm set by channel */
59};
60
61struct video_tuner
62{
63 int tuner;
64 char name[32];
65 unsigned long rangelow, rangehigh; /* Tuner range */
66 __u32 flags;
67#define VIDEO_TUNER_PAL 1
68#define VIDEO_TUNER_NTSC 2
69#define VIDEO_TUNER_SECAM 4
70#define VIDEO_TUNER_LOW 8 /* Uses KHz not MHz */
71#define VIDEO_TUNER_NORM 16 /* Tuner can set norm */
72#define VIDEO_TUNER_STEREO_ON 128 /* Tuner is seeing stereo */
73#define VIDEO_TUNER_RDS_ON 256 /* Tuner is seeing an RDS datastream */
74#define VIDEO_TUNER_MBS_ON 512 /* Tuner is seeing an MBS datastream */
75 __u16 mode; /* PAL/NTSC/SECAM/OTHER */
76#define VIDEO_MODE_PAL 0
77#define VIDEO_MODE_NTSC 1
78#define VIDEO_MODE_SECAM 2
79#define VIDEO_MODE_AUTO 3
80 __u16 signal; /* Signal strength 16bit scale */
81};
82
83struct video_picture
84{
85 __u16 brightness;
86 __u16 hue;
87 __u16 colour;
88 __u16 contrast;
89 __u16 whiteness; /* Black and white only */
90 __u16 depth; /* Capture depth */
91 __u16 palette; /* Palette in use */
92#define VIDEO_PALETTE_GREY 1 /* Linear greyscale */
93#define VIDEO_PALETTE_HI240 2 /* High 240 cube (BT848) */
94#define VIDEO_PALETTE_RGB565 3 /* 565 16 bit RGB */
95#define VIDEO_PALETTE_RGB24 4 /* 24bit RGB */
96#define VIDEO_PALETTE_RGB32 5 /* 32bit RGB */
97#define VIDEO_PALETTE_RGB555 6 /* 555 15bit RGB */
98#define VIDEO_PALETTE_YUV422 7 /* YUV422 capture */
99#define VIDEO_PALETTE_YUYV 8
100#define VIDEO_PALETTE_UYVY 9 /* The great thing about standards is ... */
101#define VIDEO_PALETTE_YUV420 10
102#define VIDEO_PALETTE_YUV411 11 /* YUV411 capture */
103#define VIDEO_PALETTE_RAW 12 /* RAW capture (BT848) */
104#define VIDEO_PALETTE_YUV422P 13 /* YUV 4:2:2 Planar */
105#define VIDEO_PALETTE_YUV411P 14 /* YUV 4:1:1 Planar */
106#define VIDEO_PALETTE_YUV420P 15 /* YUV 4:2:0 Planar */
107#define VIDEO_PALETTE_YUV410P 16 /* YUV 4:1:0 Planar */
108#define VIDEO_PALETTE_PLANAR 13 /* start of planar entries */
109#define VIDEO_PALETTE_COMPONENT 7 /* start of component entries */
110};
111
112struct video_audio
113{
114 int audio; /* Audio channel */
115 __u16 volume; /* If settable */
116 __u16 bass, treble;
117 __u32 flags;
118#define VIDEO_AUDIO_MUTE 1
119#define VIDEO_AUDIO_MUTABLE 2
120#define VIDEO_AUDIO_VOLUME 4
121#define VIDEO_AUDIO_BASS 8
122#define VIDEO_AUDIO_TREBLE 16
123#define VIDEO_AUDIO_BALANCE 32
124 char name[16];
125#define VIDEO_SOUND_MONO 1
126#define VIDEO_SOUND_STEREO 2
127#define VIDEO_SOUND_LANG1 4
128#define VIDEO_SOUND_LANG2 8
129 __u16 mode;
130 __u16 balance; /* Stereo balance */
131 __u16 step; /* Step actual volume uses */
132};
133
134struct video_clip
135{
136 __s32 x,y;
137 __s32 width, height;
138 struct video_clip *next; /* For user use/driver use only */
139};
140
141struct video_window
142{
143 __u32 x,y; /* Position of window */
144 __u32 width,height; /* Its size */
145 __u32 chromakey;
146 __u32 flags;
147 struct video_clip __user *clips; /* Set only */
148 int clipcount;
149#define VIDEO_WINDOW_INTERLACE 1
150#define VIDEO_WINDOW_CHROMAKEY 16 /* Overlay by chromakey */
151#define VIDEO_CLIP_BITMAP -1
152/* bitmap is 1024x625, a '1' bit represents a clipped pixel */
153#define VIDEO_CLIPMAP_SIZE (128 * 625)
154};
155
156struct video_capture
157{
158 __u32 x,y; /* Offsets into image */
159 __u32 width, height; /* Area to capture */
160 __u16 decimation; /* Decimation divider */
161 __u16 flags; /* Flags for capture */
162#define VIDEO_CAPTURE_ODD 0 /* Temporal */
163#define VIDEO_CAPTURE_EVEN 1
164};
165
166struct video_buffer
167{
168 void *base;
169 int height,width;
170 int depth;
171 int bytesperline;
172};
173
174struct video_mmap
175{
176 unsigned int frame; /* Frame (0 - n) for double buffer */
177 int height,width;
178 unsigned int format; /* should be VIDEO_PALETTE_* */
179};
180
181struct video_key
182{
183 __u8 key[8];
184 __u32 flags;
185};
186
187struct video_mbuf
188{
189 int size; /* Total memory to map */
190 int frames; /* Frames */
191 int offsets[VIDEO_MAX_FRAME];
192};
193
194#define VIDEO_NO_UNIT (-1)
195
196struct video_unit
197{
198 int video; /* Video minor */
199 int vbi; /* VBI minor */
200 int radio; /* Radio minor */
201 int audio; /* Audio minor */
202 int teletext; /* Teletext minor */
203};
204
205struct vbi_format {
206 __u32 sampling_rate; /* in Hz */
207 __u32 samples_per_line;
208 __u32 sample_format; /* VIDEO_PALETTE_RAW only (1 byte) */
209 __s32 start[2]; /* starting line for each frame */
210 __u32 count[2]; /* count of lines for each frame */
211 __u32 flags;
212#define VBI_UNSYNC 1 /* can distingues between top/bottom field */
213#define VBI_INTERLACED 2 /* lines are interlaced */
214};
215
216/* video_info is biased towards hardware mpeg encode/decode */
217/* but it could apply generically to any hardware compressor/decompressor */
218struct video_info
219{
220 __u32 frame_count; /* frames output since decode/encode began */
221 __u32 h_size; /* current unscaled horizontal size */
222 __u32 v_size; /* current unscaled veritcal size */
223 __u32 smpte_timecode; /* current SMPTE timecode (for current GOP) */
224 __u32 picture_type; /* current picture type */
225 __u32 temporal_reference; /* current temporal reference */
226 __u8 user_data[256]; /* user data last found in compressed stream */
227 /* user_data[0] contains user data flags, user_data[1] has count */
228};
229
230/* generic structure for setting playback modes */
231struct video_play_mode
232{
233 int mode;
234 int p1;
235 int p2;
236};
237
238/* for loading microcode / fpga programming */
239struct video_code
240{
241 char loadwhat[16]; /* name or tag of file being passed */
242 int datasize;
243 __u8 *data;
244};
245
246#define VIDIOCGCAP _IOR('v',1,struct video_capability) /* Get capabilities */
247#define VIDIOCGCHAN _IOWR('v',2,struct video_channel) /* Get channel info (sources) */
248#define VIDIOCSCHAN _IOW('v',3,struct video_channel) /* Set channel */
249#define VIDIOCGTUNER _IOWR('v',4,struct video_tuner) /* Get tuner abilities */
250#define VIDIOCSTUNER _IOW('v',5,struct video_tuner) /* Tune the tuner for the current channel */
251#define VIDIOCGPICT _IOR('v',6,struct video_picture) /* Get picture properties */
252#define VIDIOCSPICT _IOW('v',7,struct video_picture) /* Set picture properties */
253#define VIDIOCCAPTURE _IOW('v',8,int) /* Start, end capture */
254#define VIDIOCGWIN _IOR('v',9, struct video_window) /* Get the video overlay window */
255#define VIDIOCSWIN _IOW('v',10, struct video_window) /* Set the video overlay window - passes clip list for hardware smarts , chromakey etc */
256#define VIDIOCGFBUF _IOR('v',11, struct video_buffer) /* Get frame buffer */
257#define VIDIOCSFBUF _IOW('v',12, struct video_buffer) /* Set frame buffer - root only */
258#define VIDIOCKEY _IOR('v',13, struct video_key) /* Video key event - to dev 255 is to all - cuts capture on all DMA windows with this key (0xFFFFFFFF == all) */
259#define VIDIOCGFREQ _IOR('v',14, unsigned long) /* Set tuner */
260#define VIDIOCSFREQ _IOW('v',15, unsigned long) /* Set tuner */
261#define VIDIOCGAUDIO _IOR('v',16, struct video_audio) /* Get audio info */
262#define VIDIOCSAUDIO _IOW('v',17, struct video_audio) /* Audio source, mute etc */
263#define VIDIOCSYNC _IOW('v',18, int) /* Sync with mmap grabbing */
264#define VIDIOCMCAPTURE _IOW('v',19, struct video_mmap) /* Grab frames */
265#define VIDIOCGMBUF _IOR('v',20, struct video_mbuf) /* Memory map buffer info */
266#define VIDIOCGUNIT _IOR('v',21, struct video_unit) /* Get attached units */
267#define VIDIOCGCAPTURE _IOR('v',22, struct video_capture) /* Get subcapture */
268#define VIDIOCSCAPTURE _IOW('v',23, struct video_capture) /* Set subcapture */
269#define VIDIOCSPLAYMODE _IOW('v',24, struct video_play_mode) /* Set output video mode/feature */
270#define VIDIOCSWRITEMODE _IOW('v',25, int) /* Set write mode */
271#define VIDIOCGPLAYINFO _IOR('v',26, struct video_info) /* Get current playback info from hardware */
272#define VIDIOCSMICROCODE _IOW('v',27, struct video_code) /* Load microcode into hardware */
273#define VIDIOCGVBIFMT _IOR('v',28, struct vbi_format) /* Get VBI information */
274#define VIDIOCSVBIFMT _IOW('v',29, struct vbi_format) /* Set VBI information */
275
276
277#define BASE_VIDIOCPRIVATE 192 /* 192-255 are private */
278
279/* VIDIOCSWRITEMODE */
280#define VID_WRITE_MPEG_AUD 0
281#define VID_WRITE_MPEG_VID 1
282#define VID_WRITE_OSD 2
283#define VID_WRITE_TTX 3
284#define VID_WRITE_CC 4
285#define VID_WRITE_MJPEG 5
286
287/* VIDIOCSPLAYMODE */
288#define VID_PLAY_VID_OUT_MODE 0
289 /* p1: = VIDEO_MODE_PAL, VIDEO_MODE_NTSC, etc ... */
290#define VID_PLAY_GENLOCK 1
291 /* p1: 0 = OFF, 1 = ON */
292 /* p2: GENLOCK FINE DELAY value */
293#define VID_PLAY_NORMAL 2
294#define VID_PLAY_PAUSE 3
295#define VID_PLAY_SINGLE_FRAME 4
296#define VID_PLAY_FAST_FORWARD 5
297#define VID_PLAY_SLOW_MOTION 6
298#define VID_PLAY_IMMEDIATE_NORMAL 7
299#define VID_PLAY_SWITCH_CHANNELS 8
300#define VID_PLAY_FREEZE_FRAME 9
301#define VID_PLAY_STILL_MODE 10
302#define VID_PLAY_MASTER_MODE 11
303 /* p1: see below */
304#define VID_PLAY_MASTER_NONE 1
305#define VID_PLAY_MASTER_VIDEO 2
306#define VID_PLAY_MASTER_AUDIO 3
307#define VID_PLAY_ACTIVE_SCANLINES 12
308 /* p1 = first active; p2 = last active */
309#define VID_PLAY_RESET 13
310#define VID_PLAY_END_MARK 14
311
312#endif /* __LINUX_VIDEODEV_H */
313
314/*
315 * Local variables:
316 * c-basic-offset: 8
317 * End:
318 */