aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/DocBook/dvb/dvbapi.xml19
-rw-r--r--Documentation/DocBook/dvb/frontend.h.xml1
-rw-r--r--Documentation/DocBook/dvb/frontend.xml10
-rw-r--r--Documentation/DocBook/media-entities.tmpl1
-rw-r--r--Documentation/DocBook/media.tmpl8
-rw-r--r--Documentation/DocBook/v4l/lirc_device_interface.xml235
-rw-r--r--Documentation/DocBook/v4l/remote_controllers.xml2
-rw-r--r--Documentation/dvb/get_dvb_firmware25
-rw-r--r--Documentation/feature-removal-schedule.txt51
-rw-r--r--Documentation/video4linux/CARDLIST.cx238856
-rw-r--r--Documentation/video4linux/CARDLIST.em28xx1
-rw-r--r--Documentation/video4linux/CARDLIST.saa71343
-rw-r--r--Documentation/video4linux/gspca.txt8
-rw-r--r--arch/sh/boards/mach-ap325rxa/setup.c2
-rw-r--r--drivers/media/IR/Kconfig35
-rw-r--r--drivers/media/IR/Makefile3
-rw-r--r--drivers/media/IR/imon.c11
-rw-r--r--drivers/media/IR/ir-core-priv.h54
-rw-r--r--drivers/media/IR/ir-jvc-decoder.c152
-rw-r--r--drivers/media/IR/ir-keytable.c5
-rw-r--r--drivers/media/IR/ir-lirc-codec.c278
-rw-r--r--drivers/media/IR/ir-nec-decoder.c151
-rw-r--r--drivers/media/IR/ir-raw-event.c167
-rw-r--r--drivers/media/IR/ir-rc5-decoder.c167
-rw-r--r--drivers/media/IR/ir-rc6-decoder.c153
-rw-r--r--drivers/media/IR/ir-sony-decoder.c155
-rw-r--r--drivers/media/IR/ir-sysfs.c251
-rw-r--r--drivers/media/IR/keymaps/Makefile4
-rw-r--r--drivers/media/IR/keymaps/rc-dib0700-nec.c124
-rw-r--r--drivers/media/IR/keymaps/rc-dib0700-rc5.c235
-rw-r--r--drivers/media/IR/keymaps/rc-lirc.c41
-rw-r--r--drivers/media/IR/keymaps/rc-rc6-mce.c105
-rw-r--r--drivers/media/IR/lirc_dev.c764
-rw-r--r--drivers/media/IR/mceusb.c1143
-rw-r--r--drivers/media/common/saa7146_fops.c2
-rw-r--r--drivers/media/common/saa7146_vbi.c4
-rw-r--r--drivers/media/common/saa7146_video.c4
-rw-r--r--drivers/media/common/tuners/tda18271-fe.c8
-rw-r--r--drivers/media/common/tuners/tuner-simple.c3
-rw-r--r--drivers/media/common/tuners/xc5000.c59
-rw-r--r--drivers/media/dvb/bt8xx/dst_ca.c2
-rw-r--r--drivers/media/dvb/dvb-core/dmxdev.c2
-rw-r--r--drivers/media/dvb/dvb-core/dvb_ca_en50221.c10
-rw-r--r--drivers/media/dvb/dvb-core/dvb_demux.c10
-rw-r--r--drivers/media/dvb/dvb-core/dvb_frontend.c10
-rw-r--r--drivers/media/dvb/dvb-usb/a800.c12
-rw-r--r--drivers/media/dvb/dvb-usb/af9005-remote.c4
-rw-r--r--drivers/media/dvb/dvb-usb/af9005.c71
-rw-r--r--drivers/media/dvb/dvb-usb/af9005.h2
-rw-r--r--drivers/media/dvb/dvb-usb/af9015.c42
-rw-r--r--drivers/media/dvb/dvb-usb/af9015.h18
-rw-r--r--drivers/media/dvb/dvb-usb/anysee.c28
-rw-r--r--drivers/media/dvb/dvb-usb/az6027.c13
-rw-r--r--drivers/media/dvb/dvb-usb/cinergyT2-core.c12
-rw-r--r--drivers/media/dvb/dvb-usb/cxusb.c128
-rw-r--r--drivers/media/dvb/dvb-usb/dib0700.h1
-rw-r--r--drivers/media/dvb/dvb-usb/dib0700_core.c266
-rw-r--r--drivers/media/dvb/dvb-usb/dib0700_devices.c614
-rw-r--r--drivers/media/dvb/dvb-usb/dibusb-common.c2
-rw-r--r--drivers/media/dvb/dvb-usb/dibusb-mb.c40
-rw-r--r--drivers/media/dvb/dvb-usb/dibusb-mc.c10
-rw-r--r--drivers/media/dvb/dvb-usb/dibusb.h2
-rw-r--r--drivers/media/dvb/dvb-usb/digitv.c20
-rw-r--r--drivers/media/dvb/dvb-usb/dtt200u.c42
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-ids.h1
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-init.c60
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-remote.c198
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb.h92
-rw-r--r--drivers/media/dvb/dvb-usb/dw2102.c67
-rw-r--r--drivers/media/dvb/dvb-usb/gp8psk-fe.c2
-rw-r--r--drivers/media/dvb/dvb-usb/m920x.c44
-rw-r--r--drivers/media/dvb/dvb-usb/nova-t-usb2.c14
-rw-r--r--drivers/media/dvb/dvb-usb/opera1.c16
-rw-r--r--drivers/media/dvb/dvb-usb/vp702x.c14
-rw-r--r--drivers/media/dvb/dvb-usb/vp7045.c14
-rw-r--r--drivers/media/dvb/frontends/Kconfig1
-rw-r--r--drivers/media/dvb/frontends/af9013.c52
-rw-r--r--drivers/media/dvb/frontends/af9013.h2
-rw-r--r--drivers/media/dvb/frontends/af9013_priv.h8
-rw-r--r--drivers/media/dvb/frontends/dib3000mb.c9
-rw-r--r--drivers/media/dvb/frontends/dib3000mb_priv.h4
-rw-r--r--drivers/media/dvb/frontends/dib3000mc.c2
-rw-r--r--drivers/media/dvb/frontends/lgdt3305.c267
-rw-r--r--drivers/media/dvb/frontends/lgdt3305.h10
-rw-r--r--drivers/media/dvb/frontends/lgs8gxx.c50
-rw-r--r--drivers/media/dvb/frontends/mb86a16.c1
-rw-r--r--drivers/media/dvb/frontends/tda10048.c43
-rw-r--r--drivers/media/dvb/mantis/Kconfig14
-rw-r--r--drivers/media/dvb/mantis/mantis_input.c5
-rw-r--r--drivers/media/dvb/siano/sms-cards.c2
-rw-r--r--drivers/media/dvb/siano/sms-cards.h2
-rw-r--r--drivers/media/dvb/siano/smscoreapi.c4
-rw-r--r--drivers/media/dvb/siano/smsir.c261
-rw-r--r--drivers/media/dvb/siano/smsir.h63
-rw-r--r--drivers/media/dvb/siano/smsusb.c3
-rw-r--r--drivers/media/radio/si470x/radio-si470x-common.c2
-rw-r--r--drivers/media/radio/si4713-i2c.c12
-rw-r--r--drivers/media/video/Kconfig183
-rw-r--r--drivers/media/video/Makefile9
-rw-r--r--drivers/media/video/ak881x.c6
-rw-r--r--drivers/media/video/au0828/Makefile2
-rw-r--r--drivers/media/video/au0828/au0828-vbi.c138
-rw-r--r--drivers/media/video/au0828/au0828-video.c443
-rw-r--r--drivers/media/video/au0828/au0828.h20
-rw-r--r--drivers/media/video/bt8xx/bttv-risc.c2
-rw-r--r--drivers/media/video/cpia_usb.c3
-rw-r--r--drivers/media/video/cx18/cx18-ioctl.c2
-rw-r--r--drivers/media/video/cx23885/cx23885-cards.c40
-rw-r--r--drivers/media/video/cx23885/cx23885-core.c11
-rw-r--r--drivers/media/video/cx23885/cx23885-dvb.c2
-rw-r--r--drivers/media/video/cx23885/cx23885-input.c317
-rw-r--r--drivers/media/video/cx23885/cx23885-ir.c2
-rw-r--r--drivers/media/video/cx23885/cx23885.h12
-rw-r--r--drivers/media/video/cx88/cx88-alsa.c37
-rw-r--r--drivers/media/video/cx88/cx88-cards.c9
-rw-r--r--drivers/media/video/cx88/cx88-core.c2
-rw-r--r--drivers/media/video/cx88/cx88-i2c.c6
-rw-r--r--drivers/media/video/cx88/cx88-input.c46
-rw-r--r--drivers/media/video/cx88/cx88.h1
-rw-r--r--drivers/media/video/dabusb.c13
-rw-r--r--drivers/media/video/davinci/Kconfig93
-rw-r--r--drivers/media/video/em28xx/em28xx-cards.c28
-rw-r--r--drivers/media/video/em28xx/em28xx-dvb.c33
-rw-r--r--drivers/media/video/em28xx/em28xx-input.c80
-rw-r--r--drivers/media/video/em28xx/em28xx-video.c4
-rw-r--r--drivers/media/video/em28xx/em28xx.h2
-rw-r--r--drivers/media/video/fsl-viu.c1632
-rw-r--r--drivers/media/video/gspca/Kconfig18
-rw-r--r--drivers/media/video/gspca/Makefile4
-rw-r--r--drivers/media/video/gspca/conex.c8
-rw-r--r--drivers/media/video/gspca/cpia1.c19
-rw-r--r--drivers/media/video/gspca/gl860/gl860-mi2020.c731
-rw-r--r--drivers/media/video/gspca/gl860/gl860-ov9655.c4
-rw-r--r--drivers/media/video/gspca/gl860/gl860.c42
-rw-r--r--drivers/media/video/gspca/gl860/gl860.h13
-rw-r--r--drivers/media/video/gspca/gspca.c340
-rw-r--r--drivers/media/video/gspca/gspca.h22
-rw-r--r--drivers/media/video/gspca/jeilinj.c6
-rw-r--r--drivers/media/video/gspca/m5602/m5602_bridge.h1
-rw-r--r--drivers/media/video/gspca/m5602/m5602_core.c15
-rw-r--r--drivers/media/video/gspca/m5602/m5602_s5k83a.c1
-rw-r--r--drivers/media/video/gspca/mars.c13
-rw-r--r--drivers/media/video/gspca/ov519.c28
-rw-r--r--drivers/media/video/gspca/ov534.c7
-rw-r--r--drivers/media/video/gspca/pac7302.c31
-rw-r--r--drivers/media/video/gspca/pac7311.c29
-rw-r--r--drivers/media/video/gspca/sn9c20x.c18
-rw-r--r--drivers/media/video/gspca/sonixb.c8
-rw-r--r--drivers/media/video/gspca/sonixj.c38
-rw-r--r--drivers/media/video/gspca/spca1528.c605
-rw-r--r--drivers/media/video/gspca/spca500.c13
-rw-r--r--drivers/media/video/gspca/sq930x.c1402
-rw-r--r--drivers/media/video/gspca/stk014.c17
-rw-r--r--drivers/media/video/gspca/stv06xx/stv06xx.h1
-rw-r--r--drivers/media/video/gspca/sunplus.c13
-rw-r--r--drivers/media/video/gspca/t613.c408
-rw-r--r--drivers/media/video/gspca/tv8532.c227
-rw-r--r--drivers/media/video/gspca/vc032x.c228
-rw-r--r--drivers/media/video/gspca/w996Xcf.c16
-rw-r--r--drivers/media/video/gspca/zc3xx.c92
-rw-r--r--drivers/media/video/hdpvr/hdpvr-core.c5
-rw-r--r--drivers/media/video/hdpvr/hdpvr-video.c4
-rw-r--r--drivers/media/video/ir-kbd-i2c.c14
-rw-r--r--drivers/media/video/ivtv/ivtv-driver.c14
-rw-r--r--drivers/media/video/ivtv/ivtv-driver.h4
-rw-r--r--drivers/media/video/ivtv/ivtv-fileops.c30
-rw-r--r--drivers/media/video/ivtv/ivtv-firmware.c122
-rw-r--r--drivers/media/video/ivtv/ivtv-firmware.h1
-rw-r--r--drivers/media/video/ivtv/ivtv-mailbox.c8
-rw-r--r--drivers/media/video/ivtv/ivtv-mailbox.h1
-rw-r--r--drivers/media/video/ivtv/ivtv-streams.c11
-rw-r--r--drivers/media/video/ivtv/ivtv-version.h2
-rw-r--r--drivers/media/video/ivtv/ivtvfb.c45
-rw-r--r--drivers/media/video/mem2mem_testdev.c4
-rw-r--r--drivers/media/video/mt9m111.c16
-rw-r--r--drivers/media/video/mt9t112.c12
-rw-r--r--drivers/media/video/omap/omap_vout.c8
-rw-r--r--drivers/media/video/omap24xxcam.c2
-rw-r--r--drivers/media/video/ov511.c5995
-rw-r--r--drivers/media/video/ov511.h573
-rw-r--r--drivers/media/video/ov772x.c8
-rw-r--r--drivers/media/video/ov9640.c14
-rw-r--r--drivers/media/video/ovcamchip/Makefile4
-rw-r--r--drivers/media/video/ovcamchip/ov6x20.c414
-rw-r--r--drivers/media/video/ovcamchip/ov6x30.c373
-rw-r--r--drivers/media/video/ovcamchip/ov76be.c302
-rw-r--r--drivers/media/video/ovcamchip/ov7x10.c334
-rw-r--r--drivers/media/video/ovcamchip/ov7x20.c454
-rw-r--r--drivers/media/video/ovcamchip/ovcamchip_core.c395
-rw-r--r--drivers/media/video/ovcamchip/ovcamchip_priv.h101
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-ioread.c5
-rw-r--r--drivers/media/video/pxa_camera.c10
-rw-r--r--drivers/media/video/rj54n1cb0c.c10
-rw-r--r--drivers/media/video/s2255drv.c724
-rw-r--r--drivers/media/video/saa7134/saa7134-alsa.c14
-rw-r--r--drivers/media/video/saa7134/saa7134-cards.c31
-rw-r--r--drivers/media/video/saa7134/saa7134-core.c2
-rw-r--r--drivers/media/video/saa7134/saa7134-dvb.c23
-rw-r--r--drivers/media/video/saa7134/saa7134.h1
-rw-r--r--drivers/media/video/sh_mobile_ceu_camera.c149
-rw-r--r--drivers/media/video/sh_mobile_csi2.c354
-rw-r--r--drivers/media/video/sh_vou.c65
-rw-r--r--drivers/media/video/soc_camera.c3
-rw-r--r--drivers/media/video/soc_camera_platform.c42
-rw-r--r--drivers/media/video/soc_mediabus.c8
-rw-r--r--drivers/media/video/stv680.c1565
-rw-r--r--drivers/media/video/stv680.h227
-rw-r--r--drivers/media/video/tlg2300/pd-main.c3
-rw-r--r--drivers/media/video/tw9910.c8
-rw-r--r--drivers/media/video/usbvideo/Kconfig14
-rw-r--r--drivers/media/video/usbvideo/Makefile1
-rw-r--r--drivers/media/video/usbvideo/quickcam_messenger.c1126
-rw-r--r--drivers/media/video/usbvideo/quickcam_messenger.h112
-rw-r--r--drivers/media/video/uvc/uvc_ctrl.c105
-rw-r--r--drivers/media/video/uvc/uvc_driver.c15
-rw-r--r--drivers/media/video/uvc/uvc_v4l2.c103
-rw-r--r--drivers/media/video/uvc/uvcvideo.h45
-rw-r--r--drivers/media/video/v4l2-dev.c6
-rw-r--r--drivers/media/video/videobuf-core.c84
-rw-r--r--drivers/media/video/videobuf-dma-contig.c6
-rw-r--r--drivers/media/video/videobuf-dma-sg.c76
-rw-r--r--drivers/media/video/videobuf-vmalloc.c36
-rw-r--r--drivers/media/video/w9968cf.c3620
-rw-r--r--drivers/media/video/w9968cf.h333
-rw-r--r--drivers/media/video/w9968cf_decoder.h86
-rw-r--r--drivers/media/video/w9968cf_vpp.h40
-rw-r--r--drivers/media/video/zc0301/Kconfig15
-rw-r--r--drivers/media/video/zc0301/Makefile3
-rw-r--r--drivers/media/video/zc0301/zc0301.h196
-rw-r--r--drivers/media/video/zc0301/zc0301_core.c2098
-rw-r--r--drivers/media/video/zc0301/zc0301_pas202bcb.c362
-rw-r--r--drivers/media/video/zc0301/zc0301_pb0330.c188
-rw-r--r--drivers/media/video/zc0301/zc0301_sensor.h107
-rw-r--r--drivers/media/video/zoran/videocodec.c5
-rw-r--r--drivers/staging/Kconfig2
-rw-r--r--drivers/staging/Makefile1
-rw-r--r--drivers/staging/cx25821/Makefile11
-rw-r--r--drivers/staging/cx25821/cx25821-alsa.c35
-rw-r--r--drivers/staging/cx25821/cx25821-audio-upstream.c38
-rw-r--r--drivers/staging/cx25821/cx25821-audio.h13
-rw-r--r--drivers/staging/cx25821/cx25821-audups11.c420
-rw-r--r--drivers/staging/cx25821/cx25821-core.c86
-rw-r--r--drivers/staging/cx25821/cx25821-i2c.c3
-rw-r--r--drivers/staging/cx25821/cx25821-medusa-defines.h15
-rw-r--r--drivers/staging/cx25821/cx25821-medusa-reg.h32
-rw-r--r--drivers/staging/cx25821/cx25821-medusa-video.c18
-rw-r--r--drivers/staging/cx25821/cx25821-medusa-video.h4
-rw-r--r--drivers/staging/cx25821/cx25821-reg.h1826
-rw-r--r--drivers/staging/cx25821/cx25821-sram.h50
-rw-r--r--drivers/staging/cx25821/cx25821-video-upstream-ch2.c91
-rw-r--r--drivers/staging/cx25821/cx25821-video-upstream-ch2.h2
-rw-r--r--drivers/staging/cx25821/cx25821-video-upstream.c72
-rw-r--r--drivers/staging/cx25821/cx25821-video-upstream.h2
-rw-r--r--drivers/staging/cx25821/cx25821-video.c905
-rw-r--r--drivers/staging/cx25821/cx25821-video.h20
-rw-r--r--drivers/staging/cx25821/cx25821-video0.c434
-rw-r--r--drivers/staging/cx25821/cx25821-video1.c434
-rw-r--r--drivers/staging/cx25821/cx25821-video2.c436
-rw-r--r--drivers/staging/cx25821/cx25821-video3.c435
-rw-r--r--drivers/staging/cx25821/cx25821-video4.c434
-rw-r--r--drivers/staging/cx25821/cx25821-video5.c434
-rw-r--r--drivers/staging/cx25821/cx25821-video6.c434
-rw-r--r--drivers/staging/cx25821/cx25821-video7.c433
-rw-r--r--drivers/staging/cx25821/cx25821-videoioctl.c480
-rw-r--r--drivers/staging/cx25821/cx25821-vidups10.c418
-rw-r--r--drivers/staging/cx25821/cx25821-vidups9.c416
-rw-r--r--drivers/staging/cx25821/cx25821.h49
-rw-r--r--drivers/staging/lirc/Kconfig110
-rw-r--r--drivers/staging/lirc/Makefile19
-rw-r--r--drivers/staging/lirc/TODO8
-rw-r--r--drivers/staging/lirc/TODO.lirc_i2c3
-rw-r--r--drivers/staging/lirc/lirc_bt829.c383
-rw-r--r--drivers/staging/lirc/lirc_ene0100.c646
-rw-r--r--drivers/staging/lirc/lirc_ene0100.h169
-rw-r--r--drivers/staging/lirc/lirc_i2c.c536
-rw-r--r--drivers/staging/lirc/lirc_igorplugusb.c555
-rw-r--r--drivers/staging/lirc/lirc_imon.c1058
-rw-r--r--drivers/staging/lirc/lirc_it87.c1019
-rw-r--r--drivers/staging/lirc/lirc_it87.h116
-rw-r--r--drivers/staging/lirc/lirc_ite8709.c542
-rw-r--r--drivers/staging/lirc/lirc_parallel.c705
-rw-r--r--drivers/staging/lirc/lirc_parallel.h26
-rw-r--r--drivers/staging/lirc/lirc_sasem.c933
-rw-r--r--drivers/staging/lirc/lirc_serial.c1313
-rw-r--r--drivers/staging/lirc/lirc_sir.c1282
-rw-r--r--drivers/staging/lirc/lirc_streamzap.c821
-rw-r--r--drivers/staging/lirc/lirc_ttusbir.c396
-rw-r--r--drivers/staging/lirc/lirc_zilog.c1387
-rw-r--r--drivers/staging/tm6000/Kconfig4
-rw-r--r--drivers/staging/tm6000/Makefile8
-rw-r--r--drivers/staging/tm6000/tm6000-alsa.c263
-rw-r--r--drivers/staging/tm6000/tm6000-cards.c58
-rw-r--r--drivers/staging/tm6000/tm6000-core.c182
-rw-r--r--drivers/staging/tm6000/tm6000-dvb.c173
-rw-r--r--drivers/staging/tm6000/tm6000-i2c.c25
-rw-r--r--drivers/staging/tm6000/tm6000-input.c364
-rw-r--r--drivers/staging/tm6000/tm6000-stds.c36
-rw-r--r--drivers/staging/tm6000/tm6000-usb-isoc.h5
-rw-r--r--drivers/staging/tm6000/tm6000-video.c335
-rw-r--r--drivers/staging/tm6000/tm6000.h88
-rw-r--r--drivers/usb/gadget/f_uvc.c16
-rw-r--r--drivers/usb/gadget/f_uvc.h352
-rw-r--r--drivers/usb/gadget/uvc.h36
-rw-r--r--drivers/usb/gadget/webcam.c24
-rw-r--r--drivers/video/omap2/displays/panel-acx565akm.c4
-rw-r--r--include/linux/dvb/frontend.h1
-rw-r--r--include/linux/dvb/version.h2
-rw-r--r--include/linux/usb/video.h404
-rw-r--r--include/media/ir-core.h8
-rw-r--r--include/media/ir-kbd-i2c.h2
-rw-r--r--include/media/lirc.h165
-rw-r--r--include/media/lirc_dev.h225
-rw-r--r--include/media/rc-map.h10
-rw-r--r--include/media/sh_mobile_ceu.h3
-rw-r--r--include/media/sh_mobile_csi2.h46
-rw-r--r--include/media/soc_camera.h3
-rw-r--r--include/media/v4l2-mediabus.h13
-rw-r--r--include/media/videobuf-core.h6
-rw-r--r--include/media/videobuf-dma-sg.h39
-rw-r--r--include/media/videobuf-vmalloc.h2
320 files changed, 27790 insertions, 31664 deletions
diff --git a/Documentation/DocBook/dvb/dvbapi.xml b/Documentation/DocBook/dvb/dvbapi.xml
index 63c528fee624..e3a97fdd62a6 100644
--- a/Documentation/DocBook/dvb/dvbapi.xml
+++ b/Documentation/DocBook/dvb/dvbapi.xml
@@ -12,10 +12,12 @@
12<othername role="mi">O. C.</othername> 12<othername role="mi">O. C.</othername>
13<affiliation><address><email>rjkm@metzlerbros.de</email></address></affiliation> 13<affiliation><address><email>rjkm@metzlerbros.de</email></address></affiliation>
14</author> 14</author>
15</authorgroup>
16<authorgroup>
15<author> 17<author>
16<firstname>Mauro</firstname> 18<firstname>Mauro</firstname>
17<surname>Chehab</surname>
18<othername role="mi">Carvalho</othername> 19<othername role="mi">Carvalho</othername>
20<surname>Chehab</surname>
19<affiliation><address><email>mchehab@redhat.com</email></address></affiliation> 21<affiliation><address><email>mchehab@redhat.com</email></address></affiliation>
20<contrib>Ported document to Docbook XML.</contrib> 22<contrib>Ported document to Docbook XML.</contrib>
21</author> 23</author>
@@ -23,13 +25,24 @@
23<copyright> 25<copyright>
24 <year>2002</year> 26 <year>2002</year>
25 <year>2003</year> 27 <year>2003</year>
26 <year>2009</year>
27 <holder>Convergence GmbH</holder> 28 <holder>Convergence GmbH</holder>
28</copyright> 29</copyright>
30<copyright>
31 <year>2009-2010</year>
32 <holder>Mauro Carvalho Chehab</holder>
33</copyright>
29 34
30<revhistory> 35<revhistory>
31<!-- Put document revisions here, newest first. --> 36<!-- Put document revisions here, newest first. -->
32<revision> 37<revision>
38 <revnumber>2.0.3</revnumber>
39 <date>2010-07-03</date>
40 <authorinitials>mcc</authorinitials>
41 <revremark>
42 Add some frontend capabilities flags, present on kernel, but missing at the specs.
43 </revremark>
44</revision>
45<revision>
33 <revnumber>2.0.2</revnumber> 46 <revnumber>2.0.2</revnumber>
34 <date>2009-10-25</date> 47 <date>2009-10-25</date>
35 <authorinitials>mcc</authorinitials> 48 <authorinitials>mcc</authorinitials>
@@ -63,7 +76,7 @@ Added ISDB-T test originally written by Patrick Boettcher
63 76
64 77
65<title>LINUX DVB API</title> 78<title>LINUX DVB API</title>
66<subtitle>Version 3</subtitle> 79<subtitle>Version 5.2</subtitle>
67<!-- ADD THE CHAPTERS HERE --> 80<!-- ADD THE CHAPTERS HERE -->
68 <chapter id="dvb_introdution"> 81 <chapter id="dvb_introdution">
69 &sub-intro; 82 &sub-intro;
diff --git a/Documentation/DocBook/dvb/frontend.h.xml b/Documentation/DocBook/dvb/frontend.h.xml
index b99644f5340a..d08e0d401418 100644
--- a/Documentation/DocBook/dvb/frontend.h.xml
+++ b/Documentation/DocBook/dvb/frontend.h.xml
@@ -63,6 +63,7 @@ typedef enum fe_caps {
63 FE_CAN_8VSB = 0x200000, 63 FE_CAN_8VSB = 0x200000,
64 FE_CAN_16VSB = 0x400000, 64 FE_CAN_16VSB = 0x400000,
65 FE_HAS_EXTENDED_CAPS = 0x800000, /* We need more bitspace for newer APIs, indicate this. */ 65 FE_HAS_EXTENDED_CAPS = 0x800000, /* We need more bitspace for newer APIs, indicate this. */
66 FE_CAN_TURBO_FEC = 0x8000000, /* frontend supports "turbo fec modulation" */
66 FE_CAN_2G_MODULATION = 0x10000000, /* frontend supports "2nd generation modulation" (DVB-S2) */ 67 FE_CAN_2G_MODULATION = 0x10000000, /* frontend supports "2nd generation modulation" (DVB-S2) */
67 FE_NEEDS_BENDING = 0x20000000, /* not supported anymore, don't use (frontend requires frequency bending) */ 68 FE_NEEDS_BENDING = 0x20000000, /* not supported anymore, don't use (frontend requires frequency bending) */
68 FE_CAN_RECOVER = 0x40000000, /* frontend can recover from a cable unplug automatically */ 69 FE_CAN_RECOVER = 0x40000000, /* frontend can recover from a cable unplug automatically */
diff --git a/Documentation/DocBook/dvb/frontend.xml b/Documentation/DocBook/dvb/frontend.xml
index 300ba1f04177..78d756de5906 100644
--- a/Documentation/DocBook/dvb/frontend.xml
+++ b/Documentation/DocBook/dvb/frontend.xml
@@ -64,8 +64,14 @@ a specific frontend type.</para>
64 FE_CAN_BANDWIDTH_AUTO = 0x40000, 64 FE_CAN_BANDWIDTH_AUTO = 0x40000,
65 FE_CAN_GUARD_INTERVAL_AUTO = 0x80000, 65 FE_CAN_GUARD_INTERVAL_AUTO = 0x80000,
66 FE_CAN_HIERARCHY_AUTO = 0x100000, 66 FE_CAN_HIERARCHY_AUTO = 0x100000,
67 FE_CAN_MUTE_TS = 0x80000000, 67 FE_CAN_8VSB = 0x200000,
68 FE_CAN_CLEAN_SETUP = 0x40000000 68 FE_CAN_16VSB = 0x400000,
69 FE_HAS_EXTENDED_CAPS = 0x800000,
70 FE_CAN_TURBO_FEC = 0x8000000,
71 FE_CAN_2G_MODULATION = 0x10000000,
72 FE_NEEDS_BENDING = 0x20000000,
73 FE_CAN_RECOVER = 0x40000000,
74 FE_CAN_MUTE_TS = 0x80000000
69 } fe_caps_t; 75 } fe_caps_t;
70</programlisting> 76</programlisting>
71</section> 77</section>
diff --git a/Documentation/DocBook/media-entities.tmpl b/Documentation/DocBook/media-entities.tmpl
index 5d4d40f429a5..6ae97157b1c7 100644
--- a/Documentation/DocBook/media-entities.tmpl
+++ b/Documentation/DocBook/media-entities.tmpl
@@ -218,6 +218,7 @@
218<!ENTITY sub-dev-teletext SYSTEM "v4l/dev-teletext.xml"> 218<!ENTITY sub-dev-teletext SYSTEM "v4l/dev-teletext.xml">
219<!ENTITY sub-driver SYSTEM "v4l/driver.xml"> 219<!ENTITY sub-driver SYSTEM "v4l/driver.xml">
220<!ENTITY sub-libv4l SYSTEM "v4l/libv4l.xml"> 220<!ENTITY sub-libv4l SYSTEM "v4l/libv4l.xml">
221<!ENTITY sub-lirc_device_interface SYSTEM "v4l/lirc_device_interface.xml">
221<!ENTITY sub-remote_controllers SYSTEM "v4l/remote_controllers.xml"> 222<!ENTITY sub-remote_controllers SYSTEM "v4l/remote_controllers.xml">
222<!ENTITY sub-fdl-appendix SYSTEM "v4l/fdl-appendix.xml"> 223<!ENTITY sub-fdl-appendix SYSTEM "v4l/fdl-appendix.xml">
223<!ENTITY sub-close SYSTEM "v4l/func-close.xml"> 224<!ENTITY sub-close SYSTEM "v4l/func-close.xml">
diff --git a/Documentation/DocBook/media.tmpl b/Documentation/DocBook/media.tmpl
index eea564bb12cb..f11048d4053f 100644
--- a/Documentation/DocBook/media.tmpl
+++ b/Documentation/DocBook/media.tmpl
@@ -28,7 +28,7 @@
28<title>LINUX MEDIA INFRASTRUCTURE API</title> 28<title>LINUX MEDIA INFRASTRUCTURE API</title>
29 29
30<copyright> 30<copyright>
31 <year>2009</year> 31 <year>2009-2010</year>
32 <holder>LinuxTV Developers</holder> 32 <holder>LinuxTV Developers</holder>
33</copyright> 33</copyright>
34 34
@@ -61,7 +61,7 @@ Foundation. A copy of the license is included in the chapter entitled
61 in fact it covers several different video standards including 61 in fact it covers several different video standards including
62 DVB-T, DVB-S, DVB-C and ATSC. The API is currently being updated 62 DVB-T, DVB-S, DVB-C and ATSC. The API is currently being updated
63 to documment support also for DVB-S2, ISDB-T and ISDB-S.</para> 63 to documment support also for DVB-S2, ISDB-T and ISDB-S.</para>
64 <para>The third part covers other API's used by all media infrastructure devices</para> 64 <para>The third part covers Remote Controller API</para>
65 <para>For additional information and for the latest development code, 65 <para>For additional information and for the latest development code,
66 see: <ulink url="http://linuxtv.org">http://linuxtv.org</ulink>.</para> 66 see: <ulink url="http://linuxtv.org">http://linuxtv.org</ulink>.</para>
67 <para>For discussing improvements, reporting troubles, sending new drivers, etc, please mail to: <ulink url="http://vger.kernel.org/vger-lists.html#linux-media">Linux Media Mailing List (LMML).</ulink>.</para> 67 <para>For discussing improvements, reporting troubles, sending new drivers, etc, please mail to: <ulink url="http://vger.kernel.org/vger-lists.html#linux-media">Linux Media Mailing List (LMML).</ulink>.</para>
@@ -86,7 +86,7 @@ Foundation. A copy of the license is included in the chapter entitled
86</author> 86</author>
87</authorgroup> 87</authorgroup>
88<copyright> 88<copyright>
89 <year>2009</year> 89 <year>2009-2010</year>
90 <holder>Mauro Carvalho Chehab</holder> 90 <holder>Mauro Carvalho Chehab</holder>
91</copyright> 91</copyright>
92 92
@@ -101,7 +101,7 @@ Foundation. A copy of the license is included in the chapter entitled
101</revhistory> 101</revhistory>
102</partinfo> 102</partinfo>
103 103
104<title>Other API's used by media infrastructure drivers</title> 104<title>Remote Controller API</title>
105<chapter id="remote_controllers"> 105<chapter id="remote_controllers">
106&sub-remote_controllers; 106&sub-remote_controllers;
107</chapter> 107</chapter>
diff --git a/Documentation/DocBook/v4l/lirc_device_interface.xml b/Documentation/DocBook/v4l/lirc_device_interface.xml
new file mode 100644
index 000000000000..0413234023d4
--- /dev/null
+++ b/Documentation/DocBook/v4l/lirc_device_interface.xml
@@ -0,0 +1,235 @@
1<section id="lirc_dev">
2<title>LIRC Device Interface</title>
3
4
5<section id="lirc_dev_intro">
6<title>Introduction</title>
7
8<para>The LIRC device interface is a bi-directional interface for
9transporting raw IR data between userspace and kernelspace. Fundamentally,
10it is just a chardev (/dev/lircX, for X = 0, 1, 2, ...), with a number
11of standard struct file_operations defined on it. With respect to
12transporting raw IR data to and fro, the essential fops are read, write
13and ioctl.</para>
14
15<para>Example dmesg output upon a driver registering w/LIRC:</para>
16 <blockquote>
17 <para>$ dmesg |grep lirc_dev</para>
18 <para>lirc_dev: IR Remote Control driver registered, major 248</para>
19 <para>rc rc0: lirc_dev: driver ir-lirc-codec (mceusb) registered at minor = 0</para>
20 </blockquote>
21
22<para>What you should see for a chardev:</para>
23 <blockquote>
24 <para>$ ls -l /dev/lirc*</para>
25 <para>crw-rw---- 1 root root 248, 0 Jul 2 22:20 /dev/lirc0</para>
26 </blockquote>
27</section>
28
29<section id="lirc_read">
30<title>LIRC read fop</title>
31
32<para>The lircd userspace daemon reads raw IR data from the LIRC chardev. The
33exact format of the data depends on what modes a driver supports, and what
34mode has been selected. lircd obtains supported modes and sets the active mode
35via the ioctl interface, detailed at <xref linkend="lirc_ioctl"/>. The generally
36preferred mode is LIRC_MODE_MODE2, in which packets containing an int value
37describing an IR signal are read from the chardev.</para>
38
39<para>See also <ulink url="http://www.lirc.org/html/technical.html">http://www.lirc.org/html/technical.html</ulink> for more info.</para>
40</section>
41
42<section id="lirc_write">
43<title>LIRC write fop</title>
44
45<para>The data written to the chardev is a pulse/space sequence of integer
46values. Pulses and spaces are only marked implicitly by their position. The
47data must start and end with a pulse, therefore, the data must always include
48an unevent number of samples. The write function must block until the data has
49been transmitted by the hardware.</para>
50</section>
51
52<section id="lirc_ioctl">
53<title>LIRC ioctl fop</title>
54
55<para>The LIRC device's ioctl definition is bound by the ioctl function
56definition of struct file_operations, leaving us with an unsigned int
57for the ioctl command and an unsigned long for the arg. For the purposes
58of ioctl portability across 32-bit and 64-bit, these values are capped
59to their 32-bit sizes.</para>
60
61<para>The following ioctls can be used to change specific hardware settings.
62In general each driver should have a default set of settings. The driver
63implementation is expected to re-apply the default settings when the device
64is closed by user-space, so that every application opening the device can rely
65on working with the default settings initially.</para>
66
67<variablelist>
68 <varlistentry>
69 <term>LIRC_GET_FEATURES</term>
70 <listitem>
71 <para>Obviously, get the underlying hardware device's features. If a driver
72 does not announce support of certain features, calling of the corresponding
73 ioctls is undefined.</para>
74 </listitem>
75 </varlistentry>
76 <varlistentry>
77 <term>LIRC_GET_SEND_MODE</term>
78 <listitem>
79 <para>Get supported transmit mode. Only LIRC_MODE_PULSE is supported by lircd.</para>
80 </listitem>
81 </varlistentry>
82 <varlistentry>
83 <term>LIRC_GET_REC_MODE</term>
84 <listitem>
85 <para>Get supported receive modes. Only LIRC_MODE_MODE2 and LIRC_MODE_LIRCCODE
86 are supported by lircd.</para>
87 </listitem>
88 </varlistentry>
89 <varlistentry>
90 <term>LIRC_GET_SEND_CARRIER</term>
91 <listitem>
92 <para>Get carrier frequency (in Hz) currently used for transmit.</para>
93 </listitem>
94 </varlistentry>
95 <varlistentry>
96 <term>LIRC_GET_REC_CARRIER</term>
97 <listitem>
98 <para>Get carrier frequency (in Hz) currently used for IR reception.</para>
99 </listitem>
100 </varlistentry>
101 <varlistentry>
102 <term>LIRC_{G,S}ET_{SEND,REC}_DUTY_CYCLE</term>
103 <listitem>
104 <para>Get/set the duty cycle (from 0 to 100) of the carrier signal. Currently,
105 no special meaning is defined for 0 or 100, but this could be used to switch
106 off carrier generation in the future, so these values should be reserved.</para>
107 </listitem>
108 </varlistentry>
109 <varlistentry>
110 <term>LIRC_GET_REC_RESOLUTION</term>
111 <listitem>
112 <para>Some receiver have maximum resolution which is defined by internal
113 sample rate or data format limitations. E.g. it's common that signals can
114 only be reported in 50 microsecond steps. This integer value is used by
115 lircd to automatically adjust the aeps tolerance value in the lircd
116 config file.</para>
117 </listitem>
118 </varlistentry>
119 <varlistentry>
120 <term>LIRC_GET_M{IN,AX}_TIMEOUT</term>
121 <listitem>
122 <para>Some devices have internal timers that can be used to detect when
123 there's no IR activity for a long time. This can help lircd in detecting
124 that a IR signal is finished and can speed up the decoding process.
125 Returns an integer value with the minimum/maximum timeout that can be
126 set. Some devices have a fixed timeout, in that case both ioctls will
127 return the same value even though the timeout cannot be changed.</para>
128 </listitem>
129 </varlistentry>
130 <varlistentry>
131 <term>LIRC_GET_M{IN,AX}_FILTER_{PULSE,SPACE}</term>
132 <listitem>
133 <para>Some devices are able to filter out spikes in the incoming signal
134 using given filter rules. These ioctls return the hardware capabilities
135 that describe the bounds of the possible filters. Filter settings depend
136 on the IR protocols that are expected. lircd derives the settings from
137 all protocols definitions found in its config file.</para>
138 </listitem>
139 </varlistentry>
140 <varlistentry>
141 <term>LIRC_GET_LENGTH</term>
142 <listitem>
143 <para>Retrieves the code length in bits (only for LIRC_MODE_LIRCCODE).
144 Reads on the device must be done in blocks matching the bit count.
145 The bit could should be rounded up so that it matches full bytes.</para>
146 </listitem>
147 </varlistentry>
148 <varlistentry>
149 <term>LIRC_SET_{SEND,REC}_MODE</term>
150 <listitem>
151 <para>Set send/receive mode. Largely obsolete for send, as only
152 LIRC_MODE_PULSE is supported.</para>
153 </listitem>
154 </varlistentry>
155 <varlistentry>
156 <term>LIRC_SET_{SEND,REC}_CARRIER</term>
157 <listitem>
158 <para>Set send/receive carrier (in Hz).</para>
159 </listitem>
160 </varlistentry>
161 <varlistentry>
162 <term>LIRC_SET_TRANSMITTER_MASK</term>
163 <listitem>
164 <para>This enables the given set of transmitters. The first transmitter
165 is encoded by the least significant bit, etc. When an invalid bit mask
166 is given, i.e. a bit is set, even though the device does not have so many
167 transitters, then this ioctl returns the number of available transitters
168 and does nothing otherwise.</para>
169 </listitem>
170 </varlistentry>
171 <varlistentry>
172 <term>LIRC_SET_REC_TIMEOUT</term>
173 <listitem>
174 <para>Sets the integer value for IR inactivity timeout (cf.
175 LIRC_GET_MIN_TIMEOUT and LIRC_GET_MAX_TIMEOUT). A value of 0 (if
176 supported by the hardware) disables all hardware timeouts and data should
177 be reported as soon as possible. If the exact value cannot be set, then
178 the next possible value _greater_ than the given value should be set.</para>
179 </listitem>
180 </varlistentry>
181 <varlistentry>
182 <term>LIRC_SET_REC_TIMEOUT_REPORTS</term>
183 <listitem>
184 <para>Enable (1) or disable (0) timeout reports in LIRC_MODE_MODE2. By
185 default, timeout reports should be turned off.</para>
186 </listitem>
187 </varlistentry>
188 <varlistentry>
189 <term>LIRC_SET_REC_FILTER_{,PULSE,SPACE}</term>
190 <listitem>
191 <para>Pulses/spaces shorter than this are filtered out by hardware. If
192 filters cannot be set independently for pulse/space, the corresponding
193 ioctls must return an error and LIRC_SET_REC_FILTER shall be used instead.</para>
194 </listitem>
195 </varlistentry>
196 <varlistentry>
197 <term>LIRC_SET_MEASURE_CARRIER_MODE</term>
198 <listitem>
199 <para>Enable (1)/disable (0) measure mode. If enabled, from the next key
200 press on, the driver will send LIRC_MODE2_FREQUENCY packets. By default
201 this should be turned off.</para>
202 </listitem>
203 </varlistentry>
204 <varlistentry>
205 <term>LIRC_SET_REC_{DUTY_CYCLE,CARRIER}_RANGE</term>
206 <listitem>
207 <para>To set a range use LIRC_SET_REC_DUTY_CYCLE_RANGE/LIRC_SET_REC_CARRIER_RANGE
208 with the lower bound first and later LIRC_SET_REC_DUTY_CYCLE/LIRC_SET_REC_CARRIER
209 with the upper bound.</para>
210 </listitem>
211 </varlistentry>
212 <varlistentry>
213 <term>LIRC_NOTIFY_DECODE</term>
214 <listitem>
215 <para>This ioctl is called by lircd whenever a successful decoding of an
216 incoming IR signal could be done. This can be used by supporting hardware
217 to give visual feedback to the user e.g. by flashing a LED.</para>
218 </listitem>
219 </varlistentry>
220 <varlistentry>
221 <term>LIRC_SETUP_{START,END}</term>
222 <listitem>
223 <para>Setting of several driver parameters can be optimized by encapsulating
224 the according ioctl calls with LIRC_SETUP_START/LIRC_SETUP_END. When a
225 driver receives a LIRC_SETUP_START ioctl it can choose to not commit
226 further setting changes to the hardware until a LIRC_SETUP_END is received.
227 But this is open to the driver implementation and every driver must also
228 handle parameter changes which are not encapsulated by LIRC_SETUP_START
229 and LIRC_SETUP_END. Drivers can also choose to ignore these ioctls.</para>
230 </listitem>
231 </varlistentry>
232</variablelist>
233
234</section>
235</section>
diff --git a/Documentation/DocBook/v4l/remote_controllers.xml b/Documentation/DocBook/v4l/remote_controllers.xml
index 73f5eab091f4..3c3b667b28e7 100644
--- a/Documentation/DocBook/v4l/remote_controllers.xml
+++ b/Documentation/DocBook/v4l/remote_controllers.xml
@@ -173,3 +173,5 @@ keymapping.</para>
173<para>This program demonstrates how to replace the keymap tables.</para> 173<para>This program demonstrates how to replace the keymap tables.</para>
174&sub-keytable-c; 174&sub-keytable-c;
175</section> 175</section>
176
177&sub-lirc_device_interface;
diff --git a/Documentation/dvb/get_dvb_firmware b/Documentation/dvb/get_dvb_firmware
index 239cbdbf4d12..350959f4e41b 100644
--- a/Documentation/dvb/get_dvb_firmware
+++ b/Documentation/dvb/get_dvb_firmware
@@ -26,7 +26,7 @@ use IO::Handle;
26 "dec3000s", "vp7041", "dibusb", "nxt2002", "nxt2004", 26 "dec3000s", "vp7041", "dibusb", "nxt2002", "nxt2004",
27 "or51211", "or51132_qam", "or51132_vsb", "bluebird", 27 "or51211", "or51132_qam", "or51132_vsb", "bluebird",
28 "opera1", "cx231xx", "cx18", "cx23885", "pvrusb2", "mpc718", 28 "opera1", "cx231xx", "cx18", "cx23885", "pvrusb2", "mpc718",
29 "af9015", "ngene"); 29 "af9015", "ngene", "az6027");
30 30
31# Check args 31# Check args
32syntax() if (scalar(@ARGV) != 1); 32syntax() if (scalar(@ARGV) != 1);
@@ -518,11 +518,11 @@ sub bluebird {
518sub af9015 { 518sub af9015 {
519 my $sourcefile = "download.ashx?file=57"; 519 my $sourcefile = "download.ashx?file=57";
520 my $url = "http://www.ite.com.tw/EN/Services/$sourcefile"; 520 my $url = "http://www.ite.com.tw/EN/Services/$sourcefile";
521 my $hash = "ff5b096ed47c080870eacdab2de33ad6"; 521 my $hash = "e3f08935158038d385ad382442f4bb2d";
522 my $outfile = "dvb-usb-af9015.fw"; 522 my $outfile = "dvb-usb-af9015.fw";
523 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1); 523 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 1);
524 my $fwoffset = 0x22708; 524 my $fwoffset = 0x25690;
525 my $fwlength = 18225; 525 my $fwlength = 18725;
526 my ($chunklength, $buf, $rcount); 526 my ($chunklength, $buf, $rcount);
527 527
528 checkstandard(); 528 checkstandard();
@@ -567,6 +567,23 @@ sub ngene {
567 "$file1, $file2"; 567 "$file1, $file2";
568} 568}
569 569
570sub az6027{
571 my $file = "AZ6027_Linux_Driver.tar.gz";
572 my $url = "http://linux.terratec.de/files/$file";
573 my $firmware = "dvb-usb-az6027-03.fw";
574
575 wgetfile($file, $url);
576
577 #untar
578 if( system("tar xzvf $file $firmware")){
579 die "failed to untar firmware";
580 }
581 if( system("rm $file")){
582 die ("unable to remove unnecessary files");
583 }
584
585 $firmware;
586}
570# --------------------------------------------------------------- 587# ---------------------------------------------------------------
571# Utilities 588# Utilities
572 589
diff --git a/Documentation/feature-removal-schedule.txt b/Documentation/feature-removal-schedule.txt
index 1571c0c83dba..79cb554761af 100644
--- a/Documentation/feature-removal-schedule.txt
+++ b/Documentation/feature-removal-schedule.txt
@@ -459,57 +459,6 @@ Who: Corentin Chary <corentin.chary@gmail.com>
459 459
460---------------------------- 460----------------------------
461 461
462What: usbvideo quickcam_messenger driver
463When: 2.6.35
464Files: drivers/media/video/usbvideo/quickcam_messenger.[ch]
465Why: obsolete v4l1 driver replaced by gspca_stv06xx
466Who: Hans de Goede <hdegoede@redhat.com>
467
468----------------------------
469
470What: ov511 v4l1 driver
471When: 2.6.35
472Files: drivers/media/video/ov511.[ch]
473Why: obsolete v4l1 driver replaced by gspca_ov519
474Who: Hans de Goede <hdegoede@redhat.com>
475
476----------------------------
477
478What: w9968cf v4l1 driver
479When: 2.6.35
480Files: drivers/media/video/w9968cf*.[ch]
481Why: obsolete v4l1 driver replaced by gspca_ov519
482Who: Hans de Goede <hdegoede@redhat.com>
483
484----------------------------
485
486What: ovcamchip sensor framework
487When: 2.6.35
488Files: drivers/media/video/ovcamchip/*
489Why: Only used by obsoleted v4l1 drivers
490Who: Hans de Goede <hdegoede@redhat.com>
491
492----------------------------
493
494What: stv680 v4l1 driver
495When: 2.6.35
496Files: drivers/media/video/stv680.[ch]
497Why: obsolete v4l1 driver replaced by gspca_stv0680
498Who: Hans de Goede <hdegoede@redhat.com>
499
500----------------------------
501
502What: zc0301 v4l driver
503When: 2.6.35
504Files: drivers/media/video/zc0301/*
505Why: Duplicate functionality with the gspca_zc3xx driver, zc0301 only
506 supports 2 USB-ID's (because it only supports a limited set of
507 sensors) wich are also supported by the gspca_zc3xx driver
508 (which supports 53 USB-ID's in total)
509Who: Hans de Goede <hdegoede@redhat.com>
510
511----------------------------
512
513What: sysfs-class-rfkill state file 462What: sysfs-class-rfkill state file
514When: Feb 2014 463When: Feb 2014
515Files: net/rfkill/core.c 464Files: net/rfkill/core.c
diff --git a/Documentation/video4linux/CARDLIST.cx23885 b/Documentation/video4linux/CARDLIST.cx23885
index 16ca030e1185..87c46347bd63 100644
--- a/Documentation/video4linux/CARDLIST.cx23885
+++ b/Documentation/video4linux/CARDLIST.cx23885
@@ -17,9 +17,9 @@
17 16 -> DVBWorld DVB-S2 2005 [0001:2005] 17 16 -> DVBWorld DVB-S2 2005 [0001:2005]
18 17 -> NetUP Dual DVB-S2 CI [1b55:2a2c] 18 17 -> NetUP Dual DVB-S2 CI [1b55:2a2c]
19 18 -> Hauppauge WinTV-HVR1270 [0070:2211] 19 18 -> Hauppauge WinTV-HVR1270 [0070:2211]
20 19 -> Hauppauge WinTV-HVR1275 [0070:2215] 20 19 -> Hauppauge WinTV-HVR1275 [0070:2215,0070:221d,0070:22f2]
21 20 -> Hauppauge WinTV-HVR1255 [0070:2251] 21 20 -> Hauppauge WinTV-HVR1255 [0070:2251,0070:2259,0070:22f1]
22 21 -> Hauppauge WinTV-HVR1210 [0070:2291,0070:2295] 22 21 -> Hauppauge WinTV-HVR1210 [0070:2291,0070:2295,0070:2299,0070:229d,0070:22f0,0070:22f3,0070:22f4,0070:22f5]
23 22 -> Mygica X8506 DMB-TH [14f1:8651] 23 22 -> Mygica X8506 DMB-TH [14f1:8651]
24 23 -> Magic-Pro ProHDTV Extreme 2 [14f1:8657] 24 23 -> Magic-Pro ProHDTV Extreme 2 [14f1:8657]
25 24 -> Hauppauge WinTV-HVR1850 [0070:8541] 25 24 -> Hauppauge WinTV-HVR1850 [0070:8541]
diff --git a/Documentation/video4linux/CARDLIST.em28xx b/Documentation/video4linux/CARDLIST.em28xx
index 3a623aaeae5f..5c568757c301 100644
--- a/Documentation/video4linux/CARDLIST.em28xx
+++ b/Documentation/video4linux/CARDLIST.em28xx
@@ -72,3 +72,4 @@
72 73 -> Reddo DVB-C USB TV Box (em2870) 72 73 -> Reddo DVB-C USB TV Box (em2870)
73 74 -> Actionmaster/LinXcel/Digitus VC211A (em2800) 73 74 -> Actionmaster/LinXcel/Digitus VC211A (em2800)
74 75 -> Dikom DK300 (em2882) 74 75 -> Dikom DK300 (em2882)
75 76 -> KWorld PlusTV 340U or UB435-Q (ATSC) (em2870) [1b80:a340]
diff --git a/Documentation/video4linux/CARDLIST.saa7134 b/Documentation/video4linux/CARDLIST.saa7134
index 1387a69ae3aa..4000c29fcfb6 100644
--- a/Documentation/video4linux/CARDLIST.saa7134
+++ b/Documentation/video4linux/CARDLIST.saa7134
@@ -178,4 +178,5 @@
178177 -> Hawell HW-404M7 178177 -> Hawell HW-404M7
179178 -> Beholder BeholdTV H7 [5ace:7190] 179178 -> Beholder BeholdTV H7 [5ace:7190]
180179 -> Beholder BeholdTV A7 [5ace:7090] 180179 -> Beholder BeholdTV A7 [5ace:7090]
181180 -> Avermedia M733A [1461:4155,1461:4255] 181180 -> Avermedia PCI M733A [1461:4155,1461:4255]
182181 -> TechoTrend TT-budget T-3000 [13c2:2804]
diff --git a/Documentation/video4linux/gspca.txt b/Documentation/video4linux/gspca.txt
index f13eb036c439..56ba7bba7168 100644
--- a/Documentation/video4linux/gspca.txt
+++ b/Documentation/video4linux/gspca.txt
@@ -29,8 +29,12 @@ zc3xx 041e:4029 Creative WebCam Vista Pro
29zc3xx 041e:4034 Creative Instant P0620 29zc3xx 041e:4034 Creative Instant P0620
30zc3xx 041e:4035 Creative Instant P0620D 30zc3xx 041e:4035 Creative Instant P0620D
31zc3xx 041e:4036 Creative Live ! 31zc3xx 041e:4036 Creative Live !
32sq930x 041e:4038 Creative Joy-IT
32zc3xx 041e:403a Creative Nx Pro 2 33zc3xx 041e:403a Creative Nx Pro 2
33spca561 041e:403b Creative Webcam Vista (VF0010) 34spca561 041e:403b Creative Webcam Vista (VF0010)
35sq930x 041e:403c Creative Live! Ultra
36sq930x 041e:403d Creative Live! Ultra for Notebooks
37sq930x 041e:4041 Creative Live! Motion
34zc3xx 041e:4051 Creative Live!Cam Notebook Pro (VF0250) 38zc3xx 041e:4051 Creative Live!Cam Notebook Pro (VF0250)
35ov519 041e:4052 Creative Live! VISTA IM 39ov519 041e:4052 Creative Live! VISTA IM
36zc3xx 041e:4053 Creative Live!Cam Video IM 40zc3xx 041e:4053 Creative Live!Cam Video IM
@@ -138,6 +142,7 @@ finepix 04cb:013d Fujifilm FinePix unknown model
138finepix 04cb:013f Fujifilm FinePix F420 142finepix 04cb:013f Fujifilm FinePix F420
139sunplus 04f1:1001 JVC GC A50 143sunplus 04f1:1001 JVC GC A50
140spca561 04fc:0561 Flexcam 100 144spca561 04fc:0561 Flexcam 100
145spca1528 04fc:1528 Sunplus MD80 clone
141sunplus 04fc:500c Sunplus CA500C 146sunplus 04fc:500c Sunplus CA500C
142sunplus 04fc:504a Aiptek Mini PenCam 1.3 147sunplus 04fc:504a Aiptek Mini PenCam 1.3
143sunplus 04fc:504b Maxell MaxPocket LE 1.3 148sunplus 04fc:504b Maxell MaxPocket LE 1.3
@@ -253,6 +258,7 @@ pac7302 093a:2620 Apollo AC-905
253pac7302 093a:2621 PAC731x 258pac7302 093a:2621 PAC731x
254pac7302 093a:2622 Genius Eye 312 259pac7302 093a:2622 Genius Eye 312
255pac7302 093a:2624 PAC7302 260pac7302 093a:2624 PAC7302
261pac7302 093a:2625 Genius iSlim 310
256pac7302 093a:2626 Labtec 2200 262pac7302 093a:2626 Labtec 2200
257pac7302 093a:2628 Genius iLook 300 263pac7302 093a:2628 Genius iLook 300
258pac7302 093a:2629 Genious iSlim 300 264pac7302 093a:2629 Genious iSlim 300
@@ -362,6 +368,8 @@ sq905c 2770:9052 Disney pix micro 2 (VGA)
362sq905c 2770:905c All 11 known cameras with this ID 368sq905c 2770:905c All 11 known cameras with this ID
363sq905 2770:9120 All 24 known cameras with this ID 369sq905 2770:9120 All 24 known cameras with this ID
364sq905c 2770:913d All 4 known cameras with this ID 370sq905c 2770:913d All 4 known cameras with this ID
371sq930x 2770:930b Sweex Motion Tracking / I-Tec iCam Tracer
372sq930x 2770:930c Trust WB-3500T / NSG Robbie 2.0
365spca500 2899:012c Toptro Industrial 373spca500 2899:012c Toptro Industrial
366ov519 8020:ef04 ov519 374ov519 8020:ef04 ov519
367spca508 8086:0110 Intel Easy PC Camera 375spca508 8086:0110 Intel Easy PC Camera
diff --git a/arch/sh/boards/mach-ap325rxa/setup.c b/arch/sh/boards/mach-ap325rxa/setup.c
index 3a170bd3f3d0..de375b64e410 100644
--- a/arch/sh/boards/mach-ap325rxa/setup.c
+++ b/arch/sh/boards/mach-ap325rxa/setup.c
@@ -316,7 +316,7 @@ static struct soc_camera_platform_info camera_info = {
316 .format_name = "UYVY", 316 .format_name = "UYVY",
317 .format_depth = 16, 317 .format_depth = 16,
318 .format = { 318 .format = {
319 .code = V4L2_MBUS_FMT_YUYV8_2X8_BE, 319 .code = V4L2_MBUS_FMT_UYVY8_2X8,
320 .colorspace = V4L2_COLORSPACE_SMPTE170M, 320 .colorspace = V4L2_COLORSPACE_SMPTE170M,
321 .field = V4L2_FIELD_NONE, 321 .field = V4L2_FIELD_NONE,
322 .width = 640, 322 .width = 640,
diff --git a/drivers/media/IR/Kconfig b/drivers/media/IR/Kconfig
index d22a8ec523fc..999a8250b3ce 100644
--- a/drivers/media/IR/Kconfig
+++ b/drivers/media/IR/Kconfig
@@ -8,6 +8,17 @@ config VIDEO_IR
8 depends on IR_CORE 8 depends on IR_CORE
9 default IR_CORE 9 default IR_CORE
10 10
11config LIRC
12 tristate
13 default y
14
15 ---help---
16 Enable this option to build the Linux Infrared Remote
17 Control (LIRC) core device interface driver. The LIRC
18 interface passes raw IR to and from userspace, where the
19 LIRC daemon handles protocol decoding for IR reception ann
20 encoding for IR transmitting (aka "blasting").
21
11source "drivers/media/IR/keymaps/Kconfig" 22source "drivers/media/IR/keymaps/Kconfig"
12 23
13config IR_NEC_DECODER 24config IR_NEC_DECODER
@@ -33,6 +44,7 @@ config IR_RC5_DECODER
33config IR_RC6_DECODER 44config IR_RC6_DECODER
34 tristate "Enable IR raw decoder for the RC6 protocol" 45 tristate "Enable IR raw decoder for the RC6 protocol"
35 depends on IR_CORE 46 depends on IR_CORE
47 select BITREVERSE
36 default y 48 default y
37 49
38 ---help--- 50 ---help---
@@ -42,6 +54,7 @@ config IR_RC6_DECODER
42config IR_JVC_DECODER 54config IR_JVC_DECODER
43 tristate "Enable IR raw decoder for the JVC protocol" 55 tristate "Enable IR raw decoder for the JVC protocol"
44 depends on IR_CORE 56 depends on IR_CORE
57 select BITREVERSE
45 default y 58 default y
46 59
47 ---help--- 60 ---help---
@@ -57,6 +70,16 @@ config IR_SONY_DECODER
57 Enable this option if you have an infrared remote control which 70 Enable this option if you have an infrared remote control which
58 uses the Sony protocol, and you need software decoding support. 71 uses the Sony protocol, and you need software decoding support.
59 72
73config IR_LIRC_CODEC
74 tristate "Enable IR to LIRC bridge"
75 depends on IR_CORE
76 depends on LIRC
77 default y
78
79 ---help---
80 Enable this option to pass raw IR to and from userspace via
81 the LIRC interface.
82
60config IR_IMON 83config IR_IMON
61 tristate "SoundGraph iMON Receiver and Display" 84 tristate "SoundGraph iMON Receiver and Display"
62 depends on USB_ARCH_HAS_HCD 85 depends on USB_ARCH_HAS_HCD
@@ -68,3 +91,15 @@ config IR_IMON
68 91
69 To compile this driver as a module, choose M here: the 92 To compile this driver as a module, choose M here: the
70 module will be called imon. 93 module will be called imon.
94
95config IR_MCEUSB
96 tristate "Windows Media Center Ed. eHome Infrared Transceiver"
97 depends on USB_ARCH_HAS_HCD
98 depends on IR_CORE
99 select USB
100 ---help---
101 Say Y here if you want to use a Windows Media Center Edition
102 eHome Infrared Transceiver.
103
104 To compile this driver as a module, choose M here: the
105 module will be called mceusb.
diff --git a/drivers/media/IR/Makefile b/drivers/media/IR/Makefile
index b998fcced2e4..2ae4f3abfdbd 100644
--- a/drivers/media/IR/Makefile
+++ b/drivers/media/IR/Makefile
@@ -5,11 +5,14 @@ obj-y += keymaps/
5 5
6obj-$(CONFIG_IR_CORE) += ir-core.o 6obj-$(CONFIG_IR_CORE) += ir-core.o
7obj-$(CONFIG_VIDEO_IR) += ir-common.o 7obj-$(CONFIG_VIDEO_IR) += ir-common.o
8obj-$(CONFIG_LIRC) += lirc_dev.o
8obj-$(CONFIG_IR_NEC_DECODER) += ir-nec-decoder.o 9obj-$(CONFIG_IR_NEC_DECODER) += ir-nec-decoder.o
9obj-$(CONFIG_IR_RC5_DECODER) += ir-rc5-decoder.o 10obj-$(CONFIG_IR_RC5_DECODER) += ir-rc5-decoder.o
10obj-$(CONFIG_IR_RC6_DECODER) += ir-rc6-decoder.o 11obj-$(CONFIG_IR_RC6_DECODER) += ir-rc6-decoder.o
11obj-$(CONFIG_IR_JVC_DECODER) += ir-jvc-decoder.o 12obj-$(CONFIG_IR_JVC_DECODER) += ir-jvc-decoder.o
12obj-$(CONFIG_IR_SONY_DECODER) += ir-sony-decoder.o 13obj-$(CONFIG_IR_SONY_DECODER) += ir-sony-decoder.o
14obj-$(CONFIG_IR_LIRC_CODEC) += ir-lirc-codec.o
13 15
14# stand-alone IR receivers/transmitters 16# stand-alone IR receivers/transmitters
15obj-$(CONFIG_IR_IMON) += imon.o 17obj-$(CONFIG_IR_IMON) += imon.o
18obj-$(CONFIG_IR_MCEUSB) += mceusb.o
diff --git a/drivers/media/IR/imon.c b/drivers/media/IR/imon.c
index 4bbd45f4284c..65c125e44e96 100644
--- a/drivers/media/IR/imon.c
+++ b/drivers/media/IR/imon.c
@@ -407,7 +407,7 @@ static int display_close(struct inode *inode, struct file *file)
407 struct imon_context *ictx = NULL; 407 struct imon_context *ictx = NULL;
408 int retval = 0; 408 int retval = 0;
409 409
410 ictx = (struct imon_context *)file->private_data; 410 ictx = file->private_data;
411 411
412 if (!ictx) { 412 if (!ictx) {
413 err("%s: no context for device", __func__); 413 err("%s: no context for device", __func__);
@@ -812,7 +812,7 @@ static ssize_t vfd_write(struct file *file, const char *buf,
812 const unsigned char vfd_packet6[] = { 812 const unsigned char vfd_packet6[] = {
813 0x01, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF }; 813 0x01, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF };
814 814
815 ictx = (struct imon_context *)file->private_data; 815 ictx = file->private_data;
816 if (!ictx) { 816 if (!ictx) {
817 err("%s: no context for device", __func__); 817 err("%s: no context for device", __func__);
818 return -ENODEV; 818 return -ENODEV;
@@ -896,7 +896,7 @@ static ssize_t lcd_write(struct file *file, const char *buf,
896 int retval = 0; 896 int retval = 0;
897 struct imon_context *ictx; 897 struct imon_context *ictx;
898 898
899 ictx = (struct imon_context *)file->private_data; 899 ictx = file->private_data;
900 if (!ictx) { 900 if (!ictx) {
901 err("%s: no context for device", __func__); 901 err("%s: no context for device", __func__);
902 return -ENODEV; 902 return -ENODEV;
@@ -1943,7 +1943,7 @@ static struct imon_context *imon_init_intf0(struct usb_interface *intf)
1943 return ictx; 1943 return ictx;
1944 1944
1945urb_submit_failed: 1945urb_submit_failed:
1946 input_unregister_device(ictx->idev); 1946 ir_input_unregister(ictx->idev);
1947 input_free_device(ictx->idev); 1947 input_free_device(ictx->idev);
1948idev_setup_failed: 1948idev_setup_failed:
1949find_endpoint_failed: 1949find_endpoint_failed:
@@ -2067,6 +2067,7 @@ static void imon_get_ffdc_type(struct imon_context *ictx)
2067 detected_display_type = IMON_DISPLAY_TYPE_VFD; 2067 detected_display_type = IMON_DISPLAY_TYPE_VFD;
2068 break; 2068 break;
2069 /* iMON LCD, MCE IR */ 2069 /* iMON LCD, MCE IR */
2070 case 0x9e:
2070 case 0x9f: 2071 case 0x9f:
2071 dev_info(ictx->dev, "0xffdc iMON LCD, MCE IR"); 2072 dev_info(ictx->dev, "0xffdc iMON LCD, MCE IR");
2072 detected_display_type = IMON_DISPLAY_TYPE_LCD; 2073 detected_display_type = IMON_DISPLAY_TYPE_LCD;
@@ -2306,7 +2307,7 @@ static void __devexit imon_disconnect(struct usb_interface *interface)
2306 if (ifnum == 0) { 2307 if (ifnum == 0) {
2307 ictx->dev_present_intf0 = false; 2308 ictx->dev_present_intf0 = false;
2308 usb_kill_urb(ictx->rx_urb_intf0); 2309 usb_kill_urb(ictx->rx_urb_intf0);
2309 input_unregister_device(ictx->idev); 2310 ir_input_unregister(ictx->idev);
2310 if (ictx->display_supported) { 2311 if (ictx->display_supported) {
2311 if (ictx->display_type == IMON_DISPLAY_TYPE_LCD) 2312 if (ictx->display_type == IMON_DISPLAY_TYPE_LCD)
2312 usb_deregister_dev(interface, &imon_lcd_class); 2313 usb_deregister_dev(interface, &imon_lcd_class);
diff --git a/drivers/media/IR/ir-core-priv.h b/drivers/media/IR/ir-core-priv.h
index 9a5e65a471a5..babd52061bc3 100644
--- a/drivers/media/IR/ir-core-priv.h
+++ b/drivers/media/IR/ir-core-priv.h
@@ -22,17 +22,62 @@
22struct ir_raw_handler { 22struct ir_raw_handler {
23 struct list_head list; 23 struct list_head list;
24 24
25 u64 protocols; /* which are handled by this handler */
25 int (*decode)(struct input_dev *input_dev, struct ir_raw_event event); 26 int (*decode)(struct input_dev *input_dev, struct ir_raw_event event);
27
28 /* These two should only be used by the lirc decoder */
26 int (*raw_register)(struct input_dev *input_dev); 29 int (*raw_register)(struct input_dev *input_dev);
27 int (*raw_unregister)(struct input_dev *input_dev); 30 int (*raw_unregister)(struct input_dev *input_dev);
28}; 31};
29 32
30struct ir_raw_event_ctrl { 33struct ir_raw_event_ctrl {
34 struct list_head list; /* to keep track of raw clients */
31 struct work_struct rx_work; /* for the rx decoding workqueue */ 35 struct work_struct rx_work; /* for the rx decoding workqueue */
32 struct kfifo kfifo; /* fifo for the pulse/space durations */ 36 struct kfifo kfifo; /* fifo for the pulse/space durations */
33 ktime_t last_event; /* when last event occurred */ 37 ktime_t last_event; /* when last event occurred */
34 enum raw_event_type last_type; /* last event type */ 38 enum raw_event_type last_type; /* last event type */
35 struct input_dev *input_dev; /* pointer to the parent input_dev */ 39 struct input_dev *input_dev; /* pointer to the parent input_dev */
40 u64 enabled_protocols; /* enabled raw protocol decoders */
41
42 /* raw decoder state follows */
43 struct ir_raw_event prev_ev;
44 struct nec_dec {
45 int state;
46 unsigned count;
47 u32 bits;
48 } nec;
49 struct rc5_dec {
50 int state;
51 u32 bits;
52 unsigned count;
53 unsigned wanted_bits;
54 } rc5;
55 struct rc6_dec {
56 int state;
57 u8 header;
58 u32 body;
59 bool toggle;
60 unsigned count;
61 unsigned wanted_bits;
62 } rc6;
63 struct sony_dec {
64 int state;
65 u32 bits;
66 unsigned count;
67 } sony;
68 struct jvc_dec {
69 int state;
70 u16 bits;
71 u16 old_bits;
72 unsigned count;
73 bool first;
74 bool toggle;
75 } jvc;
76 struct lirc_codec {
77 struct ir_input_dev *ir_dev;
78 struct lirc_driver *drv;
79 int lircdata;
80 } lirc;
36}; 81};
37 82
38/* macros for IR decoders */ 83/* macros for IR decoders */
@@ -74,6 +119,7 @@ void ir_unregister_class(struct input_dev *input_dev);
74/* 119/*
75 * Routines from ir-raw-event.c to be used internally and by decoders 120 * Routines from ir-raw-event.c to be used internally and by decoders
76 */ 121 */
122u64 ir_raw_get_allowed_protocols(void);
77int ir_raw_event_register(struct input_dev *input_dev); 123int ir_raw_event_register(struct input_dev *input_dev);
78void ir_raw_event_unregister(struct input_dev *input_dev); 124void ir_raw_event_unregister(struct input_dev *input_dev);
79int ir_raw_handler_register(struct ir_raw_handler *ir_raw_handler); 125int ir_raw_handler_register(struct ir_raw_handler *ir_raw_handler);
@@ -123,4 +169,12 @@ void ir_raw_init(void);
123#define load_sony_decode() 0 169#define load_sony_decode() 0
124#endif 170#endif
125 171
172/* from ir-lirc-codec.c */
173#ifdef CONFIG_IR_LIRC_CODEC_MODULE
174#define load_lirc_codec() request_module("ir-lirc-codec")
175#else
176#define load_lirc_codec() 0
177#endif
178
179
126#endif /* _IR_RAW_EVENT */ 180#endif /* _IR_RAW_EVENT */
diff --git a/drivers/media/IR/ir-jvc-decoder.c b/drivers/media/IR/ir-jvc-decoder.c
index 0b804944cbb0..8894d8b36048 100644
--- a/drivers/media/IR/ir-jvc-decoder.c
+++ b/drivers/media/IR/ir-jvc-decoder.c
@@ -25,10 +25,6 @@
25#define JVC_TRAILER_PULSE (1 * JVC_UNIT) 25#define JVC_TRAILER_PULSE (1 * JVC_UNIT)
26#define JVC_TRAILER_SPACE (35 * JVC_UNIT) 26#define JVC_TRAILER_SPACE (35 * JVC_UNIT)
27 27
28/* Used to register jvc_decoder clients */
29static LIST_HEAD(decoder_list);
30DEFINE_SPINLOCK(decoder_lock);
31
32enum jvc_state { 28enum jvc_state {
33 STATE_INACTIVE, 29 STATE_INACTIVE,
34 STATE_HEADER_SPACE, 30 STATE_HEADER_SPACE,
@@ -38,87 +34,6 @@ enum jvc_state {
38 STATE_TRAILER_SPACE, 34 STATE_TRAILER_SPACE,
39}; 35};
40 36
41struct decoder_data {
42 struct list_head list;
43 struct ir_input_dev *ir_dev;
44 int enabled:1;
45
46 /* State machine control */
47 enum jvc_state state;
48 u16 jvc_bits;
49 u16 jvc_old_bits;
50 unsigned count;
51 bool first;
52 bool toggle;
53};
54
55
56/**
57 * get_decoder_data() - gets decoder data
58 * @input_dev: input device
59 *
60 * Returns the struct decoder_data that corresponds to a device
61 */
62static struct decoder_data *get_decoder_data(struct ir_input_dev *ir_dev)
63{
64 struct decoder_data *data = NULL;
65
66 spin_lock(&decoder_lock);
67 list_for_each_entry(data, &decoder_list, list) {
68 if (data->ir_dev == ir_dev)
69 break;
70 }
71 spin_unlock(&decoder_lock);
72 return data;
73}
74
75static ssize_t store_enabled(struct device *d,
76 struct device_attribute *mattr,
77 const char *buf,
78 size_t len)
79{
80 unsigned long value;
81 struct ir_input_dev *ir_dev = dev_get_drvdata(d);
82 struct decoder_data *data = get_decoder_data(ir_dev);
83
84 if (!data)
85 return -EINVAL;
86
87 if (strict_strtoul(buf, 10, &value) || value > 1)
88 return -EINVAL;
89
90 data->enabled = value;
91
92 return len;
93}
94
95static ssize_t show_enabled(struct device *d,
96 struct device_attribute *mattr, char *buf)
97{
98 struct ir_input_dev *ir_dev = dev_get_drvdata(d);
99 struct decoder_data *data = get_decoder_data(ir_dev);
100
101 if (!data)
102 return -EINVAL;
103
104 if (data->enabled)
105 return sprintf(buf, "1\n");
106 else
107 return sprintf(buf, "0\n");
108}
109
110static DEVICE_ATTR(enabled, S_IRUGO | S_IWUSR, show_enabled, store_enabled);
111
112static struct attribute *decoder_attributes[] = {
113 &dev_attr_enabled.attr,
114 NULL
115};
116
117static struct attribute_group decoder_attribute_group = {
118 .name = "jvc_decoder",
119 .attrs = decoder_attributes,
120};
121
122/** 37/**
123 * ir_jvc_decode() - Decode one JVC pulse or space 38 * ir_jvc_decode() - Decode one JVC pulse or space
124 * @input_dev: the struct input_dev descriptor of the device 39 * @input_dev: the struct input_dev descriptor of the device
@@ -128,14 +43,10 @@ static struct attribute_group decoder_attribute_group = {
128 */ 43 */
129static int ir_jvc_decode(struct input_dev *input_dev, struct ir_raw_event ev) 44static int ir_jvc_decode(struct input_dev *input_dev, struct ir_raw_event ev)
130{ 45{
131 struct decoder_data *data;
132 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); 46 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
47 struct jvc_dec *data = &ir_dev->raw->jvc;
133 48
134 data = get_decoder_data(ir_dev); 49 if (!(ir_dev->raw->enabled_protocols & IR_TYPE_JVC))
135 if (!data)
136 return -EINVAL;
137
138 if (!data->enabled)
139 return 0; 50 return 0;
140 51
141 if (IS_RESET(ev)) { 52 if (IS_RESET(ev)) {
@@ -188,9 +99,9 @@ static int ir_jvc_decode(struct input_dev *input_dev, struct ir_raw_event ev)
188 if (ev.pulse) 99 if (ev.pulse)
189 break; 100 break;
190 101
191 data->jvc_bits <<= 1; 102 data->bits <<= 1;
192 if (eq_margin(ev.duration, JVC_BIT_1_SPACE, JVC_UNIT / 2)) { 103 if (eq_margin(ev.duration, JVC_BIT_1_SPACE, JVC_UNIT / 2)) {
193 data->jvc_bits |= 1; 104 data->bits |= 1;
194 decrease_duration(&ev, JVC_BIT_1_SPACE); 105 decrease_duration(&ev, JVC_BIT_1_SPACE);
195 } else if (eq_margin(ev.duration, JVC_BIT_0_SPACE, JVC_UNIT / 2)) 106 } else if (eq_margin(ev.duration, JVC_BIT_0_SPACE, JVC_UNIT / 2))
196 decrease_duration(&ev, JVC_BIT_0_SPACE); 107 decrease_duration(&ev, JVC_BIT_0_SPACE);
@@ -223,13 +134,13 @@ static int ir_jvc_decode(struct input_dev *input_dev, struct ir_raw_event ev)
223 134
224 if (data->first) { 135 if (data->first) {
225 u32 scancode; 136 u32 scancode;
226 scancode = (bitrev8((data->jvc_bits >> 8) & 0xff) << 8) | 137 scancode = (bitrev8((data->bits >> 8) & 0xff) << 8) |
227 (bitrev8((data->jvc_bits >> 0) & 0xff) << 0); 138 (bitrev8((data->bits >> 0) & 0xff) << 0);
228 IR_dprintk(1, "JVC scancode 0x%04x\n", scancode); 139 IR_dprintk(1, "JVC scancode 0x%04x\n", scancode);
229 ir_keydown(input_dev, scancode, data->toggle); 140 ir_keydown(input_dev, scancode, data->toggle);
230 data->first = false; 141 data->first = false;
231 data->jvc_old_bits = data->jvc_bits; 142 data->old_bits = data->bits;
232 } else if (data->jvc_bits == data->jvc_old_bits) { 143 } else if (data->bits == data->old_bits) {
233 IR_dprintk(1, "JVC repeat\n"); 144 IR_dprintk(1, "JVC repeat\n");
234 ir_repeat(input_dev); 145 ir_repeat(input_dev);
235 } else { 146 } else {
@@ -249,54 +160,9 @@ out:
249 return -EINVAL; 160 return -EINVAL;
250} 161}
251 162
252static int ir_jvc_register(struct input_dev *input_dev)
253{
254 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
255 struct decoder_data *data;
256 int rc;
257
258 rc = sysfs_create_group(&ir_dev->dev.kobj, &decoder_attribute_group);
259 if (rc < 0)
260 return rc;
261
262 data = kzalloc(sizeof(*data), GFP_KERNEL);
263 if (!data) {
264 sysfs_remove_group(&ir_dev->dev.kobj, &decoder_attribute_group);
265 return -ENOMEM;
266 }
267
268 data->ir_dev = ir_dev;
269 data->enabled = 1;
270
271 spin_lock(&decoder_lock);
272 list_add_tail(&data->list, &decoder_list);
273 spin_unlock(&decoder_lock);
274
275 return 0;
276}
277
278static int ir_jvc_unregister(struct input_dev *input_dev)
279{
280 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
281 static struct decoder_data *data;
282
283 data = get_decoder_data(ir_dev);
284 if (!data)
285 return 0;
286
287 sysfs_remove_group(&ir_dev->dev.kobj, &decoder_attribute_group);
288
289 spin_lock(&decoder_lock);
290 list_del(&data->list);
291 spin_unlock(&decoder_lock);
292
293 return 0;
294}
295
296static struct ir_raw_handler jvc_handler = { 163static struct ir_raw_handler jvc_handler = {
164 .protocols = IR_TYPE_JVC,
297 .decode = ir_jvc_decode, 165 .decode = ir_jvc_decode,
298 .raw_register = ir_jvc_register,
299 .raw_unregister = ir_jvc_unregister,
300}; 166};
301 167
302static int __init ir_jvc_decode_init(void) 168static int __init ir_jvc_decode_init(void)
diff --git a/drivers/media/IR/ir-keytable.c b/drivers/media/IR/ir-keytable.c
index 94a8577e72eb..15a0f192d413 100644
--- a/drivers/media/IR/ir-keytable.c
+++ b/drivers/media/IR/ir-keytable.c
@@ -497,8 +497,9 @@ int __ir_input_register(struct input_dev *input_dev,
497 goto out_event; 497 goto out_event;
498 } 498 }
499 499
500 IR_dprintk(1, "Registered input device on %s for %s remote.\n", 500 IR_dprintk(1, "Registered input device on %s for %s remote%s.\n",
501 driver_name, rc_tab->name); 501 driver_name, rc_tab->name,
502 ir_dev->props->driver_type == RC_DRIVER_IR_RAW ? " in raw mode" : "");
502 503
503 return 0; 504 return 0;
504 505
diff --git a/drivers/media/IR/ir-lirc-codec.c b/drivers/media/IR/ir-lirc-codec.c
new file mode 100644
index 000000000000..3ba482d96c4b
--- /dev/null
+++ b/drivers/media/IR/ir-lirc-codec.c
@@ -0,0 +1,278 @@
1/* ir-lirc-codec.c - ir-core to classic lirc interface bridge
2 *
3 * Copyright (C) 2010 by Jarod Wilson <jarod@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/sched.h>
16#include <linux/wait.h>
17#include <media/lirc.h>
18#include <media/lirc_dev.h>
19#include <media/ir-core.h>
20#include "ir-core-priv.h"
21
22#define LIRCBUF_SIZE 256
23
24/**
25 * ir_lirc_decode() - Send raw IR data to lirc_dev to be relayed to the
26 * lircd userspace daemon for decoding.
27 * @input_dev: the struct input_dev descriptor of the device
28 * @duration: the struct ir_raw_event descriptor of the pulse/space
29 *
30 * This function returns -EINVAL if the lirc interfaces aren't wired up.
31 */
32static int ir_lirc_decode(struct input_dev *input_dev, struct ir_raw_event ev)
33{
34 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
35
36 if (!(ir_dev->raw->enabled_protocols & IR_TYPE_LIRC))
37 return 0;
38
39 if (!ir_dev->raw->lirc.drv || !ir_dev->raw->lirc.drv->rbuf)
40 return -EINVAL;
41
42 IR_dprintk(2, "LIRC data transfer started (%uus %s)\n",
43 TO_US(ev.duration), TO_STR(ev.pulse));
44
45 ir_dev->raw->lirc.lircdata += ev.duration / 1000;
46 if (ev.pulse)
47 ir_dev->raw->lirc.lircdata |= PULSE_BIT;
48
49 lirc_buffer_write(ir_dev->raw->lirc.drv->rbuf,
50 (unsigned char *) &ir_dev->raw->lirc.lircdata);
51 wake_up(&ir_dev->raw->lirc.drv->rbuf->wait_poll);
52
53 ir_dev->raw->lirc.lircdata = 0;
54
55 return 0;
56}
57
58static ssize_t ir_lirc_transmit_ir(struct file *file, const char *buf,
59 size_t n, loff_t *ppos)
60{
61 struct lirc_codec *lirc;
62 struct ir_input_dev *ir_dev;
63 int *txbuf; /* buffer with values to transmit */
64 int ret = 0, count;
65
66 lirc = lirc_get_pdata(file);
67 if (!lirc)
68 return -EFAULT;
69
70 if (n % sizeof(int))
71 return -EINVAL;
72
73 count = n / sizeof(int);
74 if (count > LIRCBUF_SIZE || count % 2 == 0)
75 return -EINVAL;
76
77 txbuf = memdup_user(buf, n);
78 if (IS_ERR(txbuf))
79 return PTR_ERR(txbuf);
80
81 ir_dev = lirc->ir_dev;
82 if (!ir_dev) {
83 ret = -EFAULT;
84 goto out;
85 }
86
87 if (ir_dev->props && ir_dev->props->tx_ir)
88 ret = ir_dev->props->tx_ir(ir_dev->props->priv, txbuf, (u32)n);
89
90out:
91 kfree(txbuf);
92 return ret;
93}
94
95static long ir_lirc_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
96{
97 struct lirc_codec *lirc;
98 struct ir_input_dev *ir_dev;
99 int ret = 0;
100 void *drv_data;
101 unsigned long val;
102
103 lirc = lirc_get_pdata(filep);
104 if (!lirc)
105 return -EFAULT;
106
107 ir_dev = lirc->ir_dev;
108 if (!ir_dev || !ir_dev->props || !ir_dev->props->priv)
109 return -EFAULT;
110
111 drv_data = ir_dev->props->priv;
112
113 switch (cmd) {
114 case LIRC_SET_TRANSMITTER_MASK:
115 ret = get_user(val, (unsigned long *)arg);
116 if (ret)
117 return ret;
118
119 if (ir_dev->props && ir_dev->props->s_tx_mask)
120 ret = ir_dev->props->s_tx_mask(drv_data, (u32)val);
121 else
122 return -EINVAL;
123 break;
124
125 case LIRC_SET_SEND_CARRIER:
126 ret = get_user(val, (unsigned long *)arg);
127 if (ret)
128 return ret;
129
130 if (ir_dev->props && ir_dev->props->s_tx_carrier)
131 ir_dev->props->s_tx_carrier(drv_data, (u32)val);
132 else
133 return -EINVAL;
134 break;
135
136 case LIRC_GET_SEND_MODE:
137 val = LIRC_CAN_SEND_PULSE & LIRC_CAN_SEND_MASK;
138 ret = put_user(val, (unsigned long *)arg);
139 break;
140
141 case LIRC_SET_SEND_MODE:
142 ret = get_user(val, (unsigned long *)arg);
143 if (ret)
144 return ret;
145
146 if (val != (LIRC_MODE_PULSE & LIRC_CAN_SEND_MASK))
147 return -EINVAL;
148 break;
149
150 default:
151 return lirc_dev_fop_ioctl(filep, cmd, arg);
152 }
153
154 return ret;
155}
156
157static int ir_lirc_open(void *data)
158{
159 return 0;
160}
161
162static void ir_lirc_close(void *data)
163{
164 return;
165}
166
167static struct file_operations lirc_fops = {
168 .owner = THIS_MODULE,
169 .write = ir_lirc_transmit_ir,
170 .unlocked_ioctl = ir_lirc_ioctl,
171 .read = lirc_dev_fop_read,
172 .poll = lirc_dev_fop_poll,
173 .open = lirc_dev_fop_open,
174 .release = lirc_dev_fop_close,
175};
176
177static int ir_lirc_register(struct input_dev *input_dev)
178{
179 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
180 struct lirc_driver *drv;
181 struct lirc_buffer *rbuf;
182 int rc = -ENOMEM;
183 unsigned long features;
184
185 drv = kzalloc(sizeof(struct lirc_driver), GFP_KERNEL);
186 if (!drv)
187 return rc;
188
189 rbuf = kzalloc(sizeof(struct lirc_buffer), GFP_KERNEL);
190 if (!rbuf)
191 goto rbuf_alloc_failed;
192
193 rc = lirc_buffer_init(rbuf, sizeof(int), LIRCBUF_SIZE);
194 if (rc)
195 goto rbuf_init_failed;
196
197 features = LIRC_CAN_REC_MODE2;
198 if (ir_dev->props->tx_ir) {
199 features |= LIRC_CAN_SEND_PULSE;
200 if (ir_dev->props->s_tx_mask)
201 features |= LIRC_CAN_SET_TRANSMITTER_MASK;
202 if (ir_dev->props->s_tx_carrier)
203 features |= LIRC_CAN_SET_SEND_CARRIER;
204 }
205
206 snprintf(drv->name, sizeof(drv->name), "ir-lirc-codec (%s)",
207 ir_dev->driver_name);
208 drv->minor = -1;
209 drv->features = features;
210 drv->data = &ir_dev->raw->lirc;
211 drv->rbuf = rbuf;
212 drv->set_use_inc = &ir_lirc_open;
213 drv->set_use_dec = &ir_lirc_close;
214 drv->code_length = sizeof(struct ir_raw_event) * 8;
215 drv->fops = &lirc_fops;
216 drv->dev = &ir_dev->dev;
217 drv->owner = THIS_MODULE;
218
219 drv->minor = lirc_register_driver(drv);
220 if (drv->minor < 0) {
221 rc = -ENODEV;
222 goto lirc_register_failed;
223 }
224
225 ir_dev->raw->lirc.drv = drv;
226 ir_dev->raw->lirc.ir_dev = ir_dev;
227 ir_dev->raw->lirc.lircdata = PULSE_MASK;
228
229 return 0;
230
231lirc_register_failed:
232rbuf_init_failed:
233 kfree(rbuf);
234rbuf_alloc_failed:
235 kfree(drv);
236
237 return rc;
238}
239
240static int ir_lirc_unregister(struct input_dev *input_dev)
241{
242 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
243 struct lirc_codec *lirc = &ir_dev->raw->lirc;
244
245 lirc_unregister_driver(lirc->drv->minor);
246 lirc_buffer_free(lirc->drv->rbuf);
247 kfree(lirc->drv);
248
249 return 0;
250}
251
252static struct ir_raw_handler lirc_handler = {
253 .protocols = IR_TYPE_LIRC,
254 .decode = ir_lirc_decode,
255 .raw_register = ir_lirc_register,
256 .raw_unregister = ir_lirc_unregister,
257};
258
259static int __init ir_lirc_codec_init(void)
260{
261 ir_raw_handler_register(&lirc_handler);
262
263 printk(KERN_INFO "IR LIRC bridge handler initialized\n");
264 return 0;
265}
266
267static void __exit ir_lirc_codec_exit(void)
268{
269 ir_raw_handler_unregister(&lirc_handler);
270}
271
272module_init(ir_lirc_codec_init);
273module_exit(ir_lirc_codec_exit);
274
275MODULE_LICENSE("GPL");
276MODULE_AUTHOR("Jarod Wilson <jarod@redhat.com>");
277MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com)");
278MODULE_DESCRIPTION("LIRC IR handler bridge");
diff --git a/drivers/media/IR/ir-nec-decoder.c b/drivers/media/IR/ir-nec-decoder.c
index ba79233112ef..52e0f378ae3d 100644
--- a/drivers/media/IR/ir-nec-decoder.c
+++ b/drivers/media/IR/ir-nec-decoder.c
@@ -27,10 +27,6 @@
27#define NEC_TRAILER_PULSE (1 * NEC_UNIT) 27#define NEC_TRAILER_PULSE (1 * NEC_UNIT)
28#define NEC_TRAILER_SPACE (10 * NEC_UNIT) /* even longer in reality */ 28#define NEC_TRAILER_SPACE (10 * NEC_UNIT) /* even longer in reality */
29 29
30/* Used to register nec_decoder clients */
31static LIST_HEAD(decoder_list);
32static DEFINE_SPINLOCK(decoder_lock);
33
34enum nec_state { 30enum nec_state {
35 STATE_INACTIVE, 31 STATE_INACTIVE,
36 STATE_HEADER_SPACE, 32 STATE_HEADER_SPACE,
@@ -40,84 +36,6 @@ enum nec_state {
40 STATE_TRAILER_SPACE, 36 STATE_TRAILER_SPACE,
41}; 37};
42 38
43struct decoder_data {
44 struct list_head list;
45 struct ir_input_dev *ir_dev;
46 int enabled:1;
47
48 /* State machine control */
49 enum nec_state state;
50 u32 nec_bits;
51 unsigned count;
52};
53
54
55/**
56 * get_decoder_data() - gets decoder data
57 * @input_dev: input device
58 *
59 * Returns the struct decoder_data that corresponds to a device
60 */
61static struct decoder_data *get_decoder_data(struct ir_input_dev *ir_dev)
62{
63 struct decoder_data *data = NULL;
64
65 spin_lock(&decoder_lock);
66 list_for_each_entry(data, &decoder_list, list) {
67 if (data->ir_dev == ir_dev)
68 break;
69 }
70 spin_unlock(&decoder_lock);
71 return data;
72}
73
74static ssize_t store_enabled(struct device *d,
75 struct device_attribute *mattr,
76 const char *buf,
77 size_t len)
78{
79 unsigned long value;
80 struct ir_input_dev *ir_dev = dev_get_drvdata(d);
81 struct decoder_data *data = get_decoder_data(ir_dev);
82
83 if (!data)
84 return -EINVAL;
85
86 if (strict_strtoul(buf, 10, &value) || value > 1)
87 return -EINVAL;
88
89 data->enabled = value;
90
91 return len;
92}
93
94static ssize_t show_enabled(struct device *d,
95 struct device_attribute *mattr, char *buf)
96{
97 struct ir_input_dev *ir_dev = dev_get_drvdata(d);
98 struct decoder_data *data = get_decoder_data(ir_dev);
99
100 if (!data)
101 return -EINVAL;
102
103 if (data->enabled)
104 return sprintf(buf, "1\n");
105 else
106 return sprintf(buf, "0\n");
107}
108
109static DEVICE_ATTR(enabled, S_IRUGO | S_IWUSR, show_enabled, store_enabled);
110
111static struct attribute *decoder_attributes[] = {
112 &dev_attr_enabled.attr,
113 NULL
114};
115
116static struct attribute_group decoder_attribute_group = {
117 .name = "nec_decoder",
118 .attrs = decoder_attributes,
119};
120
121/** 39/**
122 * ir_nec_decode() - Decode one NEC pulse or space 40 * ir_nec_decode() - Decode one NEC pulse or space
123 * @input_dev: the struct input_dev descriptor of the device 41 * @input_dev: the struct input_dev descriptor of the device
@@ -127,16 +45,12 @@ static struct attribute_group decoder_attribute_group = {
127 */ 45 */
128static int ir_nec_decode(struct input_dev *input_dev, struct ir_raw_event ev) 46static int ir_nec_decode(struct input_dev *input_dev, struct ir_raw_event ev)
129{ 47{
130 struct decoder_data *data;
131 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); 48 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
49 struct nec_dec *data = &ir_dev->raw->nec;
132 u32 scancode; 50 u32 scancode;
133 u8 address, not_address, command, not_command; 51 u8 address, not_address, command, not_command;
134 52
135 data = get_decoder_data(ir_dev); 53 if (!(ir_dev->raw->enabled_protocols & IR_TYPE_NEC))
136 if (!data)
137 return -EINVAL;
138
139 if (!data->enabled)
140 return 0; 54 return 0;
141 55
142 if (IS_RESET(ev)) { 56 if (IS_RESET(ev)) {
@@ -191,9 +105,9 @@ static int ir_nec_decode(struct input_dev *input_dev, struct ir_raw_event ev)
191 if (ev.pulse) 105 if (ev.pulse)
192 break; 106 break;
193 107
194 data->nec_bits <<= 1; 108 data->bits <<= 1;
195 if (eq_margin(ev.duration, NEC_BIT_1_SPACE, NEC_UNIT / 2)) 109 if (eq_margin(ev.duration, NEC_BIT_1_SPACE, NEC_UNIT / 2))
196 data->nec_bits |= 1; 110 data->bits |= 1;
197 else if (!eq_margin(ev.duration, NEC_BIT_0_SPACE, NEC_UNIT / 2)) 111 else if (!eq_margin(ev.duration, NEC_BIT_0_SPACE, NEC_UNIT / 2))
198 break; 112 break;
199 data->count++; 113 data->count++;
@@ -222,14 +136,14 @@ static int ir_nec_decode(struct input_dev *input_dev, struct ir_raw_event ev)
222 if (!geq_margin(ev.duration, NEC_TRAILER_SPACE, NEC_UNIT / 2)) 136 if (!geq_margin(ev.duration, NEC_TRAILER_SPACE, NEC_UNIT / 2))
223 break; 137 break;
224 138
225 address = bitrev8((data->nec_bits >> 24) & 0xff); 139 address = bitrev8((data->bits >> 24) & 0xff);
226 not_address = bitrev8((data->nec_bits >> 16) & 0xff); 140 not_address = bitrev8((data->bits >> 16) & 0xff);
227 command = bitrev8((data->nec_bits >> 8) & 0xff); 141 command = bitrev8((data->bits >> 8) & 0xff);
228 not_command = bitrev8((data->nec_bits >> 0) & 0xff); 142 not_command = bitrev8((data->bits >> 0) & 0xff);
229 143
230 if ((command ^ not_command) != 0xff) { 144 if ((command ^ not_command) != 0xff) {
231 IR_dprintk(1, "NEC checksum error: received 0x%08x\n", 145 IR_dprintk(1, "NEC checksum error: received 0x%08x\n",
232 data->nec_bits); 146 data->bits);
233 break; 147 break;
234 } 148 }
235 149
@@ -256,54 +170,9 @@ static int ir_nec_decode(struct input_dev *input_dev, struct ir_raw_event ev)
256 return -EINVAL; 170 return -EINVAL;
257} 171}
258 172
259static int ir_nec_register(struct input_dev *input_dev)
260{
261 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
262 struct decoder_data *data;
263 int rc;
264
265 rc = sysfs_create_group(&ir_dev->dev.kobj, &decoder_attribute_group);
266 if (rc < 0)
267 return rc;
268
269 data = kzalloc(sizeof(*data), GFP_KERNEL);
270 if (!data) {
271 sysfs_remove_group(&ir_dev->dev.kobj, &decoder_attribute_group);
272 return -ENOMEM;
273 }
274
275 data->ir_dev = ir_dev;
276 data->enabled = 1;
277
278 spin_lock(&decoder_lock);
279 list_add_tail(&data->list, &decoder_list);
280 spin_unlock(&decoder_lock);
281
282 return 0;
283}
284
285static int ir_nec_unregister(struct input_dev *input_dev)
286{
287 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
288 static struct decoder_data *data;
289
290 data = get_decoder_data(ir_dev);
291 if (!data)
292 return 0;
293
294 sysfs_remove_group(&ir_dev->dev.kobj, &decoder_attribute_group);
295
296 spin_lock(&decoder_lock);
297 list_del(&data->list);
298 spin_unlock(&decoder_lock);
299
300 return 0;
301}
302
303static struct ir_raw_handler nec_handler = { 173static struct ir_raw_handler nec_handler = {
174 .protocols = IR_TYPE_NEC,
304 .decode = ir_nec_decode, 175 .decode = ir_nec_decode,
305 .raw_register = ir_nec_register,
306 .raw_unregister = ir_nec_unregister,
307}; 176};
308 177
309static int __init ir_nec_decode_init(void) 178static int __init ir_nec_decode_init(void)
diff --git a/drivers/media/IR/ir-raw-event.c b/drivers/media/IR/ir-raw-event.c
index ea68a3f2effa..6f192ef31db1 100644
--- a/drivers/media/IR/ir-raw-event.c
+++ b/drivers/media/IR/ir-raw-event.c
@@ -20,35 +20,13 @@
20/* Define the max number of pulse/space transitions to buffer */ 20/* Define the max number of pulse/space transitions to buffer */
21#define MAX_IR_EVENT_SIZE 512 21#define MAX_IR_EVENT_SIZE 512
22 22
23/* Used to keep track of IR raw clients, protected by ir_raw_handler_lock */
24static LIST_HEAD(ir_raw_client_list);
25
23/* Used to handle IR raw handler extensions */ 26/* Used to handle IR raw handler extensions */
24static LIST_HEAD(ir_raw_handler_list);
25static DEFINE_SPINLOCK(ir_raw_handler_lock); 27static DEFINE_SPINLOCK(ir_raw_handler_lock);
26 28static LIST_HEAD(ir_raw_handler_list);
27/** 29static u64 available_protocols;
28 * RUN_DECODER() - runs an operation on all IR decoders
29 * @ops: IR raw handler operation to be called
30 * @arg: arguments to be passed to the callback
31 *
32 * Calls ir_raw_handler::ops for all registered IR handlers. It prevents
33 * new decode addition/removal while running, by locking ir_raw_handler_lock
34 * mutex. If an error occurs, it stops the ops. Otherwise, it returns a sum
35 * of the return codes.
36 */
37#define RUN_DECODER(ops, ...) ({ \
38 struct ir_raw_handler *_ir_raw_handler; \
39 int _sumrc = 0, _rc; \
40 spin_lock(&ir_raw_handler_lock); \
41 list_for_each_entry(_ir_raw_handler, &ir_raw_handler_list, list) { \
42 if (_ir_raw_handler->ops) { \
43 _rc = _ir_raw_handler->ops(__VA_ARGS__); \
44 if (_rc < 0) \
45 break; \
46 _sumrc += _rc; \
47 } \
48 } \
49 spin_unlock(&ir_raw_handler_lock); \
50 _sumrc; \
51})
52 30
53#ifdef MODULE 31#ifdef MODULE
54/* Used to load the decoders */ 32/* Used to load the decoders */
@@ -58,57 +36,17 @@ static struct work_struct wq_load;
58static void ir_raw_event_work(struct work_struct *work) 36static void ir_raw_event_work(struct work_struct *work)
59{ 37{
60 struct ir_raw_event ev; 38 struct ir_raw_event ev;
39 struct ir_raw_handler *handler;
61 struct ir_raw_event_ctrl *raw = 40 struct ir_raw_event_ctrl *raw =
62 container_of(work, struct ir_raw_event_ctrl, rx_work); 41 container_of(work, struct ir_raw_event_ctrl, rx_work);
63 42
64 while (kfifo_out(&raw->kfifo, &ev, sizeof(ev)) == sizeof(ev)) 43 while (kfifo_out(&raw->kfifo, &ev, sizeof(ev)) == sizeof(ev)) {
65 RUN_DECODER(decode, raw->input_dev, ev); 44 spin_lock(&ir_raw_handler_lock);
66} 45 list_for_each_entry(handler, &ir_raw_handler_list, list)
67 46 handler->decode(raw->input_dev, ev);
68int ir_raw_event_register(struct input_dev *input_dev) 47 spin_unlock(&ir_raw_handler_lock);
69{ 48 raw->prev_ev = ev;
70 struct ir_input_dev *ir = input_get_drvdata(input_dev);
71 int rc;
72
73 ir->raw = kzalloc(sizeof(*ir->raw), GFP_KERNEL);
74 if (!ir->raw)
75 return -ENOMEM;
76
77 ir->raw->input_dev = input_dev;
78 INIT_WORK(&ir->raw->rx_work, ir_raw_event_work);
79
80 rc = kfifo_alloc(&ir->raw->kfifo, sizeof(s64) * MAX_IR_EVENT_SIZE,
81 GFP_KERNEL);
82 if (rc < 0) {
83 kfree(ir->raw);
84 ir->raw = NULL;
85 return rc;
86 }
87
88 rc = RUN_DECODER(raw_register, input_dev);
89 if (rc < 0) {
90 kfifo_free(&ir->raw->kfifo);
91 kfree(ir->raw);
92 ir->raw = NULL;
93 return rc;
94 } 49 }
95
96 return rc;
97}
98
99void ir_raw_event_unregister(struct input_dev *input_dev)
100{
101 struct ir_input_dev *ir = input_get_drvdata(input_dev);
102
103 if (!ir->raw)
104 return;
105
106 cancel_work_sync(&ir->raw->rx_work);
107 RUN_DECODER(raw_unregister, input_dev);
108
109 kfifo_free(&ir->raw->kfifo);
110 kfree(ir->raw);
111 ir->raw = NULL;
112} 50}
113 51
114/** 52/**
@@ -204,23 +142,103 @@ void ir_raw_event_handle(struct input_dev *input_dev)
204} 142}
205EXPORT_SYMBOL_GPL(ir_raw_event_handle); 143EXPORT_SYMBOL_GPL(ir_raw_event_handle);
206 144
145/* used internally by the sysfs interface */
146u64
147ir_raw_get_allowed_protocols()
148{
149 u64 protocols;
150 spin_lock(&ir_raw_handler_lock);
151 protocols = available_protocols;
152 spin_unlock(&ir_raw_handler_lock);
153 return protocols;
154}
155
156/*
157 * Used to (un)register raw event clients
158 */
159int ir_raw_event_register(struct input_dev *input_dev)
160{
161 struct ir_input_dev *ir = input_get_drvdata(input_dev);
162 int rc;
163 struct ir_raw_handler *handler;
164
165 ir->raw = kzalloc(sizeof(*ir->raw), GFP_KERNEL);
166 if (!ir->raw)
167 return -ENOMEM;
168
169 ir->raw->input_dev = input_dev;
170 INIT_WORK(&ir->raw->rx_work, ir_raw_event_work);
171 ir->raw->enabled_protocols = ~0;
172 rc = kfifo_alloc(&ir->raw->kfifo, sizeof(s64) * MAX_IR_EVENT_SIZE,
173 GFP_KERNEL);
174 if (rc < 0) {
175 kfree(ir->raw);
176 ir->raw = NULL;
177 return rc;
178 }
179
180 spin_lock(&ir_raw_handler_lock);
181 list_add_tail(&ir->raw->list, &ir_raw_client_list);
182 list_for_each_entry(handler, &ir_raw_handler_list, list)
183 if (handler->raw_register)
184 handler->raw_register(ir->raw->input_dev);
185 spin_unlock(&ir_raw_handler_lock);
186
187 return 0;
188}
189
190void ir_raw_event_unregister(struct input_dev *input_dev)
191{
192 struct ir_input_dev *ir = input_get_drvdata(input_dev);
193 struct ir_raw_handler *handler;
194
195 if (!ir->raw)
196 return;
197
198 cancel_work_sync(&ir->raw->rx_work);
199
200 spin_lock(&ir_raw_handler_lock);
201 list_del(&ir->raw->list);
202 list_for_each_entry(handler, &ir_raw_handler_list, list)
203 if (handler->raw_unregister)
204 handler->raw_unregister(ir->raw->input_dev);
205 spin_unlock(&ir_raw_handler_lock);
206
207 kfifo_free(&ir->raw->kfifo);
208 kfree(ir->raw);
209 ir->raw = NULL;
210}
211
207/* 212/*
208 * Extension interface - used to register the IR decoders 213 * Extension interface - used to register the IR decoders
209 */ 214 */
210 215
211int ir_raw_handler_register(struct ir_raw_handler *ir_raw_handler) 216int ir_raw_handler_register(struct ir_raw_handler *ir_raw_handler)
212{ 217{
218 struct ir_raw_event_ctrl *raw;
219
213 spin_lock(&ir_raw_handler_lock); 220 spin_lock(&ir_raw_handler_lock);
214 list_add_tail(&ir_raw_handler->list, &ir_raw_handler_list); 221 list_add_tail(&ir_raw_handler->list, &ir_raw_handler_list);
222 if (ir_raw_handler->raw_register)
223 list_for_each_entry(raw, &ir_raw_client_list, list)
224 ir_raw_handler->raw_register(raw->input_dev);
225 available_protocols |= ir_raw_handler->protocols;
215 spin_unlock(&ir_raw_handler_lock); 226 spin_unlock(&ir_raw_handler_lock);
227
216 return 0; 228 return 0;
217} 229}
218EXPORT_SYMBOL(ir_raw_handler_register); 230EXPORT_SYMBOL(ir_raw_handler_register);
219 231
220void ir_raw_handler_unregister(struct ir_raw_handler *ir_raw_handler) 232void ir_raw_handler_unregister(struct ir_raw_handler *ir_raw_handler)
221{ 233{
234 struct ir_raw_event_ctrl *raw;
235
222 spin_lock(&ir_raw_handler_lock); 236 spin_lock(&ir_raw_handler_lock);
223 list_del(&ir_raw_handler->list); 237 list_del(&ir_raw_handler->list);
238 if (ir_raw_handler->raw_unregister)
239 list_for_each_entry(raw, &ir_raw_client_list, list)
240 ir_raw_handler->raw_unregister(raw->input_dev);
241 available_protocols &= ~ir_raw_handler->protocols;
224 spin_unlock(&ir_raw_handler_lock); 242 spin_unlock(&ir_raw_handler_lock);
225} 243}
226EXPORT_SYMBOL(ir_raw_handler_unregister); 244EXPORT_SYMBOL(ir_raw_handler_unregister);
@@ -235,6 +253,7 @@ static void init_decoders(struct work_struct *work)
235 load_rc6_decode(); 253 load_rc6_decode();
236 load_jvc_decode(); 254 load_jvc_decode();
237 load_sony_decode(); 255 load_sony_decode();
256 load_lirc_codec();
238 257
239 /* If needed, we may later add some init code. In this case, 258 /* If needed, we may later add some init code. In this case,
240 it is needed to change the CONFIG_MODULE test at ir-core.h 259 it is needed to change the CONFIG_MODULE test at ir-core.h
diff --git a/drivers/media/IR/ir-rc5-decoder.c b/drivers/media/IR/ir-rc5-decoder.c
index 23cdb1b1a3bc..df4770d978ad 100644
--- a/drivers/media/IR/ir-rc5-decoder.c
+++ b/drivers/media/IR/ir-rc5-decoder.c
@@ -30,10 +30,6 @@
30#define RC5_BIT_END (1 * RC5_UNIT) 30#define RC5_BIT_END (1 * RC5_UNIT)
31#define RC5X_SPACE (4 * RC5_UNIT) 31#define RC5X_SPACE (4 * RC5_UNIT)
32 32
33/* Used to register rc5_decoder clients */
34static LIST_HEAD(decoder_list);
35static DEFINE_SPINLOCK(decoder_lock);
36
37enum rc5_state { 33enum rc5_state {
38 STATE_INACTIVE, 34 STATE_INACTIVE,
39 STATE_BIT_START, 35 STATE_BIT_START,
@@ -42,87 +38,6 @@ enum rc5_state {
42 STATE_FINISHED, 38 STATE_FINISHED,
43}; 39};
44 40
45struct decoder_data {
46 struct list_head list;
47 struct ir_input_dev *ir_dev;
48 int enabled:1;
49
50 /* State machine control */
51 enum rc5_state state;
52 u32 rc5_bits;
53 struct ir_raw_event prev_ev;
54 unsigned count;
55 unsigned wanted_bits;
56};
57
58
59/**
60 * get_decoder_data() - gets decoder data
61 * @input_dev: input device
62 *
63 * Returns the struct decoder_data that corresponds to a device
64 */
65
66static struct decoder_data *get_decoder_data(struct ir_input_dev *ir_dev)
67{
68 struct decoder_data *data = NULL;
69
70 spin_lock(&decoder_lock);
71 list_for_each_entry(data, &decoder_list, list) {
72 if (data->ir_dev == ir_dev)
73 break;
74 }
75 spin_unlock(&decoder_lock);
76 return data;
77}
78
79static ssize_t store_enabled(struct device *d,
80 struct device_attribute *mattr,
81 const char *buf,
82 size_t len)
83{
84 unsigned long value;
85 struct ir_input_dev *ir_dev = dev_get_drvdata(d);
86 struct decoder_data *data = get_decoder_data(ir_dev);
87
88 if (!data)
89 return -EINVAL;
90
91 if (strict_strtoul(buf, 10, &value) || value > 1)
92 return -EINVAL;
93
94 data->enabled = value;
95
96 return len;
97}
98
99static ssize_t show_enabled(struct device *d,
100 struct device_attribute *mattr, char *buf)
101{
102 struct ir_input_dev *ir_dev = dev_get_drvdata(d);
103 struct decoder_data *data = get_decoder_data(ir_dev);
104
105 if (!data)
106 return -EINVAL;
107
108 if (data->enabled)
109 return sprintf(buf, "1\n");
110 else
111 return sprintf(buf, "0\n");
112}
113
114static DEVICE_ATTR(enabled, S_IRUGO | S_IWUSR, show_enabled, store_enabled);
115
116static struct attribute *decoder_attributes[] = {
117 &dev_attr_enabled.attr,
118 NULL
119};
120
121static struct attribute_group decoder_attribute_group = {
122 .name = "rc5_decoder",
123 .attrs = decoder_attributes,
124};
125
126/** 41/**
127 * ir_rc5_decode() - Decode one RC-5 pulse or space 42 * ir_rc5_decode() - Decode one RC-5 pulse or space
128 * @input_dev: the struct input_dev descriptor of the device 43 * @input_dev: the struct input_dev descriptor of the device
@@ -132,17 +47,13 @@ static struct attribute_group decoder_attribute_group = {
132 */ 47 */
133static int ir_rc5_decode(struct input_dev *input_dev, struct ir_raw_event ev) 48static int ir_rc5_decode(struct input_dev *input_dev, struct ir_raw_event ev)
134{ 49{
135 struct decoder_data *data;
136 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); 50 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
51 struct rc5_dec *data = &ir_dev->raw->rc5;
137 u8 toggle; 52 u8 toggle;
138 u32 scancode; 53 u32 scancode;
139 54
140 data = get_decoder_data(ir_dev); 55 if (!(ir_dev->raw->enabled_protocols & IR_TYPE_RC5))
141 if (!data) 56 return 0;
142 return -EINVAL;
143
144 if (!data->enabled)
145 return 0;
146 57
147 if (IS_RESET(ev)) { 58 if (IS_RESET(ev)) {
148 data->state = STATE_INACTIVE; 59 data->state = STATE_INACTIVE;
@@ -176,16 +87,15 @@ again:
176 if (!eq_margin(ev.duration, RC5_BIT_START, RC5_UNIT / 2)) 87 if (!eq_margin(ev.duration, RC5_BIT_START, RC5_UNIT / 2))
177 break; 88 break;
178 89
179 data->rc5_bits <<= 1; 90 data->bits <<= 1;
180 if (!ev.pulse) 91 if (!ev.pulse)
181 data->rc5_bits |= 1; 92 data->bits |= 1;
182 data->count++; 93 data->count++;
183 data->prev_ev = ev;
184 data->state = STATE_BIT_END; 94 data->state = STATE_BIT_END;
185 return 0; 95 return 0;
186 96
187 case STATE_BIT_END: 97 case STATE_BIT_END:
188 if (!is_transition(&ev, &data->prev_ev)) 98 if (!is_transition(&ev, &ir_dev->raw->prev_ev))
189 break; 99 break;
190 100
191 if (data->count == data->wanted_bits) 101 if (data->count == data->wanted_bits)
@@ -217,11 +127,11 @@ again:
217 if (data->wanted_bits == RC5X_NBITS) { 127 if (data->wanted_bits == RC5X_NBITS) {
218 /* RC5X */ 128 /* RC5X */
219 u8 xdata, command, system; 129 u8 xdata, command, system;
220 xdata = (data->rc5_bits & 0x0003F) >> 0; 130 xdata = (data->bits & 0x0003F) >> 0;
221 command = (data->rc5_bits & 0x00FC0) >> 6; 131 command = (data->bits & 0x00FC0) >> 6;
222 system = (data->rc5_bits & 0x1F000) >> 12; 132 system = (data->bits & 0x1F000) >> 12;
223 toggle = (data->rc5_bits & 0x20000) ? 1 : 0; 133 toggle = (data->bits & 0x20000) ? 1 : 0;
224 command += (data->rc5_bits & 0x01000) ? 0 : 0x40; 134 command += (data->bits & 0x01000) ? 0 : 0x40;
225 scancode = system << 16 | command << 8 | xdata; 135 scancode = system << 16 | command << 8 | xdata;
226 136
227 IR_dprintk(1, "RC5X scancode 0x%06x (toggle: %u)\n", 137 IR_dprintk(1, "RC5X scancode 0x%06x (toggle: %u)\n",
@@ -230,10 +140,10 @@ again:
230 } else { 140 } else {
231 /* RC5 */ 141 /* RC5 */
232 u8 command, system; 142 u8 command, system;
233 command = (data->rc5_bits & 0x0003F) >> 0; 143 command = (data->bits & 0x0003F) >> 0;
234 system = (data->rc5_bits & 0x007C0) >> 6; 144 system = (data->bits & 0x007C0) >> 6;
235 toggle = (data->rc5_bits & 0x00800) ? 1 : 0; 145 toggle = (data->bits & 0x00800) ? 1 : 0;
236 command += (data->rc5_bits & 0x01000) ? 0 : 0x40; 146 command += (data->bits & 0x01000) ? 0 : 0x40;
237 scancode = system << 8 | command; 147 scancode = system << 8 | command;
238 148
239 IR_dprintk(1, "RC5 scancode 0x%04x (toggle: %u)\n", 149 IR_dprintk(1, "RC5 scancode 0x%04x (toggle: %u)\n",
@@ -252,54 +162,9 @@ out:
252 return -EINVAL; 162 return -EINVAL;
253} 163}
254 164
255static int ir_rc5_register(struct input_dev *input_dev)
256{
257 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
258 struct decoder_data *data;
259 int rc;
260
261 rc = sysfs_create_group(&ir_dev->dev.kobj, &decoder_attribute_group);
262 if (rc < 0)
263 return rc;
264
265 data = kzalloc(sizeof(*data), GFP_KERNEL);
266 if (!data) {
267 sysfs_remove_group(&ir_dev->dev.kobj, &decoder_attribute_group);
268 return -ENOMEM;
269 }
270
271 data->ir_dev = ir_dev;
272 data->enabled = 1;
273
274 spin_lock(&decoder_lock);
275 list_add_tail(&data->list, &decoder_list);
276 spin_unlock(&decoder_lock);
277
278 return 0;
279}
280
281static int ir_rc5_unregister(struct input_dev *input_dev)
282{
283 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
284 static struct decoder_data *data;
285
286 data = get_decoder_data(ir_dev);
287 if (!data)
288 return 0;
289
290 sysfs_remove_group(&ir_dev->dev.kobj, &decoder_attribute_group);
291
292 spin_lock(&decoder_lock);
293 list_del(&data->list);
294 spin_unlock(&decoder_lock);
295
296 return 0;
297}
298
299static struct ir_raw_handler rc5_handler = { 165static struct ir_raw_handler rc5_handler = {
166 .protocols = IR_TYPE_RC5,
300 .decode = ir_rc5_decode, 167 .decode = ir_rc5_decode,
301 .raw_register = ir_rc5_register,
302 .raw_unregister = ir_rc5_unregister,
303}; 168};
304 169
305static int __init ir_rc5_decode_init(void) 170static int __init ir_rc5_decode_init(void)
diff --git a/drivers/media/IR/ir-rc6-decoder.c b/drivers/media/IR/ir-rc6-decoder.c
index 2bf479f4f1bc..f1624b8279bc 100644
--- a/drivers/media/IR/ir-rc6-decoder.c
+++ b/drivers/media/IR/ir-rc6-decoder.c
@@ -36,10 +36,6 @@
36#define RC6_STARTBIT_MASK 0x08 /* for the header bits */ 36#define RC6_STARTBIT_MASK 0x08 /* for the header bits */
37#define RC6_6A_MCE_TOGGLE_MASK 0x8000 /* for the body bits */ 37#define RC6_6A_MCE_TOGGLE_MASK 0x8000 /* for the body bits */
38 38
39/* Used to register rc6_decoder clients */
40static LIST_HEAD(decoder_list);
41static DEFINE_SPINLOCK(decoder_lock);
42
43enum rc6_mode { 39enum rc6_mode {
44 RC6_MODE_0, 40 RC6_MODE_0,
45 RC6_MODE_6A, 41 RC6_MODE_6A,
@@ -58,89 +54,8 @@ enum rc6_state {
58 STATE_FINISHED, 54 STATE_FINISHED,
59}; 55};
60 56
61struct decoder_data { 57static enum rc6_mode rc6_mode(struct rc6_dec *data)
62 struct list_head list;
63 struct ir_input_dev *ir_dev;
64 int enabled:1;
65
66 /* State machine control */
67 enum rc6_state state;
68 u8 header;
69 u32 body;
70 struct ir_raw_event prev_ev;
71 bool toggle;
72 unsigned count;
73 unsigned wanted_bits;
74};
75
76
77/**
78 * get_decoder_data() - gets decoder data
79 * @input_dev: input device
80 *
81 * Returns the struct decoder_data that corresponds to a device
82 */
83static struct decoder_data *get_decoder_data(struct ir_input_dev *ir_dev)
84{
85 struct decoder_data *data = NULL;
86
87 spin_lock(&decoder_lock);
88 list_for_each_entry(data, &decoder_list, list) {
89 if (data->ir_dev == ir_dev)
90 break;
91 }
92 spin_unlock(&decoder_lock);
93 return data;
94}
95
96static ssize_t store_enabled(struct device *d,
97 struct device_attribute *mattr,
98 const char *buf,
99 size_t len)
100{ 58{
101 unsigned long value;
102 struct ir_input_dev *ir_dev = dev_get_drvdata(d);
103 struct decoder_data *data = get_decoder_data(ir_dev);
104
105 if (!data)
106 return -EINVAL;
107
108 if (strict_strtoul(buf, 10, &value) || value > 1)
109 return -EINVAL;
110
111 data->enabled = value;
112
113 return len;
114}
115
116static ssize_t show_enabled(struct device *d,
117 struct device_attribute *mattr, char *buf)
118{
119 struct ir_input_dev *ir_dev = dev_get_drvdata(d);
120 struct decoder_data *data = get_decoder_data(ir_dev);
121
122 if (!data)
123 return -EINVAL;
124
125 if (data->enabled)
126 return sprintf(buf, "1\n");
127 else
128 return sprintf(buf, "0\n");
129}
130
131static DEVICE_ATTR(enabled, S_IRUGO | S_IWUSR, show_enabled, store_enabled);
132
133static struct attribute *decoder_attributes[] = {
134 &dev_attr_enabled.attr,
135 NULL
136};
137
138static struct attribute_group decoder_attribute_group = {
139 .name = "rc6_decoder",
140 .attrs = decoder_attributes,
141};
142
143static enum rc6_mode rc6_mode(struct decoder_data *data) {
144 switch (data->header & RC6_MODE_MASK) { 59 switch (data->header & RC6_MODE_MASK) {
145 case 0: 60 case 0:
146 return RC6_MODE_0; 61 return RC6_MODE_0;
@@ -162,16 +77,12 @@ static enum rc6_mode rc6_mode(struct decoder_data *data) {
162 */ 77 */
163static int ir_rc6_decode(struct input_dev *input_dev, struct ir_raw_event ev) 78static int ir_rc6_decode(struct input_dev *input_dev, struct ir_raw_event ev)
164{ 79{
165 struct decoder_data *data;
166 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); 80 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
81 struct rc6_dec *data = &ir_dev->raw->rc6;
167 u32 scancode; 82 u32 scancode;
168 u8 toggle; 83 u8 toggle;
169 84
170 data = get_decoder_data(ir_dev); 85 if (!(ir_dev->raw->enabled_protocols & IR_TYPE_RC6))
171 if (!data)
172 return -EINVAL;
173
174 if (!data->enabled)
175 return 0; 86 return 0;
176 87
177 if (IS_RESET(ev)) { 88 if (IS_RESET(ev)) {
@@ -223,12 +134,11 @@ again:
223 if (ev.pulse) 134 if (ev.pulse)
224 data->header |= 1; 135 data->header |= 1;
225 data->count++; 136 data->count++;
226 data->prev_ev = ev;
227 data->state = STATE_HEADER_BIT_END; 137 data->state = STATE_HEADER_BIT_END;
228 return 0; 138 return 0;
229 139
230 case STATE_HEADER_BIT_END: 140 case STATE_HEADER_BIT_END:
231 if (!is_transition(&ev, &data->prev_ev)) 141 if (!is_transition(&ev, &ir_dev->raw->prev_ev))
232 break; 142 break;
233 143
234 if (data->count == RC6_HEADER_NBITS) 144 if (data->count == RC6_HEADER_NBITS)
@@ -244,12 +154,11 @@ again:
244 break; 154 break;
245 155
246 data->toggle = ev.pulse; 156 data->toggle = ev.pulse;
247 data->prev_ev = ev;
248 data->state = STATE_TOGGLE_END; 157 data->state = STATE_TOGGLE_END;
249 return 0; 158 return 0;
250 159
251 case STATE_TOGGLE_END: 160 case STATE_TOGGLE_END:
252 if (!is_transition(&ev, &data->prev_ev) || 161 if (!is_transition(&ev, &ir_dev->raw->prev_ev) ||
253 !geq_margin(ev.duration, RC6_TOGGLE_END, RC6_UNIT / 2)) 162 !geq_margin(ev.duration, RC6_TOGGLE_END, RC6_UNIT / 2))
254 break; 163 break;
255 164
@@ -259,7 +168,6 @@ again:
259 } 168 }
260 169
261 data->state = STATE_BODY_BIT_START; 170 data->state = STATE_BODY_BIT_START;
262 data->prev_ev = ev;
263 decrease_duration(&ev, RC6_TOGGLE_END); 171 decrease_duration(&ev, RC6_TOGGLE_END);
264 data->count = 0; 172 data->count = 0;
265 173
@@ -291,13 +199,11 @@ again:
291 if (ev.pulse) 199 if (ev.pulse)
292 data->body |= 1; 200 data->body |= 1;
293 data->count++; 201 data->count++;
294 data->prev_ev = ev;
295
296 data->state = STATE_BODY_BIT_END; 202 data->state = STATE_BODY_BIT_END;
297 return 0; 203 return 0;
298 204
299 case STATE_BODY_BIT_END: 205 case STATE_BODY_BIT_END:
300 if (!is_transition(&ev, &data->prev_ev)) 206 if (!is_transition(&ev, &ir_dev->raw->prev_ev))
301 break; 207 break;
302 208
303 if (data->count == data->wanted_bits) 209 if (data->count == data->wanted_bits)
@@ -348,54 +254,9 @@ out:
348 return -EINVAL; 254 return -EINVAL;
349} 255}
350 256
351static int ir_rc6_register(struct input_dev *input_dev)
352{
353 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
354 struct decoder_data *data;
355 int rc;
356
357 rc = sysfs_create_group(&ir_dev->dev.kobj, &decoder_attribute_group);
358 if (rc < 0)
359 return rc;
360
361 data = kzalloc(sizeof(*data), GFP_KERNEL);
362 if (!data) {
363 sysfs_remove_group(&ir_dev->dev.kobj, &decoder_attribute_group);
364 return -ENOMEM;
365 }
366
367 data->ir_dev = ir_dev;
368 data->enabled = 1;
369
370 spin_lock(&decoder_lock);
371 list_add_tail(&data->list, &decoder_list);
372 spin_unlock(&decoder_lock);
373
374 return 0;
375}
376
377static int ir_rc6_unregister(struct input_dev *input_dev)
378{
379 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
380 static struct decoder_data *data;
381
382 data = get_decoder_data(ir_dev);
383 if (!data)
384 return 0;
385
386 sysfs_remove_group(&ir_dev->dev.kobj, &decoder_attribute_group);
387
388 spin_lock(&decoder_lock);
389 list_del(&data->list);
390 spin_unlock(&decoder_lock);
391
392 return 0;
393}
394
395static struct ir_raw_handler rc6_handler = { 257static struct ir_raw_handler rc6_handler = {
258 .protocols = IR_TYPE_RC6,
396 .decode = ir_rc6_decode, 259 .decode = ir_rc6_decode,
397 .raw_register = ir_rc6_register,
398 .raw_unregister = ir_rc6_unregister,
399}; 260};
400 261
401static int __init ir_rc6_decode_init(void) 262static int __init ir_rc6_decode_init(void)
diff --git a/drivers/media/IR/ir-sony-decoder.c b/drivers/media/IR/ir-sony-decoder.c
index 9f440c5c060d..b9074f07c7a0 100644
--- a/drivers/media/IR/ir-sony-decoder.c
+++ b/drivers/media/IR/ir-sony-decoder.c
@@ -23,10 +23,6 @@
23#define SONY_BIT_SPACE (1 * SONY_UNIT) 23#define SONY_BIT_SPACE (1 * SONY_UNIT)
24#define SONY_TRAILER_SPACE (10 * SONY_UNIT) /* minimum */ 24#define SONY_TRAILER_SPACE (10 * SONY_UNIT) /* minimum */
25 25
26/* Used to register sony_decoder clients */
27static LIST_HEAD(decoder_list);
28static DEFINE_SPINLOCK(decoder_lock);
29
30enum sony_state { 26enum sony_state {
31 STATE_INACTIVE, 27 STATE_INACTIVE,
32 STATE_HEADER_SPACE, 28 STATE_HEADER_SPACE,
@@ -35,84 +31,6 @@ enum sony_state {
35 STATE_FINISHED, 31 STATE_FINISHED,
36}; 32};
37 33
38struct decoder_data {
39 struct list_head list;
40 struct ir_input_dev *ir_dev;
41 int enabled:1;
42
43 /* State machine control */
44 enum sony_state state;
45 u32 sony_bits;
46 unsigned count;
47};
48
49
50/**
51 * get_decoder_data() - gets decoder data
52 * @input_dev: input device
53 *
54 * Returns the struct decoder_data that corresponds to a device
55 */
56static struct decoder_data *get_decoder_data(struct ir_input_dev *ir_dev)
57{
58 struct decoder_data *data = NULL;
59
60 spin_lock(&decoder_lock);
61 list_for_each_entry(data, &decoder_list, list) {
62 if (data->ir_dev == ir_dev)
63 break;
64 }
65 spin_unlock(&decoder_lock);
66 return data;
67}
68
69static ssize_t store_enabled(struct device *d,
70 struct device_attribute *mattr,
71 const char *buf,
72 size_t len)
73{
74 unsigned long value;
75 struct ir_input_dev *ir_dev = dev_get_drvdata(d);
76 struct decoder_data *data = get_decoder_data(ir_dev);
77
78 if (!data)
79 return -EINVAL;
80
81 if (strict_strtoul(buf, 10, &value) || value > 1)
82 return -EINVAL;
83
84 data->enabled = value;
85
86 return len;
87}
88
89static ssize_t show_enabled(struct device *d,
90 struct device_attribute *mattr, char *buf)
91{
92 struct ir_input_dev *ir_dev = dev_get_drvdata(d);
93 struct decoder_data *data = get_decoder_data(ir_dev);
94
95 if (!data)
96 return -EINVAL;
97
98 if (data->enabled)
99 return sprintf(buf, "1\n");
100 else
101 return sprintf(buf, "0\n");
102}
103
104static DEVICE_ATTR(enabled, S_IRUGO | S_IWUSR, show_enabled, store_enabled);
105
106static struct attribute *decoder_attributes[] = {
107 &dev_attr_enabled.attr,
108 NULL
109};
110
111static struct attribute_group decoder_attribute_group = {
112 .name = "sony_decoder",
113 .attrs = decoder_attributes,
114};
115
116/** 34/**
117 * ir_sony_decode() - Decode one Sony pulse or space 35 * ir_sony_decode() - Decode one Sony pulse or space
118 * @input_dev: the struct input_dev descriptor of the device 36 * @input_dev: the struct input_dev descriptor of the device
@@ -122,16 +40,12 @@ static struct attribute_group decoder_attribute_group = {
122 */ 40 */
123static int ir_sony_decode(struct input_dev *input_dev, struct ir_raw_event ev) 41static int ir_sony_decode(struct input_dev *input_dev, struct ir_raw_event ev)
124{ 42{
125 struct decoder_data *data;
126 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); 43 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
44 struct sony_dec *data = &ir_dev->raw->sony;
127 u32 scancode; 45 u32 scancode;
128 u8 device, subdevice, function; 46 u8 device, subdevice, function;
129 47
130 data = get_decoder_data(ir_dev); 48 if (!(ir_dev->raw->enabled_protocols & IR_TYPE_SONY))
131 if (!data)
132 return -EINVAL;
133
134 if (!data->enabled)
135 return 0; 49 return 0;
136 50
137 if (IS_RESET(ev)) { 51 if (IS_RESET(ev)) {
@@ -172,9 +86,9 @@ static int ir_sony_decode(struct input_dev *input_dev, struct ir_raw_event ev)
172 if (!ev.pulse) 86 if (!ev.pulse)
173 break; 87 break;
174 88
175 data->sony_bits <<= 1; 89 data->bits <<= 1;
176 if (eq_margin(ev.duration, SONY_BIT_1_PULSE, SONY_UNIT / 2)) 90 if (eq_margin(ev.duration, SONY_BIT_1_PULSE, SONY_UNIT / 2))
177 data->sony_bits |= 1; 91 data->bits |= 1;
178 else if (!eq_margin(ev.duration, SONY_BIT_0_PULSE, SONY_UNIT / 2)) 92 else if (!eq_margin(ev.duration, SONY_BIT_0_PULSE, SONY_UNIT / 2))
179 break; 93 break;
180 94
@@ -208,19 +122,19 @@ static int ir_sony_decode(struct input_dev *input_dev, struct ir_raw_event ev)
208 122
209 switch (data->count) { 123 switch (data->count) {
210 case 12: 124 case 12:
211 device = bitrev8((data->sony_bits << 3) & 0xF8); 125 device = bitrev8((data->bits << 3) & 0xF8);
212 subdevice = 0; 126 subdevice = 0;
213 function = bitrev8((data->sony_bits >> 4) & 0xFE); 127 function = bitrev8((data->bits >> 4) & 0xFE);
214 break; 128 break;
215 case 15: 129 case 15:
216 device = bitrev8((data->sony_bits >> 0) & 0xFF); 130 device = bitrev8((data->bits >> 0) & 0xFF);
217 subdevice = 0; 131 subdevice = 0;
218 function = bitrev8((data->sony_bits >> 7) & 0xFD); 132 function = bitrev8((data->bits >> 7) & 0xFD);
219 break; 133 break;
220 case 20: 134 case 20:
221 device = bitrev8((data->sony_bits >> 5) & 0xF8); 135 device = bitrev8((data->bits >> 5) & 0xF8);
222 subdevice = bitrev8((data->sony_bits >> 0) & 0xFF); 136 subdevice = bitrev8((data->bits >> 0) & 0xFF);
223 function = bitrev8((data->sony_bits >> 12) & 0xFE); 137 function = bitrev8((data->bits >> 12) & 0xFE);
224 break; 138 break;
225 default: 139 default:
226 IR_dprintk(1, "Sony invalid bitcount %u\n", data->count); 140 IR_dprintk(1, "Sony invalid bitcount %u\n", data->count);
@@ -241,54 +155,9 @@ out:
241 return -EINVAL; 155 return -EINVAL;
242} 156}
243 157
244static int ir_sony_register(struct input_dev *input_dev)
245{
246 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
247 struct decoder_data *data;
248 int rc;
249
250 rc = sysfs_create_group(&ir_dev->dev.kobj, &decoder_attribute_group);
251 if (rc < 0)
252 return rc;
253
254 data = kzalloc(sizeof(*data), GFP_KERNEL);
255 if (!data) {
256 sysfs_remove_group(&ir_dev->dev.kobj, &decoder_attribute_group);
257 return -ENOMEM;
258 }
259
260 data->ir_dev = ir_dev;
261 data->enabled = 1;
262
263 spin_lock(&decoder_lock);
264 list_add_tail(&data->list, &decoder_list);
265 spin_unlock(&decoder_lock);
266
267 return 0;
268}
269
270static int ir_sony_unregister(struct input_dev *input_dev)
271{
272 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
273 static struct decoder_data *data;
274
275 data = get_decoder_data(ir_dev);
276 if (!data)
277 return 0;
278
279 sysfs_remove_group(&ir_dev->dev.kobj, &decoder_attribute_group);
280
281 spin_lock(&decoder_lock);
282 list_del(&data->list);
283 spin_unlock(&decoder_lock);
284
285 return 0;
286}
287
288static struct ir_raw_handler sony_handler = { 158static struct ir_raw_handler sony_handler = {
159 .protocols = IR_TYPE_SONY,
289 .decode = ir_sony_decode, 160 .decode = ir_sony_decode,
290 .raw_register = ir_sony_register,
291 .raw_unregister = ir_sony_unregister,
292}; 161};
293 162
294static int __init ir_sony_decode_init(void) 163static int __init ir_sony_decode_init(void)
diff --git a/drivers/media/IR/ir-sysfs.c b/drivers/media/IR/ir-sysfs.c
index 2098dd1488e0..6273047e915b 100644
--- a/drivers/media/IR/ir-sysfs.c
+++ b/drivers/media/IR/ir-sysfs.c
@@ -33,125 +33,172 @@ static struct class ir_input_class = {
33 .devnode = ir_devnode, 33 .devnode = ir_devnode,
34}; 34};
35 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_LIRC, "lirc" },
47};
48
49#define PROTO_NONE "none"
50
36/** 51/**
37 * show_protocol() - shows the current IR protocol 52 * show_protocols() - shows the current IR protocol(s)
38 * @d: the device descriptor 53 * @d: the device descriptor
39 * @mattr: the device attribute struct (unused) 54 * @mattr: the device attribute struct (unused)
40 * @buf: a pointer to the output buffer 55 * @buf: a pointer to the output buffer
41 * 56 *
42 * This routine is a callback routine for input read the IR protocol type. 57 * This routine is a callback routine for input read the IR protocol type(s).
43 * it is trigged by reading /sys/class/rc/rc?/current_protocol. 58 * it is trigged by reading /sys/class/rc/rc?/protocols.
44 * It returns the protocol name, as understood by the driver. 59 * It returns the protocol names of supported protocols.
60 * Enabled protocols are printed in brackets.
45 */ 61 */
46static ssize_t show_protocol(struct device *d, 62static ssize_t show_protocols(struct device *d,
47 struct device_attribute *mattr, char *buf) 63 struct device_attribute *mattr, char *buf)
48{ 64{
49 char *s;
50 struct ir_input_dev *ir_dev = dev_get_drvdata(d); 65 struct ir_input_dev *ir_dev = dev_get_drvdata(d);
51 u64 ir_type = ir_dev->rc_tab.ir_type; 66 u64 allowed, enabled;
52 67 char *tmp = buf;
53 IR_dprintk(1, "Current protocol is %lld\n", (long long)ir_type); 68 int i;
54 69
55 /* FIXME: doesn't support multiple protocols at the same time */ 70 if (ir_dev->props->driver_type == RC_DRIVER_SCANCODE) {
56 if (ir_type == IR_TYPE_UNKNOWN) 71 enabled = ir_dev->rc_tab.ir_type;
57 s = "Unknown"; 72 allowed = ir_dev->props->allowed_protos;
58 else if (ir_type == IR_TYPE_RC5) 73 } else {
59 s = "rc-5"; 74 enabled = ir_dev->raw->enabled_protocols;
60 else if (ir_type == IR_TYPE_NEC) 75 allowed = ir_raw_get_allowed_protocols();
61 s = "nec"; 76 }
62 else if (ir_type == IR_TYPE_RC6) 77
63 s = "rc6"; 78 IR_dprintk(1, "allowed - 0x%llx, enabled - 0x%llx\n",
64 else if (ir_type == IR_TYPE_JVC) 79 (long long)allowed,
65 s = "jvc"; 80 (long long)enabled);
66 else if (ir_type == IR_TYPE_SONY)
67 s = "sony";
68 else
69 s = "other";
70 81
71 return sprintf(buf, "%s\n", s); 82 for (i = 0; i < ARRAY_SIZE(proto_names); i++) {
83 if (allowed & enabled & proto_names[i].type)
84 tmp += sprintf(tmp, "[%s] ", proto_names[i].name);
85 else if (allowed & proto_names[i].type)
86 tmp += sprintf(tmp, "%s ", proto_names[i].name);
87 }
88
89 if (tmp != buf)
90 tmp--;
91 *tmp = '\n';
92 return tmp + 1 - buf;
72} 93}
73 94
74/** 95/**
75 * store_protocol() - shows the current IR protocol 96 * store_protocols() - changes the current IR protocol(s)
76 * @d: the device descriptor 97 * @d: the device descriptor
77 * @mattr: the device attribute struct (unused) 98 * @mattr: the device attribute struct (unused)
78 * @buf: a pointer to the input buffer 99 * @buf: a pointer to the input buffer
79 * @len: length of the input buffer 100 * @len: length of the input buffer
80 * 101 *
81 * This routine is a callback routine for changing the IR protocol type. 102 * This routine is a callback routine for changing the IR protocol type.
82 * it is trigged by reading /sys/class/rc/rc?/current_protocol. 103 * It is trigged by writing to /sys/class/rc/rc?/protocols.
83 * It changes the IR the protocol name, if the IR type is recognized 104 * Writing "+proto" will add a protocol to the list of enabled protocols.
84 * by the driver. 105 * Writing "-proto" will remove a protocol from the list of enabled protocols.
85 * If an unknown protocol name is used, returns -EINVAL. 106 * Writing "proto" will enable only "proto".
107 * Writing "none" will disable all protocols.
108 * Returns -EINVAL if an invalid protocol combination or unknown protocol name
109 * is used, otherwise @len.
86 */ 110 */
87static ssize_t store_protocol(struct device *d, 111static ssize_t store_protocols(struct device *d,
88 struct device_attribute *mattr, 112 struct device_attribute *mattr,
89 const char *data, 113 const char *data,
90 size_t len) 114 size_t len)
91{ 115{
92 struct ir_input_dev *ir_dev = dev_get_drvdata(d); 116 struct ir_input_dev *ir_dev = dev_get_drvdata(d);
93 u64 ir_type = 0; 117 bool enable, disable;
94 int rc = -EINVAL; 118 const char *tmp;
119 u64 type;
120 u64 mask;
121 int rc, i, count = 0;
95 unsigned long flags; 122 unsigned long flags;
96 char *buf; 123
97 124 if (ir_dev->props->driver_type == RC_DRIVER_SCANCODE)
98 while ((buf = strsep((char **) &data, " \n")) != NULL) { 125 type = ir_dev->rc_tab.ir_type;
99 if (!strcasecmp(buf, "rc-5") || !strcasecmp(buf, "rc5")) 126 else
100 ir_type |= IR_TYPE_RC5; 127 type = ir_dev->raw->enabled_protocols;
101 if (!strcasecmp(buf, "nec")) 128
102 ir_type |= IR_TYPE_NEC; 129 while ((tmp = strsep((char **) &data, " \n")) != NULL) {
103 if (!strcasecmp(buf, "jvc")) 130 if (!*tmp)
104 ir_type |= IR_TYPE_JVC; 131 break;
105 if (!strcasecmp(buf, "sony")) 132
106 ir_type |= IR_TYPE_SONY; 133 if (*tmp == '+') {
134 enable = true;
135 disable = false;
136 tmp++;
137 } else if (*tmp == '-') {
138 enable = false;
139 disable = true;
140 tmp++;
141 } else {
142 enable = false;
143 disable = false;
144 }
145
146 if (!enable && !disable && !strncasecmp(tmp, PROTO_NONE, sizeof(PROTO_NONE))) {
147 tmp += sizeof(PROTO_NONE);
148 mask = 0;
149 count++;
150 } else {
151 for (i = 0; i < ARRAY_SIZE(proto_names); i++) {
152 if (!strncasecmp(tmp, proto_names[i].name, strlen(proto_names[i].name))) {
153 tmp += strlen(proto_names[i].name);
154 mask = proto_names[i].type;
155 break;
156 }
157 }
158 if (i == ARRAY_SIZE(proto_names)) {
159 IR_dprintk(1, "Unknown protocol: '%s'\n", tmp);
160 return -EINVAL;
161 }
162 count++;
163 }
164
165 if (enable)
166 type |= mask;
167 else if (disable)
168 type &= ~mask;
169 else
170 type = mask;
107 } 171 }
108 172
109 if (!ir_type) { 173 if (!count) {
110 IR_dprintk(1, "Unknown protocol\n"); 174 IR_dprintk(1, "Protocol not specified\n");
111 return -EINVAL; 175 return -EINVAL;
112 } 176 }
113 177
114 if (ir_dev->props && ir_dev->props->change_protocol) 178 if (ir_dev->props && ir_dev->props->change_protocol) {
115 rc = ir_dev->props->change_protocol(ir_dev->props->priv, 179 rc = ir_dev->props->change_protocol(ir_dev->props->priv,
116 ir_type); 180 type);
117 181 if (rc < 0) {
118 if (rc < 0) { 182 IR_dprintk(1, "Error setting protocols to 0x%llx\n",
119 IR_dprintk(1, "Error setting protocol to %lld\n", 183 (long long)type);
120 (long long)ir_type); 184 return -EINVAL;
121 return -EINVAL; 185 }
122 } 186 }
123 187
124 spin_lock_irqsave(&ir_dev->rc_tab.lock, flags); 188 if (ir_dev->props->driver_type == RC_DRIVER_SCANCODE) {
125 ir_dev->rc_tab.ir_type = ir_type; 189 spin_lock_irqsave(&ir_dev->rc_tab.lock, flags);
126 spin_unlock_irqrestore(&ir_dev->rc_tab.lock, flags); 190 ir_dev->rc_tab.ir_type = type;
191 spin_unlock_irqrestore(&ir_dev->rc_tab.lock, flags);
192 } else {
193 ir_dev->raw->enabled_protocols = type;
194 }
127 195
128 IR_dprintk(1, "Current protocol(s) is(are) %lld\n", 196 IR_dprintk(1, "Current protocol(s): 0x%llx\n",
129 (long long)ir_type); 197 (long long)type);
130 198
131 return len; 199 return len;
132} 200}
133 201
134static ssize_t show_supported_protocols(struct device *d,
135 struct device_attribute *mattr, char *buf)
136{
137 char *orgbuf = buf;
138 struct ir_input_dev *ir_dev = dev_get_drvdata(d);
139
140 /* FIXME: doesn't support multiple protocols at the same time */
141 if (ir_dev->props->allowed_protos == IR_TYPE_UNKNOWN)
142 buf += sprintf(buf, "unknown ");
143 if (ir_dev->props->allowed_protos & IR_TYPE_RC5)
144 buf += sprintf(buf, "rc-5 ");
145 if (ir_dev->props->allowed_protos & IR_TYPE_NEC)
146 buf += sprintf(buf, "nec ");
147 if (buf == orgbuf)
148 buf += sprintf(buf, "other ");
149
150 buf += sprintf(buf - 1, "\n");
151
152 return buf - orgbuf;
153}
154
155#define ADD_HOTPLUG_VAR(fmt, val...) \ 202#define ADD_HOTPLUG_VAR(fmt, val...) \
156 do { \ 203 do { \
157 int err = add_uevent_var(env, fmt, val); \ 204 int err = add_uevent_var(env, fmt, val); \
@@ -159,7 +206,7 @@ static ssize_t show_supported_protocols(struct device *d,
159 return err; \ 206 return err; \
160 } while (0) 207 } while (0)
161 208
162static int ir_dev_uevent(struct device *device, struct kobj_uevent_env *env) 209static int rc_dev_uevent(struct device *device, struct kobj_uevent_env *env)
163{ 210{
164 struct ir_input_dev *ir_dev = dev_get_drvdata(device); 211 struct ir_input_dev *ir_dev = dev_get_drvdata(device);
165 212
@@ -174,34 +221,26 @@ static int ir_dev_uevent(struct device *device, struct kobj_uevent_env *env)
174/* 221/*
175 * Static device attribute struct with the sysfs attributes for IR's 222 * Static device attribute struct with the sysfs attributes for IR's
176 */ 223 */
177static DEVICE_ATTR(protocol, S_IRUGO | S_IWUSR, 224static DEVICE_ATTR(protocols, S_IRUGO | S_IWUSR,
178 show_protocol, store_protocol); 225 show_protocols, store_protocols);
179 226
180static DEVICE_ATTR(supported_protocols, S_IRUGO | S_IWUSR, 227static struct attribute *rc_dev_attrs[] = {
181 show_supported_protocols, NULL); 228 &dev_attr_protocols.attr,
182
183static struct attribute *ir_hw_dev_attrs[] = {
184 &dev_attr_protocol.attr,
185 &dev_attr_supported_protocols.attr,
186 NULL, 229 NULL,
187}; 230};
188 231
189static struct attribute_group ir_hw_dev_attr_grp = { 232static struct attribute_group rc_dev_attr_grp = {
190 .attrs = ir_hw_dev_attrs, 233 .attrs = rc_dev_attrs,
191}; 234};
192 235
193static const struct attribute_group *ir_hw_dev_attr_groups[] = { 236static const struct attribute_group *rc_dev_attr_groups[] = {
194 &ir_hw_dev_attr_grp, 237 &rc_dev_attr_grp,
195 NULL 238 NULL
196}; 239};
197 240
198static struct device_type rc_dev_type = { 241static struct device_type rc_dev_type = {
199 .groups = ir_hw_dev_attr_groups, 242 .groups = rc_dev_attr_groups,
200 .uevent = ir_dev_uevent, 243 .uevent = rc_dev_uevent,
201};
202
203static struct device_type ir_raw_dev_type = {
204 .uevent = ir_dev_uevent,
205}; 244};
206 245
207/** 246/**
@@ -221,11 +260,7 @@ int ir_register_class(struct input_dev *input_dev)
221 if (unlikely(devno < 0)) 260 if (unlikely(devno < 0))
222 return devno; 261 return devno;
223 262
224 if (ir_dev->props) { 263 ir_dev->dev.type = &rc_dev_type;
225 if (ir_dev->props->driver_type == RC_DRIVER_SCANCODE)
226 ir_dev->dev.type = &rc_dev_type;
227 } else
228 ir_dev->dev.type = &ir_raw_dev_type;
229 264
230 ir_dev->dev.class = &ir_input_class; 265 ir_dev->dev.class = &ir_input_class;
231 ir_dev->dev.parent = input_dev->dev.parent; 266 ir_dev->dev.parent = input_dev->dev.parent;
diff --git a/drivers/media/IR/keymaps/Makefile b/drivers/media/IR/keymaps/Makefile
index aea649fbcf5a..cbee06243b51 100644
--- a/drivers/media/IR/keymaps/Makefile
+++ b/drivers/media/IR/keymaps/Makefile
@@ -14,6 +14,8 @@ obj-$(CONFIG_RC_MAP) += rc-adstech-dvb-t-pci.o \
14 rc-budget-ci-old.o \ 14 rc-budget-ci-old.o \
15 rc-cinergy-1400.o \ 15 rc-cinergy-1400.o \
16 rc-cinergy.o \ 16 rc-cinergy.o \
17 rc-dib0700-nec.o \
18 rc-dib0700-rc5.o \
17 rc-dm1105-nec.o \ 19 rc-dm1105-nec.o \
18 rc-dntv-live-dvb-t.o \ 20 rc-dntv-live-dvb-t.o \
19 rc-dntv-live-dvbt-pro.o \ 21 rc-dntv-live-dvbt-pro.o \
@@ -37,6 +39,7 @@ obj-$(CONFIG_RC_MAP) += rc-adstech-dvb-t-pci.o \
37 rc-kaiomy.o \ 39 rc-kaiomy.o \
38 rc-kworld-315u.o \ 40 rc-kworld-315u.o \
39 rc-kworld-plus-tv-analog.o \ 41 rc-kworld-plus-tv-analog.o \
42 rc-lirc.o \
40 rc-manli.o \ 43 rc-manli.o \
41 rc-msi-tvanywhere.o \ 44 rc-msi-tvanywhere.o \
42 rc-msi-tvanywhere-plus.o \ 45 rc-msi-tvanywhere-plus.o \
@@ -57,6 +60,7 @@ obj-$(CONFIG_RC_MAP) += rc-adstech-dvb-t-pci.o \
57 rc-pv951.o \ 60 rc-pv951.o \
58 rc-rc5-hauppauge-new.o \ 61 rc-rc5-hauppauge-new.o \
59 rc-rc5-tv.o \ 62 rc-rc5-tv.o \
63 rc-rc6-mce.o \
60 rc-real-audio-220-32-keys.o \ 64 rc-real-audio-220-32-keys.o \
61 rc-tbs-nec.o \ 65 rc-tbs-nec.o \
62 rc-terratec-cinergy-xs.o \ 66 rc-terratec-cinergy-xs.o \
diff --git a/drivers/media/IR/keymaps/rc-dib0700-nec.c b/drivers/media/IR/keymaps/rc-dib0700-nec.c
new file mode 100644
index 000000000000..ae1832038fbe
--- /dev/null
+++ b/drivers/media/IR/keymaps/rc-dib0700-nec.c
@@ -0,0 +1,124 @@
1/* rc-dvb0700-big.c - Keytable for devices in dvb0700
2 *
3 * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.com>
4 *
5 * TODO: This table is a real mess, as it merges RC codes from several
6 * devices into a big table. It also has both RC-5 and NEC codes inside.
7 * It should be broken into small tables, and the protocols should properly
8 * be indentificated.
9 *
10 * The table were imported from dib0700_devices.c.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 */
17
18#include <media/rc-map.h>
19
20static struct ir_scancode dib0700_nec_table[] = {
21 /* Key codes for the Pixelview SBTVD remote */
22 { 0x8613, KEY_MUTE },
23 { 0x8612, KEY_POWER },
24 { 0x8601, KEY_1 },
25 { 0x8602, KEY_2 },
26 { 0x8603, KEY_3 },
27 { 0x8604, KEY_4 },
28 { 0x8605, KEY_5 },
29 { 0x8606, KEY_6 },
30 { 0x8607, KEY_7 },
31 { 0x8608, KEY_8 },
32 { 0x8609, KEY_9 },
33 { 0x8600, KEY_0 },
34 { 0x860d, KEY_CHANNELUP },
35 { 0x8619, KEY_CHANNELDOWN },
36 { 0x8610, KEY_VOLUMEUP },
37 { 0x860c, KEY_VOLUMEDOWN },
38
39 { 0x860a, KEY_CAMERA },
40 { 0x860b, KEY_ZOOM },
41 { 0x861b, KEY_BACKSPACE },
42 { 0x8615, KEY_ENTER },
43
44 { 0x861d, KEY_UP },
45 { 0x861e, KEY_DOWN },
46 { 0x860e, KEY_LEFT },
47 { 0x860f, KEY_RIGHT },
48
49 { 0x8618, KEY_RECORD },
50 { 0x861a, KEY_STOP },
51
52 /* Key codes for the EvolutePC TVWay+ remote */
53 { 0x7a00, KEY_MENU },
54 { 0x7a01, KEY_RECORD },
55 { 0x7a02, KEY_PLAY },
56 { 0x7a03, KEY_STOP },
57 { 0x7a10, KEY_CHANNELUP },
58 { 0x7a11, KEY_CHANNELDOWN },
59 { 0x7a12, KEY_VOLUMEUP },
60 { 0x7a13, KEY_VOLUMEDOWN },
61 { 0x7a40, KEY_POWER },
62 { 0x7a41, KEY_MUTE },
63
64 /* Key codes for the Elgato EyeTV Diversity silver remote */
65 { 0x4501, KEY_POWER },
66 { 0x4502, KEY_MUTE },
67 { 0x4503, KEY_1 },
68 { 0x4504, KEY_2 },
69 { 0x4505, KEY_3 },
70 { 0x4506, KEY_4 },
71 { 0x4507, KEY_5 },
72 { 0x4508, KEY_6 },
73 { 0x4509, KEY_7 },
74 { 0x450a, KEY_8 },
75 { 0x450b, KEY_9 },
76 { 0x450c, KEY_LAST },
77 { 0x450d, KEY_0 },
78 { 0x450e, KEY_ENTER },
79 { 0x450f, KEY_RED },
80 { 0x4510, KEY_CHANNELUP },
81 { 0x4511, KEY_GREEN },
82 { 0x4512, KEY_VOLUMEDOWN },
83 { 0x4513, KEY_OK },
84 { 0x4514, KEY_VOLUMEUP },
85 { 0x4515, KEY_YELLOW },
86 { 0x4516, KEY_CHANNELDOWN },
87 { 0x4517, KEY_BLUE },
88 { 0x4518, KEY_LEFT }, /* Skip backwards */
89 { 0x4519, KEY_PLAYPAUSE },
90 { 0x451a, KEY_RIGHT }, /* Skip forward */
91 { 0x451b, KEY_REWIND },
92 { 0x451c, KEY_L }, /* Live */
93 { 0x451d, KEY_FASTFORWARD },
94 { 0x451e, KEY_STOP }, /* 'Reveal' for Teletext */
95 { 0x451f, KEY_MENU }, /* KEY_TEXT for Teletext */
96 { 0x4540, KEY_RECORD }, /* Font 'Size' for Teletext */
97 { 0x4541, KEY_SCREEN }, /* Full screen toggle, 'Hold' for Teletext */
98 { 0x4542, KEY_SELECT }, /* Select video input, 'Select' for Teletext */
99};
100
101static struct rc_keymap dib0700_nec_map = {
102 .map = {
103 .scan = dib0700_nec_table,
104 .size = ARRAY_SIZE(dib0700_nec_table),
105 .ir_type = IR_TYPE_NEC,
106 .name = RC_MAP_DIB0700_NEC_TABLE,
107 }
108};
109
110static int __init init_rc_map(void)
111{
112 return ir_register_map(&dib0700_nec_map);
113}
114
115static void __exit exit_rc_map(void)
116{
117 ir_unregister_map(&dib0700_nec_map);
118}
119
120module_init(init_rc_map)
121module_exit(exit_rc_map)
122
123MODULE_LICENSE("GPL");
124MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-dib0700-rc5.c b/drivers/media/IR/keymaps/rc-dib0700-rc5.c
new file mode 100644
index 000000000000..4a4797cfd77d
--- /dev/null
+++ b/drivers/media/IR/keymaps/rc-dib0700-rc5.c
@@ -0,0 +1,235 @@
1/* rc-dvb0700-big.c - Keytable for devices in dvb0700
2 *
3 * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.com>
4 *
5 * TODO: This table is a real mess, as it merges RC codes from several
6 * devices into a big table. It also has both RC-5 and NEC codes inside.
7 * It should be broken into small tables, and the protocols should properly
8 * be indentificated.
9 *
10 * The table were imported from dib0700_devices.c.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 */
17
18#include <media/rc-map.h>
19
20static struct ir_scancode dib0700_rc5_table[] = {
21 /* Key codes for the tiny Pinnacle remote*/
22 { 0x0700, KEY_MUTE },
23 { 0x0701, KEY_MENU }, /* Pinnacle logo */
24 { 0x0739, KEY_POWER },
25 { 0x0703, KEY_VOLUMEUP },
26 { 0x0709, KEY_VOLUMEDOWN },
27 { 0x0706, KEY_CHANNELUP },
28 { 0x070c, KEY_CHANNELDOWN },
29 { 0x070f, KEY_1 },
30 { 0x0715, KEY_2 },
31 { 0x0710, KEY_3 },
32 { 0x0718, KEY_4 },
33 { 0x071b, KEY_5 },
34 { 0x071e, KEY_6 },
35 { 0x0711, KEY_7 },
36 { 0x0721, KEY_8 },
37 { 0x0712, KEY_9 },
38 { 0x0727, KEY_0 },
39 { 0x0724, KEY_SCREEN }, /* 'Square' key */
40 { 0x072a, KEY_TEXT }, /* 'T' key */
41 { 0x072d, KEY_REWIND },
42 { 0x0730, KEY_PLAY },
43 { 0x0733, KEY_FASTFORWARD },
44 { 0x0736, KEY_RECORD },
45 { 0x073c, KEY_STOP },
46 { 0x073f, KEY_CANCEL }, /* '?' key */
47
48 /* Key codes for the Terratec Cinergy DT XS Diversity, similar to cinergyT2.c */
49 { 0xeb01, KEY_POWER },
50 { 0xeb02, KEY_1 },
51 { 0xeb03, KEY_2 },
52 { 0xeb04, KEY_3 },
53 { 0xeb05, KEY_4 },
54 { 0xeb06, KEY_5 },
55 { 0xeb07, KEY_6 },
56 { 0xeb08, KEY_7 },
57 { 0xeb09, KEY_8 },
58 { 0xeb0a, KEY_9 },
59 { 0xeb0b, KEY_VIDEO },
60 { 0xeb0c, KEY_0 },
61 { 0xeb0d, KEY_REFRESH },
62 { 0xeb0f, KEY_EPG },
63 { 0xeb10, KEY_UP },
64 { 0xeb11, KEY_LEFT },
65 { 0xeb12, KEY_OK },
66 { 0xeb13, KEY_RIGHT },
67 { 0xeb14, KEY_DOWN },
68 { 0xeb16, KEY_INFO },
69 { 0xeb17, KEY_RED },
70 { 0xeb18, KEY_GREEN },
71 { 0xeb19, KEY_YELLOW },
72 { 0xeb1a, KEY_BLUE },
73 { 0xeb1b, KEY_CHANNELUP },
74 { 0xeb1c, KEY_VOLUMEUP },
75 { 0xeb1d, KEY_MUTE },
76 { 0xeb1e, KEY_VOLUMEDOWN },
77 { 0xeb1f, KEY_CHANNELDOWN },
78 { 0xeb40, KEY_PAUSE },
79 { 0xeb41, KEY_HOME },
80 { 0xeb42, KEY_MENU }, /* DVD Menu */
81 { 0xeb43, KEY_SUBTITLE },
82 { 0xeb44, KEY_TEXT }, /* Teletext */
83 { 0xeb45, KEY_DELETE },
84 { 0xeb46, KEY_TV },
85 { 0xeb47, KEY_DVD },
86 { 0xeb48, KEY_STOP },
87 { 0xeb49, KEY_VIDEO },
88 { 0xeb4a, KEY_AUDIO }, /* Music */
89 { 0xeb4b, KEY_SCREEN }, /* Pic */
90 { 0xeb4c, KEY_PLAY },
91 { 0xeb4d, KEY_BACK },
92 { 0xeb4e, KEY_REWIND },
93 { 0xeb4f, KEY_FASTFORWARD },
94 { 0xeb54, KEY_PREVIOUS },
95 { 0xeb58, KEY_RECORD },
96 { 0xeb5c, KEY_NEXT },
97
98 /* Key codes for the Haupauge WinTV Nova-TD, copied from nova-t-usb2.c (Nova-T USB2) */
99 { 0x1e00, KEY_0 },
100 { 0x1e01, KEY_1 },
101 { 0x1e02, KEY_2 },
102 { 0x1e03, KEY_3 },
103 { 0x1e04, KEY_4 },
104 { 0x1e05, KEY_5 },
105 { 0x1e06, KEY_6 },
106 { 0x1e07, KEY_7 },
107 { 0x1e08, KEY_8 },
108 { 0x1e09, KEY_9 },
109 { 0x1e0a, KEY_KPASTERISK },
110 { 0x1e0b, KEY_RED },
111 { 0x1e0c, KEY_RADIO },
112 { 0x1e0d, KEY_MENU },
113 { 0x1e0e, KEY_GRAVE }, /* # */
114 { 0x1e0f, KEY_MUTE },
115 { 0x1e10, KEY_VOLUMEUP },
116 { 0x1e11, KEY_VOLUMEDOWN },
117 { 0x1e12, KEY_CHANNEL },
118 { 0x1e14, KEY_UP },
119 { 0x1e15, KEY_DOWN },
120 { 0x1e16, KEY_LEFT },
121 { 0x1e17, KEY_RIGHT },
122 { 0x1e18, KEY_VIDEO },
123 { 0x1e19, KEY_AUDIO },
124 { 0x1e1a, KEY_MEDIA },
125 { 0x1e1b, KEY_EPG },
126 { 0x1e1c, KEY_TV },
127 { 0x1e1e, KEY_NEXT },
128 { 0x1e1f, KEY_BACK },
129 { 0x1e20, KEY_CHANNELUP },
130 { 0x1e21, KEY_CHANNELDOWN },
131 { 0x1e24, KEY_LAST }, /* Skip backwards */
132 { 0x1e25, KEY_OK },
133 { 0x1e29, KEY_BLUE},
134 { 0x1e2e, KEY_GREEN },
135 { 0x1e30, KEY_PAUSE },
136 { 0x1e32, KEY_REWIND },
137 { 0x1e34, KEY_FASTFORWARD },
138 { 0x1e35, KEY_PLAY },
139 { 0x1e36, KEY_STOP },
140 { 0x1e37, KEY_RECORD },
141 { 0x1e38, KEY_YELLOW },
142 { 0x1e3b, KEY_GOTO },
143 { 0x1e3d, KEY_POWER },
144
145 /* Key codes for the Leadtek Winfast DTV Dongle */
146 { 0x0042, KEY_POWER },
147 { 0x077c, KEY_TUNER },
148 { 0x0f4e, KEY_PRINT }, /* PREVIEW */
149 { 0x0840, KEY_SCREEN }, /* full screen toggle*/
150 { 0x0f71, KEY_DOT }, /* frequency */
151 { 0x0743, KEY_0 },
152 { 0x0c41, KEY_1 },
153 { 0x0443, KEY_2 },
154 { 0x0b7f, KEY_3 },
155 { 0x0e41, KEY_4 },
156 { 0x0643, KEY_5 },
157 { 0x097f, KEY_6 },
158 { 0x0d7e, KEY_7 },
159 { 0x057c, KEY_8 },
160 { 0x0a40, KEY_9 },
161 { 0x0e4e, KEY_CLEAR },
162 { 0x047c, KEY_CHANNEL }, /* show channel number */
163 { 0x0f41, KEY_LAST }, /* recall */
164 { 0x0342, KEY_MUTE },
165 { 0x064c, KEY_RESERVED }, /* PIP button*/
166 { 0x0172, KEY_SHUFFLE }, /* SNAPSHOT */
167 { 0x0c4e, KEY_PLAYPAUSE }, /* TIMESHIFT */
168 { 0x0b70, KEY_RECORD },
169 { 0x037d, KEY_VOLUMEUP },
170 { 0x017d, KEY_VOLUMEDOWN },
171 { 0x0242, KEY_CHANNELUP },
172 { 0x007d, KEY_CHANNELDOWN },
173
174 /* Key codes for Nova-TD "credit card" remote control. */
175 { 0x1d00, KEY_0 },
176 { 0x1d01, KEY_1 },
177 { 0x1d02, KEY_2 },
178 { 0x1d03, KEY_3 },
179 { 0x1d04, KEY_4 },
180 { 0x1d05, KEY_5 },
181 { 0x1d06, KEY_6 },
182 { 0x1d07, KEY_7 },
183 { 0x1d08, KEY_8 },
184 { 0x1d09, KEY_9 },
185 { 0x1d0a, KEY_TEXT },
186 { 0x1d0d, KEY_MENU },
187 { 0x1d0f, KEY_MUTE },
188 { 0x1d10, KEY_VOLUMEUP },
189 { 0x1d11, KEY_VOLUMEDOWN },
190 { 0x1d12, KEY_CHANNEL },
191 { 0x1d14, KEY_UP },
192 { 0x1d15, KEY_DOWN },
193 { 0x1d16, KEY_LEFT },
194 { 0x1d17, KEY_RIGHT },
195 { 0x1d1c, KEY_TV },
196 { 0x1d1e, KEY_NEXT },
197 { 0x1d1f, KEY_BACK },
198 { 0x1d20, KEY_CHANNELUP },
199 { 0x1d21, KEY_CHANNELDOWN },
200 { 0x1d24, KEY_LAST },
201 { 0x1d25, KEY_OK },
202 { 0x1d30, KEY_PAUSE },
203 { 0x1d32, KEY_REWIND },
204 { 0x1d34, KEY_FASTFORWARD },
205 { 0x1d35, KEY_PLAY },
206 { 0x1d36, KEY_STOP },
207 { 0x1d37, KEY_RECORD },
208 { 0x1d3b, KEY_GOTO },
209 { 0x1d3d, KEY_POWER },
210};
211
212static struct rc_keymap dib0700_rc5_map = {
213 .map = {
214 .scan = dib0700_rc5_table,
215 .size = ARRAY_SIZE(dib0700_rc5_table),
216 .ir_type = IR_TYPE_RC5,
217 .name = RC_MAP_DIB0700_RC5_TABLE,
218 }
219};
220
221static int __init init_rc_map(void)
222{
223 return ir_register_map(&dib0700_rc5_map);
224}
225
226static void __exit exit_rc_map(void)
227{
228 ir_unregister_map(&dib0700_rc5_map);
229}
230
231module_init(init_rc_map)
232module_exit(exit_rc_map)
233
234MODULE_LICENSE("GPL");
235MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-lirc.c b/drivers/media/IR/keymaps/rc-lirc.c
new file mode 100644
index 000000000000..43fcf9035082
--- /dev/null
+++ b/drivers/media/IR/keymaps/rc-lirc.c
@@ -0,0 +1,41 @@
1/* rc-lirc.c - Empty dummy keytable, for use when its preferred to pass
2 * all raw IR data to the lirc userspace decoder.
3 *
4 * Copyright (c) 2010 by Jarod Wilson <jarod@redhat.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */
11
12#include <media/ir-core.h>
13
14static struct ir_scancode lirc[] = {
15 { },
16};
17
18static struct rc_keymap lirc_map = {
19 .map = {
20 .scan = lirc,
21 .size = ARRAY_SIZE(lirc),
22 .ir_type = IR_TYPE_LIRC,
23 .name = RC_MAP_LIRC,
24 }
25};
26
27static int __init init_rc_map_lirc(void)
28{
29 return ir_register_map(&lirc_map);
30}
31
32static void __exit exit_rc_map_lirc(void)
33{
34 ir_unregister_map(&lirc_map);
35}
36
37module_init(init_rc_map_lirc)
38module_exit(exit_rc_map_lirc)
39
40MODULE_LICENSE("GPL");
41MODULE_AUTHOR("Jarod Wilson <jarod@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-rc6-mce.c b/drivers/media/IR/keymaps/rc-rc6-mce.c
new file mode 100644
index 000000000000..c6726a8039be
--- /dev/null
+++ b/drivers/media/IR/keymaps/rc-rc6-mce.c
@@ -0,0 +1,105 @@
1/* rc-rc6-mce.c - Keytable for Windows Media Center RC-6 remotes for use
2 * with the Media Center Edition eHome Infrared Transceiver.
3 *
4 * Copyright (c) 2010 by Jarod Wilson <jarod@redhat.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */
11
12#include <media/rc-map.h>
13
14static struct ir_scancode rc6_mce[] = {
15 { 0x800f0415, KEY_REWIND },
16 { 0x800f0414, KEY_FASTFORWARD },
17 { 0x800f041b, KEY_PREVIOUS },
18 { 0x800f041a, KEY_NEXT },
19
20 { 0x800f0416, KEY_PLAY },
21 { 0x800f0418, KEY_PAUSE },
22 { 0x800f0419, KEY_STOP },
23 { 0x800f0417, KEY_RECORD },
24
25 { 0x800f041e, KEY_UP },
26 { 0x800f041f, KEY_DOWN },
27 { 0x800f0420, KEY_LEFT },
28 { 0x800f0421, KEY_RIGHT },
29
30 { 0x800f040b, KEY_ENTER },
31 { 0x800f0422, KEY_OK },
32 { 0x800f0423, KEY_EXIT },
33 { 0x800f040a, KEY_DELETE },
34
35 { 0x800f040e, KEY_MUTE },
36 { 0x800f0410, KEY_VOLUMEUP },
37 { 0x800f0411, KEY_VOLUMEDOWN },
38 { 0x800f0412, KEY_CHANNELUP },
39 { 0x800f0413, KEY_CHANNELDOWN },
40
41 { 0x800f0401, KEY_NUMERIC_1 },
42 { 0x800f0402, KEY_NUMERIC_2 },
43 { 0x800f0403, KEY_NUMERIC_3 },
44 { 0x800f0404, KEY_NUMERIC_4 },
45 { 0x800f0405, KEY_NUMERIC_5 },
46 { 0x800f0406, KEY_NUMERIC_6 },
47 { 0x800f0407, KEY_NUMERIC_7 },
48 { 0x800f0408, KEY_NUMERIC_8 },
49 { 0x800f0409, KEY_NUMERIC_9 },
50 { 0x800f0400, KEY_NUMERIC_0 },
51
52 { 0x800f041d, KEY_NUMERIC_STAR },
53 { 0x800f041c, KEY_NUMERIC_POUND },
54
55 { 0x800f0446, KEY_TV },
56 { 0x800f0447, KEY_AUDIO }, /* My Music */
57 { 0x800f0448, KEY_PVR }, /* RecordedTV */
58 { 0x800f0449, KEY_CAMERA },
59 { 0x800f044a, KEY_VIDEO },
60 { 0x800f0424, KEY_DVD },
61 { 0x800f0425, KEY_TUNER }, /* LiveTV */
62 { 0x800f0450, KEY_RADIO },
63
64 { 0x800f044c, KEY_LANGUAGE },
65 { 0x800f0427, KEY_ZOOM }, /* Aspect */
66
67 { 0x800f045b, KEY_RED },
68 { 0x800f045c, KEY_GREEN },
69 { 0x800f045d, KEY_YELLOW },
70 { 0x800f045e, KEY_BLUE },
71
72 { 0x800f040f, KEY_INFO },
73 { 0x800f0426, KEY_EPG }, /* Guide */
74 { 0x800f045a, KEY_SUBTITLE }, /* Caption/Teletext */
75 { 0x800f044d, KEY_TITLE },
76
77 { 0x800f040c, KEY_POWER },
78 { 0x800f040d, KEY_PROG1 }, /* Windows MCE button */
79
80};
81
82static struct rc_keymap rc6_mce_map = {
83 .map = {
84 .scan = rc6_mce,
85 .size = ARRAY_SIZE(rc6_mce),
86 .ir_type = IR_TYPE_RC6,
87 .name = RC_MAP_RC6_MCE,
88 }
89};
90
91static int __init init_rc_map_rc6_mce(void)
92{
93 return ir_register_map(&rc6_mce_map);
94}
95
96static void __exit exit_rc_map_rc6_mce(void)
97{
98 ir_unregister_map(&rc6_mce_map);
99}
100
101module_init(init_rc_map_rc6_mce)
102module_exit(exit_rc_map_rc6_mce)
103
104MODULE_LICENSE("GPL");
105MODULE_AUTHOR("Jarod Wilson <jarod@redhat.com>");
diff --git a/drivers/media/IR/lirc_dev.c b/drivers/media/IR/lirc_dev.c
new file mode 100644
index 000000000000..899891bec352
--- /dev/null
+++ b/drivers/media/IR/lirc_dev.c
@@ -0,0 +1,764 @@
1/*
2 * LIRC base driver
3 *
4 * by Artur Lipowski <alipowski@interia.pl>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
22#include <linux/module.h>
23#include <linux/kernel.h>
24#include <linux/sched.h>
25#include <linux/errno.h>
26#include <linux/ioctl.h>
27#include <linux/fs.h>
28#include <linux/poll.h>
29#include <linux/completion.h>
30#include <linux/errno.h>
31#include <linux/mutex.h>
32#include <linux/wait.h>
33#include <linux/unistd.h>
34#include <linux/kthread.h>
35#include <linux/bitops.h>
36#include <linux/device.h>
37#include <linux/cdev.h>
38
39#include <media/lirc.h>
40#include <media/lirc_dev.h>
41
42static int debug;
43
44#define IRCTL_DEV_NAME "BaseRemoteCtl"
45#define NOPLUG -1
46#define LOGHEAD "lirc_dev (%s[%d]): "
47
48static dev_t lirc_base_dev;
49
50struct irctl {
51 struct lirc_driver d;
52 int attached;
53 int open;
54
55 struct mutex irctl_lock;
56 struct lirc_buffer *buf;
57 unsigned int chunk_size;
58
59 struct task_struct *task;
60 long jiffies_to_wait;
61
62 struct cdev cdev;
63};
64
65static DEFINE_MUTEX(lirc_dev_lock);
66
67static struct irctl *irctls[MAX_IRCTL_DEVICES];
68
69/* Only used for sysfs but defined to void otherwise */
70static struct class *lirc_class;
71
72/* helper function
73 * initializes the irctl structure
74 */
75static void init_irctl(struct irctl *ir)
76{
77 dev_dbg(ir->d.dev, LOGHEAD "initializing irctl\n",
78 ir->d.name, ir->d.minor);
79 mutex_init(&ir->irctl_lock);
80 ir->d.minor = NOPLUG;
81}
82
83static void cleanup(struct irctl *ir)
84{
85 dev_dbg(ir->d.dev, LOGHEAD "cleaning up\n", ir->d.name, ir->d.minor);
86
87 device_destroy(lirc_class, MKDEV(MAJOR(lirc_base_dev), ir->d.minor));
88
89 if (ir->buf != ir->d.rbuf) {
90 lirc_buffer_free(ir->buf);
91 kfree(ir->buf);
92 }
93 ir->buf = NULL;
94}
95
96/* helper function
97 * reads key codes from driver and puts them into buffer
98 * returns 0 on success
99 */
100static int add_to_buf(struct irctl *ir)
101{
102 if (ir->d.add_to_buf) {
103 int res = -ENODATA;
104 int got_data = 0;
105
106 /*
107 * service the device as long as it is returning
108 * data and we have space
109 */
110get_data:
111 res = ir->d.add_to_buf(ir->d.data, ir->buf);
112 if (res == 0) {
113 got_data++;
114 goto get_data;
115 }
116
117 if (res == -ENODEV)
118 kthread_stop(ir->task);
119
120 return got_data ? 0 : res;
121 }
122
123 return 0;
124}
125
126/* main function of the polling thread
127 */
128static int lirc_thread(void *irctl)
129{
130 struct irctl *ir = irctl;
131
132 dev_dbg(ir->d.dev, LOGHEAD "poll thread started\n",
133 ir->d.name, ir->d.minor);
134
135 do {
136 if (ir->open) {
137 if (ir->jiffies_to_wait) {
138 set_current_state(TASK_INTERRUPTIBLE);
139 schedule_timeout(ir->jiffies_to_wait);
140 }
141 if (kthread_should_stop())
142 break;
143 if (!add_to_buf(ir))
144 wake_up_interruptible(&ir->buf->wait_poll);
145 } else {
146 set_current_state(TASK_INTERRUPTIBLE);
147 schedule();
148 }
149 } while (!kthread_should_stop());
150
151 dev_dbg(ir->d.dev, LOGHEAD "poll thread ended\n",
152 ir->d.name, ir->d.minor);
153
154 return 0;
155}
156
157
158static struct file_operations fops = {
159 .owner = THIS_MODULE,
160 .read = lirc_dev_fop_read,
161 .write = lirc_dev_fop_write,
162 .poll = lirc_dev_fop_poll,
163 .unlocked_ioctl = lirc_dev_fop_ioctl,
164 .open = lirc_dev_fop_open,
165 .release = lirc_dev_fop_close,
166};
167
168static int lirc_cdev_add(struct irctl *ir)
169{
170 int retval;
171 struct lirc_driver *d = &ir->d;
172
173 if (d->fops) {
174 cdev_init(&ir->cdev, d->fops);
175 ir->cdev.owner = d->owner;
176 } else {
177 cdev_init(&ir->cdev, &fops);
178 ir->cdev.owner = THIS_MODULE;
179 }
180 kobject_set_name(&ir->cdev.kobj, "lirc%d", d->minor);
181
182 retval = cdev_add(&ir->cdev, MKDEV(MAJOR(lirc_base_dev), d->minor), 1);
183 if (retval)
184 kobject_put(&ir->cdev.kobj);
185
186 return retval;
187}
188
189int lirc_register_driver(struct lirc_driver *d)
190{
191 struct irctl *ir;
192 int minor;
193 int bytes_in_key;
194 unsigned int chunk_size;
195 unsigned int buffer_size;
196 int err;
197
198 if (!d) {
199 printk(KERN_ERR "lirc_dev: lirc_register_driver: "
200 "driver pointer must be not NULL!\n");
201 err = -EBADRQC;
202 goto out;
203 }
204
205 if (MAX_IRCTL_DEVICES <= d->minor) {
206 dev_err(d->dev, "lirc_dev: lirc_register_driver: "
207 "\"minor\" must be between 0 and %d (%d)!\n",
208 MAX_IRCTL_DEVICES-1, d->minor);
209 err = -EBADRQC;
210 goto out;
211 }
212
213 if (1 > d->code_length || (BUFLEN * 8) < d->code_length) {
214 dev_err(d->dev, "lirc_dev: lirc_register_driver: "
215 "code length in bits for minor (%d) "
216 "must be less than %d!\n",
217 d->minor, BUFLEN * 8);
218 err = -EBADRQC;
219 goto out;
220 }
221
222 dev_dbg(d->dev, "lirc_dev: lirc_register_driver: sample_rate: %d\n",
223 d->sample_rate);
224 if (d->sample_rate) {
225 if (2 > d->sample_rate || HZ < d->sample_rate) {
226 dev_err(d->dev, "lirc_dev: lirc_register_driver: "
227 "sample_rate must be between 2 and %d!\n", HZ);
228 err = -EBADRQC;
229 goto out;
230 }
231 if (!d->add_to_buf) {
232 dev_err(d->dev, "lirc_dev: lirc_register_driver: "
233 "add_to_buf cannot be NULL when "
234 "sample_rate is set\n");
235 err = -EBADRQC;
236 goto out;
237 }
238 } else if (!(d->fops && d->fops->read) && !d->rbuf) {
239 dev_err(d->dev, "lirc_dev: lirc_register_driver: "
240 "fops->read and rbuf cannot all be NULL!\n");
241 err = -EBADRQC;
242 goto out;
243 } else if (!d->rbuf) {
244 if (!(d->fops && d->fops->read && d->fops->poll &&
245 d->fops->unlocked_ioctl)) {
246 dev_err(d->dev, "lirc_dev: lirc_register_driver: "
247 "neither read, poll nor unlocked_ioctl can be NULL!\n");
248 err = -EBADRQC;
249 goto out;
250 }
251 }
252
253 mutex_lock(&lirc_dev_lock);
254
255 minor = d->minor;
256
257 if (minor < 0) {
258 /* find first free slot for driver */
259 for (minor = 0; minor < MAX_IRCTL_DEVICES; minor++)
260 if (!irctls[minor])
261 break;
262 if (MAX_IRCTL_DEVICES == minor) {
263 dev_err(d->dev, "lirc_dev: lirc_register_driver: "
264 "no free slots for drivers!\n");
265 err = -ENOMEM;
266 goto out_lock;
267 }
268 } else if (irctls[minor]) {
269 dev_err(d->dev, "lirc_dev: lirc_register_driver: "
270 "minor (%d) just registered!\n", minor);
271 err = -EBUSY;
272 goto out_lock;
273 }
274
275 ir = kzalloc(sizeof(struct irctl), GFP_KERNEL);
276 if (!ir) {
277 err = -ENOMEM;
278 goto out_lock;
279 }
280 init_irctl(ir);
281 irctls[minor] = ir;
282 d->minor = minor;
283
284 if (d->sample_rate) {
285 ir->jiffies_to_wait = HZ / d->sample_rate;
286 } else {
287 /* it means - wait for external event in task queue */
288 ir->jiffies_to_wait = 0;
289 }
290
291 /* some safety check 8-) */
292 d->name[sizeof(d->name)-1] = '\0';
293
294 bytes_in_key = BITS_TO_LONGS(d->code_length) +
295 (d->code_length % 8 ? 1 : 0);
296 buffer_size = d->buffer_size ? d->buffer_size : BUFLEN / bytes_in_key;
297 chunk_size = d->chunk_size ? d->chunk_size : bytes_in_key;
298
299 if (d->rbuf) {
300 ir->buf = d->rbuf;
301 } else {
302 ir->buf = kmalloc(sizeof(struct lirc_buffer), GFP_KERNEL);
303 if (!ir->buf) {
304 err = -ENOMEM;
305 goto out_lock;
306 }
307 err = lirc_buffer_init(ir->buf, chunk_size, buffer_size);
308 if (err) {
309 kfree(ir->buf);
310 goto out_lock;
311 }
312 }
313 ir->chunk_size = ir->buf->chunk_size;
314
315 if (d->features == 0)
316 d->features = LIRC_CAN_REC_LIRCCODE;
317
318 ir->d = *d;
319 ir->d.minor = minor;
320
321 device_create(lirc_class, ir->d.dev,
322 MKDEV(MAJOR(lirc_base_dev), ir->d.minor), NULL,
323 "lirc%u", ir->d.minor);
324
325 if (d->sample_rate) {
326 /* try to fire up polling thread */
327 ir->task = kthread_run(lirc_thread, (void *)ir, "lirc_dev");
328 if (IS_ERR(ir->task)) {
329 dev_err(d->dev, "lirc_dev: lirc_register_driver: "
330 "cannot run poll thread for minor = %d\n",
331 d->minor);
332 err = -ECHILD;
333 goto out_sysfs;
334 }
335 }
336
337 err = lirc_cdev_add(ir);
338 if (err)
339 goto out_sysfs;
340
341 ir->attached = 1;
342 mutex_unlock(&lirc_dev_lock);
343
344 dev_info(ir->d.dev, "lirc_dev: driver %s registered at minor = %d\n",
345 ir->d.name, ir->d.minor);
346 return minor;
347
348out_sysfs:
349 device_destroy(lirc_class, MKDEV(MAJOR(lirc_base_dev), ir->d.minor));
350out_lock:
351 mutex_unlock(&lirc_dev_lock);
352out:
353 return err;
354}
355EXPORT_SYMBOL(lirc_register_driver);
356
357int lirc_unregister_driver(int minor)
358{
359 struct irctl *ir;
360
361 if (minor < 0 || minor >= MAX_IRCTL_DEVICES) {
362 printk(KERN_ERR "lirc_dev: lirc_unregister_driver: "
363 "\"minor (%d)\" must be between 0 and %d!\n",
364 minor, MAX_IRCTL_DEVICES-1);
365 return -EBADRQC;
366 }
367
368 ir = irctls[minor];
369
370 mutex_lock(&lirc_dev_lock);
371
372 if (ir->d.minor != minor) {
373 printk(KERN_ERR "lirc_dev: lirc_unregister_driver: "
374 "minor (%d) device not registered!", minor);
375 mutex_unlock(&lirc_dev_lock);
376 return -ENOENT;
377 }
378
379 /* end up polling thread */
380 if (ir->task)
381 kthread_stop(ir->task);
382
383 dev_dbg(ir->d.dev, "lirc_dev: driver %s unregistered from minor = %d\n",
384 ir->d.name, ir->d.minor);
385
386 ir->attached = 0;
387 if (ir->open) {
388 dev_dbg(ir->d.dev, LOGHEAD "releasing opened driver\n",
389 ir->d.name, ir->d.minor);
390 wake_up_interruptible(&ir->buf->wait_poll);
391 mutex_lock(&ir->irctl_lock);
392 ir->d.set_use_dec(ir->d.data);
393 module_put(ir->d.owner);
394 mutex_unlock(&ir->irctl_lock);
395 cdev_del(&ir->cdev);
396 } else {
397 cleanup(ir);
398 cdev_del(&ir->cdev);
399 kfree(ir);
400 irctls[minor] = NULL;
401 }
402
403 mutex_unlock(&lirc_dev_lock);
404
405 return 0;
406}
407EXPORT_SYMBOL(lirc_unregister_driver);
408
409int lirc_dev_fop_open(struct inode *inode, struct file *file)
410{
411 struct irctl *ir;
412 int retval = 0;
413
414 if (iminor(inode) >= MAX_IRCTL_DEVICES) {
415 printk(KERN_WARNING "lirc_dev [%d]: open result = -ENODEV\n",
416 iminor(inode));
417 return -ENODEV;
418 }
419
420 if (mutex_lock_interruptible(&lirc_dev_lock))
421 return -ERESTARTSYS;
422
423 ir = irctls[iminor(inode)];
424 if (!ir) {
425 retval = -ENODEV;
426 goto error;
427 }
428 file->private_data = ir;
429
430 dev_dbg(ir->d.dev, LOGHEAD "open called\n", ir->d.name, ir->d.minor);
431
432 if (ir->d.minor == NOPLUG) {
433 retval = -ENODEV;
434 goto error;
435 }
436
437 if (ir->open) {
438 retval = -EBUSY;
439 goto error;
440 }
441
442 if (try_module_get(ir->d.owner)) {
443 ++ir->open;
444 retval = ir->d.set_use_inc(ir->d.data);
445
446 if (retval) {
447 module_put(ir->d.owner);
448 --ir->open;
449 } else {
450 lirc_buffer_clear(ir->buf);
451 }
452 if (ir->task)
453 wake_up_process(ir->task);
454 }
455
456error:
457 if (ir)
458 dev_dbg(ir->d.dev, LOGHEAD "open result = %d\n",
459 ir->d.name, ir->d.minor, retval);
460
461 mutex_unlock(&lirc_dev_lock);
462
463 return retval;
464}
465EXPORT_SYMBOL(lirc_dev_fop_open);
466
467int lirc_dev_fop_close(struct inode *inode, struct file *file)
468{
469 struct irctl *ir = irctls[iminor(inode)];
470
471 dev_dbg(ir->d.dev, LOGHEAD "close called\n", ir->d.name, ir->d.minor);
472
473 WARN_ON(mutex_lock_killable(&lirc_dev_lock));
474
475 --ir->open;
476 if (ir->attached) {
477 ir->d.set_use_dec(ir->d.data);
478 module_put(ir->d.owner);
479 } else {
480 cleanup(ir);
481 irctls[ir->d.minor] = NULL;
482 kfree(ir);
483 }
484
485 mutex_unlock(&lirc_dev_lock);
486
487 return 0;
488}
489EXPORT_SYMBOL(lirc_dev_fop_close);
490
491unsigned int lirc_dev_fop_poll(struct file *file, poll_table *wait)
492{
493 struct irctl *ir = irctls[iminor(file->f_dentry->d_inode)];
494 unsigned int ret;
495
496 dev_dbg(ir->d.dev, LOGHEAD "poll called\n", ir->d.name, ir->d.minor);
497
498 if (!ir->attached) {
499 mutex_unlock(&ir->irctl_lock);
500 return POLLERR;
501 }
502
503 poll_wait(file, &ir->buf->wait_poll, wait);
504
505 if (ir->buf)
506 if (lirc_buffer_empty(ir->buf))
507 ret = 0;
508 else
509 ret = POLLIN | POLLRDNORM;
510 else
511 ret = POLLERR;
512
513 dev_dbg(ir->d.dev, LOGHEAD "poll result = %d\n",
514 ir->d.name, ir->d.minor, ret);
515
516 return ret;
517}
518EXPORT_SYMBOL(lirc_dev_fop_poll);
519
520long lirc_dev_fop_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
521{
522 unsigned long mode;
523 int result = 0;
524 struct irctl *ir = file->private_data;
525
526 dev_dbg(ir->d.dev, LOGHEAD "ioctl called (0x%x)\n",
527 ir->d.name, ir->d.minor, cmd);
528
529 if (ir->d.minor == NOPLUG || !ir->attached) {
530 dev_dbg(ir->d.dev, LOGHEAD "ioctl result = -ENODEV\n",
531 ir->d.name, ir->d.minor);
532 return -ENODEV;
533 }
534
535 mutex_lock(&ir->irctl_lock);
536
537 switch (cmd) {
538 case LIRC_GET_FEATURES:
539 result = put_user(ir->d.features, (unsigned long *)arg);
540 break;
541 case LIRC_GET_REC_MODE:
542 if (!(ir->d.features & LIRC_CAN_REC_MASK)) {
543 result = -ENOSYS;
544 break;
545 }
546
547 result = put_user(LIRC_REC2MODE
548 (ir->d.features & LIRC_CAN_REC_MASK),
549 (unsigned long *)arg);
550 break;
551 case LIRC_SET_REC_MODE:
552 if (!(ir->d.features & LIRC_CAN_REC_MASK)) {
553 result = -ENOSYS;
554 break;
555 }
556
557 result = get_user(mode, (unsigned long *)arg);
558 if (!result && !(LIRC_MODE2REC(mode) & ir->d.features))
559 result = -EINVAL;
560 /*
561 * FIXME: We should actually set the mode somehow but
562 * for now, lirc_serial doesn't support mode changing either
563 */
564 break;
565 case LIRC_GET_LENGTH:
566 result = put_user(ir->d.code_length, (unsigned long *)arg);
567 break;
568 case LIRC_GET_MIN_TIMEOUT:
569 if (!(ir->d.features & LIRC_CAN_SET_REC_TIMEOUT) ||
570 ir->d.min_timeout == 0) {
571 result = -ENOSYS;
572 break;
573 }
574
575 result = put_user(ir->d.min_timeout, (unsigned long *)arg);
576 break;
577 case LIRC_GET_MAX_TIMEOUT:
578 if (!(ir->d.features & LIRC_CAN_SET_REC_TIMEOUT) ||
579 ir->d.max_timeout == 0) {
580 result = -ENOSYS;
581 break;
582 }
583
584 result = put_user(ir->d.max_timeout, (unsigned long *)arg);
585 break;
586 default:
587 result = -EINVAL;
588 }
589
590 dev_dbg(ir->d.dev, LOGHEAD "ioctl result = %d\n",
591 ir->d.name, ir->d.minor, result);
592
593 mutex_unlock(&ir->irctl_lock);
594
595 return result;
596}
597EXPORT_SYMBOL(lirc_dev_fop_ioctl);
598
599ssize_t lirc_dev_fop_read(struct file *file,
600 char *buffer,
601 size_t length,
602 loff_t *ppos)
603{
604 struct irctl *ir = irctls[iminor(file->f_dentry->d_inode)];
605 unsigned char buf[ir->chunk_size];
606 int ret = 0, written = 0;
607 DECLARE_WAITQUEUE(wait, current);
608
609 dev_dbg(ir->d.dev, LOGHEAD "read called\n", ir->d.name, ir->d.minor);
610
611 if (mutex_lock_interruptible(&ir->irctl_lock))
612 return -ERESTARTSYS;
613 if (!ir->attached) {
614 mutex_unlock(&ir->irctl_lock);
615 return -ENODEV;
616 }
617
618 if (length % ir->chunk_size) {
619 dev_dbg(ir->d.dev, LOGHEAD "read result = -EINVAL\n",
620 ir->d.name, ir->d.minor);
621 mutex_unlock(&ir->irctl_lock);
622 return -EINVAL;
623 }
624
625 /*
626 * we add ourselves to the task queue before buffer check
627 * to avoid losing scan code (in case when queue is awaken somewhere
628 * between while condition checking and scheduling)
629 */
630 add_wait_queue(&ir->buf->wait_poll, &wait);
631 set_current_state(TASK_INTERRUPTIBLE);
632
633 /*
634 * while we didn't provide 'length' bytes, device is opened in blocking
635 * mode and 'copy_to_user' is happy, wait for data.
636 */
637 while (written < length && ret == 0) {
638 if (lirc_buffer_empty(ir->buf)) {
639 /* According to the read(2) man page, 'written' can be
640 * returned as less than 'length', instead of blocking
641 * again, returning -EWOULDBLOCK, or returning
642 * -ERESTARTSYS */
643 if (written)
644 break;
645 if (file->f_flags & O_NONBLOCK) {
646 ret = -EWOULDBLOCK;
647 break;
648 }
649 if (signal_pending(current)) {
650 ret = -ERESTARTSYS;
651 break;
652 }
653
654 mutex_unlock(&ir->irctl_lock);
655 schedule();
656 set_current_state(TASK_INTERRUPTIBLE);
657
658 if (mutex_lock_interruptible(&ir->irctl_lock)) {
659 ret = -ERESTARTSYS;
660 remove_wait_queue(&ir->buf->wait_poll, &wait);
661 set_current_state(TASK_RUNNING);
662 goto out_unlocked;
663 }
664
665 if (!ir->attached) {
666 ret = -ENODEV;
667 break;
668 }
669 } else {
670 lirc_buffer_read(ir->buf, buf);
671 ret = copy_to_user((void *)buffer+written, buf,
672 ir->buf->chunk_size);
673 written += ir->buf->chunk_size;
674 }
675 }
676
677 remove_wait_queue(&ir->buf->wait_poll, &wait);
678 set_current_state(TASK_RUNNING);
679 mutex_unlock(&ir->irctl_lock);
680
681out_unlocked:
682 dev_dbg(ir->d.dev, LOGHEAD "read result = %s (%d)\n",
683 ir->d.name, ir->d.minor, ret ? "-EFAULT" : "OK", ret);
684
685 return ret ? ret : written;
686}
687EXPORT_SYMBOL(lirc_dev_fop_read);
688
689void *lirc_get_pdata(struct file *file)
690{
691 void *data = NULL;
692
693 if (file && file->f_dentry && file->f_dentry->d_inode &&
694 file->f_dentry->d_inode->i_rdev) {
695 struct irctl *ir;
696 ir = irctls[iminor(file->f_dentry->d_inode)];
697 data = ir->d.data;
698 }
699
700 return data;
701}
702EXPORT_SYMBOL(lirc_get_pdata);
703
704
705ssize_t lirc_dev_fop_write(struct file *file, const char *buffer,
706 size_t length, loff_t *ppos)
707{
708 struct irctl *ir = irctls[iminor(file->f_dentry->d_inode)];
709
710 dev_dbg(ir->d.dev, LOGHEAD "write called\n", ir->d.name, ir->d.minor);
711
712 if (!ir->attached)
713 return -ENODEV;
714
715 return -EINVAL;
716}
717EXPORT_SYMBOL(lirc_dev_fop_write);
718
719
720static int __init lirc_dev_init(void)
721{
722 int retval;
723
724 lirc_class = class_create(THIS_MODULE, "lirc");
725 if (IS_ERR(lirc_class)) {
726 retval = PTR_ERR(lirc_class);
727 printk(KERN_ERR "lirc_dev: class_create failed\n");
728 goto error;
729 }
730
731 retval = alloc_chrdev_region(&lirc_base_dev, 0, MAX_IRCTL_DEVICES,
732 IRCTL_DEV_NAME);
733 if (retval) {
734 class_destroy(lirc_class);
735 printk(KERN_ERR "lirc_dev: alloc_chrdev_region failed\n");
736 goto error;
737 }
738
739
740 printk(KERN_INFO "lirc_dev: IR Remote Control driver registered, "
741 "major %d \n", MAJOR(lirc_base_dev));
742
743error:
744 return retval;
745}
746
747
748
749static void __exit lirc_dev_exit(void)
750{
751 class_destroy(lirc_class);
752 unregister_chrdev_region(lirc_base_dev, MAX_IRCTL_DEVICES);
753 printk(KERN_INFO "lirc_dev: module unloaded\n");
754}
755
756module_init(lirc_dev_init);
757module_exit(lirc_dev_exit);
758
759MODULE_DESCRIPTION("LIRC base driver module");
760MODULE_AUTHOR("Artur Lipowski");
761MODULE_LICENSE("GPL");
762
763module_param(debug, bool, S_IRUGO | S_IWUSR);
764MODULE_PARM_DESC(debug, "Enable debugging messages");
diff --git a/drivers/media/IR/mceusb.c b/drivers/media/IR/mceusb.c
new file mode 100644
index 000000000000..78bf7f77a1a0
--- /dev/null
+++ b/drivers/media/IR/mceusb.c
@@ -0,0 +1,1143 @@
1/*
2 * Driver for USB Windows Media Center Ed. eHome Infrared Transceivers
3 *
4 * Copyright (c) 2010 by Jarod Wilson <jarod@redhat.com>
5 *
6 * Based on the original lirc_mceusb and lirc_mceusb2 drivers, by Dan
7 * Conti, Martin Blatter and Daniel Melander, the latter of which was
8 * in turn also based on the lirc_atiusb driver by Paul Miller. The
9 * two mce drivers were merged into one by Jarod Wilson, with transmit
10 * support for the 1st-gen device added primarily by Patrick Calhoun,
11 * with a bit of tweaks by Jarod. Debugging improvements and proper
12 * support for what appears to be 3rd-gen hardware added by Jarod.
13 * Initial port from lirc driver to ir-core drivery by Jarod, based
14 * partially on a port to an earlier proposed IR infrastructure by
15 * Jon Smirl, which included enhancements and simplifications to the
16 * incoming IR buffer parsing routines.
17 *
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 *
33 */
34
35#include <linux/device.h>
36#include <linux/module.h>
37#include <linux/slab.h>
38#include <linux/usb.h>
39#include <linux/input.h>
40#include <media/ir-core.h>
41#include <media/ir-common.h>
42
43#define DRIVER_VERSION "1.91"
44#define DRIVER_AUTHOR "Jarod Wilson <jarod@wilsonet.com>"
45#define DRIVER_DESC "Windows Media Center Ed. eHome Infrared Transceiver " \
46 "device driver"
47#define DRIVER_NAME "mceusb"
48
49#define USB_BUFLEN 32 /* USB reception buffer length */
50#define USB_CTRL_MSG_SZ 2 /* Size of usb ctrl msg on gen1 hw */
51#define MCE_G1_INIT_MSGS 40 /* Init messages on gen1 hw to throw out */
52
53/* MCE constants */
54#define MCE_CMDBUF_SIZE 384 /* MCE Command buffer length */
55#define MCE_TIME_UNIT 50 /* Approx 50us resolution */
56#define MCE_CODE_LENGTH 5 /* Normal length of packet (with header) */
57#define MCE_PACKET_SIZE 4 /* Normal length of packet (without header) */
58#define MCE_PACKET_HEADER 0x84 /* Actual header format is 0x80 + num_bytes */
59#define MCE_CONTROL_HEADER 0x9F /* MCE status header */
60#define MCE_TX_HEADER_LENGTH 3 /* # of bytes in the initializing tx header */
61#define MCE_MAX_CHANNELS 2 /* Two transmitters, hardware dependent? */
62#define MCE_DEFAULT_TX_MASK 0x03 /* Val opts: TX1=0x01, TX2=0x02, ALL=0x03 */
63#define MCE_PULSE_BIT 0x80 /* Pulse bit, MSB set == PULSE else SPACE */
64#define MCE_PULSE_MASK 0x7F /* Pulse mask */
65#define MCE_MAX_PULSE_LENGTH 0x7F /* Longest transmittable pulse symbol */
66#define MCE_PACKET_LENGTH_MASK 0x1F /* Packet length mask */
67
68
69/* module parameters */
70#ifdef CONFIG_USB_DEBUG
71static int debug = 1;
72#else
73static int debug;
74#endif
75
76/* general constants */
77#define SEND_FLAG_IN_PROGRESS 1
78#define SEND_FLAG_COMPLETE 2
79#define RECV_FLAG_IN_PROGRESS 3
80#define RECV_FLAG_COMPLETE 4
81
82#define MCEUSB_RX 1
83#define MCEUSB_TX 2
84
85#define VENDOR_PHILIPS 0x0471
86#define VENDOR_SMK 0x0609
87#define VENDOR_TATUNG 0x1460
88#define VENDOR_GATEWAY 0x107b
89#define VENDOR_SHUTTLE 0x1308
90#define VENDOR_SHUTTLE2 0x051c
91#define VENDOR_MITSUMI 0x03ee
92#define VENDOR_TOPSEED 0x1784
93#define VENDOR_RICAVISION 0x179d
94#define VENDOR_ITRON 0x195d
95#define VENDOR_FIC 0x1509
96#define VENDOR_LG 0x043e
97#define VENDOR_MICROSOFT 0x045e
98#define VENDOR_FORMOSA 0x147a
99#define VENDOR_FINTEK 0x1934
100#define VENDOR_PINNACLE 0x2304
101#define VENDOR_ECS 0x1019
102#define VENDOR_WISTRON 0x0fb8
103#define VENDOR_COMPRO 0x185b
104#define VENDOR_NORTHSTAR 0x04eb
105#define VENDOR_REALTEK 0x0bda
106#define VENDOR_TIVO 0x105a
107
108static struct usb_device_id mceusb_dev_table[] = {
109 /* Original Microsoft MCE IR Transceiver (often HP-branded) */
110 { USB_DEVICE(VENDOR_MICROSOFT, 0x006d) },
111 /* Philips Infrared Transceiver - Sahara branded */
112 { USB_DEVICE(VENDOR_PHILIPS, 0x0608) },
113 /* Philips Infrared Transceiver - HP branded */
114 { USB_DEVICE(VENDOR_PHILIPS, 0x060c) },
115 /* Philips SRM5100 */
116 { USB_DEVICE(VENDOR_PHILIPS, 0x060d) },
117 /* Philips Infrared Transceiver - Omaura */
118 { USB_DEVICE(VENDOR_PHILIPS, 0x060f) },
119 /* Philips Infrared Transceiver - Spinel plus */
120 { USB_DEVICE(VENDOR_PHILIPS, 0x0613) },
121 /* Philips eHome Infrared Transceiver */
122 { USB_DEVICE(VENDOR_PHILIPS, 0x0815) },
123 /* Realtek MCE IR Receiver */
124 { USB_DEVICE(VENDOR_REALTEK, 0x0161) },
125 /* SMK/Toshiba G83C0004D410 */
126 { USB_DEVICE(VENDOR_SMK, 0x031d) },
127 /* SMK eHome Infrared Transceiver (Sony VAIO) */
128 { USB_DEVICE(VENDOR_SMK, 0x0322) },
129 /* bundled with Hauppauge PVR-150 */
130 { USB_DEVICE(VENDOR_SMK, 0x0334) },
131 /* SMK eHome Infrared Transceiver */
132 { USB_DEVICE(VENDOR_SMK, 0x0338) },
133 /* Tatung eHome Infrared Transceiver */
134 { USB_DEVICE(VENDOR_TATUNG, 0x9150) },
135 /* Shuttle eHome Infrared Transceiver */
136 { USB_DEVICE(VENDOR_SHUTTLE, 0xc001) },
137 /* Shuttle eHome Infrared Transceiver */
138 { USB_DEVICE(VENDOR_SHUTTLE2, 0xc001) },
139 /* Gateway eHome Infrared Transceiver */
140 { USB_DEVICE(VENDOR_GATEWAY, 0x3009) },
141 /* Mitsumi */
142 { USB_DEVICE(VENDOR_MITSUMI, 0x2501) },
143 /* Topseed eHome Infrared Transceiver */
144 { USB_DEVICE(VENDOR_TOPSEED, 0x0001) },
145 /* Topseed HP eHome Infrared Transceiver */
146 { USB_DEVICE(VENDOR_TOPSEED, 0x0006) },
147 /* Topseed eHome Infrared Transceiver */
148 { USB_DEVICE(VENDOR_TOPSEED, 0x0007) },
149 /* Topseed eHome Infrared Transceiver */
150 { USB_DEVICE(VENDOR_TOPSEED, 0x0008) },
151 /* Topseed eHome Infrared Transceiver */
152 { USB_DEVICE(VENDOR_TOPSEED, 0x000a) },
153 /* Topseed eHome Infrared Transceiver */
154 { USB_DEVICE(VENDOR_TOPSEED, 0x0011) },
155 /* Ricavision internal Infrared Transceiver */
156 { USB_DEVICE(VENDOR_RICAVISION, 0x0010) },
157 /* Itron ione Libra Q-11 */
158 { USB_DEVICE(VENDOR_ITRON, 0x7002) },
159 /* FIC eHome Infrared Transceiver */
160 { USB_DEVICE(VENDOR_FIC, 0x9242) },
161 /* LG eHome Infrared Transceiver */
162 { USB_DEVICE(VENDOR_LG, 0x9803) },
163 /* Microsoft MCE Infrared Transceiver */
164 { USB_DEVICE(VENDOR_MICROSOFT, 0x00a0) },
165 /* Formosa eHome Infrared Transceiver */
166 { USB_DEVICE(VENDOR_FORMOSA, 0xe015) },
167 /* Formosa21 / eHome Infrared Receiver */
168 { USB_DEVICE(VENDOR_FORMOSA, 0xe016) },
169 /* Formosa aim / Trust MCE Infrared Receiver */
170 { USB_DEVICE(VENDOR_FORMOSA, 0xe017) },
171 /* Formosa Industrial Computing / Beanbag Emulation Device */
172 { USB_DEVICE(VENDOR_FORMOSA, 0xe018) },
173 /* Formosa21 / eHome Infrared Receiver */
174 { USB_DEVICE(VENDOR_FORMOSA, 0xe03a) },
175 /* Formosa Industrial Computing AIM IR605/A */
176 { USB_DEVICE(VENDOR_FORMOSA, 0xe03c) },
177 /* Formosa Industrial Computing */
178 { USB_DEVICE(VENDOR_FORMOSA, 0xe03e) },
179 /* Fintek eHome Infrared Transceiver */
180 { USB_DEVICE(VENDOR_FINTEK, 0x0602) },
181 /* Fintek eHome Infrared Transceiver (in the AOpen MP45) */
182 { USB_DEVICE(VENDOR_FINTEK, 0x0702) },
183 /* Pinnacle Remote Kit */
184 { USB_DEVICE(VENDOR_PINNACLE, 0x0225) },
185 /* Elitegroup Computer Systems IR */
186 { USB_DEVICE(VENDOR_ECS, 0x0f38) },
187 /* Wistron Corp. eHome Infrared Receiver */
188 { USB_DEVICE(VENDOR_WISTRON, 0x0002) },
189 /* Compro K100 */
190 { USB_DEVICE(VENDOR_COMPRO, 0x3020) },
191 /* Compro K100 v2 */
192 { USB_DEVICE(VENDOR_COMPRO, 0x3082) },
193 /* Northstar Systems, Inc. eHome Infrared Transceiver */
194 { USB_DEVICE(VENDOR_NORTHSTAR, 0xe004) },
195 /* TiVo PC IR Receiver */
196 { USB_DEVICE(VENDOR_TIVO, 0x2000) },
197 /* Terminating entry */
198 { }
199};
200
201static struct usb_device_id gen3_list[] = {
202 { USB_DEVICE(VENDOR_PINNACLE, 0x0225) },
203 { USB_DEVICE(VENDOR_TOPSEED, 0x0008) },
204 {}
205};
206
207static struct usb_device_id microsoft_gen1_list[] = {
208 { USB_DEVICE(VENDOR_MICROSOFT, 0x006d) },
209 {}
210};
211
212static struct usb_device_id std_tx_mask_list[] = {
213 { USB_DEVICE(VENDOR_MICROSOFT, 0x006d) },
214 { USB_DEVICE(VENDOR_PHILIPS, 0x060c) },
215 { USB_DEVICE(VENDOR_SMK, 0x031d) },
216 { USB_DEVICE(VENDOR_SMK, 0x0322) },
217 { USB_DEVICE(VENDOR_SMK, 0x0334) },
218 { USB_DEVICE(VENDOR_TOPSEED, 0x0001) },
219 { USB_DEVICE(VENDOR_TOPSEED, 0x0006) },
220 { USB_DEVICE(VENDOR_TOPSEED, 0x0007) },
221 { USB_DEVICE(VENDOR_TOPSEED, 0x0008) },
222 { USB_DEVICE(VENDOR_TOPSEED, 0x000a) },
223 { USB_DEVICE(VENDOR_TOPSEED, 0x0011) },
224 { USB_DEVICE(VENDOR_PINNACLE, 0x0225) },
225 {}
226};
227
228/* data structure for each usb transceiver */
229struct mceusb_dev {
230 /* ir-core bits */
231 struct ir_input_dev *irdev;
232 struct ir_dev_props *props;
233 struct ir_raw_event rawir;
234
235 /* core device bits */
236 struct device *dev;
237 struct input_dev *idev;
238
239 /* usb */
240 struct usb_device *usbdev;
241 struct urb *urb_in;
242 struct usb_endpoint_descriptor *usb_ep_in;
243 struct usb_endpoint_descriptor *usb_ep_out;
244
245 /* buffers and dma */
246 unsigned char *buf_in;
247 unsigned int len_in;
248 u8 cmd; /* MCE command type */
249 u8 rem; /* Remaining IR data bytes in packet */
250 dma_addr_t dma_in;
251 dma_addr_t dma_out;
252
253 struct {
254 u32 connected:1;
255 u32 tx_mask_inverted:1;
256 u32 microsoft_gen1:1;
257 u32 reserved:29;
258 } flags;
259
260 /* transmit support */
261 int send_flags;
262 u32 carrier;
263 unsigned char tx_mask;
264
265 char name[128];
266 char phys[64];
267};
268
269/*
270 * MCE Device Command Strings
271 * Device command responses vary from device to device...
272 * - DEVICE_RESET resets the hardware to its default state
273 * - GET_REVISION fetches the hardware/software revision, common
274 * replies are ff 0b 45 ff 1b 08 and ff 0b 50 ff 1b 42
275 * - GET_CARRIER_FREQ gets the carrier mode and frequency of the
276 * device, with replies in the form of 9f 06 MM FF, where MM is 0-3,
277 * meaning clk of 10000000, 2500000, 625000 or 156250, and FF is
278 * ((clk / frequency) - 1)
279 * - GET_RX_TIMEOUT fetches the receiver timeout in units of 50us,
280 * response in the form of 9f 0c msb lsb
281 * - GET_TX_BITMASK fetches the transmitter bitmask, replies in
282 * the form of 9f 08 bm, where bm is the bitmask
283 * - GET_RX_SENSOR fetches the RX sensor setting -- long-range
284 * general use one or short-range learning one, in the form of
285 * 9f 14 ss, where ss is either 01 for long-range or 02 for short
286 * - SET_CARRIER_FREQ sets a new carrier mode and frequency
287 * - SET_TX_BITMASK sets the transmitter bitmask
288 * - SET_RX_TIMEOUT sets the receiver timeout
289 * - SET_RX_SENSOR sets which receiver sensor to use
290 */
291static char DEVICE_RESET[] = {0x00, 0xff, 0xaa};
292static char GET_REVISION[] = {0xff, 0x0b};
293static char GET_UNKNOWN[] = {0xff, 0x18};
294static char GET_UNKNOWN2[] = {0x9f, 0x05};
295static char GET_CARRIER_FREQ[] = {0x9f, 0x07};
296static char GET_RX_TIMEOUT[] = {0x9f, 0x0d};
297static char GET_TX_BITMASK[] = {0x9f, 0x13};
298static char GET_RX_SENSOR[] = {0x9f, 0x15};
299/* sub in desired values in lower byte or bytes for full command */
300/* FIXME: make use of these for transmit.
301static char SET_CARRIER_FREQ[] = {0x9f, 0x06, 0x00, 0x00};
302static char SET_TX_BITMASK[] = {0x9f, 0x08, 0x00};
303static char SET_RX_TIMEOUT[] = {0x9f, 0x0c, 0x00, 0x00};
304static char SET_RX_SENSOR[] = {0x9f, 0x14, 0x00};
305*/
306
307static void mceusb_dev_printdata(struct mceusb_dev *ir, char *buf,
308 int len, bool out)
309{
310 char codes[USB_BUFLEN * 3 + 1];
311 char inout[9];
312 int i;
313 u8 cmd, subcmd, data1, data2;
314 struct device *dev = ir->dev;
315 int idx = 0;
316
317 /* skip meaningless 0xb1 0x60 header bytes on orig receiver */
318 if (ir->flags.microsoft_gen1 && !out)
319 idx = 2;
320
321 if (len <= idx)
322 return;
323
324 for (i = 0; i < len && i < USB_BUFLEN; i++)
325 snprintf(codes + i * 3, 4, "%02x ", buf[i] & 0xFF);
326
327 dev_info(dev, "%sx data: %s (length=%d)\n",
328 (out ? "t" : "r"), codes, len);
329
330 if (out)
331 strcpy(inout, "Request\0");
332 else
333 strcpy(inout, "Got\0");
334
335 cmd = buf[idx] & 0xff;
336 subcmd = buf[idx + 1] & 0xff;
337 data1 = buf[idx + 2] & 0xff;
338 data2 = buf[idx + 3] & 0xff;
339
340 switch (cmd) {
341 case 0x00:
342 if (subcmd == 0xff && data1 == 0xaa)
343 dev_info(dev, "Device reset requested\n");
344 else
345 dev_info(dev, "Unknown command 0x%02x 0x%02x\n",
346 cmd, subcmd);
347 break;
348 case 0xff:
349 switch (subcmd) {
350 case 0x0b:
351 if (len == 2)
352 dev_info(dev, "Get hw/sw rev?\n");
353 else
354 dev_info(dev, "hw/sw rev 0x%02x 0x%02x "
355 "0x%02x 0x%02x\n", data1, data2,
356 buf[idx + 4], buf[idx + 5]);
357 break;
358 case 0xaa:
359 dev_info(dev, "Device reset requested\n");
360 break;
361 case 0xfe:
362 dev_info(dev, "Previous command not supported\n");
363 break;
364 case 0x18:
365 case 0x1b:
366 default:
367 dev_info(dev, "Unknown command 0x%02x 0x%02x\n",
368 cmd, subcmd);
369 break;
370 }
371 break;
372 case 0x9f:
373 switch (subcmd) {
374 case 0x03:
375 dev_info(dev, "Ping\n");
376 break;
377 case 0x04:
378 dev_info(dev, "Resp to 9f 05 of 0x%02x 0x%02x\n",
379 data1, data2);
380 break;
381 case 0x06:
382 dev_info(dev, "%s carrier mode and freq of "
383 "0x%02x 0x%02x\n", inout, data1, data2);
384 break;
385 case 0x07:
386 dev_info(dev, "Get carrier mode and freq\n");
387 break;
388 case 0x08:
389 dev_info(dev, "%s transmit blaster mask of 0x%02x\n",
390 inout, data1);
391 break;
392 case 0x0c:
393 /* value is in units of 50us, so x*50/100 or x/2 ms */
394 dev_info(dev, "%s receive timeout of %d ms\n",
395 inout, ((data1 << 8) | data2) / 2);
396 break;
397 case 0x0d:
398 dev_info(dev, "Get receive timeout\n");
399 break;
400 case 0x13:
401 dev_info(dev, "Get transmit blaster mask\n");
402 break;
403 case 0x14:
404 dev_info(dev, "%s %s-range receive sensor in use\n",
405 inout, data1 == 0x02 ? "short" : "long");
406 break;
407 case 0x15:
408 if (len == 2)
409 dev_info(dev, "Get receive sensor\n");
410 else
411 dev_info(dev, "Received pulse count is %d\n",
412 ((data1 << 8) | data2));
413 break;
414 case 0xfe:
415 dev_info(dev, "Error! Hardware is likely wedged...\n");
416 break;
417 case 0x05:
418 case 0x09:
419 case 0x0f:
420 default:
421 dev_info(dev, "Unknown command 0x%02x 0x%02x\n",
422 cmd, subcmd);
423 break;
424 }
425 break;
426 default:
427 break;
428 }
429}
430
431static void usb_async_callback(struct urb *urb, struct pt_regs *regs)
432{
433 struct mceusb_dev *ir;
434 int len;
435
436 if (!urb)
437 return;
438
439 ir = urb->context;
440 if (ir) {
441 len = urb->actual_length;
442
443 dev_dbg(ir->dev, "callback called (status=%d len=%d)\n",
444 urb->status, len);
445
446 if (debug)
447 mceusb_dev_printdata(ir, urb->transfer_buffer,
448 len, true);
449 }
450
451}
452
453/* request incoming or send outgoing usb packet - used to initialize remote */
454static void mce_request_packet(struct mceusb_dev *ir,
455 struct usb_endpoint_descriptor *ep,
456 unsigned char *data, int size, int urb_type)
457{
458 int res;
459 struct urb *async_urb;
460 struct device *dev = ir->dev;
461 unsigned char *async_buf;
462
463 if (urb_type == MCEUSB_TX) {
464 async_urb = usb_alloc_urb(0, GFP_KERNEL);
465 if (unlikely(!async_urb)) {
466 dev_err(dev, "Error, couldn't allocate urb!\n");
467 return;
468 }
469
470 async_buf = kzalloc(size, GFP_KERNEL);
471 if (!async_buf) {
472 dev_err(dev, "Error, couldn't allocate buf!\n");
473 usb_free_urb(async_urb);
474 return;
475 }
476
477 /* outbound data */
478 usb_fill_int_urb(async_urb, ir->usbdev,
479 usb_sndintpipe(ir->usbdev, ep->bEndpointAddress),
480 async_buf, size, (usb_complete_t) usb_async_callback,
481 ir, ep->bInterval);
482 memcpy(async_buf, data, size);
483
484 } else if (urb_type == MCEUSB_RX) {
485 /* standard request */
486 async_urb = ir->urb_in;
487 ir->send_flags = RECV_FLAG_IN_PROGRESS;
488
489 } else {
490 dev_err(dev, "Error! Unknown urb type %d\n", urb_type);
491 return;
492 }
493
494 dev_dbg(dev, "receive request called (size=%#x)\n", size);
495
496 async_urb->transfer_buffer_length = size;
497 async_urb->dev = ir->usbdev;
498
499 res = usb_submit_urb(async_urb, GFP_ATOMIC);
500 if (res) {
501 dev_dbg(dev, "receive request FAILED! (res=%d)\n", res);
502 return;
503 }
504 dev_dbg(dev, "receive request complete (res=%d)\n", res);
505}
506
507static void mce_async_out(struct mceusb_dev *ir, unsigned char *data, int size)
508{
509 mce_request_packet(ir, ir->usb_ep_out, data, size, MCEUSB_TX);
510}
511
512static void mce_sync_in(struct mceusb_dev *ir, unsigned char *data, int size)
513{
514 mce_request_packet(ir, ir->usb_ep_in, data, size, MCEUSB_RX);
515}
516
517/* Send data out the IR blaster port(s) */
518static int mceusb_tx_ir(void *priv, int *txbuf, u32 n)
519{
520 struct mceusb_dev *ir = priv;
521 int i, ret = 0;
522 int count, cmdcount = 0;
523 unsigned char *cmdbuf; /* MCE command buffer */
524 long signal_duration = 0; /* Singnal length in us */
525 struct timeval start_time, end_time;
526
527 do_gettimeofday(&start_time);
528
529 count = n / sizeof(int);
530
531 cmdbuf = kzalloc(sizeof(int) * MCE_CMDBUF_SIZE, GFP_KERNEL);
532 if (!cmdbuf)
533 return -ENOMEM;
534
535 /* MCE tx init header */
536 cmdbuf[cmdcount++] = MCE_CONTROL_HEADER;
537 cmdbuf[cmdcount++] = 0x08;
538 cmdbuf[cmdcount++] = ir->tx_mask;
539
540 /* Generate mce packet data */
541 for (i = 0; (i < count) && (cmdcount < MCE_CMDBUF_SIZE); i++) {
542 signal_duration += txbuf[i];
543 txbuf[i] = txbuf[i] / MCE_TIME_UNIT;
544
545 do { /* loop to support long pulses/spaces > 127*50us=6.35ms */
546
547 /* Insert mce packet header every 4th entry */
548 if ((cmdcount < MCE_CMDBUF_SIZE) &&
549 (cmdcount - MCE_TX_HEADER_LENGTH) %
550 MCE_CODE_LENGTH == 0)
551 cmdbuf[cmdcount++] = MCE_PACKET_HEADER;
552
553 /* Insert mce packet data */
554 if (cmdcount < MCE_CMDBUF_SIZE)
555 cmdbuf[cmdcount++] =
556 (txbuf[i] < MCE_PULSE_BIT ?
557 txbuf[i] : MCE_MAX_PULSE_LENGTH) |
558 (i & 1 ? 0x00 : MCE_PULSE_BIT);
559 else {
560 ret = -EINVAL;
561 goto out;
562 }
563
564 } while ((txbuf[i] > MCE_MAX_PULSE_LENGTH) &&
565 (txbuf[i] -= MCE_MAX_PULSE_LENGTH));
566 }
567
568 /* Fix packet length in last header */
569 cmdbuf[cmdcount - (cmdcount - MCE_TX_HEADER_LENGTH) % MCE_CODE_LENGTH] =
570 0x80 + (cmdcount - MCE_TX_HEADER_LENGTH) % MCE_CODE_LENGTH - 1;
571
572 /* Check if we have room for the empty packet at the end */
573 if (cmdcount >= MCE_CMDBUF_SIZE) {
574 ret = -EINVAL;
575 goto out;
576 }
577
578 /* All mce commands end with an empty packet (0x80) */
579 cmdbuf[cmdcount++] = 0x80;
580
581 /* Transmit the command to the mce device */
582 mce_async_out(ir, cmdbuf, cmdcount);
583
584 /*
585 * The lircd gap calculation expects the write function to
586 * wait the time it takes for the ircommand to be sent before
587 * it returns.
588 */
589 do_gettimeofday(&end_time);
590 signal_duration -= (end_time.tv_usec - start_time.tv_usec) +
591 (end_time.tv_sec - start_time.tv_sec) * 1000000;
592
593 /* delay with the closest number of ticks */
594 set_current_state(TASK_INTERRUPTIBLE);
595 schedule_timeout(usecs_to_jiffies(signal_duration));
596
597out:
598 kfree(cmdbuf);
599 return ret ? ret : n;
600}
601
602/* Sets active IR outputs -- mce devices typically (all?) have two */
603static int mceusb_set_tx_mask(void *priv, u32 mask)
604{
605 struct mceusb_dev *ir = priv;
606
607 if (ir->flags.tx_mask_inverted)
608 ir->tx_mask = (mask != 0x03 ? mask ^ 0x03 : mask) << 1;
609 else
610 ir->tx_mask = mask;
611
612 return 0;
613}
614
615/* Sets the send carrier frequency and mode */
616static int mceusb_set_tx_carrier(void *priv, u32 carrier)
617{
618 struct mceusb_dev *ir = priv;
619 int clk = 10000000;
620 int prescaler = 0, divisor = 0;
621 unsigned char cmdbuf[4] = { 0x9f, 0x06, 0x00, 0x00 };
622
623 /* Carrier has changed */
624 if (ir->carrier != carrier) {
625
626 if (carrier == 0) {
627 ir->carrier = carrier;
628 cmdbuf[2] = 0x01;
629 cmdbuf[3] = 0x80;
630 dev_dbg(ir->dev, "%s: disabling carrier "
631 "modulation\n", __func__);
632 mce_async_out(ir, cmdbuf, sizeof(cmdbuf));
633 return carrier;
634 }
635
636 for (prescaler = 0; prescaler < 4; ++prescaler) {
637 divisor = (clk >> (2 * prescaler)) / carrier;
638 if (divisor <= 0xFF) {
639 ir->carrier = carrier;
640 cmdbuf[2] = prescaler;
641 cmdbuf[3] = divisor;
642 dev_dbg(ir->dev, "%s: requesting %u HZ "
643 "carrier\n", __func__, carrier);
644
645 /* Transmit new carrier to mce device */
646 mce_async_out(ir, cmdbuf, sizeof(cmdbuf));
647 return carrier;
648 }
649 }
650
651 return -EINVAL;
652
653 }
654
655 return carrier;
656}
657
658static void mceusb_process_ir_data(struct mceusb_dev *ir, int buf_len)
659{
660 struct ir_raw_event rawir = { .pulse = false, .duration = 0 };
661 int i, start_index = 0;
662 u8 hdr = MCE_CONTROL_HEADER;
663
664 /* skip meaningless 0xb1 0x60 header bytes on orig receiver */
665 if (ir->flags.microsoft_gen1)
666 start_index = 2;
667
668 for (i = start_index; i < buf_len;) {
669 if (ir->rem == 0) {
670 /* decode mce packets of the form (84),AA,BB,CC,DD */
671 /* IR data packets can span USB messages - rem */
672 hdr = ir->buf_in[i];
673 ir->rem = (hdr & MCE_PACKET_LENGTH_MASK);
674 ir->cmd = (hdr & ~MCE_PACKET_LENGTH_MASK);
675 dev_dbg(ir->dev, "New data. rem: 0x%02x, cmd: 0x%02x\n",
676 ir->rem, ir->cmd);
677 i++;
678 }
679
680 /* don't process MCE commands */
681 if (hdr == MCE_CONTROL_HEADER || hdr == 0xff) {
682 ir->rem = 0;
683 return;
684 }
685
686 for (; (ir->rem > 0) && (i < buf_len); i++) {
687 ir->rem--;
688
689 rawir.pulse = ((ir->buf_in[i] & MCE_PULSE_BIT) != 0);
690 rawir.duration = (ir->buf_in[i] & MCE_PULSE_MASK)
691 * MCE_TIME_UNIT * 1000;
692
693 if ((ir->buf_in[i] & MCE_PULSE_MASK) == 0x7f) {
694 if (ir->rawir.pulse == rawir.pulse)
695 ir->rawir.duration += rawir.duration;
696 else {
697 ir->rawir.duration = rawir.duration;
698 ir->rawir.pulse = rawir.pulse;
699 }
700 continue;
701 }
702 rawir.duration += ir->rawir.duration;
703 ir->rawir.duration = 0;
704 ir->rawir.pulse = rawir.pulse;
705
706 dev_dbg(ir->dev, "Storing %s with duration %d\n",
707 rawir.pulse ? "pulse" : "space",
708 rawir.duration);
709
710 ir_raw_event_store(ir->idev, &rawir);
711 }
712
713 if (ir->buf_in[i] == 0x80 || ir->buf_in[i] == 0x9f)
714 ir->rem = 0;
715
716 dev_dbg(ir->dev, "calling ir_raw_event_handle\n");
717 ir_raw_event_handle(ir->idev);
718 }
719}
720
721static void mceusb_dev_recv(struct urb *urb, struct pt_regs *regs)
722{
723 struct mceusb_dev *ir;
724 int buf_len;
725
726 if (!urb)
727 return;
728
729 ir = urb->context;
730 if (!ir) {
731 usb_unlink_urb(urb);
732 return;
733 }
734
735 buf_len = urb->actual_length;
736
737 if (debug)
738 mceusb_dev_printdata(ir, urb->transfer_buffer, buf_len, false);
739
740 if (ir->send_flags == RECV_FLAG_IN_PROGRESS) {
741 ir->send_flags = SEND_FLAG_COMPLETE;
742 dev_dbg(&ir->irdev->dev, "setup answer received %d bytes\n",
743 buf_len);
744 }
745
746 switch (urb->status) {
747 /* success */
748 case 0:
749 mceusb_process_ir_data(ir, buf_len);
750 break;
751
752 case -ECONNRESET:
753 case -ENOENT:
754 case -ESHUTDOWN:
755 usb_unlink_urb(urb);
756 return;
757
758 case -EPIPE:
759 default:
760 break;
761 }
762
763 usb_submit_urb(urb, GFP_ATOMIC);
764}
765
766static void mceusb_gen1_init(struct mceusb_dev *ir)
767{
768 int ret;
769 int maxp = ir->len_in;
770 struct device *dev = ir->dev;
771 char *data;
772
773 data = kzalloc(USB_CTRL_MSG_SZ, GFP_KERNEL);
774 if (!data) {
775 dev_err(dev, "%s: memory allocation failed!\n", __func__);
776 return;
777 }
778
779 /*
780 * This is a strange one. Windows issues a set address to the device
781 * on the receive control pipe and expect a certain value pair back
782 */
783 ret = usb_control_msg(ir->usbdev, usb_rcvctrlpipe(ir->usbdev, 0),
784 USB_REQ_SET_ADDRESS, USB_TYPE_VENDOR, 0, 0,
785 data, USB_CTRL_MSG_SZ, HZ * 3);
786 dev_dbg(dev, "%s - ret = %d\n", __func__, ret);
787 dev_dbg(dev, "%s - data[0] = %d, data[1] = %d\n",
788 __func__, data[0], data[1]);
789
790 /* set feature: bit rate 38400 bps */
791 ret = usb_control_msg(ir->usbdev, usb_sndctrlpipe(ir->usbdev, 0),
792 USB_REQ_SET_FEATURE, USB_TYPE_VENDOR,
793 0xc04e, 0x0000, NULL, 0, HZ * 3);
794
795 dev_dbg(dev, "%s - ret = %d\n", __func__, ret);
796
797 /* bRequest 4: set char length to 8 bits */
798 ret = usb_control_msg(ir->usbdev, usb_sndctrlpipe(ir->usbdev, 0),
799 4, USB_TYPE_VENDOR,
800 0x0808, 0x0000, NULL, 0, HZ * 3);
801 dev_dbg(dev, "%s - retB = %d\n", __func__, ret);
802
803 /* bRequest 2: set handshaking to use DTR/DSR */
804 ret = usb_control_msg(ir->usbdev, usb_sndctrlpipe(ir->usbdev, 0),
805 2, USB_TYPE_VENDOR,
806 0x0000, 0x0100, NULL, 0, HZ * 3);
807 dev_dbg(dev, "%s - retC = %d\n", __func__, ret);
808
809 /* device reset */
810 mce_async_out(ir, DEVICE_RESET, sizeof(DEVICE_RESET));
811 mce_sync_in(ir, NULL, maxp);
812
813 /* get hw/sw revision? */
814 mce_async_out(ir, GET_REVISION, sizeof(GET_REVISION));
815 mce_sync_in(ir, NULL, maxp);
816
817 kfree(data);
818};
819
820static void mceusb_gen2_init(struct mceusb_dev *ir)
821{
822 int maxp = ir->len_in;
823
824 /* device reset */
825 mce_async_out(ir, DEVICE_RESET, sizeof(DEVICE_RESET));
826 mce_sync_in(ir, NULL, maxp);
827
828 /* get hw/sw revision? */
829 mce_async_out(ir, GET_REVISION, sizeof(GET_REVISION));
830 mce_sync_in(ir, NULL, maxp);
831
832 /* unknown what the next two actually return... */
833 mce_async_out(ir, GET_UNKNOWN, sizeof(GET_UNKNOWN));
834 mce_sync_in(ir, NULL, maxp);
835 mce_async_out(ir, GET_UNKNOWN2, sizeof(GET_UNKNOWN2));
836 mce_sync_in(ir, NULL, maxp);
837}
838
839static void mceusb_get_parameters(struct mceusb_dev *ir)
840{
841 int maxp = ir->len_in;
842
843 /* get the carrier and frequency */
844 mce_async_out(ir, GET_CARRIER_FREQ, sizeof(GET_CARRIER_FREQ));
845 mce_sync_in(ir, NULL, maxp);
846
847 /* get the transmitter bitmask */
848 mce_async_out(ir, GET_TX_BITMASK, sizeof(GET_TX_BITMASK));
849 mce_sync_in(ir, NULL, maxp);
850
851 /* get receiver timeout value */
852 mce_async_out(ir, GET_RX_TIMEOUT, sizeof(GET_RX_TIMEOUT));
853 mce_sync_in(ir, NULL, maxp);
854
855 /* get receiver sensor setting */
856 mce_async_out(ir, GET_RX_SENSOR, sizeof(GET_RX_SENSOR));
857 mce_sync_in(ir, NULL, maxp);
858}
859
860static struct input_dev *mceusb_init_input_dev(struct mceusb_dev *ir)
861{
862 struct input_dev *idev;
863 struct ir_dev_props *props;
864 struct ir_input_dev *irdev;
865 struct device *dev = ir->dev;
866 int ret = -ENODEV;
867
868 idev = input_allocate_device();
869 if (!idev) {
870 dev_err(dev, "remote input dev allocation failed\n");
871 goto idev_alloc_failed;
872 }
873
874 ret = -ENOMEM;
875 props = kzalloc(sizeof(struct ir_dev_props), GFP_KERNEL);
876 if (!props) {
877 dev_err(dev, "remote ir dev props allocation failed\n");
878 goto props_alloc_failed;
879 }
880
881 irdev = kzalloc(sizeof(struct ir_input_dev), GFP_KERNEL);
882 if (!irdev) {
883 dev_err(dev, "remote ir input dev allocation failed\n");
884 goto ir_dev_alloc_failed;
885 }
886
887 snprintf(ir->name, sizeof(ir->name), "Media Center Ed. eHome "
888 "Infrared Remote Transceiver (%04x:%04x)",
889 le16_to_cpu(ir->usbdev->descriptor.idVendor),
890 le16_to_cpu(ir->usbdev->descriptor.idProduct));
891
892 idev->name = ir->name;
893 usb_make_path(ir->usbdev, ir->phys, sizeof(ir->phys));
894 strlcat(ir->phys, "/input0", sizeof(ir->phys));
895 idev->phys = ir->phys;
896
897 props->priv = ir;
898 props->driver_type = RC_DRIVER_IR_RAW;
899 props->allowed_protos = IR_TYPE_ALL;
900 props->s_tx_mask = mceusb_set_tx_mask;
901 props->s_tx_carrier = mceusb_set_tx_carrier;
902 props->tx_ir = mceusb_tx_ir;
903
904 ir->props = props;
905 ir->irdev = irdev;
906
907 input_set_drvdata(idev, irdev);
908
909 ret = ir_input_register(idev, RC_MAP_RC6_MCE, props, DRIVER_NAME);
910 if (ret < 0) {
911 dev_err(dev, "remote input device register failed\n");
912 goto irdev_failed;
913 }
914
915 return idev;
916
917irdev_failed:
918 kfree(irdev);
919ir_dev_alloc_failed:
920 kfree(props);
921props_alloc_failed:
922 input_free_device(idev);
923idev_alloc_failed:
924 return NULL;
925}
926
927static int __devinit mceusb_dev_probe(struct usb_interface *intf,
928 const struct usb_device_id *id)
929{
930 struct usb_device *dev = interface_to_usbdev(intf);
931 struct usb_host_interface *idesc;
932 struct usb_endpoint_descriptor *ep = NULL;
933 struct usb_endpoint_descriptor *ep_in = NULL;
934 struct usb_endpoint_descriptor *ep_out = NULL;
935 struct usb_host_config *config;
936 struct mceusb_dev *ir = NULL;
937 int pipe, maxp, i;
938 char buf[63], name[128] = "";
939 bool is_gen3;
940 bool is_microsoft_gen1;
941 bool tx_mask_inverted;
942
943 dev_dbg(&intf->dev, ": %s called\n", __func__);
944
945 config = dev->actconfig;
946 idesc = intf->cur_altsetting;
947
948 is_gen3 = usb_match_id(intf, gen3_list) ? 1 : 0;
949 is_microsoft_gen1 = usb_match_id(intf, microsoft_gen1_list) ? 1 : 0;
950 tx_mask_inverted = usb_match_id(intf, std_tx_mask_list) ? 0 : 1;
951
952 /* step through the endpoints to find first bulk in and out endpoint */
953 for (i = 0; i < idesc->desc.bNumEndpoints; ++i) {
954 ep = &idesc->endpoint[i].desc;
955
956 if ((ep_in == NULL)
957 && ((ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK)
958 == USB_DIR_IN)
959 && (((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
960 == USB_ENDPOINT_XFER_BULK)
961 || ((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
962 == USB_ENDPOINT_XFER_INT))) {
963
964 ep_in = ep;
965 ep_in->bmAttributes = USB_ENDPOINT_XFER_INT;
966 ep_in->bInterval = 1;
967 dev_dbg(&intf->dev, ": acceptable inbound endpoint "
968 "found\n");
969 }
970
971 if ((ep_out == NULL)
972 && ((ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK)
973 == USB_DIR_OUT)
974 && (((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
975 == USB_ENDPOINT_XFER_BULK)
976 || ((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
977 == USB_ENDPOINT_XFER_INT))) {
978
979 ep_out = ep;
980 ep_out->bmAttributes = USB_ENDPOINT_XFER_INT;
981 ep_out->bInterval = 1;
982 dev_dbg(&intf->dev, ": acceptable outbound endpoint "
983 "found\n");
984 }
985 }
986 if (ep_in == NULL) {
987 dev_dbg(&intf->dev, ": inbound and/or endpoint not found\n");
988 return -ENODEV;
989 }
990
991 pipe = usb_rcvintpipe(dev, ep_in->bEndpointAddress);
992 maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe));
993
994 ir = kzalloc(sizeof(struct mceusb_dev), GFP_KERNEL);
995 if (!ir)
996 goto mem_alloc_fail;
997
998 ir->buf_in = usb_alloc_coherent(dev, maxp, GFP_ATOMIC, &ir->dma_in);
999 if (!ir->buf_in)
1000 goto buf_in_alloc_fail;
1001
1002 ir->urb_in = usb_alloc_urb(0, GFP_KERNEL);
1003 if (!ir->urb_in)
1004 goto urb_in_alloc_fail;
1005
1006 ir->usbdev = dev;
1007 ir->dev = &intf->dev;
1008 ir->len_in = maxp;
1009 ir->flags.microsoft_gen1 = is_microsoft_gen1;
1010 ir->flags.tx_mask_inverted = tx_mask_inverted;
1011
1012 /* Saving usb interface data for use by the transmitter routine */
1013 ir->usb_ep_in = ep_in;
1014 ir->usb_ep_out = ep_out;
1015
1016 if (dev->descriptor.iManufacturer
1017 && usb_string(dev, dev->descriptor.iManufacturer,
1018 buf, sizeof(buf)) > 0)
1019 strlcpy(name, buf, sizeof(name));
1020 if (dev->descriptor.iProduct
1021 && usb_string(dev, dev->descriptor.iProduct,
1022 buf, sizeof(buf)) > 0)
1023 snprintf(name + strlen(name), sizeof(name) - strlen(name),
1024 " %s", buf);
1025
1026 ir->idev = mceusb_init_input_dev(ir);
1027 if (!ir->idev)
1028 goto input_dev_fail;
1029
1030 /* flush buffers on the device */
1031 mce_sync_in(ir, NULL, maxp);
1032 mce_sync_in(ir, NULL, maxp);
1033
1034 /* wire up inbound data handler */
1035 usb_fill_int_urb(ir->urb_in, dev, pipe, ir->buf_in,
1036 maxp, (usb_complete_t) mceusb_dev_recv, ir, ep_in->bInterval);
1037 ir->urb_in->transfer_dma = ir->dma_in;
1038 ir->urb_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1039
1040 /* initialize device */
1041 if (ir->flags.microsoft_gen1)
1042 mceusb_gen1_init(ir);
1043 else if (!is_gen3)
1044 mceusb_gen2_init(ir);
1045
1046 mceusb_get_parameters(ir);
1047
1048 mceusb_set_tx_mask(ir, MCE_DEFAULT_TX_MASK);
1049
1050 usb_set_intfdata(intf, ir);
1051
1052 dev_info(&intf->dev, "Registered %s on usb%d:%d\n", name,
1053 dev->bus->busnum, dev->devnum);
1054
1055 return 0;
1056
1057 /* Error-handling path */
1058input_dev_fail:
1059 usb_free_urb(ir->urb_in);
1060urb_in_alloc_fail:
1061 usb_free_coherent(dev, maxp, ir->buf_in, ir->dma_in);
1062buf_in_alloc_fail:
1063 kfree(ir);
1064mem_alloc_fail:
1065 dev_err(&intf->dev, "%s: device setup failed!\n", __func__);
1066
1067 return -ENOMEM;
1068}
1069
1070
1071static void __devexit mceusb_dev_disconnect(struct usb_interface *intf)
1072{
1073 struct usb_device *dev = interface_to_usbdev(intf);
1074 struct mceusb_dev *ir = usb_get_intfdata(intf);
1075
1076 usb_set_intfdata(intf, NULL);
1077
1078 if (!ir)
1079 return;
1080
1081 ir->usbdev = NULL;
1082 ir_input_unregister(ir->idev);
1083 usb_kill_urb(ir->urb_in);
1084 usb_free_urb(ir->urb_in);
1085 usb_free_coherent(dev, ir->len_in, ir->buf_in, ir->dma_in);
1086
1087 kfree(ir);
1088}
1089
1090static int mceusb_dev_suspend(struct usb_interface *intf, pm_message_t message)
1091{
1092 struct mceusb_dev *ir = usb_get_intfdata(intf);
1093 dev_info(ir->dev, "suspend\n");
1094 usb_kill_urb(ir->urb_in);
1095 return 0;
1096}
1097
1098static int mceusb_dev_resume(struct usb_interface *intf)
1099{
1100 struct mceusb_dev *ir = usb_get_intfdata(intf);
1101 dev_info(ir->dev, "resume\n");
1102 if (usb_submit_urb(ir->urb_in, GFP_ATOMIC))
1103 return -EIO;
1104 return 0;
1105}
1106
1107static struct usb_driver mceusb_dev_driver = {
1108 .name = DRIVER_NAME,
1109 .probe = mceusb_dev_probe,
1110 .disconnect = mceusb_dev_disconnect,
1111 .suspend = mceusb_dev_suspend,
1112 .resume = mceusb_dev_resume,
1113 .reset_resume = mceusb_dev_resume,
1114 .id_table = mceusb_dev_table
1115};
1116
1117static int __init mceusb_dev_init(void)
1118{
1119 int ret;
1120
1121 ret = usb_register(&mceusb_dev_driver);
1122 if (ret < 0)
1123 printk(KERN_ERR DRIVER_NAME
1124 ": usb register failed, result = %d\n", ret);
1125
1126 return ret;
1127}
1128
1129static void __exit mceusb_dev_exit(void)
1130{
1131 usb_deregister(&mceusb_dev_driver);
1132}
1133
1134module_init(mceusb_dev_init);
1135module_exit(mceusb_dev_exit);
1136
1137MODULE_DESCRIPTION(DRIVER_DESC);
1138MODULE_AUTHOR(DRIVER_AUTHOR);
1139MODULE_LICENSE("GPL");
1140MODULE_DEVICE_TABLE(usb, mceusb_dev_table);
1141
1142module_param(debug, bool, S_IRUGO | S_IWUSR);
1143MODULE_PARM_DESC(debug, "Debug enabled or not");
diff --git a/drivers/media/common/saa7146_fops.c b/drivers/media/common/saa7146_fops.c
index 7364b9642d00..4da2a54cb8bd 100644
--- a/drivers/media/common/saa7146_fops.c
+++ b/drivers/media/common/saa7146_fops.c
@@ -57,7 +57,7 @@ void saa7146_dma_free(struct saa7146_dev *dev,struct videobuf_queue *q,
57 BUG_ON(in_interrupt()); 57 BUG_ON(in_interrupt());
58 58
59 videobuf_waiton(&buf->vb,0,0); 59 videobuf_waiton(&buf->vb,0,0);
60 videobuf_dma_unmap(q, dma); 60 videobuf_dma_unmap(q->dev, dma);
61 videobuf_dma_free(dma); 61 videobuf_dma_free(dma);
62 buf->vb.state = VIDEOBUF_NEEDS_INIT; 62 buf->vb.state = VIDEOBUF_NEEDS_INIT;
63} 63}
diff --git a/drivers/media/common/saa7146_vbi.c b/drivers/media/common/saa7146_vbi.c
index 74e2b56ecb5b..8224c301d050 100644
--- a/drivers/media/common/saa7146_vbi.c
+++ b/drivers/media/common/saa7146_vbi.c
@@ -375,7 +375,7 @@ static void vbi_init(struct saa7146_dev *dev, struct saa7146_vv *vv)
375 375
376static int vbi_open(struct saa7146_dev *dev, struct file *file) 376static int vbi_open(struct saa7146_dev *dev, struct file *file)
377{ 377{
378 struct saa7146_fh *fh = (struct saa7146_fh *)file->private_data; 378 struct saa7146_fh *fh = file->private_data;
379 379
380 u32 arbtr_ctrl = saa7146_read(dev, PCI_BT_V1); 380 u32 arbtr_ctrl = saa7146_read(dev, PCI_BT_V1);
381 int ret = 0; 381 int ret = 0;
@@ -437,7 +437,7 @@ static int vbi_open(struct saa7146_dev *dev, struct file *file)
437 437
438static void vbi_close(struct saa7146_dev *dev, struct file *file) 438static void vbi_close(struct saa7146_dev *dev, struct file *file)
439{ 439{
440 struct saa7146_fh *fh = (struct saa7146_fh *)file->private_data; 440 struct saa7146_fh *fh = file->private_data;
441 struct saa7146_vv *vv = dev->vv_data; 441 struct saa7146_vv *vv = dev->vv_data;
442 DEB_VBI(("dev:%p, fh:%p\n",dev,fh)); 442 DEB_VBI(("dev:%p, fh:%p\n",dev,fh));
443 443
diff --git a/drivers/media/common/saa7146_video.c b/drivers/media/common/saa7146_video.c
index b8b2c551a1e2..a212a91a30f0 100644
--- a/drivers/media/common/saa7146_video.c
+++ b/drivers/media/common/saa7146_video.c
@@ -1370,7 +1370,7 @@ static void video_init(struct saa7146_dev *dev, struct saa7146_vv *vv)
1370 1370
1371static int video_open(struct saa7146_dev *dev, struct file *file) 1371static int video_open(struct saa7146_dev *dev, struct file *file)
1372{ 1372{
1373 struct saa7146_fh *fh = (struct saa7146_fh *)file->private_data; 1373 struct saa7146_fh *fh = file->private_data;
1374 struct saa7146_format *sfmt; 1374 struct saa7146_format *sfmt;
1375 1375
1376 fh->video_fmt.width = 384; 1376 fh->video_fmt.width = 384;
@@ -1394,7 +1394,7 @@ static int video_open(struct saa7146_dev *dev, struct file *file)
1394 1394
1395static void video_close(struct saa7146_dev *dev, struct file *file) 1395static void video_close(struct saa7146_dev *dev, struct file *file)
1396{ 1396{
1397 struct saa7146_fh *fh = (struct saa7146_fh *)file->private_data; 1397 struct saa7146_fh *fh = file->private_data;
1398 struct saa7146_vv *vv = dev->vv_data; 1398 struct saa7146_vv *vv = dev->vv_data;
1399 struct videobuf_queue *q = &fh->video_q; 1399 struct videobuf_queue *q = &fh->video_q;
1400 int err; 1400 int err;
diff --git a/drivers/media/common/tuners/tda18271-fe.c b/drivers/media/common/tuners/tda18271-fe.c
index b2e15456d5f3..7955e49a3440 100644
--- a/drivers/media/common/tuners/tda18271-fe.c
+++ b/drivers/media/common/tuners/tda18271-fe.c
@@ -1249,7 +1249,7 @@ struct dvb_frontend *tda18271_attach(struct dvb_frontend *fe, u8 addr,
1249 struct tda18271_config *cfg) 1249 struct tda18271_config *cfg)
1250{ 1250{
1251 struct tda18271_priv *priv = NULL; 1251 struct tda18271_priv *priv = NULL;
1252 int instance; 1252 int instance, ret;
1253 1253
1254 mutex_lock(&tda18271_list_mutex); 1254 mutex_lock(&tda18271_list_mutex);
1255 1255
@@ -1268,10 +1268,12 @@ struct dvb_frontend *tda18271_attach(struct dvb_frontend *fe, u8 addr,
1268 priv->cal_initialized = false; 1268 priv->cal_initialized = false;
1269 mutex_init(&priv->lock); 1269 mutex_init(&priv->lock);
1270 1270
1271 if (tda_fail(tda18271_get_id(fe))) 1271 ret = tda18271_get_id(fe);
1272 if (tda_fail(ret))
1272 goto fail; 1273 goto fail;
1273 1274
1274 if (tda_fail(tda18271_assign_map_layout(fe))) 1275 ret = tda18271_assign_map_layout(fe);
1276 if (tda_fail(ret))
1275 goto fail; 1277 goto fail;
1276 1278
1277 mutex_lock(&priv->lock); 1279 mutex_lock(&priv->lock);
diff --git a/drivers/media/common/tuners/tuner-simple.c b/drivers/media/common/tuners/tuner-simple.c
index 8cf2ab609d5e..f8ee29e6059c 100644
--- a/drivers/media/common/tuners/tuner-simple.c
+++ b/drivers/media/common/tuners/tuner-simple.c
@@ -546,14 +546,11 @@ static int simple_set_tv_freq(struct dvb_frontend *fe,
546 struct tuner_simple_priv *priv = fe->tuner_priv; 546 struct tuner_simple_priv *priv = fe->tuner_priv;
547 u8 config, cb; 547 u8 config, cb;
548 u16 div; 548 u16 div;
549 struct tunertype *tun;
550 u8 buffer[4]; 549 u8 buffer[4];
551 int rc, IFPCoff, i; 550 int rc, IFPCoff, i;
552 enum param_type desired_type; 551 enum param_type desired_type;
553 struct tuner_params *t_params; 552 struct tuner_params *t_params;
554 553
555 tun = priv->tun;
556
557 /* IFPCoff = Video Intermediate Frequency - Vif: 554 /* IFPCoff = Video Intermediate Frequency - Vif:
558 940 =16*58.75 NTSC/J (Japan) 555 940 =16*58.75 NTSC/J (Japan)
559 732 =16*45.75 M/N STD 556 732 =16*45.75 M/N STD
diff --git a/drivers/media/common/tuners/xc5000.c b/drivers/media/common/tuners/xc5000.c
index 432003dded7c..d2b2c12a5561 100644
--- a/drivers/media/common/tuners/xc5000.c
+++ b/drivers/media/common/tuners/xc5000.c
@@ -217,6 +217,7 @@ static int xc_send_i2c_data(struct xc5000_priv *priv, u8 *buf, int len)
217 return XC_RESULT_SUCCESS; 217 return XC_RESULT_SUCCESS;
218} 218}
219 219
220#if 0
220/* This routine is never used because the only time we read data from the 221/* This routine is never used because the only time we read data from the
221 i2c bus is when we read registers, and we want that to be an atomic i2c 222 i2c bus is when we read registers, and we want that to be an atomic i2c
222 transaction in case we are on a multi-master bus */ 223 transaction in case we are on a multi-master bus */
@@ -231,6 +232,27 @@ static int xc_read_i2c_data(struct xc5000_priv *priv, u8 *buf, int len)
231 } 232 }
232 return 0; 233 return 0;
233} 234}
235#endif
236
237static int xc5000_readreg(struct xc5000_priv *priv, u16 reg, u16 *val)
238{
239 u8 buf[2] = { reg >> 8, reg & 0xff };
240 u8 bval[2] = { 0, 0 };
241 struct i2c_msg msg[2] = {
242 { .addr = priv->i2c_props.addr,
243 .flags = 0, .buf = &buf[0], .len = 2 },
244 { .addr = priv->i2c_props.addr,
245 .flags = I2C_M_RD, .buf = &bval[0], .len = 2 },
246 };
247
248 if (i2c_transfer(priv->i2c_props.adap, msg, 2) != 2) {
249 printk(KERN_WARNING "xc5000: I2C read failed\n");
250 return -EREMOTEIO;
251 }
252
253 *val = (bval[0] << 8) | bval[1];
254 return XC_RESULT_SUCCESS;
255}
234 256
235static void xc_wait(int wait_ms) 257static void xc_wait(int wait_ms)
236{ 258{
@@ -275,20 +297,14 @@ static int xc_write_reg(struct xc5000_priv *priv, u16 regAddr, u16 i2cData)
275 if (result == XC_RESULT_SUCCESS) { 297 if (result == XC_RESULT_SUCCESS) {
276 /* wait for busy flag to clear */ 298 /* wait for busy flag to clear */
277 while ((WatchDogTimer > 0) && (result == XC_RESULT_SUCCESS)) { 299 while ((WatchDogTimer > 0) && (result == XC_RESULT_SUCCESS)) {
278 buf[0] = 0; 300 result = xc5000_readreg(priv, XREG_BUSY, (u16 *)buf);
279 buf[1] = XREG_BUSY;
280
281 result = xc_send_i2c_data(priv, buf, 2);
282 if (result == XC_RESULT_SUCCESS) { 301 if (result == XC_RESULT_SUCCESS) {
283 result = xc_read_i2c_data(priv, buf, 2); 302 if ((buf[0] == 0) && (buf[1] == 0)) {
284 if (result == XC_RESULT_SUCCESS) { 303 /* busy flag cleared */
285 if ((buf[0] == 0) && (buf[1] == 0)) {
286 /* busy flag cleared */
287 break; 304 break;
288 } else { 305 } else {
289 xc_wait(5); /* wait 5 ms */ 306 xc_wait(5); /* wait 5 ms */
290 WatchDogTimer--; 307 WatchDogTimer--;
291 }
292 } 308 }
293 } 309 }
294 } 310 }
@@ -526,25 +542,6 @@ static int xc_tune_channel(struct xc5000_priv *priv, u32 freq_hz, int mode)
526 return found; 542 return found;
527} 543}
528 544
529static int xc5000_readreg(struct xc5000_priv *priv, u16 reg, u16 *val)
530{
531 u8 buf[2] = { reg >> 8, reg & 0xff };
532 u8 bval[2] = { 0, 0 };
533 struct i2c_msg msg[2] = {
534 { .addr = priv->i2c_props.addr,
535 .flags = 0, .buf = &buf[0], .len = 2 },
536 { .addr = priv->i2c_props.addr,
537 .flags = I2C_M_RD, .buf = &bval[0], .len = 2 },
538 };
539
540 if (i2c_transfer(priv->i2c_props.adap, msg, 2) != 2) {
541 printk(KERN_WARNING "xc5000: I2C read failed\n");
542 return -EREMOTEIO;
543 }
544
545 *val = (bval[0] << 8) | bval[1];
546 return XC_RESULT_SUCCESS;
547}
548 545
549static int xc5000_fwupload(struct dvb_frontend *fe) 546static int xc5000_fwupload(struct dvb_frontend *fe)
550{ 547{
diff --git a/drivers/media/dvb/bt8xx/dst_ca.c b/drivers/media/dvb/bt8xx/dst_ca.c
index 770243c720d2..cf8705162845 100644
--- a/drivers/media/dvb/bt8xx/dst_ca.c
+++ b/drivers/media/dvb/bt8xx/dst_ca.c
@@ -565,7 +565,7 @@ static long dst_ca_ioctl(struct file *file, unsigned int cmd, unsigned long ioct
565 int result = 0; 565 int result = 0;
566 566
567 lock_kernel(); 567 lock_kernel();
568 dvbdev = (struct dvb_device *)file->private_data; 568 dvbdev = file->private_data;
569 state = (struct dst_state *)dvbdev->priv; 569 state = (struct dst_state *)dvbdev->priv;
570 p_ca_message = kmalloc(sizeof (struct ca_msg), GFP_KERNEL); 570 p_ca_message = kmalloc(sizeof (struct ca_msg), GFP_KERNEL);
571 p_ca_slot_info = kmalloc(sizeof (struct ca_slot_info), GFP_KERNEL); 571 p_ca_slot_info = kmalloc(sizeof (struct ca_slot_info), GFP_KERNEL);
diff --git a/drivers/media/dvb/dvb-core/dmxdev.c b/drivers/media/dvb/dvb-core/dmxdev.c
index 425862ffb285..0042306ea11b 100644
--- a/drivers/media/dvb/dvb-core/dmxdev.c
+++ b/drivers/media/dvb/dvb-core/dmxdev.c
@@ -207,7 +207,7 @@ static int dvb_dvr_release(struct inode *inode, struct file *file)
207 } 207 }
208 /* TODO */ 208 /* TODO */
209 dvbdev->users--; 209 dvbdev->users--;
210 if(dvbdev->users==-1 && dmxdev->exit==1) { 210 if (dvbdev->users == 1 && dmxdev->exit == 1) {
211 fops_put(file->f_op); 211 fops_put(file->f_op);
212 file->f_op = NULL; 212 file->f_op = NULL;
213 mutex_unlock(&dmxdev->mutex); 213 mutex_unlock(&dmxdev->mutex);
diff --git a/drivers/media/dvb/dvb-core/dvb_ca_en50221.c b/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
index ef259a0718ac..cb97e6b85432 100644
--- a/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
+++ b/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
@@ -1318,8 +1318,11 @@ static ssize_t dvb_ca_en50221_io_write(struct file *file,
1318 1318
1319 fragbuf[0] = connection_id; 1319 fragbuf[0] = connection_id;
1320 fragbuf[1] = ((fragpos + fraglen) < count) ? 0x80 : 0x00; 1320 fragbuf[1] = ((fragpos + fraglen) < count) ? 0x80 : 0x00;
1321 if ((status = copy_from_user(fragbuf + 2, buf + fragpos, fraglen)) != 0) 1321 status = copy_from_user(fragbuf + 2, buf + fragpos, fraglen);
1322 if (status) {
1323 status = -EFAULT;
1322 goto exit; 1324 goto exit;
1325 }
1323 1326
1324 timeout = jiffies + HZ / 2; 1327 timeout = jiffies + HZ / 2;
1325 written = 0; 1328 written = 0;
@@ -1494,8 +1497,11 @@ static ssize_t dvb_ca_en50221_io_read(struct file *file, char __user * buf,
1494 1497
1495 hdr[0] = slot; 1498 hdr[0] = slot;
1496 hdr[1] = connection_id; 1499 hdr[1] = connection_id;
1497 if ((status = copy_to_user(buf, hdr, 2)) != 0) 1500 status = copy_to_user(buf, hdr, 2);
1501 if (status) {
1502 status = -EFAULT;
1498 goto exit; 1503 goto exit;
1504 }
1499 status = pktlen; 1505 status = pktlen;
1500 1506
1501exit: 1507exit:
diff --git a/drivers/media/dvb/dvb-core/dvb_demux.c b/drivers/media/dvb/dvb-core/dvb_demux.c
index 977ddba3e235..4a88a3e4db2b 100644
--- a/drivers/media/dvb/dvb-core/dvb_demux.c
+++ b/drivers/media/dvb/dvb-core/dvb_demux.c
@@ -1130,13 +1130,9 @@ static int dvbdmx_write(struct dmx_demux *demux, const char __user *buf, size_t
1130 if ((!demux->frontend) || (demux->frontend->source != DMX_MEMORY_FE)) 1130 if ((!demux->frontend) || (demux->frontend->source != DMX_MEMORY_FE))
1131 return -EINVAL; 1131 return -EINVAL;
1132 1132
1133 p = kmalloc(count, GFP_USER); 1133 p = memdup_user(buf, count);
1134 if (!p) 1134 if (IS_ERR(p))
1135 return -ENOMEM; 1135 return PTR_ERR(p);
1136 if (copy_from_user(p, buf, count)) {
1137 kfree(p);
1138 return -EFAULT;
1139 }
1140 if (mutex_lock_interruptible(&dvbdemux->mutex)) { 1136 if (mutex_lock_interruptible(&dvbdemux->mutex)) {
1141 kfree(p); 1137 kfree(p);
1142 return -ERESTARTSYS; 1138 return -ERESTARTSYS;
diff --git a/drivers/media/dvb/dvb-core/dvb_frontend.c b/drivers/media/dvb/dvb-core/dvb_frontend.c
index 44ae89ecef94..4d45b7d6b3fb 100644
--- a/drivers/media/dvb/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb/dvb-core/dvb_frontend.c
@@ -465,7 +465,7 @@ static void dvb_frontend_swzigzag(struct dvb_frontend *fe)
465 if ((fepriv->state & FESTATE_SEARCHING_FAST) || (fepriv->state & FESTATE_RETUNE)) { 465 if ((fepriv->state & FESTATE_SEARCHING_FAST) || (fepriv->state & FESTATE_RETUNE)) {
466 fepriv->delay = fepriv->min_delay; 466 fepriv->delay = fepriv->min_delay;
467 467
468 /* peform a tune */ 468 /* perform a tune */
469 retval = dvb_frontend_swzigzag_autotune(fe, 469 retval = dvb_frontend_swzigzag_autotune(fe,
470 fepriv->check_wrapped); 470 fepriv->check_wrapped);
471 if (retval < 0) { 471 if (retval < 0) {
@@ -791,7 +791,7 @@ static int dvb_frontend_start(struct dvb_frontend *fe)
791 return 0; 791 return 0;
792} 792}
793 793
794static void dvb_frontend_get_frequeny_limits(struct dvb_frontend *fe, 794static void dvb_frontend_get_frequency_limits(struct dvb_frontend *fe,
795 u32 *freq_min, u32 *freq_max) 795 u32 *freq_min, u32 *freq_max)
796{ 796{
797 *freq_min = max(fe->ops.info.frequency_min, fe->ops.tuner_ops.info.frequency_min); 797 *freq_min = max(fe->ops.info.frequency_min, fe->ops.tuner_ops.info.frequency_min);
@@ -815,7 +815,7 @@ static int dvb_frontend_check_parameters(struct dvb_frontend *fe,
815 u32 freq_max; 815 u32 freq_max;
816 816
817 /* range check: frequency */ 817 /* range check: frequency */
818 dvb_frontend_get_frequeny_limits(fe, &freq_min, &freq_max); 818 dvb_frontend_get_frequency_limits(fe, &freq_min, &freq_max);
819 if ((freq_min && parms->frequency < freq_min) || 819 if ((freq_min && parms->frequency < freq_min) ||
820 (freq_max && parms->frequency > freq_max)) { 820 (freq_max && parms->frequency > freq_max)) {
821 printk(KERN_WARNING "DVB: adapter %i frontend %i frequency %u out of range (%u..%u)\n", 821 printk(KERN_WARNING "DVB: adapter %i frontend %i frequency %u out of range (%u..%u)\n",
@@ -1627,7 +1627,7 @@ static int dvb_frontend_ioctl_legacy(struct file *file,
1627 case FE_GET_INFO: { 1627 case FE_GET_INFO: {
1628 struct dvb_frontend_info* info = parg; 1628 struct dvb_frontend_info* info = parg;
1629 memcpy(info, &fe->ops.info, sizeof(struct dvb_frontend_info)); 1629 memcpy(info, &fe->ops.info, sizeof(struct dvb_frontend_info));
1630 dvb_frontend_get_frequeny_limits(fe, &info->frequency_min, &info->frequency_max); 1630 dvb_frontend_get_frequency_limits(fe, &info->frequency_min, &info->frequency_max);
1631 1631
1632 /* Force the CAN_INVERSION_AUTO bit on. If the frontend doesn't 1632 /* Force the CAN_INVERSION_AUTO bit on. If the frontend doesn't
1633 * do it, it is done for it. */ 1633 * do it, it is done for it. */
@@ -1726,7 +1726,7 @@ static int dvb_frontend_ioctl_legacy(struct file *file,
1726 * (stv0299 for instance) take longer than 8msec to 1726 * (stv0299 for instance) take longer than 8msec to
1727 * respond to a set_voltage command. Those switches 1727 * respond to a set_voltage command. Those switches
1728 * need custom routines to switch properly. For all 1728 * need custom routines to switch properly. For all
1729 * other frontends, the following shoule work ok. 1729 * other frontends, the following should work ok.
1730 * Dish network legacy switches (as used by Dish500) 1730 * Dish network legacy switches (as used by Dish500)
1731 * are controlled by sending 9-bit command words 1731 * are controlled by sending 9-bit command words
1732 * spaced 8msec apart. 1732 * spaced 8msec apart.
diff --git a/drivers/media/dvb/dvb-usb/a800.c b/drivers/media/dvb/dvb-usb/a800.c
index b6cbb1dfc5f1..a5c363727133 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 dvb_usb_rc_key ir_codes_a800_table[] = { 40static struct ir_scancode ir_codes_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 */
@@ -146,10 +146,12 @@ static struct dvb_usb_device_properties a800_properties = {
146 .power_ctrl = a800_power_ctrl, 146 .power_ctrl = a800_power_ctrl,
147 .identify_state = a800_identify_state, 147 .identify_state = a800_identify_state,
148 148
149 .rc_interval = DEFAULT_RC_INTERVAL, 149 .rc.legacy = {
150 .rc_key_map = ir_codes_a800_table, 150 .rc_interval = DEFAULT_RC_INTERVAL,
151 .rc_key_map_size = ARRAY_SIZE(ir_codes_a800_table), 151 .rc_key_map = ir_codes_a800_table,
152 .rc_query = a800_rc_query, 152 .rc_key_map_size = ARRAY_SIZE(ir_codes_a800_table),
153 .rc_query = a800_rc_query,
154 },
153 155
154 .i2c_algo = &dibusb_i2c_algo, 156 .i2c_algo = &dibusb_i2c_algo,
155 157
diff --git a/drivers/media/dvb/dvb-usb/af9005-remote.c b/drivers/media/dvb/dvb-usb/af9005-remote.c
index b41fa873b04d..696207fe37ec 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 dvb_usb_rc_key ir_codes_af9005_table[] = { 36struct ir_scancode ir_codes_af9005_table[] = {
37 37
38 {0x01b7, KEY_POWER}, 38 {0x01b7, KEY_POWER},
39 {0x01a7, KEY_VOLUMEUP}, 39 {0x01a7, KEY_VOLUMEUP},
@@ -133,7 +133,7 @@ int af9005_rc_decode(struct dvb_usb_device *d, u8 * data, int len, u32 * event,
133 for (i = 0; i < ir_codes_af9005_table_size; i++) { 133 for (i = 0; i < ir_codes_af9005_table_size; i++) {
134 if (rc5_custom(&ir_codes_af9005_table[i]) == cust 134 if (rc5_custom(&ir_codes_af9005_table[i]) == cust
135 && rc5_data(&ir_codes_af9005_table[i]) == dat) { 135 && rc5_data(&ir_codes_af9005_table[i]) == dat) {
136 *event = ir_codes_af9005_table[i].event; 136 *event = ir_codes_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);
diff --git a/drivers/media/dvb/dvb-usb/af9005.c b/drivers/media/dvb/dvb-usb/af9005.c
index cfd6107d5349..8ecba8848bcf 100644
--- a/drivers/media/dvb/dvb-usb/af9005.c
+++ b/drivers/media/dvb/dvb-usb/af9005.c
@@ -54,50 +54,6 @@ struct af9005_device_state {
54 int led_state; 54 int led_state;
55}; 55};
56 56
57static int af9005_usb_generic_rw(struct dvb_usb_device *d, u8 *wbuf, u16 wlen,
58 u8 *rbuf, u16 rlen, int delay_ms)
59{
60 int actlen, ret = -ENOMEM;
61
62 if (wbuf == NULL || wlen == 0)
63 return -EINVAL;
64
65 if ((ret = mutex_lock_interruptible(&d->usb_mutex)))
66 return ret;
67
68 deb_xfer(">>> ");
69 debug_dump(wbuf, wlen, deb_xfer);
70
71 ret = usb_bulk_msg(d->udev, usb_sndbulkpipe(d->udev,
72 2), wbuf, wlen,
73 &actlen, 2000);
74
75 if (ret)
76 err("bulk message failed: %d (%d/%d)", ret, wlen, actlen);
77 else
78 ret = actlen != wlen ? -1 : 0;
79
80 /* an answer is expected, and no error before */
81 if (!ret && rbuf && rlen) {
82 if (delay_ms)
83 msleep(delay_ms);
84
85 ret = usb_bulk_msg(d->udev, usb_rcvbulkpipe(d->udev,
86 0x01), rbuf,
87 rlen, &actlen, 2000);
88
89 if (ret)
90 err("recv bulk message failed: %d", ret);
91 else {
92 deb_xfer("<<< ");
93 debug_dump(rbuf, actlen, deb_xfer);
94 }
95 }
96
97 mutex_unlock(&d->usb_mutex);
98 return ret;
99}
100
101static int af9005_generic_read_write(struct dvb_usb_device *d, u16 reg, 57static int af9005_generic_read_write(struct dvb_usb_device *d, u16 reg,
102 int readwrite, int type, u8 * values, int len) 58 int readwrite, int type, u8 * values, int len)
103{ 59{
@@ -146,7 +102,7 @@ static int af9005_generic_read_write(struct dvb_usb_device *d, u16 reg,
146 obuf[8] = values[0]; 102 obuf[8] = values[0];
147 obuf[7] = command; 103 obuf[7] = command;
148 104
149 ret = af9005_usb_generic_rw(d, obuf, 16, ibuf, 17, 0); 105 ret = dvb_usb_generic_rw(d, obuf, 16, ibuf, 17, 0);
150 if (ret) 106 if (ret)
151 return ret; 107 return ret;
152 108
@@ -534,7 +490,7 @@ int af9005_send_command(struct dvb_usb_device *d, u8 command, u8 * wbuf,
534 buf[6] = wlen; 490 buf[6] = wlen;
535 for (i = 0; i < wlen; i++) 491 for (i = 0; i < wlen; i++)
536 buf[7 + i] = wbuf[i]; 492 buf[7 + i] = wbuf[i];
537 ret = af9005_usb_generic_rw(d, buf, wlen + 7, ibuf, rlen + 7, 0); 493 ret = dvb_usb_generic_rw(d, buf, wlen + 7, ibuf, rlen + 7, 0);
538 if (ret) 494 if (ret)
539 return ret; 495 return ret;
540 if (ibuf[2] != 0x27) { 496 if (ibuf[2] != 0x27) {
@@ -581,7 +537,7 @@ int af9005_read_eeprom(struct dvb_usb_device *d, u8 address, u8 * values,
581 537
582 obuf[6] = len; 538 obuf[6] = len;
583 obuf[7] = address; 539 obuf[7] = address;
584 ret = af9005_usb_generic_rw(d, obuf, 16, ibuf, 14, 0); 540 ret = dvb_usb_generic_rw(d, obuf, 16, ibuf, 14, 0);
585 if (ret) 541 if (ret)
586 return ret; 542 return ret;
587 if (ibuf[2] != 0x2b) { 543 if (ibuf[2] != 0x2b) {
@@ -882,7 +838,7 @@ static int af9005_rc_query(struct dvb_usb_device *d, u32 * event, int *state)
882 obuf[2] = 0x40; /* read remote */ 838 obuf[2] = 0x40; /* read remote */
883 obuf[3] = 1; /* rest of packet length */ 839 obuf[3] = 1; /* rest of packet length */
884 obuf[4] = st->sequence++; /* sequence number */ 840 obuf[4] = st->sequence++; /* sequence number */
885 ret = af9005_usb_generic_rw(d, obuf, 5, ibuf, 256, 0); 841 ret = dvb_usb_generic_rw(d, obuf, 5, ibuf, 256, 0);
886 if (ret) { 842 if (ret) {
887 err("rc query failed"); 843 err("rc query failed");
888 return ret; 844 return ret;
@@ -1069,10 +1025,15 @@ static struct dvb_usb_device_properties af9005_properties = {
1069 1025
1070 .i2c_algo = &af9005_i2c_algo, 1026 .i2c_algo = &af9005_i2c_algo,
1071 1027
1072 .rc_interval = 200, 1028 .rc.legacy = {
1073 .rc_key_map = NULL, 1029 .rc_interval = 200,
1074 .rc_key_map_size = 0, 1030 .rc_key_map = NULL,
1075 .rc_query = af9005_rc_query, 1031 .rc_key_map_size = 0,
1032 .rc_query = af9005_rc_query,
1033 },
1034
1035 .generic_bulk_ctrl_endpoint = 2,
1036 .generic_bulk_ctrl_endpoint_response = 1,
1076 1037
1077 .num_device_descs = 3, 1038 .num_device_descs = 3,
1078 .devices = { 1039 .devices = {
@@ -1113,10 +1074,10 @@ static int __init af9005_usb_module_init(void)
1113 rc_keys_size = symbol_request(ir_codes_af9005_table_size); 1074 rc_keys_size = symbol_request(ir_codes_af9005_table_size);
1114 if (rc_decode == NULL || rc_keys == NULL || rc_keys_size == NULL) { 1075 if (rc_decode == NULL || rc_keys == NULL || rc_keys_size == NULL) {
1115 err("af9005_rc_decode function not found, disabling remote"); 1076 err("af9005_rc_decode function not found, disabling remote");
1116 af9005_properties.rc_query = NULL; 1077 af9005_properties.rc.legacy.rc_query = NULL;
1117 } else { 1078 } else {
1118 af9005_properties.rc_key_map = rc_keys; 1079 af9005_properties.rc.legacy.rc_key_map = rc_keys;
1119 af9005_properties.rc_key_map_size = *rc_keys_size; 1080 af9005_properties.rc.legacy.rc_key_map_size = *rc_keys_size;
1120 } 1081 }
1121 1082
1122 return 0; 1083 return 0;
diff --git a/drivers/media/dvb/dvb-usb/af9005.h b/drivers/media/dvb/dvb-usb/af9005.h
index 088e7083a39b..3c1fbd1c5d60 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 dvb_usb_rc_key ir_codes_af9005_table[]; 3493extern struct ir_scancode ir_codes_af9005_table[];
3494extern int ir_codes_af9005_table_size; 3494extern int ir_codes_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 66c7c3ea7990..ea1ed3b4592a 100644
--- a/drivers/media/dvb/dvb-usb/af9015.c
+++ b/drivers/media/dvb/dvb-usb/af9015.c
@@ -735,7 +735,7 @@ error:
735 735
736struct af9015_setup { 736struct af9015_setup {
737 unsigned int id; 737 unsigned int id;
738 struct dvb_usb_rc_key *rc_key_map; 738 struct ir_scancode *rc_key_map;
739 unsigned int rc_key_map_size; 739 unsigned int rc_key_map_size;
740 u8 *ir_table; 740 u8 *ir_table;
741 unsigned int ir_table_size; 741 unsigned int ir_table_size;
@@ -847,8 +847,8 @@ static void af9015_set_remote_config(struct usb_device *udev,
847 } 847 }
848 848
849 if (table) { 849 if (table) {
850 props->rc_key_map = table->rc_key_map; 850 props->rc.legacy.rc_key_map = table->rc_key_map;
851 props->rc_key_map_size = table->rc_key_map_size; 851 props->rc.legacy.rc_key_map_size = table->rc_key_map_size;
852 af9015_config.ir_table = table->ir_table; 852 af9015_config.ir_table = table->ir_table;
853 af9015_config.ir_table_size = table->ir_table_size; 853 af9015_config.ir_table_size = table->ir_table_size;
854 } 854 }
@@ -878,8 +878,8 @@ static int af9015_read_config(struct usb_device *udev)
878 deb_info("%s: IR mode:%d\n", __func__, val); 878 deb_info("%s: IR mode:%d\n", __func__, val);
879 for (i = 0; i < af9015_properties_count; i++) { 879 for (i = 0; i < af9015_properties_count; i++) {
880 if (val == AF9015_IR_MODE_DISABLED) { 880 if (val == AF9015_IR_MODE_DISABLED) {
881 af9015_properties[i].rc_key_map = NULL; 881 af9015_properties[i].rc.legacy.rc_key_map = NULL;
882 af9015_properties[i].rc_key_map_size = 0; 882 af9015_properties[i].rc.legacy.rc_key_map_size = 0;
883 } else 883 } else
884 af9015_set_remote_config(udev, &af9015_properties[i]); 884 af9015_set_remote_config(udev, &af9015_properties[i]);
885 } 885 }
@@ -1063,7 +1063,7 @@ static int af9015_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
1063{ 1063{
1064 u8 buf[8]; 1064 u8 buf[8];
1065 struct req_t req = {GET_IR_CODE, 0, 0, 0, 0, sizeof(buf), buf}; 1065 struct req_t req = {GET_IR_CODE, 0, 0, 0, 0, sizeof(buf), buf};
1066 struct dvb_usb_rc_key *keymap = d->props.rc_key_map; 1066 struct ir_scancode *keymap = d->props.rc.legacy.rc_key_map;
1067 int i, ret; 1067 int i, ret;
1068 1068
1069 memset(buf, 0, sizeof(buf)); 1069 memset(buf, 0, sizeof(buf));
@@ -1075,10 +1075,10 @@ static int af9015_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
1075 *event = 0; 1075 *event = 0;
1076 *state = REMOTE_NO_KEY_PRESSED; 1076 *state = REMOTE_NO_KEY_PRESSED;
1077 1077
1078 for (i = 0; i < d->props.rc_key_map_size; i++) { 1078 for (i = 0; i < d->props.rc.legacy.rc_key_map_size; i++) {
1079 if (!buf[1] && rc5_custom(&keymap[i]) == buf[0] && 1079 if (!buf[1] && rc5_custom(&keymap[i]) == buf[0] &&
1080 rc5_data(&keymap[i]) == buf[2]) { 1080 rc5_data(&keymap[i]) == buf[2]) {
1081 *event = keymap[i].event; 1081 *event = keymap[i].keycode;
1082 *state = REMOTE_KEY_PRESSED; 1082 *state = REMOTE_KEY_PRESSED;
1083 break; 1083 break;
1084 } 1084 }
@@ -1299,6 +1299,7 @@ static struct usb_device_id af9015_usb_table[] = {
1299 {USB_DEVICE(USB_VID_LEADTEK, USB_PID_WINFAST_DTV2000DS)}, 1299 {USB_DEVICE(USB_VID_LEADTEK, USB_PID_WINFAST_DTV2000DS)},
1300/* 30 */{USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_UB383_T)}, 1300/* 30 */{USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_UB383_T)},
1301 {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_395U_4)}, 1301 {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_395U_4)},
1302 {USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A815M)},
1302 {0}, 1303 {0},
1303}; 1304};
1304MODULE_DEVICE_TABLE(usb, af9015_usb_table); 1305MODULE_DEVICE_TABLE(usb, af9015_usb_table);
@@ -1353,8 +1354,10 @@ static struct dvb_usb_device_properties af9015_properties[] = {
1353 1354
1354 .identify_state = af9015_identify_state, 1355 .identify_state = af9015_identify_state,
1355 1356
1356 .rc_query = af9015_rc_query, 1357 .rc.legacy = {
1357 .rc_interval = 150, 1358 .rc_query = af9015_rc_query,
1359 .rc_interval = 150,
1360 },
1358 1361
1359 .i2c_algo = &af9015_i2c_algo, 1362 .i2c_algo = &af9015_i2c_algo,
1360 1363
@@ -1460,8 +1463,10 @@ static struct dvb_usb_device_properties af9015_properties[] = {
1460 1463
1461 .identify_state = af9015_identify_state, 1464 .identify_state = af9015_identify_state,
1462 1465
1463 .rc_query = af9015_rc_query, 1466 .rc.legacy = {
1464 .rc_interval = 150, 1467 .rc_query = af9015_rc_query,
1468 .rc_interval = 150,
1469 },
1465 1470
1466 .i2c_algo = &af9015_i2c_algo, 1471 .i2c_algo = &af9015_i2c_algo,
1467 1472
@@ -1567,12 +1572,14 @@ static struct dvb_usb_device_properties af9015_properties[] = {
1567 1572
1568 .identify_state = af9015_identify_state, 1573 .identify_state = af9015_identify_state,
1569 1574
1570 .rc_query = af9015_rc_query, 1575 .rc.legacy = {
1571 .rc_interval = 150, 1576 .rc_query = af9015_rc_query,
1577 .rc_interval = 150,
1578 },
1572 1579
1573 .i2c_algo = &af9015_i2c_algo, 1580 .i2c_algo = &af9015_i2c_algo,
1574 1581
1575 .num_device_descs = 8, /* max 9 */ 1582 .num_device_descs = 9, /* max 9 */
1576 .devices = { 1583 .devices = {
1577 { 1584 {
1578 .name = "AverMedia AVerTV Volar GPS 805 (A805)", 1585 .name = "AverMedia AVerTV Volar GPS 805 (A805)",
@@ -1617,6 +1624,11 @@ static struct dvb_usb_device_properties af9015_properties[] = {
1617 .cold_ids = {&af9015_usb_table[30], NULL}, 1624 .cold_ids = {&af9015_usb_table[30], NULL},
1618 .warm_ids = {NULL}, 1625 .warm_ids = {NULL},
1619 }, 1626 },
1627 {
1628 .name = "AverMedia AVerTV Volar M (A815Mac)",
1629 .cold_ids = {&af9015_usb_table[32], NULL},
1630 .warm_ids = {NULL},
1631 },
1620 } 1632 }
1621 }, 1633 },
1622}; 1634};
diff --git a/drivers/media/dvb/dvb-usb/af9015.h b/drivers/media/dvb/dvb-usb/af9015.h
index 63b2a4907b7e..c8e9349742ee 100644
--- a/drivers/media/dvb/dvb-usb/af9015.h
+++ b/drivers/media/dvb/dvb-usb/af9015.h
@@ -123,7 +123,7 @@ enum af9015_remote {
123 123
124/* LeadTek - Y04G0051 */ 124/* LeadTek - Y04G0051 */
125/* Leadtek WinFast DTV Dongle Gold */ 125/* Leadtek WinFast DTV Dongle Gold */
126static struct dvb_usb_rc_key ir_codes_af9015_table_leadtek[] = { 126static struct ir_scancode ir_codes_af9015_table_leadtek[] = {
127 { 0x001e, KEY_1 }, 127 { 0x001e, KEY_1 },
128 { 0x001f, KEY_2 }, 128 { 0x001f, KEY_2 },
129 { 0x0020, KEY_3 }, 129 { 0x0020, KEY_3 },
@@ -227,7 +227,7 @@ static u8 af9015_ir_table_leadtek[] = {
227}; 227};
228 228
229/* TwinHan AzureWave AD-TU700(704J) */ 229/* TwinHan AzureWave AD-TU700(704J) */
230static struct dvb_usb_rc_key ir_codes_af9015_table_twinhan[] = { 230static struct ir_scancode ir_codes_af9015_table_twinhan[] = {
231 { 0x053f, KEY_POWER }, 231 { 0x053f, KEY_POWER },
232 { 0x0019, KEY_FAVORITES }, /* Favorite List */ 232 { 0x0019, KEY_FAVORITES }, /* Favorite List */
233 { 0x0004, KEY_TEXT }, /* Teletext */ 233 { 0x0004, KEY_TEXT }, /* Teletext */
@@ -338,7 +338,7 @@ static u8 af9015_ir_table_twinhan[] = {
338}; 338};
339 339
340/* A-Link DTU(m) */ 340/* A-Link DTU(m) */
341static struct dvb_usb_rc_key ir_codes_af9015_table_a_link[] = { 341static struct ir_scancode ir_codes_af9015_table_a_link[] = {
342 { 0x001e, KEY_1 }, 342 { 0x001e, KEY_1 },
343 { 0x001f, KEY_2 }, 343 { 0x001f, KEY_2 },
344 { 0x0020, KEY_3 }, 344 { 0x0020, KEY_3 },
@@ -381,7 +381,7 @@ static u8 af9015_ir_table_a_link[] = {
381}; 381};
382 382
383/* MSI DIGIVOX mini II V3.0 */ 383/* MSI DIGIVOX mini II V3.0 */
384static struct dvb_usb_rc_key ir_codes_af9015_table_msi[] = { 384static struct ir_scancode ir_codes_af9015_table_msi[] = {
385 { 0x001e, KEY_1 }, 385 { 0x001e, KEY_1 },
386 { 0x001f, KEY_2 }, 386 { 0x001f, KEY_2 },
387 { 0x0020, KEY_3 }, 387 { 0x0020, KEY_3 },
@@ -424,7 +424,7 @@ static u8 af9015_ir_table_msi[] = {
424}; 424};
425 425
426/* MYGICTV U718 */ 426/* MYGICTV U718 */
427static struct dvb_usb_rc_key ir_codes_af9015_table_mygictv[] = { 427static struct ir_scancode ir_codes_af9015_table_mygictv[] = {
428 { 0x003d, KEY_SWITCHVIDEOMODE }, 428 { 0x003d, KEY_SWITCHVIDEOMODE },
429 /* TV / AV */ 429 /* TV / AV */
430 { 0x0545, KEY_POWER }, 430 { 0x0545, KEY_POWER },
@@ -550,7 +550,7 @@ static u8 af9015_ir_table_kworld[] = {
550}; 550};
551 551
552/* AverMedia Volar X */ 552/* AverMedia Volar X */
553static struct dvb_usb_rc_key ir_codes_af9015_table_avermedia[] = { 553static struct ir_scancode ir_codes_af9015_table_avermedia[] = {
554 { 0x053d, KEY_PROG1 }, /* SOURCE */ 554 { 0x053d, KEY_PROG1 }, /* SOURCE */
555 { 0x0512, KEY_POWER }, /* POWER */ 555 { 0x0512, KEY_POWER }, /* POWER */
556 { 0x051e, KEY_1 }, /* 1 */ 556 { 0x051e, KEY_1 }, /* 1 */
@@ -656,7 +656,7 @@ static u8 af9015_ir_table_avermedia_ks[] = {
656}; 656};
657 657
658/* Digittrade DVB-T USB Stick */ 658/* Digittrade DVB-T USB Stick */
659static struct dvb_usb_rc_key ir_codes_af9015_table_digittrade[] = { 659static struct ir_scancode ir_codes_af9015_table_digittrade[] = {
660 { 0x010f, KEY_LAST }, /* RETURN */ 660 { 0x010f, KEY_LAST }, /* RETURN */
661 { 0x0517, KEY_TEXT }, /* TELETEXT */ 661 { 0x0517, KEY_TEXT }, /* TELETEXT */
662 { 0x0108, KEY_EPG }, /* EPG */ 662 { 0x0108, KEY_EPG }, /* EPG */
@@ -719,7 +719,7 @@ static u8 af9015_ir_table_digittrade[] = {
719}; 719};
720 720
721/* TREKSTOR DVB-T USB Stick */ 721/* TREKSTOR DVB-T USB Stick */
722static struct dvb_usb_rc_key ir_codes_af9015_table_trekstor[] = { 722static struct ir_scancode ir_codes_af9015_table_trekstor[] = {
723 { 0x0704, KEY_AGAIN }, /* Home */ 723 { 0x0704, KEY_AGAIN }, /* Home */
724 { 0x0705, KEY_MUTE }, /* Mute */ 724 { 0x0705, KEY_MUTE }, /* Mute */
725 { 0x0706, KEY_UP }, /* Up */ 725 { 0x0706, KEY_UP }, /* Up */
@@ -782,7 +782,7 @@ static u8 af9015_ir_table_trekstor[] = {
782}; 782};
783 783
784/* MSI DIGIVOX mini III */ 784/* MSI DIGIVOX mini III */
785static struct dvb_usb_rc_key ir_codes_af9015_table_msi_digivox_iii[] = { 785static struct ir_scancode ir_codes_af9015_table_msi_digivox_iii[] = {
786 { 0x0713, KEY_POWER }, /* [red power button] */ 786 { 0x0713, KEY_POWER }, /* [red power button] */
787 { 0x073b, KEY_VIDEO }, /* Source */ 787 { 0x073b, KEY_VIDEO }, /* Source */
788 { 0x073e, KEY_ZOOM }, /* Zoom */ 788 { 0x073e, KEY_ZOOM }, /* Zoom */
diff --git a/drivers/media/dvb/dvb-usb/anysee.c b/drivers/media/dvb/dvb-usb/anysee.c
index faca1ad88a67..4685259e1614 100644
--- a/drivers/media/dvb/dvb-usb/anysee.c
+++ b/drivers/media/dvb/dvb-usb/anysee.c
@@ -377,7 +377,7 @@ static int anysee_tuner_attach(struct dvb_usb_adapter *adap)
377static int anysee_rc_query(struct dvb_usb_device *d, u32 *event, int *state) 377static int anysee_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
378{ 378{
379 u8 buf[] = {CMD_GET_IR_CODE}; 379 u8 buf[] = {CMD_GET_IR_CODE};
380 struct dvb_usb_rc_key *keymap = d->props.rc_key_map; 380 struct ir_scancode *keymap = d->props.rc.legacy.rc_key_map;
381 u8 ircode[2]; 381 u8 ircode[2];
382 int i, ret; 382 int i, ret;
383 383
@@ -388,10 +388,10 @@ static int anysee_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
388 *event = 0; 388 *event = 0;
389 *state = REMOTE_NO_KEY_PRESSED; 389 *state = REMOTE_NO_KEY_PRESSED;
390 390
391 for (i = 0; i < d->props.rc_key_map_size; i++) { 391 for (i = 0; i < d->props.rc.legacy.rc_key_map_size; i++) {
392 if (rc5_custom(&keymap[i]) == ircode[0] && 392 if (rc5_custom(&keymap[i]) == ircode[0] &&
393 rc5_data(&keymap[i]) == ircode[1]) { 393 rc5_data(&keymap[i]) == ircode[1]) {
394 *event = keymap[i].event; 394 *event = keymap[i].keycode;
395 *state = REMOTE_KEY_PRESSED; 395 *state = REMOTE_KEY_PRESSED;
396 return 0; 396 return 0;
397 } 397 }
@@ -399,7 +399,7 @@ static int anysee_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
399 return 0; 399 return 0;
400} 400}
401 401
402static struct dvb_usb_rc_key ir_codes_anysee_table[] = { 402static struct ir_scancode ir_codes_anysee_table[] = {
403 { 0x0100, KEY_0 }, 403 { 0x0100, KEY_0 },
404 { 0x0101, KEY_1 }, 404 { 0x0101, KEY_1 },
405 { 0x0102, KEY_2 }, 405 { 0x0102, KEY_2 },
@@ -463,6 +463,11 @@ static int anysee_probe(struct usb_interface *intf,
463 if (intf->num_altsetting < 1) 463 if (intf->num_altsetting < 1)
464 return -ENODEV; 464 return -ENODEV;
465 465
466 /*
467 * Anysee is always warm (its USB-bridge, Cypress FX2, uploads
468 * firmware from eeprom). If dvb_usb_device_init() succeeds that
469 * means d is a valid pointer.
470 */
466 ret = dvb_usb_device_init(intf, &anysee_properties, THIS_MODULE, &d, 471 ret = dvb_usb_device_init(intf, &anysee_properties, THIS_MODULE, &d,
467 adapter_nr); 472 adapter_nr);
468 if (ret) 473 if (ret)
@@ -479,10 +484,7 @@ static int anysee_probe(struct usb_interface *intf,
479 if (ret) 484 if (ret)
480 return ret; 485 return ret;
481 486
482 if (d) 487 return anysee_init(d);
483 ret = anysee_init(d);
484
485 return ret;
486} 488}
487 489
488static struct usb_device_id anysee_table[] = { 490static struct usb_device_id anysee_table[] = {
@@ -518,10 +520,12 @@ static struct dvb_usb_device_properties anysee_properties = {
518 } 520 }
519 }, 521 },
520 522
521 .rc_key_map = ir_codes_anysee_table, 523 .rc.legacy = {
522 .rc_key_map_size = ARRAY_SIZE(ir_codes_anysee_table), 524 .rc_key_map = ir_codes_anysee_table,
523 .rc_query = anysee_rc_query, 525 .rc_key_map_size = ARRAY_SIZE(ir_codes_anysee_table),
524 .rc_interval = 200, /* windows driver uses 500ms */ 526 .rc_query = anysee_rc_query,
527 .rc_interval = 200, /* windows driver uses 500ms */
528 },
525 529
526 .i2c_algo = &anysee_i2c_algo, 530 .i2c_algo = &anysee_i2c_algo,
527 531
diff --git a/drivers/media/dvb/dvb-usb/az6027.c b/drivers/media/dvb/dvb-usb/az6027.c
index 6681ac1c56e3..62c58288469f 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 dvb_usb_rc_key ir_codes_az6027_table[] = { 389static struct ir_scancode ir_codes_az6027_table[] = {
390 { 0x01, KEY_1 }, 390 { 0x01, KEY_1 },
391 { 0x02, KEY_2 }, 391 { 0x02, KEY_2 },
392}; 392};
@@ -1125,10 +1125,13 @@ static struct dvb_usb_device_properties az6027_properties = {
1125 .power_ctrl = az6027_power_ctrl, 1125 .power_ctrl = az6027_power_ctrl,
1126 .read_mac_address = az6027_read_mac_addr, 1126 .read_mac_address = az6027_read_mac_addr,
1127 */ 1127 */
1128 .rc_key_map = ir_codes_az6027_table, 1128 .rc.legacy = {
1129 .rc_key_map_size = ARRAY_SIZE(ir_codes_az6027_table), 1129 .rc_key_map = ir_codes_az6027_table,
1130 .rc_interval = 400, 1130 .rc_key_map_size = ARRAY_SIZE(ir_codes_az6027_table),
1131 .rc_query = az6027_rc_query, 1131 .rc_interval = 400,
1132 .rc_query = az6027_rc_query,
1133 },
1134
1132 .i2c_algo = &az6027_i2c_algo, 1135 .i2c_algo = &az6027_i2c_algo,
1133 1136
1134 .num_device_descs = 5, 1137 .num_device_descs = 5,
diff --git a/drivers/media/dvb/dvb-usb/cinergyT2-core.c b/drivers/media/dvb/dvb-usb/cinergyT2-core.c
index 5a9c14bdc980..4f5aa83fc1fc 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 dvb_usb_rc_key ir_codes_cinergyt2_table[] = { 87static struct ir_scancode ir_codes_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 },
@@ -217,10 +217,12 @@ static struct dvb_usb_device_properties cinergyt2_properties = {
217 217
218 .power_ctrl = cinergyt2_power_ctrl, 218 .power_ctrl = cinergyt2_power_ctrl,
219 219
220 .rc_interval = 50, 220 .rc.legacy = {
221 .rc_key_map = ir_codes_cinergyt2_table, 221 .rc_interval = 50,
222 .rc_key_map_size = ARRAY_SIZE(ir_codes_cinergyt2_table), 222 .rc_key_map = ir_codes_cinergyt2_table,
223 .rc_query = cinergyt2_rc_query, 223 .rc_key_map_size = ARRAY_SIZE(ir_codes_cinergyt2_table),
224 .rc_query = cinergyt2_rc_query,
225 },
224 226
225 .generic_bulk_ctrl_endpoint = 1, 227 .generic_bulk_ctrl_endpoint = 1,
226 228
diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
index 11e9e85dac86..cd9f362c37b2 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 dvb_usb_rc_key *keymap = d->props.rc_key_map; 388 struct ir_scancode *keymap = d->props.rc.legacy.rc_key_map;
389 u8 ircode[4]; 389 u8 ircode[4];
390 int i; 390 int i;
391 391
@@ -394,10 +394,10 @@ 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_key_map_size; i++) { 397 for (i = 0; i < d->props.rc.legacy.rc_key_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].event; 400 *event = keymap[i].keycode;
401 *state = REMOTE_KEY_PRESSED; 401 *state = REMOTE_KEY_PRESSED;
402 402
403 return 0; 403 return 0;
@@ -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 dvb_usb_rc_key *keymap = d->props.rc_key_map; 413 struct ir_scancode *keymap = d->props.rc.legacy.rc_key_map;
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,10 +422,10 @@ 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_key_map_size; i++) { 425 for (i = 0; i < d->props.rc.legacy.rc_key_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].event; 428 *event = keymap[i].keycode;
429 *state = REMOTE_KEY_PRESSED; 429 *state = REMOTE_KEY_PRESSED;
430 430
431 return 0; 431 return 0;
@@ -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 dvb_usb_rc_key *keymap = d->props.rc_key_map; 441 struct ir_scancode *keymap = d->props.rc.legacy.rc_key_map;
442 u8 ircode[2]; 442 u8 ircode[2];
443 int i; 443 int i;
444 444
@@ -448,10 +448,10 @@ 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_key_map_size; i++) { 451 for (i = 0; i < d->props.rc.legacy.rc_key_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].event; 454 *event = keymap[i].keycode;
455 *state = REMOTE_KEY_PRESSED; 455 *state = REMOTE_KEY_PRESSED;
456 456
457 return 0; 457 return 0;
@@ -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 dvb_usb_rc_key ir_codes_dvico_mce_table[] = { 464static struct ir_scancode ir_codes_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 dvb_usb_rc_key ir_codes_dvico_mce_table[] = {
509 { 0xfe4e, KEY_POWER }, 509 { 0xfe4e, KEY_POWER },
510}; 510};
511 511
512static struct dvb_usb_rc_key ir_codes_dvico_portable_table[] = { 512static struct ir_scancode ir_codes_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 dvb_usb_rc_key ir_codes_dvico_portable_table[] = {
548 { 0xfc00, KEY_UNKNOWN }, /* HD */ 548 { 0xfc00, KEY_UNKNOWN }, /* HD */
549}; 549};
550 550
551static struct dvb_usb_rc_key ir_codes_d680_dmb_table[] = { 551static struct ir_scancode ir_codes_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_key_map != NULL && i < 5; i++) { 926 for (i = 0; adap->dev->props.rc.legacy.rc_key_map != 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_key_map = NULL; 934 adap->dev->props.rc.legacy.rc_key_map = 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 }
@@ -1451,10 +1451,12 @@ static struct dvb_usb_device_properties cxusb_bluebird_lgh064f_properties = {
1451 1451
1452 .i2c_algo = &cxusb_i2c_algo, 1452 .i2c_algo = &cxusb_i2c_algo,
1453 1453
1454 .rc_interval = 100, 1454 .rc.legacy = {
1455 .rc_key_map = ir_codes_dvico_portable_table, 1455 .rc_interval = 100,
1456 .rc_key_map_size = ARRAY_SIZE(ir_codes_dvico_portable_table), 1456 .rc_key_map = ir_codes_dvico_portable_table,
1457 .rc_query = cxusb_rc_query, 1457 .rc_key_map_size = ARRAY_SIZE(ir_codes_dvico_portable_table),
1458 .rc_query = cxusb_rc_query,
1459 },
1458 1460
1459 .generic_bulk_ctrl_endpoint = 0x01, 1461 .generic_bulk_ctrl_endpoint = 0x01,
1460 1462
@@ -1502,10 +1504,12 @@ static struct dvb_usb_device_properties cxusb_bluebird_dee1601_properties = {
1502 1504
1503 .i2c_algo = &cxusb_i2c_algo, 1505 .i2c_algo = &cxusb_i2c_algo,
1504 1506
1505 .rc_interval = 150, 1507 .rc.legacy = {
1506 .rc_key_map = ir_codes_dvico_mce_table, 1508 .rc_interval = 150,
1507 .rc_key_map_size = ARRAY_SIZE(ir_codes_dvico_mce_table), 1509 .rc_key_map = ir_codes_dvico_mce_table,
1508 .rc_query = cxusb_rc_query, 1510 .rc_key_map_size = ARRAY_SIZE(ir_codes_dvico_mce_table),
1511 .rc_query = cxusb_rc_query,
1512 },
1509 1513
1510 .generic_bulk_ctrl_endpoint = 0x01, 1514 .generic_bulk_ctrl_endpoint = 0x01,
1511 1515
@@ -1561,10 +1565,12 @@ static struct dvb_usb_device_properties cxusb_bluebird_lgz201_properties = {
1561 1565
1562 .i2c_algo = &cxusb_i2c_algo, 1566 .i2c_algo = &cxusb_i2c_algo,
1563 1567
1564 .rc_interval = 100, 1568 .rc.legacy = {
1565 .rc_key_map = ir_codes_dvico_portable_table, 1569 .rc_interval = 100,
1566 .rc_key_map_size = ARRAY_SIZE(ir_codes_dvico_portable_table), 1570 .rc_key_map = ir_codes_dvico_portable_table,
1567 .rc_query = cxusb_rc_query, 1571 .rc_key_map_size = ARRAY_SIZE(ir_codes_dvico_portable_table),
1572 .rc_query = cxusb_rc_query,
1573 },
1568 1574
1569 .generic_bulk_ctrl_endpoint = 0x01, 1575 .generic_bulk_ctrl_endpoint = 0x01,
1570 .num_device_descs = 1, 1576 .num_device_descs = 1,
@@ -1611,10 +1617,12 @@ static struct dvb_usb_device_properties cxusb_bluebird_dtt7579_properties = {
1611 1617
1612 .i2c_algo = &cxusb_i2c_algo, 1618 .i2c_algo = &cxusb_i2c_algo,
1613 1619
1614 .rc_interval = 100, 1620 .rc.legacy = {
1615 .rc_key_map = ir_codes_dvico_portable_table, 1621 .rc_interval = 100,
1616 .rc_key_map_size = ARRAY_SIZE(ir_codes_dvico_portable_table), 1622 .rc_key_map = ir_codes_dvico_portable_table,
1617 .rc_query = cxusb_rc_query, 1623 .rc_key_map_size = ARRAY_SIZE(ir_codes_dvico_portable_table),
1624 .rc_query = cxusb_rc_query,
1625 },
1618 1626
1619 .generic_bulk_ctrl_endpoint = 0x01, 1627 .generic_bulk_ctrl_endpoint = 0x01,
1620 1628
@@ -1660,10 +1668,12 @@ static struct dvb_usb_device_properties cxusb_bluebird_dualdig4_properties = {
1660 1668
1661 .generic_bulk_ctrl_endpoint = 0x01, 1669 .generic_bulk_ctrl_endpoint = 0x01,
1662 1670
1663 .rc_interval = 100, 1671 .rc.legacy = {
1664 .rc_key_map = ir_codes_dvico_mce_table, 1672 .rc_interval = 100,
1665 .rc_key_map_size = ARRAY_SIZE(ir_codes_dvico_mce_table), 1673 .rc_key_map = ir_codes_dvico_mce_table,
1666 .rc_query = cxusb_bluebird2_rc_query, 1674 .rc_key_map_size = ARRAY_SIZE(ir_codes_dvico_mce_table),
1675 .rc_query = cxusb_bluebird2_rc_query,
1676 },
1667 1677
1668 .num_device_descs = 1, 1678 .num_device_descs = 1,
1669 .devices = { 1679 .devices = {
@@ -1708,10 +1718,12 @@ static struct dvb_usb_device_properties cxusb_bluebird_nano2_properties = {
1708 1718
1709 .generic_bulk_ctrl_endpoint = 0x01, 1719 .generic_bulk_ctrl_endpoint = 0x01,
1710 1720
1711 .rc_interval = 100, 1721 .rc.legacy = {
1712 .rc_key_map = ir_codes_dvico_portable_table, 1722 .rc_interval = 100,
1713 .rc_key_map_size = ARRAY_SIZE(ir_codes_dvico_portable_table), 1723 .rc_key_map = ir_codes_dvico_portable_table,
1714 .rc_query = cxusb_bluebird2_rc_query, 1724 .rc_key_map_size = ARRAY_SIZE(ir_codes_dvico_portable_table),
1725 .rc_query = cxusb_bluebird2_rc_query,
1726 },
1715 1727
1716 .num_device_descs = 1, 1728 .num_device_descs = 1,
1717 .devices = { 1729 .devices = {
@@ -1758,10 +1770,12 @@ static struct dvb_usb_device_properties cxusb_bluebird_nano2_needsfirmware_prope
1758 1770
1759 .generic_bulk_ctrl_endpoint = 0x01, 1771 .generic_bulk_ctrl_endpoint = 0x01,
1760 1772
1761 .rc_interval = 100, 1773 .rc.legacy = {
1762 .rc_key_map = ir_codes_dvico_portable_table, 1774 .rc_interval = 100,
1763 .rc_key_map_size = ARRAY_SIZE(ir_codes_dvico_portable_table), 1775 .rc_key_map = ir_codes_dvico_portable_table,
1764 .rc_query = cxusb_rc_query, 1776 .rc_key_map_size = ARRAY_SIZE(ir_codes_dvico_portable_table),
1777 .rc_query = cxusb_rc_query,
1778 },
1765 1779
1766 .num_device_descs = 1, 1780 .num_device_descs = 1,
1767 .devices = { 1781 .devices = {
@@ -1849,10 +1863,12 @@ struct dvb_usb_device_properties cxusb_bluebird_dualdig4_rev2_properties = {
1849 1863
1850 .generic_bulk_ctrl_endpoint = 0x01, 1864 .generic_bulk_ctrl_endpoint = 0x01,
1851 1865
1852 .rc_interval = 100, 1866 .rc.legacy = {
1853 .rc_key_map = ir_codes_dvico_mce_table, 1867 .rc_interval = 100,
1854 .rc_key_map_size = ARRAY_SIZE(ir_codes_dvico_mce_table), 1868 .rc_key_map = ir_codes_dvico_mce_table,
1855 .rc_query = cxusb_rc_query, 1869 .rc_key_map_size = ARRAY_SIZE(ir_codes_dvico_mce_table),
1870 .rc_query = cxusb_rc_query,
1871 },
1856 1872
1857 .num_device_descs = 1, 1873 .num_device_descs = 1,
1858 .devices = { 1874 .devices = {
@@ -1897,10 +1913,12 @@ static struct dvb_usb_device_properties cxusb_d680_dmb_properties = {
1897 1913
1898 .generic_bulk_ctrl_endpoint = 0x01, 1914 .generic_bulk_ctrl_endpoint = 0x01,
1899 1915
1900 .rc_interval = 100, 1916 .rc.legacy = {
1901 .rc_key_map = ir_codes_d680_dmb_table, 1917 .rc_interval = 100,
1902 .rc_key_map_size = ARRAY_SIZE(ir_codes_d680_dmb_table), 1918 .rc_key_map = ir_codes_d680_dmb_table,
1903 .rc_query = cxusb_d680_dmb_rc_query, 1919 .rc_key_map_size = ARRAY_SIZE(ir_codes_d680_dmb_table),
1920 .rc_query = cxusb_d680_dmb_rc_query,
1921 },
1904 1922
1905 .num_device_descs = 1, 1923 .num_device_descs = 1,
1906 .devices = { 1924 .devices = {
@@ -1946,10 +1964,12 @@ static struct dvb_usb_device_properties cxusb_mygica_d689_properties = {
1946 1964
1947 .generic_bulk_ctrl_endpoint = 0x01, 1965 .generic_bulk_ctrl_endpoint = 0x01,
1948 1966
1949 .rc_interval = 100, 1967 .rc.legacy = {
1950 .rc_key_map = ir_codes_d680_dmb_table, 1968 .rc_interval = 100,
1951 .rc_key_map_size = ARRAY_SIZE(ir_codes_d680_dmb_table), 1969 .rc_key_map = ir_codes_d680_dmb_table,
1952 .rc_query = cxusb_d680_dmb_rc_query, 1970 .rc_key_map_size = ARRAY_SIZE(ir_codes_d680_dmb_table),
1971 .rc_query = cxusb_d680_dmb_rc_query,
1972 },
1953 1973
1954 .num_device_descs = 1, 1974 .num_device_descs = 1,
1955 .devices = { 1975 .devices = {
diff --git a/drivers/media/dvb/dvb-usb/dib0700.h b/drivers/media/dvb/dvb-usb/dib0700.h
index 83fc24a6c31a..c2c9d236ec7e 100644
--- a/drivers/media/dvb/dvb-usb/dib0700.h
+++ b/drivers/media/dvb/dvb-usb/dib0700.h
@@ -60,6 +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);
63 64
64extern int dib0700_device_count; 65extern int dib0700_device_count;
65extern 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 4f961d2d1817..fe818348b8a3 100644
--- a/drivers/media/dvb/dvb-usb/dib0700_core.c
+++ b/drivers/media/dvb/dvb-usb/dib0700_core.c
@@ -13,10 +13,6 @@ int dvb_usb_dib0700_debug;
13module_param_named(debug,dvb_usb_dib0700_debug, int, 0644); 13module_param_named(debug,dvb_usb_dib0700_debug, int, 0644);
14MODULE_PARM_DESC(debug, "set debugging level (1=info,2=fw,4=fwdata,8=data (or-able))." DVB_USB_DEBUG_STATUS); 14MODULE_PARM_DESC(debug, "set debugging level (1=info,2=fw,4=fwdata,8=data (or-able))." DVB_USB_DEBUG_STATUS);
15 15
16int dvb_usb_dib0700_ir_proto = 1;
17module_param(dvb_usb_dib0700_ir_proto, int, 0644);
18MODULE_PARM_DESC(dvb_usb_dib0700_ir_proto, "set ir protocol (0=NEC, 1=RC5 (default), 2=RC6).");
19
20static int nb_packet_buffer_size = 21; 16static int nb_packet_buffer_size = 21;
21module_param(nb_packet_buffer_size, int, 0644); 17module_param(nb_packet_buffer_size, int, 0644);
22MODULE_PARM_DESC(nb_packet_buffer_size, 18MODULE_PARM_DESC(nb_packet_buffer_size,
@@ -53,7 +49,7 @@ static int dib0700_ctrl_wr(struct dvb_usb_device *d, u8 *tx, u8 txlen)
53 int status; 49 int status;
54 50
55 deb_data(">>> "); 51 deb_data(">>> ");
56 debug_dump(tx,txlen,deb_data); 52 debug_dump(tx, txlen, deb_data);
57 53
58 status = usb_control_msg(d->udev, usb_sndctrlpipe(d->udev,0), 54 status = usb_control_msg(d->udev, usb_sndctrlpipe(d->udev,0),
59 tx[0], USB_TYPE_VENDOR | USB_DIR_OUT, 0, 0, tx, txlen, 55 tx[0], USB_TYPE_VENDOR | USB_DIR_OUT, 0, 0, tx, txlen,
@@ -98,7 +94,7 @@ int dib0700_ctrl_rd(struct dvb_usb_device *d, u8 *tx, u8 txlen, u8 *rx, u8 rxlen
98 deb_info("ep 0 read error (status = %d)\n",status); 94 deb_info("ep 0 read error (status = %d)\n",status);
99 95
100 deb_data("<<< "); 96 deb_data("<<< ");
101 debug_dump(rx,rxlen,deb_data); 97 debug_dump(rx, rxlen, deb_data);
102 98
103 return status; /* length in case of success */ 99 return status; /* length in case of success */
104} 100}
@@ -106,28 +102,29 @@ int dib0700_ctrl_rd(struct dvb_usb_device *d, u8 *tx, u8 txlen, u8 *rx, u8 rxlen
106int dib0700_set_gpio(struct dvb_usb_device *d, enum dib07x0_gpios gpio, u8 gpio_dir, u8 gpio_val) 102int dib0700_set_gpio(struct dvb_usb_device *d, enum dib07x0_gpios gpio, u8 gpio_dir, u8 gpio_val)
107{ 103{
108 u8 buf[3] = { REQUEST_SET_GPIO, gpio, ((gpio_dir & 0x01) << 7) | ((gpio_val & 0x01) << 6) }; 104 u8 buf[3] = { REQUEST_SET_GPIO, gpio, ((gpio_dir & 0x01) << 7) | ((gpio_val & 0x01) << 6) };
109 return dib0700_ctrl_wr(d,buf,3); 105 return dib0700_ctrl_wr(d, buf, sizeof(buf));
110} 106}
111 107
112static int dib0700_set_usb_xfer_len(struct dvb_usb_device *d, u16 nb_ts_packets) 108static int dib0700_set_usb_xfer_len(struct dvb_usb_device *d, u16 nb_ts_packets)
113{ 109{
114 struct dib0700_state *st = d->priv; 110 struct dib0700_state *st = d->priv;
115 u8 b[3]; 111 u8 b[3];
116 int ret; 112 int ret;
117 113
118 if (st->fw_version >= 0x10201) { 114 if (st->fw_version >= 0x10201) {
119 b[0] = REQUEST_SET_USB_XFER_LEN; 115 b[0] = REQUEST_SET_USB_XFER_LEN;
120 b[1] = (nb_ts_packets >> 8)&0xff; 116 b[1] = (nb_ts_packets >> 8) & 0xff;
121 b[2] = nb_ts_packets & 0xff; 117 b[2] = nb_ts_packets & 0xff;
122 118
123 deb_info("set the USB xfer len to %i Ts packet\n", nb_ts_packets); 119 deb_info("set the USB xfer len to %i Ts packet\n", nb_ts_packets);
124 120
125 ret = dib0700_ctrl_wr(d, b, 3); 121 ret = dib0700_ctrl_wr(d, b, sizeof(b));
126 } else { 122 } else {
127 deb_info("this firmware does not allow to change the USB xfer len\n"); 123 deb_info("this firmware does not allow to change the USB xfer len\n");
128 ret = -EIO; 124 ret = -EIO;
129 } 125 }
130 return ret; 126
127 return ret;
131} 128}
132 129
133/* 130/*
@@ -178,7 +175,8 @@ static int dib0700_i2c_xfer_new(struct i2c_adapter *adap, struct i2c_msg *msg,
178 value = ((en_start << 7) | (en_stop << 6) | 175 value = ((en_start << 7) | (en_stop << 6) |
179 (msg[i].len & 0x3F)) << 8 | i2c_dest; 176 (msg[i].len & 0x3F)) << 8 | i2c_dest;
180 /* I2C ctrl + FE bus; */ 177 /* I2C ctrl + FE bus; */
181 index = ((gen_mode<<6)&0xC0) | ((bus_mode<<4)&0x30); 178 index = ((gen_mode << 6) & 0xC0) |
179 ((bus_mode << 4) & 0x30);
182 180
183 result = usb_control_msg(d->udev, 181 result = usb_control_msg(d->udev,
184 usb_rcvctrlpipe(d->udev, 0), 182 usb_rcvctrlpipe(d->udev, 0),
@@ -198,11 +196,12 @@ static int dib0700_i2c_xfer_new(struct i2c_adapter *adap, struct i2c_msg *msg,
198 } else { 196 } else {
199 /* Write request */ 197 /* Write request */
200 buf[0] = REQUEST_NEW_I2C_WRITE; 198 buf[0] = REQUEST_NEW_I2C_WRITE;
201 buf[1] = (msg[i].addr << 1); 199 buf[1] = msg[i].addr << 1;
202 buf[2] = (en_start << 7) | (en_stop << 6) | 200 buf[2] = (en_start << 7) | (en_stop << 6) |
203 (msg[i].len & 0x3F); 201 (msg[i].len & 0x3F);
204 /* I2C ctrl + FE bus; */ 202 /* I2C ctrl + FE bus; */
205 buf[3] = ((gen_mode<<6)&0xC0) | ((bus_mode<<4)&0x30); 203 buf[3] = ((gen_mode << 6) & 0xC0) |
204 ((bus_mode << 4) & 0x30);
206 /* The Actual i2c payload */ 205 /* The Actual i2c payload */
207 memcpy(&buf[4], msg[i].buf, msg[i].len); 206 memcpy(&buf[4], msg[i].buf, msg[i].len);
208 207
@@ -240,7 +239,7 @@ static int dib0700_i2c_xfer_legacy(struct i2c_adapter *adap,
240 239
241 for (i = 0; i < num; i++) { 240 for (i = 0; i < num; i++) {
242 /* fill in the address */ 241 /* fill in the address */
243 buf[1] = (msg[i].addr << 1); 242 buf[1] = msg[i].addr << 1;
244 /* fill the buffer */ 243 /* fill the buffer */
245 memcpy(&buf[2], msg[i].buf, msg[i].len); 244 memcpy(&buf[2], msg[i].buf, msg[i].len);
246 245
@@ -368,7 +367,8 @@ int dib0700_download_firmware(struct usb_device *udev, const struct firmware *fw
368 u8 buf[260]; 367 u8 buf[260];
369 368
370 while ((ret = dvb_usb_get_hexline(fw, &hx, &pos)) > 0) { 369 while ((ret = dvb_usb_get_hexline(fw, &hx, &pos)) > 0) {
371 deb_fwdata("writing to address 0x%08x (buffer: 0x%02x %02x)\n",hx.addr, hx.len, hx.chk); 370 deb_fwdata("writing to address 0x%08x (buffer: 0x%02x %02x)\n",
371 hx.addr, hx.len, hx.chk);
372 372
373 buf[0] = hx.len; 373 buf[0] = hx.len;
374 buf[1] = (hx.addr >> 8) & 0xff; 374 buf[1] = (hx.addr >> 8) & 0xff;
@@ -408,16 +408,16 @@ int dib0700_download_firmware(struct usb_device *udev, const struct firmware *fw
408 REQUEST_GET_VERSION, 408 REQUEST_GET_VERSION,
409 USB_TYPE_VENDOR | USB_DIR_IN, 0, 0, 409 USB_TYPE_VENDOR | USB_DIR_IN, 0, 0,
410 b, sizeof(b), USB_CTRL_GET_TIMEOUT); 410 b, sizeof(b), USB_CTRL_GET_TIMEOUT);
411 fw_version = (b[8] << 24) | (b[9] << 16) | (b[10] << 8) | b[11]; 411 fw_version = (b[8] << 24) | (b[9] << 16) | (b[10] << 8) | b[11];
412 412
413 /* set the buffer size - DVB-USB is allocating URB buffers 413 /* set the buffer size - DVB-USB is allocating URB buffers
414 * only after the firwmare download was successful */ 414 * only after the firwmare download was successful */
415 for (i = 0; i < dib0700_device_count; i++) { 415 for (i = 0; i < dib0700_device_count; i++) {
416 for (adap_num = 0; adap_num < dib0700_devices[i].num_adapters; 416 for (adap_num = 0; adap_num < dib0700_devices[i].num_adapters;
417 adap_num++) { 417 adap_num++) {
418 if (fw_version >= 0x10201) 418 if (fw_version >= 0x10201) {
419 dib0700_devices[i].adapter[adap_num].stream.u.bulk.buffersize = 188*nb_packet_buffer_size; 419 dib0700_devices[i].adapter[adap_num].stream.u.bulk.buffersize = 188*nb_packet_buffer_size;
420 else { 420 } else {
421 /* for fw version older than 1.20.1, 421 /* for fw version older than 1.20.1,
422 * the buffersize has to be n times 512 */ 422 * the buffersize has to be n times 512 */
423 dib0700_devices[i].adapter[adap_num].stream.u.bulk.buffersize = ((188*nb_packet_buffer_size+188/2)/512)*512; 423 dib0700_devices[i].adapter[adap_num].stream.u.bulk.buffersize = ((188*nb_packet_buffer_size+188/2)/512)*512;
@@ -453,7 +453,7 @@ int dib0700_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
453 if (st->disable_streaming_master_mode == 1) 453 if (st->disable_streaming_master_mode == 1)
454 b[2] = 0x00; 454 b[2] = 0x00;
455 else 455 else
456 b[2] = (0x01 << 4); /* Master mode */ 456 b[2] = 0x01 << 4; /* Master mode */
457 457
458 b[3] = 0x00; 458 b[3] = 0x00;
459 459
@@ -466,11 +466,44 @@ int dib0700_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
466 466
467 b[2] |= st->channel_state; 467 b[2] |= st->channel_state;
468 468
469 deb_info("data for streaming: %x %x\n",b[1],b[2]); 469 deb_info("data for streaming: %x %x\n", b[1], b[2]);
470 470
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)
475{
476 struct dvb_usb_device *d = priv;
477 struct dib0700_state *st = d->priv;
478 u8 rc_setup[3] = { REQUEST_SET_RC, 0, 0 };
479 int new_proto, ret;
480
481 /* Set the IR mode */
482 if (ir_type == IR_TYPE_RC5)
483 new_proto = 1;
484 else if (ir_type == IR_TYPE_NEC)
485 new_proto = 0;
486 else if (ir_type == IR_TYPE_RC6) {
487 if (st->fw_version < 0x10200)
488 return -EINVAL;
489
490 new_proto = 2;
491 } else
492 return -EINVAL;
493
494 rc_setup[1] = new_proto;
495
496 ret = dib0700_ctrl_wr(d, rc_setup, sizeof(rc_setup));
497 if (ret < 0) {
498 err("ir protocol setup failed");
499 return ret;
500 }
501
502 d->props.rc.core.protocol = ir_type;
503
504 return ret;
505}
506
474/* Number of keypresses to ignore before start repeating */ 507/* Number of keypresses to ignore before start repeating */
475#define RC_REPEAT_DELAY_V1_20 10 508#define RC_REPEAT_DELAY_V1_20 10
476 509
@@ -478,7 +511,13 @@ int dib0700_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
478struct dib0700_rc_response { 511struct dib0700_rc_response {
479 u8 report_id; 512 u8 report_id;
480 u8 data_state; 513 u8 data_state;
481 u16 system; 514 union {
515 u16 system16;
516 struct {
517 u8 system;
518 u8 not_system;
519 };
520 };
482 u8 data; 521 u8 data;
483 u8 not_data; 522 u8 not_data;
484}; 523};
@@ -487,14 +526,10 @@ struct dib0700_rc_response {
487static void dib0700_rc_urb_completion(struct urb *purb) 526static void dib0700_rc_urb_completion(struct urb *purb)
488{ 527{
489 struct dvb_usb_device *d = purb->context; 528 struct dvb_usb_device *d = purb->context;
490 struct dvb_usb_rc_key *keymap;
491 struct dib0700_state *st; 529 struct dib0700_state *st;
492 struct dib0700_rc_response poll_reply; 530 struct dib0700_rc_response *poll_reply;
493 u8 *buf; 531 u32 uninitialized_var(keycode);
494 int found = 0; 532 u8 toggle;
495 u32 event;
496 int state;
497 int i;
498 533
499 deb_info("%s()\n", __func__); 534 deb_info("%s()\n", __func__);
500 if (d == NULL) 535 if (d == NULL)
@@ -506,9 +541,8 @@ static void dib0700_rc_urb_completion(struct urb *purb)
506 return; 541 return;
507 } 542 }
508 543
509 keymap = d->props.rc_key_map;
510 st = d->priv; 544 st = d->priv;
511 buf = (u8 *)purb->transfer_buffer; 545 poll_reply = purb->transfer_buffer;
512 546
513 if (purb->status < 0) { 547 if (purb->status < 0) {
514 deb_info("discontinuing polling\n"); 548 deb_info("discontinuing polling\n");
@@ -521,104 +555,52 @@ static void dib0700_rc_urb_completion(struct urb *purb)
521 goto resubmit; 555 goto resubmit;
522 } 556 }
523 557
524 /* Set initial results in case we exit the function early */ 558 deb_data("IR ID = %02X state = %02X System = %02X %02X Cmd = %02X %02X (len %d)\n",
525 event = 0; 559 poll_reply->report_id, poll_reply->data_state,
526 state = REMOTE_NO_KEY_PRESSED; 560 poll_reply->system, poll_reply->not_system,
527 561 poll_reply->data, poll_reply->not_data,
528 deb_data("IR raw %02X %02X %02X %02X %02X %02X (len %d)\n", buf[0], 562 purb->actual_length);
529 buf[1], buf[2], buf[3], buf[4], buf[5], purb->actual_length);
530 563
531 switch (dvb_usb_dib0700_ir_proto) { 564 switch (d->props.rc.core.protocol) {
532 case 0: 565 case IR_TYPE_NEC:
533 /* NEC Protocol */ 566 toggle = 0;
534 poll_reply.report_id = 0;
535 poll_reply.data_state = 1;
536 poll_reply.system = buf[2];
537 poll_reply.data = buf[4];
538 poll_reply.not_data = buf[5];
539 567
540 /* NEC protocol sends repeat code as 0 0 0 FF */ 568 /* NEC protocol sends repeat code as 0 0 0 FF */
541 if ((poll_reply.system == 0x00) && (poll_reply.data == 0x00) 569 if ((poll_reply->system == 0x00) && (poll_reply->data == 0x00)
542 && (poll_reply.not_data == 0xff)) { 570 && (poll_reply->not_data == 0xff)) {
543 poll_reply.data_state = 2; 571 poll_reply->data_state = 2;
544 break; 572 break;
545 } 573 }
574
575 if ((poll_reply->system ^ poll_reply->not_system) != 0xff) {
576 deb_data("NEC extended protocol\n");
577 /* NEC extended code - 24 bits */
578 keycode = poll_reply->system16 << 8 | poll_reply->data;
579 } else {
580 deb_data("NEC normal protocol\n");
581 /* normal NEC code - 16 bits */
582 keycode = poll_reply->system << 8 | poll_reply->data;
583 }
584
546 break; 585 break;
547 default: 586 default:
587 deb_data("RC5 protocol\n");
548 /* RC5 Protocol */ 588 /* RC5 Protocol */
549 poll_reply.report_id = buf[0]; 589 toggle = poll_reply->report_id;
550 poll_reply.data_state = buf[1]; 590 keycode = poll_reply->system16 << 8 | poll_reply->data;
551 poll_reply.system = (buf[2] << 8) | buf[3]; 591
552 poll_reply.data = buf[4];
553 poll_reply.not_data = buf[5];
554 break; 592 break;
555 } 593 }
556 594
557 if ((poll_reply.data + poll_reply.not_data) != 0xff) { 595 if ((poll_reply->data + poll_reply->not_data) != 0xff) {
558 /* Key failed integrity check */ 596 /* Key failed integrity check */
559 err("key failed integrity check: %04x %02x %02x", 597 err("key failed integrity check: %04x %02x %02x",
560 poll_reply.system, 598 poll_reply->system,
561 poll_reply.data, poll_reply.not_data); 599 poll_reply->data, poll_reply->not_data);
562 goto resubmit;
563 }
564
565 deb_data("rid=%02x ds=%02x sm=%04x d=%02x nd=%02x\n",
566 poll_reply.report_id, poll_reply.data_state,
567 poll_reply.system, poll_reply.data, poll_reply.not_data);
568
569 /* Find the key in the map */
570 for (i = 0; i < d->props.rc_key_map_size; i++) {
571 if (rc5_custom(&keymap[i]) == (poll_reply.system & 0xff) &&
572 rc5_data(&keymap[i]) == poll_reply.data) {
573 event = keymap[i].event;
574 found = 1;
575 break;
576 }
577 }
578
579 if (found == 0) {
580 err("Unknown remote controller key: %04x %02x %02x",
581 poll_reply.system, poll_reply.data, poll_reply.not_data);
582 d->last_event = 0;
583 goto resubmit; 600 goto resubmit;
584 } 601 }
585 602
586 if (poll_reply.data_state == 1) { 603 ir_keydown(d->rc_input_dev, keycode, toggle);
587 /* New key hit */
588 st->rc_counter = 0;
589 event = keymap[i].event;
590 state = REMOTE_KEY_PRESSED;
591 d->last_event = keymap[i].event;
592 } else if (poll_reply.data_state == 2) {
593 /* Key repeated */
594 st->rc_counter++;
595
596 /* prevents unwanted double hits */
597 if (st->rc_counter > RC_REPEAT_DELAY_V1_20) {
598 event = d->last_event;
599 state = REMOTE_KEY_PRESSED;
600 st->rc_counter = RC_REPEAT_DELAY_V1_20;
601 }
602 } else {
603 err("Unknown data state [%d]", poll_reply.data_state);
604 }
605
606 switch (state) {
607 case REMOTE_NO_KEY_PRESSED:
608 break;
609 case REMOTE_KEY_PRESSED:
610 deb_info("key pressed\n");
611 d->last_event = event;
612 case REMOTE_KEY_REPEAT:
613 deb_info("key repeated\n");
614 input_event(d->rc_input_dev, EV_KEY, event, 1);
615 input_sync(d->rc_input_dev);
616 input_event(d->rc_input_dev, EV_KEY, d->last_event, 0);
617 input_sync(d->rc_input_dev);
618 break;
619 default:
620 break;
621 }
622 604
623resubmit: 605resubmit:
624 /* Clean the buffer before we requeue */ 606 /* Clean the buffer before we requeue */
@@ -631,21 +613,10 @@ resubmit:
631int dib0700_rc_setup(struct dvb_usb_device *d) 613int dib0700_rc_setup(struct dvb_usb_device *d)
632{ 614{
633 struct dib0700_state *st = d->priv; 615 struct dib0700_state *st = d->priv;
634 u8 rc_setup[3] = {REQUEST_SET_RC, dvb_usb_dib0700_ir_proto, 0};
635 struct urb *purb; 616 struct urb *purb;
636 int ret; 617 int ret;
637 int i;
638
639 if (d->props.rc_key_map == NULL)
640 return 0;
641
642 /* Set the IR mode */
643 i = dib0700_ctrl_wr(d, rc_setup, 3);
644 if (i<0) {
645 err("ir protocol setup failed");
646 return -1;
647 }
648 618
619 /* Poll-based. Don't initialize bulk mode */
649 if (st->fw_version < 0x10200) 620 if (st->fw_version < 0x10200)
650 return 0; 621 return 0;
651 622
@@ -653,14 +624,14 @@ int dib0700_rc_setup(struct dvb_usb_device *d)
653 purb = usb_alloc_urb(0, GFP_KERNEL); 624 purb = usb_alloc_urb(0, GFP_KERNEL);
654 if (purb == NULL) { 625 if (purb == NULL) {
655 err("rc usb alloc urb failed\n"); 626 err("rc usb alloc urb failed\n");
656 return -1; 627 return -ENOMEM;
657 } 628 }
658 629
659 purb->transfer_buffer = kzalloc(RC_MSG_SIZE_V1_20, GFP_KERNEL); 630 purb->transfer_buffer = kzalloc(RC_MSG_SIZE_V1_20, GFP_KERNEL);
660 if (purb->transfer_buffer == NULL) { 631 if (purb->transfer_buffer == NULL) {
661 err("rc kzalloc failed\n"); 632 err("rc kzalloc failed\n");
662 usb_free_urb(purb); 633 usb_free_urb(purb);
663 return -1; 634 return -ENOMEM;
664 } 635 }
665 636
666 purb->status = -EINPROGRESS; 637 purb->status = -EINPROGRESS;
@@ -669,12 +640,10 @@ int dib0700_rc_setup(struct dvb_usb_device *d)
669 dib0700_rc_urb_completion, d); 640 dib0700_rc_urb_completion, d);
670 641
671 ret = usb_submit_urb(purb, GFP_ATOMIC); 642 ret = usb_submit_urb(purb, GFP_ATOMIC);
672 if (ret != 0) { 643 if (ret)
673 err("rc submit urb failed\n"); 644 err("rc submit urb failed\n");
674 return -1;
675 }
676 645
677 return 0; 646 return ret;
678} 647}
679 648
680static int dib0700_probe(struct usb_interface *intf, 649static int dib0700_probe(struct usb_interface *intf,
@@ -698,6 +667,15 @@ static int dib0700_probe(struct usb_interface *intf,
698 st->fw_version = fw_version; 667 st->fw_version = fw_version;
699 st->nb_packet_buffer_size = (u32)nb_packet_buffer_size; 668 st->nb_packet_buffer_size = (u32)nb_packet_buffer_size;
700 669
670 /* Disable polling mode on newer firmwares */
671 if (st->fw_version >= 0x10200)
672 dev->props.rc.core.bulk_mode = true;
673 else
674 dev->props.rc.core.bulk_mode = false;
675
676 /* Need a higher delay, to avoid wrong repeat */
677 dev->rc_input_dev->rep[REP_DELAY] = 500;
678
701 dib0700_rc_setup(dev); 679 dib0700_rc_setup(dev);
702 680
703 return 0; 681 return 0;
diff --git a/drivers/media/dvb/dvb-usb/dib0700_devices.c b/drivers/media/dvb/dvb-usb/dib0700_devices.c
index 800800a9649e..f634d2e784b2 100644
--- a/drivers/media/dvb/dvb-usb/dib0700_devices.c
+++ b/drivers/media/dvb/dvb-usb/dib0700_devices.c
@@ -473,16 +473,19 @@ static u8 rc_request[] = { REQUEST_POLL_RC, 0 };
473/* Number of keypresses to ignore before start repeating */ 473/* Number of keypresses to ignore before start repeating */
474#define RC_REPEAT_DELAY 6 474#define RC_REPEAT_DELAY 6
475 475
476static int dib0700_rc_query(struct dvb_usb_device *d, u32 *event, int *state) 476/*
477 * This function is used only when firmware is < 1.20 version. Newer
478 * firmwares use bulk mode, with functions implemented at dib0700_core,
479 * at dib0700_rc_urb_completion()
480 */
481static int dib0700_rc_query_old_firmware(struct dvb_usb_device *d)
477{ 482{
478 u8 key[4]; 483 u8 key[4];
484 u32 keycode;
485 u8 toggle;
479 int i; 486 int i;
480 struct dvb_usb_rc_key *keymap = d->props.rc_key_map;
481 struct dib0700_state *st = d->priv; 487 struct dib0700_state *st = d->priv;
482 488
483 *event = 0;
484 *state = REMOTE_NO_KEY_PRESSED;
485
486 if (st->fw_version >= 0x10200) { 489 if (st->fw_version >= 0x10200) {
487 /* For 1.20 firmware , We need to keep the RC polling 490 /* For 1.20 firmware , We need to keep the RC polling
488 callback so we can reuse the input device setup in 491 callback so we can reuse the input device setup in
@@ -491,348 +494,45 @@ static int dib0700_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
491 return 0; 494 return 0;
492 } 495 }
493 496
494 i=dib0700_ctrl_rd(d,rc_request,2,key,4); 497 i = dib0700_ctrl_rd(d, rc_request, 2, key, 4);
495 if (i<=0) { 498 if (i <= 0) {
496 err("RC Query Failed"); 499 err("RC Query Failed");
497 return -1; 500 return -1;
498 } 501 }
499 502
500 /* losing half of KEY_0 events from Philipps rc5 remotes.. */ 503 /* losing half of KEY_0 events from Philipps rc5 remotes.. */
501 if (key[0]==0 && key[1]==0 && key[2]==0 && key[3]==0) return 0; 504 if (key[0] == 0 && key[1] == 0 && key[2] == 0 && key[3] == 0)
505 return 0;
502 506
503 /* info("%d: %2X %2X %2X %2X",dvb_usb_dib0700_ir_proto,(int)key[3-2],(int)key[3-3],(int)key[3-1],(int)key[3]); */ 507 /* info("%d: %2X %2X %2X %2X",dvb_usb_dib0700_ir_proto,(int)key[3-2],(int)key[3-3],(int)key[3-1],(int)key[3]); */
504 508
505 dib0700_rc_setup(d); /* reset ir sensor data to prevent false events */ 509 dib0700_rc_setup(d); /* reset ir sensor data to prevent false events */
506 510
507 switch (dvb_usb_dib0700_ir_proto) { 511 d->last_event = 0;
508 case 0: { 512 switch (d->props.rc.core.protocol) {
513 case IR_TYPE_NEC:
509 /* NEC protocol sends repeat code as 0 0 0 FF */ 514 /* NEC protocol sends repeat code as 0 0 0 FF */
510 if ((key[3-2] == 0x00) && (key[3-3] == 0x00) && 515 if ((key[3-2] == 0x00) && (key[3-3] == 0x00) &&
511 (key[3] == 0xFF)) { 516 (key[3] == 0xff))
512 st->rc_counter++; 517 keycode = d->last_event;
513 if (st->rc_counter > RC_REPEAT_DELAY) { 518 else {
514 *event = d->last_event; 519 keycode = key[3-2] << 8 | key[3-3];
515 *state = REMOTE_KEY_PRESSED; 520 d->last_event = keycode;
516 st->rc_counter = RC_REPEAT_DELAY;
517 }
518 return 0;
519 }
520 for (i=0;i<d->props.rc_key_map_size; i++) {
521 if (rc5_custom(&keymap[i]) == key[3-2] &&
522 rc5_data(&keymap[i]) == key[3-3]) {
523 st->rc_counter = 0;
524 *event = keymap[i].event;
525 *state = REMOTE_KEY_PRESSED;
526 d->last_event = keymap[i].event;
527 return 0;
528 }
529 } 521 }
522
523 ir_keydown(d->rc_input_dev, keycode, 0);
530 break; 524 break;
531 } 525 default:
532 default: {
533 /* RC-5 protocol changes toggle bit on new keypress */ 526 /* RC-5 protocol changes toggle bit on new keypress */
534 for (i = 0; i < d->props.rc_key_map_size; i++) { 527 keycode = key[3-2] << 8 | key[3-3];
535 if (rc5_custom(&keymap[i]) == key[3-2] && 528 toggle = key[3-1];
536 rc5_data(&keymap[i]) == key[3-3]) { 529 ir_keydown(d->rc_input_dev, keycode, toggle);
537 if (d->last_event == keymap[i].event && 530
538 key[3-1] == st->rc_toggle) {
539 st->rc_counter++;
540 /* prevents unwanted double hits */
541 if (st->rc_counter > RC_REPEAT_DELAY) {
542 *event = d->last_event;
543 *state = REMOTE_KEY_PRESSED;
544 st->rc_counter = RC_REPEAT_DELAY;
545 }
546
547 return 0;
548 }
549 st->rc_counter = 0;
550 *event = keymap[i].event;
551 *state = REMOTE_KEY_PRESSED;
552 st->rc_toggle = key[3-1];
553 d->last_event = keymap[i].event;
554 return 0;
555 }
556 }
557 break; 531 break;
558 } 532 }
559 }
560 err("Unknown remote controller key: %2X %2X %2X %2X", (int) key[3-2], (int) key[3-3], (int) key[3-1], (int) key[3]);
561 d->last_event = 0;
562 return 0; 533 return 0;
563} 534}
564 535
565static struct dvb_usb_rc_key ir_codes_dib0700_table[] = {
566 /* Key codes for the tiny Pinnacle remote*/
567 { 0x0700, KEY_MUTE },
568 { 0x0701, KEY_MENU }, /* Pinnacle logo */
569 { 0x0739, KEY_POWER },
570 { 0x0703, KEY_VOLUMEUP },
571 { 0x0709, KEY_VOLUMEDOWN },
572 { 0x0706, KEY_CHANNELUP },
573 { 0x070c, KEY_CHANNELDOWN },
574 { 0x070f, KEY_1 },
575 { 0x0715, KEY_2 },
576 { 0x0710, KEY_3 },
577 { 0x0718, KEY_4 },
578 { 0x071b, KEY_5 },
579 { 0x071e, KEY_6 },
580 { 0x0711, KEY_7 },
581 { 0x0721, KEY_8 },
582 { 0x0712, KEY_9 },
583 { 0x0727, KEY_0 },
584 { 0x0724, KEY_SCREEN }, /* 'Square' key */
585 { 0x072a, KEY_TEXT }, /* 'T' key */
586 { 0x072d, KEY_REWIND },
587 { 0x0730, KEY_PLAY },
588 { 0x0733, KEY_FASTFORWARD },
589 { 0x0736, KEY_RECORD },
590 { 0x073c, KEY_STOP },
591 { 0x073f, KEY_CANCEL }, /* '?' key */
592 /* Key codes for the Terratec Cinergy DT XS Diversity, similar to cinergyT2.c */
593 { 0xeb01, KEY_POWER },
594 { 0xeb02, KEY_1 },
595 { 0xeb03, KEY_2 },
596 { 0xeb04, KEY_3 },
597 { 0xeb05, KEY_4 },
598 { 0xeb06, KEY_5 },
599 { 0xeb07, KEY_6 },
600 { 0xeb08, KEY_7 },
601 { 0xeb09, KEY_8 },
602 { 0xeb0a, KEY_9 },
603 { 0xeb0b, KEY_VIDEO },
604 { 0xeb0c, KEY_0 },
605 { 0xeb0d, KEY_REFRESH },
606 { 0xeb0f, KEY_EPG },
607 { 0xeb10, KEY_UP },
608 { 0xeb11, KEY_LEFT },
609 { 0xeb12, KEY_OK },
610 { 0xeb13, KEY_RIGHT },
611 { 0xeb14, KEY_DOWN },
612 { 0xeb16, KEY_INFO },
613 { 0xeb17, KEY_RED },
614 { 0xeb18, KEY_GREEN },
615 { 0xeb19, KEY_YELLOW },
616 { 0xeb1a, KEY_BLUE },
617 { 0xeb1b, KEY_CHANNELUP },
618 { 0xeb1c, KEY_VOLUMEUP },
619 { 0xeb1d, KEY_MUTE },
620 { 0xeb1e, KEY_VOLUMEDOWN },
621 { 0xeb1f, KEY_CHANNELDOWN },
622 { 0xeb40, KEY_PAUSE },
623 { 0xeb41, KEY_HOME },
624 { 0xeb42, KEY_MENU }, /* DVD Menu */
625 { 0xeb43, KEY_SUBTITLE },
626 { 0xeb44, KEY_TEXT }, /* Teletext */
627 { 0xeb45, KEY_DELETE },
628 { 0xeb46, KEY_TV },
629 { 0xeb47, KEY_DVD },
630 { 0xeb48, KEY_STOP },
631 { 0xeb49, KEY_VIDEO },
632 { 0xeb4a, KEY_AUDIO }, /* Music */
633 { 0xeb4b, KEY_SCREEN }, /* Pic */
634 { 0xeb4c, KEY_PLAY },
635 { 0xeb4d, KEY_BACK },
636 { 0xeb4e, KEY_REWIND },
637 { 0xeb4f, KEY_FASTFORWARD },
638 { 0xeb54, KEY_PREVIOUS },
639 { 0xeb58, KEY_RECORD },
640 { 0xeb5c, KEY_NEXT },
641
642 /* Key codes for the Haupauge WinTV Nova-TD, copied from nova-t-usb2.c (Nova-T USB2) */
643 { 0x1e00, KEY_0 },
644 { 0x1e01, KEY_1 },
645 { 0x1e02, KEY_2 },
646 { 0x1e03, KEY_3 },
647 { 0x1e04, KEY_4 },
648 { 0x1e05, KEY_5 },
649 { 0x1e06, KEY_6 },
650 { 0x1e07, KEY_7 },
651 { 0x1e08, KEY_8 },
652 { 0x1e09, KEY_9 },
653 { 0x1e0a, KEY_KPASTERISK },
654 { 0x1e0b, KEY_RED },
655 { 0x1e0c, KEY_RADIO },
656 { 0x1e0d, KEY_MENU },
657 { 0x1e0e, KEY_GRAVE }, /* # */
658 { 0x1e0f, KEY_MUTE },
659 { 0x1e10, KEY_VOLUMEUP },
660 { 0x1e11, KEY_VOLUMEDOWN },
661 { 0x1e12, KEY_CHANNEL },
662 { 0x1e14, KEY_UP },
663 { 0x1e15, KEY_DOWN },
664 { 0x1e16, KEY_LEFT },
665 { 0x1e17, KEY_RIGHT },
666 { 0x1e18, KEY_VIDEO },
667 { 0x1e19, KEY_AUDIO },
668 { 0x1e1a, KEY_MEDIA },
669 { 0x1e1b, KEY_EPG },
670 { 0x1e1c, KEY_TV },
671 { 0x1e1e, KEY_NEXT },
672 { 0x1e1f, KEY_BACK },
673 { 0x1e20, KEY_CHANNELUP },
674 { 0x1e21, KEY_CHANNELDOWN },
675 { 0x1e24, KEY_LAST }, /* Skip backwards */
676 { 0x1e25, KEY_OK },
677 { 0x1e29, KEY_BLUE},
678 { 0x1e2e, KEY_GREEN },
679 { 0x1e30, KEY_PAUSE },
680 { 0x1e32, KEY_REWIND },
681 { 0x1e34, KEY_FASTFORWARD },
682 { 0x1e35, KEY_PLAY },
683 { 0x1e36, KEY_STOP },
684 { 0x1e37, KEY_RECORD },
685 { 0x1e38, KEY_YELLOW },
686 { 0x1e3b, KEY_GOTO },
687 { 0x1e3d, KEY_POWER },
688
689 /* Key codes for the Leadtek Winfast DTV Dongle */
690 { 0x0042, KEY_POWER },
691 { 0x077c, KEY_TUNER },
692 { 0x0f4e, KEY_PRINT }, /* PREVIEW */
693 { 0x0840, KEY_SCREEN }, /* full screen toggle*/
694 { 0x0f71, KEY_DOT }, /* frequency */
695 { 0x0743, KEY_0 },
696 { 0x0c41, KEY_1 },
697 { 0x0443, KEY_2 },
698 { 0x0b7f, KEY_3 },
699 { 0x0e41, KEY_4 },
700 { 0x0643, KEY_5 },
701 { 0x097f, KEY_6 },
702 { 0x0d7e, KEY_7 },
703 { 0x057c, KEY_8 },
704 { 0x0a40, KEY_9 },
705 { 0x0e4e, KEY_CLEAR },
706 { 0x047c, KEY_CHANNEL }, /* show channel number */
707 { 0x0f41, KEY_LAST }, /* recall */
708 { 0x0342, KEY_MUTE },
709 { 0x064c, KEY_RESERVED }, /* PIP button*/
710 { 0x0172, KEY_SHUFFLE }, /* SNAPSHOT */
711 { 0x0c4e, KEY_PLAYPAUSE }, /* TIMESHIFT */
712 { 0x0b70, KEY_RECORD },
713 { 0x037d, KEY_VOLUMEUP },
714 { 0x017d, KEY_VOLUMEDOWN },
715 { 0x0242, KEY_CHANNELUP },
716 { 0x007d, KEY_CHANNELDOWN },
717
718 /* Key codes for Nova-TD "credit card" remote control. */
719 { 0x1d00, KEY_0 },
720 { 0x1d01, KEY_1 },
721 { 0x1d02, KEY_2 },
722 { 0x1d03, KEY_3 },
723 { 0x1d04, KEY_4 },
724 { 0x1d05, KEY_5 },
725 { 0x1d06, KEY_6 },
726 { 0x1d07, KEY_7 },
727 { 0x1d08, KEY_8 },
728 { 0x1d09, KEY_9 },
729 { 0x1d0a, KEY_TEXT },
730 { 0x1d0d, KEY_MENU },
731 { 0x1d0f, KEY_MUTE },
732 { 0x1d10, KEY_VOLUMEUP },
733 { 0x1d11, KEY_VOLUMEDOWN },
734 { 0x1d12, KEY_CHANNEL },
735 { 0x1d14, KEY_UP },
736 { 0x1d15, KEY_DOWN },
737 { 0x1d16, KEY_LEFT },
738 { 0x1d17, KEY_RIGHT },
739 { 0x1d1c, KEY_TV },
740 { 0x1d1e, KEY_NEXT },
741 { 0x1d1f, KEY_BACK },
742 { 0x1d20, KEY_CHANNELUP },
743 { 0x1d21, KEY_CHANNELDOWN },
744 { 0x1d24, KEY_LAST },
745 { 0x1d25, KEY_OK },
746 { 0x1d30, KEY_PAUSE },
747 { 0x1d32, KEY_REWIND },
748 { 0x1d34, KEY_FASTFORWARD },
749 { 0x1d35, KEY_PLAY },
750 { 0x1d36, KEY_STOP },
751 { 0x1d37, KEY_RECORD },
752 { 0x1d3b, KEY_GOTO },
753 { 0x1d3d, KEY_POWER },
754
755 /* Key codes for the Pixelview SBTVD remote (proto NEC) */
756 { 0x8613, KEY_MUTE },
757 { 0x8612, KEY_POWER },
758 { 0x8601, KEY_1 },
759 { 0x8602, KEY_2 },
760 { 0x8603, KEY_3 },
761 { 0x8604, KEY_4 },
762 { 0x8605, KEY_5 },
763 { 0x8606, KEY_6 },
764 { 0x8607, KEY_7 },
765 { 0x8608, KEY_8 },
766 { 0x8609, KEY_9 },
767 { 0x8600, KEY_0 },
768 { 0x860d, KEY_CHANNELUP },
769 { 0x8619, KEY_CHANNELDOWN },
770 { 0x8610, KEY_VOLUMEUP },
771 { 0x860c, KEY_VOLUMEDOWN },
772
773 { 0x860a, KEY_CAMERA },
774 { 0x860b, KEY_ZOOM },
775 { 0x861b, KEY_BACKSPACE },
776 { 0x8615, KEY_ENTER },
777
778 { 0x861d, KEY_UP },
779 { 0x861e, KEY_DOWN },
780 { 0x860e, KEY_LEFT },
781 { 0x860f, KEY_RIGHT },
782
783 { 0x8618, KEY_RECORD },
784 { 0x861a, KEY_STOP },
785
786 /* Key codes for the EvolutePC TVWay+ remote (proto NEC) */
787 { 0x7a00, KEY_MENU },
788 { 0x7a01, KEY_RECORD },
789 { 0x7a02, KEY_PLAY },
790 { 0x7a03, KEY_STOP },
791 { 0x7a10, KEY_CHANNELUP },
792 { 0x7a11, KEY_CHANNELDOWN },
793 { 0x7a12, KEY_VOLUMEUP },
794 { 0x7a13, KEY_VOLUMEDOWN },
795 { 0x7a40, KEY_POWER },
796 { 0x7a41, KEY_MUTE },
797
798 /* Key codes for the Elgato EyeTV Diversity silver remote,
799 set dvb_usb_dib0700_ir_proto=0 */
800 { 0x4501, KEY_POWER },
801 { 0x4502, KEY_MUTE },
802 { 0x4503, KEY_1 },
803 { 0x4504, KEY_2 },
804 { 0x4505, KEY_3 },
805 { 0x4506, KEY_4 },
806 { 0x4507, KEY_5 },
807 { 0x4508, KEY_6 },
808 { 0x4509, KEY_7 },
809 { 0x450a, KEY_8 },
810 { 0x450b, KEY_9 },
811 { 0x450c, KEY_LAST },
812 { 0x450d, KEY_0 },
813 { 0x450e, KEY_ENTER },
814 { 0x450f, KEY_RED },
815 { 0x4510, KEY_CHANNELUP },
816 { 0x4511, KEY_GREEN },
817 { 0x4512, KEY_VOLUMEDOWN },
818 { 0x4513, KEY_OK },
819 { 0x4514, KEY_VOLUMEUP },
820 { 0x4515, KEY_YELLOW },
821 { 0x4516, KEY_CHANNELDOWN },
822 { 0x4517, KEY_BLUE },
823 { 0x4518, KEY_LEFT }, /* Skip backwards */
824 { 0x4519, KEY_PLAYPAUSE },
825 { 0x451a, KEY_RIGHT }, /* Skip forward */
826 { 0x451b, KEY_REWIND },
827 { 0x451c, KEY_L }, /* Live */
828 { 0x451d, KEY_FASTFORWARD },
829 { 0x451e, KEY_STOP }, /* 'Reveal' for Teletext */
830 { 0x451f, KEY_MENU }, /* KEY_TEXT for Teletext */
831 { 0x4540, KEY_RECORD }, /* Font 'Size' for Teletext */
832 { 0x4541, KEY_SCREEN }, /* Full screen toggle, 'Hold' for Teletext */
833 { 0x4542, KEY_SELECT }, /* Select video input, 'Select' for Teletext */
834};
835
836/* STK7700P: Hauppauge Nova-T Stick, AVerMedia Volar */ 536/* STK7700P: Hauppauge Nova-T Stick, AVerMedia Volar */
837static struct dibx000_agc_config stk7700p_7000m_mt2060_agc_config = { 537static struct dibx000_agc_config stk7700p_7000m_mt2060_agc_config = {
838 BAND_UHF | BAND_VHF, 538 BAND_UHF | BAND_VHF,
@@ -2168,10 +1868,17 @@ struct dvb_usb_device_properties dib0700_devices[] = {
2168 } 1868 }
2169 }, 1869 },
2170 1870
2171 .rc_interval = DEFAULT_RC_INTERVAL, 1871 .rc.core = {
2172 .rc_key_map = ir_codes_dib0700_table, 1872 .rc_interval = DEFAULT_RC_INTERVAL,
2173 .rc_key_map_size = ARRAY_SIZE(ir_codes_dib0700_table), 1873 .rc_codes = RC_MAP_DIB0700_RC5_TABLE,
2174 .rc_query = dib0700_rc_query 1874 .rc_query = dib0700_rc_query_old_firmware,
1875 .rc_props = {
1876 .allowed_protos = IR_TYPE_RC5 |
1877 IR_TYPE_RC6 |
1878 IR_TYPE_NEC,
1879 .change_protocol = dib0700_change_protocol,
1880 },
1881 },
2175 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES, 1882 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
2176 1883
2177 .num_adapters = 2, 1884 .num_adapters = 2,
@@ -2197,10 +1904,17 @@ struct dvb_usb_device_properties dib0700_devices[] = {
2197 }, 1904 },
2198 }, 1905 },
2199 1906
2200 .rc_interval = DEFAULT_RC_INTERVAL, 1907 .rc.core = {
2201 .rc_key_map = ir_codes_dib0700_table, 1908 .rc_interval = DEFAULT_RC_INTERVAL,
2202 .rc_key_map_size = ARRAY_SIZE(ir_codes_dib0700_table), 1909 .rc_codes = RC_MAP_DIB0700_RC5_TABLE,
2203 .rc_query = dib0700_rc_query 1910 .rc_query = dib0700_rc_query_old_firmware,
1911 .rc_props = {
1912 .allowed_protos = IR_TYPE_RC5 |
1913 IR_TYPE_RC6 |
1914 IR_TYPE_NEC,
1915 .change_protocol = dib0700_change_protocol,
1916 },
1917 },
2204 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES, 1918 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
2205 1919
2206 .num_adapters = 2, 1920 .num_adapters = 2,
@@ -2251,11 +1965,17 @@ struct dvb_usb_device_properties dib0700_devices[] = {
2251 1965
2252 }, 1966 },
2253 1967
2254 .rc_interval = DEFAULT_RC_INTERVAL, 1968 .rc.core = {
2255 .rc_key_map = ir_codes_dib0700_table, 1969 .rc_interval = DEFAULT_RC_INTERVAL,
2256 .rc_key_map_size = ARRAY_SIZE(ir_codes_dib0700_table), 1970 .rc_codes = RC_MAP_DIB0700_RC5_TABLE,
2257 .rc_query = dib0700_rc_query 1971 .rc_query = dib0700_rc_query_old_firmware,
2258 1972 .rc_props = {
1973 .allowed_protos = IR_TYPE_RC5 |
1974 IR_TYPE_RC6 |
1975 IR_TYPE_NEC,
1976 .change_protocol = dib0700_change_protocol,
1977 },
1978 },
2259 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES, 1979 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
2260 1980
2261 .num_adapters = 1, 1981 .num_adapters = 1,
@@ -2288,10 +2008,18 @@ struct dvb_usb_device_properties dib0700_devices[] = {
2288 } 2008 }
2289 }, 2009 },
2290 2010
2291 .rc_interval = DEFAULT_RC_INTERVAL, 2011 .rc.core = {
2292 .rc_key_map = ir_codes_dib0700_table, 2012 .rc_interval = DEFAULT_RC_INTERVAL,
2293 .rc_key_map_size = ARRAY_SIZE(ir_codes_dib0700_table), 2013 .rc_codes = RC_MAP_DIB0700_RC5_TABLE,
2294 .rc_query = dib0700_rc_query 2014 .module_name = "dib0700",
2015 .rc_query = dib0700_rc_query_old_firmware,
2016 .rc_props = {
2017 .allowed_protos = IR_TYPE_RC5 |
2018 IR_TYPE_RC6 |
2019 IR_TYPE_NEC,
2020 .change_protocol = dib0700_change_protocol,
2021 },
2022 },
2295 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES, 2023 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
2296 2024
2297 .num_adapters = 1, 2025 .num_adapters = 1,
@@ -2358,11 +2086,18 @@ struct dvb_usb_device_properties dib0700_devices[] = {
2358 }, 2086 },
2359 }, 2087 },
2360 2088
2361 .rc_interval = DEFAULT_RC_INTERVAL, 2089 .rc.core = {
2362 .rc_key_map = ir_codes_dib0700_table, 2090 .rc_interval = DEFAULT_RC_INTERVAL,
2363 .rc_key_map_size = ARRAY_SIZE(ir_codes_dib0700_table), 2091 .rc_codes = RC_MAP_DIB0700_RC5_TABLE,
2364 .rc_query = dib0700_rc_query 2092 .module_name = "dib0700",
2365 2093 .rc_query = dib0700_rc_query_old_firmware,
2094 .rc_props = {
2095 .allowed_protos = IR_TYPE_RC5 |
2096 IR_TYPE_RC6 |
2097 IR_TYPE_NEC,
2098 .change_protocol = dib0700_change_protocol,
2099 },
2100 },
2366 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES, 2101 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
2367 2102
2368 .num_adapters = 1, 2103 .num_adapters = 1,
@@ -2397,11 +2132,18 @@ struct dvb_usb_device_properties dib0700_devices[] = {
2397 }, 2132 },
2398 }, 2133 },
2399 2134
2400 .rc_interval = DEFAULT_RC_INTERVAL, 2135 .rc.core = {
2401 .rc_key_map = ir_codes_dib0700_table, 2136 .rc_interval = DEFAULT_RC_INTERVAL,
2402 .rc_key_map_size = ARRAY_SIZE(ir_codes_dib0700_table), 2137 .rc_codes = RC_MAP_DIB0700_RC5_TABLE,
2403 .rc_query = dib0700_rc_query 2138 .module_name = "dib0700",
2404 2139 .rc_query = dib0700_rc_query_old_firmware,
2140 .rc_props = {
2141 .allowed_protos = IR_TYPE_RC5 |
2142 IR_TYPE_RC6 |
2143 IR_TYPE_NEC,
2144 .change_protocol = dib0700_change_protocol,
2145 },
2146 },
2405 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES, 2147 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
2406 2148
2407 .num_adapters = 2, 2149 .num_adapters = 2,
@@ -2431,7 +2173,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
2431 } 2173 }
2432 }, 2174 },
2433 2175
2434 .num_device_descs = 7, 2176 .num_device_descs = 6,
2435 .devices = { 2177 .devices = {
2436 { "DiBcom STK7070PD reference design", 2178 { "DiBcom STK7070PD reference design",
2437 { &dib0700_usb_id_table[17], NULL }, 2179 { &dib0700_usb_id_table[17], NULL },
@@ -2458,15 +2200,69 @@ struct dvb_usb_device_properties dib0700_devices[] = {
2458 { &dib0700_usb_id_table[44], NULL }, 2200 { &dib0700_usb_id_table[44], NULL },
2459 { NULL }, 2201 { NULL },
2460 }, 2202 },
2203 },
2204
2205 .rc.core = {
2206 .rc_interval = DEFAULT_RC_INTERVAL,
2207 .rc_codes = RC_MAP_DIB0700_RC5_TABLE,
2208 .module_name = "dib0700",
2209 .rc_query = dib0700_rc_query_old_firmware,
2210 .rc_props = {
2211 .allowed_protos = IR_TYPE_RC5 |
2212 IR_TYPE_RC6 |
2213 IR_TYPE_NEC,
2214 .change_protocol = dib0700_change_protocol,
2215 },
2216 },
2217 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
2218
2219 .num_adapters = 2,
2220 .adapter = {
2221 {
2222 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
2223 .pid_filter_count = 32,
2224 .pid_filter = stk70x0p_pid_filter,
2225 .pid_filter_ctrl = stk70x0p_pid_filter_ctrl,
2226 .frontend_attach = stk7070pd_frontend_attach0,
2227 .tuner_attach = dib7070p_tuner_attach,
2228
2229 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
2230
2231 .size_of_priv = sizeof(struct dib0700_adapter_state),
2232 }, {
2233 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
2234 .pid_filter_count = 32,
2235 .pid_filter = stk70x0p_pid_filter,
2236 .pid_filter_ctrl = stk70x0p_pid_filter_ctrl,
2237 .frontend_attach = stk7070pd_frontend_attach1,
2238 .tuner_attach = dib7070p_tuner_attach,
2239
2240 DIB0700_DEFAULT_STREAMING_CONFIG(0x03),
2241
2242 .size_of_priv = sizeof(struct dib0700_adapter_state),
2243 }
2244 },
2245
2246 .num_device_descs = 1,
2247 .devices = {
2461 { "Elgato EyeTV Diversity", 2248 { "Elgato EyeTV Diversity",
2462 { &dib0700_usb_id_table[68], NULL }, 2249 { &dib0700_usb_id_table[68], NULL },
2463 { NULL }, 2250 { NULL },
2464 }, 2251 },
2465 }, 2252 },
2466 .rc_interval = DEFAULT_RC_INTERVAL, 2253
2467 .rc_key_map = ir_codes_dib0700_table, 2254 .rc.core = {
2468 .rc_key_map_size = ARRAY_SIZE(ir_codes_dib0700_table), 2255 .rc_interval = DEFAULT_RC_INTERVAL,
2469 .rc_query = dib0700_rc_query 2256 .rc_codes = RC_MAP_DIB0700_NEC_TABLE,
2257 .module_name = "dib0700",
2258 .rc_query = dib0700_rc_query_old_firmware,
2259 .rc_props = {
2260 .allowed_protos = IR_TYPE_RC5 |
2261 IR_TYPE_RC6 |
2262 IR_TYPE_NEC,
2263 .change_protocol = dib0700_change_protocol,
2264 },
2265 },
2470 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES, 2266 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
2471 2267
2472 .num_adapters = 1, 2268 .num_adapters = 1,
@@ -2525,10 +2321,19 @@ struct dvb_usb_device_properties dib0700_devices[] = {
2525 { NULL }, 2321 { NULL },
2526 }, 2322 },
2527 }, 2323 },
2528 .rc_interval = DEFAULT_RC_INTERVAL, 2324
2529 .rc_key_map = ir_codes_dib0700_table, 2325 .rc.core = {
2530 .rc_key_map_size = ARRAY_SIZE(ir_codes_dib0700_table), 2326 .rc_interval = DEFAULT_RC_INTERVAL,
2531 .rc_query = dib0700_rc_query 2327 .rc_codes = RC_MAP_DIB0700_RC5_TABLE,
2328 .module_name = "dib0700",
2329 .rc_query = dib0700_rc_query_old_firmware,
2330 .rc_props = {
2331 .allowed_protos = IR_TYPE_RC5 |
2332 IR_TYPE_RC6 |
2333 IR_TYPE_NEC,
2334 .change_protocol = dib0700_change_protocol,
2335 },
2336 },
2532 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES, 2337 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
2533 .num_adapters = 1, 2338 .num_adapters = 1,
2534 .adapter = { 2339 .adapter = {
@@ -2554,10 +2359,19 @@ struct dvb_usb_device_properties dib0700_devices[] = {
2554 { NULL }, 2359 { NULL },
2555 }, 2360 },
2556 }, 2361 },
2557 .rc_interval = DEFAULT_RC_INTERVAL, 2362
2558 .rc_key_map = ir_codes_dib0700_table, 2363 .rc.core = {
2559 .rc_key_map_size = ARRAY_SIZE(ir_codes_dib0700_table), 2364 .rc_interval = DEFAULT_RC_INTERVAL,
2560 .rc_query = dib0700_rc_query 2365 .rc_codes = RC_MAP_DIB0700_RC5_TABLE,
2366 .module_name = "dib0700",
2367 .rc_query = dib0700_rc_query_old_firmware,
2368 .rc_props = {
2369 .allowed_protos = IR_TYPE_RC5 |
2370 IR_TYPE_RC6 |
2371 IR_TYPE_NEC,
2372 .change_protocol = dib0700_change_protocol,
2373 },
2374 },
2561 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES, 2375 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
2562 .num_adapters = 1, 2376 .num_adapters = 1,
2563 .adapter = { 2377 .adapter = {
@@ -2615,10 +2429,19 @@ struct dvb_usb_device_properties dib0700_devices[] = {
2615 { NULL }, 2429 { NULL },
2616 }, 2430 },
2617 }, 2431 },
2618 .rc_interval = DEFAULT_RC_INTERVAL, 2432
2619 .rc_key_map = ir_codes_dib0700_table, 2433 .rc.core = {
2620 .rc_key_map_size = ARRAY_SIZE(ir_codes_dib0700_table), 2434 .rc_interval = DEFAULT_RC_INTERVAL,
2621 .rc_query = dib0700_rc_query 2435 .rc_codes = RC_MAP_DIB0700_RC5_TABLE,
2436 .module_name = "dib0700",
2437 .rc_query = dib0700_rc_query_old_firmware,
2438 .rc_props = {
2439 .allowed_protos = IR_TYPE_RC5 |
2440 IR_TYPE_RC6 |
2441 IR_TYPE_NEC,
2442 .change_protocol = dib0700_change_protocol,
2443 },
2444 },
2622 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES, 2445 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
2623 .num_adapters = 1, 2446 .num_adapters = 1,
2624 .adapter = { 2447 .adapter = {
@@ -2653,11 +2476,18 @@ struct dvb_usb_device_properties dib0700_devices[] = {
2653 }, 2476 },
2654 }, 2477 },
2655 2478
2656 .rc_interval = DEFAULT_RC_INTERVAL, 2479 .rc.core = {
2657 .rc_key_map = ir_codes_dib0700_table, 2480 .rc_interval = DEFAULT_RC_INTERVAL,
2658 .rc_key_map_size = ARRAY_SIZE(ir_codes_dib0700_table), 2481 .rc_codes = RC_MAP_DIB0700_NEC_TABLE,
2659 .rc_query = dib0700_rc_query 2482 .module_name = "dib0700",
2660 2483 .rc_query = dib0700_rc_query_old_firmware,
2484 .rc_props = {
2485 .allowed_protos = IR_TYPE_RC5 |
2486 IR_TYPE_RC6 |
2487 IR_TYPE_NEC,
2488 .change_protocol = dib0700_change_protocol,
2489 },
2490 },
2661 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES, 2491 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
2662 .num_adapters = 2, 2492 .num_adapters = 2,
2663 .adapter = { 2493 .adapter = {
@@ -2697,10 +2527,18 @@ struct dvb_usb_device_properties dib0700_devices[] = {
2697 }, 2527 },
2698 }, 2528 },
2699 2529
2700 .rc_interval = DEFAULT_RC_INTERVAL, 2530 .rc.core = {
2701 .rc_key_map = ir_codes_dib0700_table, 2531 .rc_interval = DEFAULT_RC_INTERVAL,
2702 .rc_key_map_size = ARRAY_SIZE(ir_codes_dib0700_table), 2532 .rc_codes = RC_MAP_DIB0700_RC5_TABLE,
2703 .rc_query = dib0700_rc_query 2533 .module_name = "dib0700",
2534 .rc_query = dib0700_rc_query_old_firmware,
2535 .rc_props = {
2536 .allowed_protos = IR_TYPE_RC5 |
2537 IR_TYPE_RC6 |
2538 IR_TYPE_NEC,
2539 .change_protocol = dib0700_change_protocol,
2540 },
2541 },
2704 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES, 2542 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
2705 .num_adapters = 1, 2543 .num_adapters = 1,
2706 .adapter = { 2544 .adapter = {
@@ -2728,10 +2566,18 @@ struct dvb_usb_device_properties dib0700_devices[] = {
2728 }, 2566 },
2729 }, 2567 },
2730 2568
2731 .rc_interval = DEFAULT_RC_INTERVAL, 2569 .rc.core = {
2732 .rc_key_map = ir_codes_dib0700_table, 2570 .rc_interval = DEFAULT_RC_INTERVAL,
2733 .rc_key_map_size = ARRAY_SIZE(ir_codes_dib0700_table), 2571 .rc_codes = RC_MAP_DIB0700_RC5_TABLE,
2734 .rc_query = dib0700_rc_query 2572 .module_name = "dib0700",
2573 .rc_query = dib0700_rc_query_old_firmware,
2574 .rc_props = {
2575 .allowed_protos = IR_TYPE_RC5 |
2576 IR_TYPE_RC6 |
2577 IR_TYPE_NEC,
2578 .change_protocol = dib0700_change_protocol,
2579 },
2580 },
2735 }, 2581 },
2736}; 2582};
2737 2583
diff --git a/drivers/media/dvb/dvb-usb/dibusb-common.c b/drivers/media/dvb/dvb-usb/dibusb-common.c
index bc08bc0b723c..ba991aa21aff 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 dvb_usb_rc_key ir_codes_dibusb_table[] = { 330struct ir_scancode ir_codes_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 },
diff --git a/drivers/media/dvb/dvb-usb/dibusb-mb.c b/drivers/media/dvb/dvb-usb/dibusb-mb.c
index eb2e6f050fbe..8e3c0d2cce16 100644
--- a/drivers/media/dvb/dvb-usb/dibusb-mb.c
+++ b/drivers/media/dvb/dvb-usb/dibusb-mb.c
@@ -211,10 +211,12 @@ static struct dvb_usb_device_properties dibusb1_1_properties = {
211 211
212 .power_ctrl = dibusb_power_ctrl, 212 .power_ctrl = dibusb_power_ctrl,
213 213
214 .rc_interval = DEFAULT_RC_INTERVAL, 214 .rc.legacy = {
215 .rc_key_map = ir_codes_dibusb_table, 215 .rc_interval = DEFAULT_RC_INTERVAL,
216 .rc_key_map_size = 111, /* wow, that is ugly ... I want to load it to the driver dynamically */ 216 .rc_key_map = ir_codes_dibusb_table,
217 .rc_query = dibusb_rc_query, 217 .rc_key_map_size = 111, /* wow, that is ugly ... I want to load it to the driver dynamically */
218 .rc_query = dibusb_rc_query,
219 },
218 220
219 .i2c_algo = &dibusb_i2c_algo, 221 .i2c_algo = &dibusb_i2c_algo,
220 222
@@ -295,10 +297,12 @@ static struct dvb_usb_device_properties dibusb1_1_an2235_properties = {
295 }, 297 },
296 .power_ctrl = dibusb_power_ctrl, 298 .power_ctrl = dibusb_power_ctrl,
297 299
298 .rc_interval = DEFAULT_RC_INTERVAL, 300 .rc.legacy = {
299 .rc_key_map = ir_codes_dibusb_table, 301 .rc_interval = DEFAULT_RC_INTERVAL,
300 .rc_key_map_size = 111, /* wow, that is ugly ... I want to load it to the driver dynamically */ 302 .rc_key_map = ir_codes_dibusb_table,
301 .rc_query = dibusb_rc_query, 303 .rc_key_map_size = 111, /* wow, that is ugly ... I want to load it to the driver dynamically */
304 .rc_query = dibusb_rc_query,
305 },
302 306
303 .i2c_algo = &dibusb_i2c_algo, 307 .i2c_algo = &dibusb_i2c_algo,
304 308
@@ -359,10 +363,12 @@ static struct dvb_usb_device_properties dibusb2_0b_properties = {
359 }, 363 },
360 .power_ctrl = dibusb2_0_power_ctrl, 364 .power_ctrl = dibusb2_0_power_ctrl,
361 365
362 .rc_interval = DEFAULT_RC_INTERVAL, 366 .rc.legacy = {
363 .rc_key_map = ir_codes_dibusb_table, 367 .rc_interval = DEFAULT_RC_INTERVAL,
364 .rc_key_map_size = 111, /* wow, that is ugly ... I want to load it to the driver dynamically */ 368 .rc_key_map = ir_codes_dibusb_table,
365 .rc_query = dibusb_rc_query, 369 .rc_key_map_size = 111, /* wow, that is ugly ... I want to load it to the driver dynamically */
370 .rc_query = dibusb_rc_query,
371 },
366 372
367 .i2c_algo = &dibusb_i2c_algo, 373 .i2c_algo = &dibusb_i2c_algo,
368 374
@@ -416,10 +422,12 @@ static struct dvb_usb_device_properties artec_t1_usb2_properties = {
416 }, 422 },
417 .power_ctrl = dibusb2_0_power_ctrl, 423 .power_ctrl = dibusb2_0_power_ctrl,
418 424
419 .rc_interval = DEFAULT_RC_INTERVAL, 425 .rc.legacy = {
420 .rc_key_map = ir_codes_dibusb_table, 426 .rc_interval = DEFAULT_RC_INTERVAL,
421 .rc_key_map_size = 111, /* wow, that is ugly ... I want to load it to the driver dynamically */ 427 .rc_key_map = ir_codes_dibusb_table,
422 .rc_query = dibusb_rc_query, 428 .rc_key_map_size = 111, /* wow, that is ugly ... I want to load it to the driver dynamically */
429 .rc_query = dibusb_rc_query,
430 },
423 431
424 .i2c_algo = &dibusb_i2c_algo, 432 .i2c_algo = &dibusb_i2c_algo,
425 433
diff --git a/drivers/media/dvb/dvb-usb/dibusb-mc.c b/drivers/media/dvb/dvb-usb/dibusb-mc.c
index 588308eb6638..1cbc41cb4e8f 100644
--- a/drivers/media/dvb/dvb-usb/dibusb-mc.c
+++ b/drivers/media/dvb/dvb-usb/dibusb-mc.c
@@ -81,10 +81,12 @@ static struct dvb_usb_device_properties dibusb_mc_properties = {
81 }, 81 },
82 .power_ctrl = dibusb2_0_power_ctrl, 82 .power_ctrl = dibusb2_0_power_ctrl,
83 83
84 .rc_interval = DEFAULT_RC_INTERVAL, 84 .rc.legacy = {
85 .rc_key_map = ir_codes_dibusb_table, 85 .rc_interval = DEFAULT_RC_INTERVAL,
86 .rc_key_map_size = 111, /* FIXME */ 86 .rc_key_map = ir_codes_dibusb_table,
87 .rc_query = dibusb_rc_query, 87 .rc_key_map_size = 111, /* FIXME */
88 .rc_query = dibusb_rc_query,
89 },
88 90
89 .i2c_algo = &dibusb_i2c_algo, 91 .i2c_algo = &dibusb_i2c_algo,
90 92
diff --git a/drivers/media/dvb/dvb-usb/dibusb.h b/drivers/media/dvb/dvb-usb/dibusb.h
index 3d50ac59088f..61a6bf389472 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 dvb_usb_rc_key ir_codes_dibusb_table[]; 127extern struct ir_scancode ir_codes_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 e826077094fa..13d006bb19db 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 dvb_usb_rc_key ir_codes_digitv_table[] = { 164static struct ir_scancode ir_codes_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_key_map_size; i++) { 240 for (i = 0; i < d->props.rc.legacy.rc_key_map_size; i++) {
241 if (rc5_custom(&d->props.rc_key_map[i]) == key[1] && 241 if (rc5_custom(&d->props.rc.legacy.rc_key_map[i]) == key[1] &&
242 rc5_data(&d->props.rc_key_map[i]) == key[2]) { 242 rc5_data(&d->props.rc.legacy.rc_key_map[i]) == key[2]) {
243 *event = d->props.rc_key_map[i].event; 243 *event = d->props.rc.legacy.rc_key_map[i].keycode;
244 *state = REMOTE_KEY_PRESSED; 244 *state = REMOTE_KEY_PRESSED;
245 return 0; 245 return 0;
246 } 246 }
@@ -310,10 +310,12 @@ static struct dvb_usb_device_properties digitv_properties = {
310 }, 310 },
311 .identify_state = digitv_identify_state, 311 .identify_state = digitv_identify_state,
312 312
313 .rc_interval = 1000, 313 .rc.legacy = {
314 .rc_key_map = ir_codes_digitv_table, 314 .rc_interval = 1000,
315 .rc_key_map_size = ARRAY_SIZE(ir_codes_digitv_table), 315 .rc_key_map = ir_codes_digitv_table,
316 .rc_query = digitv_rc_query, 316 .rc_key_map_size = ARRAY_SIZE(ir_codes_digitv_table),
317 .rc_query = digitv_rc_query,
318 },
317 319
318 .i2c_algo = &digitv_i2c_algo, 320 .i2c_algo = &digitv_i2c_algo,
319 321
diff --git a/drivers/media/dvb/dvb-usb/dtt200u.c b/drivers/media/dvb/dvb-usb/dtt200u.c
index f57e59044d4d..ca495e07f35c 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 dvb_usb_rc_key ir_codes_dtt200u_table[] = { 60static struct ir_scancode ir_codes_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 },
@@ -161,10 +161,12 @@ static struct dvb_usb_device_properties dtt200u_properties = {
161 }, 161 },
162 .power_ctrl = dtt200u_power_ctrl, 162 .power_ctrl = dtt200u_power_ctrl,
163 163
164 .rc_interval = 300, 164 .rc.legacy = {
165 .rc_key_map = ir_codes_dtt200u_table, 165 .rc_interval = 300,
166 .rc_key_map_size = ARRAY_SIZE(ir_codes_dtt200u_table), 166 .rc_key_map = ir_codes_dtt200u_table,
167 .rc_query = dtt200u_rc_query, 167 .rc_key_map_size = ARRAY_SIZE(ir_codes_dtt200u_table),
168 .rc_query = dtt200u_rc_query,
169 },
168 170
169 .generic_bulk_ctrl_endpoint = 0x01, 171 .generic_bulk_ctrl_endpoint = 0x01,
170 172
@@ -206,10 +208,12 @@ static struct dvb_usb_device_properties wt220u_properties = {
206 }, 208 },
207 .power_ctrl = dtt200u_power_ctrl, 209 .power_ctrl = dtt200u_power_ctrl,
208 210
209 .rc_interval = 300, 211 .rc.legacy = {
210 .rc_key_map = ir_codes_dtt200u_table, 212 .rc_interval = 300,
211 .rc_key_map_size = ARRAY_SIZE(ir_codes_dtt200u_table), 213 .rc_key_map = ir_codes_dtt200u_table,
212 .rc_query = dtt200u_rc_query, 214 .rc_key_map_size = ARRAY_SIZE(ir_codes_dtt200u_table),
215 .rc_query = dtt200u_rc_query,
216 },
213 217
214 .generic_bulk_ctrl_endpoint = 0x01, 218 .generic_bulk_ctrl_endpoint = 0x01,
215 219
@@ -251,10 +255,12 @@ static struct dvb_usb_device_properties wt220u_fc_properties = {
251 }, 255 },
252 .power_ctrl = dtt200u_power_ctrl, 256 .power_ctrl = dtt200u_power_ctrl,
253 257
254 .rc_interval = 300, 258 .rc.legacy = {
255 .rc_key_map = ir_codes_dtt200u_table, 259 .rc_interval = 300,
256 .rc_key_map_size = ARRAY_SIZE(ir_codes_dtt200u_table), 260 .rc_key_map = ir_codes_dtt200u_table,
257 .rc_query = dtt200u_rc_query, 261 .rc_key_map_size = ARRAY_SIZE(ir_codes_dtt200u_table),
262 .rc_query = dtt200u_rc_query,
263 },
258 264
259 .generic_bulk_ctrl_endpoint = 0x01, 265 .generic_bulk_ctrl_endpoint = 0x01,
260 266
@@ -296,10 +302,12 @@ static struct dvb_usb_device_properties wt220u_zl0353_properties = {
296 }, 302 },
297 .power_ctrl = dtt200u_power_ctrl, 303 .power_ctrl = dtt200u_power_ctrl,
298 304
299 .rc_interval = 300, 305 .rc.legacy = {
300 .rc_key_map = ir_codes_dtt200u_table, 306 .rc_interval = 300,
301 .rc_key_map_size = ARRAY_SIZE(ir_codes_dtt200u_table), 307 .rc_key_map = ir_codes_dtt200u_table,
302 .rc_query = dtt200u_rc_query, 308 .rc_key_map_size = ARRAY_SIZE(ir_codes_dtt200u_table),
309 .rc_query = dtt200u_rc_query,
310 },
303 311
304 .generic_bulk_ctrl_endpoint = 0x01, 312 .generic_bulk_ctrl_endpoint = 0x01,
305 313
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-ids.h b/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
index b4afe6f8ed19..1a774d58d664 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
@@ -197,6 +197,7 @@
197#define USB_PID_AVERMEDIA_A310 0xa310 197#define USB_PID_AVERMEDIA_A310 0xa310
198#define USB_PID_AVERMEDIA_A850 0x850a 198#define USB_PID_AVERMEDIA_A850 0x850a
199#define USB_PID_AVERMEDIA_A805 0xa805 199#define USB_PID_AVERMEDIA_A805 0xa805
200#define USB_PID_AVERMEDIA_A815M 0x815a
200#define USB_PID_TECHNOTREND_CONNECT_S2400 0x3006 201#define USB_PID_TECHNOTREND_CONNECT_S2400 0x3006
201#define USB_PID_TECHNOTREND_CONNECT_CT3650 0x300d 202#define USB_PID_TECHNOTREND_CONNECT_CT3650 0x300d
202#define USB_PID_TERRATEC_CINERGY_DT_XS_DIVERSITY 0x005a 203#define USB_PID_TERRATEC_CINERGY_DT_XS_DIVERSITY 0x005a
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-init.c b/drivers/media/dvb/dvb-usb/dvb-usb-init.c
index 5d91f70d2d2d..2e3ea0fa28e0 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-init.c
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-init.c
@@ -15,7 +15,7 @@
15 15
16/* debug */ 16/* debug */
17int dvb_usb_debug; 17int dvb_usb_debug;
18module_param_named(debug,dvb_usb_debug, int, 0644); 18module_param_named(debug, dvb_usb_debug, int, 0644);
19MODULE_PARM_DESC(debug, "set debugging level (1=info,xfer=2,pll=4,ts=8,err=16,rc=32,fw=64,mem=128,uxfer=256 (or-able))." DVB_USB_DEBUG_STATUS); 19MODULE_PARM_DESC(debug, "set debugging level (1=info,xfer=2,pll=4,ts=8,err=16,rc=32,fw=64,mem=128,uxfer=256 (or-able))." DVB_USB_DEBUG_STATUS);
20 20
21int dvb_usb_disable_rc_polling; 21int dvb_usb_disable_rc_polling;
@@ -29,7 +29,7 @@ MODULE_PARM_DESC(force_pid_filter_usage, "force all dvb-usb-devices to use a PID
29static int dvb_usb_adapter_init(struct dvb_usb_device *d, short *adapter_nrs) 29static int dvb_usb_adapter_init(struct dvb_usb_device *d, short *adapter_nrs)
30{ 30{
31 struct dvb_usb_adapter *adap; 31 struct dvb_usb_adapter *adap;
32 int ret,n; 32 int ret, n;
33 33
34 for (n = 0; n < d->props.num_adapters; n++) { 34 for (n = 0; n < d->props.num_adapters; n++) {
35 adap = &d->adapter[n]; 35 adap = &d->adapter[n];
@@ -38,7 +38,7 @@ static int dvb_usb_adapter_init(struct dvb_usb_device *d, short *adapter_nrs)
38 38
39 memcpy(&adap->props, &d->props.adapter[n], sizeof(struct dvb_usb_adapter_properties)); 39 memcpy(&adap->props, &d->props.adapter[n], sizeof(struct dvb_usb_adapter_properties));
40 40
41/* speed - when running at FULL speed we need a HW PID filter */ 41 /* speed - when running at FULL speed we need a HW PID filter */
42 if (d->udev->speed == USB_SPEED_FULL && !(adap->props.caps & DVB_USB_ADAP_HAS_PID_FILTER)) { 42 if (d->udev->speed == USB_SPEED_FULL && !(adap->props.caps & DVB_USB_ADAP_HAS_PID_FILTER)) {
43 err("This USB2.0 device cannot be run on a USB1.1 port. (it lacks a hardware PID filter)"); 43 err("This USB2.0 device cannot be run on a USB1.1 port. (it lacks a hardware PID filter)");
44 return -ENODEV; 44 return -ENODEV;
@@ -46,7 +46,7 @@ static int dvb_usb_adapter_init(struct dvb_usb_device *d, short *adapter_nrs)
46 46
47 if ((d->udev->speed == USB_SPEED_FULL && adap->props.caps & DVB_USB_ADAP_HAS_PID_FILTER) || 47 if ((d->udev->speed == USB_SPEED_FULL && adap->props.caps & DVB_USB_ADAP_HAS_PID_FILTER) ||
48 (adap->props.caps & DVB_USB_ADAP_NEED_PID_FILTERING)) { 48 (adap->props.caps & DVB_USB_ADAP_NEED_PID_FILTERING)) {
49 info("will use the device's hardware PID filter (table count: %d).",adap->props.pid_filter_count); 49 info("will use the device's hardware PID filter (table count: %d).", adap->props.pid_filter_count);
50 adap->pid_filtering = 1; 50 adap->pid_filtering = 1;
51 adap->max_feed_count = adap->props.pid_filter_count; 51 adap->max_feed_count = adap->props.pid_filter_count;
52 } else { 52 } else {
@@ -64,9 +64,9 @@ static int dvb_usb_adapter_init(struct dvb_usb_device *d, short *adapter_nrs)
64 } 64 }
65 65
66 if (adap->props.size_of_priv > 0) { 66 if (adap->props.size_of_priv > 0) {
67 adap->priv = kzalloc(adap->props.size_of_priv,GFP_KERNEL); 67 adap->priv = kzalloc(adap->props.size_of_priv, GFP_KERNEL);
68 if (adap->priv == NULL) { 68 if (adap->priv == NULL) {
69 err("no memory for priv for adapter %d.",n); 69 err("no memory for priv for adapter %d.", n);
70 return -ENOMEM; 70 return -ENOMEM;
71 } 71 }
72 } 72 }
@@ -86,8 +86,8 @@ static int dvb_usb_adapter_init(struct dvb_usb_device *d, short *adapter_nrs)
86 * sometimes a timeout occures, this helps 86 * sometimes a timeout occures, this helps
87 */ 87 */
88 if (d->props.generic_bulk_ctrl_endpoint != 0) { 88 if (d->props.generic_bulk_ctrl_endpoint != 0) {
89 usb_clear_halt(d->udev,usb_sndbulkpipe(d->udev,d->props.generic_bulk_ctrl_endpoint)); 89 usb_clear_halt(d->udev, usb_sndbulkpipe(d->udev, d->props.generic_bulk_ctrl_endpoint));
90 usb_clear_halt(d->udev,usb_rcvbulkpipe(d->udev,d->props.generic_bulk_ctrl_endpoint)); 90 usb_clear_halt(d->udev, usb_rcvbulkpipe(d->udev, d->props.generic_bulk_ctrl_endpoint));
91 } 91 }
92 92
93 return 0; 93 return 0;
@@ -96,6 +96,7 @@ static int dvb_usb_adapter_init(struct dvb_usb_device *d, short *adapter_nrs)
96static int dvb_usb_adapter_exit(struct dvb_usb_device *d) 96static int dvb_usb_adapter_exit(struct dvb_usb_device *d)
97{ 97{
98 int n; 98 int n;
99
99 for (n = 0; n < d->num_adapters_initialized; n++) { 100 for (n = 0; n < d->num_adapters_initialized; n++) {
100 dvb_usb_adapter_frontend_exit(&d->adapter[n]); 101 dvb_usb_adapter_frontend_exit(&d->adapter[n]);
101 dvb_usb_adapter_dvb_exit(&d->adapter[n]); 102 dvb_usb_adapter_dvb_exit(&d->adapter[n]);
@@ -111,11 +112,11 @@ static int dvb_usb_adapter_exit(struct dvb_usb_device *d)
111/* general initialization functions */ 112/* general initialization functions */
112static int dvb_usb_exit(struct dvb_usb_device *d) 113static int dvb_usb_exit(struct dvb_usb_device *d)
113{ 114{
114 deb_info("state before exiting everything: %x\n",d->state); 115 deb_info("state before exiting everything: %x\n", d->state);
115 dvb_usb_remote_exit(d); 116 dvb_usb_remote_exit(d);
116 dvb_usb_adapter_exit(d); 117 dvb_usb_adapter_exit(d);
117 dvb_usb_i2c_exit(d); 118 dvb_usb_i2c_exit(d);
118 deb_info("state should be zero now: %x\n",d->state); 119 deb_info("state should be zero now: %x\n", d->state);
119 d->state = DVB_USB_STATE_INIT; 120 d->state = DVB_USB_STATE_INIT;
120 kfree(d->priv); 121 kfree(d->priv);
121 kfree(d); 122 kfree(d);
@@ -132,14 +133,14 @@ static int dvb_usb_init(struct dvb_usb_device *d, short *adapter_nums)
132 d->state = DVB_USB_STATE_INIT; 133 d->state = DVB_USB_STATE_INIT;
133 134
134 if (d->props.size_of_priv > 0) { 135 if (d->props.size_of_priv > 0) {
135 d->priv = kzalloc(d->props.size_of_priv,GFP_KERNEL); 136 d->priv = kzalloc(d->props.size_of_priv, GFP_KERNEL);
136 if (d->priv == NULL) { 137 if (d->priv == NULL) {
137 err("no memory for priv in 'struct dvb_usb_device'"); 138 err("no memory for priv in 'struct dvb_usb_device'");
138 return -ENOMEM; 139 return -ENOMEM;
139 } 140 }
140 } 141 }
141 142
142/* check the capabilities and set appropriate variables */ 143 /* check the capabilities and set appropriate variables */
143 dvb_usb_device_power_ctrl(d, 1); 144 dvb_usb_device_power_ctrl(d, 1);
144 145
145 if ((ret = dvb_usb_i2c_init(d)) || 146 if ((ret = dvb_usb_i2c_init(d)) ||
@@ -157,16 +158,17 @@ static int dvb_usb_init(struct dvb_usb_device *d, short *adapter_nums)
157} 158}
158 159
159/* determine the name and the state of the just found USB device */ 160/* determine the name and the state of the just found USB device */
160static struct dvb_usb_device_description * dvb_usb_find_device(struct usb_device *udev,struct dvb_usb_device_properties *props, int *cold) 161static struct dvb_usb_device_description *dvb_usb_find_device(struct usb_device *udev, struct dvb_usb_device_properties *props, int *cold)
161{ 162{
162 int i,j; 163 int i, j;
163 struct dvb_usb_device_description *desc = NULL; 164 struct dvb_usb_device_description *desc = NULL;
165
164 *cold = -1; 166 *cold = -1;
165 167
166 for (i = 0; i < props->num_device_descs; i++) { 168 for (i = 0; i < props->num_device_descs; i++) {
167 169
168 for (j = 0; j < DVB_USB_ID_MAX_NUM && props->devices[i].cold_ids[j] != NULL; j++) { 170 for (j = 0; j < DVB_USB_ID_MAX_NUM && props->devices[i].cold_ids[j] != NULL; j++) {
169 deb_info("check for cold %x %x\n",props->devices[i].cold_ids[j]->idVendor, props->devices[i].cold_ids[j]->idProduct); 171 deb_info("check for cold %x %x\n", props->devices[i].cold_ids[j]->idVendor, props->devices[i].cold_ids[j]->idProduct);
170 if (props->devices[i].cold_ids[j]->idVendor == le16_to_cpu(udev->descriptor.idVendor) && 172 if (props->devices[i].cold_ids[j]->idVendor == le16_to_cpu(udev->descriptor.idVendor) &&
171 props->devices[i].cold_ids[j]->idProduct == le16_to_cpu(udev->descriptor.idProduct)) { 173 props->devices[i].cold_ids[j]->idProduct == le16_to_cpu(udev->descriptor.idProduct)) {
172 *cold = 1; 174 *cold = 1;
@@ -179,7 +181,7 @@ static struct dvb_usb_device_description * dvb_usb_find_device(struct usb_device
179 break; 181 break;
180 182
181 for (j = 0; j < DVB_USB_ID_MAX_NUM && props->devices[i].warm_ids[j] != NULL; j++) { 183 for (j = 0; j < DVB_USB_ID_MAX_NUM && props->devices[i].warm_ids[j] != NULL; j++) {
182 deb_info("check for warm %x %x\n",props->devices[i].warm_ids[j]->idVendor, props->devices[i].warm_ids[j]->idProduct); 184 deb_info("check for warm %x %x\n", props->devices[i].warm_ids[j]->idVendor, props->devices[i].warm_ids[j]->idProduct);
183 if (props->devices[i].warm_ids[j]->idVendor == le16_to_cpu(udev->descriptor.idVendor) && 185 if (props->devices[i].warm_ids[j]->idVendor == le16_to_cpu(udev->descriptor.idVendor) &&
184 props->devices[i].warm_ids[j]->idProduct == le16_to_cpu(udev->descriptor.idProduct)) { 186 props->devices[i].warm_ids[j]->idProduct == le16_to_cpu(udev->descriptor.idProduct)) {
185 *cold = 0; 187 *cold = 0;
@@ -190,7 +192,7 @@ static struct dvb_usb_device_description * dvb_usb_find_device(struct usb_device
190 } 192 }
191 193
192 if (desc != NULL && props->identify_state != NULL) 194 if (desc != NULL && props->identify_state != NULL)
193 props->identify_state(udev,props,&desc,cold); 195 props->identify_state(udev, props, &desc, cold);
194 196
195 return desc; 197 return desc;
196} 198}
@@ -202,7 +204,7 @@ int dvb_usb_device_power_ctrl(struct dvb_usb_device *d, int onoff)
202 else 204 else
203 d->powered--; 205 d->powered--;
204 206
205 if (d->powered == 0 || (onoff && d->powered == 1)) { // when switching from 1 to 0 or from 0 to 1 207 if (d->powered == 0 || (onoff && d->powered == 1)) { /* when switching from 1 to 0 or from 0 to 1 */
206 deb_info("power control: %d\n", onoff); 208 deb_info("power control: %d\n", onoff);
207 if (d->props.power_ctrl) 209 if (d->props.power_ctrl)
208 return d->props.power_ctrl(d, onoff); 210 return d->props.power_ctrl(d, onoff);
@@ -222,32 +224,32 @@ int dvb_usb_device_init(struct usb_interface *intf,
222 struct dvb_usb_device *d = NULL; 224 struct dvb_usb_device *d = NULL;
223 struct dvb_usb_device_description *desc = NULL; 225 struct dvb_usb_device_description *desc = NULL;
224 226
225 int ret = -ENOMEM,cold=0; 227 int ret = -ENOMEM, cold = 0;
226 228
227 if (du != NULL) 229 if (du != NULL)
228 *du = NULL; 230 *du = NULL;
229 231
230 if ((desc = dvb_usb_find_device(udev,props,&cold)) == NULL) { 232 if ((desc = dvb_usb_find_device(udev, props, &cold)) == NULL) {
231 deb_err("something went very wrong, device was not found in current device list - let's see what comes next.\n"); 233 deb_err("something went very wrong, device was not found in current device list - let's see what comes next.\n");
232 return -ENODEV; 234 return -ENODEV;
233 } 235 }
234 236
235 if (cold) { 237 if (cold) {
236 info("found a '%s' in cold state, will try to load a firmware",desc->name); 238 info("found a '%s' in cold state, will try to load a firmware", desc->name);
237 ret = dvb_usb_download_firmware(udev,props); 239 ret = dvb_usb_download_firmware(udev, props);
238 if (!props->no_reconnect || ret != 0) 240 if (!props->no_reconnect || ret != 0)
239 return ret; 241 return ret;
240 } 242 }
241 243
242 info("found a '%s' in warm state.",desc->name); 244 info("found a '%s' in warm state.", desc->name);
243 d = kzalloc(sizeof(struct dvb_usb_device),GFP_KERNEL); 245 d = kzalloc(sizeof(struct dvb_usb_device), GFP_KERNEL);
244 if (d == NULL) { 246 if (d == NULL) {
245 err("no memory for 'struct dvb_usb_device'"); 247 err("no memory for 'struct dvb_usb_device'");
246 return -ENOMEM; 248 return -ENOMEM;
247 } 249 }
248 250
249 d->udev = udev; 251 d->udev = udev;
250 memcpy(&d->props,props,sizeof(struct dvb_usb_device_properties)); 252 memcpy(&d->props, props, sizeof(struct dvb_usb_device_properties));
251 d->desc = desc; 253 d->desc = desc;
252 d->owner = owner; 254 d->owner = owner;
253 255
@@ -259,9 +261,9 @@ int dvb_usb_device_init(struct usb_interface *intf,
259 ret = dvb_usb_init(d, adapter_nums); 261 ret = dvb_usb_init(d, adapter_nums);
260 262
261 if (ret == 0) 263 if (ret == 0)
262 info("%s successfully initialized and connected.",desc->name); 264 info("%s successfully initialized and connected.", desc->name);
263 else 265 else
264 info("%s error while loading driver (%d)",desc->name,ret); 266 info("%s error while loading driver (%d)", desc->name, ret);
265 return ret; 267 return ret;
266} 268}
267EXPORT_SYMBOL(dvb_usb_device_init); 269EXPORT_SYMBOL(dvb_usb_device_init);
@@ -271,12 +273,12 @@ void dvb_usb_device_exit(struct usb_interface *intf)
271 struct dvb_usb_device *d = usb_get_intfdata(intf); 273 struct dvb_usb_device *d = usb_get_intfdata(intf);
272 const char *name = "generic DVB-USB module"; 274 const char *name = "generic DVB-USB module";
273 275
274 usb_set_intfdata(intf,NULL); 276 usb_set_intfdata(intf, NULL);
275 if (d != NULL && d->desc != NULL) { 277 if (d != NULL && d->desc != NULL) {
276 name = d->desc->name; 278 name = d->desc->name;
277 dvb_usb_exit(d); 279 dvb_usb_exit(d);
278 } 280 }
279 info("%s successfully deinitialized and disconnected.",name); 281 info("%s successfully deinitialized and disconnected.", name);
280 282
281} 283}
282EXPORT_SYMBOL(dvb_usb_device_exit); 284EXPORT_SYMBOL(dvb_usb_device_exit);
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-remote.c b/drivers/media/dvb/dvb-usb/dvb-usb-remote.c
index 852fe89539cf..b579fed3ab3f 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-remote.c
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-remote.c
@@ -8,29 +8,29 @@
8#include "dvb-usb-common.h" 8#include "dvb-usb-common.h"
9#include <linux/usb/input.h> 9#include <linux/usb/input.h>
10 10
11static int dvb_usb_getkeycode(struct input_dev *dev, 11static int legacy_dvb_usb_getkeycode(struct input_dev *dev,
12 unsigned int scancode, unsigned int *keycode) 12 unsigned int scancode, unsigned int *keycode)
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 dvb_usb_rc_key *keymap = d->props.rc_key_map; 16 struct ir_scancode *keymap = d->props.rc.legacy.rc_key_map;
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_key_map_size; i++) 20 for (i = 0; i < d->props.rc.legacy.rc_key_map_size; i++)
21 if (keymap[i].scan == scancode) { 21 if (keymap[i].scancode == scancode) {
22 *keycode = keymap[i].event; 22 *keycode = keymap[i].keycode;
23 return 0; 23 return 0;
24 } 24 }
25 25
26 /* 26 /*
27 * If is there extra space, returns KEY_RESERVED, 27 * If is there extra space, returns KEY_RESERVED,
28 * otherwise, input core won't let 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_key_map_size; i++) 31 for (i = 0; i < d->props.rc.legacy.rc_key_map_size; i++)
32 if (keymap[i].event == KEY_RESERVED || 32 if (keymap[i].keycode == KEY_RESERVED ||
33 keymap[i].event == KEY_UNKNOWN) { 33 keymap[i].keycode == KEY_UNKNOWN) {
34 *keycode = KEY_RESERVED; 34 *keycode = KEY_RESERVED;
35 return 0; 35 return 0;
36 } 36 }
@@ -38,27 +38,27 @@ static int dvb_usb_getkeycode(struct input_dev *dev,
38 return -EINVAL; 38 return -EINVAL;
39} 39}
40 40
41static int dvb_usb_setkeycode(struct input_dev *dev, 41static int legacy_dvb_usb_setkeycode(struct input_dev *dev,
42 unsigned int scancode, unsigned int keycode) 42 unsigned int scancode, unsigned int keycode)
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 dvb_usb_rc_key *keymap = d->props.rc_key_map; 46 struct ir_scancode *keymap = d->props.rc.legacy.rc_key_map;
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_key_map_size; i++) 50 for (i = 0; i < d->props.rc.legacy.rc_key_map_size; i++)
51 if (keymap[i].scan == scancode) { 51 if (keymap[i].scancode == scancode) {
52 keymap[i].event = 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_key_map_size; i++) 57 for (i = 0; i < d->props.rc.legacy.rc_key_map_size; i++)
58 if (keymap[i].event == KEY_RESERVED || 58 if (keymap[i].keycode == KEY_RESERVED ||
59 keymap[i].event == KEY_UNKNOWN) { 59 keymap[i].keycode == KEY_UNKNOWN) {
60 keymap[i].scan = scancode; 60 keymap[i].scancode = scancode;
61 keymap[i].event = keycode; 61 keymap[i].keycode = keycode;
62 return 0; 62 return 0;
63 } 63 }
64 64
@@ -78,7 +78,7 @@ static int dvb_usb_setkeycode(struct input_dev *dev,
78 * 78 *
79 * TODO: Fix the repeat rate of the input device. 79 * TODO: Fix the repeat rate of the input device.
80 */ 80 */
81static void dvb_usb_read_remote_control(struct work_struct *work) 81static void legacy_dvb_usb_read_remote_control(struct work_struct *work)
82{ 82{
83 struct dvb_usb_device *d = 83 struct dvb_usb_device *d =
84 container_of(work, struct dvb_usb_device, rc_query_work.work); 84 container_of(work, struct dvb_usb_device, rc_query_work.work);
@@ -92,7 +92,7 @@ static void dvb_usb_read_remote_control(struct work_struct *work)
92 if (dvb_usb_disable_rc_polling) 92 if (dvb_usb_disable_rc_polling)
93 return; 93 return;
94 94
95 if (d->props.rc_query(d,&event,&state)) { 95 if (d->props.rc.legacy.rc_query(d,&event,&state)) {
96 err("error while querying for an remote control event."); 96 err("error while querying for an remote control event.");
97 goto schedule; 97 goto schedule;
98 } 98 }
@@ -151,18 +151,117 @@ static void dvb_usb_read_remote_control(struct work_struct *work)
151*/ 151*/
152 152
153schedule: 153schedule:
154 schedule_delayed_work(&d->rc_query_work,msecs_to_jiffies(d->props.rc_interval)); 154 schedule_delayed_work(&d->rc_query_work,msecs_to_jiffies(d->props.rc.legacy.rc_interval));
155}
156
157static int legacy_dvb_usb_remote_init(struct dvb_usb_device *d,
158 struct input_dev *input_dev)
159{
160 int i, err, rc_interval;
161
162 input_dev->getkeycode = legacy_dvb_usb_getkeycode;
163 input_dev->setkeycode = legacy_dvb_usb_setkeycode;
164
165 /* set the bits for the keys */
166 deb_rc("key map size: %d\n", d->props.rc.legacy.rc_key_map_size);
167 for (i = 0; i < d->props.rc.legacy.rc_key_map_size; i++) {
168 deb_rc("setting bit for event %d item %d\n",
169 d->props.rc.legacy.rc_key_map[i].keycode, i);
170 set_bit(d->props.rc.legacy.rc_key_map[i].keycode, input_dev->keybit);
171 }
172
173 /* setting these two values to non-zero, we have to manage key repeats */
174 input_dev->rep[REP_PERIOD] = d->props.rc.legacy.rc_interval;
175 input_dev->rep[REP_DELAY] = d->props.rc.legacy.rc_interval + 150;
176
177 input_set_drvdata(input_dev, d);
178
179 err = input_register_device(input_dev);
180 if (err)
181 input_free_device(input_dev);
182
183 rc_interval = d->props.rc.legacy.rc_interval;
184
185 INIT_DELAYED_WORK(&d->rc_query_work, legacy_dvb_usb_read_remote_control);
186
187 info("schedule remote query interval to %d msecs.", rc_interval);
188 schedule_delayed_work(&d->rc_query_work,
189 msecs_to_jiffies(rc_interval));
190
191 d->state |= DVB_USB_STATE_REMOTE;
192
193 return err;
194}
195
196/* Remote-control poll function - called every dib->rc_query_interval ms to see
197 * whether the remote control has received anything.
198 *
199 * TODO: Fix the repeat rate of the input device.
200 */
201static void dvb_usb_read_remote_control(struct work_struct *work)
202{
203 struct dvb_usb_device *d =
204 container_of(work, struct dvb_usb_device, rc_query_work.work);
205 int err;
206
207 /* TODO: need a lock here. We can simply skip checking for the remote control
208 if we're busy. */
209
210 /* when the parameter has been set to 1 via sysfs while the
211 * driver was running, or when bulk mode is enabled after IR init
212 */
213 if (dvb_usb_disable_rc_polling || d->props.rc.core.bulk_mode)
214 return;
215
216 err = d->props.rc.core.rc_query(d);
217 if (err)
218 err("error %d while querying for an remote control event.", err);
219
220 schedule_delayed_work(&d->rc_query_work,
221 msecs_to_jiffies(d->props.rc.core.rc_interval));
222}
223
224static int rc_core_dvb_usb_remote_init(struct dvb_usb_device *d,
225 struct input_dev *input_dev)
226{
227 int err, rc_interval;
228
229 d->props.rc.core.rc_props.priv = d;
230 err = ir_input_register(input_dev,
231 d->props.rc.core.rc_codes,
232 &d->props.rc.core.rc_props,
233 d->props.rc.core.module_name);
234 if (err < 0)
235 return err;
236
237 if (!d->props.rc.core.rc_query || d->props.rc.core.bulk_mode)
238 return 0;
239
240 /* Polling mode - initialize a work queue for handling it */
241 INIT_DELAYED_WORK(&d->rc_query_work, dvb_usb_read_remote_control);
242
243 rc_interval = d->props.rc.core.rc_interval;
244
245 info("schedule remote query interval to %d msecs.", rc_interval);
246 schedule_delayed_work(&d->rc_query_work,
247 msecs_to_jiffies(rc_interval));
248
249 return 0;
155} 250}
156 251
157int dvb_usb_remote_init(struct dvb_usb_device *d) 252int dvb_usb_remote_init(struct dvb_usb_device *d)
158{ 253{
159 struct input_dev *input_dev; 254 struct input_dev *input_dev;
160 int i;
161 int err; 255 int err;
162 256
163 if (d->props.rc_key_map == NULL || 257 if (dvb_usb_disable_rc_polling)
164 d->props.rc_query == NULL || 258 return 0;
165 dvb_usb_disable_rc_polling) 259
260 if (d->props.rc.legacy.rc_key_map && d->props.rc.legacy.rc_query)
261 d->props.rc.mode = DVB_RC_LEGACY;
262 else if (d->props.rc.core.rc_codes)
263 d->props.rc.mode = DVB_RC_CORE;
264 else
166 return 0; 265 return 0;
167 266
168 usb_make_path(d->udev, d->rc_phys, sizeof(d->rc_phys)); 267 usb_make_path(d->udev, d->rc_phys, sizeof(d->rc_phys));
@@ -177,39 +276,19 @@ int dvb_usb_remote_init(struct dvb_usb_device *d)
177 input_dev->phys = d->rc_phys; 276 input_dev->phys = d->rc_phys;
178 usb_to_input_id(d->udev, &input_dev->id); 277 usb_to_input_id(d->udev, &input_dev->id);
179 input_dev->dev.parent = &d->udev->dev; 278 input_dev->dev.parent = &d->udev->dev;
180 input_dev->getkeycode = dvb_usb_getkeycode;
181 input_dev->setkeycode = dvb_usb_setkeycode;
182
183 /* set the bits for the keys */
184 deb_rc("key map size: %d\n", d->props.rc_key_map_size);
185 for (i = 0; i < d->props.rc_key_map_size; i++) {
186 deb_rc("setting bit for event %d item %d\n",
187 d->props.rc_key_map[i].event, i);
188 set_bit(d->props.rc_key_map[i].event, input_dev->keybit);
189 }
190 279
191 /* Start the remote-control polling. */ 280 /* Start the remote-control polling. */
192 if (d->props.rc_interval < 40) 281 if (d->props.rc.legacy.rc_interval < 40)
193 d->props.rc_interval = 100; /* default */ 282 d->props.rc.legacy.rc_interval = 100; /* default */
194
195 /* setting these two values to non-zero, we have to manage key repeats */
196 input_dev->rep[REP_PERIOD] = d->props.rc_interval;
197 input_dev->rep[REP_DELAY] = d->props.rc_interval + 150;
198
199 input_set_drvdata(input_dev, d);
200
201 err = input_register_device(input_dev);
202 if (err) {
203 input_free_device(input_dev);
204 return err;
205 }
206 283
207 d->rc_input_dev = input_dev; 284 d->rc_input_dev = input_dev;
208 285
209 INIT_DELAYED_WORK(&d->rc_query_work, dvb_usb_read_remote_control); 286 if (d->props.rc.mode == DVB_RC_LEGACY)
210 287 err = legacy_dvb_usb_remote_init(d, input_dev);
211 info("schedule remote query interval to %d msecs.", d->props.rc_interval); 288 else
212 schedule_delayed_work(&d->rc_query_work,msecs_to_jiffies(d->props.rc_interval)); 289 err = rc_core_dvb_usb_remote_init(d, input_dev);
290 if (err)
291 return err;
213 292
214 d->state |= DVB_USB_STATE_REMOTE; 293 d->state |= DVB_USB_STATE_REMOTE;
215 294
@@ -221,7 +300,10 @@ int dvb_usb_remote_exit(struct dvb_usb_device *d)
221 if (d->state & DVB_USB_STATE_REMOTE) { 300 if (d->state & DVB_USB_STATE_REMOTE) {
222 cancel_rearming_delayed_work(&d->rc_query_work); 301 cancel_rearming_delayed_work(&d->rc_query_work);
223 flush_scheduled_work(); 302 flush_scheduled_work();
224 input_unregister_device(d->rc_input_dev); 303 if (d->props.rc.mode == DVB_RC_LEGACY)
304 input_unregister_device(d->rc_input_dev);
305 else
306 ir_input_unregister(d->rc_input_dev);
225 } 307 }
226 d->state &= ~DVB_USB_STATE_REMOTE; 308 d->state &= ~DVB_USB_STATE_REMOTE;
227 return 0; 309 return 0;
@@ -234,7 +316,7 @@ int dvb_usb_nec_rc_key_to_event(struct dvb_usb_device *d,
234 u8 keybuf[5], u32 *event, int *state) 316 u8 keybuf[5], u32 *event, int *state)
235{ 317{
236 int i; 318 int i;
237 struct dvb_usb_rc_key *keymap = d->props.rc_key_map; 319 struct ir_scancode *keymap = d->props.rc.legacy.rc_key_map;
238 *event = 0; 320 *event = 0;
239 *state = REMOTE_NO_KEY_PRESSED; 321 *state = REMOTE_NO_KEY_PRESSED;
240 switch (keybuf[0]) { 322 switch (keybuf[0]) {
@@ -247,10 +329,10 @@ int dvb_usb_nec_rc_key_to_event(struct dvb_usb_device *d,
247 break; 329 break;
248 } 330 }
249 /* See if we can match the raw key code. */ 331 /* See if we can match the raw key code. */
250 for (i = 0; i < d->props.rc_key_map_size; i++) 332 for (i = 0; i < d->props.rc.legacy.rc_key_map_size; i++)
251 if (rc5_custom(&keymap[i]) == keybuf[1] && 333 if (rc5_custom(&keymap[i]) == keybuf[1] &&
252 rc5_data(&keymap[i]) == keybuf[3]) { 334 rc5_data(&keymap[i]) == keybuf[3]) {
253 *event = keymap[i].event; 335 *event = keymap[i].keycode;
254 *state = REMOTE_KEY_PRESSED; 336 *state = REMOTE_KEY_PRESSED;
255 return 0; 337 return 0;
256 } 338 }
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb.h b/drivers/media/dvb/dvb-usb/dvb-usb.h
index 4a9f676087bf..34f7b3ba8cc7 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb.h
+++ b/drivers/media/dvb/dvb-usb/dvb-usb.h
@@ -14,6 +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 18
18#include "dvb_frontend.h" 19#include "dvb_frontend.h"
19#include "dvb_demux.h" 20#include "dvb_demux.h"
@@ -74,30 +75,19 @@ struct dvb_usb_device_description {
74 struct usb_device_id *warm_ids[DVB_USB_ID_MAX_NUM]; 75 struct usb_device_id *warm_ids[DVB_USB_ID_MAX_NUM];
75}; 76};
76 77
77/** 78static inline u8 rc5_custom(struct ir_scancode *key)
78 * struct dvb_usb_rc_key - a remote control key and its input-event
79 * @custom: the vendor/custom part of the key
80 * @data: the actual key part
81 * @event: the input event assigned to key identified by custom and data
82 */
83struct dvb_usb_rc_key {
84 u16 scan;
85 u32 event;
86};
87
88static inline u8 rc5_custom(struct dvb_usb_rc_key *key)
89{ 79{
90 return (key->scan >> 8) & 0xff; 80 return (key->scancode >> 8) & 0xff;
91} 81}
92 82
93static inline u8 rc5_data(struct dvb_usb_rc_key *key) 83static inline u8 rc5_data(struct ir_scancode *key)
94{ 84{
95 return key->scan & 0xff; 85 return key->scancode & 0xff;
96} 86}
97 87
98static inline u8 rc5_scan(struct dvb_usb_rc_key *key) 88static inline u8 rc5_scan(struct ir_scancode *key)
99{ 89{
100 return key->scan & 0xffff; 90 return key->scancode & 0xffff;
101} 91}
102 92
103struct dvb_usb_device; 93struct dvb_usb_device;
@@ -168,6 +158,55 @@ struct dvb_usb_adapter_properties {
168}; 158};
169 159
170/** 160/**
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
163 * remote control handling).
164 * @rc_key_map_size: number of items in @rc_key_map.
165 * @rc_query: called to query an event event.
166 * @rc_interval: time in ms between two queries.
167 */
168struct dvb_rc_legacy {
169/* remote control properties */
170#define REMOTE_NO_KEY_PRESSED 0x00
171#define REMOTE_KEY_PRESSED 0x01
172#define REMOTE_KEY_REPEAT 0x02
173 struct ir_scancode *rc_key_map;
174 int rc_key_map_size;
175 int (*rc_query) (struct dvb_usb_device *, u32 *, int *);
176 int rc_interval;
177};
178
179/**
180 * struct dvb_rc properties of remote controller, using rc-core
181 * @rc_codes: name of rc codes table
182 * @protocol: type of protocol(s) currently used by the driver
183 * @rc_query: called to query an event event.
184 * @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 */
188struct dvb_rc {
189 char *rc_codes;
190 u64 protocol;
191 char *module_name;
192 int (*rc_query) (struct dvb_usb_device *d);
193 int rc_interval;
194 struct ir_dev_props rc_props;
195 bool bulk_mode; /* uses bulk mode */
196};
197
198/**
199 * enum dvb_usb_mode - Specifies if it is using a legacy driver or a new one
200 * based on rc-core
201 * This is initialized/used only inside dvb-usb-remote.c.
202 * It shouldn't be set by the drivers.
203 */
204enum dvb_usb_mode {
205 DVB_RC_LEGACY,
206 DVB_RC_CORE,
207};
208
209/**
171 * struct dvb_usb_device_properties - properties of a dvb-usb-device 210 * struct dvb_usb_device_properties - properties of a dvb-usb-device
172 * @usb_ctrl: which USB device-side controller is in use. Needed for firmware 211 * @usb_ctrl: which USB device-side controller is in use. Needed for firmware
173 * download. 212 * download.
@@ -185,11 +224,7 @@ struct dvb_usb_adapter_properties {
185 * @identify_state: called to determine the state (cold or warm), when it 224 * @identify_state: called to determine the state (cold or warm), when it
186 * is not distinguishable by the USB IDs. 225 * is not distinguishable by the USB IDs.
187 * 226 *
188 * @rc_key_map: a hard-wired array of struct dvb_usb_rc_key (NULL to disable 227 * @rc: remote controller properties
189 * remote control handling).
190 * @rc_key_map_size: number of items in @rc_key_map.
191 * @rc_query: called to query an event event.
192 * @rc_interval: time in ms between two queries.
193 * 228 *
194 * @i2c_algo: i2c_algorithm if the device has I2CoverUSB. 229 * @i2c_algo: i2c_algorithm if the device has I2CoverUSB.
195 * 230 *
@@ -233,14 +268,11 @@ struct dvb_usb_device_properties {
233 int (*identify_state) (struct usb_device *, struct dvb_usb_device_properties *, 268 int (*identify_state) (struct usb_device *, struct dvb_usb_device_properties *,
234 struct dvb_usb_device_description **, int *); 269 struct dvb_usb_device_description **, int *);
235 270
236/* remote control properties */ 271 struct {
237#define REMOTE_NO_KEY_PRESSED 0x00 272 enum dvb_usb_mode mode; /* Drivers shouldn't touch on it */
238#define REMOTE_KEY_PRESSED 0x01 273 struct dvb_rc_legacy legacy;
239#define REMOTE_KEY_REPEAT 0x02 274 struct dvb_rc core;
240 struct dvb_usb_rc_key *rc_key_map; 275 } rc;
241 int rc_key_map_size;
242 int (*rc_query) (struct dvb_usb_device *, u32 *, int *);
243 int rc_interval;
244 276
245 struct i2c_algorithm *i2c_algo; 277 struct i2c_algorithm *i2c_algo;
246 278
diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
index e8fb85380672..774df88dc6e3 100644
--- a/drivers/media/dvb/dvb-usb/dw2102.c
+++ b/drivers/media/dvb/dvb-usb/dw2102.c
@@ -74,7 +74,7 @@
74 "on firmware-problems." 74 "on firmware-problems."
75 75
76struct ir_codes_dvb_usb_table_table { 76struct ir_codes_dvb_usb_table_table {
77 struct dvb_usb_rc_key *rc_keys; 77 struct ir_scancode *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 dvb_usb_rc_key ir_codes_dw210x_table[] = { 951static struct ir_scancode ir_codes_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 dvb_usb_rc_key ir_codes_dw210x_table[] = {
982 { 0xf81b, KEY_B }, /*recall*/ 982 { 0xf81b, KEY_B }, /*recall*/
983}; 983};
984 984
985static struct dvb_usb_rc_key ir_codes_tevii_table[] = { 985static struct ir_scancode ir_codes_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 dvb_usb_rc_key ir_codes_tevii_table[] = {
1032 { 0xf858, KEY_SWITCHVIDEOMODE }, 1032 { 0xf858, KEY_SWITCHVIDEOMODE },
1033}; 1033};
1034 1034
1035static struct dvb_usb_rc_key ir_codes_tbs_table[] = { 1035static struct ir_scancode ir_codes_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 },
@@ -1075,8 +1075,8 @@ static struct ir_codes_dvb_usb_table_table keys_tables[] = {
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 dvb_usb_rc_key *keymap = d->props.rc_key_map; 1078 struct ir_scancode *keymap = d->props.rc.legacy.rc_key_map;
1079 int keymap_size = d->props.rc_key_map_size; 1079 int keymap_size = d->props.rc.legacy.rc_key_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,
@@ -1096,7 +1096,7 @@ static int dw2102_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
1096 for (i = 0; i < keymap_size ; i++) { 1096 for (i = 0; i < keymap_size ; i++) {
1097 if (rc5_data(&keymap[i]) == msg.buf[0]) { 1097 if (rc5_data(&keymap[i]) == msg.buf[0]) {
1098 *state = REMOTE_KEY_PRESSED; 1098 *state = REMOTE_KEY_PRESSED;
1099 *event = keymap[i].event; 1099 *event = keymap[i].keycode;
1100 break; 1100 break;
1101 } 1101 }
1102 1102
@@ -1185,13 +1185,13 @@ 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_key_map = ir_codes_tbs_table; 1188 s6x0_properties.rc.legacy.rc_key_map = ir_codes_tbs_table;
1189 s6x0_properties.rc_key_map_size = 1189 s6x0_properties.rc.legacy.rc_key_map_size =
1190 ARRAY_SIZE(ir_codes_tbs_table); 1190 ARRAY_SIZE(ir_codes_tbs_table);
1191 break; 1191 break;
1192 case USB_PID_TEVII_S650: 1192 case USB_PID_TEVII_S650:
1193 dw2104_properties.rc_key_map = ir_codes_tevii_table; 1193 dw2104_properties.rc.legacy.rc_key_map = ir_codes_tevii_table;
1194 dw2104_properties.rc_key_map_size = 1194 dw2104_properties.rc.legacy.rc_key_map_size =
1195 ARRAY_SIZE(ir_codes_tevii_table); 1195 ARRAY_SIZE(ir_codes_tevii_table);
1196 case USB_PID_DW2104: 1196 case USB_PID_DW2104:
1197 reset = 1; 1197 reset = 1;
@@ -1255,10 +1255,13 @@ static struct dvb_usb_device_properties dw2102_properties = {
1255 .no_reconnect = 1, 1255 .no_reconnect = 1,
1256 1256
1257 .i2c_algo = &dw2102_serit_i2c_algo, 1257 .i2c_algo = &dw2102_serit_i2c_algo,
1258 .rc_key_map = ir_codes_dw210x_table, 1258
1259 .rc_key_map_size = ARRAY_SIZE(ir_codes_dw210x_table), 1259 .rc.legacy = {
1260 .rc_interval = 150, 1260 .rc_key_map = ir_codes_dw210x_table,
1261 .rc_query = dw2102_rc_query, 1261 .rc_key_map_size = ARRAY_SIZE(ir_codes_dw210x_table),
1262 .rc_interval = 150,
1263 .rc_query = dw2102_rc_query,
1264 },
1262 1265
1263 .generic_bulk_ctrl_endpoint = 0x81, 1266 .generic_bulk_ctrl_endpoint = 0x81,
1264 /* parameter for the MPEG2-data transfer */ 1267 /* parameter for the MPEG2-data transfer */
@@ -1306,10 +1309,12 @@ static struct dvb_usb_device_properties dw2104_properties = {
1306 .no_reconnect = 1, 1309 .no_reconnect = 1,
1307 1310
1308 .i2c_algo = &dw2104_i2c_algo, 1311 .i2c_algo = &dw2104_i2c_algo,
1309 .rc_key_map = ir_codes_dw210x_table, 1312 .rc.legacy = {
1310 .rc_key_map_size = ARRAY_SIZE(ir_codes_dw210x_table), 1313 .rc_key_map = ir_codes_dw210x_table,
1311 .rc_interval = 150, 1314 .rc_key_map_size = ARRAY_SIZE(ir_codes_dw210x_table),
1312 .rc_query = dw2102_rc_query, 1315 .rc_interval = 150,
1316 .rc_query = dw2102_rc_query,
1317 },
1313 1318
1314 .generic_bulk_ctrl_endpoint = 0x81, 1319 .generic_bulk_ctrl_endpoint = 0x81,
1315 /* parameter for the MPEG2-data transfer */ 1320 /* parameter for the MPEG2-data transfer */
@@ -1353,10 +1358,12 @@ static struct dvb_usb_device_properties dw3101_properties = {
1353 .no_reconnect = 1, 1358 .no_reconnect = 1,
1354 1359
1355 .i2c_algo = &dw3101_i2c_algo, 1360 .i2c_algo = &dw3101_i2c_algo,
1356 .rc_key_map = ir_codes_dw210x_table, 1361 .rc.legacy = {
1357 .rc_key_map_size = ARRAY_SIZE(ir_codes_dw210x_table), 1362 .rc_key_map = ir_codes_dw210x_table,
1358 .rc_interval = 150, 1363 .rc_key_map_size = ARRAY_SIZE(ir_codes_dw210x_table),
1359 .rc_query = dw2102_rc_query, 1364 .rc_interval = 150,
1365 .rc_query = dw2102_rc_query,
1366 },
1360 1367
1361 .generic_bulk_ctrl_endpoint = 0x81, 1368 .generic_bulk_ctrl_endpoint = 0x81,
1362 /* parameter for the MPEG2-data transfer */ 1369 /* parameter for the MPEG2-data transfer */
@@ -1396,10 +1403,12 @@ static struct dvb_usb_device_properties s6x0_properties = {
1396 .no_reconnect = 1, 1403 .no_reconnect = 1,
1397 1404
1398 .i2c_algo = &s6x0_i2c_algo, 1405 .i2c_algo = &s6x0_i2c_algo,
1399 .rc_key_map = ir_codes_tevii_table, 1406 .rc.legacy = {
1400 .rc_key_map_size = ARRAY_SIZE(ir_codes_tevii_table), 1407 .rc_key_map = ir_codes_tevii_table,
1401 .rc_interval = 150, 1408 .rc_key_map_size = ARRAY_SIZE(ir_codes_tevii_table),
1402 .rc_query = dw2102_rc_query, 1409 .rc_interval = 150,
1410 .rc_query = dw2102_rc_query,
1411 },
1403 1412
1404 .generic_bulk_ctrl_endpoint = 0x81, 1413 .generic_bulk_ctrl_endpoint = 0x81,
1405 .num_adapters = 1, 1414 .num_adapters = 1,
@@ -1459,8 +1468,8 @@ static int dw2102_probe(struct usb_interface *intf,
1459 /* fill only different fields */ 1468 /* fill only different fields */
1460 p7500->firmware = "dvb-usb-p7500.fw"; 1469 p7500->firmware = "dvb-usb-p7500.fw";
1461 p7500->devices[0] = d7500; 1470 p7500->devices[0] = d7500;
1462 p7500->rc_key_map = ir_codes_tbs_table; 1471 p7500->rc.legacy.rc_key_map = ir_codes_tbs_table;
1463 p7500->rc_key_map_size = ARRAY_SIZE(ir_codes_tbs_table); 1472 p7500->rc.legacy.rc_key_map_size = ARRAY_SIZE(ir_codes_tbs_table);
1464 p7500->adapter->frontend_attach = prof_7500_frontend_attach; 1473 p7500->adapter->frontend_attach = prof_7500_frontend_attach;
1465 1474
1466 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-fe.c b/drivers/media/dvb/dvb-usb/gp8psk-fe.c
index 7a7f1b2b681c..dbdb5347b2a8 100644
--- a/drivers/media/dvb/dvb-usb/gp8psk-fe.c
+++ b/drivers/media/dvb/dvb-usb/gp8psk-fe.c
@@ -349,7 +349,7 @@ static struct dvb_frontend_ops gp8psk_fe_ops = {
349 * FE_CAN_QAM_16 is for compatibility 349 * FE_CAN_QAM_16 is for compatibility
350 * (Myth incorrectly detects Turbo-QPSK as plain QAM-16) 350 * (Myth incorrectly detects Turbo-QPSK as plain QAM-16)
351 */ 351 */
352 FE_CAN_QPSK | FE_CAN_QAM_16 352 FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_TURBO_FEC
353 }, 353 },
354 354
355 .release = gp8psk_fe_release, 355 .release = gp8psk_fe_release,
diff --git a/drivers/media/dvb/dvb-usb/m920x.c b/drivers/media/dvb/dvb-usb/m920x.c
index c211fef45fc3..bdef1a18b664 100644
--- a/drivers/media/dvb/dvb-usb/m920x.c
+++ b/drivers/media/dvb/dvb-usb/m920x.c
@@ -69,7 +69,7 @@ static int m920x_init(struct dvb_usb_device *d, struct m920x_inits *rc_seq)
69 int adap_enabled[M9206_MAX_ADAPTERS] = { 0 }; 69 int adap_enabled[M9206_MAX_ADAPTERS] = { 0 };
70 70
71 /* Remote controller init. */ 71 /* Remote controller init. */
72 if (d->props.rc_query) { 72 if (d->props.rc.legacy.rc_query) {
73 deb("Initialising remote control\n"); 73 deb("Initialising remote control\n");
74 while (rc_seq->address) { 74 while (rc_seq->address) {
75 if ((ret = m920x_write(d->udev, M9206_CORE, 75 if ((ret = m920x_write(d->udev, M9206_CORE,
@@ -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_key_map_size; i++) 145 for (i = 0; i < d->props.rc.legacy.rc_key_map_size; i++)
146 if (rc5_data(&d->props.rc_key_map[i]) == rc_state[1]) { 146 if (rc5_data(&d->props.rc.legacy.rc_key_map[i]) == rc_state[1]) {
147 *event = d->props.rc_key_map[i].event; 147 *event = d->props.rc.legacy.rc_key_map[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 dvb_usb_rc_key ir_codes_megasky_table [] = { 592static struct ir_scancode ir_codes_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 dvb_usb_rc_key ir_codes_megasky_table [] = {
608 { 0x000e, KEY_COFFEE }, /* "MTS" */ 608 { 0x000e, KEY_COFFEE }, /* "MTS" */
609}; 609};
610 610
611static struct dvb_usb_rc_key ir_codes_tvwalkertwin_table [] = { 611static struct ir_scancode ir_codes_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 dvb_usb_rc_key ir_codes_tvwalkertwin_table [] = {
628 { 0x001e, KEY_VOLUMEUP }, 628 { 0x001e, KEY_VOLUMEUP },
629}; 629};
630 630
631static struct dvb_usb_rc_key ir_codes_pinnacle310e_table[] = { 631static struct ir_scancode ir_codes_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 },
@@ -784,10 +784,12 @@ static struct dvb_usb_device_properties megasky_properties = {
784 .firmware = "dvb-usb-megasky-02.fw", 784 .firmware = "dvb-usb-megasky-02.fw",
785 .download_firmware = m920x_firmware_download, 785 .download_firmware = m920x_firmware_download,
786 786
787 .rc_interval = 100, 787 .rc.legacy = {
788 .rc_key_map = ir_codes_megasky_table, 788 .rc_interval = 100,
789 .rc_key_map_size = ARRAY_SIZE(ir_codes_megasky_table), 789 .rc_key_map = ir_codes_megasky_table,
790 .rc_query = m920x_rc_query, 790 .rc_key_map_size = ARRAY_SIZE(ir_codes_megasky_table),
791 .rc_query = m920x_rc_query,
792 },
791 793
792 .size_of_priv = sizeof(struct m920x_state), 794 .size_of_priv = sizeof(struct m920x_state),
793 795
@@ -885,10 +887,12 @@ static struct dvb_usb_device_properties tvwalkertwin_properties = {
885 .firmware = "dvb-usb-tvwalkert.fw", 887 .firmware = "dvb-usb-tvwalkert.fw",
886 .download_firmware = m920x_firmware_download, 888 .download_firmware = m920x_firmware_download,
887 889
888 .rc_interval = 100, 890 .rc.legacy = {
889 .rc_key_map = ir_codes_tvwalkertwin_table, 891 .rc_interval = 100,
890 .rc_key_map_size = ARRAY_SIZE(ir_codes_tvwalkertwin_table), 892 .rc_key_map = ir_codes_tvwalkertwin_table,
891 .rc_query = m920x_rc_query, 893 .rc_key_map_size = ARRAY_SIZE(ir_codes_tvwalkertwin_table),
894 .rc_query = m920x_rc_query,
895 },
892 896
893 .size_of_priv = sizeof(struct m920x_state), 897 .size_of_priv = sizeof(struct m920x_state),
894 898
@@ -992,10 +996,12 @@ static struct dvb_usb_device_properties pinnacle_pctv310e_properties = {
992 .usb_ctrl = DEVICE_SPECIFIC, 996 .usb_ctrl = DEVICE_SPECIFIC,
993 .download_firmware = NULL, 997 .download_firmware = NULL,
994 998
995 .rc_interval = 100, 999 .rc.legacy = {
996 .rc_key_map = ir_codes_pinnacle310e_table, 1000 .rc_interval = 100,
997 .rc_key_map_size = ARRAY_SIZE(ir_codes_pinnacle310e_table), 1001 .rc_key_map = ir_codes_pinnacle310e_table,
998 .rc_query = m920x_rc_query, 1002 .rc_key_map_size = ARRAY_SIZE(ir_codes_pinnacle310e_table),
1003 .rc_query = m920x_rc_query,
1004 },
999 1005
1000 .size_of_priv = sizeof(struct m920x_state), 1006 .size_of_priv = sizeof(struct m920x_state),
1001 1007
diff --git a/drivers/media/dvb/dvb-usb/nova-t-usb2.c b/drivers/media/dvb/dvb-usb/nova-t-usb2.c
index d195a587cc65..181f36a12e2a 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 dvb_usb_rc_key ir_codes_haupp_table [] = { 24static struct ir_scancode ir_codes_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 },
@@ -98,7 +98,7 @@ static int nova_t_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
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(&ir_codes_haupp_table[i]),
99 rc5_custom(&ir_codes_haupp_table[i])); 99 rc5_custom(&ir_codes_haupp_table[i]));
100 100
101 *event = ir_codes_haupp_table[i].event; 101 *event = ir_codes_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)
@@ -195,10 +195,12 @@ static struct dvb_usb_device_properties nova_t_properties = {
195 .power_ctrl = dibusb2_0_power_ctrl, 195 .power_ctrl = dibusb2_0_power_ctrl,
196 .read_mac_address = nova_t_read_mac_address, 196 .read_mac_address = nova_t_read_mac_address,
197 197
198 .rc_interval = 100, 198 .rc.legacy = {
199 .rc_key_map = ir_codes_haupp_table, 199 .rc_interval = 100,
200 .rc_key_map_size = ARRAY_SIZE(ir_codes_haupp_table), 200 .rc_key_map = ir_codes_haupp_table,
201 .rc_query = nova_t_rc_query, 201 .rc_key_map_size = ARRAY_SIZE(ir_codes_haupp_table),
202 .rc_query = nova_t_rc_query,
203 },
202 204
203 .i2c_algo = &dibusb_i2c_algo, 205 .i2c_algo = &dibusb_i2c_algo,
204 206
diff --git a/drivers/media/dvb/dvb-usb/opera1.c b/drivers/media/dvb/dvb-usb/opera1.c
index dfb81ff1d9a7..6b22ec64ab0c 100644
--- a/drivers/media/dvb/dvb-usb/opera1.c
+++ b/drivers/media/dvb/dvb-usb/opera1.c
@@ -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 dvb_usb_rc_key ir_codes_opera1_table[] = { 334static struct ir_scancode ir_codes_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},
@@ -407,9 +407,9 @@ static int opera1_rc_query(struct dvb_usb_device *dev, u32 * event, int *state)
407 for (i = 0; i < ARRAY_SIZE(ir_codes_opera1_table); i++) { 407 for (i = 0; i < ARRAY_SIZE(ir_codes_opera1_table); i++) {
408 if (rc5_scan(&ir_codes_opera1_table[i]) == (send_key & 0xffff)) { 408 if (rc5_scan(&ir_codes_opera1_table[i]) == (send_key & 0xffff)) {
409 *state = REMOTE_KEY_PRESSED; 409 *state = REMOTE_KEY_PRESSED;
410 *event = ir_codes_opera1_table[i].event; 410 *event = ir_codes_opera1_table[i].keycode;
411 opst->last_key_pressed = 411 opst->last_key_pressed =
412 ir_codes_opera1_table[i].event; 412 ir_codes_opera1_table[i].keycode;
413 break; 413 break;
414 } 414 }
415 opst->last_key_pressed = 0; 415 opst->last_key_pressed = 0;
@@ -498,10 +498,12 @@ static struct dvb_usb_device_properties opera1_properties = {
498 .power_ctrl = opera1_power_ctrl, 498 .power_ctrl = opera1_power_ctrl,
499 .i2c_algo = &opera1_i2c_algo, 499 .i2c_algo = &opera1_i2c_algo,
500 500
501 .rc_key_map = ir_codes_opera1_table, 501 .rc.legacy = {
502 .rc_key_map_size = ARRAY_SIZE(ir_codes_opera1_table), 502 .rc_key_map = ir_codes_opera1_table,
503 .rc_interval = 200, 503 .rc_key_map_size = ARRAY_SIZE(ir_codes_opera1_table),
504 .rc_query = opera1_rc_query, 504 .rc_interval = 200,
505 .rc_query = opera1_rc_query,
506 },
505 .read_mac_address = opera1_read_mac_address, 507 .read_mac_address = opera1_read_mac_address,
506 .generic_bulk_ctrl_endpoint = 0x00, 508 .generic_bulk_ctrl_endpoint = 0x00,
507 /* parameter for the MPEG2-data transfer */ 509 /* parameter for the MPEG2-data transfer */
diff --git a/drivers/media/dvb/dvb-usb/vp702x.c b/drivers/media/dvb/dvb-usb/vp702x.c
index 4d332451653b..5c9f3275aaa0 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 dvb_usb_rc_key ir_codes_vp702x_table[] = { 177static struct ir_scancode ir_codes_vp702x_table[] = {
178 { 0x0001, KEY_1 }, 178 { 0x0001, KEY_1 },
179 { 0x0002, KEY_2 }, 179 { 0x0002, KEY_2 },
180}; 180};
@@ -200,7 +200,7 @@ static int vp702x_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
200 for (i = 0; i < ARRAY_SIZE(ir_codes_vp702x_table); i++) 200 for (i = 0; i < ARRAY_SIZE(ir_codes_vp702x_table); i++)
201 if (rc5_custom(&ir_codes_vp702x_table[i]) == key[1]) { 201 if (rc5_custom(&ir_codes_vp702x_table[i]) == key[1]) {
202 *state = REMOTE_KEY_PRESSED; 202 *state = REMOTE_KEY_PRESSED;
203 *event = ir_codes_vp702x_table[i].event; 203 *event = ir_codes_vp702x_table[i].keycode;
204 break; 204 break;
205 } 205 }
206 return 0; 206 return 0;
@@ -283,10 +283,12 @@ static struct dvb_usb_device_properties vp702x_properties = {
283 }, 283 },
284 .read_mac_address = vp702x_read_mac_addr, 284 .read_mac_address = vp702x_read_mac_addr,
285 285
286 .rc_key_map = ir_codes_vp702x_table, 286 .rc.legacy = {
287 .rc_key_map_size = ARRAY_SIZE(ir_codes_vp702x_table), 287 .rc_key_map = ir_codes_vp702x_table,
288 .rc_interval = 400, 288 .rc_key_map_size = ARRAY_SIZE(ir_codes_vp702x_table),
289 .rc_query = vp702x_rc_query, 289 .rc_interval = 400,
290 .rc_query = vp702x_rc_query,
291 },
290 292
291 .num_device_descs = 1, 293 .num_device_descs = 1,
292 .devices = { 294 .devices = {
diff --git a/drivers/media/dvb/dvb-usb/vp7045.c b/drivers/media/dvb/dvb-usb/vp7045.c
index 036893fa4480..f13791ca5994 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 dvb_usb_rc_key ir_codes_vp7045_table[] = { 102static struct ir_scancode ir_codes_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 },
@@ -168,7 +168,7 @@ static int vp7045_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
168 for (i = 0; i < ARRAY_SIZE(ir_codes_vp7045_table); i++) 168 for (i = 0; i < ARRAY_SIZE(ir_codes_vp7045_table); i++)
169 if (rc5_data(&ir_codes_vp7045_table[i]) == key) { 169 if (rc5_data(&ir_codes_vp7045_table[i]) == key) {
170 *state = REMOTE_KEY_PRESSED; 170 *state = REMOTE_KEY_PRESSED;
171 *event = ir_codes_vp7045_table[i].event; 171 *event = ir_codes_vp7045_table[i].keycode;
172 break; 172 break;
173 } 173 }
174 return 0; 174 return 0;
@@ -259,10 +259,12 @@ static struct dvb_usb_device_properties vp7045_properties = {
259 .power_ctrl = vp7045_power_ctrl, 259 .power_ctrl = vp7045_power_ctrl,
260 .read_mac_address = vp7045_read_mac_addr, 260 .read_mac_address = vp7045_read_mac_addr,
261 261
262 .rc_interval = 400, 262 .rc.legacy = {
263 .rc_key_map = ir_codes_vp7045_table, 263 .rc_interval = 400,
264 .rc_key_map_size = ARRAY_SIZE(ir_codes_vp7045_table), 264 .rc_key_map = ir_codes_vp7045_table,
265 .rc_query = vp7045_rc_query, 265 .rc_key_map_size = ARRAY_SIZE(ir_codes_vp7045_table),
266 .rc_query = vp7045_rc_query,
267 },
266 268
267 .num_device_descs = 2, 269 .num_device_descs = 2,
268 .devices = { 270 .devices = {
diff --git a/drivers/media/dvb/frontends/Kconfig b/drivers/media/dvb/frontends/Kconfig
index cd7f9b7cbffa..51d578a758a7 100644
--- a/drivers/media/dvb/frontends/Kconfig
+++ b/drivers/media/dvb/frontends/Kconfig
@@ -584,6 +584,7 @@ config DVB_LGS8GL5
584config DVB_LGS8GXX 584config DVB_LGS8GXX
585 tristate "Legend Silicon LGS8913/LGS8GL5/LGS8GXX DMB-TH demodulator" 585 tristate "Legend Silicon LGS8913/LGS8GL5/LGS8GXX DMB-TH demodulator"
586 depends on DVB_CORE && I2C 586 depends on DVB_CORE && I2C
587 select FW_LOADER
587 default m if DVB_FE_CUSTOMISE 588 default m if DVB_FE_CUSTOMISE
588 help 589 help
589 A DMB-TH tuner module. Say Y when you want to support this frontend. 590 A DMB-TH tuner module. Say Y when you want to support this frontend.
diff --git a/drivers/media/dvb/frontends/af9013.c b/drivers/media/dvb/frontends/af9013.c
index 12e018b4107d..dac917f7bb7f 100644
--- a/drivers/media/dvb/frontends/af9013.c
+++ b/drivers/media/dvb/frontends/af9013.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * DVB USB Linux driver for Afatech AF9015 DVB-T USB2.0 receiver 2 * Afatech AF9013 demodulator driver
3 * 3 *
4 * Copyright (C) 2007 Antti Palosaari <crope@iki.fi> 4 * Copyright (C) 2007 Antti Palosaari <crope@iki.fi>
5 * 5 *
@@ -761,6 +761,10 @@ static int af9013_set_frontend(struct dvb_frontend *fe,
761 761
762 state->frequency = params->frequency; 762 state->frequency = params->frequency;
763 763
764 /* program tuner */
765 if (fe->ops.tuner_ops.set_params)
766 fe->ops.tuner_ops.set_params(fe, params);
767
764 /* program CFOE coefficients */ 768 /* program CFOE coefficients */
765 ret = af9013_set_coeff(state, params->u.ofdm.bandwidth); 769 ret = af9013_set_coeff(state, params->u.ofdm.bandwidth);
766 if (ret) 770 if (ret)
@@ -791,10 +795,6 @@ static int af9013_set_frontend(struct dvb_frontend *fe,
791 if (ret) 795 if (ret)
792 goto error; 796 goto error;
793 797
794 /* program tuner */
795 if (fe->ops.tuner_ops.set_params)
796 fe->ops.tuner_ops.set_params(fe, params);
797
798 /* program TPS and bandwidth, check if auto mode needed */ 798 /* program TPS and bandwidth, check if auto mode needed */
799 ret = af9013_set_ofdm_params(state, &params->u.ofdm, &auto_mode); 799 ret = af9013_set_ofdm_params(state, &params->u.ofdm, &auto_mode);
800 if (ret) 800 if (ret)
@@ -1184,45 +1184,49 @@ static int af9013_read_status(struct dvb_frontend *fe, fe_status_t *status)
1184 u8 tmp; 1184 u8 tmp;
1185 *status = 0; 1185 *status = 0;
1186 1186
1187 /* TPS lock */
1188 ret = af9013_read_reg_bits(state, 0xd330, 3, 1, &tmp);
1189 if (ret)
1190 goto error;
1191 if (tmp)
1192 *status |= FE_HAS_VITERBI | FE_HAS_CARRIER | FE_HAS_SIGNAL;
1193
1194 /* MPEG2 lock */ 1187 /* MPEG2 lock */
1195 ret = af9013_read_reg_bits(state, 0xd507, 6, 1, &tmp); 1188 ret = af9013_read_reg_bits(state, 0xd507, 6, 1, &tmp);
1196 if (ret) 1189 if (ret)
1197 goto error; 1190 goto error;
1198 if (tmp) 1191 if (tmp)
1199 *status |= FE_HAS_SYNC | FE_HAS_LOCK; 1192 *status |= FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_VITERBI |
1193 FE_HAS_SYNC | FE_HAS_LOCK;
1200 1194
1201 if (!(*status & FE_HAS_SIGNAL)) { 1195 if (!*status) {
1202 /* AGC lock */ 1196 /* TPS lock */
1203 ret = af9013_read_reg_bits(state, 0xd1a0, 6, 1, &tmp); 1197 ret = af9013_read_reg_bits(state, 0xd330, 3, 1, &tmp);
1204 if (ret) 1198 if (ret)
1205 goto error; 1199 goto error;
1206 if (tmp) 1200 if (tmp)
1207 *status |= FE_HAS_SIGNAL; 1201 *status |= FE_HAS_SIGNAL | FE_HAS_CARRIER |
1202 FE_HAS_VITERBI;
1208 } 1203 }
1209 1204
1210 if (!(*status & FE_HAS_CARRIER)) { 1205 if (!*status) {
1211 /* CFO lock */ 1206 /* CFO lock */
1212 ret = af9013_read_reg_bits(state, 0xd333, 7, 1, &tmp); 1207 ret = af9013_read_reg_bits(state, 0xd333, 7, 1, &tmp);
1213 if (ret) 1208 if (ret)
1214 goto error; 1209 goto error;
1215 if (tmp) 1210 if (tmp)
1216 *status |= FE_HAS_CARRIER; 1211 *status |= FE_HAS_SIGNAL | FE_HAS_CARRIER;
1217 } 1212 }
1218 1213
1219 if (!(*status & FE_HAS_CARRIER)) { 1214 if (!*status) {
1220 /* SFOE lock */ 1215 /* SFOE lock */
1221 ret = af9013_read_reg_bits(state, 0xd334, 6, 1, &tmp); 1216 ret = af9013_read_reg_bits(state, 0xd334, 6, 1, &tmp);
1222 if (ret) 1217 if (ret)
1223 goto error; 1218 goto error;
1224 if (tmp) 1219 if (tmp)
1225 *status |= FE_HAS_CARRIER; 1220 *status |= FE_HAS_SIGNAL | FE_HAS_CARRIER;
1221 }
1222
1223 if (!*status) {
1224 /* AGC lock */
1225 ret = af9013_read_reg_bits(state, 0xd1a0, 6, 1, &tmp);
1226 if (ret)
1227 goto error;
1228 if (tmp)
1229 *status |= FE_HAS_SIGNAL;
1226 } 1230 }
1227 1231
1228 ret = af9013_update_statistics(fe); 1232 ret = af9013_update_statistics(fe);
@@ -1574,7 +1578,7 @@ struct dvb_frontend *af9013_attach(const struct af9013_config *config,
1574{ 1578{
1575 int ret; 1579 int ret;
1576 struct af9013_state *state = NULL; 1580 struct af9013_state *state = NULL;
1577 u8 buf[3], i; 1581 u8 buf[4], i;
1578 1582
1579 /* allocate memory for the internal state */ 1583 /* allocate memory for the internal state */
1580 state = kzalloc(sizeof(struct af9013_state), GFP_KERNEL); 1584 state = kzalloc(sizeof(struct af9013_state), GFP_KERNEL);
@@ -1607,12 +1611,12 @@ struct dvb_frontend *af9013_attach(const struct af9013_config *config,
1607 } 1611 }
1608 1612
1609 /* firmware version */ 1613 /* firmware version */
1610 for (i = 0; i < 3; i++) { 1614 for (i = 0; i < 4; i++) {
1611 ret = af9013_read_reg(state, 0x5103 + i, &buf[i]); 1615 ret = af9013_read_reg(state, 0x5103 + i, &buf[i]);
1612 if (ret) 1616 if (ret)
1613 goto error; 1617 goto error;
1614 } 1618 }
1615 info("firmware version:%d.%d.%d", buf[0], buf[1], buf[2]); 1619 info("firmware version:%d.%d.%d.%d", buf[0], buf[1], buf[2], buf[3]);
1616 1620
1617 /* settings for mp2if */ 1621 /* settings for mp2if */
1618 if (state->config.output_mode == AF9013_OUTPUT_MODE_USB) { 1622 if (state->config.output_mode == AF9013_OUTPUT_MODE_USB) {
diff --git a/drivers/media/dvb/frontends/af9013.h b/drivers/media/dvb/frontends/af9013.h
index e90fa92b1c1d..72c71bb5d117 100644
--- a/drivers/media/dvb/frontends/af9013.h
+++ b/drivers/media/dvb/frontends/af9013.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * DVB USB Linux driver for Afatech AF9015 DVB-T USB2.0 receiver 2 * Afatech AF9013 demodulator driver
3 * 3 *
4 * Copyright (C) 2007 Antti Palosaari <crope@iki.fi> 4 * Copyright (C) 2007 Antti Palosaari <crope@iki.fi>
5 * 5 *
diff --git a/drivers/media/dvb/frontends/af9013_priv.h b/drivers/media/dvb/frontends/af9013_priv.h
index 163e251d0b73..0fd42b7e248e 100644
--- a/drivers/media/dvb/frontends/af9013_priv.h
+++ b/drivers/media/dvb/frontends/af9013_priv.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * DVB USB Linux driver for Afatech AF9015 DVB-T USB2.0 receiver 2 * Afatech AF9013 demodulator driver
3 * 3 *
4 * Copyright (C) 2007 Antti Palosaari <crope@iki.fi> 4 * Copyright (C) 2007 Antti Palosaari <crope@iki.fi>
5 * 5 *
@@ -132,6 +132,8 @@ static struct regdesc ofsm_init[] = {
132 { 0xd740, 2, 1, 0x00 }, 132 { 0xd740, 2, 1, 0x00 },
133 { 0xd740, 3, 1, 0x01 }, 133 { 0xd740, 3, 1, 0x01 },
134 { 0xd3c1, 4, 1, 0x01 }, 134 { 0xd3c1, 4, 1, 0x01 },
135 { 0x9124, 0, 8, 0x58 },
136 { 0x9125, 0, 2, 0x02 },
135 { 0xd3a2, 0, 8, 0x00 }, 137 { 0xd3a2, 0, 8, 0x00 },
136 { 0xd3a3, 0, 8, 0x04 }, 138 { 0xd3a3, 0, 8, 0x04 },
137 { 0xd305, 0, 8, 0x32 }, 139 { 0xd305, 0, 8, 0x32 },
@@ -143,7 +145,7 @@ static struct regdesc ofsm_init[] = {
143 { 0x911b, 0, 1, 0x01 }, 145 { 0x911b, 0, 1, 0x01 },
144 { 0x9bce, 0, 4, 0x02 }, 146 { 0x9bce, 0, 4, 0x02 },
145 { 0x9116, 0, 1, 0x01 }, 147 { 0x9116, 0, 1, 0x01 },
146 { 0x9bd1, 0, 1, 0x01 }, 148 { 0x9122, 0, 8, 0xd0 },
147 { 0xd2e0, 0, 8, 0xd0 }, 149 { 0xd2e0, 0, 8, 0xd0 },
148 { 0xd2e9, 0, 4, 0x0d }, 150 { 0xd2e9, 0, 4, 0x0d },
149 { 0xd38c, 0, 8, 0xfc }, 151 { 0xd38c, 0, 8, 0xfc },
@@ -165,7 +167,6 @@ static struct regdesc ofsm_init[] = {
165 { 0xd081, 4, 4, 0x09 }, 167 { 0xd081, 4, 4, 0x09 },
166 { 0xd098, 4, 4, 0x0f }, 168 { 0xd098, 4, 4, 0x0f },
167 { 0xd098, 0, 4, 0x03 }, 169 { 0xd098, 0, 4, 0x03 },
168 { 0xdbc0, 3, 1, 0x01 },
169 { 0xdbc0, 4, 1, 0x01 }, 170 { 0xdbc0, 4, 1, 0x01 },
170 { 0xdbc7, 0, 8, 0x08 }, 171 { 0xdbc7, 0, 8, 0x08 },
171 { 0xdbc8, 4, 4, 0x00 }, 172 { 0xdbc8, 4, 4, 0x00 },
@@ -179,6 +180,7 @@ static struct regdesc ofsm_init[] = {
179 { 0xd0f0, 0, 7, 0x1a }, 180 { 0xd0f0, 0, 7, 0x1a },
180 { 0xd0f1, 4, 1, 0x01 }, 181 { 0xd0f1, 4, 1, 0x01 },
181 { 0xd0f2, 0, 8, 0x0c }, 182 { 0xd0f2, 0, 8, 0x0c },
183 { 0xd101, 5, 3, 0x06 },
182 { 0xd103, 0, 4, 0x08 }, 184 { 0xd103, 0, 4, 0x08 },
183 { 0xd0f8, 0, 7, 0x20 }, 185 { 0xd0f8, 0, 7, 0x20 },
184 { 0xd111, 5, 1, 0x00 }, 186 { 0xd111, 5, 1, 0x00 },
diff --git a/drivers/media/dvb/frontends/dib3000mb.c b/drivers/media/dvb/frontends/dib3000mb.c
index ad4c8cfd8090..e80c59796368 100644
--- a/drivers/media/dvb/frontends/dib3000mb.c
+++ b/drivers/media/dvb/frontends/dib3000mb.c
@@ -38,11 +38,10 @@
38#define DRIVER_DESC "DiBcom 3000M-B DVB-T demodulator" 38#define DRIVER_DESC "DiBcom 3000M-B DVB-T demodulator"
39#define DRIVER_AUTHOR "Patrick Boettcher, patrick.boettcher@desy.de" 39#define DRIVER_AUTHOR "Patrick Boettcher, patrick.boettcher@desy.de"
40 40
41#ifdef CONFIG_DVB_DIBCOM_DEBUG
42static int debug; 41static int debug;
43module_param(debug, int, 0644); 42module_param(debug, int, 0644);
44MODULE_PARM_DESC(debug, "set debugging level (1=info,2=xfer,4=setfe,8=getfe (|-able))."); 43MODULE_PARM_DESC(debug, "set debugging level (1=info,2=xfer,4=setfe,8=getfe (|-able)).");
45#endif 44
46#define deb_info(args...) dprintk(0x01,args) 45#define deb_info(args...) dprintk(0x01,args)
47#define deb_i2c(args...) dprintk(0x02,args) 46#define deb_i2c(args...) dprintk(0x02,args)
48#define deb_srch(args...) dprintk(0x04,args) 47#define deb_srch(args...) dprintk(0x04,args)
@@ -51,12 +50,6 @@ MODULE_PARM_DESC(debug, "set debugging level (1=info,2=xfer,4=setfe,8=getfe (|-a
51#define deb_setf(args...) dprintk(0x04,args) 50#define deb_setf(args...) dprintk(0x04,args)
52#define deb_getf(args...) dprintk(0x08,args) 51#define deb_getf(args...) dprintk(0x08,args)
53 52
54#ifdef CONFIG_DVB_DIBCOM_DEBUG
55static int debug;
56module_param(debug, int, 0644);
57MODULE_PARM_DESC(debug, "set debugging level (1=info,2=i2c,4=srch (|-able)).");
58#endif
59
60static int dib3000_read_reg(struct dib3000_state *state, u16 reg) 53static int dib3000_read_reg(struct dib3000_state *state, u16 reg)
61{ 54{
62 u8 wb[] = { ((reg >> 8) | 0x80) & 0xff, reg & 0xff }; 55 u8 wb[] = { ((reg >> 8) | 0x80) & 0xff, reg & 0xff };
diff --git a/drivers/media/dvb/frontends/dib3000mb_priv.h b/drivers/media/dvb/frontends/dib3000mb_priv.h
index 1a12747fdc91..16c526591f36 100644
--- a/drivers/media/dvb/frontends/dib3000mb_priv.h
+++ b/drivers/media/dvb/frontends/dib3000mb_priv.h
@@ -37,12 +37,8 @@
37 37
38/* debug */ 38/* debug */
39 39
40#ifdef CONFIG_DVB_DIBCOM_DEBUG
41#define dprintk(level,args...) \ 40#define dprintk(level,args...) \
42 do { if ((debug & level)) { printk(args); } } while (0) 41 do { if ((debug & level)) { printk(args); } } while (0)
43#else
44#define dprintk(args...) do { } while (0)
45#endif
46 42
47/* mask for enabling a specific pid for the pid_filter */ 43/* mask for enabling a specific pid for the pid_filter */
48#define DIB3000_ACTIVATE_PID_FILTERING (0x2000) 44#define DIB3000_ACTIVATE_PID_FILTERING (0x2000)
diff --git a/drivers/media/dvb/frontends/dib3000mc.c b/drivers/media/dvb/frontends/dib3000mc.c
index afad252abf41..088e7fadbe3d 100644
--- a/drivers/media/dvb/frontends/dib3000mc.c
+++ b/drivers/media/dvb/frontends/dib3000mc.c
@@ -822,7 +822,7 @@ int dib3000mc_i2c_enumeration(struct i2c_adapter *i2c, int no_of_demods, u8 defa
822 822
823 dmcst = kzalloc(sizeof(struct dib3000mc_state), GFP_KERNEL); 823 dmcst = kzalloc(sizeof(struct dib3000mc_state), GFP_KERNEL);
824 if (dmcst == NULL) 824 if (dmcst == NULL)
825 return -ENODEV; 825 return -ENOMEM;
826 826
827 dmcst->i2c_adap = i2c; 827 dmcst->i2c_adap = i2c;
828 828
diff --git a/drivers/media/dvb/frontends/lgdt3305.c b/drivers/media/dvb/frontends/lgdt3305.c
index d69c775f8645..3272881cb112 100644
--- a/drivers/media/dvb/frontends/lgdt3305.c
+++ b/drivers/media/dvb/frontends/lgdt3305.c
@@ -1,7 +1,9 @@
1/* 1/*
2 * Support for LGDT3305 - VSB/QAM 2 * Support for LG Electronics LGDT3304 and LGDT3305 - VSB/QAM
3 * 3 *
4 * Copyright (C) 2008, 2009 Michael Krufky <mkrufky@linuxtv.org> 4 * Copyright (C) 2008, 2009, 2010 Michael Krufky <mkrufky@linuxtv.org>
5 *
6 * LGDT3304 support by Jarod Wilson <jarod@redhat.com>
5 * 7 *
6 * This program is free software; you can redistribute it and/or modify 8 * 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 9 * it under the terms of the GNU General Public License as published by
@@ -65,6 +67,8 @@ struct lgdt3305_state {
65 67
66/* ------------------------------------------------------------------------ */ 68/* ------------------------------------------------------------------------ */
67 69
70/* FIXME: verify & document the LGDT3304 registers */
71
68#define LGDT3305_GEN_CTRL_1 0x0000 72#define LGDT3305_GEN_CTRL_1 0x0000
69#define LGDT3305_GEN_CTRL_2 0x0001 73#define LGDT3305_GEN_CTRL_2 0x0001
70#define LGDT3305_GEN_CTRL_3 0x0002 74#define LGDT3305_GEN_CTRL_3 0x0002
@@ -358,7 +362,12 @@ static int lgdt3305_rfagc_loop(struct lgdt3305_state *state,
358 case QAM_256: 362 case QAM_256:
359 agcdelay = 0x046b; 363 agcdelay = 0x046b;
360 rfbw = 0x8889; 364 rfbw = 0x8889;
361 ifbw = 0x8888; 365 /* FIXME: investigate optimal ifbw & rfbw values for the
366 * DT3304 and re-write this switch..case block */
367 if (state->cfg->demod_chip == LGDT3304)
368 ifbw = 0x6666;
369 else /* (state->cfg->demod_chip == LGDT3305) */
370 ifbw = 0x8888;
362 break; 371 break;
363 default: 372 default:
364 return -EINVAL; 373 return -EINVAL;
@@ -410,8 +419,18 @@ static int lgdt3305_agc_setup(struct lgdt3305_state *state,
410 lg_dbg("lockdten = %d, acqen = %d\n", lockdten, acqen); 419 lg_dbg("lockdten = %d, acqen = %d\n", lockdten, acqen);
411 420
412 /* control agc function */ 421 /* control agc function */
413 lgdt3305_write_reg(state, LGDT3305_AGC_CTRL_4, 0xe1 | lockdten << 1); 422 switch (state->cfg->demod_chip) {
414 lgdt3305_set_reg_bit(state, LGDT3305_AGC_CTRL_1, 2, acqen); 423 case LGDT3304:
424 lgdt3305_write_reg(state, 0x0314, 0xe1 | lockdten << 1);
425 lgdt3305_set_reg_bit(state, 0x030e, 2, acqen);
426 break;
427 case LGDT3305:
428 lgdt3305_write_reg(state, LGDT3305_AGC_CTRL_4, 0xe1 | lockdten << 1);
429 lgdt3305_set_reg_bit(state, LGDT3305_AGC_CTRL_1, 2, acqen);
430 break;
431 default:
432 return -EINVAL;
433 }
415 434
416 return lgdt3305_rfagc_loop(state, param); 435 return lgdt3305_rfagc_loop(state, param);
417} 436}
@@ -577,61 +596,79 @@ static int lgdt3305_init(struct dvb_frontend *fe)
577 struct lgdt3305_state *state = fe->demodulator_priv; 596 struct lgdt3305_state *state = fe->demodulator_priv;
578 int ret; 597 int ret;
579 598
599 static struct lgdt3305_reg lgdt3304_init_data[] = {
600 { .reg = LGDT3305_GEN_CTRL_1, .val = 0x03, },
601 { .reg = 0x000d, .val = 0x02, },
602 { .reg = 0x000e, .val = 0x02, },
603 { .reg = LGDT3305_DGTL_AGC_REF_1, .val = 0x32, },
604 { .reg = LGDT3305_DGTL_AGC_REF_2, .val = 0xc4, },
605 { .reg = LGDT3305_CR_CTR_FREQ_1, .val = 0x00, },
606 { .reg = LGDT3305_CR_CTR_FREQ_2, .val = 0x00, },
607 { .reg = LGDT3305_CR_CTR_FREQ_3, .val = 0x00, },
608 { .reg = LGDT3305_CR_CTR_FREQ_4, .val = 0x00, },
609 { .reg = LGDT3305_CR_CTRL_7, .val = 0xf9, },
610 { .reg = 0x0112, .val = 0x17, },
611 { .reg = 0x0113, .val = 0x15, },
612 { .reg = 0x0114, .val = 0x18, },
613 { .reg = 0x0115, .val = 0xff, },
614 { .reg = 0x0116, .val = 0x3c, },
615 { .reg = 0x0214, .val = 0x67, },
616 { .reg = 0x0424, .val = 0x8d, },
617 { .reg = 0x0427, .val = 0x12, },
618 { .reg = 0x0428, .val = 0x4f, },
619 { .reg = LGDT3305_IFBW_1, .val = 0x80, },
620 { .reg = LGDT3305_IFBW_2, .val = 0x00, },
621 { .reg = 0x030a, .val = 0x08, },
622 { .reg = 0x030b, .val = 0x9b, },
623 { .reg = 0x030d, .val = 0x00, },
624 { .reg = 0x030e, .val = 0x1c, },
625 { .reg = 0x0314, .val = 0xe1, },
626 { .reg = 0x000d, .val = 0x82, },
627 { .reg = LGDT3305_TP_CTRL_1, .val = 0x5b, },
628 { .reg = LGDT3305_TP_CTRL_1, .val = 0x5b, },
629 };
630
580 static struct lgdt3305_reg lgdt3305_init_data[] = { 631 static struct lgdt3305_reg lgdt3305_init_data[] = {
581 { .reg = LGDT3305_GEN_CTRL_1, 632 { .reg = LGDT3305_GEN_CTRL_1, .val = 0x03, },
582 .val = 0x03, }, 633 { .reg = LGDT3305_GEN_CTRL_2, .val = 0xb0, },
583 { .reg = LGDT3305_GEN_CTRL_2, 634 { .reg = LGDT3305_GEN_CTRL_3, .val = 0x01, },
584 .val = 0xb0, }, 635 { .reg = LGDT3305_GEN_CONTROL, .val = 0x6f, },
585 { .reg = LGDT3305_GEN_CTRL_3, 636 { .reg = LGDT3305_GEN_CTRL_4, .val = 0x03, },
586 .val = 0x01, }, 637 { .reg = LGDT3305_DGTL_AGC_REF_1, .val = 0x32, },
587 { .reg = LGDT3305_GEN_CONTROL, 638 { .reg = LGDT3305_DGTL_AGC_REF_2, .val = 0xc4, },
588 .val = 0x6f, }, 639 { .reg = LGDT3305_CR_CTR_FREQ_1, .val = 0x00, },
589 { .reg = LGDT3305_GEN_CTRL_4, 640 { .reg = LGDT3305_CR_CTR_FREQ_2, .val = 0x00, },
590 .val = 0x03, }, 641 { .reg = LGDT3305_CR_CTR_FREQ_3, .val = 0x00, },
591 { .reg = LGDT3305_DGTL_AGC_REF_1, 642 { .reg = LGDT3305_CR_CTR_FREQ_4, .val = 0x00, },
592 .val = 0x32, }, 643 { .reg = LGDT3305_CR_CTRL_7, .val = 0x79, },
593 { .reg = LGDT3305_DGTL_AGC_REF_2, 644 { .reg = LGDT3305_AGC_POWER_REF_1, .val = 0x32, },
594 .val = 0xc4, }, 645 { .reg = LGDT3305_AGC_POWER_REF_2, .val = 0xc4, },
595 { .reg = LGDT3305_CR_CTR_FREQ_1, 646 { .reg = LGDT3305_AGC_DELAY_PT_1, .val = 0x0d, },
596 .val = 0x00, }, 647 { .reg = LGDT3305_AGC_DELAY_PT_2, .val = 0x30, },
597 { .reg = LGDT3305_CR_CTR_FREQ_2, 648 { .reg = LGDT3305_RFAGC_LOOP_FLTR_BW_1, .val = 0x80, },
598 .val = 0x00, }, 649 { .reg = LGDT3305_RFAGC_LOOP_FLTR_BW_2, .val = 0x00, },
599 { .reg = LGDT3305_CR_CTR_FREQ_3, 650 { .reg = LGDT3305_IFBW_1, .val = 0x80, },
600 .val = 0x00, }, 651 { .reg = LGDT3305_IFBW_2, .val = 0x00, },
601 { .reg = LGDT3305_CR_CTR_FREQ_4, 652 { .reg = LGDT3305_AGC_CTRL_1, .val = 0x30, },
602 .val = 0x00, }, 653 { .reg = LGDT3305_AGC_CTRL_4, .val = 0x61, },
603 { .reg = LGDT3305_CR_CTRL_7, 654 { .reg = LGDT3305_FEC_BLOCK_CTRL, .val = 0xff, },
604 .val = 0x79, }, 655 { .reg = LGDT3305_TP_CTRL_1, .val = 0x1b, },
605 { .reg = LGDT3305_AGC_POWER_REF_1,
606 .val = 0x32, },
607 { .reg = LGDT3305_AGC_POWER_REF_2,
608 .val = 0xc4, },
609 { .reg = LGDT3305_AGC_DELAY_PT_1,
610 .val = 0x0d, },
611 { .reg = LGDT3305_AGC_DELAY_PT_2,
612 .val = 0x30, },
613 { .reg = LGDT3305_RFAGC_LOOP_FLTR_BW_1,
614 .val = 0x80, },
615 { .reg = LGDT3305_RFAGC_LOOP_FLTR_BW_2,
616 .val = 0x00, },
617 { .reg = LGDT3305_IFBW_1,
618 .val = 0x80, },
619 { .reg = LGDT3305_IFBW_2,
620 .val = 0x00, },
621 { .reg = LGDT3305_AGC_CTRL_1,
622 .val = 0x30, },
623 { .reg = LGDT3305_AGC_CTRL_4,
624 .val = 0x61, },
625 { .reg = LGDT3305_FEC_BLOCK_CTRL,
626 .val = 0xff, },
627 { .reg = LGDT3305_TP_CTRL_1,
628 .val = 0x1b, },
629 }; 656 };
630 657
631 lg_dbg("\n"); 658 lg_dbg("\n");
632 659
633 ret = lgdt3305_write_regs(state, lgdt3305_init_data, 660 switch (state->cfg->demod_chip) {
634 ARRAY_SIZE(lgdt3305_init_data)); 661 case LGDT3304:
662 ret = lgdt3305_write_regs(state, lgdt3304_init_data,
663 ARRAY_SIZE(lgdt3304_init_data));
664 break;
665 case LGDT3305:
666 ret = lgdt3305_write_regs(state, lgdt3305_init_data,
667 ARRAY_SIZE(lgdt3305_init_data));
668 break;
669 default:
670 ret = -EINVAL;
671 }
635 if (lg_fail(ret)) 672 if (lg_fail(ret))
636 goto fail; 673 goto fail;
637 674
@@ -640,6 +677,76 @@ fail:
640 return ret; 677 return ret;
641} 678}
642 679
680static int lgdt3304_set_parameters(struct dvb_frontend *fe,
681 struct dvb_frontend_parameters *param)
682{
683 struct lgdt3305_state *state = fe->demodulator_priv;
684 int ret;
685
686 lg_dbg("(%d, %d)\n", param->frequency, param->u.vsb.modulation);
687
688 if (fe->ops.tuner_ops.set_params) {
689 ret = fe->ops.tuner_ops.set_params(fe, param);
690 if (fe->ops.i2c_gate_ctrl)
691 fe->ops.i2c_gate_ctrl(fe, 0);
692 if (lg_fail(ret))
693 goto fail;
694 state->current_frequency = param->frequency;
695 }
696
697 ret = lgdt3305_set_modulation(state, param);
698 if (lg_fail(ret))
699 goto fail;
700
701 ret = lgdt3305_passband_digital_agc(state, param);
702 if (lg_fail(ret))
703 goto fail;
704
705 ret = lgdt3305_agc_setup(state, param);
706 if (lg_fail(ret))
707 goto fail;
708
709 /* reg 0x030d is 3304-only... seen in vsb and qam usbsnoops... */
710 switch (param->u.vsb.modulation) {
711 case VSB_8:
712 lgdt3305_write_reg(state, 0x030d, 0x00);
713 lgdt3305_write_reg(state, LGDT3305_CR_CTR_FREQ_1, 0x4f);
714 lgdt3305_write_reg(state, LGDT3305_CR_CTR_FREQ_2, 0x0c);
715 lgdt3305_write_reg(state, LGDT3305_CR_CTR_FREQ_3, 0xac);
716 lgdt3305_write_reg(state, LGDT3305_CR_CTR_FREQ_4, 0xba);
717 break;
718 case QAM_64:
719 case QAM_256:
720 lgdt3305_write_reg(state, 0x030d, 0x14);
721 ret = lgdt3305_set_if(state, param);
722 if (lg_fail(ret))
723 goto fail;
724 break;
725 default:
726 return -EINVAL;
727 }
728
729
730 ret = lgdt3305_spectral_inversion(state, param,
731 state->cfg->spectral_inversion
732 ? 1 : 0);
733 if (lg_fail(ret))
734 goto fail;
735
736 state->current_modulation = param->u.vsb.modulation;
737
738 ret = lgdt3305_mpeg_mode(state, state->cfg->mpeg_mode);
739 if (lg_fail(ret))
740 goto fail;
741
742 /* lgdt3305_mpeg_mode_polarity calls lgdt3305_soft_reset */
743 ret = lgdt3305_mpeg_mode_polarity(state,
744 state->cfg->tpclk_edge,
745 state->cfg->tpvalid_polarity);
746fail:
747 return ret;
748}
749
643static int lgdt3305_set_parameters(struct dvb_frontend *fe, 750static int lgdt3305_set_parameters(struct dvb_frontend *fe,
644 struct dvb_frontend_parameters *param) 751 struct dvb_frontend_parameters *param)
645{ 752{
@@ -848,6 +955,10 @@ static int lgdt3305_read_status(struct dvb_frontend *fe, fe_status_t *status)
848 switch (state->current_modulation) { 955 switch (state->current_modulation) {
849 case QAM_256: 956 case QAM_256:
850 case QAM_64: 957 case QAM_64:
958 /* signal bit is unreliable on the DT3304 in QAM mode */
959 if (((LGDT3304 == state->cfg->demod_chip)) && (cr_lock))
960 *status |= FE_HAS_SIGNAL;
961
851 ret = lgdt3305_read_fec_lock_status(state, &fec_lock); 962 ret = lgdt3305_read_fec_lock_status(state, &fec_lock);
852 if (lg_fail(ret)) 963 if (lg_fail(ret))
853 goto fail; 964 goto fail;
@@ -993,6 +1104,7 @@ static void lgdt3305_release(struct dvb_frontend *fe)
993 kfree(state); 1104 kfree(state);
994} 1105}
995 1106
1107static struct dvb_frontend_ops lgdt3304_ops;
996static struct dvb_frontend_ops lgdt3305_ops; 1108static struct dvb_frontend_ops lgdt3305_ops;
997 1109
998struct dvb_frontend *lgdt3305_attach(const struct lgdt3305_config *config, 1110struct dvb_frontend *lgdt3305_attach(const struct lgdt3305_config *config,
@@ -1013,11 +1125,21 @@ struct dvb_frontend *lgdt3305_attach(const struct lgdt3305_config *config,
1013 state->cfg = config; 1125 state->cfg = config;
1014 state->i2c_adap = i2c_adap; 1126 state->i2c_adap = i2c_adap;
1015 1127
1016 memcpy(&state->frontend.ops, &lgdt3305_ops, 1128 switch (config->demod_chip) {
1017 sizeof(struct dvb_frontend_ops)); 1129 case LGDT3304:
1130 memcpy(&state->frontend.ops, &lgdt3304_ops,
1131 sizeof(struct dvb_frontend_ops));
1132 break;
1133 case LGDT3305:
1134 memcpy(&state->frontend.ops, &lgdt3305_ops,
1135 sizeof(struct dvb_frontend_ops));
1136 break;
1137 default:
1138 goto fail;
1139 }
1018 state->frontend.demodulator_priv = state; 1140 state->frontend.demodulator_priv = state;
1019 1141
1020 /* verify that we're talking to a lg dt3305 */ 1142 /* verify that we're talking to a lg dt3304/5 */
1021 ret = lgdt3305_read_reg(state, LGDT3305_GEN_CTRL_2, &val); 1143 ret = lgdt3305_read_reg(state, LGDT3305_GEN_CTRL_2, &val);
1022 if ((lg_fail(ret)) | (val == 0)) 1144 if ((lg_fail(ret)) | (val == 0))
1023 goto fail; 1145 goto fail;
@@ -1036,12 +1158,35 @@ struct dvb_frontend *lgdt3305_attach(const struct lgdt3305_config *config,
1036 1158
1037 return &state->frontend; 1159 return &state->frontend;
1038fail: 1160fail:
1039 lg_warn("unable to detect LGDT3305 hardware\n"); 1161 lg_warn("unable to detect %s hardware\n",
1162 config->demod_chip ? "LGDT3304" : "LGDT3305");
1040 kfree(state); 1163 kfree(state);
1041 return NULL; 1164 return NULL;
1042} 1165}
1043EXPORT_SYMBOL(lgdt3305_attach); 1166EXPORT_SYMBOL(lgdt3305_attach);
1044 1167
1168static struct dvb_frontend_ops lgdt3304_ops = {
1169 .info = {
1170 .name = "LG Electronics LGDT3304 VSB/QAM Frontend",
1171 .type = FE_ATSC,
1172 .frequency_min = 54000000,
1173 .frequency_max = 858000000,
1174 .frequency_stepsize = 62500,
1175 .caps = FE_CAN_QAM_64 | FE_CAN_QAM_256 | FE_CAN_8VSB
1176 },
1177 .i2c_gate_ctrl = lgdt3305_i2c_gate_ctrl,
1178 .init = lgdt3305_init,
1179 .set_frontend = lgdt3304_set_parameters,
1180 .get_frontend = lgdt3305_get_frontend,
1181 .get_tune_settings = lgdt3305_get_tune_settings,
1182 .read_status = lgdt3305_read_status,
1183 .read_ber = lgdt3305_read_ber,
1184 .read_signal_strength = lgdt3305_read_signal_strength,
1185 .read_snr = lgdt3305_read_snr,
1186 .read_ucblocks = lgdt3305_read_ucblocks,
1187 .release = lgdt3305_release,
1188};
1189
1045static struct dvb_frontend_ops lgdt3305_ops = { 1190static struct dvb_frontend_ops lgdt3305_ops = {
1046 .info = { 1191 .info = {
1047 .name = "LG Electronics LGDT3305 VSB/QAM Frontend", 1192 .name = "LG Electronics LGDT3305 VSB/QAM Frontend",
@@ -1065,10 +1210,10 @@ static struct dvb_frontend_ops lgdt3305_ops = {
1065 .release = lgdt3305_release, 1210 .release = lgdt3305_release,
1066}; 1211};
1067 1212
1068MODULE_DESCRIPTION("LG Electronics LGDT3305 ATSC/QAM-B Demodulator Driver"); 1213MODULE_DESCRIPTION("LG Electronics LGDT3304/5 ATSC/QAM-B Demodulator Driver");
1069MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>"); 1214MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>");
1070MODULE_LICENSE("GPL"); 1215MODULE_LICENSE("GPL");
1071MODULE_VERSION("0.1"); 1216MODULE_VERSION("0.2");
1072 1217
1073/* 1218/*
1074 * Local variables: 1219 * Local variables:
diff --git a/drivers/media/dvb/frontends/lgdt3305.h b/drivers/media/dvb/frontends/lgdt3305.h
index 9cb11c9cae53..02172eca4d47 100644
--- a/drivers/media/dvb/frontends/lgdt3305.h
+++ b/drivers/media/dvb/frontends/lgdt3305.h
@@ -1,7 +1,7 @@
1/* 1/*
2 * Support for LGDT3305 - VSB/QAM 2 * Support for LG Electronics LGDT3304 and LGDT3305 - VSB/QAM
3 * 3 *
4 * Copyright (C) 2008, 2009 Michael Krufky <mkrufky@linuxtv.org> 4 * Copyright (C) 2008, 2009, 2010 Michael Krufky <mkrufky@linuxtv.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
@@ -41,6 +41,11 @@ enum lgdt3305_tp_valid_polarity {
41 LGDT3305_TP_VALID_HIGH = 1, 41 LGDT3305_TP_VALID_HIGH = 1,
42}; 42};
43 43
44enum lgdt_demod_chip_type {
45 LGDT3305 = 0,
46 LGDT3304 = 1,
47};
48
44struct lgdt3305_config { 49struct lgdt3305_config {
45 u8 i2c_addr; 50 u8 i2c_addr;
46 51
@@ -65,6 +70,7 @@ struct lgdt3305_config {
65 enum lgdt3305_mpeg_mode mpeg_mode; 70 enum lgdt3305_mpeg_mode mpeg_mode;
66 enum lgdt3305_tp_clock_edge tpclk_edge; 71 enum lgdt3305_tp_clock_edge tpclk_edge;
67 enum lgdt3305_tp_valid_polarity tpvalid_polarity; 72 enum lgdt3305_tp_valid_polarity tpvalid_polarity;
73 enum lgdt_demod_chip_type demod_chip;
68}; 74};
69 75
70#if defined(CONFIG_DVB_LGDT3305) || (defined(CONFIG_DVB_LGDT3305_MODULE) && \ 76#if defined(CONFIG_DVB_LGDT3305) || (defined(CONFIG_DVB_LGDT3305_MODULE) && \
diff --git a/drivers/media/dvb/frontends/lgs8gxx.c b/drivers/media/dvb/frontends/lgs8gxx.c
index dee53960e7e8..5ea28ae2ba8f 100644
--- a/drivers/media/dvb/frontends/lgs8gxx.c
+++ b/drivers/media/dvb/frontends/lgs8gxx.c
@@ -24,6 +24,7 @@
24 */ 24 */
25 25
26#include <asm/div64.h> 26#include <asm/div64.h>
27#include <linux/firmware.h>
27 28
28#include "dvb_frontend.h" 29#include "dvb_frontend.h"
29 30
@@ -46,42 +47,6 @@ module_param(fake_signal_str, int, 0644);
46MODULE_PARM_DESC(fake_signal_str, "fake signal strength for LGS8913." 47MODULE_PARM_DESC(fake_signal_str, "fake signal strength for LGS8913."
47"Signal strength calculation is slow.(default:on)."); 48"Signal strength calculation is slow.(default:on).");
48 49
49static const u8 lgs8g75_initdat[] = {
50 0x01, 0x30, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
51 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
52 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
53 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
54 0x00, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
55 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
56 0xE4, 0xF5, 0xA8, 0xF5, 0xB8, 0xF5, 0x88, 0xF5,
57 0x89, 0xF5, 0x87, 0x75, 0xD0, 0x00, 0x11, 0x50,
58 0x11, 0x50, 0xF4, 0xF5, 0x80, 0xF5, 0x90, 0xF5,
59 0xA0, 0xF5, 0xB0, 0x75, 0x81, 0x30, 0x80, 0x01,
60 0x32, 0x90, 0x80, 0x12, 0x74, 0xFF, 0xF0, 0x90,
61 0x80, 0x13, 0x74, 0x1F, 0xF0, 0x90, 0x80, 0x23,
62 0x74, 0x01, 0xF0, 0x90, 0x80, 0x22, 0xF0, 0x90,
63 0x00, 0x48, 0x74, 0x00, 0xF0, 0x90, 0x80, 0x4D,
64 0x74, 0x05, 0xF0, 0x90, 0x80, 0x09, 0xE0, 0x60,
65 0x21, 0x12, 0x00, 0xDD, 0x14, 0x60, 0x1B, 0x12,
66 0x00, 0xDD, 0x14, 0x60, 0x15, 0x12, 0x00, 0xDD,
67 0x14, 0x60, 0x0F, 0x12, 0x00, 0xDD, 0x14, 0x60,
68 0x09, 0x12, 0x00, 0xDD, 0x14, 0x60, 0x03, 0x12,
69 0x00, 0xDD, 0x90, 0x80, 0x42, 0xE0, 0x60, 0x0B,
70 0x14, 0x60, 0x0C, 0x14, 0x60, 0x0D, 0x14, 0x60,
71 0x0E, 0x01, 0xB3, 0x74, 0x04, 0x01, 0xB9, 0x74,
72 0x05, 0x01, 0xB9, 0x74, 0x07, 0x01, 0xB9, 0x74,
73 0x0A, 0xC0, 0xE0, 0x74, 0xC8, 0x12, 0x00, 0xE2,
74 0xD0, 0xE0, 0x14, 0x70, 0xF4, 0x90, 0x80, 0x09,
75 0xE0, 0x70, 0xAE, 0x12, 0x00, 0xF6, 0x12, 0x00,
76 0xFE, 0x90, 0x00, 0x48, 0xE0, 0x04, 0xF0, 0x90,
77 0x80, 0x4E, 0xF0, 0x01, 0x73, 0x90, 0x80, 0x08,
78 0xF0, 0x22, 0xF8, 0x7A, 0x0C, 0x79, 0xFD, 0x00,
79 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD9,
80 0xF6, 0xDA, 0xF2, 0xD8, 0xEE, 0x22, 0x90, 0x80,
81 0x65, 0xE0, 0x54, 0xFD, 0xF0, 0x22, 0x90, 0x80,
82 0x65, 0xE0, 0x44, 0xC2, 0xF0, 0x22
83};
84
85/* LGS8GXX internal helper functions */ 50/* LGS8GXX internal helper functions */
86 51
87static int lgs8gxx_write_reg(struct lgs8gxx_state *priv, u8 reg, u8 data) 52static int lgs8gxx_write_reg(struct lgs8gxx_state *priv, u8 reg, u8 data)
@@ -627,9 +592,14 @@ static int lgs8913_init(struct lgs8gxx_state *priv)
627 592
628static int lgs8g75_init_data(struct lgs8gxx_state *priv) 593static int lgs8g75_init_data(struct lgs8gxx_state *priv)
629{ 594{
630 const u8 *p = lgs8g75_initdat; 595 const struct firmware *fw;
596 int rc;
631 int i; 597 int i;
632 598
599 rc = request_firmware(&fw, "lgs8g75.fw", &priv->i2c->dev);
600 if (rc)
601 return rc;
602
633 lgs8gxx_write_reg(priv, 0xC6, 0x40); 603 lgs8gxx_write_reg(priv, 0xC6, 0x40);
634 604
635 lgs8gxx_write_reg(priv, 0x3D, 0x04); 605 lgs8gxx_write_reg(priv, 0x3D, 0x04);
@@ -640,16 +610,16 @@ static int lgs8g75_init_data(struct lgs8gxx_state *priv)
640 lgs8gxx_write_reg(priv, 0x3B, 0x00); 610 lgs8gxx_write_reg(priv, 0x3B, 0x00);
641 lgs8gxx_write_reg(priv, 0x38, 0x00); 611 lgs8gxx_write_reg(priv, 0x38, 0x00);
642 612
643 for (i = 0; i < sizeof(lgs8g75_initdat); i++) { 613 for (i = 0; i < fw->size; i++) {
644 lgs8gxx_write_reg(priv, 0x38, 0x00); 614 lgs8gxx_write_reg(priv, 0x38, 0x00);
645 lgs8gxx_write_reg(priv, 0x3A, (u8)(i&0xff)); 615 lgs8gxx_write_reg(priv, 0x3A, (u8)(i&0xff));
646 lgs8gxx_write_reg(priv, 0x3B, (u8)(i>>8)); 616 lgs8gxx_write_reg(priv, 0x3B, (u8)(i>>8));
647 lgs8gxx_write_reg(priv, 0x3C, *p); 617 lgs8gxx_write_reg(priv, 0x3C, fw->data[i]);
648 p++;
649 } 618 }
650 619
651 lgs8gxx_write_reg(priv, 0x38, 0x00); 620 lgs8gxx_write_reg(priv, 0x38, 0x00);
652 621
622 release_firmware(fw);
653 return 0; 623 return 0;
654} 624}
655 625
diff --git a/drivers/media/dvb/frontends/mb86a16.c b/drivers/media/dvb/frontends/mb86a16.c
index 599d1aa519a3..33b63235b86e 100644
--- a/drivers/media/dvb/frontends/mb86a16.c
+++ b/drivers/media/dvb/frontends/mb86a16.c
@@ -1833,7 +1833,6 @@ static struct dvb_frontend_ops mb86a16_ops = {
1833 1833
1834 .get_frontend_algo = mb86a16_frontend_algo, 1834 .get_frontend_algo = mb86a16_frontend_algo,
1835 .search = mb86a16_search, 1835 .search = mb86a16_search,
1836 .read_status = mb86a16_read_status,
1837 .init = mb86a16_init, 1836 .init = mb86a16_init,
1838 .sleep = mb86a16_sleep, 1837 .sleep = mb86a16_sleep,
1839 .read_status = mb86a16_read_status, 1838 .read_status = mb86a16_read_status,
diff --git a/drivers/media/dvb/frontends/tda10048.c b/drivers/media/dvb/frontends/tda10048.c
index 4e2a7c8b2f62..93f6a75c238e 100644
--- a/drivers/media/dvb/frontends/tda10048.c
+++ b/drivers/media/dvb/frontends/tda10048.c
@@ -25,6 +25,7 @@
25#include <linux/string.h> 25#include <linux/string.h>
26#include <linux/slab.h> 26#include <linux/slab.h>
27#include <linux/delay.h> 27#include <linux/delay.h>
28#include <linux/math64.h>
28#include <asm/div64.h> 29#include <asm/div64.h>
29#include "dvb_frontend.h" 30#include "dvb_frontend.h"
30#include "dvb_math.h" 31#include "dvb_math.h"
@@ -49,8 +50,8 @@
49#define TDA10048_CONF_C4_1 0x1E 50#define TDA10048_CONF_C4_1 0x1E
50#define TDA10048_CONF_C4_2 0x1F 51#define TDA10048_CONF_C4_2 0x1F
51#define TDA10048_CODE_IN_RAM 0x20 52#define TDA10048_CODE_IN_RAM 0x20
52#define TDA10048_CHANNEL_INFO_1_R 0x22 53#define TDA10048_CHANNEL_INFO1_R 0x22
53#define TDA10048_CHANNEL_INFO_2_R 0x23 54#define TDA10048_CHANNEL_INFO2_R 0x23
54#define TDA10048_CHANNEL_INFO1 0x24 55#define TDA10048_CHANNEL_INFO1 0x24
55#define TDA10048_CHANNEL_INFO2 0x25 56#define TDA10048_CHANNEL_INFO2 0x25
56#define TDA10048_TIME_ERROR_R 0x26 57#define TDA10048_TIME_ERROR_R 0x26
@@ -63,8 +64,8 @@
63#define TDA10048_IT_STAT 0x32 64#define TDA10048_IT_STAT 0x32
64#define TDA10048_DSP_AD_LSB 0x3C 65#define TDA10048_DSP_AD_LSB 0x3C
65#define TDA10048_DSP_AD_MSB 0x3D 66#define TDA10048_DSP_AD_MSB 0x3D
66#define TDA10048_DSP_REF_LSB 0x3E 67#define TDA10048_DSP_REG_LSB 0x3E
67#define TDA10048_DSP_REF_MSB 0x3F 68#define TDA10048_DSP_REG_MSB 0x3F
68#define TDA10048_CONF_TRISTATE1 0x44 69#define TDA10048_CONF_TRISTATE1 0x44
69#define TDA10048_CONF_TRISTATE2 0x45 70#define TDA10048_CONF_TRISTATE2 0x45
70#define TDA10048_CONF_POLARITY 0x46 71#define TDA10048_CONF_POLARITY 0x46
@@ -112,7 +113,7 @@
112#define TDA10048_FREE_REG_1 0xB2 113#define TDA10048_FREE_REG_1 0xB2
113#define TDA10048_FREE_REG_2 0xB3 114#define TDA10048_FREE_REG_2 0xB3
114#define TDA10048_CONF_C3_1 0xC0 115#define TDA10048_CONF_C3_1 0xC0
115#define TDA10048_CYBER_CTRL 0xC2 116#define TDA10048_CVBER_CTRL 0xC2
116#define TDA10048_CBER_NMAX_LSB 0xC4 117#define TDA10048_CBER_NMAX_LSB 0xC4
117#define TDA10048_CBER_NMAX_MSB 0xC5 118#define TDA10048_CBER_NMAX_MSB 0xC5
118#define TDA10048_CBER_LSB 0xC6 119#define TDA10048_CBER_LSB 0xC6
@@ -120,7 +121,7 @@
120#define TDA10048_VBER_LSB 0xC8 121#define TDA10048_VBER_LSB 0xC8
121#define TDA10048_VBER_MID 0xC9 122#define TDA10048_VBER_MID 0xC9
122#define TDA10048_VBER_MSB 0xCA 123#define TDA10048_VBER_MSB 0xCA
123#define TDA10048_CYBER_LUT 0xCC 124#define TDA10048_CVBER_LUT 0xCC
124#define TDA10048_UNCOR_CTRL 0xCD 125#define TDA10048_UNCOR_CTRL 0xCD
125#define TDA10048_UNCOR_CPT_LSB 0xCE 126#define TDA10048_UNCOR_CPT_LSB 0xCE
126#define TDA10048_UNCOR_CPT_MSB 0xCF 127#define TDA10048_UNCOR_CPT_MSB 0xCF
@@ -183,7 +184,7 @@ static struct init_tab {
183 { TDA10048_AGC_IF_MAX, 0xff }, 184 { TDA10048_AGC_IF_MAX, 0xff },
184 { TDA10048_AGC_THRESHOLD_MSB, 0x00 }, 185 { TDA10048_AGC_THRESHOLD_MSB, 0x00 },
185 { TDA10048_AGC_THRESHOLD_LSB, 0x70 }, 186 { TDA10048_AGC_THRESHOLD_LSB, 0x70 },
186 { TDA10048_CYBER_CTRL, 0x38 }, 187 { TDA10048_CVBER_CTRL, 0x38 },
187 { TDA10048_AGC_GAINS, 0x12 }, 188 { TDA10048_AGC_GAINS, 0x12 },
188 { TDA10048_CONF_XO, 0x00 }, 189 { TDA10048_CONF_XO, 0x00 },
189 { TDA10048_CONF_TS1, 0x07 }, 190 { TDA10048_CONF_TS1, 0x07 },
@@ -688,7 +689,7 @@ static int tda10048_get_tps(struct tda10048_state *state,
688 p->guard_interval = GUARD_INTERVAL_1_4; 689 p->guard_interval = GUARD_INTERVAL_1_4;
689 break; 690 break;
690 } 691 }
691 switch (val & 0x02) { 692 switch (val & 0x03) {
692 case 0: 693 case 0:
693 p->transmission_mode = TRANSMISSION_MODE_2K; 694 p->transmission_mode = TRANSMISSION_MODE_2K;
694 break; 695 break;
@@ -765,6 +766,8 @@ static int tda10048_set_frontend(struct dvb_frontend *fe,
765 766
766 /* Enable demod TPS auto detection and begin acquisition */ 767 /* Enable demod TPS auto detection and begin acquisition */
767 tda10048_writereg(state, TDA10048_AUTO, 0x57); 768 tda10048_writereg(state, TDA10048_AUTO, 0x57);
769 /* trigger cber and vber acquisition */
770 tda10048_writereg(state, TDA10048_CVBER_CTRL, 0x3B);
768 771
769 return 0; 772 return 0;
770} 773}
@@ -830,12 +833,27 @@ static int tda10048_read_status(struct dvb_frontend *fe, fe_status_t *status)
830static int tda10048_read_ber(struct dvb_frontend *fe, u32 *ber) 833static int tda10048_read_ber(struct dvb_frontend *fe, u32 *ber)
831{ 834{
832 struct tda10048_state *state = fe->demodulator_priv; 835 struct tda10048_state *state = fe->demodulator_priv;
836 static u32 cber_current;
837 u32 cber_nmax;
838 u64 cber_tmp;
833 839
834 dprintk(1, "%s()\n", __func__); 840 dprintk(1, "%s()\n", __func__);
835 841
836 /* TODO: A reset may be required here */ 842 /* update cber on interrupt */
837 *ber = tda10048_readreg(state, TDA10048_CBER_MSB) << 8 | 843 if (tda10048_readreg(state, TDA10048_SOFT_IT_C3) & 0x01) {
838 tda10048_readreg(state, TDA10048_CBER_LSB); 844 cber_tmp = tda10048_readreg(state, TDA10048_CBER_MSB) << 8 |
845 tda10048_readreg(state, TDA10048_CBER_LSB);
846 cber_nmax = tda10048_readreg(state, TDA10048_CBER_NMAX_MSB) << 8 |
847 tda10048_readreg(state, TDA10048_CBER_NMAX_LSB);
848 cber_tmp *= 100000000;
849 cber_tmp *= 2;
850 cber_tmp = div_u64(cber_tmp, (cber_nmax * 32) + 1);
851 cber_current = (u32)cber_tmp;
852 /* retrigger cber acquisition */
853 tda10048_writereg(state, TDA10048_CVBER_CTRL, 0x39);
854 }
855 /* actual cber is (*ber)/1e8 */
856 *ber = cber_current;
839 857
840 return 0; 858 return 0;
841} 859}
@@ -1015,6 +1033,9 @@ static int tda10048_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
1015 1033
1016 *ucblocks = tda10048_readreg(state, TDA10048_UNCOR_CPT_MSB) << 8 | 1034 *ucblocks = tda10048_readreg(state, TDA10048_UNCOR_CPT_MSB) << 8 |
1017 tda10048_readreg(state, TDA10048_UNCOR_CPT_LSB); 1035 tda10048_readreg(state, TDA10048_UNCOR_CPT_LSB);
1036 /* clear the uncorrected TS packets counter when saturated */
1037 if (*ucblocks == 0xFFFF)
1038 tda10048_writereg(state, TDA10048_UNCOR_CTRL, 0x80);
1018 1039
1019 return 0; 1040 return 0;
1020} 1041}
diff --git a/drivers/media/dvb/mantis/Kconfig b/drivers/media/dvb/mantis/Kconfig
index f7b72a32adf3..decdeda840d0 100644
--- a/drivers/media/dvb/mantis/Kconfig
+++ b/drivers/media/dvb/mantis/Kconfig
@@ -10,9 +10,15 @@ config MANTIS_CORE
10config DVB_MANTIS 10config DVB_MANTIS
11 tristate "MANTIS based cards" 11 tristate "MANTIS based cards"
12 depends on MANTIS_CORE && DVB_CORE && PCI && I2C 12 depends on MANTIS_CORE && DVB_CORE && PCI && I2C
13 select DVB_MB86A16 13 select DVB_MB86A16 if !DVB_FE_CUSTOMISE
14 select DVB_ZL10353 14 select DVB_ZL10353 if !DVB_FE_CUSTOMISE
15 select DVB_STV0299 15 select DVB_STV0299 if !DVB_FE_CUSTOMISE
16 select DVB_LNBP21 if !DVB_FE_CUSTOMISE
17 select DVB_STB0899 if !DVB_FE_CUSTOMISE
18 select DVB_STB6100 if !DVB_FE_CUSTOMISE
19 select DVB_TDA665x if !DVB_FE_CUSTOMISE
20 select DVB_TDA10021 if !DVB_FE_CUSTOMISE
21 select DVB_TDA10023 if !DVB_FE_CUSTOMISE
16 select DVB_PLL 22 select DVB_PLL
17 help 23 help
18 Support for PCI cards based on the Mantis PCI bridge. 24 Support for PCI cards based on the Mantis PCI bridge.
@@ -23,7 +29,7 @@ config DVB_MANTIS
23config DVB_HOPPER 29config DVB_HOPPER
24 tristate "HOPPER based cards" 30 tristate "HOPPER based cards"
25 depends on MANTIS_CORE && DVB_CORE && PCI && I2C 31 depends on MANTIS_CORE && DVB_CORE && PCI && I2C
26 select DVB_ZL10353 32 select DVB_ZL10353 if !DVB_FE_CUSTOMISE
27 select DVB_PLL 33 select DVB_PLL
28 help 34 help
29 Support for PCI cards based on the Hopper PCI bridge. 35 Support for PCI cards based on the Hopper PCI bridge.
diff --git a/drivers/media/dvb/mantis/mantis_input.c b/drivers/media/dvb/mantis/mantis_input.c
index 3d4e4663220c..a99489b8418b 100644
--- a/drivers/media/dvb/mantis/mantis_input.c
+++ b/drivers/media/dvb/mantis/mantis_input.c
@@ -19,7 +19,7 @@
19*/ 19*/
20 20
21#include <linux/input.h> 21#include <linux/input.h>
22#include <media/ir-common.h> 22#include <media/ir-core.h>
23#include <linux/pci.h> 23#include <linux/pci.h>
24 24
25#include "dmxdev.h" 25#include "dmxdev.h"
@@ -104,7 +104,6 @@ EXPORT_SYMBOL_GPL(ir_mantis);
104int mantis_input_init(struct mantis_pci *mantis) 104int mantis_input_init(struct mantis_pci *mantis)
105{ 105{
106 struct input_dev *rc; 106 struct input_dev *rc;
107 struct ir_input_state rc_state;
108 char name[80], dev[80]; 107 char name[80], dev[80];
109 int err; 108 int err;
110 109
@@ -120,8 +119,6 @@ int mantis_input_init(struct mantis_pci *mantis)
120 rc->name = name; 119 rc->name = name;
121 rc->phys = dev; 120 rc->phys = dev;
122 121
123 ir_input_init(rc, &rc_state, IR_TYPE_OTHER);
124
125 rc->id.bustype = BUS_PCI; 122 rc->id.bustype = BUS_PCI;
126 rc->id.vendor = mantis->vendor_id; 123 rc->id.vendor = mantis->vendor_id;
127 rc->id.product = mantis->device_id; 124 rc->id.product = mantis->device_id;
diff --git a/drivers/media/dvb/siano/sms-cards.c b/drivers/media/dvb/siano/sms-cards.c
index cff77e2eb557..25b43e587fa6 100644
--- a/drivers/media/dvb/siano/sms-cards.c
+++ b/drivers/media/dvb/siano/sms-cards.c
@@ -64,9 +64,11 @@ static struct sms_board sms_boards[] = {
64 .type = SMS_NOVA_B0, 64 .type = SMS_NOVA_B0,
65 .fw[DEVICE_MODE_ISDBT_BDA] = "sms1xxx-hcw-55xxx-isdbt-02.fw", 65 .fw[DEVICE_MODE_ISDBT_BDA] = "sms1xxx-hcw-55xxx-isdbt-02.fw",
66 .fw[DEVICE_MODE_DVBT_BDA] = "sms1xxx-hcw-55xxx-dvbt-02.fw", 66 .fw[DEVICE_MODE_DVBT_BDA] = "sms1xxx-hcw-55xxx-dvbt-02.fw",
67 .rc_codes = RC_MAP_RC5_HAUPPAUGE_NEW,
67 .board_cfg.leds_power = 26, 68 .board_cfg.leds_power = 26,
68 .board_cfg.led0 = 27, 69 .board_cfg.led0 = 27,
69 .board_cfg.led1 = 28, 70 .board_cfg.led1 = 28,
71 .board_cfg.ir = 9,
70 .led_power = 26, 72 .led_power = 26,
71 .led_lo = 27, 73 .led_lo = 27,
72 .led_hi = 28, 74 .led_hi = 28,
diff --git a/drivers/media/dvb/siano/sms-cards.h b/drivers/media/dvb/siano/sms-cards.h
index 8f19fc000b46..d8cdf756f7cf 100644
--- a/drivers/media/dvb/siano/sms-cards.h
+++ b/drivers/media/dvb/siano/sms-cards.h
@@ -75,7 +75,7 @@ struct sms_board {
75 enum sms_device_type_st type; 75 enum sms_device_type_st type;
76 char *name, *fw[DEVICE_MODE_MAX]; 76 char *name, *fw[DEVICE_MODE_MAX];
77 struct sms_board_gpio_cfg board_cfg; 77 struct sms_board_gpio_cfg board_cfg;
78 enum ir_kb_type ir_kb_type; 78 char *rc_codes; /* Name of IR codes table */
79 79
80 /* gpios */ 80 /* gpios */
81 int led_power, led_hi, led_lo, lna_ctrl, rf_switch; 81 int led_power, led_hi, led_lo, lna_ctrl, rf_switch;
diff --git a/drivers/media/dvb/siano/smscoreapi.c b/drivers/media/dvb/siano/smscoreapi.c
index 0c87a3c3899a..828bcc2e129b 100644
--- a/drivers/media/dvb/siano/smscoreapi.c
+++ b/drivers/media/dvb/siano/smscoreapi.c
@@ -116,9 +116,7 @@ static struct smscore_registry_entry_t *smscore_find_registry(char *devpath)
116 return entry; 116 return entry;
117 } 117 }
118 } 118 }
119 entry = (struct smscore_registry_entry_t *) 119 entry = kmalloc(sizeof(struct smscore_registry_entry_t), GFP_KERNEL);
120 kmalloc(sizeof(struct smscore_registry_entry_t),
121 GFP_KERNEL);
122 if (entry) { 120 if (entry) {
123 entry->mode = default_mode; 121 entry->mode = default_mode;
124 strcpy(entry->devpath, devpath); 122 strcpy(entry->devpath, devpath);
diff --git a/drivers/media/dvb/siano/smsir.c b/drivers/media/dvb/siano/smsir.c
index a56eac76e0f0..d0e4639ee9db 100644
--- a/drivers/media/dvb/siano/smsir.c
+++ b/drivers/media/dvb/siano/smsir.c
@@ -4,6 +4,11 @@
4 MDTV receiver kernel modules. 4 MDTV receiver kernel modules.
5 Copyright (C) 2006-2009, Uri Shkolnik 5 Copyright (C) 2006-2009, Uri Shkolnik
6 6
7 Copyright (c) 2010 - Mauro Carvalho Chehab
8 - Ported the driver to use rc-core
9 - IR raw event decoding is now done at rc-core
10 - Code almost re-written
11
7 This program is free software: you can redistribute it and/or modify 12 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 13 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 2 of the License, or 14 the Free Software Foundation, either version 2 of the License, or
@@ -27,226 +32,28 @@
27#include "smsir.h" 32#include "smsir.h"
28#include "sms-cards.h" 33#include "sms-cards.h"
29 34
30/* In order to add new IR remote control - 35#define MODULE_NAME "smsmdtv"
31 * 1) Add it to the <enum ir_kb_type> @ smsir,h,
32 * 2) Add its map to keyboard_layout_maps below
33 * 3) Set your board (sms-cards sub-module) to use it
34 */
35
36static struct keyboard_layout_map_t keyboard_layout_maps[] = {
37 [SMS_IR_KB_DEFAULT_TV] = {
38 .ir_protocol = IR_RC5,
39 .rc5_kbd_address = KEYBOARD_ADDRESS_TV1,
40 .keyboard_layout_map = {
41 KEY_0, KEY_1, KEY_2,
42 KEY_3, KEY_4, KEY_5,
43 KEY_6, KEY_7, KEY_8,
44 KEY_9, 0, 0, KEY_POWER,
45 KEY_MUTE, 0, 0,
46 KEY_VOLUMEUP, KEY_VOLUMEDOWN,
47 KEY_BRIGHTNESSUP,
48 KEY_BRIGHTNESSDOWN, KEY_CHANNELUP,
49 KEY_CHANNELDOWN,
50 0, 0, 0, 0, 0, 0, 0, 0,
51 0, 0, 0, 0, 0, 0, 0, 0,
52 0, 0, 0, 0, 0, 0, 0, 0,
53 0, 0, 0, 0, 0, 0, 0, 0,
54 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
55 }
56 },
57 [SMS_IR_KB_HCW_SILVER] = {
58 .ir_protocol = IR_RC5,
59 .rc5_kbd_address = KEYBOARD_ADDRESS_LIGHTING1,
60 .keyboard_layout_map = {
61 KEY_0, KEY_1, KEY_2,
62 KEY_3, KEY_4, KEY_5,
63 KEY_6, KEY_7, KEY_8,
64 KEY_9, KEY_TEXT, KEY_RED,
65 KEY_RADIO, KEY_MENU,
66 KEY_SUBTITLE,
67 KEY_MUTE, KEY_VOLUMEUP,
68 KEY_VOLUMEDOWN, KEY_PREVIOUS, 0,
69 KEY_UP, KEY_DOWN, KEY_LEFT,
70 KEY_RIGHT, KEY_VIDEO, KEY_AUDIO,
71 KEY_MHP, KEY_EPG, KEY_TV,
72 0, KEY_NEXTSONG, KEY_EXIT,
73 KEY_CHANNELUP, KEY_CHANNELDOWN,
74 KEY_CHANNEL, 0,
75 KEY_PREVIOUSSONG, KEY_ENTER,
76 KEY_SLEEP, 0, 0, KEY_BLUE,
77 0, 0, 0, 0, KEY_GREEN, 0,
78 KEY_PAUSE, 0, KEY_REWIND,
79 0, KEY_FASTFORWARD, KEY_PLAY,
80 KEY_STOP, KEY_RECORD,
81 KEY_YELLOW, 0, 0, KEY_SELECT,
82 KEY_ZOOM, KEY_POWER, 0, 0
83 }
84 },
85 { } /* Terminating entry */
86};
87
88static u32 ir_pos;
89static u32 ir_word;
90static u32 ir_toggle;
91
92#define RC5_PUSH_BIT(dst, bit, pos) \
93 { dst <<= 1; dst |= bit; pos++; }
94
95
96static void sms_ir_rc5_event(struct smscore_device_t *coredev,
97 u32 toggle, u32 addr, u32 cmd)
98{
99 bool toggle_changed;
100 u16 keycode;
101
102 sms_log("IR RC5 word: address %d, command %d, toggle %d",
103 addr, cmd, toggle);
104
105 toggle_changed = ir_toggle != toggle;
106 /* keep toggle */
107 ir_toggle = toggle;
108
109 if (addr !=
110 keyboard_layout_maps[coredev->ir.ir_kb_type].rc5_kbd_address)
111 return; /* Check for valid address */
112
113 keycode =
114 keyboard_layout_maps
115 [coredev->ir.ir_kb_type].keyboard_layout_map[cmd];
116 36
117 if (!toggle_changed && 37void sms_ir_event(struct smscore_device_t *coredev, const char *buf, int len)
118 (keycode != KEY_VOLUMEUP && keycode != KEY_VOLUMEDOWN))
119 return; /* accept only repeated volume, reject other keys */
120
121 sms_log("kernel input keycode (from ir) %d", keycode);
122 input_report_key(coredev->ir.input_dev, keycode, 1);
123 input_sync(coredev->ir.input_dev);
124
125}
126
127/* decode raw bit pattern to RC5 code */
128/* taken from ir-functions.c */
129static u32 ir_rc5_decode(unsigned int code)
130{ 38{
131/* unsigned int org_code = code;*/
132 unsigned int pair;
133 unsigned int rc5 = 0;
134 int i; 39 int i;
40 const s32 *samples = (const void *)buf;
135 41
136 for (i = 0; i < 14; ++i) { 42 for (i = 0; i < len >> 2; i++) {
137 pair = code & 0x3; 43 struct ir_raw_event ev;
138 code >>= 2;
139
140 rc5 <<= 1;
141 switch (pair) {
142 case 0:
143 case 2:
144 break;
145 case 1:
146 rc5 |= 1;
147 break;
148 case 3:
149/* dprintk(1, "ir-common: ir_rc5_decode(%x) bad code\n", org_code);*/
150 sms_log("bad code");
151 return 0;
152 }
153 }
154/*
155 dprintk(1, "ir-common: code=%x, rc5=%x, start=%x,
156 toggle=%x, address=%x, "
157 "instr=%x\n", rc5, org_code, RC5_START(rc5),
158 RC5_TOGGLE(rc5), RC5_ADDR(rc5), RC5_INSTR(rc5));
159*/
160 return rc5;
161}
162
163static void sms_rc5_parse_word(struct smscore_device_t *coredev)
164{
165 #define RC5_START(x) (((x)>>12)&3)
166 #define RC5_TOGGLE(x) (((x)>>11)&1)
167 #define RC5_ADDR(x) (((x)>>6)&0x1F)
168 #define RC5_INSTR(x) ((x)&0x3F)
169
170 int i, j;
171 u32 rc5_word = 0;
172
173 /* Reverse the IR word direction */
174 for (i = 0 ; i < 28 ; i++)
175 RC5_PUSH_BIT(rc5_word, (ir_word>>i)&1, j)
176
177 rc5_word = ir_rc5_decode(rc5_word);
178 /* sms_log("temp = 0x%x, rc5_code = 0x%x", ir_word, rc5_word); */
179
180 sms_ir_rc5_event(coredev,
181 RC5_TOGGLE(rc5_word),
182 RC5_ADDR(rc5_word),
183 RC5_INSTR(rc5_word));
184}
185
186
187static void sms_rc5_accumulate_bits(struct smscore_device_t *coredev,
188 s32 ir_sample)
189{
190 #define RC5_TIME_GRANULARITY 200
191 #define RC5_DEF_BIT_TIME 889
192 #define RC5_MAX_SAME_BIT_CONT 4
193 #define RC5_WORD_LEN 27 /* 28 bit */
194
195 u32 i, j;
196 s32 delta_time;
197 u32 time = (ir_sample > 0) ? ir_sample : (0-ir_sample);
198 u32 level = (ir_sample < 0) ? 0 : 1;
199
200 for (i = RC5_MAX_SAME_BIT_CONT; i > 0; i--) {
201 delta_time = time - (i*RC5_DEF_BIT_TIME) + RC5_TIME_GRANULARITY;
202 if (delta_time < 0)
203 continue; /* not so many consecutive bits */
204 if (delta_time > (2 * RC5_TIME_GRANULARITY)) {
205 /* timeout */
206 if (ir_pos == (RC5_WORD_LEN-1))
207 /* complete last bit */
208 RC5_PUSH_BIT(ir_word, level, ir_pos)
209
210 if (ir_pos == RC5_WORD_LEN)
211 sms_rc5_parse_word(coredev);
212 else if (ir_pos) /* timeout within a word */
213 sms_log("IR error parsing a word");
214 44
215 ir_pos = 0; 45 ev.duration = abs(samples[i]) * 1000; /* Convert to ns */
216 ir_word = 0; 46 ev.pulse = (samples[i] > 0) ? false : true;
217 /* sms_log("timeout %d", time); */
218 break;
219 }
220 /* The time is within the range of this number of bits */
221 for (j = 0 ; j < i ; j++)
222 RC5_PUSH_BIT(ir_word, level, ir_pos)
223 47
224 break; 48 ir_raw_event_store(coredev->ir.input_dev, &ev);
225 } 49 }
226} 50 ir_raw_event_handle(coredev->ir.input_dev);
227
228void sms_ir_event(struct smscore_device_t *coredev, const char *buf, int len)
229{
230 #define IR_DATA_RECEIVE_MAX_LEN 520 /* 128*4 + 4 + 4 */
231 u32 i;
232 enum ir_protocol ir_protocol =
233 keyboard_layout_maps[coredev->ir.ir_kb_type]
234 .ir_protocol;
235 s32 *samples;
236 int count = len>>2;
237
238 samples = (s32 *)buf;
239/* sms_log("IR buffer received, length = %d", count);*/
240
241 for (i = 0; i < count; i++)
242 if (ir_protocol == IR_RC5)
243 sms_rc5_accumulate_bits(coredev, samples[i]);
244 /* IR_RCMM not implemented */
245} 51}
246 52
247int sms_ir_init(struct smscore_device_t *coredev) 53int sms_ir_init(struct smscore_device_t *coredev)
248{ 54{
249 struct input_dev *input_dev; 55 struct input_dev *input_dev;
56 int board_id = smscore_get_board_id(coredev);
250 57
251 sms_log("Allocating input device"); 58 sms_log("Allocating input device");
252 input_dev = input_allocate_device(); 59 input_dev = input_allocate_device();
@@ -256,33 +63,38 @@ int sms_ir_init(struct smscore_device_t *coredev)
256 } 63 }
257 64
258 coredev->ir.input_dev = input_dev; 65 coredev->ir.input_dev = input_dev;
259 coredev->ir.ir_kb_type =
260 sms_get_board(smscore_get_board_id(coredev))->ir_kb_type;
261 coredev->ir.keyboard_layout_map =
262 keyboard_layout_maps[coredev->ir.ir_kb_type].
263 keyboard_layout_map;
264 sms_log("IR remote keyboard type is %d", coredev->ir.ir_kb_type);
265 66
266 coredev->ir.controller = 0; /* Todo: vega/nova SPI number */ 67 coredev->ir.controller = 0; /* Todo: vega/nova SPI number */
267 coredev->ir.timeout = IR_DEFAULT_TIMEOUT; 68 coredev->ir.timeout = IR_DEFAULT_TIMEOUT;
268 sms_log("IR port %d, timeout %d ms", 69 sms_log("IR port %d, timeout %d ms",
269 coredev->ir.controller, coredev->ir.timeout); 70 coredev->ir.controller, coredev->ir.timeout);
270 71
271 snprintf(coredev->ir.name, 72 snprintf(coredev->ir.name, sizeof(coredev->ir.name),
272 IR_DEV_NAME_MAX_LEN, 73 "SMS IR (%s)", sms_get_board(board_id)->name);
273 "SMS IR w/kbd type %d", 74
274 coredev->ir.ir_kb_type); 75 strlcpy(coredev->ir.phys, coredev->devpath, sizeof(coredev->ir.phys));
76 strlcat(coredev->ir.phys, "/ir0", sizeof(coredev->ir.phys));
77
275 input_dev->name = coredev->ir.name; 78 input_dev->name = coredev->ir.name;
276 input_dev->phys = coredev->ir.name; 79 input_dev->phys = coredev->ir.phys;
277 input_dev->dev.parent = coredev->device; 80 input_dev->dev.parent = coredev->device;
278 81
279 /* Key press events only */ 82#if 0
280 input_dev->evbit[0] = BIT_MASK(EV_KEY); 83 /* TODO: properly initialize the parameters bellow */
281 input_dev->keybit[BIT_WORD(BTN_0)] = BIT_MASK(BTN_0); 84 input_dev->id.bustype = BUS_USB;
85 input_dev->id.version = 1;
86 input_dev->id.vendor = le16_to_cpu(dev->udev->descriptor.idVendor);
87 input_dev->id.product = le16_to_cpu(dev->udev->descriptor.idProduct);
88#endif
89
90 coredev->ir.props.priv = coredev;
91 coredev->ir.props.driver_type = RC_DRIVER_IR_RAW;
92 coredev->ir.props.allowed_protos = IR_TYPE_ALL;
282 93
283 sms_log("Input device (IR) %s is set for key events", input_dev->name); 94 sms_log("Input device (IR) %s is set for key events", input_dev->name);
284 95
285 if (input_register_device(input_dev)) { 96 if (ir_input_register(input_dev, sms_get_board(board_id)->rc_codes,
97 &coredev->ir.props, MODULE_NAME)) {
286 sms_err("Failed to register device"); 98 sms_err("Failed to register device");
287 input_free_device(input_dev); 99 input_free_device(input_dev);
288 return -EACCES; 100 return -EACCES;
@@ -294,8 +106,7 @@ int sms_ir_init(struct smscore_device_t *coredev)
294void sms_ir_exit(struct smscore_device_t *coredev) 106void sms_ir_exit(struct smscore_device_t *coredev)
295{ 107{
296 if (coredev->ir.input_dev) 108 if (coredev->ir.input_dev)
297 input_unregister_device(coredev->ir.input_dev); 109 ir_input_unregister(coredev->ir.input_dev);
298 110
299 sms_log(""); 111 sms_log("");
300} 112}
301
diff --git a/drivers/media/dvb/siano/smsir.h b/drivers/media/dvb/siano/smsir.h
index b7d703e2d338..926e247523bd 100644
--- a/drivers/media/dvb/siano/smsir.h
+++ b/drivers/media/dvb/siano/smsir.h
@@ -4,6 +4,11 @@ Siano Mobile Silicon, Inc.
4MDTV receiver kernel modules. 4MDTV receiver kernel modules.
5Copyright (C) 2006-2009, Uri Shkolnik 5Copyright (C) 2006-2009, Uri Shkolnik
6 6
7 Copyright (c) 2010 - Mauro Carvalho Chehab
8 - Ported the driver to use rc-core
9 - IR raw event decoding is now done at rc-core
10 - Code almost re-written
11
7This program is free software: you can redistribute it and/or modify 12This program is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by 13it under the terms of the GNU General Public License as published by
9the Free Software Foundation, either version 2 of the License, or 14the Free Software Foundation, either version 2 of the License, or
@@ -23,63 +28,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
23#define __SMS_IR_H__ 28#define __SMS_IR_H__
24 29
25#include <linux/input.h> 30#include <linux/input.h>
31#include <media/ir-core.h>
26 32
27#define IR_DEV_NAME_MAX_LEN 23 /* "SMS IR kbd type nn\0" */
28#define IR_KEYBOARD_LAYOUT_SIZE 64
29#define IR_DEFAULT_TIMEOUT 100 33#define IR_DEFAULT_TIMEOUT 100
30 34
31enum ir_kb_type {
32 SMS_IR_KB_DEFAULT_TV,
33 SMS_IR_KB_HCW_SILVER
34};
35
36enum rc5_keyboard_address {
37 KEYBOARD_ADDRESS_TV1 = 0,
38 KEYBOARD_ADDRESS_TV2 = 1,
39 KEYBOARD_ADDRESS_TELETEXT = 2,
40 KEYBOARD_ADDRESS_VIDEO = 3,
41 KEYBOARD_ADDRESS_LV1 = 4,
42 KEYBOARD_ADDRESS_VCR1 = 5,
43 KEYBOARD_ADDRESS_VCR2 = 6,
44 KEYBOARD_ADDRESS_EXPERIMENTAL = 7,
45 KEYBOARD_ADDRESS_SAT1 = 8,
46 KEYBOARD_ADDRESS_CAMERA = 9,
47 KEYBOARD_ADDRESS_SAT2 = 10,
48 KEYBOARD_ADDRESS_CDV = 12,
49 KEYBOARD_ADDRESS_CAMCORDER = 13,
50 KEYBOARD_ADDRESS_PRE_AMP = 16,
51 KEYBOARD_ADDRESS_TUNER = 17,
52 KEYBOARD_ADDRESS_RECORDER1 = 18,
53 KEYBOARD_ADDRESS_PRE_AMP1 = 19,
54 KEYBOARD_ADDRESS_CD_PLAYER = 20,
55 KEYBOARD_ADDRESS_PHONO = 21,
56 KEYBOARD_ADDRESS_SATA = 22,
57 KEYBOARD_ADDRESS_RECORDER2 = 23,
58 KEYBOARD_ADDRESS_CDR = 26,
59 KEYBOARD_ADDRESS_LIGHTING = 29,
60 KEYBOARD_ADDRESS_LIGHTING1 = 30, /* KEYBOARD_ADDRESS_HCW_SILVER */
61 KEYBOARD_ADDRESS_PHONE = 31,
62 KEYBOARD_ADDRESS_NOT_RC5 = 0xFFFF
63};
64
65enum ir_protocol {
66 IR_RC5,
67 IR_RCMM
68};
69
70struct keyboard_layout_map_t {
71 enum ir_protocol ir_protocol;
72 enum rc5_keyboard_address rc5_kbd_address;
73 u16 keyboard_layout_map[IR_KEYBOARD_LAYOUT_SIZE];
74};
75
76struct smscore_device_t; 35struct smscore_device_t;
77 36
78struct ir_t { 37struct ir_t {
79 struct input_dev *input_dev; 38 struct input_dev *input_dev;
80 enum ir_kb_type ir_kb_type; 39 char name[40];
81 char name[IR_DEV_NAME_MAX_LEN+1]; 40 char phys[32];
82 u16 *keyboard_layout_map; 41
42 char *rc_codes;
43 u64 protocol;
44 struct ir_dev_props props;
45
83 u32 timeout; 46 u32 timeout;
84 u32 controller; 47 u32 controller;
85}; 48};
diff --git a/drivers/media/dvb/siano/smsusb.c b/drivers/media/dvb/siano/smsusb.c
index a9c27fb69ba7..50d4338610e0 100644
--- a/drivers/media/dvb/siano/smsusb.c
+++ b/drivers/media/dvb/siano/smsusb.c
@@ -352,8 +352,7 @@ static int smsusb_init_device(struct usb_interface *intf, int board_id)
352 params.num_buffers = MAX_BUFFERS; 352 params.num_buffers = MAX_BUFFERS;
353 params.sendrequest_handler = smsusb_sendrequest; 353 params.sendrequest_handler = smsusb_sendrequest;
354 params.context = dev; 354 params.context = dev;
355 snprintf(params.devpath, sizeof(params.devpath), 355 usb_make_path(dev->udev, params.devpath, sizeof(params.devpath));
356 "usb\\%d-%s", dev->udev->bus->busnum, dev->udev->devpath);
357 356
358 /* register in smscore */ 357 /* register in smscore */
359 rc = smscore_register_device(&params, &dev->coredev); 358 rc = smscore_register_device(&params, &dev->coredev);
diff --git a/drivers/media/radio/si470x/radio-si470x-common.c b/drivers/media/radio/si470x/radio-si470x-common.c
index 47075fc71f11..9927a595b426 100644
--- a/drivers/media/radio/si470x/radio-si470x-common.c
+++ b/drivers/media/radio/si470x/radio-si470x-common.c
@@ -748,7 +748,7 @@ static int si470x_vidioc_s_tuner(struct file *file, void *priv,
748 struct v4l2_tuner *tuner) 748 struct v4l2_tuner *tuner)
749{ 749{
750 struct si470x_device *radio = video_drvdata(file); 750 struct si470x_device *radio = video_drvdata(file);
751 int retval = -EINVAL; 751 int retval = 0;
752 752
753 /* safety checks */ 753 /* safety checks */
754 retval = si470x_disconnect_check(radio); 754 retval = si470x_disconnect_check(radio);
diff --git a/drivers/media/radio/si4713-i2c.c b/drivers/media/radio/si4713-i2c.c
index ab63dd5b25c4..fc7f4b794649 100644
--- a/drivers/media/radio/si4713-i2c.c
+++ b/drivers/media/radio/si4713-i2c.c
@@ -1009,8 +1009,10 @@ static int si4713_write_econtrol_string(struct si4713_device *sdev,
1009 goto exit; 1009 goto exit;
1010 } 1010 }
1011 rval = copy_from_user(ps_name, control->string, len); 1011 rval = copy_from_user(ps_name, control->string, len);
1012 if (rval < 0) 1012 if (rval) {
1013 rval = -EFAULT;
1013 goto exit; 1014 goto exit;
1015 }
1014 ps_name[len] = '\0'; 1016 ps_name[len] = '\0';
1015 1017
1016 if (strlen(ps_name) % vqc.step) { 1018 if (strlen(ps_name) % vqc.step) {
@@ -1031,8 +1033,10 @@ static int si4713_write_econtrol_string(struct si4713_device *sdev,
1031 goto exit; 1033 goto exit;
1032 } 1034 }
1033 rval = copy_from_user(radio_text, control->string, len); 1035 rval = copy_from_user(radio_text, control->string, len);
1034 if (rval < 0) 1036 if (rval) {
1037 rval = -EFAULT;
1035 goto exit; 1038 goto exit;
1039 }
1036 radio_text[len] = '\0'; 1040 radio_text[len] = '\0';
1037 1041
1038 if (strlen(radio_text) % vqc.step) { 1042 if (strlen(radio_text) % vqc.step) {
@@ -1367,6 +1371,8 @@ static int si4713_read_econtrol_string(struct si4713_device *sdev,
1367 } 1371 }
1368 rval = copy_to_user(control->string, sdev->rds_info.ps_name, 1372 rval = copy_to_user(control->string, sdev->rds_info.ps_name,
1369 strlen(sdev->rds_info.ps_name) + 1); 1373 strlen(sdev->rds_info.ps_name) + 1);
1374 if (rval)
1375 rval = -EFAULT;
1370 break; 1376 break;
1371 1377
1372 case V4L2_CID_RDS_TX_RADIO_TEXT: 1378 case V4L2_CID_RDS_TX_RADIO_TEXT:
@@ -1377,6 +1383,8 @@ static int si4713_read_econtrol_string(struct si4713_device *sdev,
1377 } 1383 }
1378 rval = copy_to_user(control->string, sdev->rds_info.radio_text, 1384 rval = copy_to_user(control->string, sdev->rds_info.radio_text,
1379 strlen(sdev->rds_info.radio_text) + 1); 1385 strlen(sdev->rds_info.radio_text) + 1);
1386 if (rval)
1387 rval = -EFAULT;
1380 break; 1388 break;
1381 1389
1382 default: 1390 default:
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index 27e2acce3c3a..2e15903b976d 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -517,19 +517,6 @@ config VIDEO_UPD64083
517 517
518endmenu # encoder / decoder chips 518endmenu # encoder / decoder chips
519 519
520config DISPLAY_DAVINCI_DM646X_EVM
521 tristate "DM646x EVM Video Display"
522 depends on VIDEO_DEV && MACH_DAVINCI_DM6467_EVM
523 select VIDEOBUF_DMA_CONTIG
524 select VIDEO_DAVINCI_VPIF
525 select VIDEO_ADV7343
526 select VIDEO_THS7303
527 help
528 Support for DM6467 based display device.
529
530 To compile this driver as a module, choose M here: the
531 module will be called vpif_display.
532
533config VIDEO_SH_VOU 520config VIDEO_SH_VOU
534 tristate "SuperH VOU video output driver" 521 tristate "SuperH VOU video output driver"
535 depends on VIDEO_DEV && ARCH_SHMOBILE 522 depends on VIDEO_DEV && ARCH_SHMOBILE
@@ -537,29 +524,22 @@ config VIDEO_SH_VOU
537 help 524 help
538 Support for the Video Output Unit (VOU) on SuperH SoCs. 525 Support for the Video Output Unit (VOU) on SuperH SoCs.
539 526
540config CAPTURE_DAVINCI_DM646X_EVM 527config VIDEO_VIU
541 tristate "DM646x EVM Video Capture" 528 tristate "Freescale VIU Video Driver"
542 depends on VIDEO_DEV && MACH_DAVINCI_DM6467_EVM 529 depends on VIDEO_V4L2 && PPC_MPC512x
543 select VIDEOBUF_DMA_CONTIG 530 select VIDEOBUF_DMA_CONTIG
544 select VIDEO_DAVINCI_VPIF 531 default y
545 help 532 ---help---
546 Support for DM6467 based capture device. 533 Support for Freescale VIU video driver. This device captures
547 534 video data, or overlays video on DIU frame buffer.
548 To compile this driver as a module, choose M here: the
549 module will be called vpif_capture.
550
551config VIDEO_DAVINCI_VPIF
552 tristate "DaVinci VPIF Driver"
553 depends on DISPLAY_DAVINCI_DM646X_EVM
554 help
555 Support for DaVinci VPIF Driver.
556 535
557 To compile this driver as a module, choose M here: the 536 Say Y here if you want to enable VIU device on MPC5121e Rev2+.
558 module will be called vpif. 537 In doubt, say N.
559 538
560config VIDEO_VIVI 539config VIDEO_VIVI
561 tristate "Virtual Video Driver" 540 tristate "Virtual Video Driver"
562 depends on VIDEO_DEV && VIDEO_V4L2 && !SPARC32 && !SPARC64 && FONTS 541 depends on VIDEO_DEV && VIDEO_V4L2 && !SPARC32 && !SPARC64
542 depends on (FRAMEBUFFER_CONSOLE || STI_CONSOLE) && FONTS
563 select FONT_8x16 543 select FONT_8x16
564 select VIDEOBUF_VMALLOC 544 select VIDEOBUF_VMALLOC
565 default n 545 default n
@@ -570,66 +550,7 @@ config VIDEO_VIVI
570 Say Y here if you want to test video apps or debug V4L devices. 550 Say Y here if you want to test video apps or debug V4L devices.
571 In doubt, say N. 551 In doubt, say N.
572 552
573config VIDEO_VPSS_SYSTEM 553source "drivers/media/video/davinci/Kconfig"
574 tristate "VPSS System module driver"
575 depends on ARCH_DAVINCI
576 help
577 Support for vpss system module for video driver
578
579config VIDEO_VPFE_CAPTURE
580 tristate "VPFE Video Capture Driver"
581 depends on VIDEO_V4L2 && ARCH_DAVINCI
582 select VIDEOBUF_DMA_CONTIG
583 help
584 Support for DMXXXX VPFE based frame grabber. This is the
585 common V4L2 module for following DMXXX SoCs from Texas
586 Instruments:- DM6446 & DM355.
587
588 To compile this driver as a module, choose M here: the
589 module will be called vpfe-capture.
590
591config VIDEO_DM6446_CCDC
592 tristate "DM6446 CCDC HW module"
593 depends on ARCH_DAVINCI_DM644x && VIDEO_VPFE_CAPTURE
594 select VIDEO_VPSS_SYSTEM
595 default y
596 help
597 Enables DaVinci CCD hw module. DaVinci CCDC hw interfaces
598 with decoder modules such as TVP5146 over BT656 or
599 sensor module such as MT9T001 over a raw interface. This
600 module configures the interface and CCDC/ISIF to do
601 video frame capture from slave decoders.
602
603 To compile this driver as a module, choose M here: the
604 module will be called vpfe.
605
606config VIDEO_DM355_CCDC
607 tristate "DM355 CCDC HW module"
608 depends on ARCH_DAVINCI_DM355 && VIDEO_VPFE_CAPTURE
609 select VIDEO_VPSS_SYSTEM
610 default y
611 help
612 Enables DM355 CCD hw module. DM355 CCDC hw interfaces
613 with decoder modules such as TVP5146 over BT656 or
614 sensor module such as MT9T001 over a raw interface. This
615 module configures the interface and CCDC/ISIF to do
616 video frame capture from a slave decoders
617
618 To compile this driver as a module, choose M here: the
619 module will be called vpfe.
620
621config VIDEO_ISIF
622 tristate "ISIF HW module"
623 depends on ARCH_DAVINCI_DM365 && VIDEO_VPFE_CAPTURE
624 select VIDEO_VPSS_SYSTEM
625 default y
626 help
627 Enables ISIF hw module. This is the hardware module for
628 configuring ISIF in VPFE to capture Raw Bayer RGB data from
629 a image sensor or YUV data from a YUV source.
630
631 To compile this driver as a module, choose M here: the
632 module will be called vpfe.
633 554
634source "drivers/media/video/omap/Kconfig" 555source "drivers/media/video/omap/Kconfig"
635 556
@@ -955,6 +876,12 @@ config VIDEO_PXA27x
955 ---help--- 876 ---help---
956 This is a v4l2 driver for the PXA27x Quick Capture Interface 877 This is a v4l2 driver for the PXA27x Quick Capture Interface
957 878
879config VIDEO_SH_MOBILE_CSI2
880 tristate "SuperH Mobile MIPI CSI-2 Interface driver"
881 depends on VIDEO_DEV && SOC_CAMERA && HAVE_CLK
882 ---help---
883 This is a v4l2 driver for the SuperH MIPI CSI-2 Interface
884
958config VIDEO_SH_MOBILE_CEU 885config VIDEO_SH_MOBILE_CEU
959 tristate "SuperH Mobile CEU Interface driver" 886 tristate "SuperH Mobile CEU Interface driver"
960 depends on VIDEO_DEV && SOC_CAMERA && HAS_DMA && HAVE_CLK 887 depends on VIDEO_DEV && SOC_CAMERA && HAS_DMA && HAVE_CLK
@@ -1013,61 +940,6 @@ source "drivers/media/video/usbvideo/Kconfig"
1013 940
1014source "drivers/media/video/et61x251/Kconfig" 941source "drivers/media/video/et61x251/Kconfig"
1015 942
1016config VIDEO_OVCAMCHIP
1017 tristate "OmniVision Camera Chip support (DEPRECATED)"
1018 depends on I2C && VIDEO_V4L1
1019 default n
1020 ---help---
1021 This driver is DEPRECATED please use the gspca ov519 module
1022 instead. Note that for the ov511 / ov518 support of the gspca module
1023 you need atleast version 0.6.0 of libv4l and for the w9968cf
1024 atleast version 0.6.3 of libv4l.
1025
1026 Support for the OmniVision OV6xxx and OV7xxx series of camera chips.
1027 This driver is intended to be used with the ov511 and w9968cf USB
1028 camera drivers.
1029
1030 To compile this driver as a module, choose M here: the
1031 module will be called ovcamchip.
1032
1033config USB_W9968CF
1034 tristate "USB W996[87]CF JPEG Dual Mode Camera support (DEPRECATED)"
1035 depends on VIDEO_V4L1 && I2C && VIDEO_OVCAMCHIP
1036 default n
1037 ---help---
1038 This driver is DEPRECATED please use the gspca ov519 module
1039 instead. Note that for the w9968cf support of the gspca module
1040 you need atleast version 0.6.3 of libv4l.
1041
1042 Say Y here if you want support for cameras based on OV681 or
1043 Winbond W9967CF/W9968CF JPEG USB Dual Mode Camera Chips.
1044
1045 This driver has an optional plugin, which is distributed as a
1046 separate module only (released under GPL). It allows to use higher
1047 resolutions and framerates, but cannot be included in the official
1048 Linux kernel for performance purposes.
1049
1050 See <file:Documentation/video4linux/w9968cf.txt> for more info.
1051
1052 To compile this driver as a module, choose M here: the
1053 module will be called w9968cf.
1054
1055config USB_OV511
1056 tristate "USB OV511 Camera support (DEPRECATED)"
1057 depends on VIDEO_V4L1
1058 default n
1059 ---help---
1060 This driver is DEPRECATED please use the gspca ov519 module
1061 instead. Note that for the ov511 / ov518 support of the gspca module
1062 you need atleast version 0.6.0 of libv4l.
1063
1064 Say Y here if you want to connect this type of camera to your
1065 computer's USB port. See <file:Documentation/video4linux/ov511.txt>
1066 for more information and for a list of supported cameras.
1067
1068 To compile this driver as a module, choose M here: the
1069 module will be called ov511.
1070
1071config USB_SE401 943config USB_SE401
1072 tristate "USB SE401 Camera support" 944 tristate "USB SE401 Camera support"
1073 depends on VIDEO_V4L1 945 depends on VIDEO_V4L1
@@ -1081,25 +953,6 @@ config USB_SE401
1081 953
1082source "drivers/media/video/sn9c102/Kconfig" 954source "drivers/media/video/sn9c102/Kconfig"
1083 955
1084config USB_STV680
1085 tristate "USB STV680 (Pencam) Camera support (DEPRECATED)"
1086 depends on VIDEO_V4L1
1087 default n
1088 ---help---
1089 This driver is DEPRECATED please use the gspca stv0680 module
1090 instead. Note that for the gspca stv0680 module you need
1091 atleast version 0.6.3 of libv4l.
1092
1093 Say Y here if you want to connect this type of camera to your
1094 computer's USB port. This includes the Pencam line of cameras.
1095 See <file:Documentation/video4linux/stv680.txt> for more information
1096 and for a list of supported cameras.
1097
1098 To compile this driver as a module, choose M here: the
1099 module will be called stv680.
1100
1101source "drivers/media/video/zc0301/Kconfig"
1102
1103source "drivers/media/video/pwc/Kconfig" 956source "drivers/media/video/pwc/Kconfig"
1104 957
1105config USB_ZR364XX 958config USB_ZR364XX
diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile
index b08bd2b65cd0..1051ecc602e7 100644
--- a/drivers/media/video/Makefile
+++ b/drivers/media/video/Makefile
@@ -105,7 +105,6 @@ obj-$(CONFIG_VIDEO_TLG2300) += tlg2300/
105obj-$(CONFIG_VIDEO_CX231XX) += cx231xx/ 105obj-$(CONFIG_VIDEO_CX231XX) += cx231xx/
106obj-$(CONFIG_VIDEO_USBVISION) += usbvision/ 106obj-$(CONFIG_VIDEO_USBVISION) += usbvision/
107obj-$(CONFIG_VIDEO_PVRUSB2) += pvrusb2/ 107obj-$(CONFIG_VIDEO_PVRUSB2) += pvrusb2/
108obj-$(CONFIG_VIDEO_OVCAMCHIP) += ovcamchip/
109obj-$(CONFIG_VIDEO_CPIA2) += cpia2/ 108obj-$(CONFIG_VIDEO_CPIA2) += cpia2/
110obj-$(CONFIG_VIDEO_MXB) += mxb.o 109obj-$(CONFIG_VIDEO_MXB) += mxb.o
111obj-$(CONFIG_VIDEO_HEXIUM_ORION) += hexium_orion.o 110obj-$(CONFIG_VIDEO_HEXIUM_ORION) += hexium_orion.o
@@ -127,17 +126,13 @@ obj-$(CONFIG_VIDEO_CX2341X) += cx2341x.o
127obj-$(CONFIG_VIDEO_CAFE_CCIC) += cafe_ccic.o 126obj-$(CONFIG_VIDEO_CAFE_CCIC) += cafe_ccic.o
128 127
129obj-$(CONFIG_USB_DABUSB) += dabusb.o 128obj-$(CONFIG_USB_DABUSB) += dabusb.o
130obj-$(CONFIG_USB_OV511) += ov511.o
131obj-$(CONFIG_USB_SE401) += se401.o 129obj-$(CONFIG_USB_SE401) += se401.o
132obj-$(CONFIG_USB_STV680) += stv680.o
133obj-$(CONFIG_USB_W9968CF) += w9968cf.o
134obj-$(CONFIG_USB_ZR364XX) += zr364xx.o 130obj-$(CONFIG_USB_ZR364XX) += zr364xx.o
135obj-$(CONFIG_USB_STKWEBCAM) += stkwebcam.o 131obj-$(CONFIG_USB_STKWEBCAM) += stkwebcam.o
136 132
137obj-$(CONFIG_USB_SN9C102) += sn9c102/ 133obj-$(CONFIG_USB_SN9C102) += sn9c102/
138obj-$(CONFIG_USB_ET61X251) += et61x251/ 134obj-$(CONFIG_USB_ET61X251) += et61x251/
139obj-$(CONFIG_USB_PWC) += pwc/ 135obj-$(CONFIG_USB_PWC) += pwc/
140obj-$(CONFIG_USB_ZC0301) += zc0301/
141obj-$(CONFIG_USB_GSPCA) += gspca/ 136obj-$(CONFIG_USB_GSPCA) += gspca/
142 137
143obj-$(CONFIG_VIDEO_HDPVR) += hdpvr/ 138obj-$(CONFIG_VIDEO_HDPVR) += hdpvr/
@@ -151,6 +146,7 @@ obj-$(CONFIG_USB_S2255) += s2255drv.o
151obj-$(CONFIG_VIDEO_IVTV) += ivtv/ 146obj-$(CONFIG_VIDEO_IVTV) += ivtv/
152obj-$(CONFIG_VIDEO_CX18) += cx18/ 147obj-$(CONFIG_VIDEO_CX18) += cx18/
153 148
149obj-$(CONFIG_VIDEO_VIU) += fsl-viu.o
154obj-$(CONFIG_VIDEO_VIVI) += vivi.o 150obj-$(CONFIG_VIDEO_VIVI) += vivi.o
155obj-$(CONFIG_VIDEO_MEM2MEM_TESTDEV) += mem2mem_testdev.o 151obj-$(CONFIG_VIDEO_MEM2MEM_TESTDEV) += mem2mem_testdev.o
156obj-$(CONFIG_VIDEO_CX23885) += cx23885/ 152obj-$(CONFIG_VIDEO_CX23885) += cx23885/
@@ -165,6 +161,7 @@ obj-$(CONFIG_VIDEO_MX1) += mx1_camera.o
165obj-$(CONFIG_VIDEO_MX2) += mx2_camera.o 161obj-$(CONFIG_VIDEO_MX2) += mx2_camera.o
166obj-$(CONFIG_VIDEO_MX3) += mx3_camera.o 162obj-$(CONFIG_VIDEO_MX3) += mx3_camera.o
167obj-$(CONFIG_VIDEO_PXA27x) += pxa_camera.o 163obj-$(CONFIG_VIDEO_PXA27x) += pxa_camera.o
164obj-$(CONFIG_VIDEO_SH_MOBILE_CSI2) += sh_mobile_csi2.o
168obj-$(CONFIG_VIDEO_SH_MOBILE_CEU) += sh_mobile_ceu_camera.o 165obj-$(CONFIG_VIDEO_SH_MOBILE_CEU) += sh_mobile_ceu_camera.o
169 166
170obj-$(CONFIG_ARCH_DAVINCI) += davinci/ 167obj-$(CONFIG_ARCH_DAVINCI) += davinci/
@@ -178,7 +175,7 @@ obj-$(CONFIG_VIDEO_SAA7164) += saa7164/
178 175
179obj-$(CONFIG_VIDEO_IR_I2C) += ir-kbd-i2c.o 176obj-$(CONFIG_VIDEO_IR_I2C) += ir-kbd-i2c.o
180 177
181obj-$(CONFIG_ARCH_DAVINCI) += davinci/ 178obj-y += davinci/
182 179
183obj-$(CONFIG_ARCH_OMAP) += omap/ 180obj-$(CONFIG_ARCH_OMAP) += omap/
184 181
diff --git a/drivers/media/video/ak881x.c b/drivers/media/video/ak881x.c
index 1573392f74bd..b388654d48cd 100644
--- a/drivers/media/video/ak881x.c
+++ b/drivers/media/video/ak881x.c
@@ -126,7 +126,7 @@ static int ak881x_try_g_mbus_fmt(struct v4l2_subdev *sd,
126 v4l_bound_align_image(&mf->width, 0, 720, 2, 126 v4l_bound_align_image(&mf->width, 0, 720, 2,
127 &mf->height, 0, ak881x->lines, 1, 0); 127 &mf->height, 0, ak881x->lines, 1, 0);
128 mf->field = V4L2_FIELD_INTERLACED; 128 mf->field = V4L2_FIELD_INTERLACED;
129 mf->code = V4L2_MBUS_FMT_YUYV8_2X8_LE; 129 mf->code = V4L2_MBUS_FMT_YUYV8_2X8;
130 mf->colorspace = V4L2_COLORSPACE_SMPTE170M; 130 mf->colorspace = V4L2_COLORSPACE_SMPTE170M;
131 131
132 return 0; 132 return 0;
@@ -136,7 +136,7 @@ static int ak881x_s_mbus_fmt(struct v4l2_subdev *sd,
136 struct v4l2_mbus_framefmt *mf) 136 struct v4l2_mbus_framefmt *mf)
137{ 137{
138 if (mf->field != V4L2_FIELD_INTERLACED || 138 if (mf->field != V4L2_FIELD_INTERLACED ||
139 mf->code != V4L2_MBUS_FMT_YUYV8_2X8_LE) 139 mf->code != V4L2_MBUS_FMT_YUYV8_2X8)
140 return -EINVAL; 140 return -EINVAL;
141 141
142 return ak881x_try_g_mbus_fmt(sd, mf); 142 return ak881x_try_g_mbus_fmt(sd, mf);
@@ -148,7 +148,7 @@ static int ak881x_enum_mbus_fmt(struct v4l2_subdev *sd, unsigned int index,
148 if (index) 148 if (index)
149 return -EINVAL; 149 return -EINVAL;
150 150
151 *code = V4L2_MBUS_FMT_YUYV8_2X8_LE; 151 *code = V4L2_MBUS_FMT_YUYV8_2X8;
152 return 0; 152 return 0;
153} 153}
154 154
diff --git a/drivers/media/video/au0828/Makefile b/drivers/media/video/au0828/Makefile
index 4d2623158188..5c7f2f7d9805 100644
--- a/drivers/media/video/au0828/Makefile
+++ b/drivers/media/video/au0828/Makefile
@@ -1,4 +1,4 @@
1au0828-objs := au0828-core.o au0828-i2c.o au0828-cards.o au0828-dvb.o au0828-video.o 1au0828-objs := au0828-core.o au0828-i2c.o au0828-cards.o au0828-dvb.o au0828-video.o au0828-vbi.o
2 2
3obj-$(CONFIG_VIDEO_AU0828) += au0828.o 3obj-$(CONFIG_VIDEO_AU0828) += au0828.o
4 4
diff --git a/drivers/media/video/au0828/au0828-vbi.c b/drivers/media/video/au0828/au0828-vbi.c
new file mode 100644
index 000000000000..63f593070ee8
--- /dev/null
+++ b/drivers/media/video/au0828/au0828-vbi.c
@@ -0,0 +1,138 @@
1/*
2 au0828-vbi.c - VBI driver for au0828
3
4 Copyright (C) 2010 Devin Heitmueller <dheitmueller@kernellabs.com>
5
6 This work was sponsored by GetWellNetwork Inc.
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., 51 Franklin Street, Fifth Floor, Boston, MA
21 02110-1301, USA.
22 */
23
24#include <linux/kernel.h>
25#include <linux/module.h>
26#include <linux/init.h>
27#include <linux/slab.h>
28
29#include "au0828.h"
30
31static unsigned int vbibufs = 5;
32module_param(vbibufs, int, 0644);
33MODULE_PARM_DESC(vbibufs, "number of vbi buffers, range 2-32");
34
35/* ------------------------------------------------------------------ */
36
37static void
38free_buffer(struct videobuf_queue *vq, struct au0828_buffer *buf)
39{
40 struct au0828_fh *fh = vq->priv_data;
41 struct au0828_dev *dev = fh->dev;
42 unsigned long flags = 0;
43 if (in_interrupt())
44 BUG();
45
46 /* We used to wait for the buffer to finish here, but this didn't work
47 because, as we were keeping the state as VIDEOBUF_QUEUED,
48 videobuf_queue_cancel marked it as finished for us.
49 (Also, it could wedge forever if the hardware was misconfigured.)
50
51 This should be safe; by the time we get here, the buffer isn't
52 queued anymore. If we ever start marking the buffers as
53 VIDEOBUF_ACTIVE, it won't be, though.
54 */
55 spin_lock_irqsave(&dev->slock, flags);
56 if (dev->isoc_ctl.vbi_buf == buf)
57 dev->isoc_ctl.vbi_buf = NULL;
58 spin_unlock_irqrestore(&dev->slock, flags);
59
60 videobuf_vmalloc_free(&buf->vb);
61 buf->vb.state = VIDEOBUF_NEEDS_INIT;
62}
63
64static int
65vbi_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size)
66{
67 struct au0828_fh *fh = q->priv_data;
68 struct au0828_dev *dev = fh->dev;
69
70 *size = dev->vbi_width * dev->vbi_height * 2;
71
72 if (0 == *count)
73 *count = vbibufs;
74 if (*count < 2)
75 *count = 2;
76 if (*count > 32)
77 *count = 32;
78 return 0;
79}
80
81static int
82vbi_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
83 enum v4l2_field field)
84{
85 struct au0828_fh *fh = q->priv_data;
86 struct au0828_dev *dev = fh->dev;
87 struct au0828_buffer *buf = container_of(vb, struct au0828_buffer, vb);
88 int rc = 0;
89
90 buf->vb.size = dev->vbi_width * dev->vbi_height * 2;
91
92 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)
93 return -EINVAL;
94
95 buf->vb.width = dev->vbi_width;
96 buf->vb.height = dev->vbi_height;
97 buf->vb.field = field;
98
99 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
100 rc = videobuf_iolock(q, &buf->vb, NULL);
101 if (rc < 0)
102 goto fail;
103 }
104
105 buf->vb.state = VIDEOBUF_PREPARED;
106 return 0;
107
108fail:
109 free_buffer(q, buf);
110 return rc;
111}
112
113static void
114vbi_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
115{
116 struct au0828_buffer *buf = container_of(vb,
117 struct au0828_buffer,
118 vb);
119 struct au0828_fh *fh = vq->priv_data;
120 struct au0828_dev *dev = fh->dev;
121 struct au0828_dmaqueue *vbiq = &dev->vbiq;
122
123 buf->vb.state = VIDEOBUF_QUEUED;
124 list_add_tail(&buf->vb.queue, &vbiq->active);
125}
126
127static void vbi_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
128{
129 struct au0828_buffer *buf = container_of(vb, struct au0828_buffer, vb);
130 free_buffer(q, buf);
131}
132
133struct videobuf_queue_ops au0828_vbi_qops = {
134 .buf_setup = vbi_setup,
135 .buf_prepare = vbi_prepare,
136 .buf_queue = vbi_queue,
137 .buf_release = vbi_release,
138};
diff --git a/drivers/media/video/au0828/au0828-video.c b/drivers/media/video/au0828/au0828-video.c
index 52f25aabb6dc..7989a7ba7c40 100644
--- a/drivers/media/video/au0828/au0828-video.c
+++ b/drivers/media/video/au0828/au0828-video.c
@@ -314,6 +314,23 @@ static inline void buffer_filled(struct au0828_dev *dev,
314 wake_up(&buf->vb.done); 314 wake_up(&buf->vb.done);
315} 315}
316 316
317static inline void vbi_buffer_filled(struct au0828_dev *dev,
318 struct au0828_dmaqueue *dma_q,
319 struct au0828_buffer *buf)
320{
321 /* Advice that buffer was filled */
322 au0828_isocdbg("[%p/%d] wakeup\n", buf, buf->vb.i);
323
324 buf->vb.state = VIDEOBUF_DONE;
325 buf->vb.field_count++;
326 do_gettimeofday(&buf->vb.ts);
327
328 dev->isoc_ctl.vbi_buf = NULL;
329
330 list_del(&buf->vb.queue);
331 wake_up(&buf->vb.done);
332}
333
317/* 334/*
318 * Identify the buffer header type and properly handles 335 * Identify the buffer header type and properly handles
319 */ 336 */
@@ -327,6 +344,9 @@ static void au0828_copy_video(struct au0828_dev *dev,
327 int linesdone, currlinedone, offset, lencopy, remain; 344 int linesdone, currlinedone, offset, lencopy, remain;
328 int bytesperline = dev->width << 1; /* Assumes 16-bit depth @@@@ */ 345 int bytesperline = dev->width << 1; /* Assumes 16-bit depth @@@@ */
329 346
347 if (len == 0)
348 return;
349
330 if (dma_q->pos + len > buf->vb.size) 350 if (dma_q->pos + len > buf->vb.size)
331 len = buf->vb.size - dma_q->pos; 351 len = buf->vb.size - dma_q->pos;
332 352
@@ -414,17 +434,98 @@ static inline void get_next_buf(struct au0828_dmaqueue *dma_q,
414 return; 434 return;
415} 435}
416 436
437static void au0828_copy_vbi(struct au0828_dev *dev,
438 struct au0828_dmaqueue *dma_q,
439 struct au0828_buffer *buf,
440 unsigned char *p,
441 unsigned char *outp, unsigned long len)
442{
443 unsigned char *startwrite, *startread;
444 int bytesperline;
445 int i, j = 0;
446
447 if (dev == NULL) {
448 au0828_isocdbg("dev is null\n");
449 return;
450 }
451
452 if (dma_q == NULL) {
453 au0828_isocdbg("dma_q is null\n");
454 return;
455 }
456 if (buf == NULL)
457 return;
458 if (p == NULL) {
459 au0828_isocdbg("p is null\n");
460 return;
461 }
462 if (outp == NULL) {
463 au0828_isocdbg("outp is null\n");
464 return;
465 }
466
467 bytesperline = dev->vbi_width;
468
469 if (dma_q->pos + len > buf->vb.size)
470 len = buf->vb.size - dma_q->pos;
471
472 startread = p;
473 startwrite = outp + (dma_q->pos / 2);
474
475 /* Make sure the bottom field populates the second half of the frame */
476 if (buf->top_field == 0)
477 startwrite += bytesperline * dev->vbi_height;
478
479 for (i = 0; i < len; i += 2)
480 startwrite[j++] = startread[i+1];
481
482 dma_q->pos += len;
483}
484
485
486/*
487 * video-buf generic routine to get the next available VBI buffer
488 */
489static inline void vbi_get_next_buf(struct au0828_dmaqueue *dma_q,
490 struct au0828_buffer **buf)
491{
492 struct au0828_dev *dev = container_of(dma_q, struct au0828_dev, vbiq);
493 char *outp;
494
495 if (list_empty(&dma_q->active)) {
496 au0828_isocdbg("No active queue to serve\n");
497 dev->isoc_ctl.vbi_buf = NULL;
498 *buf = NULL;
499 return;
500 }
501
502 /* Get the next buffer */
503 *buf = list_entry(dma_q->active.next, struct au0828_buffer, vb.queue);
504 /* Cleans up buffer - Usefull for testing for frame/URB loss */
505 outp = videobuf_to_vmalloc(&(*buf)->vb);
506 memset(outp, 0x00, (*buf)->vb.size);
507
508 dev->isoc_ctl.vbi_buf = *buf;
509
510 return;
511}
512
417/* 513/*
418 * Controls the isoc copy of each urb packet 514 * Controls the isoc copy of each urb packet
419 */ 515 */
420static inline int au0828_isoc_copy(struct au0828_dev *dev, struct urb *urb) 516static inline int au0828_isoc_copy(struct au0828_dev *dev, struct urb *urb)
421{ 517{
422 struct au0828_buffer *buf; 518 struct au0828_buffer *buf;
519 struct au0828_buffer *vbi_buf;
423 struct au0828_dmaqueue *dma_q = urb->context; 520 struct au0828_dmaqueue *dma_q = urb->context;
521 struct au0828_dmaqueue *vbi_dma_q = &dev->vbiq;
424 unsigned char *outp = NULL; 522 unsigned char *outp = NULL;
523 unsigned char *vbioutp = NULL;
425 int i, len = 0, rc = 1; 524 int i, len = 0, rc = 1;
426 unsigned char *p; 525 unsigned char *p;
427 unsigned char fbyte; 526 unsigned char fbyte;
527 unsigned int vbi_field_size;
528 unsigned int remain, lencopy;
428 529
429 if (!dev) 530 if (!dev)
430 return 0; 531 return 0;
@@ -443,6 +544,10 @@ static inline int au0828_isoc_copy(struct au0828_dev *dev, struct urb *urb)
443 if (buf != NULL) 544 if (buf != NULL)
444 outp = videobuf_to_vmalloc(&buf->vb); 545 outp = videobuf_to_vmalloc(&buf->vb);
445 546
547 vbi_buf = dev->isoc_ctl.vbi_buf;
548 if (vbi_buf != NULL)
549 vbioutp = videobuf_to_vmalloc(&vbi_buf->vb);
550
446 for (i = 0; i < urb->number_of_packets; i++) { 551 for (i = 0; i < urb->number_of_packets; i++) {
447 int status = urb->iso_frame_desc[i].status; 552 int status = urb->iso_frame_desc[i].status;
448 553
@@ -472,6 +577,19 @@ static inline int au0828_isoc_copy(struct au0828_dev *dev, struct urb *urb)
472 au0828_isocdbg("Video frame %s\n", 577 au0828_isocdbg("Video frame %s\n",
473 (fbyte & 0x40) ? "odd" : "even"); 578 (fbyte & 0x40) ? "odd" : "even");
474 if (!(fbyte & 0x40)) { 579 if (!(fbyte & 0x40)) {
580 /* VBI */
581 if (vbi_buf != NULL)
582 vbi_buffer_filled(dev,
583 vbi_dma_q,
584 vbi_buf);
585 vbi_get_next_buf(vbi_dma_q, &vbi_buf);
586 if (vbi_buf == NULL)
587 vbioutp = NULL;
588 else
589 vbioutp = videobuf_to_vmalloc(
590 &vbi_buf->vb);
591
592 /* Video */
475 if (buf != NULL) 593 if (buf != NULL)
476 buffer_filled(dev, dma_q, buf); 594 buffer_filled(dev, dma_q, buf);
477 get_next_buf(dma_q, &buf); 595 get_next_buf(dma_q, &buf);
@@ -488,9 +606,36 @@ static inline int au0828_isoc_copy(struct au0828_dev *dev, struct urb *urb)
488 buf->top_field = 0; 606 buf->top_field = 0;
489 } 607 }
490 608
609 if (vbi_buf != NULL) {
610 if (fbyte & 0x40)
611 vbi_buf->top_field = 1;
612 else
613 vbi_buf->top_field = 0;
614 }
615
616 dev->vbi_read = 0;
617 vbi_dma_q->pos = 0;
491 dma_q->pos = 0; 618 dma_q->pos = 0;
492 } 619 }
493 if (buf != NULL) 620
621 vbi_field_size = dev->vbi_width * dev->vbi_height * 2;
622 if (dev->vbi_read < vbi_field_size) {
623 remain = vbi_field_size - dev->vbi_read;
624 if (len < remain)
625 lencopy = len;
626 else
627 lencopy = remain;
628
629 if (vbi_buf != NULL)
630 au0828_copy_vbi(dev, vbi_dma_q, vbi_buf, p,
631 vbioutp, len);
632
633 len -= lencopy;
634 p += lencopy;
635 dev->vbi_read += lencopy;
636 }
637
638 if (dev->vbi_read >= vbi_field_size && buf != NULL)
494 au0828_copy_video(dev, dma_q, buf, p, outp, len); 639 au0828_copy_video(dev, dma_q, buf, p, outp, len);
495 } 640 }
496 return rc; 641 return rc;
@@ -642,7 +787,7 @@ int au0828_analog_stream_enable(struct au0828_dev *d)
642 au0828_writereg(d, 0x114, 0xa0); 787 au0828_writereg(d, 0x114, 0xa0);
643 au0828_writereg(d, 0x115, 0x05); 788 au0828_writereg(d, 0x115, 0x05);
644 /* set y position */ 789 /* set y position */
645 au0828_writereg(d, 0x112, 0x02); 790 au0828_writereg(d, 0x112, 0x00);
646 au0828_writereg(d, 0x113, 0x00); 791 au0828_writereg(d, 0x113, 0x00);
647 au0828_writereg(d, 0x116, 0xf2); 792 au0828_writereg(d, 0x116, 0xf2);
648 au0828_writereg(d, 0x117, 0x00); 793 au0828_writereg(d, 0x117, 0x00);
@@ -703,47 +848,83 @@ void au0828_analog_unregister(struct au0828_dev *dev)
703 848
704 849
705/* Usage lock check functions */ 850/* Usage lock check functions */
706static int res_get(struct au0828_fh *fh) 851static int res_get(struct au0828_fh *fh, unsigned int bit)
707{ 852{
708 struct au0828_dev *dev = fh->dev; 853 struct au0828_dev *dev = fh->dev;
709 int rc = 0;
710 854
711 /* This instance already has stream_on */ 855 if (fh->resources & bit)
712 if (fh->stream_on) 856 /* have it already allocated */
713 return rc; 857 return 1;
714 858
715 if (dev->stream_on) 859 /* is it free? */
716 return -EBUSY; 860 mutex_lock(&dev->lock);
861 if (dev->resources & bit) {
862 /* no, someone else uses it */
863 mutex_unlock(&dev->lock);
864 return 0;
865 }
866 /* it's free, grab it */
867 fh->resources |= bit;
868 dev->resources |= bit;
869 dprintk(1, "res: get %d\n", bit);
870 mutex_unlock(&dev->lock);
871 return 1;
872}
717 873
718 dev->stream_on = 1; 874static int res_check(struct au0828_fh *fh, unsigned int bit)
719 fh->stream_on = 1; 875{
720 return rc; 876 return fh->resources & bit;
721} 877}
722 878
723static int res_check(struct au0828_fh *fh) 879static int res_locked(struct au0828_dev *dev, unsigned int bit)
724{ 880{
725 return fh->stream_on; 881 return dev->resources & bit;
726} 882}
727 883
728static void res_free(struct au0828_fh *fh) 884static void res_free(struct au0828_fh *fh, unsigned int bits)
729{ 885{
730 struct au0828_dev *dev = fh->dev; 886 struct au0828_dev *dev = fh->dev;
731 887
732 fh->stream_on = 0; 888 BUG_ON((fh->resources & bits) != bits);
733 dev->stream_on = 0; 889
890 mutex_lock(&dev->lock);
891 fh->resources &= ~bits;
892 dev->resources &= ~bits;
893 dprintk(1, "res: put %d\n", bits);
894 mutex_unlock(&dev->lock);
895}
896
897static int get_ressource(struct au0828_fh *fh)
898{
899 switch (fh->type) {
900 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
901 return AU0828_RESOURCE_VIDEO;
902 case V4L2_BUF_TYPE_VBI_CAPTURE:
903 return AU0828_RESOURCE_VBI;
904 default:
905 BUG();
906 return 0;
907 }
734} 908}
735 909
736static int au0828_v4l2_open(struct file *filp) 910static int au0828_v4l2_open(struct file *filp)
737{ 911{
738 int ret = 0; 912 int ret = 0;
913 struct video_device *vdev = video_devdata(filp);
739 struct au0828_dev *dev = video_drvdata(filp); 914 struct au0828_dev *dev = video_drvdata(filp);
740 struct au0828_fh *fh; 915 struct au0828_fh *fh;
741 int type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 916 int type;
742 917
743#ifdef VBI_IS_WORKING 918 switch (vdev->vfl_type) {
744 if (video_devdata(filp)->vfl_type == VFL_TYPE_GRABBER) 919 case VFL_TYPE_GRABBER:
920 type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
921 break;
922 case VFL_TYPE_VBI:
745 type = V4L2_BUF_TYPE_VBI_CAPTURE; 923 type = V4L2_BUF_TYPE_VBI_CAPTURE;
746#endif 924 break;
925 default:
926 return -EINVAL;
927 }
747 928
748 fh = kzalloc(sizeof(struct au0828_fh), GFP_KERNEL); 929 fh = kzalloc(sizeof(struct au0828_fh), GFP_KERNEL);
749 if (NULL == fh) { 930 if (NULL == fh) {
@@ -781,10 +962,21 @@ static int au0828_v4l2_open(struct file *filp)
781 dev->users++; 962 dev->users++;
782 963
783 videobuf_queue_vmalloc_init(&fh->vb_vidq, &au0828_video_qops, 964 videobuf_queue_vmalloc_init(&fh->vb_vidq, &au0828_video_qops,
784 NULL, &dev->slock, fh->type, 965 NULL, &dev->slock,
966 V4L2_BUF_TYPE_VIDEO_CAPTURE,
785 V4L2_FIELD_INTERLACED, 967 V4L2_FIELD_INTERLACED,
786 sizeof(struct au0828_buffer), fh); 968 sizeof(struct au0828_buffer), fh);
787 969
970 /* VBI Setup */
971 dev->vbi_width = 720;
972 dev->vbi_height = 1;
973 videobuf_queue_vmalloc_init(&fh->vb_vbiq, &au0828_vbi_qops,
974 NULL, &dev->slock,
975 V4L2_BUF_TYPE_VBI_CAPTURE,
976 V4L2_FIELD_SEQ_TB,
977 sizeof(struct au0828_buffer), fh);
978
979
788 return ret; 980 return ret;
789} 981}
790 982
@@ -794,17 +986,19 @@ static int au0828_v4l2_close(struct file *filp)
794 struct au0828_fh *fh = filp->private_data; 986 struct au0828_fh *fh = filp->private_data;
795 struct au0828_dev *dev = fh->dev; 987 struct au0828_dev *dev = fh->dev;
796 988
797 mutex_lock(&dev->lock); 989 if (res_check(fh, AU0828_RESOURCE_VIDEO)) {
798 if (res_check(fh))
799 res_free(fh);
800
801 if (dev->users == 1) {
802 videobuf_stop(&fh->vb_vidq); 990 videobuf_stop(&fh->vb_vidq);
803 videobuf_mmap_free(&fh->vb_vidq); 991 res_free(fh, AU0828_RESOURCE_VIDEO);
992 }
993
994 if (res_check(fh, AU0828_RESOURCE_VBI)) {
995 videobuf_stop(&fh->vb_vbiq);
996 res_free(fh, AU0828_RESOURCE_VBI);
997 }
804 998
999 if (dev->users == 1) {
805 if (dev->dev_state & DEV_DISCONNECTED) { 1000 if (dev->dev_state & DEV_DISCONNECTED) {
806 au0828_analog_unregister(dev); 1001 au0828_analog_unregister(dev);
807 mutex_unlock(&dev->lock);
808 kfree(dev); 1002 kfree(dev);
809 return 0; 1003 return 0;
810 } 1004 }
@@ -823,10 +1017,11 @@ static int au0828_v4l2_close(struct file *filp)
823 printk(KERN_INFO "Au0828 can't set alternate to 0!\n"); 1017 printk(KERN_INFO "Au0828 can't set alternate to 0!\n");
824 } 1018 }
825 1019
1020 videobuf_mmap_free(&fh->vb_vidq);
1021 videobuf_mmap_free(&fh->vb_vbiq);
826 kfree(fh); 1022 kfree(fh);
827 dev->users--; 1023 dev->users--;
828 wake_up_interruptible_nr(&dev->open, 1); 1024 wake_up_interruptible_nr(&dev->open, 1);
829 mutex_unlock(&dev->lock);
830 return 0; 1025 return 0;
831} 1026}
832 1027
@@ -842,16 +1037,21 @@ static ssize_t au0828_v4l2_read(struct file *filp, char __user *buf,
842 return rc; 1037 return rc;
843 1038
844 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { 1039 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
845 mutex_lock(&dev->lock); 1040 if (res_locked(dev, AU0828_RESOURCE_VIDEO))
846 rc = res_get(fh); 1041 return -EBUSY;
847 mutex_unlock(&dev->lock);
848
849 if (unlikely(rc < 0))
850 return rc;
851 1042
852 return videobuf_read_stream(&fh->vb_vidq, buf, count, pos, 0, 1043 return videobuf_read_stream(&fh->vb_vidq, buf, count, pos, 0,
853 filp->f_flags & O_NONBLOCK); 1044 filp->f_flags & O_NONBLOCK);
854 } 1045 }
1046
1047 if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
1048 if (!res_get(fh, AU0828_RESOURCE_VBI))
1049 return -EBUSY;
1050
1051 return videobuf_read_stream(&fh->vb_vbiq, buf, count, pos, 0,
1052 filp->f_flags & O_NONBLOCK);
1053 }
1054
855 return 0; 1055 return 0;
856} 1056}
857 1057
@@ -865,17 +1065,17 @@ static unsigned int au0828_v4l2_poll(struct file *filp, poll_table *wait)
865 if (rc < 0) 1065 if (rc < 0)
866 return rc; 1066 return rc;
867 1067
868 mutex_lock(&dev->lock); 1068 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
869 rc = res_get(fh); 1069 if (!res_get(fh, AU0828_RESOURCE_VIDEO))
870 mutex_unlock(&dev->lock); 1070 return POLLERR;
871 1071 return videobuf_poll_stream(filp, &fh->vb_vidq, wait);
872 if (unlikely(rc < 0)) 1072 } else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
873 return POLLERR; 1073 if (!res_get(fh, AU0828_RESOURCE_VBI))
874 1074 return POLLERR;
875 if (V4L2_BUF_TYPE_VIDEO_CAPTURE != fh->type) 1075 return videobuf_poll_stream(filp, &fh->vb_vbiq, wait);
1076 } else {
876 return POLLERR; 1077 return POLLERR;
877 1078 }
878 return videobuf_poll_stream(filp, &fh->vb_vidq, wait);
879} 1079}
880 1080
881static int au0828_v4l2_mmap(struct file *filp, struct vm_area_struct *vma) 1081static int au0828_v4l2_mmap(struct file *filp, struct vm_area_struct *vma)
@@ -888,14 +1088,10 @@ static int au0828_v4l2_mmap(struct file *filp, struct vm_area_struct *vma)
888 if (rc < 0) 1088 if (rc < 0)
889 return rc; 1089 return rc;
890 1090
891 mutex_lock(&dev->lock); 1091 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
892 rc = res_get(fh); 1092 rc = videobuf_mmap_mapper(&fh->vb_vidq, vma);
893 mutex_unlock(&dev->lock); 1093 else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE)
894 1094 rc = videobuf_mmap_mapper(&fh->vb_vbiq, vma);
895 if (unlikely(rc < 0))
896 return rc;
897
898 rc = videobuf_mmap_mapper(&fh->vb_vidq, vma);
899 1095
900 return rc; 1096 return rc;
901} 1097}
@@ -911,14 +1107,6 @@ static int au0828_set_format(struct au0828_dev *dev, unsigned int cmd,
911 maxwidth = 720; 1107 maxwidth = 720;
912 maxheight = 480; 1108 maxheight = 480;
913 1109
914#ifdef VBI_IS_WORKING
915 if (format->type == V4L2_BUF_TYPE_SLICED_VBI_CAPTURE) {
916 dprintk(1, "VBI format set: to be supported!\n");
917 return 0;
918 }
919 if (format->type == V4L2_BUF_TYPE_VBI_CAPTURE)
920 return 0;
921#endif
922 if (format->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 1110 if (format->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
923 return -EINVAL; 1111 return -EINVAL;
924 1112
@@ -999,9 +1187,7 @@ static int vidioc_querycap(struct file *file, void *priv,
999 1187
1000 /*set the device capabilities */ 1188 /*set the device capabilities */
1001 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | 1189 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE |
1002#ifdef VBI_IS_WORKING
1003 V4L2_CAP_VBI_CAPTURE | 1190 V4L2_CAP_VBI_CAPTURE |
1004#endif
1005 V4L2_CAP_AUDIO | 1191 V4L2_CAP_AUDIO |
1006 V4L2_CAP_READWRITE | 1192 V4L2_CAP_READWRITE |
1007 V4L2_CAP_STREAMING | 1193 V4L2_CAP_STREAMING |
@@ -1056,20 +1242,21 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
1056 struct au0828_dev *dev = fh->dev; 1242 struct au0828_dev *dev = fh->dev;
1057 int rc; 1243 int rc;
1058 1244
1245 rc = check_dev(dev);
1246 if (rc < 0)
1247 return rc;
1248
1249 mutex_lock(&dev->lock);
1250
1059 if (videobuf_queue_is_busy(&fh->vb_vidq)) { 1251 if (videobuf_queue_is_busy(&fh->vb_vidq)) {
1060 printk(KERN_INFO "%s queue busy\n", __func__); 1252 printk(KERN_INFO "%s queue busy\n", __func__);
1061 rc = -EBUSY; 1253 rc = -EBUSY;
1062 goto out; 1254 goto out;
1063 } 1255 }
1064 1256
1065 if (dev->stream_on && !fh->stream_on) { 1257 rc = au0828_set_format(dev, VIDIOC_S_FMT, f);
1066 printk(KERN_INFO "%s device in use by another fh\n", __func__);
1067 rc = -EBUSY;
1068 goto out;
1069 }
1070
1071 return au0828_set_format(dev, VIDIOC_S_FMT, f);
1072out: 1258out:
1259 mutex_unlock(&dev->lock);
1073 return rc; 1260 return rc;
1074} 1261}
1075 1262
@@ -1300,6 +1487,29 @@ static int vidioc_s_frequency(struct file *file, void *priv,
1300 return 0; 1487 return 0;
1301} 1488}
1302 1489
1490
1491/* RAW VBI ioctls */
1492
1493static int vidioc_g_fmt_vbi_cap(struct file *file, void *priv,
1494 struct v4l2_format *format)
1495{
1496 struct au0828_fh *fh = priv;
1497 struct au0828_dev *dev = fh->dev;
1498
1499 format->fmt.vbi.samples_per_line = dev->vbi_width;
1500 format->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
1501 format->fmt.vbi.offset = 0;
1502 format->fmt.vbi.flags = 0;
1503 format->fmt.vbi.sampling_rate = 6750000 * 4 / 2;
1504
1505 format->fmt.vbi.count[0] = dev->vbi_height;
1506 format->fmt.vbi.count[1] = dev->vbi_height;
1507 format->fmt.vbi.start[0] = 21;
1508 format->fmt.vbi.start[1] = 284;
1509
1510 return 0;
1511}
1512
1303static int vidioc_g_chip_ident(struct file *file, void *priv, 1513static int vidioc_g_chip_ident(struct file *file, void *priv,
1304 struct v4l2_dbg_chip_ident *chip) 1514 struct v4l2_dbg_chip_ident *chip)
1305{ 1515{
@@ -1345,25 +1555,32 @@ static int vidioc_cropcap(struct file *file, void *priv,
1345static int vidioc_streamon(struct file *file, void *priv, 1555static int vidioc_streamon(struct file *file, void *priv,
1346 enum v4l2_buf_type type) 1556 enum v4l2_buf_type type)
1347{ 1557{
1348 struct au0828_fh *fh = priv; 1558 struct au0828_fh *fh = priv;
1349 struct au0828_dev *dev = fh->dev; 1559 struct au0828_dev *dev = fh->dev;
1350 int rc; 1560 int rc = -EINVAL;
1351 1561
1352 rc = check_dev(dev); 1562 rc = check_dev(dev);
1353 if (rc < 0) 1563 if (rc < 0)
1354 return rc; 1564 return rc;
1355 1565
1566 if (unlikely(type != fh->type))
1567 return -EINVAL;
1568
1569 dprintk(1, "vidioc_streamon fh=%p t=%d fh->res=%d dev->res=%d\n",
1570 fh, type, fh->resources, dev->resources);
1571
1572 if (unlikely(!res_get(fh, get_ressource(fh))))
1573 return -EBUSY;
1574
1356 if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { 1575 if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1357 au0828_analog_stream_enable(dev); 1576 au0828_analog_stream_enable(dev);
1358 v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_stream, 1); 1577 v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_stream, 1);
1359 } 1578 }
1360 1579
1361 mutex_lock(&dev->lock); 1580 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1362 rc = res_get(fh);
1363
1364 if (likely(rc >= 0))
1365 rc = videobuf_streamon(&fh->vb_vidq); 1581 rc = videobuf_streamon(&fh->vb_vidq);
1366 mutex_unlock(&dev->lock); 1582 else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE)
1583 rc = videobuf_streamon(&fh->vb_vbiq);
1367 1584
1368 return rc; 1585 return rc;
1369} 1586}
@@ -1371,38 +1588,42 @@ static int vidioc_streamon(struct file *file, void *priv,
1371static int vidioc_streamoff(struct file *file, void *priv, 1588static int vidioc_streamoff(struct file *file, void *priv,
1372 enum v4l2_buf_type type) 1589 enum v4l2_buf_type type)
1373{ 1590{
1374 struct au0828_fh *fh = priv; 1591 struct au0828_fh *fh = priv;
1375 struct au0828_dev *dev = fh->dev; 1592 struct au0828_dev *dev = fh->dev;
1376 int i; 1593 int rc;
1377 int ret; 1594 int i;
1378 int rc;
1379 1595
1380 rc = check_dev(dev); 1596 rc = check_dev(dev);
1381 if (rc < 0) 1597 if (rc < 0)
1382 return rc; 1598 return rc;
1383 1599
1384 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 1600 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
1601 fh->type != V4L2_BUF_TYPE_VBI_CAPTURE)
1385 return -EINVAL; 1602 return -EINVAL;
1386 if (type != fh->type) 1603 if (type != fh->type)
1387 return -EINVAL; 1604 return -EINVAL;
1388 1605
1389 if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { 1606 dprintk(1, "vidioc_streamoff fh=%p t=%d fh->res=%d dev->res=%d\n",
1607 fh, type, fh->resources, dev->resources);
1608
1609 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1390 v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_stream, 0); 1610 v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_stream, 0);
1391 ret = au0828_stream_interrupt(dev); 1611 rc = au0828_stream_interrupt(dev);
1392 if (ret != 0) 1612 if (rc != 0)
1393 return ret; 1613 return rc;
1394 }
1395 1614
1396 for (i = 0; i < AU0828_MAX_INPUT; i++) { 1615 for (i = 0; i < AU0828_MAX_INPUT; i++) {
1397 if (AUVI_INPUT(i).audio_setup == NULL) 1616 if (AUVI_INPUT(i).audio_setup == NULL)
1398 continue; 1617 continue;
1399 (AUVI_INPUT(i).audio_setup)(dev, 0); 1618 (AUVI_INPUT(i).audio_setup)(dev, 0);
1400 } 1619 }
1401 1620
1402 mutex_lock(&dev->lock); 1621 videobuf_streamoff(&fh->vb_vidq);
1403 videobuf_streamoff(&fh->vb_vidq); 1622 res_free(fh, AU0828_RESOURCE_VIDEO);
1404 res_free(fh); 1623 } else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
1405 mutex_unlock(&dev->lock); 1624 videobuf_streamoff(&fh->vb_vbiq);
1625 res_free(fh, AU0828_RESOURCE_VBI);
1626 }
1406 1627
1407 return 0; 1628 return 0;
1408} 1629}
@@ -1527,19 +1748,11 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
1527 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap, 1748 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
1528 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap, 1749 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
1529 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap, 1750 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
1530#ifdef VBI_IS_WORKING
1531 .vidioc_g_fmt_vbi_cap = vidioc_g_fmt_vbi_cap, 1751 .vidioc_g_fmt_vbi_cap = vidioc_g_fmt_vbi_cap,
1532 .vidioc_try_fmt_vbi_cap = vidioc_s_fmt_vbi_cap, 1752 .vidioc_s_fmt_vbi_cap = vidioc_g_fmt_vbi_cap,
1533 .vidioc_s_fmt_vbi_cap = vidioc_s_fmt_vbi_cap,
1534#endif
1535 .vidioc_g_audio = vidioc_g_audio, 1753 .vidioc_g_audio = vidioc_g_audio,
1536 .vidioc_s_audio = vidioc_s_audio, 1754 .vidioc_s_audio = vidioc_s_audio,
1537 .vidioc_cropcap = vidioc_cropcap, 1755 .vidioc_cropcap = vidioc_cropcap,
1538#ifdef VBI_IS_WORKING
1539 .vidioc_g_fmt_sliced_vbi_cap = vidioc_g_fmt_sliced_vbi_cap,
1540 .vidioc_try_fmt_sliced_vbi_cap = vidioc_try_set_sliced_vbi_cap,
1541 .vidioc_s_fmt_sliced_vbi_cap = vidioc_try_set_sliced_vbi_cap,
1542#endif
1543 .vidioc_reqbufs = vidioc_reqbufs, 1756 .vidioc_reqbufs = vidioc_reqbufs,
1544 .vidioc_querybuf = vidioc_querybuf, 1757 .vidioc_querybuf = vidioc_querybuf,
1545 .vidioc_qbuf = vidioc_qbuf, 1758 .vidioc_qbuf = vidioc_qbuf,
@@ -1621,8 +1834,11 @@ int au0828_analog_register(struct au0828_dev *dev,
1621 spin_lock_init(&dev->slock); 1834 spin_lock_init(&dev->slock);
1622 mutex_init(&dev->lock); 1835 mutex_init(&dev->lock);
1623 1836
1837 /* init video dma queues */
1624 INIT_LIST_HEAD(&dev->vidq.active); 1838 INIT_LIST_HEAD(&dev->vidq.active);
1625 INIT_LIST_HEAD(&dev->vidq.queued); 1839 INIT_LIST_HEAD(&dev->vidq.queued);
1840 INIT_LIST_HEAD(&dev->vbiq.active);
1841 INIT_LIST_HEAD(&dev->vbiq.queued);
1626 1842
1627 dev->width = NTSC_STD_W; 1843 dev->width = NTSC_STD_W;
1628 dev->height = NTSC_STD_H; 1844 dev->height = NTSC_STD_H;
@@ -1638,26 +1854,23 @@ int au0828_analog_register(struct au0828_dev *dev,
1638 return -ENOMEM; 1854 return -ENOMEM;
1639 } 1855 }
1640 1856
1641#ifdef VBI_IS_WORKING 1857 /* allocate the VBI struct */
1642 dev->vbi_dev = video_device_alloc(); 1858 dev->vbi_dev = video_device_alloc();
1643 if (NULL == dev->vbi_dev) { 1859 if (NULL == dev->vbi_dev) {
1644 dprintk(1, "Can't allocate vbi_device.\n"); 1860 dprintk(1, "Can't allocate vbi_device.\n");
1645 kfree(dev->vdev); 1861 kfree(dev->vdev);
1646 return -ENOMEM; 1862 return -ENOMEM;
1647 } 1863 }
1648#endif
1649 1864
1650 /* Fill the video capture device struct */ 1865 /* Fill the video capture device struct */
1651 *dev->vdev = au0828_video_template; 1866 *dev->vdev = au0828_video_template;
1652 dev->vdev->parent = &dev->usbdev->dev; 1867 dev->vdev->parent = &dev->usbdev->dev;
1653 strcpy(dev->vdev->name, "au0828a video"); 1868 strcpy(dev->vdev->name, "au0828a video");
1654 1869
1655#ifdef VBI_IS_WORKING
1656 /* Setup the VBI device */ 1870 /* Setup the VBI device */
1657 *dev->vbi_dev = au0828_video_template; 1871 *dev->vbi_dev = au0828_video_template;
1658 dev->vbi_dev->parent = &dev->usbdev->dev; 1872 dev->vbi_dev->parent = &dev->usbdev->dev;
1659 strcpy(dev->vbi_dev->name, "au0828a vbi"); 1873 strcpy(dev->vbi_dev->name, "au0828a vbi");
1660#endif
1661 1874
1662 /* Register the v4l2 device */ 1875 /* Register the v4l2 device */
1663 video_set_drvdata(dev->vdev, dev); 1876 video_set_drvdata(dev->vdev, dev);
@@ -1669,7 +1882,6 @@ int au0828_analog_register(struct au0828_dev *dev,
1669 return -ENODEV; 1882 return -ENODEV;
1670 } 1883 }
1671 1884
1672#ifdef VBI_IS_WORKING
1673 /* Register the vbi device */ 1885 /* Register the vbi device */
1674 video_set_drvdata(dev->vbi_dev, dev); 1886 video_set_drvdata(dev->vbi_dev, dev);
1675 retval = video_register_device(dev->vbi_dev, VFL_TYPE_VBI, -1); 1887 retval = video_register_device(dev->vbi_dev, VFL_TYPE_VBI, -1);
@@ -1680,7 +1892,6 @@ int au0828_analog_register(struct au0828_dev *dev,
1680 video_device_release(dev->vdev); 1892 video_device_release(dev->vdev);
1681 return -ENODEV; 1893 return -ENODEV;
1682 } 1894 }
1683#endif
1684 1895
1685 dprintk(1, "%s completed!\n", __func__); 1896 dprintk(1, "%s completed!\n", __func__);
1686 1897
diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
index 207f32dec6a6..9905bc4f5f59 100644
--- a/drivers/media/video/au0828/au0828.h
+++ b/drivers/media/video/au0828/au0828.h
@@ -60,6 +60,10 @@
60 60
61#define AU0828_MAX_INPUT 4 61#define AU0828_MAX_INPUT 4
62 62
63/* au0828 resource types (used for res_get/res_lock etc */
64#define AU0828_RESOURCE_VIDEO 0x01
65#define AU0828_RESOURCE_VBI 0x02
66
63enum au0828_itype { 67enum au0828_itype {
64 AU0828_VMUX_UNDEFINED = 0, 68 AU0828_VMUX_UNDEFINED = 0,
65 AU0828_VMUX_COMPOSITE, 69 AU0828_VMUX_COMPOSITE,
@@ -115,8 +119,10 @@ enum au0828_dev_state {
115 119
116struct au0828_fh { 120struct au0828_fh {
117 struct au0828_dev *dev; 121 struct au0828_dev *dev;
118 unsigned int stream_on:1; /* Locks streams */ 122 unsigned int resources;
123
119 struct videobuf_queue vb_vidq; 124 struct videobuf_queue vb_vidq;
125 struct videobuf_queue vb_vbiq;
120 enum v4l2_buf_type type; 126 enum v4l2_buf_type type;
121}; 127};
122 128
@@ -145,7 +151,8 @@ struct au0828_usb_isoc_ctl {
145 int tmp_buf_len; 151 int tmp_buf_len;
146 152
147 /* Stores already requested buffers */ 153 /* Stores already requested buffers */
148 struct au0828_buffer *buf; 154 struct au0828_buffer *buf;
155 struct au0828_buffer *vbi_buf;
149 156
150 /* Stores the number of received fields */ 157 /* Stores the number of received fields */
151 int nfields; 158 int nfields;
@@ -194,11 +201,14 @@ struct au0828_dev {
194 /* Analog */ 201 /* Analog */
195 struct v4l2_device v4l2_dev; 202 struct v4l2_device v4l2_dev;
196 int users; 203 int users;
197 unsigned int stream_on:1; /* Locks streams */ 204 unsigned int resources; /* resources in use */
198 struct video_device *vdev; 205 struct video_device *vdev;
199 struct video_device *vbi_dev; 206 struct video_device *vbi_dev;
200 int width; 207 int width;
201 int height; 208 int height;
209 int vbi_width;
210 int vbi_height;
211 u32 vbi_read;
202 u32 field_size; 212 u32 field_size;
203 u32 frame_size; 213 u32 frame_size;
204 u32 bytesperline; 214 u32 bytesperline;
@@ -219,6 +229,7 @@ struct au0828_dev {
219 229
220 /* Isoc control struct */ 230 /* Isoc control struct */
221 struct au0828_dmaqueue vidq; 231 struct au0828_dmaqueue vidq;
232 struct au0828_dmaqueue vbiq;
222 struct au0828_usb_isoc_ctl isoc_ctl; 233 struct au0828_usb_isoc_ctl isoc_ctl;
223 spinlock_t slock; 234 spinlock_t slock;
224 235
@@ -278,6 +289,9 @@ void au0828_analog_unregister(struct au0828_dev *dev);
278extern int au0828_dvb_register(struct au0828_dev *dev); 289extern int au0828_dvb_register(struct au0828_dev *dev);
279extern void au0828_dvb_unregister(struct au0828_dev *dev); 290extern void au0828_dvb_unregister(struct au0828_dev *dev);
280 291
292/* au0828-vbi.c */
293extern struct videobuf_queue_ops au0828_vbi_qops;
294
281#define dprintk(level, fmt, arg...)\ 295#define dprintk(level, fmt, arg...)\
282 do { if (au0828_debug & level)\ 296 do { if (au0828_debug & level)\
283 printk(KERN_DEBUG DRIVER_NAME "/0: " fmt, ## arg);\ 297 printk(KERN_DEBUG DRIVER_NAME "/0: " fmt, ## arg);\
diff --git a/drivers/media/video/bt8xx/bttv-risc.c b/drivers/media/video/bt8xx/bttv-risc.c
index c24b1c100e13..0fa9f39f37a3 100644
--- a/drivers/media/video/bt8xx/bttv-risc.c
+++ b/drivers/media/video/bt8xx/bttv-risc.c
@@ -583,7 +583,7 @@ bttv_dma_free(struct videobuf_queue *q,struct bttv *btv, struct bttv_buffer *buf
583 583
584 BUG_ON(in_interrupt()); 584 BUG_ON(in_interrupt());
585 videobuf_waiton(&buf->vb,0,0); 585 videobuf_waiton(&buf->vb,0,0);
586 videobuf_dma_unmap(q, dma); 586 videobuf_dma_unmap(q->dev, dma);
587 videobuf_dma_free(dma); 587 videobuf_dma_free(dma);
588 btcx_riscmem_free(btv->c.pci,&buf->bottom); 588 btcx_riscmem_free(btv->c.pci,&buf->bottom);
589 btcx_riscmem_free(btv->c.pci,&buf->top); 589 btcx_riscmem_free(btv->c.pci,&buf->top);
diff --git a/drivers/media/video/cpia_usb.c b/drivers/media/video/cpia_usb.c
index ef1f89399983..58d193ff591c 100644
--- a/drivers/media/video/cpia_usb.c
+++ b/drivers/media/video/cpia_usb.c
@@ -584,7 +584,6 @@ static void cpia_disconnect(struct usb_interface *intf)
584{ 584{
585 struct cam_data *cam = usb_get_intfdata(intf); 585 struct cam_data *cam = usb_get_intfdata(intf);
586 struct usb_cpia *ucpia; 586 struct usb_cpia *ucpia;
587 struct usb_device *udev;
588 587
589 usb_set_intfdata(intf, NULL); 588 usb_set_intfdata(intf, NULL);
590 if (!cam) 589 if (!cam)
@@ -606,8 +605,6 @@ static void cpia_disconnect(struct usb_interface *intf)
606 if (waitqueue_active(&ucpia->wq_stream)) 605 if (waitqueue_active(&ucpia->wq_stream))
607 wake_up_interruptible(&ucpia->wq_stream); 606 wake_up_interruptible(&ucpia->wq_stream);
608 607
609 udev = interface_to_usbdev(intf);
610
611 ucpia->curbuff = ucpia->workbuff = NULL; 608 ucpia->curbuff = ucpia->workbuff = NULL;
612 609
613 vfree(ucpia->buffers[2]); 610 vfree(ucpia->buffers[2]);
diff --git a/drivers/media/video/cx18/cx18-ioctl.c b/drivers/media/video/cx18/cx18-ioctl.c
index 20eaf38ba959..d6792405f8d3 100644
--- a/drivers/media/video/cx18/cx18-ioctl.c
+++ b/drivers/media/video/cx18/cx18-ioctl.c
@@ -1081,7 +1081,7 @@ long cx18_v4l2_ioctl(struct file *filp, unsigned int cmd,
1081 unsigned long arg) 1081 unsigned long arg)
1082{ 1082{
1083 struct video_device *vfd = video_devdata(filp); 1083 struct video_device *vfd = video_devdata(filp);
1084 struct cx18_open_id *id = (struct cx18_open_id *)filp->private_data; 1084 struct cx18_open_id *id = filp->private_data;
1085 struct cx18 *cx = id->cx; 1085 struct cx18 *cx = id->cx;
1086 long res; 1086 long res;
1087 1087
diff --git a/drivers/media/video/cx23885/cx23885-cards.c b/drivers/media/video/cx23885/cx23885-cards.c
index d639186f645d..2014daedee8b 100644
--- a/drivers/media/video/cx23885/cx23885-cards.c
+++ b/drivers/media/video/cx23885/cx23885-cards.c
@@ -408,10 +408,18 @@ struct cx23885_subid cx23885_subids[] = {
408 .card = CX23885_BOARD_HAUPPAUGE_HVR1275, 408 .card = CX23885_BOARD_HAUPPAUGE_HVR1275,
409 }, { 409 }, {
410 .subvendor = 0x0070, 410 .subvendor = 0x0070,
411 .subdevice = 0x221d,
412 .card = CX23885_BOARD_HAUPPAUGE_HVR1275,
413 }, {
414 .subvendor = 0x0070,
411 .subdevice = 0x2251, 415 .subdevice = 0x2251,
412 .card = CX23885_BOARD_HAUPPAUGE_HVR1255, 416 .card = CX23885_BOARD_HAUPPAUGE_HVR1255,
413 }, { 417 }, {
414 .subvendor = 0x0070, 418 .subvendor = 0x0070,
419 .subdevice = 0x2259,
420 .card = CX23885_BOARD_HAUPPAUGE_HVR1255,
421 }, {
422 .subvendor = 0x0070,
415 .subdevice = 0x2291, 423 .subdevice = 0x2291,
416 .card = CX23885_BOARD_HAUPPAUGE_HVR1210, 424 .card = CX23885_BOARD_HAUPPAUGE_HVR1210,
417 }, { 425 }, {
@@ -419,6 +427,38 @@ struct cx23885_subid cx23885_subids[] = {
419 .subdevice = 0x2295, 427 .subdevice = 0x2295,
420 .card = CX23885_BOARD_HAUPPAUGE_HVR1210, 428 .card = CX23885_BOARD_HAUPPAUGE_HVR1210,
421 }, { 429 }, {
430 .subvendor = 0x0070,
431 .subdevice = 0x2299,
432 .card = CX23885_BOARD_HAUPPAUGE_HVR1210,
433 }, {
434 .subvendor = 0x0070,
435 .subdevice = 0x229d,
436 .card = CX23885_BOARD_HAUPPAUGE_HVR1210, /* HVR1215 */
437 }, {
438 .subvendor = 0x0070,
439 .subdevice = 0x22f0,
440 .card = CX23885_BOARD_HAUPPAUGE_HVR1210,
441 }, {
442 .subvendor = 0x0070,
443 .subdevice = 0x22f1,
444 .card = CX23885_BOARD_HAUPPAUGE_HVR1255,
445 }, {
446 .subvendor = 0x0070,
447 .subdevice = 0x22f2,
448 .card = CX23885_BOARD_HAUPPAUGE_HVR1275,
449 }, {
450 .subvendor = 0x0070,
451 .subdevice = 0x22f3,
452 .card = CX23885_BOARD_HAUPPAUGE_HVR1210, /* HVR1215 */
453 }, {
454 .subvendor = 0x0070,
455 .subdevice = 0x22f4,
456 .card = CX23885_BOARD_HAUPPAUGE_HVR1210,
457 }, {
458 .subvendor = 0x0070,
459 .subdevice = 0x22f5,
460 .card = CX23885_BOARD_HAUPPAUGE_HVR1210, /* HVR1215 */
461 }, {
422 .subvendor = 0x14f1, 462 .subvendor = 0x14f1,
423 .subdevice = 0x8651, 463 .subdevice = 0x8651,
424 .card = CX23885_BOARD_MYGICA_X8506, 464 .card = CX23885_BOARD_MYGICA_X8506,
diff --git a/drivers/media/video/cx23885/cx23885-core.c b/drivers/media/video/cx23885/cx23885-core.c
index 0dde57e96d30..ff76f64edac1 100644
--- a/drivers/media/video/cx23885/cx23885-core.c
+++ b/drivers/media/video/cx23885/cx23885-core.c
@@ -1142,7 +1142,7 @@ void cx23885_free_buffer(struct videobuf_queue *q, struct cx23885_buffer *buf)
1142 1142
1143 BUG_ON(in_interrupt()); 1143 BUG_ON(in_interrupt());
1144 videobuf_waiton(&buf->vb, 0, 0); 1144 videobuf_waiton(&buf->vb, 0, 0);
1145 videobuf_dma_unmap(q, dma); 1145 videobuf_dma_unmap(q->dev, dma);
1146 videobuf_dma_free(dma); 1146 videobuf_dma_free(dma);
1147 btcx_riscmem_free(to_pci_dev(q->dev), &buf->risc); 1147 btcx_riscmem_free(to_pci_dev(q->dev), &buf->risc);
1148 buf->vb.state = VIDEOBUF_NEEDS_INIT; 1148 buf->vb.state = VIDEOBUF_NEEDS_INIT;
@@ -1953,8 +1953,12 @@ static int __devinit cx23885_initdev(struct pci_dev *pci_dev,
1953 goto fail_irq; 1953 goto fail_irq;
1954 } 1954 }
1955 1955
1956 err = request_irq(pci_dev->irq, cx23885_irq, 1956 if (!pci_enable_msi(pci_dev))
1957 IRQF_SHARED | IRQF_DISABLED, dev->name, dev); 1957 err = request_irq(pci_dev->irq, cx23885_irq,
1958 IRQF_DISABLED, dev->name, dev);
1959 else
1960 err = request_irq(pci_dev->irq, cx23885_irq,
1961 IRQF_SHARED | IRQF_DISABLED, dev->name, dev);
1958 if (err < 0) { 1962 if (err < 0) {
1959 printk(KERN_ERR "%s: can't get IRQ %d\n", 1963 printk(KERN_ERR "%s: can't get IRQ %d\n",
1960 dev->name, pci_dev->irq); 1964 dev->name, pci_dev->irq);
@@ -2000,6 +2004,7 @@ static void __devexit cx23885_finidev(struct pci_dev *pci_dev)
2000 2004
2001 /* unregister stuff */ 2005 /* unregister stuff */
2002 free_irq(pci_dev->irq, dev); 2006 free_irq(pci_dev->irq, dev);
2007 pci_disable_msi(pci_dev);
2003 2008
2004 cx23885_dev_unregister(dev); 2009 cx23885_dev_unregister(dev);
2005 v4l2_device_unregister(v4l2_dev); 2010 v4l2_device_unregister(v4l2_dev);
diff --git a/drivers/media/video/cx23885/cx23885-dvb.c b/drivers/media/video/cx23885/cx23885-dvb.c
index 0a199d774d9b..3d70af283881 100644
--- a/drivers/media/video/cx23885/cx23885-dvb.c
+++ b/drivers/media/video/cx23885/cx23885-dvb.c
@@ -991,7 +991,7 @@ static int dvb_register(struct cx23885_tsport *port)
991 ret = videobuf_dvb_register_bus(&port->frontends, THIS_MODULE, port, 991 ret = videobuf_dvb_register_bus(&port->frontends, THIS_MODULE, port,
992 &dev->pci->dev, adapter_nr, 0, 992 &dev->pci->dev, adapter_nr, 0,
993 cx23885_dvb_fe_ioctl_override); 993 cx23885_dvb_fe_ioctl_override);
994 if (!ret) 994 if (ret)
995 return ret; 995 return ret;
996 996
997 /* init CI & MAC */ 997 /* init CI & MAC */
diff --git a/drivers/media/video/cx23885/cx23885-input.c b/drivers/media/video/cx23885/cx23885-input.c
index 5de6ba98f7a8..d0b1613ede2f 100644
--- a/drivers/media/video/cx23885/cx23885-input.c
+++ b/drivers/media/video/cx23885/cx23885-input.c
@@ -37,161 +37,55 @@
37 37
38#include <linux/input.h> 38#include <linux/input.h>
39#include <linux/slab.h> 39#include <linux/slab.h>
40#include <media/ir-common.h> 40#include <media/ir-core.h>
41#include <media/v4l2-subdev.h> 41#include <media/v4l2-subdev.h>
42 42
43#include "cx23885.h" 43#include "cx23885.h"
44 44
45#define RC5_BITS 14
46#define RC5_HALF_BITS (2*RC5_BITS)
47#define RC5_HALF_BITS_MASK ((1 << RC5_HALF_BITS) - 1)
48
49#define RC5_START_BITS_NORMAL 0x3 /* Command range 0 - 63 */
50#define RC5_START_BITS_EXTENDED 0x2 /* Command range 64 - 127 */
51
52#define RC5_EXTENDED_COMMAND_OFFSET 64
53
54#define MODULE_NAME "cx23885" 45#define MODULE_NAME "cx23885"
55 46
56static inline unsigned int rc5_command(u32 rc5_baseband) 47static void convert_measurement(u32 x, struct ir_raw_event *y)
57{ 48{
58 return RC5_INSTR(rc5_baseband) + 49 if (x == V4L2_SUBDEV_IR_PULSE_RX_SEQ_END) {
59 ((RC5_START(rc5_baseband) == RC5_START_BITS_EXTENDED) 50 y->pulse = false;
60 ? RC5_EXTENDED_COMMAND_OFFSET : 0); 51 y->duration = V4L2_SUBDEV_IR_PULSE_MAX_WIDTH_NS;
61}
62
63static void cx23885_input_process_raw_rc5(struct cx23885_dev *dev)
64{
65 struct card_ir *ir_input = dev->ir_input;
66 unsigned int code, command;
67 u32 rc5;
68
69 /* Ignore codes that are too short to be valid RC-5 */
70 if (ir_input->last_bit < (RC5_HALF_BITS - 1))
71 return;
72
73 /* The library has the manchester coding backwards; XOR to adapt. */
74 code = (ir_input->code & RC5_HALF_BITS_MASK) ^ RC5_HALF_BITS_MASK;
75 rc5 = ir_rc5_decode(code);
76
77 switch (RC5_START(rc5)) {
78 case RC5_START_BITS_NORMAL:
79 break;
80 case RC5_START_BITS_EXTENDED:
81 /* Don't allow if the remote only emits standard commands */
82 if (ir_input->start == RC5_START_BITS_NORMAL)
83 return;
84 break;
85 default:
86 return; 52 return;
87 } 53 }
88 54
89 if (ir_input->addr != RC5_ADDR(rc5)) 55 y->pulse = (x & V4L2_SUBDEV_IR_PULSE_LEVEL_MASK) ? true : false;
90 return; 56 y->duration = x & V4L2_SUBDEV_IR_PULSE_MAX_WIDTH_NS;
91
92 /* Don't generate a keypress for RC-5 auto-repeated keypresses */
93 command = rc5_command(rc5);
94 if (RC5_TOGGLE(rc5) != RC5_TOGGLE(ir_input->last_rc5) ||
95 command != rc5_command(ir_input->last_rc5) ||
96 /* Catch T == 0, CMD == 0 (e.g. '0') as first keypress after init */
97 RC5_START(ir_input->last_rc5) == 0) {
98 /* This keypress is differnet: not an auto repeat */
99 ir_input_nokey(ir_input->dev, &ir_input->ir);
100 ir_input_keydown(ir_input->dev, &ir_input->ir, command);
101 }
102 ir_input->last_rc5 = rc5;
103
104 /* Schedule when we should do the key up event: ir_input_nokey() */
105 mod_timer(&ir_input->timer_keyup,
106 jiffies + msecs_to_jiffies(ir_input->rc5_key_timeout));
107} 57}
108 58
109static void cx23885_input_next_pulse_width_rc5(struct cx23885_dev *dev, 59static void cx23885_input_process_measurements(struct cx23885_dev *dev,
110 u32 ns_pulse) 60 bool overrun)
111{ 61{
112 const int rc5_quarterbit_ns = 444444; /* 32 cycles/36 kHz/2 = 444 us */ 62 struct cx23885_kernel_ir *kernel_ir = dev->kernel_ir;
113 struct card_ir *ir_input = dev->ir_input; 63 struct ir_raw_event kernel_ir_event;
114 int i, level, quarterbits, halfbits;
115
116 if (!ir_input->active) {
117 ir_input->active = 1;
118 /* assume an initial space that we may not detect or measure */
119 ir_input->code = 0;
120 ir_input->last_bit = 0;
121 }
122 64
123 if (ns_pulse == V4L2_SUBDEV_IR_PULSE_RX_SEQ_END) { 65 u32 sd_ir_data[64];
124 ir_input->last_bit++; /* Account for the final space */ 66 ssize_t num;
125 ir_input->active = 0;
126 cx23885_input_process_raw_rc5(dev);
127 return;
128 }
129
130 level = (ns_pulse & V4L2_SUBDEV_IR_PULSE_LEVEL_MASK) ? 1 : 0;
131
132 /* Skip any leading space to sync to the start bit */
133 if (ir_input->last_bit == 0 && level == 0)
134 return;
135
136 /*
137 * With valid RC-5 we can get up to two consecutive half-bits in a
138 * single pulse measurment. Experiments have shown that the duration
139 * of a half-bit can vary. Make sure we always end up with an even
140 * number of quarter bits at the same level (mark or space).
141 */
142 ns_pulse &= V4L2_SUBDEV_IR_PULSE_MAX_WIDTH_NS;
143 quarterbits = ns_pulse / rc5_quarterbit_ns;
144 if (quarterbits & 1)
145 quarterbits++;
146 halfbits = quarterbits / 2;
147
148 for (i = 0; i < halfbits; i++) {
149 ir_input->last_bit++;
150 ir_input->code |= (level << ir_input->last_bit);
151
152 if (ir_input->last_bit >= RC5_HALF_BITS-1) {
153 ir_input->active = 0;
154 cx23885_input_process_raw_rc5(dev);
155 /*
156 * If level is 1, a leading mark is invalid for RC5.
157 * If level is 0, we scan past extra intial space.
158 * Either way we don't want to reactivate collecting
159 * marks or spaces here with any left over half-bits.
160 */
161 break;
162 }
163 }
164}
165
166static void cx23885_input_process_pulse_widths_rc5(struct cx23885_dev *dev,
167 bool add_eom)
168{
169 struct card_ir *ir_input = dev->ir_input;
170 struct ir_input_state *ir_input_state = &ir_input->ir;
171
172 u32 ns_pulse[RC5_HALF_BITS+1];
173 ssize_t num = 0;
174 int count, i; 67 int count, i;
68 bool handle = false;
175 69
176 do { 70 do {
177 v4l2_subdev_call(dev->sd_ir, ir, rx_read, (u8 *) ns_pulse, 71 num = 0;
178 sizeof(ns_pulse), &num); 72 v4l2_subdev_call(dev->sd_ir, ir, rx_read, (u8 *) sd_ir_data,
73 sizeof(sd_ir_data), &num);
179 74
180 count = num / sizeof(u32); 75 count = num / sizeof(u32);
181 76
182 /* Append an end of Rx seq, if the caller requested */ 77 for (i = 0; i < count; i++) {
183 if (add_eom && count < ARRAY_SIZE(ns_pulse)) { 78 convert_measurement(sd_ir_data[i], &kernel_ir_event);
184 ns_pulse[count] = V4L2_SUBDEV_IR_PULSE_RX_SEQ_END; 79 ir_raw_event_store(kernel_ir->inp_dev,
185 count++; 80 &kernel_ir_event);
81 handle = true;
186 } 82 }
187
188 /* Just drain the Rx FIFO, if we're called, but not RC-5 */
189 if (ir_input_state->ir_type != IR_TYPE_RC5)
190 continue;
191
192 for (i = 0; i < count; i++)
193 cx23885_input_next_pulse_width_rc5(dev, ns_pulse[i]);
194 } while (num != 0); 83 } while (num != 0);
84
85 if (overrun)
86 ir_raw_event_reset(kernel_ir->inp_dev);
87 else if (handle)
88 ir_raw_event_handle(kernel_ir->inp_dev);
195} 89}
196 90
197void cx23885_input_rx_work_handler(struct cx23885_dev *dev, u32 events) 91void cx23885_input_rx_work_handler(struct cx23885_dev *dev, u32 events)
@@ -230,7 +124,7 @@ void cx23885_input_rx_work_handler(struct cx23885_dev *dev, u32 events)
230 } 124 }
231 125
232 if (data_available) 126 if (data_available)
233 cx23885_input_process_pulse_widths_rc5(dev, overrun); 127 cx23885_input_process_measurements(dev, overrun);
234 128
235 if (overrun) { 129 if (overrun) {
236 /* If there was a FIFO overrun, clear & restart the device */ 130 /* If there was a FIFO overrun, clear & restart the device */
@@ -241,34 +135,15 @@ void cx23885_input_rx_work_handler(struct cx23885_dev *dev, u32 events)
241 } 135 }
242} 136}
243 137
244static void cx23885_input_ir_start(struct cx23885_dev *dev) 138static int cx23885_input_ir_start(struct cx23885_dev *dev)
245{ 139{
246 struct card_ir *ir_input = dev->ir_input;
247 struct ir_input_state *ir_input_state = &ir_input->ir;
248 struct v4l2_subdev_ir_parameters params; 140 struct v4l2_subdev_ir_parameters params;
249 141
250 if (dev->sd_ir == NULL) 142 if (dev->sd_ir == NULL)
251 return; 143 return -ENODEV;
252 144
253 atomic_set(&dev->ir_input_stopping, 0); 145 atomic_set(&dev->ir_input_stopping, 0);
254 146
255 /* keyup timer set up, if needed */
256 switch (dev->board) {
257 case CX23885_BOARD_HAUPPAUGE_HVR1850:
258 case CX23885_BOARD_HAUPPAUGE_HVR1290:
259 setup_timer(&ir_input->timer_keyup,
260 ir_rc5_timer_keyup, /* Not actually RC-5 specific */
261 (unsigned long) ir_input);
262 if (ir_input_state->ir_type == IR_TYPE_RC5) {
263 /*
264 * RC-5 repeats a held key every
265 * 64 bits * (2 * 32/36000) sec/bit = 113.778 ms
266 */
267 ir_input->rc5_key_timeout = 115;
268 }
269 break;
270 }
271
272 v4l2_subdev_call(dev->sd_ir, ir, rx_g_parameters, &params); 147 v4l2_subdev_call(dev->sd_ir, ir, rx_g_parameters, &params);
273 switch (dev->board) { 148 switch (dev->board) {
274 case CX23885_BOARD_HAUPPAUGE_HVR1850: 149 case CX23885_BOARD_HAUPPAUGE_HVR1850:
@@ -299,11 +174,21 @@ static void cx23885_input_ir_start(struct cx23885_dev *dev)
299 break; 174 break;
300 } 175 }
301 v4l2_subdev_call(dev->sd_ir, ir, rx_s_parameters, &params); 176 v4l2_subdev_call(dev->sd_ir, ir, rx_s_parameters, &params);
177 return 0;
178}
179
180static int cx23885_input_ir_open(void *priv)
181{
182 struct cx23885_kernel_ir *kernel_ir = priv;
183
184 if (kernel_ir->cx == NULL)
185 return -ENODEV;
186
187 return cx23885_input_ir_start(kernel_ir->cx);
302} 188}
303 189
304static void cx23885_input_ir_stop(struct cx23885_dev *dev) 190static void cx23885_input_ir_stop(struct cx23885_dev *dev)
305{ 191{
306 struct card_ir *ir_input = dev->ir_input;
307 struct v4l2_subdev_ir_parameters params; 192 struct v4l2_subdev_ir_parameters params;
308 193
309 if (dev->sd_ir == NULL) 194 if (dev->sd_ir == NULL)
@@ -327,21 +212,26 @@ static void cx23885_input_ir_stop(struct cx23885_dev *dev)
327 } 212 }
328 213
329 flush_scheduled_work(); 214 flush_scheduled_work();
215}
330 216
331 switch (dev->board) { 217static void cx23885_input_ir_close(void *priv)
332 case CX23885_BOARD_HAUPPAUGE_HVR1850: 218{
333 case CX23885_BOARD_HAUPPAUGE_HVR1290: 219 struct cx23885_kernel_ir *kernel_ir = priv;
334 del_timer_sync(&ir_input->timer_keyup); 220
335 break; 221 if (kernel_ir->cx != NULL)
336 } 222 cx23885_input_ir_stop(kernel_ir->cx);
337} 223}
338 224
339int cx23885_input_init(struct cx23885_dev *dev) 225int cx23885_input_init(struct cx23885_dev *dev)
340{ 226{
341 struct card_ir *ir; 227 struct cx23885_kernel_ir *kernel_ir;
342 struct input_dev *input_dev; 228 struct input_dev *inp_dev;
343 char *ir_codes = NULL; 229 struct ir_dev_props *props;
344 int ir_type, ir_addr, ir_start; 230
231 char *rc_map;
232 enum rc_driver_type driver_type;
233 unsigned long allowed_protos;
234
345 int ret; 235 int ret;
346 236
347 /* 237 /*
@@ -354,53 +244,59 @@ int cx23885_input_init(struct cx23885_dev *dev)
354 switch (dev->board) { 244 switch (dev->board) {
355 case CX23885_BOARD_HAUPPAUGE_HVR1850: 245 case CX23885_BOARD_HAUPPAUGE_HVR1850:
356 case CX23885_BOARD_HAUPPAUGE_HVR1290: 246 case CX23885_BOARD_HAUPPAUGE_HVR1290:
357 /* Parameters for the grey Hauppauge remote for the HVR-1850 */ 247 /* Integrated CX23888 IR controller */
358 ir_codes = RC_MAP_HAUPPAUGE_NEW; 248 driver_type = RC_DRIVER_IR_RAW;
359 ir_type = IR_TYPE_RC5; 249 allowed_protos = IR_TYPE_ALL;
360 ir_addr = 0x1e; /* RC-5 system bits emitted by the remote */ 250 /* The grey Hauppauge RC-5 remote */
361 ir_start = RC5_START_BITS_NORMAL; /* A basic RC-5 remote */ 251 rc_map = RC_MAP_RC5_HAUPPAUGE_NEW;
362 break; 252 break;
363 } 253 default:
364 if (ir_codes == NULL)
365 return -ENODEV; 254 return -ENODEV;
366
367 ir = kzalloc(sizeof(*ir), GFP_KERNEL);
368 input_dev = input_allocate_device();
369 if (!ir || !input_dev) {
370 ret = -ENOMEM;
371 goto err_out_free;
372 } 255 }
373 256
374 ir->dev = input_dev; 257 /* cx23885 board instance kernel IR state */
375 ir->addr = ir_addr; 258 kernel_ir = kzalloc(sizeof(struct cx23885_kernel_ir), GFP_KERNEL);
376 ir->start = ir_start; 259 if (kernel_ir == NULL)
260 return -ENOMEM;
377 261
378 /* init input device */ 262 kernel_ir->cx = dev;
379 snprintf(ir->name, sizeof(ir->name), "cx23885 IR (%s)", 263 kernel_ir->name = kasprintf(GFP_KERNEL, "cx23885 IR (%s)",
380 cx23885_boards[dev->board].name); 264 cx23885_boards[dev->board].name);
381 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0", pci_name(dev->pci)); 265 kernel_ir->phys = kasprintf(GFP_KERNEL, "pci-%s/ir0",
266 pci_name(dev->pci));
382 267
383 ret = ir_input_init(input_dev, &ir->ir, ir_type); 268 /* input device */
384 if (ret < 0) 269 inp_dev = input_allocate_device();
270 if (inp_dev == NULL) {
271 ret = -ENOMEM;
385 goto err_out_free; 272 goto err_out_free;
273 }
386 274
387 input_dev->name = ir->name; 275 kernel_ir->inp_dev = inp_dev;
388 input_dev->phys = ir->phys; 276 inp_dev->name = kernel_ir->name;
389 input_dev->id.bustype = BUS_PCI; 277 inp_dev->phys = kernel_ir->phys;
390 input_dev->id.version = 1; 278 inp_dev->id.bustype = BUS_PCI;
279 inp_dev->id.version = 1;
391 if (dev->pci->subsystem_vendor) { 280 if (dev->pci->subsystem_vendor) {
392 input_dev->id.vendor = dev->pci->subsystem_vendor; 281 inp_dev->id.vendor = dev->pci->subsystem_vendor;
393 input_dev->id.product = dev->pci->subsystem_device; 282 inp_dev->id.product = dev->pci->subsystem_device;
394 } else { 283 } else {
395 input_dev->id.vendor = dev->pci->vendor; 284 inp_dev->id.vendor = dev->pci->vendor;
396 input_dev->id.product = dev->pci->device; 285 inp_dev->id.product = dev->pci->device;
397 } 286 }
398 input_dev->dev.parent = &dev->pci->dev; 287 inp_dev->dev.parent = &dev->pci->dev;
399 288
400 dev->ir_input = ir; 289 /* kernel ir device properties */
401 cx23885_input_ir_start(dev); 290 props = &kernel_ir->props;
402 291 props->driver_type = driver_type;
403 ret = ir_input_register(ir->dev, ir_codes, NULL, MODULE_NAME); 292 props->allowed_protos = allowed_protos;
293 props->priv = kernel_ir;
294 props->open = cx23885_input_ir_open;
295 props->close = cx23885_input_ir_close;
296
297 /* Go */
298 dev->kernel_ir = kernel_ir;
299 ret = ir_input_register(inp_dev, rc_map, props, MODULE_NAME);
404 if (ret) 300 if (ret)
405 goto err_out_stop; 301 goto err_out_stop;
406 302
@@ -408,9 +304,12 @@ int cx23885_input_init(struct cx23885_dev *dev)
408 304
409err_out_stop: 305err_out_stop:
410 cx23885_input_ir_stop(dev); 306 cx23885_input_ir_stop(dev);
411 dev->ir_input = NULL; 307 dev->kernel_ir = NULL;
308 /* TODO: double check clean-up of kernel_ir->inp_dev */
412err_out_free: 309err_out_free:
413 kfree(ir); 310 kfree(kernel_ir->phys);
311 kfree(kernel_ir->name);
312 kfree(kernel_ir);
414 return ret; 313 return ret;
415} 314}
416 315
@@ -419,9 +318,11 @@ void cx23885_input_fini(struct cx23885_dev *dev)
419 /* Always stop the IR hardware from generating interrupts */ 318 /* Always stop the IR hardware from generating interrupts */
420 cx23885_input_ir_stop(dev); 319 cx23885_input_ir_stop(dev);
421 320
422 if (dev->ir_input == NULL) 321 if (dev->kernel_ir == NULL)
423 return; 322 return;
424 ir_input_unregister(dev->ir_input->dev); 323 ir_input_unregister(dev->kernel_ir->inp_dev);
425 kfree(dev->ir_input); 324 kfree(dev->kernel_ir->phys);
426 dev->ir_input = NULL; 325 kfree(dev->kernel_ir->name);
326 kfree(dev->kernel_ir);
327 dev->kernel_ir = NULL;
427} 328}
diff --git a/drivers/media/video/cx23885/cx23885-ir.c b/drivers/media/video/cx23885/cx23885-ir.c
index 9a677eb080af..6ceabd4fba07 100644
--- a/drivers/media/video/cx23885/cx23885-ir.c
+++ b/drivers/media/video/cx23885/cx23885-ir.c
@@ -53,7 +53,7 @@ void cx23885_ir_rx_work_handler(struct work_struct *work)
53 if (events == 0) 53 if (events == 0)
54 return; 54 return;
55 55
56 if (dev->ir_input) 56 if (dev->kernel_ir)
57 cx23885_input_rx_work_handler(dev, events); 57 cx23885_input_rx_work_handler(dev, events);
58} 58}
59 59
diff --git a/drivers/media/video/cx23885/cx23885.h b/drivers/media/video/cx23885/cx23885.h
index 8d6a55e54ee7..a33f2b71467b 100644
--- a/drivers/media/video/cx23885/cx23885.h
+++ b/drivers/media/video/cx23885/cx23885.h
@@ -30,6 +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 34
34#include "btcx-risc.h" 35#include "btcx-risc.h"
35#include "cx23885-reg.h" 36#include "cx23885-reg.h"
@@ -304,6 +305,15 @@ struct cx23885_tsport {
304 void *port_priv; 305 void *port_priv;
305}; 306};
306 307
308struct cx23885_kernel_ir {
309 struct cx23885_dev *cx;
310 char *name;
311 char *phys;
312
313 struct input_dev *inp_dev;
314 struct ir_dev_props props;
315};
316
307struct cx23885_dev { 317struct cx23885_dev {
308 atomic_t refcount; 318 atomic_t refcount;
309 struct v4l2_device v4l2_dev; 319 struct v4l2_device v4l2_dev;
@@ -363,7 +373,7 @@ struct cx23885_dev {
363 struct work_struct ir_tx_work; 373 struct work_struct ir_tx_work;
364 unsigned long ir_tx_notifications; 374 unsigned long ir_tx_notifications;
365 375
366 struct card_ir *ir_input; 376 struct cx23885_kernel_ir *kernel_ir;
367 atomic_t ir_input_stopping; 377 atomic_t ir_input_stopping;
368 378
369 /* V4l */ 379 /* V4l */
diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
index 33082c96745e..4f383cdf5296 100644
--- a/drivers/media/video/cx88/cx88-alsa.c
+++ b/drivers/media/video/cx88/cx88-alsa.c
@@ -54,6 +54,12 @@
54 Data type declarations - Can be moded to a header file later 54 Data type declarations - Can be moded to a header file later
55 ****************************************************************************/ 55 ****************************************************************************/
56 56
57struct cx88_audio_buffer {
58 unsigned int bpl;
59 struct btcx_riscmem risc;
60 struct videobuf_dmabuf dma;
61};
62
57struct cx88_audio_dev { 63struct cx88_audio_dev {
58 struct cx88_core *core; 64 struct cx88_core *core;
59 struct cx88_dmaqueue q; 65 struct cx88_dmaqueue q;
@@ -75,7 +81,7 @@ struct cx88_audio_dev {
75 81
76 struct videobuf_dmabuf *dma_risc; 82 struct videobuf_dmabuf *dma_risc;
77 83
78 struct cx88_buffer *buf; 84 struct cx88_audio_buffer *buf;
79 85
80 struct snd_pcm_substream *substream; 86 struct snd_pcm_substream *substream;
81}; 87};
@@ -123,7 +129,7 @@ MODULE_PARM_DESC(debug,"enable debug messages");
123 129
124static int _cx88_start_audio_dma(snd_cx88_card_t *chip) 130static int _cx88_start_audio_dma(snd_cx88_card_t *chip)
125{ 131{
126 struct cx88_buffer *buf = chip->buf; 132 struct cx88_audio_buffer *buf = chip->buf;
127 struct cx88_core *core=chip->core; 133 struct cx88_core *core=chip->core;
128 struct sram_channel *audio_ch = &cx88_sram_channels[SRAM_CH25]; 134 struct sram_channel *audio_ch = &cx88_sram_channels[SRAM_CH25];
129 135
@@ -283,7 +289,7 @@ static int dsp_buffer_free(snd_cx88_card_t *chip)
283 BUG_ON(!chip->dma_size); 289 BUG_ON(!chip->dma_size);
284 290
285 dprintk(2,"Freeing buffer\n"); 291 dprintk(2,"Freeing buffer\n");
286 videobuf_sg_dma_unmap(&chip->pci->dev, chip->dma_risc); 292 videobuf_dma_unmap(&chip->pci->dev, chip->dma_risc);
287 videobuf_dma_free(chip->dma_risc); 293 videobuf_dma_free(chip->dma_risc);
288 btcx_riscmem_free(chip->pci,&chip->buf->risc); 294 btcx_riscmem_free(chip->pci,&chip->buf->risc);
289 kfree(chip->buf); 295 kfree(chip->buf);
@@ -376,7 +382,7 @@ static int snd_cx88_hw_params(struct snd_pcm_substream * substream,
376 snd_cx88_card_t *chip = snd_pcm_substream_chip(substream); 382 snd_cx88_card_t *chip = snd_pcm_substream_chip(substream);
377 struct videobuf_dmabuf *dma; 383 struct videobuf_dmabuf *dma;
378 384
379 struct cx88_buffer *buf; 385 struct cx88_audio_buffer *buf;
380 int ret; 386 int ret;
381 387
382 if (substream->runtime->dma_area) { 388 if (substream->runtime->dma_area) {
@@ -391,30 +397,25 @@ static int snd_cx88_hw_params(struct snd_pcm_substream * substream,
391 BUG_ON(!chip->dma_size); 397 BUG_ON(!chip->dma_size);
392 BUG_ON(chip->num_periods & (chip->num_periods-1)); 398 BUG_ON(chip->num_periods & (chip->num_periods-1));
393 399
394 buf = videobuf_sg_alloc(sizeof(*buf)); 400 buf = kzalloc(sizeof(*buf), GFP_KERNEL);
395 if (NULL == buf) 401 if (NULL == buf)
396 return -ENOMEM; 402 return -ENOMEM;
397 403
398 buf->vb.memory = V4L2_MEMORY_MMAP; 404 buf->bpl = chip->period_size;
399 buf->vb.field = V4L2_FIELD_NONE;
400 buf->vb.width = chip->period_size;
401 buf->bpl = chip->period_size;
402 buf->vb.height = chip->num_periods;
403 buf->vb.size = chip->dma_size;
404 405
405 dma = videobuf_to_dma(&buf->vb); 406 dma = &buf->dma;
406 videobuf_dma_init(dma); 407 videobuf_dma_init(dma);
407 ret = videobuf_dma_init_kernel(dma, PCI_DMA_FROMDEVICE, 408 ret = videobuf_dma_init_kernel(dma, PCI_DMA_FROMDEVICE,
408 (PAGE_ALIGN(buf->vb.size) >> PAGE_SHIFT)); 409 (PAGE_ALIGN(chip->dma_size) >> PAGE_SHIFT));
409 if (ret < 0) 410 if (ret < 0)
410 goto error; 411 goto error;
411 412
412 ret = videobuf_sg_dma_map(&chip->pci->dev, dma); 413 ret = videobuf_dma_map(&chip->pci->dev, dma);
413 if (ret < 0) 414 if (ret < 0)
414 goto error; 415 goto error;
415 416
416 ret = cx88_risc_databuffer(chip->pci, &buf->risc, dma->sglist, 417 ret = cx88_risc_databuffer(chip->pci, &buf->risc, dma->sglist,
417 buf->vb.width, buf->vb.height, 1); 418 chip->period_size, chip->num_periods, 1);
418 if (ret < 0) 419 if (ret < 0)
419 goto error; 420 goto error;
420 421
@@ -422,12 +423,10 @@ static int snd_cx88_hw_params(struct snd_pcm_substream * substream,
422 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP|RISC_IRQ1|RISC_CNT_INC); 423 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP|RISC_IRQ1|RISC_CNT_INC);
423 buf->risc.jmp[1] = cpu_to_le32(buf->risc.dma); 424 buf->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
424 425
425 buf->vb.state = VIDEOBUF_PREPARED;
426
427 chip->buf = buf; 426 chip->buf = buf;
428 chip->dma_risc = dma; 427 chip->dma_risc = dma;
429 428
430 substream->runtime->dma_area = chip->dma_risc->vmalloc; 429 substream->runtime->dma_area = chip->dma_risc->vaddr;
431 substream->runtime->dma_bytes = chip->dma_size; 430 substream->runtime->dma_bytes = chip->dma_size;
432 substream->runtime->dma_addr = 0; 431 substream->runtime->dma_addr = 0;
433 return 0; 432 return 0;
@@ -740,7 +739,7 @@ static int __devinit snd_cx88_create(struct snd_card *card,
740 739
741 pci_set_master(pci); 740 pci_set_master(pci);
742 741
743 chip = (snd_cx88_card_t *) card->private_data; 742 chip = card->private_data;
744 743
745 core = cx88_core_get(pci); 744 core = cx88_core_get(pci);
746 if (NULL == core) { 745 if (NULL == core) {
diff --git a/drivers/media/video/cx88/cx88-cards.c b/drivers/media/video/cx88/cx88-cards.c
index 2918a6e38fe8..e8416b76da67 100644
--- a/drivers/media/video/cx88/cx88-cards.c
+++ b/drivers/media/video/cx88/cx88-cards.c
@@ -45,6 +45,10 @@ static unsigned int latency = UNSET;
45module_param(latency,int,0444); 45module_param(latency,int,0444);
46MODULE_PARM_DESC(latency,"pci latency timer"); 46MODULE_PARM_DESC(latency,"pci latency timer");
47 47
48static int disable_ir;
49module_param(disable_ir, int, 0444);
50MODULE_PARM_DESC(latency, "Disable IR support");
51
48#define info_printk(core, fmt, arg...) \ 52#define info_printk(core, fmt, arg...) \
49 printk(KERN_INFO "%s: " fmt, core->name , ## arg) 53 printk(KERN_INFO "%s: " fmt, core->name , ## arg)
50 54
@@ -3498,7 +3502,10 @@ struct cx88_core *cx88_core_create(struct pci_dev *pci, int nr)
3498 } 3502 }
3499 3503
3500 cx88_card_setup(core); 3504 cx88_card_setup(core);
3501 cx88_ir_init(core, pci); 3505 if (!disable_ir) {
3506 cx88_i2c_init_ir(core);
3507 cx88_ir_init(core, pci);
3508 }
3502 3509
3503 return core; 3510 return core;
3504} 3511}
diff --git a/drivers/media/video/cx88/cx88-core.c b/drivers/media/video/cx88/cx88-core.c
index 8b21457111b1..85eb266fb351 100644
--- a/drivers/media/video/cx88/cx88-core.c
+++ b/drivers/media/video/cx88/cx88-core.c
@@ -218,7 +218,7 @@ cx88_free_buffer(struct videobuf_queue *q, struct cx88_buffer *buf)
218 218
219 BUG_ON(in_interrupt()); 219 BUG_ON(in_interrupt());
220 videobuf_waiton(&buf->vb,0,0); 220 videobuf_waiton(&buf->vb,0,0);
221 videobuf_dma_unmap(q, dma); 221 videobuf_dma_unmap(q->dev, dma);
222 videobuf_dma_free(dma); 222 videobuf_dma_free(dma);
223 btcx_riscmem_free(to_pci_dev(q->dev), &buf->risc); 223 btcx_riscmem_free(to_pci_dev(q->dev), &buf->risc);
224 buf->vb.state = VIDEOBUF_NEEDS_INIT; 224 buf->vb.state = VIDEOBUF_NEEDS_INIT;
diff --git a/drivers/media/video/cx88/cx88-i2c.c b/drivers/media/video/cx88/cx88-i2c.c
index fb39f1184558..375ad53f7961 100644
--- a/drivers/media/video/cx88/cx88-i2c.c
+++ b/drivers/media/video/cx88/cx88-i2c.c
@@ -181,6 +181,11 @@ int cx88_i2c_init(struct cx88_core *core, struct pci_dev *pci)
181 } else 181 } else
182 printk("%s: i2c register FAILED\n", core->name); 182 printk("%s: i2c register FAILED\n", core->name);
183 183
184 return core->i2c_rc;
185}
186
187void cx88_i2c_init_ir(struct cx88_core *core)
188{
184 /* Instantiate the IR receiver device, if present */ 189 /* Instantiate the IR receiver device, if present */
185 if (0 == core->i2c_rc) { 190 if (0 == core->i2c_rc) {
186 struct i2c_board_info info; 191 struct i2c_board_info info;
@@ -207,7 +212,6 @@ int cx88_i2c_init(struct cx88_core *core, struct pci_dev *pci)
207 } 212 }
208 } 213 }
209 } 214 }
210 return core->i2c_rc;
211} 215}
212 216
213/* ----------------------------------------------------------------------- */ 217/* ----------------------------------------------------------------------- */
diff --git a/drivers/media/video/cx88/cx88-input.c b/drivers/media/video/cx88/cx88-input.c
index e185289e446c..eccc5e49a350 100644
--- a/drivers/media/video/cx88/cx88-input.c
+++ b/drivers/media/video/cx88/cx88-input.c
@@ -30,6 +30,7 @@
30#include <linux/module.h> 30#include <linux/module.h>
31 31
32#include "cx88.h" 32#include "cx88.h"
33#include <media/ir-core.h>
33#include <media/ir-common.h> 34#include <media/ir-common.h>
34 35
35#define MODULE_NAME "cx88xx" 36#define MODULE_NAME "cx88xx"
@@ -39,8 +40,8 @@
39struct cx88_IR { 40struct cx88_IR {
40 struct cx88_core *core; 41 struct cx88_core *core;
41 struct input_dev *input; 42 struct input_dev *input;
42 struct ir_input_state ir;
43 struct ir_dev_props props; 43 struct ir_dev_props props;
44 u64 ir_type;
44 45
45 int users; 46 int users;
46 47
@@ -51,7 +52,6 @@ struct cx88_IR {
51 u32 sampling; 52 u32 sampling;
52 u32 samples[16]; 53 u32 samples[16];
53 int scount; 54 int scount;
54 unsigned long release;
55 55
56 /* poll external decoder */ 56 /* poll external decoder */
57 int polling; 57 int polling;
@@ -125,29 +125,21 @@ static void cx88_ir_handle_key(struct cx88_IR *ir)
125 125
126 data = (data << 4) | ((gpio_key & 0xf0) >> 4); 126 data = (data << 4) | ((gpio_key & 0xf0) >> 4);
127 127
128 ir_input_keydown(ir->input, &ir->ir, data); 128 ir_keydown(ir->input, data, 0);
129 ir_input_nokey(ir->input, &ir->ir);
130 129
131 } else if (ir->mask_keydown) { 130 } else if (ir->mask_keydown) {
132 /* bit set on keydown */ 131 /* bit set on keydown */
133 if (gpio & ir->mask_keydown) { 132 if (gpio & ir->mask_keydown)
134 ir_input_keydown(ir->input, &ir->ir, data); 133 ir_keydown(ir->input, data, 0);
135 } else {
136 ir_input_nokey(ir->input, &ir->ir);
137 }
138 134
139 } else if (ir->mask_keyup) { 135 } else if (ir->mask_keyup) {
140 /* bit cleared on keydown */ 136 /* bit cleared on keydown */
141 if (0 == (gpio & ir->mask_keyup)) { 137 if (0 == (gpio & ir->mask_keyup))
142 ir_input_keydown(ir->input, &ir->ir, data); 138 ir_keydown(ir->input, data, 0);
143 } else {
144 ir_input_nokey(ir->input, &ir->ir);
145 }
146 139
147 } else { 140 } else {
148 /* can't distinguish keydown/up :-/ */ 141 /* can't distinguish keydown/up :-/ */
149 ir_input_keydown(ir->input, &ir->ir, data); 142 ir_keydown(ir->input, data, 0);
150 ir_input_nokey(ir->input, &ir->ir);
151 } 143 }
152} 144}
153 145
@@ -439,9 +431,7 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
439 snprintf(ir->name, sizeof(ir->name), "cx88 IR (%s)", core->board.name); 431 snprintf(ir->name, sizeof(ir->name), "cx88 IR (%s)", core->board.name);
440 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0", pci_name(pci)); 432 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0", pci_name(pci));
441 433
442 err = ir_input_init(input_dev, &ir->ir, ir_type); 434 ir->ir_type = ir_type;
443 if (err < 0)
444 goto err_out_free;
445 435
446 input_dev->name = ir->name; 436 input_dev->name = ir->name;
447 input_dev->phys = ir->phys; 437 input_dev->phys = ir->phys;
@@ -516,8 +506,6 @@ void cx88_ir_irq(struct cx88_core *core)
516 } 506 }
517 if (!ir->scount) { 507 if (!ir->scount) {
518 /* nothing to sample */ 508 /* nothing to sample */
519 if (ir->ir.keypressed && time_after(jiffies, ir->release))
520 ir_input_nokey(ir->input, &ir->ir);
521 return; 509 return;
522 } 510 }
523 511
@@ -553,7 +541,7 @@ void cx88_ir_irq(struct cx88_core *core)
553 541
554 if (ircode == 0) { /* key still pressed */ 542 if (ircode == 0) { /* key still pressed */
555 ir_dprintk("pulse distance decoded repeat code\n"); 543 ir_dprintk("pulse distance decoded repeat code\n");
556 ir->release = jiffies + msecs_to_jiffies(120); 544 ir_repeat(ir->input);
557 break; 545 break;
558 } 546 }
559 547
@@ -567,10 +555,8 @@ void cx88_ir_irq(struct cx88_core *core)
567 break; 555 break;
568 } 556 }
569 557
570 ir_dprintk("Key Code: %x\n", (ircode >> 16) & 0x7f); 558 ir_dprintk("Key Code: %x\n", (ircode >> 16) & 0xff);
571 559 ir_keydown(ir->input, (ircode >> 16) & 0xff, 0);
572 ir_input_keydown(ir->input, &ir->ir, (ircode >> 16) & 0x7f);
573 ir->release = jiffies + msecs_to_jiffies(120);
574 break; 560 break;
575 case CX88_BOARD_HAUPPAUGE: 561 case CX88_BOARD_HAUPPAUGE:
576 case CX88_BOARD_HAUPPAUGE_DVB_T1: 562 case CX88_BOARD_HAUPPAUGE_DVB_T1:
@@ -606,16 +592,16 @@ void cx88_ir_irq(struct cx88_core *core)
606 if ( dev != 0x1e && dev != 0x1f ) 592 if ( dev != 0x1e && dev != 0x1f )
607 /* not a hauppauge remote */ 593 /* not a hauppauge remote */
608 break; 594 break;
609 ir_input_keydown(ir->input, &ir->ir, code); 595 ir_keydown(ir->input, code, toggle);
610 ir->release = jiffies + msecs_to_jiffies(120);
611 break; 596 break;
612 case CX88_BOARD_PINNACLE_PCTV_HD_800i: 597 case CX88_BOARD_PINNACLE_PCTV_HD_800i:
613 ircode = ir_decode_biphase(ir->samples, ir->scount, 5, 7); 598 ircode = ir_decode_biphase(ir->samples, ir->scount, 5, 7);
614 ir_dprintk("biphase decoded: %x\n", ircode); 599 ir_dprintk("biphase decoded: %x\n", ircode);
615 if ((ircode & 0xfffff000) != 0x3000) 600 if ((ircode & 0xfffff000) != 0x3000)
616 break; 601 break;
617 ir_input_keydown(ir->input, &ir->ir, ircode & 0x3f); 602 /* Note: bit 0x800 being the toggle is assumed, not checked
618 ir->release = jiffies + msecs_to_jiffies(120); 603 with real hardware */
604 ir_keydown(ir->input, ircode & 0x3f, ircode & 0x0800 ? 1 : 0);
619 break; 605 break;
620 } 606 }
621 607
diff --git a/drivers/media/video/cx88/cx88.h b/drivers/media/video/cx88/cx88.h
index bdb03d336536..33d161a11725 100644
--- a/drivers/media/video/cx88/cx88.h
+++ b/drivers/media/video/cx88/cx88.h
@@ -636,6 +636,7 @@ extern struct videobuf_queue_ops cx8800_vbi_qops;
636/* cx88-i2c.c */ 636/* cx88-i2c.c */
637 637
638extern int cx88_i2c_init(struct cx88_core *core, struct pci_dev *pci); 638extern int cx88_i2c_init(struct cx88_core *core, struct pci_dev *pci);
639extern void cx88_i2c_init_ir(struct cx88_core *core);
639 640
640 641
641/* ----------------------------------------------------------- */ 642/* ----------------------------------------------------------- */
diff --git a/drivers/media/video/dabusb.c b/drivers/media/video/dabusb.c
index 0f505086774c..5b176bd7afdb 100644
--- a/drivers/media/video/dabusb.c
+++ b/drivers/media/video/dabusb.c
@@ -706,16 +706,11 @@ static long dabusb_ioctl (struct file *file, unsigned int cmd, unsigned long arg
706 switch (cmd) { 706 switch (cmd) {
707 707
708 case IOCTL_DAB_BULK: 708 case IOCTL_DAB_BULK:
709 pbulk = kmalloc(sizeof (bulk_transfer_t), GFP_KERNEL); 709 pbulk = memdup_user((void __user *)arg,
710 sizeof(bulk_transfer_t));
710 711
711 if (!pbulk) { 712 if (IS_ERR(pbulk)) {
712 ret = -ENOMEM; 713 ret = PTR_ERR(pbulk);
713 break;
714 }
715
716 if (copy_from_user (pbulk, (void __user *) arg, sizeof (bulk_transfer_t))) {
717 ret = -EFAULT;
718 kfree (pbulk);
719 break; 714 break;
720 } 715 }
721 716
diff --git a/drivers/media/video/davinci/Kconfig b/drivers/media/video/davinci/Kconfig
new file mode 100644
index 000000000000..6b1954035649
--- /dev/null
+++ b/drivers/media/video/davinci/Kconfig
@@ -0,0 +1,93 @@
1config DISPLAY_DAVINCI_DM646X_EVM
2 tristate "DM646x EVM Video Display"
3 depends on VIDEO_DEV && MACH_DAVINCI_DM6467_EVM
4 select VIDEOBUF_DMA_CONTIG
5 select VIDEO_DAVINCI_VPIF
6 select VIDEO_ADV7343
7 select VIDEO_THS7303
8 help
9 Support for DM6467 based display device.
10
11 To compile this driver as a module, choose M here: the
12 module will be called vpif_display.
13
14config CAPTURE_DAVINCI_DM646X_EVM
15 tristate "DM646x EVM Video Capture"
16 depends on VIDEO_DEV && MACH_DAVINCI_DM6467_EVM
17 select VIDEOBUF_DMA_CONTIG
18 select VIDEO_DAVINCI_VPIF
19 help
20 Support for DM6467 based capture device.
21
22 To compile this driver as a module, choose M here: the
23 module will be called vpif_capture.
24
25config VIDEO_DAVINCI_VPIF
26 tristate "DaVinci VPIF Driver"
27 depends on DISPLAY_DAVINCI_DM646X_EVM
28 help
29 Support for DaVinci VPIF Driver.
30
31 To compile this driver as a module, choose M here: the
32 module will be called vpif.
33
34config VIDEO_VPSS_SYSTEM
35 tristate "VPSS System module driver"
36 depends on ARCH_DAVINCI
37 help
38 Support for vpss system module for video driver
39
40config VIDEO_VPFE_CAPTURE
41 tristate "VPFE Video Capture Driver"
42 depends on VIDEO_V4L2 && (ARCH_DAVINCI || ARCH_OMAP3)
43 select VIDEOBUF_DMA_CONTIG
44 help
45 Support for DMx/AMx VPFE based frame grabber. This is the
46 common V4L2 module for following DMx/AMx SoCs from Texas
47 Instruments:- DM6446, DM365, DM355 & AM3517/05.
48
49 To compile this driver as a module, choose M here: the
50 module will be called vpfe-capture.
51
52config VIDEO_DM6446_CCDC
53 tristate "DM6446 CCDC HW module"
54 depends on VIDEO_VPFE_CAPTURE
55 select VIDEO_VPSS_SYSTEM
56 default y
57 help
58 Enables DaVinci CCD hw module. DaVinci CCDC hw interfaces
59 with decoder modules such as TVP5146 over BT656 or
60 sensor module such as MT9T001 over a raw interface. This
61 module configures the interface and CCDC/ISIF to do
62 video frame capture from slave decoders.
63
64 To compile this driver as a module, choose M here: the
65 module will be called vpfe.
66
67config VIDEO_DM355_CCDC
68 tristate "DM355 CCDC HW module"
69 depends on ARCH_DAVINCI_DM355 && VIDEO_VPFE_CAPTURE
70 select VIDEO_VPSS_SYSTEM
71 default y
72 help
73 Enables DM355 CCD hw module. DM355 CCDC hw interfaces
74 with decoder modules such as TVP5146 over BT656 or
75 sensor module such as MT9T001 over a raw interface. This
76 module configures the interface and CCDC/ISIF to do
77 video frame capture from a slave decoders
78
79 To compile this driver as a module, choose M here: the
80 module will be called vpfe.
81
82config VIDEO_ISIF
83 tristate "ISIF HW module"
84 depends on ARCH_DAVINCI_DM365 && VIDEO_VPFE_CAPTURE
85 select VIDEO_VPSS_SYSTEM
86 default y
87 help
88 Enables ISIF hw module. This is the hardware module for
89 configuring ISIF in VPFE to capture Raw Bayer RGB data from
90 a image sensor or YUV data from a YUV source.
91
92 To compile this driver as a module, choose M here: the
93 module will be called vpfe.
diff --git a/drivers/media/video/em28xx/em28xx-cards.c b/drivers/media/video/em28xx/em28xx-cards.c
index 3a4fd8514511..ffbe544e30f4 100644
--- a/drivers/media/video/em28xx/em28xx-cards.c
+++ b/drivers/media/video/em28xx/em28xx-cards.c
@@ -158,6 +158,22 @@ static struct em28xx_reg_seq evga_indtube_digital[] = {
158 { -1, -1, -1, -1}, 158 { -1, -1, -1, -1},
159}; 159};
160 160
161/*
162 * KWorld PlusTV 340U and UB435-Q (ATSC) GPIOs map:
163 * EM_GPIO_0 - currently unknown
164 * EM_GPIO_1 - LED disable/enable (1 = off, 0 = on)
165 * EM_GPIO_2 - currently unknown
166 * EM_GPIO_3 - currently unknown
167 * EM_GPIO_4 - TDA18271HD/C1 tuner (1 = active, 0 = in reset)
168 * EM_GPIO_5 - LGDT3304 ATSC/QAM demod (1 = active, 0 = in reset)
169 * EM_GPIO_6 - currently unknown
170 * EM_GPIO_7 - currently unknown
171 */
172static struct em28xx_reg_seq kworld_a340_digital[] = {
173 {EM28XX_R08_GPIO, 0x6d, ~EM_GPIO_4, 10},
174 { -1, -1, -1, -1},
175};
176
161/* Pinnacle Hybrid Pro eb1a:2881 */ 177/* Pinnacle Hybrid Pro eb1a:2881 */
162static struct em28xx_reg_seq pinnacle_hybrid_pro_analog[] = { 178static struct em28xx_reg_seq pinnacle_hybrid_pro_analog[] = {
163 {EM28XX_R08_GPIO, 0xfd, ~EM_GPIO_4, 10}, 179 {EM28XX_R08_GPIO, 0xfd, ~EM_GPIO_4, 10},
@@ -1667,6 +1683,16 @@ struct em28xx_board em28xx_boards[] = {
1667 .tuner_gpio = reddo_dvb_c_usb_box, 1683 .tuner_gpio = reddo_dvb_c_usb_box,
1668 .has_dvb = 1, 1684 .has_dvb = 1,
1669 }, 1685 },
1686 /* 1b80:a340 - Empia EM2870, NXP TDA18271HD and LG DT3304, sold
1687 * initially as the KWorld PlusTV 340U, then as the UB435-Q.
1688 * Early variants have a TDA18271HD/C1, later ones a TDA18271HD/C2 */
1689 [EM2870_BOARD_KWORLD_A340] = {
1690 .name = "KWorld PlusTV 340U or UB435-Q (ATSC)",
1691 .tuner_type = TUNER_ABSENT, /* Digital-only TDA18271HD */
1692 .has_dvb = 1,
1693 .dvb_gpio = kworld_a340_digital,
1694 .tuner_gpio = default_tuner_gpio,
1695 },
1670}; 1696};
1671const unsigned int em28xx_bcount = ARRAY_SIZE(em28xx_boards); 1697const unsigned int em28xx_bcount = ARRAY_SIZE(em28xx_boards);
1672 1698
@@ -1788,6 +1814,8 @@ struct usb_device_id em28xx_id_table[] = {
1788 .driver_info = EM2820_BOARD_IODATA_GVMVP_SZ }, 1814 .driver_info = EM2820_BOARD_IODATA_GVMVP_SZ },
1789 { USB_DEVICE(0xeb1a, 0x50a6), 1815 { USB_DEVICE(0xeb1a, 0x50a6),
1790 .driver_info = EM2860_BOARD_GADMEI_UTV330 }, 1816 .driver_info = EM2860_BOARD_GADMEI_UTV330 },
1817 { USB_DEVICE(0x1b80, 0xa340),
1818 .driver_info = EM2870_BOARD_KWORLD_A340 },
1791 { }, 1819 { },
1792}; 1820};
1793MODULE_DEVICE_TABLE(usb, em28xx_id_table); 1821MODULE_DEVICE_TABLE(usb, em28xx_id_table);
diff --git a/drivers/media/video/em28xx/em28xx-dvb.c b/drivers/media/video/em28xx/em28xx-dvb.c
index cf1d8c3655fc..3ac8d3025fea 100644
--- a/drivers/media/video/em28xx/em28xx-dvb.c
+++ b/drivers/media/video/em28xx/em28xx-dvb.c
@@ -30,11 +30,13 @@
30#include "tuner-simple.h" 30#include "tuner-simple.h"
31 31
32#include "lgdt330x.h" 32#include "lgdt330x.h"
33#include "lgdt3305.h"
33#include "zl10353.h" 34#include "zl10353.h"
34#include "s5h1409.h" 35#include "s5h1409.h"
35#include "mt352.h" 36#include "mt352.h"
36#include "mt352_priv.h" /* FIXME */ 37#include "mt352_priv.h" /* FIXME */
37#include "tda1002x.h" 38#include "tda1002x.h"
39#include "tda18271.h"
38 40
39MODULE_DESCRIPTION("driver for em28xx based DVB cards"); 41MODULE_DESCRIPTION("driver for em28xx based DVB cards");
40MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>"); 42MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
@@ -231,6 +233,18 @@ static struct lgdt330x_config em2880_lgdt3303_dev = {
231 .demod_chip = LGDT3303, 233 .demod_chip = LGDT3303,
232}; 234};
233 235
236static struct lgdt3305_config em2870_lgdt3304_dev = {
237 .i2c_addr = 0x0e,
238 .demod_chip = LGDT3304,
239 .spectral_inversion = 1,
240 .deny_i2c_rptr = 1,
241 .mpeg_mode = LGDT3305_MPEG_PARALLEL,
242 .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
243 .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
244 .vsb_if_khz = 3250,
245 .qam_if_khz = 4000,
246};
247
234static struct zl10353_config em28xx_zl10353_with_xc3028 = { 248static struct zl10353_config em28xx_zl10353_with_xc3028 = {
235 .demod_address = (0x1e >> 1), 249 .demod_address = (0x1e >> 1),
236 .no_tuner = 1, 250 .no_tuner = 1,
@@ -247,6 +261,17 @@ static struct s5h1409_config em28xx_s5h1409_with_xc3028 = {
247 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK 261 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK
248}; 262};
249 263
264static struct tda18271_std_map kworld_a340_std_map = {
265 .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 0,
266 .if_lvl = 1, .rfagc_top = 0x37, },
267 .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 1,
268 .if_lvl = 1, .rfagc_top = 0x37, },
269};
270
271static struct tda18271_config kworld_a340_config = {
272 .std_map = &kworld_a340_std_map,
273};
274
250static struct zl10353_config em28xx_zl10353_xc3028_no_i2c_gate = { 275static struct zl10353_config em28xx_zl10353_xc3028_no_i2c_gate = {
251 .demod_address = (0x1e >> 1), 276 .demod_address = (0x1e >> 1),
252 .no_tuner = 1, 277 .no_tuner = 1,
@@ -572,6 +597,14 @@ static int dvb_init(struct em28xx *dev)
572 } 597 }
573 } 598 }
574 break; 599 break;
600 case EM2870_BOARD_KWORLD_A340:
601 dvb->frontend = dvb_attach(lgdt3305_attach,
602 &em2870_lgdt3304_dev,
603 &dev->i2c_adap);
604 if (dvb->frontend != NULL)
605 dvb_attach(tda18271_attach, dvb->frontend, 0x60,
606 &dev->i2c_adap, &kworld_a340_config);
607 break;
575 default: 608 default:
576 em28xx_errdev("/2: The frontend of your DVB/ATSC card" 609 em28xx_errdev("/2: The frontend of your DVB/ATSC card"
577 " isn't supported yet\n"); 610 " isn't supported yet\n");
diff --git a/drivers/media/video/em28xx/em28xx-input.c b/drivers/media/video/em28xx/em28xx-input.c
index 5c3fd9411b1f..6759cd5570dd 100644
--- a/drivers/media/video/em28xx/em28xx-input.c
+++ b/drivers/media/video/em28xx/em28xx-input.c
@@ -65,17 +65,14 @@ struct em28xx_ir_poll_result {
65struct em28xx_IR { 65struct em28xx_IR {
66 struct em28xx *dev; 66 struct em28xx *dev;
67 struct input_dev *input; 67 struct input_dev *input;
68 struct ir_input_state ir;
69 char name[32]; 68 char name[32];
70 char phys[32]; 69 char phys[32];
71 70
72 /* poll external decoder */ 71 /* poll external decoder */
73 int polling; 72 int polling;
74 struct delayed_work work; 73 struct delayed_work work;
75 unsigned int last_toggle:1;
76 unsigned int full_code:1; 74 unsigned int full_code:1;
77 unsigned int last_readcount; 75 unsigned int last_readcount;
78 unsigned int repeat_interval;
79 76
80 int (*get_key)(struct em28xx_IR *, struct em28xx_ir_poll_result *); 77 int (*get_key)(struct em28xx_IR *, struct em28xx_ir_poll_result *);
81 78
@@ -291,67 +288,39 @@ static int em2874_polling_getkey(struct em28xx_IR *ir,
291static void em28xx_ir_handle_key(struct em28xx_IR *ir) 288static void em28xx_ir_handle_key(struct em28xx_IR *ir)
292{ 289{
293 int result; 290 int result;
294 int do_sendkey = 0;
295 struct em28xx_ir_poll_result poll_result; 291 struct em28xx_ir_poll_result poll_result;
296 292
297 /* read the registers containing the IR status */ 293 /* read the registers containing the IR status */
298 result = ir->get_key(ir, &poll_result); 294 result = ir->get_key(ir, &poll_result);
299 if (result < 0) { 295 if (unlikely(result < 0)) {
300 dprintk("ir->get_key() failed %d\n", result); 296 dprintk("ir->get_key() failed %d\n", result);
301 return; 297 return;
302 } 298 }
303 299
304 dprintk("ir->get_key result tb=%02x rc=%02x lr=%02x data=%02x%02x\n", 300 if (unlikely(poll_result.read_count != ir->last_readcount)) {
305 poll_result.toggle_bit, poll_result.read_count, 301 dprintk("%s: toggle: %d, count: %d, key 0x%02x%02x\n", __func__,
306 ir->last_readcount, poll_result.rc_address, 302 poll_result.toggle_bit, poll_result.read_count,
307 poll_result.rc_data[0]); 303 poll_result.rc_address, poll_result.rc_data[0]);
308
309 if (ir->dev->chip_id == CHIP_ID_EM2874) {
310 /* The em2874 clears the readcount field every time the
311 register is read. The em2860/2880 datasheet says that it
312 is supposed to clear the readcount, but it doesn't. So with
313 the em2874, we are looking for a non-zero read count as
314 opposed to a readcount that is incrementing */
315 ir->last_readcount = 0;
316 }
317
318 if (poll_result.read_count == 0) {
319 /* The button has not been pressed since the last read */
320 } else if (ir->last_toggle != poll_result.toggle_bit) {
321 /* A button has been pressed */
322 dprintk("button has been pressed\n");
323 ir->last_toggle = poll_result.toggle_bit;
324 ir->repeat_interval = 0;
325 do_sendkey = 1;
326 } else if (poll_result.toggle_bit == ir->last_toggle &&
327 poll_result.read_count > 0 &&
328 poll_result.read_count != ir->last_readcount) {
329 /* The button is still being held down */
330 dprintk("button being held down\n");
331
332 /* Debouncer for first keypress */
333 if (ir->repeat_interval++ > 9) {
334 /* Start repeating after 1 second */
335 do_sendkey = 1;
336 }
337 }
338
339 if (do_sendkey) {
340 dprintk("sending keypress\n");
341
342 if (ir->full_code) 304 if (ir->full_code)
343 ir_input_keydown(ir->input, &ir->ir, 305 ir_keydown(ir->input,
344 poll_result.rc_address << 8 | 306 poll_result.rc_address << 8 |
345 poll_result.rc_data[0]); 307 poll_result.rc_data[0],
308 poll_result.toggle_bit);
346 else 309 else
347 ir_input_keydown(ir->input, &ir->ir, 310 ir_keydown(ir->input,
348 poll_result.rc_data[0]); 311 poll_result.rc_data[0],
349 312 poll_result.toggle_bit);
350 ir_input_nokey(ir->input, &ir->ir); 313
314 if (ir->dev->chip_id == CHIP_ID_EM2874)
315 /* The em2874 clears the readcount field every time the
316 register is read. The em2860/2880 datasheet says that it
317 is supposed to clear the readcount, but it doesn't. So with
318 the em2874, we are looking for a non-zero read count as
319 opposed to a readcount that is incrementing */
320 ir->last_readcount = 0;
321 else
322 ir->last_readcount = poll_result.read_count;
351 } 323 }
352
353 ir->last_readcount = poll_result.read_count;
354 return;
355} 324}
356 325
357static void em28xx_ir_work(struct work_struct *work) 326static void em28xx_ir_work(struct work_struct *work)
@@ -466,11 +435,6 @@ int em28xx_ir_init(struct em28xx *dev)
466 usb_make_path(dev->udev, ir->phys, sizeof(ir->phys)); 435 usb_make_path(dev->udev, ir->phys, sizeof(ir->phys));
467 strlcat(ir->phys, "/input0", sizeof(ir->phys)); 436 strlcat(ir->phys, "/input0", sizeof(ir->phys));
468 437
469 /* Set IR protocol */
470 err = ir_input_init(input_dev, &ir->ir, IR_TYPE_OTHER);
471 if (err < 0)
472 goto err_out_free;
473
474 input_dev->name = ir->name; 438 input_dev->name = ir->name;
475 input_dev->phys = ir->phys; 439 input_dev->phys = ir->phys;
476 input_dev->id.bustype = BUS_USB; 440 input_dev->id.bustype = BUS_USB;
diff --git a/drivers/media/video/em28xx/em28xx-video.c b/drivers/media/video/em28xx/em28xx-video.c
index 20090e34173a..7b9ec6e493e4 100644
--- a/drivers/media/video/em28xx/em28xx-video.c
+++ b/drivers/media/video/em28xx/em28xx-video.c
@@ -654,12 +654,12 @@ static inline int em28xx_isoc_copy_vbi(struct em28xx *dev, struct urb *urb)
654 } 654 }
655 655
656 if (buf != NULL && dev->capture_type == 2) { 656 if (buf != NULL && dev->capture_type == 2) {
657 if (len > 4 && p[0] == 0x88 && p[1] == 0x88 && 657 if (len >= 4 && p[0] == 0x88 && p[1] == 0x88 &&
658 p[2] == 0x88 && p[3] == 0x88) { 658 p[2] == 0x88 && p[3] == 0x88) {
659 p += 4; 659 p += 4;
660 len -= 4; 660 len -= 4;
661 } 661 }
662 if (len > 4 && p[0] == 0x22 && p[1] == 0x5a) { 662 if (len >= 4 && p[0] == 0x22 && p[1] == 0x5a) {
663 em28xx_isocdbg("Video frame %d, len=%i, %s\n", 663 em28xx_isocdbg("Video frame %d, len=%i, %s\n",
664 p[2], len, (p[2] & 1) ? 664 p[2], len, (p[2] & 1) ?
665 "odd" : "even"); 665 "odd" : "even");
diff --git a/drivers/media/video/em28xx/em28xx.h b/drivers/media/video/em28xx/em28xx.h
index b252d1b1b2a7..1c61a6b65d28 100644
--- a/drivers/media/video/em28xx/em28xx.h
+++ b/drivers/media/video/em28xx/em28xx.h
@@ -32,6 +32,7 @@
32#include <linux/i2c.h> 32#include <linux/i2c.h>
33#include <linux/mutex.h> 33#include <linux/mutex.h>
34#include <media/ir-kbd-i2c.h> 34#include <media/ir-kbd-i2c.h>
35#include <media/ir-core.h>
35#if defined(CONFIG_VIDEO_EM28XX_DVB) || defined(CONFIG_VIDEO_EM28XX_DVB_MODULE) 36#if defined(CONFIG_VIDEO_EM28XX_DVB) || defined(CONFIG_VIDEO_EM28XX_DVB_MODULE)
36#include <media/videobuf-dvb.h> 37#include <media/videobuf-dvb.h>
37#endif 38#endif
@@ -113,6 +114,7 @@
113#define EM2870_BOARD_REDDO_DVB_C_USB_BOX 73 114#define EM2870_BOARD_REDDO_DVB_C_USB_BOX 73
114#define EM2800_BOARD_VC211A 74 115#define EM2800_BOARD_VC211A 74
115#define EM2882_BOARD_DIKOM_DK300 75 116#define EM2882_BOARD_DIKOM_DK300 75
117#define EM2870_BOARD_KWORLD_A340 76
116 118
117/* Limits minimum and default number of buffers */ 119/* Limits minimum and default number of buffers */
118#define EM28XX_MIN_BUF 4 120#define EM28XX_MIN_BUF 4
diff --git a/drivers/media/video/fsl-viu.c b/drivers/media/video/fsl-viu.c
new file mode 100644
index 000000000000..8f1c94f7e00c
--- /dev/null
+++ b/drivers/media/video/fsl-viu.c
@@ -0,0 +1,1632 @@
1/*
2 * Copyright 2008-2010 Freescale Semiconductor, Inc. All Rights Reserved.
3 *
4 * Freescale VIU video driver
5 *
6 * Authors: Hongjun Chen <hong-jun.chen@freescale.com>
7 * Porting to 2.6.35 by DENX Software Engineering,
8 * Anatolij Gustschin <agust@denx.de>
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version.
14 *
15 */
16
17#include <linux/module.h>
18#include <linux/clk.h>
19#include <linux/kernel.h>
20#include <linux/i2c.h>
21#include <linux/init.h>
22#include <linux/interrupt.h>
23#include <linux/io.h>
24#include <linux/of_platform.h>
25#include <linux/version.h>
26#include <media/v4l2-common.h>
27#include <media/v4l2-device.h>
28#include <media/v4l2-ioctl.h>
29#include <media/videobuf-dma-contig.h>
30
31#define DRV_NAME "fsl_viu"
32#define VIU_MAJOR_VERSION 0
33#define VIU_MINOR_VERSION 5
34#define VIU_RELEASE 0
35#define VIU_VERSION KERNEL_VERSION(VIU_MAJOR_VERSION, \
36 VIU_MINOR_VERSION, \
37 VIU_RELEASE)
38
39#define BUFFER_TIMEOUT msecs_to_jiffies(500) /* 0.5 seconds */
40
41#define VIU_VID_MEM_LIMIT 4 /* Video memory limit, in Mb */
42
43/* I2C address of video decoder chip is 0x4A */
44#define VIU_VIDEO_DECODER_ADDR 0x25
45
46/* supported controls */
47static struct v4l2_queryctrl viu_qctrl[] = {
48 {
49 .id = V4L2_CID_BRIGHTNESS,
50 .type = V4L2_CTRL_TYPE_INTEGER,
51 .name = "Brightness",
52 .minimum = 0,
53 .maximum = 255,
54 .step = 1,
55 .default_value = 127,
56 .flags = 0,
57 }, {
58 .id = V4L2_CID_CONTRAST,
59 .type = V4L2_CTRL_TYPE_INTEGER,
60 .name = "Contrast",
61 .minimum = 0,
62 .maximum = 255,
63 .step = 0x1,
64 .default_value = 0x10,
65 .flags = 0,
66 }, {
67 .id = V4L2_CID_SATURATION,
68 .type = V4L2_CTRL_TYPE_INTEGER,
69 .name = "Saturation",
70 .minimum = 0,
71 .maximum = 255,
72 .step = 0x1,
73 .default_value = 127,
74 .flags = 0,
75 }, {
76 .id = V4L2_CID_HUE,
77 .type = V4L2_CTRL_TYPE_INTEGER,
78 .name = "Hue",
79 .minimum = -128,
80 .maximum = 127,
81 .step = 0x1,
82 .default_value = 0,
83 .flags = 0,
84 }
85};
86
87static int qctl_regs[ARRAY_SIZE(viu_qctrl)];
88
89static int info_level;
90
91#define dprintk(level, fmt, arg...) \
92 do { \
93 if (level <= info_level) \
94 printk(KERN_DEBUG "viu: " fmt , ## arg); \
95 } while (0)
96
97/*
98 * Basic structures
99 */
100struct viu_fmt {
101 char name[32];
102 u32 fourcc; /* v4l2 format id */
103 u32 pixelformat;
104 int depth;
105};
106
107static struct viu_fmt formats[] = {
108 {
109 .name = "RGB-16 (5/B-6/G-5/R)",
110 .fourcc = V4L2_PIX_FMT_RGB565,
111 .pixelformat = V4L2_PIX_FMT_RGB565,
112 .depth = 16,
113 }, {
114 .name = "RGB-32 (A-R-G-B)",
115 .fourcc = V4L2_PIX_FMT_RGB32,
116 .pixelformat = V4L2_PIX_FMT_RGB32,
117 .depth = 32,
118 }
119};
120
121struct viu_dev;
122struct viu_buf;
123
124/* buffer for one video frame */
125struct viu_buf {
126 /* common v4l buffer stuff -- must be first */
127 struct videobuf_buffer vb;
128 struct viu_fmt *fmt;
129};
130
131struct viu_dmaqueue {
132 struct viu_dev *dev;
133 struct list_head active;
134 struct list_head queued;
135 struct timer_list timeout;
136};
137
138struct viu_status {
139 u32 field_irq;
140 u32 vsync_irq;
141 u32 hsync_irq;
142 u32 vstart_irq;
143 u32 dma_end_irq;
144 u32 error_irq;
145};
146
147struct viu_reg {
148 u32 status_cfg;
149 u32 luminance;
150 u32 chroma_r;
151 u32 chroma_g;
152 u32 chroma_b;
153 u32 field_base_addr;
154 u32 dma_inc;
155 u32 picture_count;
156 u32 req_alarm;
157 u32 alpha;
158} __attribute__ ((packed));
159
160struct viu_dev {
161 struct v4l2_device v4l2_dev;
162 struct mutex lock;
163 spinlock_t slock;
164 int users;
165
166 struct device *dev;
167 /* various device info */
168 struct video_device *vdev;
169 struct viu_dmaqueue vidq;
170 enum v4l2_field capfield;
171 int field;
172 int first;
173 int dma_done;
174
175 /* Hardware register area */
176 struct viu_reg *vr;
177
178 /* Interrupt vector */
179 int irq;
180 struct viu_status irqs;
181
182 /* video overlay */
183 struct v4l2_framebuffer ovbuf;
184 struct viu_fmt *ovfmt;
185 unsigned int ovenable;
186 enum v4l2_field ovfield;
187
188 /* crop */
189 struct v4l2_rect crop_current;
190
191 /* clock pointer */
192 struct clk *clk;
193
194 /* decoder */
195 struct v4l2_subdev *decoder;
196};
197
198struct viu_fh {
199 struct viu_dev *dev;
200
201 /* video capture */
202 struct videobuf_queue vb_vidq;
203 spinlock_t vbq_lock; /* spinlock for the videobuf queue */
204
205 /* video overlay */
206 struct v4l2_window win;
207 struct v4l2_clip clips[1];
208
209 /* video capture */
210 struct viu_fmt *fmt;
211 int width, height, sizeimage;
212 enum v4l2_buf_type type;
213};
214
215static struct viu_reg reg_val;
216
217/*
218 * Macro definitions of VIU registers
219 */
220
221/* STATUS_CONFIG register */
222enum status_config {
223 SOFT_RST = 1 << 0,
224
225 ERR_MASK = 0x0f << 4, /* Error code mask */
226 ERR_NO = 0x00, /* No error */
227 ERR_DMA_V = 0x01 << 4, /* DMA in vertical active */
228 ERR_DMA_VB = 0x02 << 4, /* DMA in vertical blanking */
229 ERR_LINE_TOO_LONG = 0x04 << 4, /* Line too long */
230 ERR_TOO_MANG_LINES = 0x05 << 4, /* Too many lines in field */
231 ERR_LINE_TOO_SHORT = 0x06 << 4, /* Line too short */
232 ERR_NOT_ENOUGH_LINE = 0x07 << 4, /* Not enough lines in field */
233 ERR_FIFO_OVERFLOW = 0x08 << 4, /* FIFO overflow */
234 ERR_FIFO_UNDERFLOW = 0x09 << 4, /* FIFO underflow */
235 ERR_1bit_ECC = 0x0a << 4, /* One bit ECC error */
236 ERR_MORE_ECC = 0x0b << 4, /* Two/more bits ECC error */
237
238 INT_FIELD_EN = 0x01 << 8, /* Enable field interrupt */
239 INT_VSYNC_EN = 0x01 << 9, /* Enable vsync interrupt */
240 INT_HSYNC_EN = 0x01 << 10, /* Enable hsync interrupt */
241 INT_VSTART_EN = 0x01 << 11, /* Enable vstart interrupt */
242 INT_DMA_END_EN = 0x01 << 12, /* Enable DMA end interrupt */
243 INT_ERROR_EN = 0x01 << 13, /* Enable error interrupt */
244 INT_ECC_EN = 0x01 << 14, /* Enable ECC interrupt */
245
246 INT_FIELD_STATUS = 0x01 << 16, /* field interrupt status */
247 INT_VSYNC_STATUS = 0x01 << 17, /* vsync interrupt status */
248 INT_HSYNC_STATUS = 0x01 << 18, /* hsync interrupt status */
249 INT_VSTART_STATUS = 0x01 << 19, /* vstart interrupt status */
250 INT_DMA_END_STATUS = 0x01 << 20, /* DMA end interrupt status */
251 INT_ERROR_STATUS = 0x01 << 21, /* error interrupt status */
252
253 DMA_ACT = 0x01 << 27, /* Enable DMA transfer */
254 FIELD_NO = 0x01 << 28, /* Field number */
255 DITHER_ON = 0x01 << 29, /* Dithering is on */
256 ROUND_ON = 0x01 << 30, /* Round is on */
257 MODE_32BIT = 0x01 << 31, /* Data in RGBa888,
258 * 0 in RGB565
259 */
260};
261
262#define norm_maxw() 720
263#define norm_maxh() 576
264
265#define INT_ALL_STATUS (INT_FIELD_STATUS | INT_VSYNC_STATUS | \
266 INT_HSYNC_STATUS | INT_VSTART_STATUS | \
267 INT_DMA_END_STATUS | INT_ERROR_STATUS)
268
269#define NUM_FORMATS ARRAY_SIZE(formats)
270
271static irqreturn_t viu_intr(int irq, void *dev_id);
272
273struct viu_fmt *format_by_fourcc(int fourcc)
274{
275 int i;
276
277 for (i = 0; i < NUM_FORMATS; i++) {
278 if (formats[i].pixelformat == fourcc)
279 return formats + i;
280 }
281
282 dprintk(0, "unknown pixelformat:'%4.4s'\n", (char *)&fourcc);
283 return NULL;
284}
285
286void viu_start_dma(struct viu_dev *dev)
287{
288 struct viu_reg *vr = dev->vr;
289
290 dev->field = 0;
291
292 /* Enable DMA operation */
293 out_be32(&vr->status_cfg, SOFT_RST);
294 out_be32(&vr->status_cfg, INT_FIELD_EN);
295}
296
297void viu_stop_dma(struct viu_dev *dev)
298{
299 struct viu_reg *vr = dev->vr;
300 int cnt = 100;
301 u32 status_cfg;
302
303 out_be32(&vr->status_cfg, 0);
304
305 /* Clear pending interrupts */
306 status_cfg = in_be32(&vr->status_cfg);
307 if (status_cfg & 0x3f0000)
308 out_be32(&vr->status_cfg, status_cfg & 0x3f0000);
309
310 if (status_cfg & DMA_ACT) {
311 do {
312 status_cfg = in_be32(&vr->status_cfg);
313 if (status_cfg & INT_DMA_END_STATUS)
314 break;
315 } while (cnt--);
316
317 if (cnt < 0) {
318 /* timed out, issue soft reset */
319 out_be32(&vr->status_cfg, SOFT_RST);
320 out_be32(&vr->status_cfg, 0);
321 } else {
322 /* clear DMA_END and other pending irqs */
323 out_be32(&vr->status_cfg, status_cfg & 0x3f0000);
324 }
325 }
326
327 dev->field = 0;
328}
329
330static int restart_video_queue(struct viu_dmaqueue *vidq)
331{
332 struct viu_buf *buf, *prev;
333
334 dprintk(1, "%s vidq=0x%08lx\n", __func__, (unsigned long)vidq);
335 if (!list_empty(&vidq->active)) {
336 buf = list_entry(vidq->active.next, struct viu_buf, vb.queue);
337 dprintk(2, "restart_queue [%p/%d]: restart dma\n",
338 buf, buf->vb.i);
339
340 viu_stop_dma(vidq->dev);
341
342 /* cancel all outstanding capture requests */
343 list_for_each_entry_safe(buf, prev, &vidq->active, vb.queue) {
344 list_del(&buf->vb.queue);
345 buf->vb.state = VIDEOBUF_ERROR;
346 wake_up(&buf->vb.done);
347 }
348 mod_timer(&vidq->timeout, jiffies+BUFFER_TIMEOUT);
349 return 0;
350 }
351
352 prev = NULL;
353 for (;;) {
354 if (list_empty(&vidq->queued))
355 return 0;
356 buf = list_entry(vidq->queued.next, struct viu_buf, vb.queue);
357 if (prev == NULL) {
358 list_del(&buf->vb.queue);
359 list_add_tail(&buf->vb.queue, &vidq->active);
360
361 dprintk(1, "Restarting video dma\n");
362 viu_stop_dma(vidq->dev);
363 viu_start_dma(vidq->dev);
364
365 buf->vb.state = VIDEOBUF_ACTIVE;
366 mod_timer(&vidq->timeout, jiffies+BUFFER_TIMEOUT);
367 dprintk(2, "[%p/%d] restart_queue - first active\n",
368 buf, buf->vb.i);
369
370 } else if (prev->vb.width == buf->vb.width &&
371 prev->vb.height == buf->vb.height &&
372 prev->fmt == buf->fmt) {
373 list_del(&buf->vb.queue);
374 list_add_tail(&buf->vb.queue, &vidq->active);
375 buf->vb.state = VIDEOBUF_ACTIVE;
376 dprintk(2, "[%p/%d] restart_queue - move to active\n",
377 buf, buf->vb.i);
378 } else {
379 return 0;
380 }
381 prev = buf;
382 }
383}
384
385static void viu_vid_timeout(unsigned long data)
386{
387 struct viu_dev *dev = (struct viu_dev *)data;
388 struct viu_buf *buf;
389 struct viu_dmaqueue *vidq = &dev->vidq;
390
391 while (!list_empty(&vidq->active)) {
392 buf = list_entry(vidq->active.next, struct viu_buf, vb.queue);
393 list_del(&buf->vb.queue);
394 buf->vb.state = VIDEOBUF_ERROR;
395 wake_up(&buf->vb.done);
396 dprintk(1, "viu/0: [%p/%d] timeout\n", buf, buf->vb.i);
397 }
398
399 restart_video_queue(vidq);
400}
401
402/*
403 * Videobuf operations
404 */
405static int buffer_setup(struct videobuf_queue *vq, unsigned int *count,
406 unsigned int *size)
407{
408 struct viu_fh *fh = vq->priv_data;
409
410 *size = fh->width * fh->height * fh->fmt->depth >> 3;
411 if (*count == 0)
412 *count = 32;
413
414 while (*size * *count > VIU_VID_MEM_LIMIT * 1024 * 1024)
415 (*count)--;
416
417 dprintk(1, "%s, count=%d, size=%d\n", __func__, *count, *size);
418 return 0;
419}
420
421static void free_buffer(struct videobuf_queue *vq, struct viu_buf *buf)
422{
423 struct videobuf_buffer *vb = &buf->vb;
424 void *vaddr = NULL;
425
426 BUG_ON(in_interrupt());
427
428 videobuf_waiton(&buf->vb, 0, 0);
429
430 if (vq->int_ops && vq->int_ops->vaddr)
431 vaddr = vq->int_ops->vaddr(vb);
432
433 if (vaddr)
434 videobuf_dma_contig_free(vq, &buf->vb);
435
436 buf->vb.state = VIDEOBUF_NEEDS_INIT;
437}
438
439inline int buffer_activate(struct viu_dev *dev, struct viu_buf *buf)
440{
441 struct viu_reg *vr = dev->vr;
442 int bpp;
443
444 /* setup the DMA base address */
445 reg_val.field_base_addr = videobuf_to_dma_contig(&buf->vb);
446
447 dprintk(1, "buffer_activate [%p/%d]: dma addr 0x%lx\n",
448 buf, buf->vb.i, (unsigned long)reg_val.field_base_addr);
449
450 /* interlace is on by default, set horizontal DMA increment */
451 reg_val.status_cfg = 0;
452 bpp = buf->fmt->depth >> 3;
453 switch (bpp) {
454 case 2:
455 reg_val.status_cfg &= ~MODE_32BIT;
456 reg_val.dma_inc = buf->vb.width * 2;
457 break;
458 case 4:
459 reg_val.status_cfg |= MODE_32BIT;
460 reg_val.dma_inc = buf->vb.width * 4;
461 break;
462 default:
463 dprintk(0, "doesn't support color depth(%d)\n",
464 bpp * 8);
465 return -EINVAL;
466 }
467
468 /* setup picture_count register */
469 reg_val.picture_count = (buf->vb.height / 2) << 16 |
470 buf->vb.width;
471
472 reg_val.status_cfg |= DMA_ACT | INT_DMA_END_EN | INT_FIELD_EN;
473
474 buf->vb.state = VIDEOBUF_ACTIVE;
475 dev->capfield = buf->vb.field;
476
477 /* reset dma increment if needed */
478 if (!V4L2_FIELD_HAS_BOTH(buf->vb.field))
479 reg_val.dma_inc = 0;
480
481 out_be32(&vr->dma_inc, reg_val.dma_inc);
482 out_be32(&vr->picture_count, reg_val.picture_count);
483 out_be32(&vr->field_base_addr, reg_val.field_base_addr);
484 mod_timer(&dev->vidq.timeout, jiffies + BUFFER_TIMEOUT);
485 return 0;
486}
487
488static int buffer_prepare(struct videobuf_queue *vq,
489 struct videobuf_buffer *vb,
490 enum v4l2_field field)
491{
492 struct viu_fh *fh = vq->priv_data;
493 struct viu_buf *buf = container_of(vb, struct viu_buf, vb);
494 int rc;
495
496 BUG_ON(fh->fmt == NULL);
497
498 if (fh->width < 48 || fh->width > norm_maxw() ||
499 fh->height < 32 || fh->height > norm_maxh())
500 return -EINVAL;
501 buf->vb.size = (fh->width * fh->height * fh->fmt->depth) >> 3;
502 if (buf->vb.baddr != 0 && buf->vb.bsize < buf->vb.size)
503 return -EINVAL;
504
505 if (buf->fmt != fh->fmt ||
506 buf->vb.width != fh->width ||
507 buf->vb.height != fh->height ||
508 buf->vb.field != field) {
509 buf->fmt = fh->fmt;
510 buf->vb.width = fh->width;
511 buf->vb.height = fh->height;
512 buf->vb.field = field;
513 }
514
515 if (buf->vb.state == VIDEOBUF_NEEDS_INIT) {
516 rc = videobuf_iolock(vq, &buf->vb, NULL);
517 if (rc != 0)
518 goto fail;
519
520 buf->vb.width = fh->width;
521 buf->vb.height = fh->height;
522 buf->vb.field = field;
523 buf->fmt = fh->fmt;
524 }
525
526 buf->vb.state = VIDEOBUF_PREPARED;
527 return 0;
528
529fail:
530 free_buffer(vq, buf);
531 return rc;
532}
533
534static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
535{
536 struct viu_buf *buf = container_of(vb, struct viu_buf, vb);
537 struct viu_fh *fh = vq->priv_data;
538 struct viu_dev *dev = fh->dev;
539 struct viu_dmaqueue *vidq = &dev->vidq;
540 struct viu_buf *prev;
541
542 if (!list_empty(&vidq->queued)) {
543 dprintk(1, "adding vb queue=0x%08lx\n",
544 (unsigned long)&buf->vb.queue);
545 dprintk(1, "vidq pointer 0x%p, queued 0x%p\n",
546 vidq, &vidq->queued);
547 dprintk(1, "dev %p, queued: self %p, next %p, head %p\n",
548 dev, &vidq->queued, vidq->queued.next,
549 vidq->queued.prev);
550 list_add_tail(&buf->vb.queue, &vidq->queued);
551 buf->vb.state = VIDEOBUF_QUEUED;
552 dprintk(2, "[%p/%d] buffer_queue - append to queued\n",
553 buf, buf->vb.i);
554 } else if (list_empty(&vidq->active)) {
555 dprintk(1, "adding vb active=0x%08lx\n",
556 (unsigned long)&buf->vb.queue);
557 list_add_tail(&buf->vb.queue, &vidq->active);
558 buf->vb.state = VIDEOBUF_ACTIVE;
559 mod_timer(&vidq->timeout, jiffies+BUFFER_TIMEOUT);
560 dprintk(2, "[%p/%d] buffer_queue - first active\n",
561 buf, buf->vb.i);
562
563 buffer_activate(dev, buf);
564 } else {
565 dprintk(1, "adding vb queue2=0x%08lx\n",
566 (unsigned long)&buf->vb.queue);
567 prev = list_entry(vidq->active.prev, struct viu_buf, vb.queue);
568 if (prev->vb.width == buf->vb.width &&
569 prev->vb.height == buf->vb.height &&
570 prev->fmt == buf->fmt) {
571 list_add_tail(&buf->vb.queue, &vidq->active);
572 buf->vb.state = VIDEOBUF_ACTIVE;
573 dprintk(2, "[%p/%d] buffer_queue - append to active\n",
574 buf, buf->vb.i);
575 } else {
576 list_add_tail(&buf->vb.queue, &vidq->queued);
577 buf->vb.state = VIDEOBUF_QUEUED;
578 dprintk(2, "[%p/%d] buffer_queue - first queued\n",
579 buf, buf->vb.i);
580 }
581 }
582}
583
584static void buffer_release(struct videobuf_queue *vq,
585 struct videobuf_buffer *vb)
586{
587 struct viu_buf *buf = container_of(vb, struct viu_buf, vb);
588 struct viu_fh *fh = vq->priv_data;
589 struct viu_dev *dev = (struct viu_dev *)fh->dev;
590
591 viu_stop_dma(dev);
592 free_buffer(vq, buf);
593}
594
595static struct videobuf_queue_ops viu_video_qops = {
596 .buf_setup = buffer_setup,
597 .buf_prepare = buffer_prepare,
598 .buf_queue = buffer_queue,
599 .buf_release = buffer_release,
600};
601
602/*
603 * IOCTL vidioc handling
604 */
605static int vidioc_querycap(struct file *file, void *priv,
606 struct v4l2_capability *cap)
607{
608 strcpy(cap->driver, "viu");
609 strcpy(cap->card, "viu");
610 cap->version = VIU_VERSION;
611 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE |
612 V4L2_CAP_STREAMING |
613 V4L2_CAP_VIDEO_OVERLAY |
614 V4L2_CAP_READWRITE;
615 return 0;
616}
617
618static int vidioc_enum_fmt(struct file *file, void *priv,
619 struct v4l2_fmtdesc *f)
620{
621 int index = f->index;
622
623 if (f->index > NUM_FORMATS)
624 return -EINVAL;
625
626 strlcpy(f->description, formats[index].name, sizeof(f->description));
627 f->pixelformat = formats[index].fourcc;
628 return 0;
629}
630
631static int vidioc_g_fmt_cap(struct file *file, void *priv,
632 struct v4l2_format *f)
633{
634 struct viu_fh *fh = priv;
635
636 f->fmt.pix.width = fh->width;
637 f->fmt.pix.height = fh->height;
638 f->fmt.pix.field = fh->vb_vidq.field;
639 f->fmt.pix.pixelformat = fh->fmt->pixelformat;
640 f->fmt.pix.bytesperline =
641 (f->fmt.pix.width * fh->fmt->depth) >> 3;
642 f->fmt.pix.sizeimage = fh->sizeimage;
643 return 0;
644}
645
646static int vidioc_try_fmt_cap(struct file *file, void *priv,
647 struct v4l2_format *f)
648{
649 struct viu_fmt *fmt;
650 enum v4l2_field field;
651 unsigned int maxw, maxh;
652
653 fmt = format_by_fourcc(f->fmt.pix.pixelformat);
654 if (!fmt) {
655 dprintk(1, "Fourcc format (0x%08x) invalid.",
656 f->fmt.pix.pixelformat);
657 return -EINVAL;
658 }
659
660 field = f->fmt.pix.field;
661
662 if (field == V4L2_FIELD_ANY) {
663 field = V4L2_FIELD_INTERLACED;
664 } else if (field != V4L2_FIELD_INTERLACED) {
665 dprintk(1, "Field type invalid.\n");
666 return -EINVAL;
667 }
668
669 maxw = norm_maxw();
670 maxh = norm_maxh();
671
672 f->fmt.pix.field = field;
673 if (f->fmt.pix.height < 32)
674 f->fmt.pix.height = 32;
675 if (f->fmt.pix.height > maxh)
676 f->fmt.pix.height = maxh;
677 if (f->fmt.pix.width < 48)
678 f->fmt.pix.width = 48;
679 if (f->fmt.pix.width > maxw)
680 f->fmt.pix.width = maxw;
681 f->fmt.pix.width &= ~0x03;
682 f->fmt.pix.bytesperline =
683 (f->fmt.pix.width * fmt->depth) >> 3;
684
685 return 0;
686}
687
688static int vidioc_s_fmt_cap(struct file *file, void *priv,
689 struct v4l2_format *f)
690{
691 struct viu_fh *fh = priv;
692 int ret;
693
694 ret = vidioc_try_fmt_cap(file, fh, f);
695 if (ret < 0)
696 return ret;
697
698 fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat);
699 fh->width = f->fmt.pix.width;
700 fh->height = f->fmt.pix.height;
701 fh->sizeimage = f->fmt.pix.sizeimage;
702 fh->vb_vidq.field = f->fmt.pix.field;
703 fh->type = f->type;
704 dprintk(1, "set to pixelformat '%4.6s'\n", (char *)&fh->fmt->name);
705 return 0;
706}
707
708static int vidioc_g_fmt_overlay(struct file *file, void *priv,
709 struct v4l2_format *f)
710{
711 struct viu_fh *fh = priv;
712
713 f->fmt.win = fh->win;
714 return 0;
715}
716
717static int verify_preview(struct viu_dev *dev, struct v4l2_window *win)
718{
719 enum v4l2_field field;
720 int maxw, maxh;
721
722 if (dev->ovbuf.base == NULL)
723 return -EINVAL;
724 if (dev->ovfmt == NULL)
725 return -EINVAL;
726 if (win->w.width < 48 || win->w.height < 32)
727 return -EINVAL;
728
729 field = win->field;
730 maxw = dev->crop_current.width;
731 maxh = dev->crop_current.height;
732
733 if (field == V4L2_FIELD_ANY) {
734 field = (win->w.height > maxh/2)
735 ? V4L2_FIELD_INTERLACED
736 : V4L2_FIELD_TOP;
737 }
738 switch (field) {
739 case V4L2_FIELD_TOP:
740 case V4L2_FIELD_BOTTOM:
741 maxh = maxh / 2;
742 break;
743 case V4L2_FIELD_INTERLACED:
744 break;
745 default:
746 return -EINVAL;
747 }
748
749 win->field = field;
750 if (win->w.width > maxw)
751 win->w.width = maxw;
752 if (win->w.height > maxh)
753 win->w.height = maxh;
754 return 0;
755}
756
757inline void viu_activate_overlay(struct viu_reg *viu_reg)
758{
759 struct viu_reg *vr = viu_reg;
760
761 out_be32(&vr->field_base_addr, reg_val.field_base_addr);
762 out_be32(&vr->dma_inc, reg_val.dma_inc);
763 out_be32(&vr->picture_count, reg_val.picture_count);
764}
765
766static int viu_start_preview(struct viu_dev *dev, struct viu_fh *fh)
767{
768 int bpp;
769
770 dprintk(1, "%s %dx%d %s\n", __func__,
771 fh->win.w.width, fh->win.w.height, dev->ovfmt->name);
772
773 reg_val.status_cfg = 0;
774
775 /* setup window */
776 reg_val.picture_count = (fh->win.w.height / 2) << 16 |
777 fh->win.w.width;
778
779 /* setup color depth and dma increment */
780 bpp = dev->ovfmt->depth / 8;
781 switch (bpp) {
782 case 2:
783 reg_val.status_cfg &= ~MODE_32BIT;
784 reg_val.dma_inc = fh->win.w.width * 2;
785 break;
786 case 4:
787 reg_val.status_cfg |= MODE_32BIT;
788 reg_val.dma_inc = fh->win.w.width * 4;
789 break;
790 default:
791 dprintk(0, "device doesn't support color depth(%d)\n",
792 bpp * 8);
793 return -EINVAL;
794 }
795
796 dev->ovfield = fh->win.field;
797 if (!V4L2_FIELD_HAS_BOTH(dev->ovfield))
798 reg_val.dma_inc = 0;
799
800 reg_val.status_cfg |= DMA_ACT | INT_DMA_END_EN | INT_FIELD_EN;
801
802 /* setup the base address of the overlay buffer */
803 reg_val.field_base_addr = (u32)dev->ovbuf.base;
804
805 dev->ovenable = 1;
806 viu_activate_overlay(dev->vr);
807
808 /* start dma */
809 viu_start_dma(dev);
810 return 0;
811}
812
813static int vidioc_s_fmt_overlay(struct file *file, void *priv,
814 struct v4l2_format *f)
815{
816 struct viu_fh *fh = priv;
817 struct viu_dev *dev = (struct viu_dev *)fh->dev;
818 unsigned long flags;
819 int err;
820
821 err = verify_preview(dev, &f->fmt.win);
822 if (err)
823 return err;
824
825 mutex_lock(&dev->lock);
826 fh->win = f->fmt.win;
827
828 spin_lock_irqsave(&dev->slock, flags);
829 viu_start_preview(dev, fh);
830 spin_unlock_irqrestore(&dev->slock, flags);
831 mutex_unlock(&dev->lock);
832 return 0;
833}
834
835static int vidioc_try_fmt_overlay(struct file *file, void *priv,
836 struct v4l2_format *f)
837{
838 return 0;
839}
840
841int vidioc_g_fbuf(struct file *file, void *priv, struct v4l2_framebuffer *arg)
842{
843 struct viu_fh *fh = priv;
844 struct viu_dev *dev = fh->dev;
845 struct v4l2_framebuffer *fb = arg;
846
847 *fb = dev->ovbuf;
848 fb->capability = V4L2_FBUF_CAP_LIST_CLIPPING;
849 return 0;
850}
851
852int vidioc_s_fbuf(struct file *file, void *priv, struct v4l2_framebuffer *arg)
853{
854 struct viu_fh *fh = priv;
855 struct viu_dev *dev = fh->dev;
856 struct v4l2_framebuffer *fb = arg;
857 struct viu_fmt *fmt;
858
859 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RAWIO))
860 return -EPERM;
861
862 /* check args */
863 fmt = format_by_fourcc(fb->fmt.pixelformat);
864 if (fmt == NULL)
865 return -EINVAL;
866
867 /* ok, accept it */
868 dev->ovbuf = *fb;
869 dev->ovfmt = fmt;
870 if (dev->ovbuf.fmt.bytesperline == 0) {
871 dev->ovbuf.fmt.bytesperline =
872 dev->ovbuf.fmt.width * fmt->depth / 8;
873 }
874 return 0;
875}
876
877static int vidioc_reqbufs(struct file *file, void *priv,
878 struct v4l2_requestbuffers *p)
879{
880 struct viu_fh *fh = priv;
881
882 return videobuf_reqbufs(&fh->vb_vidq, p);
883}
884
885static int vidioc_querybuf(struct file *file, void *priv,
886 struct v4l2_buffer *p)
887{
888 struct viu_fh *fh = priv;
889
890 return videobuf_querybuf(&fh->vb_vidq, p);
891}
892
893static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *p)
894{
895 struct viu_fh *fh = priv;
896
897 return videobuf_qbuf(&fh->vb_vidq, p);
898}
899
900static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
901{
902 struct viu_fh *fh = priv;
903
904 return videobuf_dqbuf(&fh->vb_vidq, p,
905 file->f_flags & O_NONBLOCK);
906}
907
908static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
909{
910 struct viu_fh *fh = priv;
911
912 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
913 return -EINVAL;
914 if (fh->type != i)
915 return -EINVAL;
916
917 return videobuf_streamon(&fh->vb_vidq);
918}
919
920static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
921{
922 struct viu_fh *fh = priv;
923
924 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
925 return -EINVAL;
926 if (fh->type != i)
927 return -EINVAL;
928
929 return videobuf_streamoff(&fh->vb_vidq);
930}
931
932#define decoder_call(viu, o, f, args...) \
933 v4l2_subdev_call(viu->decoder, o, f, ##args)
934
935static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *id)
936{
937 struct viu_fh *fh = priv;
938
939 decoder_call(fh->dev, core, s_std, *id);
940 return 0;
941}
942
943/* only one input in this driver */
944static int vidioc_enum_input(struct file *file, void *priv,
945 struct v4l2_input *inp)
946{
947 struct viu_fh *fh = priv;
948
949 if (inp->index != 0)
950 return -EINVAL;
951
952 inp->type = V4L2_INPUT_TYPE_CAMERA;
953 inp->std = fh->dev->vdev->tvnorms;
954 strcpy(inp->name, "Camera");
955 return 0;
956}
957
958static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
959{
960 *i = 0;
961 return 0;
962}
963
964static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
965{
966 struct viu_fh *fh = priv;
967
968 if (i > 1)
969 return -EINVAL;
970
971 decoder_call(fh->dev, video, s_routing, i, 0, 0);
972 return 0;
973}
974
975/* Controls */
976static int vidioc_queryctrl(struct file *file, void *priv,
977 struct v4l2_queryctrl *qc)
978{
979 int i;
980
981 for (i = 0; i < ARRAY_SIZE(viu_qctrl); i++) {
982 if (qc->id && qc->id == viu_qctrl[i].id) {
983 memcpy(qc, &(viu_qctrl[i]), sizeof(*qc));
984 return 0;
985 }
986 }
987 return -EINVAL;
988}
989
990static int vidioc_g_ctrl(struct file *file, void *priv,
991 struct v4l2_control *ctrl)
992{
993 int i;
994
995 for (i = 0; i < ARRAY_SIZE(viu_qctrl); i++) {
996 if (ctrl->id == viu_qctrl[i].id) {
997 ctrl->value = qctl_regs[i];
998 return 0;
999 }
1000 }
1001 return -EINVAL;
1002}
1003static int vidioc_s_ctrl(struct file *file, void *priv,
1004 struct v4l2_control *ctrl)
1005{
1006 int i;
1007
1008 for (i = 0; i < ARRAY_SIZE(viu_qctrl); i++) {
1009 if (ctrl->id == viu_qctrl[i].id) {
1010 if (ctrl->value < viu_qctrl[i].minimum
1011 || ctrl->value > viu_qctrl[i].maximum)
1012 return -ERANGE;
1013 qctl_regs[i] = ctrl->value;
1014 return 0;
1015 }
1016 }
1017 return -EINVAL;
1018}
1019
1020inline void viu_activate_next_buf(struct viu_dev *dev,
1021 struct viu_dmaqueue *viuq)
1022{
1023 struct viu_dmaqueue *vidq = viuq;
1024 struct viu_buf *buf;
1025
1026 /* launch another DMA operation for an active/queued buffer */
1027 if (!list_empty(&vidq->active)) {
1028 buf = list_entry(vidq->active.next, struct viu_buf,
1029 vb.queue);
1030 dprintk(1, "start another queued buffer: 0x%p\n", buf);
1031 buffer_activate(dev, buf);
1032 } else if (!list_empty(&vidq->queued)) {
1033 buf = list_entry(vidq->queued.next, struct viu_buf,
1034 vb.queue);
1035 list_del(&buf->vb.queue);
1036
1037 dprintk(1, "start another queued buffer: 0x%p\n", buf);
1038 list_add_tail(&buf->vb.queue, &vidq->active);
1039 buf->vb.state = VIDEOBUF_ACTIVE;
1040 buffer_activate(dev, buf);
1041 }
1042}
1043
1044inline void viu_default_settings(struct viu_reg *viu_reg)
1045{
1046 struct viu_reg *vr = viu_reg;
1047
1048 out_be32(&vr->luminance, 0x9512A254);
1049 out_be32(&vr->chroma_r, 0x03310000);
1050 out_be32(&vr->chroma_g, 0x06600F38);
1051 out_be32(&vr->chroma_b, 0x00000409);
1052 out_be32(&vr->alpha, 0x000000ff);
1053 out_be32(&vr->req_alarm, 0x00000090);
1054 dprintk(1, "status reg: 0x%08x, field base: 0x%08x\n",
1055 in_be32(&vr->status_cfg), in_be32(&vr->field_base_addr));
1056}
1057
1058static void viu_overlay_intr(struct viu_dev *dev, u32 status)
1059{
1060 struct viu_reg *vr = dev->vr;
1061
1062 if (status & INT_DMA_END_STATUS)
1063 dev->dma_done = 1;
1064
1065 if (status & INT_FIELD_STATUS) {
1066 if (dev->dma_done) {
1067 u32 addr = reg_val.field_base_addr;
1068
1069 dev->dma_done = 0;
1070 if (status & FIELD_NO)
1071 addr += reg_val.dma_inc;
1072
1073 out_be32(&vr->field_base_addr, addr);
1074 out_be32(&vr->dma_inc, reg_val.dma_inc);
1075 out_be32(&vr->status_cfg,
1076 (status & 0xffc0ffff) |
1077 (status & INT_ALL_STATUS) |
1078 reg_val.status_cfg);
1079 } else if (status & INT_VSYNC_STATUS) {
1080 out_be32(&vr->status_cfg,
1081 (status & 0xffc0ffff) |
1082 (status & INT_ALL_STATUS) |
1083 reg_val.status_cfg);
1084 }
1085 }
1086}
1087
1088static void viu_capture_intr(struct viu_dev *dev, u32 status)
1089{
1090 struct viu_dmaqueue *vidq = &dev->vidq;
1091 struct viu_reg *vr = dev->vr;
1092 struct viu_buf *buf;
1093 int field_num;
1094 int need_two;
1095 int dma_done = 0;
1096
1097 field_num = status & FIELD_NO;
1098 need_two = V4L2_FIELD_HAS_BOTH(dev->capfield);
1099
1100 if (status & INT_DMA_END_STATUS) {
1101 dma_done = 1;
1102 if (((field_num == 0) && (dev->field == 0)) ||
1103 (field_num && (dev->field == 1)))
1104 dev->field++;
1105 }
1106
1107 if (status & INT_FIELD_STATUS) {
1108 dprintk(1, "irq: field %d, done %d\n",
1109 !!field_num, dma_done);
1110 if (unlikely(dev->first)) {
1111 if (field_num == 0) {
1112 dev->first = 0;
1113 dprintk(1, "activate first buf\n");
1114 viu_activate_next_buf(dev, vidq);
1115 } else
1116 dprintk(1, "wait field 0\n");
1117 return;
1118 }
1119
1120 /* setup buffer address for next dma operation */
1121 if (!list_empty(&vidq->active)) {
1122 u32 addr = reg_val.field_base_addr;
1123
1124 if (field_num && need_two) {
1125 addr += reg_val.dma_inc;
1126 dprintk(1, "field 1, 0x%lx, dev field %d\n",
1127 (unsigned long)addr, dev->field);
1128 }
1129 out_be32(&vr->field_base_addr, addr);
1130 out_be32(&vr->dma_inc, reg_val.dma_inc);
1131 out_be32(&vr->status_cfg,
1132 (status & 0xffc0ffff) |
1133 (status & INT_ALL_STATUS) |
1134 reg_val.status_cfg);
1135 return;
1136 }
1137 }
1138
1139 if (dma_done && field_num && (dev->field == 2)) {
1140 dev->field = 0;
1141 buf = list_entry(vidq->active.next,
1142 struct viu_buf, vb.queue);
1143 dprintk(1, "viu/0: [%p/%d] 0x%lx/0x%lx: dma complete\n",
1144 buf, buf->vb.i,
1145 (unsigned long)videobuf_to_dma_contig(&buf->vb),
1146 (unsigned long)in_be32(&vr->field_base_addr));
1147
1148 if (waitqueue_active(&buf->vb.done)) {
1149 list_del(&buf->vb.queue);
1150 do_gettimeofday(&buf->vb.ts);
1151 buf->vb.state = VIDEOBUF_DONE;
1152 buf->vb.field_count++;
1153 wake_up(&buf->vb.done);
1154 }
1155 /* activate next dma buffer */
1156 viu_activate_next_buf(dev, vidq);
1157 }
1158}
1159
1160static irqreturn_t viu_intr(int irq, void *dev_id)
1161{
1162 struct viu_dev *dev = (struct viu_dev *)dev_id;
1163 struct viu_reg *vr = dev->vr;
1164 u32 status;
1165 u32 error;
1166
1167 status = in_be32(&vr->status_cfg);
1168
1169 if (status & INT_ERROR_STATUS) {
1170 dev->irqs.error_irq++;
1171 error = status & ERR_MASK;
1172 if (error)
1173 dprintk(1, "Err: error(%d), times:%d!\n",
1174 error >> 4, dev->irqs.error_irq);
1175 /* Clear interrupt error bit and error flags */
1176 out_be32(&vr->status_cfg,
1177 (status & 0xffc0ffff) | INT_ERROR_STATUS);
1178 }
1179
1180 if (status & INT_DMA_END_STATUS) {
1181 dev->irqs.dma_end_irq++;
1182 dev->dma_done = 1;
1183 dprintk(2, "VIU DMA end interrupt times: %d\n",
1184 dev->irqs.dma_end_irq);
1185 }
1186
1187 if (status & INT_HSYNC_STATUS)
1188 dev->irqs.hsync_irq++;
1189
1190 if (status & INT_FIELD_STATUS) {
1191 dev->irqs.field_irq++;
1192 dprintk(2, "VIU field interrupt times: %d\n",
1193 dev->irqs.field_irq);
1194 }
1195
1196 if (status & INT_VSTART_STATUS)
1197 dev->irqs.vstart_irq++;
1198
1199 if (status & INT_VSYNC_STATUS) {
1200 dev->irqs.vsync_irq++;
1201 dprintk(2, "VIU vsync interrupt times: %d\n",
1202 dev->irqs.vsync_irq);
1203 }
1204
1205 /* clear all pending irqs */
1206 status = in_be32(&vr->status_cfg);
1207 out_be32(&vr->status_cfg,
1208 (status & 0xffc0ffff) | (status & INT_ALL_STATUS));
1209
1210 if (dev->ovenable) {
1211 viu_overlay_intr(dev, status);
1212 return IRQ_HANDLED;
1213 }
1214
1215 /* Capture mode */
1216 viu_capture_intr(dev, status);
1217 return IRQ_HANDLED;
1218}
1219
1220/*
1221 * File operations for the device
1222 */
1223static int viu_open(struct file *file)
1224{
1225 struct video_device *vdev = video_devdata(file);
1226 struct viu_dev *dev = video_get_drvdata(vdev);
1227 struct viu_fh *fh;
1228 struct viu_reg *vr;
1229 int minor = vdev->minor;
1230 u32 status_cfg;
1231 int i;
1232
1233 dprintk(1, "viu: open (minor=%d)\n", minor);
1234
1235 dev->users++;
1236 if (dev->users > 1) {
1237 dev->users--;
1238 return -EBUSY;
1239 }
1240
1241 vr = dev->vr;
1242
1243 dprintk(1, "open minor=%d type=%s users=%d\n", minor,
1244 v4l2_type_names[V4L2_BUF_TYPE_VIDEO_CAPTURE], dev->users);
1245
1246 /* allocate and initialize per filehandle data */
1247 fh = kzalloc(sizeof(*fh), GFP_KERNEL);
1248 if (!fh) {
1249 dev->users--;
1250 return -ENOMEM;
1251 }
1252
1253 file->private_data = fh;
1254 fh->dev = dev;
1255
1256 fh->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1257 fh->fmt = format_by_fourcc(V4L2_PIX_FMT_RGB32);
1258 fh->width = norm_maxw();
1259 fh->height = norm_maxh();
1260 dev->crop_current.width = fh->width;
1261 dev->crop_current.height = fh->height;
1262
1263 /* Put all controls at a sane state */
1264 for (i = 0; i < ARRAY_SIZE(viu_qctrl); i++)
1265 qctl_regs[i] = viu_qctrl[i].default_value;
1266
1267 dprintk(1, "Open: fh=0x%08lx, dev=0x%08lx, dev->vidq=0x%08lx\n",
1268 (unsigned long)fh, (unsigned long)dev,
1269 (unsigned long)&dev->vidq);
1270 dprintk(1, "Open: list_empty queued=%d\n",
1271 list_empty(&dev->vidq.queued));
1272 dprintk(1, "Open: list_empty active=%d\n",
1273 list_empty(&dev->vidq.active));
1274
1275 viu_default_settings(vr);
1276
1277 status_cfg = in_be32(&vr->status_cfg);
1278 out_be32(&vr->status_cfg,
1279 status_cfg & ~(INT_VSYNC_EN | INT_HSYNC_EN |
1280 INT_FIELD_EN | INT_VSTART_EN |
1281 INT_DMA_END_EN | INT_ERROR_EN | INT_ECC_EN));
1282
1283 status_cfg = in_be32(&vr->status_cfg);
1284 out_be32(&vr->status_cfg, status_cfg | INT_ALL_STATUS);
1285
1286 spin_lock_init(&fh->vbq_lock);
1287 videobuf_queue_dma_contig_init(&fh->vb_vidq, &viu_video_qops,
1288 dev->dev, &fh->vbq_lock,
1289 fh->type, V4L2_FIELD_INTERLACED,
1290 sizeof(struct viu_buf), fh);
1291 return 0;
1292}
1293
1294static ssize_t viu_read(struct file *file, char __user *data, size_t count,
1295 loff_t *ppos)
1296{
1297 struct viu_fh *fh = file->private_data;
1298 struct viu_dev *dev = fh->dev;
1299 int ret = 0;
1300
1301 dprintk(2, "%s\n", __func__);
1302 if (dev->ovenable)
1303 dev->ovenable = 0;
1304
1305 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1306 viu_start_dma(dev);
1307 ret = videobuf_read_stream(&fh->vb_vidq, data, count,
1308 ppos, 0, file->f_flags & O_NONBLOCK);
1309 return ret;
1310 }
1311 return 0;
1312}
1313
1314static unsigned int viu_poll(struct file *file, struct poll_table_struct *wait)
1315{
1316 struct viu_fh *fh = file->private_data;
1317 struct videobuf_queue *q = &fh->vb_vidq;
1318
1319 if (V4L2_BUF_TYPE_VIDEO_CAPTURE != fh->type)
1320 return POLLERR;
1321
1322 return videobuf_poll_stream(file, q, wait);
1323}
1324
1325static int viu_release(struct file *file)
1326{
1327 struct viu_fh *fh = file->private_data;
1328 struct viu_dev *dev = fh->dev;
1329 int minor = video_devdata(file)->minor;
1330
1331 viu_stop_dma(dev);
1332 videobuf_stop(&fh->vb_vidq);
1333
1334 kfree(fh);
1335
1336 dev->users--;
1337 dprintk(1, "close (minor=%d, users=%d)\n",
1338 minor, dev->users);
1339 return 0;
1340}
1341
1342void viu_reset(struct viu_reg *reg)
1343{
1344 out_be32(&reg->status_cfg, 0);
1345 out_be32(&reg->luminance, 0x9512a254);
1346 out_be32(&reg->chroma_r, 0x03310000);
1347 out_be32(&reg->chroma_g, 0x06600f38);
1348 out_be32(&reg->chroma_b, 0x00000409);
1349 out_be32(&reg->field_base_addr, 0);
1350 out_be32(&reg->dma_inc, 0);
1351 out_be32(&reg->picture_count, 0x01e002d0);
1352 out_be32(&reg->req_alarm, 0x00000090);
1353 out_be32(&reg->alpha, 0x000000ff);
1354}
1355
1356static int viu_mmap(struct file *file, struct vm_area_struct *vma)
1357{
1358 struct viu_fh *fh = file->private_data;
1359 int ret;
1360
1361 dprintk(1, "mmap called, vma=0x%08lx\n", (unsigned long)vma);
1362
1363 ret = videobuf_mmap_mapper(&fh->vb_vidq, vma);
1364
1365 dprintk(1, "vma start=0x%08lx, size=%ld, ret=%d\n",
1366 (unsigned long)vma->vm_start,
1367 (unsigned long)vma->vm_end-(unsigned long)vma->vm_start,
1368 ret);
1369
1370 return ret;
1371}
1372
1373static struct v4l2_file_operations viu_fops = {
1374 .owner = THIS_MODULE,
1375 .open = viu_open,
1376 .release = viu_release,
1377 .read = viu_read,
1378 .poll = viu_poll,
1379 .ioctl = video_ioctl2, /* V4L2 ioctl handler */
1380 .mmap = viu_mmap,
1381};
1382
1383static const struct v4l2_ioctl_ops viu_ioctl_ops = {
1384 .vidioc_querycap = vidioc_querycap,
1385 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt,
1386 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_cap,
1387 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_cap,
1388 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_cap,
1389 .vidioc_enum_fmt_vid_overlay = vidioc_enum_fmt,
1390 .vidioc_g_fmt_vid_overlay = vidioc_g_fmt_overlay,
1391 .vidioc_try_fmt_vid_overlay = vidioc_try_fmt_overlay,
1392 .vidioc_s_fmt_vid_overlay = vidioc_s_fmt_overlay,
1393 .vidioc_g_fbuf = vidioc_g_fbuf,
1394 .vidioc_s_fbuf = vidioc_s_fbuf,
1395 .vidioc_reqbufs = vidioc_reqbufs,
1396 .vidioc_querybuf = vidioc_querybuf,
1397 .vidioc_qbuf = vidioc_qbuf,
1398 .vidioc_dqbuf = vidioc_dqbuf,
1399 .vidioc_s_std = vidioc_s_std,
1400 .vidioc_enum_input = vidioc_enum_input,
1401 .vidioc_g_input = vidioc_g_input,
1402 .vidioc_s_input = vidioc_s_input,
1403 .vidioc_queryctrl = vidioc_queryctrl,
1404 .vidioc_g_ctrl = vidioc_g_ctrl,
1405 .vidioc_s_ctrl = vidioc_s_ctrl,
1406 .vidioc_streamon = vidioc_streamon,
1407 .vidioc_streamoff = vidioc_streamoff,
1408};
1409
1410static struct video_device viu_template = {
1411 .name = "FSL viu",
1412 .fops = &viu_fops,
1413 .minor = -1,
1414 .ioctl_ops = &viu_ioctl_ops,
1415 .release = video_device_release,
1416
1417 .tvnorms = V4L2_STD_NTSC_M | V4L2_STD_PAL,
1418 .current_norm = V4L2_STD_NTSC_M,
1419};
1420
1421static int __devinit viu_of_probe(struct of_device *op,
1422 const struct of_device_id *match)
1423{
1424 struct viu_dev *viu_dev;
1425 struct video_device *vdev;
1426 struct resource r;
1427 struct viu_reg __iomem *viu_regs;
1428 struct i2c_adapter *ad;
1429 int ret, viu_irq;
1430
1431 ret = of_address_to_resource(op->dev.of_node, 0, &r);
1432 if (ret) {
1433 dev_err(&op->dev, "Can't parse device node resource\n");
1434 return -ENODEV;
1435 }
1436
1437 viu_irq = irq_of_parse_and_map(op->dev.of_node, 0);
1438 if (viu_irq == NO_IRQ) {
1439 dev_err(&op->dev, "Error while mapping the irq\n");
1440 return -EINVAL;
1441 }
1442
1443 /* request mem region */
1444 if (!devm_request_mem_region(&op->dev, r.start,
1445 sizeof(struct viu_reg), DRV_NAME)) {
1446 dev_err(&op->dev, "Error while requesting mem region\n");
1447 ret = -EBUSY;
1448 goto err;
1449 }
1450
1451 /* remap registers */
1452 viu_regs = devm_ioremap(&op->dev, r.start, sizeof(struct viu_reg));
1453 if (!viu_regs) {
1454 dev_err(&op->dev, "Can't map register set\n");
1455 ret = -ENOMEM;
1456 goto err;
1457 }
1458
1459 /* Prepare our private structure */
1460 viu_dev = devm_kzalloc(&op->dev, sizeof(struct viu_dev), GFP_ATOMIC);
1461 if (!viu_dev) {
1462 dev_err(&op->dev, "Can't allocate private structure\n");
1463 ret = -ENOMEM;
1464 goto err;
1465 }
1466
1467 viu_dev->vr = viu_regs;
1468 viu_dev->irq = viu_irq;
1469 viu_dev->dev = &op->dev;
1470
1471 /* init video dma queues */
1472 INIT_LIST_HEAD(&viu_dev->vidq.active);
1473 INIT_LIST_HEAD(&viu_dev->vidq.queued);
1474
1475 /* initialize locks */
1476 mutex_init(&viu_dev->lock);
1477
1478 snprintf(viu_dev->v4l2_dev.name,
1479 sizeof(viu_dev->v4l2_dev.name), "%s", "VIU");
1480 ret = v4l2_device_register(viu_dev->dev, &viu_dev->v4l2_dev);
1481 if (ret < 0) {
1482 dev_err(&op->dev, "v4l2_device_register() failed: %d\n", ret);
1483 goto err;
1484 }
1485
1486 ad = i2c_get_adapter(0);
1487 viu_dev->decoder = v4l2_i2c_new_subdev(&viu_dev->v4l2_dev, ad,
1488 "saa7115", "saa7113", VIU_VIDEO_DECODER_ADDR, NULL);
1489
1490 viu_dev->vidq.timeout.function = viu_vid_timeout;
1491 viu_dev->vidq.timeout.data = (unsigned long)viu_dev;
1492 init_timer(&viu_dev->vidq.timeout);
1493 viu_dev->first = 1;
1494
1495 /* Allocate memory for video device */
1496 vdev = video_device_alloc();
1497 if (vdev == NULL) {
1498 ret = -ENOMEM;
1499 goto err_vdev;
1500 }
1501
1502 memcpy(vdev, &viu_template, sizeof(viu_template));
1503
1504 vdev->v4l2_dev = &viu_dev->v4l2_dev;
1505
1506 viu_dev->vdev = vdev;
1507
1508 video_set_drvdata(viu_dev->vdev, viu_dev);
1509
1510 ret = video_register_device(viu_dev->vdev, VFL_TYPE_GRABBER, -1);
1511 if (ret < 0) {
1512 video_device_release(viu_dev->vdev);
1513 goto err_vdev;
1514 }
1515
1516 /* enable VIU clock */
1517 viu_dev->clk = clk_get(&op->dev, "viu_clk");
1518 if (IS_ERR(viu_dev->clk)) {
1519 dev_err(&op->dev, "failed to find the clock module!\n");
1520 ret = -ENODEV;
1521 goto err_clk;
1522 } else {
1523 clk_enable(viu_dev->clk);
1524 }
1525
1526 /* reset VIU module */
1527 viu_reset(viu_dev->vr);
1528
1529 /* install interrupt handler */
1530 if (request_irq(viu_dev->irq, viu_intr, 0, "viu", (void *)viu_dev)) {
1531 dev_err(&op->dev, "Request VIU IRQ failed.\n");
1532 ret = -ENODEV;
1533 goto err_irq;
1534 }
1535
1536 dev_info(&op->dev, "Freescale VIU Video Capture Board\n");
1537 return ret;
1538
1539err_irq:
1540 clk_disable(viu_dev->clk);
1541 clk_put(viu_dev->clk);
1542err_clk:
1543 video_unregister_device(viu_dev->vdev);
1544err_vdev:
1545 i2c_put_adapter(ad);
1546 v4l2_device_unregister(&viu_dev->v4l2_dev);
1547err:
1548 irq_dispose_mapping(viu_irq);
1549 return ret;
1550}
1551
1552static int __devexit viu_of_remove(struct of_device *op)
1553{
1554 struct v4l2_device *v4l2_dev = dev_get_drvdata(&op->dev);
1555 struct viu_dev *dev = container_of(v4l2_dev, struct viu_dev, v4l2_dev);
1556 struct v4l2_subdev *sdev = list_entry(v4l2_dev->subdevs.next,
1557 struct v4l2_subdev, list);
1558 struct i2c_client *client = v4l2_get_subdevdata(sdev);
1559
1560 free_irq(dev->irq, (void *)dev);
1561 irq_dispose_mapping(dev->irq);
1562
1563 clk_disable(dev->clk);
1564 clk_put(dev->clk);
1565
1566 video_unregister_device(dev->vdev);
1567 i2c_put_adapter(client->adapter);
1568 v4l2_device_unregister(&dev->v4l2_dev);
1569 return 0;
1570}
1571
1572#ifdef CONFIG_PM
1573static int viu_suspend(struct of_device *op, pm_message_t state)
1574{
1575 struct v4l2_device *v4l2_dev = dev_get_drvdata(&op->dev);
1576 struct viu_dev *dev = container_of(v4l2_dev, struct viu_dev, v4l2_dev);
1577
1578 clk_disable(dev->clk);
1579 return 0;
1580}
1581
1582static int viu_resume(struct of_device *op)
1583{
1584 struct v4l2_device *v4l2_dev = dev_get_drvdata(&op->dev);
1585 struct viu_dev *dev = container_of(v4l2_dev, struct viu_dev, v4l2_dev);
1586
1587 clk_enable(dev->clk);
1588 return 0;
1589}
1590#endif
1591
1592/*
1593 * Initialization and module stuff
1594 */
1595static struct of_device_id mpc512x_viu_of_match[] = {
1596 {
1597 .compatible = "fsl,mpc5121-viu",
1598 },
1599 {},
1600};
1601MODULE_DEVICE_TABLE(of, mpc512x_viu_of_match);
1602
1603static struct of_platform_driver viu_of_platform_driver = {
1604 .probe = viu_of_probe,
1605 .remove = __devexit_p(viu_of_remove),
1606#ifdef CONFIG_PM
1607 .suspend = viu_suspend,
1608 .resume = viu_resume,
1609#endif
1610 .driver = {
1611 .name = DRV_NAME,
1612 .owner = THIS_MODULE,
1613 .of_match_table = mpc512x_viu_of_match,
1614 },
1615};
1616
1617static int __init viu_init(void)
1618{
1619 return of_register_platform_driver(&viu_of_platform_driver);
1620}
1621
1622static void __exit viu_exit(void)
1623{
1624 of_unregister_platform_driver(&viu_of_platform_driver);
1625}
1626
1627module_init(viu_init);
1628module_exit(viu_exit);
1629
1630MODULE_DESCRIPTION("Freescale Video-In(VIU)");
1631MODULE_AUTHOR("Hongjun Chen");
1632MODULE_LICENSE("GPL");
diff --git a/drivers/media/video/gspca/Kconfig b/drivers/media/video/gspca/Kconfig
index 5d920e584de7..23db0c29f68c 100644
--- a/drivers/media/video/gspca/Kconfig
+++ b/drivers/media/video/gspca/Kconfig
@@ -246,6 +246,15 @@ config USB_GSPCA_SPCA561
246 To compile this driver as a module, choose M here: the 246 To compile this driver as a module, choose M here: the
247 module will be called gspca_spca561. 247 module will be called gspca_spca561.
248 248
249config USB_GSPCA_SPCA1528
250 tristate "SPCA1528 USB Camera Driver"
251 depends on VIDEO_V4L2 && USB_GSPCA
252 help
253 Say Y here if you want support for cameras based on the SPCA1528 chip.
254
255 To compile this driver as a module, choose M here: the
256 module will be called gspca_spca1528.
257
249config USB_GSPCA_SQ905 258config USB_GSPCA_SQ905
250 tristate "SQ Technologies SQ905 based USB Camera Driver" 259 tristate "SQ Technologies SQ905 based USB Camera Driver"
251 depends on VIDEO_V4L2 && USB_GSPCA 260 depends on VIDEO_V4L2 && USB_GSPCA
@@ -264,6 +273,15 @@ config USB_GSPCA_SQ905C
264 To compile this driver as a module, choose M here: the 273 To compile this driver as a module, choose M here: the
265 module will be called gspca_sq905c. 274 module will be called gspca_sq905c.
266 275
276config USB_GSPCA_SQ930X
277 tristate "SQ Technologies SQ930X based USB Camera Driver"
278 depends on VIDEO_V4L2 && USB_GSPCA
279 help
280 Say Y here if you want support for cameras based on the SQ930X chip.
281
282 To compile this driver as a module, choose M here: the
283 module will be called gspca_sq930x.
284
267config USB_GSPCA_STK014 285config USB_GSPCA_STK014
268 tristate "Syntek DV4000 (STK014) USB Camera Driver" 286 tristate "Syntek DV4000 (STK014) USB Camera Driver"
269 depends on VIDEO_V4L2 && USB_GSPCA 287 depends on VIDEO_V4L2 && USB_GSPCA
diff --git a/drivers/media/video/gspca/Makefile b/drivers/media/video/gspca/Makefile
index 6e4cf1ce01c9..f6616db0b7f8 100644
--- a/drivers/media/video/gspca/Makefile
+++ b/drivers/media/video/gspca/Makefile
@@ -23,8 +23,10 @@ obj-$(CONFIG_USB_GSPCA_SPCA505) += gspca_spca505.o
23obj-$(CONFIG_USB_GSPCA_SPCA506) += gspca_spca506.o 23obj-$(CONFIG_USB_GSPCA_SPCA506) += gspca_spca506.o
24obj-$(CONFIG_USB_GSPCA_SPCA508) += gspca_spca508.o 24obj-$(CONFIG_USB_GSPCA_SPCA508) += gspca_spca508.o
25obj-$(CONFIG_USB_GSPCA_SPCA561) += gspca_spca561.o 25obj-$(CONFIG_USB_GSPCA_SPCA561) += gspca_spca561.o
26obj-$(CONFIG_USB_GSPCA_SPCA1528) += gspca_spca1528.o
26obj-$(CONFIG_USB_GSPCA_SQ905) += gspca_sq905.o 27obj-$(CONFIG_USB_GSPCA_SQ905) += gspca_sq905.o
27obj-$(CONFIG_USB_GSPCA_SQ905C) += gspca_sq905c.o 28obj-$(CONFIG_USB_GSPCA_SQ905C) += gspca_sq905c.o
29obj-$(CONFIG_USB_GSPCA_SQ930X) += gspca_sq930x.o
28obj-$(CONFIG_USB_GSPCA_SUNPLUS) += gspca_sunplus.o 30obj-$(CONFIG_USB_GSPCA_SUNPLUS) += gspca_sunplus.o
29obj-$(CONFIG_USB_GSPCA_STK014) += gspca_stk014.o 31obj-$(CONFIG_USB_GSPCA_STK014) += gspca_stk014.o
30obj-$(CONFIG_USB_GSPCA_STV0680) += gspca_stv0680.o 32obj-$(CONFIG_USB_GSPCA_STV0680) += gspca_stv0680.o
@@ -58,8 +60,10 @@ gspca_spca505-objs := spca505.o
58gspca_spca506-objs := spca506.o 60gspca_spca506-objs := spca506.o
59gspca_spca508-objs := spca508.o 61gspca_spca508-objs := spca508.o
60gspca_spca561-objs := spca561.o 62gspca_spca561-objs := spca561.o
63gspca_spca1528-objs := spca1528.o
61gspca_sq905-objs := sq905.o 64gspca_sq905-objs := sq905.o
62gspca_sq905c-objs := sq905c.o 65gspca_sq905c-objs := sq905c.o
66gspca_sq930x-objs := sq930x.o
63gspca_stk014-objs := stk014.o 67gspca_stk014-objs := stk014.o
64gspca_stv0680-objs := stv0680.o 68gspca_stv0680-objs := stv0680.o
65gspca_sunplus-objs := sunplus.o 69gspca_sunplus-objs := sunplus.o
diff --git a/drivers/media/video/gspca/conex.c b/drivers/media/video/gspca/conex.c
index 19fe6b24c9a3..d6a75772f3f8 100644
--- a/drivers/media/video/gspca/conex.c
+++ b/drivers/media/video/gspca/conex.c
@@ -41,7 +41,7 @@ struct sd {
41#define QUALITY_MAX 60 41#define QUALITY_MAX 60
42#define QUALITY_DEF 40 42#define QUALITY_DEF 40
43 43
44 u8 *jpeg_hdr; 44 u8 jpeg_hdr[JPEG_HDR_SZ];
45}; 45};
46 46
47/* V4L2 controls supported by the driver */ 47/* V4L2 controls supported by the driver */
@@ -845,9 +845,6 @@ static int sd_start(struct gspca_dev *gspca_dev)
845 struct sd *sd = (struct sd *) gspca_dev; 845 struct sd *sd = (struct sd *) gspca_dev;
846 846
847 /* create the JPEG header */ 847 /* create the JPEG header */
848 sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL);
849 if (!sd->jpeg_hdr)
850 return -ENOMEM;
851 jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width, 848 jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
852 0x22); /* JPEG 411 */ 849 0x22); /* JPEG 411 */
853 jpeg_set_qual(sd->jpeg_hdr, sd->quality); 850 jpeg_set_qual(sd->jpeg_hdr, sd->quality);
@@ -862,11 +859,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
862/* called on streamoff with alt 0 and on disconnect */ 859/* called on streamoff with alt 0 and on disconnect */
863static void sd_stop0(struct gspca_dev *gspca_dev) 860static void sd_stop0(struct gspca_dev *gspca_dev)
864{ 861{
865 struct sd *sd = (struct sd *) gspca_dev;
866 int retry = 50; 862 int retry = 50;
867 863
868 kfree(sd->jpeg_hdr);
869
870 if (!gspca_dev->present) 864 if (!gspca_dev->present)
871 return; 865 return;
872 reg_w_val(gspca_dev, 0x0000, 0x00); 866 reg_w_val(gspca_dev, 0x0000, 0x00);
diff --git a/drivers/media/video/gspca/cpia1.c b/drivers/media/video/gspca/cpia1.c
index 58b696f455be..3747a1dcff54 100644
--- a/drivers/media/video/gspca/cpia1.c
+++ b/drivers/media/video/gspca/cpia1.c
@@ -1760,22 +1760,19 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
1760 data[25] == sd->params.roi.colEnd && 1760 data[25] == sd->params.roi.colEnd &&
1761 data[26] == sd->params.roi.rowStart && 1761 data[26] == sd->params.roi.rowStart &&
1762 data[27] == sd->params.roi.rowEnd) { 1762 data[27] == sd->params.roi.rowEnd) {
1763 struct gspca_frame *frame = gspca_get_i_frame(gspca_dev); 1763 u8 *image;
1764 1764
1765 atomic_set(&sd->cam_exposure, data[39] * 2); 1765 atomic_set(&sd->cam_exposure, data[39] * 2);
1766 atomic_set(&sd->fps, data[41]); 1766 atomic_set(&sd->fps, data[41]);
1767 1767
1768 if (frame == NULL) {
1769 gspca_dev->last_packet_type = DISCARD_PACKET;
1770 return;
1771 }
1772
1773 /* Check for proper EOF for last frame */ 1768 /* Check for proper EOF for last frame */
1774 if ((frame->data_end - frame->data) > 4 && 1769 image = gspca_dev->image;
1775 frame->data_end[-4] == 0xff && 1770 if (image != NULL &&
1776 frame->data_end[-3] == 0xff && 1771 gspca_dev->image_len > 4 &&
1777 frame->data_end[-2] == 0xff && 1772 image[gspca_dev->image_len - 4] == 0xff &&
1778 frame->data_end[-1] == 0xff) 1773 image[gspca_dev->image_len - 3] == 0xff &&
1774 image[gspca_dev->image_len - 2] == 0xff &&
1775 image[gspca_dev->image_len - 1] == 0xff)
1779 gspca_frame_add(gspca_dev, LAST_PACKET, 1776 gspca_frame_add(gspca_dev, LAST_PACKET,
1780 NULL, 0); 1777 NULL, 0);
1781 1778
diff --git a/drivers/media/video/gspca/gl860/gl860-mi2020.c b/drivers/media/video/gspca/gl860/gl860-mi2020.c
index 7c31b4f2abea..57782e011c9e 100644
--- a/drivers/media/video/gspca/gl860/gl860-mi2020.c
+++ b/drivers/media/video/gspca/gl860/gl860-mi2020.c
@@ -1,6 +1,7 @@
1/* Subdriver for the GL860 chip with the MI2020 sensor 1/* Subdriver for the GL860 chip with the MI2020 sensor
2 * Author Olivier LORIN, from Ice/Soro2005's logs(A), Fret_saw/Hulkie's 2 * Author Olivier LORIN, from logs by Iceman/Soro2005 + Fret_saw/Hulkie/Tricid
3 * logs(B) and Tricid"s logs(C). With the help of Kytrix/BUGabundo/Blazercist. 3 * with the help of Kytrix/BUGabundo/Blazercist.
4 * Driver achieved thanks to a webcam gift by Kytrix.
4 * 5 *
5 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
@@ -20,47 +21,70 @@
20 21
21#include "gl860.h" 22#include "gl860.h"
22 23
24static u8 dat_wbal1[] = {0x8c, 0xa2, 0x0c};
25
23static u8 dat_bright1[] = {0x8c, 0xa2, 0x06}; 26static u8 dat_bright1[] = {0x8c, 0xa2, 0x06};
24static u8 dat_bright3[] = {0x8c, 0xa1, 0x02}; 27static u8 dat_bright3[] = {0x8c, 0xa1, 0x02};
25static u8 dat_bright4[] = {0x90, 0x00, 0x0f}; 28static u8 dat_bright4[] = {0x90, 0x00, 0x0f};
26static u8 dat_bright5[] = {0x8c, 0xa1, 0x03}; 29static u8 dat_bright5[] = {0x8c, 0xa1, 0x03};
27static u8 dat_bright6[] = {0x90, 0x00, 0x05}; 30static u8 dat_bright6[] = {0x90, 0x00, 0x05};
28 31
29static u8 dat_dummy1[] = {0x90, 0x00, 0x06};
30/*static u8 dummy2[] = {0x8c, 0xa1, 0x02};*/
31/*static u8 dummy3[] = {0x90, 0x00, 0x1f};*/
32
33static u8 dat_hvflip1[] = {0x8c, 0x27, 0x19}; 32static u8 dat_hvflip1[] = {0x8c, 0x27, 0x19};
34static u8 dat_hvflip3[] = {0x8c, 0x27, 0x3b}; 33static u8 dat_hvflip3[] = {0x8c, 0x27, 0x3b};
35static u8 dat_hvflip5[] = {0x8c, 0xa1, 0x03}; 34static u8 dat_hvflip5[] = {0x8c, 0xa1, 0x03};
36static u8 dat_hvflip6[] = {0x90, 0x00, 0x06}; 35static u8 dat_hvflip6[] = {0x90, 0x00, 0x06};
37 36
37static struct idxdata tbl_middle_hvflip_low[] = {
38 {0x33, "\x90\x00\x06"},
39 {6, "\xff\xff\xff"},
40 {0x33, "\x90\x00\x06"},
41 {6, "\xff\xff\xff"},
42 {0x33, "\x90\x00\x06"},
43 {6, "\xff\xff\xff"},
44 {0x33, "\x90\x00\x06"},
45 {6, "\xff\xff\xff"},
46};
47
48static struct idxdata tbl_middle_hvflip_big[] = {
49 {0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x01"}, {0x33, "\x8c\xa1\x20"},
50 {0x33, "\x90\x00\x00"}, {0x33, "\x8c\xa7\x02"}, {0x33, "\x90\x00\x00"},
51 {102, "\xff\xff\xff"},
52 {0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x02"}, {0x33, "\x8c\xa1\x20"},
53 {0x33, "\x90\x00\x72"}, {0x33, "\x8c\xa7\x02"}, {0x33, "\x90\x00\x01"},
54};
55
56static struct idxdata tbl_end_hvflip[] = {
57 {0x33, "\x8c\xa1\x02"}, {0x33, "\x90\x00\x1f"},
58 {6, "\xff\xff\xff"},
59 {0x33, "\x8c\xa1\x02"}, {0x33, "\x90\x00\x1f"},
60 {6, "\xff\xff\xff"},
61 {0x33, "\x8c\xa1\x02"}, {0x33, "\x90\x00\x1f"},
62 {6, "\xff\xff\xff"},
63 {0x33, "\x8c\xa1\x02"}, {0x33, "\x90\x00\x1f"},
64};
65
38static u8 dat_freq1[] = { 0x8c, 0xa4, 0x04 }; 66static u8 dat_freq1[] = { 0x8c, 0xa4, 0x04 };
39 67
40static u8 dat_multi5[] = { 0x8c, 0xa1, 0x03 }; 68static u8 dat_multi5[] = { 0x8c, 0xa1, 0x03 };
41static u8 dat_multi6[] = { 0x90, 0x00, 0x05 }; 69static u8 dat_multi6[] = { 0x90, 0x00, 0x05 };
42 70
43static struct validx tbl_common1[] = { 71static struct validx tbl_init_at_startup[] = {
44 {0x0000, 0x0000}, 72 {0x0000, 0x0000}, {0x0010, 0x0010}, {0x0008, 0x00c0}, {0x0001,0x00c1},
45 {1, 0xffff}, /* msleep(35); */ 73 {0x0001, 0x00c2}, {0x0020, 0x0006}, {0x006a, 0x000d},
46 {0x006a, 0x0007}, {0x0063, 0x0006}, {0x006a, 0x000d}, {0x0000, 0x00c0}, 74 {53, 0xffff},
47 {0x0010, 0x0010}, {0x0003, 0x00c1}, {0x0042, 0x00c2}, {0x0004, 0x00d8}, 75 {0x0040, 0x0000}, {0x0063, 0x0006},
48 {0x0000, 0x0058}, {0x0002, 0x0004}, {0x0041, 0x0000},
49}; 76};
50 77
51static struct validx tbl_common2[] = { 78static struct validx tbl_common_0B[] = {
52 {0x006a, 0x0007}, 79 {0x0002, 0x0004}, {0x006a, 0x0007}, {0x00ef, 0x0006}, {0x006a,0x000d},
53 {35, 0xffff}, 80 {0x0000, 0x00c0}, {0x0010, 0x0010}, {0x0003, 0x00c1}, {0x0042,0x00c2},
54 {0x00ef, 0x0006},
55 {35, 0xffff},
56 {0x006a, 0x000d},
57 {35, 0xffff},
58 {0x0000, 0x00c0}, {0x0010, 0x0010}, {0x0003, 0x00c1}, {0x0042, 0x00c2},
59 {0x0004, 0x00d8}, {0x0000, 0x0058}, {0x0041, 0x0000}, 81 {0x0004, 0x00d8}, {0x0000, 0x0058}, {0x0041, 0x0000},
60}; 82};
61 83
62static struct idxdata tbl_common3[] = { 84static struct idxdata tbl_common_3B[] = {
63 {0x32, "\x02\x00\x08"}, {0x33, "\xf4\x03\x1d"}, 85 {0x33, "\x86\x25\x01"}, {0x33, "\x86\x25\x00"},
86 {2, "\xff\xff\xff"},
87 {0x30, "\x1a\x0a\xcc"}, {0x32, "\x02\x00\x08"}, {0x33, "\xf4\x03\x1d"},
64 {6, "\xff\xff\xff"}, /* 12 */ 88 {6, "\xff\xff\xff"}, /* 12 */
65 {0x34, "\x1e\x8f\x09"}, {0x34, "\x1c\x01\x28"}, {0x34, "\x1e\x8f\x09"}, 89 {0x34, "\x1e\x8f\x09"}, {0x34, "\x1c\x01\x28"}, {0x34, "\x1e\x8f\x09"},
66 {2, "\xff\xff\xff"}, /* - */ 90 {2, "\xff\xff\xff"}, /* - */
@@ -98,85 +122,58 @@ static struct idxdata tbl_common3[] = {
98 {0x35, "\x50\x00\x06"}, {0x35, "\x48\x07\xff"}, {0x35, "\x60\x05\x89"}, 122 {0x35, "\x50\x00\x06"}, {0x35, "\x48\x07\xff"}, {0x35, "\x60\x05\x89"},
99 {0x35, "\x58\x07\xff"}, {0x35, "\x40\x00\xa0"}, {0x35, "\x42\x00\x00"}, 123 {0x35, "\x58\x07\xff"}, {0x35, "\x40\x00\xa0"}, {0x35, "\x42\x00\x00"},
100 {0x32, "\x10\x01\xfc"}, {0x33, "\x8c\xa1\x18"}, {0x33, "\x90\x00\x3c"}, 124 {0x32, "\x10\x01\xfc"}, {0x33, "\x8c\xa1\x18"}, {0x33, "\x90\x00\x3c"},
101 {1, "\xff\xff\xff"},
102 {0x33, "\x78\x00\x00"}, 125 {0x33, "\x78\x00\x00"},
103 {1, "\xff\xff\xff"}, 126 {2, "\xff\xff\xff"},
104 {0x35, "\xb8\x1f\x20"}, {0x33, "\x8c\xa2\x06"}, {0x33, "\x90\x00\x10"}, 127 {0x35, "\xb8\x1f\x20"}, {0x33, "\x8c\xa2\x06"}, {0x33, "\x90\x00\x10"},
105 {0x33, "\x8c\xa2\x07"}, {0x33, "\x90\x00\x08"}, {0x33, "\x8c\xa2\x42"}, 128 {0x33, "\x8c\xa2\x07"}, {0x33, "\x90\x00\x08"}, {0x33, "\x8c\xa2\x42"},
106 {0x33, "\x90\x00\x0b"}, {0x33, "\x8c\xa2\x4a"}, {0x33, "\x90\x00\x8c"}, 129 {0x33, "\x90\x00\x0b"}, {0x33, "\x8c\xa2\x4a"}, {0x33, "\x90\x00\x8c"},
107 {0x35, "\xba\xfa\x08"}, {0x33, "\x8c\xa2\x02"}, {0x33, "\x90\x00\x22"}, 130 {0x35, "\xba\xfa\x08"}, {0x33, "\x8c\xa2\x02"}, {0x33, "\x90\x00\x22"},
108 {0x33, "\x8c\xa2\x03"}, {0x33, "\x90\x00\xbb"}, 131 {0x33, "\x8c\xa2\x03"}, {0x33, "\x90\x00\xbb"}, {0x33, "\x8c\xa4\x04"},
109}; 132 {0x33, "\x90\x00\x80"}, {0x33, "\x8c\xa7\x9d"}, {0x33, "\x90\x00\x00"},
110 133 {0x33, "\x8c\xa7\x9e"}, {0x33, "\x90\x00\x00"}, {0x33, "\x8c\xa2\x0c"},
111static struct idxdata tbl_common4[] = { 134 {0x33, "\x90\x00\x17"}, {0x33, "\x8c\xa2\x15"}, {0x33, "\x90\x00\x04"},
112 {0x33, "\x8c\x22\x2e"}, {0x33, "\x90\x00\xa0"}, {0x33, "\x8c\xa4\x08"}, 135 {0x33, "\x8c\xa2\x14"}, {0x33, "\x90\x00\x20"}, {0x33, "\x8c\xa1\x03"},
136 {0x33, "\x90\x00\x00"}, {0x33, "\x8c\x27\x17"}, {0x33, "\x90\x21\x11"},
137 {0x33, "\x8c\x27\x1b"}, {0x33, "\x90\x02\x4f"}, {0x33, "\x8c\x27\x25"},
138 {0x33, "\x90\x06\x0f"}, {0x33, "\x8c\x27\x39"}, {0x33, "\x90\x21\x11"},
139 {0x33, "\x8c\x27\x3d"}, {0x33, "\x90\x01\x20"}, {0x33, "\x8c\x27\x47"},
140 {0x33, "\x90\x09\x4c"}, {0x33, "\x8c\x27\x03"}, {0x33, "\x90\x02\x84"},
141 {0x33, "\x8c\x27\x05"}, {0x33, "\x90\x01\xe2"}, {0x33, "\x8c\x27\x07"},
142 {0x33, "\x90\x06\x40"}, {0x33, "\x8c\x27\x09"}, {0x33, "\x90\x04\xb0"},
143 {0x33, "\x8c\x27\x0d"}, {0x33, "\x90\x00\x00"}, {0x33, "\x8c\x27\x0f"},
144 {0x33, "\x90\x00\x00"}, {0x33, "\x8c\x27\x11"}, {0x33, "\x90\x04\xbd"},
145 {0x33, "\x8c\x27\x13"}, {0x33, "\x90\x06\x4d"}, {0x33, "\x8c\x27\x15"},
146 {0x33, "\x90\x00\x00"}, {0x33, "\x8c\x27\x17"}, {0x33, "\x90\x21\x11"},
147 {0x33, "\x8c\x27\x19"}, {0x33, "\x90\x04\x6c"}, {0x33, "\x8c\x27\x1b"},
148 {0x33, "\x90\x02\x4f"}, {0x33, "\x8c\x27\x1d"}, {0x33, "\x90\x01\x02"},
149 {0x33, "\x8c\x27\x1f"}, {0x33, "\x90\x02\x79"}, {0x33, "\x8c\x27\x21"},
150 {0x33, "\x90\x01\x55"}, {0x33, "\x8c\x27\x23"}, {0x33, "\x90\x02\x85"},
151 {0x33, "\x8c\x27\x25"}, {0x33, "\x90\x06\x0f"}, {0x33, "\x8c\x27\x27"},
152 {0x33, "\x90\x20\x20"}, {0x33, "\x8c\x27\x29"}, {0x33, "\x90\x20\x20"},
153 {0x33, "\x8c\x27\x2b"}, {0x33, "\x90\x10\x20"}, {0x33, "\x8c\x27\x2d"},
154 {0x33, "\x90\x20\x07"}, {0x33, "\x8c\x27\x2f"}, {0x33, "\x90\x00\x04"},
155 {0x33, "\x8c\x27\x31"}, {0x33, "\x90\x00\x04"}, {0x33, "\x8c\x27\x33"},
156 {0x33, "\x90\x04\xbb"}, {0x33, "\x8c\x27\x35"}, {0x33, "\x90\x06\x4b"},
157 {0x33, "\x8c\x27\x37"}, {0x33, "\x90\x00\x00"}, {0x33, "\x8c\x27\x39"},
158 {0x33, "\x90\x21\x11"}, {0x33, "\x8c\x27\x3b"}, {0x33, "\x90\x00\x24"},
159 {0x33, "\x8c\x27\x3d"}, {0x33, "\x90\x01\x20"}, {0x33, "\x8c\x27\x41"},
160 {0x33, "\x90\x01\x69"}, {0x33, "\x8c\x27\x45"}, {0x33, "\x90\x04\xed"},
161 {0x33, "\x8c\x27\x47"}, {0x33, "\x90\x09\x4c"}, {0x33, "\x8c\x27\x51"},
162 {0x33, "\x90\x00\x00"}, {0x33, "\x8c\x27\x53"}, {0x33, "\x90\x03\x20"},
163 {0x33, "\x8c\x27\x55"}, {0x33, "\x90\x00\x00"}, {0x33, "\x8c\x27\x57"},
164 {0x33, "\x90\x02\x58"}, {0x33, "\x8c\x27\x5f"}, {0x33, "\x90\x00\x00"},
165 {0x33, "\x8c\x27\x61"}, {0x33, "\x90\x06\x40"}, {0x33, "\x8c\x27\x63"},
166 {0x33, "\x90\x00\x00"}, {0x33, "\x8c\x27\x65"}, {0x33, "\x90\x04\xb0"},
167 {0x33, "\x8c\x22\x2e"}, {0x33, "\x90\x00\xa1"}, {0x33, "\x8c\xa4\x08"},
113 {0x33, "\x90\x00\x1f"}, {0x33, "\x8c\xa4\x09"}, {0x33, "\x90\x00\x21"}, 168 {0x33, "\x90\x00\x1f"}, {0x33, "\x8c\xa4\x09"}, {0x33, "\x90\x00\x21"},
114 {0x33, "\x8c\xa4\x0a"}, {0x33, "\x90\x00\x25"}, {0x33, "\x8c\xa4\x0b"}, 169 {0x33, "\x8c\xa4\x0a"}, {0x33, "\x90\x00\x25"}, {0x33, "\x8c\xa4\x0b"},
115 {0x33, "\x90\x00\x27"}, {0x33, "\x8c\x24\x11"}, {0x33, "\x90\x00\xa0"}, 170 {0x33, "\x90\x00\x27"}, {0x33, "\x8c\x24\x11"}, {0x33, "\x90\x00\xa1"},
116 {0x33, "\x8c\x24\x13"}, {0x33, "\x90\x00\xc0"}, {0x33, "\x8c\x24\x15"}, 171 {0x33, "\x8c\x24\x13"}, {0x33, "\x90\x00\xc1"}, {0x33, "\x8c\x24\x15"},
117 {0x33, "\x90\x00\xa0"}, {0x33, "\x8c\x24\x17"}, {0x33, "\x90\x00\xc0"}, 172 {0x33, "\x90\x00\x6a"}, {0x33, "\x8c\x24\x17"}, {0x33, "\x90\x00\x80"},
118}; 173 {0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x05"},
119 174 {2, "\xff\xff\xff"},
120static struct idxdata tbl_common5[] = { 175 {0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x06"},
121 {0x33, "\x8c\xa4\x04"}, {0x33, "\x90\x00\x80"}, {0x33, "\x8c\xa7\x9d"}, 176 {3, "\xff\xff\xff"},
122 {0x33, "\x90\x00\x00"}, {0x33, "\x8c\xa7\x9e"}, {0x33, "\x90\x00\x00"},
123 {0x33, "\x8c\xa2\x0c"}, {0x33, "\x90\x00\x17"}, {0x33, "\x8c\xa2\x15"},
124 {0x33, "\x90\x00\x04"}, {0x33, "\x8c\xa2\x14"}, {0x33, "\x90\x00\x20"},
125 {0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x00"}, {0x33, "\x8c\x27\x17"},
126 /* msleep(53); */
127 {0x33, "\x90\x21\x11"}, {0x33, "\x8c\x27\x1b"}, {0x33, "\x90\x02\x4f"},
128 {0x33, "\x8c\x27\x25"}, {0x33, "\x90\x06\x0f"}, {0x33, "\x8c\x27\x39"},
129 {0x33, "\x90\x21\x11"}, {0x33, "\x8c\x27\x3d"}, {0x33, "\x90\x01\x20"},
130 {0x33, "\x8c\x27\x47"}, {0x33, "\x90\x09\x4c"}, {0x33, "\x8c\x27\x03"},
131 {0x33, "\x90\x02\x84"}, {0x33, "\x8c\x27\x05"}, {0x33, "\x90\x01\xe2"},
132 {0x33, "\x8c\x27\x07"}, {0x33, "\x90\x06\x40"}, {0x33, "\x8c\x27\x09"},
133 {0x33, "\x90\x04\xb0"}, {0x33, "\x8c\x27\x0d"}, {0x33, "\x90\x00\x00"},
134 {0x33, "\x8c\x27\x0f"}, {0x33, "\x90\x00\x00"}, {0x33, "\x8c\x27\x11"},
135 {0x33, "\x90\x04\xbd"}, {0x33, "\x8c\x27\x13"}, {0x33, "\x90\x06\x4d"},
136 {0x33, "\x8c\x27\x15"}, {0x33, "\x90\x00\x00"}, {0x33, "\x8c\x27\x17"},
137 {0x33, "\x90\x21\x11"}, {0x33, "\x8c\x27\x19"}, {0x33, "\x90\x04\x6c"},
138 {0x33, "\x8c\x27\x1b"}, {0x33, "\x90\x02\x4f"}, {0x33, "\x8c\x27\x1d"},
139 {0x33, "\x90\x01\x02"}, {0x33, "\x8c\x27\x1f"}, {0x33, "\x90\x02\x79"},
140 {0x33, "\x8c\x27\x21"}, {0x33, "\x90\x01\x55"}, {0x33, "\x8c\x27\x23"},
141 {0x33, "\x90\x02\x85"}, {0x33, "\x8c\x27\x25"}, {0x33, "\x90\x06\x0f"},
142 {0x33, "\x8c\x27\x27"}, {0x33, "\x90\x20\x20"}, {0x33, "\x8c\x27\x29"},
143 {0x33, "\x90\x20\x20"}, {0x33, "\x8c\x27\x2b"}, {0x33, "\x90\x10\x20"},
144 {0x33, "\x8c\x27\x2d"}, {0x33, "\x90\x20\x07"}, {0x33, "\x8c\x27\x2f"},
145 {0x33, "\x90\x00\x04"}, {0x33, "\x8c\x27\x31"}, {0x33, "\x90\x00\x04"},
146 {0x33, "\x8c\x27\x33"}, {0x33, "\x90\x04\xbb"}, {0x33, "\x8c\x27\x35"},
147 {0x33, "\x90\x06\x4b"}, {0x33, "\x8c\x27\x37"}, {0x33, "\x90\x00\x00"},
148 {0x33, "\x8c\x27\x39"}, {0x33, "\x90\x21\x11"}, {0x33, "\x8c\x27\x3b"},
149 {0x33, "\x90\x00\x24"}, {0x33, "\x8c\x27\x3d"}, {0x33, "\x90\x01\x20"},
150 {0x33, "\x8c\x27\x41"}, {0x33, "\x90\x01\x69"}, {0x33, "\x8c\x27\x45"},
151 {0x33, "\x90\x04\xed"}, {0x33, "\x8c\x27\x47"}, {0x33, "\x90\x09\x4c"},
152 {0x33, "\x8c\x27\x51"}, {0x33, "\x90\x00\x00"}, {0x33, "\x8c\x27\x53"},
153 {0x33, "\x90\x03\x20"}, {0x33, "\x8c\x27\x55"}, {0x33, "\x90\x00\x00"},
154 {0x33, "\x8c\x27\x57"}, {0x33, "\x90\x02\x58"}, {0x33, "\x8c\x27\x5f"},
155 {0x33, "\x90\x00\x00"}, {0x33, "\x8c\x27\x61"}, {0x33, "\x90\x06\x40"},
156 {0x33, "\x8c\x27\x63"}, {0x33, "\x90\x00\x00"}, {0x33, "\x8c\x27\x65"},
157 {0x33, "\x90\x04\xb0"}, {0x33, "\x8c\x22\x2e"}, {0x33, "\x90\x00\xa1"},
158 {0x33, "\x8c\xa4\x08"}, {0x33, "\x90\x00\x1f"}, {0x33, "\x8c\xa4\x09"},
159 {0x33, "\x90\x00\x21"}, {0x33, "\x8c\xa4\x0a"}, {0x33, "\x90\x00\x25"},
160 {0x33, "\x8c\xa4\x0b"}, {0x33, "\x90\x00\x27"}, {0x33, "\x8c\x24\x11"},
161 {0x33, "\x90\x00\xa1"}, {0x33, "\x8c\x24\x13"}, {0x33, "\x90\x00\xc1"},
162 {0x33, "\x8c\x24\x15"},
163};
164
165static struct validx tbl_init_at_startup[] = {
166 {0x0000, 0x0000},
167 {53, 0xffff},
168 {0x0010, 0x0010},
169 {53, 0xffff},
170 {0x0008, 0x00c0},
171 {53, 0xffff},
172 {0x0001, 0x00c1},
173 {53, 0xffff},
174 {0x0001, 0x00c2},
175 {53, 0xffff},
176 {0x0020, 0x0006},
177 {53, 0xffff},
178 {0x006a, 0x000d},
179 {53, 0xffff},
180}; 177};
181 178
182static struct idxdata tbl_init_post_alt_low1[] = { 179static struct idxdata tbl_init_post_alt_low1[] = {
@@ -209,7 +206,7 @@ static struct idxdata tbl_init_post_alt_low3[] = {
209 {2, "\xff\xff\xff"}, 206 {2, "\xff\xff\xff"},
210 {0x33, "\x8c\xa1\x20"}, {0x33, "\x90\x00\x00"}, {0x33, "\x8c\xa1\x03"}, 207 {0x33, "\x8c\xa1\x20"}, {0x33, "\x90\x00\x00"}, {0x33, "\x8c\xa1\x03"},
211 {0x33, "\x90\x00\x01"}, {0x33, "\x8c\xa7\x02"}, {0x33, "\x90\x00\x00"}, 208 {0x33, "\x90\x00\x01"}, {0x33, "\x8c\xa7\x02"}, {0x33, "\x90\x00\x00"},
212 {2, "\xff\xff\xff"}, /* - * */ 209 {2, "\xff\xff\xff"},
213 {0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x05"}, 210 {0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x05"},
214 {2, "\xff\xff\xff"}, 211 {2, "\xff\xff\xff"},
215 {0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x06"}, 212 {0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x06"},
@@ -217,61 +214,15 @@ static struct idxdata tbl_init_post_alt_low3[] = {
217 {0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x05"}, 214 {0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x05"},
218 {2, "\xff\xff\xff"}, 215 {2, "\xff\xff\xff"},
219 {0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x06"}, 216 {0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x06"},
220 {1, "\xff\xff\xff"},
221};
222
223static struct idxdata tbl_init_post_alt_low4[] = {
224 {0x32, "\x10\x01\xf8"}, {0x34, "\xce\x01\xa8"}, {0x34, "\xd0\x66\x33"},
225 {0x34, "\xd2\x31\x9a"}, {0x34, "\xd4\x94\x63"}, {0x34, "\xd6\x4b\x25"},
226 {0x34, "\xd8\x26\x70"}, {0x34, "\xda\x72\x4c"}, {0x34, "\xdc\xff\x04"},
227 {0x34, "\xde\x01\x5b"}, {0x34, "\xe6\x01\x13"}, {0x34, "\xee\x0b\xf0"},
228 {0x34, "\xf6\x0b\xa4"}, {0x35, "\x00\xf6\xe7"}, {0x35, "\x08\x0d\xfd"},
229 {0x35, "\x10\x25\x63"}, {0x35, "\x18\x35\x6c"}, {0x35, "\x20\x42\x7e"},
230 {0x35, "\x28\x19\x44"}, {0x35, "\x30\x39\xd4"}, {0x35, "\x38\xf5\xa8"},
231 {0x35, "\x4c\x07\x90"}, {0x35, "\x44\x07\xb8"}, {0x35, "\x5c\x06\x88"},
232 {0x35, "\x54\x07\xff"}, {0x34, "\xe0\x01\x52"}, {0x34, "\xe8\x00\xcc"},
233 {0x34, "\xf0\x0d\x83"}, {0x34, "\xf8\x0c\xb3"}, {0x35, "\x02\xfe\xba"},
234 {0x35, "\x0a\x04\xe0"}, {0x35, "\x12\x1c\x63"}, {0x35, "\x1a\x2b\x5a"},
235 {0x35, "\x22\x32\x5e"}, {0x35, "\x2a\x0d\x28"}, {0x35, "\x32\x2c\x02"},
236 {0x35, "\x3a\xf4\xfa"}, {0x35, "\x4e\x07\xef"}, {0x35, "\x46\x07\x88"},
237 {0x35, "\x5e\x07\xc1"}, {0x35, "\x56\x04\x64"}, {0x34, "\xe4\x01\x15"},
238 {0x34, "\xec\x00\x82"}, {0x34, "\xf4\x0c\xce"}, {0x34, "\xfc\x0c\xba"},
239 {0x35, "\x06\x1f\x02"}, {0x35, "\x0e\x02\xe3"}, {0x35, "\x16\x1a\x50"},
240 {0x35, "\x1e\x24\x39"}, {0x35, "\x26\x23\x4c"}, {0x35, "\x2e\xf9\x1b"},
241 {0x35, "\x36\x23\x19"}, {0x35, "\x3e\x12\x08"}, {0x35, "\x52\x07\x22"},
242 {0x35, "\x4a\x03\xd3"}, {0x35, "\x62\x06\x54"}, {0x35, "\x5a\x04\x5d"},
243 {0x34, "\xe2\x01\x04"}, {0x34, "\xea\x00\xa0"}, {0x34, "\xf2\x0c\xbc"},
244 {0x34, "\xfa\x0c\x5b"}, {0x35, "\x04\x17\xf2"}, {0x35, "\x0c\x02\x08"},
245 {0x35, "\x14\x28\x43"}, {0x35, "\x1c\x28\x62"}, {0x35, "\x24\x2b\x60"},
246 {0x35, "\x2c\x07\x33"}, {0x35, "\x34\x1f\xb0"}, {0x35, "\x3c\xed\xcd"},
247 {0x35, "\x50\x00\x06"}, {0x35, "\x48\x07\xff"}, {0x35, "\x60\x05\x89"},
248 {0x35, "\x58\x07\xff"}, {0x35, "\x40\x00\xa0"}, {0x35, "\x42\x00\x00"},
249 {0x32, "\x10\x01\xfc"}, {0x33, "\x8c\xa1\x18"},
250 /* Flip/Mirror h/v=1 */
251 {0x33, "\x90\x00\x3c"}, {0x33, "\x8c\x27\x19"}, {0x33, "\x90\x04\x6c"},
252 {0x33, "\x8c\x27\x3b"}, {0x33, "\x90\x00\x24"}, {0x33, "\x8c\xa1\x03"},
253 {0x33, "\x90\x00\x06"},
254 {130, "\xff\xff\xff"},
255 {0x33, "\x90\x00\x06"}, {0x33, "\x90\x00\x06"}, {0x33, "\x90\x00\x06"},
256 {0x33, "\x90\x00\x06"}, {0x33, "\x90\x00\x06"}, {0x33, "\x90\x00\x06"},
257 {100, "\xff\xff\xff"},
258 /* ?? */
259 {0x33, "\x8c\xa1\x02"}, {0x33, "\x90\x00\x1f"}, {0x33, "\x8c\xa1\x02"},
260 {0x33, "\x90\x00\x1f"}, {0x33, "\x8c\xa1\x02"}, {0x33, "\x90\x00\x1f"},
261 {0x33, "\x8c\xa1\x02"}, {0x33, "\x90\x00\x1f"},
262 /* Brigthness=70 */
263 {0x33, "\x8c\xa2\x06"}, {0x33, "\x90\x00\x46"}, {0x33, "\x8c\xa1\x02"},
264 {0x33, "\x90\x00\x0f"}, {0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x05"},
265 /* Sharpness=20 */
266 {0x32, "\x6c\x14\x08"},
267}; 217};
268 218
269static struct idxdata tbl_init_post_alt_big1[] = { 219static struct idxdata tbl_init_post_alt_big[] = {
270 {0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x05"}, 220 {0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x05"},
271 {2, "\xff\xff\xff"}, 221 {2, "\xff\xff\xff"},
272 {0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x06"}, 222 {0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x06"},
273 {2, "\xff\xff\xff"}, 223 {2, "\xff\xff\xff"},
274 {0x34, "\x1e\x8f\x09"}, {0x34, "\x1c\x01\x28"}, {0x34, "\x1e\x8f\x09"}, 224 {0x34, "\x1e\x8f\x09"}, {0x34, "\x1c\x01\x28"}, {0x34, "\x1e\x8f\x09"},
225 {2, "\xff\xff\xff"},
275 {0x34, "\x1e\x8f\x09"}, {0x32, "\x14\x06\xe6"}, {0x33, "\x8c\xa1\x03"}, 226 {0x34, "\x1e\x8f\x09"}, {0x32, "\x14\x06\xe6"}, {0x33, "\x8c\xa1\x03"},
276 {0x33, "\x90\x00\x05"}, 227 {0x33, "\x90\x00\x05"},
277 {2, "\xff\xff\xff"}, 228 {2, "\xff\xff\xff"},
@@ -285,9 +236,17 @@ static struct idxdata tbl_init_post_alt_big1[] = {
285 {0x33, "\x90\x00\x03"}, {0x33, "\x8c\xa1\x34"}, {0x33, "\x90\x00\x03"}, 236 {0x33, "\x90\x00\x03"}, {0x33, "\x8c\xa1\x34"}, {0x33, "\x90\x00\x03"},
286 {0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x02"}, {0x33, "\x2e\x01\x00"}, 237 {0x33, "\x8c\xa1\x03"}, {0x33, "\x90\x00\x02"}, {0x33, "\x2e\x01\x00"},
287 {0x34, "\x04\x00\x2a"}, {0x33, "\x8c\xa7\x02"}, {0x33, "\x90\x00\x01"}, 238 {0x34, "\x04\x00\x2a"}, {0x33, "\x8c\xa7\x02"}, {0x33, "\x90\x00\x01"},
239 {0x33, "\x8c\x27\x97"}, {0x33, "\x90\x01\x00"},
240 {51, "\xff\xff\xff"},
241 {0x33, "\x8c\xa1\x20"}, {0x33, "\x90\x00\x00"}, {0x33, "\x8c\xa1\x03"},
242 {0x33, "\x90\x00\x01"}, {0x33, "\x8c\xa7\x02"}, {0x33, "\x90\x00\x00"},
243 {51, "\xff\xff\xff"},
244 {0x33, "\x8c\xa1\x20"}, {0x33, "\x90\x00\x72"}, {0x33, "\x8c\xa1\x03"},
245 {0x33, "\x90\x00\x02"}, {0x33, "\x8c\xa7\x02"}, {0x33, "\x90\x00\x01"},
246 {51, "\xff\xff\xff"},
288}; 247};
289 248
290static struct idxdata tbl_init_post_alt_big2[] = { 249static struct idxdata tbl_init_post_alt_3B[] = {
291 {0x32, "\x10\x01\xf8"}, {0x34, "\xce\x01\xa8"}, {0x34, "\xd0\x66\x33"}, 250 {0x32, "\x10\x01\xf8"}, {0x34, "\xce\x01\xa8"}, {0x34, "\xd0\x66\x33"},
292 {0x34, "\xd2\x31\x9a"}, {0x34, "\xd4\x94\x63"}, {0x34, "\xd6\x4b\x25"}, 251 {0x34, "\xd2\x31\x9a"}, {0x34, "\xd4\x94\x63"}, {0x34, "\xd6\x4b\x25"},
293 {0x34, "\xd8\x26\x70"}, {0x34, "\xda\x72\x4c"}, {0x34, "\xdc\xff\x04"}, 252 {0x34, "\xd8\x26\x70"}, {0x34, "\xda\x72\x4c"}, {0x34, "\xdc\xff\x04"},
@@ -316,17 +275,6 @@ static struct idxdata tbl_init_post_alt_big2[] = {
316 {0x32, "\x10\x01\xfc"}, {0x33, "\x8c\xa1\x18"}, {0x33, "\x90\x00\x3c"}, 275 {0x32, "\x10\x01\xfc"}, {0x33, "\x8c\xa1\x18"}, {0x33, "\x90\x00\x3c"},
317}; 276};
318 277
319static struct idxdata tbl_init_post_alt_big3[] = {
320 {0x33, "\x8c\xa1\x02"},
321 {0x33, "\x90\x00\x1f"},
322 {0x33, "\x8c\xa1\x02"},
323 {0x33, "\x90\x00\x1f"},
324 {0x33, "\x8c\xa1\x02"},
325 {0x33, "\x90\x00\x1f"},
326 {0x33, "\x8c\xa1\x02"},
327 {0x33, "\x90\x00\x1f"},
328};
329
330static u8 *dat_640 = "\xd0\x02\xd1\x08\xd2\xe1\xd3\x02\xd4\x10\xd5\x81"; 278static u8 *dat_640 = "\xd0\x02\xd1\x08\xd2\xe1\xd3\x02\xd4\x10\xd5\x81";
331static u8 *dat_800 = "\xd0\x02\xd1\x10\xd2\x57\xd3\x02\xd4\x18\xd5\x21"; 279static u8 *dat_800 = "\xd0\x02\xd1\x10\xd2\x57\xd3\x02\xd4\x18\xd5\x21";
332static u8 *dat_1280 = "\xd0\x02\xd1\x20\xd2\x01\xd3\x02\xd4\x28\xd5\x01"; 280static u8 *dat_1280 = "\xd0\x02\xd1\x20\xd2\x01\xd3\x02\xd4\x28\xd5\x01";
@@ -351,7 +299,7 @@ void mi2020_init_settings(struct gspca_dev *gspca_dev)
351 sd->vcur.gamma = 0; 299 sd->vcur.gamma = 0;
352 sd->vcur.hue = 0; 300 sd->vcur.hue = 0;
353 sd->vcur.saturation = 60; 301 sd->vcur.saturation = 60;
354 sd->vcur.whitebal = 50; 302 sd->vcur.whitebal = 0; /* 50, not done by hardware */
355 sd->vcur.mirror = 0; 303 sd->vcur.mirror = 0;
356 sd->vcur.flip = 0; 304 sd->vcur.flip = 0;
357 sd->vcur.AC50Hz = 1; 305 sd->vcur.AC50Hz = 1;
@@ -361,17 +309,12 @@ void mi2020_init_settings(struct gspca_dev *gspca_dev)
361 sd->vmax.sharpness = 40; 309 sd->vmax.sharpness = 40;
362 sd->vmax.contrast = 3; 310 sd->vmax.contrast = 3;
363 sd->vmax.gamma = 2; 311 sd->vmax.gamma = 2;
364 sd->vmax.hue = 0 + 1; /* 200 */ 312 sd->vmax.hue = 0 + 1; /* 200, not done by hardware */
365 sd->vmax.saturation = 0; /* 100 */ 313 sd->vmax.saturation = 0; /* 100, not done by hardware */
366 sd->vmax.whitebal = 0; /* 100 */ 314 sd->vmax.whitebal = 2; /* 100, not done by hardware */
367 sd->vmax.mirror = 1; 315 sd->vmax.mirror = 1;
368 sd->vmax.flip = 1; 316 sd->vmax.flip = 1;
369 sd->vmax.AC50Hz = 1; 317 sd->vmax.AC50Hz = 1;
370 if (_MI2020b_) {
371 sd->vmax.contrast = 0;
372 sd->vmax.gamma = 0;
373 sd->vmax.backlight = 0;
374 }
375 318
376 sd->dev_camera_settings = mi2020_camera_settings; 319 sd->dev_camera_settings = mi2020_camera_settings;
377 sd->dev_init_at_startup = mi2020_init_at_startup; 320 sd->dev_init_at_startup = mi2020_init_at_startup;
@@ -384,51 +327,9 @@ void mi2020_init_settings(struct gspca_dev *gspca_dev)
384 327
385static void common(struct gspca_dev *gspca_dev) 328static void common(struct gspca_dev *gspca_dev)
386{ 329{
387 s32 reso = gspca_dev->cam.cam_mode[(s32) gspca_dev->curr_mode].priv; 330 fetch_validx(gspca_dev, tbl_common_0B, ARRAY_SIZE(tbl_common_0B));
388 331 fetch_idxdata(gspca_dev, tbl_common_3B, ARRAY_SIZE(tbl_common_3B));
389 if (_MI2020b_) { 332 ctrl_out(gspca_dev, 0x40, 1, 0x0041, 0x0000, 0, NULL);
390 fetch_validx(gspca_dev, tbl_common1, ARRAY_SIZE(tbl_common1));
391 } else {
392 if (_MI2020_)
393 ctrl_out(gspca_dev, 0x40, 1, 0x0008, 0x0004, 0, NULL);
394 else
395 ctrl_out(gspca_dev, 0x40, 1, 0x0002, 0x0004, 0, NULL);
396 msleep(35);
397 fetch_validx(gspca_dev, tbl_common2, ARRAY_SIZE(tbl_common2));
398 }
399 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x86\x25\x01");
400 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x86\x25\x00");
401 msleep(2); /* - * */
402 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0030, 3, "\x1a\x0a\xcc");
403 if (reso == IMAGE_1600)
404 msleep(2); /* 1600 */
405 fetch_idxdata(gspca_dev, tbl_common3, ARRAY_SIZE(tbl_common3));
406
407 if (_MI2020b_ || _MI2020_)
408 fetch_idxdata(gspca_dev, tbl_common4,
409 ARRAY_SIZE(tbl_common4));
410
411 fetch_idxdata(gspca_dev, tbl_common5, ARRAY_SIZE(tbl_common5));
412 if (_MI2020b_ || _MI2020_) {
413 /* Different from fret */
414 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x90\x00\x78");
415 /* Same as fret */
416 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x8c\x24\x17");
417 /* Different from fret */
418 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x90\x00\x90");
419 } else {
420 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x90\x00\x6a");
421 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x8c\x24\x17");
422 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x90\x00\x80");
423 }
424 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x8c\xa1\x03");
425 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x90\x00\x05");
426 msleep(2);
427 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x8c\xa1\x03");
428 if (reso == IMAGE_1600)
429 msleep(14); /* 1600 */
430 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x90\x00\x06");
431 msleep(2);
432} 333}
433 334
434static int mi2020_init_at_startup(struct gspca_dev *gspca_dev) 335static int mi2020_init_at_startup(struct gspca_dev *gspca_dev)
@@ -441,8 +342,16 @@ static int mi2020_init_at_startup(struct gspca_dev *gspca_dev)
441 fetch_validx(gspca_dev, tbl_init_at_startup, 342 fetch_validx(gspca_dev, tbl_init_at_startup,
442 ARRAY_SIZE(tbl_init_at_startup)); 343 ARRAY_SIZE(tbl_init_at_startup));
443 344
345 ctrl_out(gspca_dev, 0x40, 1, 0x7a00, 0x8030, 0, NULL);
346 ctrl_in(gspca_dev, 0xc0, 2, 0x7a00, 0x8030, 1, &c);
347
444 common(gspca_dev); 348 common(gspca_dev);
445 349
350 msleep(61);
351/* ctrl_out(gspca_dev, 0x40, 11, 0x0000, 0x0000, 0, NULL); */
352/* msleep(36); */
353 ctrl_out(gspca_dev, 0x40, 1, 0x0001, 0x0000, 0, NULL);
354
446 return 0; 355 return 0;
447} 356}
448 357
@@ -450,17 +359,17 @@ static int mi2020_init_pre_alt(struct gspca_dev *gspca_dev)
450{ 359{
451 struct sd *sd = (struct sd *) gspca_dev; 360 struct sd *sd = (struct sd *) gspca_dev;
452 361
453 sd->mirrorMask = 0; 362 sd->mirrorMask = 0;
363 sd->vold.hue = -1;
454 364
455 sd->vold.backlight = -1; 365 /* These controls need to be reset */
456 sd->vold.brightness = -1; 366 sd->vold.brightness = -1;
457 sd->vold.sharpness = -1; 367 sd->vold.sharpness = -1;
458 sd->vold.contrast = -1; 368
459 sd->vold.gamma = -1; 369 /* If not different from default, they do not need to be set */
460 sd->vold.hue = -1; 370 sd->vold.contrast = 0;
461 sd->vold.mirror = -1; 371 sd->vold.gamma = 0;
462 sd->vold.flip = -1; 372 sd->vold.backlight = 0;
463 sd->vold.AC50Hz = -1;
464 373
465 mi2020_init_post_alt(gspca_dev); 374 mi2020_init_post_alt(gspca_dev);
466 375
@@ -472,10 +381,10 @@ static int mi2020_init_post_alt(struct gspca_dev *gspca_dev)
472 struct sd *sd = (struct sd *) gspca_dev; 381 struct sd *sd = (struct sd *) gspca_dev;
473 s32 reso = gspca_dev->cam.cam_mode[(s32) gspca_dev->curr_mode].priv; 382 s32 reso = gspca_dev->cam.cam_mode[(s32) gspca_dev->curr_mode].priv;
474 383
475 s32 backlight = sd->vcur.backlight;
476 s32 mirror = (((sd->vcur.mirror > 0) ^ sd->mirrorMask) > 0); 384 s32 mirror = (((sd->vcur.mirror > 0) ^ sd->mirrorMask) > 0);
477 s32 flip = (((sd->vcur.flip > 0) ^ sd->mirrorMask) > 0); 385 s32 flip = (((sd->vcur.flip > 0) ^ sd->mirrorMask) > 0);
478 s32 freq = (sd->vcur.AC50Hz > 0); 386 s32 freq = (sd->vcur.AC50Hz > 0);
387 s32 wbal = sd->vcur.whitebal;
479 388
480 u8 dat_freq2[] = {0x90, 0x00, 0x80}; 389 u8 dat_freq2[] = {0x90, 0x00, 0x80};
481 u8 dat_multi1[] = {0x8c, 0xa7, 0x00}; 390 u8 dat_multi1[] = {0x8c, 0xa7, 0x00};
@@ -484,6 +393,7 @@ static int mi2020_init_post_alt(struct gspca_dev *gspca_dev)
484 u8 dat_multi4[] = {0x90, 0x00, 0x00}; 393 u8 dat_multi4[] = {0x90, 0x00, 0x00};
485 u8 dat_hvflip2[] = {0x90, 0x04, 0x6c}; 394 u8 dat_hvflip2[] = {0x90, 0x04, 0x6c};
486 u8 dat_hvflip4[] = {0x90, 0x00, 0x24}; 395 u8 dat_hvflip4[] = {0x90, 0x00, 0x24};
396 u8 dat_wbal2[] = {0x90, 0x00, 0x00};
487 u8 c; 397 u8 c;
488 398
489 sd->nbIm = -1; 399 sd->nbIm = -1;
@@ -491,23 +401,26 @@ static int mi2020_init_post_alt(struct gspca_dev *gspca_dev)
491 dat_freq2[2] = freq ? 0xc0 : 0x80; 401 dat_freq2[2] = freq ? 0xc0 : 0x80;
492 dat_multi1[2] = 0x9d; 402 dat_multi1[2] = 0x9d;
493 dat_multi3[2] = dat_multi1[2] + 1; 403 dat_multi3[2] = dat_multi1[2] + 1;
494 dat_multi4[2] = dat_multi2[2] = backlight; 404 if (wbal == 0) {
405 dat_multi4[2] = dat_multi2[2] = 0;
406 dat_wbal2[2] = 0x17;
407 } else if (wbal == 1) {
408 dat_multi4[2] = dat_multi2[2] = 0;
409 dat_wbal2[2] = 0x35;
410 } else if (wbal == 2) {
411 dat_multi4[2] = dat_multi2[2] = 0x20;
412 dat_wbal2[2] = 0x17;
413 }
495 dat_hvflip2[2] = 0x6c + 2 * (1 - flip) + (1 - mirror); 414 dat_hvflip2[2] = 0x6c + 2 * (1 - flip) + (1 - mirror);
496 dat_hvflip4[2] = 0x24 + 2 * (1 - flip) + (1 - mirror); 415 dat_hvflip4[2] = 0x24 + 2 * (1 - flip) + (1 - mirror);
497 416
498 msleep(200); 417 msleep(200);
499
500 ctrl_out(gspca_dev, 0x40, 5, 0x0001, 0x0000, 0, NULL); 418 ctrl_out(gspca_dev, 0x40, 5, 0x0001, 0x0000, 0, NULL);
501 msleep(3); /* 35 * */ 419 msleep(2);
502 420
503 common(gspca_dev); 421 common(gspca_dev);
504 422
505 ctrl_out(gspca_dev, 0x40, 1, 0x0041, 0x0000, 0, NULL); 423 msleep(142);
506 msleep(70);
507
508 if (_MI2020b_)
509 ctrl_out(gspca_dev, 0x40, 1, 0x0040, 0x0000, 0, NULL);
510
511 ctrl_out(gspca_dev, 0x40, 1, 0x0010, 0x0010, 0, NULL); 424 ctrl_out(gspca_dev, 0x40, 1, 0x0010, 0x0010, 0, NULL);
512 ctrl_out(gspca_dev, 0x40, 1, 0x0003, 0x00c1, 0, NULL); 425 ctrl_out(gspca_dev, 0x40, 1, 0x0003, 0x00c1, 0, NULL);
513 ctrl_out(gspca_dev, 0x40, 1, 0x0042, 0x00c2, 0, NULL); 426 ctrl_out(gspca_dev, 0x40, 1, 0x0042, 0x00c2, 0, NULL);
@@ -523,8 +436,7 @@ static int mi2020_init_post_alt(struct gspca_dev *gspca_dev)
523 ctrl_out(gspca_dev, 0x40, 3, 0x0000, 0x0200, 436 ctrl_out(gspca_dev, 0x40, 3, 0x0000, 0x0200,
524 12, dat_800); 437 12, dat_800);
525 438
526 if (_MI2020c_) 439 fetch_idxdata(gspca_dev, tbl_init_post_alt_low1,
527 fetch_idxdata(gspca_dev, tbl_init_post_alt_low1,
528 ARRAY_SIZE(tbl_init_post_alt_low1)); 440 ARRAY_SIZE(tbl_init_post_alt_low1));
529 441
530 if (reso == IMAGE_800) 442 if (reso == IMAGE_800)
@@ -534,87 +446,10 @@ static int mi2020_init_post_alt(struct gspca_dev *gspca_dev)
534 fetch_idxdata(gspca_dev, tbl_init_post_alt_low3, 446 fetch_idxdata(gspca_dev, tbl_init_post_alt_low3,
535 ARRAY_SIZE(tbl_init_post_alt_low3)); 447 ARRAY_SIZE(tbl_init_post_alt_low3));
536 448
537 if (_MI2020b_) { 449 ctrl_out(gspca_dev, 0x40, 1, 0x0010, 0x0010, 0, NULL);
538 ctrl_out(gspca_dev, 0x40, 1, 0x0001, 0x0010, 0, NULL); 450 ctrl_out(gspca_dev, 0x40, 1, 0x0000, 0x00c1, 0, NULL);
539 ctrl_out(gspca_dev, 0x40, 1, 0x0000, 0x00c1, 0, NULL); 451 ctrl_out(gspca_dev, 0x40, 1, 0x0041, 0x00c2, 0, NULL);
540 ctrl_out(gspca_dev, 0x40, 1, 0x0041, 0x00c2, 0, NULL); 452 msleep(120);
541 msleep(150);
542 } else if (_MI2020c_) {
543 ctrl_out(gspca_dev, 0x40, 1, 0x0010, 0x0010, 0, NULL);
544 ctrl_out(gspca_dev, 0x40, 1, 0x0000, 0x00c1, 0, NULL);
545 ctrl_out(gspca_dev, 0x40, 1, 0x0041, 0x00c2, 0, NULL);
546 msleep(120);
547 ctrl_out(gspca_dev, 0x40, 1, 0x0040, 0x0000, 0, NULL);
548 msleep(30);
549 } else if (_MI2020_) {
550 ctrl_out(gspca_dev, 0x40, 1, 0x0001, 0x0010, 0, NULL);
551 ctrl_out(gspca_dev, 0x40, 1, 0x0000, 0x00c1, 0, NULL);
552 ctrl_out(gspca_dev, 0x40, 1, 0x0041, 0x00c2, 0, NULL);
553 msleep(120);
554 ctrl_out(gspca_dev, 0x40, 1, 0x0040, 0x0000, 0, NULL);
555 msleep(30);
556 }
557
558 /* AC power frequency */
559 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_freq1);
560 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_freq2);
561 msleep(20);
562 /* backlight */
563 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi1);
564 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi2);
565 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi3);
566 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi4);
567 /* at init time but not after */
568 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x8c\xa2\x0c");
569 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x90\x00\x17");
570 /* finish the backlight */
571 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi5);
572 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi6);
573 msleep(5);/* " */
574
575 if (_MI2020c_) {
576 fetch_idxdata(gspca_dev, tbl_init_post_alt_low4,
577 ARRAY_SIZE(tbl_init_post_alt_low4));
578 } else {
579 ctrl_in(gspca_dev, 0xc0, 2, 0x0000, 0x0000, 1, &c);
580 msleep(14); /* 0xd8 */
581
582 /* flip/mirror */
583 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,
584 3, dat_hvflip1);
585 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,
586 3, dat_hvflip2);
587 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,
588 3, dat_hvflip3);
589 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,
590 3, dat_hvflip4);
591 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,
592 3, dat_hvflip5);
593 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,
594 3, dat_hvflip6);
595 msleep(21);
596 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,
597 3, dat_dummy1);
598 msleep(5);
599 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,
600 3, dat_dummy1);
601 msleep(5);
602 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,
603 3, dat_dummy1);
604 msleep(5);
605 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,
606 3, dat_dummy1);
607 msleep(5);
608 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,
609 3, dat_dummy1);
610 msleep(5);
611 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033,
612 3, dat_dummy1);
613 /* end of flip/mirror main part */
614 msleep(246); /* 146 */
615
616 sd->nbIm = 0;
617 }
618 break; 453 break;
619 454
620 case IMAGE_1280: 455 case IMAGE_1280:
@@ -643,108 +478,62 @@ static int mi2020_init_post_alt(struct gspca_dev *gspca_dev)
643 3, "\x90\x04\xb0"); 478 3, "\x90\x04\xb0");
644 } 479 }
645 480
646 fetch_idxdata(gspca_dev, tbl_init_post_alt_big1, 481 fetch_idxdata(gspca_dev, tbl_init_post_alt_big,
647 ARRAY_SIZE(tbl_init_post_alt_big1)); 482 ARRAY_SIZE(tbl_init_post_alt_big));
648
649 if (reso == IMAGE_1600)
650 msleep(13); /* 1600 */
651 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x8c\x27\x97");
652 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x90\x01\x00");
653 msleep(53);
654 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x8c\xa1\x20");
655 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x90\x00\x00");
656 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x8c\xa1\x03");
657 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x90\x00\x01");
658 if (reso == IMAGE_1600)
659 msleep(13); /* 1600 */
660 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x8c\xa7\x02");
661 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x90\x00\x00");
662 msleep(53);
663 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x8c\xa1\x20");
664 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x90\x00\x72");
665 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x8c\xa1\x03");
666 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x90\x00\x02");
667 if (reso == IMAGE_1600)
668 msleep(13); /* 1600 */
669 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x8c\xa7\x02");
670 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x90\x00\x01");
671 msleep(53);
672
673 if (_MI2020b_) {
674 ctrl_out(gspca_dev, 0x40, 1, 0x0001, 0x0010, 0, NULL);
675 if (reso == IMAGE_1600)
676 msleep(500); /* 1600 */
677 ctrl_out(gspca_dev, 0x40, 1, 0x0000, 0x00c1, 0, NULL);
678 ctrl_out(gspca_dev, 0x40, 1, 0x0041, 0x00c2, 0, NULL);
679 msleep(1850);
680 } else if (_MI2020c_ || _MI2020_) {
681 ctrl_out(gspca_dev, 0x40, 1, 0x0001, 0x0010, 0, NULL);
682 ctrl_out(gspca_dev, 0x40, 1, 0x0000, 0x00c1, 0, NULL);
683 ctrl_out(gspca_dev, 0x40, 1, 0x0041, 0x00c2, 0, NULL);
684 msleep(1850);
685 ctrl_out(gspca_dev, 0x40, 1, 0x0040, 0x0000, 0, NULL);
686 msleep(30);
687 }
688 483
689 /* AC power frequency */ 484 ctrl_out(gspca_dev, 0x40, 1, 0x0001, 0x0010, 0, NULL);
690 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_freq1); 485 ctrl_out(gspca_dev, 0x40, 1, 0x0000, 0x00c1, 0, NULL);
691 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_freq2); 486 ctrl_out(gspca_dev, 0x40, 1, 0x0041, 0x00c2, 0, NULL);
692 msleep(20); 487 msleep(1850);
693 /* backlight */ 488 }
694 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi1);
695 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi2);
696 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi3);
697 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi4);
698 /* at init time but not after */
699 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x8c\xa2\x0c");
700 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x90\x00\x17");
701 /* finish the backlight */
702 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi5);
703 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi6);
704 msleep(6); /* " */
705 489
706 ctrl_in(gspca_dev, 0xc0, 2, 0x0000, 0x0000, 1, &c); 490 ctrl_out(gspca_dev, 0x40, 1, 0x0040, 0x0000, 0, NULL);
707 msleep(14); 491 msleep(40);
492
493 /* AC power frequency */
494 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_freq1);
495 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_freq2);
496 msleep(33);
497 /* light source */
498 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi1);
499 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi2);
500 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi3);
501 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi4);
502 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_wbal1);
503 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_wbal2);
504 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi5);
505 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi6);
506 msleep(7);
507 ctrl_in(gspca_dev, 0xc0, 2, 0x0000, 0x0000, 1, &c);
508
509 fetch_idxdata(gspca_dev, tbl_init_post_alt_3B,
510 ARRAY_SIZE(tbl_init_post_alt_3B));
511
512 /* hvflip */
513 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip1);
514 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip2);
515 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip3);
516 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip4);
517 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip5);
518 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip6);
519 msleep(250);
520
521 if (reso == IMAGE_640 || reso == IMAGE_800)
522 fetch_idxdata(gspca_dev, tbl_middle_hvflip_low,
523 ARRAY_SIZE(tbl_middle_hvflip_low));
524 else
525 fetch_idxdata(gspca_dev, tbl_middle_hvflip_big,
526 ARRAY_SIZE(tbl_middle_hvflip_big));
708 527
709 if (_MI2020c_) 528 fetch_idxdata(gspca_dev, tbl_end_hvflip,
710 fetch_idxdata(gspca_dev, tbl_init_post_alt_big2, 529 ARRAY_SIZE(tbl_end_hvflip));
711 ARRAY_SIZE(tbl_init_post_alt_big2));
712 530
713 /* flip/mirror */ 531 sd->nbIm = 0;
714 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip1);
715 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip2);
716 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip3);
717 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip4);
718 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip5);
719 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip6);
720 /* end of flip/mirror main part */
721 msleep(16);
722 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x8c\xa1\x03");
723 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x90\x00\x01");
724 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x8c\xa1\x20");
725 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x90\x00\x00");
726 if (reso == IMAGE_1600)
727 msleep(25); /* 1600 */
728 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x8c\xa7\x02");
729 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x90\x00\x00");
730 msleep(103);
731 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x8c\xa1\x03");
732 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x90\x00\x02");
733 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x8c\xa1\x20");
734 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x90\x00\x72");
735 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x8c\xa7\x02");
736 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, "\x90\x00\x01");
737 sd->nbIm = 0;
738
739 if (_MI2020c_)
740 fetch_idxdata(gspca_dev, tbl_init_post_alt_big3,
741 ARRAY_SIZE(tbl_init_post_alt_big3));
742 }
743 532
744 sd->vold.mirror = mirror; 533 sd->vold.mirror = mirror;
745 sd->vold.flip = flip; 534 sd->vold.flip = flip;
746 sd->vold.AC50Hz = freq; 535 sd->vold.AC50Hz = freq;
747 sd->vold.backlight = backlight; 536 sd->vold.whitebal = wbal;
748 537
749 mi2020_camera_settings(gspca_dev); 538 mi2020_camera_settings(gspca_dev);
750 539
@@ -772,6 +561,7 @@ static int mi2020_configure_alt(struct gspca_dev *gspca_dev)
772static int mi2020_camera_settings(struct gspca_dev *gspca_dev) 561static int mi2020_camera_settings(struct gspca_dev *gspca_dev)
773{ 562{
774 struct sd *sd = (struct sd *) gspca_dev; 563 struct sd *sd = (struct sd *) gspca_dev;
564 s32 reso = gspca_dev->cam.cam_mode[(s32) gspca_dev->curr_mode].priv;
775 565
776 s32 backlight = sd->vcur.backlight; 566 s32 backlight = sd->vcur.backlight;
777 s32 bright = sd->vcur.brightness; 567 s32 bright = sd->vcur.brightness;
@@ -782,6 +572,7 @@ static int mi2020_camera_settings(struct gspca_dev *gspca_dev)
782 s32 mirror = (((sd->vcur.mirror > 0) ^ sd->mirrorMask) > 0); 572 s32 mirror = (((sd->vcur.mirror > 0) ^ sd->mirrorMask) > 0);
783 s32 flip = (((sd->vcur.flip > 0) ^ sd->mirrorMask) > 0); 573 s32 flip = (((sd->vcur.flip > 0) ^ sd->mirrorMask) > 0);
784 s32 freq = (sd->vcur.AC50Hz > 0); 574 s32 freq = (sd->vcur.AC50Hz > 0);
575 s32 wbal = sd->vcur.whitebal;
785 576
786 u8 dat_sharp[] = {0x6c, 0x00, 0x08}; 577 u8 dat_sharp[] = {0x6c, 0x00, 0x08};
787 u8 dat_bright2[] = {0x90, 0x00, 0x00}; 578 u8 dat_bright2[] = {0x90, 0x00, 0x00};
@@ -792,6 +583,7 @@ static int mi2020_camera_settings(struct gspca_dev *gspca_dev)
792 u8 dat_multi4[] = {0x90, 0x00, 0x00}; 583 u8 dat_multi4[] = {0x90, 0x00, 0x00};
793 u8 dat_hvflip2[] = {0x90, 0x04, 0x6c}; 584 u8 dat_hvflip2[] = {0x90, 0x04, 0x6c};
794 u8 dat_hvflip4[] = {0x90, 0x00, 0x24}; 585 u8 dat_hvflip4[] = {0x90, 0x00, 0x24};
586 u8 dat_wbal2[] = {0x90, 0x00, 0x00};
795 587
796 /* Less than 4 images received -> too early to set the settings */ 588 /* Less than 4 images received -> too early to set the settings */
797 if (sd->nbIm < 4) { 589 if (sd->nbIm < 4) {
@@ -809,67 +601,89 @@ static int mi2020_camera_settings(struct gspca_dev *gspca_dev)
809 msleep(20); 601 msleep(20);
810 } 602 }
811 603
604 if (wbal != sd->vold.whitebal) {
605 sd->vold.whitebal = wbal;
606 if (wbal < 0 || wbal > sd->vmax.whitebal)
607 wbal = 0;
608
609 dat_multi1[2] = 0x9d;
610 dat_multi3[2] = dat_multi1[2] + 1;
611 if (wbal == 0) {
612 dat_multi4[2] = dat_multi2[2] = 0;
613 dat_wbal2[2] = 0x17;
614 } else if (wbal == 1) {
615 dat_multi4[2] = dat_multi2[2] = 0;
616 dat_wbal2[2] = 0x35;
617 } else if (wbal == 2) {
618 dat_multi4[2] = dat_multi2[2] = 0x20;
619 dat_wbal2[2] = 0x17;
620 }
621 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi1);
622 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi2);
623 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi3);
624 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi4);
625 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_wbal1);
626 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_wbal2);
627 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi5);
628 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi6);
629 }
630
812 if (mirror != sd->vold.mirror || flip != sd->vold.flip) { 631 if (mirror != sd->vold.mirror || flip != sd->vold.flip) {
813 sd->vold.mirror = mirror; 632 sd->vold.mirror = mirror;
814 sd->vold.flip = flip; 633 sd->vold.flip = flip;
815 634
816 dat_hvflip2[2] = 0x6c + 2 * (1 - flip) + (1 - mirror); 635 dat_hvflip2[2] = 0x6c + 2 * (1 - flip) + (1 - mirror);
817 dat_hvflip4[2] = 0x24 + 2 * (1 - flip) + (1 - mirror); 636 dat_hvflip4[2] = 0x24 + 2 * (1 - flip) + (1 - mirror);
637
638 fetch_idxdata(gspca_dev, tbl_init_post_alt_3B,
639 ARRAY_SIZE(tbl_init_post_alt_3B));
640
818 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip1); 641 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip1);
819 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip2); 642 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip2);
820 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip3); 643 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip3);
821 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip4); 644 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip4);
822 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip5); 645 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip5);
823 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip6); 646 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_hvflip6);
824 msleep(130); 647 msleep(40);
825 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_dummy1); 648
826 msleep(6); 649 if (reso == IMAGE_640 || reso == IMAGE_800)
827 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_dummy1); 650 fetch_idxdata(gspca_dev, tbl_middle_hvflip_low,
828 msleep(6); 651 ARRAY_SIZE(tbl_middle_hvflip_low));
829 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_dummy1); 652 else
830 msleep(6); 653 fetch_idxdata(gspca_dev, tbl_middle_hvflip_big,
831 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_dummy1); 654 ARRAY_SIZE(tbl_middle_hvflip_big));
832 msleep(6); 655
833 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_dummy1); 656 fetch_idxdata(gspca_dev, tbl_end_hvflip,
834 msleep(6); 657 ARRAY_SIZE(tbl_end_hvflip));
835 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_dummy1);
836 msleep(6);
837
838 /* Sometimes present, sometimes not, useful? */
839 /* ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dummy2);
840 * ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dummy3);
841 * ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dummy2);
842 * ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dummy3);
843 * ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dummy2);
844 * ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dummy3);
845 * ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dummy2);
846 * ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dummy3);*/
847 } 658 }
848 659
849 if (backlight != sd->vold.backlight) { 660 if (bright != sd->vold.brightness) {
850 sd->vold.backlight = backlight; 661 sd->vold.brightness = bright;
851 if (backlight < 0 || backlight > sd->vmax.backlight) 662 if (bright < 0 || bright > sd->vmax.brightness)
852 backlight = 0; 663 bright = 0;
853 664
854 dat_multi1[2] = 0x9d; 665 dat_bright2[2] = bright;
855 dat_multi3[2] = dat_multi1[2] + 1; 666 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_bright1);
856 dat_multi4[2] = dat_multi2[2] = backlight; 667 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_bright2);
857 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi1); 668 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_bright3);
858 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi2); 669 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_bright4);
859 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi3); 670 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_bright5);
860 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi4); 671 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_bright6);
861 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi5);
862 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi6);
863 } 672 }
864 673
865 if (gam != sd->vold.gamma) { 674 if (cntr != sd->vold.contrast || gam != sd->vold.gamma) {
675 sd->vold.contrast = cntr;
676 if (cntr < 0 || cntr > sd->vmax.contrast)
677 cntr = 0;
866 sd->vold.gamma = gam; 678 sd->vold.gamma = gam;
867 if (gam < 0 || gam > sd->vmax.gamma) 679 if (gam < 0 || gam > sd->vmax.gamma)
868 gam = 0; 680 gam = 0;
869 681
870 dat_multi1[2] = 0x6d; 682 dat_multi1[2] = 0x6d;
871 dat_multi3[2] = dat_multi1[2] + 1; 683 dat_multi3[2] = dat_multi1[2] + 1;
872 dat_multi4[2] = dat_multi2[2] = 0x40 + gam; 684 if (cntr == 0)
685 cntr = 4;
686 dat_multi4[2] = dat_multi2[2] = cntr * 0x10 + 2 - gam;
873 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi1); 687 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi1);
874 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi2); 688 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi2);
875 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi3); 689 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi3);
@@ -878,14 +692,14 @@ static int mi2020_camera_settings(struct gspca_dev *gspca_dev)
878 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi6); 692 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi6);
879 } 693 }
880 694
881 if (cntr != sd->vold.contrast) { 695 if (backlight != sd->vold.backlight) {
882 sd->vold.contrast = cntr; 696 sd->vold.backlight = backlight;
883 if (cntr < 0 || cntr > sd->vmax.contrast) 697 if (backlight < 0 || backlight > sd->vmax.backlight)
884 cntr = 0; 698 backlight = 0;
885 699
886 dat_multi1[2] = 0x6d; 700 dat_multi1[2] = 0x9d;
887 dat_multi3[2] = dat_multi1[2] + 1; 701 dat_multi3[2] = dat_multi1[2] + 1;
888 dat_multi4[2] = dat_multi2[2] = 0x12 + 16 * cntr; 702 dat_multi4[2] = dat_multi2[2] = backlight;
889 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi1); 703 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi1);
890 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi2); 704 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi2);
891 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi3); 705 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi3);
@@ -894,20 +708,6 @@ static int mi2020_camera_settings(struct gspca_dev *gspca_dev)
894 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi6); 708 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_multi6);
895 } 709 }
896 710
897 if (bright != sd->vold.brightness) {
898 sd->vold.brightness = bright;
899 if (bright < 0 || bright > sd->vmax.brightness)
900 bright = 0;
901
902 dat_bright2[2] = bright;
903 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_bright1);
904 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_bright2);
905 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_bright3);
906 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_bright4);
907 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_bright5);
908 ctrl_out(gspca_dev, 0x40, 3, 0x7a00, 0x0033, 3, dat_bright6);
909 }
910
911 if (sharp != sd->vold.sharpness) { 711 if (sharp != sd->vold.sharpness) {
912 sd->vold.sharpness = sharp; 712 sd->vold.sharpness = sharp;
913 if (sharp < 0 || sharp > sd->vmax.sharpness) 713 if (sharp < 0 || sharp > sd->vmax.sharpness)
@@ -928,9 +728,6 @@ static int mi2020_camera_settings(struct gspca_dev *gspca_dev)
928static void mi2020_post_unset_alt(struct gspca_dev *gspca_dev) 728static void mi2020_post_unset_alt(struct gspca_dev *gspca_dev)
929{ 729{
930 ctrl_out(gspca_dev, 0x40, 5, 0x0000, 0x0000, 0, NULL); 730 ctrl_out(gspca_dev, 0x40, 5, 0x0000, 0x0000, 0, NULL);
931 msleep(20); 731 msleep(40);
932 if (_MI2020c_ || _MI2020_) 732 ctrl_out(gspca_dev, 0x40, 1, 0x0001, 0x0000, 0, NULL);
933 ctrl_out(gspca_dev, 0x40, 1, 0x0001, 0x0000, 0, NULL);
934 else
935 ctrl_out(gspca_dev, 0x40, 1, 0x0041, 0x0000, 0, NULL);
936} 733}
diff --git a/drivers/media/video/gspca/gl860/gl860-ov9655.c b/drivers/media/video/gspca/gl860/gl860-ov9655.c
index d412694c50af..5ae9619d72a5 100644
--- a/drivers/media/video/gspca/gl860/gl860-ov9655.c
+++ b/drivers/media/video/gspca/gl860/gl860-ov9655.c
@@ -69,7 +69,7 @@ static u8 *tbl_640[] = {
69 "\xd0\x01\xd1\x08\xd2\xe0\xd3\x01" "\xd4\x10\xd5\x80" 69 "\xd0\x01\xd1\x08\xd2\xe0\xd3\x01" "\xd4\x10\xd5\x80"
70}; 70};
71 71
72static u8 *tbl_800[] = { 72static u8 *tbl_1280[] = {
73 "\x00\x40\x07\x6a\x06\xf3\x0d\x6a" "\x10\x10\xc1\x01" 73 "\x00\x40\x07\x6a\x06\xf3\x0d\x6a" "\x10\x10\xc1\x01"
74 , 74 ,
75 "\x12\x80\x00\x00\x01\x98\x02\x80" "\x03\x12\x04\x01\x0b\x57\x0e\x61" 75 "\x12\x80\x00\x00\x01\x98\x02\x80" "\x03\x12\x04\x01\x0b\x57\x0e\x61"
@@ -217,7 +217,7 @@ static int ov9655_init_post_alt(struct gspca_dev *gspca_dev)
217 217
218 ctrl_out(gspca_dev, 0x40, 5, 0x0001, 0x0000, 0, NULL); 218 ctrl_out(gspca_dev, 0x40, 5, 0x0001, 0x0000, 0, NULL);
219 219
220 tbl = (reso == IMAGE_640) ? tbl_640 : tbl_800; 220 tbl = (reso == IMAGE_640) ? tbl_640 : tbl_1280;
221 221
222 ctrl_out(gspca_dev, 0x40, 3, 0x0000, 0x0200, 222 ctrl_out(gspca_dev, 0x40, 3, 0x0000, 0x0200,
223 tbl_length[0], tbl[0]); 223 tbl_length[0], tbl[0]);
diff --git a/drivers/media/video/gspca/gl860/gl860.c b/drivers/media/video/gspca/gl860/gl860.c
index 9e42476c0eaf..e86eb8b4aedc 100644
--- a/drivers/media/video/gspca/gl860/gl860.c
+++ b/drivers/media/video/gspca/gl860/gl860.c
@@ -63,7 +63,7 @@ static int sd_set_##thename(struct gspca_dev *gspca_dev, s32 val)\
63\ 63\
64 sd->vcur.thename = val;\ 64 sd->vcur.thename = val;\
65 if (gspca_dev->streaming)\ 65 if (gspca_dev->streaming)\
66 sd->dev_camera_settings(gspca_dev);\ 66 sd->waitSet = 1;\
67 return 0;\ 67 return 0;\
68} \ 68} \
69static int sd_get_##thename(struct gspca_dev *gspca_dev, s32 *val)\ 69static int sd_get_##thename(struct gspca_dev *gspca_dev, s32 *val)\
@@ -91,7 +91,6 @@ SD_SETGET(contrast)
91/* control table */ 91/* control table */
92static struct ctrl sd_ctrls_mi1320[GL860_NCTRLS]; 92static struct ctrl sd_ctrls_mi1320[GL860_NCTRLS];
93static struct ctrl sd_ctrls_mi2020[GL860_NCTRLS]; 93static struct ctrl sd_ctrls_mi2020[GL860_NCTRLS];
94static struct ctrl sd_ctrls_mi2020b[GL860_NCTRLS];
95static struct ctrl sd_ctrls_ov2640[GL860_NCTRLS]; 94static struct ctrl sd_ctrls_ov2640[GL860_NCTRLS];
96static struct ctrl sd_ctrls_ov9655[GL860_NCTRLS]; 95static struct ctrl sd_ctrls_ov9655[GL860_NCTRLS];
97 96
@@ -121,8 +120,6 @@ static int gl860_build_control_table(struct gspca_dev *gspca_dev)
121 sd_ctrls = sd_ctrls_mi1320; 120 sd_ctrls = sd_ctrls_mi1320;
122 else if (_MI2020_) 121 else if (_MI2020_)
123 sd_ctrls = sd_ctrls_mi2020; 122 sd_ctrls = sd_ctrls_mi2020;
124 else if (_MI2020b_)
125 sd_ctrls = sd_ctrls_mi2020b;
126 else if (_OV2640_) 123 else if (_OV2640_)
127 sd_ctrls = sd_ctrls_ov2640; 124 sd_ctrls = sd_ctrls_ov2640;
128 else if (_OV9655_) 125 else if (_OV9655_)
@@ -187,19 +184,6 @@ static const struct sd_desc sd_desc_mi2020 = {
187 .dq_callback = sd_callback, 184 .dq_callback = sd_callback,
188}; 185};
189 186
190static const struct sd_desc sd_desc_mi2020b = {
191 .name = MODULE_NAME,
192 .ctrls = sd_ctrls_mi2020b,
193 .nctrls = GL860_NCTRLS,
194 .config = sd_config,
195 .init = sd_init,
196 .isoc_init = sd_isoc_init,
197 .start = sd_start,
198 .stop0 = sd_stop0,
199 .pkt_scan = sd_pkt_scan,
200 .dq_callback = sd_callback,
201};
202
203static const struct sd_desc sd_desc_ov2640 = { 187static const struct sd_desc sd_desc_ov2640 = {
204 .name = MODULE_NAME, 188 .name = MODULE_NAME,
205 .ctrls = sd_ctrls_ov2640, 189 .ctrls = sd_ctrls_ov2640,
@@ -235,9 +219,9 @@ static struct v4l2_pix_format mi2020_mode[] = {
235 .colorspace = V4L2_COLORSPACE_SRGB, 219 .colorspace = V4L2_COLORSPACE_SRGB,
236 .priv = 0 220 .priv = 0
237 }, 221 },
238 { 800, 600, V4L2_PIX_FMT_SGBRG8, V4L2_FIELD_NONE, 222 { 800, 598, V4L2_PIX_FMT_SGBRG8, V4L2_FIELD_NONE,
239 .bytesperline = 800, 223 .bytesperline = 800,
240 .sizeimage = 800 * 600, 224 .sizeimage = 800 * 598,
241 .colorspace = V4L2_COLORSPACE_SRGB, 225 .colorspace = V4L2_COLORSPACE_SRGB,
242 .priv = 1 226 .priv = 1
243 }, 227 },
@@ -247,9 +231,9 @@ static struct v4l2_pix_format mi2020_mode[] = {
247 .colorspace = V4L2_COLORSPACE_SRGB, 231 .colorspace = V4L2_COLORSPACE_SRGB,
248 .priv = 2 232 .priv = 2
249 }, 233 },
250 {1600, 1200, V4L2_PIX_FMT_SGBRG8, V4L2_FIELD_NONE, 234 {1600, 1198, V4L2_PIX_FMT_SGBRG8, V4L2_FIELD_NONE,
251 .bytesperline = 1600, 235 .bytesperline = 1600,
252 .sizeimage = 1600 * 1200, 236 .sizeimage = 1600 * 1198,
253 .colorspace = V4L2_COLORSPACE_SRGB, 237 .colorspace = V4L2_COLORSPACE_SRGB,
254 .priv = 3 238 .priv = 3
255 }, 239 },
@@ -344,8 +328,6 @@ static int sd_config(struct gspca_dev *gspca_dev,
344 sd->sensor = ID_OV9655; 328 sd->sensor = ID_OV9655;
345 else if (strcmp(sensor, "MI2020") == 0) 329 else if (strcmp(sensor, "MI2020") == 0)
346 sd->sensor = ID_MI2020; 330 sd->sensor = ID_MI2020;
347 else if (strcmp(sensor, "MI2020b") == 0)
348 sd->sensor = ID_MI2020b;
349 331
350 /* Get sensor and set the suitable init/start/../stop functions */ 332 /* Get sensor and set the suitable init/start/../stop functions */
351 if (gl860_guess_sensor(gspca_dev, vendor_id, product_id) == -1) 333 if (gl860_guess_sensor(gspca_dev, vendor_id, product_id) == -1)
@@ -369,13 +351,6 @@ static int sd_config(struct gspca_dev *gspca_dev,
369 dev_init_settings = mi2020_init_settings; 351 dev_init_settings = mi2020_init_settings;
370 break; 352 break;
371 353
372 case ID_MI2020b:
373 gspca_dev->sd_desc = &sd_desc_mi2020b;
374 cam->cam_mode = mi2020_mode;
375 cam->nmodes = ARRAY_SIZE(mi2020_mode);
376 dev_init_settings = mi2020_init_settings;
377 break;
378
379 case ID_OV2640: 354 case ID_OV2640:
380 gspca_dev->sd_desc = &sd_desc_ov2640; 355 gspca_dev->sd_desc = &sd_desc_ov2640;
381 cam->cam_mode = ov2640_mode; 356 cam->cam_mode = ov2640_mode;
@@ -620,10 +595,7 @@ int gl860_RTx(struct gspca_dev *gspca_dev,
620 else if (len > 1 && r < len) 595 else if (len > 1 && r < len)
621 PDEBUG(D_ERR, "short ctrl transfer %d/%d", r, len); 596 PDEBUG(D_ERR, "short ctrl transfer %d/%d", r, len);
622 597
623 if ((_MI2020_ || _MI2020b_ || _MI2020c_) && (val || index)) 598 msleep(1);
624 msleep(1);
625 if (_OV2640_)
626 msleep(1);
627 599
628 return r; 600 return r;
629} 601}
@@ -767,8 +739,6 @@ static int gl860_guess_sensor(struct gspca_dev *gspca_dev,
767 PDEBUG(D_PROBE, "05e3:f191 sensor MI1320 (1.3M)"); 739 PDEBUG(D_PROBE, "05e3:f191 sensor MI1320 (1.3M)");
768 } else if (_MI2020_) { 740 } else if (_MI2020_) {
769 PDEBUG(D_PROBE, "05e3:0503 sensor MI2020 (2.0M)"); 741 PDEBUG(D_PROBE, "05e3:0503 sensor MI2020 (2.0M)");
770 } else if (_MI2020b_) {
771 PDEBUG(D_PROBE, "05e3:0503 sensor MI2020 alt. driver (2.0M)");
772 } else if (_OV9655_) { 742 } else if (_OV9655_) {
773 PDEBUG(D_PROBE, "05e3:0503 sensor OV9655 (1.3M)"); 743 PDEBUG(D_PROBE, "05e3:0503 sensor OV9655 (1.3M)");
774 } else if (_OV2640_) { 744 } else if (_OV2640_) {
diff --git a/drivers/media/video/gspca/gl860/gl860.h b/drivers/media/video/gspca/gl860/gl860.h
index 305061ff8387..49ad4acbf602 100644
--- a/drivers/media/video/gspca/gl860/gl860.h
+++ b/drivers/media/video/gspca/gl860/gl860.h
@@ -32,19 +32,16 @@
32#define ID_OV2640 2 32#define ID_OV2640 2
33#define ID_OV9655 4 33#define ID_OV9655 4
34#define ID_MI2020 8 34#define ID_MI2020 8
35#define ID_MI2020b 16
36 35
37#define _MI1320_ (((struct sd *) gspca_dev)->sensor == ID_MI1320) 36#define _MI1320_ (((struct sd *) gspca_dev)->sensor == ID_MI1320)
38#define _MI2020_ (((struct sd *) gspca_dev)->sensor == ID_MI2020) 37#define _MI2020_ (((struct sd *) gspca_dev)->sensor == ID_MI2020)
39#define _MI2020b_ (((struct sd *) gspca_dev)->sensor == ID_MI2020b)
40#define _MI2020c_ 0
41#define _OV2640_ (((struct sd *) gspca_dev)->sensor == ID_OV2640) 38#define _OV2640_ (((struct sd *) gspca_dev)->sensor == ID_OV2640)
42#define _OV9655_ (((struct sd *) gspca_dev)->sensor == ID_OV9655) 39#define _OV9655_ (((struct sd *) gspca_dev)->sensor == ID_OV9655)
43 40
44#define IMAGE_640 0 41#define IMAGE_640 0
45#define IMAGE_800 1 42#define IMAGE_800 1
46#define IMAGE_1280 2 43#define IMAGE_1280 2
47#define IMAGE_1600 3 44#define IMAGE_1600 3
48 45
49struct sd_gl860 { 46struct sd_gl860 {
50 u16 backlight; 47 u16 backlight;
@@ -75,10 +72,10 @@ struct sd {
75 int (*dev_camera_settings)(struct gspca_dev *); 72 int (*dev_camera_settings)(struct gspca_dev *);
76 73
77 u8 swapRB; 74 u8 swapRB;
78 u8 mirrorMask; 75 u8 mirrorMask;
79 u8 sensor; 76 u8 sensor;
80 s32 nbIm; 77 s32 nbIm;
81 s32 nbRightUp; 78 s32 nbRightUp;
82 u8 waitSet; 79 u8 waitSet;
83}; 80};
84 81
diff --git a/drivers/media/video/gspca/gspca.c b/drivers/media/video/gspca/gspca.c
index 678675bb3652..d951b0f0e053 100644
--- a/drivers/media/video/gspca/gspca.c
+++ b/drivers/media/video/gspca/gspca.c
@@ -201,7 +201,7 @@ static int alloc_and_submit_int_urb(struct gspca_dev *gspca_dev,
201 201
202 buffer_len = le16_to_cpu(ep->wMaxPacketSize); 202 buffer_len = le16_to_cpu(ep->wMaxPacketSize);
203 interval = ep->bInterval; 203 interval = ep->bInterval;
204 PDEBUG(D_PROBE, "found int in endpoint: 0x%x, " 204 PDEBUG(D_CONF, "found int in endpoint: 0x%x, "
205 "buffer_len=%u, interval=%u", 205 "buffer_len=%u, interval=%u",
206 ep->bEndpointAddress, buffer_len, interval); 206 ep->bEndpointAddress, buffer_len, interval);
207 207
@@ -226,7 +226,7 @@ static int alloc_and_submit_int_urb(struct gspca_dev *gspca_dev,
226 gspca_dev->int_urb = urb; 226 gspca_dev->int_urb = urb;
227 ret = usb_submit_urb(urb, GFP_KERNEL); 227 ret = usb_submit_urb(urb, GFP_KERNEL);
228 if (ret < 0) { 228 if (ret < 0) {
229 PDEBUG(D_ERR, "submit URB failed with error %i", ret); 229 PDEBUG(D_ERR, "submit int URB failed with error %i", ret);
230 goto error_submit; 230 goto error_submit;
231 } 231 }
232 return ret; 232 return ret;
@@ -294,19 +294,6 @@ static inline int gspca_input_connect(struct gspca_dev *dev)
294} 294}
295#endif 295#endif
296 296
297/* get the current input frame buffer */
298struct gspca_frame *gspca_get_i_frame(struct gspca_dev *gspca_dev)
299{
300 struct gspca_frame *frame;
301
302 frame = gspca_dev->cur_frame;
303 if ((frame->v4l2_buf.flags & BUF_ALL_FLAGS)
304 != V4L2_BUF_FLAG_QUEUED)
305 return NULL;
306 return frame;
307}
308EXPORT_SYMBOL(gspca_get_i_frame);
309
310/* 297/*
311 * fill a video frame from an URB and resubmit 298 * fill a video frame from an URB and resubmit
312 */ 299 */
@@ -439,20 +426,20 @@ void gspca_frame_add(struct gspca_dev *gspca_dev,
439 426
440 PDEBUG(D_PACK, "add t:%d l:%d", packet_type, len); 427 PDEBUG(D_PACK, "add t:%d l:%d", packet_type, len);
441 428
442 /* check the availability of the frame buffer */
443 frame = gspca_dev->cur_frame;
444 if ((frame->v4l2_buf.flags & BUF_ALL_FLAGS)
445 != V4L2_BUF_FLAG_QUEUED) {
446 gspca_dev->last_packet_type = DISCARD_PACKET;
447 return;
448 }
449
450 /* when start of a new frame, if the current frame buffer
451 * is not queued, discard the whole frame */
452 if (packet_type == FIRST_PACKET) { 429 if (packet_type == FIRST_PACKET) {
453 frame->data_end = frame->data; 430 i = atomic_read(&gspca_dev->fr_i);
431
432 /* if there are no queued buffer, discard the whole frame */
433 if (i == atomic_read(&gspca_dev->fr_q)) {
434 gspca_dev->last_packet_type = DISCARD_PACKET;
435 return;
436 }
437 j = gspca_dev->fr_queue[i];
438 frame = &gspca_dev->frame[j];
454 frame->v4l2_buf.timestamp = ktime_to_timeval(ktime_get()); 439 frame->v4l2_buf.timestamp = ktime_to_timeval(ktime_get());
455 frame->v4l2_buf.sequence = ++gspca_dev->sequence; 440 frame->v4l2_buf.sequence = ++gspca_dev->sequence;
441 gspca_dev->image = frame->data;
442 gspca_dev->image_len = 0;
456 } else if (gspca_dev->last_packet_type == DISCARD_PACKET) { 443 } else if (gspca_dev->last_packet_type == DISCARD_PACKET) {
457 if (packet_type == LAST_PACKET) 444 if (packet_type == LAST_PACKET)
458 gspca_dev->last_packet_type = packet_type; 445 gspca_dev->last_packet_type = packet_type;
@@ -461,34 +448,37 @@ void gspca_frame_add(struct gspca_dev *gspca_dev,
461 448
462 /* append the packet to the frame buffer */ 449 /* append the packet to the frame buffer */
463 if (len > 0) { 450 if (len > 0) {
464 if (frame->data_end - frame->data + len 451 if (gspca_dev->image_len + len > gspca_dev->frsz) {
465 > frame->v4l2_buf.length) { 452 PDEBUG(D_ERR|D_PACK, "frame overflow %d > %d",
466 PDEBUG(D_ERR|D_PACK, "frame overflow %zd > %d", 453 gspca_dev->image_len + len,
467 frame->data_end - frame->data + len, 454 gspca_dev->frsz);
468 frame->v4l2_buf.length);
469 packet_type = DISCARD_PACKET; 455 packet_type = DISCARD_PACKET;
470 } else { 456 } else {
471 memcpy(frame->data_end, data, len); 457 memcpy(gspca_dev->image + gspca_dev->image_len,
472 frame->data_end += len; 458 data, len);
459 gspca_dev->image_len += len;
473 } 460 }
474 } 461 }
475 gspca_dev->last_packet_type = packet_type; 462 gspca_dev->last_packet_type = packet_type;
476 463
477 /* if last packet, wake up the application and advance in the queue */ 464 /* if last packet, invalidate packet concatenation until
465 * next first packet, wake up the application and advance
466 * in the queue */
478 if (packet_type == LAST_PACKET) { 467 if (packet_type == LAST_PACKET) {
479 frame->v4l2_buf.bytesused = frame->data_end - frame->data; 468 i = atomic_read(&gspca_dev->fr_i);
480 frame->v4l2_buf.flags &= ~V4L2_BUF_FLAG_QUEUED;
481 frame->v4l2_buf.flags |= V4L2_BUF_FLAG_DONE;
482 wake_up_interruptible(&gspca_dev->wq); /* event = new frame */
483 i = (gspca_dev->fr_i + 1) % gspca_dev->nframes;
484 gspca_dev->fr_i = i;
485 PDEBUG(D_FRAM, "frame complete len:%d q:%d i:%d o:%d",
486 frame->v4l2_buf.bytesused,
487 gspca_dev->fr_q,
488 i,
489 gspca_dev->fr_o);
490 j = gspca_dev->fr_queue[i]; 469 j = gspca_dev->fr_queue[i];
491 gspca_dev->cur_frame = &gspca_dev->frame[j]; 470 frame = &gspca_dev->frame[j];
471 frame->v4l2_buf.bytesused = gspca_dev->image_len;
472 frame->v4l2_buf.flags = (frame->v4l2_buf.flags
473 | V4L2_BUF_FLAG_DONE)
474 & ~V4L2_BUF_FLAG_QUEUED;
475 i = (i + 1) % GSPCA_MAX_FRAMES;
476 atomic_set(&gspca_dev->fr_i, i);
477 wake_up_interruptible(&gspca_dev->wq); /* event = new frame */
478 PDEBUG(D_FRAM, "frame complete len:%d",
479 frame->v4l2_buf.bytesused);
480 gspca_dev->image = NULL;
481 gspca_dev->image_len = 0;
492 } 482 }
493} 483}
494EXPORT_SYMBOL(gspca_frame_add); 484EXPORT_SYMBOL(gspca_frame_add);
@@ -506,36 +496,6 @@ static int gspca_is_compressed(__u32 format)
506 return 0; 496 return 0;
507} 497}
508 498
509static void *rvmalloc(long size)
510{
511 void *mem;
512 unsigned long adr;
513
514 mem = vmalloc_32(size);
515 if (mem != NULL) {
516 adr = (unsigned long) mem;
517 while (size > 0) {
518 SetPageReserved(vmalloc_to_page((void *) adr));
519 adr += PAGE_SIZE;
520 size -= PAGE_SIZE;
521 }
522 }
523 return mem;
524}
525
526static void rvfree(void *mem, long size)
527{
528 unsigned long adr;
529
530 adr = (unsigned long) mem;
531 while (size > 0) {
532 ClearPageReserved(vmalloc_to_page((void *) adr));
533 adr += PAGE_SIZE;
534 size -= PAGE_SIZE;
535 }
536 vfree(mem);
537}
538
539static int frame_alloc(struct gspca_dev *gspca_dev, 499static int frame_alloc(struct gspca_dev *gspca_dev,
540 unsigned int count) 500 unsigned int count)
541{ 501{
@@ -548,9 +508,9 @@ static int frame_alloc(struct gspca_dev *gspca_dev,
548 PDEBUG(D_STREAM, "frame alloc frsz: %d", frsz); 508 PDEBUG(D_STREAM, "frame alloc frsz: %d", frsz);
549 frsz = PAGE_ALIGN(frsz); 509 frsz = PAGE_ALIGN(frsz);
550 gspca_dev->frsz = frsz; 510 gspca_dev->frsz = frsz;
551 if (count > GSPCA_MAX_FRAMES) 511 if (count >= GSPCA_MAX_FRAMES)
552 count = GSPCA_MAX_FRAMES; 512 count = GSPCA_MAX_FRAMES - 1;
553 gspca_dev->frbuf = rvmalloc(frsz * count); 513 gspca_dev->frbuf = vmalloc_32(frsz * count);
554 if (!gspca_dev->frbuf) { 514 if (!gspca_dev->frbuf) {
555 err("frame alloc failed"); 515 err("frame alloc failed");
556 return -ENOMEM; 516 return -ENOMEM;
@@ -565,14 +525,12 @@ static int frame_alloc(struct gspca_dev *gspca_dev,
565 frame->v4l2_buf.length = frsz; 525 frame->v4l2_buf.length = frsz;
566 frame->v4l2_buf.memory = gspca_dev->memory; 526 frame->v4l2_buf.memory = gspca_dev->memory;
567 frame->v4l2_buf.sequence = 0; 527 frame->v4l2_buf.sequence = 0;
568 frame->data = frame->data_end = 528 frame->data = gspca_dev->frbuf + i * frsz;
569 gspca_dev->frbuf + i * frsz;
570 frame->v4l2_buf.m.offset = i * frsz; 529 frame->v4l2_buf.m.offset = i * frsz;
571 } 530 }
572 gspca_dev->fr_i = gspca_dev->fr_o = gspca_dev->fr_q = 0; 531 atomic_set(&gspca_dev->fr_q, 0);
573 gspca_dev->cur_frame = &gspca_dev->frame[0]; 532 atomic_set(&gspca_dev->fr_i, 0);
574 gspca_dev->last_packet_type = DISCARD_PACKET; 533 gspca_dev->fr_o = 0;
575 gspca_dev->sequence = 0;
576 return 0; 534 return 0;
577} 535}
578 536
@@ -582,8 +540,7 @@ static void frame_free(struct gspca_dev *gspca_dev)
582 540
583 PDEBUG(D_STREAM, "frame free"); 541 PDEBUG(D_STREAM, "frame free");
584 if (gspca_dev->frbuf != NULL) { 542 if (gspca_dev->frbuf != NULL) {
585 rvfree(gspca_dev->frbuf, 543 vfree(gspca_dev->frbuf);
586 gspca_dev->nframes * gspca_dev->frsz);
587 gspca_dev->frbuf = NULL; 544 gspca_dev->frbuf = NULL;
588 for (i = 0; i < gspca_dev->nframes; i++) 545 for (i = 0; i < gspca_dev->nframes; i++)
589 gspca_dev->frame[i].data = NULL; 546 gspca_dev->frame[i].data = NULL;
@@ -683,12 +640,16 @@ static struct usb_host_endpoint *get_ep(struct gspca_dev *gspca_dev)
683 : USB_ENDPOINT_XFER_ISOC; 640 : USB_ENDPOINT_XFER_ISOC;
684 i = gspca_dev->alt; /* previous alt setting */ 641 i = gspca_dev->alt; /* previous alt setting */
685 if (gspca_dev->cam.reverse_alts) { 642 if (gspca_dev->cam.reverse_alts) {
643 if (gspca_dev->audio)
644 i++;
686 while (++i < gspca_dev->nbalt) { 645 while (++i < gspca_dev->nbalt) {
687 ep = alt_xfer(&intf->altsetting[i], xfer); 646 ep = alt_xfer(&intf->altsetting[i], xfer);
688 if (ep) 647 if (ep)
689 break; 648 break;
690 } 649 }
691 } else { 650 } else {
651 if (gspca_dev->audio)
652 i--;
692 while (--i >= 0) { 653 while (--i >= 0) {
693 ep = alt_xfer(&intf->altsetting[i], xfer); 654 ep = alt_xfer(&intf->altsetting[i], xfer);
694 if (ep) 655 if (ep)
@@ -811,6 +772,12 @@ static int gspca_init_transfer(struct gspca_dev *gspca_dev)
811 goto out; 772 goto out;
812 } 773 }
813 774
775 /* reset the streaming variables */
776 gspca_dev->image = NULL;
777 gspca_dev->image_len = 0;
778 gspca_dev->last_packet_type = DISCARD_PACKET;
779 gspca_dev->sequence = 0;
780
814 gspca_dev->usb_err = 0; 781 gspca_dev->usb_err = 0;
815 782
816 /* set the higher alternate setting and 783 /* set the higher alternate setting and
@@ -1433,34 +1400,6 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
1433 return ret; 1400 return ret;
1434} 1401}
1435 1402
1436/*fixme: have an audio flag in gspca_dev?*/
1437static int vidioc_s_audio(struct file *file, void *priv,
1438 struct v4l2_audio *audio)
1439{
1440 if (audio->index != 0)
1441 return -EINVAL;
1442 return 0;
1443}
1444
1445static int vidioc_g_audio(struct file *file, void *priv,
1446 struct v4l2_audio *audio)
1447{
1448 strcpy(audio->name, "Microphone");
1449 return 0;
1450}
1451
1452static int vidioc_enumaudio(struct file *file, void *priv,
1453 struct v4l2_audio *audio)
1454{
1455 if (audio->index != 0)
1456 return -EINVAL;
1457
1458 strcpy(audio->name, "Microphone");
1459 audio->capability = 0;
1460 audio->mode = 0;
1461 return 0;
1462}
1463
1464static int vidioc_querymenu(struct file *file, void *priv, 1403static int vidioc_querymenu(struct file *file, void *priv,
1465 struct v4l2_querymenu *qmenu) 1404 struct v4l2_querymenu *qmenu)
1466{ 1405{
@@ -1504,7 +1443,8 @@ static int vidioc_reqbufs(struct file *file, void *priv,
1504 struct gspca_dev *gspca_dev = priv; 1443 struct gspca_dev *gspca_dev = priv;
1505 int i, ret = 0, streaming; 1444 int i, ret = 0, streaming;
1506 1445
1507 switch (rb->memory) { 1446 i = rb->memory; /* (avoid compilation warning) */
1447 switch (i) {
1508 case GSPCA_MEMORY_READ: /* (internal call) */ 1448 case GSPCA_MEMORY_READ: /* (internal call) */
1509 case V4L2_MEMORY_MMAP: 1449 case V4L2_MEMORY_MMAP:
1510 case V4L2_MEMORY_USERPTR: 1450 case V4L2_MEMORY_USERPTR:
@@ -1626,7 +1566,7 @@ static int vidioc_streamoff(struct file *file, void *priv,
1626 enum v4l2_buf_type buf_type) 1566 enum v4l2_buf_type buf_type)
1627{ 1567{
1628 struct gspca_dev *gspca_dev = priv; 1568 struct gspca_dev *gspca_dev = priv;
1629 int i, ret; 1569 int ret;
1630 1570
1631 if (buf_type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 1571 if (buf_type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1632 return -EINVAL; 1572 return -EINVAL;
@@ -1650,12 +1590,10 @@ static int vidioc_streamoff(struct file *file, void *priv,
1650 gspca_stream_off(gspca_dev); 1590 gspca_stream_off(gspca_dev);
1651 mutex_unlock(&gspca_dev->usb_lock); 1591 mutex_unlock(&gspca_dev->usb_lock);
1652 1592
1653 /* empty the application queues */ 1593 /* empty the transfer queues */
1654 for (i = 0; i < gspca_dev->nframes; i++) 1594 atomic_set(&gspca_dev->fr_q, 0);
1655 gspca_dev->frame[i].v4l2_buf.flags &= ~BUF_ALL_FLAGS; 1595 atomic_set(&gspca_dev->fr_i, 0);
1656 gspca_dev->fr_i = gspca_dev->fr_o = gspca_dev->fr_q = 0; 1596 gspca_dev->fr_o = 0;
1657 gspca_dev->last_packet_type = DISCARD_PACKET;
1658 gspca_dev->sequence = 0;
1659 ret = 0; 1597 ret = 0;
1660out: 1598out:
1661 mutex_unlock(&gspca_dev->queue_lock); 1599 mutex_unlock(&gspca_dev->queue_lock);
@@ -1732,7 +1670,7 @@ static int vidioc_s_parm(struct file *filp, void *priv,
1732 int n; 1670 int n;
1733 1671
1734 n = parm->parm.capture.readbuffers; 1672 n = parm->parm.capture.readbuffers;
1735 if (n == 0 || n > GSPCA_MAX_FRAMES) 1673 if (n == 0 || n >= GSPCA_MAX_FRAMES)
1736 parm->parm.capture.readbuffers = gspca_dev->nbufread; 1674 parm->parm.capture.readbuffers = gspca_dev->nbufread;
1737 else 1675 else
1738 gspca_dev->nbufread = n; 1676 gspca_dev->nbufread = n;
@@ -1755,49 +1693,6 @@ static int vidioc_s_parm(struct file *filp, void *priv,
1755 return 0; 1693 return 0;
1756} 1694}
1757 1695
1758#ifdef CONFIG_VIDEO_V4L1_COMPAT
1759static int vidiocgmbuf(struct file *file, void *priv,
1760 struct video_mbuf *mbuf)
1761{
1762 struct gspca_dev *gspca_dev = file->private_data;
1763 int i;
1764
1765 PDEBUG(D_STREAM, "cgmbuf");
1766 if (gspca_dev->nframes == 0) {
1767 int ret;
1768
1769 {
1770 struct v4l2_format fmt;
1771
1772 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1773 i = gspca_dev->cam.nmodes - 1; /* highest mode */
1774 fmt.fmt.pix.width = gspca_dev->cam.cam_mode[i].width;
1775 fmt.fmt.pix.height = gspca_dev->cam.cam_mode[i].height;
1776 fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_BGR24;
1777 ret = vidioc_s_fmt_vid_cap(file, priv, &fmt);
1778 if (ret != 0)
1779 return ret;
1780 }
1781 {
1782 struct v4l2_requestbuffers rb;
1783
1784 memset(&rb, 0, sizeof rb);
1785 rb.count = 4;
1786 rb.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1787 rb.memory = V4L2_MEMORY_MMAP;
1788 ret = vidioc_reqbufs(file, priv, &rb);
1789 if (ret != 0)
1790 return ret;
1791 }
1792 }
1793 mbuf->frames = gspca_dev->nframes;
1794 mbuf->size = gspca_dev->frsz * gspca_dev->nframes;
1795 for (i = 0; i < mbuf->frames; i++)
1796 mbuf->offsets[i] = gspca_dev->frame[i].v4l2_buf.m.offset;
1797 return 0;
1798}
1799#endif
1800
1801static int dev_mmap(struct file *file, struct vm_area_struct *vma) 1696static int dev_mmap(struct file *file, struct vm_area_struct *vma)
1802{ 1697{
1803 struct gspca_dev *gspca_dev = file->private_data; 1698 struct gspca_dev *gspca_dev = file->private_data;
@@ -1838,12 +1733,7 @@ static int dev_mmap(struct file *file, struct vm_area_struct *vma)
1838 ret = -EINVAL; 1733 ret = -EINVAL;
1839 goto out; 1734 goto out;
1840 } 1735 }
1841#ifdef CONFIG_VIDEO_V4L1_COMPAT 1736 if (size != frame->v4l2_buf.length) {
1842 /* v4l1 maps all the buffers */
1843 if (i != 0
1844 || size != frame->v4l2_buf.length * gspca_dev->nframes)
1845#endif
1846 if (size != frame->v4l2_buf.length) {
1847 PDEBUG(D_STREAM, "mmap bad size"); 1737 PDEBUG(D_STREAM, "mmap bad size");
1848 ret = -EINVAL; 1738 ret = -EINVAL;
1849 goto out; 1739 goto out;
@@ -1883,21 +1773,17 @@ out:
1883static int frame_wait(struct gspca_dev *gspca_dev, 1773static int frame_wait(struct gspca_dev *gspca_dev,
1884 int nonblock_ing) 1774 int nonblock_ing)
1885{ 1775{
1886 struct gspca_frame *frame; 1776 int i, ret;
1887 int i, j, ret;
1888 1777
1889 /* check if a frame is ready */ 1778 /* check if a frame is ready */
1890 i = gspca_dev->fr_o; 1779 i = gspca_dev->fr_o;
1891 j = gspca_dev->fr_queue[i]; 1780 if (i == atomic_read(&gspca_dev->fr_i)) {
1892 frame = &gspca_dev->frame[j];
1893
1894 if (!(frame->v4l2_buf.flags & V4L2_BUF_FLAG_DONE)) {
1895 if (nonblock_ing) 1781 if (nonblock_ing)
1896 return -EAGAIN; 1782 return -EAGAIN;
1897 1783
1898 /* wait till a frame is ready */ 1784 /* wait till a frame is ready */
1899 ret = wait_event_interruptible_timeout(gspca_dev->wq, 1785 ret = wait_event_interruptible_timeout(gspca_dev->wq,
1900 (frame->v4l2_buf.flags & V4L2_BUF_FLAG_DONE) || 1786 i != atomic_read(&gspca_dev->fr_i) ||
1901 !gspca_dev->streaming || !gspca_dev->present, 1787 !gspca_dev->streaming || !gspca_dev->present,
1902 msecs_to_jiffies(3000)); 1788 msecs_to_jiffies(3000));
1903 if (ret < 0) 1789 if (ret < 0)
@@ -1906,11 +1792,7 @@ static int frame_wait(struct gspca_dev *gspca_dev,
1906 return -EIO; 1792 return -EIO;
1907 } 1793 }
1908 1794
1909 gspca_dev->fr_o = (i + 1) % gspca_dev->nframes; 1795 gspca_dev->fr_o = (i + 1) % GSPCA_MAX_FRAMES;
1910 PDEBUG(D_FRAM, "frame wait q:%d i:%d o:%d",
1911 gspca_dev->fr_q,
1912 gspca_dev->fr_i,
1913 gspca_dev->fr_o);
1914 1796
1915 if (gspca_dev->sd_desc->dq_callback) { 1797 if (gspca_dev->sd_desc->dq_callback) {
1916 mutex_lock(&gspca_dev->usb_lock); 1798 mutex_lock(&gspca_dev->usb_lock);
@@ -1919,7 +1801,7 @@ static int frame_wait(struct gspca_dev *gspca_dev,
1919 gspca_dev->sd_desc->dq_callback(gspca_dev); 1801 gspca_dev->sd_desc->dq_callback(gspca_dev);
1920 mutex_unlock(&gspca_dev->usb_lock); 1802 mutex_unlock(&gspca_dev->usb_lock);
1921 } 1803 }
1922 return j; 1804 return gspca_dev->fr_queue[i];
1923} 1805}
1924 1806
1925/* 1807/*
@@ -2024,15 +1906,9 @@ static int vidioc_qbuf(struct file *file, void *priv,
2024 } 1906 }
2025 1907
2026 /* put the buffer in the 'queued' queue */ 1908 /* put the buffer in the 'queued' queue */
2027 i = gspca_dev->fr_q; 1909 i = atomic_read(&gspca_dev->fr_q);
2028 gspca_dev->fr_queue[i] = index; 1910 gspca_dev->fr_queue[i] = index;
2029 if (gspca_dev->fr_i == i) 1911 atomic_set(&gspca_dev->fr_q, (i + 1) % GSPCA_MAX_FRAMES);
2030 gspca_dev->cur_frame = frame;
2031 gspca_dev->fr_q = (i + 1) % gspca_dev->nframes;
2032 PDEBUG(D_FRAM, "qbuf q:%d i:%d o:%d",
2033 gspca_dev->fr_q,
2034 gspca_dev->fr_i,
2035 gspca_dev->fr_o);
2036 1912
2037 v4l2_buf->flags |= V4L2_BUF_FLAG_QUEUED; 1913 v4l2_buf->flags |= V4L2_BUF_FLAG_QUEUED;
2038 v4l2_buf->flags &= ~V4L2_BUF_FLAG_DONE; 1914 v4l2_buf->flags &= ~V4L2_BUF_FLAG_DONE;
@@ -2088,7 +1964,7 @@ static int read_alloc(struct gspca_dev *gspca_dev,
2088static unsigned int dev_poll(struct file *file, poll_table *wait) 1964static unsigned int dev_poll(struct file *file, poll_table *wait)
2089{ 1965{
2090 struct gspca_dev *gspca_dev = file->private_data; 1966 struct gspca_dev *gspca_dev = file->private_data;
2091 int i, ret; 1967 int ret;
2092 1968
2093 PDEBUG(D_FRAM, "poll"); 1969 PDEBUG(D_FRAM, "poll");
2094 1970
@@ -2106,11 +1982,9 @@ static unsigned int dev_poll(struct file *file, poll_table *wait)
2106 if (mutex_lock_interruptible(&gspca_dev->queue_lock) != 0) 1982 if (mutex_lock_interruptible(&gspca_dev->queue_lock) != 0)
2107 return POLLERR; 1983 return POLLERR;
2108 1984
2109 /* check the next incoming buffer */ 1985 /* check if an image has been received */
2110 i = gspca_dev->fr_o; 1986 if (gspca_dev->fr_o != atomic_read(&gspca_dev->fr_i))
2111 i = gspca_dev->fr_queue[i]; 1987 ret = POLLIN | POLLRDNORM; /* yes */
2112 if (gspca_dev->frame[i].v4l2_buf.flags & V4L2_BUF_FLAG_DONE)
2113 ret = POLLIN | POLLRDNORM; /* something to read */
2114 else 1988 else
2115 ret = 0; 1989 ret = 0;
2116 mutex_unlock(&gspca_dev->queue_lock); 1990 mutex_unlock(&gspca_dev->queue_lock);
@@ -2214,9 +2088,6 @@ static const struct v4l2_ioctl_ops dev_ioctl_ops = {
2214 .vidioc_queryctrl = vidioc_queryctrl, 2088 .vidioc_queryctrl = vidioc_queryctrl,
2215 .vidioc_g_ctrl = vidioc_g_ctrl, 2089 .vidioc_g_ctrl = vidioc_g_ctrl,
2216 .vidioc_s_ctrl = vidioc_s_ctrl, 2090 .vidioc_s_ctrl = vidioc_s_ctrl,
2217 .vidioc_g_audio = vidioc_g_audio,
2218 .vidioc_s_audio = vidioc_s_audio,
2219 .vidioc_enumaudio = vidioc_enumaudio,
2220 .vidioc_querymenu = vidioc_querymenu, 2091 .vidioc_querymenu = vidioc_querymenu,
2221 .vidioc_enum_input = vidioc_enum_input, 2092 .vidioc_enum_input = vidioc_enum_input,
2222 .vidioc_g_input = vidioc_g_input, 2093 .vidioc_g_input = vidioc_g_input,
@@ -2235,9 +2106,6 @@ static const struct v4l2_ioctl_ops dev_ioctl_ops = {
2235 .vidioc_s_register = vidioc_s_register, 2106 .vidioc_s_register = vidioc_s_register,
2236#endif 2107#endif
2237 .vidioc_g_chip_ident = vidioc_g_chip_ident, 2108 .vidioc_g_chip_ident = vidioc_g_chip_ident,
2238#ifdef CONFIG_VIDEO_V4L1_COMPAT
2239 .vidiocgmbuf = vidiocgmbuf,
2240#endif
2241}; 2109};
2242 2110
2243static struct video_device gspca_template = { 2111static struct video_device gspca_template = {
@@ -2253,31 +2121,18 @@ static struct video_device gspca_template = {
2253 * This function must be called by the sub-driver when it is 2121 * This function must be called by the sub-driver when it is
2254 * called for probing a new device. 2122 * called for probing a new device.
2255 */ 2123 */
2256int gspca_dev_probe(struct usb_interface *intf, 2124int gspca_dev_probe2(struct usb_interface *intf,
2257 const struct usb_device_id *id, 2125 const struct usb_device_id *id,
2258 const struct sd_desc *sd_desc, 2126 const struct sd_desc *sd_desc,
2259 int dev_size, 2127 int dev_size,
2260 struct module *module) 2128 struct module *module)
2261{ 2129{
2262 struct usb_interface_descriptor *interface;
2263 struct gspca_dev *gspca_dev; 2130 struct gspca_dev *gspca_dev;
2264 struct usb_device *dev = interface_to_usbdev(intf); 2131 struct usb_device *dev = interface_to_usbdev(intf);
2265 int ret; 2132 int ret;
2266 2133
2267 PDEBUG(D_PROBE, "probing %04x:%04x", id->idVendor, id->idProduct); 2134 PDEBUG(D_PROBE, "probing %04x:%04x", id->idVendor, id->idProduct);
2268 2135
2269 /* we don't handle multi-config cameras */
2270 if (dev->descriptor.bNumConfigurations != 1) {
2271 PDEBUG(D_ERR, "Too many config");
2272 return -ENODEV;
2273 }
2274
2275 /* the USB video interface must be the first one */
2276 interface = &intf->cur_altsetting->desc;
2277 if (dev->config->desc.bNumInterfaces != 1 &&
2278 interface->bInterfaceNumber != 0)
2279 return -ENODEV;
2280
2281 /* create the device */ 2136 /* create the device */
2282 if (dev_size < sizeof *gspca_dev) 2137 if (dev_size < sizeof *gspca_dev)
2283 dev_size = sizeof *gspca_dev; 2138 dev_size = sizeof *gspca_dev;
@@ -2293,8 +2148,26 @@ int gspca_dev_probe(struct usb_interface *intf,
2293 goto out; 2148 goto out;
2294 } 2149 }
2295 gspca_dev->dev = dev; 2150 gspca_dev->dev = dev;
2296 gspca_dev->iface = interface->bInterfaceNumber; 2151 gspca_dev->iface = intf->cur_altsetting->desc.bInterfaceNumber;
2297 gspca_dev->nbalt = intf->num_altsetting; 2152 gspca_dev->nbalt = intf->num_altsetting;
2153
2154 /* check if any audio device */
2155 if (dev->config->desc.bNumInterfaces != 1) {
2156 int i;
2157 struct usb_interface *intf2;
2158
2159 for (i = 0; i < dev->config->desc.bNumInterfaces; i++) {
2160 intf2 = dev->config->interface[i];
2161 if (intf2 != NULL
2162 && intf2->altsetting != NULL
2163 && intf2->altsetting->desc.bInterfaceClass ==
2164 USB_CLASS_AUDIO) {
2165 gspca_dev->audio = 1;
2166 break;
2167 }
2168 }
2169 }
2170
2298 gspca_dev->sd_desc = sd_desc; 2171 gspca_dev->sd_desc = sd_desc;
2299 gspca_dev->nbufread = 2; 2172 gspca_dev->nbufread = 2;
2300 gspca_dev->empty_packet = -1; /* don't check the empty packets */ 2173 gspca_dev->empty_packet = -1; /* don't check the empty packets */
@@ -2345,6 +2218,31 @@ out:
2345 kfree(gspca_dev); 2218 kfree(gspca_dev);
2346 return ret; 2219 return ret;
2347} 2220}
2221EXPORT_SYMBOL(gspca_dev_probe2);
2222
2223/* same function as the previous one, but check the interface */
2224int gspca_dev_probe(struct usb_interface *intf,
2225 const struct usb_device_id *id,
2226 const struct sd_desc *sd_desc,
2227 int dev_size,
2228 struct module *module)
2229{
2230 struct usb_device *dev = interface_to_usbdev(intf);
2231
2232 /* we don't handle multi-config cameras */
2233 if (dev->descriptor.bNumConfigurations != 1) {
2234 PDEBUG(D_ERR, "%04x:%04x too many config",
2235 id->idVendor, id->idProduct);
2236 return -ENODEV;
2237 }
2238
2239 /* the USB video interface must be the first one */
2240 if (dev->config->desc.bNumInterfaces != 1
2241 && intf->cur_altsetting->desc.bInterfaceNumber != 0)
2242 return -ENODEV;
2243
2244 return gspca_dev_probe2(intf, id, sd_desc, dev_size, module);
2245}
2348EXPORT_SYMBOL(gspca_dev_probe); 2246EXPORT_SYMBOL(gspca_dev_probe);
2349 2247
2350/* 2248/*
diff --git a/drivers/media/video/gspca/gspca.h b/drivers/media/video/gspca/gspca.h
index 8b963dfae861..b749c36d9f7e 100644
--- a/drivers/media/video/gspca/gspca.h
+++ b/drivers/media/video/gspca/gspca.h
@@ -7,7 +7,6 @@
7#include <linux/videodev2.h> 7#include <linux/videodev2.h>
8#include <media/v4l2-common.h> 8#include <media/v4l2-common.h>
9#include <linux/mutex.h> 9#include <linux/mutex.h>
10#include <linux/slab.h>
11 10
12/* compilation option */ 11/* compilation option */
13#define GSPCA_DEBUG 1 12#define GSPCA_DEBUG 1
@@ -148,7 +147,6 @@ enum gspca_packet_type {
148 147
149struct gspca_frame { 148struct gspca_frame {
150 __u8 *data; /* frame buffer */ 149 __u8 *data; /* frame buffer */
151 __u8 *data_end; /* end of frame while filling */
152 int vma_use_count; 150 int vma_use_count;
153 struct v4l2_buffer v4l2_buf; 151 struct v4l2_buffer v4l2_buf;
154}; 152};
@@ -177,13 +175,14 @@ struct gspca_dev {
177 175
178 __u8 *frbuf; /* buffer for nframes */ 176 __u8 *frbuf; /* buffer for nframes */
179 struct gspca_frame frame[GSPCA_MAX_FRAMES]; 177 struct gspca_frame frame[GSPCA_MAX_FRAMES];
180 struct gspca_frame *cur_frame; /* frame beeing filled */ 178 u8 *image; /* image beeing filled */
181 __u32 frsz; /* frame size */ 179 __u32 frsz; /* frame size */
182 char nframes; /* number of frames */ 180 u32 image_len; /* current length of image */
183 char fr_i; /* frame being filled */ 181 atomic_t fr_q; /* next frame to queue */
184 char fr_q; /* next frame to queue */ 182 atomic_t fr_i; /* frame being filled */
185 char fr_o; /* next frame to dequeue */
186 signed char fr_queue[GSPCA_MAX_FRAMES]; /* frame queue */ 183 signed char fr_queue[GSPCA_MAX_FRAMES]; /* frame queue */
184 char nframes; /* number of frames */
185 u8 fr_o; /* next frame to dequeue */
187 __u8 last_packet_type; 186 __u8 last_packet_type;
188 __s8 empty_packet; /* if (-1) don't check empty packets */ 187 __s8 empty_packet; /* if (-1) don't check empty packets */
189 __u8 streaming; 188 __u8 streaming;
@@ -199,6 +198,7 @@ struct gspca_dev {
199 struct mutex read_lock; /* read protection */ 198 struct mutex read_lock; /* read protection */
200 struct mutex queue_lock; /* ISOC queue protection */ 199 struct mutex queue_lock; /* ISOC queue protection */
201 int usb_err; /* USB error - protected by usb_lock */ 200 int usb_err; /* USB error - protected by usb_lock */
201 u16 pkt_size; /* ISOC packet size */
202#ifdef CONFIG_PM 202#ifdef CONFIG_PM
203 char frozen; /* suspend - resume */ 203 char frozen; /* suspend - resume */
204#endif 204#endif
@@ -209,7 +209,7 @@ struct gspca_dev {
209 __u8 iface; /* USB interface number */ 209 __u8 iface; /* USB interface number */
210 __u8 alt; /* USB alternate setting */ 210 __u8 alt; /* USB alternate setting */
211 __u8 nbalt; /* number of USB alternate settings */ 211 __u8 nbalt; /* number of USB alternate settings */
212 u16 pkt_size; /* ISOC packet size */ 212 u8 audio; /* presence of audio device */
213}; 213};
214 214
215int gspca_dev_probe(struct usb_interface *intf, 215int gspca_dev_probe(struct usb_interface *intf,
@@ -217,12 +217,16 @@ int gspca_dev_probe(struct usb_interface *intf,
217 const struct sd_desc *sd_desc, 217 const struct sd_desc *sd_desc,
218 int dev_size, 218 int dev_size,
219 struct module *module); 219 struct module *module);
220int gspca_dev_probe2(struct usb_interface *intf,
221 const struct usb_device_id *id,
222 const struct sd_desc *sd_desc,
223 int dev_size,
224 struct module *module);
220void gspca_disconnect(struct usb_interface *intf); 225void gspca_disconnect(struct usb_interface *intf);
221void gspca_frame_add(struct gspca_dev *gspca_dev, 226void gspca_frame_add(struct gspca_dev *gspca_dev,
222 enum gspca_packet_type packet_type, 227 enum gspca_packet_type packet_type,
223 const u8 *data, 228 const u8 *data,
224 int len); 229 int len);
225struct gspca_frame *gspca_get_i_frame(struct gspca_dev *gspca_dev);
226#ifdef CONFIG_PM 230#ifdef CONFIG_PM
227int gspca_suspend(struct usb_interface *intf, pm_message_t message); 231int gspca_suspend(struct usb_interface *intf, pm_message_t message);
228int gspca_resume(struct usb_interface *intf); 232int gspca_resume(struct usb_interface *intf);
diff --git a/drivers/media/video/gspca/jeilinj.c b/drivers/media/video/gspca/jeilinj.c
index 84ecd56c6470..12d9cf4caba2 100644
--- a/drivers/media/video/gspca/jeilinj.c
+++ b/drivers/media/video/gspca/jeilinj.c
@@ -50,7 +50,7 @@ struct sd {
50 struct workqueue_struct *work_thread; 50 struct workqueue_struct *work_thread;
51 u8 quality; /* image quality */ 51 u8 quality; /* image quality */
52 u8 jpegqual; /* webcam quality */ 52 u8 jpegqual; /* webcam quality */
53 u8 *jpeg_hdr; 53 u8 jpeg_hdr[JPEG_HDR_SZ];
54}; 54};
55 55
56 struct jlj_command { 56 struct jlj_command {
@@ -282,7 +282,6 @@ static void sd_stop0(struct gspca_dev *gspca_dev)
282 destroy_workqueue(dev->work_thread); 282 destroy_workqueue(dev->work_thread);
283 dev->work_thread = NULL; 283 dev->work_thread = NULL;
284 mutex_lock(&gspca_dev->usb_lock); 284 mutex_lock(&gspca_dev->usb_lock);
285 kfree(dev->jpeg_hdr);
286} 285}
287 286
288/* this function is called at probe and resume time */ 287/* this function is called at probe and resume time */
@@ -298,9 +297,6 @@ static int sd_start(struct gspca_dev *gspca_dev)
298 int ret; 297 int ret;
299 298
300 /* create the JPEG header */ 299 /* create the JPEG header */
301 dev->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL);
302 if (dev->jpeg_hdr == NULL)
303 return -ENOMEM;
304 jpeg_define(dev->jpeg_hdr, gspca_dev->height, gspca_dev->width, 300 jpeg_define(dev->jpeg_hdr, gspca_dev->height, gspca_dev->width,
305 0x21); /* JPEG 422 */ 301 0x21); /* JPEG 422 */
306 jpeg_set_qual(dev->jpeg_hdr, dev->quality); 302 jpeg_set_qual(dev->jpeg_hdr, dev->quality);
diff --git a/drivers/media/video/gspca/m5602/m5602_bridge.h b/drivers/media/video/gspca/m5602/m5602_bridge.h
index 1127a405c9b2..51af3ee3ab85 100644
--- a/drivers/media/video/gspca/m5602/m5602_bridge.h
+++ b/drivers/media/video/gspca/m5602/m5602_bridge.h
@@ -19,6 +19,7 @@
19#ifndef M5602_BRIDGE_H_ 19#ifndef M5602_BRIDGE_H_
20#define M5602_BRIDGE_H_ 20#define M5602_BRIDGE_H_
21 21
22#include <linux/slab.h>
22#include "gspca.h" 23#include "gspca.h"
23 24
24#define MODULE_NAME "ALi m5602" 25#define MODULE_NAME "ALi m5602"
diff --git a/drivers/media/video/gspca/m5602/m5602_core.c b/drivers/media/video/gspca/m5602/m5602_core.c
index 4294c75e3b11..b073d66acd04 100644
--- a/drivers/media/video/gspca/m5602/m5602_core.c
+++ b/drivers/media/video/gspca/m5602/m5602_core.c
@@ -305,30 +305,23 @@ static void m5602_urb_complete(struct gspca_dev *gspca_dev,
305 sd->frame_count); 305 sd->frame_count);
306 306
307 } else { 307 } else {
308 struct gspca_frame *frame;
309 int cur_frame_len; 308 int cur_frame_len;
310 309
311 frame = gspca_get_i_frame(gspca_dev); 310 cur_frame_len = gspca_dev->image_len;
312 if (frame == NULL) {
313 gspca_dev->last_packet_type = DISCARD_PACKET;
314 return;
315 }
316
317 cur_frame_len = frame->data_end - frame->data;
318 /* Remove urb header */ 311 /* Remove urb header */
319 data += 4; 312 data += 4;
320 len -= 4; 313 len -= 4;
321 314
322 if (cur_frame_len + len <= frame->v4l2_buf.length) { 315 if (cur_frame_len + len <= gspca_dev->frsz) {
323 PDEBUG(D_FRAM, "Continuing frame %d copying %d bytes", 316 PDEBUG(D_FRAM, "Continuing frame %d copying %d bytes",
324 sd->frame_count, len); 317 sd->frame_count, len);
325 318
326 gspca_frame_add(gspca_dev, INTER_PACKET, 319 gspca_frame_add(gspca_dev, INTER_PACKET,
327 data, len); 320 data, len);
328 } else if (frame->v4l2_buf.length - cur_frame_len > 0) { 321 } else {
329 /* Add the remaining data up to frame size */ 322 /* Add the remaining data up to frame size */
330 gspca_frame_add(gspca_dev, INTER_PACKET, data, 323 gspca_frame_add(gspca_dev, INTER_PACKET, data,
331 frame->v4l2_buf.length - cur_frame_len); 324 gspca_dev->frsz - cur_frame_len);
332 } 325 }
333 } 326 }
334} 327}
diff --git a/drivers/media/video/gspca/m5602/m5602_s5k83a.c b/drivers/media/video/gspca/m5602/m5602_s5k83a.c
index 6b3be4fa2c06..fbd91545497a 100644
--- a/drivers/media/video/gspca/m5602/m5602_s5k83a.c
+++ b/drivers/media/video/gspca/m5602/m5602_s5k83a.c
@@ -17,7 +17,6 @@
17 */ 17 */
18 18
19#include <linux/kthread.h> 19#include <linux/kthread.h>
20#include <linux/slab.h>
21#include "m5602_s5k83a.h" 20#include "m5602_s5k83a.h"
22 21
23static int s5k83a_set_gain(struct gspca_dev *gspca_dev, __s32 val); 22static int s5k83a_set_gain(struct gspca_dev *gspca_dev, __s32 val);
diff --git a/drivers/media/video/gspca/mars.c b/drivers/media/video/gspca/mars.c
index 3d9229e22b25..031f7195ce0d 100644
--- a/drivers/media/video/gspca/mars.c
+++ b/drivers/media/video/gspca/mars.c
@@ -41,7 +41,7 @@ struct sd {
41#define QUALITY_MAX 70 41#define QUALITY_MAX 70
42#define QUALITY_DEF 50 42#define QUALITY_DEF 50
43 43
44 u8 *jpeg_hdr; 44 u8 jpeg_hdr[JPEG_HDR_SZ];
45}; 45};
46 46
47/* V4L2 controls supported by the driver */ 47/* V4L2 controls supported by the driver */
@@ -200,9 +200,6 @@ static int sd_start(struct gspca_dev *gspca_dev)
200 int i; 200 int i;
201 201
202 /* create the JPEG header */ 202 /* create the JPEG header */
203 sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL);
204 if (!sd->jpeg_hdr)
205 return -ENOMEM;
206 jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width, 203 jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
207 0x21); /* JPEG 422 */ 204 0x21); /* JPEG 422 */
208 jpeg_set_qual(sd->jpeg_hdr, sd->quality); 205 jpeg_set_qual(sd->jpeg_hdr, sd->quality);
@@ -317,13 +314,6 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
317 PDEBUG(D_ERR, "Camera Stop failed"); 314 PDEBUG(D_ERR, "Camera Stop failed");
318} 315}
319 316
320static void sd_stop0(struct gspca_dev *gspca_dev)
321{
322 struct sd *sd = (struct sd *) gspca_dev;
323
324 kfree(sd->jpeg_hdr);
325}
326
327static void sd_pkt_scan(struct gspca_dev *gspca_dev, 317static void sd_pkt_scan(struct gspca_dev *gspca_dev,
328 u8 *data, /* isoc packet */ 318 u8 *data, /* isoc packet */
329 int len) /* iso packet length */ 319 int len) /* iso packet length */
@@ -486,7 +476,6 @@ static const struct sd_desc sd_desc = {
486 .init = sd_init, 476 .init = sd_init,
487 .start = sd_start, 477 .start = sd_start,
488 .stopN = sd_stopN, 478 .stopN = sd_stopN,
489 .stop0 = sd_stop0,
490 .pkt_scan = sd_pkt_scan, 479 .pkt_scan = sd_pkt_scan,
491 .get_jcomp = sd_get_jcomp, 480 .get_jcomp = sd_get_jcomp,
492 .set_jcomp = sd_set_jcomp, 481 .set_jcomp = sd_set_jcomp,
diff --git a/drivers/media/video/gspca/ov519.c b/drivers/media/video/gspca/ov519.c
index f36e11a0458d..2b2cbdbf03fe 100644
--- a/drivers/media/video/gspca/ov519.c
+++ b/drivers/media/video/gspca/ov519.c
@@ -41,6 +41,11 @@
41#include <linux/input.h> 41#include <linux/input.h>
42#include "gspca.h" 42#include "gspca.h"
43 43
44/* The jpeg_hdr is used by w996Xcf only */
45/* The CONEX_CAM define for jpeg.h needs renaming, now its used here too */
46#define CONEX_CAM
47#include "jpeg.h"
48
44MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>"); 49MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>");
45MODULE_DESCRIPTION("OV519 USB Camera Driver"); 50MODULE_DESCRIPTION("OV519 USB Camera Driver");
46MODULE_LICENSE("GPL"); 51MODULE_LICENSE("GPL");
@@ -90,6 +95,7 @@ struct sd {
90#define QUALITY_DEF 50 95#define QUALITY_DEF 50
91 96
92 __u8 stopped; /* Streaming is temporarily paused */ 97 __u8 stopped; /* Streaming is temporarily paused */
98 __u8 first_frame;
93 99
94 __u8 frame_rate; /* current Framerate */ 100 __u8 frame_rate; /* current Framerate */
95 __u8 clockdiv; /* clockdiv override */ 101 __u8 clockdiv; /* clockdiv override */
@@ -115,7 +121,7 @@ struct sd {
115 int sensor_height; 121 int sensor_height;
116 int sensor_reg_cache[256]; 122 int sensor_reg_cache[256];
117 123
118 u8 *jpeg_hdr; 124 u8 jpeg_hdr[JPEG_HDR_SZ];
119}; 125};
120 126
121/* Note this is a bit of a hack, but the w9968cf driver needs the code for all 127/* Note this is a bit of a hack, but the w9968cf driver needs the code for all
@@ -3147,7 +3153,7 @@ static int sd_config(struct gspca_dev *gspca_dev,
3147 sd->autobrightness = AUTOBRIGHT_DEF; 3153 sd->autobrightness = AUTOBRIGHT_DEF;
3148 if (sd->sensor == SEN_OV7670) { 3154 if (sd->sensor == SEN_OV7670) {
3149 sd->freq = OV7670_FREQ_DEF; 3155 sd->freq = OV7670_FREQ_DEF;
3150 gspca_dev->ctrl_dis = 1 << FREQ_IDX; 3156 gspca_dev->ctrl_dis = (1 << FREQ_IDX) | (1 << COLOR_IDX);
3151 } else { 3157 } else {
3152 sd->freq = FREQ_DEF; 3158 sd->freq = FREQ_DEF;
3153 gspca_dev->ctrl_dis = (1 << HFLIP_IDX) | (1 << VFLIP_IDX) | 3159 gspca_dev->ctrl_dis = (1 << HFLIP_IDX) | (1 << VFLIP_IDX) |
@@ -3961,6 +3967,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
3961 sd_reset_snapshot(gspca_dev); 3967 sd_reset_snapshot(gspca_dev);
3962 sd->snapshot_pressed = 0; 3968 sd->snapshot_pressed = 0;
3963 3969
3970 sd->first_frame = 3;
3971
3964 ret = ov51x_restart(sd); 3972 ret = ov51x_restart(sd);
3965 if (ret < 0) 3973 if (ret < 0)
3966 goto out; 3974 goto out;
@@ -4153,13 +4161,23 @@ static void ovfx2_pkt_scan(struct gspca_dev *gspca_dev,
4153 u8 *data, /* isoc packet */ 4161 u8 *data, /* isoc packet */
4154 int len) /* iso packet length */ 4162 int len) /* iso packet length */
4155{ 4163{
4164 struct sd *sd = (struct sd *) gspca_dev;
4165
4166 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
4167
4156 /* A short read signals EOF */ 4168 /* A short read signals EOF */
4157 if (len < OVFX2_BULK_SIZE) { 4169 if (len < OVFX2_BULK_SIZE) {
4158 gspca_frame_add(gspca_dev, LAST_PACKET, data, len); 4170 /* If the frame is short, and it is one of the first ones
4171 the sensor and bridge are still syncing, so drop it. */
4172 if (sd->first_frame) {
4173 sd->first_frame--;
4174 if (gspca_dev->image_len <
4175 sd->gspca_dev.width * sd->gspca_dev.height)
4176 gspca_dev->last_packet_type = DISCARD_PACKET;
4177 }
4178 gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
4159 gspca_frame_add(gspca_dev, FIRST_PACKET, NULL, 0); 4179 gspca_frame_add(gspca_dev, FIRST_PACKET, NULL, 0);
4160 return;
4161 } 4180 }
4162 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
4163} 4181}
4164 4182
4165static void sd_pkt_scan(struct gspca_dev *gspca_dev, 4183static void sd_pkt_scan(struct gspca_dev *gspca_dev,
diff --git a/drivers/media/video/gspca/ov534.c b/drivers/media/video/gspca/ov534.c
index dc1e4efe30fb..96cb3a976581 100644
--- a/drivers/media/video/gspca/ov534.c
+++ b/drivers/media/video/gspca/ov534.c
@@ -987,13 +987,8 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
987 data + 12, len - 12); 987 data + 12, len - 12);
988 /* If this packet is marked as EOF, end the frame */ 988 /* If this packet is marked as EOF, end the frame */
989 } else if (data[1] & UVC_STREAM_EOF) { 989 } else if (data[1] & UVC_STREAM_EOF) {
990 struct gspca_frame *frame;
991
992 sd->last_pts = 0; 990 sd->last_pts = 0;
993 frame = gspca_get_i_frame(gspca_dev); 991 if (gspca_dev->image_len + len - 12 !=
994 if (frame == NULL)
995 goto discard;
996 if (frame->data_end - frame->data + (len - 12) !=
997 gspca_dev->width * gspca_dev->height * 2) { 992 gspca_dev->width * gspca_dev->height * 2) {
998 PDEBUG(D_PACK, "wrong sized frame"); 993 PDEBUG(D_PACK, "wrong sized frame");
999 goto discard; 994 goto discard;
diff --git a/drivers/media/video/gspca/pac7302.c b/drivers/media/video/gspca/pac7302.c
index 2a68220d1ada..a66df07d7625 100644
--- a/drivers/media/video/gspca/pac7302.c
+++ b/drivers/media/video/gspca/pac7302.c
@@ -402,7 +402,7 @@ static void reg_w_buf(struct gspca_dev *gspca_dev,
402 memcpy(gspca_dev->usb_buf, buffer, len); 402 memcpy(gspca_dev->usb_buf, buffer, len);
403 ret = usb_control_msg(gspca_dev->dev, 403 ret = usb_control_msg(gspca_dev->dev,
404 usb_sndctrlpipe(gspca_dev->dev, 0), 404 usb_sndctrlpipe(gspca_dev->dev, 0),
405 1, /* request */ 405 0, /* request */
406 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 406 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
407 0, /* value */ 407 0, /* value */
408 index, gspca_dev->usb_buf, len, 408 index, gspca_dev->usb_buf, len,
@@ -804,7 +804,6 @@ static const unsigned char pac_jpeg_header2[] = {
804}; 804};
805 805
806static void pac_start_frame(struct gspca_dev *gspca_dev, 806static void pac_start_frame(struct gspca_dev *gspca_dev,
807 struct gspca_frame *frame,
808 __u16 lines, __u16 samples_per_line) 807 __u16 lines, __u16 samples_per_line)
809{ 808{
810 unsigned char tmpbuf[4]; 809 unsigned char tmpbuf[4];
@@ -829,19 +828,13 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
829 int len) /* iso packet length */ 828 int len) /* iso packet length */
830{ 829{
831 struct sd *sd = (struct sd *) gspca_dev; 830 struct sd *sd = (struct sd *) gspca_dev;
832 struct gspca_frame *frame; 831 u8 *image;
833 unsigned char *sof; 832 unsigned char *sof;
834 833
835 sof = pac_find_sof(&sd->sof_read, data, len); 834 sof = pac_find_sof(&sd->sof_read, data, len);
836 if (sof) { 835 if (sof) {
837 int n, lum_offset, footer_length; 836 int n, lum_offset, footer_length;
838 837
839 frame = gspca_get_i_frame(gspca_dev);
840 if (frame == NULL) {
841 gspca_dev->last_packet_type = DISCARD_PACKET;
842 return;
843 }
844
845 /* 6 bytes after the FF D9 EOF marker a number of lumination 838 /* 6 bytes after the FF D9 EOF marker a number of lumination
846 bytes are send corresponding to different parts of the 839 bytes are send corresponding to different parts of the
847 image, the 14th and 15th byte after the EOF seem to 840 image, the 14th and 15th byte after the EOF seem to
@@ -852,16 +845,17 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
852 /* Finish decoding current frame */ 845 /* Finish decoding current frame */
853 n = (sof - data) - (footer_length + sizeof pac_sof_marker); 846 n = (sof - data) - (footer_length + sizeof pac_sof_marker);
854 if (n < 0) { 847 if (n < 0) {
855 frame->data_end += n; 848 gspca_dev->image_len += n;
856 n = 0; 849 n = 0;
850 } else {
851 gspca_frame_add(gspca_dev, INTER_PACKET, data, n);
857 } 852 }
858 gspca_frame_add(gspca_dev, INTER_PACKET, 853
859 data, n); 854 image = gspca_dev->image;
860 if (gspca_dev->last_packet_type != DISCARD_PACKET && 855 if (image != NULL
861 frame->data_end[-2] == 0xff && 856 && image[gspca_dev->image_len - 2] == 0xff
862 frame->data_end[-1] == 0xd9) 857 && image[gspca_dev->image_len - 1] == 0xd9)
863 gspca_frame_add(gspca_dev, LAST_PACKET, 858 gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
864 NULL, 0);
865 859
866 n = sof - data; 860 n = sof - data;
867 len -= n; 861 len -= n;
@@ -877,7 +871,7 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
877 871
878 /* Start the new frame with the jpeg header */ 872 /* Start the new frame with the jpeg header */
879 /* The PAC7302 has the image rotated 90 degrees */ 873 /* The PAC7302 has the image rotated 90 degrees */
880 pac_start_frame(gspca_dev, frame, 874 pac_start_frame(gspca_dev,
881 gspca_dev->width, gspca_dev->height); 875 gspca_dev->width, gspca_dev->height);
882 } 876 }
883 gspca_frame_add(gspca_dev, INTER_PACKET, data, len); 877 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
@@ -1200,6 +1194,7 @@ static const struct usb_device_id device_table[] __devinitconst = {
1200 {USB_DEVICE(0x093a, 0x2621)}, 1194 {USB_DEVICE(0x093a, 0x2621)},
1201 {USB_DEVICE(0x093a, 0x2622), .driver_info = FL_VFLIP}, 1195 {USB_DEVICE(0x093a, 0x2622), .driver_info = FL_VFLIP},
1202 {USB_DEVICE(0x093a, 0x2624), .driver_info = FL_VFLIP}, 1196 {USB_DEVICE(0x093a, 0x2624), .driver_info = FL_VFLIP},
1197 {USB_DEVICE(0x093a, 0x2625)},
1203 {USB_DEVICE(0x093a, 0x2626)}, 1198 {USB_DEVICE(0x093a, 0x2626)},
1204 {USB_DEVICE(0x093a, 0x2628)}, 1199 {USB_DEVICE(0x093a, 0x2628)},
1205 {USB_DEVICE(0x093a, 0x2629), .driver_info = FL_VFLIP}, 1200 {USB_DEVICE(0x093a, 0x2629), .driver_info = FL_VFLIP},
diff --git a/drivers/media/video/gspca/pac7311.c b/drivers/media/video/gspca/pac7311.c
index 44fed9686729..1cb7e99e92bd 100644
--- a/drivers/media/video/gspca/pac7311.c
+++ b/drivers/media/video/gspca/pac7311.c
@@ -270,7 +270,7 @@ static void reg_w_buf(struct gspca_dev *gspca_dev,
270 memcpy(gspca_dev->usb_buf, buffer, len); 270 memcpy(gspca_dev->usb_buf, buffer, len);
271 ret = usb_control_msg(gspca_dev->dev, 271 ret = usb_control_msg(gspca_dev->dev,
272 usb_sndctrlpipe(gspca_dev->dev, 0), 272 usb_sndctrlpipe(gspca_dev->dev, 0),
273 1, /* request */ 273 0, /* request */
274 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 274 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
275 0, /* value */ 275 0, /* value */
276 index, gspca_dev->usb_buf, len, 276 index, gspca_dev->usb_buf, len,
@@ -599,7 +599,6 @@ static const unsigned char pac_jpeg_header2[] = {
599}; 599};
600 600
601static void pac_start_frame(struct gspca_dev *gspca_dev, 601static void pac_start_frame(struct gspca_dev *gspca_dev,
602 struct gspca_frame *frame,
603 __u16 lines, __u16 samples_per_line) 602 __u16 lines, __u16 samples_per_line)
604{ 603{
605 unsigned char tmpbuf[4]; 604 unsigned char tmpbuf[4];
@@ -624,19 +623,13 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
624 int len) /* iso packet length */ 623 int len) /* iso packet length */
625{ 624{
626 struct sd *sd = (struct sd *) gspca_dev; 625 struct sd *sd = (struct sd *) gspca_dev;
626 u8 *image;
627 unsigned char *sof; 627 unsigned char *sof;
628 struct gspca_frame *frame;
629 628
630 sof = pac_find_sof(&sd->sof_read, data, len); 629 sof = pac_find_sof(&sd->sof_read, data, len);
631 if (sof) { 630 if (sof) {
632 int n, lum_offset, footer_length; 631 int n, lum_offset, footer_length;
633 632
634 frame = gspca_get_i_frame(gspca_dev);
635 if (frame == NULL) {
636 gspca_dev->last_packet_type = DISCARD_PACKET;
637 return;
638 }
639
640 /* 6 bytes after the FF D9 EOF marker a number of lumination 633 /* 6 bytes after the FF D9 EOF marker a number of lumination
641 bytes are send corresponding to different parts of the 634 bytes are send corresponding to different parts of the
642 image, the 14th and 15th byte after the EOF seem to 635 image, the 14th and 15th byte after the EOF seem to
@@ -647,16 +640,16 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
647 /* Finish decoding current frame */ 640 /* Finish decoding current frame */
648 n = (sof - data) - (footer_length + sizeof pac_sof_marker); 641 n = (sof - data) - (footer_length + sizeof pac_sof_marker);
649 if (n < 0) { 642 if (n < 0) {
650 frame->data_end += n; 643 gspca_dev->image_len += n;
651 n = 0; 644 n = 0;
645 } else {
646 gspca_frame_add(gspca_dev, INTER_PACKET, data, n);
652 } 647 }
653 gspca_frame_add(gspca_dev, INTER_PACKET, 648 image = gspca_dev->image;
654 data, n); 649 if (image != NULL
655 if (gspca_dev->last_packet_type != DISCARD_PACKET && 650 && image[gspca_dev->image_len - 2] == 0xff
656 frame->data_end[-2] == 0xff && 651 && image[gspca_dev->image_len - 1] == 0xd9)
657 frame->data_end[-1] == 0xd9) 652 gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
658 gspca_frame_add(gspca_dev, LAST_PACKET,
659 NULL, 0);
660 653
661 n = sof - data; 654 n = sof - data;
662 len -= n; 655 len -= n;
@@ -671,7 +664,7 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
671 atomic_set(&sd->avg_lum, -1); 664 atomic_set(&sd->avg_lum, -1);
672 665
673 /* Start the new frame with the jpeg header */ 666 /* Start the new frame with the jpeg header */
674 pac_start_frame(gspca_dev, frame, 667 pac_start_frame(gspca_dev,
675 gspca_dev->height, gspca_dev->width); 668 gspca_dev->height, gspca_dev->width);
676 } 669 }
677 gspca_frame_add(gspca_dev, INTER_PACKET, data, len); 670 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
diff --git a/drivers/media/video/gspca/sn9c20x.c b/drivers/media/video/gspca/sn9c20x.c
index 644a7fd4701a..83a718f0f3f9 100644
--- a/drivers/media/video/gspca/sn9c20x.c
+++ b/drivers/media/video/gspca/sn9c20x.c
@@ -20,7 +20,6 @@
20 20
21#ifdef CONFIG_INPUT 21#ifdef CONFIG_INPUT
22#include <linux/input.h> 22#include <linux/input.h>
23#include <linux/slab.h>
24#endif 23#endif
25 24
26#include "gspca.h" 25#include "gspca.h"
@@ -89,7 +88,7 @@ struct sd {
89 u8 hstart; 88 u8 hstart;
90 u8 vstart; 89 u8 vstart;
91 90
92 u8 *jpeg_hdr; 91 u8 jpeg_hdr[JPEG_HDR_SZ];
93 u8 quality; 92 u8 quality;
94 93
95 u8 flags; 94 u8 flags;
@@ -2162,10 +2161,6 @@ static int sd_start(struct gspca_dev *gspca_dev)
2162 int height = gspca_dev->height; 2161 int height = gspca_dev->height;
2163 u8 fmt, scale = 0; 2162 u8 fmt, scale = 0;
2164 2163
2165 sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL);
2166 if (sd->jpeg_hdr == NULL)
2167 return -ENOMEM;
2168
2169 jpeg_define(sd->jpeg_hdr, height, width, 2164 jpeg_define(sd->jpeg_hdr, height, width,
2170 0x21); 2165 0x21);
2171 jpeg_set_qual(sd->jpeg_hdr, sd->quality); 2166 jpeg_set_qual(sd->jpeg_hdr, sd->quality);
@@ -2197,8 +2192,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
2197 } 2192 }
2198 2193
2199 configure_sensor_output(gspca_dev, mode); 2194 configure_sensor_output(gspca_dev, mode);
2200 reg_w(gspca_dev, 0x1100, sd->jpeg_hdr + JPEG_QT0_OFFSET, 64); 2195 reg_w(gspca_dev, 0x1100, &sd->jpeg_hdr[JPEG_QT0_OFFSET], 64);
2201 reg_w(gspca_dev, 0x1140, sd->jpeg_hdr + JPEG_QT1_OFFSET, 64); 2196 reg_w(gspca_dev, 0x1140, &sd->jpeg_hdr[JPEG_QT1_OFFSET], 64);
2202 reg_w(gspca_dev, 0x10fb, CLR_WIN(width, height), 5); 2197 reg_w(gspca_dev, 0x10fb, CLR_WIN(width, height), 5);
2203 reg_w(gspca_dev, 0x1180, HW_WIN(mode, sd->hstart, sd->vstart), 6); 2198 reg_w(gspca_dev, 0x1180, HW_WIN(mode, sd->hstart, sd->vstart), 6);
2204 reg_w1(gspca_dev, 0x1189, scale); 2199 reg_w1(gspca_dev, 0x1189, scale);
@@ -2226,12 +2221,6 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
2226 reg_w1(gspca_dev, 0x1061, gspca_dev->usb_buf[0] & ~0x02); 2221 reg_w1(gspca_dev, 0x1061, gspca_dev->usb_buf[0] & ~0x02);
2227} 2222}
2228 2223
2229static void sd_stop0(struct gspca_dev *gspca_dev)
2230{
2231 struct sd *sd = (struct sd *) gspca_dev;
2232 kfree(sd->jpeg_hdr);
2233}
2234
2235static void do_autoexposure(struct gspca_dev *gspca_dev, u16 avg_lum) 2224static void do_autoexposure(struct gspca_dev *gspca_dev, u16 avg_lum)
2236{ 2225{
2237 struct sd *sd = (struct sd *) gspca_dev; 2226 struct sd *sd = (struct sd *) gspca_dev;
@@ -2397,7 +2386,6 @@ static const struct sd_desc sd_desc = {
2397 .init = sd_init, 2386 .init = sd_init,
2398 .start = sd_start, 2387 .start = sd_start,
2399 .stopN = sd_stopN, 2388 .stopN = sd_stopN,
2400 .stop0 = sd_stop0,
2401 .pkt_scan = sd_pkt_scan, 2389 .pkt_scan = sd_pkt_scan,
2402#ifdef CONFIG_INPUT 2390#ifdef CONFIG_INPUT
2403 .int_pkt_scan = sd_int_pkt_scan, 2391 .int_pkt_scan = sd_int_pkt_scan,
diff --git a/drivers/media/video/gspca/sonixb.c b/drivers/media/video/gspca/sonixb.c
index 95354a339e3d..204bb3af4559 100644
--- a/drivers/media/video/gspca/sonixb.c
+++ b/drivers/media/video/gspca/sonixb.c
@@ -1251,16 +1251,10 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
1251 if (cam->cam_mode[gspca_dev->curr_mode].priv & MODE_RAW) { 1251 if (cam->cam_mode[gspca_dev->curr_mode].priv & MODE_RAW) {
1252 /* In raw mode we sometimes get some garbage after the frame 1252 /* In raw mode we sometimes get some garbage after the frame
1253 ignore this */ 1253 ignore this */
1254 struct gspca_frame *frame;
1255 int used; 1254 int used;
1256 int size = cam->cam_mode[gspca_dev->curr_mode].sizeimage; 1255 int size = cam->cam_mode[gspca_dev->curr_mode].sizeimage;
1257 1256
1258 frame = gspca_get_i_frame(gspca_dev); 1257 used = gspca_dev->image_len;
1259 if (frame == NULL) {
1260 gspca_dev->last_packet_type = DISCARD_PACKET;
1261 return;
1262 }
1263 used = frame->data_end - frame->data;
1264 if (used + len > size) 1258 if (used + len > size)
1265 len = size - used; 1259 len = size - used;
1266 } 1260 }
diff --git a/drivers/media/video/gspca/sonixj.c b/drivers/media/video/gspca/sonixj.c
index 176c5b3d5e6f..ee17b034bf6b 100644
--- a/drivers/media/video/gspca/sonixj.c
+++ b/drivers/media/video/gspca/sonixj.c
@@ -22,7 +22,6 @@
22#define MODULE_NAME "sonixj" 22#define MODULE_NAME "sonixj"
23 23
24#include <linux/input.h> 24#include <linux/input.h>
25#include <linux/slab.h>
26#include "gspca.h" 25#include "gspca.h"
27#include "jpeg.h" 26#include "jpeg.h"
28 27
@@ -392,7 +391,7 @@ static const u8 sn_gc0307[0x1c] = {
392 391
393static const u8 sn_hv7131[0x1c] = { 392static const u8 sn_hv7131[0x1c] = {
394/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */ 393/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
395 0x00, 0x03, 0x64, 0x00, 0x1a, 0x20, 0x20, 0x20, 394 0x00, 0x03, 0x60, 0x00, 0x1a, 0x20, 0x20, 0x20,
396/* reg8 reg9 rega regb regc regd rege regf */ 395/* reg8 reg9 rega regb regc regd rege regf */
397 0x81, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 396 0x81, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
398/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */ 397/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
@@ -403,7 +402,7 @@ static const u8 sn_hv7131[0x1c] = {
403 402
404static const u8 sn_mi0360[0x1c] = { 403static const u8 sn_mi0360[0x1c] = {
405/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */ 404/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
406 0x00, 0x61, 0x44, 0x00, 0x1a, 0x20, 0x20, 0x20, 405 0x00, 0x61, 0x40, 0x00, 0x1a, 0x20, 0x20, 0x20,
407/* reg8 reg9 rega regb regc regd rege regf */ 406/* reg8 reg9 rega regb regc regd rege regf */
408 0x81, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 407 0x81, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
409/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */ 408/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
@@ -1644,6 +1643,7 @@ static void bridge_init(struct gspca_dev *gspca_dev,
1644 const u8 *sn9c1xx) 1643 const u8 *sn9c1xx)
1645{ 1644{
1646 struct sd *sd = (struct sd *) gspca_dev; 1645 struct sd *sd = (struct sd *) gspca_dev;
1646 u8 reg0102[2];
1647 const u8 *reg9a; 1647 const u8 *reg9a;
1648 static const u8 reg9a_def[] = 1648 static const u8 reg9a_def[] =
1649 {0x00, 0x40, 0x20, 0x00, 0x00, 0x00}; 1649 {0x00, 0x40, 0x20, 0x00, 0x00, 0x00};
@@ -1656,7 +1656,11 @@ static void bridge_init(struct gspca_dev *gspca_dev,
1656 reg_w1(gspca_dev, 0x01, sn9c1xx[1]); 1656 reg_w1(gspca_dev, 0x01, sn9c1xx[1]);
1657 1657
1658 /* configure gpio */ 1658 /* configure gpio */
1659 reg_w(gspca_dev, 0x01, &sn9c1xx[1], 2); 1659 reg0102[0] = sn9c1xx[1];
1660 reg0102[1] = sn9c1xx[2];
1661 if (gspca_dev->audio)
1662 reg0102[1] |= 0x04; /* keep the audio connection */
1663 reg_w(gspca_dev, 0x01, reg0102, 2);
1660 reg_w(gspca_dev, 0x08, &sn9c1xx[8], 2); 1664 reg_w(gspca_dev, 0x08, &sn9c1xx[8], 2);
1661 reg_w(gspca_dev, 0x17, &sn9c1xx[0x17], 5); 1665 reg_w(gspca_dev, 0x17, &sn9c1xx[0x17], 5);
1662 switch (sd->sensor) { 1666 switch (sd->sensor) {
@@ -1737,13 +1741,12 @@ static void bridge_init(struct gspca_dev *gspca_dev,
1737 reg_w1(gspca_dev, 0x01, 0x40); 1741 reg_w1(gspca_dev, 0x01, 0x40);
1738 break; 1742 break;
1739 case SENSOR_PO2030N: 1743 case SENSOR_PO2030N:
1744 case SENSOR_OV7660:
1740 reg_w1(gspca_dev, 0x01, 0x63); 1745 reg_w1(gspca_dev, 0x01, 0x63);
1741 reg_w1(gspca_dev, 0x17, 0x20); 1746 reg_w1(gspca_dev, 0x17, 0x20);
1742 reg_w1(gspca_dev, 0x01, 0x62); 1747 reg_w1(gspca_dev, 0x01, 0x62);
1743 reg_w1(gspca_dev, 0x01, 0x42); 1748 reg_w1(gspca_dev, 0x01, 0x42);
1744 break; 1749 break;
1745 case SENSOR_OV7660:
1746 /* fall thru */
1747 case SENSOR_SP80708: 1750 case SENSOR_SP80708:
1748 reg_w1(gspca_dev, 0x01, 0x63); 1751 reg_w1(gspca_dev, 0x01, 0x63);
1749 reg_w1(gspca_dev, 0x17, 0x20); 1752 reg_w1(gspca_dev, 0x17, 0x20);
@@ -1816,7 +1819,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
1816{ 1819{
1817 struct sd *sd = (struct sd *) gspca_dev; 1820 struct sd *sd = (struct sd *) gspca_dev;
1818 const u8 *sn9c1xx; 1821 const u8 *sn9c1xx;
1819 u8 regGpio[] = { 0x29, 0x74 }; 1822 u8 regGpio[] = { 0x29, 0x74 }; /* with audio */
1820 u8 regF1; 1823 u8 regF1;
1821 1824
1822 /* setup a selector by bridge */ 1825 /* setup a selector by bridge */
@@ -1856,7 +1859,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
1856 po2030n_probe(gspca_dev); 1859 po2030n_probe(gspca_dev);
1857 break; 1860 break;
1858 } 1861 }
1859 regGpio[1] = 0x70; 1862 regGpio[1] = 0x70; /* no audio */
1860 reg_w(gspca_dev, 0x01, regGpio, 2); 1863 reg_w(gspca_dev, 0x01, regGpio, 2);
1861 break; 1864 break;
1862 default: 1865 default:
@@ -2274,7 +2277,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
2274{ 2277{
2275 struct sd *sd = (struct sd *) gspca_dev; 2278 struct sd *sd = (struct sd *) gspca_dev;
2276 int i; 2279 int i;
2277 u8 reg1, reg2, reg17; 2280 u8 reg1, reg17;
2278 const u8 *sn9c1xx; 2281 const u8 *sn9c1xx;
2279 const u8 (*init)[8]; 2282 const u8 (*init)[8];
2280 int mode; 2283 int mode;
@@ -2304,23 +2307,6 @@ static int sd_start(struct gspca_dev *gspca_dev)
2304 /* initialize the sensor */ 2307 /* initialize the sensor */
2305 i2c_w_seq(gspca_dev, sensor_init[sd->sensor]); 2308 i2c_w_seq(gspca_dev, sensor_init[sd->sensor]);
2306 2309
2307 switch (sd->sensor) {
2308 case SENSOR_ADCM1700:
2309 reg2 = 0x60;
2310 break;
2311 case SENSOR_OM6802:
2312 reg2 = 0x71;
2313 break;
2314 case SENSOR_SP80708:
2315 reg2 = 0x62;
2316 break;
2317 default:
2318 reg2 = 0x40;
2319 break;
2320 }
2321 reg_w1(gspca_dev, 0x02, reg2);
2322 reg_w1(gspca_dev, 0x02, reg2);
2323
2324 reg_w1(gspca_dev, 0x15, sn9c1xx[0x15]); 2310 reg_w1(gspca_dev, 0x15, sn9c1xx[0x15]);
2325 reg_w1(gspca_dev, 0x16, sn9c1xx[0x16]); 2311 reg_w1(gspca_dev, 0x16, sn9c1xx[0x16]);
2326 reg_w1(gspca_dev, 0x12, sn9c1xx[0x12]); 2312 reg_w1(gspca_dev, 0x12, sn9c1xx[0x12]);
diff --git a/drivers/media/video/gspca/spca1528.c b/drivers/media/video/gspca/spca1528.c
new file mode 100644
index 000000000000..3f514eb1d99d
--- /dev/null
+++ b/drivers/media/video/gspca/spca1528.c
@@ -0,0 +1,605 @@
1/*
2 * spca1528 subdriver
3 *
4 * Copyright (C) 2010 Jean-Francois Moine (http://moinejf.free.fr)
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#define MODULE_NAME "spca1528"
22
23#include "gspca.h"
24#include "jpeg.h"
25
26MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>");
27MODULE_DESCRIPTION("SPCA1528 USB Camera Driver");
28MODULE_LICENSE("GPL");
29
30/* specific webcam descriptor */
31struct sd {
32 struct gspca_dev gspca_dev; /* !! must be the first item */
33
34 u8 brightness;
35 u8 contrast;
36 u8 hue;
37 u8 color;
38 u8 sharpness;
39
40 u8 pkt_seq;
41
42 u8 jpeg_hdr[JPEG_HDR_SZ];
43};
44
45/* V4L2 controls supported by the driver */
46static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
47static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
48static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
49static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
50static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val);
51static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val);
52static int sd_setcolor(struct gspca_dev *gspca_dev, __s32 val);
53static int sd_getcolor(struct gspca_dev *gspca_dev, __s32 *val);
54static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val);
55static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val);
56
57static const struct ctrl sd_ctrls[] = {
58 {
59 {
60 .id = V4L2_CID_BRIGHTNESS,
61 .type = V4L2_CTRL_TYPE_INTEGER,
62 .name = "Brightness",
63 .minimum = 0,
64 .maximum = 255,
65 .step = 1,
66#define BRIGHTNESS_DEF 128
67 .default_value = BRIGHTNESS_DEF,
68 },
69 .set = sd_setbrightness,
70 .get = sd_getbrightness,
71 },
72 {
73 {
74 .id = V4L2_CID_CONTRAST,
75 .type = V4L2_CTRL_TYPE_INTEGER,
76 .name = "Contrast",
77 .minimum = 0,
78 .maximum = 8,
79 .step = 1,
80#define CONTRAST_DEF 1
81 .default_value = CONTRAST_DEF,
82 },
83 .set = sd_setcontrast,
84 .get = sd_getcontrast,
85 },
86 {
87 {
88 .id = V4L2_CID_HUE,
89 .type = V4L2_CTRL_TYPE_INTEGER,
90 .name = "Hue",
91 .minimum = 0,
92 .maximum = 255,
93 .step = 1,
94#define HUE_DEF 0
95 .default_value = HUE_DEF,
96 },
97 .set = sd_sethue,
98 .get = sd_gethue,
99 },
100 {
101 {
102 .id = V4L2_CID_SATURATION,
103 .type = V4L2_CTRL_TYPE_INTEGER,
104 .name = "Saturation",
105 .minimum = 0,
106 .maximum = 8,
107 .step = 1,
108#define COLOR_DEF 1
109 .default_value = COLOR_DEF,
110 },
111 .set = sd_setcolor,
112 .get = sd_getcolor,
113 },
114 {
115 {
116 .id = V4L2_CID_SHARPNESS,
117 .type = V4L2_CTRL_TYPE_INTEGER,
118 .name = "Sharpness",
119 .minimum = 0,
120 .maximum = 255,
121 .step = 1,
122#define SHARPNESS_DEF 0
123 .default_value = SHARPNESS_DEF,
124 },
125 .set = sd_setsharpness,
126 .get = sd_getsharpness,
127 },
128};
129
130static const struct v4l2_pix_format vga_mode[] = {
131/* (does not work correctly)
132 {176, 144, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
133 .bytesperline = 176,
134 .sizeimage = 176 * 144 * 5 / 8 + 590,
135 .colorspace = V4L2_COLORSPACE_JPEG,
136 .priv = 3},
137*/
138 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
139 .bytesperline = 320,
140 .sizeimage = 320 * 240 * 4 / 8 + 590,
141 .colorspace = V4L2_COLORSPACE_JPEG,
142 .priv = 2},
143 {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
144 .bytesperline = 640,
145 .sizeimage = 640 * 480 * 3 / 8 + 590,
146 .colorspace = V4L2_COLORSPACE_JPEG,
147 .priv = 1},
148};
149
150/* read <len> bytes to gspca usb_buf */
151static void reg_r(struct gspca_dev *gspca_dev,
152 u8 req,
153 u16 index,
154 int len)
155{
156#if USB_BUF_SZ < 64
157#error "USB buffer too small"
158#endif
159 struct usb_device *dev = gspca_dev->dev;
160 int ret;
161
162 if (gspca_dev->usb_err < 0)
163 return;
164 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
165 req,
166 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
167 0x0000, /* value */
168 index,
169 gspca_dev->usb_buf, len,
170 500);
171 PDEBUG(D_USBI, "GET %02x 0000 %04x %02x", req, index,
172 gspca_dev->usb_buf[0]);
173 if (ret < 0) {
174 PDEBUG(D_ERR, "reg_r err %d", ret);
175 gspca_dev->usb_err = ret;
176 }
177}
178
179static void reg_w(struct gspca_dev *gspca_dev,
180 u8 req,
181 u16 value,
182 u16 index)
183{
184 struct usb_device *dev = gspca_dev->dev;
185 int ret;
186
187 if (gspca_dev->usb_err < 0)
188 return;
189 PDEBUG(D_USBO, "SET %02x %04x %04x", req, value, index);
190 ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
191 req,
192 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
193 value, index,
194 NULL, 0, 500);
195 if (ret < 0) {
196 PDEBUG(D_ERR, "reg_w err %d", ret);
197 gspca_dev->usb_err = ret;
198 }
199}
200
201static void reg_wb(struct gspca_dev *gspca_dev,
202 u8 req,
203 u16 value,
204 u16 index,
205 u8 byte)
206{
207 struct usb_device *dev = gspca_dev->dev;
208 int ret;
209
210 if (gspca_dev->usb_err < 0)
211 return;
212 PDEBUG(D_USBO, "SET %02x %04x %04x %02x", req, value, index, byte);
213 gspca_dev->usb_buf[0] = byte;
214 ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
215 req,
216 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
217 value, index,
218 gspca_dev->usb_buf, 1, 500);
219 if (ret < 0) {
220 PDEBUG(D_ERR, "reg_w err %d", ret);
221 gspca_dev->usb_err = ret;
222 }
223}
224
225static void wait_status_0(struct gspca_dev *gspca_dev)
226{
227 int i;
228
229 i = 20;
230 do {
231 reg_r(gspca_dev, 0x21, 0x0000, 1);
232 if (gspca_dev->usb_buf[0] == 0)
233 return;
234 msleep(30);
235 } while (--i > 0);
236 PDEBUG(D_ERR, "wait_status_0 timeout");
237 gspca_dev->usb_err = -ETIME;
238}
239
240static void wait_status_1(struct gspca_dev *gspca_dev)
241{
242 int i;
243
244 i = 10;
245 do {
246 reg_r(gspca_dev, 0x21, 0x0001, 1);
247 msleep(10);
248 if (gspca_dev->usb_buf[0] == 1) {
249 reg_wb(gspca_dev, 0x21, 0x0000, 0x0001, 0x00);
250 reg_r(gspca_dev, 0x21, 0x0001, 1);
251 return;
252 }
253 } while (--i > 0);
254 PDEBUG(D_ERR, "wait_status_1 timeout");
255 gspca_dev->usb_err = -ETIME;
256}
257
258static void setbrightness(struct gspca_dev *gspca_dev)
259{
260 struct sd *sd = (struct sd *) gspca_dev;
261
262 reg_wb(gspca_dev, 0xc0, 0x0000, 0x00c0, sd->brightness);
263}
264
265static void setcontrast(struct gspca_dev *gspca_dev)
266{
267 struct sd *sd = (struct sd *) gspca_dev;
268
269 reg_wb(gspca_dev, 0xc1, 0x0000, 0x00c1, sd->contrast);
270}
271
272static void sethue(struct gspca_dev *gspca_dev)
273{
274 struct sd *sd = (struct sd *) gspca_dev;
275
276 reg_wb(gspca_dev, 0xc2, 0x0000, 0x0000, sd->hue);
277}
278
279static void setcolor(struct gspca_dev *gspca_dev)
280{
281 struct sd *sd = (struct sd *) gspca_dev;
282
283 reg_wb(gspca_dev, 0xc3, 0x0000, 0x00c3, sd->color);
284}
285
286static void setsharpness(struct gspca_dev *gspca_dev)
287{
288 struct sd *sd = (struct sd *) gspca_dev;
289
290 reg_wb(gspca_dev, 0xc4, 0x0000, 0x00c4, sd->sharpness);
291}
292
293/* this function is called at probe time */
294static int sd_config(struct gspca_dev *gspca_dev,
295 const struct usb_device_id *id)
296{
297 struct sd *sd = (struct sd *) gspca_dev;
298
299 gspca_dev->cam.cam_mode = vga_mode;
300 gspca_dev->cam.nmodes = ARRAY_SIZE(vga_mode);
301 gspca_dev->cam.npkt = 128; /* number of packets per ISOC message */
302 /*fixme: 256 in ms-win traces*/
303
304 sd->brightness = BRIGHTNESS_DEF;
305 sd->contrast = CONTRAST_DEF;
306 sd->hue = HUE_DEF;
307 sd->color = COLOR_DEF;
308 sd->sharpness = SHARPNESS_DEF;
309
310 gspca_dev->nbalt = 4; /* use alternate setting 3 */
311
312 return 0;
313}
314
315/* this function is called at probe and resume time */
316static int sd_init(struct gspca_dev *gspca_dev)
317{
318 reg_w(gspca_dev, 0x00, 0x0001, 0x2067);
319 reg_w(gspca_dev, 0x00, 0x00d0, 0x206b);
320 reg_w(gspca_dev, 0x00, 0x0000, 0x206c);
321 reg_w(gspca_dev, 0x00, 0x0001, 0x2069);
322 msleep(8);
323 reg_w(gspca_dev, 0x00, 0x00c0, 0x206b);
324 reg_w(gspca_dev, 0x00, 0x0000, 0x206c);
325 reg_w(gspca_dev, 0x00, 0x0001, 0x2069);
326
327 reg_r(gspca_dev, 0x20, 0x0000, 1);
328 reg_r(gspca_dev, 0x20, 0x0000, 5);
329 reg_r(gspca_dev, 0x23, 0x0000, 64);
330 PDEBUG(D_PROBE, "%s%s", &gspca_dev->usb_buf[0x1c],
331 &gspca_dev->usb_buf[0x30]);
332 reg_r(gspca_dev, 0x23, 0x0001, 64);
333 return gspca_dev->usb_err;
334}
335
336/* function called at start time before URB creation */
337static int sd_isoc_init(struct gspca_dev *gspca_dev)
338{
339 u8 mode;
340
341 reg_r(gspca_dev, 0x00, 0x2520, 1);
342 wait_status_0(gspca_dev);
343 reg_w(gspca_dev, 0xc5, 0x0003, 0x0000);
344 wait_status_1(gspca_dev);
345
346 wait_status_0(gspca_dev);
347 mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
348 reg_wb(gspca_dev, 0x25, 0x0000, 0x0004, mode);
349 reg_r(gspca_dev, 0x25, 0x0004, 1);
350 reg_wb(gspca_dev, 0x27, 0x0000, 0x0000, 0x06);
351 reg_r(gspca_dev, 0x27, 0x0000, 1);
352 return gspca_dev->usb_err;
353}
354
355/* -- start the camera -- */
356static int sd_start(struct gspca_dev *gspca_dev)
357{
358 struct sd *sd = (struct sd *) gspca_dev;
359
360 /* initialize the JPEG header */
361 jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
362 0x22); /* JPEG 411 */
363
364 /* the JPEG quality seems to be 82% */
365 jpeg_set_qual(sd->jpeg_hdr, 82);
366
367 /* set the controls */
368 setbrightness(gspca_dev);
369 setcontrast(gspca_dev);
370 sethue(gspca_dev);
371 setcolor(gspca_dev);
372 setsharpness(gspca_dev);
373
374 msleep(5);
375 reg_r(gspca_dev, 0x00, 0x2520, 1);
376 msleep(8);
377
378 /* start the capture */
379 wait_status_0(gspca_dev);
380 reg_w(gspca_dev, 0x31, 0x0000, 0x0004);
381 wait_status_1(gspca_dev);
382 wait_status_0(gspca_dev);
383 msleep(200);
384
385 sd->pkt_seq = 0;
386 return gspca_dev->usb_err;
387}
388
389static void sd_stopN(struct gspca_dev *gspca_dev)
390{
391 /* stop the capture */
392 wait_status_0(gspca_dev);
393 reg_w(gspca_dev, 0x31, 0x0000, 0x0000);
394 wait_status_1(gspca_dev);
395 wait_status_0(gspca_dev);
396}
397
398/* move a packet adding 0x00 after 0xff */
399static void add_packet(struct gspca_dev *gspca_dev,
400 u8 *data,
401 int len)
402{
403 int i;
404
405 i = 0;
406 do {
407 if (data[i] == 0xff) {
408 gspca_frame_add(gspca_dev, INTER_PACKET,
409 data, i + 1);
410 len -= i;
411 data += i;
412 *data = 0x00;
413 i = 0;
414 }
415 } while (++i < len);
416 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
417}
418
419static void sd_pkt_scan(struct gspca_dev *gspca_dev,
420 u8 *data, /* isoc packet */
421 int len) /* iso packet length */
422{
423 struct sd *sd = (struct sd *) gspca_dev;
424 static const u8 ffd9[] = {0xff, 0xd9};
425
426 /* image packets start with:
427 * 02 8n
428 * with <n> bit:
429 * 0x01: even (0) / odd (1) image
430 * 0x02: end of image when set
431 */
432 if (len < 3)
433 return; /* empty packet */
434 if (*data == 0x02) {
435 if (data[1] & 0x02) {
436 sd->pkt_seq = !(data[1] & 1);
437 add_packet(gspca_dev, data + 2, len - 2);
438 gspca_frame_add(gspca_dev, LAST_PACKET,
439 ffd9, 2);
440 return;
441 }
442 if ((data[1] & 1) != sd->pkt_seq)
443 goto err;
444 if (gspca_dev->last_packet_type == LAST_PACKET)
445 gspca_frame_add(gspca_dev, FIRST_PACKET,
446 sd->jpeg_hdr, JPEG_HDR_SZ);
447 add_packet(gspca_dev, data + 2, len - 2);
448 return;
449 }
450err:
451 gspca_dev->last_packet_type = DISCARD_PACKET;
452}
453
454static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
455{
456 struct sd *sd = (struct sd *) gspca_dev;
457
458 sd->brightness = val;
459 if (gspca_dev->streaming)
460 setbrightness(gspca_dev);
461 return gspca_dev->usb_err;
462}
463
464static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
465{
466 struct sd *sd = (struct sd *) gspca_dev;
467
468 *val = sd->brightness;
469 return 0;
470}
471
472static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
473{
474 struct sd *sd = (struct sd *) gspca_dev;
475
476 sd->contrast = val;
477 if (gspca_dev->streaming)
478 setcontrast(gspca_dev);
479 return gspca_dev->usb_err;
480}
481
482static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
483{
484 struct sd *sd = (struct sd *) gspca_dev;
485
486 *val = sd->contrast;
487 return 0;
488}
489
490static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val)
491{
492 struct sd *sd = (struct sd *) gspca_dev;
493
494 sd->hue = val;
495 if (gspca_dev->streaming)
496 sethue(gspca_dev);
497 return gspca_dev->usb_err;
498}
499
500static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val)
501{
502 struct sd *sd = (struct sd *) gspca_dev;
503
504 *val = sd->hue;
505 return 0;
506}
507
508static int sd_setcolor(struct gspca_dev *gspca_dev, __s32 val)
509{
510 struct sd *sd = (struct sd *) gspca_dev;
511
512 sd->color = val;
513 if (gspca_dev->streaming)
514 setcolor(gspca_dev);
515 return gspca_dev->usb_err;
516}
517
518static int sd_getcolor(struct gspca_dev *gspca_dev, __s32 *val)
519{
520 struct sd *sd = (struct sd *) gspca_dev;
521
522 *val = sd->color;
523 return 0;
524}
525
526static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val)
527{
528 struct sd *sd = (struct sd *) gspca_dev;
529
530 sd->sharpness = val;
531 if (gspca_dev->streaming)
532 setsharpness(gspca_dev);
533 return gspca_dev->usb_err;
534}
535
536static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val)
537{
538 struct sd *sd = (struct sd *) gspca_dev;
539
540 *val = sd->sharpness;
541 return 0;
542}
543
544/* sub-driver description */
545static const struct sd_desc sd_desc = {
546 .name = MODULE_NAME,
547 .ctrls = sd_ctrls,
548 .nctrls = ARRAY_SIZE(sd_ctrls),
549 .config = sd_config,
550 .init = sd_init,
551 .isoc_init = sd_isoc_init,
552 .start = sd_start,
553 .stopN = sd_stopN,
554 .pkt_scan = sd_pkt_scan,
555};
556
557/* -- module initialisation -- */
558static const __devinitdata struct usb_device_id device_table[] = {
559 {USB_DEVICE(0x04fc, 0x1528)},
560 {}
561};
562MODULE_DEVICE_TABLE(usb, device_table);
563
564/* -- device connect -- */
565static int sd_probe(struct usb_interface *intf,
566 const struct usb_device_id *id)
567{
568 /* the video interface for isochronous transfer is 1 */
569 if (intf->cur_altsetting->desc.bInterfaceNumber != 1)
570 return -ENODEV;
571
572 return gspca_dev_probe2(intf, id, &sd_desc, sizeof(struct sd),
573 THIS_MODULE);
574}
575
576static struct usb_driver sd_driver = {
577 .name = MODULE_NAME,
578 .id_table = device_table,
579 .probe = sd_probe,
580 .disconnect = gspca_disconnect,
581#ifdef CONFIG_PM
582 .suspend = gspca_suspend,
583 .resume = gspca_resume,
584#endif
585};
586
587/* -- module insert / remove -- */
588static int __init sd_mod_init(void)
589{
590 int ret;
591
592 ret = usb_register(&sd_driver);
593 if (ret < 0)
594 return ret;
595 info("registered");
596 return 0;
597}
598static void __exit sd_mod_exit(void)
599{
600 usb_deregister(&sd_driver);
601 info("deregistered");
602}
603
604module_init(sd_mod_init);
605module_exit(sd_mod_exit);
diff --git a/drivers/media/video/gspca/spca500.c b/drivers/media/video/gspca/spca500.c
index b866c73c97db..c02beb6c1e93 100644
--- a/drivers/media/video/gspca/spca500.c
+++ b/drivers/media/video/gspca/spca500.c
@@ -57,7 +57,7 @@ struct sd {
57#define PalmPixDC85 13 57#define PalmPixDC85 13
58#define ToptroIndus 14 58#define ToptroIndus 14
59 59
60 u8 *jpeg_hdr; 60 u8 jpeg_hdr[JPEG_HDR_SZ];
61}; 61};
62 62
63/* V4L2 controls supported by the driver */ 63/* V4L2 controls supported by the driver */
@@ -669,9 +669,6 @@ static int sd_start(struct gspca_dev *gspca_dev)
669 __u8 xmult, ymult; 669 __u8 xmult, ymult;
670 670
671 /* create the JPEG header */ 671 /* create the JPEG header */
672 sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL);
673 if (!sd->jpeg_hdr)
674 return -ENOMEM;
675 jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width, 672 jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
676 0x22); /* JPEG 411 */ 673 0x22); /* JPEG 411 */
677 jpeg_set_qual(sd->jpeg_hdr, sd->quality); 674 jpeg_set_qual(sd->jpeg_hdr, sd->quality);
@@ -891,13 +888,6 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
891 gspca_dev->usb_buf[0]); 888 gspca_dev->usb_buf[0]);
892} 889}
893 890
894static void sd_stop0(struct gspca_dev *gspca_dev)
895{
896 struct sd *sd = (struct sd *) gspca_dev;
897
898 kfree(sd->jpeg_hdr);
899}
900
901static void sd_pkt_scan(struct gspca_dev *gspca_dev, 891static void sd_pkt_scan(struct gspca_dev *gspca_dev,
902 u8 *data, /* isoc packet */ 892 u8 *data, /* isoc packet */
903 int len) /* iso packet length */ 893 int len) /* iso packet length */
@@ -1055,7 +1045,6 @@ static const struct sd_desc sd_desc = {
1055 .init = sd_init, 1045 .init = sd_init,
1056 .start = sd_start, 1046 .start = sd_start,
1057 .stopN = sd_stopN, 1047 .stopN = sd_stopN,
1058 .stop0 = sd_stop0,
1059 .pkt_scan = sd_pkt_scan, 1048 .pkt_scan = sd_pkt_scan,
1060 .get_jcomp = sd_get_jcomp, 1049 .get_jcomp = sd_get_jcomp,
1061 .set_jcomp = sd_set_jcomp, 1050 .set_jcomp = sd_set_jcomp,
diff --git a/drivers/media/video/gspca/sq930x.c b/drivers/media/video/gspca/sq930x.c
new file mode 100644
index 000000000000..37cee5e063cf
--- /dev/null
+++ b/drivers/media/video/gspca/sq930x.c
@@ -0,0 +1,1402 @@
1/*
2 * SQ930x subdriver
3 *
4 * Copyright (C) 2010 Jean-François Moine <http://moinejf.free.fr>
5 * Copyright (C) 2006 -2008 Gerard Klaver <gerard at gkall dot hobby dot nl>
6 * Copyright (C) 2007 Sam Revitch <samr7@cs.washington.edu>
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 * 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#define MODULE_NAME "sq930x"
24
25#include "gspca.h"
26#include "jpeg.h"
27
28MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>\n"
29 "Gerard Klaver <gerard at gkall dot hobby dot nl\n"
30 "Sam Revitch <samr7@cs.washington.edu>");
31MODULE_DESCRIPTION("GSPCA/SQ930x USB Camera Driver");
32MODULE_LICENSE("GPL");
33
34#define BULK_TRANSFER_LEN 5128
35
36/* Structure to hold all of our device specific stuff */
37struct sd {
38 struct gspca_dev gspca_dev; /* !! must be the first item */
39
40 u16 expo;
41 u8 gain;
42
43 u8 quality; /* webcam quality 0..3 */
44#define QUALITY_DEF 1
45
46 u8 gpio[2];
47
48 u8 eof_len;
49 u8 do_ctrl;
50
51 u8 sensor;
52enum {
53 SENSOR_ICX098BQ,
54 SENSOR_LZ24BP,
55 SENSOR_MI0360,
56 SENSOR_MT9V111,
57 SENSOR_OV7660,
58 SENSOR_OV9630,
59} sensors;
60 u8 type;
61#define Generic 0
62#define Creative_live_motion 1
63
64 u8 jpeg_hdr[JPEG_HDR_SZ];
65};
66
67static int sd_setexpo(struct gspca_dev *gspca_dev, __s32 val);
68static int sd_getexpo(struct gspca_dev *gspca_dev, __s32 *val);
69static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val);
70static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val);
71
72static const struct ctrl sd_ctrls[] = {
73 {
74 {
75 .id = V4L2_CID_EXPOSURE,
76 .type = V4L2_CTRL_TYPE_INTEGER,
77 .name = "Exposure",
78 .minimum = 0x0001,
79 .maximum = 0x0fff,
80 .step = 1,
81#define EXPO_DEF 0x027d
82 .default_value = EXPO_DEF,
83 },
84 .set = sd_setexpo,
85 .get = sd_getexpo,
86 },
87 {
88 {
89 .id = V4L2_CID_GAIN,
90 .type = V4L2_CTRL_TYPE_INTEGER,
91 .name = "Gain",
92 .minimum = 0x01,
93 .maximum = 0xff,
94 .step = 1,
95#define GAIN_DEF 0x61
96 .default_value = GAIN_DEF,
97 },
98 .set = sd_setgain,
99 .get = sd_getgain,
100 },
101};
102
103static struct v4l2_pix_format vga_mode[] = {
104 {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
105 .bytesperline = 160,
106 .sizeimage = 160 * 120 * 5 / 8 + 590,
107 .colorspace = V4L2_COLORSPACE_JPEG,
108 .priv = 0},
109 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
110 .bytesperline = 320,
111 .sizeimage = 320 * 240 * 4 / 8 + 590,
112 .colorspace = V4L2_COLORSPACE_JPEG,
113 .priv = 1},
114 {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
115 .bytesperline = 640,
116 .sizeimage = 640 * 480 * 3 / 8 + 590,
117 .colorspace = V4L2_COLORSPACE_JPEG,
118 .priv = 2},
119};
120
121/* JPEG quality indexed by webcam quality */
122#define QUAL_0 90
123#define QUAL_1 85
124#define QUAL_2 75
125#define QUAL_3 70
126static const u8 quality_tb[4] = { QUAL_0, QUAL_1, QUAL_2, QUAL_3 };
127
128/* sq930x registers */
129#define SQ930_CTRL_UCBUS_IO 0x0001
130#define SQ930_CTRL_I2C_IO 0x0002
131#define SQ930_CTRL_GPIO 0x0005
132#define SQ930_CTRL_CAP_START 0x0010
133#define SQ930_CTRL_CAP_STOP 0x0011
134#define SQ930_CTRL_SET_EXPOSURE 0x001d
135#define SQ930_CTRL_RESET 0x001e
136#define SQ930_CTRL_GET_DEV_INFO 0x001f
137
138/* gpio 1 (8..15) */
139#define SQ930_GPIO_DFL_I2C_SDA 0x0001
140#define SQ930_GPIO_DFL_I2C_SCL 0x0002
141#define SQ930_GPIO_RSTBAR 0x0004
142#define SQ930_GPIO_EXTRA1 0x0040
143#define SQ930_GPIO_EXTRA2 0x0080
144/* gpio 3 (24..31) */
145#define SQ930_GPIO_POWER 0x0200
146#define SQ930_GPIO_DFL_LED 0x1000
147
148struct ucbus_write_cmd {
149 u16 bw_addr;
150 u8 bw_data;
151};
152struct i2c_write_cmd {
153 u8 reg;
154 u16 val;
155};
156
157static const struct ucbus_write_cmd icx098bq_start_0[] = {
158 {0x0354, 0x00}, {0x03fa, 0x00}, {0xf800, 0x02}, {0xf801, 0xce},
159 {0xf802, 0xc1}, {0xf804, 0x00}, {0xf808, 0x00}, {0xf809, 0x0e},
160 {0xf80a, 0x01}, {0xf80b, 0xee}, {0xf807, 0x60}, {0xf80c, 0x02},
161 {0xf80d, 0xf0}, {0xf80e, 0x03}, {0xf80f, 0x0a}, {0xf81c, 0x02},
162 {0xf81d, 0xf0}, {0xf81e, 0x03}, {0xf81f, 0x0a}, {0xf83a, 0x00},
163 {0xf83b, 0x10}, {0xf83c, 0x00}, {0xf83d, 0x4e}, {0xf810, 0x04},
164 {0xf811, 0x00}, {0xf812, 0x02}, {0xf813, 0x10}, {0xf803, 0x00},
165 {0xf814, 0x01}, {0xf815, 0x18}, {0xf816, 0x00}, {0xf817, 0x48},
166 {0xf818, 0x00}, {0xf819, 0x25}, {0xf81a, 0x00}, {0xf81b, 0x3c},
167 {0xf82f, 0x03}, {0xf820, 0xff}, {0xf821, 0x0d}, {0xf822, 0xff},
168 {0xf823, 0x07}, {0xf824, 0xff}, {0xf825, 0x03}, {0xf826, 0xff},
169 {0xf827, 0x06}, {0xf828, 0xff}, {0xf829, 0x03}, {0xf82a, 0xff},
170 {0xf82b, 0x0c}, {0xf82c, 0xfd}, {0xf82d, 0x01}, {0xf82e, 0x00},
171 {0xf830, 0x00}, {0xf831, 0x47}, {0xf832, 0x00}, {0xf833, 0x00},
172 {0xf850, 0x00}, {0xf851, 0x00}, {0xf852, 0x00}, {0xf853, 0x24},
173 {0xf854, 0x00}, {0xf855, 0x18}, {0xf856, 0x00}, {0xf857, 0x3c},
174 {0xf858, 0x00}, {0xf859, 0x0c}, {0xf85a, 0x00}, {0xf85b, 0x30},
175 {0xf85c, 0x00}, {0xf85d, 0x0c}, {0xf85e, 0x00}, {0xf85f, 0x30},
176 {0xf860, 0x00}, {0xf861, 0x48}, {0xf862, 0x01}, {0xf863, 0xdc},
177 {0xf864, 0xff}, {0xf865, 0x98}, {0xf866, 0xff}, {0xf867, 0xc0},
178 {0xf868, 0xff}, {0xf869, 0x70}, {0xf86c, 0xff}, {0xf86d, 0x00},
179 {0xf86a, 0xff}, {0xf86b, 0x48}, {0xf86e, 0xff}, {0xf86f, 0x00},
180 {0xf870, 0x01}, {0xf871, 0xdb}, {0xf872, 0x01}, {0xf873, 0xfa},
181 {0xf874, 0x01}, {0xf875, 0xdb}, {0xf876, 0x01}, {0xf877, 0xfa},
182 {0xf878, 0x0f}, {0xf879, 0x0f}, {0xf87a, 0xff}, {0xf87b, 0xff},
183 {0xf800, 0x03}
184};
185static const struct ucbus_write_cmd icx098bq_start_1[] = {
186 {0xf5f0, 0x00}, {0xf5f1, 0xcd}, {0xf5f2, 0x80}, {0xf5f3, 0x80},
187 {0xf5f4, 0xc0},
188 {0xf5f0, 0x49}, {0xf5f1, 0xcd}, {0xf5f2, 0x80}, {0xf5f3, 0x80},
189 {0xf5f4, 0xc0},
190 {0xf5fa, 0x00}, {0xf5f6, 0x00}, {0xf5f7, 0x00}, {0xf5f8, 0x00},
191 {0xf5f9, 0x00}
192};
193
194static const struct ucbus_write_cmd icx098bq_start_2[] = {
195 {0xf800, 0x02}, {0xf807, 0xff}, {0xf805, 0x82}, {0xf806, 0x00},
196 {0xf807, 0x7f}, {0xf800, 0x03},
197 {0xf800, 0x02}, {0xf807, 0xff}, {0xf805, 0x40}, {0xf806, 0x00},
198 {0xf807, 0x7f}, {0xf800, 0x03},
199 {0xf800, 0x02}, {0xf807, 0xff}, {0xf805, 0xcf}, {0xf806, 0xd0},
200 {0xf807, 0x7f}, {0xf800, 0x03},
201 {0xf800, 0x02}, {0xf807, 0xff}, {0xf805, 0x00}, {0xf806, 0x00},
202 {0xf807, 0x7f}, {0xf800, 0x03}
203};
204
205static const struct ucbus_write_cmd lz24bp_start_0[] = {
206 {0x0354, 0x00}, {0x03fa, 0x00}, {0xf800, 0x02}, {0xf801, 0xbe},
207 {0xf802, 0xc6}, {0xf804, 0x00}, {0xf808, 0x00}, {0xf809, 0x06},
208 {0xf80a, 0x01}, {0xf80b, 0xfe}, {0xf807, 0x84}, {0xf80c, 0x02},
209 {0xf80d, 0xf7}, {0xf80e, 0x03}, {0xf80f, 0x0b}, {0xf81c, 0x00},
210 {0xf81d, 0x49}, {0xf81e, 0x03}, {0xf81f, 0x0b}, {0xf83a, 0x00},
211 {0xf83b, 0x01}, {0xf83c, 0x00}, {0xf83d, 0x6b}, {0xf810, 0x03},
212 {0xf811, 0x10}, {0xf812, 0x02}, {0xf813, 0x6f}, {0xf803, 0x00},
213 {0xf814, 0x00}, {0xf815, 0x44}, {0xf816, 0x00}, {0xf817, 0x48},
214 {0xf818, 0x00}, {0xf819, 0x25}, {0xf81a, 0x00}, {0xf81b, 0x3c},
215 {0xf82f, 0x03}, {0xf820, 0xff}, {0xf821, 0x0d}, {0xf822, 0xff},
216 {0xf823, 0x07}, {0xf824, 0xfd}, {0xf825, 0x07}, {0xf826, 0xf0},
217 {0xf827, 0x0c}, {0xf828, 0xff}, {0xf829, 0x03}, {0xf82a, 0xff},
218 {0xf82b, 0x0c}, {0xf82c, 0xfc}, {0xf82d, 0x01}, {0xf82e, 0x00},
219 {0xf830, 0x00}, {0xf831, 0x47}, {0xf832, 0x00}, {0xf833, 0x00},
220 {0xf850, 0x00}, {0xf851, 0x00}, {0xf852, 0x00}, {0xf853, 0x24},
221 {0xf854, 0x00}, {0xf855, 0x0c}, {0xf856, 0x00}, {0xf857, 0x30},
222 {0xf858, 0x00}, {0xf859, 0x18}, {0xf85a, 0x00}, {0xf85b, 0x3c},
223 {0xf85c, 0x00}, {0xf85d, 0x18}, {0xf85e, 0x00}, {0xf85f, 0x3c},
224 {0xf860, 0xff}, {0xf861, 0x37}, {0xf862, 0xff}, {0xf863, 0x1d},
225 {0xf864, 0xff}, {0xf865, 0x98}, {0xf866, 0xff}, {0xf867, 0xc0},
226 {0xf868, 0x00}, {0xf869, 0x37}, {0xf86c, 0x02}, {0xf86d, 0x1d},
227 {0xf86a, 0x00}, {0xf86b, 0x37}, {0xf86e, 0x02}, {0xf86f, 0x1d},
228 {0xf870, 0x01}, {0xf871, 0xc6}, {0xf872, 0x02}, {0xf873, 0x04},
229 {0xf874, 0x01}, {0xf875, 0xc6}, {0xf876, 0x02}, {0xf877, 0x04},
230 {0xf878, 0x0f}, {0xf879, 0x0f}, {0xf87a, 0xff}, {0xf87b, 0xff},
231 {0xf800, 0x03}
232};
233static const struct ucbus_write_cmd lz24bp_start_1_gen[] = {
234 {0xf5f0, 0x00}, {0xf5f1, 0xff}, {0xf5f2, 0x80}, {0xf5f3, 0x80},
235 {0xf5f4, 0xb3},
236 {0xf5f0, 0x40}, {0xf5f1, 0xff}, {0xf5f2, 0x80}, {0xf5f3, 0x80},
237 {0xf5f4, 0xb3},
238 {0xf5fa, 0x00}, {0xf5f6, 0x00}, {0xf5f7, 0x00}, {0xf5f8, 0x00},
239 {0xf5f9, 0x00}
240};
241
242static const struct ucbus_write_cmd lz24bp_start_1_clm[] = {
243 {0xf5f0, 0x00}, {0xf5f1, 0xff}, {0xf5f2, 0x88}, {0xf5f3, 0x88},
244 {0xf5f4, 0xc0},
245 {0xf5f0, 0x40}, {0xf5f1, 0xff}, {0xf5f2, 0x88}, {0xf5f3, 0x88},
246 {0xf5f4, 0xc0},
247 {0xf5fa, 0x00}, {0xf5f6, 0x00}, {0xf5f7, 0x00}, {0xf5f8, 0x00},
248 {0xf5f9, 0x00}
249};
250
251static const struct ucbus_write_cmd lz24bp_start_2[] = {
252 {0xf800, 0x02}, {0xf807, 0xff}, {0xf805, 0x80}, {0xf806, 0x00},
253 {0xf807, 0x7f}, {0xf800, 0x03},
254 {0xf800, 0x02}, {0xf807, 0xff}, {0xf805, 0x4e}, {0xf806, 0x00},
255 {0xf807, 0x7f}, {0xf800, 0x03},
256 {0xf800, 0x02}, {0xf807, 0xff}, {0xf805, 0xc0}, {0xf806, 0x48},
257 {0xf807, 0x7f}, {0xf800, 0x03},
258 {0xf800, 0x02}, {0xf807, 0xff}, {0xf805, 0x00}, {0xf806, 0x00},
259 {0xf807, 0x7f}, {0xf800, 0x03}
260};
261
262static const struct ucbus_write_cmd mi0360_start_0[] = {
263 {0x0354, 0x00}, {0x03fa, 0x00}, {0xf332, 0xcc}, {0xf333, 0xcc},
264 {0xf334, 0xcc}, {0xf335, 0xcc}, {0xf33f, 0x00}
265};
266static const struct i2c_write_cmd mi0360_init_23[] = {
267 {0x30, 0x0040}, /* reserved - def 0x0005 */
268 {0x31, 0x0000}, /* reserved - def 0x002a */
269 {0x34, 0x0100}, /* reserved - def 0x0100 */
270 {0x3d, 0x068f}, /* reserved - def 0x068f */
271};
272static const struct i2c_write_cmd mi0360_init_24[] = {
273 {0x03, 0x01e5}, /* window height */
274 {0x04, 0x0285}, /* window width */
275};
276static const struct i2c_write_cmd mi0360_init_25[] = {
277 {0x35, 0x0020}, /* global gain */
278 {0x2b, 0x0020}, /* green1 gain */
279 {0x2c, 0x002a}, /* blue gain */
280 {0x2d, 0x0028}, /* red gain */
281 {0x2e, 0x0020}, /* green2 gain */
282};
283static const struct ucbus_write_cmd mi0360_start_1[] = {
284 {0xf5f0, 0x11}, {0xf5f1, 0x99}, {0xf5f2, 0x80}, {0xf5f3, 0x80},
285 {0xf5f4, 0xa6},
286 {0xf5f0, 0x51}, {0xf5f1, 0x99}, {0xf5f2, 0x80}, {0xf5f3, 0x80},
287 {0xf5f4, 0xa6},
288 {0xf5fa, 0x00}, {0xf5f6, 0x00}, {0xf5f7, 0x00}, {0xf5f8, 0x00},
289 {0xf5f9, 0x00}
290};
291static const struct i2c_write_cmd mi0360_start_2[] = {
292 {0x62, 0x041d}, /* reserved - def 0x0418 */
293};
294static const struct i2c_write_cmd mi0360_start_3[] = {
295 {0x05, 0x007b}, /* horiz blanking */
296};
297static const struct i2c_write_cmd mi0360_start_4[] = {
298 {0x05, 0x03f5}, /* horiz blanking */
299};
300
301static const struct i2c_write_cmd mt9v111_init_0[] = {
302 {0x01, 0x0001}, /* select IFP/SOC registers */
303 {0x06, 0x300c}, /* operating mode control */
304 {0x08, 0xcc00}, /* output format control (RGB) */
305 {0x01, 0x0004}, /* select core registers */
306};
307static const struct i2c_write_cmd mt9v111_init_1[] = {
308 {0x03, 0x01e5}, /* window height */
309 {0x04, 0x0285}, /* window width */
310};
311static const struct i2c_write_cmd mt9v111_init_2[] = {
312 {0x30, 0x7800},
313 {0x31, 0x0000},
314 {0x07, 0x3002}, /* output control */
315 {0x35, 0x0020}, /* global gain */
316 {0x2b, 0x0020}, /* green1 gain */
317 {0x2c, 0x0020}, /* blue gain */
318 {0x2d, 0x0020}, /* red gain */
319 {0x2e, 0x0020}, /* green2 gain */
320};
321static const struct ucbus_write_cmd mt9v111_start_1[] = {
322 {0xf5f0, 0x11}, {0xf5f1, 0x96}, {0xf5f2, 0x80}, {0xf5f3, 0x80},
323 {0xf5f4, 0xaa},
324 {0xf5f0, 0x51}, {0xf5f1, 0x96}, {0xf5f2, 0x80}, {0xf5f3, 0x80},
325 {0xf5f4, 0xaa},
326 {0xf5fa, 0x00}, {0xf5f6, 0x0a}, {0xf5f7, 0x0a}, {0xf5f8, 0x0a},
327 {0xf5f9, 0x0a}
328};
329static const struct i2c_write_cmd mt9v111_init_3[] = {
330 {0x62, 0x0405},
331};
332static const struct i2c_write_cmd mt9v111_init_4[] = {
333 {0x05, 0x00ce}, /* horizontal blanking */
334};
335
336static const struct ucbus_write_cmd ov7660_start_0[] = {
337 {0x0354, 0x00}, {0x03fa, 0x00}, {0xf332, 0x00}, {0xf333, 0xc0},
338 {0xf334, 0x39}, {0xf335, 0xe7}, {0xf33f, 0x03}
339};
340
341static const struct ucbus_write_cmd ov9630_start_0[] = {
342 {0x0354, 0x00}, {0x03fa, 0x00}, {0xf332, 0x00}, {0xf333, 0x00},
343 {0xf334, 0x3e}, {0xf335, 0xf8}, {0xf33f, 0x03}
344};
345
346static const struct cap_s {
347 u8 cc_sizeid;
348 u8 cc_bytes[32];
349} capconfig[4][3] = {
350 [SENSOR_ICX098BQ] = {
351 {0, /* JPEG, 160x120 */
352 {0x01, 0x1f, 0x20, 0x0e, 0x00, 0x9f, 0x02, 0xee,
353 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
354 0x02, 0x8b, 0x00, 0x8b, 0x00, 0x41, 0x01, 0x41,
355 0x01, 0x41, 0x01, 0x05, 0x40, 0x01, 0xf0, 0x00} },
356 {2, /* JPEG, 320x240 */
357 {0x01, 0x1f, 0x20, 0x0e, 0x00, 0x9f, 0x02, 0xee,
358 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
359 0x02, 0xdf, 0x01, 0x00, 0x00, 0x3f, 0x01, 0x3f,
360 0x01, 0x00, 0x00, 0x05, 0x40, 0x01, 0xf0, 0x00} },
361 {4, /* JPEG, 640x480 */
362 {0x01, 0x22, 0x20, 0x0e, 0x00, 0xa2, 0x02, 0xf0,
363 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
364 0x07, 0xe1, 0x01, 0xe1, 0x01, 0x3f, 0x01, 0x3f,
365 0x01, 0x3f, 0x01, 0x05, 0x80, 0x02, 0xe0, 0x01} },
366 },
367 [SENSOR_LZ24BP] = {
368 {0, /* JPEG, 160x120 */
369 {0x01, 0x1f, 0x20, 0x0e, 0x00, 0x9f, 0x02, 0xee,
370 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
371 0x02, 0x8b, 0x00, 0x8b, 0x00, 0x41, 0x01, 0x41,
372 0x01, 0x41, 0x01, 0x05, 0x40, 0x01, 0xf0, 0x00} },
373 {2, /* JPEG, 320x240 */
374 {0x01, 0x22, 0x20, 0x0e, 0x00, 0xa2, 0x02, 0xee,
375 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
376 0x02, 0xdf, 0x01, 0x00, 0x00, 0x3f, 0x01, 0x3f,
377 0x01, 0x00, 0x00, 0x05, 0x40, 0x01, 0xf0, 0x00} },
378 {4, /* JPEG, 640x480 */
379 {0x01, 0x22, 0x20, 0x0e, 0x00, 0xa2, 0x02, 0xf0,
380 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
381 0x07, 0xe1, 0x01, 0xe1, 0x01, 0x3f, 0x01, 0x3f,
382 0x01, 0x3f, 0x01, 0x05, 0x80, 0x02, 0xe0, 0x01} },
383 },
384 [SENSOR_MI0360] = {
385 {0, /* JPEG, 160x120 */
386 {0x05, 0x3d, 0x20, 0x0b, 0x00, 0xbd, 0x02, 0x0b,
387 0x02, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
388 0x02, 0x01, 0x01, 0x01, 0x01, 0x9f, 0x00, 0x9f,
389 0x00, 0x9f, 0x01, 0x05, 0xa0, 0x00, 0x80, 0x00} },
390 {2, /* JPEG, 320x240 */
391 {0x01, 0x02, 0x20, 0x01, 0x20, 0x82, 0x02, 0xe1,
392/*fixme 03 e3 */
393 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
394 0x02, 0xdf, 0x01, 0x00, 0x00, 0x3f, 0x01, 0x3f,
395 0x01, 0x00, 0x00, 0x05, 0x40, 0x01, 0xf0, 0x00} },
396 {4, /* JPEG, 640x480 */
397 {0x01, 0x02, 0x20, 0x01, 0x20, 0x82, 0x02, 0xe3,
398 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
399 0x07, 0xe1, 0x01, 0xe1, 0x01, 0x3f, 0x01, 0x3f,
400 0x01, 0x3f, 0x01, 0x05, 0x80, 0x02, 0xe0, 0x01} },
401 },
402 [SENSOR_MT9V111] = {
403 {0, /* JPEG, 160x120 */
404 {0x05, 0x3d, 0x20, 0x0b, 0x00, 0xbd, 0x02, 0x0b,
405 0x02, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
406 0x02, 0x01, 0x01, 0x01, 0x01, 0x9f, 0x00, 0x9f,
407 0x00, 0x9f, 0x01, 0x05, 0xa0, 0x00, 0x80, 0x00} },
408 {2, /* JPEG, 320x240 */
409 {0x01, 0x02, 0x20, 0x03, 0x20, 0x82, 0x02, 0xe3,
410 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
411 0x02, 0xdf, 0x01, 0x00, 0x00, 0x3f, 0x01, 0x3f,
412 0x01, 0x00, 0x00, 0x05, 0x40, 0x01, 0xf0, 0x00} },
413 {4, /* JPEG, 640x480 */
414 {0x01, 0x02, 0x20, 0x03, 0x20, 0x82, 0x02, 0xe3,
415 0x01, 0x02, 0x00, 0x08, 0x18, 0x12, 0x78, 0xc8,
416 0x07, 0xe1, 0x01, 0xe1, 0x01, 0x3f, 0x01, 0x3f,
417 0x01, 0x3f, 0x01, 0x05, 0x80, 0x02, 0xe0, 0x01} },
418 },
419};
420
421struct sensor_s {
422 const char *name;
423 u8 i2c_addr;
424 u8 i2c_dum;
425 u8 gpio[5];
426 u8 cmd_len;
427 const struct ucbus_write_cmd *cmd;
428};
429
430static const struct sensor_s sensor_tb[] = {
431 [SENSOR_ICX098BQ] = {
432 "icx098bp",
433 0x00, 0x00,
434 {0,
435 SQ930_GPIO_DFL_I2C_SDA | SQ930_GPIO_DFL_I2C_SCL,
436 SQ930_GPIO_DFL_I2C_SDA,
437 0,
438 SQ930_GPIO_RSTBAR
439 },
440 8, icx098bq_start_0
441 },
442 [SENSOR_LZ24BP] = {
443 "lz24bp",
444 0x00, 0x00,
445 {0,
446 SQ930_GPIO_DFL_I2C_SDA | SQ930_GPIO_DFL_I2C_SCL,
447 SQ930_GPIO_DFL_I2C_SDA,
448 0,
449 SQ930_GPIO_RSTBAR
450 },
451 8, lz24bp_start_0
452 },
453 [SENSOR_MI0360] = {
454 "mi0360",
455 0x5d, 0x80,
456 {SQ930_GPIO_RSTBAR,
457 SQ930_GPIO_DFL_I2C_SDA | SQ930_GPIO_DFL_I2C_SCL,
458 SQ930_GPIO_DFL_I2C_SDA,
459 0,
460 0
461 },
462 7, mi0360_start_0
463 },
464 [SENSOR_MT9V111] = {
465 "mt9v111",
466 0x5c, 0x7f,
467 {SQ930_GPIO_RSTBAR,
468 SQ930_GPIO_DFL_I2C_SDA | SQ930_GPIO_DFL_I2C_SCL,
469 SQ930_GPIO_DFL_I2C_SDA,
470 0,
471 0
472 },
473 7, mi0360_start_0
474 },
475 [SENSOR_OV7660] = {
476 "ov7660",
477 0x21, 0x00,
478 {0,
479 SQ930_GPIO_DFL_I2C_SDA | SQ930_GPIO_DFL_I2C_SCL,
480 SQ930_GPIO_DFL_I2C_SDA,
481 0,
482 SQ930_GPIO_RSTBAR
483 },
484 7, ov7660_start_0
485 },
486 [SENSOR_OV9630] = {
487 "ov9630",
488 0x30, 0x00,
489 {0,
490 SQ930_GPIO_DFL_I2C_SDA | SQ930_GPIO_DFL_I2C_SCL,
491 SQ930_GPIO_DFL_I2C_SDA,
492 0,
493 SQ930_GPIO_RSTBAR
494 },
495 7, ov9630_start_0
496 },
497};
498
499static void reg_r(struct gspca_dev *gspca_dev,
500 u16 value, int len)
501{
502 int ret;
503
504 if (gspca_dev->usb_err < 0)
505 return;
506 ret = usb_control_msg(gspca_dev->dev,
507 usb_rcvctrlpipe(gspca_dev->dev, 0),
508 0x0c,
509 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
510 value, 0, gspca_dev->usb_buf, len,
511 500);
512 if (ret < 0) {
513 PDEBUG(D_ERR, "reg_r %04x failed %d", value, ret);
514 gspca_dev->usb_err = ret;
515 }
516}
517
518static void reg_w(struct gspca_dev *gspca_dev, u16 value, u16 index)
519{
520 int ret;
521
522 if (gspca_dev->usb_err < 0)
523 return;
524 PDEBUG(D_USBO, "reg_w v: %04x i: %04x", value, index);
525 ret = usb_control_msg(gspca_dev->dev,
526 usb_sndctrlpipe(gspca_dev->dev, 0),
527 0x0c, /* request */
528 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
529 value, index, NULL, 0,
530 500);
531 msleep(30);
532 if (ret < 0) {
533 PDEBUG(D_ERR, "reg_w %04x %04x failed %d", value, index, ret);
534 gspca_dev->usb_err = ret;
535 }
536}
537
538static void reg_wb(struct gspca_dev *gspca_dev, u16 value, u16 index,
539 const u8 *data, int len)
540{
541 int ret;
542
543 if (gspca_dev->usb_err < 0)
544 return;
545 PDEBUG(D_USBO, "reg_wb v: %04x i: %04x %02x...%02x",
546 value, index, *data, data[len - 1]);
547 memcpy(gspca_dev->usb_buf, data, len);
548 ret = usb_control_msg(gspca_dev->dev,
549 usb_sndctrlpipe(gspca_dev->dev, 0),
550 0x0c, /* request */
551 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
552 value, index, gspca_dev->usb_buf, len,
553 1000);
554 msleep(30);
555 if (ret < 0) {
556 PDEBUG(D_ERR, "reg_wb %04x %04x failed %d", value, index, ret);
557 gspca_dev->usb_err = ret;
558 }
559}
560
561static void i2c_write(struct sd *sd,
562 const struct i2c_write_cmd *cmd,
563 int ncmds)
564{
565 struct gspca_dev *gspca_dev = &sd->gspca_dev;
566 const struct sensor_s *sensor;
567 u16 val, idx;
568 u8 *buf;
569 int ret;
570
571 if (gspca_dev->usb_err < 0)
572 return;
573
574 sensor = &sensor_tb[sd->sensor];
575
576 val = (sensor->i2c_addr << 8) | SQ930_CTRL_I2C_IO;
577 idx = (cmd->val & 0xff00) | cmd->reg;
578
579 buf = gspca_dev->usb_buf;
580 *buf++ = sensor->i2c_dum;
581 *buf++ = cmd->val;
582
583 while (--ncmds > 0) {
584 cmd++;
585 *buf++ = cmd->reg;
586 *buf++ = cmd->val >> 8;
587 *buf++ = sensor->i2c_dum;
588 *buf++ = cmd->val;
589 }
590
591 PDEBUG(D_USBO, "i2c_w v: %04x i: %04x %02x...%02x",
592 val, idx, gspca_dev->usb_buf[0], buf[-1]);
593 ret = usb_control_msg(gspca_dev->dev,
594 usb_sndctrlpipe(gspca_dev->dev, 0),
595 0x0c, /* request */
596 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
597 val, idx,
598 gspca_dev->usb_buf, buf - gspca_dev->usb_buf,
599 500);
600 if (ret < 0) {
601 PDEBUG(D_ERR, "i2c_write failed %d", ret);
602 gspca_dev->usb_err = ret;
603 }
604}
605
606static void ucbus_write(struct gspca_dev *gspca_dev,
607 const struct ucbus_write_cmd *cmd,
608 int ncmds,
609 int batchsize)
610{
611 u8 *buf;
612 u16 val, idx;
613 int len, ret;
614
615 if (gspca_dev->usb_err < 0)
616 return;
617
618#ifdef GSPCA_DEBUG
619 if ((batchsize - 1) * 3 > USB_BUF_SZ) {
620 err("Bug: usb_buf overflow");
621 gspca_dev->usb_err = -ENOMEM;
622 return;
623 }
624#endif
625
626 for (;;) {
627 len = ncmds;
628 if (len > batchsize)
629 len = batchsize;
630 ncmds -= len;
631
632 val = (cmd->bw_addr << 8) | SQ930_CTRL_UCBUS_IO;
633 idx = (cmd->bw_data << 8) | (cmd->bw_addr >> 8);
634
635 buf = gspca_dev->usb_buf;
636 while (--len > 0) {
637 cmd++;
638 *buf++ = cmd->bw_addr;
639 *buf++ = cmd->bw_addr >> 8;
640 *buf++ = cmd->bw_data;
641 }
642 if (buf != gspca_dev->usb_buf)
643 PDEBUG(D_USBO, "ucbus v: %04x i: %04x %02x...%02x",
644 val, idx,
645 gspca_dev->usb_buf[0], buf[-1]);
646 else
647 PDEBUG(D_USBO, "ucbus v: %04x i: %04x",
648 val, idx);
649 ret = usb_control_msg(gspca_dev->dev,
650 usb_sndctrlpipe(gspca_dev->dev, 0),
651 0x0c, /* request */
652 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
653 val, idx,
654 gspca_dev->usb_buf, buf - gspca_dev->usb_buf,
655 500);
656 if (ret < 0) {
657 PDEBUG(D_ERR, "ucbus_write failed %d", ret);
658 gspca_dev->usb_err = ret;
659 return;
660 }
661 msleep(30);
662 if (ncmds <= 0)
663 break;
664 cmd++;
665 }
666}
667
668static void gpio_set(struct sd *sd, u16 val, u16 mask)
669{
670 struct gspca_dev *gspca_dev = &sd->gspca_dev;
671
672 if (mask & 0x00ff) {
673 sd->gpio[0] &= ~mask;
674 sd->gpio[0] |= val;
675 reg_w(gspca_dev, 0x0100 | SQ930_CTRL_GPIO,
676 ~sd->gpio[0] << 8);
677 }
678 mask >>= 8;
679 val >>= 8;
680 if (mask) {
681 sd->gpio[1] &= ~mask;
682 sd->gpio[1] |= val;
683 reg_w(gspca_dev, 0x0300 | SQ930_CTRL_GPIO,
684 ~sd->gpio[1] << 8);
685 }
686}
687
688static void gpio_init(struct sd *sd,
689 const u8 *gpio)
690{
691 gpio_set(sd, *gpio++, 0x000f);
692 gpio_set(sd, *gpio++, 0x000f);
693 gpio_set(sd, *gpio++, 0x000f);
694 gpio_set(sd, *gpio++, 0x000f);
695 gpio_set(sd, *gpio, 0x000f);
696}
697
698static void bridge_init(struct sd *sd)
699{
700 static const struct ucbus_write_cmd clkfreq_cmd = {
701 0xf031, 0 /* SQ930_CLKFREQ_60MHZ */
702 };
703
704 ucbus_write(&sd->gspca_dev, &clkfreq_cmd, 1, 1);
705
706 gpio_set(sd, SQ930_GPIO_POWER, 0xff00);
707}
708
709static void cmos_probe(struct gspca_dev *gspca_dev)
710{
711 struct sd *sd = (struct sd *) gspca_dev;
712 int i;
713 const struct sensor_s *sensor;
714 static const u8 probe_order[] = {
715/* SENSOR_LZ24BP, (tested as ccd) */
716 SENSOR_OV9630,
717 SENSOR_MI0360,
718 SENSOR_OV7660,
719 SENSOR_MT9V111,
720 };
721
722 for (i = 0; i < ARRAY_SIZE(probe_order); i++) {
723 sensor = &sensor_tb[probe_order[i]];
724 ucbus_write(&sd->gspca_dev, sensor->cmd, sensor->cmd_len, 8);
725 gpio_init(sd, sensor->gpio);
726 msleep(100);
727 reg_r(gspca_dev, (sensor->i2c_addr << 8) | 0x001c, 1);
728 msleep(100);
729 if (gspca_dev->usb_buf[0] != 0)
730 break;
731 }
732 if (i >= ARRAY_SIZE(probe_order))
733 PDEBUG(D_PROBE, "Unknown sensor");
734 else
735 sd->sensor = probe_order[i];
736}
737
738static void mt9v111_init(struct gspca_dev *gspca_dev)
739{
740 int i, nwait;
741 static const u8 cmd_001b[] = {
742 0x00, 0x3b, 0xf6, 0x01, 0x03, 0x02, 0x00, 0x00,
743 0x00, 0x00, 0x00
744 };
745 static const u8 cmd_011b[][7] = {
746 {0x10, 0x01, 0x66, 0x08, 0x00, 0x00, 0x00},
747 {0x01, 0x00, 0x1a, 0x04, 0x00, 0x00, 0x00},
748 {0x20, 0x00, 0x10, 0x04, 0x00, 0x00, 0x00},
749 {0x02, 0x01, 0xae, 0x01, 0x00, 0x00, 0x00},
750 };
751
752 reg_wb(gspca_dev, 0x001b, 0x0000, cmd_001b, sizeof cmd_001b);
753 for (i = 0; i < ARRAY_SIZE(cmd_011b); i++) {
754 reg_wb(gspca_dev, 0x001b, 0x0000, cmd_011b[i],
755 ARRAY_SIZE(cmd_011b[0]));
756 msleep(400);
757 nwait = 20;
758 for (;;) {
759 reg_r(gspca_dev, 0x031b, 1);
760 if (gspca_dev->usb_buf[0] == 0
761 || gspca_dev->usb_err != 0)
762 break;
763 if (--nwait < 0) {
764 PDEBUG(D_PROBE, "mt9v111_init timeout");
765 gspca_dev->usb_err = -ETIME;
766 return;
767 }
768 msleep(50);
769 }
770 }
771}
772
773static void global_init(struct sd *sd, int first_time)
774{
775 switch (sd->sensor) {
776 case SENSOR_ICX098BQ:
777 if (first_time)
778 ucbus_write(&sd->gspca_dev,
779 icx098bq_start_0,
780 8, 8);
781 gpio_init(sd, sensor_tb[sd->sensor].gpio);
782 break;
783 case SENSOR_LZ24BP:
784 if (sd->type != Creative_live_motion)
785 gpio_set(sd, SQ930_GPIO_EXTRA1, 0x00ff);
786 else
787 gpio_set(sd, 0, 0x00ff);
788 msleep(50);
789 if (first_time)
790 ucbus_write(&sd->gspca_dev,
791 lz24bp_start_0,
792 8, 8);
793 gpio_init(sd, sensor_tb[sd->sensor].gpio);
794 break;
795 case SENSOR_MI0360:
796 if (first_time)
797 ucbus_write(&sd->gspca_dev,
798 mi0360_start_0,
799 ARRAY_SIZE(mi0360_start_0),
800 8);
801 gpio_init(sd, sensor_tb[sd->sensor].gpio);
802 gpio_set(sd, SQ930_GPIO_EXTRA2, SQ930_GPIO_EXTRA2);
803 break;
804 default:
805/* case SENSOR_MT9V111: */
806 if (first_time)
807 mt9v111_init(&sd->gspca_dev);
808 else
809 gpio_init(sd, sensor_tb[sd->sensor].gpio);
810 break;
811 }
812}
813
814static void lz24bp_ppl(struct sd *sd, u16 ppl)
815{
816 struct ucbus_write_cmd cmds[2] = {
817 {0xf810, ppl >> 8},
818 {0xf811, ppl}
819 };
820
821 ucbus_write(&sd->gspca_dev, cmds, ARRAY_SIZE(cmds), 2);
822}
823
824static void setexposure(struct gspca_dev *gspca_dev)
825{
826 struct sd *sd = (struct sd *) gspca_dev;
827 int i, integclks, intstartclk, frameclks, min_frclk;
828 const struct sensor_s *sensor;
829 u16 cmd;
830 u8 buf[15];
831
832 integclks = sd->expo;
833 i = 0;
834 cmd = SQ930_CTRL_SET_EXPOSURE;
835
836 switch (sd->sensor) {
837 case SENSOR_ICX098BQ: /* ccd */
838 case SENSOR_LZ24BP:
839 min_frclk = sd->sensor == SENSOR_ICX098BQ ? 0x210 : 0x26f;
840 if (integclks >= min_frclk) {
841 intstartclk = 0;
842 frameclks = integclks;
843 } else {
844 intstartclk = min_frclk - integclks;
845 frameclks = min_frclk;
846 }
847 buf[i++] = intstartclk >> 8;
848 buf[i++] = intstartclk;
849 buf[i++] = frameclks >> 8;
850 buf[i++] = frameclks;
851 buf[i++] = sd->gain;
852 break;
853 default: /* cmos */
854/* case SENSOR_MI0360: */
855/* case SENSOR_MT9V111: */
856 cmd |= 0x0100;
857 sensor = &sensor_tb[sd->sensor];
858 buf[i++] = sensor->i2c_addr; /* i2c_slave_addr */
859 buf[i++] = 0x08; /* 2 * ni2c */
860 buf[i++] = 0x09; /* reg = shutter width */
861 buf[i++] = integclks >> 8; /* val H */
862 buf[i++] = sensor->i2c_dum;
863 buf[i++] = integclks; /* val L */
864 buf[i++] = 0x35; /* reg = global gain */
865 buf[i++] = 0x00; /* val H */
866 buf[i++] = sensor->i2c_dum;
867 buf[i++] = sd->gain; /* val L */
868 buf[i++] = 0x00;
869 buf[i++] = 0x00;
870 buf[i++] = 0x00;
871 buf[i++] = 0x00;
872 buf[i++] = 0x83;
873 break;
874 }
875 reg_wb(gspca_dev, cmd, 0, buf, i);
876}
877
878/* This function is called at probe time just before sd_init */
879static int sd_config(struct gspca_dev *gspca_dev,
880 const struct usb_device_id *id)
881{
882 struct sd *sd = (struct sd *) gspca_dev;
883 struct cam *cam = &gspca_dev->cam;
884
885 sd->sensor = id->driver_info >> 8;
886 sd->type = id->driver_info;
887
888 cam->cam_mode = vga_mode;
889 cam->nmodes = ARRAY_SIZE(vga_mode);
890
891 cam->bulk = 1;
892 cam->bulk_size = BULK_TRANSFER_LEN;
893/* cam->bulk_nurbs = 2; fixme: if no setexpo sync */
894
895 sd->quality = QUALITY_DEF;
896 sd->gain = GAIN_DEF;
897 sd->expo = EXPO_DEF;
898
899 return 0;
900}
901
902/* this function is called at probe and resume time */
903static int sd_init(struct gspca_dev *gspca_dev)
904{
905 struct sd *sd = (struct sd *) gspca_dev;
906
907 sd->gpio[0] = sd->gpio[1] = 0xff; /* force gpio rewrite */
908
909/*fixme: is this needed for icx098bp and mi0360?
910 if (sd->sensor != SENSOR_LZ24BP)
911 reg_w(gspca_dev, SQ930_CTRL_RESET, 0x0000);
912 */
913
914 reg_r(gspca_dev, SQ930_CTRL_GET_DEV_INFO, 8);
915/* it returns:
916 * 03 00 12 93 0b f6 c9 00 live! ultra
917 * 03 00 07 93 0b f6 ca 00 live! ultra for notebook
918 * 03 00 12 93 0b fe c8 00 Trust WB-3500T
919 * 02 00 06 93 0b fe c8 00 Joy-IT 318S
920 * 03 00 12 93 0b f6 cf 00 icam tracer - sensor icx098bq
921 * 02 00 12 93 0b fe cf 00 ProQ Motion Webcam
922 *
923 * byte
924 * 0: 02 = usb 1.0 (12Mbit) / 03 = usb2.0 (480Mbit)
925 * 1: 00
926 * 2: 06 / 07 / 12 = mode webcam? firmware??
927 * 3: 93 chip = 930b (930b or 930c)
928 * 4: 0b
929 * 5: f6 = cdd (icx098bq, lz24bp) / fe or de = cmos (i2c) (other sensors)
930 * 6: c8 / c9 / ca / cf = mode webcam?, sensor? webcam?
931 * 7: 00
932 */
933 PDEBUG(D_PROBE, "info: %02x %02x %02x %02x %02x %02x %02x %02x",
934 gspca_dev->usb_buf[0],
935 gspca_dev->usb_buf[1],
936 gspca_dev->usb_buf[2],
937 gspca_dev->usb_buf[3],
938 gspca_dev->usb_buf[4],
939 gspca_dev->usb_buf[5],
940 gspca_dev->usb_buf[6],
941 gspca_dev->usb_buf[7]);
942
943 bridge_init(sd);
944
945 if (sd->sensor == SENSOR_MI0360) {
946
947 /* no sensor probe for icam tracer */
948 if (gspca_dev->usb_buf[5] == 0xf6) { /* if CMOS */
949 sd->sensor = SENSOR_ICX098BQ;
950 gspca_dev->cam.cam_mode = &vga_mode[1];
951 gspca_dev->cam.nmodes = 1; /* only 320x240 */
952 } else {
953 cmos_probe(gspca_dev);
954 }
955 }
956
957 PDEBUG(D_PROBE, "Sensor %s", sensor_tb[sd->sensor].name);
958
959 global_init(sd, 1);
960 return gspca_dev->usb_err;
961}
962
963/* special function to create the quantization tables of the JPEG header */
964static void sd_jpeg_set_qual(u8 *jpeg_hdr,
965 int quality)
966{
967 int i, sc1, sc2;
968
969 quality = quality_tb[quality]; /* convert to JPEG quality */
970/*
971 * approximative qualities for Y and U/V:
972 * quant = 0:94%/91% 1:91%/87% 2:82%/73% 3:69%/56%
973 * should have:
974 * quant = 0:94%/91% 1:91%/87.5% 2:81.5%/72% 3:69%/54.5%
975 */
976 sc1 = 200 - quality * 2;
977 quality = quality * 7 / 5 - 40; /* UV quality */
978 sc2 = 200 - quality * 2;
979 for (i = 0; i < 64; i++) {
980 jpeg_hdr[JPEG_QT0_OFFSET + i] =
981 (jpeg_head[JPEG_QT0_OFFSET + i] * sc1 + 50) / 100;
982 jpeg_hdr[JPEG_QT1_OFFSET + i] =
983 (jpeg_head[JPEG_QT1_OFFSET + i] * sc2 + 50) / 100;
984 }
985}
986
987/* send the start/stop commands to the webcam */
988static void send_start(struct gspca_dev *gspca_dev)
989{
990 struct sd *sd = (struct sd *) gspca_dev;
991 const struct cap_s *cap;
992 int mode, quality;
993
994 mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
995 cap = &capconfig[sd->sensor][mode];
996 quality = sd->quality;
997 reg_wb(gspca_dev, (quality << 12)
998 | 0x0a00 /* 900 for Bayer */
999 | SQ930_CTRL_CAP_START,
1000 0x0500 /* a00 for Bayer */
1001 | cap->cc_sizeid,
1002 cap->cc_bytes, 32);
1003};
1004static void send_stop(struct gspca_dev *gspca_dev)
1005{
1006 reg_w(gspca_dev, SQ930_CTRL_CAP_STOP, 0);
1007};
1008
1009/* function called at start time before URB creation */
1010static int sd_isoc_init(struct gspca_dev *gspca_dev)
1011{
1012 struct sd *sd = (struct sd *) gspca_dev;
1013
1014 gspca_dev->cam.bulk_nurbs = 1; /* there must be one URB only */
1015 sd->do_ctrl = 0;
1016 return 0;
1017}
1018
1019/* start the capture */
1020static int sd_start(struct gspca_dev *gspca_dev)
1021{
1022 struct sd *sd = (struct sd *) gspca_dev;
1023 int mode;
1024
1025 /* initialize the JPEG header */
1026 jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
1027 0x21); /* JPEG 422 */
1028 sd_jpeg_set_qual(sd->jpeg_hdr, sd->quality);
1029
1030 bridge_init(sd);
1031 global_init(sd, 0);
1032 msleep(100);
1033
1034 switch (sd->sensor) {
1035 case SENSOR_ICX098BQ:
1036 ucbus_write(gspca_dev, icx098bq_start_0,
1037 ARRAY_SIZE(icx098bq_start_0),
1038 8);
1039 ucbus_write(gspca_dev, icx098bq_start_1,
1040 ARRAY_SIZE(icx098bq_start_1),
1041 5);
1042 ucbus_write(gspca_dev, icx098bq_start_2,
1043 ARRAY_SIZE(icx098bq_start_2),
1044 6);
1045 msleep(50);
1046
1047 /* 1st start */
1048 send_start(gspca_dev);
1049 gpio_set(sd, SQ930_GPIO_EXTRA2 | SQ930_GPIO_RSTBAR, 0x00ff);
1050 msleep(70);
1051 reg_w(gspca_dev, SQ930_CTRL_CAP_STOP, 0x0000);
1052 gpio_set(sd, 0x7f, 0x00ff);
1053
1054 /* 2nd start */
1055 send_start(gspca_dev);
1056 gpio_set(sd, SQ930_GPIO_EXTRA2 | SQ930_GPIO_RSTBAR, 0x00ff);
1057 goto out;
1058 case SENSOR_LZ24BP:
1059 ucbus_write(gspca_dev, lz24bp_start_0,
1060 ARRAY_SIZE(lz24bp_start_0),
1061 8);
1062 if (sd->type != Creative_live_motion)
1063 ucbus_write(gspca_dev, lz24bp_start_1_gen,
1064 ARRAY_SIZE(lz24bp_start_1_gen),
1065 5);
1066 else
1067 ucbus_write(gspca_dev, lz24bp_start_1_clm,
1068 ARRAY_SIZE(lz24bp_start_1_clm),
1069 5);
1070 ucbus_write(gspca_dev, lz24bp_start_2,
1071 ARRAY_SIZE(lz24bp_start_2),
1072 6);
1073 mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
1074 lz24bp_ppl(sd, mode == 2 ? 0x0564 : 0x0310);
1075 msleep(10);
1076 break;
1077 case SENSOR_MI0360:
1078 ucbus_write(gspca_dev, mi0360_start_0,
1079 ARRAY_SIZE(mi0360_start_0),
1080 8);
1081 i2c_write(sd, mi0360_init_23,
1082 ARRAY_SIZE(mi0360_init_23));
1083 i2c_write(sd, mi0360_init_24,
1084 ARRAY_SIZE(mi0360_init_24));
1085 i2c_write(sd, mi0360_init_25,
1086 ARRAY_SIZE(mi0360_init_25));
1087 ucbus_write(gspca_dev, mi0360_start_1,
1088 ARRAY_SIZE(mi0360_start_1),
1089 5);
1090 i2c_write(sd, mi0360_start_2,
1091 ARRAY_SIZE(mi0360_start_2));
1092 i2c_write(sd, mi0360_start_3,
1093 ARRAY_SIZE(mi0360_start_3));
1094
1095 /* 1st start */
1096 send_start(gspca_dev);
1097 msleep(60);
1098 reg_w(gspca_dev, SQ930_CTRL_CAP_STOP, 0x0000);
1099
1100 i2c_write(sd,
1101 mi0360_start_4, ARRAY_SIZE(mi0360_start_4));
1102 break;
1103 default:
1104/* case SENSOR_MT9V111: */
1105 ucbus_write(gspca_dev, mi0360_start_0,
1106 ARRAY_SIZE(mi0360_start_0),
1107 8);
1108 i2c_write(sd, mt9v111_init_0,
1109 ARRAY_SIZE(mt9v111_init_0));
1110 i2c_write(sd, mt9v111_init_1,
1111 ARRAY_SIZE(mt9v111_init_1));
1112 i2c_write(sd, mt9v111_init_2,
1113 ARRAY_SIZE(mt9v111_init_2));
1114 ucbus_write(gspca_dev, mt9v111_start_1,
1115 ARRAY_SIZE(mt9v111_start_1),
1116 8);
1117 i2c_write(sd, mt9v111_init_3,
1118 ARRAY_SIZE(mt9v111_init_3));
1119 i2c_write(sd, mt9v111_init_4,
1120 ARRAY_SIZE(mt9v111_init_4));
1121 break;
1122 }
1123
1124 send_start(gspca_dev);
1125out:
1126 msleep(1000);
1127
1128 sd->eof_len = 0; /* init packet scan */
1129
1130 if (sd->sensor == SENSOR_MT9V111)
1131 gpio_set(sd, SQ930_GPIO_DFL_LED, SQ930_GPIO_DFL_LED);
1132
1133 sd->do_ctrl = 1; /* set the exposure */
1134
1135 return gspca_dev->usb_err;
1136}
1137
1138static void sd_stopN(struct gspca_dev *gspca_dev)
1139{
1140 struct sd *sd = (struct sd *) gspca_dev;
1141
1142 if (sd->sensor == SENSOR_MT9V111)
1143 gpio_set(sd, 0, SQ930_GPIO_DFL_LED);
1144 send_stop(gspca_dev);
1145}
1146
1147/* function called when the application gets a new frame */
1148/* It sets the exposure if required and restart the bulk transfer. */
1149static void sd_dq_callback(struct gspca_dev *gspca_dev)
1150{
1151 struct sd *sd = (struct sd *) gspca_dev;
1152 int ret;
1153
1154 if (!sd->do_ctrl || gspca_dev->cam.bulk_nurbs != 0)
1155 return;
1156 sd->do_ctrl = 0;
1157
1158 setexposure(gspca_dev);
1159
1160 gspca_dev->cam.bulk_nurbs = 1;
1161 ret = usb_submit_urb(gspca_dev->urb[0], GFP_ATOMIC);
1162 if (ret < 0)
1163 PDEBUG(D_ERR|D_PACK, "sd_dq_callback() err %d", ret);
1164
1165 /* wait a little time, otherwise the webcam crashes */
1166 msleep(100);
1167}
1168
1169/* move a packet adding 0x00 after 0xff */
1170static void add_packet(struct gspca_dev *gspca_dev,
1171 u8 *data,
1172 int len)
1173{
1174 int i;
1175
1176 i = 0;
1177 do {
1178 if (data[i] == 0xff) {
1179 gspca_frame_add(gspca_dev, INTER_PACKET,
1180 data, i + 1);
1181 len -= i;
1182 data += i;
1183 *data = 0x00;
1184 i = 0;
1185 }
1186 } while (++i < len);
1187 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
1188}
1189
1190/* end a frame and start a new one */
1191static void eof_sof(struct gspca_dev *gspca_dev)
1192{
1193 struct sd *sd = (struct sd *) gspca_dev;
1194 static const u8 ffd9[] = {0xff, 0xd9};
1195
1196 /* if control set, stop bulk transfer */
1197 if (sd->do_ctrl
1198 && gspca_dev->last_packet_type == INTER_PACKET)
1199 gspca_dev->cam.bulk_nurbs = 0;
1200 gspca_frame_add(gspca_dev, LAST_PACKET,
1201 ffd9, 2);
1202 gspca_frame_add(gspca_dev, FIRST_PACKET,
1203 sd->jpeg_hdr, JPEG_HDR_SZ);
1204}
1205
1206static void sd_pkt_scan(struct gspca_dev *gspca_dev,
1207 u8 *data, /* isoc packet */
1208 int len) /* iso packet length */
1209{
1210 struct sd *sd = (struct sd *) gspca_dev;
1211 u8 *p;
1212 int l;
1213
1214 len -= 8; /* ignore last 8 bytes (00 00 55 aa 55 aa 00 00) */
1215
1216 /*
1217 * the end/start of frame is indicated by
1218 * 0x00 * 16 - 0xab * 8
1219 * aligned on 8 bytes boundary
1220 */
1221 if (sd->eof_len != 0) { /* if 'abababab' in previous pkt */
1222 if (*((u32 *) data) == 0xabababab) {
1223 /*fixme: should remove previous 0000ababab*/
1224 eof_sof(gspca_dev);
1225 data += 4;
1226 len -= 4;
1227 }
1228 sd->eof_len = 0;
1229 }
1230 p = data;
1231 l = len;
1232 for (;;) {
1233 if (*((u32 *) p) == 0xabababab) {
1234 if (l < 8) { /* (may be 4 only) */
1235 sd->eof_len = 1;
1236 break;
1237 }
1238 if (*((u32 *) p + 1) == 0xabababab) {
1239 add_packet(gspca_dev, data, p - data - 16);
1240 /* remove previous zeros */
1241 eof_sof(gspca_dev);
1242 p += 8;
1243 l -= 8;
1244 if (l <= 0)
1245 return;
1246 len = l;
1247 data = p;
1248 continue;
1249 }
1250 }
1251 p += 4;
1252 l -= 4;
1253 if (l <= 0)
1254 break;
1255 }
1256 add_packet(gspca_dev, data, len);
1257}
1258
1259static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val)
1260{
1261 struct sd *sd = (struct sd *) gspca_dev;
1262
1263 sd->gain = val;
1264 if (gspca_dev->streaming)
1265 sd->do_ctrl = 1;
1266 return 0;
1267}
1268
1269static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val)
1270{
1271 struct sd *sd = (struct sd *) gspca_dev;
1272
1273 *val = sd->gain;
1274 return 0;
1275}
1276static int sd_setexpo(struct gspca_dev *gspca_dev, __s32 val)
1277{
1278 struct sd *sd = (struct sd *) gspca_dev;
1279
1280 sd->expo = val;
1281 if (gspca_dev->streaming)
1282 sd->do_ctrl = 1;
1283 return 0;
1284}
1285
1286static int sd_getexpo(struct gspca_dev *gspca_dev, __s32 *val)
1287{
1288 struct sd *sd = (struct sd *) gspca_dev;
1289
1290 *val = sd->expo;
1291 return 0;
1292}
1293
1294static int sd_set_jcomp(struct gspca_dev *gspca_dev,
1295 struct v4l2_jpegcompression *jcomp)
1296{
1297 struct sd *sd = (struct sd *) gspca_dev;
1298 int quality;
1299
1300 if (jcomp->quality >= (QUAL_0 + QUAL_1) / 2)
1301 quality = 0;
1302 else if (jcomp->quality >= (QUAL_1 + QUAL_2) / 2)
1303 quality = 1;
1304 else if (jcomp->quality >= (QUAL_2 + QUAL_3) / 2)
1305 quality = 2;
1306 else
1307 quality = 3;
1308
1309 if (quality != sd->quality) {
1310 sd->quality = quality;
1311 if (gspca_dev->streaming) {
1312 send_stop(gspca_dev);
1313 sd_jpeg_set_qual(sd->jpeg_hdr, sd->quality);
1314 msleep(70);
1315 send_start(gspca_dev);
1316 }
1317 }
1318 return gspca_dev->usb_err;
1319}
1320
1321static int sd_get_jcomp(struct gspca_dev *gspca_dev,
1322 struct v4l2_jpegcompression *jcomp)
1323{
1324 struct sd *sd = (struct sd *) gspca_dev;
1325
1326 memset(jcomp, 0, sizeof *jcomp);
1327 jcomp->quality = quality_tb[sd->quality];
1328 jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT
1329 | V4L2_JPEG_MARKER_DQT;
1330 return 0;
1331}
1332
1333/* sub-driver description */
1334static const struct sd_desc sd_desc = {
1335 .name = MODULE_NAME,
1336 .ctrls = sd_ctrls,
1337 .nctrls = ARRAY_SIZE(sd_ctrls),
1338 .config = sd_config,
1339 .init = sd_init,
1340 .isoc_init = sd_isoc_init,
1341 .start = sd_start,
1342 .stopN = sd_stopN,
1343 .pkt_scan = sd_pkt_scan,
1344 .dq_callback = sd_dq_callback,
1345 .get_jcomp = sd_get_jcomp,
1346 .set_jcomp = sd_set_jcomp,
1347};
1348
1349/* Table of supported USB devices */
1350#define ST(sensor, type) \
1351 .driver_info = (SENSOR_ ## sensor << 8) \
1352 | (type)
1353static const __devinitdata struct usb_device_id device_table[] = {
1354 {USB_DEVICE(0x041e, 0x4038), ST(MI0360, 0)},
1355 {USB_DEVICE(0x041e, 0x403c), ST(LZ24BP, 0)},
1356 {USB_DEVICE(0x041e, 0x403d), ST(LZ24BP, 0)},
1357 {USB_DEVICE(0x041e, 0x4041), ST(LZ24BP, Creative_live_motion)},
1358 {USB_DEVICE(0x2770, 0x930b), ST(MI0360, 0)},
1359 {USB_DEVICE(0x2770, 0x930c), ST(MI0360, 0)},
1360 {}
1361};
1362MODULE_DEVICE_TABLE(usb, device_table);
1363
1364
1365/* -- device connect -- */
1366static int sd_probe(struct usb_interface *intf,
1367 const struct usb_device_id *id)
1368{
1369 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
1370 THIS_MODULE);
1371}
1372
1373static struct usb_driver sd_driver = {
1374 .name = MODULE_NAME,
1375 .id_table = device_table,
1376 .probe = sd_probe,
1377 .disconnect = gspca_disconnect,
1378#ifdef CONFIG_PM
1379 .suspend = gspca_suspend,
1380 .resume = gspca_resume,
1381#endif
1382};
1383
1384/* -- module insert / remove -- */
1385static int __init sd_mod_init(void)
1386{
1387 int ret;
1388
1389 ret = usb_register(&sd_driver);
1390 if (ret < 0)
1391 return ret;
1392 info("registered");
1393 return 0;
1394}
1395static void __exit sd_mod_exit(void)
1396{
1397 usb_deregister(&sd_driver);
1398 info("deregistered");
1399}
1400
1401module_init(sd_mod_init);
1402module_exit(sd_mod_exit);
diff --git a/drivers/media/video/gspca/stk014.c b/drivers/media/video/gspca/stk014.c
index 0fb534210a2c..2aedf4b1bfa3 100644
--- a/drivers/media/video/gspca/stk014.c
+++ b/drivers/media/video/gspca/stk014.c
@@ -36,11 +36,11 @@ struct sd {
36 unsigned char colors; 36 unsigned char colors;
37 unsigned char lightfreq; 37 unsigned char lightfreq;
38 u8 quality; 38 u8 quality;
39#define QUALITY_MIN 60 39#define QUALITY_MIN 70
40#define QUALITY_MAX 95 40#define QUALITY_MAX 95
41#define QUALITY_DEF 80 41#define QUALITY_DEF 88
42 42
43 u8 *jpeg_hdr; 43 u8 jpeg_hdr[JPEG_HDR_SZ];
44}; 44};
45 45
46/* V4L2 controls supported by the driver */ 46/* V4L2 controls supported by the driver */
@@ -337,9 +337,6 @@ static int sd_start(struct gspca_dev *gspca_dev)
337 int ret, value; 337 int ret, value;
338 338
339 /* create the JPEG header */ 339 /* create the JPEG header */
340 sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL);
341 if (!sd->jpeg_hdr)
342 return -ENOMEM;
343 jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width, 340 jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
344 0x22); /* JPEG 411 */ 341 0x22); /* JPEG 411 */
345 jpeg_set_qual(sd->jpeg_hdr, sd->quality); 342 jpeg_set_qual(sd->jpeg_hdr, sd->quality);
@@ -412,13 +409,6 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
412 PDEBUG(D_STREAM, "camera stopped"); 409 PDEBUG(D_STREAM, "camera stopped");
413} 410}
414 411
415static void sd_stop0(struct gspca_dev *gspca_dev)
416{
417 struct sd *sd = (struct sd *) gspca_dev;
418
419 kfree(sd->jpeg_hdr);
420}
421
422static void sd_pkt_scan(struct gspca_dev *gspca_dev, 412static void sd_pkt_scan(struct gspca_dev *gspca_dev,
423 u8 *data, /* isoc packet */ 413 u8 *data, /* isoc packet */
424 int len) /* iso packet length */ 414 int len) /* iso packet length */
@@ -578,7 +568,6 @@ static const struct sd_desc sd_desc = {
578 .init = sd_init, 568 .init = sd_init,
579 .start = sd_start, 569 .start = sd_start,
580 .stopN = sd_stopN, 570 .stopN = sd_stopN,
581 .stop0 = sd_stop0,
582 .pkt_scan = sd_pkt_scan, 571 .pkt_scan = sd_pkt_scan,
583 .querymenu = sd_querymenu, 572 .querymenu = sd_querymenu,
584 .get_jcomp = sd_get_jcomp, 573 .get_jcomp = sd_get_jcomp,
diff --git a/drivers/media/video/gspca/stv06xx/stv06xx.h b/drivers/media/video/gspca/stv06xx/stv06xx.h
index 992ce530f138..053a27e3a400 100644
--- a/drivers/media/video/gspca/stv06xx/stv06xx.h
+++ b/drivers/media/video/gspca/stv06xx/stv06xx.h
@@ -30,6 +30,7 @@
30#ifndef STV06XX_H_ 30#ifndef STV06XX_H_
31#define STV06XX_H_ 31#define STV06XX_H_
32 32
33#include <linux/slab.h>
33#include "gspca.h" 34#include "gspca.h"
34 35
35#define MODULE_NAME "STV06xx" 36#define MODULE_NAME "STV06xx"
diff --git a/drivers/media/video/gspca/sunplus.c b/drivers/media/video/gspca/sunplus.c
index 0c786e00ebcf..21d82bab0c2e 100644
--- a/drivers/media/video/gspca/sunplus.c
+++ b/drivers/media/video/gspca/sunplus.c
@@ -54,7 +54,7 @@ struct sd {
54#define MegapixV4 4 54#define MegapixV4 4
55#define MegaImageVI 5 55#define MegaImageVI 5
56 56
57 u8 *jpeg_hdr; 57 u8 jpeg_hdr[JPEG_HDR_SZ];
58}; 58};
59 59
60/* V4L2 controls supported by the driver */ 60/* V4L2 controls supported by the driver */
@@ -842,9 +842,6 @@ static int sd_start(struct gspca_dev *gspca_dev)
842 int enable; 842 int enable;
843 843
844 /* create the JPEG header */ 844 /* create the JPEG header */
845 sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL);
846 if (!sd->jpeg_hdr)
847 return -ENOMEM;
848 jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width, 845 jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
849 0x22); /* JPEG 411 */ 846 0x22); /* JPEG 411 */
850 jpeg_set_qual(sd->jpeg_hdr, sd->quality); 847 jpeg_set_qual(sd->jpeg_hdr, sd->quality);
@@ -954,13 +951,6 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
954 } 951 }
955} 952}
956 953
957static void sd_stop0(struct gspca_dev *gspca_dev)
958{
959 struct sd *sd = (struct sd *) gspca_dev;
960
961 kfree(sd->jpeg_hdr);
962}
963
964static void sd_pkt_scan(struct gspca_dev *gspca_dev, 954static void sd_pkt_scan(struct gspca_dev *gspca_dev,
965 u8 *data, /* isoc packet */ 955 u8 *data, /* isoc packet */
966 int len) /* iso packet length */ 956 int len) /* iso packet length */
@@ -1162,7 +1152,6 @@ static const struct sd_desc sd_desc = {
1162 .init = sd_init, 1152 .init = sd_init,
1163 .start = sd_start, 1153 .start = sd_start,
1164 .stopN = sd_stopN, 1154 .stopN = sd_stopN,
1165 .stop0 = sd_stop0,
1166 .pkt_scan = sd_pkt_scan, 1155 .pkt_scan = sd_pkt_scan,
1167 .get_jcomp = sd_get_jcomp, 1156 .get_jcomp = sd_get_jcomp,
1168 .set_jcomp = sd_set_jcomp, 1157 .set_jcomp = sd_set_jcomp,
diff --git a/drivers/media/video/gspca/t613.c b/drivers/media/video/gspca/t613.c
index 63014372adbc..2a0f12d55e48 100644
--- a/drivers/media/video/gspca/t613.c
+++ b/drivers/media/video/gspca/t613.c
@@ -1,5 +1,7 @@
1/* 1/*
2 * V4L2 by Jean-Francois Moine <http://moinejf.free.fr> 2 * T613 subdriver
3 *
4 * Copyright (C) 2010 Jean-Francois Moine (http://moinejf.free.fr)
3 * 5 *
4 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
@@ -26,6 +28,7 @@
26 28
27#define MODULE_NAME "t613" 29#define MODULE_NAME "t613"
28 30
31#include <linux/slab.h>
29#include "gspca.h" 32#include "gspca.h"
30 33
31#define V4L2_CID_EFFECTS (V4L2_CID_PRIVATE_BASE + 0) 34#define V4L2_CID_EFFECTS (V4L2_CID_PRIVATE_BASE + 0)
@@ -44,18 +47,20 @@ struct sd {
44 u8 gamma; 47 u8 gamma;
45 u8 sharpness; 48 u8 sharpness;
46 u8 freq; 49 u8 freq;
47 u8 red_balance; /* split balance */ 50 u8 red_gain;
48 u8 blue_balance; 51 u8 blue_gain;
49 u8 global_gain; /* aka gain */ 52 u8 green_gain;
50 u8 whitebalance; /* set default r/g/b and activate */ 53 u8 awb; /* set default r/g/b and activate */
51 u8 mirror; 54 u8 mirror;
52 u8 effect; 55 u8 effect;
53 56
54 u8 sensor; 57 u8 sensor;
55#define SENSOR_OM6802 0 58enum {
56#define SENSOR_OTHER 1 59 SENSOR_OM6802,
57#define SENSOR_TAS5130A 2 60 SENSOR_OTHER,
58#define SENSOR_LT168G 3 /* must verify if this is the actual model */ 61 SENSOR_TAS5130A,
62 SENSOR_LT168G, /* must verify if this is the actual model */
63} sensors;
59}; 64};
60 65
61/* V4L2 controls supported by the driver */ 66/* V4L2 controls supported by the driver */
@@ -74,24 +79,22 @@ static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val);
74static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val); 79static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val);
75static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val); 80static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val);
76 81
77 82static int sd_setawb(struct gspca_dev *gspca_dev, __s32 val);
78static int sd_setwhitebalance(struct gspca_dev *gspca_dev, __s32 val); 83static int sd_getawb(struct gspca_dev *gspca_dev, __s32 *val);
79static int sd_getwhitebalance(struct gspca_dev *gspca_dev, __s32 *val); 84static int sd_setblue_gain(struct gspca_dev *gspca_dev, __s32 val);
80static int sd_setblue_balance(struct gspca_dev *gspca_dev, __s32 val); 85static int sd_getblue_gain(struct gspca_dev *gspca_dev, __s32 *val);
81static int sd_getblue_balance(struct gspca_dev *gspca_dev, __s32 *val); 86static int sd_setred_gain(struct gspca_dev *gspca_dev, __s32 val);
82static int sd_setred_balance(struct gspca_dev *gspca_dev, __s32 val); 87static int sd_getred_gain(struct gspca_dev *gspca_dev, __s32 *val);
83static int sd_getred_balance(struct gspca_dev *gspca_dev, __s32 *val); 88static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val);
84static int sd_setglobal_gain(struct gspca_dev *gspca_dev, __s32 val); 89static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val);
85static int sd_getglobal_gain(struct gspca_dev *gspca_dev, __s32 *val); 90
86 91static int sd_setmirror(struct gspca_dev *gspca_dev, __s32 val);
87static int sd_setflip(struct gspca_dev *gspca_dev, __s32 val); 92static int sd_getmirror(struct gspca_dev *gspca_dev, __s32 *val);
88static int sd_getflip(struct gspca_dev *gspca_dev, __s32 *val);
89static int sd_seteffect(struct gspca_dev *gspca_dev, __s32 val); 93static int sd_seteffect(struct gspca_dev *gspca_dev, __s32 val);
90static int sd_geteffect(struct gspca_dev *gspca_dev, __s32 *val); 94static int sd_geteffect(struct gspca_dev *gspca_dev, __s32 *val);
91static int sd_querymenu(struct gspca_dev *gspca_dev, 95static int sd_querymenu(struct gspca_dev *gspca_dev,
92 struct v4l2_querymenu *menu); 96 struct v4l2_querymenu *menu);
93 97
94
95static const struct ctrl sd_ctrls[] = { 98static const struct ctrl sd_ctrls[] = {
96 { 99 {
97 { 100 {
@@ -177,8 +180,8 @@ static const struct ctrl sd_ctrls[] = {
177#define MIRROR_DEF 0 180#define MIRROR_DEF 0
178 .default_value = MIRROR_DEF, 181 .default_value = MIRROR_DEF,
179 }, 182 },
180 .set = sd_setflip, 183 .set = sd_setmirror,
181 .get = sd_getflip 184 .get = sd_getmirror
182 }, 185 },
183 { 186 {
184 { 187 {
@@ -198,15 +201,15 @@ static const struct ctrl sd_ctrls[] = {
198 { 201 {
199 .id = V4L2_CID_AUTO_WHITE_BALANCE, 202 .id = V4L2_CID_AUTO_WHITE_BALANCE,
200 .type = V4L2_CTRL_TYPE_INTEGER, 203 .type = V4L2_CTRL_TYPE_INTEGER,
201 .name = "White Balance", 204 .name = "Auto White Balance",
202 .minimum = 0, 205 .minimum = 0,
203 .maximum = 1, 206 .maximum = 1,
204 .step = 1, 207 .step = 1,
205#define WHITE_BALANCE_DEF 0 208#define AWB_DEF 0
206 .default_value = WHITE_BALANCE_DEF, 209 .default_value = AWB_DEF,
207 }, 210 },
208 .set = sd_setwhitebalance, 211 .set = sd_setawb,
209 .get = sd_getwhitebalance 212 .get = sd_getawb
210 }, 213 },
211 { 214 {
212 { 215 {
@@ -244,11 +247,11 @@ static const struct ctrl sd_ctrls[] = {
244 .minimum = 0x10, 247 .minimum = 0x10,
245 .maximum = 0x40, 248 .maximum = 0x40,
246 .step = 1, 249 .step = 1,
247#define BLUE_BALANCE_DEF 0x20 250#define BLUE_GAIN_DEF 0x20
248 .default_value = BLUE_BALANCE_DEF, 251 .default_value = BLUE_GAIN_DEF,
249 }, 252 },
250 .set = sd_setblue_balance, 253 .set = sd_setblue_gain,
251 .get = sd_getblue_balance, 254 .get = sd_getblue_gain,
252 }, 255 },
253 { 256 {
254 { 257 {
@@ -258,11 +261,11 @@ static const struct ctrl sd_ctrls[] = {
258 .minimum = 0x10, 261 .minimum = 0x10,
259 .maximum = 0x40, 262 .maximum = 0x40,
260 .step = 1, 263 .step = 1,
261#define RED_BALANCE_DEF 0x20 264#define RED_GAIN_DEF 0x20
262 .default_value = RED_BALANCE_DEF, 265 .default_value = RED_GAIN_DEF,
263 }, 266 },
264 .set = sd_setred_balance, 267 .set = sd_setred_gain,
265 .get = sd_getred_balance, 268 .get = sd_getred_gain,
266 }, 269 },
267 { 270 {
268 { 271 {
@@ -272,24 +275,14 @@ static const struct ctrl sd_ctrls[] = {
272 .minimum = 0x10, 275 .minimum = 0x10,
273 .maximum = 0x40, 276 .maximum = 0x40,
274 .step = 1, 277 .step = 1,
275#define global_gain_DEF 0x20 278#define GAIN_DEF 0x20
276 .default_value = global_gain_DEF, 279 .default_value = GAIN_DEF,
277 }, 280 },
278 .set = sd_setglobal_gain, 281 .set = sd_setgain,
279 .get = sd_getglobal_gain, 282 .get = sd_getgain,
280 }, 283 },
281}; 284};
282 285
283static char *effects_control[] = {
284 "Normal",
285 "Emboss", /* disabled */
286 "Monochrome",
287 "Sepia",
288 "Sketch",
289 "Sun Effect", /* disabled */
290 "Negative",
291};
292
293static const struct v4l2_pix_format vga_mode_t16[] = { 286static const struct v4l2_pix_format vga_mode_t16[] = {
294 {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, 287 {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
295 .bytesperline = 160, 288 .bytesperline = 160,
@@ -327,7 +320,6 @@ struct additional_sensor_data {
327 const u8 data1[10]; 320 const u8 data1[10];
328 const u8 data2[9]; 321 const u8 data2[9];
329 const u8 data3[9]; 322 const u8 data3[9];
330 const u8 data4[4];
331 const u8 data5[6]; 323 const u8 data5[6];
332 const u8 stream[4]; 324 const u8 stream[4];
333}; 325};
@@ -375,7 +367,7 @@ static const u8 n4_lt168g[] = {
375}; 367};
376 368
377static const struct additional_sensor_data sensor_data[] = { 369static const struct additional_sensor_data sensor_data[] = {
378 { /* 0: OM6802 */ 370[SENSOR_OM6802] = {
379 .n3 = 371 .n3 =
380 {0x61, 0x68, 0x65, 0x0a, 0x60, 0x04}, 372 {0x61, 0x68, 0x65, 0x0a, 0x60, 0x04},
381 .n4 = n4_om6802, 373 .n4 = n4_om6802,
@@ -392,14 +384,12 @@ static const struct additional_sensor_data sensor_data[] = {
392 .data3 = 384 .data3 =
393 {0x80, 0xff, 0xff, 0x80, 0xff, 0xff, 0x80, 0xff, 385 {0x80, 0xff, 0xff, 0x80, 0xff, 0xff, 0x80, 0xff,
394 0xff}, 386 0xff},
395 .data4 = /*Freq (50/60Hz). Splitted for test purpose */
396 {0x66, 0xca, 0xa8, 0xf0},
397 .data5 = /* this could be removed later */ 387 .data5 = /* this could be removed later */
398 {0x0c, 0x03, 0xab, 0x13, 0x81, 0x23}, 388 {0x0c, 0x03, 0xab, 0x13, 0x81, 0x23},
399 .stream = 389 .stream =
400 {0x0b, 0x04, 0x0a, 0x78}, 390 {0x0b, 0x04, 0x0a, 0x78},
401 }, 391 },
402 { /* 1: OTHER */ 392[SENSOR_OTHER] = {
403 .n3 = 393 .n3 =
404 {0x61, 0xc2, 0x65, 0x88, 0x60, 0x00}, 394 {0x61, 0xc2, 0x65, 0x88, 0x60, 0x00},
405 .n4 = n4_other, 395 .n4 = n4_other,
@@ -416,14 +406,12 @@ static const struct additional_sensor_data sensor_data[] = {
416 .data3 = 406 .data3 =
417 {0x4e, 0x9c, 0xec, 0x40, 0x80, 0xc0, 0x48, 0x96, 407 {0x4e, 0x9c, 0xec, 0x40, 0x80, 0xc0, 0x48, 0x96,
418 0xd9}, 408 0xd9},
419 .data4 =
420 {0x66, 0x00, 0xa8, 0xa8},
421 .data5 = 409 .data5 =
422 {0x0c, 0x03, 0xab, 0x29, 0x81, 0x69}, 410 {0x0c, 0x03, 0xab, 0x29, 0x81, 0x69},
423 .stream = 411 .stream =
424 {0x0b, 0x04, 0x0a, 0x00}, 412 {0x0b, 0x04, 0x0a, 0x00},
425 }, 413 },
426 { /* 2: TAS5130A */ 414[SENSOR_TAS5130A] = {
427 .n3 = 415 .n3 =
428 {0x61, 0xc2, 0x65, 0x0d, 0x60, 0x08}, 416 {0x61, 0xc2, 0x65, 0x0d, 0x60, 0x08},
429 .n4 = n4_tas5130a, 417 .n4 = n4_tas5130a,
@@ -440,14 +428,12 @@ static const struct additional_sensor_data sensor_data[] = {
440 .data3 = 428 .data3 =
441 {0x60, 0xa8, 0xe0, 0x60, 0xa8, 0xe0, 0x60, 0xa8, 429 {0x60, 0xa8, 0xe0, 0x60, 0xa8, 0xe0, 0x60, 0xa8,
442 0xe0}, 430 0xe0},
443 .data4 = /* Freq (50/60Hz). Splitted for test purpose */
444 {0x66, 0x00, 0xa8, 0xe8},
445 .data5 = 431 .data5 =
446 {0x0c, 0x03, 0xab, 0x10, 0x81, 0x20}, 432 {0x0c, 0x03, 0xab, 0x10, 0x81, 0x20},
447 .stream = 433 .stream =
448 {0x0b, 0x04, 0x0a, 0x40}, 434 {0x0b, 0x04, 0x0a, 0x40},
449 }, 435 },
450 { /* 3: LT168G */ 436[SENSOR_LT168G] = {
451 .n3 = {0x61, 0xc2, 0x65, 0x68, 0x60, 0x00}, 437 .n3 = {0x61, 0xc2, 0x65, 0x68, 0x60, 0x00},
452 .n4 = n4_lt168g, 438 .n4 = n4_lt168g,
453 .n4sz = sizeof n4_lt168g, 439 .n4sz = sizeof n4_lt168g,
@@ -460,7 +446,6 @@ static const struct additional_sensor_data sensor_data[] = {
460 0xff}, 446 0xff},
461 .data3 = {0x40, 0x80, 0xc0, 0x50, 0xa0, 0xf0, 0x53, 0xa6, 447 .data3 = {0x40, 0x80, 0xc0, 0x50, 0xa0, 0xf0, 0x53, 0xa6,
462 0xff}, 448 0xff},
463 .data4 = {0x66, 0x41, 0xa8, 0xf0},
464 .data5 = {0x0c, 0x03, 0xab, 0x4b, 0x81, 0x2b}, 449 .data5 = {0x0c, 0x03, 0xab, 0x4b, 0x81, 0x2b},
465 .stream = {0x0b, 0x04, 0x0a, 0x28}, 450 .stream = {0x0b, 0x04, 0x0a, 0x28},
466 }, 451 },
@@ -469,6 +454,15 @@ static const struct additional_sensor_data sensor_data[] = {
469#define MAX_EFFECTS 7 454#define MAX_EFFECTS 7
470/* easily done by soft, this table could be removed, 455/* easily done by soft, this table could be removed,
471 * i keep it here just in case */ 456 * i keep it here just in case */
457static char *effects_control[MAX_EFFECTS] = {
458 "Normal",
459 "Emboss", /* disabled */
460 "Monochrome",
461 "Sepia",
462 "Sketch",
463 "Sun Effect", /* disabled */
464 "Negative",
465};
472static const u8 effects_table[MAX_EFFECTS][6] = { 466static const u8 effects_table[MAX_EFFECTS][6] = {
473 {0xa8, 0xe8, 0xc6, 0xd2, 0xc0, 0x00}, /* Normal */ 467 {0xa8, 0xe8, 0xc6, 0xd2, 0xc0, 0x00}, /* Normal */
474 {0xa8, 0xc8, 0xc6, 0x52, 0xc0, 0x04}, /* Repujar */ 468 {0xa8, 0xc8, 0xc6, 0x52, 0xc0, 0x04}, /* Repujar */
@@ -480,40 +474,41 @@ static const u8 effects_table[MAX_EFFECTS][6] = {
480}; 474};
481 475
482static const u8 gamma_table[GAMMA_MAX][17] = { 476static const u8 gamma_table[GAMMA_MAX][17] = {
483 {0x00, 0x3e, 0x69, 0x85, 0x95, 0xa1, 0xae, 0xb9, /* 0 */ 477/* gamma table from cam1690.ini */
484 0xc2, 0xcb, 0xd4, 0xdb, 0xe3, 0xea, 0xf1, 0xf8, 478 {0x00, 0x00, 0x01, 0x04, 0x08, 0x0e, 0x16, 0x21, /* 0 */
479 0x2e, 0x3d, 0x50, 0x65, 0x7d, 0x99, 0xb8, 0xdb,
485 0xff}, 480 0xff},
486 {0x00, 0x33, 0x5a, 0x75, 0x85, 0x93, 0xa1, 0xad, /* 1 */ 481 {0x00, 0x01, 0x03, 0x08, 0x0e, 0x16, 0x21, 0x2d, /* 1 */
487 0xb7, 0xc2, 0xcb, 0xd4, 0xde, 0xe7, 0xf0, 0xf7, 482 0x3c, 0x4d, 0x60, 0x75, 0x8d, 0xa6, 0xc2, 0xe1,
488 0xff}, 483 0xff},
489 {0x00, 0x2f, 0x51, 0x6b, 0x7c, 0x8a, 0x99, 0xa6, /* 2 */ 484 {0x00, 0x01, 0x05, 0x0b, 0x12, 0x1c, 0x28, 0x35, /* 2 */
490 0xb1, 0xbc, 0xc6, 0xd0, 0xdb, 0xe4, 0xed, 0xf6, 485 0x45, 0x56, 0x69, 0x7e, 0x95, 0xad, 0xc7, 0xe3,
491 0xff}, 486 0xff},
492 {0x00, 0x29, 0x48, 0x60, 0x72, 0x81, 0x90, 0x9e, /* 3 */ 487 {0x00, 0x02, 0x07, 0x0f, 0x18, 0x24, 0x30, 0x3f, /* 3 */
493 0xaa, 0xb5, 0xbf, 0xcb, 0xd6, 0xe1, 0xeb, 0xf5, 488 0x4f, 0x61, 0x73, 0x88, 0x9d, 0xb4, 0xcd, 0xe6,
494 0xff}, 489 0xff},
495 {0x00, 0x23, 0x3f, 0x55, 0x68, 0x77, 0x86, 0x95, /* 4 */ 490 {0x00, 0x04, 0x0B, 0x15, 0x20, 0x2d, 0x3b, 0x4a, /* 4 */
496 0xa2, 0xad, 0xb9, 0xc6, 0xd2, 0xde, 0xe9, 0xf4, 491 0x5b, 0x6c, 0x7f, 0x92, 0xa7, 0xbc, 0xd2, 0xe9,
497 0xff}, 492 0xff},
498 {0x00, 0x1b, 0x33, 0x48, 0x59, 0x69, 0x79, 0x87, /* 5 */ 493 {0x00, 0x07, 0x11, 0x15, 0x20, 0x2d, 0x48, 0x58, /* 5 */
499 0x96, 0xa3, 0xb1, 0xbe, 0xcc, 0xda, 0xe7, 0xf3, 494 0x68, 0x79, 0x8b, 0x9d, 0xb0, 0xc4, 0xd7, 0xec,
500 0xff}, 495 0xff},
501 {0x00, 0x02, 0x10, 0x20, 0x32, 0x40, 0x57, 0x67, /* 6 */ 496 {0x00, 0x0c, 0x1a, 0x29, 0x38, 0x47, 0x57, 0x67, /* 6 */
502 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 497 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee,
503 0xff}, 498 0xff},
504 {0x00, 0x02, 0x14, 0x26, 0x38, 0x4a, 0x60, 0x70, /* 7 */ 499 {0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, /* 7 */
505 0x80, 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, 500 0x80, 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0,
506 0xff}, 501 0xff},
507 {0x00, 0x10, 0x22, 0x35, 0x47, 0x5a, 0x69, 0x79, /* 8 */ 502 {0x00, 0x15, 0x27, 0x38, 0x49, 0x59, 0x69, 0x79, /* 8 */
508 0x88, 0x97, 0xa7, 0xb6, 0xc4, 0xd3, 0xe0, 0xf0, 503 0x88, 0x97, 0xa7, 0xb6, 0xc4, 0xd3, 0xe2, 0xf0,
509 0xff}, 504 0xff},
510 {0x00, 0x10, 0x26, 0x40, 0x54, 0x65, 0x75, 0x84, /* 9 */ 505 {0x00, 0x1c, 0x30, 0x43, 0x54, 0x65, 0x75, 0x84, /* 9 */
511 0x93, 0xa1, 0xb0, 0xbd, 0xca, 0xd6, 0xe0, 0xf0, 506 0x93, 0xa1, 0xb0, 0xbd, 0xca, 0xd8, 0xe5, 0xf2,
512 0xff}, 507 0xff},
513 {0x00, 0x18, 0x2b, 0x44, 0x60, 0x70, 0x80, 0x8e, /* 10 */ 508 {0x00, 0x24, 0x3b, 0x4f, 0x60, 0x70, 0x80, 0x8e, /* 10 */
514 0x9c, 0xaa, 0xb7, 0xc4, 0xd0, 0xd8, 0xe2, 0xf0, 509 0x9c, 0xaa, 0xb7, 0xc4, 0xd0, 0xdc, 0xe8, 0xf3,
515 0xff}, 510 0xff},
516 {0x00, 0x1a, 0x34, 0x52, 0x66, 0x7e, 0x8d, 0x9b, /* 11 */ 511 {0x00, 0x2a, 0x3c, 0x5d, 0x6e, 0x7e, 0x8d, 0x9b, /* 11 */
517 0xa8, 0xb4, 0xc0, 0xcb, 0xd6, 0xe1, 0xeb, 0xf5, 512 0xa8, 0xb4, 0xc0, 0xcb, 0xd6, 0xe1, 0xeb, 0xf5,
518 0xff}, 513 0xff},
519 {0x00, 0x3f, 0x5a, 0x6e, 0x7f, 0x8e, 0x9c, 0xa8, /* 12 */ 514 {0x00, 0x3f, 0x5a, 0x6e, 0x7f, 0x8e, 0x9c, 0xa8, /* 12 */
@@ -577,12 +572,11 @@ static void reg_w_buf(struct gspca_dev *gspca_dev,
577 } else { 572 } else {
578 u8 *tmpbuf; 573 u8 *tmpbuf;
579 574
580 tmpbuf = kmalloc(len, GFP_KERNEL); 575 tmpbuf = kmemdup(buffer, len, GFP_KERNEL);
581 if (!tmpbuf) { 576 if (!tmpbuf) {
582 err("Out of memory"); 577 err("Out of memory");
583 return; 578 return;
584 } 579 }
585 memcpy(tmpbuf, buffer, len);
586 usb_control_msg(gspca_dev->dev, 580 usb_control_msg(gspca_dev->dev,
587 usb_sndctrlpipe(gspca_dev->dev, 0), 581 usb_sndctrlpipe(gspca_dev->dev, 0),
588 0, 582 0,
@@ -625,7 +619,6 @@ static void reg_w_ixbuf(struct gspca_dev *gspca_dev,
625 kfree(tmpbuf); 619 kfree(tmpbuf);
626} 620}
627 621
628/* Reported as OM6802*/
629static void om6802_sensor_init(struct gspca_dev *gspca_dev) 622static void om6802_sensor_init(struct gspca_dev *gspca_dev)
630{ 623{
631 int i; 624 int i;
@@ -703,12 +696,12 @@ static int sd_config(struct gspca_dev *gspca_dev,
703 sd->autogain = AUTOGAIN_DEF; 696 sd->autogain = AUTOGAIN_DEF;
704 sd->mirror = MIRROR_DEF; 697 sd->mirror = MIRROR_DEF;
705 sd->freq = FREQ_DEF; 698 sd->freq = FREQ_DEF;
706 sd->whitebalance = WHITE_BALANCE_DEF; 699 sd->awb = AWB_DEF;
707 sd->sharpness = SHARPNESS_DEF; 700 sd->sharpness = SHARPNESS_DEF;
708 sd->effect = EFFECTS_DEF; 701 sd->effect = EFFECTS_DEF;
709 sd->red_balance = RED_BALANCE_DEF; 702 sd->red_gain = RED_GAIN_DEF;
710 sd->blue_balance = BLUE_BALANCE_DEF; 703 sd->blue_gain = BLUE_GAIN_DEF;
711 sd->global_gain = global_gain_DEF; 704 sd->green_gain = GAIN_DEF * 3 - RED_GAIN_DEF - BLUE_GAIN_DEF;
712 705
713 return 0; 706 return 0;
714} 707}
@@ -761,40 +754,59 @@ static void setgamma(struct gspca_dev *gspca_dev)
761 reg_w_ixbuf(gspca_dev, 0x90, 754 reg_w_ixbuf(gspca_dev, 0x90,
762 gamma_table[sd->gamma], sizeof gamma_table[0]); 755 gamma_table[sd->gamma], sizeof gamma_table[0]);
763} 756}
764static void setglobalgain(struct gspca_dev *gspca_dev)
765{
766 757
758static void setRGB(struct gspca_dev *gspca_dev)
759{
767 struct sd *sd = (struct sd *) gspca_dev; 760 struct sd *sd = (struct sd *) gspca_dev;
768 reg_w(gspca_dev, (sd->red_balance << 8) + 0x87); 761 u8 all_gain_reg[6] =
769 reg_w(gspca_dev, (sd->blue_balance << 8) + 0x88); 762 {0x87, 0x00, 0x88, 0x00, 0x89, 0x00};
770 reg_w(gspca_dev, (sd->global_gain << 8) + 0x89); 763
764 all_gain_reg[1] = sd->red_gain;
765 all_gain_reg[3] = sd->blue_gain;
766 all_gain_reg[5] = sd->green_gain;
767 reg_w_buf(gspca_dev, all_gain_reg, sizeof all_gain_reg);
771} 768}
772 769
773/* Generic fnc for r/b balance, exposure and whitebalance */ 770/* Generic fnc for r/b balance, exposure and awb */
774static void setbalance(struct gspca_dev *gspca_dev) 771static void setawb(struct gspca_dev *gspca_dev)
775{ 772{
776 struct sd *sd = (struct sd *) gspca_dev; 773 struct sd *sd = (struct sd *) gspca_dev;
774 u16 reg80;
777 775
778 /* on whitebalance leave defaults values */ 776 reg80 = (sensor_data[sd->sensor].reg80 << 8) | 0x80;
779 if (sd->whitebalance) { 777
780 reg_w(gspca_dev, 0x3c80); 778 /* on awb leave defaults values */
781 } else { 779 if (!sd->awb) {
782 reg_w(gspca_dev, 0x3880);
783 /* shoud we wait here.. */ 780 /* shoud we wait here.. */
784 /* update and reset 'global gain' with webcam parameters */ 781 /* update and reset RGB gains with webcam values */
785 sd->red_balance = reg_r(gspca_dev, 0x0087); 782 sd->red_gain = reg_r(gspca_dev, 0x0087);
786 sd->blue_balance = reg_r(gspca_dev, 0x0088); 783 sd->blue_gain = reg_r(gspca_dev, 0x0088);
787 sd->global_gain = reg_r(gspca_dev, 0x0089); 784 sd->green_gain = reg_r(gspca_dev, 0x0089);
788 setglobalgain(gspca_dev); 785 reg80 &= ~0x0400; /* AWB off */
789 } 786 }
790 787 reg_w(gspca_dev, reg80);
788 reg_w(gspca_dev, reg80);
791} 789}
792 790
793 791static void init_gains(struct gspca_dev *gspca_dev)
794
795static void setwhitebalance(struct gspca_dev *gspca_dev)
796{ 792{
797 setbalance(gspca_dev); 793 struct sd *sd = (struct sd *) gspca_dev;
794 u16 reg80;
795 u8 all_gain_reg[8] =
796 {0x87, 0x00, 0x88, 0x00, 0x89, 0x00, 0x80, 0x00};
797
798 all_gain_reg[1] = sd->red_gain;
799 all_gain_reg[3] = sd->blue_gain;
800 all_gain_reg[5] = sd->green_gain;
801 reg80 = sensor_data[sd->sensor].reg80;
802 if (!sd->awb)
803 reg80 &= ~0x04;
804 all_gain_reg[7] = reg80;
805 reg_w_buf(gspca_dev, all_gain_reg, sizeof all_gain_reg);
806
807 reg_w(gspca_dev, (sd->red_gain << 8) + 0x87);
808 reg_w(gspca_dev, (sd->blue_gain << 8) + 0x88);
809 reg_w(gspca_dev, (sd->green_gain << 8) + 0x89);
798} 810}
799 811
800static void setsharpness(struct gspca_dev *gspca_dev) 812static void setsharpness(struct gspca_dev *gspca_dev)
@@ -807,6 +819,38 @@ static void setsharpness(struct gspca_dev *gspca_dev)
807 reg_w(gspca_dev, reg_to_write); 819 reg_w(gspca_dev, reg_to_write);
808} 820}
809 821
822static void setfreq(struct gspca_dev *gspca_dev)
823{
824 struct sd *sd = (struct sd *) gspca_dev;
825 u8 reg66;
826 u8 freq[4] = { 0x66, 0x00, 0xa8, 0xe8 };
827
828 switch (sd->sensor) {
829 case SENSOR_LT168G:
830 if (sd->freq != 0)
831 freq[3] = 0xa8;
832 reg66 = 0x41;
833 break;
834 case SENSOR_OM6802:
835 reg66 = 0xca;
836 break;
837 default:
838 reg66 = 0x40;
839 break;
840 }
841 switch (sd->freq) {
842 case 0: /* no flicker */
843 freq[3] = 0xf0;
844 break;
845 case 2: /* 60Hz */
846 reg66 &= ~0x40;
847 break;
848 }
849 freq[1] = reg66;
850
851 reg_w_buf(gspca_dev, freq, sizeof freq);
852}
853
810/* this function is called at probe and resume time */ 854/* this function is called at probe and resume time */
811static int sd_init(struct gspca_dev *gspca_dev) 855static int sd_init(struct gspca_dev *gspca_dev)
812{ 856{
@@ -901,13 +945,9 @@ static int sd_init(struct gspca_dev *gspca_dev)
901 setgamma(gspca_dev); 945 setgamma(gspca_dev);
902 setcolors(gspca_dev); 946 setcolors(gspca_dev);
903 setsharpness(gspca_dev); 947 setsharpness(gspca_dev);
904 setwhitebalance(gspca_dev); 948 init_gains(gspca_dev);
905 949 setfreq(gspca_dev);
906 reg_w(gspca_dev, 0x2087); /* tied to white balance? */
907 reg_w(gspca_dev, 0x2088);
908 reg_w(gspca_dev, 0x2089);
909 950
910 reg_w_buf(gspca_dev, sensor->data4, sizeof sensor->data4);
911 reg_w_buf(gspca_dev, sensor->data5, sizeof sensor->data5); 951 reg_w_buf(gspca_dev, sensor->data5, sizeof sensor->data5);
912 reg_w_buf(gspca_dev, sensor->nset8, sizeof sensor->nset8); 952 reg_w_buf(gspca_dev, sensor->nset8, sizeof sensor->nset8);
913 reg_w_buf(gspca_dev, sensor->stream, sizeof sensor->stream); 953 reg_w_buf(gspca_dev, sensor->stream, sizeof sensor->stream);
@@ -926,16 +966,16 @@ static int sd_init(struct gspca_dev *gspca_dev)
926 return 0; 966 return 0;
927} 967}
928 968
929static void setflip(struct gspca_dev *gspca_dev) 969static void setmirror(struct gspca_dev *gspca_dev)
930{ 970{
931 struct sd *sd = (struct sd *) gspca_dev; 971 struct sd *sd = (struct sd *) gspca_dev;
932 u8 flipcmd[8] = 972 u8 hflipcmd[8] =
933 {0x62, 0x07, 0x63, 0x03, 0x64, 0x00, 0x60, 0x09}; 973 {0x62, 0x07, 0x63, 0x03, 0x64, 0x00, 0x60, 0x09};
934 974
935 if (sd->mirror) 975 if (sd->mirror)
936 flipcmd[3] = 0x01; 976 hflipcmd[3] = 0x01;
937 977
938 reg_w_buf(gspca_dev, flipcmd, sizeof flipcmd); 978 reg_w_buf(gspca_dev, hflipcmd, sizeof hflipcmd);
939} 979}
940 980
941static void seteffect(struct gspca_dev *gspca_dev) 981static void seteffect(struct gspca_dev *gspca_dev)
@@ -956,17 +996,6 @@ static void seteffect(struct gspca_dev *gspca_dev)
956 reg_w(gspca_dev, 0xfaa6); 996 reg_w(gspca_dev, 0xfaa6);
957} 997}
958 998
959static void setlightfreq(struct gspca_dev *gspca_dev)
960{
961 struct sd *sd = (struct sd *) gspca_dev;
962 u8 freq[4] = { 0x66, 0x40, 0xa8, 0xe8 };
963
964 if (sd->freq == 2) /* 60hz */
965 freq[1] = 0x00;
966
967 reg_w_buf(gspca_dev, freq, sizeof freq);
968}
969
970/* Is this really needed? 999/* Is this really needed?
971 * i added some module parameters for test with some users */ 1000 * i added some module parameters for test with some users */
972static void poll_sensor(struct gspca_dev *gspca_dev) 1001static void poll_sensor(struct gspca_dev *gspca_dev)
@@ -979,9 +1008,7 @@ static void poll_sensor(struct gspca_dev *gspca_dev)
979 static const u8 poll2[] = 1008 static const u8 poll2[] =
980 {0x67, 0x02, 0x68, 0x71, 0x69, 0x72, 0x72, 0xa9, 1009 {0x67, 0x02, 0x68, 0x71, 0x69, 0x72, 0x72, 0xa9,
981 0x73, 0x02, 0x73, 0x02, 0x60, 0x14}; 1010 0x73, 0x02, 0x73, 0x02, 0x60, 0x14};
982 static const u8 poll3[] = 1011 static const u8 noise03[] = /* (some differences / ms-drv) */
983 {0x87, 0x3f, 0x88, 0x20, 0x89, 0x2d};
984 static const u8 poll4[] =
985 {0xa6, 0x0a, 0xea, 0xcf, 0xbe, 0x26, 0xb1, 0x5f, 1012 {0xa6, 0x0a, 0xea, 0xcf, 0xbe, 0x26, 0xb1, 0x5f,
986 0xa1, 0xb1, 0xda, 0x6b, 0xdb, 0x98, 0xdf, 0x0c, 1013 0xa1, 0xb1, 0xda, 0x6b, 0xdb, 0x98, 0xdf, 0x0c,
987 0xc2, 0x80, 0xc3, 0x10}; 1014 0xc2, 0x80, 0xc3, 0x10};
@@ -989,8 +1016,7 @@ static void poll_sensor(struct gspca_dev *gspca_dev)
989 PDEBUG(D_STREAM, "[Sensor requires polling]"); 1016 PDEBUG(D_STREAM, "[Sensor requires polling]");
990 reg_w_buf(gspca_dev, poll1, sizeof poll1); 1017 reg_w_buf(gspca_dev, poll1, sizeof poll1);
991 reg_w_buf(gspca_dev, poll2, sizeof poll2); 1018 reg_w_buf(gspca_dev, poll2, sizeof poll2);
992 reg_w_buf(gspca_dev, poll3, sizeof poll3); 1019 reg_w_buf(gspca_dev, noise03, sizeof noise03);
993 reg_w_buf(gspca_dev, poll4, sizeof poll4);
994} 1020}
995 1021
996static int sd_start(struct gspca_dev *gspca_dev) 1022static int sd_start(struct gspca_dev *gspca_dev)
@@ -1025,12 +1051,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
1025 case SENSOR_OM6802: 1051 case SENSOR_OM6802:
1026 om6802_sensor_init(gspca_dev); 1052 om6802_sensor_init(gspca_dev);
1027 break; 1053 break;
1028 case SENSOR_LT168G: 1054 case SENSOR_TAS5130A:
1029 break;
1030 case SENSOR_OTHER:
1031 break;
1032 default:
1033/* case SENSOR_TAS5130A: */
1034 i = 0; 1055 i = 0;
1035 for (;;) { 1056 for (;;) {
1036 reg_w_buf(gspca_dev, tas5130a_sensor_init[i], 1057 reg_w_buf(gspca_dev, tas5130a_sensor_init[i],
@@ -1047,7 +1068,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
1047 break; 1068 break;
1048 } 1069 }
1049 sensor = &sensor_data[sd->sensor]; 1070 sensor = &sensor_data[sd->sensor];
1050 reg_w_buf(gspca_dev, sensor->data4, sizeof sensor->data4); 1071 setfreq(gspca_dev);
1051 reg_r(gspca_dev, 0x0012); 1072 reg_r(gspca_dev, 0x0012);
1052 reg_w_buf(gspca_dev, t2, sizeof t2); 1073 reg_w_buf(gspca_dev, t2, sizeof t2);
1053 reg_w_ixbuf(gspca_dev, 0xb3, t3, sizeof t3); 1074 reg_w_ixbuf(gspca_dev, 0xb3, t3, sizeof t3);
@@ -1080,7 +1101,7 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
1080 u8 *data, /* isoc packet */ 1101 u8 *data, /* isoc packet */
1081 int len) /* iso packet length */ 1102 int len) /* iso packet length */
1082{ 1103{
1083 static u8 ffd9[] = { 0xff, 0xd9 }; 1104 int pkt_type;
1084 1105
1085 if (data[0] == 0x5a) { 1106 if (data[0] == 0x5a) {
1086 /* Control Packet, after this came the header again, 1107 /* Control Packet, after this came the header again,
@@ -1090,84 +1111,88 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
1090 } 1111 }
1091 data += 2; 1112 data += 2;
1092 len -= 2; 1113 len -= 2;
1093 if (data[0] == 0xff && data[1] == 0xd8) { 1114 if (data[0] == 0xff && data[1] == 0xd8)
1094 /* extra bytes....., could be processed too but would be 1115 pkt_type = FIRST_PACKET;
1095 * a waste of time, right now leave the application and 1116 else if (data[len - 2] == 0xff && data[len - 1] == 0xd9)
1096 * libjpeg do it for ourserlves.. */ 1117 pkt_type = LAST_PACKET;
1097 gspca_frame_add(gspca_dev, LAST_PACKET, 1118 else
1098 ffd9, 2); 1119 pkt_type = INTER_PACKET;
1099 gspca_frame_add(gspca_dev, FIRST_PACKET, data, len); 1120 gspca_frame_add(gspca_dev, pkt_type, data, len);
1100 return;
1101 }
1102
1103 if (data[len - 2] == 0xff && data[len - 1] == 0xd9) {
1104 /* Just in case, i have seen packets with the marker,
1105 * other's do not include it... */
1106 len -= 2;
1107 }
1108 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
1109} 1121}
1110 1122
1111 1123static int sd_setblue_gain(struct gspca_dev *gspca_dev, __s32 val)
1112static int sd_setblue_balance(struct gspca_dev *gspca_dev, __s32 val)
1113{ 1124{
1114 struct sd *sd = (struct sd *) gspca_dev; 1125 struct sd *sd = (struct sd *) gspca_dev;
1115 1126
1116 sd->blue_balance = val; 1127 sd->blue_gain = val;
1117 if (gspca_dev->streaming) 1128 if (gspca_dev->streaming)
1118 reg_w(gspca_dev, (val << 8) + 0x88); 1129 reg_w(gspca_dev, (val << 8) + 0x88);
1119 return 0; 1130 return 0;
1120} 1131}
1121 1132
1122static int sd_getblue_balance(struct gspca_dev *gspca_dev, __s32 *val) 1133static int sd_getblue_gain(struct gspca_dev *gspca_dev, __s32 *val)
1123{ 1134{
1124 struct sd *sd = (struct sd *) gspca_dev; 1135 struct sd *sd = (struct sd *) gspca_dev;
1125 1136
1126 *val = sd->blue_balance; 1137 *val = sd->blue_gain;
1127 return 0; 1138 return 0;
1128} 1139}
1129 1140
1130static int sd_setred_balance(struct gspca_dev *gspca_dev, __s32 val) 1141static int sd_setred_gain(struct gspca_dev *gspca_dev, __s32 val)
1131{ 1142{
1132 struct sd *sd = (struct sd *) gspca_dev; 1143 struct sd *sd = (struct sd *) gspca_dev;
1133 1144
1134 sd->red_balance = val; 1145 sd->red_gain = val;
1135 if (gspca_dev->streaming) 1146 if (gspca_dev->streaming)
1136 reg_w(gspca_dev, (val << 8) + 0x87); 1147 reg_w(gspca_dev, (val << 8) + 0x87);
1137 1148
1138 return 0; 1149 return 0;
1139} 1150}
1140 1151
1141static int sd_getred_balance(struct gspca_dev *gspca_dev, __s32 *val) 1152static int sd_getred_gain(struct gspca_dev *gspca_dev, __s32 *val)
1142{ 1153{
1143 struct sd *sd = (struct sd *) gspca_dev; 1154 struct sd *sd = (struct sd *) gspca_dev;
1144 1155
1145 *val = sd->red_balance; 1156 *val = sd->red_gain;
1146 return 0; 1157 return 0;
1147} 1158}
1148 1159
1149 1160static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val)
1150
1151static int sd_setglobal_gain(struct gspca_dev *gspca_dev, __s32 val)
1152{ 1161{
1153 struct sd *sd = (struct sd *) gspca_dev; 1162 struct sd *sd = (struct sd *) gspca_dev;
1163 u16 psg, nsg;
1164
1165 psg = sd->red_gain + sd->blue_gain + sd->green_gain;
1166 nsg = val * 3;
1167 sd->red_gain = sd->red_gain * nsg / psg;
1168 if (sd->red_gain > 0x40)
1169 sd->red_gain = 0x40;
1170 else if (sd->red_gain < 0x10)
1171 sd->red_gain = 0x10;
1172 sd->blue_gain = sd->blue_gain * nsg / psg;
1173 if (sd->blue_gain > 0x40)
1174 sd->blue_gain = 0x40;
1175 else if (sd->blue_gain < 0x10)
1176 sd->blue_gain = 0x10;
1177 sd->green_gain = sd->green_gain * nsg / psg;
1178 if (sd->green_gain > 0x40)
1179 sd->green_gain = 0x40;
1180 else if (sd->green_gain < 0x10)
1181 sd->green_gain = 0x10;
1154 1182
1155 sd->global_gain = val;
1156 if (gspca_dev->streaming) 1183 if (gspca_dev->streaming)
1157 setglobalgain(gspca_dev); 1184 setRGB(gspca_dev);
1158
1159 return 0; 1185 return 0;
1160} 1186}
1161 1187
1162static int sd_getglobal_gain(struct gspca_dev *gspca_dev, __s32 *val) 1188static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val)
1163{ 1189{
1164 struct sd *sd = (struct sd *) gspca_dev; 1190 struct sd *sd = (struct sd *) gspca_dev;
1165 1191
1166 *val = sd->global_gain; 1192 *val = (sd->red_gain + sd->blue_gain + sd->green_gain) / 3;
1167 return 0; 1193 return 0;
1168} 1194}
1169 1195
1170
1171static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val) 1196static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
1172{ 1197{
1173 struct sd *sd = (struct sd *) gspca_dev; 1198 struct sd *sd = (struct sd *) gspca_dev;
@@ -1186,35 +1211,35 @@ static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
1186 return *val; 1211 return *val;
1187} 1212}
1188 1213
1189static int sd_setwhitebalance(struct gspca_dev *gspca_dev, __s32 val) 1214static int sd_setawb(struct gspca_dev *gspca_dev, __s32 val)
1190{ 1215{
1191 struct sd *sd = (struct sd *) gspca_dev; 1216 struct sd *sd = (struct sd *) gspca_dev;
1192 1217
1193 sd->whitebalance = val; 1218 sd->awb = val;
1194 if (gspca_dev->streaming) 1219 if (gspca_dev->streaming)
1195 setwhitebalance(gspca_dev); 1220 setawb(gspca_dev);
1196 return 0; 1221 return 0;
1197} 1222}
1198 1223
1199static int sd_getwhitebalance(struct gspca_dev *gspca_dev, __s32 *val) 1224static int sd_getawb(struct gspca_dev *gspca_dev, __s32 *val)
1200{ 1225{
1201 struct sd *sd = (struct sd *) gspca_dev; 1226 struct sd *sd = (struct sd *) gspca_dev;
1202 1227
1203 *val = sd->whitebalance; 1228 *val = sd->awb;
1204 return *val; 1229 return *val;
1205} 1230}
1206 1231
1207static int sd_setflip(struct gspca_dev *gspca_dev, __s32 val) 1232static int sd_setmirror(struct gspca_dev *gspca_dev, __s32 val)
1208{ 1233{
1209 struct sd *sd = (struct sd *) gspca_dev; 1234 struct sd *sd = (struct sd *) gspca_dev;
1210 1235
1211 sd->mirror = val; 1236 sd->mirror = val;
1212 if (gspca_dev->streaming) 1237 if (gspca_dev->streaming)
1213 setflip(gspca_dev); 1238 setmirror(gspca_dev);
1214 return 0; 1239 return 0;
1215} 1240}
1216 1241
1217static int sd_getflip(struct gspca_dev *gspca_dev, __s32 *val) 1242static int sd_getmirror(struct gspca_dev *gspca_dev, __s32 *val)
1218{ 1243{
1219 struct sd *sd = (struct sd *) gspca_dev; 1244 struct sd *sd = (struct sd *) gspca_dev;
1220 1245
@@ -1300,7 +1325,7 @@ static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val)
1300 1325
1301 sd->freq = val; 1326 sd->freq = val;
1302 if (gspca_dev->streaming) 1327 if (gspca_dev->streaming)
1303 setlightfreq(gspca_dev); 1328 setfreq(gspca_dev);
1304 return 0; 1329 return 0;
1305} 1330}
1306 1331
@@ -1368,7 +1393,8 @@ static int sd_querymenu(struct gspca_dev *gspca_dev,
1368 case V4L2_CID_EFFECTS: 1393 case V4L2_CID_EFFECTS:
1369 if ((unsigned) menu->index < ARRAY_SIZE(effects_control)) { 1394 if ((unsigned) menu->index < ARRAY_SIZE(effects_control)) {
1370 strncpy((char *) menu->name, 1395 strncpy((char *) menu->name,
1371 effects_control[menu->index], 32); 1396 effects_control[menu->index],
1397 sizeof menu->name);
1372 return 0; 1398 return 0;
1373 } 1399 }
1374 break; 1400 break;
diff --git a/drivers/media/video/gspca/tv8532.c b/drivers/media/video/gspca/tv8532.c
index c7b6eb1e04d5..d9c5bf3449d4 100644
--- a/drivers/media/video/gspca/tv8532.c
+++ b/drivers/media/video/gspca/tv8532.c
@@ -30,29 +30,46 @@ MODULE_LICENSE("GPL");
30struct sd { 30struct sd {
31 struct gspca_dev gspca_dev; /* !! must be the first item */ 31 struct gspca_dev gspca_dev; /* !! must be the first item */
32 32
33 __u16 brightness; 33 __u16 exposure;
34 __u16 gain;
34 35
35 __u8 packet; 36 __u8 packet;
36}; 37};
37 38
38/* V4L2 controls supported by the driver */ 39/* V4L2 controls supported by the driver */
39static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val); 40static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val);
40static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val); 41static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val);
42static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val);
43static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val);
41 44
42static const struct ctrl sd_ctrls[] = { 45static const struct ctrl sd_ctrls[] = {
43 { 46 {
44 { 47 {
45 .id = V4L2_CID_BRIGHTNESS, 48 .id = V4L2_CID_EXPOSURE,
46 .type = V4L2_CTRL_TYPE_INTEGER, 49 .type = V4L2_CTRL_TYPE_INTEGER,
47 .name = "Brightness", 50 .name = "Exposure",
48 .minimum = 1, 51 .minimum = 1,
49 .maximum = 0x15f, /* = 352 - 1 */ 52 .maximum = 0x18f,
50 .step = 1, 53 .step = 1,
51#define BRIGHTNESS_DEF 0x14c 54#define EXPOSURE_DEF 0x18f
52 .default_value = BRIGHTNESS_DEF, 55 .default_value = EXPOSURE_DEF,
53 }, 56 },
54 .set = sd_setbrightness, 57 .set = sd_setexposure,
55 .get = sd_getbrightness, 58 .get = sd_getexposure,
59 },
60 {
61 {
62 .id = V4L2_CID_GAIN,
63 .type = V4L2_CTRL_TYPE_INTEGER,
64 .name = "Gain",
65 .minimum = 0,
66 .maximum = 0x7ff,
67 .step = 1,
68#define GAIN_DEF 0x100
69 .default_value = GAIN_DEF,
70 },
71 .set = sd_setgain,
72 .get = sd_getgain,
56 }, 73 },
57}; 74};
58 75
@@ -92,6 +109,14 @@ static const struct v4l2_pix_format sif_mode[] = {
92#define R14_AD_ROW_BEGINL 0x14 109#define R14_AD_ROW_BEGINL 0x14
93#define R15_AD_ROWBEGINH 0x15 110#define R15_AD_ROWBEGINH 0x15
94#define R1C_AD_EXPOSE_TIMEL 0x1c 111#define R1C_AD_EXPOSE_TIMEL 0x1c
112#define R20_GAIN_G1L 0x20
113#define R21_GAIN_G1H 0x21
114#define R22_GAIN_RL 0x22
115#define R23_GAIN_RH 0x23
116#define R24_GAIN_BL 0x24
117#define R25_GAIN_BH 0x25
118#define R26_GAIN_G2L 0x26
119#define R27_GAIN_G2H 0x27
95#define R28_QUANT 0x28 120#define R28_QUANT 0x28
96#define R29_LINE 0x29 121#define R29_LINE 0x29
97#define R2C_POLARITY 0x2c 122#define R2C_POLARITY 0x2c
@@ -129,18 +154,6 @@ static const u8 eeprom_data[][3] = {
129 {0x05, 0x09, 0xf1}, 154 {0x05, 0x09, 0xf1},
130}; 155};
131 156
132static int reg_r(struct gspca_dev *gspca_dev,
133 __u16 index)
134{
135 usb_control_msg(gspca_dev->dev,
136 usb_rcvctrlpipe(gspca_dev->dev, 0),
137 0x03,
138 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
139 0, /* value */
140 index, gspca_dev->usb_buf, 1,
141 500);
142 return gspca_dev->usb_buf[0];
143}
144 157
145/* write 1 byte */ 158/* write 1 byte */
146static void reg_w1(struct gspca_dev *gspca_dev, 159static void reg_w1(struct gspca_dev *gspca_dev,
@@ -183,7 +196,6 @@ static void tv_8532WriteEEprom(struct gspca_dev *gspca_dev)
183 } 196 }
184 reg_w1(gspca_dev, R07_TABLE_LEN, i); 197 reg_w1(gspca_dev, R07_TABLE_LEN, i);
185 reg_w1(gspca_dev, R01_TIMING_CONTROL_LOW, CMD_EEprom_Close); 198 reg_w1(gspca_dev, R01_TIMING_CONTROL_LOW, CMD_EEprom_Close);
186 msleep(10);
187} 199}
188 200
189/* this function is called at probe time */ 201/* this function is called at probe time */
@@ -197,53 +209,13 @@ static int sd_config(struct gspca_dev *gspca_dev,
197 cam->cam_mode = sif_mode; 209 cam->cam_mode = sif_mode;
198 cam->nmodes = ARRAY_SIZE(sif_mode); 210 cam->nmodes = ARRAY_SIZE(sif_mode);
199 211
200 sd->brightness = BRIGHTNESS_DEF; 212 sd->exposure = EXPOSURE_DEF;
213 sd->gain = GAIN_DEF;
201 return 0; 214 return 0;
202} 215}
203 216
204static void tv_8532ReadRegisters(struct gspca_dev *gspca_dev)
205{
206 int i;
207 static u8 reg_tb[] = {
208 R0C_AD_WIDTHL,
209 R0D_AD_WIDTHH,
210 R28_QUANT,
211 R29_LINE,
212 R2C_POLARITY,
213 R2D_POINT,
214 R2E_POINTH,
215 R2F_POINTB,
216 R30_POINTBH,
217 R2A_HIGH_BUDGET,
218 R2B_LOW_BUDGET,
219 R34_VID,
220 R35_VIDH,
221 R36_PID,
222 R37_PIDH,
223 R83_AD_IDH,
224 R10_AD_COL_BEGINL,
225 R11_AD_COL_BEGINH,
226 R14_AD_ROW_BEGINL,
227 R15_AD_ROWBEGINH,
228 0
229 };
230
231 i = 0;
232 do {
233 reg_r(gspca_dev, reg_tb[i]);
234 i++;
235 } while (reg_tb[i] != 0);
236}
237
238static void tv_8532_setReg(struct gspca_dev *gspca_dev) 217static void tv_8532_setReg(struct gspca_dev *gspca_dev)
239{ 218{
240 reg_w1(gspca_dev, R10_AD_COL_BEGINL, 0x44);
241 /* begin active line */
242 reg_w1(gspca_dev, R11_AD_COL_BEGINH, 0x00);
243 /* mirror and digital gain */
244 reg_w1(gspca_dev, R00_PART_CONTROL, LATENT_CHANGE | EXPO_CHANGE);
245 /* = 0x84 */
246
247 reg_w1(gspca_dev, R3B_Test3, 0x0a); /* Test0Sel = 10 */ 219 reg_w1(gspca_dev, R3B_Test3, 0x0a); /* Test0Sel = 10 */
248 /******************************************************/ 220 /******************************************************/
249 reg_w1(gspca_dev, R0E_AD_HEIGHTL, 0x90); 221 reg_w1(gspca_dev, R0E_AD_HEIGHTL, 0x90);
@@ -255,100 +227,43 @@ static void tv_8532_setReg(struct gspca_dev *gspca_dev)
255 /* mirror and digital gain */ 227 /* mirror and digital gain */
256 reg_w1(gspca_dev, R14_AD_ROW_BEGINL, 0x0a); 228 reg_w1(gspca_dev, R14_AD_ROW_BEGINL, 0x0a);
257 229
258 reg_w1(gspca_dev, R91_AD_SLOPEREG, 0x00);
259 reg_w1(gspca_dev, R94_AD_BITCONTROL, 0x02); 230 reg_w1(gspca_dev, R94_AD_BITCONTROL, 0x02);
260
261 reg_w1(gspca_dev, R01_TIMING_CONTROL_LOW, CMD_EEprom_Close);
262
263 reg_w1(gspca_dev, R91_AD_SLOPEREG, 0x00); 231 reg_w1(gspca_dev, R91_AD_SLOPEREG, 0x00);
264 reg_w1(gspca_dev, R00_PART_CONTROL, LATENT_CHANGE | EXPO_CHANGE); 232 reg_w1(gspca_dev, R00_PART_CONTROL, LATENT_CHANGE | EXPO_CHANGE);
265 /* = 0x84 */ 233 /* = 0x84 */
266} 234}
267 235
268static void tv_8532_PollReg(struct gspca_dev *gspca_dev)
269{
270 int i;
271
272 /* strange polling from tgc */
273 for (i = 0; i < 10; i++) {
274 reg_w1(gspca_dev, R2C_POLARITY, 0x10);
275 reg_w1(gspca_dev, R00_PART_CONTROL,
276 LATENT_CHANGE | EXPO_CHANGE);
277 reg_w1(gspca_dev, R31_UPD, 0x01);
278 }
279}
280
281/* this function is called at probe and resume time */ 236/* this function is called at probe and resume time */
282static int sd_init(struct gspca_dev *gspca_dev) 237static int sd_init(struct gspca_dev *gspca_dev)
283{ 238{
284 tv_8532WriteEEprom(gspca_dev); 239 tv_8532WriteEEprom(gspca_dev);
285 240
286 reg_w1(gspca_dev, R91_AD_SLOPEREG, 0x32); /* slope begin 1,7V,
287 * slope rate 2 */
288 reg_w1(gspca_dev, R94_AD_BITCONTROL, 0x00);
289 tv_8532ReadRegisters(gspca_dev);
290 reg_w1(gspca_dev, R3B_Test3, 0x0b);
291 reg_w2(gspca_dev, R0E_AD_HEIGHTL, 0x0190);
292 reg_w2(gspca_dev, R1C_AD_EXPOSE_TIMEL, 0x018f);
293 reg_w1(gspca_dev, R0C_AD_WIDTHL, 0xe8);
294 reg_w1(gspca_dev, R0D_AD_WIDTHH, 0x03);
295
296 /*******************************************************************/
297 reg_w1(gspca_dev, R28_QUANT, 0x90);
298 /* no compress - fixed Q - quant 0 */
299 reg_w1(gspca_dev, R29_LINE, 0x81);
300 /* 0x84; // CIF | 4 packet 0x29 */
301
302 /************************************************/
303 reg_w1(gspca_dev, R2C_POLARITY, 0x10);
304 /* 0x48; //0x08; 0x2c */
305 reg_w1(gspca_dev, R2D_POINT, 0x14);
306 /* 0x38; 0x2d */
307 reg_w1(gspca_dev, R2E_POINTH, 0x01);
308 /* 0x04; 0x2e */
309 reg_w1(gspca_dev, R2F_POINTB, 0x12);
310 /* 0x04; 0x2f */
311 reg_w1(gspca_dev, R30_POINTBH, 0x01);
312 /* 0x04; 0x30 */
313 reg_w1(gspca_dev, R00_PART_CONTROL, LATENT_CHANGE | EXPO_CHANGE);
314 /* 0x00<-0x84 */
315 /*************************************************/
316 reg_w1(gspca_dev, R31_UPD, 0x01); /* update registers */
317 msleep(200);
318 reg_w1(gspca_dev, R31_UPD, 0x00); /* end update */
319 /*************************************************/
320 tv_8532_setReg(gspca_dev);
321 /*************************************************/
322 reg_w1(gspca_dev, R3B_Test3, 0x0b); /* Test0Sel = 11 = GPIO */
323 /*************************************************/
324 tv_8532_setReg(gspca_dev);
325 /*************************************************/
326 tv_8532_PollReg(gspca_dev);
327 return 0; 241 return 0;
328} 242}
329 243
330static void setbrightness(struct gspca_dev *gspca_dev) 244static void setexposure(struct gspca_dev *gspca_dev)
331{ 245{
332 struct sd *sd = (struct sd *) gspca_dev; 246 struct sd *sd = (struct sd *) gspca_dev;
333 247
334 reg_w2(gspca_dev, R1C_AD_EXPOSE_TIMEL, sd->brightness); 248 reg_w2(gspca_dev, R1C_AD_EXPOSE_TIMEL, sd->exposure);
335 reg_w1(gspca_dev, R00_PART_CONTROL, LATENT_CHANGE | EXPO_CHANGE); 249 reg_w1(gspca_dev, R00_PART_CONTROL, LATENT_CHANGE | EXPO_CHANGE);
336 /* 0x84 */ 250 /* 0x84 */
337} 251}
338 252
339/* -- start the camera -- */ 253static void setgain(struct gspca_dev *gspca_dev)
340static int sd_start(struct gspca_dev *gspca_dev)
341{ 254{
342 struct sd *sd = (struct sd *) gspca_dev; 255 struct sd *sd = (struct sd *) gspca_dev;
343 256
344 reg_w1(gspca_dev, R91_AD_SLOPEREG, 0x32); /* slope begin 1,7V, 257 reg_w2(gspca_dev, R20_GAIN_G1L, sd->gain);
345 * slope rate 2 */ 258 reg_w2(gspca_dev, R22_GAIN_RL, sd->gain);
346 reg_w1(gspca_dev, R94_AD_BITCONTROL, 0x00); 259 reg_w2(gspca_dev, R24_GAIN_BL, sd->gain);
347 tv_8532ReadRegisters(gspca_dev); 260 reg_w2(gspca_dev, R26_GAIN_G2L, sd->gain);
348 reg_w1(gspca_dev, R3B_Test3, 0x0b); 261}
349 262
350 reg_w2(gspca_dev, R0E_AD_HEIGHTL, 0x0190); 263/* -- start the camera -- */
351 setbrightness(gspca_dev); 264static int sd_start(struct gspca_dev *gspca_dev)
265{
266 struct sd *sd = (struct sd *) gspca_dev;
352 267
353 reg_w1(gspca_dev, R0C_AD_WIDTHL, 0xe8); /* 0x20; 0x0c */ 268 reg_w1(gspca_dev, R0C_AD_WIDTHL, 0xe8); /* 0x20; 0x0c */
354 reg_w1(gspca_dev, R0D_AD_WIDTHH, 0x03); 269 reg_w1(gspca_dev, R0D_AD_WIDTHH, 0x03);
@@ -371,19 +286,15 @@ static int sd_start(struct gspca_dev *gspca_dev)
371 reg_w1(gspca_dev, R2E_POINTH, 0x01); 286 reg_w1(gspca_dev, R2E_POINTH, 0x01);
372 reg_w1(gspca_dev, R2F_POINTB, 0x12); 287 reg_w1(gspca_dev, R2F_POINTB, 0x12);
373 reg_w1(gspca_dev, R30_POINTBH, 0x01); 288 reg_w1(gspca_dev, R30_POINTBH, 0x01);
374 reg_w1(gspca_dev, R00_PART_CONTROL, LATENT_CHANGE | EXPO_CHANGE); 289
290 tv_8532_setReg(gspca_dev);
291
292 setexposure(gspca_dev);
293 setgain(gspca_dev);
294
375 /************************************************/ 295 /************************************************/
376 reg_w1(gspca_dev, R31_UPD, 0x01); /* update registers */ 296 reg_w1(gspca_dev, R31_UPD, 0x01); /* update registers */
377 msleep(200); 297 msleep(200);
378 reg_w1(gspca_dev, R31_UPD, 0x00); /* end update */
379 /************************************************/
380 tv_8532_setReg(gspca_dev);
381 /************************************************/
382 reg_w1(gspca_dev, R3B_Test3, 0x0b); /* Test0Sel = 11 = GPIO */
383 /************************************************/
384 tv_8532_setReg(gspca_dev);
385 /************************************************/
386 tv_8532_PollReg(gspca_dev);
387 reg_w1(gspca_dev, R31_UPD, 0x00); /* end update */ 298 reg_w1(gspca_dev, R31_UPD, 0x00); /* end update */
388 299
389 gspca_dev->empty_packet = 0; /* check the empty packets */ 300 gspca_dev->empty_packet = 0; /* check the empty packets */
@@ -428,21 +339,39 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
428 data + gspca_dev->width + 5, gspca_dev->width); 339 data + gspca_dev->width + 5, gspca_dev->width);
429} 340}
430 341
431static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val) 342static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val)
343{
344 struct sd *sd = (struct sd *) gspca_dev;
345
346 sd->exposure = val;
347 if (gspca_dev->streaming)
348 setexposure(gspca_dev);
349 return 0;
350}
351
352static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val)
353{
354 struct sd *sd = (struct sd *) gspca_dev;
355
356 *val = sd->exposure;
357 return 0;
358}
359
360static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val)
432{ 361{
433 struct sd *sd = (struct sd *) gspca_dev; 362 struct sd *sd = (struct sd *) gspca_dev;
434 363
435 sd->brightness = val; 364 sd->gain = val;
436 if (gspca_dev->streaming) 365 if (gspca_dev->streaming)
437 setbrightness(gspca_dev); 366 setgain(gspca_dev);
438 return 0; 367 return 0;
439} 368}
440 369
441static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val) 370static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val)
442{ 371{
443 struct sd *sd = (struct sd *) gspca_dev; 372 struct sd *sd = (struct sd *) gspca_dev;
444 373
445 *val = sd->brightness; 374 *val = sd->gain;
446 return 0; 375 return 0;
447} 376}
448 377
diff --git a/drivers/media/video/gspca/vc032x.c b/drivers/media/video/gspca/vc032x.c
index 732c3dfe46ff..031266a4081b 100644
--- a/drivers/media/video/gspca/vc032x.c
+++ b/drivers/media/video/gspca/vc032x.c
@@ -2748,11 +2748,11 @@ static const u8 poxxxx_init_common[][4] = {
2748 {0xb3, 0x04, 0x15, 0xcc}, 2748 {0xb3, 0x04, 0x15, 0xcc},
2749 {0xb3, 0x20, 0x00, 0xcc}, 2749 {0xb3, 0x20, 0x00, 0xcc},
2750 {0xb3, 0x21, 0x00, 0xcc}, 2750 {0xb3, 0x21, 0x00, 0xcc},
2751 {0xb3, 0x22, 0x04, 0xcc}, 2751 {0xb3, 0x22, 0x04, 0xcc}, /* sensor height = 1024 */
2752 {0xb3, 0x23, 0x00, 0xcc}, 2752 {0xb3, 0x23, 0x00, 0xcc},
2753 {0xb3, 0x14, 0x00, 0xcc}, 2753 {0xb3, 0x14, 0x00, 0xcc},
2754 {0xb3, 0x15, 0x00, 0xcc}, 2754 {0xb3, 0x15, 0x00, 0xcc},
2755 {0xb3, 0x16, 0x04, 0xcc}, 2755 {0xb3, 0x16, 0x04, 0xcc}, /* sensor width = 1280 */
2756 {0xb3, 0x17, 0xff, 0xcc}, 2756 {0xb3, 0x17, 0xff, 0xcc},
2757 {0xb3, 0x2c, 0x03, 0xcc}, 2757 {0xb3, 0x2c, 0x03, 0xcc},
2758 {0xb3, 0x2d, 0x56, 0xcc}, 2758 {0xb3, 0x2d, 0x56, 0xcc},
@@ -2919,7 +2919,7 @@ static const u8 poxxxx_initVGA[][4] = {
2919 {0x00, 0x20, 0x11, 0xaa}, 2919 {0x00, 0x20, 0x11, 0xaa},
2920 {0x00, 0x33, 0x38, 0xaa}, 2920 {0x00, 0x33, 0x38, 0xaa},
2921 {0x00, 0xbb, 0x0d, 0xaa}, 2921 {0x00, 0xbb, 0x0d, 0xaa},
2922 {0xb3, 0x22, 0x01, 0xcc}, 2922 {0xb3, 0x22, 0x01, 0xcc}, /* change to 640x480 */
2923 {0xb3, 0x23, 0xe0, 0xcc}, 2923 {0xb3, 0x23, 0xe0, 0xcc},
2924 {0xb3, 0x16, 0x02, 0xcc}, 2924 {0xb3, 0x16, 0x02, 0xcc},
2925 {0xb3, 0x17, 0x7f, 0xcc}, 2925 {0xb3, 0x17, 0x7f, 0xcc},
@@ -2935,7 +2935,7 @@ static const u8 poxxxx_initQVGA[][4] = {
2935 {0x00, 0x20, 0x33, 0xaa}, 2935 {0x00, 0x20, 0x33, 0xaa},
2936 {0x00, 0x33, 0x38, 0xaa}, 2936 {0x00, 0x33, 0x38, 0xaa},
2937 {0x00, 0xbb, 0x0d, 0xaa}, 2937 {0x00, 0xbb, 0x0d, 0xaa},
2938 {0xb3, 0x22, 0x00, 0xcc}, 2938 {0xb3, 0x22, 0x00, 0xcc}, /* change to 320x240 */
2939 {0xb3, 0x23, 0xf0, 0xcc}, 2939 {0xb3, 0x23, 0xf0, 0xcc},
2940 {0xb3, 0x16, 0x01, 0xcc}, 2940 {0xb3, 0x16, 0x01, 0xcc},
2941 {0xb3, 0x17, 0x3f, 0xcc}, 2941 {0xb3, 0x17, 0x3f, 0xcc},
@@ -3068,37 +3068,84 @@ static const struct sensor_info vc0323_probe_data[] = {
3068}; 3068};
3069 3069
3070/* read 'len' bytes in gspca_dev->usb_buf */ 3070/* read 'len' bytes in gspca_dev->usb_buf */
3071static void reg_r(struct gspca_dev *gspca_dev, 3071static void reg_r_i(struct gspca_dev *gspca_dev,
3072 u16 req, 3072 u16 req,
3073 u16 index, 3073 u16 index,
3074 u16 len) 3074 u16 len)
3075{ 3075{
3076 usb_control_msg(gspca_dev->dev, 3076 int ret;
3077
3078 if (gspca_dev->usb_err < 0)
3079 return;
3080 ret = usb_control_msg(gspca_dev->dev,
3077 usb_rcvctrlpipe(gspca_dev->dev, 0), 3081 usb_rcvctrlpipe(gspca_dev->dev, 0),
3078 req, 3082 req,
3079 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 3083 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
3080 1, /* value */ 3084 1, /* value */
3081 index, gspca_dev->usb_buf, len, 3085 index, gspca_dev->usb_buf, len,
3082 500); 3086 500);
3087 if (ret < 0) {
3088 PDEBUG(D_ERR, "reg_r err %d", ret);
3089 gspca_dev->usb_err = ret;
3090 }
3091}
3092static void reg_r(struct gspca_dev *gspca_dev,
3093 u16 req,
3094 u16 index,
3095 u16 len)
3096{
3097 reg_r_i(gspca_dev, req, index, len);
3098#ifdef GSPCA_DEBUG
3099 if (gspca_dev->usb_err < 0)
3100 return;
3101 if (len == 1)
3102 PDEBUG(D_USBI, "GET %02x 0001 %04x %02x", req, index,
3103 gspca_dev->usb_buf[0]);
3104 else
3105 PDEBUG(D_USBI, "GET %02x 0001 %04x %02x %02x %02x",
3106 req, index,
3107 gspca_dev->usb_buf[0],
3108 gspca_dev->usb_buf[1],
3109 gspca_dev->usb_buf[2]);
3110#endif
3083} 3111}
3084 3112
3085static void reg_w(struct usb_device *dev, 3113static void reg_w_i(struct gspca_dev *gspca_dev,
3086 u16 req, 3114 u16 req,
3087 u16 value, 3115 u16 value,
3088 u16 index) 3116 u16 index)
3089{ 3117{
3090 usb_control_msg(dev, 3118 int ret;
3091 usb_sndctrlpipe(dev, 0), 3119
3120 if (gspca_dev->usb_err < 0)
3121 return;
3122 ret = usb_control_msg(gspca_dev->dev,
3123 usb_sndctrlpipe(gspca_dev->dev, 0),
3092 req, 3124 req,
3093 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 3125 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
3094 value, index, NULL, 0, 3126 value, index, NULL, 0,
3095 500); 3127 500);
3128 if (ret < 0) {
3129 PDEBUG(D_ERR, "reg_w err %d", ret);
3130 gspca_dev->usb_err = ret;
3131 }
3132}
3133static void reg_w(struct gspca_dev *gspca_dev,
3134 u16 req,
3135 u16 value,
3136 u16 index)
3137{
3138#ifdef GSPCA_DEBUG
3139 if (gspca_dev->usb_err < 0)
3140 return;
3141 PDEBUG(D_USBO, "SET %02x %04x %04x", req, value, index);
3142#endif
3143 reg_w_i(gspca_dev, req, value, index);
3096} 3144}
3097 3145
3098static u16 read_sensor_register(struct gspca_dev *gspca_dev, 3146static u16 read_sensor_register(struct gspca_dev *gspca_dev,
3099 u16 address) 3147 u16 address)
3100{ 3148{
3101 struct usb_device *dev = gspca_dev->dev;
3102 u8 ldata, mdata, hdata; 3149 u8 ldata, mdata, hdata;
3103 int retry = 50; 3150 int retry = 50;
3104 3151
@@ -3108,8 +3155,8 @@ static u16 read_sensor_register(struct gspca_dev *gspca_dev,
3108 gspca_dev->usb_buf[0]); 3155 gspca_dev->usb_buf[0]);
3109 return 0; 3156 return 0;
3110 } 3157 }
3111 reg_w(dev, 0xa0, address, 0xb33a); 3158 reg_w(gspca_dev, 0xa0, address, 0xb33a);
3112 reg_w(dev, 0xa0, 0x02, 0xb339); 3159 reg_w(gspca_dev, 0xa0, 0x02, 0xb339);
3113 3160
3114 do { 3161 do {
3115 reg_r(gspca_dev, 0xa1, 0xb33b, 1); 3162 reg_r(gspca_dev, 0xa1, 0xb33b, 1);
@@ -3136,15 +3183,15 @@ static u16 read_sensor_register(struct gspca_dev *gspca_dev,
3136static int vc032x_probe_sensor(struct gspca_dev *gspca_dev) 3183static int vc032x_probe_sensor(struct gspca_dev *gspca_dev)
3137{ 3184{
3138 struct sd *sd = (struct sd *) gspca_dev; 3185 struct sd *sd = (struct sd *) gspca_dev;
3139 struct usb_device *dev = gspca_dev->dev;
3140 int i, n; 3186 int i, n;
3141 u16 value; 3187 u16 value;
3142 const struct sensor_info *ptsensor_info; 3188 const struct sensor_info *ptsensor_info;
3143 3189
3144/*fixme: should also check the other sensor (back mi1320_soc, front mc501cb)*/ 3190/*fixme: should also check the other sensor (back mi1320_soc, front mc501cb)*/
3145 if (sd->flags & FL_SAMSUNG) { 3191 if (sd->flags & FL_SAMSUNG) {
3146 reg_w(dev, 0xa0, 0x01, 0xb301); 3192 reg_w(gspca_dev, 0xa0, 0x01, 0xb301);
3147 reg_w(dev, 0x89, 0xf0ff, 0xffff); /* select the back sensor */ 3193 reg_w(gspca_dev, 0x89, 0xf0ff, 0xffff);
3194 /* select the back sensor */
3148 } 3195 }
3149 3196
3150 reg_r(gspca_dev, 0xa1, 0xbfcf, 1); 3197 reg_r(gspca_dev, 0xa1, 0xbfcf, 1);
@@ -3158,13 +3205,13 @@ static int vc032x_probe_sensor(struct gspca_dev *gspca_dev)
3158 n = ARRAY_SIZE(vc0323_probe_data); 3205 n = ARRAY_SIZE(vc0323_probe_data);
3159 } 3206 }
3160 for (i = 0; i < n; i++) { 3207 for (i = 0; i < n; i++) {
3161 reg_w(dev, 0xa0, 0x02, 0xb334); 3208 reg_w(gspca_dev, 0xa0, 0x02, 0xb334);
3162 reg_w(dev, 0xa0, ptsensor_info->m1, 0xb300); 3209 reg_w(gspca_dev, 0xa0, ptsensor_info->m1, 0xb300);
3163 reg_w(dev, 0xa0, ptsensor_info->m2, 0xb300); 3210 reg_w(gspca_dev, 0xa0, ptsensor_info->m2, 0xb300);
3164 reg_w(dev, 0xa0, 0x01, 0xb308); 3211 reg_w(gspca_dev, 0xa0, 0x01, 0xb308);
3165 reg_w(dev, 0xa0, 0x0c, 0xb309); 3212 reg_w(gspca_dev, 0xa0, 0x0c, 0xb309);
3166 reg_w(dev, 0xa0, ptsensor_info->I2cAdd, 0xb335); 3213 reg_w(gspca_dev, 0xa0, ptsensor_info->I2cAdd, 0xb335);
3167 reg_w(dev, 0xa0, ptsensor_info->op, 0xb301); 3214 reg_w(gspca_dev, 0xa0, ptsensor_info->op, 0xb301);
3168 value = read_sensor_register(gspca_dev, ptsensor_info->IdAdd); 3215 value = read_sensor_register(gspca_dev, ptsensor_info->IdAdd);
3169 if (value == 0 && ptsensor_info->IdAdd == 0x82) 3216 if (value == 0 && ptsensor_info->IdAdd == 0x82)
3170 value = read_sensor_register(gspca_dev, 0x83); 3217 value = read_sensor_register(gspca_dev, 0x83);
@@ -3192,26 +3239,33 @@ static void i2c_write(struct gspca_dev *gspca_dev,
3192 u8 reg, const u8 *val, 3239 u8 reg, const u8 *val,
3193 u8 size) /* 1 or 2 */ 3240 u8 size) /* 1 or 2 */
3194{ 3241{
3195 struct usb_device *dev = gspca_dev->dev;
3196 int retry; 3242 int retry;
3197 3243
3198 reg_r(gspca_dev, 0xa1, 0xb33f, 1); 3244#ifdef GSPCA_DEBUG
3245 if (gspca_dev->usb_err < 0)
3246 return;
3247 if (size == 1)
3248 PDEBUG(D_USBO, "i2c_w %02x %02x", reg, *val);
3249 else
3250 PDEBUG(D_USBO, "i2c_w %02x %02x%02x", reg, *val, val[1]);
3251#endif
3252 reg_r_i(gspca_dev, 0xa1, 0xb33f, 1);
3199/*fixme:should check if (!(gspca_dev->usb_buf[0] & 0x02)) error*/ 3253/*fixme:should check if (!(gspca_dev->usb_buf[0] & 0x02)) error*/
3200 reg_w(dev, 0xa0, size, 0xb334); 3254 reg_w_i(gspca_dev, 0xa0, size, 0xb334);
3201 reg_w(dev, 0xa0, reg, 0xb33a); 3255 reg_w_i(gspca_dev, 0xa0, reg, 0xb33a);
3202 reg_w(dev, 0xa0, val[0], 0xb336); 3256 reg_w_i(gspca_dev, 0xa0, val[0], 0xb336);
3203 if (size > 1) 3257 if (size > 1)
3204 reg_w(dev, 0xa0, val[1], 0xb337); 3258 reg_w_i(gspca_dev, 0xa0, val[1], 0xb337);
3205 reg_w(dev, 0xa0, 0x01, 0xb339); 3259 reg_w_i(gspca_dev, 0xa0, 0x01, 0xb339);
3206 retry = 4; 3260 retry = 4;
3207 do { 3261 do {
3208 reg_r(gspca_dev, 0xa1, 0xb33b, 1); 3262 reg_r_i(gspca_dev, 0xa1, 0xb33b, 1);
3209 if (gspca_dev->usb_buf[0] == 0) 3263 if (gspca_dev->usb_buf[0] == 0)
3210 break; 3264 break;
3211 msleep(20); 3265 msleep(20);
3212 } while (--retry > 0); 3266 } while (--retry > 0);
3213 if (retry <= 0) 3267 if (retry <= 0)
3214 PDEBUG(D_ERR, "i2c_write failed"); 3268 PDEBUG(D_ERR, "i2c_write timeout");
3215} 3269}
3216 3270
3217static void put_tab_to_reg(struct gspca_dev *gspca_dev, 3271static void put_tab_to_reg(struct gspca_dev *gspca_dev,
@@ -3221,13 +3275,12 @@ static void put_tab_to_reg(struct gspca_dev *gspca_dev,
3221 u16 ad = addr; 3275 u16 ad = addr;
3222 3276
3223 for (j = 0; j < tabsize; j++) 3277 for (j = 0; j < tabsize; j++)
3224 reg_w(gspca_dev->dev, 0xa0, tab[j], ad++); 3278 reg_w(gspca_dev, 0xa0, tab[j], ad++);
3225} 3279}
3226 3280
3227static void usb_exchange(struct gspca_dev *gspca_dev, 3281static void usb_exchange(struct gspca_dev *gspca_dev,
3228 const u8 data[][4]) 3282 const u8 data[][4])
3229{ 3283{
3230 struct usb_device *dev = gspca_dev->dev;
3231 int i = 0; 3284 int i = 0;
3232 3285
3233 for (;;) { 3286 for (;;) {
@@ -3235,7 +3288,7 @@ static void usb_exchange(struct gspca_dev *gspca_dev,
3235 default: 3288 default:
3236 return; 3289 return;
3237 case 0xcc: /* normal write */ 3290 case 0xcc: /* normal write */
3238 reg_w(dev, 0xa0, data[i][2], 3291 reg_w(gspca_dev, 0xa0, data[i][2],
3239 (data[i][0]) << 8 | data[i][1]); 3292 (data[i][0]) << 8 | data[i][1]);
3240 break; 3293 break;
3241 case 0xaa: /* i2c op */ 3294 case 0xaa: /* i2c op */
@@ -3259,7 +3312,6 @@ static int sd_config(struct gspca_dev *gspca_dev,
3259 const struct usb_device_id *id) 3312 const struct usb_device_id *id)
3260{ 3313{
3261 struct sd *sd = (struct sd *) gspca_dev; 3314 struct sd *sd = (struct sd *) gspca_dev;
3262 struct usb_device *dev = gspca_dev->dev;
3263 struct cam *cam; 3315 struct cam *cam;
3264 int sensor; 3316 int sensor;
3265 static u8 npkt[] = { /* number of packets per ISOC message */ 3317 static u8 npkt[] = { /* number of packets per ISOC message */
@@ -3363,13 +3415,6 @@ static int sd_config(struct gspca_dev *gspca_dev,
3363 if (sd->sensor == SENSOR_OV7670) 3415 if (sd->sensor == SENSOR_OV7670)
3364 sd->flags |= FL_HFLIP | FL_VFLIP; 3416 sd->flags |= FL_HFLIP | FL_VFLIP;
3365 3417
3366 if (sd->bridge == BRIDGE_VC0321) {
3367 reg_r(gspca_dev, 0x8a, 0, 3);
3368 reg_w(dev, 0x87, 0x00, 0x0f0f);
3369
3370 reg_r(gspca_dev, 0x8b, 0, 3);
3371 reg_w(dev, 0x88, 0x00, 0x0202);
3372 }
3373 return 0; 3418 return 0;
3374} 3419}
3375 3420
@@ -3378,15 +3423,21 @@ static int sd_init(struct gspca_dev *gspca_dev)
3378{ 3423{
3379 struct sd *sd = (struct sd *) gspca_dev; 3424 struct sd *sd = (struct sd *) gspca_dev;
3380 3425
3381 if (sd->sensor == SENSOR_POxxxx) { 3426 if (sd->bridge == BRIDGE_VC0321) {
3382 reg_r(gspca_dev, 0xa1, 0xb300, 1); 3427 reg_r(gspca_dev, 0x8a, 0, 3);
3383 if (gspca_dev->usb_buf[0] != 0) { 3428 reg_w(gspca_dev, 0x87, 0x00, 0x0f0f);
3384 reg_w(gspca_dev->dev, 0xa0, 0x26, 0xb300); 3429 reg_r(gspca_dev, 0x8b, 0, 3);
3385 reg_w(gspca_dev->dev, 0xa0, 0x04, 0xb300); 3430 reg_w(gspca_dev, 0x88, 0x00, 0x0202);
3386 reg_w(gspca_dev->dev, 0xa0, 0x00, 0xb300); 3431 if (sd->sensor == SENSOR_POxxxx) {
3432 reg_r(gspca_dev, 0xa1, 0xb300, 1);
3433 if (gspca_dev->usb_buf[0] != 0) {
3434 reg_w(gspca_dev, 0xa0, 0x26, 0xb300);
3435 reg_w(gspca_dev, 0xa0, 0x04, 0xb300);
3436 reg_w(gspca_dev, 0xa0, 0x00, 0xb300);
3437 }
3387 } 3438 }
3388 } 3439 }
3389 return 0; 3440 return gspca_dev->usb_err;
3390} 3441}
3391 3442
3392static void setbrightness(struct gspca_dev *gspca_dev) 3443static void setbrightness(struct gspca_dev *gspca_dev)
@@ -3516,17 +3567,17 @@ static int sd_start(struct gspca_dev *gspca_dev)
3516 3567
3517/*fixme: back sensor only*/ 3568/*fixme: back sensor only*/
3518 if (sd->flags & FL_SAMSUNG) { 3569 if (sd->flags & FL_SAMSUNG) {
3519 reg_w(gspca_dev->dev, 0x89, 0xf0ff, 0xffff); 3570 reg_w(gspca_dev, 0x89, 0xf0ff, 0xffff);
3520 reg_w(gspca_dev->dev, 0xa9, 0x8348, 0x000e); 3571 reg_w(gspca_dev, 0xa9, 0x8348, 0x000e);
3521 reg_w(gspca_dev->dev, 0xa9, 0x0000, 0x001a); 3572 reg_w(gspca_dev, 0xa9, 0x0000, 0x001a);
3522 } 3573 }
3523 3574
3524 /* Assume start use the good resolution from gspca_dev->mode */ 3575 /* Assume start use the good resolution from gspca_dev->mode */
3525 if (sd->bridge == BRIDGE_VC0321) { 3576 if (sd->bridge == BRIDGE_VC0321) {
3526 reg_w(gspca_dev->dev, 0xa0, 0xff, 0xbfec); 3577 reg_w(gspca_dev, 0xa0, 0xff, 0xbfec);
3527 reg_w(gspca_dev->dev, 0xa0, 0xff, 0xbfed); 3578 reg_w(gspca_dev, 0xa0, 0xff, 0xbfed);
3528 reg_w(gspca_dev->dev, 0xa0, 0xff, 0xbfee); 3579 reg_w(gspca_dev, 0xa0, 0xff, 0xbfee);
3529 reg_w(gspca_dev->dev, 0xa0, 0xff, 0xbfef); 3580 reg_w(gspca_dev, 0xa0, 0xff, 0xbfef);
3530 sd->image_offset = 46; 3581 sd->image_offset = 46;
3531 } else { 3582 } else {
3532 if (gspca_dev->cam.cam_mode[gspca_dev->curr_mode].pixelformat 3583 if (gspca_dev->cam.cam_mode[gspca_dev->curr_mode].pixelformat
@@ -3617,7 +3668,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
3617 init = poxxxx_initVGA; 3668 init = poxxxx_initVGA;
3618 usb_exchange(gspca_dev, init); 3669 usb_exchange(gspca_dev, init);
3619 reg_r(gspca_dev, 0x8c, 0x0000, 3); 3670 reg_r(gspca_dev, 0x8c, 0x0000, 3);
3620 reg_w(gspca_dev->dev, 0xa0, 3671 reg_w(gspca_dev, 0xa0,
3621 gspca_dev->usb_buf[2] & 1 ? 0 : 1, 3672 gspca_dev->usb_buf[2] & 1 ? 0 : 1,
3622 0xb35c); 3673 0xb35c);
3623 msleep(300); 3674 msleep(300);
@@ -3635,10 +3686,10 @@ static int sd_start(struct gspca_dev *gspca_dev)
3635 switch (sd->sensor) { 3686 switch (sd->sensor) {
3636 case SENSOR_PO1200: 3687 case SENSOR_PO1200:
3637 case SENSOR_HV7131R: 3688 case SENSOR_HV7131R:
3638 reg_w(gspca_dev->dev, 0x89, 0x0400, 0x1415); 3689 reg_w(gspca_dev, 0x89, 0x0400, 0x1415);
3639 break; 3690 break;
3640 case SENSOR_MI1310_SOC: 3691 case SENSOR_MI1310_SOC:
3641 reg_w(gspca_dev->dev, 0x89, 0x058c, 0x0000); 3692 reg_w(gspca_dev, 0x89, 0x058c, 0x0000);
3642 break; 3693 break;
3643 } 3694 }
3644 msleep(100); 3695 msleep(100);
@@ -3648,9 +3699,9 @@ static int sd_start(struct gspca_dev *gspca_dev)
3648 } 3699 }
3649 switch (sd->sensor) { 3700 switch (sd->sensor) {
3650 case SENSOR_OV7670: 3701 case SENSOR_OV7670:
3651 reg_w(gspca_dev->dev, 0x87, 0xffff, 0xffff); 3702 reg_w(gspca_dev, 0x87, 0xffff, 0xffff);
3652 reg_w(gspca_dev->dev, 0x88, 0xff00, 0xf0f1); 3703 reg_w(gspca_dev, 0x88, 0xff00, 0xf0f1);
3653 reg_w(gspca_dev->dev, 0xa0, 0x0000, 0xbfff); 3704 reg_w(gspca_dev, 0xa0, 0x0000, 0xbfff);
3654 break; 3705 break;
3655 case SENSOR_POxxxx: 3706 case SENSOR_POxxxx:
3656 setcolors(gspca_dev); 3707 setcolors(gspca_dev);
@@ -3659,51 +3710,49 @@ static int sd_start(struct gspca_dev *gspca_dev)
3659 3710
3660 /* led on */ 3711 /* led on */
3661 msleep(80); 3712 msleep(80);
3662 reg_w(gspca_dev->dev, 0x89, 0xffff, 0xfdff); 3713 reg_w(gspca_dev, 0x89, 0xffff, 0xfdff);
3663 usb_exchange(gspca_dev, poxxxx_init_end_2); 3714 usb_exchange(gspca_dev, poxxxx_init_end_2);
3664 break; 3715 break;
3665 } 3716 }
3666 return 0; 3717 return gspca_dev->usb_err;
3667} 3718}
3668 3719
3669static void sd_stopN(struct gspca_dev *gspca_dev) 3720static void sd_stopN(struct gspca_dev *gspca_dev)
3670{ 3721{
3671 struct usb_device *dev = gspca_dev->dev;
3672 struct sd *sd = (struct sd *) gspca_dev; 3722 struct sd *sd = (struct sd *) gspca_dev;
3673 3723
3674 switch (sd->sensor) { 3724 switch (sd->sensor) {
3675 case SENSOR_MI1310_SOC: 3725 case SENSOR_MI1310_SOC:
3676 reg_w(dev, 0x89, 0x058c, 0x00ff); 3726 reg_w(gspca_dev, 0x89, 0x058c, 0x00ff);
3677 break; 3727 break;
3678 case SENSOR_POxxxx: 3728 case SENSOR_POxxxx:
3679 return; 3729 return;
3680 default: 3730 default:
3681 if (!(sd->flags & FL_SAMSUNG)) 3731 if (!(sd->flags & FL_SAMSUNG))
3682 reg_w(dev, 0x89, 0xffff, 0xffff); 3732 reg_w(gspca_dev, 0x89, 0xffff, 0xffff);
3683 break; 3733 break;
3684 } 3734 }
3685 reg_w(dev, 0xa0, 0x01, 0xb301); 3735 reg_w(gspca_dev, 0xa0, 0x01, 0xb301);
3686 reg_w(dev, 0xa0, 0x09, 0xb003); 3736 reg_w(gspca_dev, 0xa0, 0x09, 0xb003);
3687} 3737}
3688 3738
3689/* called on streamoff with alt 0 and on disconnect */ 3739/* called on streamoff with alt 0 and on disconnect */
3690static void sd_stop0(struct gspca_dev *gspca_dev) 3740static void sd_stop0(struct gspca_dev *gspca_dev)
3691{ 3741{
3692 struct usb_device *dev = gspca_dev->dev;
3693 struct sd *sd = (struct sd *) gspca_dev; 3742 struct sd *sd = (struct sd *) gspca_dev;
3694 3743
3695 if (!gspca_dev->present) 3744 if (!gspca_dev->present)
3696 return; 3745 return;
3697/*fixme: is this useful?*/ 3746/*fixme: is this useful?*/
3698 if (sd->sensor == SENSOR_MI1310_SOC) 3747 if (sd->sensor == SENSOR_MI1310_SOC)
3699 reg_w(dev, 0x89, 0x058c, 0x00ff); 3748 reg_w(gspca_dev, 0x89, 0x058c, 0x00ff);
3700 else if (!(sd->flags & FL_SAMSUNG)) 3749 else if (!(sd->flags & FL_SAMSUNG))
3701 reg_w(dev, 0x89, 0xffff, 0xffff); 3750 reg_w(gspca_dev, 0x89, 0xffff, 0xffff);
3702 3751
3703 if (sd->sensor == SENSOR_POxxxx) { 3752 if (sd->sensor == SENSOR_POxxxx) {
3704 reg_w(dev, 0xa0, 0x26, 0xb300); 3753 reg_w(gspca_dev, 0xa0, 0x26, 0xb300);
3705 reg_w(dev, 0xa0, 0x04, 0xb300); 3754 reg_w(gspca_dev, 0xa0, 0x04, 0xb300);
3706 reg_w(dev, 0xa0, 0x00, 0xb300); 3755 reg_w(gspca_dev, 0xa0, 0x00, 0xb300);
3707 } 3756 }
3708} 3757}
3709 3758
@@ -3726,17 +3775,12 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
3726 /* The vc0321 sends some additional data after sending the complete 3775 /* The vc0321 sends some additional data after sending the complete
3727 * frame, we ignore this. */ 3776 * frame, we ignore this. */
3728 if (sd->bridge == BRIDGE_VC0321) { 3777 if (sd->bridge == BRIDGE_VC0321) {
3729 struct gspca_frame *frame; 3778 int size, l;
3730 int l;
3731 3779
3732 frame = gspca_get_i_frame(gspca_dev); 3780 l = gspca_dev->image_len;
3733 if (frame == NULL) { 3781 size = gspca_dev->frsz;
3734 gspca_dev->last_packet_type = DISCARD_PACKET; 3782 if (len > size - l)
3735 return; 3783 len = size - l;
3736 }
3737 l = frame->data_end - frame->data;
3738 if (len > frame->v4l2_buf.length - l)
3739 len = frame->v4l2_buf.length - l;
3740 } 3784 }
3741 gspca_frame_add(gspca_dev, INTER_PACKET, data, len); 3785 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
3742} 3786}
@@ -3748,7 +3792,7 @@ static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
3748 sd->brightness = val; 3792 sd->brightness = val;
3749 if (gspca_dev->streaming) 3793 if (gspca_dev->streaming)
3750 setbrightness(gspca_dev); 3794 setbrightness(gspca_dev);
3751 return 0; 3795 return gspca_dev->usb_err;
3752} 3796}
3753 3797
3754static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val) 3798static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
@@ -3766,7 +3810,7 @@ static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
3766 sd->contrast = val; 3810 sd->contrast = val;
3767 if (gspca_dev->streaming) 3811 if (gspca_dev->streaming)
3768 setcontrast(gspca_dev); 3812 setcontrast(gspca_dev);
3769 return 0; 3813 return gspca_dev->usb_err;
3770} 3814}
3771 3815
3772static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val) 3816static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
@@ -3784,7 +3828,7 @@ static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
3784 sd->colors = val; 3828 sd->colors = val;
3785 if (gspca_dev->streaming) 3829 if (gspca_dev->streaming)
3786 setcolors(gspca_dev); 3830 setcolors(gspca_dev);
3787 return 0; 3831 return gspca_dev->usb_err;
3788} 3832}
3789 3833
3790static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val) 3834static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
@@ -3802,7 +3846,7 @@ static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val)
3802 sd->hflip = val; 3846 sd->hflip = val;
3803 if (gspca_dev->streaming) 3847 if (gspca_dev->streaming)
3804 sethvflip(gspca_dev); 3848 sethvflip(gspca_dev);
3805 return 0; 3849 return gspca_dev->usb_err;
3806} 3850}
3807 3851
3808static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val) 3852static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val)
@@ -3820,7 +3864,7 @@ static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val)
3820 sd->vflip = val; 3864 sd->vflip = val;
3821 if (gspca_dev->streaming) 3865 if (gspca_dev->streaming)
3822 sethvflip(gspca_dev); 3866 sethvflip(gspca_dev);
3823 return 0; 3867 return gspca_dev->usb_err;
3824} 3868}
3825 3869
3826static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val) 3870static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val)
@@ -3838,7 +3882,7 @@ static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val)
3838 sd->lightfreq = val; 3882 sd->lightfreq = val;
3839 if (gspca_dev->streaming) 3883 if (gspca_dev->streaming)
3840 setlightfreq(gspca_dev); 3884 setlightfreq(gspca_dev);
3841 return 0; 3885 return gspca_dev->usb_err;
3842} 3886}
3843 3887
3844static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val) 3888static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val)
@@ -3856,7 +3900,7 @@ static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val)
3856 sd->sharpness = val; 3900 sd->sharpness = val;
3857 if (gspca_dev->streaming) 3901 if (gspca_dev->streaming)
3858 setsharpness(gspca_dev); 3902 setsharpness(gspca_dev);
3859 return 0; 3903 return gspca_dev->usb_err;
3860} 3904}
3861 3905
3862static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val) 3906static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val)
diff --git a/drivers/media/video/gspca/w996Xcf.c b/drivers/media/video/gspca/w996Xcf.c
index 2fffe203bed8..38a68591ce48 100644
--- a/drivers/media/video/gspca/w996Xcf.c
+++ b/drivers/media/video/gspca/w996Xcf.c
@@ -31,14 +31,10 @@
31 the sensor drivers to v4l2 sub drivers, and properly split of this 31 the sensor drivers to v4l2 sub drivers, and properly split of this
32 driver from ov519.c */ 32 driver from ov519.c */
33 33
34/* The CONEX_CAM define for jpeg.h needs renaming, now its used here too */
35#define CONEX_CAM
36#include "jpeg.h"
37
38#define W9968CF_I2C_BUS_DELAY 4 /* delay in us for I2C bit r/w operations */ 34#define W9968CF_I2C_BUS_DELAY 4 /* delay in us for I2C bit r/w operations */
39 35
40#define Y_QUANTABLE (sd->jpeg_hdr + JPEG_QT0_OFFSET) 36#define Y_QUANTABLE (&sd->jpeg_hdr[JPEG_QT0_OFFSET])
41#define UV_QUANTABLE (sd->jpeg_hdr + JPEG_QT1_OFFSET) 37#define UV_QUANTABLE (&sd->jpeg_hdr[JPEG_QT1_OFFSET])
42 38
43static const struct v4l2_pix_format w9968cf_vga_mode[] = { 39static const struct v4l2_pix_format w9968cf_vga_mode[] = {
44 {160, 120, V4L2_PIX_FMT_UYVY, V4L2_FIELD_NONE, 40 {160, 120, V4L2_PIX_FMT_UYVY, V4L2_FIELD_NONE,
@@ -509,11 +505,6 @@ static int w9968cf_mode_init_regs(struct sd *sd)
509 if (w9968cf_vga_mode[sd->gspca_dev.curr_mode].pixelformat == 505 if (w9968cf_vga_mode[sd->gspca_dev.curr_mode].pixelformat ==
510 V4L2_PIX_FMT_JPEG) { 506 V4L2_PIX_FMT_JPEG) {
511 /* We may get called multiple times (usb isoc bw negotiat.) */ 507 /* We may get called multiple times (usb isoc bw negotiat.) */
512 if (!sd->jpeg_hdr)
513 sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL);
514 if (!sd->jpeg_hdr)
515 return -ENOMEM;
516
517 jpeg_define(sd->jpeg_hdr, sd->gspca_dev.height, 508 jpeg_define(sd->jpeg_hdr, sd->gspca_dev.height,
518 sd->gspca_dev.width, 0x22); /* JPEG 420 */ 509 sd->gspca_dev.width, 0x22); /* JPEG 420 */
519 jpeg_set_qual(sd->jpeg_hdr, sd->quality); 510 jpeg_set_qual(sd->jpeg_hdr, sd->quality);
@@ -562,9 +553,6 @@ static void w9968cf_stop0(struct sd *sd)
562 reg_w(sd, 0x39, 0x0000); /* disable JPEG encoder */ 553 reg_w(sd, 0x39, 0x0000); /* disable JPEG encoder */
563 reg_w(sd, 0x16, 0x0000); /* stop video capture */ 554 reg_w(sd, 0x16, 0x0000); /* stop video capture */
564 } 555 }
565
566 kfree(sd->jpeg_hdr);
567 sd->jpeg_hdr = NULL;
568} 556}
569 557
570/* The w9968cf docs say that a 0 sized packet means EOF (and also SOF 558/* The w9968cf docs say that a 0 sized packet means EOF (and also SOF
diff --git a/drivers/media/video/gspca/zc3xx.c b/drivers/media/video/gspca/zc3xx.c
index d02aa5c8472a..4473f0fb8b73 100644
--- a/drivers/media/video/gspca/zc3xx.c
+++ b/drivers/media/video/gspca/zc3xx.c
@@ -22,7 +22,6 @@
22#define MODULE_NAME "zc3xx" 22#define MODULE_NAME "zc3xx"
23 23
24#include <linux/input.h> 24#include <linux/input.h>
25#include <linux/slab.h>
26#include "gspca.h" 25#include "gspca.h"
27#include "jpeg.h" 26#include "jpeg.h"
28 27
@@ -40,15 +39,16 @@ static int force_sensor = -1;
40struct sd { 39struct sd {
41 struct gspca_dev gspca_dev; /* !! must be the first item */ 40 struct gspca_dev gspca_dev; /* !! must be the first item */
42 41
42 u8 brightness;
43 u8 contrast; 43 u8 contrast;
44 u8 gamma; 44 u8 gamma;
45 u8 autogain; 45 u8 autogain;
46 u8 lightfreq; 46 u8 lightfreq;
47 u8 sharpness; 47 u8 sharpness;
48 u8 quality; /* image quality */ 48 u8 quality; /* image quality */
49#define QUALITY_MIN 40 49#define QUALITY_MIN 50
50#define QUALITY_MAX 60 50#define QUALITY_MAX 80
51#define QUALITY_DEF 50 51#define QUALITY_DEF 70
52 52
53 u8 sensor; /* Type of image sensor chip */ 53 u8 sensor; /* Type of image sensor chip */
54/* !! values used in different tables */ 54/* !! values used in different tables */
@@ -75,10 +75,12 @@ struct sd {
75#define SENSOR_MAX 19 75#define SENSOR_MAX 19
76 unsigned short chip_revision; 76 unsigned short chip_revision;
77 77
78 u8 *jpeg_hdr; 78 u8 jpeg_hdr[JPEG_HDR_SZ];
79}; 79};
80 80
81/* V4L2 controls supported by the driver */ 81/* V4L2 controls supported by the driver */
82static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
83static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
82static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val); 84static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
83static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val); 85static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
84static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val); 86static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
@@ -93,6 +95,20 @@ static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val);
93static const struct ctrl sd_ctrls[] = { 95static const struct ctrl sd_ctrls[] = {
94 { 96 {
95 { 97 {
98 .id = V4L2_CID_BRIGHTNESS,
99 .type = V4L2_CTRL_TYPE_INTEGER,
100 .name = "Brightness",
101 .minimum = 0,
102 .maximum = 255,
103 .step = 1,
104#define BRIGHTNESS_DEF 128
105 .default_value = BRIGHTNESS_DEF,
106 },
107 .set = sd_setbrightness,
108 .get = sd_getbrightness,
109 },
110 {
111 {
96 .id = V4L2_CID_CONTRAST, 112 .id = V4L2_CID_CONTRAST,
97 .type = V4L2_CTRL_TYPE_INTEGER, 113 .type = V4L2_CTRL_TYPE_INTEGER,
98 .name = "Contrast", 114 .name = "Contrast",
@@ -132,7 +148,7 @@ static const struct ctrl sd_ctrls[] = {
132 .set = sd_setautogain, 148 .set = sd_setautogain,
133 .get = sd_getautogain, 149 .get = sd_getautogain,
134 }, 150 },
135#define LIGHTFREQ_IDX 3 151#define LIGHTFREQ_IDX 4
136 { 152 {
137 { 153 {
138 .id = V4L2_CID_POWER_LINE_FREQUENCY, 154 .id = V4L2_CID_POWER_LINE_FREQUENCY,
@@ -6011,9 +6027,12 @@ static void setcontrast(struct gspca_dev *gspca_dev)
6011 struct sd *sd = (struct sd *) gspca_dev; 6027 struct sd *sd = (struct sd *) gspca_dev;
6012 struct usb_device *dev = gspca_dev->dev; 6028 struct usb_device *dev = gspca_dev->dev;
6013 const u8 *Tgamma; 6029 const u8 *Tgamma;
6014 int g, i, k, adj, gp; 6030 int g, i, brightness, contrast, adj, gp1, gp2;
6015 u8 gr[16]; 6031 u8 gr[16];
6016 static const u8 delta_tb[16] = /* delta for contrast */ 6032 static const u8 delta_b[16] = /* delta for brightness */
6033 {0x50, 0x38, 0x2d, 0x28, 0x24, 0x21, 0x1e, 0x1d,
6034 0x1d, 0x1b, 0x1b, 0x1b, 0x19, 0x18, 0x18, 0x18};
6035 static const u8 delta_c[16] = /* delta for contrast */
6017 {0x2c, 0x1a, 0x12, 0x0c, 0x0a, 0x06, 0x06, 0x06, 6036 {0x2c, 0x1a, 0x12, 0x0c, 0x0a, 0x06, 0x06, 0x06,
6018 0x04, 0x06, 0x04, 0x04, 0x03, 0x03, 0x02, 0x02}; 6037 0x04, 0x06, 0x04, 0x04, 0x03, 0x03, 0x02, 0x02};
6019 static const u8 gamma_tb[6][16] = { 6038 static const u8 gamma_tb[6][16] = {
@@ -6033,30 +6052,30 @@ static void setcontrast(struct gspca_dev *gspca_dev)
6033 6052
6034 Tgamma = gamma_tb[sd->gamma - 1]; 6053 Tgamma = gamma_tb[sd->gamma - 1];
6035 6054
6036 k = ((int) sd->contrast - 128); /* -128 / 128 */ 6055 contrast = ((int) sd->contrast - 128); /* -128 / 127 */
6056 brightness = ((int) sd->brightness - 128); /* -128 / 92 */
6037 adj = 0; 6057 adj = 0;
6038 gp = 0; 6058 gp1 = gp2 = 0;
6039 for (i = 0; i < 16; i++) { 6059 for (i = 0; i < 16; i++) {
6040 g = Tgamma[i] - delta_tb[i] * k / 256 - adj / 2; 6060 g = Tgamma[i] + delta_b[i] * brightness / 256
6061 - delta_c[i] * contrast / 256 - adj / 2;
6041 if (g > 0xff) 6062 if (g > 0xff)
6042 g = 0xff; 6063 g = 0xff;
6043 else if (g < 0) 6064 else if (g < 0)
6044 g = 0; 6065 g = 0;
6045 reg_w(dev, g, 0x0120 + i); /* gamma */ 6066 reg_w(dev, g, 0x0120 + i); /* gamma */
6046 if (k > 0) 6067 if (contrast > 0)
6047 adj--; 6068 adj--;
6048 else 6069 else if (contrast < 0)
6049 adj++; 6070 adj++;
6050 6071 if (i > 1)
6051 if (i != 0) { 6072 gr[i - 1] = (g - gp2) / 2;
6052 if (gp == 0) 6073 else if (i != 0)
6053 gr[i - 1] = 0; 6074 gr[0] = gp1 == 0 ? 0 : (g - gp1);
6054 else 6075 gp2 = gp1;
6055 gr[i - 1] = g - gp; 6076 gp1 = g;
6056 }
6057 gp = g;
6058 } 6077 }
6059 gr[15] = gr[14] / 2; 6078 gr[15] = (0xff - gp2) / 2;
6060 for (i = 0; i < 16; i++) 6079 for (i = 0; i < 16; i++)
6061 reg_w(dev, gr[i], 0x0130 + i); /* gradient */ 6080 reg_w(dev, gr[i], 0x0130 + i); /* gradient */
6062} 6081}
@@ -6744,6 +6763,7 @@ static int sd_config(struct gspca_dev *gspca_dev,
6744 cam->nmodes = ARRAY_SIZE(broken_vga_mode); 6763 cam->nmodes = ARRAY_SIZE(broken_vga_mode);
6745 break; 6764 break;
6746 } 6765 }
6766 sd->brightness = BRIGHTNESS_DEF;
6747 sd->contrast = CONTRAST_DEF; 6767 sd->contrast = CONTRAST_DEF;
6748 sd->gamma = gamma[sd->sensor]; 6768 sd->gamma = gamma[sd->sensor];
6749 sd->autogain = AUTOGAIN_DEF; 6769 sd->autogain = AUTOGAIN_DEF;
@@ -6798,9 +6818,6 @@ static int sd_start(struct gspca_dev *gspca_dev)
6798 }; 6818 };
6799 6819
6800 /* create the JPEG header */ 6820 /* create the JPEG header */
6801 sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL);
6802 if (!sd->jpeg_hdr)
6803 return -ENOMEM;
6804 jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width, 6821 jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
6805 0x21); /* JPEG 422 */ 6822 0x21); /* JPEG 422 */
6806 jpeg_set_qual(sd->jpeg_hdr, sd->quality); 6823 jpeg_set_qual(sd->jpeg_hdr, sd->quality);
@@ -6918,10 +6935,6 @@ static int sd_start(struct gspca_dev *gspca_dev)
6918 reg_w(dev, 0x00, 0x0007); /* (from win traces) */ 6935 reg_w(dev, 0x00, 0x0007); /* (from win traces) */
6919 reg_w(dev, 0x02, ZC3XX_R008_CLOCKSETTING); 6936 reg_w(dev, 0x02, ZC3XX_R008_CLOCKSETTING);
6920 break; 6937 break;
6921 case SENSOR_PAS202B:
6922 reg_w(dev, 0x32, 0x0007); /* (from win traces) */
6923 reg_w(dev, 0x02, ZC3XX_R008_CLOCKSETTING);
6924 break;
6925 } 6938 }
6926 return 0; 6939 return 0;
6927} 6940}
@@ -6931,7 +6944,6 @@ static void sd_stop0(struct gspca_dev *gspca_dev)
6931{ 6944{
6932 struct sd *sd = (struct sd *) gspca_dev; 6945 struct sd *sd = (struct sd *) gspca_dev;
6933 6946
6934 kfree(sd->jpeg_hdr);
6935 if (!gspca_dev->present) 6947 if (!gspca_dev->present)
6936 return; 6948 return;
6937 send_unknown(gspca_dev->dev, sd->sensor); 6949 send_unknown(gspca_dev->dev, sd->sensor);
@@ -6962,6 +6974,24 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
6962 gspca_frame_add(gspca_dev, INTER_PACKET, data, len); 6974 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
6963} 6975}
6964 6976
6977static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
6978{
6979 struct sd *sd = (struct sd *) gspca_dev;
6980
6981 sd->brightness = val;
6982 if (gspca_dev->streaming)
6983 setcontrast(gspca_dev);
6984 return 0;
6985}
6986
6987static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
6988{
6989 struct sd *sd = (struct sd *) gspca_dev;
6990
6991 *val = sd->brightness;
6992 return 0;
6993}
6994
6965static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val) 6995static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
6966{ 6996{
6967 struct sd *sd = (struct sd *) gspca_dev; 6997 struct sd *sd = (struct sd *) gspca_dev;
@@ -7163,9 +7193,7 @@ static const __devinitdata struct usb_device_id device_table[] = {
7163 {USB_DEVICE(0x046d, 0x08aa)}, 7193 {USB_DEVICE(0x046d, 0x08aa)},
7164 {USB_DEVICE(0x046d, 0x08ac)}, 7194 {USB_DEVICE(0x046d, 0x08ac)},
7165 {USB_DEVICE(0x046d, 0x08ad)}, 7195 {USB_DEVICE(0x046d, 0x08ad)},
7166#if !defined CONFIG_USB_ZC0301 && !defined CONFIG_USB_ZC0301_MODULE
7167 {USB_DEVICE(0x046d, 0x08ae)}, 7196 {USB_DEVICE(0x046d, 0x08ae)},
7168#endif
7169 {USB_DEVICE(0x046d, 0x08af)}, 7197 {USB_DEVICE(0x046d, 0x08af)},
7170 {USB_DEVICE(0x046d, 0x08b9)}, 7198 {USB_DEVICE(0x046d, 0x08b9)},
7171 {USB_DEVICE(0x046d, 0x08d7)}, 7199 {USB_DEVICE(0x046d, 0x08d7)},
diff --git a/drivers/media/video/hdpvr/hdpvr-core.c b/drivers/media/video/hdpvr/hdpvr-core.c
index 830d47b05e1d..0cae5b82e1a2 100644
--- a/drivers/media/video/hdpvr/hdpvr-core.c
+++ b/drivers/media/video/hdpvr/hdpvr-core.c
@@ -286,6 +286,8 @@ static int hdpvr_probe(struct usb_interface *interface,
286 goto error; 286 goto error;
287 } 287 }
288 288
289 dev->workqueue = 0;
290
289 /* register v4l2_device early so it can be used for printks */ 291 /* register v4l2_device early so it can be used for printks */
290 if (v4l2_device_register(&interface->dev, &dev->v4l2_dev)) { 292 if (v4l2_device_register(&interface->dev, &dev->v4l2_dev)) {
291 err("v4l2_device_register failed"); 293 err("v4l2_device_register failed");
@@ -380,6 +382,9 @@ static int hdpvr_probe(struct usb_interface *interface,
380 382
381error: 383error:
382 if (dev) { 384 if (dev) {
385 /* Destroy single thread */
386 if (dev->workqueue)
387 destroy_workqueue(dev->workqueue);
383 /* this frees allocated memory */ 388 /* this frees allocated memory */
384 hdpvr_delete(dev); 389 hdpvr_delete(dev);
385 } 390 }
diff --git a/drivers/media/video/hdpvr/hdpvr-video.c b/drivers/media/video/hdpvr/hdpvr-video.c
index c338f3f62e77..4863a21b1f24 100644
--- a/drivers/media/video/hdpvr/hdpvr-video.c
+++ b/drivers/media/video/hdpvr/hdpvr-video.c
@@ -394,7 +394,7 @@ err:
394 394
395static int hdpvr_release(struct file *file) 395static int hdpvr_release(struct file *file)
396{ 396{
397 struct hdpvr_fh *fh = (struct hdpvr_fh *)file->private_data; 397 struct hdpvr_fh *fh = file->private_data;
398 struct hdpvr_device *dev = fh->dev; 398 struct hdpvr_device *dev = fh->dev;
399 399
400 if (!dev) 400 if (!dev)
@@ -518,7 +518,7 @@ err:
518static unsigned int hdpvr_poll(struct file *filp, poll_table *wait) 518static unsigned int hdpvr_poll(struct file *filp, poll_table *wait)
519{ 519{
520 struct hdpvr_buffer *buf = NULL; 520 struct hdpvr_buffer *buf = NULL;
521 struct hdpvr_fh *fh = (struct hdpvr_fh *)filp->private_data; 521 struct hdpvr_fh *fh = filp->private_data;
522 struct hdpvr_device *dev = fh->dev; 522 struct hdpvr_device *dev = fh->dev;
523 unsigned int mask = 0; 523 unsigned int mask = 0;
524 524
diff --git a/drivers/media/video/ir-kbd-i2c.c b/drivers/media/video/ir-kbd-i2c.c
index 29d439742653..27ae8bbfb477 100644
--- a/drivers/media/video/ir-kbd-i2c.c
+++ b/drivers/media/video/ir-kbd-i2c.c
@@ -47,7 +47,7 @@
47#include <linux/i2c-id.h> 47#include <linux/i2c-id.h>
48#include <linux/workqueue.h> 48#include <linux/workqueue.h>
49 49
50#include <media/ir-common.h> 50#include <media/ir-core.h>
51#include <media/ir-kbd-i2c.h> 51#include <media/ir-kbd-i2c.h>
52 52
53/* ----------------------------------------------------------------------- */ 53/* ----------------------------------------------------------------------- */
@@ -272,11 +272,8 @@ static void ir_key_poll(struct IR_i2c *ir)
272 return; 272 return;
273 } 273 }
274 274
275 if (0 == rc) { 275 if (rc)
276 ir_input_nokey(ir->input, &ir->ir); 276 ir_keydown(ir->input, ir_key, 0);
277 } else {
278 ir_input_keydown(ir->input, &ir->ir, ir_key);
279 }
280} 277}
281 278
282static void ir_work(struct work_struct *work) 279static void ir_work(struct work_struct *work)
@@ -439,10 +436,7 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
439 dev_name(&client->dev)); 436 dev_name(&client->dev));
440 437
441 /* init + register input device */ 438 /* init + register input device */
442 err = ir_input_init(input_dev, &ir->ir, ir_type); 439 ir->ir_type = ir_type;
443 if (err < 0)
444 goto err_out_free;
445
446 input_dev->id.bustype = BUS_I2C; 440 input_dev->id.bustype = BUS_I2C;
447 input_dev->name = ir->name; 441 input_dev->name = ir->name;
448 input_dev->phys = ir->phys; 442 input_dev->phys = ir->phys;
diff --git a/drivers/media/video/ivtv/ivtv-driver.c b/drivers/media/video/ivtv/ivtv-driver.c
index 1b79475ca134..90daa6e751d8 100644
--- a/drivers/media/video/ivtv/ivtv-driver.c
+++ b/drivers/media/video/ivtv/ivtv-driver.c
@@ -130,6 +130,9 @@ static int ivtv_yuv_threshold = -1;
130static int ivtv_pci_latency = 1; 130static int ivtv_pci_latency = 1;
131 131
132int ivtv_debug; 132int ivtv_debug;
133#ifdef CONFIG_VIDEO_ADV_DEBUG
134int ivtv_fw_debug;
135#endif
133 136
134static int tunertype = -1; 137static int tunertype = -1;
135static int newi2c = -1; 138static int newi2c = -1;
@@ -141,6 +144,9 @@ module_param_string(pal, pal, sizeof(pal), 0644);
141module_param_string(secam, secam, sizeof(secam), 0644); 144module_param_string(secam, secam, sizeof(secam), 0644);
142module_param_string(ntsc, ntsc, sizeof(ntsc), 0644); 145module_param_string(ntsc, ntsc, sizeof(ntsc), 0644);
143module_param_named(debug,ivtv_debug, int, 0644); 146module_param_named(debug,ivtv_debug, int, 0644);
147#ifdef CONFIG_VIDEO_ADV_DEBUG
148module_param_named(fw_debug, ivtv_fw_debug, int, 0644);
149#endif
144module_param(ivtv_pci_latency, int, 0644); 150module_param(ivtv_pci_latency, int, 0644);
145module_param(ivtv_yuv_mode, int, 0644); 151module_param(ivtv_yuv_mode, int, 0644);
146module_param(ivtv_yuv_threshold, int, 0644); 152module_param(ivtv_yuv_threshold, int, 0644);
@@ -217,6 +223,10 @@ MODULE_PARM_DESC(debug,
217 "\t\t\t 256/0x0100: yuv\n" 223 "\t\t\t 256/0x0100: yuv\n"
218 "\t\t\t 512/0x0200: i2c\n" 224 "\t\t\t 512/0x0200: i2c\n"
219 "\t\t\t1024/0x0400: high volume\n"); 225 "\t\t\t1024/0x0400: high volume\n");
226#ifdef CONFIG_VIDEO_ADV_DEBUG
227MODULE_PARM_DESC(fw_debug,
228 "Enable code for debugging firmware problems. Default: 0\n");
229#endif
220MODULE_PARM_DESC(ivtv_pci_latency, 230MODULE_PARM_DESC(ivtv_pci_latency,
221 "Change the PCI latency to 64 if lower: 0 = No, 1 = Yes,\n" 231 "Change the PCI latency to 64 if lower: 0 = No, 1 = Yes,\n"
222 "\t\t\tDefault: Yes"); 232 "\t\t\tDefault: Yes");
@@ -1425,12 +1435,16 @@ EXPORT_SYMBOL(ivtv_vapi);
1425EXPORT_SYMBOL(ivtv_vapi_result); 1435EXPORT_SYMBOL(ivtv_vapi_result);
1426EXPORT_SYMBOL(ivtv_clear_irq_mask); 1436EXPORT_SYMBOL(ivtv_clear_irq_mask);
1427EXPORT_SYMBOL(ivtv_debug); 1437EXPORT_SYMBOL(ivtv_debug);
1438#ifdef CONFIG_VIDEO_ADV_DEBUG
1439EXPORT_SYMBOL(ivtv_fw_debug);
1440#endif
1428EXPORT_SYMBOL(ivtv_reset_ir_gpio); 1441EXPORT_SYMBOL(ivtv_reset_ir_gpio);
1429EXPORT_SYMBOL(ivtv_udma_setup); 1442EXPORT_SYMBOL(ivtv_udma_setup);
1430EXPORT_SYMBOL(ivtv_udma_unmap); 1443EXPORT_SYMBOL(ivtv_udma_unmap);
1431EXPORT_SYMBOL(ivtv_udma_alloc); 1444EXPORT_SYMBOL(ivtv_udma_alloc);
1432EXPORT_SYMBOL(ivtv_udma_prepare); 1445EXPORT_SYMBOL(ivtv_udma_prepare);
1433EXPORT_SYMBOL(ivtv_init_on_first_open); 1446EXPORT_SYMBOL(ivtv_init_on_first_open);
1447EXPORT_SYMBOL(ivtv_firmware_check);
1434 1448
1435module_init(module_start); 1449module_init(module_start);
1436module_exit(module_cleanup); 1450module_exit(module_cleanup);
diff --git a/drivers/media/video/ivtv/ivtv-driver.h b/drivers/media/video/ivtv/ivtv-driver.h
index 5b45fd2b2645..bd084df4448a 100644
--- a/drivers/media/video/ivtv/ivtv-driver.h
+++ b/drivers/media/video/ivtv/ivtv-driver.h
@@ -122,6 +122,9 @@
122 122
123/* debugging */ 123/* debugging */
124extern int ivtv_debug; 124extern int ivtv_debug;
125#ifdef CONFIG_VIDEO_ADV_DEBUG
126extern int ivtv_fw_debug;
127#endif
125 128
126#define IVTV_DBGFLG_WARN (1 << 0) 129#define IVTV_DBGFLG_WARN (1 << 0)
127#define IVTV_DBGFLG_INFO (1 << 1) 130#define IVTV_DBGFLG_INFO (1 << 1)
@@ -734,6 +737,7 @@ struct ivtv {
734 struct v4l2_rect osd_rect; /* current OSD position and size */ 737 struct v4l2_rect osd_rect; /* current OSD position and size */
735 struct v4l2_rect main_rect; /* current Main window position and size */ 738 struct v4l2_rect main_rect; /* current Main window position and size */
736 struct osd_info *osd_info; /* ivtvfb private OSD info */ 739 struct osd_info *osd_info; /* ivtvfb private OSD info */
740 void (*ivtvfb_restore)(struct ivtv *itv); /* Used for a warm start */
737}; 741};
738 742
739static inline struct ivtv *to_ivtv(struct v4l2_device *v4l2_dev) 743static inline struct ivtv *to_ivtv(struct v4l2_device *v4l2_dev)
diff --git a/drivers/media/video/ivtv/ivtv-fileops.c b/drivers/media/video/ivtv/ivtv-fileops.c
index 3c2cc270ccd5..a6a2cdb81566 100644
--- a/drivers/media/video/ivtv/ivtv-fileops.c
+++ b/drivers/media/video/ivtv/ivtv-fileops.c
@@ -32,6 +32,7 @@
32#include "ivtv-yuv.h" 32#include "ivtv-yuv.h"
33#include "ivtv-ioctl.h" 33#include "ivtv-ioctl.h"
34#include "ivtv-cards.h" 34#include "ivtv-cards.h"
35#include "ivtv-firmware.h"
35#include <media/v4l2-event.h> 36#include <media/v4l2-event.h>
36#include <media/saa7115.h> 37#include <media/saa7115.h>
37 38
@@ -526,6 +527,7 @@ int ivtv_start_decoding(struct ivtv_open_id *id, int speed)
526{ 527{
527 struct ivtv *itv = id->itv; 528 struct ivtv *itv = id->itv;
528 struct ivtv_stream *s = &itv->streams[id->type]; 529 struct ivtv_stream *s = &itv->streams[id->type];
530 int rc;
529 531
530 if (atomic_read(&itv->decoding) == 0) { 532 if (atomic_read(&itv->decoding) == 0) {
531 if (ivtv_claim_stream(id, s->type)) { 533 if (ivtv_claim_stream(id, s->type)) {
@@ -533,7 +535,13 @@ int ivtv_start_decoding(struct ivtv_open_id *id, int speed)
533 IVTV_DEBUG_WARN("start decode, stream already claimed\n"); 535 IVTV_DEBUG_WARN("start decode, stream already claimed\n");
534 return -EBUSY; 536 return -EBUSY;
535 } 537 }
536 ivtv_start_v4l2_decode_stream(s, 0); 538 rc = ivtv_start_v4l2_decode_stream(s, 0);
539 if (rc < 0) {
540 if (rc == -EAGAIN)
541 rc = ivtv_start_v4l2_decode_stream(s, 0);
542 if (rc < 0)
543 return rc;
544 }
537 } 545 }
538 if (s->type == IVTV_DEC_STREAM_TYPE_MPG) 546 if (s->type == IVTV_DEC_STREAM_TYPE_MPG)
539 return ivtv_set_speed(itv, speed); 547 return ivtv_set_speed(itv, speed);
@@ -912,12 +920,32 @@ int ivtv_v4l2_close(struct file *filp)
912 920
913static int ivtv_serialized_open(struct ivtv_stream *s, struct file *filp) 921static int ivtv_serialized_open(struct ivtv_stream *s, struct file *filp)
914{ 922{
923#ifdef CONFIG_VIDEO_ADV_DEBUG
924 struct video_device *vdev = video_devdata(filp);
925#endif
915 struct ivtv *itv = s->itv; 926 struct ivtv *itv = s->itv;
916 struct ivtv_open_id *item; 927 struct ivtv_open_id *item;
917 int res = 0; 928 int res = 0;
918 929
919 IVTV_DEBUG_FILE("open %s\n", s->name); 930 IVTV_DEBUG_FILE("open %s\n", s->name);
920 931
932#ifdef CONFIG_VIDEO_ADV_DEBUG
933 /* Unless ivtv_fw_debug is set, error out if firmware dead. */
934 if (ivtv_fw_debug) {
935 IVTV_WARN("Opening %s with dead firmware lockout disabled\n",
936 video_device_node_name(vdev));
937 IVTV_WARN("Selected firmware errors will be ignored\n");
938 } else {
939#else
940 if (1) {
941#endif
942 res = ivtv_firmware_check(itv, "ivtv_serialized_open");
943 if (res == -EAGAIN)
944 res = ivtv_firmware_check(itv, "ivtv_serialized_open");
945 if (res < 0)
946 return -EIO;
947 }
948
921 if (s->type == IVTV_DEC_STREAM_TYPE_MPG && 949 if (s->type == IVTV_DEC_STREAM_TYPE_MPG &&
922 test_bit(IVTV_F_S_CLAIMED, &itv->streams[IVTV_DEC_STREAM_TYPE_YUV].s_flags)) 950 test_bit(IVTV_F_S_CLAIMED, &itv->streams[IVTV_DEC_STREAM_TYPE_YUV].s_flags))
923 return -EBUSY; 951 return -EBUSY;
diff --git a/drivers/media/video/ivtv/ivtv-firmware.c b/drivers/media/video/ivtv/ivtv-firmware.c
index a71e8ba306b0..d8bf2b01729d 100644
--- a/drivers/media/video/ivtv/ivtv-firmware.c
+++ b/drivers/media/video/ivtv/ivtv-firmware.c
@@ -23,7 +23,10 @@
23#include "ivtv-mailbox.h" 23#include "ivtv-mailbox.h"
24#include "ivtv-firmware.h" 24#include "ivtv-firmware.h"
25#include "ivtv-yuv.h" 25#include "ivtv-yuv.h"
26#include "ivtv-ioctl.h"
27#include "ivtv-cards.h"
26#include <linux/firmware.h> 28#include <linux/firmware.h>
29#include <media/saa7127.h>
27 30
28#define IVTV_MASK_SPU_ENABLE 0xFFFFFFFE 31#define IVTV_MASK_SPU_ENABLE 0xFFFFFFFE
29#define IVTV_MASK_VPU_ENABLE15 0xFFFFFFF6 32#define IVTV_MASK_VPU_ENABLE15 0xFFFFFFF6
@@ -271,3 +274,122 @@ void ivtv_init_mpeg_decoder(struct ivtv *itv)
271 } 274 }
272 ivtv_vapi(itv, CX2341X_DEC_STOP_PLAYBACK, 4, 0, 0, 0, 1); 275 ivtv_vapi(itv, CX2341X_DEC_STOP_PLAYBACK, 4, 0, 0, 0, 1);
273} 276}
277
278/* Try to restart the card & restore previous settings */
279int ivtv_firmware_restart(struct ivtv *itv)
280{
281 int rc = 0;
282 v4l2_std_id std;
283 struct ivtv_open_id fh;
284 fh.itv = itv;
285
286 if (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT)
287 /* Display test image during restart */
288 ivtv_call_hw(itv, IVTV_HW_SAA7127, video, s_routing,
289 SAA7127_INPUT_TYPE_TEST_IMAGE,
290 itv->card->video_outputs[itv->active_output].video_output,
291 0);
292
293 mutex_lock(&itv->udma.lock);
294
295 rc = ivtv_firmware_init(itv);
296 if (rc) {
297 mutex_unlock(&itv->udma.lock);
298 return rc;
299 }
300
301 /* Allow settings to reload */
302 ivtv_mailbox_cache_invalidate(itv);
303
304 /* Restore video standard */
305 std = itv->std;
306 itv->std = 0;
307 ivtv_s_std(NULL, &fh, &std);
308
309 if (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT) {
310 ivtv_init_mpeg_decoder(itv);
311
312 /* Restore framebuffer if active */
313 if (itv->ivtvfb_restore)
314 itv->ivtvfb_restore(itv);
315
316 /* Restore alpha settings */
317 ivtv_set_osd_alpha(itv);
318
319 /* Restore normal output */
320 ivtv_call_hw(itv, IVTV_HW_SAA7127, video, s_routing,
321 SAA7127_INPUT_TYPE_NORMAL,
322 itv->card->video_outputs[itv->active_output].video_output,
323 0);
324 }
325
326 mutex_unlock(&itv->udma.lock);
327 return rc;
328}
329
330/* Check firmware running state. The checks fall through
331 allowing multiple failures to be logged. */
332int ivtv_firmware_check(struct ivtv *itv, char *where)
333{
334 int res = 0;
335
336 /* Check encoder is still running */
337 if (ivtv_vapi(itv, CX2341X_ENC_PING_FW, 0) < 0) {
338 IVTV_WARN("Encoder has died : %s\n", where);
339 res = -1;
340 }
341
342 /* Also check audio. Only check if not in use & encoder is okay */
343 if (!res && !atomic_read(&itv->capturing) &&
344 (!atomic_read(&itv->decoding) ||
345 (atomic_read(&itv->decoding) < 2 && test_bit(IVTV_F_I_DEC_YUV,
346 &itv->i_flags)))) {
347
348 if (ivtv_vapi(itv, CX2341X_ENC_MISC, 1, 12) < 0) {
349 IVTV_WARN("Audio has died (Encoder OK) : %s\n", where);
350 res = -2;
351 }
352 }
353
354 if (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT) {
355 /* Second audio check. Skip if audio already failed */
356 if (res != -2 && read_dec(0x100) != read_dec(0x104)) {
357 /* Wait & try again to be certain. */
358 ivtv_msleep_timeout(14, 0);
359 if (read_dec(0x100) != read_dec(0x104)) {
360 IVTV_WARN("Audio has died (Decoder) : %s\n",
361 where);
362 res = -1;
363 }
364 }
365
366 /* Check decoder is still running */
367 if (ivtv_vapi(itv, CX2341X_DEC_PING_FW, 0) < 0) {
368 IVTV_WARN("Decoder has died : %s\n", where);
369 res = -1;
370 }
371 }
372
373 /* If something failed & currently idle, try to reload */
374 if (res && !atomic_read(&itv->capturing) &&
375 !atomic_read(&itv->decoding)) {
376 IVTV_INFO("Detected in %s that firmware had failed - "
377 "Reloading\n", where);
378 res = ivtv_firmware_restart(itv);
379 /*
380 * Even if restarted ok, still signal a problem had occured.
381 * The caller can come through this function again to check
382 * if things are really ok after the restart.
383 */
384 if (!res) {
385 IVTV_INFO("Firmware restart okay\n");
386 res = -EAGAIN;
387 } else {
388 IVTV_INFO("Firmware restart failed\n");
389 }
390 } else if (res) {
391 res = -EIO;
392 }
393
394 return res;
395}
diff --git a/drivers/media/video/ivtv/ivtv-firmware.h b/drivers/media/video/ivtv/ivtv-firmware.h
index 041ba94e65bc..52bb4e5598fd 100644
--- a/drivers/media/video/ivtv/ivtv-firmware.h
+++ b/drivers/media/video/ivtv/ivtv-firmware.h
@@ -26,5 +26,6 @@ int ivtv_firmware_init(struct ivtv *itv);
26void ivtv_firmware_versions(struct ivtv *itv); 26void ivtv_firmware_versions(struct ivtv *itv);
27void ivtv_halt_firmware(struct ivtv *itv); 27void ivtv_halt_firmware(struct ivtv *itv);
28void ivtv_init_mpeg_decoder(struct ivtv *itv); 28void ivtv_init_mpeg_decoder(struct ivtv *itv);
29int ivtv_firmware_check(struct ivtv *itv, char *where);
29 30
30#endif 31#endif
diff --git a/drivers/media/video/ivtv/ivtv-mailbox.c b/drivers/media/video/ivtv/ivtv-mailbox.c
index 84577f6f41a2..e3ce96763785 100644
--- a/drivers/media/video/ivtv/ivtv-mailbox.c
+++ b/drivers/media/video/ivtv/ivtv-mailbox.c
@@ -377,3 +377,11 @@ void ivtv_api_get_data(struct ivtv_mailbox_data *mbdata, int mb,
377 for (i = 0; i < argc; i++, p++) 377 for (i = 0; i < argc; i++, p++)
378 data[i] = readl(p); 378 data[i] = readl(p);
379} 379}
380
381/* Wipe api cache */
382void ivtv_mailbox_cache_invalidate(struct ivtv *itv)
383{
384 int i;
385 for (i = 0; i < 256; i++)
386 itv->api_cache[i].last_jiffies = 0;
387}
diff --git a/drivers/media/video/ivtv/ivtv-mailbox.h b/drivers/media/video/ivtv/ivtv-mailbox.h
index 8247662c928e..2c834d2cb56f 100644
--- a/drivers/media/video/ivtv/ivtv-mailbox.h
+++ b/drivers/media/video/ivtv/ivtv-mailbox.h
@@ -30,5 +30,6 @@ int ivtv_api(struct ivtv *itv, int cmd, int args, u32 data[]);
30int ivtv_vapi_result(struct ivtv *itv, u32 data[CX2341X_MBOX_MAX_DATA], int cmd, int args, ...); 30int ivtv_vapi_result(struct ivtv *itv, u32 data[CX2341X_MBOX_MAX_DATA], int cmd, int args, ...);
31int ivtv_vapi(struct ivtv *itv, int cmd, int args, ...); 31int ivtv_vapi(struct ivtv *itv, int cmd, int args, ...);
32int ivtv_api_func(void *priv, u32 cmd, int in, int out, u32 data[CX2341X_MBOX_MAX_DATA]); 32int ivtv_api_func(void *priv, u32 cmd, int in, int out, u32 data[CX2341X_MBOX_MAX_DATA]);
33void ivtv_mailbox_cache_invalidate(struct ivtv *itv);
33 34
34#endif 35#endif
diff --git a/drivers/media/video/ivtv/ivtv-streams.c b/drivers/media/video/ivtv/ivtv-streams.c
index a937e2ff9b6e..55df4190c28d 100644
--- a/drivers/media/video/ivtv/ivtv-streams.c
+++ b/drivers/media/video/ivtv/ivtv-streams.c
@@ -42,6 +42,7 @@
42#include "ivtv-yuv.h" 42#include "ivtv-yuv.h"
43#include "ivtv-cards.h" 43#include "ivtv-cards.h"
44#include "ivtv-streams.h" 44#include "ivtv-streams.h"
45#include "ivtv-firmware.h"
45#include <media/v4l2-event.h> 46#include <media/v4l2-event.h>
46 47
47static const struct v4l2_file_operations ivtv_v4l2_enc_fops = { 48static const struct v4l2_file_operations ivtv_v4l2_enc_fops = {
@@ -674,12 +675,14 @@ static int ivtv_setup_v4l2_decode_stream(struct ivtv_stream *s)
674 /* Decoder sometimes dies here, so wait a moment */ 675 /* Decoder sometimes dies here, so wait a moment */
675 ivtv_msleep_timeout(10, 0); 676 ivtv_msleep_timeout(10, 0);
676 677
677 return 0; 678 /* Known failure point for firmware, so check */
679 return ivtv_firmware_check(itv, "ivtv_setup_v4l2_decode_stream");
678} 680}
679 681
680int ivtv_start_v4l2_decode_stream(struct ivtv_stream *s, int gop_offset) 682int ivtv_start_v4l2_decode_stream(struct ivtv_stream *s, int gop_offset)
681{ 683{
682 struct ivtv *itv = s->itv; 684 struct ivtv *itv = s->itv;
685 int rc;
683 686
684 if (s->vdev == NULL) 687 if (s->vdev == NULL)
685 return -EINVAL; 688 return -EINVAL;
@@ -689,7 +692,11 @@ int ivtv_start_v4l2_decode_stream(struct ivtv_stream *s, int gop_offset)
689 692
690 IVTV_DEBUG_INFO("Starting decode stream %s (gop_offset %d)\n", s->name, gop_offset); 693 IVTV_DEBUG_INFO("Starting decode stream %s (gop_offset %d)\n", s->name, gop_offset);
691 694
692 ivtv_setup_v4l2_decode_stream(s); 695 rc = ivtv_setup_v4l2_decode_stream(s);
696 if (rc < 0) {
697 clear_bit(IVTV_F_S_STREAMING, &s->s_flags);
698 return rc;
699 }
693 700
694 /* set dma size to 65536 bytes */ 701 /* set dma size to 65536 bytes */
695 ivtv_vapi(itv, CX2341X_DEC_SET_DMA_BLOCK_SIZE, 1, 65536); 702 ivtv_vapi(itv, CX2341X_DEC_SET_DMA_BLOCK_SIZE, 1, 65536);
diff --git a/drivers/media/video/ivtv/ivtv-version.h b/drivers/media/video/ivtv/ivtv-version.h
index b530dec399d3..b67a4048f5aa 100644
--- a/drivers/media/video/ivtv/ivtv-version.h
+++ b/drivers/media/video/ivtv/ivtv-version.h
@@ -23,7 +23,7 @@
23#define IVTV_DRIVER_NAME "ivtv" 23#define IVTV_DRIVER_NAME "ivtv"
24#define IVTV_DRIVER_VERSION_MAJOR 1 24#define IVTV_DRIVER_VERSION_MAJOR 1
25#define IVTV_DRIVER_VERSION_MINOR 4 25#define IVTV_DRIVER_VERSION_MINOR 4
26#define IVTV_DRIVER_VERSION_PATCHLEVEL 1 26#define IVTV_DRIVER_VERSION_PATCHLEVEL 2
27 27
28#define IVTV_VERSION __stringify(IVTV_DRIVER_VERSION_MAJOR) "." __stringify(IVTV_DRIVER_VERSION_MINOR) "." __stringify(IVTV_DRIVER_VERSION_PATCHLEVEL) 28#define IVTV_VERSION __stringify(IVTV_DRIVER_VERSION_MAJOR) "." __stringify(IVTV_DRIVER_VERSION_MINOR) "." __stringify(IVTV_DRIVER_VERSION_PATCHLEVEL)
29#define IVTV_DRIVER_VERSION KERNEL_VERSION(IVTV_DRIVER_VERSION_MAJOR,IVTV_DRIVER_VERSION_MINOR,IVTV_DRIVER_VERSION_PATCHLEVEL) 29#define IVTV_DRIVER_VERSION KERNEL_VERSION(IVTV_DRIVER_VERSION_MAJOR,IVTV_DRIVER_VERSION_MINOR,IVTV_DRIVER_VERSION_PATCHLEVEL)
diff --git a/drivers/media/video/ivtv/ivtvfb.c b/drivers/media/video/ivtv/ivtvfb.c
index 9ff3425891ed..be03a712731c 100644
--- a/drivers/media/video/ivtv/ivtvfb.c
+++ b/drivers/media/video/ivtv/ivtvfb.c
@@ -53,6 +53,7 @@
53#include "ivtv-i2c.h" 53#include "ivtv-i2c.h"
54#include "ivtv-udma.h" 54#include "ivtv-udma.h"
55#include "ivtv-mailbox.h" 55#include "ivtv-mailbox.h"
56#include "ivtv-firmware.h"
56 57
57/* card parameters */ 58/* card parameters */
58static int ivtvfb_card_id = -1; 59static int ivtvfb_card_id = -1;
@@ -178,6 +179,12 @@ struct osd_info {
178 struct fb_info ivtvfb_info; 179 struct fb_info ivtvfb_info;
179 struct fb_var_screeninfo ivtvfb_defined; 180 struct fb_var_screeninfo ivtvfb_defined;
180 struct fb_fix_screeninfo ivtvfb_fix; 181 struct fb_fix_screeninfo ivtvfb_fix;
182
183 /* Used for a warm start */
184 struct fb_var_screeninfo fbvar_cur;
185 int blank_cur;
186 u32 palette_cur[256];
187 u32 pan_cur;
181}; 188};
182 189
183struct ivtv_osd_coords { 190struct ivtv_osd_coords {
@@ -199,6 +206,7 @@ static int ivtvfb_get_framebuffer(struct ivtv *itv, u32 *fbbase,
199 u32 data[CX2341X_MBOX_MAX_DATA]; 206 u32 data[CX2341X_MBOX_MAX_DATA];
200 int rc; 207 int rc;
201 208
209 ivtv_firmware_check(itv, "ivtvfb_get_framebuffer");
202 rc = ivtv_vapi_result(itv, data, CX2341X_OSD_GET_FRAMEBUFFER, 0); 210 rc = ivtv_vapi_result(itv, data, CX2341X_OSD_GET_FRAMEBUFFER, 0);
203 *fbbase = data[0]; 211 *fbbase = data[0];
204 *fblength = data[1]; 212 *fblength = data[1];
@@ -581,8 +589,10 @@ static int ivtvfb_set_var(struct ivtv *itv, struct fb_var_screeninfo *var)
581 ivtv_window.height = var->yres; 589 ivtv_window.height = var->yres;
582 590
583 /* Minimum margin cannot be 0, as X won't allow such a mode */ 591 /* Minimum margin cannot be 0, as X won't allow such a mode */
584 if (!var->upper_margin) var->upper_margin++; 592 if (!var->upper_margin)
585 if (!var->left_margin) var->left_margin++; 593 var->upper_margin++;
594 if (!var->left_margin)
595 var->left_margin++;
586 ivtv_window.top = var->upper_margin - 1; 596 ivtv_window.top = var->upper_margin - 1;
587 ivtv_window.left = var->left_margin - 1; 597 ivtv_window.left = var->left_margin - 1;
588 598
@@ -595,6 +605,9 @@ static int ivtvfb_set_var(struct ivtv *itv, struct fb_var_screeninfo *var)
595 /* Force update of yuv registers */ 605 /* Force update of yuv registers */
596 itv->yuv_info.yuv_forced_update = 1; 606 itv->yuv_info.yuv_forced_update = 1;
597 607
608 /* Keep a copy of these settings */
609 memcpy(&oi->fbvar_cur, var, sizeof(oi->fbvar_cur));
610
598 IVTVFB_DEBUG_INFO("Display size: %dx%d (virtual %dx%d) @ %dbpp\n", 611 IVTVFB_DEBUG_INFO("Display size: %dx%d (virtual %dx%d) @ %dbpp\n",
599 var->xres, var->yres, 612 var->xres, var->yres,
600 var->xres_virtual, var->yres_virtual, 613 var->xres_virtual, var->yres_virtual,
@@ -829,6 +842,8 @@ static int ivtvfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *inf
829 itv->yuv_info.osd_y_pan = var->yoffset; 842 itv->yuv_info.osd_y_pan = var->yoffset;
830 /* Force update of yuv registers */ 843 /* Force update of yuv registers */
831 itv->yuv_info.yuv_forced_update = 1; 844 itv->yuv_info.yuv_forced_update = 1;
845 /* Remember this value */
846 itv->osd_info->pan_cur = osd_pan_index;
832 return 0; 847 return 0;
833} 848}
834 849
@@ -842,6 +857,7 @@ static int ivtvfb_set_par(struct fb_info *info)
842 rc = ivtvfb_set_var(itv, &info->var); 857 rc = ivtvfb_set_var(itv, &info->var);
843 ivtvfb_pan_display(&info->var, info); 858 ivtvfb_pan_display(&info->var, info);
844 ivtvfb_get_fix(itv, &info->fix); 859 ivtvfb_get_fix(itv, &info->fix);
860 ivtv_firmware_check(itv, "ivtvfb_set_par");
845 return rc; 861 return rc;
846} 862}
847 863
@@ -859,6 +875,7 @@ static int ivtvfb_setcolreg(unsigned regno, unsigned red, unsigned green,
859 if (info->var.bits_per_pixel <= 8) { 875 if (info->var.bits_per_pixel <= 8) {
860 write_reg(regno, 0x02a30); 876 write_reg(regno, 0x02a30);
861 write_reg(color, 0x02a34); 877 write_reg(color, 0x02a34);
878 itv->osd_info->palette_cur[regno] = color;
862 return 0; 879 return 0;
863 } 880 }
864 if (regno >= 16) 881 if (regno >= 16)
@@ -911,6 +928,7 @@ static int ivtvfb_blank(int blank_mode, struct fb_info *info)
911 ivtv_vapi(itv, CX2341X_OSD_SET_STATE, 1, 0); 928 ivtv_vapi(itv, CX2341X_OSD_SET_STATE, 1, 0);
912 break; 929 break;
913 } 930 }
931 itv->osd_info->blank_cur = blank_mode;
914 return 0; 932 return 0;
915} 933}
916 934
@@ -929,6 +947,21 @@ static struct fb_ops ivtvfb_ops = {
929 .fb_blank = ivtvfb_blank, 947 .fb_blank = ivtvfb_blank,
930}; 948};
931 949
950/* Restore hardware after firmware restart */
951static void ivtvfb_restore(struct ivtv *itv)
952{
953 struct osd_info *oi = itv->osd_info;
954 int i;
955
956 ivtvfb_set_var(itv, &oi->fbvar_cur);
957 ivtvfb_blank(oi->blank_cur, &oi->ivtvfb_info);
958 for (i = 0; i < 256; i++) {
959 write_reg(i, 0x02a30);
960 write_reg(oi->palette_cur[i], 0x02a34);
961 }
962 write_reg(oi->pan_cur, 0x02a0c);
963}
964
932/* Initialization */ 965/* Initialization */
933 966
934 967
@@ -1192,6 +1225,9 @@ static int ivtvfb_init_card(struct ivtv *itv)
1192 /* Enable the osd */ 1225 /* Enable the osd */
1193 ivtvfb_blank(FB_BLANK_UNBLANK, &itv->osd_info->ivtvfb_info); 1226 ivtvfb_blank(FB_BLANK_UNBLANK, &itv->osd_info->ivtvfb_info);
1194 1227
1228 /* Enable restart */
1229 itv->ivtvfb_restore = ivtvfb_restore;
1230
1195 /* Allocate DMA */ 1231 /* Allocate DMA */
1196 ivtv_udma_alloc(itv); 1232 ivtv_udma_alloc(itv);
1197 return 0; 1233 return 0;
@@ -1203,7 +1239,7 @@ static int __init ivtvfb_callback_init(struct device *dev, void *p)
1203 struct v4l2_device *v4l2_dev = dev_get_drvdata(dev); 1239 struct v4l2_device *v4l2_dev = dev_get_drvdata(dev);
1204 struct ivtv *itv = container_of(v4l2_dev, struct ivtv, v4l2_dev); 1240 struct ivtv *itv = container_of(v4l2_dev, struct ivtv, v4l2_dev);
1205 1241
1206 if (itv && (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT)) { 1242 if (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT) {
1207 if (ivtvfb_init_card(itv) == 0) { 1243 if (ivtvfb_init_card(itv) == 0) {
1208 IVTVFB_INFO("Framebuffer registered on %s\n", 1244 IVTVFB_INFO("Framebuffer registered on %s\n",
1209 itv->v4l2_dev.name); 1245 itv->v4l2_dev.name);
@@ -1219,13 +1255,14 @@ static int ivtvfb_callback_cleanup(struct device *dev, void *p)
1219 struct ivtv *itv = container_of(v4l2_dev, struct ivtv, v4l2_dev); 1255 struct ivtv *itv = container_of(v4l2_dev, struct ivtv, v4l2_dev);
1220 struct osd_info *oi = itv->osd_info; 1256 struct osd_info *oi = itv->osd_info;
1221 1257
1222 if (itv && (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT)) { 1258 if (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT) {
1223 if (unregister_framebuffer(&itv->osd_info->ivtvfb_info)) { 1259 if (unregister_framebuffer(&itv->osd_info->ivtvfb_info)) {
1224 IVTVFB_WARN("Framebuffer %d is in use, cannot unload\n", 1260 IVTVFB_WARN("Framebuffer %d is in use, cannot unload\n",
1225 itv->instance); 1261 itv->instance);
1226 return 0; 1262 return 0;
1227 } 1263 }
1228 IVTVFB_INFO("Unregister framebuffer %d\n", itv->instance); 1264 IVTVFB_INFO("Unregister framebuffer %d\n", itv->instance);
1265 itv->ivtvfb_restore = NULL;
1229 ivtvfb_blank(FB_BLANK_VSYNC_SUSPEND, &oi->ivtvfb_info); 1266 ivtvfb_blank(FB_BLANK_VSYNC_SUSPEND, &oi->ivtvfb_info);
1230 ivtvfb_release_buffers(itv); 1267 ivtvfb_release_buffers(itv);
1231 itv->osd_video_pbase = 0; 1268 itv->osd_video_pbase = 0;
diff --git a/drivers/media/video/mem2mem_testdev.c b/drivers/media/video/mem2mem_testdev.c
index 10ddeccc70eb..4525335f9bd4 100644
--- a/drivers/media/video/mem2mem_testdev.c
+++ b/drivers/media/video/mem2mem_testdev.c
@@ -903,14 +903,14 @@ static int m2mtest_release(struct file *file)
903static unsigned int m2mtest_poll(struct file *file, 903static unsigned int m2mtest_poll(struct file *file,
904 struct poll_table_struct *wait) 904 struct poll_table_struct *wait)
905{ 905{
906 struct m2mtest_ctx *ctx = (struct m2mtest_ctx *)file->private_data; 906 struct m2mtest_ctx *ctx = file->private_data;
907 907
908 return v4l2_m2m_poll(file, ctx->m2m_ctx, wait); 908 return v4l2_m2m_poll(file, ctx->m2m_ctx, wait);
909} 909}
910 910
911static int m2mtest_mmap(struct file *file, struct vm_area_struct *vma) 911static int m2mtest_mmap(struct file *file, struct vm_area_struct *vma)
912{ 912{
913 struct m2mtest_ctx *ctx = (struct m2mtest_ctx *)file->private_data; 913 struct m2mtest_ctx *ctx = file->private_data;
914 914
915 return v4l2_m2m_mmap(file, ctx->m2m_ctx, vma); 915 return v4l2_m2m_mmap(file, ctx->m2m_ctx, vma);
916} 916}
diff --git a/drivers/media/video/mt9m111.c b/drivers/media/video/mt9m111.c
index fbd0fc794720..31cc3d04bcc4 100644
--- a/drivers/media/video/mt9m111.c
+++ b/drivers/media/video/mt9m111.c
@@ -143,10 +143,10 @@ static const struct mt9m111_datafmt *mt9m111_find_datafmt(
143} 143}
144 144
145static const struct mt9m111_datafmt mt9m111_colour_fmts[] = { 145static const struct mt9m111_datafmt mt9m111_colour_fmts[] = {
146 {V4L2_MBUS_FMT_YUYV8_2X8_LE, V4L2_COLORSPACE_JPEG}, 146 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG},
147 {V4L2_MBUS_FMT_YVYU8_2X8_LE, V4L2_COLORSPACE_JPEG}, 147 {V4L2_MBUS_FMT_YVYU8_2X8, V4L2_COLORSPACE_JPEG},
148 {V4L2_MBUS_FMT_YUYV8_2X8_BE, V4L2_COLORSPACE_JPEG}, 148 {V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG},
149 {V4L2_MBUS_FMT_YVYU8_2X8_BE, V4L2_COLORSPACE_JPEG}, 149 {V4L2_MBUS_FMT_VYUY8_2X8, V4L2_COLORSPACE_JPEG},
150 {V4L2_MBUS_FMT_RGB555_2X8_PADHI_LE, V4L2_COLORSPACE_SRGB}, 150 {V4L2_MBUS_FMT_RGB555_2X8_PADHI_LE, V4L2_COLORSPACE_SRGB},
151 {V4L2_MBUS_FMT_RGB565_2X8_LE, V4L2_COLORSPACE_SRGB}, 151 {V4L2_MBUS_FMT_RGB565_2X8_LE, V4L2_COLORSPACE_SRGB},
152 {V4L2_MBUS_FMT_SBGGR8_1X8, V4L2_COLORSPACE_SRGB}, 152 {V4L2_MBUS_FMT_SBGGR8_1X8, V4L2_COLORSPACE_SRGB},
@@ -505,22 +505,22 @@ static int mt9m111_set_pixfmt(struct i2c_client *client,
505 case V4L2_MBUS_FMT_RGB565_2X8_LE: 505 case V4L2_MBUS_FMT_RGB565_2X8_LE:
506 ret = mt9m111_setfmt_rgb565(client); 506 ret = mt9m111_setfmt_rgb565(client);
507 break; 507 break;
508 case V4L2_MBUS_FMT_YUYV8_2X8_BE: 508 case V4L2_MBUS_FMT_UYVY8_2X8:
509 mt9m111->swap_yuv_y_chromas = 0; 509 mt9m111->swap_yuv_y_chromas = 0;
510 mt9m111->swap_yuv_cb_cr = 0; 510 mt9m111->swap_yuv_cb_cr = 0;
511 ret = mt9m111_setfmt_yuv(client); 511 ret = mt9m111_setfmt_yuv(client);
512 break; 512 break;
513 case V4L2_MBUS_FMT_YVYU8_2X8_BE: 513 case V4L2_MBUS_FMT_VYUY8_2X8:
514 mt9m111->swap_yuv_y_chromas = 0; 514 mt9m111->swap_yuv_y_chromas = 0;
515 mt9m111->swap_yuv_cb_cr = 1; 515 mt9m111->swap_yuv_cb_cr = 1;
516 ret = mt9m111_setfmt_yuv(client); 516 ret = mt9m111_setfmt_yuv(client);
517 break; 517 break;
518 case V4L2_MBUS_FMT_YUYV8_2X8_LE: 518 case V4L2_MBUS_FMT_YUYV8_2X8:
519 mt9m111->swap_yuv_y_chromas = 1; 519 mt9m111->swap_yuv_y_chromas = 1;
520 mt9m111->swap_yuv_cb_cr = 0; 520 mt9m111->swap_yuv_cb_cr = 0;
521 ret = mt9m111_setfmt_yuv(client); 521 ret = mt9m111_setfmt_yuv(client);
522 break; 522 break;
523 case V4L2_MBUS_FMT_YVYU8_2X8_LE: 523 case V4L2_MBUS_FMT_YVYU8_2X8:
524 mt9m111->swap_yuv_y_chromas = 1; 524 mt9m111->swap_yuv_y_chromas = 1;
525 mt9m111->swap_yuv_cb_cr = 1; 525 mt9m111->swap_yuv_cb_cr = 1;
526 ret = mt9m111_setfmt_yuv(client); 526 ret = mt9m111_setfmt_yuv(client);
diff --git a/drivers/media/video/mt9t112.c b/drivers/media/video/mt9t112.c
index e4bf1db9a87b..8ec47e42d4d0 100644
--- a/drivers/media/video/mt9t112.c
+++ b/drivers/media/video/mt9t112.c
@@ -121,22 +121,22 @@ struct mt9t112_priv {
121 121
122static const struct mt9t112_format mt9t112_cfmts[] = { 122static const struct mt9t112_format mt9t112_cfmts[] = {
123 { 123 {
124 .code = V4L2_MBUS_FMT_YUYV8_2X8_BE, 124 .code = V4L2_MBUS_FMT_UYVY8_2X8,
125 .colorspace = V4L2_COLORSPACE_JPEG, 125 .colorspace = V4L2_COLORSPACE_JPEG,
126 .fmt = 1, 126 .fmt = 1,
127 .order = 0, 127 .order = 0,
128 }, { 128 }, {
129 .code = V4L2_MBUS_FMT_YVYU8_2X8_BE, 129 .code = V4L2_MBUS_FMT_VYUY8_2X8,
130 .colorspace = V4L2_COLORSPACE_JPEG, 130 .colorspace = V4L2_COLORSPACE_JPEG,
131 .fmt = 1, 131 .fmt = 1,
132 .order = 1, 132 .order = 1,
133 }, { 133 }, {
134 .code = V4L2_MBUS_FMT_YUYV8_2X8_LE, 134 .code = V4L2_MBUS_FMT_YUYV8_2X8,
135 .colorspace = V4L2_COLORSPACE_JPEG, 135 .colorspace = V4L2_COLORSPACE_JPEG,
136 .fmt = 1, 136 .fmt = 1,
137 .order = 2, 137 .order = 2,
138 }, { 138 }, {
139 .code = V4L2_MBUS_FMT_YVYU8_2X8_LE, 139 .code = V4L2_MBUS_FMT_YVYU8_2X8,
140 .colorspace = V4L2_COLORSPACE_JPEG, 140 .colorspace = V4L2_COLORSPACE_JPEG,
141 .fmt = 1, 141 .fmt = 1,
142 .order = 3, 142 .order = 3,
@@ -972,7 +972,7 @@ static int mt9t112_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
972 struct v4l2_rect *rect = &a->c; 972 struct v4l2_rect *rect = &a->c;
973 973
974 return mt9t112_set_params(client, rect->width, rect->height, 974 return mt9t112_set_params(client, rect->width, rect->height,
975 V4L2_MBUS_FMT_YUYV8_2X8_BE); 975 V4L2_MBUS_FMT_UYVY8_2X8);
976} 976}
977 977
978static int mt9t112_g_fmt(struct v4l2_subdev *sd, 978static int mt9t112_g_fmt(struct v4l2_subdev *sd,
@@ -983,7 +983,7 @@ static int mt9t112_g_fmt(struct v4l2_subdev *sd,
983 983
984 if (!priv->format) { 984 if (!priv->format) {
985 int ret = mt9t112_set_params(client, VGA_WIDTH, VGA_HEIGHT, 985 int ret = mt9t112_set_params(client, VGA_WIDTH, VGA_HEIGHT,
986 V4L2_MBUS_FMT_YUYV8_2X8_BE); 986 V4L2_MBUS_FMT_UYVY8_2X8);
987 if (ret < 0) 987 if (ret < 0)
988 return ret; 988 return ret;
989 } 989 }
diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
index 929073e792c9..4ed51b1552e1 100644
--- a/drivers/media/video/omap/omap_vout.c
+++ b/drivers/media/video/omap/omap_vout.c
@@ -2545,19 +2545,11 @@ static int __init omap_vout_probe(struct platform_device *pdev)
2545 /* set the update mode */ 2545 /* set the update mode */
2546 if (def_display->caps & 2546 if (def_display->caps &
2547 OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE) { 2547 OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE) {
2548#ifdef CONFIG_FB_OMAP2_FORCE_AUTO_UPDATE
2549 if (dssdrv->enable_te)
2550 dssdrv->enable_te(def_display, 1);
2551 if (dssdrv->set_update_mode)
2552 dssdrv->set_update_mode(def_display,
2553 OMAP_DSS_UPDATE_AUTO);
2554#else /* MANUAL_UPDATE */
2555 if (dssdrv->enable_te) 2548 if (dssdrv->enable_te)
2556 dssdrv->enable_te(def_display, 0); 2549 dssdrv->enable_te(def_display, 0);
2557 if (dssdrv->set_update_mode) 2550 if (dssdrv->set_update_mode)
2558 dssdrv->set_update_mode(def_display, 2551 dssdrv->set_update_mode(def_display,
2559 OMAP_DSS_UPDATE_MANUAL); 2552 OMAP_DSS_UPDATE_MANUAL);
2560#endif
2561 } else { 2553 } else {
2562 if (dssdrv->set_update_mode) 2554 if (dssdrv->set_update_mode)
2563 dssdrv->set_update_mode(def_display, 2555 dssdrv->set_update_mode(def_display,
diff --git a/drivers/media/video/omap24xxcam.c b/drivers/media/video/omap24xxcam.c
index f85b2ed8a2d8..926a5aa6f7f8 100644
--- a/drivers/media/video/omap24xxcam.c
+++ b/drivers/media/video/omap24xxcam.c
@@ -426,7 +426,7 @@ static void omap24xxcam_vbq_release(struct videobuf_queue *vbq,
426 dma->direction); 426 dma->direction);
427 dma->direction = DMA_NONE; 427 dma->direction = DMA_NONE;
428 } else { 428 } else {
429 videobuf_dma_unmap(vbq, videobuf_to_dma(vb)); 429 videobuf_dma_unmap(vbq->dev, videobuf_to_dma(vb));
430 videobuf_dma_free(videobuf_to_dma(vb)); 430 videobuf_dma_free(videobuf_to_dma(vb));
431 } 431 }
432 432
diff --git a/drivers/media/video/ov511.c b/drivers/media/video/ov511.c
deleted file mode 100644
index a10912097b7a..000000000000
--- a/drivers/media/video/ov511.c
+++ /dev/null
@@ -1,5995 +0,0 @@
1/*
2 * OmniVision OV511 Camera-to-USB Bridge Driver
3 *
4 * Copyright (c) 1999-2003 Mark W. McClelland
5 * Original decompression code Copyright 1998-2000 OmniVision Technologies
6 * Many improvements by Bret Wallach <bwallac1@san.rr.com>
7 * Color fixes by by Orion Sky Lawlor <olawlor@acm.org> (2/26/2000)
8 * Snapshot code by Kevin Moore
9 * OV7620 fixes by Charl P. Botha <cpbotha@ieee.org>
10 * Changes by Claudio Matsuoka <claudio@conectiva.com>
11 * Original SAA7111A code by Dave Perks <dperks@ibm.net>
12 * URB error messages from pwc driver by Nemosoft
13 * generic_ioctl() code from videodev.c by Gerd Knorr and Alan Cox
14 * Memory management (rvmalloc) code from bttv driver, by Gerd Knorr and others
15 *
16 * Based on the Linux CPiA driver written by Peter Pregler,
17 * Scott J. Bertin and Johannes Erdfelt.
18 *
19 * Please see the file: Documentation/usb/ov511.txt
20 * and the website at: http://alpha.dyndns.org/ov511
21 * for more info.
22 *
23 * This program is free software; you can redistribute it and/or modify it
24 * under the terms of the GNU General Public License as published by the
25 * Free Software Foundation; either version 2 of the License, or (at your
26 * option) any later version.
27 *
28 * This program is distributed in the hope that it will be useful, but
29 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
30 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
31 * for more details.
32 *
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, write to the Free Software Foundation,
35 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
36 */
37
38#include <linux/module.h>
39#include <linux/init.h>
40#include <linux/vmalloc.h>
41#include <linux/slab.h>
42#include <linux/ctype.h>
43#include <linux/pagemap.h>
44#include <asm/processor.h>
45#include <linux/mm.h>
46#include <linux/device.h>
47
48#if defined (__i386__)
49 #include <asm/cpufeature.h>
50#endif
51
52#include "ov511.h"
53
54/*
55 * Version Information
56 */
57#define DRIVER_VERSION "v1.64 for Linux 2.5"
58#define EMAIL "mark@alpha.dyndns.org"
59#define DRIVER_AUTHOR "Mark McClelland <mark@alpha.dyndns.org> & Bret Wallach \
60& Orion Sky Lawlor <olawlor@acm.org> & Kevin Moore & Charl P. Botha \
61<cpbotha@ieee.org> & Claudio Matsuoka <claudio@conectiva.com>"
62#define DRIVER_DESC "ov511 USB Camera Driver"
63
64#define OV511_I2C_RETRIES 3
65#define ENABLE_Y_QUANTABLE 1
66#define ENABLE_UV_QUANTABLE 1
67
68#define OV511_MAX_UNIT_VIDEO 16
69
70/* Pixel count * bytes per YUV420 pixel (1.5) */
71#define MAX_FRAME_SIZE(w, h) ((w) * (h) * 3 / 2)
72
73#define MAX_DATA_SIZE(w, h) (MAX_FRAME_SIZE(w, h) + sizeof(struct timeval))
74
75/* Max size * bytes per YUV420 pixel (1.5) + one extra isoc frame for safety */
76#define MAX_RAW_DATA_SIZE(w, h) ((w) * (h) * 3 / 2 + 1024)
77
78#define FATAL_ERROR(rc) ((rc) < 0 && (rc) != -EPERM)
79
80/**********************************************************************
81 * Module Parameters
82 * (See ov511.txt for detailed descriptions of these)
83 **********************************************************************/
84
85/* These variables (and all static globals) default to zero */
86static int autobright = 1;
87static int autogain = 1;
88static int autoexp = 1;
89static int debug;
90static int snapshot;
91static int cams = 1;
92static int compress;
93static int testpat;
94static int dumppix;
95static int led = 1;
96static int dump_bridge;
97static int dump_sensor;
98static int printph;
99static int phy = 0x1f;
100static int phuv = 0x05;
101static int pvy = 0x06;
102static int pvuv = 0x06;
103static int qhy = 0x14;
104static int qhuv = 0x03;
105static int qvy = 0x04;
106static int qvuv = 0x04;
107static int lightfreq;
108static int bandingfilter;
109static int clockdiv = -1;
110static int packetsize = -1;
111static int framedrop = -1;
112static int fastset;
113static int force_palette;
114static int backlight;
115/* Bitmask marking allocated devices from 0 to OV511_MAX_UNIT_VIDEO */
116static unsigned long ov511_devused;
117static int unit_video[OV511_MAX_UNIT_VIDEO];
118static int remove_zeros;
119static int mirror;
120static int ov518_color;
121
122module_param(autobright, int, 0);
123MODULE_PARM_DESC(autobright, "Sensor automatically changes brightness");
124module_param(autogain, int, 0);
125MODULE_PARM_DESC(autogain, "Sensor automatically changes gain");
126module_param(autoexp, int, 0);
127MODULE_PARM_DESC(autoexp, "Sensor automatically changes exposure");
128module_param(debug, int, 0);
129MODULE_PARM_DESC(debug,
130 "Debug level: 0=none, 1=inits, 2=warning, 3=config, 4=functions, 5=max");
131module_param(snapshot, int, 0);
132MODULE_PARM_DESC(snapshot, "Enable snapshot mode");
133module_param(cams, int, 0);
134MODULE_PARM_DESC(cams, "Number of simultaneous cameras");
135module_param(compress, int, 0);
136MODULE_PARM_DESC(compress, "Turn on compression");
137module_param(testpat, int, 0);
138MODULE_PARM_DESC(testpat,
139 "Replace image with vertical bar testpattern (only partially working)");
140module_param(dumppix, int, 0);
141MODULE_PARM_DESC(dumppix, "Dump raw pixel data");
142module_param(led, int, 0);
143MODULE_PARM_DESC(led,
144 "LED policy (OV511+ or later). 0=off, 1=on (default), 2=auto (on when open)");
145module_param(dump_bridge, int, 0);
146MODULE_PARM_DESC(dump_bridge, "Dump the bridge registers");
147module_param(dump_sensor, int, 0);
148MODULE_PARM_DESC(dump_sensor, "Dump the sensor registers");
149module_param(printph, int, 0);
150MODULE_PARM_DESC(printph, "Print frame start/end headers");
151module_param(phy, int, 0);
152MODULE_PARM_DESC(phy, "Prediction range (horiz. Y)");
153module_param(phuv, int, 0);
154MODULE_PARM_DESC(phuv, "Prediction range (horiz. UV)");
155module_param(pvy, int, 0);
156MODULE_PARM_DESC(pvy, "Prediction range (vert. Y)");
157module_param(pvuv, int, 0);
158MODULE_PARM_DESC(pvuv, "Prediction range (vert. UV)");
159module_param(qhy, int, 0);
160MODULE_PARM_DESC(qhy, "Quantization threshold (horiz. Y)");
161module_param(qhuv, int, 0);
162MODULE_PARM_DESC(qhuv, "Quantization threshold (horiz. UV)");
163module_param(qvy, int, 0);
164MODULE_PARM_DESC(qvy, "Quantization threshold (vert. Y)");
165module_param(qvuv, int, 0);
166MODULE_PARM_DESC(qvuv, "Quantization threshold (vert. UV)");
167module_param(lightfreq, int, 0);
168MODULE_PARM_DESC(lightfreq,
169 "Light frequency. Set to 50 or 60 Hz, or zero for default settings");
170module_param(bandingfilter, int, 0);
171MODULE_PARM_DESC(bandingfilter,
172 "Enable banding filter (to reduce effects of fluorescent lighting)");
173module_param(clockdiv, int, 0);
174MODULE_PARM_DESC(clockdiv, "Force pixel clock divisor to a specific value");
175module_param(packetsize, int, 0);
176MODULE_PARM_DESC(packetsize, "Force a specific isoc packet size");
177module_param(framedrop, int, 0);
178MODULE_PARM_DESC(framedrop, "Force a specific frame drop register setting");
179module_param(fastset, int, 0);
180MODULE_PARM_DESC(fastset, "Allows picture settings to take effect immediately");
181module_param(force_palette, int, 0);
182MODULE_PARM_DESC(force_palette, "Force the palette to a specific value");
183module_param(backlight, int, 0);
184MODULE_PARM_DESC(backlight, "For objects that are lit from behind");
185static unsigned int num_uv;
186module_param_array(unit_video, int, &num_uv, 0);
187MODULE_PARM_DESC(unit_video,
188 "Force use of specific minor number(s). 0 is not allowed.");
189module_param(remove_zeros, int, 0);
190MODULE_PARM_DESC(remove_zeros,
191 "Remove zero-padding from uncompressed incoming data");
192module_param(mirror, int, 0);
193MODULE_PARM_DESC(mirror, "Reverse image horizontally");
194module_param(ov518_color, int, 0);
195MODULE_PARM_DESC(ov518_color, "Enable OV518 color (experimental)");
196
197MODULE_AUTHOR(DRIVER_AUTHOR);
198MODULE_DESCRIPTION(DRIVER_DESC);
199MODULE_LICENSE("GPL");
200
201/**********************************************************************
202 * Miscellaneous Globals
203 **********************************************************************/
204
205static struct usb_driver ov511_driver;
206
207/* Number of times to retry a failed I2C transaction. Increase this if you
208 * are getting "Failed to read sensor ID..." */
209static const int i2c_detect_tries = 5;
210
211static struct usb_device_id device_table [] = {
212 { USB_DEVICE(VEND_OMNIVISION, PROD_OV511) },
213 { USB_DEVICE(VEND_OMNIVISION, PROD_OV511PLUS) },
214 { USB_DEVICE(VEND_MATTEL, PROD_ME2CAM) },
215 { } /* Terminating entry */
216};
217
218MODULE_DEVICE_TABLE (usb, device_table);
219
220static unsigned char yQuanTable511[] = OV511_YQUANTABLE;
221static unsigned char uvQuanTable511[] = OV511_UVQUANTABLE;
222static unsigned char yQuanTable518[] = OV518_YQUANTABLE;
223static unsigned char uvQuanTable518[] = OV518_UVQUANTABLE;
224
225/**********************************************************************
226 * Symbolic Names
227 **********************************************************************/
228
229/* Known OV511-based cameras */
230static struct symbolic_list camlist[] = {
231 { 0, "Generic Camera (no ID)" },
232 { 1, "Mustek WCam 3X" },
233 { 3, "D-Link DSB-C300" },
234 { 4, "Generic OV511/OV7610" },
235 { 5, "Puretek PT-6007" },
236 { 6, "Lifeview USB Life TV (NTSC)" },
237 { 21, "Creative Labs WebCam 3" },
238 { 22, "Lifeview USB Life TV (PAL D/K+B/G)" },
239 { 36, "Koala-Cam" },
240 { 38, "Lifeview USB Life TV (PAL)" },
241 { 41, "Samsung Anycam MPC-M10" },
242 { 43, "Mtekvision Zeca MV402" },
243 { 46, "Suma eON" },
244 { 70, "Lifeview USB Life TV (PAL/SECAM)" },
245 { 100, "Lifeview RoboCam" },
246 { 102, "AverMedia InterCam Elite" },
247 { 112, "MediaForte MV300" }, /* or OV7110 evaluation kit */
248 { 134, "Ezonics EZCam II" },
249 { 192, "Webeye 2000B" },
250 { 253, "Alpha Vision Tech. AlphaCam SE" },
251 { -1, NULL }
252};
253
254/* Video4Linux1 Palettes */
255static struct symbolic_list v4l1_plist[] = {
256 { VIDEO_PALETTE_GREY, "GREY" },
257 { VIDEO_PALETTE_HI240, "HI240" },
258 { VIDEO_PALETTE_RGB565, "RGB565" },
259 { VIDEO_PALETTE_RGB24, "RGB24" },
260 { VIDEO_PALETTE_RGB32, "RGB32" },
261 { VIDEO_PALETTE_RGB555, "RGB555" },
262 { VIDEO_PALETTE_YUV422, "YUV422" },
263 { VIDEO_PALETTE_YUYV, "YUYV" },
264 { VIDEO_PALETTE_UYVY, "UYVY" },
265 { VIDEO_PALETTE_YUV420, "YUV420" },
266 { VIDEO_PALETTE_YUV411, "YUV411" },
267 { VIDEO_PALETTE_RAW, "RAW" },
268 { VIDEO_PALETTE_YUV422P,"YUV422P" },
269 { VIDEO_PALETTE_YUV411P,"YUV411P" },
270 { VIDEO_PALETTE_YUV420P,"YUV420P" },
271 { VIDEO_PALETTE_YUV410P,"YUV410P" },
272 { -1, NULL }
273};
274
275static struct symbolic_list brglist[] = {
276 { BRG_OV511, "OV511" },
277 { BRG_OV511PLUS, "OV511+" },
278 { BRG_OV518, "OV518" },
279 { BRG_OV518PLUS, "OV518+" },
280 { -1, NULL }
281};
282
283static struct symbolic_list senlist[] = {
284 { SEN_OV76BE, "OV76BE" },
285 { SEN_OV7610, "OV7610" },
286 { SEN_OV7620, "OV7620" },
287 { SEN_OV7620AE, "OV7620AE" },
288 { SEN_OV6620, "OV6620" },
289 { SEN_OV6630, "OV6630" },
290 { SEN_OV6630AE, "OV6630AE" },
291 { SEN_OV6630AF, "OV6630AF" },
292 { SEN_OV8600, "OV8600" },
293 { SEN_KS0127, "KS0127" },
294 { SEN_KS0127B, "KS0127B" },
295 { SEN_SAA7111A, "SAA7111A" },
296 { -1, NULL }
297};
298
299/* URB error codes: */
300static struct symbolic_list urb_errlist[] = {
301 { -ENOSR, "Buffer error (overrun)" },
302 { -EPIPE, "Stalled (device not responding)" },
303 { -EOVERFLOW, "Babble (device sends too much data)" },
304 { -EPROTO, "Bit-stuff error (bad cable?)" },
305 { -EILSEQ, "CRC/Timeout (bad cable?)" },
306 { -ETIME, "Device does not respond to token" },
307 { -ETIMEDOUT, "Device does not respond to command" },
308 { -1, NULL }
309};
310
311/**********************************************************************
312 * Memory management
313 **********************************************************************/
314static void *
315rvmalloc(unsigned long size)
316{
317 void *mem;
318 unsigned long adr;
319
320 size = PAGE_ALIGN(size);
321 mem = vmalloc_32(size);
322 if (!mem)
323 return NULL;
324
325 memset(mem, 0, size); /* Clear the ram out, no junk to the user */
326 adr = (unsigned long) mem;
327 while (size > 0) {
328 SetPageReserved(vmalloc_to_page((void *)adr));
329 adr += PAGE_SIZE;
330 size -= PAGE_SIZE;
331 }
332
333 return mem;
334}
335
336static void
337rvfree(void *mem, unsigned long size)
338{
339 unsigned long adr;
340
341 if (!mem)
342 return;
343
344 adr = (unsigned long) mem;
345 while ((long) size > 0) {
346 ClearPageReserved(vmalloc_to_page((void *)adr));
347 adr += PAGE_SIZE;
348 size -= PAGE_SIZE;
349 }
350 vfree(mem);
351}
352
353/**********************************************************************
354 *
355 * Register I/O
356 *
357 **********************************************************************/
358
359/* Write an OV51x register */
360static int
361reg_w(struct usb_ov511 *ov, unsigned char reg, unsigned char value)
362{
363 int rc;
364
365 PDEBUG(5, "0x%02X:0x%02X", reg, value);
366
367 mutex_lock(&ov->cbuf_lock);
368 ov->cbuf[0] = value;
369 rc = usb_control_msg(ov->dev,
370 usb_sndctrlpipe(ov->dev, 0),
371 (ov->bclass == BCL_OV518)?1:2 /* REG_IO */,
372 USB_TYPE_VENDOR | USB_RECIP_DEVICE,
373 0, (__u16)reg, &ov->cbuf[0], 1, 1000);
374 mutex_unlock(&ov->cbuf_lock);
375
376 if (rc < 0)
377 err("reg write: error %d: %s", rc, symbolic(urb_errlist, rc));
378
379 return rc;
380}
381
382/* Read from an OV51x register */
383/* returns: negative is error, pos or zero is data */
384static int
385reg_r(struct usb_ov511 *ov, unsigned char reg)
386{
387 int rc;
388
389 mutex_lock(&ov->cbuf_lock);
390 rc = usb_control_msg(ov->dev,
391 usb_rcvctrlpipe(ov->dev, 0),
392 (ov->bclass == BCL_OV518)?1:3 /* REG_IO */,
393 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
394 0, (__u16)reg, &ov->cbuf[0], 1, 1000);
395
396 if (rc < 0) {
397 err("reg read: error %d: %s", rc, symbolic(urb_errlist, rc));
398 } else {
399 rc = ov->cbuf[0];
400 PDEBUG(5, "0x%02X:0x%02X", reg, ov->cbuf[0]);
401 }
402
403 mutex_unlock(&ov->cbuf_lock);
404
405 return rc;
406}
407
408/*
409 * Writes bits at positions specified by mask to an OV51x reg. Bits that are in
410 * the same position as 1's in "mask" are cleared and set to "value". Bits
411 * that are in the same position as 0's in "mask" are preserved, regardless
412 * of their respective state in "value".
413 */
414static int
415reg_w_mask(struct usb_ov511 *ov,
416 unsigned char reg,
417 unsigned char value,
418 unsigned char mask)
419{
420 int ret;
421 unsigned char oldval, newval;
422
423 ret = reg_r(ov, reg);
424 if (ret < 0)
425 return ret;
426
427 oldval = (unsigned char) ret;
428 oldval &= (~mask); /* Clear the masked bits */
429 value &= mask; /* Enforce mask on value */
430 newval = oldval | value; /* Set the desired bits */
431
432 return (reg_w(ov, reg, newval));
433}
434
435/*
436 * Writes multiple (n) byte value to a single register. Only valid with certain
437 * registers (0x30 and 0xc4 - 0xce).
438 */
439static int
440ov518_reg_w32(struct usb_ov511 *ov, unsigned char reg, u32 val, int n)
441{
442 int rc;
443
444 PDEBUG(5, "0x%02X:%7d, n=%d", reg, val, n);
445
446 mutex_lock(&ov->cbuf_lock);
447
448 *((__le32 *)ov->cbuf) = __cpu_to_le32(val);
449
450 rc = usb_control_msg(ov->dev,
451 usb_sndctrlpipe(ov->dev, 0),
452 1 /* REG_IO */,
453 USB_TYPE_VENDOR | USB_RECIP_DEVICE,
454 0, (__u16)reg, ov->cbuf, n, 1000);
455 mutex_unlock(&ov->cbuf_lock);
456
457 if (rc < 0)
458 err("reg write multiple: error %d: %s", rc,
459 symbolic(urb_errlist, rc));
460
461 return rc;
462}
463
464static int
465ov511_upload_quan_tables(struct usb_ov511 *ov)
466{
467 unsigned char *pYTable = yQuanTable511;
468 unsigned char *pUVTable = uvQuanTable511;
469 unsigned char val0, val1;
470 int i, rc, reg = R511_COMP_LUT_BEGIN;
471
472 PDEBUG(4, "Uploading quantization tables");
473
474 for (i = 0; i < OV511_QUANTABLESIZE / 2; i++) {
475 if (ENABLE_Y_QUANTABLE) {
476 val0 = *pYTable++;
477 val1 = *pYTable++;
478 val0 &= 0x0f;
479 val1 &= 0x0f;
480 val0 |= val1 << 4;
481 rc = reg_w(ov, reg, val0);
482 if (rc < 0)
483 return rc;
484 }
485
486 if (ENABLE_UV_QUANTABLE) {
487 val0 = *pUVTable++;
488 val1 = *pUVTable++;
489 val0 &= 0x0f;
490 val1 &= 0x0f;
491 val0 |= val1 << 4;
492 rc = reg_w(ov, reg + OV511_QUANTABLESIZE/2, val0);
493 if (rc < 0)
494 return rc;
495 }
496
497 reg++;
498 }
499
500 return 0;
501}
502
503/* OV518 quantization tables are 8x4 (instead of 8x8) */
504static int
505ov518_upload_quan_tables(struct usb_ov511 *ov)
506{
507 unsigned char *pYTable = yQuanTable518;
508 unsigned char *pUVTable = uvQuanTable518;
509 unsigned char val0, val1;
510 int i, rc, reg = R511_COMP_LUT_BEGIN;
511
512 PDEBUG(4, "Uploading quantization tables");
513
514 for (i = 0; i < OV518_QUANTABLESIZE / 2; i++) {
515 if (ENABLE_Y_QUANTABLE) {
516 val0 = *pYTable++;
517 val1 = *pYTable++;
518 val0 &= 0x0f;
519 val1 &= 0x0f;
520 val0 |= val1 << 4;
521 rc = reg_w(ov, reg, val0);
522 if (rc < 0)
523 return rc;
524 }
525
526 if (ENABLE_UV_QUANTABLE) {
527 val0 = *pUVTable++;
528 val1 = *pUVTable++;
529 val0 &= 0x0f;
530 val1 &= 0x0f;
531 val0 |= val1 << 4;
532 rc = reg_w(ov, reg + OV518_QUANTABLESIZE/2, val0);
533 if (rc < 0)
534 return rc;
535 }
536
537 reg++;
538 }
539
540 return 0;
541}
542
543static int
544ov51x_reset(struct usb_ov511 *ov, unsigned char reset_type)
545{
546 int rc;
547
548 /* Setting bit 0 not allowed on 518/518Plus */
549 if (ov->bclass == BCL_OV518)
550 reset_type &= 0xfe;
551
552 PDEBUG(4, "Reset: type=0x%02X", reset_type);
553
554 rc = reg_w(ov, R51x_SYS_RESET, reset_type);
555 rc = reg_w(ov, R51x_SYS_RESET, 0);
556
557 if (rc < 0)
558 err("reset: command failed");
559
560 return rc;
561}
562
563/**********************************************************************
564 *
565 * Low-level I2C I/O functions
566 *
567 **********************************************************************/
568
569/* NOTE: Do not call this function directly!
570 * The OV518 I2C I/O procedure is different, hence, this function.
571 * This is normally only called from i2c_w(). Note that this function
572 * always succeeds regardless of whether the sensor is present and working.
573 */
574static int
575ov518_i2c_write_internal(struct usb_ov511 *ov,
576 unsigned char reg,
577 unsigned char value)
578{
579 int rc;
580
581 PDEBUG(5, "0x%02X:0x%02X", reg, value);
582
583 /* Select camera register */
584 rc = reg_w(ov, R51x_I2C_SADDR_3, reg);
585 if (rc < 0)
586 return rc;
587
588 /* Write "value" to I2C data port of OV511 */
589 rc = reg_w(ov, R51x_I2C_DATA, value);
590 if (rc < 0)
591 return rc;
592
593 /* Initiate 3-byte write cycle */
594 rc = reg_w(ov, R518_I2C_CTL, 0x01);
595 if (rc < 0)
596 return rc;
597
598 return 0;
599}
600
601/* NOTE: Do not call this function directly! */
602static int
603ov511_i2c_write_internal(struct usb_ov511 *ov,
604 unsigned char reg,
605 unsigned char value)
606{
607 int rc, retries;
608
609 PDEBUG(5, "0x%02X:0x%02X", reg, value);
610
611 /* Three byte write cycle */
612 for (retries = OV511_I2C_RETRIES; ; ) {
613 /* Select camera register */
614 rc = reg_w(ov, R51x_I2C_SADDR_3, reg);
615 if (rc < 0)
616 break;
617
618 /* Write "value" to I2C data port of OV511 */
619 rc = reg_w(ov, R51x_I2C_DATA, value);
620 if (rc < 0)
621 break;
622
623 /* Initiate 3-byte write cycle */
624 rc = reg_w(ov, R511_I2C_CTL, 0x01);
625 if (rc < 0)
626 break;
627
628 /* Retry until idle */
629 do {
630 rc = reg_r(ov, R511_I2C_CTL);
631 } while (rc > 0 && ((rc&1) == 0));
632 if (rc < 0)
633 break;
634
635 /* Ack? */
636 if ((rc&2) == 0) {
637 rc = 0;
638 break;
639 }
640#if 0
641 /* I2C abort */
642 reg_w(ov, R511_I2C_CTL, 0x10);
643#endif
644 if (--retries < 0) {
645 err("i2c write retries exhausted");
646 rc = -1;
647 break;
648 }
649 }
650
651 return rc;
652}
653
654/* NOTE: Do not call this function directly!
655 * The OV518 I2C I/O procedure is different, hence, this function.
656 * This is normally only called from i2c_r(). Note that this function
657 * always succeeds regardless of whether the sensor is present and working.
658 */
659static int
660ov518_i2c_read_internal(struct usb_ov511 *ov, unsigned char reg)
661{
662 int rc, value;
663
664 /* Select camera register */
665 rc = reg_w(ov, R51x_I2C_SADDR_2, reg);
666 if (rc < 0)
667 return rc;
668
669 /* Initiate 2-byte write cycle */
670 rc = reg_w(ov, R518_I2C_CTL, 0x03);
671 if (rc < 0)
672 return rc;
673
674 /* Initiate 2-byte read cycle */
675 rc = reg_w(ov, R518_I2C_CTL, 0x05);
676 if (rc < 0)
677 return rc;
678
679 value = reg_r(ov, R51x_I2C_DATA);
680
681 PDEBUG(5, "0x%02X:0x%02X", reg, value);
682
683 return value;
684}
685
686/* NOTE: Do not call this function directly!
687 * returns: negative is error, pos or zero is data */
688static int
689ov511_i2c_read_internal(struct usb_ov511 *ov, unsigned char reg)
690{
691 int rc, value, retries;
692
693 /* Two byte write cycle */
694 for (retries = OV511_I2C_RETRIES; ; ) {
695 /* Select camera register */
696 rc = reg_w(ov, R51x_I2C_SADDR_2, reg);
697 if (rc < 0)
698 return rc;
699
700 /* Initiate 2-byte write cycle */
701 rc = reg_w(ov, R511_I2C_CTL, 0x03);
702 if (rc < 0)
703 return rc;
704
705 /* Retry until idle */
706 do {
707 rc = reg_r(ov, R511_I2C_CTL);
708 } while (rc > 0 && ((rc & 1) == 0));
709 if (rc < 0)
710 return rc;
711
712 if ((rc&2) == 0) /* Ack? */
713 break;
714
715 /* I2C abort */
716 reg_w(ov, R511_I2C_CTL, 0x10);
717
718 if (--retries < 0) {
719 err("i2c write retries exhausted");
720 return -1;
721 }
722 }
723
724 /* Two byte read cycle */
725 for (retries = OV511_I2C_RETRIES; ; ) {
726 /* Initiate 2-byte read cycle */
727 rc = reg_w(ov, R511_I2C_CTL, 0x05);
728 if (rc < 0)
729 return rc;
730
731 /* Retry until idle */
732 do {
733 rc = reg_r(ov, R511_I2C_CTL);
734 } while (rc > 0 && ((rc&1) == 0));
735 if (rc < 0)
736 return rc;
737
738 if ((rc&2) == 0) /* Ack? */
739 break;
740
741 /* I2C abort */
742 rc = reg_w(ov, R511_I2C_CTL, 0x10);
743 if (rc < 0)
744 return rc;
745
746 if (--retries < 0) {
747 err("i2c read retries exhausted");
748 return -1;
749 }
750 }
751
752 value = reg_r(ov, R51x_I2C_DATA);
753
754 PDEBUG(5, "0x%02X:0x%02X", reg, value);
755
756 /* This is needed to make i2c_w() work */
757 rc = reg_w(ov, R511_I2C_CTL, 0x05);
758 if (rc < 0)
759 return rc;
760
761 return value;
762}
763
764/* returns: negative is error, pos or zero is data */
765static int
766i2c_r(struct usb_ov511 *ov, unsigned char reg)
767{
768 int rc;
769
770 mutex_lock(&ov->i2c_lock);
771
772 if (ov->bclass == BCL_OV518)
773 rc = ov518_i2c_read_internal(ov, reg);
774 else
775 rc = ov511_i2c_read_internal(ov, reg);
776
777 mutex_unlock(&ov->i2c_lock);
778
779 return rc;
780}
781
782static int
783i2c_w(struct usb_ov511 *ov, unsigned char reg, unsigned char value)
784{
785 int rc;
786
787 mutex_lock(&ov->i2c_lock);
788
789 if (ov->bclass == BCL_OV518)
790 rc = ov518_i2c_write_internal(ov, reg, value);
791 else
792 rc = ov511_i2c_write_internal(ov, reg, value);
793
794 mutex_unlock(&ov->i2c_lock);
795
796 return rc;
797}
798
799/* Do not call this function directly! */
800static int
801ov51x_i2c_write_mask_internal(struct usb_ov511 *ov,
802 unsigned char reg,
803 unsigned char value,
804 unsigned char mask)
805{
806 int rc;
807 unsigned char oldval, newval;
808
809 if (mask == 0xff) {
810 newval = value;
811 } else {
812 if (ov->bclass == BCL_OV518)
813 rc = ov518_i2c_read_internal(ov, reg);
814 else
815 rc = ov511_i2c_read_internal(ov, reg);
816 if (rc < 0)
817 return rc;
818
819 oldval = (unsigned char) rc;
820 oldval &= (~mask); /* Clear the masked bits */
821 value &= mask; /* Enforce mask on value */
822 newval = oldval | value; /* Set the desired bits */
823 }
824
825 if (ov->bclass == BCL_OV518)
826 return (ov518_i2c_write_internal(ov, reg, newval));
827 else
828 return (ov511_i2c_write_internal(ov, reg, newval));
829}
830
831/* Writes bits at positions specified by mask to an I2C reg. Bits that are in
832 * the same position as 1's in "mask" are cleared and set to "value". Bits
833 * that are in the same position as 0's in "mask" are preserved, regardless
834 * of their respective state in "value".
835 */
836static int
837i2c_w_mask(struct usb_ov511 *ov,
838 unsigned char reg,
839 unsigned char value,
840 unsigned char mask)
841{
842 int rc;
843
844 mutex_lock(&ov->i2c_lock);
845 rc = ov51x_i2c_write_mask_internal(ov, reg, value, mask);
846 mutex_unlock(&ov->i2c_lock);
847
848 return rc;
849}
850
851/* Set the read and write slave IDs. The "slave" argument is the write slave,
852 * and the read slave will be set to (slave + 1). ov->i2c_lock should be held
853 * when calling this. This should not be called from outside the i2c I/O
854 * functions.
855 */
856static int
857i2c_set_slave_internal(struct usb_ov511 *ov, unsigned char slave)
858{
859 int rc;
860
861 rc = reg_w(ov, R51x_I2C_W_SID, slave);
862 if (rc < 0)
863 return rc;
864
865 rc = reg_w(ov, R51x_I2C_R_SID, slave + 1);
866 if (rc < 0)
867 return rc;
868
869 return 0;
870}
871
872/* Write to a specific I2C slave ID and register, using the specified mask */
873static int
874i2c_w_slave(struct usb_ov511 *ov,
875 unsigned char slave,
876 unsigned char reg,
877 unsigned char value,
878 unsigned char mask)
879{
880 int rc = 0;
881
882 mutex_lock(&ov->i2c_lock);
883
884 /* Set new slave IDs */
885 rc = i2c_set_slave_internal(ov, slave);
886 if (rc < 0)
887 goto out;
888
889 rc = ov51x_i2c_write_mask_internal(ov, reg, value, mask);
890
891out:
892 /* Restore primary IDs */
893 if (i2c_set_slave_internal(ov, ov->primary_i2c_slave) < 0)
894 err("Couldn't restore primary I2C slave");
895
896 mutex_unlock(&ov->i2c_lock);
897 return rc;
898}
899
900/* Read from a specific I2C slave ID and register */
901static int
902i2c_r_slave(struct usb_ov511 *ov,
903 unsigned char slave,
904 unsigned char reg)
905{
906 int rc;
907
908 mutex_lock(&ov->i2c_lock);
909
910 /* Set new slave IDs */
911 rc = i2c_set_slave_internal(ov, slave);
912 if (rc < 0)
913 goto out;
914
915 if (ov->bclass == BCL_OV518)
916 rc = ov518_i2c_read_internal(ov, reg);
917 else
918 rc = ov511_i2c_read_internal(ov, reg);
919
920out:
921 /* Restore primary IDs */
922 if (i2c_set_slave_internal(ov, ov->primary_i2c_slave) < 0)
923 err("Couldn't restore primary I2C slave");
924
925 mutex_unlock(&ov->i2c_lock);
926 return rc;
927}
928
929/* Sets I2C read and write slave IDs. Returns <0 for error */
930static int
931ov51x_set_slave_ids(struct usb_ov511 *ov, unsigned char sid)
932{
933 int rc;
934
935 mutex_lock(&ov->i2c_lock);
936
937 rc = i2c_set_slave_internal(ov, sid);
938 if (rc < 0)
939 goto out;
940
941 // FIXME: Is this actually necessary?
942 rc = ov51x_reset(ov, OV511_RESET_NOREGS);
943out:
944 mutex_unlock(&ov->i2c_lock);
945 return rc;
946}
947
948static int
949write_regvals(struct usb_ov511 *ov, struct ov511_regvals * pRegvals)
950{
951 int rc;
952
953 while (pRegvals->bus != OV511_DONE_BUS) {
954 if (pRegvals->bus == OV511_REG_BUS) {
955 if ((rc = reg_w(ov, pRegvals->reg, pRegvals->val)) < 0)
956 return rc;
957 } else if (pRegvals->bus == OV511_I2C_BUS) {
958 if ((rc = i2c_w(ov, pRegvals->reg, pRegvals->val)) < 0)
959 return rc;
960 } else {
961 err("Bad regval array");
962 return -1;
963 }
964 pRegvals++;
965 }
966 return 0;
967}
968
969#ifdef OV511_DEBUG
970static void
971dump_i2c_range(struct usb_ov511 *ov, int reg1, int regn)
972{
973 int i, rc;
974
975 for (i = reg1; i <= regn; i++) {
976 rc = i2c_r(ov, i);
977 dev_info(&ov->dev->dev, "Sensor[0x%02X] = 0x%02X\n", i, rc);
978 }
979}
980
981static void
982dump_i2c_regs(struct usb_ov511 *ov)
983{
984 dev_info(&ov->dev->dev, "I2C REGS\n");
985 dump_i2c_range(ov, 0x00, 0x7C);
986}
987
988static void
989dump_reg_range(struct usb_ov511 *ov, int reg1, int regn)
990{
991 int i, rc;
992
993 for (i = reg1; i <= regn; i++) {
994 rc = reg_r(ov, i);
995 dev_info(&ov->dev->dev, "OV511[0x%02X] = 0x%02X\n", i, rc);
996 }
997}
998
999static void
1000ov511_dump_regs(struct usb_ov511 *ov)
1001{
1002 dev_info(&ov->dev->dev, "CAMERA INTERFACE REGS\n");
1003 dump_reg_range(ov, 0x10, 0x1f);
1004 dev_info(&ov->dev->dev, "DRAM INTERFACE REGS\n");
1005 dump_reg_range(ov, 0x20, 0x23);
1006 dev_info(&ov->dev->dev, "ISO FIFO REGS\n");
1007 dump_reg_range(ov, 0x30, 0x31);
1008 dev_info(&ov->dev->dev, "PIO REGS\n");
1009 dump_reg_range(ov, 0x38, 0x39);
1010 dump_reg_range(ov, 0x3e, 0x3e);
1011 dev_info(&ov->dev->dev, "I2C REGS\n");
1012 dump_reg_range(ov, 0x40, 0x49);
1013 dev_info(&ov->dev->dev, "SYSTEM CONTROL REGS\n");
1014 dump_reg_range(ov, 0x50, 0x55);
1015 dump_reg_range(ov, 0x5e, 0x5f);
1016 dev_info(&ov->dev->dev, "OmniCE REGS\n");
1017 dump_reg_range(ov, 0x70, 0x79);
1018 /* NOTE: Quantization tables are not readable. You will get the value
1019 * in reg. 0x79 for every table register */
1020 dump_reg_range(ov, 0x80, 0x9f);
1021 dump_reg_range(ov, 0xa0, 0xbf);
1022
1023}
1024
1025static void
1026ov518_dump_regs(struct usb_ov511 *ov)
1027{
1028 dev_info(&ov->dev->dev, "VIDEO MODE REGS\n");
1029 dump_reg_range(ov, 0x20, 0x2f);
1030 dev_info(&ov->dev->dev, "DATA PUMP AND SNAPSHOT REGS\n");
1031 dump_reg_range(ov, 0x30, 0x3f);
1032 dev_info(&ov->dev->dev, "I2C REGS\n");
1033 dump_reg_range(ov, 0x40, 0x4f);
1034 dev_info(&ov->dev->dev, "SYSTEM CONTROL AND VENDOR REGS\n");
1035 dump_reg_range(ov, 0x50, 0x5f);
1036 dev_info(&ov->dev->dev, "60 - 6F\n");
1037 dump_reg_range(ov, 0x60, 0x6f);
1038 dev_info(&ov->dev->dev, "70 - 7F\n");
1039 dump_reg_range(ov, 0x70, 0x7f);
1040 dev_info(&ov->dev->dev, "Y QUANTIZATION TABLE\n");
1041 dump_reg_range(ov, 0x80, 0x8f);
1042 dev_info(&ov->dev->dev, "UV QUANTIZATION TABLE\n");
1043 dump_reg_range(ov, 0x90, 0x9f);
1044 dev_info(&ov->dev->dev, "A0 - BF\n");
1045 dump_reg_range(ov, 0xa0, 0xbf);
1046 dev_info(&ov->dev->dev, "CBR\n");
1047 dump_reg_range(ov, 0xc0, 0xcf);
1048}
1049#endif
1050
1051/*****************************************************************************/
1052
1053/* Temporarily stops OV511 from functioning. Must do this before changing
1054 * registers while the camera is streaming */
1055static inline int
1056ov51x_stop(struct usb_ov511 *ov)
1057{
1058 PDEBUG(4, "stopping");
1059 ov->stopped = 1;
1060 if (ov->bclass == BCL_OV518)
1061 return (reg_w_mask(ov, R51x_SYS_RESET, 0x3a, 0x3a));
1062 else
1063 return (reg_w(ov, R51x_SYS_RESET, 0x3d));
1064}
1065
1066/* Restarts OV511 after ov511_stop() is called. Has no effect if it is not
1067 * actually stopped (for performance). */
1068static inline int
1069ov51x_restart(struct usb_ov511 *ov)
1070{
1071 if (ov->stopped) {
1072 PDEBUG(4, "restarting");
1073 ov->stopped = 0;
1074
1075 /* Reinitialize the stream */
1076 if (ov->bclass == BCL_OV518)
1077 reg_w(ov, 0x2f, 0x80);
1078
1079 return (reg_w(ov, R51x_SYS_RESET, 0x00));
1080 }
1081
1082 return 0;
1083}
1084
1085/* Sleeps until no frames are active. Returns !0 if got signal */
1086static int
1087ov51x_wait_frames_inactive(struct usb_ov511 *ov)
1088{
1089 return wait_event_interruptible(ov->wq, ov->curframe < 0);
1090}
1091
1092/* Resets the hardware snapshot button */
1093static void
1094ov51x_clear_snapshot(struct usb_ov511 *ov)
1095{
1096 if (ov->bclass == BCL_OV511) {
1097 reg_w(ov, R51x_SYS_SNAP, 0x00);
1098 reg_w(ov, R51x_SYS_SNAP, 0x02);
1099 reg_w(ov, R51x_SYS_SNAP, 0x00);
1100 } else if (ov->bclass == BCL_OV518) {
1101 dev_warn(&ov->dev->dev,
1102 "snapshot reset not supported yet on OV518(+)\n");
1103 } else {
1104 dev_err(&ov->dev->dev, "clear snap: invalid bridge type\n");
1105 }
1106}
1107
1108#if 0
1109/* Checks the status of the snapshot button. Returns 1 if it was pressed since
1110 * it was last cleared, and zero in all other cases (including errors) */
1111static int
1112ov51x_check_snapshot(struct usb_ov511 *ov)
1113{
1114 int ret, status = 0;
1115
1116 if (ov->bclass == BCL_OV511) {
1117 ret = reg_r(ov, R51x_SYS_SNAP);
1118 if (ret < 0) {
1119 dev_err(&ov->dev->dev,
1120 "Error checking snspshot status (%d)\n", ret);
1121 } else if (ret & 0x08) {
1122 status = 1;
1123 }
1124 } else if (ov->bclass == BCL_OV518) {
1125 dev_warn(&ov->dev->dev,
1126 "snapshot check not supported yet on OV518(+)\n");
1127 } else {
1128 dev_err(&ov->dev->dev, "clear snap: invalid bridge type\n");
1129 }
1130
1131 return status;
1132}
1133#endif
1134
1135/* This does an initial reset of an OmniVision sensor and ensures that I2C
1136 * is synchronized. Returns <0 for failure.
1137 */
1138static int
1139init_ov_sensor(struct usb_ov511 *ov)
1140{
1141 int i, success;
1142
1143 /* Reset the sensor */
1144 if (i2c_w(ov, 0x12, 0x80) < 0)
1145 return -EIO;
1146
1147 /* Wait for it to initialize */
1148 msleep(150);
1149
1150 for (i = 0, success = 0; i < i2c_detect_tries && !success; i++) {
1151 if ((i2c_r(ov, OV7610_REG_ID_HIGH) == 0x7F) &&
1152 (i2c_r(ov, OV7610_REG_ID_LOW) == 0xA2)) {
1153 success = 1;
1154 continue;
1155 }
1156
1157 /* Reset the sensor */
1158 if (i2c_w(ov, 0x12, 0x80) < 0)
1159 return -EIO;
1160 /* Wait for it to initialize */
1161 msleep(150);
1162 /* Dummy read to sync I2C */
1163 if (i2c_r(ov, 0x00) < 0)
1164 return -EIO;
1165 }
1166
1167 if (!success)
1168 return -EIO;
1169
1170 PDEBUG(1, "I2C synced in %d attempt(s)", i);
1171
1172 return 0;
1173}
1174
1175static int
1176ov511_set_packet_size(struct usb_ov511 *ov, int size)
1177{
1178 int alt, mult;
1179
1180 if (ov51x_stop(ov) < 0)
1181 return -EIO;
1182
1183 mult = size >> 5;
1184
1185 if (ov->bridge == BRG_OV511) {
1186 if (size == 0)
1187 alt = OV511_ALT_SIZE_0;
1188 else if (size == 257)
1189 alt = OV511_ALT_SIZE_257;
1190 else if (size == 513)
1191 alt = OV511_ALT_SIZE_513;
1192 else if (size == 769)
1193 alt = OV511_ALT_SIZE_769;
1194 else if (size == 993)
1195 alt = OV511_ALT_SIZE_993;
1196 else {
1197 err("Set packet size: invalid size (%d)", size);
1198 return -EINVAL;
1199 }
1200 } else if (ov->bridge == BRG_OV511PLUS) {
1201 if (size == 0)
1202 alt = OV511PLUS_ALT_SIZE_0;
1203 else if (size == 33)
1204 alt = OV511PLUS_ALT_SIZE_33;
1205 else if (size == 129)
1206 alt = OV511PLUS_ALT_SIZE_129;
1207 else if (size == 257)
1208 alt = OV511PLUS_ALT_SIZE_257;
1209 else if (size == 385)
1210 alt = OV511PLUS_ALT_SIZE_385;
1211 else if (size == 513)
1212 alt = OV511PLUS_ALT_SIZE_513;
1213 else if (size == 769)
1214 alt = OV511PLUS_ALT_SIZE_769;
1215 else if (size == 961)
1216 alt = OV511PLUS_ALT_SIZE_961;
1217 else {
1218 err("Set packet size: invalid size (%d)", size);
1219 return -EINVAL;
1220 }
1221 } else {
1222 err("Set packet size: Invalid bridge type");
1223 return -EINVAL;
1224 }
1225
1226 PDEBUG(3, "%d, mult=%d, alt=%d", size, mult, alt);
1227
1228 if (reg_w(ov, R51x_FIFO_PSIZE, mult) < 0)
1229 return -EIO;
1230
1231 if (usb_set_interface(ov->dev, ov->iface, alt) < 0) {
1232 err("Set packet size: set interface error");
1233 return -EBUSY;
1234 }
1235
1236 if (ov51x_reset(ov, OV511_RESET_NOREGS) < 0)
1237 return -EIO;
1238
1239 ov->packet_size = size;
1240
1241 if (ov51x_restart(ov) < 0)
1242 return -EIO;
1243
1244 return 0;
1245}
1246
1247/* Note: Unlike the OV511/OV511+, the size argument does NOT include the
1248 * optional packet number byte. The actual size *is* stored in ov->packet_size,
1249 * though. */
1250static int
1251ov518_set_packet_size(struct usb_ov511 *ov, int size)
1252{
1253 int alt;
1254
1255 if (ov51x_stop(ov) < 0)
1256 return -EIO;
1257
1258 if (ov->bclass == BCL_OV518) {
1259 if (size == 0)
1260 alt = OV518_ALT_SIZE_0;
1261 else if (size == 128)
1262 alt = OV518_ALT_SIZE_128;
1263 else if (size == 256)
1264 alt = OV518_ALT_SIZE_256;
1265 else if (size == 384)
1266 alt = OV518_ALT_SIZE_384;
1267 else if (size == 512)
1268 alt = OV518_ALT_SIZE_512;
1269 else if (size == 640)
1270 alt = OV518_ALT_SIZE_640;
1271 else if (size == 768)
1272 alt = OV518_ALT_SIZE_768;
1273 else if (size == 896)
1274 alt = OV518_ALT_SIZE_896;
1275 else {
1276 err("Set packet size: invalid size (%d)", size);
1277 return -EINVAL;
1278 }
1279 } else {
1280 err("Set packet size: Invalid bridge type");
1281 return -EINVAL;
1282 }
1283
1284 PDEBUG(3, "%d, alt=%d", size, alt);
1285
1286 ov->packet_size = size;
1287 if (size > 0) {
1288 /* Program ISO FIFO size reg (packet number isn't included) */
1289 ov518_reg_w32(ov, 0x30, size, 2);
1290
1291 if (ov->packet_numbering)
1292 ++ov->packet_size;
1293 }
1294
1295 if (usb_set_interface(ov->dev, ov->iface, alt) < 0) {
1296 err("Set packet size: set interface error");
1297 return -EBUSY;
1298 }
1299
1300 /* Initialize the stream */
1301 if (reg_w(ov, 0x2f, 0x80) < 0)
1302 return -EIO;
1303
1304 if (ov51x_restart(ov) < 0)
1305 return -EIO;
1306
1307 if (ov51x_reset(ov, OV511_RESET_NOREGS) < 0)
1308 return -EIO;
1309
1310 return 0;
1311}
1312
1313/* Upload compression params and quantization tables. Returns 0 for success. */
1314static int
1315ov511_init_compression(struct usb_ov511 *ov)
1316{
1317 int rc = 0;
1318
1319 if (!ov->compress_inited) {
1320 reg_w(ov, 0x70, phy);
1321 reg_w(ov, 0x71, phuv);
1322 reg_w(ov, 0x72, pvy);
1323 reg_w(ov, 0x73, pvuv);
1324 reg_w(ov, 0x74, qhy);
1325 reg_w(ov, 0x75, qhuv);
1326 reg_w(ov, 0x76, qvy);
1327 reg_w(ov, 0x77, qvuv);
1328
1329 if (ov511_upload_quan_tables(ov) < 0) {
1330 err("Error uploading quantization tables");
1331 rc = -EIO;
1332 goto out;
1333 }
1334 }
1335
1336 ov->compress_inited = 1;
1337out:
1338 return rc;
1339}
1340
1341/* Upload compression params and quantization tables. Returns 0 for success. */
1342static int
1343ov518_init_compression(struct usb_ov511 *ov)
1344{
1345 int rc = 0;
1346
1347 if (!ov->compress_inited) {
1348 if (ov518_upload_quan_tables(ov) < 0) {
1349 err("Error uploading quantization tables");
1350 rc = -EIO;
1351 goto out;
1352 }
1353 }
1354
1355 ov->compress_inited = 1;
1356out:
1357 return rc;
1358}
1359
1360/* -------------------------------------------------------------------------- */
1361
1362/* Sets sensor's contrast setting to "val" */
1363static int
1364sensor_set_contrast(struct usb_ov511 *ov, unsigned short val)
1365{
1366 int rc;
1367
1368 PDEBUG(3, "%d", val);
1369
1370 if (ov->stop_during_set)
1371 if (ov51x_stop(ov) < 0)
1372 return -EIO;
1373
1374 switch (ov->sensor) {
1375 case SEN_OV7610:
1376 case SEN_OV6620:
1377 {
1378 rc = i2c_w(ov, OV7610_REG_CNT, val >> 8);
1379 if (rc < 0)
1380 goto out;
1381 break;
1382 }
1383 case SEN_OV6630:
1384 {
1385 rc = i2c_w_mask(ov, OV7610_REG_CNT, val >> 12, 0x0f);
1386 if (rc < 0)
1387 goto out;
1388 break;
1389 }
1390 case SEN_OV7620:
1391 {
1392 unsigned char ctab[] = {
1393 0x01, 0x05, 0x09, 0x11, 0x15, 0x35, 0x37, 0x57,
1394 0x5b, 0xa5, 0xa7, 0xc7, 0xc9, 0xcf, 0xef, 0xff
1395 };
1396
1397 /* Use Y gamma control instead. Bit 0 enables it. */
1398 rc = i2c_w(ov, 0x64, ctab[val>>12]);
1399 if (rc < 0)
1400 goto out;
1401 break;
1402 }
1403 case SEN_SAA7111A:
1404 {
1405 rc = i2c_w(ov, 0x0b, val >> 9);
1406 if (rc < 0)
1407 goto out;
1408 break;
1409 }
1410 default:
1411 {
1412 PDEBUG(3, "Unsupported with this sensor");
1413 rc = -EPERM;
1414 goto out;
1415 }
1416 }
1417
1418 rc = 0; /* Success */
1419 ov->contrast = val;
1420out:
1421 if (ov51x_restart(ov) < 0)
1422 return -EIO;
1423
1424 return rc;
1425}
1426
1427/* Gets sensor's contrast setting */
1428static int
1429sensor_get_contrast(struct usb_ov511 *ov, unsigned short *val)
1430{
1431 int rc;
1432
1433 switch (ov->sensor) {
1434 case SEN_OV7610:
1435 case SEN_OV6620:
1436 rc = i2c_r(ov, OV7610_REG_CNT);
1437 if (rc < 0)
1438 return rc;
1439 else
1440 *val = rc << 8;
1441 break;
1442 case SEN_OV6630:
1443 rc = i2c_r(ov, OV7610_REG_CNT);
1444 if (rc < 0)
1445 return rc;
1446 else
1447 *val = rc << 12;
1448 break;
1449 case SEN_OV7620:
1450 /* Use Y gamma reg instead. Bit 0 is the enable bit. */
1451 rc = i2c_r(ov, 0x64);
1452 if (rc < 0)
1453 return rc;
1454 else
1455 *val = (rc & 0xfe) << 8;
1456 break;
1457 case SEN_SAA7111A:
1458 *val = ov->contrast;
1459 break;
1460 default:
1461 PDEBUG(3, "Unsupported with this sensor");
1462 return -EPERM;
1463 }
1464
1465 PDEBUG(3, "%d", *val);
1466 ov->contrast = *val;
1467
1468 return 0;
1469}
1470
1471/* -------------------------------------------------------------------------- */
1472
1473/* Sets sensor's brightness setting to "val" */
1474static int
1475sensor_set_brightness(struct usb_ov511 *ov, unsigned short val)
1476{
1477 int rc;
1478
1479 PDEBUG(4, "%d", val);
1480
1481 if (ov->stop_during_set)
1482 if (ov51x_stop(ov) < 0)
1483 return -EIO;
1484
1485 switch (ov->sensor) {
1486 case SEN_OV7610:
1487 case SEN_OV76BE:
1488 case SEN_OV6620:
1489 case SEN_OV6630:
1490 rc = i2c_w(ov, OV7610_REG_BRT, val >> 8);
1491 if (rc < 0)
1492 goto out;
1493 break;
1494 case SEN_OV7620:
1495 /* 7620 doesn't like manual changes when in auto mode */
1496 if (!ov->auto_brt) {
1497 rc = i2c_w(ov, OV7610_REG_BRT, val >> 8);
1498 if (rc < 0)
1499 goto out;
1500 }
1501 break;
1502 case SEN_SAA7111A:
1503 rc = i2c_w(ov, 0x0a, val >> 8);
1504 if (rc < 0)
1505 goto out;
1506 break;
1507 default:
1508 PDEBUG(3, "Unsupported with this sensor");
1509 rc = -EPERM;
1510 goto out;
1511 }
1512
1513 rc = 0; /* Success */
1514 ov->brightness = val;
1515out:
1516 if (ov51x_restart(ov) < 0)
1517 return -EIO;
1518
1519 return rc;
1520}
1521
1522/* Gets sensor's brightness setting */
1523static int
1524sensor_get_brightness(struct usb_ov511 *ov, unsigned short *val)
1525{
1526 int rc;
1527
1528 switch (ov->sensor) {
1529 case SEN_OV7610:
1530 case SEN_OV76BE:
1531 case SEN_OV7620:
1532 case SEN_OV6620:
1533 case SEN_OV6630:
1534 rc = i2c_r(ov, OV7610_REG_BRT);
1535 if (rc < 0)
1536 return rc;
1537 else
1538 *val = rc << 8;
1539 break;
1540 case SEN_SAA7111A:
1541 *val = ov->brightness;
1542 break;
1543 default:
1544 PDEBUG(3, "Unsupported with this sensor");
1545 return -EPERM;
1546 }
1547
1548 PDEBUG(3, "%d", *val);
1549 ov->brightness = *val;
1550
1551 return 0;
1552}
1553
1554/* -------------------------------------------------------------------------- */
1555
1556/* Sets sensor's saturation (color intensity) setting to "val" */
1557static int
1558sensor_set_saturation(struct usb_ov511 *ov, unsigned short val)
1559{
1560 int rc;
1561
1562 PDEBUG(3, "%d", val);
1563
1564 if (ov->stop_during_set)
1565 if (ov51x_stop(ov) < 0)
1566 return -EIO;
1567
1568 switch (ov->sensor) {
1569 case SEN_OV7610:
1570 case SEN_OV76BE:
1571 case SEN_OV6620:
1572 case SEN_OV6630:
1573 rc = i2c_w(ov, OV7610_REG_SAT, val >> 8);
1574 if (rc < 0)
1575 goto out;
1576 break;
1577 case SEN_OV7620:
1578// /* Use UV gamma control instead. Bits 0 & 7 are reserved. */
1579// rc = ov_i2c_write(ov->dev, 0x62, (val >> 9) & 0x7e);
1580// if (rc < 0)
1581// goto out;
1582 rc = i2c_w(ov, OV7610_REG_SAT, val >> 8);
1583 if (rc < 0)
1584 goto out;
1585 break;
1586 case SEN_SAA7111A:
1587 rc = i2c_w(ov, 0x0c, val >> 9);
1588 if (rc < 0)
1589 goto out;
1590 break;
1591 default:
1592 PDEBUG(3, "Unsupported with this sensor");
1593 rc = -EPERM;
1594 goto out;
1595 }
1596
1597 rc = 0; /* Success */
1598 ov->colour = val;
1599out:
1600 if (ov51x_restart(ov) < 0)
1601 return -EIO;
1602
1603 return rc;
1604}
1605
1606/* Gets sensor's saturation (color intensity) setting */
1607static int
1608sensor_get_saturation(struct usb_ov511 *ov, unsigned short *val)
1609{
1610 int rc;
1611
1612 switch (ov->sensor) {
1613 case SEN_OV7610:
1614 case SEN_OV76BE:
1615 case SEN_OV6620:
1616 case SEN_OV6630:
1617 rc = i2c_r(ov, OV7610_REG_SAT);
1618 if (rc < 0)
1619 return rc;
1620 else
1621 *val = rc << 8;
1622 break;
1623 case SEN_OV7620:
1624// /* Use UV gamma reg instead. Bits 0 & 7 are reserved. */
1625// rc = i2c_r(ov, 0x62);
1626// if (rc < 0)
1627// return rc;
1628// else
1629// *val = (rc & 0x7e) << 9;
1630 rc = i2c_r(ov, OV7610_REG_SAT);
1631 if (rc < 0)
1632 return rc;
1633 else
1634 *val = rc << 8;
1635 break;
1636 case SEN_SAA7111A:
1637 *val = ov->colour;
1638 break;
1639 default:
1640 PDEBUG(3, "Unsupported with this sensor");
1641 return -EPERM;
1642 }
1643
1644 PDEBUG(3, "%d", *val);
1645 ov->colour = *val;
1646
1647 return 0;
1648}
1649
1650/* -------------------------------------------------------------------------- */
1651
1652/* Sets sensor's hue (red/blue balance) setting to "val" */
1653static int
1654sensor_set_hue(struct usb_ov511 *ov, unsigned short val)
1655{
1656 int rc;
1657
1658 PDEBUG(3, "%d", val);
1659
1660 if (ov->stop_during_set)
1661 if (ov51x_stop(ov) < 0)
1662 return -EIO;
1663
1664 switch (ov->sensor) {
1665 case SEN_OV7610:
1666 case SEN_OV6620:
1667 case SEN_OV6630:
1668 rc = i2c_w(ov, OV7610_REG_RED, 0xFF - (val >> 8));
1669 if (rc < 0)
1670 goto out;
1671
1672 rc = i2c_w(ov, OV7610_REG_BLUE, val >> 8);
1673 if (rc < 0)
1674 goto out;
1675 break;
1676 case SEN_OV7620:
1677// Hue control is causing problems. I will enable it once it's fixed.
1678#if 0
1679 rc = i2c_w(ov, 0x7a, (unsigned char)(val >> 8) + 0xb);
1680 if (rc < 0)
1681 goto out;
1682
1683 rc = i2c_w(ov, 0x79, (unsigned char)(val >> 8) + 0xb);
1684 if (rc < 0)
1685 goto out;
1686#endif
1687 break;
1688 case SEN_SAA7111A:
1689 rc = i2c_w(ov, 0x0d, (val + 32768) >> 8);
1690 if (rc < 0)
1691 goto out;
1692 break;
1693 default:
1694 PDEBUG(3, "Unsupported with this sensor");
1695 rc = -EPERM;
1696 goto out;
1697 }
1698
1699 rc = 0; /* Success */
1700 ov->hue = val;
1701out:
1702 if (ov51x_restart(ov) < 0)
1703 return -EIO;
1704
1705 return rc;
1706}
1707
1708/* Gets sensor's hue (red/blue balance) setting */
1709static int
1710sensor_get_hue(struct usb_ov511 *ov, unsigned short *val)
1711{
1712 int rc;
1713
1714 switch (ov->sensor) {
1715 case SEN_OV7610:
1716 case SEN_OV6620:
1717 case SEN_OV6630:
1718 rc = i2c_r(ov, OV7610_REG_BLUE);
1719 if (rc < 0)
1720 return rc;
1721 else
1722 *val = rc << 8;
1723 break;
1724 case SEN_OV7620:
1725 rc = i2c_r(ov, 0x7a);
1726 if (rc < 0)
1727 return rc;
1728 else
1729 *val = rc << 8;
1730 break;
1731 case SEN_SAA7111A:
1732 *val = ov->hue;
1733 break;
1734 default:
1735 PDEBUG(3, "Unsupported with this sensor");
1736 return -EPERM;
1737 }
1738
1739 PDEBUG(3, "%d", *val);
1740 ov->hue = *val;
1741
1742 return 0;
1743}
1744
1745/* -------------------------------------------------------------------------- */
1746
1747static int
1748sensor_set_picture(struct usb_ov511 *ov, struct video_picture *p)
1749{
1750 int rc;
1751
1752 PDEBUG(4, "sensor_set_picture");
1753
1754 ov->whiteness = p->whiteness;
1755
1756 /* Don't return error if a setting is unsupported, or rest of settings
1757 * will not be performed */
1758
1759 rc = sensor_set_contrast(ov, p->contrast);
1760 if (FATAL_ERROR(rc))
1761 return rc;
1762
1763 rc = sensor_set_brightness(ov, p->brightness);
1764 if (FATAL_ERROR(rc))
1765 return rc;
1766
1767 rc = sensor_set_saturation(ov, p->colour);
1768 if (FATAL_ERROR(rc))
1769 return rc;
1770
1771 rc = sensor_set_hue(ov, p->hue);
1772 if (FATAL_ERROR(rc))
1773 return rc;
1774
1775 return 0;
1776}
1777
1778static int
1779sensor_get_picture(struct usb_ov511 *ov, struct video_picture *p)
1780{
1781 int rc;
1782
1783 PDEBUG(4, "sensor_get_picture");
1784
1785 /* Don't return error if a setting is unsupported, or rest of settings
1786 * will not be performed */
1787
1788 rc = sensor_get_contrast(ov, &(p->contrast));
1789 if (FATAL_ERROR(rc))
1790 return rc;
1791
1792 rc = sensor_get_brightness(ov, &(p->brightness));
1793 if (FATAL_ERROR(rc))
1794 return rc;
1795
1796 rc = sensor_get_saturation(ov, &(p->colour));
1797 if (FATAL_ERROR(rc))
1798 return rc;
1799
1800 rc = sensor_get_hue(ov, &(p->hue));
1801 if (FATAL_ERROR(rc))
1802 return rc;
1803
1804 p->whiteness = 105 << 8;
1805
1806 return 0;
1807}
1808
1809#if 0
1810// FIXME: Exposure range is only 0x00-0x7f in interlace mode
1811/* Sets current exposure for sensor. This only has an effect if auto-exposure
1812 * is off */
1813static inline int
1814sensor_set_exposure(struct usb_ov511 *ov, unsigned char val)
1815{
1816 int rc;
1817
1818 PDEBUG(3, "%d", val);
1819
1820 if (ov->stop_during_set)
1821 if (ov51x_stop(ov) < 0)
1822 return -EIO;
1823
1824 switch (ov->sensor) {
1825 case SEN_OV6620:
1826 case SEN_OV6630:
1827 case SEN_OV7610:
1828 case SEN_OV7620:
1829 case SEN_OV76BE:
1830 case SEN_OV8600:
1831 rc = i2c_w(ov, 0x10, val);
1832 if (rc < 0)
1833 goto out;
1834
1835 break;
1836 case SEN_KS0127:
1837 case SEN_KS0127B:
1838 case SEN_SAA7111A:
1839 PDEBUG(3, "Unsupported with this sensor");
1840 return -EPERM;
1841 default:
1842 err("Sensor not supported for set_exposure");
1843 return -EINVAL;
1844 }
1845
1846 rc = 0; /* Success */
1847 ov->exposure = val;
1848out:
1849 if (ov51x_restart(ov) < 0)
1850 return -EIO;
1851
1852 return rc;
1853}
1854#endif
1855
1856/* Gets current exposure level from sensor, regardless of whether it is under
1857 * manual control. */
1858static int
1859sensor_get_exposure(struct usb_ov511 *ov, unsigned char *val)
1860{
1861 int rc;
1862
1863 switch (ov->sensor) {
1864 case SEN_OV7610:
1865 case SEN_OV6620:
1866 case SEN_OV6630:
1867 case SEN_OV7620:
1868 case SEN_OV76BE:
1869 case SEN_OV8600:
1870 rc = i2c_r(ov, 0x10);
1871 if (rc < 0)
1872 return rc;
1873 else
1874 *val = rc;
1875 break;
1876 case SEN_KS0127:
1877 case SEN_KS0127B:
1878 case SEN_SAA7111A:
1879 val = NULL;
1880 PDEBUG(3, "Unsupported with this sensor");
1881 return -EPERM;
1882 default:
1883 err("Sensor not supported for get_exposure");
1884 return -EINVAL;
1885 }
1886
1887 PDEBUG(3, "%d", *val);
1888 ov->exposure = *val;
1889
1890 return 0;
1891}
1892
1893/* Turns on or off the LED. Only has an effect with OV511+/OV518(+) */
1894static void
1895ov51x_led_control(struct usb_ov511 *ov, int enable)
1896{
1897 PDEBUG(4, " (%s)", enable ? "turn on" : "turn off");
1898
1899 if (ov->bridge == BRG_OV511PLUS)
1900 reg_w(ov, R511_SYS_LED_CTL, enable ? 1 : 0);
1901 else if (ov->bclass == BCL_OV518)
1902 reg_w_mask(ov, R518_GPIO_OUT, enable ? 0x02 : 0x00, 0x02);
1903
1904 return;
1905}
1906
1907/* Matches the sensor's internal frame rate to the lighting frequency.
1908 * Valid frequencies are:
1909 * 50 - 50Hz, for European and Asian lighting
1910 * 60 - 60Hz, for American lighting
1911 *
1912 * Tested with: OV7610, OV7620, OV76BE, OV6620
1913 * Unsupported: KS0127, KS0127B, SAA7111A
1914 * Returns: 0 for success
1915 */
1916static int
1917sensor_set_light_freq(struct usb_ov511 *ov, int freq)
1918{
1919 int sixty;
1920
1921 PDEBUG(4, "%d Hz", freq);
1922
1923 if (freq == 60)
1924 sixty = 1;
1925 else if (freq == 50)
1926 sixty = 0;
1927 else {
1928 err("Invalid light freq (%d Hz)", freq);
1929 return -EINVAL;
1930 }
1931
1932 switch (ov->sensor) {
1933 case SEN_OV7610:
1934 i2c_w_mask(ov, 0x2a, sixty?0x00:0x80, 0x80);
1935 i2c_w(ov, 0x2b, sixty?0x00:0xac);
1936 i2c_w_mask(ov, 0x13, 0x10, 0x10);
1937 i2c_w_mask(ov, 0x13, 0x00, 0x10);
1938 break;
1939 case SEN_OV7620:
1940 case SEN_OV76BE:
1941 case SEN_OV8600:
1942 i2c_w_mask(ov, 0x2a, sixty?0x00:0x80, 0x80);
1943 i2c_w(ov, 0x2b, sixty?0x00:0xac);
1944 i2c_w_mask(ov, 0x76, 0x01, 0x01);
1945 break;
1946 case SEN_OV6620:
1947 case SEN_OV6630:
1948 i2c_w(ov, 0x2b, sixty?0xa8:0x28);
1949 i2c_w(ov, 0x2a, sixty?0x84:0xa4);
1950 break;
1951 case SEN_KS0127:
1952 case SEN_KS0127B:
1953 case SEN_SAA7111A:
1954 PDEBUG(5, "Unsupported with this sensor");
1955 return -EPERM;
1956 default:
1957 err("Sensor not supported for set_light_freq");
1958 return -EINVAL;
1959 }
1960
1961 ov->lightfreq = freq;
1962
1963 return 0;
1964}
1965
1966/* If enable is true, turn on the sensor's banding filter, otherwise turn it
1967 * off. This filter tries to reduce the pattern of horizontal light/dark bands
1968 * caused by some (usually fluorescent) lighting. The light frequency must be
1969 * set either before or after enabling it with ov51x_set_light_freq().
1970 *
1971 * Tested with: OV7610, OV7620, OV76BE, OV6620.
1972 * Unsupported: KS0127, KS0127B, SAA7111A
1973 * Returns: 0 for success
1974 */
1975static int
1976sensor_set_banding_filter(struct usb_ov511 *ov, int enable)
1977{
1978 int rc;
1979
1980 PDEBUG(4, " (%s)", enable ? "turn on" : "turn off");
1981
1982 if (ov->sensor == SEN_KS0127 || ov->sensor == SEN_KS0127B
1983 || ov->sensor == SEN_SAA7111A) {
1984 PDEBUG(5, "Unsupported with this sensor");
1985 return -EPERM;
1986 }
1987
1988 rc = i2c_w_mask(ov, 0x2d, enable?0x04:0x00, 0x04);
1989 if (rc < 0)
1990 return rc;
1991
1992 ov->bandfilt = enable;
1993
1994 return 0;
1995}
1996
1997/* If enable is true, turn on the sensor's auto brightness control, otherwise
1998 * turn it off.
1999 *
2000 * Unsupported: KS0127, KS0127B, SAA7111A
2001 * Returns: 0 for success
2002 */
2003static int
2004sensor_set_auto_brightness(struct usb_ov511 *ov, int enable)
2005{
2006 int rc;
2007
2008 PDEBUG(4, " (%s)", enable ? "turn on" : "turn off");
2009
2010 if (ov->sensor == SEN_KS0127 || ov->sensor == SEN_KS0127B
2011 || ov->sensor == SEN_SAA7111A) {
2012 PDEBUG(5, "Unsupported with this sensor");
2013 return -EPERM;
2014 }
2015
2016 rc = i2c_w_mask(ov, 0x2d, enable?0x10:0x00, 0x10);
2017 if (rc < 0)
2018 return rc;
2019
2020 ov->auto_brt = enable;
2021
2022 return 0;
2023}
2024
2025/* If enable is true, turn on the sensor's auto exposure control, otherwise
2026 * turn it off.
2027 *
2028 * Unsupported: KS0127, KS0127B, SAA7111A
2029 * Returns: 0 for success
2030 */
2031static int
2032sensor_set_auto_exposure(struct usb_ov511 *ov, int enable)
2033{
2034 PDEBUG(4, " (%s)", enable ? "turn on" : "turn off");
2035
2036 switch (ov->sensor) {
2037 case SEN_OV7610:
2038 i2c_w_mask(ov, 0x29, enable?0x00:0x80, 0x80);
2039 break;
2040 case SEN_OV6620:
2041 case SEN_OV7620:
2042 case SEN_OV76BE:
2043 case SEN_OV8600:
2044 i2c_w_mask(ov, 0x13, enable?0x01:0x00, 0x01);
2045 break;
2046 case SEN_OV6630:
2047 i2c_w_mask(ov, 0x28, enable?0x00:0x10, 0x10);
2048 break;
2049 case SEN_KS0127:
2050 case SEN_KS0127B:
2051 case SEN_SAA7111A:
2052 PDEBUG(5, "Unsupported with this sensor");
2053 return -EPERM;
2054 default:
2055 err("Sensor not supported for set_auto_exposure");
2056 return -EINVAL;
2057 }
2058
2059 ov->auto_exp = enable;
2060
2061 return 0;
2062}
2063
2064/* Modifies the sensor's exposure algorithm to allow proper exposure of objects
2065 * that are illuminated from behind.
2066 *
2067 * Tested with: OV6620, OV7620
2068 * Unsupported: OV7610, OV76BE, KS0127, KS0127B, SAA7111A
2069 * Returns: 0 for success
2070 */
2071static int
2072sensor_set_backlight(struct usb_ov511 *ov, int enable)
2073{
2074 PDEBUG(4, " (%s)", enable ? "turn on" : "turn off");
2075
2076 switch (ov->sensor) {
2077 case SEN_OV7620:
2078 case SEN_OV8600:
2079 i2c_w_mask(ov, 0x68, enable?0xe0:0xc0, 0xe0);
2080 i2c_w_mask(ov, 0x29, enable?0x08:0x00, 0x08);
2081 i2c_w_mask(ov, 0x28, enable?0x02:0x00, 0x02);
2082 break;
2083 case SEN_OV6620:
2084 i2c_w_mask(ov, 0x4e, enable?0xe0:0xc0, 0xe0);
2085 i2c_w_mask(ov, 0x29, enable?0x08:0x00, 0x08);
2086 i2c_w_mask(ov, 0x0e, enable?0x80:0x00, 0x80);
2087 break;
2088 case SEN_OV6630:
2089 i2c_w_mask(ov, 0x4e, enable?0x80:0x60, 0xe0);
2090 i2c_w_mask(ov, 0x29, enable?0x08:0x00, 0x08);
2091 i2c_w_mask(ov, 0x28, enable?0x02:0x00, 0x02);
2092 break;
2093 case SEN_OV7610:
2094 case SEN_OV76BE:
2095 case SEN_KS0127:
2096 case SEN_KS0127B:
2097 case SEN_SAA7111A:
2098 PDEBUG(5, "Unsupported with this sensor");
2099 return -EPERM;
2100 default:
2101 err("Sensor not supported for set_backlight");
2102 return -EINVAL;
2103 }
2104
2105 ov->backlight = enable;
2106
2107 return 0;
2108}
2109
2110static int
2111sensor_set_mirror(struct usb_ov511 *ov, int enable)
2112{
2113 PDEBUG(4, " (%s)", enable ? "turn on" : "turn off");
2114
2115 switch (ov->sensor) {
2116 case SEN_OV6620:
2117 case SEN_OV6630:
2118 case SEN_OV7610:
2119 case SEN_OV7620:
2120 case SEN_OV76BE:
2121 case SEN_OV8600:
2122 i2c_w_mask(ov, 0x12, enable?0x40:0x00, 0x40);
2123 break;
2124 case SEN_KS0127:
2125 case SEN_KS0127B:
2126 case SEN_SAA7111A:
2127 PDEBUG(5, "Unsupported with this sensor");
2128 return -EPERM;
2129 default:
2130 err("Sensor not supported for set_mirror");
2131 return -EINVAL;
2132 }
2133
2134 ov->mirror = enable;
2135
2136 return 0;
2137}
2138
2139/* Returns number of bits per pixel (regardless of where they are located;
2140 * planar or not), or zero for unsupported format.
2141 */
2142static inline int
2143get_depth(int palette)
2144{
2145 switch (palette) {
2146 case VIDEO_PALETTE_GREY: return 8;
2147 case VIDEO_PALETTE_YUV420: return 12;
2148 case VIDEO_PALETTE_YUV420P: return 12; /* Planar */
2149 default: return 0; /* Invalid format */
2150 }
2151}
2152
2153/* Bytes per frame. Used by read(). Return of 0 indicates error */
2154static inline long int
2155get_frame_length(struct ov511_frame *frame)
2156{
2157 if (!frame)
2158 return 0;
2159 else
2160 return ((frame->width * frame->height
2161 * get_depth(frame->format)) >> 3);
2162}
2163
2164static int
2165mode_init_ov_sensor_regs(struct usb_ov511 *ov, int width, int height,
2166 int mode, int sub_flag, int qvga)
2167{
2168 int clock;
2169
2170 /******** Mode (VGA/QVGA) and sensor specific regs ********/
2171
2172 switch (ov->sensor) {
2173 case SEN_OV7610:
2174 i2c_w(ov, 0x14, qvga?0x24:0x04);
2175// FIXME: Does this improve the image quality or frame rate?
2176#if 0
2177 i2c_w_mask(ov, 0x28, qvga?0x00:0x20, 0x20);
2178 i2c_w(ov, 0x24, 0x10);
2179 i2c_w(ov, 0x25, qvga?0x40:0x8a);
2180 i2c_w(ov, 0x2f, qvga?0x30:0xb0);
2181 i2c_w(ov, 0x35, qvga?0x1c:0x9c);
2182#endif
2183 break;
2184 case SEN_OV7620:
2185// i2c_w(ov, 0x2b, 0x00);
2186 i2c_w(ov, 0x14, qvga?0xa4:0x84);
2187 i2c_w_mask(ov, 0x28, qvga?0x00:0x20, 0x20);
2188 i2c_w(ov, 0x24, qvga?0x20:0x3a);
2189 i2c_w(ov, 0x25, qvga?0x30:0x60);
2190 i2c_w_mask(ov, 0x2d, qvga?0x40:0x00, 0x40);
2191 i2c_w_mask(ov, 0x67, qvga?0xf0:0x90, 0xf0);
2192 i2c_w_mask(ov, 0x74, qvga?0x20:0x00, 0x20);
2193 break;
2194 case SEN_OV76BE:
2195// i2c_w(ov, 0x2b, 0x00);
2196 i2c_w(ov, 0x14, qvga?0xa4:0x84);
2197// FIXME: Enable this once 7620AE uses 7620 initial settings
2198#if 0
2199 i2c_w_mask(ov, 0x28, qvga?0x00:0x20, 0x20);
2200 i2c_w(ov, 0x24, qvga?0x20:0x3a);
2201 i2c_w(ov, 0x25, qvga?0x30:0x60);
2202 i2c_w_mask(ov, 0x2d, qvga?0x40:0x00, 0x40);
2203 i2c_w_mask(ov, 0x67, qvga?0xb0:0x90, 0xf0);
2204 i2c_w_mask(ov, 0x74, qvga?0x20:0x00, 0x20);
2205#endif
2206 break;
2207 case SEN_OV6620:
2208 i2c_w(ov, 0x14, qvga?0x24:0x04);
2209 break;
2210 case SEN_OV6630:
2211 i2c_w(ov, 0x14, qvga?0xa0:0x80);
2212 break;
2213 default:
2214 err("Invalid sensor");
2215 return -EINVAL;
2216 }
2217
2218 /******** Palette-specific regs ********/
2219
2220 if (mode == VIDEO_PALETTE_GREY) {
2221 if (ov->sensor == SEN_OV7610 || ov->sensor == SEN_OV76BE) {
2222 /* these aren't valid on the OV6620/OV7620/6630? */
2223 i2c_w_mask(ov, 0x0e, 0x40, 0x40);
2224 }
2225
2226 if (ov->sensor == SEN_OV6630 && ov->bridge == BRG_OV518
2227 && ov518_color) {
2228 i2c_w_mask(ov, 0x12, 0x00, 0x10);
2229 i2c_w_mask(ov, 0x13, 0x00, 0x20);
2230 } else {
2231 i2c_w_mask(ov, 0x13, 0x20, 0x20);
2232 }
2233 } else {
2234 if (ov->sensor == SEN_OV7610 || ov->sensor == SEN_OV76BE) {
2235 /* not valid on the OV6620/OV7620/6630? */
2236 i2c_w_mask(ov, 0x0e, 0x00, 0x40);
2237 }
2238
2239 /* The OV518 needs special treatment. Although both the OV518
2240 * and the OV6630 support a 16-bit video bus, only the 8 bit Y
2241 * bus is actually used. The UV bus is tied to ground.
2242 * Therefore, the OV6630 needs to be in 8-bit multiplexed
2243 * output mode */
2244
2245 if (ov->sensor == SEN_OV6630 && ov->bridge == BRG_OV518
2246 && ov518_color) {
2247 i2c_w_mask(ov, 0x12, 0x10, 0x10);
2248 i2c_w_mask(ov, 0x13, 0x20, 0x20);
2249 } else {
2250 i2c_w_mask(ov, 0x13, 0x00, 0x20);
2251 }
2252 }
2253
2254 /******** Clock programming ********/
2255
2256 /* The OV6620 needs special handling. This prevents the
2257 * severe banding that normally occurs */
2258 if (ov->sensor == SEN_OV6620 || ov->sensor == SEN_OV6630)
2259 {
2260 /* Clock down */
2261
2262 i2c_w(ov, 0x2a, 0x04);
2263
2264 if (ov->compress) {
2265// clock = 0; /* This ensures the highest frame rate */
2266 clock = 3;
2267 } else if (clockdiv == -1) { /* If user didn't override it */
2268 clock = 3; /* Gives better exposure time */
2269 } else {
2270 clock = clockdiv;
2271 }
2272
2273 PDEBUG(4, "Setting clock divisor to %d", clock);
2274
2275 i2c_w(ov, 0x11, clock);
2276
2277 i2c_w(ov, 0x2a, 0x84);
2278 /* This next setting is critical. It seems to improve
2279 * the gain or the contrast. The "reserved" bits seem
2280 * to have some effect in this case. */
2281 i2c_w(ov, 0x2d, 0x85);
2282 }
2283 else
2284 {
2285 if (ov->compress) {
2286 clock = 1; /* This ensures the highest frame rate */
2287 } else if (clockdiv == -1) { /* If user didn't override it */
2288 /* Calculate and set the clock divisor */
2289 clock = ((sub_flag ? ov->subw * ov->subh
2290 : width * height)
2291 * (mode == VIDEO_PALETTE_GREY ? 2 : 3) / 2)
2292 / 66000;
2293 } else {
2294 clock = clockdiv;
2295 }
2296
2297 PDEBUG(4, "Setting clock divisor to %d", clock);
2298
2299 i2c_w(ov, 0x11, clock);
2300 }
2301
2302 /******** Special Features ********/
2303
2304 if (framedrop >= 0)
2305 i2c_w(ov, 0x16, framedrop);
2306
2307 /* Test Pattern */
2308 i2c_w_mask(ov, 0x12, (testpat?0x02:0x00), 0x02);
2309
2310 /* Enable auto white balance */
2311 i2c_w_mask(ov, 0x12, 0x04, 0x04);
2312
2313 // This will go away as soon as ov51x_mode_init_sensor_regs()
2314 // is fully tested.
2315 /* 7620/6620/6630? don't have register 0x35, so play it safe */
2316 if (ov->sensor == SEN_OV7610 || ov->sensor == SEN_OV76BE) {
2317 if (width == 640 && height == 480)
2318 i2c_w(ov, 0x35, 0x9e);
2319 else
2320 i2c_w(ov, 0x35, 0x1e);
2321 }
2322
2323 return 0;
2324}
2325
2326static int
2327set_ov_sensor_window(struct usb_ov511 *ov, int width, int height, int mode,
2328 int sub_flag)
2329{
2330 int ret;
2331 int hwsbase, hwebase, vwsbase, vwebase, hwsize, vwsize;
2332 int hoffset, voffset, hwscale = 0, vwscale = 0;
2333
2334 /* The different sensor ICs handle setting up of window differently.
2335 * IF YOU SET IT WRONG, YOU WILL GET ALL ZERO ISOC DATA FROM OV51x!!! */
2336 switch (ov->sensor) {
2337 case SEN_OV7610:
2338 case SEN_OV76BE:
2339 hwsbase = 0x38;
2340 hwebase = 0x3a;
2341 vwsbase = vwebase = 0x05;
2342 break;
2343 case SEN_OV6620:
2344 case SEN_OV6630:
2345 hwsbase = 0x38;
2346 hwebase = 0x3a;
2347 vwsbase = 0x05;
2348 vwebase = 0x06;
2349 break;
2350 case SEN_OV7620:
2351 hwsbase = 0x2f; /* From 7620.SET (spec is wrong) */
2352 hwebase = 0x2f;
2353 vwsbase = vwebase = 0x05;
2354 break;
2355 default:
2356 err("Invalid sensor");
2357 return -EINVAL;
2358 }
2359
2360 if (ov->sensor == SEN_OV6620 || ov->sensor == SEN_OV6630) {
2361 /* Note: OV518(+) does downsample on its own) */
2362 if ((width > 176 && height > 144)
2363 || ov->bclass == BCL_OV518) { /* CIF */
2364 ret = mode_init_ov_sensor_regs(ov, width, height,
2365 mode, sub_flag, 0);
2366 if (ret < 0)
2367 return ret;
2368 hwscale = 1;
2369 vwscale = 1; /* The datasheet says 0; it's wrong */
2370 hwsize = 352;
2371 vwsize = 288;
2372 } else if (width > 176 || height > 144) {
2373 err("Illegal dimensions");
2374 return -EINVAL;
2375 } else { /* QCIF */
2376 ret = mode_init_ov_sensor_regs(ov, width, height,
2377 mode, sub_flag, 1);
2378 if (ret < 0)
2379 return ret;
2380 hwsize = 176;
2381 vwsize = 144;
2382 }
2383 } else {
2384 if (width > 320 && height > 240) { /* VGA */
2385 ret = mode_init_ov_sensor_regs(ov, width, height,
2386 mode, sub_flag, 0);
2387 if (ret < 0)
2388 return ret;
2389 hwscale = 2;
2390 vwscale = 1;
2391 hwsize = 640;
2392 vwsize = 480;
2393 } else if (width > 320 || height > 240) {
2394 err("Illegal dimensions");
2395 return -EINVAL;
2396 } else { /* QVGA */
2397 ret = mode_init_ov_sensor_regs(ov, width, height,
2398 mode, sub_flag, 1);
2399 if (ret < 0)
2400 return ret;
2401 hwscale = 1;
2402 hwsize = 320;
2403 vwsize = 240;
2404 }
2405 }
2406
2407 /* Center the window */
2408 hoffset = ((hwsize - width) / 2) >> hwscale;
2409 voffset = ((vwsize - height) / 2) >> vwscale;
2410
2411 /* FIXME! - This needs to be changed to support 160x120 and 6620!!! */
2412 if (sub_flag) {
2413 i2c_w(ov, 0x17, hwsbase+(ov->subx>>hwscale));
2414 i2c_w(ov, 0x18, hwebase+((ov->subx+ov->subw)>>hwscale));
2415 i2c_w(ov, 0x19, vwsbase+(ov->suby>>vwscale));
2416 i2c_w(ov, 0x1a, vwebase+((ov->suby+ov->subh)>>vwscale));
2417 } else {
2418 i2c_w(ov, 0x17, hwsbase + hoffset);
2419 i2c_w(ov, 0x18, hwebase + hoffset + (hwsize>>hwscale));
2420 i2c_w(ov, 0x19, vwsbase + voffset);
2421 i2c_w(ov, 0x1a, vwebase + voffset + (vwsize>>vwscale));
2422 }
2423
2424#ifdef OV511_DEBUG
2425 if (dump_sensor)
2426 dump_i2c_regs(ov);
2427#endif
2428
2429 return 0;
2430}
2431
2432/* Set up the OV511/OV511+ with the given image parameters.
2433 *
2434 * Do not put any sensor-specific code in here (including I2C I/O functions)
2435 */
2436static int
2437ov511_mode_init_regs(struct usb_ov511 *ov,
2438 int width, int height, int mode, int sub_flag)
2439{
2440 int hsegs, vsegs;
2441
2442 if (sub_flag) {
2443 width = ov->subw;
2444 height = ov->subh;
2445 }
2446
2447 PDEBUG(3, "width:%d, height:%d, mode:%d, sub:%d",
2448 width, height, mode, sub_flag);
2449
2450 // FIXME: This should be moved to a 7111a-specific function once
2451 // subcapture is dealt with properly
2452 if (ov->sensor == SEN_SAA7111A) {
2453 if (width == 320 && height == 240) {
2454 /* No need to do anything special */
2455 } else if (width == 640 && height == 480) {
2456 /* Set the OV511 up as 320x480, but keep the
2457 * V4L resolution as 640x480 */
2458 width = 320;
2459 } else {
2460 err("SAA7111A only allows 320x240 or 640x480");
2461 return -EINVAL;
2462 }
2463 }
2464
2465 /* Make sure width and height are a multiple of 8 */
2466 if (width % 8 || height % 8) {
2467 err("Invalid size (%d, %d) (mode = %d)", width, height, mode);
2468 return -EINVAL;
2469 }
2470
2471 if (width < ov->minwidth || height < ov->minheight) {
2472 err("Requested dimensions are too small");
2473 return -EINVAL;
2474 }
2475
2476 if (ov51x_stop(ov) < 0)
2477 return -EIO;
2478
2479 if (mode == VIDEO_PALETTE_GREY) {
2480 reg_w(ov, R511_CAM_UV_EN, 0x00);
2481 reg_w(ov, R511_SNAP_UV_EN, 0x00);
2482 reg_w(ov, R511_SNAP_OPTS, 0x01);
2483 } else {
2484 reg_w(ov, R511_CAM_UV_EN, 0x01);
2485 reg_w(ov, R511_SNAP_UV_EN, 0x01);
2486 reg_w(ov, R511_SNAP_OPTS, 0x03);
2487 }
2488
2489 /* Here I'm assuming that snapshot size == image size.
2490 * I hope that's always true. --claudio
2491 */
2492 hsegs = (width >> 3) - 1;
2493 vsegs = (height >> 3) - 1;
2494
2495 reg_w(ov, R511_CAM_PXCNT, hsegs);
2496 reg_w(ov, R511_CAM_LNCNT, vsegs);
2497 reg_w(ov, R511_CAM_PXDIV, 0x00);
2498 reg_w(ov, R511_CAM_LNDIV, 0x00);
2499
2500 /* YUV420, low pass filter on */
2501 reg_w(ov, R511_CAM_OPTS, 0x03);
2502
2503 /* Snapshot additions */
2504 reg_w(ov, R511_SNAP_PXCNT, hsegs);
2505 reg_w(ov, R511_SNAP_LNCNT, vsegs);
2506 reg_w(ov, R511_SNAP_PXDIV, 0x00);
2507 reg_w(ov, R511_SNAP_LNDIV, 0x00);
2508
2509 if (ov->compress) {
2510 /* Enable Y and UV quantization and compression */
2511 reg_w(ov, R511_COMP_EN, 0x07);
2512 reg_w(ov, R511_COMP_LUT_EN, 0x03);
2513 ov51x_reset(ov, OV511_RESET_OMNICE);
2514 }
2515
2516 if (ov51x_restart(ov) < 0)
2517 return -EIO;
2518
2519 return 0;
2520}
2521
2522/* Sets up the OV518/OV518+ with the given image parameters
2523 *
2524 * OV518 needs a completely different approach, until we can figure out what
2525 * the individual registers do. Also, only 15 FPS is supported now.
2526 *
2527 * Do not put any sensor-specific code in here (including I2C I/O functions)
2528 */
2529static int
2530ov518_mode_init_regs(struct usb_ov511 *ov,
2531 int width, int height, int mode, int sub_flag)
2532{
2533 int hsegs, vsegs, hi_res;
2534
2535 if (sub_flag) {
2536 width = ov->subw;
2537 height = ov->subh;
2538 }
2539
2540 PDEBUG(3, "width:%d, height:%d, mode:%d, sub:%d",
2541 width, height, mode, sub_flag);
2542
2543 if (width % 16 || height % 8) {
2544 err("Invalid size (%d, %d)", width, height);
2545 return -EINVAL;
2546 }
2547
2548 if (width < ov->minwidth || height < ov->minheight) {
2549 err("Requested dimensions are too small");
2550 return -EINVAL;
2551 }
2552
2553 if (width >= 320 && height >= 240) {
2554 hi_res = 1;
2555 } else if (width >= 320 || height >= 240) {
2556 err("Invalid width/height combination (%d, %d)", width, height);
2557 return -EINVAL;
2558 } else {
2559 hi_res = 0;
2560 }
2561
2562 if (ov51x_stop(ov) < 0)
2563 return -EIO;
2564
2565 /******** Set the mode ********/
2566
2567 reg_w(ov, 0x2b, 0);
2568 reg_w(ov, 0x2c, 0);
2569 reg_w(ov, 0x2d, 0);
2570 reg_w(ov, 0x2e, 0);
2571 reg_w(ov, 0x3b, 0);
2572 reg_w(ov, 0x3c, 0);
2573 reg_w(ov, 0x3d, 0);
2574 reg_w(ov, 0x3e, 0);
2575
2576 if (ov->bridge == BRG_OV518 && ov518_color) {
2577 /* OV518 needs U and V swapped */
2578 i2c_w_mask(ov, 0x15, 0x00, 0x01);
2579
2580 if (mode == VIDEO_PALETTE_GREY) {
2581 /* Set 16-bit input format (UV data are ignored) */
2582 reg_w_mask(ov, 0x20, 0x00, 0x08);
2583
2584 /* Set 8-bit (4:0:0) output format */
2585 reg_w_mask(ov, 0x28, 0x00, 0xf0);
2586 reg_w_mask(ov, 0x38, 0x00, 0xf0);
2587 } else {
2588 /* Set 8-bit (YVYU) input format */
2589 reg_w_mask(ov, 0x20, 0x08, 0x08);
2590
2591 /* Set 12-bit (4:2:0) output format */
2592 reg_w_mask(ov, 0x28, 0x80, 0xf0);
2593 reg_w_mask(ov, 0x38, 0x80, 0xf0);
2594 }
2595 } else {
2596 reg_w(ov, 0x28, (mode == VIDEO_PALETTE_GREY) ? 0x00:0x80);
2597 reg_w(ov, 0x38, (mode == VIDEO_PALETTE_GREY) ? 0x00:0x80);
2598 }
2599
2600 hsegs = width / 16;
2601 vsegs = height / 4;
2602
2603 reg_w(ov, 0x29, hsegs);
2604 reg_w(ov, 0x2a, vsegs);
2605
2606 reg_w(ov, 0x39, hsegs);
2607 reg_w(ov, 0x3a, vsegs);
2608
2609 /* Windows driver does this here; who knows why */
2610 reg_w(ov, 0x2f, 0x80);
2611
2612 /******** Set the framerate (to 15 FPS) ********/
2613
2614 /* Mode independent, but framerate dependent, regs */
2615 reg_w(ov, 0x51, 0x02); /* Clock divider; lower==faster */
2616 reg_w(ov, 0x22, 0x18);
2617 reg_w(ov, 0x23, 0xff);
2618
2619 if (ov->bridge == BRG_OV518PLUS)
2620 reg_w(ov, 0x21, 0x19);
2621 else
2622 reg_w(ov, 0x71, 0x19); /* Compression-related? */
2623
2624 // FIXME: Sensor-specific
2625 /* Bit 5 is what matters here. Of course, it is "reserved" */
2626 i2c_w(ov, 0x54, 0x23);
2627
2628 reg_w(ov, 0x2f, 0x80);
2629
2630 if (ov->bridge == BRG_OV518PLUS) {
2631 reg_w(ov, 0x24, 0x94);
2632 reg_w(ov, 0x25, 0x90);
2633 ov518_reg_w32(ov, 0xc4, 400, 2); /* 190h */
2634 ov518_reg_w32(ov, 0xc6, 540, 2); /* 21ch */
2635 ov518_reg_w32(ov, 0xc7, 540, 2); /* 21ch */
2636 ov518_reg_w32(ov, 0xc8, 108, 2); /* 6ch */
2637 ov518_reg_w32(ov, 0xca, 131098, 3); /* 2001ah */
2638 ov518_reg_w32(ov, 0xcb, 532, 2); /* 214h */
2639 ov518_reg_w32(ov, 0xcc, 2400, 2); /* 960h */
2640 ov518_reg_w32(ov, 0xcd, 32, 2); /* 20h */
2641 ov518_reg_w32(ov, 0xce, 608, 2); /* 260h */
2642 } else {
2643 reg_w(ov, 0x24, 0x9f);
2644 reg_w(ov, 0x25, 0x90);
2645 ov518_reg_w32(ov, 0xc4, 400, 2); /* 190h */
2646 ov518_reg_w32(ov, 0xc6, 500, 2); /* 1f4h */
2647 ov518_reg_w32(ov, 0xc7, 500, 2); /* 1f4h */
2648 ov518_reg_w32(ov, 0xc8, 142, 2); /* 8eh */
2649 ov518_reg_w32(ov, 0xca, 131098, 3); /* 2001ah */
2650 ov518_reg_w32(ov, 0xcb, 532, 2); /* 214h */
2651 ov518_reg_w32(ov, 0xcc, 2000, 2); /* 7d0h */
2652 ov518_reg_w32(ov, 0xcd, 32, 2); /* 20h */
2653 ov518_reg_w32(ov, 0xce, 608, 2); /* 260h */
2654 }
2655
2656 reg_w(ov, 0x2f, 0x80);
2657
2658 if (ov51x_restart(ov) < 0)
2659 return -EIO;
2660
2661 /* Reset it just for good measure */
2662 if (ov51x_reset(ov, OV511_RESET_NOREGS) < 0)
2663 return -EIO;
2664
2665 return 0;
2666}
2667
2668/* This is a wrapper around the OV511, OV518, and sensor specific functions */
2669static int
2670mode_init_regs(struct usb_ov511 *ov,
2671 int width, int height, int mode, int sub_flag)
2672{
2673 int rc = 0;
2674
2675 if (!ov || !ov->dev)
2676 return -EFAULT;
2677
2678 if (ov->bclass == BCL_OV518) {
2679 rc = ov518_mode_init_regs(ov, width, height, mode, sub_flag);
2680 } else {
2681 rc = ov511_mode_init_regs(ov, width, height, mode, sub_flag);
2682 }
2683
2684 if (FATAL_ERROR(rc))
2685 return rc;
2686
2687 switch (ov->sensor) {
2688 case SEN_OV7610:
2689 case SEN_OV7620:
2690 case SEN_OV76BE:
2691 case SEN_OV8600:
2692 case SEN_OV6620:
2693 case SEN_OV6630:
2694 rc = set_ov_sensor_window(ov, width, height, mode, sub_flag);
2695 break;
2696 case SEN_KS0127:
2697 case SEN_KS0127B:
2698 err("KS0127-series decoders not supported yet");
2699 rc = -EINVAL;
2700 break;
2701 case SEN_SAA7111A:
2702// rc = mode_init_saa_sensor_regs(ov, width, height, mode,
2703// sub_flag);
2704
2705 PDEBUG(1, "SAA status = 0x%02X", i2c_r(ov, 0x1f));
2706 break;
2707 default:
2708 err("Unknown sensor");
2709 rc = -EINVAL;
2710 }
2711
2712 if (FATAL_ERROR(rc))
2713 return rc;
2714
2715 /* Sensor-independent settings */
2716 rc = sensor_set_auto_brightness(ov, ov->auto_brt);
2717 if (FATAL_ERROR(rc))
2718 return rc;
2719
2720 rc = sensor_set_auto_exposure(ov, ov->auto_exp);
2721 if (FATAL_ERROR(rc))
2722 return rc;
2723
2724 rc = sensor_set_banding_filter(ov, bandingfilter);
2725 if (FATAL_ERROR(rc))
2726 return rc;
2727
2728 if (ov->lightfreq) {
2729 rc = sensor_set_light_freq(ov, lightfreq);
2730 if (FATAL_ERROR(rc))
2731 return rc;
2732 }
2733
2734 rc = sensor_set_backlight(ov, ov->backlight);
2735 if (FATAL_ERROR(rc))
2736 return rc;
2737
2738 rc = sensor_set_mirror(ov, ov->mirror);
2739 if (FATAL_ERROR(rc))
2740 return rc;
2741
2742 return 0;
2743}
2744
2745/* This sets the default image parameters. This is useful for apps that use
2746 * read() and do not set these.
2747 */
2748static int
2749ov51x_set_default_params(struct usb_ov511 *ov)
2750{
2751 int i;
2752
2753 /* Set default sizes in case IOCTL (VIDIOCMCAPTURE) is not used
2754 * (using read() instead). */
2755 for (i = 0; i < OV511_NUMFRAMES; i++) {
2756 ov->frame[i].width = ov->maxwidth;
2757 ov->frame[i].height = ov->maxheight;
2758 ov->frame[i].bytes_read = 0;
2759 if (force_palette)
2760 ov->frame[i].format = force_palette;
2761 else
2762 ov->frame[i].format = VIDEO_PALETTE_YUV420;
2763
2764 ov->frame[i].depth = get_depth(ov->frame[i].format);
2765 }
2766
2767 PDEBUG(3, "%dx%d, %s", ov->maxwidth, ov->maxheight,
2768 symbolic(v4l1_plist, ov->frame[0].format));
2769
2770 /* Initialize to max width/height, YUV420 or RGB24 (if supported) */
2771 if (mode_init_regs(ov, ov->maxwidth, ov->maxheight,
2772 ov->frame[0].format, 0) < 0)
2773 return -EINVAL;
2774
2775 return 0;
2776}
2777
2778/**********************************************************************
2779 *
2780 * Video decoder stuff
2781 *
2782 **********************************************************************/
2783
2784/* Set analog input port of decoder */
2785static int
2786decoder_set_input(struct usb_ov511 *ov, int input)
2787{
2788 PDEBUG(4, "port %d", input);
2789
2790 switch (ov->sensor) {
2791 case SEN_SAA7111A:
2792 {
2793 /* Select mode */
2794 i2c_w_mask(ov, 0x02, input, 0x07);
2795 /* Bypass chrominance trap for modes 4..7 */
2796 i2c_w_mask(ov, 0x09, (input > 3) ? 0x80:0x00, 0x80);
2797 break;
2798 }
2799 default:
2800 return -EINVAL;
2801 }
2802
2803 return 0;
2804}
2805
2806/* Get ASCII name of video input */
2807static int
2808decoder_get_input_name(struct usb_ov511 *ov, int input, char *name)
2809{
2810 switch (ov->sensor) {
2811 case SEN_SAA7111A:
2812 {
2813 if (input < 0 || input > 7)
2814 return -EINVAL;
2815 else if (input < 4)
2816 sprintf(name, "CVBS-%d", input);
2817 else // if (input < 8)
2818 sprintf(name, "S-Video-%d", input - 4);
2819 break;
2820 }
2821 default:
2822 sprintf(name, "%s", "Camera");
2823 }
2824
2825 return 0;
2826}
2827
2828/* Set norm (NTSC, PAL, SECAM, AUTO) */
2829static int
2830decoder_set_norm(struct usb_ov511 *ov, int norm)
2831{
2832 PDEBUG(4, "%d", norm);
2833
2834 switch (ov->sensor) {
2835 case SEN_SAA7111A:
2836 {
2837 int reg_8, reg_e;
2838
2839 if (norm == VIDEO_MODE_NTSC) {
2840 reg_8 = 0x40; /* 60 Hz */
2841 reg_e = 0x00; /* NTSC M / PAL BGHI */
2842 } else if (norm == VIDEO_MODE_PAL) {
2843 reg_8 = 0x00; /* 50 Hz */
2844 reg_e = 0x00; /* NTSC M / PAL BGHI */
2845 } else if (norm == VIDEO_MODE_AUTO) {
2846 reg_8 = 0x80; /* Auto field detect */
2847 reg_e = 0x00; /* NTSC M / PAL BGHI */
2848 } else if (norm == VIDEO_MODE_SECAM) {
2849 reg_8 = 0x00; /* 50 Hz */
2850 reg_e = 0x50; /* SECAM / PAL 4.43 */
2851 } else {
2852 return -EINVAL;
2853 }
2854
2855 i2c_w_mask(ov, 0x08, reg_8, 0xc0);
2856 i2c_w_mask(ov, 0x0e, reg_e, 0x70);
2857 break;
2858 }
2859 default:
2860 return -EINVAL;
2861 }
2862
2863 return 0;
2864}
2865
2866/**********************************************************************
2867 *
2868 * Raw data parsing
2869 *
2870 **********************************************************************/
2871
2872/* Copies a 64-byte segment at pIn to an 8x8 block at pOut. The width of the
2873 * image at pOut is specified by w.
2874 */
2875static inline void
2876make_8x8(unsigned char *pIn, unsigned char *pOut, int w)
2877{
2878 unsigned char *pOut1 = pOut;
2879 int x, y;
2880
2881 for (y = 0; y < 8; y++) {
2882 pOut1 = pOut;
2883 for (x = 0; x < 8; x++) {
2884 *pOut1++ = *pIn++;
2885 }
2886 pOut += w;
2887 }
2888}
2889
2890/*
2891 * For RAW BW (YUV 4:0:0) images, data show up in 256 byte segments.
2892 * The segments represent 4 squares of 8x8 pixels as follows:
2893 *
2894 * 0 1 ... 7 64 65 ... 71 ... 192 193 ... 199
2895 * 8 9 ... 15 72 73 ... 79 200 201 ... 207
2896 * ... ... ...
2897 * 56 57 ... 63 120 121 ... 127 248 249 ... 255
2898 *
2899 */
2900static void
2901yuv400raw_to_yuv400p(struct ov511_frame *frame,
2902 unsigned char *pIn0, unsigned char *pOut0)
2903{
2904 int x, y;
2905 unsigned char *pIn, *pOut, *pOutLine;
2906
2907 /* Copy Y */
2908 pIn = pIn0;
2909 pOutLine = pOut0;
2910 for (y = 0; y < frame->rawheight - 1; y += 8) {
2911 pOut = pOutLine;
2912 for (x = 0; x < frame->rawwidth - 1; x += 8) {
2913 make_8x8(pIn, pOut, frame->rawwidth);
2914 pIn += 64;
2915 pOut += 8;
2916 }
2917 pOutLine += 8 * frame->rawwidth;
2918 }
2919}
2920
2921/*
2922 * For YUV 4:2:0 images, the data show up in 384 byte segments.
2923 * The first 64 bytes of each segment are U, the next 64 are V. The U and
2924 * V are arranged as follows:
2925 *
2926 * 0 1 ... 7
2927 * 8 9 ... 15
2928 * ...
2929 * 56 57 ... 63
2930 *
2931 * U and V are shipped at half resolution (1 U,V sample -> one 2x2 block).
2932 *
2933 * The next 256 bytes are full resolution Y data and represent 4 squares
2934 * of 8x8 pixels as follows:
2935 *
2936 * 0 1 ... 7 64 65 ... 71 ... 192 193 ... 199
2937 * 8 9 ... 15 72 73 ... 79 200 201 ... 207
2938 * ... ... ...
2939 * 56 57 ... 63 120 121 ... 127 ... 248 249 ... 255
2940 *
2941 * Note that the U and V data in one segment represent a 16 x 16 pixel
2942 * area, but the Y data represent a 32 x 8 pixel area. If the width is not an
2943 * even multiple of 32, the extra 8x8 blocks within a 32x8 block belong to the
2944 * next horizontal stripe.
2945 *
2946 * If dumppix module param is set, _parse_data just dumps the incoming segments,
2947 * verbatim, in order, into the frame. When used with vidcat -f ppm -s 640x480
2948 * this puts the data on the standard output and can be analyzed with the
2949 * parseppm.c utility I wrote. That's a much faster way for figuring out how
2950 * these data are scrambled.
2951 */
2952
2953/* Converts from raw, uncompressed segments at pIn0 to a YUV420P frame at pOut0.
2954 *
2955 * FIXME: Currently only handles width and height that are multiples of 16
2956 */
2957static void
2958yuv420raw_to_yuv420p(struct ov511_frame *frame,
2959 unsigned char *pIn0, unsigned char *pOut0)
2960{
2961 int k, x, y;
2962 unsigned char *pIn, *pOut, *pOutLine;
2963 const unsigned int a = frame->rawwidth * frame->rawheight;
2964 const unsigned int w = frame->rawwidth / 2;
2965
2966 /* Copy U and V */
2967 pIn = pIn0;
2968 pOutLine = pOut0 + a;
2969 for (y = 0; y < frame->rawheight - 1; y += 16) {
2970 pOut = pOutLine;
2971 for (x = 0; x < frame->rawwidth - 1; x += 16) {
2972 make_8x8(pIn, pOut, w);
2973 make_8x8(pIn + 64, pOut + a/4, w);
2974 pIn += 384;
2975 pOut += 8;
2976 }
2977 pOutLine += 8 * w;
2978 }
2979
2980 /* Copy Y */
2981 pIn = pIn0 + 128;
2982 pOutLine = pOut0;
2983 k = 0;
2984 for (y = 0; y < frame->rawheight - 1; y += 8) {
2985 pOut = pOutLine;
2986 for (x = 0; x < frame->rawwidth - 1; x += 8) {
2987 make_8x8(pIn, pOut, frame->rawwidth);
2988 pIn += 64;
2989 pOut += 8;
2990 if ((++k) > 3) {
2991 k = 0;
2992 pIn += 128;
2993 }
2994 }
2995 pOutLine += 8 * frame->rawwidth;
2996 }
2997}
2998
2999/**********************************************************************
3000 *
3001 * Decompression
3002 *
3003 **********************************************************************/
3004
3005static int
3006request_decompressor(struct usb_ov511 *ov)
3007{
3008 if (ov->bclass == BCL_OV511 || ov->bclass == BCL_OV518) {
3009 err("No decompressor available");
3010 } else {
3011 err("Unknown bridge");
3012 }
3013
3014 return -ENOSYS;
3015}
3016
3017static void
3018decompress(struct usb_ov511 *ov, struct ov511_frame *frame,
3019 unsigned char *pIn0, unsigned char *pOut0)
3020{
3021 if (!ov->decomp_ops)
3022 if (request_decompressor(ov))
3023 return;
3024
3025}
3026
3027/**********************************************************************
3028 *
3029 * Format conversion
3030 *
3031 **********************************************************************/
3032
3033/* Fuses even and odd fields together, and doubles width.
3034 * INPUT: an odd field followed by an even field at pIn0, in YUV planar format
3035 * OUTPUT: a normal YUV planar image, with correct aspect ratio
3036 */
3037static void
3038deinterlace(struct ov511_frame *frame, int rawformat,
3039 unsigned char *pIn0, unsigned char *pOut0)
3040{
3041 const int fieldheight = frame->rawheight / 2;
3042 const int fieldpix = fieldheight * frame->rawwidth;
3043 const int w = frame->width;
3044 int x, y;
3045 unsigned char *pInEven, *pInOdd, *pOut;
3046
3047 PDEBUG(5, "fieldheight=%d", fieldheight);
3048
3049 if (frame->rawheight != frame->height) {
3050 err("invalid height");
3051 return;
3052 }
3053
3054 if ((frame->rawwidth * 2) != frame->width) {
3055 err("invalid width");
3056 return;
3057 }
3058
3059 /* Y */
3060 pInOdd = pIn0;
3061 pInEven = pInOdd + fieldpix;
3062 pOut = pOut0;
3063 for (y = 0; y < fieldheight; y++) {
3064 for (x = 0; x < frame->rawwidth; x++) {
3065 *pOut = *pInEven;
3066 *(pOut+1) = *pInEven++;
3067 *(pOut+w) = *pInOdd;
3068 *(pOut+w+1) = *pInOdd++;
3069 pOut += 2;
3070 }
3071 pOut += w;
3072 }
3073
3074 if (rawformat == RAWFMT_YUV420) {
3075 /* U */
3076 pInOdd = pIn0 + fieldpix * 2;
3077 pInEven = pInOdd + fieldpix / 4;
3078 for (y = 0; y < fieldheight / 2; y++) {
3079 for (x = 0; x < frame->rawwidth / 2; x++) {
3080 *pOut = *pInEven;
3081 *(pOut+1) = *pInEven++;
3082 *(pOut+w/2) = *pInOdd;
3083 *(pOut+w/2+1) = *pInOdd++;
3084 pOut += 2;
3085 }
3086 pOut += w/2;
3087 }
3088 /* V */
3089 pInOdd = pIn0 + fieldpix * 2 + fieldpix / 2;
3090 pInEven = pInOdd + fieldpix / 4;
3091 for (y = 0; y < fieldheight / 2; y++) {
3092 for (x = 0; x < frame->rawwidth / 2; x++) {
3093 *pOut = *pInEven;
3094 *(pOut+1) = *pInEven++;
3095 *(pOut+w/2) = *pInOdd;
3096 *(pOut+w/2+1) = *pInOdd++;
3097 pOut += 2;
3098 }
3099 pOut += w/2;
3100 }
3101 }
3102}
3103
3104static void
3105ov51x_postprocess_grey(struct usb_ov511 *ov, struct ov511_frame *frame)
3106{
3107 /* Deinterlace frame, if necessary */
3108 if (ov->sensor == SEN_SAA7111A && frame->rawheight >= 480) {
3109 if (frame->compressed)
3110 decompress(ov, frame, frame->rawdata,
3111 frame->tempdata);
3112 else
3113 yuv400raw_to_yuv400p(frame, frame->rawdata,
3114 frame->tempdata);
3115
3116 deinterlace(frame, RAWFMT_YUV400, frame->tempdata,
3117 frame->data);
3118 } else {
3119 if (frame->compressed)
3120 decompress(ov, frame, frame->rawdata,
3121 frame->data);
3122 else
3123 yuv400raw_to_yuv400p(frame, frame->rawdata,
3124 frame->data);
3125 }
3126}
3127
3128/* Process raw YUV420 data into standard YUV420P */
3129static void
3130ov51x_postprocess_yuv420(struct usb_ov511 *ov, struct ov511_frame *frame)
3131{
3132 /* Deinterlace frame, if necessary */
3133 if (ov->sensor == SEN_SAA7111A && frame->rawheight >= 480) {
3134 if (frame->compressed)
3135 decompress(ov, frame, frame->rawdata, frame->tempdata);
3136 else
3137 yuv420raw_to_yuv420p(frame, frame->rawdata,
3138 frame->tempdata);
3139
3140 deinterlace(frame, RAWFMT_YUV420, frame->tempdata,
3141 frame->data);
3142 } else {
3143 if (frame->compressed)
3144 decompress(ov, frame, frame->rawdata, frame->data);
3145 else
3146 yuv420raw_to_yuv420p(frame, frame->rawdata,
3147 frame->data);
3148 }
3149}
3150
3151/* Post-processes the specified frame. This consists of:
3152 * 1. Decompress frame, if necessary
3153 * 2. Deinterlace frame and scale to proper size, if necessary
3154 * 3. Convert from YUV planar to destination format, if necessary
3155 * 4. Fix the RGB offset, if necessary
3156 */
3157static void
3158ov51x_postprocess(struct usb_ov511 *ov, struct ov511_frame *frame)
3159{
3160 if (dumppix) {
3161 memset(frame->data, 0,
3162 MAX_DATA_SIZE(ov->maxwidth, ov->maxheight));
3163 PDEBUG(4, "Dumping %d bytes", frame->bytes_recvd);
3164 memcpy(frame->data, frame->rawdata, frame->bytes_recvd);
3165 } else {
3166 switch (frame->format) {
3167 case VIDEO_PALETTE_GREY:
3168 ov51x_postprocess_grey(ov, frame);
3169 break;
3170 case VIDEO_PALETTE_YUV420:
3171 case VIDEO_PALETTE_YUV420P:
3172 ov51x_postprocess_yuv420(ov, frame);
3173 break;
3174 default:
3175 err("Cannot convert data to %s",
3176 symbolic(v4l1_plist, frame->format));
3177 }
3178 }
3179}
3180
3181/**********************************************************************
3182 *
3183 * OV51x data transfer, IRQ handler
3184 *
3185 **********************************************************************/
3186
3187static inline void
3188ov511_move_data(struct usb_ov511 *ov, unsigned char *in, int n)
3189{
3190 int num, offset;
3191 int pnum = in[ov->packet_size - 1]; /* Get packet number */
3192 int max_raw = MAX_RAW_DATA_SIZE(ov->maxwidth, ov->maxheight);
3193 struct ov511_frame *frame = &ov->frame[ov->curframe];
3194 struct timeval *ts;
3195
3196 /* SOF/EOF packets have 1st to 8th bytes zeroed and the 9th
3197 * byte non-zero. The EOF packet has image width/height in the
3198 * 10th and 11th bytes. The 9th byte is given as follows:
3199 *
3200 * bit 7: EOF
3201 * 6: compression enabled
3202 * 5: 422/420/400 modes
3203 * 4: 422/420/400 modes
3204 * 3: 1
3205 * 2: snapshot button on
3206 * 1: snapshot frame
3207 * 0: even/odd field
3208 */
3209
3210 if (printph) {
3211 dev_info(&ov->dev->dev,
3212 "ph(%3d): %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x\n",
3213 pnum, in[0], in[1], in[2], in[3], in[4], in[5], in[6],
3214 in[7], in[8], in[9], in[10], in[11]);
3215 }
3216
3217 /* Check for SOF/EOF packet */
3218 if ((in[0] | in[1] | in[2] | in[3] | in[4] | in[5] | in[6] | in[7]) ||
3219 (~in[8] & 0x08))
3220 goto check_middle;
3221
3222 /* Frame end */
3223 if (in[8] & 0x80) {
3224 ts = (struct timeval *)(frame->data
3225 + MAX_FRAME_SIZE(ov->maxwidth, ov->maxheight));
3226 do_gettimeofday(ts);
3227
3228 /* Get the actual frame size from the EOF header */
3229 frame->rawwidth = ((int)(in[9]) + 1) * 8;
3230 frame->rawheight = ((int)(in[10]) + 1) * 8;
3231
3232 PDEBUG(4, "Frame end, frame=%d, pnum=%d, w=%d, h=%d, recvd=%d",
3233 ov->curframe, pnum, frame->rawwidth, frame->rawheight,
3234 frame->bytes_recvd);
3235
3236 /* Validate the header data */
3237 RESTRICT_TO_RANGE(frame->rawwidth, ov->minwidth, ov->maxwidth);
3238 RESTRICT_TO_RANGE(frame->rawheight, ov->minheight,
3239 ov->maxheight);
3240
3241 /* Don't allow byte count to exceed buffer size */
3242 RESTRICT_TO_RANGE(frame->bytes_recvd, 8, max_raw);
3243
3244 if (frame->scanstate == STATE_LINES) {
3245 int nextf;
3246
3247 frame->grabstate = FRAME_DONE;
3248 wake_up_interruptible(&frame->wq);
3249
3250 /* If next frame is ready or grabbing,
3251 * point to it */
3252 nextf = (ov->curframe + 1) % OV511_NUMFRAMES;
3253 if (ov->frame[nextf].grabstate == FRAME_READY
3254 || ov->frame[nextf].grabstate == FRAME_GRABBING) {
3255 ov->curframe = nextf;
3256 ov->frame[nextf].scanstate = STATE_SCANNING;
3257 } else {
3258 if (frame->grabstate == FRAME_DONE) {
3259 PDEBUG(4, "** Frame done **");
3260 } else {
3261 PDEBUG(4, "Frame not ready? state = %d",
3262 ov->frame[nextf].grabstate);
3263 }
3264
3265 ov->curframe = -1;
3266 }
3267 } else {
3268 PDEBUG(5, "Frame done, but not scanning");
3269 }
3270 /* Image corruption caused by misplaced frame->segment = 0
3271 * fixed by carlosf@conectiva.com.br
3272 */
3273 } else {
3274 /* Frame start */
3275 PDEBUG(4, "Frame start, framenum = %d", ov->curframe);
3276
3277 /* Check to see if it's a snapshot frame */
3278 /* FIXME?? Should the snapshot reset go here? Performance? */
3279 if (in[8] & 0x02) {
3280 frame->snapshot = 1;
3281 PDEBUG(3, "snapshot detected");
3282 }
3283
3284 frame->scanstate = STATE_LINES;
3285 frame->bytes_recvd = 0;
3286 frame->compressed = in[8] & 0x40;
3287 }
3288
3289check_middle:
3290 /* Are we in a frame? */
3291 if (frame->scanstate != STATE_LINES) {
3292 PDEBUG(5, "Not in a frame; packet skipped");
3293 return;
3294 }
3295
3296 /* If frame start, skip header */
3297 if (frame->bytes_recvd == 0)
3298 offset = 9;
3299 else
3300 offset = 0;
3301
3302 num = n - offset - 1;
3303
3304 /* Dump all data exactly as received */
3305 if (dumppix == 2) {
3306 frame->bytes_recvd += n - 1;
3307 if (frame->bytes_recvd <= max_raw)
3308 memcpy(frame->rawdata + frame->bytes_recvd - (n - 1),
3309 in, n - 1);
3310 else
3311 PDEBUG(3, "Raw data buffer overrun!! (%d)",
3312 frame->bytes_recvd - max_raw);
3313 } else if (!frame->compressed && !remove_zeros) {
3314 frame->bytes_recvd += num;
3315 if (frame->bytes_recvd <= max_raw)
3316 memcpy(frame->rawdata + frame->bytes_recvd - num,
3317 in + offset, num);
3318 else
3319 PDEBUG(3, "Raw data buffer overrun!! (%d)",
3320 frame->bytes_recvd - max_raw);
3321 } else { /* Remove all-zero FIFO lines (aligned 32-byte blocks) */
3322 int b, read = 0, allzero, copied = 0;
3323 if (offset) {
3324 frame->bytes_recvd += 32 - offset; // Bytes out
3325 memcpy(frame->rawdata, in + offset, 32 - offset);
3326 read += 32;
3327 }
3328
3329 while (read < n - 1) {
3330 allzero = 1;
3331 for (b = 0; b < 32; b++) {
3332 if (in[read + b]) {
3333 allzero = 0;
3334 break;
3335 }
3336 }
3337
3338 if (allzero) {
3339 /* Don't copy it */
3340 } else {
3341 if (frame->bytes_recvd + copied + 32 <= max_raw)
3342 {
3343 memcpy(frame->rawdata
3344 + frame->bytes_recvd + copied,
3345 in + read, 32);
3346 copied += 32;
3347 } else {
3348 PDEBUG(3, "Raw data buffer overrun!!");
3349 }
3350 }
3351 read += 32;
3352 }
3353
3354 frame->bytes_recvd += copied;
3355 }
3356}
3357
3358static inline void
3359ov518_move_data(struct usb_ov511 *ov, unsigned char *in, int n)
3360{
3361 int max_raw = MAX_RAW_DATA_SIZE(ov->maxwidth, ov->maxheight);
3362 struct ov511_frame *frame = &ov->frame[ov->curframe];
3363 struct timeval *ts;
3364
3365 /* Don't copy the packet number byte */
3366 if (ov->packet_numbering)
3367 --n;
3368
3369 /* A false positive here is likely, until OVT gives me
3370 * the definitive SOF/EOF format */
3371 if ((!(in[0] | in[1] | in[2] | in[3] | in[5])) && in[6]) {
3372 if (printph) {
3373 dev_info(&ov->dev->dev,
3374 "ph: %2x %2x %2x %2x %2x %2x %2x %2x\n",
3375 in[0], in[1], in[2], in[3], in[4], in[5],
3376 in[6], in[7]);
3377 }
3378
3379 if (frame->scanstate == STATE_LINES) {
3380 PDEBUG(4, "Detected frame end/start");
3381 goto eof;
3382 } else { //scanstate == STATE_SCANNING
3383 /* Frame start */
3384 PDEBUG(4, "Frame start, framenum = %d", ov->curframe);
3385 goto sof;
3386 }
3387 } else {
3388 goto check_middle;
3389 }
3390
3391eof:
3392 ts = (struct timeval *)(frame->data
3393 + MAX_FRAME_SIZE(ov->maxwidth, ov->maxheight));
3394 do_gettimeofday(ts);
3395
3396 PDEBUG(4, "Frame end, curframe = %d, hw=%d, vw=%d, recvd=%d",
3397 ov->curframe,
3398 (int)(in[9]), (int)(in[10]), frame->bytes_recvd);
3399
3400 // FIXME: Since we don't know the header formats yet,
3401 // there is no way to know what the actual image size is
3402 frame->rawwidth = frame->width;
3403 frame->rawheight = frame->height;
3404
3405 /* Validate the header data */
3406 RESTRICT_TO_RANGE(frame->rawwidth, ov->minwidth, ov->maxwidth);
3407 RESTRICT_TO_RANGE(frame->rawheight, ov->minheight, ov->maxheight);
3408
3409 /* Don't allow byte count to exceed buffer size */
3410 RESTRICT_TO_RANGE(frame->bytes_recvd, 8, max_raw);
3411
3412 if (frame->scanstate == STATE_LINES) {
3413 int nextf;
3414
3415 frame->grabstate = FRAME_DONE;
3416 wake_up_interruptible(&frame->wq);
3417
3418 /* If next frame is ready or grabbing,
3419 * point to it */
3420 nextf = (ov->curframe + 1) % OV511_NUMFRAMES;
3421 if (ov->frame[nextf].grabstate == FRAME_READY
3422 || ov->frame[nextf].grabstate == FRAME_GRABBING) {
3423 ov->curframe = nextf;
3424 ov->frame[nextf].scanstate = STATE_SCANNING;
3425 frame = &ov->frame[nextf];
3426 } else {
3427 if (frame->grabstate == FRAME_DONE) {
3428 PDEBUG(4, "** Frame done **");
3429 } else {
3430 PDEBUG(4, "Frame not ready? state = %d",
3431 ov->frame[nextf].grabstate);
3432 }
3433
3434 ov->curframe = -1;
3435 PDEBUG(4, "SOF dropped (no active frame)");
3436 return; /* Nowhere to store this frame */
3437 }
3438 }
3439sof:
3440 PDEBUG(4, "Starting capture on frame %d", frame->framenum);
3441
3442// Snapshot not reverse-engineered yet.
3443#if 0
3444 /* Check to see if it's a snapshot frame */
3445 /* FIXME?? Should the snapshot reset go here? Performance? */
3446 if (in[8] & 0x02) {
3447 frame->snapshot = 1;
3448 PDEBUG(3, "snapshot detected");
3449 }
3450#endif
3451 frame->scanstate = STATE_LINES;
3452 frame->bytes_recvd = 0;
3453 frame->compressed = 1;
3454
3455check_middle:
3456 /* Are we in a frame? */
3457 if (frame->scanstate != STATE_LINES) {
3458 PDEBUG(4, "scanstate: no SOF yet");
3459 return;
3460 }
3461
3462 /* Dump all data exactly as received */
3463 if (dumppix == 2) {
3464 frame->bytes_recvd += n;
3465 if (frame->bytes_recvd <= max_raw)
3466 memcpy(frame->rawdata + frame->bytes_recvd - n, in, n);
3467 else
3468 PDEBUG(3, "Raw data buffer overrun!! (%d)",
3469 frame->bytes_recvd - max_raw);
3470 } else {
3471 /* All incoming data are divided into 8-byte segments. If the
3472 * segment contains all zero bytes, it must be skipped. These
3473 * zero-segments allow the OV518 to mainain a constant data rate
3474 * regardless of the effectiveness of the compression. Segments
3475 * are aligned relative to the beginning of each isochronous
3476 * packet. The first segment in each image is a header (the
3477 * decompressor skips it later).
3478 */
3479
3480 int b, read = 0, allzero, copied = 0;
3481
3482 while (read < n) {
3483 allzero = 1;
3484 for (b = 0; b < 8; b++) {
3485 if (in[read + b]) {
3486 allzero = 0;
3487 break;
3488 }
3489 }
3490
3491 if (allzero) {
3492 /* Don't copy it */
3493 } else {
3494 if (frame->bytes_recvd + copied + 8 <= max_raw)
3495 {
3496 memcpy(frame->rawdata
3497 + frame->bytes_recvd + copied,
3498 in + read, 8);
3499 copied += 8;
3500 } else {
3501 PDEBUG(3, "Raw data buffer overrun!!");
3502 }
3503 }
3504 read += 8;
3505 }
3506 frame->bytes_recvd += copied;
3507 }
3508}
3509
3510static void
3511ov51x_isoc_irq(struct urb *urb)
3512{
3513 int i;
3514 struct usb_ov511 *ov;
3515 struct ov511_sbuf *sbuf;
3516
3517 if (!urb->context) {
3518 PDEBUG(4, "no context");
3519 return;
3520 }
3521
3522 sbuf = urb->context;
3523 ov = sbuf->ov;
3524
3525 if (!ov || !ov->dev || !ov->user) {
3526 PDEBUG(4, "no device, or not open");
3527 return;
3528 }
3529
3530 if (!ov->streaming) {
3531 PDEBUG(4, "hmmm... not streaming, but got interrupt");
3532 return;
3533 }
3534
3535 if (urb->status == -ENOENT || urb->status == -ECONNRESET) {
3536 PDEBUG(4, "URB unlinked");
3537 return;
3538 }
3539
3540 if (urb->status != -EINPROGRESS && urb->status != 0) {
3541 err("ERROR: urb->status=%d: %s", urb->status,
3542 symbolic(urb_errlist, urb->status));
3543 }
3544
3545 /* Copy the data received into our frame buffer */
3546 PDEBUG(5, "sbuf[%d]: Moving %d packets", sbuf->n,
3547 urb->number_of_packets);
3548 for (i = 0; i < urb->number_of_packets; i++) {
3549 /* Warning: Don't call *_move_data() if no frame active! */
3550 if (ov->curframe >= 0) {
3551 int n = urb->iso_frame_desc[i].actual_length;
3552 int st = urb->iso_frame_desc[i].status;
3553 unsigned char *cdata;
3554
3555 urb->iso_frame_desc[i].actual_length = 0;
3556 urb->iso_frame_desc[i].status = 0;
3557
3558 cdata = urb->transfer_buffer
3559 + urb->iso_frame_desc[i].offset;
3560
3561 if (!n) {
3562 PDEBUG(4, "Zero-length packet");
3563 continue;
3564 }
3565
3566 if (st)
3567 PDEBUG(2, "data error: [%d] len=%d, status=%d",
3568 i, n, st);
3569
3570 if (ov->bclass == BCL_OV511)
3571 ov511_move_data(ov, cdata, n);
3572 else if (ov->bclass == BCL_OV518)
3573 ov518_move_data(ov, cdata, n);
3574 else
3575 err("Unknown bridge device (%d)", ov->bridge);
3576
3577 } else if (waitqueue_active(&ov->wq)) {
3578 wake_up_interruptible(&ov->wq);
3579 }
3580 }
3581
3582 /* Resubmit this URB */
3583 urb->dev = ov->dev;
3584 if ((i = usb_submit_urb(urb, GFP_ATOMIC)) != 0)
3585 err("usb_submit_urb() ret %d", i);
3586
3587 return;
3588}
3589
3590/****************************************************************************
3591 *
3592 * Stream initialization and termination
3593 *
3594 ***************************************************************************/
3595
3596static int
3597ov51x_init_isoc(struct usb_ov511 *ov)
3598{
3599 struct urb *urb;
3600 int fx, err, n, i, size;
3601
3602 PDEBUG(3, "*** Initializing capture ***");
3603
3604 ov->curframe = -1;
3605
3606 if (ov->bridge == BRG_OV511) {
3607 if (cams == 1)
3608 size = 993;
3609 else if (cams == 2)
3610 size = 513;
3611 else if (cams == 3 || cams == 4)
3612 size = 257;
3613 else {
3614 err("\"cams\" parameter too high!");
3615 return -1;
3616 }
3617 } else if (ov->bridge == BRG_OV511PLUS) {
3618 if (cams == 1)
3619 size = 961;
3620 else if (cams == 2)
3621 size = 513;
3622 else if (cams == 3 || cams == 4)
3623 size = 257;
3624 else if (cams >= 5 && cams <= 8)
3625 size = 129;
3626 else if (cams >= 9 && cams <= 31)
3627 size = 33;
3628 else {
3629 err("\"cams\" parameter too high!");
3630 return -1;
3631 }
3632 } else if (ov->bclass == BCL_OV518) {
3633 if (cams == 1)
3634 size = 896;
3635 else if (cams == 2)
3636 size = 512;
3637 else if (cams == 3 || cams == 4)
3638 size = 256;
3639 else if (cams >= 5 && cams <= 8)
3640 size = 128;
3641 else {
3642 err("\"cams\" parameter too high!");
3643 return -1;
3644 }
3645 } else {
3646 err("invalid bridge type");
3647 return -1;
3648 }
3649
3650 // FIXME: OV518 is hardcoded to 15 FPS (alternate 5) for now
3651 if (ov->bclass == BCL_OV518) {
3652 if (packetsize == -1) {
3653 ov518_set_packet_size(ov, 640);
3654 } else {
3655 dev_info(&ov->dev->dev, "Forcing packet size to %d\n",
3656 packetsize);
3657 ov518_set_packet_size(ov, packetsize);
3658 }
3659 } else {
3660 if (packetsize == -1) {
3661 ov511_set_packet_size(ov, size);
3662 } else {
3663 dev_info(&ov->dev->dev, "Forcing packet size to %d\n",
3664 packetsize);
3665 ov511_set_packet_size(ov, packetsize);
3666 }
3667 }
3668
3669 for (n = 0; n < OV511_NUMSBUF; n++) {
3670 urb = usb_alloc_urb(FRAMES_PER_DESC, GFP_KERNEL);
3671 if (!urb) {
3672 err("init isoc: usb_alloc_urb ret. NULL");
3673 for (i = 0; i < n; i++)
3674 usb_free_urb(ov->sbuf[i].urb);
3675 return -ENOMEM;
3676 }
3677 ov->sbuf[n].urb = urb;
3678 urb->dev = ov->dev;
3679 urb->context = &ov->sbuf[n];
3680 urb->pipe = usb_rcvisocpipe(ov->dev, OV511_ENDPOINT_ADDRESS);
3681 urb->transfer_flags = URB_ISO_ASAP;
3682 urb->transfer_buffer = ov->sbuf[n].data;
3683 urb->complete = ov51x_isoc_irq;
3684 urb->number_of_packets = FRAMES_PER_DESC;
3685 urb->transfer_buffer_length = ov->packet_size * FRAMES_PER_DESC;
3686 urb->interval = 1;
3687 for (fx = 0; fx < FRAMES_PER_DESC; fx++) {
3688 urb->iso_frame_desc[fx].offset = ov->packet_size * fx;
3689 urb->iso_frame_desc[fx].length = ov->packet_size;
3690 }
3691 }
3692
3693 ov->streaming = 1;
3694
3695 for (n = 0; n < OV511_NUMSBUF; n++) {
3696 ov->sbuf[n].urb->dev = ov->dev;
3697 err = usb_submit_urb(ov->sbuf[n].urb, GFP_KERNEL);
3698 if (err) {
3699 err("init isoc: usb_submit_urb(%d) ret %d", n, err);
3700 return err;
3701 }
3702 }
3703
3704 return 0;
3705}
3706
3707static void
3708ov51x_unlink_isoc(struct usb_ov511 *ov)
3709{
3710 int n;
3711
3712 /* Unschedule all of the iso td's */
3713 for (n = OV511_NUMSBUF - 1; n >= 0; n--) {
3714 if (ov->sbuf[n].urb) {
3715 usb_kill_urb(ov->sbuf[n].urb);
3716 usb_free_urb(ov->sbuf[n].urb);
3717 ov->sbuf[n].urb = NULL;
3718 }
3719 }
3720}
3721
3722static void
3723ov51x_stop_isoc(struct usb_ov511 *ov)
3724{
3725 if (!ov->streaming || !ov->dev)
3726 return;
3727
3728 PDEBUG(3, "*** Stopping capture ***");
3729
3730 if (ov->bclass == BCL_OV518)
3731 ov518_set_packet_size(ov, 0);
3732 else
3733 ov511_set_packet_size(ov, 0);
3734
3735 ov->streaming = 0;
3736
3737 ov51x_unlink_isoc(ov);
3738}
3739
3740static int
3741ov51x_new_frame(struct usb_ov511 *ov, int framenum)
3742{
3743 struct ov511_frame *frame;
3744 int newnum;
3745
3746 PDEBUG(4, "ov->curframe = %d, framenum = %d", ov->curframe, framenum);
3747
3748 if (!ov->dev)
3749 return -1;
3750
3751 /* If we're not grabbing a frame right now and the other frame is */
3752 /* ready to be grabbed into, then use it instead */
3753 if (ov->curframe == -1) {
3754 newnum = (framenum - 1 + OV511_NUMFRAMES) % OV511_NUMFRAMES;
3755 if (ov->frame[newnum].grabstate == FRAME_READY)
3756 framenum = newnum;
3757 } else
3758 return 0;
3759
3760 frame = &ov->frame[framenum];
3761
3762 PDEBUG(4, "framenum = %d, width = %d, height = %d", framenum,
3763 frame->width, frame->height);
3764
3765 frame->grabstate = FRAME_GRABBING;
3766 frame->scanstate = STATE_SCANNING;
3767 frame->snapshot = 0;
3768
3769 ov->curframe = framenum;
3770
3771 /* Make sure it's not too big */
3772 if (frame->width > ov->maxwidth)
3773 frame->width = ov->maxwidth;
3774
3775 frame->width &= ~7L; /* Multiple of 8 */
3776
3777 if (frame->height > ov->maxheight)
3778 frame->height = ov->maxheight;
3779
3780 frame->height &= ~3L; /* Multiple of 4 */
3781
3782 return 0;
3783}
3784
3785/****************************************************************************
3786 *
3787 * Buffer management
3788 *
3789 ***************************************************************************/
3790
3791/*
3792 * - You must acquire buf_lock before entering this function.
3793 * - Because this code will free any non-null pointer, you must be sure to null
3794 * them if you explicitly free them somewhere else!
3795 */
3796static void
3797ov51x_do_dealloc(struct usb_ov511 *ov)
3798{
3799 int i;
3800 PDEBUG(4, "entered");
3801
3802 if (ov->fbuf) {
3803 rvfree(ov->fbuf, OV511_NUMFRAMES
3804 * MAX_DATA_SIZE(ov->maxwidth, ov->maxheight));
3805 ov->fbuf = NULL;
3806 }
3807
3808 vfree(ov->rawfbuf);
3809 ov->rawfbuf = NULL;
3810
3811 vfree(ov->tempfbuf);
3812 ov->tempfbuf = NULL;
3813
3814 for (i = 0; i < OV511_NUMSBUF; i++) {
3815 kfree(ov->sbuf[i].data);
3816 ov->sbuf[i].data = NULL;
3817 }
3818
3819 for (i = 0; i < OV511_NUMFRAMES; i++) {
3820 ov->frame[i].data = NULL;
3821 ov->frame[i].rawdata = NULL;
3822 ov->frame[i].tempdata = NULL;
3823 if (ov->frame[i].compbuf) {
3824 free_page((unsigned long) ov->frame[i].compbuf);
3825 ov->frame[i].compbuf = NULL;
3826 }
3827 }
3828
3829 PDEBUG(4, "buffer memory deallocated");
3830 ov->buf_state = BUF_NOT_ALLOCATED;
3831 PDEBUG(4, "leaving");
3832}
3833
3834static int
3835ov51x_alloc(struct usb_ov511 *ov)
3836{
3837 int i;
3838 const int w = ov->maxwidth;
3839 const int h = ov->maxheight;
3840 const int data_bufsize = OV511_NUMFRAMES * MAX_DATA_SIZE(w, h);
3841 const int raw_bufsize = OV511_NUMFRAMES * MAX_RAW_DATA_SIZE(w, h);
3842
3843 PDEBUG(4, "entered");
3844 mutex_lock(&ov->buf_lock);
3845
3846 if (ov->buf_state == BUF_ALLOCATED)
3847 goto out;
3848
3849 ov->fbuf = rvmalloc(data_bufsize);
3850 if (!ov->fbuf)
3851 goto error;
3852
3853 ov->rawfbuf = vmalloc(raw_bufsize);
3854 if (!ov->rawfbuf)
3855 goto error;
3856
3857 memset(ov->rawfbuf, 0, raw_bufsize);
3858
3859 ov->tempfbuf = vmalloc(raw_bufsize);
3860 if (!ov->tempfbuf)
3861 goto error;
3862
3863 memset(ov->tempfbuf, 0, raw_bufsize);
3864
3865 for (i = 0; i < OV511_NUMSBUF; i++) {
3866 ov->sbuf[i].data = kmalloc(FRAMES_PER_DESC *
3867 MAX_FRAME_SIZE_PER_DESC, GFP_KERNEL);
3868 if (!ov->sbuf[i].data)
3869 goto error;
3870
3871 PDEBUG(4, "sbuf[%d] @ %p", i, ov->sbuf[i].data);
3872 }
3873
3874 for (i = 0; i < OV511_NUMFRAMES; i++) {
3875 ov->frame[i].data = ov->fbuf + i * MAX_DATA_SIZE(w, h);
3876 ov->frame[i].rawdata = ov->rawfbuf
3877 + i * MAX_RAW_DATA_SIZE(w, h);
3878 ov->frame[i].tempdata = ov->tempfbuf
3879 + i * MAX_RAW_DATA_SIZE(w, h);
3880
3881 ov->frame[i].compbuf =
3882 (unsigned char *) __get_free_page(GFP_KERNEL);
3883 if (!ov->frame[i].compbuf)
3884 goto error;
3885
3886 PDEBUG(4, "frame[%d] @ %p", i, ov->frame[i].data);
3887 }
3888
3889 ov->buf_state = BUF_ALLOCATED;
3890out:
3891 mutex_unlock(&ov->buf_lock);
3892 PDEBUG(4, "leaving");
3893 return 0;
3894error:
3895 ov51x_do_dealloc(ov);
3896 mutex_unlock(&ov->buf_lock);
3897 PDEBUG(4, "errored");
3898 return -ENOMEM;
3899}
3900
3901static void
3902ov51x_dealloc(struct usb_ov511 *ov)
3903{
3904 PDEBUG(4, "entered");
3905 mutex_lock(&ov->buf_lock);
3906 ov51x_do_dealloc(ov);
3907 mutex_unlock(&ov->buf_lock);
3908 PDEBUG(4, "leaving");
3909}
3910
3911/****************************************************************************
3912 *
3913 * V4L 1 API
3914 *
3915 ***************************************************************************/
3916
3917static int
3918ov51x_v4l1_open(struct file *file)
3919{
3920 struct video_device *vdev = video_devdata(file);
3921 struct usb_ov511 *ov = video_get_drvdata(vdev);
3922 int err, i;
3923
3924 PDEBUG(4, "opening");
3925
3926 mutex_lock(&ov->lock);
3927
3928 err = -EBUSY;
3929 if (ov->user)
3930 goto out;
3931
3932 ov->sub_flag = 0;
3933
3934 /* In case app doesn't set them... */
3935 err = ov51x_set_default_params(ov);
3936 if (err < 0)
3937 goto out;
3938
3939 /* Make sure frames are reset */
3940 for (i = 0; i < OV511_NUMFRAMES; i++) {
3941 ov->frame[i].grabstate = FRAME_UNUSED;
3942 ov->frame[i].bytes_read = 0;
3943 }
3944
3945 /* If compression is on, make sure now that a
3946 * decompressor can be loaded */
3947 if (ov->compress && !ov->decomp_ops) {
3948 err = request_decompressor(ov);
3949 if (err && !dumppix)
3950 goto out;
3951 }
3952
3953 err = ov51x_alloc(ov);
3954 if (err < 0)
3955 goto out;
3956
3957 err = ov51x_init_isoc(ov);
3958 if (err) {
3959 ov51x_dealloc(ov);
3960 goto out;
3961 }
3962
3963 ov->user++;
3964 file->private_data = vdev;
3965
3966 if (ov->led_policy == LED_AUTO)
3967 ov51x_led_control(ov, 1);
3968
3969out:
3970 mutex_unlock(&ov->lock);
3971 return err;
3972}
3973
3974static int
3975ov51x_v4l1_close(struct file *file)
3976{
3977 struct video_device *vdev = file->private_data;
3978 struct usb_ov511 *ov = video_get_drvdata(vdev);
3979
3980 PDEBUG(4, "ov511_close");
3981
3982 mutex_lock(&ov->lock);
3983
3984 ov->user--;
3985 ov51x_stop_isoc(ov);
3986
3987 if (ov->led_policy == LED_AUTO)
3988 ov51x_led_control(ov, 0);
3989
3990 if (ov->dev)
3991 ov51x_dealloc(ov);
3992
3993 mutex_unlock(&ov->lock);
3994
3995 /* Device unplugged while open. Only a minimum of unregistration is done
3996 * here; the disconnect callback already did the rest. */
3997 if (!ov->dev) {
3998 mutex_lock(&ov->cbuf_lock);
3999 kfree(ov->cbuf);
4000 ov->cbuf = NULL;
4001 mutex_unlock(&ov->cbuf_lock);
4002
4003 ov51x_dealloc(ov);
4004 kfree(ov);
4005 ov = NULL;
4006 }
4007
4008 file->private_data = NULL;
4009 return 0;
4010}
4011
4012/* Do not call this function directly! */
4013static long
4014ov51x_v4l1_ioctl_internal(struct file *file, unsigned int cmd, void *arg)
4015{
4016 struct video_device *vdev = file->private_data;
4017 struct usb_ov511 *ov = video_get_drvdata(vdev);
4018 PDEBUG(5, "IOCtl: 0x%X", cmd);
4019
4020 if (!ov->dev)
4021 return -EIO;
4022
4023 switch (cmd) {
4024 case VIDIOCGCAP:
4025 {
4026 struct video_capability *b = arg;
4027
4028 PDEBUG(4, "VIDIOCGCAP");
4029
4030 memset(b, 0, sizeof(struct video_capability));
4031 sprintf(b->name, "%s USB Camera",
4032 symbolic(brglist, ov->bridge));
4033 b->type = VID_TYPE_CAPTURE | VID_TYPE_SUBCAPTURE;
4034 b->channels = ov->num_inputs;
4035 b->audios = 0;
4036 b->maxwidth = ov->maxwidth;
4037 b->maxheight = ov->maxheight;
4038 b->minwidth = ov->minwidth;
4039 b->minheight = ov->minheight;
4040
4041 return 0;
4042 }
4043 case VIDIOCGCHAN:
4044 {
4045 struct video_channel *v = arg;
4046
4047 PDEBUG(4, "VIDIOCGCHAN");
4048
4049 if ((unsigned)(v->channel) >= ov->num_inputs) {
4050 err("Invalid channel (%d)", v->channel);
4051 return -EINVAL;
4052 }
4053
4054 v->norm = ov->norm;
4055 v->type = VIDEO_TYPE_CAMERA;
4056 v->flags = 0;
4057// v->flags |= (ov->has_decoder) ? VIDEO_VC_NORM : 0;
4058 v->tuners = 0;
4059 decoder_get_input_name(ov, v->channel, v->name);
4060
4061 return 0;
4062 }
4063 case VIDIOCSCHAN:
4064 {
4065 struct video_channel *v = arg;
4066 int err;
4067
4068 PDEBUG(4, "VIDIOCSCHAN");
4069
4070 /* Make sure it's not a camera */
4071 if (!ov->has_decoder) {
4072 if (v->channel == 0)
4073 return 0;
4074 else
4075 return -EINVAL;
4076 }
4077
4078 if (v->norm != VIDEO_MODE_PAL &&
4079 v->norm != VIDEO_MODE_NTSC &&
4080 v->norm != VIDEO_MODE_SECAM &&
4081 v->norm != VIDEO_MODE_AUTO) {
4082 err("Invalid norm (%d)", v->norm);
4083 return -EINVAL;
4084 }
4085
4086 if ((unsigned)(v->channel) >= ov->num_inputs) {
4087 err("Invalid channel (%d)", v->channel);
4088 return -EINVAL;
4089 }
4090
4091 err = decoder_set_input(ov, v->channel);
4092 if (err)
4093 return err;
4094
4095 err = decoder_set_norm(ov, v->norm);
4096 if (err)
4097 return err;
4098
4099 return 0;
4100 }
4101 case VIDIOCGPICT:
4102 {
4103 struct video_picture *p = arg;
4104
4105 PDEBUG(4, "VIDIOCGPICT");
4106
4107 memset(p, 0, sizeof(struct video_picture));
4108 if (sensor_get_picture(ov, p))
4109 return -EIO;
4110
4111 /* Can we get these from frame[0]? -claudio? */
4112 p->depth = ov->frame[0].depth;
4113 p->palette = ov->frame[0].format;
4114
4115 return 0;
4116 }
4117 case VIDIOCSPICT:
4118 {
4119 struct video_picture *p = arg;
4120 int i, rc;
4121
4122 PDEBUG(4, "VIDIOCSPICT");
4123
4124 if (!get_depth(p->palette))
4125 return -EINVAL;
4126
4127 if (sensor_set_picture(ov, p))
4128 return -EIO;
4129
4130 if (force_palette && p->palette != force_palette) {
4131 dev_info(&ov->dev->dev, "Palette rejected (%s)\n",
4132 symbolic(v4l1_plist, p->palette));
4133 return -EINVAL;
4134 }
4135
4136 // FIXME: Format should be independent of frames
4137 if (p->palette != ov->frame[0].format) {
4138 PDEBUG(4, "Detected format change");
4139
4140 rc = ov51x_wait_frames_inactive(ov);
4141 if (rc)
4142 return rc;
4143
4144 mode_init_regs(ov, ov->frame[0].width,
4145 ov->frame[0].height, p->palette, ov->sub_flag);
4146 }
4147
4148 PDEBUG(4, "Setting depth=%d, palette=%s",
4149 p->depth, symbolic(v4l1_plist, p->palette));
4150
4151 for (i = 0; i < OV511_NUMFRAMES; i++) {
4152 ov->frame[i].depth = p->depth;
4153 ov->frame[i].format = p->palette;
4154 }
4155
4156 return 0;
4157 }
4158 case VIDIOCGCAPTURE:
4159 {
4160 int *vf = arg;
4161
4162 PDEBUG(4, "VIDIOCGCAPTURE");
4163
4164 ov->sub_flag = *vf;
4165 return 0;
4166 }
4167 case VIDIOCSCAPTURE:
4168 {
4169 struct video_capture *vc = arg;
4170
4171 PDEBUG(4, "VIDIOCSCAPTURE");
4172
4173 if (vc->flags)
4174 return -EINVAL;
4175 if (vc->decimation)
4176 return -EINVAL;
4177
4178 vc->x &= ~3L;
4179 vc->y &= ~1L;
4180 vc->y &= ~31L;
4181
4182 if (vc->width == 0)
4183 vc->width = 32;
4184
4185 vc->height /= 16;
4186 vc->height *= 16;
4187 if (vc->height == 0)
4188 vc->height = 16;
4189
4190 ov->subx = vc->x;
4191 ov->suby = vc->y;
4192 ov->subw = vc->width;
4193 ov->subh = vc->height;
4194
4195 return 0;
4196 }
4197 case VIDIOCSWIN:
4198 {
4199 struct video_window *vw = arg;
4200 int i, rc;
4201
4202 PDEBUG(4, "VIDIOCSWIN: %dx%d", vw->width, vw->height);
4203
4204#if 0
4205 if (vw->flags)
4206 return -EINVAL;
4207 if (vw->clipcount)
4208 return -EINVAL;
4209 if (vw->height != ov->maxheight)
4210 return -EINVAL;
4211 if (vw->width != ov->maxwidth)
4212 return -EINVAL;
4213#endif
4214
4215 rc = ov51x_wait_frames_inactive(ov);
4216 if (rc)
4217 return rc;
4218
4219 rc = mode_init_regs(ov, vw->width, vw->height,
4220 ov->frame[0].format, ov->sub_flag);
4221 if (rc < 0)
4222 return rc;
4223
4224 for (i = 0; i < OV511_NUMFRAMES; i++) {
4225 ov->frame[i].width = vw->width;
4226 ov->frame[i].height = vw->height;
4227 }
4228
4229 return 0;
4230 }
4231 case VIDIOCGWIN:
4232 {
4233 struct video_window *vw = arg;
4234
4235 memset(vw, 0, sizeof(struct video_window));
4236 vw->x = 0; /* FIXME */
4237 vw->y = 0;
4238 vw->width = ov->frame[0].width;
4239 vw->height = ov->frame[0].height;
4240 vw->flags = 30;
4241
4242 PDEBUG(4, "VIDIOCGWIN: %dx%d", vw->width, vw->height);
4243
4244 return 0;
4245 }
4246 case VIDIOCGMBUF:
4247 {
4248 struct video_mbuf *vm = arg;
4249 int i;
4250
4251 PDEBUG(4, "VIDIOCGMBUF");
4252
4253 memset(vm, 0, sizeof(struct video_mbuf));
4254 vm->size = OV511_NUMFRAMES
4255 * MAX_DATA_SIZE(ov->maxwidth, ov->maxheight);
4256 vm->frames = OV511_NUMFRAMES;
4257
4258 vm->offsets[0] = 0;
4259 for (i = 1; i < OV511_NUMFRAMES; i++) {
4260 vm->offsets[i] = vm->offsets[i-1]
4261 + MAX_DATA_SIZE(ov->maxwidth, ov->maxheight);
4262 }
4263
4264 return 0;
4265 }
4266 case VIDIOCMCAPTURE:
4267 {
4268 struct video_mmap *vm = arg;
4269 int rc, depth;
4270 unsigned int f = vm->frame;
4271
4272 PDEBUG(4, "VIDIOCMCAPTURE: frame: %d, %dx%d, %s", f, vm->width,
4273 vm->height, symbolic(v4l1_plist, vm->format));
4274
4275 depth = get_depth(vm->format);
4276 if (!depth) {
4277 PDEBUG(2, "VIDIOCMCAPTURE: invalid format (%s)",
4278 symbolic(v4l1_plist, vm->format));
4279 return -EINVAL;
4280 }
4281
4282 if (f >= OV511_NUMFRAMES) {
4283 err("VIDIOCMCAPTURE: invalid frame (%d)", f);
4284 return -EINVAL;
4285 }
4286
4287 if (vm->width > ov->maxwidth
4288 || vm->height > ov->maxheight) {
4289 err("VIDIOCMCAPTURE: requested dimensions too big");
4290 return -EINVAL;
4291 }
4292
4293 if (ov->frame[f].grabstate == FRAME_GRABBING) {
4294 PDEBUG(4, "VIDIOCMCAPTURE: already grabbing");
4295 return -EBUSY;
4296 }
4297
4298 if (force_palette && (vm->format != force_palette)) {
4299 PDEBUG(2, "palette rejected (%s)",
4300 symbolic(v4l1_plist, vm->format));
4301 return -EINVAL;
4302 }
4303
4304 if ((ov->frame[f].width != vm->width) ||
4305 (ov->frame[f].height != vm->height) ||
4306 (ov->frame[f].format != vm->format) ||
4307 (ov->frame[f].sub_flag != ov->sub_flag) ||
4308 (ov->frame[f].depth != depth)) {
4309 PDEBUG(4, "VIDIOCMCAPTURE: change in image parameters");
4310
4311 rc = ov51x_wait_frames_inactive(ov);
4312 if (rc)
4313 return rc;
4314
4315 rc = mode_init_regs(ov, vm->width, vm->height,
4316 vm->format, ov->sub_flag);
4317#if 0
4318 if (rc < 0) {
4319 PDEBUG(1, "Got error while initializing regs ");
4320 return ret;
4321 }
4322#endif
4323 ov->frame[f].width = vm->width;
4324 ov->frame[f].height = vm->height;
4325 ov->frame[f].format = vm->format;
4326 ov->frame[f].sub_flag = ov->sub_flag;
4327 ov->frame[f].depth = depth;
4328 }
4329
4330 /* Mark it as ready */
4331 ov->frame[f].grabstate = FRAME_READY;
4332
4333 PDEBUG(4, "VIDIOCMCAPTURE: renewing frame %d", f);
4334
4335 return ov51x_new_frame(ov, f);
4336 }
4337 case VIDIOCSYNC:
4338 {
4339 unsigned int fnum = *((unsigned int *) arg);
4340 struct ov511_frame *frame;
4341 int rc;
4342
4343 if (fnum >= OV511_NUMFRAMES) {
4344 err("VIDIOCSYNC: invalid frame (%d)", fnum);
4345 return -EINVAL;
4346 }
4347
4348 frame = &ov->frame[fnum];
4349
4350 PDEBUG(4, "syncing to frame %d, grabstate = %d", fnum,
4351 frame->grabstate);
4352
4353 switch (frame->grabstate) {
4354 case FRAME_UNUSED:
4355 return -EINVAL;
4356 case FRAME_READY:
4357 case FRAME_GRABBING:
4358 case FRAME_ERROR:
4359redo:
4360 if (!ov->dev)
4361 return -EIO;
4362
4363 rc = wait_event_interruptible(frame->wq,
4364 (frame->grabstate == FRAME_DONE)
4365 || (frame->grabstate == FRAME_ERROR));
4366
4367 if (rc)
4368 return rc;
4369
4370 if (frame->grabstate == FRAME_ERROR) {
4371 if ((rc = ov51x_new_frame(ov, fnum)) < 0)
4372 return rc;
4373 goto redo;
4374 }
4375 /* Fall through */
4376 case FRAME_DONE:
4377 if (ov->snap_enabled && !frame->snapshot) {
4378 if ((rc = ov51x_new_frame(ov, fnum)) < 0)
4379 return rc;
4380 goto redo;
4381 }
4382
4383 frame->grabstate = FRAME_UNUSED;
4384
4385 /* Reset the hardware snapshot button */
4386 /* FIXME - Is this the best place for this? */
4387 if ((ov->snap_enabled) && (frame->snapshot)) {
4388 frame->snapshot = 0;
4389 ov51x_clear_snapshot(ov);
4390 }
4391
4392 /* Decompression, format conversion, etc... */
4393 ov51x_postprocess(ov, frame);
4394
4395 break;
4396 } /* end switch */
4397
4398 return 0;
4399 }
4400 case VIDIOCGFBUF:
4401 {
4402 struct video_buffer *vb = arg;
4403
4404 PDEBUG(4, "VIDIOCGFBUF");
4405
4406 memset(vb, 0, sizeof(struct video_buffer));
4407
4408 return 0;
4409 }
4410 case VIDIOCGUNIT:
4411 {
4412 struct video_unit *vu = arg;
4413
4414 PDEBUG(4, "VIDIOCGUNIT");
4415
4416 memset(vu, 0, sizeof(struct video_unit));
4417
4418 vu->video = ov->vdev->minor;
4419 vu->vbi = VIDEO_NO_UNIT;
4420 vu->radio = VIDEO_NO_UNIT;
4421 vu->audio = VIDEO_NO_UNIT;
4422 vu->teletext = VIDEO_NO_UNIT;
4423
4424 return 0;
4425 }
4426 case OV511IOC_WI2C:
4427 {
4428 struct ov511_i2c_struct *w = arg;
4429
4430 return i2c_w_slave(ov, w->slave, w->reg, w->value, w->mask);
4431 }
4432 case OV511IOC_RI2C:
4433 {
4434 struct ov511_i2c_struct *r = arg;
4435 int rc;
4436
4437 rc = i2c_r_slave(ov, r->slave, r->reg);
4438 if (rc < 0)
4439 return rc;
4440
4441 r->value = rc;
4442 return 0;
4443 }
4444 default:
4445 PDEBUG(3, "Unsupported IOCtl: 0x%X", cmd);
4446 return -ENOIOCTLCMD;
4447 } /* end switch */
4448
4449 return 0;
4450}
4451
4452static long
4453ov51x_v4l1_ioctl(struct file *file,
4454 unsigned int cmd, unsigned long arg)
4455{
4456 struct video_device *vdev = file->private_data;
4457 struct usb_ov511 *ov = video_get_drvdata(vdev);
4458 int rc;
4459
4460 if (mutex_lock_interruptible(&ov->lock))
4461 return -EINTR;
4462
4463 rc = video_usercopy(file, cmd, arg, ov51x_v4l1_ioctl_internal);
4464
4465 mutex_unlock(&ov->lock);
4466 return rc;
4467}
4468
4469static ssize_t
4470ov51x_v4l1_read(struct file *file, char __user *buf, size_t cnt, loff_t *ppos)
4471{
4472 struct video_device *vdev = file->private_data;
4473 int noblock = file->f_flags&O_NONBLOCK;
4474 unsigned long count = cnt;
4475 struct usb_ov511 *ov = video_get_drvdata(vdev);
4476 int i, rc = 0, frmx = -1;
4477 struct ov511_frame *frame;
4478
4479 if (mutex_lock_interruptible(&ov->lock))
4480 return -EINTR;
4481
4482 PDEBUG(4, "%ld bytes, noblock=%d", count, noblock);
4483
4484 if (!vdev || !buf) {
4485 rc = -EFAULT;
4486 goto error;
4487 }
4488
4489 if (!ov->dev) {
4490 rc = -EIO;
4491 goto error;
4492 }
4493
4494// FIXME: Only supports two frames
4495 /* See if a frame is completed, then use it. */
4496 if (ov->frame[0].grabstate >= FRAME_DONE) /* _DONE or _ERROR */
4497 frmx = 0;
4498 else if (ov->frame[1].grabstate >= FRAME_DONE)/* _DONE or _ERROR */
4499 frmx = 1;
4500
4501 /* If nonblocking we return immediately */
4502 if (noblock && (frmx == -1)) {
4503 rc = -EAGAIN;
4504 goto error;
4505 }
4506
4507 /* If no FRAME_DONE, look for a FRAME_GRABBING state. */
4508 /* See if a frame is in process (grabbing), then use it. */
4509 if (frmx == -1) {
4510 if (ov->frame[0].grabstate == FRAME_GRABBING)
4511 frmx = 0;
4512 else if (ov->frame[1].grabstate == FRAME_GRABBING)
4513 frmx = 1;
4514 }
4515
4516 /* If no frame is active, start one. */
4517 if (frmx == -1) {
4518 if ((rc = ov51x_new_frame(ov, frmx = 0))) {
4519 err("read: ov51x_new_frame error");
4520 goto error;
4521 }
4522 }
4523
4524 frame = &ov->frame[frmx];
4525
4526restart:
4527 if (!ov->dev) {
4528 rc = -EIO;
4529 goto error;
4530 }
4531
4532 /* Wait while we're grabbing the image */
4533 PDEBUG(4, "Waiting image grabbing");
4534 rc = wait_event_interruptible(frame->wq,
4535 (frame->grabstate == FRAME_DONE)
4536 || (frame->grabstate == FRAME_ERROR));
4537
4538 if (rc)
4539 goto error;
4540
4541 PDEBUG(4, "Got image, frame->grabstate = %d", frame->grabstate);
4542 PDEBUG(4, "bytes_recvd = %d", frame->bytes_recvd);
4543
4544 if (frame->grabstate == FRAME_ERROR) {
4545 frame->bytes_read = 0;
4546 err("** ick! ** Errored frame %d", ov->curframe);
4547 if (ov51x_new_frame(ov, frmx)) {
4548 err("read: ov51x_new_frame error");
4549 goto error;
4550 }
4551 goto restart;
4552 }
4553
4554
4555 /* Repeat until we get a snapshot frame */
4556 if (ov->snap_enabled)
4557 PDEBUG(4, "Waiting snapshot frame");
4558 if (ov->snap_enabled && !frame->snapshot) {
4559 frame->bytes_read = 0;
4560 if ((rc = ov51x_new_frame(ov, frmx))) {
4561 err("read: ov51x_new_frame error");
4562 goto error;
4563 }
4564 goto restart;
4565 }
4566
4567 /* Clear the snapshot */
4568 if (ov->snap_enabled && frame->snapshot) {
4569 frame->snapshot = 0;
4570 ov51x_clear_snapshot(ov);
4571 }
4572
4573 /* Decompression, format conversion, etc... */
4574 ov51x_postprocess(ov, frame);
4575
4576 PDEBUG(4, "frmx=%d, bytes_read=%ld, length=%ld", frmx,
4577 frame->bytes_read,
4578 get_frame_length(frame));
4579
4580 /* copy bytes to user space; we allow for partials reads */
4581// if ((count + frame->bytes_read)
4582// > get_frame_length((struct ov511_frame *)frame))
4583// count = frame->scanlength - frame->bytes_read;
4584
4585 /* FIXME - count hardwired to be one frame... */
4586 count = get_frame_length(frame);
4587
4588 PDEBUG(4, "Copy to user space: %ld bytes", count);
4589 if ((i = copy_to_user(buf, frame->data + frame->bytes_read, count))) {
4590 PDEBUG(4, "Copy failed! %d bytes not copied", i);
4591 rc = -EFAULT;
4592 goto error;
4593 }
4594
4595 frame->bytes_read += count;
4596 PDEBUG(4, "{copy} count used=%ld, new bytes_read=%ld",
4597 count, frame->bytes_read);
4598
4599 /* If all data have been read... */
4600 if (frame->bytes_read
4601 >= get_frame_length(frame)) {
4602 frame->bytes_read = 0;
4603
4604// FIXME: Only supports two frames
4605 /* Mark it as available to be used again. */
4606 ov->frame[frmx].grabstate = FRAME_UNUSED;
4607 if ((rc = ov51x_new_frame(ov, !frmx))) {
4608 err("ov51x_new_frame returned error");
4609 goto error;
4610 }
4611 }
4612
4613 PDEBUG(4, "read finished, returning %ld (sweet)", count);
4614
4615 mutex_unlock(&ov->lock);
4616 return count;
4617
4618error:
4619 mutex_unlock(&ov->lock);
4620 return rc;
4621}
4622
4623static int
4624ov51x_v4l1_mmap(struct file *file, struct vm_area_struct *vma)
4625{
4626 struct video_device *vdev = file->private_data;
4627 unsigned long start = vma->vm_start;
4628 unsigned long size = vma->vm_end - vma->vm_start;
4629 struct usb_ov511 *ov = video_get_drvdata(vdev);
4630 unsigned long page, pos;
4631
4632 if (ov->dev == NULL)
4633 return -EIO;
4634
4635 PDEBUG(4, "mmap: %ld (%lX) bytes", size, size);
4636
4637 if (size > (((OV511_NUMFRAMES
4638 * MAX_DATA_SIZE(ov->maxwidth, ov->maxheight)
4639 + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))))
4640 return -EINVAL;
4641
4642 if (mutex_lock_interruptible(&ov->lock))
4643 return -EINTR;
4644
4645 pos = (unsigned long)ov->fbuf;
4646 while (size > 0) {
4647 page = vmalloc_to_pfn((void *)pos);
4648 if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED)) {
4649 mutex_unlock(&ov->lock);
4650 return -EAGAIN;
4651 }
4652 start += PAGE_SIZE;
4653 pos += PAGE_SIZE;
4654 if (size > PAGE_SIZE)
4655 size -= PAGE_SIZE;
4656 else
4657 size = 0;
4658 }
4659
4660 mutex_unlock(&ov->lock);
4661 return 0;
4662}
4663
4664static const struct v4l2_file_operations ov511_fops = {
4665 .owner = THIS_MODULE,
4666 .open = ov51x_v4l1_open,
4667 .release = ov51x_v4l1_close,
4668 .read = ov51x_v4l1_read,
4669 .mmap = ov51x_v4l1_mmap,
4670 .ioctl = ov51x_v4l1_ioctl,
4671};
4672
4673static struct video_device vdev_template = {
4674 .name = "OV511 USB Camera",
4675 .fops = &ov511_fops,
4676 .release = video_device_release,
4677};
4678
4679/****************************************************************************
4680 *
4681 * OV511 and sensor configuration
4682 *
4683 ***************************************************************************/
4684
4685/* This initializes the OV7610, OV7620, or OV76BE sensor. The OV76BE uses
4686 * the same register settings as the OV7610, since they are very similar.
4687 */
4688static int
4689ov7xx0_configure(struct usb_ov511 *ov)
4690{
4691 int i, success;
4692 int rc;
4693
4694 /* Lawrence Glaister <lg@jfm.bc.ca> reports:
4695 *
4696 * Register 0x0f in the 7610 has the following effects:
4697 *
4698 * 0x85 (AEC method 1): Best overall, good contrast range
4699 * 0x45 (AEC method 2): Very overexposed
4700 * 0xa5 (spec sheet default): Ok, but the black level is
4701 * shifted resulting in loss of contrast
4702 * 0x05 (old driver setting): very overexposed, too much
4703 * contrast
4704 */
4705 static struct ov511_regvals aRegvalsNorm7610[] = {
4706 { OV511_I2C_BUS, 0x10, 0xff },
4707 { OV511_I2C_BUS, 0x16, 0x06 },
4708 { OV511_I2C_BUS, 0x28, 0x24 },
4709 { OV511_I2C_BUS, 0x2b, 0xac },
4710 { OV511_I2C_BUS, 0x12, 0x00 },
4711 { OV511_I2C_BUS, 0x38, 0x81 },
4712 { OV511_I2C_BUS, 0x28, 0x24 }, /* 0c */
4713 { OV511_I2C_BUS, 0x0f, 0x85 }, /* lg's setting */
4714 { OV511_I2C_BUS, 0x15, 0x01 },
4715 { OV511_I2C_BUS, 0x20, 0x1c },
4716 { OV511_I2C_BUS, 0x23, 0x2a },
4717 { OV511_I2C_BUS, 0x24, 0x10 },
4718 { OV511_I2C_BUS, 0x25, 0x8a },
4719 { OV511_I2C_BUS, 0x26, 0xa2 },
4720 { OV511_I2C_BUS, 0x27, 0xc2 },
4721 { OV511_I2C_BUS, 0x2a, 0x04 },
4722 { OV511_I2C_BUS, 0x2c, 0xfe },
4723 { OV511_I2C_BUS, 0x2d, 0x93 },
4724 { OV511_I2C_BUS, 0x30, 0x71 },
4725 { OV511_I2C_BUS, 0x31, 0x60 },
4726 { OV511_I2C_BUS, 0x32, 0x26 },
4727 { OV511_I2C_BUS, 0x33, 0x20 },
4728 { OV511_I2C_BUS, 0x34, 0x48 },
4729 { OV511_I2C_BUS, 0x12, 0x24 },
4730 { OV511_I2C_BUS, 0x11, 0x01 },
4731 { OV511_I2C_BUS, 0x0c, 0x24 },
4732 { OV511_I2C_BUS, 0x0d, 0x24 },
4733 { OV511_DONE_BUS, 0x0, 0x00 },
4734 };
4735
4736 static struct ov511_regvals aRegvalsNorm7620[] = {
4737 { OV511_I2C_BUS, 0x00, 0x00 },
4738 { OV511_I2C_BUS, 0x01, 0x80 },
4739 { OV511_I2C_BUS, 0x02, 0x80 },
4740 { OV511_I2C_BUS, 0x03, 0xc0 },
4741 { OV511_I2C_BUS, 0x06, 0x60 },
4742 { OV511_I2C_BUS, 0x07, 0x00 },
4743 { OV511_I2C_BUS, 0x0c, 0x24 },
4744 { OV511_I2C_BUS, 0x0c, 0x24 },
4745 { OV511_I2C_BUS, 0x0d, 0x24 },
4746 { OV511_I2C_BUS, 0x11, 0x01 },
4747 { OV511_I2C_BUS, 0x12, 0x24 },
4748 { OV511_I2C_BUS, 0x13, 0x01 },
4749 { OV511_I2C_BUS, 0x14, 0x84 },
4750 { OV511_I2C_BUS, 0x15, 0x01 },
4751 { OV511_I2C_BUS, 0x16, 0x03 },
4752 { OV511_I2C_BUS, 0x17, 0x2f },
4753 { OV511_I2C_BUS, 0x18, 0xcf },
4754 { OV511_I2C_BUS, 0x19, 0x06 },
4755 { OV511_I2C_BUS, 0x1a, 0xf5 },
4756 { OV511_I2C_BUS, 0x1b, 0x00 },
4757 { OV511_I2C_BUS, 0x20, 0x18 },
4758 { OV511_I2C_BUS, 0x21, 0x80 },
4759 { OV511_I2C_BUS, 0x22, 0x80 },
4760 { OV511_I2C_BUS, 0x23, 0x00 },
4761 { OV511_I2C_BUS, 0x26, 0xa2 },
4762 { OV511_I2C_BUS, 0x27, 0xea },
4763 { OV511_I2C_BUS, 0x28, 0x20 },
4764 { OV511_I2C_BUS, 0x29, 0x00 },
4765 { OV511_I2C_BUS, 0x2a, 0x10 },
4766 { OV511_I2C_BUS, 0x2b, 0x00 },
4767 { OV511_I2C_BUS, 0x2c, 0x88 },
4768 { OV511_I2C_BUS, 0x2d, 0x91 },
4769 { OV511_I2C_BUS, 0x2e, 0x80 },
4770 { OV511_I2C_BUS, 0x2f, 0x44 },
4771 { OV511_I2C_BUS, 0x60, 0x27 },
4772 { OV511_I2C_BUS, 0x61, 0x02 },
4773 { OV511_I2C_BUS, 0x62, 0x5f },
4774 { OV511_I2C_BUS, 0x63, 0xd5 },
4775 { OV511_I2C_BUS, 0x64, 0x57 },
4776 { OV511_I2C_BUS, 0x65, 0x83 },
4777 { OV511_I2C_BUS, 0x66, 0x55 },
4778 { OV511_I2C_BUS, 0x67, 0x92 },
4779 { OV511_I2C_BUS, 0x68, 0xcf },
4780 { OV511_I2C_BUS, 0x69, 0x76 },
4781 { OV511_I2C_BUS, 0x6a, 0x22 },
4782 { OV511_I2C_BUS, 0x6b, 0x00 },
4783 { OV511_I2C_BUS, 0x6c, 0x02 },
4784 { OV511_I2C_BUS, 0x6d, 0x44 },
4785 { OV511_I2C_BUS, 0x6e, 0x80 },
4786 { OV511_I2C_BUS, 0x6f, 0x1d },
4787 { OV511_I2C_BUS, 0x70, 0x8b },
4788 { OV511_I2C_BUS, 0x71, 0x00 },
4789 { OV511_I2C_BUS, 0x72, 0x14 },
4790 { OV511_I2C_BUS, 0x73, 0x54 },
4791 { OV511_I2C_BUS, 0x74, 0x00 },
4792 { OV511_I2C_BUS, 0x75, 0x8e },
4793 { OV511_I2C_BUS, 0x76, 0x00 },
4794 { OV511_I2C_BUS, 0x77, 0xff },
4795 { OV511_I2C_BUS, 0x78, 0x80 },
4796 { OV511_I2C_BUS, 0x79, 0x80 },
4797 { OV511_I2C_BUS, 0x7a, 0x80 },
4798 { OV511_I2C_BUS, 0x7b, 0xe2 },
4799 { OV511_I2C_BUS, 0x7c, 0x00 },
4800 { OV511_DONE_BUS, 0x0, 0x00 },
4801 };
4802
4803 PDEBUG(4, "starting configuration");
4804
4805 /* This looks redundant, but is necessary for WebCam 3 */
4806 ov->primary_i2c_slave = OV7xx0_SID;
4807 if (ov51x_set_slave_ids(ov, OV7xx0_SID) < 0)
4808 return -1;
4809
4810 if (init_ov_sensor(ov) >= 0) {
4811 PDEBUG(1, "OV7xx0 sensor initalized (method 1)");
4812 } else {
4813 /* Reset the 76xx */
4814 if (i2c_w(ov, 0x12, 0x80) < 0)
4815 return -1;
4816
4817 /* Wait for it to initialize */
4818 msleep(150);
4819
4820 i = 0;
4821 success = 0;
4822 while (i <= i2c_detect_tries) {
4823 if ((i2c_r(ov, OV7610_REG_ID_HIGH) == 0x7F) &&
4824 (i2c_r(ov, OV7610_REG_ID_LOW) == 0xA2)) {
4825 success = 1;
4826 break;
4827 } else {
4828 i++;
4829 }
4830 }
4831
4832// Was (i == i2c_detect_tries) previously. This obviously used to always report
4833// success. Whether anyone actually depended on that bug is unknown
4834 if ((i >= i2c_detect_tries) && (success == 0)) {
4835 err("Failed to read sensor ID. You might not have an");
4836 err("OV7610/20, or it may be not responding. Report");
4837 err("this to " EMAIL);
4838 err("This is only a warning. You can attempt to use");
4839 err("your camera anyway");
4840// Only issue a warning for now
4841// return -1;
4842 } else {
4843 PDEBUG(1, "OV7xx0 initialized (method 2, %dx)", i+1);
4844 }
4845 }
4846
4847 /* Detect sensor (sub)type */
4848 rc = i2c_r(ov, OV7610_REG_COM_I);
4849
4850 if (rc < 0) {
4851 err("Error detecting sensor type");
4852 return -1;
4853 } else if ((rc & 3) == 3) {
4854 dev_info(&ov->dev->dev, "Sensor is an OV7610\n");
4855 ov->sensor = SEN_OV7610;
4856 } else if ((rc & 3) == 1) {
4857 /* I don't know what's different about the 76BE yet. */
4858 if (i2c_r(ov, 0x15) & 1)
4859 dev_info(&ov->dev->dev, "Sensor is an OV7620AE\n");
4860 else
4861 dev_info(&ov->dev->dev, "Sensor is an OV76BE\n");
4862
4863 /* OV511+ will return all zero isoc data unless we
4864 * configure the sensor as a 7620. Someone needs to
4865 * find the exact reg. setting that causes this. */
4866 if (ov->bridge == BRG_OV511PLUS) {
4867 dev_info(&ov->dev->dev,
4868 "Enabling 511+/7620AE workaround\n");
4869 ov->sensor = SEN_OV7620;
4870 } else {
4871 ov->sensor = SEN_OV76BE;
4872 }
4873 } else if ((rc & 3) == 0) {
4874 dev_info(&ov->dev->dev, "Sensor is an OV7620\n");
4875 ov->sensor = SEN_OV7620;
4876 } else {
4877 err("Unknown image sensor version: %d", rc & 3);
4878 return -1;
4879 }
4880
4881 if (ov->sensor == SEN_OV7620) {
4882 PDEBUG(4, "Writing 7620 registers");
4883 if (write_regvals(ov, aRegvalsNorm7620))
4884 return -1;
4885 } else {
4886 PDEBUG(4, "Writing 7610 registers");
4887 if (write_regvals(ov, aRegvalsNorm7610))
4888 return -1;
4889 }
4890
4891 /* Set sensor-specific vars */
4892 ov->maxwidth = 640;
4893 ov->maxheight = 480;
4894 ov->minwidth = 64;
4895 ov->minheight = 48;
4896
4897 // FIXME: These do not match the actual settings yet
4898 ov->brightness = 0x80 << 8;
4899 ov->contrast = 0x80 << 8;
4900 ov->colour = 0x80 << 8;
4901 ov->hue = 0x80 << 8;
4902
4903 return 0;
4904}
4905
4906/* This initializes the OV6620, OV6630, OV6630AE, or OV6630AF sensor. */
4907static int
4908ov6xx0_configure(struct usb_ov511 *ov)
4909{
4910 int rc;
4911
4912 static struct ov511_regvals aRegvalsNorm6x20[] = {
4913 { OV511_I2C_BUS, 0x12, 0x80 }, /* reset */
4914 { OV511_I2C_BUS, 0x11, 0x01 },
4915 { OV511_I2C_BUS, 0x03, 0x60 },
4916 { OV511_I2C_BUS, 0x05, 0x7f }, /* For when autoadjust is off */
4917 { OV511_I2C_BUS, 0x07, 0xa8 },
4918 /* The ratio of 0x0c and 0x0d controls the white point */
4919 { OV511_I2C_BUS, 0x0c, 0x24 },
4920 { OV511_I2C_BUS, 0x0d, 0x24 },
4921 { OV511_I2C_BUS, 0x0f, 0x15 }, /* COMS */
4922 { OV511_I2C_BUS, 0x10, 0x75 }, /* AEC Exposure time */
4923 { OV511_I2C_BUS, 0x12, 0x24 }, /* Enable AGC */
4924 { OV511_I2C_BUS, 0x14, 0x04 },
4925 /* 0x16: 0x06 helps frame stability with moving objects */
4926 { OV511_I2C_BUS, 0x16, 0x06 },
4927// { OV511_I2C_BUS, 0x20, 0x30 }, /* Aperture correction enable */
4928 { OV511_I2C_BUS, 0x26, 0xb2 }, /* BLC enable */
4929 /* 0x28: 0x05 Selects RGB format if RGB on */
4930 { OV511_I2C_BUS, 0x28, 0x05 },
4931 { OV511_I2C_BUS, 0x2a, 0x04 }, /* Disable framerate adjust */
4932// { OV511_I2C_BUS, 0x2b, 0xac }, /* Framerate; Set 2a[7] first */
4933 { OV511_I2C_BUS, 0x2d, 0x99 },
4934 { OV511_I2C_BUS, 0x33, 0xa0 }, /* Color Processing Parameter */
4935 { OV511_I2C_BUS, 0x34, 0xd2 }, /* Max A/D range */
4936 { OV511_I2C_BUS, 0x38, 0x8b },
4937 { OV511_I2C_BUS, 0x39, 0x40 },
4938
4939 { OV511_I2C_BUS, 0x3c, 0x39 }, /* Enable AEC mode changing */
4940 { OV511_I2C_BUS, 0x3c, 0x3c }, /* Change AEC mode */
4941 { OV511_I2C_BUS, 0x3c, 0x24 }, /* Disable AEC mode changing */
4942
4943 { OV511_I2C_BUS, 0x3d, 0x80 },
4944 /* These next two registers (0x4a, 0x4b) are undocumented. They
4945 * control the color balance */
4946 { OV511_I2C_BUS, 0x4a, 0x80 },
4947 { OV511_I2C_BUS, 0x4b, 0x80 },
4948 { OV511_I2C_BUS, 0x4d, 0xd2 }, /* This reduces noise a bit */
4949 { OV511_I2C_BUS, 0x4e, 0xc1 },
4950 { OV511_I2C_BUS, 0x4f, 0x04 },
4951// Do 50-53 have any effect?
4952// Toggle 0x12[2] off and on here?
4953 { OV511_DONE_BUS, 0x0, 0x00 }, /* END MARKER */
4954 };
4955
4956 static struct ov511_regvals aRegvalsNorm6x30[] = {
4957 /*OK*/ { OV511_I2C_BUS, 0x12, 0x80 }, /* reset */
4958 { OV511_I2C_BUS, 0x11, 0x00 },
4959 /*OK*/ { OV511_I2C_BUS, 0x03, 0x60 },
4960 /*0A?*/ { OV511_I2C_BUS, 0x05, 0x7f }, /* For when autoadjust is off */
4961 { OV511_I2C_BUS, 0x07, 0xa8 },
4962 /* The ratio of 0x0c and 0x0d controls the white point */
4963 /*OK*/ { OV511_I2C_BUS, 0x0c, 0x24 },
4964 /*OK*/ { OV511_I2C_BUS, 0x0d, 0x24 },
4965 /*A*/ { OV511_I2C_BUS, 0x0e, 0x20 },
4966// /*04?*/ { OV511_I2C_BUS, 0x14, 0x80 },
4967 { OV511_I2C_BUS, 0x16, 0x03 },
4968// /*OK*/ { OV511_I2C_BUS, 0x20, 0x30 }, /* Aperture correction enable */
4969 // 21 & 22? The suggested values look wrong. Go with default
4970 /*A*/ { OV511_I2C_BUS, 0x23, 0xc0 },
4971 /*A*/ { OV511_I2C_BUS, 0x25, 0x9a }, // Check this against default
4972// /*OK*/ { OV511_I2C_BUS, 0x26, 0xb2 }, /* BLC enable */
4973
4974 /* 0x28: 0x05 Selects RGB format if RGB on */
4975// /*04?*/ { OV511_I2C_BUS, 0x28, 0x05 },
4976// /*04?*/ { OV511_I2C_BUS, 0x28, 0x45 }, // DEBUG: Tristate UV bus
4977
4978 /*OK*/ { OV511_I2C_BUS, 0x2a, 0x04 }, /* Disable framerate adjust */
4979// /*OK*/ { OV511_I2C_BUS, 0x2b, 0xac }, /* Framerate; Set 2a[7] first */
4980 { OV511_I2C_BUS, 0x2d, 0x99 },
4981// /*A*/ { OV511_I2C_BUS, 0x33, 0x26 }, // Reserved bits on 6620
4982// /*d2?*/ { OV511_I2C_BUS, 0x34, 0x03 }, /* Max A/D range */
4983// /*8b?*/ { OV511_I2C_BUS, 0x38, 0x83 },
4984// /*40?*/ { OV511_I2C_BUS, 0x39, 0xc0 }, // 6630 adds bit 7
4985// { OV511_I2C_BUS, 0x3c, 0x39 }, /* Enable AEC mode changing */
4986// { OV511_I2C_BUS, 0x3c, 0x3c }, /* Change AEC mode */
4987// { OV511_I2C_BUS, 0x3c, 0x24 }, /* Disable AEC mode changing */
4988 { OV511_I2C_BUS, 0x3d, 0x80 },
4989// /*A*/ { OV511_I2C_BUS, 0x3f, 0x0e },
4990
4991 /* These next two registers (0x4a, 0x4b) are undocumented. They
4992 * control the color balance */
4993// /*OK?*/ { OV511_I2C_BUS, 0x4a, 0x80 }, // Check these
4994// /*OK?*/ { OV511_I2C_BUS, 0x4b, 0x80 },
4995 { OV511_I2C_BUS, 0x4d, 0x10 }, /* U = 0.563u, V = 0.714v */
4996 /*c1?*/ { OV511_I2C_BUS, 0x4e, 0x40 },
4997
4998 /* UV average mode, color killer: strongest */
4999 { OV511_I2C_BUS, 0x4f, 0x07 },
5000
5001 { OV511_I2C_BUS, 0x54, 0x23 }, /* Max AGC gain: 18dB */
5002 { OV511_I2C_BUS, 0x57, 0x81 }, /* (default) */
5003 { OV511_I2C_BUS, 0x59, 0x01 }, /* AGC dark current comp: +1 */
5004 { OV511_I2C_BUS, 0x5a, 0x2c }, /* (undocumented) */
5005 { OV511_I2C_BUS, 0x5b, 0x0f }, /* AWB chrominance levels */
5006// { OV511_I2C_BUS, 0x5c, 0x10 },
5007 { OV511_DONE_BUS, 0x0, 0x00 }, /* END MARKER */
5008 };
5009
5010 PDEBUG(4, "starting sensor configuration");
5011
5012 if (init_ov_sensor(ov) < 0) {
5013 err("Failed to read sensor ID. You might not have an OV6xx0,");
5014 err("or it may be not responding. Report this to " EMAIL);
5015 return -1;
5016 } else {
5017 PDEBUG(1, "OV6xx0 sensor detected");
5018 }
5019
5020 /* Detect sensor (sub)type */
5021 rc = i2c_r(ov, OV7610_REG_COM_I);
5022
5023 if (rc < 0) {
5024 err("Error detecting sensor type");
5025 return -1;
5026 }
5027
5028 if ((rc & 3) == 0) {
5029 ov->sensor = SEN_OV6630;
5030 dev_info(&ov->dev->dev, "Sensor is an OV6630\n");
5031 } else if ((rc & 3) == 1) {
5032 ov->sensor = SEN_OV6620;
5033 dev_info(&ov->dev->dev, "Sensor is an OV6620\n");
5034 } else if ((rc & 3) == 2) {
5035 ov->sensor = SEN_OV6630;
5036 dev_info(&ov->dev->dev, "Sensor is an OV6630AE\n");
5037 } else if ((rc & 3) == 3) {
5038 ov->sensor = SEN_OV6630;
5039 dev_info(&ov->dev->dev, "Sensor is an OV6630AF\n");
5040 }
5041
5042 /* Set sensor-specific vars */
5043 ov->maxwidth = 352;
5044 ov->maxheight = 288;
5045 ov->minwidth = 64;
5046 ov->minheight = 48;
5047
5048 // FIXME: These do not match the actual settings yet
5049 ov->brightness = 0x80 << 8;
5050 ov->contrast = 0x80 << 8;
5051 ov->colour = 0x80 << 8;
5052 ov->hue = 0x80 << 8;
5053
5054 if (ov->sensor == SEN_OV6620) {
5055 PDEBUG(4, "Writing 6x20 registers");
5056 if (write_regvals(ov, aRegvalsNorm6x20))
5057 return -1;
5058 } else {
5059 PDEBUG(4, "Writing 6x30 registers");
5060 if (write_regvals(ov, aRegvalsNorm6x30))
5061 return -1;
5062 }
5063
5064 return 0;
5065}
5066
5067/* This initializes the KS0127 and KS0127B video decoders. */
5068static int
5069ks0127_configure(struct usb_ov511 *ov)
5070{
5071 int rc;
5072
5073// FIXME: I don't know how to sync or reset it yet
5074#if 0
5075 if (ov51x_init_ks_sensor(ov) < 0) {
5076 err("Failed to initialize the KS0127");
5077 return -1;
5078 } else {
5079 PDEBUG(1, "KS012x(B) sensor detected");
5080 }
5081#endif
5082
5083 /* Detect decoder subtype */
5084 rc = i2c_r(ov, 0x00);
5085 if (rc < 0) {
5086 err("Error detecting sensor type");
5087 return -1;
5088 } else if (rc & 0x08) {
5089 rc = i2c_r(ov, 0x3d);
5090 if (rc < 0) {
5091 err("Error detecting sensor type");
5092 return -1;
5093 } else if ((rc & 0x0f) == 0) {
5094 dev_info(&ov->dev->dev, "Sensor is a KS0127\n");
5095 ov->sensor = SEN_KS0127;
5096 } else if ((rc & 0x0f) == 9) {
5097 dev_info(&ov->dev->dev, "Sensor is a KS0127B Rev. A\n");
5098 ov->sensor = SEN_KS0127B;
5099 }
5100 } else {
5101 err("Error: Sensor is an unsupported KS0122");
5102 return -1;
5103 }
5104
5105 /* Set sensor-specific vars */
5106 ov->maxwidth = 640;
5107 ov->maxheight = 480;
5108 ov->minwidth = 64;
5109 ov->minheight = 48;
5110
5111 // FIXME: These do not match the actual settings yet
5112 ov->brightness = 0x80 << 8;
5113 ov->contrast = 0x80 << 8;
5114 ov->colour = 0x80 << 8;
5115 ov->hue = 0x80 << 8;
5116
5117 /* This device is not supported yet. Bail out now... */
5118 err("This sensor is not supported yet.");
5119 return -1;
5120
5121 return 0;
5122}
5123
5124/* This initializes the SAA7111A video decoder. */
5125static int
5126saa7111a_configure(struct usb_ov511 *ov)
5127{
5128 int rc;
5129
5130 /* Since there is no register reset command, all registers must be
5131 * written, otherwise gives erratic results */
5132 static struct ov511_regvals aRegvalsNormSAA7111A[] = {
5133 { OV511_I2C_BUS, 0x06, 0xce },
5134 { OV511_I2C_BUS, 0x07, 0x00 },
5135 { OV511_I2C_BUS, 0x10, 0x44 }, /* YUV422, 240/286 lines */
5136 { OV511_I2C_BUS, 0x0e, 0x01 }, /* NTSC M or PAL BGHI */
5137 { OV511_I2C_BUS, 0x00, 0x00 },
5138 { OV511_I2C_BUS, 0x01, 0x00 },
5139 { OV511_I2C_BUS, 0x03, 0x23 },
5140 { OV511_I2C_BUS, 0x04, 0x00 },
5141 { OV511_I2C_BUS, 0x05, 0x00 },
5142 { OV511_I2C_BUS, 0x08, 0xc8 }, /* Auto field freq */
5143 { OV511_I2C_BUS, 0x09, 0x01 }, /* Chrom. trap off, APER=0.25 */
5144 { OV511_I2C_BUS, 0x0a, 0x80 }, /* BRIG=128 */
5145 { OV511_I2C_BUS, 0x0b, 0x40 }, /* CONT=1.0 */
5146 { OV511_I2C_BUS, 0x0c, 0x40 }, /* SATN=1.0 */
5147 { OV511_I2C_BUS, 0x0d, 0x00 }, /* HUE=0 */
5148 { OV511_I2C_BUS, 0x0f, 0x00 },
5149 { OV511_I2C_BUS, 0x11, 0x0c },
5150 { OV511_I2C_BUS, 0x12, 0x00 },
5151 { OV511_I2C_BUS, 0x13, 0x00 },
5152 { OV511_I2C_BUS, 0x14, 0x00 },
5153 { OV511_I2C_BUS, 0x15, 0x00 },
5154 { OV511_I2C_BUS, 0x16, 0x00 },
5155 { OV511_I2C_BUS, 0x17, 0x00 },
5156 { OV511_I2C_BUS, 0x02, 0xc0 }, /* Composite input 0 */
5157 { OV511_DONE_BUS, 0x0, 0x00 },
5158 };
5159
5160// FIXME: I don't know how to sync or reset it yet
5161#if 0
5162 if (ov51x_init_saa_sensor(ov) < 0) {
5163 err("Failed to initialize the SAA7111A");
5164 return -1;
5165 } else {
5166 PDEBUG(1, "SAA7111A sensor detected");
5167 }
5168#endif
5169
5170 /* 640x480 not supported with PAL */
5171 if (ov->pal) {
5172 ov->maxwidth = 320;
5173 ov->maxheight = 240; /* Even field only */
5174 } else {
5175 ov->maxwidth = 640;
5176 ov->maxheight = 480; /* Even/Odd fields */
5177 }
5178
5179 ov->minwidth = 320;
5180 ov->minheight = 240; /* Even field only */
5181
5182 ov->has_decoder = 1;
5183 ov->num_inputs = 8;
5184 ov->norm = VIDEO_MODE_AUTO;
5185 ov->stop_during_set = 0; /* Decoder guarantees stable image */
5186
5187 /* Decoder doesn't change these values, so we use these instead of
5188 * acutally reading the registers (which doesn't work) */
5189 ov->brightness = 0x80 << 8;
5190 ov->contrast = 0x40 << 9;
5191 ov->colour = 0x40 << 9;
5192 ov->hue = 32768;
5193
5194 PDEBUG(4, "Writing SAA7111A registers");
5195 if (write_regvals(ov, aRegvalsNormSAA7111A))
5196 return -1;
5197
5198 /* Detect version of decoder. This must be done after writing the
5199 * initial regs or the decoder will lock up. */
5200 rc = i2c_r(ov, 0x00);
5201
5202 if (rc < 0) {
5203 err("Error detecting sensor version");
5204 return -1;
5205 } else {
5206 dev_info(&ov->dev->dev,
5207 "Sensor is an SAA7111A (version 0x%x)\n", rc);
5208 ov->sensor = SEN_SAA7111A;
5209 }
5210
5211 // FIXME: Fix this for OV518(+)
5212 /* Latch to negative edge of clock. Otherwise, we get incorrect
5213 * colors and jitter in the digital signal. */
5214 if (ov->bclass == BCL_OV511)
5215 reg_w(ov, 0x11, 0x00);
5216 else
5217 dev_warn(&ov->dev->dev,
5218 "SAA7111A not yet supported with OV518/OV518+\n");
5219
5220 return 0;
5221}
5222
5223/* This initializes the OV511/OV511+ and the sensor */
5224static int
5225ov511_configure(struct usb_ov511 *ov)
5226{
5227 static struct ov511_regvals aRegvalsInit511[] = {
5228 { OV511_REG_BUS, R51x_SYS_RESET, 0x7f },
5229 { OV511_REG_BUS, R51x_SYS_INIT, 0x01 },
5230 { OV511_REG_BUS, R51x_SYS_RESET, 0x7f },
5231 { OV511_REG_BUS, R51x_SYS_INIT, 0x01 },
5232 { OV511_REG_BUS, R51x_SYS_RESET, 0x3f },
5233 { OV511_REG_BUS, R51x_SYS_INIT, 0x01 },
5234 { OV511_REG_BUS, R51x_SYS_RESET, 0x3d },
5235 { OV511_DONE_BUS, 0x0, 0x00},
5236 };
5237
5238 static struct ov511_regvals aRegvalsNorm511[] = {
5239 { OV511_REG_BUS, R511_DRAM_FLOW_CTL, 0x01 },
5240 { OV511_REG_BUS, R51x_SYS_SNAP, 0x00 },
5241 { OV511_REG_BUS, R51x_SYS_SNAP, 0x02 },
5242 { OV511_REG_BUS, R51x_SYS_SNAP, 0x00 },
5243 { OV511_REG_BUS, R511_FIFO_OPTS, 0x1f },
5244 { OV511_REG_BUS, R511_COMP_EN, 0x00 },
5245 { OV511_REG_BUS, R511_COMP_LUT_EN, 0x03 },
5246 { OV511_DONE_BUS, 0x0, 0x00 },
5247 };
5248
5249 static struct ov511_regvals aRegvalsNorm511Plus[] = {
5250 { OV511_REG_BUS, R511_DRAM_FLOW_CTL, 0xff },
5251 { OV511_REG_BUS, R51x_SYS_SNAP, 0x00 },
5252 { OV511_REG_BUS, R51x_SYS_SNAP, 0x02 },
5253 { OV511_REG_BUS, R51x_SYS_SNAP, 0x00 },
5254 { OV511_REG_BUS, R511_FIFO_OPTS, 0xff },
5255 { OV511_REG_BUS, R511_COMP_EN, 0x00 },
5256 { OV511_REG_BUS, R511_COMP_LUT_EN, 0x03 },
5257 { OV511_DONE_BUS, 0x0, 0x00 },
5258 };
5259
5260 PDEBUG(4, "");
5261
5262 ov->customid = reg_r(ov, R511_SYS_CUST_ID);
5263 if (ov->customid < 0) {
5264 err("Unable to read camera bridge registers");
5265 goto error;
5266 }
5267
5268 PDEBUG (1, "CustomID = %d", ov->customid);
5269 ov->desc = symbolic(camlist, ov->customid);
5270 dev_info(&ov->dev->dev, "model: %s\n", ov->desc);
5271
5272 if (0 == strcmp(ov->desc, NOT_DEFINED_STR)) {
5273 err("Camera type (%d) not recognized", ov->customid);
5274 err("Please notify " EMAIL " of the name,");
5275 err("manufacturer, model, and this number of your camera.");
5276 err("Also include the output of the detection process.");
5277 }
5278
5279 if (ov->customid == 70) /* USB Life TV (PAL/SECAM) */
5280 ov->pal = 1;
5281
5282 if (write_regvals(ov, aRegvalsInit511))
5283 goto error;
5284
5285 if (ov->led_policy == LED_OFF || ov->led_policy == LED_AUTO)
5286 ov51x_led_control(ov, 0);
5287
5288 /* The OV511+ has undocumented bits in the flow control register.
5289 * Setting it to 0xff fixes the corruption with moving objects. */
5290 if (ov->bridge == BRG_OV511) {
5291 if (write_regvals(ov, aRegvalsNorm511))
5292 goto error;
5293 } else if (ov->bridge == BRG_OV511PLUS) {
5294 if (write_regvals(ov, aRegvalsNorm511Plus))
5295 goto error;
5296 } else {
5297 err("Invalid bridge");
5298 }
5299
5300 if (ov511_init_compression(ov))
5301 goto error;
5302
5303 ov->packet_numbering = 1;
5304 ov511_set_packet_size(ov, 0);
5305
5306 ov->snap_enabled = snapshot;
5307
5308 /* Test for 7xx0 */
5309 PDEBUG(3, "Testing for 0V7xx0");
5310 ov->primary_i2c_slave = OV7xx0_SID;
5311 if (ov51x_set_slave_ids(ov, OV7xx0_SID) < 0)
5312 goto error;
5313
5314 if (i2c_w(ov, 0x12, 0x80) < 0) {
5315 /* Test for 6xx0 */
5316 PDEBUG(3, "Testing for 0V6xx0");
5317 ov->primary_i2c_slave = OV6xx0_SID;
5318 if (ov51x_set_slave_ids(ov, OV6xx0_SID) < 0)
5319 goto error;
5320
5321 if (i2c_w(ov, 0x12, 0x80) < 0) {
5322 /* Test for 8xx0 */
5323 PDEBUG(3, "Testing for 0V8xx0");
5324 ov->primary_i2c_slave = OV8xx0_SID;
5325 if (ov51x_set_slave_ids(ov, OV8xx0_SID) < 0)
5326 goto error;
5327
5328 if (i2c_w(ov, 0x12, 0x80) < 0) {
5329 /* Test for SAA7111A */
5330 PDEBUG(3, "Testing for SAA7111A");
5331 ov->primary_i2c_slave = SAA7111A_SID;
5332 if (ov51x_set_slave_ids(ov, SAA7111A_SID) < 0)
5333 goto error;
5334
5335 if (i2c_w(ov, 0x0d, 0x00) < 0) {
5336 /* Test for KS0127 */
5337 PDEBUG(3, "Testing for KS0127");
5338 ov->primary_i2c_slave = KS0127_SID;
5339 if (ov51x_set_slave_ids(ov, KS0127_SID) < 0)
5340 goto error;
5341
5342 if (i2c_w(ov, 0x10, 0x00) < 0) {
5343 err("Can't determine sensor slave IDs");
5344 goto error;
5345 } else {
5346 if (ks0127_configure(ov) < 0) {
5347 err("Failed to configure KS0127");
5348 goto error;
5349 }
5350 }
5351 } else {
5352 if (saa7111a_configure(ov) < 0) {
5353 err("Failed to configure SAA7111A");
5354 goto error;
5355 }
5356 }
5357 } else {
5358 err("Detected unsupported OV8xx0 sensor");
5359 goto error;
5360 }
5361 } else {
5362 if (ov6xx0_configure(ov) < 0) {
5363 err("Failed to configure OV6xx0");
5364 goto error;
5365 }
5366 }
5367 } else {
5368 if (ov7xx0_configure(ov) < 0) {
5369 err("Failed to configure OV7xx0");
5370 goto error;
5371 }
5372 }
5373
5374 return 0;
5375
5376error:
5377 err("OV511 Config failed");
5378
5379 return -EBUSY;
5380}
5381
5382/* This initializes the OV518/OV518+ and the sensor */
5383static int
5384ov518_configure(struct usb_ov511 *ov)
5385{
5386 /* For 518 and 518+ */
5387 static struct ov511_regvals aRegvalsInit518[] = {
5388 { OV511_REG_BUS, R51x_SYS_RESET, 0x40 },
5389 { OV511_REG_BUS, R51x_SYS_INIT, 0xe1 },
5390 { OV511_REG_BUS, R51x_SYS_RESET, 0x3e },
5391 { OV511_REG_BUS, R51x_SYS_INIT, 0xe1 },
5392 { OV511_REG_BUS, R51x_SYS_RESET, 0x00 },
5393 { OV511_REG_BUS, R51x_SYS_INIT, 0xe1 },
5394 { OV511_REG_BUS, 0x46, 0x00 },
5395 { OV511_REG_BUS, 0x5d, 0x03 },
5396 { OV511_DONE_BUS, 0x0, 0x00},
5397 };
5398
5399 static struct ov511_regvals aRegvalsNorm518[] = {
5400 { OV511_REG_BUS, R51x_SYS_SNAP, 0x02 }, /* Reset */
5401 { OV511_REG_BUS, R51x_SYS_SNAP, 0x01 }, /* Enable */
5402 { OV511_REG_BUS, 0x31, 0x0f },
5403 { OV511_REG_BUS, 0x5d, 0x03 },
5404 { OV511_REG_BUS, 0x24, 0x9f },
5405 { OV511_REG_BUS, 0x25, 0x90 },
5406 { OV511_REG_BUS, 0x20, 0x00 },
5407 { OV511_REG_BUS, 0x51, 0x04 },
5408 { OV511_REG_BUS, 0x71, 0x19 },
5409 { OV511_DONE_BUS, 0x0, 0x00 },
5410 };
5411
5412 static struct ov511_regvals aRegvalsNorm518Plus[] = {
5413 { OV511_REG_BUS, R51x_SYS_SNAP, 0x02 }, /* Reset */
5414 { OV511_REG_BUS, R51x_SYS_SNAP, 0x01 }, /* Enable */
5415 { OV511_REG_BUS, 0x31, 0x0f },
5416 { OV511_REG_BUS, 0x5d, 0x03 },
5417 { OV511_REG_BUS, 0x24, 0x9f },
5418 { OV511_REG_BUS, 0x25, 0x90 },
5419 { OV511_REG_BUS, 0x20, 0x60 },
5420 { OV511_REG_BUS, 0x51, 0x02 },
5421 { OV511_REG_BUS, 0x71, 0x19 },
5422 { OV511_REG_BUS, 0x40, 0xff },
5423 { OV511_REG_BUS, 0x41, 0x42 },
5424 { OV511_REG_BUS, 0x46, 0x00 },
5425 { OV511_REG_BUS, 0x33, 0x04 },
5426 { OV511_REG_BUS, 0x21, 0x19 },
5427 { OV511_REG_BUS, 0x3f, 0x10 },
5428 { OV511_DONE_BUS, 0x0, 0x00 },
5429 };
5430
5431 PDEBUG(4, "");
5432
5433 /* First 5 bits of custom ID reg are a revision ID on OV518 */
5434 dev_info(&ov->dev->dev, "Device revision %d\n",
5435 0x1F & reg_r(ov, R511_SYS_CUST_ID));
5436
5437 /* Give it the default description */
5438 ov->desc = symbolic(camlist, 0);
5439
5440 if (write_regvals(ov, aRegvalsInit518))
5441 goto error;
5442
5443 /* Set LED GPIO pin to output mode */
5444 if (reg_w_mask(ov, 0x57, 0x00, 0x02) < 0)
5445 goto error;
5446
5447 /* LED is off by default with OV518; have to explicitly turn it on */
5448 if (ov->led_policy == LED_OFF || ov->led_policy == LED_AUTO)
5449 ov51x_led_control(ov, 0);
5450 else
5451 ov51x_led_control(ov, 1);
5452
5453 /* Don't require compression if dumppix is enabled; otherwise it's
5454 * required. OV518 has no uncompressed mode, to save RAM. */
5455 if (!dumppix && !ov->compress) {
5456 ov->compress = 1;
5457 dev_warn(&ov->dev->dev,
5458 "Compression required with OV518...enabling\n");
5459 }
5460
5461 if (ov->bridge == BRG_OV518) {
5462 if (write_regvals(ov, aRegvalsNorm518))
5463 goto error;
5464 } else if (ov->bridge == BRG_OV518PLUS) {
5465 if (write_regvals(ov, aRegvalsNorm518Plus))
5466 goto error;
5467 } else {
5468 err("Invalid bridge");
5469 }
5470
5471 if (reg_w(ov, 0x2f, 0x80) < 0)
5472 goto error;
5473
5474 if (ov518_init_compression(ov))
5475 goto error;
5476
5477 if (ov->bridge == BRG_OV518)
5478 {
5479 struct usb_interface *ifp;
5480 struct usb_host_interface *alt;
5481 __u16 mxps = 0;
5482
5483 ifp = usb_ifnum_to_if(ov->dev, 0);
5484 if (ifp) {
5485 alt = usb_altnum_to_altsetting(ifp, 7);
5486 if (alt)
5487 mxps = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize);
5488 }
5489
5490 /* Some OV518s have packet numbering by default, some don't */
5491 if (mxps == 897)
5492 ov->packet_numbering = 1;
5493 else
5494 ov->packet_numbering = 0;
5495 } else {
5496 /* OV518+ has packet numbering turned on by default */
5497 ov->packet_numbering = 1;
5498 }
5499
5500 ov518_set_packet_size(ov, 0);
5501
5502 ov->snap_enabled = snapshot;
5503
5504 /* Test for 76xx */
5505 ov->primary_i2c_slave = OV7xx0_SID;
5506 if (ov51x_set_slave_ids(ov, OV7xx0_SID) < 0)
5507 goto error;
5508
5509 /* The OV518 must be more aggressive about sensor detection since
5510 * I2C write will never fail if the sensor is not present. We have
5511 * to try to initialize the sensor to detect its presence */
5512
5513 if (init_ov_sensor(ov) < 0) {
5514 /* Test for 6xx0 */
5515 ov->primary_i2c_slave = OV6xx0_SID;
5516 if (ov51x_set_slave_ids(ov, OV6xx0_SID) < 0)
5517 goto error;
5518
5519 if (init_ov_sensor(ov) < 0) {
5520 /* Test for 8xx0 */
5521 ov->primary_i2c_slave = OV8xx0_SID;
5522 if (ov51x_set_slave_ids(ov, OV8xx0_SID) < 0)
5523 goto error;
5524
5525 if (init_ov_sensor(ov) < 0) {
5526 err("Can't determine sensor slave IDs");
5527 goto error;
5528 } else {
5529 err("Detected unsupported OV8xx0 sensor");
5530 goto error;
5531 }
5532 } else {
5533 if (ov6xx0_configure(ov) < 0) {
5534 err("Failed to configure OV6xx0");
5535 goto error;
5536 }
5537 }
5538 } else {
5539 if (ov7xx0_configure(ov) < 0) {
5540 err("Failed to configure OV7xx0");
5541 goto error;
5542 }
5543 }
5544
5545 ov->maxwidth = 352;
5546 ov->maxheight = 288;
5547
5548 // The OV518 cannot go as low as the sensor can
5549 ov->minwidth = 160;
5550 ov->minheight = 120;
5551
5552 return 0;
5553
5554error:
5555 err("OV518 Config failed");
5556
5557 return -EBUSY;
5558}
5559
5560/****************************************************************************
5561 * sysfs
5562 ***************************************************************************/
5563
5564static inline struct usb_ov511 *cd_to_ov(struct device *cd)
5565{
5566 struct video_device *vdev = to_video_device(cd);
5567 return video_get_drvdata(vdev);
5568}
5569
5570static ssize_t show_custom_id(struct device *cd,
5571 struct device_attribute *attr, char *buf)
5572{
5573 struct usb_ov511 *ov = cd_to_ov(cd);
5574 return sprintf(buf, "%d\n", ov->customid);
5575}
5576static DEVICE_ATTR(custom_id, S_IRUGO, show_custom_id, NULL);
5577
5578static ssize_t show_model(struct device *cd,
5579 struct device_attribute *attr, char *buf)
5580{
5581 struct usb_ov511 *ov = cd_to_ov(cd);
5582 return sprintf(buf, "%s\n", ov->desc);
5583}
5584static DEVICE_ATTR(model, S_IRUGO, show_model, NULL);
5585
5586static ssize_t show_bridge(struct device *cd,
5587 struct device_attribute *attr, char *buf)
5588{
5589 struct usb_ov511 *ov = cd_to_ov(cd);
5590 return sprintf(buf, "%s\n", symbolic(brglist, ov->bridge));
5591}
5592static DEVICE_ATTR(bridge, S_IRUGO, show_bridge, NULL);
5593
5594static ssize_t show_sensor(struct device *cd,
5595 struct device_attribute *attr, char *buf)
5596{
5597 struct usb_ov511 *ov = cd_to_ov(cd);
5598 return sprintf(buf, "%s\n", symbolic(senlist, ov->sensor));
5599}
5600static DEVICE_ATTR(sensor, S_IRUGO, show_sensor, NULL);
5601
5602static ssize_t show_brightness(struct device *cd,
5603 struct device_attribute *attr, char *buf)
5604{
5605 struct usb_ov511 *ov = cd_to_ov(cd);
5606 unsigned short x;
5607
5608 if (!ov->dev)
5609 return -ENODEV;
5610 sensor_get_brightness(ov, &x);
5611 return sprintf(buf, "%d\n", x >> 8);
5612}
5613static DEVICE_ATTR(brightness, S_IRUGO, show_brightness, NULL);
5614
5615static ssize_t show_saturation(struct device *cd,
5616 struct device_attribute *attr, char *buf)
5617{
5618 struct usb_ov511 *ov = cd_to_ov(cd);
5619 unsigned short x;
5620
5621 if (!ov->dev)
5622 return -ENODEV;
5623 sensor_get_saturation(ov, &x);
5624 return sprintf(buf, "%d\n", x >> 8);
5625}
5626static DEVICE_ATTR(saturation, S_IRUGO, show_saturation, NULL);
5627
5628static ssize_t show_contrast(struct device *cd,
5629 struct device_attribute *attr, char *buf)
5630{
5631 struct usb_ov511 *ov = cd_to_ov(cd);
5632 unsigned short x;
5633
5634 if (!ov->dev)
5635 return -ENODEV;
5636 sensor_get_contrast(ov, &x);
5637 return sprintf(buf, "%d\n", x >> 8);
5638}
5639static DEVICE_ATTR(contrast, S_IRUGO, show_contrast, NULL);
5640
5641static ssize_t show_hue(struct device *cd,
5642 struct device_attribute *attr, char *buf)
5643{
5644 struct usb_ov511 *ov = cd_to_ov(cd);
5645 unsigned short x;
5646
5647 if (!ov->dev)
5648 return -ENODEV;
5649 sensor_get_hue(ov, &x);
5650 return sprintf(buf, "%d\n", x >> 8);
5651}
5652static DEVICE_ATTR(hue, S_IRUGO, show_hue, NULL);
5653
5654static ssize_t show_exposure(struct device *cd,
5655 struct device_attribute *attr, char *buf)
5656{
5657 struct usb_ov511 *ov = cd_to_ov(cd);
5658 unsigned char exp = 0;
5659
5660 if (!ov->dev)
5661 return -ENODEV;
5662 sensor_get_exposure(ov, &exp);
5663 return sprintf(buf, "%d\n", exp);
5664}
5665static DEVICE_ATTR(exposure, S_IRUGO, show_exposure, NULL);
5666
5667static int ov_create_sysfs(struct video_device *vdev)
5668{
5669 int rc;
5670
5671 rc = device_create_file(&vdev->dev, &dev_attr_custom_id);
5672 if (rc) goto err;
5673 rc = device_create_file(&vdev->dev, &dev_attr_model);
5674 if (rc) goto err_id;
5675 rc = device_create_file(&vdev->dev, &dev_attr_bridge);
5676 if (rc) goto err_model;
5677 rc = device_create_file(&vdev->dev, &dev_attr_sensor);
5678 if (rc) goto err_bridge;
5679 rc = device_create_file(&vdev->dev, &dev_attr_brightness);
5680 if (rc) goto err_sensor;
5681 rc = device_create_file(&vdev->dev, &dev_attr_saturation);
5682 if (rc) goto err_bright;
5683 rc = device_create_file(&vdev->dev, &dev_attr_contrast);
5684 if (rc) goto err_sat;
5685 rc = device_create_file(&vdev->dev, &dev_attr_hue);
5686 if (rc) goto err_contrast;
5687 rc = device_create_file(&vdev->dev, &dev_attr_exposure);
5688 if (rc) goto err_hue;
5689
5690 return 0;
5691
5692err_hue:
5693 device_remove_file(&vdev->dev, &dev_attr_hue);
5694err_contrast:
5695 device_remove_file(&vdev->dev, &dev_attr_contrast);
5696err_sat:
5697 device_remove_file(&vdev->dev, &dev_attr_saturation);
5698err_bright:
5699 device_remove_file(&vdev->dev, &dev_attr_brightness);
5700err_sensor:
5701 device_remove_file(&vdev->dev, &dev_attr_sensor);
5702err_bridge:
5703 device_remove_file(&vdev->dev, &dev_attr_bridge);
5704err_model:
5705 device_remove_file(&vdev->dev, &dev_attr_model);
5706err_id:
5707 device_remove_file(&vdev->dev, &dev_attr_custom_id);
5708err:
5709 return rc;
5710}
5711
5712/****************************************************************************
5713 * USB routines
5714 ***************************************************************************/
5715
5716static int
5717ov51x_probe(struct usb_interface *intf, const struct usb_device_id *id)
5718{
5719 struct usb_device *dev = interface_to_usbdev(intf);
5720 struct usb_interface_descriptor *idesc;
5721 struct usb_ov511 *ov;
5722 int i, rc, nr;
5723
5724 PDEBUG(1, "probing for device...");
5725
5726 /* We don't handle multi-config cameras */
5727 if (dev->descriptor.bNumConfigurations != 1)
5728 return -ENODEV;
5729
5730 idesc = &intf->cur_altsetting->desc;
5731
5732 if (idesc->bInterfaceClass != 0xFF)
5733 return -ENODEV;
5734 if (idesc->bInterfaceSubClass != 0x00)
5735 return -ENODEV;
5736
5737 if ((ov = kzalloc(sizeof(*ov), GFP_KERNEL)) == NULL) {
5738 err("couldn't kmalloc ov struct");
5739 goto error_out;
5740 }
5741
5742 ov->dev = dev;
5743 ov->iface = idesc->bInterfaceNumber;
5744 ov->led_policy = led;
5745 ov->compress = compress;
5746 ov->lightfreq = lightfreq;
5747 ov->num_inputs = 1; /* Video decoder init functs. change this */
5748 ov->stop_during_set = !fastset;
5749 ov->backlight = backlight;
5750 ov->mirror = mirror;
5751 ov->auto_brt = autobright;
5752 ov->auto_gain = autogain;
5753 ov->auto_exp = autoexp;
5754
5755 switch (le16_to_cpu(dev->descriptor.idProduct)) {
5756 case PROD_OV511:
5757 ov->bridge = BRG_OV511;
5758 ov->bclass = BCL_OV511;
5759 break;
5760 case PROD_OV511PLUS:
5761 ov->bridge = BRG_OV511PLUS;
5762 ov->bclass = BCL_OV511;
5763 break;
5764 case PROD_OV518:
5765 ov->bridge = BRG_OV518;
5766 ov->bclass = BCL_OV518;
5767 break;
5768 case PROD_OV518PLUS:
5769 ov->bridge = BRG_OV518PLUS;
5770 ov->bclass = BCL_OV518;
5771 break;
5772 case PROD_ME2CAM:
5773 if (le16_to_cpu(dev->descriptor.idVendor) != VEND_MATTEL)
5774 goto error;
5775 ov->bridge = BRG_OV511PLUS;
5776 ov->bclass = BCL_OV511;
5777 break;
5778 default:
5779 err("Unknown product ID 0x%04x", le16_to_cpu(dev->descriptor.idProduct));
5780 goto error;
5781 }
5782
5783 dev_info(&intf->dev, "USB %s video device found\n",
5784 symbolic(brglist, ov->bridge));
5785
5786 init_waitqueue_head(&ov->wq);
5787
5788 mutex_init(&ov->lock); /* to 1 == available */
5789 mutex_init(&ov->buf_lock);
5790 mutex_init(&ov->i2c_lock);
5791 mutex_init(&ov->cbuf_lock);
5792
5793 ov->buf_state = BUF_NOT_ALLOCATED;
5794
5795 if (usb_make_path(dev, ov->usb_path, OV511_USB_PATH_LEN) < 0) {
5796 err("usb_make_path error");
5797 goto error;
5798 }
5799
5800 /* Allocate control transfer buffer. */
5801 /* Must be kmalloc()'ed, for DMA compatibility */
5802 ov->cbuf = kmalloc(OV511_CBUF_SIZE, GFP_KERNEL);
5803 if (!ov->cbuf)
5804 goto error;
5805
5806 if (ov->bclass == BCL_OV518) {
5807 if (ov518_configure(ov) < 0)
5808 goto error;
5809 } else {
5810 if (ov511_configure(ov) < 0)
5811 goto error;
5812 }
5813
5814 for (i = 0; i < OV511_NUMFRAMES; i++) {
5815 ov->frame[i].framenum = i;
5816 init_waitqueue_head(&ov->frame[i].wq);
5817 }
5818
5819 for (i = 0; i < OV511_NUMSBUF; i++) {
5820 ov->sbuf[i].ov = ov;
5821 spin_lock_init(&ov->sbuf[i].lock);
5822 ov->sbuf[i].n = i;
5823 }
5824
5825 /* Unnecessary? (This is done on open(). Need to make sure variables
5826 * are properly initialized without this before removing it, though). */
5827 if (ov51x_set_default_params(ov) < 0)
5828 goto error;
5829
5830#ifdef OV511_DEBUG
5831 if (dump_bridge) {
5832 if (ov->bclass == BCL_OV511)
5833 ov511_dump_regs(ov);
5834 else
5835 ov518_dump_regs(ov);
5836 }
5837#endif
5838
5839 ov->vdev = video_device_alloc();
5840 if (!ov->vdev)
5841 goto error;
5842
5843 memcpy(ov->vdev, &vdev_template, sizeof(*ov->vdev));
5844 ov->vdev->parent = &intf->dev;
5845 video_set_drvdata(ov->vdev, ov);
5846
5847 mutex_lock(&ov->lock);
5848
5849 /* Check to see next free device and mark as used */
5850 nr = find_first_zero_bit(&ov511_devused, OV511_MAX_UNIT_VIDEO);
5851
5852 /* Registers device */
5853 if (unit_video[nr] != 0)
5854 rc = video_register_device(ov->vdev, VFL_TYPE_GRABBER,
5855 unit_video[nr]);
5856 else
5857 rc = video_register_device(ov->vdev, VFL_TYPE_GRABBER, -1);
5858
5859 if (rc < 0) {
5860 err("video_register_device failed");
5861 mutex_unlock(&ov->lock);
5862 goto error;
5863 }
5864
5865 /* Mark device as used */
5866 ov511_devused |= 1 << nr;
5867 ov->nr = nr;
5868
5869 dev_info(&intf->dev, "Device at %s registered to %s\n",
5870 ov->usb_path, video_device_node_name(ov->vdev));
5871
5872 usb_set_intfdata(intf, ov);
5873 if (ov_create_sysfs(ov->vdev)) {
5874 err("ov_create_sysfs failed");
5875 ov511_devused &= ~(1 << nr);
5876 mutex_unlock(&ov->lock);
5877 goto error;
5878 }
5879
5880 mutex_unlock(&ov->lock);
5881
5882 return 0;
5883
5884error:
5885 if (ov->vdev) {
5886 if (!video_is_registered(ov->vdev))
5887 video_device_release(ov->vdev);
5888 else
5889 video_unregister_device(ov->vdev);
5890 ov->vdev = NULL;
5891 }
5892
5893 if (ov->cbuf) {
5894 mutex_lock(&ov->cbuf_lock);
5895 kfree(ov->cbuf);
5896 ov->cbuf = NULL;
5897 mutex_unlock(&ov->cbuf_lock);
5898 }
5899
5900 kfree(ov);
5901 ov = NULL;
5902
5903error_out:
5904 err("Camera initialization failed");
5905 return -EIO;
5906}
5907
5908static void
5909ov51x_disconnect(struct usb_interface *intf)
5910{
5911 struct usb_ov511 *ov = usb_get_intfdata(intf);
5912 int n;
5913
5914 PDEBUG(3, "");
5915
5916 mutex_lock(&ov->lock);
5917 usb_set_intfdata (intf, NULL);
5918
5919 /* Free device number */
5920 ov511_devused &= ~(1 << ov->nr);
5921
5922 if (ov->vdev)
5923 video_unregister_device(ov->vdev);
5924
5925 for (n = 0; n < OV511_NUMFRAMES; n++)
5926 ov->frame[n].grabstate = FRAME_ERROR;
5927
5928 ov->curframe = -1;
5929
5930 /* This will cause the process to request another frame */
5931 for (n = 0; n < OV511_NUMFRAMES; n++)
5932 wake_up_interruptible(&ov->frame[n].wq);
5933
5934 wake_up_interruptible(&ov->wq);
5935
5936 ov->streaming = 0;
5937 ov51x_unlink_isoc(ov);
5938 mutex_unlock(&ov->lock);
5939
5940 ov->dev = NULL;
5941
5942 /* Free the memory */
5943 if (!ov->user) {
5944 mutex_lock(&ov->cbuf_lock);
5945 kfree(ov->cbuf);
5946 ov->cbuf = NULL;
5947 mutex_unlock(&ov->cbuf_lock);
5948
5949 ov51x_dealloc(ov);
5950 kfree(ov);
5951 ov = NULL;
5952 }
5953
5954 PDEBUG(3, "Disconnect complete");
5955}
5956
5957static struct usb_driver ov511_driver = {
5958 .name = "ov511",
5959 .id_table = device_table,
5960 .probe = ov51x_probe,
5961 .disconnect = ov51x_disconnect
5962};
5963
5964/****************************************************************************
5965 *
5966 * Module routines
5967 *
5968 ***************************************************************************/
5969
5970static int __init
5971usb_ov511_init(void)
5972{
5973 int retval;
5974
5975 retval = usb_register(&ov511_driver);
5976 if (retval)
5977 goto out;
5978
5979 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
5980 DRIVER_DESC "\n");
5981
5982out:
5983 return retval;
5984}
5985
5986static void __exit
5987usb_ov511_exit(void)
5988{
5989 usb_deregister(&ov511_driver);
5990 printk(KERN_INFO KBUILD_MODNAME ": driver deregistered\n");
5991}
5992
5993module_init(usb_ov511_init);
5994module_exit(usb_ov511_exit);
5995
diff --git a/drivers/media/video/ov511.h b/drivers/media/video/ov511.h
deleted file mode 100644
index c450c92468da..000000000000
--- a/drivers/media/video/ov511.h
+++ /dev/null
@@ -1,573 +0,0 @@
1#ifndef __LINUX_OV511_H
2#define __LINUX_OV511_H
3
4#include <asm/uaccess.h>
5#include <linux/videodev.h>
6#include <media/v4l2-common.h>
7#include <media/v4l2-ioctl.h>
8#include <linux/usb.h>
9#include <linux/mutex.h>
10
11#define OV511_DEBUG /* Turn on debug messages */
12
13#ifdef OV511_DEBUG
14 #define PDEBUG(level, fmt, args...) \
15 if (debug >= (level)) \
16 printk(KERN_INFO KBUILD_MODNAME "[%s:%d] \n" fmt, \
17 __func__, __LINE__ , ## args)
18#else
19 #define PDEBUG(level, fmt, args...) do {} while(0)
20#endif
21
22/* This macro restricts an int variable to an inclusive range */
23#define RESTRICT_TO_RANGE(v,mi,ma) { \
24 if ((v) < (mi)) (v) = (mi); \
25 else if ((v) > (ma)) (v) = (ma); \
26}
27
28/* --------------------------------- */
29/* DEFINES FOR OV511 AND OTHER CHIPS */
30/* --------------------------------- */
31
32/* USB IDs */
33#define VEND_OMNIVISION 0x05A9
34#define PROD_OV511 0x0511
35#define PROD_OV511PLUS 0xA511
36#define PROD_OV518 0x0518
37#define PROD_OV518PLUS 0xA518
38
39#define VEND_MATTEL 0x0813
40#define PROD_ME2CAM 0x0002
41
42/* --------------------------------- */
43/* OV51x REGISTER MNEMONICS */
44/* --------------------------------- */
45
46/* Camera interface register numbers */
47#define R511_CAM_DELAY 0x10
48#define R511_CAM_EDGE 0x11
49#define R511_CAM_PXCNT 0x12
50#define R511_CAM_LNCNT 0x13
51#define R511_CAM_PXDIV 0x14
52#define R511_CAM_LNDIV 0x15
53#define R511_CAM_UV_EN 0x16
54#define R511_CAM_LINE_MODE 0x17
55#define R511_CAM_OPTS 0x18
56
57/* Snapshot mode camera interface register numbers */
58#define R511_SNAP_FRAME 0x19
59#define R511_SNAP_PXCNT 0x1A
60#define R511_SNAP_LNCNT 0x1B
61#define R511_SNAP_PXDIV 0x1C
62#define R511_SNAP_LNDIV 0x1D
63#define R511_SNAP_UV_EN 0x1E
64#define R511_SNAP_OPTS 0x1F
65
66/* DRAM register numbers */
67#define R511_DRAM_FLOW_CTL 0x20
68#define R511_DRAM_ARCP 0x21
69#define R511_DRAM_MRC 0x22
70#define R511_DRAM_RFC 0x23
71
72/* ISO FIFO register numbers */
73#define R51x_FIFO_PSIZE 0x30 /* 2 bytes wide w/ OV518(+) */
74#define R511_FIFO_OPTS 0x31
75
76/* Parallel IO register numbers */
77#define R511_PIO_OPTS 0x38
78#define R511_PIO_DATA 0x39
79#define R511_PIO_BIST 0x3E
80#define R518_GPIO_IN 0x55 /* OV518(+) only */
81#define R518_GPIO_OUT 0x56 /* OV518(+) only */
82#define R518_GPIO_CTL 0x57 /* OV518(+) only */
83#define R518_GPIO_PULSE_IN 0x58 /* OV518(+) only */
84#define R518_GPIO_PULSE_CLEAR 0x59 /* OV518(+) only */
85#define R518_GPIO_PULSE_POL 0x5a /* OV518(+) only */
86#define R518_GPIO_PULSE_EN 0x5b /* OV518(+) only */
87#define R518_GPIO_RESET 0x5c /* OV518(+) only */
88
89/* I2C registers */
90#define R511_I2C_CTL 0x40
91#define R518_I2C_CTL 0x47 /* OV518(+) only */
92#define R51x_I2C_W_SID 0x41
93#define R51x_I2C_SADDR_3 0x42
94#define R51x_I2C_SADDR_2 0x43
95#define R51x_I2C_R_SID 0x44
96#define R51x_I2C_DATA 0x45
97#define R51x_I2C_CLOCK 0x46
98#define R51x_I2C_TIMEOUT 0x47
99
100/* I2C snapshot registers */
101#define R511_SI2C_SADDR_3 0x48
102#define R511_SI2C_DATA 0x49
103
104/* System control registers */
105#define R51x_SYS_RESET 0x50
106 /* Reset type definitions */
107#define OV511_RESET_UDC 0x01
108#define OV511_RESET_I2C 0x02
109#define OV511_RESET_FIFO 0x04
110#define OV511_RESET_OMNICE 0x08
111#define OV511_RESET_DRAM 0x10
112#define OV511_RESET_CAM_INT 0x20
113#define OV511_RESET_OV511 0x40
114#define OV511_RESET_NOREGS 0x3F /* All but OV511 & regs */
115#define OV511_RESET_ALL 0x7F
116
117#define R511_SYS_CLOCK_DIV 0x51
118#define R51x_SYS_SNAP 0x52
119#define R51x_SYS_INIT 0x53
120#define R511_SYS_PWR_CLK 0x54 /* OV511+/OV518(+) only */
121#define R511_SYS_LED_CTL 0x55 /* OV511+ only */
122#define R511_SYS_USER 0x5E
123#define R511_SYS_CUST_ID 0x5F
124
125/* OmniCE (compression) registers */
126#define R511_COMP_PHY 0x70
127#define R511_COMP_PHUV 0x71
128#define R511_COMP_PVY 0x72
129#define R511_COMP_PVUV 0x73
130#define R511_COMP_QHY 0x74
131#define R511_COMP_QHUV 0x75
132#define R511_COMP_QVY 0x76
133#define R511_COMP_QVUV 0x77
134#define R511_COMP_EN 0x78
135#define R511_COMP_LUT_EN 0x79
136#define R511_COMP_LUT_BEGIN 0x80
137
138/* --------------------------------- */
139/* ALTERNATE NUMBERS */
140/* --------------------------------- */
141
142/* Alternate numbers for various max packet sizes (OV511 only) */
143#define OV511_ALT_SIZE_992 0
144#define OV511_ALT_SIZE_993 1
145#define OV511_ALT_SIZE_768 2
146#define OV511_ALT_SIZE_769 3
147#define OV511_ALT_SIZE_512 4
148#define OV511_ALT_SIZE_513 5
149#define OV511_ALT_SIZE_257 6
150#define OV511_ALT_SIZE_0 7
151
152/* Alternate numbers for various max packet sizes (OV511+ only) */
153#define OV511PLUS_ALT_SIZE_0 0
154#define OV511PLUS_ALT_SIZE_33 1
155#define OV511PLUS_ALT_SIZE_129 2
156#define OV511PLUS_ALT_SIZE_257 3
157#define OV511PLUS_ALT_SIZE_385 4
158#define OV511PLUS_ALT_SIZE_513 5
159#define OV511PLUS_ALT_SIZE_769 6
160#define OV511PLUS_ALT_SIZE_961 7
161
162/* Alternate numbers for various max packet sizes (OV518(+) only) */
163#define OV518_ALT_SIZE_0 0
164#define OV518_ALT_SIZE_128 1
165#define OV518_ALT_SIZE_256 2
166#define OV518_ALT_SIZE_384 3
167#define OV518_ALT_SIZE_512 4
168#define OV518_ALT_SIZE_640 5
169#define OV518_ALT_SIZE_768 6
170#define OV518_ALT_SIZE_896 7
171
172/* --------------------------------- */
173/* OV7610 REGISTER MNEMONICS */
174/* --------------------------------- */
175
176/* OV7610 registers */
177#define OV7610_REG_GAIN 0x00 /* gain setting (5:0) */
178#define OV7610_REG_BLUE 0x01 /* blue channel balance */
179#define OV7610_REG_RED 0x02 /* red channel balance */
180#define OV7610_REG_SAT 0x03 /* saturation */
181 /* 04 reserved */
182#define OV7610_REG_CNT 0x05 /* Y contrast */
183#define OV7610_REG_BRT 0x06 /* Y brightness */
184 /* 08-0b reserved */
185#define OV7610_REG_BLUE_BIAS 0x0C /* blue channel bias (5:0) */
186#define OV7610_REG_RED_BIAS 0x0D /* read channel bias (5:0) */
187#define OV7610_REG_GAMMA_COEFF 0x0E /* gamma settings */
188#define OV7610_REG_WB_RANGE 0x0F /* AEC/ALC/S-AWB settings */
189#define OV7610_REG_EXP 0x10 /* manual exposure setting */
190#define OV7610_REG_CLOCK 0x11 /* polarity/clock prescaler */
191#define OV7610_REG_COM_A 0x12 /* misc common regs */
192#define OV7610_REG_COM_B 0x13 /* misc common regs */
193#define OV7610_REG_COM_C 0x14 /* misc common regs */
194#define OV7610_REG_COM_D 0x15 /* misc common regs */
195#define OV7610_REG_FIELD_DIVIDE 0x16 /* field interval/mode settings */
196#define OV7610_REG_HWIN_START 0x17 /* horizontal window start */
197#define OV7610_REG_HWIN_END 0x18 /* horizontal window end */
198#define OV7610_REG_VWIN_START 0x19 /* vertical window start */
199#define OV7610_REG_VWIN_END 0x1A /* vertical window end */
200#define OV7610_REG_PIXEL_SHIFT 0x1B /* pixel shift */
201#define OV7610_REG_ID_HIGH 0x1C /* manufacturer ID MSB */
202#define OV7610_REG_ID_LOW 0x1D /* manufacturer ID LSB */
203 /* 0e-0f reserved */
204#define OV7610_REG_COM_E 0x20 /* misc common regs */
205#define OV7610_REG_YOFFSET 0x21 /* Y channel offset */
206#define OV7610_REG_UOFFSET 0x22 /* U channel offset */
207 /* 23 reserved */
208#define OV7610_REG_ECW 0x24 /* Exposure white level for AEC */
209#define OV7610_REG_ECB 0x25 /* Exposure black level for AEC */
210#define OV7610_REG_COM_F 0x26 /* misc settings */
211#define OV7610_REG_COM_G 0x27 /* misc settings */
212#define OV7610_REG_COM_H 0x28 /* misc settings */
213#define OV7610_REG_COM_I 0x29 /* misc settings */
214#define OV7610_REG_FRAMERATE_H 0x2A /* frame rate MSB + misc */
215#define OV7610_REG_FRAMERATE_L 0x2B /* frame rate LSB */
216#define OV7610_REG_ALC 0x2C /* Auto Level Control settings */
217#define OV7610_REG_COM_J 0x2D /* misc settings */
218#define OV7610_REG_VOFFSET 0x2E /* V channel offset adjustment */
219#define OV7610_REG_ARRAY_BIAS 0x2F /* Array bias -- don't change */
220 /* 30-32 reserved */
221#define OV7610_REG_YGAMMA 0x33 /* misc gamma settings (7:6) */
222#define OV7610_REG_BIAS_ADJUST 0x34 /* misc bias settings */
223#define OV7610_REG_COM_L 0x35 /* misc settings */
224 /* 36-37 reserved */
225#define OV7610_REG_COM_K 0x38 /* misc registers */
226
227/* --------------------------------- */
228/* I2C ADDRESSES */
229/* --------------------------------- */
230
231#define OV7xx0_SID 0x42
232#define OV6xx0_SID 0xC0
233#define OV8xx0_SID 0xA0
234#define KS0127_SID 0xD8
235#define SAA7111A_SID 0x48
236
237/* --------------------------------- */
238/* MISCELLANEOUS DEFINES */
239/* --------------------------------- */
240
241#define I2C_CLOCK_PRESCALER 0x03
242
243#define FRAMES_PER_DESC 10 /* FIXME - What should this be? */
244#define MAX_FRAME_SIZE_PER_DESC 993 /* For statically allocated stuff */
245#define PIXELS_PER_SEG 256 /* Pixels per segment */
246
247#define OV511_ENDPOINT_ADDRESS 1 /* Isoc endpoint number */
248
249#define OV511_NUMFRAMES 2
250#if OV511_NUMFRAMES > VIDEO_MAX_FRAME
251 #error "OV511_NUMFRAMES is too high"
252#endif
253
254#define OV511_NUMSBUF 2
255
256/* Control transfers use up to 4 bytes */
257#define OV511_CBUF_SIZE 4
258
259/* Size of usb_make_path() buffer */
260#define OV511_USB_PATH_LEN 64
261
262/* Bridge types */
263enum {
264 BRG_UNKNOWN,
265 BRG_OV511,
266 BRG_OV511PLUS,
267 BRG_OV518,
268 BRG_OV518PLUS,
269};
270
271/* Bridge classes */
272enum {
273 BCL_UNKNOWN,
274 BCL_OV511,
275 BCL_OV518,
276};
277
278/* Sensor types */
279enum {
280 SEN_UNKNOWN,
281 SEN_OV76BE,
282 SEN_OV7610,
283 SEN_OV7620,
284 SEN_OV7620AE,
285 SEN_OV6620,
286 SEN_OV6630,
287 SEN_OV6630AE,
288 SEN_OV6630AF,
289 SEN_OV8600,
290 SEN_KS0127,
291 SEN_KS0127B,
292 SEN_SAA7111A,
293};
294
295enum {
296 STATE_SCANNING, /* Scanning for start */
297 STATE_HEADER, /* Parsing header */
298 STATE_LINES, /* Parsing lines */
299};
300
301/* Buffer states */
302enum {
303 BUF_NOT_ALLOCATED,
304 BUF_ALLOCATED,
305};
306
307/* --------- Definition of ioctl interface --------- */
308
309#define OV511_INTERFACE_VER 101
310
311/* LED options */
312enum {
313 LED_OFF,
314 LED_ON,
315 LED_AUTO,
316};
317
318/* Raw frame formats */
319enum {
320 RAWFMT_INVALID,
321 RAWFMT_YUV400,
322 RAWFMT_YUV420,
323 RAWFMT_YUV422,
324 RAWFMT_GBR422,
325};
326
327struct ov511_i2c_struct {
328 unsigned char slave; /* Write slave ID (read ID - 1) */
329 unsigned char reg; /* Index of register */
330 unsigned char value; /* User sets this w/ write, driver does w/ read */
331 unsigned char mask; /* Bits to be changed. Not used with read ops */
332};
333
334/* ioctls */
335#define OV511IOC_WI2C _IOW('v', BASE_VIDIOCPRIVATE + 5, \
336 struct ov511_i2c_struct)
337#define OV511IOC_RI2C _IOWR('v', BASE_VIDIOCPRIVATE + 6, \
338 struct ov511_i2c_struct)
339/* ------------- End IOCTL interface -------------- */
340
341struct usb_ov511; /* Forward declaration */
342
343struct ov511_sbuf {
344 struct usb_ov511 *ov;
345 unsigned char *data;
346 struct urb *urb;
347 spinlock_t lock;
348 int n;
349};
350
351enum {
352 FRAME_UNUSED, /* Unused (no MCAPTURE) */
353 FRAME_READY, /* Ready to start grabbing */
354 FRAME_GRABBING, /* In the process of being grabbed into */
355 FRAME_DONE, /* Finished grabbing, but not been synced yet */
356 FRAME_ERROR, /* Something bad happened while processing */
357};
358
359struct ov511_regvals {
360 enum {
361 OV511_DONE_BUS,
362 OV511_REG_BUS,
363 OV511_I2C_BUS,
364 } bus;
365 unsigned char reg;
366 unsigned char val;
367};
368
369struct ov511_frame {
370 int framenum; /* Index of this frame */
371 unsigned char *data; /* Frame buffer */
372 unsigned char *tempdata; /* Temp buffer for multi-stage conversions */
373 unsigned char *rawdata; /* Raw camera data buffer */
374 unsigned char *compbuf; /* Temp buffer for decompressor */
375
376 int depth; /* Bytes per pixel */
377 int width; /* Width application is expecting */
378 int height; /* Height application is expecting */
379
380 int rawwidth; /* Actual width of frame sent from camera */
381 int rawheight; /* Actual height of frame sent from camera */
382
383 int sub_flag; /* Sub-capture mode for this frame? */
384 unsigned int format; /* Format for this frame */
385 int compressed; /* Is frame compressed? */
386
387 volatile int grabstate; /* State of grabbing */
388 int scanstate; /* State of scanning */
389
390 int bytes_recvd; /* Number of image bytes received from camera */
391
392 long bytes_read; /* Amount that has been read() */
393
394 wait_queue_head_t wq; /* Processes waiting */
395
396 int snapshot; /* True if frame was a snapshot */
397};
398
399#define DECOMP_INTERFACE_VER 4
400
401/* Compression module operations */
402struct ov51x_decomp_ops {
403 int (*decomp_400)(unsigned char *, unsigned char *, unsigned char *,
404 int, int, int);
405 int (*decomp_420)(unsigned char *, unsigned char *, unsigned char *,
406 int, int, int);
407 int (*decomp_422)(unsigned char *, unsigned char *, unsigned char *,
408 int, int, int);
409 struct module *owner;
410};
411
412struct usb_ov511 {
413 struct video_device *vdev;
414 struct usb_device *dev;
415
416 int customid;
417 char *desc;
418 unsigned char iface;
419 char usb_path[OV511_USB_PATH_LEN];
420
421 /* Determined by sensor type */
422 int maxwidth;
423 int maxheight;
424 int minwidth;
425 int minheight;
426
427 int brightness;
428 int colour;
429 int contrast;
430 int hue;
431 int whiteness;
432 int exposure;
433 int auto_brt; /* Auto brightness enabled flag */
434 int auto_gain; /* Auto gain control enabled flag */
435 int auto_exp; /* Auto exposure enabled flag */
436 int backlight; /* Backlight exposure algorithm flag */
437 int mirror; /* Image is reversed horizontally */
438
439 int led_policy; /* LED: off|on|auto; OV511+ only */
440
441 struct mutex lock; /* Serializes user-accessible operations */
442 int user; /* user count for exclusive use */
443
444 int streaming; /* Are we streaming Isochronous? */
445 int grabbing; /* Are we grabbing? */
446
447 int compress; /* Should the next frame be compressed? */
448 int compress_inited; /* Are compression params uploaded? */
449
450 int lightfreq; /* Power (lighting) frequency */
451 int bandfilt; /* Banding filter enabled flag */
452
453 unsigned char *fbuf; /* Videodev buffer area */
454 unsigned char *tempfbuf; /* Temporary (intermediate) buffer area */
455 unsigned char *rawfbuf; /* Raw camera data buffer area */
456
457 int sub_flag; /* Pix Array subcapture on flag */
458 int subx; /* Pix Array subcapture x offset */
459 int suby; /* Pix Array subcapture y offset */
460 int subw; /* Pix Array subcapture width */
461 int subh; /* Pix Array subcapture height */
462
463 int curframe; /* Current receiving sbuf */
464 struct ov511_frame frame[OV511_NUMFRAMES];
465
466 struct ov511_sbuf sbuf[OV511_NUMSBUF];
467
468 wait_queue_head_t wq; /* Processes waiting */
469
470 int snap_enabled; /* Snapshot mode enabled */
471
472 int bridge; /* Type of bridge (BRG_*) */
473 int bclass; /* Class of bridge (BCL_*) */
474 int sensor; /* Type of image sensor chip (SEN_*) */
475
476 int packet_size; /* Frame size per isoc desc */
477 int packet_numbering; /* Is ISO frame numbering enabled? */
478
479 /* Framebuffer/sbuf management */
480 int buf_state;
481 struct mutex buf_lock;
482
483 struct ov51x_decomp_ops *decomp_ops;
484
485 /* Stop streaming while changing picture settings */
486 int stop_during_set;
487
488 int stopped; /* Streaming is temporarily paused */
489
490 /* Video decoder stuff */
491 int input; /* Composite, S-VIDEO, etc... */
492 int num_inputs; /* Number of inputs */
493 int norm; /* NTSC / PAL / SECAM */
494 int has_decoder; /* Device has a video decoder */
495 int pal; /* Device is designed for PAL resolution */
496
497 /* ov511 device number ID */
498 int nr; /* Stores a device number */
499
500 /* I2C interface */
501 struct mutex i2c_lock; /* Protect I2C controller regs */
502 unsigned char primary_i2c_slave; /* I2C write id of sensor */
503
504 /* Control transaction stuff */
505 unsigned char *cbuf; /* Buffer for payload */
506 struct mutex cbuf_lock;
507};
508
509/* Used to represent a list of values and their respective symbolic names */
510struct symbolic_list {
511 int num;
512 char *name;
513};
514
515#define NOT_DEFINED_STR "Unknown"
516
517/* Returns the name of the matching element in the symbolic_list array. The
518 * end of the list must be marked with an element that has a NULL name.
519 */
520static inline char *
521symbolic(struct symbolic_list list[], int num)
522{
523 int i;
524
525 for (i = 0; list[i].name != NULL; i++)
526 if (list[i].num == num)
527 return (list[i].name);
528
529 return (NOT_DEFINED_STR);
530}
531
532/* Compression stuff */
533
534#define OV511_QUANTABLESIZE 64
535#define OV518_QUANTABLESIZE 32
536
537#define OV511_YQUANTABLE { \
538 0, 1, 1, 2, 2, 3, 3, 4, \
539 1, 1, 1, 2, 2, 3, 4, 4, \
540 1, 1, 2, 2, 3, 4, 4, 4, \
541 2, 2, 2, 3, 4, 4, 4, 4, \
542 2, 2, 3, 4, 4, 5, 5, 5, \
543 3, 3, 4, 4, 5, 5, 5, 5, \
544 3, 4, 4, 4, 5, 5, 5, 5, \
545 4, 4, 4, 4, 5, 5, 5, 5 \
546}
547
548#define OV511_UVQUANTABLE { \
549 0, 2, 2, 3, 4, 4, 4, 4, \
550 2, 2, 2, 4, 4, 4, 4, 4, \
551 2, 2, 3, 4, 4, 4, 4, 4, \
552 3, 4, 4, 4, 4, 4, 4, 4, \
553 4, 4, 4, 4, 4, 4, 4, 4, \
554 4, 4, 4, 4, 4, 4, 4, 4, \
555 4, 4, 4, 4, 4, 4, 4, 4, \
556 4, 4, 4, 4, 4, 4, 4, 4 \
557}
558
559#define OV518_YQUANTABLE { \
560 5, 4, 5, 6, 6, 7, 7, 7, \
561 5, 5, 5, 5, 6, 7, 7, 7, \
562 6, 6, 6, 6, 7, 7, 7, 8, \
563 7, 7, 6, 7, 7, 7, 8, 8 \
564}
565
566#define OV518_UVQUANTABLE { \
567 6, 6, 6, 7, 7, 7, 7, 7, \
568 6, 6, 6, 7, 7, 7, 7, 7, \
569 6, 6, 6, 7, 7, 7, 7, 8, \
570 7, 7, 7, 7, 7, 7, 8, 8 \
571}
572
573#endif
diff --git a/drivers/media/video/ov772x.c b/drivers/media/video/ov772x.c
index 34034a710214..25eb5d637eea 100644
--- a/drivers/media/video/ov772x.c
+++ b/drivers/media/video/ov772x.c
@@ -440,21 +440,21 @@ static const struct regval_list ov772x_vga_regs[] = {
440 */ 440 */
441static const struct ov772x_color_format ov772x_cfmts[] = { 441static const struct ov772x_color_format ov772x_cfmts[] = {
442 { 442 {
443 .code = V4L2_MBUS_FMT_YUYV8_2X8_LE, 443 .code = V4L2_MBUS_FMT_YUYV8_2X8,
444 .colorspace = V4L2_COLORSPACE_JPEG, 444 .colorspace = V4L2_COLORSPACE_JPEG,
445 .dsp3 = 0x0, 445 .dsp3 = 0x0,
446 .com3 = SWAP_YUV, 446 .com3 = SWAP_YUV,
447 .com7 = OFMT_YUV, 447 .com7 = OFMT_YUV,
448 }, 448 },
449 { 449 {
450 .code = V4L2_MBUS_FMT_YVYU8_2X8_LE, 450 .code = V4L2_MBUS_FMT_YVYU8_2X8,
451 .colorspace = V4L2_COLORSPACE_JPEG, 451 .colorspace = V4L2_COLORSPACE_JPEG,
452 .dsp3 = UV_ON, 452 .dsp3 = UV_ON,
453 .com3 = SWAP_YUV, 453 .com3 = SWAP_YUV,
454 .com7 = OFMT_YUV, 454 .com7 = OFMT_YUV,
455 }, 455 },
456 { 456 {
457 .code = V4L2_MBUS_FMT_YUYV8_2X8_BE, 457 .code = V4L2_MBUS_FMT_UYVY8_2X8,
458 .colorspace = V4L2_COLORSPACE_JPEG, 458 .colorspace = V4L2_COLORSPACE_JPEG,
459 .dsp3 = 0x0, 459 .dsp3 = 0x0,
460 .com3 = 0x0, 460 .com3 = 0x0,
@@ -960,7 +960,7 @@ static int ov772x_g_fmt(struct v4l2_subdev *sd,
960 if (!priv->win || !priv->cfmt) { 960 if (!priv->win || !priv->cfmt) {
961 u32 width = VGA_WIDTH, height = VGA_HEIGHT; 961 u32 width = VGA_WIDTH, height = VGA_HEIGHT;
962 int ret = ov772x_set_params(client, &width, &height, 962 int ret = ov772x_set_params(client, &width, &height,
963 V4L2_MBUS_FMT_YUYV8_2X8_LE); 963 V4L2_MBUS_FMT_YUYV8_2X8);
964 if (ret < 0) 964 if (ret < 0)
965 return ret; 965 return ret;
966 } 966 }
diff --git a/drivers/media/video/ov9640.c b/drivers/media/video/ov9640.c
index 7ce9e05b4781..40cdfab74ccc 100644
--- a/drivers/media/video/ov9640.c
+++ b/drivers/media/video/ov9640.c
@@ -155,7 +155,7 @@ static const struct ov9640_reg ov9640_regs_rgb[] = {
155}; 155};
156 156
157static enum v4l2_mbus_pixelcode ov9640_codes[] = { 157static enum v4l2_mbus_pixelcode ov9640_codes[] = {
158 V4L2_MBUS_FMT_YUYV8_2X8_BE, 158 V4L2_MBUS_FMT_UYVY8_2X8,
159 V4L2_MBUS_FMT_RGB555_2X8_PADHI_LE, 159 V4L2_MBUS_FMT_RGB555_2X8_PADHI_LE,
160 V4L2_MBUS_FMT_RGB565_2X8_LE, 160 V4L2_MBUS_FMT_RGB565_2X8_LE,
161}; 161};
@@ -430,7 +430,7 @@ static void ov9640_alter_regs(enum v4l2_mbus_pixelcode code,
430{ 430{
431 switch (code) { 431 switch (code) {
432 default: 432 default:
433 case V4L2_MBUS_FMT_YUYV8_2X8_BE: 433 case V4L2_MBUS_FMT_UYVY8_2X8:
434 alt->com12 = OV9640_COM12_YUV_AVG; 434 alt->com12 = OV9640_COM12_YUV_AVG;
435 alt->com13 = OV9640_COM13_Y_DELAY_EN | 435 alt->com13 = OV9640_COM13_Y_DELAY_EN |
436 OV9640_COM13_YUV_DLY(0x01); 436 OV9640_COM13_YUV_DLY(0x01);
@@ -493,7 +493,7 @@ static int ov9640_write_regs(struct i2c_client *client, u32 width,
493 } 493 }
494 494
495 /* select color matrix configuration for given color encoding */ 495 /* select color matrix configuration for given color encoding */
496 if (code == V4L2_MBUS_FMT_YUYV8_2X8_BE) { 496 if (code == V4L2_MBUS_FMT_UYVY8_2X8) {
497 matrix_regs = ov9640_regs_yuv; 497 matrix_regs = ov9640_regs_yuv;
498 matrix_regs_len = ARRAY_SIZE(ov9640_regs_yuv); 498 matrix_regs_len = ARRAY_SIZE(ov9640_regs_yuv);
499 } else { 499 } else {
@@ -579,8 +579,8 @@ static int ov9640_s_fmt(struct v4l2_subdev *sd,
579 cspace = V4L2_COLORSPACE_SRGB; 579 cspace = V4L2_COLORSPACE_SRGB;
580 break; 580 break;
581 default: 581 default:
582 code = V4L2_MBUS_FMT_YUYV8_2X8_BE; 582 code = V4L2_MBUS_FMT_UYVY8_2X8;
583 case V4L2_MBUS_FMT_YUYV8_2X8_BE: 583 case V4L2_MBUS_FMT_UYVY8_2X8:
584 cspace = V4L2_COLORSPACE_JPEG; 584 cspace = V4L2_COLORSPACE_JPEG;
585 } 585 }
586 586
@@ -606,8 +606,8 @@ static int ov9640_try_fmt(struct v4l2_subdev *sd,
606 mf->colorspace = V4L2_COLORSPACE_SRGB; 606 mf->colorspace = V4L2_COLORSPACE_SRGB;
607 break; 607 break;
608 default: 608 default:
609 mf->code = V4L2_MBUS_FMT_YUYV8_2X8_BE; 609 mf->code = V4L2_MBUS_FMT_UYVY8_2X8;
610 case V4L2_MBUS_FMT_YUYV8_2X8_BE: 610 case V4L2_MBUS_FMT_UYVY8_2X8:
611 mf->colorspace = V4L2_COLORSPACE_JPEG; 611 mf->colorspace = V4L2_COLORSPACE_JPEG;
612 } 612 }
613 613
diff --git a/drivers/media/video/ovcamchip/Makefile b/drivers/media/video/ovcamchip/Makefile
deleted file mode 100644
index cba4cdf20f49..000000000000
--- a/drivers/media/video/ovcamchip/Makefile
+++ /dev/null
@@ -1,4 +0,0 @@
1ovcamchip-objs := ovcamchip_core.o ov6x20.o ov6x30.o ov7x10.o ov7x20.o \
2 ov76be.o
3
4obj-$(CONFIG_VIDEO_OVCAMCHIP) += ovcamchip.o
diff --git a/drivers/media/video/ovcamchip/ov6x20.c b/drivers/media/video/ovcamchip/ov6x20.c
deleted file mode 100644
index c04130dab127..000000000000
--- a/drivers/media/video/ovcamchip/ov6x20.c
+++ /dev/null
@@ -1,414 +0,0 @@
1/* OmniVision OV6620/OV6120 Camera Chip Support Code
2 *
3 * Copyright (c) 1999-2004 Mark McClelland <mark@alpha.dyndns.org>
4 * http://alpha.dyndns.org/ov511/
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. NO WARRANTY OF ANY KIND is expressed or implied.
10 */
11
12#define DEBUG
13
14#include <linux/slab.h>
15#include "ovcamchip_priv.h"
16
17/* Registers */
18#define REG_GAIN 0x00 /* gain [5:0] */
19#define REG_BLUE 0x01 /* blue gain */
20#define REG_RED 0x02 /* red gain */
21#define REG_SAT 0x03 /* saturation */
22#define REG_CNT 0x05 /* Y contrast */
23#define REG_BRT 0x06 /* Y brightness */
24#define REG_WB_BLUE 0x0C /* WB blue ratio [5:0] */
25#define REG_WB_RED 0x0D /* WB red ratio [5:0] */
26#define REG_EXP 0x10 /* exposure */
27
28/* Window parameters */
29#define HWSBASE 0x38
30#define HWEBASE 0x3A
31#define VWSBASE 0x05
32#define VWEBASE 0x06
33
34struct ov6x20 {
35 int auto_brt;
36 int auto_exp;
37 int backlight;
38 int bandfilt;
39 int mirror;
40};
41
42/* Initial values for use with OV511/OV511+ cameras */
43static struct ovcamchip_regvals regvals_init_6x20_511[] = {
44 { 0x12, 0x80 }, /* reset */
45 { 0x11, 0x01 },
46 { 0x03, 0x60 },
47 { 0x05, 0x7f }, /* For when autoadjust is off */
48 { 0x07, 0xa8 },
49 { 0x0c, 0x24 },
50 { 0x0d, 0x24 },
51 { 0x0f, 0x15 }, /* COMS */
52 { 0x10, 0x75 }, /* AEC Exposure time */
53 { 0x12, 0x24 }, /* Enable AGC and AWB */
54 { 0x14, 0x04 },
55 { 0x16, 0x03 },
56 { 0x26, 0xb2 }, /* BLC enable */
57 /* 0x28: 0x05 Selects RGB format if RGB on */
58 { 0x28, 0x05 },
59 { 0x2a, 0x04 }, /* Disable framerate adjust */
60 { 0x2d, 0x99 },
61 { 0x33, 0xa0 }, /* Color Processing Parameter */
62 { 0x34, 0xd2 }, /* Max A/D range */
63 { 0x38, 0x8b },
64 { 0x39, 0x40 },
65
66 { 0x3c, 0x39 }, /* Enable AEC mode changing */
67 { 0x3c, 0x3c }, /* Change AEC mode */
68 { 0x3c, 0x24 }, /* Disable AEC mode changing */
69
70 { 0x3d, 0x80 },
71 /* These next two registers (0x4a, 0x4b) are undocumented. They
72 * control the color balance */
73 { 0x4a, 0x80 },
74 { 0x4b, 0x80 },
75 { 0x4d, 0xd2 }, /* This reduces noise a bit */
76 { 0x4e, 0xc1 },
77 { 0x4f, 0x04 },
78 { 0xff, 0xff }, /* END MARKER */
79};
80
81/* Initial values for use with OV518 cameras */
82static struct ovcamchip_regvals regvals_init_6x20_518[] = {
83 { 0x12, 0x80 }, /* Do a reset */
84 { 0x03, 0xc0 }, /* Saturation */
85 { 0x05, 0x8a }, /* Contrast */
86 { 0x0c, 0x24 }, /* AWB blue */
87 { 0x0d, 0x24 }, /* AWB red */
88 { 0x0e, 0x8d }, /* Additional 2x gain */
89 { 0x0f, 0x25 }, /* Black expanding level = 1.3V */
90 { 0x11, 0x01 }, /* Clock div. */
91 { 0x12, 0x24 }, /* Enable AGC and AWB */
92 { 0x13, 0x01 }, /* (default) */
93 { 0x14, 0x80 }, /* Set reserved bit 7 */
94 { 0x15, 0x01 }, /* (default) */
95 { 0x16, 0x03 }, /* (default) */
96 { 0x17, 0x38 }, /* (default) */
97 { 0x18, 0xea }, /* (default) */
98 { 0x19, 0x04 },
99 { 0x1a, 0x93 },
100 { 0x1b, 0x00 }, /* (default) */
101 { 0x1e, 0xc4 }, /* (default) */
102 { 0x1f, 0x04 }, /* (default) */
103 { 0x20, 0x20 }, /* Enable 1st stage aperture correction */
104 { 0x21, 0x10 }, /* Y offset */
105 { 0x22, 0x88 }, /* U offset */
106 { 0x23, 0xc0 }, /* Set XTAL power level */
107 { 0x24, 0x53 }, /* AEC bright ratio */
108 { 0x25, 0x7a }, /* AEC black ratio */
109 { 0x26, 0xb2 }, /* BLC enable */
110 { 0x27, 0xa2 }, /* Full output range */
111 { 0x28, 0x01 }, /* (default) */
112 { 0x29, 0x00 }, /* (default) */
113 { 0x2a, 0x84 }, /* (default) */
114 { 0x2b, 0xa8 }, /* Set custom frame rate */
115 { 0x2c, 0xa0 }, /* (reserved) */
116 { 0x2d, 0x95 }, /* Enable banding filter */
117 { 0x2e, 0x88 }, /* V offset */
118 { 0x33, 0x22 }, /* Luminance gamma on */
119 { 0x34, 0xc7 }, /* A/D bias */
120 { 0x36, 0x12 }, /* (reserved) */
121 { 0x37, 0x63 }, /* (reserved) */
122 { 0x38, 0x8b }, /* Quick AEC/AEB */
123 { 0x39, 0x00 }, /* (default) */
124 { 0x3a, 0x0f }, /* (default) */
125 { 0x3b, 0x3c }, /* (default) */
126 { 0x3c, 0x5c }, /* AEC controls */
127 { 0x3d, 0x80 }, /* Drop 1 (bad) frame when AEC change */
128 { 0x3e, 0x80 }, /* (default) */
129 { 0x3f, 0x02 }, /* (default) */
130 { 0x40, 0x10 }, /* (reserved) */
131 { 0x41, 0x10 }, /* (reserved) */
132 { 0x42, 0x00 }, /* (reserved) */
133 { 0x43, 0x7f }, /* (reserved) */
134 { 0x44, 0x80 }, /* (reserved) */
135 { 0x45, 0x1c }, /* (reserved) */
136 { 0x46, 0x1c }, /* (reserved) */
137 { 0x47, 0x80 }, /* (reserved) */
138 { 0x48, 0x5f }, /* (reserved) */
139 { 0x49, 0x00 }, /* (reserved) */
140 { 0x4a, 0x00 }, /* Color balance (undocumented) */
141 { 0x4b, 0x80 }, /* Color balance (undocumented) */
142 { 0x4c, 0x58 }, /* (reserved) */
143 { 0x4d, 0xd2 }, /* U *= .938, V *= .838 */
144 { 0x4e, 0xa0 }, /* (default) */
145 { 0x4f, 0x04 }, /* UV 3-point average */
146 { 0x50, 0xff }, /* (reserved) */
147 { 0x51, 0x58 }, /* (reserved) */
148 { 0x52, 0xc0 }, /* (reserved) */
149 { 0x53, 0x42 }, /* (reserved) */
150 { 0x27, 0xa6 }, /* Enable manual offset adj. (reg 21 & 22) */
151 { 0x12, 0x20 },
152 { 0x12, 0x24 },
153
154 { 0xff, 0xff }, /* END MARKER */
155};
156
157/* This initializes the OV6x20 camera chip and relevant variables. */
158static int ov6x20_init(struct i2c_client *c)
159{
160 struct ovcamchip *ov = i2c_get_clientdata(c);
161 struct ov6x20 *s;
162 int rc;
163
164 DDEBUG(4, &c->dev, "entered");
165
166 switch (c->adapter->id) {
167 case I2C_HW_SMBUS_OV511:
168 rc = ov_write_regvals(c, regvals_init_6x20_511);
169 break;
170 case I2C_HW_SMBUS_OV518:
171 rc = ov_write_regvals(c, regvals_init_6x20_518);
172 break;
173 default:
174 dev_err(&c->dev, "ov6x20: Unsupported adapter\n");
175 rc = -ENODEV;
176 }
177
178 if (rc < 0)
179 return rc;
180
181 ov->spriv = s = kzalloc(sizeof *s, GFP_KERNEL);
182 if (!s)
183 return -ENOMEM;
184
185 s->auto_brt = 1;
186 s->auto_exp = 1;
187
188 return rc;
189}
190
191static int ov6x20_free(struct i2c_client *c)
192{
193 struct ovcamchip *ov = i2c_get_clientdata(c);
194
195 kfree(ov->spriv);
196 return 0;
197}
198
199static int ov6x20_set_control(struct i2c_client *c,
200 struct ovcamchip_control *ctl)
201{
202 struct ovcamchip *ov = i2c_get_clientdata(c);
203 struct ov6x20 *s = ov->spriv;
204 int rc;
205 int v = ctl->value;
206
207 switch (ctl->id) {
208 case OVCAMCHIP_CID_CONT:
209 rc = ov_write(c, REG_CNT, v >> 8);
210 break;
211 case OVCAMCHIP_CID_BRIGHT:
212 rc = ov_write(c, REG_BRT, v >> 8);
213 break;
214 case OVCAMCHIP_CID_SAT:
215 rc = ov_write(c, REG_SAT, v >> 8);
216 break;
217 case OVCAMCHIP_CID_HUE:
218 rc = ov_write(c, REG_RED, 0xFF - (v >> 8));
219 if (rc < 0)
220 goto out;
221
222 rc = ov_write(c, REG_BLUE, v >> 8);
223 break;
224 case OVCAMCHIP_CID_EXP:
225 rc = ov_write(c, REG_EXP, v);
226 break;
227 case OVCAMCHIP_CID_FREQ:
228 {
229 int sixty = (v == 60);
230
231 rc = ov_write(c, 0x2b, sixty?0xa8:0x28);
232 if (rc < 0)
233 goto out;
234
235 rc = ov_write(c, 0x2a, sixty?0x84:0xa4);
236 break;
237 }
238 case OVCAMCHIP_CID_BANDFILT:
239 rc = ov_write_mask(c, 0x2d, v?0x04:0x00, 0x04);
240 s->bandfilt = v;
241 break;
242 case OVCAMCHIP_CID_AUTOBRIGHT:
243 rc = ov_write_mask(c, 0x2d, v?0x10:0x00, 0x10);
244 s->auto_brt = v;
245 break;
246 case OVCAMCHIP_CID_AUTOEXP:
247 rc = ov_write_mask(c, 0x13, v?0x01:0x00, 0x01);
248 s->auto_exp = v;
249 break;
250 case OVCAMCHIP_CID_BACKLIGHT:
251 {
252 rc = ov_write_mask(c, 0x4e, v?0xe0:0xc0, 0xe0);
253 if (rc < 0)
254 goto out;
255
256 rc = ov_write_mask(c, 0x29, v?0x08:0x00, 0x08);
257 if (rc < 0)
258 goto out;
259
260 rc = ov_write_mask(c, 0x0e, v?0x80:0x00, 0x80);
261 s->backlight = v;
262 break;
263 }
264 case OVCAMCHIP_CID_MIRROR:
265 rc = ov_write_mask(c, 0x12, v?0x40:0x00, 0x40);
266 s->mirror = v;
267 break;
268 default:
269 DDEBUG(2, &c->dev, "control not supported: %d", ctl->id);
270 return -EPERM;
271 }
272
273out:
274 DDEBUG(3, &c->dev, "id=%d, arg=%d, rc=%d", ctl->id, v, rc);
275 return rc;
276}
277
278static int ov6x20_get_control(struct i2c_client *c,
279 struct ovcamchip_control *ctl)
280{
281 struct ovcamchip *ov = i2c_get_clientdata(c);
282 struct ov6x20 *s = ov->spriv;
283 int rc = 0;
284 unsigned char val = 0;
285
286 switch (ctl->id) {
287 case OVCAMCHIP_CID_CONT:
288 rc = ov_read(c, REG_CNT, &val);
289 ctl->value = val << 8;
290 break;
291 case OVCAMCHIP_CID_BRIGHT:
292 rc = ov_read(c, REG_BRT, &val);
293 ctl->value = val << 8;
294 break;
295 case OVCAMCHIP_CID_SAT:
296 rc = ov_read(c, REG_SAT, &val);
297 ctl->value = val << 8;
298 break;
299 case OVCAMCHIP_CID_HUE:
300 rc = ov_read(c, REG_BLUE, &val);
301 ctl->value = val << 8;
302 break;
303 case OVCAMCHIP_CID_EXP:
304 rc = ov_read(c, REG_EXP, &val);
305 ctl->value = val;
306 break;
307 case OVCAMCHIP_CID_BANDFILT:
308 ctl->value = s->bandfilt;
309 break;
310 case OVCAMCHIP_CID_AUTOBRIGHT:
311 ctl->value = s->auto_brt;
312 break;
313 case OVCAMCHIP_CID_AUTOEXP:
314 ctl->value = s->auto_exp;
315 break;
316 case OVCAMCHIP_CID_BACKLIGHT:
317 ctl->value = s->backlight;
318 break;
319 case OVCAMCHIP_CID_MIRROR:
320 ctl->value = s->mirror;
321 break;
322 default:
323 DDEBUG(2, &c->dev, "control not supported: %d", ctl->id);
324 return -EPERM;
325 }
326
327 DDEBUG(3, &c->dev, "id=%d, arg=%d, rc=%d", ctl->id, ctl->value, rc);
328 return rc;
329}
330
331static int ov6x20_mode_init(struct i2c_client *c, struct ovcamchip_window *win)
332{
333 /******** QCIF-specific regs ********/
334
335 ov_write(c, 0x14, win->quarter?0x24:0x04);
336
337 /******** Palette-specific regs ********/
338
339 /* OV518 needs 8 bit multiplexed in color mode, and 16 bit in B&W */
340 if (c->adapter->id == I2C_HW_SMBUS_OV518) {
341 if (win->format == VIDEO_PALETTE_GREY)
342 ov_write_mask(c, 0x13, 0x00, 0x20);
343 else
344 ov_write_mask(c, 0x13, 0x20, 0x20);
345 } else {
346 if (win->format == VIDEO_PALETTE_GREY)
347 ov_write_mask(c, 0x13, 0x20, 0x20);
348 else
349 ov_write_mask(c, 0x13, 0x00, 0x20);
350 }
351
352 /******** Clock programming ********/
353
354 /* The OV6620 needs special handling. This prevents the
355 * severe banding that normally occurs */
356
357 /* Clock down */
358 ov_write(c, 0x2a, 0x04);
359
360 ov_write(c, 0x11, win->clockdiv);
361
362 ov_write(c, 0x2a, 0x84);
363 /* This next setting is critical. It seems to improve
364 * the gain or the contrast. The "reserved" bits seem
365 * to have some effect in this case. */
366 ov_write(c, 0x2d, 0x85); /* FIXME: This messes up banding filter */
367
368 return 0;
369}
370
371static int ov6x20_set_window(struct i2c_client *c, struct ovcamchip_window *win)
372{
373 int ret, hwscale, vwscale;
374
375 ret = ov6x20_mode_init(c, win);
376 if (ret < 0)
377 return ret;
378
379 if (win->quarter) {
380 hwscale = 0;
381 vwscale = 0;
382 } else {
383 hwscale = 1;
384 vwscale = 1; /* The datasheet says 0; it's wrong */
385 }
386
387 ov_write(c, 0x17, HWSBASE + (win->x >> hwscale));
388 ov_write(c, 0x18, HWEBASE + ((win->x + win->width) >> hwscale));
389 ov_write(c, 0x19, VWSBASE + (win->y >> vwscale));
390 ov_write(c, 0x1a, VWEBASE + ((win->y + win->height) >> vwscale));
391
392 return 0;
393}
394
395static int ov6x20_command(struct i2c_client *c, unsigned int cmd, void *arg)
396{
397 switch (cmd) {
398 case OVCAMCHIP_CMD_S_CTRL:
399 return ov6x20_set_control(c, arg);
400 case OVCAMCHIP_CMD_G_CTRL:
401 return ov6x20_get_control(c, arg);
402 case OVCAMCHIP_CMD_S_MODE:
403 return ov6x20_set_window(c, arg);
404 default:
405 DDEBUG(2, &c->dev, "command not supported: %d", cmd);
406 return -ENOIOCTLCMD;
407 }
408}
409
410struct ovcamchip_ops ov6x20_ops = {
411 .init = ov6x20_init,
412 .free = ov6x20_free,
413 .command = ov6x20_command,
414};
diff --git a/drivers/media/video/ovcamchip/ov6x30.c b/drivers/media/video/ovcamchip/ov6x30.c
deleted file mode 100644
index 73b94f51a85a..000000000000
--- a/drivers/media/video/ovcamchip/ov6x30.c
+++ /dev/null
@@ -1,373 +0,0 @@
1/* OmniVision OV6630/OV6130 Camera Chip Support Code
2 *
3 * Copyright (c) 1999-2004 Mark McClelland <mark@alpha.dyndns.org>
4 * http://alpha.dyndns.org/ov511/
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. NO WARRANTY OF ANY KIND is expressed or implied.
10 */
11
12#define DEBUG
13
14#include <linux/slab.h>
15#include "ovcamchip_priv.h"
16
17/* Registers */
18#define REG_GAIN 0x00 /* gain [5:0] */
19#define REG_BLUE 0x01 /* blue gain */
20#define REG_RED 0x02 /* red gain */
21#define REG_SAT 0x03 /* saturation [7:3] */
22#define REG_CNT 0x05 /* Y contrast [3:0] */
23#define REG_BRT 0x06 /* Y brightness */
24#define REG_SHARP 0x07 /* sharpness */
25#define REG_WB_BLUE 0x0C /* WB blue ratio [5:0] */
26#define REG_WB_RED 0x0D /* WB red ratio [5:0] */
27#define REG_EXP 0x10 /* exposure */
28
29/* Window parameters */
30#define HWSBASE 0x38
31#define HWEBASE 0x3A
32#define VWSBASE 0x05
33#define VWEBASE 0x06
34
35struct ov6x30 {
36 int auto_brt;
37 int auto_exp;
38 int backlight;
39 int bandfilt;
40 int mirror;
41};
42
43static struct ovcamchip_regvals regvals_init_6x30[] = {
44 { 0x12, 0x80 }, /* reset */
45 { 0x00, 0x1f }, /* Gain */
46 { 0x01, 0x99 }, /* Blue gain */
47 { 0x02, 0x7c }, /* Red gain */
48 { 0x03, 0xc0 }, /* Saturation */
49 { 0x05, 0x0a }, /* Contrast */
50 { 0x06, 0x95 }, /* Brightness */
51 { 0x07, 0x2d }, /* Sharpness */
52 { 0x0c, 0x20 },
53 { 0x0d, 0x20 },
54 { 0x0e, 0x20 },
55 { 0x0f, 0x05 },
56 { 0x10, 0x9a }, /* "exposure check" */
57 { 0x11, 0x00 }, /* Pixel clock = fastest */
58 { 0x12, 0x24 }, /* Enable AGC and AWB */
59 { 0x13, 0x21 },
60 { 0x14, 0x80 },
61 { 0x15, 0x01 },
62 { 0x16, 0x03 },
63 { 0x17, 0x38 },
64 { 0x18, 0xea },
65 { 0x19, 0x04 },
66 { 0x1a, 0x93 },
67 { 0x1b, 0x00 },
68 { 0x1e, 0xc4 },
69 { 0x1f, 0x04 },
70 { 0x20, 0x20 },
71 { 0x21, 0x10 },
72 { 0x22, 0x88 },
73 { 0x23, 0xc0 }, /* Crystal circuit power level */
74 { 0x25, 0x9a }, /* Increase AEC black pixel ratio */
75 { 0x26, 0xb2 }, /* BLC enable */
76 { 0x27, 0xa2 },
77 { 0x28, 0x00 },
78 { 0x29, 0x00 },
79 { 0x2a, 0x84 }, /* (keep) */
80 { 0x2b, 0xa8 }, /* (keep) */
81 { 0x2c, 0xa0 },
82 { 0x2d, 0x95 }, /* Enable auto-brightness */
83 { 0x2e, 0x88 },
84 { 0x33, 0x26 },
85 { 0x34, 0x03 },
86 { 0x36, 0x8f },
87 { 0x37, 0x80 },
88 { 0x38, 0x83 },
89 { 0x39, 0x80 },
90 { 0x3a, 0x0f },
91 { 0x3b, 0x3c },
92 { 0x3c, 0x1a },
93 { 0x3d, 0x80 },
94 { 0x3e, 0x80 },
95 { 0x3f, 0x0e },
96 { 0x40, 0x00 }, /* White bal */
97 { 0x41, 0x00 }, /* White bal */
98 { 0x42, 0x80 },
99 { 0x43, 0x3f }, /* White bal */
100 { 0x44, 0x80 },
101 { 0x45, 0x20 },
102 { 0x46, 0x20 },
103 { 0x47, 0x80 },
104 { 0x48, 0x7f },
105 { 0x49, 0x00 },
106 { 0x4a, 0x00 },
107 { 0x4b, 0x80 },
108 { 0x4c, 0xd0 },
109 { 0x4d, 0x10 }, /* U = 0.563u, V = 0.714v */
110 { 0x4e, 0x40 },
111 { 0x4f, 0x07 }, /* UV average mode, color killer: strongest */
112 { 0x50, 0xff },
113 { 0x54, 0x23 }, /* Max AGC gain: 18dB */
114 { 0x55, 0xff },
115 { 0x56, 0x12 },
116 { 0x57, 0x81 }, /* (default) */
117 { 0x58, 0x75 },
118 { 0x59, 0x01 }, /* AGC dark current compensation: +1 */
119 { 0x5a, 0x2c },
120 { 0x5b, 0x0f }, /* AWB chrominance levels */
121 { 0x5c, 0x10 },
122 { 0x3d, 0x80 },
123 { 0x27, 0xa6 },
124 /* Toggle AWB off and on */
125 { 0x12, 0x20 },
126 { 0x12, 0x24 },
127
128 { 0xff, 0xff }, /* END MARKER */
129};
130
131/* This initializes the OV6x30 camera chip and relevant variables. */
132static int ov6x30_init(struct i2c_client *c)
133{
134 struct ovcamchip *ov = i2c_get_clientdata(c);
135 struct ov6x30 *s;
136 int rc;
137
138 DDEBUG(4, &c->dev, "entered");
139
140 rc = ov_write_regvals(c, regvals_init_6x30);
141 if (rc < 0)
142 return rc;
143
144 ov->spriv = s = kzalloc(sizeof *s, GFP_KERNEL);
145 if (!s)
146 return -ENOMEM;
147
148 s->auto_brt = 1;
149 s->auto_exp = 1;
150
151 return rc;
152}
153
154static int ov6x30_free(struct i2c_client *c)
155{
156 struct ovcamchip *ov = i2c_get_clientdata(c);
157
158 kfree(ov->spriv);
159 return 0;
160}
161
162static int ov6x30_set_control(struct i2c_client *c,
163 struct ovcamchip_control *ctl)
164{
165 struct ovcamchip *ov = i2c_get_clientdata(c);
166 struct ov6x30 *s = ov->spriv;
167 int rc;
168 int v = ctl->value;
169
170 switch (ctl->id) {
171 case OVCAMCHIP_CID_CONT:
172 rc = ov_write_mask(c, REG_CNT, v >> 12, 0x0f);
173 break;
174 case OVCAMCHIP_CID_BRIGHT:
175 rc = ov_write(c, REG_BRT, v >> 8);
176 break;
177 case OVCAMCHIP_CID_SAT:
178 rc = ov_write(c, REG_SAT, v >> 8);
179 break;
180 case OVCAMCHIP_CID_HUE:
181 rc = ov_write(c, REG_RED, 0xFF - (v >> 8));
182 if (rc < 0)
183 goto out;
184
185 rc = ov_write(c, REG_BLUE, v >> 8);
186 break;
187 case OVCAMCHIP_CID_EXP:
188 rc = ov_write(c, REG_EXP, v);
189 break;
190 case OVCAMCHIP_CID_FREQ:
191 {
192 int sixty = (v == 60);
193
194 rc = ov_write(c, 0x2b, sixty?0xa8:0x28);
195 if (rc < 0)
196 goto out;
197
198 rc = ov_write(c, 0x2a, sixty?0x84:0xa4);
199 break;
200 }
201 case OVCAMCHIP_CID_BANDFILT:
202 rc = ov_write_mask(c, 0x2d, v?0x04:0x00, 0x04);
203 s->bandfilt = v;
204 break;
205 case OVCAMCHIP_CID_AUTOBRIGHT:
206 rc = ov_write_mask(c, 0x2d, v?0x10:0x00, 0x10);
207 s->auto_brt = v;
208 break;
209 case OVCAMCHIP_CID_AUTOEXP:
210 rc = ov_write_mask(c, 0x28, v?0x00:0x10, 0x10);
211 s->auto_exp = v;
212 break;
213 case OVCAMCHIP_CID_BACKLIGHT:
214 {
215 rc = ov_write_mask(c, 0x4e, v?0x80:0x60, 0xe0);
216 if (rc < 0)
217 goto out;
218
219 rc = ov_write_mask(c, 0x29, v?0x08:0x00, 0x08);
220 if (rc < 0)
221 goto out;
222
223 rc = ov_write_mask(c, 0x28, v?0x02:0x00, 0x02);
224 s->backlight = v;
225 break;
226 }
227 case OVCAMCHIP_CID_MIRROR:
228 rc = ov_write_mask(c, 0x12, v?0x40:0x00, 0x40);
229 s->mirror = v;
230 break;
231 default:
232 DDEBUG(2, &c->dev, "control not supported: %d", ctl->id);
233 return -EPERM;
234 }
235
236out:
237 DDEBUG(3, &c->dev, "id=%d, arg=%d, rc=%d", ctl->id, v, rc);
238 return rc;
239}
240
241static int ov6x30_get_control(struct i2c_client *c,
242 struct ovcamchip_control *ctl)
243{
244 struct ovcamchip *ov = i2c_get_clientdata(c);
245 struct ov6x30 *s = ov->spriv;
246 int rc = 0;
247 unsigned char val = 0;
248
249 switch (ctl->id) {
250 case OVCAMCHIP_CID_CONT:
251 rc = ov_read(c, REG_CNT, &val);
252 ctl->value = (val & 0x0f) << 12;
253 break;
254 case OVCAMCHIP_CID_BRIGHT:
255 rc = ov_read(c, REG_BRT, &val);
256 ctl->value = val << 8;
257 break;
258 case OVCAMCHIP_CID_SAT:
259 rc = ov_read(c, REG_SAT, &val);
260 ctl->value = val << 8;
261 break;
262 case OVCAMCHIP_CID_HUE:
263 rc = ov_read(c, REG_BLUE, &val);
264 ctl->value = val << 8;
265 break;
266 case OVCAMCHIP_CID_EXP:
267 rc = ov_read(c, REG_EXP, &val);
268 ctl->value = val;
269 break;
270 case OVCAMCHIP_CID_BANDFILT:
271 ctl->value = s->bandfilt;
272 break;
273 case OVCAMCHIP_CID_AUTOBRIGHT:
274 ctl->value = s->auto_brt;
275 break;
276 case OVCAMCHIP_CID_AUTOEXP:
277 ctl->value = s->auto_exp;
278 break;
279 case OVCAMCHIP_CID_BACKLIGHT:
280 ctl->value = s->backlight;
281 break;
282 case OVCAMCHIP_CID_MIRROR:
283 ctl->value = s->mirror;
284 break;
285 default:
286 DDEBUG(2, &c->dev, "control not supported: %d", ctl->id);
287 return -EPERM;
288 }
289
290 DDEBUG(3, &c->dev, "id=%d, arg=%d, rc=%d", ctl->id, ctl->value, rc);
291 return rc;
292}
293
294static int ov6x30_mode_init(struct i2c_client *c, struct ovcamchip_window *win)
295{
296 /******** QCIF-specific regs ********/
297
298 ov_write_mask(c, 0x14, win->quarter?0x20:0x00, 0x20);
299
300 /******** Palette-specific regs ********/
301
302 if (win->format == VIDEO_PALETTE_GREY) {
303 if (c->adapter->id == I2C_HW_SMBUS_OV518) {
304 /* Do nothing - we're already in 8-bit mode */
305 } else {
306 ov_write_mask(c, 0x13, 0x20, 0x20);
307 }
308 } else {
309 /* The OV518 needs special treatment. Although both the OV518
310 * and the OV6630 support a 16-bit video bus, only the 8 bit Y
311 * bus is actually used. The UV bus is tied to ground.
312 * Therefore, the OV6630 needs to be in 8-bit multiplexed
313 * output mode */
314
315 if (c->adapter->id == I2C_HW_SMBUS_OV518) {
316 /* Do nothing - we want to stay in 8-bit mode */
317 /* Warning: Messing with reg 0x13 breaks OV518 color */
318 } else {
319 ov_write_mask(c, 0x13, 0x00, 0x20);
320 }
321 }
322
323 /******** Clock programming ********/
324
325 ov_write(c, 0x11, win->clockdiv);
326
327 return 0;
328}
329
330static int ov6x30_set_window(struct i2c_client *c, struct ovcamchip_window *win)
331{
332 int ret, hwscale, vwscale;
333
334 ret = ov6x30_mode_init(c, win);
335 if (ret < 0)
336 return ret;
337
338 if (win->quarter) {
339 hwscale = 0;
340 vwscale = 0;
341 } else {
342 hwscale = 1;
343 vwscale = 1; /* The datasheet says 0; it's wrong */
344 }
345
346 ov_write(c, 0x17, HWSBASE + (win->x >> hwscale));
347 ov_write(c, 0x18, HWEBASE + ((win->x + win->width) >> hwscale));
348 ov_write(c, 0x19, VWSBASE + (win->y >> vwscale));
349 ov_write(c, 0x1a, VWEBASE + ((win->y + win->height) >> vwscale));
350
351 return 0;
352}
353
354static int ov6x30_command(struct i2c_client *c, unsigned int cmd, void *arg)
355{
356 switch (cmd) {
357 case OVCAMCHIP_CMD_S_CTRL:
358 return ov6x30_set_control(c, arg);
359 case OVCAMCHIP_CMD_G_CTRL:
360 return ov6x30_get_control(c, arg);
361 case OVCAMCHIP_CMD_S_MODE:
362 return ov6x30_set_window(c, arg);
363 default:
364 DDEBUG(2, &c->dev, "command not supported: %d", cmd);
365 return -ENOIOCTLCMD;
366 }
367}
368
369struct ovcamchip_ops ov6x30_ops = {
370 .init = ov6x30_init,
371 .free = ov6x30_free,
372 .command = ov6x30_command,
373};
diff --git a/drivers/media/video/ovcamchip/ov76be.c b/drivers/media/video/ovcamchip/ov76be.c
deleted file mode 100644
index 11f6be924d8b..000000000000
--- a/drivers/media/video/ovcamchip/ov76be.c
+++ /dev/null
@@ -1,302 +0,0 @@
1/* OmniVision OV76BE Camera Chip Support Code
2 *
3 * Copyright (c) 1999-2004 Mark McClelland <mark@alpha.dyndns.org>
4 * http://alpha.dyndns.org/ov511/
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. NO WARRANTY OF ANY KIND is expressed or implied.
10 */
11
12#define DEBUG
13
14#include <linux/slab.h>
15#include "ovcamchip_priv.h"
16
17/* OV7610 registers: Since the OV76BE is undocumented, we'll settle for these
18 * for now. */
19#define REG_GAIN 0x00 /* gain [5:0] */
20#define REG_BLUE 0x01 /* blue channel balance */
21#define REG_RED 0x02 /* red channel balance */
22#define REG_SAT 0x03 /* saturation */
23#define REG_CNT 0x05 /* Y contrast */
24#define REG_BRT 0x06 /* Y brightness */
25#define REG_BLUE_BIAS 0x0C /* blue channel bias [5:0] */
26#define REG_RED_BIAS 0x0D /* red channel bias [5:0] */
27#define REG_GAMMA_COEFF 0x0E /* gamma settings */
28#define REG_WB_RANGE 0x0F /* AEC/ALC/S-AWB settings */
29#define REG_EXP 0x10 /* manual exposure setting */
30#define REG_CLOCK 0x11 /* polarity/clock prescaler */
31#define REG_FIELD_DIVIDE 0x16 /* field interval/mode settings */
32#define REG_HWIN_START 0x17 /* horizontal window start */
33#define REG_HWIN_END 0x18 /* horizontal window end */
34#define REG_VWIN_START 0x19 /* vertical window start */
35#define REG_VWIN_END 0x1A /* vertical window end */
36#define REG_PIXEL_SHIFT 0x1B /* pixel shift */
37#define REG_YOFFSET 0x21 /* Y channel offset */
38#define REG_UOFFSET 0x22 /* U channel offset */
39#define REG_ECW 0x24 /* exposure white level for AEC */
40#define REG_ECB 0x25 /* exposure black level for AEC */
41#define REG_FRAMERATE_H 0x2A /* frame rate MSB + misc */
42#define REG_FRAMERATE_L 0x2B /* frame rate LSB */
43#define REG_ALC 0x2C /* Auto Level Control settings */
44#define REG_VOFFSET 0x2E /* V channel offset adjustment */
45#define REG_ARRAY_BIAS 0x2F /* array bias -- don't change */
46#define REG_YGAMMA 0x33 /* misc gamma settings [7:6] */
47#define REG_BIAS_ADJUST 0x34 /* misc bias settings */
48
49/* Window parameters */
50#define HWSBASE 0x38
51#define HWEBASE 0x3a
52#define VWSBASE 0x05
53#define VWEBASE 0x05
54
55struct ov76be {
56 int auto_brt;
57 int auto_exp;
58 int bandfilt;
59 int mirror;
60};
61
62/* NOTE: These are the same as the 7x10 settings, but should eventually be
63 * optimized for the OV76BE */
64static struct ovcamchip_regvals regvals_init_76be[] = {
65 { 0x10, 0xff },
66 { 0x16, 0x03 },
67 { 0x28, 0x24 },
68 { 0x2b, 0xac },
69 { 0x12, 0x00 },
70 { 0x38, 0x81 },
71 { 0x28, 0x24 }, /* 0c */
72 { 0x0f, 0x85 }, /* lg's setting */
73 { 0x15, 0x01 },
74 { 0x20, 0x1c },
75 { 0x23, 0x2a },
76 { 0x24, 0x10 },
77 { 0x25, 0x8a },
78 { 0x26, 0xa2 },
79 { 0x27, 0xc2 },
80 { 0x2a, 0x04 },
81 { 0x2c, 0xfe },
82 { 0x2d, 0x93 },
83 { 0x30, 0x71 },
84 { 0x31, 0x60 },
85 { 0x32, 0x26 },
86 { 0x33, 0x20 },
87 { 0x34, 0x48 },
88 { 0x12, 0x24 },
89 { 0x11, 0x01 },
90 { 0x0c, 0x24 },
91 { 0x0d, 0x24 },
92 { 0xff, 0xff }, /* END MARKER */
93};
94
95/* This initializes the OV76be camera chip and relevant variables. */
96static int ov76be_init(struct i2c_client *c)
97{
98 struct ovcamchip *ov = i2c_get_clientdata(c);
99 struct ov76be *s;
100 int rc;
101
102 DDEBUG(4, &c->dev, "entered");
103
104 rc = ov_write_regvals(c, regvals_init_76be);
105 if (rc < 0)
106 return rc;
107
108 ov->spriv = s = kzalloc(sizeof *s, GFP_KERNEL);
109 if (!s)
110 return -ENOMEM;
111
112 s->auto_brt = 1;
113 s->auto_exp = 1;
114
115 return rc;
116}
117
118static int ov76be_free(struct i2c_client *c)
119{
120 struct ovcamchip *ov = i2c_get_clientdata(c);
121
122 kfree(ov->spriv);
123 return 0;
124}
125
126static int ov76be_set_control(struct i2c_client *c,
127 struct ovcamchip_control *ctl)
128{
129 struct ovcamchip *ov = i2c_get_clientdata(c);
130 struct ov76be *s = ov->spriv;
131 int rc;
132 int v = ctl->value;
133
134 switch (ctl->id) {
135 case OVCAMCHIP_CID_BRIGHT:
136 rc = ov_write(c, REG_BRT, v >> 8);
137 break;
138 case OVCAMCHIP_CID_SAT:
139 rc = ov_write(c, REG_SAT, v >> 8);
140 break;
141 case OVCAMCHIP_CID_EXP:
142 rc = ov_write(c, REG_EXP, v);
143 break;
144 case OVCAMCHIP_CID_FREQ:
145 {
146 int sixty = (v == 60);
147
148 rc = ov_write_mask(c, 0x2a, sixty?0x00:0x80, 0x80);
149 if (rc < 0)
150 goto out;
151
152 rc = ov_write(c, 0x2b, sixty?0x00:0xac);
153 if (rc < 0)
154 goto out;
155
156 rc = ov_write_mask(c, 0x76, 0x01, 0x01);
157 break;
158 }
159 case OVCAMCHIP_CID_BANDFILT:
160 rc = ov_write_mask(c, 0x2d, v?0x04:0x00, 0x04);
161 s->bandfilt = v;
162 break;
163 case OVCAMCHIP_CID_AUTOBRIGHT:
164 rc = ov_write_mask(c, 0x2d, v?0x10:0x00, 0x10);
165 s->auto_brt = v;
166 break;
167 case OVCAMCHIP_CID_AUTOEXP:
168 rc = ov_write_mask(c, 0x13, v?0x01:0x00, 0x01);
169 s->auto_exp = v;
170 break;
171 case OVCAMCHIP_CID_MIRROR:
172 rc = ov_write_mask(c, 0x12, v?0x40:0x00, 0x40);
173 s->mirror = v;
174 break;
175 default:
176 DDEBUG(2, &c->dev, "control not supported: %d", ctl->id);
177 return -EPERM;
178 }
179
180out:
181 DDEBUG(3, &c->dev, "id=%d, arg=%d, rc=%d", ctl->id, v, rc);
182 return rc;
183}
184
185static int ov76be_get_control(struct i2c_client *c,
186 struct ovcamchip_control *ctl)
187{
188 struct ovcamchip *ov = i2c_get_clientdata(c);
189 struct ov76be *s = ov->spriv;
190 int rc = 0;
191 unsigned char val = 0;
192
193 switch (ctl->id) {
194 case OVCAMCHIP_CID_BRIGHT:
195 rc = ov_read(c, REG_BRT, &val);
196 ctl->value = val << 8;
197 break;
198 case OVCAMCHIP_CID_SAT:
199 rc = ov_read(c, REG_SAT, &val);
200 ctl->value = val << 8;
201 break;
202 case OVCAMCHIP_CID_EXP:
203 rc = ov_read(c, REG_EXP, &val);
204 ctl->value = val;
205 break;
206 case OVCAMCHIP_CID_BANDFILT:
207 ctl->value = s->bandfilt;
208 break;
209 case OVCAMCHIP_CID_AUTOBRIGHT:
210 ctl->value = s->auto_brt;
211 break;
212 case OVCAMCHIP_CID_AUTOEXP:
213 ctl->value = s->auto_exp;
214 break;
215 case OVCAMCHIP_CID_MIRROR:
216 ctl->value = s->mirror;
217 break;
218 default:
219 DDEBUG(2, &c->dev, "control not supported: %d", ctl->id);
220 return -EPERM;
221 }
222
223 DDEBUG(3, &c->dev, "id=%d, arg=%d, rc=%d", ctl->id, ctl->value, rc);
224 return rc;
225}
226
227static int ov76be_mode_init(struct i2c_client *c, struct ovcamchip_window *win)
228{
229 int qvga = win->quarter;
230
231 /******** QVGA-specific regs ********/
232
233 ov_write(c, 0x14, qvga?0xa4:0x84);
234
235 /******** Palette-specific regs ********/
236
237 if (win->format == VIDEO_PALETTE_GREY) {
238 ov_write_mask(c, 0x0e, 0x40, 0x40);
239 ov_write_mask(c, 0x13, 0x20, 0x20);
240 } else {
241 ov_write_mask(c, 0x0e, 0x00, 0x40);
242 ov_write_mask(c, 0x13, 0x00, 0x20);
243 }
244
245 /******** Clock programming ********/
246
247 ov_write(c, 0x11, win->clockdiv);
248
249 /******** Resolution-specific ********/
250
251 if (win->width == 640 && win->height == 480)
252 ov_write(c, 0x35, 0x9e);
253 else
254 ov_write(c, 0x35, 0x1e);
255
256 return 0;
257}
258
259static int ov76be_set_window(struct i2c_client *c, struct ovcamchip_window *win)
260{
261 int ret, hwscale, vwscale;
262
263 ret = ov76be_mode_init(c, win);
264 if (ret < 0)
265 return ret;
266
267 if (win->quarter) {
268 hwscale = 1;
269 vwscale = 0;
270 } else {
271 hwscale = 2;
272 vwscale = 1;
273 }
274
275 ov_write(c, 0x17, HWSBASE + (win->x >> hwscale));
276 ov_write(c, 0x18, HWEBASE + ((win->x + win->width) >> hwscale));
277 ov_write(c, 0x19, VWSBASE + (win->y >> vwscale));
278 ov_write(c, 0x1a, VWEBASE + ((win->y + win->height) >> vwscale));
279
280 return 0;
281}
282
283static int ov76be_command(struct i2c_client *c, unsigned int cmd, void *arg)
284{
285 switch (cmd) {
286 case OVCAMCHIP_CMD_S_CTRL:
287 return ov76be_set_control(c, arg);
288 case OVCAMCHIP_CMD_G_CTRL:
289 return ov76be_get_control(c, arg);
290 case OVCAMCHIP_CMD_S_MODE:
291 return ov76be_set_window(c, arg);
292 default:
293 DDEBUG(2, &c->dev, "command not supported: %d", cmd);
294 return -ENOIOCTLCMD;
295 }
296}
297
298struct ovcamchip_ops ov76be_ops = {
299 .init = ov76be_init,
300 .free = ov76be_free,
301 .command = ov76be_command,
302};
diff --git a/drivers/media/video/ovcamchip/ov7x10.c b/drivers/media/video/ovcamchip/ov7x10.c
deleted file mode 100644
index 5206e7913924..000000000000
--- a/drivers/media/video/ovcamchip/ov7x10.c
+++ /dev/null
@@ -1,334 +0,0 @@
1/* OmniVision OV7610/OV7110 Camera Chip Support Code
2 *
3 * Copyright (c) 1999-2004 Mark McClelland <mark@alpha.dyndns.org>
4 * http://alpha.dyndns.org/ov511/
5 *
6 * Color fixes by by Orion Sky Lawlor <olawlor@acm.org> (2/26/2000)
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version. NO WARRANTY OF ANY KIND is expressed or implied.
12 */
13
14#define DEBUG
15
16#include <linux/slab.h>
17#include "ovcamchip_priv.h"
18
19/* Registers */
20#define REG_GAIN 0x00 /* gain [5:0] */
21#define REG_BLUE 0x01 /* blue channel balance */
22#define REG_RED 0x02 /* red channel balance */
23#define REG_SAT 0x03 /* saturation */
24#define REG_CNT 0x05 /* Y contrast */
25#define REG_BRT 0x06 /* Y brightness */
26#define REG_BLUE_BIAS 0x0C /* blue channel bias [5:0] */
27#define REG_RED_BIAS 0x0D /* red channel bias [5:0] */
28#define REG_GAMMA_COEFF 0x0E /* gamma settings */
29#define REG_WB_RANGE 0x0F /* AEC/ALC/S-AWB settings */
30#define REG_EXP 0x10 /* manual exposure setting */
31#define REG_CLOCK 0x11 /* polarity/clock prescaler */
32#define REG_FIELD_DIVIDE 0x16 /* field interval/mode settings */
33#define REG_HWIN_START 0x17 /* horizontal window start */
34#define REG_HWIN_END 0x18 /* horizontal window end */
35#define REG_VWIN_START 0x19 /* vertical window start */
36#define REG_VWIN_END 0x1A /* vertical window end */
37#define REG_PIXEL_SHIFT 0x1B /* pixel shift */
38#define REG_YOFFSET 0x21 /* Y channel offset */
39#define REG_UOFFSET 0x22 /* U channel offset */
40#define REG_ECW 0x24 /* exposure white level for AEC */
41#define REG_ECB 0x25 /* exposure black level for AEC */
42#define REG_FRAMERATE_H 0x2A /* frame rate MSB + misc */
43#define REG_FRAMERATE_L 0x2B /* frame rate LSB */
44#define REG_ALC 0x2C /* Auto Level Control settings */
45#define REG_VOFFSET 0x2E /* V channel offset adjustment */
46#define REG_ARRAY_BIAS 0x2F /* array bias -- don't change */
47#define REG_YGAMMA 0x33 /* misc gamma settings [7:6] */
48#define REG_BIAS_ADJUST 0x34 /* misc bias settings */
49
50/* Window parameters */
51#define HWSBASE 0x38
52#define HWEBASE 0x3a
53#define VWSBASE 0x05
54#define VWEBASE 0x05
55
56struct ov7x10 {
57 int auto_brt;
58 int auto_exp;
59 int bandfilt;
60 int mirror;
61};
62
63/* Lawrence Glaister <lg@jfm.bc.ca> reports:
64 *
65 * Register 0x0f in the 7610 has the following effects:
66 *
67 * 0x85 (AEC method 1): Best overall, good contrast range
68 * 0x45 (AEC method 2): Very overexposed
69 * 0xa5 (spec sheet default): Ok, but the black level is
70 * shifted resulting in loss of contrast
71 * 0x05 (old driver setting): very overexposed, too much
72 * contrast
73 */
74static struct ovcamchip_regvals regvals_init_7x10[] = {
75 { 0x10, 0xff },
76 { 0x16, 0x03 },
77 { 0x28, 0x24 },
78 { 0x2b, 0xac },
79 { 0x12, 0x00 },
80 { 0x38, 0x81 },
81 { 0x28, 0x24 }, /* 0c */
82 { 0x0f, 0x85 }, /* lg's setting */
83 { 0x15, 0x01 },
84 { 0x20, 0x1c },
85 { 0x23, 0x2a },
86 { 0x24, 0x10 },
87 { 0x25, 0x8a },
88 { 0x26, 0xa2 },
89 { 0x27, 0xc2 },
90 { 0x2a, 0x04 },
91 { 0x2c, 0xfe },
92 { 0x2d, 0x93 },
93 { 0x30, 0x71 },
94 { 0x31, 0x60 },
95 { 0x32, 0x26 },
96 { 0x33, 0x20 },
97 { 0x34, 0x48 },
98 { 0x12, 0x24 },
99 { 0x11, 0x01 },
100 { 0x0c, 0x24 },
101 { 0x0d, 0x24 },
102 { 0xff, 0xff }, /* END MARKER */
103};
104
105/* This initializes the OV7x10 camera chip and relevant variables. */
106static int ov7x10_init(struct i2c_client *c)
107{
108 struct ovcamchip *ov = i2c_get_clientdata(c);
109 struct ov7x10 *s;
110 int rc;
111
112 DDEBUG(4, &c->dev, "entered");
113
114 rc = ov_write_regvals(c, regvals_init_7x10);
115 if (rc < 0)
116 return rc;
117
118 ov->spriv = s = kzalloc(sizeof *s, GFP_KERNEL);
119 if (!s)
120 return -ENOMEM;
121
122 s->auto_brt = 1;
123 s->auto_exp = 1;
124
125 return rc;
126}
127
128static int ov7x10_free(struct i2c_client *c)
129{
130 struct ovcamchip *ov = i2c_get_clientdata(c);
131
132 kfree(ov->spriv);
133 return 0;
134}
135
136static int ov7x10_set_control(struct i2c_client *c,
137 struct ovcamchip_control *ctl)
138{
139 struct ovcamchip *ov = i2c_get_clientdata(c);
140 struct ov7x10 *s = ov->spriv;
141 int rc;
142 int v = ctl->value;
143
144 switch (ctl->id) {
145 case OVCAMCHIP_CID_CONT:
146 rc = ov_write(c, REG_CNT, v >> 8);
147 break;
148 case OVCAMCHIP_CID_BRIGHT:
149 rc = ov_write(c, REG_BRT, v >> 8);
150 break;
151 case OVCAMCHIP_CID_SAT:
152 rc = ov_write(c, REG_SAT, v >> 8);
153 break;
154 case OVCAMCHIP_CID_HUE:
155 rc = ov_write(c, REG_RED, 0xFF - (v >> 8));
156 if (rc < 0)
157 goto out;
158
159 rc = ov_write(c, REG_BLUE, v >> 8);
160 break;
161 case OVCAMCHIP_CID_EXP:
162 rc = ov_write(c, REG_EXP, v);
163 break;
164 case OVCAMCHIP_CID_FREQ:
165 {
166 int sixty = (v == 60);
167
168 rc = ov_write_mask(c, 0x2a, sixty?0x00:0x80, 0x80);
169 if (rc < 0)
170 goto out;
171
172 rc = ov_write(c, 0x2b, sixty?0x00:0xac);
173 if (rc < 0)
174 goto out;
175
176 rc = ov_write_mask(c, 0x13, 0x10, 0x10);
177 if (rc < 0)
178 goto out;
179
180 rc = ov_write_mask(c, 0x13, 0x00, 0x10);
181 break;
182 }
183 case OVCAMCHIP_CID_BANDFILT:
184 rc = ov_write_mask(c, 0x2d, v?0x04:0x00, 0x04);
185 s->bandfilt = v;
186 break;
187 case OVCAMCHIP_CID_AUTOBRIGHT:
188 rc = ov_write_mask(c, 0x2d, v?0x10:0x00, 0x10);
189 s->auto_brt = v;
190 break;
191 case OVCAMCHIP_CID_AUTOEXP:
192 rc = ov_write_mask(c, 0x29, v?0x00:0x80, 0x80);
193 s->auto_exp = v;
194 break;
195 case OVCAMCHIP_CID_MIRROR:
196 rc = ov_write_mask(c, 0x12, v?0x40:0x00, 0x40);
197 s->mirror = v;
198 break;
199 default:
200 DDEBUG(2, &c->dev, "control not supported: %d", ctl->id);
201 return -EPERM;
202 }
203
204out:
205 DDEBUG(3, &c->dev, "id=%d, arg=%d, rc=%d", ctl->id, v, rc);
206 return rc;
207}
208
209static int ov7x10_get_control(struct i2c_client *c,
210 struct ovcamchip_control *ctl)
211{
212 struct ovcamchip *ov = i2c_get_clientdata(c);
213 struct ov7x10 *s = ov->spriv;
214 int rc = 0;
215 unsigned char val = 0;
216
217 switch (ctl->id) {
218 case OVCAMCHIP_CID_CONT:
219 rc = ov_read(c, REG_CNT, &val);
220 ctl->value = val << 8;
221 break;
222 case OVCAMCHIP_CID_BRIGHT:
223 rc = ov_read(c, REG_BRT, &val);
224 ctl->value = val << 8;
225 break;
226 case OVCAMCHIP_CID_SAT:
227 rc = ov_read(c, REG_SAT, &val);
228 ctl->value = val << 8;
229 break;
230 case OVCAMCHIP_CID_HUE:
231 rc = ov_read(c, REG_BLUE, &val);
232 ctl->value = val << 8;
233 break;
234 case OVCAMCHIP_CID_EXP:
235 rc = ov_read(c, REG_EXP, &val);
236 ctl->value = val;
237 break;
238 case OVCAMCHIP_CID_BANDFILT:
239 ctl->value = s->bandfilt;
240 break;
241 case OVCAMCHIP_CID_AUTOBRIGHT:
242 ctl->value = s->auto_brt;
243 break;
244 case OVCAMCHIP_CID_AUTOEXP:
245 ctl->value = s->auto_exp;
246 break;
247 case OVCAMCHIP_CID_MIRROR:
248 ctl->value = s->mirror;
249 break;
250 default:
251 DDEBUG(2, &c->dev, "control not supported: %d", ctl->id);
252 return -EPERM;
253 }
254
255 DDEBUG(3, &c->dev, "id=%d, arg=%d, rc=%d", ctl->id, ctl->value, rc);
256 return rc;
257}
258
259static int ov7x10_mode_init(struct i2c_client *c, struct ovcamchip_window *win)
260{
261 int qvga = win->quarter;
262
263 /******** QVGA-specific regs ********/
264
265 ov_write(c, 0x14, qvga?0x24:0x04);
266
267 /******** Palette-specific regs ********/
268
269 if (win->format == VIDEO_PALETTE_GREY) {
270 ov_write_mask(c, 0x0e, 0x40, 0x40);
271 ov_write_mask(c, 0x13, 0x20, 0x20);
272 } else {
273 ov_write_mask(c, 0x0e, 0x00, 0x40);
274 ov_write_mask(c, 0x13, 0x00, 0x20);
275 }
276
277 /******** Clock programming ********/
278
279 ov_write(c, 0x11, win->clockdiv);
280
281 /******** Resolution-specific ********/
282
283 if (win->width == 640 && win->height == 480)
284 ov_write(c, 0x35, 0x9e);
285 else
286 ov_write(c, 0x35, 0x1e);
287
288 return 0;
289}
290
291static int ov7x10_set_window(struct i2c_client *c, struct ovcamchip_window *win)
292{
293 int ret, hwscale, vwscale;
294
295 ret = ov7x10_mode_init(c, win);
296 if (ret < 0)
297 return ret;
298
299 if (win->quarter) {
300 hwscale = 1;
301 vwscale = 0;
302 } else {
303 hwscale = 2;
304 vwscale = 1;
305 }
306
307 ov_write(c, 0x17, HWSBASE + (win->x >> hwscale));
308 ov_write(c, 0x18, HWEBASE + ((win->x + win->width) >> hwscale));
309 ov_write(c, 0x19, VWSBASE + (win->y >> vwscale));
310 ov_write(c, 0x1a, VWEBASE + ((win->y + win->height) >> vwscale));
311
312 return 0;
313}
314
315static int ov7x10_command(struct i2c_client *c, unsigned int cmd, void *arg)
316{
317 switch (cmd) {
318 case OVCAMCHIP_CMD_S_CTRL:
319 return ov7x10_set_control(c, arg);
320 case OVCAMCHIP_CMD_G_CTRL:
321 return ov7x10_get_control(c, arg);
322 case OVCAMCHIP_CMD_S_MODE:
323 return ov7x10_set_window(c, arg);
324 default:
325 DDEBUG(2, &c->dev, "command not supported: %d", cmd);
326 return -ENOIOCTLCMD;
327 }
328}
329
330struct ovcamchip_ops ov7x10_ops = {
331 .init = ov7x10_init,
332 .free = ov7x10_free,
333 .command = ov7x10_command,
334};
diff --git a/drivers/media/video/ovcamchip/ov7x20.c b/drivers/media/video/ovcamchip/ov7x20.c
deleted file mode 100644
index 8e26ae338f31..000000000000
--- a/drivers/media/video/ovcamchip/ov7x20.c
+++ /dev/null
@@ -1,454 +0,0 @@
1/* OmniVision OV7620/OV7120 Camera Chip Support Code
2 *
3 * Copyright (c) 1999-2004 Mark McClelland <mark@alpha.dyndns.org>
4 * http://alpha.dyndns.org/ov511/
5 *
6 * OV7620 fixes by Charl P. Botha <cpbotha@ieee.org>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version. NO WARRANTY OF ANY KIND is expressed or implied.
12 */
13
14#define DEBUG
15
16#include <linux/slab.h>
17#include "ovcamchip_priv.h"
18
19/* Registers */
20#define REG_GAIN 0x00 /* gain [5:0] */
21#define REG_BLUE 0x01 /* blue gain */
22#define REG_RED 0x02 /* red gain */
23#define REG_SAT 0x03 /* saturation */
24#define REG_BRT 0x06 /* Y brightness */
25#define REG_SHARP 0x07 /* analog sharpness */
26#define REG_BLUE_BIAS 0x0C /* WB blue ratio [5:0] */
27#define REG_RED_BIAS 0x0D /* WB red ratio [5:0] */
28#define REG_EXP 0x10 /* exposure */
29
30/* Default control settings. Values are in terms of V4L2 controls. */
31#define OV7120_DFL_BRIGHT 0x60
32#define OV7620_DFL_BRIGHT 0x60
33#define OV7120_DFL_SAT 0xb0
34#define OV7620_DFL_SAT 0xc0
35#define DFL_AUTO_EXP 1
36#define DFL_AUTO_GAIN 1
37#define OV7120_DFL_GAIN 0x00
38#define OV7620_DFL_GAIN 0x00
39/* NOTE: Since autoexposure is the default, these aren't programmed into the
40 * OV7x20 chip. They are just here because V4L2 expects a default */
41#define OV7120_DFL_EXP 0x7f
42#define OV7620_DFL_EXP 0x7f
43
44/* Window parameters */
45#define HWSBASE 0x2F /* From 7620.SET (spec is wrong) */
46#define HWEBASE 0x2F
47#define VWSBASE 0x05
48#define VWEBASE 0x05
49
50struct ov7x20 {
51 int auto_brt;
52 int auto_exp;
53 int auto_gain;
54 int backlight;
55 int bandfilt;
56 int mirror;
57};
58
59/* Contrast look-up table */
60static unsigned char ctab[] = {
61 0x01, 0x05, 0x09, 0x11, 0x15, 0x35, 0x37, 0x57,
62 0x5b, 0xa5, 0xa7, 0xc7, 0xc9, 0xcf, 0xef, 0xff
63};
64
65/* Settings for (Black & White) OV7120 camera chip */
66static struct ovcamchip_regvals regvals_init_7120[] = {
67 { 0x12, 0x80 }, /* reset */
68 { 0x13, 0x00 }, /* Autoadjust off */
69 { 0x12, 0x20 }, /* Disable AWB */
70 { 0x13, DFL_AUTO_GAIN?0x01:0x00 }, /* Autoadjust on (if desired) */
71 { 0x00, OV7120_DFL_GAIN },
72 { 0x01, 0x80 },
73 { 0x02, 0x80 },
74 { 0x03, OV7120_DFL_SAT },
75 { 0x06, OV7120_DFL_BRIGHT },
76 { 0x07, 0x00 },
77 { 0x0c, 0x20 },
78 { 0x0d, 0x20 },
79 { 0x11, 0x01 },
80 { 0x14, 0x84 },
81 { 0x15, 0x01 },
82 { 0x16, 0x03 },
83 { 0x17, 0x2f },
84 { 0x18, 0xcf },
85 { 0x19, 0x06 },
86 { 0x1a, 0xf5 },
87 { 0x1b, 0x00 },
88 { 0x20, 0x08 },
89 { 0x21, 0x80 },
90 { 0x22, 0x80 },
91 { 0x23, 0x00 },
92 { 0x26, 0xa0 },
93 { 0x27, 0xfa },
94 { 0x28, 0x20 }, /* DON'T set bit 6. It is for the OV7620 only */
95 { 0x29, DFL_AUTO_EXP?0x00:0x80 },
96 { 0x2a, 0x10 },
97 { 0x2b, 0x00 },
98 { 0x2c, 0x88 },
99 { 0x2d, 0x95 },
100 { 0x2e, 0x80 },
101 { 0x2f, 0x44 },
102 { 0x60, 0x20 },
103 { 0x61, 0x02 },
104 { 0x62, 0x5f },
105 { 0x63, 0xd5 },
106 { 0x64, 0x57 },
107 { 0x65, 0x83 }, /* OV says "don't change this value" */
108 { 0x66, 0x55 },
109 { 0x67, 0x92 },
110 { 0x68, 0xcf },
111 { 0x69, 0x76 },
112 { 0x6a, 0x22 },
113 { 0x6b, 0xe2 },
114 { 0x6c, 0x40 },
115 { 0x6d, 0x48 },
116 { 0x6e, 0x80 },
117 { 0x6f, 0x0d },
118 { 0x70, 0x89 },
119 { 0x71, 0x00 },
120 { 0x72, 0x14 },
121 { 0x73, 0x54 },
122 { 0x74, 0xa0 },
123 { 0x75, 0x8e },
124 { 0x76, 0x00 },
125 { 0x77, 0xff },
126 { 0x78, 0x80 },
127 { 0x79, 0x80 },
128 { 0x7a, 0x80 },
129 { 0x7b, 0xe6 },
130 { 0x7c, 0x00 },
131 { 0x24, 0x3a },
132 { 0x25, 0x60 },
133 { 0xff, 0xff }, /* END MARKER */
134};
135
136/* Settings for (color) OV7620 camera chip */
137static struct ovcamchip_regvals regvals_init_7620[] = {
138 { 0x12, 0x80 }, /* reset */
139 { 0x00, OV7620_DFL_GAIN },
140 { 0x01, 0x80 },
141 { 0x02, 0x80 },
142 { 0x03, OV7620_DFL_SAT },
143 { 0x06, OV7620_DFL_BRIGHT },
144 { 0x07, 0x00 },
145 { 0x0c, 0x24 },
146 { 0x0c, 0x24 },
147 { 0x0d, 0x24 },
148 { 0x11, 0x01 },
149 { 0x12, 0x24 },
150 { 0x13, DFL_AUTO_GAIN?0x01:0x00 },
151 { 0x14, 0x84 },
152 { 0x15, 0x01 },
153 { 0x16, 0x03 },
154 { 0x17, 0x2f },
155 { 0x18, 0xcf },
156 { 0x19, 0x06 },
157 { 0x1a, 0xf5 },
158 { 0x1b, 0x00 },
159 { 0x20, 0x18 },
160 { 0x21, 0x80 },
161 { 0x22, 0x80 },
162 { 0x23, 0x00 },
163 { 0x26, 0xa2 },
164 { 0x27, 0xea },
165 { 0x28, 0x20 },
166 { 0x29, DFL_AUTO_EXP?0x00:0x80 },
167 { 0x2a, 0x10 },
168 { 0x2b, 0x00 },
169 { 0x2c, 0x88 },
170 { 0x2d, 0x91 },
171 { 0x2e, 0x80 },
172 { 0x2f, 0x44 },
173 { 0x60, 0x27 },
174 { 0x61, 0x02 },
175 { 0x62, 0x5f },
176 { 0x63, 0xd5 },
177 { 0x64, 0x57 },
178 { 0x65, 0x83 },
179 { 0x66, 0x55 },
180 { 0x67, 0x92 },
181 { 0x68, 0xcf },
182 { 0x69, 0x76 },
183 { 0x6a, 0x22 },
184 { 0x6b, 0x00 },
185 { 0x6c, 0x02 },
186 { 0x6d, 0x44 },
187 { 0x6e, 0x80 },
188 { 0x6f, 0x1d },
189 { 0x70, 0x8b },
190 { 0x71, 0x00 },
191 { 0x72, 0x14 },
192 { 0x73, 0x54 },
193 { 0x74, 0x00 },
194 { 0x75, 0x8e },
195 { 0x76, 0x00 },
196 { 0x77, 0xff },
197 { 0x78, 0x80 },
198 { 0x79, 0x80 },
199 { 0x7a, 0x80 },
200 { 0x7b, 0xe2 },
201 { 0x7c, 0x00 },
202 { 0xff, 0xff }, /* END MARKER */
203};
204
205/* Returns index into the specified look-up table, with 'n' elements, for which
206 * the value is greater than or equal to "val". If a match isn't found, (n-1)
207 * is returned. The entries in the table must be in ascending order. */
208static inline int ov7x20_lut_find(unsigned char lut[], int n, unsigned char val)
209{
210 int i = 0;
211
212 while (lut[i] < val && i < n)
213 i++;
214
215 return i;
216}
217
218/* This initializes the OV7x20 camera chip and relevant variables. */
219static int ov7x20_init(struct i2c_client *c)
220{
221 struct ovcamchip *ov = i2c_get_clientdata(c);
222 struct ov7x20 *s;
223 int rc;
224
225 DDEBUG(4, &c->dev, "entered");
226
227 if (ov->mono)
228 rc = ov_write_regvals(c, regvals_init_7120);
229 else
230 rc = ov_write_regvals(c, regvals_init_7620);
231
232 if (rc < 0)
233 return rc;
234
235 ov->spriv = s = kzalloc(sizeof *s, GFP_KERNEL);
236 if (!s)
237 return -ENOMEM;
238
239 s->auto_brt = 1;
240 s->auto_exp = DFL_AUTO_EXP;
241 s->auto_gain = DFL_AUTO_GAIN;
242
243 return 0;
244}
245
246static int ov7x20_free(struct i2c_client *c)
247{
248 struct ovcamchip *ov = i2c_get_clientdata(c);
249
250 kfree(ov->spriv);
251 return 0;
252}
253
254static int ov7x20_set_v4l1_control(struct i2c_client *c,
255 struct ovcamchip_control *ctl)
256{
257 struct ovcamchip *ov = i2c_get_clientdata(c);
258 struct ov7x20 *s = ov->spriv;
259 int rc;
260 int v = ctl->value;
261
262 switch (ctl->id) {
263 case OVCAMCHIP_CID_CONT:
264 {
265 /* Use Y gamma control instead. Bit 0 enables it. */
266 rc = ov_write(c, 0x64, ctab[v >> 12]);
267 break;
268 }
269 case OVCAMCHIP_CID_BRIGHT:
270 /* 7620 doesn't like manual changes when in auto mode */
271 if (!s->auto_brt)
272 rc = ov_write(c, REG_BRT, v >> 8);
273 else
274 rc = 0;
275 break;
276 case OVCAMCHIP_CID_SAT:
277 rc = ov_write(c, REG_SAT, v >> 8);
278 break;
279 case OVCAMCHIP_CID_EXP:
280 if (!s->auto_exp)
281 rc = ov_write(c, REG_EXP, v);
282 else
283 rc = -EBUSY;
284 break;
285 case OVCAMCHIP_CID_FREQ:
286 {
287 int sixty = (v == 60);
288
289 rc = ov_write_mask(c, 0x2a, sixty?0x00:0x80, 0x80);
290 if (rc < 0)
291 goto out;
292
293 rc = ov_write(c, 0x2b, sixty?0x00:0xac);
294 if (rc < 0)
295 goto out;
296
297 rc = ov_write_mask(c, 0x76, 0x01, 0x01);
298 break;
299 }
300 case OVCAMCHIP_CID_BANDFILT:
301 rc = ov_write_mask(c, 0x2d, v?0x04:0x00, 0x04);
302 s->bandfilt = v;
303 break;
304 case OVCAMCHIP_CID_AUTOBRIGHT:
305 rc = ov_write_mask(c, 0x2d, v?0x10:0x00, 0x10);
306 s->auto_brt = v;
307 break;
308 case OVCAMCHIP_CID_AUTOEXP:
309 rc = ov_write_mask(c, 0x13, v?0x01:0x00, 0x01);
310 s->auto_exp = v;
311 break;
312 case OVCAMCHIP_CID_BACKLIGHT:
313 {
314 rc = ov_write_mask(c, 0x68, v?0xe0:0xc0, 0xe0);
315 if (rc < 0)
316 goto out;
317
318 rc = ov_write_mask(c, 0x29, v?0x08:0x00, 0x08);
319 if (rc < 0)
320 goto out;
321
322 rc = ov_write_mask(c, 0x28, v?0x02:0x00, 0x02);
323 s->backlight = v;
324 break;
325 }
326 case OVCAMCHIP_CID_MIRROR:
327 rc = ov_write_mask(c, 0x12, v?0x40:0x00, 0x40);
328 s->mirror = v;
329 break;
330 default:
331 DDEBUG(2, &c->dev, "control not supported: %d", ctl->id);
332 return -EPERM;
333 }
334
335out:
336 DDEBUG(3, &c->dev, "id=%d, arg=%d, rc=%d", ctl->id, v, rc);
337 return rc;
338}
339
340static int ov7x20_get_v4l1_control(struct i2c_client *c,
341 struct ovcamchip_control *ctl)
342{
343 struct ovcamchip *ov = i2c_get_clientdata(c);
344 struct ov7x20 *s = ov->spriv;
345 int rc = 0;
346 unsigned char val = 0;
347
348 switch (ctl->id) {
349 case OVCAMCHIP_CID_CONT:
350 rc = ov_read(c, 0x64, &val);
351 ctl->value = ov7x20_lut_find(ctab, 16, val) << 12;
352 break;
353 case OVCAMCHIP_CID_BRIGHT:
354 rc = ov_read(c, REG_BRT, &val);
355 ctl->value = val << 8;
356 break;
357 case OVCAMCHIP_CID_SAT:
358 rc = ov_read(c, REG_SAT, &val);
359 ctl->value = val << 8;
360 break;
361 case OVCAMCHIP_CID_EXP:
362 rc = ov_read(c, REG_EXP, &val);
363 ctl->value = val;
364 break;
365 case OVCAMCHIP_CID_BANDFILT:
366 ctl->value = s->bandfilt;
367 break;
368 case OVCAMCHIP_CID_AUTOBRIGHT:
369 ctl->value = s->auto_brt;
370 break;
371 case OVCAMCHIP_CID_AUTOEXP:
372 ctl->value = s->auto_exp;
373 break;
374 case OVCAMCHIP_CID_BACKLIGHT:
375 ctl->value = s->backlight;
376 break;
377 case OVCAMCHIP_CID_MIRROR:
378 ctl->value = s->mirror;
379 break;
380 default:
381 DDEBUG(2, &c->dev, "control not supported: %d", ctl->id);
382 return -EPERM;
383 }
384
385 DDEBUG(3, &c->dev, "id=%d, arg=%d, rc=%d", ctl->id, ctl->value, rc);
386 return rc;
387}
388
389static int ov7x20_mode_init(struct i2c_client *c, struct ovcamchip_window *win)
390{
391 struct ovcamchip *ov = i2c_get_clientdata(c);
392 int qvga = win->quarter;
393
394 /******** QVGA-specific regs ********/
395 ov_write_mask(c, 0x14, qvga?0x20:0x00, 0x20);
396 ov_write_mask(c, 0x28, qvga?0x00:0x20, 0x20);
397 ov_write(c, 0x24, qvga?0x20:0x3a);
398 ov_write(c, 0x25, qvga?0x30:0x60);
399 ov_write_mask(c, 0x2d, qvga?0x40:0x00, 0x40);
400 if (!ov->mono)
401 ov_write_mask(c, 0x67, qvga?0xf0:0x90, 0xf0);
402 ov_write_mask(c, 0x74, qvga?0x20:0x00, 0x20);
403
404 /******** Clock programming ********/
405
406 ov_write(c, 0x11, win->clockdiv);
407
408 return 0;
409}
410
411static int ov7x20_set_window(struct i2c_client *c, struct ovcamchip_window *win)
412{
413 int ret, hwscale, vwscale;
414
415 ret = ov7x20_mode_init(c, win);
416 if (ret < 0)
417 return ret;
418
419 if (win->quarter) {
420 hwscale = 1;
421 vwscale = 0;
422 } else {
423 hwscale = 2;
424 vwscale = 1;
425 }
426
427 ov_write(c, 0x17, HWSBASE + (win->x >> hwscale));
428 ov_write(c, 0x18, HWEBASE + ((win->x + win->width) >> hwscale));
429 ov_write(c, 0x19, VWSBASE + (win->y >> vwscale));
430 ov_write(c, 0x1a, VWEBASE + ((win->y + win->height) >> vwscale));
431
432 return 0;
433}
434
435static int ov7x20_command(struct i2c_client *c, unsigned int cmd, void *arg)
436{
437 switch (cmd) {
438 case OVCAMCHIP_CMD_S_CTRL:
439 return ov7x20_set_v4l1_control(c, arg);
440 case OVCAMCHIP_CMD_G_CTRL:
441 return ov7x20_get_v4l1_control(c, arg);
442 case OVCAMCHIP_CMD_S_MODE:
443 return ov7x20_set_window(c, arg);
444 default:
445 DDEBUG(2, &c->dev, "command not supported: %d", cmd);
446 return -ENOIOCTLCMD;
447 }
448}
449
450struct ovcamchip_ops ov7x20_ops = {
451 .init = ov7x20_init,
452 .free = ov7x20_free,
453 .command = ov7x20_command,
454};
diff --git a/drivers/media/video/ovcamchip/ovcamchip_core.c b/drivers/media/video/ovcamchip/ovcamchip_core.c
deleted file mode 100644
index d573d8428998..000000000000
--- a/drivers/media/video/ovcamchip/ovcamchip_core.c
+++ /dev/null
@@ -1,395 +0,0 @@
1/* Shared Code for OmniVision Camera Chip Drivers
2 *
3 * Copyright (c) 2004 Mark McClelland <mark@alpha.dyndns.org>
4 * http://alpha.dyndns.org/ov511/
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. NO WARRANTY OF ANY KIND is expressed or implied.
10 */
11
12#define DEBUG
13
14#include <linux/init.h>
15#include <linux/module.h>
16#include <linux/slab.h>
17#include <linux/delay.h>
18#include <linux/i2c.h>
19#include <media/v4l2-device.h>
20#include <media/v4l2-i2c-drv.h>
21#include "ovcamchip_priv.h"
22
23#define DRIVER_VERSION "v2.27 for Linux 2.6"
24#define DRIVER_AUTHOR "Mark McClelland <mark@alpha.dyndns.org>"
25#define DRIVER_DESC "OV camera chip I2C driver"
26
27#define PINFO(fmt, args...) printk(KERN_INFO "ovcamchip: " fmt "\n" , ## args);
28#define PERROR(fmt, args...) printk(KERN_ERR "ovcamchip: " fmt "\n" , ## args);
29
30#ifdef DEBUG
31int ovcamchip_debug = 0;
32static int debug;
33module_param(debug, int, 0);
34MODULE_PARM_DESC(debug,
35 "Debug level: 0=none, 1=inits, 2=warning, 3=config, 4=functions, 5=all");
36#endif
37
38/* By default, let bridge driver tell us if chip is monochrome. mono=0
39 * will ignore that and always treat chips as color. mono=1 will force
40 * monochrome mode for all chips. */
41static int mono = -1;
42module_param(mono, int, 0);
43MODULE_PARM_DESC(mono,
44 "1=chips are monochrome (OVx1xx), 0=force color, -1=autodetect (default)");
45
46MODULE_AUTHOR(DRIVER_AUTHOR);
47MODULE_DESCRIPTION(DRIVER_DESC);
48MODULE_LICENSE("GPL");
49
50
51/* Registers common to all chips, that are needed for detection */
52#define GENERIC_REG_ID_HIGH 0x1C /* manufacturer ID MSB */
53#define GENERIC_REG_ID_LOW 0x1D /* manufacturer ID LSB */
54#define GENERIC_REG_COM_I 0x29 /* misc ID bits */
55
56static char *chip_names[NUM_CC_TYPES] = {
57 [CC_UNKNOWN] = "Unknown chip",
58 [CC_OV76BE] = "OV76BE",
59 [CC_OV7610] = "OV7610",
60 [CC_OV7620] = "OV7620",
61 [CC_OV7620AE] = "OV7620AE",
62 [CC_OV6620] = "OV6620",
63 [CC_OV6630] = "OV6630",
64 [CC_OV6630AE] = "OV6630AE",
65 [CC_OV6630AF] = "OV6630AF",
66};
67
68/* ----------------------------------------------------------------------- */
69
70int ov_write_regvals(struct i2c_client *c, struct ovcamchip_regvals *rvals)
71{
72 int rc;
73
74 while (rvals->reg != 0xff) {
75 rc = ov_write(c, rvals->reg, rvals->val);
76 if (rc < 0)
77 return rc;
78 rvals++;
79 }
80
81 return 0;
82}
83
84/* Writes bits at positions specified by mask to an I2C reg. Bits that are in
85 * the same position as 1's in "mask" are cleared and set to "value". Bits
86 * that are in the same position as 0's in "mask" are preserved, regardless
87 * of their respective state in "value".
88 */
89int ov_write_mask(struct i2c_client *c,
90 unsigned char reg,
91 unsigned char value,
92 unsigned char mask)
93{
94 int rc;
95 unsigned char oldval, newval;
96
97 if (mask == 0xff) {
98 newval = value;
99 } else {
100 rc = ov_read(c, reg, &oldval);
101 if (rc < 0)
102 return rc;
103
104 oldval &= (~mask); /* Clear the masked bits */
105 value &= mask; /* Enforce mask on value */
106 newval = oldval | value; /* Set the desired bits */
107 }
108
109 return ov_write(c, reg, newval);
110}
111
112/* ----------------------------------------------------------------------- */
113
114/* Reset the chip and ensure that I2C is synchronized. Returns <0 if failure.
115 */
116static int init_camchip(struct i2c_client *c)
117{
118 int i, success;
119 unsigned char high, low;
120
121 /* Reset the chip */
122 ov_write(c, 0x12, 0x80);
123
124 /* Wait for it to initialize */
125 msleep(150);
126
127 for (i = 0, success = 0; i < I2C_DETECT_RETRIES && !success; i++) {
128 if (ov_read(c, GENERIC_REG_ID_HIGH, &high) >= 0) {
129 if (ov_read(c, GENERIC_REG_ID_LOW, &low) >= 0) {
130 if (high == 0x7F && low == 0xA2) {
131 success = 1;
132 continue;
133 }
134 }
135 }
136
137 /* Reset the chip */
138 ov_write(c, 0x12, 0x80);
139
140 /* Wait for it to initialize */
141 msleep(150);
142
143 /* Dummy read to sync I2C */
144 ov_read(c, 0x00, &low);
145 }
146
147 if (!success)
148 return -EIO;
149
150 PDEBUG(1, "I2C synced in %d attempt(s)", i);
151
152 return 0;
153}
154
155/* This detects the OV7610, OV7620, or OV76BE chip. */
156static int ov7xx0_detect(struct i2c_client *c)
157{
158 struct ovcamchip *ov = i2c_get_clientdata(c);
159 int rc;
160 unsigned char val;
161
162 PDEBUG(4, "");
163
164 /* Detect chip (sub)type */
165 rc = ov_read(c, GENERIC_REG_COM_I, &val);
166 if (rc < 0) {
167 PERROR("Error detecting ov7xx0 type");
168 return rc;
169 }
170
171 if ((val & 3) == 3) {
172 PINFO("Camera chip is an OV7610");
173 ov->subtype = CC_OV7610;
174 } else if ((val & 3) == 1) {
175 rc = ov_read(c, 0x15, &val);
176 if (rc < 0) {
177 PERROR("Error detecting ov7xx0 type");
178 return rc;
179 }
180
181 if (val & 1) {
182 PINFO("Camera chip is an OV7620AE");
183 /* OV7620 is a close enough match for now. There are
184 * some definite differences though, so this should be
185 * fixed */
186 ov->subtype = CC_OV7620;
187 } else {
188 PINFO("Camera chip is an OV76BE");
189 ov->subtype = CC_OV76BE;
190 }
191 } else if ((val & 3) == 0) {
192 PINFO("Camera chip is an OV7620");
193 ov->subtype = CC_OV7620;
194 } else {
195 PERROR("Unknown camera chip version: %d", val & 3);
196 return -ENOSYS;
197 }
198
199 if (ov->subtype == CC_OV76BE)
200 ov->sops = &ov76be_ops;
201 else if (ov->subtype == CC_OV7620)
202 ov->sops = &ov7x20_ops;
203 else
204 ov->sops = &ov7x10_ops;
205
206 return 0;
207}
208
209/* This detects the OV6620, OV6630, OV6630AE, or OV6630AF chip. */
210static int ov6xx0_detect(struct i2c_client *c)
211{
212 struct ovcamchip *ov = i2c_get_clientdata(c);
213 int rc;
214 unsigned char val;
215
216 PDEBUG(4, "");
217
218 /* Detect chip (sub)type */
219 rc = ov_read(c, GENERIC_REG_COM_I, &val);
220 if (rc < 0) {
221 PERROR("Error detecting ov6xx0 type");
222 return -1;
223 }
224
225 if ((val & 3) == 0) {
226 ov->subtype = CC_OV6630;
227 PINFO("Camera chip is an OV6630");
228 } else if ((val & 3) == 1) {
229 ov->subtype = CC_OV6620;
230 PINFO("Camera chip is an OV6620");
231 } else if ((val & 3) == 2) {
232 ov->subtype = CC_OV6630;
233 PINFO("Camera chip is an OV6630AE");
234 } else if ((val & 3) == 3) {
235 ov->subtype = CC_OV6630;
236 PINFO("Camera chip is an OV6630AF");
237 }
238
239 if (ov->subtype == CC_OV6620)
240 ov->sops = &ov6x20_ops;
241 else
242 ov->sops = &ov6x30_ops;
243
244 return 0;
245}
246
247static int ovcamchip_detect(struct i2c_client *c)
248{
249 /* Ideally we would just try a single register write and see if it NAKs.
250 * That isn't possible since the OV518 can't report I2C transaction
251 * failures. So, we have to try to initialize the chip (i.e. reset it
252 * and check the ID registers) to detect its presence. */
253
254 /* Test for 7xx0 */
255 PDEBUG(3, "Testing for 0V7xx0");
256 if (init_camchip(c) < 0)
257 return -ENODEV;
258 /* 7-bit addresses with bit 0 set are for the OV7xx0 */
259 if (c->addr & 1) {
260 if (ov7xx0_detect(c) < 0) {
261 PERROR("Failed to init OV7xx0");
262 return -EIO;
263 }
264 return 0;
265 }
266 /* Test for 6xx0 */
267 PDEBUG(3, "Testing for 0V6xx0");
268 if (ov6xx0_detect(c) < 0) {
269 PERROR("Failed to init OV6xx0");
270 return -EIO;
271 }
272 return 0;
273}
274
275/* ----------------------------------------------------------------------- */
276
277static long ovcamchip_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
278{
279 struct ovcamchip *ov = to_ovcamchip(sd);
280 struct i2c_client *c = v4l2_get_subdevdata(sd);
281
282 if (!ov->initialized &&
283 cmd != OVCAMCHIP_CMD_Q_SUBTYPE &&
284 cmd != OVCAMCHIP_CMD_INITIALIZE) {
285 v4l2_err(sd, "Camera chip not initialized yet!\n");
286 return -EPERM;
287 }
288
289 switch (cmd) {
290 case OVCAMCHIP_CMD_Q_SUBTYPE:
291 {
292 *(int *)arg = ov->subtype;
293 return 0;
294 }
295 case OVCAMCHIP_CMD_INITIALIZE:
296 {
297 int rc;
298
299 if (mono == -1)
300 ov->mono = *(int *)arg;
301 else
302 ov->mono = mono;
303
304 if (ov->mono) {
305 if (ov->subtype != CC_OV7620)
306 v4l2_warn(sd, "Monochrome not "
307 "implemented for this chip\n");
308 else
309 v4l2_info(sd, "Initializing chip as "
310 "monochrome\n");
311 }
312
313 rc = ov->sops->init(c);
314 if (rc < 0)
315 return rc;
316
317 ov->initialized = 1;
318 return 0;
319 }
320 default:
321 return ov->sops->command(c, cmd, arg);
322 }
323}
324
325/* ----------------------------------------------------------------------- */
326
327static const struct v4l2_subdev_core_ops ovcamchip_core_ops = {
328 .ioctl = ovcamchip_ioctl,
329};
330
331static const struct v4l2_subdev_ops ovcamchip_ops = {
332 .core = &ovcamchip_core_ops,
333};
334
335static int ovcamchip_probe(struct i2c_client *client,
336 const struct i2c_device_id *id)
337{
338 struct ovcamchip *ov;
339 struct v4l2_subdev *sd;
340 int rc = 0;
341
342 ov = kzalloc(sizeof *ov, GFP_KERNEL);
343 if (!ov) {
344 rc = -ENOMEM;
345 goto no_ov;
346 }
347 sd = &ov->sd;
348 v4l2_i2c_subdev_init(sd, client, &ovcamchip_ops);
349
350 rc = ovcamchip_detect(client);
351 if (rc < 0)
352 goto error;
353
354 v4l_info(client, "%s found @ 0x%02x (%s)\n",
355 chip_names[ov->subtype], client->addr << 1, client->adapter->name);
356
357 PDEBUG(1, "Camera chip detection complete");
358
359 return rc;
360error:
361 kfree(ov);
362no_ov:
363 PDEBUG(1, "returning %d", rc);
364 return rc;
365}
366
367static int ovcamchip_remove(struct i2c_client *client)
368{
369 struct v4l2_subdev *sd = i2c_get_clientdata(client);
370 struct ovcamchip *ov = to_ovcamchip(sd);
371 int rc;
372
373 v4l2_device_unregister_subdev(sd);
374 rc = ov->sops->free(client);
375 if (rc < 0)
376 return rc;
377
378 kfree(ov);
379 return 0;
380}
381
382/* ----------------------------------------------------------------------- */
383
384static const struct i2c_device_id ovcamchip_id[] = {
385 { "ovcamchip", 0 },
386 { }
387};
388MODULE_DEVICE_TABLE(i2c, ovcamchip_id);
389
390static struct v4l2_i2c_driver_data v4l2_i2c_data = {
391 .name = "ovcamchip",
392 .probe = ovcamchip_probe,
393 .remove = ovcamchip_remove,
394 .id_table = ovcamchip_id,
395};
diff --git a/drivers/media/video/ovcamchip/ovcamchip_priv.h b/drivers/media/video/ovcamchip/ovcamchip_priv.h
deleted file mode 100644
index 4f07b78c88bc..000000000000
--- a/drivers/media/video/ovcamchip/ovcamchip_priv.h
+++ /dev/null
@@ -1,101 +0,0 @@
1/* OmniVision* camera chip driver private definitions for core code and
2 * chip-specific code
3 *
4 * Copyright (c) 1999-2004 Mark McClelland
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. NO WARRANTY OF ANY KIND is expressed or implied.
10 *
11 * * OmniVision is a trademark of OmniVision Technologies, Inc. This driver
12 * is not sponsored or developed by them.
13 */
14
15#ifndef __LINUX_OVCAMCHIP_PRIV_H
16#define __LINUX_OVCAMCHIP_PRIV_H
17
18#include <linux/i2c.h>
19#include <media/v4l2-subdev.h>
20#include <media/ovcamchip.h>
21
22#ifdef DEBUG
23extern int ovcamchip_debug;
24#endif
25
26#define PDEBUG(level, fmt, args...) \
27 if (ovcamchip_debug >= (level)) pr_debug("[%s:%d] " fmt "\n", \
28 __func__, __LINE__ , ## args)
29
30#define DDEBUG(level, dev, fmt, args...) \
31 if (ovcamchip_debug >= (level)) dev_dbg(dev, "[%s:%d] " fmt "\n", \
32 __func__, __LINE__ , ## args)
33
34/* Number of times to retry chip detection. Increase this if you are getting
35 * "Failed to init camera chip" */
36#define I2C_DETECT_RETRIES 10
37
38struct ovcamchip_regvals {
39 unsigned char reg;
40 unsigned char val;
41};
42
43struct ovcamchip_ops {
44 int (*init)(struct i2c_client *);
45 int (*free)(struct i2c_client *);
46 int (*command)(struct i2c_client *, unsigned int, void *);
47};
48
49struct ovcamchip {
50 struct v4l2_subdev sd;
51 struct ovcamchip_ops *sops;
52 void *spriv; /* Private data for OV7x10.c etc... */
53 int subtype; /* = SEN_OV7610 etc... */
54 int mono; /* Monochrome chip? (invalid until init) */
55 int initialized; /* OVCAMCHIP_CMD_INITIALIZE was successful */
56};
57
58static inline struct ovcamchip *to_ovcamchip(struct v4l2_subdev *sd)
59{
60 return container_of(sd, struct ovcamchip, sd);
61}
62
63extern struct ovcamchip_ops ov6x20_ops;
64extern struct ovcamchip_ops ov6x30_ops;
65extern struct ovcamchip_ops ov7x10_ops;
66extern struct ovcamchip_ops ov7x20_ops;
67extern struct ovcamchip_ops ov76be_ops;
68
69/* --------------------------------- */
70/* I2C I/O */
71/* --------------------------------- */
72
73static inline int ov_read(struct i2c_client *c, unsigned char reg,
74 unsigned char *value)
75{
76 int rc;
77
78 rc = i2c_smbus_read_byte_data(c, reg);
79 *value = (unsigned char) rc;
80 return rc;
81}
82
83static inline int ov_write(struct i2c_client *c, unsigned char reg,
84 unsigned char value )
85{
86 return i2c_smbus_write_byte_data(c, reg, value);
87}
88
89/* --------------------------------- */
90/* FUNCTION PROTOTYPES */
91/* --------------------------------- */
92
93/* Functions in ovcamchip_core.c */
94
95extern int ov_write_regvals(struct i2c_client *c,
96 struct ovcamchip_regvals *rvals);
97
98extern int ov_write_mask(struct i2c_client *c, unsigned char reg,
99 unsigned char value, unsigned char mask);
100
101#endif
diff --git a/drivers/media/video/pvrusb2/pvrusb2-ioread.c b/drivers/media/video/pvrusb2/pvrusb2-ioread.c
index b4824782d858..bba6115c9ae8 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-ioread.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-ioread.c
@@ -223,7 +223,10 @@ int pvr2_ioread_setup(struct pvr2_ioread *cp,struct pvr2_stream *sp)
223 " pvr2_ioread_setup (setup) id=%p",cp); 223 " pvr2_ioread_setup (setup) id=%p",cp);
224 pvr2_stream_kill(sp); 224 pvr2_stream_kill(sp);
225 ret = pvr2_stream_set_buffer_count(sp,BUFFER_COUNT); 225 ret = pvr2_stream_set_buffer_count(sp,BUFFER_COUNT);
226 if (ret < 0) return ret; 226 if (ret < 0) {
227 mutex_unlock(&cp->mutex);
228 return ret;
229 }
227 for (idx = 0; idx < BUFFER_COUNT; idx++) { 230 for (idx = 0; idx < BUFFER_COUNT; idx++) {
228 bp = pvr2_stream_get_buffer(sp,idx); 231 bp = pvr2_stream_get_buffer(sp,idx);
229 pvr2_buffer_set_buffer(bp, 232 pvr2_buffer_set_buffer(bp,
diff --git a/drivers/media/video/pxa_camera.c b/drivers/media/video/pxa_camera.c
index fb242f6cfb1f..9de7d59916bd 100644
--- a/drivers/media/video/pxa_camera.c
+++ b/drivers/media/video/pxa_camera.c
@@ -276,7 +276,7 @@ static void free_buffer(struct videobuf_queue *vq, struct pxa_buffer *buf)
276 * longer in STATE_QUEUED or STATE_ACTIVE 276 * longer in STATE_QUEUED or STATE_ACTIVE
277 */ 277 */
278 videobuf_waiton(&buf->vb, 0, 0); 278 videobuf_waiton(&buf->vb, 0, 0);
279 videobuf_dma_unmap(vq, dma); 279 videobuf_dma_unmap(vq->dev, dma);
280 videobuf_dma_free(dma); 280 videobuf_dma_free(dma);
281 281
282 for (i = 0; i < ARRAY_SIZE(buf->dmas); i++) { 282 for (i = 0; i < ARRAY_SIZE(buf->dmas); i++) {
@@ -1284,7 +1284,7 @@ static int pxa_camera_get_formats(struct soc_camera_device *icd, unsigned int id
1284 } 1284 }
1285 1285
1286 switch (code) { 1286 switch (code) {
1287 case V4L2_MBUS_FMT_YUYV8_2X8_BE: 1287 case V4L2_MBUS_FMT_UYVY8_2X8:
1288 formats++; 1288 formats++;
1289 if (xlate) { 1289 if (xlate) {
1290 xlate->host_fmt = &pxa_camera_formats[0]; 1290 xlate->host_fmt = &pxa_camera_formats[0];
@@ -1293,9 +1293,9 @@ static int pxa_camera_get_formats(struct soc_camera_device *icd, unsigned int id
1293 dev_dbg(dev, "Providing format %s using code %d\n", 1293 dev_dbg(dev, "Providing format %s using code %d\n",
1294 pxa_camera_formats[0].name, code); 1294 pxa_camera_formats[0].name, code);
1295 } 1295 }
1296 case V4L2_MBUS_FMT_YVYU8_2X8_BE: 1296 case V4L2_MBUS_FMT_VYUY8_2X8:
1297 case V4L2_MBUS_FMT_YUYV8_2X8_LE: 1297 case V4L2_MBUS_FMT_YUYV8_2X8:
1298 case V4L2_MBUS_FMT_YVYU8_2X8_LE: 1298 case V4L2_MBUS_FMT_YVYU8_2X8:
1299 case V4L2_MBUS_FMT_RGB565_2X8_LE: 1299 case V4L2_MBUS_FMT_RGB565_2X8_LE:
1300 case V4L2_MBUS_FMT_RGB555_2X8_PADHI_LE: 1300 case V4L2_MBUS_FMT_RGB555_2X8_PADHI_LE:
1301 if (xlate) 1301 if (xlate)
diff --git a/drivers/media/video/rj54n1cb0c.c b/drivers/media/video/rj54n1cb0c.c
index 47fd207ba3b1..ce78fff23425 100644
--- a/drivers/media/video/rj54n1cb0c.c
+++ b/drivers/media/video/rj54n1cb0c.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Driver for RJ54N1CB0C CMOS Image Sensor from Micron 2 * Driver for RJ54N1CB0C CMOS Image Sensor from Sharp
3 * 3 *
4 * Copyright (C) 2009, Guennadi Liakhovetski <g.liakhovetski@gmx.de> 4 * Copyright (C) 2009, Guennadi Liakhovetski <g.liakhovetski@gmx.de>
5 * 5 *
@@ -127,8 +127,8 @@ static const struct rj54n1_datafmt *rj54n1_find_datafmt(
127} 127}
128 128
129static const struct rj54n1_datafmt rj54n1_colour_fmts[] = { 129static const struct rj54n1_datafmt rj54n1_colour_fmts[] = {
130 {V4L2_MBUS_FMT_YUYV8_2X8_LE, V4L2_COLORSPACE_JPEG}, 130 {V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG},
131 {V4L2_MBUS_FMT_YVYU8_2X8_LE, V4L2_COLORSPACE_JPEG}, 131 {V4L2_MBUS_FMT_YVYU8_2X8, V4L2_COLORSPACE_JPEG},
132 {V4L2_MBUS_FMT_RGB565_2X8_LE, V4L2_COLORSPACE_SRGB}, 132 {V4L2_MBUS_FMT_RGB565_2X8_LE, V4L2_COLORSPACE_SRGB},
133 {V4L2_MBUS_FMT_RGB565_2X8_BE, V4L2_COLORSPACE_SRGB}, 133 {V4L2_MBUS_FMT_RGB565_2X8_BE, V4L2_COLORSPACE_SRGB},
134 {V4L2_MBUS_FMT_SBGGR10_2X8_PADHI_LE, V4L2_COLORSPACE_SRGB}, 134 {V4L2_MBUS_FMT_SBGGR10_2X8_PADHI_LE, V4L2_COLORSPACE_SRGB},
@@ -1046,12 +1046,12 @@ static int rj54n1_s_fmt(struct v4l2_subdev *sd,
1046 1046
1047 /* RA_SEL_UL is only relevant for raw modes, ignored otherwise. */ 1047 /* RA_SEL_UL is only relevant for raw modes, ignored otherwise. */
1048 switch (mf->code) { 1048 switch (mf->code) {
1049 case V4L2_MBUS_FMT_YUYV8_2X8_LE: 1049 case V4L2_MBUS_FMT_YUYV8_2X8:
1050 ret = reg_write(client, RJ54N1_OUT_SEL, 0); 1050 ret = reg_write(client, RJ54N1_OUT_SEL, 0);
1051 if (!ret) 1051 if (!ret)
1052 ret = reg_set(client, RJ54N1_BYTE_SWAP, 8, 8); 1052 ret = reg_set(client, RJ54N1_BYTE_SWAP, 8, 8);
1053 break; 1053 break;
1054 case V4L2_MBUS_FMT_YVYU8_2X8_LE: 1054 case V4L2_MBUS_FMT_YVYU8_2X8:
1055 ret = reg_write(client, RJ54N1_OUT_SEL, 0); 1055 ret = reg_write(client, RJ54N1_OUT_SEL, 0);
1056 if (!ret) 1056 if (!ret)
1057 ret = reg_set(client, RJ54N1_BYTE_SWAP, 0, 8); 1057 ret = reg_set(client, RJ54N1_BYTE_SWAP, 0, 8);
diff --git a/drivers/media/video/s2255drv.c b/drivers/media/video/s2255drv.c
index 3c7a79f3812a..8ec7c9a45a17 100644
--- a/drivers/media/video/s2255drv.c
+++ b/drivers/media/video/s2255drv.c
@@ -191,7 +191,6 @@ struct s2255_bufferi {
191struct s2255_dmaqueue { 191struct s2255_dmaqueue {
192 struct list_head active; 192 struct list_head active;
193 struct s2255_dev *dev; 193 struct s2255_dev *dev;
194 int channel;
195}; 194};
196 195
197/* for firmware loading, fw_state */ 196/* for firmware loading, fw_state */
@@ -226,51 +225,60 @@ struct s2255_pipeinfo {
226}; 225};
227 226
228struct s2255_fmt; /*forward declaration */ 227struct s2255_fmt; /*forward declaration */
228struct s2255_dev;
229
230struct s2255_channel {
231 struct video_device vdev;
232 int resources;
233 struct s2255_dmaqueue vidq;
234 struct s2255_bufferi buffer;
235 struct s2255_mode mode;
236 /* jpeg compression */
237 struct v4l2_jpegcompression jc;
238 /* capture parameters (for high quality mode full size) */
239 struct v4l2_captureparm cap_parm;
240 int cur_frame;
241 int last_frame;
242
243 int b_acquire;
244 /* allocated image size */
245 unsigned long req_image_size;
246 /* received packet size */
247 unsigned long pkt_size;
248 int bad_payload;
249 unsigned long frame_count;
250 /* if JPEG image */
251 int jpg_size;
252 /* if channel configured to default state */
253 int configured;
254 wait_queue_head_t wait_setmode;
255 int setmode_ready;
256 /* video status items */
257 int vidstatus;
258 wait_queue_head_t wait_vidstatus;
259 int vidstatus_ready;
260 unsigned int width;
261 unsigned int height;
262 const struct s2255_fmt *fmt;
263 int idx; /* channel number on device, 0-3 */
264};
265
229 266
230struct s2255_dev { 267struct s2255_dev {
231 struct video_device vdev[MAX_CHANNELS]; 268 struct s2255_channel channel[MAX_CHANNELS];
232 struct v4l2_device v4l2_dev; 269 struct v4l2_device v4l2_dev;
233 atomic_t channels; /* number of channels registered */ 270 atomic_t num_channels;
234 int frames; 271 int frames;
235 struct mutex lock; 272 struct mutex lock;
236 struct mutex open_lock; 273 struct mutex open_lock;
237 int resources[MAX_CHANNELS];
238 struct usb_device *udev; 274 struct usb_device *udev;
239 struct usb_interface *interface; 275 struct usb_interface *interface;
240 u8 read_endpoint; 276 u8 read_endpoint;
241
242 struct s2255_dmaqueue vidq[MAX_CHANNELS];
243 struct timer_list timer; 277 struct timer_list timer;
244 struct s2255_fw *fw_data; 278 struct s2255_fw *fw_data;
245 struct s2255_pipeinfo pipe; 279 struct s2255_pipeinfo pipe;
246 struct s2255_bufferi buffer[MAX_CHANNELS];
247 struct s2255_mode mode[MAX_CHANNELS];
248 /* jpeg compression */
249 struct v4l2_jpegcompression jc[MAX_CHANNELS];
250 /* capture parameters (for high quality mode full size) */
251 struct v4l2_captureparm cap_parm[MAX_CHANNELS];
252 const struct s2255_fmt *cur_fmt[MAX_CHANNELS];
253 int cur_frame[MAX_CHANNELS];
254 int last_frame[MAX_CHANNELS];
255 u32 cc; /* current channel */ 280 u32 cc; /* current channel */
256 int b_acquire[MAX_CHANNELS];
257 /* allocated image size */
258 unsigned long req_image_size[MAX_CHANNELS];
259 /* received packet size */
260 unsigned long pkt_size[MAX_CHANNELS];
261 int bad_payload[MAX_CHANNELS];
262 unsigned long frame_count[MAX_CHANNELS];
263 int frame_ready; 281 int frame_ready;
264 /* if JPEG image */
265 int jpg_size[MAX_CHANNELS];
266 /* if channel configured to default state */
267 int chn_configured[MAX_CHANNELS];
268 wait_queue_head_t wait_setmode[MAX_CHANNELS];
269 int setmode_ready[MAX_CHANNELS];
270 /* video status items */
271 int vidstatus[MAX_CHANNELS];
272 wait_queue_head_t wait_vidstatus[MAX_CHANNELS];
273 int vidstatus_ready[MAX_CHANNELS];
274 int chn_ready; 282 int chn_ready;
275 spinlock_t slock; 283 spinlock_t slock;
276 /* dsp firmware version (f2255usb.bin) */ 284 /* dsp firmware version (f2255usb.bin) */
@@ -298,16 +306,10 @@ struct s2255_buffer {
298 306
299struct s2255_fh { 307struct s2255_fh {
300 struct s2255_dev *dev; 308 struct s2255_dev *dev;
301 const struct s2255_fmt *fmt;
302 unsigned int width;
303 unsigned int height;
304 struct videobuf_queue vb_vidq; 309 struct videobuf_queue vb_vidq;
305 enum v4l2_buf_type type; 310 enum v4l2_buf_type type;
306 int channel; 311 struct s2255_channel *channel;
307 /* mode below is the desired mode. 312 int resources;
308 mode in s2255_dev is the current mode that was last set */
309 struct s2255_mode mode;
310 int resources[MAX_CHANNELS];
311}; 313};
312 314
313/* current cypress EEPROM firmware version */ 315/* current cypress EEPROM firmware version */
@@ -360,12 +362,11 @@ static int *s2255_debug = &debug;
360 362
361static int s2255_start_readpipe(struct s2255_dev *dev); 363static int s2255_start_readpipe(struct s2255_dev *dev);
362static void s2255_stop_readpipe(struct s2255_dev *dev); 364static void s2255_stop_readpipe(struct s2255_dev *dev);
363static int s2255_start_acquire(struct s2255_dev *dev, unsigned long chn); 365static int s2255_start_acquire(struct s2255_channel *channel);
364static int s2255_stop_acquire(struct s2255_dev *dev, unsigned long chn); 366static int s2255_stop_acquire(struct s2255_channel *channel);
365static void s2255_fillbuff(struct s2255_dev *dev, struct s2255_buffer *buf, 367static void s2255_fillbuff(struct s2255_channel *chn, struct s2255_buffer *buf,
366 int chn, int jpgsize); 368 int jpgsize);
367static int s2255_set_mode(struct s2255_dev *dev, unsigned long chn, 369static int s2255_set_mode(struct s2255_channel *chan, struct s2255_mode *mode);
368 struct s2255_mode *mode);
369static int s2255_board_shutdown(struct s2255_dev *dev); 370static int s2255_board_shutdown(struct s2255_dev *dev);
370static void s2255_fwload_start(struct s2255_dev *dev, int reset); 371static void s2255_fwload_start(struct s2255_dev *dev, int reset);
371static void s2255_destroy(struct s2255_dev *dev); 372static void s2255_destroy(struct s2255_dev *dev);
@@ -577,10 +578,11 @@ static void s2255_fwchunk_complete(struct urb *urb)
577 578
578} 579}
579 580
580static int s2255_got_frame(struct s2255_dev *dev, int chn, int jpgsize) 581static int s2255_got_frame(struct s2255_channel *channel, int jpgsize)
581{ 582{
582 struct s2255_dmaqueue *dma_q = &dev->vidq[chn]; 583 struct s2255_dmaqueue *dma_q = &channel->vidq;
583 struct s2255_buffer *buf; 584 struct s2255_buffer *buf;
585 struct s2255_dev *dev = to_s2255_dev(channel->vdev.v4l2_dev);
584 unsigned long flags = 0; 586 unsigned long flags = 0;
585 int rc = 0; 587 int rc = 0;
586 spin_lock_irqsave(&dev->slock, flags); 588 spin_lock_irqsave(&dev->slock, flags);
@@ -593,7 +595,7 @@ static int s2255_got_frame(struct s2255_dev *dev, int chn, int jpgsize)
593 struct s2255_buffer, vb.queue); 595 struct s2255_buffer, vb.queue);
594 list_del(&buf->vb.queue); 596 list_del(&buf->vb.queue);
595 do_gettimeofday(&buf->vb.ts); 597 do_gettimeofday(&buf->vb.ts);
596 s2255_fillbuff(dev, buf, dma_q->channel, jpgsize); 598 s2255_fillbuff(channel, buf, jpgsize);
597 wake_up(&buf->vb.done); 599 wake_up(&buf->vb.done);
598 dprintk(2, "%s: [buf/i] [%p/%d]\n", __func__, buf, buf->vb.i); 600 dprintk(2, "%s: [buf/i] [%p/%d]\n", __func__, buf, buf->vb.i);
599unlock: 601unlock:
@@ -621,8 +623,8 @@ static const struct s2255_fmt *format_by_fourcc(int fourcc)
621 * http://v4l.videotechnology.com/ 623 * http://v4l.videotechnology.com/
622 * 624 *
623 */ 625 */
624static void s2255_fillbuff(struct s2255_dev *dev, struct s2255_buffer *buf, 626static void s2255_fillbuff(struct s2255_channel *channel,
625 int chn, int jpgsize) 627 struct s2255_buffer *buf, int jpgsize)
626{ 628{
627 int pos = 0; 629 int pos = 0;
628 struct timeval ts; 630 struct timeval ts;
@@ -633,12 +635,11 @@ static void s2255_fillbuff(struct s2255_dev *dev, struct s2255_buffer *buf,
633 635
634 if (!vbuf) 636 if (!vbuf)
635 return; 637 return;
636 638 last_frame = channel->last_frame;
637 last_frame = dev->last_frame[chn];
638 if (last_frame != -1) { 639 if (last_frame != -1) {
639 frm = &dev->buffer[chn].frame[last_frame]; 640 frm = &channel->buffer.frame[last_frame];
640 tmpbuf = 641 tmpbuf =
641 (const char *)dev->buffer[chn].frame[last_frame].lpvbits; 642 (const char *)channel->buffer.frame[last_frame].lpvbits;
642 switch (buf->fmt->fourcc) { 643 switch (buf->fmt->fourcc) {
643 case V4L2_PIX_FMT_YUYV: 644 case V4L2_PIX_FMT_YUYV:
644 case V4L2_PIX_FMT_UYVY: 645 case V4L2_PIX_FMT_UYVY:
@@ -661,7 +662,7 @@ static void s2255_fillbuff(struct s2255_dev *dev, struct s2255_buffer *buf,
661 default: 662 default:
662 printk(KERN_DEBUG "s2255: unknown format?\n"); 663 printk(KERN_DEBUG "s2255: unknown format?\n");
663 } 664 }
664 dev->last_frame[chn] = -1; 665 channel->last_frame = -1;
665 } else { 666 } else {
666 printk(KERN_ERR "s2255: =======no frame\n"); 667 printk(KERN_ERR "s2255: =======no frame\n");
667 return; 668 return;
@@ -671,7 +672,7 @@ static void s2255_fillbuff(struct s2255_dev *dev, struct s2255_buffer *buf,
671 (unsigned long)vbuf, pos); 672 (unsigned long)vbuf, pos);
672 /* tell v4l buffer was filled */ 673 /* tell v4l buffer was filled */
673 674
674 buf->vb.field_count = dev->frame_count[chn] * 2; 675 buf->vb.field_count = channel->frame_count * 2;
675 do_gettimeofday(&ts); 676 do_gettimeofday(&ts);
676 buf->vb.ts = ts; 677 buf->vb.ts = ts;
677 buf->vb.state = VIDEOBUF_DONE; 678 buf->vb.state = VIDEOBUF_DONE;
@@ -686,8 +687,8 @@ static int buffer_setup(struct videobuf_queue *vq, unsigned int *count,
686 unsigned int *size) 687 unsigned int *size)
687{ 688{
688 struct s2255_fh *fh = vq->priv_data; 689 struct s2255_fh *fh = vq->priv_data;
689 690 struct s2255_channel *channel = fh->channel;
690 *size = fh->width * fh->height * (fh->fmt->depth >> 3); 691 *size = channel->width * channel->height * (channel->fmt->depth >> 3);
691 692
692 if (0 == *count) 693 if (0 == *count)
693 *count = S2255_DEF_BUFS; 694 *count = S2255_DEF_BUFS;
@@ -710,30 +711,31 @@ static int buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
710 enum v4l2_field field) 711 enum v4l2_field field)
711{ 712{
712 struct s2255_fh *fh = vq->priv_data; 713 struct s2255_fh *fh = vq->priv_data;
714 struct s2255_channel *channel = fh->channel;
713 struct s2255_buffer *buf = container_of(vb, struct s2255_buffer, vb); 715 struct s2255_buffer *buf = container_of(vb, struct s2255_buffer, vb);
714 int rc; 716 int rc;
717 int w = channel->width;
718 int h = channel->height;
715 dprintk(4, "%s, field=%d\n", __func__, field); 719 dprintk(4, "%s, field=%d\n", __func__, field);
716 if (fh->fmt == NULL) 720 if (channel->fmt == NULL)
717 return -EINVAL; 721 return -EINVAL;
718 722
719 if ((fh->width < norm_minw(&fh->dev->vdev[fh->channel])) || 723 if ((w < norm_minw(&channel->vdev)) ||
720 (fh->width > norm_maxw(&fh->dev->vdev[fh->channel])) || 724 (w > norm_maxw(&channel->vdev)) ||
721 (fh->height < norm_minh(&fh->dev->vdev[fh->channel])) || 725 (h < norm_minh(&channel->vdev)) ||
722 (fh->height > norm_maxh(&fh->dev->vdev[fh->channel]))) { 726 (h > norm_maxh(&channel->vdev))) {
723 dprintk(4, "invalid buffer prepare\n"); 727 dprintk(4, "invalid buffer prepare\n");
724 return -EINVAL; 728 return -EINVAL;
725 } 729 }
726 730 buf->vb.size = w * h * (channel->fmt->depth >> 3);
727 buf->vb.size = fh->width * fh->height * (fh->fmt->depth >> 3);
728
729 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size) { 731 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size) {
730 dprintk(4, "invalid buffer prepare\n"); 732 dprintk(4, "invalid buffer prepare\n");
731 return -EINVAL; 733 return -EINVAL;
732 } 734 }
733 735
734 buf->fmt = fh->fmt; 736 buf->fmt = channel->fmt;
735 buf->vb.width = fh->width; 737 buf->vb.width = w;
736 buf->vb.height = fh->height; 738 buf->vb.height = h;
737 buf->vb.field = field; 739 buf->vb.field = field;
738 740
739 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) { 741 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
@@ -753,8 +755,8 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
753{ 755{
754 struct s2255_buffer *buf = container_of(vb, struct s2255_buffer, vb); 756 struct s2255_buffer *buf = container_of(vb, struct s2255_buffer, vb);
755 struct s2255_fh *fh = vq->priv_data; 757 struct s2255_fh *fh = vq->priv_data;
756 struct s2255_dev *dev = fh->dev; 758 struct s2255_channel *channel = fh->channel;
757 struct s2255_dmaqueue *vidq = &dev->vidq[fh->channel]; 759 struct s2255_dmaqueue *vidq = &channel->vidq;
758 dprintk(1, "%s\n", __func__); 760 dprintk(1, "%s\n", __func__);
759 buf->vb.state = VIDEOBUF_QUEUED; 761 buf->vb.state = VIDEOBUF_QUEUED;
760 list_add_tail(&buf->vb.queue, &vidq->active); 762 list_add_tail(&buf->vb.queue, &vidq->active);
@@ -765,7 +767,7 @@ static void buffer_release(struct videobuf_queue *vq,
765{ 767{
766 struct s2255_buffer *buf = container_of(vb, struct s2255_buffer, vb); 768 struct s2255_buffer *buf = container_of(vb, struct s2255_buffer, vb);
767 struct s2255_fh *fh = vq->priv_data; 769 struct s2255_fh *fh = vq->priv_data;
768 dprintk(4, "%s %d\n", __func__, fh->channel); 770 dprintk(4, "%s %d\n", __func__, fh->channel->idx);
769 free_buffer(vq, buf); 771 free_buffer(vq, buf);
770} 772}
771 773
@@ -777,39 +779,43 @@ static struct videobuf_queue_ops s2255_video_qops = {
777}; 779};
778 780
779 781
780static int res_get(struct s2255_dev *dev, struct s2255_fh *fh) 782static int res_get(struct s2255_fh *fh)
781{ 783{
784 struct s2255_dev *dev = fh->dev;
782 /* is it free? */ 785 /* is it free? */
786 struct s2255_channel *channel = fh->channel;
783 mutex_lock(&dev->lock); 787 mutex_lock(&dev->lock);
784 if (dev->resources[fh->channel]) { 788 if (channel->resources) {
785 /* no, someone else uses it */ 789 /* no, someone else uses it */
786 mutex_unlock(&dev->lock); 790 mutex_unlock(&dev->lock);
787 return 0; 791 return 0;
788 } 792 }
789 /* it's free, grab it */ 793 /* it's free, grab it */
790 dev->resources[fh->channel] = 1; 794 channel->resources = 1;
791 fh->resources[fh->channel] = 1; 795 fh->resources = 1;
792 dprintk(1, "s2255: res: get\n"); 796 dprintk(1, "s2255: res: get\n");
793 mutex_unlock(&dev->lock); 797 mutex_unlock(&dev->lock);
794 return 1; 798 return 1;
795} 799}
796 800
797static int res_locked(struct s2255_dev *dev, struct s2255_fh *fh) 801static int res_locked(struct s2255_fh *fh)
798{ 802{
799 return dev->resources[fh->channel]; 803 return fh->channel->resources;
800} 804}
801 805
802static int res_check(struct s2255_fh *fh) 806static int res_check(struct s2255_fh *fh)
803{ 807{
804 return fh->resources[fh->channel]; 808 return fh->resources;
805} 809}
806 810
807 811
808static void res_free(struct s2255_dev *dev, struct s2255_fh *fh) 812static void res_free(struct s2255_fh *fh)
809{ 813{
814 struct s2255_channel *channel = fh->channel;
815 struct s2255_dev *dev = fh->dev;
810 mutex_lock(&dev->lock); 816 mutex_lock(&dev->lock);
811 dev->resources[fh->channel] = 0; 817 channel->resources = 0;
812 fh->resources[fh->channel] = 0; 818 fh->resources = 0;
813 mutex_unlock(&dev->lock); 819 mutex_unlock(&dev->lock);
814 dprintk(1, "res: put\n"); 820 dprintk(1, "res: put\n");
815} 821}
@@ -869,12 +875,13 @@ static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
869 struct v4l2_format *f) 875 struct v4l2_format *f)
870{ 876{
871 struct s2255_fh *fh = priv; 877 struct s2255_fh *fh = priv;
878 struct s2255_channel *channel = fh->channel;
872 879
873 f->fmt.pix.width = fh->width; 880 f->fmt.pix.width = channel->width;
874 f->fmt.pix.height = fh->height; 881 f->fmt.pix.height = channel->height;
875 f->fmt.pix.field = fh->vb_vidq.field; 882 f->fmt.pix.field = fh->vb_vidq.field;
876 f->fmt.pix.pixelformat = fh->fmt->fourcc; 883 f->fmt.pix.pixelformat = channel->fmt->fourcc;
877 f->fmt.pix.bytesperline = f->fmt.pix.width * (fh->fmt->depth >> 3); 884 f->fmt.pix.bytesperline = f->fmt.pix.width * (channel->fmt->depth >> 3);
878 f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline; 885 f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline;
879 return 0; 886 return 0;
880} 887}
@@ -886,11 +893,10 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
886 enum v4l2_field field; 893 enum v4l2_field field;
887 int b_any_field = 0; 894 int b_any_field = 0;
888 struct s2255_fh *fh = priv; 895 struct s2255_fh *fh = priv;
889 struct s2255_dev *dev = fh->dev; 896 struct s2255_channel *channel = fh->channel;
890 int is_ntsc; 897 int is_ntsc;
891
892 is_ntsc = 898 is_ntsc =
893 (dev->vdev[fh->channel].current_norm & V4L2_STD_NTSC) ? 1 : 0; 899 (channel->vdev.current_norm & V4L2_STD_NTSC) ? 1 : 0;
894 900
895 fmt = format_by_fourcc(f->fmt.pix.pixelformat); 901 fmt = format_by_fourcc(f->fmt.pix.pixelformat);
896 902
@@ -982,8 +988,10 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
982 struct v4l2_format *f) 988 struct v4l2_format *f)
983{ 989{
984 struct s2255_fh *fh = priv; 990 struct s2255_fh *fh = priv;
991 struct s2255_channel *channel = fh->channel;
985 const struct s2255_fmt *fmt; 992 const struct s2255_fmt *fmt;
986 struct videobuf_queue *q = &fh->vb_vidq; 993 struct videobuf_queue *q = &fh->vb_vidq;
994 struct s2255_mode mode;
987 int ret; 995 int ret;
988 int norm; 996 int norm;
989 997
@@ -1005,54 +1013,61 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
1005 goto out_s_fmt; 1013 goto out_s_fmt;
1006 } 1014 }
1007 1015
1008 if (res_locked(fh->dev, fh)) { 1016 if (res_locked(fh)) {
1009 dprintk(1, "%s: channel busy\n", __func__); 1017 dprintk(1, "%s: channel busy\n", __func__);
1010 ret = -EBUSY; 1018 ret = -EBUSY;
1011 goto out_s_fmt; 1019 goto out_s_fmt;
1012 } 1020 }
1013 1021 mode = channel->mode;
1014 fh->fmt = fmt; 1022 channel->fmt = fmt;
1015 fh->width = f->fmt.pix.width; 1023 channel->width = f->fmt.pix.width;
1016 fh->height = f->fmt.pix.height; 1024 channel->height = f->fmt.pix.height;
1017 fh->vb_vidq.field = f->fmt.pix.field; 1025 fh->vb_vidq.field = f->fmt.pix.field;
1018 fh->type = f->type; 1026 fh->type = f->type;
1019 norm = norm_minw(&fh->dev->vdev[fh->channel]); 1027 norm = norm_minw(&channel->vdev);
1020 if (fh->width > norm_minw(&fh->dev->vdev[fh->channel])) { 1028 if (channel->width > norm_minw(&channel->vdev)) {
1021 if (fh->height > norm_minh(&fh->dev->vdev[fh->channel])) { 1029 if (channel->height > norm_minh(&channel->vdev)) {
1022 if (fh->dev->cap_parm[fh->channel].capturemode & 1030 if (channel->cap_parm.capturemode &
1023 V4L2_MODE_HIGHQUALITY) 1031 V4L2_MODE_HIGHQUALITY)
1024 fh->mode.scale = SCALE_4CIFSI; 1032 mode.scale = SCALE_4CIFSI;
1025 else 1033 else
1026 fh->mode.scale = SCALE_4CIFS; 1034 mode.scale = SCALE_4CIFS;
1027 } else 1035 } else
1028 fh->mode.scale = SCALE_2CIFS; 1036 mode.scale = SCALE_2CIFS;
1029 1037
1030 } else { 1038 } else {
1031 fh->mode.scale = SCALE_1CIFS; 1039 mode.scale = SCALE_1CIFS;
1032 } 1040 }
1033
1034 /* color mode */ 1041 /* color mode */
1035 switch (fh->fmt->fourcc) { 1042 switch (channel->fmt->fourcc) {
1036 case V4L2_PIX_FMT_GREY: 1043 case V4L2_PIX_FMT_GREY:
1037 fh->mode.color &= ~MASK_COLOR; 1044 mode.color &= ~MASK_COLOR;
1038 fh->mode.color |= COLOR_Y8; 1045 mode.color |= COLOR_Y8;
1039 break; 1046 break;
1040 case V4L2_PIX_FMT_JPEG: 1047 case V4L2_PIX_FMT_JPEG:
1041 fh->mode.color &= ~MASK_COLOR; 1048 mode.color &= ~MASK_COLOR;
1042 fh->mode.color |= COLOR_JPG; 1049 mode.color |= COLOR_JPG;
1043 fh->mode.color |= (fh->dev->jc[fh->channel].quality << 8); 1050 mode.color |= (channel->jc.quality << 8);
1044 break; 1051 break;
1045 case V4L2_PIX_FMT_YUV422P: 1052 case V4L2_PIX_FMT_YUV422P:
1046 fh->mode.color &= ~MASK_COLOR; 1053 mode.color &= ~MASK_COLOR;
1047 fh->mode.color |= COLOR_YUVPL; 1054 mode.color |= COLOR_YUVPL;
1048 break; 1055 break;
1049 case V4L2_PIX_FMT_YUYV: 1056 case V4L2_PIX_FMT_YUYV:
1050 case V4L2_PIX_FMT_UYVY: 1057 case V4L2_PIX_FMT_UYVY:
1051 default: 1058 default:
1052 fh->mode.color &= ~MASK_COLOR; 1059 mode.color &= ~MASK_COLOR;
1053 fh->mode.color |= COLOR_YUVPK; 1060 mode.color |= COLOR_YUVPK;
1054 break; 1061 break;
1055 } 1062 }
1063 if ((mode.color & MASK_COLOR) != (channel->mode.color & MASK_COLOR))
1064 mode.restart = 1;
1065 else if (mode.scale != channel->mode.scale)
1066 mode.restart = 1;
1067 else if (mode.format != channel->mode.format)
1068 mode.restart = 1;
1069 channel->mode = mode;
1070 (void) s2255_set_mode(channel, &mode);
1056 ret = 0; 1071 ret = 0;
1057out_s_fmt: 1072out_s_fmt:
1058 mutex_unlock(&q->vb_lock); 1073 mutex_unlock(&q->vb_lock);
@@ -1197,26 +1212,27 @@ static void s2255_print_cfg(struct s2255_dev *sdev, struct s2255_mode *mode)
1197 * When the restart parameter is set, we sleep for ONE frame to allow the 1212 * When the restart parameter is set, we sleep for ONE frame to allow the
1198 * DSP time to get the new frame 1213 * DSP time to get the new frame
1199 */ 1214 */
1200static int s2255_set_mode(struct s2255_dev *dev, unsigned long chn, 1215static int s2255_set_mode(struct s2255_channel *channel,
1201 struct s2255_mode *mode) 1216 struct s2255_mode *mode)
1202{ 1217{
1203 int res; 1218 int res;
1204 __le32 *buffer; 1219 __le32 *buffer;
1205 unsigned long chn_rev; 1220 unsigned long chn_rev;
1221 struct s2255_dev *dev = to_s2255_dev(channel->vdev.v4l2_dev);
1206 mutex_lock(&dev->lock); 1222 mutex_lock(&dev->lock);
1207 chn_rev = G_chnmap[chn]; 1223 chn_rev = G_chnmap[channel->idx];
1208 dprintk(3, "%s channel %lu\n", __func__, chn); 1224 dprintk(3, "%s channel: %d\n", __func__, channel->idx);
1209 /* if JPEG, set the quality */ 1225 /* if JPEG, set the quality */
1210 if ((mode->color & MASK_COLOR) == COLOR_JPG) { 1226 if ((mode->color & MASK_COLOR) == COLOR_JPG) {
1211 mode->color &= ~MASK_COLOR; 1227 mode->color &= ~MASK_COLOR;
1212 mode->color |= COLOR_JPG; 1228 mode->color |= COLOR_JPG;
1213 mode->color &= ~MASK_JPG_QUALITY; 1229 mode->color &= ~MASK_JPG_QUALITY;
1214 mode->color |= (dev->jc[chn].quality << 8); 1230 mode->color |= (channel->jc.quality << 8);
1215 } 1231 }
1216 /* save the mode */ 1232 /* save the mode */
1217 dev->mode[chn] = *mode; 1233 channel->mode = *mode;
1218 dev->req_image_size[chn] = get_transfer_size(mode); 1234 channel->req_image_size = get_transfer_size(mode);
1219 dprintk(1, "%s: reqsize %ld\n", __func__, dev->req_image_size[chn]); 1235 dprintk(1, "%s: reqsize %ld\n", __func__, channel->req_image_size);
1220 buffer = kzalloc(512, GFP_KERNEL); 1236 buffer = kzalloc(512, GFP_KERNEL);
1221 if (buffer == NULL) { 1237 if (buffer == NULL) {
1222 dev_err(&dev->udev->dev, "out of mem\n"); 1238 dev_err(&dev->udev->dev, "out of mem\n");
@@ -1227,38 +1243,38 @@ static int s2255_set_mode(struct s2255_dev *dev, unsigned long chn,
1227 buffer[0] = IN_DATA_TOKEN; 1243 buffer[0] = IN_DATA_TOKEN;
1228 buffer[1] = (__le32) cpu_to_le32(chn_rev); 1244 buffer[1] = (__le32) cpu_to_le32(chn_rev);
1229 buffer[2] = CMD_SET_MODE; 1245 buffer[2] = CMD_SET_MODE;
1230 memcpy(&buffer[3], &dev->mode[chn], sizeof(struct s2255_mode)); 1246 memcpy(&buffer[3], &channel->mode, sizeof(struct s2255_mode));
1231 dev->setmode_ready[chn] = 0; 1247 channel->setmode_ready = 0;
1232 res = s2255_write_config(dev->udev, (unsigned char *)buffer, 512); 1248 res = s2255_write_config(dev->udev, (unsigned char *)buffer, 512);
1233 if (debug) 1249 if (debug)
1234 s2255_print_cfg(dev, mode); 1250 s2255_print_cfg(dev, mode);
1235 kfree(buffer); 1251 kfree(buffer);
1236 /* wait at least 3 frames before continuing */ 1252 /* wait at least 3 frames before continuing */
1237 if (mode->restart) { 1253 if (mode->restart) {
1238 wait_event_timeout(dev->wait_setmode[chn], 1254 wait_event_timeout(channel->wait_setmode,
1239 (dev->setmode_ready[chn] != 0), 1255 (channel->setmode_ready != 0),
1240 msecs_to_jiffies(S2255_SETMODE_TIMEOUT)); 1256 msecs_to_jiffies(S2255_SETMODE_TIMEOUT));
1241 if (dev->setmode_ready[chn] != 1) { 1257 if (channel->setmode_ready != 1) {
1242 printk(KERN_DEBUG "s2255: no set mode response\n"); 1258 printk(KERN_DEBUG "s2255: no set mode response\n");
1243 res = -EFAULT; 1259 res = -EFAULT;
1244 } 1260 }
1245 } 1261 }
1246 /* clear the restart flag */ 1262 /* clear the restart flag */
1247 dev->mode[chn].restart = 0; 1263 channel->mode.restart = 0;
1248 mutex_unlock(&dev->lock); 1264 mutex_unlock(&dev->lock);
1249 dprintk(1, "%s chn %lu, result: %d\n", __func__, chn, res); 1265 dprintk(1, "%s chn %d, result: %d\n", __func__, channel->idx, res);
1250 return res; 1266 return res;
1251} 1267}
1252 1268
1253static int s2255_cmd_status(struct s2255_dev *dev, unsigned long chn, 1269static int s2255_cmd_status(struct s2255_channel *channel, u32 *pstatus)
1254 u32 *pstatus)
1255{ 1270{
1256 int res; 1271 int res;
1257 __le32 *buffer; 1272 __le32 *buffer;
1258 u32 chn_rev; 1273 u32 chn_rev;
1274 struct s2255_dev *dev = to_s2255_dev(channel->vdev.v4l2_dev);
1259 mutex_lock(&dev->lock); 1275 mutex_lock(&dev->lock);
1260 chn_rev = G_chnmap[chn]; 1276 chn_rev = G_chnmap[channel->idx];
1261 dprintk(4, "%s chan %lu\n", __func__, chn); 1277 dprintk(4, "%s chan %d\n", __func__, channel->idx);
1262 buffer = kzalloc(512, GFP_KERNEL); 1278 buffer = kzalloc(512, GFP_KERNEL);
1263 if (buffer == NULL) { 1279 if (buffer == NULL) {
1264 dev_err(&dev->udev->dev, "out of mem\n"); 1280 dev_err(&dev->udev->dev, "out of mem\n");
@@ -1270,17 +1286,17 @@ static int s2255_cmd_status(struct s2255_dev *dev, unsigned long chn,
1270 buffer[1] = (__le32) cpu_to_le32(chn_rev); 1286 buffer[1] = (__le32) cpu_to_le32(chn_rev);
1271 buffer[2] = CMD_STATUS; 1287 buffer[2] = CMD_STATUS;
1272 *pstatus = 0; 1288 *pstatus = 0;
1273 dev->vidstatus_ready[chn] = 0; 1289 channel->vidstatus_ready = 0;
1274 res = s2255_write_config(dev->udev, (unsigned char *)buffer, 512); 1290 res = s2255_write_config(dev->udev, (unsigned char *)buffer, 512);
1275 kfree(buffer); 1291 kfree(buffer);
1276 wait_event_timeout(dev->wait_vidstatus[chn], 1292 wait_event_timeout(channel->wait_vidstatus,
1277 (dev->vidstatus_ready[chn] != 0), 1293 (channel->vidstatus_ready != 0),
1278 msecs_to_jiffies(S2255_VIDSTATUS_TIMEOUT)); 1294 msecs_to_jiffies(S2255_VIDSTATUS_TIMEOUT));
1279 if (dev->vidstatus_ready[chn] != 1) { 1295 if (channel->vidstatus_ready != 1) {
1280 printk(KERN_DEBUG "s2255: no vidstatus response\n"); 1296 printk(KERN_DEBUG "s2255: no vidstatus response\n");
1281 res = -EFAULT; 1297 res = -EFAULT;
1282 } 1298 }
1283 *pstatus = dev->vidstatus[chn]; 1299 *pstatus = channel->vidstatus;
1284 dprintk(4, "%s, vid status %d\n", __func__, *pstatus); 1300 dprintk(4, "%s, vid status %d\n", __func__, *pstatus);
1285 mutex_unlock(&dev->lock); 1301 mutex_unlock(&dev->lock);
1286 return res; 1302 return res;
@@ -1291,9 +1307,7 @@ static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
1291 int res; 1307 int res;
1292 struct s2255_fh *fh = priv; 1308 struct s2255_fh *fh = priv;
1293 struct s2255_dev *dev = fh->dev; 1309 struct s2255_dev *dev = fh->dev;
1294 struct s2255_mode *new_mode; 1310 struct s2255_channel *channel = fh->channel;
1295 struct s2255_mode *old_mode;
1296 int chn;
1297 int j; 1311 int j;
1298 dprintk(4, "%s\n", __func__); 1312 dprintk(4, "%s\n", __func__);
1299 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) { 1313 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
@@ -1305,51 +1319,32 @@ static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
1305 return -EINVAL; 1319 return -EINVAL;
1306 } 1320 }
1307 1321
1308 if (!res_get(dev, fh)) { 1322 if (!res_get(fh)) {
1309 s2255_dev_err(&dev->udev->dev, "stream busy\n"); 1323 s2255_dev_err(&dev->udev->dev, "stream busy\n");
1310 return -EBUSY; 1324 return -EBUSY;
1311 } 1325 }
1312 1326 channel->last_frame = -1;
1313 /* send a set mode command everytime with restart. 1327 channel->bad_payload = 0;
1314 in case we switch resolutions or other parameters */ 1328 channel->cur_frame = 0;
1315 chn = fh->channel; 1329 channel->frame_count = 0;
1316 new_mode = &fh->mode;
1317 old_mode = &fh->dev->mode[chn];
1318
1319 if ((new_mode->color & MASK_COLOR) != (old_mode->color & MASK_COLOR))
1320 new_mode->restart = 1;
1321 else if (new_mode->scale != old_mode->scale)
1322 new_mode->restart = 1;
1323 else if (new_mode->format != old_mode->format)
1324 new_mode->restart = 1;
1325
1326 s2255_set_mode(dev, chn, new_mode);
1327 new_mode->restart = 0;
1328 *old_mode = *new_mode;
1329 dev->cur_fmt[chn] = fh->fmt;
1330 dev->last_frame[chn] = -1;
1331 dev->bad_payload[chn] = 0;
1332 dev->cur_frame[chn] = 0;
1333 dev->frame_count[chn] = 0;
1334 for (j = 0; j < SYS_FRAMES; j++) { 1330 for (j = 0; j < SYS_FRAMES; j++) {
1335 dev->buffer[chn].frame[j].ulState = S2255_READ_IDLE; 1331 channel->buffer.frame[j].ulState = S2255_READ_IDLE;
1336 dev->buffer[chn].frame[j].cur_size = 0; 1332 channel->buffer.frame[j].cur_size = 0;
1337 } 1333 }
1338 res = videobuf_streamon(&fh->vb_vidq); 1334 res = videobuf_streamon(&fh->vb_vidq);
1339 if (res == 0) { 1335 if (res == 0) {
1340 s2255_start_acquire(dev, chn); 1336 s2255_start_acquire(channel);
1341 dev->b_acquire[chn] = 1; 1337 channel->b_acquire = 1;
1342 } else { 1338 } else
1343 res_free(dev, fh); 1339 res_free(fh);
1344 } 1340
1345 return res; 1341 return res;
1346} 1342}
1347 1343
1348static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i) 1344static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
1349{ 1345{
1350 struct s2255_fh *fh = priv; 1346 struct s2255_fh *fh = priv;
1351 struct s2255_dev *dev = fh->dev; 1347 dprintk(4, "%s\n, channel: %d", __func__, fh->channel->idx);
1352 dprintk(4, "%s\n, channel: %d", __func__, fh->channel);
1353 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) { 1348 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1354 printk(KERN_ERR "invalid fh type0\n"); 1349 printk(KERN_ERR "invalid fh type0\n");
1355 return -EINVAL; 1350 return -EINVAL;
@@ -1358,16 +1353,16 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
1358 printk(KERN_ERR "invalid type i\n"); 1353 printk(KERN_ERR "invalid type i\n");
1359 return -EINVAL; 1354 return -EINVAL;
1360 } 1355 }
1361 s2255_stop_acquire(dev, fh->channel); 1356 s2255_stop_acquire(fh->channel);
1362 videobuf_streamoff(&fh->vb_vidq); 1357 videobuf_streamoff(&fh->vb_vidq);
1363 res_free(dev, fh); 1358 res_free(fh);
1364 return 0; 1359 return 0;
1365} 1360}
1366 1361
1367static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *i) 1362static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *i)
1368{ 1363{
1369 struct s2255_fh *fh = priv; 1364 struct s2255_fh *fh = priv;
1370 struct s2255_mode *mode; 1365 struct s2255_mode mode;
1371 struct videobuf_queue *q = &fh->vb_vidq; 1366 struct videobuf_queue *q = &fh->vb_vidq;
1372 int ret = 0; 1367 int ret = 0;
1373 mutex_lock(&q->vb_lock); 1368 mutex_lock(&q->vb_lock);
@@ -1376,29 +1371,32 @@ static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *i)
1376 ret = -EBUSY; 1371 ret = -EBUSY;
1377 goto out_s_std; 1372 goto out_s_std;
1378 } 1373 }
1379 if (res_locked(fh->dev, fh)) { 1374 if (res_locked(fh)) {
1380 dprintk(1, "can't change standard after started\n"); 1375 dprintk(1, "can't change standard after started\n");
1381 ret = -EBUSY; 1376 ret = -EBUSY;
1382 goto out_s_std; 1377 goto out_s_std;
1383 } 1378 }
1384 mode = &fh->mode; 1379 mode = fh->channel->mode;
1385 if (*i & V4L2_STD_NTSC) { 1380 if (*i & V4L2_STD_NTSC) {
1386 dprintk(4, "%s NTSC\n", __func__); 1381 dprintk(4, "%s NTSC\n", __func__);
1387 /* if changing format, reset frame decimation/intervals */ 1382 /* if changing format, reset frame decimation/intervals */
1388 if (mode->format != FORMAT_NTSC) { 1383 if (mode.format != FORMAT_NTSC) {
1389 mode->format = FORMAT_NTSC; 1384 mode.restart = 1;
1390 mode->fdec = FDEC_1; 1385 mode.format = FORMAT_NTSC;
1386 mode.fdec = FDEC_1;
1391 } 1387 }
1392 } else if (*i & V4L2_STD_PAL) { 1388 } else if (*i & V4L2_STD_PAL) {
1393 dprintk(4, "%s PAL\n", __func__); 1389 dprintk(4, "%s PAL\n", __func__);
1394 mode->format = FORMAT_PAL; 1390 if (mode.format != FORMAT_PAL) {
1395 if (mode->format != FORMAT_PAL) { 1391 mode.restart = 1;
1396 mode->format = FORMAT_PAL; 1392 mode.format = FORMAT_PAL;
1397 mode->fdec = FDEC_1; 1393 mode.fdec = FDEC_1;
1398 } 1394 }
1399 } else { 1395 } else {
1400 ret = -EINVAL; 1396 ret = -EINVAL;
1401 } 1397 }
1398 if (mode.restart)
1399 s2255_set_mode(fh->channel, &mode);
1402out_s_std: 1400out_s_std:
1403 mutex_unlock(&q->vb_lock); 1401 mutex_unlock(&q->vb_lock);
1404 return ret; 1402 return ret;
@@ -1416,6 +1414,7 @@ static int vidioc_enum_input(struct file *file, void *priv,
1416{ 1414{
1417 struct s2255_fh *fh = priv; 1415 struct s2255_fh *fh = priv;
1418 struct s2255_dev *dev = fh->dev; 1416 struct s2255_dev *dev = fh->dev;
1417 struct s2255_channel *channel = fh->channel;
1419 u32 status = 0; 1418 u32 status = 0;
1420 if (inp->index != 0) 1419 if (inp->index != 0)
1421 return -EINVAL; 1420 return -EINVAL;
@@ -1424,7 +1423,7 @@ static int vidioc_enum_input(struct file *file, void *priv,
1424 inp->status = 0; 1423 inp->status = 0;
1425 if (dev->dsp_fw_ver >= S2255_MIN_DSP_STATUS) { 1424 if (dev->dsp_fw_ver >= S2255_MIN_DSP_STATUS) {
1426 int rc; 1425 int rc;
1427 rc = s2255_cmd_status(dev, fh->channel, &status); 1426 rc = s2255_cmd_status(fh->channel, &status);
1428 dprintk(4, "s2255_cmd_status rc: %d status %x\n", rc, status); 1427 dprintk(4, "s2255_cmd_status rc: %d status %x\n", rc, status);
1429 if (rc == 0) 1428 if (rc == 0)
1430 inp->status = (status & 0x01) ? 0 1429 inp->status = (status & 0x01) ? 0
@@ -1436,7 +1435,7 @@ static int vidioc_enum_input(struct file *file, void *priv,
1436 strlcpy(inp->name, "Composite", sizeof(inp->name)); 1435 strlcpy(inp->name, "Composite", sizeof(inp->name));
1437 break; 1436 break;
1438 case 0x2257: 1437 case 0x2257:
1439 strlcpy(inp->name, (fh->channel < 2) ? "Composite" : "S-Video", 1438 strlcpy(inp->name, (channel->idx < 2) ? "Composite" : "S-Video",
1440 sizeof(inp->name)); 1439 sizeof(inp->name));
1441 break; 1440 break;
1442 } 1441 }
@@ -1460,6 +1459,7 @@ static int vidioc_queryctrl(struct file *file, void *priv,
1460 struct v4l2_queryctrl *qc) 1459 struct v4l2_queryctrl *qc)
1461{ 1460{
1462 struct s2255_fh *fh = priv; 1461 struct s2255_fh *fh = priv;
1462 struct s2255_channel *channel = fh->channel;
1463 struct s2255_dev *dev = fh->dev; 1463 struct s2255_dev *dev = fh->dev;
1464 switch (qc->id) { 1464 switch (qc->id) {
1465 case V4L2_CID_BRIGHTNESS: 1465 case V4L2_CID_BRIGHTNESS:
@@ -1477,7 +1477,7 @@ static int vidioc_queryctrl(struct file *file, void *priv,
1477 case V4L2_CID_PRIVATE_COLORFILTER: 1477 case V4L2_CID_PRIVATE_COLORFILTER:
1478 if (dev->dsp_fw_ver < S2255_MIN_DSP_COLORFILTER) 1478 if (dev->dsp_fw_ver < S2255_MIN_DSP_COLORFILTER)
1479 return -EINVAL; 1479 return -EINVAL;
1480 if ((dev->pid == 0x2257) && (fh->channel > 1)) 1480 if ((dev->pid == 0x2257) && (channel->idx > 1))
1481 return -EINVAL; 1481 return -EINVAL;
1482 strlcpy(qc->name, "Color Filter", sizeof(qc->name)); 1482 strlcpy(qc->name, "Color Filter", sizeof(qc->name));
1483 qc->type = V4L2_CTRL_TYPE_MENU; 1483 qc->type = V4L2_CTRL_TYPE_MENU;
@@ -1499,25 +1499,26 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
1499{ 1499{
1500 struct s2255_fh *fh = priv; 1500 struct s2255_fh *fh = priv;
1501 struct s2255_dev *dev = fh->dev; 1501 struct s2255_dev *dev = fh->dev;
1502 struct s2255_channel *channel = fh->channel;
1502 switch (ctrl->id) { 1503 switch (ctrl->id) {
1503 case V4L2_CID_BRIGHTNESS: 1504 case V4L2_CID_BRIGHTNESS:
1504 ctrl->value = fh->mode.bright; 1505 ctrl->value = channel->mode.bright;
1505 break; 1506 break;
1506 case V4L2_CID_CONTRAST: 1507 case V4L2_CID_CONTRAST:
1507 ctrl->value = fh->mode.contrast; 1508 ctrl->value = channel->mode.contrast;
1508 break; 1509 break;
1509 case V4L2_CID_SATURATION: 1510 case V4L2_CID_SATURATION:
1510 ctrl->value = fh->mode.saturation; 1511 ctrl->value = channel->mode.saturation;
1511 break; 1512 break;
1512 case V4L2_CID_HUE: 1513 case V4L2_CID_HUE:
1513 ctrl->value = fh->mode.hue; 1514 ctrl->value = channel->mode.hue;
1514 break; 1515 break;
1515 case V4L2_CID_PRIVATE_COLORFILTER: 1516 case V4L2_CID_PRIVATE_COLORFILTER:
1516 if (dev->dsp_fw_ver < S2255_MIN_DSP_COLORFILTER) 1517 if (dev->dsp_fw_ver < S2255_MIN_DSP_COLORFILTER)
1517 return -EINVAL; 1518 return -EINVAL;
1518 if ((dev->pid == 0x2257) && (fh->channel > 1)) 1519 if ((dev->pid == 0x2257) && (channel->idx > 1))
1519 return -EINVAL; 1520 return -EINVAL;
1520 ctrl->value = !((fh->mode.color & MASK_INPUT_TYPE) >> 16); 1521 ctrl->value = !((channel->mode.color & MASK_INPUT_TYPE) >> 16);
1521 break; 1522 break;
1522 default: 1523 default:
1523 return -EINVAL; 1524 return -EINVAL;
@@ -1530,41 +1531,42 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
1530 struct v4l2_control *ctrl) 1531 struct v4l2_control *ctrl)
1531{ 1532{
1532 struct s2255_fh *fh = priv; 1533 struct s2255_fh *fh = priv;
1533 struct s2255_dev *dev = fh->dev; 1534 struct s2255_channel *channel = fh->channel;
1534 struct s2255_mode *mode; 1535 struct s2255_dev *dev = to_s2255_dev(channel->vdev.v4l2_dev);
1535 mode = &fh->mode; 1536 struct s2255_mode mode;
1537 mode = channel->mode;
1536 dprintk(4, "%s\n", __func__); 1538 dprintk(4, "%s\n", __func__);
1537 /* update the mode to the corresponding value */ 1539 /* update the mode to the corresponding value */
1538 switch (ctrl->id) { 1540 switch (ctrl->id) {
1539 case V4L2_CID_BRIGHTNESS: 1541 case V4L2_CID_BRIGHTNESS:
1540 mode->bright = ctrl->value; 1542 mode.bright = ctrl->value;
1541 break; 1543 break;
1542 case V4L2_CID_CONTRAST: 1544 case V4L2_CID_CONTRAST:
1543 mode->contrast = ctrl->value; 1545 mode.contrast = ctrl->value;
1544 break; 1546 break;
1545 case V4L2_CID_HUE: 1547 case V4L2_CID_HUE:
1546 mode->hue = ctrl->value; 1548 mode.hue = ctrl->value;
1547 break; 1549 break;
1548 case V4L2_CID_SATURATION: 1550 case V4L2_CID_SATURATION:
1549 mode->saturation = ctrl->value; 1551 mode.saturation = ctrl->value;
1550 break; 1552 break;
1551 case V4L2_CID_PRIVATE_COLORFILTER: 1553 case V4L2_CID_PRIVATE_COLORFILTER:
1552 if (dev->dsp_fw_ver < S2255_MIN_DSP_COLORFILTER) 1554 if (dev->dsp_fw_ver < S2255_MIN_DSP_COLORFILTER)
1553 return -EINVAL; 1555 return -EINVAL;
1554 if ((dev->pid == 0x2257) && (fh->channel > 1)) 1556 if ((dev->pid == 0x2257) && (channel->idx > 1))
1555 return -EINVAL; 1557 return -EINVAL;
1556 mode->color &= ~MASK_INPUT_TYPE; 1558 mode.color &= ~MASK_INPUT_TYPE;
1557 mode->color |= ((ctrl->value ? 0 : 1) << 16); 1559 mode.color |= ((ctrl->value ? 0 : 1) << 16);
1558 break; 1560 break;
1559 default: 1561 default:
1560 return -EINVAL; 1562 return -EINVAL;
1561 } 1563 }
1562 mode->restart = 0; 1564 mode.restart = 0;
1563 /* set mode here. Note: stream does not need restarted. 1565 /* set mode here. Note: stream does not need restarted.
1564 some V4L programs restart stream unnecessarily 1566 some V4L programs restart stream unnecessarily
1565 after a s_crtl. 1567 after a s_crtl.
1566 */ 1568 */
1567 s2255_set_mode(dev, fh->channel, mode); 1569 s2255_set_mode(fh->channel, &mode);
1568 return 0; 1570 return 0;
1569} 1571}
1570 1572
@@ -1572,8 +1574,8 @@ static int vidioc_g_jpegcomp(struct file *file, void *priv,
1572 struct v4l2_jpegcompression *jc) 1574 struct v4l2_jpegcompression *jc)
1573{ 1575{
1574 struct s2255_fh *fh = priv; 1576 struct s2255_fh *fh = priv;
1575 struct s2255_dev *dev = fh->dev; 1577 struct s2255_channel *channel = fh->channel;
1576 *jc = dev->jc[fh->channel]; 1578 *jc = channel->jc;
1577 dprintk(2, "%s: quality %d\n", __func__, jc->quality); 1579 dprintk(2, "%s: quality %d\n", __func__, jc->quality);
1578 return 0; 1580 return 0;
1579} 1581}
@@ -1582,10 +1584,10 @@ static int vidioc_s_jpegcomp(struct file *file, void *priv,
1582 struct v4l2_jpegcompression *jc) 1584 struct v4l2_jpegcompression *jc)
1583{ 1585{
1584 struct s2255_fh *fh = priv; 1586 struct s2255_fh *fh = priv;
1585 struct s2255_dev *dev = fh->dev; 1587 struct s2255_channel *channel = fh->channel;
1586 if (jc->quality < 0 || jc->quality > 100) 1588 if (jc->quality < 0 || jc->quality > 100)
1587 return -EINVAL; 1589 return -EINVAL;
1588 dev->jc[fh->channel].quality = jc->quality; 1590 channel->jc.quality = jc->quality;
1589 dprintk(2, "%s: quality %d\n", __func__, jc->quality); 1591 dprintk(2, "%s: quality %d\n", __func__, jc->quality);
1590 return 0; 1592 return 0;
1591} 1593}
@@ -1594,17 +1596,17 @@ static int vidioc_g_parm(struct file *file, void *priv,
1594 struct v4l2_streamparm *sp) 1596 struct v4l2_streamparm *sp)
1595{ 1597{
1596 struct s2255_fh *fh = priv; 1598 struct s2255_fh *fh = priv;
1597 struct s2255_dev *dev = fh->dev;
1598 __u32 def_num, def_dem; 1599 __u32 def_num, def_dem;
1600 struct s2255_channel *channel = fh->channel;
1599 if (sp->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 1601 if (sp->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1600 return -EINVAL; 1602 return -EINVAL;
1601 memset(sp, 0, sizeof(struct v4l2_streamparm)); 1603 memset(sp, 0, sizeof(struct v4l2_streamparm));
1602 sp->parm.capture.capability = V4L2_CAP_TIMEPERFRAME; 1604 sp->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
1603 sp->parm.capture.capturemode = dev->cap_parm[fh->channel].capturemode; 1605 sp->parm.capture.capturemode = channel->cap_parm.capturemode;
1604 def_num = (fh->mode.format == FORMAT_NTSC) ? 1001 : 1000; 1606 def_num = (channel->mode.format == FORMAT_NTSC) ? 1001 : 1000;
1605 def_dem = (fh->mode.format == FORMAT_NTSC) ? 30000 : 25000; 1607 def_dem = (channel->mode.format == FORMAT_NTSC) ? 30000 : 25000;
1606 sp->parm.capture.timeperframe.denominator = def_dem; 1608 sp->parm.capture.timeperframe.denominator = def_dem;
1607 switch (fh->mode.fdec) { 1609 switch (channel->mode.fdec) {
1608 default: 1610 default:
1609 case FDEC_1: 1611 case FDEC_1:
1610 sp->parm.capture.timeperframe.numerator = def_num; 1612 sp->parm.capture.timeperframe.numerator = def_num;
@@ -1630,17 +1632,19 @@ static int vidioc_s_parm(struct file *file, void *priv,
1630 struct v4l2_streamparm *sp) 1632 struct v4l2_streamparm *sp)
1631{ 1633{
1632 struct s2255_fh *fh = priv; 1634 struct s2255_fh *fh = priv;
1633 struct s2255_dev *dev = fh->dev; 1635 struct s2255_channel *channel = fh->channel;
1636 struct s2255_mode mode;
1634 int fdec = FDEC_1; 1637 int fdec = FDEC_1;
1635 __u32 def_num, def_dem; 1638 __u32 def_num, def_dem;
1636 if (sp->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 1639 if (sp->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1637 return -EINVAL; 1640 return -EINVAL;
1641 mode = channel->mode;
1638 /* high quality capture mode requires a stream restart */ 1642 /* high quality capture mode requires a stream restart */
1639 if (dev->cap_parm[fh->channel].capturemode 1643 if (channel->cap_parm.capturemode
1640 != sp->parm.capture.capturemode && res_locked(fh->dev, fh)) 1644 != sp->parm.capture.capturemode && res_locked(fh))
1641 return -EBUSY; 1645 return -EBUSY;
1642 def_num = (fh->mode.format == FORMAT_NTSC) ? 1001 : 1000; 1646 def_num = (mode.format == FORMAT_NTSC) ? 1001 : 1000;
1643 def_dem = (fh->mode.format == FORMAT_NTSC) ? 30000 : 25000; 1647 def_dem = (mode.format == FORMAT_NTSC) ? 30000 : 25000;
1644 if (def_dem != sp->parm.capture.timeperframe.denominator) 1648 if (def_dem != sp->parm.capture.timeperframe.denominator)
1645 sp->parm.capture.timeperframe.numerator = def_num; 1649 sp->parm.capture.timeperframe.numerator = def_num;
1646 else if (sp->parm.capture.timeperframe.numerator <= def_num) 1650 else if (sp->parm.capture.timeperframe.numerator <= def_num)
@@ -1655,9 +1659,9 @@ static int vidioc_s_parm(struct file *file, void *priv,
1655 sp->parm.capture.timeperframe.numerator = def_num * 5; 1659 sp->parm.capture.timeperframe.numerator = def_num * 5;
1656 fdec = FDEC_5; 1660 fdec = FDEC_5;
1657 } 1661 }
1658 fh->mode.fdec = fdec; 1662 mode.fdec = fdec;
1659 sp->parm.capture.timeperframe.denominator = def_dem; 1663 sp->parm.capture.timeperframe.denominator = def_dem;
1660 s2255_set_mode(dev, fh->channel, &fh->mode); 1664 s2255_set_mode(channel, &mode);
1661 dprintk(4, "%s capture mode, %d timeperframe %d/%d, fdec %d\n", 1665 dprintk(4, "%s capture mode, %d timeperframe %d/%d, fdec %d\n",
1662 __func__, 1666 __func__,
1663 sp->parm.capture.capturemode, 1667 sp->parm.capture.capturemode,
@@ -1707,24 +1711,13 @@ static int vidioc_enum_frameintervals(struct file *file, void *priv,
1707static int s2255_open(struct file *file) 1711static int s2255_open(struct file *file)
1708{ 1712{
1709 struct video_device *vdev = video_devdata(file); 1713 struct video_device *vdev = video_devdata(file);
1710 struct s2255_dev *dev = video_drvdata(file); 1714 struct s2255_channel *channel = video_drvdata(file);
1715 struct s2255_dev *dev = to_s2255_dev(vdev->v4l2_dev);
1711 struct s2255_fh *fh; 1716 struct s2255_fh *fh;
1712 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 1717 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1713 int i = 0;
1714 int cur_channel = -1;
1715 int state; 1718 int state;
1716 dprintk(1, "s2255: open called (dev=%s)\n", 1719 dprintk(1, "s2255: open called (dev=%s)\n",
1717 video_device_node_name(vdev)); 1720 video_device_node_name(vdev));
1718
1719 for (i = 0; i < MAX_CHANNELS; i++) {
1720 if (&dev->vdev[i] == vdev) {
1721 cur_channel = i;
1722 break;
1723 }
1724 }
1725 if (i == MAX_CHANNELS)
1726 return -ENODEV;
1727
1728 /* 1721 /*
1729 * open lock necessary to prevent multiple instances 1722 * open lock necessary to prevent multiple instances
1730 * of v4l-conf (or other programs) from simultaneously 1723 * of v4l-conf (or other programs) from simultaneously
@@ -1806,24 +1799,20 @@ static int s2255_open(struct file *file)
1806 file->private_data = fh; 1799 file->private_data = fh;
1807 fh->dev = dev; 1800 fh->dev = dev;
1808 fh->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 1801 fh->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1809 fh->mode = dev->mode[cur_channel]; 1802 fh->channel = channel;
1810 fh->fmt = dev->cur_fmt[cur_channel]; 1803 if (!channel->configured) {
1811 /* default 4CIF NTSC */ 1804 /* configure channel to default state */
1812 fh->width = LINE_SZ_4CIFS_NTSC; 1805 channel->fmt = &formats[0];
1813 fh->height = NUM_LINES_4CIFS_NTSC * 2; 1806 s2255_set_mode(channel, &channel->mode);
1814 fh->channel = cur_channel; 1807 channel->configured = 1;
1815 /* configure channel to default state */
1816 if (!dev->chn_configured[cur_channel]) {
1817 s2255_set_mode(dev, cur_channel, &fh->mode);
1818 dev->chn_configured[cur_channel] = 1;
1819 } 1808 }
1820 dprintk(1, "%s: dev=%s type=%s\n", __func__, 1809 dprintk(1, "%s: dev=%s type=%s\n", __func__,
1821 video_device_node_name(vdev), v4l2_type_names[type]); 1810 video_device_node_name(vdev), v4l2_type_names[type]);
1822 dprintk(2, "%s: fh=0x%08lx, dev=0x%08lx, vidq=0x%08lx\n", __func__, 1811 dprintk(2, "%s: fh=0x%08lx, dev=0x%08lx, vidq=0x%08lx\n", __func__,
1823 (unsigned long)fh, (unsigned long)dev, 1812 (unsigned long)fh, (unsigned long)dev,
1824 (unsigned long)&dev->vidq[cur_channel]); 1813 (unsigned long)&channel->vidq);
1825 dprintk(4, "%s: list_empty active=%d\n", __func__, 1814 dprintk(4, "%s: list_empty active=%d\n", __func__,
1826 list_empty(&dev->vidq[cur_channel].active)); 1815 list_empty(&channel->vidq.active));
1827 videobuf_queue_vmalloc_init(&fh->vb_vidq, &s2255_video_qops, 1816 videobuf_queue_vmalloc_init(&fh->vb_vidq, &s2255_video_qops,
1828 NULL, &dev->slock, 1817 NULL, &dev->slock,
1829 fh->type, 1818 fh->type,
@@ -1865,6 +1854,7 @@ static void s2255_destroy(struct s2255_dev *dev)
1865 mutex_destroy(&dev->open_lock); 1854 mutex_destroy(&dev->open_lock);
1866 mutex_destroy(&dev->lock); 1855 mutex_destroy(&dev->lock);
1867 usb_put_dev(dev->udev); 1856 usb_put_dev(dev->udev);
1857 v4l2_device_unregister(&dev->v4l2_dev);
1868 dprintk(1, "%s", __func__); 1858 dprintk(1, "%s", __func__);
1869 kfree(dev); 1859 kfree(dev);
1870} 1860}
@@ -1874,14 +1864,15 @@ static int s2255_release(struct file *file)
1874 struct s2255_fh *fh = file->private_data; 1864 struct s2255_fh *fh = file->private_data;
1875 struct s2255_dev *dev = fh->dev; 1865 struct s2255_dev *dev = fh->dev;
1876 struct video_device *vdev = video_devdata(file); 1866 struct video_device *vdev = video_devdata(file);
1867 struct s2255_channel *channel = fh->channel;
1877 if (!dev) 1868 if (!dev)
1878 return -ENODEV; 1869 return -ENODEV;
1879 /* turn off stream */ 1870 /* turn off stream */
1880 if (res_check(fh)) { 1871 if (res_check(fh)) {
1881 if (dev->b_acquire[fh->channel]) 1872 if (channel->b_acquire)
1882 s2255_stop_acquire(dev, fh->channel); 1873 s2255_stop_acquire(fh->channel);
1883 videobuf_streamoff(&fh->vb_vidq); 1874 videobuf_streamoff(&fh->vb_vidq);
1884 res_free(dev, fh); 1875 res_free(fh);
1885 } 1876 }
1886 videobuf_mmap_free(&fh->vb_vidq); 1877 videobuf_mmap_free(&fh->vb_vidq);
1887 dprintk(1, "%s (dev=%s)\n", __func__, video_device_node_name(vdev)); 1878 dprintk(1, "%s (dev=%s)\n", __func__, video_device_node_name(vdev));
@@ -1945,9 +1936,10 @@ static const struct v4l2_ioctl_ops s2255_ioctl_ops = {
1945 1936
1946static void s2255_video_device_release(struct video_device *vdev) 1937static void s2255_video_device_release(struct video_device *vdev)
1947{ 1938{
1948 struct s2255_dev *dev = video_get_drvdata(vdev); 1939 struct s2255_dev *dev = to_s2255_dev(vdev->v4l2_dev);
1949 dprintk(4, "%s, chnls: %d \n", __func__, atomic_read(&dev->channels)); 1940 dprintk(4, "%s, chnls: %d \n", __func__,
1950 if (atomic_dec_and_test(&dev->channels)) 1941 atomic_read(&dev->num_channels));
1942 if (atomic_dec_and_test(&dev->num_channels))
1951 s2255_destroy(dev); 1943 s2255_destroy(dev);
1952 return; 1944 return;
1953} 1945}
@@ -1966,47 +1958,48 @@ static int s2255_probe_v4l(struct s2255_dev *dev)
1966 int ret; 1958 int ret;
1967 int i; 1959 int i;
1968 int cur_nr = video_nr; 1960 int cur_nr = video_nr;
1961 struct s2255_channel *channel;
1969 ret = v4l2_device_register(&dev->interface->dev, &dev->v4l2_dev); 1962 ret = v4l2_device_register(&dev->interface->dev, &dev->v4l2_dev);
1970 if (ret) 1963 if (ret)
1971 return ret; 1964 return ret;
1972 /* initialize all video 4 linux */ 1965 /* initialize all video 4 linux */
1973 /* register 4 video devices */ 1966 /* register 4 video devices */
1974 for (i = 0; i < MAX_CHANNELS; i++) { 1967 for (i = 0; i < MAX_CHANNELS; i++) {
1975 INIT_LIST_HEAD(&dev->vidq[i].active); 1968 channel = &dev->channel[i];
1976 dev->vidq[i].dev = dev; 1969 INIT_LIST_HEAD(&channel->vidq.active);
1977 dev->vidq[i].channel = i; 1970 channel->vidq.dev = dev;
1978 /* register 4 video devices */ 1971 /* register 4 video devices */
1979 memcpy(&dev->vdev[i], &template, sizeof(struct video_device)); 1972 channel->vdev = template;
1980 dev->vdev[i].v4l2_dev = &dev->v4l2_dev; 1973 channel->vdev.v4l2_dev = &dev->v4l2_dev;
1981 video_set_drvdata(&dev->vdev[i], dev); 1974 video_set_drvdata(&channel->vdev, channel);
1982 if (video_nr == -1) 1975 if (video_nr == -1)
1983 ret = video_register_device(&dev->vdev[i], 1976 ret = video_register_device(&channel->vdev,
1984 VFL_TYPE_GRABBER, 1977 VFL_TYPE_GRABBER,
1985 video_nr); 1978 video_nr);
1986 else 1979 else
1987 ret = video_register_device(&dev->vdev[i], 1980 ret = video_register_device(&channel->vdev,
1988 VFL_TYPE_GRABBER, 1981 VFL_TYPE_GRABBER,
1989 cur_nr + i); 1982 cur_nr + i);
1983
1990 if (ret) { 1984 if (ret) {
1991 dev_err(&dev->udev->dev, 1985 dev_err(&dev->udev->dev,
1992 "failed to register video device!\n"); 1986 "failed to register video device!\n");
1993 break; 1987 break;
1994 } 1988 }
1995 atomic_inc(&dev->channels); 1989 atomic_inc(&dev->num_channels);
1996 v4l2_info(&dev->v4l2_dev, "V4L2 device registered as %s\n", 1990 v4l2_info(&dev->v4l2_dev, "V4L2 device registered as %s\n",
1997 video_device_node_name(&dev->vdev[i])); 1991 video_device_node_name(&channel->vdev));
1998 1992
1999 } 1993 }
2000
2001 printk(KERN_INFO "Sensoray 2255 V4L driver Revision: %d.%d\n", 1994 printk(KERN_INFO "Sensoray 2255 V4L driver Revision: %d.%d\n",
2002 S2255_MAJOR_VERSION, 1995 S2255_MAJOR_VERSION,
2003 S2255_MINOR_VERSION); 1996 S2255_MINOR_VERSION);
2004 /* if no channels registered, return error and probe will fail*/ 1997 /* if no channels registered, return error and probe will fail*/
2005 if (atomic_read(&dev->channels) == 0) { 1998 if (atomic_read(&dev->num_channels) == 0) {
2006 v4l2_device_unregister(&dev->v4l2_dev); 1999 v4l2_device_unregister(&dev->v4l2_dev);
2007 return ret; 2000 return ret;
2008 } 2001 }
2009 if (atomic_read(&dev->channels) != MAX_CHANNELS) 2002 if (atomic_read(&dev->num_channels) != MAX_CHANNELS)
2010 printk(KERN_WARNING "s2255: Not all channels available.\n"); 2003 printk(KERN_WARNING "s2255: Not all channels available.\n");
2011 return 0; 2004 return 0;
2012} 2005}
@@ -2033,12 +2026,11 @@ static int save_frame(struct s2255_dev *dev, struct s2255_pipeinfo *pipe_info)
2033 s32 idx = -1; 2026 s32 idx = -1;
2034 struct s2255_framei *frm; 2027 struct s2255_framei *frm;
2035 unsigned char *pdata; 2028 unsigned char *pdata;
2036 2029 struct s2255_channel *channel;
2037 dprintk(100, "buffer to user\n"); 2030 dprintk(100, "buffer to user\n");
2038 2031 channel = &dev->channel[dev->cc];
2039 idx = dev->cur_frame[dev->cc]; 2032 idx = channel->cur_frame;
2040 frm = &dev->buffer[dev->cc].frame[idx]; 2033 frm = &channel->buffer.frame[idx];
2041
2042 if (frm->ulState == S2255_READ_IDLE) { 2034 if (frm->ulState == S2255_READ_IDLE) {
2043 int jj; 2035 int jj;
2044 unsigned int cc; 2036 unsigned int cc;
@@ -2063,16 +2055,18 @@ static int save_frame(struct s2255_dev *dev, struct s2255_pipeinfo *pipe_info)
2063 } 2055 }
2064 /* reverse it */ 2056 /* reverse it */
2065 dev->cc = G_chnmap[cc]; 2057 dev->cc = G_chnmap[cc];
2058 channel = &dev->channel[dev->cc];
2066 payload = pdword[3]; 2059 payload = pdword[3];
2067 if (payload > dev->req_image_size[dev->cc]) { 2060 if (payload > channel->req_image_size) {
2068 dev->bad_payload[dev->cc]++; 2061 channel->bad_payload++;
2069 /* discard the bad frame */ 2062 /* discard the bad frame */
2070 return -EINVAL; 2063 return -EINVAL;
2071 } 2064 }
2072 dev->pkt_size[dev->cc] = payload; 2065 channel->pkt_size = payload;
2073 dev->jpg_size[dev->cc] = pdword[4]; 2066 channel->jpg_size = pdword[4];
2074 break; 2067 break;
2075 case S2255_MARKER_RESPONSE: 2068 case S2255_MARKER_RESPONSE:
2069
2076 pdata += DEF_USB_BLOCK; 2070 pdata += DEF_USB_BLOCK;
2077 jj += DEF_USB_BLOCK; 2071 jj += DEF_USB_BLOCK;
2078 if (pdword[1] >= MAX_CHANNELS) 2072 if (pdword[1] >= MAX_CHANNELS)
@@ -2080,12 +2074,13 @@ static int save_frame(struct s2255_dev *dev, struct s2255_pipeinfo *pipe_info)
2080 cc = G_chnmap[pdword[1]]; 2074 cc = G_chnmap[pdword[1]];
2081 if (cc >= MAX_CHANNELS) 2075 if (cc >= MAX_CHANNELS)
2082 break; 2076 break;
2077 channel = &dev->channel[cc];
2083 switch (pdword[2]) { 2078 switch (pdword[2]) {
2084 case S2255_RESPONSE_SETMODE: 2079 case S2255_RESPONSE_SETMODE:
2085 /* check if channel valid */ 2080 /* check if channel valid */
2086 /* set mode ready */ 2081 /* set mode ready */
2087 dev->setmode_ready[cc] = 1; 2082 channel->setmode_ready = 1;
2088 wake_up(&dev->wait_setmode[cc]); 2083 wake_up(&channel->wait_setmode);
2089 dprintk(5, "setmode ready %d\n", cc); 2084 dprintk(5, "setmode ready %d\n", cc);
2090 break; 2085 break;
2091 case S2255_RESPONSE_FW: 2086 case S2255_RESPONSE_FW:
@@ -2099,9 +2094,9 @@ static int save_frame(struct s2255_dev *dev, struct s2255_pipeinfo *pipe_info)
2099 wake_up(&dev->fw_data->wait_fw); 2094 wake_up(&dev->fw_data->wait_fw);
2100 break; 2095 break;
2101 case S2255_RESPONSE_STATUS: 2096 case S2255_RESPONSE_STATUS:
2102 dev->vidstatus[cc] = pdword[3]; 2097 channel->vidstatus = pdword[3];
2103 dev->vidstatus_ready[cc] = 1; 2098 channel->vidstatus_ready = 1;
2104 wake_up(&dev->wait_vidstatus[cc]); 2099 wake_up(&channel->wait_vidstatus);
2105 dprintk(5, "got vidstatus %x chan %d\n", 2100 dprintk(5, "got vidstatus %x chan %d\n",
2106 pdword[3], cc); 2101 pdword[3], cc);
2107 break; 2102 break;
@@ -2118,13 +2113,11 @@ static int save_frame(struct s2255_dev *dev, struct s2255_pipeinfo *pipe_info)
2118 if (!bframe) 2113 if (!bframe)
2119 return -EINVAL; 2114 return -EINVAL;
2120 } 2115 }
2121 2116 channel = &dev->channel[dev->cc];
2122 2117 idx = channel->cur_frame;
2123 idx = dev->cur_frame[dev->cc]; 2118 frm = &channel->buffer.frame[idx];
2124 frm = &dev->buffer[dev->cc].frame[idx];
2125
2126 /* search done. now find out if should be acquiring on this channel */ 2119 /* search done. now find out if should be acquiring on this channel */
2127 if (!dev->b_acquire[dev->cc]) { 2120 if (!channel->b_acquire) {
2128 /* we found a frame, but this channel is turned off */ 2121 /* we found a frame, but this channel is turned off */
2129 frm->ulState = S2255_READ_IDLE; 2122 frm->ulState = S2255_READ_IDLE;
2130 return -EINVAL; 2123 return -EINVAL;
@@ -2149,30 +2142,28 @@ static int save_frame(struct s2255_dev *dev, struct s2255_pipeinfo *pipe_info)
2149 2142
2150 copy_size = (pipe_info->cur_transfer_size - offset); 2143 copy_size = (pipe_info->cur_transfer_size - offset);
2151 2144
2152 size = dev->pkt_size[dev->cc] - PREFIX_SIZE; 2145 size = channel->pkt_size - PREFIX_SIZE;
2153 2146
2154 /* sanity check on pdest */ 2147 /* sanity check on pdest */
2155 if ((copy_size + frm->cur_size) < dev->req_image_size[dev->cc]) 2148 if ((copy_size + frm->cur_size) < channel->req_image_size)
2156 memcpy(pdest, psrc, copy_size); 2149 memcpy(pdest, psrc, copy_size);
2157 2150
2158 frm->cur_size += copy_size; 2151 frm->cur_size += copy_size;
2159 dprintk(4, "cur_size size %lu size %lu \n", frm->cur_size, size); 2152 dprintk(4, "cur_size size %lu size %lu \n", frm->cur_size, size);
2160 2153
2161 if (frm->cur_size >= size) { 2154 if (frm->cur_size >= size) {
2162
2163 u32 cc = dev->cc;
2164 dprintk(2, "****************[%d]Buffer[%d]full*************\n", 2155 dprintk(2, "****************[%d]Buffer[%d]full*************\n",
2165 cc, idx); 2156 dev->cc, idx);
2166 dev->last_frame[cc] = dev->cur_frame[cc]; 2157 channel->last_frame = channel->cur_frame;
2167 dev->cur_frame[cc]++; 2158 channel->cur_frame++;
2168 /* end of system frame ring buffer, start at zero */ 2159 /* end of system frame ring buffer, start at zero */
2169 if ((dev->cur_frame[cc] == SYS_FRAMES) || 2160 if ((channel->cur_frame == SYS_FRAMES) ||
2170 (dev->cur_frame[cc] == dev->buffer[cc].dwFrames)) 2161 (channel->cur_frame == channel->buffer.dwFrames))
2171 dev->cur_frame[cc] = 0; 2162 channel->cur_frame = 0;
2172 /* frame ready */ 2163 /* frame ready */
2173 if (dev->b_acquire[cc]) 2164 if (channel->b_acquire)
2174 s2255_got_frame(dev, cc, dev->jpg_size[cc]); 2165 s2255_got_frame(channel, channel->jpg_size);
2175 dev->frame_count[cc]++; 2166 channel->frame_count++;
2176 frm->ulState = S2255_READ_IDLE; 2167 frm->ulState = S2255_READ_IDLE;
2177 frm->cur_size = 0; 2168 frm->cur_size = 0;
2178 2169
@@ -2245,16 +2236,12 @@ static int s2255_get_fx2fw(struct s2255_dev *dev)
2245 * Create the system ring buffer to copy frames into from the 2236 * Create the system ring buffer to copy frames into from the
2246 * usb read pipe. 2237 * usb read pipe.
2247 */ 2238 */
2248static int s2255_create_sys_buffers(struct s2255_dev *dev, unsigned long chn) 2239static int s2255_create_sys_buffers(struct s2255_channel *channel)
2249{ 2240{
2250 unsigned long i; 2241 unsigned long i;
2251 unsigned long reqsize; 2242 unsigned long reqsize;
2252 dprintk(1, "create sys buffers\n"); 2243 dprintk(1, "create sys buffers\n");
2253 if (chn >= MAX_CHANNELS) 2244 channel->buffer.dwFrames = SYS_FRAMES;
2254 return -1;
2255
2256 dev->buffer[chn].dwFrames = SYS_FRAMES;
2257
2258 /* always allocate maximum size(PAL) for system buffers */ 2245 /* always allocate maximum size(PAL) for system buffers */
2259 reqsize = SYS_FRAMES_MAXSIZE; 2246 reqsize = SYS_FRAMES_MAXSIZE;
2260 2247
@@ -2263,42 +2250,40 @@ static int s2255_create_sys_buffers(struct s2255_dev *dev, unsigned long chn)
2263 2250
2264 for (i = 0; i < SYS_FRAMES; i++) { 2251 for (i = 0; i < SYS_FRAMES; i++) {
2265 /* allocate the frames */ 2252 /* allocate the frames */
2266 dev->buffer[chn].frame[i].lpvbits = vmalloc(reqsize); 2253 channel->buffer.frame[i].lpvbits = vmalloc(reqsize);
2267 2254 dprintk(1, "valloc %p chan %d, idx %lu, pdata %p\n",
2268 dprintk(1, "valloc %p chan %lu, idx %lu, pdata %p\n", 2255 &channel->buffer.frame[i], channel->idx, i,
2269 &dev->buffer[chn].frame[i], chn, i, 2256 channel->buffer.frame[i].lpvbits);
2270 dev->buffer[chn].frame[i].lpvbits); 2257 channel->buffer.frame[i].size = reqsize;
2271 dev->buffer[chn].frame[i].size = reqsize; 2258 if (channel->buffer.frame[i].lpvbits == NULL) {
2272 if (dev->buffer[chn].frame[i].lpvbits == NULL) {
2273 printk(KERN_INFO "out of memory. using less frames\n"); 2259 printk(KERN_INFO "out of memory. using less frames\n");
2274 dev->buffer[chn].dwFrames = i; 2260 channel->buffer.dwFrames = i;
2275 break; 2261 break;
2276 } 2262 }
2277 } 2263 }
2278 2264
2279 /* make sure internal states are set */ 2265 /* make sure internal states are set */
2280 for (i = 0; i < SYS_FRAMES; i++) { 2266 for (i = 0; i < SYS_FRAMES; i++) {
2281 dev->buffer[chn].frame[i].ulState = 0; 2267 channel->buffer.frame[i].ulState = 0;
2282 dev->buffer[chn].frame[i].cur_size = 0; 2268 channel->buffer.frame[i].cur_size = 0;
2283 } 2269 }
2284 2270
2285 dev->cur_frame[chn] = 0; 2271 channel->cur_frame = 0;
2286 dev->last_frame[chn] = -1; 2272 channel->last_frame = -1;
2287 return 0; 2273 return 0;
2288} 2274}
2289 2275
2290static int s2255_release_sys_buffers(struct s2255_dev *dev, 2276static int s2255_release_sys_buffers(struct s2255_channel *channel)
2291 unsigned long channel)
2292{ 2277{
2293 unsigned long i; 2278 unsigned long i;
2294 dprintk(1, "release sys buffers\n"); 2279 dprintk(1, "release sys buffers\n");
2295 for (i = 0; i < SYS_FRAMES; i++) { 2280 for (i = 0; i < SYS_FRAMES; i++) {
2296 if (dev->buffer[channel].frame[i].lpvbits) { 2281 if (channel->buffer.frame[i].lpvbits) {
2297 dprintk(1, "vfree %p\n", 2282 dprintk(1, "vfree %p\n",
2298 dev->buffer[channel].frame[i].lpvbits); 2283 channel->buffer.frame[i].lpvbits);
2299 vfree(dev->buffer[channel].frame[i].lpvbits); 2284 vfree(channel->buffer.frame[i].lpvbits);
2300 } 2285 }
2301 dev->buffer[channel].frame[i].lpvbits = NULL; 2286 channel->buffer.frame[i].lpvbits = NULL;
2302 } 2287 }
2303 return 0; 2288 return 0;
2304} 2289}
@@ -2335,17 +2320,20 @@ static int s2255_board_init(struct s2255_dev *dev)
2335 fw_ver & 0xff); 2320 fw_ver & 0xff);
2336 2321
2337 for (j = 0; j < MAX_CHANNELS; j++) { 2322 for (j = 0; j < MAX_CHANNELS; j++) {
2338 dev->b_acquire[j] = 0; 2323 struct s2255_channel *channel = &dev->channel[j];
2339 dev->mode[j] = mode_def; 2324 channel->b_acquire = 0;
2325 channel->mode = mode_def;
2340 if (dev->pid == 0x2257 && j > 1) 2326 if (dev->pid == 0x2257 && j > 1)
2341 dev->mode[j].color |= (1 << 16); 2327 channel->mode.color |= (1 << 16);
2342 dev->jc[j].quality = S2255_DEF_JPEG_QUAL; 2328 channel->jc.quality = S2255_DEF_JPEG_QUAL;
2343 dev->cur_fmt[j] = &formats[0]; 2329 channel->width = LINE_SZ_4CIFS_NTSC;
2344 dev->mode[j].restart = 1; 2330 channel->height = NUM_LINES_4CIFS_NTSC * 2;
2345 dev->req_image_size[j] = get_transfer_size(&mode_def); 2331 channel->fmt = &formats[0];
2346 dev->frame_count[j] = 0; 2332 channel->mode.restart = 1;
2333 channel->req_image_size = get_transfer_size(&mode_def);
2334 channel->frame_count = 0;
2347 /* create the system buffers */ 2335 /* create the system buffers */
2348 s2255_create_sys_buffers(dev, j); 2336 s2255_create_sys_buffers(channel);
2349 } 2337 }
2350 /* start read pipe */ 2338 /* start read pipe */
2351 s2255_start_readpipe(dev); 2339 s2255_start_readpipe(dev);
@@ -2359,14 +2347,12 @@ static int s2255_board_shutdown(struct s2255_dev *dev)
2359 dprintk(1, "%s: dev: %p", __func__, dev); 2347 dprintk(1, "%s: dev: %p", __func__, dev);
2360 2348
2361 for (i = 0; i < MAX_CHANNELS; i++) { 2349 for (i = 0; i < MAX_CHANNELS; i++) {
2362 if (dev->b_acquire[i]) 2350 if (dev->channel[i].b_acquire)
2363 s2255_stop_acquire(dev, i); 2351 s2255_stop_acquire(&dev->channel[i]);
2364 } 2352 }
2365
2366 s2255_stop_readpipe(dev); 2353 s2255_stop_readpipe(dev);
2367
2368 for (i = 0; i < MAX_CHANNELS; i++) 2354 for (i = 0; i < MAX_CHANNELS; i++)
2369 s2255_release_sys_buffers(dev, i); 2355 s2255_release_sys_buffers(&dev->channel[i]);
2370 /* release transfer buffer */ 2356 /* release transfer buffer */
2371 kfree(dev->pipe.transfer_buffer); 2357 kfree(dev->pipe.transfer_buffer);
2372 return 0; 2358 return 0;
@@ -2459,29 +2445,26 @@ static int s2255_start_readpipe(struct s2255_dev *dev)
2459} 2445}
2460 2446
2461/* starts acquisition process */ 2447/* starts acquisition process */
2462static int s2255_start_acquire(struct s2255_dev *dev, unsigned long chn) 2448static int s2255_start_acquire(struct s2255_channel *channel)
2463{ 2449{
2464 unsigned char *buffer; 2450 unsigned char *buffer;
2465 int res; 2451 int res;
2466 unsigned long chn_rev; 2452 unsigned long chn_rev;
2467 int j; 2453 int j;
2468 if (chn >= MAX_CHANNELS) { 2454 struct s2255_dev *dev = to_s2255_dev(channel->vdev.v4l2_dev);
2469 dprintk(2, "start acquire failed, bad channel %lu\n", chn); 2455 chn_rev = G_chnmap[channel->idx];
2470 return -1;
2471 }
2472 chn_rev = G_chnmap[chn];
2473 buffer = kzalloc(512, GFP_KERNEL); 2456 buffer = kzalloc(512, GFP_KERNEL);
2474 if (buffer == NULL) { 2457 if (buffer == NULL) {
2475 dev_err(&dev->udev->dev, "out of mem\n"); 2458 dev_err(&dev->udev->dev, "out of mem\n");
2476 return -ENOMEM; 2459 return -ENOMEM;
2477 } 2460 }
2478 2461
2479 dev->last_frame[chn] = -1; 2462 channel->last_frame = -1;
2480 dev->bad_payload[chn] = 0; 2463 channel->bad_payload = 0;
2481 dev->cur_frame[chn] = 0; 2464 channel->cur_frame = 0;
2482 for (j = 0; j < SYS_FRAMES; j++) { 2465 for (j = 0; j < SYS_FRAMES; j++) {
2483 dev->buffer[chn].frame[j].ulState = 0; 2466 channel->buffer.frame[j].ulState = 0;
2484 dev->buffer[chn].frame[j].cur_size = 0; 2467 channel->buffer.frame[j].cur_size = 0;
2485 } 2468 }
2486 2469
2487 /* send the start command */ 2470 /* send the start command */
@@ -2492,21 +2475,18 @@ static int s2255_start_acquire(struct s2255_dev *dev, unsigned long chn)
2492 if (res != 0) 2475 if (res != 0)
2493 dev_err(&dev->udev->dev, "CMD_START error\n"); 2476 dev_err(&dev->udev->dev, "CMD_START error\n");
2494 2477
2495 dprintk(2, "start acquire exit[%lu] %d \n", chn, res); 2478 dprintk(2, "start acquire exit[%d] %d \n", channel->idx, res);
2496 kfree(buffer); 2479 kfree(buffer);
2497 return 0; 2480 return 0;
2498} 2481}
2499 2482
2500static int s2255_stop_acquire(struct s2255_dev *dev, unsigned long chn) 2483static int s2255_stop_acquire(struct s2255_channel *channel)
2501{ 2484{
2502 unsigned char *buffer; 2485 unsigned char *buffer;
2503 int res; 2486 int res;
2504 unsigned long chn_rev; 2487 unsigned long chn_rev;
2505 if (chn >= MAX_CHANNELS) { 2488 struct s2255_dev *dev = to_s2255_dev(channel->vdev.v4l2_dev);
2506 dprintk(2, "stop acquire failed, bad channel %lu\n", chn); 2489 chn_rev = G_chnmap[channel->idx];
2507 return -1;
2508 }
2509 chn_rev = G_chnmap[chn];
2510 buffer = kzalloc(512, GFP_KERNEL); 2490 buffer = kzalloc(512, GFP_KERNEL);
2511 if (buffer == NULL) { 2491 if (buffer == NULL) {
2512 dev_err(&dev->udev->dev, "out of mem\n"); 2492 dev_err(&dev->udev->dev, "out of mem\n");
@@ -2520,8 +2500,8 @@ static int s2255_stop_acquire(struct s2255_dev *dev, unsigned long chn)
2520 if (res != 0) 2500 if (res != 0)
2521 dev_err(&dev->udev->dev, "CMD_STOP error\n"); 2501 dev_err(&dev->udev->dev, "CMD_STOP error\n");
2522 kfree(buffer); 2502 kfree(buffer);
2523 dev->b_acquire[chn] = 0; 2503 channel->b_acquire = 0;
2524 dprintk(4, "%s: chn %lu, res %d\n", __func__, chn, res); 2504 dprintk(4, "%s: chn %d, res %d\n", __func__, channel->idx, res);
2525 return res; 2505 return res;
2526} 2506}
2527 2507
@@ -2575,7 +2555,7 @@ static int s2255_probe(struct usb_interface *interface,
2575 s2255_dev_err(&interface->dev, "out of memory\n"); 2555 s2255_dev_err(&interface->dev, "out of memory\n");
2576 return -ENOMEM; 2556 return -ENOMEM;
2577 } 2557 }
2578 atomic_set(&dev->channels, 0); 2558 atomic_set(&dev->num_channels, 0);
2579 dev->pid = id->idProduct; 2559 dev->pid = id->idProduct;
2580 dev->fw_data = kzalloc(sizeof(struct s2255_fw), GFP_KERNEL); 2560 dev->fw_data = kzalloc(sizeof(struct s2255_fw), GFP_KERNEL);
2581 if (!dev->fw_data) 2561 if (!dev->fw_data)
@@ -2612,8 +2592,10 @@ static int s2255_probe(struct usb_interface *interface,
2612 dev->timer.data = (unsigned long)dev->fw_data; 2592 dev->timer.data = (unsigned long)dev->fw_data;
2613 init_waitqueue_head(&dev->fw_data->wait_fw); 2593 init_waitqueue_head(&dev->fw_data->wait_fw);
2614 for (i = 0; i < MAX_CHANNELS; i++) { 2594 for (i = 0; i < MAX_CHANNELS; i++) {
2615 init_waitqueue_head(&dev->wait_setmode[i]); 2595 struct s2255_channel *channel = &dev->channel[i];
2616 init_waitqueue_head(&dev->wait_vidstatus[i]); 2596 dev->channel[i].idx = i;
2597 init_waitqueue_head(&channel->wait_setmode);
2598 init_waitqueue_head(&channel->wait_vidstatus);
2617 } 2599 }
2618 2600
2619 dev->fw_data->fw_urb = usb_alloc_urb(0, GFP_KERNEL); 2601 dev->fw_data->fw_urb = usb_alloc_urb(0, GFP_KERNEL);
@@ -2651,7 +2633,7 @@ static int s2255_probe(struct usb_interface *interface,
2651 printk(KERN_INFO "s2255: f2255usb.bin out of date.\n"); 2633 printk(KERN_INFO "s2255: f2255usb.bin out of date.\n");
2652 if (dev->pid == 0x2257 && *pRel < S2255_MIN_DSP_COLORFILTER) 2634 if (dev->pid == 0x2257 && *pRel < S2255_MIN_DSP_COLORFILTER)
2653 printk(KERN_WARNING "s2255: 2257 requires firmware %d" 2635 printk(KERN_WARNING "s2255: 2257 requires firmware %d"
2654 "or above.\n", S2255_MIN_DSP_COLORFILTER); 2636 " or above.\n", S2255_MIN_DSP_COLORFILTER);
2655 } 2637 }
2656 usb_reset_device(dev->udev); 2638 usb_reset_device(dev->udev);
2657 /* load 2255 board specific */ 2639 /* load 2255 board specific */
@@ -2693,25 +2675,23 @@ static void s2255_disconnect(struct usb_interface *interface)
2693{ 2675{
2694 struct s2255_dev *dev = to_s2255_dev(usb_get_intfdata(interface)); 2676 struct s2255_dev *dev = to_s2255_dev(usb_get_intfdata(interface));
2695 int i; 2677 int i;
2696 int channels = atomic_read(&dev->channels); 2678 int channels = atomic_read(&dev->num_channels);
2697 v4l2_device_unregister(&dev->v4l2_dev); 2679 v4l2_device_disconnect(&dev->v4l2_dev);
2698 /*see comments in the uvc_driver.c usb disconnect function */ 2680 /*see comments in the uvc_driver.c usb disconnect function */
2699 atomic_inc(&dev->channels); 2681 atomic_inc(&dev->num_channels);
2700 /* unregister each video device. */ 2682 /* unregister each video device. */
2701 for (i = 0; i < channels; i++) { 2683 for (i = 0; i < channels; i++)
2702 if (video_is_registered(&dev->vdev[i])) 2684 video_unregister_device(&dev->channel[i].vdev);
2703 video_unregister_device(&dev->vdev[i]);
2704 }
2705 /* wake up any of our timers */ 2685 /* wake up any of our timers */
2706 atomic_set(&dev->fw_data->fw_state, S2255_FW_DISCONNECTING); 2686 atomic_set(&dev->fw_data->fw_state, S2255_FW_DISCONNECTING);
2707 wake_up(&dev->fw_data->wait_fw); 2687 wake_up(&dev->fw_data->wait_fw);
2708 for (i = 0; i < MAX_CHANNELS; i++) { 2688 for (i = 0; i < MAX_CHANNELS; i++) {
2709 dev->setmode_ready[i] = 1; 2689 dev->channel[i].setmode_ready = 1;
2710 wake_up(&dev->wait_setmode[i]); 2690 wake_up(&dev->channel[i].wait_setmode);
2711 dev->vidstatus_ready[i] = 1; 2691 dev->channel[i].vidstatus_ready = 1;
2712 wake_up(&dev->wait_vidstatus[i]); 2692 wake_up(&dev->channel[i].wait_vidstatus);
2713 } 2693 }
2714 if (atomic_dec_and_test(&dev->channels)) 2694 if (atomic_dec_and_test(&dev->num_channels))
2715 s2255_destroy(dev); 2695 s2255_destroy(dev);
2716 dev_info(&interface->dev, "%s\n", __func__); 2696 dev_info(&interface->dev, "%s\n", __func__);
2717} 2697}
diff --git a/drivers/media/video/saa7134/saa7134-alsa.c b/drivers/media/video/saa7134/saa7134-alsa.c
index d3bd82ad010a..10460fd3ce39 100644
--- a/drivers/media/video/saa7134/saa7134-alsa.c
+++ b/drivers/media/video/saa7134/saa7134-alsa.c
@@ -630,7 +630,7 @@ static int snd_card_saa7134_hw_params(struct snd_pcm_substream * substream,
630 /* release the old buffer */ 630 /* release the old buffer */
631 if (substream->runtime->dma_area) { 631 if (substream->runtime->dma_area) {
632 saa7134_pgtable_free(dev->pci, &dev->dmasound.pt); 632 saa7134_pgtable_free(dev->pci, &dev->dmasound.pt);
633 videobuf_sg_dma_unmap(&dev->pci->dev, &dev->dmasound.dma); 633 videobuf_dma_unmap(&dev->pci->dev, &dev->dmasound.dma);
634 dsp_buffer_free(dev); 634 dsp_buffer_free(dev);
635 substream->runtime->dma_area = NULL; 635 substream->runtime->dma_area = NULL;
636 } 636 }
@@ -646,12 +646,12 @@ static int snd_card_saa7134_hw_params(struct snd_pcm_substream * substream,
646 return err; 646 return err;
647 } 647 }
648 648
649 if (0 != (err = videobuf_sg_dma_map(&dev->pci->dev, &dev->dmasound.dma))) { 649 if (0 != (err = videobuf_dma_map(&dev->pci->dev, &dev->dmasound.dma))) {
650 dsp_buffer_free(dev); 650 dsp_buffer_free(dev);
651 return err; 651 return err;
652 } 652 }
653 if (0 != (err = saa7134_pgtable_alloc(dev->pci,&dev->dmasound.pt))) { 653 if (0 != (err = saa7134_pgtable_alloc(dev->pci,&dev->dmasound.pt))) {
654 videobuf_sg_dma_unmap(&dev->pci->dev, &dev->dmasound.dma); 654 videobuf_dma_unmap(&dev->pci->dev, &dev->dmasound.dma);
655 dsp_buffer_free(dev); 655 dsp_buffer_free(dev);
656 return err; 656 return err;
657 } 657 }
@@ -660,7 +660,7 @@ static int snd_card_saa7134_hw_params(struct snd_pcm_substream * substream,
660 dev->dmasound.dma.sglen, 660 dev->dmasound.dma.sglen,
661 0))) { 661 0))) {
662 saa7134_pgtable_free(dev->pci, &dev->dmasound.pt); 662 saa7134_pgtable_free(dev->pci, &dev->dmasound.pt);
663 videobuf_sg_dma_unmap(&dev->pci->dev, &dev->dmasound.dma); 663 videobuf_dma_unmap(&dev->pci->dev, &dev->dmasound.dma);
664 dsp_buffer_free(dev); 664 dsp_buffer_free(dev);
665 return err; 665 return err;
666 } 666 }
@@ -669,7 +669,7 @@ static int snd_card_saa7134_hw_params(struct snd_pcm_substream * substream,
669 byte, but it doesn't work. So I allocate the DMA using the 669 byte, but it doesn't work. So I allocate the DMA using the
670 V4L functions, and force ALSA to use that as the DMA area */ 670 V4L functions, and force ALSA to use that as the DMA area */
671 671
672 substream->runtime->dma_area = dev->dmasound.dma.vmalloc; 672 substream->runtime->dma_area = dev->dmasound.dma.vaddr;
673 substream->runtime->dma_bytes = dev->dmasound.bufsize; 673 substream->runtime->dma_bytes = dev->dmasound.bufsize;
674 substream->runtime->dma_addr = 0; 674 substream->runtime->dma_addr = 0;
675 675
@@ -696,7 +696,7 @@ static int snd_card_saa7134_hw_free(struct snd_pcm_substream * substream)
696 696
697 if (substream->runtime->dma_area) { 697 if (substream->runtime->dma_area) {
698 saa7134_pgtable_free(dev->pci, &dev->dmasound.pt); 698 saa7134_pgtable_free(dev->pci, &dev->dmasound.pt);
699 videobuf_sg_dma_unmap(&dev->pci->dev, &dev->dmasound.dma); 699 videobuf_dma_unmap(&dev->pci->dev, &dev->dmasound.dma);
700 dsp_buffer_free(dev); 700 dsp_buffer_free(dev);
701 substream->runtime->dma_area = NULL; 701 substream->runtime->dma_area = NULL;
702 } 702 }
@@ -1080,7 +1080,7 @@ static int alsa_card_saa7134_create(struct saa7134_dev *dev, int devnum)
1080 /* Card "creation" */ 1080 /* Card "creation" */
1081 1081
1082 card->private_free = snd_saa7134_free; 1082 card->private_free = snd_saa7134_free;
1083 chip = (snd_card_saa7134_t *) card->private_data; 1083 chip = card->private_data;
1084 1084
1085 spin_lock_init(&chip->lock); 1085 spin_lock_init(&chip->lock);
1086 spin_lock_init(&chip->mixer_lock); 1086 spin_lock_init(&chip->mixer_lock);
diff --git a/drivers/media/video/saa7134/saa7134-cards.c b/drivers/media/video/saa7134/saa7134-cards.c
index 07f6bb8ef9d9..ec697fcd406e 100644
--- a/drivers/media/video/saa7134/saa7134-cards.c
+++ b/drivers/media/video/saa7134/saa7134-cards.c
@@ -5462,6 +5462,30 @@ struct saa7134_board saa7134_boards[] = {
5462 .amux = TV, 5462 .amux = TV,
5463 }, 5463 },
5464 }, 5464 },
5465 [SAA7134_BOARD_TECHNOTREND_BUDGET_T3000] = {
5466 .name = "TechoTrend TT-budget T-3000",
5467 .tuner_type = TUNER_PHILIPS_TD1316,
5468 .audio_clock = 0x00187de7,
5469 .radio_type = UNSET,
5470 .tuner_addr = 0x63,
5471 .radio_addr = ADDR_UNSET,
5472 .tda9887_conf = TDA9887_PRESENT | TDA9887_PORT1_ACTIVE,
5473 .mpeg = SAA7134_MPEG_DVB,
5474 .inputs = {{
5475 .name = name_tv,
5476 .vmux = 3,
5477 .amux = TV,
5478 .tv = 1,
5479 }, {
5480 .name = name_comp1,
5481 .vmux = 0,
5482 .amux = LINE2,
5483 }, {
5484 .name = name_svideo,
5485 .vmux = 8,
5486 .amux = LINE2,
5487 } },
5488 },
5465 5489
5466}; 5490};
5467 5491
@@ -6631,6 +6655,12 @@ struct pci_device_id saa7134_pci_tbl[] = {
6631 .subdevice = 0x6655, 6655 .subdevice = 0x6655,
6632 .driver_data = SAA7134_BOARD_LEADTEK_WINFAST_DTV1000S, 6656 .driver_data = SAA7134_BOARD_LEADTEK_WINFAST_DTV1000S,
6633 }, { 6657 }, {
6658 .vendor = PCI_VENDOR_ID_PHILIPS,
6659 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
6660 .subvendor = 0x13c2,
6661 .subdevice = 0x2804,
6662 .driver_data = SAA7134_BOARD_TECHNOTREND_BUDGET_T3000,
6663 }, {
6634 /* --- boards without eeprom + subsystem ID --- */ 6664 /* --- boards without eeprom + subsystem ID --- */
6635 .vendor = PCI_VENDOR_ID_PHILIPS, 6665 .vendor = PCI_VENDOR_ID_PHILIPS,
6636 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 6666 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
@@ -7320,6 +7350,7 @@ int saa7134_board_init2(struct saa7134_dev *dev)
7320 case SAA7134_BOARD_VIDEOMATE_DVBT_300: 7350 case SAA7134_BOARD_VIDEOMATE_DVBT_300:
7321 case SAA7134_BOARD_ASUS_EUROPA2_HYBRID: 7351 case SAA7134_BOARD_ASUS_EUROPA2_HYBRID:
7322 case SAA7134_BOARD_ASUS_EUROPA_HYBRID: 7352 case SAA7134_BOARD_ASUS_EUROPA_HYBRID:
7353 case SAA7134_BOARD_TECHNOTREND_BUDGET_T3000:
7323 { 7354 {
7324 7355
7325 /* The Philips EUROPA based hybrid boards have the tuner 7356 /* The Philips EUROPA based hybrid boards have the tuner
diff --git a/drivers/media/video/saa7134/saa7134-core.c b/drivers/media/video/saa7134/saa7134-core.c
index 90f231881297..40bc635e8a3f 100644
--- a/drivers/media/video/saa7134/saa7134-core.c
+++ b/drivers/media/video/saa7134/saa7134-core.c
@@ -256,7 +256,7 @@ void saa7134_dma_free(struct videobuf_queue *q,struct saa7134_buf *buf)
256 BUG_ON(in_interrupt()); 256 BUG_ON(in_interrupt());
257 257
258 videobuf_waiton(&buf->vb,0,0); 258 videobuf_waiton(&buf->vb,0,0);
259 videobuf_dma_unmap(q, dma); 259 videobuf_dma_unmap(q->dev, dma);
260 videobuf_dma_free(dma); 260 videobuf_dma_free(dma);
261 buf->vb.state = VIDEOBUF_NEEDS_INIT; 261 buf->vb.state = VIDEOBUF_NEEDS_INIT;
262} 262}
diff --git a/drivers/media/video/saa7134/saa7134-dvb.c b/drivers/media/video/saa7134/saa7134-dvb.c
index 31e82be1b7e7..f26fe7661a1d 100644
--- a/drivers/media/video/saa7134/saa7134-dvb.c
+++ b/drivers/media/video/saa7134/saa7134-dvb.c
@@ -481,6 +481,17 @@ static struct tda1004x_config medion_cardbus = {
481 .request_firmware = philips_tda1004x_request_firmware 481 .request_firmware = philips_tda1004x_request_firmware
482}; 482};
483 483
484static struct tda1004x_config technotrend_budget_t3000_config = {
485 .demod_address = 0x8,
486 .invert = 1,
487 .invert_oclk = 0,
488 .xtal_freq = TDA10046_XTAL_4M,
489 .agc_config = TDA10046_AGC_DEFAULT,
490 .if_freq = TDA10046_FREQ_3617,
491 .tuner_address = 0x63,
492 .request_firmware = philips_tda1004x_request_firmware
493};
494
484/* ------------------------------------------------------------------ 495/* ------------------------------------------------------------------
485 * tda 1004x based cards with philips silicon tuner 496 * tda 1004x based cards with philips silicon tuner
486 */ 497 */
@@ -1168,6 +1179,18 @@ static int dvb_init(struct saa7134_dev *dev)
1168 fe0->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params; 1179 fe0->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
1169 } 1180 }
1170 break; 1181 break;
1182 case SAA7134_BOARD_TECHNOTREND_BUDGET_T3000:
1183 fe0->dvb.frontend = dvb_attach(tda10046_attach,
1184 &technotrend_budget_t3000_config,
1185 &dev->i2c_adap);
1186 if (fe0->dvb.frontend) {
1187 dev->original_demod_sleep = fe0->dvb.frontend->ops.sleep;
1188 fe0->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
1189 fe0->dvb.frontend->ops.tuner_ops.init = philips_europa_tuner_init;
1190 fe0->dvb.frontend->ops.tuner_ops.sleep = philips_europa_tuner_sleep;
1191 fe0->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
1192 }
1193 break;
1171 case SAA7134_BOARD_VIDEOMATE_DVBT_200: 1194 case SAA7134_BOARD_VIDEOMATE_DVBT_200:
1172 fe0->dvb.frontend = dvb_attach(tda10046_attach, 1195 fe0->dvb.frontend = dvb_attach(tda10046_attach,
1173 &philips_tu1216_61_config, 1196 &philips_tu1216_61_config,
diff --git a/drivers/media/video/saa7134/saa7134.h b/drivers/media/video/saa7134/saa7134.h
index 756a1ca8833d..c040a1808542 100644
--- a/drivers/media/video/saa7134/saa7134.h
+++ b/drivers/media/video/saa7134/saa7134.h
@@ -304,6 +304,7 @@ struct saa7134_format {
304#define SAA7134_BOARD_BEHOLD_H7 178 304#define SAA7134_BOARD_BEHOLD_H7 178
305#define SAA7134_BOARD_BEHOLD_A7 179 305#define SAA7134_BOARD_BEHOLD_A7 179
306#define SAA7134_BOARD_AVERMEDIA_M733A 180 306#define SAA7134_BOARD_AVERMEDIA_M733A 180
307#define SAA7134_BOARD_TECHNOTREND_BUDGET_T3000 181
307 308
308#define SAA7134_MAXBOARDS 32 309#define SAA7134_MAXBOARDS 32
309#define SAA7134_INPUT_MAX 8 310#define SAA7134_INPUT_MAX 8
diff --git a/drivers/media/video/sh_mobile_ceu_camera.c b/drivers/media/video/sh_mobile_ceu_camera.c
index 961bfa2fea97..2b24bd0de3ad 100644
--- a/drivers/media/video/sh_mobile_ceu_camera.c
+++ b/drivers/media/video/sh_mobile_ceu_camera.c
@@ -633,6 +633,12 @@ static void sh_mobile_ceu_set_rect(struct soc_camera_device *icd)
633 cdwdr_width *= 2; 633 cdwdr_width *= 2;
634 } 634 }
635 635
636 /* CSI2 special configuration */
637 if (pcdev->pdata->csi2_dev) {
638 in_width = ((in_width - 2) * 2);
639 left_offset *= 2;
640 }
641
636 /* Set CAMOR, CAPWR, CFSZR, take care of CDWDR */ 642 /* Set CAMOR, CAPWR, CFSZR, take care of CDWDR */
637 camor = left_offset | (top_offset << 16); 643 camor = left_offset | (top_offset << 16);
638 644
@@ -743,16 +749,16 @@ static int sh_mobile_ceu_set_bus_param(struct soc_camera_device *icd,
743 case V4L2_PIX_FMT_NV16: 749 case V4L2_PIX_FMT_NV16:
744 case V4L2_PIX_FMT_NV61: 750 case V4L2_PIX_FMT_NV61:
745 switch (cam->code) { 751 switch (cam->code) {
746 case V4L2_MBUS_FMT_YUYV8_2X8_BE: 752 case V4L2_MBUS_FMT_UYVY8_2X8:
747 value = 0x00000000; /* Cb0, Y0, Cr0, Y1 */ 753 value = 0x00000000; /* Cb0, Y0, Cr0, Y1 */
748 break; 754 break;
749 case V4L2_MBUS_FMT_YVYU8_2X8_BE: 755 case V4L2_MBUS_FMT_VYUY8_2X8:
750 value = 0x00000100; /* Cr0, Y0, Cb0, Y1 */ 756 value = 0x00000100; /* Cr0, Y0, Cb0, Y1 */
751 break; 757 break;
752 case V4L2_MBUS_FMT_YUYV8_2X8_LE: 758 case V4L2_MBUS_FMT_YUYV8_2X8:
753 value = 0x00000200; /* Y0, Cb0, Y1, Cr0 */ 759 value = 0x00000200; /* Y0, Cb0, Y1, Cr0 */
754 break; 760 break;
755 case V4L2_MBUS_FMT_YVYU8_2X8_LE: 761 case V4L2_MBUS_FMT_YVYU8_2X8:
756 value = 0x00000300; /* Y0, Cr0, Y1, Cb0 */ 762 value = 0x00000300; /* Y0, Cr0, Y1, Cb0 */
757 break; 763 break;
758 default: 764 default:
@@ -767,6 +773,11 @@ static int sh_mobile_ceu_set_bus_param(struct soc_camera_device *icd,
767 value |= common_flags & SOCAM_VSYNC_ACTIVE_LOW ? 1 << 1 : 0; 773 value |= common_flags & SOCAM_VSYNC_ACTIVE_LOW ? 1 << 1 : 0;
768 value |= common_flags & SOCAM_HSYNC_ACTIVE_LOW ? 1 << 0 : 0; 774 value |= common_flags & SOCAM_HSYNC_ACTIVE_LOW ? 1 << 0 : 0;
769 value |= pcdev->is_16bit ? 1 << 12 : 0; 775 value |= pcdev->is_16bit ? 1 << 12 : 0;
776
777 /* CSI2 mode */
778 if (pcdev->pdata->csi2_dev)
779 value |= 3 << 12;
780
770 ceu_write(pcdev, CAMCR, value); 781 ceu_write(pcdev, CAMCR, value);
771 782
772 ceu_write(pcdev, CAPCR, 0x00300000); 783 ceu_write(pcdev, CAPCR, 0x00300000);
@@ -883,6 +894,8 @@ static int sh_mobile_ceu_get_formats(struct soc_camera_device *icd, unsigned int
883{ 894{
884 struct v4l2_subdev *sd = soc_camera_to_subdev(icd); 895 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
885 struct device *dev = icd->dev.parent; 896 struct device *dev = icd->dev.parent;
897 struct soc_camera_host *ici = to_soc_camera_host(dev);
898 struct sh_mobile_ceu_dev *pcdev = ici->priv;
886 int ret, k, n; 899 int ret, k, n;
887 int formats = 0; 900 int formats = 0;
888 struct sh_mobile_ceu_cam *cam; 901 struct sh_mobile_ceu_cam *cam;
@@ -896,19 +909,19 @@ static int sh_mobile_ceu_get_formats(struct soc_camera_device *icd, unsigned int
896 909
897 fmt = soc_mbus_get_fmtdesc(code); 910 fmt = soc_mbus_get_fmtdesc(code);
898 if (!fmt) { 911 if (!fmt) {
899 dev_err(icd->dev.parent, 912 dev_err(dev, "Invalid format code #%u: %d\n", idx, code);
900 "Invalid format code #%u: %d\n", idx, code);
901 return -EINVAL; 913 return -EINVAL;
902 } 914 }
903 915
904 ret = sh_mobile_ceu_try_bus_param(icd, fmt->bits_per_sample); 916 if (!pcdev->pdata->csi2_dev) {
905 if (ret < 0) 917 ret = sh_mobile_ceu_try_bus_param(icd, fmt->bits_per_sample);
906 return 0; 918 if (ret < 0)
919 return 0;
920 }
907 921
908 if (!icd->host_priv) { 922 if (!icd->host_priv) {
909 struct v4l2_mbus_framefmt mf; 923 struct v4l2_mbus_framefmt mf;
910 struct v4l2_rect rect; 924 struct v4l2_rect rect;
911 struct device *dev = icd->dev.parent;
912 int shift = 0; 925 int shift = 0;
913 926
914 /* FIXME: subwindow is lost between close / open */ 927 /* FIXME: subwindow is lost between close / open */
@@ -927,7 +940,8 @@ static int sh_mobile_ceu_get_formats(struct soc_camera_device *icd, unsigned int
927 /* Try 2560x1920, 1280x960, 640x480, 320x240 */ 940 /* Try 2560x1920, 1280x960, 640x480, 320x240 */
928 mf.width = 2560 >> shift; 941 mf.width = 2560 >> shift;
929 mf.height = 1920 >> shift; 942 mf.height = 1920 >> shift;
930 ret = v4l2_subdev_call(sd, video, s_mbus_fmt, &mf); 943 ret = v4l2_device_call_until_err(sd->v4l2_dev, 0, video,
944 s_mbus_fmt, &mf);
931 if (ret < 0) 945 if (ret < 0)
932 return ret; 946 return ret;
933 shift++; 947 shift++;
@@ -965,10 +979,10 @@ static int sh_mobile_ceu_get_formats(struct soc_camera_device *icd, unsigned int
965 cam->extra_fmt = NULL; 979 cam->extra_fmt = NULL;
966 980
967 switch (code) { 981 switch (code) {
968 case V4L2_MBUS_FMT_YUYV8_2X8_BE: 982 case V4L2_MBUS_FMT_UYVY8_2X8:
969 case V4L2_MBUS_FMT_YVYU8_2X8_BE: 983 case V4L2_MBUS_FMT_VYUY8_2X8:
970 case V4L2_MBUS_FMT_YUYV8_2X8_LE: 984 case V4L2_MBUS_FMT_YUYV8_2X8:
971 case V4L2_MBUS_FMT_YVYU8_2X8_LE: 985 case V4L2_MBUS_FMT_YVYU8_2X8:
972 if (cam->extra_fmt) 986 if (cam->extra_fmt)
973 break; 987 break;
974 988
@@ -1005,7 +1019,7 @@ static int sh_mobile_ceu_get_formats(struct soc_camera_device *icd, unsigned int
1005 xlate->code = code; 1019 xlate->code = code;
1006 xlate++; 1020 xlate++;
1007 dev_dbg(dev, "Providing format %s in pass-through mode\n", 1021 dev_dbg(dev, "Providing format %s in pass-through mode\n",
1008 xlate->host_fmt->name); 1022 fmt->name);
1009 } 1023 }
1010 1024
1011 return formats; 1025 return formats;
@@ -1228,7 +1242,8 @@ static int client_s_fmt(struct soc_camera_device *icd,
1228 struct v4l2_cropcap cap; 1242 struct v4l2_cropcap cap;
1229 int ret; 1243 int ret;
1230 1244
1231 ret = v4l2_subdev_call(sd, video, s_mbus_fmt, mf); 1245 ret = v4l2_device_call_until_err(sd->v4l2_dev, 0, video,
1246 s_mbus_fmt, mf);
1232 if (ret < 0) 1247 if (ret < 0)
1233 return ret; 1248 return ret;
1234 1249
@@ -1257,7 +1272,8 @@ static int client_s_fmt(struct soc_camera_device *icd,
1257 tmp_h = min(2 * tmp_h, max_height); 1272 tmp_h = min(2 * tmp_h, max_height);
1258 mf->width = tmp_w; 1273 mf->width = tmp_w;
1259 mf->height = tmp_h; 1274 mf->height = tmp_h;
1260 ret = v4l2_subdev_call(sd, video, s_mbus_fmt, mf); 1275 ret = v4l2_device_call_until_err(sd->v4l2_dev, 0, video,
1276 s_mbus_fmt, mf);
1261 dev_geo(dev, "Camera scaled to %ux%u\n", 1277 dev_geo(dev, "Camera scaled to %ux%u\n",
1262 mf->width, mf->height); 1278 mf->width, mf->height);
1263 if (ret < 0) { 1279 if (ret < 0) {
@@ -1514,7 +1530,8 @@ static int sh_mobile_ceu_set_fmt(struct soc_camera_device *icd,
1514 struct device *dev = icd->dev.parent; 1530 struct device *dev = icd->dev.parent;
1515 __u32 pixfmt = pix->pixelformat; 1531 __u32 pixfmt = pix->pixelformat;
1516 const struct soc_camera_format_xlate *xlate; 1532 const struct soc_camera_format_xlate *xlate;
1517 unsigned int ceu_sub_width, ceu_sub_height; 1533 /* Keep Compiler Happy */
1534 unsigned int ceu_sub_width = 0, ceu_sub_height = 0;
1518 u16 scale_v, scale_h; 1535 u16 scale_v, scale_h;
1519 int ret; 1536 int ret;
1520 bool image_mode; 1537 bool image_mode;
@@ -1569,8 +1586,8 @@ static int sh_mobile_ceu_set_fmt(struct soc_camera_device *icd,
1569 1586
1570 /* Done with the camera. Now see if we can improve the result */ 1587 /* Done with the camera. Now see if we can improve the result */
1571 1588
1572 dev_geo(dev, "Camera %d fmt %ux%u, requested %ux%u\n", 1589 dev_geo(dev, "fmt %ux%u, requested %ux%u\n",
1573 ret, mf.width, mf.height, pix->width, pix->height); 1590 mf.width, mf.height, pix->width, pix->height);
1574 if (ret < 0) 1591 if (ret < 0)
1575 return ret; 1592 return ret;
1576 1593
@@ -1634,6 +1651,9 @@ static int sh_mobile_ceu_try_fmt(struct soc_camera_device *icd,
1634 int width, height; 1651 int width, height;
1635 int ret; 1652 int ret;
1636 1653
1654 dev_geo(icd->dev.parent, "TRY_FMT(pix=0x%x, %ux%u)\n",
1655 pixfmt, pix->width, pix->height);
1656
1637 xlate = soc_camera_xlate_by_fourcc(icd, pixfmt); 1657 xlate = soc_camera_xlate_by_fourcc(icd, pixfmt);
1638 if (!xlate) { 1658 if (!xlate) {
1639 dev_warn(icd->dev.parent, "Format %x not found\n", pixfmt); 1659 dev_warn(icd->dev.parent, "Format %x not found\n", pixfmt);
@@ -1660,7 +1680,7 @@ static int sh_mobile_ceu_try_fmt(struct soc_camera_device *icd,
1660 mf.code = xlate->code; 1680 mf.code = xlate->code;
1661 mf.colorspace = pix->colorspace; 1681 mf.colorspace = pix->colorspace;
1662 1682
1663 ret = v4l2_subdev_call(sd, video, try_mbus_fmt, &mf); 1683 ret = v4l2_device_call_until_err(sd->v4l2_dev, 0, video, try_mbus_fmt, &mf);
1664 if (ret < 0) 1684 if (ret < 0)
1665 return ret; 1685 return ret;
1666 1686
@@ -1684,7 +1704,8 @@ static int sh_mobile_ceu_try_fmt(struct soc_camera_device *icd,
1684 */ 1704 */
1685 mf.width = 2560; 1705 mf.width = 2560;
1686 mf.height = 1920; 1706 mf.height = 1920;
1687 ret = v4l2_subdev_call(sd, video, try_mbus_fmt, &mf); 1707 ret = v4l2_device_call_until_err(sd->v4l2_dev, 0, video,
1708 try_mbus_fmt, &mf);
1688 if (ret < 0) { 1709 if (ret < 0) {
1689 /* Shouldn't actually happen... */ 1710 /* Shouldn't actually happen... */
1690 dev_err(icd->dev.parent, 1711 dev_err(icd->dev.parent,
@@ -1699,6 +1720,9 @@ static int sh_mobile_ceu_try_fmt(struct soc_camera_device *icd,
1699 pix->height = height; 1720 pix->height = height;
1700 } 1721 }
1701 1722
1723 dev_geo(icd->dev.parent, "%s(): return %d, fmt 0x%x, %ux%u\n",
1724 __func__, ret, pix->pixelformat, pix->width, pix->height);
1725
1702 return ret; 1726 return ret;
1703} 1727}
1704 1728
@@ -1853,6 +1877,30 @@ static struct soc_camera_host_ops sh_mobile_ceu_host_ops = {
1853 .num_controls = ARRAY_SIZE(sh_mobile_ceu_controls), 1877 .num_controls = ARRAY_SIZE(sh_mobile_ceu_controls),
1854}; 1878};
1855 1879
1880struct bus_wait {
1881 struct notifier_block notifier;
1882 struct completion completion;
1883 struct device *dev;
1884};
1885
1886static int bus_notify(struct notifier_block *nb,
1887 unsigned long action, void *data)
1888{
1889 struct device *dev = data;
1890 struct bus_wait *wait = container_of(nb, struct bus_wait, notifier);
1891
1892 if (wait->dev != dev)
1893 return NOTIFY_DONE;
1894
1895 switch (action) {
1896 case BUS_NOTIFY_UNBOUND_DRIVER:
1897 /* Protect from module unloading */
1898 wait_for_completion(&wait->completion);
1899 return NOTIFY_OK;
1900 }
1901 return NOTIFY_DONE;
1902}
1903
1856static int __devinit sh_mobile_ceu_probe(struct platform_device *pdev) 1904static int __devinit sh_mobile_ceu_probe(struct platform_device *pdev)
1857{ 1905{
1858 struct sh_mobile_ceu_dev *pcdev; 1906 struct sh_mobile_ceu_dev *pcdev;
@@ -1860,6 +1908,11 @@ static int __devinit sh_mobile_ceu_probe(struct platform_device *pdev)
1860 void __iomem *base; 1908 void __iomem *base;
1861 unsigned int irq; 1909 unsigned int irq;
1862 int err = 0; 1910 int err = 0;
1911 struct bus_wait wait = {
1912 .completion = COMPLETION_INITIALIZER_ONSTACK(wait.completion),
1913 .notifier.notifier_call = bus_notify,
1914 };
1915 struct device *csi2;
1863 1916
1864 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1917 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1865 irq = platform_get_irq(pdev, 0); 1918 irq = platform_get_irq(pdev, 0);
@@ -1931,12 +1984,54 @@ static int __devinit sh_mobile_ceu_probe(struct platform_device *pdev)
1931 pcdev->ici.drv_name = dev_name(&pdev->dev); 1984 pcdev->ici.drv_name = dev_name(&pdev->dev);
1932 pcdev->ici.ops = &sh_mobile_ceu_host_ops; 1985 pcdev->ici.ops = &sh_mobile_ceu_host_ops;
1933 1986
1987 /* CSI2 interfacing */
1988 csi2 = pcdev->pdata->csi2_dev;
1989 if (csi2) {
1990 wait.dev = csi2;
1991
1992 err = bus_register_notifier(&platform_bus_type, &wait.notifier);
1993 if (err < 0)
1994 goto exit_free_clk;
1995
1996 /*
1997 * From this point the driver module will not unload, until
1998 * we complete the completion.
1999 */
2000
2001 if (!csi2->driver || !csi2->driver->owner) {
2002 complete(&wait.completion);
2003 /* Either too late, or probing failed */
2004 bus_unregister_notifier(&platform_bus_type, &wait.notifier);
2005 err = -ENXIO;
2006 goto exit_free_clk;
2007 }
2008
2009 /*
2010 * The module is still loaded, in the worst case it is hanging
2011 * in device release on our completion. So, _now_ dereferencing
2012 * the "owner" is safe!
2013 */
2014
2015 err = try_module_get(csi2->driver->owner);
2016
2017 /* Let notifier complete, if it has been locked */
2018 complete(&wait.completion);
2019 bus_unregister_notifier(&platform_bus_type, &wait.notifier);
2020 if (!err) {
2021 err = -ENODEV;
2022 goto exit_free_clk;
2023 }
2024 }
2025
1934 err = soc_camera_host_register(&pcdev->ici); 2026 err = soc_camera_host_register(&pcdev->ici);
1935 if (err) 2027 if (err)
1936 goto exit_free_clk; 2028 goto exit_module_put;
1937 2029
1938 return 0; 2030 return 0;
1939 2031
2032exit_module_put:
2033 if (csi2 && csi2->driver)
2034 module_put(csi2->driver->owner);
1940exit_free_clk: 2035exit_free_clk:
1941 pm_runtime_disable(&pdev->dev); 2036 pm_runtime_disable(&pdev->dev);
1942 free_irq(pcdev->irq, pcdev); 2037 free_irq(pcdev->irq, pcdev);
@@ -1956,6 +2051,7 @@ static int __devexit sh_mobile_ceu_remove(struct platform_device *pdev)
1956 struct soc_camera_host *soc_host = to_soc_camera_host(&pdev->dev); 2051 struct soc_camera_host *soc_host = to_soc_camera_host(&pdev->dev);
1957 struct sh_mobile_ceu_dev *pcdev = container_of(soc_host, 2052 struct sh_mobile_ceu_dev *pcdev = container_of(soc_host,
1958 struct sh_mobile_ceu_dev, ici); 2053 struct sh_mobile_ceu_dev, ici);
2054 struct device *csi2 = pcdev->pdata->csi2_dev;
1959 2055
1960 soc_camera_host_unregister(soc_host); 2056 soc_camera_host_unregister(soc_host);
1961 pm_runtime_disable(&pdev->dev); 2057 pm_runtime_disable(&pdev->dev);
@@ -1963,7 +2059,10 @@ static int __devexit sh_mobile_ceu_remove(struct platform_device *pdev)
1963 if (platform_get_resource(pdev, IORESOURCE_MEM, 1)) 2059 if (platform_get_resource(pdev, IORESOURCE_MEM, 1))
1964 dma_release_declared_memory(&pdev->dev); 2060 dma_release_declared_memory(&pdev->dev);
1965 iounmap(pcdev->base); 2061 iounmap(pcdev->base);
2062 if (csi2 && csi2->driver)
2063 module_put(csi2->driver->owner);
1966 kfree(pcdev); 2064 kfree(pcdev);
2065
1967 return 0; 2066 return 0;
1968} 2067}
1969 2068
@@ -1995,6 +2094,8 @@ static struct platform_driver sh_mobile_ceu_driver = {
1995 2094
1996static int __init sh_mobile_ceu_init(void) 2095static int __init sh_mobile_ceu_init(void)
1997{ 2096{
2097 /* Whatever return code */
2098 request_module("sh_mobile_csi2");
1998 return platform_driver_register(&sh_mobile_ceu_driver); 2099 return platform_driver_register(&sh_mobile_ceu_driver);
1999} 2100}
2000 2101
diff --git a/drivers/media/video/sh_mobile_csi2.c b/drivers/media/video/sh_mobile_csi2.c
new file mode 100644
index 000000000000..84a646819318
--- /dev/null
+++ b/drivers/media/video/sh_mobile_csi2.c
@@ -0,0 +1,354 @@
1/*
2 * Driver for the SH-Mobile MIPI CSI-2 unit
3 *
4 * Copyright (C) 2010, Guennadi Liakhovetski <g.liakhovetski@gmx.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 version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#include <linux/delay.h>
12#include <linux/i2c.h>
13#include <linux/io.h>
14#include <linux/platform_device.h>
15#include <linux/pm_runtime.h>
16#include <linux/slab.h>
17#include <linux/videodev2.h>
18
19#include <media/sh_mobile_csi2.h>
20#include <media/soc_camera.h>
21#include <media/v4l2-common.h>
22#include <media/v4l2-dev.h>
23#include <media/v4l2-device.h>
24#include <media/v4l2-mediabus.h>
25#include <media/v4l2-subdev.h>
26
27#define SH_CSI2_TREF 0x00
28#define SH_CSI2_SRST 0x04
29#define SH_CSI2_PHYCNT 0x08
30#define SH_CSI2_CHKSUM 0x0C
31#define SH_CSI2_VCDT 0x10
32
33struct sh_csi2 {
34 struct v4l2_subdev subdev;
35 struct list_head list;
36 struct notifier_block notifier;
37 unsigned int irq;
38 void __iomem *base;
39 struct platform_device *pdev;
40 struct sh_csi2_client_config *client;
41};
42
43static int sh_csi2_try_fmt(struct v4l2_subdev *sd,
44 struct v4l2_mbus_framefmt *mf)
45{
46 struct sh_csi2 *priv = container_of(sd, struct sh_csi2, subdev);
47 struct sh_csi2_pdata *pdata = priv->pdev->dev.platform_data;
48
49 if (mf->width > 8188)
50 mf->width = 8188;
51 else if (mf->width & 1)
52 mf->width &= ~1;
53
54 switch (pdata->type) {
55 case SH_CSI2C:
56 switch (mf->code) {
57 case V4L2_MBUS_FMT_UYVY8_2X8: /* YUV422 */
58 case V4L2_MBUS_FMT_YUYV8_1_5X8: /* YUV420 */
59 case V4L2_MBUS_FMT_GREY8_1X8: /* RAW8 */
60 case V4L2_MBUS_FMT_SBGGR8_1X8:
61 case V4L2_MBUS_FMT_SGRBG8_1X8:
62 break;
63 default:
64 /* All MIPI CSI-2 devices must support one of primary formats */
65 mf->code = V4L2_MBUS_FMT_YUYV8_2X8;
66 }
67 break;
68 case SH_CSI2I:
69 switch (mf->code) {
70 case V4L2_MBUS_FMT_GREY8_1X8: /* RAW8 */
71 case V4L2_MBUS_FMT_SBGGR8_1X8:
72 case V4L2_MBUS_FMT_SGRBG8_1X8:
73 case V4L2_MBUS_FMT_SBGGR10_1X10: /* RAW10 */
74 case V4L2_MBUS_FMT_SBGGR12_1X12: /* RAW12 */
75 break;
76 default:
77 /* All MIPI CSI-2 devices must support one of primary formats */
78 mf->code = V4L2_MBUS_FMT_SBGGR8_1X8;
79 }
80 break;
81 }
82
83 return 0;
84}
85
86/*
87 * We have done our best in try_fmt to try and tell the sensor, which formats
88 * we support. If now the configuration is unsuitable for us we can only
89 * error out.
90 */
91static int sh_csi2_s_fmt(struct v4l2_subdev *sd,
92 struct v4l2_mbus_framefmt *mf)
93{
94 struct sh_csi2 *priv = container_of(sd, struct sh_csi2, subdev);
95 u32 tmp = (priv->client->channel & 3) << 8;
96
97 dev_dbg(sd->v4l2_dev->dev, "%s(%u)\n", __func__, mf->code);
98 if (mf->width > 8188 || mf->width & 1)
99 return -EINVAL;
100
101 switch (mf->code) {
102 case V4L2_MBUS_FMT_UYVY8_2X8:
103 tmp |= 0x1e; /* YUV422 8 bit */
104 break;
105 case V4L2_MBUS_FMT_YUYV8_1_5X8:
106 tmp |= 0x18; /* YUV420 8 bit */
107 break;
108 case V4L2_MBUS_FMT_RGB555_2X8_PADHI_BE:
109 tmp |= 0x21; /* RGB555 */
110 break;
111 case V4L2_MBUS_FMT_RGB565_2X8_BE:
112 tmp |= 0x22; /* RGB565 */
113 break;
114 case V4L2_MBUS_FMT_GREY8_1X8:
115 case V4L2_MBUS_FMT_SBGGR8_1X8:
116 case V4L2_MBUS_FMT_SGRBG8_1X8:
117 tmp |= 0x2a; /* RAW8 */
118 break;
119 default:
120 return -EINVAL;
121 }
122
123 iowrite32(tmp, priv->base + SH_CSI2_VCDT);
124
125 return 0;
126}
127
128static struct v4l2_subdev_video_ops sh_csi2_subdev_video_ops = {
129 .s_mbus_fmt = sh_csi2_s_fmt,
130 .try_mbus_fmt = sh_csi2_try_fmt,
131};
132
133static struct v4l2_subdev_core_ops sh_csi2_subdev_core_ops;
134
135static struct v4l2_subdev_ops sh_csi2_subdev_ops = {
136 .core = &sh_csi2_subdev_core_ops,
137 .video = &sh_csi2_subdev_video_ops,
138};
139
140static void sh_csi2_hwinit(struct sh_csi2 *priv)
141{
142 struct sh_csi2_pdata *pdata = priv->pdev->dev.platform_data;
143 __u32 tmp = 0x10; /* Enable MIPI CSI clock lane */
144
145 /* Reflect registers immediately */
146 iowrite32(0x00000001, priv->base + SH_CSI2_TREF);
147 /* reset CSI2 harware */
148 iowrite32(0x00000001, priv->base + SH_CSI2_SRST);
149 udelay(5);
150 iowrite32(0x00000000, priv->base + SH_CSI2_SRST);
151
152 if (priv->client->lanes & 3)
153 tmp |= priv->client->lanes & 3;
154 else
155 /* Default - both lanes */
156 tmp |= 3;
157
158 if (priv->client->phy == SH_CSI2_PHY_MAIN)
159 tmp |= 0x8000;
160
161 iowrite32(tmp, priv->base + SH_CSI2_PHYCNT);
162
163 tmp = 0;
164 if (pdata->flags & SH_CSI2_ECC)
165 tmp |= 2;
166 if (pdata->flags & SH_CSI2_CRC)
167 tmp |= 1;
168 iowrite32(tmp, priv->base + SH_CSI2_CHKSUM);
169}
170
171static int sh_csi2_set_bus_param(struct soc_camera_device *icd,
172 unsigned long flags)
173{
174 return 0;
175}
176
177static unsigned long sh_csi2_query_bus_param(struct soc_camera_device *icd)
178{
179 struct soc_camera_link *icl = to_soc_camera_link(icd);
180 const unsigned long flags = SOCAM_PCLK_SAMPLE_RISING |
181 SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_HIGH |
182 SOCAM_MASTER | SOCAM_DATAWIDTH_8 | SOCAM_DATA_ACTIVE_HIGH;
183
184 return soc_camera_apply_sensor_flags(icl, flags);
185}
186
187static int sh_csi2_notify(struct notifier_block *nb,
188 unsigned long action, void *data)
189{
190 struct device *dev = data;
191 struct soc_camera_device *icd = to_soc_camera_dev(dev);
192 struct v4l2_device *v4l2_dev = dev_get_drvdata(dev->parent);
193 struct sh_csi2 *priv =
194 container_of(nb, struct sh_csi2, notifier);
195 struct sh_csi2_pdata *pdata = priv->pdev->dev.platform_data;
196 int ret, i;
197
198 for (i = 0; i < pdata->num_clients; i++)
199 if (&pdata->clients[i].pdev->dev == icd->pdev)
200 break;
201
202 dev_dbg(dev, "%s(%p): action = %lu, found #%d\n", __func__, dev, action, i);
203
204 if (i == pdata->num_clients)
205 return NOTIFY_DONE;
206
207 switch (action) {
208 case BUS_NOTIFY_BOUND_DRIVER:
209 snprintf(priv->subdev.name, V4L2_SUBDEV_NAME_SIZE, "%s%s",
210 dev_name(v4l2_dev->dev), ".mipi-csi");
211 ret = v4l2_device_register_subdev(v4l2_dev, &priv->subdev);
212 dev_dbg(dev, "%s(%p): ret(register_subdev) = %d\n", __func__, priv, ret);
213 if (ret < 0)
214 return NOTIFY_DONE;
215
216 priv->client = pdata->clients + i;
217
218 icd->ops->set_bus_param = sh_csi2_set_bus_param;
219 icd->ops->query_bus_param = sh_csi2_query_bus_param;
220
221 pm_runtime_get_sync(v4l2_get_subdevdata(&priv->subdev));
222
223 sh_csi2_hwinit(priv);
224 break;
225 case BUS_NOTIFY_UNBIND_DRIVER:
226 priv->client = NULL;
227
228 /* Driver is about to be unbound */
229 icd->ops->set_bus_param = NULL;
230 icd->ops->query_bus_param = NULL;
231
232 v4l2_device_unregister_subdev(&priv->subdev);
233
234 pm_runtime_put(v4l2_get_subdevdata(&priv->subdev));
235 break;
236 }
237
238 return NOTIFY_OK;
239}
240
241static __devinit int sh_csi2_probe(struct platform_device *pdev)
242{
243 struct resource *res;
244 unsigned int irq;
245 int ret;
246 struct sh_csi2 *priv;
247 /* Platform data specify the PHY, lanes, ECC, CRC */
248 struct sh_csi2_pdata *pdata = pdev->dev.platform_data;
249
250 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
251 /* Interrupt unused so far */
252 irq = platform_get_irq(pdev, 0);
253
254 if (!res || (int)irq <= 0 || !pdata) {
255 dev_err(&pdev->dev, "Not enough CSI2 platform resources.\n");
256 return -ENODEV;
257 }
258
259 /* TODO: Add support for CSI2I. Careful: different register layout! */
260 if (pdata->type != SH_CSI2C) {
261 dev_err(&pdev->dev, "Only CSI2C supported ATM.\n");
262 return -EINVAL;
263 }
264
265 priv = kzalloc(sizeof(struct sh_csi2), GFP_KERNEL);
266 if (!priv)
267 return -ENOMEM;
268
269 priv->irq = irq;
270 priv->notifier.notifier_call = sh_csi2_notify;
271
272 /* We MUST attach after the MIPI sensor */
273 ret = bus_register_notifier(&soc_camera_bus_type, &priv->notifier);
274 if (ret < 0) {
275 dev_err(&pdev->dev, "CSI2 cannot register notifier\n");
276 goto ernotify;
277 }
278
279 if (!request_mem_region(res->start, resource_size(res), pdev->name)) {
280 dev_err(&pdev->dev, "CSI2 register region already claimed\n");
281 ret = -EBUSY;
282 goto ereqreg;
283 }
284
285 priv->base = ioremap(res->start, resource_size(res));
286 if (!priv->base) {
287 ret = -ENXIO;
288 dev_err(&pdev->dev, "Unable to ioremap CSI2 registers.\n");
289 goto eremap;
290 }
291
292 priv->pdev = pdev;
293
294 v4l2_subdev_init(&priv->subdev, &sh_csi2_subdev_ops);
295 v4l2_set_subdevdata(&priv->subdev, &pdev->dev);
296
297 platform_set_drvdata(pdev, priv);
298
299 pm_runtime_enable(&pdev->dev);
300
301 dev_dbg(&pdev->dev, "CSI2 probed.\n");
302
303 return 0;
304
305eremap:
306 release_mem_region(res->start, resource_size(res));
307ereqreg:
308 bus_unregister_notifier(&soc_camera_bus_type, &priv->notifier);
309ernotify:
310 kfree(priv);
311
312 return ret;
313}
314
315static __devexit int sh_csi2_remove(struct platform_device *pdev)
316{
317 struct sh_csi2 *priv = platform_get_drvdata(pdev);
318 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
319
320 bus_unregister_notifier(&soc_camera_bus_type, &priv->notifier);
321 pm_runtime_disable(&pdev->dev);
322 iounmap(priv->base);
323 release_mem_region(res->start, resource_size(res));
324 platform_set_drvdata(pdev, NULL);
325 kfree(priv);
326
327 return 0;
328}
329
330static struct platform_driver __refdata sh_csi2_pdrv = {
331 .remove = __devexit_p(sh_csi2_remove),
332 .driver = {
333 .name = "sh-mobile-csi2",
334 .owner = THIS_MODULE,
335 },
336};
337
338static int __init sh_csi2_init(void)
339{
340 return platform_driver_probe(&sh_csi2_pdrv, sh_csi2_probe);
341}
342
343static void __exit sh_csi2_exit(void)
344{
345 platform_driver_unregister(&sh_csi2_pdrv);
346}
347
348module_init(sh_csi2_init);
349module_exit(sh_csi2_exit);
350
351MODULE_DESCRIPTION("SH-Mobile MIPI CSI-2 driver");
352MODULE_AUTHOR("Guennadi Liakhovetski <g.liakhovetski@gmx.de>");
353MODULE_LICENSE("GPL v2");
354MODULE_ALIAS("platform:sh-mobile-csi2");
diff --git a/drivers/media/video/sh_vou.c b/drivers/media/video/sh_vou.c
index f5b892a2a8ee..d394187eb701 100644
--- a/drivers/media/video/sh_vou.c
+++ b/drivers/media/video/sh_vou.c
@@ -18,6 +18,7 @@
18#include <linux/kernel.h> 18#include <linux/kernel.h>
19#include <linux/platform_device.h> 19#include <linux/platform_device.h>
20#include <linux/pm_runtime.h> 20#include <linux/pm_runtime.h>
21#include <linux/slab.h>
21#include <linux/version.h> 22#include <linux/version.h>
22#include <linux/videodev2.h> 23#include <linux/videodev2.h>
23 24
@@ -57,7 +58,7 @@ enum sh_vou_status {
57}; 58};
58 59
59#define VOU_MAX_IMAGE_WIDTH 720 60#define VOU_MAX_IMAGE_WIDTH 720
60#define VOU_MAX_IMAGE_HEIGHT 480 61#define VOU_MAX_IMAGE_HEIGHT 576
61 62
62struct sh_vou_device { 63struct sh_vou_device {
63 struct v4l2_device v4l2_dev; 64 struct v4l2_device v4l2_dev;
@@ -527,20 +528,17 @@ struct sh_vou_geometry {
527static void vou_adjust_input(struct sh_vou_geometry *geo, v4l2_std_id std) 528static void vou_adjust_input(struct sh_vou_geometry *geo, v4l2_std_id std)
528{ 529{
529 /* The compiler cannot know, that best and idx will indeed be set */ 530 /* The compiler cannot know, that best and idx will indeed be set */
530 unsigned int best_err = UINT_MAX, best = 0, width_max, height_max; 531 unsigned int best_err = UINT_MAX, best = 0, img_height_max;
531 int i, idx = 0; 532 int i, idx = 0;
532 533
533 if (std & V4L2_STD_525_60) { 534 if (std & V4L2_STD_525_60)
534 width_max = 858; 535 img_height_max = 480;
535 height_max = 262; 536 else
536 } else { 537 img_height_max = 576;
537 width_max = 864;
538 height_max = 312;
539 }
540 538
541 /* Image width must be a multiple of 4 */ 539 /* Image width must be a multiple of 4 */
542 v4l_bound_align_image(&geo->in_width, 0, VOU_MAX_IMAGE_WIDTH, 2, 540 v4l_bound_align_image(&geo->in_width, 0, VOU_MAX_IMAGE_WIDTH, 2,
543 &geo->in_height, 0, VOU_MAX_IMAGE_HEIGHT, 1, 0); 541 &geo->in_height, 0, img_height_max, 1, 0);
544 542
545 /* Select scales to come as close as possible to the output image */ 543 /* Select scales to come as close as possible to the output image */
546 for (i = ARRAY_SIZE(vou_scale_h_num) - 1; i >= 0; i--) { 544 for (i = ARRAY_SIZE(vou_scale_h_num) - 1; i >= 0; i--) {
@@ -573,7 +571,7 @@ static void vou_adjust_input(struct sh_vou_geometry *geo, v4l2_std_id std)
573 unsigned int found = geo->output.height * vou_scale_v_den[i] / 571 unsigned int found = geo->output.height * vou_scale_v_den[i] /
574 vou_scale_v_num[i]; 572 vou_scale_v_num[i];
575 573
576 if (found > VOU_MAX_IMAGE_HEIGHT) 574 if (found > img_height_max)
577 /* scales increase */ 575 /* scales increase */
578 break; 576 break;
579 577
@@ -597,15 +595,18 @@ static void vou_adjust_input(struct sh_vou_geometry *geo, v4l2_std_id std)
597 */ 595 */
598static void vou_adjust_output(struct sh_vou_geometry *geo, v4l2_std_id std) 596static void vou_adjust_output(struct sh_vou_geometry *geo, v4l2_std_id std)
599{ 597{
600 unsigned int best_err = UINT_MAX, best, width_max, height_max; 598 unsigned int best_err = UINT_MAX, best, width_max, height_max,
599 img_height_max;
601 int i, idx; 600 int i, idx;
602 601
603 if (std & V4L2_STD_525_60) { 602 if (std & V4L2_STD_525_60) {
604 width_max = 858; 603 width_max = 858;
605 height_max = 262 * 2; 604 height_max = 262 * 2;
605 img_height_max = 480;
606 } else { 606 } else {
607 width_max = 864; 607 width_max = 864;
608 height_max = 312 * 2; 608 height_max = 312 * 2;
609 img_height_max = 576;
609 } 610 }
610 611
611 /* Select scales to come as close as possible to the output image */ 612 /* Select scales to come as close as possible to the output image */
@@ -644,7 +645,7 @@ static void vou_adjust_output(struct sh_vou_geometry *geo, v4l2_std_id std)
644 unsigned int found = geo->in_height * vou_scale_v_num[i] / 645 unsigned int found = geo->in_height * vou_scale_v_num[i] /
645 vou_scale_v_den[i]; 646 vou_scale_v_den[i];
646 647
647 if (found > VOU_MAX_IMAGE_HEIGHT) 648 if (found > img_height_max)
648 /* scales increase */ 649 /* scales increase */
649 break; 650 break;
650 651
@@ -673,11 +674,12 @@ static int sh_vou_s_fmt_vid_out(struct file *file, void *priv,
673 struct video_device *vdev = video_devdata(file); 674 struct video_device *vdev = video_devdata(file);
674 struct sh_vou_device *vou_dev = video_get_drvdata(vdev); 675 struct sh_vou_device *vou_dev = video_get_drvdata(vdev);
675 struct v4l2_pix_format *pix = &fmt->fmt.pix; 676 struct v4l2_pix_format *pix = &fmt->fmt.pix;
677 unsigned int img_height_max;
676 int pix_idx; 678 int pix_idx;
677 struct sh_vou_geometry geo; 679 struct sh_vou_geometry geo;
678 struct v4l2_mbus_framefmt mbfmt = { 680 struct v4l2_mbus_framefmt mbfmt = {
679 /* Revisit: is this the correct code? */ 681 /* Revisit: is this the correct code? */
680 .code = V4L2_MBUS_FMT_YUYV8_2X8_LE, 682 .code = V4L2_MBUS_FMT_YUYV8_2X8,
681 .field = V4L2_FIELD_INTERLACED, 683 .field = V4L2_FIELD_INTERLACED,
682 .colorspace = V4L2_COLORSPACE_SMPTE170M, 684 .colorspace = V4L2_COLORSPACE_SMPTE170M,
683 }; 685 };
@@ -701,9 +703,14 @@ static int sh_vou_s_fmt_vid_out(struct file *file, void *priv,
701 if (pix_idx == ARRAY_SIZE(vou_fmt)) 703 if (pix_idx == ARRAY_SIZE(vou_fmt))
702 return -EINVAL; 704 return -EINVAL;
703 705
706 if (vou_dev->std & V4L2_STD_525_60)
707 img_height_max = 480;
708 else
709 img_height_max = 576;
710
704 /* Image width must be a multiple of 4 */ 711 /* Image width must be a multiple of 4 */
705 v4l_bound_align_image(&pix->width, 0, VOU_MAX_IMAGE_WIDTH, 2, 712 v4l_bound_align_image(&pix->width, 0, VOU_MAX_IMAGE_WIDTH, 2,
706 &pix->height, 0, VOU_MAX_IMAGE_HEIGHT, 1, 0); 713 &pix->height, 0, img_height_max, 1, 0);
707 714
708 geo.in_width = pix->width; 715 geo.in_width = pix->width;
709 geo.in_height = pix->height; 716 geo.in_height = pix->height;
@@ -724,8 +731,8 @@ static int sh_vou_s_fmt_vid_out(struct file *file, void *priv,
724 731
725 /* Sanity checks */ 732 /* Sanity checks */
726 if ((unsigned)mbfmt.width > VOU_MAX_IMAGE_WIDTH || 733 if ((unsigned)mbfmt.width > VOU_MAX_IMAGE_WIDTH ||
727 (unsigned)mbfmt.height > VOU_MAX_IMAGE_HEIGHT || 734 (unsigned)mbfmt.height > img_height_max ||
728 mbfmt.code != V4L2_MBUS_FMT_YUYV8_2X8_LE) 735 mbfmt.code != V4L2_MBUS_FMT_YUYV8_2X8)
729 return -EIO; 736 return -EIO;
730 737
731 if (mbfmt.width != geo.output.width || 738 if (mbfmt.width != geo.output.width ||
@@ -936,10 +943,11 @@ static int sh_vou_s_crop(struct file *file, void *fh, struct v4l2_crop *a)
936 struct sh_vou_geometry geo; 943 struct sh_vou_geometry geo;
937 struct v4l2_mbus_framefmt mbfmt = { 944 struct v4l2_mbus_framefmt mbfmt = {
938 /* Revisit: is this the correct code? */ 945 /* Revisit: is this the correct code? */
939 .code = V4L2_MBUS_FMT_YUYV8_2X8_LE, 946 .code = V4L2_MBUS_FMT_YUYV8_2X8,
940 .field = V4L2_FIELD_INTERLACED, 947 .field = V4L2_FIELD_INTERLACED,
941 .colorspace = V4L2_COLORSPACE_SMPTE170M, 948 .colorspace = V4L2_COLORSPACE_SMPTE170M,
942 }; 949 };
950 unsigned int img_height_max;
943 int ret; 951 int ret;
944 952
945 dev_dbg(vou_dev->v4l2_dev.dev, "%s(): %ux%u@%u:%u\n", __func__, 953 dev_dbg(vou_dev->v4l2_dev.dev, "%s(): %ux%u@%u:%u\n", __func__,
@@ -948,14 +956,19 @@ static int sh_vou_s_crop(struct file *file, void *fh, struct v4l2_crop *a)
948 if (a->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) 956 if (a->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
949 return -EINVAL; 957 return -EINVAL;
950 958
959 if (vou_dev->std & V4L2_STD_525_60)
960 img_height_max = 480;
961 else
962 img_height_max = 576;
963
951 v4l_bound_align_image(&rect->width, 0, VOU_MAX_IMAGE_WIDTH, 1, 964 v4l_bound_align_image(&rect->width, 0, VOU_MAX_IMAGE_WIDTH, 1,
952 &rect->height, 0, VOU_MAX_IMAGE_HEIGHT, 1, 0); 965 &rect->height, 0, img_height_max, 1, 0);
953 966
954 if (rect->width + rect->left > VOU_MAX_IMAGE_WIDTH) 967 if (rect->width + rect->left > VOU_MAX_IMAGE_WIDTH)
955 rect->left = VOU_MAX_IMAGE_WIDTH - rect->width; 968 rect->left = VOU_MAX_IMAGE_WIDTH - rect->width;
956 969
957 if (rect->height + rect->top > VOU_MAX_IMAGE_HEIGHT) 970 if (rect->height + rect->top > img_height_max)
958 rect->top = VOU_MAX_IMAGE_HEIGHT - rect->height; 971 rect->top = img_height_max - rect->height;
959 972
960 geo.output = *rect; 973 geo.output = *rect;
961 geo.in_width = pix->width; 974 geo.in_width = pix->width;
@@ -980,8 +993,8 @@ static int sh_vou_s_crop(struct file *file, void *fh, struct v4l2_crop *a)
980 993
981 /* Sanity checks */ 994 /* Sanity checks */
982 if ((unsigned)mbfmt.width > VOU_MAX_IMAGE_WIDTH || 995 if ((unsigned)mbfmt.width > VOU_MAX_IMAGE_WIDTH ||
983 (unsigned)mbfmt.height > VOU_MAX_IMAGE_HEIGHT || 996 (unsigned)mbfmt.height > img_height_max ||
984 mbfmt.code != V4L2_MBUS_FMT_YUYV8_2X8_LE) 997 mbfmt.code != V4L2_MBUS_FMT_YUYV8_2X8)
985 return -EIO; 998 return -EIO;
986 999
987 geo.output.width = mbfmt.width; 1000 geo.output.width = mbfmt.width;
@@ -1329,13 +1342,13 @@ static int __devinit sh_vou_probe(struct platform_device *pdev)
1329 rect->left = 0; 1342 rect->left = 0;
1330 rect->top = 0; 1343 rect->top = 0;
1331 rect->width = VOU_MAX_IMAGE_WIDTH; 1344 rect->width = VOU_MAX_IMAGE_WIDTH;
1332 rect->height = VOU_MAX_IMAGE_HEIGHT; 1345 rect->height = 480;
1333 pix->width = VOU_MAX_IMAGE_WIDTH; 1346 pix->width = VOU_MAX_IMAGE_WIDTH;
1334 pix->height = VOU_MAX_IMAGE_HEIGHT; 1347 pix->height = 480;
1335 pix->pixelformat = V4L2_PIX_FMT_YVYU; 1348 pix->pixelformat = V4L2_PIX_FMT_YVYU;
1336 pix->field = V4L2_FIELD_NONE; 1349 pix->field = V4L2_FIELD_NONE;
1337 pix->bytesperline = VOU_MAX_IMAGE_WIDTH * 2; 1350 pix->bytesperline = VOU_MAX_IMAGE_WIDTH * 2;
1338 pix->sizeimage = VOU_MAX_IMAGE_WIDTH * 2 * VOU_MAX_IMAGE_HEIGHT; 1351 pix->sizeimage = VOU_MAX_IMAGE_WIDTH * 2 * 480;
1339 pix->colorspace = V4L2_COLORSPACE_SMPTE170M; 1352 pix->colorspace = V4L2_COLORSPACE_SMPTE170M;
1340 1353
1341 region = request_mem_region(reg_res->start, resource_size(reg_res), 1354 region = request_mem_region(reg_res->start, resource_size(reg_res),
diff --git a/drivers/media/video/soc_camera.c b/drivers/media/video/soc_camera.c
index 475757bfd7ba..f2032939fd4b 100644
--- a/drivers/media/video/soc_camera.c
+++ b/drivers/media/video/soc_camera.c
@@ -1107,13 +1107,14 @@ static int soc_camera_resume(struct device *dev)
1107 return ret; 1107 return ret;
1108} 1108}
1109 1109
1110static struct bus_type soc_camera_bus_type = { 1110struct bus_type soc_camera_bus_type = {
1111 .name = "soc-camera", 1111 .name = "soc-camera",
1112 .probe = soc_camera_probe, 1112 .probe = soc_camera_probe,
1113 .remove = soc_camera_remove, 1113 .remove = soc_camera_remove,
1114 .suspend = soc_camera_suspend, 1114 .suspend = soc_camera_suspend,
1115 .resume = soc_camera_resume, 1115 .resume = soc_camera_resume,
1116}; 1116};
1117EXPORT_SYMBOL_GPL(soc_camera_bus_type);
1117 1118
1118static struct device_driver ic_drv = { 1119static struct device_driver ic_drv = {
1119 .name = "camera", 1120 .name = "camera",
diff --git a/drivers/media/video/soc_camera_platform.c b/drivers/media/video/soc_camera_platform.c
index 248c986f0989..bf406e89c992 100644
--- a/drivers/media/video/soc_camera_platform.c
+++ b/drivers/media/video/soc_camera_platform.c
@@ -56,8 +56,8 @@ soc_camera_platform_query_bus_param(struct soc_camera_device *icd)
56 return p->bus_param; 56 return p->bus_param;
57} 57}
58 58
59static int soc_camera_platform_try_fmt(struct v4l2_subdev *sd, 59static int soc_camera_platform_fill_fmt(struct v4l2_subdev *sd,
60 struct v4l2_mbus_framefmt *mf) 60 struct v4l2_mbus_framefmt *mf)
61{ 61{
62 struct soc_camera_platform_info *p = v4l2_get_subdevdata(sd); 62 struct soc_camera_platform_info *p = v4l2_get_subdevdata(sd);
63 63
@@ -65,6 +65,7 @@ static int soc_camera_platform_try_fmt(struct v4l2_subdev *sd,
65 mf->height = p->format.height; 65 mf->height = p->format.height;
66 mf->code = p->format.code; 66 mf->code = p->format.code;
67 mf->colorspace = p->format.colorspace; 67 mf->colorspace = p->format.colorspace;
68 mf->field = p->format.field;
68 69
69 return 0; 70 return 0;
70} 71}
@@ -83,10 +84,45 @@ static int soc_camera_platform_enum_fmt(struct v4l2_subdev *sd, unsigned int ind
83 return 0; 84 return 0;
84} 85}
85 86
87static int soc_camera_platform_g_crop(struct v4l2_subdev *sd,
88 struct v4l2_crop *a)
89{
90 struct soc_camera_platform_info *p = v4l2_get_subdevdata(sd);
91
92 a->c.left = 0;
93 a->c.top = 0;
94 a->c.width = p->format.width;
95 a->c.height = p->format.height;
96 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
97
98 return 0;
99}
100
101static int soc_camera_platform_cropcap(struct v4l2_subdev *sd,
102 struct v4l2_cropcap *a)
103{
104 struct soc_camera_platform_info *p = v4l2_get_subdevdata(sd);
105
106 a->bounds.left = 0;
107 a->bounds.top = 0;
108 a->bounds.width = p->format.width;
109 a->bounds.height = p->format.height;
110 a->defrect = a->bounds;
111 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
112 a->pixelaspect.numerator = 1;
113 a->pixelaspect.denominator = 1;
114
115 return 0;
116}
117
86static struct v4l2_subdev_video_ops platform_subdev_video_ops = { 118static struct v4l2_subdev_video_ops platform_subdev_video_ops = {
87 .s_stream = soc_camera_platform_s_stream, 119 .s_stream = soc_camera_platform_s_stream,
88 .try_mbus_fmt = soc_camera_platform_try_fmt,
89 .enum_mbus_fmt = soc_camera_platform_enum_fmt, 120 .enum_mbus_fmt = soc_camera_platform_enum_fmt,
121 .cropcap = soc_camera_platform_cropcap,
122 .g_crop = soc_camera_platform_g_crop,
123 .try_mbus_fmt = soc_camera_platform_fill_fmt,
124 .g_mbus_fmt = soc_camera_platform_fill_fmt,
125 .s_mbus_fmt = soc_camera_platform_fill_fmt,
90}; 126};
91 127
92static struct v4l2_subdev_ops platform_subdev_ops = { 128static struct v4l2_subdev_ops platform_subdev_ops = {
diff --git a/drivers/media/video/soc_mediabus.c b/drivers/media/video/soc_mediabus.c
index 8b63b6545e76..91391214c682 100644
--- a/drivers/media/video/soc_mediabus.c
+++ b/drivers/media/video/soc_mediabus.c
@@ -18,28 +18,28 @@
18#define MBUS_IDX(f) (V4L2_MBUS_FMT_ ## f - V4L2_MBUS_FMT_FIXED - 1) 18#define MBUS_IDX(f) (V4L2_MBUS_FMT_ ## f - V4L2_MBUS_FMT_FIXED - 1)
19 19
20static const struct soc_mbus_pixelfmt mbus_fmt[] = { 20static const struct soc_mbus_pixelfmt mbus_fmt[] = {
21 [MBUS_IDX(YUYV8_2X8_LE)] = { 21 [MBUS_IDX(YUYV8_2X8)] = {
22 .fourcc = V4L2_PIX_FMT_YUYV, 22 .fourcc = V4L2_PIX_FMT_YUYV,
23 .name = "YUYV", 23 .name = "YUYV",
24 .bits_per_sample = 8, 24 .bits_per_sample = 8,
25 .packing = SOC_MBUS_PACKING_2X8_PADHI, 25 .packing = SOC_MBUS_PACKING_2X8_PADHI,
26 .order = SOC_MBUS_ORDER_LE, 26 .order = SOC_MBUS_ORDER_LE,
27 }, 27 },
28 [MBUS_IDX(YVYU8_2X8_LE)] = { 28 [MBUS_IDX(YVYU8_2X8)] = {
29 .fourcc = V4L2_PIX_FMT_YVYU, 29 .fourcc = V4L2_PIX_FMT_YVYU,
30 .name = "YVYU", 30 .name = "YVYU",
31 .bits_per_sample = 8, 31 .bits_per_sample = 8,
32 .packing = SOC_MBUS_PACKING_2X8_PADHI, 32 .packing = SOC_MBUS_PACKING_2X8_PADHI,
33 .order = SOC_MBUS_ORDER_LE, 33 .order = SOC_MBUS_ORDER_LE,
34 }, 34 },
35 [MBUS_IDX(YUYV8_2X8_BE)] = { 35 [MBUS_IDX(UYVY8_2X8)] = {
36 .fourcc = V4L2_PIX_FMT_UYVY, 36 .fourcc = V4L2_PIX_FMT_UYVY,
37 .name = "UYVY", 37 .name = "UYVY",
38 .bits_per_sample = 8, 38 .bits_per_sample = 8,
39 .packing = SOC_MBUS_PACKING_2X8_PADHI, 39 .packing = SOC_MBUS_PACKING_2X8_PADHI,
40 .order = SOC_MBUS_ORDER_LE, 40 .order = SOC_MBUS_ORDER_LE,
41 }, 41 },
42 [MBUS_IDX(YVYU8_2X8_BE)] = { 42 [MBUS_IDX(VYUY8_2X8)] = {
43 .fourcc = V4L2_PIX_FMT_VYUY, 43 .fourcc = V4L2_PIX_FMT_VYUY,
44 .name = "VYUY", 44 .name = "VYUY",
45 .bits_per_sample = 8, 45 .bits_per_sample = 8,
diff --git a/drivers/media/video/stv680.c b/drivers/media/video/stv680.c
deleted file mode 100644
index 5938ad8702ef..000000000000
--- a/drivers/media/video/stv680.c
+++ /dev/null
@@ -1,1565 +0,0 @@
1/*
2 * STV0680 USB Camera Driver, by Kevin Sisson (kjsisson@bellsouth.net)
3 *
4 * Thanks to STMicroelectronics for information on the usb commands, and
5 * to Steve Miller at STM for his help and encouragement while I was
6 * writing this driver.
7 *
8 * This driver is based heavily on the
9 * Endpoints (formerly known as AOX) se401 USB Camera Driver
10 * Copyright (c) 2000 Jeroen B. Vreeken (pe1rxq@amsat.org)
11 *
12 * Still somewhat based on the Linux ov511 driver.
13 *
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the
16 * Free Software Foundation; either version 2 of the License, or (at your
17 * option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * 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 Foundation,
26 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 *
28 * History:
29 * ver 0.1 October, 2001. Initial attempt.
30 *
31 * ver 0.2 November, 2001. Fixed asbility to resize, added brightness
32 * function, made more stable (?)
33 *
34 * ver 0.21 Nov, 2001. Added gamma correction and white balance,
35 * due to Alexander Schwartz. Still trying to
36 * improve stablility. Moved stuff into stv680.h
37 *
38 * ver 0.22 Nov, 2001. Added sharpen function (by Michael Sweet,
39 * mike@easysw.com) from GIMP, also used in pencam.
40 * Simple, fast, good integer math routine.
41 *
42 * ver 0.23 Dec, 2001 (gkh)
43 * Took out sharpen function, ran code through
44 * Lindent, and did other minor tweaks to get
45 * things to work properly with 2.5.1
46 *
47 * ver 0.24 Jan, 2002 (kjs)
48 * Fixed the problem with webcam crashing after
49 * two pictures. Changed the way pic is halved to
50 * improve quality. Got rid of green line around
51 * frame. Fix brightness reset when changing size
52 * bug. Adjusted gamma filters slightly.
53 *
54 * ver 0.25 Jan, 2002 (kjs)
55 * Fixed a bug in which the driver sometimes attempted
56 * to set to a non-supported size. This allowed
57 * gnomemeeting to work.
58 * Fixed proc entry removal bug.
59 */
60
61#include <linux/module.h>
62#include <linux/init.h>
63#include <linux/vmalloc.h>
64#include <linux/slab.h>
65#include <linux/smp_lock.h>
66#include <linux/pagemap.h>
67#include <linux/errno.h>
68#include <linux/videodev.h>
69#include <media/v4l2-common.h>
70#include <media/v4l2-ioctl.h>
71#include <linux/usb.h>
72#include <linux/mutex.h>
73
74#include "stv680.h"
75
76static int video_nr = -1;
77
78static int swapRGB; /* 0 = default for auto select */
79
80/* 0 = default to allow auto select; -1 = swap never, +1 = swap always */
81static int swapRGB_on;
82
83static unsigned int debug;
84
85#define PDEBUG(level, fmt, args...) \
86 do { \
87 if (debug >= level) \
88 printk(KERN_INFO KBUILD_MODNAME " [%s:%d] \n" fmt, \
89 __func__, __LINE__ , ## args); \
90 } while (0)
91
92
93/*
94 * Version Information
95 */
96#define DRIVER_VERSION "v0.25"
97#define DRIVER_AUTHOR "Kevin Sisson <kjsisson@bellsouth.net>"
98#define DRIVER_DESC "STV0680 USB Camera Driver"
99
100MODULE_AUTHOR (DRIVER_AUTHOR);
101MODULE_DESCRIPTION (DRIVER_DESC);
102MODULE_LICENSE ("GPL");
103module_param(debug, int, S_IRUGO | S_IWUSR);
104MODULE_PARM_DESC (debug, "Debug enabled or not");
105module_param(swapRGB_on, int, 0);
106MODULE_PARM_DESC (swapRGB_on, "Red/blue swap: 1=always, 0=auto, -1=never");
107module_param(video_nr, int, 0);
108
109/********************************************************************
110 *
111 * Memory management
112 *
113 * This is a shameless copy from the USB-cpia driver (linux kernel
114 * version 2.3.29 or so, I have no idea what this code actually does ;).
115 * Actually it seems to be a copy of a shameless copy of the bttv-driver.
116 * Or that is a copy of a shameless copy of ... (To the powers: is there
117 * no generic kernel-function to do this sort of stuff?)
118 *
119 * Yes, it was a shameless copy from the bttv-driver. IIRC, Alan says
120 * there will be one, but apparentely not yet -jerdfelt
121 *
122 * So I copied it again for the ov511 driver -claudio
123 *
124 * Same for the se401 driver -Jeroen
125 *
126 * And the STV0680 driver - Kevin
127 ********************************************************************/
128static void *rvmalloc (unsigned long size)
129{
130 void *mem;
131 unsigned long adr;
132
133 size = PAGE_ALIGN(size);
134 mem = vmalloc_32 (size);
135 if (!mem)
136 return NULL;
137
138 memset (mem, 0, size); /* Clear the ram out, no junk to the user */
139 adr = (unsigned long) mem;
140 while (size > 0) {
141 SetPageReserved(vmalloc_to_page((void *)adr));
142 adr += PAGE_SIZE;
143 size -= PAGE_SIZE;
144 }
145 return mem;
146}
147
148static void rvfree (void *mem, unsigned long size)
149{
150 unsigned long adr;
151
152 if (!mem)
153 return;
154
155 adr = (unsigned long) mem;
156 while ((long) size > 0) {
157 ClearPageReserved(vmalloc_to_page((void *)adr));
158 adr += PAGE_SIZE;
159 size -= PAGE_SIZE;
160 }
161 vfree (mem);
162}
163
164
165/*********************************************************************
166 * pencam read/write functions
167 ********************************************************************/
168
169static int stv_sndctrl (int set, struct usb_stv *stv680, unsigned short req, unsigned short value, unsigned char *buffer, int size)
170{
171 int ret = -1;
172
173 switch (set) {
174 case 0: /* 0xc1 */
175 ret = usb_control_msg (stv680->udev,
176 usb_rcvctrlpipe (stv680->udev, 0),
177 req,
178 (USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT),
179 value, 0, buffer, size, PENCAM_TIMEOUT);
180 break;
181
182 case 1: /* 0x41 */
183 ret = usb_control_msg (stv680->udev,
184 usb_sndctrlpipe (stv680->udev, 0),
185 req,
186 (USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT),
187 value, 0, buffer, size, PENCAM_TIMEOUT);
188 break;
189
190 case 2: /* 0x80 */
191 ret = usb_control_msg (stv680->udev,
192 usb_rcvctrlpipe (stv680->udev, 0),
193 req,
194 (USB_DIR_IN | USB_RECIP_DEVICE),
195 value, 0, buffer, size, PENCAM_TIMEOUT);
196 break;
197
198 case 3: /* 0x40 */
199 ret = usb_control_msg (stv680->udev,
200 usb_sndctrlpipe (stv680->udev, 0),
201 req,
202 (USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE),
203 value, 0, buffer, size, PENCAM_TIMEOUT);
204 break;
205
206 }
207 if ((ret < 0) && (req != 0x0a)) {
208 PDEBUG (1, "STV(e): usb_control_msg error %i, request = 0x%x, error = %i", set, req, ret);
209 }
210 return ret;
211}
212
213static int stv_set_config (struct usb_stv *dev, int configuration, int interface, int alternate)
214{
215
216 if (configuration != dev->udev->actconfig->desc.bConfigurationValue
217 || usb_reset_configuration (dev->udev) < 0) {
218 PDEBUG (1, "STV(e): FAILED to reset configuration %i", configuration);
219 return -1;
220 }
221 if (usb_set_interface (dev->udev, interface, alternate) < 0) {
222 PDEBUG (1, "STV(e): FAILED to set alternate interface %i", alternate);
223 return -1;
224 }
225 return 0;
226}
227
228static int stv_stop_video (struct usb_stv *dev)
229{
230 int i;
231 unsigned char *buf;
232
233 buf = kmalloc (40, GFP_KERNEL);
234 if (buf == NULL) {
235 PDEBUG (0, "STV(e): Out of (small buf) memory");
236 return -1;
237 }
238
239 /* this is a high priority command; it stops all lower order commands */
240 if ((i = stv_sndctrl (1, dev, 0x04, 0x0000, buf, 0x0)) < 0) {
241 i = stv_sndctrl (0, dev, 0x80, 0, buf, 0x02); /* Get Last Error; 2 = busy */
242 PDEBUG (1, "STV(i): last error: %i, command = 0x%x", buf[0], buf[1]);
243 } else {
244 PDEBUG (1, "STV(i): Camera reset to idle mode.");
245 }
246
247 if ((i = stv_set_config (dev, 1, 0, 0)) < 0)
248 PDEBUG (1, "STV(e): Reset config during exit failed");
249
250 /* get current mode */
251 buf[0] = 0xf0;
252 if ((i = stv_sndctrl (0, dev, 0x87, 0, buf, 0x08)) != 0x08) /* get mode */
253 PDEBUG (0, "STV(e): Stop_video: problem setting original mode");
254 if (dev->origMode != buf[0]) {
255 memset (buf, 0, 8);
256 buf[0] = (unsigned char) dev->origMode;
257 if ((i = stv_sndctrl (3, dev, 0x07, 0x0100, buf, 0x08)) != 0x08) {
258 PDEBUG (0, "STV(e): Stop_video: Set_Camera_Mode failed");
259 i = -1;
260 }
261 buf[0] = 0xf0;
262 i = stv_sndctrl (0, dev, 0x87, 0, buf, 0x08);
263 if ((i != 0x08) || (buf[0] != dev->origMode)) {
264 PDEBUG (0, "STV(e): camera NOT set to original resolution.");
265 i = -1;
266 } else
267 PDEBUG (0, "STV(i): Camera set to original resolution");
268 }
269 /* origMode */
270 kfree(buf);
271 return i;
272}
273
274static int stv_set_video_mode (struct usb_stv *dev)
275{
276 int i, stop_video = 1;
277 unsigned char *buf;
278
279 buf = kmalloc (40, GFP_KERNEL);
280 if (buf == NULL) {
281 PDEBUG (0, "STV(e): Out of (small buf) memory");
282 return -1;
283 }
284
285 if ((i = stv_set_config (dev, 1, 0, 0)) < 0) {
286 kfree(buf);
287 return i;
288 }
289
290 i = stv_sndctrl (2, dev, 0x06, 0x0100, buf, 0x12);
291 if (!(i > 0) && (buf[8] == 0x53) && (buf[9] == 0x05)) {
292 PDEBUG (1, "STV(e): Could not get descriptor 0100.");
293 goto error;
294 }
295
296 /* set alternate interface 1 */
297 if ((i = stv_set_config (dev, 1, 0, 1)) < 0)
298 goto error;
299
300 if ((i = stv_sndctrl (0, dev, 0x85, 0, buf, 0x10)) != 0x10)
301 goto error;
302 PDEBUG (1, "STV(i): Setting video mode.");
303 /* Switch to Video mode: 0x0100 = VGA (640x480), 0x0000 = CIF (352x288) 0x0300 = QVGA (320x240) */
304 if ((i = stv_sndctrl (1, dev, 0x09, dev->VideoMode, buf, 0x0)) < 0) {
305 stop_video = 0;
306 goto error;
307 }
308 goto exit;
309
310error:
311 kfree(buf);
312 if (stop_video == 1)
313 stv_stop_video (dev);
314 return -1;
315
316exit:
317 kfree(buf);
318 return 0;
319}
320
321static int stv_init (struct usb_stv *stv680)
322{
323 int i = 0;
324 unsigned char *buffer;
325 unsigned long int bufsize;
326
327 buffer = kzalloc (40, GFP_KERNEL);
328 if (buffer == NULL) {
329 PDEBUG (0, "STV(e): Out of (small buf) memory");
330 return -1;
331 }
332 udelay (100);
333
334 /* set config 1, interface 0, alternate 0 */
335 if ((i = stv_set_config (stv680, 1, 0, 0)) < 0) {
336 kfree(buffer);
337 PDEBUG (0, "STV(e): set config 1,0,0 failed");
338 return -1;
339 }
340 /* ping camera to be sure STV0680 is present */
341 if ((i = stv_sndctrl (0, stv680, 0x88, 0x5678, buffer, 0x02)) != 0x02)
342 goto error;
343 if ((buffer[0] != 0x56) || (buffer[1] != 0x78)) {
344 PDEBUG (1, "STV(e): camera ping failed!!");
345 goto error;
346 }
347
348 /* get camera descriptor */
349 if ((i = stv_sndctrl (2, stv680, 0x06, 0x0200, buffer, 0x09)) != 0x09)
350 goto error;
351 i = stv_sndctrl (2, stv680, 0x06, 0x0200, buffer, 0x22);
352 if (!(i >= 0) && (buffer[7] == 0xa0) && (buffer[8] == 0x23)) {
353 PDEBUG (1, "STV(e): Could not get descriptor 0200.");
354 goto error;
355 }
356 if ((i = stv_sndctrl (0, stv680, 0x8a, 0, buffer, 0x02)) != 0x02)
357 goto error;
358 if ((i = stv_sndctrl (0, stv680, 0x8b, 0, buffer, 0x24)) != 0x24)
359 goto error;
360 if ((i = stv_sndctrl (0, stv680, 0x85, 0, buffer, 0x10)) != 0x10)
361 goto error;
362
363 stv680->SupportedModes = buffer[7];
364 i = stv680->SupportedModes;
365 stv680->CIF = 0;
366 stv680->VGA = 0;
367 stv680->QVGA = 0;
368 if (i & 1)
369 stv680->CIF = 1;
370 if (i & 2)
371 stv680->VGA = 1;
372 if (i & 8)
373 stv680->QVGA = 1;
374 if (stv680->SupportedModes == 0) {
375 PDEBUG (0, "STV(e): There are NO supported STV680 modes!!");
376 i = -1;
377 goto error;
378 } else {
379 if (stv680->CIF)
380 PDEBUG (0, "STV(i): CIF is supported");
381 if (stv680->QVGA)
382 PDEBUG (0, "STV(i): QVGA is supported");
383 }
384 /* FW rev, ASIC rev, sensor ID */
385 PDEBUG (1, "STV(i): Firmware rev is %i.%i", buffer[0], buffer[1]);
386 PDEBUG (1, "STV(i): ASIC rev is %i.%i", buffer[2], buffer[3]);
387 PDEBUG (1, "STV(i): Sensor ID is %i", (buffer[4]*16) + (buffer[5]>>4));
388
389 /* set alternate interface 1 */
390 if ((i = stv_set_config (stv680, 1, 0, 1)) < 0)
391 goto error;
392
393 if ((i = stv_sndctrl (0, stv680, 0x85, 0, buffer, 0x10)) != 0x10)
394 goto error;
395 if ((i = stv_sndctrl (0, stv680, 0x8d, 0, buffer, 0x08)) != 0x08)
396 goto error;
397 i = buffer[3];
398 PDEBUG (0, "STV(i): Camera has %i pictures.", i);
399
400 /* get current mode */
401 if ((i = stv_sndctrl (0, stv680, 0x87, 0, buffer, 0x08)) != 0x08)
402 goto error;
403 stv680->origMode = buffer[0]; /* 01 = VGA, 03 = QVGA, 00 = CIF */
404
405 /* This will attemp CIF mode, if supported. If not, set to QVGA */
406 memset (buffer, 0, 8);
407 if (stv680->CIF)
408 buffer[0] = 0x00;
409 else if (stv680->QVGA)
410 buffer[0] = 0x03;
411 if ((i = stv_sndctrl (3, stv680, 0x07, 0x0100, buffer, 0x08)) != 0x08) {
412 PDEBUG (0, "STV(i): Set_Camera_Mode failed");
413 i = -1;
414 goto error;
415 }
416 buffer[0] = 0xf0;
417 stv_sndctrl (0, stv680, 0x87, 0, buffer, 0x08);
418 if (((stv680->CIF == 1) && (buffer[0] != 0x00)) || ((stv680->QVGA == 1) && (buffer[0] != 0x03))) {
419 PDEBUG (0, "STV(e): Error setting camera video mode!");
420 i = -1;
421 goto error;
422 } else {
423 if (buffer[0] == 0) {
424 stv680->VideoMode = 0x0000;
425 PDEBUG (0, "STV(i): Video Mode set to CIF");
426 }
427 if (buffer[0] == 0x03) {
428 stv680->VideoMode = 0x0300;
429 PDEBUG (0, "STV(i): Video Mode set to QVGA");
430 }
431 }
432 if ((i = stv_sndctrl (0, stv680, 0x8f, 0, buffer, 0x10)) != 0x10)
433 goto error;
434 bufsize = (buffer[0] << 24) | (buffer[1] << 16) | (buffer[2] << 8) | (buffer[3]);
435 stv680->cwidth = (buffer[4] << 8) | (buffer[5]); /* ->camera = 322, 356, 644 */
436 stv680->cheight = (buffer[6] << 8) | (buffer[7]); /* ->camera = 242, 292, 484 */
437 stv680->origGain = buffer[12];
438
439 goto exit;
440
441error:
442 i = stv_sndctrl (0, stv680, 0x80, 0, buffer, 0x02); /* Get Last Error */
443 PDEBUG (1, "STV(i): last error: %i, command = 0x%x", buffer[0], buffer[1]);
444 kfree(buffer);
445 return -1;
446
447exit:
448 kfree(buffer);
449
450 /* video = 320x240, 352x288 */
451 if (stv680->CIF == 1) {
452 stv680->maxwidth = 352;
453 stv680->maxheight = 288;
454 stv680->vwidth = 352;
455 stv680->vheight = 288;
456 }
457 if (stv680->QVGA == 1) {
458 stv680->maxwidth = 320;
459 stv680->maxheight = 240;
460 stv680->vwidth = 320;
461 stv680->vheight = 240;
462 }
463
464 stv680->rawbufsize = bufsize; /* must be ./. by 8 */
465 stv680->maxframesize = bufsize * 3; /* RGB size */
466 PDEBUG (2, "STV(i): cwidth = %i, cheight = %i", stv680->cwidth, stv680->cheight);
467 PDEBUG (1, "STV(i): width = %i, height = %i, rawbufsize = %li", stv680->vwidth, stv680->vheight, stv680->rawbufsize);
468
469 /* some default values */
470 stv680->bulk_in_endpointAddr = 0x82;
471 stv680->dropped = 0;
472 stv680->error = 0;
473 stv680->framecount = 0;
474 stv680->readcount = 0;
475 stv680->streaming = 0;
476 /* bright, white, colour, hue, contrast are set by software, not in stv0680 */
477 stv680->brightness = 32767;
478 stv680->chgbright = 0;
479 stv680->whiteness = 0; /* only for greyscale */
480 stv680->colour = 32767;
481 stv680->contrast = 32767;
482 stv680->hue = 32767;
483 stv680->palette = STV_VIDEO_PALETTE;
484 stv680->depth = 24; /* rgb24 bits */
485 if ((swapRGB_on == 0) && (swapRGB == 0))
486 PDEBUG (1, "STV(i): swapRGB is (auto) OFF");
487 else if ((swapRGB_on == 0) && (swapRGB == 1))
488 PDEBUG (1, "STV(i): swapRGB is (auto) ON");
489 else if (swapRGB_on == 1)
490 PDEBUG (1, "STV(i): swapRGB is (forced) ON");
491 else if (swapRGB_on == -1)
492 PDEBUG (1, "STV(i): swapRGB is (forced) OFF");
493
494 if (stv_set_video_mode (stv680) < 0) {
495 PDEBUG (0, "STV(e): Could not set video mode in stv_init");
496 return -1;
497 }
498
499 return 0;
500}
501
502/***************** last of pencam routines *******************/
503
504/****************************************************************************
505 * sysfs
506 ***************************************************************************/
507#define stv680_file(name, variable, field) \
508static ssize_t show_##name(struct device *class_dev, \
509 struct device_attribute *attr, char *buf) \
510{ \
511 struct video_device *vdev = to_video_device(class_dev); \
512 struct usb_stv *stv = video_get_drvdata(vdev); \
513 return sprintf(buf, field, stv->variable); \
514} \
515static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL);
516
517stv680_file(model, camera_name, "%s\n");
518stv680_file(in_use, user, "%d\n");
519stv680_file(streaming, streaming, "%d\n");
520stv680_file(palette, palette, "%i\n");
521stv680_file(frames_total, readcount, "%d\n");
522stv680_file(frames_read, framecount, "%d\n");
523stv680_file(packets_dropped, dropped, "%d\n");
524stv680_file(decoding_errors, error, "%d\n");
525
526static int stv680_create_sysfs_files(struct video_device *vdev)
527{
528 int rc;
529
530 rc = device_create_file(&vdev->dev, &dev_attr_model);
531 if (rc) goto err;
532 rc = device_create_file(&vdev->dev, &dev_attr_in_use);
533 if (rc) goto err_model;
534 rc = device_create_file(&vdev->dev, &dev_attr_streaming);
535 if (rc) goto err_inuse;
536 rc = device_create_file(&vdev->dev, &dev_attr_palette);
537 if (rc) goto err_stream;
538 rc = device_create_file(&vdev->dev, &dev_attr_frames_total);
539 if (rc) goto err_pal;
540 rc = device_create_file(&vdev->dev, &dev_attr_frames_read);
541 if (rc) goto err_framtot;
542 rc = device_create_file(&vdev->dev, &dev_attr_packets_dropped);
543 if (rc) goto err_framread;
544 rc = device_create_file(&vdev->dev, &dev_attr_decoding_errors);
545 if (rc) goto err_dropped;
546
547 return 0;
548
549err_dropped:
550 device_remove_file(&vdev->dev, &dev_attr_packets_dropped);
551err_framread:
552 device_remove_file(&vdev->dev, &dev_attr_frames_read);
553err_framtot:
554 device_remove_file(&vdev->dev, &dev_attr_frames_total);
555err_pal:
556 device_remove_file(&vdev->dev, &dev_attr_palette);
557err_stream:
558 device_remove_file(&vdev->dev, &dev_attr_streaming);
559err_inuse:
560 device_remove_file(&vdev->dev, &dev_attr_in_use);
561err_model:
562 device_remove_file(&vdev->dev, &dev_attr_model);
563err:
564 PDEBUG(0, "STV(e): Could not create sysfs files");
565 return rc;
566}
567
568static void stv680_remove_sysfs_files(struct video_device *vdev)
569{
570 device_remove_file(&vdev->dev, &dev_attr_model);
571 device_remove_file(&vdev->dev, &dev_attr_in_use);
572 device_remove_file(&vdev->dev, &dev_attr_streaming);
573 device_remove_file(&vdev->dev, &dev_attr_palette);
574 device_remove_file(&vdev->dev, &dev_attr_frames_total);
575 device_remove_file(&vdev->dev, &dev_attr_frames_read);
576 device_remove_file(&vdev->dev, &dev_attr_packets_dropped);
577 device_remove_file(&vdev->dev, &dev_attr_decoding_errors);
578}
579
580/********************************************************************
581 * Camera control
582 *******************************************************************/
583
584static int stv680_get_pict (struct usb_stv *stv680, struct video_picture *p)
585{
586 /* This sets values for v4l interface. max/min = 65535/0 */
587
588 p->brightness = stv680->brightness;
589 p->whiteness = stv680->whiteness; /* greyscale */
590 p->colour = stv680->colour;
591 p->contrast = stv680->contrast;
592 p->hue = stv680->hue;
593 p->palette = stv680->palette;
594 p->depth = stv680->depth;
595 return 0;
596}
597
598static int stv680_set_pict (struct usb_stv *stv680, struct video_picture *p)
599{
600 /* See above stv680_get_pict */
601
602 if (p->palette != STV_VIDEO_PALETTE) {
603 PDEBUG (2, "STV(e): Palette set error in _set_pic");
604 return 1;
605 }
606
607 if (stv680->brightness != p->brightness) {
608 stv680->chgbright = 1;
609 stv680->brightness = p->brightness;
610 }
611
612 stv680->whiteness = p->whiteness; /* greyscale */
613 stv680->colour = p->colour;
614 stv680->contrast = p->contrast;
615 stv680->hue = p->hue;
616 stv680->palette = p->palette;
617 stv680->depth = p->depth;
618
619 return 0;
620}
621
622static void stv680_video_irq (struct urb *urb)
623{
624 struct usb_stv *stv680 = urb->context;
625 int length = urb->actual_length;
626
627 if (length < stv680->rawbufsize)
628 PDEBUG (2, "STV(i): Lost data in transfer: exp %li, got %i", stv680->rawbufsize, length);
629
630 /* ohoh... */
631 if (!stv680->streaming)
632 return;
633
634 if (!stv680->udev) {
635 PDEBUG (0, "STV(e): device vapourished in video_irq");
636 return;
637 }
638
639 /* 0 sized packets happen if we are to fast, but sometimes the camera
640 keeps sending them forever...
641 */
642 if (length && !urb->status) {
643 stv680->nullpackets = 0;
644 switch (stv680->scratch[stv680->scratch_next].state) {
645 case BUFFER_READY:
646 case BUFFER_BUSY:
647 stv680->dropped++;
648 break;
649
650 case BUFFER_UNUSED:
651 memcpy (stv680->scratch[stv680->scratch_next].data,
652 (unsigned char *) urb->transfer_buffer, length);
653 stv680->scratch[stv680->scratch_next].state = BUFFER_READY;
654 stv680->scratch[stv680->scratch_next].length = length;
655 if (waitqueue_active (&stv680->wq)) {
656 wake_up_interruptible (&stv680->wq);
657 }
658 stv680->scratch_overflow = 0;
659 stv680->scratch_next++;
660 if (stv680->scratch_next >= STV680_NUMSCRATCH)
661 stv680->scratch_next = 0;
662 break;
663 } /* switch */
664 } else {
665 stv680->nullpackets++;
666 if (stv680->nullpackets > STV680_MAX_NULLPACKETS) {
667 if (waitqueue_active (&stv680->wq)) {
668 wake_up_interruptible (&stv680->wq);
669 }
670 }
671 } /* if - else */
672
673 /* Resubmit urb for new data */
674 urb->status = 0;
675 urb->dev = stv680->udev;
676 if (usb_submit_urb (urb, GFP_ATOMIC))
677 PDEBUG (0, "STV(e): urb burned down in video irq");
678 return;
679} /* _video_irq */
680
681static int stv680_start_stream (struct usb_stv *stv680)
682{
683 struct urb *urb;
684 int err = 0, i;
685
686 stv680->streaming = 1;
687
688 /* Do some memory allocation */
689 for (i = 0; i < STV680_NUMFRAMES; i++) {
690 stv680->frame[i].data = stv680->fbuf + i * stv680->maxframesize;
691 stv680->frame[i].curpix = 0;
692 }
693 /* packet size = 4096 */
694 for (i = 0; i < STV680_NUMSBUF; i++) {
695 stv680->sbuf[i].data = kmalloc (stv680->rawbufsize, GFP_KERNEL);
696 if (stv680->sbuf[i].data == NULL) {
697 PDEBUG (0, "STV(e): Could not kmalloc raw data buffer %i", i);
698 goto nomem_err;
699 }
700 }
701
702 stv680->scratch_next = 0;
703 stv680->scratch_use = 0;
704 stv680->scratch_overflow = 0;
705 for (i = 0; i < STV680_NUMSCRATCH; i++) {
706 stv680->scratch[i].data = kmalloc (stv680->rawbufsize, GFP_KERNEL);
707 if (stv680->scratch[i].data == NULL) {
708 PDEBUG (0, "STV(e): Could not kmalloc raw scratch buffer %i", i);
709 goto nomem_err;
710 }
711 stv680->scratch[i].state = BUFFER_UNUSED;
712 }
713
714 for (i = 0; i < STV680_NUMSBUF; i++) {
715 urb = usb_alloc_urb (0, GFP_KERNEL);
716 if (!urb)
717 goto nomem_err;
718
719 /* sbuf is urb->transfer_buffer, later gets memcpyed to scratch */
720 usb_fill_bulk_urb (urb, stv680->udev,
721 usb_rcvbulkpipe (stv680->udev, stv680->bulk_in_endpointAddr),
722 stv680->sbuf[i].data, stv680->rawbufsize,
723 stv680_video_irq, stv680);
724 stv680->urb[i] = urb;
725 err = usb_submit_urb (stv680->urb[i], GFP_KERNEL);
726 if (err) {
727 PDEBUG (0, "STV(e): urb burned down with err "
728 "%d in start stream %d", err, i);
729 goto nomem_err;
730 }
731 } /* i STV680_NUMSBUF */
732
733 stv680->framecount = 0;
734 return 0;
735
736 nomem_err:
737 for (i = 0; i < STV680_NUMSBUF; i++) {
738 usb_kill_urb(stv680->urb[i]);
739 usb_free_urb(stv680->urb[i]);
740 stv680->urb[i] = NULL;
741 kfree(stv680->sbuf[i].data);
742 stv680->sbuf[i].data = NULL;
743 }
744 /* used in irq, free only as all URBs are dead */
745 for (i = 0; i < STV680_NUMSCRATCH; i++) {
746 kfree(stv680->scratch[i].data);
747 stv680->scratch[i].data = NULL;
748 }
749 return -ENOMEM;
750
751}
752
753static int stv680_stop_stream (struct usb_stv *stv680)
754{
755 int i;
756
757 if (!stv680->streaming || !stv680->udev)
758 return 1;
759
760 stv680->streaming = 0;
761
762 for (i = 0; i < STV680_NUMSBUF; i++)
763 if (stv680->urb[i]) {
764 usb_kill_urb (stv680->urb[i]);
765 usb_free_urb (stv680->urb[i]);
766 stv680->urb[i] = NULL;
767 kfree(stv680->sbuf[i].data);
768 }
769 for (i = 0; i < STV680_NUMSCRATCH; i++) {
770 kfree(stv680->scratch[i].data);
771 stv680->scratch[i].data = NULL;
772 }
773
774 return 0;
775}
776
777static int stv680_set_size (struct usb_stv *stv680, int width, int height)
778{
779 int wasstreaming = stv680->streaming;
780
781 /* Check to see if we need to change */
782 if ((stv680->vwidth == width) && (stv680->vheight == height))
783 return 0;
784
785 PDEBUG (1, "STV(i): size request for %i x %i", width, height);
786 /* Check for a valid mode */
787 if ((!width || !height) || ((width & 1) || (height & 1))) {
788 PDEBUG (1, "STV(e): set_size error: request: v.width = %i, v.height = %i actual: stv.width = %i, stv.height = %i", width, height, stv680->vwidth, stv680->vheight);
789 return 1;
790 }
791
792 if ((width < (stv680->maxwidth / 2)) || (height < (stv680->maxheight / 2))) {
793 width = stv680->maxwidth / 2;
794 height = stv680->maxheight / 2;
795 } else if ((width >= 158) && (width <= 166) && (stv680->QVGA == 1)) {
796 width = 160;
797 height = 120;
798 } else if ((width >= 172) && (width <= 180) && (stv680->CIF == 1)) {
799 width = 176;
800 height = 144;
801 } else if ((width >= 318) && (width <= 350) && (stv680->QVGA == 1)) {
802 width = 320;
803 height = 240;
804 } else if ((width >= 350) && (width <= 358) && (stv680->CIF == 1)) {
805 width = 352;
806 height = 288;
807 } else {
808 PDEBUG (1, "STV(e): request for non-supported size: request: v.width = %i, v.height = %i actual: stv.width = %i, stv.height = %i", width, height, stv680->vwidth, stv680->vheight);
809 return 1;
810 }
811
812 /* Stop a current stream and start it again at the new size */
813 if (wasstreaming)
814 stv680_stop_stream (stv680);
815 stv680->vwidth = width;
816 stv680->vheight = height;
817 PDEBUG (1, "STV(i): size set to %i x %i", stv680->vwidth, stv680->vheight);
818 if (wasstreaming)
819 stv680_start_stream (stv680);
820
821 return 0;
822}
823
824/**********************************************************************
825 * Video Decoding
826 **********************************************************************/
827
828/******* routines from the pencam program; hey, they work! ********/
829
830/*
831 * STV0680 Vision Camera Chipset Driver
832 * Copyright (C) 2000 Adam Harrison <adam@antispin.org>
833*/
834
835#define RED 0
836#define GREEN 1
837#define BLUE 2
838#define AD(x, y, w) (((y)*(w)+(x))*3)
839
840static void bayer_unshuffle (struct usb_stv *stv680, struct stv680_scratch *buffer)
841{
842 int x, y, i;
843 int w = stv680->cwidth;
844 int vw = stv680->cwidth, vh = stv680->cheight;
845 unsigned int p = 0;
846 int colour = 0, bayer = 0;
847 unsigned char *raw = buffer->data;
848 struct stv680_frame *frame = &stv680->frame[stv680->curframe];
849 unsigned char *output = frame->data;
850 unsigned char *temp = frame->data;
851 int offset = buffer->offset;
852
853 if (frame->curpix == 0) {
854 if (frame->grabstate == FRAME_READY) {
855 frame->grabstate = FRAME_GRABBING;
856 }
857 }
858 if (offset != frame->curpix) { /* Regard frame as lost :( */
859 frame->curpix = 0;
860 stv680->error++;
861 return;
862 }
863
864 if ((stv680->vwidth == 320) || (stv680->vwidth == 160)) {
865 vw = 320;
866 vh = 240;
867 }
868 if ((stv680->vwidth == 352) || (stv680->vwidth == 176)) {
869 vw = 352;
870 vh = 288;
871 }
872
873 memset (output, 0, 3 * vw * vh); /* clear output matrix. */
874
875 for (y = 0; y < vh; y++) {
876 for (x = 0; x < vw; x++) {
877 if (x & 1)
878 p = *(raw + y * w + (x >> 1));
879 else
880 p = *(raw + y * w + (x >> 1) + (w >> 1));
881
882 if (y & 1)
883 bayer = 2;
884 else
885 bayer = 0;
886 if (x & 1)
887 bayer++;
888
889 switch (bayer) {
890 case 0:
891 case 3:
892 colour = 1;
893 break;
894 case 1:
895 colour = 0;
896 break;
897 case 2:
898 colour = 2;
899 break;
900 }
901 i = (y * vw + x) * 3;
902 *(output + i + colour) = (unsigned char) p;
903 } /* for x */
904
905 } /* for y */
906
907 /****** gamma correction plus hardcoded white balance */
908 /* Thanks to Alexander Schwartx <alexander.schwartx@gmx.net> for this code.
909 Correction values red[], green[], blue[], are generated by
910 (pow(i/256.0, GAMMA)*255.0)*white balanceRGB where GAMMA=0.55, 1<i<255.
911 White balance (RGB)= 1.0, 1.17, 1.48. Values are calculated as double float and
912 converted to unsigned char. Values are in stv680.h */
913
914 for (y = 0; y < vh; y++) {
915 for (x = 0; x < vw; x++) {
916 i = (y * vw + x) * 3;
917 *(output + i) = red[*(output + i)];
918 *(output + i + 1) = green[*(output + i + 1)];
919 *(output + i + 2) = blue[*(output + i + 2)];
920 }
921 }
922
923 /****** bayer demosaic ******/
924 for (y = 1; y < (vh - 1); y++) {
925 for (x = 1; x < (vw - 1); x++) { /* work out pixel type */
926 if (y & 1)
927 bayer = 0;
928 else
929 bayer = 2;
930 if (!(x & 1))
931 bayer++;
932
933 switch (bayer) {
934 case 0: /* green. blue lr, red tb */
935 *(output + AD (x, y, vw) + BLUE) = ((int) *(output + AD (x - 1, y, vw) + BLUE) + (int) *(output + AD (x + 1, y, vw) + BLUE)) >> 1;
936 *(output + AD (x, y, vw) + RED) = ((int) *(output + AD (x, y - 1, vw) + RED) + (int) *(output + AD (x, y + 1, vw) + RED)) >> 1;
937 break;
938
939 case 1: /* blue. green lrtb, red diagonals */
940 *(output + AD (x, y, vw) + GREEN) = ((int) *(output + AD (x - 1, y, vw) + GREEN) + (int) *(output + AD (x + 1, y, vw) + GREEN) + (int) *(output + AD (x, y - 1, vw) + GREEN) + (int) *(output + AD (x, y + 1, vw) + GREEN)) >> 2;
941 *(output + AD (x, y, vw) + RED) = ((int) *(output + AD (x - 1, y - 1, vw) + RED) + (int) *(output + AD (x - 1, y + 1, vw) + RED) + (int) *(output + AD (x + 1, y - 1, vw) + RED) + (int) *(output + AD (x + 1, y + 1, vw) + RED)) >> 2;
942 break;
943
944 case 2: /* red. green lrtb, blue diagonals */
945 *(output + AD (x, y, vw) + GREEN) = ((int) *(output + AD (x - 1, y, vw) + GREEN) + (int) *(output + AD (x + 1, y, vw) + GREEN) + (int) *(output + AD (x, y - 1, vw) + GREEN) + (int) *(output + AD (x, y + 1, vw) + GREEN)) >> 2;
946 *(output + AD (x, y, vw) + BLUE) = ((int) *(output + AD (x - 1, y - 1, vw) + BLUE) + (int) *(output + AD (x + 1, y - 1, vw) + BLUE) + (int) *(output + AD (x - 1, y + 1, vw) + BLUE) + (int) *(output + AD (x + 1, y + 1, vw) + BLUE)) >> 2;
947 break;
948
949 case 3: /* green. red lr, blue tb */
950 *(output + AD (x, y, vw) + RED) = ((int) *(output + AD (x - 1, y, vw) + RED) + (int) *(output + AD (x + 1, y, vw) + RED)) >> 1;
951 *(output + AD (x, y, vw) + BLUE) = ((int) *(output + AD (x, y - 1, vw) + BLUE) + (int) *(output + AD (x, y + 1, vw) + BLUE)) >> 1;
952 break;
953 } /* switch */
954 } /* for x */
955 } /* for y - end demosaic */
956
957 /* fix top and bottom row, left and right side */
958 i = vw * 3;
959 memcpy (output, (output + i), i);
960 memcpy ((output + (vh * i)), (output + ((vh - 1) * i)), i);
961 for (y = 0; y < vh; y++) {
962 i = y * vw * 3;
963 memcpy ((output + i), (output + i + 3), 3);
964 memcpy ((output + i + (vw * 3)), (output + i + (vw - 1) * 3), 3);
965 }
966
967 /* process all raw data, then trim to size if necessary */
968 if ((stv680->vwidth == 160) || (stv680->vwidth == 176)) {
969 i = 0;
970 for (y = 0; y < vh; y++) {
971 if (!(y & 1)) {
972 for (x = 0; x < vw; x++) {
973 p = (y * vw + x) * 3;
974 if (!(x & 1)) {
975 *(output + i) = *(output + p);
976 *(output + i + 1) = *(output + p + 1);
977 *(output + i + 2) = *(output + p + 2);
978 i += 3;
979 }
980 } /* for x */
981 }
982 } /* for y */
983 }
984 /* reset to proper width */
985 if ((stv680->vwidth == 160)) {
986 vw = 160;
987 vh = 120;
988 }
989 if ((stv680->vwidth == 176)) {
990 vw = 176;
991 vh = 144;
992 }
993
994 /* output is RGB; some programs want BGR */
995 /* swapRGB_on=0 -> program decides; swapRGB_on=1, always swap */
996 /* swapRGB_on=-1, never swap */
997 if (((swapRGB == 1) && (swapRGB_on != -1)) || (swapRGB_on == 1)) {
998 for (y = 0; y < vh; y++) {
999 for (x = 0; x < vw; x++) {
1000 i = (y * vw + x) * 3;
1001 *(temp) = *(output + i);
1002 *(output + i) = *(output + i + 2);
1003 *(output + i + 2) = *(temp);
1004 }
1005 }
1006 }
1007 /* brightness */
1008 if (stv680->chgbright == 1) {
1009 if (stv680->brightness >= 32767) {
1010 p = (stv680->brightness - 32767) / 256;
1011 for (x = 0; x < (vw * vh * 3); x++) {
1012 if ((*(output + x) + (unsigned char) p) > 255)
1013 *(output + x) = 255;
1014 else
1015 *(output + x) += (unsigned char) p;
1016 } /* for */
1017 } else {
1018 p = (32767 - stv680->brightness) / 256;
1019 for (x = 0; x < (vw * vh * 3); x++) {
1020 if ((unsigned char) p > *(output + x))
1021 *(output + x) = 0;
1022 else
1023 *(output + x) -= (unsigned char) p;
1024 } /* for */
1025 } /* else */
1026 }
1027 /* if */
1028 frame->curpix = 0;
1029 frame->curlinepix = 0;
1030 frame->grabstate = FRAME_DONE;
1031 stv680->framecount++;
1032 stv680->readcount++;
1033 if (stv680->frame[(stv680->curframe + 1) & (STV680_NUMFRAMES - 1)].grabstate == FRAME_READY) {
1034 stv680->curframe = (stv680->curframe + 1) & (STV680_NUMFRAMES - 1);
1035 }
1036
1037} /* bayer_unshuffle */
1038
1039/******* end routines from the pencam program *********/
1040
1041static int stv680_newframe (struct usb_stv *stv680, int framenr)
1042{
1043 int errors = 0;
1044
1045 while (stv680->streaming && (stv680->frame[framenr].grabstate == FRAME_READY || stv680->frame[framenr].grabstate == FRAME_GRABBING)) {
1046 if (!stv680->frame[framenr].curpix) {
1047 errors++;
1048 }
1049 wait_event_interruptible (stv680->wq, (stv680->scratch[stv680->scratch_use].state == BUFFER_READY));
1050
1051 if (stv680->nullpackets > STV680_MAX_NULLPACKETS) {
1052 stv680->nullpackets = 0;
1053 PDEBUG (2, "STV(i): too many null length packets, restarting capture");
1054 stv680_stop_stream (stv680);
1055 stv680_start_stream (stv680);
1056 } else {
1057 if (stv680->scratch[stv680->scratch_use].state != BUFFER_READY) {
1058 stv680->frame[framenr].grabstate = FRAME_ERROR;
1059 PDEBUG (2, "STV(e): FRAME_ERROR in _newframe");
1060 return -EIO;
1061 }
1062 stv680->scratch[stv680->scratch_use].state = BUFFER_BUSY;
1063
1064 bayer_unshuffle (stv680, &stv680->scratch[stv680->scratch_use]);
1065
1066 stv680->scratch[stv680->scratch_use].state = BUFFER_UNUSED;
1067 stv680->scratch_use++;
1068 if (stv680->scratch_use >= STV680_NUMSCRATCH)
1069 stv680->scratch_use = 0;
1070 if (errors > STV680_MAX_ERRORS) {
1071 errors = 0;
1072 PDEBUG (2, "STV(i): too many errors, restarting capture");
1073 stv680_stop_stream (stv680);
1074 stv680_start_stream (stv680);
1075 }
1076 } /* else */
1077 } /* while */
1078 return 0;
1079}
1080
1081/*********************************************************************
1082 * Video4Linux
1083 *********************************************************************/
1084
1085static int stv_open(struct file *file)
1086{
1087 struct video_device *dev = video_devdata(file);
1088 struct usb_stv *stv680 = video_get_drvdata(dev);
1089 int err = 0;
1090
1091 /* we are called with the BKL held */
1092 lock_kernel();
1093 stv680->user = 1;
1094 err = stv_init (stv680); /* main initialization routine for camera */
1095
1096 if (err >= 0) {
1097 stv680->fbuf = rvmalloc (stv680->maxframesize * STV680_NUMFRAMES);
1098 if (!stv680->fbuf) {
1099 PDEBUG (0, "STV(e): Could not rvmalloc frame bufer");
1100 err = -ENOMEM;
1101 }
1102 file->private_data = dev;
1103 }
1104 if (err)
1105 stv680->user = 0;
1106 unlock_kernel();
1107
1108 return err;
1109}
1110
1111static int stv_close(struct file *file)
1112{
1113 struct video_device *dev = file->private_data;
1114 struct usb_stv *stv680 = video_get_drvdata(dev);
1115 int i;
1116
1117 for (i = 0; i < STV680_NUMFRAMES; i++)
1118 stv680->frame[i].grabstate = FRAME_UNUSED;
1119 if (stv680->streaming)
1120 stv680_stop_stream (stv680);
1121
1122 if ((i = stv_stop_video (stv680)) < 0)
1123 PDEBUG (1, "STV(e): stop_video failed in stv_close");
1124
1125 rvfree (stv680->fbuf, stv680->maxframesize * STV680_NUMFRAMES);
1126 stv680->user = 0;
1127
1128 if (stv680->removed) {
1129 kfree(stv680);
1130 stv680 = NULL;
1131 PDEBUG (0, "STV(i): device unregistered");
1132 }
1133 file->private_data = NULL;
1134 return 0;
1135}
1136
1137static long stv680_do_ioctl(struct file *file, unsigned int cmd, void *arg)
1138{
1139 struct video_device *vdev = file->private_data;
1140 struct usb_stv *stv680 = video_get_drvdata(vdev);
1141
1142 if (!stv680->udev)
1143 return -EIO;
1144
1145 switch (cmd) {
1146 case VIDIOCGCAP:{
1147 struct video_capability *b = arg;
1148
1149 strcpy (b->name, stv680->camera_name);
1150 b->type = VID_TYPE_CAPTURE;
1151 b->channels = 1;
1152 b->audios = 0;
1153 b->maxwidth = stv680->maxwidth;
1154 b->maxheight = stv680->maxheight;
1155 b->minwidth = stv680->maxwidth / 2;
1156 b->minheight = stv680->maxheight / 2;
1157 return 0;
1158 }
1159 case VIDIOCGCHAN:{
1160 struct video_channel *v = arg;
1161
1162 if (v->channel != 0)
1163 return -EINVAL;
1164 v->flags = 0;
1165 v->tuners = 0;
1166 v->type = VIDEO_TYPE_CAMERA;
1167 strcpy (v->name, "STV Camera");
1168 return 0;
1169 }
1170 case VIDIOCSCHAN:{
1171 struct video_channel *v = arg;
1172 if (v->channel != 0)
1173 return -EINVAL;
1174 return 0;
1175 }
1176 case VIDIOCGPICT:{
1177 struct video_picture *p = arg;
1178
1179 stv680_get_pict (stv680, p);
1180 return 0;
1181 }
1182 case VIDIOCSPICT:{
1183 struct video_picture *p = arg;
1184
1185 if (stv680_set_pict (stv680, p))
1186 return -EINVAL;
1187 return 0;
1188 }
1189 case VIDIOCSWIN:{
1190 struct video_window *vw = arg;
1191
1192 if (vw->flags)
1193 return -EINVAL;
1194 if (vw->clipcount)
1195 return -EINVAL;
1196 if (vw->width != stv680->vwidth) {
1197 if (stv680_set_size (stv680, vw->width, vw->height)) {
1198 PDEBUG (2, "STV(e): failed (from user) set size in VIDIOCSWIN");
1199 return -EINVAL;
1200 }
1201 }
1202 return 0;
1203 }
1204 case VIDIOCGWIN:{
1205 struct video_window *vw = arg;
1206
1207 vw->x = 0; /* FIXME */
1208 vw->y = 0;
1209 vw->chromakey = 0;
1210 vw->flags = 0;
1211 vw->clipcount = 0;
1212 vw->width = stv680->vwidth;
1213 vw->height = stv680->vheight;
1214 return 0;
1215 }
1216 case VIDIOCGMBUF:{
1217 struct video_mbuf *vm = arg;
1218 int i;
1219
1220 memset (vm, 0, sizeof (*vm));
1221 vm->size = STV680_NUMFRAMES * stv680->maxframesize;
1222 vm->frames = STV680_NUMFRAMES;
1223 for (i = 0; i < STV680_NUMFRAMES; i++)
1224 vm->offsets[i] = stv680->maxframesize * i;
1225 return 0;
1226 }
1227 case VIDIOCMCAPTURE:{
1228 struct video_mmap *vm = arg;
1229
1230 if (vm->format != STV_VIDEO_PALETTE) {
1231 PDEBUG (2, "STV(i): VIDIOCMCAPTURE vm.format (%i) != VIDEO_PALETTE (%i)",
1232 vm->format, STV_VIDEO_PALETTE);
1233 if ((vm->format == 3) && (swapRGB_on == 0)) {
1234 PDEBUG (2, "STV(i): VIDIOCMCAPTURE swapRGB is (auto) ON");
1235 /* this may fix those apps (e.g., xawtv) that want BGR */
1236 swapRGB = 1;
1237 }
1238 return -EINVAL;
1239 }
1240 if (vm->frame >= STV680_NUMFRAMES) {
1241 PDEBUG (2, "STV(e): VIDIOCMCAPTURE vm.frame > NUMFRAMES");
1242 return -EINVAL;
1243 }
1244 if ((stv680->frame[vm->frame].grabstate == FRAME_ERROR)
1245 || (stv680->frame[vm->frame].grabstate == FRAME_GRABBING)) {
1246 PDEBUG (2, "STV(e): VIDIOCMCAPTURE grabstate (%i) error",
1247 stv680->frame[vm->frame].grabstate);
1248 return -EBUSY;
1249 }
1250 /* Is this according to the v4l spec??? */
1251 if (stv680->vwidth != vm->width) {
1252 if (stv680_set_size (stv680, vm->width, vm->height)) {
1253 PDEBUG (2, "STV(e): VIDIOCMCAPTURE set_size failed");
1254 return -EINVAL;
1255 }
1256 }
1257 stv680->frame[vm->frame].grabstate = FRAME_READY;
1258
1259 if (!stv680->streaming)
1260 stv680_start_stream (stv680);
1261
1262 return 0;
1263 }
1264 case VIDIOCSYNC:{
1265 int *frame = arg;
1266 int ret = 0;
1267
1268 if (*frame < 0 || *frame >= STV680_NUMFRAMES) {
1269 PDEBUG (2, "STV(e): Bad frame # in VIDIOCSYNC");
1270 return -EINVAL;
1271 }
1272 ret = stv680_newframe (stv680, *frame);
1273 stv680->frame[*frame].grabstate = FRAME_UNUSED;
1274 return ret;
1275 }
1276 case VIDIOCGFBUF:{
1277 struct video_buffer *vb = arg;
1278
1279 memset (vb, 0, sizeof (*vb));
1280 return 0;
1281 }
1282 case VIDIOCKEY:
1283 return 0;
1284 case VIDIOCCAPTURE:
1285 {
1286 PDEBUG (2, "STV(e): VIDIOCCAPTURE failed");
1287 return -EINVAL;
1288 }
1289 case VIDIOCSFBUF:
1290 case VIDIOCGTUNER:
1291 case VIDIOCSTUNER:
1292 case VIDIOCGFREQ:
1293 case VIDIOCSFREQ:
1294 case VIDIOCGAUDIO:
1295 case VIDIOCSAUDIO:
1296 return -EINVAL;
1297 default:
1298 return -ENOIOCTLCMD;
1299 } /* end switch */
1300
1301 return 0;
1302}
1303
1304static long stv680_ioctl(struct file *file,
1305 unsigned int cmd, unsigned long arg)
1306{
1307 return video_usercopy(file, cmd, arg, stv680_do_ioctl);
1308}
1309
1310static int stv680_mmap (struct file *file, struct vm_area_struct *vma)
1311{
1312 struct video_device *dev = file->private_data;
1313 struct usb_stv *stv680 = video_get_drvdata(dev);
1314 unsigned long start = vma->vm_start;
1315 unsigned long size = vma->vm_end-vma->vm_start;
1316 unsigned long page, pos;
1317
1318 mutex_lock(&stv680->lock);
1319
1320 if (stv680->udev == NULL) {
1321 mutex_unlock(&stv680->lock);
1322 return -EIO;
1323 }
1324 if (size > (((STV680_NUMFRAMES * stv680->maxframesize) + PAGE_SIZE - 1)
1325 & ~(PAGE_SIZE - 1))) {
1326 mutex_unlock(&stv680->lock);
1327 return -EINVAL;
1328 }
1329 pos = (unsigned long) stv680->fbuf;
1330 while (size > 0) {
1331 page = vmalloc_to_pfn((void *)pos);
1332 if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED)) {
1333 mutex_unlock(&stv680->lock);
1334 return -EAGAIN;
1335 }
1336 start += PAGE_SIZE;
1337 pos += PAGE_SIZE;
1338 if (size > PAGE_SIZE)
1339 size -= PAGE_SIZE;
1340 else
1341 size = 0;
1342 }
1343 mutex_unlock(&stv680->lock);
1344
1345 return 0;
1346}
1347
1348static ssize_t stv680_read (struct file *file, char __user *buf,
1349 size_t count, loff_t *ppos)
1350{
1351 struct video_device *dev = file->private_data;
1352 unsigned long int realcount = count;
1353 int ret = 0;
1354 struct usb_stv *stv680 = video_get_drvdata(dev);
1355 unsigned long int i;
1356
1357 if (STV680_NUMFRAMES != 2) {
1358 PDEBUG (0, "STV(e): STV680_NUMFRAMES needs to be 2!");
1359 return -1;
1360 }
1361 if (stv680->udev == NULL)
1362 return -EIO;
1363 if (realcount > (stv680->vwidth * stv680->vheight * 3))
1364 realcount = stv680->vwidth * stv680->vheight * 3;
1365
1366 /* Shouldn't happen: */
1367 if (stv680->frame[0].grabstate == FRAME_GRABBING) {
1368 PDEBUG (2, "STV(e): FRAME_GRABBING in stv680_read");
1369 return -EBUSY;
1370 }
1371 stv680->frame[0].grabstate = FRAME_READY;
1372 stv680->frame[1].grabstate = FRAME_UNUSED;
1373 stv680->curframe = 0;
1374
1375 if (!stv680->streaming)
1376 stv680_start_stream (stv680);
1377
1378 if (!stv680->streaming) {
1379 ret = stv680_newframe (stv680, 0); /* ret should = 0 */
1380 }
1381
1382 ret = stv680_newframe (stv680, 0);
1383
1384 if (!ret) {
1385 if ((i = copy_to_user (buf, stv680->frame[0].data, realcount)) != 0) {
1386 PDEBUG (2, "STV(e): copy_to_user frame 0 failed, ret count = %li", i);
1387 return -EFAULT;
1388 }
1389 } else {
1390 realcount = ret;
1391 }
1392 stv680->frame[0].grabstate = FRAME_UNUSED;
1393 return realcount;
1394} /* stv680_read */
1395
1396static const struct v4l2_file_operations stv680_fops = {
1397 .owner = THIS_MODULE,
1398 .open = stv_open,
1399 .release = stv_close,
1400 .read = stv680_read,
1401 .mmap = stv680_mmap,
1402 .ioctl = stv680_ioctl,
1403};
1404static struct video_device stv680_template = {
1405 .name = "STV0680 USB camera",
1406 .fops = &stv680_fops,
1407 .release = video_device_release,
1408};
1409
1410static int stv680_probe (struct usb_interface *intf, const struct usb_device_id *id)
1411{
1412 struct usb_device *dev = interface_to_usbdev(intf);
1413 struct usb_host_interface *interface;
1414 struct usb_stv *stv680 = NULL;
1415 char *camera_name = NULL;
1416 int retval = 0;
1417
1418 /* We don't handle multi-config cameras */
1419 if (dev->descriptor.bNumConfigurations != 1) {
1420 PDEBUG (0, "STV(e): Number of Configurations != 1");
1421 return -ENODEV;
1422 }
1423
1424 interface = &intf->altsetting[0];
1425 /* Is it a STV680? */
1426 if ((le16_to_cpu(dev->descriptor.idVendor) == USB_PENCAM_VENDOR_ID) &&
1427 (le16_to_cpu(dev->descriptor.idProduct) == USB_PENCAM_PRODUCT_ID)) {
1428 camera_name = "STV0680";
1429 PDEBUG (0, "STV(i): STV0680 camera found.");
1430 } else if ((le16_to_cpu(dev->descriptor.idVendor) == USB_CREATIVEGOMINI_VENDOR_ID) &&
1431 (le16_to_cpu(dev->descriptor.idProduct) == USB_CREATIVEGOMINI_PRODUCT_ID)) {
1432 camera_name = "Creative WebCam Go Mini";
1433 PDEBUG (0, "STV(i): Creative WebCam Go Mini found.");
1434 } else {
1435 PDEBUG (0, "STV(e): Vendor/Product ID do not match STV0680 or Creative WebCam Go Mini values.");
1436 PDEBUG (0, "STV(e): Check that the STV0680 or Creative WebCam Go Mini camera is connected to the computer.");
1437 retval = -ENODEV;
1438 goto error;
1439 }
1440 /* We found one */
1441 if ((stv680 = kzalloc (sizeof (*stv680), GFP_KERNEL)) == NULL) {
1442 PDEBUG (0, "STV(e): couldn't kmalloc stv680 struct.");
1443 retval = -ENOMEM;
1444 goto error;
1445 }
1446
1447 stv680->udev = dev;
1448 stv680->camera_name = camera_name;
1449
1450 stv680->vdev = video_device_alloc();
1451 if (!stv680->vdev) {
1452 retval = -ENOMEM;
1453 goto error;
1454 }
1455 memcpy(stv680->vdev, &stv680_template, sizeof(stv680_template));
1456 stv680->vdev->parent = &intf->dev;
1457 video_set_drvdata(stv680->vdev, stv680);
1458
1459 memcpy (stv680->vdev->name, stv680->camera_name, strlen (stv680->camera_name));
1460 init_waitqueue_head (&stv680->wq);
1461 mutex_init (&stv680->lock);
1462 wmb ();
1463
1464 if (video_register_device(stv680->vdev, VFL_TYPE_GRABBER, video_nr) < 0) {
1465 PDEBUG (0, "STV(e): video_register_device failed");
1466 retval = -EIO;
1467 goto error_vdev;
1468 }
1469 PDEBUG(0, "STV(i): registered new video device: %s",
1470 video_device_node_name(stv680->vdev));
1471
1472 usb_set_intfdata (intf, stv680);
1473 retval = stv680_create_sysfs_files(stv680->vdev);
1474 if (retval)
1475 goto error_unreg;
1476 return 0;
1477
1478error_unreg:
1479 video_unregister_device(stv680->vdev);
1480error_vdev:
1481 video_device_release(stv680->vdev);
1482error:
1483 kfree(stv680);
1484 return retval;
1485}
1486
1487static inline void usb_stv680_remove_disconnected (struct usb_stv *stv680)
1488{
1489 int i;
1490
1491 stv680->udev = NULL;
1492 stv680->frame[0].grabstate = FRAME_ERROR;
1493 stv680->frame[1].grabstate = FRAME_ERROR;
1494 stv680->streaming = 0;
1495
1496 wake_up_interruptible (&stv680->wq);
1497
1498 for (i = 0; i < STV680_NUMSBUF; i++)
1499 if (stv680->urb[i]) {
1500 usb_kill_urb (stv680->urb[i]);
1501 usb_free_urb (stv680->urb[i]);
1502 stv680->urb[i] = NULL;
1503 kfree(stv680->sbuf[i].data);
1504 }
1505 for (i = 0; i < STV680_NUMSCRATCH; i++)
1506 kfree(stv680->scratch[i].data);
1507 PDEBUG (0, "STV(i): %s disconnected", stv680->camera_name);
1508
1509 /* Free the memory */
1510 kfree(stv680);
1511}
1512
1513static void stv680_disconnect (struct usb_interface *intf)
1514{
1515 struct usb_stv *stv680 = usb_get_intfdata (intf);
1516
1517 usb_set_intfdata (intf, NULL);
1518
1519 if (stv680) {
1520 /* We don't want people trying to open up the device */
1521 if (stv680->vdev) {
1522 stv680_remove_sysfs_files(stv680->vdev);
1523 video_unregister_device(stv680->vdev);
1524 stv680->vdev = NULL;
1525 }
1526 if (!stv680->user) {
1527 usb_stv680_remove_disconnected (stv680);
1528 } else {
1529 stv680->removed = 1;
1530 }
1531 }
1532}
1533
1534static struct usb_driver stv680_driver = {
1535 .name = "stv680",
1536 .probe = stv680_probe,
1537 .disconnect = stv680_disconnect,
1538 .id_table = device_table
1539};
1540
1541/********************************************************************
1542 * Module routines
1543 ********************************************************************/
1544
1545static int __init usb_stv680_init (void)
1546{
1547 if (usb_register (&stv680_driver) < 0) {
1548 PDEBUG (0, "STV(e): Could not setup STV0680 driver");
1549 return -1;
1550 }
1551 PDEBUG (0, "STV(i): usb camera driver version %s registering", DRIVER_VERSION);
1552
1553 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
1554 DRIVER_DESC "\n");
1555 return 0;
1556}
1557
1558static void __exit usb_stv680_exit (void)
1559{
1560 usb_deregister (&stv680_driver);
1561 PDEBUG (0, "STV(i): driver deregistered");
1562}
1563
1564module_init (usb_stv680_init);
1565module_exit (usb_stv680_exit);
diff --git a/drivers/media/video/stv680.h b/drivers/media/video/stv680.h
deleted file mode 100644
index a08f1b08a4b0..000000000000
--- a/drivers/media/video/stv680.h
+++ /dev/null
@@ -1,227 +0,0 @@
1/****************************************************************************
2 *
3 * Filename: stv680.h
4 *
5 * Description:
6 * This is a USB driver for STV0680 based usb video cameras.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 *
22 ****************************************************************************/
23
24/* size of usb transfers */
25#define STV680_PACKETSIZE 4096
26
27/* number of queued bulk transfers to use, may have problems if > 1 */
28#define STV680_NUMSBUF 1
29
30/* number of frames supported by the v4l part */
31#define STV680_NUMFRAMES 2
32
33/* scratch buffers for passing data to the decoders: 2 or 4 are good */
34#define STV680_NUMSCRATCH 2
35
36/* number of nul sized packets to receive before kicking the camera */
37#define STV680_MAX_NULLPACKETS 200
38
39/* number of decoding errors before kicking the camera */
40#define STV680_MAX_ERRORS 100
41
42#define USB_PENCAM_VENDOR_ID 0x0553
43#define USB_PENCAM_PRODUCT_ID 0x0202
44
45#define USB_CREATIVEGOMINI_VENDOR_ID 0x041e
46#define USB_CREATIVEGOMINI_PRODUCT_ID 0x4007
47
48#define PENCAM_TIMEOUT 1000
49/* fmt 4 */
50#define STV_VIDEO_PALETTE VIDEO_PALETTE_RGB24
51
52static struct usb_device_id device_table[] = {
53 {USB_DEVICE (USB_PENCAM_VENDOR_ID, USB_PENCAM_PRODUCT_ID)},
54 {USB_DEVICE (USB_CREATIVEGOMINI_VENDOR_ID, USB_CREATIVEGOMINI_PRODUCT_ID)},
55 {}
56};
57MODULE_DEVICE_TABLE (usb, device_table);
58
59struct stv680_sbuf {
60 unsigned char *data;
61};
62
63enum {
64 FRAME_UNUSED, /* Unused (no MCAPTURE) */
65 FRAME_READY, /* Ready to start grabbing */
66 FRAME_GRABBING, /* In the process of being grabbed into */
67 FRAME_DONE, /* Finished grabbing, but not been synced yet */
68 FRAME_ERROR, /* Something bad happened while processing */
69};
70
71enum {
72 BUFFER_UNUSED,
73 BUFFER_READY,
74 BUFFER_BUSY,
75 BUFFER_DONE,
76};
77
78/* raw camera data <- sbuf (urb transfer buf) */
79struct stv680_scratch {
80 unsigned char *data;
81 volatile int state;
82 int offset;
83 int length;
84};
85
86/* processed data for display ends up here, after bayer */
87struct stv680_frame {
88 unsigned char *data; /* Frame buffer */
89 volatile int grabstate; /* State of grabbing */
90 unsigned char *curline;
91 int curlinepix;
92 int curpix;
93};
94
95/* this is almost the video structure uvd_t, with extra parameters for stv */
96struct usb_stv {
97 struct video_device *vdev;
98
99 struct usb_device *udev;
100
101 unsigned char bulk_in_endpointAddr; /* __u8 the address of the bulk in endpoint */
102 char *camera_name;
103
104 unsigned int VideoMode; /* 0x0100 = VGA, 0x0000 = CIF, 0x0300 = QVGA */
105 int SupportedModes;
106 int CIF;
107 int VGA;
108 int QVGA;
109 int cwidth; /* camera width */
110 int cheight; /* camera height */
111 int maxwidth; /* max video width */
112 int maxheight; /* max video height */
113 int vwidth; /* current width for video window */
114 int vheight; /* current height for video window */
115 unsigned long int rawbufsize;
116 unsigned long int maxframesize; /* rawbufsize * 3 for RGB */
117
118 int origGain;
119 int origMode; /* original camera mode */
120
121 struct mutex lock; /* to lock the structure */
122 int user; /* user count for exclusive use */
123 int removed; /* device disconnected */
124 int streaming; /* Are we streaming video? */
125 char *fbuf; /* Videodev buffer area */
126 struct urb *urb[STV680_NUMSBUF]; /* # of queued bulk transfers */
127 int curframe; /* Current receiving frame */
128 struct stv680_frame frame[STV680_NUMFRAMES]; /* # frames supported by v4l part */
129 int readcount;
130 int framecount;
131 int error;
132 int dropped;
133 int scratch_next;
134 int scratch_use;
135 int scratch_overflow;
136 struct stv680_scratch scratch[STV680_NUMSCRATCH]; /* for decoders */
137 struct stv680_sbuf sbuf[STV680_NUMSBUF];
138
139 unsigned int brightness;
140 unsigned int chgbright;
141 unsigned int whiteness;
142 unsigned int colour;
143 unsigned int contrast;
144 unsigned int hue;
145 unsigned int palette;
146 unsigned int depth; /* rgb24 in bits */
147
148 wait_queue_head_t wq; /* Processes waiting */
149
150 int nullpackets;
151};
152
153
154static const unsigned char red[256] = {
155 0, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
156 18, 18, 18, 18, 18, 18, 18, 25, 30, 35, 38, 42,
157 44, 47, 50, 53, 54, 57, 59, 61, 63, 65, 67, 69,
158 71, 71, 73, 75, 77, 78, 80, 81, 82, 84, 85, 87,
159 88, 89, 90, 91, 93, 94, 95, 97, 98, 98, 99, 101,
160 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113,
161 114, 115, 116, 116, 117, 118, 119, 120, 121, 122, 123, 124,
162 125, 125, 126, 127, 128, 129, 129, 130, 131, 132, 133, 134,
163 134, 135, 135, 136, 137, 138, 139, 140, 140, 141, 142, 143,
164 143, 143, 144, 145, 146, 147, 147, 148, 149, 150, 150, 151,
165 152, 152, 152, 153, 154, 154, 155, 156, 157, 157, 158, 159,
166 159, 160, 161, 161, 161, 162, 163, 163, 164, 165, 165, 166,
167 167, 167, 168, 168, 169, 170, 170, 170, 171, 171, 172, 173,
168 173, 174, 174, 175, 176, 176, 177, 178, 178, 179, 179, 179,
169 180, 180, 181, 181, 182, 183, 183, 184, 184, 185, 185, 186,
170 187, 187, 188, 188, 188, 188, 189, 190, 190, 191, 191, 192,
171 192, 193, 193, 194, 195, 195, 196, 196, 197, 197, 197, 197,
172 198, 198, 199, 199, 200, 201, 201, 202, 202, 203, 203, 204,
173 204, 205, 205, 206, 206, 206, 206, 207, 207, 208, 208, 209,
174 209, 210, 210, 211, 211, 212, 212, 213, 213, 214, 214, 215,
175 215, 215, 215, 216, 216, 217, 217, 218, 218, 218, 219, 219,
176 220, 220, 221, 221
177};
178
179static const unsigned char green[256] = {
180 0, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
181 21, 21, 21, 21, 21, 21, 21, 28, 34, 39, 43, 47,
182 50, 53, 56, 59, 61, 64, 66, 68, 71, 73, 75, 77,
183 79, 80, 82, 84, 86, 87, 89, 91, 92, 94, 95, 97,
184 98, 100, 101, 102, 104, 105, 106, 108, 109, 110, 111, 113,
185 114, 115, 116, 117, 118, 120, 121, 122, 123, 124, 125, 126,
186 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138,
187 139, 140, 141, 142, 143, 144, 144, 145, 146, 147, 148, 149,
188 150, 151, 151, 152, 153, 154, 155, 156, 156, 157, 158, 159,
189 160, 160, 161, 162, 163, 164, 164, 165, 166, 167, 167, 168,
190 169, 170, 170, 171, 172, 172, 173, 174, 175, 175, 176, 177,
191 177, 178, 179, 179, 180, 181, 182, 182, 183, 184, 184, 185,
192 186, 186, 187, 187, 188, 189, 189, 190, 191, 191, 192, 193,
193 193, 194, 194, 195, 196, 196, 197, 198, 198, 199, 199, 200,
194 201, 201, 202, 202, 203, 204, 204, 205, 205, 206, 206, 207,
195 208, 208, 209, 209, 210, 210, 211, 212, 212, 213, 213, 214,
196 214, 215, 215, 216, 217, 217, 218, 218, 219, 219, 220, 220,
197 221, 221, 222, 222, 223, 224, 224, 225, 225, 226, 226, 227,
198 227, 228, 228, 229, 229, 230, 230, 231, 231, 232, 232, 233,
199 233, 234, 234, 235, 235, 236, 236, 237, 237, 238, 238, 239,
200 239, 240, 240, 241, 241, 242, 242, 243, 243, 243, 244, 244,
201 245, 245, 246, 246
202};
203
204static const unsigned char blue[256] = {
205 0, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
206 23, 23, 23, 23, 23, 23, 23, 30, 37, 42, 47, 51,
207 55, 58, 61, 64, 67, 70, 72, 74, 78, 80, 82, 84,
208 86, 88, 90, 92, 94, 95, 97, 100, 101, 103, 104, 106,
209 107, 110, 111, 112, 114, 115, 116, 118, 119, 121, 122, 124,
210 125, 126, 127, 128, 129, 132, 133, 134, 135, 136, 137, 138,
211 139, 140, 141, 143, 144, 145, 146, 147, 148, 149, 150, 151,
212 152, 154, 155, 156, 157, 158, 158, 159, 160, 161, 162, 163,
213 165, 166, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174,
214 176, 176, 177, 178, 179, 180, 180, 181, 182, 183, 183, 184,
215 185, 187, 187, 188, 189, 189, 190, 191, 192, 192, 193, 194,
216 194, 195, 196, 196, 198, 199, 200, 200, 201, 202, 202, 203,
217 204, 204, 205, 205, 206, 207, 207, 209, 210, 210, 211, 212,
218 212, 213, 213, 214, 215, 215, 216, 217, 217, 218, 218, 220,
219 221, 221, 222, 222, 223, 224, 224, 225, 225, 226, 226, 227,
220 228, 228, 229, 229, 231, 231, 232, 233, 233, 234, 234, 235,
221 235, 236, 236, 237, 238, 238, 239, 239, 240, 240, 242, 242,
222 243, 243, 244, 244, 245, 246, 246, 247, 247, 248, 248, 249,
223 249, 250, 250, 251, 251, 253, 253, 254, 254, 255, 255, 255,
224 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
225 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
226 255, 255, 255, 255
227};
diff --git a/drivers/media/video/tlg2300/pd-main.c b/drivers/media/video/tlg2300/pd-main.c
index 256cc558ba13..4555f4a5f4c8 100644
--- a/drivers/media/video/tlg2300/pd-main.c
+++ b/drivers/media/video/tlg2300/pd-main.c
@@ -227,12 +227,11 @@ static int firmware_download(struct usb_device *udev)
227 227
228 fwlength = fw->size; 228 fwlength = fw->size;
229 229
230 fwbuf = kzalloc(fwlength, GFP_KERNEL); 230 fwbuf = kmemdup(fw->data, fwlength, GFP_KERNEL);
231 if (!fwbuf) { 231 if (!fwbuf) {
232 ret = -ENOMEM; 232 ret = -ENOMEM;
233 goto out; 233 goto out;
234 } 234 }
235 memcpy(fwbuf, fw->data, fwlength);
236 235
237 max_packet_size = udev->ep_out[0x1]->desc.wMaxPacketSize; 236 max_packet_size = udev->ep_out[0x1]->desc.wMaxPacketSize;
238 log("\t\t download size : %d", (int)max_packet_size); 237 log("\t\t download size : %d", (int)max_packet_size);
diff --git a/drivers/media/video/tw9910.c b/drivers/media/video/tw9910.c
index 445dc93413e3..a727962781a3 100644
--- a/drivers/media/video/tw9910.c
+++ b/drivers/media/video/tw9910.c
@@ -768,7 +768,7 @@ static int tw9910_g_fmt(struct v4l2_subdev *sd,
768 768
769 mf->width = priv->scale->width; 769 mf->width = priv->scale->width;
770 mf->height = priv->scale->height; 770 mf->height = priv->scale->height;
771 mf->code = V4L2_MBUS_FMT_YUYV8_2X8_BE; 771 mf->code = V4L2_MBUS_FMT_UYVY8_2X8;
772 mf->colorspace = V4L2_COLORSPACE_JPEG; 772 mf->colorspace = V4L2_COLORSPACE_JPEG;
773 mf->field = V4L2_FIELD_INTERLACED_BT; 773 mf->field = V4L2_FIELD_INTERLACED_BT;
774 774
@@ -797,7 +797,7 @@ static int tw9910_s_fmt(struct v4l2_subdev *sd,
797 /* 797 /*
798 * check color format 798 * check color format
799 */ 799 */
800 if (mf->code != V4L2_MBUS_FMT_YUYV8_2X8_BE) 800 if (mf->code != V4L2_MBUS_FMT_UYVY8_2X8)
801 return -EINVAL; 801 return -EINVAL;
802 802
803 mf->colorspace = V4L2_COLORSPACE_JPEG; 803 mf->colorspace = V4L2_COLORSPACE_JPEG;
@@ -824,7 +824,7 @@ static int tw9910_try_fmt(struct v4l2_subdev *sd,
824 return -EINVAL; 824 return -EINVAL;
825 } 825 }
826 826
827 mf->code = V4L2_MBUS_FMT_YUYV8_2X8_BE; 827 mf->code = V4L2_MBUS_FMT_UYVY8_2X8;
828 mf->colorspace = V4L2_COLORSPACE_JPEG; 828 mf->colorspace = V4L2_COLORSPACE_JPEG;
829 829
830 /* 830 /*
@@ -909,7 +909,7 @@ static int tw9910_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
909 if (index) 909 if (index)
910 return -EINVAL; 910 return -EINVAL;
911 911
912 *code = V4L2_MBUS_FMT_YUYV8_2X8_BE; 912 *code = V4L2_MBUS_FMT_UYVY8_2X8;
913 return 0; 913 return 0;
914} 914}
915 915
diff --git a/drivers/media/video/usbvideo/Kconfig b/drivers/media/video/usbvideo/Kconfig
index adb1c044ad7d..d6e16959f78b 100644
--- a/drivers/media/video/usbvideo/Kconfig
+++ b/drivers/media/video/usbvideo/Kconfig
@@ -37,17 +37,3 @@ config USB_KONICAWC
37 To compile this driver as a module, choose M here: the 37 To compile this driver as a module, choose M here: the
38 module will be called konicawc. 38 module will be called konicawc.
39 39
40config USB_QUICKCAM_MESSENGER
41 tristate "USB Logitech Quickcam Messenger (DEPRECATED)"
42 depends on VIDEO_V4L1
43 select VIDEO_USBVIDEO
44 ---help---
45 This driver is DEPRECATED please use the gspca stv06xx module
46 instead.
47
48 Say Y or M here to enable support for the USB Logitech Quickcam
49 Messenger webcam.
50
51 To compile this driver as a module, choose M here: the
52 module will be called quickcam_messenger.
53
diff --git a/drivers/media/video/usbvideo/Makefile b/drivers/media/video/usbvideo/Makefile
index 4a1b144bee4d..bb52eb8dc2f9 100644
--- a/drivers/media/video/usbvideo/Makefile
+++ b/drivers/media/video/usbvideo/Makefile
@@ -2,4 +2,3 @@ obj-$(CONFIG_VIDEO_USBVIDEO) += usbvideo.o
2obj-$(CONFIG_USB_IBMCAM) += ibmcam.o ultracam.o 2obj-$(CONFIG_USB_IBMCAM) += ibmcam.o ultracam.o
3obj-$(CONFIG_USB_KONICAWC) += konicawc.o 3obj-$(CONFIG_USB_KONICAWC) += konicawc.o
4obj-$(CONFIG_USB_VICAM) += vicam.o 4obj-$(CONFIG_USB_VICAM) += vicam.o
5obj-$(CONFIG_USB_QUICKCAM_MESSENGER) += quickcam_messenger.o
diff --git a/drivers/media/video/usbvideo/quickcam_messenger.c b/drivers/media/video/usbvideo/quickcam_messenger.c
deleted file mode 100644
index fbd665fa1979..000000000000
--- a/drivers/media/video/usbvideo/quickcam_messenger.c
+++ /dev/null
@@ -1,1126 +0,0 @@
1/*
2 * Driver for Logitech Quickcam Messenger usb video camera
3 * Copyright (C) Jaya Kumar
4 *
5 * This work was sponsored by CIS(M) Sdn Bhd.
6 * History:
7 * 05/08/2006 - Jaya Kumar
8 * I wrote this based on the konicawc by Simon Evans.
9 * -
10 * Full credit for reverse engineering and creating an initial
11 * working linux driver for the VV6422 goes to the qce-ga project by
12 * Tuukka Toivonen, Jochen Hoenicke, Peter McConnell,
13 * Cristiano De Michele, Georg Acher, Jean-Frederic Clere as well as
14 * others.
15 * ---
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 *
30 */
31
32#include <linux/kernel.h>
33#include <linux/module.h>
34#include <linux/init.h>
35#include <linux/input.h>
36#include <linux/usb/input.h>
37#include <linux/slab.h>
38
39#include "usbvideo.h"
40#include "quickcam_messenger.h"
41
42/*
43 * Version Information
44 */
45
46#ifdef CONFIG_USB_DEBUG
47static int debug;
48#define DEBUG(n, format, arg...) \
49 if (n <= debug) { \
50 printk(KERN_DEBUG __FILE__ ":%s(): " format "\n", __func__ , ## arg); \
51 }
52#else
53#define DEBUG(n, arg...)
54static const int debug;
55#endif
56
57#define DRIVER_VERSION "v0.01"
58#define DRIVER_DESC "Logitech Quickcam Messenger USB"
59
60#define USB_LOGITECH_VENDOR_ID 0x046D
61#define USB_QCM_PRODUCT_ID 0x08F0
62
63#define MAX_CAMERAS 1
64
65#define MAX_COLOUR 32768
66#define MAX_HUE 32768
67#define MAX_BRIGHTNESS 32768
68#define MAX_CONTRAST 32768
69#define MAX_WHITENESS 32768
70
71static int size = SIZE_320X240;
72static int colour = MAX_COLOUR;
73static int hue = MAX_HUE;
74static int brightness = MAX_BRIGHTNESS;
75static int contrast = MAX_CONTRAST;
76static int whiteness = MAX_WHITENESS;
77
78static struct usbvideo *cams;
79
80static struct usb_device_id qcm_table [] = {
81 { USB_DEVICE(USB_LOGITECH_VENDOR_ID, USB_QCM_PRODUCT_ID) },
82 { }
83};
84MODULE_DEVICE_TABLE(usb, qcm_table);
85
86#ifdef CONFIG_INPUT
87static void qcm_register_input(struct qcm *cam, struct usb_device *dev)
88{
89 struct input_dev *input_dev;
90 int error;
91
92 usb_make_path(dev, cam->input_physname, sizeof(cam->input_physname));
93 strlcat(cam->input_physname, "/input0", sizeof(cam->input_physname));
94
95 cam->input = input_dev = input_allocate_device();
96 if (!input_dev) {
97 dev_warn(&dev->dev, "insufficient mem for cam input device\n");
98 return;
99 }
100
101 input_dev->name = "QCM button";
102 input_dev->phys = cam->input_physname;
103 usb_to_input_id(dev, &input_dev->id);
104 input_dev->dev.parent = &dev->dev;
105
106 input_dev->evbit[0] = BIT_MASK(EV_KEY);
107 input_dev->keybit[BIT_WORD(KEY_CAMERA)] = BIT_MASK(KEY_CAMERA);
108
109 error = input_register_device(cam->input);
110 if (error) {
111 dev_warn(&dev->dev,
112 "Failed to register camera's input device, err: %d\n",
113 error);
114 input_free_device(cam->input);
115 cam->input = NULL;
116 }
117}
118
119static void qcm_unregister_input(struct qcm *cam)
120{
121 if (cam->input) {
122 input_unregister_device(cam->input);
123 cam->input = NULL;
124 }
125}
126
127static void qcm_report_buttonstat(struct qcm *cam)
128{
129 if (cam->input) {
130 input_report_key(cam->input, KEY_CAMERA, cam->button_sts);
131 input_sync(cam->input);
132 }
133}
134
135static void qcm_int_irq(struct urb *urb)
136{
137 int ret;
138 struct uvd *uvd = urb->context;
139 struct qcm *cam;
140
141 if (!CAMERA_IS_OPERATIONAL(uvd))
142 return;
143
144 if (!uvd->streaming)
145 return;
146
147 uvd->stats.urb_count++;
148
149 if (urb->status < 0)
150 uvd->stats.iso_err_count++;
151 else {
152 if (urb->actual_length > 0 ) {
153 cam = (struct qcm *) uvd->user_data;
154 if (cam->button_sts_buf == 0x88)
155 cam->button_sts = 0x0;
156 else if (cam->button_sts_buf == 0x80)
157 cam->button_sts = 0x1;
158 qcm_report_buttonstat(cam);
159 }
160 }
161
162 ret = usb_submit_urb(urb, GFP_ATOMIC);
163 if (ret < 0)
164 err("usb_submit_urb error (%d)", ret);
165}
166
167static int qcm_setup_input_int(struct qcm *cam, struct uvd *uvd)
168{
169 int errflag;
170 usb_fill_int_urb(cam->button_urb, uvd->dev,
171 usb_rcvintpipe(uvd->dev, uvd->video_endp + 1),
172 &cam->button_sts_buf,
173 1,
174 qcm_int_irq,
175 uvd, 16);
176
177 errflag = usb_submit_urb(cam->button_urb, GFP_KERNEL);
178 if (errflag)
179 err ("usb_submit_int ret %d", errflag);
180 return errflag;
181}
182
183static void qcm_stop_int_data(struct qcm *cam)
184{
185 usb_kill_urb(cam->button_urb);
186}
187
188static int qcm_alloc_int_urb(struct qcm *cam)
189{
190 cam->button_urb = usb_alloc_urb(0, GFP_KERNEL);
191
192 if (!cam->button_urb)
193 return -ENOMEM;
194
195 return 0;
196}
197
198static void qcm_free_int(struct qcm *cam)
199{
200 usb_free_urb(cam->button_urb);
201}
202#endif /* CONFIG_INPUT */
203
204static int qcm_stv_setb(struct usb_device *dev, u16 reg, u8 val)
205{
206 int ret;
207
208 /* we'll wait up to 3 slices but no more */
209 ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
210 0x04, USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_DEVICE,
211 reg, 0, &val, 1, 3*HZ);
212 return ret;
213}
214
215static int qcm_stv_setw(struct usb_device *dev, u16 reg, __le16 val)
216{
217 int ret;
218
219 /* we'll wait up to 3 slices but no more */
220 ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
221 0x04, USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_DEVICE,
222 reg, 0, &val, 2, 3*HZ);
223 return ret;
224}
225
226static int qcm_stv_getw(struct usb_device *dev, unsigned short reg,
227 __le16 *val)
228{
229 int ret;
230
231 /* we'll wait up to 3 slices but no more */
232 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
233 0x04, USB_TYPE_VENDOR | USB_DIR_IN | USB_RECIP_DEVICE,
234 reg, 0, val, 2, 3*HZ);
235 return ret;
236}
237
238static int qcm_camera_on(struct uvd *uvd)
239{
240 int ret;
241 CHECK_RET(ret, qcm_stv_setb(uvd->dev, STV_ISO_ENABLE, 0x01));
242 return 0;
243}
244
245static int qcm_camera_off(struct uvd *uvd)
246{
247 int ret;
248 CHECK_RET(ret, qcm_stv_setb(uvd->dev, STV_ISO_ENABLE, 0x00));
249 return 0;
250}
251
252static void qcm_hsv2rgb(u16 hue, u16 sat, u16 val, u16 *r, u16 *g, u16 *b)
253{
254 unsigned int segment, valsat;
255 signed int h = (signed int) hue;
256 unsigned int s = (sat - 32768) * 2; /* rescale */
257 unsigned int v = val;
258 unsigned int p;
259
260 /*
261 the registers controlling gain are 8 bit of which
262 we affect only the last 4 bits with our gain.
263 we know that if saturation is 0, (unsaturated) then
264 we're grayscale (center axis of the colour cone) so
265 we set rgb=value. we use a formula obtained from
266 wikipedia to map the cone to the RGB plane. it's
267 as follows for the human value case of h=0..360,
268 s=0..1, v=0..1
269 h_i = h/60 % 6 , f = h/60 - h_i , p = v(1-s)
270 q = v(1 - f*s) , t = v(1 - (1-f)s)
271 h_i==0 => r=v , g=t, b=p
272 h_i==1 => r=q , g=v, b=p
273 h_i==2 => r=p , g=v, b=t
274 h_i==3 => r=p , g=q, b=v
275 h_i==4 => r=t , g=p, b=v
276 h_i==5 => r=v , g=p, b=q
277 the bottom side (the point) and the stuff just up
278 of that is black so we simplify those two cases.
279 */
280 if (sat < 32768) {
281 /* anything less than this is unsaturated */
282 *r = val;
283 *g = val;
284 *b = val;
285 return;
286 }
287 if (val <= (0xFFFF/8)) {
288 /* anything less than this is black */
289 *r = 0;
290 *g = 0;
291 *b = 0;
292 return;
293 }
294
295 /* the rest of this code is copying tukkat's
296 implementation of the hsv2rgb conversion as taken
297 from qc-usb-messenger code. the 10923 is 0xFFFF/6
298 to divide the cone into 6 sectors. */
299
300 segment = (h + 10923) & 0xFFFF;
301 segment = segment*3 >> 16; /* 0..2: 0=R, 1=G, 2=B */
302 hue -= segment * 21845; /* -10923..10923 */
303 h = hue;
304 h *= 3;
305 valsat = v*s >> 16; /* 0..65534 */
306 p = v - valsat;
307 if (h >= 0) {
308 unsigned int t = v - (valsat * (32769 - h) >> 15);
309 switch (segment) {
310 case 0: /* R-> */
311 *r = v;
312 *g = t;
313 *b = p;
314 break;
315 case 1: /* G-> */
316 *r = p;
317 *g = v;
318 *b = t;
319 break;
320 case 2: /* B-> */
321 *r = t;
322 *g = p;
323 *b = v;
324 break;
325 }
326 } else {
327 unsigned int q = v - (valsat * (32769 + h) >> 15);
328 switch (segment) {
329 case 0: /* ->R */
330 *r = v;
331 *g = p;
332 *b = q;
333 break;
334 case 1: /* ->G */
335 *r = q;
336 *g = v;
337 *b = p;
338 break;
339 case 2: /* ->B */
340 *r = p;
341 *g = q;
342 *b = v;
343 break;
344 }
345 }
346}
347
348static int qcm_sensor_set_gains(struct uvd *uvd, u16 hue,
349 u16 saturation, u16 value)
350{
351 int ret;
352 u16 r=0,g=0,b=0;
353
354 /* this code is based on qc-usb-messenger */
355 qcm_hsv2rgb(hue, saturation, value, &r, &g, &b);
356
357 r >>= 12;
358 g >>= 12;
359 b >>= 12;
360
361 /* min val is 8 */
362 r = max((u16) 8, r);
363 g = max((u16) 8, g);
364 b = max((u16) 8, b);
365
366 r |= 0x30;
367 g |= 0x30;
368 b |= 0x30;
369
370 /* set the r,g,b gain registers */
371 CHECK_RET(ret, qcm_stv_setb(uvd->dev, 0x0509, r));
372 CHECK_RET(ret, qcm_stv_setb(uvd->dev, 0x050A, g));
373 CHECK_RET(ret, qcm_stv_setb(uvd->dev, 0x050B, b));
374
375 /* doing as qc-usb did */
376 CHECK_RET(ret, qcm_stv_setb(uvd->dev, 0x050C, 0x2A));
377 CHECK_RET(ret, qcm_stv_setb(uvd->dev, 0x050D, 0x01));
378 CHECK_RET(ret, qcm_stv_setb(uvd->dev, 0x143F, 0x01));
379
380 return 0;
381}
382
383static int qcm_sensor_set_exposure(struct uvd *uvd, int exposure)
384{
385 int ret;
386 int formedval;
387
388 /* calculation was from qc-usb-messenger driver */
389 formedval = ( exposure >> 12 );
390
391 /* max value for formedval is 14 */
392 formedval = min(formedval, 14);
393
394 CHECK_RET(ret, qcm_stv_setb(uvd->dev,
395 0x143A, 0xF0 | formedval));
396 CHECK_RET(ret, qcm_stv_setb(uvd->dev, 0x143F, 0x01));
397 return 0;
398}
399
400static int qcm_sensor_setlevels(struct uvd *uvd, int brightness, int contrast,
401 int hue, int colour)
402{
403 int ret;
404 /* brightness is exposure, contrast is gain, colour is saturation */
405 CHECK_RET(ret,
406 qcm_sensor_set_exposure(uvd, brightness));
407 CHECK_RET(ret, qcm_sensor_set_gains(uvd, hue, colour, contrast));
408
409 return 0;
410}
411
412static int qcm_sensor_setsize(struct uvd *uvd, u8 size)
413{
414 int ret;
415
416 CHECK_RET(ret, qcm_stv_setb(uvd->dev, 0x1505, size));
417 return 0;
418}
419
420static int qcm_sensor_set_shutter(struct uvd *uvd, int whiteness)
421{
422 int ret;
423 /* some rescaling as done by the qc-usb-messenger code */
424 if (whiteness > 0xC000)
425 whiteness = 0xC000 + (whiteness & 0x3FFF)*8;
426
427 CHECK_RET(ret, qcm_stv_setb(uvd->dev, 0x143D,
428 (whiteness >> 8) & 0xFF));
429 CHECK_RET(ret, qcm_stv_setb(uvd->dev, 0x143E,
430 (whiteness >> 16) & 0x03));
431 CHECK_RET(ret, qcm_stv_setb(uvd->dev, 0x143F, 0x01));
432
433 return 0;
434}
435
436static int qcm_sensor_init(struct uvd *uvd)
437{
438 struct qcm *cam = (struct qcm *) uvd->user_data;
439 int ret;
440 int i;
441
442 for (i=0; i < ARRAY_SIZE(regval_table) ; i++) {
443 CHECK_RET(ret, qcm_stv_setb(uvd->dev,
444 regval_table[i].reg,
445 regval_table[i].val));
446 }
447
448 CHECK_RET(ret, qcm_stv_setw(uvd->dev, 0x15c1,
449 cpu_to_le16(ISOC_PACKET_SIZE)));
450 CHECK_RET(ret, qcm_stv_setb(uvd->dev, 0x15c3, 0x08));
451 CHECK_RET(ret, qcm_stv_setb(uvd->dev, 0x143f, 0x01));
452
453 CHECK_RET(ret, qcm_stv_setb(uvd->dev, STV_ISO_ENABLE, 0x00));
454
455 CHECK_RET(ret, qcm_sensor_setsize(uvd, camera_sizes[cam->size].cmd));
456
457 CHECK_RET(ret, qcm_sensor_setlevels(uvd, uvd->vpic.brightness,
458 uvd->vpic.contrast, uvd->vpic.hue, uvd->vpic.colour));
459
460 CHECK_RET(ret, qcm_sensor_set_shutter(uvd, uvd->vpic.whiteness));
461 CHECK_RET(ret, qcm_sensor_setsize(uvd, camera_sizes[cam->size].cmd));
462
463 return 0;
464}
465
466static int qcm_set_camera_size(struct uvd *uvd)
467{
468 int ret;
469 struct qcm *cam = (struct qcm *) uvd->user_data;
470
471 CHECK_RET(ret, qcm_sensor_setsize(uvd, camera_sizes[cam->size].cmd));
472 cam->width = camera_sizes[cam->size].width;
473 cam->height = camera_sizes[cam->size].height;
474 uvd->videosize = VIDEOSIZE(cam->width, cam->height);
475
476 return 0;
477}
478
479static int qcm_setup_on_open(struct uvd *uvd)
480{
481 int ret;
482
483 CHECK_RET(ret, qcm_sensor_set_gains(uvd, uvd->vpic.hue,
484 uvd->vpic.colour, uvd->vpic.contrast));
485 CHECK_RET(ret, qcm_sensor_set_exposure(uvd, uvd->vpic.brightness));
486 CHECK_RET(ret, qcm_sensor_set_shutter(uvd, uvd->vpic.whiteness));
487 CHECK_RET(ret, qcm_set_camera_size(uvd));
488 CHECK_RET(ret, qcm_camera_on(uvd));
489 return 0;
490}
491
492static void qcm_adjust_picture(struct uvd *uvd)
493{
494 int ret;
495 struct qcm *cam = (struct qcm *) uvd->user_data;
496
497 ret = qcm_camera_off(uvd);
498 if (ret) {
499 err("can't turn camera off. abandoning pic adjustment");
500 return;
501 }
502
503 /* if there's been a change in contrast, hue, or
504 colour then we need to recalculate hsv in order
505 to update gains */
506 if ((cam->contrast != uvd->vpic.contrast) ||
507 (cam->hue != uvd->vpic.hue) ||
508 (cam->colour != uvd->vpic.colour)) {
509 cam->contrast = uvd->vpic.contrast;
510 cam->hue = uvd->vpic.hue;
511 cam->colour = uvd->vpic.colour;
512 ret = qcm_sensor_set_gains(uvd, cam->hue, cam->colour,
513 cam->contrast);
514 if (ret) {
515 err("can't set gains. abandoning pic adjustment");
516 return;
517 }
518 }
519
520 if (cam->brightness != uvd->vpic.brightness) {
521 cam->brightness = uvd->vpic.brightness;
522 ret = qcm_sensor_set_exposure(uvd, cam->brightness);
523 if (ret) {
524 err("can't set exposure. abandoning pic adjustment");
525 return;
526 }
527 }
528
529 if (cam->whiteness != uvd->vpic.whiteness) {
530 cam->whiteness = uvd->vpic.whiteness;
531 qcm_sensor_set_shutter(uvd, cam->whiteness);
532 if (ret) {
533 err("can't set shutter. abandoning pic adjustment");
534 return;
535 }
536 }
537
538 ret = qcm_camera_on(uvd);
539 if (ret) {
540 err("can't reenable camera. pic adjustment failed");
541 return;
542 }
543}
544
545static int qcm_process_frame(struct uvd *uvd, u8 *cdata, int framelen)
546{
547 int datalen;
548 int totaldata;
549 struct framehdr {
550 __be16 id;
551 __be16 len;
552 };
553 struct framehdr *fhdr;
554
555 totaldata = 0;
556 while (framelen) {
557 fhdr = (struct framehdr *) cdata;
558 datalen = be16_to_cpu(fhdr->len);
559 framelen -= 4;
560 cdata += 4;
561
562 if ((fhdr->id) == cpu_to_be16(0x8001)) {
563 RingQueue_Enqueue(&uvd->dp, marker, 4);
564 totaldata += 4;
565 continue;
566 }
567 if ((fhdr->id & cpu_to_be16(0xFF00)) == cpu_to_be16(0x0200)) {
568 RingQueue_Enqueue(&uvd->dp, cdata, datalen);
569 totaldata += datalen;
570 }
571 framelen -= datalen;
572 cdata += datalen;
573 }
574 return totaldata;
575}
576
577static int qcm_compress_iso(struct uvd *uvd, struct urb *dataurb)
578{
579 int totlen;
580 int i;
581 unsigned char *cdata;
582
583 totlen=0;
584 for (i = 0; i < dataurb->number_of_packets; i++) {
585 int n = dataurb->iso_frame_desc[i].actual_length;
586 int st = dataurb->iso_frame_desc[i].status;
587
588 cdata = dataurb->transfer_buffer +
589 dataurb->iso_frame_desc[i].offset;
590
591 if (st < 0) {
592 dev_warn(&uvd->dev->dev,
593 "Data error: packet=%d. len=%d. status=%d.\n",
594 i, n, st);
595 uvd->stats.iso_err_count++;
596 continue;
597 }
598 if (!n)
599 continue;
600
601 totlen += qcm_process_frame(uvd, cdata, n);
602 }
603 return totlen;
604}
605
606static void resubmit_urb(struct uvd *uvd, struct urb *urb)
607{
608 int ret;
609
610 urb->dev = uvd->dev;
611 ret = usb_submit_urb(urb, GFP_ATOMIC);
612 if (ret)
613 err("usb_submit_urb error (%d)", ret);
614}
615
616static void qcm_isoc_irq(struct urb *urb)
617{
618 int len;
619 struct uvd *uvd = urb->context;
620
621 if (!CAMERA_IS_OPERATIONAL(uvd))
622 return;
623
624 if (!uvd->streaming)
625 return;
626
627 uvd->stats.urb_count++;
628
629 if (!urb->actual_length) {
630 resubmit_urb(uvd, urb);
631 return;
632 }
633
634 len = qcm_compress_iso(uvd, urb);
635 resubmit_urb(uvd, urb);
636 uvd->stats.urb_length = len;
637 uvd->stats.data_count += len;
638 if (len)
639 RingQueue_WakeUpInterruptible(&uvd->dp);
640}
641
642static int qcm_start_data(struct uvd *uvd)
643{
644 struct qcm *cam = (struct qcm *) uvd->user_data;
645 int i;
646 int errflag;
647 int pktsz;
648 int err;
649
650 pktsz = uvd->iso_packet_len;
651 if (!CAMERA_IS_OPERATIONAL(uvd)) {
652 err("Camera is not operational");
653 return -EFAULT;
654 }
655
656 err = usb_set_interface(uvd->dev, uvd->iface, uvd->ifaceAltActive);
657 if (err < 0) {
658 err("usb_set_interface error");
659 uvd->last_error = err;
660 return -EBUSY;
661 }
662
663 for (i=0; i < USBVIDEO_NUMSBUF; i++) {
664 int j, k;
665 struct urb *urb = uvd->sbuf[i].urb;
666 urb->dev = uvd->dev;
667 urb->context = uvd;
668 urb->pipe = usb_rcvisocpipe(uvd->dev, uvd->video_endp);
669 urb->interval = 1;
670 urb->transfer_flags = URB_ISO_ASAP;
671 urb->transfer_buffer = uvd->sbuf[i].data;
672 urb->complete = qcm_isoc_irq;
673 urb->number_of_packets = FRAMES_PER_DESC;
674 urb->transfer_buffer_length = pktsz * FRAMES_PER_DESC;
675 for (j=k=0; j < FRAMES_PER_DESC; j++, k += pktsz) {
676 urb->iso_frame_desc[j].offset = k;
677 urb->iso_frame_desc[j].length = pktsz;
678 }
679 }
680
681 uvd->streaming = 1;
682 uvd->curframe = -1;
683 for (i=0; i < USBVIDEO_NUMSBUF; i++) {
684 errflag = usb_submit_urb(uvd->sbuf[i].urb, GFP_KERNEL);
685 if (errflag)
686 err ("usb_submit_isoc(%d) ret %d", i, errflag);
687 }
688
689 CHECK_RET(err, qcm_setup_input_int(cam, uvd));
690 CHECK_RET(err, qcm_camera_on(uvd));
691 return 0;
692}
693
694static void qcm_stop_data(struct uvd *uvd)
695{
696 struct qcm *cam;
697 int i, j;
698 int ret;
699
700 if ((uvd == NULL) || (!uvd->streaming) || (uvd->dev == NULL))
701 return;
702 cam = (struct qcm *) uvd->user_data;
703
704 ret = qcm_camera_off(uvd);
705 if (ret)
706 dev_warn(&uvd->dev->dev, "couldn't turn the cam off.\n");
707
708 uvd->streaming = 0;
709
710 /* Unschedule all of the iso td's */
711 for (i=0; i < USBVIDEO_NUMSBUF; i++)
712 usb_kill_urb(uvd->sbuf[i].urb);
713
714 qcm_stop_int_data(cam);
715
716 if (!uvd->remove_pending) {
717 /* Set packet size to 0 */
718 j = usb_set_interface(uvd->dev, uvd->iface,
719 uvd->ifaceAltInactive);
720 if (j < 0) {
721 err("usb_set_interface() error %d.", j);
722 uvd->last_error = j;
723 }
724 }
725}
726
727static void qcm_process_isoc(struct uvd *uvd, struct usbvideo_frame *frame)
728{
729 struct qcm *cam = (struct qcm *) uvd->user_data;
730 int x;
731 struct rgb *rgbL0;
732 struct rgb *rgbL1;
733 struct bayL0 *bayL0;
734 struct bayL1 *bayL1;
735 int hor,ver,hordel,verdel;
736 assert(frame != NULL);
737
738 switch (cam->size) {
739 case SIZE_160X120:
740 hor = 162; ver = 124; hordel = 1; verdel = 2;
741 break;
742 case SIZE_320X240:
743 default:
744 hor = 324; ver = 248; hordel = 2; verdel = 4;
745 break;
746 }
747
748 if (frame->scanstate == ScanState_Scanning) {
749 while (RingQueue_GetLength(&uvd->dp) >=
750 4 + (hor*verdel + hordel)) {
751 if ((RING_QUEUE_PEEK(&uvd->dp, 0) == 0x00) &&
752 (RING_QUEUE_PEEK(&uvd->dp, 1) == 0xff) &&
753 (RING_QUEUE_PEEK(&uvd->dp, 2) == 0x00) &&
754 (RING_QUEUE_PEEK(&uvd->dp, 3) == 0xff)) {
755 frame->curline = 0;
756 frame->scanstate = ScanState_Lines;
757 frame->frameState = FrameState_Grabbing;
758 RING_QUEUE_DEQUEUE_BYTES(&uvd->dp, 4);
759 /*
760 * if we're starting, we need to discard the first
761 * 4 lines of y bayer data
762 * and the first 2 gr elements of x bayer data
763 */
764 RING_QUEUE_DEQUEUE_BYTES(&uvd->dp,
765 (hor*verdel + hordel));
766 break;
767 }
768 RING_QUEUE_DEQUEUE_BYTES(&uvd->dp, 1);
769 }
770 }
771
772 if (frame->scanstate == ScanState_Scanning)
773 return;
774
775 /* now we can start processing bayer data so long as we have at least
776 * 2 lines worth of data. this is the simplest demosaicing method that
777 * I could think of. I use each 2x2 bayer element without interpolation
778 * to generate 4 rgb pixels.
779 */
780 while ( frame->curline < cam->height &&
781 (RingQueue_GetLength(&uvd->dp) >= hor*2)) {
782 /* get 2 lines of bayer for demosaicing
783 * into 2 lines of RGB */
784 RingQueue_Dequeue(&uvd->dp, cam->scratch, hor*2);
785 bayL0 = (struct bayL0 *) cam->scratch;
786 bayL1 = (struct bayL1 *) (cam->scratch + hor);
787 /* frame->curline is the rgb y line */
788 rgbL0 = (struct rgb *)
789 ( frame->data + (cam->width*3*frame->curline));
790 /* w/2 because we're already doing 2 pixels */
791 rgbL1 = rgbL0 + (cam->width/2);
792
793 for (x=0; x < cam->width; x+=2) {
794 rgbL0->r = bayL0->r;
795 rgbL0->g = bayL0->g;
796 rgbL0->b = bayL1->b;
797
798 rgbL0->r2 = bayL0->r;
799 rgbL0->g2 = bayL1->g;
800 rgbL0->b2 = bayL1->b;
801
802 rgbL1->r = bayL0->r;
803 rgbL1->g = bayL1->g;
804 rgbL1->b = bayL1->b;
805
806 rgbL1->r2 = bayL0->r;
807 rgbL1->g2 = bayL1->g;
808 rgbL1->b2 = bayL1->b;
809
810 rgbL0++;
811 rgbL1++;
812
813 bayL0++;
814 bayL1++;
815 }
816
817 frame->seqRead_Length += cam->width*3*2;
818 frame->curline += 2;
819 }
820 /* See if we filled the frame */
821 if (frame->curline == cam->height) {
822 frame->frameState = FrameState_Done_Hold;
823 frame->curline = 0;
824 uvd->curframe = -1;
825 uvd->stats.frame_num++;
826 }
827}
828
829/* taken from konicawc */
830static int qcm_set_video_mode(struct uvd *uvd, struct video_window *vw)
831{
832 int ret;
833 int newsize;
834 int oldsize;
835 int x = vw->width;
836 int y = vw->height;
837 struct qcm *cam = (struct qcm *) uvd->user_data;
838
839 if (x > 0 && y > 0) {
840 DEBUG(2, "trying to find size %d,%d", x, y);
841 for (newsize = 0; newsize <= MAX_FRAME_SIZE; newsize++) {
842 if ((camera_sizes[newsize].width == x) &&
843 (camera_sizes[newsize].height == y))
844 break;
845 }
846 } else
847 newsize = cam->size;
848
849 if (newsize > MAX_FRAME_SIZE) {
850 DEBUG(1, "couldn't find size %d,%d", x, y);
851 return -EINVAL;
852 }
853
854 if (newsize == cam->size) {
855 DEBUG(1, "Nothing to do");
856 return 0;
857 }
858
859 qcm_stop_data(uvd);
860
861 if (cam->size != newsize) {
862 oldsize = cam->size;
863 cam->size = newsize;
864 ret = qcm_set_camera_size(uvd);
865 if (ret) {
866 err("Couldn't set camera size, err=%d",ret);
867 /* restore the original size */
868 cam->size = oldsize;
869 return ret;
870 }
871 }
872
873 /* Flush the input queue and clear any current frame in progress */
874
875 RingQueue_Flush(&uvd->dp);
876 if (uvd->curframe != -1) {
877 uvd->frame[uvd->curframe].curline = 0;
878 uvd->frame[uvd->curframe].seqRead_Length = 0;
879 uvd->frame[uvd->curframe].seqRead_Index = 0;
880 }
881
882 CHECK_RET(ret, qcm_start_data(uvd));
883 return 0;
884}
885
886static int qcm_configure_video(struct uvd *uvd)
887{
888 int ret;
889 memset(&uvd->vpic, 0, sizeof(uvd->vpic));
890 memset(&uvd->vpic_old, 0x55, sizeof(uvd->vpic_old));
891
892 uvd->vpic.colour = colour;
893 uvd->vpic.hue = hue;
894 uvd->vpic.brightness = brightness;
895 uvd->vpic.contrast = contrast;
896 uvd->vpic.whiteness = whiteness;
897 uvd->vpic.depth = 24;
898 uvd->vpic.palette = VIDEO_PALETTE_RGB24;
899
900 memset(&uvd->vcap, 0, sizeof(uvd->vcap));
901 strcpy(uvd->vcap.name, "QCM USB Camera");
902 uvd->vcap.type = VID_TYPE_CAPTURE;
903 uvd->vcap.channels = 1;
904 uvd->vcap.audios = 0;
905
906 uvd->vcap.minwidth = camera_sizes[SIZE_160X120].width;
907 uvd->vcap.minheight = camera_sizes[SIZE_160X120].height;
908 uvd->vcap.maxwidth = camera_sizes[SIZE_320X240].width;
909 uvd->vcap.maxheight = camera_sizes[SIZE_320X240].height;
910
911 memset(&uvd->vchan, 0, sizeof(uvd->vchan));
912 uvd->vchan.flags = 0 ;
913 uvd->vchan.tuners = 0;
914 uvd->vchan.channel = 0;
915 uvd->vchan.type = VIDEO_TYPE_CAMERA;
916 strcpy(uvd->vchan.name, "Camera");
917
918 CHECK_RET(ret, qcm_sensor_init(uvd));
919 return 0;
920}
921
922static int qcm_probe(struct usb_interface *intf,
923 const struct usb_device_id *devid)
924{
925 int err;
926 struct uvd *uvd;
927 struct usb_device *dev = interface_to_usbdev(intf);
928 struct qcm *cam;
929 size_t buffer_size;
930 unsigned char video_ep;
931 struct usb_host_interface *interface;
932 struct usb_endpoint_descriptor *endpoint;
933 int i,j;
934 unsigned int ifacenum, ifacenum_inact=0;
935 __le16 sensor_id;
936
937 /* we don't support multiconfig cams */
938 if (dev->descriptor.bNumConfigurations != 1)
939 return -ENODEV;
940
941 /* first check for the video interface and not
942 * the audio interface */
943 interface = &intf->cur_altsetting[0];
944 if ((interface->desc.bInterfaceClass != USB_CLASS_VENDOR_SPEC)
945 || (interface->desc.bInterfaceSubClass !=
946 USB_CLASS_VENDOR_SPEC))
947 return -ENODEV;
948
949 /*
950 walk through each endpoint in each setting in the interface
951 stop when we find the one that's an isochronous IN endpoint.
952 */
953 for (i=0; i < intf->num_altsetting; i++) {
954 interface = &intf->cur_altsetting[i];
955 ifacenum = interface->desc.bAlternateSetting;
956 /* walk the end points */
957 for (j=0; j < interface->desc.bNumEndpoints; j++) {
958 endpoint = &interface->endpoint[j].desc;
959
960 if (usb_endpoint_dir_out(endpoint))
961 continue; /* not input then not good */
962
963 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
964 if (!buffer_size) {
965 ifacenum_inact = ifacenum;
966 continue; /* 0 pkt size is not what we want */
967 }
968
969 if (usb_endpoint_xfer_isoc(endpoint)) {
970 video_ep = endpoint->bEndpointAddress;
971 /* break out of the search */
972 goto good_videoep;
973 }
974 }
975 }
976 /* failed out since nothing useful was found */
977 err("No suitable endpoint was found\n");
978 return -ENODEV;
979
980good_videoep:
981 /* disable isochronous stream before doing anything else */
982 err = qcm_stv_setb(dev, STV_ISO_ENABLE, 0);
983 if (err < 0) {
984 err("Failed to disable sensor stream");
985 return -EIO;
986 }
987
988 /*
989 Check that this is the same unknown sensor that is known to work. This
990 sensor is suspected to be the ST VV6422C001. I'll check the same value
991 that the qc-usb driver checks. This value is probably not even the
992 sensor ID since it matches the USB dev ID. Oh well. If it doesn't
993 match, it's probably a diff sensor so exit and apologize.
994 */
995 err = qcm_stv_getw(dev, CMOS_SENSOR_IDREV, &sensor_id);
996 if (err < 0) {
997 err("Couldn't read sensor values. Err %d\n",err);
998 return err;
999 }
1000 if (sensor_id != cpu_to_le16(0x08F0)) {
1001 err("Sensor ID %x != %x. Unsupported. Sorry\n",
1002 le16_to_cpu(sensor_id), (0x08F0));
1003 return -ENODEV;
1004 }
1005
1006 uvd = usbvideo_AllocateDevice(cams);
1007 if (!uvd)
1008 return -ENOMEM;
1009
1010 cam = (struct qcm *) uvd->user_data;
1011
1012 /* buf for doing demosaicing */
1013 cam->scratch = kmalloc(324*2, GFP_KERNEL);
1014 if (!cam->scratch) /* uvd freed in dereg */
1015 return -ENOMEM;
1016
1017 /* yes, if we fail after here, cam->scratch gets freed
1018 by qcm_free_uvd */
1019
1020 err = qcm_alloc_int_urb(cam);
1021 if (err < 0)
1022 return err;
1023
1024 /* yes, if we fail after here, int urb gets freed
1025 by qcm_free_uvd */
1026
1027 RESTRICT_TO_RANGE(size, SIZE_160X120, SIZE_320X240);
1028 cam->width = camera_sizes[size].width;
1029 cam->height = camera_sizes[size].height;
1030 cam->size = size;
1031
1032 uvd->debug = debug;
1033 uvd->flags = 0;
1034 uvd->dev = dev;
1035 uvd->iface = intf->altsetting->desc.bInterfaceNumber;
1036 uvd->ifaceAltActive = ifacenum;
1037 uvd->ifaceAltInactive = ifacenum_inact;
1038 uvd->video_endp = video_ep;
1039 uvd->iso_packet_len = buffer_size;
1040 uvd->paletteBits = 1L << VIDEO_PALETTE_RGB24;
1041 uvd->defaultPalette = VIDEO_PALETTE_RGB24;
1042 uvd->canvas = VIDEOSIZE(320, 240);
1043 uvd->videosize = VIDEOSIZE(cam->width, cam->height);
1044 err = qcm_configure_video(uvd);
1045 if (err) {
1046 err("failed to configure video settings");
1047 return err;
1048 }
1049
1050 err = usbvideo_RegisterVideoDevice(uvd);
1051 if (err) { /* the uvd gets freed in Deregister */
1052 err("usbvideo_RegisterVideoDevice() failed.");
1053 return err;
1054 }
1055
1056 uvd->max_frame_size = (320 * 240 * 3);
1057 qcm_register_input(cam, dev);
1058 usb_set_intfdata(intf, uvd);
1059 return 0;
1060}
1061
1062static void qcm_free_uvd(struct uvd *uvd)
1063{
1064 struct qcm *cam = (struct qcm *) uvd->user_data;
1065
1066 kfree(cam->scratch);
1067 qcm_unregister_input(cam);
1068 qcm_free_int(cam);
1069}
1070
1071static struct usbvideo_cb qcm_driver = {
1072 .probe = qcm_probe,
1073 .setupOnOpen = qcm_setup_on_open,
1074 .processData = qcm_process_isoc,
1075 .setVideoMode = qcm_set_video_mode,
1076 .startDataPump = qcm_start_data,
1077 .stopDataPump = qcm_stop_data,
1078 .adjustPicture = qcm_adjust_picture,
1079 .userFree = qcm_free_uvd
1080};
1081
1082static int __init qcm_init(void)
1083{
1084 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
1085 DRIVER_DESC "\n");
1086
1087 return usbvideo_register(
1088 &cams,
1089 MAX_CAMERAS,
1090 sizeof(struct qcm),
1091 "QCM",
1092 &qcm_driver,
1093 THIS_MODULE,
1094 qcm_table);
1095}
1096
1097static void __exit qcm_exit(void)
1098{
1099 usbvideo_Deregister(&cams);
1100}
1101
1102module_param(size, int, 0);
1103MODULE_PARM_DESC(size, "Initial Size 0: 160x120 1: 320x240");
1104module_param(colour, int, 0);
1105MODULE_PARM_DESC(colour, "Initial colour");
1106module_param(hue, int, 0);
1107MODULE_PARM_DESC(hue, "Initial hue");
1108module_param(brightness, int, 0);
1109MODULE_PARM_DESC(brightness, "Initial brightness");
1110module_param(contrast, int, 0);
1111MODULE_PARM_DESC(contrast, "Initial contrast");
1112module_param(whiteness, int, 0);
1113MODULE_PARM_DESC(whiteness, "Initial whiteness");
1114
1115#ifdef CONFIG_USB_DEBUG
1116module_param(debug, int, S_IRUGO | S_IWUSR);
1117MODULE_PARM_DESC(debug, "Debug level: 0-9 (default=0)");
1118#endif
1119
1120module_init(qcm_init);
1121module_exit(qcm_exit);
1122
1123MODULE_LICENSE("GPL");
1124MODULE_AUTHOR("Jaya Kumar");
1125MODULE_DESCRIPTION("QCM USB Camera");
1126MODULE_SUPPORTED_DEVICE("QCM USB Camera");
diff --git a/drivers/media/video/usbvideo/quickcam_messenger.h b/drivers/media/video/usbvideo/quickcam_messenger.h
deleted file mode 100644
index 17ace394d981..000000000000
--- a/drivers/media/video/usbvideo/quickcam_messenger.h
+++ /dev/null
@@ -1,112 +0,0 @@
1#ifndef quickcam_messenger_h
2#define quickcam_messenger_h
3
4#ifndef CONFIG_INPUT
5/* if we're not using input we dummy out these functions */
6#define qcm_register_input(...)
7#define qcm_unregister_input(...)
8#define qcm_report_buttonstat(...)
9#define qcm_setup_input_int(...) 0
10#define qcm_stop_int_data(...)
11#define qcm_alloc_int_urb(...) 0
12#define qcm_free_int(...)
13#endif
14
15
16#define CHECK_RET(ret, expr) \
17 if ((ret = expr) < 0) return ret
18
19/* Control Registers for the STVV6422 ASIC
20 * - this define is taken from the qc-usb-messenger code
21 */
22#define STV_ISO_ENABLE 0x1440
23#define ISOC_PACKET_SIZE 1023
24
25/* Chip identification number including revision indicator */
26#define CMOS_SENSOR_IDREV 0xE00A
27
28struct rgb {
29 u8 b;
30 u8 g;
31 u8 r;
32 u8 b2;
33 u8 g2;
34 u8 r2;
35};
36
37struct bayL0 {
38 u8 g;
39 u8 r;
40};
41
42struct bayL1 {
43 u8 b;
44 u8 g;
45};
46
47struct cam_size {
48 u16 width;
49 u16 height;
50 u8 cmd;
51};
52
53static const struct cam_size camera_sizes[] = {
54 { 160, 120, 0xf },
55 { 320, 240, 0x2 },
56};
57
58enum frame_sizes {
59 SIZE_160X120 = 0,
60 SIZE_320X240 = 1,
61};
62
63#define MAX_FRAME_SIZE SIZE_320X240
64
65struct qcm {
66 u16 colour;
67 u16 hue;
68 u16 brightness;
69 u16 contrast;
70 u16 whiteness;
71
72 u8 size;
73 int height;
74 int width;
75 u8 *scratch;
76 struct urb *button_urb;
77 u8 button_sts;
78 u8 button_sts_buf;
79
80#ifdef CONFIG_INPUT
81 struct input_dev *input;
82 char input_physname[64];
83#endif
84};
85
86struct regval {
87 u16 reg;
88 u8 val;
89};
90/* this table is derived from the
91qc-usb-messenger code */
92static const struct regval regval_table[] = {
93 { STV_ISO_ENABLE, 0x00 },
94 { 0x1436, 0x00 }, { 0x1432, 0x03 },
95 { 0x143a, 0xF9 }, { 0x0509, 0x38 },
96 { 0x050a, 0x38 }, { 0x050b, 0x38 },
97 { 0x050c, 0x2A }, { 0x050d, 0x01 },
98 { 0x1431, 0x00 }, { 0x1433, 0x34 },
99 { 0x1438, 0x18 }, { 0x1439, 0x00 },
100 { 0x143b, 0x05 }, { 0x143c, 0x00 },
101 { 0x143e, 0x01 }, { 0x143d, 0x00 },
102 { 0x1442, 0xe2 }, { 0x1500, 0xd0 },
103 { 0x1500, 0xd0 }, { 0x1500, 0x50 },
104 { 0x1501, 0xaf }, { 0x1502, 0xc2 },
105 { 0x1503, 0x45 }, { 0x1505, 0x02 },
106 { 0x150e, 0x8e }, { 0x150f, 0x37 },
107 { 0x15c0, 0x00 },
108};
109
110static const unsigned char marker[] = { 0x00, 0xff, 0x00, 0xFF };
111
112#endif /* quickcam_messenger_h */
diff --git a/drivers/media/video/uvc/uvc_ctrl.c b/drivers/media/video/uvc/uvc_ctrl.c
index 27a79f087b15..a350fad0db43 100644
--- a/drivers/media/video/uvc/uvc_ctrl.c
+++ b/drivers/media/video/uvc/uvc_ctrl.c
@@ -606,6 +606,26 @@ static struct uvc_control_mapping uvc_ctrl_mappings[] = {
606 .set = uvc_ctrl_set_zoom, 606 .set = uvc_ctrl_set_zoom,
607 }, 607 },
608 { 608 {
609 .id = V4L2_CID_PAN_ABSOLUTE,
610 .name = "Pan (Absolute)",
611 .entity = UVC_GUID_UVC_CAMERA,
612 .selector = UVC_CT_PANTILT_ABSOLUTE_CONTROL,
613 .size = 32,
614 .offset = 0,
615 .v4l2_type = V4L2_CTRL_TYPE_INTEGER,
616 .data_type = UVC_CTRL_DATA_TYPE_UNSIGNED,
617 },
618 {
619 .id = V4L2_CID_TILT_ABSOLUTE,
620 .name = "Tilt (Absolute)",
621 .entity = UVC_GUID_UVC_CAMERA,
622 .selector = UVC_CT_PANTILT_ABSOLUTE_CONTROL,
623 .size = 32,
624 .offset = 32,
625 .v4l2_type = V4L2_CTRL_TYPE_INTEGER,
626 .data_type = UVC_CTRL_DATA_TYPE_UNSIGNED,
627 },
628 {
609 .id = V4L2_CID_PRIVACY, 629 .id = V4L2_CID_PRIVACY,
610 .name = "Privacy", 630 .name = "Privacy",
611 .entity = UVC_GUID_UVC_CAMERA, 631 .entity = UVC_GUID_UVC_CAMERA,
@@ -623,7 +643,7 @@ static struct uvc_control_mapping uvc_ctrl_mappings[] = {
623 643
624static inline __u8 *uvc_ctrl_data(struct uvc_control *ctrl, int id) 644static inline __u8 *uvc_ctrl_data(struct uvc_control *ctrl, int id)
625{ 645{
626 return ctrl->data + id * ctrl->info->size; 646 return ctrl->uvc_data + id * ctrl->info->size;
627} 647}
628 648
629static inline int uvc_test_bit(const __u8 *data, int bit) 649static inline int uvc_test_bit(const __u8 *data, int bit)
@@ -678,6 +698,14 @@ static void uvc_set_le_value(struct uvc_control_mapping *mapping,
678 int offset = mapping->offset; 698 int offset = mapping->offset;
679 __u8 mask; 699 __u8 mask;
680 700
701 /* According to the v4l2 spec, writing any value to a button control
702 * should result in the action belonging to the button control being
703 * triggered. UVC devices however want to see a 1 written -> override
704 * value.
705 */
706 if (mapping->v4l2_type == V4L2_CTRL_TYPE_BUTTON)
707 value = -1;
708
681 data += offset / 8; 709 data += offset / 8;
682 offset &= 7; 710 offset &= 7;
683 711
@@ -1265,13 +1293,15 @@ int uvc_ctrl_resume_device(struct uvc_device *dev)
1265 * Control and mapping handling 1293 * Control and mapping handling
1266 */ 1294 */
1267 1295
1268static void uvc_ctrl_add_ctrl(struct uvc_device *dev, 1296static int uvc_ctrl_add_ctrl(struct uvc_device *dev,
1269 struct uvc_control_info *info) 1297 struct uvc_control_info *info)
1270{ 1298{
1271 struct uvc_entity *entity; 1299 struct uvc_entity *entity;
1272 struct uvc_control *ctrl = NULL; 1300 struct uvc_control *ctrl = NULL;
1273 int ret, found = 0; 1301 int ret = 0, found = 0;
1274 unsigned int i; 1302 unsigned int i;
1303 u8 *uvc_info;
1304 u8 *uvc_data;
1275 1305
1276 list_for_each_entry(entity, &dev->entities, list) { 1306 list_for_each_entry(entity, &dev->entities, list) {
1277 if (!uvc_entity_match_guid(entity, info->entity)) 1307 if (!uvc_entity_match_guid(entity, info->entity))
@@ -1290,56 +1320,69 @@ static void uvc_ctrl_add_ctrl(struct uvc_device *dev,
1290 } 1320 }
1291 1321
1292 if (!found) 1322 if (!found)
1293 return; 1323 return 0;
1324
1325 uvc_data = kmalloc(info->size * UVC_CTRL_DATA_LAST + 1, GFP_KERNEL);
1326 if (uvc_data == NULL)
1327 return -ENOMEM;
1328
1329 uvc_info = uvc_data + info->size * UVC_CTRL_DATA_LAST;
1294 1330
1295 if (UVC_ENTITY_TYPE(entity) == UVC_VC_EXTENSION_UNIT) { 1331 if (UVC_ENTITY_TYPE(entity) == UVC_VC_EXTENSION_UNIT) {
1296 /* Check if the device control information and length match 1332 /* Check if the device control information and length match
1297 * the user supplied information. 1333 * the user supplied information.
1298 */ 1334 */
1299 __u32 flags;
1300 __le16 size;
1301 __u8 inf;
1302
1303 ret = uvc_query_ctrl(dev, UVC_GET_LEN, ctrl->entity->id, 1335 ret = uvc_query_ctrl(dev, UVC_GET_LEN, ctrl->entity->id,
1304 dev->intfnum, info->selector, (__u8 *)&size, 2); 1336 dev->intfnum, info->selector, uvc_data, 2);
1305 if (ret < 0) { 1337 if (ret < 0) {
1306 uvc_trace(UVC_TRACE_CONTROL, 1338 uvc_trace(UVC_TRACE_CONTROL,
1307 "GET_LEN failed on control %pUl/%u (%d).\n", 1339 "GET_LEN failed on control %pUl/%u (%d).\n",
1308 info->entity, info->selector, ret); 1340 info->entity, info->selector, ret);
1309 return; 1341 goto done;
1310 } 1342 }
1311 1343
1312 if (info->size != le16_to_cpu(size)) { 1344 if (info->size != le16_to_cpu(*(__le16 *)uvc_data)) {
1313 uvc_trace(UVC_TRACE_CONTROL, "Control %pUl/%u size " 1345 uvc_trace(UVC_TRACE_CONTROL, "Control %pUl/%u size "
1314 "doesn't match user supplied value.\n", 1346 "doesn't match user supplied value.\n",
1315 info->entity, info->selector); 1347 info->entity, info->selector);
1316 return; 1348 ret = -EINVAL;
1349 goto done;
1317 } 1350 }
1318 1351
1319 ret = uvc_query_ctrl(dev, UVC_GET_INFO, ctrl->entity->id, 1352 ret = uvc_query_ctrl(dev, UVC_GET_INFO, ctrl->entity->id,
1320 dev->intfnum, info->selector, &inf, 1); 1353 dev->intfnum, info->selector, uvc_info, 1);
1321 if (ret < 0) { 1354 if (ret < 0) {
1322 uvc_trace(UVC_TRACE_CONTROL, 1355 uvc_trace(UVC_TRACE_CONTROL,
1323 "GET_INFO failed on control %pUl/%u (%d).\n", 1356 "GET_INFO failed on control %pUl/%u (%d).\n",
1324 info->entity, info->selector, ret); 1357 info->entity, info->selector, ret);
1325 return; 1358 goto done;
1326 } 1359 }
1327 1360
1328 flags = info->flags; 1361 if (((info->flags & UVC_CONTROL_GET_CUR) &&
1329 if (((flags & UVC_CONTROL_GET_CUR) && !(inf & (1 << 0))) || 1362 !(*uvc_info & UVC_CONTROL_CAP_GET)) ||
1330 ((flags & UVC_CONTROL_SET_CUR) && !(inf & (1 << 1)))) { 1363 ((info->flags & UVC_CONTROL_SET_CUR) &&
1364 !(*uvc_info & UVC_CONTROL_CAP_SET))) {
1331 uvc_trace(UVC_TRACE_CONTROL, "Control %pUl/%u flags " 1365 uvc_trace(UVC_TRACE_CONTROL, "Control %pUl/%u flags "
1332 "don't match supported operations.\n", 1366 "don't match supported operations.\n",
1333 info->entity, info->selector); 1367 info->entity, info->selector);
1334 return; 1368 ret = -EINVAL;
1369 goto done;
1335 } 1370 }
1336 } 1371 }
1337 1372
1338 ctrl->info = info; 1373 ctrl->info = info;
1339 ctrl->data = kmalloc(ctrl->info->size * UVC_CTRL_DATA_LAST, GFP_KERNEL); 1374 ctrl->uvc_data = uvc_data;
1375 ctrl->uvc_info = uvc_info;
1376
1340 uvc_trace(UVC_TRACE_CONTROL, "Added control %pUl/%u to device %s " 1377 uvc_trace(UVC_TRACE_CONTROL, "Added control %pUl/%u to device %s "
1341 "entity %u\n", ctrl->info->entity, ctrl->info->selector, 1378 "entity %u\n", ctrl->info->entity, ctrl->info->selector,
1342 dev->udev->devpath, entity->id); 1379 dev->udev->devpath, entity->id);
1380
1381done:
1382 if (ret < 0)
1383 kfree(uvc_data);
1384
1385 return ret;
1343} 1386}
1344 1387
1345/* 1388/*
@@ -1572,12 +1615,34 @@ void uvc_ctrl_cleanup_device(struct uvc_device *dev)
1572 1615
1573 list_for_each_entry(entity, &dev->entities, list) { 1616 list_for_each_entry(entity, &dev->entities, list) {
1574 for (i = 0; i < entity->ncontrols; ++i) 1617 for (i = 0; i < entity->ncontrols; ++i)
1575 kfree(entity->controls[i].data); 1618 kfree(entity->controls[i].uvc_data);
1576 1619
1577 kfree(entity->controls); 1620 kfree(entity->controls);
1578 } 1621 }
1579} 1622}
1580 1623
1624void uvc_ctrl_cleanup(void)
1625{
1626 struct uvc_control_info *info;
1627 struct uvc_control_info *ni;
1628 struct uvc_control_mapping *mapping;
1629 struct uvc_control_mapping *nm;
1630
1631 list_for_each_entry_safe(info, ni, &uvc_driver.controls, list) {
1632 if (!(info->flags & UVC_CONTROL_EXTENSION))
1633 continue;
1634
1635 list_for_each_entry_safe(mapping, nm, &info->mappings, list) {
1636 list_del(&mapping->list);
1637 kfree(mapping->menu_info);
1638 kfree(mapping);
1639 }
1640
1641 list_del(&info->list);
1642 kfree(info);
1643 }
1644}
1645
1581void uvc_ctrl_init(void) 1646void uvc_ctrl_init(void)
1582{ 1647{
1583 struct uvc_control_info *ctrl = uvc_ctrls; 1648 struct uvc_control_info *ctrl = uvc_ctrls;
diff --git a/drivers/media/video/uvc/uvc_driver.c b/drivers/media/video/uvc/uvc_driver.c
index 838b56f097cf..7eaf99b22a48 100644
--- a/drivers/media/video/uvc/uvc_driver.c
+++ b/drivers/media/video/uvc/uvc_driver.c
@@ -637,14 +637,13 @@ static int uvc_parse_streaming(struct uvc_device *dev,
637 } 637 }
638 streaming->header.bControlSize = n; 638 streaming->header.bControlSize = n;
639 639
640 streaming->header.bmaControls = kmalloc(p*n, GFP_KERNEL); 640 streaming->header.bmaControls = kmemdup(&buffer[size], p * n,
641 GFP_KERNEL);
641 if (streaming->header.bmaControls == NULL) { 642 if (streaming->header.bmaControls == NULL) {
642 ret = -ENOMEM; 643 ret = -ENOMEM;
643 goto error; 644 goto error;
644 } 645 }
645 646
646 memcpy(streaming->header.bmaControls, &buffer[size], p*n);
647
648 buflen -= buffer[0]; 647 buflen -= buffer[0];
649 buffer += buffer[0]; 648 buffer += buffer[0];
650 649
@@ -2174,6 +2173,15 @@ static struct usb_device_id uvc_ids[] = {
2174 .bInterfaceSubClass = 1, 2173 .bInterfaceSubClass = 1,
2175 .bInterfaceProtocol = 0, 2174 .bInterfaceProtocol = 0,
2176 .driver_info = UVC_QUIRK_PROBE_EXTRAFIELDS }, 2175 .driver_info = UVC_QUIRK_PROBE_EXTRAFIELDS },
2176 /* Manta MM-353 Plako */
2177 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2178 | USB_DEVICE_ID_MATCH_INT_INFO,
2179 .idVendor = 0x18ec,
2180 .idProduct = 0x3188,
2181 .bInterfaceClass = USB_CLASS_VIDEO,
2182 .bInterfaceSubClass = 1,
2183 .bInterfaceProtocol = 0,
2184 .driver_info = UVC_QUIRK_PROBE_MINMAX },
2177 /* FSC WebCam V30S */ 2185 /* FSC WebCam V30S */
2178 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 2186 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2179 | USB_DEVICE_ID_MATCH_INT_INFO, 2187 | USB_DEVICE_ID_MATCH_INT_INFO,
@@ -2261,6 +2269,7 @@ static int __init uvc_init(void)
2261static void __exit uvc_cleanup(void) 2269static void __exit uvc_cleanup(void)
2262{ 2270{
2263 usb_deregister(&uvc_driver.driver); 2271 usb_deregister(&uvc_driver.driver);
2272 uvc_ctrl_cleanup();
2264} 2273}
2265 2274
2266module_init(uvc_init); 2275module_init(uvc_init);
diff --git a/drivers/media/video/uvc/uvc_v4l2.c b/drivers/media/video/uvc/uvc_v4l2.c
index 7c9ab2933496..86db32697b80 100644
--- a/drivers/media/video/uvc/uvc_v4l2.c
+++ b/drivers/media/video/uvc/uvc_v4l2.c
@@ -29,6 +29,71 @@
29#include "uvcvideo.h" 29#include "uvcvideo.h"
30 30
31/* ------------------------------------------------------------------------ 31/* ------------------------------------------------------------------------
32 * UVC ioctls
33 */
34static int uvc_ioctl_ctrl_map(struct uvc_xu_control_mapping *xmap, int old)
35{
36 struct uvc_control_mapping *map;
37 unsigned int size;
38 int ret;
39
40 map = kzalloc(sizeof *map, GFP_KERNEL);
41 if (map == NULL)
42 return -ENOMEM;
43
44 map->id = xmap->id;
45 memcpy(map->name, xmap->name, sizeof map->name);
46 memcpy(map->entity, xmap->entity, sizeof map->entity);
47 map->selector = xmap->selector;
48 map->size = xmap->size;
49 map->offset = xmap->offset;
50 map->v4l2_type = xmap->v4l2_type;
51 map->data_type = xmap->data_type;
52
53 switch (xmap->v4l2_type) {
54 case V4L2_CTRL_TYPE_INTEGER:
55 case V4L2_CTRL_TYPE_BOOLEAN:
56 case V4L2_CTRL_TYPE_BUTTON:
57 break;
58
59 case V4L2_CTRL_TYPE_MENU:
60 if (old) {
61 ret = -EINVAL;
62 goto done;
63 }
64
65 size = xmap->menu_count * sizeof(*map->menu_info);
66 map->menu_info = kmalloc(size, GFP_KERNEL);
67 if (map->menu_info == NULL) {
68 ret = -ENOMEM;
69 goto done;
70 }
71
72 if (copy_from_user(map->menu_info, xmap->menu_info, size)) {
73 ret = -EFAULT;
74 goto done;
75 }
76
77 map->menu_count = xmap->menu_count;
78 break;
79
80 default:
81 ret = -EINVAL;
82 goto done;
83 }
84
85 ret = uvc_ctrl_add_mapping(map);
86
87done:
88 if (ret < 0) {
89 kfree(map->menu_info);
90 kfree(map);
91 }
92
93 return ret;
94}
95
96/* ------------------------------------------------------------------------
32 * V4L2 interface 97 * V4L2 interface
33 */ 98 */
34 99
@@ -451,7 +516,7 @@ static int uvc_v4l2_open(struct file *file)
451 516
452static int uvc_v4l2_release(struct file *file) 517static int uvc_v4l2_release(struct file *file)
453{ 518{
454 struct uvc_fh *handle = (struct uvc_fh *)file->private_data; 519 struct uvc_fh *handle = file->private_data;
455 struct uvc_streaming *stream = handle->stream; 520 struct uvc_streaming *stream = handle->stream;
456 521
457 uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_release\n"); 522 uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_release\n");
@@ -482,7 +547,7 @@ static int uvc_v4l2_release(struct file *file)
482static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg) 547static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
483{ 548{
484 struct video_device *vdev = video_devdata(file); 549 struct video_device *vdev = video_devdata(file);
485 struct uvc_fh *handle = (struct uvc_fh *)file->private_data; 550 struct uvc_fh *handle = file->private_data;
486 struct uvc_video_chain *chain = handle->chain; 551 struct uvc_video_chain *chain = handle->chain;
487 struct uvc_streaming *stream = handle->stream; 552 struct uvc_streaming *stream = handle->stream;
488 long ret = 0; 553 long ret = 0;
@@ -963,6 +1028,9 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
963 if (!capable(CAP_SYS_ADMIN)) 1028 if (!capable(CAP_SYS_ADMIN))
964 return -EPERM; 1029 return -EPERM;
965 1030
1031 if (xinfo->size == 0)
1032 return -EINVAL;
1033
966 info = kzalloc(sizeof *info, GFP_KERNEL); 1034 info = kzalloc(sizeof *info, GFP_KERNEL);
967 if (info == NULL) 1035 if (info == NULL)
968 return -ENOMEM; 1036 return -ENOMEM;
@@ -974,7 +1042,8 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
974 info->flags = xinfo->flags; 1042 info->flags = xinfo->flags;
975 1043
976 info->flags |= UVC_CONTROL_GET_MIN | UVC_CONTROL_GET_MAX | 1044 info->flags |= UVC_CONTROL_GET_MIN | UVC_CONTROL_GET_MAX |
977 UVC_CONTROL_GET_RES | UVC_CONTROL_GET_DEF; 1045 UVC_CONTROL_GET_RES | UVC_CONTROL_GET_DEF |
1046 UVC_CONTROL_EXTENSION;
978 1047
979 ret = uvc_ctrl_add_info(info); 1048 ret = uvc_ctrl_add_info(info);
980 if (ret < 0) 1049 if (ret < 0)
@@ -982,32 +1051,12 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
982 break; 1051 break;
983 } 1052 }
984 1053
1054 case UVCIOC_CTRL_MAP_OLD:
985 case UVCIOC_CTRL_MAP: 1055 case UVCIOC_CTRL_MAP:
986 {
987 struct uvc_xu_control_mapping *xmap = arg;
988 struct uvc_control_mapping *map;
989
990 if (!capable(CAP_SYS_ADMIN)) 1056 if (!capable(CAP_SYS_ADMIN))
991 return -EPERM; 1057 return -EPERM;
992 1058
993 map = kzalloc(sizeof *map, GFP_KERNEL); 1059 return uvc_ioctl_ctrl_map(arg, cmd == UVCIOC_CTRL_MAP_OLD);
994 if (map == NULL)
995 return -ENOMEM;
996
997 map->id = xmap->id;
998 memcpy(map->name, xmap->name, sizeof map->name);
999 memcpy(map->entity, xmap->entity, sizeof map->entity);
1000 map->selector = xmap->selector;
1001 map->size = xmap->size;
1002 map->offset = xmap->offset;
1003 map->v4l2_type = xmap->v4l2_type;
1004 map->data_type = xmap->data_type;
1005
1006 ret = uvc_ctrl_add_mapping(map);
1007 if (ret < 0)
1008 kfree(map);
1009 break;
1010 }
1011 1060
1012 case UVCIOC_CTRL_GET: 1061 case UVCIOC_CTRL_GET:
1013 return uvc_xu_ctrl_query(chain, arg, 0); 1062 return uvc_xu_ctrl_query(chain, arg, 0);
@@ -1067,7 +1116,7 @@ static const struct vm_operations_struct uvc_vm_ops = {
1067 1116
1068static int uvc_v4l2_mmap(struct file *file, struct vm_area_struct *vma) 1117static int uvc_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
1069{ 1118{
1070 struct uvc_fh *handle = (struct uvc_fh *)file->private_data; 1119 struct uvc_fh *handle = file->private_data;
1071 struct uvc_streaming *stream = handle->stream; 1120 struct uvc_streaming *stream = handle->stream;
1072 struct uvc_video_queue *queue = &stream->queue; 1121 struct uvc_video_queue *queue = &stream->queue;
1073 struct uvc_buffer *uninitialized_var(buffer); 1122 struct uvc_buffer *uninitialized_var(buffer);
@@ -1122,7 +1171,7 @@ done:
1122 1171
1123static unsigned int uvc_v4l2_poll(struct file *file, poll_table *wait) 1172static unsigned int uvc_v4l2_poll(struct file *file, poll_table *wait)
1124{ 1173{
1125 struct uvc_fh *handle = (struct uvc_fh *)file->private_data; 1174 struct uvc_fh *handle = file->private_data;
1126 struct uvc_streaming *stream = handle->stream; 1175 struct uvc_streaming *stream = handle->stream;
1127 1176
1128 uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_poll\n"); 1177 uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_poll\n");
diff --git a/drivers/media/video/uvc/uvcvideo.h b/drivers/media/video/uvc/uvcvideo.h
index d1f88406a5e7..ac272456fbfd 100644
--- a/drivers/media/video/uvc/uvcvideo.h
+++ b/drivers/media/video/uvc/uvcvideo.h
@@ -27,6 +27,8 @@
27#define UVC_CONTROL_RESTORE (1 << 6) 27#define UVC_CONTROL_RESTORE (1 << 6)
28/* Control can be updated by the camera. */ 28/* Control can be updated by the camera. */
29#define UVC_CONTROL_AUTO_UPDATE (1 << 7) 29#define UVC_CONTROL_AUTO_UPDATE (1 << 7)
30/* Control is an extension unit control. */
31#define UVC_CONTROL_EXTENSION (1 << 8)
30 32
31#define UVC_CONTROL_GET_RANGE (UVC_CONTROL_GET_CUR | UVC_CONTROL_GET_MIN | \ 33#define UVC_CONTROL_GET_RANGE (UVC_CONTROL_GET_CUR | UVC_CONTROL_GET_MIN | \
32 UVC_CONTROL_GET_MAX | UVC_CONTROL_GET_RES | \ 34 UVC_CONTROL_GET_MAX | UVC_CONTROL_GET_RES | \
@@ -40,6 +42,15 @@ struct uvc_xu_control_info {
40 __u32 flags; 42 __u32 flags;
41}; 43};
42 44
45struct uvc_menu_info {
46 __u32 value;
47 __u8 name[32];
48};
49
50struct uvc_xu_control_mapping_old {
51 __u8 reserved[64];
52};
53
43struct uvc_xu_control_mapping { 54struct uvc_xu_control_mapping {
44 __u32 id; 55 __u32 id;
45 __u8 name[32]; 56 __u8 name[32];
@@ -50,6 +61,11 @@ struct uvc_xu_control_mapping {
50 __u8 offset; 61 __u8 offset;
51 enum v4l2_ctrl_type v4l2_type; 62 enum v4l2_ctrl_type v4l2_type;
52 __u32 data_type; 63 __u32 data_type;
64
65 struct uvc_menu_info __user *menu_info;
66 __u32 menu_count;
67
68 __u32 reserved[4];
53}; 69};
54 70
55struct uvc_xu_control { 71struct uvc_xu_control {
@@ -60,6 +76,7 @@ struct uvc_xu_control {
60}; 76};
61 77
62#define UVCIOC_CTRL_ADD _IOW('U', 1, struct uvc_xu_control_info) 78#define UVCIOC_CTRL_ADD _IOW('U', 1, struct uvc_xu_control_info)
79#define UVCIOC_CTRL_MAP_OLD _IOWR('U', 2, struct uvc_xu_control_mapping_old)
63#define UVCIOC_CTRL_MAP _IOWR('U', 2, struct uvc_xu_control_mapping) 80#define UVCIOC_CTRL_MAP _IOWR('U', 2, struct uvc_xu_control_mapping)
64#define UVCIOC_CTRL_GET _IOWR('U', 3, struct uvc_xu_control) 81#define UVCIOC_CTRL_GET _IOWR('U', 3, struct uvc_xu_control)
65#define UVCIOC_CTRL_SET _IOW('U', 4, struct uvc_xu_control) 82#define UVCIOC_CTRL_SET _IOW('U', 4, struct uvc_xu_control)
@@ -179,30 +196,6 @@ struct uvc_device;
179/* TODO: Put the most frequently accessed fields at the beginning of 196/* TODO: Put the most frequently accessed fields at the beginning of
180 * structures to maximize cache efficiency. 197 * structures to maximize cache efficiency.
181 */ 198 */
182struct uvc_streaming_control {
183 __u16 bmHint;
184 __u8 bFormatIndex;
185 __u8 bFrameIndex;
186 __u32 dwFrameInterval;
187 __u16 wKeyFrameRate;
188 __u16 wPFrameRate;
189 __u16 wCompQuality;
190 __u16 wCompWindowSize;
191 __u16 wDelay;
192 __u32 dwMaxVideoFrameSize;
193 __u32 dwMaxPayloadTransferSize;
194 __u32 dwClockFrequency;
195 __u8 bmFramingInfo;
196 __u8 bPreferedVersion;
197 __u8 bMinVersion;
198 __u8 bMaxVersion;
199};
200
201struct uvc_menu_info {
202 __u32 value;
203 __u8 name[32];
204};
205
206struct uvc_control_info { 199struct uvc_control_info {
207 struct list_head list; 200 struct list_head list;
208 struct list_head mappings; 201 struct list_head mappings;
@@ -250,7 +243,8 @@ struct uvc_control {
250 modified : 1, 243 modified : 1,
251 cached : 1; 244 cached : 1;
252 245
253 __u8 *data; 246 __u8 *uvc_data;
247 __u8 *uvc_info;
254}; 248};
255 249
256struct uvc_format_desc { 250struct uvc_format_desc {
@@ -625,6 +619,7 @@ extern int uvc_ctrl_init_device(struct uvc_device *dev);
625extern void uvc_ctrl_cleanup_device(struct uvc_device *dev); 619extern void uvc_ctrl_cleanup_device(struct uvc_device *dev);
626extern int uvc_ctrl_resume_device(struct uvc_device *dev); 620extern int uvc_ctrl_resume_device(struct uvc_device *dev);
627extern void uvc_ctrl_init(void); 621extern void uvc_ctrl_init(void);
622extern void uvc_ctrl_cleanup(void);
628 623
629extern int uvc_ctrl_begin(struct uvc_video_chain *chain); 624extern int uvc_ctrl_begin(struct uvc_video_chain *chain);
630extern int __uvc_ctrl_commit(struct uvc_video_chain *chain, int rollback); 625extern int __uvc_ctrl_commit(struct uvc_video_chain *chain, int rollback);
diff --git a/drivers/media/video/v4l2-dev.c b/drivers/media/video/v4l2-dev.c
index 0ca7ec9ca902..9e89bf617790 100644
--- a/drivers/media/video/v4l2-dev.c
+++ b/drivers/media/video/v4l2-dev.c
@@ -410,7 +410,7 @@ static int __video_register_device(struct video_device *vdev, int type, int nr,
410 int minor_offset = 0; 410 int minor_offset = 0;
411 int minor_cnt = VIDEO_NUM_DEVICES; 411 int minor_cnt = VIDEO_NUM_DEVICES;
412 const char *name_base; 412 const char *name_base;
413 void *priv = video_get_drvdata(vdev); 413 void *priv = vdev->dev.p;
414 414
415 /* A minor value of -1 marks this video device as never 415 /* A minor value of -1 marks this video device as never
416 having been registered */ 416 having been registered */
@@ -536,9 +536,9 @@ static int __video_register_device(struct video_device *vdev, int type, int nr,
536 536
537 /* Part 4: register the device with sysfs */ 537 /* Part 4: register the device with sysfs */
538 memset(&vdev->dev, 0, sizeof(vdev->dev)); 538 memset(&vdev->dev, 0, sizeof(vdev->dev));
539 /* The memset above cleared the device's drvdata, so 539 /* The memset above cleared the device's device_private, so
540 put back the copy we made earlier. */ 540 put back the copy we made earlier. */
541 video_set_drvdata(vdev, priv); 541 vdev->dev.p = priv;
542 vdev->dev.class = &video_class; 542 vdev->dev.class = &video_class;
543 vdev->dev.devt = MKDEV(VIDEO_MAJOR, vdev->minor); 543 vdev->dev.devt = MKDEV(VIDEO_MAJOR, vdev->minor);
544 if (vdev->parent) 544 if (vdev->parent)
diff --git a/drivers/media/video/videobuf-core.c b/drivers/media/video/videobuf-core.c
index 7d3378437ded..ce1595bef629 100644
--- a/drivers/media/video/videobuf-core.c
+++ b/drivers/media/video/videobuf-core.c
@@ -52,18 +52,18 @@ MODULE_LICENSE("GPL");
52#define CALL(q, f, arg...) \ 52#define CALL(q, f, arg...) \
53 ((q->int_ops->f) ? q->int_ops->f(arg) : 0) 53 ((q->int_ops->f) ? q->int_ops->f(arg) : 0)
54 54
55struct videobuf_buffer *videobuf_alloc(struct videobuf_queue *q) 55struct videobuf_buffer *videobuf_alloc_vb(struct videobuf_queue *q)
56{ 56{
57 struct videobuf_buffer *vb; 57 struct videobuf_buffer *vb;
58 58
59 BUG_ON(q->msize < sizeof(*vb)); 59 BUG_ON(q->msize < sizeof(*vb));
60 60
61 if (!q->int_ops || !q->int_ops->alloc) { 61 if (!q->int_ops || !q->int_ops->alloc_vb) {
62 printk(KERN_ERR "No specific ops defined!\n"); 62 printk(KERN_ERR "No specific ops defined!\n");
63 BUG(); 63 BUG();
64 } 64 }
65 65
66 vb = q->int_ops->alloc(q->msize); 66 vb = q->int_ops->alloc_vb(q->msize);
67 if (NULL != vb) { 67 if (NULL != vb) {
68 init_waitqueue_head(&vb->done); 68 init_waitqueue_head(&vb->done);
69 vb->magic = MAGIC_BUFFER; 69 vb->magic = MAGIC_BUFFER;
@@ -71,7 +71,7 @@ struct videobuf_buffer *videobuf_alloc(struct videobuf_queue *q)
71 71
72 return vb; 72 return vb;
73} 73}
74EXPORT_SYMBOL_GPL(videobuf_alloc); 74EXPORT_SYMBOL_GPL(videobuf_alloc_vb);
75 75
76#define WAITON_CONDITION (vb->state != VIDEOBUF_ACTIVE &&\ 76#define WAITON_CONDITION (vb->state != VIDEOBUF_ACTIVE &&\
77 vb->state != VIDEOBUF_QUEUED) 77 vb->state != VIDEOBUF_QUEUED)
@@ -195,6 +195,45 @@ int videobuf_queue_is_busy(struct videobuf_queue *q)
195} 195}
196EXPORT_SYMBOL_GPL(videobuf_queue_is_busy); 196EXPORT_SYMBOL_GPL(videobuf_queue_is_busy);
197 197
198/**
199 * __videobuf_free() - free all the buffers and their control structures
200 *
201 * This function can only be called if streaming/reading is off, i.e. no buffers
202 * are under control of the driver.
203 */
204/* Locking: Caller holds q->vb_lock */
205static int __videobuf_free(struct videobuf_queue *q)
206{
207 int i;
208
209 dprintk(1, "%s\n", __func__);
210 if (!q)
211 return 0;
212
213 if (q->streaming || q->reading) {
214 dprintk(1, "Cannot free buffers when streaming or reading\n");
215 return -EBUSY;
216 }
217
218 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
219
220 for (i = 0; i < VIDEO_MAX_FRAME; i++)
221 if (q->bufs[i] && q->bufs[i]->map) {
222 dprintk(1, "Cannot free mmapped buffers\n");
223 return -EBUSY;
224 }
225
226 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
227 if (NULL == q->bufs[i])
228 continue;
229 q->ops->buf_release(q, q->bufs[i]);
230 kfree(q->bufs[i]);
231 q->bufs[i] = NULL;
232 }
233
234 return 0;
235}
236
198/* Locking: Caller holds q->vb_lock */ 237/* Locking: Caller holds q->vb_lock */
199void videobuf_queue_cancel(struct videobuf_queue *q) 238void videobuf_queue_cancel(struct videobuf_queue *q)
200{ 239{
@@ -308,36 +347,11 @@ static void videobuf_status(struct videobuf_queue *q, struct v4l2_buffer *b,
308 b->sequence = vb->field_count >> 1; 347 b->sequence = vb->field_count >> 1;
309} 348}
310 349
311/* Locking: Caller holds q->vb_lock */
312static int __videobuf_mmap_free(struct videobuf_queue *q)
313{
314 int i;
315
316 if (!q)
317 return 0;
318
319 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
320
321 for (i = 0; i < VIDEO_MAX_FRAME; i++)
322 if (q->bufs[i] && q->bufs[i]->map)
323 return -EBUSY;
324
325 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
326 if (NULL == q->bufs[i])
327 continue;
328 q->ops->buf_release(q, q->bufs[i]);
329 kfree(q->bufs[i]);
330 q->bufs[i] = NULL;
331 }
332
333 return 0;
334}
335
336int videobuf_mmap_free(struct videobuf_queue *q) 350int videobuf_mmap_free(struct videobuf_queue *q)
337{ 351{
338 int ret; 352 int ret;
339 mutex_lock(&q->vb_lock); 353 mutex_lock(&q->vb_lock);
340 ret = __videobuf_mmap_free(q); 354 ret = __videobuf_free(q);
341 mutex_unlock(&q->vb_lock); 355 mutex_unlock(&q->vb_lock);
342 return ret; 356 return ret;
343} 357}
@@ -353,13 +367,13 @@ int __videobuf_mmap_setup(struct videobuf_queue *q,
353 367
354 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS); 368 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
355 369
356 err = __videobuf_mmap_free(q); 370 err = __videobuf_free(q);
357 if (0 != err) 371 if (0 != err)
358 return err; 372 return err;
359 373
360 /* Allocate and initialize buffers */ 374 /* Allocate and initialize buffers */
361 for (i = 0; i < bcount; i++) { 375 for (i = 0; i < bcount; i++) {
362 q->bufs[i] = videobuf_alloc(q); 376 q->bufs[i] = videobuf_alloc_vb(q);
363 377
364 if (NULL == q->bufs[i]) 378 if (NULL == q->bufs[i])
365 break; 379 break;
@@ -766,7 +780,7 @@ static ssize_t videobuf_read_zerocopy(struct videobuf_queue *q,
766 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS); 780 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
767 781
768 /* setup stuff */ 782 /* setup stuff */
769 q->read_buf = videobuf_alloc(q); 783 q->read_buf = videobuf_alloc_vb(q);
770 if (NULL == q->read_buf) 784 if (NULL == q->read_buf)
771 return -ENOMEM; 785 return -ENOMEM;
772 786
@@ -871,7 +885,7 @@ ssize_t videobuf_read_one(struct videobuf_queue *q,
871 if (NULL == q->read_buf) { 885 if (NULL == q->read_buf) {
872 /* need to capture a new frame */ 886 /* need to capture a new frame */
873 retval = -ENOMEM; 887 retval = -ENOMEM;
874 q->read_buf = videobuf_alloc(q); 888 q->read_buf = videobuf_alloc_vb(q);
875 889
876 dprintk(1, "video alloc=0x%p\n", q->read_buf); 890 dprintk(1, "video alloc=0x%p\n", q->read_buf);
877 if (NULL == q->read_buf) 891 if (NULL == q->read_buf)
@@ -970,7 +984,7 @@ static void __videobuf_read_stop(struct videobuf_queue *q)
970 int i; 984 int i;
971 985
972 videobuf_queue_cancel(q); 986 videobuf_queue_cancel(q);
973 __videobuf_mmap_free(q); 987 __videobuf_free(q);
974 INIT_LIST_HEAD(&q->stream); 988 INIT_LIST_HEAD(&q->stream);
975 for (i = 0; i < VIDEO_MAX_FRAME; i++) { 989 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
976 if (NULL == q->bufs[i]) 990 if (NULL == q->bufs[i])
diff --git a/drivers/media/video/videobuf-dma-contig.c b/drivers/media/video/videobuf-dma-contig.c
index 74730c624cfc..372b87efcd05 100644
--- a/drivers/media/video/videobuf-dma-contig.c
+++ b/drivers/media/video/videobuf-dma-contig.c
@@ -190,7 +190,7 @@ static int videobuf_dma_contig_user_get(struct videobuf_dma_contig_memory *mem,
190 return ret; 190 return ret;
191} 191}
192 192
193static struct videobuf_buffer *__videobuf_alloc(size_t size) 193static struct videobuf_buffer *__videobuf_alloc_vb(size_t size)
194{ 194{
195 struct videobuf_dma_contig_memory *mem; 195 struct videobuf_dma_contig_memory *mem;
196 struct videobuf_buffer *vb; 196 struct videobuf_buffer *vb;
@@ -280,8 +280,6 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
280 return -ENOMEM; 280 return -ENOMEM;
281 281
282 buf->map = map; 282 buf->map = map;
283 map->start = vma->vm_start;
284 map->end = vma->vm_end;
285 map->q = q; 283 map->q = q;
286 284
287 buf->baddr = vma->vm_start; 285 buf->baddr = vma->vm_start;
@@ -338,7 +336,7 @@ error:
338static struct videobuf_qtype_ops qops = { 336static struct videobuf_qtype_ops qops = {
339 .magic = MAGIC_QTYPE_OPS, 337 .magic = MAGIC_QTYPE_OPS,
340 338
341 .alloc = __videobuf_alloc, 339 .alloc_vb = __videobuf_alloc_vb,
342 .iolock = __videobuf_iolock, 340 .iolock = __videobuf_iolock,
343 .mmap_mapper = __videobuf_mmap_mapper, 341 .mmap_mapper = __videobuf_mmap_mapper,
344 .vaddr = __videobuf_to_vaddr, 342 .vaddr = __videobuf_to_vaddr,
diff --git a/drivers/media/video/videobuf-dma-sg.c b/drivers/media/video/videobuf-dma-sg.c
index 8359e6badd36..06f9a9c2a39a 100644
--- a/drivers/media/video/videobuf-dma-sg.c
+++ b/drivers/media/video/videobuf-dma-sg.c
@@ -57,7 +57,13 @@ MODULE_LICENSE("GPL");
57 57
58/* --------------------------------------------------------------------- */ 58/* --------------------------------------------------------------------- */
59 59
60struct scatterlist *videobuf_vmalloc_to_sg(unsigned char *virt, int nr_pages) 60/*
61 * Return a scatterlist for some page-aligned vmalloc()'ed memory
62 * block (NULL on errors). Memory for the scatterlist is allocated
63 * using kmalloc. The caller must free the memory.
64 */
65static struct scatterlist *videobuf_vmalloc_to_sg(unsigned char *virt,
66 int nr_pages)
61{ 67{
62 struct scatterlist *sglist; 68 struct scatterlist *sglist;
63 struct page *pg; 69 struct page *pg;
@@ -81,10 +87,14 @@ err:
81 vfree(sglist); 87 vfree(sglist);
82 return NULL; 88 return NULL;
83} 89}
84EXPORT_SYMBOL_GPL(videobuf_vmalloc_to_sg);
85 90
86struct scatterlist *videobuf_pages_to_sg(struct page **pages, int nr_pages, 91/*
87 int offset) 92 * Return a scatterlist for a an array of userpages (NULL on errors).
93 * Memory for the scatterlist is allocated using kmalloc. The caller
94 * must free the memory.
95 */
96static struct scatterlist *videobuf_pages_to_sg(struct page **pages,
97 int nr_pages, int offset)
88{ 98{
89 struct scatterlist *sglist; 99 struct scatterlist *sglist;
90 int i; 100 int i;
@@ -201,17 +211,17 @@ int videobuf_dma_init_kernel(struct videobuf_dmabuf *dma, int direction,
201 dprintk(1, "init kernel [%d pages]\n", nr_pages); 211 dprintk(1, "init kernel [%d pages]\n", nr_pages);
202 212
203 dma->direction = direction; 213 dma->direction = direction;
204 dma->vmalloc = vmalloc_32(nr_pages << PAGE_SHIFT); 214 dma->vaddr = vmalloc_32(nr_pages << PAGE_SHIFT);
205 if (NULL == dma->vmalloc) { 215 if (NULL == dma->vaddr) {
206 dprintk(1, "vmalloc_32(%d pages) failed\n", nr_pages); 216 dprintk(1, "vmalloc_32(%d pages) failed\n", nr_pages);
207 return -ENOMEM; 217 return -ENOMEM;
208 } 218 }
209 219
210 dprintk(1, "vmalloc is at addr 0x%08lx, size=%d\n", 220 dprintk(1, "vmalloc is at addr 0x%08lx, size=%d\n",
211 (unsigned long)dma->vmalloc, 221 (unsigned long)dma->vaddr,
212 nr_pages << PAGE_SHIFT); 222 nr_pages << PAGE_SHIFT);
213 223
214 memset(dma->vmalloc, 0, nr_pages << PAGE_SHIFT); 224 memset(dma->vaddr, 0, nr_pages << PAGE_SHIFT);
215 dma->nr_pages = nr_pages; 225 dma->nr_pages = nr_pages;
216 226
217 return 0; 227 return 0;
@@ -235,7 +245,7 @@ int videobuf_dma_init_overlay(struct videobuf_dmabuf *dma, int direction,
235} 245}
236EXPORT_SYMBOL_GPL(videobuf_dma_init_overlay); 246EXPORT_SYMBOL_GPL(videobuf_dma_init_overlay);
237 247
238int videobuf_dma_map(struct videobuf_queue *q, struct videobuf_dmabuf *dma) 248int videobuf_dma_map(struct device *dev, struct videobuf_dmabuf *dma)
239{ 249{
240 MAGIC_CHECK(dma->magic, MAGIC_DMABUF); 250 MAGIC_CHECK(dma->magic, MAGIC_DMABUF);
241 BUG_ON(0 == dma->nr_pages); 251 BUG_ON(0 == dma->nr_pages);
@@ -244,8 +254,8 @@ int videobuf_dma_map(struct videobuf_queue *q, struct videobuf_dmabuf *dma)
244 dma->sglist = videobuf_pages_to_sg(dma->pages, dma->nr_pages, 254 dma->sglist = videobuf_pages_to_sg(dma->pages, dma->nr_pages,
245 dma->offset); 255 dma->offset);
246 } 256 }
247 if (dma->vmalloc) { 257 if (dma->vaddr) {
248 dma->sglist = videobuf_vmalloc_to_sg(dma->vmalloc, 258 dma->sglist = videobuf_vmalloc_to_sg(dma->vaddr,
249 dma->nr_pages); 259 dma->nr_pages);
250 } 260 }
251 if (dma->bus_addr) { 261 if (dma->bus_addr) {
@@ -263,7 +273,7 @@ int videobuf_dma_map(struct videobuf_queue *q, struct videobuf_dmabuf *dma)
263 return -ENOMEM; 273 return -ENOMEM;
264 } 274 }
265 if (!dma->bus_addr) { 275 if (!dma->bus_addr) {
266 dma->sglen = dma_map_sg(q->dev, dma->sglist, 276 dma->sglen = dma_map_sg(dev, dma->sglist,
267 dma->nr_pages, dma->direction); 277 dma->nr_pages, dma->direction);
268 if (0 == dma->sglen) { 278 if (0 == dma->sglen) {
269 printk(KERN_WARNING 279 printk(KERN_WARNING
@@ -279,14 +289,14 @@ int videobuf_dma_map(struct videobuf_queue *q, struct videobuf_dmabuf *dma)
279} 289}
280EXPORT_SYMBOL_GPL(videobuf_dma_map); 290EXPORT_SYMBOL_GPL(videobuf_dma_map);
281 291
282int videobuf_dma_unmap(struct videobuf_queue *q, struct videobuf_dmabuf *dma) 292int videobuf_dma_unmap(struct device *dev, struct videobuf_dmabuf *dma)
283{ 293{
284 MAGIC_CHECK(dma->magic, MAGIC_DMABUF); 294 MAGIC_CHECK(dma->magic, MAGIC_DMABUF);
285 295
286 if (!dma->sglen) 296 if (!dma->sglen)
287 return 0; 297 return 0;
288 298
289 dma_unmap_sg(q->dev, dma->sglist, dma->sglen, dma->direction); 299 dma_unmap_sg(dev, dma->sglist, dma->sglen, dma->direction);
290 300
291 vfree(dma->sglist); 301 vfree(dma->sglist);
292 dma->sglist = NULL; 302 dma->sglist = NULL;
@@ -309,8 +319,8 @@ int videobuf_dma_free(struct videobuf_dmabuf *dma)
309 dma->pages = NULL; 319 dma->pages = NULL;
310 } 320 }
311 321
312 vfree(dma->vmalloc); 322 vfree(dma->vaddr);
313 dma->vmalloc = NULL; 323 dma->vaddr = NULL;
314 324
315 if (dma->bus_addr) 325 if (dma->bus_addr)
316 dma->bus_addr = 0; 326 dma->bus_addr = 0;
@@ -322,28 +332,6 @@ EXPORT_SYMBOL_GPL(videobuf_dma_free);
322 332
323/* --------------------------------------------------------------------- */ 333/* --------------------------------------------------------------------- */
324 334
325int videobuf_sg_dma_map(struct device *dev, struct videobuf_dmabuf *dma)
326{
327 struct videobuf_queue q;
328
329 q.dev = dev;
330
331 return videobuf_dma_map(&q, dma);
332}
333EXPORT_SYMBOL_GPL(videobuf_sg_dma_map);
334
335int videobuf_sg_dma_unmap(struct device *dev, struct videobuf_dmabuf *dma)
336{
337 struct videobuf_queue q;
338
339 q.dev = dev;
340
341 return videobuf_dma_unmap(&q, dma);
342}
343EXPORT_SYMBOL_GPL(videobuf_sg_dma_unmap);
344
345/* --------------------------------------------------------------------- */
346
347static void videobuf_vm_open(struct vm_area_struct *vma) 335static void videobuf_vm_open(struct vm_area_struct *vma)
348{ 336{
349 struct videobuf_mapping *map = vma->vm_private_data; 337 struct videobuf_mapping *map = vma->vm_private_data;
@@ -428,7 +416,7 @@ static const struct vm_operations_struct videobuf_vm_ops = {
428 struct videobuf_dma_sg_memory 416 struct videobuf_dma_sg_memory
429 */ 417 */
430 418
431static struct videobuf_buffer *__videobuf_alloc(size_t size) 419static struct videobuf_buffer *__videobuf_alloc_vb(size_t size)
432{ 420{
433 struct videobuf_dma_sg_memory *mem; 421 struct videobuf_dma_sg_memory *mem;
434 struct videobuf_buffer *vb; 422 struct videobuf_buffer *vb;
@@ -456,7 +444,7 @@ static void *__videobuf_to_vaddr(struct videobuf_buffer *buf)
456 444
457 MAGIC_CHECK(mem->magic, MAGIC_SG_MEM); 445 MAGIC_CHECK(mem->magic, MAGIC_SG_MEM);
458 446
459 return mem->dma.vmalloc; 447 return mem->dma.vaddr;
460} 448}
461 449
462static int __videobuf_iolock(struct videobuf_queue *q, 450static int __videobuf_iolock(struct videobuf_queue *q,
@@ -520,7 +508,7 @@ static int __videobuf_iolock(struct videobuf_queue *q,
520 default: 508 default:
521 BUG(); 509 BUG();
522 } 510 }
523 err = videobuf_dma_map(q, &mem->dma); 511 err = videobuf_dma_map(q->dev, &mem->dma);
524 if (0 != err) 512 if (0 != err)
525 return err; 513 return err;
526 514
@@ -620,8 +608,6 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
620 } 608 }
621 609
622 map->count = 1; 610 map->count = 1;
623 map->start = vma->vm_start;
624 map->end = vma->vm_end;
625 map->q = q; 611 map->q = q;
626 vma->vm_ops = &videobuf_vm_ops; 612 vma->vm_ops = &videobuf_vm_ops;
627 vma->vm_flags |= VM_DONTEXPAND | VM_RESERVED; 613 vma->vm_flags |= VM_DONTEXPAND | VM_RESERVED;
@@ -638,7 +624,7 @@ done:
638static struct videobuf_qtype_ops sg_ops = { 624static struct videobuf_qtype_ops sg_ops = {
639 .magic = MAGIC_QTYPE_OPS, 625 .magic = MAGIC_QTYPE_OPS,
640 626
641 .alloc = __videobuf_alloc, 627 .alloc_vb = __videobuf_alloc_vb,
642 .iolock = __videobuf_iolock, 628 .iolock = __videobuf_iolock,
643 .sync = __videobuf_sync, 629 .sync = __videobuf_sync,
644 .mmap_mapper = __videobuf_mmap_mapper, 630 .mmap_mapper = __videobuf_mmap_mapper,
@@ -654,7 +640,7 @@ void *videobuf_sg_alloc(size_t size)
654 640
655 q.msize = size; 641 q.msize = size;
656 642
657 return videobuf_alloc(&q); 643 return videobuf_alloc_vb(&q);
658} 644}
659EXPORT_SYMBOL_GPL(videobuf_sg_alloc); 645EXPORT_SYMBOL_GPL(videobuf_sg_alloc);
660 646
diff --git a/drivers/media/video/videobuf-vmalloc.c b/drivers/media/video/videobuf-vmalloc.c
index 583728f4c221..e7fe31d54f07 100644
--- a/drivers/media/video/videobuf-vmalloc.c
+++ b/drivers/media/video/videobuf-vmalloc.c
@@ -102,10 +102,10 @@ static void videobuf_vm_close(struct vm_area_struct *vma)
102 called with IRQ's disabled 102 called with IRQ's disabled
103 */ 103 */
104 dprintk(1, "%s: buf[%d] freeing (%p)\n", 104 dprintk(1, "%s: buf[%d] freeing (%p)\n",
105 __func__, i, mem->vmalloc); 105 __func__, i, mem->vaddr);
106 106
107 vfree(mem->vmalloc); 107 vfree(mem->vaddr);
108 mem->vmalloc = NULL; 108 mem->vaddr = NULL;
109 } 109 }
110 110
111 q->bufs[i]->map = NULL; 111 q->bufs[i]->map = NULL;
@@ -135,7 +135,7 @@ static const struct vm_operations_struct videobuf_vm_ops = {
135 struct videobuf_dma_sg_memory 135 struct videobuf_dma_sg_memory
136 */ 136 */
137 137
138static struct videobuf_buffer *__videobuf_alloc(size_t size) 138static struct videobuf_buffer *__videobuf_alloc_vb(size_t size)
139{ 139{
140 struct videobuf_vmalloc_memory *mem; 140 struct videobuf_vmalloc_memory *mem;
141 struct videobuf_buffer *vb; 141 struct videobuf_buffer *vb;
@@ -170,7 +170,7 @@ static int __videobuf_iolock(struct videobuf_queue *q,
170 dprintk(1, "%s memory method MMAP\n", __func__); 170 dprintk(1, "%s memory method MMAP\n", __func__);
171 171
172 /* All handling should be done by __videobuf_mmap_mapper() */ 172 /* All handling should be done by __videobuf_mmap_mapper() */
173 if (!mem->vmalloc) { 173 if (!mem->vaddr) {
174 printk(KERN_ERR "memory is not alloced/mmapped.\n"); 174 printk(KERN_ERR "memory is not alloced/mmapped.\n");
175 return -EINVAL; 175 return -EINVAL;
176 } 176 }
@@ -189,13 +189,13 @@ static int __videobuf_iolock(struct videobuf_queue *q,
189 * read() method. 189 * read() method.
190 */ 190 */
191 191
192 mem->vmalloc = vmalloc_user(pages); 192 mem->vaddr = vmalloc_user(pages);
193 if (!mem->vmalloc) { 193 if (!mem->vaddr) {
194 printk(KERN_ERR "vmalloc (%d pages) failed\n", pages); 194 printk(KERN_ERR "vmalloc (%d pages) failed\n", pages);
195 return -ENOMEM; 195 return -ENOMEM;
196 } 196 }
197 dprintk(1, "vmalloc is at addr %p (%d pages)\n", 197 dprintk(1, "vmalloc is at addr %p (%d pages)\n",
198 mem->vmalloc, pages); 198 mem->vaddr, pages);
199 199
200#if 0 200#if 0
201 int rc; 201 int rc;
@@ -245,8 +245,6 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
245 return -ENOMEM; 245 return -ENOMEM;
246 246
247 buf->map = map; 247 buf->map = map;
248 map->start = vma->vm_start;
249 map->end = vma->vm_end;
250 map->q = q; 248 map->q = q;
251 249
252 buf->baddr = vma->vm_start; 250 buf->baddr = vma->vm_start;
@@ -256,18 +254,18 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
256 MAGIC_CHECK(mem->magic, MAGIC_VMAL_MEM); 254 MAGIC_CHECK(mem->magic, MAGIC_VMAL_MEM);
257 255
258 pages = PAGE_ALIGN(vma->vm_end - vma->vm_start); 256 pages = PAGE_ALIGN(vma->vm_end - vma->vm_start);
259 mem->vmalloc = vmalloc_user(pages); 257 mem->vaddr = vmalloc_user(pages);
260 if (!mem->vmalloc) { 258 if (!mem->vaddr) {
261 printk(KERN_ERR "vmalloc (%d pages) failed\n", pages); 259 printk(KERN_ERR "vmalloc (%d pages) failed\n", pages);
262 goto error; 260 goto error;
263 } 261 }
264 dprintk(1, "vmalloc is at addr %p (%d pages)\n", mem->vmalloc, pages); 262 dprintk(1, "vmalloc is at addr %p (%d pages)\n", mem->vaddr, pages);
265 263
266 /* Try to remap memory */ 264 /* Try to remap memory */
267 retval = remap_vmalloc_range(vma, mem->vmalloc, 0); 265 retval = remap_vmalloc_range(vma, mem->vaddr, 0);
268 if (retval < 0) { 266 if (retval < 0) {
269 printk(KERN_ERR "mmap: remap failed with error %d. ", retval); 267 printk(KERN_ERR "mmap: remap failed with error %d. ", retval);
270 vfree(mem->vmalloc); 268 vfree(mem->vaddr);
271 goto error; 269 goto error;
272 } 270 }
273 271
@@ -293,7 +291,7 @@ error:
293static struct videobuf_qtype_ops qops = { 291static struct videobuf_qtype_ops qops = {
294 .magic = MAGIC_QTYPE_OPS, 292 .magic = MAGIC_QTYPE_OPS,
295 293
296 .alloc = __videobuf_alloc, 294 .alloc_vb = __videobuf_alloc_vb,
297 .iolock = __videobuf_iolock, 295 .iolock = __videobuf_iolock,
298 .mmap_mapper = __videobuf_mmap_mapper, 296 .mmap_mapper = __videobuf_mmap_mapper,
299 .vaddr = videobuf_to_vmalloc, 297 .vaddr = videobuf_to_vmalloc,
@@ -319,7 +317,7 @@ void *videobuf_to_vmalloc(struct videobuf_buffer *buf)
319 BUG_ON(!mem); 317 BUG_ON(!mem);
320 MAGIC_CHECK(mem->magic, MAGIC_VMAL_MEM); 318 MAGIC_CHECK(mem->magic, MAGIC_VMAL_MEM);
321 319
322 return mem->vmalloc; 320 return mem->vaddr;
323} 321}
324EXPORT_SYMBOL_GPL(videobuf_to_vmalloc); 322EXPORT_SYMBOL_GPL(videobuf_to_vmalloc);
325 323
@@ -341,8 +339,8 @@ void videobuf_vmalloc_free(struct videobuf_buffer *buf)
341 339
342 MAGIC_CHECK(mem->magic, MAGIC_VMAL_MEM); 340 MAGIC_CHECK(mem->magic, MAGIC_VMAL_MEM);
343 341
344 vfree(mem->vmalloc); 342 vfree(mem->vaddr);
345 mem->vmalloc = NULL; 343 mem->vaddr = NULL;
346 344
347 return; 345 return;
348} 346}
diff --git a/drivers/media/video/w9968cf.c b/drivers/media/video/w9968cf.c
deleted file mode 100644
index d807eea91757..000000000000
--- a/drivers/media/video/w9968cf.c
+++ /dev/null
@@ -1,3620 +0,0 @@
1/***************************************************************************
2 * Video4Linux driver for W996[87]CF JPEG USB Dual Mode Camera Chip. *
3 * *
4 * Copyright (C) 2002-2004 by Luca Risolia <luca.risolia@studio.unibo.it> *
5 * *
6 * - Memory management code from bttv driver by Ralph Metzler, *
7 * Marcus Metzler and Gerd Knorr. *
8 * - I2C interface to kernel, high-level image sensor control routines and *
9 * some symbolic names from OV511 driver by Mark W. McClelland. *
10 * - Low-level I2C fast write function by Piotr Czerczak. *
11 * - Low-level I2C read function by Frederic Jouault. *
12 * *
13 * This program is free software; you can redistribute it and/or modify *
14 * it under the terms of the GNU General Public License as published by *
15 * the Free Software Foundation; either version 2 of the License, or *
16 * (at your option) any later version. *
17 * *
18 * This program is distributed in the hope that it will be useful, *
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
21 * GNU General Public License for more details. *
22 * *
23 * You should have received a copy of the GNU General Public License *
24 * along with this program; if not, write to the Free Software *
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
26 ***************************************************************************/
27
28#include <linux/module.h>
29#include <linux/kernel.h>
30#include <linux/kmod.h>
31#include <linux/init.h>
32#include <linux/fs.h>
33#include <linux/vmalloc.h>
34#include <linux/slab.h>
35#include <linux/mm.h>
36#include <linux/string.h>
37#include <linux/errno.h>
38#include <linux/sched.h>
39#include <linux/ioctl.h>
40#include <linux/delay.h>
41#include <linux/stddef.h>
42#include <asm/page.h>
43#include <asm/uaccess.h>
44#include <linux/page-flags.h>
45#include <linux/videodev.h>
46#include <media/v4l2-ioctl.h>
47
48#include "w9968cf.h"
49#include "w9968cf_decoder.h"
50
51static struct w9968cf_vpp_t* w9968cf_vpp;
52static DECLARE_WAIT_QUEUE_HEAD(w9968cf_vppmod_wait);
53
54static LIST_HEAD(w9968cf_dev_list); /* head of V4L registered cameras list */
55static DEFINE_MUTEX(w9968cf_devlist_mutex); /* semaphore for list traversal */
56
57static DECLARE_RWSEM(w9968cf_disconnect); /* prevent races with open() */
58
59
60/****************************************************************************
61 * Module macros and parameters *
62 ****************************************************************************/
63
64MODULE_DEVICE_TABLE(usb, winbond_id_table);
65
66MODULE_AUTHOR(W9968CF_MODULE_AUTHOR" "W9968CF_AUTHOR_EMAIL);
67MODULE_DESCRIPTION(W9968CF_MODULE_NAME);
68MODULE_VERSION(W9968CF_MODULE_VERSION);
69MODULE_LICENSE(W9968CF_MODULE_LICENSE);
70MODULE_SUPPORTED_DEVICE("Video");
71
72static unsigned short simcams = W9968CF_SIMCAMS;
73static short video_nr[]={[0 ... W9968CF_MAX_DEVICES-1] = -1}; /*-1=first free*/
74static unsigned int packet_size[] = {[0 ... W9968CF_MAX_DEVICES-1] =
75 W9968CF_PACKET_SIZE};
76static unsigned short max_buffers[] = {[0 ... W9968CF_MAX_DEVICES-1] =
77 W9968CF_BUFFERS};
78static int double_buffer[] = {[0 ... W9968CF_MAX_DEVICES-1] =
79 W9968CF_DOUBLE_BUFFER};
80static int clamping[] = {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_CLAMPING};
81static unsigned short filter_type[]= {[0 ... W9968CF_MAX_DEVICES-1] =
82 W9968CF_FILTER_TYPE};
83static int largeview[]= {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_LARGEVIEW};
84static unsigned short decompression[] = {[0 ... W9968CF_MAX_DEVICES-1] =
85 W9968CF_DECOMPRESSION};
86static int upscaling[]= {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_UPSCALING};
87static unsigned short force_palette[] = {[0 ... W9968CF_MAX_DEVICES-1] = 0};
88static int force_rgb[] = {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_FORCE_RGB};
89static int autobright[] = {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_AUTOBRIGHT};
90static int autoexp[] = {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_AUTOEXP};
91static unsigned short lightfreq[] = {[0 ... W9968CF_MAX_DEVICES-1] =
92 W9968CF_LIGHTFREQ};
93static int bandingfilter[] = {[0 ... W9968CF_MAX_DEVICES-1]=
94 W9968CF_BANDINGFILTER};
95static short clockdiv[] = {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_CLOCKDIV};
96static int backlight[] = {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_BACKLIGHT};
97static int mirror[] = {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_MIRROR};
98static int monochrome[] = {[0 ... W9968CF_MAX_DEVICES-1]=W9968CF_MONOCHROME};
99static unsigned int brightness[] = {[0 ... W9968CF_MAX_DEVICES-1] =
100 W9968CF_BRIGHTNESS};
101static unsigned int hue[] = {[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_HUE};
102static unsigned int colour[]={[0 ... W9968CF_MAX_DEVICES-1] = W9968CF_COLOUR};
103static unsigned int contrast[] = {[0 ... W9968CF_MAX_DEVICES-1] =
104 W9968CF_CONTRAST};
105static unsigned int whiteness[] = {[0 ... W9968CF_MAX_DEVICES-1] =
106 W9968CF_WHITENESS};
107#ifdef W9968CF_DEBUG
108static unsigned short debug = W9968CF_DEBUG_LEVEL;
109static int specific_debug = W9968CF_SPECIFIC_DEBUG;
110#endif
111
112static unsigned int param_nv[24]; /* number of values per parameter */
113
114module_param(simcams, ushort, 0644);
115module_param_array(video_nr, short, &param_nv[0], 0444);
116module_param_array(packet_size, uint, &param_nv[1], 0444);
117module_param_array(max_buffers, ushort, &param_nv[2], 0444);
118module_param_array(double_buffer, bool, &param_nv[3], 0444);
119module_param_array(clamping, bool, &param_nv[4], 0444);
120module_param_array(filter_type, ushort, &param_nv[5], 0444);
121module_param_array(largeview, bool, &param_nv[6], 0444);
122module_param_array(decompression, ushort, &param_nv[7], 0444);
123module_param_array(upscaling, bool, &param_nv[8], 0444);
124module_param_array(force_palette, ushort, &param_nv[9], 0444);
125module_param_array(force_rgb, ushort, &param_nv[10], 0444);
126module_param_array(autobright, bool, &param_nv[11], 0444);
127module_param_array(autoexp, bool, &param_nv[12], 0444);
128module_param_array(lightfreq, ushort, &param_nv[13], 0444);
129module_param_array(bandingfilter, bool, &param_nv[14], 0444);
130module_param_array(clockdiv, short, &param_nv[15], 0444);
131module_param_array(backlight, bool, &param_nv[16], 0444);
132module_param_array(mirror, bool, &param_nv[17], 0444);
133module_param_array(monochrome, bool, &param_nv[18], 0444);
134module_param_array(brightness, uint, &param_nv[19], 0444);
135module_param_array(hue, uint, &param_nv[20], 0444);
136module_param_array(colour, uint, &param_nv[21], 0444);
137module_param_array(contrast, uint, &param_nv[22], 0444);
138module_param_array(whiteness, uint, &param_nv[23], 0444);
139#ifdef W9968CF_DEBUG
140module_param(debug, ushort, 0644);
141module_param(specific_debug, bool, 0644);
142#endif
143
144MODULE_PARM_DESC(simcams,
145 "\n<n> Number of cameras allowed to stream simultaneously."
146 "\nn may vary from 0 to "
147 __MODULE_STRING(W9968CF_MAX_DEVICES)"."
148 "\nDefault value is "__MODULE_STRING(W9968CF_SIMCAMS)"."
149 "\n");
150MODULE_PARM_DESC(video_nr,
151 "\n<-1|n[,...]> Specify V4L minor mode number."
152 "\n -1 = use next available (default)"
153 "\n n = use minor number n (integer >= 0)"
154 "\nYou can specify up to "__MODULE_STRING(W9968CF_MAX_DEVICES)
155 " cameras this way."
156 "\nFor example:"
157 "\nvideo_nr=-1,2,-1 would assign minor number 2 to"
158 "\nthe second camera and use auto for the first"
159 "\none and for every other camera."
160 "\n");
161MODULE_PARM_DESC(packet_size,
162 "\n<n[,...]> Specify the maximum data payload"
163 "\nsize in bytes for alternate settings, for each device."
164 "\nn is scaled between 63 and 1023 "
165 "(default is "__MODULE_STRING(W9968CF_PACKET_SIZE)")."
166 "\n");
167MODULE_PARM_DESC(max_buffers,
168 "\n<n[,...]> For advanced users."
169 "\nSpecify the maximum number of video frame buffers"
170 "\nto allocate for each device, from 2 to "
171 __MODULE_STRING(W9968CF_MAX_BUFFERS)
172 ". (default is "__MODULE_STRING(W9968CF_BUFFERS)")."
173 "\n");
174MODULE_PARM_DESC(double_buffer,
175 "\n<0|1[,...]> "
176 "Hardware double buffering: 0 disabled, 1 enabled."
177 "\nIt should be enabled if you want smooth video output: if"
178 "\nyou obtain out of sync. video, disable it, or try to"
179 "\ndecrease the 'clockdiv' module parameter value."
180 "\nDefault value is "__MODULE_STRING(W9968CF_DOUBLE_BUFFER)
181 " for every device."
182 "\n");
183MODULE_PARM_DESC(clamping,
184 "\n<0|1[,...]> Video data clamping: 0 disabled, 1 enabled."
185 "\nDefault value is "__MODULE_STRING(W9968CF_CLAMPING)
186 " for every device."
187 "\n");
188MODULE_PARM_DESC(filter_type,
189 "\n<0|1|2[,...]> Video filter type."
190 "\n0 none, 1 (1-2-1) 3-tap filter, "
191 "2 (2-3-6-3-2) 5-tap filter."
192 "\nDefault value is "__MODULE_STRING(W9968CF_FILTER_TYPE)
193 " for every device."
194 "\nThe filter is used to reduce noise and aliasing artifacts"
195 "\nproduced by the CCD or CMOS image sensor, and the scaling"
196 " process."
197 "\n");
198MODULE_PARM_DESC(largeview,
199 "\n<0|1[,...]> Large view: 0 disabled, 1 enabled."
200 "\nDefault value is "__MODULE_STRING(W9968CF_LARGEVIEW)
201 " for every device."
202 "\n");
203MODULE_PARM_DESC(upscaling,
204 "\n<0|1[,...]> Software scaling (for non-compressed video):"
205 "\n0 disabled, 1 enabled."
206 "\nDisable it if you have a slow CPU or you don't have"
207 " enough memory."
208 "\nDefault value is "__MODULE_STRING(W9968CF_UPSCALING)
209 " for every device."
210 "\nIf 'w9968cf-vpp' is not present, this parameter is"
211 " set to 0."
212 "\n");
213MODULE_PARM_DESC(decompression,
214 "\n<0|1|2[,...]> Software video decompression:"
215 "\n- 0 disables decompression (doesn't allow formats needing"
216 " decompression)"
217 "\n- 1 forces decompression (allows formats needing"
218 " decompression only);"
219 "\n- 2 allows any permitted formats."
220 "\nFormats supporting compressed video are YUV422P and"
221 " YUV420P/YUV420 "
222 "\nin any resolutions where both width and height are "
223 "a multiple of 16."
224 "\nDefault value is "__MODULE_STRING(W9968CF_DECOMPRESSION)
225 " for every device."
226 "\nIf 'w9968cf-vpp' is not present, forcing decompression is "
227 "\nnot allowed; in this case this parameter is set to 2."
228 "\n");
229MODULE_PARM_DESC(force_palette,
230 "\n<0"
231 "|" __MODULE_STRING(VIDEO_PALETTE_UYVY)
232 "|" __MODULE_STRING(VIDEO_PALETTE_YUV420)
233 "|" __MODULE_STRING(VIDEO_PALETTE_YUV422P)
234 "|" __MODULE_STRING(VIDEO_PALETTE_YUV420P)
235 "|" __MODULE_STRING(VIDEO_PALETTE_YUYV)
236 "|" __MODULE_STRING(VIDEO_PALETTE_YUV422)
237 "|" __MODULE_STRING(VIDEO_PALETTE_GREY)
238 "|" __MODULE_STRING(VIDEO_PALETTE_RGB555)
239 "|" __MODULE_STRING(VIDEO_PALETTE_RGB565)
240 "|" __MODULE_STRING(VIDEO_PALETTE_RGB24)
241 "|" __MODULE_STRING(VIDEO_PALETTE_RGB32)
242 "[,...]>"
243 " Force picture palette."
244 "\nIn order:"
245 "\n- 0 allows any of the following formats:"
246 "\n- UYVY 16 bpp - Original video, compression disabled"
247 "\n- YUV420 12 bpp - Original video, compression enabled"
248 "\n- YUV422P 16 bpp - Original video, compression enabled"
249 "\n- YUV420P 12 bpp - Original video, compression enabled"
250 "\n- YUVY 16 bpp - Software conversion from UYVY"
251 "\n- YUV422 16 bpp - Software conversion from UYVY"
252 "\n- GREY 8 bpp - Software conversion from UYVY"
253 "\n- RGB555 16 bpp - Software conversion from UYVY"
254 "\n- RGB565 16 bpp - Software conversion from UYVY"
255 "\n- RGB24 24 bpp - Software conversion from UYVY"
256 "\n- RGB32 32 bpp - Software conversion from UYVY"
257 "\nWhen not 0, this parameter will override 'decompression'."
258 "\nDefault value is 0 for every device."
259 "\nInitial palette is "
260 __MODULE_STRING(W9968CF_PALETTE_DECOMP_ON)"."
261 "\nIf 'w9968cf-vpp' is not present, this parameter is"
262 " set to 9 (UYVY)."
263 "\n");
264MODULE_PARM_DESC(force_rgb,
265 "\n<0|1[,...]> Read RGB video data instead of BGR:"
266 "\n 1 = use RGB component ordering."
267 "\n 0 = use BGR component ordering."
268 "\nThis parameter has effect when using RGBX palettes only."
269 "\nDefault value is "__MODULE_STRING(W9968CF_FORCE_RGB)
270 " for every device."
271 "\n");
272MODULE_PARM_DESC(autobright,
273 "\n<0|1[,...]> Image sensor automatically changes brightness:"
274 "\n 0 = no, 1 = yes"
275 "\nDefault value is "__MODULE_STRING(W9968CF_AUTOBRIGHT)
276 " for every device."
277 "\n");
278MODULE_PARM_DESC(autoexp,
279 "\n<0|1[,...]> Image sensor automatically changes exposure:"
280 "\n 0 = no, 1 = yes"
281 "\nDefault value is "__MODULE_STRING(W9968CF_AUTOEXP)
282 " for every device."
283 "\n");
284MODULE_PARM_DESC(lightfreq,
285 "\n<50|60[,...]> Light frequency in Hz:"
286 "\n 50 for European and Asian lighting,"
287 " 60 for American lighting."
288 "\nDefault value is "__MODULE_STRING(W9968CF_LIGHTFREQ)
289 " for every device."
290 "\n");
291MODULE_PARM_DESC(bandingfilter,
292 "\n<0|1[,...]> Banding filter to reduce effects of"
293 " fluorescent lighting:"
294 "\n 0 disabled, 1 enabled."
295 "\nThis filter tries to reduce the pattern of horizontal"
296 "\nlight/dark bands caused by some (usually fluorescent)"
297 " lighting."
298 "\nDefault value is "__MODULE_STRING(W9968CF_BANDINGFILTER)
299 " for every device."
300 "\n");
301MODULE_PARM_DESC(clockdiv,
302 "\n<-1|n[,...]> "
303 "Force pixel clock divisor to a specific value (for experts):"
304 "\n n may vary from 0 to 127."
305 "\n -1 for automatic value."
306 "\nSee also the 'double_buffer' module parameter."
307 "\nDefault value is "__MODULE_STRING(W9968CF_CLOCKDIV)
308 " for every device."
309 "\n");
310MODULE_PARM_DESC(backlight,
311 "\n<0|1[,...]> Objects are lit from behind:"
312 "\n 0 = no, 1 = yes"
313 "\nDefault value is "__MODULE_STRING(W9968CF_BACKLIGHT)
314 " for every device."
315 "\n");
316MODULE_PARM_DESC(mirror,
317 "\n<0|1[,...]> Reverse image horizontally:"
318 "\n 0 = no, 1 = yes"
319 "\nDefault value is "__MODULE_STRING(W9968CF_MIRROR)
320 " for every device."
321 "\n");
322MODULE_PARM_DESC(monochrome,
323 "\n<0|1[,...]> Use image sensor as monochrome sensor:"
324 "\n 0 = no, 1 = yes"
325 "\nNot all the sensors support monochrome color."
326 "\nDefault value is "__MODULE_STRING(W9968CF_MONOCHROME)
327 " for every device."
328 "\n");
329MODULE_PARM_DESC(brightness,
330 "\n<n[,...]> Set picture brightness (0-65535)."
331 "\nDefault value is "__MODULE_STRING(W9968CF_BRIGHTNESS)
332 " for every device."
333 "\nThis parameter has no effect if 'autobright' is enabled."
334 "\n");
335MODULE_PARM_DESC(hue,
336 "\n<n[,...]> Set picture hue (0-65535)."
337 "\nDefault value is "__MODULE_STRING(W9968CF_HUE)
338 " for every device."
339 "\n");
340MODULE_PARM_DESC(colour,
341 "\n<n[,...]> Set picture saturation (0-65535)."
342 "\nDefault value is "__MODULE_STRING(W9968CF_COLOUR)
343 " for every device."
344 "\n");
345MODULE_PARM_DESC(contrast,
346 "\n<n[,...]> Set picture contrast (0-65535)."
347 "\nDefault value is "__MODULE_STRING(W9968CF_CONTRAST)
348 " for every device."
349 "\n");
350MODULE_PARM_DESC(whiteness,
351 "\n<n[,...]> Set picture whiteness (0-65535)."
352 "\nDefault value is "__MODULE_STRING(W9968CF_WHITENESS)
353 " for every device."
354 "\n");
355#ifdef W9968CF_DEBUG
356MODULE_PARM_DESC(debug,
357 "\n<n> Debugging information level, from 0 to 6:"
358 "\n0 = none (use carefully)"
359 "\n1 = critical errors"
360 "\n2 = significant informations"
361 "\n3 = configuration or general messages"
362 "\n4 = warnings"
363 "\n5 = called functions"
364 "\n6 = function internals"
365 "\nLevel 5 and 6 are useful for testing only, when only "
366 "one device is used."
367 "\nDefault value is "__MODULE_STRING(W9968CF_DEBUG_LEVEL)"."
368 "\n");
369MODULE_PARM_DESC(specific_debug,
370 "\n<0|1> Enable or disable specific debugging messages:"
371 "\n0 = print messages concerning every level"
372 " <= 'debug' level."
373 "\n1 = print messages concerning the level"
374 " indicated by 'debug'."
375 "\nDefault value is "
376 __MODULE_STRING(W9968CF_SPECIFIC_DEBUG)"."
377 "\n");
378#endif /* W9968CF_DEBUG */
379
380
381
382/****************************************************************************
383 * Some prototypes *
384 ****************************************************************************/
385
386/* Video4linux interface */
387static const struct v4l2_file_operations w9968cf_fops;
388static int w9968cf_open(struct file *);
389static int w9968cf_release(struct file *);
390static int w9968cf_mmap(struct file *, struct vm_area_struct *);
391static long w9968cf_ioctl(struct file *, unsigned, unsigned long);
392static ssize_t w9968cf_read(struct file *, char __user *, size_t, loff_t *);
393static long w9968cf_v4l_ioctl(struct file *, unsigned int,
394 void __user *);
395
396/* USB-specific */
397static int w9968cf_start_transfer(struct w9968cf_device*);
398static int w9968cf_stop_transfer(struct w9968cf_device*);
399static int w9968cf_write_reg(struct w9968cf_device*, u16 value, u16 index);
400static int w9968cf_read_reg(struct w9968cf_device*, u16 index);
401static int w9968cf_write_fsb(struct w9968cf_device*, u16* data);
402static int w9968cf_write_sb(struct w9968cf_device*, u16 value);
403static int w9968cf_read_sb(struct w9968cf_device*);
404static int w9968cf_upload_quantizationtables(struct w9968cf_device*);
405static void w9968cf_urb_complete(struct urb *urb);
406
407/* Low-level I2C (SMBus) I/O */
408static int w9968cf_smbus_start(struct w9968cf_device*);
409static int w9968cf_smbus_stop(struct w9968cf_device*);
410static int w9968cf_smbus_write_byte(struct w9968cf_device*, u8 v);
411static int w9968cf_smbus_read_byte(struct w9968cf_device*, u8* v);
412static int w9968cf_smbus_write_ack(struct w9968cf_device*);
413static int w9968cf_smbus_read_ack(struct w9968cf_device*);
414static int w9968cf_smbus_refresh_bus(struct w9968cf_device*);
415static int w9968cf_i2c_adap_read_byte(struct w9968cf_device* cam,
416 u16 address, u8* value);
417static int w9968cf_i2c_adap_read_byte_data(struct w9968cf_device*, u16 address,
418 u8 subaddress, u8* value);
419static int w9968cf_i2c_adap_write_byte(struct w9968cf_device*,
420 u16 address, u8 subaddress);
421static int w9968cf_i2c_adap_fastwrite_byte_data(struct w9968cf_device*,
422 u16 address, u8 subaddress,
423 u8 value);
424
425/* I2C interface to kernel */
426static int w9968cf_i2c_init(struct w9968cf_device*);
427static int w9968cf_i2c_smbus_xfer(struct i2c_adapter*, u16 addr,
428 unsigned short flags, char read_write,
429 u8 command, int size, union i2c_smbus_data*);
430static u32 w9968cf_i2c_func(struct i2c_adapter*);
431
432/* Memory management */
433static void* rvmalloc(unsigned long size);
434static void rvfree(void *mem, unsigned long size);
435static void w9968cf_deallocate_memory(struct w9968cf_device*);
436static int w9968cf_allocate_memory(struct w9968cf_device*);
437
438/* High-level image sensor control functions */
439static int w9968cf_sensor_set_control(struct w9968cf_device*,int cid,int val);
440static int w9968cf_sensor_get_control(struct w9968cf_device*,int cid,int *val);
441static int w9968cf_sensor_cmd(struct w9968cf_device*,
442 unsigned int cmd, void *arg);
443static int w9968cf_sensor_init(struct w9968cf_device*);
444static int w9968cf_sensor_update_settings(struct w9968cf_device*);
445static int w9968cf_sensor_get_picture(struct w9968cf_device*);
446static int w9968cf_sensor_update_picture(struct w9968cf_device*,
447 struct video_picture pict);
448
449/* Other helper functions */
450static void w9968cf_configure_camera(struct w9968cf_device*,struct usb_device*,
451 enum w9968cf_model_id,
452 const unsigned short dev_nr);
453static void w9968cf_adjust_configuration(struct w9968cf_device*);
454static int w9968cf_turn_on_led(struct w9968cf_device*);
455static int w9968cf_init_chip(struct w9968cf_device*);
456static inline u16 w9968cf_valid_palette(u16 palette);
457static inline u16 w9968cf_valid_depth(u16 palette);
458static inline u8 w9968cf_need_decompression(u16 palette);
459static int w9968cf_set_picture(struct w9968cf_device*, struct video_picture);
460static int w9968cf_set_window(struct w9968cf_device*, struct video_window);
461static int w9968cf_postprocess_frame(struct w9968cf_device*,
462 struct w9968cf_frame_t*);
463static int w9968cf_adjust_window_size(struct w9968cf_device*, u32 *w, u32 *h);
464static void w9968cf_init_framelist(struct w9968cf_device*);
465static void w9968cf_push_frame(struct w9968cf_device*, u8 f_num);
466static void w9968cf_pop_frame(struct w9968cf_device*,struct w9968cf_frame_t**);
467static void w9968cf_release_resources(struct w9968cf_device*);
468
469
470
471/****************************************************************************
472 * Symbolic names *
473 ****************************************************************************/
474
475/* Used to represent a list of values and their respective symbolic names */
476struct w9968cf_symbolic_list {
477 const int num;
478 const char *name;
479};
480
481/*--------------------------------------------------------------------------
482 Returns the name of the matching element in the symbolic_list array. The
483 end of the list must be marked with an element that has a NULL name.
484 --------------------------------------------------------------------------*/
485static inline const char *
486symbolic(struct w9968cf_symbolic_list list[], const int num)
487{
488 int i;
489
490 for (i = 0; list[i].name != NULL; i++)
491 if (list[i].num == num)
492 return (list[i].name);
493
494 return "Unknown";
495}
496
497static struct w9968cf_symbolic_list camlist[] = {
498 { W9968CF_MOD_GENERIC, "W996[87]CF JPEG USB Dual Mode Camera" },
499 { W9968CF_MOD_CLVBWGP, "Creative Labs Video Blaster WebCam Go Plus" },
500
501 /* Other cameras (having the same descriptors as Generic W996[87]CF) */
502 { W9968CF_MOD_ADPVDMA, "Aroma Digi Pen VGA Dual Mode ADG-5000" },
503 { W9986CF_MOD_AAU, "AVerMedia AVerTV USB" },
504 { W9968CF_MOD_CLVBWG, "Creative Labs Video Blaster WebCam Go" },
505 { W9968CF_MOD_LL, "Lebon LDC-035A" },
506 { W9968CF_MOD_EEEMC, "Ezonics EZ-802 EZMega Cam" },
507 { W9968CF_MOD_OOE, "OmniVision OV8610-EDE" },
508 { W9968CF_MOD_ODPVDMPC, "OPCOM Digi Pen VGA Dual Mode Pen Camera" },
509 { W9968CF_MOD_PDPII, "Pretec Digi Pen-II" },
510 { W9968CF_MOD_PDP480, "Pretec DigiPen-480" },
511
512 { -1, NULL }
513};
514
515static struct w9968cf_symbolic_list senlist[] = {
516 { CC_OV76BE, "OV76BE" },
517 { CC_OV7610, "OV7610" },
518 { CC_OV7620, "OV7620" },
519 { CC_OV7620AE, "OV7620AE" },
520 { CC_OV6620, "OV6620" },
521 { CC_OV6630, "OV6630" },
522 { CC_OV6630AE, "OV6630AE" },
523 { CC_OV6630AF, "OV6630AF" },
524 { -1, NULL }
525};
526
527/* Video4Linux1 palettes */
528static struct w9968cf_symbolic_list v4l1_plist[] = {
529 { VIDEO_PALETTE_GREY, "GREY" },
530 { VIDEO_PALETTE_HI240, "HI240" },
531 { VIDEO_PALETTE_RGB565, "RGB565" },
532 { VIDEO_PALETTE_RGB24, "RGB24" },
533 { VIDEO_PALETTE_RGB32, "RGB32" },
534 { VIDEO_PALETTE_RGB555, "RGB555" },
535 { VIDEO_PALETTE_YUV422, "YUV422" },
536 { VIDEO_PALETTE_YUYV, "YUYV" },
537 { VIDEO_PALETTE_UYVY, "UYVY" },
538 { VIDEO_PALETTE_YUV420, "YUV420" },
539 { VIDEO_PALETTE_YUV411, "YUV411" },
540 { VIDEO_PALETTE_RAW, "RAW" },
541 { VIDEO_PALETTE_YUV422P, "YUV422P" },
542 { VIDEO_PALETTE_YUV411P, "YUV411P" },
543 { VIDEO_PALETTE_YUV420P, "YUV420P" },
544 { VIDEO_PALETTE_YUV410P, "YUV410P" },
545 { -1, NULL }
546};
547
548/* Decoder error codes: */
549static struct w9968cf_symbolic_list decoder_errlist[] = {
550 { W9968CF_DEC_ERR_CORRUPTED_DATA, "Corrupted data" },
551 { W9968CF_DEC_ERR_BUF_OVERFLOW, "Buffer overflow" },
552 { W9968CF_DEC_ERR_NO_SOI, "SOI marker not found" },
553 { W9968CF_DEC_ERR_NO_SOF0, "SOF0 marker not found" },
554 { W9968CF_DEC_ERR_NO_SOS, "SOS marker not found" },
555 { W9968CF_DEC_ERR_NO_EOI, "EOI marker not found" },
556 { -1, NULL }
557};
558
559/* URB error codes: */
560static struct w9968cf_symbolic_list urb_errlist[] = {
561 { -ENOMEM, "No memory for allocation of internal structures" },
562 { -ENOSPC, "The host controller's bandwidth is already consumed" },
563 { -ENOENT, "URB was canceled by unlink_urb" },
564 { -EXDEV, "ISO transfer only partially completed" },
565 { -EAGAIN, "Too match scheduled for the future" },
566 { -ENXIO, "URB already queued" },
567 { -EFBIG, "Too much ISO frames requested" },
568 { -ENOSR, "Buffer error (overrun)" },
569 { -EPIPE, "Specified endpoint is stalled (device not responding)"},
570 { -EOVERFLOW, "Babble (too much data)" },
571 { -EPROTO, "Bit-stuff error (bad cable?)" },
572 { -EILSEQ, "CRC/Timeout" },
573 { -ETIME, "Device does not respond to token" },
574 { -ETIMEDOUT, "Device does not respond to command" },
575 { -1, NULL }
576};
577
578/****************************************************************************
579 * Memory management functions *
580 ****************************************************************************/
581static void* rvmalloc(unsigned long size)
582{
583 void* mem;
584 unsigned long adr;
585
586 size = PAGE_ALIGN(size);
587 mem = vmalloc_32(size);
588 if (!mem)
589 return NULL;
590
591 memset(mem, 0, size); /* Clear the ram out, no junk to the user */
592 adr = (unsigned long) mem;
593 while (size > 0) {
594 SetPageReserved(vmalloc_to_page((void *)adr));
595 adr += PAGE_SIZE;
596 size -= PAGE_SIZE;
597 }
598
599 return mem;
600}
601
602
603static void rvfree(void* mem, unsigned long size)
604{
605 unsigned long adr;
606
607 if (!mem)
608 return;
609
610 adr = (unsigned long) mem;
611 while ((long) size > 0) {
612 ClearPageReserved(vmalloc_to_page((void *)adr));
613 adr += PAGE_SIZE;
614 size -= PAGE_SIZE;
615 }
616 vfree(mem);
617}
618
619
620/*--------------------------------------------------------------------------
621 Deallocate previously allocated memory.
622 --------------------------------------------------------------------------*/
623static void w9968cf_deallocate_memory(struct w9968cf_device* cam)
624{
625 u8 i;
626
627 /* Free the isochronous transfer buffers */
628 for (i = 0; i < W9968CF_URBS; i++) {
629 kfree(cam->transfer_buffer[i]);
630 cam->transfer_buffer[i] = NULL;
631 }
632
633 /* Free temporary frame buffer */
634 if (cam->frame_tmp.buffer) {
635 rvfree(cam->frame_tmp.buffer, cam->frame_tmp.size);
636 cam->frame_tmp.buffer = NULL;
637 }
638
639 /* Free helper buffer */
640 if (cam->frame_vpp.buffer) {
641 rvfree(cam->frame_vpp.buffer, cam->frame_vpp.size);
642 cam->frame_vpp.buffer = NULL;
643 }
644
645 /* Free video frame buffers */
646 if (cam->frame[0].buffer) {
647 rvfree(cam->frame[0].buffer, cam->nbuffers*cam->frame[0].size);
648 cam->frame[0].buffer = NULL;
649 }
650
651 cam->nbuffers = 0;
652
653 DBG(5, "Memory successfully deallocated")
654}
655
656
657/*--------------------------------------------------------------------------
658 Allocate memory buffers for USB transfers and video frames.
659 This function is called by open() only.
660 Return 0 on success, a negative number otherwise.
661 --------------------------------------------------------------------------*/
662static int w9968cf_allocate_memory(struct w9968cf_device* cam)
663{
664 const u16 p_size = wMaxPacketSize[cam->altsetting-1];
665 void* buff = NULL;
666 unsigned long hw_bufsize, vpp_bufsize;
667 u8 i, bpp;
668
669 /* NOTE: Deallocation is done elsewhere in case of error */
670
671 /* Calculate the max amount of raw data per frame from the device */
672 hw_bufsize = cam->maxwidth*cam->maxheight*2;
673
674 /* Calculate the max buf. size needed for post-processing routines */
675 bpp = (w9968cf_vpp) ? 4 : 2;
676 if (cam->upscaling)
677 vpp_bufsize = max(W9968CF_MAX_WIDTH*W9968CF_MAX_HEIGHT*bpp,
678 cam->maxwidth*cam->maxheight*bpp);
679 else
680 vpp_bufsize = cam->maxwidth*cam->maxheight*bpp;
681
682 /* Allocate memory for the isochronous transfer buffers */
683 for (i = 0; i < W9968CF_URBS; i++) {
684 if (!(cam->transfer_buffer[i] =
685 kzalloc(W9968CF_ISO_PACKETS*p_size, GFP_KERNEL))) {
686 DBG(1, "Couldn't allocate memory for the isochronous "
687 "transfer buffers (%u bytes)",
688 p_size * W9968CF_ISO_PACKETS)
689 return -ENOMEM;
690 }
691 }
692
693 /* Allocate memory for the temporary frame buffer */
694 if (!(cam->frame_tmp.buffer = rvmalloc(hw_bufsize))) {
695 DBG(1, "Couldn't allocate memory for the temporary "
696 "video frame buffer (%lu bytes)", hw_bufsize)
697 return -ENOMEM;
698 }
699 cam->frame_tmp.size = hw_bufsize;
700 cam->frame_tmp.number = -1;
701
702 /* Allocate memory for the helper buffer */
703 if (w9968cf_vpp) {
704 if (!(cam->frame_vpp.buffer = rvmalloc(vpp_bufsize))) {
705 DBG(1, "Couldn't allocate memory for the helper buffer"
706 " (%lu bytes)", vpp_bufsize)
707 return -ENOMEM;
708 }
709 cam->frame_vpp.size = vpp_bufsize;
710 } else
711 cam->frame_vpp.buffer = NULL;
712
713 /* Allocate memory for video frame buffers */
714 cam->nbuffers = cam->max_buffers;
715 while (cam->nbuffers >= 2) {
716 if ((buff = rvmalloc(cam->nbuffers * vpp_bufsize)))
717 break;
718 else
719 cam->nbuffers--;
720 }
721
722 if (!buff) {
723 DBG(1, "Couldn't allocate memory for the video frame buffers")
724 cam->nbuffers = 0;
725 return -ENOMEM;
726 }
727
728 if (cam->nbuffers != cam->max_buffers)
729 DBG(2, "Couldn't allocate memory for %u video frame buffers. "
730 "Only memory for %u buffers has been allocated",
731 cam->max_buffers, cam->nbuffers)
732
733 for (i = 0; i < cam->nbuffers; i++) {
734 cam->frame[i].buffer = buff + i*vpp_bufsize;
735 cam->frame[i].size = vpp_bufsize;
736 cam->frame[i].number = i;
737 /* Circular list */
738 if (i != cam->nbuffers-1)
739 cam->frame[i].next = &cam->frame[i+1];
740 else
741 cam->frame[i].next = &cam->frame[0];
742 cam->frame[i].status = F_UNUSED;
743 }
744
745 DBG(5, "Memory successfully allocated")
746 return 0;
747}
748
749
750
751/****************************************************************************
752 * USB-specific functions *
753 ****************************************************************************/
754
755/*--------------------------------------------------------------------------
756 This is an handler function which is called after the URBs are completed.
757 It collects multiple data packets coming from the camera by putting them
758 into frame buffers: one or more zero data length data packets are used to
759 mark the end of a video frame; the first non-zero data packet is the start
760 of the next video frame; if an error is encountered in a packet, the entire
761 video frame is discarded and grabbed again.
762 If there are no requested frames in the FIFO list, packets are collected into
763 a temporary buffer.
764 --------------------------------------------------------------------------*/
765static void w9968cf_urb_complete(struct urb *urb)
766{
767 struct w9968cf_device* cam = (struct w9968cf_device*)urb->context;
768 struct w9968cf_frame_t** f;
769 unsigned int len, status;
770 void* pos;
771 u8 i;
772 int err = 0;
773
774 if ((!cam->streaming) || cam->disconnected) {
775 DBG(4, "Got interrupt, but not streaming")
776 return;
777 }
778
779 /* "(*f)" will be used instead of "cam->frame_current" */
780 f = &cam->frame_current;
781
782 /* If a frame has been requested and we are grabbing into
783 the temporary frame, we'll switch to that requested frame */
784 if ((*f) == &cam->frame_tmp && *cam->requested_frame) {
785 if (cam->frame_tmp.status == F_GRABBING) {
786 w9968cf_pop_frame(cam, &cam->frame_current);
787 (*f)->status = F_GRABBING;
788 (*f)->length = cam->frame_tmp.length;
789 memcpy((*f)->buffer, cam->frame_tmp.buffer,
790 (*f)->length);
791 DBG(6, "Switched from temp. frame to frame #%d",
792 (*f)->number)
793 }
794 }
795
796 for (i = 0; i < urb->number_of_packets; i++) {
797 len = urb->iso_frame_desc[i].actual_length;
798 status = urb->iso_frame_desc[i].status;
799 pos = urb->iso_frame_desc[i].offset + urb->transfer_buffer;
800
801 if (status && len != 0) {
802 DBG(4, "URB failed, error in data packet "
803 "(error #%u, %s)",
804 status, symbolic(urb_errlist, status))
805 (*f)->status = F_ERROR;
806 continue;
807 }
808
809 if (len) { /* start of frame */
810
811 if ((*f)->status == F_UNUSED) {
812 (*f)->status = F_GRABBING;
813 (*f)->length = 0;
814 }
815
816 /* Buffer overflows shouldn't happen, however...*/
817 if ((*f)->length + len > (*f)->size) {
818 DBG(4, "Buffer overflow: bad data packets")
819 (*f)->status = F_ERROR;
820 }
821
822 if ((*f)->status == F_GRABBING) {
823 memcpy((*f)->buffer + (*f)->length, pos, len);
824 (*f)->length += len;
825 }
826
827 } else if ((*f)->status == F_GRABBING) { /* end of frame */
828
829 DBG(6, "Frame #%d successfully grabbed", (*f)->number)
830
831 if (cam->vpp_flag & VPP_DECOMPRESSION) {
832 err = w9968cf_vpp->check_headers((*f)->buffer,
833 (*f)->length);
834 if (err) {
835 DBG(4, "Skip corrupted frame: %s",
836 symbolic(decoder_errlist, err))
837 (*f)->status = F_UNUSED;
838 continue; /* grab this frame again */
839 }
840 }
841
842 (*f)->status = F_READY;
843 (*f)->queued = 0;
844
845 /* Take a pointer to the new frame from the FIFO list.
846 If the list is empty,we'll use the temporary frame*/
847 if (*cam->requested_frame)
848 w9968cf_pop_frame(cam, &cam->frame_current);
849 else {
850 cam->frame_current = &cam->frame_tmp;
851 (*f)->status = F_UNUSED;
852 }
853
854 } else if ((*f)->status == F_ERROR)
855 (*f)->status = F_UNUSED; /* grab it again */
856
857 PDBGG("Frame length %lu | pack.#%u | pack.len. %u | state %d",
858 (unsigned long)(*f)->length, i, len, (*f)->status)
859
860 } /* end for */
861
862 /* Resubmit this URB */
863 urb->dev = cam->usbdev;
864 urb->status = 0;
865 spin_lock(&cam->urb_lock);
866 if (cam->streaming)
867 if ((err = usb_submit_urb(urb, GFP_ATOMIC))) {
868 cam->misconfigured = 1;
869 DBG(1, "Couldn't resubmit the URB: error %d, %s",
870 err, symbolic(urb_errlist, err))
871 }
872 spin_unlock(&cam->urb_lock);
873
874 /* Wake up the user process */
875 wake_up_interruptible(&cam->wait_queue);
876}
877
878
879/*---------------------------------------------------------------------------
880 Setup the URB structures for the isochronous transfer.
881 Submit the URBs so that the data transfer begins.
882 Return 0 on success, a negative number otherwise.
883 ---------------------------------------------------------------------------*/
884static int w9968cf_start_transfer(struct w9968cf_device* cam)
885{
886 struct usb_device *udev = cam->usbdev;
887 struct urb* urb;
888 const u16 p_size = wMaxPacketSize[cam->altsetting-1];
889 u16 w, h, d;
890 int vidcapt;
891 u32 t_size;
892 int err = 0;
893 s8 i, j;
894
895 for (i = 0; i < W9968CF_URBS; i++) {
896 urb = usb_alloc_urb(W9968CF_ISO_PACKETS, GFP_KERNEL);
897 if (!urb) {
898 for (j = 0; j < i; j++)
899 usb_free_urb(cam->urb[j]);
900 DBG(1, "Couldn't allocate the URB structures")
901 return -ENOMEM;
902 }
903
904 cam->urb[i] = urb;
905 urb->dev = udev;
906 urb->context = (void*)cam;
907 urb->pipe = usb_rcvisocpipe(udev, 1);
908 urb->transfer_flags = URB_ISO_ASAP;
909 urb->number_of_packets = W9968CF_ISO_PACKETS;
910 urb->complete = w9968cf_urb_complete;
911 urb->transfer_buffer = cam->transfer_buffer[i];
912 urb->transfer_buffer_length = p_size*W9968CF_ISO_PACKETS;
913 urb->interval = 1;
914 for (j = 0; j < W9968CF_ISO_PACKETS; j++) {
915 urb->iso_frame_desc[j].offset = p_size*j;
916 urb->iso_frame_desc[j].length = p_size;
917 }
918 }
919
920 /* Transfer size per frame, in WORD ! */
921 d = cam->hw_depth;
922 w = cam->hw_width;
923 h = cam->hw_height;
924
925 t_size = (w*h*d)/16;
926
927 err = w9968cf_write_reg(cam, 0xbf17, 0x00); /* reset everything */
928 err += w9968cf_write_reg(cam, 0xbf10, 0x00); /* normal operation */
929
930 /* Transfer size */
931 err += w9968cf_write_reg(cam, t_size & 0xffff, 0x3d); /* low bits */
932 err += w9968cf_write_reg(cam, t_size >> 16, 0x3e); /* high bits */
933
934 if (cam->vpp_flag & VPP_DECOMPRESSION)
935 err += w9968cf_upload_quantizationtables(cam);
936
937 vidcapt = w9968cf_read_reg(cam, 0x16); /* read picture settings */
938 err += w9968cf_write_reg(cam, vidcapt|0x8000, 0x16); /* capt. enable */
939
940 err += usb_set_interface(udev, 0, cam->altsetting);
941 err += w9968cf_write_reg(cam, 0x8a05, 0x3c); /* USB FIFO enable */
942
943 if (err || (vidcapt < 0)) {
944 for (i = 0; i < W9968CF_URBS; i++)
945 usb_free_urb(cam->urb[i]);
946 DBG(1, "Couldn't tell the camera to start the data transfer")
947 return err;
948 }
949
950 w9968cf_init_framelist(cam);
951
952 /* Begin to grab into the temporary buffer */
953 cam->frame_tmp.status = F_UNUSED;
954 cam->frame_tmp.queued = 0;
955 cam->frame_current = &cam->frame_tmp;
956
957 if (!(cam->vpp_flag & VPP_DECOMPRESSION))
958 DBG(5, "Isochronous transfer size: %lu bytes/frame",
959 (unsigned long)t_size*2)
960
961 DBG(5, "Starting the isochronous transfer...")
962
963 cam->streaming = 1;
964
965 /* Submit the URBs */
966 for (i = 0; i < W9968CF_URBS; i++) {
967 err = usb_submit_urb(cam->urb[i], GFP_KERNEL);
968 if (err) {
969 cam->streaming = 0;
970 for (j = i-1; j >= 0; j--) {
971 usb_kill_urb(cam->urb[j]);
972 usb_free_urb(cam->urb[j]);
973 }
974 DBG(1, "Couldn't send a transfer request to the "
975 "USB core (error #%d, %s)", err,
976 symbolic(urb_errlist, err))
977 return err;
978 }
979 }
980
981 return 0;
982}
983
984
985/*--------------------------------------------------------------------------
986 Stop the isochronous transfer and set alternate setting to 0 (0Mb/s).
987 Return 0 on success, a negative number otherwise.
988 --------------------------------------------------------------------------*/
989static int w9968cf_stop_transfer(struct w9968cf_device* cam)
990{
991 struct usb_device *udev = cam->usbdev;
992 unsigned long lock_flags;
993 int err = 0;
994 s8 i;
995
996 if (!cam->streaming)
997 return 0;
998
999 /* This avoids race conditions with usb_submit_urb()
1000 in the URB completition handler */
1001 spin_lock_irqsave(&cam->urb_lock, lock_flags);
1002 cam->streaming = 0;
1003 spin_unlock_irqrestore(&cam->urb_lock, lock_flags);
1004
1005 for (i = W9968CF_URBS-1; i >= 0; i--)
1006 if (cam->urb[i]) {
1007 usb_kill_urb(cam->urb[i]);
1008 usb_free_urb(cam->urb[i]);
1009 cam->urb[i] = NULL;
1010 }
1011
1012 if (cam->disconnected)
1013 goto exit;
1014
1015 err = w9968cf_write_reg(cam, 0x0a05, 0x3c); /* stop USB transfer */
1016 err += usb_set_interface(udev, 0, 0); /* 0 Mb/s */
1017 err += w9968cf_write_reg(cam, 0x0000, 0x39); /* disable JPEG encoder */
1018 err += w9968cf_write_reg(cam, 0x0000, 0x16); /* stop video capture */
1019
1020 if (err) {
1021 DBG(2, "Failed to tell the camera to stop the isochronous "
1022 "transfer. However this is not a critical error.")
1023 return -EIO;
1024 }
1025
1026exit:
1027 DBG(5, "Isochronous transfer stopped")
1028 return 0;
1029}
1030
1031
1032/*--------------------------------------------------------------------------
1033 Write a W9968CF register.
1034 Return 0 on success, -1 otherwise.
1035 --------------------------------------------------------------------------*/
1036static int w9968cf_write_reg(struct w9968cf_device* cam, u16 value, u16 index)
1037{
1038 struct usb_device* udev = cam->usbdev;
1039 int res;
1040
1041 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0,
1042 USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_DEVICE,
1043 value, index, NULL, 0, W9968CF_USB_CTRL_TIMEOUT);
1044
1045 if (res < 0)
1046 DBG(4, "Failed to write a register "
1047 "(value 0x%04X, index 0x%02X, error #%d, %s)",
1048 value, index, res, symbolic(urb_errlist, res))
1049
1050 return (res >= 0) ? 0 : -1;
1051}
1052
1053
1054/*--------------------------------------------------------------------------
1055 Read a W9968CF register.
1056 Return the register value on success, -1 otherwise.
1057 --------------------------------------------------------------------------*/
1058static int w9968cf_read_reg(struct w9968cf_device* cam, u16 index)
1059{
1060 struct usb_device* udev = cam->usbdev;
1061 u16* buff = cam->control_buffer;
1062 int res;
1063
1064 res = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), 1,
1065 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1066 0, index, buff, 2, W9968CF_USB_CTRL_TIMEOUT);
1067
1068 if (res < 0)
1069 DBG(4, "Failed to read a register "
1070 "(index 0x%02X, error #%d, %s)",
1071 index, res, symbolic(urb_errlist, res))
1072
1073 return (res >= 0) ? (int)(*buff) : -1;
1074}
1075
1076
1077/*--------------------------------------------------------------------------
1078 Write 64-bit data to the fast serial bus registers.
1079 Return 0 on success, -1 otherwise.
1080 --------------------------------------------------------------------------*/
1081static int w9968cf_write_fsb(struct w9968cf_device* cam, u16* data)
1082{
1083 struct usb_device* udev = cam->usbdev;
1084 u16 value;
1085 int res;
1086
1087 value = *data++;
1088
1089 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0,
1090 USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_DEVICE,
1091 value, 0x06, data, 6, W9968CF_USB_CTRL_TIMEOUT);
1092
1093 if (res < 0)
1094 DBG(4, "Failed to write the FSB registers "
1095 "(error #%d, %s)", res, symbolic(urb_errlist, res))
1096
1097 return (res >= 0) ? 0 : -1;
1098}
1099
1100
1101/*--------------------------------------------------------------------------
1102 Write data to the serial bus control register.
1103 Return 0 on success, a negative number otherwise.
1104 --------------------------------------------------------------------------*/
1105static int w9968cf_write_sb(struct w9968cf_device* cam, u16 value)
1106{
1107 int err = 0;
1108
1109 err = w9968cf_write_reg(cam, value, 0x01);
1110 udelay(W9968CF_I2C_BUS_DELAY);
1111
1112 return err;
1113}
1114
1115
1116/*--------------------------------------------------------------------------
1117 Read data from the serial bus control register.
1118 Return 0 on success, a negative number otherwise.
1119 --------------------------------------------------------------------------*/
1120static int w9968cf_read_sb(struct w9968cf_device* cam)
1121{
1122 int v = 0;
1123
1124 v = w9968cf_read_reg(cam, 0x01);
1125 udelay(W9968CF_I2C_BUS_DELAY);
1126
1127 return v;
1128}
1129
1130
1131/*--------------------------------------------------------------------------
1132 Upload quantization tables for the JPEG compression.
1133 This function is called by w9968cf_start_transfer().
1134 Return 0 on success, a negative number otherwise.
1135 --------------------------------------------------------------------------*/
1136static int w9968cf_upload_quantizationtables(struct w9968cf_device* cam)
1137{
1138 u16 a, b;
1139 int err = 0, i, j;
1140
1141 err += w9968cf_write_reg(cam, 0x0010, 0x39); /* JPEG clock enable */
1142
1143 for (i = 0, j = 0; i < 32; i++, j += 2) {
1144 a = Y_QUANTABLE[j] | ((unsigned)(Y_QUANTABLE[j+1]) << 8);
1145 b = UV_QUANTABLE[j] | ((unsigned)(UV_QUANTABLE[j+1]) << 8);
1146 err += w9968cf_write_reg(cam, a, 0x40+i);
1147 err += w9968cf_write_reg(cam, b, 0x60+i);
1148 }
1149 err += w9968cf_write_reg(cam, 0x0012, 0x39); /* JPEG encoder enable */
1150
1151 return err;
1152}
1153
1154
1155
1156/****************************************************************************
1157 * Low-level I2C I/O functions. *
1158 * The adapter supports the following I2C transfer functions: *
1159 * i2c_adap_fastwrite_byte_data() (at 400 kHz bit frequency only) *
1160 * i2c_adap_read_byte_data() *
1161 * i2c_adap_read_byte() *
1162 ****************************************************************************/
1163
1164static int w9968cf_smbus_start(struct w9968cf_device* cam)
1165{
1166 int err = 0;
1167
1168 err += w9968cf_write_sb(cam, 0x0011); /* SDE=1, SDA=0, SCL=1 */
1169 err += w9968cf_write_sb(cam, 0x0010); /* SDE=1, SDA=0, SCL=0 */
1170
1171 return err;
1172}
1173
1174
1175static int w9968cf_smbus_stop(struct w9968cf_device* cam)
1176{
1177 int err = 0;
1178
1179 err += w9968cf_write_sb(cam, 0x0011); /* SDE=1, SDA=0, SCL=1 */
1180 err += w9968cf_write_sb(cam, 0x0013); /* SDE=1, SDA=1, SCL=1 */
1181
1182 return err;
1183}
1184
1185
1186static int w9968cf_smbus_write_byte(struct w9968cf_device* cam, u8 v)
1187{
1188 u8 bit;
1189 int err = 0, sda;
1190
1191 for (bit = 0 ; bit < 8 ; bit++) {
1192 sda = (v & 0x80) ? 2 : 0;
1193 v <<= 1;
1194 /* SDE=1, SDA=sda, SCL=0 */
1195 err += w9968cf_write_sb(cam, 0x10 | sda);
1196 /* SDE=1, SDA=sda, SCL=1 */
1197 err += w9968cf_write_sb(cam, 0x11 | sda);
1198 /* SDE=1, SDA=sda, SCL=0 */
1199 err += w9968cf_write_sb(cam, 0x10 | sda);
1200 }
1201
1202 return err;
1203}
1204
1205
1206static int w9968cf_smbus_read_byte(struct w9968cf_device* cam, u8* v)
1207{
1208 u8 bit;
1209 int err = 0;
1210
1211 *v = 0;
1212 for (bit = 0 ; bit < 8 ; bit++) {
1213 *v <<= 1;
1214 err += w9968cf_write_sb(cam, 0x0013);
1215 *v |= (w9968cf_read_sb(cam) & 0x0008) ? 1 : 0;
1216 err += w9968cf_write_sb(cam, 0x0012);
1217 }
1218
1219 return err;
1220}
1221
1222
1223static int w9968cf_smbus_write_ack(struct w9968cf_device* cam)
1224{
1225 int err = 0;
1226
1227 err += w9968cf_write_sb(cam, 0x0010); /* SDE=1, SDA=0, SCL=0 */
1228 err += w9968cf_write_sb(cam, 0x0011); /* SDE=1, SDA=0, SCL=1 */
1229 err += w9968cf_write_sb(cam, 0x0010); /* SDE=1, SDA=0, SCL=0 */
1230
1231 return err;
1232}
1233
1234
1235static int w9968cf_smbus_read_ack(struct w9968cf_device* cam)
1236{
1237 int err = 0, sda;
1238
1239 err += w9968cf_write_sb(cam, 0x0013); /* SDE=1, SDA=1, SCL=1 */
1240 sda = (w9968cf_read_sb(cam) & 0x08) ? 1 : 0; /* sda = SDA */
1241 err += w9968cf_write_sb(cam, 0x0012); /* SDE=1, SDA=1, SCL=0 */
1242 if (sda < 0)
1243 err += sda;
1244 if (sda == 1) {
1245 DBG(6, "Couldn't receive the ACK")
1246 err += -1;
1247 }
1248
1249 return err;
1250}
1251
1252
1253/* This seems to refresh the communication through the serial bus */
1254static int w9968cf_smbus_refresh_bus(struct w9968cf_device* cam)
1255{
1256 int err = 0, j;
1257
1258 for (j = 1; j <= 10; j++) {
1259 err = w9968cf_write_reg(cam, 0x0020, 0x01);
1260 err += w9968cf_write_reg(cam, 0x0000, 0x01);
1261 if (err)
1262 break;
1263 }
1264
1265 return err;
1266}
1267
1268
1269/* SMBus protocol: S Addr Wr [A] Subaddr [A] Value [A] P */
1270static int
1271w9968cf_i2c_adap_fastwrite_byte_data(struct w9968cf_device* cam,
1272 u16 address, u8 subaddress,u8 value)
1273{
1274 u16* data = cam->data_buffer;
1275 int err = 0;
1276
1277 err += w9968cf_smbus_refresh_bus(cam);
1278
1279 /* Enable SBUS outputs */
1280 err += w9968cf_write_sb(cam, 0x0020);
1281
1282 data[0] = 0x082f | ((address & 0x80) ? 0x1500 : 0x0);
1283 data[0] |= (address & 0x40) ? 0x4000 : 0x0;
1284 data[1] = 0x2082 | ((address & 0x40) ? 0x0005 : 0x0);
1285 data[1] |= (address & 0x20) ? 0x0150 : 0x0;
1286 data[1] |= (address & 0x10) ? 0x5400 : 0x0;
1287 data[2] = 0x8208 | ((address & 0x08) ? 0x0015 : 0x0);
1288 data[2] |= (address & 0x04) ? 0x0540 : 0x0;
1289 data[2] |= (address & 0x02) ? 0x5000 : 0x0;
1290 data[3] = 0x1d20 | ((address & 0x02) ? 0x0001 : 0x0);
1291 data[3] |= (address & 0x01) ? 0x0054 : 0x0;
1292
1293 err += w9968cf_write_fsb(cam, data);
1294
1295 data[0] = 0x8208 | ((subaddress & 0x80) ? 0x0015 : 0x0);
1296 data[0] |= (subaddress & 0x40) ? 0x0540 : 0x0;
1297 data[0] |= (subaddress & 0x20) ? 0x5000 : 0x0;
1298 data[1] = 0x0820 | ((subaddress & 0x20) ? 0x0001 : 0x0);
1299 data[1] |= (subaddress & 0x10) ? 0x0054 : 0x0;
1300 data[1] |= (subaddress & 0x08) ? 0x1500 : 0x0;
1301 data[1] |= (subaddress & 0x04) ? 0x4000 : 0x0;
1302 data[2] = 0x2082 | ((subaddress & 0x04) ? 0x0005 : 0x0);
1303 data[2] |= (subaddress & 0x02) ? 0x0150 : 0x0;
1304 data[2] |= (subaddress & 0x01) ? 0x5400 : 0x0;
1305 data[3] = 0x001d;
1306
1307 err += w9968cf_write_fsb(cam, data);
1308
1309 data[0] = 0x8208 | ((value & 0x80) ? 0x0015 : 0x0);
1310 data[0] |= (value & 0x40) ? 0x0540 : 0x0;
1311 data[0] |= (value & 0x20) ? 0x5000 : 0x0;
1312 data[1] = 0x0820 | ((value & 0x20) ? 0x0001 : 0x0);
1313 data[1] |= (value & 0x10) ? 0x0054 : 0x0;
1314 data[1] |= (value & 0x08) ? 0x1500 : 0x0;
1315 data[1] |= (value & 0x04) ? 0x4000 : 0x0;
1316 data[2] = 0x2082 | ((value & 0x04) ? 0x0005 : 0x0);
1317 data[2] |= (value & 0x02) ? 0x0150 : 0x0;
1318 data[2] |= (value & 0x01) ? 0x5400 : 0x0;
1319 data[3] = 0xfe1d;
1320
1321 err += w9968cf_write_fsb(cam, data);
1322
1323 /* Disable SBUS outputs */
1324 err += w9968cf_write_sb(cam, 0x0000);
1325
1326 if (!err)
1327 DBG(5, "I2C write byte data done, addr.0x%04X, subaddr.0x%02X "
1328 "value 0x%02X", address, subaddress, value)
1329 else
1330 DBG(5, "I2C write byte data failed, addr.0x%04X, "
1331 "subaddr.0x%02X, value 0x%02X",
1332 address, subaddress, value)
1333
1334 return err;
1335}
1336
1337
1338/* SMBus protocol: S Addr Wr [A] Subaddr [A] P S Addr+1 Rd [A] [Value] NA P */
1339static int
1340w9968cf_i2c_adap_read_byte_data(struct w9968cf_device* cam,
1341 u16 address, u8 subaddress,
1342 u8* value)
1343{
1344 int err = 0;
1345
1346 /* Serial data enable */
1347 err += w9968cf_write_sb(cam, 0x0013); /* don't change ! */
1348
1349 err += w9968cf_smbus_start(cam);
1350 err += w9968cf_smbus_write_byte(cam, address);
1351 err += w9968cf_smbus_read_ack(cam);
1352 err += w9968cf_smbus_write_byte(cam, subaddress);
1353 err += w9968cf_smbus_read_ack(cam);
1354 err += w9968cf_smbus_stop(cam);
1355 err += w9968cf_smbus_start(cam);
1356 err += w9968cf_smbus_write_byte(cam, address + 1);
1357 err += w9968cf_smbus_read_ack(cam);
1358 err += w9968cf_smbus_read_byte(cam, value);
1359 err += w9968cf_smbus_write_ack(cam);
1360 err += w9968cf_smbus_stop(cam);
1361
1362 /* Serial data disable */
1363 err += w9968cf_write_sb(cam, 0x0000);
1364
1365 if (!err)
1366 DBG(5, "I2C read byte data done, addr.0x%04X, "
1367 "subaddr.0x%02X, value 0x%02X",
1368 address, subaddress, *value)
1369 else
1370 DBG(5, "I2C read byte data failed, addr.0x%04X, "
1371 "subaddr.0x%02X, wrong value 0x%02X",
1372 address, subaddress, *value)
1373
1374 return err;
1375}
1376
1377
1378/* SMBus protocol: S Addr+1 Rd [A] [Value] NA P */
1379static int
1380w9968cf_i2c_adap_read_byte(struct w9968cf_device* cam,
1381 u16 address, u8* value)
1382{
1383 int err = 0;
1384
1385 /* Serial data enable */
1386 err += w9968cf_write_sb(cam, 0x0013);
1387
1388 err += w9968cf_smbus_start(cam);
1389 err += w9968cf_smbus_write_byte(cam, address + 1);
1390 err += w9968cf_smbus_read_ack(cam);
1391 err += w9968cf_smbus_read_byte(cam, value);
1392 err += w9968cf_smbus_write_ack(cam);
1393 err += w9968cf_smbus_stop(cam);
1394
1395 /* Serial data disable */
1396 err += w9968cf_write_sb(cam, 0x0000);
1397
1398 if (!err)
1399 DBG(5, "I2C read byte done, addr.0x%04X, "
1400 "value 0x%02X", address, *value)
1401 else
1402 DBG(5, "I2C read byte failed, addr.0x%04X, "
1403 "wrong value 0x%02X", address, *value)
1404
1405 return err;
1406}
1407
1408
1409/* SMBus protocol: S Addr Wr [A] Value [A] P */
1410static int
1411w9968cf_i2c_adap_write_byte(struct w9968cf_device* cam,
1412 u16 address, u8 value)
1413{
1414 DBG(4, "i2c_write_byte() is an unsupported transfer mode")
1415 return -EINVAL;
1416}
1417
1418
1419
1420/****************************************************************************
1421 * I2C interface to kernel *
1422 ****************************************************************************/
1423
1424static int
1425w9968cf_i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
1426 unsigned short flags, char read_write, u8 command,
1427 int size, union i2c_smbus_data *data)
1428{
1429 struct v4l2_device *v4l2_dev = i2c_get_adapdata(adapter);
1430 struct w9968cf_device *cam = to_cam(v4l2_dev);
1431 u8 i;
1432 int err = 0;
1433
1434 if (size == I2C_SMBUS_BYTE) {
1435 /* Why addr <<= 1? See OVXXX0_SID defines in ovcamchip.h */
1436 addr <<= 1;
1437
1438 if (read_write == I2C_SMBUS_WRITE)
1439 err = w9968cf_i2c_adap_write_byte(cam, addr, command);
1440 else if (read_write == I2C_SMBUS_READ)
1441 for (i = 1; i <= W9968CF_I2C_RW_RETRIES; i++) {
1442 err = w9968cf_i2c_adap_read_byte(cam, addr,
1443 &data->byte);
1444 if (err) {
1445 if (w9968cf_smbus_refresh_bus(cam)) {
1446 err = -EIO;
1447 break;
1448 }
1449 } else
1450 break;
1451 }
1452 } else if (size == I2C_SMBUS_BYTE_DATA) {
1453 addr <<= 1;
1454
1455 if (read_write == I2C_SMBUS_WRITE)
1456 err = w9968cf_i2c_adap_fastwrite_byte_data(cam, addr,
1457 command, data->byte);
1458 else if (read_write == I2C_SMBUS_READ) {
1459 for (i = 1; i <= W9968CF_I2C_RW_RETRIES; i++) {
1460 err = w9968cf_i2c_adap_read_byte_data(cam,addr,
1461 command, &data->byte);
1462 if (err) {
1463 if (w9968cf_smbus_refresh_bus(cam)) {
1464 err = -EIO;
1465 break;
1466 }
1467 } else
1468 break;
1469 }
1470
1471 } else
1472 return -EINVAL;
1473
1474 } else {
1475 DBG(4, "Unsupported I2C transfer mode (%d)", size)
1476 return -EINVAL;
1477 }
1478 return err;
1479}
1480
1481
1482static u32 w9968cf_i2c_func(struct i2c_adapter* adap)
1483{
1484 return I2C_FUNC_SMBUS_READ_BYTE |
1485 I2C_FUNC_SMBUS_READ_BYTE_DATA |
1486 I2C_FUNC_SMBUS_WRITE_BYTE_DATA;
1487}
1488
1489
1490static int w9968cf_i2c_init(struct w9968cf_device* cam)
1491{
1492 int err = 0;
1493
1494 static struct i2c_algorithm algo = {
1495 .smbus_xfer = w9968cf_i2c_smbus_xfer,
1496 .functionality = w9968cf_i2c_func,
1497 };
1498
1499 static struct i2c_adapter adap = {
1500 .owner = THIS_MODULE,
1501 .algo = &algo,
1502 };
1503
1504 memcpy(&cam->i2c_adapter, &adap, sizeof(struct i2c_adapter));
1505 strcpy(cam->i2c_adapter.name, "w9968cf");
1506 cam->i2c_adapter.dev.parent = &cam->usbdev->dev;
1507 i2c_set_adapdata(&cam->i2c_adapter, &cam->v4l2_dev);
1508
1509 DBG(6, "Registering I2C adapter with kernel...")
1510
1511 err = i2c_add_adapter(&cam->i2c_adapter);
1512 if (err)
1513 DBG(1, "Failed to register the I2C adapter")
1514 else
1515 DBG(5, "I2C adapter registered")
1516
1517 return err;
1518}
1519
1520
1521
1522/****************************************************************************
1523 * Helper functions *
1524 ****************************************************************************/
1525
1526/*--------------------------------------------------------------------------
1527 Turn on the LED on some webcams. A beep should be heard too.
1528 Return 0 on success, a negative number otherwise.
1529 --------------------------------------------------------------------------*/
1530static int w9968cf_turn_on_led(struct w9968cf_device* cam)
1531{
1532 int err = 0;
1533
1534 err += w9968cf_write_reg(cam, 0xff00, 0x00); /* power-down */
1535 err += w9968cf_write_reg(cam, 0xbf17, 0x00); /* reset everything */
1536 err += w9968cf_write_reg(cam, 0xbf10, 0x00); /* normal operation */
1537 err += w9968cf_write_reg(cam, 0x0010, 0x01); /* serial bus, SDS high */
1538 err += w9968cf_write_reg(cam, 0x0000, 0x01); /* serial bus, SDS low */
1539 err += w9968cf_write_reg(cam, 0x0010, 0x01); /* ..high 'beep-beep' */
1540
1541 if (err)
1542 DBG(2, "Couldn't turn on the LED")
1543
1544 DBG(5, "LED turned on")
1545
1546 return err;
1547}
1548
1549
1550/*--------------------------------------------------------------------------
1551 Write some registers for the device initialization.
1552 This function is called once on open().
1553 Return 0 on success, a negative number otherwise.
1554 --------------------------------------------------------------------------*/
1555static int w9968cf_init_chip(struct w9968cf_device* cam)
1556{
1557 unsigned long hw_bufsize = cam->maxwidth*cam->maxheight*2,
1558 y0 = 0x0000,
1559 u0 = y0 + hw_bufsize/2,
1560 v0 = u0 + hw_bufsize/4,
1561 y1 = v0 + hw_bufsize/4,
1562 u1 = y1 + hw_bufsize/2,
1563 v1 = u1 + hw_bufsize/4;
1564 int err = 0;
1565
1566 err += w9968cf_write_reg(cam, 0xff00, 0x00); /* power off */
1567 err += w9968cf_write_reg(cam, 0xbf10, 0x00); /* power on */
1568
1569 err += w9968cf_write_reg(cam, 0x405d, 0x03); /* DRAM timings */
1570 err += w9968cf_write_reg(cam, 0x0030, 0x04); /* SDRAM timings */
1571
1572 err += w9968cf_write_reg(cam, y0 & 0xffff, 0x20); /* Y buf.0, low */
1573 err += w9968cf_write_reg(cam, y0 >> 16, 0x21); /* Y buf.0, high */
1574 err += w9968cf_write_reg(cam, u0 & 0xffff, 0x24); /* U buf.0, low */
1575 err += w9968cf_write_reg(cam, u0 >> 16, 0x25); /* U buf.0, high */
1576 err += w9968cf_write_reg(cam, v0 & 0xffff, 0x28); /* V buf.0, low */
1577 err += w9968cf_write_reg(cam, v0 >> 16, 0x29); /* V buf.0, high */
1578
1579 err += w9968cf_write_reg(cam, y1 & 0xffff, 0x22); /* Y buf.1, low */
1580 err += w9968cf_write_reg(cam, y1 >> 16, 0x23); /* Y buf.1, high */
1581 err += w9968cf_write_reg(cam, u1 & 0xffff, 0x26); /* U buf.1, low */
1582 err += w9968cf_write_reg(cam, u1 >> 16, 0x27); /* U buf.1, high */
1583 err += w9968cf_write_reg(cam, v1 & 0xffff, 0x2a); /* V buf.1, low */
1584 err += w9968cf_write_reg(cam, v1 >> 16, 0x2b); /* V buf.1, high */
1585
1586 err += w9968cf_write_reg(cam, y1 & 0xffff, 0x32); /* JPEG buf 0 low */
1587 err += w9968cf_write_reg(cam, y1 >> 16, 0x33); /* JPEG buf 0 high */
1588
1589 err += w9968cf_write_reg(cam, y1 & 0xffff, 0x34); /* JPEG buf 1 low */
1590 err += w9968cf_write_reg(cam, y1 >> 16, 0x35); /* JPEG bug 1 high */
1591
1592 err += w9968cf_write_reg(cam, 0x0000, 0x36);/* JPEG restart interval */
1593 err += w9968cf_write_reg(cam, 0x0804, 0x37);/*JPEG VLE FIFO threshold*/
1594 err += w9968cf_write_reg(cam, 0x0000, 0x38);/* disable hw up-scaling */
1595 err += w9968cf_write_reg(cam, 0x0000, 0x3f); /* JPEG/MCTL test data */
1596
1597 err += w9968cf_set_picture(cam, cam->picture); /* this before */
1598 err += w9968cf_set_window(cam, cam->window);
1599
1600 if (err)
1601 DBG(1, "Chip initialization failed")
1602 else
1603 DBG(5, "Chip successfully initialized")
1604
1605 return err;
1606}
1607
1608
1609/*--------------------------------------------------------------------------
1610 Return non-zero if the palette is supported, 0 otherwise.
1611 --------------------------------------------------------------------------*/
1612static inline u16 w9968cf_valid_palette(u16 palette)
1613{
1614 u8 i = 0;
1615 while (w9968cf_formatlist[i].palette != 0) {
1616 if (palette == w9968cf_formatlist[i].palette)
1617 return palette;
1618 i++;
1619 }
1620 return 0;
1621}
1622
1623
1624/*--------------------------------------------------------------------------
1625 Return the depth corresponding to the given palette.
1626 Palette _must_ be supported !
1627 --------------------------------------------------------------------------*/
1628static inline u16 w9968cf_valid_depth(u16 palette)
1629{
1630 u8 i=0;
1631 while (w9968cf_formatlist[i].palette != palette)
1632 i++;
1633
1634 return w9968cf_formatlist[i].depth;
1635}
1636
1637
1638/*--------------------------------------------------------------------------
1639 Return non-zero if the format requires decompression, 0 otherwise.
1640 --------------------------------------------------------------------------*/
1641static inline u8 w9968cf_need_decompression(u16 palette)
1642{
1643 u8 i = 0;
1644 while (w9968cf_formatlist[i].palette != 0) {
1645 if (palette == w9968cf_formatlist[i].palette)
1646 return w9968cf_formatlist[i].compression;
1647 i++;
1648 }
1649 return 0;
1650}
1651
1652
1653/*--------------------------------------------------------------------------
1654 Change the picture settings of the camera.
1655 Return 0 on success, a negative number otherwise.
1656 --------------------------------------------------------------------------*/
1657static int
1658w9968cf_set_picture(struct w9968cf_device* cam, struct video_picture pict)
1659{
1660 u16 fmt, hw_depth, hw_palette, reg_v = 0x0000;
1661 int err = 0;
1662
1663 /* Make sure we are using a valid depth */
1664 pict.depth = w9968cf_valid_depth(pict.palette);
1665
1666 fmt = pict.palette;
1667
1668 hw_depth = pict.depth; /* depth used by the winbond chip */
1669 hw_palette = pict.palette; /* palette used by the winbond chip */
1670
1671 /* VS & HS polarities */
1672 reg_v = (cam->vs_polarity << 12) | (cam->hs_polarity << 11);
1673
1674 switch (fmt)
1675 {
1676 case VIDEO_PALETTE_UYVY:
1677 reg_v |= 0x0000;
1678 cam->vpp_flag = VPP_NONE;
1679 break;
1680 case VIDEO_PALETTE_YUV422P:
1681 reg_v |= 0x0002;
1682 cam->vpp_flag = VPP_DECOMPRESSION;
1683 break;
1684 case VIDEO_PALETTE_YUV420:
1685 case VIDEO_PALETTE_YUV420P:
1686 reg_v |= 0x0003;
1687 cam->vpp_flag = VPP_DECOMPRESSION;
1688 break;
1689 case VIDEO_PALETTE_YUYV:
1690 case VIDEO_PALETTE_YUV422:
1691 reg_v |= 0x0000;
1692 cam->vpp_flag = VPP_SWAP_YUV_BYTES;
1693 hw_palette = VIDEO_PALETTE_UYVY;
1694 break;
1695 /* Original video is used instead of RGBX palettes.
1696 Software conversion later. */
1697 case VIDEO_PALETTE_GREY:
1698 case VIDEO_PALETTE_RGB555:
1699 case VIDEO_PALETTE_RGB565:
1700 case VIDEO_PALETTE_RGB24:
1701 case VIDEO_PALETTE_RGB32:
1702 reg_v |= 0x0000; /* UYVY 16 bit is used */
1703 hw_depth = 16;
1704 hw_palette = VIDEO_PALETTE_UYVY;
1705 cam->vpp_flag = VPP_UYVY_TO_RGBX;
1706 break;
1707 }
1708
1709 /* NOTE: due to memory issues, it is better to disable the hardware
1710 double buffering during compression */
1711 if (cam->double_buffer && !(cam->vpp_flag & VPP_DECOMPRESSION))
1712 reg_v |= 0x0080;
1713
1714 if (cam->clamping)
1715 reg_v |= 0x0020;
1716
1717 if (cam->filter_type == 1)
1718 reg_v |= 0x0008;
1719 else if (cam->filter_type == 2)
1720 reg_v |= 0x000c;
1721
1722 if ((err = w9968cf_write_reg(cam, reg_v, 0x16)))
1723 goto error;
1724
1725 if ((err = w9968cf_sensor_update_picture(cam, pict)))
1726 goto error;
1727
1728 /* If all went well, update the device data structure */
1729 memcpy(&cam->picture, &pict, sizeof(pict));
1730 cam->hw_depth = hw_depth;
1731 cam->hw_palette = hw_palette;
1732
1733 /* Settings changed, so we clear the frame buffers */
1734 memset(cam->frame[0].buffer, 0, cam->nbuffers*cam->frame[0].size);
1735
1736 DBG(4, "Palette is %s, depth is %u bpp",
1737 symbolic(v4l1_plist, pict.palette), pict.depth)
1738
1739 return 0;
1740
1741error:
1742 DBG(1, "Failed to change picture settings")
1743 return err;
1744}
1745
1746
1747/*--------------------------------------------------------------------------
1748 Change the capture area size of the camera.
1749 This function _must_ be called _after_ w9968cf_set_picture().
1750 Return 0 on success, a negative number otherwise.
1751 --------------------------------------------------------------------------*/
1752static int
1753w9968cf_set_window(struct w9968cf_device* cam, struct video_window win)
1754{
1755 u16 x, y, w, h, scx, scy, cw, ch, ax, ay;
1756 unsigned long fw, fh;
1757 struct ovcamchip_window s_win;
1758 int err = 0;
1759
1760 /* Work around to avoid FP arithmetics */
1761 #define SC(x) ((x) << 10)
1762 #define UNSC(x) ((x) >> 10)
1763
1764 /* Make sure we are using a supported resolution */
1765 if ((err = w9968cf_adjust_window_size(cam, &win.width, &win.height)))
1766 goto error;
1767
1768 /* Scaling factors */
1769 fw = SC(win.width) / cam->maxwidth;
1770 fh = SC(win.height) / cam->maxheight;
1771
1772 /* Set up the width and height values used by the chip */
1773 if ((win.width > cam->maxwidth) || (win.height > cam->maxheight)) {
1774 cam->vpp_flag |= VPP_UPSCALE;
1775 /* Calculate largest w,h mantaining the same w/h ratio */
1776 w = (fw >= fh) ? cam->maxwidth : SC(win.width)/fh;
1777 h = (fw >= fh) ? SC(win.height)/fw : cam->maxheight;
1778 if (w < cam->minwidth) /* just in case */
1779 w = cam->minwidth;
1780 if (h < cam->minheight) /* just in case */
1781 h = cam->minheight;
1782 } else {
1783 cam->vpp_flag &= ~VPP_UPSCALE;
1784 w = win.width;
1785 h = win.height;
1786 }
1787
1788 /* x,y offsets of the cropped area */
1789 scx = cam->start_cropx;
1790 scy = cam->start_cropy;
1791
1792 /* Calculate cropped area manteining the right w/h ratio */
1793 if (cam->largeview && !(cam->vpp_flag & VPP_UPSCALE)) {
1794 cw = (fw >= fh) ? cam->maxwidth : SC(win.width)/fh;
1795 ch = (fw >= fh) ? SC(win.height)/fw : cam->maxheight;
1796 } else {
1797 cw = w;
1798 ch = h;
1799 }
1800
1801 /* Setup the window of the sensor */
1802 s_win.format = VIDEO_PALETTE_UYVY;
1803 s_win.width = cam->maxwidth;
1804 s_win.height = cam->maxheight;
1805 s_win.quarter = 0; /* full progressive video */
1806
1807 /* Center it */
1808 s_win.x = (s_win.width - cw) / 2;
1809 s_win.y = (s_win.height - ch) / 2;
1810
1811 /* Clock divisor */
1812 if (cam->clockdiv >= 0)
1813 s_win.clockdiv = cam->clockdiv; /* manual override */
1814 else
1815 switch (cam->sensor) {
1816 case CC_OV6620:
1817 s_win.clockdiv = 0;
1818 break;
1819 case CC_OV6630:
1820 s_win.clockdiv = 0;
1821 break;
1822 case CC_OV76BE:
1823 case CC_OV7610:
1824 case CC_OV7620:
1825 s_win.clockdiv = 0;
1826 break;
1827 default:
1828 s_win.clockdiv = W9968CF_DEF_CLOCKDIVISOR;
1829 }
1830
1831 /* We have to scale win.x and win.y offsets */
1832 if ( (cam->largeview && !(cam->vpp_flag & VPP_UPSCALE))
1833 || (cam->vpp_flag & VPP_UPSCALE) ) {
1834 ax = SC(win.x)/fw;
1835 ay = SC(win.y)/fh;
1836 } else {
1837 ax = win.x;
1838 ay = win.y;
1839 }
1840
1841 if ((ax + cw) > cam->maxwidth)
1842 ax = cam->maxwidth - cw;
1843
1844 if ((ay + ch) > cam->maxheight)
1845 ay = cam->maxheight - ch;
1846
1847 /* Adjust win.x, win.y */
1848 if ( (cam->largeview && !(cam->vpp_flag & VPP_UPSCALE))
1849 || (cam->vpp_flag & VPP_UPSCALE) ) {
1850 win.x = UNSC(ax*fw);
1851 win.y = UNSC(ay*fh);
1852 } else {
1853 win.x = ax;
1854 win.y = ay;
1855 }
1856
1857 /* Offsets used by the chip */
1858 x = ax + s_win.x;
1859 y = ay + s_win.y;
1860
1861 /* Go ! */
1862 if ((err = w9968cf_sensor_cmd(cam, OVCAMCHIP_CMD_S_MODE, &s_win)))
1863 goto error;
1864
1865 err += w9968cf_write_reg(cam, scx + x, 0x10);
1866 err += w9968cf_write_reg(cam, scy + y, 0x11);
1867 err += w9968cf_write_reg(cam, scx + x + cw, 0x12);
1868 err += w9968cf_write_reg(cam, scy + y + ch, 0x13);
1869 err += w9968cf_write_reg(cam, w, 0x14);
1870 err += w9968cf_write_reg(cam, h, 0x15);
1871
1872 /* JPEG width & height */
1873 err += w9968cf_write_reg(cam, w, 0x30);
1874 err += w9968cf_write_reg(cam, h, 0x31);
1875
1876 /* Y & UV frame buffer strides (in WORD) */
1877 if (cam->vpp_flag & VPP_DECOMPRESSION) {
1878 err += w9968cf_write_reg(cam, w/2, 0x2c);
1879 err += w9968cf_write_reg(cam, w/4, 0x2d);
1880 } else
1881 err += w9968cf_write_reg(cam, w, 0x2c);
1882
1883 if (err)
1884 goto error;
1885
1886 /* If all went well, update the device data structure */
1887 memcpy(&cam->window, &win, sizeof(win));
1888 cam->hw_width = w;
1889 cam->hw_height = h;
1890
1891 /* Settings changed, so we clear the frame buffers */
1892 memset(cam->frame[0].buffer, 0, cam->nbuffers*cam->frame[0].size);
1893
1894 DBG(4, "The capture area is %dx%d, Offset (x,y)=(%u,%u)",
1895 win.width, win.height, win.x, win.y)
1896
1897 PDBGG("x=%u ,y=%u, w=%u, h=%u, ax=%u, ay=%u, s_win.x=%u, s_win.y=%u, "
1898 "cw=%u, ch=%u, win.x=%u, win.y=%u, win.width=%u, win.height=%u",
1899 x, y, w, h, ax, ay, s_win.x, s_win.y, cw, ch, win.x, win.y,
1900 win.width, win.height)
1901
1902 return 0;
1903
1904error:
1905 DBG(1, "Failed to change the capture area size")
1906 return err;
1907}
1908
1909
1910/*--------------------------------------------------------------------------
1911 Adjust the asked values for window width and height.
1912 Return 0 on success, -1 otherwise.
1913 --------------------------------------------------------------------------*/
1914static int
1915w9968cf_adjust_window_size(struct w9968cf_device *cam, u32 *width, u32 *height)
1916{
1917 unsigned int maxw, maxh, align;
1918
1919 maxw = cam->upscaling && !(cam->vpp_flag & VPP_DECOMPRESSION) &&
1920 w9968cf_vpp ? max((u16)W9968CF_MAX_WIDTH, cam->maxwidth)
1921 : cam->maxwidth;
1922 maxh = cam->upscaling && !(cam->vpp_flag & VPP_DECOMPRESSION) &&
1923 w9968cf_vpp ? max((u16)W9968CF_MAX_HEIGHT, cam->maxheight)
1924 : cam->maxheight;
1925 align = (cam->vpp_flag & VPP_DECOMPRESSION) ? 4 : 0;
1926
1927 v4l_bound_align_image(width, cam->minwidth, maxw, align,
1928 height, cam->minheight, maxh, align, 0);
1929
1930 PDBGG("Window size adjusted w=%u, h=%u ", *width, *height)
1931
1932 return 0;
1933}
1934
1935
1936/*--------------------------------------------------------------------------
1937 Initialize the FIFO list of requested frames.
1938 --------------------------------------------------------------------------*/
1939static void w9968cf_init_framelist(struct w9968cf_device* cam)
1940{
1941 u8 i;
1942
1943 for (i = 0; i < cam->nbuffers; i++) {
1944 cam->requested_frame[i] = NULL;
1945 cam->frame[i].queued = 0;
1946 cam->frame[i].status = F_UNUSED;
1947 }
1948}
1949
1950
1951/*--------------------------------------------------------------------------
1952 Add a frame in the FIFO list of requested frames.
1953 This function is called in process context.
1954 --------------------------------------------------------------------------*/
1955static void w9968cf_push_frame(struct w9968cf_device* cam, u8 f_num)
1956{
1957 u8 f;
1958 unsigned long lock_flags;
1959
1960 spin_lock_irqsave(&cam->flist_lock, lock_flags);
1961
1962 for (f=0; cam->requested_frame[f] != NULL; f++);
1963 cam->requested_frame[f] = &cam->frame[f_num];
1964 cam->frame[f_num].queued = 1;
1965 cam->frame[f_num].status = F_UNUSED; /* clear the status */
1966
1967 spin_unlock_irqrestore(&cam->flist_lock, lock_flags);
1968
1969 DBG(6, "Frame #%u pushed into the FIFO list. Position %u", f_num, f)
1970}
1971
1972
1973/*--------------------------------------------------------------------------
1974 Read, store and remove the first pointer in the FIFO list of requested
1975 frames. This function is called in interrupt context.
1976 --------------------------------------------------------------------------*/
1977static void
1978w9968cf_pop_frame(struct w9968cf_device* cam, struct w9968cf_frame_t** framep)
1979{
1980 u8 i;
1981
1982 spin_lock(&cam->flist_lock);
1983
1984 *framep = cam->requested_frame[0];
1985
1986 /* Shift the list of pointers */
1987 for (i = 0; i < cam->nbuffers-1; i++)
1988 cam->requested_frame[i] = cam->requested_frame[i+1];
1989 cam->requested_frame[i] = NULL;
1990
1991 spin_unlock(&cam->flist_lock);
1992
1993 DBG(6,"Popped frame #%d from the list", (*framep)->number)
1994}
1995
1996
1997/*--------------------------------------------------------------------------
1998 High-level video post-processing routine on grabbed frames.
1999 Return 0 on success, a negative number otherwise.
2000 --------------------------------------------------------------------------*/
2001static int
2002w9968cf_postprocess_frame(struct w9968cf_device* cam,
2003 struct w9968cf_frame_t* fr)
2004{
2005 void *pIn = fr->buffer, *pOut = cam->frame_vpp.buffer, *tmp;
2006 u16 w = cam->window.width,
2007 h = cam->window.height,
2008 d = cam->picture.depth,
2009 fmt = cam->picture.palette,
2010 rgb = cam->force_rgb,
2011 hw_w = cam->hw_width,
2012 hw_h = cam->hw_height,
2013 hw_d = cam->hw_depth;
2014 int err = 0;
2015
2016 #define _PSWAP(pIn, pOut) {tmp = (pIn); (pIn) = (pOut); (pOut) = tmp;}
2017
2018 if (cam->vpp_flag & VPP_DECOMPRESSION) {
2019 memcpy(pOut, pIn, fr->length);
2020 _PSWAP(pIn, pOut)
2021 err = w9968cf_vpp->decode(pIn, fr->length, hw_w, hw_h, pOut);
2022 PDBGG("Compressed frame length: %lu",(unsigned long)fr->length)
2023 fr->length = (hw_w*hw_h*hw_d)/8;
2024 _PSWAP(pIn, pOut)
2025 if (err) {
2026 DBG(4, "An error occurred while decoding the frame: "
2027 "%s", symbolic(decoder_errlist, err))
2028 return err;
2029 } else
2030 DBG(6, "Frame decoded")
2031 }
2032
2033 if (cam->vpp_flag & VPP_SWAP_YUV_BYTES) {
2034 w9968cf_vpp->swap_yuvbytes(pIn, fr->length);
2035 DBG(6, "Original UYVY component ordering changed")
2036 }
2037
2038 if (cam->vpp_flag & VPP_UPSCALE) {
2039 w9968cf_vpp->scale_up(pIn, pOut, hw_w, hw_h, hw_d, w, h);
2040 fr->length = (w*h*hw_d)/8;
2041 _PSWAP(pIn, pOut)
2042 DBG(6, "Vertical up-scaling done: %u,%u,%ubpp->%u,%u",
2043 hw_w, hw_h, hw_d, w, h)
2044 }
2045
2046 if (cam->vpp_flag & VPP_UYVY_TO_RGBX) {
2047 w9968cf_vpp->uyvy_to_rgbx(pIn, fr->length, pOut, fmt, rgb);
2048 fr->length = (w*h*d)/8;
2049 _PSWAP(pIn, pOut)
2050 DBG(6, "UYVY-16bit to %s conversion done",
2051 symbolic(v4l1_plist, fmt))
2052 }
2053
2054 if (pOut == fr->buffer)
2055 memcpy(fr->buffer, cam->frame_vpp.buffer, fr->length);
2056
2057 return 0;
2058}
2059
2060
2061
2062/****************************************************************************
2063 * Image sensor control routines *
2064 ****************************************************************************/
2065
2066static int
2067w9968cf_sensor_set_control(struct w9968cf_device* cam, int cid, int val)
2068{
2069 struct ovcamchip_control ctl;
2070 int err;
2071
2072 ctl.id = cid;
2073 ctl.value = val;
2074
2075 err = w9968cf_sensor_cmd(cam, OVCAMCHIP_CMD_S_CTRL, &ctl);
2076
2077 return err;
2078}
2079
2080
2081static int
2082w9968cf_sensor_get_control(struct w9968cf_device* cam, int cid, int* val)
2083{
2084 struct ovcamchip_control ctl;
2085 int err;
2086
2087 ctl.id = cid;
2088
2089 err = w9968cf_sensor_cmd(cam, OVCAMCHIP_CMD_G_CTRL, &ctl);
2090 if (!err)
2091 *val = ctl.value;
2092
2093 return err;
2094}
2095
2096
2097static int
2098w9968cf_sensor_cmd(struct w9968cf_device* cam, unsigned int cmd, void* arg)
2099{
2100 int rc;
2101
2102 rc = v4l2_subdev_call(cam->sensor_sd, core, ioctl, cmd, arg);
2103 /* The I2C driver returns -EPERM on non-supported controls */
2104 return (rc < 0 && rc != -EPERM) ? rc : 0;
2105}
2106
2107
2108/*--------------------------------------------------------------------------
2109 Update some settings of the image sensor.
2110 Returns: 0 on success, a negative number otherwise.
2111 --------------------------------------------------------------------------*/
2112static int w9968cf_sensor_update_settings(struct w9968cf_device* cam)
2113{
2114 int err = 0;
2115
2116 /* Auto brightness */
2117 err = w9968cf_sensor_set_control(cam, OVCAMCHIP_CID_AUTOBRIGHT,
2118 cam->auto_brt);
2119 if (err)
2120 return err;
2121
2122 /* Auto exposure */
2123 err = w9968cf_sensor_set_control(cam, OVCAMCHIP_CID_AUTOEXP,
2124 cam->auto_exp);
2125 if (err)
2126 return err;
2127
2128 /* Banding filter */
2129 err = w9968cf_sensor_set_control(cam, OVCAMCHIP_CID_BANDFILT,
2130 cam->bandfilt);
2131 if (err)
2132 return err;
2133
2134 /* Light frequency */
2135 err = w9968cf_sensor_set_control(cam, OVCAMCHIP_CID_FREQ,
2136 cam->lightfreq);
2137 if (err)
2138 return err;
2139
2140 /* Back light */
2141 err = w9968cf_sensor_set_control(cam, OVCAMCHIP_CID_BACKLIGHT,
2142 cam->backlight);
2143 if (err)
2144 return err;
2145
2146 /* Mirror */
2147 err = w9968cf_sensor_set_control(cam, OVCAMCHIP_CID_MIRROR,
2148 cam->mirror);
2149 if (err)
2150 return err;
2151
2152 return 0;
2153}
2154
2155
2156/*--------------------------------------------------------------------------
2157 Get some current picture settings from the image sensor and update the
2158 internal 'picture' structure of the camera.
2159 Returns: 0 on success, a negative number otherwise.
2160 --------------------------------------------------------------------------*/
2161static int w9968cf_sensor_get_picture(struct w9968cf_device* cam)
2162{
2163 int err, v;
2164
2165 err = w9968cf_sensor_get_control(cam, OVCAMCHIP_CID_CONT, &v);
2166 if (err)
2167 return err;
2168 cam->picture.contrast = v;
2169
2170 err = w9968cf_sensor_get_control(cam, OVCAMCHIP_CID_BRIGHT, &v);
2171 if (err)
2172 return err;
2173 cam->picture.brightness = v;
2174
2175 err = w9968cf_sensor_get_control(cam, OVCAMCHIP_CID_SAT, &v);
2176 if (err)
2177 return err;
2178 cam->picture.colour = v;
2179
2180 err = w9968cf_sensor_get_control(cam, OVCAMCHIP_CID_HUE, &v);
2181 if (err)
2182 return err;
2183 cam->picture.hue = v;
2184
2185 DBG(5, "Got picture settings from the image sensor")
2186
2187 PDBGG("Brightness, contrast, hue, colour, whiteness are "
2188 "%u,%u,%u,%u,%u", cam->picture.brightness,cam->picture.contrast,
2189 cam->picture.hue, cam->picture.colour, cam->picture.whiteness)
2190
2191 return 0;
2192}
2193
2194
2195/*--------------------------------------------------------------------------
2196 Update picture settings of the image sensor.
2197 Returns: 0 on success, a negative number otherwise.
2198 --------------------------------------------------------------------------*/
2199static int
2200w9968cf_sensor_update_picture(struct w9968cf_device* cam,
2201 struct video_picture pict)
2202{
2203 int err = 0;
2204
2205 if ((!cam->sensor_initialized)
2206 || pict.contrast != cam->picture.contrast) {
2207 err = w9968cf_sensor_set_control(cam, OVCAMCHIP_CID_CONT,
2208 pict.contrast);
2209 if (err)
2210 goto fail;
2211 DBG(4, "Contrast changed from %u to %u",
2212 cam->picture.contrast, pict.contrast)
2213 cam->picture.contrast = pict.contrast;
2214 }
2215
2216 if (((!cam->sensor_initialized) ||
2217 pict.brightness != cam->picture.brightness) && (!cam->auto_brt)) {
2218 err = w9968cf_sensor_set_control(cam, OVCAMCHIP_CID_BRIGHT,
2219 pict.brightness);
2220 if (err)
2221 goto fail;
2222 DBG(4, "Brightness changed from %u to %u",
2223 cam->picture.brightness, pict.brightness)
2224 cam->picture.brightness = pict.brightness;
2225 }
2226
2227 if ((!cam->sensor_initialized) || pict.colour != cam->picture.colour) {
2228 err = w9968cf_sensor_set_control(cam, OVCAMCHIP_CID_SAT,
2229 pict.colour);
2230 if (err)
2231 goto fail;
2232 DBG(4, "Colour changed from %u to %u",
2233 cam->picture.colour, pict.colour)
2234 cam->picture.colour = pict.colour;
2235 }
2236
2237 if ((!cam->sensor_initialized) || pict.hue != cam->picture.hue) {
2238 err = w9968cf_sensor_set_control(cam, OVCAMCHIP_CID_HUE,
2239 pict.hue);
2240 if (err)
2241 goto fail;
2242 DBG(4, "Hue changed from %u to %u",
2243 cam->picture.hue, pict.hue)
2244 cam->picture.hue = pict.hue;
2245 }
2246
2247 return 0;
2248
2249fail:
2250 DBG(4, "Failed to change sensor picture setting")
2251 return err;
2252}
2253
2254
2255
2256/****************************************************************************
2257 * Camera configuration *
2258 ****************************************************************************/
2259
2260/*--------------------------------------------------------------------------
2261 This function is called when a supported image sensor is detected.
2262 Return 0 if the initialization succeeds, a negative number otherwise.
2263 --------------------------------------------------------------------------*/
2264static int w9968cf_sensor_init(struct w9968cf_device* cam)
2265{
2266 int err = 0;
2267
2268 if ((err = w9968cf_sensor_cmd(cam, OVCAMCHIP_CMD_INITIALIZE,
2269 &cam->monochrome)))
2270 goto error;
2271
2272 if ((err = w9968cf_sensor_cmd(cam, OVCAMCHIP_CMD_Q_SUBTYPE,
2273 &cam->sensor)))
2274 goto error;
2275
2276 /* NOTE: Make sure width and height are a multiple of 16 */
2277 switch (v4l2_i2c_subdev_addr(cam->sensor_sd)) {
2278 case OV6xx0_SID:
2279 cam->maxwidth = 352;
2280 cam->maxheight = 288;
2281 cam->minwidth = 64;
2282 cam->minheight = 48;
2283 break;
2284 case OV7xx0_SID:
2285 cam->maxwidth = 640;
2286 cam->maxheight = 480;
2287 cam->minwidth = 64;
2288 cam->minheight = 48;
2289 break;
2290 default:
2291 DBG(1, "Not supported image sensor detected for %s",
2292 symbolic(camlist, cam->id))
2293 return -EINVAL;
2294 }
2295
2296 /* These values depend on the ones in the ovxxx0.c sources */
2297 switch (cam->sensor) {
2298 case CC_OV7620:
2299 cam->start_cropx = 287;
2300 cam->start_cropy = 35;
2301 /* Seems to work around a bug in the image sensor */
2302 cam->vs_polarity = 1;
2303 cam->hs_polarity = 1;
2304 break;
2305 default:
2306 cam->start_cropx = 320;
2307 cam->start_cropy = 35;
2308 cam->vs_polarity = 1;
2309 cam->hs_polarity = 0;
2310 }
2311
2312 if ((err = w9968cf_sensor_update_settings(cam)))
2313 goto error;
2314
2315 if ((err = w9968cf_sensor_update_picture(cam, cam->picture)))
2316 goto error;
2317
2318 cam->sensor_initialized = 1;
2319
2320 DBG(2, "%s image sensor initialized", symbolic(senlist, cam->sensor))
2321 return 0;
2322
2323error:
2324 cam->sensor_initialized = 0;
2325 cam->sensor = CC_UNKNOWN;
2326 DBG(1, "Image sensor initialization failed for %s (%s). "
2327 "Try to detach and attach this device again",
2328 symbolic(camlist, cam->id), video_device_node_name(cam->v4ldev))
2329 return err;
2330}
2331
2332
2333/*--------------------------------------------------------------------------
2334 Fill some basic fields in the main device data structure.
2335 This function is called once on w9968cf_usb_probe() for each recognized
2336 camera.
2337 --------------------------------------------------------------------------*/
2338static void
2339w9968cf_configure_camera(struct w9968cf_device* cam,
2340 struct usb_device* udev,
2341 enum w9968cf_model_id mod_id,
2342 const unsigned short dev_nr)
2343{
2344 mutex_init(&cam->fileop_mutex);
2345 init_waitqueue_head(&cam->open);
2346 spin_lock_init(&cam->urb_lock);
2347 spin_lock_init(&cam->flist_lock);
2348
2349 cam->users = 0;
2350 cam->disconnected = 0;
2351 cam->id = mod_id;
2352 cam->sensor = CC_UNKNOWN;
2353 cam->sensor_initialized = 0;
2354
2355 /* Calculate the alternate setting number (from 1 to 16)
2356 according to the 'packet_size' module parameter */
2357 if (packet_size[dev_nr] < W9968CF_MIN_PACKET_SIZE)
2358 packet_size[dev_nr] = W9968CF_MIN_PACKET_SIZE;
2359 for (cam->altsetting = 1;
2360 packet_size[dev_nr] < wMaxPacketSize[cam->altsetting-1];
2361 cam->altsetting++);
2362
2363 cam->max_buffers = (max_buffers[dev_nr] < 2 ||
2364 max_buffers[dev_nr] > W9968CF_MAX_BUFFERS)
2365 ? W9968CF_BUFFERS : (u8)max_buffers[dev_nr];
2366
2367 cam->double_buffer = (double_buffer[dev_nr] == 0 ||
2368 double_buffer[dev_nr] == 1)
2369 ? (u8)double_buffer[dev_nr]:W9968CF_DOUBLE_BUFFER;
2370
2371 cam->clamping = (clamping[dev_nr] == 0 || clamping[dev_nr] == 1)
2372 ? (u8)clamping[dev_nr] : W9968CF_CLAMPING;
2373
2374 cam->filter_type = (filter_type[dev_nr] == 0 ||
2375 filter_type[dev_nr] == 1 ||
2376 filter_type[dev_nr] == 2)
2377 ? (u8)filter_type[dev_nr] : W9968CF_FILTER_TYPE;
2378
2379 cam->capture = 1;
2380
2381 cam->largeview = (largeview[dev_nr] == 0 || largeview[dev_nr] == 1)
2382 ? (u8)largeview[dev_nr] : W9968CF_LARGEVIEW;
2383
2384 cam->decompression = (decompression[dev_nr] == 0 ||
2385 decompression[dev_nr] == 1 ||
2386 decompression[dev_nr] == 2)
2387 ? (u8)decompression[dev_nr]:W9968CF_DECOMPRESSION;
2388
2389 cam->upscaling = (upscaling[dev_nr] == 0 ||
2390 upscaling[dev_nr] == 1)
2391 ? (u8)upscaling[dev_nr] : W9968CF_UPSCALING;
2392
2393 cam->auto_brt = (autobright[dev_nr] == 0 || autobright[dev_nr] == 1)
2394 ? (u8)autobright[dev_nr] : W9968CF_AUTOBRIGHT;
2395
2396 cam->auto_exp = (autoexp[dev_nr] == 0 || autoexp[dev_nr] == 1)
2397 ? (u8)autoexp[dev_nr] : W9968CF_AUTOEXP;
2398
2399 cam->lightfreq = (lightfreq[dev_nr] == 50 || lightfreq[dev_nr] == 60)
2400 ? (u8)lightfreq[dev_nr] : W9968CF_LIGHTFREQ;
2401
2402 cam->bandfilt = (bandingfilter[dev_nr] == 0 ||
2403 bandingfilter[dev_nr] == 1)
2404 ? (u8)bandingfilter[dev_nr] : W9968CF_BANDINGFILTER;
2405
2406 cam->backlight = (backlight[dev_nr] == 0 || backlight[dev_nr] == 1)
2407 ? (u8)backlight[dev_nr] : W9968CF_BACKLIGHT;
2408
2409 cam->clockdiv = (clockdiv[dev_nr] == -1 || clockdiv[dev_nr] >= 0)
2410 ? (s8)clockdiv[dev_nr] : W9968CF_CLOCKDIV;
2411
2412 cam->mirror = (mirror[dev_nr] == 0 || mirror[dev_nr] == 1)
2413 ? (u8)mirror[dev_nr] : W9968CF_MIRROR;
2414
2415 cam->monochrome = (monochrome[dev_nr] == 0 || monochrome[dev_nr] == 1)
2416 ? monochrome[dev_nr] : W9968CF_MONOCHROME;
2417
2418 cam->picture.brightness = (u16)brightness[dev_nr];
2419 cam->picture.hue = (u16)hue[dev_nr];
2420 cam->picture.colour = (u16)colour[dev_nr];
2421 cam->picture.contrast = (u16)contrast[dev_nr];
2422 cam->picture.whiteness = (u16)whiteness[dev_nr];
2423 if (w9968cf_valid_palette((u16)force_palette[dev_nr])) {
2424 cam->picture.palette = (u16)force_palette[dev_nr];
2425 cam->force_palette = 1;
2426 } else {
2427 cam->force_palette = 0;
2428 if (cam->decompression == 0)
2429 cam->picture.palette = W9968CF_PALETTE_DECOMP_OFF;
2430 else if (cam->decompression == 1)
2431 cam->picture.palette = W9968CF_PALETTE_DECOMP_FORCE;
2432 else
2433 cam->picture.palette = W9968CF_PALETTE_DECOMP_ON;
2434 }
2435 cam->picture.depth = w9968cf_valid_depth(cam->picture.palette);
2436
2437 cam->force_rgb = (force_rgb[dev_nr] == 0 || force_rgb[dev_nr] == 1)
2438 ? (u8)force_rgb[dev_nr] : W9968CF_FORCE_RGB;
2439
2440 cam->window.x = 0;
2441 cam->window.y = 0;
2442 cam->window.width = W9968CF_WIDTH;
2443 cam->window.height = W9968CF_HEIGHT;
2444 cam->window.chromakey = 0;
2445 cam->window.clipcount = 0;
2446 cam->window.flags = 0;
2447
2448 DBG(3, "%s configured with settings #%u:",
2449 symbolic(camlist, cam->id), dev_nr)
2450
2451 DBG(3, "- Data packet size for USB isochrnous transfer: %u bytes",
2452 wMaxPacketSize[cam->altsetting-1])
2453
2454 DBG(3, "- Number of requested video frame buffers: %u",
2455 cam->max_buffers)
2456
2457 if (cam->double_buffer)
2458 DBG(3, "- Hardware double buffering enabled")
2459 else
2460 DBG(3, "- Hardware double buffering disabled")
2461
2462 if (cam->filter_type == 0)
2463 DBG(3, "- Video filtering disabled")
2464 else if (cam->filter_type == 1)
2465 DBG(3, "- Video filtering enabled: type 1-2-1")
2466 else if (cam->filter_type == 2)
2467 DBG(3, "- Video filtering enabled: type 2-3-6-3-2")
2468
2469 if (cam->clamping)
2470 DBG(3, "- Video data clamping (CCIR-601 format) enabled")
2471 else
2472 DBG(3, "- Video data clamping (CCIR-601 format) disabled")
2473
2474 if (cam->largeview)
2475 DBG(3, "- Large view enabled")
2476 else
2477 DBG(3, "- Large view disabled")
2478
2479 if ((cam->decompression) == 0 && (!cam->force_palette))
2480 DBG(3, "- Decompression disabled")
2481 else if ((cam->decompression) == 1 && (!cam->force_palette))
2482 DBG(3, "- Decompression forced")
2483 else if ((cam->decompression) == 2 && (!cam->force_palette))
2484 DBG(3, "- Decompression allowed")
2485
2486 if (cam->upscaling)
2487 DBG(3, "- Software image scaling enabled")
2488 else
2489 DBG(3, "- Software image scaling disabled")
2490
2491 if (cam->force_palette)
2492 DBG(3, "- Image palette forced to %s",
2493 symbolic(v4l1_plist, cam->picture.palette))
2494
2495 if (cam->force_rgb)
2496 DBG(3, "- RGB component ordering will be used instead of BGR")
2497
2498 if (cam->auto_brt)
2499 DBG(3, "- Auto brightness enabled")
2500 else
2501 DBG(3, "- Auto brightness disabled")
2502
2503 if (cam->auto_exp)
2504 DBG(3, "- Auto exposure enabled")
2505 else
2506 DBG(3, "- Auto exposure disabled")
2507
2508 if (cam->backlight)
2509 DBG(3, "- Backlight exposure algorithm enabled")
2510 else
2511 DBG(3, "- Backlight exposure algorithm disabled")
2512
2513 if (cam->mirror)
2514 DBG(3, "- Mirror enabled")
2515 else
2516 DBG(3, "- Mirror disabled")
2517
2518 if (cam->bandfilt)
2519 DBG(3, "- Banding filter enabled")
2520 else
2521 DBG(3, "- Banding filter disabled")
2522
2523 DBG(3, "- Power lighting frequency: %u", cam->lightfreq)
2524
2525 if (cam->clockdiv == -1)
2526 DBG(3, "- Automatic clock divisor enabled")
2527 else
2528 DBG(3, "- Clock divisor: %d", cam->clockdiv)
2529
2530 if (cam->monochrome)
2531 DBG(3, "- Image sensor used as monochrome")
2532 else
2533 DBG(3, "- Image sensor not used as monochrome")
2534}
2535
2536
2537/*--------------------------------------------------------------------------
2538 If the video post-processing module is not loaded, some parameters
2539 must be overridden.
2540 --------------------------------------------------------------------------*/
2541static void w9968cf_adjust_configuration(struct w9968cf_device* cam)
2542{
2543 if (!w9968cf_vpp) {
2544 if (cam->decompression == 1) {
2545 cam->decompression = 2;
2546 DBG(2, "Video post-processing module not found: "
2547 "'decompression' parameter forced to 2")
2548 }
2549 if (cam->upscaling) {
2550 cam->upscaling = 0;
2551 DBG(2, "Video post-processing module not found: "
2552 "'upscaling' parameter forced to 0")
2553 }
2554 if (cam->picture.palette != VIDEO_PALETTE_UYVY) {
2555 cam->force_palette = 0;
2556 DBG(2, "Video post-processing module not found: "
2557 "'force_palette' parameter forced to 0")
2558 }
2559 cam->picture.palette = VIDEO_PALETTE_UYVY;
2560 cam->picture.depth = w9968cf_valid_depth(cam->picture.palette);
2561 }
2562}
2563
2564
2565/*--------------------------------------------------------------------------
2566 Release the resources used by the driver.
2567 This function is called on disconnect
2568 (or on close if deallocation has been deferred)
2569 --------------------------------------------------------------------------*/
2570static void w9968cf_release_resources(struct w9968cf_device* cam)
2571{
2572 mutex_lock(&w9968cf_devlist_mutex);
2573
2574 DBG(2, "V4L device deregistered: %s",
2575 video_device_node_name(cam->v4ldev))
2576
2577 video_unregister_device(cam->v4ldev);
2578 list_del(&cam->v4llist);
2579 i2c_del_adapter(&cam->i2c_adapter);
2580 w9968cf_deallocate_memory(cam);
2581 kfree(cam->control_buffer);
2582 kfree(cam->data_buffer);
2583 v4l2_device_unregister(&cam->v4l2_dev);
2584
2585 mutex_unlock(&w9968cf_devlist_mutex);
2586}
2587
2588
2589
2590/****************************************************************************
2591 * Video4Linux interface *
2592 ****************************************************************************/
2593
2594static int w9968cf_open(struct file *filp)
2595{
2596 struct w9968cf_device* cam;
2597 int err;
2598
2599 /* This the only safe way to prevent race conditions with disconnect */
2600 if (!down_read_trylock(&w9968cf_disconnect))
2601 return -EAGAIN;
2602
2603 cam = (struct w9968cf_device*)video_get_drvdata(video_devdata(filp));
2604
2605 mutex_lock(&cam->dev_mutex);
2606
2607 if (cam->sensor == CC_UNKNOWN) {
2608 DBG(2, "No supported image sensor has been detected by the "
2609 "'ovcamchip' module for the %s (%s). Make sure "
2610 "it is loaded *before* (re)connecting the camera.",
2611 symbolic(camlist, cam->id),
2612 video_device_node_name(cam->v4ldev))
2613 mutex_unlock(&cam->dev_mutex);
2614 up_read(&w9968cf_disconnect);
2615 return -ENODEV;
2616 }
2617
2618 if (cam->users) {
2619 DBG(2, "%s (%s) has been already occupied by '%s'",
2620 symbolic(camlist, cam->id),
2621 video_device_node_name(cam->v4ldev), cam->command)
2622 if ((filp->f_flags & O_NONBLOCK)||(filp->f_flags & O_NDELAY)) {
2623 mutex_unlock(&cam->dev_mutex);
2624 up_read(&w9968cf_disconnect);
2625 return -EWOULDBLOCK;
2626 }
2627 mutex_unlock(&cam->dev_mutex);
2628 err = wait_event_interruptible_exclusive(cam->open,
2629 cam->disconnected ||
2630 !cam->users);
2631 if (err) {
2632 up_read(&w9968cf_disconnect);
2633 return err;
2634 }
2635 if (cam->disconnected) {
2636 up_read(&w9968cf_disconnect);
2637 return -ENODEV;
2638 }
2639 mutex_lock(&cam->dev_mutex);
2640 }
2641
2642 DBG(5, "Opening '%s', %s ...",
2643 symbolic(camlist, cam->id), video_device_node_name(cam->v4ldev))
2644
2645 cam->streaming = 0;
2646 cam->misconfigured = 0;
2647
2648 w9968cf_adjust_configuration(cam);
2649
2650 if ((err = w9968cf_allocate_memory(cam)))
2651 goto deallocate_memory;
2652
2653 if ((err = w9968cf_init_chip(cam)))
2654 goto deallocate_memory;
2655
2656 if ((err = w9968cf_start_transfer(cam)))
2657 goto deallocate_memory;
2658
2659 filp->private_data = cam;
2660
2661 cam->users++;
2662 strcpy(cam->command, current->comm);
2663
2664 init_waitqueue_head(&cam->wait_queue);
2665
2666 DBG(5, "Video device is open")
2667
2668 mutex_unlock(&cam->dev_mutex);
2669 up_read(&w9968cf_disconnect);
2670
2671 return 0;
2672
2673deallocate_memory:
2674 w9968cf_deallocate_memory(cam);
2675 DBG(2, "Failed to open the video device")
2676 mutex_unlock(&cam->dev_mutex);
2677 up_read(&w9968cf_disconnect);
2678 return err;
2679}
2680
2681
2682static int w9968cf_release(struct file *filp)
2683{
2684 struct w9968cf_device* cam;
2685
2686 cam = (struct w9968cf_device*)video_get_drvdata(video_devdata(filp));
2687
2688 mutex_lock(&cam->dev_mutex); /* prevent disconnect() to be called */
2689
2690 w9968cf_stop_transfer(cam);
2691
2692 if (cam->disconnected) {
2693 w9968cf_release_resources(cam);
2694 mutex_unlock(&cam->dev_mutex);
2695 kfree(cam);
2696 return 0;
2697 }
2698
2699 cam->users--;
2700 w9968cf_deallocate_memory(cam);
2701 wake_up_interruptible_nr(&cam->open, 1);
2702
2703 DBG(5, "Video device closed")
2704 mutex_unlock(&cam->dev_mutex);
2705 return 0;
2706}
2707
2708
2709static ssize_t
2710w9968cf_read(struct file* filp, char __user * buf, size_t count, loff_t* f_pos)
2711{
2712 struct w9968cf_device* cam;
2713 struct w9968cf_frame_t* fr;
2714 int err = 0;
2715
2716 cam = (struct w9968cf_device*)video_get_drvdata(video_devdata(filp));
2717
2718 if (filp->f_flags & O_NONBLOCK)
2719 return -EWOULDBLOCK;
2720
2721 if (mutex_lock_interruptible(&cam->fileop_mutex))
2722 return -ERESTARTSYS;
2723
2724 if (cam->disconnected) {
2725 DBG(2, "Device not present")
2726 mutex_unlock(&cam->fileop_mutex);
2727 return -ENODEV;
2728 }
2729
2730 if (cam->misconfigured) {
2731 DBG(2, "The camera is misconfigured. Close and open it again.")
2732 mutex_unlock(&cam->fileop_mutex);
2733 return -EIO;
2734 }
2735
2736 if (!cam->frame[0].queued)
2737 w9968cf_push_frame(cam, 0);
2738
2739 if (!cam->frame[1].queued)
2740 w9968cf_push_frame(cam, 1);
2741
2742 err = wait_event_interruptible(cam->wait_queue,
2743 cam->frame[0].status == F_READY ||
2744 cam->frame[1].status == F_READY ||
2745 cam->disconnected);
2746 if (err) {
2747 mutex_unlock(&cam->fileop_mutex);
2748 return err;
2749 }
2750 if (cam->disconnected) {
2751 mutex_unlock(&cam->fileop_mutex);
2752 return -ENODEV;
2753 }
2754
2755 fr = (cam->frame[0].status == F_READY) ? &cam->frame[0]:&cam->frame[1];
2756
2757 if (w9968cf_vpp)
2758 w9968cf_postprocess_frame(cam, fr);
2759
2760 if (count > fr->length)
2761 count = fr->length;
2762
2763 if (copy_to_user(buf, fr->buffer, count)) {
2764 fr->status = F_UNUSED;
2765 mutex_unlock(&cam->fileop_mutex);
2766 return -EFAULT;
2767 }
2768 *f_pos += count;
2769
2770 fr->status = F_UNUSED;
2771
2772 DBG(5, "%zu bytes read", count)
2773
2774 mutex_unlock(&cam->fileop_mutex);
2775 return count;
2776}
2777
2778
2779static int w9968cf_mmap(struct file* filp, struct vm_area_struct *vma)
2780{
2781 struct w9968cf_device* cam = (struct w9968cf_device*)
2782 video_get_drvdata(video_devdata(filp));
2783 unsigned long vsize = vma->vm_end - vma->vm_start,
2784 psize = cam->nbuffers * cam->frame[0].size,
2785 start = vma->vm_start,
2786 pos = (unsigned long)cam->frame[0].buffer,
2787 page;
2788
2789 if (cam->disconnected) {
2790 DBG(2, "Device not present")
2791 return -ENODEV;
2792 }
2793
2794 if (cam->misconfigured) {
2795 DBG(2, "The camera is misconfigured. Close and open it again")
2796 return -EIO;
2797 }
2798
2799 PDBGG("mmapping %lu bytes...", vsize)
2800
2801 if (vsize > psize - (vma->vm_pgoff << PAGE_SHIFT))
2802 return -EINVAL;
2803
2804 while (vsize > 0) {
2805 page = vmalloc_to_pfn((void *)pos);
2806 if (remap_pfn_range(vma, start, page + vma->vm_pgoff,
2807 PAGE_SIZE, vma->vm_page_prot))
2808 return -EAGAIN;
2809 start += PAGE_SIZE;
2810 pos += PAGE_SIZE;
2811 vsize -= PAGE_SIZE;
2812 }
2813
2814 DBG(5, "mmap method successfully called")
2815 return 0;
2816}
2817
2818
2819static long
2820w9968cf_ioctl(struct file *filp,
2821 unsigned int cmd, unsigned long arg)
2822{
2823 struct w9968cf_device* cam;
2824 long err;
2825
2826 cam = (struct w9968cf_device*)video_get_drvdata(video_devdata(filp));
2827
2828 if (mutex_lock_interruptible(&cam->fileop_mutex))
2829 return -ERESTARTSYS;
2830
2831 if (cam->disconnected) {
2832 DBG(2, "Device not present")
2833 mutex_unlock(&cam->fileop_mutex);
2834 return -ENODEV;
2835 }
2836
2837 if (cam->misconfigured) {
2838 DBG(2, "The camera is misconfigured. Close and open it again.")
2839 mutex_unlock(&cam->fileop_mutex);
2840 return -EIO;
2841 }
2842
2843 err = w9968cf_v4l_ioctl(filp, cmd, (void __user *)arg);
2844
2845 mutex_unlock(&cam->fileop_mutex);
2846 return err;
2847}
2848
2849
2850static long w9968cf_v4l_ioctl(struct file *filp,
2851 unsigned int cmd, void __user *arg)
2852{
2853 struct w9968cf_device* cam;
2854 const char* v4l1_ioctls[] = {
2855 "?", "CGAP", "GCHAN", "SCHAN", "GTUNER", "STUNER",
2856 "GPICT", "SPICT", "CCAPTURE", "GWIN", "SWIN", "GFBUF",
2857 "SFBUF", "KEY", "GFREQ", "SFREQ", "GAUDIO", "SAUDIO",
2858 "SYNC", "MCAPTURE", "GMBUF", "GUNIT", "GCAPTURE", "SCAPTURE",
2859 "SPLAYMODE", "SWRITEMODE", "GPLAYINFO", "SMICROCODE",
2860 "GVBIFMT", "SVBIFMT"
2861 };
2862
2863 #define V4L1_IOCTL(cmd) \
2864 ((_IOC_NR((cmd)) < ARRAY_SIZE(v4l1_ioctls)) ? \
2865 v4l1_ioctls[_IOC_NR((cmd))] : "?")
2866
2867 cam = (struct w9968cf_device*)video_get_drvdata(video_devdata(filp));
2868
2869 switch (cmd) {
2870
2871 case VIDIOCGCAP: /* get video capability */
2872 {
2873 struct video_capability cap = {
2874 .type = VID_TYPE_CAPTURE | VID_TYPE_SCALES,
2875 .channels = 1,
2876 .audios = 0,
2877 .minwidth = cam->minwidth,
2878 .minheight = cam->minheight,
2879 };
2880 sprintf(cap.name, "W996[87]CF USB Camera");
2881 cap.maxwidth = (cam->upscaling && w9968cf_vpp)
2882 ? max((u16)W9968CF_MAX_WIDTH, cam->maxwidth)
2883 : cam->maxwidth;
2884 cap.maxheight = (cam->upscaling && w9968cf_vpp)
2885 ? max((u16)W9968CF_MAX_HEIGHT, cam->maxheight)
2886 : cam->maxheight;
2887
2888 if (copy_to_user(arg, &cap, sizeof(cap)))
2889 return -EFAULT;
2890
2891 DBG(5, "VIDIOCGCAP successfully called")
2892 return 0;
2893 }
2894
2895 case VIDIOCGCHAN: /* get video channel informations */
2896 {
2897 struct video_channel chan;
2898 if (copy_from_user(&chan, arg, sizeof(chan)))
2899 return -EFAULT;
2900
2901 if (chan.channel != 0)
2902 return -EINVAL;
2903
2904 strcpy(chan.name, "Camera");
2905 chan.tuners = 0;
2906 chan.flags = 0;
2907 chan.type = VIDEO_TYPE_CAMERA;
2908 chan.norm = VIDEO_MODE_AUTO;
2909
2910 if (copy_to_user(arg, &chan, sizeof(chan)))
2911 return -EFAULT;
2912
2913 DBG(5, "VIDIOCGCHAN successfully called")
2914 return 0;
2915 }
2916
2917 case VIDIOCSCHAN: /* set active channel */
2918 {
2919 struct video_channel chan;
2920
2921 if (copy_from_user(&chan, arg, sizeof(chan)))
2922 return -EFAULT;
2923
2924 if (chan.channel != 0)
2925 return -EINVAL;
2926
2927 DBG(5, "VIDIOCSCHAN successfully called")
2928 return 0;
2929 }
2930
2931 case VIDIOCGPICT: /* get image properties of the picture */
2932 {
2933 if (w9968cf_sensor_get_picture(cam))
2934 return -EIO;
2935
2936 if (copy_to_user(arg, &cam->picture, sizeof(cam->picture)))
2937 return -EFAULT;
2938
2939 DBG(5, "VIDIOCGPICT successfully called")
2940 return 0;
2941 }
2942
2943 case VIDIOCSPICT: /* change picture settings */
2944 {
2945 struct video_picture pict;
2946 int err = 0;
2947
2948 if (copy_from_user(&pict, arg, sizeof(pict)))
2949 return -EFAULT;
2950
2951 if ( (cam->force_palette || !w9968cf_vpp)
2952 && pict.palette != cam->picture.palette ) {
2953 DBG(4, "Palette %s rejected: only %s is allowed",
2954 symbolic(v4l1_plist, pict.palette),
2955 symbolic(v4l1_plist, cam->picture.palette))
2956 return -EINVAL;
2957 }
2958
2959 if (!w9968cf_valid_palette(pict.palette)) {
2960 DBG(4, "Palette %s not supported. VIDIOCSPICT failed",
2961 symbolic(v4l1_plist, pict.palette))
2962 return -EINVAL;
2963 }
2964
2965 if (!cam->force_palette) {
2966 if (cam->decompression == 0) {
2967 if (w9968cf_need_decompression(pict.palette)) {
2968 DBG(4, "Decompression disabled: palette %s is not "
2969 "allowed. VIDIOCSPICT failed",
2970 symbolic(v4l1_plist, pict.palette))
2971 return -EINVAL;
2972 }
2973 } else if (cam->decompression == 1) {
2974 if (!w9968cf_need_decompression(pict.palette)) {
2975 DBG(4, "Decompression forced: palette %s is not "
2976 "allowed. VIDIOCSPICT failed",
2977 symbolic(v4l1_plist, pict.palette))
2978 return -EINVAL;
2979 }
2980 }
2981 }
2982
2983 if (pict.depth != w9968cf_valid_depth(pict.palette)) {
2984 DBG(4, "Requested depth %u bpp is not valid for %s "
2985 "palette: ignored and changed to %u bpp",
2986 pict.depth, symbolic(v4l1_plist, pict.palette),
2987 w9968cf_valid_depth(pict.palette))
2988 pict.depth = w9968cf_valid_depth(pict.palette);
2989 }
2990
2991 if (pict.palette != cam->picture.palette) {
2992 if(*cam->requested_frame
2993 || cam->frame_current->queued) {
2994 err = wait_event_interruptible
2995 ( cam->wait_queue,
2996 cam->disconnected ||
2997 (!*cam->requested_frame &&
2998 !cam->frame_current->queued) );
2999 if (err)
3000 return err;
3001 if (cam->disconnected)
3002 return -ENODEV;
3003 }
3004
3005 if (w9968cf_stop_transfer(cam))
3006 goto ioctl_fail;
3007
3008 if (w9968cf_set_picture(cam, pict))
3009 goto ioctl_fail;
3010
3011 if (w9968cf_start_transfer(cam))
3012 goto ioctl_fail;
3013
3014 } else if (w9968cf_sensor_update_picture(cam, pict))
3015 return -EIO;
3016
3017
3018 DBG(5, "VIDIOCSPICT successfully called")
3019 return 0;
3020 }
3021
3022 case VIDIOCSWIN: /* set capture area */
3023 {
3024 struct video_window win;
3025 int err = 0;
3026
3027 if (copy_from_user(&win, arg, sizeof(win)))
3028 return -EFAULT;
3029
3030 DBG(6, "VIDIOCSWIN called: clipcount=%d, flags=%u, "
3031 "x=%u, y=%u, %ux%u", win.clipcount, win.flags,
3032 win.x, win.y, win.width, win.height)
3033
3034 if (win.clipcount != 0 || win.flags != 0)
3035 return -EINVAL;
3036
3037 if ((err = w9968cf_adjust_window_size(cam, &win.width,
3038 &win.height))) {
3039 DBG(4, "Resolution not supported (%ux%u). "
3040 "VIDIOCSWIN failed", win.width, win.height)
3041 return err;
3042 }
3043
3044 if (win.x != cam->window.x ||
3045 win.y != cam->window.y ||
3046 win.width != cam->window.width ||
3047 win.height != cam->window.height) {
3048 if(*cam->requested_frame
3049 || cam->frame_current->queued) {
3050 err = wait_event_interruptible
3051 ( cam->wait_queue,
3052 cam->disconnected ||
3053 (!*cam->requested_frame &&
3054 !cam->frame_current->queued) );
3055 if (err)
3056 return err;
3057 if (cam->disconnected)
3058 return -ENODEV;
3059 }
3060
3061 if (w9968cf_stop_transfer(cam))
3062 goto ioctl_fail;
3063
3064 /* This _must_ be called before set_window() */
3065 if (w9968cf_set_picture(cam, cam->picture))
3066 goto ioctl_fail;
3067
3068 if (w9968cf_set_window(cam, win))
3069 goto ioctl_fail;
3070
3071 if (w9968cf_start_transfer(cam))
3072 goto ioctl_fail;
3073 }
3074
3075 DBG(5, "VIDIOCSWIN successfully called. ")
3076 return 0;
3077 }
3078
3079 case VIDIOCGWIN: /* get current window properties */
3080 {
3081 if (copy_to_user(arg,&cam->window,sizeof(struct video_window)))
3082 return -EFAULT;
3083
3084 DBG(5, "VIDIOCGWIN successfully called")
3085 return 0;
3086 }
3087
3088 case VIDIOCGMBUF: /* request for memory (mapped) buffer */
3089 {
3090 struct video_mbuf mbuf;
3091 u8 i;
3092
3093 mbuf.size = cam->nbuffers * cam->frame[0].size;
3094 mbuf.frames = cam->nbuffers;
3095 for (i = 0; i < cam->nbuffers; i++)
3096 mbuf.offsets[i] = (unsigned long)cam->frame[i].buffer -
3097 (unsigned long)cam->frame[0].buffer;
3098
3099 if (copy_to_user(arg, &mbuf, sizeof(mbuf)))
3100 return -EFAULT;
3101
3102 DBG(5, "VIDIOCGMBUF successfully called")
3103 return 0;
3104 }
3105
3106 case VIDIOCMCAPTURE: /* start the capture to a frame */
3107 {
3108 struct video_mmap mmap;
3109 struct w9968cf_frame_t* fr;
3110 u32 w, h;
3111 int err = 0;
3112
3113 if (copy_from_user(&mmap, arg, sizeof(mmap)))
3114 return -EFAULT;
3115
3116 DBG(6, "VIDIOCMCAPTURE called: frame #%u, format=%s, %dx%d",
3117 mmap.frame, symbolic(v4l1_plist, mmap.format),
3118 mmap.width, mmap.height)
3119
3120 if (mmap.frame >= cam->nbuffers) {
3121 DBG(4, "Invalid frame number (%u). "
3122 "VIDIOCMCAPTURE failed", mmap.frame)
3123 return -EINVAL;
3124 }
3125
3126 if (mmap.format!=cam->picture.palette &&
3127 (cam->force_palette || !w9968cf_vpp)) {
3128 DBG(4, "Palette %s rejected: only %s is allowed",
3129 symbolic(v4l1_plist, mmap.format),
3130 symbolic(v4l1_plist, cam->picture.palette))
3131 return -EINVAL;
3132 }
3133
3134 if (!w9968cf_valid_palette(mmap.format)) {
3135 DBG(4, "Palette %s not supported. "
3136 "VIDIOCMCAPTURE failed",
3137 symbolic(v4l1_plist, mmap.format))
3138 return -EINVAL;
3139 }
3140
3141 if (!cam->force_palette) {
3142 if (cam->decompression == 0) {
3143 if (w9968cf_need_decompression(mmap.format)) {
3144 DBG(4, "Decompression disabled: palette %s is not "
3145 "allowed. VIDIOCSPICT failed",
3146 symbolic(v4l1_plist, mmap.format))
3147 return -EINVAL;
3148 }
3149 } else if (cam->decompression == 1) {
3150 if (!w9968cf_need_decompression(mmap.format)) {
3151 DBG(4, "Decompression forced: palette %s is not "
3152 "allowed. VIDIOCSPICT failed",
3153 symbolic(v4l1_plist, mmap.format))
3154 return -EINVAL;
3155 }
3156 }
3157 }
3158
3159 w = mmap.width; h = mmap.height;
3160 err = w9968cf_adjust_window_size(cam, &w, &h);
3161 mmap.width = w; mmap.height = h;
3162 if (err) {
3163 DBG(4, "Resolution not supported (%dx%d). "
3164 "VIDIOCMCAPTURE failed",
3165 mmap.width, mmap.height)
3166 return err;
3167 }
3168
3169 fr = &cam->frame[mmap.frame];
3170
3171 if (mmap.width != cam->window.width ||
3172 mmap.height != cam->window.height ||
3173 mmap.format != cam->picture.palette) {
3174
3175 struct video_window win;
3176 struct video_picture pict;
3177
3178 if(*cam->requested_frame
3179 || cam->frame_current->queued) {
3180 DBG(6, "VIDIOCMCAPTURE. Change settings for "
3181 "frame #%u: %dx%d, format %s. Wait...",
3182 mmap.frame, mmap.width, mmap.height,
3183 symbolic(v4l1_plist, mmap.format))
3184 err = wait_event_interruptible
3185 ( cam->wait_queue,
3186 cam->disconnected ||
3187 (!*cam->requested_frame &&
3188 !cam->frame_current->queued) );
3189 if (err)
3190 return err;
3191 if (cam->disconnected)
3192 return -ENODEV;
3193 }
3194
3195 memcpy(&win, &cam->window, sizeof(win));
3196 memcpy(&pict, &cam->picture, sizeof(pict));
3197 win.width = mmap.width;
3198 win.height = mmap.height;
3199 pict.palette = mmap.format;
3200
3201 if (w9968cf_stop_transfer(cam))
3202 goto ioctl_fail;
3203
3204 /* This before set_window */
3205 if (w9968cf_set_picture(cam, pict))
3206 goto ioctl_fail;
3207
3208 if (w9968cf_set_window(cam, win))
3209 goto ioctl_fail;
3210
3211 if (w9968cf_start_transfer(cam))
3212 goto ioctl_fail;
3213
3214 } else if (fr->queued) {
3215
3216 DBG(6, "Wait until frame #%u is free", mmap.frame)
3217
3218 err = wait_event_interruptible(cam->wait_queue,
3219 cam->disconnected ||
3220 (!fr->queued));
3221 if (err)
3222 return err;
3223 if (cam->disconnected)
3224 return -ENODEV;
3225 }
3226
3227 w9968cf_push_frame(cam, mmap.frame);
3228 DBG(5, "VIDIOCMCAPTURE(%u): successfully called", mmap.frame)
3229 return 0;
3230 }
3231
3232 case VIDIOCSYNC: /* wait until the capture of a frame is finished */
3233 {
3234 unsigned int f_num;
3235 struct w9968cf_frame_t* fr;
3236 int err = 0;
3237
3238 if (copy_from_user(&f_num, arg, sizeof(f_num)))
3239 return -EFAULT;
3240
3241 if (f_num >= cam->nbuffers) {
3242 DBG(4, "Invalid frame number (%u). "
3243 "VIDIOCMCAPTURE failed", f_num)
3244 return -EINVAL;
3245 }
3246
3247 DBG(6, "VIDIOCSYNC called for frame #%u", f_num)
3248
3249 fr = &cam->frame[f_num];
3250
3251 switch (fr->status) {
3252 case F_UNUSED:
3253 if (!fr->queued) {
3254 DBG(4, "VIDIOSYNC: Frame #%u not requested!",
3255 f_num)
3256 return -EFAULT;
3257 }
3258 case F_ERROR:
3259 case F_GRABBING:
3260 err = wait_event_interruptible(cam->wait_queue,
3261 (fr->status == F_READY)
3262 || cam->disconnected);
3263 if (err)
3264 return err;
3265 if (cam->disconnected)
3266 return -ENODEV;
3267 break;
3268 case F_READY:
3269 break;
3270 }
3271
3272 if (w9968cf_vpp)
3273 w9968cf_postprocess_frame(cam, fr);
3274
3275 fr->status = F_UNUSED;
3276
3277 DBG(5, "VIDIOCSYNC(%u) successfully called", f_num)
3278 return 0;
3279 }
3280
3281 case VIDIOCGUNIT:/* report the unit numbers of the associated devices*/
3282 {
3283 struct video_unit unit = {
3284 .video = cam->v4ldev->minor,
3285 .vbi = VIDEO_NO_UNIT,
3286 .radio = VIDEO_NO_UNIT,
3287 .audio = VIDEO_NO_UNIT,
3288 .teletext = VIDEO_NO_UNIT,
3289 };
3290
3291 if (copy_to_user(arg, &unit, sizeof(unit)))
3292 return -EFAULT;
3293
3294 DBG(5, "VIDIOCGUNIT successfully called")
3295 return 0;
3296 }
3297
3298 case VIDIOCKEY:
3299 return 0;
3300
3301 case VIDIOCGFBUF:
3302 {
3303 if (clear_user(arg, sizeof(struct video_buffer)))
3304 return -EFAULT;
3305
3306 DBG(5, "VIDIOCGFBUF successfully called")
3307 return 0;
3308 }
3309
3310 case VIDIOCGTUNER:
3311 {
3312 struct video_tuner tuner;
3313 if (copy_from_user(&tuner, arg, sizeof(tuner)))
3314 return -EFAULT;
3315
3316 if (tuner.tuner != 0)
3317 return -EINVAL;
3318
3319 strcpy(tuner.name, "no_tuner");
3320 tuner.rangelow = 0;
3321 tuner.rangehigh = 0;
3322 tuner.flags = VIDEO_TUNER_NORM;
3323 tuner.mode = VIDEO_MODE_AUTO;
3324 tuner.signal = 0xffff;
3325
3326 if (copy_to_user(arg, &tuner, sizeof(tuner)))
3327 return -EFAULT;
3328
3329 DBG(5, "VIDIOCGTUNER successfully called")
3330 return 0;
3331 }
3332
3333 case VIDIOCSTUNER:
3334 {
3335 struct video_tuner tuner;
3336 if (copy_from_user(&tuner, arg, sizeof(tuner)))
3337 return -EFAULT;
3338
3339 if (tuner.tuner != 0)
3340 return -EINVAL;
3341
3342 if (tuner.mode != VIDEO_MODE_AUTO)
3343 return -EINVAL;
3344
3345 DBG(5, "VIDIOCSTUNER successfully called")
3346 return 0;
3347 }
3348
3349 case VIDIOCSFBUF:
3350 case VIDIOCCAPTURE:
3351 case VIDIOCGFREQ:
3352 case VIDIOCSFREQ:
3353 case VIDIOCGAUDIO:
3354 case VIDIOCSAUDIO:
3355 case VIDIOCSPLAYMODE:
3356 case VIDIOCSWRITEMODE:
3357 case VIDIOCGPLAYINFO:
3358 case VIDIOCSMICROCODE:
3359 case VIDIOCGVBIFMT:
3360 case VIDIOCSVBIFMT:
3361 DBG(4, "Unsupported V4L1 IOCtl: VIDIOC%s "
3362 "(type 0x%01X, "
3363 "n. 0x%01X, "
3364 "dir. 0x%01X, "
3365 "size 0x%02X)",
3366 V4L1_IOCTL(cmd),
3367 _IOC_TYPE(cmd),_IOC_NR(cmd),_IOC_DIR(cmd),_IOC_SIZE(cmd))
3368
3369 return -EINVAL;
3370
3371 default:
3372 DBG(4, "Invalid V4L1 IOCtl: VIDIOC%s "
3373 "type 0x%01X, "
3374 "n. 0x%01X, "
3375 "dir. 0x%01X, "
3376 "size 0x%02X",
3377 V4L1_IOCTL(cmd),
3378 _IOC_TYPE(cmd),_IOC_NR(cmd),_IOC_DIR(cmd),_IOC_SIZE(cmd))
3379
3380 return -ENOIOCTLCMD;
3381
3382 } /* end of switch */
3383
3384ioctl_fail:
3385 cam->misconfigured = 1;
3386 DBG(1, "VIDIOC%s failed because of hardware problems. "
3387 "To use the camera, close and open it again.", V4L1_IOCTL(cmd))
3388 return -EFAULT;
3389}
3390
3391
3392static const struct v4l2_file_operations w9968cf_fops = {
3393 .owner = THIS_MODULE,
3394 .open = w9968cf_open,
3395 .release = w9968cf_release,
3396 .read = w9968cf_read,
3397 .ioctl = w9968cf_ioctl,
3398 .mmap = w9968cf_mmap,
3399};
3400
3401
3402
3403/****************************************************************************
3404 * USB probe and V4L registration, disconnect and id_table[] definition *
3405 ****************************************************************************/
3406
3407static int
3408w9968cf_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
3409{
3410 struct usb_device *udev = interface_to_usbdev(intf);
3411 struct w9968cf_device* cam;
3412 int err = 0;
3413 enum w9968cf_model_id mod_id;
3414 struct list_head* ptr;
3415 u8 sc = 0; /* number of simultaneous cameras */
3416 static unsigned short dev_nr; /* 0 - we are handling device number n */
3417 static unsigned short addrs[] = {
3418 OV7xx0_SID,
3419 OV6xx0_SID,
3420 I2C_CLIENT_END
3421 };
3422
3423 if (le16_to_cpu(udev->descriptor.idVendor) == winbond_id_table[0].idVendor &&
3424 le16_to_cpu(udev->descriptor.idProduct) == winbond_id_table[0].idProduct)
3425 mod_id = W9968CF_MOD_CLVBWGP; /* see camlist[] table */
3426 else if (le16_to_cpu(udev->descriptor.idVendor) == winbond_id_table[1].idVendor &&
3427 le16_to_cpu(udev->descriptor.idProduct) == winbond_id_table[1].idProduct)
3428 mod_id = W9968CF_MOD_GENERIC; /* see camlist[] table */
3429 else
3430 return -ENODEV;
3431
3432 cam = (struct w9968cf_device*)
3433 kzalloc(sizeof(struct w9968cf_device), GFP_KERNEL);
3434 if (!cam)
3435 return -ENOMEM;
3436
3437 err = v4l2_device_register(&intf->dev, &cam->v4l2_dev);
3438 if (err)
3439 goto fail0;
3440
3441 mutex_init(&cam->dev_mutex);
3442 mutex_lock(&cam->dev_mutex);
3443
3444 cam->usbdev = udev;
3445
3446 DBG(2, "%s detected", symbolic(camlist, mod_id))
3447
3448 if (simcams > W9968CF_MAX_DEVICES)
3449 simcams = W9968CF_SIMCAMS;
3450
3451 /* How many cameras are connected ? */
3452 mutex_lock(&w9968cf_devlist_mutex);
3453 list_for_each(ptr, &w9968cf_dev_list)
3454 sc++;
3455 mutex_unlock(&w9968cf_devlist_mutex);
3456
3457 if (sc >= simcams) {
3458 DBG(2, "Device rejected: too many connected cameras "
3459 "(max. %u)", simcams)
3460 err = -EPERM;
3461 goto fail;
3462 }
3463
3464
3465 /* Allocate 2 bytes of memory for camera control USB transfers */
3466 if (!(cam->control_buffer = kzalloc(2, GFP_KERNEL))) {
3467 DBG(1,"Couldn't allocate memory for camera control transfers")
3468 err = -ENOMEM;
3469 goto fail;
3470 }
3471
3472 /* Allocate 8 bytes of memory for USB data transfers to the FSB */
3473 if (!(cam->data_buffer = kzalloc(8, GFP_KERNEL))) {
3474 DBG(1, "Couldn't allocate memory for data "
3475 "transfers to the FSB")
3476 err = -ENOMEM;
3477 goto fail;
3478 }
3479
3480 /* Register the V4L device */
3481 cam->v4ldev = video_device_alloc();
3482 if (!cam->v4ldev) {
3483 DBG(1, "Could not allocate memory for a V4L structure")
3484 err = -ENOMEM;
3485 goto fail;
3486 }
3487
3488 strcpy(cam->v4ldev->name, symbolic(camlist, mod_id));
3489 cam->v4ldev->fops = &w9968cf_fops;
3490 cam->v4ldev->release = video_device_release;
3491 video_set_drvdata(cam->v4ldev, cam);
3492 cam->v4ldev->v4l2_dev = &cam->v4l2_dev;
3493
3494 err = video_register_device(cam->v4ldev, VFL_TYPE_GRABBER,
3495 video_nr[dev_nr]);
3496 if (err) {
3497 DBG(1, "V4L device registration failed")
3498 if (err == -ENFILE && video_nr[dev_nr] == -1)
3499 DBG(2, "Couldn't find a free /dev/videoX node")
3500 video_nr[dev_nr] = -1;
3501 dev_nr = (dev_nr < W9968CF_MAX_DEVICES-1) ? dev_nr+1 : 0;
3502 goto fail;
3503 }
3504
3505 DBG(2, "V4L device registered as %s",
3506 video_device_node_name(cam->v4ldev))
3507
3508 /* Set some basic constants */
3509 w9968cf_configure_camera(cam, udev, mod_id, dev_nr);
3510
3511 /* Add a new entry into the list of V4L registered devices */
3512 mutex_lock(&w9968cf_devlist_mutex);
3513 list_add(&cam->v4llist, &w9968cf_dev_list);
3514 mutex_unlock(&w9968cf_devlist_mutex);
3515 dev_nr = (dev_nr < W9968CF_MAX_DEVICES-1) ? dev_nr+1 : 0;
3516
3517 w9968cf_turn_on_led(cam);
3518
3519 w9968cf_i2c_init(cam);
3520 cam->sensor_sd = v4l2_i2c_new_subdev(&cam->v4l2_dev,
3521 &cam->i2c_adapter,
3522 "ovcamchip", "ovcamchip", 0, addrs);
3523
3524 usb_set_intfdata(intf, cam);
3525 mutex_unlock(&cam->dev_mutex);
3526
3527 err = w9968cf_sensor_init(cam);
3528 return 0;
3529
3530fail: /* Free unused memory */
3531 kfree(cam->control_buffer);
3532 kfree(cam->data_buffer);
3533 if (cam->v4ldev)
3534 video_device_release(cam->v4ldev);
3535 mutex_unlock(&cam->dev_mutex);
3536 v4l2_device_unregister(&cam->v4l2_dev);
3537fail0:
3538 kfree(cam);
3539 return err;
3540}
3541
3542
3543static void w9968cf_usb_disconnect(struct usb_interface* intf)
3544{
3545 struct w9968cf_device* cam =
3546 (struct w9968cf_device*)usb_get_intfdata(intf);
3547
3548 if (cam) {
3549 down_write(&w9968cf_disconnect);
3550 /* Prevent concurrent accesses to data */
3551 mutex_lock(&cam->dev_mutex);
3552
3553 cam->disconnected = 1;
3554
3555 DBG(2, "Disconnecting %s...", symbolic(camlist, cam->id));
3556
3557 v4l2_device_disconnect(&cam->v4l2_dev);
3558
3559 wake_up_interruptible_all(&cam->open);
3560
3561 if (cam->users) {
3562 DBG(2, "The device is open (%s)! "
3563 "Process name: %s. Deregistration and memory "
3564 "deallocation are deferred on close.",
3565 video_device_node_name(cam->v4ldev), cam->command)
3566 cam->misconfigured = 1;
3567 w9968cf_stop_transfer(cam);
3568 wake_up_interruptible(&cam->wait_queue);
3569 } else
3570 w9968cf_release_resources(cam);
3571
3572 mutex_unlock(&cam->dev_mutex);
3573 up_write(&w9968cf_disconnect);
3574
3575 if (!cam->users) {
3576 kfree(cam);
3577 }
3578 }
3579}
3580
3581
3582static struct usb_driver w9968cf_usb_driver = {
3583 .name = "w9968cf",
3584 .id_table = winbond_id_table,
3585 .probe = w9968cf_usb_probe,
3586 .disconnect = w9968cf_usb_disconnect,
3587};
3588
3589
3590
3591/****************************************************************************
3592 * Module init, exit and intermodule communication *
3593 ****************************************************************************/
3594
3595static int __init w9968cf_module_init(void)
3596{
3597 int err;
3598
3599 KDBG(2, W9968CF_MODULE_NAME" "W9968CF_MODULE_VERSION)
3600 KDBG(3, W9968CF_MODULE_AUTHOR)
3601
3602 if ((err = usb_register(&w9968cf_usb_driver)))
3603 return err;
3604
3605 return 0;
3606}
3607
3608
3609static void __exit w9968cf_module_exit(void)
3610{
3611 /* w9968cf_usb_disconnect() will be called */
3612 usb_deregister(&w9968cf_usb_driver);
3613
3614 KDBG(2, W9968CF_MODULE_NAME" deregistered")
3615}
3616
3617
3618module_init(w9968cf_module_init);
3619module_exit(w9968cf_module_exit);
3620
diff --git a/drivers/media/video/w9968cf.h b/drivers/media/video/w9968cf.h
deleted file mode 100644
index 73ad864b4842..000000000000
--- a/drivers/media/video/w9968cf.h
+++ /dev/null
@@ -1,333 +0,0 @@
1/***************************************************************************
2 * Video4Linux driver for W996[87]CF JPEG USB Dual Mode Camera Chip. *
3 * *
4 * Copyright (C) 2002-2004 by Luca Risolia <luca.risolia@studio.unibo.it> *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
19 ***************************************************************************/
20
21#ifndef _W9968CF_H_
22#define _W9968CF_H_
23
24#include <linux/videodev2.h>
25#include <linux/usb.h>
26#include <linux/i2c.h>
27#include <linux/device.h>
28#include <linux/spinlock.h>
29#include <linux/list.h>
30#include <linux/wait.h>
31#include <linux/param.h>
32#include <linux/types.h>
33#include <linux/rwsem.h>
34#include <linux/mutex.h>
35
36#include <media/v4l2-device.h>
37#include <media/ovcamchip.h>
38
39#include "w9968cf_vpp.h"
40
41
42/****************************************************************************
43 * Default values *
44 ****************************************************************************/
45
46#define W9968CF_VPPMOD_LOAD 1 /* automatic 'w9968cf-vpp' module loading */
47
48/* Comment/uncomment the following line to enable/disable debugging messages */
49#define W9968CF_DEBUG
50
51/* These have effect only if W9968CF_DEBUG is defined */
52#define W9968CF_DEBUG_LEVEL 2 /* from 0 to 6. 0 for no debug informations */
53#define W9968CF_SPECIFIC_DEBUG 0 /* 0 or 1 */
54
55#define W9968CF_MAX_DEVICES 32
56#define W9968CF_SIMCAMS W9968CF_MAX_DEVICES /* simultaneous cameras */
57
58#define W9968CF_MAX_BUFFERS 32
59#define W9968CF_BUFFERS 2 /* n. of frame buffers from 2 to MAX_BUFFERS */
60
61/* Maximum data payload sizes in bytes for alternate settings */
62static const u16 wMaxPacketSize[] = {1023, 959, 895, 831, 767, 703, 639, 575,
63 511, 447, 383, 319, 255, 191, 127, 63};
64#define W9968CF_PACKET_SIZE 1023 /* according to wMaxPacketSizes[] */
65#define W9968CF_MIN_PACKET_SIZE 63 /* minimum value */
66#define W9968CF_ISO_PACKETS 5 /* n.of packets for isochronous transfers */
67#define W9968CF_USB_CTRL_TIMEOUT 1000 /* timeout (ms) for usb control commands */
68#define W9968CF_URBS 2 /* n. of scheduled URBs for ISO transfer */
69
70#define W9968CF_I2C_BUS_DELAY 4 /* delay in us for I2C bit r/w operations */
71#define W9968CF_I2C_RW_RETRIES 15 /* number of max I2C r/w retries */
72
73/* Available video formats */
74struct w9968cf_format {
75 const u16 palette;
76 const u16 depth;
77 const u8 compression;
78};
79
80static const struct w9968cf_format w9968cf_formatlist[] = {
81 { VIDEO_PALETTE_UYVY, 16, 0 }, /* original video */
82 { VIDEO_PALETTE_YUV422P, 16, 1 }, /* with JPEG compression */
83 { VIDEO_PALETTE_YUV420P, 12, 1 }, /* with JPEG compression */
84 { VIDEO_PALETTE_YUV420, 12, 1 }, /* same as YUV420P */
85 { VIDEO_PALETTE_YUYV, 16, 0 }, /* software conversion */
86 { VIDEO_PALETTE_YUV422, 16, 0 }, /* software conversion */
87 { VIDEO_PALETTE_GREY, 8, 0 }, /* software conversion */
88 { VIDEO_PALETTE_RGB555, 16, 0 }, /* software conversion */
89 { VIDEO_PALETTE_RGB565, 16, 0 }, /* software conversion */
90 { VIDEO_PALETTE_RGB24, 24, 0 }, /* software conversion */
91 { VIDEO_PALETTE_RGB32, 32, 0 }, /* software conversion */
92 { 0, 0, 0 } /* 0 is a terminating entry */
93};
94
95#define W9968CF_DECOMPRESSION 2 /* decomp:0=disable,1=force,2=any formats */
96#define W9968CF_PALETTE_DECOMP_OFF VIDEO_PALETTE_UYVY /* when decomp=0 */
97#define W9968CF_PALETTE_DECOMP_FORCE VIDEO_PALETTE_YUV420P /* when decomp=1 */
98#define W9968CF_PALETTE_DECOMP_ON VIDEO_PALETTE_UYVY /* when decomp=2 */
99
100#define W9968CF_FORCE_RGB 0 /* read RGB instead of BGR, yes=1/no=0 */
101
102#define W9968CF_MAX_WIDTH 800 /* Has effect if up-scaling is on */
103#define W9968CF_MAX_HEIGHT 600 /* Has effect if up-scaling is on */
104#define W9968CF_WIDTH 320 /* from 128 to 352, multiple of 16 */
105#define W9968CF_HEIGHT 240 /* from 96 to 288, multiple of 16 */
106
107#define W9968CF_CLAMPING 0 /* 0 disable, 1 enable video data clamping */
108#define W9968CF_FILTER_TYPE 0 /* 0 disable 1 (1-2-1), 2 (2-3-6-3-2) */
109#define W9968CF_DOUBLE_BUFFER 1 /* 0 disable, 1 enable double buffer */
110#define W9968CF_LARGEVIEW 1 /* 0 disable, 1 enable */
111#define W9968CF_UPSCALING 0 /* 0 disable, 1 enable */
112
113#define W9968CF_MONOCHROME 0 /* 0 not monochrome, 1 monochrome sensor */
114#define W9968CF_BRIGHTNESS 31000 /* from 0 to 65535 */
115#define W9968CF_HUE 32768 /* from 0 to 65535 */
116#define W9968CF_COLOUR 32768 /* from 0 to 65535 */
117#define W9968CF_CONTRAST 50000 /* from 0 to 65535 */
118#define W9968CF_WHITENESS 32768 /* from 0 to 65535 */
119
120#define W9968CF_AUTOBRIGHT 0 /* 0 disable, 1 enable automatic brightness */
121#define W9968CF_AUTOEXP 1 /* 0 disable, 1 enable automatic exposure */
122#define W9968CF_LIGHTFREQ 50 /* light frequency. 50Hz (Europe) or 60Hz */
123#define W9968CF_BANDINGFILTER 0 /* 0 disable, 1 enable banding filter */
124#define W9968CF_BACKLIGHT 0 /* 0 or 1, 1=object is lit from behind */
125#define W9968CF_MIRROR 0 /* 0 or 1 [don't] reverse image horizontally*/
126
127#define W9968CF_CLOCKDIV -1 /* -1 = automatic clock divisor */
128#define W9968CF_DEF_CLOCKDIVISOR 0 /* default sensor clock divisor value */
129
130
131/****************************************************************************
132 * Globals *
133 ****************************************************************************/
134
135#define W9968CF_MODULE_NAME "V4L driver for W996[87]CF JPEG USB " \
136 "Dual Mode Camera Chip"
137#define W9968CF_MODULE_VERSION "1:1.34-basic"
138#define W9968CF_MODULE_AUTHOR "(C) 2002-2004 Luca Risolia"
139#define W9968CF_AUTHOR_EMAIL "<luca.risolia@studio.unibo.it>"
140#define W9968CF_MODULE_LICENSE "GPL"
141
142static const struct usb_device_id winbond_id_table[] = {
143 {
144 /* Creative Labs Video Blaster WebCam Go Plus */
145 USB_DEVICE(0x041e, 0x4003),
146 .driver_info = (unsigned long)"w9968cf",
147 },
148 {
149 /* Generic W996[87]CF JPEG USB Dual Mode Camera */
150 USB_DEVICE(0x1046, 0x9967),
151 .driver_info = (unsigned long)"w9968cf",
152 },
153 { } /* terminating entry */
154};
155
156/* W996[87]CF camera models, internal ids: */
157enum w9968cf_model_id {
158 W9968CF_MOD_GENERIC = 1, /* Generic W996[87]CF based device */
159 W9968CF_MOD_CLVBWGP = 11,/*Creative Labs Video Blaster WebCam Go Plus*/
160 W9968CF_MOD_ADPVDMA = 21, /* Aroma Digi Pen VGA Dual Mode ADG-5000 */
161 W9986CF_MOD_AAU = 31, /* AVerMedia AVerTV USB */
162 W9968CF_MOD_CLVBWG = 34, /* Creative Labs Video Blaster WebCam Go */
163 W9968CF_MOD_LL = 37, /* Lebon LDC-035A */
164 W9968CF_MOD_EEEMC = 40, /* Ezonics EZ-802 EZMega Cam */
165 W9968CF_MOD_OOE = 42, /* OmniVision OV8610-EDE */
166 W9968CF_MOD_ODPVDMPC = 43,/* OPCOM Digi Pen VGA Dual Mode Pen Camera */
167 W9968CF_MOD_PDPII = 46, /* Pretec Digi Pen-II */
168 W9968CF_MOD_PDP480 = 49, /* Pretec DigiPen-480 */
169};
170
171enum w9968cf_frame_status {
172 F_READY, /* finished grabbing & ready to be read/synced */
173 F_GRABBING, /* in the process of being grabbed into */
174 F_ERROR, /* something bad happened while processing */
175 F_UNUSED /* unused (no VIDIOCMCAPTURE) */
176};
177
178struct w9968cf_frame_t {
179 void* buffer;
180 unsigned long size;
181 u32 length;
182 int number;
183 enum w9968cf_frame_status status;
184 struct w9968cf_frame_t* next;
185 u8 queued;
186};
187
188enum w9968cf_vpp_flag {
189 VPP_NONE = 0x00,
190 VPP_UPSCALE = 0x01,
191 VPP_SWAP_YUV_BYTES = 0x02,
192 VPP_DECOMPRESSION = 0x04,
193 VPP_UYVY_TO_RGBX = 0x08,
194};
195
196/* Main device driver structure */
197struct w9968cf_device {
198 enum w9968cf_model_id id; /* private device identifier */
199
200 struct v4l2_device v4l2_dev;
201 struct video_device* v4ldev; /* -> V4L structure */
202 struct list_head v4llist; /* entry of the list of V4L cameras */
203
204 struct usb_device* usbdev; /* -> main USB structure */
205 struct urb* urb[W9968CF_URBS]; /* -> USB request block structs */
206 void* transfer_buffer[W9968CF_URBS]; /* -> ISO transfer buffers */
207 u16* control_buffer; /* -> buffer for control req.*/
208 u16* data_buffer; /* -> data to send to the FSB */
209
210 struct w9968cf_frame_t frame[W9968CF_MAX_BUFFERS];
211 struct w9968cf_frame_t frame_tmp; /* temporary frame */
212 struct w9968cf_frame_t frame_vpp; /* helper frame.*/
213 struct w9968cf_frame_t* frame_current; /* -> frame being grabbed */
214 struct w9968cf_frame_t* requested_frame[W9968CF_MAX_BUFFERS];
215
216 u8 max_buffers, /* number of requested buffers */
217 force_palette, /* yes=1/no=0 */
218 force_rgb, /* read RGB instead of BGR, yes=1, no=0 */
219 double_buffer, /* hardware double buffering yes=1/no=0 */
220 clamping, /* video data clamping yes=1/no=0 */
221 filter_type, /* 0=disabled, 1=3 tap, 2=5 tap filter */
222 capture, /* 0=disabled, 1=enabled */
223 largeview, /* 0=disabled, 1=enabled */
224 decompression, /* 0=disabled, 1=forced, 2=allowed */
225 upscaling; /* software image scaling, 0=enabled, 1=disabled */
226
227 struct video_picture picture; /* current picture settings */
228 struct video_window window; /* current window settings */
229
230 u16 hw_depth, /* depth (used by the chip) */
231 hw_palette, /* palette (used by the chip) */
232 hw_width, /* width (used by the chip) */
233 hw_height, /* height (used by the chip) */
234 hs_polarity, /* 0=negative sync pulse, 1=positive sync pulse */
235 vs_polarity, /* 0=negative sync pulse, 1=positive sync pulse */
236 start_cropx, /* pixels from HS inactive edge to 1st cropped pixel*/
237 start_cropy; /* pixels from VS inactive edge to 1st cropped pixel*/
238
239 enum w9968cf_vpp_flag vpp_flag; /* post-processing routines in use */
240
241 u8 nbuffers, /* number of allocated frame buffers */
242 altsetting, /* camera alternate setting */
243 disconnected, /* flag: yes=1, no=0 */
244 misconfigured, /* flag: yes=1, no=0 */
245 users, /* flag: number of users holding the device */
246 streaming; /* flag: yes=1, no=0 */
247
248 u8 sensor_initialized; /* flag: yes=1, no=0 */
249
250 /* Determined by the image sensor type: */
251 int sensor, /* type of image sensor chip (CC_*) */
252 monochrome; /* image sensor is (probably) monochrome */
253 u16 maxwidth, /* maximum width supported by the image sensor */
254 maxheight, /* maximum height supported by the image sensor */
255 minwidth, /* minimum width supported by the image sensor */
256 minheight; /* minimum height supported by the image sensor */
257 u8 auto_brt, /* auto brightness enabled flag */
258 auto_exp, /* auto exposure enabled flag */
259 backlight, /* backlight exposure algorithm flag */
260 mirror, /* image is reversed horizontally */
261 lightfreq, /* power (lighting) frequency */
262 bandfilt; /* banding filter enabled flag */
263 s8 clockdiv; /* clock divisor */
264
265 /* I2C interface to kernel */
266 struct i2c_adapter i2c_adapter;
267 struct v4l2_subdev *sensor_sd;
268
269 /* Locks */
270 struct mutex dev_mutex, /* for probe, disconnect,open and close */
271 fileop_mutex; /* for read and ioctl */
272 spinlock_t urb_lock, /* for submit_urb() and unlink_urb() */
273 flist_lock; /* for requested frame list accesses */
274 wait_queue_head_t open, wait_queue;
275
276 char command[16]; /* name of the program holding the device */
277};
278
279static inline struct w9968cf_device *to_cam(struct v4l2_device *v4l2_dev)
280{
281 return container_of(v4l2_dev, struct w9968cf_device, v4l2_dev);
282}
283
284
285/****************************************************************************
286 * Macros for debugging *
287 ****************************************************************************/
288
289#undef DBG
290#undef KDBG
291#ifdef W9968CF_DEBUG
292/* For device specific debugging messages */
293# define DBG(level, fmt, args...) \
294{ \
295 if ( ((specific_debug) && (debug == (level))) || \
296 ((!specific_debug) && (debug >= (level))) ) { \
297 if ((level) == 1) \
298 v4l2_err(&cam->v4l2_dev, fmt "\n", ## args); \
299 else if ((level) == 2 || (level) == 3) \
300 v4l2_info(&cam->v4l2_dev, fmt "\n", ## args); \
301 else if ((level) == 4) \
302 v4l2_warn(&cam->v4l2_dev, fmt "\n", ## args); \
303 else if ((level) >= 5) \
304 v4l2_info(&cam->v4l2_dev, "[%s:%d] " fmt "\n", \
305 __func__, __LINE__ , ## args); \
306 } \
307}
308/* For generic kernel (not device specific) messages */
309# define KDBG(level, fmt, args...) \
310{ \
311 if ( ((specific_debug) && (debug == (level))) || \
312 ((!specific_debug) && (debug >= (level))) ) { \
313 if ((level) >= 1 && (level) <= 4) \
314 pr_info("w9968cf: " fmt "\n", ## args); \
315 else if ((level) >= 5) \
316 pr_debug("w9968cf: [%s:%d] " fmt "\n", __func__, \
317 __LINE__ , ## args); \
318 } \
319}
320#else
321 /* Not debugging: nothing */
322# define DBG(level, fmt, args...) do {;} while(0);
323# define KDBG(level, fmt, args...) do {;} while(0);
324#endif
325
326#undef PDBG
327#define PDBG(fmt, args...) \
328v4l2_info(&cam->v4l2_dev, "[%s:%d] " fmt "\n", __func__, __LINE__ , ## args);
329
330#undef PDBGG
331#define PDBGG(fmt, args...) do {;} while(0); /* nothing: it's a placeholder */
332
333#endif /* _W9968CF_H_ */
diff --git a/drivers/media/video/w9968cf_decoder.h b/drivers/media/video/w9968cf_decoder.h
deleted file mode 100644
index 59decbfc540a..000000000000
--- a/drivers/media/video/w9968cf_decoder.h
+++ /dev/null
@@ -1,86 +0,0 @@
1/***************************************************************************
2 * Video decoder for the W996[87]CF driver for Linux. *
3 * *
4 * Copyright (C) 2003 2004 by Luca Risolia <luca.risolia@studio.unibo.it> *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
19 ***************************************************************************/
20
21#ifndef _W9968CF_DECODER_H_
22#define _W9968CF_DECODER_H_
23
24/* Comment/uncomment this for high/low quality of compressed video */
25#define W9968CF_DEC_FAST_LOWQUALITY_VIDEO
26
27#ifdef W9968CF_DEC_FAST_LOWQUALITY_VIDEO
28static const unsigned char Y_QUANTABLE[64] = {
29 16, 11, 10, 16, 24, 40, 51, 61,
30 12, 12, 14, 19, 26, 58, 60, 55,
31 14, 13, 16, 24, 40, 57, 69, 56,
32 14, 17, 22, 29, 51, 87, 80, 62,
33 18, 22, 37, 56, 68, 109, 103, 77,
34 24, 35, 55, 64, 81, 104, 113, 92,
35 49, 64, 78, 87, 103, 121, 120, 101,
36 72, 92, 95, 98, 112, 100, 103, 99
37};
38
39static const unsigned char UV_QUANTABLE[64] = {
40 17, 18, 24, 47, 99, 99, 99, 99,
41 18, 21, 26, 66, 99, 99, 99, 99,
42 24, 26, 56, 99, 99, 99, 99, 99,
43 47, 66, 99, 99, 99, 99, 99, 99,
44 99, 99, 99, 99, 99, 99, 99, 99,
45 99, 99, 99, 99, 99, 99, 99, 99,
46 99, 99, 99, 99, 99, 99, 99, 99,
47 99, 99, 99, 99, 99, 99, 99, 99
48};
49#else
50static const unsigned char Y_QUANTABLE[64] = {
51 8, 5, 5, 8, 12, 20, 25, 30,
52 6, 6, 7, 9, 13, 29, 30, 27,
53 7, 6, 8, 12, 20, 28, 34, 28,
54 7, 8, 11, 14, 25, 43, 40, 31,
55 9, 11, 18, 28, 34, 54, 51, 38,
56 12, 17, 27, 32, 40, 52, 56, 46,
57 24, 32, 39, 43, 51, 60, 60, 50,
58 36, 46, 47, 49, 56, 50, 51, 49
59};
60
61static const unsigned char UV_QUANTABLE[64] = {
62 8, 9, 12, 23, 49, 49, 49, 49,
63 9, 10, 13, 33, 49, 49, 49, 49,
64 12, 13, 28, 49, 49, 49, 49, 49,
65 23, 33, 49, 49, 49, 49, 49, 49,
66 49, 49, 49, 49, 49, 49, 49, 49,
67 49, 49, 49, 49, 49, 49, 49, 49,
68 49, 49, 49, 49, 49, 49, 49, 49,
69 49, 49, 49, 49, 49, 49, 49, 49
70};
71#endif
72
73#define W9968CF_DEC_ERR_CORRUPTED_DATA -1
74#define W9968CF_DEC_ERR_BUF_OVERFLOW -2
75#define W9968CF_DEC_ERR_NO_SOI -3
76#define W9968CF_DEC_ERR_NO_SOF0 -4
77#define W9968CF_DEC_ERR_NO_SOS -5
78#define W9968CF_DEC_ERR_NO_EOI -6
79
80extern void w9968cf_init_decoder(void);
81extern int w9968cf_check_headers(const unsigned char* Pin,
82 const unsigned long BUF_SIZE);
83extern int w9968cf_decode(const char* Pin, const unsigned long BUF_SIZE,
84 const unsigned W, const unsigned H, char* Pout);
85
86#endif /* _W9968CF_DECODER_H_ */
diff --git a/drivers/media/video/w9968cf_vpp.h b/drivers/media/video/w9968cf_vpp.h
deleted file mode 100644
index 88c9b6c0cc36..000000000000
--- a/drivers/media/video/w9968cf_vpp.h
+++ /dev/null
@@ -1,40 +0,0 @@
1/***************************************************************************
2 * Interface for video post-processing functions for the W996[87]CF driver *
3 * for Linux. *
4 * *
5 * Copyright (C) 2002-2004 by Luca Risolia <luca.risolia@studio.unibo.it> *
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the Free Software *
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
20 ***************************************************************************/
21
22#ifndef _W9968CF_VPP_H_
23#define _W9968CF_VPP_H_
24
25#include <linux/module.h>
26#include <asm/types.h>
27
28struct w9968cf_vpp_t {
29 struct module* owner;
30 int (*check_headers)(const unsigned char*, const unsigned long);
31 int (*decode)(const char*, const unsigned long, const unsigned,
32 const unsigned, char*);
33 void (*swap_yuvbytes)(void*, unsigned long);
34 void (*uyvy_to_rgbx)(u8*, unsigned long, u8*, u16, u8);
35 void (*scale_up)(u8*, u8*, u16, u16, u16, u16, u16);
36
37 u8 busy; /* read-only flag: module is/is not in use */
38};
39
40#endif /* _W9968CF_VPP_H_ */
diff --git a/drivers/media/video/zc0301/Kconfig b/drivers/media/video/zc0301/Kconfig
deleted file mode 100644
index a7e610e0be9e..000000000000
--- a/drivers/media/video/zc0301/Kconfig
+++ /dev/null
@@ -1,15 +0,0 @@
1config USB_ZC0301
2 tristate "USB ZC0301[P] webcam support (DEPRECATED)"
3 depends on VIDEO_V4L2
4 default n
5 ---help---
6 This driver is DEPRECATED please use the gspca zc3xx module
7 instead.
8
9 Say Y here if you want support for cameras based on the ZC0301 or
10 ZC0301P Image Processors and Control Chips.
11
12 See <file:Documentation/video4linux/zc0301.txt> for more info.
13
14 To compile this driver as a module, choose M here: the
15 module will be called zc0301.
diff --git a/drivers/media/video/zc0301/Makefile b/drivers/media/video/zc0301/Makefile
deleted file mode 100644
index d9e6d97fade6..000000000000
--- a/drivers/media/video/zc0301/Makefile
+++ /dev/null
@@ -1,3 +0,0 @@
1zc0301-objs := zc0301_core.o zc0301_pb0330.o zc0301_pas202bcb.o
2
3obj-$(CONFIG_USB_ZC0301) += zc0301.o
diff --git a/drivers/media/video/zc0301/zc0301.h b/drivers/media/video/zc0301/zc0301.h
deleted file mode 100644
index b1b5cceb4baa..000000000000
--- a/drivers/media/video/zc0301/zc0301.h
+++ /dev/null
@@ -1,196 +0,0 @@
1/***************************************************************************
2 * V4L2 driver for ZC0301[P] Image Processor and Control Chip *
3 * *
4 * Copyright (C) 2006-2007 by Luca Risolia <luca.risolia@studio.unibo.it> *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
19 ***************************************************************************/
20
21#ifndef _ZC0301_H_
22#define _ZC0301_H_
23
24#include <linux/version.h>
25#include <linux/usb.h>
26#include <linux/videodev2.h>
27#include <media/v4l2-common.h>
28#include <media/v4l2-ioctl.h>
29#include <linux/device.h>
30#include <linux/list.h>
31#include <linux/spinlock.h>
32#include <linux/time.h>
33#include <linux/wait.h>
34#include <linux/types.h>
35#include <linux/param.h>
36#include <linux/mutex.h>
37#include <linux/rwsem.h>
38#include <linux/stddef.h>
39#include <linux/string.h>
40#include <linux/kref.h>
41
42#include "zc0301_sensor.h"
43
44/*****************************************************************************/
45
46#define ZC0301_DEBUG
47#define ZC0301_DEBUG_LEVEL 2
48#define ZC0301_MAX_DEVICES 64
49#define ZC0301_FORCE_MUNMAP 0
50#define ZC0301_MAX_FRAMES 32
51#define ZC0301_COMPRESSION_QUALITY 0
52#define ZC0301_URBS 2
53#define ZC0301_ISO_PACKETS 7
54#define ZC0301_ALTERNATE_SETTING 7
55#define ZC0301_URB_TIMEOUT msecs_to_jiffies(2 * ZC0301_ISO_PACKETS)
56#define ZC0301_CTRL_TIMEOUT 100
57#define ZC0301_FRAME_TIMEOUT 2
58
59/*****************************************************************************/
60
61ZC0301_ID_TABLE
62ZC0301_SENSOR_TABLE
63
64enum zc0301_frame_state {
65 F_UNUSED,
66 F_QUEUED,
67 F_GRABBING,
68 F_DONE,
69 F_ERROR,
70};
71
72struct zc0301_frame_t {
73 void* bufmem;
74 struct v4l2_buffer buf;
75 enum zc0301_frame_state state;
76 struct list_head frame;
77 unsigned long vma_use_count;
78};
79
80enum zc0301_dev_state {
81 DEV_INITIALIZED = 0x01,
82 DEV_DISCONNECTED = 0x02,
83 DEV_MISCONFIGURED = 0x04,
84};
85
86enum zc0301_io_method {
87 IO_NONE,
88 IO_READ,
89 IO_MMAP,
90};
91
92enum zc0301_stream_state {
93 STREAM_OFF,
94 STREAM_INTERRUPT,
95 STREAM_ON,
96};
97
98struct zc0301_module_param {
99 u8 force_munmap;
100 u16 frame_timeout;
101};
102
103static DECLARE_RWSEM(zc0301_dev_lock);
104
105struct zc0301_device {
106 struct video_device* v4ldev;
107
108 struct zc0301_sensor sensor;
109
110 struct usb_device* usbdev;
111 struct urb* urb[ZC0301_URBS];
112 void* transfer_buffer[ZC0301_URBS];
113 u8* control_buffer;
114
115 struct zc0301_frame_t *frame_current, frame[ZC0301_MAX_FRAMES];
116 struct list_head inqueue, outqueue;
117 u32 frame_count, nbuffers, nreadbuffers;
118
119 enum zc0301_io_method io;
120 enum zc0301_stream_state stream;
121
122 struct v4l2_jpegcompression compression;
123
124 struct zc0301_module_param module_param;
125
126 struct kref kref;
127 enum zc0301_dev_state state;
128 u8 users;
129
130 struct completion probe;
131 struct mutex open_mutex, fileop_mutex;
132 spinlock_t queue_lock;
133 wait_queue_head_t wait_open, wait_frame, wait_stream;
134};
135
136/*****************************************************************************/
137
138struct zc0301_device*
139zc0301_match_id(struct zc0301_device* cam, const struct usb_device_id *id)
140{
141 return usb_match_id(usb_ifnum_to_if(cam->usbdev, 0), id) ? cam : NULL;
142}
143
144void
145zc0301_attach_sensor(struct zc0301_device* cam, struct zc0301_sensor* sensor)
146{
147 memcpy(&cam->sensor, sensor, sizeof(struct zc0301_sensor));
148}
149
150/*****************************************************************************/
151
152#undef DBG
153#undef KDBG
154#ifdef ZC0301_DEBUG
155# define DBG(level, fmt, args...) \
156do { \
157 if (debug >= (level)) { \
158 if ((level) == 1) \
159 dev_err(&cam->usbdev->dev, fmt "\n", ## args); \
160 else if ((level) == 2) \
161 dev_info(&cam->usbdev->dev, fmt "\n", ## args); \
162 else if ((level) >= 3) \
163 dev_info(&cam->usbdev->dev, "[%s:%s:%d] " fmt "\n", \
164 __FILE__, __func__, __LINE__ , ## args); \
165 } \
166} while (0)
167# define KDBG(level, fmt, args...) \
168do { \
169 if (debug >= (level)) { \
170 if ((level) == 1 || (level) == 2) \
171 pr_info("zc0301: " fmt "\n", ## args); \
172 else if ((level) == 3) \
173 pr_debug("sn9c102: [%s:%s:%d] " fmt "\n", __FILE__, \
174 __func__, __LINE__ , ## args); \
175 } \
176} while (0)
177# define V4LDBG(level, name, cmd) \
178do { \
179 if (debug >= (level)) \
180 v4l_print_ioctl(name, cmd); \
181} while (0)
182#else
183# define DBG(level, fmt, args...) do {;} while(0)
184# define KDBG(level, fmt, args...) do {;} while(0)
185# define V4LDBG(level, name, cmd) do {;} while(0)
186#endif
187
188#undef PDBG
189#define PDBG(fmt, args...) \
190dev_info(&cam->usbdev->dev, "[%s:%s:%d] " fmt "\n", __FILE__, __func__, \
191 __LINE__ , ## args)
192
193#undef PDBGG
194#define PDBGG(fmt, args...) do {;} while(0) /* placeholder */
195
196#endif /* _ZC0301_H_ */
diff --git a/drivers/media/video/zc0301/zc0301_core.c b/drivers/media/video/zc0301/zc0301_core.c
deleted file mode 100644
index bb51cfb0c647..000000000000
--- a/drivers/media/video/zc0301/zc0301_core.c
+++ /dev/null
@@ -1,2098 +0,0 @@
1/***************************************************************************
2 * Video4Linux2 driver for ZC0301[P] Image Processor and Control Chip *
3 * *
4 * Copyright (C) 2006-2007 by Luca Risolia <luca.risolia@studio.unibo.it> *
5 * *
6 * Informations about the chip internals needed to enable the I2C protocol *
7 * have been taken from the documentation of the ZC030x Video4Linux1 *
8 * driver written by Andrew Birkett <andy@nobugs.org> *
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the Free Software *
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
23 ***************************************************************************/
24
25#include <linux/module.h>
26#include <linux/init.h>
27#include <linux/kernel.h>
28#include <linux/param.h>
29#include <linux/errno.h>
30#include <linux/slab.h>
31#include <linux/device.h>
32#include <linux/fs.h>
33#include <linux/delay.h>
34#include <linux/compiler.h>
35#include <linux/ioctl.h>
36#include <linux/poll.h>
37#include <linux/stat.h>
38#include <linux/mm.h>
39#include <linux/vmalloc.h>
40#include <linux/page-flags.h>
41#include <asm/byteorder.h>
42#include <asm/page.h>
43#include <asm/uaccess.h>
44
45#include "zc0301.h"
46
47/*****************************************************************************/
48
49#define ZC0301_MODULE_NAME "V4L2 driver for ZC0301[P] " \
50 "Image Processor and Control Chip"
51#define ZC0301_MODULE_AUTHOR "(C) 2006-2007 Luca Risolia"
52#define ZC0301_AUTHOR_EMAIL "<luca.risolia@studio.unibo.it>"
53#define ZC0301_MODULE_LICENSE "GPL"
54#define ZC0301_MODULE_VERSION "1:1.10"
55#define ZC0301_MODULE_VERSION_CODE KERNEL_VERSION(1, 1, 10)
56
57/*****************************************************************************/
58
59MODULE_DEVICE_TABLE(usb, zc0301_id_table);
60
61MODULE_AUTHOR(ZC0301_MODULE_AUTHOR " " ZC0301_AUTHOR_EMAIL);
62MODULE_DESCRIPTION(ZC0301_MODULE_NAME);
63MODULE_VERSION(ZC0301_MODULE_VERSION);
64MODULE_LICENSE(ZC0301_MODULE_LICENSE);
65
66static short video_nr[] = {[0 ... ZC0301_MAX_DEVICES-1] = -1};
67module_param_array(video_nr, short, NULL, 0444);
68MODULE_PARM_DESC(video_nr,
69 "\n<-1|n[,...]> Specify V4L2 minor mode number."
70 "\n -1 = use next available (default)"
71 "\n n = use minor number n (integer >= 0)"
72 "\nYou can specify up to "
73 __MODULE_STRING(ZC0301_MAX_DEVICES) " cameras this way."
74 "\nFor example:"
75 "\nvideo_nr=-1,2,-1 would assign minor number 2 to"
76 "\nthe second registered camera and use auto for the first"
77 "\none and for every other camera."
78 "\n");
79
80static short force_munmap[] = {[0 ... ZC0301_MAX_DEVICES-1] =
81 ZC0301_FORCE_MUNMAP};
82module_param_array(force_munmap, bool, NULL, 0444);
83MODULE_PARM_DESC(force_munmap,
84 "\n<0|1[,...]> Force the application to unmap previously"
85 "\nmapped buffer memory before calling any VIDIOC_S_CROP or"
86 "\nVIDIOC_S_FMT ioctl's. Not all the applications support"
87 "\nthis feature. This parameter is specific for each"
88 "\ndetected camera."
89 "\n 0 = do not force memory unmapping"
90 "\n 1 = force memory unmapping (save memory)"
91 "\nDefault value is "__MODULE_STRING(ZC0301_FORCE_MUNMAP)"."
92 "\n");
93
94static unsigned int frame_timeout[] = {[0 ... ZC0301_MAX_DEVICES-1] =
95 ZC0301_FRAME_TIMEOUT};
96module_param_array(frame_timeout, uint, NULL, 0644);
97MODULE_PARM_DESC(frame_timeout,
98 "\n<n[,...]> Timeout for a video frame in seconds."
99 "\nThis parameter is specific for each detected camera."
100 "\nDefault value is "__MODULE_STRING(ZC0301_FRAME_TIMEOUT)"."
101 "\n");
102
103#ifdef ZC0301_DEBUG
104static unsigned short debug = ZC0301_DEBUG_LEVEL;
105module_param(debug, ushort, 0644);
106MODULE_PARM_DESC(debug,
107 "\n<n> Debugging information level, from 0 to 3:"
108 "\n0 = none (use carefully)"
109 "\n1 = critical errors"
110 "\n2 = significant informations"
111 "\n3 = more verbose messages"
112 "\nLevel 3 is useful for testing only, when only "
113 "one device is used."
114 "\nDefault value is "__MODULE_STRING(ZC0301_DEBUG_LEVEL)"."
115 "\n");
116#endif
117
118/*****************************************************************************/
119
120static u32
121zc0301_request_buffers(struct zc0301_device* cam, u32 count,
122 enum zc0301_io_method io)
123{
124 struct v4l2_pix_format* p = &(cam->sensor.pix_format);
125 struct v4l2_rect* r = &(cam->sensor.cropcap.bounds);
126 const size_t imagesize = cam->module_param.force_munmap ||
127 io == IO_READ ?
128 (p->width * p->height * p->priv) / 8 :
129 (r->width * r->height * p->priv) / 8;
130 void* buff = NULL;
131 u32 i;
132
133 if (count > ZC0301_MAX_FRAMES)
134 count = ZC0301_MAX_FRAMES;
135
136 cam->nbuffers = count;
137 while (cam->nbuffers > 0) {
138 if ((buff = vmalloc_32_user(cam->nbuffers *
139 PAGE_ALIGN(imagesize))))
140 break;
141 cam->nbuffers--;
142 }
143
144 for (i = 0; i < cam->nbuffers; i++) {
145 cam->frame[i].bufmem = buff + i*PAGE_ALIGN(imagesize);
146 cam->frame[i].buf.index = i;
147 cam->frame[i].buf.m.offset = i*PAGE_ALIGN(imagesize);
148 cam->frame[i].buf.length = imagesize;
149 cam->frame[i].buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
150 cam->frame[i].buf.sequence = 0;
151 cam->frame[i].buf.field = V4L2_FIELD_NONE;
152 cam->frame[i].buf.memory = V4L2_MEMORY_MMAP;
153 cam->frame[i].buf.flags = 0;
154 }
155
156 return cam->nbuffers;
157}
158
159
160static void zc0301_release_buffers(struct zc0301_device* cam)
161{
162 if (cam->nbuffers) {
163 vfree(cam->frame[0].bufmem);
164 cam->nbuffers = 0;
165 }
166 cam->frame_current = NULL;
167}
168
169
170static void zc0301_empty_framequeues(struct zc0301_device* cam)
171{
172 u32 i;
173
174 INIT_LIST_HEAD(&cam->inqueue);
175 INIT_LIST_HEAD(&cam->outqueue);
176
177 for (i = 0; i < ZC0301_MAX_FRAMES; i++) {
178 cam->frame[i].state = F_UNUSED;
179 cam->frame[i].buf.bytesused = 0;
180 }
181}
182
183
184static void zc0301_requeue_outqueue(struct zc0301_device* cam)
185{
186 struct zc0301_frame_t *i;
187
188 list_for_each_entry(i, &cam->outqueue, frame) {
189 i->state = F_QUEUED;
190 list_add(&i->frame, &cam->inqueue);
191 }
192
193 INIT_LIST_HEAD(&cam->outqueue);
194}
195
196
197static void zc0301_queue_unusedframes(struct zc0301_device* cam)
198{
199 unsigned long lock_flags;
200 u32 i;
201
202 for (i = 0; i < cam->nbuffers; i++)
203 if (cam->frame[i].state == F_UNUSED) {
204 cam->frame[i].state = F_QUEUED;
205 spin_lock_irqsave(&cam->queue_lock, lock_flags);
206 list_add_tail(&cam->frame[i].frame, &cam->inqueue);
207 spin_unlock_irqrestore(&cam->queue_lock, lock_flags);
208 }
209}
210
211/*****************************************************************************/
212
213int zc0301_write_reg(struct zc0301_device* cam, u16 index, u16 value)
214{
215 struct usb_device* udev = cam->usbdev;
216 int res;
217
218 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0xa0, 0x40,
219 value, index, NULL, 0, ZC0301_CTRL_TIMEOUT);
220 if (res < 0) {
221 DBG(3, "Failed to write a register (index 0x%04X, "
222 "value 0x%02X, error %d)",index, value, res);
223 return -1;
224 }
225
226 return 0;
227}
228
229
230int zc0301_read_reg(struct zc0301_device* cam, u16 index)
231{
232 struct usb_device* udev = cam->usbdev;
233 u8* buff = cam->control_buffer;
234 int res;
235
236 res = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), 0xa1, 0xc0,
237 0x0001, index, buff, 1, ZC0301_CTRL_TIMEOUT);
238 if (res < 0)
239 DBG(3, "Failed to read a register (index 0x%04X, error %d)",
240 index, res);
241
242 PDBGG("Read: index 0x%04X, value: 0x%04X", index, (int)(*buff));
243
244 return (res >= 0) ? (int)(*buff) : -1;
245}
246
247
248int zc0301_i2c_read(struct zc0301_device* cam, u16 address, u8 length)
249{
250 int err = 0, res, r0, r1;
251
252 err += zc0301_write_reg(cam, 0x0092, address);
253 err += zc0301_write_reg(cam, 0x0090, 0x02);
254
255 msleep(1);
256
257 res = zc0301_read_reg(cam, 0x0091);
258 if (res < 0)
259 err += res;
260 r0 = zc0301_read_reg(cam, 0x0095);
261 if (r0 < 0)
262 err += r0;
263 r1 = zc0301_read_reg(cam, 0x0096);
264 if (r1 < 0)
265 err += r1;
266
267 res = (length <= 1) ? r0 : r0 | (r1 << 8);
268
269 if (err)
270 DBG(3, "I2C read failed at address 0x%04X, value: 0x%04X",
271 address, res);
272
273
274 PDBGG("I2C read: address 0x%04X, value: 0x%04X", address, res);
275
276 return err ? -1 : res;
277}
278
279
280int zc0301_i2c_write(struct zc0301_device* cam, u16 address, u16 value)
281{
282 int err = 0, res;
283
284 err += zc0301_write_reg(cam, 0x0092, address);
285 err += zc0301_write_reg(cam, 0x0093, value & 0xff);
286 err += zc0301_write_reg(cam, 0x0094, value >> 8);
287 err += zc0301_write_reg(cam, 0x0090, 0x01);
288
289 msleep(1);
290
291 res = zc0301_read_reg(cam, 0x0091);
292 if (res < 0)
293 err += res;
294
295 if (err)
296 DBG(3, "I2C write failed at address 0x%04X, value: 0x%04X",
297 address, value);
298
299 PDBGG("I2C write: address 0x%04X, value: 0x%04X", address, value);
300
301 return err ? -1 : 0;
302}
303
304/*****************************************************************************/
305
306static void zc0301_urb_complete(struct urb *urb)
307{
308 struct zc0301_device* cam = urb->context;
309 struct zc0301_frame_t** f;
310 size_t imagesize;
311 u8 i;
312 int err = 0;
313
314 if (urb->status == -ENOENT)
315 return;
316
317 f = &cam->frame_current;
318
319 if (cam->stream == STREAM_INTERRUPT) {
320 cam->stream = STREAM_OFF;
321 if ((*f))
322 (*f)->state = F_QUEUED;
323 DBG(3, "Stream interrupted");
324 wake_up(&cam->wait_stream);
325 }
326
327 if (cam->state & DEV_DISCONNECTED)
328 return;
329
330 if (cam->state & DEV_MISCONFIGURED) {
331 wake_up_interruptible(&cam->wait_frame);
332 return;
333 }
334
335 if (cam->stream == STREAM_OFF || list_empty(&cam->inqueue))
336 goto resubmit_urb;
337
338 if (!(*f))
339 (*f) = list_entry(cam->inqueue.next, struct zc0301_frame_t,
340 frame);
341
342 imagesize = (cam->sensor.pix_format.width *
343 cam->sensor.pix_format.height *
344 cam->sensor.pix_format.priv) / 8;
345
346 for (i = 0; i < urb->number_of_packets; i++) {
347 unsigned int len, status;
348 void *pos;
349 u16* soi;
350 u8 sof;
351
352 len = urb->iso_frame_desc[i].actual_length;
353 status = urb->iso_frame_desc[i].status;
354 pos = urb->iso_frame_desc[i].offset + urb->transfer_buffer;
355
356 if (status) {
357 DBG(3, "Error in isochronous frame");
358 (*f)->state = F_ERROR;
359 continue;
360 }
361
362 sof = (*(soi = pos) == 0xd8ff);
363
364 PDBGG("Isochrnous frame: length %u, #%u i,", len, i);
365
366 if ((*f)->state == F_QUEUED || (*f)->state == F_ERROR)
367start_of_frame:
368 if (sof) {
369 (*f)->state = F_GRABBING;
370 (*f)->buf.bytesused = 0;
371 do_gettimeofday(&(*f)->buf.timestamp);
372 DBG(3, "SOF detected: new video frame");
373 }
374
375 if ((*f)->state == F_GRABBING) {
376 if (sof && (*f)->buf.bytesused)
377 goto end_of_frame;
378
379 if ((*f)->buf.bytesused + len > imagesize) {
380 DBG(3, "Video frame size exceeded");
381 (*f)->state = F_ERROR;
382 continue;
383 }
384
385 memcpy((*f)->bufmem+(*f)->buf.bytesused, pos, len);
386 (*f)->buf.bytesused += len;
387
388 if ((*f)->buf.bytesused == imagesize) {
389 u32 b;
390end_of_frame:
391 b = (*f)->buf.bytesused;
392 (*f)->state = F_DONE;
393 (*f)->buf.sequence= ++cam->frame_count;
394 spin_lock(&cam->queue_lock);
395 list_move_tail(&(*f)->frame, &cam->outqueue);
396 if (!list_empty(&cam->inqueue))
397 (*f) = list_entry(cam->inqueue.next,
398 struct zc0301_frame_t,
399 frame);
400 else
401 (*f) = NULL;
402 spin_unlock(&cam->queue_lock);
403 DBG(3, "Video frame captured: : %lu bytes",
404 (unsigned long)(b));
405
406 if (!(*f))
407 goto resubmit_urb;
408
409 if (sof)
410 goto start_of_frame;
411 }
412 }
413 }
414
415resubmit_urb:
416 urb->dev = cam->usbdev;
417 err = usb_submit_urb(urb, GFP_ATOMIC);
418 if (err < 0 && err != -EPERM) {
419 cam->state |= DEV_MISCONFIGURED;
420 DBG(1, "usb_submit_urb() failed");
421 }
422
423 wake_up_interruptible(&cam->wait_frame);
424}
425
426
427static int zc0301_start_transfer(struct zc0301_device* cam)
428{
429 struct usb_device *udev = cam->usbdev;
430 struct usb_host_interface* altsetting = usb_altnum_to_altsetting(
431 usb_ifnum_to_if(udev, 0),
432 ZC0301_ALTERNATE_SETTING);
433 const unsigned int psz = le16_to_cpu(altsetting->
434 endpoint[0].desc.wMaxPacketSize);
435 struct urb* urb;
436 s8 i, j;
437 int err = 0;
438
439 for (i = 0; i < ZC0301_URBS; i++) {
440 cam->transfer_buffer[i] = kzalloc(ZC0301_ISO_PACKETS * psz,
441 GFP_KERNEL);
442 if (!cam->transfer_buffer[i]) {
443 err = -ENOMEM;
444 DBG(1, "Not enough memory");
445 goto free_buffers;
446 }
447 }
448
449 for (i = 0; i < ZC0301_URBS; i++) {
450 urb = usb_alloc_urb(ZC0301_ISO_PACKETS, GFP_KERNEL);
451 cam->urb[i] = urb;
452 if (!urb) {
453 err = -ENOMEM;
454 DBG(1, "usb_alloc_urb() failed");
455 goto free_urbs;
456 }
457 urb->dev = udev;
458 urb->context = cam;
459 urb->pipe = usb_rcvisocpipe(udev, 1);
460 urb->transfer_flags = URB_ISO_ASAP;
461 urb->number_of_packets = ZC0301_ISO_PACKETS;
462 urb->complete = zc0301_urb_complete;
463 urb->transfer_buffer = cam->transfer_buffer[i];
464 urb->transfer_buffer_length = psz * ZC0301_ISO_PACKETS;
465 urb->interval = 1;
466 for (j = 0; j < ZC0301_ISO_PACKETS; j++) {
467 urb->iso_frame_desc[j].offset = psz * j;
468 urb->iso_frame_desc[j].length = psz;
469 }
470 }
471
472 err = usb_set_interface(udev, 0, ZC0301_ALTERNATE_SETTING);
473 if (err) {
474 DBG(1, "usb_set_interface() failed");
475 goto free_urbs;
476 }
477
478 cam->frame_current = NULL;
479
480 for (i = 0; i < ZC0301_URBS; i++) {
481 err = usb_submit_urb(cam->urb[i], GFP_KERNEL);
482 if (err) {
483 for (j = i-1; j >= 0; j--)
484 usb_kill_urb(cam->urb[j]);
485 DBG(1, "usb_submit_urb() failed, error %d", err);
486 goto free_urbs;
487 }
488 }
489
490 return 0;
491
492free_urbs:
493 for (i = 0; (i < ZC0301_URBS) && cam->urb[i]; i++)
494 usb_free_urb(cam->urb[i]);
495
496free_buffers:
497 for (i = 0; (i < ZC0301_URBS) && cam->transfer_buffer[i]; i++)
498 kfree(cam->transfer_buffer[i]);
499
500 return err;
501}
502
503
504static int zc0301_stop_transfer(struct zc0301_device* cam)
505{
506 struct usb_device *udev = cam->usbdev;
507 s8 i;
508 int err = 0;
509
510 if (cam->state & DEV_DISCONNECTED)
511 return 0;
512
513 for (i = ZC0301_URBS-1; i >= 0; i--) {
514 usb_kill_urb(cam->urb[i]);
515 usb_free_urb(cam->urb[i]);
516 kfree(cam->transfer_buffer[i]);
517 }
518
519 err = usb_set_interface(udev, 0, 0); /* 0 Mb/s */
520 if (err)
521 DBG(3, "usb_set_interface() failed");
522
523 return err;
524}
525
526
527static int zc0301_stream_interrupt(struct zc0301_device* cam)
528{
529 long timeout;
530
531 cam->stream = STREAM_INTERRUPT;
532 timeout = wait_event_timeout(cam->wait_stream,
533 (cam->stream == STREAM_OFF) ||
534 (cam->state & DEV_DISCONNECTED),
535 ZC0301_URB_TIMEOUT);
536 if (cam->state & DEV_DISCONNECTED)
537 return -ENODEV;
538 else if (cam->stream != STREAM_OFF) {
539 cam->state |= DEV_MISCONFIGURED;
540 DBG(1, "URB timeout reached. The camera is misconfigured. To "
541 "use it, close and open %s again.",
542 video_device_node_name(cam->v4ldev));
543 return -EIO;
544 }
545
546 return 0;
547}
548
549/*****************************************************************************/
550
551static int
552zc0301_set_compression(struct zc0301_device* cam,
553 struct v4l2_jpegcompression* compression)
554{
555 int r, err = 0;
556
557 if ((r = zc0301_read_reg(cam, 0x0008)) < 0)
558 err += r;
559 err += zc0301_write_reg(cam, 0x0008, r | 0x11 | compression->quality);
560
561 return err ? -EIO : 0;
562}
563
564
565static int zc0301_init(struct zc0301_device* cam)
566{
567 struct zc0301_sensor* s = &cam->sensor;
568 struct v4l2_control ctrl;
569 struct v4l2_queryctrl *qctrl;
570 struct v4l2_rect* rect;
571 u8 i = 0;
572 int err = 0;
573
574 if (!(cam->state & DEV_INITIALIZED)) {
575 mutex_init(&cam->open_mutex);
576 init_waitqueue_head(&cam->wait_open);
577 qctrl = s->qctrl;
578 rect = &(s->cropcap.defrect);
579 cam->compression.quality = ZC0301_COMPRESSION_QUALITY;
580 } else { /* use current values */
581 qctrl = s->_qctrl;
582 rect = &(s->_rect);
583 }
584
585 if (s->init) {
586 err = s->init(cam);
587 if (err) {
588 DBG(3, "Sensor initialization failed");
589 return err;
590 }
591 }
592
593 if ((err = zc0301_set_compression(cam, &cam->compression))) {
594 DBG(3, "set_compression() failed");
595 return err;
596 }
597
598 if (s->set_crop)
599 if ((err = s->set_crop(cam, rect))) {
600 DBG(3, "set_crop() failed");
601 return err;
602 }
603
604 if (s->set_ctrl) {
605 for (i = 0; i < ARRAY_SIZE(s->qctrl); i++)
606 if (s->qctrl[i].id != 0 &&
607 !(s->qctrl[i].flags & V4L2_CTRL_FLAG_DISABLED)) {
608 ctrl.id = s->qctrl[i].id;
609 ctrl.value = qctrl[i].default_value;
610 err = s->set_ctrl(cam, &ctrl);
611 if (err) {
612 DBG(3, "Set %s control failed",
613 s->qctrl[i].name);
614 return err;
615 }
616 DBG(3, "Image sensor supports '%s' control",
617 s->qctrl[i].name);
618 }
619 }
620
621 if (!(cam->state & DEV_INITIALIZED)) {
622 mutex_init(&cam->fileop_mutex);
623 spin_lock_init(&cam->queue_lock);
624 init_waitqueue_head(&cam->wait_frame);
625 init_waitqueue_head(&cam->wait_stream);
626 cam->nreadbuffers = 2;
627 memcpy(s->_qctrl, s->qctrl, sizeof(s->qctrl));
628 memcpy(&(s->_rect), &(s->cropcap.defrect),
629 sizeof(struct v4l2_rect));
630 cam->state |= DEV_INITIALIZED;
631 }
632
633 DBG(2, "Initialization succeeded");
634 return 0;
635}
636
637/*****************************************************************************/
638
639static void zc0301_release_resources(struct kref *kref)
640{
641 struct zc0301_device *cam = container_of(kref, struct zc0301_device,
642 kref);
643 DBG(2, "V4L2 device %s deregistered",
644 video_device_node_name(cam->v4ldev));
645 video_set_drvdata(cam->v4ldev, NULL);
646 video_unregister_device(cam->v4ldev);
647 usb_put_dev(cam->usbdev);
648 kfree(cam->control_buffer);
649 kfree(cam);
650}
651
652
653static int zc0301_open(struct file *filp)
654{
655 struct zc0301_device* cam;
656 int err = 0;
657
658 if (!down_read_trylock(&zc0301_dev_lock))
659 return -EAGAIN;
660
661 cam = video_drvdata(filp);
662
663 if (wait_for_completion_interruptible(&cam->probe)) {
664 up_read(&zc0301_dev_lock);
665 return -ERESTARTSYS;
666 }
667
668 kref_get(&cam->kref);
669
670 if (mutex_lock_interruptible(&cam->open_mutex)) {
671 kref_put(&cam->kref, zc0301_release_resources);
672 up_read(&zc0301_dev_lock);
673 return -ERESTARTSYS;
674 }
675
676 if (cam->state & DEV_DISCONNECTED) {
677 DBG(1, "Device not present");
678 err = -ENODEV;
679 goto out;
680 }
681
682 if (cam->users) {
683 DBG(2, "Device %s is busy...",
684 video_device_node_name(cam->v4ldev));
685 DBG(3, "Simultaneous opens are not supported");
686 if ((filp->f_flags & O_NONBLOCK) ||
687 (filp->f_flags & O_NDELAY)) {
688 err = -EWOULDBLOCK;
689 goto out;
690 }
691 DBG(2, "A blocking open() has been requested. Wait for the "
692 "device to be released...");
693 up_read(&zc0301_dev_lock);
694 err = wait_event_interruptible_exclusive(cam->wait_open,
695 (cam->state & DEV_DISCONNECTED)
696 || !cam->users);
697 down_read(&zc0301_dev_lock);
698 if (err)
699 goto out;
700 if (cam->state & DEV_DISCONNECTED) {
701 err = -ENODEV;
702 goto out;
703 }
704 }
705
706 if (cam->state & DEV_MISCONFIGURED) {
707 err = zc0301_init(cam);
708 if (err) {
709 DBG(1, "Initialization failed again. "
710 "I will retry on next open().");
711 goto out;
712 }
713 cam->state &= ~DEV_MISCONFIGURED;
714 }
715
716 if ((err = zc0301_start_transfer(cam)))
717 goto out;
718
719 filp->private_data = cam;
720 cam->users++;
721 cam->io = IO_NONE;
722 cam->stream = STREAM_OFF;
723 cam->nbuffers = 0;
724 cam->frame_count = 0;
725 zc0301_empty_framequeues(cam);
726
727 DBG(3, "Video device %s is open",
728 video_device_node_name(cam->v4ldev));
729
730out:
731 mutex_unlock(&cam->open_mutex);
732 if (err)
733 kref_put(&cam->kref, zc0301_release_resources);
734 up_read(&zc0301_dev_lock);
735 return err;
736}
737
738
739static int zc0301_release(struct file *filp)
740{
741 struct zc0301_device* cam;
742
743 down_write(&zc0301_dev_lock);
744
745 cam = video_drvdata(filp);
746
747 zc0301_stop_transfer(cam);
748 zc0301_release_buffers(cam);
749 cam->users--;
750 wake_up_interruptible_nr(&cam->wait_open, 1);
751
752 DBG(3, "Video device %s closed",
753 video_device_node_name(cam->v4ldev));
754
755 kref_put(&cam->kref, zc0301_release_resources);
756
757 up_write(&zc0301_dev_lock);
758
759 return 0;
760}
761
762
763static ssize_t
764zc0301_read(struct file* filp, char __user * buf, size_t count, loff_t* f_pos)
765{
766 struct zc0301_device *cam = video_drvdata(filp);
767 struct zc0301_frame_t* f, * i;
768 unsigned long lock_flags;
769 long timeout;
770 int err = 0;
771
772 if (mutex_lock_interruptible(&cam->fileop_mutex))
773 return -ERESTARTSYS;
774
775 if (cam->state & DEV_DISCONNECTED) {
776 DBG(1, "Device not present");
777 mutex_unlock(&cam->fileop_mutex);
778 return -ENODEV;
779 }
780
781 if (cam->state & DEV_MISCONFIGURED) {
782 DBG(1, "The camera is misconfigured. Close and open it "
783 "again.");
784 mutex_unlock(&cam->fileop_mutex);
785 return -EIO;
786 }
787
788 if (cam->io == IO_MMAP) {
789 DBG(3, "Close and open the device again to choose the read "
790 "method");
791 mutex_unlock(&cam->fileop_mutex);
792 return -EBUSY;
793 }
794
795 if (cam->io == IO_NONE) {
796 if (!zc0301_request_buffers(cam, cam->nreadbuffers, IO_READ)) {
797 DBG(1, "read() failed, not enough memory");
798 mutex_unlock(&cam->fileop_mutex);
799 return -ENOMEM;
800 }
801 cam->io = IO_READ;
802 cam->stream = STREAM_ON;
803 }
804
805 if (list_empty(&cam->inqueue)) {
806 if (!list_empty(&cam->outqueue))
807 zc0301_empty_framequeues(cam);
808 zc0301_queue_unusedframes(cam);
809 }
810
811 if (!count) {
812 mutex_unlock(&cam->fileop_mutex);
813 return 0;
814 }
815
816 if (list_empty(&cam->outqueue)) {
817 if (filp->f_flags & O_NONBLOCK) {
818 mutex_unlock(&cam->fileop_mutex);
819 return -EAGAIN;
820 }
821 timeout = wait_event_interruptible_timeout
822 ( cam->wait_frame,
823 (!list_empty(&cam->outqueue)) ||
824 (cam->state & DEV_DISCONNECTED) ||
825 (cam->state & DEV_MISCONFIGURED),
826 msecs_to_jiffies(
827 cam->module_param.frame_timeout * 1000
828 )
829 );
830 if (timeout < 0) {
831 mutex_unlock(&cam->fileop_mutex);
832 return timeout;
833 }
834 if (cam->state & DEV_DISCONNECTED) {
835 mutex_unlock(&cam->fileop_mutex);
836 return -ENODEV;
837 }
838 if (!timeout || (cam->state & DEV_MISCONFIGURED)) {
839 mutex_unlock(&cam->fileop_mutex);
840 return -EIO;
841 }
842 }
843
844 f = list_entry(cam->outqueue.prev, struct zc0301_frame_t, frame);
845
846 if (count > f->buf.bytesused)
847 count = f->buf.bytesused;
848
849 if (copy_to_user(buf, f->bufmem, count)) {
850 err = -EFAULT;
851 goto exit;
852 }
853 *f_pos += count;
854
855exit:
856 spin_lock_irqsave(&cam->queue_lock, lock_flags);
857 list_for_each_entry(i, &cam->outqueue, frame)
858 i->state = F_UNUSED;
859 INIT_LIST_HEAD(&cam->outqueue);
860 spin_unlock_irqrestore(&cam->queue_lock, lock_flags);
861
862 zc0301_queue_unusedframes(cam);
863
864 PDBGG("Frame #%lu, bytes read: %zu",
865 (unsigned long)f->buf.index, count);
866
867 mutex_unlock(&cam->fileop_mutex);
868
869 return err ? err : count;
870}
871
872
873static unsigned int zc0301_poll(struct file *filp, poll_table *wait)
874{
875 struct zc0301_device *cam = video_drvdata(filp);
876 struct zc0301_frame_t* f;
877 unsigned long lock_flags;
878 unsigned int mask = 0;
879
880 if (mutex_lock_interruptible(&cam->fileop_mutex))
881 return POLLERR;
882
883 if (cam->state & DEV_DISCONNECTED) {
884 DBG(1, "Device not present");
885 goto error;
886 }
887
888 if (cam->state & DEV_MISCONFIGURED) {
889 DBG(1, "The camera is misconfigured. Close and open it "
890 "again.");
891 goto error;
892 }
893
894 if (cam->io == IO_NONE) {
895 if (!zc0301_request_buffers(cam, cam->nreadbuffers, IO_READ)) {
896 DBG(1, "poll() failed, not enough memory");
897 goto error;
898 }
899 cam->io = IO_READ;
900 cam->stream = STREAM_ON;
901 }
902
903 if (cam->io == IO_READ) {
904 spin_lock_irqsave(&cam->queue_lock, lock_flags);
905 list_for_each_entry(f, &cam->outqueue, frame)
906 f->state = F_UNUSED;
907 INIT_LIST_HEAD(&cam->outqueue);
908 spin_unlock_irqrestore(&cam->queue_lock, lock_flags);
909 zc0301_queue_unusedframes(cam);
910 }
911
912 poll_wait(filp, &cam->wait_frame, wait);
913
914 if (!list_empty(&cam->outqueue))
915 mask |= POLLIN | POLLRDNORM;
916
917 mutex_unlock(&cam->fileop_mutex);
918
919 return mask;
920
921error:
922 mutex_unlock(&cam->fileop_mutex);
923 return POLLERR;
924}
925
926
927static void zc0301_vm_open(struct vm_area_struct* vma)
928{
929 struct zc0301_frame_t* f = vma->vm_private_data;
930 f->vma_use_count++;
931}
932
933
934static void zc0301_vm_close(struct vm_area_struct* vma)
935{
936 /* NOTE: buffers are not freed here */
937 struct zc0301_frame_t* f = vma->vm_private_data;
938 f->vma_use_count--;
939}
940
941
942static const struct vm_operations_struct zc0301_vm_ops = {
943 .open = zc0301_vm_open,
944 .close = zc0301_vm_close,
945};
946
947
948static int zc0301_mmap(struct file* filp, struct vm_area_struct *vma)
949{
950 struct zc0301_device *cam = video_drvdata(filp);
951 unsigned long size = vma->vm_end - vma->vm_start,
952 start = vma->vm_start;
953 void *pos;
954 u32 i;
955
956 if (mutex_lock_interruptible(&cam->fileop_mutex))
957 return -ERESTARTSYS;
958
959 if (cam->state & DEV_DISCONNECTED) {
960 DBG(1, "Device not present");
961 mutex_unlock(&cam->fileop_mutex);
962 return -ENODEV;
963 }
964
965 if (cam->state & DEV_MISCONFIGURED) {
966 DBG(1, "The camera is misconfigured. Close and open it "
967 "again.");
968 mutex_unlock(&cam->fileop_mutex);
969 return -EIO;
970 }
971
972 if (!(vma->vm_flags & (VM_WRITE | VM_READ))) {
973 mutex_unlock(&cam->fileop_mutex);
974 return -EACCES;
975 }
976
977 if (cam->io != IO_MMAP ||
978 size != PAGE_ALIGN(cam->frame[0].buf.length)) {
979 mutex_unlock(&cam->fileop_mutex);
980 return -EINVAL;
981 }
982
983 for (i = 0; i < cam->nbuffers; i++) {
984 if ((cam->frame[i].buf.m.offset>>PAGE_SHIFT) == vma->vm_pgoff)
985 break;
986 }
987 if (i == cam->nbuffers) {
988 mutex_unlock(&cam->fileop_mutex);
989 return -EINVAL;
990 }
991
992 vma->vm_flags |= VM_IO;
993 vma->vm_flags |= VM_RESERVED;
994
995 pos = cam->frame[i].bufmem;
996 while (size > 0) { /* size is page-aligned */
997 if (vm_insert_page(vma, start, vmalloc_to_page(pos))) {
998 mutex_unlock(&cam->fileop_mutex);
999 return -EAGAIN;
1000 }
1001 start += PAGE_SIZE;
1002 pos += PAGE_SIZE;
1003 size -= PAGE_SIZE;
1004 }
1005
1006 vma->vm_ops = &zc0301_vm_ops;
1007 vma->vm_private_data = &cam->frame[i];
1008 zc0301_vm_open(vma);
1009
1010 mutex_unlock(&cam->fileop_mutex);
1011
1012 return 0;
1013}
1014
1015/*****************************************************************************/
1016
1017static int
1018zc0301_vidioc_querycap(struct zc0301_device* cam, void __user * arg)
1019{
1020 struct v4l2_capability cap = {
1021 .driver = "zc0301",
1022 .version = ZC0301_MODULE_VERSION_CODE,
1023 .capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE |
1024 V4L2_CAP_STREAMING,
1025 };
1026
1027 strlcpy(cap.card, cam->v4ldev->name, sizeof(cap.card));
1028 if (usb_make_path(cam->usbdev, cap.bus_info, sizeof(cap.bus_info)) < 0)
1029 strlcpy(cap.bus_info, dev_name(&cam->usbdev->dev),
1030 sizeof(cap.bus_info));
1031
1032 if (copy_to_user(arg, &cap, sizeof(cap)))
1033 return -EFAULT;
1034
1035 return 0;
1036}
1037
1038
1039static int
1040zc0301_vidioc_enuminput(struct zc0301_device* cam, void __user * arg)
1041{
1042 struct v4l2_input i;
1043
1044 if (copy_from_user(&i, arg, sizeof(i)))
1045 return -EFAULT;
1046
1047 if (i.index)
1048 return -EINVAL;
1049
1050 memset(&i, 0, sizeof(i));
1051 strcpy(i.name, "Camera");
1052 i.type = V4L2_INPUT_TYPE_CAMERA;
1053
1054 if (copy_to_user(arg, &i, sizeof(i)))
1055 return -EFAULT;
1056
1057 return 0;
1058}
1059
1060
1061static int
1062zc0301_vidioc_g_input(struct zc0301_device* cam, void __user * arg)
1063{
1064 int index = 0;
1065
1066 if (copy_to_user(arg, &index, sizeof(index)))
1067 return -EFAULT;
1068
1069 return 0;
1070}
1071
1072
1073static int
1074zc0301_vidioc_s_input(struct zc0301_device* cam, void __user * arg)
1075{
1076 int index;
1077
1078 if (copy_from_user(&index, arg, sizeof(index)))
1079 return -EFAULT;
1080
1081 if (index != 0)
1082 return -EINVAL;
1083
1084 return 0;
1085}
1086
1087
1088static int
1089zc0301_vidioc_query_ctrl(struct zc0301_device* cam, void __user * arg)
1090{
1091 struct zc0301_sensor* s = &cam->sensor;
1092 struct v4l2_queryctrl qc;
1093 u8 i;
1094
1095 if (copy_from_user(&qc, arg, sizeof(qc)))
1096 return -EFAULT;
1097
1098 for (i = 0; i < ARRAY_SIZE(s->qctrl); i++)
1099 if (qc.id && qc.id == s->qctrl[i].id) {
1100 memcpy(&qc, &(s->qctrl[i]), sizeof(qc));
1101 if (copy_to_user(arg, &qc, sizeof(qc)))
1102 return -EFAULT;
1103 return 0;
1104 }
1105
1106 return -EINVAL;
1107}
1108
1109
1110static int
1111zc0301_vidioc_g_ctrl(struct zc0301_device* cam, void __user * arg)
1112{
1113 struct zc0301_sensor* s = &cam->sensor;
1114 struct v4l2_control ctrl;
1115 int err = 0;
1116 u8 i;
1117
1118 if (!s->get_ctrl && !s->set_ctrl)
1119 return -EINVAL;
1120
1121 if (copy_from_user(&ctrl, arg, sizeof(ctrl)))
1122 return -EFAULT;
1123
1124 if (!s->get_ctrl) {
1125 for (i = 0; i < ARRAY_SIZE(s->qctrl); i++)
1126 if (ctrl.id == s->qctrl[i].id) {
1127 ctrl.value = s->_qctrl[i].default_value;
1128 goto exit;
1129 }
1130 return -EINVAL;
1131 } else
1132 err = s->get_ctrl(cam, &ctrl);
1133
1134exit:
1135 if (copy_to_user(arg, &ctrl, sizeof(ctrl)))
1136 return -EFAULT;
1137
1138 return err;
1139}
1140
1141
1142static int
1143zc0301_vidioc_s_ctrl(struct zc0301_device* cam, void __user * arg)
1144{
1145 struct zc0301_sensor* s = &cam->sensor;
1146 struct v4l2_control ctrl;
1147 u8 i;
1148 int err = 0;
1149
1150 if (!s->set_ctrl)
1151 return -EINVAL;
1152
1153 if (copy_from_user(&ctrl, arg, sizeof(ctrl)))
1154 return -EFAULT;
1155
1156 for (i = 0; i < ARRAY_SIZE(s->qctrl); i++) {
1157 if (ctrl.id == s->qctrl[i].id) {
1158 if (s->qctrl[i].flags & V4L2_CTRL_FLAG_DISABLED)
1159 return -EINVAL;
1160 if (ctrl.value < s->qctrl[i].minimum ||
1161 ctrl.value > s->qctrl[i].maximum)
1162 return -ERANGE;
1163 ctrl.value -= ctrl.value % s->qctrl[i].step;
1164 break;
1165 }
1166 }
1167 if (i == ARRAY_SIZE(s->qctrl))
1168 return -EINVAL;
1169 if ((err = s->set_ctrl(cam, &ctrl)))
1170 return err;
1171
1172 s->_qctrl[i].default_value = ctrl.value;
1173
1174 return 0;
1175}
1176
1177
1178static int
1179zc0301_vidioc_cropcap(struct zc0301_device* cam, void __user * arg)
1180{
1181 struct v4l2_cropcap* cc = &(cam->sensor.cropcap);
1182
1183 cc->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1184 cc->pixelaspect.numerator = 1;
1185 cc->pixelaspect.denominator = 1;
1186
1187 if (copy_to_user(arg, cc, sizeof(*cc)))
1188 return -EFAULT;
1189
1190 return 0;
1191}
1192
1193
1194static int
1195zc0301_vidioc_g_crop(struct zc0301_device* cam, void __user * arg)
1196{
1197 struct zc0301_sensor* s = &cam->sensor;
1198 struct v4l2_crop crop = {
1199 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
1200 };
1201
1202 memcpy(&(crop.c), &(s->_rect), sizeof(struct v4l2_rect));
1203
1204 if (copy_to_user(arg, &crop, sizeof(crop)))
1205 return -EFAULT;
1206
1207 return 0;
1208}
1209
1210
1211static int
1212zc0301_vidioc_s_crop(struct zc0301_device* cam, void __user * arg)
1213{
1214 struct zc0301_sensor* s = &cam->sensor;
1215 struct v4l2_crop crop;
1216 struct v4l2_rect* rect;
1217 struct v4l2_rect* bounds = &(s->cropcap.bounds);
1218 const enum zc0301_stream_state stream = cam->stream;
1219 const u32 nbuffers = cam->nbuffers;
1220 u32 i;
1221 int err = 0;
1222
1223 if (copy_from_user(&crop, arg, sizeof(crop)))
1224 return -EFAULT;
1225
1226 rect = &(crop.c);
1227
1228 if (crop.type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1229 return -EINVAL;
1230
1231 if (cam->module_param.force_munmap)
1232 for (i = 0; i < cam->nbuffers; i++)
1233 if (cam->frame[i].vma_use_count) {
1234 DBG(3, "VIDIOC_S_CROP failed. "
1235 "Unmap the buffers first.");
1236 return -EBUSY;
1237 }
1238
1239 if (!s->set_crop) {
1240 memcpy(rect, &(s->_rect), sizeof(*rect));
1241 if (copy_to_user(arg, &crop, sizeof(crop)))
1242 return -EFAULT;
1243 return 0;
1244 }
1245
1246 rect->left &= ~7L;
1247 rect->top &= ~7L;
1248 if (rect->width < 8)
1249 rect->width = 8;
1250 if (rect->height < 8)
1251 rect->height = 8;
1252 if (rect->width > bounds->width)
1253 rect->width = bounds->width;
1254 if (rect->height > bounds->height)
1255 rect->height = bounds->height;
1256 if (rect->left < bounds->left)
1257 rect->left = bounds->left;
1258 if (rect->top < bounds->top)
1259 rect->top = bounds->top;
1260 if (rect->left + rect->width > bounds->left + bounds->width)
1261 rect->left = bounds->left+bounds->width - rect->width;
1262 if (rect->top + rect->height > bounds->top + bounds->height)
1263 rect->top = bounds->top+bounds->height - rect->height;
1264 rect->width &= ~7L;
1265 rect->height &= ~7L;
1266
1267 if (cam->stream == STREAM_ON)
1268 if ((err = zc0301_stream_interrupt(cam)))
1269 return err;
1270
1271 if (copy_to_user(arg, &crop, sizeof(crop))) {
1272 cam->stream = stream;
1273 return -EFAULT;
1274 }
1275
1276 if (cam->module_param.force_munmap || cam->io == IO_READ)
1277 zc0301_release_buffers(cam);
1278
1279 if (s->set_crop)
1280 err += s->set_crop(cam, rect);
1281
1282 if (err) { /* atomic, no rollback in ioctl() */
1283 cam->state |= DEV_MISCONFIGURED;
1284 DBG(1, "VIDIOC_S_CROP failed because of hardware problems. To "
1285 "use the camera, close and open %s again.",
1286 video_device_node_name(cam->v4ldev));
1287 return -EIO;
1288 }
1289
1290 s->pix_format.width = rect->width;
1291 s->pix_format.height = rect->height;
1292 memcpy(&(s->_rect), rect, sizeof(*rect));
1293
1294 if ((cam->module_param.force_munmap || cam->io == IO_READ) &&
1295 nbuffers != zc0301_request_buffers(cam, nbuffers, cam->io)) {
1296 cam->state |= DEV_MISCONFIGURED;
1297 DBG(1, "VIDIOC_S_CROP failed because of not enough memory. To "
1298 "use the camera, close and open %s again.",
1299 video_device_node_name(cam->v4ldev));
1300 return -ENOMEM;
1301 }
1302
1303 if (cam->io == IO_READ)
1304 zc0301_empty_framequeues(cam);
1305 else if (cam->module_param.force_munmap)
1306 zc0301_requeue_outqueue(cam);
1307
1308 cam->stream = stream;
1309
1310 return 0;
1311}
1312
1313
1314static int
1315zc0301_vidioc_enum_framesizes(struct zc0301_device* cam, void __user * arg)
1316{
1317 struct v4l2_frmsizeenum frmsize;
1318
1319 if (copy_from_user(&frmsize, arg, sizeof(frmsize)))
1320 return -EFAULT;
1321
1322 if (frmsize.index != 0 && frmsize.index != 1)
1323 return -EINVAL;
1324
1325 if (frmsize.pixel_format != V4L2_PIX_FMT_JPEG)
1326 return -EINVAL;
1327
1328 frmsize.type = V4L2_FRMSIZE_TYPE_DISCRETE;
1329
1330 if (frmsize.index == 1) {
1331 frmsize.discrete.width = cam->sensor.cropcap.defrect.width;
1332 frmsize.discrete.height = cam->sensor.cropcap.defrect.height;
1333 }
1334 memset(&frmsize.reserved, 0, sizeof(frmsize.reserved));
1335
1336 if (copy_to_user(arg, &frmsize, sizeof(frmsize)))
1337 return -EFAULT;
1338
1339 return 0;
1340}
1341
1342
1343static int
1344zc0301_vidioc_enum_fmt(struct zc0301_device* cam, void __user * arg)
1345{
1346 struct v4l2_fmtdesc fmtd;
1347
1348 if (copy_from_user(&fmtd, arg, sizeof(fmtd)))
1349 return -EFAULT;
1350
1351 if (fmtd.type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1352 return -EINVAL;
1353
1354 if (fmtd.index == 0) {
1355 strcpy(fmtd.description, "JPEG");
1356 fmtd.pixelformat = V4L2_PIX_FMT_JPEG;
1357 fmtd.flags = V4L2_FMT_FLAG_COMPRESSED;
1358 } else
1359 return -EINVAL;
1360
1361 fmtd.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1362 memset(&fmtd.reserved, 0, sizeof(fmtd.reserved));
1363
1364 if (copy_to_user(arg, &fmtd, sizeof(fmtd)))
1365 return -EFAULT;
1366
1367 return 0;
1368}
1369
1370
1371static int
1372zc0301_vidioc_g_fmt(struct zc0301_device* cam, void __user * arg)
1373{
1374 struct v4l2_format format;
1375 struct v4l2_pix_format* pfmt = &(cam->sensor.pix_format);
1376
1377 if (copy_from_user(&format, arg, sizeof(format)))
1378 return -EFAULT;
1379
1380 if (format.type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1381 return -EINVAL;
1382
1383 pfmt->bytesperline = 0;
1384 pfmt->sizeimage = pfmt->height * ((pfmt->width*pfmt->priv)/8);
1385 pfmt->field = V4L2_FIELD_NONE;
1386 memcpy(&(format.fmt.pix), pfmt, sizeof(*pfmt));
1387
1388 if (copy_to_user(arg, &format, sizeof(format)))
1389 return -EFAULT;
1390
1391 return 0;
1392}
1393
1394
1395static int
1396zc0301_vidioc_try_s_fmt(struct zc0301_device* cam, unsigned int cmd,
1397 void __user * arg)
1398{
1399 struct zc0301_sensor* s = &cam->sensor;
1400 struct v4l2_format format;
1401 struct v4l2_pix_format* pix;
1402 struct v4l2_pix_format* pfmt = &(s->pix_format);
1403 struct v4l2_rect* bounds = &(s->cropcap.bounds);
1404 struct v4l2_rect rect;
1405 const enum zc0301_stream_state stream = cam->stream;
1406 const u32 nbuffers = cam->nbuffers;
1407 u32 i;
1408 int err = 0;
1409
1410 if (copy_from_user(&format, arg, sizeof(format)))
1411 return -EFAULT;
1412
1413 pix = &(format.fmt.pix);
1414
1415 if (format.type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1416 return -EINVAL;
1417
1418 memcpy(&rect, &(s->_rect), sizeof(rect));
1419
1420 if (!s->set_crop) {
1421 pix->width = rect.width;
1422 pix->height = rect.height;
1423 } else {
1424 rect.width = pix->width;
1425 rect.height = pix->height;
1426 }
1427
1428 if (rect.width < 8)
1429 rect.width = 8;
1430 if (rect.height < 8)
1431 rect.height = 8;
1432 if (rect.width > bounds->left + bounds->width - rect.left)
1433 rect.width = bounds->left + bounds->width - rect.left;
1434 if (rect.height > bounds->top + bounds->height - rect.top)
1435 rect.height = bounds->top + bounds->height - rect.top;
1436 rect.width &= ~7L;
1437 rect.height &= ~7L;
1438
1439 pix->width = rect.width;
1440 pix->height = rect.height;
1441 pix->pixelformat = pfmt->pixelformat;
1442 pix->priv = pfmt->priv;
1443 pix->colorspace = pfmt->colorspace;
1444 pix->bytesperline = 0;
1445 pix->sizeimage = pix->height * ((pix->width * pix->priv) / 8);
1446 pix->field = V4L2_FIELD_NONE;
1447
1448 if (cmd == VIDIOC_TRY_FMT) {
1449 if (copy_to_user(arg, &format, sizeof(format)))
1450 return -EFAULT;
1451 return 0;
1452 }
1453
1454 if (cam->module_param.force_munmap)
1455 for (i = 0; i < cam->nbuffers; i++)
1456 if (cam->frame[i].vma_use_count) {
1457 DBG(3, "VIDIOC_S_FMT failed. "
1458 "Unmap the buffers first.");
1459 return -EBUSY;
1460 }
1461
1462 if (cam->stream == STREAM_ON)
1463 if ((err = zc0301_stream_interrupt(cam)))
1464 return err;
1465
1466 if (copy_to_user(arg, &format, sizeof(format))) {
1467 cam->stream = stream;
1468 return -EFAULT;
1469 }
1470
1471 if (cam->module_param.force_munmap || cam->io == IO_READ)
1472 zc0301_release_buffers(cam);
1473
1474 if (s->set_crop)
1475 err += s->set_crop(cam, &rect);
1476
1477 if (err) { /* atomic, no rollback in ioctl() */
1478 cam->state |= DEV_MISCONFIGURED;
1479 DBG(1, "VIDIOC_S_FMT failed because of hardware problems. To "
1480 "use the camera, close and open %s again.",
1481 video_device_node_name(cam->v4ldev));
1482 return -EIO;
1483 }
1484
1485 memcpy(pfmt, pix, sizeof(*pix));
1486 memcpy(&(s->_rect), &rect, sizeof(rect));
1487
1488 if ((cam->module_param.force_munmap || cam->io == IO_READ) &&
1489 nbuffers != zc0301_request_buffers(cam, nbuffers, cam->io)) {
1490 cam->state |= DEV_MISCONFIGURED;
1491 DBG(1, "VIDIOC_S_FMT failed because of not enough memory. To "
1492 "use the camera, close and open %s again.",
1493 video_device_node_name(cam->v4ldev));
1494 return -ENOMEM;
1495 }
1496
1497 if (cam->io == IO_READ)
1498 zc0301_empty_framequeues(cam);
1499 else if (cam->module_param.force_munmap)
1500 zc0301_requeue_outqueue(cam);
1501
1502 cam->stream = stream;
1503
1504 return 0;
1505}
1506
1507
1508static int
1509zc0301_vidioc_g_jpegcomp(struct zc0301_device* cam, void __user * arg)
1510{
1511 if (copy_to_user(arg, &cam->compression, sizeof(cam->compression)))
1512 return -EFAULT;
1513
1514 return 0;
1515}
1516
1517
1518static int
1519zc0301_vidioc_s_jpegcomp(struct zc0301_device* cam, void __user * arg)
1520{
1521 struct v4l2_jpegcompression jc;
1522 const enum zc0301_stream_state stream = cam->stream;
1523 int err = 0;
1524
1525 if (copy_from_user(&jc, arg, sizeof(jc)))
1526 return -EFAULT;
1527
1528 if (jc.quality != 0)
1529 return -EINVAL;
1530
1531 if (cam->stream == STREAM_ON)
1532 if ((err = zc0301_stream_interrupt(cam)))
1533 return err;
1534
1535 err += zc0301_set_compression(cam, &jc);
1536 if (err) { /* atomic, no rollback in ioctl() */
1537 cam->state |= DEV_MISCONFIGURED;
1538 DBG(1, "VIDIOC_S_JPEGCOMP failed because of hardware "
1539 "problems. To use the camera, close and open %s again.",
1540 video_device_node_name(cam->v4ldev));
1541 return -EIO;
1542 }
1543
1544 cam->compression.quality = jc.quality;
1545
1546 cam->stream = stream;
1547
1548 return 0;
1549}
1550
1551
1552static int
1553zc0301_vidioc_reqbufs(struct zc0301_device* cam, void __user * arg)
1554{
1555 struct v4l2_requestbuffers rb;
1556 u32 i;
1557 int err;
1558
1559 if (copy_from_user(&rb, arg, sizeof(rb)))
1560 return -EFAULT;
1561
1562 if (rb.type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
1563 rb.memory != V4L2_MEMORY_MMAP)
1564 return -EINVAL;
1565
1566 if (cam->io == IO_READ) {
1567 DBG(3, "Close and open the device again to choose the mmap "
1568 "I/O method");
1569 return -EBUSY;
1570 }
1571
1572 for (i = 0; i < cam->nbuffers; i++)
1573 if (cam->frame[i].vma_use_count) {
1574 DBG(3, "VIDIOC_REQBUFS failed. "
1575 "Previous buffers are still mapped.");
1576 return -EBUSY;
1577 }
1578
1579 if (cam->stream == STREAM_ON)
1580 if ((err = zc0301_stream_interrupt(cam)))
1581 return err;
1582
1583 zc0301_empty_framequeues(cam);
1584
1585 zc0301_release_buffers(cam);
1586 if (rb.count)
1587 rb.count = zc0301_request_buffers(cam, rb.count, IO_MMAP);
1588
1589 if (copy_to_user(arg, &rb, sizeof(rb))) {
1590 zc0301_release_buffers(cam);
1591 cam->io = IO_NONE;
1592 return -EFAULT;
1593 }
1594
1595 cam->io = rb.count ? IO_MMAP : IO_NONE;
1596
1597 return 0;
1598}
1599
1600
1601static int
1602zc0301_vidioc_querybuf(struct zc0301_device* cam, void __user * arg)
1603{
1604 struct v4l2_buffer b;
1605
1606 if (copy_from_user(&b, arg, sizeof(b)))
1607 return -EFAULT;
1608
1609 if (b.type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
1610 b.index >= cam->nbuffers || cam->io != IO_MMAP)
1611 return -EINVAL;
1612
1613 memcpy(&b, &cam->frame[b.index].buf, sizeof(b));
1614
1615 if (cam->frame[b.index].vma_use_count)
1616 b.flags |= V4L2_BUF_FLAG_MAPPED;
1617
1618 if (cam->frame[b.index].state == F_DONE)
1619 b.flags |= V4L2_BUF_FLAG_DONE;
1620 else if (cam->frame[b.index].state != F_UNUSED)
1621 b.flags |= V4L2_BUF_FLAG_QUEUED;
1622
1623 if (copy_to_user(arg, &b, sizeof(b)))
1624 return -EFAULT;
1625
1626 return 0;
1627}
1628
1629
1630static int
1631zc0301_vidioc_qbuf(struct zc0301_device* cam, void __user * arg)
1632{
1633 struct v4l2_buffer b;
1634 unsigned long lock_flags;
1635
1636 if (copy_from_user(&b, arg, sizeof(b)))
1637 return -EFAULT;
1638
1639 if (b.type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
1640 b.index >= cam->nbuffers || cam->io != IO_MMAP)
1641 return -EINVAL;
1642
1643 if (cam->frame[b.index].state != F_UNUSED)
1644 return -EINVAL;
1645
1646 cam->frame[b.index].state = F_QUEUED;
1647
1648 spin_lock_irqsave(&cam->queue_lock, lock_flags);
1649 list_add_tail(&cam->frame[b.index].frame, &cam->inqueue);
1650 spin_unlock_irqrestore(&cam->queue_lock, lock_flags);
1651
1652 PDBGG("Frame #%lu queued", (unsigned long)b.index);
1653
1654 return 0;
1655}
1656
1657
1658static int
1659zc0301_vidioc_dqbuf(struct zc0301_device* cam, struct file* filp,
1660 void __user * arg)
1661{
1662 struct v4l2_buffer b;
1663 struct zc0301_frame_t *f;
1664 unsigned long lock_flags;
1665 long timeout;
1666
1667 if (copy_from_user(&b, arg, sizeof(b)))
1668 return -EFAULT;
1669
1670 if (b.type != V4L2_BUF_TYPE_VIDEO_CAPTURE || cam->io!= IO_MMAP)
1671 return -EINVAL;
1672
1673 if (list_empty(&cam->outqueue)) {
1674 if (cam->stream == STREAM_OFF)
1675 return -EINVAL;
1676 if (filp->f_flags & O_NONBLOCK)
1677 return -EAGAIN;
1678 timeout = wait_event_interruptible_timeout
1679 ( cam->wait_frame,
1680 (!list_empty(&cam->outqueue)) ||
1681 (cam->state & DEV_DISCONNECTED) ||
1682 (cam->state & DEV_MISCONFIGURED),
1683 cam->module_param.frame_timeout *
1684 1000 * msecs_to_jiffies(1) );
1685 if (timeout < 0)
1686 return timeout;
1687 if (cam->state & DEV_DISCONNECTED)
1688 return -ENODEV;
1689 if (!timeout || (cam->state & DEV_MISCONFIGURED))
1690 return -EIO;
1691 }
1692
1693 spin_lock_irqsave(&cam->queue_lock, lock_flags);
1694 f = list_entry(cam->outqueue.next, struct zc0301_frame_t, frame);
1695 list_del(cam->outqueue.next);
1696 spin_unlock_irqrestore(&cam->queue_lock, lock_flags);
1697
1698 f->state = F_UNUSED;
1699
1700 memcpy(&b, &f->buf, sizeof(b));
1701 if (f->vma_use_count)
1702 b.flags |= V4L2_BUF_FLAG_MAPPED;
1703
1704 if (copy_to_user(arg, &b, sizeof(b)))
1705 return -EFAULT;
1706
1707 PDBGG("Frame #%lu dequeued", (unsigned long)f->buf.index);
1708
1709 return 0;
1710}
1711
1712
1713static int
1714zc0301_vidioc_streamon(struct zc0301_device* cam, void __user * arg)
1715{
1716 int type;
1717
1718 if (copy_from_user(&type, arg, sizeof(type)))
1719 return -EFAULT;
1720
1721 if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE || cam->io != IO_MMAP)
1722 return -EINVAL;
1723
1724 cam->stream = STREAM_ON;
1725
1726 DBG(3, "Stream on");
1727
1728 return 0;
1729}
1730
1731
1732static int
1733zc0301_vidioc_streamoff(struct zc0301_device* cam, void __user * arg)
1734{
1735 int type, err;
1736
1737 if (copy_from_user(&type, arg, sizeof(type)))
1738 return -EFAULT;
1739
1740 if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE || cam->io != IO_MMAP)
1741 return -EINVAL;
1742
1743 if (cam->stream == STREAM_ON)
1744 if ((err = zc0301_stream_interrupt(cam)))
1745 return err;
1746
1747 zc0301_empty_framequeues(cam);
1748
1749 DBG(3, "Stream off");
1750
1751 return 0;
1752}
1753
1754
1755static int
1756zc0301_vidioc_g_parm(struct zc0301_device* cam, void __user * arg)
1757{
1758 struct v4l2_streamparm sp;
1759
1760 if (copy_from_user(&sp, arg, sizeof(sp)))
1761 return -EFAULT;
1762
1763 if (sp.type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1764 return -EINVAL;
1765
1766 sp.parm.capture.extendedmode = 0;
1767 sp.parm.capture.readbuffers = cam->nreadbuffers;
1768
1769 if (copy_to_user(arg, &sp, sizeof(sp)))
1770 return -EFAULT;
1771
1772 return 0;
1773}
1774
1775
1776static int
1777zc0301_vidioc_s_parm(struct zc0301_device* cam, void __user * arg)
1778{
1779 struct v4l2_streamparm sp;
1780
1781 if (copy_from_user(&sp, arg, sizeof(sp)))
1782 return -EFAULT;
1783
1784 if (sp.type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1785 return -EINVAL;
1786
1787 sp.parm.capture.extendedmode = 0;
1788
1789 if (sp.parm.capture.readbuffers == 0)
1790 sp.parm.capture.readbuffers = cam->nreadbuffers;
1791
1792 if (sp.parm.capture.readbuffers > ZC0301_MAX_FRAMES)
1793 sp.parm.capture.readbuffers = ZC0301_MAX_FRAMES;
1794
1795 if (copy_to_user(arg, &sp, sizeof(sp)))
1796 return -EFAULT;
1797
1798 cam->nreadbuffers = sp.parm.capture.readbuffers;
1799
1800 return 0;
1801}
1802
1803
1804static long zc0301_ioctl_v4l2(struct file *filp,
1805 unsigned int cmd, void __user *arg)
1806{
1807 struct zc0301_device *cam = video_drvdata(filp);
1808
1809 switch (cmd) {
1810
1811 case VIDIOC_QUERYCAP:
1812 return zc0301_vidioc_querycap(cam, arg);
1813
1814 case VIDIOC_ENUMINPUT:
1815 return zc0301_vidioc_enuminput(cam, arg);
1816
1817 case VIDIOC_G_INPUT:
1818 return zc0301_vidioc_g_input(cam, arg);
1819
1820 case VIDIOC_S_INPUT:
1821 return zc0301_vidioc_s_input(cam, arg);
1822
1823 case VIDIOC_QUERYCTRL:
1824 return zc0301_vidioc_query_ctrl(cam, arg);
1825
1826 case VIDIOC_G_CTRL:
1827 return zc0301_vidioc_g_ctrl(cam, arg);
1828
1829 case VIDIOC_S_CTRL:
1830 return zc0301_vidioc_s_ctrl(cam, arg);
1831
1832 case VIDIOC_CROPCAP:
1833 return zc0301_vidioc_cropcap(cam, arg);
1834
1835 case VIDIOC_G_CROP:
1836 return zc0301_vidioc_g_crop(cam, arg);
1837
1838 case VIDIOC_S_CROP:
1839 return zc0301_vidioc_s_crop(cam, arg);
1840
1841 case VIDIOC_ENUM_FMT:
1842 return zc0301_vidioc_enum_fmt(cam, arg);
1843
1844 case VIDIOC_G_FMT:
1845 return zc0301_vidioc_g_fmt(cam, arg);
1846
1847 case VIDIOC_TRY_FMT:
1848 case VIDIOC_S_FMT:
1849 return zc0301_vidioc_try_s_fmt(cam, cmd, arg);
1850
1851 case VIDIOC_ENUM_FRAMESIZES:
1852 return zc0301_vidioc_enum_framesizes(cam, arg);
1853
1854 case VIDIOC_G_JPEGCOMP:
1855 return zc0301_vidioc_g_jpegcomp(cam, arg);
1856
1857 case VIDIOC_S_JPEGCOMP:
1858 return zc0301_vidioc_s_jpegcomp(cam, arg);
1859
1860 case VIDIOC_REQBUFS:
1861 return zc0301_vidioc_reqbufs(cam, arg);
1862
1863 case VIDIOC_QUERYBUF:
1864 return zc0301_vidioc_querybuf(cam, arg);
1865
1866 case VIDIOC_QBUF:
1867 return zc0301_vidioc_qbuf(cam, arg);
1868
1869 case VIDIOC_DQBUF:
1870 return zc0301_vidioc_dqbuf(cam, filp, arg);
1871
1872 case VIDIOC_STREAMON:
1873 return zc0301_vidioc_streamon(cam, arg);
1874
1875 case VIDIOC_STREAMOFF:
1876 return zc0301_vidioc_streamoff(cam, arg);
1877
1878 case VIDIOC_G_PARM:
1879 return zc0301_vidioc_g_parm(cam, arg);
1880
1881 case VIDIOC_S_PARM:
1882 return zc0301_vidioc_s_parm(cam, arg);
1883
1884 case VIDIOC_G_STD:
1885 case VIDIOC_S_STD:
1886 case VIDIOC_QUERYSTD:
1887 case VIDIOC_ENUMSTD:
1888 case VIDIOC_QUERYMENU:
1889 case VIDIOC_ENUM_FRAMEINTERVALS:
1890 return -EINVAL;
1891
1892 default:
1893 return -EINVAL;
1894
1895 }
1896}
1897
1898
1899static long zc0301_ioctl(struct file *filp,
1900 unsigned int cmd, unsigned long arg)
1901{
1902 struct zc0301_device *cam = video_drvdata(filp);
1903 int err = 0;
1904
1905 if (mutex_lock_interruptible(&cam->fileop_mutex))
1906 return -ERESTARTSYS;
1907
1908 if (cam->state & DEV_DISCONNECTED) {
1909 DBG(1, "Device not present");
1910 mutex_unlock(&cam->fileop_mutex);
1911 return -ENODEV;
1912 }
1913
1914 if (cam->state & DEV_MISCONFIGURED) {
1915 DBG(1, "The camera is misconfigured. Close and open it "
1916 "again.");
1917 mutex_unlock(&cam->fileop_mutex);
1918 return -EIO;
1919 }
1920
1921 V4LDBG(3, "zc0301", cmd);
1922
1923 err = zc0301_ioctl_v4l2(filp, cmd, (void __user *)arg);
1924
1925 mutex_unlock(&cam->fileop_mutex);
1926
1927 return err;
1928}
1929
1930
1931static const struct v4l2_file_operations zc0301_fops = {
1932 .owner = THIS_MODULE,
1933 .open = zc0301_open,
1934 .release = zc0301_release,
1935 .ioctl = zc0301_ioctl,
1936 .read = zc0301_read,
1937 .poll = zc0301_poll,
1938 .mmap = zc0301_mmap,
1939};
1940
1941/*****************************************************************************/
1942
1943static int
1944zc0301_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
1945{
1946 struct usb_device *udev = interface_to_usbdev(intf);
1947 struct zc0301_device* cam;
1948 static unsigned int dev_nr;
1949 unsigned int i;
1950 int err = 0;
1951
1952 if (!(cam = kzalloc(sizeof(struct zc0301_device), GFP_KERNEL)))
1953 return -ENOMEM;
1954
1955 cam->usbdev = udev;
1956
1957 if (!(cam->control_buffer = kzalloc(4, GFP_KERNEL))) {
1958 DBG(1, "kmalloc() failed");
1959 err = -ENOMEM;
1960 goto fail;
1961 }
1962
1963 if (!(cam->v4ldev = video_device_alloc())) {
1964 DBG(1, "video_device_alloc() failed");
1965 err = -ENOMEM;
1966 goto fail;
1967 }
1968
1969 DBG(2, "ZC0301[P] Image Processor and Control Chip detected "
1970 "(vid/pid 0x%04X:0x%04X)",id->idVendor, id->idProduct);
1971
1972 for (i = 0; zc0301_sensor_table[i]; i++) {
1973 err = zc0301_sensor_table[i](cam);
1974 if (!err)
1975 break;
1976 }
1977
1978 if (!err)
1979 DBG(2, "%s image sensor detected", cam->sensor.name);
1980 else {
1981 DBG(1, "No supported image sensor detected");
1982 err = -ENODEV;
1983 goto fail;
1984 }
1985
1986 if (zc0301_init(cam)) {
1987 DBG(1, "Initialization failed. I will retry on open().");
1988 cam->state |= DEV_MISCONFIGURED;
1989 }
1990
1991 strcpy(cam->v4ldev->name, "ZC0301[P] PC Camera");
1992 cam->v4ldev->fops = &zc0301_fops;
1993 cam->v4ldev->release = video_device_release;
1994 cam->v4ldev->parent = &udev->dev;
1995 video_set_drvdata(cam->v4ldev, cam);
1996
1997 init_completion(&cam->probe);
1998
1999 err = video_register_device(cam->v4ldev, VFL_TYPE_GRABBER,
2000 video_nr[dev_nr]);
2001 if (err) {
2002 DBG(1, "V4L2 device registration failed");
2003 if (err == -ENFILE && video_nr[dev_nr] == -1)
2004 DBG(1, "Free /dev/videoX node not found");
2005 video_nr[dev_nr] = -1;
2006 dev_nr = (dev_nr < ZC0301_MAX_DEVICES-1) ? dev_nr+1 : 0;
2007 complete_all(&cam->probe);
2008 goto fail;
2009 }
2010
2011 DBG(2, "V4L2 device registered as %s",
2012 video_device_node_name(cam->v4ldev));
2013
2014 cam->module_param.force_munmap = force_munmap[dev_nr];
2015 cam->module_param.frame_timeout = frame_timeout[dev_nr];
2016
2017 dev_nr = (dev_nr < ZC0301_MAX_DEVICES-1) ? dev_nr+1 : 0;
2018
2019 usb_set_intfdata(intf, cam);
2020 kref_init(&cam->kref);
2021 usb_get_dev(cam->usbdev);
2022
2023 complete_all(&cam->probe);
2024
2025 return 0;
2026
2027fail:
2028 if (cam) {
2029 kfree(cam->control_buffer);
2030 if (cam->v4ldev)
2031 video_device_release(cam->v4ldev);
2032 kfree(cam);
2033 }
2034 return err;
2035}
2036
2037
2038static void zc0301_usb_disconnect(struct usb_interface* intf)
2039{
2040 struct zc0301_device* cam;
2041
2042 down_write(&zc0301_dev_lock);
2043
2044 cam = usb_get_intfdata(intf);
2045
2046 DBG(2, "Disconnecting %s...", cam->v4ldev->name);
2047
2048 if (cam->users) {
2049 DBG(2, "Device %s is open! Deregistration and "
2050 "memory deallocation are deferred.",
2051 video_device_node_name(cam->v4ldev));
2052 cam->state |= DEV_MISCONFIGURED;
2053 zc0301_stop_transfer(cam);
2054 cam->state |= DEV_DISCONNECTED;
2055 wake_up_interruptible(&cam->wait_frame);
2056 wake_up(&cam->wait_stream);
2057 } else
2058 cam->state |= DEV_DISCONNECTED;
2059
2060 wake_up_interruptible_all(&cam->wait_open);
2061
2062 kref_put(&cam->kref, zc0301_release_resources);
2063
2064 up_write(&zc0301_dev_lock);
2065}
2066
2067
2068static struct usb_driver zc0301_usb_driver = {
2069 .name = "zc0301",
2070 .id_table = zc0301_id_table,
2071 .probe = zc0301_usb_probe,
2072 .disconnect = zc0301_usb_disconnect,
2073};
2074
2075/*****************************************************************************/
2076
2077static int __init zc0301_module_init(void)
2078{
2079 int err = 0;
2080
2081 KDBG(2, ZC0301_MODULE_NAME " v" ZC0301_MODULE_VERSION);
2082 KDBG(3, ZC0301_MODULE_AUTHOR);
2083
2084 if ((err = usb_register(&zc0301_usb_driver)))
2085 KDBG(1, "usb_register() failed");
2086
2087 return err;
2088}
2089
2090
2091static void __exit zc0301_module_exit(void)
2092{
2093 usb_deregister(&zc0301_usb_driver);
2094}
2095
2096
2097module_init(zc0301_module_init);
2098module_exit(zc0301_module_exit);
diff --git a/drivers/media/video/zc0301/zc0301_pas202bcb.c b/drivers/media/video/zc0301/zc0301_pas202bcb.c
deleted file mode 100644
index 24b0dfba357e..000000000000
--- a/drivers/media/video/zc0301/zc0301_pas202bcb.c
+++ /dev/null
@@ -1,362 +0,0 @@
1/***************************************************************************
2 * Plug-in for PAS202BCB image sensor connected to the ZC0301 Image *
3 * Processor and Control Chip *
4 * *
5 * Copyright (C) 2006-2007 by Luca Risolia <luca.risolia@studio.unibo.it> *
6 * *
7 * Initialization values of the ZC0301[P] have been taken from the SPCA5XX *
8 * driver maintained by Michel Xhaard <mxhaard@magic.fr> *
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/*
26 NOTE: Sensor controls are disabled for now, becouse changing them while
27 streaming sometimes results in out-of-sync video frames. We'll use
28 the default initialization, until we know how to stop and start video
29 in the chip. However, the image quality still looks good under various
30 light conditions.
31*/
32
33#include <linux/delay.h>
34#include "zc0301_sensor.h"
35
36
37static struct zc0301_sensor pas202bcb;
38
39
40static int pas202bcb_init(struct zc0301_device* cam)
41{
42 int err = 0;
43
44 err += zc0301_write_reg(cam, 0x0002, 0x00);
45 err += zc0301_write_reg(cam, 0x0003, 0x02);
46 err += zc0301_write_reg(cam, 0x0004, 0x80);
47 err += zc0301_write_reg(cam, 0x0005, 0x01);
48 err += zc0301_write_reg(cam, 0x0006, 0xE0);
49 err += zc0301_write_reg(cam, 0x0098, 0x00);
50 err += zc0301_write_reg(cam, 0x009A, 0x03);
51 err += zc0301_write_reg(cam, 0x011A, 0x00);
52 err += zc0301_write_reg(cam, 0x011C, 0x03);
53 err += zc0301_write_reg(cam, 0x009B, 0x01);
54 err += zc0301_write_reg(cam, 0x009C, 0xE6);
55 err += zc0301_write_reg(cam, 0x009D, 0x02);
56 err += zc0301_write_reg(cam, 0x009E, 0x86);
57
58 err += zc0301_i2c_write(cam, 0x02, 0x02);
59 err += zc0301_i2c_write(cam, 0x0A, 0x01);
60 err += zc0301_i2c_write(cam, 0x0B, 0x01);
61 err += zc0301_i2c_write(cam, 0x0D, 0x00);
62 err += zc0301_i2c_write(cam, 0x12, 0x05);
63 err += zc0301_i2c_write(cam, 0x13, 0x63);
64 err += zc0301_i2c_write(cam, 0x15, 0x70);
65
66 err += zc0301_write_reg(cam, 0x0101, 0xB7);
67 err += zc0301_write_reg(cam, 0x0100, 0x0D);
68 err += zc0301_write_reg(cam, 0x0189, 0x06);
69 err += zc0301_write_reg(cam, 0x01AD, 0x00);
70 err += zc0301_write_reg(cam, 0x01C5, 0x03);
71 err += zc0301_write_reg(cam, 0x01CB, 0x13);
72 err += zc0301_write_reg(cam, 0x0250, 0x08);
73 err += zc0301_write_reg(cam, 0x0301, 0x08);
74 err += zc0301_write_reg(cam, 0x018D, 0x70);
75 err += zc0301_write_reg(cam, 0x0008, 0x03);
76 err += zc0301_write_reg(cam, 0x01C6, 0x04);
77 err += zc0301_write_reg(cam, 0x01CB, 0x07);
78 err += zc0301_write_reg(cam, 0x0120, 0x11);
79 err += zc0301_write_reg(cam, 0x0121, 0x37);
80 err += zc0301_write_reg(cam, 0x0122, 0x58);
81 err += zc0301_write_reg(cam, 0x0123, 0x79);
82 err += zc0301_write_reg(cam, 0x0124, 0x91);
83 err += zc0301_write_reg(cam, 0x0125, 0xA6);
84 err += zc0301_write_reg(cam, 0x0126, 0xB8);
85 err += zc0301_write_reg(cam, 0x0127, 0xC7);
86 err += zc0301_write_reg(cam, 0x0128, 0xD3);
87 err += zc0301_write_reg(cam, 0x0129, 0xDE);
88 err += zc0301_write_reg(cam, 0x012A, 0xE6);
89 err += zc0301_write_reg(cam, 0x012B, 0xED);
90 err += zc0301_write_reg(cam, 0x012C, 0xF3);
91 err += zc0301_write_reg(cam, 0x012D, 0xF8);
92 err += zc0301_write_reg(cam, 0x012E, 0xFB);
93 err += zc0301_write_reg(cam, 0x012F, 0xFF);
94 err += zc0301_write_reg(cam, 0x0130, 0x26);
95 err += zc0301_write_reg(cam, 0x0131, 0x23);
96 err += zc0301_write_reg(cam, 0x0132, 0x20);
97 err += zc0301_write_reg(cam, 0x0133, 0x1C);
98 err += zc0301_write_reg(cam, 0x0134, 0x16);
99 err += zc0301_write_reg(cam, 0x0135, 0x13);
100 err += zc0301_write_reg(cam, 0x0136, 0x10);
101 err += zc0301_write_reg(cam, 0x0137, 0x0D);
102 err += zc0301_write_reg(cam, 0x0138, 0x0B);
103 err += zc0301_write_reg(cam, 0x0139, 0x09);
104 err += zc0301_write_reg(cam, 0x013A, 0x07);
105 err += zc0301_write_reg(cam, 0x013B, 0x06);
106 err += zc0301_write_reg(cam, 0x013C, 0x05);
107 err += zc0301_write_reg(cam, 0x013D, 0x04);
108 err += zc0301_write_reg(cam, 0x013E, 0x03);
109 err += zc0301_write_reg(cam, 0x013F, 0x02);
110 err += zc0301_write_reg(cam, 0x010A, 0x4C);
111 err += zc0301_write_reg(cam, 0x010B, 0xF5);
112 err += zc0301_write_reg(cam, 0x010C, 0xFF);
113 err += zc0301_write_reg(cam, 0x010D, 0xF9);
114 err += zc0301_write_reg(cam, 0x010E, 0x51);
115 err += zc0301_write_reg(cam, 0x010F, 0xF5);
116 err += zc0301_write_reg(cam, 0x0110, 0xFB);
117 err += zc0301_write_reg(cam, 0x0111, 0xED);
118 err += zc0301_write_reg(cam, 0x0112, 0x5F);
119 err += zc0301_write_reg(cam, 0x0180, 0x00);
120 err += zc0301_write_reg(cam, 0x0019, 0x00);
121 err += zc0301_write_reg(cam, 0x0087, 0x20);
122 err += zc0301_write_reg(cam, 0x0088, 0x21);
123
124 err += zc0301_i2c_write(cam, 0x20, 0x02);
125 err += zc0301_i2c_write(cam, 0x21, 0x1B);
126 err += zc0301_i2c_write(cam, 0x03, 0x44);
127 err += zc0301_i2c_write(cam, 0x0E, 0x01);
128 err += zc0301_i2c_write(cam, 0x0F, 0x00);
129
130 err += zc0301_write_reg(cam, 0x01A9, 0x14);
131 err += zc0301_write_reg(cam, 0x01AA, 0x24);
132 err += zc0301_write_reg(cam, 0x0190, 0x00);
133 err += zc0301_write_reg(cam, 0x0191, 0x02);
134 err += zc0301_write_reg(cam, 0x0192, 0x1B);
135 err += zc0301_write_reg(cam, 0x0195, 0x00);
136 err += zc0301_write_reg(cam, 0x0196, 0x00);
137 err += zc0301_write_reg(cam, 0x0197, 0x4D);
138 err += zc0301_write_reg(cam, 0x018C, 0x10);
139 err += zc0301_write_reg(cam, 0x018F, 0x20);
140 err += zc0301_write_reg(cam, 0x001D, 0x44);
141 err += zc0301_write_reg(cam, 0x001E, 0x6F);
142 err += zc0301_write_reg(cam, 0x001F, 0xAD);
143 err += zc0301_write_reg(cam, 0x0020, 0xEB);
144 err += zc0301_write_reg(cam, 0x0087, 0x0F);
145 err += zc0301_write_reg(cam, 0x0088, 0x0E);
146 err += zc0301_write_reg(cam, 0x0180, 0x40);
147 err += zc0301_write_reg(cam, 0x0192, 0x1B);
148 err += zc0301_write_reg(cam, 0x0191, 0x02);
149 err += zc0301_write_reg(cam, 0x0190, 0x00);
150 err += zc0301_write_reg(cam, 0x0116, 0x1D);
151 err += zc0301_write_reg(cam, 0x0117, 0x40);
152 err += zc0301_write_reg(cam, 0x0118, 0x99);
153 err += zc0301_write_reg(cam, 0x0180, 0x42);
154 err += zc0301_write_reg(cam, 0x0116, 0x1D);
155 err += zc0301_write_reg(cam, 0x0117, 0x40);
156 err += zc0301_write_reg(cam, 0x0118, 0x99);
157 err += zc0301_write_reg(cam, 0x0007, 0x00);
158
159 err += zc0301_i2c_write(cam, 0x11, 0x01);
160
161 msleep(100);
162
163 return err;
164}
165
166
167static int pas202bcb_get_ctrl(struct zc0301_device* cam,
168 struct v4l2_control* ctrl)
169{
170 switch (ctrl->id) {
171 case V4L2_CID_EXPOSURE:
172 {
173 int r1 = zc0301_i2c_read(cam, 0x04, 1),
174 r2 = zc0301_i2c_read(cam, 0x05, 1);
175 if (r1 < 0 || r2 < 0)
176 return -EIO;
177 ctrl->value = (r1 << 6) | (r2 & 0x3f);
178 }
179 return 0;
180 case V4L2_CID_RED_BALANCE:
181 if ((ctrl->value = zc0301_i2c_read(cam, 0x09, 1)) < 0)
182 return -EIO;
183 ctrl->value &= 0x0f;
184 return 0;
185 case V4L2_CID_BLUE_BALANCE:
186 if ((ctrl->value = zc0301_i2c_read(cam, 0x07, 1)) < 0)
187 return -EIO;
188 ctrl->value &= 0x0f;
189 return 0;
190 case V4L2_CID_GAIN:
191 if ((ctrl->value = zc0301_i2c_read(cam, 0x10, 1)) < 0)
192 return -EIO;
193 ctrl->value &= 0x1f;
194 return 0;
195 case ZC0301_V4L2_CID_GREEN_BALANCE:
196 if ((ctrl->value = zc0301_i2c_read(cam, 0x08, 1)) < 0)
197 return -EIO;
198 ctrl->value &= 0x0f;
199 return 0;
200 case ZC0301_V4L2_CID_DAC_MAGNITUDE:
201 if ((ctrl->value = zc0301_i2c_read(cam, 0x0c, 1)) < 0)
202 return -EIO;
203 return 0;
204 default:
205 return -EINVAL;
206 }
207}
208
209
210static int pas202bcb_set_ctrl(struct zc0301_device* cam,
211 const struct v4l2_control* ctrl)
212{
213 int err = 0;
214
215 switch (ctrl->id) {
216 case V4L2_CID_EXPOSURE:
217 err += zc0301_i2c_write(cam, 0x04, ctrl->value >> 6);
218 err += zc0301_i2c_write(cam, 0x05, ctrl->value & 0x3f);
219 break;
220 case V4L2_CID_RED_BALANCE:
221 err += zc0301_i2c_write(cam, 0x09, ctrl->value);
222 break;
223 case V4L2_CID_BLUE_BALANCE:
224 err += zc0301_i2c_write(cam, 0x07, ctrl->value);
225 break;
226 case V4L2_CID_GAIN:
227 err += zc0301_i2c_write(cam, 0x10, ctrl->value);
228 break;
229 case ZC0301_V4L2_CID_GREEN_BALANCE:
230 err += zc0301_i2c_write(cam, 0x08, ctrl->value);
231 break;
232 case ZC0301_V4L2_CID_DAC_MAGNITUDE:
233 err += zc0301_i2c_write(cam, 0x0c, ctrl->value);
234 break;
235 default:
236 return -EINVAL;
237 }
238 err += zc0301_i2c_write(cam, 0x11, 0x01);
239
240 return err ? -EIO : 0;
241}
242
243
244static struct zc0301_sensor pas202bcb = {
245 .name = "PAS202BCB",
246 .init = &pas202bcb_init,
247 .qctrl = {
248 {
249 .id = V4L2_CID_EXPOSURE,
250 .type = V4L2_CTRL_TYPE_INTEGER,
251 .name = "exposure",
252 .minimum = 0x01e5,
253 .maximum = 0x3fff,
254 .step = 0x0001,
255 .default_value = 0x01e5,
256 .flags = V4L2_CTRL_FLAG_DISABLED,
257 },
258 {
259 .id = V4L2_CID_GAIN,
260 .type = V4L2_CTRL_TYPE_INTEGER,
261 .name = "global gain",
262 .minimum = 0x00,
263 .maximum = 0x1f,
264 .step = 0x01,
265 .default_value = 0x0c,
266 .flags = V4L2_CTRL_FLAG_DISABLED,
267 },
268 {
269 .id = ZC0301_V4L2_CID_DAC_MAGNITUDE,
270 .type = V4L2_CTRL_TYPE_INTEGER,
271 .name = "DAC magnitude",
272 .minimum = 0x00,
273 .maximum = 0xff,
274 .step = 0x01,
275 .default_value = 0x00,
276 .flags = V4L2_CTRL_FLAG_DISABLED,
277 },
278 {
279 .id = V4L2_CID_RED_BALANCE,
280 .type = V4L2_CTRL_TYPE_INTEGER,
281 .name = "red balance",
282 .minimum = 0x00,
283 .maximum = 0x0f,
284 .step = 0x01,
285 .default_value = 0x01,
286 .flags = V4L2_CTRL_FLAG_DISABLED,
287 },
288 {
289 .id = V4L2_CID_BLUE_BALANCE,
290 .type = V4L2_CTRL_TYPE_INTEGER,
291 .name = "blue balance",
292 .minimum = 0x00,
293 .maximum = 0x0f,
294 .step = 0x01,
295 .default_value = 0x05,
296 .flags = V4L2_CTRL_FLAG_DISABLED,
297 },
298 {
299 .id = ZC0301_V4L2_CID_GREEN_BALANCE,
300 .type = V4L2_CTRL_TYPE_INTEGER,
301 .name = "green balance",
302 .minimum = 0x00,
303 .maximum = 0x0f,
304 .step = 0x01,
305 .default_value = 0x00,
306 .flags = V4L2_CTRL_FLAG_DISABLED,
307 },
308 },
309 .get_ctrl = &pas202bcb_get_ctrl,
310 .set_ctrl = &pas202bcb_set_ctrl,
311 .cropcap = {
312 .bounds = {
313 .left = 0,
314 .top = 0,
315 .width = 640,
316 .height = 480,
317 },
318 .defrect = {
319 .left = 0,
320 .top = 0,
321 .width = 640,
322 .height = 480,
323 },
324 },
325 .pix_format = {
326 .width = 640,
327 .height = 480,
328 .pixelformat = V4L2_PIX_FMT_JPEG,
329 .priv = 8,
330 .colorspace = V4L2_COLORSPACE_JPEG,
331 },
332};
333
334
335int zc0301_probe_pas202bcb(struct zc0301_device* cam)
336{
337 int r0 = 0, r1 = 0, err = 0;
338 unsigned int pid = 0;
339
340 err += zc0301_write_reg(cam, 0x0000, 0x01);
341 err += zc0301_write_reg(cam, 0x0010, 0x0e);
342 err += zc0301_write_reg(cam, 0x0001, 0x01);
343 err += zc0301_write_reg(cam, 0x0012, 0x03);
344 err += zc0301_write_reg(cam, 0x0012, 0x01);
345 err += zc0301_write_reg(cam, 0x008d, 0x08);
346
347 msleep(10);
348
349 r0 = zc0301_i2c_read(cam, 0x00, 1);
350 r1 = zc0301_i2c_read(cam, 0x01, 1);
351
352 if (r0 < 0 || r1 < 0 || err)
353 return -EIO;
354
355 pid = (r0 << 4) | ((r1 & 0xf0) >> 4);
356 if (pid != 0x017)
357 return -ENODEV;
358
359 zc0301_attach_sensor(cam, &pas202bcb);
360
361 return 0;
362}
diff --git a/drivers/media/video/zc0301/zc0301_pb0330.c b/drivers/media/video/zc0301/zc0301_pb0330.c
deleted file mode 100644
index 9519aba3612e..000000000000
--- a/drivers/media/video/zc0301/zc0301_pb0330.c
+++ /dev/null
@@ -1,188 +0,0 @@
1/***************************************************************************
2 * Plug-in for PB-0330 image sensor connected to the ZC0301P Image *
3 * Processor and Control Chip *
4 * *
5 * Copyright (C) 2006-2007 by Luca Risolia <luca.risolia@studio.unibo.it> *
6 * *
7 * Initialization values of the ZC0301[P] have been taken from the SPCA5XX *
8 * driver maintained by Michel Xhaard <mxhaard@magic.fr> *
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the Free Software *
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
23 ***************************************************************************/
24
25#include <linux/delay.h>
26#include "zc0301_sensor.h"
27
28
29static struct zc0301_sensor pb0330;
30
31
32static int pb0330_init(struct zc0301_device* cam)
33{
34 int err = 0;
35
36 err += zc0301_write_reg(cam, 0x0000, 0x01);
37 err += zc0301_write_reg(cam, 0x0008, 0x03);
38 err += zc0301_write_reg(cam, 0x0010, 0x0A);
39 err += zc0301_write_reg(cam, 0x0002, 0x00);
40 err += zc0301_write_reg(cam, 0x0003, 0x02);
41 err += zc0301_write_reg(cam, 0x0004, 0x80);
42 err += zc0301_write_reg(cam, 0x0005, 0x01);
43 err += zc0301_write_reg(cam, 0x0006, 0xE0);
44 err += zc0301_write_reg(cam, 0x0001, 0x01);
45 err += zc0301_write_reg(cam, 0x0012, 0x05);
46 err += zc0301_write_reg(cam, 0x0012, 0x07);
47 err += zc0301_write_reg(cam, 0x0098, 0x00);
48 err += zc0301_write_reg(cam, 0x009A, 0x00);
49 err += zc0301_write_reg(cam, 0x011A, 0x00);
50 err += zc0301_write_reg(cam, 0x011C, 0x00);
51 err += zc0301_write_reg(cam, 0x0012, 0x05);
52
53 err += zc0301_i2c_write(cam, 0x01, 0x0006);
54 err += zc0301_i2c_write(cam, 0x02, 0x0011);
55 err += zc0301_i2c_write(cam, 0x03, 0x01E7);
56 err += zc0301_i2c_write(cam, 0x04, 0x0287);
57 err += zc0301_i2c_write(cam, 0x06, 0x0003);
58 err += zc0301_i2c_write(cam, 0x07, 0x3002);
59 err += zc0301_i2c_write(cam, 0x20, 0x1100);
60 err += zc0301_i2c_write(cam, 0x2F, 0xF7B0);
61 err += zc0301_i2c_write(cam, 0x30, 0x0005);
62 err += zc0301_i2c_write(cam, 0x31, 0x0000);
63 err += zc0301_i2c_write(cam, 0x34, 0x0100);
64 err += zc0301_i2c_write(cam, 0x35, 0x0060);
65 err += zc0301_i2c_write(cam, 0x3D, 0x068F);
66 err += zc0301_i2c_write(cam, 0x40, 0x01E0);
67 err += zc0301_i2c_write(cam, 0x58, 0x0078);
68 err += zc0301_i2c_write(cam, 0x62, 0x0411);
69
70 err += zc0301_write_reg(cam, 0x0087, 0x10);
71 err += zc0301_write_reg(cam, 0x0101, 0x37);
72 err += zc0301_write_reg(cam, 0x0012, 0x05);
73 err += zc0301_write_reg(cam, 0x0100, 0x0D);
74 err += zc0301_write_reg(cam, 0x0189, 0x06);
75 err += zc0301_write_reg(cam, 0x01AD, 0x00);
76 err += zc0301_write_reg(cam, 0x01C5, 0x03);
77 err += zc0301_write_reg(cam, 0x01CB, 0x13);
78 err += zc0301_write_reg(cam, 0x0250, 0x08);
79 err += zc0301_write_reg(cam, 0x0301, 0x08);
80 err += zc0301_write_reg(cam, 0x01A8, 0x60);
81 err += zc0301_write_reg(cam, 0x018D, 0x6C);
82 err += zc0301_write_reg(cam, 0x01AD, 0x09);
83 err += zc0301_write_reg(cam, 0x01AE, 0x15);
84 err += zc0301_write_reg(cam, 0x010A, 0x50);
85 err += zc0301_write_reg(cam, 0x010B, 0xF8);
86 err += zc0301_write_reg(cam, 0x010C, 0xF8);
87 err += zc0301_write_reg(cam, 0x010D, 0xF8);
88 err += zc0301_write_reg(cam, 0x010E, 0x50);
89 err += zc0301_write_reg(cam, 0x010F, 0xF8);
90 err += zc0301_write_reg(cam, 0x0110, 0xF8);
91 err += zc0301_write_reg(cam, 0x0111, 0xF8);
92 err += zc0301_write_reg(cam, 0x0112, 0x50);
93 err += zc0301_write_reg(cam, 0x0008, 0x03);
94 err += zc0301_write_reg(cam, 0x01C6, 0x08);
95 err += zc0301_write_reg(cam, 0x01CB, 0x0F);
96 err += zc0301_write_reg(cam, 0x010A, 0x50);
97 err += zc0301_write_reg(cam, 0x010B, 0xF8);
98 err += zc0301_write_reg(cam, 0x010C, 0xF8);
99 err += zc0301_write_reg(cam, 0x010D, 0xF8);
100 err += zc0301_write_reg(cam, 0x010E, 0x50);
101 err += zc0301_write_reg(cam, 0x010F, 0xF8);
102 err += zc0301_write_reg(cam, 0x0110, 0xF8);
103 err += zc0301_write_reg(cam, 0x0111, 0xF8);
104 err += zc0301_write_reg(cam, 0x0112, 0x50);
105 err += zc0301_write_reg(cam, 0x0180, 0x00);
106 err += zc0301_write_reg(cam, 0x0019, 0x00);
107
108 err += zc0301_i2c_write(cam, 0x05, 0x0066);
109 err += zc0301_i2c_write(cam, 0x09, 0x02B2);
110 err += zc0301_i2c_write(cam, 0x10, 0x0002);
111
112 err += zc0301_write_reg(cam, 0x011D, 0x60);
113 err += zc0301_write_reg(cam, 0x0190, 0x00);
114 err += zc0301_write_reg(cam, 0x0191, 0x07);
115 err += zc0301_write_reg(cam, 0x0192, 0x8C);
116 err += zc0301_write_reg(cam, 0x0195, 0x00);
117 err += zc0301_write_reg(cam, 0x0196, 0x00);
118 err += zc0301_write_reg(cam, 0x0197, 0x8A);
119 err += zc0301_write_reg(cam, 0x018C, 0x10);
120 err += zc0301_write_reg(cam, 0x018F, 0x20);
121 err += zc0301_write_reg(cam, 0x01A9, 0x14);
122 err += zc0301_write_reg(cam, 0x01AA, 0x24);
123 err += zc0301_write_reg(cam, 0x001D, 0xD7);
124 err += zc0301_write_reg(cam, 0x001E, 0xF0);
125 err += zc0301_write_reg(cam, 0x001F, 0xF8);
126 err += zc0301_write_reg(cam, 0x0020, 0xFF);
127 err += zc0301_write_reg(cam, 0x01AD, 0x09);
128 err += zc0301_write_reg(cam, 0x01AE, 0x15);
129 err += zc0301_write_reg(cam, 0x0180, 0x40);
130 err += zc0301_write_reg(cam, 0x0180, 0x42);
131
132 msleep(100);
133
134 return err;
135}
136
137
138static struct zc0301_sensor pb0330 = {
139 .name = "PB-0330",
140 .init = &pb0330_init,
141 .cropcap = {
142 .bounds = {
143 .left = 0,
144 .top = 0,
145 .width = 640,
146 .height = 480,
147 },
148 .defrect = {
149 .left = 0,
150 .top = 0,
151 .width = 640,
152 .height = 480,
153 },
154 },
155 .pix_format = {
156 .width = 640,
157 .height = 480,
158 .pixelformat = V4L2_PIX_FMT_JPEG,
159 .priv = 8,
160 .colorspace = V4L2_COLORSPACE_JPEG,
161 },
162};
163
164
165int zc0301_probe_pb0330(struct zc0301_device* cam)
166{
167 int r0, err = 0;
168
169 err += zc0301_write_reg(cam, 0x0000, 0x01);
170 err += zc0301_write_reg(cam, 0x0010, 0x0a);
171 err += zc0301_write_reg(cam, 0x0001, 0x01);
172 err += zc0301_write_reg(cam, 0x0012, 0x03);
173 err += zc0301_write_reg(cam, 0x0012, 0x01);
174
175 msleep(10);
176
177 r0 = zc0301_i2c_read(cam, 0x00, 2);
178
179 if (r0 < 0 || err)
180 return -EIO;
181
182 if (r0 != 0x8243)
183 return -ENODEV;
184
185 zc0301_attach_sensor(cam, &pb0330);
186
187 return 0;
188}
diff --git a/drivers/media/video/zc0301/zc0301_sensor.h b/drivers/media/video/zc0301/zc0301_sensor.h
deleted file mode 100644
index 0be783c203f7..000000000000
--- a/drivers/media/video/zc0301/zc0301_sensor.h
+++ /dev/null
@@ -1,107 +0,0 @@
1/***************************************************************************
2 * API for image sensors connected to the ZC0301[P] Image Processor and *
3 * Control Chip *
4 * *
5 * Copyright (C) 2006-2007 by Luca Risolia <luca.risolia@studio.unibo.it> *
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the Free Software *
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
20 ***************************************************************************/
21
22#ifndef _ZC0301_SENSOR_H_
23#define _ZC0301_SENSOR_H_
24
25#include <linux/usb.h>
26#include <linux/videodev2.h>
27#include <linux/device.h>
28#include <linux/stddef.h>
29#include <linux/errno.h>
30#include <asm/types.h>
31
32struct zc0301_device;
33struct zc0301_sensor;
34
35/*****************************************************************************/
36
37extern int zc0301_probe_pas202bcb(struct zc0301_device* cam);
38extern int zc0301_probe_pb0330(struct zc0301_device* cam);
39
40#define ZC0301_SENSOR_TABLE \
41/* Weak detections must go at the end of the list */ \
42static int (*zc0301_sensor_table[])(struct zc0301_device*) = { \
43 &zc0301_probe_pas202bcb, \
44 &zc0301_probe_pb0330, \
45 NULL, \
46};
47
48extern struct zc0301_device*
49zc0301_match_id(struct zc0301_device* cam, const struct usb_device_id *id);
50
51extern void
52zc0301_attach_sensor(struct zc0301_device* cam, struct zc0301_sensor* sensor);
53
54#define ZC0301_USB_DEVICE(vend, prod, intclass) \
55 .match_flags = USB_DEVICE_ID_MATCH_DEVICE | \
56 USB_DEVICE_ID_MATCH_INT_CLASS, \
57 .idVendor = (vend), \
58 .idProduct = (prod), \
59 .bInterfaceClass = (intclass)
60
61#if !defined CONFIG_USB_GSPCA_ZC3XX && !defined CONFIG_USB_GSPCA_ZC3XX_MODULE
62#define ZC0301_ID_TABLE \
63static const struct usb_device_id zc0301_id_table[] = { \
64 { ZC0301_USB_DEVICE(0x046d, 0x08ae, 0xff), }, /* PAS202 */ \
65 { ZC0301_USB_DEVICE(0x0ac8, 0x303b, 0xff), }, /* PB-0330 */ \
66 { } \
67};
68#else
69#define ZC0301_ID_TABLE \
70static const struct usb_device_id zc0301_id_table[] = { \
71 { ZC0301_USB_DEVICE(0x046d, 0x08ae, 0xff), }, /* PAS202 */ \
72 { } \
73};
74#endif
75
76/*****************************************************************************/
77
78extern int zc0301_write_reg(struct zc0301_device*, u16 index, u16 value);
79extern int zc0301_read_reg(struct zc0301_device*, u16 index);
80extern int zc0301_i2c_write(struct zc0301_device*, u16 address, u16 value);
81extern int zc0301_i2c_read(struct zc0301_device*, u16 address, u8 length);
82
83/*****************************************************************************/
84
85#define ZC0301_MAX_CTRLS (V4L2_CID_LASTP1 - V4L2_CID_BASE + 10)
86#define ZC0301_V4L2_CID_DAC_MAGNITUDE (V4L2_CID_PRIVATE_BASE + 0)
87#define ZC0301_V4L2_CID_GREEN_BALANCE (V4L2_CID_PRIVATE_BASE + 1)
88
89struct zc0301_sensor {
90 char name[32];
91
92 struct v4l2_queryctrl qctrl[ZC0301_MAX_CTRLS];
93 struct v4l2_cropcap cropcap;
94 struct v4l2_pix_format pix_format;
95
96 int (*init)(struct zc0301_device*);
97 int (*get_ctrl)(struct zc0301_device*, struct v4l2_control* ctrl);
98 int (*set_ctrl)(struct zc0301_device*,
99 const struct v4l2_control* ctrl);
100 int (*set_crop)(struct zc0301_device*, const struct v4l2_rect* rect);
101
102 /* Private */
103 struct v4l2_queryctrl _qctrl[ZC0301_MAX_CTRLS];
104 struct v4l2_rect _rect;
105};
106
107#endif /* _ZC0301_SENSOR_H_ */
diff --git a/drivers/media/video/zoran/videocodec.c b/drivers/media/video/zoran/videocodec.c
index cf24956f3204..c01071635290 100644
--- a/drivers/media/video/zoran/videocodec.c
+++ b/drivers/media/video/zoran/videocodec.c
@@ -107,15 +107,14 @@ videocodec_attach (struct videocodec_master *master)
107 if (!try_module_get(h->codec->owner)) 107 if (!try_module_get(h->codec->owner))
108 return NULL; 108 return NULL;
109 109
110 codec = 110 codec = kmemdup(h->codec, sizeof(struct videocodec),
111 kmalloc(sizeof(struct videocodec), GFP_KERNEL); 111 GFP_KERNEL);
112 if (!codec) { 112 if (!codec) {
113 dprintk(1, 113 dprintk(1,
114 KERN_ERR 114 KERN_ERR
115 "videocodec_attach: no mem\n"); 115 "videocodec_attach: no mem\n");
116 goto out_module_put; 116 goto out_module_put;
117 } 117 }
118 memcpy(codec, h->codec, sizeof(struct videocodec));
119 118
120 snprintf(codec->name, sizeof(codec->name), 119 snprintf(codec->name, sizeof(codec->name),
121 "%s[%d]", codec->name, h->attached); 120 "%s[%d]", codec->name, h->attached);
diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig
index 984a75440710..929651725855 100644
--- a/drivers/staging/Kconfig
+++ b/drivers/staging/Kconfig
@@ -147,5 +147,7 @@ source "drivers/staging/mrst-touchscreen/Kconfig"
147 147
148source "drivers/staging/msm/Kconfig" 148source "drivers/staging/msm/Kconfig"
149 149
150source "drivers/staging/lirc/Kconfig"
151
150endif # !STAGING_EXCLUDE_BUILD 152endif # !STAGING_EXCLUDE_BUILD
151endif # STAGING 153endif # STAGING
diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile
index 9fa25133874a..6c5b5237ccb9 100644
--- a/drivers/staging/Makefile
+++ b/drivers/staging/Makefile
@@ -8,6 +8,7 @@ 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_LIRC_STAGING) += lirc/
11obj-$(CONFIG_USB_IP_COMMON) += usbip/ 12obj-$(CONFIG_USB_IP_COMMON) += usbip/
12obj-$(CONFIG_W35UND) += winbond/ 13obj-$(CONFIG_W35UND) += winbond/
13obj-$(CONFIG_PRISM2_USB) += wlan-ng/ 14obj-$(CONFIG_PRISM2_USB) += wlan-ng/
diff --git a/drivers/staging/cx25821/Makefile b/drivers/staging/cx25821/Makefile
index 10f87f05d8e8..d0eb16eac092 100644
--- a/drivers/staging/cx25821/Makefile
+++ b/drivers/staging/cx25821/Makefile
@@ -1,9 +1,8 @@
1cx25821-objs := cx25821-core.o cx25821-cards.o cx25821-i2c.o cx25821-gpio.o \ 1cx25821-objs := cx25821-core.o cx25821-cards.o cx25821-i2c.o \
2 cx25821-medusa-video.o cx25821-video.o cx25821-video0.o cx25821-video1.o \ 2 cx25821-gpio.o cx25821-medusa-video.o \
3 cx25821-video2.o cx25821-video3.o cx25821-video4.o cx25821-video5.o \ 3 cx25821-video.o cx25821-video-upstream.o \
4 cx25821-video6.o cx25821-video7.o cx25821-vidups9.o cx25821-vidups10.o \ 4 cx25821-video-upstream-ch2.o \
5 cx25821-audups11.o cx25821-video-upstream.o cx25821-video-upstream-ch2.o \ 5 cx25821-audio-upstream.o
6 cx25821-audio-upstream.o cx25821-videoioctl.o
7 6
8obj-$(CONFIG_VIDEO_CX25821) += cx25821.o 7obj-$(CONFIG_VIDEO_CX25821) += cx25821.o
9obj-$(CONFIG_VIDEO_CX25821_ALSA) += cx25821-alsa.o 8obj-$(CONFIG_VIDEO_CX25821_ALSA) += cx25821-alsa.o
diff --git a/drivers/staging/cx25821/cx25821-alsa.c b/drivers/staging/cx25821/cx25821-alsa.c
index 1798975a69bd..a43b18816fa5 100644
--- a/drivers/staging/cx25821/cx25821-alsa.c
+++ b/drivers/staging/cx25821/cx25821-alsa.c
@@ -55,6 +55,12 @@
55static struct snd_card *snd_cx25821_cards[SNDRV_CARDS]; 55static struct snd_card *snd_cx25821_cards[SNDRV_CARDS];
56static int devno; 56static int devno;
57 57
58struct cx25821_audio_buffer {
59 unsigned int bpl;
60 struct btcx_riscmem risc;
61 struct videobuf_dmabuf dma;
62};
63
58struct cx25821_audio_dev { 64struct cx25821_audio_dev {
59 struct cx25821_dev *dev; 65 struct cx25821_dev *dev;
60 struct cx25821_dmaqueue q; 66 struct cx25821_dmaqueue q;
@@ -77,7 +83,7 @@ struct cx25821_audio_dev {
77 83
78 struct videobuf_dmabuf *dma_risc; 84 struct videobuf_dmabuf *dma_risc;
79 85
80 struct cx25821_buffer *buf; 86 struct cx25821_audio_buffer *buf;
81 87
82 struct snd_pcm_substream *substream; 88 struct snd_pcm_substream *substream;
83}; 89};
@@ -136,7 +142,7 @@ MODULE_PARM_DESC(debug, "enable debug messages");
136 142
137static int _cx25821_start_audio_dma(struct cx25821_audio_dev *chip) 143static int _cx25821_start_audio_dma(struct cx25821_audio_dev *chip)
138{ 144{
139 struct cx25821_buffer *buf = chip->buf; 145 struct cx25821_audio_buffer *buf = chip->buf;
140 struct cx25821_dev *dev = chip->dev; 146 struct cx25821_dev *dev = chip->dev;
141 struct sram_channel *audio_ch = 147 struct sram_channel *audio_ch =
142 &cx25821_sram_channels[AUDIO_SRAM_CHANNEL]; 148 &cx25821_sram_channels[AUDIO_SRAM_CHANNEL];
@@ -331,7 +337,7 @@ static int dsp_buffer_free(struct cx25821_audio_dev *chip)
331 BUG_ON(!chip->dma_size); 337 BUG_ON(!chip->dma_size);
332 338
333 dprintk(2, "Freeing buffer\n"); 339 dprintk(2, "Freeing buffer\n");
334 videobuf_sg_dma_unmap(&chip->pci->dev, chip->dma_risc); 340 videobuf_dma_unmap(&chip->pci->dev, chip->dma_risc);
335 videobuf_dma_free(chip->dma_risc); 341 videobuf_dma_free(chip->dma_risc);
336 btcx_riscmem_free(chip->pci, &chip->buf->risc); 342 btcx_riscmem_free(chip->pci, &chip->buf->risc);
337 kfree(chip->buf); 343 kfree(chip->buf);
@@ -432,7 +438,7 @@ static int snd_cx25821_hw_params(struct snd_pcm_substream *substream,
432 struct cx25821_audio_dev *chip = snd_pcm_substream_chip(substream); 438 struct cx25821_audio_dev *chip = snd_pcm_substream_chip(substream);
433 struct videobuf_dmabuf *dma; 439 struct videobuf_dmabuf *dma;
434 440
435 struct cx25821_buffer *buf; 441 struct cx25821_audio_buffer *buf;
436 int ret; 442 int ret;
437 443
438 if (substream->runtime->dma_area) { 444 if (substream->runtime->dma_area) {
@@ -447,36 +453,31 @@ static int snd_cx25821_hw_params(struct snd_pcm_substream *substream,
447 BUG_ON(!chip->dma_size); 453 BUG_ON(!chip->dma_size);
448 BUG_ON(chip->num_periods & (chip->num_periods - 1)); 454 BUG_ON(chip->num_periods & (chip->num_periods - 1));
449 455
450 buf = videobuf_sg_alloc(sizeof(*buf)); 456 buf = kzalloc(sizeof(*buf), GFP_KERNEL);
451 if (NULL == buf) 457 if (NULL == buf)
452 return -ENOMEM; 458 return -ENOMEM;
453 459
454 if (chip->period_size > AUDIO_LINE_SIZE) 460 if (chip->period_size > AUDIO_LINE_SIZE)
455 chip->period_size = AUDIO_LINE_SIZE; 461 chip->period_size = AUDIO_LINE_SIZE;
456 462
457 buf->vb.memory = V4L2_MEMORY_MMAP;
458 buf->vb.field = V4L2_FIELD_NONE;
459 buf->vb.width = chip->period_size;
460 buf->bpl = chip->period_size; 463 buf->bpl = chip->period_size;
461 buf->vb.height = chip->num_periods;
462 buf->vb.size = chip->dma_size;
463 464
464 dma = videobuf_to_dma(&buf->vb); 465 dma = &buf->dma;
465 videobuf_dma_init(dma); 466 videobuf_dma_init(dma);
466
467 ret = videobuf_dma_init_kernel(dma, PCI_DMA_FROMDEVICE, 467 ret = videobuf_dma_init_kernel(dma, PCI_DMA_FROMDEVICE,
468 (PAGE_ALIGN(buf->vb.size) >> 468 (PAGE_ALIGN(chip->dma_size) >>
469 PAGE_SHIFT)); 469 PAGE_SHIFT));
470 if (ret < 0) 470 if (ret < 0)
471 goto error; 471 goto error;
472 472
473 ret = videobuf_sg_dma_map(&chip->pci->dev, dma); 473 ret = videobuf_dma_map(&chip->pci->dev, dma);
474 if (ret < 0) 474 if (ret < 0)
475 goto error; 475 goto error;
476 476
477 ret = 477 ret =
478 cx25821_risc_databuffer_audio(chip->pci, &buf->risc, dma->sglist, 478 cx25821_risc_databuffer_audio(chip->pci, &buf->risc, dma->sglist,
479 buf->vb.width, buf->vb.height, 1); 479 chip->period_size, chip->num_periods,
480 1);
480 if (ret < 0) { 481 if (ret < 0) {
481 printk(KERN_INFO 482 printk(KERN_INFO
482 "DEBUG: ERROR after cx25821_risc_databuffer_audio()\n"); 483 "DEBUG: ERROR after cx25821_risc_databuffer_audio()\n");
@@ -488,12 +489,10 @@ static int snd_cx25821_hw_params(struct snd_pcm_substream *substream,
488 buf->risc.jmp[1] = cpu_to_le32(buf->risc.dma); 489 buf->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
489 buf->risc.jmp[2] = cpu_to_le32(0); /* bits 63-32 */ 490 buf->risc.jmp[2] = cpu_to_le32(0); /* bits 63-32 */
490 491
491 buf->vb.state = VIDEOBUF_PREPARED;
492
493 chip->buf = buf; 492 chip->buf = buf;
494 chip->dma_risc = dma; 493 chip->dma_risc = dma;
495 494
496 substream->runtime->dma_area = chip->dma_risc->vmalloc; 495 substream->runtime->dma_area = chip->dma_risc->vaddr;
497 substream->runtime->dma_bytes = chip->dma_size; 496 substream->runtime->dma_bytes = chip->dma_size;
498 substream->runtime->dma_addr = 0; 497 substream->runtime->dma_addr = 0;
499 498
diff --git a/drivers/staging/cx25821/cx25821-audio-upstream.c b/drivers/staging/cx25821/cx25821-audio-upstream.c
index eb39d13f7d75..cdff49f409f2 100644
--- a/drivers/staging/cx25821/cx25821-audio-upstream.c
+++ b/drivers/staging/cx25821/cx25821-audio-upstream.c
@@ -106,7 +106,7 @@ static __le32 *cx25821_risc_field_upstream_audio(struct cx25821_dev *dev,
106{ 106{
107 unsigned int line; 107 unsigned int line;
108 struct sram_channel *sram_ch = 108 struct sram_channel *sram_ch =
109 &dev->sram_channels[dev->_audio_upstream_channel_select]; 109 dev->channels[dev->_audio_upstream_channel_select].sram_channels;
110 int offset = 0; 110 int offset = 0;
111 111
112 /* scan lines */ 112 /* scan lines */
@@ -217,7 +217,7 @@ void cx25821_free_memory_audio(struct cx25821_dev *dev)
217void cx25821_stop_upstream_audio(struct cx25821_dev *dev) 217void cx25821_stop_upstream_audio(struct cx25821_dev *dev)
218{ 218{
219 struct sram_channel *sram_ch = 219 struct sram_channel *sram_ch =
220 &dev->sram_channels[AUDIO_UPSTREAM_SRAM_CHANNEL_B]; 220 dev->channels[AUDIO_UPSTREAM_SRAM_CHANNEL_B].sram_channels;
221 u32 tmp = 0; 221 u32 tmp = 0;
222 222
223 if (!dev->_audio_is_running) { 223 if (!dev->_audio_is_running) {
@@ -287,14 +287,14 @@ int cx25821_get_audio_data(struct cx25821_dev *dev,
287 return PTR_ERR(myfile); 287 return PTR_ERR(myfile);
288 } else { 288 } else {
289 if (!(myfile->f_op)) { 289 if (!(myfile->f_op)) {
290 printk("%s: File has no file operations registered!\n", 290 printk(KERN_ERR "%s: File has no file operations registered!\n",
291 __func__); 291 __func__);
292 filp_close(myfile, NULL); 292 filp_close(myfile, NULL);
293 return -EIO; 293 return -EIO;
294 } 294 }
295 295
296 if (!myfile->f_op->read) { 296 if (!myfile->f_op->read) {
297 printk("%s: File has no READ operations registered!\n", 297 printk(KERN_ERR "%s: File has no READ operations registered!\n",
298 __func__); 298 __func__);
299 filp_close(myfile, NULL); 299 filp_close(myfile, NULL);
300 return -EIO; 300 return -EIO;
@@ -353,8 +353,9 @@ static void cx25821_audioups_handler(struct work_struct *work)
353 } 353 }
354 354
355 cx25821_get_audio_data(dev, 355 cx25821_get_audio_data(dev,
356 &dev->sram_channels[dev-> 356 dev->channels[dev->
357 _audio_upstream_channel_select]); 357 _audio_upstream_channel_select].
358 sram_channels);
358} 359}
359 360
360int cx25821_openfile_audio(struct cx25821_dev *dev, 361int cx25821_openfile_audio(struct cx25821_dev *dev,
@@ -378,14 +379,14 @@ int cx25821_openfile_audio(struct cx25821_dev *dev,
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("%s: File has no file operations registered!\n", 382 printk(KERN_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("%s: File has no READ operations registered!\n", 389 printk(KERN_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;
@@ -505,7 +506,7 @@ int cx25821_audio_upstream_irq(struct cx25821_dev *dev, int chan_num,
505{ 506{
506 int i = 0; 507 int i = 0;
507 u32 int_msk_tmp; 508 u32 int_msk_tmp;
508 struct sram_channel *channel = &dev->sram_channels[chan_num]; 509 struct sram_channel *channel = dev->channels[chan_num].sram_channels;
509 dma_addr_t risc_phys_jump_addr; 510 dma_addr_t risc_phys_jump_addr;
510 __le32 *rp; 511 __le32 *rp;
511 512
@@ -569,15 +570,15 @@ int cx25821_audio_upstream_irq(struct cx25821_dev *dev, int chan_num,
569 spin_unlock(&dev->slock); 570 spin_unlock(&dev->slock);
570 } else { 571 } else {
571 if (status & FLD_AUD_SRC_OF) 572 if (status & FLD_AUD_SRC_OF)
572 printk("%s: Audio Received Overflow Error Interrupt!\n", 573 printk(KERN_WARNING "%s: Audio Received Overflow Error Interrupt!\n",
573 __func__); 574 __func__);
574 575
575 if (status & FLD_AUD_SRC_SYNC) 576 if (status & FLD_AUD_SRC_SYNC)
576 printk("%s: Audio Received Sync Error Interrupt!\n", 577 printk(KERN_WARNING "%s: Audio Received Sync Error Interrupt!\n",
577 __func__); 578 __func__);
578 579
579 if (status & FLD_AUD_SRC_OPC_ERR) 580 if (status & FLD_AUD_SRC_OPC_ERR)
580 printk("%s: Audio Received OpCode Error Interrupt!\n", 581 printk(KERN_WARNING "%s: Audio Received OpCode Error Interrupt!\n",
581 __func__); 582 __func__);
582 583
583 /* Read and write back the interrupt status register to clear 584 /* Read and write back the interrupt status register to clear
@@ -586,7 +587,7 @@ int cx25821_audio_upstream_irq(struct cx25821_dev *dev, int chan_num,
586 } 587 }
587 588
588 if (dev->_audiofile_status == END_OF_FILE) { 589 if (dev->_audiofile_status == END_OF_FILE) {
589 printk("cx25821: EOF Channel Audio Framecount = %d\n", 590 printk(KERN_WARNING "cx25821: EOF Channel Audio Framecount = %d\n",
590 dev->_audioframe_count); 591 dev->_audioframe_count);
591 return -1; 592 return -1;
592 } 593 }
@@ -607,7 +608,8 @@ static irqreturn_t cx25821_upstream_irq_audio(int irq, void *dev_id)
607 if (!dev) 608 if (!dev)
608 return -1; 609 return -1;
609 610
610 sram_ch = &dev->sram_channels[dev->_audio_upstream_channel_select]; 611 sram_ch = dev->channels[dev->_audio_upstream_channel_select].
612 sram_channels;
611 613
612 msk_stat = cx_read(sram_ch->int_mstat); 614 msk_stat = cx_read(sram_ch->int_mstat);
613 audio_status = cx_read(sram_ch->int_stat); 615 audio_status = cx_read(sram_ch->int_stat);
@@ -644,8 +646,8 @@ static void cx25821_wait_fifo_enable(struct cx25821_dev *dev,
644 646
645 /* 10 millisecond timeout */ 647 /* 10 millisecond timeout */
646 if (count++ > 1000) { 648 if (count++ > 1000) {
647 printk 649 printk(KERN_ERR
648 ("cx25821 ERROR: %s() fifo is NOT turned on. Timeout!\n", 650 "cx25821 ERROR: %s() fifo is NOT turned on. Timeout!\n",
649 __func__); 651 __func__);
650 return; 652 return;
651 } 653 }
@@ -726,12 +728,12 @@ int cx25821_audio_upstream_init(struct cx25821_dev *dev, int channel_select)
726 int str_length = 0; 728 int str_length = 0;
727 729
728 if (dev->_audio_is_running) { 730 if (dev->_audio_is_running) {
729 printk("Audio Channel is still running so return!\n"); 731 printk(KERN_WARNING "Audio Channel is still running so return!\n");
730 return 0; 732 return 0;
731 } 733 }
732 734
733 dev->_audio_upstream_channel_select = channel_select; 735 dev->_audio_upstream_channel_select = channel_select;
734 sram_ch = &dev->sram_channels[channel_select]; 736 sram_ch = dev->channels[channel_select].sram_channels;
735 737
736 /* Work queue */ 738 /* Work queue */
737 INIT_WORK(&dev->_audio_work_entry, cx25821_audioups_handler); 739 INIT_WORK(&dev->_audio_work_entry, cx25821_audioups_handler);
diff --git a/drivers/staging/cx25821/cx25821-audio.h b/drivers/staging/cx25821/cx25821-audio.h
index 503f42f036a8..434b2a312a80 100644
--- a/drivers/staging/cx25821/cx25821-audio.h
+++ b/drivers/staging/cx25821/cx25821-audio.h
@@ -27,24 +27,25 @@
27#define LINES_PER_BUFFER 15 27#define LINES_PER_BUFFER 15
28#define AUDIO_LINE_SIZE 128 28#define AUDIO_LINE_SIZE 128
29 29
30//Number of buffer programs to use at once. 30/* Number of buffer programs to use at once. */
31#define NUMBER_OF_PROGRAMS 8 31#define NUMBER_OF_PROGRAMS 8
32 32
33//Max size of the RISC program for a buffer. - worst case is 2 writes per line 33/*
34// Space is also added for the 4 no-op instructions added on the end. 34 Max size of the RISC program for a buffer. - worst case is 2 writes per line
35 35 Space is also added for the 4 no-op instructions added on the end.
36*/
36#ifndef USE_RISC_NOOP 37#ifndef USE_RISC_NOOP
37#define MAX_BUFFER_PROGRAM_SIZE \ 38#define MAX_BUFFER_PROGRAM_SIZE \
38 (2*LINES_PER_BUFFER*RISC_WRITE_INSTRUCTION_SIZE + RISC_WRITECR_INSTRUCTION_SIZE*4) 39 (2*LINES_PER_BUFFER*RISC_WRITE_INSTRUCTION_SIZE + RISC_WRITECR_INSTRUCTION_SIZE*4)
39#endif 40#endif
40 41
41// MAE 12 July 2005 Try to use NOOP RISC instruction instead 42/* MAE 12 July 2005 Try to use NOOP RISC instruction instead */
42#ifdef USE_RISC_NOOP 43#ifdef USE_RISC_NOOP
43#define MAX_BUFFER_PROGRAM_SIZE \ 44#define MAX_BUFFER_PROGRAM_SIZE \
44 (2*LINES_PER_BUFFER*RISC_WRITE_INSTRUCTION_SIZE + RISC_NOOP_INSTRUCTION_SIZE*4) 45 (2*LINES_PER_BUFFER*RISC_WRITE_INSTRUCTION_SIZE + RISC_NOOP_INSTRUCTION_SIZE*4)
45#endif 46#endif
46 47
47//Sizes of various instructions in bytes. Used when adding instructions. 48/* Sizes of various instructions in bytes. Used when adding instructions. */
48#define RISC_WRITE_INSTRUCTION_SIZE 12 49#define RISC_WRITE_INSTRUCTION_SIZE 12
49#define RISC_JUMP_INSTRUCTION_SIZE 12 50#define RISC_JUMP_INSTRUCTION_SIZE 12
50#define RISC_SKIP_INSTRUCTION_SIZE 4 51#define RISC_SKIP_INSTRUCTION_SIZE 4
diff --git a/drivers/staging/cx25821/cx25821-audups11.c b/drivers/staging/cx25821/cx25821-audups11.c
deleted file mode 100644
index e49ead982f39..000000000000
--- a/drivers/staging/cx25821/cx25821-audups11.c
+++ /dev/null
@@ -1,420 +0,0 @@
1/*
2 * Driver for the Conexant CX25821 PCIe bridge
3 *
4 * Copyright (C) 2009 Conexant Systems Inc.
5 * Authors <shu.lin@conexant.com>, <hiep.huynh@conexant.com>
6 * Based on Steven Toth <stoth@linuxtv.org> cx23885 driver
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 *
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#include <linux/slab.h>
25
26#include "cx25821-video.h"
27
28static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
29{
30 struct cx25821_buffer *buf =
31 container_of(vb, struct cx25821_buffer, vb);
32 struct cx25821_buffer *prev;
33 struct cx25821_fh *fh = vq->priv_data;
34 struct cx25821_dev *dev = fh->dev;
35 struct cx25821_dmaqueue *q = &dev->vidq[SRAM_CH11];
36
37 /* add jump to stopper */
38 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
39 buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma);
40 buf->risc.jmp[2] = cpu_to_le32(0); /* bits 63-32 */
41
42 dprintk(2, "jmp to stopper (0x%x)\n", buf->risc.jmp[1]);
43
44 if (!list_empty(&q->queued)) {
45 list_add_tail(&buf->vb.queue, &q->queued);
46 buf->vb.state = VIDEOBUF_QUEUED;
47 dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf,
48 buf->vb.i);
49
50 } else if (list_empty(&q->active)) {
51 list_add_tail(&buf->vb.queue, &q->active);
52 cx25821_start_video_dma(dev, q, buf,
53 &dev->sram_channels[SRAM_CH11]);
54 buf->vb.state = VIDEOBUF_ACTIVE;
55 buf->count = q->count++;
56 mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
57 dprintk(2,
58 "[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
59 buf, buf->vb.i, buf->count, q->count);
60 } else {
61 prev =
62 list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
63 if (prev->vb.width == buf->vb.width
64 && prev->vb.height == buf->vb.height
65 && prev->fmt == buf->fmt) {
66 list_add_tail(&buf->vb.queue, &q->active);
67 buf->vb.state = VIDEOBUF_ACTIVE;
68 buf->count = q->count++;
69 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
70
71 /* 64 bit bits 63-32 */
72 prev->risc.jmp[2] = cpu_to_le32(0);
73 dprintk(2,
74 "[%p/%d] buffer_queue - append to active, buf->count=%d\n",
75 buf, buf->vb.i, buf->count);
76
77 } else {
78 list_add_tail(&buf->vb.queue, &q->queued);
79 buf->vb.state = VIDEOBUF_QUEUED;
80 dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf,
81 buf->vb.i);
82 }
83 }
84
85 if (list_empty(&q->active)) {
86 dprintk(2, "active queue empty!\n");
87 }
88}
89
90static struct videobuf_queue_ops cx25821_video_qops = {
91 .buf_setup = cx25821_buffer_setup,
92 .buf_prepare = cx25821_buffer_prepare,
93 .buf_queue = buffer_queue,
94 .buf_release = cx25821_buffer_release,
95};
96
97static int video_open(struct file *file)
98{
99 struct video_device *vdev = video_devdata(file);
100 struct cx25821_dev *dev = video_drvdata(file);
101 struct cx25821_fh *fh;
102 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
103
104 printk("open dev=%s type=%s\n", video_device_node_name(vdev),
105 v4l2_type_names[type]);
106
107 /* allocate + initialize per filehandle data */
108 fh = kzalloc(sizeof(*fh), GFP_KERNEL);
109 if (NULL == fh)
110 return -ENOMEM;
111
112 lock_kernel();
113
114 file->private_data = fh;
115 fh->dev = dev;
116 fh->type = type;
117 fh->width = 720;
118
119 if (dev->tvnorm & V4L2_STD_PAL_BG || dev->tvnorm & V4L2_STD_PAL_DK)
120 fh->height = 576;
121 else
122 fh->height = 480;
123
124 dev->channel_opened = 10;
125 fh->fmt = format_by_fourcc(V4L2_PIX_FMT_YUYV);
126
127 v4l2_prio_open(&dev->prio, &fh->prio);
128
129 videobuf_queue_sg_init(&fh->vidq, &cx25821_video_qops,
130 &dev->pci->dev, &dev->slock,
131 V4L2_BUF_TYPE_VIDEO_CAPTURE,
132 V4L2_FIELD_INTERLACED,
133 sizeof(struct cx25821_buffer), fh);
134
135 dprintk(1, "post videobuf_queue_init()\n");
136 unlock_kernel();
137
138 return 0;
139}
140
141static ssize_t video_read(struct file *file, char __user * data, size_t count,
142 loff_t * ppos)
143{
144 struct cx25821_fh *fh = file->private_data;
145
146 switch (fh->type) {
147 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
148 if (cx25821_res_locked(fh->dev, RESOURCE_VIDEO11))
149 return -EBUSY;
150
151 return videobuf_read_one(&fh->vidq, data, count, ppos,
152 file->f_flags & O_NONBLOCK);
153
154 default:
155 BUG();
156 return 0;
157 }
158}
159
160static unsigned int video_poll(struct file *file,
161 struct poll_table_struct *wait)
162{
163 struct cx25821_fh *fh = file->private_data;
164 struct cx25821_buffer *buf;
165
166 if (cx25821_res_check(fh, RESOURCE_VIDEO11)) {
167 /* streaming capture */
168 if (list_empty(&fh->vidq.stream))
169 return POLLERR;
170 buf = list_entry(fh->vidq.stream.next,
171 struct cx25821_buffer, vb.stream);
172 } else {
173 /* read() capture */
174 buf = (struct cx25821_buffer *)fh->vidq.read_buf;
175 if (NULL == buf)
176 return POLLERR;
177 }
178
179 poll_wait(file, &buf->vb.done, wait);
180 if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR)
181 return POLLIN | POLLRDNORM;
182 return 0;
183}
184
185static int video_release(struct file *file)
186{
187 struct cx25821_fh *fh = file->private_data;
188 struct cx25821_dev *dev = fh->dev;
189
190 //stop the risc engine and fifo
191 //cx_write(channel11->dma_ctl, 0);
192
193 /* stop video capture */
194 if (cx25821_res_check(fh, RESOURCE_VIDEO11)) {
195 videobuf_queue_cancel(&fh->vidq);
196 cx25821_res_free(dev, fh, RESOURCE_VIDEO11);
197 }
198
199 if (fh->vidq.read_buf) {
200 cx25821_buffer_release(&fh->vidq, fh->vidq.read_buf);
201 kfree(fh->vidq.read_buf);
202 }
203
204 videobuf_mmap_free(&fh->vidq);
205
206 v4l2_prio_close(&dev->prio, fh->prio);
207
208 file->private_data = NULL;
209 kfree(fh);
210
211 return 0;
212}
213
214static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
215{
216 struct cx25821_fh *fh = priv;
217 struct cx25821_dev *dev = fh->dev;
218
219 if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)) {
220 return -EINVAL;
221 }
222
223 if (unlikely(i != fh->type)) {
224 return -EINVAL;
225 }
226
227 if (unlikely(!cx25821_res_get(dev, fh, cx25821_get_resource(fh, RESOURCE_VIDEO11)))) {
228 return -EBUSY;
229 }
230
231 return videobuf_streamon(get_queue(fh));
232}
233
234static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
235{
236 struct cx25821_fh *fh = priv;
237 struct cx25821_dev *dev = fh->dev;
238 int err, res;
239
240 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
241 return -EINVAL;
242 if (i != fh->type)
243 return -EINVAL;
244
245 res = cx25821_get_resource(fh, RESOURCE_VIDEO11);
246 err = videobuf_streamoff(get_queue(fh));
247 if (err < 0)
248 return err;
249 cx25821_res_free(dev, fh, res);
250 return 0;
251}
252
253static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
254 struct v4l2_format *f)
255{
256 struct cx25821_fh *fh = priv;
257 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
258 int err;
259
260 if (fh) {
261 err = v4l2_prio_check(&dev->prio, fh->prio);
262 if (0 != err)
263 return err;
264 }
265
266 dprintk(2, "%s()\n", __func__);
267 err = cx25821_vidioc_try_fmt_vid_cap(file, priv, f);
268
269 if (0 != err)
270 return err;
271 fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat);
272 fh->width = f->fmt.pix.width;
273 fh->height = f->fmt.pix.height;
274 fh->vidq.field = f->fmt.pix.field;
275 dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width,
276 fh->height, fh->vidq.field);
277 cx25821_call_all(dev, video, s_fmt, f);
278 return 0;
279}
280
281static long video_ioctl_upstream11(struct file *file, unsigned int cmd,
282 unsigned long arg)
283{
284 struct cx25821_fh *fh = file->private_data;
285 struct cx25821_dev *dev = fh->dev;
286 int command = 0;
287 struct upstream_user_struct *data_from_user;
288
289 data_from_user = (struct upstream_user_struct *)arg;
290
291 if (!data_from_user) {
292 printk
293 ("cx25821 in %s(): Upstream data is INVALID. Returning.\n",
294 __func__);
295 return 0;
296 }
297
298 command = data_from_user->command;
299
300 if (command != UPSTREAM_START_AUDIO && command != UPSTREAM_STOP_AUDIO) {
301 return 0;
302 }
303
304 dev->input_filename = data_from_user->input_filename;
305 dev->input_audiofilename = data_from_user->input_filename;
306 dev->vid_stdname = data_from_user->vid_stdname;
307 dev->pixel_format = data_from_user->pixel_format;
308 dev->channel_select = data_from_user->channel_select;
309 dev->command = data_from_user->command;
310
311 switch (command) {
312 case UPSTREAM_START_AUDIO:
313 cx25821_start_upstream_audio(dev, data_from_user);
314 break;
315
316 case UPSTREAM_STOP_AUDIO:
317 cx25821_stop_upstream_audio(dev);
318 break;
319 }
320
321 return 0;
322}
323
324static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
325{
326 struct cx25821_fh *fh = priv;
327 return videobuf_dqbuf(get_queue(fh), p, file->f_flags & O_NONBLOCK);
328}
329
330static int vidioc_log_status(struct file *file, void *priv)
331{
332 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
333 char name[32 + 2];
334
335 snprintf(name, sizeof(name), "%s/2", dev->name);
336 printk(KERN_INFO "%s/2: ============ START LOG STATUS ============\n",
337 dev->name);
338 cx25821_call_all(dev, core, log_status);
339 printk(KERN_INFO "%s/2: ============= END LOG STATUS =============\n",
340 dev->name);
341 return 0;
342}
343
344static int vidioc_s_ctrl(struct file *file, void *priv,
345 struct v4l2_control *ctl)
346{
347 struct cx25821_fh *fh = priv;
348 struct cx25821_dev *dev;
349 int err;
350
351 if (fh) {
352 dev = fh->dev;
353 err = v4l2_prio_check(&dev->prio, fh->prio);
354 if (0 != err)
355 return err;
356 }
357 return 0;
358}
359
360// exported stuff
361static const struct v4l2_file_operations video_fops = {
362 .owner = THIS_MODULE,
363 .open = video_open,
364 .release = video_release,
365 .read = video_read,
366 .poll = video_poll,
367 .mmap = cx25821_video_mmap,
368 .ioctl = video_ioctl_upstream11,
369};
370
371static const struct v4l2_ioctl_ops video_ioctl_ops = {
372 .vidioc_querycap = cx25821_vidioc_querycap,
373 .vidioc_enum_fmt_vid_cap = cx25821_vidioc_enum_fmt_vid_cap,
374 .vidioc_g_fmt_vid_cap = cx25821_vidioc_g_fmt_vid_cap,
375 .vidioc_try_fmt_vid_cap = cx25821_vidioc_try_fmt_vid_cap,
376 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
377 .vidioc_reqbufs = cx25821_vidioc_reqbufs,
378 .vidioc_querybuf = cx25821_vidioc_querybuf,
379 .vidioc_qbuf = cx25821_vidioc_qbuf,
380 .vidioc_dqbuf = vidioc_dqbuf,
381#ifdef TUNER_FLAG
382 .vidioc_s_std = cx25821_vidioc_s_std,
383 .vidioc_querystd = cx25821_vidioc_querystd,
384#endif
385 .vidioc_cropcap = cx25821_vidioc_cropcap,
386 .vidioc_s_crop = cx25821_vidioc_s_crop,
387 .vidioc_g_crop = cx25821_vidioc_g_crop,
388 .vidioc_enum_input = cx25821_vidioc_enum_input,
389 .vidioc_g_input = cx25821_vidioc_g_input,
390 .vidioc_s_input = cx25821_vidioc_s_input,
391 .vidioc_g_ctrl = cx25821_vidioc_g_ctrl,
392 .vidioc_s_ctrl = vidioc_s_ctrl,
393 .vidioc_queryctrl = cx25821_vidioc_queryctrl,
394 .vidioc_streamon = vidioc_streamon,
395 .vidioc_streamoff = vidioc_streamoff,
396 .vidioc_log_status = vidioc_log_status,
397 .vidioc_g_priority = cx25821_vidioc_g_priority,
398 .vidioc_s_priority = cx25821_vidioc_s_priority,
399#ifdef CONFIG_VIDEO_V4L1_COMPAT
400 .vidiocgmbuf = cx25821_vidiocgmbuf,
401#endif
402#ifdef TUNER_FLAG
403 .vidioc_g_tuner = cx25821_vidioc_g_tuner,
404 .vidioc_s_tuner = cx25821_vidioc_s_tuner,
405 .vidioc_g_frequency = cx25821_vidioc_g_frequency,
406 .vidioc_s_frequency = cx25821_vidioc_s_frequency,
407#endif
408#ifdef CONFIG_VIDEO_ADV_DEBUG
409 .vidioc_g_register = cx25821_vidioc_g_register,
410 .vidioc_s_register = cx25821_vidioc_s_register,
411#endif
412};
413
414struct video_device cx25821_video_template11 = {
415 .name = "cx25821-audioupstream",
416 .fops = &video_fops,
417 .ioctl_ops = &video_ioctl_ops,
418 .tvnorms = CX25821_NORMS,
419 .current_norm = V4L2_STD_NTSC_M,
420};
diff --git a/drivers/staging/cx25821/cx25821-core.c b/drivers/staging/cx25821/cx25821-core.c
index d90abb383fc8..c487c19256b9 100644
--- a/drivers/staging/cx25821/cx25821-core.c
+++ b/drivers/staging/cx25821/cx25821-core.c
@@ -781,14 +781,14 @@ static void cx25821_shutdown(struct cx25821_dev *dev)
781 781
782 /* Disable Video A/B activity */ 782 /* Disable Video A/B activity */
783 for (i = 0; i < VID_CHANNEL_NUM; i++) { 783 for (i = 0; i < VID_CHANNEL_NUM; i++) {
784 cx_write(dev->sram_channels[i].dma_ctl, 0); 784 cx_write(dev->channels[i].sram_channels->dma_ctl, 0);
785 cx_write(dev->sram_channels[i].int_msk, 0); 785 cx_write(dev->channels[i].sram_channels->int_msk, 0);
786 } 786 }
787 787
788 for (i = VID_UPSTREAM_SRAM_CHANNEL_I; i <= VID_UPSTREAM_SRAM_CHANNEL_J; 788 for (i = VID_UPSTREAM_SRAM_CHANNEL_I; i <= VID_UPSTREAM_SRAM_CHANNEL_J;
789 i++) { 789 i++) {
790 cx_write(dev->sram_channels[i].dma_ctl, 0); 790 cx_write(dev->channels[i].sram_channels->dma_ctl, 0);
791 cx_write(dev->sram_channels[i].int_msk, 0); 791 cx_write(dev->channels[i].sram_channels->int_msk, 0);
792 } 792 }
793 793
794 /* Disable Audio activity */ 794 /* Disable Audio activity */
@@ -805,12 +805,10 @@ static void cx25821_shutdown(struct cx25821_dev *dev)
805void cx25821_set_pixel_format(struct cx25821_dev *dev, int channel_select, 805void cx25821_set_pixel_format(struct cx25821_dev *dev, int channel_select,
806 u32 format) 806 u32 format)
807{ 807{
808 struct sram_channel *ch;
809
810 if (channel_select <= 7 && channel_select >= 0) { 808 if (channel_select <= 7 && channel_select >= 0) {
811 ch = &cx25821_sram_channels[channel_select]; 809 cx_write(dev->channels[channel_select].
812 cx_write(ch->pix_frmt, format); 810 sram_channels->pix_frmt, format);
813 dev->pixel_formats[channel_select] = format; 811 dev->channels[channel_select].pixel_formats = format;
814 } 812 }
815} 813}
816 814
@@ -831,7 +829,7 @@ static void cx25821_initialize(struct cx25821_dev *dev)
831 cx_write(PCI_INT_STAT, 0xffffffff); 829 cx_write(PCI_INT_STAT, 0xffffffff);
832 830
833 for (i = 0; i < VID_CHANNEL_NUM; i++) 831 for (i = 0; i < VID_CHANNEL_NUM; i++)
834 cx_write(dev->sram_channels[i].int_stat, 0xffffffff); 832 cx_write(dev->channels[i].sram_channels->int_stat, 0xffffffff);
835 833
836 cx_write(AUD_A_INT_STAT, 0xffffffff); 834 cx_write(AUD_A_INT_STAT, 0xffffffff);
837 cx_write(AUD_B_INT_STAT, 0xffffffff); 835 cx_write(AUD_B_INT_STAT, 0xffffffff);
@@ -845,21 +843,22 @@ static void cx25821_initialize(struct cx25821_dev *dev)
845 mdelay(100); 843 mdelay(100);
846 844
847 for (i = 0; i < VID_CHANNEL_NUM; i++) { 845 for (i = 0; i < VID_CHANNEL_NUM; i++) {
848 cx25821_set_vip_mode(dev, &dev->sram_channels[i]); 846 cx25821_set_vip_mode(dev, dev->channels[i].sram_channels);
849 cx25821_sram_channel_setup(dev, &dev->sram_channels[i], 1440, 847 cx25821_sram_channel_setup(dev, dev->channels[i].sram_channels,
850 0); 848 1440, 0);
851 dev->pixel_formats[i] = PIXEL_FRMT_422; 849 dev->channels[i].pixel_formats = PIXEL_FRMT_422;
852 dev->use_cif_resolution[i] = FALSE; 850 dev->channels[i].use_cif_resolution = FALSE;
853 } 851 }
854 852
855 /* Probably only affect Downstream */ 853 /* Probably only affect Downstream */
856 for (i = VID_UPSTREAM_SRAM_CHANNEL_I; i <= VID_UPSTREAM_SRAM_CHANNEL_J; 854 for (i = VID_UPSTREAM_SRAM_CHANNEL_I; i <= VID_UPSTREAM_SRAM_CHANNEL_J;
857 i++) { 855 i++) {
858 cx25821_set_vip_mode(dev, &dev->sram_channels[i]); 856 cx25821_set_vip_mode(dev, dev->channels[i].sram_channels);
859 } 857 }
860 858
861 cx25821_sram_channel_setup_audio(dev, &dev->sram_channels[SRAM_CH08], 859 cx25821_sram_channel_setup_audio(dev,
862 128, 0); 860 dev->channels[SRAM_CH08].sram_channels,
861 128, 0);
863 862
864 cx25821_gpio_init(dev); 863 cx25821_gpio_init(dev);
865} 864}
@@ -902,21 +901,6 @@ static int cx25821_dev_setup(struct cx25821_dev *dev)
902{ 901{
903 int io_size = 0, i; 902 int io_size = 0, i;
904 903
905 struct video_device *video_template[] = {
906 &cx25821_video_template0,
907 &cx25821_video_template1,
908 &cx25821_video_template2,
909 &cx25821_video_template3,
910 &cx25821_video_template4,
911 &cx25821_video_template5,
912 &cx25821_video_template6,
913 &cx25821_video_template7,
914 &cx25821_video_template9,
915 &cx25821_video_template10,
916 &cx25821_video_template11,
917 &cx25821_videoioctl_template,
918 };
919
920 printk(KERN_INFO "\n***********************************\n"); 904 printk(KERN_INFO "\n***********************************\n");
921 printk(KERN_INFO "cx25821 set up\n"); 905 printk(KERN_INFO "cx25821 set up\n");
922 printk(KERN_INFO "***********************************\n\n"); 906 printk(KERN_INFO "***********************************\n\n");
@@ -947,7 +931,8 @@ static int cx25821_dev_setup(struct cx25821_dev *dev)
947 931
948 /* Apply a sensible clock frequency for the PCIe bridge */ 932 /* Apply a sensible clock frequency for the PCIe bridge */
949 dev->clk_freq = 28000000; 933 dev->clk_freq = 28000000;
950 dev->sram_channels = cx25821_sram_channels; 934 for (i = 0; i < MAX_VID_CHANNEL_NUM; i++)
935 dev->channels[i].sram_channels = &cx25821_sram_channels[i];
951 936
952 if (dev->nr > 1) 937 if (dev->nr > 1)
953 CX25821_INFO("dev->nr > 1!"); 938 CX25821_INFO("dev->nr > 1!");
@@ -970,7 +955,6 @@ static int cx25821_dev_setup(struct cx25821_dev *dev)
970 dev->i2c_bus[0].reg_wdata = I2C1_WDATA; 955 dev->i2c_bus[0].reg_wdata = I2C1_WDATA;
971 dev->i2c_bus[0].i2c_period = (0x07 << 24); /* 1.95MHz */ 956 dev->i2c_bus[0].i2c_period = (0x07 << 24); /* 1.95MHz */
972 957
973
974 if (cx25821_get_resources(dev) < 0) { 958 if (cx25821_get_resources(dev) < 0) {
975 printk(KERN_ERR "%s No more PCIe resources for " 959 printk(KERN_ERR "%s No more PCIe resources for "
976 "subsystem: %04x:%04x\n", 960 "subsystem: %04x:%04x\n",
@@ -1018,37 +1002,24 @@ static int cx25821_dev_setup(struct cx25821_dev *dev)
1018 dev->i2c_bus[0].i2c_rc); 1002 dev->i2c_bus[0].i2c_rc);
1019 1003
1020 cx25821_card_setup(dev); 1004 cx25821_card_setup(dev);
1021 medusa_video_init(dev);
1022 1005
1023 for (i = 0; i < VID_CHANNEL_NUM; i++) { 1006 if (medusa_video_init(dev) < 0)
1024 if (cx25821_video_register(dev, i, video_template[i]) < 0) { 1007 CX25821_ERR("%s() Failed to initialize medusa!\n"
1025 printk(KERN_ERR 1008 , __func__);
1026 "%s() Failed to register analog video adapters on VID channel %d\n",
1027 __func__, i);
1028 }
1029 }
1030 1009
1031 for (i = VID_UPSTREAM_SRAM_CHANNEL_I; 1010 cx25821_video_register(dev);
1032 i <= AUDIO_UPSTREAM_SRAM_CHANNEL_B; i++) {
1033 /* Since we don't have template8 for Audio Downstream */
1034 if (cx25821_video_register(dev, i, video_template[i - 1]) < 0) {
1035 printk(KERN_ERR
1036 "%s() Failed to register analog video adapters for Upstream channel %d.\n",
1037 __func__, i);
1038 }
1039 }
1040 1011
1041 /* register IOCTL device */ 1012 /* register IOCTL device */
1042 dev->ioctl_dev = 1013 dev->ioctl_dev =
1043 cx25821_vdev_init(dev, dev->pci, video_template[VIDEO_IOCTL_CH], 1014 cx25821_vdev_init(dev, dev->pci, &cx25821_videoioctl_template,
1044 "video"); 1015 "video");
1045 1016
1046 if (video_register_device 1017 if (video_register_device
1047 (dev->ioctl_dev, VFL_TYPE_GRABBER, VIDEO_IOCTL_CH) < 0) { 1018 (dev->ioctl_dev, VFL_TYPE_GRABBER, VIDEO_IOCTL_CH) < 0) {
1048 cx25821_videoioctl_unregister(dev); 1019 cx25821_videoioctl_unregister(dev);
1049 printk(KERN_ERR 1020 printk(KERN_ERR
1050 "%s() Failed to register video adapter for IOCTL so releasing.\n", 1021 "%s() Failed to register video adapter for IOCTL, so \
1051 __func__); 1022 unregistering videoioctl device.\n", __func__);
1052 } 1023 }
1053 1024
1054 cx25821_dev_checkrevision(dev); 1025 cx25821_dev_checkrevision(dev);
@@ -1349,7 +1320,7 @@ void cx25821_free_buffer(struct videobuf_queue *q, struct cx25821_buffer *buf)
1349 1320
1350 BUG_ON(in_interrupt()); 1321 BUG_ON(in_interrupt());
1351 videobuf_waiton(&buf->vb, 0, 0); 1322 videobuf_waiton(&buf->vb, 0, 0);
1352 videobuf_dma_unmap(q, dma); 1323 videobuf_dma_unmap(q->dev, dma);
1353 videobuf_dma_free(dma); 1324 videobuf_dma_free(dma);
1354 btcx_riscmem_free(to_pci_dev(q->dev), &buf->risc); 1325 btcx_riscmem_free(to_pci_dev(q->dev), &buf->risc);
1355 buf->vb.state = VIDEOBUF_NEEDS_INIT; 1326 buf->vb.state = VIDEOBUF_NEEDS_INIT;
@@ -1371,7 +1342,8 @@ static irqreturn_t cx25821_irq(int irq, void *dev_id)
1371 1342
1372 for (i = 0; i < VID_CHANNEL_NUM; i++) { 1343 for (i = 0; i < VID_CHANNEL_NUM; i++) {
1373 if (pci_status & mask[i]) { 1344 if (pci_status & mask[i]) {
1374 vid_status = cx_read(dev->sram_channels[i].int_stat); 1345 vid_status = cx_read(dev->channels[i].
1346 sram_channels->int_stat);
1375 1347
1376 if (vid_status) 1348 if (vid_status)
1377 handled += 1349 handled +=
diff --git a/drivers/staging/cx25821/cx25821-i2c.c b/drivers/staging/cx25821/cx25821-i2c.c
index 08f45b52df6a..e43572e61ece 100644
--- a/drivers/staging/cx25821/cx25821-i2c.c
+++ b/drivers/staging/cx25821/cx25821-i2c.c
@@ -282,6 +282,9 @@ static u32 cx25821_functionality(struct i2c_adapter *adap)
282static struct i2c_algorithm cx25821_i2c_algo_template = { 282static struct i2c_algorithm cx25821_i2c_algo_template = {
283 .master_xfer = i2c_xfer, 283 .master_xfer = i2c_xfer,
284 .functionality = cx25821_functionality, 284 .functionality = cx25821_functionality,
285#ifdef NEED_ALGO_CONTROL
286 .algo_control = dummy_algo_control,
287#endif
285}; 288};
286 289
287static struct i2c_adapter cx25821_i2c_adap_template = { 290static struct i2c_adapter cx25821_i2c_adap_template = {
diff --git a/drivers/staging/cx25821/cx25821-medusa-defines.h b/drivers/staging/cx25821/cx25821-medusa-defines.h
index b0d216ba7f81..60d197f57556 100644
--- a/drivers/staging/cx25821/cx25821-medusa-defines.h
+++ b/drivers/staging/cx25821/cx25821-medusa-defines.h
@@ -23,7 +23,7 @@
23#ifndef _MEDUSA_DEF_H_ 23#ifndef _MEDUSA_DEF_H_
24#define _MEDUSA_DEF_H_ 24#define _MEDUSA_DEF_H_
25 25
26// Video deocder that we supported 26/* Video deocder that we supported */
27#define VDEC_A 0 27#define VDEC_A 0
28#define VDEC_B 1 28#define VDEC_B 1
29#define VDEC_C 2 29#define VDEC_C 2
@@ -33,19 +33,10 @@
33#define VDEC_G 6 33#define VDEC_G 6
34#define VDEC_H 7 34#define VDEC_H 7
35 35
36//#define AUTO_SWITCH_BIT[] = { 8, 9, 10, 11, 12, 13, 14, 15 }; 36/* end of display sequence */
37
38// The following bit position enables automatic source switching for decoder A-H.
39// Display index per camera.
40//#define VDEC_INDEX[] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7};
41
42// Select input bit to video decoder A-H.
43//#define CH_SRC_SEL_BIT[] = {24, 25, 26, 27, 28, 29, 30, 31};
44
45// end of display sequence
46#define END_OF_SEQ 0xF; 37#define END_OF_SEQ 0xF;
47 38
48// registry string size 39/* registry string size */
49#define MAX_REGISTRY_SZ 40; 40#define MAX_REGISTRY_SZ 40;
50 41
51#endif 42#endif
diff --git a/drivers/staging/cx25821/cx25821-medusa-reg.h b/drivers/staging/cx25821/cx25821-medusa-reg.h
index 12c90f831b22..f7f33b3e7058 100644
--- a/drivers/staging/cx25821/cx25821-medusa-reg.h
+++ b/drivers/staging/cx25821/cx25821-medusa-reg.h
@@ -23,11 +23,11 @@
23#ifndef __MEDUSA_REGISTERS__ 23#ifndef __MEDUSA_REGISTERS__
24#define __MEDUSA_REGISTERS__ 24#define __MEDUSA_REGISTERS__
25 25
26// Serial Slave Registers 26/* Serial Slave Registers */
27#define HOST_REGISTER1 0x0000 27#define HOST_REGISTER1 0x0000
28#define HOST_REGISTER2 0x0001 28#define HOST_REGISTER2 0x0001
29 29
30// Chip Configuration Registers 30/* Chip Configuration Registers */
31#define CHIP_CTRL 0x0100 31#define CHIP_CTRL 0x0100
32#define AFE_AB_CTRL 0x0104 32#define AFE_AB_CTRL 0x0104
33#define AFE_CD_CTRL 0x0108 33#define AFE_CD_CTRL 0x0108
@@ -92,7 +92,7 @@
92#define ABIST_CLAMP_E 0x01F4 92#define ABIST_CLAMP_E 0x01F4
93#define ABIST_CLAMP_F 0x01F8 93#define ABIST_CLAMP_F 0x01F8
94 94
95// Digital Video Encoder A Registers 95/* Digital Video Encoder A Registers */
96#define DENC_A_REG_1 0x0200 96#define DENC_A_REG_1 0x0200
97#define DENC_A_REG_2 0x0204 97#define DENC_A_REG_2 0x0204
98#define DENC_A_REG_3 0x0208 98#define DENC_A_REG_3 0x0208
@@ -102,7 +102,7 @@
102#define DENC_A_REG_7 0x0218 102#define DENC_A_REG_7 0x0218
103#define DENC_A_REG_8 0x021C 103#define DENC_A_REG_8 0x021C
104 104
105// Digital Video Encoder B Registers 105/* Digital Video Encoder B Registers */
106#define DENC_B_REG_1 0x0300 106#define DENC_B_REG_1 0x0300
107#define DENC_B_REG_2 0x0304 107#define DENC_B_REG_2 0x0304
108#define DENC_B_REG_3 0x0308 108#define DENC_B_REG_3 0x0308
@@ -112,7 +112,7 @@
112#define DENC_B_REG_7 0x0318 112#define DENC_B_REG_7 0x0318
113#define DENC_B_REG_8 0x031C 113#define DENC_B_REG_8 0x031C
114 114
115// Video Decoder A Registers 115/* Video Decoder A Registers */
116#define MODE_CTRL 0x1000 116#define MODE_CTRL 0x1000
117#define OUT_CTRL1 0x1004 117#define OUT_CTRL1 0x1004
118#define OUT_CTRL_NS 0x1008 118#define OUT_CTRL_NS 0x1008
@@ -153,7 +153,7 @@
153#define VERSION 0x11F8 153#define VERSION 0x11F8
154#define SOFT_RST_CTRL 0x11FC 154#define SOFT_RST_CTRL 0x11FC
155 155
156// Video Decoder B Registers 156/* Video Decoder B Registers */
157#define VDEC_B_MODE_CTRL 0x1200 157#define VDEC_B_MODE_CTRL 0x1200
158#define VDEC_B_OUT_CTRL1 0x1204 158#define VDEC_B_OUT_CTRL1 0x1204
159#define VDEC_B_OUT_CTRL_NS 0x1208 159#define VDEC_B_OUT_CTRL_NS 0x1208
@@ -194,7 +194,7 @@
194#define VDEC_B_VERSION 0x13F8 194#define VDEC_B_VERSION 0x13F8
195#define VDEC_B_SOFT_RST_CTRL 0x13FC 195#define VDEC_B_SOFT_RST_CTRL 0x13FC
196 196
197// Video Decoder C Registers 197/* Video Decoder C Registers */
198#define VDEC_C_MODE_CTRL 0x1400 198#define VDEC_C_MODE_CTRL 0x1400
199#define VDEC_C_OUT_CTRL1 0x1404 199#define VDEC_C_OUT_CTRL1 0x1404
200#define VDEC_C_OUT_CTRL_NS 0x1408 200#define VDEC_C_OUT_CTRL_NS 0x1408
@@ -235,7 +235,7 @@
235#define VDEC_C_VERSION 0x15F8 235#define VDEC_C_VERSION 0x15F8
236#define VDEC_C_SOFT_RST_CTRL 0x15FC 236#define VDEC_C_SOFT_RST_CTRL 0x15FC
237 237
238// Video Decoder D Registers 238/* Video Decoder D Registers */
239#define VDEC_D_MODE_CTRL 0x1600 239#define VDEC_D_MODE_CTRL 0x1600
240#define VDEC_D_OUT_CTRL1 0x1604 240#define VDEC_D_OUT_CTRL1 0x1604
241#define VDEC_D_OUT_CTRL_NS 0x1608 241#define VDEC_D_OUT_CTRL_NS 0x1608
@@ -276,7 +276,7 @@
276#define VDEC_D_VERSION 0x17F8 276#define VDEC_D_VERSION 0x17F8
277#define VDEC_D_SOFT_RST_CTRL 0x17FC 277#define VDEC_D_SOFT_RST_CTRL 0x17FC
278 278
279// Video Decoder E Registers 279/* Video Decoder E Registers */
280#define VDEC_E_MODE_CTRL 0x1800 280#define VDEC_E_MODE_CTRL 0x1800
281#define VDEC_E_OUT_CTRL1 0x1804 281#define VDEC_E_OUT_CTRL1 0x1804
282#define VDEC_E_OUT_CTRL_NS 0x1808 282#define VDEC_E_OUT_CTRL_NS 0x1808
@@ -317,7 +317,7 @@
317#define VDEC_E_VERSION 0x19F8 317#define VDEC_E_VERSION 0x19F8
318#define VDEC_E_SOFT_RST_CTRL 0x19FC 318#define VDEC_E_SOFT_RST_CTRL 0x19FC
319 319
320// Video Decoder F Registers 320/* Video Decoder F Registers */
321#define VDEC_F_MODE_CTRL 0x1A00 321#define VDEC_F_MODE_CTRL 0x1A00
322#define VDEC_F_OUT_CTRL1 0x1A04 322#define VDEC_F_OUT_CTRL1 0x1A04
323#define VDEC_F_OUT_CTRL_NS 0x1A08 323#define VDEC_F_OUT_CTRL_NS 0x1A08
@@ -358,7 +358,7 @@
358#define VDEC_F_VERSION 0x1BF8 358#define VDEC_F_VERSION 0x1BF8
359#define VDEC_F_SOFT_RST_CTRL 0x1BFC 359#define VDEC_F_SOFT_RST_CTRL 0x1BFC
360 360
361// Video Decoder G Registers 361/* Video Decoder G Registers */
362#define VDEC_G_MODE_CTRL 0x1C00 362#define VDEC_G_MODE_CTRL 0x1C00
363#define VDEC_G_OUT_CTRL1 0x1C04 363#define VDEC_G_OUT_CTRL1 0x1C04
364#define VDEC_G_OUT_CTRL_NS 0x1C08 364#define VDEC_G_OUT_CTRL_NS 0x1C08
@@ -399,7 +399,7 @@
399#define VDEC_G_VERSION 0x1DF8 399#define VDEC_G_VERSION 0x1DF8
400#define VDEC_G_SOFT_RST_CTRL 0x1DFC 400#define VDEC_G_SOFT_RST_CTRL 0x1DFC
401 401
402// Video Decoder H Registers 402/* Video Decoder H Registers */
403#define VDEC_H_MODE_CTRL 0x1E00 403#define VDEC_H_MODE_CTRL 0x1E00
404#define VDEC_H_OUT_CTRL1 0x1E04 404#define VDEC_H_OUT_CTRL1 0x1E04
405#define VDEC_H_OUT_CTRL_NS 0x1E08 405#define VDEC_H_OUT_CTRL_NS 0x1E08
@@ -440,14 +440,14 @@
440#define VDEC_H_VERSION 0x1FF8 440#define VDEC_H_VERSION 0x1FF8
441#define VDEC_H_SOFT_RST_CTRL 0x1FFC 441#define VDEC_H_SOFT_RST_CTRL 0x1FFC
442 442
443//***************************************************************************** 443/*****************************************************************************/
444// LUMA_CTRL register fields 444/* LUMA_CTRL register fields */
445#define VDEC_A_BRITE_CTRL 0x1014 445#define VDEC_A_BRITE_CTRL 0x1014
446#define VDEC_A_CNTRST_CTRL 0x1015 446#define VDEC_A_CNTRST_CTRL 0x1015
447#define VDEC_A_PEAK_SEL 0x1016 447#define VDEC_A_PEAK_SEL 0x1016
448 448
449//***************************************************************************** 449/*****************************************************************************/
450// CHROMA_CTRL register fields 450/* CHROMA_CTRL register fields */
451#define VDEC_A_USAT_CTRL 0x1018 451#define VDEC_A_USAT_CTRL 0x1018
452#define VDEC_A_VSAT_CTRL 0x1019 452#define VDEC_A_VSAT_CTRL 0x1019
453#define VDEC_A_HUE_CTRL 0x101A 453#define VDEC_A_HUE_CTRL 0x101A
diff --git a/drivers/staging/cx25821/cx25821-medusa-video.c b/drivers/staging/cx25821/cx25821-medusa-video.c
index 34616dc507f9..ef9f2b82a860 100644
--- a/drivers/staging/cx25821/cx25821-medusa-video.c
+++ b/drivers/staging/cx25821/cx25821-medusa-video.c
@@ -778,9 +778,9 @@ int medusa_set_saturation(struct cx25821_dev *dev, int saturation, int decoder)
778 778
779int medusa_video_init(struct cx25821_dev *dev) 779int medusa_video_init(struct cx25821_dev *dev)
780{ 780{
781 u32 value, tmp = 0; 781 u32 value = 0, tmp = 0;
782 int ret_val; 782 int ret_val = 0;
783 int i; 783 int i = 0;
784 784
785 mutex_lock(&dev->lock); 785 mutex_lock(&dev->lock);
786 786
@@ -790,6 +790,7 @@ int medusa_video_init(struct cx25821_dev *dev)
790 value = cx25821_i2c_read(&dev->i2c_bus[0], MON_A_CTRL, &tmp); 790 value = cx25821_i2c_read(&dev->i2c_bus[0], MON_A_CTRL, &tmp);
791 value &= 0xFFFFF0FF; 791 value &= 0xFFFFF0FF;
792 ret_val = cx25821_i2c_write(&dev->i2c_bus[0], MON_A_CTRL, value); 792 ret_val = cx25821_i2c_write(&dev->i2c_bus[0], MON_A_CTRL, value);
793
793 if (ret_val < 0) 794 if (ret_val < 0)
794 goto error; 795 goto error;
795 796
@@ -797,6 +798,7 @@ int medusa_video_init(struct cx25821_dev *dev)
797 value = cx25821_i2c_read(&dev->i2c_bus[0], MON_A_CTRL, &tmp); 798 value = cx25821_i2c_read(&dev->i2c_bus[0], MON_A_CTRL, &tmp);
798 value &= 0xFFFFFFDF; 799 value &= 0xFFFFFFDF;
799 ret_val = cx25821_i2c_write(&dev->i2c_bus[0], MON_A_CTRL, value); 800 ret_val = cx25821_i2c_write(&dev->i2c_bus[0], MON_A_CTRL, value);
801
800 if (ret_val < 0) 802 if (ret_val < 0)
801 goto error; 803 goto error;
802 804
@@ -812,6 +814,7 @@ int medusa_video_init(struct cx25821_dev *dev)
812 value &= 0xFF70FF70; 814 value &= 0xFF70FF70;
813 value |= 0x00090008; /* set en_active */ 815 value |= 0x00090008; /* set en_active */
814 ret_val = cx25821_i2c_write(&dev->i2c_bus[0], DENC_AB_CTRL, value); 816 ret_val = cx25821_i2c_write(&dev->i2c_bus[0], DENC_AB_CTRL, value);
817
815 if (ret_val < 0) 818 if (ret_val < 0)
816 goto error; 819 goto error;
817 820
@@ -826,8 +829,10 @@ int medusa_video_init(struct cx25821_dev *dev)
826 /* select AFE clock to output mode */ 829 /* select AFE clock to output mode */
827 value = cx25821_i2c_read(&dev->i2c_bus[0], AFE_AB_DIAG_CTRL, &tmp); 830 value = cx25821_i2c_read(&dev->i2c_bus[0], AFE_AB_DIAG_CTRL, &tmp);
828 value &= 0x83FFFFFF; 831 value &= 0x83FFFFFF;
829 ret_val = cx25821_i2c_write(&dev->i2c_bus[0], AFE_AB_DIAG_CTRL, 832 ret_val =
830 value | 0x10000000); 833 cx25821_i2c_write(&dev->i2c_bus[0], AFE_AB_DIAG_CTRL,
834 value | 0x10000000);
835
831 if (ret_val < 0) 836 if (ret_val < 0)
832 goto error; 837 goto error;
833 838
@@ -849,12 +854,15 @@ int medusa_video_init(struct cx25821_dev *dev)
849 854
850 value |= 7; 855 value |= 7;
851 ret_val = cx25821_i2c_write(&dev->i2c_bus[0], PIN_OE_CTRL, value); 856 ret_val = cx25821_i2c_write(&dev->i2c_bus[0], PIN_OE_CTRL, value);
857
852 if (ret_val < 0) 858 if (ret_val < 0)
853 goto error; 859 goto error;
854 860
861
855 mutex_unlock(&dev->lock); 862 mutex_unlock(&dev->lock);
856 863
857 ret_val = medusa_set_videostandard(dev); 864 ret_val = medusa_set_videostandard(dev);
865
858 return ret_val; 866 return ret_val;
859 867
860error: 868error:
diff --git a/drivers/staging/cx25821/cx25821-medusa-video.h b/drivers/staging/cx25821/cx25821-medusa-video.h
index 2fab4b2f251c..6175e0961855 100644
--- a/drivers/staging/cx25821/cx25821-medusa-video.h
+++ b/drivers/staging/cx25821/cx25821-medusa-video.h
@@ -25,7 +25,7 @@
25 25
26#include "cx25821-medusa-defines.h" 26#include "cx25821-medusa-defines.h"
27 27
28// Color control constants 28/* Color control constants */
29#define VIDEO_PROCAMP_MIN 0 29#define VIDEO_PROCAMP_MIN 0
30#define VIDEO_PROCAMP_MAX 10000 30#define VIDEO_PROCAMP_MAX 10000
31#define UNSIGNED_BYTE_MIN 0 31#define UNSIGNED_BYTE_MIN 0
@@ -33,7 +33,7 @@
33#define SIGNED_BYTE_MIN -128 33#define SIGNED_BYTE_MIN -128
34#define SIGNED_BYTE_MAX 127 34#define SIGNED_BYTE_MAX 127
35 35
36// Default video color settings 36/* Default video color settings */
37#define SHARPNESS_DEFAULT 50 37#define SHARPNESS_DEFAULT 50
38#define SATURATION_DEFAULT 5000 38#define SATURATION_DEFAULT 5000
39#define BRIGHTNESS_DEFAULT 6200 39#define BRIGHTNESS_DEFAULT 6200
diff --git a/drivers/staging/cx25821/cx25821-reg.h b/drivers/staging/cx25821/cx25821-reg.h
index 7241e7ee3fd3..cfe0f32db377 100644
--- a/drivers/staging/cx25821/cx25821-reg.h
+++ b/drivers/staging/cx25821/cx25821-reg.h
@@ -48,24 +48,24 @@
48#define RISC_SYNC_EVEN_VBI 0x00000207 48#define RISC_SYNC_EVEN_VBI 0x00000207
49#define RISC_NOOP 0xF0000000 49#define RISC_NOOP 0xF0000000
50 50
51//***************************************************************************** 51/*****************************************************************************
52// ASB SRAM 52* ASB SRAM
53//***************************************************************************** 53 *****************************************************************************/
54#define TX_SRAM 0x000000 // Transmit SRAM 54#define TX_SRAM 0x000000 /* Transmit SRAM */
55 55
56//***************************************************************************** 56/*****************************************************************************/
57#define RX_RAM 0x010000 // Receive SRAM 57#define RX_RAM 0x010000 /* Receive SRAM */
58 58
59//***************************************************************************** 59/*****************************************************************************
60// Application Layer (AL) 60* Application Layer (AL)
61//***************************************************************************** 61 *****************************************************************************/
62#define DEV_CNTRL2 0x040000 // Device control 62#define DEV_CNTRL2 0x040000 /* Device control */
63#define FLD_RUN_RISC 0x00000020 63#define FLD_RUN_RISC 0x00000020
64 64
65//***************************************************************************** 65/* ***************************************************************************** */
66#define PCI_INT_MSK 0x040010 // PCI interrupt mask 66#define PCI_INT_MSK 0x040010 /* PCI interrupt mask */
67#define PCI_INT_STAT 0x040014 // PCI interrupt status 67#define PCI_INT_STAT 0x040014 /* PCI interrupt status */
68#define PCI_INT_MSTAT 0x040018 // PCI interrupt masked status 68#define PCI_INT_MSTAT 0x040018 /* PCI interrupt masked status */
69#define FLD_HAMMERHEAD_INT (1 << 27) 69#define FLD_HAMMERHEAD_INT (1 << 27)
70#define FLD_UART_INT (1 << 26) 70#define FLD_UART_INT (1 << 26)
71#define FLD_IRQN_INT (1 << 25) 71#define FLD_IRQN_INT (1 << 25)
@@ -93,65 +93,65 @@
93#define FLD_VID_B_INT (1 << 1) 93#define FLD_VID_B_INT (1 << 1)
94#define FLD_VID_A_INT (1 << 0) 94#define FLD_VID_A_INT (1 << 0)
95 95
96//***************************************************************************** 96/* ***************************************************************************** */
97#define VID_A_INT_MSK 0x040020 // Video A interrupt mask 97#define VID_A_INT_MSK 0x040020 /* Video A interrupt mask */
98#define VID_A_INT_STAT 0x040024 // Video A interrupt status 98#define VID_A_INT_STAT 0x040024 /* Video A interrupt status */
99#define VID_A_INT_MSTAT 0x040028 // Video A interrupt masked status 99#define VID_A_INT_MSTAT 0x040028 /* Video A interrupt masked status */
100#define VID_A_INT_SSTAT 0x04002C // Video A interrupt set status 100#define VID_A_INT_SSTAT 0x04002C /* Video A interrupt set status */
101 101
102//***************************************************************************** 102/* ***************************************************************************** */
103#define VID_B_INT_MSK 0x040030 // Video B interrupt mask 103#define VID_B_INT_MSK 0x040030 /* Video B interrupt mask */
104#define VID_B_INT_STAT 0x040034 // Video B interrupt status 104#define VID_B_INT_STAT 0x040034 /* Video B interrupt status */
105#define VID_B_INT_MSTAT 0x040038 // Video B interrupt masked status 105#define VID_B_INT_MSTAT 0x040038 /* Video B interrupt masked status */
106#define VID_B_INT_SSTAT 0x04003C // Video B interrupt set status 106#define VID_B_INT_SSTAT 0x04003C /* Video B interrupt set status */
107 107
108//***************************************************************************** 108/* ***************************************************************************** */
109#define VID_C_INT_MSK 0x040040 // Video C interrupt mask 109#define VID_C_INT_MSK 0x040040 /* Video C interrupt mask */
110#define VID_C_INT_STAT 0x040044 // Video C interrupt status 110#define VID_C_INT_STAT 0x040044 /* Video C interrupt status */
111#define VID_C_INT_MSTAT 0x040048 // Video C interrupt masked status 111#define VID_C_INT_MSTAT 0x040048 /* Video C interrupt masked status */
112#define VID_C_INT_SSTAT 0x04004C // Video C interrupt set status 112#define VID_C_INT_SSTAT 0x04004C /* Video C interrupt set status */
113 113
114//***************************************************************************** 114/* ***************************************************************************** */
115#define VID_D_INT_MSK 0x040050 // Video D interrupt mask 115#define VID_D_INT_MSK 0x040050 /* Video D interrupt mask */
116#define VID_D_INT_STAT 0x040054 // Video D interrupt status 116#define VID_D_INT_STAT 0x040054 /* Video D interrupt status */
117#define VID_D_INT_MSTAT 0x040058 // Video D interrupt masked status 117#define VID_D_INT_MSTAT 0x040058 /* Video D interrupt masked status */
118#define VID_D_INT_SSTAT 0x04005C // Video D interrupt set status 118#define VID_D_INT_SSTAT 0x04005C /* Video D interrupt set status */
119 119
120//***************************************************************************** 120/* ***************************************************************************** */
121#define VID_E_INT_MSK 0x040060 // Video E interrupt mask 121#define VID_E_INT_MSK 0x040060 /* Video E interrupt mask */
122#define VID_E_INT_STAT 0x040064 // Video E interrupt status 122#define VID_E_INT_STAT 0x040064 /* Video E interrupt status */
123#define VID_E_INT_MSTAT 0x040068 // Video E interrupt masked status 123#define VID_E_INT_MSTAT 0x040068 /* Video E interrupt masked status */
124#define VID_E_INT_SSTAT 0x04006C // Video E interrupt set status 124#define VID_E_INT_SSTAT 0x04006C /* Video E interrupt set status */
125 125
126//***************************************************************************** 126/* ***************************************************************************** */
127#define VID_F_INT_MSK 0x040070 // Video F interrupt mask 127#define VID_F_INT_MSK 0x040070 /* Video F interrupt mask */
128#define VID_F_INT_STAT 0x040074 // Video F interrupt status 128#define VID_F_INT_STAT 0x040074 /* Video F interrupt status */
129#define VID_F_INT_MSTAT 0x040078 // Video F interrupt masked status 129#define VID_F_INT_MSTAT 0x040078 /* Video F interrupt masked status */
130#define VID_F_INT_SSTAT 0x04007C // Video F interrupt set status 130#define VID_F_INT_SSTAT 0x04007C /* Video F interrupt set status */
131 131
132//***************************************************************************** 132/* ***************************************************************************** */
133#define VID_G_INT_MSK 0x040080 // Video G interrupt mask 133#define VID_G_INT_MSK 0x040080 /* Video G interrupt mask */
134#define VID_G_INT_STAT 0x040084 // Video G interrupt status 134#define VID_G_INT_STAT 0x040084 /* Video G interrupt status */
135#define VID_G_INT_MSTAT 0x040088 // Video G interrupt masked status 135#define VID_G_INT_MSTAT 0x040088 /* Video G interrupt masked status */
136#define VID_G_INT_SSTAT 0x04008C // Video G interrupt set status 136#define VID_G_INT_SSTAT 0x04008C /* Video G interrupt set status */
137 137
138//***************************************************************************** 138/* ***************************************************************************** */
139#define VID_H_INT_MSK 0x040090 // Video H interrupt mask 139#define VID_H_INT_MSK 0x040090 /* Video H interrupt mask */
140#define VID_H_INT_STAT 0x040094 // Video H interrupt status 140#define VID_H_INT_STAT 0x040094 /* Video H interrupt status */
141#define VID_H_INT_MSTAT 0x040098 // Video H interrupt masked status 141#define VID_H_INT_MSTAT 0x040098 /* Video H interrupt masked status */
142#define VID_H_INT_SSTAT 0x04009C // Video H interrupt set status 142#define VID_H_INT_SSTAT 0x04009C /* Video H interrupt set status */
143 143
144//***************************************************************************** 144/* ***************************************************************************** */
145#define VID_I_INT_MSK 0x0400A0 // Video I interrupt mask 145#define VID_I_INT_MSK 0x0400A0 /* Video I interrupt mask */
146#define VID_I_INT_STAT 0x0400A4 // Video I interrupt status 146#define VID_I_INT_STAT 0x0400A4 /* Video I interrupt status */
147#define VID_I_INT_MSTAT 0x0400A8 // Video I interrupt masked status 147#define VID_I_INT_MSTAT 0x0400A8 /* Video I interrupt masked status */
148#define VID_I_INT_SSTAT 0x0400AC // Video I interrupt set status 148#define VID_I_INT_SSTAT 0x0400AC /* Video I interrupt set status */
149 149
150//***************************************************************************** 150/* ***************************************************************************** */
151#define VID_J_INT_MSK 0x0400B0 // Video J interrupt mask 151#define VID_J_INT_MSK 0x0400B0 /* Video J interrupt mask */
152#define VID_J_INT_STAT 0x0400B4 // Video J interrupt status 152#define VID_J_INT_STAT 0x0400B4 /* Video J interrupt status */
153#define VID_J_INT_MSTAT 0x0400B8 // Video J interrupt masked status 153#define VID_J_INT_MSTAT 0x0400B8 /* Video J interrupt masked status */
154#define VID_J_INT_SSTAT 0x0400BC // Video J interrupt set status 154#define VID_J_INT_SSTAT 0x0400BC /* Video J interrupt set status */
155 155
156#define FLD_VID_SRC_OPC_ERR 0x00020000 156#define FLD_VID_SRC_OPC_ERR 0x00020000
157#define FLD_VID_DST_OPC_ERR 0x00010000 157#define FLD_VID_DST_OPC_ERR 0x00010000
@@ -166,35 +166,35 @@
166#define FLD_VID_SRC_ERRORS FLD_VID_SRC_OPC_ERR | FLD_VID_SRC_SYNC | FLD_VID_SRC_UF 166#define FLD_VID_SRC_ERRORS FLD_VID_SRC_OPC_ERR | FLD_VID_SRC_SYNC | FLD_VID_SRC_UF
167#define FLD_VID_DST_ERRORS FLD_VID_DST_OPC_ERR | FLD_VID_DST_SYNC | FLD_VID_DST_OF 167#define FLD_VID_DST_ERRORS FLD_VID_DST_OPC_ERR | FLD_VID_DST_SYNC | FLD_VID_DST_OF
168 168
169//***************************************************************************** 169/* ***************************************************************************** */
170#define AUD_A_INT_MSK 0x0400C0 // Audio Int interrupt mask 170#define AUD_A_INT_MSK 0x0400C0 /* Audio Int interrupt mask */
171#define AUD_A_INT_STAT 0x0400C4 // Audio Int interrupt status 171#define AUD_A_INT_STAT 0x0400C4 /* Audio Int interrupt status */
172#define AUD_A_INT_MSTAT 0x0400C8 // Audio Int interrupt masked status 172#define AUD_A_INT_MSTAT 0x0400C8 /* Audio Int interrupt masked status */
173#define AUD_A_INT_SSTAT 0x0400CC // Audio Int interrupt set status 173#define AUD_A_INT_SSTAT 0x0400CC /* Audio Int interrupt set status */
174 174
175//***************************************************************************** 175/* ***************************************************************************** */
176#define AUD_B_INT_MSK 0x0400D0 // Audio Int interrupt mask 176#define AUD_B_INT_MSK 0x0400D0 /* Audio Int interrupt mask */
177#define AUD_B_INT_STAT 0x0400D4 // Audio Int interrupt status 177#define AUD_B_INT_STAT 0x0400D4 /* Audio Int interrupt status */
178#define AUD_B_INT_MSTAT 0x0400D8 // Audio Int interrupt masked status 178#define AUD_B_INT_MSTAT 0x0400D8 /* Audio Int interrupt masked status */
179#define AUD_B_INT_SSTAT 0x0400DC // Audio Int interrupt set status 179#define AUD_B_INT_SSTAT 0x0400DC /* Audio Int interrupt set status */
180 180
181//***************************************************************************** 181/* ***************************************************************************** */
182#define AUD_C_INT_MSK 0x0400E0 // Audio Int interrupt mask 182#define AUD_C_INT_MSK 0x0400E0 /* Audio Int interrupt mask */
183#define AUD_C_INT_STAT 0x0400E4 // Audio Int interrupt status 183#define AUD_C_INT_STAT 0x0400E4 /* Audio Int interrupt status */
184#define AUD_C_INT_MSTAT 0x0400E8 // Audio Int interrupt masked status 184#define AUD_C_INT_MSTAT 0x0400E8 /* Audio Int interrupt masked status */
185#define AUD_C_INT_SSTAT 0x0400EC // Audio Int interrupt set status 185#define AUD_C_INT_SSTAT 0x0400EC /* Audio Int interrupt set status */
186 186
187//***************************************************************************** 187/* ***************************************************************************** */
188#define AUD_D_INT_MSK 0x0400F0 // Audio Int interrupt mask 188#define AUD_D_INT_MSK 0x0400F0 /* Audio Int interrupt mask */
189#define AUD_D_INT_STAT 0x0400F4 // Audio Int interrupt status 189#define AUD_D_INT_STAT 0x0400F4 /* Audio Int interrupt status */
190#define AUD_D_INT_MSTAT 0x0400F8 // Audio Int interrupt masked status 190#define AUD_D_INT_MSTAT 0x0400F8 /* Audio Int interrupt masked status */
191#define AUD_D_INT_SSTAT 0x0400FC // Audio Int interrupt set status 191#define AUD_D_INT_SSTAT 0x0400FC /* Audio Int interrupt set status */
192 192
193//***************************************************************************** 193/* ***************************************************************************** */
194#define AUD_E_INT_MSK 0x040100 // Audio Int interrupt mask 194#define AUD_E_INT_MSK 0x040100 /* Audio Int interrupt mask */
195#define AUD_E_INT_STAT 0x040104 // Audio Int interrupt status 195#define AUD_E_INT_STAT 0x040104 /* Audio Int interrupt status */
196#define AUD_E_INT_MSTAT 0x040108 // Audio Int interrupt masked status 196#define AUD_E_INT_MSTAT 0x040108 /* Audio Int interrupt masked status */
197#define AUD_E_INT_SSTAT 0x04010C // Audio Int interrupt set status 197#define AUD_E_INT_SSTAT 0x04010C /* Audio Int interrupt set status */
198 198
199#define FLD_AUD_SRC_OPC_ERR 0x00020000 199#define FLD_AUD_SRC_OPC_ERR 0x00020000
200#define FLD_AUD_DST_OPC_ERR 0x00010000 200#define FLD_AUD_DST_OPC_ERR 0x00010000
@@ -207,17 +207,17 @@
207#define FLD_AUD_SRC_RISCI1 0x00000002 207#define FLD_AUD_SRC_RISCI1 0x00000002
208#define FLD_AUD_DST_RISCI1 0x00000001 208#define FLD_AUD_DST_RISCI1 0x00000001
209 209
210//***************************************************************************** 210/* ***************************************************************************** */
211#define MBIF_A_INT_MSK 0x040110 // MBIF Int interrupt mask 211#define MBIF_A_INT_MSK 0x040110 /* MBIF Int interrupt mask */
212#define MBIF_A_INT_STAT 0x040114 // MBIF Int interrupt status 212#define MBIF_A_INT_STAT 0x040114 /* MBIF Int interrupt status */
213#define MBIF_A_INT_MSTAT 0x040118 // MBIF Int interrupt masked status 213#define MBIF_A_INT_MSTAT 0x040118 /* MBIF Int interrupt masked status */
214#define MBIF_A_INT_SSTAT 0x04011C // MBIF Int interrupt set status 214#define MBIF_A_INT_SSTAT 0x04011C /* MBIF Int interrupt set status */
215 215
216//***************************************************************************** 216/* ***************************************************************************** */
217#define MBIF_B_INT_MSK 0x040120 // MBIF Int interrupt mask 217#define MBIF_B_INT_MSK 0x040120 /* MBIF Int interrupt mask */
218#define MBIF_B_INT_STAT 0x040124 // MBIF Int interrupt status 218#define MBIF_B_INT_STAT 0x040124 /* MBIF Int interrupt status */
219#define MBIF_B_INT_MSTAT 0x040128 // MBIF Int interrupt masked status 219#define MBIF_B_INT_MSTAT 0x040128 /* MBIF Int interrupt masked status */
220#define MBIF_B_INT_SSTAT 0x04012C // MBIF Int interrupt set status 220#define MBIF_B_INT_SSTAT 0x04012C /* MBIF Int interrupt set status */
221 221
222#define FLD_MBIF_DST_OPC_ERR 0x00010000 222#define FLD_MBIF_DST_OPC_ERR 0x00010000
223#define FLD_MBIF_DST_SYNC 0x00001000 223#define FLD_MBIF_DST_SYNC 0x00001000
@@ -225,35 +225,35 @@
225#define FLD_MBIF_DST_RISCI2 0x00000010 225#define FLD_MBIF_DST_RISCI2 0x00000010
226#define FLD_MBIF_DST_RISCI1 0x00000001 226#define FLD_MBIF_DST_RISCI1 0x00000001
227 227
228//***************************************************************************** 228/* ***************************************************************************** */
229#define AUD_EXT_INT_MSK 0x040060 // Audio Ext interrupt mask 229#define AUD_EXT_INT_MSK 0x040060 /* Audio Ext interrupt mask */
230#define AUD_EXT_INT_STAT 0x040064 // Audio Ext interrupt status 230#define AUD_EXT_INT_STAT 0x040064 /* Audio Ext interrupt status */
231#define AUD_EXT_INT_MSTAT 0x040068 // Audio Ext interrupt masked status 231#define AUD_EXT_INT_MSTAT 0x040068 /* Audio Ext interrupt masked status */
232#define AUD_EXT_INT_SSTAT 0x04006C // Audio Ext interrupt set status 232#define AUD_EXT_INT_SSTAT 0x04006C /* Audio Ext interrupt set status */
233#define FLD_AUD_EXT_OPC_ERR 0x00010000 233#define FLD_AUD_EXT_OPC_ERR 0x00010000
234#define FLD_AUD_EXT_SYNC 0x00001000 234#define FLD_AUD_EXT_SYNC 0x00001000
235#define FLD_AUD_EXT_OF 0x00000100 235#define FLD_AUD_EXT_OF 0x00000100
236#define FLD_AUD_EXT_RISCI2 0x00000010 236#define FLD_AUD_EXT_RISCI2 0x00000010
237#define FLD_AUD_EXT_RISCI1 0x00000001 237#define FLD_AUD_EXT_RISCI1 0x00000001
238 238
239//***************************************************************************** 239/* ***************************************************************************** */
240#define GPIO_LO 0x110010 // Lower of GPIO pins [31:0] 240#define GPIO_LO 0x110010 /* Lower of GPIO pins [31:0] */
241#define GPIO_HI 0x110014 // Upper WORD of GPIO pins [47:31] 241#define GPIO_HI 0x110014 /* Upper WORD of GPIO pins [47:31] */
242 242
243#define GPIO_LO_OE 0x110018 // Lower of GPIO output enable [31:0] 243#define GPIO_LO_OE 0x110018 /* Lower of GPIO output enable [31:0] */
244#define GPIO_HI_OE 0x11001C // Upper word of GPIO output enable [47:32] 244#define GPIO_HI_OE 0x11001C /* Upper word of GPIO output enable [47:32] */
245 245
246#define GPIO_LO_INT_MSK 0x11003C // GPIO interrupt mask 246#define GPIO_LO_INT_MSK 0x11003C /* GPIO interrupt mask */
247#define GPIO_LO_INT_STAT 0x110044 // GPIO interrupt status 247#define GPIO_LO_INT_STAT 0x110044 /* GPIO interrupt status */
248#define GPIO_LO_INT_MSTAT 0x11004C // GPIO interrupt masked status 248#define GPIO_LO_INT_MSTAT 0x11004C /* GPIO interrupt masked status */
249#define GPIO_LO_ISM_SNS 0x110054 // GPIO interrupt sensitivity 249#define GPIO_LO_ISM_SNS 0x110054 /* GPIO interrupt sensitivity */
250#define GPIO_LO_ISM_POL 0x11005C // GPIO interrupt polarity 250#define GPIO_LO_ISM_POL 0x11005C /* GPIO interrupt polarity */
251 251
252#define GPIO_HI_INT_MSK 0x110040 // GPIO interrupt mask 252#define GPIO_HI_INT_MSK 0x110040 /* GPIO interrupt mask */
253#define GPIO_HI_INT_STAT 0x110048 // GPIO interrupt status 253#define GPIO_HI_INT_STAT 0x110048 /* GPIO interrupt status */
254#define GPIO_HI_INT_MSTAT 0x110050 // GPIO interrupt masked status 254#define GPIO_HI_INT_MSTAT 0x110050 /* GPIO interrupt masked status */
255#define GPIO_HI_ISM_SNS 0x110058 // GPIO interrupt sensitivity 255#define GPIO_HI_ISM_SNS 0x110058 /* GPIO interrupt sensitivity */
256#define GPIO_HI_ISM_POL 0x110060 // GPIO interrupt polarity 256#define GPIO_HI_ISM_POL 0x110060 /* GPIO interrupt polarity */
257 257
258#define FLD_GPIO43_INT (1 << 11) 258#define FLD_GPIO43_INT (1 << 11)
259#define FLD_GPIO42_INT (1 << 10) 259#define FLD_GPIO42_INT (1 << 10)
@@ -271,236 +271,236 @@
271#define FLD_GPIO1_INT (1 << 1) 271#define FLD_GPIO1_INT (1 << 1)
272#define FLD_GPIO0_INT (1 << 0) 272#define FLD_GPIO0_INT (1 << 0)
273 273
274//***************************************************************************** 274/* ***************************************************************************** */
275#define TC_REQ 0x040090 // Rider PCI Express traFFic class request 275#define TC_REQ 0x040090 /* Rider PCI Express traFFic class request */
276 276
277//***************************************************************************** 277/* ***************************************************************************** */
278#define TC_REQ_SET 0x040094 // Rider PCI Express traFFic class request set 278#define TC_REQ_SET 0x040094 /* Rider PCI Express traFFic class request set */
279 279
280//***************************************************************************** 280/* ***************************************************************************** */
281// Rider 281/* Rider */
282//***************************************************************************** 282/* ***************************************************************************** */
283 283
284// PCI Compatible Header 284/* PCI Compatible Header */
285//***************************************************************************** 285/* ***************************************************************************** */
286#define RDR_CFG0 0x050000 286#define RDR_CFG0 0x050000
287#define RDR_VENDOR_DEVICE_ID_CFG 0x050000 287#define RDR_VENDOR_DEVICE_ID_CFG 0x050000
288 288
289//***************************************************************************** 289/* ***************************************************************************** */
290#define RDR_CFG1 0x050004 290#define RDR_CFG1 0x050004
291 291
292//***************************************************************************** 292/* ***************************************************************************** */
293#define RDR_CFG2 0x050008 293#define RDR_CFG2 0x050008
294 294
295//***************************************************************************** 295/* ***************************************************************************** */
296#define RDR_CFG3 0x05000C 296#define RDR_CFG3 0x05000C
297 297
298//***************************************************************************** 298/* ***************************************************************************** */
299#define RDR_CFG4 0x050010 299#define RDR_CFG4 0x050010
300 300
301//***************************************************************************** 301/* ***************************************************************************** */
302#define RDR_CFG5 0x050014 302#define RDR_CFG5 0x050014
303 303
304//***************************************************************************** 304/* ***************************************************************************** */
305#define RDR_CFG6 0x050018 305#define RDR_CFG6 0x050018
306 306
307//***************************************************************************** 307/* ***************************************************************************** */
308#define RDR_CFG7 0x05001C 308#define RDR_CFG7 0x05001C
309 309
310//***************************************************************************** 310/* ***************************************************************************** */
311#define RDR_CFG8 0x050020 311#define RDR_CFG8 0x050020
312 312
313//***************************************************************************** 313/* ***************************************************************************** */
314#define RDR_CFG9 0x050024 314#define RDR_CFG9 0x050024
315 315
316//***************************************************************************** 316/* ***************************************************************************** */
317#define RDR_CFGA 0x050028 317#define RDR_CFGA 0x050028
318 318
319//***************************************************************************** 319/* ***************************************************************************** */
320#define RDR_CFGB 0x05002C 320#define RDR_CFGB 0x05002C
321#define RDR_SUSSYSTEM_ID_CFG 0x05002C 321#define RDR_SUSSYSTEM_ID_CFG 0x05002C
322 322
323//***************************************************************************** 323/* ***************************************************************************** */
324#define RDR_CFGC 0x050030 324#define RDR_CFGC 0x050030
325 325
326//***************************************************************************** 326/* ***************************************************************************** */
327#define RDR_CFGD 0x050034 327#define RDR_CFGD 0x050034
328 328
329//***************************************************************************** 329/* ***************************************************************************** */
330#define RDR_CFGE 0x050038 330#define RDR_CFGE 0x050038
331 331
332//***************************************************************************** 332/* ***************************************************************************** */
333#define RDR_CFGF 0x05003C 333#define RDR_CFGF 0x05003C
334 334
335//***************************************************************************** 335/* ***************************************************************************** */
336// PCI-Express Capabilities 336/* PCI-Express Capabilities */
337//***************************************************************************** 337/* ***************************************************************************** */
338#define RDR_PECAP 0x050040 338#define RDR_PECAP 0x050040
339 339
340//***************************************************************************** 340/* ***************************************************************************** */
341#define RDR_PEDEVCAP 0x050044 341#define RDR_PEDEVCAP 0x050044
342 342
343//***************************************************************************** 343/* ***************************************************************************** */
344#define RDR_PEDEVSC 0x050048 344#define RDR_PEDEVSC 0x050048
345 345
346//***************************************************************************** 346/* ***************************************************************************** */
347#define RDR_PELINKCAP 0x05004C 347#define RDR_PELINKCAP 0x05004C
348 348
349//***************************************************************************** 349/* ***************************************************************************** */
350#define RDR_PELINKSC 0x050050 350#define RDR_PELINKSC 0x050050
351 351
352//***************************************************************************** 352/* ***************************************************************************** */
353#define RDR_PMICAP 0x050080 353#define RDR_PMICAP 0x050080
354 354
355//***************************************************************************** 355/* ***************************************************************************** */
356#define RDR_PMCSR 0x050084 356#define RDR_PMCSR 0x050084
357 357
358//***************************************************************************** 358/* ***************************************************************************** */
359#define RDR_VPDCAP 0x050090 359#define RDR_VPDCAP 0x050090
360 360
361//***************************************************************************** 361/* ***************************************************************************** */
362#define RDR_VPDDATA 0x050094 362#define RDR_VPDDATA 0x050094
363 363
364//***************************************************************************** 364/* ***************************************************************************** */
365#define RDR_MSICAP 0x0500A0 365#define RDR_MSICAP 0x0500A0
366 366
367//***************************************************************************** 367/* ***************************************************************************** */
368#define RDR_MSIARL 0x0500A4 368#define RDR_MSIARL 0x0500A4
369 369
370//***************************************************************************** 370/* ***************************************************************************** */
371#define RDR_MSIARU 0x0500A8 371#define RDR_MSIARU 0x0500A8
372 372
373//***************************************************************************** 373/* ***************************************************************************** */
374#define RDR_MSIDATA 0x0500AC 374#define RDR_MSIDATA 0x0500AC
375 375
376//***************************************************************************** 376/* ***************************************************************************** */
377// PCI Express Extended Capabilities 377/* PCI Express Extended Capabilities */
378//***************************************************************************** 378/* ***************************************************************************** */
379#define RDR_AERXCAP 0x050100 379#define RDR_AERXCAP 0x050100
380 380
381//***************************************************************************** 381/* ***************************************************************************** */
382#define RDR_AERUESTA 0x050104 382#define RDR_AERUESTA 0x050104
383 383
384//***************************************************************************** 384/* ***************************************************************************** */
385#define RDR_AERUEMSK 0x050108 385#define RDR_AERUEMSK 0x050108
386 386
387//***************************************************************************** 387/* ***************************************************************************** */
388#define RDR_AERUESEV 0x05010C 388#define RDR_AERUESEV 0x05010C
389 389
390//***************************************************************************** 390/* ***************************************************************************** */
391#define RDR_AERCESTA 0x050110 391#define RDR_AERCESTA 0x050110
392 392
393//***************************************************************************** 393/* ***************************************************************************** */
394#define RDR_AERCEMSK 0x050114 394#define RDR_AERCEMSK 0x050114
395 395
396//***************************************************************************** 396/* ***************************************************************************** */
397#define RDR_AERCC 0x050118 397#define RDR_AERCC 0x050118
398 398
399//***************************************************************************** 399/* ***************************************************************************** */
400#define RDR_AERHL0 0x05011C 400#define RDR_AERHL0 0x05011C
401 401
402//***************************************************************************** 402/* ***************************************************************************** */
403#define RDR_AERHL1 0x050120 403#define RDR_AERHL1 0x050120
404 404
405//***************************************************************************** 405/* ***************************************************************************** */
406#define RDR_AERHL2 0x050124 406#define RDR_AERHL2 0x050124
407 407
408//***************************************************************************** 408/* ***************************************************************************** */
409#define RDR_AERHL3 0x050128 409#define RDR_AERHL3 0x050128
410 410
411//***************************************************************************** 411/* ***************************************************************************** */
412#define RDR_VCXCAP 0x050200 412#define RDR_VCXCAP 0x050200
413 413
414//***************************************************************************** 414/* ***************************************************************************** */
415#define RDR_VCCAP1 0x050204 415#define RDR_VCCAP1 0x050204
416 416
417//***************************************************************************** 417/* ***************************************************************************** */
418#define RDR_VCCAP2 0x050208 418#define RDR_VCCAP2 0x050208
419 419
420//***************************************************************************** 420/* ***************************************************************************** */
421#define RDR_VCSC 0x05020C 421#define RDR_VCSC 0x05020C
422 422
423//***************************************************************************** 423/* ***************************************************************************** */
424#define RDR_VCR0_CAP 0x050210 424#define RDR_VCR0_CAP 0x050210
425 425
426//***************************************************************************** 426/* ***************************************************************************** */
427#define RDR_VCR0_CTRL 0x050214 427#define RDR_VCR0_CTRL 0x050214
428 428
429//***************************************************************************** 429/* ***************************************************************************** */
430#define RDR_VCR0_STAT 0x050218 430#define RDR_VCR0_STAT 0x050218
431 431
432//***************************************************************************** 432/* ***************************************************************************** */
433#define RDR_VCR1_CAP 0x05021C 433#define RDR_VCR1_CAP 0x05021C
434 434
435//***************************************************************************** 435/* ***************************************************************************** */
436#define RDR_VCR1_CTRL 0x050220 436#define RDR_VCR1_CTRL 0x050220
437 437
438//***************************************************************************** 438/* ***************************************************************************** */
439#define RDR_VCR1_STAT 0x050224 439#define RDR_VCR1_STAT 0x050224
440 440
441//***************************************************************************** 441/* ***************************************************************************** */
442#define RDR_VCR2_CAP 0x050228 442#define RDR_VCR2_CAP 0x050228
443 443
444//***************************************************************************** 444/* ***************************************************************************** */
445#define RDR_VCR2_CTRL 0x05022C 445#define RDR_VCR2_CTRL 0x05022C
446 446
447//***************************************************************************** 447/* ***************************************************************************** */
448#define RDR_VCR2_STAT 0x050230 448#define RDR_VCR2_STAT 0x050230
449 449
450//***************************************************************************** 450/* ***************************************************************************** */
451#define RDR_VCR3_CAP 0x050234 451#define RDR_VCR3_CAP 0x050234
452 452
453//***************************************************************************** 453/* ***************************************************************************** */
454#define RDR_VCR3_CTRL 0x050238 454#define RDR_VCR3_CTRL 0x050238
455 455
456//***************************************************************************** 456/* ***************************************************************************** */
457#define RDR_VCR3_STAT 0x05023C 457#define RDR_VCR3_STAT 0x05023C
458 458
459//***************************************************************************** 459/* ***************************************************************************** */
460#define RDR_VCARB0 0x050240 460#define RDR_VCARB0 0x050240
461 461
462//***************************************************************************** 462/* ***************************************************************************** */
463#define RDR_VCARB1 0x050244 463#define RDR_VCARB1 0x050244
464 464
465//***************************************************************************** 465/* ***************************************************************************** */
466#define RDR_VCARB2 0x050248 466#define RDR_VCARB2 0x050248
467 467
468//***************************************************************************** 468/* ***************************************************************************** */
469#define RDR_VCARB3 0x05024C 469#define RDR_VCARB3 0x05024C
470 470
471//***************************************************************************** 471/* ***************************************************************************** */
472#define RDR_VCARB4 0x050250 472#define RDR_VCARB4 0x050250
473 473
474//***************************************************************************** 474/* ***************************************************************************** */
475#define RDR_VCARB5 0x050254 475#define RDR_VCARB5 0x050254
476 476
477//***************************************************************************** 477/* ***************************************************************************** */
478#define RDR_VCARB6 0x050258 478#define RDR_VCARB6 0x050258
479 479
480//***************************************************************************** 480/* ***************************************************************************** */
481#define RDR_VCARB7 0x05025C 481#define RDR_VCARB7 0x05025C
482 482
483//***************************************************************************** 483/* ***************************************************************************** */
484#define RDR_RDRSTAT0 0x050300 484#define RDR_RDRSTAT0 0x050300
485 485
486//***************************************************************************** 486/* ***************************************************************************** */
487#define RDR_RDRSTAT1 0x050304 487#define RDR_RDRSTAT1 0x050304
488 488
489//***************************************************************************** 489/* ***************************************************************************** */
490#define RDR_RDRCTL0 0x050308 490#define RDR_RDRCTL0 0x050308
491 491
492//***************************************************************************** 492/* ***************************************************************************** */
493#define RDR_RDRCTL1 0x05030C 493#define RDR_RDRCTL1 0x05030C
494 494
495//***************************************************************************** 495/* ***************************************************************************** */
496// Transaction Layer Registers 496/* Transaction Layer Registers */
497//***************************************************************************** 497/* ***************************************************************************** */
498#define RDR_TLSTAT0 0x050310 498#define RDR_TLSTAT0 0x050310
499 499
500//***************************************************************************** 500/* ***************************************************************************** */
501#define RDR_TLSTAT1 0x050314 501#define RDR_TLSTAT1 0x050314
502 502
503//***************************************************************************** 503/* ***************************************************************************** */
504#define RDR_TLCTL0 0x050318 504#define RDR_TLCTL0 0x050318
505#define FLD_CFG_UR_CPL_MODE 0x00000040 505#define FLD_CFG_UR_CPL_MODE 0x00000040
506#define FLD_CFG_CORR_ERR_QUITE 0x00000020 506#define FLD_CFG_CORR_ERR_QUITE 0x00000020
@@ -510,569 +510,569 @@
510#define FLD_CFG_RELAX_ORDER_MSK 0x00000002 510#define FLD_CFG_RELAX_ORDER_MSK 0x00000002
511#define FLD_CFG_TAG_ORDER_EN 0x00000001 511#define FLD_CFG_TAG_ORDER_EN 0x00000001
512 512
513//***************************************************************************** 513/* ***************************************************************************** */
514#define RDR_TLCTL1 0x05031C 514#define RDR_TLCTL1 0x05031C
515 515
516//***************************************************************************** 516/* ***************************************************************************** */
517#define RDR_REQRCAL 0x050320 517#define RDR_REQRCAL 0x050320
518 518
519//***************************************************************************** 519/* ***************************************************************************** */
520#define RDR_REQRCAU 0x050324 520#define RDR_REQRCAU 0x050324
521 521
522//***************************************************************************** 522/* ***************************************************************************** */
523#define RDR_REQEPA 0x050328 523#define RDR_REQEPA 0x050328
524 524
525//***************************************************************************** 525/* ***************************************************************************** */
526#define RDR_REQCTRL 0x05032C 526#define RDR_REQCTRL 0x05032C
527 527
528//***************************************************************************** 528/* ***************************************************************************** */
529#define RDR_REQSTAT 0x050330 529#define RDR_REQSTAT 0x050330
530 530
531//***************************************************************************** 531/* ***************************************************************************** */
532#define RDR_TL_TEST 0x050334 532#define RDR_TL_TEST 0x050334
533 533
534//***************************************************************************** 534/* ***************************************************************************** */
535#define RDR_VCR01_CTL 0x050348 535#define RDR_VCR01_CTL 0x050348
536 536
537//***************************************************************************** 537/* ***************************************************************************** */
538#define RDR_VCR23_CTL 0x05034C 538#define RDR_VCR23_CTL 0x05034C
539 539
540//***************************************************************************** 540/* ***************************************************************************** */
541#define RDR_RX_VCR0_FC 0x050350 541#define RDR_RX_VCR0_FC 0x050350
542 542
543//***************************************************************************** 543/* ***************************************************************************** */
544#define RDR_RX_VCR1_FC 0x050354 544#define RDR_RX_VCR1_FC 0x050354
545 545
546//***************************************************************************** 546/* ***************************************************************************** */
547#define RDR_RX_VCR2_FC 0x050358 547#define RDR_RX_VCR2_FC 0x050358
548 548
549//***************************************************************************** 549/* ***************************************************************************** */
550#define RDR_RX_VCR3_FC 0x05035C 550#define RDR_RX_VCR3_FC 0x05035C
551 551
552//***************************************************************************** 552/* ***************************************************************************** */
553// Data Link Layer Registers 553/* Data Link Layer Registers */
554//***************************************************************************** 554/* ***************************************************************************** */
555#define RDR_DLLSTAT 0x050360 555#define RDR_DLLSTAT 0x050360
556 556
557//***************************************************************************** 557/* ***************************************************************************** */
558#define RDR_DLLCTRL 0x050364 558#define RDR_DLLCTRL 0x050364
559 559
560//***************************************************************************** 560/* ***************************************************************************** */
561#define RDR_REPLAYTO 0x050368 561#define RDR_REPLAYTO 0x050368
562 562
563//***************************************************************************** 563/* ***************************************************************************** */
564#define RDR_ACKLATTO 0x05036C 564#define RDR_ACKLATTO 0x05036C
565 565
566//***************************************************************************** 566/* ***************************************************************************** */
567// MAC Layer Registers 567/* MAC Layer Registers */
568//***************************************************************************** 568/* ***************************************************************************** */
569#define RDR_MACSTAT0 0x050380 569#define RDR_MACSTAT0 0x050380
570 570
571//***************************************************************************** 571/* ***************************************************************************** */
572#define RDR_MACSTAT1 0x050384 572#define RDR_MACSTAT1 0x050384
573 573
574//***************************************************************************** 574/* ***************************************************************************** */
575#define RDR_MACCTRL0 0x050388 575#define RDR_MACCTRL0 0x050388
576 576
577//***************************************************************************** 577/* ***************************************************************************** */
578#define RDR_MACCTRL1 0x05038C 578#define RDR_MACCTRL1 0x05038C
579 579
580//***************************************************************************** 580/* ***************************************************************************** */
581#define RDR_MACCTRL2 0x050390 581#define RDR_MACCTRL2 0x050390
582 582
583//***************************************************************************** 583/* ***************************************************************************** */
584#define RDR_MAC_LB_DATA 0x050394 584#define RDR_MAC_LB_DATA 0x050394
585 585
586//***************************************************************************** 586/* ***************************************************************************** */
587#define RDR_L0S_EXIT_LAT 0x050398 587#define RDR_L0S_EXIT_LAT 0x050398
588 588
589//***************************************************************************** 589/* ***************************************************************************** */
590// DMAC 590/* DMAC */
591//***************************************************************************** 591/* ***************************************************************************** */
592#define DMA1_PTR1 0x100000 // DMA Current Ptr : Ch#1 592#define DMA1_PTR1 0x100000 /* DMA Current Ptr : Ch#1 */
593 593
594//***************************************************************************** 594/* ***************************************************************************** */
595#define DMA2_PTR1 0x100004 // DMA Current Ptr : Ch#2 595#define DMA2_PTR1 0x100004 /* DMA Current Ptr : Ch#2 */
596 596
597//***************************************************************************** 597/* ***************************************************************************** */
598#define DMA3_PTR1 0x100008 // DMA Current Ptr : Ch#3 598#define DMA3_PTR1 0x100008 /* DMA Current Ptr : Ch#3 */
599 599
600//***************************************************************************** 600/* ***************************************************************************** */
601#define DMA4_PTR1 0x10000C // DMA Current Ptr : Ch#4 601#define DMA4_PTR1 0x10000C /* DMA Current Ptr : Ch#4 */
602 602
603//***************************************************************************** 603/* ***************************************************************************** */
604#define DMA5_PTR1 0x100010 // DMA Current Ptr : Ch#5 604#define DMA5_PTR1 0x100010 /* DMA Current Ptr : Ch#5 */
605 605
606//***************************************************************************** 606/* ***************************************************************************** */
607#define DMA6_PTR1 0x100014 // DMA Current Ptr : Ch#6 607#define DMA6_PTR1 0x100014 /* DMA Current Ptr : Ch#6 */
608 608
609//***************************************************************************** 609/* ***************************************************************************** */
610#define DMA7_PTR1 0x100018 // DMA Current Ptr : Ch#7 610#define DMA7_PTR1 0x100018 /* DMA Current Ptr : Ch#7 */
611 611
612//***************************************************************************** 612/* ***************************************************************************** */
613#define DMA8_PTR1 0x10001C // DMA Current Ptr : Ch#8 613#define DMA8_PTR1 0x10001C /* DMA Current Ptr : Ch#8 */
614 614
615//***************************************************************************** 615/* ***************************************************************************** */
616#define DMA9_PTR1 0x100020 // DMA Current Ptr : Ch#9 616#define DMA9_PTR1 0x100020 /* DMA Current Ptr : Ch#9 */
617 617
618//***************************************************************************** 618/* ***************************************************************************** */
619#define DMA10_PTR1 0x100024 // DMA Current Ptr : Ch#10 619#define DMA10_PTR1 0x100024 /* DMA Current Ptr : Ch#10 */
620 620
621//***************************************************************************** 621/* ***************************************************************************** */
622#define DMA11_PTR1 0x100028 // DMA Current Ptr : Ch#11 622#define DMA11_PTR1 0x100028 /* DMA Current Ptr : Ch#11 */
623 623
624//***************************************************************************** 624/* ***************************************************************************** */
625#define DMA12_PTR1 0x10002C // DMA Current Ptr : Ch#12 625#define DMA12_PTR1 0x10002C /* DMA Current Ptr : Ch#12 */
626 626
627//***************************************************************************** 627/* ***************************************************************************** */
628#define DMA13_PTR1 0x100030 // DMA Current Ptr : Ch#13 628#define DMA13_PTR1 0x100030 /* DMA Current Ptr : Ch#13 */
629 629
630//***************************************************************************** 630/* ***************************************************************************** */
631#define DMA14_PTR1 0x100034 // DMA Current Ptr : Ch#14 631#define DMA14_PTR1 0x100034 /* DMA Current Ptr : Ch#14 */
632 632
633//***************************************************************************** 633/* ***************************************************************************** */
634#define DMA15_PTR1 0x100038 // DMA Current Ptr : Ch#15 634#define DMA15_PTR1 0x100038 /* DMA Current Ptr : Ch#15 */
635 635
636//***************************************************************************** 636/* ***************************************************************************** */
637#define DMA16_PTR1 0x10003C // DMA Current Ptr : Ch#16 637#define DMA16_PTR1 0x10003C /* DMA Current Ptr : Ch#16 */
638 638
639//***************************************************************************** 639/* ***************************************************************************** */
640#define DMA17_PTR1 0x100040 // DMA Current Ptr : Ch#17 640#define DMA17_PTR1 0x100040 /* DMA Current Ptr : Ch#17 */
641 641
642//***************************************************************************** 642/* ***************************************************************************** */
643#define DMA18_PTR1 0x100044 // DMA Current Ptr : Ch#18 643#define DMA18_PTR1 0x100044 /* DMA Current Ptr : Ch#18 */
644 644
645//***************************************************************************** 645/* ***************************************************************************** */
646#define DMA19_PTR1 0x100048 // DMA Current Ptr : Ch#19 646#define DMA19_PTR1 0x100048 /* DMA Current Ptr : Ch#19 */
647 647
648//***************************************************************************** 648/* ***************************************************************************** */
649#define DMA20_PTR1 0x10004C // DMA Current Ptr : Ch#20 649#define DMA20_PTR1 0x10004C /* DMA Current Ptr : Ch#20 */
650 650
651//***************************************************************************** 651/* ***************************************************************************** */
652#define DMA21_PTR1 0x100050 // DMA Current Ptr : Ch#21 652#define DMA21_PTR1 0x100050 /* DMA Current Ptr : Ch#21 */
653 653
654//***************************************************************************** 654/* ***************************************************************************** */
655#define DMA22_PTR1 0x100054 // DMA Current Ptr : Ch#22 655#define DMA22_PTR1 0x100054 /* DMA Current Ptr : Ch#22 */
656 656
657//***************************************************************************** 657/* ***************************************************************************** */
658#define DMA23_PTR1 0x100058 // DMA Current Ptr : Ch#23 658#define DMA23_PTR1 0x100058 /* DMA Current Ptr : Ch#23 */
659 659
660//***************************************************************************** 660/* ***************************************************************************** */
661#define DMA24_PTR1 0x10005C // DMA Current Ptr : Ch#24 661#define DMA24_PTR1 0x10005C /* DMA Current Ptr : Ch#24 */
662 662
663//***************************************************************************** 663/* ***************************************************************************** */
664#define DMA25_PTR1 0x100060 // DMA Current Ptr : Ch#25 664#define DMA25_PTR1 0x100060 /* DMA Current Ptr : Ch#25 */
665 665
666//***************************************************************************** 666/* ***************************************************************************** */
667#define DMA26_PTR1 0x100064 // DMA Current Ptr : Ch#26 667#define DMA26_PTR1 0x100064 /* DMA Current Ptr : Ch#26 */
668 668
669//***************************************************************************** 669/* ***************************************************************************** */
670#define DMA1_PTR2 0x100080 // DMA Tab Ptr : Ch#1 670#define DMA1_PTR2 0x100080 /* DMA Tab Ptr : Ch#1 */
671 671
672//***************************************************************************** 672/* ***************************************************************************** */
673#define DMA2_PTR2 0x100084 // DMA Tab Ptr : Ch#2 673#define DMA2_PTR2 0x100084 /* DMA Tab Ptr : Ch#2 */
674 674
675//***************************************************************************** 675/* ***************************************************************************** */
676#define DMA3_PTR2 0x100088 // DMA Tab Ptr : Ch#3 676#define DMA3_PTR2 0x100088 /* DMA Tab Ptr : Ch#3 */
677 677
678//***************************************************************************** 678/* ***************************************************************************** */
679#define DMA4_PTR2 0x10008C // DMA Tab Ptr : Ch#4 679#define DMA4_PTR2 0x10008C /* DMA Tab Ptr : Ch#4 */
680 680
681//***************************************************************************** 681/* ***************************************************************************** */
682#define DMA5_PTR2 0x100090 // DMA Tab Ptr : Ch#5 682#define DMA5_PTR2 0x100090 /* DMA Tab Ptr : Ch#5 */
683 683
684//***************************************************************************** 684/* ***************************************************************************** */
685#define DMA6_PTR2 0x100094 // DMA Tab Ptr : Ch#6 685#define DMA6_PTR2 0x100094 /* DMA Tab Ptr : Ch#6 */
686 686
687//***************************************************************************** 687/* ***************************************************************************** */
688#define DMA7_PTR2 0x100098 // DMA Tab Ptr : Ch#7 688#define DMA7_PTR2 0x100098 /* DMA Tab Ptr : Ch#7 */
689 689
690//***************************************************************************** 690/* ***************************************************************************** */
691#define DMA8_PTR2 0x10009C // DMA Tab Ptr : Ch#8 691#define DMA8_PTR2 0x10009C /* DMA Tab Ptr : Ch#8 */
692 692
693//***************************************************************************** 693/* ***************************************************************************** */
694#define DMA9_PTR2 0x1000A0 // DMA Tab Ptr : Ch#9 694#define DMA9_PTR2 0x1000A0 /* DMA Tab Ptr : Ch#9 */
695 695
696//***************************************************************************** 696/* ***************************************************************************** */
697#define DMA10_PTR2 0x1000A4 // DMA Tab Ptr : Ch#10 697#define DMA10_PTR2 0x1000A4 /* DMA Tab Ptr : Ch#10 */
698 698
699//***************************************************************************** 699/* ***************************************************************************** */
700#define DMA11_PTR2 0x1000A8 // DMA Tab Ptr : Ch#11 700#define DMA11_PTR2 0x1000A8 /* DMA Tab Ptr : Ch#11 */
701 701
702//***************************************************************************** 702/* ***************************************************************************** */
703#define DMA12_PTR2 0x1000AC // DMA Tab Ptr : Ch#12 703#define DMA12_PTR2 0x1000AC /* DMA Tab Ptr : Ch#12 */
704 704
705//***************************************************************************** 705/* ***************************************************************************** */
706#define DMA13_PTR2 0x1000B0 // DMA Tab Ptr : Ch#13 706#define DMA13_PTR2 0x1000B0 /* DMA Tab Ptr : Ch#13 */
707 707
708//***************************************************************************** 708/* ***************************************************************************** */
709#define DMA14_PTR2 0x1000B4 // DMA Tab Ptr : Ch#14 709#define DMA14_PTR2 0x1000B4 /* DMA Tab Ptr : Ch#14 */
710 710
711//***************************************************************************** 711/* ***************************************************************************** */
712#define DMA15_PTR2 0x1000B8 // DMA Tab Ptr : Ch#15 712#define DMA15_PTR2 0x1000B8 /* DMA Tab Ptr : Ch#15 */
713 713
714//***************************************************************************** 714/* ***************************************************************************** */
715#define DMA16_PTR2 0x1000BC // DMA Tab Ptr : Ch#16 715#define DMA16_PTR2 0x1000BC /* DMA Tab Ptr : Ch#16 */
716 716
717//***************************************************************************** 717/* ***************************************************************************** */
718#define DMA17_PTR2 0x1000C0 // DMA Tab Ptr : Ch#17 718#define DMA17_PTR2 0x1000C0 /* DMA Tab Ptr : Ch#17 */
719 719
720//***************************************************************************** 720/* ***************************************************************************** */
721#define DMA18_PTR2 0x1000C4 // DMA Tab Ptr : Ch#18 721#define DMA18_PTR2 0x1000C4 /* DMA Tab Ptr : Ch#18 */
722 722
723//***************************************************************************** 723/* ***************************************************************************** */
724#define DMA19_PTR2 0x1000C8 // DMA Tab Ptr : Ch#19 724#define DMA19_PTR2 0x1000C8 /* DMA Tab Ptr : Ch#19 */
725 725
726//***************************************************************************** 726/* ***************************************************************************** */
727#define DMA20_PTR2 0x1000CC // DMA Tab Ptr : Ch#20 727#define DMA20_PTR2 0x1000CC /* DMA Tab Ptr : Ch#20 */
728 728
729//***************************************************************************** 729/* ***************************************************************************** */
730#define DMA21_PTR2 0x1000D0 // DMA Tab Ptr : Ch#21 730#define DMA21_PTR2 0x1000D0 /* DMA Tab Ptr : Ch#21 */
731 731
732//***************************************************************************** 732/* ***************************************************************************** */
733#define DMA22_PTR2 0x1000D4 // DMA Tab Ptr : Ch#22 733#define DMA22_PTR2 0x1000D4 /* DMA Tab Ptr : Ch#22 */
734 734
735//***************************************************************************** 735/* ***************************************************************************** */
736#define DMA23_PTR2 0x1000D8 // DMA Tab Ptr : Ch#23 736#define DMA23_PTR2 0x1000D8 /* DMA Tab Ptr : Ch#23 */
737 737
738//***************************************************************************** 738/* ***************************************************************************** */
739#define DMA24_PTR2 0x1000DC // DMA Tab Ptr : Ch#24 739#define DMA24_PTR2 0x1000DC /* DMA Tab Ptr : Ch#24 */
740 740
741//***************************************************************************** 741/* ***************************************************************************** */
742#define DMA25_PTR2 0x1000E0 // DMA Tab Ptr : Ch#25 742#define DMA25_PTR2 0x1000E0 /* DMA Tab Ptr : Ch#25 */
743 743
744//***************************************************************************** 744/* ***************************************************************************** */
745#define DMA26_PTR2 0x1000E4 // DMA Tab Ptr : Ch#26 745#define DMA26_PTR2 0x1000E4 /* DMA Tab Ptr : Ch#26 */
746 746
747//***************************************************************************** 747/* ***************************************************************************** */
748#define DMA1_CNT1 0x100100 // DMA BuFFer Size : Ch#1 748#define DMA1_CNT1 0x100100 /* DMA BuFFer Size : Ch#1 */
749 749
750//***************************************************************************** 750/* ***************************************************************************** */
751#define DMA2_CNT1 0x100104 // DMA BuFFer Size : Ch#2 751#define DMA2_CNT1 0x100104 /* DMA BuFFer Size : Ch#2 */
752 752
753//***************************************************************************** 753/* ***************************************************************************** */
754#define DMA3_CNT1 0x100108 // DMA BuFFer Size : Ch#3 754#define DMA3_CNT1 0x100108 /* DMA BuFFer Size : Ch#3 */
755 755
756//***************************************************************************** 756/* ***************************************************************************** */
757#define DMA4_CNT1 0x10010C // DMA BuFFer Size : Ch#4 757#define DMA4_CNT1 0x10010C /* DMA BuFFer Size : Ch#4 */
758 758
759//***************************************************************************** 759/* ***************************************************************************** */
760#define DMA5_CNT1 0x100110 // DMA BuFFer Size : Ch#5 760#define DMA5_CNT1 0x100110 /* DMA BuFFer Size : Ch#5 */
761 761
762//***************************************************************************** 762/* ***************************************************************************** */
763#define DMA6_CNT1 0x100114 // DMA BuFFer Size : Ch#6 763#define DMA6_CNT1 0x100114 /* DMA BuFFer Size : Ch#6 */
764 764
765//***************************************************************************** 765/* ***************************************************************************** */
766#define DMA7_CNT1 0x100118 // DMA BuFFer Size : Ch#7 766#define DMA7_CNT1 0x100118 /* DMA BuFFer Size : Ch#7 */
767 767
768//***************************************************************************** 768/* ***************************************************************************** */
769#define DMA8_CNT1 0x10011C // DMA BuFFer Size : Ch#8 769#define DMA8_CNT1 0x10011C /* DMA BuFFer Size : Ch#8 */
770 770
771//***************************************************************************** 771/* ***************************************************************************** */
772#define DMA9_CNT1 0x100120 // DMA BuFFer Size : Ch#9 772#define DMA9_CNT1 0x100120 /* DMA BuFFer Size : Ch#9 */
773 773
774//***************************************************************************** 774/* ***************************************************************************** */
775#define DMA10_CNT1 0x100124 // DMA BuFFer Size : Ch#10 775#define DMA10_CNT1 0x100124 /* DMA BuFFer Size : Ch#10 */
776 776
777//***************************************************************************** 777/* ***************************************************************************** */
778#define DMA11_CNT1 0x100128 // DMA BuFFer Size : Ch#11 778#define DMA11_CNT1 0x100128 /* DMA BuFFer Size : Ch#11 */
779 779
780//***************************************************************************** 780/* ***************************************************************************** */
781#define DMA12_CNT1 0x10012C // DMA BuFFer Size : Ch#12 781#define DMA12_CNT1 0x10012C /* DMA BuFFer Size : Ch#12 */
782 782
783//***************************************************************************** 783/* ***************************************************************************** */
784#define DMA13_CNT1 0x100130 // DMA BuFFer Size : Ch#13 784#define DMA13_CNT1 0x100130 /* DMA BuFFer Size : Ch#13 */
785 785
786//***************************************************************************** 786/* ***************************************************************************** */
787#define DMA14_CNT1 0x100134 // DMA BuFFer Size : Ch#14 787#define DMA14_CNT1 0x100134 /* DMA BuFFer Size : Ch#14 */
788 788
789//***************************************************************************** 789/* ***************************************************************************** */
790#define DMA15_CNT1 0x100138 // DMA BuFFer Size : Ch#15 790#define DMA15_CNT1 0x100138 /* DMA BuFFer Size : Ch#15 */
791 791
792//***************************************************************************** 792/* ***************************************************************************** */
793#define DMA16_CNT1 0x10013C // DMA BuFFer Size : Ch#16 793#define DMA16_CNT1 0x10013C /* DMA BuFFer Size : Ch#16 */
794 794
795//***************************************************************************** 795/* ***************************************************************************** */
796#define DMA17_CNT1 0x100140 // DMA BuFFer Size : Ch#17 796#define DMA17_CNT1 0x100140 /* DMA BuFFer Size : Ch#17 */
797 797
798//***************************************************************************** 798/* ***************************************************************************** */
799#define DMA18_CNT1 0x100144 // DMA BuFFer Size : Ch#18 799#define DMA18_CNT1 0x100144 /* DMA BuFFer Size : Ch#18 */
800 800
801//***************************************************************************** 801/* ***************************************************************************** */
802#define DMA19_CNT1 0x100148 // DMA BuFFer Size : Ch#19 802#define DMA19_CNT1 0x100148 /* DMA BuFFer Size : Ch#19 */
803 803
804//***************************************************************************** 804/* ***************************************************************************** */
805#define DMA20_CNT1 0x10014C // DMA BuFFer Size : Ch#20 805#define DMA20_CNT1 0x10014C /* DMA BuFFer Size : Ch#20 */
806 806
807//***************************************************************************** 807/* ***************************************************************************** */
808#define DMA21_CNT1 0x100150 // DMA BuFFer Size : Ch#21 808#define DMA21_CNT1 0x100150 /* DMA BuFFer Size : Ch#21 */
809 809
810//***************************************************************************** 810/* ***************************************************************************** */
811#define DMA22_CNT1 0x100154 // DMA BuFFer Size : Ch#22 811#define DMA22_CNT1 0x100154 /* DMA BuFFer Size : Ch#22 */
812 812
813//***************************************************************************** 813/* ***************************************************************************** */
814#define DMA23_CNT1 0x100158 // DMA BuFFer Size : Ch#23 814#define DMA23_CNT1 0x100158 /* DMA BuFFer Size : Ch#23 */
815 815
816//***************************************************************************** 816/* ***************************************************************************** */
817#define DMA24_CNT1 0x10015C // DMA BuFFer Size : Ch#24 817#define DMA24_CNT1 0x10015C /* DMA BuFFer Size : Ch#24 */
818 818
819//***************************************************************************** 819/* ***************************************************************************** */
820#define DMA25_CNT1 0x100160 // DMA BuFFer Size : Ch#25 820#define DMA25_CNT1 0x100160 /* DMA BuFFer Size : Ch#25 */
821 821
822//***************************************************************************** 822/* ***************************************************************************** */
823#define DMA26_CNT1 0x100164 // DMA BuFFer Size : Ch#26 823#define DMA26_CNT1 0x100164 /* DMA BuFFer Size : Ch#26 */
824 824
825//***************************************************************************** 825/* ***************************************************************************** */
826#define DMA1_CNT2 0x100180 // DMA Table Size : Ch#1 826#define DMA1_CNT2 0x100180 /* DMA Table Size : Ch#1 */
827 827
828//***************************************************************************** 828/* ***************************************************************************** */
829#define DMA2_CNT2 0x100184 // DMA Table Size : Ch#2 829#define DMA2_CNT2 0x100184 /* DMA Table Size : Ch#2 */
830 830
831//***************************************************************************** 831/* ***************************************************************************** */
832#define DMA3_CNT2 0x100188 // DMA Table Size : Ch#3 832#define DMA3_CNT2 0x100188 /* DMA Table Size : Ch#3 */
833 833
834//***************************************************************************** 834/* ***************************************************************************** */
835#define DMA4_CNT2 0x10018C // DMA Table Size : Ch#4 835#define DMA4_CNT2 0x10018C /* DMA Table Size : Ch#4 */
836 836
837//***************************************************************************** 837/* ***************************************************************************** */
838#define DMA5_CNT2 0x100190 // DMA Table Size : Ch#5 838#define DMA5_CNT2 0x100190 /* DMA Table Size : Ch#5 */
839 839
840//***************************************************************************** 840/* ***************************************************************************** */
841#define DMA6_CNT2 0x100194 // DMA Table Size : Ch#6 841#define DMA6_CNT2 0x100194 /* DMA Table Size : Ch#6 */
842 842
843//***************************************************************************** 843/* ***************************************************************************** */
844#define DMA7_CNT2 0x100198 // DMA Table Size : Ch#7 844#define DMA7_CNT2 0x100198 /* DMA Table Size : Ch#7 */
845 845
846//***************************************************************************** 846/* ***************************************************************************** */
847#define DMA8_CNT2 0x10019C // DMA Table Size : Ch#8 847#define DMA8_CNT2 0x10019C /* DMA Table Size : Ch#8 */
848 848
849//***************************************************************************** 849/* ***************************************************************************** */
850#define DMA9_CNT2 0x1001A0 // DMA Table Size : Ch#9 850#define DMA9_CNT2 0x1001A0 /* DMA Table Size : Ch#9 */
851 851
852//***************************************************************************** 852/* ***************************************************************************** */
853#define DMA10_CNT2 0x1001A4 // DMA Table Size : Ch#10 853#define DMA10_CNT2 0x1001A4 /* DMA Table Size : Ch#10 */
854 854
855//***************************************************************************** 855/* ***************************************************************************** */
856#define DMA11_CNT2 0x1001A8 // DMA Table Size : Ch#11 856#define DMA11_CNT2 0x1001A8 /* DMA Table Size : Ch#11 */
857 857
858//***************************************************************************** 858/* ***************************************************************************** */
859#define DMA12_CNT2 0x1001AC // DMA Table Size : Ch#12 859#define DMA12_CNT2 0x1001AC /* DMA Table Size : Ch#12 */
860 860
861//***************************************************************************** 861/* ***************************************************************************** */
862#define DMA13_CNT2 0x1001B0 // DMA Table Size : Ch#13 862#define DMA13_CNT2 0x1001B0 /* DMA Table Size : Ch#13 */
863 863
864//***************************************************************************** 864/* ***************************************************************************** */
865#define DMA14_CNT2 0x1001B4 // DMA Table Size : Ch#14 865#define DMA14_CNT2 0x1001B4 /* DMA Table Size : Ch#14 */
866 866
867//***************************************************************************** 867/* ***************************************************************************** */
868#define DMA15_CNT2 0x1001B8 // DMA Table Size : Ch#15 868#define DMA15_CNT2 0x1001B8 /* DMA Table Size : Ch#15 */
869 869
870//***************************************************************************** 870/* ***************************************************************************** */
871#define DMA16_CNT2 0x1001BC // DMA Table Size : Ch#16 871#define DMA16_CNT2 0x1001BC /* DMA Table Size : Ch#16 */
872 872
873//***************************************************************************** 873/* ***************************************************************************** */
874#define DMA17_CNT2 0x1001C0 // DMA Table Size : Ch#17 874#define DMA17_CNT2 0x1001C0 /* DMA Table Size : Ch#17 */
875 875
876//***************************************************************************** 876/* ***************************************************************************** */
877#define DMA18_CNT2 0x1001C4 // DMA Table Size : Ch#18 877#define DMA18_CNT2 0x1001C4 /* DMA Table Size : Ch#18 */
878 878
879//***************************************************************************** 879/* ***************************************************************************** */
880#define DMA19_CNT2 0x1001C8 // DMA Table Size : Ch#19 880#define DMA19_CNT2 0x1001C8 /* DMA Table Size : Ch#19 */
881 881
882//***************************************************************************** 882/* ***************************************************************************** */
883#define DMA20_CNT2 0x1001CC // DMA Table Size : Ch#20 883#define DMA20_CNT2 0x1001CC /* DMA Table Size : Ch#20 */
884 884
885//***************************************************************************** 885/* ***************************************************************************** */
886#define DMA21_CNT2 0x1001D0 // DMA Table Size : Ch#21 886#define DMA21_CNT2 0x1001D0 /* DMA Table Size : Ch#21 */
887 887
888//***************************************************************************** 888/* ***************************************************************************** */
889#define DMA22_CNT2 0x1001D4 // DMA Table Size : Ch#22 889#define DMA22_CNT2 0x1001D4 /* DMA Table Size : Ch#22 */
890 890
891//***************************************************************************** 891/* ***************************************************************************** */
892#define DMA23_CNT2 0x1001D8 // DMA Table Size : Ch#23 892#define DMA23_CNT2 0x1001D8 /* DMA Table Size : Ch#23 */
893 893
894//***************************************************************************** 894/* ***************************************************************************** */
895#define DMA24_CNT2 0x1001DC // DMA Table Size : Ch#24 895#define DMA24_CNT2 0x1001DC /* DMA Table Size : Ch#24 */
896 896
897//***************************************************************************** 897/* ***************************************************************************** */
898#define DMA25_CNT2 0x1001E0 // DMA Table Size : Ch#25 898#define DMA25_CNT2 0x1001E0 /* DMA Table Size : Ch#25 */
899 899
900//***************************************************************************** 900/* ***************************************************************************** */
901#define DMA26_CNT2 0x1001E4 // DMA Table Size : Ch#26 901#define DMA26_CNT2 0x1001E4 /* DMA Table Size : Ch#26 */
902 902
903//***************************************************************************** 903/* ***************************************************************************** */
904 // ITG 904 /* ITG */
905//***************************************************************************** 905/* ***************************************************************************** */
906#define TM_CNT_LDW 0x110000 // Timer : Counter low 906#define TM_CNT_LDW 0x110000 /* Timer : Counter low */
907 907
908//***************************************************************************** 908/* ***************************************************************************** */
909#define TM_CNT_UW 0x110004 // Timer : Counter high word 909#define TM_CNT_UW 0x110004 /* Timer : Counter high word */
910 910
911//***************************************************************************** 911/* ***************************************************************************** */
912#define TM_LMT_LDW 0x110008 // Timer : Limit low 912#define TM_LMT_LDW 0x110008 /* Timer : Limit low */
913 913
914//***************************************************************************** 914/* ***************************************************************************** */
915#define TM_LMT_UW 0x11000C // Timer : Limit high word 915#define TM_LMT_UW 0x11000C /* Timer : Limit high word */
916 916
917//***************************************************************************** 917/* ***************************************************************************** */
918#define GP0_IO 0x110010 // GPIO output enables data I/O 918#define GP0_IO 0x110010 /* GPIO output enables data I/O */
919#define FLD_GP_OE 0x00FF0000 // GPIO: GP_OE output enable 919#define FLD_GP_OE 0x00FF0000 /* GPIO: GP_OE output enable */
920#define FLD_GP_IN 0x0000FF00 // GPIO: GP_IN status 920#define FLD_GP_IN 0x0000FF00 /* GPIO: GP_IN status */
921#define FLD_GP_OUT 0x000000FF // GPIO: GP_OUT control 921#define FLD_GP_OUT 0x000000FF /* GPIO: GP_OUT control */
922 922
923//***************************************************************************** 923/* ***************************************************************************** */
924#define GPIO_ISM 0x110014 // GPIO interrupt sensitivity mode 924#define GPIO_ISM 0x110014 /* GPIO interrupt sensitivity mode */
925#define FLD_GP_ISM_SNS 0x00000070 925#define FLD_GP_ISM_SNS 0x00000070
926#define FLD_GP_ISM_POL 0x00000007 926#define FLD_GP_ISM_POL 0x00000007
927 927
928//***************************************************************************** 928/* ***************************************************************************** */
929#define SOFT_RESET 0x11001C // Output system reset reg 929#define SOFT_RESET 0x11001C /* Output system reset reg */
930#define FLD_PECOS_SOFT_RESET 0x00000001 930#define FLD_PECOS_SOFT_RESET 0x00000001
931 931
932//***************************************************************************** 932/* ***************************************************************************** */
933#define MC416_RWD 0x110020 // MC416 GPIO[18:3] pin 933#define MC416_RWD 0x110020 /* MC416 GPIO[18:3] pin */
934#define MC416_OEN 0x110024 // Output enable of GPIO[18:3] 934#define MC416_OEN 0x110024 /* Output enable of GPIO[18:3] */
935#define MC416_CTL 0x110028 935#define MC416_CTL 0x110028
936 936
937//***************************************************************************** 937/* ***************************************************************************** */
938#define ALT_PIN_OUT_SEL 0x11002C // Alternate GPIO output select 938#define ALT_PIN_OUT_SEL 0x11002C /* Alternate GPIO output select */
939 939
940#define FLD_ALT_GPIO_OUT_SEL 0xF0000000 940#define FLD_ALT_GPIO_OUT_SEL 0xF0000000
941// 0 Disabled <-- default 941/* 0 Disabled <-- default */
942// 1 GPIO[0] 942/* 1 GPIO[0] */
943// 2 GPIO[10] 943/* 2 GPIO[10] */
944// 3 VIP_656_DATA_VAL 944/* 3 VIP_656_DATA_VAL */
945// 4 VIP_656_DATA[0] 945/* 4 VIP_656_DATA[0] */
946// 5 VIP_656_CLK 946/* 5 VIP_656_CLK */
947// 6 VIP_656_DATA_EXT[1] 947/* 6 VIP_656_DATA_EXT[1] */
948// 7 VIP_656_DATA_EXT[0] 948/* 7 VIP_656_DATA_EXT[0] */
949// 8 ATT_IF 949/* 8 ATT_IF */
950 950
951#define FLD_AUX_PLL_CLK_ALT_SEL 0x0F000000 951#define FLD_AUX_PLL_CLK_ALT_SEL 0x0F000000
952// 0 AUX_PLL_CLK<-- default 952/* 0 AUX_PLL_CLK<-- default */
953// 1 GPIO[2] 953/* 1 GPIO[2] */
954// 2 GPIO[10] 954/* 2 GPIO[10] */
955// 3 VIP_656_DATA_VAL 955/* 3 VIP_656_DATA_VAL */
956// 4 VIP_656_DATA[0] 956/* 4 VIP_656_DATA[0] */
957// 5 VIP_656_CLK 957/* 5 VIP_656_CLK */
958// 6 VIP_656_DATA_EXT[1] 958/* 6 VIP_656_DATA_EXT[1] */
959// 7 VIP_656_DATA_EXT[0] 959/* 7 VIP_656_DATA_EXT[0] */
960 960
961#define FLD_IR_TX_ALT_SEL 0x00F00000 961#define FLD_IR_TX_ALT_SEL 0x00F00000
962// 0 IR_TX <-- default 962/* 0 IR_TX <-- default */
963// 1 GPIO[1] 963/* 1 GPIO[1] */
964// 2 GPIO[10] 964/* 2 GPIO[10] */
965// 3 VIP_656_DATA_VAL 965/* 3 VIP_656_DATA_VAL */
966// 4 VIP_656_DATA[0] 966/* 4 VIP_656_DATA[0] */
967// 5 VIP_656_CLK 967/* 5 VIP_656_CLK */
968// 6 VIP_656_DATA_EXT[1] 968/* 6 VIP_656_DATA_EXT[1] */
969// 7 VIP_656_DATA_EXT[0] 969/* 7 VIP_656_DATA_EXT[0] */
970 970
971#define FLD_IR_RX_ALT_SEL 0x000F0000 971#define FLD_IR_RX_ALT_SEL 0x000F0000
972// 0 IR_RX <-- default 972/* 0 IR_RX <-- default */
973// 1 GPIO[0] 973/* 1 GPIO[0] */
974// 2 GPIO[10] 974/* 2 GPIO[10] */
975// 3 VIP_656_DATA_VAL 975/* 3 VIP_656_DATA_VAL */
976// 4 VIP_656_DATA[0] 976/* 4 VIP_656_DATA[0] */
977// 5 VIP_656_CLK 977/* 5 VIP_656_CLK */
978// 6 VIP_656_DATA_EXT[1] 978/* 6 VIP_656_DATA_EXT[1] */
979// 7 VIP_656_DATA_EXT[0] 979/* 7 VIP_656_DATA_EXT[0] */
980 980
981#define FLD_GPIO10_ALT_SEL 0x0000F000 981#define FLD_GPIO10_ALT_SEL 0x0000F000
982// 0 GPIO[10] <-- default 982/* 0 GPIO[10] <-- default */
983// 1 GPIO[0] 983/* 1 GPIO[0] */
984// 2 GPIO[10] 984/* 2 GPIO[10] */
985// 3 VIP_656_DATA_VAL 985/* 3 VIP_656_DATA_VAL */
986// 4 VIP_656_DATA[0] 986/* 4 VIP_656_DATA[0] */
987// 5 VIP_656_CLK 987/* 5 VIP_656_CLK */
988// 6 VIP_656_DATA_EXT[1] 988/* 6 VIP_656_DATA_EXT[1] */
989// 7 VIP_656_DATA_EXT[0] 989/* 7 VIP_656_DATA_EXT[0] */
990 990
991#define FLD_GPIO2_ALT_SEL 0x00000F00 991#define FLD_GPIO2_ALT_SEL 0x00000F00
992// 0 GPIO[2] <-- default 992/* 0 GPIO[2] <-- default */
993// 1 GPIO[1] 993/* 1 GPIO[1] */
994// 2 GPIO[10] 994/* 2 GPIO[10] */
995// 3 VIP_656_DATA_VAL 995/* 3 VIP_656_DATA_VAL */
996// 4 VIP_656_DATA[0] 996/* 4 VIP_656_DATA[0] */
997// 5 VIP_656_CLK 997/* 5 VIP_656_CLK */
998// 6 VIP_656_DATA_EXT[1] 998/* 6 VIP_656_DATA_EXT[1] */
999// 7 VIP_656_DATA_EXT[0] 999/* 7 VIP_656_DATA_EXT[0] */
1000 1000
1001#define FLD_GPIO1_ALT_SEL 0x000000F0 1001#define FLD_GPIO1_ALT_SEL 0x000000F0
1002// 0 GPIO[1] <-- default 1002/* 0 GPIO[1] <-- default */
1003// 1 GPIO[0] 1003/* 1 GPIO[0] */
1004// 2 GPIO[10] 1004/* 2 GPIO[10] */
1005// 3 VIP_656_DATA_VAL 1005/* 3 VIP_656_DATA_VAL */
1006// 4 VIP_656_DATA[0] 1006/* 4 VIP_656_DATA[0] */
1007// 5 VIP_656_CLK 1007/* 5 VIP_656_CLK */
1008// 6 VIP_656_DATA_EXT[1] 1008/* 6 VIP_656_DATA_EXT[1] */
1009// 7 VIP_656_DATA_EXT[0] 1009/* 7 VIP_656_DATA_EXT[0] */
1010 1010
1011#define FLD_GPIO0_ALT_SEL 0x0000000F 1011#define FLD_GPIO0_ALT_SEL 0x0000000F
1012// 0 GPIO[0] <-- default 1012/* 0 GPIO[0] <-- default */
1013// 1 GPIO[1] 1013/* 1 GPIO[1] */
1014// 2 GPIO[10] 1014/* 2 GPIO[10] */
1015// 3 VIP_656_DATA_VAL 1015/* 3 VIP_656_DATA_VAL */
1016// 4 VIP_656_DATA[0] 1016/* 4 VIP_656_DATA[0] */
1017// 5 VIP_656_CLK 1017/* 5 VIP_656_CLK */
1018// 6 VIP_656_DATA_EXT[1] 1018/* 6 VIP_656_DATA_EXT[1] */
1019// 7 VIP_656_DATA_EXT[0] 1019/* 7 VIP_656_DATA_EXT[0] */
1020 1020
1021#define ALT_PIN_IN_SEL 0x110030 // Alternate GPIO input select 1021#define ALT_PIN_IN_SEL 0x110030 /* Alternate GPIO input select */
1022 1022
1023#define FLD_GPIO10_ALT_IN_SEL 0x0000F000 1023#define FLD_GPIO10_ALT_IN_SEL 0x0000F000
1024// 0 GPIO[10] <-- default 1024/* 0 GPIO[10] <-- default */
1025// 1 IR_RX 1025/* 1 IR_RX */
1026// 2 IR_TX 1026/* 2 IR_TX */
1027// 3 AUX_PLL_CLK 1027/* 3 AUX_PLL_CLK */
1028// 4 IF_ATT_SEL 1028/* 4 IF_ATT_SEL */
1029// 5 GPIO[0] 1029/* 5 GPIO[0] */
1030// 6 GPIO[1] 1030/* 6 GPIO[1] */
1031// 7 GPIO[2] 1031/* 7 GPIO[2] */
1032 1032
1033#define FLD_GPIO2_ALT_IN_SEL 0x00000F00 1033#define FLD_GPIO2_ALT_IN_SEL 0x00000F00
1034// 0 GPIO[2] <-- default 1034/* 0 GPIO[2] <-- default */
1035// 1 IR_RX 1035/* 1 IR_RX */
1036// 2 IR_TX 1036/* 2 IR_TX */
1037// 3 AUX_PLL_CLK 1037/* 3 AUX_PLL_CLK */
1038// 4 IF_ATT_SEL 1038/* 4 IF_ATT_SEL */
1039 1039
1040#define FLD_GPIO1_ALT_IN_SEL 0x000000F0 1040#define FLD_GPIO1_ALT_IN_SEL 0x000000F0
1041// 0 GPIO[1] <-- default 1041/* 0 GPIO[1] <-- default */
1042// 1 IR_RX 1042/* 1 IR_RX */
1043// 2 IR_TX 1043/* 2 IR_TX */
1044// 3 AUX_PLL_CLK 1044/* 3 AUX_PLL_CLK */
1045// 4 IF_ATT_SEL 1045/* 4 IF_ATT_SEL */
1046 1046
1047#define FLD_GPIO0_ALT_IN_SEL 0x0000000F 1047#define FLD_GPIO0_ALT_IN_SEL 0x0000000F
1048// 0 GPIO[0] <-- default 1048/* 0 GPIO[0] <-- default */
1049// 1 IR_RX 1049/* 1 IR_RX */
1050// 2 IR_TX 1050/* 2 IR_TX */
1051// 3 AUX_PLL_CLK 1051/* 3 AUX_PLL_CLK */
1052// 4 IF_ATT_SEL 1052/* 4 IF_ATT_SEL */
1053 1053
1054//***************************************************************************** 1054/* ***************************************************************************** */
1055#define TEST_BUS_CTL1 0x110040 // Test bus control register #1 1055#define TEST_BUS_CTL1 0x110040 /* Test bus control register #1 */
1056 1056
1057//***************************************************************************** 1057/* ***************************************************************************** */
1058#define TEST_BUS_CTL2 0x110044 // Test bus control register #2 1058#define TEST_BUS_CTL2 0x110044 /* Test bus control register #2 */
1059 1059
1060//***************************************************************************** 1060/* ***************************************************************************** */
1061#define CLK_DELAY 0x110048 // Clock delay 1061#define CLK_DELAY 0x110048 /* Clock delay */
1062#define FLD_MOE_CLK_DIS 0x80000000 // Disable MoE clock 1062#define FLD_MOE_CLK_DIS 0x80000000 /* Disable MoE clock */
1063 1063
1064//***************************************************************************** 1064/* ***************************************************************************** */
1065#define PAD_CTRL 0x110068 // Pad drive strength control 1065#define PAD_CTRL 0x110068 /* Pad drive strength control */
1066 1066
1067//***************************************************************************** 1067/* ***************************************************************************** */
1068#define MBIST_CTRL 0x110050 // SRAM memory built-in self test control 1068#define MBIST_CTRL 0x110050 /* SRAM memory built-in self test control */
1069 1069
1070//***************************************************************************** 1070/* ***************************************************************************** */
1071#define MBIST_STAT 0x110054 // SRAM memory built-in self test status 1071#define MBIST_STAT 0x110054 /* SRAM memory built-in self test status */
1072 1072
1073//***************************************************************************** 1073/* ***************************************************************************** */
1074// PLL registers 1074/* PLL registers */
1075//***************************************************************************** 1075/* ***************************************************************************** */
1076#define PLL_A_INT_FRAC 0x110088 1076#define PLL_A_INT_FRAC 0x110088
1077#define PLL_A_POST_STAT_BIST 0x11008C 1077#define PLL_A_POST_STAT_BIST 0x11008C
1078#define PLL_B_INT_FRAC 0x110090 1078#define PLL_B_INT_FRAC 0x110090
@@ -1090,260 +1090,260 @@
1090#define VID_CH_MODE_SEL 0x110078 1090#define VID_CH_MODE_SEL 0x110078
1091#define VID_CH_CLK_SEL 0x11007C 1091#define VID_CH_CLK_SEL 0x11007C
1092 1092
1093//***************************************************************************** 1093/* ***************************************************************************** */
1094#define VBI_A_DMA 0x130008 // VBI A DMA data port 1094#define VBI_A_DMA 0x130008 /* VBI A DMA data port */
1095 1095
1096//***************************************************************************** 1096/* ***************************************************************************** */
1097#define VID_A_VIP_CTL 0x130080 // Video A VIP format control 1097#define VID_A_VIP_CTL 0x130080 /* Video A VIP format control */
1098#define FLD_VIP_MODE 0x00000001 1098#define FLD_VIP_MODE 0x00000001
1099 1099
1100//***************************************************************************** 1100/* ***************************************************************************** */
1101#define VID_A_PIXEL_FRMT 0x130084 // Video A pixel format 1101#define VID_A_PIXEL_FRMT 0x130084 /* Video A pixel format */
1102#define FLD_VID_A_GAMMA_DIS 0x00000008 1102#define FLD_VID_A_GAMMA_DIS 0x00000008
1103#define FLD_VID_A_FORMAT 0x00000007 1103#define FLD_VID_A_FORMAT 0x00000007
1104#define FLD_VID_A_GAMMA_FACTOR 0x00000010 1104#define FLD_VID_A_GAMMA_FACTOR 0x00000010
1105 1105
1106//***************************************************************************** 1106/* ***************************************************************************** */
1107#define VID_A_VBI_CTL 0x130088 // Video A VBI miscellaneous control 1107#define VID_A_VBI_CTL 0x130088 /* Video A VBI miscellaneous control */
1108#define FLD_VID_A_VIP_EXT 0x00000003 1108#define FLD_VID_A_VIP_EXT 0x00000003
1109 1109
1110//***************************************************************************** 1110/* ***************************************************************************** */
1111#define VID_B_DMA 0x130100 // Video B DMA data port 1111#define VID_B_DMA 0x130100 /* Video B DMA data port */
1112 1112
1113//***************************************************************************** 1113/* ***************************************************************************** */
1114#define VBI_B_DMA 0x130108 // VBI B DMA data port 1114#define VBI_B_DMA 0x130108 /* VBI B DMA data port */
1115 1115
1116//***************************************************************************** 1116/* ***************************************************************************** */
1117#define VID_B_SRC_SEL 0x130144 // Video B source select 1117#define VID_B_SRC_SEL 0x130144 /* Video B source select */
1118#define FLD_VID_B_SRC_SEL 0x00000000 1118#define FLD_VID_B_SRC_SEL 0x00000000
1119 1119
1120//***************************************************************************** 1120/* ***************************************************************************** */
1121#define VID_B_LNGTH 0x130150 // Video B line length 1121#define VID_B_LNGTH 0x130150 /* Video B line length */
1122#define FLD_VID_B_LN_LNGTH 0x00000FFF 1122#define FLD_VID_B_LN_LNGTH 0x00000FFF
1123 1123
1124//***************************************************************************** 1124/* ***************************************************************************** */
1125#define VID_B_VIP_CTL 0x130180 // Video B VIP format control 1125#define VID_B_VIP_CTL 0x130180 /* Video B VIP format control */
1126 1126
1127//***************************************************************************** 1127/* ***************************************************************************** */
1128#define VID_B_PIXEL_FRMT 0x130184 // Video B pixel format 1128#define VID_B_PIXEL_FRMT 0x130184 /* Video B pixel format */
1129#define FLD_VID_B_GAMMA_DIS 0x00000008 1129#define FLD_VID_B_GAMMA_DIS 0x00000008
1130#define FLD_VID_B_FORMAT 0x00000007 1130#define FLD_VID_B_FORMAT 0x00000007
1131#define FLD_VID_B_GAMMA_FACTOR 0x00000010 1131#define FLD_VID_B_GAMMA_FACTOR 0x00000010
1132 1132
1133//***************************************************************************** 1133/* ***************************************************************************** */
1134#define VID_C_DMA 0x130200 // Video C DMA data port 1134#define VID_C_DMA 0x130200 /* Video C DMA data port */
1135 1135
1136//***************************************************************************** 1136/* ***************************************************************************** */
1137#define VID_C_LNGTH 0x130250 // Video C line length 1137#define VID_C_LNGTH 0x130250 /* Video C line length */
1138#define FLD_VID_C_LN_LNGTH 0x00000FFF 1138#define FLD_VID_C_LN_LNGTH 0x00000FFF
1139 1139
1140//***************************************************************************** 1140/* ***************************************************************************** */
1141// Video Destination Channels 1141/* Video Destination Channels */
1142//***************************************************************************** 1142/* ***************************************************************************** */
1143 1143
1144#define VID_DST_A_GPCNT 0x130020 // Video A general purpose counter 1144#define VID_DST_A_GPCNT 0x130020 /* Video A general purpose counter */
1145#define VID_DST_B_GPCNT 0x130120 // Video B general purpose counter 1145#define VID_DST_B_GPCNT 0x130120 /* Video B general purpose counter */
1146#define VID_DST_C_GPCNT 0x130220 // Video C general purpose counter 1146#define VID_DST_C_GPCNT 0x130220 /* Video C general purpose counter */
1147#define VID_DST_D_GPCNT 0x130320 // Video D general purpose counter 1147#define VID_DST_D_GPCNT 0x130320 /* Video D general purpose counter */
1148#define VID_DST_E_GPCNT 0x130420 // Video E general purpose counter 1148#define VID_DST_E_GPCNT 0x130420 /* Video E general purpose counter */
1149#define VID_DST_F_GPCNT 0x130520 // Video F general purpose counter 1149#define VID_DST_F_GPCNT 0x130520 /* Video F general purpose counter */
1150#define VID_DST_G_GPCNT 0x130620 // Video G general purpose counter 1150#define VID_DST_G_GPCNT 0x130620 /* Video G general purpose counter */
1151#define VID_DST_H_GPCNT 0x130720 // Video H general purpose counter 1151#define VID_DST_H_GPCNT 0x130720 /* Video H general purpose counter */
1152 1152
1153//***************************************************************************** 1153/* ***************************************************************************** */
1154 1154
1155#define VID_DST_A_GPCNT_CTL 0x130030 // Video A general purpose control 1155#define VID_DST_A_GPCNT_CTL 0x130030 /* Video A general purpose control */
1156#define VID_DST_B_GPCNT_CTL 0x130130 // Video B general purpose control 1156#define VID_DST_B_GPCNT_CTL 0x130130 /* Video B general purpose control */
1157#define VID_DST_C_GPCNT_CTL 0x130230 // Video C general purpose control 1157#define VID_DST_C_GPCNT_CTL 0x130230 /* Video C general purpose control */
1158#define VID_DST_D_GPCNT_CTL 0x130330 // Video D general purpose control 1158#define VID_DST_D_GPCNT_CTL 0x130330 /* Video D general purpose control */
1159#define VID_DST_E_GPCNT_CTL 0x130430 // Video E general purpose control 1159#define VID_DST_E_GPCNT_CTL 0x130430 /* Video E general purpose control */
1160#define VID_DST_F_GPCNT_CTL 0x130530 // Video F general purpose control 1160#define VID_DST_F_GPCNT_CTL 0x130530 /* Video F general purpose control */
1161#define VID_DST_G_GPCNT_CTL 0x130630 // Video G general purpose control 1161#define VID_DST_G_GPCNT_CTL 0x130630 /* Video G general purpose control */
1162#define VID_DST_H_GPCNT_CTL 0x130730 // Video H general purpose control 1162#define VID_DST_H_GPCNT_CTL 0x130730 /* Video H general purpose control */
1163 1163
1164//***************************************************************************** 1164/* ***************************************************************************** */
1165 1165
1166#define VID_DST_A_DMA_CTL 0x130040 // Video A DMA control 1166#define VID_DST_A_DMA_CTL 0x130040 /* Video A DMA control */
1167#define VID_DST_B_DMA_CTL 0x130140 // Video B DMA control 1167#define VID_DST_B_DMA_CTL 0x130140 /* Video B DMA control */
1168#define VID_DST_C_DMA_CTL 0x130240 // Video C DMA control 1168#define VID_DST_C_DMA_CTL 0x130240 /* Video C DMA control */
1169#define VID_DST_D_DMA_CTL 0x130340 // Video D DMA control 1169#define VID_DST_D_DMA_CTL 0x130340 /* Video D DMA control */
1170#define VID_DST_E_DMA_CTL 0x130440 // Video E DMA control 1170#define VID_DST_E_DMA_CTL 0x130440 /* Video E DMA control */
1171#define VID_DST_F_DMA_CTL 0x130540 // Video F DMA control 1171#define VID_DST_F_DMA_CTL 0x130540 /* Video F DMA control */
1172#define VID_DST_G_DMA_CTL 0x130640 // Video G DMA control 1172#define VID_DST_G_DMA_CTL 0x130640 /* Video G DMA control */
1173#define VID_DST_H_DMA_CTL 0x130740 // Video H DMA control 1173#define VID_DST_H_DMA_CTL 0x130740 /* Video H DMA control */
1174 1174
1175#define FLD_VID_RISC_EN 0x00000010 1175#define FLD_VID_RISC_EN 0x00000010
1176#define FLD_VID_FIFO_EN 0x00000001 1176#define FLD_VID_FIFO_EN 0x00000001
1177 1177
1178//***************************************************************************** 1178/* ***************************************************************************** */
1179 1179
1180#define VID_DST_A_VIP_CTL 0x130080 // Video A VIP control 1180#define VID_DST_A_VIP_CTL 0x130080 /* Video A VIP control */
1181#define VID_DST_B_VIP_CTL 0x130180 // Video B VIP control 1181#define VID_DST_B_VIP_CTL 0x130180 /* Video B VIP control */
1182#define VID_DST_C_VIP_CTL 0x130280 // Video C VIP control 1182#define VID_DST_C_VIP_CTL 0x130280 /* Video C VIP control */
1183#define VID_DST_D_VIP_CTL 0x130380 // Video D VIP control 1183#define VID_DST_D_VIP_CTL 0x130380 /* Video D VIP control */
1184#define VID_DST_E_VIP_CTL 0x130480 // Video E VIP control 1184#define VID_DST_E_VIP_CTL 0x130480 /* Video E VIP control */
1185#define VID_DST_F_VIP_CTL 0x130580 // Video F VIP control 1185#define VID_DST_F_VIP_CTL 0x130580 /* Video F VIP control */
1186#define VID_DST_G_VIP_CTL 0x130680 // Video G VIP control 1186#define VID_DST_G_VIP_CTL 0x130680 /* Video G VIP control */
1187#define VID_DST_H_VIP_CTL 0x130780 // Video H VIP control 1187#define VID_DST_H_VIP_CTL 0x130780 /* Video H VIP control */
1188 1188
1189//***************************************************************************** 1189/* ***************************************************************************** */
1190 1190
1191#define VID_DST_A_PIX_FRMT 0x130084 // Video A Pixel format 1191#define VID_DST_A_PIX_FRMT 0x130084 /* Video A Pixel format */
1192#define VID_DST_B_PIX_FRMT 0x130184 // Video B Pixel format 1192#define VID_DST_B_PIX_FRMT 0x130184 /* Video B Pixel format */
1193#define VID_DST_C_PIX_FRMT 0x130284 // Video C Pixel format 1193#define VID_DST_C_PIX_FRMT 0x130284 /* Video C Pixel format */
1194#define VID_DST_D_PIX_FRMT 0x130384 // Video D Pixel format 1194#define VID_DST_D_PIX_FRMT 0x130384 /* Video D Pixel format */
1195#define VID_DST_E_PIX_FRMT 0x130484 // Video E Pixel format 1195#define VID_DST_E_PIX_FRMT 0x130484 /* Video E Pixel format */
1196#define VID_DST_F_PIX_FRMT 0x130584 // Video F Pixel format 1196#define VID_DST_F_PIX_FRMT 0x130584 /* Video F Pixel format */
1197#define VID_DST_G_PIX_FRMT 0x130684 // Video G Pixel format 1197#define VID_DST_G_PIX_FRMT 0x130684 /* Video G Pixel format */
1198#define VID_DST_H_PIX_FRMT 0x130784 // Video H Pixel format 1198#define VID_DST_H_PIX_FRMT 0x130784 /* Video H Pixel format */
1199 1199
1200//***************************************************************************** 1200/* ***************************************************************************** */
1201// Video Source Channels 1201/* Video Source Channels */
1202//***************************************************************************** 1202/* ***************************************************************************** */
1203 1203
1204#define VID_SRC_A_GPCNT_CTL 0x130804 // Video A general purpose control 1204#define VID_SRC_A_GPCNT_CTL 0x130804 /* Video A general purpose control */
1205#define VID_SRC_B_GPCNT_CTL 0x130904 // Video B general purpose control 1205#define VID_SRC_B_GPCNT_CTL 0x130904 /* Video B general purpose control */
1206#define VID_SRC_C_GPCNT_CTL 0x130A04 // Video C general purpose control 1206#define VID_SRC_C_GPCNT_CTL 0x130A04 /* Video C general purpose control */
1207#define VID_SRC_D_GPCNT_CTL 0x130B04 // Video D general purpose control 1207#define VID_SRC_D_GPCNT_CTL 0x130B04 /* Video D general purpose control */
1208#define VID_SRC_E_GPCNT_CTL 0x130C04 // Video E general purpose control 1208#define VID_SRC_E_GPCNT_CTL 0x130C04 /* Video E general purpose control */
1209#define VID_SRC_F_GPCNT_CTL 0x130D04 // Video F general purpose control 1209#define VID_SRC_F_GPCNT_CTL 0x130D04 /* Video F general purpose control */
1210#define VID_SRC_I_GPCNT_CTL 0x130E04 // Video I general purpose control 1210#define VID_SRC_I_GPCNT_CTL 0x130E04 /* Video I general purpose control */
1211#define VID_SRC_J_GPCNT_CTL 0x130F04 // Video J general purpose control 1211#define VID_SRC_J_GPCNT_CTL 0x130F04 /* Video J general purpose control */
1212 1212
1213//***************************************************************************** 1213/* ***************************************************************************** */
1214 1214
1215#define VID_SRC_A_GPCNT 0x130808 // Video A general purpose counter 1215#define VID_SRC_A_GPCNT 0x130808 /* Video A general purpose counter */
1216#define VID_SRC_B_GPCNT 0x130908 // Video B general purpose counter 1216#define VID_SRC_B_GPCNT 0x130908 /* Video B general purpose counter */
1217#define VID_SRC_C_GPCNT 0x130A08 // Video C general purpose counter 1217#define VID_SRC_C_GPCNT 0x130A08 /* Video C general purpose counter */
1218#define VID_SRC_D_GPCNT 0x130B08 // Video D general purpose counter 1218#define VID_SRC_D_GPCNT 0x130B08 /* Video D general purpose counter */
1219#define VID_SRC_E_GPCNT 0x130C08 // Video E general purpose counter 1219#define VID_SRC_E_GPCNT 0x130C08 /* Video E general purpose counter */
1220#define VID_SRC_F_GPCNT 0x130D08 // Video F general purpose counter 1220#define VID_SRC_F_GPCNT 0x130D08 /* Video F general purpose counter */
1221#define VID_SRC_I_GPCNT 0x130E08 // Video I general purpose counter 1221#define VID_SRC_I_GPCNT 0x130E08 /* Video I general purpose counter */
1222#define VID_SRC_J_GPCNT 0x130F08 // Video J general purpose counter 1222#define VID_SRC_J_GPCNT 0x130F08 /* Video J general purpose counter */
1223 1223
1224//***************************************************************************** 1224/* ***************************************************************************** */
1225 1225
1226#define VID_SRC_A_DMA_CTL 0x13080C // Video A DMA control 1226#define VID_SRC_A_DMA_CTL 0x13080C /* Video A DMA control */
1227#define VID_SRC_B_DMA_CTL 0x13090C // Video B DMA control 1227#define VID_SRC_B_DMA_CTL 0x13090C /* Video B DMA control */
1228#define VID_SRC_C_DMA_CTL 0x130A0C // Video C DMA control 1228#define VID_SRC_C_DMA_CTL 0x130A0C /* Video C DMA control */
1229#define VID_SRC_D_DMA_CTL 0x130B0C // Video D DMA control 1229#define VID_SRC_D_DMA_CTL 0x130B0C /* Video D DMA control */
1230#define VID_SRC_E_DMA_CTL 0x130C0C // Video E DMA control 1230#define VID_SRC_E_DMA_CTL 0x130C0C /* Video E DMA control */
1231#define VID_SRC_F_DMA_CTL 0x130D0C // Video F DMA control 1231#define VID_SRC_F_DMA_CTL 0x130D0C /* Video F DMA control */
1232#define VID_SRC_I_DMA_CTL 0x130E0C // Video I DMA control 1232#define VID_SRC_I_DMA_CTL 0x130E0C /* Video I DMA control */
1233#define VID_SRC_J_DMA_CTL 0x130F0C // Video J DMA control 1233#define VID_SRC_J_DMA_CTL 0x130F0C /* Video J DMA control */
1234 1234
1235#define FLD_APB_RISC_EN 0x00000010 1235#define FLD_APB_RISC_EN 0x00000010
1236#define FLD_APB_FIFO_EN 0x00000001 1236#define FLD_APB_FIFO_EN 0x00000001
1237 1237
1238//***************************************************************************** 1238/* ***************************************************************************** */
1239 1239
1240#define VID_SRC_A_FMT_CTL 0x130810 // Video A format control 1240#define VID_SRC_A_FMT_CTL 0x130810 /* Video A format control */
1241#define VID_SRC_B_FMT_CTL 0x130910 // Video B format control 1241#define VID_SRC_B_FMT_CTL 0x130910 /* Video B format control */
1242#define VID_SRC_C_FMT_CTL 0x130A10 // Video C format control 1242#define VID_SRC_C_FMT_CTL 0x130A10 /* Video C format control */
1243#define VID_SRC_D_FMT_CTL 0x130B10 // Video D format control 1243#define VID_SRC_D_FMT_CTL 0x130B10 /* Video D format control */
1244#define VID_SRC_E_FMT_CTL 0x130C10 // Video E format control 1244#define VID_SRC_E_FMT_CTL 0x130C10 /* Video E format control */
1245#define VID_SRC_F_FMT_CTL 0x130D10 // Video F format control 1245#define VID_SRC_F_FMT_CTL 0x130D10 /* Video F format control */
1246#define VID_SRC_I_FMT_CTL 0x130E10 // Video I format control 1246#define VID_SRC_I_FMT_CTL 0x130E10 /* Video I format control */
1247#define VID_SRC_J_FMT_CTL 0x130F10 // Video J format control 1247#define VID_SRC_J_FMT_CTL 0x130F10 /* Video J format control */
1248 1248
1249//***************************************************************************** 1249/* ***************************************************************************** */
1250 1250
1251#define VID_SRC_A_ACTIVE_CTL1 0x130814 // Video A active control 1 1251#define VID_SRC_A_ACTIVE_CTL1 0x130814 /* Video A active control 1 */
1252#define VID_SRC_B_ACTIVE_CTL1 0x130914 // Video B active control 1 1252#define VID_SRC_B_ACTIVE_CTL1 0x130914 /* Video B active control 1 */
1253#define VID_SRC_C_ACTIVE_CTL1 0x130A14 // Video C active control 1 1253#define VID_SRC_C_ACTIVE_CTL1 0x130A14 /* Video C active control 1 */
1254#define VID_SRC_D_ACTIVE_CTL1 0x130B14 // Video D active control 1 1254#define VID_SRC_D_ACTIVE_CTL1 0x130B14 /* Video D active control 1 */
1255#define VID_SRC_E_ACTIVE_CTL1 0x130C14 // Video E active control 1 1255#define VID_SRC_E_ACTIVE_CTL1 0x130C14 /* Video E active control 1 */
1256#define VID_SRC_F_ACTIVE_CTL1 0x130D14 // Video F active control 1 1256#define VID_SRC_F_ACTIVE_CTL1 0x130D14 /* Video F active control 1 */
1257#define VID_SRC_I_ACTIVE_CTL1 0x130E14 // Video I active control 1 1257#define VID_SRC_I_ACTIVE_CTL1 0x130E14 /* Video I active control 1 */
1258#define VID_SRC_J_ACTIVE_CTL1 0x130F14 // Video J active control 1 1258#define VID_SRC_J_ACTIVE_CTL1 0x130F14 /* Video J active control 1 */
1259 1259
1260//***************************************************************************** 1260/* ***************************************************************************** */
1261 1261
1262#define VID_SRC_A_ACTIVE_CTL2 0x130818 // Video A active control 2 1262#define VID_SRC_A_ACTIVE_CTL2 0x130818 /* Video A active control 2 */
1263#define VID_SRC_B_ACTIVE_CTL2 0x130918 // Video B active control 2 1263#define VID_SRC_B_ACTIVE_CTL2 0x130918 /* Video B active control 2 */
1264#define VID_SRC_C_ACTIVE_CTL2 0x130A18 // Video C active control 2 1264#define VID_SRC_C_ACTIVE_CTL2 0x130A18 /* Video C active control 2 */
1265#define VID_SRC_D_ACTIVE_CTL2 0x130B18 // Video D active control 2 1265#define VID_SRC_D_ACTIVE_CTL2 0x130B18 /* Video D active control 2 */
1266#define VID_SRC_E_ACTIVE_CTL2 0x130C18 // Video E active control 2 1266#define VID_SRC_E_ACTIVE_CTL2 0x130C18 /* Video E active control 2 */
1267#define VID_SRC_F_ACTIVE_CTL2 0x130D18 // Video F active control 2 1267#define VID_SRC_F_ACTIVE_CTL2 0x130D18 /* Video F active control 2 */
1268#define VID_SRC_I_ACTIVE_CTL2 0x130E18 // Video I active control 2 1268#define VID_SRC_I_ACTIVE_CTL2 0x130E18 /* Video I active control 2 */
1269#define VID_SRC_J_ACTIVE_CTL2 0x130F18 // Video J active control 2 1269#define VID_SRC_J_ACTIVE_CTL2 0x130F18 /* Video J active control 2 */
1270 1270
1271//***************************************************************************** 1271/* ***************************************************************************** */
1272 1272
1273#define VID_SRC_A_CDT_SZ 0x13081C // Video A CDT size 1273#define VID_SRC_A_CDT_SZ 0x13081C /* Video A CDT size */
1274#define VID_SRC_B_CDT_SZ 0x13091C // Video B CDT size 1274#define VID_SRC_B_CDT_SZ 0x13091C /* Video B CDT size */
1275#define VID_SRC_C_CDT_SZ 0x130A1C // Video C CDT size 1275#define VID_SRC_C_CDT_SZ 0x130A1C /* Video C CDT size */
1276#define VID_SRC_D_CDT_SZ 0x130B1C // Video D CDT size 1276#define VID_SRC_D_CDT_SZ 0x130B1C /* Video D CDT size */
1277#define VID_SRC_E_CDT_SZ 0x130C1C // Video E CDT size 1277#define VID_SRC_E_CDT_SZ 0x130C1C /* Video E CDT size */
1278#define VID_SRC_F_CDT_SZ 0x130D1C // Video F CDT size 1278#define VID_SRC_F_CDT_SZ 0x130D1C /* Video F CDT size */
1279#define VID_SRC_I_CDT_SZ 0x130E1C // Video I CDT size 1279#define VID_SRC_I_CDT_SZ 0x130E1C /* Video I CDT size */
1280#define VID_SRC_J_CDT_SZ 0x130F1C // Video J CDT size 1280#define VID_SRC_J_CDT_SZ 0x130F1C /* Video J CDT size */
1281 1281
1282//***************************************************************************** 1282/* ***************************************************************************** */
1283// Audio I/F 1283/* Audio I/F */
1284//***************************************************************************** 1284/* ***************************************************************************** */
1285#define AUD_DST_A_DMA 0x140000 // Audio Int A DMA data port 1285#define AUD_DST_A_DMA 0x140000 /* Audio Int A DMA data port */
1286#define AUD_SRC_A_DMA 0x140008 // Audio Int A DMA data port 1286#define AUD_SRC_A_DMA 0x140008 /* Audio Int A DMA data port */
1287 1287
1288#define AUD_A_GPCNT 0x140010 // Audio Int A gp counter 1288#define AUD_A_GPCNT 0x140010 /* Audio Int A gp counter */
1289#define FLD_AUD_A_GP_CNT 0x0000FFFF 1289#define FLD_AUD_A_GP_CNT 0x0000FFFF
1290 1290
1291#define AUD_A_GPCNT_CTL 0x140014 // Audio Int A gp control 1291#define AUD_A_GPCNT_CTL 0x140014 /* Audio Int A gp control */
1292 1292
1293#define AUD_A_LNGTH 0x140018 // Audio Int A line length 1293#define AUD_A_LNGTH 0x140018 /* Audio Int A line length */
1294 1294
1295#define AUD_A_CFG 0x14001C // Audio Int A configuration 1295#define AUD_A_CFG 0x14001C /* Audio Int A configuration */
1296 1296
1297//***************************************************************************** 1297/* ***************************************************************************** */
1298#define AUD_DST_B_DMA 0x140100 // Audio Int B DMA data port 1298#define AUD_DST_B_DMA 0x140100 /* Audio Int B DMA data port */
1299#define AUD_SRC_B_DMA 0x140108 // Audio Int B DMA data port 1299#define AUD_SRC_B_DMA 0x140108 /* Audio Int B DMA data port */
1300 1300
1301#define AUD_B_GPCNT 0x140110 // Audio Int B gp counter 1301#define AUD_B_GPCNT 0x140110 /* Audio Int B gp counter */
1302#define FLD_AUD_B_GP_CNT 0x0000FFFF 1302#define FLD_AUD_B_GP_CNT 0x0000FFFF
1303 1303
1304#define AUD_B_GPCNT_CTL 0x140114 // Audio Int B gp control 1304#define AUD_B_GPCNT_CTL 0x140114 /* Audio Int B gp control */
1305 1305
1306#define AUD_B_LNGTH 0x140118 // Audio Int B line length 1306#define AUD_B_LNGTH 0x140118 /* Audio Int B line length */
1307 1307
1308#define AUD_B_CFG 0x14011C // Audio Int B configuration 1308#define AUD_B_CFG 0x14011C /* Audio Int B configuration */
1309 1309
1310//***************************************************************************** 1310/* ***************************************************************************** */
1311#define AUD_DST_C_DMA 0x140200 // Audio Int C DMA data port 1311#define AUD_DST_C_DMA 0x140200 /* Audio Int C DMA data port */
1312#define AUD_SRC_C_DMA 0x140208 // Audio Int C DMA data port 1312#define AUD_SRC_C_DMA 0x140208 /* Audio Int C DMA data port */
1313 1313
1314#define AUD_C_GPCNT 0x140210 // Audio Int C gp counter 1314#define AUD_C_GPCNT 0x140210 /* Audio Int C gp counter */
1315#define FLD_AUD_C_GP_CNT 0x0000FFFF 1315#define FLD_AUD_C_GP_CNT 0x0000FFFF
1316 1316
1317#define AUD_C_GPCNT_CTL 0x140214 // Audio Int C gp control 1317#define AUD_C_GPCNT_CTL 0x140214 /* Audio Int C gp control */
1318 1318
1319#define AUD_C_LNGTH 0x140218 // Audio Int C line length 1319#define AUD_C_LNGTH 0x140218 /* Audio Int C line length */
1320 1320
1321#define AUD_C_CFG 0x14021C // Audio Int C configuration 1321#define AUD_C_CFG 0x14021C /* Audio Int C configuration */
1322 1322
1323//***************************************************************************** 1323/* ***************************************************************************** */
1324#define AUD_DST_D_DMA 0x140300 // Audio Int D DMA data port 1324#define AUD_DST_D_DMA 0x140300 /* Audio Int D DMA data port */
1325#define AUD_SRC_D_DMA 0x140308 // Audio Int D DMA data port 1325#define AUD_SRC_D_DMA 0x140308 /* Audio Int D DMA data port */
1326 1326
1327#define AUD_D_GPCNT 0x140310 // Audio Int D gp counter 1327#define AUD_D_GPCNT 0x140310 /* Audio Int D gp counter */
1328#define FLD_AUD_D_GP_CNT 0x0000FFFF 1328#define FLD_AUD_D_GP_CNT 0x0000FFFF
1329 1329
1330#define AUD_D_GPCNT_CTL 0x140314 // Audio Int D gp control 1330#define AUD_D_GPCNT_CTL 0x140314 /* Audio Int D gp control */
1331 1331
1332#define AUD_D_LNGTH 0x140318 // Audio Int D line length 1332#define AUD_D_LNGTH 0x140318 /* Audio Int D line length */
1333 1333
1334#define AUD_D_CFG 0x14031C // Audio Int D configuration 1334#define AUD_D_CFG 0x14031C /* Audio Int D configuration */
1335 1335
1336//***************************************************************************** 1336/* ***************************************************************************** */
1337#define AUD_SRC_E_DMA 0x140400 // Audio Int E DMA data port 1337#define AUD_SRC_E_DMA 0x140400 /* Audio Int E DMA data port */
1338 1338
1339#define AUD_E_GPCNT 0x140410 // Audio Int E gp counter 1339#define AUD_E_GPCNT 0x140410 /* Audio Int E gp counter */
1340#define FLD_AUD_E_GP_CNT 0x0000FFFF 1340#define FLD_AUD_E_GP_CNT 0x0000FFFF
1341 1341
1342#define AUD_E_GPCNT_CTL 0x140414 // Audio Int E gp control 1342#define AUD_E_GPCNT_CTL 0x140414 /* Audio Int E gp control */
1343 1343
1344#define AUD_E_CFG 0x14041C // Audio Int E configuration 1344#define AUD_E_CFG 0x14041C /* Audio Int E configuration */
1345 1345
1346//***************************************************************************** 1346/* ***************************************************************************** */
1347 1347
1348#define FLD_AUD_DST_LN_LNGTH 0x00000FFF 1348#define FLD_AUD_DST_LN_LNGTH 0x00000FFF
1349 1349
@@ -1361,8 +1361,8 @@
1361 1361
1362#define FLD_AUD_SRC_ENABLE 0x00010000 1362#define FLD_AUD_SRC_ENABLE 0x00010000
1363 1363
1364//***************************************************************************** 1364/* ***************************************************************************** */
1365#define AUD_INT_DMA_CTL 0x140500 // Audio Int DMA control 1365#define AUD_INT_DMA_CTL 0x140500 /* Audio Int DMA control */
1366 1366
1367#define FLD_AUD_SRC_E_RISC_EN 0x00008000 1367#define FLD_AUD_SRC_E_RISC_EN 0x00008000
1368#define FLD_AUD_SRC_C_RISC_EN 0x00004000 1368#define FLD_AUD_SRC_C_RISC_EN 0x00004000
@@ -1384,15 +1384,15 @@
1384#define FLD_AUD_DST_B_FIFO_EN 0x00000002 1384#define FLD_AUD_DST_B_FIFO_EN 0x00000002
1385#define FLD_AUD_DST_A_FIFO_EN 0x00000001 1385#define FLD_AUD_DST_A_FIFO_EN 0x00000001
1386 1386
1387//***************************************************************************** 1387/* ***************************************************************************** */
1388// 1388/* */
1389// Mobilygen Interface Registers 1389/* Mobilygen Interface Registers */
1390// 1390/* */
1391//***************************************************************************** 1391/* ***************************************************************************** */
1392// Mobilygen Interface A 1392/* Mobilygen Interface A */
1393//***************************************************************************** 1393/* ***************************************************************************** */
1394#define MB_IF_A_DMA 0x150000 // MBIF A DMA data port 1394#define MB_IF_A_DMA 0x150000 /* MBIF A DMA data port */
1395#define MB_IF_A_GPCN 0x150008 // MBIF A GP counter 1395#define MB_IF_A_GPCN 0x150008 /* MBIF A GP counter */
1396#define MB_IF_A_GPCN_CTRL 0x15000C 1396#define MB_IF_A_GPCN_CTRL 0x15000C
1397#define MB_IF_A_DMA_CTRL 0x150010 1397#define MB_IF_A_DMA_CTRL 0x150010
1398#define MB_IF_A_LENGTH 0x150014 1398#define MB_IF_A_LENGTH 0x150014
@@ -1415,11 +1415,11 @@
1415#define MB_IF_A_DATA_STRUCT_D 0x150058 1415#define MB_IF_A_DATA_STRUCT_D 0x150058
1416#define MB_IF_A_DATA_STRUCT_E 0x15005C 1416#define MB_IF_A_DATA_STRUCT_E 0x15005C
1417#define MB_IF_A_DATA_STRUCT_F 0x150060 1417#define MB_IF_A_DATA_STRUCT_F 0x150060
1418//***************************************************************************** 1418/* ***************************************************************************** */
1419// Mobilygen Interface B 1419/* Mobilygen Interface B */
1420//***************************************************************************** 1420/* ***************************************************************************** */
1421#define MB_IF_B_DMA 0x160000 // MBIF A DMA data port 1421#define MB_IF_B_DMA 0x160000 /* MBIF A DMA data port */
1422#define MB_IF_B_GPCN 0x160008 // MBIF A GP counter 1422#define MB_IF_B_GPCN 0x160008 /* MBIF A GP counter */
1423#define MB_IF_B_GPCN_CTRL 0x16000C 1423#define MB_IF_B_GPCN_CTRL 0x16000C
1424#define MB_IF_B_DMA_CTRL 0x160010 1424#define MB_IF_B_DMA_CTRL 0x160010
1425#define MB_IF_B_LENGTH 0x160014 1425#define MB_IF_B_LENGTH 0x160014
@@ -1443,14 +1443,14 @@
1443#define MB_IF_B_DATA_STRUCT_E 0x16005C 1443#define MB_IF_B_DATA_STRUCT_E 0x16005C
1444#define MB_IF_B_DATA_STRUCT_F 0x160060 1444#define MB_IF_B_DATA_STRUCT_F 0x160060
1445 1445
1446// MB_DMA_CTRL 1446/* MB_DMA_CTRL */
1447#define FLD_MB_IF_RISC_EN 0x00000010 1447#define FLD_MB_IF_RISC_EN 0x00000010
1448#define FLD_MB_IF_FIFO_EN 0x00000001 1448#define FLD_MB_IF_FIFO_EN 0x00000001
1449 1449
1450// MB_LENGTH 1450/* MB_LENGTH */
1451#define FLD_MB_IF_LN_LNGTH 0x00000FFF 1451#define FLD_MB_IF_LN_LNGTH 0x00000FFF
1452 1452
1453// MB_HCMD register 1453/* MB_HCMD register */
1454#define FLD_MB_HCMD_H_GO 0x80000000 1454#define FLD_MB_HCMD_H_GO 0x80000000
1455#define FLD_MB_HCMD_H_BUSY 0x40000000 1455#define FLD_MB_HCMD_H_BUSY 0x40000000
1456#define FLD_MB_HCMD_H_DMA_HOLD 0x10000000 1456#define FLD_MB_HCMD_H_DMA_HOLD 0x10000000
@@ -1461,118 +1461,118 @@
1461#define FLD_MB_HCMD_H_ADDR 0x00FF0000 1461#define FLD_MB_HCMD_H_ADDR 0x00FF0000
1462#define FLD_MB_HCMD_H_DATA 0x0000FFFF 1462#define FLD_MB_HCMD_H_DATA 0x0000FFFF
1463 1463
1464//***************************************************************************** 1464/* ***************************************************************************** */
1465// I2C #1 1465/* I2C #1 */
1466//***************************************************************************** 1466/* ***************************************************************************** */
1467#define I2C1_ADDR 0x180000 // I2C #1 address 1467#define I2C1_ADDR 0x180000 /* I2C #1 address */
1468#define FLD_I2C_DADDR 0xfe000000 // RW [31:25] I2C Device Address 1468#define FLD_I2C_DADDR 0xfe000000 /* RW [31:25] I2C Device Address */
1469 // RO [24] reserved 1469 /* RO [24] reserved */
1470//***************************************************************************** 1470/* ***************************************************************************** */
1471#define FLD_I2C_SADDR 0x00FFFFFF // RW [23:0] I2C Sub-address 1471#define FLD_I2C_SADDR 0x00FFFFFF /* RW [23:0] I2C Sub-address */
1472 1472
1473//***************************************************************************** 1473/* ***************************************************************************** */
1474#define I2C1_WDATA 0x180004 // I2C #1 write data 1474#define I2C1_WDATA 0x180004 /* I2C #1 write data */
1475#define FLD_I2C_WDATA 0xFFFFFFFF // RW [31:0] 1475#define FLD_I2C_WDATA 0xFFFFFFFF /* RW [31:0] */
1476 1476
1477//***************************************************************************** 1477/* ***************************************************************************** */
1478#define I2C1_CTRL 0x180008 // I2C #1 control 1478#define I2C1_CTRL 0x180008 /* I2C #1 control */
1479#define FLD_I2C_PERIOD 0xFF000000 // RW [31:24] 1479#define FLD_I2C_PERIOD 0xFF000000 /* RW [31:24] */
1480#define FLD_I2C_SCL_IN 0x00200000 // RW [21] 1480#define FLD_I2C_SCL_IN 0x00200000 /* RW [21] */
1481#define FLD_I2C_SDA_IN 0x00100000 // RW [20] 1481#define FLD_I2C_SDA_IN 0x00100000 /* RW [20] */
1482 // RO [19:18] reserved 1482 /* RO [19:18] reserved */
1483#define FLD_I2C_SCL_OUT 0x00020000 // RW [17] 1483#define FLD_I2C_SCL_OUT 0x00020000 /* RW [17] */
1484#define FLD_I2C_SDA_OUT 0x00010000 // RW [16] 1484#define FLD_I2C_SDA_OUT 0x00010000 /* RW [16] */
1485 // RO [15] reserved 1485 /* RO [15] reserved */
1486#define FLD_I2C_DATA_LEN 0x00007000 // RW [14:12] 1486#define FLD_I2C_DATA_LEN 0x00007000 /* RW [14:12] */
1487#define FLD_I2C_SADDR_INC 0x00000800 // RW [11] 1487#define FLD_I2C_SADDR_INC 0x00000800 /* RW [11] */
1488 // RO [10:9] reserved 1488 /* RO [10:9] reserved */
1489#define FLD_I2C_SADDR_LEN 0x00000300 // RW [9:8] 1489#define FLD_I2C_SADDR_LEN 0x00000300 /* RW [9:8] */
1490 // RO [7:6] reserved 1490 /* RO [7:6] reserved */
1491#define FLD_I2C_SOFT 0x00000020 // RW [5] 1491#define FLD_I2C_SOFT 0x00000020 /* RW [5] */
1492#define FLD_I2C_NOSTOP 0x00000010 // RW [4] 1492#define FLD_I2C_NOSTOP 0x00000010 /* RW [4] */
1493#define FLD_I2C_EXTEND 0x00000008 // RW [3] 1493#define FLD_I2C_EXTEND 0x00000008 /* RW [3] */
1494#define FLD_I2C_SYNC 0x00000004 // RW [2] 1494#define FLD_I2C_SYNC 0x00000004 /* RW [2] */
1495#define FLD_I2C_READ_SA 0x00000002 // RW [1] 1495#define FLD_I2C_READ_SA 0x00000002 /* RW [1] */
1496#define FLD_I2C_READ_WRN 0x00000001 // RW [0] 1496#define FLD_I2C_READ_WRN 0x00000001 /* RW [0] */
1497 1497
1498//***************************************************************************** 1498/* ***************************************************************************** */
1499#define I2C1_RDATA 0x18000C // I2C #1 read data 1499#define I2C1_RDATA 0x18000C /* I2C #1 read data */
1500#define FLD_I2C_RDATA 0xFFFFFFFF // RO [31:0] 1500#define FLD_I2C_RDATA 0xFFFFFFFF /* RO [31:0] */
1501 1501
1502//***************************************************************************** 1502/* ***************************************************************************** */
1503#define I2C1_STAT 0x180010 // I2C #1 status 1503#define I2C1_STAT 0x180010 /* I2C #1 status */
1504#define FLD_I2C_XFER_IN_PROG 0x00000002 // RO [1] 1504#define FLD_I2C_XFER_IN_PROG 0x00000002 /* RO [1] */
1505#define FLD_I2C_RACK 0x00000001 // RO [0] 1505#define FLD_I2C_RACK 0x00000001 /* RO [0] */
1506 1506
1507//***************************************************************************** 1507/* ***************************************************************************** */
1508// I2C #2 1508/* I2C #2 */
1509//***************************************************************************** 1509/* ***************************************************************************** */
1510#define I2C2_ADDR 0x190000 // I2C #2 address 1510#define I2C2_ADDR 0x190000 /* I2C #2 address */
1511 1511
1512//***************************************************************************** 1512/* ***************************************************************************** */
1513#define I2C2_WDATA 0x190004 // I2C #2 write data 1513#define I2C2_WDATA 0x190004 /* I2C #2 write data */
1514 1514
1515//***************************************************************************** 1515/* ***************************************************************************** */
1516#define I2C2_CTRL 0x190008 // I2C #2 control 1516#define I2C2_CTRL 0x190008 /* I2C #2 control */
1517 1517
1518//***************************************************************************** 1518/* ***************************************************************************** */
1519#define I2C2_RDATA 0x19000C // I2C #2 read data 1519#define I2C2_RDATA 0x19000C /* I2C #2 read data */
1520 1520
1521//***************************************************************************** 1521/* ***************************************************************************** */
1522#define I2C2_STAT 0x190010 // I2C #2 status 1522#define I2C2_STAT 0x190010 /* I2C #2 status */
1523 1523
1524//***************************************************************************** 1524/* ***************************************************************************** */
1525// I2C #3 1525/* I2C #3 */
1526//***************************************************************************** 1526/* ***************************************************************************** */
1527#define I2C3_ADDR 0x1A0000 // I2C #3 address 1527#define I2C3_ADDR 0x1A0000 /* I2C #3 address */
1528 1528
1529//***************************************************************************** 1529/* ***************************************************************************** */
1530#define I2C3_WDATA 0x1A0004 // I2C #3 write data 1530#define I2C3_WDATA 0x1A0004 /* I2C #3 write data */
1531 1531
1532//***************************************************************************** 1532/* ***************************************************************************** */
1533#define I2C3_CTRL 0x1A0008 // I2C #3 control 1533#define I2C3_CTRL 0x1A0008 /* I2C #3 control */
1534 1534
1535//***************************************************************************** 1535/* ***************************************************************************** */
1536#define I2C3_RDATA 0x1A000C // I2C #3 read data 1536#define I2C3_RDATA 0x1A000C /* I2C #3 read data */
1537 1537
1538//***************************************************************************** 1538/* ***************************************************************************** */
1539#define I2C3_STAT 0x1A0010 // I2C #3 status 1539#define I2C3_STAT 0x1A0010 /* I2C #3 status */
1540 1540
1541//***************************************************************************** 1541/* ***************************************************************************** */
1542// UART 1542/* UART */
1543//***************************************************************************** 1543/* ***************************************************************************** */
1544#define UART_CTL 0x1B0000 // UART Control Register 1544#define UART_CTL 0x1B0000 /* UART Control Register */
1545#define FLD_LOOP_BACK_EN (1 << 7) // RW field - default 0 1545#define FLD_LOOP_BACK_EN (1 << 7) /* RW field - default 0 */
1546#define FLD_RX_TRG_SZ (3 << 2) // RW field - default 0 1546#define FLD_RX_TRG_SZ (3 << 2) /* RW field - default 0 */
1547#define FLD_RX_EN (1 << 1) // RW field - default 0 1547#define FLD_RX_EN (1 << 1) /* RW field - default 0 */
1548#define FLD_TX_EN (1 << 0) // RW field - default 0 1548#define FLD_TX_EN (1 << 0) /* RW field - default 0 */
1549 1549
1550//***************************************************************************** 1550/* ***************************************************************************** */
1551#define UART_BRD 0x1B0004 // UART Baud Rate Divisor 1551#define UART_BRD 0x1B0004 /* UART Baud Rate Divisor */
1552#define FLD_BRD 0x0000FFFF // RW field - default 0x197 1552#define FLD_BRD 0x0000FFFF /* RW field - default 0x197 */
1553 1553
1554//***************************************************************************** 1554/* ***************************************************************************** */
1555#define UART_DBUF 0x1B0008 // UART Tx/Rx Data BuFFer 1555#define UART_DBUF 0x1B0008 /* UART Tx/Rx Data BuFFer */
1556#define FLD_DB 0xFFFFFFFF // RW field - default 0 1556#define FLD_DB 0xFFFFFFFF /* RW field - default 0 */
1557 1557
1558//***************************************************************************** 1558/* ***************************************************************************** */
1559#define UART_ISR 0x1B000C // UART Interrupt Status 1559#define UART_ISR 0x1B000C /* UART Interrupt Status */
1560#define FLD_RXD_TIMEOUT_EN (1 << 7) // RW field - default 0 1560#define FLD_RXD_TIMEOUT_EN (1 << 7) /* RW field - default 0 */
1561#define FLD_FRM_ERR_EN (1 << 6) // RW field - default 0 1561#define FLD_FRM_ERR_EN (1 << 6) /* RW field - default 0 */
1562#define FLD_RXD_RDY_EN (1 << 5) // RW field - default 0 1562#define FLD_RXD_RDY_EN (1 << 5) /* RW field - default 0 */
1563#define FLD_TXD_EMPTY_EN (1 << 4) // RW field - default 0 1563#define FLD_TXD_EMPTY_EN (1 << 4) /* RW field - default 0 */
1564#define FLD_RXD_OVERFLOW (1 << 3) // RW field - default 0 1564#define FLD_RXD_OVERFLOW (1 << 3) /* RW field - default 0 */
1565#define FLD_FRM_ERR (1 << 2) // RW field - default 0 1565#define FLD_FRM_ERR (1 << 2) /* RW field - default 0 */
1566#define FLD_RXD_RDY (1 << 1) // RW field - default 0 1566#define FLD_RXD_RDY (1 << 1) /* RW field - default 0 */
1567#define FLD_TXD_EMPTY (1 << 0) // RW field - default 0 1567#define FLD_TXD_EMPTY (1 << 0) /* RW field - default 0 */
1568 1568
1569//***************************************************************************** 1569/* ***************************************************************************** */
1570#define UART_CNT 0x1B0010 // UART Tx/Rx FIFO Byte Count 1570#define UART_CNT 0x1B0010 /* UART Tx/Rx FIFO Byte Count */
1571#define FLD_TXD_CNT (0x1F << 8) // RW field - default 0 1571#define FLD_TXD_CNT (0x1F << 8) /* RW field - default 0 */
1572#define FLD_RXD_CNT (0x1F << 0) // RW field - default 0 1572#define FLD_RXD_CNT (0x1F << 0) /* RW field - default 0 */
1573 1573
1574//***************************************************************************** 1574/* ***************************************************************************** */
1575// Motion Detection 1575/* Motion Detection */
1576#define MD_CH0_GRID_BLOCK_YCNT 0x170014 1576#define MD_CH0_GRID_BLOCK_YCNT 0x170014
1577#define MD_CH1_GRID_BLOCK_YCNT 0x170094 1577#define MD_CH1_GRID_BLOCK_YCNT 0x170094
1578#define MD_CH2_GRID_BLOCK_YCNT 0x170114 1578#define MD_CH2_GRID_BLOCK_YCNT 0x170114
@@ -1589,4 +1589,4 @@
1589#define PIXEL_ENGINE_VIP1 0 1589#define PIXEL_ENGINE_VIP1 0
1590#define PIXEL_ENGINE_VIP2 1 1590#define PIXEL_ENGINE_VIP2 1
1591 1591
1592#endif //Athena_REGISTERS 1592#endif /* Athena_REGISTERS */
diff --git a/drivers/staging/cx25821/cx25821-sram.h b/drivers/staging/cx25821/cx25821-sram.h
index bd677ee22996..5f05d153bc4d 100644
--- a/drivers/staging/cx25821/cx25821-sram.h
+++ b/drivers/staging/cx25821/cx25821-sram.h
@@ -23,34 +23,34 @@
23#ifndef __ATHENA_SRAM_H__ 23#ifndef __ATHENA_SRAM_H__
24#define __ATHENA_SRAM_H__ 24#define __ATHENA_SRAM_H__
25 25
26//#define RX_SRAM_START_SIZE = 0; // Start of reserved SRAM 26/* #define RX_SRAM_START_SIZE = 0; // Start of reserved SRAM */
27#define VID_CMDS_SIZE 80 // Video CMDS size in bytes 27#define VID_CMDS_SIZE 80 /* Video CMDS size in bytes */
28#define AUDIO_CMDS_SIZE 80 // AUDIO CMDS size in bytes 28#define AUDIO_CMDS_SIZE 80 /* AUDIO CMDS size in bytes */
29#define MBIF_CMDS_SIZE 80 // MBIF CMDS size in bytes 29#define MBIF_CMDS_SIZE 80 /* MBIF CMDS size in bytes */
30 30
31//#define RX_SRAM_POOL_START_SIZE = 0; // Start of useable RX SRAM for buffers 31/* #define RX_SRAM_POOL_START_SIZE = 0; // Start of useable RX SRAM for buffers */
32#define VID_IQ_SIZE 64 // VID instruction queue size in bytes 32#define VID_IQ_SIZE 64 /* VID instruction queue size in bytes */
33#define MBIF_IQ_SIZE 64 33#define MBIF_IQ_SIZE 64
34#define AUDIO_IQ_SIZE 64 // AUD instruction queue size in bytes 34#define AUDIO_IQ_SIZE 64 /* AUD instruction queue size in bytes */
35 35
36#define VID_CDT_SIZE 64 // VID cluster descriptor table size in bytes 36#define VID_CDT_SIZE 64 /* VID cluster descriptor table size in bytes */
37#define MBIF_CDT_SIZE 64 // MBIF/HBI cluster descriptor table size in bytes 37#define MBIF_CDT_SIZE 64 /* MBIF/HBI cluster descriptor table size in bytes */
38#define AUDIO_CDT_SIZE 48 // AUD cluster descriptor table size in bytes 38#define AUDIO_CDT_SIZE 48 /* AUD cluster descriptor table size in bytes */
39 39
40//#define RX_SRAM_POOL_FREE_SIZE = 16; // Start of available RX SRAM 40/* #define RX_SRAM_POOL_FREE_SIZE = 16; // Start of available RX SRAM */
41//#define RX_SRAM_END_SIZE = 0; // End of RX SRAM 41/* #define RX_SRAM_END_SIZE = 0; // End of RX SRAM */
42 42
43//#define TX_SRAM_POOL_START_SIZE = 0; // Start of transmit pool SRAM 43/* #define TX_SRAM_POOL_START_SIZE = 0; // Start of transmit pool SRAM */
44//#define MSI_DATA_SIZE = 64; // Reserved (MSI Data, RISC working stora 44/* #define MSI_DATA_SIZE = 64; // Reserved (MSI Data, RISC working stora */
45 45
46#define VID_CLUSTER_SIZE 1440 // VID cluster data line 46#define VID_CLUSTER_SIZE 1440 /* VID cluster data line */
47#define AUDIO_CLUSTER_SIZE 128 // AUDIO cluster data line 47#define AUDIO_CLUSTER_SIZE 128 /* AUDIO cluster data line */
48#define MBIF_CLUSTER_SIZE 1440 // MBIF/HBI cluster data line 48#define MBIF_CLUSTER_SIZE 1440 /* MBIF/HBI cluster data line */
49 49
50//#define TX_SRAM_POOL_FREE_SIZE = 704; // Start of available TX SRAM 50/* #define TX_SRAM_POOL_FREE_SIZE = 704; // Start of available TX SRAM */
51//#define TX_SRAM_END_SIZE = 0; // End of TX SRAM 51/* #define TX_SRAM_END_SIZE = 0; // End of TX SRAM */
52 52
53// Receive SRAM 53/* Receive SRAM */
54#define RX_SRAM_START 0x10000 54#define RX_SRAM_START 0x10000
55#define VID_A_DOWN_CMDS 0x10000 55#define VID_A_DOWN_CMDS 0x10000
56#define VID_B_DOWN_CMDS 0x10050 56#define VID_B_DOWN_CMDS 0x10050
@@ -78,9 +78,9 @@
78#define AUD_E_UP_CMDS 0x10730 78#define AUD_E_UP_CMDS 0x10730
79#define MBIF_A_DOWN_CMDS 0x10780 79#define MBIF_A_DOWN_CMDS 0x10780
80#define MBIF_B_DOWN_CMDS 0x107D0 80#define MBIF_B_DOWN_CMDS 0x107D0
81#define DMA_SCRATCH_PAD 0x10820 // Scratch pad area from 0x10820 to 0x10B40 81#define DMA_SCRATCH_PAD 0x10820 /* Scratch pad area from 0x10820 to 0x10B40 */
82 82
83//#define RX_SRAM_POOL_START = 0x105B0; 83/* #define RX_SRAM_POOL_START = 0x105B0; */
84 84
85#define VID_A_IQ 0x11000 85#define VID_A_IQ 0x11000
86#define VID_B_IQ 0x11040 86#define VID_B_IQ 0x11040
@@ -118,7 +118,7 @@
118#define MBIF_A_CDT 0x10C00 118#define MBIF_A_CDT 0x10C00
119#define MBIF_B_CDT 0x10CC0 119#define MBIF_B_CDT 0x10CC0
120 120
121// Cluster Buffer for RX 121/* Cluster Buffer for RX */
122#define VID_A_UP_CLUSTER_1 0x11400 122#define VID_A_UP_CLUSTER_1 0x11400
123#define VID_A_UP_CLUSTER_2 0x119A0 123#define VID_A_UP_CLUSTER_2 0x119A0
124#define VID_A_UP_CLUSTER_3 0x11F40 124#define VID_A_UP_CLUSTER_3 0x11F40
@@ -178,9 +178,9 @@
178#define RX_SRAM_POOL_FREE 0x1CE00 178#define RX_SRAM_POOL_FREE 0x1CE00
179#define RX_SRAM_END 0x1D000 179#define RX_SRAM_END 0x1D000
180 180
181// Free Receive SRAM 144 Bytes 181/* Free Receive SRAM 144 Bytes */
182 182
183// Transmit SRAM 183/* Transmit SRAM */
184#define TX_SRAM_POOL_START 0x00000 184#define TX_SRAM_POOL_START 0x00000
185 185
186#define VID_A_DOWN_CLUSTER_1 0x00040 186#define VID_A_DOWN_CLUSTER_1 0x00040
diff --git a/drivers/staging/cx25821/cx25821-video-upstream-ch2.c b/drivers/staging/cx25821/cx25821-video-upstream-ch2.c
index 343df6619fe8..d12dbb572e8b 100644
--- a/drivers/staging/cx25821/cx25821-video-upstream-ch2.c
+++ b/drivers/staging/cx25821/cx25821-video-upstream-ch2.c
@@ -84,7 +84,7 @@ static __le32 *cx25821_risc_field_upstream_ch2(struct cx25821_dev *dev,
84{ 84{
85 unsigned int line, i; 85 unsigned int line, i;
86 struct sram_channel *sram_ch = 86 struct sram_channel *sram_ch =
87 &dev->sram_channels[dev->_channel2_upstream_select]; 87 dev->channels[dev->_channel2_upstream_select].sram_channels;
88 int dist_betwn_starts = bpl * 2; 88 int dist_betwn_starts = bpl * 2;
89 89
90 /* sync instruction */ 90 /* sync instruction */
@@ -110,8 +110,11 @@ static __le32 *cx25821_risc_field_upstream_ch2(struct cx25821_dev *dev,
110 offset += dist_betwn_starts; 110 offset += dist_betwn_starts;
111 } 111 }
112 112
113 // check if we need to enable the FIFO after the first 4 lines 113 /*
114 // For the upstream video channel, the risc engine will enable the FIFO. 114 check if we need to enable the FIFO after the first 4 lines
115 For the upstream video channel, the risc engine will enable
116 the FIFO.
117 */
115 if (fifo_enable && line == 3) { 118 if (fifo_enable && line == 3) {
116 *(rp++) = RISC_WRITECR; 119 *(rp++) = RISC_WRITECR;
117 *(rp++) = sram_ch->dma_ctl; 120 *(rp++) = sram_ch->dma_ctl;
@@ -130,7 +133,7 @@ int cx25821_risc_buffer_upstream_ch2(struct cx25821_dev *dev,
130{ 133{
131 __le32 *rp; 134 __le32 *rp;
132 int fifo_enable = 0; 135 int fifo_enable = 0;
133 int singlefield_lines = lines >> 1; //get line count for single field 136 int singlefield_lines = lines >> 1; /*get line count for single field */
134 int odd_num_lines = singlefield_lines; 137 int odd_num_lines = singlefield_lines;
135 int frame = 0; 138 int frame = 0;
136 int frame_size = 0; 139 int frame_size = 0;
@@ -174,7 +177,7 @@ int cx25821_risc_buffer_upstream_ch2(struct cx25821_dev *dev,
174 177
175 fifo_enable = FIFO_DISABLE; 178 fifo_enable = FIFO_DISABLE;
176 179
177 //Even field 180 /* Even field */
178 rp = cx25821_risc_field_upstream_ch2(dev, rp, 181 rp = cx25821_risc_field_upstream_ch2(dev, rp,
179 dev-> 182 dev->
180 _data_buf_phys_addr_ch2 + 183 _data_buf_phys_addr_ch2 +
@@ -192,7 +195,10 @@ int cx25821_risc_buffer_upstream_ch2(struct cx25821_dev *dev,
192 risc_phys_jump_addr = dev->_dma_phys_start_addr_ch2; 195 risc_phys_jump_addr = dev->_dma_phys_start_addr_ch2;
193 } 196 }
194 197
195 // Loop to 2ndFrameRISC or to Start of Risc program & generate IRQ 198 /*
199 Loop to 2ndFrameRISC or to Start of
200 Risc program & generate IRQ
201 */
196 *(rp++) = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | risc_flag); 202 *(rp++) = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | risc_flag);
197 *(rp++) = cpu_to_le32(risc_phys_jump_addr); 203 *(rp++) = cpu_to_le32(risc_phys_jump_addr);
198 *(rp++) = cpu_to_le32(0); 204 *(rp++) = cpu_to_le32(0);
@@ -204,7 +210,7 @@ int cx25821_risc_buffer_upstream_ch2(struct cx25821_dev *dev,
204void cx25821_stop_upstream_video_ch2(struct cx25821_dev *dev) 210void cx25821_stop_upstream_video_ch2(struct cx25821_dev *dev)
205{ 211{
206 struct sram_channel *sram_ch = 212 struct sram_channel *sram_ch =
207 &dev->sram_channels[VID_UPSTREAM_SRAM_CHANNEL_J]; 213 dev->channels[VID_UPSTREAM_SRAM_CHANNEL_J].sram_channels;
208 u32 tmp = 0; 214 u32 tmp = 0;
209 215
210 if (!dev->_is_running_ch2) { 216 if (!dev->_is_running_ch2) {
@@ -212,15 +218,15 @@ void cx25821_stop_upstream_video_ch2(struct cx25821_dev *dev)
212 ("cx25821: No video file is currently running so return!\n"); 218 ("cx25821: No video file is currently running so return!\n");
213 return; 219 return;
214 } 220 }
215 //Disable RISC interrupts 221 /* Disable RISC interrupts */
216 tmp = cx_read(sram_ch->int_msk); 222 tmp = cx_read(sram_ch->int_msk);
217 cx_write(sram_ch->int_msk, tmp & ~_intr_msk); 223 cx_write(sram_ch->int_msk, tmp & ~_intr_msk);
218 224
219 //Turn OFF risc and fifo 225 /* Turn OFF risc and fifo */
220 tmp = cx_read(sram_ch->dma_ctl); 226 tmp = cx_read(sram_ch->dma_ctl);
221 cx_write(sram_ch->dma_ctl, tmp & ~(FLD_VID_FIFO_EN | FLD_VID_RISC_EN)); 227 cx_write(sram_ch->dma_ctl, tmp & ~(FLD_VID_FIFO_EN | FLD_VID_RISC_EN));
222 228
223 //Clear data buffer memory 229 /* Clear data buffer memory */
224 if (dev->_data_buf_virt_addr_ch2) 230 if (dev->_data_buf_virt_addr_ch2)
225 memset(dev->_data_buf_virt_addr_ch2, 0, 231 memset(dev->_data_buf_virt_addr_ch2, 0,
226 dev->_data_buf_size_ch2); 232 dev->_data_buf_size_ch2);
@@ -371,8 +377,8 @@ static void cx25821_vidups_handler_ch2(struct work_struct *work)
371 } 377 }
372 378
373 cx25821_get_frame_ch2(dev, 379 cx25821_get_frame_ch2(dev,
374 &dev->sram_channels[dev-> 380 dev->channels[dev->
375 _channel2_upstream_select]); 381 _channel2_upstream_select].sram_channels);
376} 382}
377 383
378int cx25821_openfile_ch2(struct cx25821_dev *dev, struct sram_channel *sram_ch) 384int cx25821_openfile_ch2(struct cx25821_dev *dev, struct sram_channel *sram_ch)
@@ -488,7 +494,7 @@ static int cx25821_upstream_buffer_prepare_ch2(struct cx25821_dev *dev,
488 return -ENOMEM; 494 return -ENOMEM;
489 } 495 }
490 496
491 //Iniitize at this address until n bytes to 0 497 /* Iniitize at this address until n bytes to 0 */
492 memset(dev->_dma_virt_addr_ch2, 0, dev->_risc_size_ch2); 498 memset(dev->_dma_virt_addr_ch2, 0, dev->_risc_size_ch2);
493 499
494 if (dev->_data_buf_virt_addr_ch2 != NULL) { 500 if (dev->_data_buf_virt_addr_ch2 != NULL) {
@@ -496,7 +502,7 @@ static int cx25821_upstream_buffer_prepare_ch2(struct cx25821_dev *dev,
496 dev->_data_buf_virt_addr_ch2, 502 dev->_data_buf_virt_addr_ch2,
497 dev->_data_buf_phys_addr_ch2); 503 dev->_data_buf_phys_addr_ch2);
498 } 504 }
499 //For Video Data buffer allocation 505 /* For Video Data buffer allocation */
500 dev->_data_buf_virt_addr_ch2 = 506 dev->_data_buf_virt_addr_ch2 =
501 pci_alloc_consistent(dev->pci, dev->upstream_databuf_size_ch2, 507 pci_alloc_consistent(dev->pci, dev->upstream_databuf_size_ch2,
502 &data_dma_addr); 508 &data_dma_addr);
@@ -509,14 +515,14 @@ static int cx25821_upstream_buffer_prepare_ch2(struct cx25821_dev *dev,
509 return -ENOMEM; 515 return -ENOMEM;
510 } 516 }
511 517
512 //Initialize at this address until n bytes to 0 518 /* Initialize at this address until n bytes to 0 */
513 memset(dev->_data_buf_virt_addr_ch2, 0, dev->_data_buf_size_ch2); 519 memset(dev->_data_buf_virt_addr_ch2, 0, dev->_data_buf_size_ch2);
514 520
515 ret = cx25821_openfile_ch2(dev, sram_ch); 521 ret = cx25821_openfile_ch2(dev, sram_ch);
516 if (ret < 0) 522 if (ret < 0)
517 return ret; 523 return ret;
518 524
519 //Creating RISC programs 525 /* Creating RISC programs */
520 ret = 526 ret =
521 cx25821_risc_buffer_upstream_ch2(dev, dev->pci, 0, bpl, 527 cx25821_risc_buffer_upstream_ch2(dev, dev->pci, 0, bpl,
522 dev->_lines_count_ch2); 528 dev->_lines_count_ch2);
@@ -536,7 +542,7 @@ int cx25821_video_upstream_irq_ch2(struct cx25821_dev *dev, int chan_num,
536 u32 status) 542 u32 status)
537{ 543{
538 u32 int_msk_tmp; 544 u32 int_msk_tmp;
539 struct sram_channel *channel = &dev->sram_channels[chan_num]; 545 struct sram_channel *channel = dev->channels[chan_num].sram_channels;
540 int singlefield_lines = NTSC_FIELD_HEIGHT; 546 int singlefield_lines = NTSC_FIELD_HEIGHT;
541 int line_size_in_bytes = Y422_LINE_SZ; 547 int line_size_in_bytes = Y422_LINE_SZ;
542 int odd_risc_prog_size = 0; 548 int odd_risc_prog_size = 0;
@@ -544,10 +550,13 @@ int cx25821_video_upstream_irq_ch2(struct cx25821_dev *dev, int chan_num,
544 __le32 *rp; 550 __le32 *rp;
545 551
546 if (status & FLD_VID_SRC_RISC1) { 552 if (status & FLD_VID_SRC_RISC1) {
547 // We should only process one program per call 553 /* We should only process one program per call */
548 u32 prog_cnt = cx_read(channel->gpcnt); 554 u32 prog_cnt = cx_read(channel->gpcnt);
549 555
550 //Since we've identified our IRQ, clear our bits from the interrupt mask and interrupt status registers 556 /*
557 Since we've identified our IRQ, clear our bits from the
558 interrupt mask and interrupt status registers
559 */
551 int_msk_tmp = cx_read(channel->int_msk); 560 int_msk_tmp = cx_read(channel->int_msk);
552 cx_write(channel->int_msk, int_msk_tmp & ~_intr_msk); 561 cx_write(channel->int_msk, int_msk_tmp & ~_intr_msk);
553 cx_write(channel->int_stat, _intr_msk); 562 cx_write(channel->int_stat, _intr_msk);
@@ -588,7 +597,7 @@ int cx25821_video_upstream_irq_ch2(struct cx25821_dev *dev, int chan_num,
588 FIFO_DISABLE, 597 FIFO_DISABLE,
589 ODD_FIELD); 598 ODD_FIELD);
590 599
591 // Jump to Even Risc program of 1st Frame 600 /* Jump to Even Risc program of 1st Frame */
592 *(rp++) = cpu_to_le32(RISC_JUMP); 601 *(rp++) = cpu_to_le32(RISC_JUMP);
593 *(rp++) = cpu_to_le32(risc_phys_jump_addr); 602 *(rp++) = cpu_to_le32(risc_phys_jump_addr);
594 *(rp++) = cpu_to_le32(0); 603 *(rp++) = cpu_to_le32(0);
@@ -603,7 +612,7 @@ int cx25821_video_upstream_irq_ch2(struct cx25821_dev *dev, int chan_num,
603 dev->_frame_count_ch2); 612 dev->_frame_count_ch2);
604 return -1; 613 return -1;
605 } 614 }
606 //ElSE, set the interrupt mask register, re-enable irq. 615 /* ElSE, set the interrupt mask register, re-enable irq. */
607 int_msk_tmp = cx_read(channel->int_msk); 616 int_msk_tmp = cx_read(channel->int_msk);
608 cx_write(channel->int_msk, int_msk_tmp |= _intr_msk); 617 cx_write(channel->int_msk, int_msk_tmp |= _intr_msk);
609 618
@@ -623,12 +632,12 @@ static irqreturn_t cx25821_upstream_irq_ch2(int irq, void *dev_id)
623 632
624 channel_num = VID_UPSTREAM_SRAM_CHANNEL_J; 633 channel_num = VID_UPSTREAM_SRAM_CHANNEL_J;
625 634
626 sram_ch = &dev->sram_channels[channel_num]; 635 sram_ch = dev->channels[channel_num].sram_channels;
627 636
628 msk_stat = cx_read(sram_ch->int_mstat); 637 msk_stat = cx_read(sram_ch->int_mstat);
629 vid_status = cx_read(sram_ch->int_stat); 638 vid_status = cx_read(sram_ch->int_stat);
630 639
631 // Only deal with our interrupt 640 /* Only deal with our interrupt */
632 if (vid_status) { 641 if (vid_status) {
633 handled = 642 handled =
634 cx25821_video_upstream_irq_ch2(dev, channel_num, 643 cx25821_video_upstream_irq_ch2(dev, channel_num,
@@ -658,7 +667,10 @@ static void cx25821_set_pixelengine_ch2(struct cx25821_dev *dev,
658 value |= dev->_isNTSC_ch2 ? 0 : 0x10; 667 value |= dev->_isNTSC_ch2 ? 0 : 0x10;
659 cx_write(ch->vid_fmt_ctl, value); 668 cx_write(ch->vid_fmt_ctl, value);
660 669
661 // set number of active pixels in each line. Default is 720 pixels in both NTSC and PAL format 670 /*
671 set number of active pixels in each line. Default is 720
672 pixels in both NTSC and PAL format
673 */
662 cx_write(ch->vid_active_ctl1, width); 674 cx_write(ch->vid_active_ctl1, width);
663 675
664 num_lines = (height / 2) & 0x3FF; 676 num_lines = (height / 2) & 0x3FF;
@@ -670,7 +682,7 @@ static void cx25821_set_pixelengine_ch2(struct cx25821_dev *dev,
670 682
671 value = (num_lines << 16) | odd_num_lines; 683 value = (num_lines << 16) | odd_num_lines;
672 684
673 // set number of active lines in field 0 (top) and field 1 (bottom) 685 /* set number of active lines in field 0 (top) and field 1 (bottom) */
674 cx_write(ch->vid_active_ctl2, value); 686 cx_write(ch->vid_active_ctl2, value);
675 687
676 cx_write(ch->vid_cdt_size, VID_CDT_SIZE >> 3); 688 cx_write(ch->vid_cdt_size, VID_CDT_SIZE >> 3);
@@ -682,21 +694,27 @@ int cx25821_start_video_dma_upstream_ch2(struct cx25821_dev *dev,
682 u32 tmp = 0; 694 u32 tmp = 0;
683 int err = 0; 695 int err = 0;
684 696
685 // 656/VIP SRC Upstream Channel I & J and 7 - Host Bus Interface for channel A-C 697 /*
698 656/VIP SRC Upstream Channel I & J and 7 - Host Bus Interface
699 for channel A-C
700 */
686 tmp = cx_read(VID_CH_MODE_SEL); 701 tmp = cx_read(VID_CH_MODE_SEL);
687 cx_write(VID_CH_MODE_SEL, tmp | 0x1B0001FF); 702 cx_write(VID_CH_MODE_SEL, tmp | 0x1B0001FF);
688 703
689 // Set the physical start address of the RISC program in the initial program counter(IPC) member of the cmds. 704 /*
705 Set the physical start address of the RISC program in the initial
706 program counter(IPC) member of the cmds.
707 */
690 cx_write(sram_ch->cmds_start + 0, dev->_dma_phys_addr_ch2); 708 cx_write(sram_ch->cmds_start + 0, dev->_dma_phys_addr_ch2);
691 cx_write(sram_ch->cmds_start + 4, 0); /* Risc IPC High 64 bits 63-32 */ 709 cx_write(sram_ch->cmds_start + 4, 0); /* Risc IPC High 64 bits 63-32 */
692 710
693 /* reset counter */ 711 /* reset counter */
694 cx_write(sram_ch->gpcnt_ctl, 3); 712 cx_write(sram_ch->gpcnt_ctl, 3);
695 713
696 // Clear our bits from the interrupt status register. 714 /* Clear our bits from the interrupt status register. */
697 cx_write(sram_ch->int_stat, _intr_msk); 715 cx_write(sram_ch->int_stat, _intr_msk);
698 716
699 //Set the interrupt mask register, enable irq. 717 /* Set the interrupt mask register, enable irq. */
700 cx_set(PCI_INT_MSK, cx_read(PCI_INT_MSK) | (1 << sram_ch->irq_bit)); 718 cx_set(PCI_INT_MSK, cx_read(PCI_INT_MSK) | (1 << sram_ch->irq_bit));
701 tmp = cx_read(sram_ch->int_msk); 719 tmp = cx_read(sram_ch->int_msk);
702 cx_write(sram_ch->int_msk, tmp |= _intr_msk); 720 cx_write(sram_ch->int_msk, tmp |= _intr_msk);
@@ -709,7 +727,7 @@ int cx25821_start_video_dma_upstream_ch2(struct cx25821_dev *dev,
709 dev->pci->irq); 727 dev->pci->irq);
710 goto fail_irq; 728 goto fail_irq;
711 } 729 }
712 // Start the DMA engine 730 /* Start the DMA engine */
713 tmp = cx_read(sram_ch->dma_ctl); 731 tmp = cx_read(sram_ch->dma_ctl);
714 cx_set(sram_ch->dma_ctl, tmp | FLD_VID_RISC_EN); 732 cx_set(sram_ch->dma_ctl, tmp | FLD_VID_RISC_EN);
715 733
@@ -740,7 +758,7 @@ int cx25821_vidupstream_init_ch2(struct cx25821_dev *dev, int channel_select,
740 } 758 }
741 759
742 dev->_channel2_upstream_select = channel_select; 760 dev->_channel2_upstream_select = channel_select;
743 sram_ch = &dev->sram_channels[channel_select]; 761 sram_ch = dev->channels[channel_select].sram_channels;
744 762
745 INIT_WORK(&dev->_irq_work_entry_ch2, cx25821_vidups_handler_ch2); 763 INIT_WORK(&dev->_irq_work_entry_ch2, cx25821_vidups_handler_ch2);
746 dev->_irq_queues_ch2 = 764 dev->_irq_queues_ch2 =
@@ -751,7 +769,10 @@ int cx25821_vidupstream_init_ch2(struct cx25821_dev *dev, int channel_select,
751 ("cx25821: create_singlethread_workqueue() for Video FAILED!\n"); 769 ("cx25821: create_singlethread_workqueue() for Video FAILED!\n");
752 return -ENOMEM; 770 return -ENOMEM;
753 } 771 }
754 // 656/VIP SRC Upstream Channel I & J and 7 - Host Bus Interface for channel A-C 772 /*
773 656/VIP SRC Upstream Channel I & J and 7 -
774 Host Bus Interface for channel A-C
775 */
755 tmp = cx_read(VID_CH_MODE_SEL); 776 tmp = cx_read(VID_CH_MODE_SEL);
756 cx_write(VID_CH_MODE_SEL, tmp | 0x1B0001FF); 777 cx_write(VID_CH_MODE_SEL, tmp | 0x1B0001FF);
757 778
@@ -787,7 +808,7 @@ int cx25821_vidupstream_init_ch2(struct cx25821_dev *dev, int channel_select,
787 str_length + 1); 808 str_length + 1);
788 } 809 }
789 810
790 //Default if filename is empty string 811 /* Default if filename is empty string */
791 if (strcmp(dev->input_filename_ch2, "") == 0) { 812 if (strcmp(dev->input_filename_ch2, "") == 0) {
792 if (dev->_isNTSC_ch2) { 813 if (dev->_isNTSC_ch2) {
793 dev->_filename_ch2 = 814 dev->_filename_ch2 =
@@ -812,7 +833,7 @@ int cx25821_vidupstream_init_ch2(struct cx25821_dev *dev, int channel_select,
812 dev->upstream_riscbuf_size_ch2 = risc_buffer_size * 2; 833 dev->upstream_riscbuf_size_ch2 = risc_buffer_size * 2;
813 dev->upstream_databuf_size_ch2 = data_frame_size * 2; 834 dev->upstream_databuf_size_ch2 = data_frame_size * 2;
814 835
815 //Allocating buffers and prepare RISC program 836 /* Allocating buffers and prepare RISC program */
816 retval = 837 retval =
817 cx25821_upstream_buffer_prepare_ch2(dev, sram_ch, 838 cx25821_upstream_buffer_prepare_ch2(dev, sram_ch,
818 dev->_line_size_ch2); 839 dev->_line_size_ch2);
diff --git a/drivers/staging/cx25821/cx25821-video-upstream-ch2.h b/drivers/staging/cx25821/cx25821-video-upstream-ch2.h
index 73feea114c1c..62340636c916 100644
--- a/drivers/staging/cx25821/cx25821-video-upstream-ch2.h
+++ b/drivers/staging/cx25821/cx25821-video-upstream-ch2.h
@@ -37,7 +37,7 @@
37#define RESET_STATUS -1 37#define RESET_STATUS -1
38#define NUM_NO_OPS 5 38#define NUM_NO_OPS 5
39 39
40// PAL and NTSC line sizes and number of lines. 40/* PAL and NTSC line sizes and number of lines. */
41#define WIDTH_D1 720 41#define WIDTH_D1 720
42#define NTSC_LINES_PER_FRAME 480 42#define NTSC_LINES_PER_FRAME 480
43#define PAL_LINES_PER_FRAME 576 43#define PAL_LINES_PER_FRAME 576
diff --git a/drivers/staging/cx25821/cx25821-video-upstream.c b/drivers/staging/cx25821/cx25821-video-upstream.c
index 7a3dad91eba8..756a820a76cb 100644
--- a/drivers/staging/cx25821/cx25821-video-upstream.c
+++ b/drivers/staging/cx25821/cx25821-video-upstream.c
@@ -134,7 +134,7 @@ static __le32 *cx25821_risc_field_upstream(struct cx25821_dev *dev, __le32 * rp,
134{ 134{
135 unsigned int line, i; 135 unsigned int line, i;
136 struct sram_channel *sram_ch = 136 struct sram_channel *sram_ch =
137 &dev->sram_channels[dev->_channel_upstream_select]; 137 dev->channels[dev->_channel_upstream_select].sram_channels;
138 int dist_betwn_starts = bpl * 2; 138 int dist_betwn_starts = bpl * 2;
139 139
140 /* sync instruction */ 140 /* sync instruction */
@@ -253,7 +253,7 @@ int cx25821_risc_buffer_upstream(struct cx25821_dev *dev,
253void cx25821_stop_upstream_video_ch1(struct cx25821_dev *dev) 253void cx25821_stop_upstream_video_ch1(struct cx25821_dev *dev)
254{ 254{
255 struct sram_channel *sram_ch = 255 struct sram_channel *sram_ch =
256 &dev->sram_channels[VID_UPSTREAM_SRAM_CHANNEL_I]; 256 dev->channels[VID_UPSTREAM_SRAM_CHANNEL_I].sram_channels;
257 u32 tmp = 0; 257 u32 tmp = 0;
258 258
259 if (!dev->_is_running) { 259 if (!dev->_is_running) {
@@ -346,20 +346,23 @@ int cx25821_get_frame(struct cx25821_dev *dev, struct sram_channel *sram_ch)
346 346
347 if (IS_ERR(myfile)) { 347 if (IS_ERR(myfile)) {
348 const int open_errno = -PTR_ERR(myfile); 348 const int open_errno = -PTR_ERR(myfile);
349 printk(KERN_ERR "%s(): ERROR opening file(%s) with errno = %d!\n", 349 printk(KERN_ERR
350 __func__, dev->_filename, open_errno); 350 "%s(): ERROR opening file(%s) with errno = %d!\n",
351 __func__, dev->_filename, open_errno);
351 return PTR_ERR(myfile); 352 return PTR_ERR(myfile);
352 } else { 353 } else {
353 if (!(myfile->f_op)) { 354 if (!(myfile->f_op)) {
354 printk(KERN_ERR "%s: File has no file operations registered!", 355 printk(KERN_ERR
355 __func__); 356 "%s: File has no file operations registered!",
357 __func__);
356 filp_close(myfile, NULL); 358 filp_close(myfile, NULL);
357 return -EIO; 359 return -EIO;
358 } 360 }
359 361
360 if (!myfile->f_op->read) { 362 if (!myfile->f_op->read) {
361 printk(KERN_ERR "%s: File has no READ operations registered!", 363 printk(KERN_ERR
362 __func__); 364 "%s: File has no READ operations registered!",
365 __func__);
363 filp_close(myfile, NULL); 366 filp_close(myfile, NULL);
364 return -EIO; 367 return -EIO;
365 } 368 }
@@ -386,7 +389,8 @@ int cx25821_get_frame(struct cx25821_dev *dev, struct sram_channel *sram_ch)
386 389
387 if (vfs_read_retval < line_size) { 390 if (vfs_read_retval < line_size) {
388 printk(KERN_INFO 391 printk(KERN_INFO
389 "Done: exit %s() since no more bytes to read from Video file.\n", 392 "Done: exit %s() since no more bytes to \
393 read from Video file.\n",
390 __func__); 394 __func__);
391 break; 395 break;
392 } 396 }
@@ -411,13 +415,15 @@ static void cx25821_vidups_handler(struct work_struct *work)
411 container_of(work, struct cx25821_dev, _irq_work_entry); 415 container_of(work, struct cx25821_dev, _irq_work_entry);
412 416
413 if (!dev) { 417 if (!dev) {
414 printk(KERN_ERR "ERROR %s(): since container_of(work_struct) FAILED!\n", 418 printk(KERN_ERR
415 __func__); 419 "ERROR %s(): since container_of(work_struct) FAILED!\n",
420 __func__);
416 return; 421 return;
417 } 422 }
418 423
419 cx25821_get_frame(dev, 424 cx25821_get_frame(dev,
420 &dev->sram_channels[dev->_channel_upstream_select]); 425 dev->channels[dev->_channel_upstream_select].
426 sram_channels);
421} 427}
422 428
423int cx25821_openfile(struct cx25821_dev *dev, struct sram_channel *sram_ch) 429int cx25821_openfile(struct cx25821_dev *dev, struct sram_channel *sram_ch)
@@ -437,20 +443,22 @@ int cx25821_openfile(struct cx25821_dev *dev, struct sram_channel *sram_ch)
437 443
438 if (IS_ERR(myfile)) { 444 if (IS_ERR(myfile)) {
439 const int open_errno = -PTR_ERR(myfile); 445 const int open_errno = -PTR_ERR(myfile);
440 printk(KERN_ERR "%s(): ERROR opening file(%s) with errno = %d!\n", 446 printk(KERN_ERR "%s(): ERROR opening file(%s) with errno = %d!\n",
441 __func__, dev->_filename, open_errno); 447 __func__, dev->_filename, open_errno);
442 return PTR_ERR(myfile); 448 return PTR_ERR(myfile);
443 } else { 449 } else {
444 if (!(myfile->f_op)) { 450 if (!(myfile->f_op)) {
445 printk(KERN_ERR "%s: File has no file operations registered!", 451 printk(KERN_ERR
446 __func__); 452 "%s: File has no file operations registered!",
453 __func__);
447 filp_close(myfile, NULL); 454 filp_close(myfile, NULL);
448 return -EIO; 455 return -EIO;
449 } 456 }
450 457
451 if (!myfile->f_op->read) { 458 if (!myfile->f_op->read) {
452 printk 459 printk(KERN_ERR
453 (KERN_ERR "%s: File has no READ operations registered! Returning.", 460 "%s: File has no READ operations registered! \
461 Returning.",
454 __func__); 462 __func__);
455 filp_close(myfile, NULL); 463 filp_close(myfile, NULL);
456 return -EIO; 464 return -EIO;
@@ -480,7 +488,8 @@ int cx25821_openfile(struct cx25821_dev *dev, struct sram_channel *sram_ch)
480 488
481 if (vfs_read_retval < line_size) { 489 if (vfs_read_retval < line_size) {
482 printk(KERN_INFO 490 printk(KERN_INFO
483 "Done: exit %s() since no more bytes to read from Video file.\n", 491 "Done: exit %s() since no more \
492 bytes to read from Video file.\n",
484 __func__); 493 __func__);
485 break; 494 break;
486 } 495 }
@@ -526,7 +535,8 @@ int cx25821_upstream_buffer_prepare(struct cx25821_dev *dev,
526 535
527 if (!dev->_dma_virt_addr) { 536 if (!dev->_dma_virt_addr) {
528 printk 537 printk
529 (KERN_ERR "cx25821: FAILED to allocate memory for Risc buffer! Returning.\n"); 538 (KERN_ERR "cx25821: FAILED to allocate memory for Risc \
539 buffer! Returning.\n");
530 return -ENOMEM; 540 return -ENOMEM;
531 } 541 }
532 542
@@ -547,7 +557,8 @@ int cx25821_upstream_buffer_prepare(struct cx25821_dev *dev,
547 557
548 if (!dev->_data_buf_virt_addr) { 558 if (!dev->_data_buf_virt_addr) {
549 printk 559 printk
550 (KERN_ERR "cx25821: FAILED to allocate memory for data buffer! Returning.\n"); 560 (KERN_ERR "cx25821: FAILED to allocate memory for data \
561 buffer! Returning.\n");
551 return -ENOMEM; 562 return -ENOMEM;
552 } 563 }
553 564
@@ -578,7 +589,7 @@ int cx25821_video_upstream_irq(struct cx25821_dev *dev, int chan_num,
578 u32 status) 589 u32 status)
579{ 590{
580 u32 int_msk_tmp; 591 u32 int_msk_tmp;
581 struct sram_channel *channel = &dev->sram_channels[chan_num]; 592 struct sram_channel *channel = dev->channels[chan_num].sram_channels;
582 int singlefield_lines = NTSC_FIELD_HEIGHT; 593 int singlefield_lines = NTSC_FIELD_HEIGHT;
583 int line_size_in_bytes = Y422_LINE_SZ; 594 int line_size_in_bytes = Y422_LINE_SZ;
584 int odd_risc_prog_size = 0; 595 int odd_risc_prog_size = 0;
@@ -642,16 +653,16 @@ int cx25821_video_upstream_irq(struct cx25821_dev *dev, int chan_num,
642 } else { 653 } else {
643 if (status & FLD_VID_SRC_UF) 654 if (status & FLD_VID_SRC_UF)
644 printk 655 printk
645 (KERN_ERR "%s: Video Received Underflow Error Interrupt!\n", 656 (KERN_ERR "%s: Video Received Underflow Error \
646 __func__); 657 Interrupt!\n", __func__);
647 658
648 if (status & FLD_VID_SRC_SYNC) 659 if (status & FLD_VID_SRC_SYNC)
649 printk(KERN_ERR "%s: Video Received Sync Error Interrupt!\n", 660 printk(KERN_ERR "%s: Video Received Sync Error \
650 __func__); 661 Interrupt!\n", __func__);
651 662
652 if (status & FLD_VID_SRC_OPC_ERR) 663 if (status & FLD_VID_SRC_OPC_ERR)
653 printk(KERN_ERR "%s: Video Received OpCode Error Interrupt!\n", 664 printk(KERN_ERR "%s: Video Received OpCode Error \
654 __func__); 665 Interrupt!\n", __func__);
655 } 666 }
656 667
657 if (dev->_file_status == END_OF_FILE) { 668 if (dev->_file_status == END_OF_FILE) {
@@ -679,7 +690,7 @@ static irqreturn_t cx25821_upstream_irq(int irq, void *dev_id)
679 690
680 channel_num = VID_UPSTREAM_SRAM_CHANNEL_I; 691 channel_num = VID_UPSTREAM_SRAM_CHANNEL_I;
681 692
682 sram_ch = &dev->sram_channels[channel_num]; 693 sram_ch = dev->channels[channel_num].sram_channels;
683 694
684 msk_stat = cx_read(sram_ch->int_mstat); 695 msk_stat = cx_read(sram_ch->int_mstat);
685 vid_status = cx_read(sram_ch->int_stat); 696 vid_status = cx_read(sram_ch->int_stat);
@@ -800,14 +811,15 @@ int cx25821_vidupstream_init_ch1(struct cx25821_dev *dev, int channel_select,
800 } 811 }
801 812
802 dev->_channel_upstream_select = channel_select; 813 dev->_channel_upstream_select = channel_select;
803 sram_ch = &dev->sram_channels[channel_select]; 814 sram_ch = dev->channels[channel_select].sram_channels;
804 815
805 INIT_WORK(&dev->_irq_work_entry, cx25821_vidups_handler); 816 INIT_WORK(&dev->_irq_work_entry, cx25821_vidups_handler);
806 dev->_irq_queues = create_singlethread_workqueue("cx25821_workqueue"); 817 dev->_irq_queues = create_singlethread_workqueue("cx25821_workqueue");
807 818
808 if (!dev->_irq_queues) { 819 if (!dev->_irq_queues) {
809 printk 820 printk
810 (KERN_ERR "cx25821: create_singlethread_workqueue() for Video FAILED!\n"); 821 (KERN_ERR "cx25821: create_singlethread_workqueue() for \
822 Video FAILED!\n");
811 return -ENOMEM; 823 return -ENOMEM;
812 } 824 }
813 /* 656/VIP SRC Upstream Channel I & J and 7 - Host Bus Interface for 825 /* 656/VIP SRC Upstream Channel I & J and 7 - Host Bus Interface for
diff --git a/drivers/staging/cx25821/cx25821-video-upstream.h b/drivers/staging/cx25821/cx25821-video-upstream.h
index cc9f93842514..10dee5c24a81 100644
--- a/drivers/staging/cx25821/cx25821-video-upstream.h
+++ b/drivers/staging/cx25821/cx25821-video-upstream.h
@@ -38,7 +38,7 @@
38#define RESET_STATUS -1 38#define RESET_STATUS -1
39#define NUM_NO_OPS 5 39#define NUM_NO_OPS 5
40 40
41// PAL and NTSC line sizes and number of lines. 41/* PAL and NTSC line sizes and number of lines. */
42#define WIDTH_D1 720 42#define WIDTH_D1 720
43#define NTSC_LINES_PER_FRAME 480 43#define NTSC_LINES_PER_FRAME 480
44#define PAL_LINES_PER_FRAME 576 44#define PAL_LINES_PER_FRAME 576
diff --git a/drivers/staging/cx25821/cx25821-video.c b/drivers/staging/cx25821/cx25821-video.c
index 791212c1a661..1d5e8796d383 100644
--- a/drivers/staging/cx25821/cx25821-video.c
+++ b/drivers/staging/cx25821/cx25821-video.c
@@ -4,6 +4,9 @@
4 * Copyright (C) 2009 Conexant Systems Inc. 4 * Copyright (C) 2009 Conexant Systems Inc.
5 * Authors <shu.lin@conexant.com>, <hiep.huynh@conexant.com> 5 * Authors <shu.lin@conexant.com>, <hiep.huynh@conexant.com>
6 * Based on Steven Toth <stoth@linuxtv.org> cx23885 driver 6 * Based on Steven Toth <stoth@linuxtv.org> cx23885 driver
7 * Parts adapted/taken from Eduardo Moscoso Rubino
8 * Copyright (C) 2009 Eduardo Moscoso Rubino <moscoso@TopoLogica.com>
9 *
7 * 10 *
8 * This program is free software; you can redistribute it and/or modify 11 * 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 12 * it under the terms of the GNU General Public License as published by
@@ -24,7 +27,7 @@
24#include "cx25821-video.h" 27#include "cx25821-video.h"
25 28
26MODULE_DESCRIPTION("v4l2 driver module for cx25821 based TV cards"); 29MODULE_DESCRIPTION("v4l2 driver module for cx25821 based TV cards");
27MODULE_AUTHOR("Steven Toth <stoth@linuxtv.org>"); 30MODULE_AUTHOR("Hiep Huynh <hiep.huynh@conexant.com>");
28MODULE_LICENSE("GPL"); 31MODULE_LICENSE("GPL");
29 32
30static unsigned int video_nr[] = {[0 ... (CX25821_MAXBOARDS - 1)] = UNSET }; 33static unsigned int video_nr[] = {[0 ... (CX25821_MAXBOARDS - 1)] = UNSET };
@@ -48,7 +51,10 @@ unsigned int vid_limit = 16;
48module_param(vid_limit, int, 0644); 51module_param(vid_limit, int, 0644);
49MODULE_PARM_DESC(vid_limit, "capture memory limit in megabytes"); 52MODULE_PARM_DESC(vid_limit, "capture memory limit in megabytes");
50 53
51static void init_controls(struct cx25821_dev *dev, int chan_num); 54static void cx25821_init_controls(struct cx25821_dev *dev, int chan_num);
55
56static const struct v4l2_file_operations video_fops;
57static const struct v4l2_ioctl_ops video_ioctl_ops;
52 58
53#define FORMAT_FLAGS_PACKED 0x01 59#define FORMAT_FLAGS_PACKED 0x01
54 60
@@ -211,7 +217,7 @@ static int cx25821_ctrl_query(struct v4l2_queryctrl *qctrl)
211} 217}
212*/ 218*/
213 219
214// resource management 220/* resource management */
215int cx25821_res_get(struct cx25821_dev *dev, struct cx25821_fh *fh, unsigned int bit) 221int cx25821_res_get(struct cx25821_dev *dev, struct cx25821_fh *fh, unsigned int bit)
216{ 222{
217 dprintk(1, "%s()\n", __func__); 223 dprintk(1, "%s()\n", __func__);
@@ -221,14 +227,14 @@ int cx25821_res_get(struct cx25821_dev *dev, struct cx25821_fh *fh, unsigned int
221 227
222 /* is it free? */ 228 /* is it free? */
223 mutex_lock(&dev->lock); 229 mutex_lock(&dev->lock);
224 if (dev->resources & bit) { 230 if (dev->channels[fh->channel_id].resources & bit) {
225 /* no, someone else uses it */ 231 /* no, someone else uses it */
226 mutex_unlock(&dev->lock); 232 mutex_unlock(&dev->lock);
227 return 0; 233 return 0;
228 } 234 }
229 /* it's free, grab it */ 235 /* it's free, grab it */
230 fh->resources |= bit; 236 fh->resources |= bit;
231 dev->resources |= bit; 237 dev->channels[fh->channel_id].resources |= bit;
232 dprintk(1, "res: get %d\n", bit); 238 dprintk(1, "res: get %d\n", bit);
233 mutex_unlock(&dev->lock); 239 mutex_unlock(&dev->lock);
234 return 1; 240 return 1;
@@ -239,9 +245,9 @@ int cx25821_res_check(struct cx25821_fh *fh, unsigned int bit)
239 return fh->resources & bit; 245 return fh->resources & bit;
240} 246}
241 247
242int cx25821_res_locked(struct cx25821_dev *dev, unsigned int bit) 248int cx25821_res_locked(struct cx25821_fh *fh, unsigned int bit)
243{ 249{
244 return dev->resources & bit; 250 return fh->dev->channels[fh->channel_id].resources & bit;
245} 251}
246 252
247void cx25821_res_free(struct cx25821_dev *dev, struct cx25821_fh *fh, unsigned int bits) 253void cx25821_res_free(struct cx25821_dev *dev, struct cx25821_fh *fh, unsigned int bits)
@@ -251,7 +257,7 @@ void cx25821_res_free(struct cx25821_dev *dev, struct cx25821_fh *fh, unsigned i
251 257
252 mutex_lock(&dev->lock); 258 mutex_lock(&dev->lock);
253 fh->resources &= ~bits; 259 fh->resources &= ~bits;
254 dev->resources &= ~bits; 260 dev->channels[fh->channel_id].resources &= ~bits;
255 dprintk(1, "res: put %d\n", bits); 261 dprintk(1, "res: put %d\n", bits);
256 mutex_unlock(&dev->lock); 262 mutex_unlock(&dev->lock);
257} 263}
@@ -358,11 +364,11 @@ void cx25821_vid_timeout(unsigned long data)
358 struct cx25821_data *timeout_data = (struct cx25821_data *)data; 364 struct cx25821_data *timeout_data = (struct cx25821_data *)data;
359 struct cx25821_dev *dev = timeout_data->dev; 365 struct cx25821_dev *dev = timeout_data->dev;
360 struct sram_channel *channel = timeout_data->channel; 366 struct sram_channel *channel = timeout_data->channel;
361 struct cx25821_dmaqueue *q = &dev->vidq[channel->i]; 367 struct cx25821_dmaqueue *q = &dev->channels[channel->i].vidq;
362 struct cx25821_buffer *buf; 368 struct cx25821_buffer *buf;
363 unsigned long flags; 369 unsigned long flags;
364 370
365 //cx25821_sram_channel_dump(dev, channel); 371 /* cx25821_sram_channel_dump(dev, channel); */
366 cx_clear(channel->dma_ctl, 0x11); 372 cx_clear(channel->dma_ctl, 0x11);
367 373
368 spin_lock_irqsave(&dev->slock, flags); 374 spin_lock_irqsave(&dev->slock, flags);
@@ -384,7 +390,7 @@ int cx25821_video_irq(struct cx25821_dev *dev, int chan_num, u32 status)
384 u32 count = 0; 390 u32 count = 0;
385 int handled = 0; 391 int handled = 0;
386 u32 mask; 392 u32 mask;
387 struct sram_channel *channel = &dev->sram_channels[chan_num]; 393 struct sram_channel *channel = dev->channels[chan_num].sram_channels;
388 394
389 mask = cx_read(channel->int_msk); 395 mask = cx_read(channel->int_msk);
390 if (0 == (status & mask)) 396 if (0 == (status & mask))
@@ -404,7 +410,8 @@ int cx25821_video_irq(struct cx25821_dev *dev, int chan_num, u32 status)
404 if (status & FLD_VID_DST_RISC1) { 410 if (status & FLD_VID_DST_RISC1) {
405 spin_lock(&dev->slock); 411 spin_lock(&dev->slock);
406 count = cx_read(channel->gpcnt); 412 count = cx_read(channel->gpcnt);
407 cx25821_video_wakeup(dev, &dev->vidq[channel->i], count); 413 cx25821_video_wakeup(dev,
414 &dev->channels[channel->i].vidq, count);
408 spin_unlock(&dev->slock); 415 spin_unlock(&dev->slock);
409 handled++; 416 handled++;
410 } 417 }
@@ -413,8 +420,9 @@ int cx25821_video_irq(struct cx25821_dev *dev, int chan_num, u32 status)
413 if (status & 0x10) { 420 if (status & 0x10) {
414 dprintk(2, "stopper video\n"); 421 dprintk(2, "stopper video\n");
415 spin_lock(&dev->slock); 422 spin_lock(&dev->slock);
416 cx25821_restart_video_queue(dev, &dev->vidq[channel->i], 423 cx25821_restart_video_queue(dev,
417 channel); 424 &dev->channels[channel->i].vidq,
425 channel);
418 spin_unlock(&dev->slock); 426 spin_unlock(&dev->slock);
419 handled++; 427 handled++;
420 } 428 }
@@ -437,72 +445,95 @@ void cx25821_video_unregister(struct cx25821_dev *dev, int chan_num)
437{ 445{
438 cx_clear(PCI_INT_MSK, 1); 446 cx_clear(PCI_INT_MSK, 1);
439 447
440 if (dev->video_dev[chan_num]) { 448 if (dev->channels[chan_num].video_dev) {
441 if (video_is_registered(dev->video_dev[chan_num])) 449 if (video_is_registered(dev->channels[chan_num].video_dev))
442 video_unregister_device(dev->video_dev[chan_num]); 450 video_unregister_device(
451 dev->channels[chan_num].video_dev);
443 else 452 else
444 video_device_release(dev->video_dev[chan_num]); 453 video_device_release(
454 dev->channels[chan_num].video_dev);
445 455
446 dev->video_dev[chan_num] = NULL; 456 dev->channels[chan_num].video_dev = NULL;
447 457
448 btcx_riscmem_free(dev->pci, &dev->vidq[chan_num].stopper); 458 btcx_riscmem_free(dev->pci,
459 &dev->channels[chan_num].vidq.stopper);
449 460
450 printk(KERN_WARNING "device %d released!\n", chan_num); 461 printk(KERN_WARNING "device %d released!\n", chan_num);
451 } 462 }
452 463
453} 464}
454 465
455int cx25821_video_register(struct cx25821_dev *dev, int chan_num, 466int cx25821_video_register(struct cx25821_dev *dev)
456 struct video_device *video_template)
457{ 467{
458 int err; 468 int err;
469 int i;
470
471 struct video_device cx25821_video_device = {
472 .name = "cx25821-video",
473 .fops = &video_fops,
474 .minor = -1,
475 .ioctl_ops = &video_ioctl_ops,
476 .tvnorms = CX25821_NORMS,
477 .current_norm = V4L2_STD_NTSC_M,
478 };
459 479
460 spin_lock_init(&dev->slock); 480 spin_lock_init(&dev->slock);
461 481
462 //printk(KERN_WARNING "Channel %d\n", chan_num); 482 for (i = 0; i < MAX_VID_CHANNEL_NUM - 1; ++i) {
483 cx25821_init_controls(dev, i);
463 484
464#ifdef TUNER_FLAG 485 cx25821_risc_stopper(dev->pci,
465 dev->tvnorm = video_template->current_norm; 486 &dev->channels[i].vidq.stopper,
466#endif 487 dev->channels[i].sram_channels->dma_ctl,
488 0x11, 0);
489
490 dev->channels[i].sram_channels = &cx25821_sram_channels[i];
491 dev->channels[i].video_dev = NULL;
492 dev->channels[i].resources = 0;
493
494 cx_write(dev->channels[i].sram_channels->int_stat,
495 0xffffffff);
496
497 INIT_LIST_HEAD(&dev->channels[i].vidq.active);
498 INIT_LIST_HEAD(&dev->channels[i].vidq.queued);
499
500 dev->channels[i].timeout_data.dev = dev;
501 dev->channels[i].timeout_data.channel =
502 &cx25821_sram_channels[i];
503 dev->channels[i].vidq.timeout.function =
504 cx25821_vid_timeout;
505 dev->channels[i].vidq.timeout.data =
506 (unsigned long)&dev->channels[i].timeout_data;
507 init_timer(&dev->channels[i].vidq.timeout);
508
509 /* register v4l devices */
510 dev->channels[i].video_dev = cx25821_vdev_init(dev,
511 dev->pci, &cx25821_video_device, "video");
512
513 err = video_register_device(dev->channels[i].video_dev,
514 VFL_TYPE_GRABBER, video_nr[dev->nr]);
515
516 if (err < 0)
517 goto fail_unreg;
467 518
468 /* init video dma queues */
469 dev->timeout_data[chan_num].dev = dev;
470 dev->timeout_data[chan_num].channel = &dev->sram_channels[chan_num];
471 INIT_LIST_HEAD(&dev->vidq[chan_num].active);
472 INIT_LIST_HEAD(&dev->vidq[chan_num].queued);
473 dev->vidq[chan_num].timeout.function = cx25821_vid_timeout;
474 dev->vidq[chan_num].timeout.data =
475 (unsigned long)&dev->timeout_data[chan_num];
476 init_timer(&dev->vidq[chan_num].timeout);
477 cx25821_risc_stopper(dev->pci, &dev->vidq[chan_num].stopper,
478 dev->sram_channels[chan_num].dma_ctl, 0x11, 0);
479
480 /* register v4l devices */
481 dev->video_dev[chan_num] =
482 cx25821_vdev_init(dev, dev->pci, video_template, "video");
483 err =
484 video_register_device(dev->video_dev[chan_num], VFL_TYPE_GRABBER,
485 video_nr[dev->nr]);
486
487 if (err < 0) {
488 goto fail_unreg;
489 } 519 }
490 //set PCI interrupt 520
521 /* set PCI interrupt */
491 cx_set(PCI_INT_MSK, 0xff); 522 cx_set(PCI_INT_MSK, 0xff);
492 523
493 /* initial device configuration */ 524 /* initial device configuration */
494 mutex_lock(&dev->lock); 525 mutex_lock(&dev->lock);
495#ifdef TUNER_FLAG 526#ifdef TUNER_FLAG
527 dev->tvnorm = cx25821_video_device.current_norm;
496 cx25821_set_tvnorm(dev, dev->tvnorm); 528 cx25821_set_tvnorm(dev, dev->tvnorm);
497#endif 529#endif
498 mutex_unlock(&dev->lock); 530 mutex_unlock(&dev->lock);
499 531
500 init_controls(dev, chan_num);
501 532
502 return 0; 533 return 0;
503 534
504 fail_unreg: 535fail_unreg:
505 cx25821_video_unregister(dev, chan_num); 536 cx25821_video_unregister(dev, i);
506 return err; 537 return err;
507} 538}
508 539
@@ -533,7 +564,7 @@ int cx25821_buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
533 u32 line0_offset, line1_offset; 564 u32 line0_offset, line1_offset;
534 struct videobuf_dmabuf *dma = videobuf_to_dma(&buf->vb); 565 struct videobuf_dmabuf *dma = videobuf_to_dma(&buf->vb);
535 int bpl_local = LINE_SIZE_D1; 566 int bpl_local = LINE_SIZE_D1;
536 int channel_opened = 0; 567 int channel_opened = fh->channel_id;
537 568
538 BUG_ON(NULL == fh->fmt); 569 BUG_ON(NULL == fh->fmt);
539 if (fh->width < 48 || fh->width > 720 || 570 if (fh->width < 48 || fh->width > 720 ||
@@ -572,26 +603,29 @@ int cx25821_buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
572 channel_opened = (channel_opened < 0 603 channel_opened = (channel_opened < 0
573 || channel_opened > 7) ? 7 : channel_opened; 604 || channel_opened > 7) ? 7 : channel_opened;
574 605
575 if (dev->pixel_formats[channel_opened] == PIXEL_FRMT_411) 606 if (dev->channels[channel_opened]
607 .pixel_formats == PIXEL_FRMT_411)
576 buf->bpl = (buf->fmt->depth * buf->vb.width) >> 3; 608 buf->bpl = (buf->fmt->depth * buf->vb.width) >> 3;
577 else 609 else
578 buf->bpl = (buf->fmt->depth >> 3) * (buf->vb.width); 610 buf->bpl = (buf->fmt->depth >> 3) * (buf->vb.width);
579 611
580 if (dev->pixel_formats[channel_opened] == PIXEL_FRMT_411) { 612 if (dev->channels[channel_opened]
613 .pixel_formats == PIXEL_FRMT_411) {
581 bpl_local = buf->bpl; 614 bpl_local = buf->bpl;
582 } else { 615 } else {
583 bpl_local = buf->bpl; //Default 616 bpl_local = buf->bpl; /* Default */
584 617
585 if (channel_opened >= 0 && channel_opened <= 7) { 618 if (channel_opened >= 0 && channel_opened <= 7) {
586 if (dev->use_cif_resolution[channel_opened]) { 619 if (dev->channels[channel_opened]
620 .use_cif_resolution) {
587 if (dev->tvnorm & V4L2_STD_PAL_BG 621 if (dev->tvnorm & V4L2_STD_PAL_BG
588 || dev->tvnorm & V4L2_STD_PAL_DK) 622 || dev->tvnorm & V4L2_STD_PAL_DK)
589 bpl_local = 352 << 1; 623 bpl_local = 352 << 1;
590 else 624 else
591 bpl_local = 625 bpl_local =
592 dev-> 626 dev->channels[channel_opened].
593 cif_width[channel_opened] << 627 cif_width <<
594 1; 628 1;
595 } 629 }
596 } 630 }
597 } 631 }
@@ -685,6 +719,383 @@ int cx25821_video_mmap(struct file *file, struct vm_area_struct *vma)
685 return videobuf_mmap_mapper(get_queue(fh), vma); 719 return videobuf_mmap_mapper(get_queue(fh), vma);
686} 720}
687 721
722
723static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
724{
725 struct cx25821_buffer *buf =
726 container_of(vb, struct cx25821_buffer, vb);
727 struct cx25821_buffer *prev;
728 struct cx25821_fh *fh = vq->priv_data;
729 struct cx25821_dev *dev = fh->dev;
730 struct cx25821_dmaqueue *q = &dev->channels[fh->channel_id].vidq;
731
732 /* add jump to stopper */
733 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
734 buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma);
735 buf->risc.jmp[2] = cpu_to_le32(0); /* bits 63-32 */
736
737 dprintk(2, "jmp to stopper (0x%x)\n", buf->risc.jmp[1]);
738
739 if (!list_empty(&q->queued)) {
740 list_add_tail(&buf->vb.queue, &q->queued);
741 buf->vb.state = VIDEOBUF_QUEUED;
742 dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf,
743 buf->vb.i);
744
745 } else if (list_empty(&q->active)) {
746 list_add_tail(&buf->vb.queue, &q->active);
747 cx25821_start_video_dma(dev, q, buf,
748 dev->channels[fh->channel_id].
749 sram_channels);
750 buf->vb.state = VIDEOBUF_ACTIVE;
751 buf->count = q->count++;
752 mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
753 dprintk(2,
754 "[%p/%d] buffer_queue - first active, buf cnt = %d, \
755 q->count = %d\n",
756 buf, buf->vb.i, buf->count, q->count);
757 } else {
758 prev =
759 list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
760 if (prev->vb.width == buf->vb.width
761 && prev->vb.height == buf->vb.height
762 && prev->fmt == buf->fmt) {
763 list_add_tail(&buf->vb.queue, &q->active);
764 buf->vb.state = VIDEOBUF_ACTIVE;
765 buf->count = q->count++;
766 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
767
768 /* 64 bit bits 63-32 */
769 prev->risc.jmp[2] = cpu_to_le32(0);
770 dprintk(2,
771 "[%p/%d] buffer_queue - append to active, \
772 buf->count=%d\n",
773 buf, buf->vb.i, buf->count);
774
775 } else {
776 list_add_tail(&buf->vb.queue, &q->queued);
777 buf->vb.state = VIDEOBUF_QUEUED;
778 dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf,
779 buf->vb.i);
780 }
781 }
782
783 if (list_empty(&q->active))
784 dprintk(2, "active queue empty!\n");
785}
786
787static struct videobuf_queue_ops cx25821_video_qops = {
788 .buf_setup = cx25821_buffer_setup,
789 .buf_prepare = cx25821_buffer_prepare,
790 .buf_queue = buffer_queue,
791 .buf_release = cx25821_buffer_release,
792};
793
794static int video_open(struct file *file)
795{
796 struct video_device *vdev = video_devdata(file);
797 struct cx25821_dev *h, *dev = video_drvdata(file);
798 struct cx25821_fh *fh;
799 struct list_head *list;
800 int minor = video_devdata(file)->minor;
801 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
802 u32 pix_format;
803 int ch_id = 0;
804 int i;
805
806 dprintk(1, "open dev=%s type=%s\n",
807 video_device_node_name(vdev),
808 v4l2_type_names[type]);
809
810 /* allocate + initialize per filehandle data */
811 fh = kzalloc(sizeof(*fh), GFP_KERNEL);
812 if (NULL == fh)
813 return -ENOMEM;
814
815 lock_kernel();
816
817 list_for_each(list, &cx25821_devlist)
818 {
819 h = list_entry(list, struct cx25821_dev, devlist);
820
821 for (i = 0; i < MAX_VID_CHANNEL_NUM; i++) {
822 if (h->channels[i].video_dev &&
823 h->channels[i].video_dev->minor == minor) {
824 dev = h;
825 ch_id = i;
826 type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
827 }
828 }
829 }
830
831 if (NULL == dev) {
832 unlock_kernel();
833 return -ENODEV;
834 }
835
836 file->private_data = fh;
837 fh->dev = dev;
838 fh->type = type;
839 fh->width = 720;
840 fh->channel_id = ch_id;
841
842 if (dev->tvnorm & V4L2_STD_PAL_BG || dev->tvnorm & V4L2_STD_PAL_DK)
843 fh->height = 576;
844 else
845 fh->height = 480;
846
847 dev->channel_opened = fh->channel_id;
848 pix_format =
849 (dev->channels[ch_id].pixel_formats ==
850 PIXEL_FRMT_411) ? V4L2_PIX_FMT_Y41P : V4L2_PIX_FMT_YUYV;
851 fh->fmt = format_by_fourcc(pix_format);
852
853 v4l2_prio_open(&dev->channels[ch_id].prio, &fh->prio);
854
855 videobuf_queue_sg_init(&fh->vidq, &cx25821_video_qops,
856 &dev->pci->dev, &dev->slock,
857 V4L2_BUF_TYPE_VIDEO_CAPTURE,
858 V4L2_FIELD_INTERLACED,
859 sizeof(struct cx25821_buffer), fh);
860
861 dprintk(1, "post videobuf_queue_init()\n");
862 unlock_kernel();
863
864 return 0;
865}
866
867static ssize_t video_read(struct file *file, char __user * data, size_t count,
868 loff_t *ppos)
869{
870 struct cx25821_fh *fh = file->private_data;
871
872 switch (fh->type) {
873 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
874 if (cx25821_res_locked(fh, RESOURCE_VIDEO0))
875 return -EBUSY;
876
877 return videobuf_read_one(&fh->vidq, data, count, ppos,
878 file->f_flags & O_NONBLOCK);
879
880 default:
881 BUG();
882 return 0;
883 }
884}
885
886static unsigned int video_poll(struct file *file,
887 struct poll_table_struct *wait)
888{
889 struct cx25821_fh *fh = file->private_data;
890 struct cx25821_buffer *buf;
891
892 if (cx25821_res_check(fh, RESOURCE_VIDEO0)) {
893 /* streaming capture */
894 if (list_empty(&fh->vidq.stream))
895 return POLLERR;
896 buf = list_entry(fh->vidq.stream.next,
897 struct cx25821_buffer, vb.stream);
898 } else {
899 /* read() capture */
900 buf = (struct cx25821_buffer *)fh->vidq.read_buf;
901 if (NULL == buf)
902 return POLLERR;
903 }
904
905 poll_wait(file, &buf->vb.done, wait);
906 if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR) {
907 if (buf->vb.state == VIDEOBUF_DONE) {
908 struct cx25821_dev *dev = fh->dev;
909
910 if (dev && dev->channels[fh->channel_id]
911 .use_cif_resolution) {
912 u8 cam_id = *((char *)buf->vb.baddr + 3);
913 memcpy((char *)buf->vb.baddr,
914 (char *)buf->vb.baddr + (fh->width * 2),
915 (fh->width * 2));
916 *((char *)buf->vb.baddr + 3) = cam_id;
917 }
918 }
919
920 return POLLIN | POLLRDNORM;
921 }
922
923 return 0;
924}
925
926static int video_release(struct file *file)
927{
928 struct cx25821_fh *fh = file->private_data;
929 struct cx25821_dev *dev = fh->dev;
930
931 /* stop the risc engine and fifo */
932 cx_write(channel0->dma_ctl, 0); /* FIFO and RISC disable */
933
934 /* stop video capture */
935 if (cx25821_res_check(fh, RESOURCE_VIDEO0)) {
936 videobuf_queue_cancel(&fh->vidq);
937 cx25821_res_free(dev, fh, RESOURCE_VIDEO0);
938 }
939
940 if (fh->vidq.read_buf) {
941 cx25821_buffer_release(&fh->vidq, fh->vidq.read_buf);
942 kfree(fh->vidq.read_buf);
943 }
944
945 videobuf_mmap_free(&fh->vidq);
946
947 v4l2_prio_close(&dev->channels[fh->channel_id].prio, fh->prio);
948 file->private_data = NULL;
949 kfree(fh);
950
951 return 0;
952}
953
954static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
955{
956 struct cx25821_fh *fh = priv;
957 struct cx25821_dev *dev = fh->dev;
958
959 if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE))
960 return -EINVAL;
961
962 if (unlikely(i != fh->type))
963 return -EINVAL;
964
965 if (unlikely(!cx25821_res_get(dev, fh,
966 cx25821_get_resource(fh, RESOURCE_VIDEO0))))
967 return -EBUSY;
968
969 return videobuf_streamon(get_queue(fh));
970}
971
972static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
973{
974 struct cx25821_fh *fh = priv;
975 struct cx25821_dev *dev = fh->dev;
976 int err, res;
977
978 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
979 return -EINVAL;
980 if (i != fh->type)
981 return -EINVAL;
982
983 res = cx25821_get_resource(fh, RESOURCE_VIDEO0);
984 err = videobuf_streamoff(get_queue(fh));
985 if (err < 0)
986 return err;
987 cx25821_res_free(dev, fh, res);
988 return 0;
989}
990
991static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
992 struct v4l2_format *f)
993{
994 struct cx25821_fh *fh = priv;
995 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
996 int err;
997 int pix_format = PIXEL_FRMT_422;
998
999 if (fh) {
1000 err = v4l2_prio_check(&dev->channels[fh->channel_id]
1001 .prio, fh->prio);
1002 if (0 != err)
1003 return err;
1004 }
1005
1006 dprintk(2, "%s()\n", __func__);
1007 err = cx25821_vidioc_try_fmt_vid_cap(file, priv, f);
1008
1009 if (0 != err)
1010 return err;
1011
1012 fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat);
1013 fh->vidq.field = f->fmt.pix.field;
1014
1015 /* check if width and height is valid based on set standard */
1016 if (cx25821_is_valid_width(f->fmt.pix.width, dev->tvnorm))
1017 fh->width = f->fmt.pix.width;
1018
1019 if (cx25821_is_valid_height(f->fmt.pix.height, dev->tvnorm))
1020 fh->height = f->fmt.pix.height;
1021
1022 if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_Y41P)
1023 pix_format = PIXEL_FRMT_411;
1024 else if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_YUYV)
1025 pix_format = PIXEL_FRMT_422;
1026 else
1027 return -EINVAL;
1028
1029 cx25821_set_pixel_format(dev, SRAM_CH00, pix_format);
1030
1031 /* check if cif resolution */
1032 if (fh->width == 320 || fh->width == 352)
1033 dev->channels[fh->channel_id].use_cif_resolution = 1;
1034 else
1035 dev->channels[fh->channel_id].use_cif_resolution = 0;
1036
1037 dev->channels[fh->channel_id].cif_width = fh->width;
1038 medusa_set_resolution(dev, fh->width, SRAM_CH00);
1039
1040 dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width,
1041 fh->height, fh->vidq.field);
1042 cx25821_call_all(dev, video, s_fmt, f);
1043
1044 return 0;
1045}
1046
1047static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
1048{
1049 int ret_val = 0;
1050 struct cx25821_fh *fh = priv;
1051 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
1052
1053 ret_val = videobuf_dqbuf(get_queue(fh), p, file->f_flags & O_NONBLOCK);
1054
1055 p->sequence = dev->channels[fh->channel_id].vidq.count;
1056
1057 return ret_val;
1058}
1059
1060static int vidioc_log_status(struct file *file, void *priv)
1061{
1062 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
1063 struct cx25821_fh *fh = priv;
1064 char name[32 + 2];
1065
1066 struct sram_channel *sram_ch = dev->channels[fh->channel_id]
1067 .sram_channels;
1068 u32 tmp = 0;
1069
1070 snprintf(name, sizeof(name), "%s/2", dev->name);
1071 printk(KERN_INFO "%s/2: ============ START LOG STATUS ============\n",
1072 dev->name);
1073 cx25821_call_all(dev, core, log_status);
1074 tmp = cx_read(sram_ch->dma_ctl);
1075 printk(KERN_INFO "Video input 0 is %s\n",
1076 (tmp & 0x11) ? "streaming" : "stopped");
1077 printk(KERN_INFO "%s/2: ============= END LOG STATUS =============\n",
1078 dev->name);
1079 return 0;
1080}
1081
1082static int vidioc_s_ctrl(struct file *file, void *priv,
1083 struct v4l2_control *ctl)
1084{
1085 struct cx25821_fh *fh = priv;
1086 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
1087 int err;
1088
1089 if (fh) {
1090 err = v4l2_prio_check(&dev->channels[fh->channel_id]
1091 .prio, fh->prio);
1092 if (0 != err)
1093 return err;
1094 }
1095
1096 return cx25821_set_control(dev, ctl, fh->channel_id);
1097}
1098
688/* VIDEO IOCTLS */ 1099/* VIDEO IOCTLS */
689int cx25821_vidioc_g_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f) 1100int cx25821_vidioc_g_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f)
690{ 1101{
@@ -822,8 +1233,9 @@ int cx25821_vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *p)
822int cx25821_vidioc_g_priority(struct file *file, void *f, enum v4l2_priority *p) 1233int cx25821_vidioc_g_priority(struct file *file, void *f, enum v4l2_priority *p)
823{ 1234{
824 struct cx25821_dev *dev = ((struct cx25821_fh *)f)->dev; 1235 struct cx25821_dev *dev = ((struct cx25821_fh *)f)->dev;
1236 struct cx25821_fh *fh = f;
825 1237
826 *p = v4l2_prio_max(&dev->prio); 1238 *p = v4l2_prio_max(&dev->channels[fh->channel_id].prio);
827 1239
828 return 0; 1240 return 0;
829} 1241}
@@ -833,7 +1245,8 @@ int cx25821_vidioc_s_priority(struct file *file, void *f, enum v4l2_priority pri
833 struct cx25821_fh *fh = f; 1245 struct cx25821_fh *fh = f;
834 struct cx25821_dev *dev = ((struct cx25821_fh *)f)->dev; 1246 struct cx25821_dev *dev = ((struct cx25821_fh *)f)->dev;
835 1247
836 return v4l2_prio_change(&dev->prio, &fh->prio, prio); 1248 return v4l2_prio_change(&dev->channels[fh->channel_id]
1249 .prio, &fh->prio, prio);
837} 1250}
838 1251
839#ifdef TUNER_FLAG 1252#ifdef TUNER_FLAG
@@ -846,7 +1259,8 @@ int cx25821_vidioc_s_std(struct file *file, void *priv, v4l2_std_id * tvnorms)
846 dprintk(1, "%s()\n", __func__); 1259 dprintk(1, "%s()\n", __func__);
847 1260
848 if (fh) { 1261 if (fh) {
849 err = v4l2_prio_check(&dev->prio, fh->prio); 1262 err = v4l2_prio_check(&dev->channels[fh->channel_id]
1263 .prio, fh->prio);
850 if (0 != err) 1264 if (0 != err)
851 return err; 1265 return err;
852 } 1266 }
@@ -916,7 +1330,8 @@ int cx25821_vidioc_s_input(struct file *file, void *priv, unsigned int i)
916 dprintk(1, "%s(%d)\n", __func__, i); 1330 dprintk(1, "%s(%d)\n", __func__, i);
917 1331
918 if (fh) { 1332 if (fh) {
919 err = v4l2_prio_check(&dev->prio, fh->prio); 1333 err = v4l2_prio_check(&dev->channels[fh->channel_id]
1334 .prio, fh->prio);
920 if (0 != err) 1335 if (0 != err)
921 return err; 1336 return err;
922 } 1337 }
@@ -967,9 +1382,14 @@ int cx25821_vidioc_s_frequency(struct file *file, void *priv, struct v4l2_freque
967 int err; 1382 int err;
968 1383
969 if (fh) { 1384 if (fh) {
970 err = v4l2_prio_check(&dev->prio, fh->prio); 1385 dev = fh->dev;
1386 err = v4l2_prio_check(&dev->channels[fh->channel_id]
1387 .prio, fh->prio);
971 if (0 != err) 1388 if (0 != err)
972 return err; 1389 return err;
1390 } else {
1391 printk(KERN_ERR "Invalid fh pointer!\n");
1392 return -EINVAL;
973 } 1393 }
974 1394
975 return cx25821_set_freq(dev, f); 1395 return cx25821_set_freq(dev, f);
@@ -1031,7 +1451,8 @@ int cx25821_vidioc_s_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
1031 int err; 1451 int err;
1032 1452
1033 if (fh) { 1453 if (fh) {
1034 err = v4l2_prio_check(&dev->prio, fh->prio); 1454 err = v4l2_prio_check(&dev->channels[fh->channel_id]
1455 .prio, fh->prio);
1035 if (0 != err) 1456 if (0 != err)
1036 return err; 1457 return err;
1037 } 1458 }
@@ -1046,7 +1467,7 @@ int cx25821_vidioc_s_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
1046} 1467}
1047 1468
1048#endif 1469#endif
1049// ****************************************************************************************** 1470/*****************************************************************************/
1050static const struct v4l2_queryctrl no_ctl = { 1471static const struct v4l2_queryctrl no_ctl = {
1051 .name = "42", 1472 .name = "42",
1052 .flags = V4L2_CTRL_FLAG_DISABLED, 1473 .flags = V4L2_CTRL_FLAG_DISABLED,
@@ -1129,6 +1550,7 @@ static const struct v4l2_queryctrl *ctrl_by_id(unsigned int id)
1129int cx25821_vidioc_g_ctrl(struct file *file, void *priv, struct v4l2_control *ctl) 1550int cx25821_vidioc_g_ctrl(struct file *file, void *priv, struct v4l2_control *ctl)
1130{ 1551{
1131 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev; 1552 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
1553 struct cx25821_fh *fh = priv;
1132 1554
1133 const struct v4l2_queryctrl *ctrl; 1555 const struct v4l2_queryctrl *ctrl;
1134 1556
@@ -1138,16 +1560,16 @@ int cx25821_vidioc_g_ctrl(struct file *file, void *priv, struct v4l2_control *ct
1138 return -EINVAL; 1560 return -EINVAL;
1139 switch (ctl->id) { 1561 switch (ctl->id) {
1140 case V4L2_CID_BRIGHTNESS: 1562 case V4L2_CID_BRIGHTNESS:
1141 ctl->value = dev->ctl_bright; 1563 ctl->value = dev->channels[fh->channel_id].ctl_bright;
1142 break; 1564 break;
1143 case V4L2_CID_HUE: 1565 case V4L2_CID_HUE:
1144 ctl->value = dev->ctl_hue; 1566 ctl->value = dev->channels[fh->channel_id].ctl_hue;
1145 break; 1567 break;
1146 case V4L2_CID_CONTRAST: 1568 case V4L2_CID_CONTRAST:
1147 ctl->value = dev->ctl_contrast; 1569 ctl->value = dev->channels[fh->channel_id].ctl_contrast;
1148 break; 1570 break;
1149 case V4L2_CID_SATURATION: 1571 case V4L2_CID_SATURATION:
1150 ctl->value = dev->ctl_saturation; 1572 ctl->value = dev->channels[fh->channel_id].ctl_saturation;
1151 break; 1573 break;
1152 } 1574 }
1153 return 0; 1575 return 0;
@@ -1181,19 +1603,19 @@ int cx25821_set_control(struct cx25821_dev *dev,
1181 1603
1182 switch (ctl->id) { 1604 switch (ctl->id) {
1183 case V4L2_CID_BRIGHTNESS: 1605 case V4L2_CID_BRIGHTNESS:
1184 dev->ctl_bright = ctl->value; 1606 dev->channels[chan_num].ctl_bright = ctl->value;
1185 medusa_set_brightness(dev, ctl->value, chan_num); 1607 medusa_set_brightness(dev, ctl->value, chan_num);
1186 break; 1608 break;
1187 case V4L2_CID_HUE: 1609 case V4L2_CID_HUE:
1188 dev->ctl_hue = ctl->value; 1610 dev->channels[chan_num].ctl_hue = ctl->value;
1189 medusa_set_hue(dev, ctl->value, chan_num); 1611 medusa_set_hue(dev, ctl->value, chan_num);
1190 break; 1612 break;
1191 case V4L2_CID_CONTRAST: 1613 case V4L2_CID_CONTRAST:
1192 dev->ctl_contrast = ctl->value; 1614 dev->channels[chan_num].ctl_contrast = ctl->value;
1193 medusa_set_contrast(dev, ctl->value, chan_num); 1615 medusa_set_contrast(dev, ctl->value, chan_num);
1194 break; 1616 break;
1195 case V4L2_CID_SATURATION: 1617 case V4L2_CID_SATURATION:
1196 dev->ctl_saturation = ctl->value; 1618 dev->channels[chan_num].ctl_saturation = ctl->value;
1197 medusa_set_saturation(dev, ctl->value, chan_num); 1619 medusa_set_saturation(dev, ctl->value, chan_num);
1198 break; 1620 break;
1199 } 1621 }
@@ -1203,7 +1625,7 @@ int cx25821_set_control(struct cx25821_dev *dev,
1203 return err; 1625 return err;
1204} 1626}
1205 1627
1206static void init_controls(struct cx25821_dev *dev, int chan_num) 1628static void cx25821_init_controls(struct cx25821_dev *dev, int chan_num)
1207{ 1629{
1208 struct v4l2_control ctrl; 1630 struct v4l2_control ctrl;
1209 int i; 1631 int i;
@@ -1239,23 +1661,24 @@ int cx25821_vidioc_s_crop(struct file *file, void *priv, struct v4l2_crop *crop)
1239 int err; 1661 int err;
1240 1662
1241 if (fh) { 1663 if (fh) {
1242 err = v4l2_prio_check(&dev->prio, fh->prio); 1664 err = v4l2_prio_check(&dev->channels[fh->channel_id].
1665 prio, fh->prio);
1243 if (0 != err) 1666 if (0 != err)
1244 return err; 1667 return err;
1245 } 1668 }
1246 // cx25821_vidioc_s_crop not supported 1669 /* cx25821_vidioc_s_crop not supported */
1247 return -EINVAL; 1670 return -EINVAL;
1248} 1671}
1249 1672
1250int cx25821_vidioc_g_crop(struct file *file, void *priv, struct v4l2_crop *crop) 1673int cx25821_vidioc_g_crop(struct file *file, void *priv, struct v4l2_crop *crop)
1251{ 1674{
1252 // cx25821_vidioc_g_crop not supported 1675 /* cx25821_vidioc_g_crop not supported */
1253 return -EINVAL; 1676 return -EINVAL;
1254} 1677}
1255 1678
1256int cx25821_vidioc_querystd(struct file *file, void *priv, v4l2_std_id * norm) 1679int cx25821_vidioc_querystd(struct file *file, void *priv, v4l2_std_id * norm)
1257{ 1680{
1258 // medusa does not support video standard sensing of current input 1681 /* medusa does not support video standard sensing of current input */
1259 *norm = CX25821_NORMS; 1682 *norm = CX25821_NORMS;
1260 1683
1261 return 0; 1684 return 0;
@@ -1297,3 +1720,325 @@ int cx25821_is_valid_height(u32 height, v4l2_std_id tvnorm)
1297 1720
1298 return 0; 1721 return 0;
1299} 1722}
1723
1724static long video_ioctl_upstream9(struct file *file, unsigned int cmd,
1725 unsigned long arg)
1726{
1727 struct cx25821_fh *fh = file->private_data;
1728 struct cx25821_dev *dev = fh->dev;
1729 int command = 0;
1730 struct upstream_user_struct *data_from_user;
1731
1732 data_from_user = (struct upstream_user_struct *)arg;
1733
1734 if (!data_from_user) {
1735 printk
1736 ("cx25821 in %s(): Upstream data is INVALID. Returning.\n",
1737 __func__);
1738 return 0;
1739 }
1740
1741 command = data_from_user->command;
1742
1743 if (command != UPSTREAM_START_VIDEO &&
1744 command != UPSTREAM_STOP_VIDEO)
1745 return 0;
1746
1747 dev->input_filename = data_from_user->input_filename;
1748 dev->input_audiofilename = data_from_user->input_filename;
1749 dev->vid_stdname = data_from_user->vid_stdname;
1750 dev->pixel_format = data_from_user->pixel_format;
1751 dev->channel_select = data_from_user->channel_select;
1752 dev->command = data_from_user->command;
1753
1754 switch (command) {
1755 case UPSTREAM_START_VIDEO:
1756 cx25821_start_upstream_video_ch1(dev, data_from_user);
1757 break;
1758
1759 case UPSTREAM_STOP_VIDEO:
1760 cx25821_stop_upstream_video_ch1(dev);
1761 break;
1762 }
1763
1764 return 0;
1765}
1766
1767static long video_ioctl_upstream10(struct file *file, unsigned int cmd,
1768 unsigned long arg)
1769{
1770 struct cx25821_fh *fh = file->private_data;
1771 struct cx25821_dev *dev = fh->dev;
1772 int command = 0;
1773 struct upstream_user_struct *data_from_user;
1774
1775 data_from_user = (struct upstream_user_struct *)arg;
1776
1777 if (!data_from_user) {
1778 printk
1779 ("cx25821 in %s(): Upstream data is INVALID. Returning.\n",
1780 __func__);
1781 return 0;
1782 }
1783
1784 command = data_from_user->command;
1785
1786 if (command != UPSTREAM_START_VIDEO &&
1787 command != UPSTREAM_STOP_VIDEO)
1788 return 0;
1789
1790 dev->input_filename_ch2 = data_from_user->input_filename;
1791 dev->input_audiofilename = data_from_user->input_filename;
1792 dev->vid_stdname_ch2 = data_from_user->vid_stdname;
1793 dev->pixel_format_ch2 = data_from_user->pixel_format;
1794 dev->channel_select_ch2 = data_from_user->channel_select;
1795 dev->command_ch2 = data_from_user->command;
1796
1797 switch (command) {
1798 case UPSTREAM_START_VIDEO:
1799 cx25821_start_upstream_video_ch2(dev, data_from_user);
1800 break;
1801
1802 case UPSTREAM_STOP_VIDEO:
1803 cx25821_stop_upstream_video_ch2(dev);
1804 break;
1805 }
1806
1807 return 0;
1808}
1809
1810static long video_ioctl_upstream11(struct file *file, unsigned int cmd,
1811 unsigned long arg)
1812{
1813 struct cx25821_fh *fh = file->private_data;
1814 struct cx25821_dev *dev = fh->dev;
1815 int command = 0;
1816 struct upstream_user_struct *data_from_user;
1817
1818 data_from_user = (struct upstream_user_struct *)arg;
1819
1820 if (!data_from_user) {
1821 printk
1822 ("cx25821 in %s(): Upstream data is INVALID. Returning.\n",
1823 __func__);
1824 return 0;
1825 }
1826
1827 command = data_from_user->command;
1828
1829 if (command != UPSTREAM_START_AUDIO &&
1830 command != UPSTREAM_STOP_AUDIO)
1831 return 0;
1832
1833 dev->input_filename = data_from_user->input_filename;
1834 dev->input_audiofilename = data_from_user->input_filename;
1835 dev->vid_stdname = data_from_user->vid_stdname;
1836 dev->pixel_format = data_from_user->pixel_format;
1837 dev->channel_select = data_from_user->channel_select;
1838 dev->command = data_from_user->command;
1839
1840 switch (command) {
1841 case UPSTREAM_START_AUDIO:
1842 cx25821_start_upstream_audio(dev, data_from_user);
1843 break;
1844
1845 case UPSTREAM_STOP_AUDIO:
1846 cx25821_stop_upstream_audio(dev);
1847 break;
1848 }
1849
1850 return 0;
1851}
1852
1853static long video_ioctl_set(struct file *file, unsigned int cmd,
1854 unsigned long arg)
1855{
1856 struct cx25821_fh *fh = file->private_data;
1857 struct cx25821_dev *dev = fh->dev;
1858 struct downstream_user_struct *data_from_user;
1859 int command;
1860 int width = 720;
1861 int selected_channel = 0, pix_format = 0, i = 0;
1862 int cif_enable = 0, cif_width = 0;
1863 u32 value = 0;
1864
1865 data_from_user = (struct downstream_user_struct *)arg;
1866
1867 if (!data_from_user) {
1868 printk(
1869 "cx25821 in %s(): User data is INVALID. Returning.\n",
1870 __func__);
1871 return 0;
1872 }
1873
1874 command = data_from_user->command;
1875
1876 if (command != SET_VIDEO_STD && command != SET_PIXEL_FORMAT
1877 && command != ENABLE_CIF_RESOLUTION && command != REG_READ
1878 && command != REG_WRITE && command != MEDUSA_READ
1879 && command != MEDUSA_WRITE) {
1880 return 0;
1881 }
1882
1883 switch (command) {
1884 case SET_VIDEO_STD:
1885 dev->tvnorm =
1886 !strcmp(data_from_user->vid_stdname,
1887 "PAL") ? V4L2_STD_PAL_BG : V4L2_STD_NTSC_M;
1888 medusa_set_videostandard(dev);
1889 break;
1890
1891 case SET_PIXEL_FORMAT:
1892 selected_channel = data_from_user->decoder_select;
1893 pix_format = data_from_user->pixel_format;
1894
1895 if (!(selected_channel <= 7 && selected_channel >= 0)) {
1896 selected_channel -= 4;
1897 selected_channel = selected_channel % 8;
1898 }
1899
1900 if (selected_channel >= 0)
1901 cx25821_set_pixel_format(dev, selected_channel,
1902 pix_format);
1903
1904 break;
1905
1906 case ENABLE_CIF_RESOLUTION:
1907 selected_channel = data_from_user->decoder_select;
1908 cif_enable = data_from_user->cif_resolution_enable;
1909 cif_width = data_from_user->cif_width;
1910
1911 if (cif_enable) {
1912 if (dev->tvnorm & V4L2_STD_PAL_BG
1913 || dev->tvnorm & V4L2_STD_PAL_DK)
1914 width = 352;
1915 else
1916 width = (cif_width == 320
1917 || cif_width == 352) ? cif_width : 320;
1918 }
1919
1920 if (!(selected_channel <= 7 && selected_channel >= 0)) {
1921 selected_channel -= 4;
1922 selected_channel = selected_channel % 8;
1923 }
1924
1925 if (selected_channel <= 7 && selected_channel >= 0) {
1926 dev->channels[selected_channel].
1927 use_cif_resolution = cif_enable;
1928 dev->channels[selected_channel].cif_width = width;
1929 } else {
1930 for (i = 0; i < VID_CHANNEL_NUM; i++) {
1931 dev->channels[i].use_cif_resolution =
1932 cif_enable;
1933 dev->channels[i].cif_width = width;
1934 }
1935 }
1936
1937 medusa_set_resolution(dev, width, selected_channel);
1938 break;
1939 case REG_READ:
1940 data_from_user->reg_data = cx_read(data_from_user->reg_address);
1941 break;
1942 case REG_WRITE:
1943 cx_write(data_from_user->reg_address, data_from_user->reg_data);
1944 break;
1945 case MEDUSA_READ:
1946 value =
1947 cx25821_i2c_read(&dev->i2c_bus[0],
1948 (u16) data_from_user->reg_address,
1949 &data_from_user->reg_data);
1950 break;
1951 case MEDUSA_WRITE:
1952 cx25821_i2c_write(&dev->i2c_bus[0],
1953 (u16) data_from_user->reg_address,
1954 data_from_user->reg_data);
1955 break;
1956 }
1957
1958 return 0;
1959}
1960
1961static long cx25821_video_ioctl(struct file *file,
1962 unsigned int cmd, unsigned long arg)
1963{
1964 int ret = 0;
1965
1966 struct cx25821_fh *fh = file->private_data;
1967
1968 /* check to see if it's the video upstream */
1969 if (fh->channel_id == SRAM_CH09) {
1970 ret = video_ioctl_upstream9(file, cmd, arg);
1971 return ret;
1972 } else if (fh->channel_id == SRAM_CH10) {
1973 ret = video_ioctl_upstream10(file, cmd, arg);
1974 return ret;
1975 } else if (fh->channel_id == SRAM_CH11) {
1976 ret = video_ioctl_upstream11(file, cmd, arg);
1977 ret = video_ioctl_set(file, cmd, arg);
1978 return ret;
1979 }
1980
1981 return video_ioctl2(file, cmd, arg);
1982}
1983
1984/* exported stuff */
1985static const struct v4l2_file_operations video_fops = {
1986 .owner = THIS_MODULE,
1987 .open = video_open,
1988 .release = video_release,
1989 .read = video_read,
1990 .poll = video_poll,
1991 .mmap = cx25821_video_mmap,
1992 .ioctl = cx25821_video_ioctl,
1993};
1994
1995static const struct v4l2_ioctl_ops video_ioctl_ops = {
1996 .vidioc_querycap = cx25821_vidioc_querycap,
1997 .vidioc_enum_fmt_vid_cap = cx25821_vidioc_enum_fmt_vid_cap,
1998 .vidioc_g_fmt_vid_cap = cx25821_vidioc_g_fmt_vid_cap,
1999 .vidioc_try_fmt_vid_cap = cx25821_vidioc_try_fmt_vid_cap,
2000 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
2001 .vidioc_reqbufs = cx25821_vidioc_reqbufs,
2002 .vidioc_querybuf = cx25821_vidioc_querybuf,
2003 .vidioc_qbuf = cx25821_vidioc_qbuf,
2004 .vidioc_dqbuf = vidioc_dqbuf,
2005#ifdef TUNER_FLAG
2006 .vidioc_s_std = cx25821_vidioc_s_std,
2007 .vidioc_querystd = cx25821_vidioc_querystd,
2008#endif
2009 .vidioc_cropcap = cx25821_vidioc_cropcap,
2010 .vidioc_s_crop = cx25821_vidioc_s_crop,
2011 .vidioc_g_crop = cx25821_vidioc_g_crop,
2012 .vidioc_enum_input = cx25821_vidioc_enum_input,
2013 .vidioc_g_input = cx25821_vidioc_g_input,
2014 .vidioc_s_input = cx25821_vidioc_s_input,
2015 .vidioc_g_ctrl = cx25821_vidioc_g_ctrl,
2016 .vidioc_s_ctrl = vidioc_s_ctrl,
2017 .vidioc_queryctrl = cx25821_vidioc_queryctrl,
2018 .vidioc_streamon = vidioc_streamon,
2019 .vidioc_streamoff = vidioc_streamoff,
2020 .vidioc_log_status = vidioc_log_status,
2021 .vidioc_g_priority = cx25821_vidioc_g_priority,
2022 .vidioc_s_priority = cx25821_vidioc_s_priority,
2023#ifdef CONFIG_VIDEO_V4L1_COMPAT
2024 .vidiocgmbuf = cx25821_vidiocgmbuf,
2025#endif
2026#ifdef TUNER_FLAG
2027 .vidioc_g_tuner = cx25821_vidioc_g_tuner,
2028 .vidioc_s_tuner = cx25821_vidioc_s_tuner,
2029 .vidioc_g_frequency = cx25821_vidioc_g_frequency,
2030 .vidioc_s_frequency = cx25821_vidioc_s_frequency,
2031#endif
2032#ifdef CONFIG_VIDEO_ADV_DEBUG
2033 .vidioc_g_register = cx25821_vidioc_g_register,
2034 .vidioc_s_register = cx25821_vidioc_s_register,
2035#endif
2036};
2037
2038struct video_device cx25821_videoioctl_template = {
2039 .name = "cx25821-videoioctl",
2040 .fops = &video_fops,
2041 .ioctl_ops = &video_ioctl_ops,
2042 .tvnorms = CX25821_NORMS,
2043 .current_norm = V4L2_STD_NTSC_M,
2044};
diff --git a/drivers/staging/cx25821/cx25821-video.h b/drivers/staging/cx25821/cx25821-video.h
index 0bddc02be57d..cc6034b1a95d 100644
--- a/drivers/staging/cx25821/cx25821-video.h
+++ b/drivers/staging/cx25821/cx25821-video.h
@@ -54,7 +54,7 @@
54 printk(KERN_DEBUG "%s/0: " fmt, dev->name, ## arg);\ 54 printk(KERN_DEBUG "%s/0: " fmt, dev->name, ## arg);\
55 } while (0) 55 } while (0)
56 56
57//For IOCTL to identify running upstream 57/* For IOCTL to identify running upstream */
58#define UPSTREAM_START_VIDEO 700 58#define UPSTREAM_START_VIDEO 700
59#define UPSTREAM_STOP_VIDEO 701 59#define UPSTREAM_STOP_VIDEO 701
60#define UPSTREAM_START_AUDIO 702 60#define UPSTREAM_START_AUDIO 702
@@ -80,19 +80,8 @@ extern struct sram_channel *channel7;
80extern struct sram_channel *channel9; 80extern struct sram_channel *channel9;
81extern struct sram_channel *channel10; 81extern struct sram_channel *channel10;
82extern struct sram_channel *channel11; 82extern struct sram_channel *channel11;
83extern struct video_device cx25821_video_template0;
84extern struct video_device cx25821_video_template1;
85extern struct video_device cx25821_video_template2;
86extern struct video_device cx25821_video_template3;
87extern struct video_device cx25821_video_template4;
88extern struct video_device cx25821_video_template5;
89extern struct video_device cx25821_video_template6;
90extern struct video_device cx25821_video_template7;
91extern struct video_device cx25821_video_template9;
92extern struct video_device cx25821_video_template10;
93extern struct video_device cx25821_video_template11;
94extern struct video_device cx25821_videoioctl_template; 83extern struct video_device cx25821_videoioctl_template;
95//extern const u32 *ctrl_classes[]; 84/* extern const u32 *ctrl_classes[]; */
96 85
97extern unsigned int vid_limit; 86extern unsigned int vid_limit;
98 87
@@ -113,7 +102,7 @@ extern int cx25821_set_tvnorm(struct cx25821_dev *dev, v4l2_std_id norm);
113extern int cx25821_res_get(struct cx25821_dev *dev, struct cx25821_fh *fh, 102extern int cx25821_res_get(struct cx25821_dev *dev, struct cx25821_fh *fh,
114 unsigned int bit); 103 unsigned int bit);
115extern int cx25821_res_check(struct cx25821_fh *fh, unsigned int bit); 104extern int cx25821_res_check(struct cx25821_fh *fh, unsigned int bit);
116extern int cx25821_res_locked(struct cx25821_dev *dev, unsigned int bit); 105extern int cx25821_res_locked(struct cx25821_fh *fh, unsigned int bit);
117extern void cx25821_res_free(struct cx25821_dev *dev, struct cx25821_fh *fh, 106extern void cx25821_res_free(struct cx25821_dev *dev, struct cx25821_fh *fh,
118 unsigned int bits); 107 unsigned int bits);
119extern int cx25821_video_mux(struct cx25821_dev *dev, unsigned int input); 108extern int cx25821_video_mux(struct cx25821_dev *dev, unsigned int input);
@@ -126,8 +115,7 @@ extern int cx25821_set_scale(struct cx25821_dev *dev, unsigned int width,
126 unsigned int height, enum v4l2_field field); 115 unsigned int height, enum v4l2_field field);
127extern int cx25821_video_irq(struct cx25821_dev *dev, int chan_num, u32 status); 116extern int cx25821_video_irq(struct cx25821_dev *dev, int chan_num, u32 status);
128extern void cx25821_video_unregister(struct cx25821_dev *dev, int chan_num); 117extern void cx25821_video_unregister(struct cx25821_dev *dev, int chan_num);
129extern int cx25821_video_register(struct cx25821_dev *dev, int chan_num, 118extern int cx25821_video_register(struct cx25821_dev *dev);
130 struct video_device *video_template);
131extern int cx25821_get_format_size(void); 119extern int cx25821_get_format_size(void);
132 120
133extern int cx25821_buffer_setup(struct videobuf_queue *q, unsigned int *count, 121extern int cx25821_buffer_setup(struct videobuf_queue *q, unsigned int *count,
diff --git a/drivers/staging/cx25821/cx25821-video0.c b/drivers/staging/cx25821/cx25821-video0.c
deleted file mode 100644
index 0be2cc15d856..000000000000
--- a/drivers/staging/cx25821/cx25821-video0.c
+++ /dev/null
@@ -1,434 +0,0 @@
1/*
2 * Driver for the Conexant CX25821 PCIe bridge
3 *
4 * Copyright (C) 2009 Conexant Systems Inc.
5 * Authors <shu.lin@conexant.com>, <hiep.huynh@conexant.com>
6 * Based on Steven Toth <stoth@linuxtv.org> cx23885 driver
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 *
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#include "cx25821-video.h"
25
26static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
27{
28 struct cx25821_buffer *buf =
29 container_of(vb, struct cx25821_buffer, vb);
30 struct cx25821_buffer *prev;
31 struct cx25821_fh *fh = vq->priv_data;
32 struct cx25821_dev *dev = fh->dev;
33 struct cx25821_dmaqueue *q = &dev->vidq[SRAM_CH00];
34
35 /* add jump to stopper */
36 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
37 buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma);
38 buf->risc.jmp[2] = cpu_to_le32(0); /* bits 63-32 */
39
40 dprintk(2, "jmp to stopper (0x%x)\n", buf->risc.jmp[1]);
41
42 if (!list_empty(&q->queued)) {
43 list_add_tail(&buf->vb.queue, &q->queued);
44 buf->vb.state = VIDEOBUF_QUEUED;
45 dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf,
46 buf->vb.i);
47
48 } else if (list_empty(&q->active)) {
49 list_add_tail(&buf->vb.queue, &q->active);
50 cx25821_start_video_dma(dev, q, buf,
51 &dev->sram_channels[SRAM_CH00]);
52 buf->vb.state = VIDEOBUF_ACTIVE;
53 buf->count = q->count++;
54 mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
55 dprintk(2,
56 "[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
57 buf, buf->vb.i, buf->count, q->count);
58 } else {
59 prev =
60 list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
61 if (prev->vb.width == buf->vb.width
62 && prev->vb.height == buf->vb.height
63 && prev->fmt == buf->fmt) {
64 list_add_tail(&buf->vb.queue, &q->active);
65 buf->vb.state = VIDEOBUF_ACTIVE;
66 buf->count = q->count++;
67 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
68
69 /* 64 bit bits 63-32 */
70 prev->risc.jmp[2] = cpu_to_le32(0);
71 dprintk(2,
72 "[%p/%d] buffer_queue - append to active, buf->count=%d\n",
73 buf, buf->vb.i, buf->count);
74
75 } else {
76 list_add_tail(&buf->vb.queue, &q->queued);
77 buf->vb.state = VIDEOBUF_QUEUED;
78 dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf,
79 buf->vb.i);
80 }
81 }
82
83 if (list_empty(&q->active)) {
84 dprintk(2, "active queue empty!\n");
85 }
86}
87
88static struct videobuf_queue_ops cx25821_video_qops = {
89 .buf_setup = cx25821_buffer_setup,
90 .buf_prepare = cx25821_buffer_prepare,
91 .buf_queue = buffer_queue,
92 .buf_release = cx25821_buffer_release,
93};
94
95static int video_open(struct file *file)
96{
97 struct video_device *vdev = video_devdata(file);
98 struct cx25821_dev *dev = video_drvdata(file);
99 struct cx25821_fh *fh;
100 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
101 u32 pix_format;
102
103 printk("open dev=%s type=%s\n", video_device_node_name(vdev),
104 v4l2_type_names[type]);
105
106 /* allocate + initialize per filehandle data */
107 fh = kzalloc(sizeof(*fh), GFP_KERNEL);
108 if (NULL == fh)
109 return -ENOMEM;
110
111 lock_kernel();
112
113 file->private_data = fh;
114 fh->dev = dev;
115 fh->type = type;
116 fh->width = 720;
117
118 if (dev->tvnorm & V4L2_STD_PAL_BG || dev->tvnorm & V4L2_STD_PAL_DK)
119 fh->height = 576;
120 else
121 fh->height = 480;
122
123 dev->channel_opened = SRAM_CH00;
124 pix_format =
125 (dev->pixel_formats[dev->channel_opened] ==
126 PIXEL_FRMT_411) ? V4L2_PIX_FMT_Y41P : V4L2_PIX_FMT_YUYV;
127 fh->fmt = format_by_fourcc(pix_format);
128
129 v4l2_prio_open(&dev->prio, &fh->prio);
130
131 videobuf_queue_sg_init(&fh->vidq, &cx25821_video_qops,
132 &dev->pci->dev, &dev->slock,
133 V4L2_BUF_TYPE_VIDEO_CAPTURE,
134 V4L2_FIELD_INTERLACED,
135 sizeof(struct cx25821_buffer), fh);
136
137 dprintk(1, "post videobuf_queue_init()\n");
138 unlock_kernel();
139
140 return 0;
141}
142
143static ssize_t video_read(struct file *file, char __user * data, size_t count,
144 loff_t * ppos)
145{
146 struct cx25821_fh *fh = file->private_data;
147
148 switch (fh->type) {
149 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
150 if (cx25821_res_locked(fh->dev, RESOURCE_VIDEO0))
151 return -EBUSY;
152
153 return videobuf_read_one(&fh->vidq, data, count, ppos,
154 file->f_flags & O_NONBLOCK);
155
156 default:
157 BUG();
158 return 0;
159 }
160}
161
162static unsigned int video_poll(struct file *file,
163 struct poll_table_struct *wait)
164{
165 struct cx25821_fh *fh = file->private_data;
166 struct cx25821_buffer *buf;
167
168 if (cx25821_res_check(fh, RESOURCE_VIDEO0)) {
169 /* streaming capture */
170 if (list_empty(&fh->vidq.stream))
171 return POLLERR;
172 buf = list_entry(fh->vidq.stream.next,
173 struct cx25821_buffer, vb.stream);
174 } else {
175 /* read() capture */
176 buf = (struct cx25821_buffer *)fh->vidq.read_buf;
177 if (NULL == buf)
178 return POLLERR;
179 }
180
181 poll_wait(file, &buf->vb.done, wait);
182 if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR) {
183 if (buf->vb.state == VIDEOBUF_DONE) {
184 struct cx25821_dev *dev = fh->dev;
185
186 if (dev && dev->use_cif_resolution[SRAM_CH00]) {
187 u8 cam_id = *((char *)buf->vb.baddr + 3);
188 memcpy((char *)buf->vb.baddr,
189 (char *)buf->vb.baddr + (fh->width * 2),
190 (fh->width * 2));
191 *((char *)buf->vb.baddr + 3) = cam_id;
192 }
193 }
194
195 return POLLIN | POLLRDNORM;
196 }
197
198 return 0;
199}
200
201static int video_release(struct file *file)
202{
203 struct cx25821_fh *fh = file->private_data;
204 struct cx25821_dev *dev = fh->dev;
205
206 //stop the risc engine and fifo
207 cx_write(channel0->dma_ctl, 0); /* FIFO and RISC disable */
208
209 /* stop video capture */
210 if (cx25821_res_check(fh, RESOURCE_VIDEO0)) {
211 videobuf_queue_cancel(&fh->vidq);
212 cx25821_res_free(dev, fh, RESOURCE_VIDEO0);
213 }
214
215 if (fh->vidq.read_buf) {
216 cx25821_buffer_release(&fh->vidq, fh->vidq.read_buf);
217 kfree(fh->vidq.read_buf);
218 }
219
220 videobuf_mmap_free(&fh->vidq);
221
222 v4l2_prio_close(&dev->prio, fh->prio);
223 file->private_data = NULL;
224 kfree(fh);
225
226 return 0;
227}
228
229static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
230{
231 struct cx25821_fh *fh = priv;
232 struct cx25821_dev *dev = fh->dev;
233
234 if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)) {
235 return -EINVAL;
236 }
237
238 if (unlikely(i != fh->type)) {
239 return -EINVAL;
240 }
241
242 if (unlikely(!cx25821_res_get(dev, fh, cx25821_get_resource(fh, RESOURCE_VIDEO0)))) {
243 return -EBUSY;
244 }
245
246 return videobuf_streamon(get_queue(fh));
247}
248
249static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
250{
251 struct cx25821_fh *fh = priv;
252 struct cx25821_dev *dev = fh->dev;
253 int err, res;
254
255 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
256 return -EINVAL;
257 if (i != fh->type)
258 return -EINVAL;
259
260 res = cx25821_get_resource(fh, RESOURCE_VIDEO0);
261 err = videobuf_streamoff(get_queue(fh));
262 if (err < 0)
263 return err;
264 cx25821_res_free(dev, fh, res);
265 return 0;
266}
267
268static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
269 struct v4l2_format *f)
270{
271 struct cx25821_fh *fh = priv;
272 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
273 int err;
274 int pix_format = PIXEL_FRMT_422;
275
276 if (fh) {
277 err = v4l2_prio_check(&dev->prio, fh->prio);
278 if (0 != err)
279 return err;
280 }
281
282 dprintk(2, "%s()\n", __func__);
283 err = cx25821_vidioc_try_fmt_vid_cap(file, priv, f);
284
285 if (0 != err)
286 return err;
287
288 fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat);
289 fh->vidq.field = f->fmt.pix.field;
290
291 // check if width and height is valid based on set standard
292 if (cx25821_is_valid_width(f->fmt.pix.width, dev->tvnorm)) {
293 fh->width = f->fmt.pix.width;
294 }
295
296 if (cx25821_is_valid_height(f->fmt.pix.height, dev->tvnorm)) {
297 fh->height = f->fmt.pix.height;
298 }
299
300 if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_Y41P)
301 pix_format = PIXEL_FRMT_411;
302 else if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_YUYV)
303 pix_format = PIXEL_FRMT_422;
304 else
305 return -EINVAL;
306
307 cx25821_set_pixel_format(dev, SRAM_CH00, pix_format);
308
309 // check if cif resolution
310 if (fh->width == 320 || fh->width == 352) {
311 dev->use_cif_resolution[SRAM_CH00] = 1;
312 } else {
313 dev->use_cif_resolution[SRAM_CH00] = 0;
314 }
315 dev->cif_width[SRAM_CH00] = fh->width;
316 medusa_set_resolution(dev, fh->width, SRAM_CH00);
317
318 dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width,
319 fh->height, fh->vidq.field);
320 cx25821_call_all(dev, video, s_fmt, f);
321
322 return 0;
323}
324
325static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
326{
327 int ret_val = 0;
328 struct cx25821_fh *fh = priv;
329 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
330
331 ret_val = videobuf_dqbuf(get_queue(fh), p, file->f_flags & O_NONBLOCK);
332
333 p->sequence = dev->vidq[SRAM_CH00].count;
334
335 return ret_val;
336}
337
338static int vidioc_log_status(struct file *file, void *priv)
339{
340 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
341 char name[32 + 2];
342
343 struct sram_channel *sram_ch = &dev->sram_channels[SRAM_CH00];
344 u32 tmp = 0;
345
346 snprintf(name, sizeof(name), "%s/2", dev->name);
347 printk(KERN_INFO "%s/2: ============ START LOG STATUS ============\n",
348 dev->name);
349 cx25821_call_all(dev, core, log_status);
350 tmp = cx_read(sram_ch->dma_ctl);
351 printk(KERN_INFO "Video input 0 is %s\n",
352 (tmp & 0x11) ? "streaming" : "stopped");
353 printk(KERN_INFO "%s/2: ============= END LOG STATUS =============\n",
354 dev->name);
355 return 0;
356}
357
358static int vidioc_s_ctrl(struct file *file, void *priv,
359 struct v4l2_control *ctl)
360{
361 struct cx25821_fh *fh = priv;
362 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
363 int err;
364
365 if (fh) {
366 err = v4l2_prio_check(&dev->prio, fh->prio);
367 if (0 != err)
368 return err;
369 }
370
371 return cx25821_set_control(dev, ctl, SRAM_CH00);
372}
373
374// exported stuff
375static const struct v4l2_file_operations video_fops = {
376 .owner = THIS_MODULE,
377 .open = video_open,
378 .release = video_release,
379 .read = video_read,
380 .poll = video_poll,
381 .mmap = cx25821_video_mmap,
382 .ioctl = video_ioctl2,
383};
384
385static const struct v4l2_ioctl_ops video_ioctl_ops = {
386 .vidioc_querycap = cx25821_vidioc_querycap,
387 .vidioc_enum_fmt_vid_cap = cx25821_vidioc_enum_fmt_vid_cap,
388 .vidioc_g_fmt_vid_cap = cx25821_vidioc_g_fmt_vid_cap,
389 .vidioc_try_fmt_vid_cap = cx25821_vidioc_try_fmt_vid_cap,
390 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
391 .vidioc_reqbufs = cx25821_vidioc_reqbufs,
392 .vidioc_querybuf = cx25821_vidioc_querybuf,
393 .vidioc_qbuf = cx25821_vidioc_qbuf,
394 .vidioc_dqbuf = vidioc_dqbuf,
395#ifdef TUNER_FLAG
396 .vidioc_s_std = cx25821_vidioc_s_std,
397 .vidioc_querystd = cx25821_vidioc_querystd,
398#endif
399 .vidioc_cropcap = cx25821_vidioc_cropcap,
400 .vidioc_s_crop = cx25821_vidioc_s_crop,
401 .vidioc_g_crop = cx25821_vidioc_g_crop,
402 .vidioc_enum_input = cx25821_vidioc_enum_input,
403 .vidioc_g_input = cx25821_vidioc_g_input,
404 .vidioc_s_input = cx25821_vidioc_s_input,
405 .vidioc_g_ctrl = cx25821_vidioc_g_ctrl,
406 .vidioc_s_ctrl = vidioc_s_ctrl,
407 .vidioc_queryctrl = cx25821_vidioc_queryctrl,
408 .vidioc_streamon = vidioc_streamon,
409 .vidioc_streamoff = vidioc_streamoff,
410 .vidioc_log_status = vidioc_log_status,
411 .vidioc_g_priority = cx25821_vidioc_g_priority,
412 .vidioc_s_priority = cx25821_vidioc_s_priority,
413#ifdef CONFIG_VIDEO_V4L1_COMPAT
414 .vidiocgmbuf = cx25821_vidiocgmbuf,
415#endif
416#ifdef TUNER_FLAG
417 .vidioc_g_tuner = cx25821_vidioc_g_tuner,
418 .vidioc_s_tuner = cx25821_vidioc_s_tuner,
419 .vidioc_g_frequency = cx25821_vidioc_g_frequency,
420 .vidioc_s_frequency = cx25821_vidioc_s_frequency,
421#endif
422#ifdef CONFIG_VIDEO_ADV_DEBUG
423 .vidioc_g_register = cx25821_vidioc_g_register,
424 .vidioc_s_register = cx25821_vidioc_s_register,
425#endif
426};
427
428struct video_device cx25821_video_template0 = {
429 .name = "cx25821-video",
430 .fops = &video_fops,
431 .ioctl_ops = &video_ioctl_ops,
432 .tvnorms = CX25821_NORMS,
433 .current_norm = V4L2_STD_NTSC_M,
434};
diff --git a/drivers/staging/cx25821/cx25821-video1.c b/drivers/staging/cx25821/cx25821-video1.c
deleted file mode 100644
index b0bae627bfb1..000000000000
--- a/drivers/staging/cx25821/cx25821-video1.c
+++ /dev/null
@@ -1,434 +0,0 @@
1/*
2 * Driver for the Conexant CX25821 PCIe bridge
3 *
4 * Copyright (C) 2009 Conexant Systems Inc.
5 * Authors <shu.lin@conexant.com>, <hiep.huynh@conexant.com>
6 * Based on Steven Toth <stoth@linuxtv.org> cx23885 driver
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 *
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#include "cx25821-video.h"
25
26static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
27{
28 struct cx25821_buffer *buf =
29 container_of(vb, struct cx25821_buffer, vb);
30 struct cx25821_buffer *prev;
31 struct cx25821_fh *fh = vq->priv_data;
32 struct cx25821_dev *dev = fh->dev;
33 struct cx25821_dmaqueue *q = &dev->vidq[SRAM_CH01];
34
35 /* add jump to stopper */
36 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
37 buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma);
38 buf->risc.jmp[2] = cpu_to_le32(0); /* bits 63-32 */
39
40 dprintk(2, "jmp to stopper (0x%x)\n", buf->risc.jmp[1]);
41
42 if (!list_empty(&q->queued)) {
43 list_add_tail(&buf->vb.queue, &q->queued);
44 buf->vb.state = VIDEOBUF_QUEUED;
45 dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf,
46 buf->vb.i);
47
48 } else if (list_empty(&q->active)) {
49 list_add_tail(&buf->vb.queue, &q->active);
50 cx25821_start_video_dma(dev, q, buf,
51 &dev->sram_channels[SRAM_CH01]);
52 buf->vb.state = VIDEOBUF_ACTIVE;
53 buf->count = q->count++;
54 mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
55 dprintk(2,
56 "[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
57 buf, buf->vb.i, buf->count, q->count);
58 } else {
59 prev =
60 list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
61 if (prev->vb.width == buf->vb.width
62 && prev->vb.height == buf->vb.height
63 && prev->fmt == buf->fmt) {
64 list_add_tail(&buf->vb.queue, &q->active);
65 buf->vb.state = VIDEOBUF_ACTIVE;
66 buf->count = q->count++;
67 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
68
69 /* 64 bit bits 63-32 */
70 prev->risc.jmp[2] = cpu_to_le32(0);
71 dprintk(2,
72 "[%p/%d] buffer_queue - append to active, buf->count=%d\n",
73 buf, buf->vb.i, buf->count);
74
75 } else {
76 list_add_tail(&buf->vb.queue, &q->queued);
77 buf->vb.state = VIDEOBUF_QUEUED;
78 dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf,
79 buf->vb.i);
80 }
81 }
82
83 if (list_empty(&q->active)) {
84 dprintk(2, "active queue empty!\n");
85 }
86}
87
88static struct videobuf_queue_ops cx25821_video_qops = {
89 .buf_setup = cx25821_buffer_setup,
90 .buf_prepare = cx25821_buffer_prepare,
91 .buf_queue = buffer_queue,
92 .buf_release = cx25821_buffer_release,
93};
94
95static int video_open(struct file *file)
96{
97 struct video_device *vdev = video_devdata(file);
98 struct cx25821_dev *dev = video_drvdata(file);
99 struct cx25821_fh *fh;
100 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
101 u32 pix_format;
102
103 printk("open dev=%s type=%s\n", video_device_node_name(vdev),
104 v4l2_type_names[type]);
105
106 /* allocate + initialize per filehandle data */
107 fh = kzalloc(sizeof(*fh), GFP_KERNEL);
108 if (NULL == fh)
109 return -ENOMEM;
110
111 lock_kernel();
112
113 file->private_data = fh;
114 fh->dev = dev;
115 fh->type = type;
116 fh->width = 720;
117
118 if (dev->tvnorm & V4L2_STD_PAL_BG || dev->tvnorm & V4L2_STD_PAL_DK)
119 fh->height = 576;
120 else
121 fh->height = 480;
122
123 dev->channel_opened = SRAM_CH01;
124 pix_format =
125 (dev->pixel_formats[dev->channel_opened] ==
126 PIXEL_FRMT_411) ? V4L2_PIX_FMT_Y41P : V4L2_PIX_FMT_YUYV;
127 fh->fmt = format_by_fourcc(pix_format);
128
129 v4l2_prio_open(&dev->prio, &fh->prio);
130
131 videobuf_queue_sg_init(&fh->vidq, &cx25821_video_qops,
132 &dev->pci->dev, &dev->slock,
133 V4L2_BUF_TYPE_VIDEO_CAPTURE,
134 V4L2_FIELD_INTERLACED,
135 sizeof(struct cx25821_buffer), fh);
136
137 dprintk(1, "post videobuf_queue_init()\n");
138 unlock_kernel();
139
140 return 0;
141}
142
143static ssize_t video_read(struct file *file, char __user * data, size_t count,
144 loff_t * ppos)
145{
146 struct cx25821_fh *fh = file->private_data;
147
148 switch (fh->type) {
149 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
150 if (cx25821_res_locked(fh->dev, RESOURCE_VIDEO1))
151 return -EBUSY;
152
153 return videobuf_read_one(&fh->vidq, data, count, ppos,
154 file->f_flags & O_NONBLOCK);
155
156 default:
157 BUG();
158 return 0;
159 }
160}
161
162static unsigned int video_poll(struct file *file,
163 struct poll_table_struct *wait)
164{
165 struct cx25821_fh *fh = file->private_data;
166 struct cx25821_buffer *buf;
167
168 if (cx25821_res_check(fh, RESOURCE_VIDEO1)) {
169 /* streaming capture */
170 if (list_empty(&fh->vidq.stream))
171 return POLLERR;
172 buf = list_entry(fh->vidq.stream.next,
173 struct cx25821_buffer, vb.stream);
174 } else {
175 /* read() capture */
176 buf = (struct cx25821_buffer *)fh->vidq.read_buf;
177 if (NULL == buf)
178 return POLLERR;
179 }
180
181 poll_wait(file, &buf->vb.done, wait);
182 if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR) {
183 if (buf->vb.state == VIDEOBUF_DONE) {
184 struct cx25821_dev *dev = fh->dev;
185
186 if (dev && dev->use_cif_resolution[SRAM_CH01]) {
187 u8 cam_id = *((char *)buf->vb.baddr + 3);
188 memcpy((char *)buf->vb.baddr,
189 (char *)buf->vb.baddr + (fh->width * 2),
190 (fh->width * 2));
191 *((char *)buf->vb.baddr + 3) = cam_id;
192 }
193 }
194
195 return POLLIN | POLLRDNORM;
196 }
197
198 return 0;
199}
200
201static int video_release(struct file *file)
202{
203 struct cx25821_fh *fh = file->private_data;
204 struct cx25821_dev *dev = fh->dev;
205
206 //stop the risc engine and fifo
207 cx_write(channel1->dma_ctl, 0); /* FIFO and RISC disable */
208
209 /* stop video capture */
210 if (cx25821_res_check(fh, RESOURCE_VIDEO1)) {
211 videobuf_queue_cancel(&fh->vidq);
212 cx25821_res_free(dev, fh, RESOURCE_VIDEO1);
213 }
214
215 if (fh->vidq.read_buf) {
216 cx25821_buffer_release(&fh->vidq, fh->vidq.read_buf);
217 kfree(fh->vidq.read_buf);
218 }
219
220 videobuf_mmap_free(&fh->vidq);
221
222 v4l2_prio_close(&dev->prio, fh->prio);
223 file->private_data = NULL;
224 kfree(fh);
225
226 return 0;
227}
228
229static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
230{
231 struct cx25821_fh *fh = priv;
232 struct cx25821_dev *dev = fh->dev;
233
234 if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)) {
235 return -EINVAL;
236 }
237
238 if (unlikely(i != fh->type)) {
239 return -EINVAL;
240 }
241
242 if (unlikely(!cx25821_res_get(dev, fh, cx25821_get_resource(fh, RESOURCE_VIDEO1)))) {
243 return -EBUSY;
244 }
245
246 return videobuf_streamon(get_queue(fh));
247}
248
249static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
250{
251 struct cx25821_fh *fh = priv;
252 struct cx25821_dev *dev = fh->dev;
253 int err, res;
254
255 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
256 return -EINVAL;
257 if (i != fh->type)
258 return -EINVAL;
259
260 res = cx25821_get_resource(fh, RESOURCE_VIDEO1);
261 err = videobuf_streamoff(get_queue(fh));
262 if (err < 0)
263 return err;
264 cx25821_res_free(dev, fh, res);
265 return 0;
266}
267
268static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
269 struct v4l2_format *f)
270{
271 struct cx25821_fh *fh = priv;
272 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
273 int err;
274 int pix_format = 0;
275
276 if (fh) {
277 err = v4l2_prio_check(&dev->prio, fh->prio);
278 if (0 != err)
279 return err;
280 }
281
282 dprintk(2, "%s()\n", __func__);
283 err = cx25821_vidioc_try_fmt_vid_cap(file, priv, f);
284
285 if (0 != err)
286 return err;
287
288 fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat);
289 fh->vidq.field = f->fmt.pix.field;
290
291 // check if width and height is valid based on set standard
292 if (cx25821_is_valid_width(f->fmt.pix.width, dev->tvnorm)) {
293 fh->width = f->fmt.pix.width;
294 }
295
296 if (cx25821_is_valid_height(f->fmt.pix.height, dev->tvnorm)) {
297 fh->height = f->fmt.pix.height;
298 }
299
300 if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_Y41P)
301 pix_format = PIXEL_FRMT_411;
302 else if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_YUYV)
303 pix_format = PIXEL_FRMT_422;
304 else
305 return -EINVAL;
306
307 cx25821_set_pixel_format(dev, SRAM_CH01, pix_format);
308
309 // check if cif resolution
310 if (fh->width == 320 || fh->width == 352) {
311 dev->use_cif_resolution[SRAM_CH01] = 1;
312 } else {
313 dev->use_cif_resolution[SRAM_CH01] = 0;
314 }
315 dev->cif_width[SRAM_CH01] = fh->width;
316 medusa_set_resolution(dev, fh->width, SRAM_CH01);
317
318 dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width,
319 fh->height, fh->vidq.field);
320 cx25821_call_all(dev, video, s_fmt, f);
321
322 return 0;
323}
324
325static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
326{
327 int ret_val = 0;
328 struct cx25821_fh *fh = priv;
329 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
330
331 ret_val = videobuf_dqbuf(get_queue(fh), p, file->f_flags & O_NONBLOCK);
332
333 p->sequence = dev->vidq[SRAM_CH01].count;
334
335 return ret_val;
336}
337
338static int vidioc_log_status(struct file *file, void *priv)
339{
340 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
341 char name[32 + 2];
342
343 struct sram_channel *sram_ch = &dev->sram_channels[SRAM_CH01];
344 u32 tmp = 0;
345
346 snprintf(name, sizeof(name), "%s/2", dev->name);
347 printk(KERN_INFO "%s/2: ============ START LOG STATUS ============\n",
348 dev->name);
349 cx25821_call_all(dev, core, log_status);
350 tmp = cx_read(sram_ch->dma_ctl);
351 printk(KERN_INFO "Video input 1 is %s\n",
352 (tmp & 0x11) ? "streaming" : "stopped");
353 printk(KERN_INFO "%s/2: ============= END LOG STATUS =============\n",
354 dev->name);
355 return 0;
356}
357
358static int vidioc_s_ctrl(struct file *file, void *priv,
359 struct v4l2_control *ctl)
360{
361 struct cx25821_fh *fh = priv;
362 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
363 int err;
364
365 if (fh) {
366 err = v4l2_prio_check(&dev->prio, fh->prio);
367 if (0 != err)
368 return err;
369 }
370
371 return cx25821_set_control(dev, ctl, SRAM_CH01);
372}
373
374//exported stuff
375static const struct v4l2_file_operations video_fops = {
376 .owner = THIS_MODULE,
377 .open = video_open,
378 .release = video_release,
379 .read = video_read,
380 .poll = video_poll,
381 .mmap = cx25821_video_mmap,
382 .ioctl = video_ioctl2,
383};
384
385static const struct v4l2_ioctl_ops video_ioctl_ops = {
386 .vidioc_querycap = cx25821_vidioc_querycap,
387 .vidioc_enum_fmt_vid_cap = cx25821_vidioc_enum_fmt_vid_cap,
388 .vidioc_g_fmt_vid_cap = cx25821_vidioc_g_fmt_vid_cap,
389 .vidioc_try_fmt_vid_cap = cx25821_vidioc_try_fmt_vid_cap,
390 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
391 .vidioc_reqbufs = cx25821_vidioc_reqbufs,
392 .vidioc_querybuf = cx25821_vidioc_querybuf,
393 .vidioc_qbuf = cx25821_vidioc_qbuf,
394 .vidioc_dqbuf = vidioc_dqbuf,
395#ifdef TUNER_FLAG
396 .vidioc_s_std = cx25821_vidioc_s_std,
397 .vidioc_querystd = cx25821_vidioc_querystd,
398#endif
399 .vidioc_cropcap = cx25821_vidioc_cropcap,
400 .vidioc_s_crop = cx25821_vidioc_s_crop,
401 .vidioc_g_crop = cx25821_vidioc_g_crop,
402 .vidioc_enum_input = cx25821_vidioc_enum_input,
403 .vidioc_g_input = cx25821_vidioc_g_input,
404 .vidioc_s_input = cx25821_vidioc_s_input,
405 .vidioc_g_ctrl = cx25821_vidioc_g_ctrl,
406 .vidioc_s_ctrl = vidioc_s_ctrl,
407 .vidioc_queryctrl = cx25821_vidioc_queryctrl,
408 .vidioc_streamon = vidioc_streamon,
409 .vidioc_streamoff = vidioc_streamoff,
410 .vidioc_log_status = vidioc_log_status,
411 .vidioc_g_priority = cx25821_vidioc_g_priority,
412 .vidioc_s_priority = cx25821_vidioc_s_priority,
413#ifdef CONFIG_VIDEO_V4L1_COMPAT
414 .vidiocgmbuf = cx25821_vidiocgmbuf,
415#endif
416#ifdef TUNER_FLAG
417 .vidioc_g_tuner = cx25821_vidioc_g_tuner,
418 .vidioc_s_tuner = cx25821_vidioc_s_tuner,
419 .vidioc_g_frequency = cx25821_vidioc_g_frequency,
420 .vidioc_s_frequency = cx25821_vidioc_s_frequency,
421#endif
422#ifdef CONFIG_VIDEO_ADV_DEBUG
423 .vidioc_g_register = cx25821_vidioc_g_register,
424 .vidioc_s_register = cx25821_vidioc_s_register,
425#endif
426};
427
428struct video_device cx25821_video_template1 = {
429 .name = "cx25821-video",
430 .fops = &video_fops,
431 .ioctl_ops = &video_ioctl_ops,
432 .tvnorms = CX25821_NORMS,
433 .current_norm = V4L2_STD_NTSC_M,
434};
diff --git a/drivers/staging/cx25821/cx25821-video2.c b/drivers/staging/cx25821/cx25821-video2.c
deleted file mode 100644
index 400cdb80674e..000000000000
--- a/drivers/staging/cx25821/cx25821-video2.c
+++ /dev/null
@@ -1,436 +0,0 @@
1/*
2 * Driver for the Conexant CX25821 PCIe bridge
3 *
4 * Copyright (C) 2009 Conexant Systems Inc.
5 * Authors <shu.lin@conexant.com>, <hiep.huynh@conexant.com>
6 * Based on Steven Toth <stoth@linuxtv.org> cx23885 driver
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 *
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#include "cx25821-video.h"
25
26static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
27{
28 struct cx25821_buffer *buf =
29 container_of(vb, struct cx25821_buffer, vb);
30 struct cx25821_buffer *prev;
31 struct cx25821_fh *fh = vq->priv_data;
32 struct cx25821_dev *dev = fh->dev;
33 struct cx25821_dmaqueue *q = &dev->vidq[SRAM_CH02];
34
35 /* add jump to stopper */
36 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
37 buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma);
38 buf->risc.jmp[2] = cpu_to_le32(0); /* bits 63-32 */
39
40 dprintk(2, "jmp to stopper (0x%x)\n", buf->risc.jmp[1]);
41
42 if (!list_empty(&q->queued)) {
43 list_add_tail(&buf->vb.queue, &q->queued);
44 buf->vb.state = VIDEOBUF_QUEUED;
45 dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf,
46 buf->vb.i);
47
48 } else if (list_empty(&q->active)) {
49 list_add_tail(&buf->vb.queue, &q->active);
50 cx25821_start_video_dma(dev, q, buf,
51 &dev->sram_channels[SRAM_CH02]);
52 buf->vb.state = VIDEOBUF_ACTIVE;
53 buf->count = q->count++;
54 mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
55 dprintk(2,
56 "[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
57 buf, buf->vb.i, buf->count, q->count);
58 } else {
59 prev =
60 list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
61 if (prev->vb.width == buf->vb.width
62 && prev->vb.height == buf->vb.height
63 && prev->fmt == buf->fmt) {
64 list_add_tail(&buf->vb.queue, &q->active);
65 buf->vb.state = VIDEOBUF_ACTIVE;
66 buf->count = q->count++;
67 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
68
69 /* 64 bit bits 63-32 */
70 prev->risc.jmp[2] = cpu_to_le32(0);
71 dprintk(2,
72 "[%p/%d] buffer_queue - append to active, buf->count=%d\n",
73 buf, buf->vb.i, buf->count);
74
75 } else {
76 list_add_tail(&buf->vb.queue, &q->queued);
77 buf->vb.state = VIDEOBUF_QUEUED;
78 dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf,
79 buf->vb.i);
80 }
81 }
82
83 if (list_empty(&q->active)) {
84 dprintk(2, "active queue empty!\n");
85 }
86}
87
88static struct videobuf_queue_ops cx25821_video_qops = {
89 .buf_setup = cx25821_buffer_setup,
90 .buf_prepare = cx25821_buffer_prepare,
91 .buf_queue = buffer_queue,
92 .buf_release = cx25821_buffer_release,
93};
94
95static int video_open(struct file *file)
96{
97 struct video_device *vdev = video_devdata(file);
98 struct cx25821_dev *dev = video_drvdata(file);
99 struct cx25821_fh *fh;
100 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
101 u32 pix_format;
102
103 printk("open dev=%s type=%s\n", video_device_node_name(vdev),
104 v4l2_type_names[type]);
105
106 /* allocate + initialize per filehandle data */
107 fh = kzalloc(sizeof(*fh), GFP_KERNEL);
108 if (NULL == fh)
109 return -ENOMEM;
110
111 lock_kernel();
112
113 file->private_data = fh;
114 fh->dev = dev;
115 fh->type = type;
116 fh->width = 720;
117
118 if (dev->tvnorm & V4L2_STD_PAL_BG || dev->tvnorm & V4L2_STD_PAL_DK)
119 fh->height = 576;
120 else
121 fh->height = 480;
122
123 dev->channel_opened = SRAM_CH02;
124 pix_format =
125 (dev->pixel_formats[dev->channel_opened] ==
126 PIXEL_FRMT_411) ? V4L2_PIX_FMT_Y41P : V4L2_PIX_FMT_YUYV;
127 fh->fmt = format_by_fourcc(pix_format);
128
129 v4l2_prio_open(&dev->prio, &fh->prio);
130
131 videobuf_queue_sg_init(&fh->vidq, &cx25821_video_qops,
132 &dev->pci->dev, &dev->slock,
133 V4L2_BUF_TYPE_VIDEO_CAPTURE,
134 V4L2_FIELD_INTERLACED,
135 sizeof(struct cx25821_buffer), fh);
136
137 dprintk(1, "post videobuf_queue_init()\n");
138 unlock_kernel();
139
140 return 0;
141}
142
143static ssize_t video_read(struct file *file, char __user * data, size_t count,
144 loff_t * ppos)
145{
146 struct cx25821_fh *fh = file->private_data;
147
148 switch (fh->type) {
149 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
150 if (cx25821_res_locked(fh->dev, RESOURCE_VIDEO2))
151 return -EBUSY;
152
153 return videobuf_read_one(&fh->vidq, data, count, ppos,
154 file->f_flags & O_NONBLOCK);
155
156 default:
157 BUG();
158 return 0;
159 }
160}
161
162static unsigned int video_poll(struct file *file,
163 struct poll_table_struct *wait)
164{
165 struct cx25821_fh *fh = file->private_data;
166 struct cx25821_buffer *buf;
167
168 if (cx25821_res_check(fh, RESOURCE_VIDEO2)) {
169 /* streaming capture */
170 if (list_empty(&fh->vidq.stream))
171 return POLLERR;
172 buf = list_entry(fh->vidq.stream.next,
173 struct cx25821_buffer, vb.stream);
174 } else {
175 /* read() capture */
176 buf = (struct cx25821_buffer *)fh->vidq.read_buf;
177 if (NULL == buf)
178 return POLLERR;
179 }
180
181 poll_wait(file, &buf->vb.done, wait);
182 if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR) {
183 if (buf->vb.state == VIDEOBUF_DONE) {
184 struct cx25821_dev *dev = fh->dev;
185
186 if (dev && dev->use_cif_resolution[SRAM_CH02]) {
187 u8 cam_id = *((char *)buf->vb.baddr + 3);
188 memcpy((char *)buf->vb.baddr,
189 (char *)buf->vb.baddr + (fh->width * 2),
190 (fh->width * 2));
191 *((char *)buf->vb.baddr + 3) = cam_id;
192 }
193 }
194
195 return POLLIN | POLLRDNORM;
196 }
197
198 return 0;
199}
200
201static int video_release(struct file *file)
202{
203 struct cx25821_fh *fh = file->private_data;
204 struct cx25821_dev *dev = fh->dev;
205
206 //stop the risc engine and fifo
207 cx_write(channel2->dma_ctl, 0); /* FIFO and RISC disable */
208
209 /* stop video capture */
210 if (cx25821_res_check(fh, RESOURCE_VIDEO2)) {
211 videobuf_queue_cancel(&fh->vidq);
212 cx25821_res_free(dev, fh, RESOURCE_VIDEO2);
213 }
214
215 if (fh->vidq.read_buf) {
216 cx25821_buffer_release(&fh->vidq, fh->vidq.read_buf);
217 kfree(fh->vidq.read_buf);
218 }
219
220 videobuf_mmap_free(&fh->vidq);
221
222 v4l2_prio_close(&dev->prio, fh->prio);
223 file->private_data = NULL;
224 kfree(fh);
225
226 return 0;
227}
228
229static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
230{
231 struct cx25821_fh *fh = priv;
232 struct cx25821_dev *dev = fh->dev;
233
234 if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)) {
235 return -EINVAL;
236 }
237
238 if (unlikely(i != fh->type)) {
239 return -EINVAL;
240 }
241
242 if (unlikely(!cx25821_res_get(dev, fh, cx25821_get_resource(fh, RESOURCE_VIDEO2)))) {
243 return -EBUSY;
244 }
245
246 return videobuf_streamon(get_queue(fh));
247}
248
249static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
250{
251 struct cx25821_fh *fh = priv;
252 struct cx25821_dev *dev = fh->dev;
253 int err, res;
254
255 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
256 return -EINVAL;
257 if (i != fh->type)
258 return -EINVAL;
259
260 res = cx25821_get_resource(fh, RESOURCE_VIDEO2);
261 err = videobuf_streamoff(get_queue(fh));
262 if (err < 0)
263 return err;
264 cx25821_res_free(dev, fh, res);
265 return 0;
266}
267
268static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
269 struct v4l2_format *f)
270{
271 struct cx25821_fh *fh = priv;
272 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
273 int err;
274 int pix_format = 0;
275
276 if (fh) {
277 err = v4l2_prio_check(&dev->prio, fh->prio);
278 if (0 != err)
279 return err;
280 }
281
282 dprintk(2, "%s()\n", __func__);
283 err = cx25821_vidioc_try_fmt_vid_cap(file, priv, f);
284
285 if (0 != err)
286 return err;
287
288 fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat);
289 fh->vidq.field = f->fmt.pix.field;
290
291 // check if width and height is valid based on set standard
292 if (cx25821_is_valid_width(f->fmt.pix.width, dev->tvnorm)) {
293 fh->width = f->fmt.pix.width;
294 }
295
296 if (cx25821_is_valid_height(f->fmt.pix.height, dev->tvnorm)) {
297 fh->height = f->fmt.pix.height;
298 }
299
300 if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_Y41P)
301 pix_format = PIXEL_FRMT_411;
302 else if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_YUYV)
303 pix_format = PIXEL_FRMT_422;
304 else
305 return -EINVAL;
306
307 cx25821_set_pixel_format(dev, SRAM_CH02, pix_format);
308
309 // check if cif resolution
310 if (fh->width == 320 || fh->width == 352) {
311 dev->use_cif_resolution[SRAM_CH02] = 1;
312 } else {
313 dev->use_cif_resolution[SRAM_CH02] = 0;
314 }
315 dev->cif_width[SRAM_CH02] = fh->width;
316 medusa_set_resolution(dev, fh->width, SRAM_CH02);
317
318 dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width,
319 fh->height, fh->vidq.field);
320 cx25821_call_all(dev, video, s_fmt, f);
321
322 return 0;
323}
324
325static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
326{
327 int ret_val = 0;
328 struct cx25821_fh *fh = priv;
329 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
330
331 ret_val = videobuf_dqbuf(get_queue(fh), p, file->f_flags & O_NONBLOCK);
332
333 p->sequence = dev->vidq[SRAM_CH02].count;
334
335 return ret_val;
336}
337
338static int vidioc_log_status(struct file *file, void *priv)
339{
340 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
341 char name[32 + 2];
342
343 struct sram_channel *sram_ch = &dev->sram_channels[SRAM_CH02];
344 u32 tmp = 0;
345
346 snprintf(name, sizeof(name), "%s/2", dev->name);
347 printk(KERN_INFO "%s/2: ============ START LOG STATUS ============\n",
348 dev->name);
349
350 cx25821_call_all(dev, core, log_status);
351
352 tmp = cx_read(sram_ch->dma_ctl);
353 printk(KERN_INFO "Video input 2 is %s\n",
354 (tmp & 0x11) ? "streaming" : "stopped");
355 printk(KERN_INFO "%s/2: ============= END LOG STATUS =============\n",
356 dev->name);
357 return 0;
358}
359
360static int vidioc_s_ctrl(struct file *file, void *priv,
361 struct v4l2_control *ctl)
362{
363 struct cx25821_fh *fh = priv;
364 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
365 int err;
366
367 if (fh) {
368 err = v4l2_prio_check(&dev->prio, fh->prio);
369 if (0 != err)
370 return err;
371 }
372
373 return cx25821_set_control(dev, ctl, SRAM_CH02);
374}
375
376// exported stuff
377static const struct v4l2_file_operations video_fops = {
378 .owner = THIS_MODULE,
379 .open = video_open,
380 .release = video_release,
381 .read = video_read,
382 .poll = video_poll,
383 .mmap = cx25821_video_mmap,
384 .ioctl = video_ioctl2,
385};
386
387static const struct v4l2_ioctl_ops video_ioctl_ops = {
388 .vidioc_querycap = cx25821_vidioc_querycap,
389 .vidioc_enum_fmt_vid_cap = cx25821_vidioc_enum_fmt_vid_cap,
390 .vidioc_g_fmt_vid_cap = cx25821_vidioc_g_fmt_vid_cap,
391 .vidioc_try_fmt_vid_cap = cx25821_vidioc_try_fmt_vid_cap,
392 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
393 .vidioc_reqbufs = cx25821_vidioc_reqbufs,
394 .vidioc_querybuf = cx25821_vidioc_querybuf,
395 .vidioc_qbuf = cx25821_vidioc_qbuf,
396 .vidioc_dqbuf = vidioc_dqbuf,
397#ifdef TUNER_FLAG
398 .vidioc_s_std = cx25821_vidioc_s_std,
399 .vidioc_querystd = cx25821_vidioc_querystd,
400#endif
401 .vidioc_cropcap = cx25821_vidioc_cropcap,
402 .vidioc_s_crop = cx25821_vidioc_s_crop,
403 .vidioc_g_crop = cx25821_vidioc_g_crop,
404 .vidioc_enum_input = cx25821_vidioc_enum_input,
405 .vidioc_g_input = cx25821_vidioc_g_input,
406 .vidioc_s_input = cx25821_vidioc_s_input,
407 .vidioc_g_ctrl = cx25821_vidioc_g_ctrl,
408 .vidioc_s_ctrl = vidioc_s_ctrl,
409 .vidioc_queryctrl = cx25821_vidioc_queryctrl,
410 .vidioc_streamon = vidioc_streamon,
411 .vidioc_streamoff = vidioc_streamoff,
412 .vidioc_log_status = vidioc_log_status,
413 .vidioc_g_priority = cx25821_vidioc_g_priority,
414 .vidioc_s_priority = cx25821_vidioc_s_priority,
415#ifdef CONFIG_VIDEO_V4L1_COMPAT
416 .vidiocgmbuf = cx25821_vidiocgmbuf,
417#endif
418#ifdef TUNER_FLAG
419 .vidioc_g_tuner = cx25821_vidioc_g_tuner,
420 .vidioc_s_tuner = cx25821_vidioc_s_tuner,
421 .vidioc_g_frequency = cx25821_vidioc_g_frequency,
422 .vidioc_s_frequency = cx25821_vidioc_s_frequency,
423#endif
424#ifdef CONFIG_VIDEO_ADV_DEBUG
425 .vidioc_g_register = cx25821_vidioc_g_register,
426 .vidioc_s_register = cx25821_vidioc_s_register,
427#endif
428};
429
430struct video_device cx25821_video_template2 = {
431 .name = "cx25821-video",
432 .fops = &video_fops,
433 .ioctl_ops = &video_ioctl_ops,
434 .tvnorms = CX25821_NORMS,
435 .current_norm = V4L2_STD_NTSC_M,
436};
diff --git a/drivers/staging/cx25821/cx25821-video3.c b/drivers/staging/cx25821/cx25821-video3.c
deleted file mode 100644
index 3b216ed0906e..000000000000
--- a/drivers/staging/cx25821/cx25821-video3.c
+++ /dev/null
@@ -1,435 +0,0 @@
1/*
2 * Driver for the Conexant CX25821 PCIe bridge
3 *
4 * Copyright (C) 2009 Conexant Systems Inc.
5 * Authors <shu.lin@conexant.com>, <hiep.huynh@conexant.com>
6 * Based on Steven Toth <stoth@linuxtv.org> cx23885 driver
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 *
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#include "cx25821-video.h"
25
26static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
27{
28 struct cx25821_buffer *buf =
29 container_of(vb, struct cx25821_buffer, vb);
30 struct cx25821_buffer *prev;
31 struct cx25821_fh *fh = vq->priv_data;
32 struct cx25821_dev *dev = fh->dev;
33 struct cx25821_dmaqueue *q = &dev->vidq[SRAM_CH03];
34
35 /* add jump to stopper */
36 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
37 buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma);
38 buf->risc.jmp[2] = cpu_to_le32(0); /* bits 63-32 */
39
40 dprintk(2, "jmp to stopper (0x%x)\n", buf->risc.jmp[1]);
41
42 if (!list_empty(&q->queued)) {
43 list_add_tail(&buf->vb.queue, &q->queued);
44 buf->vb.state = VIDEOBUF_QUEUED;
45 dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf,
46 buf->vb.i);
47
48 } else if (list_empty(&q->active)) {
49 list_add_tail(&buf->vb.queue, &q->active);
50 cx25821_start_video_dma(dev, q, buf,
51 &dev->sram_channels[SRAM_CH03]);
52 buf->vb.state = VIDEOBUF_ACTIVE;
53 buf->count = q->count++;
54 mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
55 dprintk(2,
56 "[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
57 buf, buf->vb.i, buf->count, q->count);
58 } else {
59 prev =
60 list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
61 if (prev->vb.width == buf->vb.width
62 && prev->vb.height == buf->vb.height
63 && prev->fmt == buf->fmt) {
64 list_add_tail(&buf->vb.queue, &q->active);
65 buf->vb.state = VIDEOBUF_ACTIVE;
66 buf->count = q->count++;
67 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
68
69 /* 64 bit bits 63-32 */
70 prev->risc.jmp[2] = cpu_to_le32(0);
71 dprintk(2,
72 "[%p/%d] buffer_queue - append to active, buf->count=%d\n",
73 buf, buf->vb.i, buf->count);
74
75 } else {
76 list_add_tail(&buf->vb.queue, &q->queued);
77 buf->vb.state = VIDEOBUF_QUEUED;
78 dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf,
79 buf->vb.i);
80 }
81 }
82
83 if (list_empty(&q->active)) {
84 dprintk(2, "active queue empty!\n");
85 }
86}
87
88static struct videobuf_queue_ops cx25821_video_qops = {
89 .buf_setup = cx25821_buffer_setup,
90 .buf_prepare = cx25821_buffer_prepare,
91 .buf_queue = buffer_queue,
92 .buf_release = cx25821_buffer_release,
93};
94
95static int video_open(struct file *file)
96{
97 struct video_device *vdev = video_devdata(file);
98 struct cx25821_dev *dev = video_drvdata(file);
99 struct cx25821_fh *fh;
100 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
101 u32 pix_format;
102
103 printk("open dev=%s type=%s\n", video_device_node_name(vdev),
104 v4l2_type_names[type]);
105
106 /* allocate + initialize per filehandle data */
107 fh = kzalloc(sizeof(*fh), GFP_KERNEL);
108 if (NULL == fh)
109 return -ENOMEM;
110
111 lock_kernel();
112
113 file->private_data = fh;
114 fh->dev = dev;
115 fh->type = type;
116 fh->width = 720;
117
118 if (dev->tvnorm & V4L2_STD_PAL_BG || dev->tvnorm & V4L2_STD_PAL_DK)
119 fh->height = 576;
120 else
121 fh->height = 480;
122
123 dev->channel_opened = SRAM_CH03;
124 pix_format =
125 (dev->pixel_formats[dev->channel_opened] ==
126 PIXEL_FRMT_411) ? V4L2_PIX_FMT_Y41P : V4L2_PIX_FMT_YUYV;
127 fh->fmt = format_by_fourcc(pix_format);
128
129 v4l2_prio_open(&dev->prio, &fh->prio);
130
131 videobuf_queue_sg_init(&fh->vidq, &cx25821_video_qops,
132 &dev->pci->dev, &dev->slock,
133 V4L2_BUF_TYPE_VIDEO_CAPTURE,
134 V4L2_FIELD_INTERLACED,
135 sizeof(struct cx25821_buffer), fh);
136
137 dprintk(1, "post videobuf_queue_init()\n");
138 unlock_kernel();
139
140 return 0;
141}
142
143static ssize_t video_read(struct file *file, char __user * data, size_t count,
144 loff_t * ppos)
145{
146 struct cx25821_fh *fh = file->private_data;
147
148 switch (fh->type) {
149 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
150 if (cx25821_res_locked(fh->dev, RESOURCE_VIDEO3))
151 return -EBUSY;
152
153 return videobuf_read_one(&fh->vidq, data, count, ppos,
154 file->f_flags & O_NONBLOCK);
155
156 default:
157 BUG();
158 return 0;
159 }
160}
161
162static unsigned int video_poll(struct file *file,
163 struct poll_table_struct *wait)
164{
165 struct cx25821_fh *fh = file->private_data;
166 struct cx25821_buffer *buf;
167
168 if (cx25821_res_check(fh, RESOURCE_VIDEO3)) {
169 /* streaming capture */
170 if (list_empty(&fh->vidq.stream))
171 return POLLERR;
172 buf = list_entry(fh->vidq.stream.next,
173 struct cx25821_buffer, vb.stream);
174 } else {
175 /* read() capture */
176 buf = (struct cx25821_buffer *)fh->vidq.read_buf;
177 if (NULL == buf)
178 return POLLERR;
179 }
180
181 poll_wait(file, &buf->vb.done, wait);
182 if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR) {
183 if (buf->vb.state == VIDEOBUF_DONE) {
184 struct cx25821_dev *dev = fh->dev;
185
186 if (dev && dev->use_cif_resolution[SRAM_CH03]) {
187 u8 cam_id = *((char *)buf->vb.baddr + 3);
188 memcpy((char *)buf->vb.baddr,
189 (char *)buf->vb.baddr + (fh->width * 2),
190 (fh->width * 2));
191 *((char *)buf->vb.baddr + 3) = cam_id;
192 }
193 }
194
195 return POLLIN | POLLRDNORM;
196 }
197
198 return 0;
199}
200
201static int video_release(struct file *file)
202{
203 struct cx25821_fh *fh = file->private_data;
204 struct cx25821_dev *dev = fh->dev;
205
206 //stop the risc engine and fifo
207 cx_write(channel3->dma_ctl, 0); /* FIFO and RISC disable */
208
209 /* stop video capture */
210 if (cx25821_res_check(fh, RESOURCE_VIDEO3)) {
211 videobuf_queue_cancel(&fh->vidq);
212 cx25821_res_free(dev, fh, RESOURCE_VIDEO3);
213 }
214
215 if (fh->vidq.read_buf) {
216 cx25821_buffer_release(&fh->vidq, fh->vidq.read_buf);
217 kfree(fh->vidq.read_buf);
218 }
219
220 videobuf_mmap_free(&fh->vidq);
221
222 v4l2_prio_close(&dev->prio, fh->prio);
223 file->private_data = NULL;
224 kfree(fh);
225
226 return 0;
227}
228
229static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
230{
231 struct cx25821_fh *fh = priv;
232 struct cx25821_dev *dev = fh->dev;
233
234 if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)) {
235 return -EINVAL;
236 }
237
238 if (unlikely(i != fh->type)) {
239 return -EINVAL;
240 }
241
242 if (unlikely(!cx25821_res_get(dev, fh, cx25821_get_resource(fh, RESOURCE_VIDEO3)))) {
243 return -EBUSY;
244 }
245
246 return videobuf_streamon(get_queue(fh));
247}
248
249static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
250{
251 struct cx25821_fh *fh = priv;
252 struct cx25821_dev *dev = fh->dev;
253 int err, res;
254
255 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
256 return -EINVAL;
257 if (i != fh->type)
258 return -EINVAL;
259
260 res = cx25821_get_resource(fh, RESOURCE_VIDEO3);
261 err = videobuf_streamoff(get_queue(fh));
262 if (err < 0)
263 return err;
264 cx25821_res_free(dev, fh, res);
265 return 0;
266}
267
268static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
269 struct v4l2_format *f)
270{
271 struct cx25821_fh *fh = priv;
272 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
273 int err;
274 int pix_format = 0;
275
276 if (fh) {
277 err = v4l2_prio_check(&dev->prio, fh->prio);
278 if (0 != err)
279 return err;
280 }
281
282 dprintk(2, "%s()\n", __func__);
283 err = cx25821_vidioc_try_fmt_vid_cap(file, priv, f);
284
285 if (0 != err)
286 return err;
287
288 fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat);
289 fh->vidq.field = f->fmt.pix.field;
290
291 // check if width and height is valid based on set standard
292 if (cx25821_is_valid_width(f->fmt.pix.width, dev->tvnorm)) {
293 fh->width = f->fmt.pix.width;
294 }
295
296 if (cx25821_is_valid_height(f->fmt.pix.height, dev->tvnorm)) {
297 fh->height = f->fmt.pix.height;
298 }
299
300 if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_Y41P)
301 pix_format = PIXEL_FRMT_411;
302 else if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_YUYV)
303 pix_format = PIXEL_FRMT_422;
304 else
305 return -EINVAL;
306
307 cx25821_set_pixel_format(dev, SRAM_CH03, pix_format);
308
309 // check if cif resolution
310 if (fh->width == 320 || fh->width == 352) {
311 dev->use_cif_resolution[SRAM_CH03] = 1;
312 } else {
313 dev->use_cif_resolution[SRAM_CH03] = 0;
314 }
315 dev->cif_width[SRAM_CH03] = fh->width;
316 medusa_set_resolution(dev, fh->width, SRAM_CH03);
317
318 dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width,
319 fh->height, fh->vidq.field);
320 cx25821_call_all(dev, video, s_fmt, f);
321
322 return 0;
323}
324
325static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
326{
327 int ret_val = 0;
328 struct cx25821_fh *fh = priv;
329 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
330
331 ret_val = videobuf_dqbuf(get_queue(fh), p, file->f_flags & O_NONBLOCK);
332
333 p->sequence = dev->vidq[SRAM_CH03].count;
334
335 return ret_val;
336}
337
338static int vidioc_log_status(struct file *file, void *priv)
339{
340 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
341 char name[32 + 2];
342
343 struct sram_channel *sram_ch = &dev->sram_channels[SRAM_CH03];
344 u32 tmp = 0;
345
346 snprintf(name, sizeof(name), "%s/2", dev->name);
347 printk(KERN_INFO "%s/2: ============ START LOG STATUS ============\n",
348 dev->name);
349 cx25821_call_all(dev, core, log_status);
350
351 tmp = cx_read(sram_ch->dma_ctl);
352 printk(KERN_INFO "Video input 3 is %s\n",
353 (tmp & 0x11) ? "streaming" : "stopped");
354 printk(KERN_INFO "%s/2: ============= END LOG STATUS =============\n",
355 dev->name);
356 return 0;
357}
358
359static int vidioc_s_ctrl(struct file *file, void *priv,
360 struct v4l2_control *ctl)
361{
362 struct cx25821_fh *fh = priv;
363 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
364 int err;
365
366 if (fh) {
367 err = v4l2_prio_check(&dev->prio, fh->prio);
368 if (0 != err)
369 return err;
370 }
371
372 return cx25821_set_control(dev, ctl, SRAM_CH03);
373}
374
375// exported stuff
376static const struct v4l2_file_operations video_fops = {
377 .owner = THIS_MODULE,
378 .open = video_open,
379 .release = video_release,
380 .read = video_read,
381 .poll = video_poll,
382 .mmap = cx25821_video_mmap,
383 .ioctl = video_ioctl2,
384};
385
386static const struct v4l2_ioctl_ops video_ioctl_ops = {
387 .vidioc_querycap = cx25821_vidioc_querycap,
388 .vidioc_enum_fmt_vid_cap = cx25821_vidioc_enum_fmt_vid_cap,
389 .vidioc_g_fmt_vid_cap = cx25821_vidioc_g_fmt_vid_cap,
390 .vidioc_try_fmt_vid_cap = cx25821_vidioc_try_fmt_vid_cap,
391 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
392 .vidioc_reqbufs = cx25821_vidioc_reqbufs,
393 .vidioc_querybuf = cx25821_vidioc_querybuf,
394 .vidioc_qbuf = cx25821_vidioc_qbuf,
395 .vidioc_dqbuf = vidioc_dqbuf,
396#ifdef TUNER_FLAG
397 .vidioc_s_std = cx25821_vidioc_s_std,
398 .vidioc_querystd = cx25821_vidioc_querystd,
399#endif
400 .vidioc_cropcap = cx25821_vidioc_cropcap,
401 .vidioc_s_crop = cx25821_vidioc_s_crop,
402 .vidioc_g_crop = cx25821_vidioc_g_crop,
403 .vidioc_enum_input = cx25821_vidioc_enum_input,
404 .vidioc_g_input = cx25821_vidioc_g_input,
405 .vidioc_s_input = cx25821_vidioc_s_input,
406 .vidioc_g_ctrl = cx25821_vidioc_g_ctrl,
407 .vidioc_s_ctrl = vidioc_s_ctrl,
408 .vidioc_queryctrl = cx25821_vidioc_queryctrl,
409 .vidioc_streamon = vidioc_streamon,
410 .vidioc_streamoff = vidioc_streamoff,
411 .vidioc_log_status = vidioc_log_status,
412 .vidioc_g_priority = cx25821_vidioc_g_priority,
413 .vidioc_s_priority = cx25821_vidioc_s_priority,
414#ifdef CONFIG_VIDEO_V4L1_COMPAT
415 .vidiocgmbuf = cx25821_vidiocgmbuf,
416#endif
417#ifdef TUNER_FLAG
418 .vidioc_g_tuner = cx25821_vidioc_g_tuner,
419 .vidioc_s_tuner = cx25821_vidioc_s_tuner,
420 .vidioc_g_frequency = cx25821_vidioc_g_frequency,
421 .vidioc_s_frequency = cx25821_vidioc_s_frequency,
422#endif
423#ifdef CONFIG_VIDEO_ADV_DEBUG
424 .vidioc_g_register = cx25821_vidioc_g_register,
425 .vidioc_s_register = cx25821_vidioc_s_register,
426#endif
427};
428
429struct video_device cx25821_video_template3 = {
430 .name = "cx25821-video",
431 .fops = &video_fops,
432 .ioctl_ops = &video_ioctl_ops,
433 .tvnorms = CX25821_NORMS,
434 .current_norm = V4L2_STD_NTSC_M,
435};
diff --git a/drivers/staging/cx25821/cx25821-video4.c b/drivers/staging/cx25821/cx25821-video4.c
deleted file mode 100644
index f7b08c51868a..000000000000
--- a/drivers/staging/cx25821/cx25821-video4.c
+++ /dev/null
@@ -1,434 +0,0 @@
1/*
2 * Driver for the Conexant CX25821 PCIe bridge
3 *
4 * Copyright (C) 2009 Conexant Systems Inc.
5 * Authors <shu.lin@conexant.com>, <hiep.huynh@conexant.com>
6 * Based on Steven Toth <stoth@linuxtv.org> cx23885 driver
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 *
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#include "cx25821-video.h"
25
26static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
27{
28 struct cx25821_buffer *buf =
29 container_of(vb, struct cx25821_buffer, vb);
30 struct cx25821_buffer *prev;
31 struct cx25821_fh *fh = vq->priv_data;
32 struct cx25821_dev *dev = fh->dev;
33 struct cx25821_dmaqueue *q = &dev->vidq[SRAM_CH04];
34
35 /* add jump to stopper */
36 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
37 buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma);
38 buf->risc.jmp[2] = cpu_to_le32(0); /* bits 63-32 */
39
40 dprintk(2, "jmp to stopper (0x%x)\n", buf->risc.jmp[1]);
41
42 if (!list_empty(&q->queued)) {
43 list_add_tail(&buf->vb.queue, &q->queued);
44 buf->vb.state = VIDEOBUF_QUEUED;
45 dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf,
46 buf->vb.i);
47
48 } else if (list_empty(&q->active)) {
49 list_add_tail(&buf->vb.queue, &q->active);
50 cx25821_start_video_dma(dev, q, buf,
51 &dev->sram_channels[SRAM_CH04]);
52 buf->vb.state = VIDEOBUF_ACTIVE;
53 buf->count = q->count++;
54 mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
55 dprintk(2,
56 "[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
57 buf, buf->vb.i, buf->count, q->count);
58 } else {
59 prev =
60 list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
61 if (prev->vb.width == buf->vb.width
62 && prev->vb.height == buf->vb.height
63 && prev->fmt == buf->fmt) {
64 list_add_tail(&buf->vb.queue, &q->active);
65 buf->vb.state = VIDEOBUF_ACTIVE;
66 buf->count = q->count++;
67 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
68
69 /* 64 bit bits 63-32 */
70 prev->risc.jmp[2] = cpu_to_le32(0);
71 dprintk(2,
72 "[%p/%d] buffer_queue - append to active, buf->count=%d\n",
73 buf, buf->vb.i, buf->count);
74
75 } else {
76 list_add_tail(&buf->vb.queue, &q->queued);
77 buf->vb.state = VIDEOBUF_QUEUED;
78 dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf,
79 buf->vb.i);
80 }
81 }
82
83 if (list_empty(&q->active)) {
84 dprintk(2, "active queue empty!\n");
85 }
86}
87
88static struct videobuf_queue_ops cx25821_video_qops = {
89 .buf_setup = cx25821_buffer_setup,
90 .buf_prepare = cx25821_buffer_prepare,
91 .buf_queue = buffer_queue,
92 .buf_release = cx25821_buffer_release,
93};
94
95static int video_open(struct file *file)
96{
97 struct video_device *vdev = video_devdata(file);
98 struct cx25821_dev *dev = video_drvdata(file);
99 struct cx25821_fh *fh;
100 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
101 u32 pix_format;
102
103 printk("open dev=%s type=%s\n", video_device_node_name(vdev),
104 v4l2_type_names[type]);
105
106 /* allocate + initialize per filehandle data */
107 fh = kzalloc(sizeof(*fh), GFP_KERNEL);
108 if (NULL == fh)
109 return -ENOMEM;
110
111 lock_kernel();
112
113 file->private_data = fh;
114 fh->dev = dev;
115 fh->type = type;
116 fh->width = 720;
117
118 if (dev->tvnorm & V4L2_STD_PAL_BG || dev->tvnorm & V4L2_STD_PAL_DK)
119 fh->height = 576;
120 else
121 fh->height = 480;
122
123 dev->channel_opened = SRAM_CH04;
124 pix_format =
125 (dev->pixel_formats[dev->channel_opened] ==
126 PIXEL_FRMT_411) ? V4L2_PIX_FMT_Y41P : V4L2_PIX_FMT_YUYV;
127 fh->fmt = format_by_fourcc(pix_format);
128
129 v4l2_prio_open(&dev->prio, &fh->prio);
130 videobuf_queue_sg_init(&fh->vidq, &cx25821_video_qops,
131 &dev->pci->dev, &dev->slock,
132 V4L2_BUF_TYPE_VIDEO_CAPTURE,
133 V4L2_FIELD_INTERLACED,
134 sizeof(struct cx25821_buffer), fh);
135
136 dprintk(1, "post videobuf_queue_init()\n");
137 unlock_kernel();
138
139 return 0;
140}
141
142static ssize_t video_read(struct file *file, char __user * data, size_t count,
143 loff_t * ppos)
144{
145 struct cx25821_fh *fh = file->private_data;
146
147 switch (fh->type) {
148 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
149 if (cx25821_res_locked(fh->dev, RESOURCE_VIDEO4))
150 return -EBUSY;
151
152 return videobuf_read_one(&fh->vidq, data, count, ppos,
153 file->f_flags & O_NONBLOCK);
154
155 default:
156 BUG();
157 return 0;
158 }
159}
160
161static unsigned int video_poll(struct file *file,
162 struct poll_table_struct *wait)
163{
164 struct cx25821_fh *fh = file->private_data;
165 struct cx25821_buffer *buf;
166
167 if (cx25821_res_check(fh, RESOURCE_VIDEO4)) {
168 /* streaming capture */
169 if (list_empty(&fh->vidq.stream))
170 return POLLERR;
171 buf = list_entry(fh->vidq.stream.next,
172 struct cx25821_buffer, vb.stream);
173 } else {
174 /* read() capture */
175 buf = (struct cx25821_buffer *)fh->vidq.read_buf;
176 if (NULL == buf)
177 return POLLERR;
178 }
179
180 poll_wait(file, &buf->vb.done, wait);
181 if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR) {
182 if (buf->vb.state == VIDEOBUF_DONE) {
183 struct cx25821_dev *dev = fh->dev;
184
185 if (dev && dev->use_cif_resolution[SRAM_CH04]) {
186 u8 cam_id = *((char *)buf->vb.baddr + 3);
187 memcpy((char *)buf->vb.baddr,
188 (char *)buf->vb.baddr + (fh->width * 2),
189 (fh->width * 2));
190 *((char *)buf->vb.baddr + 3) = cam_id;
191 }
192 }
193
194 return POLLIN | POLLRDNORM;
195 }
196
197 return 0;
198}
199
200static int video_release(struct file *file)
201{
202 struct cx25821_fh *fh = file->private_data;
203 struct cx25821_dev *dev = fh->dev;
204
205 //stop the risc engine and fifo
206 cx_write(channel4->dma_ctl, 0); /* FIFO and RISC disable */
207
208 /* stop video capture */
209 if (cx25821_res_check(fh, RESOURCE_VIDEO4)) {
210 videobuf_queue_cancel(&fh->vidq);
211 cx25821_res_free(dev, fh, RESOURCE_VIDEO4);
212 }
213
214 if (fh->vidq.read_buf) {
215 cx25821_buffer_release(&fh->vidq, fh->vidq.read_buf);
216 kfree(fh->vidq.read_buf);
217 }
218
219 videobuf_mmap_free(&fh->vidq);
220
221 v4l2_prio_close(&dev->prio, fh->prio);
222 file->private_data = NULL;
223 kfree(fh);
224
225 return 0;
226}
227
228static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
229{
230 struct cx25821_fh *fh = priv;
231 struct cx25821_dev *dev = fh->dev;
232
233 if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)) {
234 return -EINVAL;
235 }
236
237 if (unlikely(i != fh->type)) {
238 return -EINVAL;
239 }
240
241 if (unlikely(!cx25821_res_get(dev, fh, cx25821_get_resource(fh, RESOURCE_VIDEO4)))) {
242 return -EBUSY;
243 }
244
245 return videobuf_streamon(get_queue(fh));
246}
247
248static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
249{
250 struct cx25821_fh *fh = priv;
251 struct cx25821_dev *dev = fh->dev;
252 int err, res;
253
254 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
255 return -EINVAL;
256 if (i != fh->type)
257 return -EINVAL;
258
259 res = cx25821_get_resource(fh, RESOURCE_VIDEO4);
260 err = videobuf_streamoff(get_queue(fh));
261 if (err < 0)
262 return err;
263 cx25821_res_free(dev, fh, res);
264 return 0;
265}
266
267static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
268 struct v4l2_format *f)
269{
270 struct cx25821_fh *fh = priv;
271 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
272 int err;
273 int pix_format = 0;
274
275 // check priority
276 if (fh) {
277 err = v4l2_prio_check(&dev->prio, fh->prio);
278 if (0 != err)
279 return err;
280 }
281 dprintk(2, "%s()\n", __func__);
282 err = cx25821_vidioc_try_fmt_vid_cap(file, priv, f);
283
284 if (0 != err)
285 return err;
286
287 fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat);
288 fh->vidq.field = f->fmt.pix.field;
289
290 // check if width and height is valid based on set standard
291 if (cx25821_is_valid_width(f->fmt.pix.width, dev->tvnorm)) {
292 fh->width = f->fmt.pix.width;
293 }
294
295 if (cx25821_is_valid_height(f->fmt.pix.height, dev->tvnorm)) {
296 fh->height = f->fmt.pix.height;
297 }
298
299 if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_Y41P)
300 pix_format = PIXEL_FRMT_411;
301 else if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_YUYV)
302 pix_format = PIXEL_FRMT_422;
303 else
304 return -EINVAL;
305
306 cx25821_set_pixel_format(dev, SRAM_CH04, pix_format);
307
308 // check if cif resolution
309 if (fh->width == 320 || fh->width == 352) {
310 dev->use_cif_resolution[SRAM_CH04] = 1;
311 } else {
312 dev->use_cif_resolution[SRAM_CH04] = 0;
313 }
314 dev->cif_width[SRAM_CH04] = fh->width;
315 medusa_set_resolution(dev, fh->width, SRAM_CH04);
316
317 dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width,
318 fh->height, fh->vidq.field);
319 cx25821_call_all(dev, video, s_fmt, f);
320
321 return 0;
322}
323
324static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
325{
326 int ret_val = 0;
327 struct cx25821_fh *fh = priv;
328 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
329
330 ret_val = videobuf_dqbuf(get_queue(fh), p, file->f_flags & O_NONBLOCK);
331
332 p->sequence = dev->vidq[SRAM_CH04].count;
333
334 return ret_val;
335}
336
337static int vidioc_log_status(struct file *file, void *priv)
338{
339 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
340 char name[32 + 2];
341
342 struct sram_channel *sram_ch = &dev->sram_channels[SRAM_CH04];
343 u32 tmp = 0;
344
345 snprintf(name, sizeof(name), "%s/2", dev->name);
346 printk(KERN_INFO "%s/2: ============ START LOG STATUS ============\n",
347 dev->name);
348 cx25821_call_all(dev, core, log_status);
349
350 tmp = cx_read(sram_ch->dma_ctl);
351 printk(KERN_INFO "Video input 4 is %s\n",
352 (tmp & 0x11) ? "streaming" : "stopped");
353 printk(KERN_INFO "%s/2: ============= END LOG STATUS =============\n",
354 dev->name);
355 return 0;
356}
357
358static int vidioc_s_ctrl(struct file *file, void *priv,
359 struct v4l2_control *ctl)
360{
361 struct cx25821_fh *fh = priv;
362 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
363 int err;
364
365 if (fh) {
366 err = v4l2_prio_check(&dev->prio, fh->prio);
367 if (0 != err)
368 return err;
369 }
370
371 return cx25821_set_control(dev, ctl, SRAM_CH04);
372}
373
374// exported stuff
375static const struct v4l2_file_operations video_fops = {
376 .owner = THIS_MODULE,
377 .open = video_open,
378 .release = video_release,
379 .read = video_read,
380 .poll = video_poll,
381 .mmap = cx25821_video_mmap,
382 .ioctl = video_ioctl2,
383};
384
385static const struct v4l2_ioctl_ops video_ioctl_ops = {
386 .vidioc_querycap = cx25821_vidioc_querycap,
387 .vidioc_enum_fmt_vid_cap = cx25821_vidioc_enum_fmt_vid_cap,
388 .vidioc_g_fmt_vid_cap = cx25821_vidioc_g_fmt_vid_cap,
389 .vidioc_try_fmt_vid_cap = cx25821_vidioc_try_fmt_vid_cap,
390 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
391 .vidioc_reqbufs = cx25821_vidioc_reqbufs,
392 .vidioc_querybuf = cx25821_vidioc_querybuf,
393 .vidioc_qbuf = cx25821_vidioc_qbuf,
394 .vidioc_dqbuf = vidioc_dqbuf,
395#ifdef TUNER_FLAG
396 .vidioc_s_std = cx25821_vidioc_s_std,
397 .vidioc_querystd = cx25821_vidioc_querystd,
398#endif
399 .vidioc_cropcap = cx25821_vidioc_cropcap,
400 .vidioc_s_crop = cx25821_vidioc_s_crop,
401 .vidioc_g_crop = cx25821_vidioc_g_crop,
402 .vidioc_enum_input = cx25821_vidioc_enum_input,
403 .vidioc_g_input = cx25821_vidioc_g_input,
404 .vidioc_s_input = cx25821_vidioc_s_input,
405 .vidioc_g_ctrl = cx25821_vidioc_g_ctrl,
406 .vidioc_s_ctrl = vidioc_s_ctrl,
407 .vidioc_queryctrl = cx25821_vidioc_queryctrl,
408 .vidioc_streamon = vidioc_streamon,
409 .vidioc_streamoff = vidioc_streamoff,
410 .vidioc_log_status = vidioc_log_status,
411 .vidioc_g_priority = cx25821_vidioc_g_priority,
412 .vidioc_s_priority = cx25821_vidioc_s_priority,
413#ifdef CONFIG_VIDEO_V4L1_COMPAT
414 .vidiocgmbuf = cx25821_vidiocgmbuf,
415#endif
416#ifdef TUNER_FLAG
417 .vidioc_g_tuner = cx25821_vidioc_g_tuner,
418 .vidioc_s_tuner = cx25821_vidioc_s_tuner,
419 .vidioc_g_frequency = cx25821_vidioc_g_frequency,
420 .vidioc_s_frequency = cx25821_vidioc_s_frequency,
421#endif
422#ifdef CONFIG_VIDEO_ADV_DEBUG
423 .vidioc_g_register = cx25821_vidioc_g_register,
424 .vidioc_s_register = cx25821_vidioc_s_register,
425#endif
426};
427
428struct video_device cx25821_video_template4 = {
429 .name = "cx25821-video",
430 .fops = &video_fops,
431 .ioctl_ops = &video_ioctl_ops,
432 .tvnorms = CX25821_NORMS,
433 .current_norm = V4L2_STD_NTSC_M,
434};
diff --git a/drivers/staging/cx25821/cx25821-video5.c b/drivers/staging/cx25821/cx25821-video5.c
deleted file mode 100644
index 59370337b076..000000000000
--- a/drivers/staging/cx25821/cx25821-video5.c
+++ /dev/null
@@ -1,434 +0,0 @@
1/*
2 * Driver for the Conexant CX25821 PCIe bridge
3 *
4 * Copyright (C) 2009 Conexant Systems Inc.
5 * Authors <shu.lin@conexant.com>, <hiep.huynh@conexant.com>
6 * Based on Steven Toth <stoth@linuxtv.org> cx23885 driver
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 *
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#include "cx25821-video.h"
25
26static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
27{
28 struct cx25821_buffer *buf =
29 container_of(vb, struct cx25821_buffer, vb);
30 struct cx25821_buffer *prev;
31 struct cx25821_fh *fh = vq->priv_data;
32 struct cx25821_dev *dev = fh->dev;
33 struct cx25821_dmaqueue *q = &dev->vidq[SRAM_CH05];
34
35 /* add jump to stopper */
36 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
37 buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma);
38 buf->risc.jmp[2] = cpu_to_le32(0); /* bits 63-32 */
39
40 dprintk(2, "jmp to stopper (0x%x)\n", buf->risc.jmp[1]);
41
42 if (!list_empty(&q->queued)) {
43 list_add_tail(&buf->vb.queue, &q->queued);
44 buf->vb.state = VIDEOBUF_QUEUED;
45 dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf,
46 buf->vb.i);
47
48 } else if (list_empty(&q->active)) {
49 list_add_tail(&buf->vb.queue, &q->active);
50 cx25821_start_video_dma(dev, q, buf,
51 &dev->sram_channels[SRAM_CH05]);
52 buf->vb.state = VIDEOBUF_ACTIVE;
53 buf->count = q->count++;
54 mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
55 dprintk(2,
56 "[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
57 buf, buf->vb.i, buf->count, q->count);
58 } else {
59 prev =
60 list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
61 if (prev->vb.width == buf->vb.width
62 && prev->vb.height == buf->vb.height
63 && prev->fmt == buf->fmt) {
64 list_add_tail(&buf->vb.queue, &q->active);
65 buf->vb.state = VIDEOBUF_ACTIVE;
66 buf->count = q->count++;
67 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
68
69 /* 64 bit bits 63-32 */
70 prev->risc.jmp[2] = cpu_to_le32(0);
71 dprintk(2,
72 "[%p/%d] buffer_queue - append to active, buf->count=%d\n",
73 buf, buf->vb.i, buf->count);
74
75 } else {
76 list_add_tail(&buf->vb.queue, &q->queued);
77 buf->vb.state = VIDEOBUF_QUEUED;
78 dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf,
79 buf->vb.i);
80 }
81 }
82
83 if (list_empty(&q->active)) {
84 dprintk(2, "active queue empty!\n");
85 }
86}
87
88static struct videobuf_queue_ops cx25821_video_qops = {
89 .buf_setup = cx25821_buffer_setup,
90 .buf_prepare = cx25821_buffer_prepare,
91 .buf_queue = buffer_queue,
92 .buf_release = cx25821_buffer_release,
93};
94
95static int video_open(struct file *file)
96{
97 struct video_device *vdev = video_devdata(file);
98 struct cx25821_dev *dev = video_drvdata(file);
99 struct cx25821_fh *fh;
100 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
101 u32 pix_format;
102
103 printk("open dev=%s type=%s\n", video_device_node_name(vdev),
104 v4l2_type_names[type]);
105
106 /* allocate + initialize per filehandle data */
107 fh = kzalloc(sizeof(*fh), GFP_KERNEL);
108 if (NULL == fh)
109 return -ENOMEM;
110
111 lock_kernel();
112
113 file->private_data = fh;
114 fh->dev = dev;
115 fh->type = type;
116 fh->width = 720;
117
118 if (dev->tvnorm & V4L2_STD_PAL_BG || dev->tvnorm & V4L2_STD_PAL_DK)
119 fh->height = 576;
120 else
121 fh->height = 480;
122
123 dev->channel_opened = SRAM_CH05;
124 pix_format =
125 (dev->pixel_formats[dev->channel_opened] ==
126 PIXEL_FRMT_411) ? V4L2_PIX_FMT_Y41P : V4L2_PIX_FMT_YUYV;
127 fh->fmt = format_by_fourcc(pix_format);
128
129 v4l2_prio_open(&dev->prio, &fh->prio);
130
131 videobuf_queue_sg_init(&fh->vidq, &cx25821_video_qops,
132 &dev->pci->dev, &dev->slock,
133 V4L2_BUF_TYPE_VIDEO_CAPTURE,
134 V4L2_FIELD_INTERLACED,
135 sizeof(struct cx25821_buffer), fh);
136
137 dprintk(1, "post videobuf_queue_init()\n");
138 unlock_kernel();
139
140 return 0;
141}
142
143static ssize_t video_read(struct file *file, char __user * data, size_t count,
144 loff_t * ppos)
145{
146 struct cx25821_fh *fh = file->private_data;
147
148 switch (fh->type) {
149 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
150 if (cx25821_res_locked(fh->dev, RESOURCE_VIDEO5))
151 return -EBUSY;
152
153 return videobuf_read_one(&fh->vidq, data, count, ppos,
154 file->f_flags & O_NONBLOCK);
155
156 default:
157 BUG();
158 return 0;
159 }
160}
161
162static unsigned int video_poll(struct file *file,
163 struct poll_table_struct *wait)
164{
165 struct cx25821_fh *fh = file->private_data;
166 struct cx25821_buffer *buf;
167
168 if (cx25821_res_check(fh, RESOURCE_VIDEO5)) {
169 /* streaming capture */
170 if (list_empty(&fh->vidq.stream))
171 return POLLERR;
172 buf = list_entry(fh->vidq.stream.next,
173 struct cx25821_buffer, vb.stream);
174 } else {
175 /* read() capture */
176 buf = (struct cx25821_buffer *)fh->vidq.read_buf;
177 if (NULL == buf)
178 return POLLERR;
179 }
180
181 poll_wait(file, &buf->vb.done, wait);
182 if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR) {
183 if (buf->vb.state == VIDEOBUF_DONE) {
184 struct cx25821_dev *dev = fh->dev;
185
186 if (dev && dev->use_cif_resolution[SRAM_CH05]) {
187 u8 cam_id = *((char *)buf->vb.baddr + 3);
188 memcpy((char *)buf->vb.baddr,
189 (char *)buf->vb.baddr + (fh->width * 2),
190 (fh->width * 2));
191 *((char *)buf->vb.baddr + 3) = cam_id;
192 }
193 }
194
195 return POLLIN | POLLRDNORM;
196 }
197
198 return 0;
199}
200
201static int video_release(struct file *file)
202{
203 struct cx25821_fh *fh = file->private_data;
204 struct cx25821_dev *dev = fh->dev;
205
206 //stop the risc engine and fifo
207 cx_write(channel5->dma_ctl, 0); /* FIFO and RISC disable */
208
209 /* stop video capture */
210 if (cx25821_res_check(fh, RESOURCE_VIDEO5)) {
211 videobuf_queue_cancel(&fh->vidq);
212 cx25821_res_free(dev, fh, RESOURCE_VIDEO5);
213 }
214
215 if (fh->vidq.read_buf) {
216 cx25821_buffer_release(&fh->vidq, fh->vidq.read_buf);
217 kfree(fh->vidq.read_buf);
218 }
219
220 videobuf_mmap_free(&fh->vidq);
221
222 v4l2_prio_close(&dev->prio, fh->prio);
223 file->private_data = NULL;
224 kfree(fh);
225
226 return 0;
227}
228
229static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
230{
231 struct cx25821_fh *fh = priv;
232 struct cx25821_dev *dev = fh->dev;
233
234 if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)) {
235 return -EINVAL;
236 }
237
238 if (unlikely(i != fh->type)) {
239 return -EINVAL;
240 }
241
242 if (unlikely(!cx25821_res_get(dev, fh, cx25821_get_resource(fh, RESOURCE_VIDEO5)))) {
243 return -EBUSY;
244 }
245
246 return videobuf_streamon(get_queue(fh));
247}
248
249static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
250{
251 struct cx25821_fh *fh = priv;
252 struct cx25821_dev *dev = fh->dev;
253 int err, res;
254
255 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
256 return -EINVAL;
257 if (i != fh->type)
258 return -EINVAL;
259
260 res = cx25821_get_resource(fh, RESOURCE_VIDEO5);
261 err = videobuf_streamoff(get_queue(fh));
262 if (err < 0)
263 return err;
264 cx25821_res_free(dev, fh, res);
265 return 0;
266}
267
268static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
269 struct v4l2_format *f)
270{
271 struct cx25821_fh *fh = priv;
272 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
273 int err;
274 int pix_format = 0;
275
276 if (fh) {
277 err = v4l2_prio_check(&dev->prio, fh->prio);
278 if (0 != err)
279 return err;
280 }
281
282 dprintk(2, "%s()\n", __func__);
283 err = cx25821_vidioc_try_fmt_vid_cap(file, priv, f);
284
285 if (0 != err)
286 return err;
287
288 fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat);
289 fh->vidq.field = f->fmt.pix.field;
290
291 // check if width and height is valid based on set standard
292 if (cx25821_is_valid_width(f->fmt.pix.width, dev->tvnorm)) {
293 fh->width = f->fmt.pix.width;
294 }
295
296 if (cx25821_is_valid_height(f->fmt.pix.height, dev->tvnorm)) {
297 fh->height = f->fmt.pix.height;
298 }
299
300 if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_Y41P)
301 pix_format = PIXEL_FRMT_411;
302 else if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_YUYV)
303 pix_format = PIXEL_FRMT_422;
304 else
305 return -EINVAL;
306
307 cx25821_set_pixel_format(dev, SRAM_CH05, pix_format);
308
309 // check if cif resolution
310 if (fh->width == 320 || fh->width == 352) {
311 dev->use_cif_resolution[SRAM_CH05] = 1;
312 } else {
313 dev->use_cif_resolution[SRAM_CH05] = 0;
314 }
315 dev->cif_width[SRAM_CH05] = fh->width;
316 medusa_set_resolution(dev, fh->width, SRAM_CH05);
317
318 dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width,
319 fh->height, fh->vidq.field);
320 cx25821_call_all(dev, video, s_fmt, f);
321
322 return 0;
323}
324
325static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
326{
327 int ret_val = 0;
328 struct cx25821_fh *fh = priv;
329 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
330
331 ret_val = videobuf_dqbuf(get_queue(fh), p, file->f_flags & O_NONBLOCK);
332
333 p->sequence = dev->vidq[SRAM_CH05].count;
334
335 return ret_val;
336}
337static int vidioc_log_status(struct file *file, void *priv)
338{
339 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
340 char name[32 + 2];
341
342 struct sram_channel *sram_ch = &dev->sram_channels[SRAM_CH05];
343 u32 tmp = 0;
344
345 snprintf(name, sizeof(name), "%s/2", dev->name);
346 printk(KERN_INFO "%s/2: ============ START LOG STATUS ============\n",
347 dev->name);
348 cx25821_call_all(dev, core, log_status);
349
350 tmp = cx_read(sram_ch->dma_ctl);
351 printk(KERN_INFO "Video input 5 is %s\n",
352 (tmp & 0x11) ? "streaming" : "stopped");
353 printk(KERN_INFO "%s/2: ============= END LOG STATUS =============\n",
354 dev->name);
355 return 0;
356}
357
358static int vidioc_s_ctrl(struct file *file, void *priv,
359 struct v4l2_control *ctl)
360{
361 struct cx25821_fh *fh = priv;
362 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
363 int err;
364
365 if (fh) {
366 err = v4l2_prio_check(&dev->prio, fh->prio);
367 if (0 != err)
368 return err;
369 }
370
371 return cx25821_set_control(dev, ctl, SRAM_CH05);
372}
373
374// exported stuff
375static const struct v4l2_file_operations video_fops = {
376 .owner = THIS_MODULE,
377 .open = video_open,
378 .release = video_release,
379 .read = video_read,
380 .poll = video_poll,
381 .mmap = cx25821_video_mmap,
382 .ioctl = video_ioctl2,
383};
384
385static const struct v4l2_ioctl_ops video_ioctl_ops = {
386 .vidioc_querycap = cx25821_vidioc_querycap,
387 .vidioc_enum_fmt_vid_cap = cx25821_vidioc_enum_fmt_vid_cap,
388 .vidioc_g_fmt_vid_cap = cx25821_vidioc_g_fmt_vid_cap,
389 .vidioc_try_fmt_vid_cap = cx25821_vidioc_try_fmt_vid_cap,
390 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
391 .vidioc_reqbufs = cx25821_vidioc_reqbufs,
392 .vidioc_querybuf = cx25821_vidioc_querybuf,
393 .vidioc_qbuf = cx25821_vidioc_qbuf,
394 .vidioc_dqbuf = vidioc_dqbuf,
395#ifdef TUNER_FLAG
396 .vidioc_s_std = cx25821_vidioc_s_std,
397 .vidioc_querystd = cx25821_vidioc_querystd,
398#endif
399 .vidioc_cropcap = cx25821_vidioc_cropcap,
400 .vidioc_s_crop = cx25821_vidioc_s_crop,
401 .vidioc_g_crop = cx25821_vidioc_g_crop,
402 .vidioc_enum_input = cx25821_vidioc_enum_input,
403 .vidioc_g_input = cx25821_vidioc_g_input,
404 .vidioc_s_input = cx25821_vidioc_s_input,
405 .vidioc_g_ctrl = cx25821_vidioc_g_ctrl,
406 .vidioc_s_ctrl = vidioc_s_ctrl,
407 .vidioc_queryctrl = cx25821_vidioc_queryctrl,
408 .vidioc_streamon = vidioc_streamon,
409 .vidioc_streamoff = vidioc_streamoff,
410 .vidioc_log_status = vidioc_log_status,
411 .vidioc_g_priority = cx25821_vidioc_g_priority,
412 .vidioc_s_priority = cx25821_vidioc_s_priority,
413#ifdef CONFIG_VIDEO_V4L1_COMPAT
414 .vidiocgmbuf = cx25821_vidiocgmbuf,
415#endif
416#ifdef TUNER_FLAG
417 .vidioc_g_tuner = cx25821_vidioc_g_tuner,
418 .vidioc_s_tuner = cx25821_vidioc_s_tuner,
419 .vidioc_g_frequency = cx25821_vidioc_g_frequency,
420 .vidioc_s_frequency = cx25821_vidioc_s_frequency,
421#endif
422#ifdef CONFIG_VIDEO_ADV_DEBUG
423 .vidioc_g_register = cx25821_vidioc_g_register,
424 .vidioc_s_register = cx25821_vidioc_s_register,
425#endif
426};
427
428struct video_device cx25821_video_template5 = {
429 .name = "cx25821-video",
430 .fops = &video_fops,
431 .ioctl_ops = &video_ioctl_ops,
432 .tvnorms = CX25821_NORMS,
433 .current_norm = V4L2_STD_NTSC_M,
434};
diff --git a/drivers/staging/cx25821/cx25821-video6.c b/drivers/staging/cx25821/cx25821-video6.c
deleted file mode 100644
index 4db2eb83d35a..000000000000
--- a/drivers/staging/cx25821/cx25821-video6.c
+++ /dev/null
@@ -1,434 +0,0 @@
1/*
2 * Driver for the Conexant CX25821 PCIe bridge
3 *
4 * Copyright (C) 2009 Conexant Systems Inc.
5 * Authors <shu.lin@conexant.com>, <hiep.huynh@conexant.com>
6 * Based on Steven Toth <stoth@linuxtv.org> cx23885 driver
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 *
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#include "cx25821-video.h"
25
26static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
27{
28 struct cx25821_buffer *buf =
29 container_of(vb, struct cx25821_buffer, vb);
30 struct cx25821_buffer *prev;
31 struct cx25821_fh *fh = vq->priv_data;
32 struct cx25821_dev *dev = fh->dev;
33 struct cx25821_dmaqueue *q = &dev->vidq[SRAM_CH06];
34
35 /* add jump to stopper */
36 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
37 buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma);
38 buf->risc.jmp[2] = cpu_to_le32(0); /* bits 63-32 */
39
40 dprintk(2, "jmp to stopper (0x%x)\n", buf->risc.jmp[1]);
41
42 if (!list_empty(&q->queued)) {
43 list_add_tail(&buf->vb.queue, &q->queued);
44 buf->vb.state = VIDEOBUF_QUEUED;
45 dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf,
46 buf->vb.i);
47
48 } else if (list_empty(&q->active)) {
49 list_add_tail(&buf->vb.queue, &q->active);
50 cx25821_start_video_dma(dev, q, buf,
51 &dev->sram_channels[SRAM_CH06]);
52 buf->vb.state = VIDEOBUF_ACTIVE;
53 buf->count = q->count++;
54 mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
55 dprintk(2,
56 "[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
57 buf, buf->vb.i, buf->count, q->count);
58 } else {
59 prev =
60 list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
61 if (prev->vb.width == buf->vb.width
62 && prev->vb.height == buf->vb.height
63 && prev->fmt == buf->fmt) {
64 list_add_tail(&buf->vb.queue, &q->active);
65 buf->vb.state = VIDEOBUF_ACTIVE;
66 buf->count = q->count++;
67 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
68
69 /* 64 bit bits 63-32 */
70 prev->risc.jmp[2] = cpu_to_le32(0);
71 dprintk(2,
72 "[%p/%d] buffer_queue - append to active, buf->count=%d\n",
73 buf, buf->vb.i, buf->count);
74
75 } else {
76 list_add_tail(&buf->vb.queue, &q->queued);
77 buf->vb.state = VIDEOBUF_QUEUED;
78 dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf,
79 buf->vb.i);
80 }
81 }
82
83 if (list_empty(&q->active)) {
84 dprintk(2, "active queue empty!\n");
85 }
86}
87
88static struct videobuf_queue_ops cx25821_video_qops = {
89 .buf_setup = cx25821_buffer_setup,
90 .buf_prepare = cx25821_buffer_prepare,
91 .buf_queue = buffer_queue,
92 .buf_release = cx25821_buffer_release,
93};
94
95static int video_open(struct file *file)
96{
97 struct video_device *vdev = video_devdata(file);
98 struct cx25821_dev *dev = video_drvdata(file);
99 struct cx25821_fh *fh;
100 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
101 u32 pix_format;
102
103 printk("open dev=%s type=%s\n", video_device_node_name(vdev),
104 v4l2_type_names[type]);
105
106 /* allocate + initialize per filehandle data */
107 fh = kzalloc(sizeof(*fh), GFP_KERNEL);
108 if (NULL == fh)
109 return -ENOMEM;
110
111 lock_kernel();
112
113 file->private_data = fh;
114 fh->dev = dev;
115 fh->type = type;
116 fh->width = 720;
117
118 if (dev->tvnorm & V4L2_STD_PAL_BG || dev->tvnorm & V4L2_STD_PAL_DK)
119 fh->height = 576;
120 else
121 fh->height = 480;
122
123 dev->channel_opened = SRAM_CH06;
124 pix_format =
125 (dev->pixel_formats[dev->channel_opened] ==
126 PIXEL_FRMT_411) ? V4L2_PIX_FMT_Y41P : V4L2_PIX_FMT_YUYV;
127 fh->fmt = format_by_fourcc(pix_format);
128
129 v4l2_prio_open(&dev->prio, &fh->prio);
130
131 videobuf_queue_sg_init(&fh->vidq, &cx25821_video_qops,
132 &dev->pci->dev, &dev->slock,
133 V4L2_BUF_TYPE_VIDEO_CAPTURE,
134 V4L2_FIELD_INTERLACED,
135 sizeof(struct cx25821_buffer), fh);
136
137 dprintk(1, "post videobuf_queue_init()\n");
138 unlock_kernel();
139
140 return 0;
141}
142
143static ssize_t video_read(struct file *file, char __user * data, size_t count,
144 loff_t * ppos)
145{
146 struct cx25821_fh *fh = file->private_data;
147
148 switch (fh->type) {
149 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
150 if (cx25821_res_locked(fh->dev, RESOURCE_VIDEO6))
151 return -EBUSY;
152
153 return videobuf_read_one(&fh->vidq, data, count, ppos,
154 file->f_flags & O_NONBLOCK);
155
156 default:
157 BUG();
158 return 0;
159 }
160}
161
162static unsigned int video_poll(struct file *file,
163 struct poll_table_struct *wait)
164{
165 struct cx25821_fh *fh = file->private_data;
166 struct cx25821_buffer *buf;
167
168 if (cx25821_res_check(fh, RESOURCE_VIDEO6)) {
169 /* streaming capture */
170 if (list_empty(&fh->vidq.stream))
171 return POLLERR;
172 buf = list_entry(fh->vidq.stream.next,
173 struct cx25821_buffer, vb.stream);
174 } else {
175 /* read() capture */
176 buf = (struct cx25821_buffer *)fh->vidq.read_buf;
177 if (NULL == buf)
178 return POLLERR;
179 }
180
181 poll_wait(file, &buf->vb.done, wait);
182 if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR) {
183 if (buf->vb.state == VIDEOBUF_DONE) {
184 struct cx25821_dev *dev = fh->dev;
185
186 if (dev && dev->use_cif_resolution[SRAM_CH06]) {
187 u8 cam_id = *((char *)buf->vb.baddr + 3);
188 memcpy((char *)buf->vb.baddr,
189 (char *)buf->vb.baddr + (fh->width * 2),
190 (fh->width * 2));
191 *((char *)buf->vb.baddr + 3) = cam_id;
192 }
193 }
194
195 return POLLIN | POLLRDNORM;
196 }
197
198 return 0;
199}
200
201static int video_release(struct file *file)
202{
203 struct cx25821_fh *fh = file->private_data;
204 struct cx25821_dev *dev = fh->dev;
205
206 //stop the risc engine and fifo
207 cx_write(channel6->dma_ctl, 0); /* FIFO and RISC disable */
208
209 /* stop video capture */
210 if (cx25821_res_check(fh, RESOURCE_VIDEO6)) {
211 videobuf_queue_cancel(&fh->vidq);
212 cx25821_res_free(dev, fh, RESOURCE_VIDEO6);
213 }
214 if (fh->vidq.read_buf) {
215 cx25821_buffer_release(&fh->vidq, fh->vidq.read_buf);
216 kfree(fh->vidq.read_buf);
217 }
218
219 videobuf_mmap_free(&fh->vidq);
220
221 v4l2_prio_close(&dev->prio, fh->prio);
222 file->private_data = NULL;
223 kfree(fh);
224
225 return 0;
226}
227
228static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
229{
230 struct cx25821_fh *fh = priv;
231 struct cx25821_dev *dev = fh->dev;
232
233 if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)) {
234 return -EINVAL;
235 }
236
237 if (unlikely(i != fh->type)) {
238 return -EINVAL;
239 }
240
241 if (unlikely(!cx25821_res_get(dev, fh, cx25821_get_resource(fh, RESOURCE_VIDEO6)))) {
242 return -EBUSY;
243 }
244
245 return videobuf_streamon(get_queue(fh));
246}
247
248static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
249{
250 struct cx25821_fh *fh = priv;
251 struct cx25821_dev *dev = fh->dev;
252 int err, res;
253
254 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
255 return -EINVAL;
256 if (i != fh->type)
257 return -EINVAL;
258
259 res = cx25821_get_resource(fh, RESOURCE_VIDEO6);
260 err = videobuf_streamoff(get_queue(fh));
261 if (err < 0)
262 return err;
263 cx25821_res_free(dev, fh, res);
264 return 0;
265}
266
267static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
268 struct v4l2_format *f)
269{
270 struct cx25821_fh *fh = priv;
271 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
272 int err;
273 int pix_format = 0;
274
275 if (fh) {
276 err = v4l2_prio_check(&dev->prio, fh->prio);
277 if (0 != err)
278 return err;
279 }
280
281 dprintk(2, "%s()\n", __func__);
282 err = cx25821_vidioc_try_fmt_vid_cap(file, priv, f);
283
284 if (0 != err)
285 return err;
286
287 fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat);
288 fh->vidq.field = f->fmt.pix.field;
289
290 // check if width and height is valid based on set standard
291 if (cx25821_is_valid_width(f->fmt.pix.width, dev->tvnorm)) {
292 fh->width = f->fmt.pix.width;
293 }
294
295 if (cx25821_is_valid_height(f->fmt.pix.height, dev->tvnorm)) {
296 fh->height = f->fmt.pix.height;
297 }
298
299 if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_Y41P)
300 pix_format = PIXEL_FRMT_411;
301 else if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_YUYV)
302 pix_format = PIXEL_FRMT_422;
303 else
304 return -EINVAL;
305
306 cx25821_set_pixel_format(dev, SRAM_CH06, pix_format);
307
308 // check if cif resolution
309 if (fh->width == 320 || fh->width == 352) {
310 dev->use_cif_resolution[SRAM_CH06] = 1;
311 } else {
312 dev->use_cif_resolution[SRAM_CH06] = 0;
313 }
314 dev->cif_width[SRAM_CH06] = fh->width;
315 medusa_set_resolution(dev, fh->width, SRAM_CH06);
316
317 dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width,
318 fh->height, fh->vidq.field);
319 cx25821_call_all(dev, video, s_fmt, f);
320
321 return 0;
322}
323
324static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
325{
326 int ret_val = 0;
327 struct cx25821_fh *fh = priv;
328 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
329
330 ret_val = videobuf_dqbuf(get_queue(fh), p, file->f_flags & O_NONBLOCK);
331
332 p->sequence = dev->vidq[SRAM_CH06].count;
333
334 return ret_val;
335}
336
337static int vidioc_log_status(struct file *file, void *priv)
338{
339 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
340 char name[32 + 2];
341
342 struct sram_channel *sram_ch = &dev->sram_channels[SRAM_CH06];
343 u32 tmp = 0;
344
345 snprintf(name, sizeof(name), "%s/2", dev->name);
346 printk(KERN_INFO "%s/2: ============ START LOG STATUS ============\n",
347 dev->name);
348 cx25821_call_all(dev, core, log_status);
349
350 tmp = cx_read(sram_ch->dma_ctl);
351 printk(KERN_INFO "Video input 6 is %s\n",
352 (tmp & 0x11) ? "streaming" : "stopped");
353 printk(KERN_INFO "%s/2: ============= END LOG STATUS =============\n",
354 dev->name);
355 return 0;
356}
357
358static int vidioc_s_ctrl(struct file *file, void *priv,
359 struct v4l2_control *ctl)
360{
361 struct cx25821_fh *fh = priv;
362 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
363 int err;
364
365 if (fh) {
366 err = v4l2_prio_check(&dev->prio, fh->prio);
367 if (0 != err)
368 return err;
369 }
370
371 return cx25821_set_control(dev, ctl, SRAM_CH06);
372}
373
374// exported stuff
375static const struct v4l2_file_operations video_fops = {
376 .owner = THIS_MODULE,
377 .open = video_open,
378 .release = video_release,
379 .read = video_read,
380 .poll = video_poll,
381 .mmap = cx25821_video_mmap,
382 .ioctl = video_ioctl2,
383};
384
385static const struct v4l2_ioctl_ops video_ioctl_ops = {
386 .vidioc_querycap = cx25821_vidioc_querycap,
387 .vidioc_enum_fmt_vid_cap = cx25821_vidioc_enum_fmt_vid_cap,
388 .vidioc_g_fmt_vid_cap = cx25821_vidioc_g_fmt_vid_cap,
389 .vidioc_try_fmt_vid_cap = cx25821_vidioc_try_fmt_vid_cap,
390 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
391 .vidioc_reqbufs = cx25821_vidioc_reqbufs,
392 .vidioc_querybuf = cx25821_vidioc_querybuf,
393 .vidioc_qbuf = cx25821_vidioc_qbuf,
394 .vidioc_dqbuf = vidioc_dqbuf,
395#ifdef TUNER_FLAG
396 .vidioc_s_std = cx25821_vidioc_s_std,
397 .vidioc_querystd = cx25821_vidioc_querystd,
398#endif
399 .vidioc_cropcap = cx25821_vidioc_cropcap,
400 .vidioc_s_crop = cx25821_vidioc_s_crop,
401 .vidioc_g_crop = cx25821_vidioc_g_crop,
402 .vidioc_enum_input = cx25821_vidioc_enum_input,
403 .vidioc_g_input = cx25821_vidioc_g_input,
404 .vidioc_s_input = cx25821_vidioc_s_input,
405 .vidioc_g_ctrl = cx25821_vidioc_g_ctrl,
406 .vidioc_s_ctrl = vidioc_s_ctrl,
407 .vidioc_queryctrl = cx25821_vidioc_queryctrl,
408 .vidioc_streamon = vidioc_streamon,
409 .vidioc_streamoff = vidioc_streamoff,
410 .vidioc_log_status = vidioc_log_status,
411 .vidioc_g_priority = cx25821_vidioc_g_priority,
412 .vidioc_s_priority = cx25821_vidioc_s_priority,
413#ifdef CONFIG_VIDEO_V4L1_COMPAT
414 .vidiocgmbuf = cx25821_vidiocgmbuf,
415#endif
416#ifdef TUNER_FLAG
417 .vidioc_g_tuner = cx25821_vidioc_g_tuner,
418 .vidioc_s_tuner = cx25821_vidioc_s_tuner,
419 .vidioc_g_frequency = cx25821_vidioc_g_frequency,
420 .vidioc_s_frequency = cx25821_vidioc_s_frequency,
421#endif
422#ifdef CONFIG_VIDEO_ADV_DEBUG
423 .vidioc_g_register = cx25821_vidioc_g_register,
424 .vidioc_s_register = cx25821_vidioc_s_register,
425#endif
426};
427
428struct video_device cx25821_video_template6 = {
429 .name = "cx25821-video",
430 .fops = &video_fops,
431 .ioctl_ops = &video_ioctl_ops,
432 .tvnorms = CX25821_NORMS,
433 .current_norm = V4L2_STD_NTSC_M,
434};
diff --git a/drivers/staging/cx25821/cx25821-video7.c b/drivers/staging/cx25821/cx25821-video7.c
deleted file mode 100644
index 5e4a769badad..000000000000
--- a/drivers/staging/cx25821/cx25821-video7.c
+++ /dev/null
@@ -1,433 +0,0 @@
1/*
2 * Driver for the Conexant CX25821 PCIe bridge
3 *
4 * Copyright (C) 2009 Conexant Systems Inc.
5 * Authors <shu.lin@conexant.com>, <hiep.huynh@conexant.com>
6 * Based on Steven Toth <stoth@linuxtv.org> cx23885 driver
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 *
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#include "cx25821-video.h"
25
26static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
27{
28 struct cx25821_buffer *buf =
29 container_of(vb, struct cx25821_buffer, vb);
30 struct cx25821_buffer *prev;
31 struct cx25821_fh *fh = vq->priv_data;
32 struct cx25821_dev *dev = fh->dev;
33 struct cx25821_dmaqueue *q = &dev->vidq[SRAM_CH07];
34
35 /* add jump to stopper */
36 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
37 buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma);
38 buf->risc.jmp[2] = cpu_to_le32(0); /* bits 63-32 */
39
40 dprintk(2, "jmp to stopper (0x%x)\n", buf->risc.jmp[1]);
41 if (!list_empty(&q->queued)) {
42 list_add_tail(&buf->vb.queue, &q->queued);
43 buf->vb.state = VIDEOBUF_QUEUED;
44 dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf,
45 buf->vb.i);
46
47 } else if (list_empty(&q->active)) {
48 list_add_tail(&buf->vb.queue, &q->active);
49 cx25821_start_video_dma(dev, q, buf,
50 &dev->sram_channels[SRAM_CH07]);
51 buf->vb.state = VIDEOBUF_ACTIVE;
52 buf->count = q->count++;
53 mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
54 dprintk(2,
55 "[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
56 buf, buf->vb.i, buf->count, q->count);
57 } else {
58 prev =
59 list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
60 if (prev->vb.width == buf->vb.width
61 && prev->vb.height == buf->vb.height
62 && prev->fmt == buf->fmt) {
63 list_add_tail(&buf->vb.queue, &q->active);
64 buf->vb.state = VIDEOBUF_ACTIVE;
65 buf->count = q->count++;
66 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
67
68 /* 64 bit bits 63-32 */
69 prev->risc.jmp[2] = cpu_to_le32(0);
70 dprintk(2,
71 "[%p/%d] buffer_queue - append to active, buf->count=%d\n",
72 buf, buf->vb.i, buf->count);
73
74 } else {
75 list_add_tail(&buf->vb.queue, &q->queued);
76 buf->vb.state = VIDEOBUF_QUEUED;
77 dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf,
78 buf->vb.i);
79 }
80 }
81
82 if (list_empty(&q->active)) {
83 dprintk(2, "active queue empty!\n");
84 }
85}
86
87static struct videobuf_queue_ops cx25821_video_qops = {
88 .buf_setup = cx25821_buffer_setup,
89 .buf_prepare = cx25821_buffer_prepare,
90 .buf_queue = buffer_queue,
91 .buf_release = cx25821_buffer_release,
92};
93
94static int video_open(struct file *file)
95{
96 struct video_device *vdev = video_devdata(file);
97 struct cx25821_dev *dev = video_drvdata(file);
98 struct cx25821_fh *fh;
99 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
100 u32 pix_format;
101
102 printk("open dev=%s type=%s\n", video_device_node_name(vdev),
103 v4l2_type_names[type]);
104
105 /* allocate + initialize per filehandle data */
106 fh = kzalloc(sizeof(*fh), GFP_KERNEL);
107 if (NULL == fh)
108 return -ENOMEM;
109
110 lock_kernel();
111
112 file->private_data = fh;
113 fh->dev = dev;
114 fh->type = type;
115 fh->width = 720;
116
117 if (dev->tvnorm & V4L2_STD_PAL_BG || dev->tvnorm & V4L2_STD_PAL_DK)
118 fh->height = 576;
119 else
120 fh->height = 480;
121
122 dev->channel_opened = SRAM_CH07;
123 pix_format =
124 (dev->pixel_formats[dev->channel_opened] ==
125 PIXEL_FRMT_411) ? V4L2_PIX_FMT_Y41P : V4L2_PIX_FMT_YUYV;
126 fh->fmt = format_by_fourcc(pix_format);
127
128 v4l2_prio_open(&dev->prio, &fh->prio);
129
130 videobuf_queue_sg_init(&fh->vidq, &cx25821_video_qops,
131 &dev->pci->dev, &dev->slock,
132 V4L2_BUF_TYPE_VIDEO_CAPTURE,
133 V4L2_FIELD_INTERLACED,
134 sizeof(struct cx25821_buffer), fh);
135
136 dprintk(1, "post videobuf_queue_init()\n");
137 unlock_kernel();
138
139 return 0;
140}
141
142static ssize_t video_read(struct file *file, char __user * data, size_t count,
143 loff_t * ppos)
144{
145 struct cx25821_fh *fh = file->private_data;
146
147 switch (fh->type) {
148 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
149 if (cx25821_res_locked(fh->dev, RESOURCE_VIDEO7))
150 return -EBUSY;
151
152 return videobuf_read_one(&fh->vidq, data, count, ppos,
153 file->f_flags & O_NONBLOCK);
154
155 default:
156 BUG();
157 return 0;
158 }
159}
160
161static unsigned int video_poll(struct file *file,
162 struct poll_table_struct *wait)
163{
164 struct cx25821_fh *fh = file->private_data;
165 struct cx25821_buffer *buf;
166
167 if (cx25821_res_check(fh, RESOURCE_VIDEO7)) {
168 /* streaming capture */
169 if (list_empty(&fh->vidq.stream))
170 return POLLERR;
171 buf = list_entry(fh->vidq.stream.next,
172 struct cx25821_buffer, vb.stream);
173 } else {
174 /* read() capture */
175 buf = (struct cx25821_buffer *)fh->vidq.read_buf;
176 if (NULL == buf)
177 return POLLERR;
178 }
179
180 poll_wait(file, &buf->vb.done, wait);
181 if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR) {
182 if (buf->vb.state == VIDEOBUF_DONE) {
183 struct cx25821_dev *dev = fh->dev;
184
185 if (dev && dev->use_cif_resolution[SRAM_CH07]) {
186 u8 cam_id = *((char *)buf->vb.baddr + 3);
187 memcpy((char *)buf->vb.baddr,
188 (char *)buf->vb.baddr + (fh->width * 2),
189 (fh->width * 2));
190 *((char *)buf->vb.baddr + 3) = cam_id;
191 }
192 }
193
194 return POLLIN | POLLRDNORM;
195 }
196
197 return 0;
198}
199
200static int video_release(struct file *file)
201{
202 struct cx25821_fh *fh = file->private_data;
203 struct cx25821_dev *dev = fh->dev;
204
205 //stop the risc engine and fifo
206 cx_write(channel7->dma_ctl, 0); /* FIFO and RISC disable */
207
208 /* stop video capture */
209 if (cx25821_res_check(fh, RESOURCE_VIDEO7)) {
210 videobuf_queue_cancel(&fh->vidq);
211 cx25821_res_free(dev, fh, RESOURCE_VIDEO7);
212 }
213
214 if (fh->vidq.read_buf) {
215 cx25821_buffer_release(&fh->vidq, fh->vidq.read_buf);
216 kfree(fh->vidq.read_buf);
217 }
218
219 videobuf_mmap_free(&fh->vidq);
220
221 v4l2_prio_close(&dev->prio, fh->prio);
222 file->private_data = NULL;
223 kfree(fh);
224
225 return 0;
226}
227
228static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
229{
230 struct cx25821_fh *fh = priv;
231 struct cx25821_dev *dev = fh->dev;
232
233 if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)) {
234 return -EINVAL;
235 }
236
237 if (unlikely(i != fh->type)) {
238 return -EINVAL;
239 }
240
241 if (unlikely(!cx25821_res_get(dev, fh, cx25821_get_resource(fh, RESOURCE_VIDEO7)))) {
242 return -EBUSY;
243 }
244
245 return videobuf_streamon(get_queue(fh));
246}
247
248static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
249{
250 struct cx25821_fh *fh = priv;
251 struct cx25821_dev *dev = fh->dev;
252 int err, res;
253
254 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
255 return -EINVAL;
256 if (i != fh->type)
257 return -EINVAL;
258
259 res = cx25821_get_resource(fh, RESOURCE_VIDEO7);
260 err = videobuf_streamoff(get_queue(fh));
261 if (err < 0)
262 return err;
263 cx25821_res_free(dev, fh, res);
264 return 0;
265}
266
267static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
268 struct v4l2_format *f)
269{
270 struct cx25821_fh *fh = priv;
271 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
272 int err;
273 int pix_format = 0;
274
275 if (fh) {
276 err = v4l2_prio_check(&dev->prio, fh->prio);
277 if (0 != err)
278 return err;
279 }
280
281 dprintk(2, "%s()\n", __func__);
282 err = cx25821_vidioc_try_fmt_vid_cap(file, priv, f);
283
284 if (0 != err)
285 return err;
286
287 fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat);
288 fh->vidq.field = f->fmt.pix.field;
289
290 // check if width and height is valid based on set standard
291 if (cx25821_is_valid_width(f->fmt.pix.width, dev->tvnorm)) {
292 fh->width = f->fmt.pix.width;
293 }
294
295 if (cx25821_is_valid_height(f->fmt.pix.height, dev->tvnorm)) {
296 fh->height = f->fmt.pix.height;
297 }
298
299 if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_Y41P)
300 pix_format = PIXEL_FRMT_411;
301 else if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_YUYV)
302 pix_format = PIXEL_FRMT_422;
303 else
304 return -EINVAL;
305
306 cx25821_set_pixel_format(dev, SRAM_CH07, pix_format);
307
308 // check if cif resolution
309 if (fh->width == 320 || fh->width == 352) {
310 dev->use_cif_resolution[SRAM_CH07] = 1;
311 } else {
312 dev->use_cif_resolution[SRAM_CH07] = 0;
313 }
314 dev->cif_width[SRAM_CH07] = fh->width;
315 medusa_set_resolution(dev, fh->width, SRAM_CH07);
316
317 dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width,
318 fh->height, fh->vidq.field);
319 cx25821_call_all(dev, video, s_fmt, f);
320
321 return 0;
322}
323
324static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
325{
326 int ret_val = 0;
327 struct cx25821_fh *fh = priv;
328 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
329
330 ret_val = videobuf_dqbuf(get_queue(fh), p, file->f_flags & O_NONBLOCK);
331
332 p->sequence = dev->vidq[SRAM_CH07].count;
333
334 return ret_val;
335}
336static int vidioc_log_status(struct file *file, void *priv)
337{
338 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
339 char name[32 + 2];
340
341 struct sram_channel *sram_ch = &dev->sram_channels[SRAM_CH07];
342 u32 tmp = 0;
343
344 snprintf(name, sizeof(name), "%s/2", dev->name);
345 printk(KERN_INFO "%s/2: ============ START LOG STATUS ============\n",
346 dev->name);
347 cx25821_call_all(dev, core, log_status);
348
349 tmp = cx_read(sram_ch->dma_ctl);
350 printk(KERN_INFO "Video input 7 is %s\n",
351 (tmp & 0x11) ? "streaming" : "stopped");
352 printk(KERN_INFO "%s/2: ============= END LOG STATUS =============\n",
353 dev->name);
354 return 0;
355}
356
357static int vidioc_s_ctrl(struct file *file, void *priv,
358 struct v4l2_control *ctl)
359{
360 struct cx25821_fh *fh = priv;
361 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
362 int err;
363
364 if (fh) {
365 err = v4l2_prio_check(&dev->prio, fh->prio);
366 if (0 != err)
367 return err;
368 }
369
370 return cx25821_set_control(dev, ctl, SRAM_CH07);
371}
372
373// exported stuff
374static const struct v4l2_file_operations video_fops = {
375 .owner = THIS_MODULE,
376 .open = video_open,
377 .release = video_release,
378 .read = video_read,
379 .poll = video_poll,
380 .mmap = cx25821_video_mmap,
381 .ioctl = video_ioctl2,
382};
383
384static const struct v4l2_ioctl_ops video_ioctl_ops = {
385 .vidioc_querycap = cx25821_vidioc_querycap,
386 .vidioc_enum_fmt_vid_cap = cx25821_vidioc_enum_fmt_vid_cap,
387 .vidioc_g_fmt_vid_cap = cx25821_vidioc_g_fmt_vid_cap,
388 .vidioc_try_fmt_vid_cap = cx25821_vidioc_try_fmt_vid_cap,
389 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
390 .vidioc_reqbufs = cx25821_vidioc_reqbufs,
391 .vidioc_querybuf = cx25821_vidioc_querybuf,
392 .vidioc_qbuf = cx25821_vidioc_qbuf,
393 .vidioc_dqbuf = vidioc_dqbuf,
394#ifdef TUNER_FLAG
395 .vidioc_s_std = cx25821_vidioc_s_std,
396 .vidioc_querystd = cx25821_vidioc_querystd,
397#endif
398 .vidioc_cropcap = cx25821_vidioc_cropcap,
399 .vidioc_s_crop = cx25821_vidioc_s_crop,
400 .vidioc_g_crop = cx25821_vidioc_g_crop,
401 .vidioc_enum_input = cx25821_vidioc_enum_input,
402 .vidioc_g_input = cx25821_vidioc_g_input,
403 .vidioc_s_input = cx25821_vidioc_s_input,
404 .vidioc_g_ctrl = cx25821_vidioc_g_ctrl,
405 .vidioc_s_ctrl = vidioc_s_ctrl,
406 .vidioc_queryctrl = cx25821_vidioc_queryctrl,
407 .vidioc_streamon = vidioc_streamon,
408 .vidioc_streamoff = vidioc_streamoff,
409 .vidioc_log_status = vidioc_log_status,
410 .vidioc_g_priority = cx25821_vidioc_g_priority,
411 .vidioc_s_priority = cx25821_vidioc_s_priority,
412#ifdef CONFIG_VIDEO_V4L1_COMPAT
413 .vidiocgmbuf = cx25821_vidiocgmbuf,
414#endif
415#ifdef TUNER_FLAG
416 .vidioc_g_tuner = cx25821_vidioc_g_tuner,
417 .vidioc_s_tuner = cx25821_vidioc_s_tuner,
418 .vidioc_g_frequency = cx25821_vidioc_g_frequency,
419 .vidioc_s_frequency = cx25821_vidioc_s_frequency,
420#endif
421#ifdef CONFIG_VIDEO_ADV_DEBUG
422 .vidioc_g_register = cx25821_vidioc_g_register,
423 .vidioc_s_register = cx25821_vidioc_s_register,
424#endif
425};
426
427struct video_device cx25821_video_template7 = {
428 .name = "cx25821-video",
429 .fops = &video_fops,
430 .ioctl_ops = &video_ioctl_ops,
431 .tvnorms = CX25821_NORMS,
432 .current_norm = V4L2_STD_NTSC_M,
433};
diff --git a/drivers/staging/cx25821/cx25821-videoioctl.c b/drivers/staging/cx25821/cx25821-videoioctl.c
deleted file mode 100644
index d16807d88be0..000000000000
--- a/drivers/staging/cx25821/cx25821-videoioctl.c
+++ /dev/null
@@ -1,480 +0,0 @@
1/*
2 * Driver for the Conexant CX25821 PCIe bridge
3 *
4 * Copyright (C) 2009 Conexant Systems Inc.
5 * Authors <shu.lin@conexant.com>, <hiep.huynh@conexant.com>
6 * Based on Steven Toth <stoth@linuxtv.org> cx23885 driver
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 *
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#include "cx25821-video.h"
25
26static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
27{
28 struct cx25821_buffer *buf =
29 container_of(vb, struct cx25821_buffer, vb);
30 struct cx25821_buffer *prev;
31 struct cx25821_fh *fh = vq->priv_data;
32 struct cx25821_dev *dev = fh->dev;
33 struct cx25821_dmaqueue *q = &dev->vidq[VIDEO_IOCTL_CH];
34
35 /* add jump to stopper */
36 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
37 buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma);
38 buf->risc.jmp[2] = cpu_to_le32(0); /* bits 63-32 */
39
40 dprintk(2, "jmp to stopper (0x%x)\n", buf->risc.jmp[1]);
41
42 if (!list_empty(&q->queued)) {
43 list_add_tail(&buf->vb.queue, &q->queued);
44 buf->vb.state = VIDEOBUF_QUEUED;
45 dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf,
46 buf->vb.i);
47
48 } else if (list_empty(&q->active)) {
49 list_add_tail(&buf->vb.queue, &q->active);
50 cx25821_start_video_dma(dev, q, buf,
51 &dev->sram_channels[VIDEO_IOCTL_CH]);
52 buf->vb.state = VIDEOBUF_ACTIVE;
53 buf->count = q->count++;
54 mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
55 dprintk(2,
56 "[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
57 buf, buf->vb.i, buf->count, q->count);
58 } else {
59 prev =
60 list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
61 if (prev->vb.width == buf->vb.width
62 && prev->vb.height == buf->vb.height
63 && prev->fmt == buf->fmt) {
64 list_add_tail(&buf->vb.queue, &q->active);
65 buf->vb.state = VIDEOBUF_ACTIVE;
66 buf->count = q->count++;
67 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
68
69 /* 64 bit bits 63-32 */
70 prev->risc.jmp[2] = cpu_to_le32(0);
71 dprintk(2,
72 "[%p/%d] buffer_queue - append to active, buf->count=%d\n",
73 buf, buf->vb.i, buf->count);
74
75 } else {
76 list_add_tail(&buf->vb.queue, &q->queued);
77 buf->vb.state = VIDEOBUF_QUEUED;
78 dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf,
79 buf->vb.i);
80 }
81 }
82
83 if (list_empty(&q->active)) {
84 dprintk(2, "active queue empty!\n");
85 }
86}
87
88static struct videobuf_queue_ops cx25821_video_qops = {
89 .buf_setup = cx25821_buffer_setup,
90 .buf_prepare = cx25821_buffer_prepare,
91 .buf_queue = buffer_queue,
92 .buf_release = cx25821_buffer_release,
93};
94
95static int video_open(struct file *file)
96{
97 struct video_device *vdev = video_devdata(file);
98 struct cx25821_dev *dev = video_drvdata(file);
99 struct cx25821_fh *fh;
100 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
101 u32 pix_format;
102
103 printk("open dev=%s type=%s\n", video_device_node_name(vdev),
104 v4l2_type_names[type]);
105
106 /* allocate + initialize per filehandle data */
107 fh = kzalloc(sizeof(*fh), GFP_KERNEL);
108 if (NULL == fh)
109 return -ENOMEM;
110
111 lock_kernel();
112
113 file->private_data = fh;
114 fh->dev = dev;
115 fh->type = type;
116 fh->width = 720;
117
118 if (dev->tvnorm & V4L2_STD_PAL_BG || dev->tvnorm & V4L2_STD_PAL_DK)
119 fh->height = 576;
120 else
121 fh->height = 480;
122
123 dev->channel_opened = VIDEO_IOCTL_CH;
124 pix_format = V4L2_PIX_FMT_YUYV;
125 fh->fmt = format_by_fourcc(pix_format);
126
127 v4l2_prio_open(&dev->prio, &fh->prio);
128
129 videobuf_queue_sg_init(&fh->vidq, &cx25821_video_qops,
130 &dev->pci->dev, &dev->slock,
131 V4L2_BUF_TYPE_VIDEO_CAPTURE,
132 V4L2_FIELD_INTERLACED,
133 sizeof(struct cx25821_buffer), fh);
134
135 dprintk(1, "post videobuf_queue_init()\n");
136 unlock_kernel();
137
138 return 0;
139}
140
141static ssize_t video_read(struct file *file, char __user * data, size_t count,
142 loff_t * ppos)
143{
144 struct cx25821_fh *fh = file->private_data;
145
146 switch (fh->type) {
147 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
148 if (cx25821_res_locked(fh->dev, RESOURCE_VIDEO_IOCTL))
149 return -EBUSY;
150
151 return videobuf_read_one(&fh->vidq, data, count, ppos,
152 file->f_flags & O_NONBLOCK);
153
154 default:
155 BUG();
156 return 0;
157 }
158}
159
160static unsigned int video_poll(struct file *file,
161 struct poll_table_struct *wait)
162{
163 struct cx25821_fh *fh = file->private_data;
164 struct cx25821_buffer *buf;
165
166 if (cx25821_res_check(fh, RESOURCE_VIDEO_IOCTL)) {
167 /* streaming capture */
168 if (list_empty(&fh->vidq.stream))
169 return POLLERR;
170 buf = list_entry(fh->vidq.stream.next,
171 struct cx25821_buffer, vb.stream);
172 } else {
173 /* read() capture */
174 buf = (struct cx25821_buffer *)fh->vidq.read_buf;
175 if (NULL == buf)
176 return POLLERR;
177 }
178
179 poll_wait(file, &buf->vb.done, wait);
180 if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR)
181 return POLLIN | POLLRDNORM;
182
183 return 0;
184}
185
186static int video_release(struct file *file)
187{
188 struct cx25821_fh *fh = file->private_data;
189 struct cx25821_dev *dev = fh->dev;
190
191 /* stop video capture */
192 if (cx25821_res_check(fh, RESOURCE_VIDEO_IOCTL)) {
193 videobuf_queue_cancel(&fh->vidq);
194 cx25821_res_free(dev, fh, RESOURCE_VIDEO_IOCTL);
195 }
196
197 if (fh->vidq.read_buf) {
198 cx25821_buffer_release(&fh->vidq, fh->vidq.read_buf);
199 kfree(fh->vidq.read_buf);
200 }
201
202 videobuf_mmap_free(&fh->vidq);
203
204 v4l2_prio_close(&dev->prio, fh->prio);
205
206 file->private_data = NULL;
207 kfree(fh);
208
209 return 0;
210}
211
212static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
213{
214 struct cx25821_fh *fh = priv;
215 struct cx25821_dev *dev = fh->dev;
216
217 if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)) {
218 return -EINVAL;
219 }
220
221 if (unlikely(i != fh->type)) {
222 return -EINVAL;
223 }
224
225 if (unlikely(!cx25821_res_get(dev, fh, cx25821_get_resource(fh, RESOURCE_VIDEO_IOCTL)))) {
226 return -EBUSY;
227 }
228
229 return videobuf_streamon(get_queue(fh));
230}
231
232static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
233{
234 struct cx25821_fh *fh = priv;
235 struct cx25821_dev *dev = fh->dev;
236 int err, res;
237
238 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
239 return -EINVAL;
240 if (i != fh->type)
241 return -EINVAL;
242
243 res = cx25821_get_resource(fh, RESOURCE_VIDEO_IOCTL);
244 err = videobuf_streamoff(get_queue(fh));
245 if (err < 0)
246 return err;
247 cx25821_res_free(dev, fh, res);
248 return 0;
249}
250
251static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
252 struct v4l2_format *f)
253{
254 struct cx25821_fh *fh = priv;
255 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
256 int err;
257
258 if (fh) {
259 err = v4l2_prio_check(&dev->prio, fh->prio);
260 if (0 != err)
261 return err;
262 }
263
264 dprintk(2, "%s()\n", __func__);
265 err = cx25821_vidioc_try_fmt_vid_cap(file, priv, f);
266
267 if (0 != err)
268 return err;
269 fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat);
270 fh->width = f->fmt.pix.width;
271 fh->height = f->fmt.pix.height;
272 fh->vidq.field = f->fmt.pix.field;
273 dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width,
274 fh->height, fh->vidq.field);
275 cx25821_call_all(dev, video, s_fmt, f);
276 return 0;
277}
278
279static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
280{
281 struct cx25821_fh *fh = priv;
282 return videobuf_dqbuf(get_queue(fh), p, file->f_flags & O_NONBLOCK);
283}
284
285static long video_ioctl_set(struct file *file, unsigned int cmd,
286 unsigned long arg)
287{
288 struct cx25821_fh *fh = file->private_data;
289 struct cx25821_dev *dev = fh->dev;
290 struct downstream_user_struct *data_from_user;
291 int command;
292 int width = 720;
293 int selected_channel = 0, pix_format = 0, i = 0;
294 int cif_enable = 0, cif_width = 0;
295 u32 value = 0;
296
297 data_from_user = (struct downstream_user_struct *)arg;
298
299 if (!data_from_user) {
300 printk("cx25821 in %s(): User data is INVALID. Returning.\n",
301 __func__);
302 return 0;
303 }
304
305 command = data_from_user->command;
306
307 if (command != SET_VIDEO_STD && command != SET_PIXEL_FORMAT
308 && command != ENABLE_CIF_RESOLUTION && command != REG_READ
309 && command != REG_WRITE && command != MEDUSA_READ
310 && command != MEDUSA_WRITE) {
311 return 0;
312 }
313
314 switch (command) {
315 case SET_VIDEO_STD:
316 dev->tvnorm =
317 !strcmp(data_from_user->vid_stdname,
318 "PAL") ? V4L2_STD_PAL_BG : V4L2_STD_NTSC_M;
319 medusa_set_videostandard(dev);
320 break;
321
322 case SET_PIXEL_FORMAT:
323 selected_channel = data_from_user->decoder_select;
324 pix_format = data_from_user->pixel_format;
325
326 if (!(selected_channel <= 7 && selected_channel >= 0)) {
327 selected_channel -= 4;
328 selected_channel = selected_channel % 8;
329 }
330
331 if (selected_channel >= 0)
332 cx25821_set_pixel_format(dev, selected_channel,
333 pix_format);
334
335 break;
336
337 case ENABLE_CIF_RESOLUTION:
338 selected_channel = data_from_user->decoder_select;
339 cif_enable = data_from_user->cif_resolution_enable;
340 cif_width = data_from_user->cif_width;
341
342 if (cif_enable) {
343 if (dev->tvnorm & V4L2_STD_PAL_BG
344 || dev->tvnorm & V4L2_STD_PAL_DK)
345 width = 352;
346 else
347 width = (cif_width == 320
348 || cif_width == 352) ? cif_width : 320;
349 }
350
351 if (!(selected_channel <= 7 && selected_channel >= 0)) {
352 selected_channel -= 4;
353 selected_channel = selected_channel % 8;
354 }
355
356 if (selected_channel <= 7 && selected_channel >= 0) {
357 dev->use_cif_resolution[selected_channel] = cif_enable;
358 dev->cif_width[selected_channel] = width;
359 } else {
360 for (i = 0; i < VID_CHANNEL_NUM; i++) {
361 dev->use_cif_resolution[i] = cif_enable;
362 dev->cif_width[i] = width;
363 }
364 }
365
366 medusa_set_resolution(dev, width, selected_channel);
367 break;
368 case REG_READ:
369 data_from_user->reg_data = cx_read(data_from_user->reg_address);
370 break;
371 case REG_WRITE:
372 cx_write(data_from_user->reg_address, data_from_user->reg_data);
373 break;
374 case MEDUSA_READ:
375 value =
376 cx25821_i2c_read(&dev->i2c_bus[0],
377 (u16) data_from_user->reg_address,
378 &data_from_user->reg_data);
379 break;
380 case MEDUSA_WRITE:
381 cx25821_i2c_write(&dev->i2c_bus[0],
382 (u16) data_from_user->reg_address,
383 data_from_user->reg_data);
384 break;
385 }
386
387 return 0;
388}
389
390static int vidioc_log_status(struct file *file, void *priv)
391{
392 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
393 char name[32 + 2];
394
395 snprintf(name, sizeof(name), "%s/2", dev->name);
396 printk(KERN_INFO "%s/2: ============ START LOG STATUS ============\n",
397 dev->name);
398 cx25821_call_all(dev, core, log_status);
399 printk(KERN_INFO "%s/2: ============= END LOG STATUS =============\n",
400 dev->name);
401 return 0;
402}
403
404static int vidioc_s_ctrl(struct file *file, void *priv,
405 struct v4l2_control *ctl)
406{
407 struct cx25821_fh *fh = priv;
408 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
409 int err;
410
411 if (fh) {
412 err = v4l2_prio_check(&dev->prio, fh->prio);
413 if (0 != err)
414 return err;
415 }
416
417 return 0;
418}
419
420// exported stuff
421static const struct v4l2_file_operations video_fops = {
422 .owner = THIS_MODULE,
423 .open = video_open,
424 .release = video_release,
425 .read = video_read,
426 .poll = video_poll,
427 .mmap = cx25821_video_mmap,
428 .ioctl = video_ioctl_set,
429};
430
431static const struct v4l2_ioctl_ops video_ioctl_ops = {
432 .vidioc_querycap = cx25821_vidioc_querycap,
433 .vidioc_enum_fmt_vid_cap = cx25821_vidioc_enum_fmt_vid_cap,
434 .vidioc_g_fmt_vid_cap = cx25821_vidioc_g_fmt_vid_cap,
435 .vidioc_try_fmt_vid_cap = cx25821_vidioc_try_fmt_vid_cap,
436 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
437 .vidioc_reqbufs = cx25821_vidioc_reqbufs,
438 .vidioc_querybuf = cx25821_vidioc_querybuf,
439 .vidioc_qbuf = cx25821_vidioc_qbuf,
440 .vidioc_dqbuf = vidioc_dqbuf,
441#ifdef TUNER_FLAG
442 .vidioc_s_std = cx25821_vidioc_s_std,
443 .vidioc_querystd = cx25821_vidioc_querystd,
444#endif
445 .vidioc_cropcap = cx25821_vidioc_cropcap,
446 .vidioc_s_crop = cx25821_vidioc_s_crop,
447 .vidioc_g_crop = cx25821_vidioc_g_crop,
448 .vidioc_enum_input = cx25821_vidioc_enum_input,
449 .vidioc_g_input = cx25821_vidioc_g_input,
450 .vidioc_s_input = cx25821_vidioc_s_input,
451 .vidioc_g_ctrl = cx25821_vidioc_g_ctrl,
452 .vidioc_s_ctrl = vidioc_s_ctrl,
453 .vidioc_queryctrl = cx25821_vidioc_queryctrl,
454 .vidioc_streamon = vidioc_streamon,
455 .vidioc_streamoff = vidioc_streamoff,
456 .vidioc_log_status = vidioc_log_status,
457 .vidioc_g_priority = cx25821_vidioc_g_priority,
458 .vidioc_s_priority = cx25821_vidioc_s_priority,
459#ifdef CONFIG_VIDEO_V4L1_COMPAT
460 .vidiocgmbuf = cx25821_vidiocgmbuf,
461#endif
462#ifdef TUNER_FLAG
463 .vidioc_g_tuner = cx25821_vidioc_g_tuner,
464 .vidioc_s_tuner = cx25821_vidioc_s_tuner,
465 .vidioc_g_frequency = cx25821_vidioc_g_frequency,
466 .vidioc_s_frequency = cx25821_vidioc_s_frequency,
467#endif
468#ifdef CONFIG_VIDEO_ADV_DEBUG
469 .vidioc_g_register = cx25821_vidioc_g_register,
470 .vidioc_s_register = cx25821_vidioc_s_register,
471#endif
472};
473
474struct video_device cx25821_videoioctl_template = {
475 .name = "cx25821-videoioctl",
476 .fops = &video_fops,
477 .ioctl_ops = &video_ioctl_ops,
478 .tvnorms = CX25821_NORMS,
479 .current_norm = V4L2_STD_NTSC_M,
480};
diff --git a/drivers/staging/cx25821/cx25821-vidups10.c b/drivers/staging/cx25821/cx25821-vidups10.c
deleted file mode 100644
index c746a17ccbd2..000000000000
--- a/drivers/staging/cx25821/cx25821-vidups10.c
+++ /dev/null
@@ -1,418 +0,0 @@
1/*
2 * Driver for the Conexant CX25821 PCIe bridge
3 *
4 * Copyright (C) 2009 Conexant Systems Inc.
5 * Authors <shu.lin@conexant.com>, <hiep.huynh@conexant.com>
6 * Based on Steven Toth <stoth@linuxtv.org> cx23885 driver
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 *
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#include "cx25821-video.h"
25
26static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
27{
28 struct cx25821_buffer *buf =
29 container_of(vb, struct cx25821_buffer, vb);
30 struct cx25821_buffer *prev;
31 struct cx25821_fh *fh = vq->priv_data;
32 struct cx25821_dev *dev = fh->dev;
33 struct cx25821_dmaqueue *q = &dev->vidq[SRAM_CH10];
34
35 /* add jump to stopper */
36 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
37 buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma);
38 buf->risc.jmp[2] = cpu_to_le32(0); /* bits 63-32 */
39
40 dprintk(2, "jmp to stopper (0x%x)\n", buf->risc.jmp[1]);
41
42 if (!list_empty(&q->queued)) {
43 list_add_tail(&buf->vb.queue, &q->queued);
44 buf->vb.state = VIDEOBUF_QUEUED;
45 dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf,
46 buf->vb.i);
47
48 } else if (list_empty(&q->active)) {
49 list_add_tail(&buf->vb.queue, &q->active);
50 cx25821_start_video_dma(dev, q, buf,
51 &dev->sram_channels[SRAM_CH10]);
52 buf->vb.state = VIDEOBUF_ACTIVE;
53 buf->count = q->count++;
54 mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
55 dprintk(2,
56 "[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
57 buf, buf->vb.i, buf->count, q->count);
58 } else {
59 prev =
60 list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
61 if (prev->vb.width == buf->vb.width
62 && prev->vb.height == buf->vb.height
63 && prev->fmt == buf->fmt) {
64 list_add_tail(&buf->vb.queue, &q->active);
65 buf->vb.state = VIDEOBUF_ACTIVE;
66 buf->count = q->count++;
67 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
68
69 /* 64 bit bits 63-32 */
70 prev->risc.jmp[2] = cpu_to_le32(0);
71 dprintk(2,
72 "[%p/%d] buffer_queue - append to active, buf->count=%d\n",
73 buf, buf->vb.i, buf->count);
74
75 } else {
76 list_add_tail(&buf->vb.queue, &q->queued);
77 buf->vb.state = VIDEOBUF_QUEUED;
78 dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf,
79 buf->vb.i);
80 }
81 }
82
83 if (list_empty(&q->active)) {
84 dprintk(2, "active queue empty!\n");
85 }
86}
87
88static struct videobuf_queue_ops cx25821_video_qops = {
89 .buf_setup = cx25821_buffer_setup,
90 .buf_prepare = cx25821_buffer_prepare,
91 .buf_queue = buffer_queue,
92 .buf_release = cx25821_buffer_release,
93};
94
95static int video_open(struct file *file)
96{
97 struct video_device *vdev = video_devdata(file);
98 struct cx25821_dev *dev = video_drvdata(file);
99 struct cx25821_fh *fh;
100 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
101
102 printk("open dev=%s type=%s\n", video_device_node_name(vdev),
103 v4l2_type_names[type]);
104
105 /* allocate + initialize per filehandle data */
106 fh = kzalloc(sizeof(*fh), GFP_KERNEL);
107 if (NULL == fh)
108 return -ENOMEM;
109
110 lock_kernel();
111
112 file->private_data = fh;
113 fh->dev = dev;
114 fh->type = type;
115 fh->width = 720;
116
117 if (dev->tvnorm & V4L2_STD_PAL_BG || dev->tvnorm & V4L2_STD_PAL_DK)
118 fh->height = 576;
119 else
120 fh->height = 480;
121
122 dev->channel_opened = 9;
123 fh->fmt = format_by_fourcc(V4L2_PIX_FMT_YUYV);
124
125 v4l2_prio_open(&dev->prio, &fh->prio);
126
127 videobuf_queue_sg_init(&fh->vidq, &cx25821_video_qops,
128 &dev->pci->dev, &dev->slock,
129 V4L2_BUF_TYPE_VIDEO_CAPTURE,
130 V4L2_FIELD_INTERLACED,
131 sizeof(struct cx25821_buffer), fh);
132
133 dprintk(1, "post videobuf_queue_init()\n");
134 unlock_kernel();
135
136 return 0;
137}
138
139static ssize_t video_read(struct file *file, char __user * data, size_t count,
140 loff_t * ppos)
141{
142 struct cx25821_fh *fh = file->private_data;
143
144 switch (fh->type) {
145 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
146 if (cx25821_res_locked(fh->dev, RESOURCE_VIDEO10))
147 return -EBUSY;
148
149 return videobuf_read_one(&fh->vidq, data, count, ppos,
150 file->f_flags & O_NONBLOCK);
151
152 default:
153 BUG();
154 return 0;
155 }
156}
157
158static unsigned int video_poll(struct file *file,
159 struct poll_table_struct *wait)
160{
161 struct cx25821_fh *fh = file->private_data;
162 struct cx25821_buffer *buf;
163
164 if (cx25821_res_check(fh, RESOURCE_VIDEO10)) {
165 /* streaming capture */
166 if (list_empty(&fh->vidq.stream))
167 return POLLERR;
168 buf = list_entry(fh->vidq.stream.next,
169 struct cx25821_buffer, vb.stream);
170 } else {
171 /* read() capture */
172 buf = (struct cx25821_buffer *)fh->vidq.read_buf;
173 if (NULL == buf)
174 return POLLERR;
175 }
176
177 poll_wait(file, &buf->vb.done, wait);
178 if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR)
179 return POLLIN | POLLRDNORM;
180 return 0;
181}
182
183static int video_release(struct file *file)
184{
185 struct cx25821_fh *fh = file->private_data;
186 struct cx25821_dev *dev = fh->dev;
187
188 //stop the risc engine and fifo
189 //cx_write(channel10->dma_ctl, 0);
190
191 /* stop video capture */
192 if (cx25821_res_check(fh, RESOURCE_VIDEO10)) {
193 videobuf_queue_cancel(&fh->vidq);
194 cx25821_res_free(dev, fh, RESOURCE_VIDEO10);
195 }
196
197 if (fh->vidq.read_buf) {
198 cx25821_buffer_release(&fh->vidq, fh->vidq.read_buf);
199 kfree(fh->vidq.read_buf);
200 }
201
202 videobuf_mmap_free(&fh->vidq);
203
204 v4l2_prio_close(&dev->prio, fh->prio);
205
206 file->private_data = NULL;
207 kfree(fh);
208
209 return 0;
210}
211
212static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
213{
214 struct cx25821_fh *fh = priv;
215 struct cx25821_dev *dev = fh->dev;
216
217 if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)) {
218 return -EINVAL;
219 }
220
221 if (unlikely(i != fh->type)) {
222 return -EINVAL;
223 }
224
225 if (unlikely(!cx25821_res_get(dev, fh, cx25821_get_resource(fh, RESOURCE_VIDEO10)))) {
226 return -EBUSY;
227 }
228
229 return videobuf_streamon(get_queue(fh));
230}
231
232static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
233{
234 struct cx25821_fh *fh = priv;
235 struct cx25821_dev *dev = fh->dev;
236 int err, res;
237
238 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
239 return -EINVAL;
240 if (i != fh->type)
241 return -EINVAL;
242
243 res = cx25821_get_resource(fh, RESOURCE_VIDEO10);
244 err = videobuf_streamoff(get_queue(fh));
245 if (err < 0)
246 return err;
247 cx25821_res_free(dev, fh, res);
248 return 0;
249}
250
251static long video_ioctl_upstream10(struct file *file, unsigned int cmd,
252 unsigned long arg)
253{
254 struct cx25821_fh *fh = file->private_data;
255 struct cx25821_dev *dev = fh->dev;
256 int command = 0;
257 struct upstream_user_struct *data_from_user;
258
259 data_from_user = (struct upstream_user_struct *)arg;
260
261 if (!data_from_user) {
262 printk
263 ("cx25821 in %s(): Upstream data is INVALID. Returning.\n",
264 __func__);
265 return 0;
266 }
267
268 command = data_from_user->command;
269
270 if (command != UPSTREAM_START_VIDEO && command != UPSTREAM_STOP_VIDEO) {
271 return 0;
272 }
273
274 dev->input_filename_ch2 = data_from_user->input_filename;
275 dev->input_audiofilename = data_from_user->input_filename;
276 dev->vid_stdname_ch2 = data_from_user->vid_stdname;
277 dev->pixel_format_ch2 = data_from_user->pixel_format;
278 dev->channel_select_ch2 = data_from_user->channel_select;
279 dev->command_ch2 = data_from_user->command;
280
281 switch (command) {
282 case UPSTREAM_START_VIDEO:
283 cx25821_start_upstream_video_ch2(dev, data_from_user);
284 break;
285
286 case UPSTREAM_STOP_VIDEO:
287 cx25821_stop_upstream_video_ch2(dev);
288 break;
289 }
290
291 return 0;
292}
293
294static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
295 struct v4l2_format *f)
296{
297 struct cx25821_fh *fh = priv;
298 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
299 int err;
300
301 if (fh) {
302 err = v4l2_prio_check(&dev->prio, fh->prio);
303 if (0 != err)
304 return err;
305 }
306
307 dprintk(2, "%s()\n", __func__);
308 err = cx25821_vidioc_try_fmt_vid_cap(file, priv, f);
309
310 if (0 != err)
311 return err;
312 fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat);
313 fh->width = f->fmt.pix.width;
314 fh->height = f->fmt.pix.height;
315 fh->vidq.field = f->fmt.pix.field;
316 dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width,
317 fh->height, fh->vidq.field);
318 cx25821_call_all(dev, video, s_fmt, f);
319 return 0;
320}
321
322static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
323{
324 struct cx25821_fh *fh = priv;
325 return videobuf_dqbuf(get_queue(fh), p, file->f_flags & O_NONBLOCK);
326}
327
328static int vidioc_log_status(struct file *file, void *priv)
329{
330 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
331 char name[32 + 2];
332
333 snprintf(name, sizeof(name), "%s/2", dev->name);
334 printk(KERN_INFO "%s/2: ============ START LOG STATUS ============\n",
335 dev->name);
336 cx25821_call_all(dev, core, log_status);
337 printk(KERN_INFO "%s/2: ============= END LOG STATUS =============\n",
338 dev->name);
339 return 0;
340}
341
342static int vidioc_s_ctrl(struct file *file, void *priv,
343 struct v4l2_control *ctl)
344{
345 struct cx25821_fh *fh = priv;
346 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
347 int err;
348
349 if (fh) {
350 err = v4l2_prio_check(&dev->prio, fh->prio);
351 if (0 != err)
352 return err;
353 }
354
355 return 0;
356}
357
358//exported stuff
359static const struct v4l2_file_operations video_fops = {
360 .owner = THIS_MODULE,
361 .open = video_open,
362 .release = video_release,
363 .read = video_read,
364 .poll = video_poll,
365 .mmap = cx25821_video_mmap,
366 .ioctl = video_ioctl_upstream10,
367};
368
369static const struct v4l2_ioctl_ops video_ioctl_ops = {
370 .vidioc_querycap = cx25821_vidioc_querycap,
371 .vidioc_enum_fmt_vid_cap = cx25821_vidioc_enum_fmt_vid_cap,
372 .vidioc_g_fmt_vid_cap = cx25821_vidioc_g_fmt_vid_cap,
373 .vidioc_try_fmt_vid_cap = cx25821_vidioc_try_fmt_vid_cap,
374 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
375 .vidioc_reqbufs = cx25821_vidioc_reqbufs,
376 .vidioc_querybuf = cx25821_vidioc_querybuf,
377 .vidioc_qbuf = cx25821_vidioc_qbuf,
378 .vidioc_dqbuf = vidioc_dqbuf,
379#ifdef TUNER_FLAG
380 .vidioc_s_std = cx25821_vidioc_s_std,
381 .vidioc_querystd = cx25821_vidioc_querystd,
382#endif
383 .vidioc_cropcap = cx25821_vidioc_cropcap,
384 .vidioc_s_crop = cx25821_vidioc_s_crop,
385 .vidioc_g_crop = cx25821_vidioc_g_crop,
386 .vidioc_enum_input = cx25821_vidioc_enum_input,
387 .vidioc_g_input = cx25821_vidioc_g_input,
388 .vidioc_s_input = cx25821_vidioc_s_input,
389 .vidioc_g_ctrl = cx25821_vidioc_g_ctrl,
390 .vidioc_s_ctrl = vidioc_s_ctrl,
391 .vidioc_queryctrl = cx25821_vidioc_queryctrl,
392 .vidioc_streamon = vidioc_streamon,
393 .vidioc_streamoff = vidioc_streamoff,
394 .vidioc_log_status = vidioc_log_status,
395 .vidioc_g_priority = cx25821_vidioc_g_priority,
396 .vidioc_s_priority = cx25821_vidioc_s_priority,
397#ifdef CONFIG_VIDEO_V4L1_COMPAT
398 .vidiocgmbuf = cx25821_vidiocgmbuf,
399#endif
400#ifdef TUNER_FLAG
401 .vidioc_g_tuner = cx25821_vidioc_g_tuner,
402 .vidioc_s_tuner = cx25821_vidioc_s_tuner,
403 .vidioc_g_frequency = cx25821_vidioc_g_frequency,
404 .vidioc_s_frequency = cx25821_vidioc_s_frequency,
405#endif
406#ifdef CONFIG_VIDEO_ADV_DEBUG
407 .vidioc_g_register = cx25821_vidioc_g_register,
408 .vidioc_s_register = cx25821_vidioc_s_register,
409#endif
410};
411
412struct video_device cx25821_video_template10 = {
413 .name = "cx25821-upstream10",
414 .fops = &video_fops,
415 .ioctl_ops = &video_ioctl_ops,
416 .tvnorms = CX25821_NORMS,
417 .current_norm = V4L2_STD_NTSC_M,
418};
diff --git a/drivers/staging/cx25821/cx25821-vidups9.c b/drivers/staging/cx25821/cx25821-vidups9.c
deleted file mode 100644
index 466e0f34ae34..000000000000
--- a/drivers/staging/cx25821/cx25821-vidups9.c
+++ /dev/null
@@ -1,416 +0,0 @@
1/*
2 * Driver for the Conexant CX25821 PCIe bridge
3 *
4 * Copyright (C) 2009 Conexant Systems Inc.
5 * Authors <shu.lin@conexant.com>, <hiep.huynh@conexant.com>
6 * Based on Steven Toth <stoth@linuxtv.org> cx23885 driver
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 *
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#include "cx25821-video.h"
25
26static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
27{
28 struct cx25821_buffer *buf =
29 container_of(vb, struct cx25821_buffer, vb);
30 struct cx25821_buffer *prev;
31 struct cx25821_fh *fh = vq->priv_data;
32 struct cx25821_dev *dev = fh->dev;
33 struct cx25821_dmaqueue *q = &dev->vidq[SRAM_CH09];
34
35 /* add jump to stopper */
36 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
37 buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma);
38 buf->risc.jmp[2] = cpu_to_le32(0); /* bits 63-32 */
39
40 dprintk(2, "jmp to stopper (0x%x)\n", buf->risc.jmp[1]);
41
42 if (!list_empty(&q->queued)) {
43 list_add_tail(&buf->vb.queue, &q->queued);
44 buf->vb.state = VIDEOBUF_QUEUED;
45 dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf,
46 buf->vb.i);
47
48 } else if (list_empty(&q->active)) {
49 list_add_tail(&buf->vb.queue, &q->active);
50 cx25821_start_video_dma(dev, q, buf,
51 &dev->sram_channels[SRAM_CH09]);
52 buf->vb.state = VIDEOBUF_ACTIVE;
53 buf->count = q->count++;
54 mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
55 dprintk(2,
56 "[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
57 buf, buf->vb.i, buf->count, q->count);
58 } else {
59 prev =
60 list_entry(q->active.prev, struct cx25821_buffer, vb.queue);
61 if (prev->vb.width == buf->vb.width
62 && prev->vb.height == buf->vb.height
63 && prev->fmt == buf->fmt) {
64 list_add_tail(&buf->vb.queue, &q->active);
65 buf->vb.state = VIDEOBUF_ACTIVE;
66 buf->count = q->count++;
67 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
68
69 /* 64 bit bits 63-32 */
70 prev->risc.jmp[2] = cpu_to_le32(0);
71 dprintk(2,
72 "[%p/%d] buffer_queue - append to active, buf->count=%d\n",
73 buf, buf->vb.i, buf->count);
74
75 } else {
76 list_add_tail(&buf->vb.queue, &q->queued);
77 buf->vb.state = VIDEOBUF_QUEUED;
78 dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf,
79 buf->vb.i);
80 }
81 }
82
83 if (list_empty(&q->active)) {
84 dprintk(2, "active queue empty!\n");
85 }
86}
87
88static struct videobuf_queue_ops cx25821_video_qops = {
89 .buf_setup = cx25821_buffer_setup,
90 .buf_prepare = cx25821_buffer_prepare,
91 .buf_queue = buffer_queue,
92 .buf_release = cx25821_buffer_release,
93};
94
95static int video_open(struct file *file)
96{
97 struct video_device *vdev = video_devdata(file);
98 struct cx25821_dev *dev = video_drvdata(file);
99 struct cx25821_fh *fh;
100 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
101
102 printk("open dev=%s type=%s\n", video_device_node_name(vdev),
103 v4l2_type_names[type]);
104
105 /* allocate + initialize per filehandle data */
106 fh = kzalloc(sizeof(*fh), GFP_KERNEL);
107 if (NULL == fh)
108 return -ENOMEM;
109
110 lock_kernel();
111
112 file->private_data = fh;
113 fh->dev = dev;
114 fh->type = type;
115 fh->width = 720;
116
117 if (dev->tvnorm & V4L2_STD_PAL_BG || dev->tvnorm & V4L2_STD_PAL_DK)
118 fh->height = 576;
119 else
120 fh->height = 480;
121
122 dev->channel_opened = 8;
123 fh->fmt = format_by_fourcc(V4L2_PIX_FMT_YUYV);
124
125 v4l2_prio_open(&dev->prio, &fh->prio);
126
127 videobuf_queue_sg_init(&fh->vidq, &cx25821_video_qops,
128 &dev->pci->dev, &dev->slock,
129 V4L2_BUF_TYPE_VIDEO_CAPTURE,
130 V4L2_FIELD_INTERLACED,
131 sizeof(struct cx25821_buffer), fh);
132
133 dprintk(1, "post videobuf_queue_init()\n");
134 unlock_kernel();
135
136 return 0;
137}
138
139static ssize_t video_read(struct file *file, char __user * data, size_t count,
140 loff_t * ppos)
141{
142 struct cx25821_fh *fh = file->private_data;
143
144 switch (fh->type) {
145 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
146 if (cx25821_res_locked(fh->dev, RESOURCE_VIDEO9))
147 return -EBUSY;
148
149 return videobuf_read_one(&fh->vidq, data, count, ppos,
150 file->f_flags & O_NONBLOCK);
151
152 default:
153 BUG();
154 return 0;
155 }
156}
157
158static unsigned int video_poll(struct file *file,
159 struct poll_table_struct *wait)
160{
161 struct cx25821_fh *fh = file->private_data;
162 struct cx25821_buffer *buf;
163
164 if (cx25821_res_check(fh, RESOURCE_VIDEO9)) {
165 /* streaming capture */
166 if (list_empty(&fh->vidq.stream))
167 return POLLERR;
168 buf = list_entry(fh->vidq.stream.next,
169 struct cx25821_buffer, vb.stream);
170 } else {
171 /* read() capture */
172 buf = (struct cx25821_buffer *)fh->vidq.read_buf;
173 if (NULL == buf)
174 return POLLERR;
175 }
176
177 poll_wait(file, &buf->vb.done, wait);
178 if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR)
179 return POLLIN | POLLRDNORM;
180 return 0;
181}
182
183static int video_release(struct file *file)
184{
185 struct cx25821_fh *fh = file->private_data;
186 struct cx25821_dev *dev = fh->dev;
187
188 //stop the risc engine and fifo
189 //cx_write(channel9->dma_ctl, 0);
190
191 /* stop video capture */
192 if (cx25821_res_check(fh, RESOURCE_VIDEO9)) {
193 videobuf_queue_cancel(&fh->vidq);
194 cx25821_res_free(dev, fh, RESOURCE_VIDEO9);
195 }
196
197 if (fh->vidq.read_buf) {
198 cx25821_buffer_release(&fh->vidq, fh->vidq.read_buf);
199 kfree(fh->vidq.read_buf);
200 }
201
202 videobuf_mmap_free(&fh->vidq);
203
204 v4l2_prio_close(&dev->prio, fh->prio);
205
206 file->private_data = NULL;
207 kfree(fh);
208
209 return 0;
210}
211
212static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
213{
214 struct cx25821_fh *fh = priv;
215 struct cx25821_dev *dev = fh->dev;
216
217 if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)) {
218 return -EINVAL;
219 }
220
221 if (unlikely(i != fh->type)) {
222 return -EINVAL;
223 }
224
225 if (unlikely(!cx25821_res_get(dev, fh, cx25821_get_resource(fh, RESOURCE_VIDEO9)))) {
226 return -EBUSY;
227 }
228
229 return videobuf_streamon(get_queue(fh));
230}
231
232static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
233{
234 struct cx25821_fh *fh = priv;
235 struct cx25821_dev *dev = fh->dev;
236 int err, res;
237
238 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
239 return -EINVAL;
240 if (i != fh->type)
241 return -EINVAL;
242
243 res = cx25821_get_resource(fh, RESOURCE_VIDEO9);
244 err = videobuf_streamoff(get_queue(fh));
245 if (err < 0)
246 return err;
247 cx25821_res_free(dev, fh, res);
248 return 0;
249}
250
251static long video_ioctl_upstream9(struct file *file, unsigned int cmd,
252 unsigned long arg)
253{
254 struct cx25821_fh *fh = file->private_data;
255 struct cx25821_dev *dev = fh->dev;
256 int command = 0;
257 struct upstream_user_struct *data_from_user;
258
259 data_from_user = (struct upstream_user_struct *)arg;
260
261 if (!data_from_user) {
262 printk
263 ("cx25821 in %s(): Upstream data is INVALID. Returning.\n",
264 __func__);
265 return 0;
266 }
267
268 command = data_from_user->command;
269
270 if (command != UPSTREAM_START_VIDEO && command != UPSTREAM_STOP_VIDEO) {
271 return 0;
272 }
273
274 dev->input_filename = data_from_user->input_filename;
275 dev->input_audiofilename = data_from_user->input_filename;
276 dev->vid_stdname = data_from_user->vid_stdname;
277 dev->pixel_format = data_from_user->pixel_format;
278 dev->channel_select = data_from_user->channel_select;
279 dev->command = data_from_user->command;
280
281 switch (command) {
282 case UPSTREAM_START_VIDEO:
283 cx25821_start_upstream_video_ch1(dev, data_from_user);
284 break;
285
286 case UPSTREAM_STOP_VIDEO:
287 cx25821_stop_upstream_video_ch1(dev);
288 break;
289 }
290
291 return 0;
292}
293
294static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
295 struct v4l2_format *f)
296{
297 struct cx25821_fh *fh = priv;
298 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
299 int err;
300
301 if (fh) {
302 err = v4l2_prio_check(&dev->prio, fh->prio);
303 if (0 != err)
304 return err;
305 }
306
307 dprintk(2, "%s()\n", __func__);
308 err = cx25821_vidioc_try_fmt_vid_cap(file, priv, f);
309
310 if (0 != err)
311 return err;
312 fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat);
313 fh->width = f->fmt.pix.width;
314 fh->height = f->fmt.pix.height;
315 fh->vidq.field = f->fmt.pix.field;
316 dprintk(2, "%s() width=%d height=%d field=%d\n", __func__, fh->width,
317 fh->height, fh->vidq.field);
318 cx25821_call_all(dev, video, s_fmt, f);
319 return 0;
320}
321
322static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
323{
324 struct cx25821_fh *fh = priv;
325 return videobuf_dqbuf(get_queue(fh), p, file->f_flags & O_NONBLOCK);
326}
327static int vidioc_log_status(struct file *file, void *priv)
328{
329 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
330 char name[32 + 2];
331
332 snprintf(name, sizeof(name), "%s/2", dev->name);
333 printk(KERN_INFO "%s/2: ============ START LOG STATUS ============\n",
334 dev->name);
335 cx25821_call_all(dev, core, log_status);
336 printk(KERN_INFO "%s/2: ============= END LOG STATUS =============\n",
337 dev->name);
338 return 0;
339}
340
341static int vidioc_s_ctrl(struct file *file, void *priv,
342 struct v4l2_control *ctl)
343{
344 struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
345 struct cx25821_fh *fh = priv;
346 int err;
347 if (fh) {
348 err = v4l2_prio_check(&dev->prio, fh->prio);
349 if (0 != err)
350 return err;
351 }
352
353 return 0;
354}
355
356// exported stuff
357static const struct v4l2_file_operations video_fops = {
358 .owner = THIS_MODULE,
359 .open = video_open,
360 .release = video_release,
361 .read = video_read,
362 .poll = video_poll,
363 .mmap = cx25821_video_mmap,
364 .ioctl = video_ioctl_upstream9,
365};
366
367static const struct v4l2_ioctl_ops video_ioctl_ops = {
368 .vidioc_querycap = cx25821_vidioc_querycap,
369 .vidioc_enum_fmt_vid_cap = cx25821_vidioc_enum_fmt_vid_cap,
370 .vidioc_g_fmt_vid_cap = cx25821_vidioc_g_fmt_vid_cap,
371 .vidioc_try_fmt_vid_cap = cx25821_vidioc_try_fmt_vid_cap,
372 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
373 .vidioc_reqbufs = cx25821_vidioc_reqbufs,
374 .vidioc_querybuf = cx25821_vidioc_querybuf,
375 .vidioc_qbuf = cx25821_vidioc_qbuf,
376 .vidioc_dqbuf = vidioc_dqbuf,
377#ifdef TUNER_FLAG
378 .vidioc_s_std = cx25821_vidioc_s_std,
379 .vidioc_querystd = cx25821_vidioc_querystd,
380#endif
381 .vidioc_cropcap = cx25821_vidioc_cropcap,
382 .vidioc_s_crop = cx25821_vidioc_s_crop,
383 .vidioc_g_crop = cx25821_vidioc_g_crop,
384 .vidioc_enum_input = cx25821_vidioc_enum_input,
385 .vidioc_g_input = cx25821_vidioc_g_input,
386 .vidioc_s_input = cx25821_vidioc_s_input,
387 .vidioc_g_ctrl = cx25821_vidioc_g_ctrl,
388 .vidioc_s_ctrl = vidioc_s_ctrl,
389 .vidioc_queryctrl = cx25821_vidioc_queryctrl,
390 .vidioc_streamon = vidioc_streamon,
391 .vidioc_streamoff = vidioc_streamoff,
392 .vidioc_log_status = vidioc_log_status,
393 .vidioc_g_priority = cx25821_vidioc_g_priority,
394 .vidioc_s_priority = cx25821_vidioc_s_priority,
395#ifdef CONFIG_VIDEO_V4L1_COMPAT
396 .vidiocgmbuf = cx25821_vidiocgmbuf,
397#endif
398#ifdef TUNER_FLAG
399 .vidioc_g_tuner = cx25821_vidioc_g_tuner,
400 .vidioc_s_tuner = cx25821_vidioc_s_tuner,
401 .vidioc_g_frequency = cx25821_vidioc_g_frequency,
402 .vidioc_s_frequency = cx25821_vidioc_s_frequency,
403#endif
404#ifdef CONFIG_VIDEO_ADV_DEBUG
405 .vidioc_g_register = cx25821_vidioc_g_register,
406 .vidioc_s_register = cx25821_vidioc_s_register,
407#endif
408};
409
410struct video_device cx25821_video_template9 = {
411 .name = "cx25821-upstream9",
412 .fops = &video_fops,
413 .ioctl_ops = &video_ioctl_ops,
414 .tvnorms = CX25821_NORMS,
415 .current_norm = V4L2_STD_NTSC_M,
416};
diff --git a/drivers/staging/cx25821/cx25821.h b/drivers/staging/cx25821/cx25821.h
index cf2286d83b6a..1b628f61578a 100644
--- a/drivers/staging/cx25821/cx25821.h
+++ b/drivers/staging/cx25821/cx25821.h
@@ -61,7 +61,7 @@
61#define FALSE 0 61#define FALSE 0
62#define LINE_SIZE_D1 1440 62#define LINE_SIZE_D1 1440
63 63
64// Number of decoders and encoders 64/* Number of decoders and encoders */
65#define MAX_DECODERS 8 65#define MAX_DECODERS 8
66#define MAX_ENCODERS 2 66#define MAX_ENCODERS 2
67#define QUAD_DECODERS 4 67#define QUAD_DECODERS 4
@@ -139,6 +139,7 @@ struct cx25821_fh {
139 /* video capture */ 139 /* video capture */
140 struct cx25821_fmt *fmt; 140 struct cx25821_fmt *fmt;
141 unsigned int width, height; 141 unsigned int width, height;
142 int channel_id;
142 143
143 /* vbi capture */ 144 /* vbi capture */
144 struct videobuf_queue vidq; 145 struct videobuf_queue vidq;
@@ -236,13 +237,34 @@ struct cx25821_data {
236 struct sram_channel *channel; 237 struct sram_channel *channel;
237}; 238};
238 239
240struct cx25821_channel {
241 struct v4l2_prio_state prio;
242
243 int ctl_bright;
244 int ctl_contrast;
245 int ctl_hue;
246 int ctl_saturation;
247
248 struct cx25821_data timeout_data;
249
250 struct video_device *video_dev;
251 struct cx25821_dmaqueue vidq;
252
253 struct sram_channel *sram_channels;
254
255 struct mutex lock;
256 int resources;
257
258 int pixel_formats;
259 int use_cif_resolution;
260 int cif_width;
261};
262
239struct cx25821_dev { 263struct cx25821_dev {
240 struct list_head devlist; 264 struct list_head devlist;
241 atomic_t refcount; 265 atomic_t refcount;
242 struct v4l2_device v4l2_dev; 266 struct v4l2_device v4l2_dev;
243 267
244 struct v4l2_prio_state prio;
245
246 /* pci stuff */ 268 /* pci stuff */
247 struct pci_dev *pci; 269 struct pci_dev *pci;
248 unsigned char pci_rev, pci_lat; 270 unsigned char pci_rev, pci_lat;
@@ -261,13 +283,12 @@ struct cx25821_dev {
261 int nr; 283 int nr;
262 struct mutex lock; 284 struct mutex lock;
263 285
286 struct cx25821_channel channels[MAX_VID_CHANNEL_NUM];
287
264 /* board details */ 288 /* board details */
265 unsigned int board; 289 unsigned int board;
266 char name[32]; 290 char name[32];
267 291
268 /* sram configuration */
269 struct sram_channel *sram_channels;
270
271 /* Analog video */ 292 /* Analog video */
272 u32 resources; 293 u32 resources;
273 unsigned int input; 294 unsigned int input;
@@ -282,13 +303,6 @@ struct cx25821_dev {
282 unsigned char videc_addr; 303 unsigned char videc_addr;
283 unsigned short _max_num_decoders; 304 unsigned short _max_num_decoders;
284 305
285 int ctl_bright;
286 int ctl_contrast;
287 int ctl_hue;
288 int ctl_saturation;
289
290 struct cx25821_data timeout_data[MAX_VID_CHANNEL_NUM];
291
292 /* Analog Audio Upstream */ 306 /* Analog Audio Upstream */
293 int _audio_is_running; 307 int _audio_is_running;
294 int _audiopixel_format; 308 int _audiopixel_format;
@@ -297,7 +311,7 @@ struct cx25821_dev {
297 int _audio_lines_count; 311 int _audio_lines_count;
298 int _audioframe_count; 312 int _audioframe_count;
299 int _audio_upstream_channel_select; 313 int _audio_upstream_channel_select;
300 int _last_index_irq; //The last interrupt index processed. 314 int _last_index_irq; /* The last interrupt index processed. */
301 315
302 __le32 *_risc_audio_jmp_addr; 316 __le32 *_risc_audio_jmp_addr;
303 __le32 *_risc_virt_start_addr; 317 __le32 *_risc_virt_start_addr;
@@ -313,12 +327,10 @@ struct cx25821_dev {
313 327
314 /* V4l */ 328 /* V4l */
315 u32 freq; 329 u32 freq;
316 struct video_device *video_dev[MAX_VID_CHANNEL_NUM];
317 struct video_device *vbi_dev; 330 struct video_device *vbi_dev;
318 struct video_device *radio_dev; 331 struct video_device *radio_dev;
319 struct video_device *ioctl_dev; 332 struct video_device *ioctl_dev;
320 333
321 struct cx25821_dmaqueue vidq[MAX_VID_CHANNEL_NUM];
322 spinlock_t slock; 334 spinlock_t slock;
323 335
324 /* Video Upstream */ 336 /* Video Upstream */
@@ -401,9 +413,6 @@ struct cx25821_dev {
401 int pixel_format; 413 int pixel_format;
402 int channel_select; 414 int channel_select;
403 int command; 415 int command;
404 int pixel_formats[VID_CHANNEL_NUM];
405 int use_cif_resolution[VID_CHANNEL_NUM];
406 int cif_width[VID_CHANNEL_NUM];
407 int channel_opened; 416 int channel_opened;
408}; 417};
409 418
@@ -482,7 +491,7 @@ struct sram_channel {
482 u32 fld_aud_fifo_en; 491 u32 fld_aud_fifo_en;
483 u32 fld_aud_risc_en; 492 u32 fld_aud_risc_en;
484 493
485 //For Upstream Video 494 /* For Upstream Video */
486 u32 vid_fmt_ctl; 495 u32 vid_fmt_ctl;
487 u32 vid_active_ctl1; 496 u32 vid_active_ctl1;
488 u32 vid_active_ctl2; 497 u32 vid_active_ctl2;
diff --git a/drivers/staging/lirc/Kconfig b/drivers/staging/lirc/Kconfig
new file mode 100644
index 000000000000..968c2adee06b
--- /dev/null
+++ b/drivers/staging/lirc/Kconfig
@@ -0,0 +1,110 @@
1#
2# LIRC driver(s) configuration
3#
4menuconfig LIRC_STAGING
5 bool "Linux Infrared Remote Control IR receiver/transmitter drivers"
6 help
7 Say Y here, and all supported Linux Infrared Remote Control IR and
8 RF receiver and transmitter drivers will be displayed. When paired
9 with a remote control and the lirc daemon, the receiver drivers
10 allow control of your Linux system via remote control.
11
12if LIRC_STAGING
13
14config LIRC_BT829
15 tristate "BT829 based hardware"
16 depends on LIRC_STAGING
17 help
18 Driver for the IR interface on BT829-based hardware
19
20config LIRC_ENE0100
21 tristate "ENE KB3924/ENE0100 CIR Port Reciever"
22 depends on LIRC_STAGING
23 help
24 This is a driver for CIR port handled by ENE KB3924 embedded
25 controller found on some notebooks.
26 It appears on PNP list as ENE0100.
27
28config LIRC_I2C
29 tristate "I2C Based IR Receivers"
30 depends on LIRC_STAGING
31 help
32 Driver for I2C-based IR receivers, such as those commonly
33 found onboard Hauppauge PVR-150/250/350 video capture cards
34
35config LIRC_IGORPLUGUSB
36 tristate "Igor Cesko's USB IR Receiver"
37 depends on LIRC_STAGING && USB
38 help
39 Driver for Igor Cesko's USB IR Receiver
40
41config LIRC_IMON
42 tristate "Legacy SoundGraph iMON Receiver and Display"
43 depends on LIRC_STAGING
44 help
45 Driver for the original SoundGraph iMON IR Receiver and Display
46
47 Current generation iMON devices use the input layer imon driver.
48
49config LIRC_IT87
50 tristate "ITE IT87XX CIR Port Receiver"
51 depends on LIRC_STAGING
52 help
53 Driver for the ITE IT87xx IR Receiver
54
55config LIRC_ITE8709
56 tristate "ITE8709 CIR Port Receiver"
57 depends on LIRC_STAGING && PNP
58 help
59 Driver for the ITE8709 IR Receiver
60
61config LIRC_PARALLEL
62 tristate "Homebrew Parallel Port Receiver"
63 depends on LIRC_STAGING && !SMP
64 help
65 Driver for Homebrew Parallel Port Receivers
66
67config LIRC_SASEM
68 tristate "Sasem USB IR Remote"
69 depends on LIRC_STAGING
70 help
71 Driver for the Sasem OnAir Remocon-V or Dign HV5 HTPC IR/VFD Module
72
73config LIRC_SERIAL
74 tristate "Homebrew Serial Port Receiver"
75 depends on LIRC_STAGING
76 help
77 Driver for Homebrew Serial Port Receivers
78
79config LIRC_SERIAL_TRANSMITTER
80 bool "Serial Port Transmitter"
81 default y
82 depends on LIRC_SERIAL
83 help
84 Serial Port Transmitter support
85
86config LIRC_SIR
87 tristate "Built-in SIR IrDA port"
88 depends on LIRC_STAGING
89 help
90 Driver for the SIR IrDA port
91
92config LIRC_STREAMZAP
93 tristate "Streamzap PC Receiver"
94 depends on LIRC_STAGING
95 help
96 Driver for the Streamzap PC Receiver
97
98config LIRC_TTUSBIR
99 tristate "Technotrend USB IR Receiver"
100 depends on LIRC_STAGING && USB
101 help
102 Driver for the Technotrend USB IR Receiver
103
104config LIRC_ZILOG
105 tristate "Zilog/Hauppauge IR Transmitter"
106 depends on LIRC_STAGING
107 help
108 Driver for the Zilog/Hauppauge IR Transmitter, found on
109 PVR-150/500, HVR-1200/1250/1700/1800, HD-PVR and other cards
110endif
diff --git a/drivers/staging/lirc/Makefile b/drivers/staging/lirc/Makefile
new file mode 100644
index 000000000000..a019182a7a38
--- /dev/null
+++ b/drivers/staging/lirc/Makefile
@@ -0,0 +1,19 @@
1# Makefile for the lirc drivers.
2#
3
4# Each configuration option enables a list of files.
5
6obj-$(CONFIG_LIRC_BT829) += lirc_bt829.o
7obj-$(CONFIG_LIRC_ENE0100) += lirc_ene0100.o
8obj-$(CONFIG_LIRC_I2C) += lirc_i2c.o
9obj-$(CONFIG_LIRC_IGORPLUGUSB) += lirc_igorplugusb.o
10obj-$(CONFIG_LIRC_IMON) += lirc_imon.o
11obj-$(CONFIG_LIRC_IT87) += lirc_it87.o
12obj-$(CONFIG_LIRC_ITE8709) += lirc_ite8709.o
13obj-$(CONFIG_LIRC_PARALLEL) += lirc_parallel.o
14obj-$(CONFIG_LIRC_SASEM) += lirc_sasem.o
15obj-$(CONFIG_LIRC_SERIAL) += lirc_serial.o
16obj-$(CONFIG_LIRC_SIR) += lirc_sir.o
17obj-$(CONFIG_LIRC_STREAMZAP) += lirc_streamzap.o
18obj-$(CONFIG_LIRC_TTUSBIR) += lirc_ttusbir.o
19obj-$(CONFIG_LIRC_ZILOG) += lirc_zilog.o
diff --git a/drivers/staging/lirc/TODO b/drivers/staging/lirc/TODO
new file mode 100644
index 000000000000..b6cb593f55c6
--- /dev/null
+++ b/drivers/staging/lirc/TODO
@@ -0,0 +1,8 @@
1- All drivers should either be ported to ir-core, or dropped entirely
2 (see drivers/media/IR/mceusb.c vs. lirc_mceusb.c in lirc cvs for an
3 example of a previously completed port).
4
5Please send patches to:
6Jarod Wilson <jarod@wilsonet.com>
7Greg Kroah-Hartman <greg@kroah.com>
8
diff --git a/drivers/staging/lirc/TODO.lirc_i2c b/drivers/staging/lirc/TODO.lirc_i2c
new file mode 100644
index 000000000000..1f0a6ff65439
--- /dev/null
+++ b/drivers/staging/lirc/TODO.lirc_i2c
@@ -0,0 +1,3 @@
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/lirc_bt829.c b/drivers/staging/lirc/lirc_bt829.c
new file mode 100644
index 000000000000..33881025426b
--- /dev/null
+++ b/drivers/staging/lirc/lirc_bt829.c
@@ -0,0 +1,383 @@
1/*
2 * Remote control driver for the TV-card based on bt829
3 *
4 * by Leonid Froenchenko <lfroen@galileo.co.il>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19*/
20
21#include <linux/kernel.h>
22#include <linux/module.h>
23#include <linux/threads.h>
24#include <linux/sched.h>
25#include <linux/ioport.h>
26#include <linux/pci.h>
27#include <linux/delay.h>
28
29#include <media/lirc_dev.h>
30
31static int poll_main(void);
32static int atir_init_start(void);
33
34static void write_index(unsigned char index, unsigned int value);
35static unsigned int read_index(unsigned char index);
36
37static void do_i2c_start(void);
38static void do_i2c_stop(void);
39
40static void seems_wr_byte(unsigned char al);
41static unsigned char seems_rd_byte(void);
42
43static unsigned int read_index(unsigned char al);
44static void write_index(unsigned char ah, unsigned int edx);
45
46static void cycle_delay(int cycle);
47
48static void do_set_bits(unsigned char bl);
49static unsigned char do_get_bits(void);
50
51#define DATA_PCI_OFF 0x7FFC00
52#define WAIT_CYCLE 20
53
54#define DRIVER_NAME "lirc_bt829"
55
56static int debug;
57#define dprintk(fmt, args...) \
58 do { \
59 if (debug) \
60 printk(KERN_DEBUG DRIVER_NAME ": "fmt, ## args); \
61 } while (0)
62
63static int atir_minor;
64static unsigned long pci_addr_phys;
65static unsigned char *pci_addr_lin;
66
67static struct lirc_driver atir_driver;
68
69static struct pci_dev *do_pci_probe(void)
70{
71 struct pci_dev *my_dev;
72 my_dev = pci_get_device(PCI_VENDOR_ID_ATI,
73 PCI_DEVICE_ID_ATI_264VT, NULL);
74 if (my_dev) {
75 printk(KERN_ERR DRIVER_NAME ": Using device: %s\n",
76 pci_name(my_dev));
77 pci_addr_phys = 0;
78 if (my_dev->resource[0].flags & IORESOURCE_MEM) {
79 pci_addr_phys = my_dev->resource[0].start;
80 printk(KERN_INFO DRIVER_NAME ": memory at 0x%08X\n",
81 (unsigned int)pci_addr_phys);
82 }
83 if (pci_addr_phys == 0) {
84 printk(KERN_ERR DRIVER_NAME ": no memory resource ?\n");
85 return NULL;
86 }
87 } else {
88 printk(KERN_ERR DRIVER_NAME ": pci_probe failed\n");
89 return NULL;
90 }
91 return my_dev;
92}
93
94static int atir_add_to_buf(void *data, struct lirc_buffer *buf)
95{
96 unsigned char key;
97 int status;
98 status = poll_main();
99 key = (status >> 8) & 0xFF;
100 if (status & 0xFF) {
101 dprintk("reading key %02X\n", key);
102 lirc_buffer_write(buf, &key);
103 return 0;
104 }
105 return -ENODATA;
106}
107
108static int atir_set_use_inc(void *data)
109{
110 dprintk("driver is opened\n");
111 return 0;
112}
113
114static void atir_set_use_dec(void *data)
115{
116 dprintk("driver is closed\n");
117}
118
119int init_module(void)
120{
121 struct pci_dev *pdev;
122
123 pdev = do_pci_probe();
124 if (pdev == NULL)
125 return 1;
126
127 if (!atir_init_start())
128 return 1;
129
130 strcpy(atir_driver.name, "ATIR");
131 atir_driver.minor = -1;
132 atir_driver.code_length = 8;
133 atir_driver.sample_rate = 10;
134 atir_driver.data = 0;
135 atir_driver.add_to_buf = atir_add_to_buf;
136 atir_driver.set_use_inc = atir_set_use_inc;
137 atir_driver.set_use_dec = atir_set_use_dec;
138 atir_driver.dev = &pdev->dev;
139 atir_driver.owner = THIS_MODULE;
140
141 atir_minor = lirc_register_driver(&atir_driver);
142 if (atir_minor < 0) {
143 printk(KERN_ERR DRIVER_NAME ": failed to register driver!\n");
144 return atir_minor;
145 }
146 dprintk("driver is registered on minor %d\n", atir_minor);
147
148 return 0;
149}
150
151
152void cleanup_module(void)
153{
154 lirc_unregister_driver(atir_minor);
155}
156
157
158static int atir_init_start(void)
159{
160 pci_addr_lin = ioremap(pci_addr_phys + DATA_PCI_OFF, 0x400);
161 if (pci_addr_lin == 0) {
162 printk(KERN_INFO DRIVER_NAME ": pci mem must be mapped\n");
163 return 0;
164 }
165 return 1;
166}
167
168static void cycle_delay(int cycle)
169{
170 udelay(WAIT_CYCLE*cycle);
171}
172
173
174static int poll_main()
175{
176 unsigned char status_high, status_low;
177
178 do_i2c_start();
179
180 seems_wr_byte(0xAA);
181 seems_wr_byte(0x01);
182
183 do_i2c_start();
184
185 seems_wr_byte(0xAB);
186
187 status_low = seems_rd_byte();
188 status_high = seems_rd_byte();
189
190 do_i2c_stop();
191
192 return (status_high << 8) | status_low;
193}
194
195static void do_i2c_start(void)
196{
197 do_set_bits(3);
198 cycle_delay(4);
199
200 do_set_bits(1);
201 cycle_delay(7);
202
203 do_set_bits(0);
204 cycle_delay(2);
205}
206
207static void do_i2c_stop(void)
208{
209 unsigned char bits;
210 bits = do_get_bits() & 0xFD;
211 do_set_bits(bits);
212 cycle_delay(1);
213
214 bits |= 1;
215 do_set_bits(bits);
216 cycle_delay(2);
217
218 bits |= 2;
219 do_set_bits(bits);
220 bits = 3;
221 do_set_bits(bits);
222 cycle_delay(2);
223}
224
225static void seems_wr_byte(unsigned char value)
226{
227 int i;
228 unsigned char reg;
229
230 reg = do_get_bits();
231 for (i = 0; i < 8; i++) {
232 if (value & 0x80)
233 reg |= 0x02;
234 else
235 reg &= 0xFD;
236
237 do_set_bits(reg);
238 cycle_delay(1);
239
240 reg |= 1;
241 do_set_bits(reg);
242 cycle_delay(1);
243
244 reg &= 0xFE;
245 do_set_bits(reg);
246 cycle_delay(1);
247 value <<= 1;
248 }
249 cycle_delay(2);
250
251 reg |= 2;
252 do_set_bits(reg);
253
254 reg |= 1;
255 do_set_bits(reg);
256
257 cycle_delay(1);
258 do_get_bits();
259
260 reg &= 0xFE;
261 do_set_bits(reg);
262 cycle_delay(3);
263}
264
265static unsigned char seems_rd_byte(void)
266{
267 int i;
268 int rd_byte;
269 unsigned char bits_2, bits_1;
270
271 bits_1 = do_get_bits() | 2;
272 do_set_bits(bits_1);
273
274 rd_byte = 0;
275 for (i = 0; i < 8; i++) {
276 bits_1 &= 0xFE;
277 do_set_bits(bits_1);
278 cycle_delay(2);
279
280 bits_1 |= 1;
281 do_set_bits(bits_1);
282 cycle_delay(1);
283
284 bits_2 = do_get_bits();
285 if (bits_2 & 2)
286 rd_byte |= 1;
287
288 rd_byte <<= 1;
289 }
290
291 bits_1 = 0;
292 if (bits_2 == 0)
293 bits_1 |= 2;
294
295 do_set_bits(bits_1);
296 cycle_delay(2);
297
298 bits_1 |= 1;
299 do_set_bits(bits_1);
300 cycle_delay(3);
301
302 bits_1 &= 0xFE;
303 do_set_bits(bits_1);
304 cycle_delay(2);
305
306 rd_byte >>= 1;
307 rd_byte &= 0xFF;
308 return rd_byte;
309}
310
311static void do_set_bits(unsigned char new_bits)
312{
313 int reg_val;
314 reg_val = read_index(0x34);
315 if (new_bits & 2) {
316 reg_val &= 0xFFFFFFDF;
317 reg_val |= 1;
318 } else {
319 reg_val &= 0xFFFFFFFE;
320 reg_val |= 0x20;
321 }
322 reg_val |= 0x10;
323 write_index(0x34, reg_val);
324
325 reg_val = read_index(0x31);
326 if (new_bits & 1)
327 reg_val |= 0x1000000;
328 else
329 reg_val &= 0xFEFFFFFF;
330
331 reg_val |= 0x8000000;
332 write_index(0x31, reg_val);
333}
334
335static unsigned char do_get_bits(void)
336{
337 unsigned char bits;
338 int reg_val;
339
340 reg_val = read_index(0x34);
341 reg_val |= 0x10;
342 reg_val &= 0xFFFFFFDF;
343 write_index(0x34, reg_val);
344
345 reg_val = read_index(0x34);
346 bits = 0;
347 if (reg_val & 8)
348 bits |= 2;
349 else
350 bits &= 0xFD;
351
352 reg_val = read_index(0x31);
353 if (reg_val & 0x1000000)
354 bits |= 1;
355 else
356 bits &= 0xFE;
357
358 return bits;
359}
360
361static unsigned int read_index(unsigned char index)
362{
363 unsigned char *addr;
364 unsigned int value;
365 /* addr = pci_addr_lin + DATA_PCI_OFF + ((index & 0xFF) << 2); */
366 addr = pci_addr_lin + ((index & 0xFF) << 2);
367 value = readl(addr);
368 return value;
369}
370
371static void write_index(unsigned char index, unsigned int reg_val)
372{
373 unsigned char *addr;
374 addr = pci_addr_lin + ((index & 0xFF) << 2);
375 writel(reg_val, addr);
376}
377
378MODULE_AUTHOR("Froenchenko Leonid");
379MODULE_DESCRIPTION("IR remote driver for bt829 based TV cards");
380MODULE_LICENSE("GPL");
381
382module_param(debug, bool, S_IRUGO | S_IWUSR);
383MODULE_PARM_DESC(debug, "Debug enabled or not");
diff --git a/drivers/staging/lirc/lirc_ene0100.c b/drivers/staging/lirc/lirc_ene0100.c
new file mode 100644
index 000000000000..a152c52b0745
--- /dev/null
+++ b/drivers/staging/lirc/lirc_ene0100.c
@@ -0,0 +1,646 @@
1/*
2 * driver for ENE KB3926 B/C/D CIR (also known as ENE0100)
3 *
4 * Copyright (C) 2009 Maxim Levitsky <maximlevitsky@gmail.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; either version 2 of the
9 * License, or (at your option) any later version.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 * USA
20 */
21
22#include <linux/kernel.h>
23#include <linux/module.h>
24#include <linux/pnp.h>
25#include <linux/io.h>
26#include <linux/interrupt.h>
27#include <linux/sched.h>
28#include "lirc_ene0100.h"
29
30static int sample_period = 75;
31static int enable_idle = 1;
32static int enable_learning;
33
34static void ene_set_idle(struct ene_device *dev, int idle);
35static void ene_set_inputs(struct ene_device *dev, int enable);
36
37/* read a hardware register */
38static u8 ene_hw_read_reg(struct ene_device *dev, u16 reg)
39{
40 outb(reg >> 8, dev->hw_io + ENE_ADDR_HI);
41 outb(reg & 0xFF, dev->hw_io + ENE_ADDR_LO);
42 return inb(dev->hw_io + ENE_IO);
43}
44
45/* write a hardware register */
46static void ene_hw_write_reg(struct ene_device *dev, u16 reg, u8 value)
47{
48 outb(reg >> 8, dev->hw_io + ENE_ADDR_HI);
49 outb(reg & 0xFF, dev->hw_io + ENE_ADDR_LO);
50 outb(value, dev->hw_io + ENE_IO);
51}
52
53/* change specific bits in hardware register */
54static void ene_hw_write_reg_mask(struct ene_device *dev,
55 u16 reg, u8 value, u8 mask)
56{
57 u8 regvalue;
58
59 outb(reg >> 8, dev->hw_io + ENE_ADDR_HI);
60 outb(reg & 0xFF, dev->hw_io + ENE_ADDR_LO);
61
62 regvalue = inb(dev->hw_io + ENE_IO) & ~mask;
63 regvalue |= (value & mask);
64 outb(regvalue, dev->hw_io + ENE_IO);
65}
66
67/* read irq status and ack it */
68static int ene_hw_irq_status(struct ene_device *dev, int *buffer_pointer)
69{
70 u8 irq_status;
71 u8 fw_flags1, fw_flags2;
72
73 fw_flags2 = ene_hw_read_reg(dev, ENE_FW2);
74
75 if (buffer_pointer)
76 *buffer_pointer = 4 * (fw_flags2 & ENE_FW2_BUF_HIGH);
77
78 if (dev->hw_revision < ENE_HW_C) {
79 irq_status = ene_hw_read_reg(dev, ENEB_IRQ_STATUS);
80
81 if (!(irq_status & ENEB_IRQ_STATUS_IR))
82 return 0;
83 ene_hw_write_reg(dev, ENEB_IRQ_STATUS,
84 irq_status & ~ENEB_IRQ_STATUS_IR);
85
86 /* rev B support only recieving */
87 return ENE_IRQ_RX;
88 }
89
90 irq_status = ene_hw_read_reg(dev, ENEC_IRQ);
91
92 if (!(irq_status & ENEC_IRQ_STATUS))
93 return 0;
94
95 /* original driver does that twice - a workaround ? */
96 ene_hw_write_reg(dev, ENEC_IRQ, irq_status & ~ENEC_IRQ_STATUS);
97 ene_hw_write_reg(dev, ENEC_IRQ, irq_status & ~ENEC_IRQ_STATUS);
98
99 /* clear unknown flag in F8F9 */
100 if (fw_flags2 & ENE_FW2_IRQ_CLR)
101 ene_hw_write_reg(dev, ENE_FW2, fw_flags2 & ~ENE_FW2_IRQ_CLR);
102
103 /* check if this is a TX interrupt */
104 fw_flags1 = ene_hw_read_reg(dev, ENE_FW1);
105
106 if (fw_flags1 & ENE_FW1_TXIRQ) {
107 ene_hw_write_reg(dev, ENE_FW1, fw_flags1 & ~ENE_FW1_TXIRQ);
108 return ENE_IRQ_TX;
109 } else
110 return ENE_IRQ_RX;
111}
112
113static int ene_hw_detect(struct ene_device *dev)
114{
115 u8 chip_major, chip_minor;
116 u8 hw_revision, old_ver;
117 u8 tmp;
118 u8 fw_capabilities;
119
120 tmp = ene_hw_read_reg(dev, ENE_HW_UNK);
121 ene_hw_write_reg(dev, ENE_HW_UNK, tmp & ~ENE_HW_UNK_CLR);
122
123 chip_major = ene_hw_read_reg(dev, ENE_HW_VER_MAJOR);
124 chip_minor = ene_hw_read_reg(dev, ENE_HW_VER_MINOR);
125
126 ene_hw_write_reg(dev, ENE_HW_UNK, tmp);
127 hw_revision = ene_hw_read_reg(dev, ENE_HW_VERSION);
128 old_ver = ene_hw_read_reg(dev, ENE_HW_VER_OLD);
129
130 if (hw_revision == 0xFF) {
131
132 ene_printk(KERN_WARNING, "device seems to be disabled\n");
133 ene_printk(KERN_WARNING,
134 "send a mail to lirc-list@lists.sourceforge.net\n");
135 ene_printk(KERN_WARNING, "please attach output of acpidump\n");
136
137 return -ENODEV;
138 }
139
140 if (chip_major == 0x33) {
141 ene_printk(KERN_WARNING, "chips 0x33xx aren't supported yet\n");
142 return -ENODEV;
143 }
144
145 if (chip_major == 0x39 && chip_minor == 0x26 && hw_revision == 0xC0) {
146 dev->hw_revision = ENE_HW_C;
147 ene_printk(KERN_WARNING,
148 "KB3926C detected, driver support is not complete!\n");
149
150 } else if (old_ver == 0x24 && hw_revision == 0xC0) {
151 dev->hw_revision = ENE_HW_B;
152 ene_printk(KERN_NOTICE, "KB3926B detected\n");
153 } else {
154 dev->hw_revision = ENE_HW_D;
155 ene_printk(KERN_WARNING,
156 "unknown ENE chip detected, assuming KB3926D\n");
157 ene_printk(KERN_WARNING, "driver support incomplete");
158
159 }
160
161 ene_printk(KERN_DEBUG, "chip is 0x%02x%02x - 0x%02x, 0x%02x\n",
162 chip_major, chip_minor, old_ver, hw_revision);
163
164
165 /* detect features hardware supports */
166
167 if (dev->hw_revision < ENE_HW_C)
168 return 0;
169
170 fw_capabilities = ene_hw_read_reg(dev, ENE_FW2);
171
172 dev->hw_gpio40_learning = fw_capabilities & ENE_FW2_GP40_AS_LEARN;
173 dev->hw_learning_and_tx_capable = fw_capabilities & ENE_FW2_LEARNING;
174
175 dev->hw_fan_as_normal_input = dev->hw_learning_and_tx_capable &&
176 fw_capabilities & ENE_FW2_FAN_AS_NRML_IN;
177
178 ene_printk(KERN_NOTICE, "hardware features:\n");
179 ene_printk(KERN_NOTICE,
180 "learning and tx %s, gpio40_learn %s, fan_in %s\n",
181 dev->hw_learning_and_tx_capable ? "on" : "off",
182 dev->hw_gpio40_learning ? "on" : "off",
183 dev->hw_fan_as_normal_input ? "on" : "off");
184
185 if (!dev->hw_learning_and_tx_capable && enable_learning)
186 enable_learning = 0;
187
188 if (dev->hw_learning_and_tx_capable) {
189 ene_printk(KERN_WARNING,
190 "Device supports transmitting, but the driver doesn't\n");
191 ene_printk(KERN_WARNING,
192 "due to lack of hardware to test against.\n");
193 ene_printk(KERN_WARNING,
194 "Send a mail to: lirc-list@lists.sourceforge.net\n");
195 }
196 return 0;
197}
198
199/* hardware initialization */
200static int ene_hw_init(void *data)
201{
202 u8 reg_value;
203 struct ene_device *dev = (struct ene_device *)data;
204 dev->in_use = 1;
205
206 if (dev->hw_revision < ENE_HW_C) {
207 ene_hw_write_reg(dev, ENEB_IRQ, dev->irq << 1);
208 ene_hw_write_reg(dev, ENEB_IRQ_UNK1, 0x01);
209 } else {
210 reg_value = ene_hw_read_reg(dev, ENEC_IRQ) & 0xF0;
211 reg_value |= ENEC_IRQ_UNK_EN;
212 reg_value &= ~ENEC_IRQ_STATUS;
213 reg_value |= (dev->irq & ENEC_IRQ_MASK);
214 ene_hw_write_reg(dev, ENEC_IRQ, reg_value);
215 ene_hw_write_reg(dev, ENE_TX_UNK1, 0x63);
216 }
217
218 ene_hw_write_reg(dev, ENE_CIR_CONF2, 0x00);
219 ene_set_inputs(dev, enable_learning);
220
221 /* set sampling period */
222 ene_hw_write_reg(dev, ENE_CIR_SAMPLE_PERIOD, sample_period);
223
224 /* ack any pending irqs - just in case */
225 ene_hw_irq_status(dev, NULL);
226
227 /* enter idle mode */
228 ene_set_idle(dev, 1);
229
230 /* enable firmware bits */
231 ene_hw_write_reg_mask(dev, ENE_FW1,
232 ENE_FW1_ENABLE | ENE_FW1_IRQ,
233 ENE_FW1_ENABLE | ENE_FW1_IRQ);
234 /* clear stats */
235 dev->sample = 0;
236 return 0;
237}
238
239/* this enables gpio40 signal, used if connected to wide band input*/
240static void ene_enable_gpio40(struct ene_device *dev, int enable)
241{
242 ene_hw_write_reg_mask(dev, ENE_CIR_CONF1, enable ?
243 0 : ENE_CIR_CONF2_GPIO40DIS,
244 ENE_CIR_CONF2_GPIO40DIS);
245}
246
247/* this enables the classic sampler */
248static void ene_enable_normal_recieve(struct ene_device *dev, int enable)
249{
250 ene_hw_write_reg(dev, ENE_CIR_CONF1, enable ? ENE_CIR_CONF1_ADC_ON : 0);
251}
252
253/* this enables recieve via fan input */
254static void ene_enable_fan_recieve(struct ene_device *dev, int enable)
255{
256 if (!enable)
257 ene_hw_write_reg(dev, ENE_FAN_AS_IN1, 0);
258 else {
259 ene_hw_write_reg(dev, ENE_FAN_AS_IN1, ENE_FAN_AS_IN1_EN);
260 ene_hw_write_reg(dev, ENE_FAN_AS_IN2, ENE_FAN_AS_IN2_EN);
261 }
262 dev->fan_input_inuse = enable;
263}
264
265/* determine which input to use*/
266static void ene_set_inputs(struct ene_device *dev, int learning_enable)
267{
268 ene_enable_normal_recieve(dev, 1);
269
270 /* old hardware doesn't support learning mode for sure */
271 if (dev->hw_revision <= ENE_HW_B)
272 return;
273
274 /* reciever not learning capable, still set gpio40 correctly */
275 if (!dev->hw_learning_and_tx_capable) {
276 ene_enable_gpio40(dev, !dev->hw_gpio40_learning);
277 return;
278 }
279
280 /* enable learning mode */
281 if (learning_enable) {
282 ene_enable_gpio40(dev, dev->hw_gpio40_learning);
283
284 /* fan input is not used for learning */
285 if (dev->hw_fan_as_normal_input)
286 ene_enable_fan_recieve(dev, 0);
287
288 /* disable learning mode */
289 } else {
290 if (dev->hw_fan_as_normal_input) {
291 ene_enable_fan_recieve(dev, 1);
292 ene_enable_normal_recieve(dev, 0);
293 } else
294 ene_enable_gpio40(dev, !dev->hw_gpio40_learning);
295 }
296
297 /* set few additional settings for this mode */
298 ene_hw_write_reg_mask(dev, ENE_CIR_CONF1, learning_enable ?
299 ENE_CIR_CONF1_LEARN1 : 0, ENE_CIR_CONF1_LEARN1);
300
301 ene_hw_write_reg_mask(dev, ENE_CIR_CONF2, learning_enable ?
302 ENE_CIR_CONF2_LEARN2 : 0, ENE_CIR_CONF2_LEARN2);
303}
304
305/* deinitialization */
306static void ene_hw_deinit(void *data)
307{
308 struct ene_device *dev = (struct ene_device *)data;
309
310 /* disable samplers */
311 ene_enable_normal_recieve(dev, 0);
312
313 if (dev->hw_fan_as_normal_input)
314 ene_enable_fan_recieve(dev, 0);
315
316 /* disable hardware IRQ and firmware flag */
317 ene_hw_write_reg_mask(dev, ENE_FW1, 0, ENE_FW1_ENABLE | ENE_FW1_IRQ);
318
319 ene_set_idle(dev, 1);
320 dev->in_use = 0;
321}
322
323/* sends current sample to userspace */
324static void send_sample(struct ene_device *dev)
325{
326 int value = abs(dev->sample) & PULSE_MASK;
327
328 if (dev->sample > 0)
329 value |= PULSE_BIT;
330
331 if (!lirc_buffer_full(dev->lirc_driver->rbuf)) {
332 lirc_buffer_write(dev->lirc_driver->rbuf, (void *)&value);
333 wake_up(&dev->lirc_driver->rbuf->wait_poll);
334 }
335 dev->sample = 0;
336}
337
338/* this updates current sample */
339static void update_sample(struct ene_device *dev, int sample)
340{
341 if (!dev->sample)
342 dev->sample = sample;
343 else if (same_sign(dev->sample, sample))
344 dev->sample += sample;
345 else {
346 send_sample(dev);
347 dev->sample = sample;
348 }
349}
350
351/* enable or disable idle mode */
352static void ene_set_idle(struct ene_device *dev, int idle)
353{
354 struct timeval now;
355 int disable = idle && enable_idle && (dev->hw_revision < ENE_HW_C);
356
357 ene_hw_write_reg_mask(dev, ENE_CIR_SAMPLE_PERIOD,
358 disable ? 0 : ENE_CIR_SAMPLE_OVERFLOW,
359 ENE_CIR_SAMPLE_OVERFLOW);
360 dev->idle = idle;
361
362 /* remember when we have entered the idle mode */
363 if (idle) {
364 do_gettimeofday(&dev->gap_start);
365 return;
366 }
367
368 /* send the gap between keypresses now */
369 do_gettimeofday(&now);
370
371 if (now.tv_sec - dev->gap_start.tv_sec > 16)
372 dev->sample = space(PULSE_MASK);
373 else
374 dev->sample = dev->sample +
375 space(1000000ull * (now.tv_sec - dev->gap_start.tv_sec))
376 + space(now.tv_usec - dev->gap_start.tv_usec);
377
378 if (abs(dev->sample) > PULSE_MASK)
379 dev->sample = space(PULSE_MASK);
380 send_sample(dev);
381}
382
383/* interrupt handler */
384static irqreturn_t ene_hw_irq(int irq, void *data)
385{
386 u16 hw_value;
387 int i, hw_sample;
388 int space;
389 int buffer_pointer;
390 int irq_status;
391
392 struct ene_device *dev = (struct ene_device *)data;
393 irq_status = ene_hw_irq_status(dev, &buffer_pointer);
394
395 if (!irq_status)
396 return IRQ_NONE;
397
398 /* TODO: only RX for now */
399 if (irq_status == ENE_IRQ_TX)
400 return IRQ_HANDLED;
401
402 for (i = 0; i < ENE_SAMPLES_SIZE; i++) {
403
404 hw_value = ene_hw_read_reg(dev,
405 ENE_SAMPLE_BUFFER + buffer_pointer + i);
406
407 if (dev->fan_input_inuse) {
408 /* read high part of the sample */
409 hw_value |= ene_hw_read_reg(dev,
410 ENE_SAMPLE_BUFFER_FAN + buffer_pointer + i) << 8;
411
412 /* test for _space_ bit */
413 space = !(hw_value & ENE_FAN_SMPL_PULS_MSK);
414
415 /* clear space bit, and other unused bits */
416 hw_value &= ENE_FAN_VALUE_MASK;
417 hw_sample = hw_value * ENE_SAMPLE_PERIOD_FAN;
418
419 } else {
420 space = hw_value & ENE_SAMPLE_SPC_MASK;
421 hw_value &= ENE_SAMPLE_VALUE_MASK;
422 hw_sample = hw_value * sample_period;
423 }
424
425 /* no more data */
426 if (!(hw_value))
427 break;
428
429 if (space)
430 hw_sample *= -1;
431
432 /* overflow sample recieved, handle it */
433
434 if (!dev->fan_input_inuse && hw_value == ENE_SAMPLE_OVERFLOW) {
435
436 if (dev->idle)
437 continue;
438
439 if (dev->sample > 0 || abs(dev->sample) <= ENE_MAXGAP)
440 update_sample(dev, hw_sample);
441 else
442 ene_set_idle(dev, 1);
443
444 continue;
445 }
446
447 /* normal first sample recieved */
448 if (!dev->fan_input_inuse && dev->idle) {
449 ene_set_idle(dev, 0);
450
451 /* discard first recieved value, its random
452 since its the time signal was off before
453 first pulse if idle mode is enabled, HW
454 does that for us */
455
456 if (!enable_idle)
457 continue;
458 }
459 update_sample(dev, hw_sample);
460 send_sample(dev);
461 }
462 return IRQ_HANDLED;
463}
464
465static int ene_probe(struct pnp_dev *pnp_dev,
466 const struct pnp_device_id *dev_id)
467{
468 struct ene_device *dev;
469 struct lirc_driver *lirc_driver;
470 int error = -ENOMEM;
471
472 dev = kzalloc(sizeof(struct ene_device), GFP_KERNEL);
473
474 if (!dev)
475 goto err1;
476
477 dev->pnp_dev = pnp_dev;
478 pnp_set_drvdata(pnp_dev, dev);
479
480
481 /* prepare lirc interface */
482 error = -ENOMEM;
483 lirc_driver = kzalloc(sizeof(struct lirc_driver), GFP_KERNEL);
484
485 if (!lirc_driver)
486 goto err2;
487
488 dev->lirc_driver = lirc_driver;
489
490 strcpy(lirc_driver->name, ENE_DRIVER_NAME);
491 lirc_driver->minor = -1;
492 lirc_driver->code_length = sizeof(int) * 8;
493 lirc_driver->features = LIRC_CAN_REC_MODE2;
494 lirc_driver->data = dev;
495 lirc_driver->set_use_inc = ene_hw_init;
496 lirc_driver->set_use_dec = ene_hw_deinit;
497 lirc_driver->dev = &pnp_dev->dev;
498 lirc_driver->owner = THIS_MODULE;
499
500 lirc_driver->rbuf = kzalloc(sizeof(struct lirc_buffer), GFP_KERNEL);
501
502 if (!lirc_driver->rbuf)
503 goto err3;
504
505 if (lirc_buffer_init(lirc_driver->rbuf, sizeof(int), sizeof(int) * 256))
506 goto err4;
507
508 error = -ENODEV;
509 if (lirc_register_driver(lirc_driver))
510 goto err5;
511
512 /* validate resources */
513 if (!pnp_port_valid(pnp_dev, 0) ||
514 pnp_port_len(pnp_dev, 0) < ENE_MAX_IO)
515 goto err6;
516
517 if (!pnp_irq_valid(pnp_dev, 0))
518 goto err6;
519
520 dev->hw_io = pnp_port_start(pnp_dev, 0);
521 dev->irq = pnp_irq(pnp_dev, 0);
522
523 /* claim the resources */
524 error = -EBUSY;
525 if (!request_region(dev->hw_io, ENE_MAX_IO, ENE_DRIVER_NAME))
526 goto err6;
527
528 if (request_irq(dev->irq, ene_hw_irq,
529 IRQF_SHARED, ENE_DRIVER_NAME, (void *)dev))
530 goto err7;
531
532 /* detect hardware version and features */
533 error = ene_hw_detect(dev);
534 if (error)
535 goto err8;
536
537 ene_printk(KERN_NOTICE, "driver has been succesfully loaded\n");
538 return 0;
539
540err8:
541 free_irq(dev->irq, dev);
542err7:
543 release_region(dev->hw_io, ENE_MAX_IO);
544err6:
545 lirc_unregister_driver(lirc_driver->minor);
546err5:
547 lirc_buffer_free(lirc_driver->rbuf);
548err4:
549 kfree(lirc_driver->rbuf);
550err3:
551 kfree(lirc_driver);
552err2:
553 kfree(dev);
554err1:
555 return error;
556}
557
558static void ene_remove(struct pnp_dev *pnp_dev)
559{
560 struct ene_device *dev = pnp_get_drvdata(pnp_dev);
561 ene_hw_deinit(dev);
562 free_irq(dev->irq, dev);
563 release_region(dev->hw_io, ENE_MAX_IO);
564 lirc_unregister_driver(dev->lirc_driver->minor);
565 lirc_buffer_free(dev->lirc_driver->rbuf);
566 kfree(dev->lirc_driver);
567 kfree(dev);
568}
569
570#ifdef CONFIG_PM
571
572/* TODO: make 'wake on IR' configurable and add .shutdown */
573/* currently impossible due to lack of kernel support */
574
575static int ene_suspend(struct pnp_dev *pnp_dev, pm_message_t state)
576{
577 struct ene_device *dev = pnp_get_drvdata(pnp_dev);
578 ene_hw_write_reg_mask(dev, ENE_FW1, ENE_FW1_WAKE, ENE_FW1_WAKE);
579 return 0;
580}
581
582static int ene_resume(struct pnp_dev *pnp_dev)
583{
584 struct ene_device *dev = pnp_get_drvdata(pnp_dev);
585 if (dev->in_use)
586 ene_hw_init(dev);
587
588 ene_hw_write_reg_mask(dev, ENE_FW1, 0, ENE_FW1_WAKE);
589 return 0;
590}
591
592#endif
593
594static const struct pnp_device_id ene_ids[] = {
595 {.id = "ENE0100",},
596 {},
597};
598
599static struct pnp_driver ene_driver = {
600 .name = ENE_DRIVER_NAME,
601 .id_table = ene_ids,
602 .flags = PNP_DRIVER_RES_DO_NOT_CHANGE,
603
604 .probe = ene_probe,
605 .remove = __devexit_p(ene_remove),
606
607#ifdef CONFIG_PM
608 .suspend = ene_suspend,
609 .resume = ene_resume,
610#endif
611};
612
613static int __init ene_init(void)
614{
615 if (sample_period < 5) {
616 ene_printk(KERN_ERR, "sample period must be at\n");
617 ene_printk(KERN_ERR, "least 5 us, (at least 30 recommended)\n");
618 return -EINVAL;
619 }
620 return pnp_register_driver(&ene_driver);
621}
622
623static void ene_exit(void)
624{
625 pnp_unregister_driver(&ene_driver);
626}
627
628module_param(sample_period, int, S_IRUGO);
629MODULE_PARM_DESC(sample_period, "Hardware sample period (75 us default)");
630
631module_param(enable_idle, bool, S_IRUGO | S_IWUSR);
632MODULE_PARM_DESC(enable_idle,
633 "Enables turning off signal sampling after long inactivity time; "
634 "if disabled might help detecting input signal (default: enabled)");
635
636module_param(enable_learning, bool, S_IRUGO);
637MODULE_PARM_DESC(enable_learning, "Use wide band (learning) reciever");
638
639MODULE_DEVICE_TABLE(pnp, ene_ids);
640MODULE_DESCRIPTION
641 ("LIRC driver for KB3926B/KB3926C/KB3926D (aka ENE0100) CIR port");
642MODULE_AUTHOR("Maxim Levitsky");
643MODULE_LICENSE("GPL");
644
645module_init(ene_init);
646module_exit(ene_exit);
diff --git a/drivers/staging/lirc/lirc_ene0100.h b/drivers/staging/lirc/lirc_ene0100.h
new file mode 100644
index 000000000000..776b693bb307
--- /dev/null
+++ b/drivers/staging/lirc/lirc_ene0100.h
@@ -0,0 +1,169 @@
1/*
2 * driver for ENE KB3926 B/C/D CIR (also known as ENE0100)
3 *
4 * Copyright (C) 2009 Maxim Levitsky <maximlevitsky@gmail.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; either version 2 of the
9 * License, or (at your option) any later version.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 * USA
20 */
21
22#include <media/lirc.h>
23#include <media/lirc_dev.h>
24
25/* hardware address */
26#define ENE_STATUS 0 /* hardware status - unused */
27#define ENE_ADDR_HI 1 /* hi byte of register address */
28#define ENE_ADDR_LO 2 /* low byte of register address */
29#define ENE_IO 3 /* read/write window */
30#define ENE_MAX_IO 4
31
32/* 8 bytes of samples, divided in 2 halfs*/
33#define ENE_SAMPLE_BUFFER 0xF8F0 /* regular sample buffer */
34#define ENE_SAMPLE_SPC_MASK (1 << 7) /* sample is space */
35#define ENE_SAMPLE_VALUE_MASK 0x7F
36#define ENE_SAMPLE_OVERFLOW 0x7F
37#define ENE_SAMPLES_SIZE 4
38
39/* fan input sample buffer */
40#define ENE_SAMPLE_BUFFER_FAN 0xF8FB /* this buffer holds high byte of */
41 /* each sample of normal buffer */
42
43#define ENE_FAN_SMPL_PULS_MSK 0x8000 /* this bit of combined sample */
44 /* if set, says that sample is pulse */
45#define ENE_FAN_VALUE_MASK 0x0FFF /* mask for valid bits of the value */
46
47/* first firmware register */
48#define ENE_FW1 0xF8F8
49#define ENE_FW1_ENABLE (1 << 0) /* enable fw processing */
50#define ENE_FW1_TXIRQ (1 << 1) /* TX interrupt pending */
51#define ENE_FW1_WAKE (1 << 6) /* enable wake from S3 */
52#define ENE_FW1_IRQ (1 << 7) /* enable interrupt */
53
54/* second firmware register */
55#define ENE_FW2 0xF8F9
56#define ENE_FW2_BUF_HIGH (1 << 0) /* which half of the buffer to read */
57#define ENE_FW2_IRQ_CLR (1 << 2) /* clear this on IRQ */
58#define ENE_FW2_GP40_AS_LEARN (1 << 4) /* normal input is used as */
59 /* learning input */
60#define ENE_FW2_FAN_AS_NRML_IN (1 << 6) /* fan is used as normal input */
61#define ENE_FW2_LEARNING (1 << 7) /* hardware supports learning and TX */
62
63/* fan as input settings - only if learning capable */
64#define ENE_FAN_AS_IN1 0xFE30 /* fan init reg 1 */
65#define ENE_FAN_AS_IN1_EN 0xCD
66#define ENE_FAN_AS_IN2 0xFE31 /* fan init reg 2 */
67#define ENE_FAN_AS_IN2_EN 0x03
68#define ENE_SAMPLE_PERIOD_FAN 61 /* fan input has fixed sample period */
69
70/* IRQ registers block (for revision B) */
71#define ENEB_IRQ 0xFD09 /* IRQ number */
72#define ENEB_IRQ_UNK1 0xFD17 /* unknown setting = 1 */
73#define ENEB_IRQ_STATUS 0xFD80 /* irq status */
74#define ENEB_IRQ_STATUS_IR (1 << 5) /* IR irq */
75
76/* IRQ registers block (for revision C,D) */
77#define ENEC_IRQ 0xFE9B /* new irq settings register */
78#define ENEC_IRQ_MASK 0x0F /* irq number mask */
79#define ENEC_IRQ_UNK_EN (1 << 4) /* always enabled */
80#define ENEC_IRQ_STATUS (1 << 5) /* irq status and ACK */
81
82/* CIR block settings */
83#define ENE_CIR_CONF1 0xFEC0
84#define ENE_CIR_CONF1_ADC_ON 0x7 /* reciever on gpio40 enabled */
85#define ENE_CIR_CONF1_LEARN1 (1 << 3) /* enabled on learning mode */
86#define ENE_CIR_CONF1_TX_ON 0x30 /* enabled on transmit */
87#define ENE_CIR_CONF1_TX_CARR (1 << 7) /* send TX carrier or not */
88
89#define ENE_CIR_CONF2 0xFEC1 /* unknown setting = 0 */
90#define ENE_CIR_CONF2_LEARN2 (1 << 4) /* set on enable learning */
91#define ENE_CIR_CONF2_GPIO40DIS (1 << 5) /* disable normal input via gpio40 */
92
93#define ENE_CIR_SAMPLE_PERIOD 0xFEC8 /* sample period in us */
94#define ENE_CIR_SAMPLE_OVERFLOW (1 << 7) /* interrupt on overflows if set */
95
96
97/* transmitter - not implemented yet */
98/* KB3926C and higher */
99/* transmission is very similiar to recieving, a byte is written to */
100/* ENE_TX_INPUT, in same manner as it is read from sample buffer */
101/* sample period is fixed*/
102
103
104/* transmitter ports */
105#define ENE_TX_PORT1 0xFC01 /* this enables one or both */
106#define ENE_TX_PORT1_EN (1 << 5) /* TX ports */
107#define ENE_TX_PORT2 0xFC08
108#define ENE_TX_PORT2_EN (1 << 1)
109
110#define ENE_TX_INPUT 0xFEC9 /* next byte to transmit */
111#define ENE_TX_SPC_MASK (1 << 7) /* Transmitted sample is space */
112#define ENE_TX_UNK1 0xFECB /* set to 0x63 */
113#define ENE_TX_SMPL_PERIOD 50 /* transmit sample period */
114
115
116#define ENE_TX_CARRIER 0xFECE /* TX carrier * 2 (khz) */
117#define ENE_TX_CARRIER_UNKBIT 0x80 /* This bit set on transmit */
118#define ENE_TX_CARRIER_LOW 0xFECF /* TX carrier / 2 */
119
120/* Hardware versions */
121#define ENE_HW_VERSION 0xFF00 /* hardware revision */
122#define ENE_HW_UNK 0xFF1D
123#define ENE_HW_UNK_CLR (1 << 2)
124#define ENE_HW_VER_MAJOR 0xFF1E /* chip version */
125#define ENE_HW_VER_MINOR 0xFF1F
126#define ENE_HW_VER_OLD 0xFD00
127
128#define same_sign(a, b) ((((a) > 0) && (b) > 0) || ((a) < 0 && (b) < 0))
129
130#define ENE_DRIVER_NAME "enecir"
131#define ENE_MAXGAP 250000 /* this is amount of time we wait
132 before turning the sampler, chosen
133 arbitry */
134
135#define space(len) (-(len)) /* add a space */
136
137/* software defines */
138#define ENE_IRQ_RX 1
139#define ENE_IRQ_TX 2
140
141#define ENE_HW_B 1 /* 3926B */
142#define ENE_HW_C 2 /* 3926C */
143#define ENE_HW_D 3 /* 3926D */
144
145#define ene_printk(level, text, ...) \
146 printk(level ENE_DRIVER_NAME ": " text, ## __VA_ARGS__)
147
148struct ene_device {
149 struct pnp_dev *pnp_dev;
150 struct lirc_driver *lirc_driver;
151
152 /* hw settings */
153 unsigned long hw_io;
154 int irq;
155
156 int hw_revision; /* hardware revision */
157 int hw_learning_and_tx_capable; /* learning capable */
158 int hw_gpio40_learning; /* gpio40 is learning */
159 int hw_fan_as_normal_input; /* fan input is used as regular input */
160
161 /* device data */
162 int idle;
163 int fan_input_inuse;
164
165 int sample;
166 int in_use;
167
168 struct timeval gap_start;
169};
diff --git a/drivers/staging/lirc/lirc_i2c.c b/drivers/staging/lirc/lirc_i2c.c
new file mode 100644
index 000000000000..6df2c0e8d721
--- /dev/null
+++ b/drivers/staging/lirc/lirc_i2c.c
@@ -0,0 +1,536 @@
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_igorplugusb.c b/drivers/staging/lirc/lirc_igorplugusb.c
new file mode 100644
index 000000000000..bce600ede263
--- /dev/null
+++ b/drivers/staging/lirc/lirc_igorplugusb.c
@@ -0,0 +1,555 @@
1/*
2 * lirc_igorplugusb - USB remote support for LIRC
3 *
4 * Supports the standard homebrew IgorPlugUSB receiver with Igor's firmware.
5 * See http://www.cesko.host.sk/IgorPlugUSB/IgorPlug-USB%20(AVR)_eng.htm
6 *
7 * The device can only record bursts of up to 36 pulses/spaces.
8 * Works fine with RC5. Longer commands lead to device buffer overrun.
9 * (Maybe a better firmware or a microcontroller with more ram can help?)
10 *
11 * Version 0.1 [beta status]
12 *
13 * Copyright (C) 2004 Jan M. Hochstein
14 * <hochstein@algo.informatik.tu-darmstadt.de>
15 *
16 * This driver was derived from:
17 * Paul Miller <pmiller9@users.sourceforge.net>
18 * "lirc_atiusb" module
19 * Vladimir Dergachev <volodya@minspring.com>'s 2002
20 * "USB ATI Remote support" (input device)
21 * Adrian Dewhurst <sailor-lk@sailorfrag.net>'s 2002
22 * "USB StreamZap remote driver" (LIRC)
23 * Artur Lipowski <alipowski@kki.net.pl>'s 2002
24 * "lirc_dev" and "lirc_gpio" LIRC modules
25 */
26
27/*
28 * This program is free software; you can redistribute it and/or modify
29 * it under the terms of the GNU General Public License as published by
30 * the Free Software Foundation; either version 2 of the License, or
31 * (at your option) any later version.
32 *
33 * This program is distributed in the hope that it will be useful,
34 * but WITHOUT ANY WARRANTY; without even the implied warranty of
35 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36 * GNU General Public License for more details.
37 *
38 * You should have received a copy of the GNU General Public License
39 * along with this program; if not, write to the Free Software
40 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
41 */
42
43#include <linux/module.h>
44#include <linux/kernel.h>
45#include <linux/kmod.h>
46#include <linux/sched.h>
47#include <linux/errno.h>
48#include <linux/fs.h>
49#include <linux/usb.h>
50#include <linux/time.h>
51
52#include <media/lirc.h>
53#include <media/lirc_dev.h>
54
55
56/* module identification */
57#define DRIVER_VERSION "0.1"
58#define DRIVER_AUTHOR \
59 "Jan M. Hochstein <hochstein@algo.informatik.tu-darmstadt.de>"
60#define DRIVER_DESC "USB remote driver for LIRC"
61#define DRIVER_NAME "lirc_igorplugusb"
62
63/* debugging support */
64#ifdef CONFIG_USB_DEBUG
65static int debug = 1;
66#else
67static int debug;
68#endif
69
70#define dprintk(fmt, args...) \
71 do { \
72 if (debug) \
73 printk(KERN_DEBUG fmt, ## args); \
74 } while (0)
75
76/* One mode2 pulse/space has 4 bytes. */
77#define CODE_LENGTH sizeof(int)
78
79/* Igor's firmware cannot record bursts longer than 36. */
80#define DEVICE_BUFLEN 36
81
82/*
83 * Header at the beginning of the device's buffer:
84 * unsigned char data_length
85 * unsigned char data_start (!=0 means ring-buffer overrun)
86 * unsigned char counter (incremented by each burst)
87 */
88#define DEVICE_HEADERLEN 3
89
90/* This is for the gap */
91#define ADDITIONAL_LIRC_BYTES 2
92
93/* times to poll per second */
94#define SAMPLE_RATE 100
95static int sample_rate = SAMPLE_RATE;
96
97
98/**** Igor's USB Request Codes */
99
100#define SET_INFRABUFFER_EMPTY 1
101/**
102 * Params: none
103 * Answer: empty
104 */
105
106#define GET_INFRACODE 2
107/**
108 * Params:
109 * wValue: offset to begin reading infra buffer
110 *
111 * Answer: infra data
112 */
113
114#define SET_DATAPORT_DIRECTION 3
115/**
116 * Params:
117 * wValue: (byte) 1 bit for each data port pin (0=in, 1=out)
118 *
119 * Answer: empty
120 */
121
122#define GET_DATAPORT_DIRECTION 4
123/**
124 * Params: none
125 *
126 * Answer: (byte) 1 bit for each data port pin (0=in, 1=out)
127 */
128
129#define SET_OUT_DATAPORT 5
130/**
131 * Params:
132 * wValue: byte to write to output data port
133 *
134 * Answer: empty
135 */
136
137#define GET_OUT_DATAPORT 6
138/**
139 * Params: none
140 *
141 * Answer: least significant 3 bits read from output data port
142 */
143
144#define GET_IN_DATAPORT 7
145/**
146 * Params: none
147 *
148 * Answer: least significant 3 bits read from input data port
149 */
150
151#define READ_EEPROM 8
152/**
153 * Params:
154 * wValue: offset to begin reading EEPROM
155 *
156 * Answer: EEPROM bytes
157 */
158
159#define WRITE_EEPROM 9
160/**
161 * Params:
162 * wValue: offset to EEPROM byte
163 * wIndex: byte to write
164 *
165 * Answer: empty
166 */
167
168#define SEND_RS232 10
169/**
170 * Params:
171 * wValue: byte to send
172 *
173 * Answer: empty
174 */
175
176#define RECV_RS232 11
177/**
178 * Params: none
179 *
180 * Answer: byte received
181 */
182
183#define SET_RS232_BAUD 12
184/**
185 * Params:
186 * wValue: byte to write to UART bit rate register (UBRR)
187 *
188 * Answer: empty
189 */
190
191#define GET_RS232_BAUD 13
192/**
193 * Params: none
194 *
195 * Answer: byte read from UART bit rate register (UBRR)
196 */
197
198
199/* data structure for each usb remote */
200struct igorplug {
201
202 /* usb */
203 struct usb_device *usbdev;
204 struct urb *urb_in;
205 int devnum;
206
207 unsigned char *buf_in;
208 unsigned int len_in;
209 int in_space;
210 struct timeval last_time;
211
212 dma_addr_t dma_in;
213
214 /* lirc */
215 struct lirc_driver *d;
216
217 /* handle sending (init strings) */
218 int send_flags;
219 wait_queue_head_t wait_out;
220};
221
222static int unregister_from_lirc(struct igorplug *ir)
223{
224 struct lirc_driver *d = ir->d;
225 int devnum;
226
227 if (!ir->d)
228 return -EINVAL;
229
230 devnum = ir->devnum;
231 dprintk(DRIVER_NAME "[%d]: unregister from lirc called\n", devnum);
232
233 lirc_unregister_driver(d->minor);
234
235 printk(DRIVER_NAME "[%d]: usb remote disconnected\n", devnum);
236
237 kfree(d);
238 ir->d = NULL;
239 kfree(ir);
240 return 0;
241}
242
243static int set_use_inc(void *data)
244{
245 struct igorplug *ir = data;
246
247 if (!ir) {
248 printk(DRIVER_NAME "[?]: set_use_inc called with no context\n");
249 return -EIO;
250 }
251 dprintk(DRIVER_NAME "[%d]: set use inc\n", ir->devnum);
252
253 if (!ir->usbdev)
254 return -ENODEV;
255
256 return 0;
257}
258
259static void set_use_dec(void *data)
260{
261 struct igorplug *ir = data;
262
263 if (!ir) {
264 printk(DRIVER_NAME "[?]: set_use_dec called with no context\n");
265 return;
266 }
267 dprintk(DRIVER_NAME "[%d]: set use dec\n", ir->devnum);
268}
269
270
271/**
272 * Called in user context.
273 * return 0 if data was added to the buffer and
274 * -ENODATA if none was available. This should add some number of bits
275 * evenly divisible by code_length to the buffer
276 */
277static int usb_remote_poll(void *data, struct lirc_buffer *buf)
278{
279 int ret;
280 struct igorplug *ir = (struct igorplug *)data;
281
282 if (!ir->usbdev) /* Has the device been removed? */
283 return -ENODEV;
284
285 memset(ir->buf_in, 0, ir->len_in);
286
287 ret = usb_control_msg(
288 ir->usbdev, usb_rcvctrlpipe(ir->usbdev, 0),
289 GET_INFRACODE, USB_TYPE_VENDOR|USB_DIR_IN,
290 0/* offset */, /*unused*/0,
291 ir->buf_in, ir->len_in,
292 /*timeout*/HZ * USB_CTRL_GET_TIMEOUT);
293 if (ret > 0) {
294 int i = DEVICE_HEADERLEN;
295 int code, timediff;
296 struct timeval now;
297
298 if (ret <= 1) /* ACK packet has 1 byte --> ignore */
299 return -ENODATA;
300
301 dprintk(DRIVER_NAME ": Got %d bytes. Header: %02x %02x %02x\n",
302 ret, ir->buf_in[0], ir->buf_in[1], ir->buf_in[2]);
303
304 if (ir->buf_in[2] != 0) {
305 printk(DRIVER_NAME "[%d]: Device buffer overrun.\n",
306 ir->devnum);
307 /* start at earliest byte */
308 i = DEVICE_HEADERLEN + ir->buf_in[2];
309 /* where are we now? space, gap or pulse? */
310 }
311
312 do_gettimeofday(&now);
313 timediff = now.tv_sec - ir->last_time.tv_sec;
314 if (timediff + 1 > PULSE_MASK / 1000000)
315 timediff = PULSE_MASK;
316 else {
317 timediff *= 1000000;
318 timediff += now.tv_usec - ir->last_time.tv_usec;
319 }
320 ir->last_time.tv_sec = now.tv_sec;
321 ir->last_time.tv_usec = now.tv_usec;
322
323 /* create leading gap */
324 code = timediff;
325 lirc_buffer_write(buf, (unsigned char *)&code);
326 ir->in_space = 1; /* next comes a pulse */
327
328 /* MODE2: pulse/space (PULSE_BIT) in 1us units */
329
330 while (i < ret) {
331 /* 1 Igor-tick = 85.333333 us */
332 code = (unsigned int)ir->buf_in[i] * 85
333 + (unsigned int)ir->buf_in[i] / 3;
334 if (ir->in_space)
335 code |= PULSE_BIT;
336 lirc_buffer_write(buf, (unsigned char *)&code);
337 /* 1 chunk = CODE_LENGTH bytes */
338 ir->in_space ^= 1;
339 ++i;
340 }
341
342 ret = usb_control_msg(
343 ir->usbdev, usb_rcvctrlpipe(ir->usbdev, 0),
344 SET_INFRABUFFER_EMPTY, USB_TYPE_VENDOR|USB_DIR_IN,
345 /*unused*/0, /*unused*/0,
346 /*dummy*/ir->buf_in, /*dummy*/ir->len_in,
347 /*timeout*/HZ * USB_CTRL_GET_TIMEOUT);
348 if (ret < 0)
349 printk(DRIVER_NAME "[%d]: SET_INFRABUFFER_EMPTY: "
350 "error %d\n", ir->devnum, ret);
351 return 0;
352 } else if (ret < 0)
353 printk(DRIVER_NAME "[%d]: GET_INFRACODE: error %d\n",
354 ir->devnum, ret);
355
356 return -ENODATA;
357}
358
359
360
361static int usb_remote_probe(struct usb_interface *intf,
362 const struct usb_device_id *id)
363{
364 struct usb_device *dev = NULL;
365 struct usb_host_interface *idesc = NULL;
366 struct usb_host_endpoint *ep_ctl2;
367 struct igorplug *ir = NULL;
368 struct lirc_driver *driver = NULL;
369 int devnum, pipe, maxp;
370 int minor = 0;
371 char buf[63], name[128] = "";
372 int mem_failure = 0;
373 int ret;
374
375 dprintk(DRIVER_NAME ": usb probe called.\n");
376
377 dev = interface_to_usbdev(intf);
378
379 idesc = intf->cur_altsetting;
380
381 if (idesc->desc.bNumEndpoints != 1)
382 return -ENODEV;
383 ep_ctl2 = idesc->endpoint;
384 if (((ep_ctl2->desc.bEndpointAddress & USB_ENDPOINT_DIR_MASK)
385 != USB_DIR_IN)
386 || (ep_ctl2->desc.bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
387 != USB_ENDPOINT_XFER_CONTROL)
388 return -ENODEV;
389 pipe = usb_rcvctrlpipe(dev, ep_ctl2->desc.bEndpointAddress);
390 devnum = dev->devnum;
391 maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe));
392
393 dprintk(DRIVER_NAME "[%d]: bytes_in_key=%lu maxp=%d\n",
394 devnum, CODE_LENGTH, maxp);
395
396
397 mem_failure = 0;
398 ir = kzalloc(sizeof(struct igorplug), GFP_KERNEL);
399 if (!ir) {
400 mem_failure = 1;
401 goto mem_failure_switch;
402 }
403 driver = kzalloc(sizeof(struct lirc_driver), GFP_KERNEL);
404 if (!driver) {
405 mem_failure = 2;
406 goto mem_failure_switch;
407 }
408
409 ir->buf_in = usb_alloc_coherent(dev,
410 DEVICE_BUFLEN+DEVICE_HEADERLEN,
411 GFP_ATOMIC, &ir->dma_in);
412 if (!ir->buf_in) {
413 mem_failure = 3;
414 goto mem_failure_switch;
415 }
416
417 strcpy(driver->name, DRIVER_NAME " ");
418 driver->minor = -1;
419 driver->code_length = CODE_LENGTH * 8; /* in bits */
420 driver->features = LIRC_CAN_REC_MODE2;
421 driver->data = ir;
422 driver->chunk_size = CODE_LENGTH;
423 driver->buffer_size = DEVICE_BUFLEN + ADDITIONAL_LIRC_BYTES;
424 driver->set_use_inc = &set_use_inc;
425 driver->set_use_dec = &set_use_dec;
426 driver->sample_rate = sample_rate; /* per second */
427 driver->add_to_buf = &usb_remote_poll;
428 driver->dev = &intf->dev;
429 driver->owner = THIS_MODULE;
430
431 init_waitqueue_head(&ir->wait_out);
432
433 minor = lirc_register_driver(driver);
434 if (minor < 0)
435 mem_failure = 9;
436
437mem_failure_switch:
438
439 switch (mem_failure) {
440 case 9:
441 usb_free_coherent(dev, DEVICE_BUFLEN+DEVICE_HEADERLEN,
442 ir->buf_in, ir->dma_in);
443 case 3:
444 kfree(driver);
445 case 2:
446 kfree(ir);
447 case 1:
448 printk(DRIVER_NAME "[%d]: out of memory (code=%d)\n",
449 devnum, mem_failure);
450 return -ENOMEM;
451 }
452
453 driver->minor = minor;
454 ir->d = driver;
455 ir->devnum = devnum;
456 ir->usbdev = dev;
457 ir->len_in = DEVICE_BUFLEN+DEVICE_HEADERLEN;
458 ir->in_space = 1; /* First mode2 event is a space. */
459 do_gettimeofday(&ir->last_time);
460
461 if (dev->descriptor.iManufacturer
462 && usb_string(dev, dev->descriptor.iManufacturer,
463 buf, sizeof(buf)) > 0)
464 strlcpy(name, buf, sizeof(name));
465 if (dev->descriptor.iProduct
466 && usb_string(dev, dev->descriptor.iProduct, buf, sizeof(buf)) > 0)
467 snprintf(name + strlen(name), sizeof(name) - strlen(name),
468 " %s", buf);
469 printk(DRIVER_NAME "[%d]: %s on usb%d:%d\n", devnum, name,
470 dev->bus->busnum, devnum);
471
472 /* clear device buffer */
473 ret = usb_control_msg(ir->usbdev, usb_rcvctrlpipe(ir->usbdev, 0),
474 SET_INFRABUFFER_EMPTY, USB_TYPE_VENDOR|USB_DIR_IN,
475 /*unused*/0, /*unused*/0,
476 /*dummy*/ir->buf_in, /*dummy*/ir->len_in,
477 /*timeout*/HZ * USB_CTRL_GET_TIMEOUT);
478 if (ret < 0)
479 printk(DRIVER_NAME "[%d]: SET_INFRABUFFER_EMPTY: error %d\n",
480 devnum, ret);
481
482 usb_set_intfdata(intf, ir);
483 return 0;
484}
485
486
487static void usb_remote_disconnect(struct usb_interface *intf)
488{
489 struct usb_device *dev = interface_to_usbdev(intf);
490 struct igorplug *ir = usb_get_intfdata(intf);
491 usb_set_intfdata(intf, NULL);
492
493 if (!ir || !ir->d)
494 return;
495
496 ir->usbdev = NULL;
497 wake_up_all(&ir->wait_out);
498
499 usb_free_coherent(dev, ir->len_in, ir->buf_in, ir->dma_in);
500
501 unregister_from_lirc(ir);
502}
503
504static struct usb_device_id usb_remote_id_table[] = {
505 /* Igor Plug USB (Atmel's Manufact. ID) */
506 { USB_DEVICE(0x03eb, 0x0002) },
507
508 /* Terminating entry */
509 { }
510};
511
512static struct usb_driver usb_remote_driver = {
513 .name = DRIVER_NAME,
514 .probe = usb_remote_probe,
515 .disconnect = usb_remote_disconnect,
516 .id_table = usb_remote_id_table
517};
518
519static int __init usb_remote_init(void)
520{
521 int i;
522
523 printk(KERN_INFO "\n"
524 DRIVER_NAME ": " DRIVER_DESC " v" DRIVER_VERSION "\n");
525 printk(DRIVER_NAME ": " DRIVER_AUTHOR "\n");
526 dprintk(DRIVER_NAME ": debug mode enabled\n");
527
528 i = usb_register(&usb_remote_driver);
529 if (i < 0) {
530 printk(DRIVER_NAME ": usb register failed, result = %d\n", i);
531 return -ENODEV;
532 }
533
534 return 0;
535}
536
537static void __exit usb_remote_exit(void)
538{
539 usb_deregister(&usb_remote_driver);
540}
541
542module_init(usb_remote_init);
543module_exit(usb_remote_exit);
544
545#include <linux/vermagic.h>
546MODULE_INFO(vermagic, VERMAGIC_STRING);
547
548MODULE_DESCRIPTION(DRIVER_DESC);
549MODULE_AUTHOR(DRIVER_AUTHOR);
550MODULE_LICENSE("GPL");
551MODULE_DEVICE_TABLE(usb, usb_remote_id_table);
552
553module_param(sample_rate, int, S_IRUGO | S_IWUSR);
554MODULE_PARM_DESC(sample_rate, "Sampling rate in Hz (default: 100)");
555
diff --git a/drivers/staging/lirc/lirc_imon.c b/drivers/staging/lirc/lirc_imon.c
new file mode 100644
index 000000000000..66493253042e
--- /dev/null
+++ b/drivers/staging/lirc/lirc_imon.c
@@ -0,0 +1,1058 @@
1/*
2 * lirc_imon.c: LIRC/VFD/LCD driver for SoundGraph iMON IR/VFD/LCD
3 * including the iMON PAD model
4 *
5 * Copyright(C) 2004 Venky Raju(dev@venky.ws)
6 * Copyright(C) 2009 Jarod Wilson <jarod@wilsonet.com>
7 *
8 * lirc_imon is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23#include <linux/errno.h>
24#include <linux/init.h>
25#include <linux/kernel.h>
26#include <linux/module.h>
27#include <linux/slab.h>
28#include <linux/uaccess.h>
29#include <linux/usb.h>
30
31#include <media/lirc.h>
32#include <media/lirc_dev.h>
33
34
35#define MOD_AUTHOR "Venky Raju <dev@venky.ws>"
36#define MOD_DESC "Driver for SoundGraph iMON MultiMedia IR/Display"
37#define MOD_NAME "lirc_imon"
38#define MOD_VERSION "0.8"
39
40#define DISPLAY_MINOR_BASE 144
41#define DEVICE_NAME "lcd%d"
42
43#define BUF_CHUNK_SIZE 4
44#define BUF_SIZE 128
45
46#define BIT_DURATION 250 /* each bit received is 250us */
47
48/*** P R O T O T Y P E S ***/
49
50/* USB Callback prototypes */
51static int imon_probe(struct usb_interface *interface,
52 const struct usb_device_id *id);
53static void imon_disconnect(struct usb_interface *interface);
54static void usb_rx_callback(struct urb *urb);
55static void usb_tx_callback(struct urb *urb);
56
57/* suspend/resume support */
58static int imon_resume(struct usb_interface *intf);
59static int imon_suspend(struct usb_interface *intf, pm_message_t message);
60
61/* Display file_operations function prototypes */
62static int display_open(struct inode *inode, struct file *file);
63static int display_close(struct inode *inode, struct file *file);
64
65/* VFD write operation */
66static ssize_t vfd_write(struct file *file, const char *buf,
67 size_t n_bytes, loff_t *pos);
68
69/* LIRC driver function prototypes */
70static int ir_open(void *data);
71static void ir_close(void *data);
72
73/* Driver init/exit prototypes */
74static int __init imon_init(void);
75static void __exit imon_exit(void);
76
77/*** G L O B A L S ***/
78#define IMON_DATA_BUF_SZ 35
79
80struct imon_context {
81 struct usb_device *usbdev;
82 /* Newer devices have two interfaces */
83 int display; /* not all controllers do */
84 int display_isopen; /* display port has been opened */
85 int ir_isopen; /* IR port open */
86 int dev_present; /* USB device presence */
87 struct mutex ctx_lock; /* to lock this object */
88 wait_queue_head_t remove_ok; /* For unexpected USB disconnects */
89
90 int vfd_proto_6p; /* some VFD require a 6th packet */
91
92 struct lirc_driver *driver;
93 struct usb_endpoint_descriptor *rx_endpoint;
94 struct usb_endpoint_descriptor *tx_endpoint;
95 struct urb *rx_urb;
96 struct urb *tx_urb;
97 unsigned char usb_rx_buf[8];
98 unsigned char usb_tx_buf[8];
99
100 struct rx_data {
101 int count; /* length of 0 or 1 sequence */
102 int prev_bit; /* logic level of sequence */
103 int initial_space; /* initial space flag */
104 } rx;
105
106 struct tx_t {
107 unsigned char data_buf[IMON_DATA_BUF_SZ]; /* user data buffer */
108 struct completion finished; /* wait for write to finish */
109 atomic_t busy; /* write in progress */
110 int status; /* status of tx completion */
111 } tx;
112};
113
114static const struct file_operations display_fops = {
115 .owner = THIS_MODULE,
116 .open = &display_open,
117 .write = &vfd_write,
118 .release = &display_close
119};
120
121/*
122 * USB Device ID for iMON USB Control Boards
123 *
124 * The Windows drivers contain 6 different inf files, more or less one for
125 * each new device until the 0x0034-0x0046 devices, which all use the same
126 * driver. Some of the devices in the 34-46 range haven't been definitively
127 * identified yet. Early devices have either a TriGem Computer, Inc. or a
128 * Samsung vendor ID (0x0aa8 and 0x04e8 respectively), while all later
129 * devices use the SoundGraph vendor ID (0x15c2).
130 */
131static struct usb_device_id imon_usb_id_table[] = {
132 /* TriGem iMON (IR only) -- TG_iMON.inf */
133 { USB_DEVICE(0x0aa8, 0x8001) },
134
135 /* SoundGraph iMON (IR only) -- sg_imon.inf */
136 { USB_DEVICE(0x04e8, 0xff30) },
137
138 /* SoundGraph iMON VFD (IR & VFD) -- iMON_VFD.inf */
139 { USB_DEVICE(0x0aa8, 0xffda) },
140
141 /* SoundGraph iMON SS (IR & VFD) -- iMON_SS.inf */
142 { USB_DEVICE(0x15c2, 0xffda) },
143
144 {}
145};
146
147/* Some iMON VFD models requires a 6th packet for VFD writes */
148static struct usb_device_id vfd_proto_6p_list[] = {
149 { USB_DEVICE(0x15c2, 0xffda) },
150 {}
151};
152
153/* Some iMON devices have no lcd/vfd, don't set one up */
154static struct usb_device_id ir_only_list[] = {
155 { USB_DEVICE(0x0aa8, 0x8001) },
156 { USB_DEVICE(0x04e8, 0xff30) },
157 {}
158};
159
160/* USB Device data */
161static struct usb_driver imon_driver = {
162 .name = MOD_NAME,
163 .probe = imon_probe,
164 .disconnect = imon_disconnect,
165 .suspend = imon_suspend,
166 .resume = imon_resume,
167 .id_table = imon_usb_id_table,
168};
169
170static struct usb_class_driver imon_class = {
171 .name = DEVICE_NAME,
172 .fops = &display_fops,
173 .minor_base = DISPLAY_MINOR_BASE,
174};
175
176/* to prevent races between open() and disconnect(), probing, etc */
177static DEFINE_MUTEX(driver_lock);
178
179static int debug;
180
181/*** M O D U L E C O D E ***/
182
183MODULE_AUTHOR(MOD_AUTHOR);
184MODULE_DESCRIPTION(MOD_DESC);
185MODULE_VERSION(MOD_VERSION);
186MODULE_LICENSE("GPL");
187MODULE_DEVICE_TABLE(usb, imon_usb_id_table);
188module_param(debug, int, S_IRUGO | S_IWUSR);
189MODULE_PARM_DESC(debug, "Debug messages: 0=no, 1=yes(default: no)");
190
191static void free_imon_context(struct imon_context *context)
192{
193 struct device *dev = context->driver->dev;
194 usb_free_urb(context->tx_urb);
195 usb_free_urb(context->rx_urb);
196 lirc_buffer_free(context->driver->rbuf);
197 kfree(context->driver->rbuf);
198 kfree(context->driver);
199 kfree(context);
200
201 dev_dbg(dev, "%s: iMON context freed\n", __func__);
202}
203
204static void deregister_from_lirc(struct imon_context *context)
205{
206 int retval;
207 int minor = context->driver->minor;
208
209 retval = lirc_unregister_driver(minor);
210 if (retval)
211 err("%s: unable to deregister from lirc(%d)",
212 __func__, retval);
213 else
214 printk(KERN_INFO MOD_NAME ": Deregistered iMON driver "
215 "(minor:%d)\n", minor);
216
217}
218
219/**
220 * Called when the Display device (e.g. /dev/lcd0)
221 * is opened by the application.
222 */
223static int display_open(struct inode *inode, struct file *file)
224{
225 struct usb_interface *interface;
226 struct imon_context *context = NULL;
227 int subminor;
228 int retval = 0;
229
230 /* prevent races with disconnect */
231 mutex_lock(&driver_lock);
232
233 subminor = iminor(inode);
234 interface = usb_find_interface(&imon_driver, subminor);
235 if (!interface) {
236 err("%s: could not find interface for minor %d",
237 __func__, subminor);
238 retval = -ENODEV;
239 goto exit;
240 }
241 context = usb_get_intfdata(interface);
242
243 if (!context) {
244 err("%s: no context found for minor %d",
245 __func__, subminor);
246 retval = -ENODEV;
247 goto exit;
248 }
249
250 mutex_lock(&context->ctx_lock);
251
252 if (!context->display) {
253 err("%s: display not supported by device", __func__);
254 retval = -ENODEV;
255 } else if (context->display_isopen) {
256 err("%s: display port is already open", __func__);
257 retval = -EBUSY;
258 } else {
259 context->display_isopen = 1;
260 file->private_data = context;
261 dev_info(context->driver->dev, "display port opened\n");
262 }
263
264 mutex_unlock(&context->ctx_lock);
265
266exit:
267 mutex_unlock(&driver_lock);
268 return retval;
269}
270
271/**
272 * Called when the display device (e.g. /dev/lcd0)
273 * is closed by the application.
274 */
275static int display_close(struct inode *inode, struct file *file)
276{
277 struct imon_context *context = NULL;
278 int retval = 0;
279
280 context = (struct imon_context *)file->private_data;
281
282 if (!context) {
283 err("%s: no context for device", __func__);
284 return -ENODEV;
285 }
286
287 mutex_lock(&context->ctx_lock);
288
289 if (!context->display) {
290 err("%s: display not supported by device", __func__);
291 retval = -ENODEV;
292 } else if (!context->display_isopen) {
293 err("%s: display is not open", __func__);
294 retval = -EIO;
295 } else {
296 context->display_isopen = 0;
297 dev_info(context->driver->dev, "display port closed\n");
298 if (!context->dev_present && !context->ir_isopen) {
299 /*
300 * Device disconnected before close and IR port is not
301 * open. If IR port is open, context will be deleted by
302 * ir_close.
303 */
304 mutex_unlock(&context->ctx_lock);
305 free_imon_context(context);
306 return retval;
307 }
308 }
309
310 mutex_unlock(&context->ctx_lock);
311 return retval;
312}
313
314/**
315 * Sends a packet to the device -- this function must be called
316 * with context->ctx_lock held.
317 */
318static int send_packet(struct imon_context *context)
319{
320 unsigned int pipe;
321 int interval = 0;
322 int retval = 0;
323 struct usb_ctrlrequest *control_req = NULL;
324
325 /* Check if we need to use control or interrupt urb */
326 pipe = usb_sndintpipe(context->usbdev,
327 context->tx_endpoint->bEndpointAddress);
328 interval = context->tx_endpoint->bInterval;
329
330 usb_fill_int_urb(context->tx_urb, context->usbdev, pipe,
331 context->usb_tx_buf,
332 sizeof(context->usb_tx_buf),
333 usb_tx_callback, context, interval);
334
335 context->tx_urb->actual_length = 0;
336
337 init_completion(&context->tx.finished);
338 atomic_set(&(context->tx.busy), 1);
339
340 retval = usb_submit_urb(context->tx_urb, GFP_KERNEL);
341 if (retval) {
342 atomic_set(&(context->tx.busy), 0);
343 err("%s: error submitting urb(%d)", __func__, retval);
344 } else {
345 /* Wait for transmission to complete (or abort) */
346 mutex_unlock(&context->ctx_lock);
347 retval = wait_for_completion_interruptible(
348 &context->tx.finished);
349 if (retval)
350 err("%s: task interrupted", __func__);
351 mutex_lock(&context->ctx_lock);
352
353 retval = context->tx.status;
354 if (retval)
355 err("%s: packet tx failed (%d)", __func__, retval);
356 }
357
358 kfree(control_req);
359
360 return retval;
361}
362
363/**
364 * Writes data to the VFD. The iMON VFD is 2x16 characters
365 * and requires data in 5 consecutive USB interrupt packets,
366 * each packet but the last carrying 7 bytes.
367 *
368 * I don't know if the VFD board supports features such as
369 * scrolling, clearing rows, blanking, etc. so at
370 * the caller must provide a full screen of data. If fewer
371 * than 32 bytes are provided spaces will be appended to
372 * generate a full screen.
373 */
374static ssize_t vfd_write(struct file *file, const char *buf,
375 size_t n_bytes, loff_t *pos)
376{
377 int i;
378 int offset;
379 int seq;
380 int retval = 0;
381 struct imon_context *context;
382 const unsigned char vfd_packet6[] = {
383 0x01, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF };
384 int *data_buf;
385
386 context = (struct imon_context *)file->private_data;
387 if (!context) {
388 err("%s: no context for device", __func__);
389 return -ENODEV;
390 }
391
392 mutex_lock(&context->ctx_lock);
393
394 if (!context->dev_present) {
395 err("%s: no iMON device present", __func__);
396 retval = -ENODEV;
397 goto exit;
398 }
399
400 if (n_bytes <= 0 || n_bytes > IMON_DATA_BUF_SZ - 3) {
401 err("%s: invalid payload size", __func__);
402 retval = -EINVAL;
403 goto exit;
404 }
405
406 data_buf = memdup_user(buf, n_bytes);
407 if (IS_ERR(data_buf)) {
408 retval = PTR_ERR(data_buf);
409 goto exit;
410 }
411
412 memcpy(context->tx.data_buf, data_buf, n_bytes);
413
414 /* Pad with spaces */
415 for (i = n_bytes; i < IMON_DATA_BUF_SZ - 3; ++i)
416 context->tx.data_buf[i] = ' ';
417
418 for (i = IMON_DATA_BUF_SZ - 3; i < IMON_DATA_BUF_SZ; ++i)
419 context->tx.data_buf[i] = 0xFF;
420
421 offset = 0;
422 seq = 0;
423
424 do {
425 memcpy(context->usb_tx_buf, context->tx.data_buf + offset, 7);
426 context->usb_tx_buf[7] = (unsigned char) seq;
427
428 retval = send_packet(context);
429 if (retval) {
430 err("%s: send packet failed for packet #%d",
431 __func__, seq/2);
432 goto exit;
433 } else {
434 seq += 2;
435 offset += 7;
436 }
437
438 } while (offset < IMON_DATA_BUF_SZ);
439
440 if (context->vfd_proto_6p) {
441 /* Send packet #6 */
442 memcpy(context->usb_tx_buf, &vfd_packet6, sizeof(vfd_packet6));
443 context->usb_tx_buf[7] = (unsigned char) seq;
444 retval = send_packet(context);
445 if (retval)
446 err("%s: send packet failed for packet #%d",
447 __func__, seq/2);
448 }
449
450exit:
451 mutex_unlock(&context->ctx_lock);
452
453 return (!retval) ? n_bytes : retval;
454}
455
456/**
457 * Callback function for USB core API: transmit data
458 */
459static void usb_tx_callback(struct urb *urb)
460{
461 struct imon_context *context;
462
463 if (!urb)
464 return;
465 context = (struct imon_context *)urb->context;
466 if (!context)
467 return;
468
469 context->tx.status = urb->status;
470
471 /* notify waiters that write has finished */
472 atomic_set(&context->tx.busy, 0);
473 complete(&context->tx.finished);
474
475 return;
476}
477
478/**
479 * Called by lirc_dev when the application opens /dev/lirc
480 */
481static int ir_open(void *data)
482{
483 int retval = 0;
484 struct imon_context *context;
485
486 /* prevent races with disconnect */
487 mutex_lock(&driver_lock);
488
489 context = (struct imon_context *)data;
490
491 /* initial IR protocol decode variables */
492 context->rx.count = 0;
493 context->rx.initial_space = 1;
494 context->rx.prev_bit = 0;
495
496 context->ir_isopen = 1;
497 dev_info(context->driver->dev, "IR port opened\n");
498
499 mutex_unlock(&driver_lock);
500 return retval;
501}
502
503/**
504 * Called by lirc_dev when the application closes /dev/lirc
505 */
506static void ir_close(void *data)
507{
508 struct imon_context *context;
509
510 context = (struct imon_context *)data;
511 if (!context) {
512 err("%s: no context for device", __func__);
513 return;
514 }
515
516 mutex_lock(&context->ctx_lock);
517
518 context->ir_isopen = 0;
519 dev_info(context->driver->dev, "IR port closed\n");
520
521 if (!context->dev_present) {
522 /*
523 * Device disconnected while IR port was still open. Driver
524 * was not deregistered at disconnect time, so do it now.
525 */
526 deregister_from_lirc(context);
527
528 if (!context->display_isopen) {
529 mutex_unlock(&context->ctx_lock);
530 free_imon_context(context);
531 return;
532 }
533 /*
534 * If display port is open, context will be deleted by
535 * display_close
536 */
537 }
538
539 mutex_unlock(&context->ctx_lock);
540 return;
541}
542
543/**
544 * Convert bit count to time duration (in us) and submit
545 * the value to lirc_dev.
546 */
547static void submit_data(struct imon_context *context)
548{
549 unsigned char buf[4];
550 int value = context->rx.count;
551 int i;
552
553 dev_dbg(context->driver->dev, "submitting data to LIRC\n");
554
555 value *= BIT_DURATION;
556 value &= PULSE_MASK;
557 if (context->rx.prev_bit)
558 value |= PULSE_BIT;
559
560 for (i = 0; i < 4; ++i)
561 buf[i] = value>>(i*8);
562
563 lirc_buffer_write(context->driver->rbuf, buf);
564 wake_up(&context->driver->rbuf->wait_poll);
565 return;
566}
567
568static inline int tv2int(const struct timeval *a, const struct timeval *b)
569{
570 int usecs = 0;
571 int sec = 0;
572
573 if (b->tv_usec > a->tv_usec) {
574 usecs = 1000000;
575 sec--;
576 }
577
578 usecs += a->tv_usec - b->tv_usec;
579
580 sec += a->tv_sec - b->tv_sec;
581 sec *= 1000;
582 usecs /= 1000;
583 sec += usecs;
584
585 if (sec < 0)
586 sec = 1000;
587
588 return sec;
589}
590
591/**
592 * Process the incoming packet
593 */
594static void imon_incoming_packet(struct imon_context *context,
595 struct urb *urb, int intf)
596{
597 int len = urb->actual_length;
598 unsigned char *buf = urb->transfer_buffer;
599 struct device *dev = context->driver->dev;
600 int octet, bit;
601 unsigned char mask;
602 int i, chunk_num;
603
604 /*
605 * just bail out if no listening IR client
606 */
607 if (!context->ir_isopen)
608 return;
609
610 if (len != 8) {
611 dev_warn(dev, "imon %s: invalid incoming packet "
612 "size (len = %d, intf%d)\n", __func__, len, intf);
613 return;
614 }
615
616 if (debug) {
617 printk(KERN_INFO "raw packet: ");
618 for (i = 0; i < len; ++i)
619 printk("%02x ", buf[i]);
620 printk("\n");
621 }
622
623 /*
624 * Translate received data to pulse and space lengths.
625 * Received data is active low, i.e. pulses are 0 and
626 * spaces are 1.
627 *
628 * My original algorithm was essentially similar to
629 * Changwoo Ryu's with the exception that he switched
630 * the incoming bits to active high and also fed an
631 * initial space to LIRC at the start of a new sequence
632 * if the previous bit was a pulse.
633 *
634 * I've decided to adopt his algorithm.
635 */
636
637 if (buf[7] == 1 && context->rx.initial_space) {
638 /* LIRC requires a leading space */
639 context->rx.prev_bit = 0;
640 context->rx.count = 4;
641 submit_data(context);
642 context->rx.count = 0;
643 }
644
645 for (octet = 0; octet < 5; ++octet) {
646 mask = 0x80;
647 for (bit = 0; bit < 8; ++bit) {
648 int curr_bit = !(buf[octet] & mask);
649 if (curr_bit != context->rx.prev_bit) {
650 if (context->rx.count) {
651 submit_data(context);
652 context->rx.count = 0;
653 }
654 context->rx.prev_bit = curr_bit;
655 }
656 ++context->rx.count;
657 mask >>= 1;
658 }
659 }
660
661 if (chunk_num == 10) {
662 if (context->rx.count) {
663 submit_data(context);
664 context->rx.count = 0;
665 }
666 context->rx.initial_space = context->rx.prev_bit;
667 }
668}
669
670/**
671 * Callback function for USB core API: receive data
672 */
673static void usb_rx_callback(struct urb *urb)
674{
675 struct imon_context *context;
676 unsigned char *buf;
677 int len;
678 int intfnum = 0;
679
680 if (!urb)
681 return;
682
683 context = (struct imon_context *)urb->context;
684 if (!context)
685 return;
686
687 buf = urb->transfer_buffer;
688 len = urb->actual_length;
689
690 switch (urb->status) {
691 case -ENOENT: /* usbcore unlink successful! */
692 return;
693
694 case 0:
695 imon_incoming_packet(context, urb, intfnum);
696 break;
697
698 default:
699 dev_warn(context->driver->dev, "imon %s: status(%d): ignored\n",
700 __func__, urb->status);
701 break;
702 }
703
704 usb_submit_urb(context->rx_urb, GFP_ATOMIC);
705
706 return;
707}
708
709/**
710 * Callback function for USB core API: Probe
711 */
712static int imon_probe(struct usb_interface *interface,
713 const struct usb_device_id *id)
714{
715 struct usb_device *usbdev = NULL;
716 struct usb_host_interface *iface_desc = NULL;
717 struct usb_endpoint_descriptor *rx_endpoint = NULL;
718 struct usb_endpoint_descriptor *tx_endpoint = NULL;
719 struct urb *rx_urb = NULL;
720 struct urb *tx_urb = NULL;
721 struct lirc_driver *driver = NULL;
722 struct lirc_buffer *rbuf = NULL;
723 struct device *dev = &interface->dev;
724 int ifnum;
725 int lirc_minor = 0;
726 int num_endpts;
727 int retval = 0;
728 int display_ep_found = 0;
729 int ir_ep_found = 0;
730 int alloc_status = 0;
731 int vfd_proto_6p = 0;
732 int code_length;
733 struct imon_context *context = NULL;
734 int i;
735 u16 vendor, product;
736
737 context = kzalloc(sizeof(struct imon_context), GFP_KERNEL);
738 if (!context) {
739 err("%s: kzalloc failed for context", __func__);
740 alloc_status = 1;
741 goto alloc_status_switch;
742 }
743
744 /*
745 * Try to auto-detect the type of display if the user hasn't set
746 * it by hand via the display_type modparam. Default is VFD.
747 */
748 if (usb_match_id(interface, ir_only_list))
749 context->display = 0;
750 else
751 context->display = 1;
752
753 code_length = BUF_CHUNK_SIZE * 8;
754
755 usbdev = usb_get_dev(interface_to_usbdev(interface));
756 iface_desc = interface->cur_altsetting;
757 num_endpts = iface_desc->desc.bNumEndpoints;
758 ifnum = iface_desc->desc.bInterfaceNumber;
759 vendor = le16_to_cpu(usbdev->descriptor.idVendor);
760 product = le16_to_cpu(usbdev->descriptor.idProduct);
761
762 dev_dbg(dev, "%s: found iMON device (%04x:%04x, intf%d)\n",
763 __func__, vendor, product, ifnum);
764
765 /* prevent races probing devices w/multiple interfaces */
766 mutex_lock(&driver_lock);
767
768 /*
769 * Scan the endpoint list and set:
770 * first input endpoint = IR endpoint
771 * first output endpoint = display endpoint
772 */
773 for (i = 0; i < num_endpts && !(ir_ep_found && display_ep_found); ++i) {
774 struct usb_endpoint_descriptor *ep;
775 int ep_dir;
776 int ep_type;
777 ep = &iface_desc->endpoint[i].desc;
778 ep_dir = ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK;
779 ep_type = ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
780
781 if (!ir_ep_found &&
782 ep_dir == USB_DIR_IN &&
783 ep_type == USB_ENDPOINT_XFER_INT) {
784
785 rx_endpoint = ep;
786 ir_ep_found = 1;
787 dev_dbg(dev, "%s: found IR endpoint\n", __func__);
788
789 } else if (!display_ep_found && ep_dir == USB_DIR_OUT &&
790 ep_type == USB_ENDPOINT_XFER_INT) {
791 tx_endpoint = ep;
792 display_ep_found = 1;
793 dev_dbg(dev, "%s: found display endpoint\n", __func__);
794 }
795 }
796
797 /*
798 * Some iMON receivers have no display. Unfortunately, it seems
799 * that SoundGraph recycles device IDs between devices both with
800 * and without... :\
801 */
802 if (context->display == 0) {
803 display_ep_found = 0;
804 dev_dbg(dev, "%s: device has no display\n", __func__);
805 }
806
807 /* Input endpoint is mandatory */
808 if (!ir_ep_found) {
809 err("%s: no valid input (IR) endpoint found.", __func__);
810 retval = -ENODEV;
811 alloc_status = 2;
812 goto alloc_status_switch;
813 }
814
815 /* Determine if display requires 6 packets */
816 if (display_ep_found) {
817 if (usb_match_id(interface, vfd_proto_6p_list))
818 vfd_proto_6p = 1;
819
820 dev_dbg(dev, "%s: vfd_proto_6p: %d\n",
821 __func__, vfd_proto_6p);
822 }
823
824 driver = kzalloc(sizeof(struct lirc_driver), GFP_KERNEL);
825 if (!driver) {
826 err("%s: kzalloc failed for lirc_driver", __func__);
827 alloc_status = 2;
828 goto alloc_status_switch;
829 }
830 rbuf = kmalloc(sizeof(struct lirc_buffer), GFP_KERNEL);
831 if (!rbuf) {
832 err("%s: kmalloc failed for lirc_buffer", __func__);
833 alloc_status = 3;
834 goto alloc_status_switch;
835 }
836 if (lirc_buffer_init(rbuf, BUF_CHUNK_SIZE, BUF_SIZE)) {
837 err("%s: lirc_buffer_init failed", __func__);
838 alloc_status = 4;
839 goto alloc_status_switch;
840 }
841 rx_urb = usb_alloc_urb(0, GFP_KERNEL);
842 if (!rx_urb) {
843 err("%s: usb_alloc_urb failed for IR urb", __func__);
844 alloc_status = 5;
845 goto alloc_status_switch;
846 }
847 tx_urb = usb_alloc_urb(0, GFP_KERNEL);
848 if (!tx_urb) {
849 err("%s: usb_alloc_urb failed for display urb",
850 __func__);
851 alloc_status = 6;
852 goto alloc_status_switch;
853 }
854
855 mutex_init(&context->ctx_lock);
856 context->vfd_proto_6p = vfd_proto_6p;
857
858 strcpy(driver->name, MOD_NAME);
859 driver->minor = -1;
860 driver->code_length = sizeof(int) * 8;
861 driver->sample_rate = 0;
862 driver->features = LIRC_CAN_REC_MODE2;
863 driver->data = context;
864 driver->rbuf = rbuf;
865 driver->set_use_inc = ir_open;
866 driver->set_use_dec = ir_close;
867 driver->dev = &interface->dev;
868 driver->owner = THIS_MODULE;
869
870 mutex_lock(&context->ctx_lock);
871
872 context->driver = driver;
873 /* start out in keyboard mode */
874
875 lirc_minor = lirc_register_driver(driver);
876 if (lirc_minor < 0) {
877 err("%s: lirc_register_driver failed", __func__);
878 alloc_status = 7;
879 goto alloc_status_switch;
880 } else
881 dev_info(dev, "Registered iMON driver "
882 "(lirc minor: %d)\n", lirc_minor);
883
884 /* Needed while unregistering! */
885 driver->minor = lirc_minor;
886
887 context->usbdev = usbdev;
888 context->dev_present = 1;
889 context->rx_endpoint = rx_endpoint;
890 context->rx_urb = rx_urb;
891
892 /*
893 * tx is used to send characters to lcd/vfd, associate RF
894 * remotes, set IR protocol, and maybe more...
895 */
896 context->tx_endpoint = tx_endpoint;
897 context->tx_urb = tx_urb;
898
899 if (display_ep_found)
900 context->display = 1;
901
902 usb_fill_int_urb(context->rx_urb, context->usbdev,
903 usb_rcvintpipe(context->usbdev,
904 context->rx_endpoint->bEndpointAddress),
905 context->usb_rx_buf, sizeof(context->usb_rx_buf),
906 usb_rx_callback, context,
907 context->rx_endpoint->bInterval);
908
909 retval = usb_submit_urb(context->rx_urb, GFP_KERNEL);
910
911 if (retval) {
912 err("%s: usb_submit_urb failed for intf0 (%d)",
913 __func__, retval);
914 mutex_unlock(&context->ctx_lock);
915 goto exit;
916 }
917
918 usb_set_intfdata(interface, context);
919
920 if (context->display && ifnum == 0) {
921 dev_dbg(dev, "%s: Registering iMON display with sysfs\n",
922 __func__);
923
924 if (usb_register_dev(interface, &imon_class)) {
925 /* Not a fatal error, so ignore */
926 dev_info(dev, "%s: could not get a minor number for "
927 "display\n", __func__);
928 }
929 }
930
931 dev_info(dev, "iMON device (%04x:%04x, intf%d) on "
932 "usb<%d:%d> initialized\n", vendor, product, ifnum,
933 usbdev->bus->busnum, usbdev->devnum);
934
935alloc_status_switch:
936 mutex_unlock(&context->ctx_lock);
937
938 switch (alloc_status) {
939 case 7:
940 usb_free_urb(tx_urb);
941 case 6:
942 usb_free_urb(rx_urb);
943 case 5:
944 if (rbuf)
945 lirc_buffer_free(rbuf);
946 case 4:
947 kfree(rbuf);
948 case 3:
949 kfree(driver);
950 case 2:
951 kfree(context);
952 context = NULL;
953 case 1:
954 if (retval != -ENODEV)
955 retval = -ENOMEM;
956 break;
957 case 0:
958 retval = 0;
959 }
960
961exit:
962 mutex_unlock(&driver_lock);
963
964 return retval;
965}
966
967/**
968 * Callback function for USB core API: disconnect
969 */
970static void imon_disconnect(struct usb_interface *interface)
971{
972 struct imon_context *context;
973 int ifnum;
974
975 /* prevent races with ir_open()/display_open() */
976 mutex_lock(&driver_lock);
977
978 context = usb_get_intfdata(interface);
979 ifnum = interface->cur_altsetting->desc.bInterfaceNumber;
980
981 mutex_lock(&context->ctx_lock);
982
983 usb_set_intfdata(interface, NULL);
984
985 /* Abort ongoing write */
986 if (atomic_read(&context->tx.busy)) {
987 usb_kill_urb(context->tx_urb);
988 complete_all(&context->tx.finished);
989 }
990
991 context->dev_present = 0;
992 usb_kill_urb(context->rx_urb);
993 if (context->display)
994 usb_deregister_dev(interface, &imon_class);
995
996 if (!context->ir_isopen && !context->dev_present) {
997 deregister_from_lirc(context);
998 mutex_unlock(&context->ctx_lock);
999 if (!context->display_isopen)
1000 free_imon_context(context);
1001 } else
1002 mutex_unlock(&context->ctx_lock);
1003
1004 mutex_unlock(&driver_lock);
1005
1006 printk(KERN_INFO "%s: iMON device (intf%d) disconnected\n",
1007 __func__, ifnum);
1008}
1009
1010static int imon_suspend(struct usb_interface *intf, pm_message_t message)
1011{
1012 struct imon_context *context = usb_get_intfdata(intf);
1013
1014 usb_kill_urb(context->rx_urb);
1015
1016 return 0;
1017}
1018
1019static int imon_resume(struct usb_interface *intf)
1020{
1021 int rc = 0;
1022 struct imon_context *context = usb_get_intfdata(intf);
1023
1024 usb_fill_int_urb(context->rx_urb, context->usbdev,
1025 usb_rcvintpipe(context->usbdev,
1026 context->rx_endpoint->bEndpointAddress),
1027 context->usb_rx_buf, sizeof(context->usb_rx_buf),
1028 usb_rx_callback, context,
1029 context->rx_endpoint->bInterval);
1030
1031 rc = usb_submit_urb(context->rx_urb, GFP_ATOMIC);
1032
1033 return rc;
1034}
1035
1036static int __init imon_init(void)
1037{
1038 int rc;
1039
1040 printk(KERN_INFO MOD_NAME ": " MOD_DESC ", v" MOD_VERSION "\n");
1041
1042 rc = usb_register(&imon_driver);
1043 if (rc) {
1044 err("%s: usb register failed(%d)", __func__, rc);
1045 return -ENODEV;
1046 }
1047
1048 return 0;
1049}
1050
1051static void __exit imon_exit(void)
1052{
1053 usb_deregister(&imon_driver);
1054 printk(KERN_INFO MOD_NAME ": module removed. Goodbye!\n");
1055}
1056
1057module_init(imon_init);
1058module_exit(imon_exit);
diff --git a/drivers/staging/lirc/lirc_it87.c b/drivers/staging/lirc/lirc_it87.c
new file mode 100644
index 000000000000..09f36961c6d2
--- /dev/null
+++ b/drivers/staging/lirc/lirc_it87.c
@@ -0,0 +1,1019 @@
1/*
2 * LIRC driver for ITE IT8712/IT8705 CIR port
3 *
4 * Copyright (C) 2001 Hans-Gunter Lutke Uphues <hg_lu@web.de>
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; either version 2 of the
9 * License, or (at your option) any later version.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 * USA
20 *
21 * ITE IT8705 and IT8712(not tested) and IT8720 CIR-port support for lirc based
22 * via cut and paste from lirc_sir.c (C) 2000 Milan Pikula
23 *
24 * Attention: Sendmode only tested with debugging logs
25 *
26 * 2001/02/27 Christoph Bartelmus <lirc@bartelmus.de> :
27 * reimplemented read function
28 * 2005/06/05 Andrew Calkin implemented support for Asus Digimatrix,
29 * based on work of the following member of the Outertrack Digimatrix
30 * Forum: Art103 <r_tay@hotmail.com>
31 * 2009/12/24 James Edwards <jimbo-lirc@edwardsclan.net> implemeted support
32 * for ITE8704/ITE8718, on my machine, the DSDT reports 8704, but the
33 * chip identifies as 18.
34 */
35
36#include <linux/module.h>
37#include <linux/sched.h>
38#include <linux/errno.h>
39#include <linux/signal.h>
40#include <linux/fs.h>
41#include <linux/interrupt.h>
42#include <linux/ioport.h>
43#include <linux/kernel.h>
44#include <linux/time.h>
45#include <linux/string.h>
46#include <linux/types.h>
47#include <linux/wait.h>
48#include <linux/mm.h>
49#include <linux/delay.h>
50#include <linux/poll.h>
51#include <asm/system.h>
52#include <linux/io.h>
53#include <linux/irq.h>
54#include <linux/fcntl.h>
55
56#include <linux/timer.h>
57#include <linux/pnp.h>
58
59#include <media/lirc.h>
60#include <media/lirc_dev.h>
61
62#include "lirc_it87.h"
63
64#ifdef LIRC_IT87_DIGIMATRIX
65static int digimatrix = 1;
66static int it87_freq = 36; /* kHz */
67static int irq = 9;
68#else
69static int digimatrix;
70static int it87_freq = 38; /* kHz */
71static int irq = IT87_CIR_DEFAULT_IRQ;
72#endif
73
74static unsigned long it87_bits_in_byte_out;
75static unsigned long it87_send_counter;
76static unsigned char it87_RXEN_mask = IT87_CIR_RCR_RXEN;
77
78#define RBUF_LEN 1024
79
80#define LIRC_DRIVER_NAME "lirc_it87"
81
82/* timeout for sequences in jiffies (=5/100s) */
83/* must be longer than TIME_CONST */
84#define IT87_TIMEOUT (HZ*5/100)
85
86/* module parameters */
87static int debug;
88#define dprintk(fmt, args...) \
89 do { \
90 if (debug) \
91 printk(KERN_DEBUG LIRC_DRIVER_NAME ": " \
92 fmt, ## args); \
93 } while (0)
94
95static int io = IT87_CIR_DEFAULT_IOBASE;
96/* receiver demodulator default: off */
97static int it87_enable_demodulator;
98
99static int timer_enabled;
100static DEFINE_SPINLOCK(timer_lock);
101static struct timer_list timerlist;
102/* time of last signal change detected */
103static struct timeval last_tv = {0, 0};
104/* time of last UART data ready interrupt */
105static struct timeval last_intr_tv = {0, 0};
106static int last_value;
107
108static DECLARE_WAIT_QUEUE_HEAD(lirc_read_queue);
109
110static DEFINE_SPINLOCK(hardware_lock);
111static DEFINE_SPINLOCK(dev_lock);
112
113static int rx_buf[RBUF_LEN];
114unsigned int rx_tail, rx_head;
115
116static struct pnp_driver it87_pnp_driver;
117
118/* SECTION: Prototypes */
119
120/* Communication with user-space */
121static int lirc_open(struct inode *inode, struct file *file);
122static int lirc_close(struct inode *inode, struct file *file);
123static unsigned int lirc_poll(struct file *file, poll_table *wait);
124static ssize_t lirc_read(struct file *file, char *buf,
125 size_t count, loff_t *ppos);
126static ssize_t lirc_write(struct file *file, const char *buf,
127 size_t n, loff_t *pos);
128static long lirc_ioctl(struct file *filep, unsigned int cmd, unsigned long arg);
129static void add_read_queue(int flag, unsigned long val);
130static int init_chrdev(void);
131static void drop_chrdev(void);
132/* Hardware */
133static irqreturn_t it87_interrupt(int irq, void *dev_id);
134static void send_space(unsigned long len);
135static void send_pulse(unsigned long len);
136static void init_send(void);
137static void terminate_send(unsigned long len);
138static int init_hardware(void);
139static void drop_hardware(void);
140/* Initialisation */
141static int init_port(void);
142static void drop_port(void);
143
144
145/* SECTION: Communication with user-space */
146
147static int lirc_open(struct inode *inode, struct file *file)
148{
149 spin_lock(&dev_lock);
150 if (module_refcount(THIS_MODULE)) {
151 spin_unlock(&dev_lock);
152 return -EBUSY;
153 }
154 spin_unlock(&dev_lock);
155 return 0;
156}
157
158
159static int lirc_close(struct inode *inode, struct file *file)
160{
161 return 0;
162}
163
164
165static unsigned int lirc_poll(struct file *file, poll_table *wait)
166{
167 poll_wait(file, &lirc_read_queue, wait);
168 if (rx_head != rx_tail)
169 return POLLIN | POLLRDNORM;
170 return 0;
171}
172
173
174static ssize_t lirc_read(struct file *file, char *buf,
175 size_t count, loff_t *ppos)
176{
177 int n = 0;
178 int retval = 0;
179
180 while (n < count) {
181 if (file->f_flags & O_NONBLOCK && rx_head == rx_tail) {
182 retval = -EAGAIN;
183 break;
184 }
185 retval = wait_event_interruptible(lirc_read_queue,
186 rx_head != rx_tail);
187 if (retval)
188 break;
189
190 if (copy_to_user((void *) buf + n, (void *) (rx_buf + rx_head),
191 sizeof(int))) {
192 retval = -EFAULT;
193 break;
194 }
195 rx_head = (rx_head + 1) & (RBUF_LEN - 1);
196 n += sizeof(int);
197 }
198 if (n)
199 return n;
200 return retval;
201}
202
203
204static ssize_t lirc_write(struct file *file, const char *buf,
205 size_t n, loff_t *pos)
206{
207 int i = 0;
208 int *tx_buf;
209
210 if (n % sizeof(int))
211 return -EINVAL;
212 tx_buf = memdup_user(buf, n);
213 if (IS_ERR(tx_buf))
214 return PTR_ERR(tx_buf);
215 n /= sizeof(int);
216 init_send();
217 while (1) {
218 if (i >= n)
219 break;
220 if (tx_buf[i])
221 send_pulse(tx_buf[i]);
222 i++;
223 if (i >= n)
224 break;
225 if (tx_buf[i])
226 send_space(tx_buf[i]);
227 i++;
228 }
229 terminate_send(tx_buf[i - 1]);
230 return n;
231}
232
233
234static long lirc_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
235{
236 int retval = 0;
237 unsigned long value = 0;
238 unsigned int ivalue;
239 unsigned long hw_flags;
240
241 if (cmd == LIRC_GET_FEATURES)
242 value = LIRC_CAN_SEND_PULSE |
243 LIRC_CAN_SET_SEND_CARRIER |
244 LIRC_CAN_REC_MODE2;
245 else if (cmd == LIRC_GET_SEND_MODE)
246 value = LIRC_MODE_PULSE;
247 else if (cmd == LIRC_GET_REC_MODE)
248 value = LIRC_MODE_MODE2;
249
250 switch (cmd) {
251 case LIRC_GET_FEATURES:
252 case LIRC_GET_SEND_MODE:
253 case LIRC_GET_REC_MODE:
254 retval = put_user(value, (unsigned long *) arg);
255 break;
256
257 case LIRC_SET_SEND_MODE:
258 case LIRC_SET_REC_MODE:
259 retval = get_user(value, (unsigned long *) arg);
260 break;
261
262 case LIRC_SET_SEND_CARRIER:
263 retval = get_user(ivalue, (unsigned int *) arg);
264 if (retval)
265 return retval;
266 ivalue /= 1000;
267 if (ivalue > IT87_CIR_FREQ_MAX ||
268 ivalue < IT87_CIR_FREQ_MIN)
269 return -EINVAL;
270
271 it87_freq = ivalue;
272
273 spin_lock_irqsave(&hardware_lock, hw_flags);
274 outb(((inb(io + IT87_CIR_TCR2) & IT87_CIR_TCR2_TXMPW) |
275 (it87_freq - IT87_CIR_FREQ_MIN) << 3),
276 io + IT87_CIR_TCR2);
277 spin_unlock_irqrestore(&hardware_lock, hw_flags);
278 dprintk("demodulation frequency: %d kHz\n", it87_freq);
279
280 break;
281
282 default:
283 retval = -EINVAL;
284 }
285
286 if (retval)
287 return retval;
288
289 if (cmd == LIRC_SET_REC_MODE) {
290 if (value != LIRC_MODE_MODE2)
291 retval = -ENOSYS;
292 } else if (cmd == LIRC_SET_SEND_MODE) {
293 if (value != LIRC_MODE_PULSE)
294 retval = -ENOSYS;
295 }
296 return retval;
297}
298
299static void add_read_queue(int flag, unsigned long val)
300{
301 unsigned int new_rx_tail;
302 int newval;
303
304 dprintk("add flag %d with val %lu\n", flag, val);
305
306 newval = val & PULSE_MASK;
307
308 /*
309 * statistically, pulses are ~TIME_CONST/2 too long. we could
310 * maybe make this more exact, but this is good enough
311 */
312 if (flag) {
313 /* pulse */
314 if (newval > TIME_CONST / 2)
315 newval -= TIME_CONST / 2;
316 else /* should not ever happen */
317 newval = 1;
318 newval |= PULSE_BIT;
319 } else
320 newval += TIME_CONST / 2;
321 new_rx_tail = (rx_tail + 1) & (RBUF_LEN - 1);
322 if (new_rx_tail == rx_head) {
323 dprintk("Buffer overrun.\n");
324 return;
325 }
326 rx_buf[rx_tail] = newval;
327 rx_tail = new_rx_tail;
328 wake_up_interruptible(&lirc_read_queue);
329}
330
331
332static const struct file_operations lirc_fops = {
333 .owner = THIS_MODULE,
334 .read = lirc_read,
335 .write = lirc_write,
336 .poll = lirc_poll,
337 .unlocked_ioctl = lirc_ioctl,
338 .open = lirc_open,
339 .release = lirc_close,
340};
341
342static int set_use_inc(void *data)
343{
344 return 0;
345}
346
347static void set_use_dec(void *data)
348{
349}
350
351static struct lirc_driver driver = {
352 .name = LIRC_DRIVER_NAME,
353 .minor = -1,
354 .code_length = 1,
355 .sample_rate = 0,
356 .data = NULL,
357 .add_to_buf = NULL,
358 .set_use_inc = set_use_inc,
359 .set_use_dec = set_use_dec,
360 .fops = &lirc_fops,
361 .dev = NULL,
362 .owner = THIS_MODULE,
363};
364
365
366#ifdef MODULE
367static int init_chrdev(void)
368{
369 driver.minor = lirc_register_driver(&driver);
370
371 if (driver.minor < 0) {
372 printk(KERN_ERR LIRC_DRIVER_NAME ": init_chrdev() failed.\n");
373 return -EIO;
374 }
375 return 0;
376}
377
378
379static void drop_chrdev(void)
380{
381 lirc_unregister_driver(driver.minor);
382}
383#endif
384
385
386/* SECTION: Hardware */
387static long delta(struct timeval *tv1, struct timeval *tv2)
388{
389 unsigned long deltv;
390
391 deltv = tv2->tv_sec - tv1->tv_sec;
392 if (deltv > 15)
393 deltv = 0xFFFFFF;
394 else
395 deltv = deltv*1000000 + tv2->tv_usec - tv1->tv_usec;
396 return deltv;
397}
398
399static void it87_timeout(unsigned long data)
400{
401 unsigned long flags;
402
403 /* avoid interference with interrupt */
404 spin_lock_irqsave(&timer_lock, flags);
405
406 if (digimatrix) {
407 /* We have timed out. Disable the RX mechanism. */
408
409 outb((inb(io + IT87_CIR_RCR) & ~IT87_CIR_RCR_RXEN) |
410 IT87_CIR_RCR_RXACT, io + IT87_CIR_RCR);
411 if (it87_RXEN_mask)
412 outb(inb(io + IT87_CIR_RCR) | IT87_CIR_RCR_RXEN,
413 io + IT87_CIR_RCR);
414 dprintk(" TIMEOUT\n");
415 timer_enabled = 0;
416
417 /* fifo clear */
418 outb(inb(io + IT87_CIR_TCR1) | IT87_CIR_TCR1_FIFOCLR,
419 io+IT87_CIR_TCR1);
420
421 } else {
422 /*
423 * if last received signal was a pulse, but receiving stopped
424 * within the 9 bit frame, we need to finish this pulse and
425 * simulate a signal change to from pulse to space. Otherwise
426 * upper layers will receive two sequences next time.
427 */
428
429 if (last_value) {
430 unsigned long pulse_end;
431
432 /* determine 'virtual' pulse end: */
433 pulse_end = delta(&last_tv, &last_intr_tv);
434 dprintk("timeout add %d for %lu usec\n",
435 last_value, pulse_end);
436 add_read_queue(last_value, pulse_end);
437 last_value = 0;
438 last_tv = last_intr_tv;
439 }
440 }
441 spin_unlock_irqrestore(&timer_lock, flags);
442}
443
444static irqreturn_t it87_interrupt(int irq, void *dev_id)
445{
446 unsigned char data;
447 struct timeval curr_tv;
448 static unsigned long deltv;
449 unsigned long deltintrtv;
450 unsigned long flags, hw_flags;
451 int iir, lsr;
452 int fifo = 0;
453 static char lastbit;
454 char bit;
455
456 /* Bit duration in microseconds */
457 const unsigned long bit_duration = 1000000ul /
458 (115200 / IT87_CIR_BAUDRATE_DIVISOR);
459
460
461 iir = inb(io + IT87_CIR_IIR);
462
463 switch (iir & IT87_CIR_IIR_IID) {
464 case 0x4:
465 case 0x6:
466 lsr = inb(io + IT87_CIR_RSR) & (IT87_CIR_RSR_RXFTO |
467 IT87_CIR_RSR_RXFBC);
468 fifo = lsr & IT87_CIR_RSR_RXFBC;
469 dprintk("iir: 0x%x fifo: 0x%x\n", iir, lsr);
470
471 /* avoid interference with timer */
472 spin_lock_irqsave(&timer_lock, flags);
473 spin_lock_irqsave(&hardware_lock, hw_flags);
474 if (digimatrix) {
475 static unsigned long acc_pulse;
476 static unsigned long acc_space;
477
478 do {
479 data = inb(io + IT87_CIR_DR);
480 data = ~data;
481 fifo--;
482 if (data != 0x00) {
483 if (timer_enabled)
484 del_timer(&timerlist);
485 /*
486 * start timer for end of
487 * sequence detection
488 */
489 timerlist.expires = jiffies +
490 IT87_TIMEOUT;
491 add_timer(&timerlist);
492 timer_enabled = 1;
493 }
494 /* Loop through */
495 for (bit = 0; bit < 8; ++bit) {
496 if ((data >> bit) & 1) {
497 ++acc_pulse;
498 if (lastbit == 0) {
499 add_read_queue(0,
500 acc_space *
501 bit_duration);
502 acc_space = 0;
503 }
504 } else {
505 ++acc_space;
506 if (lastbit == 1) {
507 add_read_queue(1,
508 acc_pulse *
509 bit_duration);
510 acc_pulse = 0;
511 }
512 }
513 lastbit = (data >> bit) & 1;
514 }
515
516 } while (fifo != 0);
517 } else { /* Normal Operation */
518 do {
519 del_timer(&timerlist);
520 data = inb(io + IT87_CIR_DR);
521
522 dprintk("data=%02x\n", data);
523 do_gettimeofday(&curr_tv);
524 deltv = delta(&last_tv, &curr_tv);
525 deltintrtv = delta(&last_intr_tv, &curr_tv);
526
527 dprintk("t %lu , d %d\n",
528 deltintrtv, (int)data);
529
530 /*
531 * if nothing came in last 2 cycles,
532 * it was gap
533 */
534 if (deltintrtv > TIME_CONST * 2) {
535 if (last_value) {
536 dprintk("GAP\n");
537
538 /* simulate signal change */
539 add_read_queue(last_value,
540 deltv -
541 deltintrtv);
542 last_value = 0;
543 last_tv.tv_sec =
544 last_intr_tv.tv_sec;
545 last_tv.tv_usec =
546 last_intr_tv.tv_usec;
547 deltv = deltintrtv;
548 }
549 }
550 data = 1;
551 if (data ^ last_value) {
552 /*
553 * deltintrtv > 2*TIME_CONST,
554 * remember ? the other case is
555 * timeout
556 */
557 add_read_queue(last_value,
558 deltv-TIME_CONST);
559 last_value = data;
560 last_tv = curr_tv;
561 if (last_tv.tv_usec >= TIME_CONST)
562 last_tv.tv_usec -= TIME_CONST;
563 else {
564 last_tv.tv_sec--;
565 last_tv.tv_usec += 1000000 -
566 TIME_CONST;
567 }
568 }
569 last_intr_tv = curr_tv;
570 if (data) {
571 /*
572 * start timer for end of
573 * sequence detection
574 */
575 timerlist.expires =
576 jiffies + IT87_TIMEOUT;
577 add_timer(&timerlist);
578 }
579 outb((inb(io + IT87_CIR_RCR) &
580 ~IT87_CIR_RCR_RXEN) |
581 IT87_CIR_RCR_RXACT,
582 io + IT87_CIR_RCR);
583 if (it87_RXEN_mask)
584 outb(inb(io + IT87_CIR_RCR) |
585 IT87_CIR_RCR_RXEN,
586 io + IT87_CIR_RCR);
587 fifo--;
588 } while (fifo != 0);
589 }
590 spin_unlock_irqrestore(&hardware_lock, hw_flags);
591 spin_unlock_irqrestore(&timer_lock, flags);
592
593 return IRQ_RETVAL(IRQ_HANDLED);
594
595 default:
596 /* not our irq */
597 dprintk("unknown IRQ (shouldn't happen) !!\n");
598 return IRQ_RETVAL(IRQ_NONE);
599 }
600}
601
602
603static void send_it87(unsigned long len, unsigned long stime,
604 unsigned char send_byte, unsigned int count_bits)
605{
606 long count = len / stime;
607 long time_left = 0;
608 static unsigned char byte_out;
609 unsigned long hw_flags;
610
611 dprintk("%s: len=%ld, sb=%d\n", __func__, len, send_byte);
612
613 time_left = (long)len - (long)count * (long)stime;
614 count += ((2 * time_left) / stime);
615 while (count) {
616 long i = 0;
617 for (i = 0; i < count_bits; i++) {
618 byte_out = (byte_out << 1) | (send_byte & 1);
619 it87_bits_in_byte_out++;
620 }
621 if (it87_bits_in_byte_out == 8) {
622 dprintk("out=0x%x, tsr_txfbc: 0x%x\n",
623 byte_out,
624 inb(io + IT87_CIR_TSR) &
625 IT87_CIR_TSR_TXFBC);
626
627 while ((inb(io + IT87_CIR_TSR) &
628 IT87_CIR_TSR_TXFBC) >= IT87_CIR_FIFO_SIZE)
629 ;
630
631 spin_lock_irqsave(&hardware_lock, hw_flags);
632 outb(byte_out, io + IT87_CIR_DR);
633 spin_unlock_irqrestore(&hardware_lock, hw_flags);
634
635 it87_bits_in_byte_out = 0;
636 it87_send_counter++;
637 byte_out = 0;
638 }
639 count--;
640 }
641}
642
643
644/*TODO: maybe exchange space and pulse because it8705 only modulates 0-bits */
645
646static void send_space(unsigned long len)
647{
648 send_it87(len, TIME_CONST, IT87_CIR_SPACE, IT87_CIR_BAUDRATE_DIVISOR);
649}
650
651static void send_pulse(unsigned long len)
652{
653 send_it87(len, TIME_CONST, IT87_CIR_PULSE, IT87_CIR_BAUDRATE_DIVISOR);
654}
655
656
657static void init_send()
658{
659 unsigned long flags;
660
661 spin_lock_irqsave(&hardware_lock, flags);
662 /* RXEN=0: receiver disable */
663 it87_RXEN_mask = 0;
664 outb(inb(io + IT87_CIR_RCR) & ~IT87_CIR_RCR_RXEN,
665 io + IT87_CIR_RCR);
666 spin_unlock_irqrestore(&hardware_lock, flags);
667 it87_bits_in_byte_out = 0;
668 it87_send_counter = 0;
669}
670
671
672static void terminate_send(unsigned long len)
673{
674 unsigned long flags;
675 unsigned long last = 0;
676
677 last = it87_send_counter;
678 /* make sure all necessary data has been sent */
679 while (last == it87_send_counter)
680 send_space(len);
681 /* wait until all data sent */
682 while ((inb(io + IT87_CIR_TSR) & IT87_CIR_TSR_TXFBC) != 0)
683 ;
684 /* then re-enable receiver */
685 spin_lock_irqsave(&hardware_lock, flags);
686 it87_RXEN_mask = IT87_CIR_RCR_RXEN;
687 outb(inb(io + IT87_CIR_RCR) | IT87_CIR_RCR_RXEN,
688 io + IT87_CIR_RCR);
689 spin_unlock_irqrestore(&hardware_lock, flags);
690}
691
692
693static int init_hardware(void)
694{
695 unsigned long flags;
696 unsigned char it87_rcr = 0;
697
698 spin_lock_irqsave(&hardware_lock, flags);
699 /* init cir-port */
700 /* enable r/w-access to Baudrate-Register */
701 outb(IT87_CIR_IER_BR, io + IT87_CIR_IER);
702 outb(IT87_CIR_BAUDRATE_DIVISOR % 0x100, io+IT87_CIR_BDLR);
703 outb(IT87_CIR_BAUDRATE_DIVISOR / 0x100, io+IT87_CIR_BDHR);
704 /* Baudrate Register off, define IRQs: Input only */
705 if (digimatrix) {
706 outb(IT87_CIR_IER_IEC | IT87_CIR_IER_RFOIE, io + IT87_CIR_IER);
707 /* RX: HCFS=0, RXDCR = 001b (33,75..38,25 kHz), RXEN=1 */
708 } else {
709 outb(IT87_CIR_IER_IEC | IT87_CIR_IER_RDAIE, io + IT87_CIR_IER);
710 /* RX: HCFS=0, RXDCR = 001b (35,6..40,3 kHz), RXEN=1 */
711 }
712 it87_rcr = (IT87_CIR_RCR_RXEN & it87_RXEN_mask) | 0x1;
713 if (it87_enable_demodulator)
714 it87_rcr |= IT87_CIR_RCR_RXEND;
715 outb(it87_rcr, io + IT87_CIR_RCR);
716 if (digimatrix) {
717 /* Set FIFO depth to 1 byte, and disable TX */
718 outb(inb(io + IT87_CIR_TCR1) | 0x00,
719 io + IT87_CIR_TCR1);
720
721 /*
722 * TX: it87_freq (36kHz), 'reserved' sensitivity
723 * setting (0x00)
724 */
725 outb(((it87_freq - IT87_CIR_FREQ_MIN) << 3) | 0x00,
726 io + IT87_CIR_TCR2);
727 } else {
728 /* TX: 38kHz, 13,3us (pulse-width) */
729 outb(((it87_freq - IT87_CIR_FREQ_MIN) << 3) | 0x06,
730 io + IT87_CIR_TCR2);
731 }
732 spin_unlock_irqrestore(&hardware_lock, flags);
733 return 0;
734}
735
736
737static void drop_hardware(void)
738{
739 unsigned long flags;
740
741 spin_lock_irqsave(&hardware_lock, flags);
742 disable_irq(irq);
743 /* receiver disable */
744 it87_RXEN_mask = 0;
745 outb(0x1, io + IT87_CIR_RCR);
746 /* turn off irqs */
747 outb(0, io + IT87_CIR_IER);
748 /* fifo clear */
749 outb(IT87_CIR_TCR1_FIFOCLR, io+IT87_CIR_TCR1);
750 /* reset */
751 outb(IT87_CIR_IER_RESET, io+IT87_CIR_IER);
752 enable_irq(irq);
753 spin_unlock_irqrestore(&hardware_lock, flags);
754}
755
756
757static unsigned char it87_read(unsigned char port)
758{
759 outb(port, IT87_ADRPORT);
760 return inb(IT87_DATAPORT);
761}
762
763
764static void it87_write(unsigned char port, unsigned char data)
765{
766 outb(port, IT87_ADRPORT);
767 outb(data, IT87_DATAPORT);
768}
769
770
771/* SECTION: Initialisation */
772
773static int init_port(void)
774{
775 unsigned long hw_flags;
776 int retval = 0;
777
778 unsigned char init_bytes[4] = IT87_INIT;
779 unsigned char it87_chipid = 0;
780 unsigned char ldn = 0;
781 unsigned int it87_io = 0;
782 unsigned int it87_irq = 0;
783
784 /* Enter MB PnP Mode */
785 outb(init_bytes[0], IT87_ADRPORT);
786 outb(init_bytes[1], IT87_ADRPORT);
787 outb(init_bytes[2], IT87_ADRPORT);
788 outb(init_bytes[3], IT87_ADRPORT);
789
790 /* 8712 or 8705 ? */
791 it87_chipid = it87_read(IT87_CHIP_ID1);
792 if (it87_chipid != 0x87) {
793 retval = -ENXIO;
794 return retval;
795 }
796 it87_chipid = it87_read(IT87_CHIP_ID2);
797 if ((it87_chipid != 0x05) &&
798 (it87_chipid != 0x12) &&
799 (it87_chipid != 0x18) &&
800 (it87_chipid != 0x20)) {
801 printk(KERN_INFO LIRC_DRIVER_NAME
802 ": no IT8704/05/12/18/20 found (claimed IT87%02x), "
803 "exiting..\n", it87_chipid);
804 retval = -ENXIO;
805 return retval;
806 }
807 printk(KERN_INFO LIRC_DRIVER_NAME
808 ": found IT87%02x.\n",
809 it87_chipid);
810
811 /* get I/O-Port and IRQ */
812 if (it87_chipid == 0x12 || it87_chipid == 0x18)
813 ldn = IT8712_CIR_LDN;
814 else
815 ldn = IT8705_CIR_LDN;
816 it87_write(IT87_LDN, ldn);
817
818 it87_io = it87_read(IT87_CIR_BASE_MSB) * 256 +
819 it87_read(IT87_CIR_BASE_LSB);
820 if (it87_io == 0) {
821 if (io == 0)
822 io = IT87_CIR_DEFAULT_IOBASE;
823 printk(KERN_INFO LIRC_DRIVER_NAME
824 ": set default io 0x%x\n",
825 io);
826 it87_write(IT87_CIR_BASE_MSB, io / 0x100);
827 it87_write(IT87_CIR_BASE_LSB, io % 0x100);
828 } else
829 io = it87_io;
830
831 it87_irq = it87_read(IT87_CIR_IRQ);
832 if (digimatrix || it87_irq == 0) {
833 if (irq == 0)
834 irq = IT87_CIR_DEFAULT_IRQ;
835 printk(KERN_INFO LIRC_DRIVER_NAME
836 ": set default irq 0x%x\n",
837 irq);
838 it87_write(IT87_CIR_IRQ, irq);
839 } else
840 irq = it87_irq;
841
842 spin_lock_irqsave(&hardware_lock, hw_flags);
843 /* reset */
844 outb(IT87_CIR_IER_RESET, io+IT87_CIR_IER);
845 /* fifo clear */
846 outb(IT87_CIR_TCR1_FIFOCLR |
847 /* IT87_CIR_TCR1_ILE | */
848 IT87_CIR_TCR1_TXRLE |
849 IT87_CIR_TCR1_TXENDF, io+IT87_CIR_TCR1);
850 spin_unlock_irqrestore(&hardware_lock, hw_flags);
851
852 /* get I/O port access and IRQ line */
853 if (request_region(io, 8, LIRC_DRIVER_NAME) == NULL) {
854 printk(KERN_ERR LIRC_DRIVER_NAME
855 ": i/o port 0x%.4x already in use.\n", io);
856 /* Leaving MB PnP Mode */
857 it87_write(IT87_CFGCTRL, 0x2);
858 return -EBUSY;
859 }
860
861 /* activate CIR-Device */
862 it87_write(IT87_CIR_ACT, 0x1);
863
864 /* Leaving MB PnP Mode */
865 it87_write(IT87_CFGCTRL, 0x2);
866
867 retval = request_irq(irq, it87_interrupt, 0 /*IRQF_DISABLED*/,
868 LIRC_DRIVER_NAME, NULL);
869 if (retval < 0) {
870 printk(KERN_ERR LIRC_DRIVER_NAME
871 ": IRQ %d already in use.\n",
872 irq);
873 release_region(io, 8);
874 return retval;
875 }
876
877 printk(KERN_INFO LIRC_DRIVER_NAME
878 ": I/O port 0x%.4x, IRQ %d.\n", io, irq);
879
880 init_timer(&timerlist);
881 timerlist.function = it87_timeout;
882 timerlist.data = 0xabadcafe;
883
884 return 0;
885}
886
887
888static void drop_port(void)
889{
890#if 0
891 unsigned char init_bytes[4] = IT87_INIT;
892
893 /* Enter MB PnP Mode */
894 outb(init_bytes[0], IT87_ADRPORT);
895 outb(init_bytes[1], IT87_ADRPORT);
896 outb(init_bytes[2], IT87_ADRPORT);
897 outb(init_bytes[3], IT87_ADRPORT);
898
899 /* deactivate CIR-Device */
900 it87_write(IT87_CIR_ACT, 0x0);
901
902 /* Leaving MB PnP Mode */
903 it87_write(IT87_CFGCTRL, 0x2);
904#endif
905
906 del_timer_sync(&timerlist);
907 free_irq(irq, NULL);
908 release_region(io, 8);
909}
910
911
912static int init_lirc_it87(void)
913{
914 int retval;
915
916 init_waitqueue_head(&lirc_read_queue);
917 retval = init_port();
918 if (retval < 0)
919 return retval;
920 init_hardware();
921 printk(KERN_INFO LIRC_DRIVER_NAME ": Installed.\n");
922 return 0;
923}
924
925static int it87_probe(struct pnp_dev *pnp_dev,
926 const struct pnp_device_id *dev_id)
927{
928 int retval;
929
930 driver.dev = &pnp_dev->dev;
931
932 retval = init_chrdev();
933 if (retval < 0)
934 return retval;
935
936 retval = init_lirc_it87();
937 if (retval)
938 goto init_lirc_it87_failed;
939
940 return 0;
941
942init_lirc_it87_failed:
943 drop_chrdev();
944
945 return retval;
946}
947
948static int __init lirc_it87_init(void)
949{
950 return pnp_register_driver(&it87_pnp_driver);
951}
952
953
954static void __exit lirc_it87_exit(void)
955{
956 drop_hardware();
957 drop_chrdev();
958 drop_port();
959 pnp_unregister_driver(&it87_pnp_driver);
960 printk(KERN_INFO LIRC_DRIVER_NAME ": Uninstalled.\n");
961}
962
963/* SECTION: PNP for ITE8704/18 */
964
965static const struct pnp_device_id pnp_dev_table[] = {
966 {"ITE8704", 0},
967 {}
968};
969
970MODULE_DEVICE_TABLE(pnp, pnp_dev_table);
971
972static struct pnp_driver it87_pnp_driver = {
973 .name = LIRC_DRIVER_NAME,
974 .id_table = pnp_dev_table,
975 .probe = it87_probe,
976};
977
978module_init(lirc_it87_init);
979module_exit(lirc_it87_exit);
980
981MODULE_DESCRIPTION("LIRC driver for ITE IT8704/05/12/18/20 CIR port");
982MODULE_AUTHOR("Hans-Gunter Lutke Uphues");
983MODULE_LICENSE("GPL");
984
985module_param(io, int, S_IRUGO);
986MODULE_PARM_DESC(io, "I/O base address (default: 0x310)");
987
988module_param(irq, int, S_IRUGO);
989#ifdef LIRC_IT87_DIGIMATRIX
990MODULE_PARM_DESC(irq, "Interrupt (1,3-12) (default: 9)");
991#else
992MODULE_PARM_DESC(irq, "Interrupt (1,3-12) (default: 7)");
993#endif
994
995module_param(it87_enable_demodulator, bool, S_IRUGO);
996MODULE_PARM_DESC(it87_enable_demodulator,
997 "Receiver demodulator enable/disable (1/0), default: 0");
998
999module_param(debug, bool, S_IRUGO | S_IWUSR);
1000MODULE_PARM_DESC(debug, "Enable debugging messages");
1001
1002module_param(digimatrix, bool, S_IRUGO | S_IWUSR);
1003#ifdef LIRC_IT87_DIGIMATRIX
1004MODULE_PARM_DESC(digimatrix,
1005 "Asus Digimatrix it87 compat. enable/disable (1/0), default: 1");
1006#else
1007MODULE_PARM_DESC(digimatrix,
1008 "Asus Digimatrix it87 compat. enable/disable (1/0), default: 0");
1009#endif
1010
1011
1012module_param(it87_freq, int, S_IRUGO);
1013#ifdef LIRC_IT87_DIGIMATRIX
1014MODULE_PARM_DESC(it87_freq,
1015 "Carrier demodulator frequency (kHz), (default: 36)");
1016#else
1017MODULE_PARM_DESC(it87_freq,
1018 "Carrier demodulator frequency (kHz), (default: 38)");
1019#endif
diff --git a/drivers/staging/lirc/lirc_it87.h b/drivers/staging/lirc/lirc_it87.h
new file mode 100644
index 000000000000..cf021c893a35
--- /dev/null
+++ b/drivers/staging/lirc/lirc_it87.h
@@ -0,0 +1,116 @@
1/* lirc_it87.h */
2/* SECTION: Definitions */
3
4/********************************* ITE IT87xx ************************/
5
6/* based on the following documentation from ITE:
7 a) IT8712F Preliminary CIR Programming Guide V0.1
8 b) IT8705F Simple LPC I/O Preliminary Specification V0.3
9 c) IT8712F EC-LPC I/O Preliminary Specification V0.5
10*/
11
12/* IT8712/05 Ports: */
13#define IT87_ADRPORT 0x2e
14#define IT87_DATAPORT 0x2f
15#define IT87_INIT {0x87, 0x01, 0x55, 0x55}
16
17/* alternate Ports: */
18/*
19#define IT87_ADRPORT 0x4e
20#define IT87_DATAPORT 0x4f
21#define IT87_INIT {0x87, 0x01, 0x55, 0xaa}
22 */
23
24/* IT8712/05 Registers */
25#define IT87_CFGCTRL 0x2
26#define IT87_LDN 0x7
27#define IT87_CHIP_ID1 0x20
28#define IT87_CHIP_ID2 0x21
29#define IT87_CFG_VERSION 0x22
30#define IT87_SWSUSPEND 0x23
31
32#define IT8712_CIR_LDN 0xa
33#define IT8705_CIR_LDN 0x7
34
35/* CIR Configuration Registers: */
36#define IT87_CIR_ACT 0x30
37#define IT87_CIR_BASE_MSB 0x60
38#define IT87_CIR_BASE_LSB 0x61
39#define IT87_CIR_IRQ 0x70
40#define IT87_CIR_CONFIG 0xf0
41
42/* List of IT87_CIR registers: offset to BaseAddr */
43#define IT87_CIR_DR 0
44#define IT87_CIR_IER 1
45#define IT87_CIR_RCR 2
46#define IT87_CIR_TCR1 3
47#define IT87_CIR_TCR2 4
48#define IT87_CIR_TSR 5
49#define IT87_CIR_RSR 6
50#define IT87_CIR_BDLR 5
51#define IT87_CIR_BDHR 6
52#define IT87_CIR_IIR 7
53
54/* Bit Definition */
55/* IER: */
56#define IT87_CIR_IER_TM_EN 0x80
57#define IT87_CIR_IER_RESEVED 0x40
58#define IT87_CIR_IER_RESET 0x20
59#define IT87_CIR_IER_BR 0x10
60#define IT87_CIR_IER_IEC 0x8
61#define IT87_CIR_IER_RFOIE 0x4
62#define IT87_CIR_IER_RDAIE 0x2
63#define IT87_CIR_IER_TLDLIE 0x1
64
65/* RCR: */
66#define IT87_CIR_RCR_RDWOS 0x80
67#define IT87_CIR_RCR_HCFS 0x40
68#define IT87_CIR_RCR_RXEN 0x20
69#define IT87_CIR_RCR_RXEND 0x10
70#define IT87_CIR_RCR_RXACT 0x8
71#define IT87_CIR_RCR_RXDCR 0x7
72
73/* TCR1: */
74#define IT87_CIR_TCR1_FIFOCLR 0x80
75#define IT87_CIR_TCR1_ILE 0x40
76#define IT87_CIR_TCR1_FIFOTL 0x30
77#define IT87_CIR_TCR1_TXRLE 0x8
78#define IT87_CIR_TCR1_TXENDF 0x4
79#define IT87_CIR_TCR1_TXMPM 0x3
80
81/* TCR2: */
82#define IT87_CIR_TCR2_CFQ 0xf8
83#define IT87_CIR_TCR2_TXMPW 0x7
84
85/* TSR: */
86#define IT87_CIR_TSR_RESERVED 0xc0
87#define IT87_CIR_TSR_TXFBC 0x3f
88
89/* RSR: */
90#define IT87_CIR_RSR_RXFTO 0x80
91#define IT87_CIR_RSR_RESERVED 0x40
92#define IT87_CIR_RSR_RXFBC 0x3f
93
94/* IIR: */
95#define IT87_CIR_IIR_RESERVED 0xf8
96#define IT87_CIR_IIR_IID 0x6
97#define IT87_CIR_IIR_IIP 0x1
98
99/* TM: */
100#define IT87_CIR_TM_IL_SEL 0x80
101#define IT87_CIR_TM_RESERVED 0x40
102#define IT87_CIR_TM_TM_REG 0x3f
103
104#define IT87_CIR_FIFO_SIZE 32
105
106/* Baudratedivisor for IT87: power of 2: only 1,2,4 or 8) */
107#define IT87_CIR_BAUDRATE_DIVISOR 0x1
108#define IT87_CIR_DEFAULT_IOBASE 0x310
109#define IT87_CIR_DEFAULT_IRQ 0x7
110#define IT87_CIR_SPACE 0x00
111#define IT87_CIR_PULSE 0xff
112#define IT87_CIR_FREQ_MIN 27
113#define IT87_CIR_FREQ_MAX 58
114#define TIME_CONST (IT87_CIR_BAUDRATE_DIVISOR * 8000000ul / 115200ul)
115
116/********************************* ITE IT87xx ************************/
diff --git a/drivers/staging/lirc/lirc_ite8709.c b/drivers/staging/lirc/lirc_ite8709.c
new file mode 100644
index 000000000000..9352f45bbece
--- /dev/null
+++ b/drivers/staging/lirc/lirc_ite8709.c
@@ -0,0 +1,542 @@
1/*
2 * LIRC driver for ITE8709 CIR port
3 *
4 * Copyright (C) 2008 Grégory Lardière <spmf2004-lirc@yahoo.fr>
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; either version 2 of the
9 * License, or (at your option) any later version.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 * USA
20 */
21
22#include <linux/module.h>
23#include <linux/interrupt.h>
24#include <linux/sched.h>
25#include <linux/delay.h>
26#include <linux/pnp.h>
27#include <linux/io.h>
28
29#include <media/lirc.h>
30#include <media/lirc_dev.h>
31
32#define LIRC_DRIVER_NAME "lirc_ite8709"
33
34#define BUF_CHUNK_SIZE sizeof(int)
35#define BUF_SIZE (128*BUF_CHUNK_SIZE)
36
37/*
38 * The ITE8709 device seems to be the combination of IT8512 superIO chip and
39 * a specific firmware running on the IT8512's embedded micro-controller.
40 * In addition of the embedded micro-controller, the IT8512 chip contains a
41 * CIR module and several other modules. A few modules are directly accessible
42 * by the host CPU, but most of them are only accessible by the
43 * micro-controller. The CIR module is only accessible by the micro-controller.
44 * The battery-backed SRAM module is accessible by the host CPU and the
45 * micro-controller. So one of the MC's firmware role is to act as a bridge
46 * between the host CPU and the CIR module. The firmware implements a kind of
47 * communication protocol using the SRAM module as a shared memory. The IT8512
48 * specification is publicly available on ITE's web site, but the communication
49 * protocol is not, so it was reverse-engineered.
50 */
51
52/* ITE8709 Registers addresses and values (reverse-engineered) */
53#define ITE8709_MODE 0x1a
54#define ITE8709_REG_ADR 0x1b
55#define ITE8709_REG_VAL 0x1c
56#define ITE8709_IIR 0x1e /* Interrupt identification register */
57#define ITE8709_RFSR 0x1f /* Receiver FIFO status register */
58#define ITE8709_FIFO_START 0x20
59
60#define ITE8709_MODE_READY 0X00
61#define ITE8709_MODE_WRITE 0X01
62#define ITE8709_MODE_READ 0X02
63#define ITE8709_IIR_RDAI 0x02 /* Receiver data available interrupt */
64#define ITE8709_IIR_RFOI 0x04 /* Receiver FIFO overrun interrupt */
65#define ITE8709_RFSR_MASK 0x3f /* FIFO byte count mask */
66
67/*
68 * IT8512 CIR-module registers addresses and values
69 * (from IT8512 E/F specification v0.4.1)
70 */
71#define IT8512_REG_MSTCR 0x01 /* Master control register */
72#define IT8512_REG_IER 0x02 /* Interrupt enable register */
73#define IT8512_REG_CFR 0x04 /* Carrier frequency register */
74#define IT8512_REG_RCR 0x05 /* Receive control register */
75#define IT8512_REG_BDLR 0x08 /* Baud rate divisor low byte register */
76#define IT8512_REG_BDHR 0x09 /* Baud rate divisor high byte register */
77
78#define IT8512_MSTCR_RESET 0x01 /* Reset registers to default value */
79#define IT8512_MSTCR_FIFOCLR 0x02 /* Clear FIFO */
80#define IT8512_MSTCR_FIFOTL_7 0x04 /* FIFO threshold level : 7 */
81#define IT8512_MSTCR_FIFOTL_25 0x0c /* FIFO threshold level : 25 */
82#define IT8512_IER_RDAIE 0x02 /* Enable data interrupt request */
83#define IT8512_IER_RFOIE 0x04 /* Enable FIFO overrun interrupt req */
84#define IT8512_IER_IEC 0x80 /* Enable interrupt request */
85#define IT8512_CFR_CF_36KHZ 0x09 /* Carrier freq : low speed, 36kHz */
86#define IT8512_RCR_RXDCR_1 0x01 /* Demodulation carrier range : 1 */
87#define IT8512_RCR_RXACT 0x08 /* Receiver active */
88#define IT8512_RCR_RXEN 0x80 /* Receiver enable */
89#define IT8512_BDR_6 6 /* Baud rate divisor : 6 */
90
91/* Actual values used by this driver */
92#define CFG_FIFOTL IT8512_MSTCR_FIFOTL_25
93#define CFG_CR_FREQ IT8512_CFR_CF_36KHZ
94#define CFG_DCR IT8512_RCR_RXDCR_1
95#define CFG_BDR IT8512_BDR_6
96#define CFG_TIMEOUT 100000 /* Rearm interrupt when a space is > 100 ms */
97
98static int debug;
99
100struct ite8709_device {
101 int use_count;
102 int io;
103 int irq;
104 spinlock_t hardware_lock;
105 unsigned long long acc_pulse;
106 unsigned long long acc_space;
107 char lastbit;
108 struct timeval last_tv;
109 struct lirc_driver driver;
110 struct tasklet_struct tasklet;
111 char force_rearm;
112 char rearmed;
113 char device_busy;
114};
115
116#define dprintk(fmt, args...) \
117 do { \
118 if (debug) \
119 printk(KERN_DEBUG LIRC_DRIVER_NAME ": " \
120 fmt, ## args); \
121 } while (0)
122
123
124static unsigned char ite8709_read(struct ite8709_device *dev,
125 unsigned char port)
126{
127 outb(port, dev->io);
128 return inb(dev->io+1);
129}
130
131static void ite8709_write(struct ite8709_device *dev, unsigned char port,
132 unsigned char data)
133{
134 outb(port, dev->io);
135 outb(data, dev->io+1);
136}
137
138static void ite8709_wait_device(struct ite8709_device *dev)
139{
140 int i = 0;
141 /*
142 * loop until device tells it's ready to continue
143 * iterations count is usually ~750 but can sometimes achieve 13000
144 */
145 for (i = 0; i < 15000; i++) {
146 udelay(2);
147 if (ite8709_read(dev, ITE8709_MODE) == ITE8709_MODE_READY)
148 break;
149 }
150}
151
152static void ite8709_write_register(struct ite8709_device *dev,
153 unsigned char reg_adr, unsigned char reg_value)
154{
155 ite8709_wait_device(dev);
156
157 ite8709_write(dev, ITE8709_REG_VAL, reg_value);
158 ite8709_write(dev, ITE8709_REG_ADR, reg_adr);
159 ite8709_write(dev, ITE8709_MODE, ITE8709_MODE_WRITE);
160}
161
162static void ite8709_init_hardware(struct ite8709_device *dev)
163{
164 spin_lock_irq(&dev->hardware_lock);
165 dev->device_busy = 1;
166 spin_unlock_irq(&dev->hardware_lock);
167
168 ite8709_write_register(dev, IT8512_REG_BDHR, (CFG_BDR >> 8) & 0xff);
169 ite8709_write_register(dev, IT8512_REG_BDLR, CFG_BDR & 0xff);
170 ite8709_write_register(dev, IT8512_REG_CFR, CFG_CR_FREQ);
171 ite8709_write_register(dev, IT8512_REG_IER,
172 IT8512_IER_IEC | IT8512_IER_RFOIE | IT8512_IER_RDAIE);
173 ite8709_write_register(dev, IT8512_REG_RCR, CFG_DCR);
174 ite8709_write_register(dev, IT8512_REG_MSTCR,
175 CFG_FIFOTL | IT8512_MSTCR_FIFOCLR);
176 ite8709_write_register(dev, IT8512_REG_RCR,
177 IT8512_RCR_RXEN | IT8512_RCR_RXACT | CFG_DCR);
178
179 spin_lock_irq(&dev->hardware_lock);
180 dev->device_busy = 0;
181 spin_unlock_irq(&dev->hardware_lock);
182
183 tasklet_enable(&dev->tasklet);
184}
185
186static void ite8709_drop_hardware(struct ite8709_device *dev)
187{
188 tasklet_disable(&dev->tasklet);
189
190 spin_lock_irq(&dev->hardware_lock);
191 dev->device_busy = 1;
192 spin_unlock_irq(&dev->hardware_lock);
193
194 ite8709_write_register(dev, IT8512_REG_RCR, 0);
195 ite8709_write_register(dev, IT8512_REG_MSTCR,
196 IT8512_MSTCR_RESET | IT8512_MSTCR_FIFOCLR);
197
198 spin_lock_irq(&dev->hardware_lock);
199 dev->device_busy = 0;
200 spin_unlock_irq(&dev->hardware_lock);
201}
202
203static int ite8709_set_use_inc(void *data)
204{
205 struct ite8709_device *dev;
206 dev = data;
207 if (dev->use_count == 0)
208 ite8709_init_hardware(dev);
209 dev->use_count++;
210 return 0;
211}
212
213static void ite8709_set_use_dec(void *data)
214{
215 struct ite8709_device *dev;
216 dev = data;
217 dev->use_count--;
218 if (dev->use_count == 0)
219 ite8709_drop_hardware(dev);
220}
221
222static void ite8709_add_read_queue(struct ite8709_device *dev, int flag,
223 unsigned long long val)
224{
225 int value;
226
227 dprintk("add a %llu usec %s\n", val, flag ? "pulse" : "space");
228
229 value = (val > PULSE_MASK) ? PULSE_MASK : val;
230 if (flag)
231 value |= PULSE_BIT;
232
233 if (!lirc_buffer_full(dev->driver.rbuf)) {
234 lirc_buffer_write(dev->driver.rbuf, (void *) &value);
235 wake_up(&dev->driver.rbuf->wait_poll);
236 }
237}
238
239static irqreturn_t ite8709_interrupt(int irq, void *dev_id)
240{
241 unsigned char data;
242 int iir, rfsr, i;
243 int fifo = 0;
244 char bit;
245 struct timeval curr_tv;
246
247 /* Bit duration in microseconds */
248 const unsigned long bit_duration = 1000000ul / (115200 / CFG_BDR);
249
250 struct ite8709_device *dev;
251 dev = dev_id;
252
253 /*
254 * If device is busy, we simply discard data because we are in one of
255 * these two cases : shutting down or rearming the device, so this
256 * doesn't really matter and this avoids waiting too long in IRQ ctx
257 */
258 spin_lock(&dev->hardware_lock);
259 if (dev->device_busy) {
260 spin_unlock(&dev->hardware_lock);
261 return IRQ_RETVAL(IRQ_HANDLED);
262 }
263
264 iir = ite8709_read(dev, ITE8709_IIR);
265
266 switch (iir) {
267 case ITE8709_IIR_RFOI:
268 dprintk("fifo overrun, scheduling forced rearm just in case\n");
269 dev->force_rearm = 1;
270 tasklet_schedule(&dev->tasklet);
271 spin_unlock(&dev->hardware_lock);
272 return IRQ_RETVAL(IRQ_HANDLED);
273
274 case ITE8709_IIR_RDAI:
275 rfsr = ite8709_read(dev, ITE8709_RFSR);
276 fifo = rfsr & ITE8709_RFSR_MASK;
277 if (fifo > 32)
278 fifo = 32;
279 dprintk("iir: 0x%x rfsr: 0x%x fifo: %d\n", iir, rfsr, fifo);
280
281 if (dev->rearmed) {
282 do_gettimeofday(&curr_tv);
283 dev->acc_space += 1000000ull
284 * (curr_tv.tv_sec - dev->last_tv.tv_sec)
285 + (curr_tv.tv_usec - dev->last_tv.tv_usec);
286 dev->rearmed = 0;
287 }
288 for (i = 0; i < fifo; i++) {
289 data = ite8709_read(dev, i+ITE8709_FIFO_START);
290 data = ~data;
291 /* Loop through */
292 for (bit = 0; bit < 8; ++bit) {
293 if ((data >> bit) & 1) {
294 dev->acc_pulse += bit_duration;
295 if (dev->lastbit == 0) {
296 ite8709_add_read_queue(dev, 0,
297 dev->acc_space);
298 dev->acc_space = 0;
299 }
300 } else {
301 dev->acc_space += bit_duration;
302 if (dev->lastbit == 1) {
303 ite8709_add_read_queue(dev, 1,
304 dev->acc_pulse);
305 dev->acc_pulse = 0;
306 }
307 }
308 dev->lastbit = (data >> bit) & 1;
309 }
310 }
311 ite8709_write(dev, ITE8709_RFSR, 0);
312
313 if (dev->acc_space > CFG_TIMEOUT) {
314 dprintk("scheduling rearm IRQ\n");
315 do_gettimeofday(&dev->last_tv);
316 dev->force_rearm = 0;
317 tasklet_schedule(&dev->tasklet);
318 }
319
320 spin_unlock(&dev->hardware_lock);
321 return IRQ_RETVAL(IRQ_HANDLED);
322
323 default:
324 /* not our irq */
325 dprintk("unknown IRQ (shouldn't happen) !!\n");
326 spin_unlock(&dev->hardware_lock);
327 return IRQ_RETVAL(IRQ_NONE);
328 }
329}
330
331static void ite8709_rearm_irq(unsigned long data)
332{
333 struct ite8709_device *dev;
334 unsigned long flags;
335 dev = (struct ite8709_device *) data;
336
337 spin_lock_irqsave(&dev->hardware_lock, flags);
338 dev->device_busy = 1;
339 spin_unlock_irqrestore(&dev->hardware_lock, flags);
340
341 if (dev->force_rearm || dev->acc_space > CFG_TIMEOUT) {
342 dprintk("rearming IRQ\n");
343 ite8709_write_register(dev, IT8512_REG_RCR,
344 IT8512_RCR_RXACT | CFG_DCR);
345 ite8709_write_register(dev, IT8512_REG_MSTCR,
346 CFG_FIFOTL | IT8512_MSTCR_FIFOCLR);
347 ite8709_write_register(dev, IT8512_REG_RCR,
348 IT8512_RCR_RXEN | IT8512_RCR_RXACT | CFG_DCR);
349 if (!dev->force_rearm)
350 dev->rearmed = 1;
351 dev->force_rearm = 0;
352 }
353
354 spin_lock_irqsave(&dev->hardware_lock, flags);
355 dev->device_busy = 0;
356 spin_unlock_irqrestore(&dev->hardware_lock, flags);
357}
358
359static int ite8709_cleanup(struct ite8709_device *dev, int stage, int errno,
360 char *msg)
361{
362 if (msg != NULL)
363 printk(KERN_ERR LIRC_DRIVER_NAME ": %s\n", msg);
364
365 switch (stage) {
366 case 6:
367 if (dev->use_count > 0)
368 ite8709_drop_hardware(dev);
369 case 5:
370 free_irq(dev->irq, dev);
371 case 4:
372 release_region(dev->io, 2);
373 case 3:
374 lirc_unregister_driver(dev->driver.minor);
375 case 2:
376 lirc_buffer_free(dev->driver.rbuf);
377 kfree(dev->driver.rbuf);
378 case 1:
379 kfree(dev);
380 case 0:
381 ;
382 }
383
384 return errno;
385}
386
387static int __devinit ite8709_pnp_probe(struct pnp_dev *dev,
388 const struct pnp_device_id *dev_id)
389{
390 struct lirc_driver *driver;
391 struct ite8709_device *ite8709_dev;
392 int ret;
393
394 /* Check resources validity */
395 if (!pnp_irq_valid(dev, 0))
396 return ite8709_cleanup(NULL, 0, -ENODEV, "invalid IRQ");
397 if (!pnp_port_valid(dev, 2))
398 return ite8709_cleanup(NULL, 0, -ENODEV, "invalid IO port");
399
400 /* Allocate memory for device struct */
401 ite8709_dev = kzalloc(sizeof(struct ite8709_device), GFP_KERNEL);
402 if (ite8709_dev == NULL)
403 return ite8709_cleanup(NULL, 0, -ENOMEM, "kzalloc failed");
404 pnp_set_drvdata(dev, ite8709_dev);
405
406 /* Initialize device struct */
407 ite8709_dev->use_count = 0;
408 ite8709_dev->irq = pnp_irq(dev, 0);
409 ite8709_dev->io = pnp_port_start(dev, 2);
410 ite8709_dev->hardware_lock =
411 __SPIN_LOCK_UNLOCKED(ite8709_dev->hardware_lock);
412 ite8709_dev->acc_pulse = 0;
413 ite8709_dev->acc_space = 0;
414 ite8709_dev->lastbit = 0;
415 do_gettimeofday(&ite8709_dev->last_tv);
416 tasklet_init(&ite8709_dev->tasklet, ite8709_rearm_irq,
417 (long) ite8709_dev);
418 ite8709_dev->force_rearm = 0;
419 ite8709_dev->rearmed = 0;
420 ite8709_dev->device_busy = 0;
421
422 /* Initialize driver struct */
423 driver = &ite8709_dev->driver;
424 strcpy(driver->name, LIRC_DRIVER_NAME);
425 driver->minor = -1;
426 driver->code_length = sizeof(int) * 8;
427 driver->sample_rate = 0;
428 driver->features = LIRC_CAN_REC_MODE2;
429 driver->data = ite8709_dev;
430 driver->add_to_buf = NULL;
431 driver->set_use_inc = ite8709_set_use_inc;
432 driver->set_use_dec = ite8709_set_use_dec;
433 driver->dev = &dev->dev;
434 driver->owner = THIS_MODULE;
435
436 /* Initialize LIRC buffer */
437 driver->rbuf = kmalloc(sizeof(struct lirc_buffer), GFP_KERNEL);
438 if (!driver->rbuf)
439 return ite8709_cleanup(ite8709_dev, 1, -ENOMEM,
440 "can't allocate lirc_buffer");
441 if (lirc_buffer_init(driver->rbuf, BUF_CHUNK_SIZE, BUF_SIZE))
442 return ite8709_cleanup(ite8709_dev, 1, -ENOMEM,
443 "lirc_buffer_init() failed");
444
445 /* Register LIRC driver */
446 ret = lirc_register_driver(driver);
447 if (ret < 0)
448 return ite8709_cleanup(ite8709_dev, 2, ret,
449 "lirc_register_driver() failed");
450
451 /* Reserve I/O port access */
452 if (!request_region(ite8709_dev->io, 2, LIRC_DRIVER_NAME))
453 return ite8709_cleanup(ite8709_dev, 3, -EBUSY,
454 "i/o port already in use");
455
456 /* Reserve IRQ line */
457 ret = request_irq(ite8709_dev->irq, ite8709_interrupt, 0,
458 LIRC_DRIVER_NAME, ite8709_dev);
459 if (ret < 0)
460 return ite8709_cleanup(ite8709_dev, 4, ret,
461 "IRQ already in use");
462
463 /* Initialize hardware */
464 ite8709_drop_hardware(ite8709_dev); /* Shutdown hw until first use */
465
466 printk(KERN_INFO LIRC_DRIVER_NAME ": device found : irq=%d io=0x%x\n",
467 ite8709_dev->irq, ite8709_dev->io);
468
469 return 0;
470}
471
472static void __devexit ite8709_pnp_remove(struct pnp_dev *dev)
473{
474 struct ite8709_device *ite8709_dev;
475 ite8709_dev = pnp_get_drvdata(dev);
476
477 ite8709_cleanup(ite8709_dev, 6, 0, NULL);
478
479 printk(KERN_INFO LIRC_DRIVER_NAME ": device removed\n");
480}
481
482#ifdef CONFIG_PM
483static int ite8709_pnp_suspend(struct pnp_dev *dev, pm_message_t state)
484{
485 struct ite8709_device *ite8709_dev;
486 ite8709_dev = pnp_get_drvdata(dev);
487
488 if (ite8709_dev->use_count > 0)
489 ite8709_drop_hardware(ite8709_dev);
490
491 return 0;
492}
493
494static int ite8709_pnp_resume(struct pnp_dev *dev)
495{
496 struct ite8709_device *ite8709_dev;
497 ite8709_dev = pnp_get_drvdata(dev);
498
499 if (ite8709_dev->use_count > 0)
500 ite8709_init_hardware(ite8709_dev);
501
502 return 0;
503}
504#else
505#define ite8709_pnp_suspend NULL
506#define ite8709_pnp_resume NULL
507#endif
508
509static const struct pnp_device_id pnp_dev_table[] = {
510 {"ITE8709", 0},
511 {}
512};
513
514MODULE_DEVICE_TABLE(pnp, pnp_dev_table);
515
516static struct pnp_driver ite8709_pnp_driver = {
517 .name = LIRC_DRIVER_NAME,
518 .probe = ite8709_pnp_probe,
519 .remove = __devexit_p(ite8709_pnp_remove),
520 .suspend = ite8709_pnp_suspend,
521 .resume = ite8709_pnp_resume,
522 .id_table = pnp_dev_table,
523};
524
525static int __init ite8709_init_module(void)
526{
527 return pnp_register_driver(&ite8709_pnp_driver);
528}
529module_init(ite8709_init_module);
530
531static void __exit ite8709_cleanup_module(void)
532{
533 pnp_unregister_driver(&ite8709_pnp_driver);
534}
535module_exit(ite8709_cleanup_module);
536
537MODULE_DESCRIPTION("LIRC driver for ITE8709 CIR port");
538MODULE_AUTHOR("Grégory Lardière");
539MODULE_LICENSE("GPL");
540
541module_param(debug, bool, S_IRUGO | S_IWUSR);
542MODULE_PARM_DESC(debug, "Enable debugging messages");
diff --git a/drivers/staging/lirc/lirc_parallel.c b/drivers/staging/lirc/lirc_parallel.c
new file mode 100644
index 000000000000..a1ebd071640f
--- /dev/null
+++ b/drivers/staging/lirc/lirc_parallel.c
@@ -0,0 +1,705 @@
1/*
2 * lirc_parallel.c
3 *
4 * lirc_parallel - device driver for infra-red signal receiving and
5 * transmitting unit built by the author
6 *
7 * Copyright (C) 1998 Christoph Bartelmus <lirc@bartelmus.de>
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 */
24
25/*** Includes ***/
26
27#ifdef CONFIG_SMP
28#error "--- Sorry, this driver is not SMP safe. ---"
29#endif
30
31#include <linux/module.h>
32#include <linux/sched.h>
33#include <linux/errno.h>
34#include <linux/signal.h>
35#include <linux/fs.h>
36#include <linux/kernel.h>
37#include <linux/ioport.h>
38#include <linux/time.h>
39#include <linux/mm.h>
40#include <linux/delay.h>
41
42#include <linux/io.h>
43#include <linux/signal.h>
44#include <linux/irq.h>
45#include <linux/uaccess.h>
46#include <asm/div64.h>
47
48#include <linux/poll.h>
49#include <linux/parport.h>
50
51#include <media/lirc.h>
52#include <media/lirc_dev.h>
53
54#include "lirc_parallel.h"
55
56#define LIRC_DRIVER_NAME "lirc_parallel"
57
58#ifndef LIRC_IRQ
59#define LIRC_IRQ 7
60#endif
61#ifndef LIRC_PORT
62#define LIRC_PORT 0x378
63#endif
64#ifndef LIRC_TIMER
65#define LIRC_TIMER 65536
66#endif
67
68/*** Global Variables ***/
69
70static int debug;
71static int check_pselecd;
72
73unsigned int irq = LIRC_IRQ;
74unsigned int io = LIRC_PORT;
75#ifdef LIRC_TIMER
76unsigned int timer;
77unsigned int default_timer = LIRC_TIMER;
78#endif
79
80#define RBUF_SIZE (256) /* this must be a power of 2 larger than 1 */
81
82static int rbuf[RBUF_SIZE];
83
84DECLARE_WAIT_QUEUE_HEAD(lirc_wait);
85
86unsigned int rptr;
87unsigned int wptr;
88unsigned int lost_irqs;
89int is_open;
90
91struct parport *pport;
92struct pardevice *ppdevice;
93int is_claimed;
94
95unsigned int tx_mask = 1;
96
97/*** Internal Functions ***/
98
99static unsigned int in(int offset)
100{
101 switch (offset) {
102 case LIRC_LP_BASE:
103 return parport_read_data(pport);
104 case LIRC_LP_STATUS:
105 return parport_read_status(pport);
106 case LIRC_LP_CONTROL:
107 return parport_read_control(pport);
108 }
109 return 0; /* make compiler happy */
110}
111
112static void out(int offset, int value)
113{
114 switch (offset) {
115 case LIRC_LP_BASE:
116 parport_write_data(pport, value);
117 break;
118 case LIRC_LP_CONTROL:
119 parport_write_control(pport, value);
120 break;
121 case LIRC_LP_STATUS:
122 printk(KERN_INFO "%s: attempt to write to status register\n",
123 LIRC_DRIVER_NAME);
124 break;
125 }
126}
127
128static unsigned int lirc_get_timer(void)
129{
130 return in(LIRC_PORT_TIMER) & LIRC_PORT_TIMER_BIT;
131}
132
133static unsigned int lirc_get_signal(void)
134{
135 return in(LIRC_PORT_SIGNAL) & LIRC_PORT_SIGNAL_BIT;
136}
137
138static void lirc_on(void)
139{
140 out(LIRC_PORT_DATA, tx_mask);
141}
142
143static void lirc_off(void)
144{
145 out(LIRC_PORT_DATA, 0);
146}
147
148static unsigned int init_lirc_timer(void)
149{
150 struct timeval tv, now;
151 unsigned int level, newlevel, timeelapsed, newtimer;
152 int count = 0;
153
154 do_gettimeofday(&tv);
155 tv.tv_sec++; /* wait max. 1 sec. */
156 level = lirc_get_timer();
157 do {
158 newlevel = lirc_get_timer();
159 if (level == 0 && newlevel != 0)
160 count++;
161 level = newlevel;
162 do_gettimeofday(&now);
163 } while (count < 1000 && (now.tv_sec < tv.tv_sec
164 || (now.tv_sec == tv.tv_sec
165 && now.tv_usec < tv.tv_usec)));
166
167 timeelapsed = ((now.tv_sec + 1 - tv.tv_sec)*1000000
168 + (now.tv_usec - tv.tv_usec));
169 if (count >= 1000 && timeelapsed > 0) {
170 if (default_timer == 0) {
171 /* autodetect timer */
172 newtimer = (1000000*count)/timeelapsed;
173 printk(KERN_INFO "%s: %u Hz timer detected\n",
174 LIRC_DRIVER_NAME, newtimer);
175 return newtimer;
176 } else {
177 newtimer = (1000000*count)/timeelapsed;
178 if (abs(newtimer - default_timer) > default_timer/10) {
179 /* bad timer */
180 printk(KERN_NOTICE "%s: bad timer: %u Hz\n",
181 LIRC_DRIVER_NAME, newtimer);
182 printk(KERN_NOTICE "%s: using default timer: "
183 "%u Hz\n",
184 LIRC_DRIVER_NAME, default_timer);
185 return default_timer;
186 } else {
187 printk(KERN_INFO "%s: %u Hz timer detected\n",
188 LIRC_DRIVER_NAME, newtimer);
189 return newtimer; /* use detected value */
190 }
191 }
192 } else {
193 printk(KERN_NOTICE "%s: no timer detected\n", LIRC_DRIVER_NAME);
194 return 0;
195 }
196}
197
198static int lirc_claim(void)
199{
200 if (parport_claim(ppdevice) != 0) {
201 printk(KERN_WARNING "%s: could not claim port\n",
202 LIRC_DRIVER_NAME);
203 printk(KERN_WARNING "%s: waiting for port becoming available"
204 "\n", LIRC_DRIVER_NAME);
205 if (parport_claim_or_block(ppdevice) < 0) {
206 printk(KERN_NOTICE "%s: could not claim port, giving"
207 " up\n", LIRC_DRIVER_NAME);
208 return 0;
209 }
210 }
211 out(LIRC_LP_CONTROL, LP_PSELECP|LP_PINITP);
212 is_claimed = 1;
213 return 1;
214}
215
216/*** interrupt handler ***/
217
218static void rbuf_write(int signal)
219{
220 unsigned int nwptr;
221
222 nwptr = (wptr + 1) & (RBUF_SIZE - 1);
223 if (nwptr == rptr) {
224 /* no new signals will be accepted */
225 lost_irqs++;
226 printk(KERN_NOTICE "%s: buffer overrun\n", LIRC_DRIVER_NAME);
227 return;
228 }
229 rbuf[wptr] = signal;
230 wptr = nwptr;
231}
232
233static void irq_handler(void *blah)
234{
235 struct timeval tv;
236 static struct timeval lasttv;
237 static int init;
238 long signal;
239 int data;
240 unsigned int level, newlevel;
241 unsigned int timeout;
242
243 if (!module_refcount(THIS_MODULE))
244 return;
245
246 if (!is_claimed)
247 return;
248
249#if 0
250 /* disable interrupt */
251 disable_irq(irq);
252 out(LIRC_PORT_IRQ, in(LIRC_PORT_IRQ) & (~LP_PINTEN));
253#endif
254 if (check_pselecd && (in(1) & LP_PSELECD))
255 return;
256
257#ifdef LIRC_TIMER
258 if (init) {
259 do_gettimeofday(&tv);
260
261 signal = tv.tv_sec - lasttv.tv_sec;
262 if (signal > 15)
263 /* really long time */
264 data = PULSE_MASK;
265 else
266 data = (int) (signal*1000000 +
267 tv.tv_usec - lasttv.tv_usec +
268 LIRC_SFH506_DELAY);
269
270 rbuf_write(data); /* space */
271 } else {
272 if (timer == 0) {
273 /*
274 * wake up; we'll lose this signal, but it will be
275 * garbage if the device is turned on anyway
276 */
277 timer = init_lirc_timer();
278 /* enable_irq(irq); */
279 return;
280 }
281 init = 1;
282 }
283
284 timeout = timer/10; /* timeout after 1/10 sec. */
285 signal = 1;
286 level = lirc_get_timer();
287 do {
288 newlevel = lirc_get_timer();
289 if (level == 0 && newlevel != 0)
290 signal++;
291 level = newlevel;
292
293 /* giving up */
294 if (signal > timeout
295 || (check_pselecd && (in(1) & LP_PSELECD))) {
296 signal = 0;
297 printk(KERN_NOTICE "%s: timeout\n", LIRC_DRIVER_NAME);
298 break;
299 }
300 } while (lirc_get_signal());
301
302 if (signal != 0) {
303 /* ajust value to usecs */
304 unsigned long long helper;
305
306 helper = ((unsigned long long) signal)*1000000;
307 do_div(helper, timer);
308 signal = (long) helper;
309
310 if (signal > LIRC_SFH506_DELAY)
311 data = signal - LIRC_SFH506_DELAY;
312 else
313 data = 1;
314 rbuf_write(PULSE_BIT|data); /* pulse */
315 }
316 do_gettimeofday(&lasttv);
317#else
318 /* add your code here */
319#endif
320
321 wake_up_interruptible(&lirc_wait);
322
323 /* enable interrupt */
324 /*
325 enable_irq(irq);
326 out(LIRC_PORT_IRQ, in(LIRC_PORT_IRQ)|LP_PINTEN);
327 */
328}
329
330/*** file operations ***/
331
332static loff_t lirc_lseek(struct file *filep, loff_t offset, int orig)
333{
334 return -ESPIPE;
335}
336
337static ssize_t lirc_read(struct file *filep, char *buf, size_t n, loff_t *ppos)
338{
339 int result = 0;
340 int count = 0;
341 DECLARE_WAITQUEUE(wait, current);
342
343 if (n % sizeof(int))
344 return -EINVAL;
345
346 add_wait_queue(&lirc_wait, &wait);
347 set_current_state(TASK_INTERRUPTIBLE);
348 while (count < n) {
349 if (rptr != wptr) {
350 if (copy_to_user(buf+count, (char *) &rbuf[rptr],
351 sizeof(int))) {
352 result = -EFAULT;
353 break;
354 }
355 rptr = (rptr + 1) & (RBUF_SIZE - 1);
356 count += sizeof(int);
357 } else {
358 if (filep->f_flags & O_NONBLOCK) {
359 result = -EAGAIN;
360 break;
361 }
362 if (signal_pending(current)) {
363 result = -ERESTARTSYS;
364 break;
365 }
366 schedule();
367 set_current_state(TASK_INTERRUPTIBLE);
368 }
369 }
370 remove_wait_queue(&lirc_wait, &wait);
371 set_current_state(TASK_RUNNING);
372 return count ? count : result;
373}
374
375static ssize_t lirc_write(struct file *filep, const char *buf, size_t n,
376 loff_t *ppos)
377{
378 int count;
379 unsigned int i;
380 unsigned int level, newlevel;
381 unsigned long flags;
382 int counttimer;
383 int *wbuf;
384
385 if (!is_claimed)
386 return -EBUSY;
387
388 count = n / sizeof(int);
389
390 if (n % sizeof(int) || count % 2 == 0)
391 return -EINVAL;
392
393 wbuf = memdup_user(buf, n);
394 if (IS_ERR(wbuf))
395 return PTR_ERR(wbuf);
396
397#ifdef LIRC_TIMER
398 if (timer == 0) {
399 /* try again if device is ready */
400 timer = init_lirc_timer();
401 if (timer == 0)
402 return -EIO;
403 }
404
405 /* adjust values from usecs */
406 for (i = 0; i < count; i++) {
407 unsigned long long helper;
408
409 helper = ((unsigned long long) wbuf[i])*timer;
410 do_div(helper, 1000000);
411 wbuf[i] = (int) helper;
412 }
413
414 local_irq_save(flags);
415 i = 0;
416 while (i < count) {
417 level = lirc_get_timer();
418 counttimer = 0;
419 lirc_on();
420 do {
421 newlevel = lirc_get_timer();
422 if (level == 0 && newlevel != 0)
423 counttimer++;
424 level = newlevel;
425 if (check_pselecd && (in(1) & LP_PSELECD)) {
426 lirc_off();
427 local_irq_restore(flags);
428 return -EIO;
429 }
430 } while (counttimer < wbuf[i]);
431 i++;
432
433 lirc_off();
434 if (i == count)
435 break;
436 counttimer = 0;
437 do {
438 newlevel = lirc_get_timer();
439 if (level == 0 && newlevel != 0)
440 counttimer++;
441 level = newlevel;
442 if (check_pselecd && (in(1) & LP_PSELECD)) {
443 local_irq_restore(flags);
444 return -EIO;
445 }
446 } while (counttimer < wbuf[i]);
447 i++;
448 }
449 local_irq_restore(flags);
450#else
451 /* place code that handles write without external timer here */
452#endif
453 return n;
454}
455
456static unsigned int lirc_poll(struct file *file, poll_table *wait)
457{
458 poll_wait(file, &lirc_wait, wait);
459 if (rptr != wptr)
460 return POLLIN | POLLRDNORM;
461 return 0;
462}
463
464static long lirc_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
465{
466 int result;
467 unsigned long features = LIRC_CAN_SET_TRANSMITTER_MASK |
468 LIRC_CAN_SEND_PULSE | LIRC_CAN_REC_MODE2;
469 unsigned long mode;
470 unsigned int ivalue;
471
472 switch (cmd) {
473 case LIRC_GET_FEATURES:
474 result = put_user(features, (unsigned long *) arg);
475 if (result)
476 return result;
477 break;
478 case LIRC_GET_SEND_MODE:
479 result = put_user(LIRC_MODE_PULSE, (unsigned long *) arg);
480 if (result)
481 return result;
482 break;
483 case LIRC_GET_REC_MODE:
484 result = put_user(LIRC_MODE_MODE2, (unsigned long *) arg);
485 if (result)
486 return result;
487 break;
488 case LIRC_SET_SEND_MODE:
489 result = get_user(mode, (unsigned long *) arg);
490 if (result)
491 return result;
492 if (mode != LIRC_MODE_PULSE)
493 return -EINVAL;
494 break;
495 case LIRC_SET_REC_MODE:
496 result = get_user(mode, (unsigned long *) arg);
497 if (result)
498 return result;
499 if (mode != LIRC_MODE_MODE2)
500 return -ENOSYS;
501 break;
502 case LIRC_SET_TRANSMITTER_MASK:
503 result = get_user(ivalue, (unsigned int *) arg);
504 if (result)
505 return result;
506 if ((ivalue & LIRC_PARALLEL_TRANSMITTER_MASK) != ivalue)
507 return LIRC_PARALLEL_MAX_TRANSMITTERS;
508 tx_mask = ivalue;
509 break;
510 default:
511 return -ENOIOCTLCMD;
512 }
513 return 0;
514}
515
516static int lirc_open(struct inode *node, struct file *filep)
517{
518 if (module_refcount(THIS_MODULE) || !lirc_claim())
519 return -EBUSY;
520
521 parport_enable_irq(pport);
522
523 /* init read ptr */
524 rptr = 0;
525 wptr = 0;
526 lost_irqs = 0;
527
528 is_open = 1;
529 return 0;
530}
531
532static int lirc_close(struct inode *node, struct file *filep)
533{
534 if (is_claimed) {
535 is_claimed = 0;
536 parport_release(ppdevice);
537 }
538 is_open = 0;
539 return 0;
540}
541
542static const struct file_operations lirc_fops = {
543 .owner = THIS_MODULE,
544 .llseek = lirc_lseek,
545 .read = lirc_read,
546 .write = lirc_write,
547 .poll = lirc_poll,
548 .unlocked_ioctl = lirc_ioctl,
549 .open = lirc_open,
550 .release = lirc_close
551};
552
553static int set_use_inc(void *data)
554{
555 return 0;
556}
557
558static void set_use_dec(void *data)
559{
560}
561
562static struct lirc_driver driver = {
563 .name = LIRC_DRIVER_NAME,
564 .minor = -1,
565 .code_length = 1,
566 .sample_rate = 0,
567 .data = NULL,
568 .add_to_buf = NULL,
569 .set_use_inc = set_use_inc,
570 .set_use_dec = set_use_dec,
571 .fops = &lirc_fops,
572 .dev = NULL,
573 .owner = THIS_MODULE,
574};
575
576static int pf(void *handle);
577static void kf(void *handle);
578
579static struct timer_list poll_timer;
580static void poll_state(unsigned long ignored);
581
582static void poll_state(unsigned long ignored)
583{
584 printk(KERN_NOTICE "%s: time\n",
585 LIRC_DRIVER_NAME);
586 del_timer(&poll_timer);
587 if (is_claimed)
588 return;
589 kf(NULL);
590 if (!is_claimed) {
591 printk(KERN_NOTICE "%s: could not claim port, giving up\n",
592 LIRC_DRIVER_NAME);
593 init_timer(&poll_timer);
594 poll_timer.expires = jiffies + HZ;
595 poll_timer.data = (unsigned long)current;
596 poll_timer.function = poll_state;
597 add_timer(&poll_timer);
598 }
599}
600
601static int pf(void *handle)
602{
603 parport_disable_irq(pport);
604 is_claimed = 0;
605 return 0;
606}
607
608static void kf(void *handle)
609{
610 if (!is_open)
611 return;
612 if (!lirc_claim())
613 return;
614 parport_enable_irq(pport);
615 lirc_off();
616 /* this is a bit annoying when you actually print...*/
617 /*
618 printk(KERN_INFO "%s: reclaimed port\n", LIRC_DRIVER_NAME);
619 */
620}
621
622/*** module initialization and cleanup ***/
623
624static int __init lirc_parallel_init(void)
625{
626 pport = parport_find_base(io);
627 if (pport == NULL) {
628 printk(KERN_NOTICE "%s: no port at %x found\n",
629 LIRC_DRIVER_NAME, io);
630 return -ENXIO;
631 }
632 ppdevice = parport_register_device(pport, LIRC_DRIVER_NAME,
633 pf, kf, irq_handler, 0, NULL);
634 parport_put_port(pport);
635 if (ppdevice == NULL) {
636 printk(KERN_NOTICE "%s: parport_register_device() failed\n",
637 LIRC_DRIVER_NAME);
638 return -ENXIO;
639 }
640 if (parport_claim(ppdevice) != 0)
641 goto skip_init;
642 is_claimed = 1;
643 out(LIRC_LP_CONTROL, LP_PSELECP|LP_PINITP);
644
645#ifdef LIRC_TIMER
646 if (debug)
647 out(LIRC_PORT_DATA, tx_mask);
648
649 timer = init_lirc_timer();
650
651#if 0 /* continue even if device is offline */
652 if (timer == 0) {
653 is_claimed = 0;
654 parport_release(pport);
655 parport_unregister_device(ppdevice);
656 return -EIO;
657 }
658
659#endif
660 if (debug)
661 out(LIRC_PORT_DATA, 0);
662#endif
663
664 is_claimed = 0;
665 parport_release(ppdevice);
666 skip_init:
667 driver.minor = lirc_register_driver(&driver);
668 if (driver.minor < 0) {
669 printk(KERN_NOTICE "%s: register_chrdev() failed\n",
670 LIRC_DRIVER_NAME);
671 parport_unregister_device(ppdevice);
672 return -EIO;
673 }
674 printk(KERN_INFO "%s: installed using port 0x%04x irq %d\n",
675 LIRC_DRIVER_NAME, io, irq);
676 return 0;
677}
678
679static void __exit lirc_parallel_exit(void)
680{
681 parport_unregister_device(ppdevice);
682 lirc_unregister_driver(driver.minor);
683}
684
685module_init(lirc_parallel_init);
686module_exit(lirc_parallel_exit);
687
688MODULE_DESCRIPTION("Infrared receiver driver for parallel ports.");
689MODULE_AUTHOR("Christoph Bartelmus");
690MODULE_LICENSE("GPL");
691
692module_param(io, int, S_IRUGO);
693MODULE_PARM_DESC(io, "I/O address base (0x3bc, 0x378 or 0x278)");
694
695module_param(irq, int, S_IRUGO);
696MODULE_PARM_DESC(irq, "Interrupt (7 or 5)");
697
698module_param(tx_mask, int, S_IRUGO);
699MODULE_PARM_DESC(tx_maxk, "Transmitter mask (default: 0x01)");
700
701module_param(debug, bool, S_IRUGO | S_IWUSR);
702MODULE_PARM_DESC(debug, "Enable debugging messages");
703
704module_param(check_pselecd, bool, S_IRUGO | S_IWUSR);
705MODULE_PARM_DESC(debug, "Check for printer (default: 0)");
diff --git a/drivers/staging/lirc/lirc_parallel.h b/drivers/staging/lirc/lirc_parallel.h
new file mode 100644
index 000000000000..4bed6afe0632
--- /dev/null
+++ b/drivers/staging/lirc/lirc_parallel.h
@@ -0,0 +1,26 @@
1/* lirc_parallel.h */
2
3#ifndef _LIRC_PARALLEL_H
4#define _LIRC_PARALLEL_H
5
6#include <linux/lp.h>
7
8#define LIRC_PORT_LEN 3
9
10#define LIRC_LP_BASE 0
11#define LIRC_LP_STATUS 1
12#define LIRC_LP_CONTROL 2
13
14#define LIRC_PORT_DATA LIRC_LP_BASE /* base */
15#define LIRC_PORT_TIMER LIRC_LP_STATUS /* status port */
16#define LIRC_PORT_TIMER_BIT LP_PBUSY /* busy signal */
17#define LIRC_PORT_SIGNAL LIRC_LP_STATUS /* status port */
18#define LIRC_PORT_SIGNAL_BIT LP_PACK /* ack signal */
19#define LIRC_PORT_IRQ LIRC_LP_CONTROL /* control port */
20
21#define LIRC_SFH506_DELAY 0 /* delay t_phl in usecs */
22
23#define LIRC_PARALLEL_MAX_TRANSMITTERS 8
24#define LIRC_PARALLEL_TRANSMITTER_MASK ((1<<LIRC_PARALLEL_MAX_TRANSMITTERS) - 1)
25
26#endif
diff --git a/drivers/staging/lirc/lirc_sasem.c b/drivers/staging/lirc/lirc_sasem.c
new file mode 100644
index 000000000000..73166c3f581f
--- /dev/null
+++ b/drivers/staging/lirc/lirc_sasem.c
@@ -0,0 +1,933 @@
1/*
2 * lirc_sasem.c - USB remote support for LIRC
3 * Version 0.5
4 *
5 * Copyright (C) 2004-2005 Oliver Stabel <oliver.stabel@gmx.de>
6 * Tim Davies <tim@opensystems.net.au>
7 *
8 * This driver was derived from:
9 * Venky Raju <dev@venky.ws>
10 * "lirc_imon - "LIRC/VFD driver for Ahanix/Soundgraph IMON IR/VFD"
11 * Paul Miller <pmiller9@users.sourceforge.net>'s 2003-2004
12 * "lirc_atiusb - USB remote support for LIRC"
13 * Culver Consulting Services <henry@culcon.com>'s 2003
14 * "Sasem OnAir VFD/IR USB driver"
15 *
16 *
17 * NOTE - The LCDproc iMon driver should work with this module. More info at
18 * http://www.frogstorm.info/sasem
19 */
20
21/*
22 * This program is free software; you can redistribute it and/or modify
23 * it under the terms of the GNU General Public License as published by
24 * the Free Software Foundation; either version 2 of the License, or
25 * (at your option) any later version.
26 *
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
31 *
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
35 */
36
37#include <linux/errno.h>
38#include <linux/init.h>
39#include <linux/kernel.h>
40#include <linux/module.h>
41#include <linux/slab.h>
42#include <linux/uaccess.h>
43#include <linux/usb.h>
44
45#include <media/lirc.h>
46#include <media/lirc_dev.h>
47
48
49#define MOD_AUTHOR "Oliver Stabel <oliver.stabel@gmx.de>, " \
50 "Tim Davies <tim@opensystems.net.au>"
51#define MOD_DESC "USB Driver for Sasem Remote Controller V1.1"
52#define MOD_NAME "lirc_sasem"
53#define MOD_VERSION "0.5"
54
55#define VFD_MINOR_BASE 144 /* Same as LCD */
56#define DEVICE_NAME "lcd%d"
57
58#define BUF_CHUNK_SIZE 8
59#define BUF_SIZE 128
60
61#define IOCTL_LCD_CONTRAST 1
62
63/*** P R O T O T Y P E S ***/
64
65/* USB Callback prototypes */
66static int sasem_probe(struct usb_interface *interface,
67 const struct usb_device_id *id);
68static void sasem_disconnect(struct usb_interface *interface);
69static void usb_rx_callback(struct urb *urb);
70static void usb_tx_callback(struct urb *urb);
71
72/* VFD file_operations function prototypes */
73static int vfd_open(struct inode *inode, struct file *file);
74static long vfd_ioctl(struct file *file, unsigned cmd, unsigned long arg);
75static int vfd_close(struct inode *inode, struct file *file);
76static ssize_t vfd_write(struct file *file, const char *buf,
77 size_t n_bytes, loff_t *pos);
78
79/* LIRC driver function prototypes */
80static int ir_open(void *data);
81static void ir_close(void *data);
82
83/* Driver init/exit prototypes */
84static int __init sasem_init(void);
85static void __exit sasem_exit(void);
86
87/*** G L O B A L S ***/
88#define SASEM_DATA_BUF_SZ 32
89
90struct sasem_context {
91
92 struct usb_device *dev;
93 int vfd_isopen; /* VFD port has been opened */
94 unsigned int vfd_contrast; /* VFD contrast */
95 int ir_isopen; /* IR port has been opened */
96 int dev_present; /* USB device presence */
97 struct mutex ctx_lock; /* to lock this object */
98 wait_queue_head_t remove_ok; /* For unexpected USB disconnects */
99
100 struct lirc_driver *driver;
101 struct usb_endpoint_descriptor *rx_endpoint;
102 struct usb_endpoint_descriptor *tx_endpoint;
103 struct urb *rx_urb;
104 struct urb *tx_urb;
105 unsigned char usb_rx_buf[8];
106 unsigned char usb_tx_buf[8];
107
108 struct tx_t {
109 unsigned char data_buf[SASEM_DATA_BUF_SZ]; /* user data buffer */
110 struct completion finished; /* wait for write to finish */
111 atomic_t busy; /* write in progress */
112 int status; /* status of tx completion */
113 } tx;
114
115 /* for dealing with repeat codes (wish there was a toggle bit!) */
116 struct timeval presstime;
117 char lastcode[8];
118 int codesaved;
119};
120
121/* VFD file operations */
122static const struct file_operations vfd_fops = {
123 .owner = THIS_MODULE,
124 .open = &vfd_open,
125 .write = &vfd_write,
126 .unlocked_ioctl = &vfd_ioctl,
127 .release = &vfd_close,
128};
129
130/* USB Device ID for Sasem USB Control Board */
131static struct usb_device_id sasem_usb_id_table[] = {
132 /* Sasem USB Control Board */
133 { USB_DEVICE(0x11ba, 0x0101) },
134 /* Terminating entry */
135 {}
136};
137
138/* USB Device data */
139static struct usb_driver sasem_driver = {
140 .name = MOD_NAME,
141 .probe = sasem_probe,
142 .disconnect = sasem_disconnect,
143 .id_table = sasem_usb_id_table,
144};
145
146static struct usb_class_driver sasem_class = {
147 .name = DEVICE_NAME,
148 .fops = &vfd_fops,
149 .minor_base = VFD_MINOR_BASE,
150};
151
152/* to prevent races between open() and disconnect() */
153static DEFINE_MUTEX(disconnect_lock);
154
155static int debug;
156
157
158/*** M O D U L E C O D E ***/
159
160MODULE_AUTHOR(MOD_AUTHOR);
161MODULE_DESCRIPTION(MOD_DESC);
162MODULE_LICENSE("GPL");
163module_param(debug, int, S_IRUGO | S_IWUSR);
164MODULE_PARM_DESC(debug, "Debug messages: 0=no, 1=yes (default: no)");
165
166static void delete_context(struct sasem_context *context)
167{
168 usb_free_urb(context->tx_urb); /* VFD */
169 usb_free_urb(context->rx_urb); /* IR */
170 lirc_buffer_free(context->driver->rbuf);
171 kfree(context->driver->rbuf);
172 kfree(context->driver);
173 kfree(context);
174
175 if (debug)
176 printk(KERN_INFO "%s: context deleted\n", __func__);
177}
178
179static void deregister_from_lirc(struct sasem_context *context)
180{
181 int retval;
182 int minor = context->driver->minor;
183
184 retval = lirc_unregister_driver(minor);
185 if (retval)
186 err("%s: unable to deregister from lirc (%d)",
187 __func__, retval);
188 else
189 printk(KERN_INFO "Deregistered Sasem driver (minor:%d)\n",
190 minor);
191
192}
193
194/**
195 * Called when the VFD device (e.g. /dev/usb/lcd)
196 * is opened by the application.
197 */
198static int vfd_open(struct inode *inode, struct file *file)
199{
200 struct usb_interface *interface;
201 struct sasem_context *context = NULL;
202 int subminor;
203 int retval = 0;
204
205 /* prevent races with disconnect */
206 mutex_lock(&disconnect_lock);
207
208 subminor = iminor(inode);
209 interface = usb_find_interface(&sasem_driver, subminor);
210 if (!interface) {
211 err("%s: could not find interface for minor %d",
212 __func__, subminor);
213 retval = -ENODEV;
214 goto exit;
215 }
216 context = usb_get_intfdata(interface);
217
218 if (!context) {
219 err("%s: no context found for minor %d",
220 __func__, subminor);
221 retval = -ENODEV;
222 goto exit;
223 }
224
225 mutex_lock(&context->ctx_lock);
226
227 if (context->vfd_isopen) {
228 err("%s: VFD port is already open", __func__);
229 retval = -EBUSY;
230 } else {
231 context->vfd_isopen = 1;
232 file->private_data = context;
233 printk(KERN_INFO "VFD port opened\n");
234 }
235
236 mutex_unlock(&context->ctx_lock);
237
238exit:
239 mutex_unlock(&disconnect_lock);
240 return retval;
241}
242
243/**
244 * Called when the VFD device (e.g. /dev/usb/lcd)
245 * is closed by the application.
246 */
247static long vfd_ioctl(struct file *file, unsigned cmd, unsigned long arg)
248{
249 struct sasem_context *context = NULL;
250
251 context = (struct sasem_context *) file->private_data;
252
253 if (!context) {
254 err("%s: no context for device", __func__);
255 return -ENODEV;
256 }
257
258 mutex_lock(&context->ctx_lock);
259
260 switch (cmd) {
261 case IOCTL_LCD_CONTRAST:
262 if (arg > 1000)
263 arg = 1000;
264 context->vfd_contrast = (unsigned int)arg;
265 break;
266 default:
267 printk(KERN_INFO "Unknown IOCTL command\n");
268 mutex_unlock(&context->ctx_lock);
269 return -ENOIOCTLCMD; /* not supported */
270 }
271
272 mutex_unlock(&context->ctx_lock);
273 return 0;
274}
275
276/**
277 * Called when the VFD device (e.g. /dev/usb/lcd)
278 * is closed by the application.
279 */
280static int vfd_close(struct inode *inode, struct file *file)
281{
282 struct sasem_context *context = NULL;
283 int retval = 0;
284
285 context = (struct sasem_context *) file->private_data;
286
287 if (!context) {
288 err("%s: no context for device", __func__);
289 return -ENODEV;
290 }
291
292 mutex_lock(&context->ctx_lock);
293
294 if (!context->vfd_isopen) {
295 err("%s: VFD is not open", __func__);
296 retval = -EIO;
297 } else {
298 context->vfd_isopen = 0;
299 printk(KERN_INFO "VFD port closed\n");
300 if (!context->dev_present && !context->ir_isopen) {
301
302 /* Device disconnected before close and IR port is
303 * not open. If IR port is open, context will be
304 * deleted by ir_close. */
305 mutex_unlock(&context->ctx_lock);
306 delete_context(context);
307 return retval;
308 }
309 }
310
311 mutex_unlock(&context->ctx_lock);
312 return retval;
313}
314
315/**
316 * Sends a packet to the VFD.
317 */
318static int send_packet(struct sasem_context *context)
319{
320 unsigned int pipe;
321 int interval = 0;
322 int retval = 0;
323
324 pipe = usb_sndintpipe(context->dev,
325 context->tx_endpoint->bEndpointAddress);
326 interval = context->tx_endpoint->bInterval;
327
328 usb_fill_int_urb(context->tx_urb, context->dev, pipe,
329 context->usb_tx_buf, sizeof(context->usb_tx_buf),
330 usb_tx_callback, context, interval);
331
332 context->tx_urb->actual_length = 0;
333
334 init_completion(&context->tx.finished);
335 atomic_set(&(context->tx.busy), 1);
336
337 retval = usb_submit_urb(context->tx_urb, GFP_KERNEL);
338 if (retval) {
339 atomic_set(&(context->tx.busy), 0);
340 err("%s: error submitting urb (%d)", __func__, retval);
341 } else {
342 /* Wait for transmission to complete (or abort) */
343 mutex_unlock(&context->ctx_lock);
344 wait_for_completion(&context->tx.finished);
345 mutex_lock(&context->ctx_lock);
346
347 retval = context->tx.status;
348 if (retval)
349 err("%s: packet tx failed (%d)", __func__, retval);
350 }
351
352 return retval;
353}
354
355/**
356 * Writes data to the VFD. The Sasem VFD is 2x16 characters
357 * and requires data in 9 consecutive USB interrupt packets,
358 * each packet carrying 8 bytes.
359 */
360static ssize_t vfd_write(struct file *file, const char *buf,
361 size_t n_bytes, loff_t *pos)
362{
363 int i;
364 int retval = 0;
365 struct sasem_context *context;
366 int *data_buf;
367
368 context = (struct sasem_context *) file->private_data;
369 if (!context) {
370 err("%s: no context for device", __func__);
371 return -ENODEV;
372 }
373
374 mutex_lock(&context->ctx_lock);
375
376 if (!context->dev_present) {
377 err("%s: no Sasem device present", __func__);
378 retval = -ENODEV;
379 goto exit;
380 }
381
382 if (n_bytes <= 0 || n_bytes > SASEM_DATA_BUF_SZ) {
383 err("%s: invalid payload size", __func__);
384 retval = -EINVAL;
385 goto exit;
386 }
387
388 data_buf = memdup_user(buf, n_bytes);
389 if (PTR_ERR(data_buf))
390 return PTR_ERR(data_buf);
391
392 memcpy(context->tx.data_buf, data_buf, n_bytes);
393
394 /* Pad with spaces */
395 for (i = n_bytes; i < SASEM_DATA_BUF_SZ; ++i)
396 context->tx.data_buf[i] = ' ';
397
398 /* Nine 8 byte packets to be sent */
399 /* NOTE: "\x07\x01\0\0\0\0\0\0" or "\x0c\0\0\0\0\0\0\0"
400 * will clear the VFD */
401 for (i = 0; i < 9; i++) {
402 switch (i) {
403 case 0:
404 memcpy(context->usb_tx_buf, "\x07\0\0\0\0\0\0\0", 8);
405 context->usb_tx_buf[1] = (context->vfd_contrast) ?
406 (0x2B - (context->vfd_contrast - 1) / 250)
407 : 0x2B;
408 break;
409 case 1:
410 memcpy(context->usb_tx_buf, "\x09\x01\0\0\0\0\0\0", 8);
411 break;
412 case 2:
413 memcpy(context->usb_tx_buf, "\x0b\x01\0\0\0\0\0\0", 8);
414 break;
415 case 3:
416 memcpy(context->usb_tx_buf, context->tx.data_buf, 8);
417 break;
418 case 4:
419 memcpy(context->usb_tx_buf,
420 context->tx.data_buf + 8, 8);
421 break;
422 case 5:
423 memcpy(context->usb_tx_buf, "\x09\x01\0\0\0\0\0\0", 8);
424 break;
425 case 6:
426 memcpy(context->usb_tx_buf, "\x0b\x02\0\0\0\0\0\0", 8);
427 break;
428 case 7:
429 memcpy(context->usb_tx_buf,
430 context->tx.data_buf + 16, 8);
431 break;
432 case 8:
433 memcpy(context->usb_tx_buf,
434 context->tx.data_buf + 24, 8);
435 break;
436 }
437 retval = send_packet(context);
438 if (retval) {
439
440 err("%s: send packet failed for packet #%d",
441 __func__, i);
442 goto exit;
443 }
444 }
445exit:
446
447 mutex_unlock(&context->ctx_lock);
448
449 return (!retval) ? n_bytes : retval;
450}
451
452/**
453 * Callback function for USB core API: transmit data
454 */
455static void usb_tx_callback(struct urb *urb)
456{
457 struct sasem_context *context;
458
459 if (!urb)
460 return;
461 context = (struct sasem_context *) urb->context;
462 if (!context)
463 return;
464
465 context->tx.status = urb->status;
466
467 /* notify waiters that write has finished */
468 atomic_set(&context->tx.busy, 0);
469 complete(&context->tx.finished);
470
471 return;
472}
473
474/**
475 * Called by lirc_dev when the application opens /dev/lirc
476 */
477static int ir_open(void *data)
478{
479 int retval = 0;
480 struct sasem_context *context;
481
482 /* prevent races with disconnect */
483 mutex_lock(&disconnect_lock);
484
485 context = (struct sasem_context *) data;
486
487 mutex_lock(&context->ctx_lock);
488
489 if (context->ir_isopen) {
490 err("%s: IR port is already open", __func__);
491 retval = -EBUSY;
492 goto exit;
493 }
494
495 usb_fill_int_urb(context->rx_urb, context->dev,
496 usb_rcvintpipe(context->dev,
497 context->rx_endpoint->bEndpointAddress),
498 context->usb_rx_buf, sizeof(context->usb_rx_buf),
499 usb_rx_callback, context, context->rx_endpoint->bInterval);
500
501 retval = usb_submit_urb(context->rx_urb, GFP_KERNEL);
502
503 if (retval)
504 err("%s: usb_submit_urb failed for ir_open (%d)",
505 __func__, retval);
506 else {
507 context->ir_isopen = 1;
508 printk(KERN_INFO "IR port opened\n");
509 }
510
511exit:
512 mutex_unlock(&context->ctx_lock);
513
514 mutex_unlock(&disconnect_lock);
515 return 0;
516}
517
518/**
519 * Called by lirc_dev when the application closes /dev/lirc
520 */
521static void ir_close(void *data)
522{
523 struct sasem_context *context;
524
525 context = (struct sasem_context *)data;
526 if (!context) {
527 err("%s: no context for device", __func__);
528 return;
529 }
530
531 mutex_lock(&context->ctx_lock);
532
533 usb_kill_urb(context->rx_urb);
534 context->ir_isopen = 0;
535 printk(KERN_INFO "IR port closed\n");
536
537 if (!context->dev_present) {
538
539 /*
540 * Device disconnected while IR port was
541 * still open. Driver was not deregistered
542 * at disconnect time, so do it now.
543 */
544 deregister_from_lirc(context);
545
546 if (!context->vfd_isopen) {
547
548 mutex_unlock(&context->ctx_lock);
549 delete_context(context);
550 return;
551 }
552 /* If VFD port is open, context will be deleted by vfd_close */
553 }
554
555 mutex_unlock(&context->ctx_lock);
556 return;
557}
558
559/**
560 * Process the incoming packet
561 */
562static void incoming_packet(struct sasem_context *context,
563 struct urb *urb)
564{
565 int len = urb->actual_length;
566 unsigned char *buf = urb->transfer_buffer;
567 long ms;
568 struct timeval tv;
569
570 if (len != 8) {
571 printk(KERN_WARNING "%s: invalid incoming packet size (%d)\n",
572 __func__, len);
573 return;
574 }
575
576#ifdef DEBUG
577 int i;
578 for (i = 0; i < 8; ++i)
579 printk(KERN_INFO "%02x ", buf[i]);
580 printk(KERN_INFO "\n");
581#endif
582
583 /*
584 * Lirc could deal with the repeat code, but we really need to block it
585 * if it arrives too late. Otherwise we could repeat the wrong code.
586 */
587
588 /* get the time since the last button press */
589 do_gettimeofday(&tv);
590 ms = (tv.tv_sec - context->presstime.tv_sec) * 1000 +
591 (tv.tv_usec - context->presstime.tv_usec) / 1000;
592
593 if (memcmp(buf, "\x08\0\0\0\0\0\0\0", 8) == 0) {
594 /*
595 * the repeat code is being sent, so we copy
596 * the old code to LIRC
597 */
598
599 /*
600 * NOTE: Only if the last code was less than 250ms ago
601 * - no one should be able to push another (undetected) button
602 * in that time and then get a false repeat of the previous
603 * press but it is long enough for a genuine repeat
604 */
605 if ((ms < 250) && (context->codesaved != 0)) {
606 memcpy(buf, &context->lastcode, 8);
607 context->presstime.tv_sec = tv.tv_sec;
608 context->presstime.tv_usec = tv.tv_usec;
609 }
610 } else {
611 /* save the current valid code for repeats */
612 memcpy(&context->lastcode, buf, 8);
613 /*
614 * set flag to signal a valid code was save;
615 * just for safety reasons
616 */
617 context->codesaved = 1;
618 context->presstime.tv_sec = tv.tv_sec;
619 context->presstime.tv_usec = tv.tv_usec;
620 }
621
622 lirc_buffer_write(context->driver->rbuf, buf);
623 wake_up(&context->driver->rbuf->wait_poll);
624}
625
626/**
627 * Callback function for USB core API: receive data
628 */
629static void usb_rx_callback(struct urb *urb)
630{
631 struct sasem_context *context;
632
633 if (!urb)
634 return;
635 context = (struct sasem_context *) urb->context;
636 if (!context)
637 return;
638
639 switch (urb->status) {
640
641 case -ENOENT: /* usbcore unlink successful! */
642 return;
643
644 case 0:
645 if (context->ir_isopen)
646 incoming_packet(context, urb);
647 break;
648
649 default:
650 printk(KERN_WARNING "%s: status (%d): ignored",
651 __func__, urb->status);
652 break;
653 }
654
655 usb_submit_urb(context->rx_urb, GFP_ATOMIC);
656 return;
657}
658
659
660
661/**
662 * Callback function for USB core API: Probe
663 */
664static int sasem_probe(struct usb_interface *interface,
665 const struct usb_device_id *id)
666{
667 struct usb_device *dev = NULL;
668 struct usb_host_interface *iface_desc = NULL;
669 struct usb_endpoint_descriptor *rx_endpoint = NULL;
670 struct usb_endpoint_descriptor *tx_endpoint = NULL;
671 struct urb *rx_urb = NULL;
672 struct urb *tx_urb = NULL;
673 struct lirc_driver *driver = NULL;
674 struct lirc_buffer *rbuf = NULL;
675 int lirc_minor = 0;
676 int num_endpoints;
677 int retval = 0;
678 int vfd_ep_found;
679 int ir_ep_found;
680 int alloc_status;
681 struct sasem_context *context = NULL;
682 int i;
683
684 printk(KERN_INFO "%s: found Sasem device\n", __func__);
685
686
687 dev = usb_get_dev(interface_to_usbdev(interface));
688 iface_desc = interface->cur_altsetting;
689 num_endpoints = iface_desc->desc.bNumEndpoints;
690
691 /*
692 * Scan the endpoint list and set:
693 * first input endpoint = IR endpoint
694 * first output endpoint = VFD endpoint
695 */
696
697 ir_ep_found = 0;
698 vfd_ep_found = 0;
699
700 for (i = 0; i < num_endpoints && !(ir_ep_found && vfd_ep_found); ++i) {
701
702 struct usb_endpoint_descriptor *ep;
703 int ep_dir;
704 int ep_type;
705 ep = &iface_desc->endpoint [i].desc;
706 ep_dir = ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK;
707 ep_type = ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
708
709 if (!ir_ep_found &&
710 ep_dir == USB_DIR_IN &&
711 ep_type == USB_ENDPOINT_XFER_INT) {
712
713 rx_endpoint = ep;
714 ir_ep_found = 1;
715 if (debug)
716 printk(KERN_INFO "%s: found IR endpoint\n",
717 __func__);
718
719 } else if (!vfd_ep_found &&
720 ep_dir == USB_DIR_OUT &&
721 ep_type == USB_ENDPOINT_XFER_INT) {
722
723 tx_endpoint = ep;
724 vfd_ep_found = 1;
725 if (debug)
726 printk(KERN_INFO "%s: found VFD endpoint\n",
727 __func__);
728 }
729 }
730
731 /* Input endpoint is mandatory */
732 if (!ir_ep_found) {
733
734 err("%s: no valid input (IR) endpoint found.", __func__);
735 retval = -ENODEV;
736 goto exit;
737 }
738
739 if (!vfd_ep_found)
740 printk(KERN_INFO "%s: no valid output (VFD) endpoint found.\n",
741 __func__);
742
743
744 /* Allocate memory */
745 alloc_status = 0;
746
747 context = kzalloc(sizeof(struct sasem_context), GFP_KERNEL);
748 if (!context) {
749 err("%s: kzalloc failed for context", __func__);
750 alloc_status = 1;
751 goto alloc_status_switch;
752 }
753 driver = kzalloc(sizeof(struct lirc_driver), GFP_KERNEL);
754 if (!driver) {
755 err("%s: kzalloc failed for lirc_driver", __func__);
756 alloc_status = 2;
757 goto alloc_status_switch;
758 }
759 rbuf = kmalloc(sizeof(struct lirc_buffer), GFP_KERNEL);
760 if (!rbuf) {
761 err("%s: kmalloc failed for lirc_buffer", __func__);
762 alloc_status = 3;
763 goto alloc_status_switch;
764 }
765 if (lirc_buffer_init(rbuf, BUF_CHUNK_SIZE, BUF_SIZE)) {
766 err("%s: lirc_buffer_init failed", __func__);
767 alloc_status = 4;
768 goto alloc_status_switch;
769 }
770 rx_urb = usb_alloc_urb(0, GFP_KERNEL);
771 if (!rx_urb) {
772 err("%s: usb_alloc_urb failed for IR urb", __func__);
773 alloc_status = 5;
774 goto alloc_status_switch;
775 }
776 if (vfd_ep_found) {
777 tx_urb = usb_alloc_urb(0, GFP_KERNEL);
778 if (!tx_urb) {
779 err("%s: usb_alloc_urb failed for VFD urb",
780 __func__);
781 alloc_status = 6;
782 goto alloc_status_switch;
783 }
784 }
785
786 mutex_init(&context->ctx_lock);
787
788 strcpy(driver->name, MOD_NAME);
789 driver->minor = -1;
790 driver->code_length = 64;
791 driver->sample_rate = 0;
792 driver->features = LIRC_CAN_REC_LIRCCODE;
793 driver->data = context;
794 driver->rbuf = rbuf;
795 driver->set_use_inc = ir_open;
796 driver->set_use_dec = ir_close;
797 driver->dev = &interface->dev;
798 driver->owner = THIS_MODULE;
799
800 mutex_lock(&context->ctx_lock);
801
802 lirc_minor = lirc_register_driver(driver);
803 if (lirc_minor < 0) {
804 err("%s: lirc_register_driver failed", __func__);
805 alloc_status = 7;
806 mutex_unlock(&context->ctx_lock);
807 } else
808 printk(KERN_INFO "%s: Registered Sasem driver (minor:%d)\n",
809 __func__, lirc_minor);
810
811alloc_status_switch:
812
813 switch (alloc_status) {
814
815 case 7:
816 if (vfd_ep_found)
817 usb_free_urb(tx_urb);
818 case 6:
819 usb_free_urb(rx_urb);
820 case 5:
821 lirc_buffer_free(rbuf);
822 case 4:
823 kfree(rbuf);
824 case 3:
825 kfree(driver);
826 case 2:
827 kfree(context);
828 context = NULL;
829 case 1:
830 retval = -ENOMEM;
831 goto exit;
832 }
833
834 /* Needed while unregistering! */
835 driver->minor = lirc_minor;
836
837 context->dev = dev;
838 context->dev_present = 1;
839 context->rx_endpoint = rx_endpoint;
840 context->rx_urb = rx_urb;
841 if (vfd_ep_found) {
842 context->tx_endpoint = tx_endpoint;
843 context->tx_urb = tx_urb;
844 context->vfd_contrast = 1000; /* range 0 - 1000 */
845 }
846 context->driver = driver;
847
848 usb_set_intfdata(interface, context);
849
850 if (vfd_ep_found) {
851
852 if (debug)
853 printk(KERN_INFO "Registering VFD with sysfs\n");
854 if (usb_register_dev(interface, &sasem_class))
855 /* Not a fatal error, so ignore */
856 printk(KERN_INFO "%s: could not get a minor number "
857 "for VFD\n", __func__);
858 }
859
860 printk(KERN_INFO "%s: Sasem device on usb<%d:%d> initialized\n",
861 __func__, dev->bus->busnum, dev->devnum);
862
863 mutex_unlock(&context->ctx_lock);
864exit:
865 return retval;
866}
867
868/**
869 * Callback function for USB core API: disonnect
870 */
871static void sasem_disconnect(struct usb_interface *interface)
872{
873 struct sasem_context *context;
874
875 /* prevent races with ir_open()/vfd_open() */
876 mutex_lock(&disconnect_lock);
877
878 context = usb_get_intfdata(interface);
879 mutex_lock(&context->ctx_lock);
880
881 printk(KERN_INFO "%s: Sasem device disconnected\n", __func__);
882
883 usb_set_intfdata(interface, NULL);
884 context->dev_present = 0;
885
886 /* Stop reception */
887 usb_kill_urb(context->rx_urb);
888
889 /* Abort ongoing write */
890 if (atomic_read(&context->tx.busy)) {
891
892 usb_kill_urb(context->tx_urb);
893 wait_for_completion(&context->tx.finished);
894 }
895
896 /* De-register from lirc_dev if IR port is not open */
897 if (!context->ir_isopen)
898 deregister_from_lirc(context);
899
900 usb_deregister_dev(interface, &sasem_class);
901
902 mutex_unlock(&context->ctx_lock);
903
904 if (!context->ir_isopen && !context->vfd_isopen)
905 delete_context(context);
906
907 mutex_unlock(&disconnect_lock);
908}
909
910static int __init sasem_init(void)
911{
912 int rc;
913
914 printk(KERN_INFO MOD_DESC ", v" MOD_VERSION "\n");
915 printk(KERN_INFO MOD_AUTHOR "\n");
916
917 rc = usb_register(&sasem_driver);
918 if (rc < 0) {
919 err("%s: usb register failed (%d)", __func__, rc);
920 return -ENODEV;
921 }
922 return 0;
923}
924
925static void __exit sasem_exit(void)
926{
927 usb_deregister(&sasem_driver);
928 printk(KERN_INFO "module removed. Goodbye!\n");
929}
930
931
932module_init(sasem_init);
933module_exit(sasem_exit);
diff --git a/drivers/staging/lirc/lirc_serial.c b/drivers/staging/lirc/lirc_serial.c
new file mode 100644
index 000000000000..9456f8e3f9ef
--- /dev/null
+++ b/drivers/staging/lirc/lirc_serial.c
@@ -0,0 +1,1313 @@
1/*
2 * lirc_serial.c
3 *
4 * lirc_serial - Device driver that records pulse- and pause-lengths
5 * (space-lengths) between DDCD event on a serial port.
6 *
7 * Copyright (C) 1996,97 Ralph Metzler <rjkm@thp.uni-koeln.de>
8 * Copyright (C) 1998 Trent Piepho <xyzzy@u.washington.edu>
9 * Copyright (C) 1998 Ben Pfaff <blp@gnu.org>
10 * Copyright (C) 1999 Christoph Bartelmus <lirc@bartelmus.de>
11 * Copyright (C) 2007 Andrei Tanas <andrei@tanas.ca> (suspend/resume support)
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 */
27
28/*
29 * Steve's changes to improve transmission fidelity:
30 * - for systems with the rdtsc instruction and the clock counter, a
31 * send_pule that times the pulses directly using the counter.
32 * This means that the LIRC_SERIAL_TRANSMITTER_LATENCY fudge is
33 * not needed. Measurement shows very stable waveform, even where
34 * PCI activity slows the access to the UART, which trips up other
35 * versions.
36 * - For other system, non-integer-microsecond pulse/space lengths,
37 * done using fixed point binary. So, much more accurate carrier
38 * frequency.
39 * - fine tuned transmitter latency, taking advantage of fractional
40 * microseconds in previous change
41 * - Fixed bug in the way transmitter latency was accounted for by
42 * tuning the pulse lengths down - the send_pulse routine ignored
43 * this overhead as it timed the overall pulse length - so the
44 * pulse frequency was right but overall pulse length was too
45 * long. Fixed by accounting for latency on each pulse/space
46 * iteration.
47 *
48 * Steve Davies <steve@daviesfam.org> July 2001
49 */
50
51#include <linux/module.h>
52#include <linux/errno.h>
53#include <linux/signal.h>
54#include <linux/sched.h>
55#include <linux/fs.h>
56#include <linux/interrupt.h>
57#include <linux/ioport.h>
58#include <linux/kernel.h>
59#include <linux/serial_reg.h>
60#include <linux/time.h>
61#include <linux/string.h>
62#include <linux/types.h>
63#include <linux/wait.h>
64#include <linux/mm.h>
65#include <linux/delay.h>
66#include <linux/poll.h>
67#include <linux/platform_device.h>
68
69#include <asm/system.h>
70#include <linux/io.h>
71#include <linux/irq.h>
72#include <linux/fcntl.h>
73#include <linux/spinlock.h>
74
75#ifdef CONFIG_LIRC_SERIAL_NSLU2
76#include <asm/hardware.h>
77#endif
78/* From Intel IXP42X Developer's Manual (#252480-005): */
79/* ftp://download.intel.com/design/network/manuals/25248005.pdf */
80#define UART_IE_IXP42X_UUE 0x40 /* IXP42X UART Unit enable */
81#define UART_IE_IXP42X_RTOIE 0x10 /* IXP42X Receiver Data Timeout int.enable */
82
83#include <media/lirc.h>
84#include <media/lirc_dev.h>
85
86#define LIRC_DRIVER_NAME "lirc_serial"
87
88struct lirc_serial {
89 int signal_pin;
90 int signal_pin_change;
91 u8 on;
92 u8 off;
93 long (*send_pulse)(unsigned long length);
94 void (*send_space)(long length);
95 int features;
96 spinlock_t lock;
97};
98
99#define LIRC_HOMEBREW 0
100#define LIRC_IRDEO 1
101#define LIRC_IRDEO_REMOTE 2
102#define LIRC_ANIMAX 3
103#define LIRC_IGOR 4
104#define LIRC_NSLU2 5
105
106/*** module parameters ***/
107static int type;
108static int io;
109static int irq;
110static int iommap;
111static int ioshift;
112static int softcarrier = 1;
113static int share_irq;
114static int debug;
115static int sense = -1; /* -1 = auto, 0 = active high, 1 = active low */
116static int txsense; /* 0 = active high, 1 = active low */
117
118#define dprintk(fmt, args...) \
119 do { \
120 if (debug) \
121 printk(KERN_DEBUG LIRC_DRIVER_NAME ": " \
122 fmt, ## args); \
123 } while (0)
124
125/* forward declarations */
126static long send_pulse_irdeo(unsigned long length);
127static long send_pulse_homebrew(unsigned long length);
128static void send_space_irdeo(long length);
129static void send_space_homebrew(long length);
130
131static struct lirc_serial hardware[] = {
132 [LIRC_HOMEBREW] = {
133 .signal_pin = UART_MSR_DCD,
134 .signal_pin_change = UART_MSR_DDCD,
135 .on = (UART_MCR_RTS | UART_MCR_OUT2 | UART_MCR_DTR),
136 .off = (UART_MCR_RTS | UART_MCR_OUT2),
137 .send_pulse = send_pulse_homebrew,
138 .send_space = send_space_homebrew,
139#ifdef CONFIG_LIRC_SERIAL_TRANSMITTER
140 .features = (LIRC_CAN_SET_SEND_DUTY_CYCLE |
141 LIRC_CAN_SET_SEND_CARRIER |
142 LIRC_CAN_SEND_PULSE | LIRC_CAN_REC_MODE2)
143#else
144 .features = LIRC_CAN_REC_MODE2
145#endif
146 },
147
148 [LIRC_IRDEO] = {
149 .signal_pin = UART_MSR_DSR,
150 .signal_pin_change = UART_MSR_DDSR,
151 .on = UART_MCR_OUT2,
152 .off = (UART_MCR_RTS | UART_MCR_DTR | UART_MCR_OUT2),
153 .send_pulse = send_pulse_irdeo,
154 .send_space = send_space_irdeo,
155 .features = (LIRC_CAN_SET_SEND_DUTY_CYCLE |
156 LIRC_CAN_SEND_PULSE | LIRC_CAN_REC_MODE2)
157 },
158
159 [LIRC_IRDEO_REMOTE] = {
160 .signal_pin = UART_MSR_DSR,
161 .signal_pin_change = UART_MSR_DDSR,
162 .on = (UART_MCR_RTS | UART_MCR_DTR | UART_MCR_OUT2),
163 .off = (UART_MCR_RTS | UART_MCR_DTR | UART_MCR_OUT2),
164 .send_pulse = send_pulse_irdeo,
165 .send_space = send_space_irdeo,
166 .features = (LIRC_CAN_SET_SEND_DUTY_CYCLE |
167 LIRC_CAN_SEND_PULSE | LIRC_CAN_REC_MODE2)
168 },
169
170 [LIRC_ANIMAX] = {
171 .signal_pin = UART_MSR_DCD,
172 .signal_pin_change = UART_MSR_DDCD,
173 .on = 0,
174 .off = (UART_MCR_RTS | UART_MCR_DTR | UART_MCR_OUT2),
175 .send_pulse = NULL,
176 .send_space = NULL,
177 .features = LIRC_CAN_REC_MODE2
178 },
179
180 [LIRC_IGOR] = {
181 .signal_pin = UART_MSR_DSR,
182 .signal_pin_change = UART_MSR_DDSR,
183 .on = (UART_MCR_RTS | UART_MCR_OUT2 | UART_MCR_DTR),
184 .off = (UART_MCR_RTS | UART_MCR_OUT2),
185 .send_pulse = send_pulse_homebrew,
186 .send_space = send_space_homebrew,
187#ifdef CONFIG_LIRC_SERIAL_TRANSMITTER
188 .features = (LIRC_CAN_SET_SEND_DUTY_CYCLE |
189 LIRC_CAN_SET_SEND_CARRIER |
190 LIRC_CAN_SEND_PULSE | LIRC_CAN_REC_MODE2)
191#else
192 .features = LIRC_CAN_REC_MODE2
193#endif
194 },
195
196#ifdef CONFIG_LIRC_SERIAL_NSLU2
197 /*
198 * Modified Linksys Network Storage Link USB 2.0 (NSLU2):
199 * We receive on CTS of the 2nd serial port (R142,LHS), we
200 * transmit with a IR diode between GPIO[1] (green status LED),
201 * and ground (Matthias Goebl <matthias.goebl@goebl.net>).
202 * See also http://www.nslu2-linux.org for this device
203 */
204 [LIRC_NSLU2] = {
205 .signal_pin = UART_MSR_CTS,
206 .signal_pin_change = UART_MSR_DCTS,
207 .on = (UART_MCR_RTS | UART_MCR_OUT2 | UART_MCR_DTR),
208 .off = (UART_MCR_RTS | UART_MCR_OUT2),
209 .send_pulse = send_pulse_homebrew,
210 .send_space = send_space_homebrew,
211#ifdef CONFIG_LIRC_SERIAL_TRANSMITTER
212 .features = (LIRC_CAN_SET_SEND_DUTY_CYCLE |
213 LIRC_CAN_SET_SEND_CARRIER |
214 LIRC_CAN_SEND_PULSE | LIRC_CAN_REC_MODE2)
215#else
216 .features = LIRC_CAN_REC_MODE2
217#endif
218 },
219#endif
220
221};
222
223#define RS_ISR_PASS_LIMIT 256
224
225/*
226 * A long pulse code from a remote might take up to 300 bytes. The
227 * daemon should read the bytes as soon as they are generated, so take
228 * the number of keys you think you can push before the daemon runs
229 * and multiply by 300. The driver will warn you if you overrun this
230 * buffer. If you have a slow computer or non-busmastering IDE disks,
231 * maybe you will need to increase this.
232 */
233
234/* This MUST be a power of two! It has to be larger than 1 as well. */
235
236#define RBUF_LEN 256
237
238static struct timeval lasttv = {0, 0};
239
240static struct lirc_buffer rbuf;
241
242static unsigned int freq = 38000;
243static unsigned int duty_cycle = 50;
244
245/* Initialized in init_timing_params() */
246static unsigned long period;
247static unsigned long pulse_width;
248static unsigned long space_width;
249
250#if defined(__i386__)
251/*
252 * From:
253 * Linux I/O port programming mini-HOWTO
254 * Author: Riku Saikkonen <Riku.Saikkonen@hut.fi>
255 * v, 28 December 1997
256 *
257 * [...]
258 * Actually, a port I/O instruction on most ports in the 0-0x3ff range
259 * takes almost exactly 1 microsecond, so if you're, for example, using
260 * the parallel port directly, just do additional inb()s from that port
261 * to delay.
262 * [...]
263 */
264/* transmitter latency 1.5625us 0x1.90 - this figure arrived at from
265 * comment above plus trimming to match actual measured frequency.
266 * This will be sensitive to cpu speed, though hopefully most of the 1.5us
267 * is spent in the uart access. Still - for reference test machine was a
268 * 1.13GHz Athlon system - Steve
269 */
270
271/*
272 * changed from 400 to 450 as this works better on slower machines;
273 * faster machines will use the rdtsc code anyway
274 */
275#define LIRC_SERIAL_TRANSMITTER_LATENCY 450
276
277#else
278
279/* does anybody have information on other platforms ? */
280/* 256 = 1<<8 */
281#define LIRC_SERIAL_TRANSMITTER_LATENCY 256
282
283#endif /* __i386__ */
284/*
285 * FIXME: should we be using hrtimers instead of this
286 * LIRC_SERIAL_TRANSMITTER_LATENCY nonsense?
287 */
288
289/* fetch serial input packet (1 byte) from register offset */
290static u8 sinp(int offset)
291{
292 if (iommap != 0)
293 /* the register is memory-mapped */
294 offset <<= ioshift;
295
296 return inb(io + offset);
297}
298
299/* write serial output packet (1 byte) of value to register offset */
300static void soutp(int offset, u8 value)
301{
302 if (iommap != 0)
303 /* the register is memory-mapped */
304 offset <<= ioshift;
305
306 outb(value, io + offset);
307}
308
309static void on(void)
310{
311#ifdef CONFIG_LIRC_SERIAL_NSLU2
312 /*
313 * On NSLU2, we put the transmit diode between the output of the green
314 * status LED and ground
315 */
316 if (type == LIRC_NSLU2) {
317 gpio_line_set(NSLU2_LED_GRN, IXP4XX_GPIO_LOW);
318 return;
319 }
320#endif
321 if (txsense)
322 soutp(UART_MCR, hardware[type].off);
323 else
324 soutp(UART_MCR, hardware[type].on);
325}
326
327static void off(void)
328{
329#ifdef CONFIG_LIRC_SERIAL_NSLU2
330 if (type == LIRC_NSLU2) {
331 gpio_line_set(NSLU2_LED_GRN, IXP4XX_GPIO_HIGH);
332 return;
333 }
334#endif
335 if (txsense)
336 soutp(UART_MCR, hardware[type].on);
337 else
338 soutp(UART_MCR, hardware[type].off);
339}
340
341#ifndef MAX_UDELAY_MS
342#define MAX_UDELAY_US 5000
343#else
344#define MAX_UDELAY_US (MAX_UDELAY_MS*1000)
345#endif
346
347static void safe_udelay(unsigned long usecs)
348{
349 while (usecs > MAX_UDELAY_US) {
350 udelay(MAX_UDELAY_US);
351 usecs -= MAX_UDELAY_US;
352 }
353 udelay(usecs);
354}
355
356#ifdef USE_RDTSC
357/*
358 * This is an overflow/precision juggle, complicated in that we can't
359 * do long long divide in the kernel
360 */
361
362/*
363 * When we use the rdtsc instruction to measure clocks, we keep the
364 * pulse and space widths as clock cycles. As this is CPU speed
365 * dependent, the widths must be calculated in init_port and ioctl
366 * time
367 */
368
369/* So send_pulse can quickly convert microseconds to clocks */
370static unsigned long conv_us_to_clocks;
371
372static int init_timing_params(unsigned int new_duty_cycle,
373 unsigned int new_freq)
374{
375 unsigned long long loops_per_sec, work;
376
377 duty_cycle = new_duty_cycle;
378 freq = new_freq;
379
380 loops_per_sec = current_cpu_data.loops_per_jiffy;
381 loops_per_sec *= HZ;
382
383 /* How many clocks in a microsecond?, avoiding long long divide */
384 work = loops_per_sec;
385 work *= 4295; /* 4295 = 2^32 / 1e6 */
386 conv_us_to_clocks = (work >> 32);
387
388 /*
389 * Carrier period in clocks, approach good up to 32GHz clock,
390 * gets carrier frequency within 8Hz
391 */
392 period = loops_per_sec >> 3;
393 period /= (freq >> 3);
394
395 /* Derive pulse and space from the period */
396 pulse_width = period * duty_cycle / 100;
397 space_width = period - pulse_width;
398 dprintk("in init_timing_params, freq=%d, duty_cycle=%d, "
399 "clk/jiffy=%ld, pulse=%ld, space=%ld, "
400 "conv_us_to_clocks=%ld\n",
401 freq, duty_cycle, current_cpu_data.loops_per_jiffy,
402 pulse_width, space_width, conv_us_to_clocks);
403 return 0;
404}
405#else /* ! USE_RDTSC */
406static int init_timing_params(unsigned int new_duty_cycle,
407 unsigned int new_freq)
408{
409/*
410 * period, pulse/space width are kept with 8 binary places -
411 * IE multiplied by 256.
412 */
413 if (256 * 1000000L / new_freq * new_duty_cycle / 100 <=
414 LIRC_SERIAL_TRANSMITTER_LATENCY)
415 return -EINVAL;
416 if (256 * 1000000L / new_freq * (100 - new_duty_cycle) / 100 <=
417 LIRC_SERIAL_TRANSMITTER_LATENCY)
418 return -EINVAL;
419 duty_cycle = new_duty_cycle;
420 freq = new_freq;
421 period = 256 * 1000000L / freq;
422 pulse_width = period * duty_cycle / 100;
423 space_width = period - pulse_width;
424 dprintk("in init_timing_params, freq=%d pulse=%ld, "
425 "space=%ld\n", freq, pulse_width, space_width);
426 return 0;
427}
428#endif /* USE_RDTSC */
429
430
431/* return value: space length delta */
432
433static long send_pulse_irdeo(unsigned long length)
434{
435 long rawbits, ret;
436 int i;
437 unsigned char output;
438 unsigned char chunk, shifted;
439
440 /* how many bits have to be sent ? */
441 rawbits = length * 1152 / 10000;
442 if (duty_cycle > 50)
443 chunk = 3;
444 else
445 chunk = 1;
446 for (i = 0, output = 0x7f; rawbits > 0; rawbits -= 3) {
447 shifted = chunk << (i * 3);
448 shifted >>= 1;
449 output &= (~shifted);
450 i++;
451 if (i == 3) {
452 soutp(UART_TX, output);
453 while (!(sinp(UART_LSR) & UART_LSR_THRE))
454 ;
455 output = 0x7f;
456 i = 0;
457 }
458 }
459 if (i != 0) {
460 soutp(UART_TX, output);
461 while (!(sinp(UART_LSR) & UART_LSR_TEMT))
462 ;
463 }
464
465 if (i == 0)
466 ret = (-rawbits) * 10000 / 1152;
467 else
468 ret = (3 - i) * 3 * 10000 / 1152 + (-rawbits) * 10000 / 1152;
469
470 return ret;
471}
472
473#ifdef USE_RDTSC
474/* Version that uses Pentium rdtsc instruction to measure clocks */
475
476/*
477 * This version does sub-microsecond timing using rdtsc instruction,
478 * and does away with the fudged LIRC_SERIAL_TRANSMITTER_LATENCY
479 * Implicitly i586 architecture... - Steve
480 */
481
482static long send_pulse_homebrew_softcarrier(unsigned long length)
483{
484 int flag;
485 unsigned long target, start, now;
486
487 /* Get going quick as we can */
488 rdtscl(start);
489 on();
490 /* Convert length from microseconds to clocks */
491 length *= conv_us_to_clocks;
492 /* And loop till time is up - flipping at right intervals */
493 now = start;
494 target = pulse_width;
495 flag = 1;
496 /*
497 * FIXME: This looks like a hard busy wait, without even an occasional,
498 * polite, cpu_relax() call. There's got to be a better way?
499 *
500 * The i2c code has the result of a lot of bit-banging work, I wonder if
501 * there's something there which could be helpful here.
502 */
503 while ((now - start) < length) {
504 /* Delay till flip time */
505 do {
506 rdtscl(now);
507 } while ((now - start) < target);
508
509 /* flip */
510 if (flag) {
511 rdtscl(now);
512 off();
513 target += space_width;
514 } else {
515 rdtscl(now); on();
516 target += pulse_width;
517 }
518 flag = !flag;
519 }
520 rdtscl(now);
521 return ((now - start) - length) / conv_us_to_clocks;
522}
523#else /* ! USE_RDTSC */
524/* Version using udelay() */
525
526/*
527 * here we use fixed point arithmetic, with 8
528 * fractional bits. that gets us within 0.1% or so of the right average
529 * frequency, albeit with some jitter in pulse length - Steve
530 */
531
532/* To match 8 fractional bits used for pulse/space length */
533
534static long send_pulse_homebrew_softcarrier(unsigned long length)
535{
536 int flag;
537 unsigned long actual, target, d;
538 length <<= 8;
539
540 actual = 0; target = 0; flag = 0;
541 while (actual < length) {
542 if (flag) {
543 off();
544 target += space_width;
545 } else {
546 on();
547 target += pulse_width;
548 }
549 d = (target - actual -
550 LIRC_SERIAL_TRANSMITTER_LATENCY + 128) >> 8;
551 /*
552 * Note - we've checked in ioctl that the pulse/space
553 * widths are big enough so that d is > 0
554 */
555 udelay(d);
556 actual += (d << 8) + LIRC_SERIAL_TRANSMITTER_LATENCY;
557 flag = !flag;
558 }
559 return (actual-length) >> 8;
560}
561#endif /* USE_RDTSC */
562
563static long send_pulse_homebrew(unsigned long length)
564{
565 if (length <= 0)
566 return 0;
567
568 if (softcarrier)
569 return send_pulse_homebrew_softcarrier(length);
570 else {
571 on();
572 safe_udelay(length);
573 return 0;
574 }
575}
576
577static void send_space_irdeo(long length)
578{
579 if (length <= 0)
580 return;
581
582 safe_udelay(length);
583}
584
585static void send_space_homebrew(long length)
586{
587 off();
588 if (length <= 0)
589 return;
590 safe_udelay(length);
591}
592
593static void rbwrite(int l)
594{
595 if (lirc_buffer_full(&rbuf)) {
596 /* no new signals will be accepted */
597 dprintk("Buffer overrun\n");
598 return;
599 }
600 lirc_buffer_write(&rbuf, (void *)&l);
601}
602
603static void frbwrite(int l)
604{
605 /* simple noise filter */
606 static int pulse, space;
607 static unsigned int ptr;
608
609 if (ptr > 0 && (l & PULSE_BIT)) {
610 pulse += l & PULSE_MASK;
611 if (pulse > 250) {
612 rbwrite(space);
613 rbwrite(pulse | PULSE_BIT);
614 ptr = 0;
615 pulse = 0;
616 }
617 return;
618 }
619 if (!(l & PULSE_BIT)) {
620 if (ptr == 0) {
621 if (l > 20000) {
622 space = l;
623 ptr++;
624 return;
625 }
626 } else {
627 if (l > 20000) {
628 space += pulse;
629 if (space > PULSE_MASK)
630 space = PULSE_MASK;
631 space += l;
632 if (space > PULSE_MASK)
633 space = PULSE_MASK;
634 pulse = 0;
635 return;
636 }
637 rbwrite(space);
638 rbwrite(pulse | PULSE_BIT);
639 ptr = 0;
640 pulse = 0;
641 }
642 }
643 rbwrite(l);
644}
645
646static irqreturn_t irq_handler(int i, void *blah)
647{
648 struct timeval tv;
649 int counter, dcd;
650 u8 status;
651 long deltv;
652 int data;
653 static int last_dcd = -1;
654
655 if ((sinp(UART_IIR) & UART_IIR_NO_INT)) {
656 /* not our interrupt */
657 return IRQ_NONE;
658 }
659
660 counter = 0;
661 do {
662 counter++;
663 status = sinp(UART_MSR);
664 if (counter > RS_ISR_PASS_LIMIT) {
665 printk(KERN_WARNING LIRC_DRIVER_NAME ": AIEEEE: "
666 "We're caught!\n");
667 break;
668 }
669 if ((status & hardware[type].signal_pin_change)
670 && sense != -1) {
671 /* get current time */
672 do_gettimeofday(&tv);
673
674 /* New mode, written by Trent Piepho
675 <xyzzy@u.washington.edu>. */
676
677 /*
678 * The old format was not very portable.
679 * We now use an int to pass pulses
680 * and spaces to user space.
681 *
682 * If PULSE_BIT is set a pulse has been
683 * received, otherwise a space has been
684 * received. The driver needs to know if your
685 * receiver is active high or active low, or
686 * the space/pulse sense could be
687 * inverted. The bits denoted by PULSE_MASK are
688 * the length in microseconds. Lengths greater
689 * than or equal to 16 seconds are clamped to
690 * PULSE_MASK. All other bits are unused.
691 * This is a much simpler interface for user
692 * programs, as well as eliminating "out of
693 * phase" errors with space/pulse
694 * autodetection.
695 */
696
697 /* calc time since last interrupt in microseconds */
698 dcd = (status & hardware[type].signal_pin) ? 1 : 0;
699
700 if (dcd == last_dcd) {
701 printk(KERN_WARNING LIRC_DRIVER_NAME
702 ": ignoring spike: %d %d %lx %lx %lx %lx\n",
703 dcd, sense,
704 tv.tv_sec, lasttv.tv_sec,
705 tv.tv_usec, lasttv.tv_usec);
706 continue;
707 }
708
709 deltv = tv.tv_sec-lasttv.tv_sec;
710 if (tv.tv_sec < lasttv.tv_sec ||
711 (tv.tv_sec == lasttv.tv_sec &&
712 tv.tv_usec < lasttv.tv_usec)) {
713 printk(KERN_WARNING LIRC_DRIVER_NAME
714 ": AIEEEE: your clock just jumped "
715 "backwards\n");
716 printk(KERN_WARNING LIRC_DRIVER_NAME
717 ": %d %d %lx %lx %lx %lx\n",
718 dcd, sense,
719 tv.tv_sec, lasttv.tv_sec,
720 tv.tv_usec, lasttv.tv_usec);
721 data = PULSE_MASK;
722 } else if (deltv > 15) {
723 data = PULSE_MASK; /* really long time */
724 if (!(dcd^sense)) {
725 /* sanity check */
726 printk(KERN_WARNING LIRC_DRIVER_NAME
727 ": AIEEEE: "
728 "%d %d %lx %lx %lx %lx\n",
729 dcd, sense,
730 tv.tv_sec, lasttv.tv_sec,
731 tv.tv_usec, lasttv.tv_usec);
732 /*
733 * detecting pulse while this
734 * MUST be a space!
735 */
736 sense = sense ? 0 : 1;
737 }
738 } else
739 data = (int) (deltv*1000000 +
740 tv.tv_usec -
741 lasttv.tv_usec);
742 frbwrite(dcd^sense ? data : (data|PULSE_BIT));
743 lasttv = tv;
744 last_dcd = dcd;
745 wake_up_interruptible(&rbuf.wait_poll);
746 }
747 } while (!(sinp(UART_IIR) & UART_IIR_NO_INT)); /* still pending ? */
748 return IRQ_HANDLED;
749}
750
751
752static int hardware_init_port(void)
753{
754 u8 scratch, scratch2, scratch3;
755
756 /*
757 * This is a simple port existence test, borrowed from the autoconfig
758 * function in drivers/serial/8250.c
759 */
760 scratch = sinp(UART_IER);
761 soutp(UART_IER, 0);
762#ifdef __i386__
763 outb(0xff, 0x080);
764#endif
765 scratch2 = sinp(UART_IER) & 0x0f;
766 soutp(UART_IER, 0x0f);
767#ifdef __i386__
768 outb(0x00, 0x080);
769#endif
770 scratch3 = sinp(UART_IER) & 0x0f;
771 soutp(UART_IER, scratch);
772 if (scratch2 != 0 || scratch3 != 0x0f) {
773 /* we fail, there's nothing here */
774 printk(KERN_ERR LIRC_DRIVER_NAME ": port existence test "
775 "failed, cannot continue\n");
776 return -EINVAL;
777 }
778
779
780
781 /* Set DLAB 0. */
782 soutp(UART_LCR, sinp(UART_LCR) & (~UART_LCR_DLAB));
783
784 /* First of all, disable all interrupts */
785 soutp(UART_IER, sinp(UART_IER) &
786 (~(UART_IER_MSI|UART_IER_RLSI|UART_IER_THRI|UART_IER_RDI)));
787
788 /* Clear registers. */
789 sinp(UART_LSR);
790 sinp(UART_RX);
791 sinp(UART_IIR);
792 sinp(UART_MSR);
793
794#ifdef CONFIG_LIRC_SERIAL_NSLU2
795 if (type == LIRC_NSLU2) {
796 /* Setup NSLU2 UART */
797
798 /* Enable UART */
799 soutp(UART_IER, sinp(UART_IER) | UART_IE_IXP42X_UUE);
800 /* Disable Receiver data Time out interrupt */
801 soutp(UART_IER, sinp(UART_IER) & ~UART_IE_IXP42X_RTOIE);
802 /* set out2 = interrupt unmask; off() doesn't set MCR
803 on NSLU2 */
804 soutp(UART_MCR, UART_MCR_RTS|UART_MCR_OUT2);
805 }
806#endif
807
808 /* Set line for power source */
809 off();
810
811 /* Clear registers again to be sure. */
812 sinp(UART_LSR);
813 sinp(UART_RX);
814 sinp(UART_IIR);
815 sinp(UART_MSR);
816
817 switch (type) {
818 case LIRC_IRDEO:
819 case LIRC_IRDEO_REMOTE:
820 /* setup port to 7N1 @ 115200 Baud */
821 /* 7N1+start = 9 bits at 115200 ~ 3 bits at 38kHz */
822
823 /* Set DLAB 1. */
824 soutp(UART_LCR, sinp(UART_LCR) | UART_LCR_DLAB);
825 /* Set divisor to 1 => 115200 Baud */
826 soutp(UART_DLM, 0);
827 soutp(UART_DLL, 1);
828 /* Set DLAB 0 + 7N1 */
829 soutp(UART_LCR, UART_LCR_WLEN7);
830 /* THR interrupt already disabled at this point */
831 break;
832 default:
833 break;
834 }
835
836 return 0;
837}
838
839static int init_port(void)
840{
841 int i, nlow, nhigh;
842
843 /* Reserve io region. */
844 /*
845 * Future MMAP-Developers: Attention!
846 * For memory mapped I/O you *might* need to use ioremap() first,
847 * for the NSLU2 it's done in boot code.
848 */
849 if (((iommap != 0)
850 && (request_mem_region(iommap, 8 << ioshift,
851 LIRC_DRIVER_NAME) == NULL))
852 || ((iommap == 0)
853 && (request_region(io, 8, LIRC_DRIVER_NAME) == NULL))) {
854 printk(KERN_ERR LIRC_DRIVER_NAME
855 ": port %04x already in use\n", io);
856 printk(KERN_WARNING LIRC_DRIVER_NAME
857 ": use 'setserial /dev/ttySX uart none'\n");
858 printk(KERN_WARNING LIRC_DRIVER_NAME
859 ": or compile the serial port driver as module and\n");
860 printk(KERN_WARNING LIRC_DRIVER_NAME
861 ": make sure this module is loaded first\n");
862 return -EBUSY;
863 }
864
865 if (hardware_init_port() < 0)
866 return -EINVAL;
867
868 /* Initialize pulse/space widths */
869 init_timing_params(duty_cycle, freq);
870
871 /* If pin is high, then this must be an active low receiver. */
872 if (sense == -1) {
873 /* wait 1/2 sec for the power supply */
874 msleep(500);
875
876 /*
877 * probe 9 times every 0.04s, collect "votes" for
878 * active high/low
879 */
880 nlow = 0;
881 nhigh = 0;
882 for (i = 0; i < 9; i++) {
883 if (sinp(UART_MSR) & hardware[type].signal_pin)
884 nlow++;
885 else
886 nhigh++;
887 msleep(40);
888 }
889 sense = (nlow >= nhigh ? 1 : 0);
890 printk(KERN_INFO LIRC_DRIVER_NAME ": auto-detected active "
891 "%s receiver\n", sense ? "low" : "high");
892 } else
893 printk(KERN_INFO LIRC_DRIVER_NAME ": Manually using active "
894 "%s receiver\n", sense ? "low" : "high");
895
896 return 0;
897}
898
899static int set_use_inc(void *data)
900{
901 int result;
902 unsigned long flags;
903
904 /* initialize timestamp */
905 do_gettimeofday(&lasttv);
906
907 result = request_irq(irq, irq_handler,
908 IRQF_DISABLED | (share_irq ? IRQF_SHARED : 0),
909 LIRC_DRIVER_NAME, (void *)&hardware);
910
911 switch (result) {
912 case -EBUSY:
913 printk(KERN_ERR LIRC_DRIVER_NAME ": IRQ %d busy\n", irq);
914 return -EBUSY;
915 case -EINVAL:
916 printk(KERN_ERR LIRC_DRIVER_NAME
917 ": Bad irq number or handler\n");
918 return -EINVAL;
919 default:
920 dprintk("Interrupt %d, port %04x obtained\n", irq, io);
921 break;
922 };
923
924 spin_lock_irqsave(&hardware[type].lock, flags);
925
926 /* Set DLAB 0. */
927 soutp(UART_LCR, sinp(UART_LCR) & (~UART_LCR_DLAB));
928
929 soutp(UART_IER, sinp(UART_IER)|UART_IER_MSI);
930
931 spin_unlock_irqrestore(&hardware[type].lock, flags);
932
933 return 0;
934}
935
936static void set_use_dec(void *data)
937{ unsigned long flags;
938
939 spin_lock_irqsave(&hardware[type].lock, flags);
940
941 /* Set DLAB 0. */
942 soutp(UART_LCR, sinp(UART_LCR) & (~UART_LCR_DLAB));
943
944 /* First of all, disable all interrupts */
945 soutp(UART_IER, sinp(UART_IER) &
946 (~(UART_IER_MSI|UART_IER_RLSI|UART_IER_THRI|UART_IER_RDI)));
947 spin_unlock_irqrestore(&hardware[type].lock, flags);
948
949 free_irq(irq, (void *)&hardware);
950
951 dprintk("freed IRQ %d\n", irq);
952}
953
954static ssize_t lirc_write(struct file *file, const char *buf,
955 size_t n, loff_t *ppos)
956{
957 int i, count;
958 unsigned long flags;
959 long delta = 0;
960 int *wbuf;
961
962 if (!(hardware[type].features & LIRC_CAN_SEND_PULSE))
963 return -EBADF;
964
965 count = n / sizeof(int);
966 if (n % sizeof(int) || count % 2 == 0)
967 return -EINVAL;
968 wbuf = memdup_user(buf, n);
969 if (PTR_ERR(wbuf))
970 return PTR_ERR(wbuf);
971 spin_lock_irqsave(&hardware[type].lock, flags);
972 if (type == LIRC_IRDEO) {
973 /* DTR, RTS down */
974 on();
975 }
976 for (i = 0; i < count; i++) {
977 if (i%2)
978 hardware[type].send_space(wbuf[i] - delta);
979 else
980 delta = hardware[type].send_pulse(wbuf[i]);
981 }
982 off();
983 spin_unlock_irqrestore(&hardware[type].lock, flags);
984 return n;
985}
986
987static long lirc_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
988{
989 int result;
990 unsigned long value;
991 unsigned int ivalue;
992
993 switch (cmd) {
994 case LIRC_GET_SEND_MODE:
995 if (!(hardware[type].features&LIRC_CAN_SEND_MASK))
996 return -ENOIOCTLCMD;
997
998 result = put_user(LIRC_SEND2MODE
999 (hardware[type].features&LIRC_CAN_SEND_MASK),
1000 (unsigned long *) arg);
1001 if (result)
1002 return result;
1003 break;
1004
1005 case LIRC_SET_SEND_MODE:
1006 if (!(hardware[type].features&LIRC_CAN_SEND_MASK))
1007 return -ENOIOCTLCMD;
1008
1009 result = get_user(value, (unsigned long *) arg);
1010 if (result)
1011 return result;
1012 /* only LIRC_MODE_PULSE supported */
1013 if (value != LIRC_MODE_PULSE)
1014 return -ENOSYS;
1015 break;
1016
1017 case LIRC_GET_LENGTH:
1018 return -ENOSYS;
1019 break;
1020
1021 case LIRC_SET_SEND_DUTY_CYCLE:
1022 dprintk("SET_SEND_DUTY_CYCLE\n");
1023 if (!(hardware[type].features&LIRC_CAN_SET_SEND_DUTY_CYCLE))
1024 return -ENOIOCTLCMD;
1025
1026 result = get_user(ivalue, (unsigned int *) arg);
1027 if (result)
1028 return result;
1029 if (ivalue <= 0 || ivalue > 100)
1030 return -EINVAL;
1031 return init_timing_params(ivalue, freq);
1032 break;
1033
1034 case LIRC_SET_SEND_CARRIER:
1035 dprintk("SET_SEND_CARRIER\n");
1036 if (!(hardware[type].features&LIRC_CAN_SET_SEND_CARRIER))
1037 return -ENOIOCTLCMD;
1038
1039 result = get_user(ivalue, (unsigned int *) arg);
1040 if (result)
1041 return result;
1042 if (ivalue > 500000 || ivalue < 20000)
1043 return -EINVAL;
1044 return init_timing_params(duty_cycle, ivalue);
1045 break;
1046
1047 default:
1048 return lirc_dev_fop_ioctl(filep, cmd, arg);
1049 }
1050 return 0;
1051}
1052
1053static const struct file_operations lirc_fops = {
1054 .owner = THIS_MODULE,
1055 .write = lirc_write,
1056 .unlocked_ioctl = lirc_ioctl,
1057 .read = lirc_dev_fop_read,
1058 .poll = lirc_dev_fop_poll,
1059 .open = lirc_dev_fop_open,
1060 .release = lirc_dev_fop_close,
1061};
1062
1063static struct lirc_driver driver = {
1064 .name = LIRC_DRIVER_NAME,
1065 .minor = -1,
1066 .code_length = 1,
1067 .sample_rate = 0,
1068 .data = NULL,
1069 .add_to_buf = NULL,
1070 .rbuf = &rbuf,
1071 .set_use_inc = set_use_inc,
1072 .set_use_dec = set_use_dec,
1073 .fops = &lirc_fops,
1074 .dev = NULL,
1075 .owner = THIS_MODULE,
1076};
1077
1078static struct platform_device *lirc_serial_dev;
1079
1080static int __devinit lirc_serial_probe(struct platform_device *dev)
1081{
1082 return 0;
1083}
1084
1085static int __devexit lirc_serial_remove(struct platform_device *dev)
1086{
1087 return 0;
1088}
1089
1090static int lirc_serial_suspend(struct platform_device *dev,
1091 pm_message_t state)
1092{
1093 /* Set DLAB 0. */
1094 soutp(UART_LCR, sinp(UART_LCR) & (~UART_LCR_DLAB));
1095
1096 /* Disable all interrupts */
1097 soutp(UART_IER, sinp(UART_IER) &
1098 (~(UART_IER_MSI|UART_IER_RLSI|UART_IER_THRI|UART_IER_RDI)));
1099
1100 /* Clear registers. */
1101 sinp(UART_LSR);
1102 sinp(UART_RX);
1103 sinp(UART_IIR);
1104 sinp(UART_MSR);
1105
1106 return 0;
1107}
1108
1109/* twisty maze... need a forward-declaration here... */
1110static void lirc_serial_exit(void);
1111
1112static int lirc_serial_resume(struct platform_device *dev)
1113{
1114 unsigned long flags;
1115
1116 if (hardware_init_port() < 0) {
1117 lirc_serial_exit();
1118 return -EINVAL;
1119 }
1120
1121 spin_lock_irqsave(&hardware[type].lock, flags);
1122 /* Enable Interrupt */
1123 do_gettimeofday(&lasttv);
1124 soutp(UART_IER, sinp(UART_IER)|UART_IER_MSI);
1125 off();
1126
1127 lirc_buffer_clear(&rbuf);
1128
1129 spin_unlock_irqrestore(&hardware[type].lock, flags);
1130
1131 return 0;
1132}
1133
1134static struct platform_driver lirc_serial_driver = {
1135 .probe = lirc_serial_probe,
1136 .remove = __devexit_p(lirc_serial_remove),
1137 .suspend = lirc_serial_suspend,
1138 .resume = lirc_serial_resume,
1139 .driver = {
1140 .name = "lirc_serial",
1141 .owner = THIS_MODULE,
1142 },
1143};
1144
1145static int __init lirc_serial_init(void)
1146{
1147 int result;
1148
1149 /* Init read buffer. */
1150 result = lirc_buffer_init(&rbuf, sizeof(int), RBUF_LEN);
1151 if (result < 0)
1152 return -ENOMEM;
1153
1154 result = platform_driver_register(&lirc_serial_driver);
1155 if (result) {
1156 printk("lirc register returned %d\n", result);
1157 goto exit_buffer_free;
1158 }
1159
1160 lirc_serial_dev = platform_device_alloc("lirc_serial", 0);
1161 if (!lirc_serial_dev) {
1162 result = -ENOMEM;
1163 goto exit_driver_unregister;
1164 }
1165
1166 result = platform_device_add(lirc_serial_dev);
1167 if (result)
1168 goto exit_device_put;
1169
1170 return 0;
1171
1172exit_device_put:
1173 platform_device_put(lirc_serial_dev);
1174exit_driver_unregister:
1175 platform_driver_unregister(&lirc_serial_driver);
1176exit_buffer_free:
1177 lirc_buffer_free(&rbuf);
1178 return result;
1179}
1180
1181static void lirc_serial_exit(void)
1182{
1183 platform_device_unregister(lirc_serial_dev);
1184 platform_driver_unregister(&lirc_serial_driver);
1185 lirc_buffer_free(&rbuf);
1186}
1187
1188static int __init lirc_serial_init_module(void)
1189{
1190 int result;
1191
1192 result = lirc_serial_init();
1193 if (result)
1194 return result;
1195
1196 switch (type) {
1197 case LIRC_HOMEBREW:
1198 case LIRC_IRDEO:
1199 case LIRC_IRDEO_REMOTE:
1200 case LIRC_ANIMAX:
1201 case LIRC_IGOR:
1202 /* if nothing specified, use ttyS0/com1 and irq 4 */
1203 io = io ? io : 0x3f8;
1204 irq = irq ? irq : 4;
1205 break;
1206#ifdef CONFIG_LIRC_SERIAL_NSLU2
1207 case LIRC_NSLU2:
1208 io = io ? io : IRQ_IXP4XX_UART2;
1209 irq = irq ? irq : (IXP4XX_UART2_BASE_VIRT + REG_OFFSET);
1210 iommap = iommap ? iommap : IXP4XX_UART2_BASE_PHYS;
1211 ioshift = ioshift ? ioshift : 2;
1212 break;
1213#endif
1214 default:
1215 result = -EINVAL;
1216 goto exit_serial_exit;
1217 }
1218 if (!softcarrier) {
1219 switch (type) {
1220 case LIRC_HOMEBREW:
1221 case LIRC_IGOR:
1222#ifdef CONFIG_LIRC_SERIAL_NSLU2
1223 case LIRC_NSLU2:
1224#endif
1225 hardware[type].features &=
1226 ~(LIRC_CAN_SET_SEND_DUTY_CYCLE|
1227 LIRC_CAN_SET_SEND_CARRIER);
1228 break;
1229 }
1230 }
1231
1232 result = init_port();
1233 if (result < 0)
1234 goto exit_serial_exit;
1235 driver.features = hardware[type].features;
1236 driver.dev = &lirc_serial_dev->dev;
1237 driver.minor = lirc_register_driver(&driver);
1238 if (driver.minor < 0) {
1239 printk(KERN_ERR LIRC_DRIVER_NAME
1240 ": register_chrdev failed!\n");
1241 result = -EIO;
1242 goto exit_release;
1243 }
1244 return 0;
1245exit_release:
1246 release_region(io, 8);
1247exit_serial_exit:
1248 lirc_serial_exit();
1249 return result;
1250}
1251
1252static void __exit lirc_serial_exit_module(void)
1253{
1254 lirc_serial_exit();
1255 if (iommap != 0)
1256 release_mem_region(iommap, 8 << ioshift);
1257 else
1258 release_region(io, 8);
1259 lirc_unregister_driver(driver.minor);
1260 dprintk("cleaned up module\n");
1261}
1262
1263
1264module_init(lirc_serial_init_module);
1265module_exit(lirc_serial_exit_module);
1266
1267MODULE_DESCRIPTION("Infra-red receiver driver for serial ports.");
1268MODULE_AUTHOR("Ralph Metzler, Trent Piepho, Ben Pfaff, "
1269 "Christoph Bartelmus, Andrei Tanas");
1270MODULE_LICENSE("GPL");
1271
1272module_param(type, int, S_IRUGO);
1273MODULE_PARM_DESC(type, "Hardware type (0 = home-brew, 1 = IRdeo,"
1274 " 2 = IRdeo Remote, 3 = AnimaX, 4 = IgorPlug,"
1275 " 5 = NSLU2 RX:CTS2/TX:GreenLED)");
1276
1277module_param(io, int, S_IRUGO);
1278MODULE_PARM_DESC(io, "I/O address base (0x3f8 or 0x2f8)");
1279
1280/* some architectures (e.g. intel xscale) have memory mapped registers */
1281module_param(iommap, bool, S_IRUGO);
1282MODULE_PARM_DESC(iommap, "physical base for memory mapped I/O"
1283 " (0 = no memory mapped io)");
1284
1285/*
1286 * some architectures (e.g. intel xscale) align the 8bit serial registers
1287 * on 32bit word boundaries.
1288 * See linux-kernel/serial/8250.c serial_in()/out()
1289 */
1290module_param(ioshift, int, S_IRUGO);
1291MODULE_PARM_DESC(ioshift, "shift I/O register offset (0 = no shift)");
1292
1293module_param(irq, int, S_IRUGO);
1294MODULE_PARM_DESC(irq, "Interrupt (4 or 3)");
1295
1296module_param(share_irq, bool, S_IRUGO);
1297MODULE_PARM_DESC(share_irq, "Share interrupts (0 = off, 1 = on)");
1298
1299module_param(sense, bool, S_IRUGO);
1300MODULE_PARM_DESC(sense, "Override autodetection of IR receiver circuit"
1301 " (0 = active high, 1 = active low )");
1302
1303#ifdef CONFIG_LIRC_SERIAL_TRANSMITTER
1304module_param(txsense, bool, S_IRUGO);
1305MODULE_PARM_DESC(txsense, "Sense of transmitter circuit"
1306 " (0 = active high, 1 = active low )");
1307#endif
1308
1309module_param(softcarrier, bool, S_IRUGO);
1310MODULE_PARM_DESC(softcarrier, "Software carrier (0 = off, 1 = on, default on)");
1311
1312module_param(debug, bool, S_IRUGO | S_IWUSR);
1313MODULE_PARM_DESC(debug, "Enable debugging messages");
diff --git a/drivers/staging/lirc/lirc_sir.c b/drivers/staging/lirc/lirc_sir.c
new file mode 100644
index 000000000000..eb08fa7138ba
--- /dev/null
+++ b/drivers/staging/lirc/lirc_sir.c
@@ -0,0 +1,1282 @@
1/*
2 * LIRC SIR driver, (C) 2000 Milan Pikula <www@fornax.sk>
3 *
4 * lirc_sir - Device driver for use with SIR (serial infra red)
5 * mode of IrDA on many notebooks.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 *
22 * 2000/09/16 Frank Przybylski <mail@frankprzybylski.de> :
23 * added timeout and relaxed pulse detection, removed gap bug
24 *
25 * 2000/12/15 Christoph Bartelmus <lirc@bartelmus.de> :
26 * added support for Tekram Irmate 210 (sending does not work yet,
27 * kind of disappointing that nobody was able to implement that
28 * before),
29 * major clean-up
30 *
31 * 2001/02/27 Christoph Bartelmus <lirc@bartelmus.de> :
32 * added support for StrongARM SA1100 embedded microprocessor
33 * parts cut'n'pasted from sa1100_ir.c (C) 2000 Russell King
34 */
35
36#include <linux/module.h>
37#include <linux/sched.h>
38#include <linux/errno.h>
39#include <linux/signal.h>
40#include <linux/fs.h>
41#include <linux/interrupt.h>
42#include <linux/ioport.h>
43#include <linux/kernel.h>
44#include <linux/serial_reg.h>
45#include <linux/time.h>
46#include <linux/string.h>
47#include <linux/types.h>
48#include <linux/wait.h>
49#include <linux/mm.h>
50#include <linux/delay.h>
51#include <linux/poll.h>
52#include <asm/system.h>
53#include <linux/io.h>
54#include <asm/irq.h>
55#include <linux/fcntl.h>
56#ifdef LIRC_ON_SA1100
57#include <asm/hardware.h>
58#ifdef CONFIG_SA1100_COLLIE
59#include <asm/arch/tc35143.h>
60#include <asm/ucb1200.h>
61#endif
62#endif
63
64#include <linux/timer.h>
65
66#include <media/lirc.h>
67#include <media/lirc_dev.h>
68
69/* SECTION: Definitions */
70
71/*** Tekram dongle ***/
72#ifdef LIRC_SIR_TEKRAM
73/* stolen from kernel source */
74/* definitions for Tekram dongle */
75#define TEKRAM_115200 0x00
76#define TEKRAM_57600 0x01
77#define TEKRAM_38400 0x02
78#define TEKRAM_19200 0x03
79#define TEKRAM_9600 0x04
80#define TEKRAM_2400 0x08
81
82#define TEKRAM_PW 0x10 /* Pulse select bit */
83
84/* 10bit * 1s/115200bit in milliseconds = 87ms*/
85#define TIME_CONST (10000000ul/115200ul)
86
87#endif
88
89#ifdef LIRC_SIR_ACTISYS_ACT200L
90static void init_act200(void);
91#elif defined(LIRC_SIR_ACTISYS_ACT220L)
92static void init_act220(void);
93#endif
94
95/*** SA1100 ***/
96#ifdef LIRC_ON_SA1100
97struct sa1100_ser2_registers {
98 /* HSSP control register */
99 unsigned char hscr0;
100 /* UART registers */
101 unsigned char utcr0;
102 unsigned char utcr1;
103 unsigned char utcr2;
104 unsigned char utcr3;
105 unsigned char utcr4;
106 unsigned char utdr;
107 unsigned char utsr0;
108 unsigned char utsr1;
109} sr;
110
111static int irq = IRQ_Ser2ICP;
112
113#define LIRC_ON_SA1100_TRANSMITTER_LATENCY 0
114
115/* pulse/space ratio of 50/50 */
116static unsigned long pulse_width = (13-LIRC_ON_SA1100_TRANSMITTER_LATENCY);
117/* 1000000/freq-pulse_width */
118static unsigned long space_width = (13-LIRC_ON_SA1100_TRANSMITTER_LATENCY);
119static unsigned int freq = 38000; /* modulation frequency */
120static unsigned int duty_cycle = 50; /* duty cycle of 50% */
121
122#endif
123
124#define RBUF_LEN 1024
125#define WBUF_LEN 1024
126
127#define LIRC_DRIVER_NAME "lirc_sir"
128
129#define PULSE '['
130
131#ifndef LIRC_SIR_TEKRAM
132/* 9bit * 1s/115200bit in milli seconds = 78.125ms*/
133#define TIME_CONST (9000000ul/115200ul)
134#endif
135
136
137/* timeout for sequences in jiffies (=5/100s), must be longer than TIME_CONST */
138#define SIR_TIMEOUT (HZ*5/100)
139
140#ifndef LIRC_ON_SA1100
141#ifndef LIRC_IRQ
142#define LIRC_IRQ 4
143#endif
144#ifndef LIRC_PORT
145/* for external dongles, default to com1 */
146#if defined(LIRC_SIR_ACTISYS_ACT200L) || \
147 defined(LIRC_SIR_ACTISYS_ACT220L) || \
148 defined(LIRC_SIR_TEKRAM)
149#define LIRC_PORT 0x3f8
150#else
151/* onboard sir ports are typically com3 */
152#define LIRC_PORT 0x3e8
153#endif
154#endif
155
156static int io = LIRC_PORT;
157static int irq = LIRC_IRQ;
158static int threshold = 3;
159#endif
160
161static DEFINE_SPINLOCK(timer_lock);
162static struct timer_list timerlist;
163/* time of last signal change detected */
164static struct timeval last_tv = {0, 0};
165/* time of last UART data ready interrupt */
166static struct timeval last_intr_tv = {0, 0};
167static int last_value;
168
169static DECLARE_WAIT_QUEUE_HEAD(lirc_read_queue);
170
171static DEFINE_SPINLOCK(hardware_lock);
172
173static int rx_buf[RBUF_LEN];
174static unsigned int rx_tail, rx_head;
175
176static int debug;
177#define dprintk(fmt, args...) \
178 do { \
179 if (debug) \
180 printk(KERN_DEBUG LIRC_DRIVER_NAME ": " \
181 fmt, ## args); \
182 } while (0)
183
184/* SECTION: Prototypes */
185
186/* Communication with user-space */
187static unsigned int lirc_poll(struct file *file, poll_table *wait);
188static ssize_t lirc_read(struct file *file, char *buf, size_t count,
189 loff_t *ppos);
190static ssize_t lirc_write(struct file *file, const char *buf, size_t n,
191 loff_t *pos);
192static long lirc_ioctl(struct file *filep, unsigned int cmd, unsigned long arg);
193static void add_read_queue(int flag, unsigned long val);
194static int init_chrdev(void);
195static void drop_chrdev(void);
196/* Hardware */
197static irqreturn_t sir_interrupt(int irq, void *dev_id);
198static void send_space(unsigned long len);
199static void send_pulse(unsigned long len);
200static int init_hardware(void);
201static void drop_hardware(void);
202/* Initialisation */
203static int init_port(void);
204static void drop_port(void);
205
206#ifdef LIRC_ON_SA1100
207static void on(void)
208{
209 PPSR |= PPC_TXD2;
210}
211
212static void off(void)
213{
214 PPSR &= ~PPC_TXD2;
215}
216#else
217static inline unsigned int sinp(int offset)
218{
219 return inb(io + offset);
220}
221
222static inline void soutp(int offset, int value)
223{
224 outb(value, io + offset);
225}
226#endif
227
228#ifndef MAX_UDELAY_MS
229#define MAX_UDELAY_US 5000
230#else
231#define MAX_UDELAY_US (MAX_UDELAY_MS*1000)
232#endif
233
234static void safe_udelay(unsigned long usecs)
235{
236 while (usecs > MAX_UDELAY_US) {
237 udelay(MAX_UDELAY_US);
238 usecs -= MAX_UDELAY_US;
239 }
240 udelay(usecs);
241}
242
243/* SECTION: Communication with user-space */
244
245static unsigned int lirc_poll(struct file *file, poll_table *wait)
246{
247 poll_wait(file, &lirc_read_queue, wait);
248 if (rx_head != rx_tail)
249 return POLLIN | POLLRDNORM;
250 return 0;
251}
252
253static ssize_t lirc_read(struct file *file, char *buf, size_t count,
254 loff_t *ppos)
255{
256 int n = 0;
257 int retval = 0;
258 DECLARE_WAITQUEUE(wait, current);
259
260 if (count % sizeof(int))
261 return -EINVAL;
262
263 add_wait_queue(&lirc_read_queue, &wait);
264 set_current_state(TASK_INTERRUPTIBLE);
265 while (n < count) {
266 if (rx_head != rx_tail) {
267 if (copy_to_user((void *) buf + n,
268 (void *) (rx_buf + rx_head),
269 sizeof(int))) {
270 retval = -EFAULT;
271 break;
272 }
273 rx_head = (rx_head + 1) & (RBUF_LEN - 1);
274 n += sizeof(int);
275 } else {
276 if (file->f_flags & O_NONBLOCK) {
277 retval = -EAGAIN;
278 break;
279 }
280 if (signal_pending(current)) {
281 retval = -ERESTARTSYS;
282 break;
283 }
284 schedule();
285 set_current_state(TASK_INTERRUPTIBLE);
286 }
287 }
288 remove_wait_queue(&lirc_read_queue, &wait);
289 set_current_state(TASK_RUNNING);
290 return n ? n : retval;
291}
292static ssize_t lirc_write(struct file *file, const char *buf, size_t n,
293 loff_t *pos)
294{
295 unsigned long flags;
296 int i, count;
297 int *tx_buf;
298
299 count = n / sizeof(int);
300 if (n % sizeof(int) || count % 2 == 0)
301 return -EINVAL;
302 tx_buf = memdup_user(buf, n);
303 if (IS_ERR(tx_buf))
304 return PTR_ERR(tx_buf);
305 i = 0;
306#ifdef LIRC_ON_SA1100
307 /* disable receiver */
308 Ser2UTCR3 = 0;
309#endif
310 local_irq_save(flags);
311 while (1) {
312 if (i >= count)
313 break;
314 if (tx_buf[i])
315 send_pulse(tx_buf[i]);
316 i++;
317 if (i >= count)
318 break;
319 if (tx_buf[i])
320 send_space(tx_buf[i]);
321 i++;
322 }
323 local_irq_restore(flags);
324#ifdef LIRC_ON_SA1100
325 off();
326 udelay(1000); /* wait 1ms for IR diode to recover */
327 Ser2UTCR3 = 0;
328 /* clear status register to prevent unwanted interrupts */
329 Ser2UTSR0 &= (UTSR0_RID | UTSR0_RBB | UTSR0_REB);
330 /* enable receiver */
331 Ser2UTCR3 = UTCR3_RXE|UTCR3_RIE;
332#endif
333 return count;
334}
335
336static long lirc_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
337{
338 int retval = 0;
339 unsigned long value = 0;
340#ifdef LIRC_ON_SA1100
341 unsigned int ivalue;
342
343 if (cmd == LIRC_GET_FEATURES)
344 value = LIRC_CAN_SEND_PULSE |
345 LIRC_CAN_SET_SEND_DUTY_CYCLE |
346 LIRC_CAN_SET_SEND_CARRIER |
347 LIRC_CAN_REC_MODE2;
348 else if (cmd == LIRC_GET_SEND_MODE)
349 value = LIRC_MODE_PULSE;
350 else if (cmd == LIRC_GET_REC_MODE)
351 value = LIRC_MODE_MODE2;
352#else
353 if (cmd == LIRC_GET_FEATURES)
354 value = LIRC_CAN_SEND_PULSE | LIRC_CAN_REC_MODE2;
355 else if (cmd == LIRC_GET_SEND_MODE)
356 value = LIRC_MODE_PULSE;
357 else if (cmd == LIRC_GET_REC_MODE)
358 value = LIRC_MODE_MODE2;
359#endif
360
361 switch (cmd) {
362 case LIRC_GET_FEATURES:
363 case LIRC_GET_SEND_MODE:
364 case LIRC_GET_REC_MODE:
365 retval = put_user(value, (unsigned long *) arg);
366 break;
367
368 case LIRC_SET_SEND_MODE:
369 case LIRC_SET_REC_MODE:
370 retval = get_user(value, (unsigned long *) arg);
371 break;
372#ifdef LIRC_ON_SA1100
373 case LIRC_SET_SEND_DUTY_CYCLE:
374 retval = get_user(ivalue, (unsigned int *) arg);
375 if (retval)
376 return retval;
377 if (ivalue <= 0 || ivalue > 100)
378 return -EINVAL;
379 /* (ivalue/100)*(1000000/freq) */
380 duty_cycle = ivalue;
381 pulse_width = (unsigned long) duty_cycle*10000/freq;
382 space_width = (unsigned long) 1000000L/freq-pulse_width;
383 if (pulse_width >= LIRC_ON_SA1100_TRANSMITTER_LATENCY)
384 pulse_width -= LIRC_ON_SA1100_TRANSMITTER_LATENCY;
385 if (space_width >= LIRC_ON_SA1100_TRANSMITTER_LATENCY)
386 space_width -= LIRC_ON_SA1100_TRANSMITTER_LATENCY;
387 break;
388 case LIRC_SET_SEND_CARRIER:
389 retval = get_user(ivalue, (unsigned int *) arg);
390 if (retval)
391 return retval;
392 if (ivalue > 500000 || ivalue < 20000)
393 return -EINVAL;
394 freq = ivalue;
395 pulse_width = (unsigned long) duty_cycle*10000/freq;
396 space_width = (unsigned long) 1000000L/freq-pulse_width;
397 if (pulse_width >= LIRC_ON_SA1100_TRANSMITTER_LATENCY)
398 pulse_width -= LIRC_ON_SA1100_TRANSMITTER_LATENCY;
399 if (space_width >= LIRC_ON_SA1100_TRANSMITTER_LATENCY)
400 space_width -= LIRC_ON_SA1100_TRANSMITTER_LATENCY;
401 break;
402#endif
403 default:
404 retval = -ENOIOCTLCMD;
405
406 }
407
408 if (retval)
409 return retval;
410 if (cmd == LIRC_SET_REC_MODE) {
411 if (value != LIRC_MODE_MODE2)
412 retval = -ENOSYS;
413 } else if (cmd == LIRC_SET_SEND_MODE) {
414 if (value != LIRC_MODE_PULSE)
415 retval = -ENOSYS;
416 }
417
418 return retval;
419}
420
421static void add_read_queue(int flag, unsigned long val)
422{
423 unsigned int new_rx_tail;
424 int newval;
425
426 dprintk("add flag %d with val %lu\n", flag, val);
427
428 newval = val & PULSE_MASK;
429
430 /*
431 * statistically, pulses are ~TIME_CONST/2 too long. we could
432 * maybe make this more exact, but this is good enough
433 */
434 if (flag) {
435 /* pulse */
436 if (newval > TIME_CONST/2)
437 newval -= TIME_CONST/2;
438 else /* should not ever happen */
439 newval = 1;
440 newval |= PULSE_BIT;
441 } else {
442 newval += TIME_CONST/2;
443 }
444 new_rx_tail = (rx_tail + 1) & (RBUF_LEN - 1);
445 if (new_rx_tail == rx_head) {
446 dprintk("Buffer overrun.\n");
447 return;
448 }
449 rx_buf[rx_tail] = newval;
450 rx_tail = new_rx_tail;
451 wake_up_interruptible(&lirc_read_queue);
452}
453
454static const struct file_operations lirc_fops = {
455 .owner = THIS_MODULE,
456 .read = lirc_read,
457 .write = lirc_write,
458 .poll = lirc_poll,
459 .unlocked_ioctl = lirc_ioctl,
460 .open = lirc_dev_fop_open,
461 .release = lirc_dev_fop_close,
462};
463
464static int set_use_inc(void *data)
465{
466 return 0;
467}
468
469static void set_use_dec(void *data)
470{
471}
472
473static struct lirc_driver driver = {
474 .name = LIRC_DRIVER_NAME,
475 .minor = -1,
476 .code_length = 1,
477 .sample_rate = 0,
478 .data = NULL,
479 .add_to_buf = NULL,
480 .set_use_inc = set_use_inc,
481 .set_use_dec = set_use_dec,
482 .fops = &lirc_fops,
483 .dev = NULL,
484 .owner = THIS_MODULE,
485};
486
487
488static int init_chrdev(void)
489{
490 driver.minor = lirc_register_driver(&driver);
491 if (driver.minor < 0) {
492 printk(KERN_ERR LIRC_DRIVER_NAME ": init_chrdev() failed.\n");
493 return -EIO;
494 }
495 return 0;
496}
497
498static void drop_chrdev(void)
499{
500 lirc_unregister_driver(driver.minor);
501}
502
503/* SECTION: Hardware */
504static long delta(struct timeval *tv1, struct timeval *tv2)
505{
506 unsigned long deltv;
507
508 deltv = tv2->tv_sec - tv1->tv_sec;
509 if (deltv > 15)
510 deltv = 0xFFFFFF;
511 else
512 deltv = deltv*1000000 +
513 tv2->tv_usec -
514 tv1->tv_usec;
515 return deltv;
516}
517
518static void sir_timeout(unsigned long data)
519{
520 /*
521 * if last received signal was a pulse, but receiving stopped
522 * within the 9 bit frame, we need to finish this pulse and
523 * simulate a signal change to from pulse to space. Otherwise
524 * upper layers will receive two sequences next time.
525 */
526
527 unsigned long flags;
528 unsigned long pulse_end;
529
530 /* avoid interference with interrupt */
531 spin_lock_irqsave(&timer_lock, flags);
532 if (last_value) {
533#ifndef LIRC_ON_SA1100
534 /* clear unread bits in UART and restart */
535 outb(UART_FCR_CLEAR_RCVR, io + UART_FCR);
536#endif
537 /* determine 'virtual' pulse end: */
538 pulse_end = delta(&last_tv, &last_intr_tv);
539 dprintk("timeout add %d for %lu usec\n", last_value, pulse_end);
540 add_read_queue(last_value, pulse_end);
541 last_value = 0;
542 last_tv = last_intr_tv;
543 }
544 spin_unlock_irqrestore(&timer_lock, flags);
545}
546
547static irqreturn_t sir_interrupt(int irq, void *dev_id)
548{
549 unsigned char data;
550 struct timeval curr_tv;
551 static unsigned long deltv;
552#ifdef LIRC_ON_SA1100
553 int status;
554 static int n;
555
556 status = Ser2UTSR0;
557 /*
558 * Deal with any receive errors first. The bytes in error may be
559 * the only bytes in the receive FIFO, so we do this first.
560 */
561 while (status & UTSR0_EIF) {
562 int bstat;
563
564 if (debug) {
565 dprintk("EIF\n");
566 bstat = Ser2UTSR1;
567
568 if (bstat & UTSR1_FRE)
569 dprintk("frame error\n");
570 if (bstat & UTSR1_ROR)
571 dprintk("receive fifo overrun\n");
572 if (bstat & UTSR1_PRE)
573 dprintk("parity error\n");
574 }
575
576 bstat = Ser2UTDR;
577 n++;
578 status = Ser2UTSR0;
579 }
580
581 if (status & (UTSR0_RFS | UTSR0_RID)) {
582 do_gettimeofday(&curr_tv);
583 deltv = delta(&last_tv, &curr_tv);
584 do {
585 data = Ser2UTDR;
586 dprintk("%d data: %u\n", n, (unsigned int) data);
587 n++;
588 } while (status & UTSR0_RID && /* do not empty fifo in order to
589 * get UTSR0_RID in any case */
590 Ser2UTSR1 & UTSR1_RNE); /* data ready */
591
592 if (status&UTSR0_RID) {
593 add_read_queue(0 , deltv - n * TIME_CONST); /*space*/
594 add_read_queue(1, n * TIME_CONST); /*pulse*/
595 n = 0;
596 last_tv = curr_tv;
597 }
598 }
599
600 if (status & UTSR0_TFS)
601 printk(KERN_ERR "transmit fifo not full, shouldn't happen\n");
602
603 /* We must clear certain bits. */
604 status &= (UTSR0_RID | UTSR0_RBB | UTSR0_REB);
605 if (status)
606 Ser2UTSR0 = status;
607#else
608 unsigned long deltintrtv;
609 unsigned long flags;
610 int iir, lsr;
611
612 while ((iir = inb(io + UART_IIR) & UART_IIR_ID)) {
613 switch (iir&UART_IIR_ID) { /* FIXME toto treba preriedit */
614 case UART_IIR_MSI:
615 (void) inb(io + UART_MSR);
616 break;
617 case UART_IIR_RLSI:
618 (void) inb(io + UART_LSR);
619 break;
620 case UART_IIR_THRI:
621#if 0
622 if (lsr & UART_LSR_THRE) /* FIFO is empty */
623 outb(data, io + UART_TX)
624#endif
625 break;
626 case UART_IIR_RDI:
627 /* avoid interference with timer */
628 spin_lock_irqsave(&timer_lock, flags);
629 do {
630 del_timer(&timerlist);
631 data = inb(io + UART_RX);
632 do_gettimeofday(&curr_tv);
633 deltv = delta(&last_tv, &curr_tv);
634 deltintrtv = delta(&last_intr_tv, &curr_tv);
635 dprintk("t %lu, d %d\n", deltintrtv, (int)data);
636 /*
637 * if nothing came in last X cycles,
638 * it was gap
639 */
640 if (deltintrtv > TIME_CONST * threshold) {
641 if (last_value) {
642 dprintk("GAP\n");
643 /* simulate signal change */
644 add_read_queue(last_value,
645 deltv -
646 deltintrtv);
647 last_value = 0;
648 last_tv.tv_sec =
649 last_intr_tv.tv_sec;
650 last_tv.tv_usec =
651 last_intr_tv.tv_usec;
652 deltv = deltintrtv;
653 }
654 }
655 data = 1;
656 if (data ^ last_value) {
657 /*
658 * deltintrtv > 2*TIME_CONST, remember?
659 * the other case is timeout
660 */
661 add_read_queue(last_value,
662 deltv-TIME_CONST);
663 last_value = data;
664 last_tv = curr_tv;
665 if (last_tv.tv_usec >= TIME_CONST) {
666 last_tv.tv_usec -= TIME_CONST;
667 } else {
668 last_tv.tv_sec--;
669 last_tv.tv_usec += 1000000 -
670 TIME_CONST;
671 }
672 }
673 last_intr_tv = curr_tv;
674 if (data) {
675 /*
676 * start timer for end of
677 * sequence detection
678 */
679 timerlist.expires = jiffies +
680 SIR_TIMEOUT;
681 add_timer(&timerlist);
682 }
683
684 lsr = inb(io + UART_LSR);
685 } while (lsr & UART_LSR_DR); /* data ready */
686 spin_unlock_irqrestore(&timer_lock, flags);
687 break;
688 default:
689 break;
690 }
691 }
692#endif
693 return IRQ_RETVAL(IRQ_HANDLED);
694}
695
696#ifdef LIRC_ON_SA1100
697static void send_pulse(unsigned long length)
698{
699 unsigned long k, delay;
700 int flag;
701
702 if (length == 0)
703 return;
704 /*
705 * this won't give us the carrier frequency we really want
706 * due to integer arithmetic, but we can accept this inaccuracy
707 */
708
709 for (k = flag = 0; k < length; k += delay, flag = !flag) {
710 if (flag) {
711 off();
712 delay = space_width;
713 } else {
714 on();
715 delay = pulse_width;
716 }
717 safe_udelay(delay);
718 }
719 off();
720}
721
722static void send_space(unsigned long length)
723{
724 if (length == 0)
725 return;
726 off();
727 safe_udelay(length);
728}
729#else
730static void send_space(unsigned long len)
731{
732 safe_udelay(len);
733}
734
735static void send_pulse(unsigned long len)
736{
737 long bytes_out = len / TIME_CONST;
738 long time_left;
739
740 time_left = (long)len - (long)bytes_out * (long)TIME_CONST;
741 if (bytes_out == 0) {
742 bytes_out++;
743 time_left = 0;
744 }
745 while (bytes_out--) {
746 outb(PULSE, io + UART_TX);
747 /* FIXME treba seriozne cakanie z char/serial.c */
748 while (!(inb(io + UART_LSR) & UART_LSR_THRE))
749 ;
750 }
751#if 0
752 if (time_left > 0)
753 safe_udelay(time_left);
754#endif
755}
756#endif
757
758#ifdef CONFIG_SA1100_COLLIE
759static int sa1100_irda_set_power_collie(int state)
760{
761 if (state) {
762 /*
763 * 0 - off
764 * 1 - short range, lowest power
765 * 2 - medium range, medium power
766 * 3 - maximum range, high power
767 */
768 ucb1200_set_io_direction(TC35143_GPIO_IR_ON,
769 TC35143_IODIR_OUTPUT);
770 ucb1200_set_io(TC35143_GPIO_IR_ON, TC35143_IODAT_LOW);
771 udelay(100);
772 } else {
773 /* OFF */
774 ucb1200_set_io_direction(TC35143_GPIO_IR_ON,
775 TC35143_IODIR_OUTPUT);
776 ucb1200_set_io(TC35143_GPIO_IR_ON, TC35143_IODAT_HIGH);
777 }
778 return 0;
779}
780#endif
781
782static int init_hardware(void)
783{
784 unsigned long flags;
785
786 spin_lock_irqsave(&hardware_lock, flags);
787 /* reset UART */
788#ifdef LIRC_ON_SA1100
789#ifdef CONFIG_SA1100_BITSY
790 if (machine_is_bitsy()) {
791 printk(KERN_INFO "Power on IR module\n");
792 set_bitsy_egpio(EGPIO_BITSY_IR_ON);
793 }
794#endif
795#ifdef CONFIG_SA1100_COLLIE
796 sa1100_irda_set_power_collie(3); /* power on */
797#endif
798 sr.hscr0 = Ser2HSCR0;
799
800 sr.utcr0 = Ser2UTCR0;
801 sr.utcr1 = Ser2UTCR1;
802 sr.utcr2 = Ser2UTCR2;
803 sr.utcr3 = Ser2UTCR3;
804 sr.utcr4 = Ser2UTCR4;
805
806 sr.utdr = Ser2UTDR;
807 sr.utsr0 = Ser2UTSR0;
808 sr.utsr1 = Ser2UTSR1;
809
810 /* configure GPIO */
811 /* output */
812 PPDR |= PPC_TXD2;
813 PSDR |= PPC_TXD2;
814 /* set output to 0 */
815 off();
816
817 /* Enable HP-SIR modulation, and ensure that the port is disabled. */
818 Ser2UTCR3 = 0;
819 Ser2HSCR0 = sr.hscr0 & (~HSCR0_HSSP);
820
821 /* clear status register to prevent unwanted interrupts */
822 Ser2UTSR0 &= (UTSR0_RID | UTSR0_RBB | UTSR0_REB);
823
824 /* 7N1 */
825 Ser2UTCR0 = UTCR0_1StpBit|UTCR0_7BitData;
826 /* 115200 */
827 Ser2UTCR1 = 0;
828 Ser2UTCR2 = 1;
829 /* use HPSIR, 1.6 usec pulses */
830 Ser2UTCR4 = UTCR4_HPSIR|UTCR4_Z1_6us;
831
832 /* enable receiver, receive fifo interrupt */
833 Ser2UTCR3 = UTCR3_RXE|UTCR3_RIE;
834
835 /* clear status register to prevent unwanted interrupts */
836 Ser2UTSR0 &= (UTSR0_RID | UTSR0_RBB | UTSR0_REB);
837
838#elif defined(LIRC_SIR_TEKRAM)
839 /* disable FIFO */
840 soutp(UART_FCR,
841 UART_FCR_CLEAR_RCVR|
842 UART_FCR_CLEAR_XMIT|
843 UART_FCR_TRIGGER_1);
844
845 /* Set DLAB 0. */
846 soutp(UART_LCR, sinp(UART_LCR) & (~UART_LCR_DLAB));
847
848 /* First of all, disable all interrupts */
849 soutp(UART_IER, sinp(UART_IER) &
850 (~(UART_IER_MSI|UART_IER_RLSI|UART_IER_THRI|UART_IER_RDI)));
851
852 /* Set DLAB 1. */
853 soutp(UART_LCR, sinp(UART_LCR) | UART_LCR_DLAB);
854
855 /* Set divisor to 12 => 9600 Baud */
856 soutp(UART_DLM, 0);
857 soutp(UART_DLL, 12);
858
859 /* Set DLAB 0. */
860 soutp(UART_LCR, sinp(UART_LCR) & (~UART_LCR_DLAB));
861
862 /* power supply */
863 soutp(UART_MCR, UART_MCR_RTS|UART_MCR_DTR|UART_MCR_OUT2);
864 safe_udelay(50*1000);
865
866 /* -DTR low -> reset PIC */
867 soutp(UART_MCR, UART_MCR_RTS|UART_MCR_OUT2);
868 udelay(1*1000);
869
870 soutp(UART_MCR, UART_MCR_RTS|UART_MCR_DTR|UART_MCR_OUT2);
871 udelay(100);
872
873
874 /* -RTS low -> send control byte */
875 soutp(UART_MCR, UART_MCR_DTR|UART_MCR_OUT2);
876 udelay(7);
877 soutp(UART_TX, TEKRAM_115200|TEKRAM_PW);
878
879 /* one byte takes ~1042 usec to transmit at 9600,8N1 */
880 udelay(1500);
881
882 /* back to normal operation */
883 soutp(UART_MCR, UART_MCR_RTS|UART_MCR_DTR|UART_MCR_OUT2);
884 udelay(50);
885
886 udelay(1500);
887
888 /* read previous control byte */
889 printk(KERN_INFO LIRC_DRIVER_NAME
890 ": 0x%02x\n", sinp(UART_RX));
891
892 /* Set DLAB 1. */
893 soutp(UART_LCR, sinp(UART_LCR) | UART_LCR_DLAB);
894
895 /* Set divisor to 1 => 115200 Baud */
896 soutp(UART_DLM, 0);
897 soutp(UART_DLL, 1);
898
899 /* Set DLAB 0, 8 Bit */
900 soutp(UART_LCR, UART_LCR_WLEN8);
901 /* enable interrupts */
902 soutp(UART_IER, sinp(UART_IER)|UART_IER_RDI);
903#else
904 outb(0, io + UART_MCR);
905 outb(0, io + UART_IER);
906 /* init UART */
907 /* set DLAB, speed = 115200 */
908 outb(UART_LCR_DLAB | UART_LCR_WLEN7, io + UART_LCR);
909 outb(1, io + UART_DLL); outb(0, io + UART_DLM);
910 /* 7N1+start = 9 bits at 115200 ~ 3 bits at 44000 */
911 outb(UART_LCR_WLEN7, io + UART_LCR);
912 /* FIFO operation */
913 outb(UART_FCR_ENABLE_FIFO, io + UART_FCR);
914 /* interrupts */
915 /* outb(UART_IER_RLSI|UART_IER_RDI|UART_IER_THRI, io + UART_IER); */
916 outb(UART_IER_RDI, io + UART_IER);
917 /* turn on UART */
918 outb(UART_MCR_DTR|UART_MCR_RTS|UART_MCR_OUT2, io + UART_MCR);
919#ifdef LIRC_SIR_ACTISYS_ACT200L
920 init_act200();
921#elif defined(LIRC_SIR_ACTISYS_ACT220L)
922 init_act220();
923#endif
924#endif
925 spin_unlock_irqrestore(&hardware_lock, flags);
926 return 0;
927}
928
929static void drop_hardware(void)
930{
931 unsigned long flags;
932
933 spin_lock_irqsave(&hardware_lock, flags);
934
935#ifdef LIRC_ON_SA1100
936 Ser2UTCR3 = 0;
937
938 Ser2UTCR0 = sr.utcr0;
939 Ser2UTCR1 = sr.utcr1;
940 Ser2UTCR2 = sr.utcr2;
941 Ser2UTCR4 = sr.utcr4;
942 Ser2UTCR3 = sr.utcr3;
943
944 Ser2HSCR0 = sr.hscr0;
945#ifdef CONFIG_SA1100_BITSY
946 if (machine_is_bitsy())
947 clr_bitsy_egpio(EGPIO_BITSY_IR_ON);
948#endif
949#ifdef CONFIG_SA1100_COLLIE
950 sa1100_irda_set_power_collie(0); /* power off */
951#endif
952#else
953 /* turn off interrupts */
954 outb(0, io + UART_IER);
955#endif
956 spin_unlock_irqrestore(&hardware_lock, flags);
957}
958
959/* SECTION: Initialisation */
960
961static int init_port(void)
962{
963 int retval;
964
965 /* get I/O port access and IRQ line */
966#ifndef LIRC_ON_SA1100
967 if (request_region(io, 8, LIRC_DRIVER_NAME) == NULL) {
968 printk(KERN_ERR LIRC_DRIVER_NAME
969 ": i/o port 0x%.4x already in use.\n", io);
970 return -EBUSY;
971 }
972#endif
973 retval = request_irq(irq, sir_interrupt, IRQF_DISABLED,
974 LIRC_DRIVER_NAME, NULL);
975 if (retval < 0) {
976# ifndef LIRC_ON_SA1100
977 release_region(io, 8);
978# endif
979 printk(KERN_ERR LIRC_DRIVER_NAME
980 ": IRQ %d already in use.\n",
981 irq);
982 return retval;
983 }
984#ifndef LIRC_ON_SA1100
985 printk(KERN_INFO LIRC_DRIVER_NAME
986 ": I/O port 0x%.4x, IRQ %d.\n",
987 io, irq);
988#endif
989
990 init_timer(&timerlist);
991 timerlist.function = sir_timeout;
992 timerlist.data = 0xabadcafe;
993
994 return 0;
995}
996
997static void drop_port(void)
998{
999 free_irq(irq, NULL);
1000 del_timer_sync(&timerlist);
1001#ifndef LIRC_ON_SA1100
1002 release_region(io, 8);
1003#endif
1004}
1005
1006#ifdef LIRC_SIR_ACTISYS_ACT200L
1007/* Crystal/Cirrus CS8130 IR transceiver, used in Actisys Act200L dongle */
1008/* some code borrowed from Linux IRDA driver */
1009
1010/* Register 0: Control register #1 */
1011#define ACT200L_REG0 0x00
1012#define ACT200L_TXEN 0x01 /* Enable transmitter */
1013#define ACT200L_RXEN 0x02 /* Enable receiver */
1014#define ACT200L_ECHO 0x08 /* Echo control chars */
1015
1016/* Register 1: Control register #2 */
1017#define ACT200L_REG1 0x10
1018#define ACT200L_LODB 0x01 /* Load new baud rate count value */
1019#define ACT200L_WIDE 0x04 /* Expand the maximum allowable pulse */
1020
1021/* Register 3: Transmit mode register #2 */
1022#define ACT200L_REG3 0x30
1023#define ACT200L_B0 0x01 /* DataBits, 0=6, 1=7, 2=8, 3=9(8P) */
1024#define ACT200L_B1 0x02 /* DataBits, 0=6, 1=7, 2=8, 3=9(8P) */
1025#define ACT200L_CHSY 0x04 /* StartBit Synced 0=bittime, 1=startbit */
1026
1027/* Register 4: Output Power register */
1028#define ACT200L_REG4 0x40
1029#define ACT200L_OP0 0x01 /* Enable LED1C output */
1030#define ACT200L_OP1 0x02 /* Enable LED2C output */
1031#define ACT200L_BLKR 0x04
1032
1033/* Register 5: Receive Mode register */
1034#define ACT200L_REG5 0x50
1035#define ACT200L_RWIDL 0x01 /* fixed 1.6us pulse mode */
1036 /*.. other various IRDA bit modes, and TV remote modes..*/
1037
1038/* Register 6: Receive Sensitivity register #1 */
1039#define ACT200L_REG6 0x60
1040#define ACT200L_RS0 0x01 /* receive threshold bit 0 */
1041#define ACT200L_RS1 0x02 /* receive threshold bit 1 */
1042
1043/* Register 7: Receive Sensitivity register #2 */
1044#define ACT200L_REG7 0x70
1045#define ACT200L_ENPOS 0x04 /* Ignore the falling edge */
1046
1047/* Register 8,9: Baud Rate Divider register #1,#2 */
1048#define ACT200L_REG8 0x80
1049#define ACT200L_REG9 0x90
1050
1051#define ACT200L_2400 0x5f
1052#define ACT200L_9600 0x17
1053#define ACT200L_19200 0x0b
1054#define ACT200L_38400 0x05
1055#define ACT200L_57600 0x03
1056#define ACT200L_115200 0x01
1057
1058/* Register 13: Control register #3 */
1059#define ACT200L_REG13 0xd0
1060#define ACT200L_SHDW 0x01 /* Enable access to shadow registers */
1061
1062/* Register 15: Status register */
1063#define ACT200L_REG15 0xf0
1064
1065/* Register 21: Control register #4 */
1066#define ACT200L_REG21 0x50
1067#define ACT200L_EXCK 0x02 /* Disable clock output driver */
1068#define ACT200L_OSCL 0x04 /* oscillator in low power, medium accuracy mode */
1069
1070static void init_act200(void)
1071{
1072 int i;
1073 __u8 control[] = {
1074 ACT200L_REG15,
1075 ACT200L_REG13 | ACT200L_SHDW,
1076 ACT200L_REG21 | ACT200L_EXCK | ACT200L_OSCL,
1077 ACT200L_REG13,
1078 ACT200L_REG7 | ACT200L_ENPOS,
1079 ACT200L_REG6 | ACT200L_RS0 | ACT200L_RS1,
1080 ACT200L_REG5 | ACT200L_RWIDL,
1081 ACT200L_REG4 | ACT200L_OP0 | ACT200L_OP1 | ACT200L_BLKR,
1082 ACT200L_REG3 | ACT200L_B0,
1083 ACT200L_REG0 | ACT200L_TXEN | ACT200L_RXEN,
1084 ACT200L_REG8 | (ACT200L_115200 & 0x0f),
1085 ACT200L_REG9 | ((ACT200L_115200 >> 4) & 0x0f),
1086 ACT200L_REG1 | ACT200L_LODB | ACT200L_WIDE
1087 };
1088
1089 /* Set DLAB 1. */
1090 soutp(UART_LCR, UART_LCR_DLAB | UART_LCR_WLEN8);
1091
1092 /* Set divisor to 12 => 9600 Baud */
1093 soutp(UART_DLM, 0);
1094 soutp(UART_DLL, 12);
1095
1096 /* Set DLAB 0. */
1097 soutp(UART_LCR, UART_LCR_WLEN8);
1098 /* Set divisor to 12 => 9600 Baud */
1099
1100 /* power supply */
1101 soutp(UART_MCR, UART_MCR_RTS|UART_MCR_DTR|UART_MCR_OUT2);
1102 for (i = 0; i < 50; i++)
1103 safe_udelay(1000);
1104
1105 /* Reset the dongle : set RTS low for 25 ms */
1106 soutp(UART_MCR, UART_MCR_DTR|UART_MCR_OUT2);
1107 for (i = 0; i < 25; i++)
1108 udelay(1000);
1109
1110 soutp(UART_MCR, UART_MCR_RTS|UART_MCR_DTR|UART_MCR_OUT2);
1111 udelay(100);
1112
1113 /* Clear DTR and set RTS to enter command mode */
1114 soutp(UART_MCR, UART_MCR_RTS|UART_MCR_OUT2);
1115 udelay(7);
1116
1117 /* send out the control register settings for 115K 7N1 SIR operation */
1118 for (i = 0; i < sizeof(control); i++) {
1119 soutp(UART_TX, control[i]);
1120 /* one byte takes ~1042 usec to transmit at 9600,8N1 */
1121 udelay(1500);
1122 }
1123
1124 /* back to normal operation */
1125 soutp(UART_MCR, UART_MCR_RTS|UART_MCR_DTR|UART_MCR_OUT2);
1126 udelay(50);
1127
1128 udelay(1500);
1129 soutp(UART_LCR, sinp(UART_LCR) | UART_LCR_DLAB);
1130
1131 /* Set DLAB 1. */
1132 soutp(UART_LCR, UART_LCR_DLAB | UART_LCR_WLEN7);
1133
1134 /* Set divisor to 1 => 115200 Baud */
1135 soutp(UART_DLM, 0);
1136 soutp(UART_DLL, 1);
1137
1138 /* Set DLAB 0. */
1139 soutp(UART_LCR, sinp(UART_LCR) & (~UART_LCR_DLAB));
1140
1141 /* Set DLAB 0, 7 Bit */
1142 soutp(UART_LCR, UART_LCR_WLEN7);
1143
1144 /* enable interrupts */
1145 soutp(UART_IER, sinp(UART_IER)|UART_IER_RDI);
1146}
1147#endif
1148
1149#ifdef LIRC_SIR_ACTISYS_ACT220L
1150/*
1151 * Derived from linux IrDA driver (net/irda/actisys.c)
1152 * Drop me a mail for any kind of comment: maxx@spaceboyz.net
1153 */
1154
1155void init_act220(void)
1156{
1157 int i;
1158
1159 /* DLAB 1 */
1160 soutp(UART_LCR, UART_LCR_DLAB|UART_LCR_WLEN7);
1161
1162 /* 9600 baud */
1163 soutp(UART_DLM, 0);
1164 soutp(UART_DLL, 12);
1165
1166 /* DLAB 0 */
1167 soutp(UART_LCR, UART_LCR_WLEN7);
1168
1169 /* reset the dongle, set DTR low for 10us */
1170 soutp(UART_MCR, UART_MCR_RTS|UART_MCR_OUT2);
1171 udelay(10);
1172
1173 /* back to normal (still 9600) */
1174 soutp(UART_MCR, UART_MCR_DTR|UART_MCR_RTS|UART_MCR_OUT2);
1175
1176 /*
1177 * send RTS pulses until we reach 115200
1178 * i hope this is really the same for act220l/act220l+
1179 */
1180 for (i = 0; i < 3; i++) {
1181 udelay(10);
1182 /* set RTS low for 10 us */
1183 soutp(UART_MCR, UART_MCR_DTR|UART_MCR_OUT2);
1184 udelay(10);
1185 /* set RTS high for 10 us */
1186 soutp(UART_MCR, UART_MCR_RTS|UART_MCR_DTR|UART_MCR_OUT2);
1187 }
1188
1189 /* back to normal operation */
1190 udelay(1500); /* better safe than sorry ;) */
1191
1192 /* Set DLAB 1. */
1193 soutp(UART_LCR, UART_LCR_DLAB | UART_LCR_WLEN7);
1194
1195 /* Set divisor to 1 => 115200 Baud */
1196 soutp(UART_DLM, 0);
1197 soutp(UART_DLL, 1);
1198
1199 /* Set DLAB 0, 7 Bit */
1200 /* The dongle doesn't seem to have any problems with operation at 7N1 */
1201 soutp(UART_LCR, UART_LCR_WLEN7);
1202
1203 /* enable interrupts */
1204 soutp(UART_IER, UART_IER_RDI);
1205}
1206#endif
1207
1208static int init_lirc_sir(void)
1209{
1210 int retval;
1211
1212 init_waitqueue_head(&lirc_read_queue);
1213 retval = init_port();
1214 if (retval < 0)
1215 return retval;
1216 init_hardware();
1217 printk(KERN_INFO LIRC_DRIVER_NAME
1218 ": Installed.\n");
1219 return 0;
1220}
1221
1222
1223static int __init lirc_sir_init(void)
1224{
1225 int retval;
1226
1227 retval = init_chrdev();
1228 if (retval < 0)
1229 return retval;
1230 retval = init_lirc_sir();
1231 if (retval) {
1232 drop_chrdev();
1233 return retval;
1234 }
1235 return 0;
1236}
1237
1238static void __exit lirc_sir_exit(void)
1239{
1240 drop_hardware();
1241 drop_chrdev();
1242 drop_port();
1243 printk(KERN_INFO LIRC_DRIVER_NAME ": Uninstalled.\n");
1244}
1245
1246module_init(lirc_sir_init);
1247module_exit(lirc_sir_exit);
1248
1249#ifdef LIRC_SIR_TEKRAM
1250MODULE_DESCRIPTION("Infrared receiver driver for Tekram Irmate 210");
1251MODULE_AUTHOR("Christoph Bartelmus");
1252#elif defined(LIRC_ON_SA1100)
1253MODULE_DESCRIPTION("LIRC driver for StrongARM SA1100 embedded microprocessor");
1254MODULE_AUTHOR("Christoph Bartelmus");
1255#elif defined(LIRC_SIR_ACTISYS_ACT200L)
1256MODULE_DESCRIPTION("LIRC driver for Actisys Act200L");
1257MODULE_AUTHOR("Karl Bongers");
1258#elif defined(LIRC_SIR_ACTISYS_ACT220L)
1259MODULE_DESCRIPTION("LIRC driver for Actisys Act220L(+)");
1260MODULE_AUTHOR("Jan Roemisch");
1261#else
1262MODULE_DESCRIPTION("Infrared receiver driver for SIR type serial ports");
1263MODULE_AUTHOR("Milan Pikula");
1264#endif
1265MODULE_LICENSE("GPL");
1266
1267#ifdef LIRC_ON_SA1100
1268module_param(irq, int, S_IRUGO);
1269MODULE_PARM_DESC(irq, "Interrupt (16)");
1270#else
1271module_param(io, int, S_IRUGO);
1272MODULE_PARM_DESC(io, "I/O address base (0x3f8 or 0x2f8)");
1273
1274module_param(irq, int, S_IRUGO);
1275MODULE_PARM_DESC(irq, "Interrupt (4 or 3)");
1276
1277module_param(threshold, int, S_IRUGO);
1278MODULE_PARM_DESC(threshold, "space detection threshold (3)");
1279#endif
1280
1281module_param(debug, bool, S_IRUGO | S_IWUSR);
1282MODULE_PARM_DESC(debug, "Enable debugging messages");
diff --git a/drivers/staging/lirc/lirc_streamzap.c b/drivers/staging/lirc/lirc_streamzap.c
new file mode 100644
index 000000000000..be09c103f0c9
--- /dev/null
+++ b/drivers/staging/lirc/lirc_streamzap.c
@@ -0,0 +1,821 @@
1/*
2 * Streamzap Remote Control driver
3 *
4 * Copyright (c) 2005 Christoph Bartelmus <lirc@bartelmus.de>
5 *
6 * This driver was based on the work of Greg Wickham and Adrian
7 * Dewhurst. It was substantially rewritten to support correct signal
8 * gaps and now maintains a delay buffer, which is used to present
9 * consistent timing behaviour to user space applications. Without the
10 * delay buffer an ugly hack would be required in lircd, which can
11 * cause sluggish signal decoding in certain situations.
12 *
13 * This driver is based on the USB skeleton driver packaged with the
14 * kernel; copyright (C) 2001-2003 Greg Kroah-Hartman (greg@kroah.com)
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 */
30
31#include <linux/kernel.h>
32#include <linux/errno.h>
33#include <linux/init.h>
34#include <linux/slab.h>
35#include <linux/module.h>
36#include <linux/smp_lock.h>
37#include <linux/completion.h>
38#include <linux/uaccess.h>
39#include <linux/usb.h>
40
41#include <media/lirc.h>
42#include <media/lirc_dev.h>
43
44#define DRIVER_VERSION "1.28"
45#define DRIVER_NAME "lirc_streamzap"
46#define DRIVER_DESC "Streamzap Remote Control driver"
47
48static int debug;
49
50#define USB_STREAMZAP_VENDOR_ID 0x0e9c
51#define USB_STREAMZAP_PRODUCT_ID 0x0000
52
53/* Use our own dbg macro */
54#define dprintk(fmt, args...) \
55 do { \
56 if (debug) \
57 printk(KERN_DEBUG DRIVER_NAME "[%d]: " \
58 fmt "\n", ## args); \
59 } while (0)
60
61/* table of devices that work with this driver */
62static struct usb_device_id streamzap_table[] = {
63 /* Streamzap Remote Control */
64 { USB_DEVICE(USB_STREAMZAP_VENDOR_ID, USB_STREAMZAP_PRODUCT_ID) },
65 /* Terminating entry */
66 { }
67};
68
69MODULE_DEVICE_TABLE(usb, streamzap_table);
70
71#define STREAMZAP_PULSE_MASK 0xf0
72#define STREAMZAP_SPACE_MASK 0x0f
73#define STREAMZAP_TIMEOUT 0xff
74#define STREAMZAP_RESOLUTION 256
75
76/* number of samples buffered */
77#define STREAMZAP_BUF_LEN 128
78
79enum StreamzapDecoderState {
80 PulseSpace,
81 FullPulse,
82 FullSpace,
83 IgnorePulse
84};
85
86/* Structure to hold all of our device specific stuff
87 *
88 * some remarks regarding locking:
89 * theoretically this struct can be accessed from three threads:
90 *
91 * - from lirc_dev through set_use_inc/set_use_dec
92 *
93 * - from the USB layer throuh probe/disconnect/irq
94 *
95 * Careful placement of lirc_register_driver/lirc_unregister_driver
96 * calls will prevent conflicts. lirc_dev makes sure that
97 * set_use_inc/set_use_dec are not being executed and will not be
98 * called after lirc_unregister_driver returns.
99 *
100 * - by the timer callback
101 *
102 * The timer is only running when the device is connected and the
103 * LIRC device is open. Making sure the timer is deleted by
104 * set_use_dec will make conflicts impossible.
105 */
106struct usb_streamzap {
107
108 /* usb */
109 /* save off the usb device pointer */
110 struct usb_device *udev;
111 /* the interface for this device */
112 struct usb_interface *interface;
113
114 /* buffer & dma */
115 unsigned char *buf_in;
116 dma_addr_t dma_in;
117 unsigned int buf_in_len;
118
119 struct usb_endpoint_descriptor *endpoint;
120
121 /* IRQ */
122 struct urb *urb_in;
123
124 /* lirc */
125 struct lirc_driver *driver;
126 struct lirc_buffer *delay_buf;
127
128 /* timer used to support delay buffering */
129 struct timer_list delay_timer;
130 int timer_running;
131 spinlock_t timer_lock;
132
133 /* tracks whether we are currently receiving some signal */
134 int idle;
135 /* sum of signal lengths received since signal start */
136 unsigned long sum;
137 /* start time of signal; necessary for gap tracking */
138 struct timeval signal_last;
139 struct timeval signal_start;
140 enum StreamzapDecoderState decoder_state;
141 struct timer_list flush_timer;
142 int flush;
143 int in_use;
144 int timeout_enabled;
145};
146
147
148/* local function prototypes */
149static int streamzap_probe(struct usb_interface *interface,
150 const struct usb_device_id *id);
151static void streamzap_disconnect(struct usb_interface *interface);
152static void usb_streamzap_irq(struct urb *urb);
153static int streamzap_use_inc(void *data);
154static void streamzap_use_dec(void *data);
155static long streamzap_ioctl(struct file *filep, unsigned int cmd,
156 unsigned long arg);
157static int streamzap_suspend(struct usb_interface *intf, pm_message_t message);
158static int streamzap_resume(struct usb_interface *intf);
159
160/* usb specific object needed to register this driver with the usb subsystem */
161
162static struct usb_driver streamzap_driver = {
163 .name = DRIVER_NAME,
164 .probe = streamzap_probe,
165 .disconnect = streamzap_disconnect,
166 .suspend = streamzap_suspend,
167 .resume = streamzap_resume,
168 .id_table = streamzap_table,
169};
170
171static void stop_timer(struct usb_streamzap *sz)
172{
173 unsigned long flags;
174
175 spin_lock_irqsave(&sz->timer_lock, flags);
176 if (sz->timer_running) {
177 sz->timer_running = 0;
178 spin_unlock_irqrestore(&sz->timer_lock, flags);
179 del_timer_sync(&sz->delay_timer);
180 } else {
181 spin_unlock_irqrestore(&sz->timer_lock, flags);
182 }
183}
184
185static void flush_timeout(unsigned long arg)
186{
187 struct usb_streamzap *sz = (struct usb_streamzap *) arg;
188
189 /* finally start accepting data */
190 sz->flush = 0;
191}
192static void delay_timeout(unsigned long arg)
193{
194 unsigned long flags;
195 /* deliver data every 10 ms */
196 static unsigned long timer_inc =
197 (10000/(1000000/HZ)) == 0 ? 1 : (10000/(1000000/HZ));
198 struct usb_streamzap *sz = (struct usb_streamzap *) arg;
199 int data;
200
201 spin_lock_irqsave(&sz->timer_lock, flags);
202
203 if (!lirc_buffer_empty(sz->delay_buf) &&
204 !lirc_buffer_full(sz->driver->rbuf)) {
205 lirc_buffer_read(sz->delay_buf, (unsigned char *) &data);
206 lirc_buffer_write(sz->driver->rbuf, (unsigned char *) &data);
207 }
208 if (!lirc_buffer_empty(sz->delay_buf)) {
209 while (lirc_buffer_available(sz->delay_buf) <
210 STREAMZAP_BUF_LEN / 2 &&
211 !lirc_buffer_full(sz->driver->rbuf)) {
212 lirc_buffer_read(sz->delay_buf,
213 (unsigned char *) &data);
214 lirc_buffer_write(sz->driver->rbuf,
215 (unsigned char *) &data);
216 }
217 if (sz->timer_running) {
218 sz->delay_timer.expires = jiffies + timer_inc;
219 add_timer(&sz->delay_timer);
220 }
221 } else {
222 sz->timer_running = 0;
223 }
224
225 if (!lirc_buffer_empty(sz->driver->rbuf))
226 wake_up(&sz->driver->rbuf->wait_poll);
227
228 spin_unlock_irqrestore(&sz->timer_lock, flags);
229}
230
231static void flush_delay_buffer(struct usb_streamzap *sz)
232{
233 int data;
234 int empty = 1;
235
236 while (!lirc_buffer_empty(sz->delay_buf)) {
237 empty = 0;
238 lirc_buffer_read(sz->delay_buf, (unsigned char *) &data);
239 if (!lirc_buffer_full(sz->driver->rbuf)) {
240 lirc_buffer_write(sz->driver->rbuf,
241 (unsigned char *) &data);
242 } else {
243 dprintk("buffer overflow", sz->driver->minor);
244 }
245 }
246 if (!empty)
247 wake_up(&sz->driver->rbuf->wait_poll);
248}
249
250static void push(struct usb_streamzap *sz, unsigned char *data)
251{
252 unsigned long flags;
253
254 spin_lock_irqsave(&sz->timer_lock, flags);
255 if (lirc_buffer_full(sz->delay_buf)) {
256 int read_data;
257
258 lirc_buffer_read(sz->delay_buf,
259 (unsigned char *) &read_data);
260 if (!lirc_buffer_full(sz->driver->rbuf)) {
261 lirc_buffer_write(sz->driver->rbuf,
262 (unsigned char *) &read_data);
263 } else {
264 dprintk("buffer overflow", sz->driver->minor);
265 }
266 }
267
268 lirc_buffer_write(sz->delay_buf, data);
269
270 if (!sz->timer_running) {
271 sz->delay_timer.expires = jiffies + HZ/10;
272 add_timer(&sz->delay_timer);
273 sz->timer_running = 1;
274 }
275
276 spin_unlock_irqrestore(&sz->timer_lock, flags);
277}
278
279static void push_full_pulse(struct usb_streamzap *sz,
280 unsigned char value)
281{
282 int pulse;
283
284 if (sz->idle) {
285 long deltv;
286 int tmp;
287
288 sz->signal_last = sz->signal_start;
289 do_gettimeofday(&sz->signal_start);
290
291 deltv = sz->signal_start.tv_sec-sz->signal_last.tv_sec;
292 if (deltv > 15) {
293 /* really long time */
294 tmp = LIRC_SPACE(LIRC_VALUE_MASK);
295 } else {
296 tmp = (int) (deltv*1000000+
297 sz->signal_start.tv_usec -
298 sz->signal_last.tv_usec);
299 tmp -= sz->sum;
300 tmp = LIRC_SPACE(tmp);
301 }
302 dprintk("ls %u", sz->driver->minor, tmp);
303 push(sz, (char *)&tmp);
304
305 sz->idle = 0;
306 sz->sum = 0;
307 }
308
309 pulse = ((int) value) * STREAMZAP_RESOLUTION;
310 pulse += STREAMZAP_RESOLUTION / 2;
311 sz->sum += pulse;
312 pulse = LIRC_PULSE(pulse);
313
314 dprintk("p %u", sz->driver->minor, pulse & PULSE_MASK);
315 push(sz, (char *)&pulse);
316}
317
318static void push_half_pulse(struct usb_streamzap *sz,
319 unsigned char value)
320{
321 push_full_pulse(sz, (value & STREAMZAP_PULSE_MASK)>>4);
322}
323
324static void push_full_space(struct usb_streamzap *sz,
325 unsigned char value)
326{
327 int space;
328
329 space = ((int) value)*STREAMZAP_RESOLUTION;
330 space += STREAMZAP_RESOLUTION/2;
331 sz->sum += space;
332 space = LIRC_SPACE(space);
333 dprintk("s %u", sz->driver->minor, space);
334 push(sz, (char *)&space);
335}
336
337static void push_half_space(struct usb_streamzap *sz,
338 unsigned char value)
339{
340 push_full_space(sz, value & STREAMZAP_SPACE_MASK);
341}
342
343/**
344 * usb_streamzap_irq - IRQ handler
345 *
346 * This procedure is invoked on reception of data from
347 * the usb remote.
348 */
349static void usb_streamzap_irq(struct urb *urb)
350{
351 struct usb_streamzap *sz;
352 int len;
353 unsigned int i = 0;
354
355 if (!urb)
356 return;
357
358 sz = urb->context;
359 len = urb->actual_length;
360
361 switch (urb->status) {
362 case -ECONNRESET:
363 case -ENOENT:
364 case -ESHUTDOWN:
365 /*
366 * this urb is terminated, clean up.
367 * sz might already be invalid at this point
368 */
369 dprintk("urb status: %d", -1, urb->status);
370 return;
371 default:
372 break;
373 }
374
375 dprintk("received %d", sz->driver->minor, urb->actual_length);
376 if (!sz->flush) {
377 for (i = 0; i < urb->actual_length; i++) {
378 dprintk("%d: %x", sz->driver->minor,
379 i, (unsigned char) sz->buf_in[i]);
380 switch (sz->decoder_state) {
381 case PulseSpace:
382 if ((sz->buf_in[i]&STREAMZAP_PULSE_MASK) ==
383 STREAMZAP_PULSE_MASK) {
384 sz->decoder_state = FullPulse;
385 continue;
386 } else if ((sz->buf_in[i]&STREAMZAP_SPACE_MASK)
387 == STREAMZAP_SPACE_MASK) {
388 push_half_pulse(sz, sz->buf_in[i]);
389 sz->decoder_state = FullSpace;
390 continue;
391 } else {
392 push_half_pulse(sz, sz->buf_in[i]);
393 push_half_space(sz, sz->buf_in[i]);
394 }
395 break;
396 case FullPulse:
397 push_full_pulse(sz, sz->buf_in[i]);
398 sz->decoder_state = IgnorePulse;
399 break;
400 case FullSpace:
401 if (sz->buf_in[i] == STREAMZAP_TIMEOUT) {
402 sz->idle = 1;
403 stop_timer(sz);
404 if (sz->timeout_enabled) {
405 int timeout =
406 LIRC_TIMEOUT
407 (STREAMZAP_TIMEOUT *
408 STREAMZAP_RESOLUTION);
409 push(sz, (char *)&timeout);
410 }
411 flush_delay_buffer(sz);
412 } else
413 push_full_space(sz, sz->buf_in[i]);
414 sz->decoder_state = PulseSpace;
415 break;
416 case IgnorePulse:
417 if ((sz->buf_in[i]&STREAMZAP_SPACE_MASK) ==
418 STREAMZAP_SPACE_MASK) {
419 sz->decoder_state = FullSpace;
420 continue;
421 }
422 push_half_space(sz, sz->buf_in[i]);
423 sz->decoder_state = PulseSpace;
424 break;
425 }
426 }
427 }
428
429 usb_submit_urb(urb, GFP_ATOMIC);
430
431 return;
432}
433
434static const struct file_operations streamzap_fops = {
435 .owner = THIS_MODULE,
436 .unlocked_ioctl = streamzap_ioctl,
437 .read = lirc_dev_fop_read,
438 .write = lirc_dev_fop_write,
439 .poll = lirc_dev_fop_poll,
440 .open = lirc_dev_fop_open,
441 .release = lirc_dev_fop_close,
442};
443
444
445/**
446 * streamzap_probe
447 *
448 * Called by usb-core to associated with a candidate device
449 * On any failure the return value is the ERROR
450 * On success return 0
451 */
452static int streamzap_probe(struct usb_interface *interface,
453 const struct usb_device_id *id)
454{
455 struct usb_device *udev = interface_to_usbdev(interface);
456 struct usb_host_interface *iface_host;
457 struct usb_streamzap *sz;
458 struct lirc_driver *driver;
459 struct lirc_buffer *lirc_buf;
460 struct lirc_buffer *delay_buf;
461 char buf[63], name[128] = "";
462 int retval = -ENOMEM;
463 int minor = 0;
464
465 /* Allocate space for device driver specific data */
466 sz = kzalloc(sizeof(struct usb_streamzap), GFP_KERNEL);
467 if (sz == NULL)
468 return -ENOMEM;
469
470 sz->udev = udev;
471 sz->interface = interface;
472
473 /* Check to ensure endpoint information matches requirements */
474 iface_host = interface->cur_altsetting;
475
476 if (iface_host->desc.bNumEndpoints != 1) {
477 err("%s: Unexpected desc.bNumEndpoints (%d)", __func__,
478 iface_host->desc.bNumEndpoints);
479 retval = -ENODEV;
480 goto free_sz;
481 }
482
483 sz->endpoint = &(iface_host->endpoint[0].desc);
484 if ((sz->endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK)
485 != USB_DIR_IN) {
486 err("%s: endpoint doesn't match input device 02%02x",
487 __func__, sz->endpoint->bEndpointAddress);
488 retval = -ENODEV;
489 goto free_sz;
490 }
491
492 if ((sz->endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
493 != USB_ENDPOINT_XFER_INT) {
494 err("%s: endpoint attributes don't match xfer 02%02x",
495 __func__, sz->endpoint->bmAttributes);
496 retval = -ENODEV;
497 goto free_sz;
498 }
499
500 if (sz->endpoint->wMaxPacketSize == 0) {
501 err("%s: endpoint message size==0? ", __func__);
502 retval = -ENODEV;
503 goto free_sz;
504 }
505
506 /* Allocate the USB buffer and IRQ URB */
507
508 sz->buf_in_len = sz->endpoint->wMaxPacketSize;
509 sz->buf_in = usb_alloc_coherent(sz->udev, sz->buf_in_len,
510 GFP_ATOMIC, &sz->dma_in);
511 if (sz->buf_in == NULL)
512 goto free_sz;
513
514 sz->urb_in = usb_alloc_urb(0, GFP_KERNEL);
515 if (sz->urb_in == NULL)
516 goto free_sz;
517
518 /* Connect this device to the LIRC sub-system */
519 driver = kzalloc(sizeof(struct lirc_driver), GFP_KERNEL);
520 if (!driver)
521 goto free_sz;
522
523 lirc_buf = kmalloc(sizeof(struct lirc_buffer), GFP_KERNEL);
524 if (!lirc_buf)
525 goto free_driver;
526 if (lirc_buffer_init(lirc_buf, sizeof(int), STREAMZAP_BUF_LEN))
527 goto kfree_lirc_buf;
528
529 delay_buf = kmalloc(sizeof(struct lirc_buffer), GFP_KERNEL);
530 if (!delay_buf)
531 goto free_lirc_buf;
532 if (lirc_buffer_init(delay_buf, sizeof(int), STREAMZAP_BUF_LEN))
533 goto kfree_delay_buf;
534
535 sz->driver = driver;
536 strcpy(sz->driver->name, DRIVER_NAME);
537 sz->driver->minor = -1;
538 sz->driver->sample_rate = 0;
539 sz->driver->code_length = sizeof(int) * 8;
540 sz->driver->features = LIRC_CAN_REC_MODE2 |
541 LIRC_CAN_GET_REC_RESOLUTION |
542 LIRC_CAN_SET_REC_TIMEOUT;
543 sz->driver->data = sz;
544 sz->driver->min_timeout = STREAMZAP_TIMEOUT * STREAMZAP_RESOLUTION;
545 sz->driver->max_timeout = STREAMZAP_TIMEOUT * STREAMZAP_RESOLUTION;
546 sz->driver->rbuf = lirc_buf;
547 sz->delay_buf = delay_buf;
548 sz->driver->set_use_inc = &streamzap_use_inc;
549 sz->driver->set_use_dec = &streamzap_use_dec;
550 sz->driver->fops = &streamzap_fops;
551 sz->driver->dev = &interface->dev;
552 sz->driver->owner = THIS_MODULE;
553
554 sz->idle = 1;
555 sz->decoder_state = PulseSpace;
556 init_timer(&sz->delay_timer);
557 sz->delay_timer.function = delay_timeout;
558 sz->delay_timer.data = (unsigned long) sz;
559 sz->timer_running = 0;
560 spin_lock_init(&sz->timer_lock);
561
562 init_timer(&sz->flush_timer);
563 sz->flush_timer.function = flush_timeout;
564 sz->flush_timer.data = (unsigned long) sz;
565 /* Complete final initialisations */
566
567 usb_fill_int_urb(sz->urb_in, udev,
568 usb_rcvintpipe(udev, sz->endpoint->bEndpointAddress),
569 sz->buf_in, sz->buf_in_len, usb_streamzap_irq, sz,
570 sz->endpoint->bInterval);
571 sz->urb_in->transfer_dma = sz->dma_in;
572 sz->urb_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
573
574 if (udev->descriptor.iManufacturer
575 && usb_string(udev, udev->descriptor.iManufacturer,
576 buf, sizeof(buf)) > 0)
577 strlcpy(name, buf, sizeof(name));
578
579 if (udev->descriptor.iProduct
580 && usb_string(udev, udev->descriptor.iProduct,
581 buf, sizeof(buf)) > 0)
582 snprintf(name + strlen(name), sizeof(name) - strlen(name),
583 " %s", buf);
584
585 minor = lirc_register_driver(driver);
586
587 if (minor < 0)
588 goto free_delay_buf;
589
590 sz->driver->minor = minor;
591
592 usb_set_intfdata(interface, sz);
593
594 printk(KERN_INFO DRIVER_NAME "[%d]: %s on usb%d:%d attached\n",
595 sz->driver->minor, name,
596 udev->bus->busnum, sz->udev->devnum);
597
598 return 0;
599
600free_delay_buf:
601 lirc_buffer_free(sz->delay_buf);
602kfree_delay_buf:
603 kfree(delay_buf);
604free_lirc_buf:
605 lirc_buffer_free(sz->driver->rbuf);
606kfree_lirc_buf:
607 kfree(lirc_buf);
608free_driver:
609 kfree(driver);
610free_sz:
611 if (retval == -ENOMEM)
612 err("Out of memory");
613
614 if (sz) {
615 usb_free_urb(sz->urb_in);
616 usb_free_coherent(udev, sz->buf_in_len, sz->buf_in, sz->dma_in);
617 kfree(sz);
618 }
619
620 return retval;
621}
622
623static int streamzap_use_inc(void *data)
624{
625 struct usb_streamzap *sz = data;
626
627 if (!sz) {
628 dprintk("%s called with no context", -1, __func__);
629 return -EINVAL;
630 }
631 dprintk("set use inc", sz->driver->minor);
632
633 lirc_buffer_clear(sz->driver->rbuf);
634 lirc_buffer_clear(sz->delay_buf);
635
636 sz->flush_timer.expires = jiffies + HZ;
637 sz->flush = 1;
638 add_timer(&sz->flush_timer);
639
640 sz->urb_in->dev = sz->udev;
641 if (usb_submit_urb(sz->urb_in, GFP_ATOMIC)) {
642 dprintk("open result = -EIO error submitting urb",
643 sz->driver->minor);
644 return -EIO;
645 }
646 sz->in_use++;
647
648 return 0;
649}
650
651static void streamzap_use_dec(void *data)
652{
653 struct usb_streamzap *sz = data;
654
655 if (!sz) {
656 dprintk("%s called with no context", -1, __func__);
657 return;
658 }
659 dprintk("set use dec", sz->driver->minor);
660
661 if (sz->flush) {
662 sz->flush = 0;
663 del_timer_sync(&sz->flush_timer);
664 }
665
666 usb_kill_urb(sz->urb_in);
667
668 stop_timer(sz);
669
670 sz->in_use--;
671}
672
673static long streamzap_ioctl(struct file *filep, unsigned int cmd,
674 unsigned long arg)
675{
676 int result = 0;
677 int val;
678 struct usb_streamzap *sz = lirc_get_pdata(filep);
679
680 switch (cmd) {
681 case LIRC_GET_REC_RESOLUTION:
682 result = put_user(STREAMZAP_RESOLUTION, (unsigned int *) arg);
683 break;
684 case LIRC_SET_REC_TIMEOUT:
685 result = get_user(val, (int *)arg);
686 if (result == 0) {
687 if (val == STREAMZAP_TIMEOUT * STREAMZAP_RESOLUTION)
688 sz->timeout_enabled = 1;
689 else if (val == 0)
690 sz->timeout_enabled = 0;
691 else
692 result = -EINVAL;
693 }
694 break;
695 default:
696 return lirc_dev_fop_ioctl(filep, cmd, arg);
697 }
698 return result;
699}
700
701/**
702 * streamzap_disconnect
703 *
704 * Called by the usb core when the device is removed from the system.
705 *
706 * This routine guarantees that the driver will not submit any more urbs
707 * by clearing dev->udev. It is also supposed to terminate any currently
708 * active urbs. Unfortunately, usb_bulk_msg(), used in streamzap_read(),
709 * does not provide any way to do this.
710 */
711static void streamzap_disconnect(struct usb_interface *interface)
712{
713 struct usb_streamzap *sz;
714 int errnum;
715 int minor;
716
717 sz = usb_get_intfdata(interface);
718
719 /* unregister from the LIRC sub-system */
720
721 errnum = lirc_unregister_driver(sz->driver->minor);
722 if (errnum != 0)
723 dprintk("error in lirc_unregister: (returned %d)",
724 sz->driver->minor, errnum);
725
726 lirc_buffer_free(sz->delay_buf);
727 lirc_buffer_free(sz->driver->rbuf);
728
729 /* unregister from the USB sub-system */
730
731 usb_free_urb(sz->urb_in);
732
733 usb_free_coherent(sz->udev, sz->buf_in_len, sz->buf_in, sz->dma_in);
734
735 minor = sz->driver->minor;
736 kfree(sz->driver->rbuf);
737 kfree(sz->driver);
738 kfree(sz->delay_buf);
739 kfree(sz);
740
741 printk(KERN_INFO DRIVER_NAME "[%d]: disconnected\n", minor);
742}
743
744static int streamzap_suspend(struct usb_interface *intf, pm_message_t message)
745{
746 struct usb_streamzap *sz = usb_get_intfdata(intf);
747
748 printk(KERN_INFO DRIVER_NAME "[%d]: suspend\n", sz->driver->minor);
749 if (sz->in_use) {
750 if (sz->flush) {
751 sz->flush = 0;
752 del_timer_sync(&sz->flush_timer);
753 }
754
755 stop_timer(sz);
756
757 usb_kill_urb(sz->urb_in);
758 }
759 return 0;
760}
761
762static int streamzap_resume(struct usb_interface *intf)
763{
764 struct usb_streamzap *sz = usb_get_intfdata(intf);
765
766 lirc_buffer_clear(sz->driver->rbuf);
767 lirc_buffer_clear(sz->delay_buf);
768
769 if (sz->in_use) {
770 sz->flush_timer.expires = jiffies + HZ;
771 sz->flush = 1;
772 add_timer(&sz->flush_timer);
773
774 sz->urb_in->dev = sz->udev;
775 if (usb_submit_urb(sz->urb_in, GFP_ATOMIC)) {
776 dprintk("open result = -EIO error submitting urb",
777 sz->driver->minor);
778 return -EIO;
779 }
780 }
781 return 0;
782}
783
784/**
785 * usb_streamzap_init
786 */
787static int __init usb_streamzap_init(void)
788{
789 int result;
790
791 /* register this driver with the USB subsystem */
792 result = usb_register(&streamzap_driver);
793
794 if (result) {
795 err("usb_register failed. Error number %d",
796 result);
797 return result;
798 }
799
800 printk(KERN_INFO DRIVER_NAME " " DRIVER_VERSION " registered\n");
801 return 0;
802}
803
804/**
805 * usb_streamzap_exit
806 */
807static void __exit usb_streamzap_exit(void)
808{
809 usb_deregister(&streamzap_driver);
810}
811
812
813module_init(usb_streamzap_init);
814module_exit(usb_streamzap_exit);
815
816MODULE_AUTHOR("Christoph Bartelmus, Greg Wickham, Adrian Dewhurst");
817MODULE_DESCRIPTION(DRIVER_DESC);
818MODULE_LICENSE("GPL");
819
820module_param(debug, bool, S_IRUGO | S_IWUSR);
821MODULE_PARM_DESC(debug, "Enable debugging messages");
diff --git a/drivers/staging/lirc/lirc_ttusbir.c b/drivers/staging/lirc/lirc_ttusbir.c
new file mode 100644
index 000000000000..e345ab9a004c
--- /dev/null
+++ b/drivers/staging/lirc/lirc_ttusbir.c
@@ -0,0 +1,396 @@
1/*
2 * lirc_ttusbir.c
3 *
4 * lirc_ttusbir - LIRC device driver for the TechnoTrend USB IR Receiver
5 *
6 * Copyright (C) 2007 Stefan Macher <st_maker-lirc@yahoo.de>
7 *
8 * This LIRC driver provides access to the TechnoTrend USB IR Receiver.
9 * The receiver delivers the IR signal as raw sampled true/false data in
10 * isochronous USB packets each of size 128 byte.
11 * Currently the driver reduces the sampling rate by factor of 8 as this
12 * is still more than enough to decode RC-5 - others should be analyzed.
13 * But the driver does not rely on RC-5 it should be able to decode every
14 * IR signal that is not too fast.
15 */
16
17/*
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 */
32
33#include <linux/version.h>
34#include <linux/kernel.h>
35#include <linux/init.h>
36#include <linux/module.h>
37#include <linux/errno.h>
38#include <linux/slab.h>
39#include <linux/usb.h>
40
41#include <media/lirc.h>
42#include <media/lirc_dev.h>
43
44MODULE_DESCRIPTION("TechnoTrend USB IR device driver for LIRC");
45MODULE_AUTHOR("Stefan Macher (st_maker-lirc@yahoo.de)");
46MODULE_LICENSE("GPL");
47
48/* #define DEBUG */
49#ifdef DEBUG
50#define DPRINTK printk
51#else
52#define DPRINTK(_x_, a...)
53#endif
54
55/* function declarations */
56static int probe(struct usb_interface *intf, const struct usb_device_id *id);
57static void disconnect(struct usb_interface *intf);
58static void urb_complete(struct urb *urb);
59static int set_use_inc(void *data);
60static void set_use_dec(void *data);
61
62static int num_urbs = 2;
63module_param(num_urbs, int, S_IRUGO);
64MODULE_PARM_DESC(num_urbs,
65 "Number of URBs in queue. Try to increase to 4 in case "
66 "of problems (default: 2; minimum: 2)");
67
68/* table of devices that work with this driver */
69static struct usb_device_id device_id_table[] = {
70 /* TechnoTrend USB IR Receiver */
71 { USB_DEVICE(0x0B48, 0x2003) },
72 /* Terminating entry */
73 { }
74};
75MODULE_DEVICE_TABLE(usb, device_id_table);
76
77/* USB driver definition */
78static struct usb_driver usb_driver = {
79 .name = "TTUSBIR",
80 .id_table = &(device_id_table[0]),
81 .probe = probe,
82 .disconnect = disconnect,
83};
84
85/* USB device definition */
86struct ttusbir_device {
87 struct usb_driver *usb_driver;
88 struct usb_device *udev;
89 struct usb_interface *interf;
90 struct usb_class_driver class_driver;
91 unsigned int ifnum; /* Interface number to use */
92 unsigned int alt_setting; /* alternate setting to use */
93 unsigned int endpoint; /* Endpoint to use */
94 struct urb **urb; /* num_urb URB pointers*/
95 char **buffer; /* 128 byte buffer for each URB */
96 struct lirc_buffer rbuf; /* Buffer towards LIRC */
97 struct lirc_driver driver;
98 int minor;
99 int last_pulse; /* remembers if last received byte was pulse or space */
100 int last_num; /* remembers how many last bytes appeared */
101 int opened;
102};
103
104/*** LIRC specific functions ***/
105static int set_use_inc(void *data)
106{
107 int i, retval;
108 struct ttusbir_device *ttusbir = data;
109
110 DPRINTK("Sending first URBs\n");
111 /* @TODO Do I need to check if I am already opened */
112 ttusbir->opened = 1;
113
114 for (i = 0; i < num_urbs; i++) {
115 retval = usb_submit_urb(ttusbir->urb[i], GFP_KERNEL);
116 if (retval) {
117 err("%s: usb_submit_urb failed on urb %d",
118 __func__, i);
119 return retval;
120 }
121 }
122 return 0;
123}
124
125static void set_use_dec(void *data)
126{
127 struct ttusbir_device *ttusbir = data;
128
129 DPRINTK("Device closed\n");
130
131 ttusbir->opened = 0;
132}
133
134/*** USB specific functions ***/
135
136/*
137 * This mapping table is used to do a very simple filtering of the
138 * input signal.
139 * For a value with at least 4 bits set it returns 0xFF otherwise
140 * 0x00. For faster IR signals this can not be used. But for RC-5 we
141 * still have about 14 samples per pulse/space, i.e. we sample with 14
142 * times higher frequency than the signal frequency
143 */
144const unsigned char map_table[] = {
145 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
146 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
147 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
148 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF,
149 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
150 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF,
151 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF,
152 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF,
153 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
154 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF,
155 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF,
156 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF,
157 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF,
158 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF,
159 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF,
160 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
161 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
162 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF,
163 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF,
164 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF,
165 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF,
166 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF,
167 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF,
168 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
169 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF,
170 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF,
171 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF,
172 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
173 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF,
174 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
175 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
176 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
177};
178
179static void urb_complete(struct urb *urb)
180{
181 struct ttusbir_device *ttusbir;
182 unsigned char *buf;
183 int i;
184 int l;
185
186 ttusbir = urb->context;
187
188 if (!ttusbir->opened)
189 return;
190
191 buf = (unsigned char *)urb->transfer_buffer;
192
193 for (i = 0; i < 128; i++) {
194 /* Here we do the filtering and some kind of down sampling */
195 buf[i] = ~map_table[buf[i]];
196 if (ttusbir->last_pulse == buf[i]) {
197 if (ttusbir->last_num < PULSE_MASK/63)
198 ttusbir->last_num++;
199 /*
200 * else we are in a idle period and do not need to
201 * increment any longer
202 */
203 } else {
204 l = ttusbir->last_num * 62; /* about 62 = us/byte */
205 if (ttusbir->last_pulse) /* pulse or space? */
206 l |= PULSE_BIT;
207 if (!lirc_buffer_full(&ttusbir->rbuf)) {
208 lirc_buffer_write(&ttusbir->rbuf, (void *)&l);
209 wake_up_interruptible(&ttusbir->rbuf.wait_poll);
210 }
211 ttusbir->last_num = 0;
212 ttusbir->last_pulse = buf[i];
213 }
214 }
215 usb_submit_urb(urb, GFP_ATOMIC); /* keep data rolling :-) */
216}
217
218/*
219 * Called whenever the USB subsystem thinks we could be the right driver
220 * to handle this device
221 */
222static int probe(struct usb_interface *intf, const struct usb_device_id *id)
223{
224 int alt_set, endp;
225 int found = 0;
226 int i, j;
227 int struct_size;
228 struct usb_host_interface *host_interf;
229 struct usb_interface_descriptor *interf_desc;
230 struct usb_host_endpoint *host_endpoint;
231 struct ttusbir_device *ttusbir;
232
233 DPRINTK("Module ttusbir probe\n");
234
235 /* To reduce memory fragmentation we use only one allocation */
236 struct_size = sizeof(struct ttusbir_device) +
237 (sizeof(struct urb *) * num_urbs) +
238 (sizeof(char *) * num_urbs) +
239 (num_urbs * 128);
240 ttusbir = kzalloc(struct_size, GFP_KERNEL);
241 if (!ttusbir)
242 return -ENOMEM;
243
244 ttusbir->urb = (struct urb **)((char *)ttusbir +
245 sizeof(struct ttusbir_device));
246 ttusbir->buffer = (char **)((char *)ttusbir->urb +
247 (sizeof(struct urb *) * num_urbs));
248 for (i = 0; i < num_urbs; i++)
249 ttusbir->buffer[i] = (char *)ttusbir->buffer +
250 (sizeof(char *)*num_urbs) + (i * 128);
251
252 ttusbir->usb_driver = &usb_driver;
253 ttusbir->alt_setting = -1;
254 /* @TODO check if error can be returned */
255 ttusbir->udev = usb_get_dev(interface_to_usbdev(intf));
256 ttusbir->interf = intf;
257 ttusbir->last_pulse = 0x00;
258 ttusbir->last_num = 0;
259
260 /*
261 * Now look for interface setting we can handle
262 * We are searching for the alt setting where end point
263 * 0x82 has max packet size 16
264 */
265 for (alt_set = 0; alt_set < intf->num_altsetting && !found; alt_set++) {
266 host_interf = &intf->altsetting[alt_set];
267 interf_desc = &host_interf->desc;
268 for (endp = 0; endp < interf_desc->bNumEndpoints; endp++) {
269 host_endpoint = &host_interf->endpoint[endp];
270 if ((host_endpoint->desc.bEndpointAddress == 0x82) &&
271 (host_endpoint->desc.wMaxPacketSize == 0x10)) {
272 ttusbir->alt_setting = alt_set;
273 ttusbir->endpoint = endp;
274 found = 1;
275 break;
276 }
277 }
278 }
279 if (ttusbir->alt_setting != -1)
280 DPRINTK("alt setting: %d\n", ttusbir->alt_setting);
281 else {
282 err("Could not find alternate setting\n");
283 kfree(ttusbir);
284 return -EINVAL;
285 }
286
287 /* OK lets setup this interface setting */
288 usb_set_interface(ttusbir->udev, 0, ttusbir->alt_setting);
289
290 /* Store device info in interface structure */
291 usb_set_intfdata(intf, ttusbir);
292
293 /* Register as a LIRC driver */
294 if (lirc_buffer_init(&ttusbir->rbuf, sizeof(int), 256) < 0) {
295 err("Could not get memory for LIRC data buffer\n");
296 usb_set_intfdata(intf, NULL);
297 kfree(ttusbir);
298 return -ENOMEM;
299 }
300 strcpy(ttusbir->driver.name, "TTUSBIR");
301 ttusbir->driver.minor = -1;
302 ttusbir->driver.code_length = 1;
303 ttusbir->driver.sample_rate = 0;
304 ttusbir->driver.data = ttusbir;
305 ttusbir->driver.add_to_buf = NULL;
306 ttusbir->driver.rbuf = &ttusbir->rbuf;
307 ttusbir->driver.set_use_inc = set_use_inc;
308 ttusbir->driver.set_use_dec = set_use_dec;
309 ttusbir->driver.dev = &intf->dev;
310 ttusbir->driver.owner = THIS_MODULE;
311 ttusbir->driver.features = LIRC_CAN_REC_MODE2;
312 ttusbir->minor = lirc_register_driver(&ttusbir->driver);
313 if (ttusbir->minor < 0) {
314 err("Error registering as LIRC driver\n");
315 usb_set_intfdata(intf, NULL);
316 lirc_buffer_free(&ttusbir->rbuf);
317 kfree(ttusbir);
318 return -EIO;
319 }
320
321 /* Allocate and setup the URB that we will use to talk to the device */
322 for (i = 0; i < num_urbs; i++) {
323 ttusbir->urb[i] = usb_alloc_urb(8, GFP_KERNEL);
324 if (!ttusbir->urb[i]) {
325 err("Could not allocate memory for the URB\n");
326 for (j = i - 1; j >= 0; j--)
327 kfree(ttusbir->urb[j]);
328 lirc_buffer_free(&ttusbir->rbuf);
329 lirc_unregister_driver(ttusbir->minor);
330 kfree(ttusbir);
331 usb_set_intfdata(intf, NULL);
332 return -ENOMEM;
333 }
334 ttusbir->urb[i]->dev = ttusbir->udev;
335 ttusbir->urb[i]->context = ttusbir;
336 ttusbir->urb[i]->pipe = usb_rcvisocpipe(ttusbir->udev,
337 ttusbir->endpoint);
338 ttusbir->urb[i]->interval = 1;
339 ttusbir->urb[i]->transfer_flags = URB_ISO_ASAP;
340 ttusbir->urb[i]->transfer_buffer = &ttusbir->buffer[i][0];
341 ttusbir->urb[i]->complete = urb_complete;
342 ttusbir->urb[i]->number_of_packets = 8;
343 ttusbir->urb[i]->transfer_buffer_length = 128;
344 for (j = 0; j < 8; j++) {
345 ttusbir->urb[i]->iso_frame_desc[j].offset = j*16;
346 ttusbir->urb[i]->iso_frame_desc[j].length = 16;
347 }
348 }
349 return 0;
350}
351
352/**
353 * Called when the driver is unloaded or the device is unplugged
354 */
355static void disconnect(struct usb_interface *intf)
356{
357 int i;
358 struct ttusbir_device *ttusbir;
359
360 DPRINTK("Module ttusbir disconnect\n");
361
362 ttusbir = (struct ttusbir_device *) usb_get_intfdata(intf);
363 usb_set_intfdata(intf, NULL);
364 lirc_unregister_driver(ttusbir->minor);
365 DPRINTK("unregistered\n");
366
367 for (i = 0; i < num_urbs; i++) {
368 usb_kill_urb(ttusbir->urb[i]);
369 usb_free_urb(ttusbir->urb[i]);
370 }
371 DPRINTK("URBs killed\n");
372 lirc_buffer_free(&ttusbir->rbuf);
373 kfree(ttusbir);
374}
375
376static int ttusbir_init_module(void)
377{
378 int result;
379
380 DPRINTK(KERN_DEBUG "Module ttusbir init\n");
381
382 /* register this driver with the USB subsystem */
383 result = usb_register(&usb_driver);
384 if (result)
385 err("usb_register failed. Error number %d", result);
386 return result;
387}
388
389static void ttusbir_exit_module(void)
390{
391 printk(KERN_DEBUG "Module ttusbir exit\n");
392 usb_deregister(&usb_driver);
393}
394
395module_init(ttusbir_init_module);
396module_exit(ttusbir_exit_module);
diff --git a/drivers/staging/lirc/lirc_zilog.c b/drivers/staging/lirc/lirc_zilog.c
new file mode 100644
index 000000000000..100caab10451
--- /dev/null
+++ b/drivers/staging/lirc/lirc_zilog.c
@@ -0,0 +1,1387 @@
1/*
2 * i2c IR lirc driver for devices with zilog IR processors
3 *
4 * Copyright (c) 2000 Gerd Knorr <kraxel@goldbach.in-berlin.de>
5 * modified for PixelView (BT878P+W/FM) by
6 * Michal Kochanowicz <mkochano@pld.org.pl>
7 * Christoph Bartelmus <lirc@bartelmus.de>
8 * modified for KNC ONE TV Station/Anubis Typhoon TView Tuner by
9 * Ulrich Mueller <ulrich.mueller42@web.de>
10 * modified for Asus TV-Box and Creative/VisionTek BreakOut-Box by
11 * Stefan Jahn <stefan@lkcc.org>
12 * modified for inclusion into kernel sources by
13 * Jerome Brock <jbrock@users.sourceforge.net>
14 * modified for Leadtek Winfast PVR2000 by
15 * Thomas Reitmayr (treitmayr@yahoo.com)
16 * modified for Hauppauge PVR-150 IR TX device by
17 * Mark Weaver <mark@npsl.co.uk>
18 * changed name from lirc_pvr150 to lirc_zilog, works on more than pvr-150
19 * Jarod Wilson <jarod@redhat.com>
20 *
21 * parts are cut&pasted from the lirc_i2c.c driver
22 *
23 * This program is free software; you can redistribute it and/or modify
24 * it under the terms of the GNU General Public License as published by
25 * the Free Software Foundation; either version 2 of the License, or
26 * (at your option) any later version.
27 *
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU General Public License for more details.
32 *
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, write to the Free Software
35 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
36 *
37 */
38
39
40#include <linux/version.h>
41#include <linux/module.h>
42#include <linux/kmod.h>
43#include <linux/kernel.h>
44#include <linux/sched.h>
45#include <linux/fs.h>
46#include <linux/poll.h>
47#include <linux/string.h>
48#include <linux/timer.h>
49#include <linux/delay.h>
50#include <linux/completion.h>
51#include <linux/errno.h>
52#include <linux/slab.h>
53#include <linux/i2c.h>
54#include <linux/firmware.h>
55#include <linux/vmalloc.h>
56
57#include <linux/mutex.h>
58#include <linux/kthread.h>
59
60#include <media/lirc_dev.h>
61#include <media/lirc.h>
62
63struct IR {
64 struct lirc_driver l;
65
66 /* Device info */
67 struct mutex ir_lock;
68 int open;
69
70 /* RX device */
71 struct i2c_client c_rx;
72 int have_rx;
73
74 /* RX device buffer & lock */
75 struct lirc_buffer buf;
76 struct mutex buf_lock;
77
78 /* RX polling thread data */
79 struct completion *t_notify;
80 struct completion *t_notify2;
81 int shutdown;
82 struct task_struct *task;
83
84 /* RX read data */
85 unsigned char b[3];
86
87 /* TX device */
88 struct i2c_client c_tx;
89 int need_boot;
90 int have_tx;
91};
92
93/* Minor -> data mapping */
94static struct IR *ir_devices[MAX_IRCTL_DEVICES];
95
96/* Block size for IR transmitter */
97#define TX_BLOCK_SIZE 99
98
99/* Hauppauge IR transmitter data */
100struct tx_data_struct {
101 /* Boot block */
102 unsigned char *boot_data;
103
104 /* Start of binary data block */
105 unsigned char *datap;
106
107 /* End of binary data block */
108 unsigned char *endp;
109
110 /* Number of installed codesets */
111 unsigned int num_code_sets;
112
113 /* Pointers to codesets */
114 unsigned char **code_sets;
115
116 /* Global fixed data template */
117 int fixed[TX_BLOCK_SIZE];
118};
119
120static struct tx_data_struct *tx_data;
121static struct mutex tx_data_lock;
122
123#define zilog_notify(s, args...) printk(KERN_NOTICE KBUILD_MODNAME ": " s, \
124 ## args)
125#define zilog_error(s, args...) printk(KERN_ERR KBUILD_MODNAME ": " s, ## args)
126
127#define ZILOG_HAUPPAUGE_IR_RX_NAME "Zilog/Hauppauge IR RX"
128#define ZILOG_HAUPPAUGE_IR_TX_NAME "Zilog/Hauppauge IR TX"
129
130/* module parameters */
131static int debug; /* debug output */
132static int disable_rx; /* disable RX device */
133static int disable_tx; /* disable TX device */
134static int minor = -1; /* minor number */
135
136#define dprintk(fmt, args...) \
137 do { \
138 if (debug) \
139 printk(KERN_DEBUG KBUILD_MODNAME ": " fmt, \
140 ## args); \
141 } while (0)
142
143static int add_to_buf(struct IR *ir)
144{
145 __u16 code;
146 unsigned char codes[2];
147 unsigned char keybuf[6];
148 int got_data = 0;
149 int ret;
150 int failures = 0;
151 unsigned char sendbuf[1] = { 0 };
152
153 if (lirc_buffer_full(&ir->buf)) {
154 dprintk("buffer overflow\n");
155 return -EOVERFLOW;
156 }
157
158 /*
159 * service the device as long as it is returning
160 * data and we have space
161 */
162 do {
163 /*
164 * Lock i2c bus for the duration. RX/TX chips interfere so
165 * this is worth it
166 */
167 mutex_lock(&ir->ir_lock);
168
169 /*
170 * Send random "poll command" (?) Windows driver does this
171 * and it is a good point to detect chip failure.
172 */
173 ret = i2c_master_send(&ir->c_rx, sendbuf, 1);
174 if (ret != 1) {
175 zilog_error("i2c_master_send failed with %d\n", ret);
176 if (failures >= 3) {
177 mutex_unlock(&ir->ir_lock);
178 zilog_error("unable to read from the IR chip "
179 "after 3 resets, giving up\n");
180 return ret;
181 }
182
183 /* Looks like the chip crashed, reset it */
184 zilog_error("polling the IR receiver chip failed, "
185 "trying reset\n");
186
187 set_current_state(TASK_UNINTERRUPTIBLE);
188 schedule_timeout((100 * HZ + 999) / 1000);
189 ir->need_boot = 1;
190
191 ++failures;
192 mutex_unlock(&ir->ir_lock);
193 continue;
194 }
195
196 ret = i2c_master_recv(&ir->c_rx, keybuf, sizeof(keybuf));
197 mutex_unlock(&ir->ir_lock);
198 if (ret != sizeof(keybuf)) {
199 zilog_error("i2c_master_recv failed with %d -- "
200 "keeping last read buffer\n", ret);
201 } else {
202 ir->b[0] = keybuf[3];
203 ir->b[1] = keybuf[4];
204 ir->b[2] = keybuf[5];
205 dprintk("key (0x%02x/0x%02x)\n", ir->b[0], ir->b[1]);
206 }
207
208 /* key pressed ? */
209#ifdef I2C_HW_B_HDPVR
210 if (ir->c_rx.adapter->id == I2C_HW_B_HDPVR) {
211 if (got_data && (keybuf[0] == 0x80))
212 return 0;
213 else if (got_data && (keybuf[0] == 0x00))
214 return -ENODATA;
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;
220
221 /* look what we have */
222 code = (((__u16)ir->b[0] & 0x7f) << 6) | (ir->b[1] >> 2);
223
224 codes[0] = (code >> 8) & 0xff;
225 codes[1] = code & 0xff;
226
227 /* return it */
228 lirc_buffer_write(&ir->buf, codes);
229 ++got_data;
230 } while (!lirc_buffer_full(&ir->buf));
231
232 return 0;
233}
234
235/*
236 * Main function of the polling thread -- from lirc_dev.
237 * We don't fit the LIRC model at all anymore. This is horrible, but
238 * basically we have a single RX/TX device with a nasty failure mode
239 * that needs to be accounted for across the pair. lirc lets us provide
240 * fops, but prevents us from using the internal polling, etc. if we do
241 * so. Hence the replication. Might be neater to extend the LIRC model
242 * to account for this but I'd think it's a very special case of seriously
243 * messed up hardware.
244 */
245static int lirc_thread(void *arg)
246{
247 struct IR *ir = arg;
248
249 if (ir->t_notify != NULL)
250 complete(ir->t_notify);
251
252 dprintk("poll thread started\n");
253
254 do {
255 if (ir->open) {
256 set_current_state(TASK_INTERRUPTIBLE);
257
258 /*
259 * This is ~113*2 + 24 + jitter (2*repeat gap +
260 * code length). We use this interval as the chip
261 * resets every time you poll it (bad!). This is
262 * therefore just sufficient to catch all of the
263 * button presses. It makes the remote much more
264 * responsive. You can see the difference by
265 * running irw and holding down a button. With
266 * 100ms, the old polling interval, you'll notice
267 * breaks in the repeat sequence corresponding to
268 * lost keypresses.
269 */
270 schedule_timeout((260 * HZ) / 1000);
271 if (ir->shutdown)
272 break;
273 if (!add_to_buf(ir))
274 wake_up_interruptible(&ir->buf.wait_poll);
275 } else {
276 /* if device not opened so we can sleep half a second */
277 set_current_state(TASK_INTERRUPTIBLE);
278 schedule_timeout(HZ/2);
279 }
280 } while (!ir->shutdown);
281
282 if (ir->t_notify2 != NULL)
283 wait_for_completion(ir->t_notify2);
284
285 ir->task = NULL;
286 if (ir->t_notify != NULL)
287 complete(ir->t_notify);
288
289 dprintk("poll thread ended\n");
290 return 0;
291}
292
293static int set_use_inc(void *data)
294{
295 struct IR *ir = data;
296
297 if (ir->l.owner == NULL || try_module_get(ir->l.owner) == 0)
298 return -ENODEV;
299
300 /* lock bttv in memory while /dev/lirc is in use */
301 /*
302 * this is completely broken code. lirc_unregister_driver()
303 * must be possible even when the device is open
304 */
305 if (ir->c_rx.addr)
306 i2c_use_client(&ir->c_rx);
307 if (ir->c_tx.addr)
308 i2c_use_client(&ir->c_tx);
309
310 return 0;
311}
312
313static void set_use_dec(void *data)
314{
315 struct IR *ir = data;
316
317 if (ir->c_rx.addr)
318 i2c_release_client(&ir->c_rx);
319 if (ir->c_tx.addr)
320 i2c_release_client(&ir->c_tx);
321 if (ir->l.owner != NULL)
322 module_put(ir->l.owner);
323}
324
325/* safe read of a uint32 (always network byte order) */
326static int read_uint32(unsigned char **data,
327 unsigned char *endp, unsigned int *val)
328{
329 if (*data + 4 > endp)
330 return 0;
331 *val = ((*data)[0] << 24) | ((*data)[1] << 16) |
332 ((*data)[2] << 8) | (*data)[3];
333 *data += 4;
334 return 1;
335}
336
337/* safe read of a uint8 */
338static int read_uint8(unsigned char **data,
339 unsigned char *endp, unsigned char *val)
340{
341 if (*data + 1 > endp)
342 return 0;
343 *val = *((*data)++);
344 return 1;
345}
346
347/* safe skipping of N bytes */
348static int skip(unsigned char **data,
349 unsigned char *endp, unsigned int distance)
350{
351 if (*data + distance > endp)
352 return 0;
353 *data += distance;
354 return 1;
355}
356
357/* decompress key data into the given buffer */
358static int get_key_data(unsigned char *buf,
359 unsigned int codeset, unsigned int key)
360{
361 unsigned char *data, *endp, *diffs, *key_block;
362 unsigned char keys, ndiffs, id;
363 unsigned int base, lim, pos, i;
364
365 /* Binary search for the codeset */
366 for (base = 0, lim = tx_data->num_code_sets; lim; lim >>= 1) {
367 pos = base + (lim >> 1);
368 data = tx_data->code_sets[pos];
369
370 if (!read_uint32(&data, tx_data->endp, &i))
371 goto corrupt;
372
373 if (i == codeset)
374 break;
375 else if (codeset > i) {
376 base = pos + 1;
377 --lim;
378 }
379 }
380 /* Not found? */
381 if (!lim)
382 return -EPROTO;
383
384 /* Set end of data block */
385 endp = pos < tx_data->num_code_sets - 1 ?
386 tx_data->code_sets[pos + 1] : tx_data->endp;
387
388 /* Read the block header */
389 if (!read_uint8(&data, endp, &keys) ||
390 !read_uint8(&data, endp, &ndiffs) ||
391 ndiffs > TX_BLOCK_SIZE || keys == 0)
392 goto corrupt;
393
394 /* Save diffs & skip */
395 diffs = data;
396 if (!skip(&data, endp, ndiffs))
397 goto corrupt;
398
399 /* Read the id of the first key */
400 if (!read_uint8(&data, endp, &id))
401 goto corrupt;
402
403 /* Unpack the first key's data */
404 for (i = 0; i < TX_BLOCK_SIZE; ++i) {
405 if (tx_data->fixed[i] == -1) {
406 if (!read_uint8(&data, endp, &buf[i]))
407 goto corrupt;
408 } else {
409 buf[i] = (unsigned char)tx_data->fixed[i];
410 }
411 }
412
413 /* Early out key found/not found */
414 if (key == id)
415 return 0;
416 if (keys == 1)
417 return -EPROTO;
418
419 /* Sanity check */
420 key_block = data;
421 if (!skip(&data, endp, (keys - 1) * (ndiffs + 1)))
422 goto corrupt;
423
424 /* Binary search for the key */
425 for (base = 0, lim = keys - 1; lim; lim >>= 1) {
426 /* Seek to block */
427 unsigned char *key_data;
428 pos = base + (lim >> 1);
429 key_data = key_block + (ndiffs + 1) * pos;
430
431 if (*key_data == key) {
432 /* skip key id */
433 ++key_data;
434
435 /* found, so unpack the diffs */
436 for (i = 0; i < ndiffs; ++i) {
437 unsigned char val;
438 if (!read_uint8(&key_data, endp, &val) ||
439 diffs[i] >= TX_BLOCK_SIZE)
440 goto corrupt;
441 buf[diffs[i]] = val;
442 }
443
444 return 0;
445 } else if (key > *key_data) {
446 base = pos + 1;
447 --lim;
448 }
449 }
450 /* Key not found */
451 return -EPROTO;
452
453corrupt:
454 zilog_error("firmware is corrupt\n");
455 return -EFAULT;
456}
457
458/* send a block of data to the IR TX device */
459static int send_data_block(struct IR *ir, unsigned char *data_block)
460{
461 int i, j, ret;
462 unsigned char buf[5];
463
464 for (i = 0; i < TX_BLOCK_SIZE;) {
465 int tosend = TX_BLOCK_SIZE - i;
466 if (tosend > 4)
467 tosend = 4;
468 buf[0] = (unsigned char)(i + 1);
469 for (j = 0; j < tosend; ++j)
470 buf[1 + j] = data_block[i + j];
471 dprintk("%02x %02x %02x %02x %02x",
472 buf[0], buf[1], buf[2], buf[3], buf[4]);
473 ret = i2c_master_send(&ir->c_tx, buf, tosend + 1);
474 if (ret != tosend + 1) {
475 zilog_error("i2c_master_send failed with %d\n", ret);
476 return ret < 0 ? ret : -EFAULT;
477 }
478 i += tosend;
479 }
480 return 0;
481}
482
483/* send boot data to the IR TX device */
484static int send_boot_data(struct IR *ir)
485{
486 int ret;
487 unsigned char buf[4];
488
489 /* send the boot block */
490 ret = send_data_block(ir, tx_data->boot_data);
491 if (ret != 0)
492 return ret;
493
494 /* kick it off? */
495 buf[0] = 0x00;
496 buf[1] = 0x20;
497 ret = i2c_master_send(&ir->c_tx, buf, 2);
498 if (ret != 2) {
499 zilog_error("i2c_master_send failed with %d\n", ret);
500 return ret < 0 ? ret : -EFAULT;
501 }
502 ret = i2c_master_send(&ir->c_tx, buf, 1);
503 if (ret != 1) {
504 zilog_error("i2c_master_send failed with %d\n", ret);
505 return ret < 0 ? ret : -EFAULT;
506 }
507
508 /* Here comes the firmware version... (hopefully) */
509 ret = i2c_master_recv(&ir->c_tx, buf, 4);
510 if (ret != 4) {
511 zilog_error("i2c_master_recv failed with %d\n", ret);
512 return 0;
513 }
514 if (buf[0] != 0x80) {
515 zilog_error("unexpected IR TX response: %02x\n", buf[0]);
516 return 0;
517 }
518 zilog_notify("Zilog/Hauppauge IR blaster firmware version "
519 "%d.%d.%d loaded\n", buf[1], buf[2], buf[3]);
520
521 return 0;
522}
523
524/* unload "firmware", lock held */
525static void fw_unload_locked(void)
526{
527 if (tx_data) {
528 if (tx_data->code_sets)
529 vfree(tx_data->code_sets);
530
531 if (tx_data->datap)
532 vfree(tx_data->datap);
533
534 vfree(tx_data);
535 tx_data = NULL;
536 dprintk("successfully unloaded IR blaster firmware\n");
537 }
538}
539
540/* unload "firmware" for the IR TX device */
541static void fw_unload(void)
542{
543 mutex_lock(&tx_data_lock);
544 fw_unload_locked();
545 mutex_unlock(&tx_data_lock);
546}
547
548/* load "firmware" for the IR TX device */
549static int fw_load(struct IR *ir)
550{
551 int ret;
552 unsigned int i;
553 unsigned char *data, version, num_global_fixed;
554 const struct firmware *fw_entry;
555
556 /* Already loaded? */
557 mutex_lock(&tx_data_lock);
558 if (tx_data) {
559 ret = 0;
560 goto out;
561 }
562
563 /* Request codeset data file */
564 ret = request_firmware(&fw_entry, "haup-ir-blaster.bin", &ir->c_tx.dev);
565 if (ret != 0) {
566 zilog_error("firmware haup-ir-blaster.bin not available "
567 "(%d)\n", ret);
568 ret = ret < 0 ? ret : -EFAULT;
569 goto out;
570 }
571 dprintk("firmware of size %zu loaded\n", fw_entry->size);
572
573 /* Parse the file */
574 tx_data = vmalloc(sizeof(*tx_data));
575 if (tx_data == NULL) {
576 zilog_error("out of memory\n");
577 release_firmware(fw_entry);
578 ret = -ENOMEM;
579 goto out;
580 }
581 tx_data->code_sets = NULL;
582
583 /* Copy the data so hotplug doesn't get confused and timeout */
584 tx_data->datap = vmalloc(fw_entry->size);
585 if (tx_data->datap == NULL) {
586 zilog_error("out of memory\n");
587 release_firmware(fw_entry);
588 vfree(tx_data);
589 ret = -ENOMEM;
590 goto out;
591 }
592 memcpy(tx_data->datap, fw_entry->data, fw_entry->size);
593 tx_data->endp = tx_data->datap + fw_entry->size;
594 release_firmware(fw_entry); fw_entry = NULL;
595
596 /* Check version */
597 data = tx_data->datap;
598 if (!read_uint8(&data, tx_data->endp, &version))
599 goto corrupt;
600 if (version != 1) {
601 zilog_error("unsupported code set file version (%u, expected"
602 "1) -- please upgrade to a newer driver",
603 version);
604 fw_unload_locked();
605 ret = -EFAULT;
606 goto out;
607 }
608
609 /* Save boot block for later */
610 tx_data->boot_data = data;
611 if (!skip(&data, tx_data->endp, TX_BLOCK_SIZE))
612 goto corrupt;
613
614 if (!read_uint32(&data, tx_data->endp,
615 &tx_data->num_code_sets))
616 goto corrupt;
617
618 dprintk("%u IR blaster codesets loaded\n", tx_data->num_code_sets);
619
620 tx_data->code_sets = vmalloc(
621 tx_data->num_code_sets * sizeof(char *));
622 if (tx_data->code_sets == NULL) {
623 fw_unload_locked();
624 ret = -ENOMEM;
625 goto out;
626 }
627
628 for (i = 0; i < TX_BLOCK_SIZE; ++i)
629 tx_data->fixed[i] = -1;
630
631 /* Read global fixed data template */
632 if (!read_uint8(&data, tx_data->endp, &num_global_fixed) ||
633 num_global_fixed > TX_BLOCK_SIZE)
634 goto corrupt;
635 for (i = 0; i < num_global_fixed; ++i) {
636 unsigned char pos, val;
637 if (!read_uint8(&data, tx_data->endp, &pos) ||
638 !read_uint8(&data, tx_data->endp, &val) ||
639 pos >= TX_BLOCK_SIZE)
640 goto corrupt;
641 tx_data->fixed[pos] = (int)val;
642 }
643
644 /* Filch out the position of each code set */
645 for (i = 0; i < tx_data->num_code_sets; ++i) {
646 unsigned int id;
647 unsigned char keys;
648 unsigned char ndiffs;
649
650 /* Save the codeset position */
651 tx_data->code_sets[i] = data;
652
653 /* Read header */
654 if (!read_uint32(&data, tx_data->endp, &id) ||
655 !read_uint8(&data, tx_data->endp, &keys) ||
656 !read_uint8(&data, tx_data->endp, &ndiffs) ||
657 ndiffs > TX_BLOCK_SIZE || keys == 0)
658 goto corrupt;
659
660 /* skip diff positions */
661 if (!skip(&data, tx_data->endp, ndiffs))
662 goto corrupt;
663
664 /*
665 * After the diffs we have the first key id + data -
666 * global fixed
667 */
668 if (!skip(&data, tx_data->endp,
669 1 + TX_BLOCK_SIZE - num_global_fixed))
670 goto corrupt;
671
672 /* Then we have keys-1 blocks of key id+diffs */
673 if (!skip(&data, tx_data->endp,
674 (ndiffs + 1) * (keys - 1)))
675 goto corrupt;
676 }
677 ret = 0;
678 goto out;
679
680corrupt:
681 zilog_error("firmware is corrupt\n");
682 fw_unload_locked();
683 ret = -EFAULT;
684
685out:
686 mutex_unlock(&tx_data_lock);
687 return ret;
688}
689
690/* initialise the IR TX device */
691static int tx_init(struct IR *ir)
692{
693 int ret;
694
695 /* Load 'firmware' */
696 ret = fw_load(ir);
697 if (ret != 0)
698 return ret;
699
700 /* Send boot block */
701 ret = send_boot_data(ir);
702 if (ret != 0)
703 return ret;
704 ir->need_boot = 0;
705
706 /* Looks good */
707 return 0;
708}
709
710/* do nothing stub to make LIRC happy */
711static loff_t lseek(struct file *filep, loff_t offset, int orig)
712{
713 return -ESPIPE;
714}
715
716/* copied from lirc_dev */
717static ssize_t read(struct file *filep, char *outbuf, size_t n, loff_t *ppos)
718{
719 struct IR *ir = (struct IR *)filep->private_data;
720 unsigned char buf[ir->buf.chunk_size];
721 int ret = 0, written = 0;
722 DECLARE_WAITQUEUE(wait, current);
723
724 dprintk("read called\n");
725 if (ir->c_rx.addr == 0)
726 return -ENODEV;
727
728 if (mutex_lock_interruptible(&ir->buf_lock))
729 return -ERESTARTSYS;
730
731 if (n % ir->buf.chunk_size) {
732 dprintk("read result = -EINVAL\n");
733 mutex_unlock(&ir->buf_lock);
734 return -EINVAL;
735 }
736
737 /*
738 * we add ourselves to the task queue before buffer check
739 * to avoid losing scan code (in case when queue is awaken somewhere
740 * between while condition checking and scheduling)
741 */
742 add_wait_queue(&ir->buf.wait_poll, &wait);
743 set_current_state(TASK_INTERRUPTIBLE);
744
745 /*
746 * while we didn't provide 'length' bytes, device is opened in blocking
747 * mode and 'copy_to_user' is happy, wait for data.
748 */
749 while (written < n && ret == 0) {
750 if (lirc_buffer_empty(&ir->buf)) {
751 /*
752 * According to the read(2) man page, 'written' can be
753 * returned as less than 'n', instead of blocking
754 * again, returning -EWOULDBLOCK, or returning
755 * -ERESTARTSYS
756 */
757 if (written)
758 break;
759 if (filep->f_flags & O_NONBLOCK) {
760 ret = -EWOULDBLOCK;
761 break;
762 }
763 if (signal_pending(current)) {
764 ret = -ERESTARTSYS;
765 break;
766 }
767 schedule();
768 set_current_state(TASK_INTERRUPTIBLE);
769 } else {
770 lirc_buffer_read(&ir->buf, buf);
771 ret = copy_to_user((void *)outbuf+written, buf,
772 ir->buf.chunk_size);
773 written += ir->buf.chunk_size;
774 }
775 }
776
777 remove_wait_queue(&ir->buf.wait_poll, &wait);
778 set_current_state(TASK_RUNNING);
779 mutex_unlock(&ir->buf_lock);
780
781 dprintk("read result = %s (%d)\n",
782 ret ? "-EFAULT" : "OK", ret);
783
784 return ret ? ret : written;
785}
786
787/* send a keypress to the IR TX device */
788static int send_code(struct IR *ir, unsigned int code, unsigned int key)
789{
790 unsigned char data_block[TX_BLOCK_SIZE];
791 unsigned char buf[2];
792 int i, ret;
793
794 /* Get data for the codeset/key */
795 ret = get_key_data(data_block, code, key);
796
797 if (ret == -EPROTO) {
798 zilog_error("failed to get data for code %u, key %u -- check "
799 "lircd.conf entries\n", code, key);
800 return ret;
801 } else if (ret != 0)
802 return ret;
803
804 /* Send the data block */
805 ret = send_data_block(ir, data_block);
806 if (ret != 0)
807 return ret;
808
809 /* Send data block length? */
810 buf[0] = 0x00;
811 buf[1] = 0x40;
812 ret = i2c_master_send(&ir->c_tx, buf, 2);
813 if (ret != 2) {
814 zilog_error("i2c_master_send failed with %d\n", ret);
815 return ret < 0 ? ret : -EFAULT;
816 }
817 ret = i2c_master_send(&ir->c_tx, buf, 1);
818 if (ret != 1) {
819 zilog_error("i2c_master_send failed with %d\n", ret);
820 return ret < 0 ? ret : -EFAULT;
821 }
822
823 /* Send finished download? */
824 ret = i2c_master_recv(&ir->c_tx, buf, 1);
825 if (ret != 1) {
826 zilog_error("i2c_master_recv failed with %d\n", ret);
827 return ret < 0 ? ret : -EFAULT;
828 }
829 if (buf[0] != 0xA0) {
830 zilog_error("unexpected IR TX response #1: %02x\n",
831 buf[0]);
832 return -EFAULT;
833 }
834
835 /* Send prepare command? */
836 buf[0] = 0x00;
837 buf[1] = 0x80;
838 ret = i2c_master_send(&ir->c_tx, buf, 2);
839 if (ret != 2) {
840 zilog_error("i2c_master_send failed with %d\n", ret);
841 return ret < 0 ? ret : -EFAULT;
842 }
843
844#ifdef I2C_HW_B_HDPVR
845 /*
846 * 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
848 * going to skip this whole mess and say we're done on the HD PVR
849 */
850 if (ir->c_rx.adapter->id == I2C_HW_B_HDPVR)
851 goto done;
852#endif
853
854 /*
855 * This bit NAKs until the device is ready, so we retry it
856 * sleeping a bit each time. This seems to be what the windows
857 * driver does, approximately.
858 * Try for up to 1s.
859 */
860 for (i = 0; i < 20; ++i) {
861 set_current_state(TASK_UNINTERRUPTIBLE);
862 schedule_timeout((50 * HZ + 999) / 1000);
863 ret = i2c_master_send(&ir->c_tx, buf, 1);
864 if (ret == 1)
865 break;
866 dprintk("NAK expected: i2c_master_send "
867 "failed with %d (try %d)\n", ret, i+1);
868 }
869 if (ret != 1) {
870 zilog_error("IR TX chip never got ready: last i2c_master_send "
871 "failed with %d\n", ret);
872 return ret < 0 ? ret : -EFAULT;
873 }
874
875 /* Seems to be an 'ok' response */
876 i = i2c_master_recv(&ir->c_tx, buf, 1);
877 if (i != 1) {
878 zilog_error("i2c_master_recv failed with %d\n", ret);
879 return -EFAULT;
880 }
881 if (buf[0] != 0x80) {
882 zilog_error("unexpected IR TX response #2: %02x\n", buf[0]);
883 return -EFAULT;
884 }
885
886done:
887 /* Oh good, it worked */
888 dprintk("sent code %u, key %u\n", code, key);
889 return 0;
890}
891
892/*
893 * Write a code to the device. We take in a 32-bit number (an int) and then
894 * decode this to a codeset/key index. The key data is then decompressed and
895 * sent to the device. We have a spin lock as per i2c documentation to prevent
896 * multiple concurrent sends which would probably cause the device to explode.
897 */
898static ssize_t write(struct file *filep, const char *buf, size_t n,
899 loff_t *ppos)
900{
901 struct IR *ir = (struct IR *)filep->private_data;
902 size_t i;
903 int failures = 0;
904
905 if (ir->c_tx.addr == 0)
906 return -ENODEV;
907
908 /* Validate user parameters */
909 if (n % sizeof(int))
910 return -EINVAL;
911
912 /* Lock i2c bus for the duration */
913 mutex_lock(&ir->ir_lock);
914
915 /* Send each keypress */
916 for (i = 0; i < n;) {
917 int ret = 0;
918 int command;
919
920 if (copy_from_user(&command, buf + i, sizeof(command))) {
921 mutex_unlock(&ir->ir_lock);
922 return -EFAULT;
923 }
924
925 /* Send boot data first if required */
926 if (ir->need_boot == 1) {
927 ret = send_boot_data(ir);
928 if (ret == 0)
929 ir->need_boot = 0;
930 }
931
932 /* Send the code */
933 if (ret == 0) {
934 ret = send_code(ir, (unsigned)command >> 16,
935 (unsigned)command & 0xFFFF);
936 if (ret == -EPROTO) {
937 mutex_unlock(&ir->ir_lock);
938 return ret;
939 }
940 }
941
942 /*
943 * Hmm, a failure. If we've had a few then give up, otherwise
944 * try a reset
945 */
946 if (ret != 0) {
947 /* Looks like the chip crashed, reset it */
948 zilog_error("sending to the IR transmitter chip "
949 "failed, trying reset\n");
950
951 if (failures >= 3) {
952 zilog_error("unable to send to the IR chip "
953 "after 3 resets, giving up\n");
954 mutex_unlock(&ir->ir_lock);
955 return ret;
956 }
957 set_current_state(TASK_UNINTERRUPTIBLE);
958 schedule_timeout((100 * HZ + 999) / 1000);
959 ir->need_boot = 1;
960 ++failures;
961 } else
962 i += sizeof(int);
963 }
964
965 /* Release i2c bus */
966 mutex_unlock(&ir->ir_lock);
967
968 /* All looks good */
969 return n;
970}
971
972/* copied from lirc_dev */
973static unsigned int poll(struct file *filep, poll_table *wait)
974{
975 struct IR *ir = (struct IR *)filep->private_data;
976 unsigned int ret;
977
978 dprintk("poll called\n");
979 if (ir->c_rx.addr == 0)
980 return -ENODEV;
981
982 mutex_lock(&ir->buf_lock);
983
984 poll_wait(filep, &ir->buf.wait_poll, wait);
985
986 dprintk("poll result = %s\n",
987 lirc_buffer_empty(&ir->buf) ? "0" : "POLLIN|POLLRDNORM");
988
989 ret = lirc_buffer_empty(&ir->buf) ? 0 : (POLLIN|POLLRDNORM);
990
991 mutex_unlock(&ir->buf_lock);
992 return ret;
993}
994
995static long ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
996{
997 struct IR *ir = (struct IR *)filep->private_data;
998 int result;
999 unsigned long mode, features = 0;
1000
1001 if (ir->c_rx.addr != 0)
1002 features |= LIRC_CAN_REC_LIRCCODE;
1003 if (ir->c_tx.addr != 0)
1004 features |= LIRC_CAN_SEND_PULSE;
1005
1006 switch (cmd) {
1007 case LIRC_GET_LENGTH:
1008 result = put_user((unsigned long)13,
1009 (unsigned long *)arg);
1010 break;
1011 case LIRC_GET_FEATURES:
1012 result = put_user(features, (unsigned long *) arg);
1013 break;
1014 case LIRC_GET_REC_MODE:
1015 if (!(features&LIRC_CAN_REC_MASK))
1016 return -ENOSYS;
1017
1018 result = put_user(LIRC_REC2MODE
1019 (features&LIRC_CAN_REC_MASK),
1020 (unsigned long *)arg);
1021 break;
1022 case LIRC_SET_REC_MODE:
1023 if (!(features&LIRC_CAN_REC_MASK))
1024 return -ENOSYS;
1025
1026 result = get_user(mode, (unsigned long *)arg);
1027 if (!result && !(LIRC_MODE2REC(mode) & features))
1028 result = -EINVAL;
1029 break;
1030 case LIRC_GET_SEND_MODE:
1031 if (!(features&LIRC_CAN_SEND_MASK))
1032 return -ENOSYS;
1033
1034 result = put_user(LIRC_MODE_PULSE, (unsigned long *) arg);
1035 break;
1036 case LIRC_SET_SEND_MODE:
1037 if (!(features&LIRC_CAN_SEND_MASK))
1038 return -ENOSYS;
1039
1040 result = get_user(mode, (unsigned long *) arg);
1041 if (!result && mode != LIRC_MODE_PULSE)
1042 return -EINVAL;
1043 break;
1044 default:
1045 return -EINVAL;
1046 }
1047 return result;
1048}
1049
1050/*
1051 * Open the IR device. Get hold of our IR structure and
1052 * stash it in private_data for the file
1053 */
1054static int open(struct inode *node, struct file *filep)
1055{
1056 struct IR *ir;
1057 int ret;
1058
1059 /* find our IR struct */
1060 unsigned minor = MINOR(node->i_rdev);
1061 if (minor >= MAX_IRCTL_DEVICES) {
1062 dprintk("minor %d: open result = -ENODEV\n",
1063 minor);
1064 return -ENODEV;
1065 }
1066 ir = ir_devices[minor];
1067
1068 /* increment in use count */
1069 mutex_lock(&ir->ir_lock);
1070 ++ir->open;
1071 ret = set_use_inc(ir);
1072 if (ret != 0) {
1073 --ir->open;
1074 mutex_unlock(&ir->ir_lock);
1075 return ret;
1076 }
1077 mutex_unlock(&ir->ir_lock);
1078
1079 /* stash our IR struct */
1080 filep->private_data = ir;
1081
1082 return 0;
1083}
1084
1085/* Close the IR device */
1086static int close(struct inode *node, struct file *filep)
1087{
1088 /* find our IR struct */
1089 struct IR *ir = (struct IR *)filep->private_data;
1090 if (ir == NULL) {
1091 zilog_error("close: no private_data attached to the file!\n");
1092 return -ENODEV;
1093 }
1094
1095 /* decrement in use count */
1096 mutex_lock(&ir->ir_lock);
1097 --ir->open;
1098 set_use_dec(ir);
1099 mutex_unlock(&ir->ir_lock);
1100
1101 return 0;
1102}
1103
1104static struct lirc_driver lirc_template = {
1105 .name = "lirc_zilog",
1106 .set_use_inc = set_use_inc,
1107 .set_use_dec = set_use_dec,
1108 .owner = THIS_MODULE
1109};
1110
1111static int ir_remove(struct i2c_client *client);
1112static 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);
1114
1115static const struct i2c_device_id ir_transceiver_id[] = {
1116 /* Generic entry for any IR transceiver */
1117 { "ir_video", 0 },
1118 /* IR device specific entries should be added here */
1119 { "ir_tx_z8f0811_haup", 0 },
1120 { "ir_rx_z8f0811_haup", 0 },
1121 { }
1122};
1123
1124static struct i2c_driver driver = {
1125 .driver = {
1126 .owner = THIS_MODULE,
1127 .name = "Zilog/Hauppauge i2c IR",
1128 },
1129 .probe = ir_probe,
1130 .remove = ir_remove,
1131 .command = ir_command,
1132 .id_table = ir_transceiver_id,
1133};
1134
1135static const struct file_operations lirc_fops = {
1136 .owner = THIS_MODULE,
1137 .llseek = lseek,
1138 .read = read,
1139 .write = write,
1140 .poll = poll,
1141 .unlocked_ioctl = ioctl,
1142 .open = open,
1143 .release = close
1144};
1145
1146static int ir_remove(struct i2c_client *client)
1147{
1148 struct IR *ir = i2c_get_clientdata(client);
1149
1150 mutex_lock(&ir->ir_lock);
1151
1152 if (ir->have_rx || ir->have_tx) {
1153 DECLARE_COMPLETION(tn);
1154 DECLARE_COMPLETION(tn2);
1155
1156 /* end up polling thread */
1157 if (ir->task && !IS_ERR(ir->task)) {
1158 ir->t_notify = &tn;
1159 ir->t_notify2 = &tn2;
1160 ir->shutdown = 1;
1161 wake_up_process(ir->task);
1162 complete(&tn2);
1163 wait_for_completion(&tn);
1164 ir->t_notify = NULL;
1165 ir->t_notify2 = NULL;
1166 }
1167
1168 } else {
1169 mutex_unlock(&ir->ir_lock);
1170 zilog_error("%s: detached from something we didn't "
1171 "attach to\n", __func__);
1172 return -ENODEV;
1173 }
1174
1175 /* unregister lirc driver */
1176 if (ir->l.minor >= 0 && ir->l.minor < MAX_IRCTL_DEVICES) {
1177 lirc_unregister_driver(ir->l.minor);
1178 ir_devices[ir->l.minor] = NULL;
1179 }
1180
1181 /* free memory */
1182 lirc_buffer_free(&ir->buf);
1183 mutex_unlock(&ir->ir_lock);
1184 kfree(ir);
1185
1186 return 0;
1187}
1188
1189static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
1190{
1191 struct IR *ir = NULL;
1192 struct i2c_adapter *adap = client->adapter;
1193 char buf;
1194 int ret;
1195 int have_rx = 0, have_tx = 0;
1196
1197 dprintk("%s: adapter id=0x%x, client addr=0x%02x\n",
1198 __func__, adap->id, client->addr);
1199
1200 /*
1201 * The external IR receiver is at i2c address 0x71.
1202 * The IR transmitter is at 0x70.
1203 */
1204 client->addr = 0x70;
1205
1206 if (!disable_tx) {
1207 if (i2c_master_recv(client, &buf, 1) == 1)
1208 have_tx = 1;
1209 dprintk("probe 0x70 @ %s: %s\n",
1210 adap->name, have_tx ? "success" : "failed");
1211 }
1212
1213 if (!disable_rx) {
1214 client->addr = 0x71;
1215 if (i2c_master_recv(client, &buf, 1) == 1)
1216 have_rx = 1;
1217 dprintk("probe 0x71 @ %s: %s\n",
1218 adap->name, have_rx ? "success" : "failed");
1219 }
1220
1221 if (!(have_rx || have_tx)) {
1222 zilog_error("%s: no devices found\n", adap->name);
1223 goto out_nodev;
1224 }
1225
1226 printk(KERN_INFO "lirc_zilog: chip found with %s\n",
1227 have_rx && have_tx ? "RX and TX" :
1228 have_rx ? "RX only" : "TX only");
1229
1230 ir = kzalloc(sizeof(struct IR), GFP_KERNEL);
1231
1232 if (!ir)
1233 goto out_nomem;
1234
1235 ret = lirc_buffer_init(&ir->buf, 2, BUFLEN / 2);
1236 if (ret)
1237 goto out_nomem;
1238
1239 mutex_init(&ir->ir_lock);
1240 mutex_init(&ir->buf_lock);
1241 ir->need_boot = 1;
1242
1243 memcpy(&ir->l, &lirc_template, sizeof(struct lirc_driver));
1244 ir->l.minor = -1;
1245
1246 /* I2C attach to device */
1247 i2c_set_clientdata(client, ir);
1248
1249 /* initialise RX device */
1250 if (have_rx) {
1251 DECLARE_COMPLETION(tn);
1252 memcpy(&ir->c_rx, client, sizeof(struct i2c_client));
1253
1254 ir->c_rx.addr = 0x71;
1255 strlcpy(ir->c_rx.name, ZILOG_HAUPPAUGE_IR_RX_NAME,
1256 I2C_NAME_SIZE);
1257
1258 /* try to fire up polling thread */
1259 ir->t_notify = &tn;
1260 ir->task = kthread_run(lirc_thread, ir, "lirc_zilog");
1261 if (IS_ERR(ir->task)) {
1262 ret = PTR_ERR(ir->task);
1263 zilog_error("lirc_register_driver: cannot run "
1264 "poll thread %d\n", ret);
1265 goto err;
1266 }
1267 wait_for_completion(&tn);
1268 ir->t_notify = NULL;
1269 ir->have_rx = 1;
1270 }
1271
1272 /* initialise TX device */
1273 if (have_tx) {
1274 memcpy(&ir->c_tx, client, sizeof(struct i2c_client));
1275 ir->c_tx.addr = 0x70;
1276 strlcpy(ir->c_tx.name, ZILOG_HAUPPAUGE_IR_TX_NAME,
1277 I2C_NAME_SIZE);
1278 ir->have_tx = 1;
1279 }
1280
1281 /* set lirc_dev stuff */
1282 ir->l.code_length = 13;
1283 ir->l.rbuf = &ir->buf;
1284 ir->l.fops = &lirc_fops;
1285 ir->l.data = ir;
1286 ir->l.minor = minor;
1287 ir->l.dev = &adap->dev;
1288 ir->l.sample_rate = 0;
1289
1290 /* register with lirc */
1291 ir->l.minor = lirc_register_driver(&ir->l);
1292 if (ir->l.minor < 0 || ir->l.minor >= MAX_IRCTL_DEVICES) {
1293 zilog_error("ir_attach: \"minor\" must be between 0 and %d "
1294 "(%d)!\n", MAX_IRCTL_DEVICES-1, ir->l.minor);
1295 ret = -EBADRQC;
1296 goto err;
1297 }
1298
1299 /* store this for getting back in open() later on */
1300 ir_devices[ir->l.minor] = ir;
1301
1302 /*
1303 * if we have the tx device, load the 'firmware'. We do this
1304 * after registering with lirc as otherwise hotplug seems to take
1305 * 10s to create the lirc device.
1306 */
1307 if (have_tx) {
1308 /* Special TX init */
1309 ret = tx_init(ir);
1310 if (ret != 0)
1311 goto err;
1312 }
1313
1314 return 0;
1315
1316err:
1317 /* undo everything, hopefully... */
1318 if (ir->c_rx.addr)
1319 ir_remove(&ir->c_rx);
1320 if (ir->c_tx.addr)
1321 ir_remove(&ir->c_tx);
1322 return ret;
1323
1324out_nodev:
1325 zilog_error("no device found\n");
1326 return -ENODEV;
1327
1328out_nomem:
1329 zilog_error("memory allocation failure\n");
1330 kfree(ir);
1331 return -ENOMEM;
1332}
1333
1334static int ir_command(struct i2c_client *client, unsigned int cmd, void *arg)
1335{
1336 /* nothing */
1337 return 0;
1338}
1339
1340static int __init zilog_init(void)
1341{
1342 int ret;
1343
1344 zilog_notify("Zilog/Hauppauge IR driver initializing\n");
1345
1346 mutex_init(&tx_data_lock);
1347
1348 request_module("firmware_class");
1349
1350 ret = i2c_add_driver(&driver);
1351 if (ret)
1352 zilog_error("initialization failed\n");
1353 else
1354 zilog_notify("initialization complete\n");
1355
1356 return ret;
1357}
1358
1359static void __exit zilog_exit(void)
1360{
1361 i2c_del_driver(&driver);
1362 /* if loaded */
1363 fw_unload();
1364 zilog_notify("Zilog/Hauppauge IR driver unloaded\n");
1365}
1366
1367module_init(zilog_init);
1368module_exit(zilog_exit);
1369
1370MODULE_DESCRIPTION("Zilog/Hauppauge infrared transmitter driver (i2c stack)");
1371MODULE_AUTHOR("Gerd Knorr, Michal Kochanowicz, Christoph Bartelmus, "
1372 "Ulrich Mueller, Stefan Jahn, Jerome Brock, Mark Weaver");
1373MODULE_LICENSE("GPL");
1374/* for compat with old name, which isn't all that accurate anymore */
1375MODULE_ALIAS("lirc_pvr150");
1376
1377module_param(minor, int, 0444);
1378MODULE_PARM_DESC(minor, "Preferred minor device number");
1379
1380module_param(debug, bool, 0644);
1381MODULE_PARM_DESC(debug, "Enable debugging messages");
1382
1383module_param(disable_rx, bool, 0644);
1384MODULE_PARM_DESC(disable_rx, "Disable the IR receiver device");
1385
1386module_param(disable_tx, bool, 0644);
1387MODULE_PARM_DESC(disable_tx, "Disable the IR transmitter device");
diff --git a/drivers/staging/tm6000/Kconfig b/drivers/staging/tm6000/Kconfig
index 3657e33e8817..c725356cc346 100644
--- a/drivers/staging/tm6000/Kconfig
+++ b/drivers/staging/tm6000/Kconfig
@@ -26,8 +26,8 @@ config VIDEO_TM6000_ALSA
26 module will be called tm6000-alsa. 26 module will be called tm6000-alsa.
27 27
28config VIDEO_TM6000_DVB 28config VIDEO_TM6000_DVB
29 bool "DVB Support for tm6000 based TV cards" 29 tristate "DVB Support for tm6000 based TV cards"
30 depends on VIDEO_TM6000 && DVB_CORE && EXPERIMENTAL 30 depends on VIDEO_TM6000 && DVB_CORE && USB && EXPERIMENTAL
31 select DVB_ZL10353 31 select DVB_ZL10353
32 ---help--- 32 ---help---
33 This adds support for DVB cards based on the tm5600/tm6000 chip. 33 This adds support for DVB cards based on the tm5600/tm6000 chip.
diff --git a/drivers/staging/tm6000/Makefile b/drivers/staging/tm6000/Makefile
index 93370fccc073..77e06bfd2c46 100644
--- a/drivers/staging/tm6000/Makefile
+++ b/drivers/staging/tm6000/Makefile
@@ -2,14 +2,12 @@ tm6000-objs := tm6000-cards.o \
2 tm6000-core.o \ 2 tm6000-core.o \
3 tm6000-i2c.o \ 3 tm6000-i2c.o \
4 tm6000-video.o \ 4 tm6000-video.o \
5 tm6000-stds.o 5 tm6000-stds.o \
6 6 tm6000-input.o
7ifeq ($(CONFIG_VIDEO_TM6000_DVB),y)
8tm6000-objs += tm6000-dvb.o
9endif
10 7
11obj-$(CONFIG_VIDEO_TM6000) += tm6000.o 8obj-$(CONFIG_VIDEO_TM6000) += tm6000.o
12obj-$(CONFIG_VIDEO_TM6000_ALSA) += tm6000-alsa.o 9obj-$(CONFIG_VIDEO_TM6000_ALSA) += tm6000-alsa.o
10obj-$(CONFIG_VIDEO_TM6000_DVB) += tm6000-dvb.o
13 11
14EXTRA_CFLAGS = -Idrivers/media/video 12EXTRA_CFLAGS = -Idrivers/media/video
15EXTRA_CFLAGS += -Idrivers/media/common/tuners 13EXTRA_CFLAGS += -Idrivers/media/common/tuners
diff --git a/drivers/staging/tm6000/tm6000-alsa.c b/drivers/staging/tm6000/tm6000-alsa.c
index 273e26ede650..087137d9164d 100644
--- a/drivers/staging/tm6000/tm6000-alsa.c
+++ b/drivers/staging/tm6000/tm6000-alsa.c
@@ -16,6 +16,7 @@
16#include <linux/interrupt.h> 16#include <linux/interrupt.h>
17#include <linux/usb.h> 17#include <linux/usb.h>
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/vmalloc.h>
19 20
20#include <asm/delay.h> 21#include <asm/delay.h>
21#include <sound/core.h> 22#include <sound/core.h>
@@ -36,34 +37,11 @@
36 } while (0) 37 } while (0)
37 38
38/**************************************************************************** 39/****************************************************************************
39 Data type declarations - Can be moded to a header file later
40 ****************************************************************************/
41
42struct snd_tm6000_card {
43 struct snd_card *card;
44
45 spinlock_t reg_lock;
46
47 atomic_t count;
48
49 unsigned int period_size;
50 unsigned int num_periods;
51
52 struct tm6000_core *core;
53 struct tm6000_buffer *buf;
54
55 int bufsize;
56
57 struct snd_pcm_substream *substream;
58};
59
60
61/****************************************************************************
62 Module global static vars 40 Module global static vars
63 ****************************************************************************/ 41 ****************************************************************************/
64 42
65static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ 43static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
66static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 44
67static int enable[SNDRV_CARDS] = {1, [1 ... (SNDRV_CARDS - 1)] = 1}; 45static int enable[SNDRV_CARDS] = {1, [1 ... (SNDRV_CARDS - 1)] = 1};
68 46
69module_param_array(enable, bool, NULL, 0444); 47module_param_array(enable, bool, NULL, 0444);
@@ -100,11 +78,15 @@ static int _tm6000_start_audio_dma(struct snd_tm6000_card *chip)
100 struct tm6000_core *core = chip->core; 78 struct tm6000_core *core = chip->core;
101 int val; 79 int val;
102 80
81 dprintk(1, "Starting audio DMA\n");
82
103 /* Enables audio */ 83 /* Enables audio */
104 val = tm6000_get_reg(core, TM6010_REQ07_RCC_ACTIVE_VIDEO_IF, 0x0); 84 val = tm6000_get_reg(core, TM6010_REQ07_RCC_ACTIVE_VIDEO_IF, 0x0);
105 val |= 0x20; 85 val |= 0x20;
106 tm6000_set_reg(core, TM6010_REQ07_RCC_ACTIVE_VIDEO_IF, val); 86 tm6000_set_reg(core, TM6010_REQ07_RCC_ACTIVE_VIDEO_IF, val);
107 87
88 tm6000_set_audio_bitrate(core, 48000);
89
108 tm6000_set_reg(core, TM6010_REQ08_R01_A_INIT, 0x80); 90 tm6000_set_reg(core, TM6010_REQ08_R01_A_INIT, 0x80);
109 91
110 return 0; 92 return 0;
@@ -129,19 +111,39 @@ static int _tm6000_stop_audio_dma(struct snd_tm6000_card *chip)
129 return 0; 111 return 0;
130} 112}
131 113
132static int dsp_buffer_free(struct snd_tm6000_card *chip) 114static void dsp_buffer_free(struct snd_pcm_substream *substream)
133{ 115{
134 BUG_ON(!chip->bufsize); 116 struct snd_tm6000_card *chip = snd_pcm_substream_chip(substream);
135 117
136 dprintk(2, "Freeing buffer\n"); 118 dprintk(2, "Freeing buffer\n");
137 119
138 /* FIXME: Frees buffer */ 120 vfree(substream->runtime->dma_area);
121 substream->runtime->dma_area = NULL;
122 substream->runtime->dma_bytes = 0;
123}
139 124
140 chip->bufsize = 0; 125static int dsp_buffer_alloc(struct snd_pcm_substream *substream, int size)
126{
127 struct snd_tm6000_card *chip = snd_pcm_substream_chip(substream);
128
129 dprintk(2, "Allocating buffer\n");
130
131 if (substream->runtime->dma_area) {
132 if (substream->runtime->dma_bytes > size)
133 return 0;
134 dsp_buffer_free(substream);
135 }
141 136
142 return 0; 137 substream->runtime->dma_area = vmalloc(size);
138 if (!substream->runtime->dma_area)
139 return -ENOMEM;
140
141 substream->runtime->dma_bytes = size;
142
143 return 0;
143} 144}
144 145
146
145/**************************************************************************** 147/****************************************************************************
146 ALSA PCM Interface 148 ALSA PCM Interface
147 ****************************************************************************/ 149 ****************************************************************************/
@@ -158,16 +160,16 @@ static struct snd_pcm_hardware snd_tm6000_digital_hw = {
158 SNDRV_PCM_INFO_MMAP_VALID, 160 SNDRV_PCM_INFO_MMAP_VALID,
159 .formats = SNDRV_PCM_FMTBIT_S16_LE, 161 .formats = SNDRV_PCM_FMTBIT_S16_LE,
160 162
161 .rates = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000, 163 .rates = SNDRV_PCM_RATE_48000,
162 .rate_min = 44100, 164 .rate_min = 48000,
163 .rate_max = 48000, 165 .rate_max = 48000,
164 .channels_min = 2, 166 .channels_min = 2,
165 .channels_max = 2, 167 .channels_max = 2,
166 .period_bytes_min = DEFAULT_FIFO_SIZE/4, 168 .period_bytes_min = 62720,
167 .period_bytes_max = DEFAULT_FIFO_SIZE/4, 169 .period_bytes_max = 62720,
168 .periods_min = 1, 170 .periods_min = 1,
169 .periods_max = 1024, 171 .periods_max = 1024,
170 .buffer_bytes_max = (1024*1024), 172 .buffer_bytes_max = 62720 * 8,
171}; 173};
172 174
173/* 175/*
@@ -202,29 +204,64 @@ static int snd_tm6000_close(struct snd_pcm_substream *substream)
202 return 0; 204 return 0;
203} 205}
204 206
207static int tm6000_fillbuf(struct tm6000_core *core, char *buf, int size)
208{
209 struct snd_tm6000_card *chip = core->adev;
210 struct snd_pcm_substream *substream = chip->substream;
211 struct snd_pcm_runtime *runtime;
212 int period_elapsed = 0;
213 unsigned int stride, buf_pos;
214
215 if (!size || !substream)
216 return -EINVAL;
217
218 runtime = substream->runtime;
219 if (!runtime || !runtime->dma_area)
220 return -EINVAL;
221
222 buf_pos = chip->buf_pos;
223 stride = runtime->frame_bits >> 3;
224
225 dprintk(1, "Copying %d bytes at %p[%d] - buf size=%d x %d\n", size,
226 runtime->dma_area, buf_pos,
227 (unsigned int)runtime->buffer_size, stride);
228
229 if (buf_pos + size >= runtime->buffer_size * stride) {
230 unsigned int cnt = runtime->buffer_size * stride - buf_pos;
231 memcpy(runtime->dma_area + buf_pos, buf, cnt);
232 memcpy(runtime->dma_area, buf + cnt, size - cnt);
233 } else
234 memcpy(runtime->dma_area + buf_pos, buf, size);
235
236 chip->buf_pos += size;
237 if (chip->buf_pos >= runtime->buffer_size * stride)
238 chip->buf_pos -= runtime->buffer_size * stride;
239
240 chip->period_pos += size;
241 if (chip->period_pos >= runtime->period_size) {
242 chip->period_pos -= runtime->period_size;
243 period_elapsed = 1;
244 }
245
246 if (period_elapsed)
247 snd_pcm_period_elapsed(substream);
248
249 return 0;
250}
251
205/* 252/*
206 * hw_params callback 253 * hw_params callback
207 */ 254 */
208static int snd_tm6000_hw_params(struct snd_pcm_substream *substream, 255static int snd_tm6000_hw_params(struct snd_pcm_substream *substream,
209 struct snd_pcm_hw_params *hw_params) 256 struct snd_pcm_hw_params *hw_params)
210{ 257{
211 struct snd_tm6000_card *chip = snd_pcm_substream_chip(substream); 258 int size, rc;
212
213 if (substream->runtime->dma_area) {
214 dsp_buffer_free(chip);
215 substream->runtime->dma_area = NULL;
216 }
217
218 chip->period_size = params_period_bytes(hw_params);
219 chip->num_periods = params_periods(hw_params);
220 chip->bufsize = chip->period_size * params_periods(hw_params);
221
222 BUG_ON(!chip->bufsize);
223 259
224 dprintk(1, "Setting buffer\n"); 260 size = params_period_bytes(hw_params) * params_periods(hw_params);
225
226 /* FIXME: Allocate buffer for audio */
227 261
262 rc = dsp_buffer_alloc(substream, size);
263 if (rc < 0)
264 return rc;
228 265
229 return 0; 266 return 0;
230} 267}
@@ -234,13 +271,9 @@ static int snd_tm6000_hw_params(struct snd_pcm_substream *substream,
234 */ 271 */
235static int snd_tm6000_hw_free(struct snd_pcm_substream *substream) 272static int snd_tm6000_hw_free(struct snd_pcm_substream *substream)
236{ 273{
237
238 struct snd_tm6000_card *chip = snd_pcm_substream_chip(substream); 274 struct snd_tm6000_card *chip = snd_pcm_substream_chip(substream);
239 275
240 if (substream->runtime->dma_area) { 276 _tm6000_stop_audio_dma(chip);
241 dsp_buffer_free(chip);
242 substream->runtime->dma_area = NULL;
243 }
244 277
245 return 0; 278 return 0;
246} 279}
@@ -250,6 +283,11 @@ static int snd_tm6000_hw_free(struct snd_pcm_substream *substream)
250 */ 283 */
251static int snd_tm6000_prepare(struct snd_pcm_substream *substream) 284static int snd_tm6000_prepare(struct snd_pcm_substream *substream)
252{ 285{
286 struct snd_tm6000_card *chip = snd_pcm_substream_chip(substream);
287
288 chip->buf_pos = 0;
289 chip->period_pos = 0;
290
253 return 0; 291 return 0;
254} 292}
255 293
@@ -287,12 +325,8 @@ static int snd_tm6000_card_trigger(struct snd_pcm_substream *substream, int cmd)
287static snd_pcm_uframes_t snd_tm6000_pointer(struct snd_pcm_substream *substream) 325static snd_pcm_uframes_t snd_tm6000_pointer(struct snd_pcm_substream *substream)
288{ 326{
289 struct snd_tm6000_card *chip = snd_pcm_substream_chip(substream); 327 struct snd_tm6000_card *chip = snd_pcm_substream_chip(substream);
290 struct snd_pcm_runtime *runtime = substream->runtime;
291 u16 count;
292
293 count = atomic_read(&chip->count);
294 328
295 return runtime->period_size * (count & (runtime->periods-1)); 329 return chip->buf_pos;
296} 330}
297 331
298/* 332/*
@@ -312,21 +346,6 @@ static struct snd_pcm_ops snd_tm6000_pcm_ops = {
312/* 346/*
313 * create a PCM device 347 * create a PCM device
314 */ 348 */
315static int __devinit snd_tm6000_pcm(struct snd_tm6000_card *chip,
316 int device, char *name)
317{
318 int err;
319 struct snd_pcm *pcm;
320
321 err = snd_pcm_new(chip->card, name, device, 0, 1, &pcm);
322 if (err < 0)
323 return err;
324 pcm->private_data = chip;
325 strcpy(pcm->name, name);
326 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_tm6000_pcm_ops);
327
328 return 0;
329}
330 349
331/* FIXME: Control interface - How to control volume/mute? */ 350/* FIXME: Control interface - How to control volume/mute? */
332 351
@@ -337,27 +356,41 @@ static int __devinit snd_tm6000_pcm(struct snd_tm6000_card *chip,
337/* 356/*
338 * Alsa Constructor - Component probe 357 * Alsa Constructor - Component probe
339 */ 358 */
340 359int tm6000_audio_init(struct tm6000_core *dev)
341int tm6000_audio_init(struct tm6000_core *dev, int idx)
342{ 360{
343 struct snd_card *card; 361 struct snd_card *card;
344 struct snd_tm6000_card *chip; 362 struct snd_tm6000_card *chip;
345 int rc, len; 363 int rc;
346 char component[14]; 364 static int devnr;
365 char component[14];
366 struct snd_pcm *pcm;
367
368 if (!dev)
369 return 0;
347 370
348 if (idx >= SNDRV_CARDS) 371 if (devnr >= SNDRV_CARDS)
349 return -ENODEV; 372 return -ENODEV;
350 373
351 if (!enable[idx]) 374 if (!enable[devnr])
352 return -ENOENT; 375 return -ENOENT;
353 376
354 rc = snd_card_create(index[idx], id[idx], THIS_MODULE, 0, &card); 377 rc = snd_card_create(index[devnr], "tm6000", THIS_MODULE, 0, &card);
355 if (rc < 0) { 378 if (rc < 0) {
356 snd_printk(KERN_ERR "cannot create card instance %d\n", idx); 379 snd_printk(KERN_ERR "cannot create card instance %d\n", devnr);
357 return rc; 380 return rc;
358 } 381 }
382 strcpy(card->driver, "tm6000-alsa");
383 strcpy(card->shortname, "TM5600/60x0");
384 sprintf(card->longname, "TM5600/60x0 Audio at bus %d device %d",
385 dev->udev->bus->busnum, dev->udev->devnum);
386
387 sprintf(component, "USB%04x:%04x",
388 le16_to_cpu(dev->udev->descriptor.idVendor),
389 le16_to_cpu(dev->udev->descriptor.idProduct));
390 snd_component_add(card, component);
391 snd_card_set_dev(card, &dev->udev->dev);
359 392
360 chip = kzalloc(sizeof(*chip), GFP_KERNEL); 393 chip = kzalloc(sizeof(struct snd_tm6000_card), GFP_KERNEL);
361 if (!chip) { 394 if (!chip) {
362 rc = -ENOMEM; 395 rc = -ENOMEM;
363 goto error; 396 goto error;
@@ -365,45 +398,24 @@ int tm6000_audio_init(struct tm6000_core *dev, int idx)
365 398
366 chip->core = dev; 399 chip->core = dev;
367 chip->card = card; 400 chip->card = card;
401 dev->adev = chip;
402 spin_lock_init(&chip->reg_lock);
368 403
369 strcpy(card->driver, "tm6000-alsa"); 404 rc = snd_pcm_new(card, "TM6000 Audio", 0, 0, 1, &pcm);
370 sprintf(component, "USB%04x:%04x",
371 le16_to_cpu(dev->udev->descriptor.idVendor),
372 le16_to_cpu(dev->udev->descriptor.idProduct));
373 snd_component_add(card, component);
374
375 if (dev->udev->descriptor.iManufacturer)
376 len = usb_string(dev->udev,
377 dev->udev->descriptor.iManufacturer,
378 card->longname, sizeof(card->longname));
379 else
380 len = 0;
381
382 if (len > 0)
383 strlcat(card->longname, " ", sizeof(card->longname));
384
385 strlcat(card->longname, card->shortname, sizeof(card->longname));
386
387 len = strlcat(card->longname, " at ", sizeof(card->longname));
388
389 if (len < sizeof(card->longname))
390 usb_make_path(dev->udev, card->longname + len,
391 sizeof(card->longname) - len);
392
393 strlcat(card->longname,
394 dev->udev->speed == USB_SPEED_LOW ? ", low speed" :
395 dev->udev->speed == USB_SPEED_FULL ? ", full speed" :
396 ", high speed",
397 sizeof(card->longname));
398
399 rc = snd_tm6000_pcm(chip, 0, "tm6000 Digital");
400 if (rc < 0) 405 if (rc < 0)
401 goto error; 406 goto error;
402 407
408 pcm->info_flags = 0;
409 pcm->private_data = chip;
410 strcpy(pcm->name, "Trident TM5600/60x0");
411
412 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_tm6000_pcm_ops);
413
403 rc = snd_card_register(card); 414 rc = snd_card_register(card);
404 if (rc < 0) 415 if (rc < 0)
405 goto error; 416 goto error;
406 417
418 dprintk(1,"Registered audio driver for %s\n", card->longname);
407 419
408 return 0; 420 return 0;
409 421
@@ -414,14 +426,31 @@ error:
414 426
415static int tm6000_audio_fini(struct tm6000_core *dev) 427static int tm6000_audio_fini(struct tm6000_core *dev)
416{ 428{
429 struct snd_tm6000_card *chip = dev->adev;
430
431 if (!dev)
432 return 0;
433
434 if (!chip)
435 return 0;
436
437 if (!chip->card)
438 return 0;
439
440 snd_card_free(chip->card);
441 chip->card = NULL;
442 kfree(chip);
443 dev->adev = NULL;
444
417 return 0; 445 return 0;
418} 446}
419 447
420struct tm6000_ops audio_ops = { 448struct tm6000_ops audio_ops = {
421 .id = TM6000_AUDIO, 449 .type = TM6000_AUDIO,
422 .name = "TM6000 Audio Extension", 450 .name = "TM6000 Audio Extension",
423 .init = tm6000_audio_init, 451 .init = tm6000_audio_init,
424 .fini = tm6000_audio_fini, 452 .fini = tm6000_audio_fini,
453 .fillbuf = tm6000_fillbuf,
425}; 454};
426 455
427static int __init tm6000_alsa_register(void) 456static int __init tm6000_alsa_register(void)
diff --git a/drivers/staging/tm6000/tm6000-cards.c b/drivers/staging/tm6000/tm6000-cards.c
index 6a9ae40c7c6d..9d091c34991b 100644
--- a/drivers/staging/tm6000/tm6000-cards.c
+++ b/drivers/staging/tm6000/tm6000-cards.c
@@ -29,6 +29,7 @@
29#include <media/tuner.h> 29#include <media/tuner.h>
30#include <media/tvaudio.h> 30#include <media/tvaudio.h>
31#include <media/i2c-addr.h> 31#include <media/i2c-addr.h>
32#include <media/rc-map.h>
32 33
33#include "tm6000.h" 34#include "tm6000.h"
34#include "tm6000-regs.h" 35#include "tm6000-regs.h"
@@ -69,6 +70,8 @@ struct tm6000_board {
69 int demod_addr; /* demodulator address */ 70 int demod_addr; /* demodulator address */
70 71
71 struct tm6000_gpio gpio; 72 struct tm6000_gpio gpio;
73
74 char *ir_codes;
72}; 75};
73 76
74struct tm6000_board tm6000_boards[] = { 77struct tm6000_board tm6000_boards[] = {
@@ -276,6 +279,7 @@ struct tm6000_board tm6000_boards[] = {
276 .dvb_led = TM6010_GPIO_5, 279 .dvb_led = TM6010_GPIO_5,
277 .ir = TM6010_GPIO_0, 280 .ir = TM6010_GPIO_0,
278 }, 281 },
282 .ir_codes = RC_MAP_NEC_TERRATEC_CINERGY_XS,
279 }, 283 },
280 [TM6010_BOARD_TWINHAN_TU501] = { 284 [TM6010_BOARD_TWINHAN_TU501] = {
281 .name = "Twinhan TU501(704D1)", 285 .name = "Twinhan TU501(704D1)",
@@ -347,7 +351,7 @@ int tm6000_xc5000_callback(void *ptr, int component, int command, int arg)
347 } 351 }
348 return (rc); 352 return (rc);
349} 353}
350 354EXPORT_SYMBOL_GPL(tm6000_xc5000_callback);
351 355
352/* Tuner callback to provide the proper gpio changes needed for xc2028 */ 356/* Tuner callback to provide the proper gpio changes needed for xc2028 */
353 357
@@ -361,6 +365,8 @@ int tm6000_tuner_callback(void *ptr, int component, int command, int arg)
361 365
362 switch (command) { 366 switch (command) {
363 case XC2028_RESET_CLK: 367 case XC2028_RESET_CLK:
368 tm6000_ir_wait(dev, 0);
369
364 tm6000_set_reg(dev, REQ_04_EN_DISABLE_MCU_INT, 370 tm6000_set_reg(dev, REQ_04_EN_DISABLE_MCU_INT,
365 0x02, arg); 371 0x02, arg);
366 msleep(10); 372 msleep(10);
@@ -410,13 +416,14 @@ int tm6000_tuner_callback(void *ptr, int component, int command, int arg)
410 msleep(130); 416 msleep(130);
411 break; 417 break;
412 } 418 }
419
420 tm6000_ir_wait(dev, 1);
413 break; 421 break;
414 case 1: 422 case 1:
415 tm6000_set_reg(dev, REQ_04_EN_DISABLE_MCU_INT, 423 tm6000_set_reg(dev, REQ_04_EN_DISABLE_MCU_INT,
416 0x02, 0x01); 424 0x02, 0x01);
417 msleep(10); 425 msleep(10);
418 break; 426 break;
419
420 case 2: 427 case 2:
421 rc = tm6000_i2c_reset(dev, 100); 428 rc = tm6000_i2c_reset(dev, 100);
422 break; 429 break;
@@ -424,6 +431,7 @@ int tm6000_tuner_callback(void *ptr, int component, int command, int arg)
424 } 431 }
425 return rc; 432 return rc;
426} 433}
434EXPORT_SYMBOL_GPL(tm6000_tuner_callback);
427 435
428int tm6000_cards_setup(struct tm6000_core *dev) 436int tm6000_cards_setup(struct tm6000_core *dev)
429{ 437{
@@ -635,6 +643,8 @@ static int tm6000_init_dev(struct tm6000_core *dev)
635 643
636 dev->gpio = tm6000_boards[dev->model].gpio; 644 dev->gpio = tm6000_boards[dev->model].gpio;
637 645
646 dev->ir_codes = tm6000_boards[dev->model].ir_codes;
647
638 dev->demod_addr = tm6000_boards[dev->model].demod_addr; 648 dev->demod_addr = tm6000_boards[dev->model].demod_addr;
639 649
640 dev->caps = tm6000_boards[dev->model].caps; 650 dev->caps = tm6000_boards[dev->model].caps;
@@ -681,31 +691,13 @@ static int tm6000_init_dev(struct tm6000_core *dev)
681 goto err; 691 goto err;
682 692
683 tm6000_add_into_devlist(dev); 693 tm6000_add_into_devlist(dev);
684
685 tm6000_init_extension(dev); 694 tm6000_init_extension(dev);
686 695
687 if (dev->caps.has_dvb) { 696 tm6000_ir_init(dev);
688 dev->dvb = kzalloc(sizeof(*(dev->dvb)), GFP_KERNEL);
689 if (!dev->dvb) {
690 rc = -ENOMEM;
691 goto err2;
692 }
693 697
694#ifdef CONFIG_VIDEO_TM6000_DVB
695 rc = tm6000_dvb_register(dev);
696 if (rc < 0) {
697 kfree(dev->dvb);
698 dev->dvb = NULL;
699 goto err2;
700 }
701#endif
702 }
703 mutex_unlock(&dev->lock); 698 mutex_unlock(&dev->lock);
704 return 0; 699 return 0;
705 700
706err2:
707 v4l2_device_unregister(&dev->v4l2_dev);
708
709err: 701err:
710 mutex_unlock(&dev->lock); 702 mutex_unlock(&dev->lock);
711 return rc; 703 return rc;
@@ -724,7 +716,7 @@ static void get_max_endpoint(struct usb_device *udev,
724 unsigned int size = tmp & 0x7ff; 716 unsigned int size = tmp & 0x7ff;
725 717
726 if (udev->speed == USB_SPEED_HIGH) 718 if (udev->speed == USB_SPEED_HIGH)
727 size = size * hb_mult (tmp); 719 size = size * hb_mult(tmp);
728 720
729 if (size > tm_ep->maxsize) { 721 if (size > tm_ep->maxsize) {
730 tm_ep->endp = curr_e; 722 tm_ep->endp = curr_e;
@@ -848,6 +840,19 @@ static int tm6000_usb_probe(struct usb_interface *interface,
848 &dev->isoc_out); 840 &dev->isoc_out);
849 } 841 }
850 break; 842 break;
843 case USB_ENDPOINT_XFER_INT:
844 if (!dir_out) {
845 get_max_endpoint(usbdev,
846 &interface->altsetting[i],
847 "INT IN", e,
848 &dev->int_in);
849 } else {
850 get_max_endpoint(usbdev,
851 &interface->altsetting[i],
852 "INT OUT", e,
853 &dev->int_out);
854 }
855 break;
851 } 856 }
852 } 857 }
853 } 858 }
@@ -906,12 +911,7 @@ static void tm6000_usb_disconnect(struct usb_interface *interface)
906 911
907 mutex_lock(&dev->lock); 912 mutex_lock(&dev->lock);
908 913
909#ifdef CONFIG_VIDEO_TM6000_DVB 914 tm6000_ir_fini(dev);
910 if (dev->dvb) {
911 tm6000_dvb_unregister(dev);
912 kfree(dev->dvb);
913 }
914#endif
915 915
916 if (dev->gpio.power_led) { 916 if (dev->gpio.power_led) {
917 switch (dev->model) { 917 switch (dev->model) {
@@ -942,8 +942,8 @@ static void tm6000_usb_disconnect(struct usb_interface *interface)
942 942
943 usb_put_dev(dev->udev); 943 usb_put_dev(dev->udev);
944 944
945 tm6000_remove_from_devlist(dev);
946 tm6000_close_extension(dev); 945 tm6000_close_extension(dev);
946 tm6000_remove_from_devlist(dev);
947 947
948 mutex_unlock(&dev->lock); 948 mutex_unlock(&dev->lock);
949 kfree(dev); 949 kfree(dev);
diff --git a/drivers/staging/tm6000/tm6000-core.c b/drivers/staging/tm6000/tm6000-core.c
index c3690e3580da..cded411d8bba 100644
--- a/drivers/staging/tm6000/tm6000-core.c
+++ b/drivers/staging/tm6000/tm6000-core.c
@@ -32,66 +32,64 @@
32 32
33#define USB_TIMEOUT 5*HZ /* ms */ 33#define USB_TIMEOUT 5*HZ /* ms */
34 34
35int tm6000_read_write_usb (struct tm6000_core *dev, u8 req_type, u8 req, 35int tm6000_read_write_usb(struct tm6000_core *dev, u8 req_type, u8 req,
36 u16 value, u16 index, u8 *buf, u16 len) 36 u16 value, u16 index, u8 *buf, u16 len)
37{ 37{
38 int ret, i; 38 int ret, i;
39 unsigned int pipe; 39 unsigned int pipe;
40 static int ini=0, last=0, n=0; 40 static int ini = 0, last = 0, n = 0;
41 u8 *data=NULL; 41 u8 *data = NULL;
42 42
43 if (len) 43 if (len)
44 data = kzalloc(len, GFP_KERNEL); 44 data = kzalloc(len, GFP_KERNEL);
45 45
46 46
47 if (req_type & USB_DIR_IN) 47 if (req_type & USB_DIR_IN)
48 pipe=usb_rcvctrlpipe(dev->udev, 0); 48 pipe = usb_rcvctrlpipe(dev->udev, 0);
49 else { 49 else {
50 pipe=usb_sndctrlpipe(dev->udev, 0); 50 pipe = usb_sndctrlpipe(dev->udev, 0);
51 memcpy(data, buf, len); 51 memcpy(data, buf, len);
52 } 52 }
53 53
54 if (tm6000_debug & V4L2_DEBUG_I2C) { 54 if (tm6000_debug & V4L2_DEBUG_I2C) {
55 if (!ini) 55 if (!ini)
56 last=ini=jiffies; 56 last = ini = jiffies;
57 57
58 printk("%06i (dev %p, pipe %08x): ", n, dev->udev, pipe); 58 printk("%06i (dev %p, pipe %08x): ", n, dev->udev, pipe);
59 59
60 printk( "%s: %06u ms %06u ms %02x %02x %02x %02x %02x %02x %02x %02x ", 60 printk("%s: %06u ms %06u ms %02x %02x %02x %02x %02x %02x %02x %02x ",
61 (req_type & USB_DIR_IN)?" IN":"OUT", 61 (req_type & USB_DIR_IN) ? " IN" : "OUT",
62 jiffies_to_msecs(jiffies-last), 62 jiffies_to_msecs(jiffies-last),
63 jiffies_to_msecs(jiffies-ini), 63 jiffies_to_msecs(jiffies-ini),
64 req_type, req,value&0xff,value>>8, index&0xff, index>>8, 64 req_type, req, value&0xff, value>>8, index&0xff,
65 len&0xff, len>>8); 65 index>>8, len&0xff, len>>8);
66 last=jiffies; 66 last = jiffies;
67 n++; 67 n++;
68 68
69 if ( !(req_type & USB_DIR_IN) ) { 69 if (!(req_type & USB_DIR_IN)) {
70 printk(">>> "); 70 printk(">>> ");
71 for (i=0;i<len;i++) { 71 for (i = 0; i < len; i++)
72 printk(" %02x",buf[i]); 72 printk(" %02x", buf[i]);
73 }
74 printk("\n"); 73 printk("\n");
75 } 74 }
76 } 75 }
77 76
78 ret = usb_control_msg(dev->udev, pipe, req, req_type, value, index, data, 77 ret = usb_control_msg(dev->udev, pipe, req, req_type, value, index,
79 len, USB_TIMEOUT); 78 data, len, USB_TIMEOUT);
80 79
81 if (req_type & USB_DIR_IN) 80 if (req_type & USB_DIR_IN)
82 memcpy(buf, data, len); 81 memcpy(buf, data, len);
83 82
84 if (tm6000_debug & V4L2_DEBUG_I2C) { 83 if (tm6000_debug & V4L2_DEBUG_I2C) {
85 if (ret<0) { 84 if (ret < 0) {
86 if (req_type & USB_DIR_IN) 85 if (req_type & USB_DIR_IN)
87 printk("<<< (len=%d)\n",len); 86 printk("<<< (len=%d)\n", len);
88 87
89 printk("%s: Error #%d\n", __FUNCTION__, ret); 88 printk("%s: Error #%d\n", __FUNCTION__, ret);
90 } else if (req_type & USB_DIR_IN) { 89 } else if (req_type & USB_DIR_IN) {
91 printk("<<< "); 90 printk("<<< ");
92 for (i=0;i<len;i++) { 91 for (i = 0; i < len; i++)
93 printk(" %02x",buf[i]); 92 printk(" %02x", buf[i]);
94 }
95 printk("\n"); 93 printk("\n");
96 } 94 }
97 } 95 }
@@ -103,52 +101,52 @@ int tm6000_read_write_usb (struct tm6000_core *dev, u8 req_type, u8 req,
103 return ret; 101 return ret;
104} 102}
105 103
106int tm6000_set_reg (struct tm6000_core *dev, u8 req, u16 value, u16 index) 104int tm6000_set_reg(struct tm6000_core *dev, u8 req, u16 value, u16 index)
107{ 105{
108 return 106 return
109 tm6000_read_write_usb (dev, USB_DIR_OUT | USB_TYPE_VENDOR, 107 tm6000_read_write_usb(dev, USB_DIR_OUT | USB_TYPE_VENDOR,
110 req, value, index, NULL, 0); 108 req, value, index, NULL, 0);
111} 109}
112EXPORT_SYMBOL_GPL(tm6000_set_reg); 110EXPORT_SYMBOL_GPL(tm6000_set_reg);
113 111
114int tm6000_get_reg (struct tm6000_core *dev, u8 req, u16 value, u16 index) 112int tm6000_get_reg(struct tm6000_core *dev, u8 req, u16 value, u16 index)
115{ 113{
116 int rc; 114 int rc;
117 u8 buf[1]; 115 u8 buf[1];
118 116
119 rc=tm6000_read_write_usb (dev, USB_DIR_IN | USB_TYPE_VENDOR, req, 117 rc = tm6000_read_write_usb(dev, USB_DIR_IN | USB_TYPE_VENDOR, req,
120 value, index, buf, 1); 118 value, index, buf, 1);
121 119
122 if (rc<0) 120 if (rc < 0)
123 return rc; 121 return rc;
124 122
125 return *buf; 123 return *buf;
126} 124}
127EXPORT_SYMBOL_GPL(tm6000_get_reg); 125EXPORT_SYMBOL_GPL(tm6000_get_reg);
128 126
129int tm6000_get_reg16 (struct tm6000_core *dev, u8 req, u16 value, u16 index) 127int tm6000_get_reg16(struct tm6000_core *dev, u8 req, u16 value, u16 index)
130{ 128{
131 int rc; 129 int rc;
132 u8 buf[2]; 130 u8 buf[2];
133 131
134 rc=tm6000_read_write_usb (dev, USB_DIR_IN | USB_TYPE_VENDOR, req, 132 rc = tm6000_read_write_usb(dev, USB_DIR_IN | USB_TYPE_VENDOR, req,
135 value, index, buf, 2); 133 value, index, buf, 2);
136 134
137 if (rc<0) 135 if (rc < 0)
138 return rc; 136 return rc;
139 137
140 return buf[1]|buf[0]<<8; 138 return buf[1]|buf[0]<<8;
141} 139}
142 140
143int tm6000_get_reg32 (struct tm6000_core *dev, u8 req, u16 value, u16 index) 141int tm6000_get_reg32(struct tm6000_core *dev, u8 req, u16 value, u16 index)
144{ 142{
145 int rc; 143 int rc;
146 u8 buf[4]; 144 u8 buf[4];
147 145
148 rc=tm6000_read_write_usb (dev, USB_DIR_IN | USB_TYPE_VENDOR, req, 146 rc = tm6000_read_write_usb(dev, USB_DIR_IN | USB_TYPE_VENDOR, req,
149 value, index, buf, 4); 147 value, index, buf, 4);
150 148
151 if (rc<0) 149 if (rc < 0)
152 return rc; 150 return rc;
153 151
154 return buf[3] | buf[2] << 8 | buf[1] << 16 | buf[0] << 24; 152 return buf[3] | buf[2] << 8 | buf[1] << 16 | buf[0] << 24;
@@ -188,7 +186,7 @@ void tm6000_set_fourcc_format(struct tm6000_core *dev)
188 } 186 }
189} 187}
190 188
191int tm6000_init_analog_mode (struct tm6000_core *dev) 189int tm6000_init_analog_mode(struct tm6000_core *dev)
192{ 190{
193 if (dev->dev_type == TM6010) { 191 if (dev->dev_type == TM6010) {
194 int val; 192 int val;
@@ -294,12 +292,10 @@ int tm6000_init_analog_mode (struct tm6000_core *dev)
294 /* Enables soft reset */ 292 /* Enables soft reset */
295 tm6000_set_reg(dev, TM6010_REQ07_R3F_RESET, 0x01); 293 tm6000_set_reg(dev, TM6010_REQ07_R3F_RESET, 0x01);
296 294
297 if (dev->scaler) { 295 if (dev->scaler)
298 tm6000_set_reg(dev, TM6010_REQ07_RC0_ACTIVE_VIDEO_SOURCE, 0x20); 296 tm6000_set_reg(dev, TM6010_REQ07_RC0_ACTIVE_VIDEO_SOURCE, 0x20);
299 } else { 297 else /* Enable Hfilter and disable TS Drop err */
300 /* Enable Hfilter and disable TS Drop err */
301 tm6000_set_reg(dev, TM6010_REQ07_RC0_ACTIVE_VIDEO_SOURCE, 0x80); 298 tm6000_set_reg(dev, TM6010_REQ07_RC0_ACTIVE_VIDEO_SOURCE, 0x80);
302 }
303 299
304 tm6000_set_reg(dev, TM6010_REQ07_RC3_HSTART1, 0x88); 300 tm6000_set_reg(dev, TM6010_REQ07_RC3_HSTART1, 0x88);
305 tm6000_set_reg(dev, TM6010_REQ07_RD8_IR_WAKEUP_SEL, 0x23); 301 tm6000_set_reg(dev, TM6010_REQ07_RD8_IR_WAKEUP_SEL, 0x23);
@@ -332,13 +328,13 @@ int tm6000_init_analog_mode (struct tm6000_core *dev)
332 /*FIXME: Hack!!! */ 328 /*FIXME: Hack!!! */
333 struct v4l2_frequency f; 329 struct v4l2_frequency f;
334 mutex_lock(&dev->lock); 330 mutex_lock(&dev->lock);
335 f.frequency=dev->freq; 331 f.frequency = dev->freq;
336 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, &f); 332 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, &f);
337 mutex_unlock(&dev->lock); 333 mutex_unlock(&dev->lock);
338 334
339 msleep(100); 335 msleep(100);
340 tm6000_set_standard (dev, &dev->norm); 336 tm6000_set_standard(dev, &dev->norm);
341 tm6000_set_audio_bitrate (dev,48000); 337 tm6000_set_audio_bitrate(dev, 48000);
342 338
343 /* switch dvb led off */ 339 /* switch dvb led off */
344 if (dev->gpio.dvb_led) { 340 if (dev->gpio.dvb_led) {
@@ -349,7 +345,7 @@ int tm6000_init_analog_mode (struct tm6000_core *dev)
349 return 0; 345 return 0;
350} 346}
351 347
352int tm6000_init_digital_mode (struct tm6000_core *dev) 348int tm6000_init_digital_mode(struct tm6000_core *dev)
353{ 349{
354 if (dev->dev_type == TM6010) { 350 if (dev->dev_type == TM6010) {
355 int val; 351 int val;
@@ -366,10 +362,8 @@ int tm6000_init_digital_mode (struct tm6000_core *dev)
366 tm6000_set_reg(dev, TM6010_REQ08_RE2_POWER_DOWN_CTRL1, 0xfc); 362 tm6000_set_reg(dev, TM6010_REQ08_RE2_POWER_DOWN_CTRL1, 0xfc);
367 tm6000_set_reg(dev, TM6010_REQ08_RE6_POWER_DOWN_CTRL2, 0xff); 363 tm6000_set_reg(dev, TM6010_REQ08_RE6_POWER_DOWN_CTRL2, 0xff);
368 tm6000_set_reg(dev, TM6010_REQ08_RF1_AADC_POWER_DOWN, 0xfe); 364 tm6000_set_reg(dev, TM6010_REQ08_RF1_AADC_POWER_DOWN, 0xfe);
369 tm6000_read_write_usb (dev, 0xc0, 0x0e, 0x00c2, 0x0008, buf, 2); 365 tm6000_read_write_usb(dev, 0xc0, 0x0e, 0x00c2, 0x0008, buf, 2);
370 printk (KERN_INFO "buf %#x %#x \n", buf[0], buf[1]); 366 printk(KERN_INFO"buf %#x %#x\n", buf[0], buf[1]);
371
372
373 } else { 367 } else {
374 tm6000_set_reg(dev, TM6010_REQ07_RFF_SOFT_RESET, 0x08); 368 tm6000_set_reg(dev, TM6010_REQ07_RFF_SOFT_RESET, 0x08);
375 tm6000_set_reg(dev, TM6010_REQ07_RFF_SOFT_RESET, 0x00); 369 tm6000_set_reg(dev, TM6010_REQ07_RFF_SOFT_RESET, 0x00);
@@ -377,7 +371,7 @@ int tm6000_init_digital_mode (struct tm6000_core *dev)
377 tm6000_set_reg(dev, TM6010_REQ07_RD8_IR_PULSE_CNT0, 0x08); 371 tm6000_set_reg(dev, TM6010_REQ07_RD8_IR_PULSE_CNT0, 0x08);
378 tm6000_set_reg(dev, TM6010_REQ07_RE2_OUT_SEL2, 0x0c); 372 tm6000_set_reg(dev, TM6010_REQ07_RE2_OUT_SEL2, 0x0c);
379 tm6000_set_reg(dev, TM6010_REQ07_RE8_TYPESEL_MOS_I2S, 0xff); 373 tm6000_set_reg(dev, TM6010_REQ07_RE8_TYPESEL_MOS_I2S, 0xff);
380 tm6000_set_reg (dev, REQ_07_SET_GET_AVREG, 0x00eb, 0xd8); 374 tm6000_set_reg(dev, REQ_07_SET_GET_AVREG, 0x00eb, 0xd8);
381 tm6000_set_reg(dev, TM6010_REQ07_RC0_ACTIVE_VIDEO_SOURCE, 0x40); 375 tm6000_set_reg(dev, TM6010_REQ07_RC0_ACTIVE_VIDEO_SOURCE, 0x40);
382 tm6000_set_reg(dev, TM6010_REQ07_RC1_TRESHOLD, 0xd0); 376 tm6000_set_reg(dev, TM6010_REQ07_RC1_TRESHOLD, 0xd0);
383 tm6000_set_reg(dev, TM6010_REQ07_RC3_HSTART1, 0x09); 377 tm6000_set_reg(dev, TM6010_REQ07_RC3_HSTART1, 0x09);
@@ -388,14 +382,14 @@ int tm6000_init_digital_mode (struct tm6000_core *dev)
388 382
389 tm6000_set_reg(dev, TM6010_REQ07_RE2_OUT_SEL2, 0x0c); 383 tm6000_set_reg(dev, TM6010_REQ07_RE2_OUT_SEL2, 0x0c);
390 tm6000_set_reg(dev, TM6010_REQ07_RE8_TYPESEL_MOS_I2S, 0xff); 384 tm6000_set_reg(dev, TM6010_REQ07_RE8_TYPESEL_MOS_I2S, 0xff);
391 tm6000_set_reg (dev, REQ_07_SET_GET_AVREG, 0x00eb, 0x08); 385 tm6000_set_reg(dev, REQ_07_SET_GET_AVREG, 0x00eb, 0x08);
392 msleep(50); 386 msleep(50);
393 387
394 tm6000_set_reg (dev, REQ_04_EN_DISABLE_MCU_INT, 0x0020, 0x00); 388 tm6000_set_reg(dev, REQ_04_EN_DISABLE_MCU_INT, 0x0020, 0x00);
395 msleep(50); 389 msleep(50);
396 tm6000_set_reg (dev, REQ_04_EN_DISABLE_MCU_INT, 0x0020, 0x01); 390 tm6000_set_reg(dev, REQ_04_EN_DISABLE_MCU_INT, 0x0020, 0x01);
397 msleep(50); 391 msleep(50);
398 tm6000_set_reg (dev, REQ_04_EN_DISABLE_MCU_INT, 0x0020, 0x00); 392 tm6000_set_reg(dev, REQ_04_EN_DISABLE_MCU_INT, 0x0020, 0x00);
399 msleep(100); 393 msleep(100);
400 } 394 }
401 395
@@ -407,6 +401,7 @@ int tm6000_init_digital_mode (struct tm6000_core *dev)
407 401
408 return 0; 402 return 0;
409} 403}
404EXPORT_SYMBOL(tm6000_init_digital_mode);
410 405
411struct reg_init { 406struct reg_init {
412 u8 req; 407 u8 req;
@@ -566,9 +561,9 @@ struct reg_init tm6010_init_tab[] = {
566 { TM6010_REQ07_RD8_IR_WAKEUP_SEL, 0xff }, 561 { TM6010_REQ07_RD8_IR_WAKEUP_SEL, 0xff },
567}; 562};
568 563
569int tm6000_init (struct tm6000_core *dev) 564int tm6000_init(struct tm6000_core *dev)
570{ 565{
571 int board, rc=0, i, size; 566 int board, rc = 0, i, size;
572 struct reg_init *tab; 567 struct reg_init *tab;
573 568
574 if (dev->dev_type == TM6010) { 569 if (dev->dev_type == TM6010) {
@@ -580,12 +575,12 @@ int tm6000_init (struct tm6000_core *dev)
580 } 575 }
581 576
582 /* Load board's initialization table */ 577 /* Load board's initialization table */
583 for (i=0; i< size; i++) { 578 for (i = 0; i < size; i++) {
584 rc= tm6000_set_reg (dev, tab[i].req, tab[i].reg, tab[i].val); 579 rc = tm6000_set_reg(dev, tab[i].req, tab[i].reg, tab[i].val);
585 if (rc<0) { 580 if (rc < 0) {
586 printk (KERN_ERR "Error %i while setting req %d, " 581 printk(KERN_ERR "Error %i while setting req %d, "
587 "reg %d to value %d\n", rc, 582 "reg %d to value %d\n", rc,
588 tab[i].req,tab[i].reg, tab[i].val); 583 tab[i].req, tab[i].reg, tab[i].val);
589 return rc; 584 return rc;
590 } 585 }
591 } 586 }
@@ -593,12 +588,11 @@ int tm6000_init (struct tm6000_core *dev)
593 msleep(5); /* Just to be conservative */ 588 msleep(5); /* Just to be conservative */
594 589
595 /* Check board version - maybe 10Moons specific */ 590 /* Check board version - maybe 10Moons specific */
596 board=tm6000_get_reg32 (dev, REQ_40_GET_VERSION, 0, 0); 591 board = tm6000_get_reg32(dev, REQ_40_GET_VERSION, 0, 0);
597 if (board >=0) { 592 if (board >= 0)
598 printk (KERN_INFO "Board version = 0x%08x\n",board); 593 printk(KERN_INFO "Board version = 0x%08x\n", board);
599 } else { 594 else
600 printk (KERN_ERR "Error %i while retrieving board version\n",board); 595 printk(KERN_ERR "Error %i while retrieving board version\n", board);
601 }
602 596
603 rc = tm6000_cards_setup(dev); 597 rc = tm6000_cards_setup(dev);
604 598
@@ -609,23 +603,32 @@ int tm6000_set_audio_bitrate(struct tm6000_core *dev, int bitrate)
609{ 603{
610 int val; 604 int val;
611 605
612 val=tm6000_get_reg (dev, REQ_07_SET_GET_AVREG, 0xeb, 0x0); 606 if (dev->dev_type == TM6010) {
613printk("Original value=%d\n",val); 607 val = tm6000_get_reg(dev, TM6010_REQ08_R0A_A_I2S_MOD, 0);
614 if (val<0) 608 if (val < 0)
609 return val;
610 val = (val & 0xf0) | 0x1; /* 48 kHz, not muted */
611 val = tm6000_set_reg(dev, TM6010_REQ08_R0A_A_I2S_MOD, val);
612 if (val < 0)
613 return val;
614 }
615
616 val = tm6000_get_reg(dev, REQ_07_SET_GET_AVREG, 0xeb, 0x0);
617 if (val < 0)
615 return val; 618 return val;
616 619
617 val &= 0x0f; /* Preserve the audio input control bits */ 620 val &= 0x0f; /* Preserve the audio input control bits */
618 switch (bitrate) { 621 switch (bitrate) {
619 case 44100: 622 case 44100:
620 val|=0xd0; 623 val |= 0xd0;
621 dev->audio_bitrate=bitrate; 624 dev->audio_bitrate = bitrate;
622 break; 625 break;
623 case 48000: 626 case 48000:
624 val|=0x60; 627 val |= 0x60;
625 dev->audio_bitrate=bitrate; 628 dev->audio_bitrate = bitrate;
626 break; 629 break;
627 } 630 }
628 val=tm6000_set_reg (dev, REQ_07_SET_GET_AVREG, 0xeb, val); 631 val = tm6000_set_reg(dev, REQ_07_SET_GET_AVREG, 0xeb, val);
629 632
630 return val; 633 return val;
631} 634}
@@ -659,6 +662,23 @@ void tm6000_add_into_devlist(struct tm6000_core *dev)
659static LIST_HEAD(tm6000_extension_devlist); 662static LIST_HEAD(tm6000_extension_devlist);
660static DEFINE_MUTEX(tm6000_extension_devlist_lock); 663static DEFINE_MUTEX(tm6000_extension_devlist_lock);
661 664
665int tm6000_call_fillbuf(struct tm6000_core *dev, enum tm6000_ops_type type,
666 char *buf, int size)
667{
668 struct tm6000_ops *ops = NULL;
669
670 /* FIXME: tm6000_extension_devlist_lock should be a spinlock */
671
672 if (!list_empty(&tm6000_extension_devlist)) {
673 list_for_each_entry(ops, &tm6000_extension_devlist, next) {
674 if (ops->fillbuf && ops->type == type)
675 ops->fillbuf(dev, buf, size);
676 }
677 }
678
679 return 0;
680}
681
662int tm6000_register_extension(struct tm6000_ops *ops) 682int tm6000_register_extension(struct tm6000_ops *ops)
663{ 683{
664 struct tm6000_core *dev = NULL; 684 struct tm6000_core *dev = NULL;
@@ -667,10 +687,10 @@ int tm6000_register_extension(struct tm6000_ops *ops)
667 mutex_lock(&tm6000_extension_devlist_lock); 687 mutex_lock(&tm6000_extension_devlist_lock);
668 list_add_tail(&ops->next, &tm6000_extension_devlist); 688 list_add_tail(&ops->next, &tm6000_extension_devlist);
669 list_for_each_entry(dev, &tm6000_devlist, devlist) { 689 list_for_each_entry(dev, &tm6000_devlist, devlist) {
670 if (dev) 690 ops->init(dev);
671 ops->init(dev); 691 printk(KERN_INFO "%s: Initialized (%s) extension\n",
692 dev->name, ops->name);
672 } 693 }
673 printk(KERN_INFO "tm6000: Initialized (%s) extension\n", ops->name);
674 mutex_unlock(&tm6000_extension_devlist_lock); 694 mutex_unlock(&tm6000_extension_devlist_lock);
675 mutex_unlock(&tm6000_devlist_mutex); 695 mutex_unlock(&tm6000_devlist_mutex);
676 return 0; 696 return 0;
diff --git a/drivers/staging/tm6000/tm6000-dvb.c b/drivers/staging/tm6000/tm6000-dvb.c
index 86c1c8b5f25a..f501edccf9c4 100644
--- a/drivers/staging/tm6000/tm6000-dvb.c
+++ b/drivers/staging/tm6000/tm6000-dvb.c
@@ -31,12 +31,25 @@
31#include "tuner-xc2028.h" 31#include "tuner-xc2028.h"
32#include "xc5000.h" 32#include "xc5000.h"
33 33
34static void inline print_err_status (struct tm6000_core *dev, 34MODULE_DESCRIPTION("DVB driver extension module for tm5600/6000/6010 based TV cards");
35 int packet, int status) 35MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
36MODULE_LICENSE("GPL");
37
38MODULE_SUPPORTED_DEVICE("{{Trident, tm5600},"
39 "{{Trident, tm6000},"
40 "{{Trident, tm6010}");
41
42static int debug;
43
44module_param(debug, int, 0644);
45MODULE_PARM_DESC(debug, "enable debug message");
46
47static inline void print_err_status(struct tm6000_core *dev,
48 int packet, int status)
36{ 49{
37 char *errmsg = "Unknown"; 50 char *errmsg = "Unknown";
38 51
39 switch(status) { 52 switch (status) {
40 case -ENOENT: 53 case -ENOENT:
41 errmsg = "unlinked synchronuously"; 54 errmsg = "unlinked synchronuously";
42 break; 55 break;
@@ -62,7 +75,7 @@ static void inline print_err_status (struct tm6000_core *dev,
62 errmsg = "Device does not respond"; 75 errmsg = "Device does not respond";
63 break; 76 break;
64 } 77 }
65 if (packet<0) { 78 if (packet < 0) {
66 dprintk(dev, 1, "URB status %d [%s].\n", 79 dprintk(dev, 1, "URB status %d [%s].\n",
67 status, errmsg); 80 status, errmsg);
68 } else { 81 } else {
@@ -74,19 +87,17 @@ static void inline print_err_status (struct tm6000_core *dev,
74static void tm6000_urb_received(struct urb *urb) 87static void tm6000_urb_received(struct urb *urb)
75{ 88{
76 int ret; 89 int ret;
77 struct tm6000_core* dev = urb->context; 90 struct tm6000_core *dev = urb->context;
78 91
79 if(urb->status != 0) { 92 if (urb->status != 0)
80 print_err_status (dev,0,urb->status); 93 print_err_status(dev, 0, urb->status);
81 } 94 else if (urb->actual_length > 0)
82 else if(urb->actual_length>0){
83 dvb_dmx_swfilter(&dev->dvb->demux, urb->transfer_buffer, 95 dvb_dmx_swfilter(&dev->dvb->demux, urb->transfer_buffer,
84 urb->actual_length); 96 urb->actual_length);
85 }
86 97
87 if(dev->dvb->streams > 0) { 98 if (dev->dvb->streams > 0) {
88 ret = usb_submit_urb(urb, GFP_ATOMIC); 99 ret = usb_submit_urb(urb, GFP_ATOMIC);
89 if(ret < 0) { 100 if (ret < 0) {
90 printk(KERN_ERR "tm6000: error %s\n", __FUNCTION__); 101 printk(KERN_ERR "tm6000: error %s\n", __FUNCTION__);
91 kfree(urb->transfer_buffer); 102 kfree(urb->transfer_buffer);
92 usb_free_urb(urb); 103 usb_free_urb(urb);
@@ -100,7 +111,7 @@ int tm6000_start_stream(struct tm6000_core *dev)
100 unsigned int pipe, size; 111 unsigned int pipe, size;
101 struct tm6000_dvb *dvb = dev->dvb; 112 struct tm6000_dvb *dvb = dev->dvb;
102 113
103 printk(KERN_INFO "tm6000: got start stream request %s\n",__FUNCTION__); 114 printk(KERN_INFO "tm6000: got start stream request %s\n", __FUNCTION__);
104 115
105 if (dev->mode != TM6000_MODE_DIGITAL) { 116 if (dev->mode != TM6000_MODE_DIGITAL) {
106 tm6000_init_digital_mode(dev); 117 tm6000_init_digital_mode(dev);
@@ -108,7 +119,7 @@ int tm6000_start_stream(struct tm6000_core *dev)
108 } 119 }
109 120
110 dvb->bulk_urb = usb_alloc_urb(0, GFP_KERNEL); 121 dvb->bulk_urb = usb_alloc_urb(0, GFP_KERNEL);
111 if(dvb->bulk_urb == NULL) { 122 if (dvb->bulk_urb == NULL) {
112 printk(KERN_ERR "tm6000: couldn't allocate urb\n"); 123 printk(KERN_ERR "tm6000: couldn't allocate urb\n");
113 return -ENOMEM; 124 return -ENOMEM;
114 } 125 }
@@ -120,7 +131,7 @@ int tm6000_start_stream(struct tm6000_core *dev)
120 size = size * 15; /* 512 x 8 or 12 or 15 */ 131 size = size * 15; /* 512 x 8 or 12 or 15 */
121 132
122 dvb->bulk_urb->transfer_buffer = kzalloc(size, GFP_KERNEL); 133 dvb->bulk_urb->transfer_buffer = kzalloc(size, GFP_KERNEL);
123 if(dvb->bulk_urb->transfer_buffer == NULL) { 134 if (dvb->bulk_urb->transfer_buffer == NULL) {
124 usb_free_urb(dvb->bulk_urb); 135 usb_free_urb(dvb->bulk_urb);
125 printk(KERN_ERR "tm6000: couldn't allocate transfer buffer!\n"); 136 printk(KERN_ERR "tm6000: couldn't allocate transfer buffer!\n");
126 return -ENOMEM; 137 return -ENOMEM;
@@ -132,20 +143,20 @@ int tm6000_start_stream(struct tm6000_core *dev)
132 tm6000_urb_received, dev); 143 tm6000_urb_received, dev);
133 144
134 ret = usb_clear_halt(dev->udev, pipe); 145 ret = usb_clear_halt(dev->udev, pipe);
135 if(ret < 0) { 146 if (ret < 0) {
136 printk(KERN_ERR "tm6000: error %i in %s during pipe reset\n",ret,__FUNCTION__); 147 printk(KERN_ERR "tm6000: error %i in %s during pipe reset\n",
148 ret, __FUNCTION__);
137 return ret; 149 return ret;
138 } 150 } else
139 else {
140 printk(KERN_ERR "tm6000: pipe resetted\n"); 151 printk(KERN_ERR "tm6000: pipe resetted\n");
141 }
142 152
143/* mutex_lock(&tm6000_driver.open_close_mutex); */ 153/* mutex_lock(&tm6000_driver.open_close_mutex); */
144 ret = usb_submit_urb(dvb->bulk_urb, GFP_KERNEL); 154 ret = usb_submit_urb(dvb->bulk_urb, GFP_KERNEL);
145 155
146/* mutex_unlock(&tm6000_driver.open_close_mutex); */ 156/* mutex_unlock(&tm6000_driver.open_close_mutex); */
147 if (ret) { 157 if (ret) {
148 printk(KERN_ERR "tm6000: submit of urb failed (error=%i)\n",ret); 158 printk(KERN_ERR "tm6000: submit of urb failed (error=%i)\n",
159 ret);
149 160
150 kfree(dvb->bulk_urb->transfer_buffer); 161 kfree(dvb->bulk_urb->transfer_buffer);
151 usb_free_urb(dvb->bulk_urb); 162 usb_free_urb(dvb->bulk_urb);
@@ -159,10 +170,10 @@ void tm6000_stop_stream(struct tm6000_core *dev)
159{ 170{
160 struct tm6000_dvb *dvb = dev->dvb; 171 struct tm6000_dvb *dvb = dev->dvb;
161 172
162 if(dvb->bulk_urb) { 173 if (dvb->bulk_urb) {
163 printk (KERN_INFO "urb killing\n"); 174 printk(KERN_INFO "urb killing\n");
164 usb_kill_urb(dvb->bulk_urb); 175 usb_kill_urb(dvb->bulk_urb);
165 printk (KERN_INFO "urb buffer free\n"); 176 printk(KERN_INFO "urb buffer free\n");
166 kfree(dvb->bulk_urb->transfer_buffer); 177 kfree(dvb->bulk_urb->transfer_buffer);
167 usb_free_urb(dvb->bulk_urb); 178 usb_free_urb(dvb->bulk_urb);
168 dvb->bulk_urb = NULL; 179 dvb->bulk_urb = NULL;
@@ -174,35 +185,34 @@ int tm6000_start_feed(struct dvb_demux_feed *feed)
174 struct dvb_demux *demux = feed->demux; 185 struct dvb_demux *demux = feed->demux;
175 struct tm6000_core *dev = demux->priv; 186 struct tm6000_core *dev = demux->priv;
176 struct tm6000_dvb *dvb = dev->dvb; 187 struct tm6000_dvb *dvb = dev->dvb;
177 printk(KERN_INFO "tm6000: got start feed request %s\n",__FUNCTION__); 188 printk(KERN_INFO "tm6000: got start feed request %s\n", __FUNCTION__);
178 189
179 mutex_lock(&dvb->mutex); 190 mutex_lock(&dvb->mutex);
180 if(dvb->streams == 0) { 191 if (dvb->streams == 0) {
181 dvb->streams = 1; 192 dvb->streams = 1;
182/* mutex_init(&tm6000_dev->streming_mutex); */ 193/* mutex_init(&tm6000_dev->streming_mutex); */
183 tm6000_start_stream(dev); 194 tm6000_start_stream(dev);
184 } 195 } else
185 else {
186 ++(dvb->streams); 196 ++(dvb->streams);
187 }
188 mutex_unlock(&dvb->mutex); 197 mutex_unlock(&dvb->mutex);
189 198
190 return 0; 199 return 0;
191} 200}
192 201
193int tm6000_stop_feed(struct dvb_demux_feed *feed) { 202int tm6000_stop_feed(struct dvb_demux_feed *feed)
203{
194 struct dvb_demux *demux = feed->demux; 204 struct dvb_demux *demux = feed->demux;
195 struct tm6000_core *dev = demux->priv; 205 struct tm6000_core *dev = demux->priv;
196 struct tm6000_dvb *dvb = dev->dvb; 206 struct tm6000_dvb *dvb = dev->dvb;
197 207
198 printk(KERN_INFO "tm6000: got stop feed request %s\n",__FUNCTION__); 208 printk(KERN_INFO "tm6000: got stop feed request %s\n", __FUNCTION__);
199 209
200 mutex_lock(&dvb->mutex); 210 mutex_lock(&dvb->mutex);
201 211
202 printk (KERN_INFO "stream %#x\n", dvb->streams); 212 printk(KERN_INFO "stream %#x\n", dvb->streams);
203 --(dvb->streams); 213 --(dvb->streams);
204 if(dvb->streams == 0) { 214 if (dvb->streams == 0) {
205 printk (KERN_INFO "stop stream\n"); 215 printk(KERN_INFO "stop stream\n");
206 tm6000_stop_stream(dev); 216 tm6000_stop_stream(dev);
207/* mutex_destroy(&tm6000_dev->streaming_mutex); */ 217/* mutex_destroy(&tm6000_dev->streaming_mutex); */
208 } 218 }
@@ -216,9 +226,9 @@ int tm6000_dvb_attach_frontend(struct tm6000_core *dev)
216{ 226{
217 struct tm6000_dvb *dvb = dev->dvb; 227 struct tm6000_dvb *dvb = dev->dvb;
218 228
219 if(dev->caps.has_zl10353) { 229 if (dev->caps.has_zl10353) {
220 struct zl10353_config config = 230 struct zl10353_config config = {
221 {.demod_address = dev->demod_addr, 231 .demod_address = dev->demod_addr,
222 .no_tuner = 1, 232 .no_tuner = 1,
223 .parallel_ts = 1, 233 .parallel_ts = 1,
224 .if2 = 45700, 234 .if2 = 45700,
@@ -227,8 +237,7 @@ int tm6000_dvb_attach_frontend(struct tm6000_core *dev)
227 237
228 dvb->frontend = dvb_attach(zl10353_attach, &config, 238 dvb->frontend = dvb_attach(zl10353_attach, &config,
229 &dev->i2c_adap); 239 &dev->i2c_adap);
230 } 240 } else {
231 else {
232 printk(KERN_ERR "tm6000: no frontend defined for the device!\n"); 241 printk(KERN_ERR "tm6000: no frontend defined for the device!\n");
233 return -1; 242 return -1;
234 } 243 }
@@ -238,7 +247,7 @@ int tm6000_dvb_attach_frontend(struct tm6000_core *dev)
238 247
239DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); 248DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
240 249
241int tm6000_dvb_register(struct tm6000_core *dev) 250int register_dvb(struct tm6000_core *dev)
242{ 251{
243 int ret = -1; 252 int ret = -1;
244 struct tm6000_dvb *dvb = dev->dvb; 253 struct tm6000_dvb *dvb = dev->dvb;
@@ -249,13 +258,13 @@ int tm6000_dvb_register(struct tm6000_core *dev)
249 258
250 /* attach the frontend */ 259 /* attach the frontend */
251 ret = tm6000_dvb_attach_frontend(dev); 260 ret = tm6000_dvb_attach_frontend(dev);
252 if(ret < 0) { 261 if (ret < 0) {
253 printk(KERN_ERR "tm6000: couldn't attach the frontend!\n"); 262 printk(KERN_ERR "tm6000: couldn't attach the frontend!\n");
254 goto err; 263 goto err;
255 } 264 }
256 265
257 ret = dvb_register_adapter(&dvb->adapter, "Trident TVMaster 6000 DVB-T", 266 ret = dvb_register_adapter(&dvb->adapter, "Trident TVMaster 6000 DVB-T",
258 THIS_MODULE, &dev->udev->dev, adapter_nr); 267 THIS_MODULE, &dev->udev->dev, adapter_nr);
259 dvb->adapter.priv = dev; 268 dvb->adapter.priv = dev;
260 269
261 if (dvb->frontend) { 270 if (dvb->frontend) {
@@ -308,9 +317,8 @@ int tm6000_dvb_register(struct tm6000_core *dev)
308 break; 317 break;
309 } 318 }
310 } 319 }
311 } else { 320 } else
312 printk(KERN_ERR "tm6000: no frontend found\n"); 321 printk(KERN_ERR "tm6000: no frontend found\n");
313 }
314 322
315 dvb->demux.dmx.capabilities = DMX_TS_FILTERING | DMX_SECTION_FILTERING 323 dvb->demux.dmx.capabilities = DMX_TS_FILTERING | DMX_SECTION_FILTERING
316 | DMX_MEMORY_BASED_FILTERING; 324 | DMX_MEMORY_BASED_FILTERING;
@@ -321,7 +329,7 @@ int tm6000_dvb_register(struct tm6000_core *dev)
321 dvb->demux.stop_feed = tm6000_stop_feed; 329 dvb->demux.stop_feed = tm6000_stop_feed;
322 dvb->demux.write_to_decoder = NULL; 330 dvb->demux.write_to_decoder = NULL;
323 ret = dvb_dmx_init(&dvb->demux); 331 ret = dvb_dmx_init(&dvb->demux);
324 if(ret < 0) { 332 if (ret < 0) {
325 printk("tm6000: dvb_dmx_init failed (errno = %d)\n", ret); 333 printk("tm6000: dvb_dmx_init failed (errno = %d)\n", ret);
326 goto frontend_err; 334 goto frontend_err;
327 } 335 }
@@ -331,7 +339,7 @@ int tm6000_dvb_register(struct tm6000_core *dev)
331 dvb->dmxdev.capabilities = 0; 339 dvb->dmxdev.capabilities = 0;
332 340
333 ret = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter); 341 ret = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter);
334 if(ret < 0) { 342 if (ret < 0) {
335 printk("tm6000: dvb_dmxdev_init failed (errno = %d)\n", ret); 343 printk("tm6000: dvb_dmxdev_init failed (errno = %d)\n", ret);
336 goto dvb_dmx_err; 344 goto dvb_dmx_err;
337 } 345 }
@@ -341,7 +349,7 @@ int tm6000_dvb_register(struct tm6000_core *dev)
341dvb_dmx_err: 349dvb_dmx_err:
342 dvb_dmx_release(&dvb->demux); 350 dvb_dmx_release(&dvb->demux);
343frontend_err: 351frontend_err:
344 if(dvb->frontend) { 352 if (dvb->frontend) {
345 dvb_frontend_detach(dvb->frontend); 353 dvb_frontend_detach(dvb->frontend);
346 dvb_unregister_frontend(dvb->frontend); 354 dvb_unregister_frontend(dvb->frontend);
347 } 355 }
@@ -351,11 +359,11 @@ err:
351 return ret; 359 return ret;
352} 360}
353 361
354void tm6000_dvb_unregister(struct tm6000_core *dev) 362void unregister_dvb(struct tm6000_core *dev)
355{ 363{
356 struct tm6000_dvb *dvb = dev->dvb; 364 struct tm6000_dvb *dvb = dev->dvb;
357 365
358 if(dvb->bulk_urb != NULL) { 366 if (dvb->bulk_urb != NULL) {
359 struct urb *bulk_urb = dvb->bulk_urb; 367 struct urb *bulk_urb = dvb->bulk_urb;
360 368
361 kfree(bulk_urb->transfer_buffer); 369 kfree(bulk_urb->transfer_buffer);
@@ -365,7 +373,7 @@ void tm6000_dvb_unregister(struct tm6000_core *dev)
365 } 373 }
366 374
367/* mutex_lock(&tm6000_driver.open_close_mutex); */ 375/* mutex_lock(&tm6000_driver.open_close_mutex); */
368 if(dvb->frontend) { 376 if (dvb->frontend) {
369 dvb_frontend_detach(dvb->frontend); 377 dvb_frontend_detach(dvb->frontend);
370 dvb_unregister_frontend(dvb->frontend); 378 dvb_unregister_frontend(dvb->frontend);
371 } 379 }
@@ -375,5 +383,70 @@ void tm6000_dvb_unregister(struct tm6000_core *dev)
375 dvb_unregister_adapter(&dvb->adapter); 383 dvb_unregister_adapter(&dvb->adapter);
376 mutex_destroy(&dvb->mutex); 384 mutex_destroy(&dvb->mutex);
377/* mutex_unlock(&tm6000_driver.open_close_mutex); */ 385/* mutex_unlock(&tm6000_driver.open_close_mutex); */
386}
378 387
388static int dvb_init(struct tm6000_core *dev)
389{
390 struct tm6000_dvb *dvb;
391 int rc;
392
393 if (!dev)
394 return 0;
395
396 if (!dev->caps.has_dvb)
397 return 0;
398
399 dvb = kzalloc(sizeof(struct tm6000_dvb), GFP_KERNEL);
400 if (!dvb) {
401 printk(KERN_INFO "Cannot allocate memory\n");
402 return -ENOMEM;
403 }
404
405 dev->dvb = dvb;
406
407 rc = register_dvb(dev);
408 if (rc < 0) {
409 kfree(dvb);
410 dev->dvb = NULL;
411 return 0;
412 }
413
414 return 0;
415}
416
417static int dvb_fini(struct tm6000_core *dev)
418{
419 if (!dev)
420 return 0;
421
422 if (!dev->caps.has_dvb)
423 return 0;
424
425 if (dev->dvb) {
426 unregister_dvb(dev);
427 kfree(dev->dvb);
428 dev->dvb = NULL;
429 }
430
431 return 0;
379} 432}
433
434static struct tm6000_ops dvb_ops = {
435 .type = TM6000_DVB,
436 .name = "TM6000 dvb Extension",
437 .init = dvb_init,
438 .fini = dvb_fini,
439};
440
441static int __init tm6000_dvb_register(void)
442{
443 return tm6000_register_extension(&dvb_ops);
444}
445
446static void __exit tm6000_dvb_unregister(void)
447{
448 tm6000_unregister_extension(&dvb_ops);
449}
450
451module_init(tm6000_dvb_register);
452module_exit(tm6000_dvb_unregister);
diff --git a/drivers/staging/tm6000/tm6000-i2c.c b/drivers/staging/tm6000/tm6000-i2c.c
index 94ff489a1bbb..79bc67f0311f 100644
--- a/drivers/staging/tm6000/tm6000-i2c.c
+++ b/drivers/staging/tm6000/tm6000-i2c.c
@@ -40,7 +40,7 @@ static unsigned int i2c_debug = 0;
40module_param(i2c_debug, int, 0644); 40module_param(i2c_debug, int, 0644);
41MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]"); 41MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]");
42 42
43#define i2c_dprintk(lvl,fmt, args...) if (i2c_debug>=lvl) do{ \ 43#define i2c_dprintk(lvl, fmt, args...) if (i2c_debug >= lvl) do { \
44 printk(KERN_DEBUG "%s at %s: " fmt, \ 44 printk(KERN_DEBUG "%s at %s: " fmt, \
45 dev->name, __FUNCTION__ , ##args); } while (0) 45 dev->name, __FUNCTION__ , ##args); } while (0)
46 46
@@ -171,7 +171,7 @@ static int tm6000_i2c_xfer(struct i2c_adapter *i2c_adap,
171 return 0; 171 return 0;
172 for (i = 0; i < num; i++) { 172 for (i = 0; i < num; i++) {
173 addr = (msgs[i].addr << 1) & 0xff; 173 addr = (msgs[i].addr << 1) & 0xff;
174 i2c_dprintk(2,"%s %s addr=0x%x len=%d:", 174 i2c_dprintk(2, "%s %s addr=0x%x len=%d:",
175 (msgs[i].flags & I2C_M_RD) ? "read" : "write", 175 (msgs[i].flags & I2C_M_RD) ? "read" : "write",
176 i == num - 1 ? "stop" : "nonstop", addr, msgs[i].len); 176 i == num - 1 ? "stop" : "nonstop", addr, msgs[i].len);
177 if (msgs[i].flags & I2C_M_RD) { 177 if (msgs[i].flags & I2C_M_RD) {
@@ -235,7 +235,7 @@ static int tm6000_i2c_xfer(struct i2c_adapter *i2c_adap,
235 235
236 return num; 236 return num;
237err: 237err:
238 i2c_dprintk(2," ERROR: %i\n", rc); 238 i2c_dprintk(2, " ERROR: %i\n", rc);
239 return rc; 239 return rc;
240} 240}
241 241
@@ -266,11 +266,10 @@ static int tm6000_i2c_eeprom(struct tm6000_core *dev,
266 if (0 == (i % 16)) 266 if (0 == (i % 16))
267 printk(KERN_INFO "%s: i2c eeprom %02x:", dev->name, i); 267 printk(KERN_INFO "%s: i2c eeprom %02x:", dev->name, i);
268 printk(" %02x", eedata[i]); 268 printk(" %02x", eedata[i]);
269 if ((eedata[i] >= ' ') && (eedata[i] <= 'z')) { 269 if ((eedata[i] >= ' ') && (eedata[i] <= 'z'))
270 bytes[i%16] = eedata[i]; 270 bytes[i%16] = eedata[i];
271 } else { 271 else
272 bytes[i%16]='.'; 272 bytes[i%16] = '.';
273 }
274 273
275 i++; 274 i++;
276 275
@@ -305,15 +304,15 @@ static u32 functionality(struct i2c_adapter *adap)
305} 304}
306 305
307#define mass_write(addr, reg, data...) \ 306#define mass_write(addr, reg, data...) \
308 { const static u8 _val[] = data; \ 307 { static const u8 _val[] = data; \
309 rc=tm6000_read_write_usb(dev,USB_DIR_OUT | USB_TYPE_VENDOR, \ 308 rc = tm6000_read_write_usb(dev, USB_DIR_OUT | USB_TYPE_VENDOR, \
310 REQ_16_SET_GET_I2C_WR1_RDN,(reg<<8)+addr, 0x00, (u8 *) _val, \ 309 REQ_16_SET_GET_I2C_WR1_RDN, (reg<<8)+addr, 0x00, (u8 *) _val, \
311 ARRAY_SIZE(_val)); \ 310 ARRAY_SIZE(_val)); \
312 if (rc<0) { \ 311 if (rc < 0) { \
313 printk(KERN_ERR "Error on line %d: %d\n",__LINE__,rc); \ 312 printk(KERN_ERR "Error on line %d: %d\n", __LINE__, rc); \
314 return rc; \ 313 return rc; \
315 } \ 314 } \
316 msleep (10); \ 315 msleep(10); \
317 } 316 }
318 317
319static struct i2c_algorithm tm6000_algo = { 318static struct i2c_algorithm tm6000_algo = {
diff --git a/drivers/staging/tm6000/tm6000-input.c b/drivers/staging/tm6000/tm6000-input.c
new file mode 100644
index 000000000000..32f7a0af6938
--- /dev/null
+++ b/drivers/staging/tm6000/tm6000-input.c
@@ -0,0 +1,364 @@
1/*
2 tm6000-input.c - driver for TM5600/TM6000/TM6010 USB video capture devices
3
4 Copyright (C) 2010 Stefan Ringel <stefan.ringel@arcor.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 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
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20#include <linux/module.h>
21#include <linux/init.h>
22#include <linux/delay.h>
23
24#include <linux/input.h>
25#include <linux/usb.h>
26
27#include <media/ir-core.h>
28#include <media/ir-common.h>
29
30#include "tm6000.h"
31#include "tm6000-regs.h"
32
33static unsigned int ir_debug;
34module_param(ir_debug, int, 0644);
35MODULE_PARM_DESC(ir_debug, "enable debug message [IR]");
36
37static unsigned int enable_ir = 1;
38module_param(enable_ir, int, 0644);
39MODULE_PARM_DESC(enable_ir, "enable ir (default is enable");
40
41#undef dprintk
42
43#define dprintk(fmt, arg...) \
44 if (ir_debug) { \
45 printk(KERN_DEBUG "%s/ir: " fmt, ir->name , ## arg); \
46 }
47
48struct tm6000_ir_poll_result {
49 u8 rc_data[4];
50};
51
52struct tm6000_IR {
53 struct tm6000_core *dev;
54 struct ir_input_dev *input;
55 struct ir_input_state ir;
56 char name[32];
57 char phys[32];
58
59 /* poll expernal decoder */
60 int polling;
61 struct delayed_work work;
62 u8 wait:1;
63 struct urb *int_urb;
64 u8 *urb_data;
65 u8 key:1;
66
67 int (*get_key) (struct tm6000_IR *, struct tm6000_ir_poll_result *);
68
69 /* IR device properties */
70 struct ir_dev_props props;
71};
72
73
74void tm6000_ir_wait(struct tm6000_core *dev, u8 state)
75{
76 struct tm6000_IR *ir = dev->ir;
77
78 if (!dev->ir)
79 return;
80
81 if (state)
82 ir->wait = 1;
83 else
84 ir->wait = 0;
85}
86
87
88static int tm6000_ir_config(struct tm6000_IR *ir)
89{
90 struct tm6000_core *dev = ir->dev;
91 u8 buf[10];
92 int rc;
93
94 /* hack */
95 buf[0] = 0xff;
96 buf[1] = 0xff;
97 buf[2] = 0xf2;
98 buf[3] = 0x2b;
99 buf[4] = 0x20;
100 buf[5] = 0x35;
101 buf[6] = 0x60;
102 buf[7] = 0x04;
103 buf[8] = 0xc0;
104 buf[9] = 0x08;
105
106 rc = tm6000_read_write_usb(dev, USB_DIR_OUT | USB_TYPE_VENDOR |
107 USB_RECIP_DEVICE, REQ_00_SET_IR_VALUE, 0, 0, buf, 0x0a);
108 msleep(100);
109
110 if (rc < 0) {
111 printk(KERN_INFO "IR configuration failed");
112 return rc;
113 }
114 return 0;
115}
116
117static void tm6000_ir_urb_received(struct urb *urb)
118{
119 struct tm6000_core *dev = urb->context;
120 struct tm6000_IR *ir = dev->ir;
121 int rc;
122
123 if (urb->status != 0)
124 printk(KERN_INFO "not ready\n");
125 else if (urb->actual_length > 0)
126 memcpy(ir->urb_data, urb->transfer_buffer, urb->actual_length);
127
128 dprintk("data %02x %02x %02x %02x\n", ir->urb_data[0],
129 ir->urb_data[1], ir->urb_data[2], ir->urb_data[3]);
130
131 ir->key = 1;
132
133 rc = usb_submit_urb(urb, GFP_ATOMIC);
134}
135
136static int default_polling_getkey(struct tm6000_IR *ir,
137 struct tm6000_ir_poll_result *poll_result)
138{
139 struct tm6000_core *dev = ir->dev;
140 int rc;
141 u8 buf[2];
142
143 if (ir->wait && !&dev->int_in) {
144 poll_result->rc_data[0] = 0xff;
145 return 0;
146 }
147
148 if (&dev->int_in) {
149 poll_result->rc_data[0] = ir->urb_data[0];
150 poll_result->rc_data[1] = ir->urb_data[1];
151 } else {
152 tm6000_set_reg(dev, REQ_04_EN_DISABLE_MCU_INT, 2, 0);
153 msleep(10);
154 tm6000_set_reg(dev, REQ_04_EN_DISABLE_MCU_INT, 2, 1);
155 msleep(10);
156
157 rc = tm6000_read_write_usb(dev, USB_DIR_IN | USB_TYPE_VENDOR |
158 USB_RECIP_DEVICE, REQ_02_GET_IR_CODE, 0, 0, buf, 1);
159
160 msleep(10);
161
162 dprintk("read data=%02x\n", buf[0]);
163 if (rc < 0)
164 return rc;
165
166 poll_result->rc_data[0] = buf[0];
167 }
168 return 0;
169}
170
171static void tm6000_ir_handle_key(struct tm6000_IR *ir)
172{
173 int result;
174 struct tm6000_ir_poll_result poll_result;
175
176 /* read the registers containing the IR status */
177 result = ir->get_key(ir, &poll_result);
178 if (result < 0) {
179 printk(KERN_INFO "ir->get_key() failed %d\n", result);
180 return;
181 }
182
183 dprintk("ir->get_key result data=%02x %02x\n",
184 poll_result.rc_data[0], poll_result.rc_data[1]);
185
186 if (poll_result.rc_data[0] != 0xff && ir->key == 1) {
187 ir_input_keydown(ir->input->input_dev, &ir->ir,
188 poll_result.rc_data[0] | poll_result.rc_data[1] << 8);
189
190 ir_input_nokey(ir->input->input_dev, &ir->ir);
191 ir->key = 0;
192 }
193 return;
194}
195
196static void tm6000_ir_work(struct work_struct *work)
197{
198 struct tm6000_IR *ir = container_of(work, struct tm6000_IR, work.work);
199
200 tm6000_ir_handle_key(ir);
201 schedule_delayed_work(&ir->work, msecs_to_jiffies(ir->polling));
202}
203
204static int tm6000_ir_start(void *priv)
205{
206 struct tm6000_IR *ir = priv;
207
208 INIT_DELAYED_WORK(&ir->work, tm6000_ir_work);
209 schedule_delayed_work(&ir->work, 0);
210
211 return 0;
212}
213
214static void tm6000_ir_stop(void *priv)
215{
216 struct tm6000_IR *ir = priv;
217
218 cancel_delayed_work_sync(&ir->work);
219}
220
221int tm6000_ir_change_protocol(void *priv, u64 ir_type)
222{
223 struct tm6000_IR *ir = priv;
224
225 ir->get_key = default_polling_getkey;
226
227 tm6000_ir_config(ir);
228 /* TODO */
229 return 0;
230}
231
232int tm6000_ir_init(struct tm6000_core *dev)
233{
234 struct tm6000_IR *ir;
235 struct ir_input_dev *ir_input_dev;
236 int err = -ENOMEM;
237 int pipe, size, rc;
238
239 if (!enable_ir)
240 return -ENODEV;
241
242 if (!dev->caps.has_remote)
243 return 0;
244
245 if (!dev->ir_codes)
246 return 0;
247
248 ir = kzalloc(sizeof(*ir), GFP_KERNEL);
249 ir_input_dev = kzalloc(sizeof(*ir_input_dev), GFP_KERNEL);
250 ir_input_dev->input_dev = input_allocate_device();
251 if (!ir || !ir_input_dev || !ir_input_dev->input_dev)
252 goto err_out_free;
253
254 /* record handles to ourself */
255 ir->dev = dev;
256 dev->ir = ir;
257
258 ir->input = ir_input_dev;
259
260 /* input einrichten */
261 ir->props.allowed_protos = IR_TYPE_RC5 | IR_TYPE_NEC;
262 ir->props.priv = ir;
263 ir->props.change_protocol = tm6000_ir_change_protocol;
264 ir->props.open = tm6000_ir_start;
265 ir->props.close = tm6000_ir_stop;
266 ir->props.driver_type = RC_DRIVER_SCANCODE;
267
268 ir->polling = 50;
269
270 snprintf(ir->name, sizeof(ir->name), "tm5600/60x0 IR (%s)",
271 dev->name);
272
273 usb_make_path(dev->udev, ir->phys, sizeof(ir->phys));
274 strlcat(ir->phys, "/input0", sizeof(ir->phys));
275
276 tm6000_ir_change_protocol(ir, IR_TYPE_UNKNOWN);
277 err = ir_input_init(ir_input_dev->input_dev, &ir->ir, IR_TYPE_OTHER);
278 if (err < 0)
279 goto err_out_free;
280
281 ir_input_dev->input_dev->name = ir->name;
282 ir_input_dev->input_dev->phys = ir->phys;
283 ir_input_dev->input_dev->id.bustype = BUS_USB;
284 ir_input_dev->input_dev->id.version = 1;
285 ir_input_dev->input_dev->id.vendor = le16_to_cpu(dev->udev->descriptor.idVendor);
286 ir_input_dev->input_dev->id.product = le16_to_cpu(dev->udev->descriptor.idProduct);
287
288 ir_input_dev->input_dev->dev.parent = &dev->udev->dev;
289
290 if (&dev->int_in) {
291 dprintk("IR over int\n");
292
293 ir->int_urb = usb_alloc_urb(0, GFP_KERNEL);
294
295 pipe = usb_rcvintpipe(dev->udev,
296 dev->int_in.endp->desc.bEndpointAddress
297 & USB_ENDPOINT_NUMBER_MASK);
298
299 size = usb_maxpacket(dev->udev, pipe, usb_pipeout(pipe));
300 dprintk("IR max size: %d\n", size);
301
302 ir->int_urb->transfer_buffer = kzalloc(size, GFP_KERNEL);
303 if (ir->int_urb->transfer_buffer == NULL) {
304 usb_free_urb(ir->int_urb);
305 goto err_out_stop;
306 }
307 dprintk("int interval: %d\n", dev->int_in.endp->desc.bInterval);
308 usb_fill_int_urb(ir->int_urb, dev->udev, pipe,
309 ir->int_urb->transfer_buffer, size,
310 tm6000_ir_urb_received, dev,
311 dev->int_in.endp->desc.bInterval);
312 rc = usb_submit_urb(ir->int_urb, GFP_KERNEL);
313 if (rc) {
314 kfree(ir->int_urb->transfer_buffer);
315 usb_free_urb(ir->int_urb);
316 err = rc;
317 goto err_out_stop;
318 }
319 ir->urb_data = kzalloc(size, GFP_KERNEL);
320 }
321
322 /* ir register */
323 err = ir_input_register(ir->input->input_dev, dev->ir_codes,
324 &ir->props, "tm6000");
325 if (err)
326 goto err_out_stop;
327
328 return 0;
329
330err_out_stop:
331 dev->ir = NULL;
332err_out_free:
333 kfree(ir_input_dev);
334 kfree(ir);
335 return err;
336}
337
338int tm6000_ir_fini(struct tm6000_core *dev)
339{
340 struct tm6000_IR *ir = dev->ir;
341
342 /* skip detach on non attached board */
343
344 if (!ir)
345 return 0;
346
347 ir_input_unregister(ir->input->input_dev);
348
349 if (ir->int_urb) {
350 usb_kill_urb(ir->int_urb);
351 kfree(ir->int_urb->transfer_buffer);
352 usb_free_urb(ir->int_urb);
353 ir->int_urb = NULL;
354 kfree(ir->urb_data);
355 ir->urb_data = NULL;
356 }
357
358 kfree(ir->input);
359 ir->input = NULL;
360 kfree(ir);
361 dev->ir = NULL;
362
363 return 0;
364}
diff --git a/drivers/staging/tm6000/tm6000-stds.c b/drivers/staging/tm6000/tm6000-stds.c
index b3564f611e5e..6bf4a73b320d 100644
--- a/drivers/staging/tm6000/tm6000-stds.c
+++ b/drivers/staging/tm6000/tm6000-stds.c
@@ -77,7 +77,7 @@ static struct tm6000_std_tv_settings tv_stds[] = {
77 {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e}, 77 {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e},
78 {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f}, 78 {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f},
79 {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x00}, 79 {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x00},
80 {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x01}, 80 {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x31},
81 {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x1e}, 81 {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x1e},
82 {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x83}, 82 {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x83},
83 {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0x0a}, 83 {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0x0a},
@@ -135,7 +135,7 @@ static struct tm6000_std_tv_settings tv_stds[] = {
135 {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e}, 135 {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e},
136 {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f}, 136 {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f},
137 {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x02}, 137 {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x02},
138 {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x01}, 138 {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x31},
139 {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x1e}, 139 {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x1e},
140 {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x91}, 140 {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x91},
141 {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0x1f}, 141 {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0x1f},
@@ -193,7 +193,7 @@ static struct tm6000_std_tv_settings tv_stds[] = {
193 {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e}, 193 {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e},
194 {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f}, 194 {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f},
195 {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x02}, 195 {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x02},
196 {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x01}, 196 {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x31},
197 {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x25}, 197 {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x25},
198 {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0xd5}, 198 {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0xd5},
199 {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0x63}, 199 {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0x63},
@@ -251,7 +251,7 @@ static struct tm6000_std_tv_settings tv_stds[] = {
251 {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e}, 251 {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e},
252 {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f}, 252 {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f},
253 {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x02}, 253 {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x02},
254 {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x01}, 254 {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x31},
255 {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x24}, 255 {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x24},
256 {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x92}, 256 {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x92},
257 {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0xe8}, 257 {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0xe8},
@@ -308,7 +308,7 @@ static struct tm6000_std_tv_settings tv_stds[] = {
308 {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0f}, 308 {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0f},
309 {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f}, 309 {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f},
310 {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x00}, 310 {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x00},
311 {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x01}, 311 {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x31},
312 {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x1e}, 312 {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x1e},
313 {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x8b}, 313 {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x8b},
314 {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0xa2}, 314 {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0xa2},
@@ -354,7 +354,7 @@ static struct tm6000_std_settings composite_stds[] = {
354 {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e}, 354 {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e},
355 {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f}, 355 {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f},
356 {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x00}, 356 {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x00},
357 {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x01}, 357 {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x31},
358 {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x1e}, 358 {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x1e},
359 {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x83}, 359 {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x83},
360 {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0x0a}, 360 {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0x0a},
@@ -396,7 +396,7 @@ static struct tm6000_std_settings composite_stds[] = {
396 {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e}, 396 {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e},
397 {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f}, 397 {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f},
398 {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x02}, 398 {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x02},
399 {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x01}, 399 {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x31},
400 {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x1e}, 400 {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x1e},
401 {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x91}, 401 {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x91},
402 {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0x1f}, 402 {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0x1f},
@@ -438,7 +438,7 @@ static struct tm6000_std_settings composite_stds[] = {
438 {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e}, 438 {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e},
439 {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f}, 439 {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f},
440 {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x02}, 440 {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x02},
441 {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x01}, 441 {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x31},
442 {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x25}, 442 {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x25},
443 {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0xd5}, 443 {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0xd5},
444 {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0x63}, 444 {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0x63},
@@ -480,7 +480,7 @@ static struct tm6000_std_settings composite_stds[] = {
480 {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e}, 480 {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e},
481 {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f}, 481 {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f},
482 {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x02}, 482 {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x02},
483 {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x01}, 483 {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x31},
484 {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x24}, 484 {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x24},
485 {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x92}, 485 {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x92},
486 {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0xe8}, 486 {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0xe8},
@@ -521,7 +521,7 @@ static struct tm6000_std_settings composite_stds[] = {
521 {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0f}, 521 {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0f},
522 {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f}, 522 {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f},
523 {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x00}, 523 {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x00},
524 {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x01}, 524 {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x31},
525 {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x1e}, 525 {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x1e},
526 {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x8b}, 526 {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x8b},
527 {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0xa2}, 527 {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0xa2},
@@ -567,7 +567,7 @@ static struct tm6000_std_settings svideo_stds[] = {
567 {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e}, 567 {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e},
568 {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f}, 568 {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f},
569 {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x04}, 569 {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x04},
570 {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x01}, 570 {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x31},
571 {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x1e}, 571 {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x1e},
572 {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x83}, 572 {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x83},
573 {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0x0a}, 573 {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0x0a},
@@ -609,7 +609,7 @@ static struct tm6000_std_settings svideo_stds[] = {
609 {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e}, 609 {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e},
610 {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f}, 610 {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f},
611 {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x04}, 611 {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x04},
612 {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x01}, 612 {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x31},
613 {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x1e}, 613 {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x1e},
614 {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x91}, 614 {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x91},
615 {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0x1f}, 615 {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0x1f},
@@ -651,7 +651,7 @@ static struct tm6000_std_settings svideo_stds[] = {
651 {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e}, 651 {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e},
652 {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f}, 652 {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f},
653 {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x04}, 653 {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x04},
654 {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x00}, 654 {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x30},
655 {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x25}, 655 {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x25},
656 {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0xd5}, 656 {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0xd5},
657 {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0x63}, 657 {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0x63},
@@ -693,7 +693,7 @@ static struct tm6000_std_settings svideo_stds[] = {
693 {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e}, 693 {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e},
694 {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f}, 694 {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f},
695 {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x03}, 695 {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x03},
696 {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x01}, 696 {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x31},
697 {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x24}, 697 {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x24},
698 {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x92}, 698 {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x92},
699 {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0xe8}, 699 {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0xe8},
@@ -734,7 +734,7 @@ static struct tm6000_std_settings svideo_stds[] = {
734 {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0f}, 734 {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0f},
735 {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f}, 735 {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f},
736 {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x03}, 736 {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x03},
737 {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x00}, 737 {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x30},
738 {TM6010_REQ07_R17_HLOOP_MAXSTATE, 0x8b}, 738 {TM6010_REQ07_R17_HLOOP_MAXSTATE, 0x8b},
739 {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x1e}, 739 {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x1e},
740 {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x8b}, 740 {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x8b},
@@ -763,11 +763,11 @@ static struct tm6000_std_settings svideo_stds[] = {
763void tm6000_get_std_res(struct tm6000_core *dev) 763void tm6000_get_std_res(struct tm6000_core *dev)
764{ 764{
765 /* Currently, those are the only supported resoltions */ 765 /* Currently, those are the only supported resoltions */
766 if (dev->norm & V4L2_STD_525_60) { 766 if (dev->norm & V4L2_STD_525_60)
767 dev->height = 480; 767 dev->height = 480;
768 } else { 768 else
769 dev->height = 576; 769 dev->height = 576;
770 } 770
771 dev->width = 720; 771 dev->width = 720;
772} 772}
773 773
diff --git a/drivers/staging/tm6000/tm6000-usb-isoc.h b/drivers/staging/tm6000/tm6000-usb-isoc.h
index 5a5049acd4ec..138716a8f056 100644
--- a/drivers/staging/tm6000/tm6000-usb-isoc.h
+++ b/drivers/staging/tm6000/tm6000-usb-isoc.h
@@ -39,7 +39,7 @@ struct usb_isoc_ctl {
39 int pos, size, pktsize; 39 int pos, size, pktsize;
40 40
41 /* Last field: ODD or EVEN? */ 41 /* Last field: ODD or EVEN? */
42 int field; 42 int vfield;
43 43
44 /* Stores incomplete commands */ 44 /* Stores incomplete commands */
45 u32 tmp_buf; 45 u32 tmp_buf;
@@ -47,7 +47,4 @@ struct usb_isoc_ctl {
47 47
48 /* Stores already requested buffers */ 48 /* Stores already requested buffers */
49 struct tm6000_buffer *buf; 49 struct tm6000_buffer *buf;
50
51 /* Stores the number of received fields */
52 int nfields;
53}; 50};
diff --git a/drivers/staging/tm6000/tm6000-video.c b/drivers/staging/tm6000/tm6000-video.c
index 56fa371e08c8..ce0a089a0771 100644
--- a/drivers/staging/tm6000/tm6000-video.c
+++ b/drivers/staging/tm6000/tm6000-video.c
@@ -56,6 +56,7 @@ static int video_nr = -1; /* /dev/videoN, -1 for autodetect */
56 56
57/* Debug level */ 57/* Debug level */
58int tm6000_debug; 58int tm6000_debug;
59EXPORT_SYMBOL_GPL(tm6000_debug);
59 60
60/* supported controls */ 61/* supported controls */
61static struct v4l2_queryctrl tm6000_qctrl[] = { 62static struct v4l2_queryctrl tm6000_qctrl[] = {
@@ -149,8 +150,6 @@ static inline void get_next_buf(struct tm6000_dmaqueue *dma_q,
149 150
150 /* Cleans up buffer - Usefull for testing for frame/URB loss */ 151 /* Cleans up buffer - Usefull for testing for frame/URB loss */
151 outp = videobuf_to_vmalloc(&(*buf)->vb); 152 outp = videobuf_to_vmalloc(&(*buf)->vb);
152// if (outp)
153// memset(outp, 0, (*buf)->vb.size);
154 153
155 return; 154 return;
156} 155}
@@ -186,236 +185,152 @@ const char *tm6000_msg_type[] = {
186/* 185/*
187 * Identify the tm5600/6000 buffer header type and properly handles 186 * Identify the tm5600/6000 buffer header type and properly handles
188 */ 187 */
189static int copy_packet(struct urb *urb, u32 header, u8 **ptr, u8 *endp,
190 u8 *out_p, struct tm6000_buffer **buf)
191{
192 struct tm6000_dmaqueue *dma_q = urb->context;
193 struct tm6000_core *dev = container_of(dma_q, struct tm6000_core, vidq);
194 u8 c;
195 unsigned int cmd, cpysize, pktsize, size, field, block, line, pos = 0;
196 int rc = 0;
197 /* FIXME: move to tm6000-isoc */
198 static int last_line = -2, start_line = -2, last_field = -2;
199
200 /* FIXME: this is the hardcoded window size
201 */
202 unsigned int linewidth = (*buf)->vb.width << 1;
203
204 if (!dev->isoc_ctl.cmd) {
205 c = (header >> 24) & 0xff;
206
207 /* split the header fields */
208 size = ((header & 0x7e) << 1);
209
210 if (size > 0)
211 size -= 4;
212
213 block = (header >> 7) & 0xf;
214 field = (header >> 11) & 0x1;
215 line = (header >> 12) & 0x1ff;
216 cmd = (header >> 21) & 0x7;
217
218 /* Validates header fields */
219 if(size > TM6000_URB_MSG_LEN)
220 size = TM6000_URB_MSG_LEN;
221
222 if (cmd == TM6000_URB_MSG_VIDEO) {
223 if ((block+1)*TM6000_URB_MSG_LEN>linewidth)
224 cmd = TM6000_URB_MSG_ERR;
225
226 /* FIXME: Mounts the image as field0+field1
227 * It should, instead, check if the user selected
228 * entrelaced or non-entrelaced mode
229 */
230 pos = ((line << 1) - field - 1) * linewidth +
231 block * TM6000_URB_MSG_LEN;
232
233 /* Don't allow to write out of the buffer */
234 if (pos+TM6000_URB_MSG_LEN > (*buf)->vb.size) {
235 dprintk(dev, V4L2_DEBUG_ISOC,
236 "ERR: size=%d, num=%d, line=%d, "
237 "field=%d\n",
238 size, block, line, field);
239
240 cmd = TM6000_URB_MSG_ERR;
241 }
242 } else {
243 pos=0;
244 }
245
246 /* Prints debug info */
247 dprintk(dev, V4L2_DEBUG_ISOC, "size=%d, num=%d, "
248 " line=%d, field=%d\n",
249 size, block, line, field);
250
251 if ((last_line!=line)&&(last_line+1!=line) &&
252 (cmd != TM6000_URB_MSG_ERR) ) {
253 if (cmd != TM6000_URB_MSG_VIDEO) {
254 dprintk(dev, V4L2_DEBUG_ISOC, "cmd=%d, "
255 "size=%d, num=%d, line=%d, field=%d\n",
256 cmd, size, block, line, field);
257 }
258 if (start_line<0)
259 start_line=last_line;
260 /* Prints debug info */
261 dprintk(dev, V4L2_DEBUG_ISOC, "lines= %d-%d, "
262 "field=%d\n",
263 start_line, last_line, field);
264
265 if ((start_line<6 && last_line>200) &&
266 (last_field != field) ) {
267
268 dev->isoc_ctl.nfields++;
269 if (dev->isoc_ctl.nfields>=2) {
270 dev->isoc_ctl.nfields=0;
271
272 /* Announces that a new buffer were filled */
273 buffer_filled (dev, dma_q, *buf);
274 dprintk(dev, V4L2_DEBUG_ISOC,
275 "new buffer filled\n");
276 get_next_buf (dma_q, buf);
277 if (!*buf)
278 return rc;
279 out_p = videobuf_to_vmalloc(&((*buf)->vb));
280 if (!out_p)
281 return rc;
282
283 pos = dev->isoc_ctl.pos = 0;
284 }
285 }
286
287 start_line=line;
288 last_field=field;
289 }
290 if (cmd == TM6000_URB_MSG_VIDEO)
291 last_line = line;
292
293 pktsize = TM6000_URB_MSG_LEN;
294 } else {
295 /* Continue the last copy */
296 cmd = dev->isoc_ctl.cmd;
297 size= dev->isoc_ctl.size;
298 pos = dev->isoc_ctl.pos;
299 pktsize = dev->isoc_ctl.pktsize;
300 }
301
302 cpysize = (endp-(*ptr) > size) ? size : endp - *ptr;
303
304 if (cpysize) {
305 /* handles each different URB message */
306 switch(cmd) {
307 case TM6000_URB_MSG_VIDEO:
308 /* Fills video buffer */
309 memcpy(&out_p[pos], *ptr, cpysize);
310 break;
311 case TM6000_URB_MSG_PTS:
312 break;
313 case TM6000_URB_MSG_AUDIO:
314 /* Need some code to process audio */
315 printk ("%ld: cmd=%s, size=%d\n", jiffies,
316 tm6000_msg_type[cmd],size);
317 break;
318 case TM6000_URB_MSG_VBI:
319 break;
320 default:
321 dprintk (dev, V4L2_DEBUG_ISOC, "cmd=%s, size=%d\n",
322 tm6000_msg_type[cmd],size);
323 }
324 }
325 if (cpysize<size) {
326 /* End of URB packet, but cmd processing is not
327 * complete. Preserve the state for a next packet
328 */
329 dev->isoc_ctl.pos = pos+cpysize;
330 dev->isoc_ctl.size= size-cpysize;
331 dev->isoc_ctl.cmd = cmd;
332 dev->isoc_ctl.pktsize = pktsize-cpysize;
333 (*ptr)+=cpysize;
334 } else {
335 dev->isoc_ctl.cmd = 0;
336 (*ptr)+=pktsize;
337 }
338
339 return rc;
340}
341
342static int copy_streams(u8 *data, unsigned long len, 188static int copy_streams(u8 *data, unsigned long len,
343 struct urb *urb) 189 struct urb *urb)
344{ 190{
345 struct tm6000_dmaqueue *dma_q = urb->context; 191 struct tm6000_dmaqueue *dma_q = urb->context;
346 struct tm6000_core *dev= container_of(dma_q,struct tm6000_core,vidq); 192 struct tm6000_core *dev= container_of(dma_q,struct tm6000_core,vidq);
347 u8 *ptr=data, *endp=data+len; 193 u8 *ptr=data, *endp=data+len, c;
348 unsigned long header=0; 194 unsigned long header=0;
349 int rc=0; 195 int rc=0;
350 struct tm6000_buffer *buf; 196 unsigned int cmd, cpysize, pktsize, size, field, block, line, pos = 0;
351 char *outp = NULL; 197 struct tm6000_buffer *vbuf;
352 198 char *voutp = NULL;
353 get_next_buf(dma_q, &buf); 199 unsigned int linewidth;
354 if (buf)
355 outp = videobuf_to_vmalloc(&buf->vb);
356 200
357 if (!outp) 201 /* get video buffer */
202 get_next_buf (dma_q, &vbuf);
203 if (!vbuf)
204 return rc;
205 voutp = videobuf_to_vmalloc(&vbuf->vb);
206 if (!voutp)
358 return 0; 207 return 0;
359 208
360 for (ptr=data; ptr<endp;) { 209 for (ptr = data; ptr < endp;) {
361 if (!dev->isoc_ctl.cmd) { 210 if (!dev->isoc_ctl.cmd) {
362 u8 *p=(u8 *)&dev->isoc_ctl.tmp_buf; 211 /* Header */
363 /* FIXME: This seems very complex 212 if (dev->isoc_ctl.tmp_buf_len > 0) {
364 * It just recovers up to 3 bytes of the header that 213 /* from last urb or packet */
365 * might be at the previous packet 214 header = dev->isoc_ctl.tmp_buf;
366 */ 215 if (4 - dev->isoc_ctl.tmp_buf_len > 0) {
367 if (dev->isoc_ctl.tmp_buf_len) { 216 memcpy ((u8 *)&header +
368 while (dev->isoc_ctl.tmp_buf_len) {
369 if ( *(ptr+3-dev->isoc_ctl.tmp_buf_len) == 0x47) {
370 break;
371 }
372 p++;
373 dev->isoc_ctl.tmp_buf_len--;
374 }
375 if (dev->isoc_ctl.tmp_buf_len) {
376 memcpy(&header, p,
377 dev->isoc_ctl.tmp_buf_len);
378 memcpy((u8 *)&header +
379 dev->isoc_ctl.tmp_buf_len, 217 dev->isoc_ctl.tmp_buf_len,
380 ptr, 218 ptr,
381 4 - dev->isoc_ctl.tmp_buf_len); 219 4 - dev->isoc_ctl.tmp_buf_len);
382 ptr += 4 - dev->isoc_ctl.tmp_buf_len; 220 ptr += 4 - dev->isoc_ctl.tmp_buf_len;
383 goto HEADER;
384 } 221 }
385 } 222 dev->isoc_ctl.tmp_buf_len = 0;
386 /* Seek for sync */ 223 } else {
387 for (;ptr<endp-3;ptr++) { 224 if (ptr + 3 >= endp) {
388 if (*(ptr+3)==0x47) 225 /* have incomplete header */
389 break; 226 dev->isoc_ctl.tmp_buf_len = endp - ptr;
227 memcpy (&dev->isoc_ctl.tmp_buf, ptr,
228 dev->isoc_ctl.tmp_buf_len);
229 return rc;
230 }
231 /* Seek for sync */
232 for (; ptr < endp - 3; ptr++) {
233 if (*(ptr + 3) == 0x47)
234 break;
235 }
236 /* Get message header */
237 header = *(unsigned long *)ptr;
238 ptr += 4;
390 } 239 }
391 240
392 if (ptr+3>=endp) { 241 /* split the header fields */
393 dev->isoc_ctl.tmp_buf_len=endp-ptr; 242 c = (header >> 24) & 0xff;
394 memcpy (&dev->isoc_ctl.tmp_buf,ptr, 243 size = ((header & 0x7e) << 1);
395 dev->isoc_ctl.tmp_buf_len); 244 if (size > 0)
396 dev->isoc_ctl.cmd=0; 245 size -= 4;
397 return rc; 246 block = (header >> 7) & 0xf;
247 field = (header >> 11) & 0x1;
248 line = (header >> 12) & 0x1ff;
249 cmd = (header >> 21) & 0x7;
250 /* Validates haeder fields */
251 if (size > TM6000_URB_MSG_LEN)
252 size = TM6000_URB_MSG_LEN;
253 pktsize = TM6000_URB_MSG_LEN;
254 /* calculate position in buffer
255 * and change the buffer
256 */
257 switch (cmd) {
258 case TM6000_URB_MSG_VIDEO:
259 if ((dev->isoc_ctl.vfield != field) &&
260 (field == 1)) {
261 /* Announces that a new buffer
262 * were filled
263 */
264 buffer_filled (dev, dma_q, vbuf);
265 dprintk (dev, V4L2_DEBUG_ISOC,
266 "new buffer filled\n");
267 get_next_buf (dma_q, &vbuf);
268 if (!vbuf)
269 return rc;
270 voutp = videobuf_to_vmalloc (&vbuf->vb);
271 if (!voutp)
272 return rc;
273 memset(voutp, 0, vbuf->vb.size);
274 }
275 linewidth = vbuf->vb.width << 1;
276 pos = ((line << 1) - field - 1) * linewidth +
277 block * TM6000_URB_MSG_LEN;
278 /* Don't allow to write out of the buffer */
279 if (pos + size > vbuf->vb.size)
280 cmd = TM6000_URB_MSG_ERR;
281 dev->isoc_ctl.vfield = field;
282 break;
283 case TM6000_URB_MSG_VBI:
284 break;
285 case TM6000_URB_MSG_AUDIO:
286 case TM6000_URB_MSG_PTS:
287 size = pktsize; /* Size is always 180 bytes */
288 break;
398 } 289 }
399 290 } else {
400 /* Get message header */ 291 /* Continue the last copy */
401 header=*(unsigned long *)ptr; 292 cmd = dev->isoc_ctl.cmd;
402 ptr+=4; 293 size = dev->isoc_ctl.size;
294 pos = dev->isoc_ctl.pos;
295 pktsize = dev->isoc_ctl.pktsize;
403 } 296 }
404HEADER: 297 cpysize = (endp - ptr > size) ? size : endp - ptr;
405 /* Copy or continue last copy */ 298 if (cpysize) {
406 rc=copy_packet(urb,header,&ptr,endp,outp,&buf); 299 /* copy data in different buffers */
407 if (rc<0) { 300 switch (cmd) {
408 buf=NULL; 301 case TM6000_URB_MSG_VIDEO:
409 printk(KERN_ERR "tm6000: buffer underrun at %ld\n", 302 /* Fills video buffer */
410 jiffies); 303 if (vbuf)
411 return rc; 304 memcpy (&voutp[pos], ptr, cpysize);
305 break;
306 case TM6000_URB_MSG_AUDIO:
307 tm6000_call_fillbuf(dev, TM6000_AUDIO, ptr, cpysize);
308 break;
309 case TM6000_URB_MSG_VBI:
310 /* Need some code to copy vbi buffer */
311 break;
312 case TM6000_URB_MSG_PTS:
313 /* Need some code to copy pts */
314 break;
315 }
316 }
317 if (ptr + pktsize > endp) {
318 /* End of URB packet, but cmd processing is not
319 * complete. Preserve the state for a next packet
320 */
321 dev->isoc_ctl.pos = pos + cpysize;
322 dev->isoc_ctl.size = size - cpysize;
323 dev->isoc_ctl.cmd = cmd;
324 dev->isoc_ctl.pktsize = pktsize - (endp - ptr);
325 ptr += endp - ptr;
326 } else {
327 dev->isoc_ctl.cmd = 0;
328 ptr += pktsize;
412 } 329 }
413 if (!buf)
414 return 0;
415 } 330 }
416
417 return 0; 331 return 0;
418} 332}
333
419/* 334/*
420 * Identify the tm5600/6000 buffer header type and properly handles 335 * Identify the tm5600/6000 buffer header type and properly handles
421 */ 336 */
@@ -510,7 +425,6 @@ static inline int tm6000_isoc_copy(struct urb *urb)
510{ 425{
511 struct tm6000_dmaqueue *dma_q = urb->context; 426 struct tm6000_dmaqueue *dma_q = urb->context;
512 struct tm6000_core *dev= container_of(dma_q,struct tm6000_core,vidq); 427 struct tm6000_core *dev= container_of(dma_q,struct tm6000_core,vidq);
513 struct tm6000_buffer *buf;
514 int i, len=0, rc=1, status; 428 int i, len=0, rc=1, status;
515 char *p; 429 char *p;
516 430
@@ -585,7 +499,6 @@ static void tm6000_uninit_isoc(struct tm6000_core *dev)
585 struct urb *urb; 499 struct urb *urb;
586 int i; 500 int i;
587 501
588 dev->isoc_ctl.nfields = -1;
589 dev->isoc_ctl.buf = NULL; 502 dev->isoc_ctl.buf = NULL;
590 for (i = 0; i < dev->isoc_ctl.num_bufs; i++) { 503 for (i = 0; i < dev->isoc_ctl.num_bufs; i++) {
591 urb=dev->isoc_ctl.urb[i]; 504 urb=dev->isoc_ctl.urb[i];
@@ -610,8 +523,6 @@ static void tm6000_uninit_isoc(struct tm6000_core *dev)
610 dev->isoc_ctl.urb=NULL; 523 dev->isoc_ctl.urb=NULL;
611 dev->isoc_ctl.transfer_buffer=NULL; 524 dev->isoc_ctl.transfer_buffer=NULL;
612 dev->isoc_ctl.num_bufs = 0; 525 dev->isoc_ctl.num_bufs = 0;
613
614 dev->isoc_ctl.num_bufs=0;
615} 526}
616 527
617/* 528/*
diff --git a/drivers/staging/tm6000/tm6000.h b/drivers/staging/tm6000/tm6000.h
index 7bbaf26dea14..1ec1bff9b294 100644
--- a/drivers/staging/tm6000/tm6000.h
+++ b/drivers/staging/tm6000/tm6000.h
@@ -20,8 +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// Use the tm6000-hack, instead of the proper initialization code 23/* Use the tm6000-hack, instead of the proper initialization code i*/
24//#define HACK 1 24/* #define HACK 1 */
25 25
26#include <linux/videodev2.h> 26#include <linux/videodev2.h>
27#include <media/v4l2-common.h> 27#include <media/v4l2-common.h>
@@ -98,7 +98,7 @@ enum tm6000_io_method {
98}; 98};
99 99
100enum tm6000_mode { 100enum tm6000_mode {
101 TM6000_MODE_UNKNOWN=0, 101 TM6000_MODE_UNKNOWN = 0,
102 TM6000_MODE_ANALOG, 102 TM6000_MODE_ANALOG,
103 TM6000_MODE_DIGITAL, 103 TM6000_MODE_DIGITAL,
104}; 104};
@@ -128,10 +128,21 @@ struct tm6000_dvb {
128 struct dvb_frontend *frontend; 128 struct dvb_frontend *frontend;
129 struct dmxdev dmxdev; 129 struct dmxdev dmxdev;
130 unsigned int streams; 130 unsigned int streams;
131 struct urb *bulk_urb; 131 struct urb *bulk_urb;
132 struct mutex mutex; 132 struct mutex mutex;
133}; 133};
134 134
135struct snd_tm6000_card {
136 struct snd_card *card;
137 spinlock_t reg_lock;
138 struct tm6000_core *core;
139 struct snd_pcm_substream *substream;
140
141 /* temporary data for buffer fill processing */
142 unsigned buf_pos;
143 unsigned period_pos;
144};
145
135struct tm6000_endpoint { 146struct tm6000_endpoint {
136 struct usb_host_endpoint *endp; 147 struct usb_host_endpoint *endp;
137 __u8 bInterfaceNumber; 148 __u8 bInterfaceNumber;
@@ -147,7 +158,7 @@ struct tm6000_core {
147 enum tm6000_devtype dev_type; /* type of device */ 158 enum tm6000_devtype dev_type; /* type of device */
148 159
149 v4l2_std_id norm; /* Current norm */ 160 v4l2_std_id norm; /* Current norm */
150 int width,height; /* Selected resolution */ 161 int width, height; /* Selected resolution */
151 162
152 enum tm6000_core_state state; 163 enum tm6000_core_state state;
153 164
@@ -160,6 +171,8 @@ struct tm6000_core {
160 171
161 struct tm6000_gpio gpio; 172 struct tm6000_gpio gpio;
162 173
174 char *ir_codes;
175
163 /* Demodulator configuration */ 176 /* Demodulator configuration */
164 int demod_addr; /* demodulator address */ 177 int demod_addr; /* demodulator address */
165 178
@@ -190,6 +203,11 @@ struct tm6000_core {
190 /* DVB-T support */ 203 /* DVB-T support */
191 struct tm6000_dvb *dvb; 204 struct tm6000_dvb *dvb;
192 205
206 /* audio support */
207 struct snd_tm6000_card *adev;
208
209 struct tm6000_IR *ir;
210
193 /* locks */ 211 /* locks */
194 struct mutex lock; 212 struct mutex lock;
195 213
@@ -197,6 +215,7 @@ struct tm6000_core {
197 struct usb_device *udev; /* the usb device */ 215 struct usb_device *udev; /* the usb device */
198 216
199 struct tm6000_endpoint bulk_in, bulk_out, isoc_in, isoc_out; 217 struct tm6000_endpoint bulk_in, bulk_out, isoc_in, isoc_out;
218 struct tm6000_endpoint int_in, int_out;
200 219
201 /* scaler!=0 if scaler is active*/ 220 /* scaler!=0 if scaler is active*/
202 int scaler; 221 int scaler;
@@ -207,14 +226,18 @@ struct tm6000_core {
207 spinlock_t slock; 226 spinlock_t slock;
208}; 227};
209 228
210#define TM6000_AUDIO 0x10 229enum tm6000_ops_type {
230 TM6000_AUDIO = 0x10,
231 TM6000_DVB = 0x20,
232};
211 233
212struct tm6000_ops { 234struct tm6000_ops {
213 struct list_head next; 235 struct list_head next;
214 char *name; 236 char *name;
215 int id; 237 enum tm6000_ops_type type;
216 int (*init)(struct tm6000_core *); 238 int (*init)(struct tm6000_core *);
217 int (*fini)(struct tm6000_core *); 239 int (*fini)(struct tm6000_core *);
240 int (*fillbuf)(struct tm6000_core *, char *buf, int size);
218}; 241};
219 242
220struct tm6000_fh { 243struct tm6000_fh {
@@ -222,7 +245,7 @@ struct tm6000_fh {
222 245
223 /* video capture */ 246 /* video capture */
224 struct tm6000_fmt *fmt; 247 struct tm6000_fmt *fmt;
225 unsigned int width,height; 248 unsigned int width, height;
226 struct videobuf_queue vb_vidq; 249 struct videobuf_queue vb_vidq;
227 250
228 enum v4l2_buf_type type; 251 enum v4l2_buf_type type;
@@ -234,28 +257,24 @@ struct tm6000_fh {
234 257
235/* In tm6000-cards.c */ 258/* In tm6000-cards.c */
236 259
237int tm6000_tuner_callback (void *ptr, int component, int command, int arg); 260int tm6000_tuner_callback(void *ptr, int component, int command, int arg);
238int tm6000_xc5000_callback (void *ptr, int component, int command, int arg); 261int tm6000_xc5000_callback(void *ptr, int component, int command, int arg);
239int tm6000_cards_setup(struct tm6000_core *dev); 262int tm6000_cards_setup(struct tm6000_core *dev);
240 263
241/* In tm6000-core.c */ 264/* In tm6000-core.c */
242 265
243int tm6000_read_write_usb (struct tm6000_core *dev, u8 reqtype, u8 req, 266int tm6000_read_write_usb(struct tm6000_core *dev, u8 reqtype, u8 req,
244 u16 value, u16 index, u8 *buf, u16 len); 267 u16 value, u16 index, u8 *buf, u16 len);
245int tm6000_get_reg (struct tm6000_core *dev, u8 req, u16 value, u16 index); 268int tm6000_get_reg(struct tm6000_core *dev, u8 req, u16 value, u16 index);
246int tm6000_get_reg16(struct tm6000_core *dev, u8 req, u16 value, u16 index); 269int tm6000_get_reg16(struct tm6000_core *dev, u8 req, u16 value, u16 index);
247int tm6000_get_reg32(struct tm6000_core *dev, u8 req, u16 value, u16 index); 270int tm6000_get_reg32(struct tm6000_core *dev, u8 req, u16 value, u16 index);
248int tm6000_set_reg (struct tm6000_core *dev, u8 req, u16 value, u16 index); 271int tm6000_set_reg(struct tm6000_core *dev, u8 req, u16 value, u16 index);
249int tm6000_i2c_reset(struct tm6000_core *dev, u16 tsleep); 272int tm6000_i2c_reset(struct tm6000_core *dev, u16 tsleep);
273int tm6000_init(struct tm6000_core *dev);
250 274
251int tm6000_init (struct tm6000_core *dev); 275int tm6000_init_analog_mode(struct tm6000_core *dev);
252 276int tm6000_init_digital_mode(struct tm6000_core *dev);
253int tm6000_init_analog_mode (struct tm6000_core *dev); 277int tm6000_set_audio_bitrate(struct tm6000_core *dev, int bitrate);
254int tm6000_init_digital_mode (struct tm6000_core *dev);
255int tm6000_set_audio_bitrate (struct tm6000_core *dev, int bitrate);
256
257int tm6000_dvb_register(struct tm6000_core *dev);
258void tm6000_dvb_unregister(struct tm6000_core *dev);
259 278
260int tm6000_v4l2_register(struct tm6000_core *dev); 279int tm6000_v4l2_register(struct tm6000_core *dev);
261int tm6000_v4l2_unregister(struct tm6000_core *dev); 280int tm6000_v4l2_unregister(struct tm6000_core *dev);
@@ -268,10 +287,13 @@ int tm6000_register_extension(struct tm6000_ops *ops);
268void tm6000_unregister_extension(struct tm6000_ops *ops); 287void tm6000_unregister_extension(struct tm6000_ops *ops);
269void tm6000_init_extension(struct tm6000_core *dev); 288void tm6000_init_extension(struct tm6000_core *dev);
270void tm6000_close_extension(struct tm6000_core *dev); 289void tm6000_close_extension(struct tm6000_core *dev);
290int tm6000_call_fillbuf(struct tm6000_core *dev, enum tm6000_ops_type type,
291 char *buf, int size);
292
271 293
272/* In tm6000-stds.c */ 294/* In tm6000-stds.c */
273void tm6000_get_std_res(struct tm6000_core *dev); 295void tm6000_get_std_res(struct tm6000_core *dev);
274int tm6000_set_standard (struct tm6000_core *dev, v4l2_std_id *norm); 296int tm6000_set_standard(struct tm6000_core *dev, v4l2_std_id *norm);
275 297
276/* In tm6000-i2c.c */ 298/* In tm6000-i2c.c */
277int tm6000_i2c_register(struct tm6000_core *dev); 299int tm6000_i2c_register(struct tm6000_core *dev);
@@ -285,14 +307,14 @@ int tm6000_vidioc_streamon(struct file *file, void *priv,
285 enum v4l2_buf_type i); 307 enum v4l2_buf_type i);
286int tm6000_vidioc_streamoff(struct file *file, void *priv, 308int tm6000_vidioc_streamoff(struct file *file, void *priv,
287 enum v4l2_buf_type i); 309 enum v4l2_buf_type i);
288int tm6000_vidioc_reqbufs (struct file *file, void *priv, 310int tm6000_vidioc_reqbufs(struct file *file, void *priv,
289 struct v4l2_requestbuffers *rb); 311 struct v4l2_requestbuffers *rb);
290int tm6000_vidioc_querybuf (struct file *file, void *priv, 312int tm6000_vidioc_querybuf(struct file *file, void *priv,
291 struct v4l2_buffer *b); 313 struct v4l2_buffer *b);
292int tm6000_vidioc_qbuf (struct file *file, void *priv, struct v4l2_buffer *b); 314int tm6000_vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *b);
293int tm6000_vidioc_dqbuf (struct file *file, void *priv, struct v4l2_buffer *b); 315int tm6000_vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b);
294ssize_t tm6000_v4l2_read(struct file *filp, char __user * buf, size_t count, 316ssize_t tm6000_v4l2_read(struct file *filp, char __user * buf, size_t count,
295 loff_t * f_pos); 317 loff_t *f_pos);
296unsigned int tm6000_v4l2_poll(struct file *file, 318unsigned int tm6000_v4l2_poll(struct file *file,
297 struct poll_table_struct *wait); 319 struct poll_table_struct *wait);
298int tm6000_queue_init(struct tm6000_core *dev); 320int tm6000_queue_init(struct tm6000_core *dev);
@@ -300,6 +322,10 @@ int tm6000_queue_init(struct tm6000_core *dev);
300/* In tm6000-alsa.c */ 322/* In tm6000-alsa.c */
301/*int tm6000_audio_init(struct tm6000_core *dev, int idx);*/ 323/*int tm6000_audio_init(struct tm6000_core *dev, int idx);*/
302 324
325/* In tm6000-input.c */
326int tm6000_ir_init(struct tm6000_core *dev);
327int tm6000_ir_fini(struct tm6000_core *dev);
328void tm6000_ir_wait(struct tm6000_core *dev, u8 state);
303 329
304/* Debug stuff */ 330/* Debug stuff */
305 331
@@ -307,7 +333,7 @@ extern int tm6000_debug;
307 333
308#define dprintk(dev, level, fmt, arg...) do {\ 334#define dprintk(dev, level, fmt, arg...) do {\
309 if (tm6000_debug & level) \ 335 if (tm6000_debug & level) \
310 printk(KERN_INFO "(%lu) %s %s :"fmt, jiffies, \ 336 printk(KERN_INFO "(%lu) %s %s :"fmt, jiffies, \
311 dev->name, __FUNCTION__ , ##arg); } while (0) 337 dev->name, __FUNCTION__ , ##arg); } while (0)
312 338
313#define V4L2_DEBUG_REG 0x0004 339#define V4L2_DEBUG_REG 0x0004
@@ -320,5 +346,3 @@ extern int tm6000_debug;
320#define tm6000_err(fmt, arg...) do {\ 346#define tm6000_err(fmt, arg...) do {\
321 printk(KERN_ERR "tm6000 %s :"fmt, \ 347 printk(KERN_ERR "tm6000 %s :"fmt, \
322 __FUNCTION__ , ##arg); } while (0) 348 __FUNCTION__ , ##arg); } while (0)
323
324
diff --git a/drivers/usb/gadget/f_uvc.c b/drivers/usb/gadget/f_uvc.c
index dbe6db0184fd..be446b7e7eaa 100644
--- a/drivers/usb/gadget/f_uvc.c
+++ b/drivers/usb/gadget/f_uvc.c
@@ -61,12 +61,12 @@ static struct usb_gadget_strings *uvc_function_strings[] = {
61#define UVC_INTF_VIDEO_STREAMING 1 61#define UVC_INTF_VIDEO_STREAMING 1
62 62
63static struct usb_interface_assoc_descriptor uvc_iad __initdata = { 63static struct usb_interface_assoc_descriptor uvc_iad __initdata = {
64 .bLength = USB_DT_INTERFACE_ASSOCIATION_SIZE, 64 .bLength = sizeof(uvc_iad),
65 .bDescriptorType = USB_DT_INTERFACE_ASSOCIATION, 65 .bDescriptorType = USB_DT_INTERFACE_ASSOCIATION,
66 .bFirstInterface = 0, 66 .bFirstInterface = 0,
67 .bInterfaceCount = 2, 67 .bInterfaceCount = 2,
68 .bFunctionClass = USB_CLASS_VIDEO, 68 .bFunctionClass = USB_CLASS_VIDEO,
69 .bFunctionSubClass = 0x03, 69 .bFunctionSubClass = UVC_SC_VIDEO_INTERFACE_COLLECTION,
70 .bFunctionProtocol = 0x00, 70 .bFunctionProtocol = 0x00,
71 .iFunction = 0, 71 .iFunction = 0,
72}; 72};
@@ -78,7 +78,7 @@ static struct usb_interface_descriptor uvc_control_intf __initdata = {
78 .bAlternateSetting = 0, 78 .bAlternateSetting = 0,
79 .bNumEndpoints = 1, 79 .bNumEndpoints = 1,
80 .bInterfaceClass = USB_CLASS_VIDEO, 80 .bInterfaceClass = USB_CLASS_VIDEO,
81 .bInterfaceSubClass = 0x01, 81 .bInterfaceSubClass = UVC_SC_VIDEOCONTROL,
82 .bInterfaceProtocol = 0x00, 82 .bInterfaceProtocol = 0x00,
83 .iInterface = 0, 83 .iInterface = 0,
84}; 84};
@@ -106,7 +106,7 @@ static struct usb_interface_descriptor uvc_streaming_intf_alt0 __initdata = {
106 .bAlternateSetting = 0, 106 .bAlternateSetting = 0,
107 .bNumEndpoints = 0, 107 .bNumEndpoints = 0,
108 .bInterfaceClass = USB_CLASS_VIDEO, 108 .bInterfaceClass = USB_CLASS_VIDEO,
109 .bInterfaceSubClass = 0x02, 109 .bInterfaceSubClass = UVC_SC_VIDEOSTREAMING,
110 .bInterfaceProtocol = 0x00, 110 .bInterfaceProtocol = 0x00,
111 .iInterface = 0, 111 .iInterface = 0,
112}; 112};
@@ -118,7 +118,7 @@ static struct usb_interface_descriptor uvc_streaming_intf_alt1 __initdata = {
118 .bAlternateSetting = 1, 118 .bAlternateSetting = 1,
119 .bNumEndpoints = 1, 119 .bNumEndpoints = 1,
120 .bInterfaceClass = USB_CLASS_VIDEO, 120 .bInterfaceClass = USB_CLASS_VIDEO,
121 .bInterfaceSubClass = 0x02, 121 .bInterfaceSubClass = UVC_SC_VIDEOSTREAMING,
122 .bInterfaceProtocol = 0x00, 122 .bInterfaceProtocol = 0x00,
123 .iInterface = 0, 123 .iInterface = 0,
124}; 124};
@@ -603,15 +603,15 @@ uvc_bind_config(struct usb_configuration *c,
603 603
604 /* Validate the descriptors. */ 604 /* Validate the descriptors. */
605 if (control == NULL || control[0] == NULL || 605 if (control == NULL || control[0] == NULL ||
606 control[0]->bDescriptorSubType != UVC_DT_HEADER) 606 control[0]->bDescriptorSubType != UVC_VC_HEADER)
607 goto error; 607 goto error;
608 608
609 if (fs_streaming == NULL || fs_streaming[0] == NULL || 609 if (fs_streaming == NULL || fs_streaming[0] == NULL ||
610 fs_streaming[0]->bDescriptorSubType != UVC_DT_INPUT_HEADER) 610 fs_streaming[0]->bDescriptorSubType != UVC_VS_INPUT_HEADER)
611 goto error; 611 goto error;
612 612
613 if (hs_streaming == NULL || hs_streaming[0] == NULL || 613 if (hs_streaming == NULL || hs_streaming[0] == NULL ||
614 hs_streaming[0]->bDescriptorSubType != UVC_DT_INPUT_HEADER) 614 hs_streaming[0]->bDescriptorSubType != UVC_VS_INPUT_HEADER)
615 goto error; 615 goto error;
616 616
617 uvc->desc.control = control; 617 uvc->desc.control = control;
diff --git a/drivers/usb/gadget/f_uvc.h b/drivers/usb/gadget/f_uvc.h
index 8a5db7c4fe7c..e18a6636c283 100644
--- a/drivers/usb/gadget/f_uvc.h
+++ b/drivers/usb/gadget/f_uvc.h
@@ -15,357 +15,7 @@
15#define _F_UVC_H_ 15#define _F_UVC_H_
16 16
17#include <linux/usb/composite.h> 17#include <linux/usb/composite.h>
18 18#include <linux/usb/video.h>
19#define USB_CLASS_VIDEO_CONTROL 1
20#define USB_CLASS_VIDEO_STREAMING 2
21
22struct uvc_descriptor_header {
23 __u8 bLength;
24 __u8 bDescriptorType;
25 __u8 bDescriptorSubType;
26} __attribute__ ((packed));
27
28struct uvc_header_descriptor {
29 __u8 bLength;
30 __u8 bDescriptorType;
31 __u8 bDescriptorSubType;
32 __u16 bcdUVC;
33 __u16 wTotalLength;
34 __u32 dwClockFrequency;
35 __u8 bInCollection;
36 __u8 baInterfaceNr[];
37} __attribute__((__packed__));
38
39#define UVC_HEADER_DESCRIPTOR(n) uvc_header_descriptor_##n
40
41#define DECLARE_UVC_HEADER_DESCRIPTOR(n) \
42struct UVC_HEADER_DESCRIPTOR(n) { \
43 __u8 bLength; \
44 __u8 bDescriptorType; \
45 __u8 bDescriptorSubType; \
46 __u16 bcdUVC; \
47 __u16 wTotalLength; \
48 __u32 dwClockFrequency; \
49 __u8 bInCollection; \
50 __u8 baInterfaceNr[n]; \
51} __attribute__ ((packed))
52
53struct uvc_input_terminal_descriptor {
54 __u8 bLength;
55 __u8 bDescriptorType;
56 __u8 bDescriptorSubType;
57 __u8 bTerminalID;
58 __u16 wTerminalType;
59 __u8 bAssocTerminal;
60 __u8 iTerminal;
61} __attribute__((__packed__));
62
63struct uvc_output_terminal_descriptor {
64 __u8 bLength;
65 __u8 bDescriptorType;
66 __u8 bDescriptorSubType;
67 __u8 bTerminalID;
68 __u16 wTerminalType;
69 __u8 bAssocTerminal;
70 __u8 bSourceID;
71 __u8 iTerminal;
72} __attribute__((__packed__));
73
74struct uvc_camera_terminal_descriptor {
75 __u8 bLength;
76 __u8 bDescriptorType;
77 __u8 bDescriptorSubType;
78 __u8 bTerminalID;
79 __u16 wTerminalType;
80 __u8 bAssocTerminal;
81 __u8 iTerminal;
82 __u16 wObjectiveFocalLengthMin;
83 __u16 wObjectiveFocalLengthMax;
84 __u16 wOcularFocalLength;
85 __u8 bControlSize;
86 __u8 bmControls[3];
87} __attribute__((__packed__));
88
89struct uvc_selector_unit_descriptor {
90 __u8 bLength;
91 __u8 bDescriptorType;
92 __u8 bDescriptorSubType;
93 __u8 bUnitID;
94 __u8 bNrInPins;
95 __u8 baSourceID[0];
96 __u8 iSelector;
97} __attribute__((__packed__));
98
99#define UVC_SELECTOR_UNIT_DESCRIPTOR(n) \
100 uvc_selector_unit_descriptor_##n
101
102#define DECLARE_UVC_SELECTOR_UNIT_DESCRIPTOR(n) \
103struct UVC_SELECTOR_UNIT_DESCRIPTOR(n) { \
104 __u8 bLength; \
105 __u8 bDescriptorType; \
106 __u8 bDescriptorSubType; \
107 __u8 bUnitID; \
108 __u8 bNrInPins; \
109 __u8 baSourceID[n]; \
110 __u8 iSelector; \
111} __attribute__ ((packed))
112
113struct uvc_processing_unit_descriptor {
114 __u8 bLength;
115 __u8 bDescriptorType;
116 __u8 bDescriptorSubType;
117 __u8 bUnitID;
118 __u8 bSourceID;
119 __u16 wMaxMultiplier;
120 __u8 bControlSize;
121 __u8 bmControls[2];
122 __u8 iProcessing;
123} __attribute__((__packed__));
124
125struct uvc_extension_unit_descriptor {
126 __u8 bLength;
127 __u8 bDescriptorType;
128 __u8 bDescriptorSubType;
129 __u8 bUnitID;
130 __u8 guidExtensionCode[16];
131 __u8 bNumControls;
132 __u8 bNrInPins;
133 __u8 baSourceID[0];
134 __u8 bControlSize;
135 __u8 bmControls[0];
136 __u8 iExtension;
137} __attribute__((__packed__));
138
139#define UVC_EXTENSION_UNIT_DESCRIPTOR(p, n) \
140 uvc_extension_unit_descriptor_##p_##n
141
142#define DECLARE_UVC_EXTENSION_UNIT_DESCRIPTOR(p, n) \
143struct UVC_EXTENSION_UNIT_DESCRIPTOR(p, n) { \
144 __u8 bLength; \
145 __u8 bDescriptorType; \
146 __u8 bDescriptorSubType; \
147 __u8 bUnitID; \
148 __u8 guidExtensionCode[16]; \
149 __u8 bNumControls; \
150 __u8 bNrInPins; \
151 __u8 baSourceID[p]; \
152 __u8 bControlSize; \
153 __u8 bmControls[n]; \
154 __u8 iExtension; \
155} __attribute__ ((packed))
156
157struct uvc_control_endpoint_descriptor {
158 __u8 bLength;
159 __u8 bDescriptorType;
160 __u8 bDescriptorSubType;
161 __u16 wMaxTransferSize;
162} __attribute__((__packed__));
163
164#define UVC_DT_HEADER 1
165#define UVC_DT_INPUT_TERMINAL 2
166#define UVC_DT_OUTPUT_TERMINAL 3
167#define UVC_DT_SELECTOR_UNIT 4
168#define UVC_DT_PROCESSING_UNIT 5
169#define UVC_DT_EXTENSION_UNIT 6
170
171#define UVC_DT_HEADER_SIZE(n) (12+(n))
172#define UVC_DT_INPUT_TERMINAL_SIZE 8
173#define UVC_DT_OUTPUT_TERMINAL_SIZE 9
174#define UVC_DT_CAMERA_TERMINAL_SIZE(n) (15+(n))
175#define UVC_DT_SELECTOR_UNIT_SIZE(n) (6+(n))
176#define UVC_DT_PROCESSING_UNIT_SIZE(n) (9+(n))
177#define UVC_DT_EXTENSION_UNIT_SIZE(p,n) (24+(p)+(n))
178#define UVC_DT_CONTROL_ENDPOINT_SIZE 5
179
180struct uvc_input_header_descriptor {
181 __u8 bLength;
182 __u8 bDescriptorType;
183 __u8 bDescriptorSubType;
184 __u8 bNumFormats;
185 __u16 wTotalLength;
186 __u8 bEndpointAddress;
187 __u8 bmInfo;
188 __u8 bTerminalLink;
189 __u8 bStillCaptureMethod;
190 __u8 bTriggerSupport;
191 __u8 bTriggerUsage;
192 __u8 bControlSize;
193 __u8 bmaControls[];
194} __attribute__((__packed__));
195
196#define UVC_INPUT_HEADER_DESCRIPTOR(n, p) \
197 uvc_input_header_descriptor_##n_##p
198
199#define DECLARE_UVC_INPUT_HEADER_DESCRIPTOR(n, p) \
200struct UVC_INPUT_HEADER_DESCRIPTOR(n, p) { \
201 __u8 bLength; \
202 __u8 bDescriptorType; \
203 __u8 bDescriptorSubType; \
204 __u8 bNumFormats; \
205 __u16 wTotalLength; \
206 __u8 bEndpointAddress; \
207 __u8 bmInfo; \
208 __u8 bTerminalLink; \
209 __u8 bStillCaptureMethod; \
210 __u8 bTriggerSupport; \
211 __u8 bTriggerUsage; \
212 __u8 bControlSize; \
213 __u8 bmaControls[p][n]; \
214} __attribute__ ((packed))
215
216struct uvc_output_header_descriptor {
217 __u8 bLength;
218 __u8 bDescriptorType;
219 __u8 bDescriptorSubType;
220 __u8 bNumFormats;
221 __u16 wTotalLength;
222 __u8 bEndpointAddress;
223 __u8 bTerminalLink;
224 __u8 bControlSize;
225 __u8 bmaControls[];
226} __attribute__((__packed__));
227
228#define UVC_OUTPUT_HEADER_DESCRIPTOR(n, p) \
229 uvc_output_header_descriptor_##n_##p
230
231#define DECLARE_UVC_OUTPUT_HEADER_DESCRIPTOR(n, p) \
232struct UVC_OUTPUT_HEADER_DESCRIPTOR(n, p) { \
233 __u8 bLength; \
234 __u8 bDescriptorType; \
235 __u8 bDescriptorSubType; \
236 __u8 bNumFormats; \
237 __u16 wTotalLength; \
238 __u8 bEndpointAddress; \
239 __u8 bTerminalLink; \
240 __u8 bControlSize; \
241 __u8 bmaControls[p][n]; \
242} __attribute__ ((packed))
243
244struct uvc_format_uncompressed {
245 __u8 bLength;
246 __u8 bDescriptorType;
247 __u8 bDescriptorSubType;
248 __u8 bFormatIndex;
249 __u8 bNumFrameDescriptors;
250 __u8 guidFormat[16];
251 __u8 bBitsPerPixel;
252 __u8 bDefaultFrameIndex;
253 __u8 bAspectRatioX;
254 __u8 bAspectRatioY;
255 __u8 bmInterfaceFlags;
256 __u8 bCopyProtect;
257} __attribute__((__packed__));
258
259struct uvc_frame_uncompressed {
260 __u8 bLength;
261 __u8 bDescriptorType;
262 __u8 bDescriptorSubType;
263 __u8 bFrameIndex;
264 __u8 bmCapabilities;
265 __u16 wWidth;
266 __u16 wHeight;
267 __u32 dwMinBitRate;
268 __u32 dwMaxBitRate;
269 __u32 dwMaxVideoFrameBufferSize;
270 __u32 dwDefaultFrameInterval;
271 __u8 bFrameIntervalType;
272 __u32 dwFrameInterval[];
273} __attribute__((__packed__));
274
275#define UVC_FRAME_UNCOMPRESSED(n) \
276 uvc_frame_uncompressed_##n
277
278#define DECLARE_UVC_FRAME_UNCOMPRESSED(n) \
279struct UVC_FRAME_UNCOMPRESSED(n) { \
280 __u8 bLength; \
281 __u8 bDescriptorType; \
282 __u8 bDescriptorSubType; \
283 __u8 bFrameIndex; \
284 __u8 bmCapabilities; \
285 __u16 wWidth; \
286 __u16 wHeight; \
287 __u32 dwMinBitRate; \
288 __u32 dwMaxBitRate; \
289 __u32 dwMaxVideoFrameBufferSize; \
290 __u32 dwDefaultFrameInterval; \
291 __u8 bFrameIntervalType; \
292 __u32 dwFrameInterval[n]; \
293} __attribute__ ((packed))
294
295struct uvc_format_mjpeg {
296 __u8 bLength;
297 __u8 bDescriptorType;
298 __u8 bDescriptorSubType;
299 __u8 bFormatIndex;
300 __u8 bNumFrameDescriptors;
301 __u8 bmFlags;
302 __u8 bDefaultFrameIndex;
303 __u8 bAspectRatioX;
304 __u8 bAspectRatioY;
305 __u8 bmInterfaceFlags;
306 __u8 bCopyProtect;
307} __attribute__((__packed__));
308
309struct uvc_frame_mjpeg {
310 __u8 bLength;
311 __u8 bDescriptorType;
312 __u8 bDescriptorSubType;
313 __u8 bFrameIndex;
314 __u8 bmCapabilities;
315 __u16 wWidth;
316 __u16 wHeight;
317 __u32 dwMinBitRate;
318 __u32 dwMaxBitRate;
319 __u32 dwMaxVideoFrameBufferSize;
320 __u32 dwDefaultFrameInterval;
321 __u8 bFrameIntervalType;
322 __u32 dwFrameInterval[];
323} __attribute__((__packed__));
324
325#define UVC_FRAME_MJPEG(n) \
326 uvc_frame_mjpeg_##n
327
328#define DECLARE_UVC_FRAME_MJPEG(n) \
329struct UVC_FRAME_MJPEG(n) { \
330 __u8 bLength; \
331 __u8 bDescriptorType; \
332 __u8 bDescriptorSubType; \
333 __u8 bFrameIndex; \
334 __u8 bmCapabilities; \
335 __u16 wWidth; \
336 __u16 wHeight; \
337 __u32 dwMinBitRate; \
338 __u32 dwMaxBitRate; \
339 __u32 dwMaxVideoFrameBufferSize; \
340 __u32 dwDefaultFrameInterval; \
341 __u8 bFrameIntervalType; \
342 __u32 dwFrameInterval[n]; \
343} __attribute__ ((packed))
344
345struct uvc_color_matching_descriptor {
346 __u8 bLength;
347 __u8 bDescriptorType;
348 __u8 bDescriptorSubType;
349 __u8 bColorPrimaries;
350 __u8 bTransferCharacteristics;
351 __u8 bMatrixCoefficients;
352} __attribute__((__packed__));
353
354#define UVC_DT_INPUT_HEADER 1
355#define UVC_DT_OUTPUT_HEADER 2
356#define UVC_DT_FORMAT_UNCOMPRESSED 4
357#define UVC_DT_FRAME_UNCOMPRESSED 5
358#define UVC_DT_FORMAT_MJPEG 6
359#define UVC_DT_FRAME_MJPEG 7
360#define UVC_DT_COLOR_MATCHING 13
361
362#define UVC_DT_INPUT_HEADER_SIZE(n, p) (13+(n*p))
363#define UVC_DT_OUTPUT_HEADER_SIZE(n, p) (9+(n*p))
364#define UVC_DT_FORMAT_UNCOMPRESSED_SIZE 27
365#define UVC_DT_FRAME_UNCOMPRESSED_SIZE(n) (26+4*(n))
366#define UVC_DT_FORMAT_MJPEG_SIZE 11
367#define UVC_DT_FRAME_MJPEG_SIZE(n) (26+4*(n))
368#define UVC_DT_COLOR_MATCHING_SIZE 6
369 19
370extern int uvc_bind_config(struct usb_configuration *c, 20extern int uvc_bind_config(struct usb_configuration *c,
371 const struct uvc_descriptor_header * const *control, 21 const struct uvc_descriptor_header * const *control,
diff --git a/drivers/usb/gadget/uvc.h b/drivers/usb/gadget/uvc.h
index e92454cddd7d..5b7919460fd2 100644
--- a/drivers/usb/gadget/uvc.h
+++ b/drivers/usb/gadget/uvc.h
@@ -48,39 +48,6 @@ struct uvc_event
48#define UVC_INTF_STREAMING 1 48#define UVC_INTF_STREAMING 1
49 49
50/* ------------------------------------------------------------------------ 50/* ------------------------------------------------------------------------
51 * UVC constants & structures
52 */
53
54/* Values for bmHeaderInfo (Video and Still Image Payload Headers, 2.4.3.3) */
55#define UVC_STREAM_EOH (1 << 7)
56#define UVC_STREAM_ERR (1 << 6)
57#define UVC_STREAM_STI (1 << 5)
58#define UVC_STREAM_RES (1 << 4)
59#define UVC_STREAM_SCR (1 << 3)
60#define UVC_STREAM_PTS (1 << 2)
61#define UVC_STREAM_EOF (1 << 1)
62#define UVC_STREAM_FID (1 << 0)
63
64struct uvc_streaming_control {
65 __u16 bmHint;
66 __u8 bFormatIndex;
67 __u8 bFrameIndex;
68 __u32 dwFrameInterval;
69 __u16 wKeyFrameRate;
70 __u16 wPFrameRate;
71 __u16 wCompQuality;
72 __u16 wCompWindowSize;
73 __u16 wDelay;
74 __u32 dwMaxVideoFrameSize;
75 __u32 dwMaxPayloadTransferSize;
76 __u32 dwClockFrequency;
77 __u8 bmFramingInfo;
78 __u8 bPreferedVersion;
79 __u8 bMinVersion;
80 __u8 bMaxVersion;
81} __attribute__((__packed__));
82
83/* ------------------------------------------------------------------------
84 * Debugging, printing and logging 51 * Debugging, printing and logging
85 */ 52 */
86 53
@@ -137,9 +104,6 @@ extern unsigned int uvc_gadget_trace_param;
137#define UVC_MAX_REQUEST_SIZE 64 104#define UVC_MAX_REQUEST_SIZE 64
138#define UVC_MAX_EVENTS 4 105#define UVC_MAX_EVENTS 4
139 106
140#define USB_DT_INTERFACE_ASSOCIATION_SIZE 8
141#define USB_CLASS_MISC 0xef
142
143/* ------------------------------------------------------------------------ 107/* ------------------------------------------------------------------------
144 * Structures 108 * Structures
145 */ 109 */
diff --git a/drivers/usb/gadget/webcam.c b/drivers/usb/gadget/webcam.c
index f5f3030cc416..288d21155abe 100644
--- a/drivers/usb/gadget/webcam.c
+++ b/drivers/usb/gadget/webcam.c
@@ -90,7 +90,7 @@ DECLARE_UVC_HEADER_DESCRIPTOR(1);
90static const struct UVC_HEADER_DESCRIPTOR(1) uvc_control_header = { 90static const struct UVC_HEADER_DESCRIPTOR(1) uvc_control_header = {
91 .bLength = UVC_DT_HEADER_SIZE(1), 91 .bLength = UVC_DT_HEADER_SIZE(1),
92 .bDescriptorType = USB_DT_CS_INTERFACE, 92 .bDescriptorType = USB_DT_CS_INTERFACE,
93 .bDescriptorSubType = UVC_DT_HEADER, 93 .bDescriptorSubType = UVC_VC_HEADER,
94 .bcdUVC = cpu_to_le16(0x0100), 94 .bcdUVC = cpu_to_le16(0x0100),
95 .wTotalLength = 0, /* dynamic */ 95 .wTotalLength = 0, /* dynamic */
96 .dwClockFrequency = cpu_to_le32(48000000), 96 .dwClockFrequency = cpu_to_le32(48000000),
@@ -101,7 +101,7 @@ static const struct UVC_HEADER_DESCRIPTOR(1) uvc_control_header = {
101static const struct uvc_camera_terminal_descriptor uvc_camera_terminal = { 101static const struct uvc_camera_terminal_descriptor uvc_camera_terminal = {
102 .bLength = UVC_DT_CAMERA_TERMINAL_SIZE(3), 102 .bLength = UVC_DT_CAMERA_TERMINAL_SIZE(3),
103 .bDescriptorType = USB_DT_CS_INTERFACE, 103 .bDescriptorType = USB_DT_CS_INTERFACE,
104 .bDescriptorSubType = UVC_DT_INPUT_TERMINAL, 104 .bDescriptorSubType = UVC_VC_INPUT_TERMINAL,
105 .bTerminalID = 1, 105 .bTerminalID = 1,
106 .wTerminalType = cpu_to_le16(0x0201), 106 .wTerminalType = cpu_to_le16(0x0201),
107 .bAssocTerminal = 0, 107 .bAssocTerminal = 0,
@@ -118,7 +118,7 @@ static const struct uvc_camera_terminal_descriptor uvc_camera_terminal = {
118static const struct uvc_processing_unit_descriptor uvc_processing = { 118static const struct uvc_processing_unit_descriptor uvc_processing = {
119 .bLength = UVC_DT_PROCESSING_UNIT_SIZE(2), 119 .bLength = UVC_DT_PROCESSING_UNIT_SIZE(2),
120 .bDescriptorType = USB_DT_CS_INTERFACE, 120 .bDescriptorType = USB_DT_CS_INTERFACE,
121 .bDescriptorSubType = UVC_DT_PROCESSING_UNIT, 121 .bDescriptorSubType = UVC_VC_PROCESSING_UNIT,
122 .bUnitID = 2, 122 .bUnitID = 2,
123 .bSourceID = 1, 123 .bSourceID = 1,
124 .wMaxMultiplier = cpu_to_le16(16*1024), 124 .wMaxMultiplier = cpu_to_le16(16*1024),
@@ -131,7 +131,7 @@ static const struct uvc_processing_unit_descriptor uvc_processing = {
131static const struct uvc_output_terminal_descriptor uvc_output_terminal = { 131static const struct uvc_output_terminal_descriptor uvc_output_terminal = {
132 .bLength = UVC_DT_OUTPUT_TERMINAL_SIZE, 132 .bLength = UVC_DT_OUTPUT_TERMINAL_SIZE,
133 .bDescriptorType = USB_DT_CS_INTERFACE, 133 .bDescriptorType = USB_DT_CS_INTERFACE,
134 .bDescriptorSubType = UVC_DT_OUTPUT_TERMINAL, 134 .bDescriptorSubType = UVC_VC_OUTPUT_TERMINAL,
135 .bTerminalID = 3, 135 .bTerminalID = 3,
136 .wTerminalType = cpu_to_le16(0x0101), 136 .wTerminalType = cpu_to_le16(0x0101),
137 .bAssocTerminal = 0, 137 .bAssocTerminal = 0,
@@ -144,7 +144,7 @@ DECLARE_UVC_INPUT_HEADER_DESCRIPTOR(1, 2);
144static const struct UVC_INPUT_HEADER_DESCRIPTOR(1, 2) uvc_input_header = { 144static const struct UVC_INPUT_HEADER_DESCRIPTOR(1, 2) uvc_input_header = {
145 .bLength = UVC_DT_INPUT_HEADER_SIZE(1, 2), 145 .bLength = UVC_DT_INPUT_HEADER_SIZE(1, 2),
146 .bDescriptorType = USB_DT_CS_INTERFACE, 146 .bDescriptorType = USB_DT_CS_INTERFACE,
147 .bDescriptorSubType = UVC_DT_INPUT_HEADER, 147 .bDescriptorSubType = UVC_VS_INPUT_HEADER,
148 .bNumFormats = 2, 148 .bNumFormats = 2,
149 .wTotalLength = 0, /* dynamic */ 149 .wTotalLength = 0, /* dynamic */
150 .bEndpointAddress = 0, /* dynamic */ 150 .bEndpointAddress = 0, /* dynamic */
@@ -161,7 +161,7 @@ static const struct UVC_INPUT_HEADER_DESCRIPTOR(1, 2) uvc_input_header = {
161static const struct uvc_format_uncompressed uvc_format_yuv = { 161static const struct uvc_format_uncompressed uvc_format_yuv = {
162 .bLength = UVC_DT_FORMAT_UNCOMPRESSED_SIZE, 162 .bLength = UVC_DT_FORMAT_UNCOMPRESSED_SIZE,
163 .bDescriptorType = USB_DT_CS_INTERFACE, 163 .bDescriptorType = USB_DT_CS_INTERFACE,
164 .bDescriptorSubType = UVC_DT_FORMAT_UNCOMPRESSED, 164 .bDescriptorSubType = UVC_VS_FORMAT_UNCOMPRESSED,
165 .bFormatIndex = 1, 165 .bFormatIndex = 1,
166 .bNumFrameDescriptors = 2, 166 .bNumFrameDescriptors = 2,
167 .guidFormat = 167 .guidFormat =
@@ -181,7 +181,7 @@ DECLARE_UVC_FRAME_UNCOMPRESSED(3);
181static const struct UVC_FRAME_UNCOMPRESSED(3) uvc_frame_yuv_360p = { 181static const struct UVC_FRAME_UNCOMPRESSED(3) uvc_frame_yuv_360p = {
182 .bLength = UVC_DT_FRAME_UNCOMPRESSED_SIZE(3), 182 .bLength = UVC_DT_FRAME_UNCOMPRESSED_SIZE(3),
183 .bDescriptorType = USB_DT_CS_INTERFACE, 183 .bDescriptorType = USB_DT_CS_INTERFACE,
184 .bDescriptorSubType = UVC_DT_FRAME_UNCOMPRESSED, 184 .bDescriptorSubType = UVC_VS_FRAME_UNCOMPRESSED,
185 .bFrameIndex = 1, 185 .bFrameIndex = 1,
186 .bmCapabilities = 0, 186 .bmCapabilities = 0,
187 .wWidth = cpu_to_le16(640), 187 .wWidth = cpu_to_le16(640),
@@ -199,7 +199,7 @@ static const struct UVC_FRAME_UNCOMPRESSED(3) uvc_frame_yuv_360p = {
199static const struct UVC_FRAME_UNCOMPRESSED(1) uvc_frame_yuv_720p = { 199static const struct UVC_FRAME_UNCOMPRESSED(1) uvc_frame_yuv_720p = {
200 .bLength = UVC_DT_FRAME_UNCOMPRESSED_SIZE(1), 200 .bLength = UVC_DT_FRAME_UNCOMPRESSED_SIZE(1),
201 .bDescriptorType = USB_DT_CS_INTERFACE, 201 .bDescriptorType = USB_DT_CS_INTERFACE,
202 .bDescriptorSubType = UVC_DT_FRAME_UNCOMPRESSED, 202 .bDescriptorSubType = UVC_VS_FRAME_UNCOMPRESSED,
203 .bFrameIndex = 2, 203 .bFrameIndex = 2,
204 .bmCapabilities = 0, 204 .bmCapabilities = 0,
205 .wWidth = cpu_to_le16(1280), 205 .wWidth = cpu_to_le16(1280),
@@ -215,7 +215,7 @@ static const struct UVC_FRAME_UNCOMPRESSED(1) uvc_frame_yuv_720p = {
215static const struct uvc_format_mjpeg uvc_format_mjpg = { 215static const struct uvc_format_mjpeg uvc_format_mjpg = {
216 .bLength = UVC_DT_FORMAT_MJPEG_SIZE, 216 .bLength = UVC_DT_FORMAT_MJPEG_SIZE,
217 .bDescriptorType = USB_DT_CS_INTERFACE, 217 .bDescriptorType = USB_DT_CS_INTERFACE,
218 .bDescriptorSubType = UVC_DT_FORMAT_MJPEG, 218 .bDescriptorSubType = UVC_VS_FORMAT_MJPEG,
219 .bFormatIndex = 2, 219 .bFormatIndex = 2,
220 .bNumFrameDescriptors = 2, 220 .bNumFrameDescriptors = 2,
221 .bmFlags = 0, 221 .bmFlags = 0,
@@ -232,7 +232,7 @@ DECLARE_UVC_FRAME_MJPEG(3);
232static const struct UVC_FRAME_MJPEG(3) uvc_frame_mjpg_360p = { 232static const struct UVC_FRAME_MJPEG(3) uvc_frame_mjpg_360p = {
233 .bLength = UVC_DT_FRAME_MJPEG_SIZE(3), 233 .bLength = UVC_DT_FRAME_MJPEG_SIZE(3),
234 .bDescriptorType = USB_DT_CS_INTERFACE, 234 .bDescriptorType = USB_DT_CS_INTERFACE,
235 .bDescriptorSubType = UVC_DT_FRAME_MJPEG, 235 .bDescriptorSubType = UVC_VS_FRAME_MJPEG,
236 .bFrameIndex = 1, 236 .bFrameIndex = 1,
237 .bmCapabilities = 0, 237 .bmCapabilities = 0,
238 .wWidth = cpu_to_le16(640), 238 .wWidth = cpu_to_le16(640),
@@ -250,7 +250,7 @@ static const struct UVC_FRAME_MJPEG(3) uvc_frame_mjpg_360p = {
250static const struct UVC_FRAME_MJPEG(1) uvc_frame_mjpg_720p = { 250static const struct UVC_FRAME_MJPEG(1) uvc_frame_mjpg_720p = {
251 .bLength = UVC_DT_FRAME_MJPEG_SIZE(1), 251 .bLength = UVC_DT_FRAME_MJPEG_SIZE(1),
252 .bDescriptorType = USB_DT_CS_INTERFACE, 252 .bDescriptorType = USB_DT_CS_INTERFACE,
253 .bDescriptorSubType = UVC_DT_FRAME_MJPEG, 253 .bDescriptorSubType = UVC_VS_FRAME_MJPEG,
254 .bFrameIndex = 2, 254 .bFrameIndex = 2,
255 .bmCapabilities = 0, 255 .bmCapabilities = 0,
256 .wWidth = cpu_to_le16(1280), 256 .wWidth = cpu_to_le16(1280),
@@ -266,7 +266,7 @@ static const struct UVC_FRAME_MJPEG(1) uvc_frame_mjpg_720p = {
266static const struct uvc_color_matching_descriptor uvc_color_matching = { 266static const struct uvc_color_matching_descriptor uvc_color_matching = {
267 .bLength = UVC_DT_COLOR_MATCHING_SIZE, 267 .bLength = UVC_DT_COLOR_MATCHING_SIZE,
268 .bDescriptorType = USB_DT_CS_INTERFACE, 268 .bDescriptorType = USB_DT_CS_INTERFACE,
269 .bDescriptorSubType = UVC_DT_COLOR_MATCHING, 269 .bDescriptorSubType = UVC_VS_COLORFORMAT,
270 .bColorPrimaries = 1, 270 .bColorPrimaries = 1,
271 .bTransferCharacteristics = 1, 271 .bTransferCharacteristics = 1,
272 .bMatrixCoefficients = 4, 272 .bMatrixCoefficients = 4,
diff --git a/drivers/video/omap2/displays/panel-acx565akm.c b/drivers/video/omap2/displays/panel-acx565akm.c
index 1f8eb70e2937..07fbb8a733bb 100644
--- a/drivers/video/omap2/displays/panel-acx565akm.c
+++ b/drivers/video/omap2/displays/panel-acx565akm.c
@@ -592,7 +592,7 @@ static int acx_panel_power_on(struct omap_dss_device *dssdev)
592 r = omapdss_sdi_display_enable(dssdev); 592 r = omapdss_sdi_display_enable(dssdev);
593 if (r) { 593 if (r) {
594 pr_err("%s sdi enable failed\n", __func__); 594 pr_err("%s sdi enable failed\n", __func__);
595 return r; 595 goto fail_unlock;
596 } 596 }
597 597
598 /*FIXME tweak me */ 598 /*FIXME tweak me */
@@ -633,6 +633,8 @@ static int acx_panel_power_on(struct omap_dss_device *dssdev)
633 return acx565akm_bl_update_status(md->bl_dev); 633 return acx565akm_bl_update_status(md->bl_dev);
634fail: 634fail:
635 omapdss_sdi_display_disable(dssdev); 635 omapdss_sdi_display_disable(dssdev);
636fail_unlock:
637 mutex_unlock(&md->mutex);
636 return r; 638 return r;
637} 639}
638 640
diff --git a/include/linux/dvb/frontend.h b/include/linux/dvb/frontend.h
index b6cb5425cde3..493a2bf85f62 100644
--- a/include/linux/dvb/frontend.h
+++ b/include/linux/dvb/frontend.h
@@ -62,6 +62,7 @@ typedef enum fe_caps {
62 FE_CAN_8VSB = 0x200000, 62 FE_CAN_8VSB = 0x200000,
63 FE_CAN_16VSB = 0x400000, 63 FE_CAN_16VSB = 0x400000,
64 FE_HAS_EXTENDED_CAPS = 0x800000, /* We need more bitspace for newer APIs, indicate this. */ 64 FE_HAS_EXTENDED_CAPS = 0x800000, /* We need more bitspace for newer APIs, indicate this. */
65 FE_CAN_TURBO_FEC = 0x8000000, /* frontend supports "turbo fec modulation" */
65 FE_CAN_2G_MODULATION = 0x10000000, /* frontend supports "2nd generation modulation" (DVB-S2) */ 66 FE_CAN_2G_MODULATION = 0x10000000, /* frontend supports "2nd generation modulation" (DVB-S2) */
66 FE_NEEDS_BENDING = 0x20000000, /* not supported anymore, don't use (frontend requires frequency bending) */ 67 FE_NEEDS_BENDING = 0x20000000, /* not supported anymore, don't use (frontend requires frequency bending) */
67 FE_CAN_RECOVER = 0x40000000, /* frontend can recover from a cable unplug automatically */ 68 FE_CAN_RECOVER = 0x40000000, /* frontend can recover from a cable unplug automatically */
diff --git a/include/linux/dvb/version.h b/include/linux/dvb/version.h
index 540b0583d9fb..5a7546c12688 100644
--- a/include/linux/dvb/version.h
+++ b/include/linux/dvb/version.h
@@ -24,6 +24,6 @@
24#define _DVBVERSION_H_ 24#define _DVBVERSION_H_
25 25
26#define DVB_API_VERSION 5 26#define DVB_API_VERSION 5
27#define DVB_API_VERSION_MINOR 1 27#define DVB_API_VERSION_MINOR 2
28 28
29#endif /*_DVBVERSION_H_*/ 29#endif /*_DVBVERSION_H_*/
diff --git a/include/linux/usb/video.h b/include/linux/usb/video.h
index be436d9ee479..3b3b95e01f71 100644
--- a/include/linux/usb/video.h
+++ b/include/linux/usb/video.h
@@ -160,5 +160,409 @@
160#define UVC_STATUS_TYPE_CONTROL 1 160#define UVC_STATUS_TYPE_CONTROL 1
161#define UVC_STATUS_TYPE_STREAMING 2 161#define UVC_STATUS_TYPE_STREAMING 2
162 162
163/* 2.4.3.3. Payload Header Information */
164#define UVC_STREAM_EOH (1 << 7)
165#define UVC_STREAM_ERR (1 << 6)
166#define UVC_STREAM_STI (1 << 5)
167#define UVC_STREAM_RES (1 << 4)
168#define UVC_STREAM_SCR (1 << 3)
169#define UVC_STREAM_PTS (1 << 2)
170#define UVC_STREAM_EOF (1 << 1)
171#define UVC_STREAM_FID (1 << 0)
172
173/* 4.1.2. Control Capabilities */
174#define UVC_CONTROL_CAP_GET (1 << 0)
175#define UVC_CONTROL_CAP_SET (1 << 1)
176#define UVC_CONTROL_CAP_DISABLED (1 << 2)
177#define UVC_CONTROL_CAP_AUTOUPDATE (1 << 3)
178#define UVC_CONTROL_CAP_ASYNCHRONOUS (1 << 4)
179
180/* ------------------------------------------------------------------------
181 * UVC structures
182 */
183
184/* All UVC descriptors have these 3 fields at the beginning */
185struct uvc_descriptor_header {
186 __u8 bLength;
187 __u8 bDescriptorType;
188 __u8 bDescriptorSubType;
189} __attribute__((packed));
190
191/* 3.7.2. Video Control Interface Header Descriptor */
192struct uvc_header_descriptor {
193 __u8 bLength;
194 __u8 bDescriptorType;
195 __u8 bDescriptorSubType;
196 __u16 bcdUVC;
197 __u16 wTotalLength;
198 __u32 dwClockFrequency;
199 __u8 bInCollection;
200 __u8 baInterfaceNr[];
201} __attribute__((__packed__));
202
203#define UVC_DT_HEADER_SIZE(n) (12+(n))
204
205#define UVC_HEADER_DESCRIPTOR(n) \
206 uvc_header_descriptor_##n
207
208#define DECLARE_UVC_HEADER_DESCRIPTOR(n) \
209struct UVC_HEADER_DESCRIPTOR(n) { \
210 __u8 bLength; \
211 __u8 bDescriptorType; \
212 __u8 bDescriptorSubType; \
213 __u16 bcdUVC; \
214 __u16 wTotalLength; \
215 __u32 dwClockFrequency; \
216 __u8 bInCollection; \
217 __u8 baInterfaceNr[n]; \
218} __attribute__ ((packed))
219
220/* 3.7.2.1. Input Terminal Descriptor */
221struct uvc_input_terminal_descriptor {
222 __u8 bLength;
223 __u8 bDescriptorType;
224 __u8 bDescriptorSubType;
225 __u8 bTerminalID;
226 __u16 wTerminalType;
227 __u8 bAssocTerminal;
228 __u8 iTerminal;
229} __attribute__((__packed__));
230
231#define UVC_DT_INPUT_TERMINAL_SIZE 8
232
233/* 3.7.2.2. Output Terminal Descriptor */
234struct uvc_output_terminal_descriptor {
235 __u8 bLength;
236 __u8 bDescriptorType;
237 __u8 bDescriptorSubType;
238 __u8 bTerminalID;
239 __u16 wTerminalType;
240 __u8 bAssocTerminal;
241 __u8 bSourceID;
242 __u8 iTerminal;
243} __attribute__((__packed__));
244
245#define UVC_DT_OUTPUT_TERMINAL_SIZE 9
246
247/* 3.7.2.3. Camera Terminal Descriptor */
248struct uvc_camera_terminal_descriptor {
249 __u8 bLength;
250 __u8 bDescriptorType;
251 __u8 bDescriptorSubType;
252 __u8 bTerminalID;
253 __u16 wTerminalType;
254 __u8 bAssocTerminal;
255 __u8 iTerminal;
256 __u16 wObjectiveFocalLengthMin;
257 __u16 wObjectiveFocalLengthMax;
258 __u16 wOcularFocalLength;
259 __u8 bControlSize;
260 __u8 bmControls[3];
261} __attribute__((__packed__));
262
263#define UVC_DT_CAMERA_TERMINAL_SIZE(n) (15+(n))
264
265/* 3.7.2.4. Selector Unit Descriptor */
266struct uvc_selector_unit_descriptor {
267 __u8 bLength;
268 __u8 bDescriptorType;
269 __u8 bDescriptorSubType;
270 __u8 bUnitID;
271 __u8 bNrInPins;
272 __u8 baSourceID[0];
273 __u8 iSelector;
274} __attribute__((__packed__));
275
276#define UVC_DT_SELECTOR_UNIT_SIZE(n) (6+(n))
277
278#define UVC_SELECTOR_UNIT_DESCRIPTOR(n) \
279 uvc_selector_unit_descriptor_##n
280
281#define DECLARE_UVC_SELECTOR_UNIT_DESCRIPTOR(n) \
282struct UVC_SELECTOR_UNIT_DESCRIPTOR(n) { \
283 __u8 bLength; \
284 __u8 bDescriptorType; \
285 __u8 bDescriptorSubType; \
286 __u8 bUnitID; \
287 __u8 bNrInPins; \
288 __u8 baSourceID[n]; \
289 __u8 iSelector; \
290} __attribute__ ((packed))
291
292/* 3.7.2.5. Processing Unit Descriptor */
293struct uvc_processing_unit_descriptor {
294 __u8 bLength;
295 __u8 bDescriptorType;
296 __u8 bDescriptorSubType;
297 __u8 bUnitID;
298 __u8 bSourceID;
299 __u16 wMaxMultiplier;
300 __u8 bControlSize;
301 __u8 bmControls[2];
302 __u8 iProcessing;
303} __attribute__((__packed__));
304
305#define UVC_DT_PROCESSING_UNIT_SIZE(n) (9+(n))
306
307/* 3.7.2.6. Extension Unit Descriptor */
308struct uvc_extension_unit_descriptor {
309 __u8 bLength;
310 __u8 bDescriptorType;
311 __u8 bDescriptorSubType;
312 __u8 bUnitID;
313 __u8 guidExtensionCode[16];
314 __u8 bNumControls;
315 __u8 bNrInPins;
316 __u8 baSourceID[0];
317 __u8 bControlSize;
318 __u8 bmControls[0];
319 __u8 iExtension;
320} __attribute__((__packed__));
321
322#define UVC_DT_EXTENSION_UNIT_SIZE(p, n) (24+(p)+(n))
323
324#define UVC_EXTENSION_UNIT_DESCRIPTOR(p, n) \
325 uvc_extension_unit_descriptor_##p_##n
326
327#define DECLARE_UVC_EXTENSION_UNIT_DESCRIPTOR(p, n) \
328struct UVC_EXTENSION_UNIT_DESCRIPTOR(p, n) { \
329 __u8 bLength; \
330 __u8 bDescriptorType; \
331 __u8 bDescriptorSubType; \
332 __u8 bUnitID; \
333 __u8 guidExtensionCode[16]; \
334 __u8 bNumControls; \
335 __u8 bNrInPins; \
336 __u8 baSourceID[p]; \
337 __u8 bControlSize; \
338 __u8 bmControls[n]; \
339 __u8 iExtension; \
340} __attribute__ ((packed))
341
342/* 3.8.2.2. Video Control Interrupt Endpoint Descriptor */
343struct uvc_control_endpoint_descriptor {
344 __u8 bLength;
345 __u8 bDescriptorType;
346 __u8 bDescriptorSubType;
347 __u16 wMaxTransferSize;
348} __attribute__((__packed__));
349
350#define UVC_DT_CONTROL_ENDPOINT_SIZE 5
351
352/* 3.9.2.1. Input Header Descriptor */
353struct uvc_input_header_descriptor {
354 __u8 bLength;
355 __u8 bDescriptorType;
356 __u8 bDescriptorSubType;
357 __u8 bNumFormats;
358 __u16 wTotalLength;
359 __u8 bEndpointAddress;
360 __u8 bmInfo;
361 __u8 bTerminalLink;
362 __u8 bStillCaptureMethod;
363 __u8 bTriggerSupport;
364 __u8 bTriggerUsage;
365 __u8 bControlSize;
366 __u8 bmaControls[];
367} __attribute__((__packed__));
368
369#define UVC_DT_INPUT_HEADER_SIZE(n, p) (13+(n*p))
370
371#define UVC_INPUT_HEADER_DESCRIPTOR(n, p) \
372 uvc_input_header_descriptor_##n_##p
373
374#define DECLARE_UVC_INPUT_HEADER_DESCRIPTOR(n, p) \
375struct UVC_INPUT_HEADER_DESCRIPTOR(n, p) { \
376 __u8 bLength; \
377 __u8 bDescriptorType; \
378 __u8 bDescriptorSubType; \
379 __u8 bNumFormats; \
380 __u16 wTotalLength; \
381 __u8 bEndpointAddress; \
382 __u8 bmInfo; \
383 __u8 bTerminalLink; \
384 __u8 bStillCaptureMethod; \
385 __u8 bTriggerSupport; \
386 __u8 bTriggerUsage; \
387 __u8 bControlSize; \
388 __u8 bmaControls[p][n]; \
389} __attribute__ ((packed))
390
391/* 3.9.2.2. Output Header Descriptor */
392struct uvc_output_header_descriptor {
393 __u8 bLength;
394 __u8 bDescriptorType;
395 __u8 bDescriptorSubType;
396 __u8 bNumFormats;
397 __u16 wTotalLength;
398 __u8 bEndpointAddress;
399 __u8 bTerminalLink;
400 __u8 bControlSize;
401 __u8 bmaControls[];
402} __attribute__((__packed__));
403
404#define UVC_DT_OUTPUT_HEADER_SIZE(n, p) (9+(n*p))
405
406#define UVC_OUTPUT_HEADER_DESCRIPTOR(n, p) \
407 uvc_output_header_descriptor_##n_##p
408
409#define DECLARE_UVC_OUTPUT_HEADER_DESCRIPTOR(n, p) \
410struct UVC_OUTPUT_HEADER_DESCRIPTOR(n, p) { \
411 __u8 bLength; \
412 __u8 bDescriptorType; \
413 __u8 bDescriptorSubType; \
414 __u8 bNumFormats; \
415 __u16 wTotalLength; \
416 __u8 bEndpointAddress; \
417 __u8 bTerminalLink; \
418 __u8 bControlSize; \
419 __u8 bmaControls[p][n]; \
420} __attribute__ ((packed))
421
422/* 3.9.2.6. Color matching descriptor */
423struct uvc_color_matching_descriptor {
424 __u8 bLength;
425 __u8 bDescriptorType;
426 __u8 bDescriptorSubType;
427 __u8 bColorPrimaries;
428 __u8 bTransferCharacteristics;
429 __u8 bMatrixCoefficients;
430} __attribute__((__packed__));
431
432#define UVC_DT_COLOR_MATCHING_SIZE 6
433
434/* 4.3.1.1. Video Probe and Commit Controls */
435struct uvc_streaming_control {
436 __u16 bmHint;
437 __u8 bFormatIndex;
438 __u8 bFrameIndex;
439 __u32 dwFrameInterval;
440 __u16 wKeyFrameRate;
441 __u16 wPFrameRate;
442 __u16 wCompQuality;
443 __u16 wCompWindowSize;
444 __u16 wDelay;
445 __u32 dwMaxVideoFrameSize;
446 __u32 dwMaxPayloadTransferSize;
447 __u32 dwClockFrequency;
448 __u8 bmFramingInfo;
449 __u8 bPreferedVersion;
450 __u8 bMinVersion;
451 __u8 bMaxVersion;
452} __attribute__((__packed__));
453
454/* Uncompressed Payload - 3.1.1. Uncompressed Video Format Descriptor */
455struct uvc_format_uncompressed {
456 __u8 bLength;
457 __u8 bDescriptorType;
458 __u8 bDescriptorSubType;
459 __u8 bFormatIndex;
460 __u8 bNumFrameDescriptors;
461 __u8 guidFormat[16];
462 __u8 bBitsPerPixel;
463 __u8 bDefaultFrameIndex;
464 __u8 bAspectRatioX;
465 __u8 bAspectRatioY;
466 __u8 bmInterfaceFlags;
467 __u8 bCopyProtect;
468} __attribute__((__packed__));
469
470#define UVC_DT_FORMAT_UNCOMPRESSED_SIZE 27
471
472/* Uncompressed Payload - 3.1.2. Uncompressed Video Frame Descriptor */
473struct uvc_frame_uncompressed {
474 __u8 bLength;
475 __u8 bDescriptorType;
476 __u8 bDescriptorSubType;
477 __u8 bFrameIndex;
478 __u8 bmCapabilities;
479 __u16 wWidth;
480 __u16 wHeight;
481 __u32 dwMinBitRate;
482 __u32 dwMaxBitRate;
483 __u32 dwMaxVideoFrameBufferSize;
484 __u32 dwDefaultFrameInterval;
485 __u8 bFrameIntervalType;
486 __u32 dwFrameInterval[];
487} __attribute__((__packed__));
488
489#define UVC_DT_FRAME_UNCOMPRESSED_SIZE(n) (26+4*(n))
490
491#define UVC_FRAME_UNCOMPRESSED(n) \
492 uvc_frame_uncompressed_##n
493
494#define DECLARE_UVC_FRAME_UNCOMPRESSED(n) \
495struct UVC_FRAME_UNCOMPRESSED(n) { \
496 __u8 bLength; \
497 __u8 bDescriptorType; \
498 __u8 bDescriptorSubType; \
499 __u8 bFrameIndex; \
500 __u8 bmCapabilities; \
501 __u16 wWidth; \
502 __u16 wHeight; \
503 __u32 dwMinBitRate; \
504 __u32 dwMaxBitRate; \
505 __u32 dwMaxVideoFrameBufferSize; \
506 __u32 dwDefaultFrameInterval; \
507 __u8 bFrameIntervalType; \
508 __u32 dwFrameInterval[n]; \
509} __attribute__ ((packed))
510
511/* MJPEG Payload - 3.1.1. MJPEG Video Format Descriptor */
512struct uvc_format_mjpeg {
513 __u8 bLength;
514 __u8 bDescriptorType;
515 __u8 bDescriptorSubType;
516 __u8 bFormatIndex;
517 __u8 bNumFrameDescriptors;
518 __u8 bmFlags;
519 __u8 bDefaultFrameIndex;
520 __u8 bAspectRatioX;
521 __u8 bAspectRatioY;
522 __u8 bmInterfaceFlags;
523 __u8 bCopyProtect;
524} __attribute__((__packed__));
525
526#define UVC_DT_FORMAT_MJPEG_SIZE 11
527
528/* MJPEG Payload - 3.1.2. MJPEG Video Frame Descriptor */
529struct uvc_frame_mjpeg {
530 __u8 bLength;
531 __u8 bDescriptorType;
532 __u8 bDescriptorSubType;
533 __u8 bFrameIndex;
534 __u8 bmCapabilities;
535 __u16 wWidth;
536 __u16 wHeight;
537 __u32 dwMinBitRate;
538 __u32 dwMaxBitRate;
539 __u32 dwMaxVideoFrameBufferSize;
540 __u32 dwDefaultFrameInterval;
541 __u8 bFrameIntervalType;
542 __u32 dwFrameInterval[];
543} __attribute__((__packed__));
544
545#define UVC_DT_FRAME_MJPEG_SIZE(n) (26+4*(n))
546
547#define UVC_FRAME_MJPEG(n) \
548 uvc_frame_mjpeg_##n
549
550#define DECLARE_UVC_FRAME_MJPEG(n) \
551struct UVC_FRAME_MJPEG(n) { \
552 __u8 bLength; \
553 __u8 bDescriptorType; \
554 __u8 bDescriptorSubType; \
555 __u8 bFrameIndex; \
556 __u8 bmCapabilities; \
557 __u16 wWidth; \
558 __u16 wHeight; \
559 __u32 dwMinBitRate; \
560 __u32 dwMaxBitRate; \
561 __u32 dwMaxVideoFrameBufferSize; \
562 __u32 dwDefaultFrameInterval; \
563 __u8 bFrameIntervalType; \
564 __u32 dwFrameInterval[n]; \
565} __attribute__ ((packed))
566
163#endif /* __LINUX_USB_VIDEO_H */ 567#endif /* __LINUX_USB_VIDEO_H */
164 568
diff --git a/include/media/ir-core.h b/include/media/ir-core.h
index ad1303f20e00..513e60dd1010 100644
--- a/include/media/ir-core.h
+++ b/include/media/ir-core.h
@@ -47,15 +47,21 @@ enum rc_driver_type {
47 * is opened. 47 * is opened.
48 * @close: callback to allow drivers to disable polling/irq when IR input device 48 * @close: callback to allow drivers to disable polling/irq when IR input device
49 * is opened. 49 * is opened.
50 * @s_tx_mask: set transmitter mask (for devices with multiple tx outputs)
51 * @s_tx_carrier: set transmit carrier frequency
52 * @tx_ir: transmit IR
50 */ 53 */
51struct ir_dev_props { 54struct ir_dev_props {
52 enum rc_driver_type driver_type; 55 enum rc_driver_type driver_type;
53 unsigned long allowed_protos; 56 unsigned long allowed_protos;
54 u32 scanmask; 57 u32 scanmask;
55 void *priv; 58 void *priv;
56 int (*change_protocol)(void *priv, u64 ir_type); 59 int (*change_protocol)(void *priv, u64 ir_type);
57 int (*open)(void *priv); 60 int (*open)(void *priv);
58 void (*close)(void *priv); 61 void (*close)(void *priv);
62 int (*s_tx_mask)(void *priv, u32 mask);
63 int (*s_tx_carrier)(void *priv, u32 carrier);
64 int (*tx_ir)(void *priv, int *txbuf, u32 n);
59}; 65};
60 66
61struct ir_input_dev { 67struct ir_input_dev {
diff --git a/include/media/ir-kbd-i2c.h b/include/media/ir-kbd-i2c.h
index 0506e45c9a4f..5e96d7a430be 100644
--- a/include/media/ir-kbd-i2c.h
+++ b/include/media/ir-kbd-i2c.h
@@ -11,7 +11,7 @@ struct IR_i2c {
11 struct i2c_client *c; 11 struct i2c_client *c;
12 struct input_dev *input; 12 struct input_dev *input;
13 struct ir_input_state ir; 13 struct ir_input_state ir;
14 14 u64 ir_type;
15 /* Used to avoid fast repeating */ 15 /* Used to avoid fast repeating */
16 unsigned char old; 16 unsigned char old;
17 17
diff --git a/include/media/lirc.h b/include/media/lirc.h
new file mode 100644
index 000000000000..42c467c50519
--- /dev/null
+++ b/include/media/lirc.h
@@ -0,0 +1,165 @@
1/*
2 * lirc.h - linux infrared remote control header file
3 * last modified 2010/07/13 by Jarod Wilson
4 */
5
6#ifndef _LINUX_LIRC_H
7#define _LINUX_LIRC_H
8
9#include <linux/types.h>
10#include <linux/ioctl.h>
11
12#define PULSE_BIT 0x01000000
13#define PULSE_MASK 0x00FFFFFF
14
15#define LIRC_MODE2_SPACE 0x00000000
16#define LIRC_MODE2_PULSE 0x01000000
17#define LIRC_MODE2_FREQUENCY 0x02000000
18#define LIRC_MODE2_TIMEOUT 0x03000000
19
20#define LIRC_VALUE_MASK 0x00FFFFFF
21#define LIRC_MODE2_MASK 0xFF000000
22
23#define LIRC_SPACE(val) (((val)&LIRC_VALUE_MASK) | LIRC_MODE2_SPACE)
24#define LIRC_PULSE(val) (((val)&LIRC_VALUE_MASK) | LIRC_MODE2_PULSE)
25#define LIRC_FREQUENCY(val) (((val)&LIRC_VALUE_MASK) | LIRC_MODE2_FREQUENCY)
26#define LIRC_TIMEOUT(val) (((val)&LIRC_VALUE_MASK) | LIRC_MODE2_TIMEOUT)
27
28#define LIRC_VALUE(val) ((val)&LIRC_VALUE_MASK)
29#define LIRC_MODE2(val) ((val)&LIRC_MODE2_MASK)
30
31#define LIRC_IS_SPACE(val) (LIRC_MODE2(val) == LIRC_MODE2_SPACE)
32#define LIRC_IS_PULSE(val) (LIRC_MODE2(val) == LIRC_MODE2_PULSE)
33#define LIRC_IS_FREQUENCY(val) (LIRC_MODE2(val) == LIRC_MODE2_FREQUENCY)
34#define LIRC_IS_TIMEOUT(val) (LIRC_MODE2(val) == LIRC_MODE2_TIMEOUT)
35
36/* used heavily by lirc userspace */
37#define lirc_t int
38
39/*** lirc compatible hardware features ***/
40
41#define LIRC_MODE2SEND(x) (x)
42#define LIRC_SEND2MODE(x) (x)
43#define LIRC_MODE2REC(x) ((x) << 16)
44#define LIRC_REC2MODE(x) ((x) >> 16)
45
46#define LIRC_MODE_RAW 0x00000001
47#define LIRC_MODE_PULSE 0x00000002
48#define LIRC_MODE_MODE2 0x00000004
49#define LIRC_MODE_LIRCCODE 0x00000010
50
51
52#define LIRC_CAN_SEND_RAW LIRC_MODE2SEND(LIRC_MODE_RAW)
53#define LIRC_CAN_SEND_PULSE LIRC_MODE2SEND(LIRC_MODE_PULSE)
54#define LIRC_CAN_SEND_MODE2 LIRC_MODE2SEND(LIRC_MODE_MODE2)
55#define LIRC_CAN_SEND_LIRCCODE LIRC_MODE2SEND(LIRC_MODE_LIRCCODE)
56
57#define LIRC_CAN_SEND_MASK 0x0000003f
58
59#define LIRC_CAN_SET_SEND_CARRIER 0x00000100
60#define LIRC_CAN_SET_SEND_DUTY_CYCLE 0x00000200
61#define LIRC_CAN_SET_TRANSMITTER_MASK 0x00000400
62
63#define LIRC_CAN_REC_RAW LIRC_MODE2REC(LIRC_MODE_RAW)
64#define LIRC_CAN_REC_PULSE LIRC_MODE2REC(LIRC_MODE_PULSE)
65#define LIRC_CAN_REC_MODE2 LIRC_MODE2REC(LIRC_MODE_MODE2)
66#define LIRC_CAN_REC_LIRCCODE LIRC_MODE2REC(LIRC_MODE_LIRCCODE)
67
68#define LIRC_CAN_REC_MASK LIRC_MODE2REC(LIRC_CAN_SEND_MASK)
69
70#define LIRC_CAN_SET_REC_CARRIER (LIRC_CAN_SET_SEND_CARRIER << 16)
71#define LIRC_CAN_SET_REC_DUTY_CYCLE (LIRC_CAN_SET_SEND_DUTY_CYCLE << 16)
72
73#define LIRC_CAN_SET_REC_DUTY_CYCLE_RANGE 0x40000000
74#define LIRC_CAN_SET_REC_CARRIER_RANGE 0x80000000
75#define LIRC_CAN_GET_REC_RESOLUTION 0x20000000
76#define LIRC_CAN_SET_REC_TIMEOUT 0x10000000
77#define LIRC_CAN_SET_REC_FILTER 0x08000000
78
79#define LIRC_CAN_MEASURE_CARRIER 0x02000000
80
81#define LIRC_CAN_SEND(x) ((x)&LIRC_CAN_SEND_MASK)
82#define LIRC_CAN_REC(x) ((x)&LIRC_CAN_REC_MASK)
83
84#define LIRC_CAN_NOTIFY_DECODE 0x01000000
85
86/*** IOCTL commands for lirc driver ***/
87
88#define LIRC_GET_FEATURES _IOR('i', 0x00000000, __u32)
89
90#define LIRC_GET_SEND_MODE _IOR('i', 0x00000001, __u32)
91#define LIRC_GET_REC_MODE _IOR('i', 0x00000002, __u32)
92#define LIRC_GET_SEND_CARRIER _IOR('i', 0x00000003, __u32)
93#define LIRC_GET_REC_CARRIER _IOR('i', 0x00000004, __u32)
94#define LIRC_GET_SEND_DUTY_CYCLE _IOR('i', 0x00000005, __u32)
95#define LIRC_GET_REC_DUTY_CYCLE _IOR('i', 0x00000006, __u32)
96#define LIRC_GET_REC_RESOLUTION _IOR('i', 0x00000007, __u32)
97
98#define LIRC_GET_MIN_TIMEOUT _IOR('i', 0x00000008, __u32)
99#define LIRC_GET_MAX_TIMEOUT _IOR('i', 0x00000009, __u32)
100
101#define LIRC_GET_MIN_FILTER_PULSE _IOR('i', 0x0000000a, __u32)
102#define LIRC_GET_MAX_FILTER_PULSE _IOR('i', 0x0000000b, __u32)
103#define LIRC_GET_MIN_FILTER_SPACE _IOR('i', 0x0000000c, __u32)
104#define LIRC_GET_MAX_FILTER_SPACE _IOR('i', 0x0000000d, __u32)
105
106/* code length in bits, currently only for LIRC_MODE_LIRCCODE */
107#define LIRC_GET_LENGTH _IOR('i', 0x0000000f, __u32)
108
109#define LIRC_SET_SEND_MODE _IOW('i', 0x00000011, __u32)
110#define LIRC_SET_REC_MODE _IOW('i', 0x00000012, __u32)
111/* Note: these can reset the according pulse_width */
112#define LIRC_SET_SEND_CARRIER _IOW('i', 0x00000013, __u32)
113#define LIRC_SET_REC_CARRIER _IOW('i', 0x00000014, __u32)
114#define LIRC_SET_SEND_DUTY_CYCLE _IOW('i', 0x00000015, __u32)
115#define LIRC_SET_REC_DUTY_CYCLE _IOW('i', 0x00000016, __u32)
116#define LIRC_SET_TRANSMITTER_MASK _IOW('i', 0x00000017, __u32)
117
118/*
119 * when a timeout != 0 is set the driver will send a
120 * LIRC_MODE2_TIMEOUT data packet, otherwise LIRC_MODE2_TIMEOUT is
121 * never sent, timeout is disabled by default
122 */
123#define LIRC_SET_REC_TIMEOUT _IOW('i', 0x00000018, __u32)
124
125/* 1 enables, 0 disables timeout reports in MODE2 */
126#define LIRC_SET_REC_TIMEOUT_REPORTS _IOW('i', 0x00000019, __u32)
127
128/*
129 * pulses shorter than this are filtered out by hardware (software
130 * emulation in lirc_dev?)
131 */
132#define LIRC_SET_REC_FILTER_PULSE _IOW('i', 0x0000001a, __u32)
133/*
134 * spaces shorter than this are filtered out by hardware (software
135 * emulation in lirc_dev?)
136 */
137#define LIRC_SET_REC_FILTER_SPACE _IOW('i', 0x0000001b, __u32)
138/*
139 * if filter cannot be set independantly for pulse/space, this should
140 * be used
141 */
142#define LIRC_SET_REC_FILTER _IOW('i', 0x0000001c, __u32)
143
144/*
145 * if enabled from the next key press on the driver will send
146 * LIRC_MODE2_FREQUENCY packets
147 */
148#define LIRC_SET_MEASURE_CARRIER_MODE _IOW('i', 0x0000001d, __u32)
149
150/*
151 * to set a range use
152 * LIRC_SET_REC_DUTY_CYCLE_RANGE/LIRC_SET_REC_CARRIER_RANGE with the
153 * lower bound first and later
154 * LIRC_SET_REC_DUTY_CYCLE/LIRC_SET_REC_CARRIER with the upper bound
155 */
156
157#define LIRC_SET_REC_DUTY_CYCLE_RANGE _IOW('i', 0x0000001e, __u32)
158#define LIRC_SET_REC_CARRIER_RANGE _IOW('i', 0x0000001f, __u32)
159
160#define LIRC_NOTIFY_DECODE _IO('i', 0x00000020)
161
162#define LIRC_SETUP_START _IO('i', 0x00000021)
163#define LIRC_SETUP_END _IO('i', 0x00000022)
164
165#endif
diff --git a/include/media/lirc_dev.h b/include/media/lirc_dev.h
new file mode 100644
index 000000000000..b1f60663cb39
--- /dev/null
+++ b/include/media/lirc_dev.h
@@ -0,0 +1,225 @@
1/*
2 * LIRC base driver
3 *
4 * by Artur Lipowski <alipowski@interia.pl>
5 * This code is licensed under GNU GPL
6 *
7 */
8
9#ifndef _LINUX_LIRC_DEV_H
10#define _LINUX_LIRC_DEV_H
11
12#define MAX_IRCTL_DEVICES 4
13#define BUFLEN 16
14
15#define mod(n, div) ((n) % (div))
16
17#include <linux/slab.h>
18#include <linux/fs.h>
19#include <linux/ioctl.h>
20#include <linux/poll.h>
21#include <linux/kfifo.h>
22#include <media/lirc.h>
23
24struct lirc_buffer {
25 wait_queue_head_t wait_poll;
26 spinlock_t fifo_lock;
27 unsigned int chunk_size;
28 unsigned int size; /* in chunks */
29 /* Using chunks instead of bytes pretends to simplify boundary checking
30 * And should allow for some performance fine tunning later */
31 struct kfifo fifo;
32 u8 fifo_initialized;
33};
34
35static inline void lirc_buffer_clear(struct lirc_buffer *buf)
36{
37 unsigned long flags;
38
39 if (buf->fifo_initialized) {
40 spin_lock_irqsave(&buf->fifo_lock, flags);
41 kfifo_reset(&buf->fifo);
42 spin_unlock_irqrestore(&buf->fifo_lock, flags);
43 } else
44 WARN(1, "calling %s on an uninitialized lirc_buffer\n",
45 __func__);
46}
47
48static inline int lirc_buffer_init(struct lirc_buffer *buf,
49 unsigned int chunk_size,
50 unsigned int size)
51{
52 int ret;
53
54 init_waitqueue_head(&buf->wait_poll);
55 spin_lock_init(&buf->fifo_lock);
56 buf->chunk_size = chunk_size;
57 buf->size = size;
58 ret = kfifo_alloc(&buf->fifo, size * chunk_size, GFP_KERNEL);
59 if (ret == 0)
60 buf->fifo_initialized = 1;
61
62 return ret;
63}
64
65static inline void lirc_buffer_free(struct lirc_buffer *buf)
66{
67 if (buf->fifo_initialized) {
68 kfifo_free(&buf->fifo);
69 buf->fifo_initialized = 0;
70 } else
71 WARN(1, "calling %s on an uninitialized lirc_buffer\n",
72 __func__);
73}
74
75static inline int lirc_buffer_len(struct lirc_buffer *buf)
76{
77 int len;
78 unsigned long flags;
79
80 spin_lock_irqsave(&buf->fifo_lock, flags);
81 len = kfifo_len(&buf->fifo);
82 spin_unlock_irqrestore(&buf->fifo_lock, flags);
83
84 return len;
85}
86
87static inline int lirc_buffer_full(struct lirc_buffer *buf)
88{
89 return lirc_buffer_len(buf) == buf->size * buf->chunk_size;
90}
91
92static inline int lirc_buffer_empty(struct lirc_buffer *buf)
93{
94 return !lirc_buffer_len(buf);
95}
96
97static inline int lirc_buffer_available(struct lirc_buffer *buf)
98{
99 return buf->size - (lirc_buffer_len(buf) / buf->chunk_size);
100}
101
102static inline unsigned int lirc_buffer_read(struct lirc_buffer *buf,
103 unsigned char *dest)
104{
105 unsigned int ret = 0;
106
107 if (lirc_buffer_len(buf) >= buf->chunk_size)
108 ret = kfifo_out_locked(&buf->fifo, dest, buf->chunk_size,
109 &buf->fifo_lock);
110 return ret;
111
112}
113
114static inline unsigned int lirc_buffer_write(struct lirc_buffer *buf,
115 unsigned char *orig)
116{
117 unsigned int ret;
118
119 ret = kfifo_in_locked(&buf->fifo, orig, buf->chunk_size,
120 &buf->fifo_lock);
121
122 return ret;
123}
124
125struct lirc_driver {
126 char name[40];
127 int minor;
128 unsigned long code_length;
129 unsigned int buffer_size; /* in chunks holding one code each */
130 int sample_rate;
131 unsigned long features;
132
133 unsigned int chunk_size;
134
135 void *data;
136 int min_timeout;
137 int max_timeout;
138 int (*add_to_buf) (void *data, struct lirc_buffer *buf);
139 struct lirc_buffer *rbuf;
140 int (*set_use_inc) (void *data);
141 void (*set_use_dec) (void *data);
142 struct file_operations *fops;
143 struct device *dev;
144 struct module *owner;
145};
146
147/* name:
148 * this string will be used for logs
149 *
150 * minor:
151 * indicates minor device (/dev/lirc) number for registered driver
152 * if caller fills it with negative value, then the first free minor
153 * number will be used (if available)
154 *
155 * code_length:
156 * length of the remote control key code expressed in bits
157 *
158 * sample_rate:
159 *
160 * data:
161 * it may point to any driver data and this pointer will be passed to
162 * all callback functions
163 *
164 * add_to_buf:
165 * add_to_buf will be called after specified period of the time or
166 * triggered by the external event, this behavior depends on value of
167 * the sample_rate this function will be called in user context. This
168 * routine should return 0 if data was added to the buffer and
169 * -ENODATA if none was available. This should add some number of bits
170 * evenly divisible by code_length to the buffer
171 *
172 * rbuf:
173 * if not NULL, it will be used as a read buffer, you will have to
174 * write to the buffer by other means, like irq's (see also
175 * lirc_serial.c).
176 *
177 * set_use_inc:
178 * set_use_inc will be called after device is opened
179 *
180 * set_use_dec:
181 * set_use_dec will be called after device is closed
182 *
183 * fops:
184 * file_operations for drivers which don't fit the current driver model.
185 *
186 * Some ioctl's can be directly handled by lirc_dev if the driver's
187 * ioctl function is NULL or if it returns -ENOIOCTLCMD (see also
188 * lirc_serial.c).
189 *
190 * owner:
191 * the module owning this struct
192 *
193 */
194
195
196/* following functions can be called ONLY from user context
197 *
198 * returns negative value on error or minor number
199 * of the registered device if success
200 * contents of the structure pointed by p is copied
201 */
202extern int lirc_register_driver(struct lirc_driver *d);
203
204/* returns negative value on error or 0 if success
205*/
206extern int lirc_unregister_driver(int minor);
207
208/* Returns the private data stored in the lirc_driver
209 * associated with the given device file pointer.
210 */
211void *lirc_get_pdata(struct file *file);
212
213/* default file operations
214 * used by drivers if they override only some operations
215 */
216int lirc_dev_fop_open(struct inode *inode, struct file *file);
217int lirc_dev_fop_close(struct inode *inode, struct file *file);
218unsigned int lirc_dev_fop_poll(struct file *file, poll_table *wait);
219long lirc_dev_fop_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
220ssize_t lirc_dev_fop_read(struct file *file, char *buffer, size_t length,
221 loff_t *ppos);
222ssize_t lirc_dev_fop_write(struct file *file, const char *buffer, size_t length,
223 loff_t *ppos);
224
225#endif
diff --git a/include/media/rc-map.h b/include/media/rc-map.h
index c78e99a435b6..9569d0863f8b 100644
--- a/include/media/rc-map.h
+++ b/include/media/rc-map.h
@@ -17,8 +17,13 @@
17#define IR_TYPE_RC6 (1 << 2) /* Philips RC6 protocol */ 17#define IR_TYPE_RC6 (1 << 2) /* Philips RC6 protocol */
18#define IR_TYPE_JVC (1 << 3) /* JVC protocol */ 18#define IR_TYPE_JVC (1 << 3) /* JVC protocol */
19#define IR_TYPE_SONY (1 << 4) /* Sony12/15/20 protocol */ 19#define IR_TYPE_SONY (1 << 4) /* Sony12/15/20 protocol */
20#define IR_TYPE_LIRC (1 << 30) /* Pass raw IR to lirc userspace */
20#define IR_TYPE_OTHER (1u << 31) 21#define IR_TYPE_OTHER (1u << 31)
21 22
23#define IR_TYPE_ALL (IR_TYPE_RC5 | IR_TYPE_NEC | IR_TYPE_RC6 | \
24 IR_TYPE_JVC | IR_TYPE_SONY | IR_TYPE_LIRC | \
25 IR_TYPE_OTHER)
26
22struct ir_scancode { 27struct ir_scancode {
23 u32 scancode; 28 u32 scancode;
24 u32 keycode; 29 u32 keycode;
@@ -64,6 +69,8 @@ void rc_map_init(void);
64#define RC_MAP_BUDGET_CI_OLD "rc-budget-ci-old" 69#define RC_MAP_BUDGET_CI_OLD "rc-budget-ci-old"
65#define RC_MAP_CINERGY_1400 "rc-cinergy-1400" 70#define RC_MAP_CINERGY_1400 "rc-cinergy-1400"
66#define RC_MAP_CINERGY "rc-cinergy" 71#define RC_MAP_CINERGY "rc-cinergy"
72#define RC_MAP_DIB0700_NEC_TABLE "rc-dib0700-nec"
73#define RC_MAP_DIB0700_RC5_TABLE "rc-dib0700-rc5"
67#define RC_MAP_DM1105_NEC "rc-dm1105-nec" 74#define RC_MAP_DM1105_NEC "rc-dm1105-nec"
68#define RC_MAP_DNTV_LIVE_DVBT_PRO "rc-dntv-live-dvbt-pro" 75#define RC_MAP_DNTV_LIVE_DVBT_PRO "rc-dntv-live-dvbt-pro"
69#define RC_MAP_DNTV_LIVE_DVB_T "rc-dntv-live-dvb-t" 76#define RC_MAP_DNTV_LIVE_DVB_T "rc-dntv-live-dvb-t"
@@ -87,6 +94,7 @@ void rc_map_init(void);
87#define RC_MAP_KAIOMY "rc-kaiomy" 94#define RC_MAP_KAIOMY "rc-kaiomy"
88#define RC_MAP_KWORLD_315U "rc-kworld-315u" 95#define RC_MAP_KWORLD_315U "rc-kworld-315u"
89#define RC_MAP_KWORLD_PLUS_TV_ANALOG "rc-kworld-plus-tv-analog" 96#define RC_MAP_KWORLD_PLUS_TV_ANALOG "rc-kworld-plus-tv-analog"
97#define RC_MAP_LIRC "rc-lirc"
90#define RC_MAP_MANLI "rc-manli" 98#define RC_MAP_MANLI "rc-manli"
91#define RC_MAP_MSI_TVANYWHERE_PLUS "rc-msi-tvanywhere-plus" 99#define RC_MAP_MSI_TVANYWHERE_PLUS "rc-msi-tvanywhere-plus"
92#define RC_MAP_MSI_TVANYWHERE "rc-msi-tvanywhere" 100#define RC_MAP_MSI_TVANYWHERE "rc-msi-tvanywhere"
@@ -107,6 +115,7 @@ void rc_map_init(void);
107#define RC_MAP_PV951 "rc-pv951" 115#define RC_MAP_PV951 "rc-pv951"
108#define RC_MAP_RC5_HAUPPAUGE_NEW "rc-rc5-hauppauge-new" 116#define RC_MAP_RC5_HAUPPAUGE_NEW "rc-rc5-hauppauge-new"
109#define RC_MAP_RC5_TV "rc-rc5-tv" 117#define RC_MAP_RC5_TV "rc-rc5-tv"
118#define RC_MAP_RC6_MCE "rc-rc6-mce"
110#define RC_MAP_REAL_AUDIO_220_32_KEYS "rc-real-audio-220-32-keys" 119#define RC_MAP_REAL_AUDIO_220_32_KEYS "rc-real-audio-220-32-keys"
111#define RC_MAP_TBS_NEC "rc-tbs-nec" 120#define RC_MAP_TBS_NEC "rc-tbs-nec"
112#define RC_MAP_TERRATEC_CINERGY_XS "rc-terratec-cinergy-xs" 121#define RC_MAP_TERRATEC_CINERGY_XS "rc-terratec-cinergy-xs"
@@ -116,6 +125,7 @@ void rc_map_init(void);
116#define RC_MAP_VIDEOMATE_TV_PVR "rc-videomate-tv-pvr" 125#define RC_MAP_VIDEOMATE_TV_PVR "rc-videomate-tv-pvr"
117#define RC_MAP_WINFAST "rc-winfast" 126#define RC_MAP_WINFAST "rc-winfast"
118#define RC_MAP_WINFAST_USBII_DELUXE "rc-winfast-usbii-deluxe" 127#define RC_MAP_WINFAST_USBII_DELUXE "rc-winfast-usbii-deluxe"
128
119/* 129/*
120 * Please, do not just append newer Remote Controller names at the end. 130 * Please, do not just append newer Remote Controller names at the end.
121 * The names should be ordered in alphabetical order 131 * The names should be ordered in alphabetical order
diff --git a/include/media/sh_mobile_ceu.h b/include/media/sh_mobile_ceu.h
index b67747836878..80346a6d28a9 100644
--- a/include/media/sh_mobile_ceu.h
+++ b/include/media/sh_mobile_ceu.h
@@ -6,8 +6,11 @@
6#define SH_CEU_FLAG_HSYNC_LOW (1 << 2) /* default High if possible */ 6#define SH_CEU_FLAG_HSYNC_LOW (1 << 2) /* default High if possible */
7#define SH_CEU_FLAG_VSYNC_LOW (1 << 3) /* default High if possible */ 7#define SH_CEU_FLAG_VSYNC_LOW (1 << 3) /* default High if possible */
8 8
9struct device;
10
9struct sh_mobile_ceu_info { 11struct sh_mobile_ceu_info {
10 unsigned long flags; 12 unsigned long flags;
13 struct device *csi2_dev;
11}; 14};
12 15
13#endif /* __ASM_SH_MOBILE_CEU_H__ */ 16#endif /* __ASM_SH_MOBILE_CEU_H__ */
diff --git a/include/media/sh_mobile_csi2.h b/include/media/sh_mobile_csi2.h
new file mode 100644
index 000000000000..4d2615174461
--- /dev/null
+++ b/include/media/sh_mobile_csi2.h
@@ -0,0 +1,46 @@
1/*
2 * Driver header for the SH-Mobile MIPI CSI-2 unit
3 *
4 * Copyright (C) 2010, Guennadi Liakhovetski <g.liakhovetski@gmx.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 version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#ifndef SH_MIPI_CSI
12#define SH_MIPI_CSI
13
14enum sh_csi2_phy {
15 SH_CSI2_PHY_MAIN,
16 SH_CSI2_PHY_SUB,
17};
18
19enum sh_csi2_type {
20 SH_CSI2C,
21 SH_CSI2I,
22};
23
24#define SH_CSI2_CRC (1 << 0)
25#define SH_CSI2_ECC (1 << 1)
26
27struct platform_device;
28
29struct sh_csi2_client_config {
30 enum sh_csi2_phy phy;
31 unsigned char lanes; /* bitmask[3:0] */
32 unsigned char channel; /* 0..3 */
33 struct platform_device *pdev; /* client platform device */
34};
35
36struct sh_csi2_pdata {
37 enum sh_csi2_type type;
38 unsigned int flags;
39 struct sh_csi2_client_config *clients;
40 int num_clients;
41};
42
43struct device;
44struct v4l2_device;
45
46#endif
diff --git a/include/media/soc_camera.h b/include/media/soc_camera.h
index b8289c2f609b..2ce957301f77 100644
--- a/include/media/soc_camera.h
+++ b/include/media/soc_camera.h
@@ -12,12 +12,15 @@
12#ifndef SOC_CAMERA_H 12#ifndef SOC_CAMERA_H
13#define SOC_CAMERA_H 13#define SOC_CAMERA_H
14 14
15#include <linux/device.h>
15#include <linux/mutex.h> 16#include <linux/mutex.h>
16#include <linux/pm.h> 17#include <linux/pm.h>
17#include <linux/videodev2.h> 18#include <linux/videodev2.h>
18#include <media/videobuf-core.h> 19#include <media/videobuf-core.h>
19#include <media/v4l2-device.h> 20#include <media/v4l2-device.h>
20 21
22extern struct bus_type soc_camera_bus_type;
23
21struct soc_camera_device { 24struct soc_camera_device {
22 struct list_head list; 25 struct list_head list;
23 struct device dev; 26 struct device dev;
diff --git a/include/media/v4l2-mediabus.h b/include/media/v4l2-mediabus.h
index 865cda7cd611..f0cf2e7def06 100644
--- a/include/media/v4l2-mediabus.h
+++ b/include/media/v4l2-mediabus.h
@@ -24,10 +24,10 @@
24 */ 24 */
25enum v4l2_mbus_pixelcode { 25enum v4l2_mbus_pixelcode {
26 V4L2_MBUS_FMT_FIXED = 1, 26 V4L2_MBUS_FMT_FIXED = 1,
27 V4L2_MBUS_FMT_YUYV8_2X8_LE, 27 V4L2_MBUS_FMT_YUYV8_2X8,
28 V4L2_MBUS_FMT_YVYU8_2X8_LE, 28 V4L2_MBUS_FMT_YVYU8_2X8,
29 V4L2_MBUS_FMT_YUYV8_2X8_BE, 29 V4L2_MBUS_FMT_UYVY8_2X8,
30 V4L2_MBUS_FMT_YVYU8_2X8_BE, 30 V4L2_MBUS_FMT_VYUY8_2X8,
31 V4L2_MBUS_FMT_RGB555_2X8_PADHI_LE, 31 V4L2_MBUS_FMT_RGB555_2X8_PADHI_LE,
32 V4L2_MBUS_FMT_RGB555_2X8_PADHI_BE, 32 V4L2_MBUS_FMT_RGB555_2X8_PADHI_BE,
33 V4L2_MBUS_FMT_RGB565_2X8_LE, 33 V4L2_MBUS_FMT_RGB565_2X8_LE,
@@ -41,6 +41,11 @@ enum v4l2_mbus_pixelcode {
41 V4L2_MBUS_FMT_SBGGR10_2X8_PADHI_BE, 41 V4L2_MBUS_FMT_SBGGR10_2X8_PADHI_BE,
42 V4L2_MBUS_FMT_SBGGR10_2X8_PADLO_BE, 42 V4L2_MBUS_FMT_SBGGR10_2X8_PADLO_BE,
43 V4L2_MBUS_FMT_SGRBG8_1X8, 43 V4L2_MBUS_FMT_SGRBG8_1X8,
44 V4L2_MBUS_FMT_SBGGR12_1X12,
45 V4L2_MBUS_FMT_YUYV8_1_5X8,
46 V4L2_MBUS_FMT_YVYU8_1_5X8,
47 V4L2_MBUS_FMT_UYVY8_1_5X8,
48 V4L2_MBUS_FMT_VYUY8_1_5X8,
44}; 49};
45 50
46/** 51/**
diff --git a/include/media/videobuf-core.h b/include/media/videobuf-core.h
index f91a736c133d..f2c41cebf453 100644
--- a/include/media/videobuf-core.h
+++ b/include/media/videobuf-core.h
@@ -54,8 +54,6 @@ struct videobuf_queue;
54 54
55struct videobuf_mapping { 55struct videobuf_mapping {
56 unsigned int count; 56 unsigned int count;
57 unsigned long start;
58 unsigned long end;
59 struct videobuf_queue *q; 57 struct videobuf_queue *q;
60}; 58};
61 59
@@ -127,7 +125,7 @@ struct videobuf_queue_ops {
127struct videobuf_qtype_ops { 125struct videobuf_qtype_ops {
128 u32 magic; 126 u32 magic;
129 127
130 struct videobuf_buffer *(*alloc)(size_t size); 128 struct videobuf_buffer *(*alloc_vb)(size_t size);
131 void *(*vaddr) (struct videobuf_buffer *buf); 129 void *(*vaddr) (struct videobuf_buffer *buf);
132 int (*iolock) (struct videobuf_queue *q, 130 int (*iolock) (struct videobuf_queue *q,
133 struct videobuf_buffer *vb, 131 struct videobuf_buffer *vb,
@@ -173,7 +171,7 @@ int videobuf_waiton(struct videobuf_buffer *vb, int non_blocking, int intr);
173int videobuf_iolock(struct videobuf_queue *q, struct videobuf_buffer *vb, 171int videobuf_iolock(struct videobuf_queue *q, struct videobuf_buffer *vb,
174 struct v4l2_framebuffer *fbuf); 172 struct v4l2_framebuffer *fbuf);
175 173
176struct videobuf_buffer *videobuf_alloc(struct videobuf_queue *q); 174struct videobuf_buffer *videobuf_alloc_vb(struct videobuf_queue *q);
177 175
178/* Used on videobuf-dvb */ 176/* Used on videobuf-dvb */
179void *videobuf_queue_to_vaddr(struct videobuf_queue *q, 177void *videobuf_queue_to_vaddr(struct videobuf_queue *q,
diff --git a/include/media/videobuf-dma-sg.h b/include/media/videobuf-dma-sg.h
index a195f3b9c00a..97e07f46a0fa 100644
--- a/include/media/videobuf-dma-sg.h
+++ b/include/media/videobuf-dma-sg.h
@@ -25,23 +25,6 @@
25/* --------------------------------------------------------------------- */ 25/* --------------------------------------------------------------------- */
26 26
27/* 27/*
28 * Return a scatterlist for some page-aligned vmalloc()'ed memory
29 * block (NULL on errors). Memory for the scatterlist is allocated
30 * using kmalloc. The caller must free the memory.
31 */
32struct scatterlist *videobuf_vmalloc_to_sg(unsigned char *virt, int nr_pages);
33
34/*
35 * Return a scatterlist for a an array of userpages (NULL on errors).
36 * Memory for the scatterlist is allocated using kmalloc. The caller
37 * must free the memory.
38 */
39struct scatterlist *videobuf_pages_to_sg(struct page **pages, int nr_pages,
40 int offset);
41
42/* --------------------------------------------------------------------- */
43
44/*
45 * A small set of helper functions to manage buffers (both userland 28 * A small set of helper functions to manage buffers (both userland
46 * and kernel) for DMA. 29 * and kernel) for DMA.
47 * 30 *
@@ -68,7 +51,7 @@ struct videobuf_dmabuf {
68 struct page **pages; 51 struct page **pages;
69 52
70 /* for kernel buffers */ 53 /* for kernel buffers */
71 void *vmalloc; 54 void *vaddr;
72 55
73 /* for overlay buffers (pci-pci dma) */ 56 /* for overlay buffers (pci-pci dma) */
74 dma_addr_t bus_addr; 57 dma_addr_t bus_addr;
@@ -87,6 +70,16 @@ struct videobuf_dma_sg_memory {
87 struct videobuf_dmabuf dma; 70 struct videobuf_dmabuf dma;
88}; 71};
89 72
73/*
74 * Scatter-gather DMA buffer API.
75 *
76 * These functions provide a simple way to create a page list and a
77 * scatter-gather list from a kernel, userspace of physical address and map the
78 * memory for DMA operation.
79 *
80 * Despite the name, this is totally unrelated to videobuf, except that
81 * videobuf-dma-sg uses the same API internally.
82 */
90void videobuf_dma_init(struct videobuf_dmabuf *dma); 83void videobuf_dma_init(struct videobuf_dmabuf *dma);
91int videobuf_dma_init_user(struct videobuf_dmabuf *dma, int direction, 84int videobuf_dma_init_user(struct videobuf_dmabuf *dma, int direction,
92 unsigned long data, unsigned long size); 85 unsigned long data, unsigned long size);
@@ -96,8 +89,8 @@ int videobuf_dma_init_overlay(struct videobuf_dmabuf *dma, int direction,
96 dma_addr_t addr, int nr_pages); 89 dma_addr_t addr, int nr_pages);
97int videobuf_dma_free(struct videobuf_dmabuf *dma); 90int videobuf_dma_free(struct videobuf_dmabuf *dma);
98 91
99int videobuf_dma_map(struct videobuf_queue *q, struct videobuf_dmabuf *dma); 92int videobuf_dma_map(struct device *dev, struct videobuf_dmabuf *dma);
100int videobuf_dma_unmap(struct videobuf_queue *q, struct videobuf_dmabuf *dma); 93int videobuf_dma_unmap(struct device *dev, struct videobuf_dmabuf *dma);
101struct videobuf_dmabuf *videobuf_to_dma(struct videobuf_buffer *buf); 94struct videobuf_dmabuf *videobuf_to_dma(struct videobuf_buffer *buf);
102 95
103void *videobuf_sg_alloc(size_t size); 96void *videobuf_sg_alloc(size_t size);
@@ -111,11 +104,5 @@ void videobuf_queue_sg_init(struct videobuf_queue *q,
111 unsigned int msize, 104 unsigned int msize,
112 void *priv); 105 void *priv);
113 106
114/*FIXME: these variants are used only on *-alsa code, where videobuf is
115 * used without queue
116 */
117int videobuf_sg_dma_map(struct device *dev, struct videobuf_dmabuf *dma);
118int videobuf_sg_dma_unmap(struct device *dev, struct videobuf_dmabuf *dma);
119
120#endif /* _VIDEOBUF_DMA_SG_H */ 107#endif /* _VIDEOBUF_DMA_SG_H */
121 108
diff --git a/include/media/videobuf-vmalloc.h b/include/media/videobuf-vmalloc.h
index 851eb1a2ff2a..e19403c18dae 100644
--- a/include/media/videobuf-vmalloc.h
+++ b/include/media/videobuf-vmalloc.h
@@ -22,7 +22,7 @@
22struct videobuf_vmalloc_memory { 22struct videobuf_vmalloc_memory {
23 u32 magic; 23 u32 magic;
24 24
25 void *vmalloc; 25 void *vaddr;
26 26
27 /* remap_vmalloc_range seems to need to run 27 /* remap_vmalloc_range seems to need to run
28 * after mmap() on some cases */ 28 * after mmap() on some cases */